|
1 | | - |
2 | | -import { Compartment } from '@codemirror/state' |
3 | | -import { EditorView } from '@codemirror/view' |
4 | 1 | import type { ThemeMode } from 'pane-registry' |
| 2 | +import { Compartment, EditorState } from '@codemirror/state' |
| 3 | +import { EditorView, drawSelection, keymap, lineNumbers } from '@codemirror/view' |
| 4 | +import { defaultHighlightStyle, syntaxHighlighting, StreamLanguage } from '@codemirror/language' |
| 5 | +import { defaultKeymap, history, historyKeymap } from '@codemirror/commands' |
| 6 | +import { css } from '@codemirror/lang-css' |
| 7 | +import { html } from '@codemirror/lang-html' |
| 8 | +import { javascript } from '@codemirror/lang-javascript' |
| 9 | +import { json } from '@codemirror/lang-json' |
| 10 | +import { xml } from '@codemirror/lang-xml' |
| 11 | +// import { oneDark } from '@codemirror/theme-one-dark' |
| 12 | +import { turtle } from '@codemirror/legacy-modes/mode/turtle' |
| 13 | +import { sparql } from '@codemirror/legacy-modes/mode/sparql' |
| 14 | +import { ntriples } from '@codemirror/legacy-modes/mode/ntriples' |
5 | 15 | import { darkThemeExtension } from './themes/dark' |
6 | 16 |
|
7 | 17 | export class SourceEditor { |
8 | | - private _view: EditorView | null = null |
9 | | - private _languageCompartment = new Compartment() |
10 | | - private _editableCompartment = new Compartment() |
| 18 | + private _view: any = null |
| 19 | + private _languageCompartment: any = null |
| 20 | + private _editableCompartment: any = null |
11 | 21 |
|
12 | 22 | async initialize(container: HTMLElement, initialDoc = '', contentType: string = 'text/turtle', theme: ThemeMode = 'dark') { |
13 | 23 | if (this._view) { |
14 | 24 | this._view.destroy() |
15 | 25 | } |
16 | | - const [ |
17 | | - { EditorState }, |
18 | | - { drawSelection, keymap, lineNumbers }, |
19 | | - { defaultHighlightStyle, syntaxHighlighting }, |
20 | | - { defaultKeymap, history, historyKeymap }, |
21 | | - { oneDark } |
22 | | - ] = await Promise.all([ |
23 | | - import(/* webpackChunkName: "codemirror-core" */ '@codemirror/state'), |
24 | | - import(/* webpackChunkName: "codemirror-core" */ '@codemirror/view'), |
25 | | - import(/* webpackChunkName: "codemirror-core" */ '@codemirror/language'), |
26 | | - import(/* webpackChunkName: "codemirror-core" */ '@codemirror/commands'), |
27 | | - import(/* webpackChunkName: "codemirror-core" */ '@codemirror/theme-one-dark') |
28 | | - ]) |
| 26 | + |
| 27 | + this._languageCompartment = new Compartment() |
| 28 | + this._editableCompartment = new Compartment() |
29 | 29 | const languageExtension = await this._getLanguageExtension(contentType) |
30 | 30 | /* we could add this if we want to update automatically |
31 | 31 | perhaps or tell the user they have unsaved changes , |
@@ -103,52 +103,39 @@ export class SourceEditor { |
103 | 103 | } |
104 | 104 |
|
105 | 105 | private async _getLanguageExtension(contentType: string) { |
106 | | - const getStreamLanguage = async () => |
107 | | - (await import(/* webpackChunkName: "codemirror-core" */ '@codemirror/language')).StreamLanguage |
108 | | - |
| 106 | + |
109 | 107 | switch (contentType) { |
110 | 108 | case 'text/turtle': |
111 | 109 | case 'text/n3': |
112 | | - const turtleStreamLanguage = await getStreamLanguage() |
113 | | - const { turtle } = await import(/* webpackChunkName: "lang-rdf" */ '@codemirror/legacy-modes/mode/turtle') |
114 | | - return turtleStreamLanguage.define(turtle) |
| 110 | + return StreamLanguage.define(turtle) |
115 | 111 |
|
116 | 112 | case 'application/sparql-update': |
117 | 113 | case 'application/sparql-query': |
118 | | - const sparqlStreamLanguage = await getStreamLanguage() |
119 | | - const { sparql } = await import(/* webpackChunkName: "lang-rdf" */ '@codemirror/legacy-modes/mode/sparql') |
120 | | - return sparqlStreamLanguage.define(sparql) |
| 114 | + return StreamLanguage.define(sparql) |
121 | 115 |
|
122 | 116 | case 'application/nquads': |
123 | 117 | case 'application/n-quads': |
124 | 118 | case 'application/n-triples': |
125 | | - const nTriplesStreamLanguage = await getStreamLanguage() |
126 | | - const { ntriples } = await import(/* webpackChunkName: "lang-rdf" */ '@codemirror/legacy-modes/mode/ntriples') |
127 | | - return nTriplesStreamLanguage.define(ntriples) |
| 119 | + return StreamLanguage.define(ntriples) |
128 | 120 |
|
129 | 121 | case 'application/json': |
130 | 122 | case 'application/ld+json': |
131 | | - const { json } = await import(/* webpackChunkName: "lang-json" */ '@codemirror/lang-json') |
132 | 123 | return json() |
133 | 124 |
|
134 | 125 | case 'text/html': |
135 | 126 | case 'application/xhtml+xml': |
136 | | - const { html } = await import(/* webpackChunkName: "lang-html" */ '@codemirror/lang-html') |
137 | 127 | return html() |
138 | 128 |
|
139 | 129 | case 'application/rdf+xml': |
140 | 130 | case 'application/xml': |
141 | | - const { xml } = await import(/* webpackChunkName: "lang-xml" */ '@codemirror/lang-xml') |
142 | 131 | return xml() |
143 | 132 |
|
144 | 133 | case 'text/css': |
145 | | - const { css } = await import(/* webpackChunkName: "lang-css" */ '@codemirror/lang-css') |
146 | 134 | return css() |
147 | 135 |
|
148 | 136 | case 'text/javascript': |
149 | 137 | case 'application/javascript': |
150 | 138 | case 'application/ecmascript': |
151 | | - const { javascript } = await import(/* webpackChunkName: "lang-javascript" */ '@codemirror/lang-javascript') |
152 | 139 | return javascript() |
153 | 140 |
|
154 | 141 | default: |
|
0 commit comments