123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- //@ts-check
- (function () {
- const corePaths = {
- src: '/vscode/out/vs',
- 'npm/dev': 'node_modules/monaco-editor-core/dev/vs',
- 'npm/min': 'node_modules/monaco-editor-core/min/vs',
- built: '/vscode/out-monaco-editor-core/min/vs',
- releaseDev: 'out/monaco-editor/dev/vs',
- releaseMin: 'out/monaco-editor/min/vs'
- };
- const pluginPaths = {
- src: 'out/amd',
- dev: 'out/release/dev/vs',
- min: 'out/release/min/vs'
- };
- const parsedQuery = parseQueryString();
- const editorQueryName = 'editor';
- const pluginsQueryName = 'plugins';
- const defaultEditorQueryValue = 'npm/dev';
- const defaultPluginsQueryValue = 'src';
- const editorQueryValue = parsedQuery[editorQueryName] || defaultEditorQueryValue;
- const pluginsQueryValue = parsedQuery[pluginsQueryName] || defaultPluginsQueryValue;
- const corePath = resolvePath(corePaths[editorQueryValue]);
- const pluginPath = resolvePath(pluginPaths[pluginsQueryValue]);
- const isRelease = /release/.test(editorQueryValue);
- (function () {
- let div = document.createElement('div');
- div.className = 'dev-setup-control';
- div.style.position = 'fixed';
- div.style.top = '0';
- div.style.right = '0';
- div.style.background = 'lightgray';
- div.style.padding = '5px 20px 5px 5px';
- div.style.zIndex = '1000';
- div.innerHTML = // CodeQL [SM03712] This code is not deployed and serves as local test code. No risk of malicious input.
- '<ul><li>' + // CodeQL [SM03712] This code is not deployed and serves as local test code. No risk of malicious input.
- renderLoadingOptions(true) + // CodeQL [SM03712] This code is not deployed and serves as local test code. No risk of malicious input.
- (isRelease ? '' : `</li><li>${renderLoadingOptions(false)}`) + // CodeQL [SM03712] This code is not deployed and serves as local test code. No risk of malicious input.
- '</li></ul>'; // CodeQL [SM03712] This code is not deployed and serves as local test code. No risk of malicious input.
- document.body.appendChild(div);
- let aElements = document.getElementsByTagName('a');
- for (let i = 0; i < aElements.length; i++) {
- let aElement = aElements[i];
- if (aElement.className === 'loading-opts') {
- aElement.href += window.location.search; // CodeQL [SM01507] This code is not deployed and serves as local test code. No risk of malicious input.
- }
- }
- })();
- /** @type {any} */
- const global = self;
- global.getCodiconPath = () => {
- return `${corePath}/base/browser/ui/codicons/codicon/codicon.ttf`;
- };
- /**
- *
- * @param {()=>void} callback
- * @param {string} [PATH_PREFIX]
- */
- global.loadEditor = (callback, PATH_PREFIX) => {
- PATH_PREFIX = PATH_PREFIX || '';
- loadScript(`${PATH_PREFIX}${corePath}/loader.js`, () => {
- global.AMD = true;
- /** @type {{[name:string]: string;}} */
- const loaderPathsConfig = {};
- if (isRelease) {
- loaderPathsConfig['vs'] = `${PATH_PREFIX}${corePath}`;
- } else {
- loaderPathsConfig[
- 'vs/fillers/monaco-editor-core'
- ] = `${PATH_PREFIX}/monaco-editor/out/amd/fillers/monaco-editor-core-amd`;
- loaderPathsConfig['vs/language'] = `${PATH_PREFIX}${pluginPath}/language`;
- loaderPathsConfig['vs/basic-language'] = `${PATH_PREFIX}${pluginPath}/basic-language`;
- loaderPathsConfig['vs'] = `${PATH_PREFIX}${corePath}`;
- }
- console.log('LOADER CONFIG: ');
- console.log(JSON.stringify(loaderPathsConfig, null, '\t'));
- /** @type {any} */
- const req = require;
- req.config({
- paths: loaderPathsConfig
- // 'vs/nls' : {
- // availableLanguages: {
- // '*': 'de'
- // }
- // }
- });
- req(['vs/editor/editor.main'], () => {
- if (isRelease) {
- callback();
- return;
- }
- // At this point we've loaded the monaco-editor-core
- req(
- [
- 'vs/basic-languages/monaco.contribution',
- 'vs/language/css/monaco.contribution',
- 'vs/language/html/monaco.contribution',
- 'vs/language/json/monaco.contribution',
- 'vs/language/typescript/monaco.contribution'
- ],
- callback
- );
- });
- });
- };
- function parseQueryString() {
- const str = window.location.search.replace(/^\?/, '');
- const pieces = str.split(/&/);
- /** @type {{[name:string]: string;}} */
- const result = {};
- pieces.forEach((piece) => {
- const config = piece.split(/=/);
- result[config[0]] = config[1];
- });
- return result;
- }
- /**
- * @param {string} path
- */
- function resolvePath(path) {
- if (/^\//.test(path)) {
- return path;
- }
- return `/monaco-editor/${path}`;
- }
- /**
- * @param {boolean} isEditor
- */
- function renderLoadingOptions(isEditor) {
- const name = isEditor ? 'editor' : 'plugins';
- const paths = isEditor ? corePaths : pluginPaths;
- const selectedPath = isEditor ? editorQueryValue : pluginsQueryValue;
- return (
- '<strong style="width:130px;display:inline-block;">' +
- name +
- '</strong>:   ' +
- Object.keys(paths)
- .map((path) => {
- if (path === selectedPath) {
- return '<strong>' + path + '</strong>';
- }
- return '<a href="' + generateUrlForLoadingOption(isEditor, path) + '">' + path + '</a>';
- })
- .join('   ')
- );
- }
- /**
- * @param {boolean} isEditor
- * @param {string} value
- */
- function generateUrlForLoadingOption(isEditor, value) {
- /** @type {{[name:string]: string;}} */
- const newQueryOptions = {};
- const newEditorQueryValue = isEditor ? value : editorQueryValue;
- const newPluginsQueryValue = isEditor ? pluginsQueryValue : value;
- if (newEditorQueryValue !== defaultEditorQueryValue) {
- newQueryOptions[editorQueryName] = newEditorQueryValue;
- }
- if (newPluginsQueryValue !== defaultPluginsQueryValue) {
- newQueryOptions[pluginsQueryName] = newPluginsQueryValue;
- }
- let search = Object.keys(newQueryOptions)
- .map((key) => `${key}=${newQueryOptions[key]}`)
- .join('&');
- if (search.length > 0) {
- search = '?' + search;
- }
- return toHREF(search);
- }
- /**
- * @param {string} search
- */
- function toHREF(search) {
- let port = window.location.port;
- if (port.length > 0) {
- port = ':' + port;
- }
- return (
- window.location.protocol +
- '//' +
- window.location.hostname +
- port +
- window.location.pathname +
- search +
- window.location.hash
- );
- }
- function loadScript(path, callback) {
- const script = document.createElement('script');
- script.onload = callback;
- script.async = true;
- script.type = 'text/javascript';
- script.src = path;
- document.head.appendChild(script);
- }
- })();
|