@workbench-kit/shell-react 0.0.2-prototype.0.2.6

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 (93) hide show
  1. package/package.json +49 -0
  2. package/src/chat-ai-mock-proposals.ts +39 -0
  3. package/src/chat-command-input.ts +52 -0
  4. package/src/chat-command-policy.ts +54 -0
  5. package/src/chat-command-surface.tsx +155 -0
  6. package/src/chat-view-data.ts +20 -0
  7. package/src/chat-view.tsx +220 -0
  8. package/src/command-inspector-surface.tsx +46 -0
  9. package/src/commands-view-data.ts +17 -0
  10. package/src/commands-view.tsx +43 -0
  11. package/src/createCommandWorkspaceExplorerPort.ts +86 -0
  12. package/src/devtools/WorkbenchDevtoolsPanel.tsx +124 -0
  13. package/src/devtools/WorkbenchDevtoolsShell.tsx +17 -0
  14. package/src/devtools/index.ts +11 -0
  15. package/src/devtools/use-workbench-devtools-snapshot.ts +84 -0
  16. package/src/devtools/workbench-devtools-snapshot.ts +140 -0
  17. package/src/devtools/workbench-devtools.css +82 -0
  18. package/src/editor-area-dnd.ts +69 -0
  19. package/src/editor-area-model.ts +71 -0
  20. package/src/editor-area.css +454 -0
  21. package/src/editor-area.tsx +676 -0
  22. package/src/editor-host-surface.tsx +634 -0
  23. package/src/editor-pane-visibility.ts +130 -0
  24. package/src/editor-resource.ts +36 -0
  25. package/src/editor-state-storage.ts +193 -0
  26. package/src/editor-tab-context-menu.ts +118 -0
  27. package/src/editor-view-providers.tsx +552 -0
  28. package/src/editor-workspace-file-availability.ts +15 -0
  29. package/src/editor-workspace-reconcile.tsx +28 -0
  30. package/src/explorer-context-menu.ts +114 -0
  31. package/src/explorer-reveal.ts +112 -0
  32. package/src/explorer-view-data.ts +58 -0
  33. package/src/explorer-view.tsx +224 -0
  34. package/src/extension-context-menu.ts +52 -0
  35. package/src/extension-management-model.ts +313 -0
  36. package/src/extensions-view-data.ts +19 -0
  37. package/src/extensions-view.tsx +38 -0
  38. package/src/field-remap-demo.tsx +18 -0
  39. package/src/field-remap-editor-surface.tsx +36 -0
  40. package/src/field-remap-flow-adapter.ts +240 -0
  41. package/src/field-remap-flow.tsx +369 -0
  42. package/src/field-remap-graph.tsx +559 -0
  43. package/src/field-remap-panel.tsx +175 -0
  44. package/src/field-remap-samples.ts +352 -0
  45. package/src/field-remap-tree.tsx +404 -0
  46. package/src/field-remap-view-data.ts +16 -0
  47. package/src/field-remap-view.css +676 -0
  48. package/src/field-remap-view.tsx +86 -0
  49. package/src/index.ts +199 -0
  50. package/src/jdw-lab-view-data.ts +25 -0
  51. package/src/jdw-lab-view.css +21 -0
  52. package/src/jdw-lab-view.tsx +79 -0
  53. package/src/jdw-widget-form-view.tsx +65 -0
  54. package/src/jdw-widget-preview-view.tsx +51 -0
  55. package/src/json-form-source-patch.ts +323 -0
  56. package/src/jsonata-transform.ts +36 -0
  57. package/src/keybinding-management-settings.tsx +16 -0
  58. package/src/keybinding-overrides-storage.ts +57 -0
  59. package/src/management-palette-commands.ts +38 -0
  60. package/src/management-settings-ids.ts +12 -0
  61. package/src/management-settings.tsx +75 -0
  62. package/src/preference-settings-storage.ts +58 -0
  63. package/src/provider.tsx +573 -0
  64. package/src/search-view-data.ts +15 -0
  65. package/src/search-view.tsx +62 -0
  66. package/src/shell-model.tsx +149 -0
  67. package/src/shell-secondary-actions.tsx +59 -0
  68. package/src/shell-settings-constants.ts +9 -0
  69. package/src/shell-settings.tsx +599 -0
  70. package/src/shell-titlebar-layout-controls.tsx +4 -0
  71. package/src/shell-view-host.tsx +199 -0
  72. package/src/shell.tsx +649 -0
  73. package/src/table-mapping-adapter.ts +59 -0
  74. package/src/use-active-workspace-path.ts +15 -0
  75. package/src/use-command-management.ts +191 -0
  76. package/src/use-context-key-revision.ts +18 -0
  77. package/src/use-editor.ts +107 -0
  78. package/src/use-extension-management.ts +193 -0
  79. package/src/use-keybinding-management.ts +130 -0
  80. package/src/use-persisted-workbench-appearance.ts +33 -0
  81. package/src/use-workbench-chat-command-proposals.ts +194 -0
  82. package/src/use-workbench-command-descriptors.ts +41 -0
  83. package/src/workbench-appearance-storage.ts +115 -0
  84. package/src/workbench-command-host.tsx +243 -0
  85. package/src/workbench-command-palette.ts +208 -0
  86. package/src/workbench-keybinding-bridge.ts +54 -0
  87. package/src/workbench-layout-storage.ts +145 -0
  88. package/src/workbench-profile-modal.tsx +118 -0
  89. package/src/workbench-shell-command-registration.ts +58 -0
  90. package/src/workbench-startup-gate.tsx +136 -0
  91. package/src/workbench-status-sections.ts +43 -0
  92. package/src/workbench-user-commands.ts +46 -0
  93. package/src/workspace-view-state.ts +35 -0
@@ -0,0 +1,552 @@
1
+ import type { CSSProperties, ReactNode } from 'react';
2
+ import {
3
+ JDW_SCHEMA_DOCUMENT_MIME,
4
+ JDW_WIDGET_DOCUMENT_MIME,
5
+ isJdwDocumentPath,
6
+ isJdwSchemaDocument,
7
+ } from '@workbench-kit/react/jdw/document';
8
+ import { parseJsonWidgetData } from '@workbench-kit/react/jdw/parse';
9
+ import { ScrollArea, Select, TextInput } from '@workbench-kit/react/primitives';
10
+ import { WorkbenchMarkdownPreview } from '@workbench-kit/react/workbench/markdown-preview';
11
+ import {
12
+ createEditorDocumentViewProviderRegistry as createCoreEditorDocumentViewProviderRegistry,
13
+ EditorDocumentViewProviderRegistry,
14
+ type CreateEditorDocumentViewProviderRegistryOptions as CoreCreateEditorDocumentViewProviderRegistryOptions,
15
+ } from '@workbench-kit/workbench-core';
16
+ import type {
17
+ EditorDocumentContext,
18
+ EditorDocumentViewKind,
19
+ EditorDocumentViewProvider,
20
+ EditorDocumentViewRenderContext,
21
+ } from '@workbench-kit/workbench-core';
22
+
23
+ import { JdwWidgetFormView } from './jdw-widget-form-view.js';
24
+ import { JdwWidgetPreviewView } from './jdw-widget-preview-view.js';
25
+ import { replaceJsonValueAtPath, type JsonFormPath } from './json-form-source-patch.js';
26
+
27
+ type JsonPath = JsonFormPath;
28
+
29
+ export type {
30
+ EditorDocumentContext,
31
+ EditorDocumentViewKind,
32
+ EditorDocumentViewProvider,
33
+ EditorDocumentViewRenderContext,
34
+ };
35
+ export { EditorDocumentViewProviderRegistry };
36
+
37
+ export interface ResolvedEditorDocumentViews {
38
+ readonly formProvider: EditorDocumentViewProvider | undefined;
39
+ readonly previewProvider: EditorDocumentViewProvider | undefined;
40
+ }
41
+
42
+ export const JSON_FORM_PROVIDER_ID = 'workbench-kit.editor.form.json' as const;
43
+ export const JDW_WIDGET_FORM_PROVIDER_ID = 'workbench-kit.editor.form.jdw-widget' as const;
44
+ export const JDW_PREVIEW_PROVIDER_ID = 'workbench-kit.editor.preview.jdw' as const;
45
+ export const MARKDOWN_PREVIEW_PROVIDER_ID = 'workbench-kit.editor.preview.markdown' as const;
46
+
47
+ /**
48
+ * Opt-in shallow top-level JSON object form.
49
+ * Not included in {@link DEFAULT_EDITOR_DOCUMENT_VIEW_PROVIDERS} — plain JSON is
50
+ * Code-only unless a host registers a dedicated form provider (or this one).
51
+ */
52
+ export const JSON_FORM_PROVIDER: EditorDocumentViewProvider = {
53
+ id: JSON_FORM_PROVIDER_ID,
54
+ kind: 'form',
55
+ label: 'Form',
56
+ priority: 0,
57
+ matches: (document) =>
58
+ !isJdwSchemaDocument(document) &&
59
+ !isJdwDocument(document) &&
60
+ !isJdwWidgetJson(document.content) &&
61
+ (isJsonLikeDocument(document) || parseJsonObject(document.content) !== null),
62
+ render: ({ document, onContentChange }) => (
63
+ <JsonObjectFormView content={document.content} onContentChange={onContentChange} />
64
+ ),
65
+ };
66
+
67
+ const JDW_WIDGET_FORM_PROVIDER: EditorDocumentViewProvider = {
68
+ id: JDW_WIDGET_FORM_PROVIDER_ID,
69
+ kind: 'form',
70
+ label: 'Form',
71
+ priority: 20,
72
+ matches: (document) =>
73
+ !isJdwSchemaDocument(document) &&
74
+ (isJdwDocument(document) || isJdwWidgetJson(document.content)),
75
+ render: ({ document, onContentChange }) => (
76
+ <JdwWidgetFormView
77
+ content={document.content}
78
+ path={document.path}
79
+ onContentChange={onContentChange}
80
+ />
81
+ ),
82
+ };
83
+
84
+ const JDW_PREVIEW_PROVIDER: EditorDocumentViewProvider = {
85
+ id: JDW_PREVIEW_PROVIDER_ID,
86
+ kind: 'preview',
87
+ label: 'Preview',
88
+ priority: 10,
89
+ matches: (document) =>
90
+ !isJdwSchemaDocument(document) &&
91
+ (isJdwDocument(document) || isJdwWidgetJson(document.content)),
92
+ render: ({ document }) => (
93
+ <JdwWidgetPreviewView
94
+ className="workbench-editor-area__jdw-preview-viewport"
95
+ content={document.content}
96
+ path={document.path}
97
+ />
98
+ ),
99
+ };
100
+
101
+ const MARKDOWN_PREVIEW_PROVIDER: EditorDocumentViewProvider = {
102
+ id: MARKDOWN_PREVIEW_PROVIDER_ID,
103
+ kind: 'preview',
104
+ label: 'Preview',
105
+ priority: 5,
106
+ matches: isMarkdownDocument,
107
+ render: ({ document }) => <WorkbenchMarkdownPreview source={document.content} />,
108
+ };
109
+
110
+ export const DEFAULT_EDITOR_DOCUMENT_VIEW_PROVIDERS: readonly EditorDocumentViewProvider[] = [
111
+ JDW_WIDGET_FORM_PROVIDER,
112
+ JDW_PREVIEW_PROVIDER,
113
+ MARKDOWN_PREVIEW_PROVIDER,
114
+ ];
115
+
116
+ export interface CreateEditorDocumentViewProviderRegistryOptions extends CoreCreateEditorDocumentViewProviderRegistryOptions {
117
+ readonly includeDefaultProviders?: boolean | undefined;
118
+ }
119
+
120
+ export function createEditorDocumentViewProviderRegistry(
121
+ options: CreateEditorDocumentViewProviderRegistryOptions = {},
122
+ ): EditorDocumentViewProviderRegistry {
123
+ const providers = [
124
+ ...(options.includeDefaultProviders === false ? [] : DEFAULT_EDITOR_DOCUMENT_VIEW_PROVIDERS),
125
+ ...(options.providers ?? []),
126
+ ];
127
+ return createCoreEditorDocumentViewProviderRegistry({ providers });
128
+ }
129
+
130
+ export function resolveEditorDocumentViews(
131
+ document: EditorDocumentContext,
132
+ providers: readonly EditorDocumentViewProvider[] = DEFAULT_EDITOR_DOCUMENT_VIEW_PROVIDERS,
133
+ ): ResolvedEditorDocumentViews {
134
+ return {
135
+ formProvider: resolveEditorDocumentViewProvider(document, 'form', providers),
136
+ previewProvider: resolveEditorDocumentViewProvider(document, 'preview', providers),
137
+ };
138
+ }
139
+
140
+ export function resolveEditorDocumentViewProvider(
141
+ document: EditorDocumentContext,
142
+ kind: EditorDocumentViewKind,
143
+ providers: readonly EditorDocumentViewProvider[] = DEFAULT_EDITOR_DOCUMENT_VIEW_PROVIDERS,
144
+ ): EditorDocumentViewProvider | undefined {
145
+ return providers
146
+ .filter(
147
+ (provider) => provider.kind === kind && matchesEditorDocumentViewProvider(provider, document),
148
+ )
149
+ .sort((left, right) => (right.priority ?? 0) - (left.priority ?? 0))[0];
150
+ }
151
+
152
+ export function matchesEditorDocumentViewProvider(
153
+ provider: EditorDocumentViewProvider,
154
+ document: EditorDocumentContext,
155
+ ): boolean {
156
+ if (provider.matches) {
157
+ return provider.matches(document);
158
+ }
159
+
160
+ const mimeType = document.mimeType?.toLowerCase();
161
+ const path = normalizePath(document.path);
162
+ const hasMimeTypes = Boolean(provider.mimeTypes?.length);
163
+ const hasFilenamePatterns = Boolean(provider.filenamePatterns?.length);
164
+
165
+ if (!hasMimeTypes && !hasFilenamePatterns) {
166
+ return false;
167
+ }
168
+
169
+ const mimeMatches =
170
+ !hasMimeTypes ||
171
+ Boolean(provider.mimeTypes?.some((candidate) => candidate.toLowerCase() === mimeType));
172
+ const pathMatches =
173
+ !hasFilenamePatterns ||
174
+ Boolean(provider.filenamePatterns?.some((pattern) => matchesFilenamePattern(pattern, path)));
175
+
176
+ return mimeMatches && pathMatches;
177
+ }
178
+
179
+ function matchesFilenamePattern(pattern: string, path: string): boolean {
180
+ const normalizedPattern = normalizePath(pattern);
181
+ const segments = path.split('/');
182
+ const target = normalizedPattern.includes('/') ? path : (segments[segments.length - 1] ?? path);
183
+ const regex = new RegExp(`^${globToRegExpSource(normalizedPattern)}$`, 'i');
184
+ return regex.test(target);
185
+ }
186
+
187
+ function globToRegExpSource(pattern: string): string {
188
+ let source = '';
189
+
190
+ for (let index = 0; index < pattern.length; index += 1) {
191
+ const char = pattern[index];
192
+ const nextChar = pattern[index + 1];
193
+
194
+ if (char === '*' && nextChar === '*') {
195
+ source += '.*';
196
+ index += 1;
197
+ continue;
198
+ }
199
+
200
+ if (char === '*') {
201
+ source += '[^/]*';
202
+ continue;
203
+ }
204
+
205
+ if (char === '?') {
206
+ source += '[^/]';
207
+ continue;
208
+ }
209
+
210
+ source += escapeRegExp(char ?? '');
211
+ }
212
+
213
+ return source;
214
+ }
215
+
216
+ function normalizePath(path: string): string {
217
+ return path.split('\\').join('/');
218
+ }
219
+
220
+ function escapeRegExp(value: string): string {
221
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
222
+ }
223
+
224
+ function JsonObjectFormView({
225
+ content,
226
+ onContentChange,
227
+ }: {
228
+ content: string;
229
+ onContentChange: (content: string) => void;
230
+ }) {
231
+ const parsed = parseJsonObject(content);
232
+
233
+ const handleFieldChange = (path: JsonPath, nextValue: string) => {
234
+ if (!parsed) {
235
+ return;
236
+ }
237
+
238
+ const previousValue = getJsonPathValue(parsed, path);
239
+ const coerced = coerceFormFieldValue(previousValue, nextValue);
240
+ onContentChange(replaceJsonValueAtPath(content, path, coerced));
241
+ };
242
+
243
+ if (!parsed) {
244
+ return (
245
+ <ScrollArea className="workbench-editor-area__form-placeholder" orientation="vertical">
246
+ <p>Form view is unavailable while the document is not valid JSON.</p>
247
+ <p>Switch to Source to fix parse errors.</p>
248
+ </ScrollArea>
249
+ );
250
+ }
251
+
252
+ const entries = Object.entries(parsed);
253
+
254
+ if (entries.length === 0) {
255
+ return (
256
+ <ScrollArea className="workbench-editor-area__form-placeholder" orientation="vertical">
257
+ <p>Form view</p>
258
+ <p>This JSON object has no top-level fields yet.</p>
259
+ </ScrollArea>
260
+ );
261
+ }
262
+
263
+ return (
264
+ <ScrollArea
265
+ as="form"
266
+ className="workbench-editor-area__form"
267
+ orientation="vertical"
268
+ onSubmit={(event) => {
269
+ event.preventDefault();
270
+ }}
271
+ >
272
+ <div className="workbench-editor-area__form-grid">
273
+ {entries.map(([key, value]) => (
274
+ <JsonValueFormField
275
+ key={key}
276
+ depth={0}
277
+ label={key}
278
+ path={[key]}
279
+ value={value}
280
+ onFieldChange={handleFieldChange}
281
+ />
282
+ ))}
283
+ </div>
284
+ </ScrollArea>
285
+ );
286
+ }
287
+
288
+ function JsonValueFormField({
289
+ depth = 0,
290
+ label,
291
+ path,
292
+ value,
293
+ onFieldChange,
294
+ }: {
295
+ depth?: number;
296
+ label: string;
297
+ path: JsonPath;
298
+ value: unknown;
299
+ onFieldChange: (path: JsonPath, value: string) => void;
300
+ }) {
301
+ if (Array.isArray(value)) {
302
+ return (
303
+ <JsonFormGroup depth={depth} label={label} meta={`array (${value.length})`} path={path}>
304
+ {value.length === 0 ? (
305
+ <div className="workbench-editor-area__form-empty" style={formDepthStyle(depth + 1)}>
306
+ Empty array
307
+ </div>
308
+ ) : (
309
+ value.map((item, index) => (
310
+ <JsonValueFormField
311
+ key={index}
312
+ depth={depth + 1}
313
+ label={`[${index}]`}
314
+ path={[...path, index]}
315
+ value={item}
316
+ onFieldChange={onFieldChange}
317
+ />
318
+ ))
319
+ )}
320
+ </JsonFormGroup>
321
+ );
322
+ }
323
+
324
+ if (isJsonRecord(value)) {
325
+ const entries = Object.entries(value);
326
+
327
+ return (
328
+ <JsonFormGroup depth={depth} label={label} meta={`object (${entries.length})`} path={path}>
329
+ {entries.length === 0 ? (
330
+ <div className="workbench-editor-area__form-empty" style={formDepthStyle(depth + 1)}>
331
+ Empty object
332
+ </div>
333
+ ) : (
334
+ entries.map(([key, childValue]) => (
335
+ <JsonValueFormField
336
+ key={key}
337
+ depth={depth + 1}
338
+ label={key}
339
+ path={[...path, key]}
340
+ value={childValue}
341
+ onFieldChange={onFieldChange}
342
+ />
343
+ ))
344
+ )}
345
+ </JsonFormGroup>
346
+ );
347
+ }
348
+
349
+ const fieldLabel = getJsonPathLabel(path);
350
+ const labelStyle = formDepthStyle(depth);
351
+
352
+ if (typeof value === 'boolean') {
353
+ return (
354
+ <label className="workbench-editor-area__form-field">
355
+ <span className="workbench-editor-area__form-label" style={labelStyle}>
356
+ {label}
357
+ </span>
358
+ <Select
359
+ aria-label={fieldLabel}
360
+ className="workbench-editor-area__form-control"
361
+ controlWidth="full"
362
+ value={String(value)}
363
+ onValueChange={(nextValue) => {
364
+ onFieldChange(path, nextValue);
365
+ }}
366
+ >
367
+ <option value="true">true</option>
368
+ <option value="false">false</option>
369
+ </Select>
370
+ </label>
371
+ );
372
+ }
373
+
374
+ if (typeof value === 'string' || typeof value === 'number') {
375
+ return (
376
+ <label className="workbench-editor-area__form-field">
377
+ <span className="workbench-editor-area__form-label" style={labelStyle}>
378
+ {label}
379
+ </span>
380
+ <TextInput
381
+ aria-label={fieldLabel}
382
+ className="workbench-editor-area__form-control"
383
+ controlWidth="full"
384
+ onValueChange={(nextValue) => {
385
+ onFieldChange(path, nextValue);
386
+ }}
387
+ step={typeof value === 'number' ? 'any' : undefined}
388
+ type={typeof value === 'number' ? 'number' : 'text'}
389
+ value={formatFormFieldValue(value)}
390
+ />
391
+ </label>
392
+ );
393
+ }
394
+
395
+ return (
396
+ <div className="workbench-editor-area__form-field">
397
+ <span className="workbench-editor-area__form-label" style={labelStyle}>
398
+ {label}
399
+ </span>
400
+ <output aria-label={fieldLabel} className="workbench-editor-area__form-readonly">
401
+ {formatFormFieldValue(value)}
402
+ </output>
403
+ </div>
404
+ );
405
+ }
406
+
407
+ function JsonFormGroup({
408
+ children,
409
+ depth,
410
+ label,
411
+ meta,
412
+ path,
413
+ }: {
414
+ children: ReactNode;
415
+ depth: number;
416
+ label: string;
417
+ meta: string;
418
+ path: JsonPath;
419
+ }) {
420
+ return (
421
+ <>
422
+ <div
423
+ aria-label={getJsonPathLabel(path)}
424
+ className="workbench-editor-area__form-group-header"
425
+ role="group"
426
+ style={formDepthStyle(depth)}
427
+ >
428
+ <span className="workbench-editor-area__form-label">{label}</span>
429
+ <span className="workbench-editor-area__form-badge">{meta}</span>
430
+ </div>
431
+ {children}
432
+ </>
433
+ );
434
+ }
435
+
436
+ function formDepthStyle(depth: number): CSSProperties {
437
+ return {
438
+ '--workbench-editor-form-depth': String(depth),
439
+ } as CSSProperties;
440
+ }
441
+
442
+ function isJsonLikeDocument(document: EditorDocumentContext): boolean {
443
+ const mimeType = document.mimeType?.toLowerCase();
444
+ const path = document.path.toLowerCase();
445
+
446
+ return (
447
+ path.endsWith('.json') ||
448
+ mimeType === 'application/json' ||
449
+ mimeType === 'application/schema+json' ||
450
+ mimeType === JDW_SCHEMA_DOCUMENT_MIME ||
451
+ Boolean(mimeType?.endsWith('+json'))
452
+ );
453
+ }
454
+
455
+ function isJdwDocument(document: EditorDocumentContext): boolean {
456
+ return document.mimeType === JDW_WIDGET_DOCUMENT_MIME || isJdwDocumentPath(document.path);
457
+ }
458
+
459
+ function isMarkdownDocument(document: EditorDocumentContext): boolean {
460
+ const mimeType = document.mimeType?.toLowerCase();
461
+ const path = document.path.toLowerCase();
462
+
463
+ return path.endsWith('.md') || path.endsWith('.mdx') || mimeType === 'text/markdown';
464
+ }
465
+
466
+ function parseJsonObject(content: string): Record<string, unknown> | null {
467
+ const trimmed = content.trim();
468
+ if (!trimmed) {
469
+ return {};
470
+ }
471
+
472
+ try {
473
+ const parsed: unknown = JSON.parse(trimmed);
474
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
475
+ return null;
476
+ }
477
+
478
+ return parsed as Record<string, unknown>;
479
+ } catch {
480
+ return null;
481
+ }
482
+ }
483
+
484
+ function isJsonRecord(value: unknown): value is Record<string, unknown> {
485
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
486
+ }
487
+
488
+ function isJdwWidgetJson(content: string): boolean {
489
+ const parsed = parseJsonWidgetData(content);
490
+ return parsed.value !== null;
491
+ }
492
+
493
+ function formatFormFieldValue(value: unknown): string {
494
+ if (typeof value === 'string') {
495
+ return value;
496
+ }
497
+
498
+ if (typeof value === 'number' || typeof value === 'boolean') {
499
+ return String(value);
500
+ }
501
+
502
+ return JSON.stringify(value) ?? String(value);
503
+ }
504
+
505
+ function coerceFormFieldValue(previousValue: unknown, nextValue: string): unknown {
506
+ if (typeof previousValue === 'number') {
507
+ const parsedNumber = Number(nextValue);
508
+ return Number.isNaN(parsedNumber) ? previousValue : parsedNumber;
509
+ }
510
+
511
+ if (typeof previousValue === 'boolean') {
512
+ if (nextValue === 'true') {
513
+ return true;
514
+ }
515
+
516
+ if (nextValue === 'false') {
517
+ return false;
518
+ }
519
+ }
520
+
521
+ return nextValue;
522
+ }
523
+
524
+ function getJsonPathValue(value: unknown, path: JsonPath): unknown {
525
+ let cursor = value;
526
+
527
+ for (const segment of path) {
528
+ if (Array.isArray(cursor) && typeof segment === 'number') {
529
+ cursor = cursor[segment];
530
+ continue;
531
+ }
532
+
533
+ if (isJsonRecord(cursor) && typeof segment === 'string') {
534
+ cursor = cursor[segment];
535
+ continue;
536
+ }
537
+
538
+ return undefined;
539
+ }
540
+
541
+ return cursor;
542
+ }
543
+
544
+ function getJsonPathLabel(path: JsonPath): string {
545
+ return path.reduce<string>((label, segment) => {
546
+ if (typeof segment === 'number') {
547
+ return `${label}[${segment}]`;
548
+ }
549
+
550
+ return label ? `${label}.${segment}` : segment;
551
+ }, '');
552
+ }
@@ -0,0 +1,15 @@
1
+ import { parseWorkspaceResourceUri } from '@workbench-kit/workspace';
2
+
3
+ /** Pure helper — kept out of React component modules for Fast Refresh. */
4
+ export function createWorkspaceFileAvailabilityChecker(
5
+ filePaths: ReadonlySet<string>,
6
+ ): (resourceUri: string) => boolean {
7
+ return (resourceUri) => {
8
+ const parsed = parseWorkspaceResourceUri(resourceUri);
9
+ if (!parsed || parsed.kind !== 'file') {
10
+ return true;
11
+ }
12
+
13
+ return filePaths.has(parsed.path);
14
+ };
15
+ }
@@ -0,0 +1,28 @@
1
+ import { useEffect } from 'react';
2
+
3
+ import { createWorkspaceFileAvailabilityChecker } from './editor-workspace-file-availability.js';
4
+ import { useEditorService } from './use-editor.js';
5
+ import { useWorkbench } from './provider.js';
6
+ import { isWorkspaceResourceService, useWorkspaceResourceState } from './workspace-view-state.js';
7
+
8
+ /** Component-only module so Vite Fast Refresh can accept this boundary. */
9
+ export function EditorWorkspaceReconciler(): null {
10
+ const { workspaceHostPort } = useWorkbench();
11
+ const editorService = useEditorService();
12
+ const workspaceService = isWorkspaceResourceService(workspaceHostPort?.service)
13
+ ? workspaceHostPort.service
14
+ : undefined;
15
+ const workspaceState = useWorkspaceResourceState(workspaceService);
16
+
17
+ useEffect(() => {
18
+ if (!workspaceService) {
19
+ return;
20
+ }
21
+
22
+ const files = workspaceState?.files ?? workspaceService.getState().files;
23
+ const filePaths = new Set(files.map((file) => file.path));
24
+ editorService.reconcileWorkspaceFileTabs(createWorkspaceFileAvailabilityChecker(filePaths));
25
+ }, [editorService, workspaceService, workspaceState]);
26
+
27
+ return null;
28
+ }
@@ -0,0 +1,114 @@
1
+ import type { ContextMenuItem } from '@workbench-kit/react/overlay';
2
+ import {
3
+ WORKBENCH_COMMAND_SURFACE_WORKSPACE,
4
+ commandMenuItemsToContextMenuItems,
5
+ createWorkbenchWorkspaceCommands,
6
+ createWorkbenchWorkspaceFolderMenuEntries,
7
+ createWorkbenchWorkspaceTargetMenuEntries,
8
+ type WorkbenchWorkspaceCommandContext,
9
+ } from '@workbench-kit/react/workbench/commands';
10
+ import {
11
+ createCommandRegistry,
12
+ executeCommand as executeRegisteredCommand,
13
+ resolveCommandMenuItems,
14
+ } from '@workbench-kit/platform';
15
+ import { parentPathOf, type WorkspaceTreeNode } from '@workbench-kit/workspace';
16
+ import type { ExtensionRegistry } from '@workbench-kit/workbench-core';
17
+ import {
18
+ appendExtensionContextMenuItems,
19
+ createExtensionContextMenuItems,
20
+ } from './extension-context-menu.js';
21
+
22
+ const workspaceCommandRegistry = createCommandRegistry(createWorkbenchWorkspaceCommands());
23
+ const workspaceFolderMenuEntries =
24
+ createWorkbenchWorkspaceFolderMenuEntries<WorkbenchWorkspaceCommandContext>();
25
+ const workspaceTargetMenuEntries =
26
+ createWorkbenchWorkspaceTargetMenuEntries<WorkbenchWorkspaceCommandContext>();
27
+ const EXPLORER_CONTEXT_MENU = 'explorer/context';
28
+ const EXPLORER_EXTENSION_MENU_SEPARATOR_ID = 'explorer-extension-separator';
29
+
30
+ export function createExplorerItemContextMenuItems({
31
+ actionPaths,
32
+ copyPaths,
33
+ createFile,
34
+ createFolder,
35
+ deleteTargets,
36
+ executeExtensionCommand,
37
+ extensionRegistry,
38
+ files,
39
+ node,
40
+ openFiles,
41
+ revealFolder,
42
+ renameTarget,
43
+ }: {
44
+ actionPaths: readonly string[];
45
+ copyPaths: (paths: string[]) => void;
46
+ createFile: (parentPath: string) => void;
47
+ createFolder: (parentPath: string) => void;
48
+ deleteTargets: (paths: string[]) => void;
49
+ executeExtensionCommand?: ((commandId: string) => unknown) | undefined;
50
+ extensionRegistry?: ExtensionRegistry | undefined;
51
+ files: readonly { path: string }[];
52
+ node: WorkspaceTreeNode;
53
+ openFiles: (paths: string[]) => void;
54
+ revealFolder: (path: string) => void;
55
+ renameTarget: () => void;
56
+ }): ContextMenuItem[] {
57
+ const fileActionPaths =
58
+ node.type === 'file'
59
+ ? actionPaths.length > 0
60
+ ? [...actionPaths]
61
+ : [node.path]
62
+ : actionPaths.filter((path) => files.some((file) => file.path === path));
63
+ const multiFileAction = fileActionPaths.length > 1;
64
+ const targetPaths = node.type === 'folder' ? [node.path] : [...fileActionPaths];
65
+ const contextKeys = {
66
+ 'workspace.hasSelection': targetPaths.length > 0,
67
+ 'workspace.multiSelection': node.type === 'file' && multiFileAction,
68
+ };
69
+
70
+ const context: WorkbenchWorkspaceCommandContext = {
71
+ copyWorkspaceTarget: () => copyPaths([...targetPaths]),
72
+ createWorkspaceFile: () =>
73
+ createFile(node.type === 'folder' ? node.path : parentPathOf(node.path)),
74
+ createWorkspaceFolder: () =>
75
+ createFolder(node.type === 'folder' ? node.path : parentPathOf(node.path)),
76
+ deleteWorkspaceTarget: () => deleteTargets([...targetPaths]),
77
+ fileActionPaths,
78
+ multiFileAction,
79
+ openWorkspaceTarget: () => {
80
+ if (node.type === 'folder') {
81
+ revealFolder(node.path);
82
+ return;
83
+ }
84
+
85
+ openFiles(fileActionPaths);
86
+ },
87
+ renameWorkspaceTarget: renameTarget,
88
+ targetPaths,
89
+ workspaceTargetKind: node.type,
90
+ };
91
+
92
+ const baseItems = commandMenuItemsToContextMenuItems(
93
+ resolveCommandMenuItems({
94
+ context,
95
+ contextKeys,
96
+ entries: node.type === 'folder' ? workspaceFolderMenuEntries : workspaceTargetMenuEntries,
97
+ registry: workspaceCommandRegistry,
98
+ surface: WORKBENCH_COMMAND_SURFACE_WORKSPACE,
99
+ }),
100
+ (commandId) =>
101
+ executeRegisteredCommand(workspaceCommandRegistry, commandId, context, contextKeys),
102
+ );
103
+
104
+ return appendExtensionContextMenuItems(
105
+ baseItems,
106
+ createExtensionContextMenuItems({
107
+ contextKeys,
108
+ executeCommand: executeExtensionCommand,
109
+ extensionRegistry,
110
+ menu: EXPLORER_CONTEXT_MENU,
111
+ }),
112
+ EXPLORER_EXTENSION_MENU_SEPARATOR_ID,
113
+ );
114
+ }