@sanity/code-input 2.29.5-get-started-template.15 → 2.29.5-purple-unicorn.807

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 (113) hide show
  1. package/CodeInput.js +7 -0
  2. package/deprecatedSchema.js +7 -0
  3. package/lib/CodeInput.cjs +39 -0
  4. package/lib/CodeInput.cjs.map +1 -0
  5. package/lib/CodeInput.js +33 -333
  6. package/lib/CodeInput.js.map +1 -0
  7. package/lib/_CodeInput-d6f5810b.js +846 -0
  8. package/lib/_CodeInput-d6f5810b.js.map +1 -0
  9. package/lib/_CodeInput-f70e9606.cjs +857 -0
  10. package/lib/_CodeInput-f70e9606.cjs.map +1 -0
  11. package/lib/_reExport.js +19 -0
  12. package/lib/deprecatedSchema.cjs +23 -0
  13. package/lib/deprecatedSchema.cjs.map +1 -0
  14. package/lib/deprecatedSchema.js +19 -24
  15. package/lib/deprecatedSchema.js.map +1 -0
  16. package/lib/dts/src/CodeInput.d.ts +17 -0
  17. package/lib/dts/src/CodeInput.d.ts.map +1 -0
  18. package/lib/dts/src/CodeInput.js +155 -0
  19. package/lib/dts/src/CodeInput.js.map +1 -0
  20. package/{dist/dts → lib/dts/src}/PreviewCode.d.ts +8 -8
  21. package/lib/dts/src/PreviewCode.d.ts.map +1 -0
  22. package/lib/dts/src/PreviewCode.js +50 -0
  23. package/lib/dts/src/PreviewCode.js.map +1 -0
  24. package/lib/dts/src/__workshop__/dev.d.ts +3 -0
  25. package/lib/dts/src/__workshop__/dev.d.ts.map +1 -0
  26. package/lib/dts/src/__workshop__/dev.js +18 -0
  27. package/lib/dts/src/__workshop__/dev.js.map +1 -0
  28. package/lib/dts/src/__workshop__/index.d.ts +3 -0
  29. package/lib/dts/src/__workshop__/index.d.ts.map +1 -0
  30. package/lib/dts/src/__workshop__/index.js +10 -0
  31. package/lib/dts/src/__workshop__/index.js.map +1 -0
  32. package/{dist/dts → lib/dts/src}/config.d.ts +15 -15
  33. package/lib/dts/src/config.d.ts.map +1 -0
  34. package/lib/dts/src/config.js +38 -0
  35. package/lib/dts/src/config.js.map +1 -0
  36. package/{dist/dts → lib/dts/src}/createHighlightMarkers.d.ts +3 -3
  37. package/lib/dts/src/createHighlightMarkers.d.ts.map +1 -0
  38. package/lib/dts/src/createHighlightMarkers.js +22 -0
  39. package/lib/dts/src/createHighlightMarkers.js.map +1 -0
  40. package/{dist/dts → lib/dts/src}/deprecatedSchema.d.ts +11 -11
  41. package/lib/dts/src/deprecatedSchema.d.ts.map +1 -0
  42. package/lib/dts/src/deprecatedSchema.js +19 -0
  43. package/lib/dts/src/deprecatedSchema.js.map +1 -0
  44. package/{dist/dts → lib/dts/src}/editorSupport.d.ts +27 -27
  45. package/lib/dts/src/editorSupport.d.ts.map +1 -0
  46. package/lib/dts/src/editorSupport.js +32 -0
  47. package/lib/dts/src/editorSupport.js.map +1 -0
  48. package/{dist/dts → lib/dts/src}/getMedia.d.ts +2 -2
  49. package/lib/dts/src/getMedia.d.ts.map +1 -0
  50. package/lib/dts/src/getMedia.js +35 -0
  51. package/lib/dts/src/getMedia.js.map +1 -0
  52. package/lib/dts/src/groq.d.ts +2 -0
  53. package/lib/dts/src/groq.d.ts.map +1 -0
  54. package/lib/dts/src/groq.js +612 -0
  55. package/lib/dts/src/groq.js.map +1 -0
  56. package/lib/dts/src/index.d.ts +4 -0
  57. package/lib/dts/src/index.d.ts.map +1 -0
  58. package/lib/dts/src/index.js +7 -0
  59. package/lib/dts/src/index.js.map +1 -0
  60. package/lib/dts/src/schema.d.ts +47 -0
  61. package/lib/dts/src/schema.d.ts.map +1 -0
  62. package/lib/dts/src/schema.js +59 -0
  63. package/lib/dts/src/schema.js.map +1 -0
  64. package/{dist/dts → lib/dts/src}/types.d.ts +28 -28
  65. package/lib/dts/src/types.d.ts.map +1 -0
  66. package/lib/dts/src/types.js +2 -0
  67. package/lib/dts/src/types.js.map +1 -0
  68. package/lib/dts/tsconfig.tsbuildinfo +1 -0
  69. package/lib/index.cjs +45 -0
  70. package/lib/index.cjs.map +1 -0
  71. package/lib/index.js +43 -0
  72. package/lib/index.js.map +1 -0
  73. package/lib/schema.cjs +174 -0
  74. package/lib/schema.cjs.map +1 -0
  75. package/lib/schema.js +159 -62
  76. package/lib/schema.js.map +1 -0
  77. package/package.json +63 -12
  78. package/schema.js +7 -0
  79. package/src/CodeInput.tsx +327 -0
  80. package/src/PreviewCode.tsx +89 -0
  81. package/src/__workshop__/dev.tsx +35 -0
  82. package/src/__workshop__/index.ts +10 -0
  83. package/src/config.ts +45 -0
  84. package/src/createHighlightMarkers.ts +24 -0
  85. package/src/deprecatedSchema.ts +19 -0
  86. package/src/editorSupport.ts +33 -0
  87. package/src/getMedia.tsx +95 -0
  88. package/src/groq.ts +630 -0
  89. package/src/index.ts +11 -0
  90. package/src/schema.tsx +69 -0
  91. package/src/types.ts +26 -0
  92. package/dist/dts/CodeInput.d.ts +0 -23
  93. package/dist/dts/CodeInput.d.ts.map +0 -1
  94. package/dist/dts/PreviewCode.d.ts.map +0 -1
  95. package/dist/dts/config.d.ts.map +0 -1
  96. package/dist/dts/createHighlightMarkers.d.ts.map +0 -1
  97. package/dist/dts/deprecatedSchema.d.ts.map +0 -1
  98. package/dist/dts/editorSupport.d.ts.map +0 -1
  99. package/dist/dts/getMedia.d.ts.map +0 -1
  100. package/dist/dts/groq.d.ts +0 -376
  101. package/dist/dts/groq.d.ts.map +0 -1
  102. package/dist/dts/schema.d.ts +0 -44
  103. package/dist/dts/schema.d.ts.map +0 -1
  104. package/dist/dts/types.d.ts.map +0 -1
  105. package/lib/@types/css.d.js +0 -1
  106. package/lib/PreviewCode.js +0 -79
  107. package/lib/config.js +0 -103
  108. package/lib/createHighlightMarkers.js +0 -31
  109. package/lib/editorSupport.js +0 -55
  110. package/lib/getMedia.js +0 -110
  111. package/lib/groq.js +0 -414
  112. package/lib/types.js +0 -5
  113. package/tsconfig.json +0 -26
@@ -0,0 +1,846 @@
1
+ import React, { useRef, useMemo, useImperativeHandle, useCallback, useEffect } from 'react';
2
+ import { set, setIfMissing, unset, MemberField } from '@sanity/base/form';
3
+ import { Card, Select, Stack } from '@sanity/ui';
4
+ import AceEditor from 'react-ace';
5
+ import styled, { css } from 'styled-components';
6
+ import 'ace-builds/src-noconflict/mode-batchfile';
7
+ import 'ace-builds/src-noconflict/mode-csharp';
8
+ import 'ace-builds/src-noconflict/mode-css';
9
+ import 'ace-builds/src-noconflict/mode-golang';
10
+ import 'ace-builds/src-noconflict/mode-html';
11
+ import 'ace-builds/src-noconflict/mode-java';
12
+ import 'ace-builds/src-noconflict/mode-javascript';
13
+ import 'ace-builds/src-noconflict/mode-json';
14
+ import 'ace-builds/src-noconflict/mode-jsx';
15
+ import 'ace-builds/src-noconflict/mode-markdown';
16
+ import 'ace-builds/src-noconflict/mode-mysql';
17
+ import 'ace-builds/src-noconflict/mode-php';
18
+ import 'ace-builds/src-noconflict/mode-python';
19
+ import 'ace-builds/src-noconflict/mode-ruby';
20
+ import 'ace-builds/src-noconflict/mode-sass';
21
+ import 'ace-builds/src-noconflict/mode-scss';
22
+ import 'ace-builds/src-noconflict/mode-sh';
23
+ import 'ace-builds/src-noconflict/mode-text';
24
+ import 'ace-builds/src-noconflict/mode-tsx';
25
+ import 'ace-builds/src-noconflict/mode-typescript';
26
+ import 'ace-builds/src-noconflict/mode-xml';
27
+ import 'ace-builds/src-noconflict/mode-yaml';
28
+ import 'ace-builds/src-noconflict/theme-github';
29
+ import 'ace-builds/src-noconflict/theme-monokai';
30
+ import 'ace-builds/src-noconflict/theme-terminal';
31
+ import 'ace-builds/src-noconflict/theme-tomorrow';
32
+
33
+ const highlightMarkersCSS = css `
34
+ .ace_editor_markers_highlight {
35
+ position: absolute;
36
+ background-color: ${({ theme }) => theme.sanity.color.solid.primary.enabled.bg};
37
+ opacity: 0.2;
38
+ width: 100% !important;
39
+ border-radius: 0 !important;
40
+ }
41
+ `;
42
+ function createHighlightMarkers(rows) {
43
+ return rows.map((row) => ({
44
+ startRow: Number(row) - 1,
45
+ startCol: 0,
46
+ endRow: Number(row) - 1,
47
+ endCol: +Infinity,
48
+ className: 'ace_editor_markers_highlight',
49
+ type: 'screenLine',
50
+ inFront: true,
51
+ }));
52
+ }
53
+
54
+ /* eslint-disable no-undef */
55
+ // Grammar from https://github.com/sanity-io/vscode-sanity
56
+ const rules = {
57
+ start: [
58
+ {
59
+ include: '#query',
60
+ },
61
+ {
62
+ include: '#value',
63
+ },
64
+ {
65
+ include: '#pair',
66
+ },
67
+ ],
68
+ '#query': [
69
+ {
70
+ include: '#nullary-access-operator',
71
+ },
72
+ {
73
+ include: '#arraylike',
74
+ },
75
+ {
76
+ include: '#pipe',
77
+ },
78
+ {
79
+ include: '#sort-order',
80
+ },
81
+ {
82
+ include: '#filter',
83
+ },
84
+ ],
85
+ '#variable': [
86
+ {
87
+ token: 'variable.other.groq',
88
+ regex: /\$[_A-Za-z][_0-9A-Za-z]*/,
89
+ },
90
+ ],
91
+ '#keyword': [
92
+ {
93
+ token: 'keyword.other.groq',
94
+ regex: /\b(?:asc|desc|in|match)\b/,
95
+ },
96
+ ],
97
+ '#comparison': [
98
+ {
99
+ token: 'keyword.operator.comparison.groq',
100
+ // eslint-disable-next-line no-div-regex
101
+ regex: /==|!=|>=|<=|<!=>|<|>/,
102
+ },
103
+ ],
104
+ '#operator': [
105
+ {
106
+ token: 'keyword.operator.arithmetic.groq',
107
+ regex: /\+|-|\*{1,2}|\/|%/,
108
+ },
109
+ ],
110
+ '#pipe': [
111
+ {
112
+ token: 'keyword.operator.pipe.groq',
113
+ regex: /\|/,
114
+ },
115
+ ],
116
+ '#logical': [
117
+ {
118
+ token: 'keyword.operator.logical.groq',
119
+ regex: /!|&&|\|\|/,
120
+ },
121
+ ],
122
+ '#reference': [
123
+ {
124
+ token: 'keyword.operator.reference.groq',
125
+ regex: /->/,
126
+ },
127
+ ],
128
+ '#pair': [
129
+ {
130
+ include: '#identifier',
131
+ },
132
+ {
133
+ include: '#value',
134
+ },
135
+ {
136
+ include: '#filter',
137
+ },
138
+ {
139
+ token: 'keyword.operator.pair.groq',
140
+ regex: /[=]>/,
141
+ },
142
+ ],
143
+ '#arraylike': [
144
+ {
145
+ token: 'punctuation.definition.bracket.begin.groq',
146
+ regex: /\[/,
147
+ push: [
148
+ {
149
+ token: ['text', 'keyword.operator.descendant.groq'],
150
+ regex: /(\])((?:\s*\.)?)/,
151
+ next: 'pop',
152
+ },
153
+ {
154
+ include: '#range',
155
+ },
156
+ {
157
+ include: '#filter',
158
+ },
159
+ {
160
+ include: '#array-values',
161
+ },
162
+ ],
163
+ },
164
+ ],
165
+ '#array': [
166
+ {
167
+ token: 'punctuation.definition.bracket.begin.groq',
168
+ regex: /\[/,
169
+ push: [
170
+ {
171
+ token: 'punctuation.definition.bracket.end.groq',
172
+ regex: /\]/,
173
+ next: 'pop',
174
+ },
175
+ {
176
+ include: '#array-values',
177
+ },
178
+ {
179
+ defaultToken: 'meta.structure.array.groq',
180
+ },
181
+ ],
182
+ },
183
+ ],
184
+ '#range': [
185
+ {
186
+ token: [
187
+ 'meta.structure.range.groq',
188
+ 'constant.numeric.groq',
189
+ 'meta.structure.range.groq',
190
+ 'keyword.operator.range.groq',
191
+ 'meta.structure.range.groq',
192
+ 'constant.numeric.groq',
193
+ 'meta.structure.range.groq',
194
+ ],
195
+ regex: /(\s*)(\d+)(\s*)(\.{2,3})(\s*)(\d+)(\s*)/,
196
+ },
197
+ ],
198
+ '#spread': [
199
+ {
200
+ token: 'punctuation.definition.spread.begin.groq',
201
+ regex: /\.\.\./,
202
+ push: [
203
+ {
204
+ include: '#array',
205
+ },
206
+ {
207
+ include: '#function-call',
208
+ },
209
+ {
210
+ include: '#projection',
211
+ },
212
+ {
213
+ token: 'punctuation.definition.spread.end.groq',
214
+ regex: /(?=.)/,
215
+ next: 'pop',
216
+ },
217
+ {
218
+ defaultToken: 'meta.structure.spread.groq',
219
+ },
220
+ ],
221
+ },
222
+ ],
223
+ '#array-values': [
224
+ {
225
+ include: '#value',
226
+ },
227
+ {
228
+ include: '#spread',
229
+ },
230
+ {
231
+ token: 'punctuation.separator.array.groq',
232
+ regex: /,/,
233
+ },
234
+ {
235
+ token: 'invalid.illegal.expected-array-separator.groq',
236
+ regex: /[^\s\]]/,
237
+ },
238
+ ],
239
+ '#filter': [
240
+ {
241
+ include: '#function-call',
242
+ },
243
+ {
244
+ include: '#keyword',
245
+ },
246
+ {
247
+ include: '#constant',
248
+ },
249
+ {
250
+ include: '#identifier',
251
+ },
252
+ {
253
+ include: '#value',
254
+ },
255
+ {
256
+ include: '#comparison',
257
+ },
258
+ {
259
+ include: '#operator',
260
+ },
261
+ {
262
+ include: '#logical',
263
+ },
264
+ ],
265
+ '#comments': [
266
+ {
267
+ token: ['punctuation.definition.comment.groq', 'comment.line.double-slash.js'],
268
+ regex: /(\/\/)(.*$)/,
269
+ },
270
+ ],
271
+ '#nullary-access-operator': [
272
+ {
273
+ token: 'constant.language.groq',
274
+ regex: /[*@^]/,
275
+ },
276
+ ],
277
+ '#constant': [
278
+ {
279
+ token: 'constant.language.groq',
280
+ regex: /\b(?:true|false|null)\b/,
281
+ },
282
+ ],
283
+ '#number': [
284
+ {
285
+ token: 'constant.numeric.groq',
286
+ regex: /-?(?:0|[1-9]\d*)(?:(?:\.\d+)?(?:[eE][+-]?\d+)?)?/,
287
+ },
288
+ ],
289
+ '#named-projection': [
290
+ {
291
+ include: '#identifier',
292
+ },
293
+ {
294
+ include: '#objectkey',
295
+ },
296
+ {
297
+ include: '#projection',
298
+ },
299
+ ],
300
+ '#projection': [
301
+ {
302
+ token: 'punctuation.definition.projection.begin.groq',
303
+ regex: /\{/,
304
+ push: [
305
+ {
306
+ token: 'punctuation.definition.projection.end.groq',
307
+ regex: /\}/,
308
+ next: 'pop',
309
+ },
310
+ {
311
+ include: '#identifier',
312
+ },
313
+ {
314
+ include: '#objectkey',
315
+ },
316
+ {
317
+ include: '#named-projection',
318
+ },
319
+ {
320
+ include: '#comments',
321
+ },
322
+ {
323
+ include: '#spread',
324
+ },
325
+ {
326
+ include: '#pair',
327
+ },
328
+ {
329
+ token: 'punctuation.separator.projection.key-value.groq',
330
+ regex: /:/,
331
+ push: [
332
+ {
333
+ token: 'punctuation.separator.projection.pair.groq',
334
+ regex: /,|(?=\})/,
335
+ next: 'pop',
336
+ },
337
+ {
338
+ include: '#nullary-access-operator',
339
+ },
340
+ {
341
+ include: '#arraylike',
342
+ },
343
+ {
344
+ include: '#value',
345
+ },
346
+ {
347
+ include: '#spread',
348
+ },
349
+ {
350
+ include: '#identifier',
351
+ },
352
+ {
353
+ include: '#operator',
354
+ },
355
+ {
356
+ include: '#comparison',
357
+ },
358
+ {
359
+ include: '#pair',
360
+ },
361
+ {
362
+ token: 'invalid.illegal.expected-projection-separator.groq',
363
+ regex: /[^\s,]/,
364
+ },
365
+ {
366
+ defaultToken: 'meta.structure.projection.value.groq',
367
+ },
368
+ ],
369
+ },
370
+ {
371
+ token: 'invalid.illegal.expected-projection-separator.groq',
372
+ regex: /[^\s},]/,
373
+ },
374
+ {
375
+ defaultToken: 'meta.structure.projection.groq',
376
+ },
377
+ ],
378
+ },
379
+ ],
380
+ '#string': [
381
+ {
382
+ include: '#single-string',
383
+ },
384
+ {
385
+ include: '#double-string',
386
+ },
387
+ ],
388
+ '#double-string': [
389
+ {
390
+ token: 'punctuation.definition.string.begin.groq',
391
+ regex: /"/,
392
+ push: [
393
+ {
394
+ token: 'punctuation.definition.string.end.groq',
395
+ regex: /"/,
396
+ next: 'pop',
397
+ },
398
+ {
399
+ include: '#stringcontent',
400
+ },
401
+ {
402
+ defaultToken: 'string.quoted.double.groq',
403
+ },
404
+ ],
405
+ },
406
+ ],
407
+ '#single-string': [
408
+ {
409
+ token: 'punctuation.definition.string.single.begin.groq',
410
+ regex: /'/,
411
+ push: [
412
+ {
413
+ token: 'punctuation.definition.string.single.end.groq',
414
+ regex: /'/,
415
+ next: 'pop',
416
+ },
417
+ {
418
+ include: '#stringcontent',
419
+ },
420
+ {
421
+ defaultToken: 'string.quoted.single.groq',
422
+ },
423
+ ],
424
+ },
425
+ ],
426
+ '#objectkey': [
427
+ {
428
+ include: '#string',
429
+ },
430
+ ],
431
+ '#stringcontent': [
432
+ {
433
+ token: 'constant.character.escape.groq',
434
+ regex: /\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4})/,
435
+ },
436
+ {
437
+ token: 'invalid.illegal.unrecognized-string-escape.groq',
438
+ regex: /\\./,
439
+ },
440
+ ],
441
+ '#sort-pair': [
442
+ {
443
+ token: ['variable.other.readwrite.groq', 'text', 'keyword.other.groq'],
444
+ regex: /([_A-Za-z][_0-9A-Za-z]*)(?:(\s*)(asc|desc))?/,
445
+ },
446
+ {
447
+ token: ['constant.language.groq', 'punctuation.definition.bracket.begin.groq'],
448
+ regex: /(@)(\[)/,
449
+ push: [
450
+ {
451
+ token: ['punctuation.definition.bracket.begin.groq', 'text', 'keyword.other.groq'],
452
+ regex: /(\])(?:(\s*)(asc|desc))?/,
453
+ next: 'pop',
454
+ },
455
+ {
456
+ include: '#string',
457
+ },
458
+ ],
459
+ },
460
+ ],
461
+ '#sort-order': [
462
+ {
463
+ token: 'support.function.sortorder.begin.groq',
464
+ regex: /\border\s*\(/,
465
+ push: [
466
+ {
467
+ token: 'support.function.sortorder.end.groq',
468
+ regex: /\)/,
469
+ next: 'pop',
470
+ },
471
+ {
472
+ include: '#sort-pair',
473
+ },
474
+ {
475
+ token: 'punctuation.separator.array.groq',
476
+ regex: /,/,
477
+ },
478
+ {
479
+ token: 'invalid.illegal.expected-sort-separator.groq',
480
+ regex: /[^\s\]]/,
481
+ },
482
+ {
483
+ defaultToken: 'support.function.sortorder.groq',
484
+ },
485
+ ],
486
+ },
487
+ ],
488
+ '#function-call': [
489
+ {
490
+ include: '#function-var-arg',
491
+ },
492
+ {
493
+ include: '#function-single-arg',
494
+ },
495
+ {
496
+ include: '#function-round',
497
+ },
498
+ ],
499
+ '#function-var-arg': [
500
+ {
501
+ token: 'support.function.vararg.begin.groq',
502
+ regex: /\b(?:coalesce|select)\s*\(/,
503
+ push: [
504
+ {
505
+ token: 'support.function.vararg.end.groq',
506
+ regex: /\)/,
507
+ next: 'pop',
508
+ },
509
+ {
510
+ include: '#value',
511
+ },
512
+ {
513
+ include: '#identifier',
514
+ },
515
+ {
516
+ include: '#filter',
517
+ },
518
+ {
519
+ include: '#pair',
520
+ },
521
+ {
522
+ token: 'punctuation.separator.array.groq',
523
+ regex: /,/,
524
+ },
525
+ {
526
+ defaultToken: 'support.function.vararg.groq',
527
+ },
528
+ ],
529
+ },
530
+ ],
531
+ '#function-single-arg': [
532
+ {
533
+ token: 'support.function.singlearg.begin.groq',
534
+ regex: /\b(?:count|defined|length|path|references)\s*\(/,
535
+ push: [
536
+ {
537
+ token: 'support.function.singlearg.end.groq',
538
+ regex: /\)/,
539
+ next: 'pop',
540
+ },
541
+ {
542
+ include: '#query',
543
+ },
544
+ {
545
+ include: '#identifier',
546
+ },
547
+ {
548
+ include: '#value',
549
+ },
550
+ {
551
+ include: '#pair',
552
+ },
553
+ {
554
+ defaultToken: 'support.function.singlearg.groq',
555
+ },
556
+ ],
557
+ },
558
+ ],
559
+ '#identifier': [
560
+ {
561
+ token: [
562
+ 'variable.other.readwrite.groq',
563
+ 'text',
564
+ 'punctuation.definition.block.js',
565
+ 'text',
566
+ 'keyword.operator.reference.groq',
567
+ ],
568
+ regex: /([_A-Za-z][_0-9A-Za-z]*)(\s*)((?:\[\s*\])?)(\s*)(->)/,
569
+ },
570
+ {
571
+ token: [
572
+ 'variable.other.readwrite.groq',
573
+ 'constant.language.groq',
574
+ 'text',
575
+ 'punctuation.definition.block.js',
576
+ 'text',
577
+ 'keyword.operator.descendant.groq',
578
+ ],
579
+ regex: /(?:([_A-Za-z][_0-9A-Za-z]*)|([@^]))(\s*)((?:\[\s*\])?)(\s*)(\.)/,
580
+ },
581
+ {
582
+ token: 'variable.other.readwrite.groq',
583
+ regex: /[_A-Za-z][_0-9A-Za-z]*/,
584
+ },
585
+ ],
586
+ '#value': [
587
+ {
588
+ include: '#constant',
589
+ },
590
+ {
591
+ include: '#number',
592
+ },
593
+ {
594
+ include: '#string',
595
+ },
596
+ {
597
+ include: '#array',
598
+ },
599
+ {
600
+ include: '#variable',
601
+ },
602
+ {
603
+ include: '#projection',
604
+ },
605
+ {
606
+ include: '#comments',
607
+ },
608
+ {
609
+ include: '#function-call',
610
+ },
611
+ ],
612
+ };
613
+ ace.define('ace/mode/groq_highlight_rules', ['require', 'exports', 'module', 'ace/lib/oop', 'ace/mode/text_highlight_rules'], (acequire, exports, _module) => {
614
+ const oop = acequire('../lib/oop');
615
+ const TextHighlightRules = acequire('./text_highlight_rules').TextHighlightRules;
616
+ const GroqHighlightRules = function () {
617
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
618
+ // @ts-ignore
619
+ this.$rules = rules;
620
+ // @ts-ignore
621
+ this.normalizeRules();
622
+ /* eslint-enable @typescript-eslint/ban-ts-comment */
623
+ };
624
+ oop.inherits(GroqHighlightRules, TextHighlightRules);
625
+ exports.GroqHighlightRules = GroqHighlightRules;
626
+ });
627
+ ace.define('ace/mode/groq', [
628
+ 'require',
629
+ 'exports',
630
+ 'module',
631
+ 'ace/lib/oop',
632
+ 'ace/mode/text',
633
+ 'ace/tokenizer',
634
+ 'ace/mode/groq_highlight_rules',
635
+ 'ace/mode/folding/cstyle',
636
+ ], (acequire, exports, _module) => {
637
+ const oop = acequire('../lib/oop');
638
+ const TextMode = acequire('./text').Mode;
639
+ const Tokenizer = acequire('../tokenizer').Tokenizer;
640
+ const GroqHighlightRules = acequire('./groq_highlight_rules').GroqHighlightRules;
641
+ const FoldMode = acequire('./folding/cstyle').FoldMode;
642
+ const Mode = function () {
643
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
644
+ const highlighter = new GroqHighlightRules();
645
+ // @ts-ignore
646
+ this.foldingRules = new FoldMode();
647
+ // @ts-ignore
648
+ this.$tokenizer = new Tokenizer(highlighter.getRules());
649
+ // @ts-ignore
650
+ this.$keywordList = highlighter.$keywordList;
651
+ /* eslint-enable @typescript-eslint/ban-ts-comment */
652
+ };
653
+ oop.inherits(Mode, TextMode);
654
+ (function () {
655
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
656
+ // @ts-ignore
657
+ this.lineCommentStart = "'";
658
+ /* eslint-enable @typescript-eslint/ban-ts-comment */
659
+ }.call(Mode.prototype));
660
+ exports.Mode = Mode;
661
+ });
662
+
663
+ // NOTE: MAKE SURE THESE ALIGN WITH IMPORTS IN ./editorSupport
664
+ const SUPPORTED_LANGUAGES = [
665
+ { title: 'Batch file', value: 'batchfile' },
666
+ { title: 'C#', value: 'csharp' },
667
+ { title: 'CSS', value: 'css' },
668
+ { title: 'Go', value: 'golang' },
669
+ { title: 'GROQ', value: 'groq' },
670
+ { title: 'HTML', value: 'html' },
671
+ { title: 'Java', value: 'java' },
672
+ { title: 'JavaScript', value: 'javascript' },
673
+ { title: 'JSON', value: 'json' },
674
+ { title: 'JSX', value: 'jsx' },
675
+ { title: 'Markdown', value: 'markdown' },
676
+ { title: 'MySQL', value: 'mysql' },
677
+ { title: 'PHP', value: 'php' },
678
+ { title: 'Plain text', value: 'text' },
679
+ { title: 'Python', value: 'python' },
680
+ { title: 'Ruby', value: 'ruby' },
681
+ { title: 'SASS', value: 'sass' },
682
+ { title: 'SCSS', value: 'scss' },
683
+ { title: 'sh', value: 'sh' },
684
+ { title: 'TSX', value: 'tsx' },
685
+ { title: 'TypeScript', value: 'typescript' },
686
+ { title: 'XML', value: 'xml' },
687
+ { title: 'YAML', value: 'yaml' },
688
+ ];
689
+ const LANGUAGE_ALIASES = { js: 'javascript' };
690
+ const SUPPORTED_THEMES = ['github', 'monokai', 'terminal', 'tomorrow'];
691
+ const DEFAULT_THEME = 'tomorrow';
692
+ const ACE_SET_OPTIONS = {
693
+ useSoftTabs: true,
694
+ navigateWithinSoftTabs: true /* note only supported by ace v1.2.7 or higher */,
695
+ };
696
+ const ACE_EDITOR_PROPS = { $blockScrolling: true };
697
+ const PATH_CODE = ['code'];
698
+
699
+ /* eslint-disable react/jsx-handler-names */
700
+ const EditorContainer = styled(Card) `
701
+ position: relative;
702
+ box-sizing: border-box;
703
+ overflow: hidden;
704
+ z-index: 0;
705
+
706
+ .ace_editor {
707
+ font-family: ${({ theme }) => theme.sanity.fonts.code.family};
708
+ font-size: ${({ theme }) => theme.sanity.fonts.code.sizes[1]};
709
+ line-height: inherit;
710
+ }
711
+
712
+ ${highlightMarkersCSS}
713
+
714
+ &:not([disabled]):not([readonly]) {
715
+ &:focus,
716
+ &:focus-within {
717
+ box-shadow: 0 0 0 2px ${({ theme }) => theme.sanity.color.base.focusRing};
718
+ background-color: ${({ theme }) => theme.sanity.color.base.bg};
719
+ border-color: ${({ theme }) => theme.sanity.color.base.focusRing};
720
+ }
721
+ }
722
+ `;
723
+ // Returns a string with the mode name if supported (because aliases), otherwise false
724
+ function isSupportedLanguage(mode) {
725
+ const alias = LANGUAGE_ALIASES[mode];
726
+ if (alias) {
727
+ return alias;
728
+ }
729
+ const isSupported = SUPPORTED_LANGUAGES.find((lang) => lang.value === mode);
730
+ if (isSupported) {
731
+ return mode;
732
+ }
733
+ return false;
734
+ }
735
+ function CodeInput(props) {
736
+ const { focusRef, members, onBlur, onChange, onFocusPath, readOnly, renderField, renderInput, renderItem, schemaType: type, value, } = props;
737
+ const aceEditorRef = useRef();
738
+ const fieldMembers = useMemo(() => members.filter((member) => member.kind === 'field'), [members]);
739
+ const languageFieldMember = fieldMembers.find((member) => member.name === 'language');
740
+ const filenameMember = fieldMembers.find((member) => member.name === 'filename');
741
+ const codeFieldMember = fieldMembers.find((member) => member.name === 'code');
742
+ useImperativeHandle(focusRef, () => ({
743
+ focus: () => {
744
+ aceEditorRef?.current?.editor?.focus();
745
+ },
746
+ }));
747
+ const handleCodeFocus = useCallback(() => {
748
+ onFocusPath(PATH_CODE);
749
+ }, [onFocusPath]);
750
+ const getTheme = useCallback(() => {
751
+ const preferredTheme = type.options?.theme;
752
+ return preferredTheme && SUPPORTED_THEMES.find((theme) => theme === preferredTheme)
753
+ ? preferredTheme
754
+ : DEFAULT_THEME;
755
+ }, [type]);
756
+ const handleToggleSelectLine = useCallback((lineNumber) => {
757
+ const editorSession = aceEditorRef.current?.editor?.getSession();
758
+ const backgroundMarkers = editorSession?.getMarkers(true);
759
+ const currentHighlightedLines = Object.keys(backgroundMarkers)
760
+ .filter((key) => backgroundMarkers[key].type === 'screenLine')
761
+ .map((key) => backgroundMarkers[key].range.start.row);
762
+ const currentIndex = currentHighlightedLines.indexOf(lineNumber);
763
+ if (currentIndex > -1) {
764
+ // toggle remove
765
+ currentHighlightedLines.splice(currentIndex, 1);
766
+ }
767
+ else {
768
+ // toggle add
769
+ currentHighlightedLines.push(lineNumber);
770
+ currentHighlightedLines.sort();
771
+ }
772
+ onChange(set(currentHighlightedLines.map((line) =>
773
+ // ace starts at line (row) 0, but we store it starting at line 1
774
+ line + 1), ['highlightedLines']));
775
+ }, [aceEditorRef, onChange]);
776
+ const handleGutterMouseDown = useCallback((event) => {
777
+ const target = event.domEvent.target;
778
+ if (target.classList.contains('ace_gutter-cell')) {
779
+ const row = event.getDocumentPosition().row;
780
+ handleToggleSelectLine(row);
781
+ }
782
+ }, [handleToggleSelectLine]);
783
+ useEffect(() => {
784
+ const editor = aceEditorRef?.current?.editor;
785
+ return () => {
786
+ editor?.session?.removeListener('guttermousedown', handleGutterMouseDown);
787
+ };
788
+ }, [aceEditorRef, handleGutterMouseDown]);
789
+ const handleEditorLoad = useCallback((editor) => {
790
+ editor?.on('guttermousedown', handleGutterMouseDown);
791
+ }, [handleGutterMouseDown]);
792
+ const getLanguageAlternatives = useCallback(() => {
793
+ const languageAlternatives = type.options?.languageAlternatives;
794
+ if (!languageAlternatives) {
795
+ return SUPPORTED_LANGUAGES;
796
+ }
797
+ if (!Array.isArray(languageAlternatives)) {
798
+ throw new Error(`'options.languageAlternatives' should be an array, got ${typeof languageAlternatives}`);
799
+ }
800
+ return languageAlternatives.reduce((acc, { title, value: val, mode }) => {
801
+ const alias = LANGUAGE_ALIASES[val];
802
+ if (alias) {
803
+ // eslint-disable-next-line no-console
804
+ console.warn(`'options.languageAlternatives' lists a language with value "%s", which is an alias of "%s" - please replace the value to read "%s"`, val, alias, alias);
805
+ return acc.concat({ title, value: alias, mode: mode });
806
+ }
807
+ if (!mode && !SUPPORTED_LANGUAGES.find((lang) => lang.value === val)) {
808
+ // eslint-disable-next-line no-console
809
+ console.warn(`'options.languageAlternatives' lists a language which is not supported: "%s", syntax highlighting will be disabled.`, val);
810
+ }
811
+ return acc.concat({ title, value: val, mode });
812
+ }, []);
813
+ }, [type]);
814
+ const handleCodeChange = useCallback((code) => {
815
+ const path = PATH_CODE;
816
+ const fixedLanguage = type.options?.language;
817
+ onChange([
818
+ setIfMissing({ _type: type.name, language: fixedLanguage }),
819
+ code ? set(code, path) : unset(path),
820
+ ]);
821
+ }, [onChange, type]);
822
+ const languages = getLanguageAlternatives().slice();
823
+ const fixedLanguage = type.options?.language;
824
+ const language = value?.language || fixedLanguage;
825
+ // the language config from the schema
826
+ const configured = languages.find((entry) => entry.value === language);
827
+ // is the language officially supported (e.g. we import the mode by default)
828
+ const supported = language && isSupportedLanguage(language);
829
+ const mode = configured?.mode || (supported ? language : 'text');
830
+ const renderLanguageInput = useCallback((inputProps) => {
831
+ return (React.createElement(Select, { ...inputProps }, languages.map((lang) => (React.createElement("option", { key: lang.value, value: lang.value }, lang.title)))));
832
+ }, [languages]);
833
+ const renderCodeInput = useCallback((inputProps) => {
834
+ return (React.createElement(EditorContainer, { radius: 1, shadow: 1, readOnly: readOnly },
835
+ React.createElement(AceEditor, { ref: aceEditorRef, mode: mode, theme: getTheme(), width: "100%", onChange: handleCodeChange, name: inputProps.id, value: inputProps.value, markers: value && value.highlightedLines
836
+ ? createHighlightMarkers(value.highlightedLines)
837
+ : undefined, onLoad: handleEditorLoad, readOnly: readOnly, tabSize: 2, wrapEnabled: true, setOptions: ACE_SET_OPTIONS, editorProps: ACE_EDITOR_PROPS, onFocus: handleCodeFocus, onBlur: onBlur })));
838
+ }, [getTheme, handleCodeChange, handleCodeFocus, handleEditorLoad, mode, onBlur, readOnly, value]);
839
+ return (React.createElement(Stack, { space: 4 },
840
+ languageFieldMember && (React.createElement(MemberField, { member: languageFieldMember, renderItem: renderItem, renderField: renderField, renderInput: renderLanguageInput })),
841
+ type.options?.withFilename && filenameMember && (React.createElement(MemberField, { member: filenameMember, renderItem: renderItem, renderField: renderField, renderInput: renderInput })),
842
+ codeFieldMember && (React.createElement(MemberField, { member: codeFieldMember, renderInput: renderCodeInput, renderItem: renderItem, renderField: renderField }))));
843
+ }
844
+
845
+ export { ACE_SET_OPTIONS as A, CodeInput as C, ACE_EDITOR_PROPS as a, createHighlightMarkers as c };
846
+ //# sourceMappingURL=_CodeInput-d6f5810b.js.map