@sanity/code-input 3.0.1 → 4.1.0

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.
Files changed (52) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +140 -64
  3. package/lib/_chunks/CodeMirrorProxy-3836f097.js +619 -0
  4. package/lib/_chunks/CodeMirrorProxy-3836f097.js.map +1 -0
  5. package/lib/_chunks/CodeMirrorProxy-e83d4d37.js +611 -0
  6. package/lib/_chunks/CodeMirrorProxy-e83d4d37.js.map +1 -0
  7. package/lib/_chunks/index-17e68aff.js +563 -0
  8. package/lib/_chunks/index-17e68aff.js.map +1 -0
  9. package/lib/_chunks/index-9a4cb814.js +549 -0
  10. package/lib/_chunks/index-9a4cb814.js.map +1 -0
  11. package/lib/{src/index.d.ts → index.d.ts} +18 -10
  12. package/lib/index.esm.js +1 -1
  13. package/lib/index.esm.js.map +1 -1
  14. package/lib/index.js +10 -1
  15. package/lib/index.js.map +1 -1
  16. package/package.json +53 -27
  17. package/src/CodeInput.tsx +72 -272
  18. package/src/LanguageField.tsx +33 -0
  19. package/src/LanguageInput.tsx +32 -0
  20. package/src/PreviewCode.tsx +40 -68
  21. package/src/__workshop__/index.ts +22 -0
  22. package/src/__workshop__/lazy.tsx +54 -0
  23. package/src/__workshop__/preview.tsx +24 -0
  24. package/src/__workshop__/props.tsx +24 -0
  25. package/src/codemirror/CodeMirrorProxy.tsx +157 -0
  26. package/src/codemirror/CodeModeContext.tsx +4 -0
  27. package/src/codemirror/defaultCodeModes.ts +109 -0
  28. package/src/codemirror/extensions/highlightLineExtension.ts +164 -0
  29. package/src/codemirror/extensions/theme.ts +61 -0
  30. package/src/codemirror/extensions/useCodeMirrorTheme.ts +63 -0
  31. package/src/codemirror/extensions/useFontSize.ts +24 -0
  32. package/src/codemirror/useCodeMirror-client.test.tsx +49 -0
  33. package/src/{ace-editor/AceEditor-server.test.tsx → codemirror/useCodeMirror-server.test.tsx} +3 -4
  34. package/src/codemirror/useCodeMirror.tsx +12 -0
  35. package/src/codemirror/useLanguageMode.tsx +52 -0
  36. package/src/config.ts +1 -13
  37. package/src/getMedia.tsx +0 -2
  38. package/src/index.ts +4 -11
  39. package/src/plugin.tsx +39 -0
  40. package/src/schema.tsx +3 -7
  41. package/src/types.ts +19 -3
  42. package/src/ui/focusRingStyle.ts +27 -0
  43. package/src/useFieldMember.ts +16 -0
  44. package/lib/_chunks/editorSupport-895caf32.esm.js +0 -2
  45. package/lib/_chunks/editorSupport-895caf32.esm.js.map +0 -1
  46. package/lib/_chunks/editorSupport-bda3d360.js +0 -2
  47. package/lib/_chunks/editorSupport-bda3d360.js.map +0 -1
  48. package/src/ace-editor/AceEditor-client.test.tsx +0 -37
  49. package/src/ace-editor/AceEditorLazy.tsx +0 -19
  50. package/src/ace-editor/editorSupport.ts +0 -34
  51. package/src/ace-editor/groq.ts +0 -630
  52. package/src/createHighlightMarkers.ts +0 -24
@@ -0,0 +1,619 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var CodeMirror = require('@uiw/react-codemirror');
6
+ var ui = require('@sanity/ui');
7
+ var codemirrorThemes = require('@uiw/codemirror-themes');
8
+ var highlight = require('@lezer/highlight');
9
+ var index = require('./index-17e68aff.js');
10
+ var language = require('@codemirror/language');
11
+ var state = require('@codemirror/state');
12
+ var view = require('@codemirror/view');
13
+ function _interopDefaultCompat(e) {
14
+ return e && typeof e === 'object' && 'default' in e ? e : {
15
+ default: e
16
+ };
17
+ }
18
+ var CodeMirror__default = /*#__PURE__*/_interopDefaultCompat(CodeMirror);
19
+ function useCodeMirrorTheme() {
20
+ const theme = ui.useTheme();
21
+ return react.useMemo(() => {
22
+ const {
23
+ code: codeFont
24
+ } = theme.sanity.fonts;
25
+ const {
26
+ base,
27
+ card,
28
+ dark,
29
+ syntax
30
+ } = theme.sanity.color;
31
+ return codemirrorThemes.createTheme({
32
+ theme: dark ? "dark" : "light",
33
+ settings: {
34
+ background: card.enabled.bg,
35
+ foreground: card.enabled.code.fg,
36
+ lineHighlight: card.enabled.bg,
37
+ fontFamily: codeFont.family,
38
+ caret: base.focusRing,
39
+ selection: ui.rgba(base.focusRing, 0.2),
40
+ selectionMatch: ui.rgba(base.focusRing, 0.4),
41
+ gutterBackground: card.disabled.bg,
42
+ gutterForeground: card.disabled.code.fg,
43
+ gutterActiveForeground: card.enabled.fg
44
+ },
45
+ styles: [{
46
+ tag: [highlight.tags.heading, highlight.tags.heading2, highlight.tags.heading3, highlight.tags.heading4, highlight.tags.heading5, highlight.tags.heading6],
47
+ color: card.enabled.fg
48
+ }, {
49
+ tag: highlight.tags.angleBracket,
50
+ color: card.enabled.code.fg
51
+ }, {
52
+ tag: highlight.tags.atom,
53
+ color: syntax.keyword
54
+ }, {
55
+ tag: highlight.tags.attributeName,
56
+ color: syntax.attrName
57
+ }, {
58
+ tag: highlight.tags.bool,
59
+ color: syntax.boolean
60
+ }, {
61
+ tag: highlight.tags.bracket,
62
+ color: card.enabled.code.fg
63
+ }, {
64
+ tag: highlight.tags.className,
65
+ color: syntax.className
66
+ }, {
67
+ tag: highlight.tags.comment,
68
+ color: syntax.comment
69
+ }, {
70
+ tag: highlight.tags.definition(highlight.tags.typeName),
71
+ color: syntax.function
72
+ }, {
73
+ tag: [highlight.tags.definition(highlight.tags.variableName), highlight.tags.function(highlight.tags.variableName), highlight.tags.className, highlight.tags.attributeName],
74
+ color: syntax.function
75
+ }, {
76
+ tag: [highlight.tags.function(highlight.tags.propertyName), highlight.tags.propertyName],
77
+ color: syntax.function
78
+ }, {
79
+ tag: highlight.tags.keyword,
80
+ color: syntax.keyword
81
+ }, {
82
+ tag: highlight.tags.null,
83
+ color: syntax.number
84
+ }, {
85
+ tag: highlight.tags.number,
86
+ color: syntax.number
87
+ }, {
88
+ tag: highlight.tags.meta,
89
+ color: card.enabled.code.fg
90
+ }, {
91
+ tag: highlight.tags.operator,
92
+ color: syntax.operator
93
+ }, {
94
+ tag: highlight.tags.propertyName,
95
+ color: syntax.property
96
+ }, {
97
+ tag: [highlight.tags.string, highlight.tags.special(highlight.tags.brace)],
98
+ color: syntax.string
99
+ }, {
100
+ tag: highlight.tags.tagName,
101
+ color: syntax.className
102
+ }, {
103
+ tag: highlight.tags.typeName,
104
+ color: syntax.keyword
105
+ }]
106
+ });
107
+ }, [theme]);
108
+ }
109
+ const defaultCodeModes = [{
110
+ name: "groq",
111
+ loader: () => import('@codemirror/lang-javascript').then(_ref => {
112
+ let {
113
+ javascript
114
+ } = _ref;
115
+ return javascript({
116
+ jsx: false
117
+ });
118
+ })
119
+ }, {
120
+ name: "javascript",
121
+ loader: () => import('@codemirror/lang-javascript').then(_ref2 => {
122
+ let {
123
+ javascript
124
+ } = _ref2;
125
+ return javascript({
126
+ jsx: false
127
+ });
128
+ })
129
+ }, {
130
+ name: "jsx",
131
+ loader: () => import('@codemirror/lang-javascript').then(_ref3 => {
132
+ let {
133
+ javascript
134
+ } = _ref3;
135
+ return javascript({
136
+ jsx: true
137
+ });
138
+ })
139
+ }, {
140
+ name: "typescript",
141
+ loader: () => import('@codemirror/lang-javascript').then(_ref4 => {
142
+ let {
143
+ javascript
144
+ } = _ref4;
145
+ return javascript({
146
+ jsx: false,
147
+ typescript: true
148
+ });
149
+ })
150
+ }, {
151
+ name: "tsx",
152
+ loader: () => import('@codemirror/lang-javascript').then(_ref5 => {
153
+ let {
154
+ javascript
155
+ } = _ref5;
156
+ return javascript({
157
+ jsx: true,
158
+ typescript: true
159
+ });
160
+ })
161
+ }, {
162
+ name: "php",
163
+ loader: () => import('@codemirror/lang-php').then(_ref6 => {
164
+ let {
165
+ php
166
+ } = _ref6;
167
+ return php();
168
+ })
169
+ }, {
170
+ name: "sql",
171
+ loader: () => import('@codemirror/lang-sql').then(_ref7 => {
172
+ let {
173
+ sql
174
+ } = _ref7;
175
+ return sql();
176
+ })
177
+ }, {
178
+ name: "mysql",
179
+ loader: () => import('@codemirror/lang-sql').then(_ref8 => {
180
+ let {
181
+ sql,
182
+ MySQL
183
+ } = _ref8;
184
+ return sql({
185
+ dialect: MySQL
186
+ });
187
+ })
188
+ }, {
189
+ name: "json",
190
+ loader: () => import('@codemirror/lang-json').then(_ref9 => {
191
+ let {
192
+ json
193
+ } = _ref9;
194
+ return json();
195
+ })
196
+ }, {
197
+ name: "markdown",
198
+ loader: () => import('@codemirror/lang-markdown').then(_ref10 => {
199
+ let {
200
+ markdown
201
+ } = _ref10;
202
+ return markdown();
203
+ })
204
+ }, {
205
+ name: "java",
206
+ loader: () => import('@codemirror/lang-java').then(_ref11 => {
207
+ let {
208
+ java
209
+ } = _ref11;
210
+ return java();
211
+ })
212
+ }, {
213
+ name: "html",
214
+ loader: () => import('@codemirror/lang-html').then(_ref12 => {
215
+ let {
216
+ html
217
+ } = _ref12;
218
+ return html();
219
+ })
220
+ }, {
221
+ name: "csharp",
222
+ loader: () => import('@codemirror/legacy-modes/mode/clike').then(_ref13 => {
223
+ let {
224
+ csharp
225
+ } = _ref13;
226
+ return language.StreamLanguage.define(csharp);
227
+ })
228
+ }, {
229
+ name: "sh",
230
+ loader: () => import('@codemirror/legacy-modes/mode/shell').then(_ref14 => {
231
+ let {
232
+ shell
233
+ } = _ref14;
234
+ return language.StreamLanguage.define(shell);
235
+ })
236
+ }, {
237
+ name: "css",
238
+ loader: () => import('@codemirror/legacy-modes/mode/css').then(_ref15 => {
239
+ let {
240
+ css
241
+ } = _ref15;
242
+ return language.StreamLanguage.define(css);
243
+ })
244
+ }, {
245
+ name: "scss",
246
+ loader: () => import('@codemirror/legacy-modes/mode/css').then(_ref16 => {
247
+ let {
248
+ css
249
+ } = _ref16;
250
+ return language.StreamLanguage.define(css);
251
+ })
252
+ }, {
253
+ name: "sass",
254
+ loader: () => import('@codemirror/legacy-modes/mode/sass').then(_ref17 => {
255
+ let {
256
+ sass
257
+ } = _ref17;
258
+ return language.StreamLanguage.define(sass);
259
+ })
260
+ }, {
261
+ name: "ruby",
262
+ loader: () => import('@codemirror/legacy-modes/mode/ruby').then(_ref18 => {
263
+ let {
264
+ ruby
265
+ } = _ref18;
266
+ return language.StreamLanguage.define(ruby);
267
+ })
268
+ }, {
269
+ name: "python",
270
+ loader: () => import('@codemirror/legacy-modes/mode/python').then(_ref19 => {
271
+ let {
272
+ python
273
+ } = _ref19;
274
+ return language.StreamLanguage.define(python);
275
+ })
276
+ }, {
277
+ name: "xml",
278
+ loader: () => import('@codemirror/legacy-modes/mode/xml').then(_ref20 => {
279
+ let {
280
+ xml
281
+ } = _ref20;
282
+ return language.StreamLanguage.define(xml);
283
+ })
284
+ }, {
285
+ name: "yaml",
286
+ loader: () => import('@codemirror/legacy-modes/mode/yaml').then(_ref21 => {
287
+ let {
288
+ yaml
289
+ } = _ref21;
290
+ return language.StreamLanguage.define(yaml);
291
+ })
292
+ }, {
293
+ name: "golang",
294
+ loader: () => import('@codemirror/legacy-modes/mode/go').then(_ref22 => {
295
+ let {
296
+ go
297
+ } = _ref22;
298
+ return language.StreamLanguage.define(go);
299
+ })
300
+ }, {
301
+ name: "text",
302
+ loader: () => void 0
303
+ }, {
304
+ name: "batch",
305
+ loader: () => void 0
306
+ }];
307
+ const highlightLineClass = "cm-highlight-line";
308
+ const addLineHighlight = state.StateEffect.define();
309
+ const removeLineHighlight = state.StateEffect.define();
310
+ const lineHighlightField = state.StateField.define({
311
+ create() {
312
+ return view.Decoration.none;
313
+ },
314
+ update(lines, tr) {
315
+ lines = lines.map(tr.changes);
316
+ for (const e of tr.effects) {
317
+ if (e.is(addLineHighlight)) {
318
+ lines = lines.update({
319
+ add: [lineHighlightMark.range(e.value)]
320
+ });
321
+ }
322
+ if (e.is(removeLineHighlight)) {
323
+ lines = lines.update({
324
+ filter: from => {
325
+ return from !== e.value;
326
+ }
327
+ });
328
+ }
329
+ }
330
+ return lines;
331
+ },
332
+ toJSON(value, state) {
333
+ const highlightLines = [];
334
+ const iter = value.iter();
335
+ while (iter.value) {
336
+ const lineNumber = state.doc.lineAt(iter.from).number;
337
+ if (!highlightLines.includes(lineNumber)) {
338
+ highlightLines.push(lineNumber);
339
+ }
340
+ iter.next();
341
+ }
342
+ return highlightLines;
343
+ },
344
+ fromJSON(value, state) {
345
+ const lines = state.doc.lines;
346
+ const highlights = value.filter(line => line <= lines).map(line => lineHighlightMark.range(state.doc.line(line).from));
347
+ return view.Decoration.none.update({
348
+ add: highlights
349
+ });
350
+ },
351
+ provide: f => view.EditorView.decorations.from(f)
352
+ });
353
+ const lineHighlightMark = view.Decoration.line({
354
+ class: highlightLineClass
355
+ });
356
+ const highlightState = {
357
+ highlight: lineHighlightField
358
+ };
359
+ function createCodeMirrorTheme(options) {
360
+ const {
361
+ themeCtx
362
+ } = options;
363
+ const dark = {
364
+ color: themeCtx.theme.color.dark[themeCtx.tone]
365
+ };
366
+ const light = {
367
+ color: themeCtx.theme.color.light[themeCtx.tone]
368
+ };
369
+ return view.EditorView.baseTheme({
370
+ ".cm-lineNumbers": {
371
+ cursor: "default"
372
+ },
373
+ ".cm-line.cm-line": {
374
+ position: "relative"
375
+ },
376
+ // need set background with pseudoelement so it does not render over selection color
377
+ [".".concat(highlightLineClass, "::before")]: {
378
+ position: "absolute",
379
+ top: 0,
380
+ bottom: 0,
381
+ left: 0,
382
+ right: 0,
383
+ zIndex: -3,
384
+ content: "''",
385
+ boxSizing: "border-box"
386
+ },
387
+ ["&dark .".concat(highlightLineClass, "::before")]: {
388
+ background: ui.rgba(dark.color.muted.caution.pressed.bg, 0.5)
389
+ },
390
+ ["&light .".concat(highlightLineClass, "::before")]: {
391
+ background: ui.rgba(light.color.muted.caution.pressed.bg, 0.75)
392
+ }
393
+ });
394
+ }
395
+ const highlightLine = config => {
396
+ const highlightTheme = createCodeMirrorTheme({
397
+ themeCtx: config.theme
398
+ });
399
+ return [lineHighlightField, config.readOnly ? [] : view.lineNumbers({
400
+ domEventHandlers: {
401
+ mousedown: (editorView, lineInfo) => {
402
+ const line = editorView.state.doc.lineAt(lineInfo.from);
403
+ let isHighlighted = false;
404
+ editorView.state.field(lineHighlightField).between(line.from, line.to, (from, to, value) => {
405
+ if (value) {
406
+ isHighlighted = true;
407
+ return false;
408
+ }
409
+ return void 0;
410
+ });
411
+ if (isHighlighted) {
412
+ editorView.dispatch({
413
+ effects: removeLineHighlight.of(line.from)
414
+ });
415
+ } else {
416
+ editorView.dispatch({
417
+ effects: addLineHighlight.of(line.from)
418
+ });
419
+ }
420
+ if (config == null ? void 0 : config.onHighlightChange) {
421
+ config.onHighlightChange(editorView.state.toJSON(highlightState).highlight);
422
+ }
423
+ return true;
424
+ }
425
+ }
426
+ }), highlightTheme];
427
+ };
428
+ function setHighlightedLines(view, highlightLines) {
429
+ const doc = view.state.doc;
430
+ const lines = doc.lines;
431
+ const allLineNumbers = Array.from({
432
+ length: lines
433
+ }, (x, i) => i + 1);
434
+ view.dispatch({
435
+ effects: allLineNumbers.map(lineNumber => {
436
+ const line = doc.line(lineNumber);
437
+ if (highlightLines == null ? void 0 : highlightLines.includes(lineNumber)) {
438
+ return addLineHighlight.of(line.from);
439
+ }
440
+ return removeLineHighlight.of(line.from);
441
+ })
442
+ });
443
+ }
444
+ function useFontSizeExtension(props) {
445
+ const {
446
+ fontSize: fontSizeProp
447
+ } = props;
448
+ const theme = ui.useTheme();
449
+ return react.useMemo(() => {
450
+ const {
451
+ code: codeFont
452
+ } = theme.sanity.fonts;
453
+ const {
454
+ fontSize,
455
+ lineHeight
456
+ } = codeFont.sizes[fontSizeProp] || codeFont.sizes[2];
457
+ return view.EditorView.baseTheme({
458
+ "&": {
459
+ fontSize: ui.rem(fontSize)
460
+ },
461
+ "& .cm-scroller": {
462
+ lineHeight: "".concat(lineHeight / fontSize, " !important")
463
+ }
464
+ });
465
+ }, [fontSizeProp, theme]);
466
+ }
467
+ function useThemeExtension() {
468
+ const themeCtx = ui.useRootTheme();
469
+ return react.useMemo(() => {
470
+ const dark = {
471
+ color: themeCtx.theme.color.dark[themeCtx.tone]
472
+ };
473
+ const light = {
474
+ color: themeCtx.theme.color.light[themeCtx.tone]
475
+ };
476
+ return view.EditorView.baseTheme({
477
+ "&.cm-editor": {
478
+ height: "100%"
479
+ },
480
+ "&.cm-editor.cm-focused": {
481
+ outline: "none"
482
+ },
483
+ // Matching brackets
484
+ "&.cm-editor.cm-focused .cm-matchingBracket": {
485
+ backgroundColor: "transparent"
486
+ },
487
+ "&.cm-editor.cm-focused .cm-nonmatchingBracket": {
488
+ backgroundColor: "transparent"
489
+ },
490
+ "&dark.cm-editor.cm-focused .cm-matchingBracket": {
491
+ outline: "1px solid ".concat(dark.color.base.border)
492
+ },
493
+ "&dark.cm-editor.cm-focused .cm-nonmatchingBracket": {
494
+ outline: "1px solid ".concat(dark.color.base.border)
495
+ },
496
+ "&light.cm-editor.cm-focused .cm-matchingBracket": {
497
+ outline: "1px solid ".concat(light.color.base.border)
498
+ },
499
+ "&light.cm-editor.cm-focused .cm-nonmatchingBracket": {
500
+ outline: "1px solid ".concat(light.color.base.border)
501
+ },
502
+ // Size and padding of gutter
503
+ "& .cm-lineNumbers .cm-gutterElement": {
504
+ minWidth: "32px !important",
505
+ padding: "0 8px !important"
506
+ },
507
+ "& .cm-gutter.cm-foldGutter": {
508
+ width: "0px !important"
509
+ },
510
+ // Color of gutter
511
+ "&dark .cm-gutters": {
512
+ color: "".concat(ui.rgba(dark.color.card.enabled.code.fg, 0.5), " !important"),
513
+ borderRight: "1px solid ".concat(ui.rgba(dark.color.base.border, 0.5))
514
+ },
515
+ "&light .cm-gutters": {
516
+ color: "".concat(ui.rgba(light.color.card.enabled.code.fg, 0.5), " !important"),
517
+ borderRight: "1px solid ".concat(ui.rgba(light.color.base.border, 0.5))
518
+ }
519
+ });
520
+ }, [themeCtx]);
521
+ }
522
+ const CodeMirrorProxy = react.forwardRef(function CodeMirrorProxy2(props, ref) {
523
+ const {
524
+ basicSetup: basicSetupProp,
525
+ highlightLines,
526
+ languageMode,
527
+ onHighlightChange,
528
+ readOnly,
529
+ value,
530
+ ...codeMirrorProps
531
+ } = props;
532
+ const themeCtx = ui.useRootTheme();
533
+ const codeMirrorTheme = useCodeMirrorTheme();
534
+ const [editorView, setEditorView] = react.useState(void 0);
535
+ const themeExtension = useThemeExtension();
536
+ const fontSizeExtension = useFontSizeExtension({
537
+ fontSize: 1
538
+ });
539
+ const languageExtension = useLanguageExtension(languageMode);
540
+ const highlightLineExtension = react.useMemo(() => highlightLine({
541
+ onHighlightChange,
542
+ readOnly,
543
+ theme: themeCtx
544
+ }), [onHighlightChange, readOnly, themeCtx]);
545
+ const extensions = react.useMemo(() => {
546
+ const baseExtensions = [themeExtension, fontSizeExtension, highlightLineExtension, view.EditorView.lineWrapping];
547
+ if (languageExtension) {
548
+ return [...baseExtensions, languageExtension];
549
+ }
550
+ return baseExtensions;
551
+ }, [fontSizeExtension, highlightLineExtension, languageExtension, themeExtension]);
552
+ react.useEffect(() => {
553
+ if (editorView) {
554
+ setHighlightedLines(editorView, highlightLines != null ? highlightLines : []);
555
+ }
556
+ }, [editorView, highlightLines, value]);
557
+ const initialState = react.useMemo(() => {
558
+ return {
559
+ json: {
560
+ doc: value != null ? value : "",
561
+ selection: {
562
+ main: 0,
563
+ ranges: [{
564
+ anchor: 0,
565
+ head: 0
566
+ }]
567
+ },
568
+ highlight: highlightLines != null ? highlightLines : []
569
+ },
570
+ fields: highlightState
571
+ };
572
+ }, []);
573
+ const handleCreateEditor = react.useCallback(view => {
574
+ setEditorView(view);
575
+ }, []);
576
+ const basicSetup = react.useMemo(() => basicSetupProp != null ? basicSetupProp : {
577
+ highlightActiveLine: false
578
+ }, [basicSetupProp]);
579
+ return /* @__PURE__ */jsxRuntime.jsx(CodeMirror__default.default, {
580
+ ...codeMirrorProps,
581
+ value,
582
+ ref,
583
+ extensions,
584
+ theme: codeMirrorTheme,
585
+ onCreateEditor: handleCreateEditor,
586
+ initialState,
587
+ basicSetup
588
+ });
589
+ });
590
+ function useLanguageExtension(mode) {
591
+ const codeConfig = react.useContext(index.CodeInputConfigContext);
592
+ const [languageExtension, setLanguageExtension] = react.useState();
593
+ react.useEffect(() => {
594
+ var _a;
595
+ const customModes = (_a = codeConfig == null ? void 0 : codeConfig.codeModes) != null ? _a : [];
596
+ const modes = [...customModes, ...defaultCodeModes];
597
+ const codeMode = modes.find(m => m.name === mode);
598
+ if (!(codeMode == null ? void 0 : codeMode.loader)) {
599
+ console.warn("Found no codeMode for language mode ".concat(mode, ", syntax highlighting will be disabled."));
600
+ }
601
+ let active = true;
602
+ Promise.resolve(codeMode == null ? void 0 : codeMode.loader()).then(extension => {
603
+ if (active) {
604
+ setLanguageExtension(extension);
605
+ }
606
+ }).catch(e => {
607
+ console.error("Failed to load language mode ".concat(mode), e);
608
+ if (active) {
609
+ setLanguageExtension(void 0);
610
+ }
611
+ });
612
+ return () => {
613
+ active = false;
614
+ };
615
+ }, [mode, codeConfig]);
616
+ return languageExtension;
617
+ }
618
+ exports.default = CodeMirrorProxy;
619
+ //# sourceMappingURL=CodeMirrorProxy-3836f097.js.map