diff options
author | silverwind <me@silverwind.io> | 2022-02-26 16:47:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-26 23:47:52 +0800 |
commit | 329b9591601b444a645f14fd9e0ec086a6bb7eeb (patch) | |
tree | 52d97d279d87a948e76497c43166bf19ac15b013 /web_src/js | |
parent | 6d55a132a5b706e05cfdd02f8ff597972665c554 (diff) | |
download | gitea-329b9591601b444a645f14fd9e0ec086a6bb7eeb.tar.gz gitea-329b9591601b444a645f14fd9e0ec086a6bb7eeb.zip |
Remove CodeMirror dependencies (#18911)
EasyMDE already loads all the modes and plugins it needs, so there is no reason for neither the webpack dependency nor the vendored copy
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/features/comp/EasyMDE.js | 43 |
1 files changed, 3 insertions, 40 deletions
diff --git a/web_src/js/features/comp/EasyMDE.js b/web_src/js/features/comp/EasyMDE.js index 9d711088d8..af28c0b0ee 100644 --- a/web_src/js/features/comp/EasyMDE.js +++ b/web_src/js/features/comp/EasyMDE.js @@ -1,50 +1,13 @@ import $ from 'jquery'; import attachTribute from '../tribute.js'; -const {appSubUrl} = window.config; - -function loadScript(url) { - return new Promise((resolve, reject) => { - const script = document.createElement('script'); - script.async = true; - script.addEventListener('load', () => { - resolve(); - }); - script.addEventListener('error', (e) => { - reject(e.error); - }); - script.src = url; - document.body.appendChild(script); - }); -} - /** * @returns {EasyMDE} */ export async function importEasyMDE() { - // for CodeMirror: the plugins should be loaded dynamically - // https://github.com/codemirror/CodeMirror/issues/5484 - // https://github.com/codemirror/CodeMirror/issues/4838 - - // EasyMDE's CSS should be loaded via webpack config, otherwise our own styles can not overwrite the default styles. - const [{default: EasyMDE}, {default: CodeMirror}] = await Promise.all([ - import(/* webpackChunkName: "easymde" */'easymde'), - import(/* webpackChunkName: "codemirror" */'codemirror'), - ]); - - // CodeMirror plugins must be loaded by a "Plain browser env" - window.CodeMirror = CodeMirror; - await Promise.all([ - loadScript(`${appSubUrl}/assets/vendor/plugins/codemirror/addon/mode/loadmode.js`), - loadScript(`${appSubUrl}/assets/vendor/plugins/codemirror/mode/meta.js`), - ]); - - // the loadmode.js/meta.js would set the modeURL/modeInfo properties, so we check it to make sure our loading works - if (!CodeMirror.modeURL || !CodeMirror.modeInfo) { - throw new Error('failed to load plugins for CodeMirror'); - } - - CodeMirror.modeURL = `${appSubUrl}/assets/vendor/plugins/codemirror/mode/%N/%N.js`; + // EasyMDE's CSS should be loaded via webpack config, otherwise our own styles can + // not overwrite the default styles. + const {default: EasyMDE} = await import(/* webpackChunkName: "easymde" */'easymde'); return EasyMDE; } |