@coldsmirk/inkstone-react 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,566 +1,5 @@
1
- import { catppuccinLatte, catppuccinMacchiato } from "@catppuccin/codemirror";
2
- import { flavors } from "@catppuccin/palette";
3
- import { indentUnit } from "@codemirror/language";
4
- import { EditorState, Prec } from "@codemirror/state";
5
- import { EditorView } from "@codemirror/view";
6
- import { ControlledEditorHost, codeMirrorLanguages, documentExtensions, loadLanguage, normalizeContext, normalizeContext as normalizeContext$1, searchPhrasesZhCn, searchPhrasesZhCn as searchPhrasesZhCn$1, setMinijinjaContext } from "@coldsmirk/inkstone-codemirror";
7
- import { useCallback, useEffect, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
8
- import { jsx } from "react/jsx-runtime";
9
- import { getHighlighter, shikiThemeId } from "@coldsmirk/inkstone-core";
10
- import { disabledKeybindings, ensureMonacoHost, installDisabledKeybindings, monacoLanguages } from "@coldsmirk/inkstone-monaco";
11
- import { Editor, loader } from "@monaco-editor/react";
12
- import { shikiToMonaco } from "@shikijs/monaco";
13
- //#region src/use-latest.ts
14
- function useLatest(value) {
15
- const ref = useRef(value);
16
- useInsertionEffect(() => {
17
- ref.current = value;
18
- });
19
- return ref;
20
- }
21
- //#endregion
22
- //#region src/codemirror-editor.tsx
23
- function toCssSize(value) {
24
- if (value === void 0) return;
25
- return typeof value === "number" ? `${value}px` : value;
26
- }
27
- function alphaOf(color, alphaValue) {
28
- return `rgba(${color.rgb.r}, ${color.rgb.g}, ${color.rgb.b}, ${alphaValue})`;
29
- }
30
- function completionIconMask(body) {
31
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">${body}</svg>`;
32
- return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
33
- }
34
- const COMPLETION_ICON_FALLBACK = completionIconMask("<circle cx=\"8\" cy=\"8\" r=\"2.5\"/>");
35
- const COMPLETION_ICONS = {
36
- keyword: completionIconMask("<path d=\"M5.5 5 2.5 8l3 3\"/><path d=\"m10.5 5 3 3-3 3\"/>"),
37
- function: completionIconMask("<path d=\"M10.8 3.4c-2-.4-2.9.7-3.2 2.5L6.4 12c-.3 1.7-1.2 2.2-2.6 1.8\"/><path d=\"M4.6 7.5h5\"/>"),
38
- method: completionIconMask("<path d=\"M10.8 3.4c-2-.4-2.9.7-3.2 2.5L6.4 12c-.3 1.7-1.2 2.2-2.6 1.8\"/><path d=\"M4.6 7.5h5\"/>"),
39
- variable: completionIconMask("<path d=\"M4 5c2.2 0 5.3 6 8 6\"/><path d=\"M12 5c-2.7 0-5.8 6-8 6\"/>"),
40
- constant: completionIconMask("<path d=\"M3.5 5.2h9\"/><path d=\"M6.2 5.2v6.3\"/><path d=\"M10.2 5.2v4.4c0 1.3.6 1.9 1.7 1.9\"/>"),
41
- property: completionIconMask("<circle cx=\"4.9\" cy=\"11.1\" r=\"1.8\"/><circle cx=\"11.1\" cy=\"4.9\" r=\"1.8\"/><path d=\"M6.4 9.6l3.2-3.2\"/>"),
42
- class: completionIconMask("<rect x=\"3.5\" y=\"3.5\" width=\"9\" height=\"9\" rx=\"2.2\"/>"),
43
- interface: completionIconMask("<circle cx=\"8\" cy=\"8\" r=\"4.5\"/>"),
44
- type: completionIconMask("<path d=\"M4 4.5h8\"/><path d=\"M8 4.5V12\"/>"),
45
- enum: completionIconMask("<path d=\"M6.5 4.5h6\"/><path d=\"M6.5 8h6\"/><path d=\"M6.5 11.5h6\"/><path d=\"M3.4 4.5h.01\"/><path d=\"M3.4 8h.01\"/><path d=\"M3.4 11.5h.01\"/>"),
46
- namespace: completionIconMask("<path d=\"M6.2 3.5c-1.3 0-1.9.6-1.9 1.9v1.2c0 .9-.4 1.4-1.3 1.4.9 0 1.3.5 1.3 1.4v1.2c0 1.3.6 1.9 1.9 1.9\"/><path d=\"M9.8 3.5c1.3 0 1.9.6 1.9 1.9v1.2c0 .9.4 1.4 1.3 1.4-.9 0-1.3.5-1.3 1.4v1.2c0 1.3-.6 1.9-1.9 1.9\"/>"),
47
- text: completionIconMask("<path d=\"M3.5 5h9\"/><path d=\"M3.5 8h9\"/><path d=\"M3.5 11h5.5\"/>")
48
- };
49
- function completionIconRules() {
50
- const rules = {};
51
- for (const [kind, mask] of Object.entries(COMPLETION_ICONS)) rules[`.cm-completionIcon-${kind}:after`] = {
52
- maskImage: mask,
53
- WebkitMaskImage: mask
54
- };
55
- return rules;
56
- }
57
- function chromeTheme(dark) {
58
- const { colors } = dark ? flavors.macchiato : flavors.latte;
59
- const hairline = `1px solid ${alphaOf(colors.overlay0, .35)}`;
60
- const frame = {
61
- border: hairline,
62
- borderRadius: "8px",
63
- boxShadow: dark ? "0 8px 24px rgba(0, 0, 0, 0.5)" : "0 8px 24px rgba(0, 0, 0, 0.12)"
64
- };
65
- return EditorView.theme({
66
- "&": { colorScheme: dark ? "dark" : "light" },
67
- ".cm-tooltip": frame,
68
- ".cm-tooltip.cm-tooltip-autocomplete": {
69
- ...frame,
70
- "& > ul": {
71
- borderRadius: "7px",
72
- padding: "4px",
73
- maxHeight: "16em"
74
- },
75
- "& > ul > li": {
76
- display: "flex",
77
- alignItems: "center",
78
- padding: "3px 8px",
79
- borderRadius: "5px",
80
- lineHeight: "1.45"
81
- }
82
- },
83
- ".cm-completionLabel": {
84
- minWidth: "0",
85
- overflow: "hidden",
86
- textOverflow: "ellipsis"
87
- },
88
- ".cm-completionMatchedText": {
89
- textDecoration: "none",
90
- fontWeight: "600",
91
- color: colors.blue.hex
92
- },
93
- ".cm-completionDetail": {
94
- marginLeft: "auto",
95
- paddingLeft: "12px",
96
- fontStyle: "normal",
97
- fontSize: "85%",
98
- color: colors.overlay1.hex
99
- },
100
- ".cm-completionIcon": {
101
- width: "14px",
102
- paddingRight: "8px",
103
- opacity: "1",
104
- color: colors.overlay1.hex
105
- },
106
- ".cm-completionIcon:after": {
107
- content: "''",
108
- display: "block",
109
- width: "12px",
110
- height: "12px",
111
- backgroundColor: "currentColor",
112
- maskImage: COMPLETION_ICON_FALLBACK,
113
- WebkitMaskImage: COMPLETION_ICON_FALLBACK,
114
- maskRepeat: "no-repeat",
115
- WebkitMaskRepeat: "no-repeat",
116
- maskPosition: "center",
117
- WebkitMaskPosition: "center",
118
- maskSize: "contain",
119
- WebkitMaskSize: "contain"
120
- },
121
- ...completionIconRules(),
122
- ".cm-completionIcon-keyword": { color: colors.mauve.hex },
123
- ".cm-completionIcon-function, .cm-completionIcon-method": { color: colors.blue.hex },
124
- ".cm-completionIcon-variable": { color: colors.peach.hex },
125
- ".cm-completionIcon-constant": { color: colors.sky.hex },
126
- ".cm-completionIcon-property": { color: colors.teal.hex },
127
- ".cm-completionIcon-namespace": { color: colors.sapphire.hex },
128
- ".cm-completionIcon-text": { color: colors.overlay1.hex },
129
- ".cm-completionIcon-class, .cm-completionIcon-type, .cm-completionIcon-interface, .cm-completionIcon-enum": { color: colors.yellow.hex },
130
- ".cm-tooltip.cm-completionInfo": {
131
- ...frame,
132
- padding: "8px 10px",
133
- maxWidth: "26em"
134
- },
135
- ".cm-tooltip-lint": { padding: "4px" },
136
- ".cm-diagnostic": {
137
- margin: "0",
138
- padding: "3px 8px",
139
- borderLeftWidth: "3px",
140
- borderRadius: "5px",
141
- lineHeight: "1.45"
142
- },
143
- ".cm-diagnostic-error": { borderLeftColor: colors.red.hex },
144
- ".cm-diagnostic-warning": { borderLeftColor: colors.yellow.hex },
145
- ".cm-diagnostic-info": { borderLeftColor: colors.overlay1.hex },
146
- ".cm-diagnostic-hint": { borderLeftColor: colors.blue.hex },
147
- ".cm-diagnosticAction": {
148
- padding: "2px 6px",
149
- backgroundColor: colors.surface1.hex,
150
- color: colors.text.hex,
151
- borderRadius: "4px"
152
- },
153
- ".cm-diagnosticSource": {
154
- fontSize: "85%",
155
- color: colors.overlay1.hex,
156
- opacity: "1"
157
- },
158
- "&.cm-focused": { outline: "none" },
159
- ".cm-activeLine": { backgroundColor: alphaOf(colors.overlay0, .12) },
160
- ".cm-activeLineGutter": { backgroundColor: alphaOf(colors.overlay0, .12) },
161
- "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": { backgroundColor: alphaOf(colors.blue, dark ? .35 : .25) },
162
- ".cm-selectionBackground": { backgroundColor: alphaOf(colors.blue, dark ? .2 : .14) },
163
- ".cm-content ::selection": { backgroundColor: alphaOf(colors.blue, dark ? .35 : .25) },
164
- ".cm-scroller, .cm-tooltip-autocomplete > ul, .cm-tooltip.cm-completionInfo": {
165
- scrollbarWidth: "thin",
166
- scrollbarColor: `${alphaOf(colors.overlay0, .55)} transparent`
167
- },
168
- ".cm-panels.cm-panels-top": { borderBottom: hairline },
169
- ".cm-panels.cm-panels-bottom": { borderTop: hairline },
170
- ".cm-panel.cm-search, .cm-panel.cm-gotoLine": {
171
- position: "relative",
172
- display: "flex",
173
- flexWrap: "wrap",
174
- alignItems: "center",
175
- columnGap: "8px",
176
- rowGap: "8px",
177
- margin: "0",
178
- padding: "10px 44px 10px 14px"
179
- },
180
- ".cm-panel.cm-search br": {
181
- flexBasis: "100%",
182
- height: "0",
183
- margin: "0",
184
- border: "none"
185
- },
186
- ".cm-panel.cm-search label, .cm-panel.cm-gotoLine label": {
187
- display: "inline-flex",
188
- alignItems: "center",
189
- gap: "6px",
190
- margin: "0",
191
- fontSize: "12.5px",
192
- color: colors.subtext0.hex,
193
- cursor: "pointer",
194
- userSelect: "none"
195
- },
196
- ".cm-panel.cm-search input[type=checkbox]": {
197
- margin: "0",
198
- width: "14px",
199
- height: "14px",
200
- accentColor: colors.blue.hex
201
- },
202
- ".cm-panel.cm-search button[name=close]": {
203
- position: "absolute",
204
- top: "10px",
205
- right: "10px",
206
- boxSizing: "border-box",
207
- width: "28px",
208
- height: "28px",
209
- padding: "0",
210
- display: "inline-flex",
211
- alignItems: "center",
212
- justifyContent: "center",
213
- fontSize: "16px",
214
- lineHeight: "1",
215
- color: colors.overlay1.hex,
216
- background: "transparent",
217
- border: "none",
218
- borderRadius: "6px",
219
- cursor: "pointer"
220
- },
221
- ".cm-panel.cm-search button[name=close]:hover": {
222
- backgroundColor: colors.surface0.hex,
223
- color: colors.text.hex
224
- },
225
- ".cm-panel .cm-textfield": {
226
- boxSizing: "border-box",
227
- height: "28px",
228
- width: "240px",
229
- maxWidth: "100%",
230
- margin: "0",
231
- padding: "0 10px",
232
- fontSize: "12.5px",
233
- color: colors.text.hex,
234
- backgroundColor: colors.base.hex,
235
- border: hairline,
236
- borderRadius: "6px"
237
- },
238
- ".cm-panel .cm-textfield:focus": {
239
- outline: "none",
240
- borderColor: alphaOf(colors.blue, .6),
241
- boxShadow: `0 0 0 2px ${alphaOf(colors.blue, .2)}`
242
- },
243
- ".cm-panel .cm-button": {
244
- boxSizing: "border-box",
245
- height: "28px",
246
- margin: "0",
247
- padding: "0 12px",
248
- fontSize: "12.5px",
249
- color: colors.text.hex,
250
- backgroundImage: "none",
251
- backgroundColor: colors.surface0.hex,
252
- border: hairline,
253
- borderRadius: "6px",
254
- cursor: "pointer"
255
- },
256
- ".cm-panel .cm-button:hover": { backgroundColor: colors.surface1.hex },
257
- ".cm-panel .cm-button:active": {
258
- backgroundImage: "none",
259
- backgroundColor: colors.surface1.hex
260
- }
261
- }, { dark });
262
- }
263
- function defaultThemeExtensions(dark, height, width, fontSize, lineHeight) {
264
- const extensions = [Prec.low(chromeTheme(dark)), Prec.low(dark ? catppuccinMacchiato : catppuccinLatte)];
265
- const cssHeight = toCssSize(height);
266
- const cssWidth = toCssSize(width);
267
- if (cssHeight !== void 0 || cssWidth !== void 0 || fontSize !== void 0 || lineHeight !== void 0) {
268
- const root = {};
269
- if (cssHeight !== void 0) root.height = cssHeight;
270
- if (cssWidth !== void 0) root.width = cssWidth;
271
- if (fontSize !== void 0) root.fontSize = `${fontSize}px`;
272
- const spec = { "&": root };
273
- const scroller = {};
274
- if (cssHeight !== void 0) scroller.overflow = "auto";
275
- if (lineHeight !== void 0) scroller.lineHeight = lineHeight < 8 ? String(lineHeight) : `${lineHeight}px`;
276
- if (Object.keys(scroller).length > 0) spec[".cm-scroller"] = scroller;
277
- extensions.push(EditorView.theme(spec));
278
- }
279
- return extensions;
280
- }
281
- function CodeMirrorEditor({ value, onChange, language, context, placeholder, lineWrapping = false, showLineNumbers = false, folding = false, spellcheck = false, search = false, extensions, dynamicExtensions, dark = false, locale = "en", height, width, fontSize = 14, lineHeight = 1.6, tabSize, className, onMount, onFocus, onBlur }) {
282
- const containerRef = useRef(null);
283
- const hostRef = useRef(null);
284
- const valueTransitionRef = useRef(false);
285
- const onChangeRef = useLatest(onChange);
286
- const onMountRef = useLatest(onMount);
287
- const onFocusRef = useLatest(onFocus);
288
- const onBlurRef = useLatest(onBlur);
289
- const lastContextRef = useRef(null);
290
- const [languageExtension, setLanguageExtension] = useState([]);
291
- useEffect(() => {
292
- if (!language) {
293
- setLanguageExtension([]);
294
- return;
295
- }
296
- let cancelled = false;
297
- loadLanguage(language).then((extension) => {
298
- if (!cancelled) setLanguageExtension([extension]);
299
- }).catch((error) => {
300
- console.error("inkstone: failed to load CodeMirror language", language, error);
301
- if (!cancelled) setLanguageExtension([]);
302
- });
303
- return () => {
304
- cancelled = true;
305
- };
306
- }, [language]);
307
- const dynamic = useMemo(() => [
308
- ...defaultThemeExtensions(dark, height, width, fontSize, lineHeight),
309
- ...tabSize === void 0 ? [] : [EditorState.tabSize.of(tabSize), indentUnit.of(" ".repeat(tabSize))],
310
- ...locale === "zh-cn" ? [searchPhrasesZhCn$1] : [],
311
- ...languageExtension,
312
- ...dynamicExtensions ?? []
313
- ], [
314
- dark,
315
- height,
316
- width,
317
- fontSize,
318
- lineHeight,
319
- tabSize,
320
- locale,
321
- languageExtension,
322
- dynamicExtensions
323
- ]);
324
- const contextSchema = useMemo(() => context ? normalizeContext$1(context) : null, [context]);
325
- useEffect(() => {
326
- const container = containerRef.current;
327
- if (!container) return;
328
- const host = new ControlledEditorHost({
329
- parent: container,
330
- doc: value,
331
- onChange: (next) => {
332
- if (!valueTransitionRef.current) onChangeRef.current?.(next);
333
- },
334
- extensions: [
335
- ...documentExtensions({
336
- placeholder,
337
- lineWrapping,
338
- showLineNumbers,
339
- folding,
340
- spellcheck,
341
- search
342
- }),
343
- EditorView.updateListener.of((update) => {
344
- if (update.focusChanged) if (update.view.hasFocus) onFocusRef.current?.();
345
- else onBlurRef.current?.();
346
- }),
347
- ...extensions ?? []
348
- ],
349
- dynamicExtensions: dynamic
350
- });
351
- hostRef.current = host;
352
- onMountRef.current?.(host.view);
353
- return () => {
354
- host.destroy();
355
- hostRef.current = null;
356
- };
357
- }, []);
358
- useInsertionEffect(() => {
359
- const host = hostRef.current;
360
- valueTransitionRef.current = host !== null && host.view.state.doc.toString() !== value;
361
- }, [value]);
362
- useLayoutEffect(() => {
363
- try {
364
- hostRef.current?.setValue(value);
365
- } finally {
366
- valueTransitionRef.current = false;
367
- }
368
- }, [value]);
369
- useEffect(() => {
370
- hostRef.current?.reconfigure(dynamic);
371
- }, [dynamic]);
372
- useEffect(() => {
373
- const host = hostRef.current;
374
- if (!host) return;
375
- const key = contextSchema ? JSON.stringify(contextSchema) : "";
376
- const last = lastContextRef.current;
377
- if (last && last.key === key && last.language === languageExtension) return;
378
- lastContextRef.current = {
379
- key,
380
- language: languageExtension
381
- };
382
- if (key === "" && (!last || last.key === "")) return;
383
- host.view.dispatch({ effects: setMinijinjaContext.of(contextSchema) });
384
- }, [contextSchema, languageExtension]);
385
- return /* @__PURE__ */ jsx("div", {
386
- ref: containerRef,
387
- className
388
- });
389
- }
390
- //#endregion
391
- //#region src/use-shiki-highlighter.ts
392
- function useShikiHighlighter() {
393
- const [state, setState] = useState("loading");
394
- const highlighterRef = useRef(null);
395
- useEffect(() => {
396
- let cancelled = false;
397
- getHighlighter().then((highlighter) => {
398
- if (cancelled) return;
399
- highlighterRef.current = highlighter;
400
- setState("ready");
401
- }).catch((error) => {
402
- console.error("inkstone: shiki highlighter failed to load", error);
403
- if (!cancelled) setState("failed");
404
- });
405
- return () => {
406
- cancelled = true;
407
- };
408
- }, []);
409
- return {
410
- state,
411
- highlighterRef
412
- };
413
- }
414
- //#endregion
415
- //#region src/monaco-editor.tsx
416
- const DEFAULT_MONACO_OPTIONS = {
417
- find: { addExtraSpaceOnTop: false },
418
- minimap: { enabled: false },
419
- fontSize: 14,
420
- lineHeight: 1.6,
421
- fontFamily: "var(--inkstone-font-family-code, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace)",
422
- scrollBeyondLastLine: false,
423
- automaticLayout: true,
424
- renderLineHighlight: "line",
425
- smoothScrolling: true,
426
- padding: {
427
- top: 12,
428
- bottom: 12
429
- },
430
- fixedOverflowWidgets: true,
431
- quickSuggestions: {
432
- other: true,
433
- comments: false,
434
- strings: true
435
- },
436
- wordBasedSuggestions: "off",
437
- tabCompletion: "on",
438
- scrollbar: {
439
- alwaysConsumeMouseWheel: false,
440
- verticalScrollbarSize: 8,
441
- horizontalScrollbarSize: 8
442
- }
443
- };
444
- function documentOptions({ placeholder, lineWrapping, showLineNumbers, folding, disableContextMenu, fontSize, lineHeight, tabSize }) {
445
- const resolved = {
446
- placeholder,
447
- wordWrap: lineWrapping ? "on" : "off",
448
- lineNumbers: showLineNumbers ? "on" : "off",
449
- folding,
450
- contextmenu: !disableContextMenu
451
- };
452
- if (fontSize !== void 0) resolved.fontSize = fontSize;
453
- if (lineHeight !== void 0) resolved.lineHeight = lineHeight;
454
- if (tabSize !== void 0) resolved.tabSize = tabSize;
455
- return resolved;
456
- }
457
- let loaderConfigured = false;
458
- function configureLoader(monaco) {
459
- if (loaderConfigured) return;
460
- loaderConfigured = true;
461
- loader.config({ monaco });
462
- }
463
- let shikiRegistered = false;
464
- function registerShikiHighlighting(monaco, highlighter) {
465
- if (shikiRegistered) return;
466
- shikiRegistered = true;
467
- const canonical = new Set(highlighter.getLoadedLanguages().map((id) => highlighter.getLanguage(id).name));
468
- const registered = new Set(monaco.languages.getLanguages().map((registeredLanguage) => registeredLanguage.id));
469
- for (const lang of canonical) if (!registered.has(lang)) monaco.languages.register({ id: lang });
470
- shikiToMonaco(highlighter, monaco);
471
- }
472
- function MonacoEditor({ value, onChange, language = "javascript", dark = false, locale, placeholder, lineWrapping = false, showLineNumbers = false, folding = false, disableContextMenu = false, disableFind = false, disableCommandPalette = false, fontSize, lineHeight, tabSize = 2, path, height = "100%", width, className, options, hostOptions, loading = "Loading editor…", failure = "Editor failed to load", beforeMount, onMount, onFocus, onBlur }) {
473
- const [hostState, setHostState] = useState("loading");
474
- const { state: shikiState, highlighterRef } = useShikiHighlighter();
475
- const hostOptionsRef = useRef(hostOptions);
476
- const localeRef = useRef(locale);
477
- const beforeMountRef = useLatest(beforeMount);
478
- const onMountRef = useLatest(onMount);
479
- const onFocusRef = useLatest(onFocus);
480
- const onBlurRef = useLatest(onBlur);
481
- const onChangeRef = useLatest(onChange);
482
- const appliedPathRef = useRef(path);
483
- const pathChangingRef = useRef(false);
484
- useInsertionEffect(() => {
485
- pathChangingRef.current = path !== appliedPathRef.current;
486
- }, [path]);
487
- useEffect(() => {
488
- appliedPathRef.current = path;
489
- pathChangingRef.current = false;
490
- }, [path]);
491
- const handleChange = useCallback((next) => {
492
- if (pathChangingRef.current) return;
493
- onChangeRef.current?.(next ?? "");
494
- }, [onChangeRef]);
495
- const mergedOptions = useMemo(() => {
496
- return {
497
- ...DEFAULT_MONACO_OPTIONS,
498
- ...documentOptions({
499
- placeholder,
500
- lineWrapping,
501
- showLineNumbers,
502
- folding,
503
- disableContextMenu,
504
- fontSize,
505
- lineHeight,
506
- tabSize
507
- }),
508
- ...options
509
- };
510
- }, [
511
- placeholder,
512
- lineWrapping,
513
- showLineNumbers,
514
- folding,
515
- disableContextMenu,
516
- fontSize,
517
- lineHeight,
518
- tabSize,
519
- options
520
- ]);
521
- useEffect(() => {
522
- let cancelled = false;
523
- ensureMonacoHost({
524
- ...hostOptionsRef.current,
525
- locale: localeRef.current ?? hostOptionsRef.current?.locale
526
- }).then((monaco) => {
527
- configureLoader(monaco);
528
- if (!cancelled) setHostState("ready");
529
- }).catch((error) => {
530
- console.error("inkstone: monaco host failed to load", error);
531
- if (!cancelled) setHostState("failed");
532
- });
533
- return () => {
534
- cancelled = true;
535
- };
536
- }, []);
537
- if (hostState === "failed") return failure;
538
- if (hostState === "loading" || shikiState === "loading") return loading;
539
- const handleBeforeMount = (monaco) => {
540
- const highlighter = highlighterRef.current;
541
- if (highlighter) registerShikiHighlighting(monaco, highlighter);
542
- beforeMountRef.current?.(monaco);
543
- };
544
- const handleMount = (editorInstance, monaco) => {
545
- installDisabledKeybindings(monaco, editorInstance, disabledKeybindings(monaco, disableFind, disableCommandPalette));
546
- editorInstance.onDidFocusEditorText(() => onFocusRef.current?.());
547
- editorInstance.onDidBlurEditorText(() => onBlurRef.current?.());
548
- onMountRef.current?.(editorInstance, monaco);
549
- };
550
- return /* @__PURE__ */ jsx(Editor, {
551
- beforeMount: handleBeforeMount,
552
- className,
553
- height,
554
- language,
555
- loading,
556
- options: mergedOptions,
557
- path,
558
- theme: shikiState === "ready" ? shikiThemeId(dark) : dark ? "vs-dark" : "vs",
559
- value,
560
- width,
561
- onChange: handleChange,
562
- onMount: handleMount
563
- });
564
- }
565
- //#endregion
566
- export { CodeMirrorEditor, DEFAULT_MONACO_OPTIONS, MonacoEditor, codeMirrorLanguages, monacoLanguages, normalizeContext, searchPhrasesZhCn, useShikiHighlighter };
1
+ import { a as CodeMirrorDiffEditor, i as CodeMirrorEditor, n as normalizeContext, r as searchPhrasesZhCn, t as codeMirrorLanguages } from "./codemirror-B27C5np1.js";
2
+ import { i as MonacoEditor, n as MonacoDiffEditor, r as DEFAULT_MONACO_OPTIONS, t as monacoLanguages } from "./monaco-CP5BIXrw.js";
3
+ import { t as useShikiHighlighter } from "./use-shiki-highlighter-CzSQcX2f.js";
4
+ import "./shiki.js";
5
+ export { CodeMirrorDiffEditor, CodeMirrorEditor, DEFAULT_MONACO_OPTIONS, MonacoDiffEditor, MonacoEditor, codeMirrorLanguages, monacoLanguages, normalizeContext, searchPhrasesZhCn, useShikiHighlighter };