User:Imbushuo/MonacoLoader.js

var MwMonaco;(function(n){var t=function{function n(n,t){this.m_textAreaControl=n;this.m_docType="markdown";window.monacoUserConfig&&(this.m_userOptions=window.monacoUserConfig);t&&t.autoLoad&&this.initialize}return n.determineAvailability=function{return document.getElementById("wpTextbox1")?!0:!1},n.prototype.checkTitleExtensionAsync=function{var t=this;return new monaco.Promise(function(i,r){mw.loader.using("mediawiki.Uri").then(function{var f=new mw.Uri;if(f.query.title){var u=f.query.title,e=u.lastIndexOf("."),o=u.indexOf(":");t.m_docPrefix=u.substring(0,o);t.m_docExtension=u.substring(e);n.g_prefixMapping[t.m_docPrefix]?i(n.g_prefixMapping[t.m_docPrefix]):n.g_extMapping[t.m_docExtension]?i(n.g_extMapping[t.m_docExtension]):i("plaintext")}else r("Unable to load title")})})},n.prototype.createLibraryXhrPromise=function(n){return new monaco.Promise(function(t,i){$.ajax({url:n.url,cache:!0}).then(function(i){t({content:i,fileName:n.fileName,url:n.url})}).fail(function{i(null)})})},n.prototype.loadReferenceLibrariesAsync=function{var t=this;return new monaco.Promise(function(i){switch(t.m_docType){case"javascript":case"typescript":console.info("Loading references for script editor.");var r=[];n.g_commonLibraries.forEach(function(n){return r.push(t.createLibraryXhrPromise(n))});monaco.Promise.join(r).then(function(n){n.forEach(function(n){console.info("Loaded module "+n.fileName+".");monaco.languages.typescript.typescriptDefaults.addExtraLib(n.content,n.fileName);monaco.languages.typescript.javascriptDefaults.addExtraLib(n.content,n.fileName)});i(!0)},function{return i(!1)});break;case"plaintext":$.getScript("/w/index.php?title=User:imbushuo/MonacoEditor/MediaWikiIntelliSense.min.js&action=raw&ctype=text/javascript",function{var n=new MwMonacoExtension.TitleAutoCompletionSource;monaco.languages.registerCompletionItemProvider("plaintext",{provideCompletionItems:function(t,i){var u=t.getValueInRange({startLineNumber:1,startColumn:1,endLineNumber:i.lineNumber,endColumn:i.column}),r=n.matchRule.exec(u);return r&&r.length>1?n.getCandidateItemsAsync(r[1]):[]}});i(!0)}).fail(function{return i(!1)});break;default:i(!0)}})},n.prototype.createEditorHost=function{var t=document.createElement("div"),n;return t.id="editorToolbar",t.style.cssText="width:100%;height:36px;background: rgb(37,37,38);",$("#wpTextbox1").after(t),n=document.createElement("div"),n.id="editorContainer",n.style.cssText="width:100%;height:500px;",$(t).after(n),$("#wpTextbox1").hide,n},n.prototype.getTheme=function{return this.m_userOptions&&this.m_userOptions.theme?this.m_userOptions.theme:"vs-dark"},n.prototype.getFontFamily=function{return this.m_userOptions&&this.m_userOptions.fontFamily?this.m_userOptions.fontFamily:"Iosevka, Consolas, Monaco, 'Source Han Sans SC', 'Source Han Sans', 'Microsoft YaHei', monospace"},n.prototype.initialize=function{var t=this;n.determineAvailability&&this.checkTitleExtensionAsync.then(function(n){t.m_docType=n;t.m_hostControl=t.createEditorHost;t.loadReferenceLibrariesAsync.then(function{t.m_editorControl=monaco.editor.create(t.m_hostControl,{value:t.m_textAreaControl.value,language:t.m_docType,theme:t.getTheme,fontFamily:t.getFontFamily,automaticLayout:!0});$("#editform").submit(function{$("#wpTextbox1").val(t.m_editorControl.getModel.getValue)})})})},n};t.g_prefixMapping={Module:"lua","模块":"lua"};t.g_extMapping={".js":"javascript",".ts":"typescript",".css":"css",".less":"less",".scss":"scss"};t.g_commonLibraries=[{url:"/w/index.php?title=User:Imbushuo/MonacoEditor/jquery.d.ts&action=raw&ctype=text/typescript",fileName:"jquery.d.ts"},{url:"/w/index.php?index=User:Imbushuo/MonacoEditor/mediawiki.d.ts&action=raw&ctype=text/typescript",fileName:"mediawiki.d.ts"}];n.MonacoLoader=t})(MwMonaco||(MwMonaco={})); //# sourceMappingURL=MonacoLoader.min.js.map