Procházet zdrojové kódy

Wed IDE加载优化

xuxueli před 7 roky
rodič
revize
48d30d7750

+ 23 - 5
xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/jobcode.index.ftl Zobrazit soubor

@@ -109,16 +109,34 @@
109 109
     </div>
110 110
 	
111 111
 <@netCommon.commonScript />
112
+
113
+
114
+    <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" />
115
+    <#assign glueTypeIdeMode = "text/x-java" />
116
+
117
+    <#if jobInfo.glueType == "GLUE_GROOVY" >
118
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js" />
119
+        <#assign glueTypeIdeMode = "text/x-java" />
120
+    <#elseif jobInfo.glueType == "GLUE_SHELL" >
121
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/shell/shell.js" />
122
+        <#assign glueTypeIdeMode = "text/x-sh" />
123
+    <#elseif jobInfo.glueType == "GLUE_PYTHON" >
124
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/python/python.js" />
125
+        <#assign glueTypeIdeMode = "text/x-python" />
126
+    <#elseif jobInfo.glueType == "GLUE_NODEJS" >
127
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/javascript/javascript.js" />
128
+        <#assign glueTypeIdeMode = "text/javascript" />
129
+    </#if>
130
+
131
+
112 132
 <script src="${request.contextPath}/static/plugins/codemirror/lib/codemirror.js"></script>
113
-<script src="${request.contextPath}/static/plugins/codemirror/mode/clike/clike.js"></script>
114
-<script src="${request.contextPath}/static/plugins/codemirror/mode/shell/shell.js"></script>
115
-<script src="${request.contextPath}/static/plugins/codemirror/mode/python/python.js"></script>
116
-<script src="${request.contextPath}/static/plugins/codemirror/mode/javascript/javascript.js"></script>
133
+<script src="${glueTypeModeSrc}"></script>
117 134
 <script src="${request.contextPath}/static/plugins/codemirror/addon/hint/show-hint.js"></script>
118 135
 <script src="${request.contextPath}/static/plugins/codemirror/addon/hint/anyword-hint.js"></script>
136
+
119 137
 <script>
120 138
 var id = '${jobInfo.id}';
121
-var glueType = '${jobInfo.glueType}';
139
+var ideMode = '${glueTypeIdeMode}';
122 140
 </script>
123 141
 <script src="${request.contextPath}/static/js/jobcode.index.1.js"></script>
124 142
 

+ 13 - 21
xxl-job-admin/src/main/webapp/static/js/jobcode.index.1.js Zobrazit soubor

@@ -8,36 +8,28 @@ $(function() {
8 8
 	});*/
9 9
 
10 10
 	var codeEditor;
11
-	function initIde(glueType, glueSource) {
12
-		var ideMode = "text/x-java";
13
-		if ('GLUE_GROOVY'==glueType){
14
-			ideMode = "text/x-java";
15
-		} else if ('GLUE_SHELL'==glueType){
16
-			ideMode = "text/x-sh";
17
-		} else if ('GLUE_PYTHON'==glueType){
18
-			ideMode = "text/x-python";
19
-		} else if ('GLUE_NODEJS'==glueType){
20
-			ideMode = "text/javascript"
11
+	function initIde(glueSource) {
12
+		if (codeEditor == null) {
13
+            codeEditor = CodeMirror(document.getElementById("ideWindow"), {
14
+                mode : ideMode,
15
+                lineNumbers : true,
16
+                matchBrackets : true,
17
+                value: glueSource
18
+            });
19
+		} else {
20
+            codeEditor.setValue(glueSource);
21 21
 		}
22
-
23
-		codeEditor = CodeMirror(document.getElementById("ideWindow"), {
24
-			mode : ideMode,
25
-			lineNumbers : true,
26
-			matchBrackets : true,
27
-			value: glueSource
28
-		});
29 22
 	}
30 23
 
31
-	initIde(glueType, $("#version_now").val());
24
+	initIde($("#version_now").val());
32 25
 
33 26
 	// code change
34 27
 	$(".source_version").click(function(){
35
-		var glueType = $(this).attr('glueType');
36 28
 		var sourceId = $(this).attr('version');
37 29
 		var temp = $( "#" + sourceId ).val();
38 30
 
39
-		codeEditor.setValue('');
40
-		initIde(glueType, temp);
31
+		//codeEditor.setValue('');
32
+		initIde(temp);
41 33
 	});
42 34
 
43 35
 	// code source save

+ 32 - 65
xxl-job-admin/src/main/webapp/static/plugins/codemirror/mode/javascript/javascript.js Zobrazit soubor

@@ -11,6 +11,11 @@
11 11
 })(function(CodeMirror) {
12 12
 "use strict";
13 13
 
14
+function expressionAllowed(stream, state, backUp) {
15
+  return /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
16
+    (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
17
+}
18
+
14 19
 CodeMirror.defineMode("javascript", function(config, parserConfig) {
15 20
   var indentUnit = config.indentUnit;
16 21
   var statementIndent = parserConfig.statementIndent;
@@ -36,12 +41,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
36 41
       "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
37 42
       "this": kw("this"), "class": kw("class"), "super": kw("atom"),
38 43
       "yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
39
-      "await": C
44
+      "await": C, "async": kw("async")
40 45
     };
41 46
 
42 47
     // Extend the 'normal' keywords with the TypeScript language extensions
43 48
     if (isTS) {
44
-      var type = {type: "variable", style: "type"};
49
+      var type = {type: "variable", style: "variable-3"};
45 50
       var tsKeywords = {
46 51
         // object-like things
47 52
         "interface": kw("class"),
@@ -49,13 +54,16 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
49 54
         "namespace": C,
50 55
         "module": kw("module"),
51 56
         "enum": kw("module"),
57
+        "type": kw("type"),
52 58
 
53 59
         // scope modifiers
54 60
         "public": kw("modifier"),
55 61
         "private": kw("modifier"),
56 62
         "protected": kw("modifier"),
57 63
         "abstract": kw("modifier"),
58
-        "readonly": kw("modifier"),
64
+
65
+        // operators
66
+        "as": operator,
59 67
 
60 68
         // types
61 69
         "string": type, "number": type, "boolean": type, "any": type
@@ -143,16 +151,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
143 151
       return ret("operator", "operator", stream.current());
144 152
     } else if (wordRE.test(ch)) {
145 153
       stream.eatWhile(wordRE);
146
-      var word = stream.current()
147
-      if (state.lastType != ".") {
148
-        if (keywords.propertyIsEnumerable(word)) {
149
-          var kw = keywords[word]
150
-          return ret(kw.type, kw.style, word)
151
-        }
152
-        if (word == "async" && stream.match(/^\s*[\(\w]/, false))
153
-          return ret("async", "keyword", word)
154
-      }
155
-      return ret("variable", "variable", word)
154
+      var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
155
+      return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
156
+                     ret("variable", "variable", word);
156 157
     }
157 158
   }
158 159
 
@@ -360,18 +361,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
360 361
     }
361 362
     if (type == "function") return cont(functiondef);
362 363
     if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
363
-    if (type == "variable") {
364
-      if (isTS && value == "type") {
365
-        cx.marked = "keyword"
366
-        return cont(typeexpr, expect("operator"), typeexpr, expect(";"));
367
-      } if (isTS && value == "declare") {
368
-        cx.marked = "keyword"
369
-        return cont(statement)
370
-      } else {
371
-        return cont(pushlex("stat"), maybelabel);
372
-      }
373
-    }
374
-    if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"),
364
+    if (type == "variable") return cont(pushlex("stat"), maybelabel);
365
+    if (type == "switch") return cont(pushlex("form"), parenExpr, pushlex("}", "switch"), expect("{"),
375 366
                                       block, poplex, poplex);
376 367
     if (type == "case") return cont(expression, expect(":"));
377 368
     if (type == "default") return cont(expect(":"));
@@ -380,7 +371,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
380 371
     if (type == "class") return cont(pushlex("form"), className, poplex);
381 372
     if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
382 373
     if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
383
-    if (type == "module") return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
374
+    if (type == "module") return cont(pushlex("form"), pattern, pushlex("}"), expect("{"), block, poplex, poplex)
375
+    if (type == "type") return cont(typeexpr, expect("operator"), typeexpr, expect(";"));
384 376
     if (type == "async") return cont(statement)
385 377
     if (value == "@") return cont(expression, statement)
386 378
     return pass(pushlex("stat"), expression, expect(";"), poplex);
@@ -398,7 +390,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
398 390
   function expressionInner(type, noComma) {
399 391
     if (cx.state.fatArrowAt == cx.stream.start) {
400 392
       var body = noComma ? arrowBodyNoComma : arrowBody;
401
-      if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext);
393
+      if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
402 394
       else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
403 395
     }
404 396
 
@@ -433,7 +425,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
433 425
     var expr = noComma == false ? expression : expressionNoComma;
434 426
     if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
435 427
     if (type == "operator") {
436
-      if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me);
428
+      if (/\+\+|--/.test(value)) return cont(me);
437 429
       if (value == "?") return cont(expression, expect(":"), expr);
438 430
       return cont(expr);
439 431
     }
@@ -442,7 +434,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
442 434
     if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
443 435
     if (type == ".") return cont(property, me);
444 436
     if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
445
-    if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) }
446 437
   }
447 438
   function quasi(type, value) {
448 439
     if (type != "quasi") return pass();
@@ -467,7 +458,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
467 458
   function maybeTarget(noComma) {
468 459
     return function(type) {
469 460
       if (type == ".") return cont(noComma ? targetNoComma : target);
470
-      else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma)
471 461
       else return pass(noComma ? expressionNoComma : expression);
472 462
     };
473 463
   }
@@ -502,7 +492,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
502 492
     } else if (type == "[") {
503 493
       return cont(expression, expect("]"), afterprop);
504 494
     } else if (type == "spread") {
505
-      return cont(expression, afterprop);
495
+      return cont(expression);
506 496
     } else if (type == ":") {
507 497
       return pass(afterprop)
508 498
     }
@@ -549,19 +539,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
549 539
       if (value == "?") return cont(maybetype);
550 540
     }
551 541
   }
552
-  function typeexpr(type, value) {
553
-    if (type == "variable") {
554
-      if (value == "keyof") {
555
-        cx.marked = "keyword"
556
-        return cont(typeexpr)
557
-      } else {
558
-        cx.marked = "type"
559
-        return cont(afterType)
560
-      }
561
-    }
542
+  function typeexpr(type) {
543
+    if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
562 544
     if (type == "string" || type == "number" || type == "atom") return cont(afterType);
563
-    if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType)
564
-    if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
545
+    if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex)
565 546
     if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
566 547
   }
567 548
   function maybeReturnType(type) {
@@ -575,8 +556,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
575 556
       return cont(typeprop)
576 557
     } else if (type == ":") {
577 558
       return cont(typeexpr)
578
-    } else if (type == "[") {
579
-      return cont(expression, maybetype, expect("]"), typeprop)
580 559
     }
581 560
   }
582 561
   function typearg(type) {
@@ -587,10 +566,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
587 566
     if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
588 567
     if (value == "|" || type == ".") return cont(typeexpr)
589 568
     if (type == "[") return cont(expect("]"), afterType)
590
-    if (value == "extends") return cont(typeexpr)
591
-  }
592
-  function maybeTypeArgs(_, value) {
593
-    if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
594 569
   }
595 570
   function vardef() {
596 571
     return pass(pattern, maybetype, maybeAssign, vardefCont);
@@ -649,7 +624,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
649 624
     if (isTS && value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, functiondef)
650 625
   }
651 626
   function funarg(type) {
652
-    if (type == "spread" || type == "modifier") return cont(funarg);
627
+    if (type == "spread") return cont(funarg);
653 628
     return pass(pattern, maybetype, maybeAssign);
654 629
   }
655 630
   function classExpression(type, value) {
@@ -667,14 +642,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
667 642
     if (type == "{") return cont(pushlex("}"), classBody, poplex);
668 643
   }
669 644
   function classBody(type, value) {
670
-    if (type == "modifier" || type == "async" ||
671
-        (type == "variable" &&
672
-         (value == "static" || value == "get" || value == "set") &&
673
-         cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) {
674
-      cx.marked = "keyword";
675
-      return cont(classBody);
676
-    }
677 645
     if (type == "variable" || cx.style == "keyword") {
646
+      if ((value == "async" || value == "static" || value == "get" || value == "set" ||
647
+           (isTS && (value == "public" || value == "private" || value == "protected" || value == "readonly" || value == "abstract"))) &&
648
+          cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
649
+        cx.marked = "keyword";
650
+        return cont(classBody);
651
+      }
678 652
       cx.marked = "property";
679 653
       return cont(isTS ? classfield : functiondef, classBody);
680 654
     }
@@ -734,12 +708,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
734 708
       /[,.]/.test(textAfter.charAt(0));
735 709
   }
736 710
 
737
-  function expressionAllowed(stream, state, backUp) {
738
-    return state.tokenize == tokenBase &&
739
-      /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
740
-      (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
741
-  }
742
-
743 711
   // Interface
744 712
 
745 713
   return {
@@ -814,7 +782,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
814 782
     jsonMode: jsonMode,
815 783
 
816 784
     expressionAllowed: expressionAllowed,
817
-
818 785
     skipExpression: function(state) {
819 786
       var top = state.cc[state.cc.length - 1]
820 787
       if (top == expression || top == expressionNoComma) state.cc.pop()
@@ -835,4 +802,4 @@ CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true})
835 802
 CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
836 803
 CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
837 804
 
838
-});
805
+});