@workbench-kit/shell-react 0.0.2-prototype.0.2.6 → 0.0.2-prototype.0.2.8
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/README.md +41 -0
- package/package.json +9 -9
- package/src/{chat-ai-mock-proposals.ts → chat/ai-mock-proposals.ts} +39 -39
- package/src/{chat-command-input.ts → chat/command-input.ts} +52 -52
- package/src/{chat-command-policy.ts → chat/command-policy.ts} +54 -54
- package/src/{chat-command-surface.tsx → chat/command-surface.tsx} +155 -155
- package/src/{use-workbench-chat-command-proposals.ts → chat/use-chat-command-proposals.ts} +194 -194
- package/src/{chat-view-data.ts → chat/view-data.ts} +20 -20
- package/src/{chat-view.tsx → chat/view.tsx} +220 -220
- package/src/{command-inspector-surface.tsx → commands/inspector-surface.tsx} +46 -46
- package/src/{use-workbench-command-descriptors.ts → commands/use-command-descriptors.ts} +41 -41
- package/src/{use-context-key-revision.ts → commands/use-context-key-revision.ts} +18 -18
- package/src/{commands-view-data.ts → commands/view-data.ts} +17 -17
- package/src/{commands-view.tsx → commands/view.tsx} +43 -43
- package/src/devtools/WorkbenchDevtoolsPanel.tsx +124 -124
- package/src/devtools/WorkbenchDevtoolsShell.tsx +17 -17
- package/src/devtools/index.ts +11 -11
- package/src/devtools/use-workbench-devtools-snapshot.ts +84 -84
- package/src/devtools/workbench-devtools-snapshot.ts +140 -140
- package/src/devtools/workbench-devtools.css +82 -82
- package/src/{editor-area-dnd.ts → editor/area-dnd.ts} +69 -69
- package/src/{editor-area-model.ts → editor/area-model.ts} +71 -71
- package/src/{editor-area.css → editor/area.css} +454 -454
- package/src/{editor-area.tsx → editor/area.tsx} +676 -676
- package/src/{editor-host-surface.tsx → editor/host-surface.tsx} +631 -634
- package/src/{editor-pane-visibility.ts → editor/pane-visibility.ts} +130 -130
- package/src/{editor-resource.ts → editor/resource.ts} +36 -36
- package/src/{editor-state-storage.ts → editor/state-storage.ts} +182 -193
- package/src/{editor-tab-context-menu.ts → editor/tab-context-menu.ts} +118 -118
- package/src/{use-editor.ts → editor/use-editor.ts} +114 -107
- package/src/{editor-view-providers.tsx → editor/view-providers.tsx} +552 -552
- package/src/{editor-workspace-file-availability.ts → editor/workspace-file-availability.ts} +15 -15
- package/src/{editor-workspace-reconcile.tsx → editor/workspace-reconcile.tsx} +31 -28
- package/src/{explorer-context-menu.ts → explorer/context-menu.ts} +114 -114
- package/src/{createCommandWorkspaceExplorerPort.ts → explorer/create-command-workspace-explorer-port.ts} +86 -86
- package/src/{explorer-reveal.ts → explorer/reveal.ts} +112 -112
- package/src/{search-view-data.ts → explorer/search-view-data.ts} +15 -15
- package/src/{search-view.tsx → explorer/search-view.tsx} +65 -62
- package/src/{use-active-workspace-path.ts → explorer/use-active-workspace-path.ts} +15 -15
- package/src/{explorer-view-data.ts → explorer/view-data.ts} +58 -58
- package/src/{explorer-view.tsx → explorer/view.tsx} +227 -224
- package/src/{extension-context-menu.ts → extensions/context-menu.ts} +52 -52
- package/src/{extension-management-model.ts → extensions/management-model.ts} +313 -313
- package/src/{use-extension-management.ts → extensions/use-extension-management.ts} +241 -193
- package/src/{extensions-view-data.ts → extensions/view-data.ts} +19 -19
- package/src/{extensions-view.tsx → extensions/view.tsx} +63 -38
- package/src/{field-remap-demo.tsx → field-remap/demo.tsx} +18 -18
- package/src/{field-remap-editor-surface.tsx → field-remap/editor-surface.tsx} +36 -36
- package/src/{field-remap-flow-adapter.ts → field-remap/flow-adapter.ts} +240 -240
- package/src/{field-remap-flow.tsx → field-remap/flow.tsx} +369 -369
- package/src/{field-remap-graph.tsx → field-remap/graph.tsx} +559 -559
- package/src/field-remap/jsonata-transform.ts +166 -0
- package/src/{field-remap-panel.tsx → field-remap/panel.tsx} +193 -175
- package/src/{field-remap-samples.ts → field-remap/samples.ts} +352 -352
- package/src/{table-mapping-adapter.ts → field-remap/table-mapping-adapter.ts} +59 -59
- package/src/{field-remap-tree.tsx → field-remap/tree.tsx} +404 -404
- package/src/{field-remap-view-data.ts → field-remap/view-data.ts} +16 -16
- package/src/{field-remap-view.css → field-remap/view.css} +676 -676
- package/src/{field-remap-view.tsx → field-remap/view.tsx} +86 -86
- package/src/index.ts +212 -199
- package/src/{json-form-source-patch.ts → jdw/json-form-source-patch.ts} +323 -323
- package/src/{jdw-lab-view-data.ts → jdw/lab-view-data.ts} +25 -25
- package/src/{jdw-lab-view.css → jdw/lab-view.css} +21 -21
- package/src/{jdw-lab-view.tsx → jdw/lab-view.tsx} +79 -79
- package/src/{jdw-widget-form-view.tsx → jdw/widget-form-view.tsx} +68 -65
- package/src/{jdw-widget-preview-view.tsx → jdw/widget-preview-view.tsx} +54 -51
- package/src/{keybinding-overrides-storage.ts → management/keybinding-overrides-storage.ts} +49 -57
- package/src/{keybinding-management-settings.tsx → management/keybinding-settings.tsx} +16 -16
- package/src/{management-palette-commands.ts → management/palette-commands.ts} +38 -38
- package/src/{preference-settings-storage.ts → management/preference-settings-storage.ts} +50 -58
- package/src/{management-settings-ids.ts → management/settings-ids.ts} +12 -12
- package/src/{management-settings.tsx → management/settings.tsx} +96 -75
- package/src/{use-command-management.ts → management/use-command-management.ts} +191 -191
- package/src/{use-keybinding-management.ts → management/use-keybinding-management.ts} +130 -130
- package/src/{shell-model.tsx → shell/model.tsx} +149 -149
- package/src/{provider.tsx → shell/provider.tsx} +603 -573
- package/src/{shell-secondary-actions.tsx → shell/secondary-actions.tsx} +59 -59
- package/src/{shell-settings-constants.ts → shell/settings-constants.ts} +9 -9
- package/src/{shell-settings.tsx → shell/settings.tsx} +599 -599
- package/src/{shell.tsx → shell/shell.tsx} +680 -649
- package/src/{shell-titlebar-layout-controls.tsx → shell/titlebar-layout-controls.tsx} +4 -4
- package/src/{shell-view-host.tsx → shell/view-host.tsx} +212 -199
- package/src/{workbench-appearance-storage.ts → workbench/appearance-storage.ts} +107 -115
- package/src/{workbench-command-host.tsx → workbench/command-host.tsx} +243 -243
- package/src/{workbench-command-palette.ts → workbench/command-palette.ts} +208 -208
- package/src/{workbench-keybinding-bridge.ts → workbench/keybinding-bridge.ts} +54 -54
- package/src/{workbench-layout-storage.ts → workbench/layout-storage.ts} +134 -145
- package/src/{workbench-profile-modal.tsx → workbench/profile-modal.tsx} +118 -118
- package/src/{workbench-shell-command-registration.ts → workbench/shell-command-registration.ts} +58 -58
- package/src/{workbench-startup-gate.tsx → workbench/startup-gate.tsx} +136 -136
- package/src/{workbench-status-sections.ts → workbench/status-sections.ts} +43 -43
- package/src/{use-persisted-workbench-appearance.ts → workbench/use-persisted-appearance.ts} +33 -33
- package/src/{workbench-user-commands.ts → workbench/user-commands.ts} +46 -46
- package/src/{workspace-view-state.ts → workbench/workspace-view-state.ts} +35 -35
- package/src/jsonata-transform.ts +0 -36
|
@@ -1,634 +1,631 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isValidElement,
|
|
3
|
-
lazy,
|
|
4
|
-
Suspense,
|
|
5
|
-
useCallback,
|
|
6
|
-
useEffect,
|
|
7
|
-
useMemo,
|
|
8
|
-
useRef,
|
|
9
|
-
useState,
|
|
10
|
-
type ReactNode,
|
|
11
|
-
} from 'react';
|
|
12
|
-
import { createPortal } from 'react-dom';
|
|
13
|
-
import { IconButton, ScrollArea } from '@workbench-kit/react/primitives';
|
|
14
|
-
import { SplitView } from '@workbench-kit/react/workbench/split-view';
|
|
15
|
-
import type { WorkspaceEditorTheme } from '@workbench-kit/react/workbench/workspace/editor';
|
|
16
|
-
import {
|
|
17
|
-
EDITOR_SAVE_COMMAND_ID,
|
|
18
|
-
type EditorHost,
|
|
19
|
-
type EditorTabState,
|
|
20
|
-
} from '@workbench-kit/workbench-core';
|
|
21
|
-
|
|
22
|
-
import { CommandInspectorSurface } from '
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}),
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
:
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
className="workbench-editor-area__text-editor"
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
candidate.
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
className="workbench-editor-area__missing-resource"
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
<
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
value ===
|
|
617
|
-
value ===
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
return null;
|
|
634
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
isValidElement,
|
|
3
|
+
lazy,
|
|
4
|
+
Suspense,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { createPortal } from 'react-dom';
|
|
13
|
+
import { IconButton, ScrollArea } from '@workbench-kit/react/primitives';
|
|
14
|
+
import { SplitView } from '@workbench-kit/react/workbench/split-view';
|
|
15
|
+
import type { WorkspaceEditorTheme } from '@workbench-kit/react/workbench/workspace/editor';
|
|
16
|
+
import {
|
|
17
|
+
EDITOR_SAVE_COMMAND_ID,
|
|
18
|
+
type EditorHost,
|
|
19
|
+
type EditorTabState,
|
|
20
|
+
} from '@workbench-kit/workbench-core';
|
|
21
|
+
|
|
22
|
+
import { CommandInspectorSurface } from '../commands/inspector-surface.js';
|
|
23
|
+
import { resolveEditorDocumentViews, type EditorDocumentViewProvider } from './view-providers.js';
|
|
24
|
+
import { mimeTypeForResource, pathForResource } from './resource.js';
|
|
25
|
+
import { FieldRemapEditorSurface } from '../field-remap/editor-surface.js';
|
|
26
|
+
import {
|
|
27
|
+
editorViewModeToPaneVisibility,
|
|
28
|
+
getVisibleEditorPaneKinds,
|
|
29
|
+
paneVisibilityToPrimaryViewMode,
|
|
30
|
+
resolveDefaultEditorPaneVisibility,
|
|
31
|
+
resolveEffectiveEditorPaneVisibility,
|
|
32
|
+
type EditorPaneKind,
|
|
33
|
+
type EditorPaneVisibility,
|
|
34
|
+
type EditorViewMode,
|
|
35
|
+
} from './pane-visibility.js';
|
|
36
|
+
import { useWorkbench } from '../shell/provider.js';
|
|
37
|
+
import { useEditorHost, useEditorService } from './use-editor.js';
|
|
38
|
+
|
|
39
|
+
export type { EditorViewMode } from './pane-visibility.js';
|
|
40
|
+
|
|
41
|
+
const WorkspaceEditor = lazy(async () => {
|
|
42
|
+
const module = await import('@workbench-kit/react/workbench/workspace/editor');
|
|
43
|
+
return { default: module.WorkspaceEditor };
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export interface EditorHostSurfaceProps {
|
|
47
|
+
activeTab: EditorTabState | undefined;
|
|
48
|
+
defaultViewModeForResource: ((resourceUri: string) => EditorViewMode | undefined) | undefined;
|
|
49
|
+
modeToolbarHost: HTMLDivElement | null;
|
|
50
|
+
onModeToolbarVisibleChange: (visible: boolean) => void;
|
|
51
|
+
theme: WorkspaceEditorTheme | undefined;
|
|
52
|
+
viewProviders: readonly EditorDocumentViewProvider[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function EditorHostSurface({
|
|
56
|
+
activeTab,
|
|
57
|
+
defaultViewModeForResource,
|
|
58
|
+
modeToolbarHost,
|
|
59
|
+
onModeToolbarVisibleChange,
|
|
60
|
+
theme,
|
|
61
|
+
viewProviders,
|
|
62
|
+
}: EditorHostSurfaceProps) {
|
|
63
|
+
const editorService = useEditorService();
|
|
64
|
+
const host = useEditorHost(activeTab?.id);
|
|
65
|
+
const hostFrameRef = useRef<HTMLDivElement>(null);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!host || !activeTab) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
host.onDidChangeDirty = (dirty) => {
|
|
73
|
+
editorService.setDirty(activeTab.id, dirty);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return () => {
|
|
77
|
+
host.onDidChangeDirty = undefined;
|
|
78
|
+
};
|
|
79
|
+
}, [activeTab, editorService, host]);
|
|
80
|
+
|
|
81
|
+
if (!activeTab || !host) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const rendered = host.render();
|
|
86
|
+
|
|
87
|
+
if (isMissingResourceEditorRenderPayload(rendered)) {
|
|
88
|
+
return (
|
|
89
|
+
<MissingResourceEditorSurface
|
|
90
|
+
message={rendered.message}
|
|
91
|
+
resourceUri={rendered.resourceUri}
|
|
92
|
+
tabId={activeTab.id}
|
|
93
|
+
title={host.title ?? activeTab.title}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (isCommandInspectorEditorRenderPayload(rendered)) {
|
|
99
|
+
return (
|
|
100
|
+
<CommandInspectorSurface
|
|
101
|
+
commandId={rendered.commandId}
|
|
102
|
+
resourceUri={rendered.resourceUri}
|
|
103
|
+
tabId={activeTab.id}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (isFieldRemapEditorRenderPayload(rendered)) {
|
|
109
|
+
return (
|
|
110
|
+
<FieldRemapEditorSurface
|
|
111
|
+
resourceUri={rendered.resourceUri}
|
|
112
|
+
surfaceId={rendered.surfaceId}
|
|
113
|
+
tabId={activeTab.id}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (isTextEditorRenderPayload(rendered)) {
|
|
119
|
+
return (
|
|
120
|
+
<TextEditorSurface
|
|
121
|
+
defaultViewModeForResource={defaultViewModeForResource}
|
|
122
|
+
host={host as TextEditorHostLike}
|
|
123
|
+
initialContent={rendered.initialContent}
|
|
124
|
+
modeToolbarHost={modeToolbarHost}
|
|
125
|
+
mimeType={rendered.mimeType}
|
|
126
|
+
onModeToolbarVisibleChange={onModeToolbarVisibleChange}
|
|
127
|
+
resourceUri={rendered.resourceUri}
|
|
128
|
+
tabId={activeTab.id}
|
|
129
|
+
theme={theme}
|
|
130
|
+
viewProviders={viewProviders}
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<div
|
|
137
|
+
ref={hostFrameRef}
|
|
138
|
+
aria-label={host.title ?? activeTab.title ?? 'Editor'}
|
|
139
|
+
className="workbench-editor-area__host"
|
|
140
|
+
data-editor-host-id={activeTab.id}
|
|
141
|
+
>
|
|
142
|
+
{toReactNode(rendered)}
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface TextEditorHostLike extends EditorHost {
|
|
148
|
+
getContent?(): string;
|
|
149
|
+
markDirty?(): void;
|
|
150
|
+
setContent?(content: string): void;
|
|
151
|
+
setDirty?(dirty: boolean): void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface TextEditorRenderPayload {
|
|
155
|
+
initialContent: string;
|
|
156
|
+
kind: 'workbench-kit.builtin.editor/text';
|
|
157
|
+
mimeType?: string | undefined;
|
|
158
|
+
resourceUri: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function TextEditorSurface({
|
|
162
|
+
defaultViewModeForResource,
|
|
163
|
+
host,
|
|
164
|
+
initialContent,
|
|
165
|
+
modeToolbarHost,
|
|
166
|
+
mimeType,
|
|
167
|
+
onModeToolbarVisibleChange,
|
|
168
|
+
resourceUri,
|
|
169
|
+
tabId,
|
|
170
|
+
theme,
|
|
171
|
+
viewProviders,
|
|
172
|
+
}: {
|
|
173
|
+
defaultViewModeForResource: ((resourceUri: string) => EditorViewMode | undefined) | undefined;
|
|
174
|
+
host: TextEditorHostLike;
|
|
175
|
+
initialContent: string;
|
|
176
|
+
modeToolbarHost: HTMLDivElement | null;
|
|
177
|
+
mimeType?: string | undefined;
|
|
178
|
+
onModeToolbarVisibleChange: (visible: boolean) => void;
|
|
179
|
+
resourceUri: string;
|
|
180
|
+
tabId: string;
|
|
181
|
+
theme: WorkspaceEditorTheme | undefined;
|
|
182
|
+
viewProviders: readonly EditorDocumentViewProvider[];
|
|
183
|
+
}) {
|
|
184
|
+
const editorService = useEditorService();
|
|
185
|
+
const { executeCommand, workspaceHostPort } = useWorkbench();
|
|
186
|
+
const [content, setContent] = useState(initialContent);
|
|
187
|
+
const previousResourceUriRef = useRef<string | undefined>(undefined);
|
|
188
|
+
const splitSizesRef = useRef<Record<string, number>>({});
|
|
189
|
+
const editorDocument = useMemo(
|
|
190
|
+
() => ({
|
|
191
|
+
content,
|
|
192
|
+
mimeType: mimeType ?? mimeTypeForResource(resourceUri),
|
|
193
|
+
path: pathForResource(resourceUri),
|
|
194
|
+
resourceUri,
|
|
195
|
+
}),
|
|
196
|
+
[content, mimeType, resourceUri],
|
|
197
|
+
);
|
|
198
|
+
const { formProvider, previewProvider } = useMemo(
|
|
199
|
+
() => resolveEditorDocumentViews(editorDocument, viewProviders),
|
|
200
|
+
[editorDocument, viewProviders],
|
|
201
|
+
);
|
|
202
|
+
const formEligible = Boolean(formProvider);
|
|
203
|
+
const previewEligible = Boolean(previewProvider);
|
|
204
|
+
const [panePreference, setPanePreference] = useState<EditorPaneVisibility>(() =>
|
|
205
|
+
resolveDefaultEditorPaneVisibility(defaultViewModeForResource?.(resourceUri), {
|
|
206
|
+
formEligible,
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
209
|
+
const paneVisibility = useMemo(
|
|
210
|
+
() => resolveEffectiveEditorPaneVisibility(panePreference, { formEligible, previewEligible }),
|
|
211
|
+
[formEligible, panePreference, previewEligible],
|
|
212
|
+
);
|
|
213
|
+
const codeIcon = isJsonSourceDocument(editorDocument) ? 'codicon-json' : 'codicon-code';
|
|
214
|
+
const modeToolbarVisible = formEligible || previewEligible;
|
|
215
|
+
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
const resourceChanged = previousResourceUriRef.current !== resourceUri;
|
|
218
|
+
previousResourceUriRef.current = resourceUri;
|
|
219
|
+
|
|
220
|
+
if (resourceChanged) {
|
|
221
|
+
setContent(initialContent);
|
|
222
|
+
setPanePreference(
|
|
223
|
+
resolveDefaultEditorPaneVisibility(defaultViewModeForResource?.(resourceUri), {
|
|
224
|
+
formEligible,
|
|
225
|
+
}),
|
|
226
|
+
);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
setContent((current) => (current === initialContent ? current : initialContent));
|
|
231
|
+
}, [defaultViewModeForResource, formEligible, initialContent, resourceUri]);
|
|
232
|
+
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
onModeToolbarVisibleChange(modeToolbarVisible);
|
|
235
|
+
}, [modeToolbarVisible, onModeToolbarVisibleChange]);
|
|
236
|
+
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
return () => {
|
|
239
|
+
onModeToolbarVisibleChange(false);
|
|
240
|
+
};
|
|
241
|
+
}, [onModeToolbarVisibleChange]);
|
|
242
|
+
|
|
243
|
+
const getSplitSize = useCallback((key: string, defaultPercent: number) => {
|
|
244
|
+
return splitSizesRef.current[key] ?? defaultPercent;
|
|
245
|
+
}, []);
|
|
246
|
+
|
|
247
|
+
const setSplitSize = useCallback((key: string, percent: number) => {
|
|
248
|
+
splitSizesRef.current[key] = percent;
|
|
249
|
+
}, []);
|
|
250
|
+
|
|
251
|
+
const handleChange = useCallback(
|
|
252
|
+
(nextContent: string) => {
|
|
253
|
+
setContent(nextContent);
|
|
254
|
+
host.setContent?.(nextContent);
|
|
255
|
+
host.markDirty?.();
|
|
256
|
+
editorService.promotePreviewOnEdit(tabId);
|
|
257
|
+
},
|
|
258
|
+
[editorService, host, tabId],
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const handleSave = useCallback(
|
|
262
|
+
(nextContent: string) => {
|
|
263
|
+
if (nextContent !== content) {
|
|
264
|
+
handleChange(nextContent);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
void executeCommand(EDITOR_SAVE_COMMAND_ID);
|
|
268
|
+
},
|
|
269
|
+
[content, executeCommand, handleChange],
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const sourcePane = (
|
|
273
|
+
<div className="workbench-editor-area__source-pane">
|
|
274
|
+
<Suspense
|
|
275
|
+
fallback={
|
|
276
|
+
<div className="workbench-editor-area__editor-loading" role="status">
|
|
277
|
+
Loading editor...
|
|
278
|
+
</div>
|
|
279
|
+
}
|
|
280
|
+
>
|
|
281
|
+
<WorkspaceEditor
|
|
282
|
+
file={editorDocument}
|
|
283
|
+
showFileBar
|
|
284
|
+
showHeader={false}
|
|
285
|
+
theme={theme}
|
|
286
|
+
value={content}
|
|
287
|
+
onChange={handleChange}
|
|
288
|
+
onSave={workspaceHostPort ? handleSave : undefined}
|
|
289
|
+
/>
|
|
290
|
+
</Suspense>
|
|
291
|
+
</div>
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const previewPane = previewProvider ? (
|
|
295
|
+
<ScrollArea
|
|
296
|
+
aria-label="Preview"
|
|
297
|
+
as="section"
|
|
298
|
+
className="workbench-editor-area__preview-pane"
|
|
299
|
+
orientation="vertical"
|
|
300
|
+
>
|
|
301
|
+
{toReactNode(
|
|
302
|
+
previewProvider.render({ document: editorDocument, onContentChange: handleChange }),
|
|
303
|
+
)}
|
|
304
|
+
</ScrollArea>
|
|
305
|
+
) : null;
|
|
306
|
+
const formPane = formProvider
|
|
307
|
+
? toReactNode(formProvider.render({ document: editorDocument, onContentChange: handleChange }))
|
|
308
|
+
: null;
|
|
309
|
+
const paneByKind: Record<EditorPaneKind, ReactNode | null> = {
|
|
310
|
+
code: sourcePane,
|
|
311
|
+
form: formPane,
|
|
312
|
+
preview: previewPane,
|
|
313
|
+
};
|
|
314
|
+
const visiblePaneEntries = getVisibleEditorPaneKinds(paneVisibility)
|
|
315
|
+
.map((kind) => ({ kind, node: paneByKind[kind] }))
|
|
316
|
+
.filter((entry): entry is { kind: EditorPaneKind; node: ReactNode } => entry.node !== null);
|
|
317
|
+
const editorBody = composeEditorPaneLayout(visiblePaneEntries, getSplitSize, setSplitSize);
|
|
318
|
+
const modeToolbar =
|
|
319
|
+
modeToolbarVisible && modeToolbarHost
|
|
320
|
+
? createPortal(
|
|
321
|
+
<EditorViewModeIconSelect
|
|
322
|
+
codeIcon={codeIcon}
|
|
323
|
+
formEligible={formEligible}
|
|
324
|
+
previewEligible={previewEligible}
|
|
325
|
+
value={paneVisibilityToPrimaryViewMode(paneVisibility)}
|
|
326
|
+
onValueChange={(mode) => {
|
|
327
|
+
setPanePreference(editorViewModeToPaneVisibility(mode));
|
|
328
|
+
}}
|
|
329
|
+
/>,
|
|
330
|
+
modeToolbarHost,
|
|
331
|
+
)
|
|
332
|
+
: null;
|
|
333
|
+
|
|
334
|
+
return (
|
|
335
|
+
<>
|
|
336
|
+
{modeToolbar}
|
|
337
|
+
<section
|
|
338
|
+
aria-label={host.title ?? resourceUri}
|
|
339
|
+
className="workbench-editor-area__text-editor"
|
|
340
|
+
data-resource-uri={resourceUri}
|
|
341
|
+
>
|
|
342
|
+
<div className="workbench-editor-area__text-editor-body">{editorBody}</div>
|
|
343
|
+
</section>
|
|
344
|
+
</>
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function composeEditorPaneLayout(
|
|
349
|
+
panes: readonly { kind: EditorPaneKind; node: ReactNode }[],
|
|
350
|
+
getSplitSize: (key: string, defaultPercent: number) => number,
|
|
351
|
+
onSplitSizeChange: (key: string, percent: number) => void,
|
|
352
|
+
): ReactNode {
|
|
353
|
+
if (panes.length === 0) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (panes.length === 1) {
|
|
358
|
+
return panes[0]?.node ?? null;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const layoutSignature = panes.map((pane) => pane.kind).join('|');
|
|
362
|
+
|
|
363
|
+
return panes.slice(1).reduce<ReactNode>((primary, entry, splitIndex) => {
|
|
364
|
+
const primaryKind = panes[0]?.kind;
|
|
365
|
+
const primaryLabel = primaryKind ? editorPaneKindLabel(primaryKind) : 'Editor pane';
|
|
366
|
+
const splitKey = `${layoutSignature}#${splitIndex}`;
|
|
367
|
+
|
|
368
|
+
return (
|
|
369
|
+
<SplitView
|
|
370
|
+
key={splitKey}
|
|
371
|
+
className="workbench-editor-area__split"
|
|
372
|
+
defaultPrimarySizePercent={50}
|
|
373
|
+
minPrimarySizePercent={25}
|
|
374
|
+
primarySizePercent={getSplitSize(splitKey, 50)}
|
|
375
|
+
onPrimarySizePercentChange={(percent) => {
|
|
376
|
+
onSplitSizeChange(splitKey, percent);
|
|
377
|
+
}}
|
|
378
|
+
primary={
|
|
379
|
+
<section aria-label={primaryLabel} className="workbench-editor-area__split-pane">
|
|
380
|
+
{primary}
|
|
381
|
+
</section>
|
|
382
|
+
}
|
|
383
|
+
secondary={
|
|
384
|
+
<section
|
|
385
|
+
aria-label={editorPaneKindLabel(entry.kind)}
|
|
386
|
+
className="workbench-editor-area__split-pane"
|
|
387
|
+
>
|
|
388
|
+
{entry.node}
|
|
389
|
+
</section>
|
|
390
|
+
}
|
|
391
|
+
/>
|
|
392
|
+
);
|
|
393
|
+
}, panes[0]?.node ?? null);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function editorPaneKindLabel(kind: EditorPaneKind): string {
|
|
397
|
+
switch (kind) {
|
|
398
|
+
case 'code':
|
|
399
|
+
return 'Code';
|
|
400
|
+
case 'form':
|
|
401
|
+
return 'Form';
|
|
402
|
+
case 'preview':
|
|
403
|
+
return 'Preview';
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function EditorViewModeIconSelect({
|
|
408
|
+
codeIcon,
|
|
409
|
+
formEligible,
|
|
410
|
+
onValueChange,
|
|
411
|
+
previewEligible,
|
|
412
|
+
value,
|
|
413
|
+
}: {
|
|
414
|
+
codeIcon: string;
|
|
415
|
+
formEligible: boolean;
|
|
416
|
+
onValueChange: (mode: EditorViewMode) => void;
|
|
417
|
+
previewEligible: boolean;
|
|
418
|
+
value: EditorViewMode;
|
|
419
|
+
}) {
|
|
420
|
+
const resolvedValue =
|
|
421
|
+
(value === 'form' && !formEligible) || (value === 'preview' && !previewEligible)
|
|
422
|
+
? 'code'
|
|
423
|
+
: value;
|
|
424
|
+
|
|
425
|
+
return (
|
|
426
|
+
<div
|
|
427
|
+
aria-label="Editor view mode"
|
|
428
|
+
className="workbench-editor-area__view-toolbar"
|
|
429
|
+
data-testid="editor-view-mode-select"
|
|
430
|
+
role="radiogroup"
|
|
431
|
+
>
|
|
432
|
+
<EditorViewModeIconButton
|
|
433
|
+
checked={resolvedValue === 'code'}
|
|
434
|
+
icon={codeIcon}
|
|
435
|
+
label="Code"
|
|
436
|
+
onSelect={() => {
|
|
437
|
+
onValueChange('code');
|
|
438
|
+
}}
|
|
439
|
+
/>
|
|
440
|
+
{formEligible ? (
|
|
441
|
+
<EditorViewModeIconButton
|
|
442
|
+
checked={resolvedValue === 'form'}
|
|
443
|
+
icon="codicon-symbol-field"
|
|
444
|
+
label="Form"
|
|
445
|
+
onSelect={() => {
|
|
446
|
+
onValueChange('form');
|
|
447
|
+
}}
|
|
448
|
+
/>
|
|
449
|
+
) : null}
|
|
450
|
+
{previewEligible ? (
|
|
451
|
+
<EditorViewModeIconButton
|
|
452
|
+
checked={resolvedValue === 'preview'}
|
|
453
|
+
icon="codicon-preview"
|
|
454
|
+
label="Preview"
|
|
455
|
+
onSelect={() => {
|
|
456
|
+
onValueChange('preview');
|
|
457
|
+
}}
|
|
458
|
+
/>
|
|
459
|
+
) : null}
|
|
460
|
+
</div>
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function EditorViewModeIconButton({
|
|
465
|
+
checked,
|
|
466
|
+
icon,
|
|
467
|
+
label,
|
|
468
|
+
onSelect,
|
|
469
|
+
}: {
|
|
470
|
+
checked: boolean;
|
|
471
|
+
icon: string;
|
|
472
|
+
label: string;
|
|
473
|
+
onSelect: () => void;
|
|
474
|
+
}) {
|
|
475
|
+
return (
|
|
476
|
+
<IconButton
|
|
477
|
+
aria-checked={checked}
|
|
478
|
+
className={[
|
|
479
|
+
'workbench-editor-area__view-button',
|
|
480
|
+
checked && 'workbench-editor-area__view-button--active',
|
|
481
|
+
]
|
|
482
|
+
.filter(Boolean)
|
|
483
|
+
.join(' ')}
|
|
484
|
+
compact
|
|
485
|
+
icon={icon}
|
|
486
|
+
label={label}
|
|
487
|
+
role="radio"
|
|
488
|
+
onClick={onSelect}
|
|
489
|
+
/>
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function isJsonSourceDocument(document: { mimeType?: string | undefined; path: string }): boolean {
|
|
494
|
+
const mimeType = document.mimeType?.toLowerCase();
|
|
495
|
+
return document.path.toLowerCase().endsWith('.json') || Boolean(mimeType?.includes('json'));
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
interface CommandInspectorEditorRenderPayload {
|
|
499
|
+
readonly commandId: string;
|
|
500
|
+
readonly kind: 'workbench-kit.builtin.commands/inspector';
|
|
501
|
+
readonly resourceUri: string;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function isCommandInspectorEditorRenderPayload(
|
|
505
|
+
value: unknown,
|
|
506
|
+
): value is CommandInspectorEditorRenderPayload {
|
|
507
|
+
if (typeof value !== 'object' || value === null) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const candidate = value as Partial<CommandInspectorEditorRenderPayload>;
|
|
512
|
+
return (
|
|
513
|
+
candidate.kind === 'workbench-kit.builtin.commands/inspector' &&
|
|
514
|
+
typeof candidate.commandId === 'string' &&
|
|
515
|
+
typeof candidate.resourceUri === 'string'
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
interface FieldRemapEditorRenderPayload {
|
|
520
|
+
readonly kind: 'workbench-kit.samples.field-remap/editor';
|
|
521
|
+
readonly resourceUri: string;
|
|
522
|
+
readonly surfaceId: string;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function isFieldRemapEditorRenderPayload(value: unknown): value is FieldRemapEditorRenderPayload {
|
|
526
|
+
if (typeof value !== 'object' || value === null) {
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const candidate = value as Partial<FieldRemapEditorRenderPayload>;
|
|
531
|
+
return (
|
|
532
|
+
candidate.kind === 'workbench-kit.samples.field-remap/editor' &&
|
|
533
|
+
typeof candidate.resourceUri === 'string' &&
|
|
534
|
+
typeof candidate.surfaceId === 'string' &&
|
|
535
|
+
candidate.surfaceId.length > 0
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function isTextEditorRenderPayload(value: unknown): value is TextEditorRenderPayload {
|
|
540
|
+
if (typeof value !== 'object' || value === null) {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const candidate = value as Partial<TextEditorRenderPayload>;
|
|
545
|
+
return (
|
|
546
|
+
candidate.kind === 'workbench-kit.builtin.editor/text' &&
|
|
547
|
+
typeof candidate.resourceUri === 'string' &&
|
|
548
|
+
typeof candidate.initialContent === 'string'
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
interface MissingResourceEditorRenderPayload {
|
|
553
|
+
readonly kind: 'workbench-kit.builtin.editor/missing-resource';
|
|
554
|
+
readonly message: string;
|
|
555
|
+
readonly resourceUri: string;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function isMissingResourceEditorRenderPayload(
|
|
559
|
+
value: unknown,
|
|
560
|
+
): value is MissingResourceEditorRenderPayload {
|
|
561
|
+
if (typeof value !== 'object' || value === null) {
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const candidate = value as Partial<MissingResourceEditorRenderPayload>;
|
|
566
|
+
return (
|
|
567
|
+
candidate.kind === 'workbench-kit.builtin.editor/missing-resource' &&
|
|
568
|
+
typeof candidate.resourceUri === 'string' &&
|
|
569
|
+
typeof candidate.message === 'string'
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function MissingResourceEditorSurface({
|
|
574
|
+
message,
|
|
575
|
+
resourceUri,
|
|
576
|
+
tabId,
|
|
577
|
+
title,
|
|
578
|
+
}: {
|
|
579
|
+
message: string;
|
|
580
|
+
resourceUri: string;
|
|
581
|
+
tabId: string;
|
|
582
|
+
title?: string | undefined;
|
|
583
|
+
}) {
|
|
584
|
+
const editorService = useEditorService();
|
|
585
|
+
const path = pathForResource(resourceUri);
|
|
586
|
+
|
|
587
|
+
return (
|
|
588
|
+
<section
|
|
589
|
+
aria-label={title ?? path}
|
|
590
|
+
className="workbench-editor-area__missing-resource"
|
|
591
|
+
data-resource-uri={resourceUri}
|
|
592
|
+
>
|
|
593
|
+
<div className="workbench-editor-area__missing-resource-body" role="alert">
|
|
594
|
+
<p className="workbench-editor-area__missing-resource-title">Unable to open editor</p>
|
|
595
|
+
<p className="workbench-editor-area__missing-resource-message">{message}</p>
|
|
596
|
+
<p className="workbench-editor-area__missing-resource-path">{path}</p>
|
|
597
|
+
<button
|
|
598
|
+
className="workbench-editor-area__missing-resource-close"
|
|
599
|
+
type="button"
|
|
600
|
+
onClick={() => {
|
|
601
|
+
editorService.closeEditor(tabId);
|
|
602
|
+
}}
|
|
603
|
+
>
|
|
604
|
+
Close tab
|
|
605
|
+
</button>
|
|
606
|
+
</div>
|
|
607
|
+
</section>
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function toReactNode(value: unknown): ReactNode {
|
|
612
|
+
if (
|
|
613
|
+
value === undefined ||
|
|
614
|
+
value === null ||
|
|
615
|
+
typeof value === 'boolean' ||
|
|
616
|
+
typeof value === 'symbol' ||
|
|
617
|
+
typeof value === 'function'
|
|
618
|
+
) {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (typeof value === 'string' || typeof value === 'number' || isValidElement(value)) {
|
|
623
|
+
return value;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (Array.isArray(value)) {
|
|
627
|
+
return value as ReactNode;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
return null;
|
|
631
|
+
}
|