@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,112 @@
1
+ import type { WorkspaceSelectionState } from '@workbench-kit/workspace';
2
+
3
+ import {
4
+ BUILTIN_EXPLORER_FOCUS_COMMAND_ID,
5
+ BUILTIN_EXPLORER_REVEAL_COMMAND_ID,
6
+ BUILTIN_EXPLORER_VIEW_CONTAINER_ID,
7
+ resolveExplorerRevealPath,
8
+ } from './explorer-view-data.js';
9
+
10
+ export {
11
+ BUILTIN_EXPLORER_FOCUS_COMMAND_ID,
12
+ BUILTIN_EXPLORER_REVEAL_COMMAND_ID,
13
+ BUILTIN_EXPLORER_VIEW_CONTAINER_ID,
14
+ resolveExplorerRevealPath,
15
+ };
16
+
17
+ type ExplorerRevealListener = (path: string) => void;
18
+
19
+ let pendingRevealPath: string | undefined;
20
+ let revealListener: ExplorerRevealListener | undefined;
21
+
22
+ export function publishExplorerRevealRequest(path: string): void {
23
+ const normalizedPath = path.trim();
24
+ if (!normalizedPath) {
25
+ return;
26
+ }
27
+
28
+ pendingRevealPath = normalizedPath;
29
+ revealListener?.(normalizedPath);
30
+ }
31
+
32
+ export function subscribeExplorerRevealRequest(listener: ExplorerRevealListener): () => void {
33
+ revealListener = listener;
34
+
35
+ if (pendingRevealPath) {
36
+ listener(pendingRevealPath);
37
+ pendingRevealPath = undefined;
38
+ }
39
+
40
+ return () => {
41
+ if (revealListener === listener) {
42
+ revealListener = undefined;
43
+ }
44
+ };
45
+ }
46
+
47
+ export function applyExplorerPathReveal(
48
+ path: string,
49
+ {
50
+ revealFolder,
51
+ setSelection,
52
+ }: {
53
+ revealFolder: (folderPath: string) => void;
54
+ setSelection: (selection: WorkspaceSelectionState) => void;
55
+ },
56
+ ): void {
57
+ const normalizedPath = path.trim();
58
+ if (!normalizedPath) {
59
+ return;
60
+ }
61
+
62
+ workspaceExplorerParentPaths(normalizedPath).forEach((folderPath) => {
63
+ revealFolder(folderPath);
64
+ });
65
+ setSelection({
66
+ anchorPath: normalizedPath,
67
+ focusedPath: normalizedPath,
68
+ paths: [normalizedPath],
69
+ });
70
+ }
71
+
72
+ function workspaceExplorerParentPaths(path: string): string[] {
73
+ const segments = path.split('/').filter(Boolean);
74
+ return segments.slice(0, -1).map((_, index) => segments.slice(0, index + 1).join('/'));
75
+ }
76
+
77
+ export function isExplorerHostCommand(commandId: string): boolean {
78
+ return (
79
+ commandId === BUILTIN_EXPLORER_REVEAL_COMMAND_ID ||
80
+ commandId === BUILTIN_EXPLORER_FOCUS_COMMAND_ID
81
+ );
82
+ }
83
+
84
+ export async function runExplorerHostCommandSideEffects(
85
+ commandId: string,
86
+ args: readonly unknown[],
87
+ result: unknown,
88
+ {
89
+ focusExplorerView,
90
+ revealPath,
91
+ }: {
92
+ focusExplorerView: () => void;
93
+ revealPath: (path: string) => void;
94
+ },
95
+ ): Promise<void> {
96
+ if (commandId === BUILTIN_EXPLORER_FOCUS_COMMAND_ID) {
97
+ focusExplorerView();
98
+ return;
99
+ }
100
+
101
+ if (commandId !== BUILTIN_EXPLORER_REVEAL_COMMAND_ID) {
102
+ return;
103
+ }
104
+
105
+ const path = resolveExplorerRevealPath(args[0], result);
106
+ if (!path) {
107
+ return;
108
+ }
109
+
110
+ focusExplorerView();
111
+ revealPath(path);
112
+ }
@@ -0,0 +1,58 @@
1
+ export const BUILTIN_EXPLORER_VIEW_RENDER_KIND = 'workbench-kit.builtin.explorer.view' as const;
2
+ export const BUILTIN_EXPLORER_VIEW_CONTAINER_ID = 'explorer' as const;
3
+ export const BUILTIN_EXPLORER_MOVE_COMMAND_ID = 'workbench-kit.builtin.explorer.move' as const;
4
+ export const BUILTIN_EXPLORER_REFRESH_COMMAND_ID =
5
+ 'workbench-kit.builtin.explorer.refresh' as const;
6
+ export const BUILTIN_EXPLORER_REVEAL_COMMAND_ID = 'workbench-kit.builtin.explorer.reveal' as const;
7
+ export const BUILTIN_EXPLORER_FOCUS_COMMAND_ID = 'workbench-kit.builtin.explorer.focus' as const;
8
+
9
+ interface ExplorerRevealCommandResult {
10
+ readonly path?: string | undefined;
11
+ }
12
+
13
+ export interface BuiltinExplorerViewRenderData {
14
+ readonly kind: typeof BUILTIN_EXPLORER_VIEW_RENDER_KIND;
15
+ }
16
+
17
+ export function isBuiltinExplorerViewRenderData(
18
+ value: unknown,
19
+ ): value is BuiltinExplorerViewRenderData {
20
+ return (
21
+ typeof value === 'object' &&
22
+ value !== null &&
23
+ (value as { kind?: unknown }).kind === BUILTIN_EXPLORER_VIEW_RENDER_KIND
24
+ );
25
+ }
26
+
27
+ export function resolveExplorerRevealPath(input: unknown, result: unknown): string | undefined {
28
+ const resultPath = readRevealPath(result);
29
+ if (resultPath) {
30
+ return resultPath;
31
+ }
32
+
33
+ return readRevealPath(input);
34
+ }
35
+
36
+ function readRevealPath(value: unknown): string | undefined {
37
+ if (typeof value === 'string') {
38
+ const normalizedPath = value.trim();
39
+ return normalizedPath.length > 0 ? normalizedPath : undefined;
40
+ }
41
+
42
+ if (typeof value !== 'object' || value === null) {
43
+ return undefined;
44
+ }
45
+
46
+ const record = value as ExplorerRevealCommandResult & {
47
+ paths?: readonly string[] | undefined;
48
+ };
49
+ const directPath = typeof record.path === 'string' ? record.path.trim() : '';
50
+ if (directPath) {
51
+ return directPath;
52
+ }
53
+
54
+ const firstPath = record.paths?.find(
55
+ (path) => typeof path === 'string' && path.trim().length > 0,
56
+ );
57
+ return firstPath?.trim();
58
+ }
@@ -0,0 +1,224 @@
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useMemo,
5
+ useRef,
6
+ useState,
7
+ type MouseEvent as ReactMouseEvent,
8
+ } from 'react';
9
+ import { ContextMenu, type ContextMenuItem } from '@workbench-kit/react/overlay';
10
+ import { ViewEmptyState } from '@workbench-kit/react/primitives';
11
+ import {
12
+ WORKBENCH_WORKSPACE_COPY_PATH_COMMAND_ID,
13
+ WORKBENCH_WORKSPACE_DELETE_COMMAND_ID,
14
+ WORKBENCH_WORKSPACE_OPEN_COMMAND_ID,
15
+ } from '@workbench-kit/react/workbench/commands';
16
+ import {
17
+ WorkspaceExplorerPanel,
18
+ buildWorkspaceExplorerNodes,
19
+ resolveWorkspaceExplorerSectionTitle,
20
+ useWorkspaceExplorerController,
21
+ } from '@workbench-kit/react/workbench/workspace';
22
+ import { type WorkspaceExplorerItemContextMenuMeta } from '@workbench-kit/react/workbench/workspace/explorer';
23
+ import { resolveWorkspaceCreateParentPath, type WorkspaceTreeNode } from '@workbench-kit/workspace';
24
+ import { createCommandWorkspaceExplorerPort } from './createCommandWorkspaceExplorerPort.js';
25
+ import { createExplorerItemContextMenuItems } from './explorer-context-menu.js';
26
+ import { applyExplorerPathReveal, subscribeExplorerRevealRequest } from './explorer-reveal.js';
27
+ import {
28
+ BUILTIN_EXPLORER_REFRESH_COMMAND_ID,
29
+ type BuiltinExplorerViewRenderData,
30
+ } from './explorer-view-data.js';
31
+ import { useWorkbench } from './provider.js';
32
+ import { useActiveWorkspacePath } from './use-active-workspace-path.js';
33
+ import { useActiveEditorTab } from './use-editor.js';
34
+ import { isWorkspaceResourceService, useWorkspaceResourceState } from './workspace-view-state.js';
35
+
36
+ export type { BuiltinExplorerViewRenderData };
37
+ export {
38
+ BUILTIN_EXPLORER_MOVE_COMMAND_ID,
39
+ BUILTIN_EXPLORER_REFRESH_COMMAND_ID,
40
+ BUILTIN_EXPLORER_VIEW_RENDER_KIND,
41
+ isBuiltinExplorerViewRenderData,
42
+ } from './explorer-view-data.js';
43
+
44
+ interface ExplorerContextMenuState {
45
+ readonly ariaLabel: string;
46
+ readonly items: ContextMenuItem[];
47
+ readonly x: number;
48
+ readonly y: number;
49
+ }
50
+
51
+ export function BuiltinExplorerView() {
52
+ const { executeCommand, extensionRegistry, workspaceHostPort } = useWorkbench();
53
+ const activeTab = useActiveEditorTab();
54
+ const workspaceService = isWorkspaceResourceService(workspaceHostPort?.service)
55
+ ? workspaceHostPort.service
56
+ : undefined;
57
+ const workspaceState = useWorkspaceResourceState(workspaceService);
58
+ const [contextMenu, setContextMenu] = useState<ExplorerContextMenuState | null>(null);
59
+ const [seededExpandedPaths, setSeededExpandedPaths] = useState(false);
60
+
61
+ const activePath = useActiveWorkspacePath(activeTab?.resourceUri);
62
+
63
+ const port = useMemo(
64
+ () =>
65
+ createCommandWorkspaceExplorerPort({
66
+ executeCommand,
67
+ workspaceState,
68
+ }),
69
+ [executeCommand, workspaceState],
70
+ );
71
+
72
+ const explorer = useWorkspaceExplorerController({
73
+ activePath,
74
+ initialExpandedPaths: workspaceState?.expandedPaths,
75
+ port,
76
+ });
77
+ const explorerRef = useRef(explorer);
78
+ explorerRef.current = explorer;
79
+
80
+ useEffect(() => {
81
+ if (!workspaceState || seededExpandedPaths) {
82
+ return;
83
+ }
84
+
85
+ workspaceState.expandedPaths.forEach((path) => {
86
+ explorer.revealFolder(path);
87
+ });
88
+ setSeededExpandedPaths(true);
89
+ }, [explorer, seededExpandedPaths, workspaceState]);
90
+
91
+ useEffect(
92
+ () =>
93
+ subscribeExplorerRevealRequest((path) => {
94
+ const currentExplorer = explorerRef.current;
95
+ applyExplorerPathReveal(path, {
96
+ revealFolder: currentExplorer.revealFolder,
97
+ setSelection: (selection) => {
98
+ currentExplorer.handleSelectionChange(selection, { mode: 'single', reason: 'click' });
99
+ },
100
+ });
101
+ }),
102
+ [],
103
+ );
104
+
105
+ const nodes = useMemo(
106
+ () =>
107
+ buildWorkspaceExplorerNodes({
108
+ files: workspaceState?.files ?? [],
109
+ folders: workspaceState?.folders ?? [],
110
+ }),
111
+ [workspaceState],
112
+ );
113
+
114
+ const sectionTitle = useMemo(
115
+ () => resolveWorkspaceExplorerSectionTitle(workspaceState?.files ?? []),
116
+ [workspaceState?.files],
117
+ );
118
+
119
+ const createParentPath = useMemo(
120
+ () =>
121
+ resolveWorkspaceCreateParentPath(
122
+ explorer.selection.focusedPath,
123
+ workspaceState?.folders ?? [],
124
+ ),
125
+ [explorer.selection.focusedPath, workspaceState?.folders],
126
+ );
127
+
128
+ const executeWorkspaceCommand = useCallback(
129
+ async (commandId: string, payload?: unknown) => {
130
+ await executeCommand(commandId, payload);
131
+ },
132
+ [executeCommand],
133
+ );
134
+
135
+ const handleItemContextMenu = useCallback(
136
+ (
137
+ event: ReactMouseEvent<HTMLButtonElement>,
138
+ node: WorkspaceTreeNode,
139
+ meta: WorkspaceExplorerItemContextMenuMeta,
140
+ ) => {
141
+ event.preventDefault();
142
+ setContextMenu({
143
+ ariaLabel: `${node.name} menu`,
144
+ items: createExplorerItemContextMenuItems({
145
+ actionPaths: meta.actionPaths,
146
+ copyPaths: (paths) => {
147
+ void executeWorkspaceCommand(WORKBENCH_WORKSPACE_COPY_PATH_COMMAND_ID, { paths });
148
+ },
149
+ createFile: (parentPath) => explorer.startCreate('create-file', parentPath),
150
+ createFolder: (parentPath) => explorer.startCreate('create-folder', parentPath),
151
+ deleteTargets: (paths) => {
152
+ void executeWorkspaceCommand(WORKBENCH_WORKSPACE_DELETE_COMMAND_ID, {
153
+ kind: node.type,
154
+ paths,
155
+ });
156
+ },
157
+ executeExtensionCommand: (commandId) => executeCommand(commandId),
158
+ extensionRegistry,
159
+ files: workspaceState?.files ?? [],
160
+ node,
161
+ openFiles: (paths) => {
162
+ void executeWorkspaceCommand(WORKBENCH_WORKSPACE_OPEN_COMMAND_ID, {
163
+ kind: 'file',
164
+ paths,
165
+ });
166
+ },
167
+ revealFolder: explorer.revealFolder,
168
+ renameTarget: () => explorer.startRename(node, meta.actionPaths),
169
+ }),
170
+ x: event.clientX,
171
+ y: event.clientY,
172
+ });
173
+ },
174
+ [executeWorkspaceCommand, explorer, workspaceState?.files],
175
+ );
176
+
177
+ if (!workspaceService || !workspaceState) {
178
+ return (
179
+ <ViewEmptyState className="workbench-explorer-view">
180
+ No virtual workspace is registered.
181
+ </ViewEmptyState>
182
+ );
183
+ }
184
+
185
+ return (
186
+ <>
187
+ <WorkspaceExplorerPanel
188
+ activePath={activePath}
189
+ aria-label="Workspace Explorer"
190
+ expandedPaths={explorer.expandedPaths}
191
+ focusedPath={explorer.selection.focusedPath}
192
+ inlineEdit={explorer.inlineEdit}
193
+ nodes={nodes}
194
+ onNewFile={() => explorer.startCreate('create-file', createParentPath)}
195
+ onNewFolder={() => explorer.startCreate('create-folder', createParentPath)}
196
+ onRefresh={() => {
197
+ void executeWorkspaceCommand(BUILTIN_EXPLORER_REFRESH_COMMAND_ID);
198
+ }}
199
+ sectionTitle={sectionTitle}
200
+ selectedPaths={explorer.selection.paths}
201
+ selectionAnchorPath={explorer.selection.anchorPath}
202
+ onActivateFile={explorer.handleActivateFile}
203
+ onItemContextMenu={handleItemContextMenu}
204
+ onInlineEditCancel={explorer.cancelInlineEdit}
205
+ onInlineEditCommit={explorer.handleInlineEditCommit}
206
+ onInlineEditValueChange={explorer.handleInlineEditValueChange}
207
+ onRequestDelete={explorer.handleRequestDelete}
208
+ onRequestMove={explorer.handleRequestMove}
209
+ onRequestRename={explorer.handleRequestRename}
210
+ onSelectionChange={explorer.handleSelectionChange}
211
+ onToggleFolder={explorer.handleToggleFolder}
212
+ />
213
+ {contextMenu ? (
214
+ <ContextMenu
215
+ ariaLabel={contextMenu.ariaLabel}
216
+ items={contextMenu.items}
217
+ x={contextMenu.x}
218
+ y={contextMenu.y}
219
+ onClose={() => setContextMenu(null)}
220
+ />
221
+ ) : null}
222
+ </>
223
+ );
224
+ }
@@ -0,0 +1,52 @@
1
+ import type { ContextMenuItem } from '@workbench-kit/react/overlay';
2
+ import { commandMenuItemsToContextMenuItems } from '@workbench-kit/react/workbench/commands';
3
+ import {
4
+ resolveWorkbenchMenuContributions,
5
+ type ExtensionRegistry,
6
+ } from '@workbench-kit/workbench-core';
7
+
8
+ export interface ExtensionContextMenuInput {
9
+ readonly contextKeys?: object | undefined;
10
+ readonly executeCommand?: ((commandId: string) => unknown) | undefined;
11
+ readonly extensionRegistry?: ExtensionRegistry | undefined;
12
+ readonly menu: string;
13
+ }
14
+
15
+ export function createExtensionContextMenuItems({
16
+ contextKeys,
17
+ executeCommand,
18
+ extensionRegistry,
19
+ menu,
20
+ }: ExtensionContextMenuInput): ContextMenuItem[] {
21
+ if (!extensionRegistry || !executeCommand) {
22
+ return [];
23
+ }
24
+
25
+ const menuItems = resolveWorkbenchMenuContributions({
26
+ commandRegistry: extensionRegistry.commands,
27
+ context: undefined,
28
+ contextKeys,
29
+ menu,
30
+ menuItems: extensionRegistry.menus.getMenuItems(menu),
31
+ });
32
+
33
+ return commandMenuItemsToContextMenuItems([...menuItems], (commandId) => {
34
+ void executeCommand(commandId);
35
+ });
36
+ }
37
+
38
+ export function appendExtensionContextMenuItems(
39
+ baseItems: readonly ContextMenuItem[],
40
+ extensionItems: readonly ContextMenuItem[],
41
+ separatorId: string,
42
+ ): ContextMenuItem[] {
43
+ if (extensionItems.length === 0) {
44
+ return [...baseItems];
45
+ }
46
+
47
+ if (baseItems.length === 0) {
48
+ return [...extensionItems];
49
+ }
50
+
51
+ return [...baseItems, { id: separatorId, type: 'separator' }, ...extensionItems];
52
+ }