diff --git a/o2web/source/o2_core/o2.js b/o2web/source/o2_core/o2.js index c20e943605dc3771a8b05948f060b341e973e720..8bbc92a3a6db0f0e7fa1305bbd9197e23cd6a414 100644 --- a/o2web/source/o2_core/o2.js +++ b/o2web/source/o2_core/o2.js @@ -147,6 +147,7 @@ var MSXML = function(){ return new ActiveXObject('Microsoft.XMLHTTP'); }; return _attempt(XMLHTTP, MSXML2, MSXML); })(); + this.o2.request = _request; var _returnBase = function(number, base) { return (number).toString(base).toUpperCase(); @@ -290,13 +291,13 @@ _removeListener(xhr, 'load', _checkCssLoaded); _removeListener(xhr, 'error', _checkCssErrorLoaded); - if (err) {failure(xhr); return} + if (err) {if (failure) failure(xhr); return} var status = xhr.status; status = (status == 1223) ? 204 : status; if ((status >= 200 && status < 300)) - success(xhr); + if (success) success(xhr); else if ((status >= 300 && status < 400)) - failure(xhr); + if (failure) failure(xhr); else failure(xhr); if (completed) completed(xhr); @@ -308,7 +309,7 @@ _addListener(xhr, "readystatechange", _checkCssLoaded); xhr.send(); }; - + this.o2.xhr_get = _xhr_get; var _loadSequence = function(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun){ loadSingle(ms[n], function(module){ if (module) thisLoaded.push(module); @@ -343,7 +344,7 @@ "mootools": ["/o2_lib/mootools/mootools-1.6.0_all.js"], "ckeditor": ["/o2_lib/htmleditor/ckeditor4114/ckeditor.js"], "ckeditor5": ["/o2_lib/htmleditor/ckeditor5-12-1-0/ckeditor.js"], - "raphael": ["/o2_lib/raphael/raphael.js"], + "raphael": ["/o2_lib/raphael/raphael_230.js"], "d3": ["/o2_lib/d3/d3.min.js"], "ace": ["/o2_lib/ace/src-min-noconflict/ace.js","/o2_lib/ace/src-min-noconflict/ext-language_tools.js"], "monaco": ["/o2_lib/vs/loader.js"], diff --git a/o2web/source/o2_core/o2/widget/JavascriptEditor.js b/o2web/source/o2_core/o2/widget/JavascriptEditor.js index 13faec022b7cc515ec3215fcc12619b9cbcc5172..c0027c223b170d8f8162eed6e421fbc7dfd866e2 100644 --- a/o2web/source/o2_core/o2/widget/JavascriptEditor.js +++ b/o2web/source/o2_core/o2/widget/JavascriptEditor.js @@ -1,7 +1,5 @@ o2.widget = o2.widget || {}; o2.require("o2.widget.codemirror", null, false); -o2.require("o2.widget.ace", null, false); -o2.require("o2.widget.monaco", null, false); o2.require("o2.xDesktop.UserData", null, false); o2.widget.JavascriptEditor = new Class({ Implements: [Options, Events], @@ -14,12 +12,12 @@ o2.widget.JavascriptEditor = new Class({ value: "", mode: "javascript", "lineNumbers": true - } + }, + "runtime": "web" }, initialize: function(node, options){ this.setOptions(options); this.unbindEvents = []; - this.editorClass = o2.widget[this.options.type]; this.node = $(node); }, getDefaultEditorData: function(){ @@ -56,6 +54,7 @@ o2.widget.JavascriptEditor = new Class({ }, load: function(callback){ this.getEditorTheme(function(json){ + this.options.type = o2.editorData.javascriptEditor.editor || "monaco"; if (this.options.type.toLowerCase()=="ace"){ this.loadAce(callback); } @@ -73,6 +72,18 @@ o2.widget.JavascriptEditor = new Class({ }.bind(this)); }, + loadMonacoEditor: function(callback){ + if (!window.monaco){ + o2.load("monaco", {"sequence": true}, function(){ + require.config({ paths: { "vs": "/o2_lib/vs" }}); + require(["vs/editor/editor.main"], function() { + if (callback) callback(); + }); + }.bind(this)); + }else{ + if (callback) callback(); + } + }, loadMonaco: function(callback){ if (o2.editorData.javascriptEditor){ this.theme = o2.editorData.javascriptEditor.monaco_theme; @@ -86,104 +97,49 @@ o2.widget.JavascriptEditor = new Class({ if (!this.theme) this.theme = "vs"; if( !this.fontSize )this.fontSize = "12px"; - this.editorClass.load(function(){ - this.editor = monaco.editor.create(this.node, { - value: this.options.option.value, - language: this.options.option.mode, - theme: this.theme, - fontSize: this.fontSize, - lineNumbersMinChars: 3, - lineNumbers: (this.options.option.lineNumbers) ? "on" : "off", - mouseWheelZoom: true, - automaticLayout: true - }); - this.focus(); - - o2.require("o2.xScript.Macro", function() { - var json = null; - o2.getJSON("/o2_core/o2/widget/$JavascriptEditor/environment.json", function (data) { - json = data; - }, false); - this.Macro = new o2.Macro.FormContext(json); - - //registerReferenceProvider - //monaco.languages.registerReferenceProvider('javascript', { - monaco.languages.registerCompletionItemProvider('javascript', { - "triggerCharacters": ["."], - provideCompletionItems: function (model, position, context, token) { - debugger; - var textUntilPosition = model.getValueInRange({ - startLineNumber: position.lineNumber, - startColumn: 1, - endLineNumber: position.lineNumber, - endColumn: position.column - }); - var textPrefix = textUntilPosition.substr(0, textUntilPosition.lastIndexOf(".")); - code = "try {return "+textPrefix+";}catch(e){return null;}"; - //code = "try {return this;}catch(e){return null;}"; - var o = this.Macro.exec(code); - - var word = model.getWordUntilPosition(position); - var range = { - startLineNumber: position.lineNumber, - endLineNumber: position.lineNumber, - startColumn: word.startColumn, - endColumn: word.endColumn - }; - - if (o) { - var arr = []; - Object.keys(o).each(function (key) { - var type = typeOf(o[key]); - if (type === "function") { - var count = o[key].length; - var v = key + "("; - for (var i = 1; i <= count; i++) v += (i == count) ? "par" + i : "par" + i + ", "; - v += ")"; - arr.push({ - label: key, - kind: monaco.languages.CompletionItemKind.Function, - //documentation: "Fast, unopinionated, minimalist web framework", - insertText: v, - range: range, - detail: type - }); - } else { - arr.push({ - label: key, - kind: monaco.languages.CompletionItemKind.Interface, - //documentation: "Fast, unopinionated, minimalist web framework", - insertText: key, - range: range, - detail: type - }); - } - }); - } - return {suggestions: arr} - }.bind(this) + + o2.require("o2.widget.monaco", function () { + this.editorClass = o2.widget.monaco; + + this.editorClass.load(function(){ + + this.editor = monaco.editor.create(this.node, { + value: this.options.option.value, + language: this.options.option.mode, + theme: this.theme, + fontSize: this.fontSize, + lineNumbersMinChars: 3, + lineNumbers: this.options.option.lineNumbers ? "on" : "off", + mouseWheelZoom: true, + automaticLayout: true }); + this.focus(); - }); + this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function(e){ + this.fireEvent("save"); + }.bind(this)); - this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function(e){ - this.fireEvent("save"); - }.bind(this)); + this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Alt | monaco.KeyCode.KEY_I, function(e){ + this.format(); + }.bind(this)); + this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Alt | monaco.KeyCode.KEY_F, function(e){ + this.format(); + }.bind(this)); - this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Alt | monaco.KeyCode.KEY_I, function(e){ - this.format(); - }.bind(this)); - this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Alt | monaco.KeyCode.KEY_F, function(e){ - this.format(); - }.bind(this)); + if( this.fontSize ){ + this.editor.updateOptions( {"fontSize": this.fontSize} ); + } - if( this.fontSize ){ - this.editor.updateOptions( {"fontSize": this.fontSize} ); - } + o2.widget.JavascriptEditor.getCompletionEnvironment(this.options.runtime, function(){ + this.monacoModel = this.editor.getModel(); + this.monacoModel.o2Editor = this; + this.registerCompletion(); + }.bind(this)); - this.fireEvent("postLoad"); - if (callback) callback(); + this.fireEvent("postLoad"); + if (callback) callback(); + }.bind(this)); }.bind(this)); }, @@ -200,110 +156,201 @@ o2.widget.JavascriptEditor = new Class({ if (!this.theme) this.theme = "tomorrow"; if( !this.fontSize )this.fontSize = "12px"; - this.editorClass.load(function(){ - var exports = ace.require("ace/ext/language_tools"); - this.editor = ace.edit(this.node); - this.editor.session.setMode("ace/mode/"+this.options.option.mode); - this.editor.setTheme("ace/theme/"+this.theme); - this.editor.setOptions({ - enableBasicAutocompletion: true, - enableSnippets: true, - enableLiveAutocompletion: true, - lineNumbers: this.options.option.lineNumbers - }); - if (this.options.option.value) this.editor.setValue(this.options.option.value); + o2.require("o2.widget.ace", function(){ + this.editorClass = o2.widget.ace; + + this.editorClass.load(function(){ + this.editor = ace.edit(this.node); + this.editor.session.setMode("ace/mode/"+this.options.option.mode); + this.editor.setTheme("ace/theme/"+this.theme); + this.editor.setOptions({ + enableBasicAutocompletion: true, + enableSnippets: true, + enableLiveAutocompletion: true, + showLineNumbers: this.options.option.lineNumbers + }); + if (this.options.option.value) this.editor.setValue(this.options.option.value); + this.editor.o2Editor = this; + + this.focus(); + + this.editor.commands.addCommand({ + name: 'save', + bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, + exec: function(editor) { + this.fireEvent("save"); + }.bind(this), + readOnly: false + }); - this.focus(); + this.editor.commands.addCommand({ + name: 'format', + bindKey: {win: 'Ctrl-Alt-i|Ctrl-Alt-f', mac: 'Command-i|Command-f'}, + exec: function(editor, e, e1) { + this.format(); + }.bind(this), + readOnly: false + }); - //this.editor.focus(); - //this.editor.navigateFileStart(); - //添加自动完成列表 - o2.require("o2.xScript.Macro", function(){ - var json = null; - o2.getJSON("/o2_core/o2/widget/$JavascriptEditor/environment.json", function(data){ json = data; }, false); - this.Macro = new o2.Macro.FormContext(json); - exports.addCompleter({ - identifierRegexps: [ - /[a-zA-Z_0-9\$\-\u00A2-\uFFFF\.]/ - ], - getCompletions: function(editor, session, pos, prefix, callback){ - var x = prefix.substr(0, prefix.lastIndexOf(".")); - code = "try {return "+x+";}catch(e){return null;}"; - var o = this.Macro.exec(code); - - if (o){ - var arr1 = []; - var arr2 = []; - Object.keys(o).each(function(key){ - var type = typeOf(o[key]); - if (type==="function") { - var count = o[key].length; - var v = x+"."+key+"("; - for (var i=1; i<=count; i++) v+= (i==count) ? "par"+i : "par"+i+", "; - v+=");"; - arr1.push({ - caption: key, - value: v, - score: 3, - meta: type - }); - }else{ - arr2.push({ - caption: key, - value: x+"."+key, - score: 3, - meta: type - }); - } - }); - callback(null, arr1.concat(arr2)); - } + this.editor.commands.addCommand({ + name: "showKeyboardShortcuts", + bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"}, + exec: function(editor) { + ace.config.loadModule("ace/ext/keybinding_menu", function(module) { + module.init(editor); + editor.showKeyboardShortcuts() + }) }.bind(this) }); - }.bind(this)); - this.editor.commands.addCommand({ - name: 'save', - bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, - exec: function(editor) { - this.fireEvent("save"); - }.bind(this), - readOnly: false - }); + this.node.addEvent("keydown", function(e){ + e.stopPropagation(); + }); - this.editor.commands.addCommand({ - name: 'format', - bindKey: {win: 'Ctrl-Alt-i|Ctrl-Alt-f', mac: 'Command-i|Command-f'}, - exec: function(editor, e, e1) { - this.format(); - }.bind(this), - readOnly: false - }); + if( this.fontSize ){ + this.setFontSize( this.fontSize ); + } + + o2.widget.JavascriptEditor.getCompletionEnvironment(this.options.runtime, function(){ + this.registerCompletion(); + }.bind(this)); + + this.fireEvent("postLoad"); + if (callback) callback(); + }.bind(this)); + }.bind(this)); + }, + registerCompletion: function(){ + debugger; + if (this.editor){ + switch (this.options.type.toLowerCase()) { + case "ace": this.registerCompletionAce(); break; + case "monaco": this.registerCompletionMonaco(); break; + } + } + }, - this.editor.commands.addCommand({ - name: "showKeyboardShortcuts", - bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"}, - exec: function(editor) { - ace.config.loadModule("ace/ext/keybinding_menu", function(module) { - module.init(editor); - editor.showKeyboardShortcuts() - }) + getCompletionObject: function(textPrefix, runtime){ + var macro = o2.widget.JavascriptEditor.runtimeEnvironment[runtime]; + var o = null; + if (macro){ + code = "try {return "+textPrefix+";}catch(e){return null;}"; + o = macro.exec(code); + } + return o; + }, + registerCompletionMonaco: function(){ + if (!o2.widget.monaco.registeredCompletion){ + monaco.languages.registerCompletionItemProvider('javascript', { + "triggerCharacters": ["."], + provideCompletionItems: function (model, position, context, token) { + var textUntilPosition = model.getValueInRange({ startLineNumber: position.lineNumber, startColumn: 1, endLineNumber: position.lineNumber, endColumn: position.column }); + var textPrefix = textUntilPosition.substr(0, textUntilPosition.lastIndexOf(".")); + var o = this.getCompletionObject(textPrefix, model.o2Editor.options.runtime); + + var word = model.getWordUntilPosition(position); + var range = { startLineNumber: position.lineNumber, endLineNumber: position.lineNumber, startColumn: word.startColumn, endColumn: word.endColumn }; + + if (o) { + var arr = []; + Object.keys(o).each(function (key) { + var type = typeOf(o[key]); + if (type === "function") { + var count = o[key].length; + var v = key + "("; + for (var i = 1; i <= count; i++) v += (i == count) ? "par" + i : "par" + i + ", "; + v += ")"; + arr.push({ label: key, kind: monaco.languages.CompletionItemKind.Function, insertText: v, range: range, detail: type }); + } else { + arr.push({ label: key, kind: monaco.languages.CompletionItemKind.Interface, insertText: key, range: range, detail: type }); + } + }); + } + return {suggestions: arr} }.bind(this) }); - - this.node.addEvent("keydown", function(e){ - e.stopPropagation(); + o2.widget.monaco.registeredCompletion = true; + } + }, + registerCompletionAce: function(){ + if (!o2.widget.ace.registeredCompletion){ + //添加自动完成列表 + var exports = ace.require("ace/ext/language_tools"); + exports.addCompleter({ + identifierRegexps: [ + /[a-zA-Z_0-9\$\-\u00A2-\uFFFF\.]/ + ], + getCompletions: function(editor, session, pos, prefix, callback){ + var x = prefix.substr(0, prefix.lastIndexOf(".")); + var o = this.getCompletionObject(x, editor.o2Editor.options.runtime); + + if (o){ + var arr = []; + Object.keys(o).each(function(key){ + var type = typeOf(o[key]); + if (type==="function") { + var count = o[key].length; + var v = x+"."+key+"("; + for (var i=1; i<=count; i++) v+= (i==count) ? "par"+i : "par"+i+", "; + v+=");"; + arr.push({ caption: key, value: v, score: 3, meta: type }); + }else{ + arr.push({ caption: key, value: x+"."+key, score: 3, meta: type }); + } + }); + callback(null, arr); + } + }.bind(this) }); - - if( this.fontSize ){ - this.editor.setFontSize( this.fontSize ); + o2.widget.ace.registeredCompletion = true; + } + }, + changeEditor: function(type){ + debugger; + if (this.editor){ + var value = this.getValue(); + this.destroyEditor(); + this.options.type = type; + this.load(function(){ + this.setValue(value); + }.bind(this)); + }else{ + this.options.type = o2.editorData.javascriptEditor.editor; + if (this.options.type.toLowerCase()=="ace"){ + this.loadAce(callback); } - - this.fireEvent("postLoad"); - if (callback) callback(); - }.bind(this)); + if (this.options.type.toLowerCase()=="monaco"){ + this.loadMonaco(callback); + } + if (this.options.type.toLowerCase()=="codeMirror"){ + this.loadCodeMirror(callback); + } + } + }, + destroyEditor: function(){ + if (this.editor){ + switch (this.options.type.toLowerCase()) { + case "ace": this.editor.destroy(); this.node.empty(); break; + case "monaco": this.editor.dispose(); break; + } + } + }, + setTheme: function(theme){ + if (this.editor){ + switch (this.options.type.toLowerCase()) { + case "ace": this.editor.setTheme( "ace/theme/"+theme); break; + case "monaco": monaco.editor.setTheme(theme); break; + } + } + }, + setFontSize: function(fontSize){ + if (this.editor){ + switch (this.options.type.toLowerCase()) { + case "ace": this.editor.setFontSize( fontSize ); break; + case "monaco": this.editor.updateOptions({"fontSize": fontSize}); break; + } + } }, - setValue: function(v){ if (this.editor) this.editor.setValue(v); }, @@ -411,7 +458,33 @@ o2.widget.JavascriptEditor = new Class({ } this.editor.gotoLine(p.row+1, p.column+1, true); }, - + showLineNumbers: function(){ + if (this.editor){ + switch (this.options.type.toLowerCase()) { + case "ace": this.editor.setOption("showLineNumbers", true); break; + case "codeMirror": this.editor.setOption("lineNumbers", true); break; + case "monaco": this.editor.updateOptions({"lineNumbers": "on"}); + } + } + }, + hideLineNumbers: function(){ + if (this.editor){ + switch (this.options.type.toLowerCase()) { + case "ace": this.editor.setOption("showLineNumbers", false); break; + case "codeMirror": this.editor.setOption("lineNumbers", false); break; + case "monaco": this.editor.updateOptions({"lineNumbers": "off"}); + } + } + }, + max: function(){ + if (this.editor){ + switch (this.options.type.toLowerCase()) { + case "codeMirror": this.editor.setSize("100%", "100%"); break; + case "ace": this.editor.resize(); break; + case "monaco": this.editor.layout(); break; + } + } + }, loadCodeMirror: function(callback){ if (this.fireEvent("queryLoad")){ @@ -428,12 +501,6 @@ o2.widget.JavascriptEditor = new Class({ }.bind(this)); } }, - showLineNumbers: function(){ - if (this.options.type.toLowerCase()=="codeMirror") this.editor.setOption("lineNumbers", true); - }, - max: function(){ - if (this.options.type.toLowerCase()=="codeMirror") this.editor.setSize("100%", "100%"); - }, getCursorPixelPosition: function(){ var session = this.editor.getSession(); @@ -465,6 +532,83 @@ o2.widget.JavascriptEditor = new Class({ } return buf.reverse().join(""); } +}); + +o2.widget.JavascriptEditor.runtimeEnvironment = {}; +o2.widget.JavascriptEditor.getCompletionEnvironment = function(runtime, callback) { + if (!o2.widget.JavascriptEditor.runtimeEnvironment[runtime]) { + o2.require("o2.xScript.Macro", function() { + switch (runtime) { + case "service": + o2.widget.JavascriptEditor.getServiceCompletionEnvironment(runtime,callback); + break; + case "server": + o2.widget.JavascriptEditor.getServerCompletionEnvironment(runtime,callback); + break; + default: + o2.widget.JavascriptEditor.getDefaultCompletionEnvironment(runtime,callback); + } + }); + } else { + if (callback) callback(); + } +}; + +o2.widget.JavascriptEditor.getServiceCompletionEnvironment = function(runtime, callback) { + var serviceScriptText = null; + var serviceScriptSubstitute = null; + var check = function () { + if (o2.typeOf(serviceScriptText) !== "null" && o2.typeOf(serviceScriptSubstitute) !== "null") { + var code = "o2.Macro.swapSpace.tmpMacroCompletionFunction = function (){\n" + serviceScriptSubstitute + "\n" + serviceScriptText + "\nreturn bind;" + "\n};"; + Browser.exec(code); + var ev = o2.Macro.swapSpace.tmpMacroCompletionFunction(); + o2.widget.JavascriptEditor.runtimeEnvironment[runtime] = { + "environment": ev, + exec: function(code){ + return o2.Macro.exec(code, this.environment); + } + } + if (callback) callback(); + } + } - -}); \ No newline at end of file + o2.xhr_get("../x_desktop/js/initialServiceScriptText.js", function (xhr) { + serviceScriptText = xhr.responseText; + check(); + }, function () { + serviceScriptText = ""; + check(); + }); + o2.xhr_get("../x_desktop/js/initalServiceScriptSubstitute.js", function (xhr) { + serviceScriptSubstitute = xhr.responseText; + check(); + }, function () { + serviceScriptSubstitute = ""; + check(); + }); +}; + +o2.widget.JavascriptEditor.getServerCompletionEnvironment = function(runtime, callback) { + o2.xhr_get("../x_desktop/js/initialScriptText.js", function (xhr) { + var code = "o2.Macro.swapSpace.tmpMacroCompletionFunction = function (){\n" + xhr.responseText + "\nreturn bind;" + "\n};"; + Browser.exec(code); + var ev = o2.Macro.swapSpace.tmpMacroCompletionFunction(); + o2.widget.JavascriptEditor.runtimeEnvironment[runtime] = { + "environment": ev, + exec: function(code){ + return o2.Macro.exec(code, this.environment); + } + } + if (callback) callback(); + }.bind(this), false); + +}; + +o2.widget.JavascriptEditor.getDefaultCompletionEnvironment = function(runtime, callback){ + var json = null; + o2.getJSON("../o2_core/o2/widget/$JavascriptEditor/environment.json", function (data) { + json = data; + o2.widget.JavascriptEditor.runtimeEnvironment[runtime] = new o2.Macro.FormContext(json); + if (callback) callback(); + }); +} \ No newline at end of file diff --git a/o2web/source/o2_core/o2/widget/MWFRaphael.js b/o2web/source/o2_core/o2/widget/MWFRaphael.js index 28fa766a990eaccf94c3cc4950259aec606cdb91..ecd75b587d404fd6668f95e07b4fcfd9aeed7d44 100644 --- a/o2web/source/o2_core/o2/widget/MWFRaphael.js +++ b/o2web/source/o2_core/o2/widget/MWFRaphael.js @@ -4,10 +4,18 @@ o2.widget.MWFRaphael = MWFRaphael = { if (window.Raphael){ if (callback) callback(); }else{ - COMMON.AjaxModule.load("raphael", function(){ - this.expandRaphael(); - if (callback) callback(); - }.bind(this), true, true); + if(!window.Raphael && typeof require === 'function' && define.amd){ + require(["../o2_lib/raphael/raphael.js"], function(r){ + window.Raphael = r; + this.expandRaphael(); + if (callback) callback(); + }.bind(this)); + }else{ + COMMON.AjaxModule.load("raphael", function(){ + this.expandRaphael(); + if (callback) callback(); + }.bind(this), true, true); + } } }, expandRaphael: function(){ diff --git a/o2web/source/o2_core/o2/widget/ScriptArea.js b/o2web/source/o2_core/o2/widget/ScriptArea.js index c94225c5a4cd141eaa52d9cf5c93a85bab34cc5d..c27723cd334270001eaeeee3a8b397e122b979df 100644 --- a/o2web/source/o2_core/o2/widget/ScriptArea.js +++ b/o2web/source/o2_core/o2/widget/ScriptArea.js @@ -68,6 +68,7 @@ o2.widget.ScriptArea = new Class({ } }, maxSize: function(){ + debugger; var obj = this.options.maxObj; var coordinates = obj.getCoordinates(obj.getOffsetParent()); @@ -80,8 +81,8 @@ o2.widget.ScriptArea = new Class({ "position": "absolute", // "top": coordinates.top, // "left": coordinates.left, - "top": "0px", - "left": "0px", + "top": coordinates.top+"px", + "left": coordinates.left+"px", "width": coordinates.width, "height": coordinates.height-2, "z-index": 20001 @@ -97,7 +98,8 @@ o2.widget.ScriptArea = new Class({ returnSize: function(){ var size = this.container.retrieve("size"); - this.editor.setOption("lineNumbers", false); + //this.editor.setOption("lineNumbers", false); + this.jsEditor.hideLineNumbers(); this.container.inject(this.node); this.container.setStyles({ "position": "static", diff --git a/o2web/source/o2_core/o2/widget/ace.js b/o2web/source/o2_core/o2/widget/ace.js index 38664b2b702e9ae94a221f16bc870051fa5dede1..fab45ce09814f7a0e4e161a8789b67753a22d70d 100644 --- a/o2web/source/o2_core/o2/widget/ace.js +++ b/o2web/source/o2_core/o2/widget/ace.js @@ -2,15 +2,20 @@ o2.widget = o2.widget || {}; o2.widget.ace = { //"ace": COMMON.contentPath+"/res/framework/ace/src-min/ace.js", //"tools": COMMON.contentPath+"/res/framework/ace/src-min/ext-language_tools.js", + "callbackList": [], "load": function(callback){ if (!window.ace){ - var jsLoaded = false; - var cssLoaded = false; - o2.load("ace", {"sequence": true}, function(){ - //COMMON.AjaxModule.loadDom("ace-tools", function(){ - if (callback) callback(); - //}.bind(this)) - }.bind(this)); + this.callbackList.push(callback); + if (!this.isLoadding) { + this.isLoadding = true; + o2.load("ace", {"sequence": true}, function(){ + this.isLoadding = false; + while (this.callbackList.length){ + this.callbackList.shift()(); + } + }.bind(this)); + } + }else{ if (callback) callback(); } diff --git a/o2web/source/o2_core/o2/widget/codemirror.js b/o2web/source/o2_core/o2/widget/codemirror.js index a70dffe7c0525dfab395bf5032d554d6ad4b6d9e..cbfd8e197b488087c65e5297ac3ccfb969ff8528 100644 --- a/o2web/source/o2_core/o2/widget/codemirror.js +++ b/o2web/source/o2_core/o2/widget/codemirror.js @@ -11,8 +11,8 @@ o2.widget.codemirror = { "php": COMMON.contentPath+"/res/framework/codemirror/mode/php/php.js" }, "addon": { - - + + }, "load": function(callback){ var jsLoaded = false; @@ -42,9 +42,5 @@ o2.widget.codemirror = { if (callback) callback(); } } - -}; - - - +}; \ No newline at end of file diff --git a/o2web/source/o2_core/o2/widget/monaco.js b/o2web/source/o2_core/o2/widget/monaco.js index b12d9eea905130632adba4d66d81cd4ad365a4bf..d0679b4ad90ae20e29e7e6399d3ecaa0dd5fabde 100644 --- a/o2web/source/o2_core/o2/widget/monaco.js +++ b/o2web/source/o2_core/o2/widget/monaco.js @@ -1,23 +1,22 @@ o2.widget = o2.widget || {}; o2.widget.monaco = { - //"ace": COMMON.contentPath+"/res/framework/ace/src-min/ace.js", - //"tools": COMMON.contentPath+"/res/framework/ace/src-min/ext-language_tools.js", + "callbackList": [], "load": function(callback){ if (!window.monaco){ - o2.load("monaco", {"sequence": true}, function(){ - require.config({ paths: { "vs": "/o2_lib/vs" }}); - require(["vs/editor/editor.main"], function() { - if (callback) callback(); - // var editor = monaco.editor.create(document.getElementById('container'), { - // value: [ - // 'function x() {', - // '\tconsole.log("Hello world!");', - // '}' - // ].join('\n'), - // language: 'javascript' - // }); - }); - }.bind(this)); + this.callbackList.push(callback); + if (!this.isLoadding){ + this.isLoadding = true; + o2.load("monaco", {"sequence": true}, function(){ + require.config({ paths: { "vs": "/o2_lib/vs" }}); + require(["vs/editor/editor.main"], function() { + this.isLoadding = false; + while (this.callbackList.length){ + this.callbackList.shift()(); + } + //if (callback) callback(); + }.bind(this)); + }.bind(this)); + } }else{ if (callback) callback(); } diff --git a/o2web/source/o2_lib/vs/loader.js b/o2web/source/o2_lib/vs/loader.js index 379676c6e437f32f43802c351243314f3b871d28..136ad1c4f37f186322ca977ebb9bde25c3e73cb3 100644 --- a/o2web/source/o2_lib/vs/loader.js +++ b/o2web/source/o2_lib/vs/loader.js @@ -4,34 +4,1812 @@ * Released under the MIT license * https://github.com/Microsoft/vscode/blob/master/LICENSE.txt *-----------------------------------------------------------*/ -"use strict";var define,AMDLoader,_amdLoaderGlobal=this,_commonjsGlobal="object"==typeof global?global:{};!function(e){e.global=_amdLoaderGlobal;var t=function(){function t(){this._detected=!1,this._isWindows=!1,this._isNode=!1,this._isElectronRenderer=!1,this._isWebWorker=!1}return Object.defineProperty(t.prototype,"isWindows",{get:function(){return this._detect(),this._isWindows},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isNode",{get:function(){return this._detect(),this._isNode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isElectronRenderer",{get:function(){return this._detect(),this._isElectronRenderer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isWebWorker",{get:function(){return this._detect(),this._isWebWorker},enumerable:!0,configurable:!0}),t.prototype._detect=function(){this._detected||(this._detected=!0,this._isWindows=t._isWindows(),this._isNode="undefined"!=typeof module&&!!module.exports, -this._isElectronRenderer="undefined"!=typeof process&&void 0!==process.versions&&void 0!==process.versions.electron&&"renderer"===process.type,this._isWebWorker="function"==typeof e.global.importScripts)},t._isWindows=function(){return!!("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Windows")>=0)||"undefined"!=typeof process&&"win32"===process.platform},t}();e.Environment=t}(AMDLoader||(AMDLoader={})),function(e){var t=function(e,t,r){this.type=e,this.detail=t,this.timestamp=r};e.LoaderEvent=t;var r=function(){function r(e){this._events=[new t(1,"",e)]}return r.prototype.record=function(r,n){this._events.push(new t(r,n,e.Utilities.getHighPerformanceTimestamp()))},r.prototype.getEvents=function(){return this._events},r}();e.LoaderEventRecorder=r;var n=function(){function e(){}return e.prototype.record=function(e,t){},e.prototype.getEvents=function(){return[]},e.INSTANCE=new e,e}();e.NullLoaderEventRecorder=n}(AMDLoader||(AMDLoader={})),function(e){var t=function(){ -function t(){}return t.fileUriToFilePath=function(e,t){if(t=decodeURI(t).replace(/%23/g,"#"),e){if(/^file:\/\/\//.test(t))return t.substr(8);if(/^file:\/\//.test(t))return t.substr(5)}else if(/^file:\/\//.test(t))return t.substr(7);return t},t.startsWith=function(e,t){return e.length>=t.length&&e.substr(0,t.length)===t},t.endsWith=function(e,t){return e.length>=t.length&&e.substr(e.length-t.length)===t},t.containsQueryString=function(e){return/^[^\#]*\?/gi.test(e)},t.isAbsolutePath=function(e){return/^((http:\/\/)|(https:\/\/)|(file:\/\/)|(\/))/.test(e)},t.forEachProperty=function(e,t){if(e){var r=void 0;for(r in e)e.hasOwnProperty(r)&&t(r,e[r])}},t.isEmpty=function(e){var r=!0;return t.forEachProperty(e,(function(){r=!1})),r},t.recursiveClone=function(e){if(!e||"object"!=typeof e)return e;var r=Array.isArray(e)?[]:{};return t.forEachProperty(e,(function(e,n){r[e]=n&&"object"==typeof n?t.recursiveClone(n):n})),r},t.generateAnonymousModule=function(){return"===anonymous"+t.NEXT_ANONYMOUS_ID+++"==="}, -t.isAnonymousModule=function(e){return t.startsWith(e,"===anonymous")},t.getHighPerformanceTimestamp=function(){return this.PERFORMANCE_NOW_PROBED||(this.PERFORMANCE_NOW_PROBED=!0,this.HAS_PERFORMANCE_NOW=e.global.performance&&"function"==typeof e.global.performance.now),this.HAS_PERFORMANCE_NOW?e.global.performance.now():Date.now()},t.NEXT_ANONYMOUS_ID=1,t.PERFORMANCE_NOW_PROBED=!1,t.HAS_PERFORMANCE_NOW=!1,t}();e.Utilities=t}(AMDLoader||(AMDLoader={})),function(e){function t(e){if(e instanceof Error)return e;var t=new Error(e.message||String(e)||"Unknown Error");return e.stack&&(t.stack=e.stack),t}e.ensureError=t;var r=function(){function r(){}return r.validateConfigurationOptions=function(r){if("string"!=typeof(r=r||{}).baseUrl&&(r.baseUrl=""),"boolean"!=typeof r.isBuild&&(r.isBuild=!1),"object"!=typeof r.paths&&(r.paths={}),"object"!=typeof r.config&&(r.config={}),void 0===r.catchError&&(r.catchError=!1),void 0===r.recordStats&&(r.recordStats=!1),"string"!=typeof r.urlArgs&&(r.urlArgs=""), -"function"!=typeof r.onError&&(r.onError=function(e){return"loading"===e.phase?(console.error('Loading "'+e.moduleId+'" failed'),console.error(e),console.error("Here are the modules that depend on it:"),void console.error(e.neededBy)):"factory"===e.phase?(console.error('The factory method of "'+e.moduleId+'" has thrown an exception'),void console.error(e)):void 0}),Array.isArray(r.ignoreDuplicateModules)||(r.ignoreDuplicateModules=[]),r.baseUrl.length>0&&(e.Utilities.endsWith(r.baseUrl,"/")||(r.baseUrl+="/")),"string"!=typeof r.cspNonce&&(r.cspNonce=""),Array.isArray(r.nodeModules)||(r.nodeModules=[]),r.nodeCachedData&&"object"==typeof r.nodeCachedData&&("string"!=typeof r.nodeCachedData.seed&&(r.nodeCachedData.seed="seed"),("number"!=typeof r.nodeCachedData.writeDelay||r.nodeCachedData.writeDelay<0)&&(r.nodeCachedData.writeDelay=7e3),!r.nodeCachedData.path||"string"!=typeof r.nodeCachedData.path)){var n=t(new Error("INVALID cached data configuration, 'path' MUST be set"));n.phase="configuration", -r.onError(n),r.nodeCachedData=void 0}return r},r.mergeConfigurationOptions=function(t,n){void 0===t&&(t=null),void 0===n&&(n=null);var o=e.Utilities.recursiveClone(n||{});return e.Utilities.forEachProperty(t,(function(t,r){"ignoreDuplicateModules"===t&&void 0!==o.ignoreDuplicateModules?o.ignoreDuplicateModules=o.ignoreDuplicateModules.concat(r):"paths"===t&&void 0!==o.paths?e.Utilities.forEachProperty(r,(function(e,t){return o.paths[e]=t})):"config"===t&&void 0!==o.config?e.Utilities.forEachProperty(r,(function(e,t){return o.config[e]=t})):o[t]=e.Utilities.recursiveClone(r)})),r.validateConfigurationOptions(o)},r}();e.ConfigurationOptionsUtil=r;var n=function(){function t(e,t){if(this._env=e,this.options=r.mergeConfigurationOptions(t),this._createIgnoreDuplicateModulesMap(),this._createNodeModulesMap(),this._createSortedPathsRules(),""===this.options.baseUrl){if(this.options.nodeRequire&&this.options.nodeRequire.main&&this.options.nodeRequire.main.filename&&this._env.isNode){ -var n=this.options.nodeRequire.main.filename,o=Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\"));this.options.baseUrl=n.substring(0,o+1)}if(this.options.nodeMain&&this._env.isNode){n=this.options.nodeMain,o=Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\"));this.options.baseUrl=n.substring(0,o+1)}}}return t.prototype._createIgnoreDuplicateModulesMap=function(){this.ignoreDuplicateModulesMap={};for(var e=0;e=5||(s=i.length,o._fs.writeFile(r,Buffer.concat([a,i]),(function(e){e&&n.getConfig().onError(e),n.getRecorder().record(63,r),u()})))}),i*Math.pow(4,d++))};u()},t.prototype._readSourceAndCachedData=function(e,t,r,n){if(t){var o=void 0,i=void 0,s=void 0,d=2,a=function(e){e?n(e):0==--d&&n(void 0,o,i,s)};this._fs.readFile(e,{encoding:"utf8"},(function(e,t){o=t,a(e)})),this._fs.readFile(t,(function(e,n){!e&&n&&n.length>0?(s=n.slice(0,16),i=n.slice(16),r.record(60,t)):r.record(61,t),a()}))}else this._fs.readFile(e,{encoding:"utf8"},n)},t.prototype._verifyCachedData=function(e,t,r,n,o){var i=this;n&&(e.cachedDataRejected||setTimeout((function(){var e=i._crypto.createHash("md5").update(t,"utf8").digest() -;n.equals(e)||(o.getConfig().onError(new Error("FAILED TO VERIFY CACHED DATA, deleting stale '"+r+"' now, but a RESTART IS REQUIRED")),i._fs.unlink(r,(function(e){return o.getConfig().onError(e)})))}),Math.ceil(5e3*(1+Math.random()))))},t._BOM=65279,t._PREFIX="(function (require, define, __filename, __dirname) { ",t._SUFFIX="\n});",t}();e.createScriptLoader=function(e){return new t(e)}}(AMDLoader||(AMDLoader={})),function(e){var t=function(){function t(e){var t=e.lastIndexOf("/");this.fromModulePath=-1!==t?e.substr(0,t+1):""}return t._normalizeModuleId=function(e){var t,r=e;for(t=/\/\.\//;t.test(r);)r=r.replace(t,"/");for(r=r.replace(/^\.\//g,""),t=/\/(([^\/])|([^\/][^\/\.])|([^\/\.][^\/])|([^\/][^\/][^\/]+))\/\.\.\//;t.test(r);)r=r.replace(t,"/");return r=r.replace(/^(([^\/])|([^\/][^\/\.])|([^\/\.][^\/])|([^\/][^\/][^\/]+))\/\.\.\//,"")},t.prototype.resolveModule=function(r){var n=r -;return e.Utilities.isAbsolutePath(n)||(e.Utilities.startsWith(n,"./")||e.Utilities.startsWith(n,"../"))&&(n=t._normalizeModuleId(this.fromModulePath+n)),n},t.ROOT=new t(""),t}();e.ModuleIdResolver=t;var r=function(){function t(e,t,r,n,o,i){this.id=e,this.strId=t,this.dependencies=r,this._callback=n,this._errorback=o,this.moduleIdResolver=i,this.exports={},this.error=null,this.exportsPassedIn=!1,this.unresolvedDependenciesCount=this.dependencies.length,this._isComplete=!1}return t._safeInvokeFunction=function(t,r){try{return{returnedValue:t.apply(e.global,r),producedError:null}}catch(e){return{returnedValue:null,producedError:e}}},t._invokeFactory=function(t,r,n,o){return t.isBuild()&&!e.Utilities.isAnonymousModule(r)?{returnedValue:null,producedError:null}:t.shouldCatchError()?this._safeInvokeFunction(n,o):{returnedValue:n.apply(e.global,o),producedError:null}},t.prototype.complete=function(r,n,o){this._isComplete=!0;var i=null;if(this._callback)if("function"==typeof this._callback){r.record(21,this.strId) -;var s=t._invokeFactory(n,this.strId,this._callback,o);i=s.producedError,r.record(22,this.strId),i||void 0===s.returnedValue||this.exportsPassedIn&&!e.Utilities.isEmpty(this.exports)||(this.exports=s.returnedValue)}else this.exports=this._callback;if(i){var d=e.ensureError(i);d.phase="factory",d.moduleId=this.strId,this.error=d,n.onError(d)}this.dependencies=null,this._callback=null,this._errorback=null,this.moduleIdResolver=null},t.prototype.onDependencyError=function(e){return this._isComplete=!0,this.error=e,!!this._errorback&&(this._errorback(e),!0)},t.prototype.isComplete=function(){return this._isComplete},t}();e.Module=r;var n=function(){function e(){this._nextId=0,this._strModuleIdToIntModuleId=new Map,this._intModuleIdToStrModuleId=[],this.getModuleId("exports"),this.getModuleId("module"),this.getModuleId("require")}return e.prototype.getMaxModuleId=function(){return this._nextId},e.prototype.getModuleId=function(e){var t=this._strModuleIdToIntModuleId.get(e);return void 0===t&&(t=this._nextId++, -this._strModuleIdToIntModuleId.set(e,t),this._intModuleIdToStrModuleId[t]=e),t},e.prototype.getStrModuleId=function(e){return this._intModuleIdToStrModuleId[e]},e}(),o=function(){function e(e){this.id=e}return e.EXPORTS=new e(0),e.MODULE=new e(1),e.REQUIRE=new e(2),e}();e.RegularDependency=o;var i=function(e,t,r){this.id=e,this.pluginId=t,this.pluginParam=r};e.PluginDependency=i;var s=function(){function s(t,r,o,i,s){void 0===s&&(s=0),this._env=t,this._scriptLoader=r,this._loaderAvailableTimestamp=s,this._defineFunc=o,this._requireFunc=i,this._moduleIdProvider=new n,this._config=new e.Configuration(this._env),this._modules2=[],this._knownModules2=[],this._inverseDependencies2=[],this._inversePluginDependencies2=new Map,this._currentAnnonymousDefineCall=null,this._recorder=null,this._buildInfoPath=[],this._buildInfoDefineStack=[],this._buildInfoDependencies=[]}return s.prototype.reset=function(){return new s(this._env,this._scriptLoader,this._defineFunc,this._requireFunc,this._loaderAvailableTimestamp)}, -s.prototype.getGlobalAMDDefineFunc=function(){return this._defineFunc},s.prototype.getGlobalAMDRequireFunc=function(){return this._requireFunc},s._findRelevantLocationInStack=function(e,t){for(var r=function(e){return e.replace(/\\/g,"/")},n=r(e),o=t.split(/\n/),i=0;i=0){var n=t.resolveModule(e.substr(0,r)),s=t.resolveModule(e.substr(r+1)),d=this._moduleIdProvider.getModuleId(n+"!"+s),a=this._moduleIdProvider.getModuleId(n);return new i(d,a,s)}return new o(this._moduleIdProvider.getModuleId(t.resolveModule(e)))},s.prototype._normalizeDependencies=function(e,t){for(var r=[],n=0,o=0,i=e.length;o0;){var u=a.shift(),l=this._modules2[u];l&&(d=l.onDependencyError(n)||d);var c=this._inverseDependencies2[u];if(c)for(i=0,s=c.length;i0;){var d=s.shift().dependencies;if(d)for(o=0,i=d.length;o=n.length)t._onLoadError(e,r);else{var s=n[o],d=t.getRecorder() -;if(t._config.isBuild()&&"empty:"===s)return t._buildInfoPath[e]=s,t.defineModule(t._moduleIdProvider.getStrModuleId(e),[],null,null,null),void t._onLoad(e);d.record(10,s),t._scriptLoader.load(t,s,(function(){t._config.isBuild()&&(t._buildInfoPath[e]=s),d.record(11,s),t._onLoad(e)}),(function(e){d.record(12,s),i(e)}))}};i(null)}},s.prototype._loadPluginDependency=function(e,r){var n=this;if(!this._modules2[r.id]&&!this._knownModules2[r.id]){this._knownModules2[r.id]=!0;var o=function(e){n.defineModule(n._moduleIdProvider.getStrModuleId(r.id),[],e,null,null)};o.error=function(e){n._config.onError(n._createLoadError(r.id,e))},e.load(r.pluginParam,this._createRequire(t.ROOT),o,this._config.getOptionsLiteral())}},s.prototype._resolve=function(e){var t=this,r=e.dependencies;if(r)for(var n=0,s=r.length;n \n")),e.unresolvedDependenciesCount--}else if(this._inverseDependencies2[d.id]=this._inverseDependencies2[d.id]||[],this._inverseDependencies2[d.id].push(e.id),d instanceof i){var l=this._modules2[d.pluginId];if(l&&l.isComplete()){this._loadPluginDependency(l.exports,d);continue}var c=this._inversePluginDependencies2.get(d.pluginId);c||(c=[],this._inversePluginDependencies2.set(d.pluginId,c)),c.push(d),this._loadModule(d.pluginId)}else this._loadModule(d.id)}else e.unresolvedDependenciesCount--;else e.unresolvedDependenciesCount--;else e.exportsPassedIn=!0,e.unresolvedDependenciesCount--} -0===e.unresolvedDependenciesCount&&this._onModuleComplete(e)},s.prototype._onModuleComplete=function(e){var t=this,r=this.getRecorder();if(!e.isComplete()){var n=e.dependencies,i=[];if(n)for(var s=0,d=n.length;s= 0) { + return true; + } + } + if (typeof process !== 'undefined') { + return (process.platform === 'win32'); + } + return false; + }; + return Environment; + }()); + AMDLoader.Environment = Environment; +})(AMDLoader || (AMDLoader = {})); +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +var AMDLoader; +(function (AMDLoader) { + var LoaderEvent = /** @class */ (function () { + function LoaderEvent(type, detail, timestamp) { + this.type = type; + this.detail = detail; + this.timestamp = timestamp; + } + return LoaderEvent; + }()); + AMDLoader.LoaderEvent = LoaderEvent; + var LoaderEventRecorder = /** @class */ (function () { + function LoaderEventRecorder(loaderAvailableTimestamp) { + this._events = [new LoaderEvent(1 /* LoaderAvailable */, '', loaderAvailableTimestamp)]; + } + LoaderEventRecorder.prototype.record = function (type, detail) { + this._events.push(new LoaderEvent(type, detail, AMDLoader.Utilities.getHighPerformanceTimestamp())); + }; + LoaderEventRecorder.prototype.getEvents = function () { + return this._events; + }; + return LoaderEventRecorder; + }()); + AMDLoader.LoaderEventRecorder = LoaderEventRecorder; + var NullLoaderEventRecorder = /** @class */ (function () { + function NullLoaderEventRecorder() { + } + NullLoaderEventRecorder.prototype.record = function (type, detail) { + // Nothing to do + }; + NullLoaderEventRecorder.prototype.getEvents = function () { + return []; + }; + NullLoaderEventRecorder.INSTANCE = new NullLoaderEventRecorder(); + return NullLoaderEventRecorder; + }()); + AMDLoader.NullLoaderEventRecorder = NullLoaderEventRecorder; +})(AMDLoader || (AMDLoader = {})); +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +var AMDLoader; +(function (AMDLoader) { + var Utilities = /** @class */ (function () { + function Utilities() { + } + /** + * This method does not take care of / vs \ + */ + Utilities.fileUriToFilePath = function (isWindows, uri) { + uri = decodeURI(uri).replace(/%23/g, '#'); + if (isWindows) { + if (/^file:\/\/\//.test(uri)) { + // This is a URI without a hostname => return only the path segment + return uri.substr(8); + } + if (/^file:\/\//.test(uri)) { + return uri.substr(5); + } + } + else { + if (/^file:\/\//.test(uri)) { + return uri.substr(7); + } + } + // Not sure... + return uri; + }; + Utilities.startsWith = function (haystack, needle) { + return haystack.length >= needle.length && haystack.substr(0, needle.length) === needle; + }; + Utilities.endsWith = function (haystack, needle) { + return haystack.length >= needle.length && haystack.substr(haystack.length - needle.length) === needle; + }; + // only check for "?" before "#" to ensure that there is a real Query-String + Utilities.containsQueryString = function (url) { + return /^[^\#]*\?/gi.test(url); + }; + /** + * Does `url` start with http:// or https:// or file:// or / ? + */ + Utilities.isAbsolutePath = function (url) { + return /^((http:\/\/)|(https:\/\/)|(file:\/\/)|(\/))/.test(url); + }; + Utilities.forEachProperty = function (obj, callback) { + if (obj) { + var key = void 0; + for (key in obj) { + if (obj.hasOwnProperty(key)) { + callback(key, obj[key]); + } + } + } + }; + Utilities.isEmpty = function (obj) { + var isEmpty = true; + Utilities.forEachProperty(obj, function () { + isEmpty = false; + }); + return isEmpty; + }; + Utilities.recursiveClone = function (obj) { + if (!obj || typeof obj !== 'object') { + return obj; + } + var result = Array.isArray(obj) ? [] : {}; + Utilities.forEachProperty(obj, function (key, value) { + if (value && typeof value === 'object') { + result[key] = Utilities.recursiveClone(value); + } + else { + result[key] = value; + } + }); + return result; + }; + Utilities.generateAnonymousModule = function () { + return '===anonymous' + (Utilities.NEXT_ANONYMOUS_ID++) + '==='; + }; + Utilities.isAnonymousModule = function (id) { + return Utilities.startsWith(id, '===anonymous'); + }; + Utilities.getHighPerformanceTimestamp = function () { + if (!this.PERFORMANCE_NOW_PROBED) { + this.PERFORMANCE_NOW_PROBED = true; + this.HAS_PERFORMANCE_NOW = (AMDLoader.global.performance && typeof AMDLoader.global.performance.now === 'function'); + } + return (this.HAS_PERFORMANCE_NOW ? AMDLoader.global.performance.now() : Date.now()); + }; + Utilities.NEXT_ANONYMOUS_ID = 1; + Utilities.PERFORMANCE_NOW_PROBED = false; + Utilities.HAS_PERFORMANCE_NOW = false; + return Utilities; + }()); + AMDLoader.Utilities = Utilities; +})(AMDLoader || (AMDLoader = {})); +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +var AMDLoader; +(function (AMDLoader) { + function ensureError(err) { + if (err instanceof Error) { + return err; + } + var result = new Error(err.message || String(err) || 'Unknown Error'); + if (err.stack) { + result.stack = err.stack; + } + return result; + } + AMDLoader.ensureError = ensureError; + ; + var ConfigurationOptionsUtil = /** @class */ (function () { + function ConfigurationOptionsUtil() { + } + /** + * Ensure configuration options make sense + */ + ConfigurationOptionsUtil.validateConfigurationOptions = function (options) { + function defaultOnError(err) { + if (err.phase === 'loading') { + console.error('Loading "' + err.moduleId + '" failed'); + console.error(err); + console.error('Here are the modules that depend on it:'); + console.error(err.neededBy); + return; + } + if (err.phase === 'factory') { + console.error('The factory method of "' + err.moduleId + '" has thrown an exception'); + console.error(err); + return; + } + } + options = options || {}; + if (typeof options.baseUrl !== 'string') { + options.baseUrl = ''; + } + if (typeof options.isBuild !== 'boolean') { + options.isBuild = false; + } + if (typeof options.paths !== 'object') { + options.paths = {}; + } + if (typeof options.config !== 'object') { + options.config = {}; + } + if (typeof options.catchError === 'undefined') { + options.catchError = false; + } + if (typeof options.recordStats === 'undefined') { + options.recordStats = false; + } + if (typeof options.urlArgs !== 'string') { + options.urlArgs = ''; + } + if (typeof options.onError !== 'function') { + options.onError = defaultOnError; + } + if (!Array.isArray(options.ignoreDuplicateModules)) { + options.ignoreDuplicateModules = []; + } + if (options.baseUrl.length > 0) { + if (!AMDLoader.Utilities.endsWith(options.baseUrl, '/')) { + options.baseUrl += '/'; + } + } + if (typeof options.cspNonce !== 'string') { + options.cspNonce = ''; + } + if (!Array.isArray(options.nodeModules)) { + options.nodeModules = []; + } + if (options.nodeCachedData && typeof options.nodeCachedData === 'object') { + if (typeof options.nodeCachedData.seed !== 'string') { + options.nodeCachedData.seed = 'seed'; + } + if (typeof options.nodeCachedData.writeDelay !== 'number' || options.nodeCachedData.writeDelay < 0) { + options.nodeCachedData.writeDelay = 1000 * 7; + } + if (!options.nodeCachedData.path || typeof options.nodeCachedData.path !== 'string') { + var err = ensureError(new Error('INVALID cached data configuration, \'path\' MUST be set')); + err.phase = 'configuration'; + options.onError(err); + options.nodeCachedData = undefined; + } + } + return options; + }; + ConfigurationOptionsUtil.mergeConfigurationOptions = function (overwrite, base) { + if (overwrite === void 0) { overwrite = null; } + if (base === void 0) { base = null; } + var result = AMDLoader.Utilities.recursiveClone(base || {}); + // Merge known properties and overwrite the unknown ones + AMDLoader.Utilities.forEachProperty(overwrite, function (key, value) { + if (key === 'ignoreDuplicateModules' && typeof result.ignoreDuplicateModules !== 'undefined') { + result.ignoreDuplicateModules = result.ignoreDuplicateModules.concat(value); + } + else if (key === 'paths' && typeof result.paths !== 'undefined') { + AMDLoader.Utilities.forEachProperty(value, function (key2, value2) { return result.paths[key2] = value2; }); + } + else if (key === 'config' && typeof result.config !== 'undefined') { + AMDLoader.Utilities.forEachProperty(value, function (key2, value2) { return result.config[key2] = value2; }); + } + else { + result[key] = AMDLoader.Utilities.recursiveClone(value); + } + }); + return ConfigurationOptionsUtil.validateConfigurationOptions(result); + }; + return ConfigurationOptionsUtil; + }()); + AMDLoader.ConfigurationOptionsUtil = ConfigurationOptionsUtil; + var Configuration = /** @class */ (function () { + function Configuration(env, options) { + this._env = env; + this.options = ConfigurationOptionsUtil.mergeConfigurationOptions(options); + this._createIgnoreDuplicateModulesMap(); + this._createNodeModulesMap(); + this._createSortedPathsRules(); + if (this.options.baseUrl === '') { + if (this.options.nodeRequire && this.options.nodeRequire.main && this.options.nodeRequire.main.filename && this._env.isNode) { + var nodeMain = this.options.nodeRequire.main.filename; + var dirnameIndex = Math.max(nodeMain.lastIndexOf('/'), nodeMain.lastIndexOf('\\')); + this.options.baseUrl = nodeMain.substring(0, dirnameIndex + 1); + } + if (this.options.nodeMain && this._env.isNode) { + var nodeMain = this.options.nodeMain; + var dirnameIndex = Math.max(nodeMain.lastIndexOf('/'), nodeMain.lastIndexOf('\\')); + this.options.baseUrl = nodeMain.substring(0, dirnameIndex + 1); + } + } + } + Configuration.prototype._createIgnoreDuplicateModulesMap = function () { + // Build a map out of the ignoreDuplicateModules array + this.ignoreDuplicateModulesMap = {}; + for (var i = 0; i < this.options.ignoreDuplicateModules.length; i++) { + this.ignoreDuplicateModulesMap[this.options.ignoreDuplicateModules[i]] = true; + } + }; + Configuration.prototype._createNodeModulesMap = function () { + // Build a map out of nodeModules array + this.nodeModulesMap = Object.create(null); + for (var _i = 0, _a = this.options.nodeModules; _i < _a.length; _i++) { + var nodeModule = _a[_i]; + this.nodeModulesMap[nodeModule] = true; + } + }; + Configuration.prototype._createSortedPathsRules = function () { + var _this = this; + // Create an array our of the paths rules, sorted descending by length to + // result in a more specific -> less specific order + this.sortedPathsRules = []; + AMDLoader.Utilities.forEachProperty(this.options.paths, function (from, to) { + if (!Array.isArray(to)) { + _this.sortedPathsRules.push({ + from: from, + to: [to] + }); + } + else { + _this.sortedPathsRules.push({ + from: from, + to: to + }); + } + }); + this.sortedPathsRules.sort(function (a, b) { + return b.from.length - a.from.length; + }); + }; + /** + * Clone current configuration and overwrite options selectively. + * @param options The selective options to overwrite with. + * @result A new configuration + */ + Configuration.prototype.cloneAndMerge = function (options) { + return new Configuration(this._env, ConfigurationOptionsUtil.mergeConfigurationOptions(options, this.options)); + }; + /** + * Get current options bag. Useful for passing it forward to plugins. + */ + Configuration.prototype.getOptionsLiteral = function () { + return this.options; + }; + Configuration.prototype._applyPaths = function (moduleId) { + var pathRule; + for (var i = 0, len = this.sortedPathsRules.length; i < len; i++) { + pathRule = this.sortedPathsRules[i]; + if (AMDLoader.Utilities.startsWith(moduleId, pathRule.from)) { + var result = []; + for (var j = 0, lenJ = pathRule.to.length; j < lenJ; j++) { + result.push(pathRule.to[j] + moduleId.substr(pathRule.from.length)); + } + return result; + } + } + return [moduleId]; + }; + Configuration.prototype._addUrlArgsToUrl = function (url) { + if (AMDLoader.Utilities.containsQueryString(url)) { + return url + '&' + this.options.urlArgs; + } + else { + return url + '?' + this.options.urlArgs; + } + }; + Configuration.prototype._addUrlArgsIfNecessaryToUrl = function (url) { + if (this.options.urlArgs) { + return this._addUrlArgsToUrl(url); + } + return url; + }; + Configuration.prototype._addUrlArgsIfNecessaryToUrls = function (urls) { + if (this.options.urlArgs) { + for (var i = 0, len = urls.length; i < len; i++) { + urls[i] = this._addUrlArgsToUrl(urls[i]); + } + } + return urls; + }; + /** + * Transform a module id to a location. Appends .js to module ids + */ + Configuration.prototype.moduleIdToPaths = function (moduleId) { + if (this.nodeModulesMap[moduleId] === true) { + // This is a node module... + if (this.isBuild()) { + // ...and we are at build time, drop it + return ['empty:']; + } + else { + // ...and at runtime we create a `shortcut`-path + return ['node|' + moduleId]; + } + } + var result = moduleId; + var results; + if (!AMDLoader.Utilities.endsWith(result, '.js') && !AMDLoader.Utilities.isAbsolutePath(result)) { + results = this._applyPaths(result); + for (var i = 0, len = results.length; i < len; i++) { + if (this.isBuild() && results[i] === 'empty:') { + continue; + } + if (!AMDLoader.Utilities.isAbsolutePath(results[i])) { + results[i] = this.options.baseUrl + results[i]; + } + if (!AMDLoader.Utilities.endsWith(results[i], '.js') && !AMDLoader.Utilities.containsQueryString(results[i])) { + results[i] = results[i] + '.js'; + } + } + } + else { + if (!AMDLoader.Utilities.endsWith(result, '.js') && !AMDLoader.Utilities.containsQueryString(result)) { + result = result + '.js'; + } + results = [result]; + } + return this._addUrlArgsIfNecessaryToUrls(results); + }; + /** + * Transform a module id or url to a location. + */ + Configuration.prototype.requireToUrl = function (url) { + var result = url; + if (!AMDLoader.Utilities.isAbsolutePath(result)) { + result = this._applyPaths(result)[0]; + if (!AMDLoader.Utilities.isAbsolutePath(result)) { + result = this.options.baseUrl + result; + } + } + return this._addUrlArgsIfNecessaryToUrl(result); + }; + /** + * Flag to indicate if current execution is as part of a build. + */ + Configuration.prototype.isBuild = function () { + return this.options.isBuild; + }; + /** + * Test if module `moduleId` is expected to be defined multiple times + */ + Configuration.prototype.isDuplicateMessageIgnoredFor = function (moduleId) { + return this.ignoreDuplicateModulesMap.hasOwnProperty(moduleId); + }; + /** + * Get the configuration settings for the provided module id + */ + Configuration.prototype.getConfigForModule = function (moduleId) { + if (this.options.config) { + return this.options.config[moduleId]; + } + }; + /** + * Should errors be caught when executing module factories? + */ + Configuration.prototype.shouldCatchError = function () { + return this.options.catchError; + }; + /** + * Should statistics be recorded? + */ + Configuration.prototype.shouldRecordStats = function () { + return this.options.recordStats; + }; + /** + * Forward an error to the error handler. + */ + Configuration.prototype.onError = function (err) { + this.options.onError(err); + }; + return Configuration; + }()); + AMDLoader.Configuration = Configuration; +})(AMDLoader || (AMDLoader = {})); +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +var AMDLoader; +(function (AMDLoader) { + /** + * Load `scriptSrc` only once (avoid multiple