@sanity/code-input 2.29.5-get-started-template.13 → 2.29.5-purple-unicorn.779

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