|
13 | 13 | export let rightMarkers = [];
|
14 | 14 | export let provideCodeActions = null;
|
15 | 15 |
|
| 16 | + export let waiting = null; |
16 | 17 | let rootElement,
|
17 | 18 | editor,
|
18 | 19 | setLeftValue,
|
|
21 | 22 | setRightMarkers,
|
22 | 23 | getLeftEditor,
|
23 | 24 | codeActionProviderDisposable;
|
| 25 | + const loadingMonaco = loadMonacoEditor(); |
| 26 | + // eslint-disable-next-line no-use-before-define -- TODO |
| 27 | + $: loading = Promise.all([waiting, loadingMonaco]); |
24 | 28 | $: {
|
25 | 29 | if (setLeftValue) {
|
26 | 30 | setLeftValue(code);
|
|
44 | 48 | $: {
|
45 | 49 | disposeCodeActionProvider();
|
46 | 50 | if (provideCodeActions) {
|
47 |
| - loadMonacoEditor().then((monaco) => { |
| 51 | + loadingMonaco.then((monaco) => { |
48 | 52 | codeActionProviderDisposable = monaco.languages.registerCodeActionProvider(language, {
|
49 | 53 | provideCodeActions(model, range, context) {
|
50 | 54 | const editor = getLeftEditor?.();
|
|
63 | 67 | }
|
64 | 68 | }
|
65 | 69 |
|
| 70 | + let started = false; |
66 | 71 | onMount(async () => {
|
67 |
| - const monaco = await loadMonacoEditor(); |
| 72 | + started = true; |
| 73 | + await loading; |
| 74 | + const monaco = await loadingMonaco; |
68 | 75 | const options = {
|
69 | 76 | value: code,
|
70 | 77 | readOnly,
|
|
172 | 179 | }
|
173 | 180 | }
|
174 | 181 | async function updateMarkers(editor, markers) {
|
175 |
| - const monaco = await loadMonacoEditor(); |
| 182 | + const monaco = await loadingMonaco; |
176 | 183 | const model = editor.getModel();
|
177 | 184 | const id = editor.getId();
|
178 | 185 | monaco.editor.setModelMarkers(model, id, JSON.parse(JSON.stringify(markers)));
|
|
206 | 213 | codeActionProviderDisposable.dispose();
|
207 | 214 | }
|
208 | 215 | }
|
| 216 | +
|
| 217 | + function typewriter(node, { speed = 50 }) { |
| 218 | + const valid = |
| 219 | + node.childNodes.length === 0 || |
| 220 | + (node.childNodes.length === 1 && node.childNodes[0].nodeType === Node.TEXT_NODE); |
| 221 | +
|
| 222 | + if (!valid) { |
| 223 | + throw new Error(`This transition only works on elements with a single text node child`); |
| 224 | + } |
| 225 | +
|
| 226 | + const texts = node.textContent.split(/(?=\S)/); |
| 227 | + const duration = texts.length * speed; |
| 228 | +
|
| 229 | + return { |
| 230 | + duration, |
| 231 | + tick: (t) => { |
| 232 | + const i = ~~(texts.length * t); |
| 233 | + node.textContent = texts.slice(0, i).join(''); |
| 234 | + } |
| 235 | + }; |
| 236 | + } |
209 | 237 | </script>
|
210 | 238 |
|
211 |
| -<div bind:this={rootElement} class="root" /> |
| 239 | +{#await loading} |
| 240 | + {#if started} |
| 241 | + {#if diffEditor} |
| 242 | + <div |
| 243 | + class="eslint-editor-monaco-root eslint-editor-monaco-root--wait eslint-editor-monaco-root__flex" |
| 244 | + > |
| 245 | + <pre in:typewriter>Loading...</pre> |
| 246 | + <pre in:typewriter>Loading...</pre> |
| 247 | + </div> |
| 248 | + {:else} |
| 249 | + <pre |
| 250 | + class="eslint-editor-monaco-root eslint-editor-monaco-root--wait" |
| 251 | + in:typewriter>Loading...</pre> |
| 252 | + {/if} |
| 253 | + {/if} |
| 254 | +{:then _} |
| 255 | + <div bind:this={rootElement} class="eslint-editor-monaco-root" /> |
| 256 | +{/await} |
212 | 257 |
|
213 | 258 | <style>
|
214 |
| - .root { |
| 259 | + .eslint-editor-monaco-root { |
215 | 260 | width: 100%;
|
216 | 261 | height: 100%;
|
217 | 262 | }
|
| 263 | +
|
| 264 | + .eslint-editor-monaco-root--wait { |
| 265 | + color: #9cdcfe; |
| 266 | + border: 1px solid #cfd4db; |
| 267 | + background-color: #282c34; |
| 268 | + font-family: Menlo, Monaco, 'Courier New', monospace; |
| 269 | + font-size: 14px; |
| 270 | + line-height: 21px; |
| 271 | + padding-left: 52px; |
| 272 | + } |
| 273 | + .eslint-editor-monaco-root__flex { |
| 274 | + display: flex; |
| 275 | + } |
| 276 | + .eslint-editor-monaco-root__flex > * { |
| 277 | + height: 100%; |
| 278 | + width: 50%; |
| 279 | + } |
218 | 280 | </style>
|
0 commit comments