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

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 (105) hide show
  1. package/README.md +98 -0
  2. package/package.json +51 -0
  3. package/src/chat/ai-mock-proposals.ts +39 -0
  4. package/src/chat/command-input.ts +52 -0
  5. package/src/chat/command-policy.ts +54 -0
  6. package/src/chat/command-surface.tsx +155 -0
  7. package/src/chat/use-chat-command-proposals.ts +194 -0
  8. package/src/chat/view-data.ts +20 -0
  9. package/src/chat/view.tsx +220 -0
  10. package/src/commands/inspector-surface.tsx +46 -0
  11. package/src/commands/use-command-descriptors.ts +41 -0
  12. package/src/commands/use-context-key-revision.ts +18 -0
  13. package/src/commands/view-data.ts +17 -0
  14. package/src/commands/view.tsx +43 -0
  15. package/src/devtools/WorkbenchDevtoolsPanel.tsx +124 -0
  16. package/src/devtools/WorkbenchDevtoolsShell.tsx +17 -0
  17. package/src/devtools/index.ts +11 -0
  18. package/src/devtools/use-workbench-devtools-snapshot.ts +84 -0
  19. package/src/devtools/workbench-devtools-snapshot.ts +140 -0
  20. package/src/devtools/workbench-devtools.css +82 -0
  21. package/src/editor/area-dnd.ts +69 -0
  22. package/src/editor/area-model.ts +71 -0
  23. package/src/editor/area.css +454 -0
  24. package/src/editor/area.tsx +676 -0
  25. package/src/editor/host-surface.tsx +691 -0
  26. package/src/editor/markdown-document-view-data.ts +16 -0
  27. package/src/editor/pane-visibility.ts +130 -0
  28. package/src/editor/resource.ts +36 -0
  29. package/src/editor/state-storage.ts +182 -0
  30. package/src/editor/tab-context-menu.ts +118 -0
  31. package/src/editor/use-editor.ts +138 -0
  32. package/src/editor/view-providers.tsx +504 -0
  33. package/src/editor/workspace-file-availability.ts +15 -0
  34. package/src/editor/workspace-reconcile.tsx +31 -0
  35. package/src/explorer/context-menu.ts +114 -0
  36. package/src/explorer/create-command-workspace-explorer-port.ts +86 -0
  37. package/src/explorer/reveal.ts +112 -0
  38. package/src/explorer/search-view-data.ts +15 -0
  39. package/src/explorer/search-view.tsx +65 -0
  40. package/src/explorer/use-active-workspace-path.ts +15 -0
  41. package/src/explorer/view-data.ts +58 -0
  42. package/src/explorer/view.tsx +227 -0
  43. package/src/extensions/context-menu.ts +52 -0
  44. package/src/extensions/management-model.ts +313 -0
  45. package/src/extensions/use-extension-management.ts +241 -0
  46. package/src/extensions/view-data.ts +19 -0
  47. package/src/extensions/view.tsx +63 -0
  48. package/src/field-remap/chrome-labels.ts +74 -0
  49. package/src/field-remap/convert-note-editor.tsx +206 -0
  50. package/src/field-remap/convert-palette.tsx +126 -0
  51. package/src/field-remap/demo.tsx +105 -0
  52. package/src/field-remap/detail-panel.tsx +659 -0
  53. package/src/field-remap/editor-surface.tsx +36 -0
  54. package/src/field-remap/flow-adapter.ts +838 -0
  55. package/src/field-remap/flow-ops.ts +442 -0
  56. package/src/field-remap/flow.tsx +948 -0
  57. package/src/field-remap/graph.tsx +559 -0
  58. package/src/field-remap/index.ts +88 -0
  59. package/src/field-remap/io-class-browse.tsx +145 -0
  60. package/src/field-remap/jsonata-transform.ts +166 -0
  61. package/src/field-remap/panel.tsx +466 -0
  62. package/src/field-remap/samples.ts +507 -0
  63. package/src/field-remap/shape-io-editor.tsx +170 -0
  64. package/src/field-remap/table-mapping-adapter.ts +59 -0
  65. package/src/field-remap/transform-options-editor.tsx +312 -0
  66. package/src/field-remap/tree.tsx +404 -0
  67. package/src/field-remap/view-data.ts +16 -0
  68. package/src/field-remap/view.css +1367 -0
  69. package/src/field-remap/view.tsx +86 -0
  70. package/src/index.ts +294 -0
  71. package/src/jdw/document-view-data.ts +31 -0
  72. package/src/jdw/json-form-source-patch.ts +323 -0
  73. package/src/jdw/lab-view-data.ts +25 -0
  74. package/src/jdw/lab-view.css +21 -0
  75. package/src/jdw/lab-view.tsx +79 -0
  76. package/src/jdw/widget-form-view.tsx +68 -0
  77. package/src/jdw/widget-preview-view.tsx +54 -0
  78. package/src/management/keybinding-overrides-storage.ts +49 -0
  79. package/src/management/keybinding-settings.tsx +16 -0
  80. package/src/management/palette-commands.ts +38 -0
  81. package/src/management/preference-settings-storage.ts +50 -0
  82. package/src/management/settings-ids.ts +12 -0
  83. package/src/management/settings.tsx +96 -0
  84. package/src/management/use-command-management.ts +191 -0
  85. package/src/management/use-keybinding-management.ts +130 -0
  86. package/src/shell/model.tsx +149 -0
  87. package/src/shell/provider.tsx +606 -0
  88. package/src/shell/secondary-actions.tsx +59 -0
  89. package/src/shell/settings-constants.ts +9 -0
  90. package/src/shell/settings.tsx +599 -0
  91. package/src/shell/shell.tsx +680 -0
  92. package/src/shell/titlebar-layout-controls.tsx +4 -0
  93. package/src/shell/view-host.tsx +212 -0
  94. package/src/workbench/appearance-storage.ts +107 -0
  95. package/src/workbench/command-host.tsx +243 -0
  96. package/src/workbench/command-palette.ts +208 -0
  97. package/src/workbench/keybinding-bridge.ts +54 -0
  98. package/src/workbench/layout-storage.ts +134 -0
  99. package/src/workbench/profile-modal.tsx +118 -0
  100. package/src/workbench/shell-command-registration.ts +58 -0
  101. package/src/workbench/startup-gate.tsx +136 -0
  102. package/src/workbench/status-sections.ts +43 -0
  103. package/src/workbench/use-persisted-appearance.ts +33 -0
  104. package/src/workbench/user-commands.ts +46 -0
  105. package/src/workbench/workspace-view-state.ts +35 -0
@@ -0,0 +1,86 @@
1
+ import type {
2
+ WorkspaceExplorerControllerPort,
3
+ WorkspaceExplorerMutationResult,
4
+ WorkspaceExplorerWorkspaceSnapshot,
5
+ } from '@workbench-kit/react/workbench/workspace';
6
+ import type { VirtualWorkspaceState } from '@workbench-kit/workspace';
7
+
8
+ import { BUILTIN_EXPLORER_MOVE_COMMAND_ID } from './view-data.js';
9
+
10
+ const WORKBENCH_WORKSPACE_DELETE_COMMAND_ID = 'workspace.delete' as const;
11
+ const WORKBENCH_WORKSPACE_NEW_FILE_COMMAND_ID = 'workspace.newFile' as const;
12
+ const WORKBENCH_WORKSPACE_NEW_FOLDER_COMMAND_ID = 'workspace.newFolder' as const;
13
+ const WORKBENCH_WORKSPACE_OPEN_COMMAND_ID = 'workspace.open' as const;
14
+ const WORKBENCH_WORKSPACE_RENAME_COMMAND_ID = 'workspace.rename' as const;
15
+
16
+ interface WorkspaceCommandResult {
17
+ readonly path?: string | undefined;
18
+ readonly paths?: readonly string[] | undefined;
19
+ }
20
+
21
+ export function createCommandWorkspaceExplorerPort({
22
+ executeCommand,
23
+ workspaceState,
24
+ }: {
25
+ executeCommand(commandId: string, payload?: unknown): Promise<unknown>;
26
+ workspaceState: VirtualWorkspaceState | undefined;
27
+ }): WorkspaceExplorerControllerPort {
28
+ const snapshot: WorkspaceExplorerWorkspaceSnapshot = {
29
+ files: workspaceState?.files ?? [],
30
+ folders: workspaceState?.folders ?? [],
31
+ };
32
+
33
+ return {
34
+ snapshot,
35
+ createFile(input) {
36
+ return runWorkspaceCommand(executeCommand, WORKBENCH_WORKSPACE_NEW_FILE_COMMAND_ID, input);
37
+ },
38
+ createFolder(input) {
39
+ return runWorkspaceCommand(executeCommand, WORKBENCH_WORKSPACE_NEW_FOLDER_COMMAND_ID, input);
40
+ },
41
+ deleteEntries({ kind, paths }) {
42
+ void executeCommand(WORKBENCH_WORKSPACE_DELETE_COMMAND_ID, {
43
+ kind,
44
+ paths,
45
+ });
46
+ },
47
+ moveEntries(input) {
48
+ return runWorkspaceCommand(executeCommand, BUILTIN_EXPLORER_MOVE_COMMAND_ID, {
49
+ sourcePaths: input.sourcePaths,
50
+ targetFolderPath: input.targetFolderPath,
51
+ });
52
+ },
53
+ openFile(path) {
54
+ void executeCommand(WORKBENCH_WORKSPACE_OPEN_COMMAND_ID, {
55
+ kind: 'file',
56
+ path,
57
+ paths: [path],
58
+ });
59
+ },
60
+ renameEntry(input) {
61
+ return runWorkspaceCommand(executeCommand, WORKBENCH_WORKSPACE_RENAME_COMMAND_ID, input);
62
+ },
63
+ };
64
+ }
65
+
66
+ async function runWorkspaceCommand(
67
+ executeCommand: (commandId: string, payload?: unknown) => Promise<unknown>,
68
+ commandId: string,
69
+ payload: unknown,
70
+ ): Promise<WorkspaceExplorerMutationResult | undefined> {
71
+ const result = await executeCommand(commandId, payload);
72
+ return isWorkspaceCommandResult(result) ? result : undefined;
73
+ }
74
+
75
+ function isWorkspaceCommandResult(value: unknown): value is WorkspaceCommandResult {
76
+ if (typeof value !== 'object' || value === null) {
77
+ return false;
78
+ }
79
+
80
+ const result = value as WorkspaceCommandResult;
81
+ return (
82
+ (result.path === undefined || typeof result.path === 'string') &&
83
+ (result.paths === undefined ||
84
+ (Array.isArray(result.paths) && result.paths.every((path) => typeof path === 'string')))
85
+ );
86
+ }
@@ -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 './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,15 @@
1
+ export const BUILTIN_SEARCH_VIEW_RENDER_KIND = 'workbench-kit.builtin.search.view' as const;
2
+
3
+ export interface BuiltinSearchViewRenderData {
4
+ readonly kind: typeof BUILTIN_SEARCH_VIEW_RENDER_KIND;
5
+ }
6
+
7
+ export function isBuiltinSearchViewRenderData(
8
+ value: unknown,
9
+ ): value is BuiltinSearchViewRenderData {
10
+ return (
11
+ typeof value === 'object' &&
12
+ value !== null &&
13
+ (value as { kind?: unknown }).kind === BUILTIN_SEARCH_VIEW_RENDER_KIND
14
+ );
15
+ }
@@ -0,0 +1,65 @@
1
+ import { useCallback, useMemo, useState } from 'react';
2
+ import { ViewEmptyState } from '@workbench-kit/react/primitives';
3
+ import { WorkspaceSearchPanel } from '@workbench-kit/react/workbench/workspace';
4
+ import { searchWorkspaceFiles, type WorkspaceSearchResult } from '@workbench-kit/workspace';
5
+
6
+ import { useWorkbench } from '../shell/provider.js';
7
+ import { useActiveWorkspacePath } from './use-active-workspace-path.js';
8
+ import { useActiveEditorTab } from '../editor/use-editor.js';
9
+ import {
10
+ BUILTIN_SEARCH_VIEW_RENDER_KIND,
11
+ isBuiltinSearchViewRenderData,
12
+ type BuiltinSearchViewRenderData,
13
+ } from './search-view-data.js';
14
+ import {
15
+ isWorkspaceResourceService,
16
+ useWorkspaceResourceState,
17
+ } from '../workbench/workspace-view-state.js';
18
+
19
+ export type { BuiltinSearchViewRenderData };
20
+ export { BUILTIN_SEARCH_VIEW_RENDER_KIND, isBuiltinSearchViewRenderData };
21
+
22
+ const WORKSPACE_OPEN_COMMAND_ID = 'workspace.open' as const;
23
+
24
+ export function BuiltinSearchView() {
25
+ const { executeCommand, workspaceHostPort } = useWorkbench();
26
+ const activeTab = useActiveEditorTab();
27
+ const workspaceService = isWorkspaceResourceService(workspaceHostPort?.service)
28
+ ? workspaceHostPort.service
29
+ : undefined;
30
+ const workspaceState = useWorkspaceResourceState(workspaceService);
31
+ const [query, setQuery] = useState(workspaceState?.searchQuery ?? '');
32
+
33
+ const activePath = useActiveWorkspacePath(activeTab?.resourceUri);
34
+
35
+ const results = useMemo<WorkspaceSearchResult[]>(() => {
36
+ if (!workspaceState) return [];
37
+ return searchWorkspaceFiles(workspaceState.files, query);
38
+ }, [query, workspaceState]);
39
+
40
+ const openResult = useCallback(
41
+ (result: WorkspaceSearchResult) => {
42
+ void executeCommand(WORKSPACE_OPEN_COMMAND_ID, { path: result.path });
43
+ },
44
+ [executeCommand],
45
+ );
46
+
47
+ if (!workspaceState) {
48
+ return (
49
+ <ViewEmptyState className="workbench-search-view">
50
+ No virtual workspace is registered.
51
+ </ViewEmptyState>
52
+ );
53
+ }
54
+
55
+ return (
56
+ <WorkspaceSearchPanel
57
+ activePath={activePath}
58
+ className="workbench-search-view"
59
+ query={query}
60
+ results={results}
61
+ onActivateResult={openResult}
62
+ onQueryChange={setQuery}
63
+ />
64
+ );
65
+ }
@@ -0,0 +1,15 @@
1
+ import { useMemo } from 'react';
2
+ import { parseWorkspaceResourceUri } from '@workbench-kit/workspace';
3
+
4
+ export function resolveActiveWorkspacePath(resourceUri: string | undefined): string | undefined {
5
+ if (!resourceUri) {
6
+ return undefined;
7
+ }
8
+
9
+ const resource = parseWorkspaceResourceUri(resourceUri);
10
+ return resource?.kind === 'file' ? resource.path : undefined;
11
+ }
12
+
13
+ export function useActiveWorkspacePath(resourceUri: string | undefined): string | undefined {
14
+ return useMemo(() => resolveActiveWorkspacePath(resourceUri), [resourceUri]);
15
+ }
@@ -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,227 @@
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 './create-command-workspace-explorer-port.js';
25
+ import { createExplorerItemContextMenuItems } from './context-menu.js';
26
+ import { applyExplorerPathReveal, subscribeExplorerRevealRequest } from './reveal.js';
27
+ import {
28
+ BUILTIN_EXPLORER_REFRESH_COMMAND_ID,
29
+ type BuiltinExplorerViewRenderData,
30
+ } from './view-data.js';
31
+ import { useWorkbench } from '../shell/provider.js';
32
+ import { useActiveWorkspacePath } from './use-active-workspace-path.js';
33
+ import { useActiveEditorTab } from '../editor/use-editor.js';
34
+ import {
35
+ isWorkspaceResourceService,
36
+ useWorkspaceResourceState,
37
+ } from '../workbench/workspace-view-state.js';
38
+
39
+ export type { BuiltinExplorerViewRenderData };
40
+ export {
41
+ BUILTIN_EXPLORER_MOVE_COMMAND_ID,
42
+ BUILTIN_EXPLORER_REFRESH_COMMAND_ID,
43
+ BUILTIN_EXPLORER_VIEW_RENDER_KIND,
44
+ isBuiltinExplorerViewRenderData,
45
+ } from './view-data.js';
46
+
47
+ interface ExplorerContextMenuState {
48
+ readonly ariaLabel: string;
49
+ readonly items: ContextMenuItem[];
50
+ readonly x: number;
51
+ readonly y: number;
52
+ }
53
+
54
+ export function BuiltinExplorerView() {
55
+ const { executeCommand, extensionRegistry, workspaceHostPort } = useWorkbench();
56
+ const activeTab = useActiveEditorTab();
57
+ const workspaceService = isWorkspaceResourceService(workspaceHostPort?.service)
58
+ ? workspaceHostPort.service
59
+ : undefined;
60
+ const workspaceState = useWorkspaceResourceState(workspaceService);
61
+ const [contextMenu, setContextMenu] = useState<ExplorerContextMenuState | null>(null);
62
+ const [seededExpandedPaths, setSeededExpandedPaths] = useState(false);
63
+
64
+ const activePath = useActiveWorkspacePath(activeTab?.resourceUri);
65
+
66
+ const port = useMemo(
67
+ () =>
68
+ createCommandWorkspaceExplorerPort({
69
+ executeCommand,
70
+ workspaceState,
71
+ }),
72
+ [executeCommand, workspaceState],
73
+ );
74
+
75
+ const explorer = useWorkspaceExplorerController({
76
+ activePath,
77
+ initialExpandedPaths: workspaceState?.expandedPaths,
78
+ port,
79
+ });
80
+ const explorerRef = useRef(explorer);
81
+ explorerRef.current = explorer;
82
+
83
+ useEffect(() => {
84
+ if (!workspaceState || seededExpandedPaths) {
85
+ return;
86
+ }
87
+
88
+ workspaceState.expandedPaths.forEach((path) => {
89
+ explorer.revealFolder(path);
90
+ });
91
+ setSeededExpandedPaths(true);
92
+ }, [explorer, seededExpandedPaths, workspaceState]);
93
+
94
+ useEffect(
95
+ () =>
96
+ subscribeExplorerRevealRequest((path) => {
97
+ const currentExplorer = explorerRef.current;
98
+ applyExplorerPathReveal(path, {
99
+ revealFolder: currentExplorer.revealFolder,
100
+ setSelection: (selection) => {
101
+ currentExplorer.handleSelectionChange(selection, { mode: 'single', reason: 'click' });
102
+ },
103
+ });
104
+ }),
105
+ [],
106
+ );
107
+
108
+ const nodes = useMemo(
109
+ () =>
110
+ buildWorkspaceExplorerNodes({
111
+ files: workspaceState?.files ?? [],
112
+ folders: workspaceState?.folders ?? [],
113
+ }),
114
+ [workspaceState],
115
+ );
116
+
117
+ const sectionTitle = useMemo(
118
+ () => resolveWorkspaceExplorerSectionTitle(workspaceState?.files ?? []),
119
+ [workspaceState?.files],
120
+ );
121
+
122
+ const createParentPath = useMemo(
123
+ () =>
124
+ resolveWorkspaceCreateParentPath(
125
+ explorer.selection.focusedPath,
126
+ workspaceState?.folders ?? [],
127
+ ),
128
+ [explorer.selection.focusedPath, workspaceState?.folders],
129
+ );
130
+
131
+ const executeWorkspaceCommand = useCallback(
132
+ async (commandId: string, payload?: unknown) => {
133
+ await executeCommand(commandId, payload);
134
+ },
135
+ [executeCommand],
136
+ );
137
+
138
+ const handleItemContextMenu = useCallback(
139
+ (
140
+ event: ReactMouseEvent<HTMLButtonElement>,
141
+ node: WorkspaceTreeNode,
142
+ meta: WorkspaceExplorerItemContextMenuMeta,
143
+ ) => {
144
+ event.preventDefault();
145
+ setContextMenu({
146
+ ariaLabel: `${node.name} menu`,
147
+ items: createExplorerItemContextMenuItems({
148
+ actionPaths: meta.actionPaths,
149
+ copyPaths: (paths) => {
150
+ void executeWorkspaceCommand(WORKBENCH_WORKSPACE_COPY_PATH_COMMAND_ID, { paths });
151
+ },
152
+ createFile: (parentPath) => explorer.startCreate('create-file', parentPath),
153
+ createFolder: (parentPath) => explorer.startCreate('create-folder', parentPath),
154
+ deleteTargets: (paths) => {
155
+ void executeWorkspaceCommand(WORKBENCH_WORKSPACE_DELETE_COMMAND_ID, {
156
+ kind: node.type,
157
+ paths,
158
+ });
159
+ },
160
+ executeExtensionCommand: (commandId) => executeCommand(commandId),
161
+ extensionRegistry,
162
+ files: workspaceState?.files ?? [],
163
+ node,
164
+ openFiles: (paths) => {
165
+ void executeWorkspaceCommand(WORKBENCH_WORKSPACE_OPEN_COMMAND_ID, {
166
+ kind: 'file',
167
+ paths,
168
+ });
169
+ },
170
+ revealFolder: explorer.revealFolder,
171
+ renameTarget: () => explorer.startRename(node, meta.actionPaths),
172
+ }),
173
+ x: event.clientX,
174
+ y: event.clientY,
175
+ });
176
+ },
177
+ [executeWorkspaceCommand, explorer, workspaceState?.files],
178
+ );
179
+
180
+ if (!workspaceService || !workspaceState) {
181
+ return (
182
+ <ViewEmptyState className="workbench-explorer-view">
183
+ No virtual workspace is registered.
184
+ </ViewEmptyState>
185
+ );
186
+ }
187
+
188
+ return (
189
+ <>
190
+ <WorkspaceExplorerPanel
191
+ activePath={activePath}
192
+ aria-label="Workspace Explorer"
193
+ expandedPaths={explorer.expandedPaths}
194
+ focusedPath={explorer.selection.focusedPath}
195
+ inlineEdit={explorer.inlineEdit}
196
+ nodes={nodes}
197
+ onNewFile={() => explorer.startCreate('create-file', createParentPath)}
198
+ onNewFolder={() => explorer.startCreate('create-folder', createParentPath)}
199
+ onRefresh={() => {
200
+ void executeWorkspaceCommand(BUILTIN_EXPLORER_REFRESH_COMMAND_ID);
201
+ }}
202
+ sectionTitle={sectionTitle}
203
+ selectedPaths={explorer.selection.paths}
204
+ selectionAnchorPath={explorer.selection.anchorPath}
205
+ onActivateFile={explorer.handleActivateFile}
206
+ onItemContextMenu={handleItemContextMenu}
207
+ onInlineEditCancel={explorer.cancelInlineEdit}
208
+ onInlineEditCommit={explorer.handleInlineEditCommit}
209
+ onInlineEditValueChange={explorer.handleInlineEditValueChange}
210
+ onRequestDelete={explorer.handleRequestDelete}
211
+ onRequestMove={explorer.handleRequestMove}
212
+ onRequestRename={explorer.handleRequestRename}
213
+ onSelectionChange={explorer.handleSelectionChange}
214
+ onToggleFolder={explorer.handleToggleFolder}
215
+ />
216
+ {contextMenu ? (
217
+ <ContextMenu
218
+ ariaLabel={contextMenu.ariaLabel}
219
+ items={contextMenu.items}
220
+ x={contextMenu.x}
221
+ y={contextMenu.y}
222
+ onClose={() => setContextMenu(null)}
223
+ />
224
+ ) : null}
225
+ </>
226
+ );
227
+ }
@@ -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
+ }