diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /app/assets/javascripts/editor | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'app/assets/javascripts/editor')
-rw-r--r-- | app/assets/javascripts/editor/constants.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/editor/editor_lite.js | 37 |
2 files changed, 38 insertions, 0 deletions
diff --git a/app/assets/javascripts/editor/constants.js b/app/assets/javascripts/editor/constants.js index 9ee692e953a..b02eb37206a 100644 --- a/app/assets/javascripts/editor/constants.js +++ b/app/assets/javascripts/editor/constants.js @@ -5,3 +5,4 @@ export const EDITOR_LITE_INSTANCE_ERROR_NO_EL = __( ); export const URI_PREFIX = 'gitlab'; +export const CONTENT_UPDATE_DEBOUNCE = 250; diff --git a/app/assets/javascripts/editor/editor_lite.js b/app/assets/javascripts/editor/editor_lite.js index bbd5461ae4d..e52e64d4c2d 100644 --- a/app/assets/javascripts/editor/editor_lite.js +++ b/app/assets/javascripts/editor/editor_lite.js @@ -39,6 +39,26 @@ export default class Editor { monacoEditor.setModelLanguage(model, id); } + static pushToImportsArray(arr, toImport) { + arr.push(import(toImport)); + } + + static loadExtensions(extensions) { + if (!extensions) { + return Promise.resolve(); + } + const promises = []; + const extensionsArray = typeof extensions === 'string' ? extensions.split(',') : extensions; + + extensionsArray.forEach(ext => { + const prefix = ext.includes('/') ? '' : 'editor/'; + const trimmedExt = ext.replace(/^\//, '').trim(); + Editor.pushToImportsArray(promises, `~/${prefix}${trimmedExt}`); + }); + + return Promise.all(promises); + } + /** * Creates a monaco instance with the given options. * @@ -53,6 +73,7 @@ export default class Editor { blobPath = '', blobContent = '', blobGlobalId = '', + extensions = [], ...instanceOptions } = {}) { if (!el) { @@ -80,6 +101,22 @@ export default class Editor { model.dispose(); }); instance.updateModelLanguage = path => Editor.updateModelLanguage(path, instance); + instance.use = args => this.use(args, instance); + + Editor.loadExtensions(extensions, instance) + .then(modules => { + if (modules) { + modules.forEach(module => { + instance.use(module.default); + }); + } + }) + .then(() => { + el.dispatchEvent(new Event('editor-ready')); + }) + .catch(e => { + throw e; + }); this.instances.push(instance); return instance; |