@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.
Files changed (95) hide show
  1. package/README.md +41 -0
  2. package/package.json +9 -9
  3. package/src/{chat-ai-mock-proposals.ts → chat/ai-mock-proposals.ts} +39 -39
  4. package/src/{chat-command-input.ts → chat/command-input.ts} +52 -52
  5. package/src/{chat-command-policy.ts → chat/command-policy.ts} +54 -54
  6. package/src/{chat-command-surface.tsx → chat/command-surface.tsx} +155 -155
  7. package/src/{use-workbench-chat-command-proposals.ts → chat/use-chat-command-proposals.ts} +194 -194
  8. package/src/{chat-view-data.ts → chat/view-data.ts} +20 -20
  9. package/src/{chat-view.tsx → chat/view.tsx} +220 -220
  10. package/src/{command-inspector-surface.tsx → commands/inspector-surface.tsx} +46 -46
  11. package/src/{use-workbench-command-descriptors.ts → commands/use-command-descriptors.ts} +41 -41
  12. package/src/{use-context-key-revision.ts → commands/use-context-key-revision.ts} +18 -18
  13. package/src/{commands-view-data.ts → commands/view-data.ts} +17 -17
  14. package/src/{commands-view.tsx → commands/view.tsx} +43 -43
  15. package/src/devtools/WorkbenchDevtoolsPanel.tsx +124 -124
  16. package/src/devtools/WorkbenchDevtoolsShell.tsx +17 -17
  17. package/src/devtools/index.ts +11 -11
  18. package/src/devtools/use-workbench-devtools-snapshot.ts +84 -84
  19. package/src/devtools/workbench-devtools-snapshot.ts +140 -140
  20. package/src/devtools/workbench-devtools.css +82 -82
  21. package/src/{editor-area-dnd.ts → editor/area-dnd.ts} +69 -69
  22. package/src/{editor-area-model.ts → editor/area-model.ts} +71 -71
  23. package/src/{editor-area.css → editor/area.css} +454 -454
  24. package/src/{editor-area.tsx → editor/area.tsx} +676 -676
  25. package/src/{editor-host-surface.tsx → editor/host-surface.tsx} +631 -634
  26. package/src/{editor-pane-visibility.ts → editor/pane-visibility.ts} +130 -130
  27. package/src/{editor-resource.ts → editor/resource.ts} +36 -36
  28. package/src/{editor-state-storage.ts → editor/state-storage.ts} +182 -193
  29. package/src/{editor-tab-context-menu.ts → editor/tab-context-menu.ts} +118 -118
  30. package/src/{use-editor.ts → editor/use-editor.ts} +114 -107
  31. package/src/{editor-view-providers.tsx → editor/view-providers.tsx} +552 -552
  32. package/src/{editor-workspace-file-availability.ts → editor/workspace-file-availability.ts} +15 -15
  33. package/src/{editor-workspace-reconcile.tsx → editor/workspace-reconcile.tsx} +31 -28
  34. package/src/{explorer-context-menu.ts → explorer/context-menu.ts} +114 -114
  35. package/src/{createCommandWorkspaceExplorerPort.ts → explorer/create-command-workspace-explorer-port.ts} +86 -86
  36. package/src/{explorer-reveal.ts → explorer/reveal.ts} +112 -112
  37. package/src/{search-view-data.ts → explorer/search-view-data.ts} +15 -15
  38. package/src/{search-view.tsx → explorer/search-view.tsx} +65 -62
  39. package/src/{use-active-workspace-path.ts → explorer/use-active-workspace-path.ts} +15 -15
  40. package/src/{explorer-view-data.ts → explorer/view-data.ts} +58 -58
  41. package/src/{explorer-view.tsx → explorer/view.tsx} +227 -224
  42. package/src/{extension-context-menu.ts → extensions/context-menu.ts} +52 -52
  43. package/src/{extension-management-model.ts → extensions/management-model.ts} +313 -313
  44. package/src/{use-extension-management.ts → extensions/use-extension-management.ts} +241 -193
  45. package/src/{extensions-view-data.ts → extensions/view-data.ts} +19 -19
  46. package/src/{extensions-view.tsx → extensions/view.tsx} +63 -38
  47. package/src/{field-remap-demo.tsx → field-remap/demo.tsx} +18 -18
  48. package/src/{field-remap-editor-surface.tsx → field-remap/editor-surface.tsx} +36 -36
  49. package/src/{field-remap-flow-adapter.ts → field-remap/flow-adapter.ts} +240 -240
  50. package/src/{field-remap-flow.tsx → field-remap/flow.tsx} +369 -369
  51. package/src/{field-remap-graph.tsx → field-remap/graph.tsx} +559 -559
  52. package/src/field-remap/jsonata-transform.ts +166 -0
  53. package/src/{field-remap-panel.tsx → field-remap/panel.tsx} +193 -175
  54. package/src/{field-remap-samples.ts → field-remap/samples.ts} +352 -352
  55. package/src/{table-mapping-adapter.ts → field-remap/table-mapping-adapter.ts} +59 -59
  56. package/src/{field-remap-tree.tsx → field-remap/tree.tsx} +404 -404
  57. package/src/{field-remap-view-data.ts → field-remap/view-data.ts} +16 -16
  58. package/src/{field-remap-view.css → field-remap/view.css} +676 -676
  59. package/src/{field-remap-view.tsx → field-remap/view.tsx} +86 -86
  60. package/src/index.ts +212 -199
  61. package/src/{json-form-source-patch.ts → jdw/json-form-source-patch.ts} +323 -323
  62. package/src/{jdw-lab-view-data.ts → jdw/lab-view-data.ts} +25 -25
  63. package/src/{jdw-lab-view.css → jdw/lab-view.css} +21 -21
  64. package/src/{jdw-lab-view.tsx → jdw/lab-view.tsx} +79 -79
  65. package/src/{jdw-widget-form-view.tsx → jdw/widget-form-view.tsx} +68 -65
  66. package/src/{jdw-widget-preview-view.tsx → jdw/widget-preview-view.tsx} +54 -51
  67. package/src/{keybinding-overrides-storage.ts → management/keybinding-overrides-storage.ts} +49 -57
  68. package/src/{keybinding-management-settings.tsx → management/keybinding-settings.tsx} +16 -16
  69. package/src/{management-palette-commands.ts → management/palette-commands.ts} +38 -38
  70. package/src/{preference-settings-storage.ts → management/preference-settings-storage.ts} +50 -58
  71. package/src/{management-settings-ids.ts → management/settings-ids.ts} +12 -12
  72. package/src/{management-settings.tsx → management/settings.tsx} +96 -75
  73. package/src/{use-command-management.ts → management/use-command-management.ts} +191 -191
  74. package/src/{use-keybinding-management.ts → management/use-keybinding-management.ts} +130 -130
  75. package/src/{shell-model.tsx → shell/model.tsx} +149 -149
  76. package/src/{provider.tsx → shell/provider.tsx} +603 -573
  77. package/src/{shell-secondary-actions.tsx → shell/secondary-actions.tsx} +59 -59
  78. package/src/{shell-settings-constants.ts → shell/settings-constants.ts} +9 -9
  79. package/src/{shell-settings.tsx → shell/settings.tsx} +599 -599
  80. package/src/{shell.tsx → shell/shell.tsx} +680 -649
  81. package/src/{shell-titlebar-layout-controls.tsx → shell/titlebar-layout-controls.tsx} +4 -4
  82. package/src/{shell-view-host.tsx → shell/view-host.tsx} +212 -199
  83. package/src/{workbench-appearance-storage.ts → workbench/appearance-storage.ts} +107 -115
  84. package/src/{workbench-command-host.tsx → workbench/command-host.tsx} +243 -243
  85. package/src/{workbench-command-palette.ts → workbench/command-palette.ts} +208 -208
  86. package/src/{workbench-keybinding-bridge.ts → workbench/keybinding-bridge.ts} +54 -54
  87. package/src/{workbench-layout-storage.ts → workbench/layout-storage.ts} +134 -145
  88. package/src/{workbench-profile-modal.tsx → workbench/profile-modal.tsx} +118 -118
  89. package/src/{workbench-shell-command-registration.ts → workbench/shell-command-registration.ts} +58 -58
  90. package/src/{workbench-startup-gate.tsx → workbench/startup-gate.tsx} +136 -136
  91. package/src/{workbench-status-sections.ts → workbench/status-sections.ts} +43 -43
  92. package/src/{use-persisted-workbench-appearance.ts → workbench/use-persisted-appearance.ts} +33 -33
  93. package/src/{workbench-user-commands.ts → workbench/user-commands.ts} +46 -46
  94. package/src/{workspace-view-state.ts → workbench/workspace-view-state.ts} +35 -35
  95. package/src/jsonata-transform.ts +0 -36
@@ -1,193 +1,182 @@
1
- import type {
2
- EditorGroupState,
3
- EditorLayoutDirection,
4
- EditorLayoutNode,
5
- EditorState,
6
- EditorTabState,
7
- WorkbenchStorageReader,
8
- WorkbenchStorageWriter,
9
- } from '@workbench-kit/workbench-core';
10
-
11
- export const DEFAULT_WORKBENCH_EDITOR_STATE_STORAGE_KEY = 'workbench-kit/.workbench/editors';
12
-
13
- export function isWorkbenchEditorStatePersistenceAvailable(): boolean {
14
- try {
15
- return typeof globalThis.localStorage !== 'undefined';
16
- } catch {
17
- return false;
18
- }
19
- }
20
-
21
- export function editorStateToStorageValue(state: EditorState): EditorState {
22
- return {
23
- activeGroupId: state.activeGroupId,
24
- groups: state.groups.map((group) => ({
25
- activeTabId: group.activeTabId,
26
- id: group.id,
27
- tabs: group.tabs.map((tab) => ({
28
- dirty: false,
29
- editorId: tab.editorId,
30
- icon: tab.icon,
31
- id: tab.id,
32
- pinned: tab.pinned,
33
- preview: tab.preview,
34
- resourceUri: tab.resourceUri,
35
- title: tab.title,
36
- })),
37
- })),
38
- layout: cloneEditorLayoutForStorage(state.layout),
39
- };
40
- }
41
-
42
- export function readPersistedEditorState(
43
- storageKey = DEFAULT_WORKBENCH_EDITOR_STATE_STORAGE_KEY,
44
- storage?: WorkbenchStorageReader,
45
- ): EditorState | undefined {
46
- const resolvedStorage = storage ?? getBrowserLocalStorage();
47
- if (!resolvedStorage) return undefined;
48
-
49
- try {
50
- const raw = resolvedStorage.getItem(storageKey);
51
- if (!raw) return undefined;
52
-
53
- return parseEditorStateStorageValue(JSON.parse(raw) as unknown);
54
- } catch {
55
- return undefined;
56
- }
57
- }
58
-
59
- export function writePersistedEditorState(
60
- state: EditorState,
61
- storageKey = DEFAULT_WORKBENCH_EDITOR_STATE_STORAGE_KEY,
62
- storage?: WorkbenchStorageWriter,
63
- ): void {
64
- const resolvedStorage = storage ?? getBrowserLocalStorage();
65
- if (!resolvedStorage) return;
66
-
67
- try {
68
- resolvedStorage.setItem(storageKey, JSON.stringify(editorStateToStorageValue(state), null, 2));
69
- } catch {
70
- // Ignore quota and security errors so the shell keeps working offline.
71
- }
72
- }
73
-
74
- function parseEditorStateStorageValue(value: unknown): EditorState | undefined {
75
- if (!isRecord(value)) {
76
- return undefined;
77
- }
78
-
79
- const groups = Array.isArray(value.groups)
80
- ? value.groups.flatMap(parseEditorGroupStorageValue)
81
- : [];
82
- const layout = parseEditorLayoutStorageValue(value.layout);
83
- if (groups.length === 0 || !layout) {
84
- return undefined;
85
- }
86
-
87
- return {
88
- activeGroupId: typeof value.activeGroupId === 'string' ? value.activeGroupId : undefined,
89
- groups,
90
- layout,
91
- };
92
- }
93
-
94
- function parseEditorGroupStorageValue(value: unknown): EditorGroupState[] {
95
- if (!isRecord(value) || typeof value.id !== 'string' || !Array.isArray(value.tabs)) {
96
- return [];
97
- }
98
-
99
- return [
100
- {
101
- activeTabId: typeof value.activeTabId === 'string' ? value.activeTabId : undefined,
102
- id: value.id,
103
- tabs: value.tabs.flatMap(parseEditorTabStorageValue),
104
- },
105
- ];
106
- }
107
-
108
- function parseEditorTabStorageValue(value: unknown): EditorTabState[] {
109
- if (
110
- !isRecord(value) ||
111
- typeof value.id !== 'string' ||
112
- typeof value.editorId !== 'string' ||
113
- typeof value.resourceUri !== 'string'
114
- ) {
115
- return [];
116
- }
117
-
118
- return [
119
- {
120
- dirty: false,
121
- editorId: value.editorId,
122
- icon: typeof value.icon === 'string' ? value.icon : undefined,
123
- id: value.id,
124
- pinned: typeof value.pinned === 'boolean' ? value.pinned : true,
125
- preview: typeof value.preview === 'boolean' ? value.preview : false,
126
- resourceUri: value.resourceUri,
127
- title: typeof value.title === 'string' ? value.title : undefined,
128
- },
129
- ];
130
- }
131
-
132
- function parseEditorLayoutStorageValue(value: unknown): EditorLayoutNode | undefined {
133
- if (!isRecord(value) || typeof value.type !== 'string') {
134
- return undefined;
135
- }
136
-
137
- if (value.type === 'group') {
138
- return typeof value.groupId === 'string'
139
- ? {
140
- groupId: value.groupId,
141
- type: 'group',
142
- }
143
- : undefined;
144
- }
145
-
146
- if (value.type !== 'split' || !Array.isArray(value.children)) {
147
- return undefined;
148
- }
149
-
150
- const direction = parseEditorLayoutDirection(value.direction);
151
- const children = value.children
152
- .map(parseEditorLayoutStorageValue)
153
- .filter((child): child is EditorLayoutNode => child !== undefined);
154
- if (!direction || children.length === 0) {
155
- return undefined;
156
- }
157
-
158
- return {
159
- children,
160
- direction,
161
- ...(typeof value.primarySizePercent === 'number' && Number.isFinite(value.primarySizePercent)
162
- ? { primarySizePercent: value.primarySizePercent }
163
- : {}),
164
- type: 'split',
165
- };
166
- }
167
-
168
- function parseEditorLayoutDirection(value: unknown): EditorLayoutDirection | undefined {
169
- return value === 'horizontal' || value === 'vertical' ? value : undefined;
170
- }
171
-
172
- function cloneEditorLayoutForStorage(layout: EditorLayoutNode): EditorLayoutNode {
173
- if (layout.type === 'group') {
174
- return { ...layout };
175
- }
176
-
177
- return {
178
- ...layout,
179
- children: layout.children.map(cloneEditorLayoutForStorage),
180
- };
181
- }
182
-
183
- function isRecord(value: unknown): value is Record<string, unknown> {
184
- return typeof value === 'object' && value !== null;
185
- }
186
-
187
- function getBrowserLocalStorage(): (WorkbenchStorageReader & WorkbenchStorageWriter) | undefined {
188
- if (!isWorkbenchEditorStatePersistenceAvailable()) {
189
- return undefined;
190
- }
191
-
192
- return globalThis.localStorage;
193
- }
1
+ import {
2
+ createBrowserWorkbenchStorage,
3
+ type EditorGroupState,
4
+ type EditorLayoutDirection,
5
+ type EditorLayoutNode,
6
+ type EditorState,
7
+ type EditorTabState,
8
+ type WorkbenchStorageReader,
9
+ type WorkbenchStorageWriter,
10
+ } from '@workbench-kit/workbench-core';
11
+
12
+ export const DEFAULT_WORKBENCH_EDITOR_STATE_STORAGE_KEY = 'workbench-kit/.workbench/editors';
13
+
14
+ export function isWorkbenchEditorStatePersistenceAvailable(): boolean {
15
+ return createBrowserWorkbenchStorage({ kind: 'local' }) !== undefined;
16
+ }
17
+
18
+ export function editorStateToStorageValue(state: EditorState): EditorState {
19
+ return {
20
+ activeGroupId: state.activeGroupId,
21
+ groups: state.groups.map((group) => ({
22
+ activeTabId: group.activeTabId,
23
+ id: group.id,
24
+ tabs: group.tabs.map((tab) => ({
25
+ dirty: false,
26
+ editorId: tab.editorId,
27
+ icon: tab.icon,
28
+ id: tab.id,
29
+ pinned: tab.pinned,
30
+ preview: tab.preview,
31
+ resourceUri: tab.resourceUri,
32
+ title: tab.title,
33
+ })),
34
+ })),
35
+ layout: cloneEditorLayoutForStorage(state.layout),
36
+ };
37
+ }
38
+
39
+ export function readPersistedEditorState(
40
+ storageKey = DEFAULT_WORKBENCH_EDITOR_STATE_STORAGE_KEY,
41
+ storage?: WorkbenchStorageReader,
42
+ ): EditorState | undefined {
43
+ const resolvedStorage = storage ?? createBrowserWorkbenchStorage({ kind: 'local' });
44
+ if (!resolvedStorage) return undefined;
45
+
46
+ try {
47
+ const raw = resolvedStorage.getItem(storageKey);
48
+ if (!raw) return undefined;
49
+
50
+ return parseEditorStateStorageValue(JSON.parse(raw) as unknown);
51
+ } catch {
52
+ return undefined;
53
+ }
54
+ }
55
+
56
+ export function writePersistedEditorState(
57
+ state: EditorState,
58
+ storageKey = DEFAULT_WORKBENCH_EDITOR_STATE_STORAGE_KEY,
59
+ storage?: WorkbenchStorageWriter,
60
+ ): void {
61
+ const resolvedStorage = storage ?? createBrowserWorkbenchStorage({ kind: 'local' });
62
+ if (!resolvedStorage) return;
63
+
64
+ try {
65
+ resolvedStorage.setItem(storageKey, JSON.stringify(editorStateToStorageValue(state), null, 2));
66
+ } catch {
67
+ // Ignore quota and security errors so the shell keeps working offline.
68
+ }
69
+ }
70
+
71
+ function parseEditorStateStorageValue(value: unknown): EditorState | undefined {
72
+ if (!isRecord(value)) {
73
+ return undefined;
74
+ }
75
+
76
+ const groups = Array.isArray(value.groups)
77
+ ? value.groups.flatMap(parseEditorGroupStorageValue)
78
+ : [];
79
+ const layout = parseEditorLayoutStorageValue(value.layout);
80
+ if (groups.length === 0 || !layout) {
81
+ return undefined;
82
+ }
83
+
84
+ return {
85
+ activeGroupId: typeof value.activeGroupId === 'string' ? value.activeGroupId : undefined,
86
+ groups,
87
+ layout,
88
+ };
89
+ }
90
+
91
+ function parseEditorGroupStorageValue(value: unknown): EditorGroupState[] {
92
+ if (!isRecord(value) || typeof value.id !== 'string' || !Array.isArray(value.tabs)) {
93
+ return [];
94
+ }
95
+
96
+ return [
97
+ {
98
+ activeTabId: typeof value.activeTabId === 'string' ? value.activeTabId : undefined,
99
+ id: value.id,
100
+ tabs: value.tabs.flatMap(parseEditorTabStorageValue),
101
+ },
102
+ ];
103
+ }
104
+
105
+ function parseEditorTabStorageValue(value: unknown): EditorTabState[] {
106
+ if (
107
+ !isRecord(value) ||
108
+ typeof value.id !== 'string' ||
109
+ typeof value.editorId !== 'string' ||
110
+ typeof value.resourceUri !== 'string'
111
+ ) {
112
+ return [];
113
+ }
114
+
115
+ return [
116
+ {
117
+ dirty: false,
118
+ editorId: value.editorId,
119
+ icon: typeof value.icon === 'string' ? value.icon : undefined,
120
+ id: value.id,
121
+ pinned: typeof value.pinned === 'boolean' ? value.pinned : true,
122
+ preview: typeof value.preview === 'boolean' ? value.preview : false,
123
+ resourceUri: value.resourceUri,
124
+ title: typeof value.title === 'string' ? value.title : undefined,
125
+ },
126
+ ];
127
+ }
128
+
129
+ function parseEditorLayoutStorageValue(value: unknown): EditorLayoutNode | undefined {
130
+ if (!isRecord(value) || typeof value.type !== 'string') {
131
+ return undefined;
132
+ }
133
+
134
+ if (value.type === 'group') {
135
+ return typeof value.groupId === 'string'
136
+ ? {
137
+ groupId: value.groupId,
138
+ type: 'group',
139
+ }
140
+ : undefined;
141
+ }
142
+
143
+ if (value.type !== 'split' || !Array.isArray(value.children)) {
144
+ return undefined;
145
+ }
146
+
147
+ const direction = parseEditorLayoutDirection(value.direction);
148
+ const children = value.children
149
+ .map(parseEditorLayoutStorageValue)
150
+ .filter((child): child is EditorLayoutNode => child !== undefined);
151
+ if (!direction || children.length === 0) {
152
+ return undefined;
153
+ }
154
+
155
+ return {
156
+ children,
157
+ direction,
158
+ ...(typeof value.primarySizePercent === 'number' && Number.isFinite(value.primarySizePercent)
159
+ ? { primarySizePercent: value.primarySizePercent }
160
+ : {}),
161
+ type: 'split',
162
+ };
163
+ }
164
+
165
+ function parseEditorLayoutDirection(value: unknown): EditorLayoutDirection | undefined {
166
+ return value === 'horizontal' || value === 'vertical' ? value : undefined;
167
+ }
168
+
169
+ function cloneEditorLayoutForStorage(layout: EditorLayoutNode): EditorLayoutNode {
170
+ if (layout.type === 'group') {
171
+ return { ...layout };
172
+ }
173
+
174
+ return {
175
+ ...layout,
176
+ children: layout.children.map(cloneEditorLayoutForStorage),
177
+ };
178
+ }
179
+
180
+ function isRecord(value: unknown): value is Record<string, unknown> {
181
+ return typeof value === 'object' && value !== null;
182
+ }
@@ -1,118 +1,118 @@
1
- import {
2
- createCommandRegistry,
3
- executeCommand as executeRegisteredCommand,
4
- resolveCommandMenuItems,
5
- } from '@workbench-kit/platform';
6
- import type { ContextMenuItem } from '@workbench-kit/react/overlay';
7
- import {
8
- WORKBENCH_COMMAND_SURFACE_EDITOR,
9
- WORKBENCH_EDITOR_DELETE_COMMAND_ID,
10
- commandMenuItemsToContextMenuItems,
11
- createWorkbenchEditorCommands,
12
- createWorkbenchEditorTabMenuEntries,
13
- type WorkbenchEditorCommandContext,
14
- } from '@workbench-kit/react/workbench/commands';
15
- import type {
16
- EditorService,
17
- EditorTabState,
18
- ExtensionRegistry,
19
- } from '@workbench-kit/workbench-core';
20
-
21
- import { copyResourcePath, pathForResource } from './editor-resource.js';
22
- import {
23
- appendExtensionContextMenuItems,
24
- createExtensionContextMenuItems,
25
- } from './extension-context-menu.js';
26
-
27
- const editorCommandRegistry = createCommandRegistry(createWorkbenchEditorCommands());
28
- const editorTabMenuEntries = createWorkbenchEditorTabMenuEntries().filter((entry) =>
29
- entry.type === 'separator'
30
- ? entry.id !== 'tab-danger-separator'
31
- : entry.commandId !== WORKBENCH_EDITOR_DELETE_COMMAND_ID,
32
- );
33
- const EDITOR_TAB_CONTEXT_MENU = 'editor/tab/context';
34
- const EDITOR_TAB_EXTENSION_MENU_SEPARATOR_ID = 'editor-tab-extension-separator';
35
-
36
- export function createEditorTabContextMenuItems({
37
- editorService,
38
- executeExtensionCommand,
39
- extensionRegistry,
40
- groupId,
41
- tab,
42
- tabs,
43
- }: {
44
- editorService: EditorService;
45
- executeExtensionCommand?: ((commandId: string) => unknown) | undefined;
46
- extensionRegistry?: ExtensionRegistry | undefined;
47
- groupId: string;
48
- tab: EditorTabState;
49
- tabs: readonly EditorTabState[];
50
- }): ContextMenuItem[] {
51
- const closeableTabs = tabs.filter((candidate) => candidate.id !== tab.id);
52
- const context: WorkbenchEditorCommandContext = {
53
- canCloseAll: tabs.length > 0,
54
- canCloseOthers: closeableTabs.length > 0,
55
- canClosePath: true,
56
- canCopyPath: true,
57
- canDeletePath: false,
58
- canDiscardFile: false,
59
- canSaveFile: false,
60
- canSplitDown: true,
61
- canSplitRight: true,
62
- canTogglePinned: true,
63
- closeAll: () => tabs.forEach((candidate) => editorService.closeEditor(candidate.id)),
64
- closeOthers: () =>
65
- closeableTabs.forEach((candidate) => editorService.closeEditor(candidate.id)),
66
- closePath: () => editorService.closeEditor(tab.id),
67
- copyPath: () => copyResourcePath(tab.resourceUri),
68
- deletePath: () => undefined,
69
- discardFile: () => undefined,
70
- filePath: pathForResource(tab.resourceUri),
71
- hasMultipleOpenFiles: tabs.length > 1,
72
- hasOpenFiles: tabs.length > 0,
73
- hasUnsavedChanges: tab.dirty,
74
- isPinned: tab.pinned,
75
- saveFile: () => undefined,
76
- splitDown: () =>
77
- editorService.splitEditor({
78
- afterGroupId: groupId,
79
- direction: 'vertical',
80
- tabId: tab.id,
81
- }),
82
- splitRight: () =>
83
- editorService.splitEditor({
84
- afterGroupId: groupId,
85
- direction: 'horizontal',
86
- tabId: tab.id,
87
- }),
88
- togglePinned: () => editorService.togglePinnedEditor(tab.id),
89
- };
90
-
91
- const contextKeys = {
92
- 'editor.hasResource': Boolean(tab.resourceUri),
93
- 'editor.isDirty': tab.dirty,
94
- 'editor.isPinned': tab.pinned,
95
- };
96
-
97
- const baseItems = commandMenuItemsToContextMenuItems(
98
- resolveCommandMenuItems({
99
- context,
100
- contextKeys,
101
- entries: editorTabMenuEntries,
102
- registry: editorCommandRegistry,
103
- surface: WORKBENCH_COMMAND_SURFACE_EDITOR,
104
- }),
105
- (commandId) => executeRegisteredCommand(editorCommandRegistry, commandId, context, contextKeys),
106
- );
107
-
108
- return appendExtensionContextMenuItems(
109
- baseItems,
110
- createExtensionContextMenuItems({
111
- contextKeys,
112
- executeCommand: executeExtensionCommand,
113
- extensionRegistry,
114
- menu: EDITOR_TAB_CONTEXT_MENU,
115
- }),
116
- EDITOR_TAB_EXTENSION_MENU_SEPARATOR_ID,
117
- );
118
- }
1
+ import {
2
+ createCommandRegistry,
3
+ executeCommand as executeRegisteredCommand,
4
+ resolveCommandMenuItems,
5
+ } from '@workbench-kit/platform';
6
+ import type { ContextMenuItem } from '@workbench-kit/react/overlay';
7
+ import {
8
+ WORKBENCH_COMMAND_SURFACE_EDITOR,
9
+ WORKBENCH_EDITOR_DELETE_COMMAND_ID,
10
+ commandMenuItemsToContextMenuItems,
11
+ createWorkbenchEditorCommands,
12
+ createWorkbenchEditorTabMenuEntries,
13
+ type WorkbenchEditorCommandContext,
14
+ } from '@workbench-kit/react/workbench/commands';
15
+ import type {
16
+ EditorService,
17
+ EditorTabState,
18
+ ExtensionRegistry,
19
+ } from '@workbench-kit/workbench-core';
20
+
21
+ import { copyResourcePath, pathForResource } from './resource.js';
22
+ import {
23
+ appendExtensionContextMenuItems,
24
+ createExtensionContextMenuItems,
25
+ } from '../extensions/context-menu.js';
26
+
27
+ const editorCommandRegistry = createCommandRegistry(createWorkbenchEditorCommands());
28
+ const editorTabMenuEntries = createWorkbenchEditorTabMenuEntries().filter((entry) =>
29
+ entry.type === 'separator'
30
+ ? entry.id !== 'tab-danger-separator'
31
+ : entry.commandId !== WORKBENCH_EDITOR_DELETE_COMMAND_ID,
32
+ );
33
+ const EDITOR_TAB_CONTEXT_MENU = 'editor/tab/context';
34
+ const EDITOR_TAB_EXTENSION_MENU_SEPARATOR_ID = 'editor-tab-extension-separator';
35
+
36
+ export function createEditorTabContextMenuItems({
37
+ editorService,
38
+ executeExtensionCommand,
39
+ extensionRegistry,
40
+ groupId,
41
+ tab,
42
+ tabs,
43
+ }: {
44
+ editorService: EditorService;
45
+ executeExtensionCommand?: ((commandId: string) => unknown) | undefined;
46
+ extensionRegistry?: ExtensionRegistry | undefined;
47
+ groupId: string;
48
+ tab: EditorTabState;
49
+ tabs: readonly EditorTabState[];
50
+ }): ContextMenuItem[] {
51
+ const closeableTabs = tabs.filter((candidate) => candidate.id !== tab.id);
52
+ const context: WorkbenchEditorCommandContext = {
53
+ canCloseAll: tabs.length > 0,
54
+ canCloseOthers: closeableTabs.length > 0,
55
+ canClosePath: true,
56
+ canCopyPath: true,
57
+ canDeletePath: false,
58
+ canDiscardFile: false,
59
+ canSaveFile: false,
60
+ canSplitDown: true,
61
+ canSplitRight: true,
62
+ canTogglePinned: true,
63
+ closeAll: () => tabs.forEach((candidate) => editorService.closeEditor(candidate.id)),
64
+ closeOthers: () =>
65
+ closeableTabs.forEach((candidate) => editorService.closeEditor(candidate.id)),
66
+ closePath: () => editorService.closeEditor(tab.id),
67
+ copyPath: () => copyResourcePath(tab.resourceUri),
68
+ deletePath: () => undefined,
69
+ discardFile: () => undefined,
70
+ filePath: pathForResource(tab.resourceUri),
71
+ hasMultipleOpenFiles: tabs.length > 1,
72
+ hasOpenFiles: tabs.length > 0,
73
+ hasUnsavedChanges: tab.dirty,
74
+ isPinned: tab.pinned,
75
+ saveFile: () => undefined,
76
+ splitDown: () =>
77
+ editorService.splitEditor({
78
+ afterGroupId: groupId,
79
+ direction: 'vertical',
80
+ tabId: tab.id,
81
+ }),
82
+ splitRight: () =>
83
+ editorService.splitEditor({
84
+ afterGroupId: groupId,
85
+ direction: 'horizontal',
86
+ tabId: tab.id,
87
+ }),
88
+ togglePinned: () => editorService.togglePinnedEditor(tab.id),
89
+ };
90
+
91
+ const contextKeys = {
92
+ 'editor.hasResource': Boolean(tab.resourceUri),
93
+ 'editor.isDirty': tab.dirty,
94
+ 'editor.isPinned': tab.pinned,
95
+ };
96
+
97
+ const baseItems = commandMenuItemsToContextMenuItems(
98
+ resolveCommandMenuItems({
99
+ context,
100
+ contextKeys,
101
+ entries: editorTabMenuEntries,
102
+ registry: editorCommandRegistry,
103
+ surface: WORKBENCH_COMMAND_SURFACE_EDITOR,
104
+ }),
105
+ (commandId) => executeRegisteredCommand(editorCommandRegistry, commandId, context, contextKeys),
106
+ );
107
+
108
+ return appendExtensionContextMenuItems(
109
+ baseItems,
110
+ createExtensionContextMenuItems({
111
+ contextKeys,
112
+ executeCommand: executeExtensionCommand,
113
+ extensionRegistry,
114
+ menu: EDITOR_TAB_CONTEXT_MENU,
115
+ }),
116
+ EDITOR_TAB_EXTENSION_MENU_SEPARATOR_ID,
117
+ );
118
+ }