├── .gitignore
├── app.js
├── components
└── codeEditor
│ ├── code-editor.html
│ ├── codeEditor.js
│ ├── services
│ └── textUtils.js
│ ├── styles
│ └── codemirror
│ │ ├── codemirror.css
│ │ └── themes
│ │ └── vibrant-ink.css
│ └── vendor
│ └── codemirror
│ ├── codemirror.js
│ └── modes
│ └── javascript
│ ├── index.html
│ ├── javascript.js
│ ├── json-ld.html
│ ├── test.js
│ └── typescript.html
├── index.html
├── package.json
├── readme.md
├── server.js
└── vendor
├── .DS_Store
└── angular.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /node_modules
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | angular.module("demo", []);
--------------------------------------------------------------------------------
/components/codeEditor/code-editor.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/components/codeEditor/codeEditor.js:
--------------------------------------------------------------------------------
1 | angular.module("demo").directive("codeEditor", function($timeout, TextUtils){
2 | return {
3 | restrict: "E",
4 | replace: true,
5 | require: "?ngModel",
6 | transclude: true,
7 | scope: {
8 | syntax: "@",
9 | theme: "@"
10 | },
11 | templateUrl: "components/codeEditor/code-editor.html",
12 | link: function(scope, element, attrs, ngModelCtrl, transclude){
13 | // Initialize Codemirror
14 | var editor = CodeMirror(element[0], {
15 | mode: scope.syntax || "javascript",
16 | theme: scope.theme || "default",
17 | lineNumbers: true
18 | });
19 |
20 | // Handle setting the editor when the model changes if ngModel exists
21 | if(ngModelCtrl) {
22 | // Timeout is required here to give ngModel a chance to setup. This prevents
23 | // a value of undefined getting passed as the view is rendered for the first
24 | // time, which causes CodeMirror to throw an error.
25 | $timeout(function(){
26 | ngModelCtrl.$render = function() {
27 | editor.setValue(ngModelCtrl.$viewValue);
28 | }
29 | })
30 | }
31 |
32 | transclude(scope, function(clonedEl){
33 | var initialText = TextUtils.normalizeWhitespace(clonedEl.text());
34 | editor.setValue(initialText);
35 |
36 | // Handle setting the model if ngModel exists
37 | if(ngModelCtrl){
38 | // Wrap these initial setting calls in a $timeout to give angular a chance
39 | // to setup the view and set any initial model values that may be set in the view
40 | $timeout(function(){
41 | // Populate the initial ng-model if it exists and is empty.
42 | // Prioritize the value in ngModel.
43 | if(initialText && !ngModelCtrl.$viewValue){
44 | ngModelCtrl.$setViewValue(initialText);
45 | }
46 |
47 | // Whenever the editor emits any change events, update the value
48 | // of the model.
49 | editor.on('change', function(){
50 | ngModelCtrl.$setViewValue(editor.getValue());
51 | });
52 | });
53 | }
54 | });
55 |
56 | // Clean up the CodeMirror change event whenever the directive is destroyed
57 | scope.$on('$destroy', function(){
58 | editor.off('change');
59 | });
60 | }
61 | }
62 | });
--------------------------------------------------------------------------------
/components/codeEditor/services/textUtils.js:
--------------------------------------------------------------------------------
1 | angular.module('demo').factory("TextUtils", function(){
2 | return {
3 | // Strip leading whitespace from initial value, this is similar to
4 | // rails' strip_heredoc function, it uses the first line with content
5 | // as the leading whitespace baseline
6 | normalizeWhitespace: function(str) {
7 | // Strip an initial blank whitespace caused from having text nested inside an html tag
8 | var string = str.replace(/^\n/, '');
9 |
10 | // Find the first text with an indent and get the length of the indent
11 | var firstIndentLength = new RegExp("(?:^|\n)([ \t\r]+)").exec(string)[1].length
12 |
13 | // Use the first indent length as a baseline and normalize all other lines
14 | return string.replace(new RegExp("(^|\n)[ \t\r]{"+firstIndentLength+"}", 'g'), "$1")
15 | }
16 | };
17 | });
--------------------------------------------------------------------------------
/components/codeEditor/styles/codemirror/codemirror.css:
--------------------------------------------------------------------------------
1 | /* BASICS */
2 |
3 | .CodeMirror {
4 | /* Set height, width, borders, and global font properties here */
5 | font-family: monospace;
6 | height: 300px;
7 | color: black;
8 | }
9 |
10 | /* PADDING */
11 |
12 | .CodeMirror-lines {
13 | padding: 4px 0; /* Vertical padding around content */
14 | }
15 | .CodeMirror pre {
16 | padding: 0 4px; /* Horizontal padding of content */
17 | }
18 |
19 | .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
20 | background-color: white; /* The little square between H and V scrollbars */
21 | }
22 |
23 | /* GUTTER */
24 |
25 | .CodeMirror-gutters {
26 | border-right: 1px solid #ddd;
27 | background-color: #f7f7f7;
28 | white-space: nowrap;
29 | }
30 | .CodeMirror-linenumbers {}
31 | .CodeMirror-linenumber {
32 | padding: 0 3px 0 5px;
33 | min-width: 20px;
34 | text-align: right;
35 | color: #999;
36 | -moz-box-sizing: content-box;
37 | box-sizing: content-box;
38 | }
39 |
40 | .CodeMirror-guttermarker { color: black; }
41 | .CodeMirror-guttermarker-subtle { color: #999; }
42 |
43 | /* CURSOR */
44 |
45 | .CodeMirror div.CodeMirror-cursor {
46 | border-left: 1px solid black;
47 | }
48 | /* Shown when moving in bi-directional text */
49 | .CodeMirror div.CodeMirror-secondarycursor {
50 | border-left: 1px solid silver;
51 | }
52 | .CodeMirror.cm-fat-cursor div.CodeMirror-cursor {
53 | width: auto;
54 | border: 0;
55 | background: #7e7;
56 | }
57 | .CodeMirror.cm-fat-cursor div.CodeMirror-cursors {
58 | z-index: 1;
59 | }
60 |
61 | .cm-animate-fat-cursor {
62 | width: auto;
63 | border: 0;
64 | -webkit-animation: blink 1.06s steps(1) infinite;
65 | -moz-animation: blink 1.06s steps(1) infinite;
66 | animation: blink 1.06s steps(1) infinite;
67 | }
68 | @-moz-keyframes blink {
69 | 0% { background: #7e7; }
70 | 50% { background: none; }
71 | 100% { background: #7e7; }
72 | }
73 | @-webkit-keyframes blink {
74 | 0% { background: #7e7; }
75 | 50% { background: none; }
76 | 100% { background: #7e7; }
77 | }
78 | @keyframes blink {
79 | 0% { background: #7e7; }
80 | 50% { background: none; }
81 | 100% { background: #7e7; }
82 | }
83 |
84 | /* Can style cursor different in overwrite (non-insert) mode */
85 | div.CodeMirror-overwrite div.CodeMirror-cursor {}
86 |
87 | .cm-tab { display: inline-block; text-decoration: inherit; }
88 |
89 | .CodeMirror-ruler {
90 | border-left: 1px solid #ccc;
91 | position: absolute;
92 | }
93 |
94 | /* DEFAULT THEME */
95 |
96 | .cm-s-default .cm-keyword {color: #708;}
97 | .cm-s-default .cm-atom {color: #219;}
98 | .cm-s-default .cm-number {color: #164;}
99 | .cm-s-default .cm-def {color: #00f;}
100 | .cm-s-default .cm-variable,
101 | .cm-s-default .cm-punctuation,
102 | .cm-s-default .cm-property,
103 | .cm-s-default .cm-operator {}
104 | .cm-s-default .cm-variable-2 {color: #05a;}
105 | .cm-s-default .cm-variable-3 {color: #085;}
106 | .cm-s-default .cm-comment {color: #a50;}
107 | .cm-s-default .cm-string {color: #a11;}
108 | .cm-s-default .cm-string-2 {color: #f50;}
109 | .cm-s-default .cm-meta {color: #555;}
110 | .cm-s-default .cm-qualifier {color: #555;}
111 | .cm-s-default .cm-builtin {color: #30a;}
112 | .cm-s-default .cm-bracket {color: #997;}
113 | .cm-s-default .cm-tag {color: #170;}
114 | .cm-s-default .cm-attribute {color: #00c;}
115 | .cm-s-default .cm-header {color: blue;}
116 | .cm-s-default .cm-quote {color: #090;}
117 | .cm-s-default .cm-hr {color: #999;}
118 | .cm-s-default .cm-link {color: #00c;}
119 |
120 | .cm-negative {color: #d44;}
121 | .cm-positive {color: #292;}
122 | .cm-header, .cm-strong {font-weight: bold;}
123 | .cm-em {font-style: italic;}
124 | .cm-link {text-decoration: underline;}
125 | .cm-strikethrough {text-decoration: line-through;}
126 |
127 | .cm-s-default .cm-error {color: #f00;}
128 | .cm-invalidchar {color: #f00;}
129 |
130 | /* Default styles for common addons */
131 |
132 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
133 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
134 | .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
135 | .CodeMirror-activeline-background {background: #e8f2ff;}
136 |
137 | /* STOP */
138 |
139 | /* The rest of this file contains styles related to the mechanics of
140 | the editor. You probably shouldn't touch them. */
141 |
142 | .CodeMirror {
143 | position: relative;
144 | overflow: hidden;
145 | background: white;
146 | }
147 |
148 | .CodeMirror-scroll {
149 | overflow: scroll !important; /* Things will break if this is overridden */
150 | /* 30px is the magic margin used to hide the element's real scrollbars */
151 | /* See overflow: hidden in .CodeMirror */
152 | margin-bottom: -30px; margin-right: -30px;
153 | padding-bottom: 30px;
154 | height: 100%;
155 | outline: none; /* Prevent dragging from highlighting the element */
156 | position: relative;
157 | -moz-box-sizing: content-box;
158 | box-sizing: content-box;
159 | }
160 | .CodeMirror-sizer {
161 | position: relative;
162 | border-right: 30px solid transparent;
163 | -moz-box-sizing: content-box;
164 | box-sizing: content-box;
165 | }
166 |
167 | /* The fake, visible scrollbars. Used to force redraw during scrolling
168 | before actuall scrolling happens, thus preventing shaking and
169 | flickering artifacts. */
170 | .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
171 | position: absolute;
172 | z-index: 6;
173 | display: none;
174 | }
175 | .CodeMirror-vscrollbar {
176 | right: 0; top: 0;
177 | overflow-x: hidden;
178 | overflow-y: scroll;
179 | }
180 | .CodeMirror-hscrollbar {
181 | bottom: 0; left: 0;
182 | overflow-y: hidden;
183 | overflow-x: scroll;
184 | }
185 | .CodeMirror-scrollbar-filler {
186 | right: 0; bottom: 0;
187 | }
188 | .CodeMirror-gutter-filler {
189 | left: 0; bottom: 0;
190 | }
191 |
192 | .CodeMirror-gutters {
193 | position: absolute; left: 0; top: 0;
194 | z-index: 3;
195 | }
196 | .CodeMirror-gutter {
197 | white-space: normal;
198 | height: 100%;
199 | -moz-box-sizing: content-box;
200 | box-sizing: content-box;
201 | display: inline-block;
202 | margin-bottom: -30px;
203 | /* Hack to make IE7 behave */
204 | *zoom:1;
205 | *display:inline;
206 | }
207 | .CodeMirror-gutter-wrapper {
208 | position: absolute;
209 | z-index: 4;
210 | height: 100%;
211 | }
212 | .CodeMirror-gutter-elt {
213 | position: absolute;
214 | cursor: default;
215 | z-index: 4;
216 | }
217 | .CodeMirror-gutter-wrapper {
218 | -webkit-user-select: none;
219 | -moz-user-select: none;
220 | user-select: none;
221 | }
222 |
223 | .CodeMirror-lines {
224 | cursor: text;
225 | min-height: 1px; /* prevents collapsing before first draw */
226 | }
227 | .CodeMirror pre {
228 | /* Reset some styles that the rest of the page might have set */
229 | -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
230 | border-width: 0;
231 | background: transparent;
232 | font-family: inherit;
233 | font-size: inherit;
234 | margin: 0;
235 | white-space: pre;
236 | word-wrap: normal;
237 | line-height: inherit;
238 | color: inherit;
239 | z-index: 2;
240 | position: relative;
241 | overflow: visible;
242 | -webkit-tap-highlight-color: transparent;
243 | }
244 | .CodeMirror-wrap pre {
245 | word-wrap: break-word;
246 | white-space: pre-wrap;
247 | word-break: normal;
248 | }
249 |
250 | .CodeMirror-linebackground {
251 | position: absolute;
252 | left: 0; right: 0; top: 0; bottom: 0;
253 | z-index: 0;
254 | }
255 |
256 | .CodeMirror-linewidget {
257 | position: relative;
258 | z-index: 2;
259 | overflow: auto;
260 | }
261 |
262 | .CodeMirror-widget {}
263 |
264 | .CodeMirror-code {
265 | outline: none;
266 | }
267 |
268 | .CodeMirror-measure {
269 | position: absolute;
270 | width: 100%;
271 | height: 0;
272 | overflow: hidden;
273 | visibility: hidden;
274 | }
275 | .CodeMirror-measure pre { position: static; }
276 |
277 | .CodeMirror div.CodeMirror-cursor {
278 | position: absolute;
279 | border-right: none;
280 | width: 0;
281 | }
282 |
283 | div.CodeMirror-cursors {
284 | visibility: hidden;
285 | position: relative;
286 | z-index: 3;
287 | }
288 | .CodeMirror-focused div.CodeMirror-cursors {
289 | visibility: visible;
290 | }
291 |
292 | .CodeMirror-selected { background: #d9d9d9; }
293 | .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
294 | .CodeMirror-crosshair { cursor: crosshair; }
295 | .CodeMirror ::selection { background: #d7d4f0; }
296 | .CodeMirror ::-moz-selection { background: #d7d4f0; }
297 |
298 | .cm-searching {
299 | background: #ffa;
300 | background: rgba(255, 255, 0, .4);
301 | }
302 |
303 | /* IE7 hack to prevent it from returning funny offsetTops on the spans */
304 | .CodeMirror span { *vertical-align: text-bottom; }
305 |
306 | /* Used to force a border model for a node */
307 | .cm-force-border { padding-right: .1px; }
308 |
309 | @media print {
310 | /* Hide the cursor when printing */
311 | .CodeMirror div.CodeMirror-cursors {
312 | visibility: hidden;
313 | }
314 | }
315 |
316 | /* See issue #2901 */
317 | .cm-tab-wrap-hack:after { content: ''; }
318 |
319 | /* Help users use markselection to safely style text background */
320 | span.CodeMirror-selectedtext { background: none; }
321 |
--------------------------------------------------------------------------------
/components/codeEditor/styles/codemirror/themes/vibrant-ink.css:
--------------------------------------------------------------------------------
1 | /* Taken from the popular Visual Studio Vibrant Ink Schema */
2 |
3 | .cm-s-vibrant-ink.CodeMirror { background: black; color: white; }
4 | .cm-s-vibrant-ink .CodeMirror-selected { background: #35493c !important; }
5 | .cm-s-vibrant-ink.CodeMirror ::selection { background: rgba(53, 73, 60, 0.99); }
6 | .cm-s-vibrant-ink.CodeMirror ::-moz-selection { background: rgba(53, 73, 60, 0.99); }
7 |
8 | .cm-s-vibrant-ink .CodeMirror-gutters { background: #002240; border-right: 1px solid #aaa; }
9 | .cm-s-vibrant-ink .CodeMirror-guttermarker { color: white; }
10 | .cm-s-vibrant-ink .CodeMirror-guttermarker-subtle { color: #d0d0d0; }
11 | .cm-s-vibrant-ink .CodeMirror-linenumber { color: #d0d0d0; }
12 | .cm-s-vibrant-ink .CodeMirror-cursor { border-left: 1px solid white !important; }
13 |
14 | .cm-s-vibrant-ink .cm-keyword { color: #CC7832; }
15 | .cm-s-vibrant-ink .cm-atom { color: #FC0; }
16 | .cm-s-vibrant-ink .cm-number { color: #FFEE98; }
17 | .cm-s-vibrant-ink .cm-def { color: #8DA6CE; }
18 | .cm-s-vibrant-ink span.cm-variable-2, .cm-s-vibrant span.cm-tag { color: #FFC66D }
19 | .cm-s-vibrant-ink span.cm-variable-3, .cm-s-vibrant span.cm-def { color: #FFC66D }
20 | .cm-s-vibrant-ink .cm-operator { color: #888; }
21 | .cm-s-vibrant-ink .cm-comment { color: gray; font-weight: bold; }
22 | .cm-s-vibrant-ink .cm-string { color: #A5C25C }
23 | .cm-s-vibrant-ink .cm-string-2 { color: red }
24 | .cm-s-vibrant-ink .cm-meta { color: #D8FA3C; }
25 | .cm-s-vibrant-ink .cm-builtin { color: #8DA6CE; }
26 | .cm-s-vibrant-ink .cm-tag { color: #8DA6CE; }
27 | .cm-s-vibrant-ink .cm-attribute { color: #8DA6CE; }
28 | .cm-s-vibrant-ink .cm-header { color: #FF6400; }
29 | .cm-s-vibrant-ink .cm-hr { color: #AEAEAE; }
30 | .cm-s-vibrant-ink .cm-link { color: blue; }
31 | .cm-s-vibrant-ink .cm-error { border-bottom: 1px solid red; }
32 |
33 | .cm-s-vibrant-ink .CodeMirror-activeline-background {background: #27282E !important;}
34 | .cm-s-vibrant-ink .CodeMirror-matchingbracket {outline:1px solid grey; color:white !important;}
35 |
--------------------------------------------------------------------------------
/components/codeEditor/vendor/codemirror/modes/javascript/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | CodeMirror: JavaScript mode
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
27 |
28 |
29 | JavaScript mode
30 |
31 |
32 |
81 |
82 |
90 |
91 |
92 | JavaScript mode supports several configuration options:
93 |
94 | json
which will set the mode to expect JSON
95 | data rather than a JavaScript program.
96 | jsonld
which will set the mode to expect
97 | JSON-LD linked data rather
98 | than a JavaScript program (demo ).
99 | typescript
which will activate additional
100 | syntax highlighting and some other things for TypeScript code
101 | (demo ).
102 | statementIndent
which (given a number) will
103 | determine the amount of indentation to use for statements
104 | continued on a new line.
105 | wordCharacters
, a regexp that indicates which
106 | characters should be considered part of an identifier.
107 | Defaults to /[\w$]/
, which does not handle
108 | non-ASCII identifiers. Can be set to something more elaborate
109 | to improve Unicode support.
110 |
111 |
112 |
113 | MIME types defined: text/javascript
, application/json
, application/ld+json
, text/typescript
, application/typescript
.
114 |
115 |
--------------------------------------------------------------------------------
/components/codeEditor/vendor/codemirror/modes/javascript/javascript.js:
--------------------------------------------------------------------------------
1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 | // Distributed under an MIT license: http://codemirror.net/LICENSE
3 |
4 | // TODO actually recognize syntax of TypeScript constructs
5 |
6 | (function(mod) {
7 | if (typeof exports == "object" && typeof module == "object") // CommonJS
8 | mod(require("../../lib/codemirror"));
9 | else if (typeof define == "function" && define.amd) // AMD
10 | define(["../../lib/codemirror"], mod);
11 | else // Plain browser env
12 | mod(CodeMirror);
13 | })(function(CodeMirror) {
14 | "use strict";
15 |
16 | CodeMirror.defineMode("javascript", function(config, parserConfig) {
17 | var indentUnit = config.indentUnit;
18 | var statementIndent = parserConfig.statementIndent;
19 | var jsonldMode = parserConfig.jsonld;
20 | var jsonMode = parserConfig.json || jsonldMode;
21 | var isTS = parserConfig.typescript;
22 | var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
23 |
24 | // Tokenizer
25 |
26 | var keywords = function(){
27 | function kw(type) {return {type: type, style: "keyword"};}
28 | var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
29 | var operator = kw("operator"), atom = {type: "atom", style: "atom"};
30 |
31 | var jsKeywords = {
32 | "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
33 | "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, "debugger": C,
34 | "var": kw("var"), "const": kw("var"), "let": kw("var"),
35 | "function": kw("function"), "catch": kw("catch"),
36 | "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
37 | "in": operator, "typeof": operator, "instanceof": operator,
38 | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
39 | "this": kw("this"), "module": kw("module"), "class": kw("class"), "super": kw("atom"),
40 | "yield": C, "export": kw("export"), "import": kw("import"), "extends": C
41 | };
42 |
43 | // Extend the 'normal' keywords with the TypeScript language extensions
44 | if (isTS) {
45 | var type = {type: "variable", style: "variable-3"};
46 | var tsKeywords = {
47 | // object-like things
48 | "interface": kw("interface"),
49 | "extends": kw("extends"),
50 | "constructor": kw("constructor"),
51 |
52 | // scope modifiers
53 | "public": kw("public"),
54 | "private": kw("private"),
55 | "protected": kw("protected"),
56 | "static": kw("static"),
57 |
58 | // types
59 | "string": type, "number": type, "bool": type, "any": type
60 | };
61 |
62 | for (var attr in tsKeywords) {
63 | jsKeywords[attr] = tsKeywords[attr];
64 | }
65 | }
66 |
67 | return jsKeywords;
68 | }();
69 |
70 | var isOperatorChar = /[+\-*&%=<>!?|~^]/;
71 | var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
72 |
73 | function readRegexp(stream) {
74 | var escaped = false, next, inSet = false;
75 | while ((next = stream.next()) != null) {
76 | if (!escaped) {
77 | if (next == "/" && !inSet) return;
78 | if (next == "[") inSet = true;
79 | else if (inSet && next == "]") inSet = false;
80 | }
81 | escaped = !escaped && next == "\\";
82 | }
83 | }
84 |
85 | // Used as scratch variables to communicate multiple values without
86 | // consing up tons of objects.
87 | var type, content;
88 | function ret(tp, style, cont) {
89 | type = tp; content = cont;
90 | return style;
91 | }
92 | function tokenBase(stream, state) {
93 | var ch = stream.next();
94 | if (ch == '"' || ch == "'") {
95 | state.tokenize = tokenString(ch);
96 | return state.tokenize(stream, state);
97 | } else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
98 | return ret("number", "number");
99 | } else if (ch == "." && stream.match("..")) {
100 | return ret("spread", "meta");
101 | } else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
102 | return ret(ch);
103 | } else if (ch == "=" && stream.eat(">")) {
104 | return ret("=>", "operator");
105 | } else if (ch == "0" && stream.eat(/x/i)) {
106 | stream.eatWhile(/[\da-f]/i);
107 | return ret("number", "number");
108 | } else if (/\d/.test(ch)) {
109 | stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
110 | return ret("number", "number");
111 | } else if (ch == "/") {
112 | if (stream.eat("*")) {
113 | state.tokenize = tokenComment;
114 | return tokenComment(stream, state);
115 | } else if (stream.eat("/")) {
116 | stream.skipToEnd();
117 | return ret("comment", "comment");
118 | } else if (state.lastType == "operator" || state.lastType == "keyword c" ||
119 | state.lastType == "sof" || /^[\[{}\(,;:]$/.test(state.lastType)) {
120 | readRegexp(stream);
121 | stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
122 | return ret("regexp", "string-2");
123 | } else {
124 | stream.eatWhile(isOperatorChar);
125 | return ret("operator", "operator", stream.current());
126 | }
127 | } else if (ch == "`") {
128 | state.tokenize = tokenQuasi;
129 | return tokenQuasi(stream, state);
130 | } else if (ch == "#") {
131 | stream.skipToEnd();
132 | return ret("error", "error");
133 | } else if (isOperatorChar.test(ch)) {
134 | stream.eatWhile(isOperatorChar);
135 | return ret("operator", "operator", stream.current());
136 | } else if (wordRE.test(ch)) {
137 | stream.eatWhile(wordRE);
138 | var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
139 | return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
140 | ret("variable", "variable", word);
141 | }
142 | }
143 |
144 | function tokenString(quote) {
145 | return function(stream, state) {
146 | var escaped = false, next;
147 | if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
148 | state.tokenize = tokenBase;
149 | return ret("jsonld-keyword", "meta");
150 | }
151 | while ((next = stream.next()) != null) {
152 | if (next == quote && !escaped) break;
153 | escaped = !escaped && next == "\\";
154 | }
155 | if (!escaped) state.tokenize = tokenBase;
156 | return ret("string", "string");
157 | };
158 | }
159 |
160 | function tokenComment(stream, state) {
161 | var maybeEnd = false, ch;
162 | while (ch = stream.next()) {
163 | if (ch == "/" && maybeEnd) {
164 | state.tokenize = tokenBase;
165 | break;
166 | }
167 | maybeEnd = (ch == "*");
168 | }
169 | return ret("comment", "comment");
170 | }
171 |
172 | function tokenQuasi(stream, state) {
173 | var escaped = false, next;
174 | while ((next = stream.next()) != null) {
175 | if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
176 | state.tokenize = tokenBase;
177 | break;
178 | }
179 | escaped = !escaped && next == "\\";
180 | }
181 | return ret("quasi", "string-2", stream.current());
182 | }
183 |
184 | var brackets = "([{}])";
185 | // This is a crude lookahead trick to try and notice that we're
186 | // parsing the argument patterns for a fat-arrow function before we
187 | // actually hit the arrow token. It only works if the arrow is on
188 | // the same line as the arguments and there's no strange noise
189 | // (comments) in between. Fallback is to only notice when we hit the
190 | // arrow, and not declare the arguments as locals for the arrow
191 | // body.
192 | function findFatArrow(stream, state) {
193 | if (state.fatArrowAt) state.fatArrowAt = null;
194 | var arrow = stream.string.indexOf("=>", stream.start);
195 | if (arrow < 0) return;
196 |
197 | var depth = 0, sawSomething = false;
198 | for (var pos = arrow - 1; pos >= 0; --pos) {
199 | var ch = stream.string.charAt(pos);
200 | var bracket = brackets.indexOf(ch);
201 | if (bracket >= 0 && bracket < 3) {
202 | if (!depth) { ++pos; break; }
203 | if (--depth == 0) break;
204 | } else if (bracket >= 3 && bracket < 6) {
205 | ++depth;
206 | } else if (wordRE.test(ch)) {
207 | sawSomething = true;
208 | } else if (/["'\/]/.test(ch)) {
209 | return;
210 | } else if (sawSomething && !depth) {
211 | ++pos;
212 | break;
213 | }
214 | }
215 | if (sawSomething && !depth) state.fatArrowAt = pos;
216 | }
217 |
218 | // Parser
219 |
220 | var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
221 |
222 | function JSLexical(indented, column, type, align, prev, info) {
223 | this.indented = indented;
224 | this.column = column;
225 | this.type = type;
226 | this.prev = prev;
227 | this.info = info;
228 | if (align != null) this.align = align;
229 | }
230 |
231 | function inScope(state, varname) {
232 | for (var v = state.localVars; v; v = v.next)
233 | if (v.name == varname) return true;
234 | for (var cx = state.context; cx; cx = cx.prev) {
235 | for (var v = cx.vars; v; v = v.next)
236 | if (v.name == varname) return true;
237 | }
238 | }
239 |
240 | function parseJS(state, style, type, content, stream) {
241 | var cc = state.cc;
242 | // Communicate our context to the combinators.
243 | // (Less wasteful than consing up a hundred closures on every call.)
244 | cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
245 |
246 | if (!state.lexical.hasOwnProperty("align"))
247 | state.lexical.align = true;
248 |
249 | while(true) {
250 | var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
251 | if (combinator(type, content)) {
252 | while(cc.length && cc[cc.length - 1].lex)
253 | cc.pop()();
254 | if (cx.marked) return cx.marked;
255 | if (type == "variable" && inScope(state, content)) return "variable-2";
256 | return style;
257 | }
258 | }
259 | }
260 |
261 | // Combinator utils
262 |
263 | var cx = {state: null, column: null, marked: null, cc: null};
264 | function pass() {
265 | for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
266 | }
267 | function cont() {
268 | pass.apply(null, arguments);
269 | return true;
270 | }
271 | function register(varname) {
272 | function inList(list) {
273 | for (var v = list; v; v = v.next)
274 | if (v.name == varname) return true;
275 | return false;
276 | }
277 | var state = cx.state;
278 | if (state.context) {
279 | cx.marked = "def";
280 | if (inList(state.localVars)) return;
281 | state.localVars = {name: varname, next: state.localVars};
282 | } else {
283 | if (inList(state.globalVars)) return;
284 | if (parserConfig.globalVars)
285 | state.globalVars = {name: varname, next: state.globalVars};
286 | }
287 | }
288 |
289 | // Combinators
290 |
291 | var defaultVars = {name: "this", next: {name: "arguments"}};
292 | function pushcontext() {
293 | cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
294 | cx.state.localVars = defaultVars;
295 | }
296 | function popcontext() {
297 | cx.state.localVars = cx.state.context.vars;
298 | cx.state.context = cx.state.context.prev;
299 | }
300 | function pushlex(type, info) {
301 | var result = function() {
302 | var state = cx.state, indent = state.indented;
303 | if (state.lexical.type == "stat") indent = state.lexical.indented;
304 | else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
305 | indent = outer.indented;
306 | state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
307 | };
308 | result.lex = true;
309 | return result;
310 | }
311 | function poplex() {
312 | var state = cx.state;
313 | if (state.lexical.prev) {
314 | if (state.lexical.type == ")")
315 | state.indented = state.lexical.indented;
316 | state.lexical = state.lexical.prev;
317 | }
318 | }
319 | poplex.lex = true;
320 |
321 | function expect(wanted) {
322 | function exp(type) {
323 | if (type == wanted) return cont();
324 | else if (wanted == ";") return pass();
325 | else return cont(exp);
326 | };
327 | return exp;
328 | }
329 |
330 | function statement(type, value) {
331 | if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
332 | if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
333 | if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
334 | if (type == "{") return cont(pushlex("}"), block, poplex);
335 | if (type == ";") return cont();
336 | if (type == "if") {
337 | if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
338 | cx.state.cc.pop()();
339 | return cont(pushlex("form"), expression, statement, poplex, maybeelse);
340 | }
341 | if (type == "function") return cont(functiondef);
342 | if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
343 | if (type == "variable") return cont(pushlex("stat"), maybelabel);
344 | if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
345 | block, poplex, poplex);
346 | if (type == "case") return cont(expression, expect(":"));
347 | if (type == "default") return cont(expect(":"));
348 | if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
349 | statement, poplex, popcontext);
350 | if (type == "module") return cont(pushlex("form"), pushcontext, afterModule, popcontext, poplex);
351 | if (type == "class") return cont(pushlex("form"), className, poplex);
352 | if (type == "export") return cont(pushlex("form"), afterExport, poplex);
353 | if (type == "import") return cont(pushlex("form"), afterImport, poplex);
354 | return pass(pushlex("stat"), expression, expect(";"), poplex);
355 | }
356 | function expression(type) {
357 | return expressionInner(type, false);
358 | }
359 | function expressionNoComma(type) {
360 | return expressionInner(type, true);
361 | }
362 | function expressionInner(type, noComma) {
363 | if (cx.state.fatArrowAt == cx.stream.start) {
364 | var body = noComma ? arrowBodyNoComma : arrowBody;
365 | if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
366 | else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
367 | }
368 |
369 | var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
370 | if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
371 | if (type == "function") return cont(functiondef, maybeop);
372 | if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
373 | if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop);
374 | if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
375 | if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
376 | if (type == "{") return contCommasep(objprop, "}", null, maybeop);
377 | if (type == "quasi") { return pass(quasi, maybeop); }
378 | return cont();
379 | }
380 | function maybeexpression(type) {
381 | if (type.match(/[;\}\)\],]/)) return pass();
382 | return pass(expression);
383 | }
384 | function maybeexpressionNoComma(type) {
385 | if (type.match(/[;\}\)\],]/)) return pass();
386 | return pass(expressionNoComma);
387 | }
388 |
389 | function maybeoperatorComma(type, value) {
390 | if (type == ",") return cont(expression);
391 | return maybeoperatorNoComma(type, value, false);
392 | }
393 | function maybeoperatorNoComma(type, value, noComma) {
394 | var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
395 | var expr = noComma == false ? expression : expressionNoComma;
396 | if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
397 | if (type == "operator") {
398 | if (/\+\+|--/.test(value)) return cont(me);
399 | if (value == "?") return cont(expression, expect(":"), expr);
400 | return cont(expr);
401 | }
402 | if (type == "quasi") { return pass(quasi, me); }
403 | if (type == ";") return;
404 | if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
405 | if (type == ".") return cont(property, me);
406 | if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
407 | }
408 | function quasi(type, value) {
409 | if (type != "quasi") return pass();
410 | if (value.slice(value.length - 2) != "${") return cont(quasi);
411 | return cont(expression, continueQuasi);
412 | }
413 | function continueQuasi(type) {
414 | if (type == "}") {
415 | cx.marked = "string-2";
416 | cx.state.tokenize = tokenQuasi;
417 | return cont(quasi);
418 | }
419 | }
420 | function arrowBody(type) {
421 | findFatArrow(cx.stream, cx.state);
422 | return pass(type == "{" ? statement : expression);
423 | }
424 | function arrowBodyNoComma(type) {
425 | findFatArrow(cx.stream, cx.state);
426 | return pass(type == "{" ? statement : expressionNoComma);
427 | }
428 | function maybelabel(type) {
429 | if (type == ":") return cont(poplex, statement);
430 | return pass(maybeoperatorComma, expect(";"), poplex);
431 | }
432 | function property(type) {
433 | if (type == "variable") {cx.marked = "property"; return cont();}
434 | }
435 | function objprop(type, value) {
436 | if (type == "variable" || cx.style == "keyword") {
437 | cx.marked = "property";
438 | if (value == "get" || value == "set") return cont(getterSetter);
439 | return cont(afterprop);
440 | } else if (type == "number" || type == "string") {
441 | cx.marked = jsonldMode ? "property" : (cx.style + " property");
442 | return cont(afterprop);
443 | } else if (type == "jsonld-keyword") {
444 | return cont(afterprop);
445 | } else if (type == "[") {
446 | return cont(expression, expect("]"), afterprop);
447 | }
448 | }
449 | function getterSetter(type) {
450 | if (type != "variable") return pass(afterprop);
451 | cx.marked = "property";
452 | return cont(functiondef);
453 | }
454 | function afterprop(type) {
455 | if (type == ":") return cont(expressionNoComma);
456 | if (type == "(") return pass(functiondef);
457 | }
458 | function commasep(what, end) {
459 | function proceed(type) {
460 | if (type == ",") {
461 | var lex = cx.state.lexical;
462 | if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
463 | return cont(what, proceed);
464 | }
465 | if (type == end) return cont();
466 | return cont(expect(end));
467 | }
468 | return function(type) {
469 | if (type == end) return cont();
470 | return pass(what, proceed);
471 | };
472 | }
473 | function contCommasep(what, end, info) {
474 | for (var i = 3; i < arguments.length; i++)
475 | cx.cc.push(arguments[i]);
476 | return cont(pushlex(end, info), commasep(what, end), poplex);
477 | }
478 | function block(type) {
479 | if (type == "}") return cont();
480 | return pass(statement, block);
481 | }
482 | function maybetype(type) {
483 | if (isTS && type == ":") return cont(typedef);
484 | }
485 | function typedef(type) {
486 | if (type == "variable"){cx.marked = "variable-3"; return cont();}
487 | }
488 | function vardef() {
489 | return pass(pattern, maybetype, maybeAssign, vardefCont);
490 | }
491 | function pattern(type, value) {
492 | if (type == "variable") { register(value); return cont(); }
493 | if (type == "[") return contCommasep(pattern, "]");
494 | if (type == "{") return contCommasep(proppattern, "}");
495 | }
496 | function proppattern(type, value) {
497 | if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
498 | register(value);
499 | return cont(maybeAssign);
500 | }
501 | if (type == "variable") cx.marked = "property";
502 | return cont(expect(":"), pattern, maybeAssign);
503 | }
504 | function maybeAssign(_type, value) {
505 | if (value == "=") return cont(expressionNoComma);
506 | }
507 | function vardefCont(type) {
508 | if (type == ",") return cont(vardef);
509 | }
510 | function maybeelse(type, value) {
511 | if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
512 | }
513 | function forspec(type) {
514 | if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
515 | }
516 | function forspec1(type) {
517 | if (type == "var") return cont(vardef, expect(";"), forspec2);
518 | if (type == ";") return cont(forspec2);
519 | if (type == "variable") return cont(formaybeinof);
520 | return pass(expression, expect(";"), forspec2);
521 | }
522 | function formaybeinof(_type, value) {
523 | if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
524 | return cont(maybeoperatorComma, forspec2);
525 | }
526 | function forspec2(type, value) {
527 | if (type == ";") return cont(forspec3);
528 | if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
529 | return pass(expression, expect(";"), forspec3);
530 | }
531 | function forspec3(type) {
532 | if (type != ")") cont(expression);
533 | }
534 | function functiondef(type, value) {
535 | if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
536 | if (type == "variable") {register(value); return cont(functiondef);}
537 | if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext);
538 | }
539 | function funarg(type) {
540 | if (type == "spread") return cont(funarg);
541 | return pass(pattern, maybetype);
542 | }
543 | function className(type, value) {
544 | if (type == "variable") {register(value); return cont(classNameAfter);}
545 | }
546 | function classNameAfter(type, value) {
547 | if (value == "extends") return cont(expression, classNameAfter);
548 | if (type == "{") return cont(pushlex("}"), classBody, poplex);
549 | }
550 | function classBody(type, value) {
551 | if (type == "variable" || cx.style == "keyword") {
552 | cx.marked = "property";
553 | if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody);
554 | return cont(functiondef, classBody);
555 | }
556 | if (value == "*") {
557 | cx.marked = "keyword";
558 | return cont(classBody);
559 | }
560 | if (type == ";") return cont(classBody);
561 | if (type == "}") return cont();
562 | }
563 | function classGetterSetter(type) {
564 | if (type != "variable") return pass();
565 | cx.marked = "property";
566 | return cont();
567 | }
568 | function afterModule(type, value) {
569 | if (type == "string") return cont(statement);
570 | if (type == "variable") { register(value); return cont(maybeFrom); }
571 | }
572 | function afterExport(_type, value) {
573 | if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
574 | if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
575 | return pass(statement);
576 | }
577 | function afterImport(type) {
578 | if (type == "string") return cont();
579 | return pass(importSpec, maybeFrom);
580 | }
581 | function importSpec(type, value) {
582 | if (type == "{") return contCommasep(importSpec, "}");
583 | if (type == "variable") register(value);
584 | return cont();
585 | }
586 | function maybeFrom(_type, value) {
587 | if (value == "from") { cx.marked = "keyword"; return cont(expression); }
588 | }
589 | function arrayLiteral(type) {
590 | if (type == "]") return cont();
591 | return pass(expressionNoComma, maybeArrayComprehension);
592 | }
593 | function maybeArrayComprehension(type) {
594 | if (type == "for") return pass(comprehension, expect("]"));
595 | if (type == ",") return cont(commasep(maybeexpressionNoComma, "]"));
596 | return pass(commasep(expressionNoComma, "]"));
597 | }
598 | function comprehension(type) {
599 | if (type == "for") return cont(forspec, comprehension);
600 | if (type == "if") return cont(expression, comprehension);
601 | }
602 |
603 | function isContinuedStatement(state, textAfter) {
604 | return state.lastType == "operator" || state.lastType == "," ||
605 | isOperatorChar.test(textAfter.charAt(0)) ||
606 | /[,.]/.test(textAfter.charAt(0));
607 | }
608 |
609 | // Interface
610 |
611 | return {
612 | startState: function(basecolumn) {
613 | var state = {
614 | tokenize: tokenBase,
615 | lastType: "sof",
616 | cc: [],
617 | lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
618 | localVars: parserConfig.localVars,
619 | context: parserConfig.localVars && {vars: parserConfig.localVars},
620 | indented: 0
621 | };
622 | if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
623 | state.globalVars = parserConfig.globalVars;
624 | return state;
625 | },
626 |
627 | token: function(stream, state) {
628 | if (stream.sol()) {
629 | if (!state.lexical.hasOwnProperty("align"))
630 | state.lexical.align = false;
631 | state.indented = stream.indentation();
632 | findFatArrow(stream, state);
633 | }
634 | if (state.tokenize != tokenComment && stream.eatSpace()) return null;
635 | var style = state.tokenize(stream, state);
636 | if (type == "comment") return style;
637 | state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
638 | return parseJS(state, style, type, content, stream);
639 | },
640 |
641 | indent: function(state, textAfter) {
642 | if (state.tokenize == tokenComment) return CodeMirror.Pass;
643 | if (state.tokenize != tokenBase) return 0;
644 | var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
645 | // Kludge to prevent 'maybelse' from blocking lexical scope pops
646 | if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
647 | var c = state.cc[i];
648 | if (c == poplex) lexical = lexical.prev;
649 | else if (c != maybeelse) break;
650 | }
651 | if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev;
652 | if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
653 | lexical = lexical.prev;
654 | var type = lexical.type, closing = firstChar == type;
655 |
656 | if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
657 | else if (type == "form" && firstChar == "{") return lexical.indented;
658 | else if (type == "form") return lexical.indented + indentUnit;
659 | else if (type == "stat")
660 | return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
661 | else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
662 | return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
663 | else if (lexical.align) return lexical.column + (closing ? 0 : 1);
664 | else return lexical.indented + (closing ? 0 : indentUnit);
665 | },
666 |
667 | electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
668 | blockCommentStart: jsonMode ? null : "/*",
669 | blockCommentEnd: jsonMode ? null : "*/",
670 | lineComment: jsonMode ? null : "//",
671 | fold: "brace",
672 |
673 | helperType: jsonMode ? "json" : "javascript",
674 | jsonldMode: jsonldMode,
675 | jsonMode: jsonMode
676 | };
677 | });
678 |
679 | CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
680 |
681 | CodeMirror.defineMIME("text/javascript", "javascript");
682 | CodeMirror.defineMIME("text/ecmascript", "javascript");
683 | CodeMirror.defineMIME("application/javascript", "javascript");
684 | CodeMirror.defineMIME("application/x-javascript", "javascript");
685 | CodeMirror.defineMIME("application/ecmascript", "javascript");
686 | CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
687 | CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
688 | CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
689 | CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
690 | CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
691 |
692 | });
693 |
--------------------------------------------------------------------------------
/components/codeEditor/vendor/codemirror/modes/javascript/json-ld.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | CodeMirror: JSON-LD mode
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
27 |
28 |
29 | JSON-LD mode
30 |
31 |
32 |
61 |
62 |
70 |
71 | This is a specialization of the JavaScript mode .
72 |
73 |
--------------------------------------------------------------------------------
/components/codeEditor/vendor/codemirror/modes/javascript/test.js:
--------------------------------------------------------------------------------
1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 | // Distributed under an MIT license: http://codemirror.net/LICENSE
3 |
4 | (function() {
5 | var mode = CodeMirror.getMode({indentUnit: 2}, "javascript");
6 | function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
7 |
8 | MT("locals",
9 | "[keyword function] [variable foo]([def a], [def b]) { [keyword var] [def c] [operator =] [number 10]; [keyword return] [variable-2 a] [operator +] [variable-2 c] [operator +] [variable d]; }");
10 |
11 | MT("comma-and-binop",
12 | "[keyword function](){ [keyword var] [def x] [operator =] [number 1] [operator +] [number 2], [def y]; }");
13 |
14 | MT("destructuring",
15 | "([keyword function]([def a], [[[def b], [def c] ]]) {",
16 | " [keyword let] {[def d], [property foo]: [def c][operator =][number 10], [def x]} [operator =] [variable foo]([variable-2 a]);",
17 | " [[[variable-2 c], [variable y] ]] [operator =] [variable-2 c];",
18 | "})();");
19 |
20 | MT("class_body",
21 | "[keyword class] [variable Foo] {",
22 | " [property constructor]() {}",
23 | " [property sayName]() {",
24 | " [keyword return] [string-2 `foo${][variable foo][string-2 }oo`];",
25 | " }",
26 | "}");
27 |
28 | MT("class",
29 | "[keyword class] [variable Point] [keyword extends] [variable SuperThing] {",
30 | " [property get] [property prop]() { [keyword return] [number 24]; }",
31 | " [property constructor]([def x], [def y]) {",
32 | " [keyword super]([string 'something']);",
33 | " [keyword this].[property x] [operator =] [variable-2 x];",
34 | " }",
35 | "}");
36 |
37 | MT("module",
38 | "[keyword module] [string 'foo'] {",
39 | " [keyword export] [keyword let] [def x] [operator =] [number 42];",
40 | " [keyword export] [keyword *] [keyword from] [string 'somewhere'];",
41 | "}");
42 |
43 | MT("import",
44 | "[keyword function] [variable foo]() {",
45 | " [keyword import] [def $] [keyword from] [string 'jquery'];",
46 | " [keyword module] [def crypto] [keyword from] [string 'crypto'];",
47 | " [keyword import] { [def encrypt], [def decrypt] } [keyword from] [string 'crypto'];",
48 | "}");
49 |
50 | MT("const",
51 | "[keyword function] [variable f]() {",
52 | " [keyword const] [[ [def a], [def b] ]] [operator =] [[ [number 1], [number 2] ]];",
53 | "}");
54 |
55 | MT("for/of",
56 | "[keyword for]([keyword let] [variable of] [keyword of] [variable something]) {}");
57 |
58 | MT("generator",
59 | "[keyword function*] [variable repeat]([def n]) {",
60 | " [keyword for]([keyword var] [def i] [operator =] [number 0]; [variable-2 i] [operator <] [variable-2 n]; [operator ++][variable-2 i])",
61 | " [keyword yield] [variable-2 i];",
62 | "}");
63 |
64 | MT("quotedStringAddition",
65 | "[keyword let] [variable f] [operator =] [variable a] [operator +] [string 'fatarrow'] [operator +] [variable c];");
66 |
67 | MT("quotedFatArrow",
68 | "[keyword let] [variable f] [operator =] [variable a] [operator +] [string '=>'] [operator +] [variable c];");
69 |
70 | MT("fatArrow",
71 | "[variable array].[property filter]([def a] [operator =>] [variable-2 a] [operator +] [number 1]);",
72 | "[variable a];", // No longer in scope
73 | "[keyword let] [variable f] [operator =] ([[ [def a], [def b] ]], [def c]) [operator =>] [variable-2 a] [operator +] [variable-2 c];",
74 | "[variable c];");
75 |
76 | MT("spread",
77 | "[keyword function] [variable f]([def a], [meta ...][def b]) {",
78 | " [variable something]([variable-2 a], [meta ...][variable-2 b]);",
79 | "}");
80 |
81 | MT("comprehension",
82 | "[keyword function] [variable f]() {",
83 | " [[([variable x] [operator +] [number 1]) [keyword for] ([keyword var] [def x] [keyword in] [variable y]) [keyword if] [variable pred]([variable-2 x]) ]];",
84 | " ([variable u] [keyword for] ([keyword var] [def u] [keyword of] [variable generateValues]()) [keyword if] ([variable-2 u].[property color] [operator ===] [string 'blue']));",
85 | "}");
86 |
87 | MT("quasi",
88 | "[variable re][string-2 `fofdlakj${][variable x] [operator +] ([variable re][string-2 `foo`]) [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]");
89 |
90 | MT("quasi_no_function",
91 | "[variable x] [operator =] [string-2 `fofdlakj${][variable x] [operator +] [string-2 `foo`] [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]");
92 |
93 | MT("indent_statement",
94 | "[keyword var] [variable x] [operator =] [number 10]",
95 | "[variable x] [operator +=] [variable y] [operator +]",
96 | " [atom Infinity]",
97 | "[keyword debugger];");
98 |
99 | MT("indent_if",
100 | "[keyword if] ([number 1])",
101 | " [keyword break];",
102 | "[keyword else] [keyword if] ([number 2])",
103 | " [keyword continue];",
104 | "[keyword else]",
105 | " [number 10];",
106 | "[keyword if] ([number 1]) {",
107 | " [keyword break];",
108 | "} [keyword else] [keyword if] ([number 2]) {",
109 | " [keyword continue];",
110 | "} [keyword else] {",
111 | " [number 10];",
112 | "}");
113 |
114 | MT("indent_for",
115 | "[keyword for] ([keyword var] [variable i] [operator =] [number 0];",
116 | " [variable i] [operator <] [number 100];",
117 | " [variable i][operator ++])",
118 | " [variable doSomething]([variable i]);",
119 | "[keyword debugger];");
120 |
121 | MT("indent_c_style",
122 | "[keyword function] [variable foo]()",
123 | "{",
124 | " [keyword debugger];",
125 | "}");
126 |
127 | MT("indent_else",
128 | "[keyword for] (;;)",
129 | " [keyword if] ([variable foo])",
130 | " [keyword if] ([variable bar])",
131 | " [number 1];",
132 | " [keyword else]",
133 | " [number 2];",
134 | " [keyword else]",
135 | " [number 3];");
136 |
137 | MT("indent_funarg",
138 | "[variable foo]([number 10000],",
139 | " [keyword function]([def a]) {",
140 | " [keyword debugger];",
141 | "};");
142 |
143 | MT("indent_below_if",
144 | "[keyword for] (;;)",
145 | " [keyword if] ([variable foo])",
146 | " [number 1];",
147 | "[number 2];");
148 |
149 | MT("multilinestring",
150 | "[keyword var] [variable x] [operator =] [string 'foo\\]",
151 | "[string bar'];");
152 |
153 | MT("scary_regexp",
154 | "[string-2 /foo[[/]]bar/];");
155 |
156 | MT("indent_strange_array",
157 | "[keyword var] [variable x] [operator =] [[",
158 | " [number 1],,",
159 | " [number 2],",
160 | "]];",
161 | "[number 10];");
162 |
163 | var jsonld_mode = CodeMirror.getMode(
164 | {indentUnit: 2},
165 | {name: "javascript", jsonld: true}
166 | );
167 | function LD(name) {
168 | test.mode(name, jsonld_mode, Array.prototype.slice.call(arguments, 1));
169 | }
170 |
171 | LD("json_ld_keywords",
172 | '{',
173 | ' [meta "@context"]: {',
174 | ' [meta "@base"]: [string "http://example.com"],',
175 | ' [meta "@vocab"]: [string "http://xmlns.com/foaf/0.1/"],',
176 | ' [property "likesFlavor"]: {',
177 | ' [meta "@container"]: [meta "@list"]',
178 | ' [meta "@reverse"]: [string "@beFavoriteOf"]',
179 | ' },',
180 | ' [property "nick"]: { [meta "@container"]: [meta "@set"] },',
181 | ' [property "nick"]: { [meta "@container"]: [meta "@index"] }',
182 | ' },',
183 | ' [meta "@graph"]: [[ {',
184 | ' [meta "@id"]: [string "http://dbpedia.org/resource/John_Lennon"],',
185 | ' [property "name"]: [string "John Lennon"],',
186 | ' [property "modified"]: {',
187 | ' [meta "@value"]: [string "2010-05-29T14:17:39+02:00"],',
188 | ' [meta "@type"]: [string "http://www.w3.org/2001/XMLSchema#dateTime"]',
189 | ' }',
190 | ' } ]]',
191 | '}');
192 |
193 | LD("json_ld_fake",
194 | '{',
195 | ' [property "@fake"]: [string "@fake"],',
196 | ' [property "@contextual"]: [string "@identifier"],',
197 | ' [property "user@domain.com"]: [string "@graphical"],',
198 | ' [property "@ID"]: [string "@@ID"]',
199 | '}');
200 | })();
201 |
--------------------------------------------------------------------------------
/components/codeEditor/vendor/codemirror/modes/javascript/typescript.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | CodeMirror: TypeScript mode
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
24 |
25 |
26 | TypeScript mode
27 |
28 |
29 |
51 |
52 |
59 |
60 | This is a specialization of the JavaScript mode .
61 |
62 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Posts
4 |
5 |
6 |
7 | var sum = function (a, b) {
8 | return a + b;
9 | }
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "express": "^4.12.2"
4 | },
5 | "scripts": {
6 | "start": "node server.js"
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Code Editor Directive
2 |
3 | This is demo code for the blog post on blog.codeschool.com
4 |
5 | ## Running the sample server
6 | You can run the simple node based server by running the following commands.
7 | ```
8 | npm install
9 | npm start
10 | ```
11 |
12 | visit [http://localhost:8888](http://localhost:8888) in your browser.
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | // To run type the following into the console.
2 |
3 | var express = require('express');
4 | var app = express();
5 | app.use("/", express.static("./"));
6 |
7 | // Start the server
8 | var server = app.listen(8000, function() {
9 | console.log('Listening on port %d', server.address().port);
10 | });
11 |
--------------------------------------------------------------------------------
/vendor/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeschool/CodeEditorDirectiveExample/86e9c1c4a70ee56c5c5e67346f68f2dbfef75d8a/vendor/.DS_Store
--------------------------------------------------------------------------------