2023-12-13 21:45:02 +02:00
|
|
|
|
|
|
|
import * as codeMirrorView from '@codemirror/view';
|
|
|
|
import * as codeMirrorState from '@codemirror/state';
|
2024-03-26 13:36:30 +02:00
|
|
|
import * as codeMirrorSearch from '@codemirror/search';
|
2023-12-13 21:45:02 +02:00
|
|
|
import * as codeMirrorLanguage from '@codemirror/language';
|
|
|
|
import * as codeMirrorAutocomplete from '@codemirror/autocomplete';
|
|
|
|
import * as codeMirrorCommands from '@codemirror/commands';
|
|
|
|
import * as codeMirrorLint from '@codemirror/lint';
|
2024-01-22 17:28:00 +02:00
|
|
|
import * as codeMirrorLangHtml from '@codemirror/lang-html';
|
|
|
|
import * as codeMirrorLangMarkdown from '@codemirror/lang-markdown';
|
|
|
|
import * as codeMirrorLanguageData from '@codemirror/language-data';
|
|
|
|
|
2023-12-13 21:45:02 +02:00
|
|
|
import * as lezerHighlight from '@lezer/highlight';
|
|
|
|
import * as lezerCommon from '@lezer/common';
|
|
|
|
import * as lezerMarkdown from '@lezer/markdown';
|
2024-01-22 17:28:00 +02:00
|
|
|
|
2023-12-13 21:45:02 +02:00
|
|
|
|
|
|
|
// Exposes CodeMirror libraries to plugins.
|
|
|
|
//
|
|
|
|
// Plugins can't bundle their own copies of the CodeMirror libraries, as multiple
|
|
|
|
// copies of some libraries can cause issues.
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-12-13 21:45:02 +02:00
|
|
|
const libraryNameToPackage: Record<string, any> = {
|
|
|
|
'@codemirror/view': codeMirrorView,
|
|
|
|
'@codemirror/state': codeMirrorState,
|
2024-03-26 13:36:30 +02:00
|
|
|
'@codemirror/search': codeMirrorSearch,
|
2023-12-13 21:45:02 +02:00
|
|
|
'@codemirror/language': codeMirrorLanguage,
|
|
|
|
'@codemirror/autocomplete': codeMirrorAutocomplete,
|
|
|
|
'@codemirror/commands': codeMirrorCommands,
|
|
|
|
'@codemirror/lint': codeMirrorLint,
|
|
|
|
'@codemirror/lang-html': codeMirrorLangHtml,
|
2024-01-22 17:28:00 +02:00
|
|
|
'@codemirror/lang-markdown': codeMirrorLangMarkdown,
|
2023-12-20 21:10:20 +02:00
|
|
|
'@codemirror/language-data': codeMirrorLanguageData,
|
2024-01-22 17:28:00 +02:00
|
|
|
|
2023-12-13 21:45:02 +02:00
|
|
|
'@lezer/common': lezerCommon,
|
|
|
|
'@lezer/markdown': lezerMarkdown,
|
2024-01-22 17:28:00 +02:00
|
|
|
'@lezer/highlight': lezerHighlight,
|
2023-12-13 21:45:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const codeMirrorRequire = (library: string) => {
|
|
|
|
// Here, we use hasOwnProperty instead of "in" to prevent
|
|
|
|
// require("constructor") or require("__proto__") from returning
|
|
|
|
// a constructor or prototype object.
|
|
|
|
if (libraryNameToPackage.hasOwnProperty(library)) {
|
|
|
|
return libraryNameToPackage[library];
|
|
|
|
}
|
|
|
|
|
2024-02-22 17:39:46 +02:00
|
|
|
// Although window.require doesn't work on mobile, some desktop-only plugins
|
|
|
|
// originally developed for CodeMirror 5 rely on it.
|
|
|
|
if (typeof window.require === 'function') {
|
|
|
|
return window.require(library);
|
|
|
|
}
|
|
|
|
|
2023-12-13 21:45:02 +02:00
|
|
|
throw new Error(`Cannot find library ${library}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default codeMirrorRequire;
|