@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.
- package/README.md +98 -0
- package/package.json +51 -0
- package/src/chat/ai-mock-proposals.ts +39 -0
- package/src/chat/command-input.ts +52 -0
- package/src/chat/command-policy.ts +54 -0
- package/src/chat/command-surface.tsx +155 -0
- package/src/chat/use-chat-command-proposals.ts +194 -0
- package/src/chat/view-data.ts +20 -0
- package/src/chat/view.tsx +220 -0
- package/src/commands/inspector-surface.tsx +46 -0
- package/src/commands/use-command-descriptors.ts +41 -0
- package/src/commands/use-context-key-revision.ts +18 -0
- package/src/commands/view-data.ts +17 -0
- package/src/commands/view.tsx +43 -0
- package/src/devtools/WorkbenchDevtoolsPanel.tsx +124 -0
- package/src/devtools/WorkbenchDevtoolsShell.tsx +17 -0
- package/src/devtools/index.ts +11 -0
- package/src/devtools/use-workbench-devtools-snapshot.ts +84 -0
- package/src/devtools/workbench-devtools-snapshot.ts +140 -0
- package/src/devtools/workbench-devtools.css +82 -0
- package/src/editor/area-dnd.ts +69 -0
- package/src/editor/area-model.ts +71 -0
- package/src/editor/area.css +454 -0
- package/src/editor/area.tsx +676 -0
- package/src/editor/host-surface.tsx +691 -0
- package/src/editor/markdown-document-view-data.ts +16 -0
- package/src/editor/pane-visibility.ts +130 -0
- package/src/editor/resource.ts +36 -0
- package/src/editor/state-storage.ts +182 -0
- package/src/editor/tab-context-menu.ts +118 -0
- package/src/editor/use-editor.ts +138 -0
- package/src/editor/view-providers.tsx +504 -0
- package/src/editor/workspace-file-availability.ts +15 -0
- package/src/editor/workspace-reconcile.tsx +31 -0
- package/src/explorer/context-menu.ts +114 -0
- package/src/explorer/create-command-workspace-explorer-port.ts +86 -0
- package/src/explorer/reveal.ts +112 -0
- package/src/explorer/search-view-data.ts +15 -0
- package/src/explorer/search-view.tsx +65 -0
- package/src/explorer/use-active-workspace-path.ts +15 -0
- package/src/explorer/view-data.ts +58 -0
- package/src/explorer/view.tsx +227 -0
- package/src/extensions/context-menu.ts +52 -0
- package/src/extensions/management-model.ts +313 -0
- package/src/extensions/use-extension-management.ts +241 -0
- package/src/extensions/view-data.ts +19 -0
- package/src/extensions/view.tsx +63 -0
- package/src/field-remap/chrome-labels.ts +74 -0
- package/src/field-remap/convert-note-editor.tsx +206 -0
- package/src/field-remap/convert-palette.tsx +126 -0
- package/src/field-remap/demo.tsx +105 -0
- package/src/field-remap/detail-panel.tsx +659 -0
- package/src/field-remap/editor-surface.tsx +36 -0
- package/src/field-remap/flow-adapter.ts +838 -0
- package/src/field-remap/flow-ops.ts +442 -0
- package/src/field-remap/flow.tsx +948 -0
- package/src/field-remap/graph.tsx +559 -0
- package/src/field-remap/index.ts +88 -0
- package/src/field-remap/io-class-browse.tsx +145 -0
- package/src/field-remap/jsonata-transform.ts +166 -0
- package/src/field-remap/panel.tsx +466 -0
- package/src/field-remap/samples.ts +507 -0
- package/src/field-remap/shape-io-editor.tsx +170 -0
- package/src/field-remap/table-mapping-adapter.ts +59 -0
- package/src/field-remap/transform-options-editor.tsx +312 -0
- package/src/field-remap/tree.tsx +404 -0
- package/src/field-remap/view-data.ts +16 -0
- package/src/field-remap/view.css +1367 -0
- package/src/field-remap/view.tsx +86 -0
- package/src/index.ts +294 -0
- package/src/jdw/document-view-data.ts +31 -0
- package/src/jdw/json-form-source-patch.ts +323 -0
- package/src/jdw/lab-view-data.ts +25 -0
- package/src/jdw/lab-view.css +21 -0
- package/src/jdw/lab-view.tsx +79 -0
- package/src/jdw/widget-form-view.tsx +68 -0
- package/src/jdw/widget-preview-view.tsx +54 -0
- package/src/management/keybinding-overrides-storage.ts +49 -0
- package/src/management/keybinding-settings.tsx +16 -0
- package/src/management/palette-commands.ts +38 -0
- package/src/management/preference-settings-storage.ts +50 -0
- package/src/management/settings-ids.ts +12 -0
- package/src/management/settings.tsx +96 -0
- package/src/management/use-command-management.ts +191 -0
- package/src/management/use-keybinding-management.ts +130 -0
- package/src/shell/model.tsx +149 -0
- package/src/shell/provider.tsx +606 -0
- package/src/shell/secondary-actions.tsx +59 -0
- package/src/shell/settings-constants.ts +9 -0
- package/src/shell/settings.tsx +599 -0
- package/src/shell/shell.tsx +680 -0
- package/src/shell/titlebar-layout-controls.tsx +4 -0
- package/src/shell/view-host.tsx +212 -0
- package/src/workbench/appearance-storage.ts +107 -0
- package/src/workbench/command-host.tsx +243 -0
- package/src/workbench/command-palette.ts +208 -0
- package/src/workbench/keybinding-bridge.ts +54 -0
- package/src/workbench/layout-storage.ts +134 -0
- package/src/workbench/profile-modal.tsx +118 -0
- package/src/workbench/shell-command-registration.ts +58 -0
- package/src/workbench/startup-gate.tsx +136 -0
- package/src/workbench/status-sections.ts +43 -0
- package/src/workbench/use-persisted-appearance.ts +33 -0
- package/src/workbench/user-commands.ts +46 -0
- package/src/workbench/workspace-view-state.ts +35 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { isValidElement, useEffect, useMemo, useRef, type FocusEvent, type ReactNode } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
ExtensionCatalogTrustPolicy,
|
|
4
|
+
ExtensionRegistry,
|
|
5
|
+
ViewHost,
|
|
6
|
+
ViewHostFactoryRegistry,
|
|
7
|
+
ViewProvider,
|
|
8
|
+
} from '@workbench-kit/workbench-core';
|
|
9
|
+
|
|
10
|
+
import { BuiltinChatView } from '../chat/view.js';
|
|
11
|
+
import { isBuiltinChatViewRenderData } from '../chat/view-data.js';
|
|
12
|
+
import { BuiltinCommandsView } from '../commands/view.js';
|
|
13
|
+
import { isBuiltinCommandsViewRenderData } from '../commands/view-data.js';
|
|
14
|
+
import { BuiltinExplorerView } from '../explorer/view.js';
|
|
15
|
+
import { isBuiltinExplorerViewRenderData } from '../explorer/view-data.js';
|
|
16
|
+
import { BuiltinExtensionsView } from '../extensions/view.js';
|
|
17
|
+
import { isBuiltinExtensionsViewRenderData } from '../extensions/view-data.js';
|
|
18
|
+
import { SampleJdwLabView } from '../jdw/lab-view.js';
|
|
19
|
+
import { isSampleJdwLabViewRenderData } from '../jdw/lab-view-data.js';
|
|
20
|
+
import { SampleFieldRemapView } from '../field-remap/view.js';
|
|
21
|
+
import { isSampleFieldRemapViewRenderData } from '../field-remap/view-data.js';
|
|
22
|
+
import { BuiltinSearchView } from '../explorer/search-view.js';
|
|
23
|
+
import { isBuiltinSearchViewRenderData } from '../explorer/search-view-data.js';
|
|
24
|
+
|
|
25
|
+
export function renderDefaultPrimarySidebar(
|
|
26
|
+
extensionRegistry: Pick<ExtensionRegistry, 'viewHostFactories' | 'views'>,
|
|
27
|
+
activeViewContainerId: string | undefined,
|
|
28
|
+
catalogUrl?: string | undefined,
|
|
29
|
+
catalogTrustPolicy?: ExtensionCatalogTrustPolicy | undefined,
|
|
30
|
+
) {
|
|
31
|
+
const views = activeViewContainerId
|
|
32
|
+
? extensionRegistry.views.getViews(activeViewContainerId)
|
|
33
|
+
: extensionRegistry.views.getViews();
|
|
34
|
+
if (views.length === 0) {
|
|
35
|
+
return <aside aria-label="Primary sidebar" />;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<aside
|
|
40
|
+
aria-label="Primary sidebar"
|
|
41
|
+
className="workbench-primary-side-bar shell-react-primary-sidebar"
|
|
42
|
+
>
|
|
43
|
+
{views.map((view) => (
|
|
44
|
+
<section key={view.id} data-view-id={view.id}>
|
|
45
|
+
<WorkbenchViewHost
|
|
46
|
+
catalogTrustPolicy={catalogTrustPolicy}
|
|
47
|
+
catalogUrl={catalogUrl}
|
|
48
|
+
fallback={view.name}
|
|
49
|
+
provider={extensionRegistry.views.getViewProvider(view.id)}
|
|
50
|
+
viewHostFactories={extensionRegistry.viewHostFactories}
|
|
51
|
+
viewId={view.id}
|
|
52
|
+
/>
|
|
53
|
+
</section>
|
|
54
|
+
))}
|
|
55
|
+
</aside>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function WorkbenchViewHost({
|
|
60
|
+
catalogTrustPolicy,
|
|
61
|
+
catalogUrl,
|
|
62
|
+
fallback,
|
|
63
|
+
provider,
|
|
64
|
+
viewHostFactories,
|
|
65
|
+
viewId,
|
|
66
|
+
}: {
|
|
67
|
+
catalogTrustPolicy?: ExtensionCatalogTrustPolicy | undefined;
|
|
68
|
+
catalogUrl?: string | undefined;
|
|
69
|
+
fallback: ReactNode;
|
|
70
|
+
provider: ViewProvider | undefined;
|
|
71
|
+
viewHostFactories: ViewHostFactoryRegistry;
|
|
72
|
+
viewId: string;
|
|
73
|
+
}) {
|
|
74
|
+
const hostFrameRef = useRef<HTMLDivElement>(null);
|
|
75
|
+
const host = useMemo(() => {
|
|
76
|
+
if (!provider) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return viewHostFactories.createViewHost({ viewId, provider });
|
|
81
|
+
}, [provider, viewHostFactories, viewId]);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!host) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
host.onDidShow?.();
|
|
89
|
+
|
|
90
|
+
const resizeObserver =
|
|
91
|
+
typeof ResizeObserver !== 'undefined' && host.onDidResize
|
|
92
|
+
? new ResizeObserver((entries) => {
|
|
93
|
+
const entry = entries[0];
|
|
94
|
+
if (!entry) return;
|
|
95
|
+
|
|
96
|
+
host.onDidResize?.({
|
|
97
|
+
height: entry.contentRect.height,
|
|
98
|
+
width: entry.contentRect.width,
|
|
99
|
+
});
|
|
100
|
+
})
|
|
101
|
+
: undefined;
|
|
102
|
+
|
|
103
|
+
if (resizeObserver && hostFrameRef.current) {
|
|
104
|
+
resizeObserver.observe(hostFrameRef.current);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return () => {
|
|
108
|
+
resizeObserver?.disconnect();
|
|
109
|
+
host.onDidHide?.();
|
|
110
|
+
host.dispose();
|
|
111
|
+
};
|
|
112
|
+
}, [host]);
|
|
113
|
+
|
|
114
|
+
if (!host) {
|
|
115
|
+
return <>{fallback}</>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<div
|
|
120
|
+
ref={hostFrameRef}
|
|
121
|
+
aria-label={host.title}
|
|
122
|
+
data-view-host-id={host.id ?? provider?.viewId}
|
|
123
|
+
onBlur={(event) => notifyViewHostBlur(host, event)}
|
|
124
|
+
onFocus={(event) => notifyViewHostFocus(host, event)}
|
|
125
|
+
>
|
|
126
|
+
{toWorkbenchViewHostReactNode(host.render(), fallback, { catalogTrustPolicy, catalogUrl })}
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function notifyViewHostFocus(host: ViewHost, event: FocusEvent<HTMLDivElement>): void {
|
|
132
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
133
|
+
host.onDidFocus?.();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function notifyViewHostBlur(host: ViewHost, event: FocusEvent<HTMLDivElement>): void {
|
|
138
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
139
|
+
host.onDidBlur?.();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function toReactNode(value: unknown, fallback: ReactNode): ReactNode {
|
|
144
|
+
if (
|
|
145
|
+
value === undefined ||
|
|
146
|
+
value === null ||
|
|
147
|
+
typeof value === 'boolean' ||
|
|
148
|
+
typeof value === 'symbol' ||
|
|
149
|
+
typeof value === 'function'
|
|
150
|
+
) {
|
|
151
|
+
return fallback;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (typeof value === 'string' || typeof value === 'number' || isValidElement(value)) {
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (Array.isArray(value)) {
|
|
159
|
+
return value as ReactNode;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return fallback;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function toWorkbenchViewHostReactNode(
|
|
166
|
+
value: unknown,
|
|
167
|
+
fallback: ReactNode,
|
|
168
|
+
options: {
|
|
169
|
+
catalogTrustPolicy?: ExtensionCatalogTrustPolicy | undefined;
|
|
170
|
+
catalogUrl?: string | undefined;
|
|
171
|
+
} = {},
|
|
172
|
+
): ReactNode {
|
|
173
|
+
if (isBuiltinExplorerViewRenderData(value)) {
|
|
174
|
+
return <BuiltinExplorerView />;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (isBuiltinChatViewRenderData(value)) {
|
|
178
|
+
return <BuiltinChatView mode={value.mode} />;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (isBuiltinSearchViewRenderData(value)) {
|
|
182
|
+
return <BuiltinSearchView />;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (isBuiltinCommandsViewRenderData(value)) {
|
|
186
|
+
return <BuiltinCommandsView />;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (isBuiltinExtensionsViewRenderData(value)) {
|
|
190
|
+
return (
|
|
191
|
+
<BuiltinExtensionsView
|
|
192
|
+
catalogTrustPolicy={options.catalogTrustPolicy}
|
|
193
|
+
catalogUrl={options.catalogUrl}
|
|
194
|
+
/>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (isSampleJdwLabViewRenderData(value)) {
|
|
199
|
+
return (
|
|
200
|
+
<SampleJdwLabView
|
|
201
|
+
templateJdwPath={value.templateJdwPath}
|
|
202
|
+
widgetTreePath={value.widgetTreePath}
|
|
203
|
+
/>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (isSampleFieldRemapViewRenderData(value)) {
|
|
208
|
+
return <SampleFieldRemapView />;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return toReactNode(value, fallback);
|
|
212
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_DARK_THEME_PRESET,
|
|
3
|
+
DEFAULT_LIGHT_THEME_PRESET,
|
|
4
|
+
DEFAULT_SHELL_PRESET,
|
|
5
|
+
isShellPresetId,
|
|
6
|
+
type WorkbenchAppearanceSettings,
|
|
7
|
+
type WorkbenchColorSchemePreference,
|
|
8
|
+
} from '@workbench-kit/react/workbench';
|
|
9
|
+
import {
|
|
10
|
+
createBrowserWorkbenchStorage,
|
|
11
|
+
type WorkbenchStorageReader,
|
|
12
|
+
type WorkbenchStorageWriter,
|
|
13
|
+
} from '@workbench-kit/workbench-core';
|
|
14
|
+
|
|
15
|
+
export type { WorkbenchAppearanceSettings } from '@workbench-kit/react/workbench/themePresets';
|
|
16
|
+
|
|
17
|
+
export const DEFAULT_WORKBENCH_APPEARANCE_STORAGE_KEY = 'workbench-kit/.workbench/appearance';
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_WORKBENCH_APPEARANCE: WorkbenchAppearanceSettings = {
|
|
20
|
+
darkPreset: DEFAULT_DARK_THEME_PRESET,
|
|
21
|
+
lightPreset: DEFAULT_LIGHT_THEME_PRESET,
|
|
22
|
+
shellPreset: DEFAULT_SHELL_PRESET,
|
|
23
|
+
themePreference: 'system',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function isWorkbenchAppearancePersistenceAvailable(): boolean {
|
|
27
|
+
return createBrowserWorkbenchStorage({ kind: 'local' }) !== undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function readPersistedWorkbenchAppearance(
|
|
31
|
+
storageKey = DEFAULT_WORKBENCH_APPEARANCE_STORAGE_KEY,
|
|
32
|
+
storage?: WorkbenchStorageReader,
|
|
33
|
+
): WorkbenchAppearanceSettings {
|
|
34
|
+
const resolvedStorage = storage ?? createBrowserWorkbenchStorage({ kind: 'local' });
|
|
35
|
+
if (!resolvedStorage) {
|
|
36
|
+
return DEFAULT_WORKBENCH_APPEARANCE;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const raw = resolvedStorage.getItem(storageKey);
|
|
41
|
+
if (!raw) {
|
|
42
|
+
return DEFAULT_WORKBENCH_APPEARANCE;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return normalizeWorkbenchAppearance(JSON.parse(raw) as unknown);
|
|
46
|
+
} catch {
|
|
47
|
+
return DEFAULT_WORKBENCH_APPEARANCE;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function writePersistedWorkbenchAppearance(
|
|
52
|
+
settings: WorkbenchAppearanceSettings,
|
|
53
|
+
storageKey = DEFAULT_WORKBENCH_APPEARANCE_STORAGE_KEY,
|
|
54
|
+
storage?: WorkbenchStorageWriter,
|
|
55
|
+
): void {
|
|
56
|
+
const resolvedStorage = storage ?? createBrowserWorkbenchStorage({ kind: 'local' });
|
|
57
|
+
if (!resolvedStorage) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
resolvedStorage.setItem(storageKey, JSON.stringify(settings, null, 2));
|
|
63
|
+
} catch {
|
|
64
|
+
// Ignore quota and security errors so the shell keeps working offline.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function normalizeWorkbenchAppearance(value: unknown): WorkbenchAppearanceSettings {
|
|
69
|
+
if (typeof value !== 'object' || value === null) {
|
|
70
|
+
return DEFAULT_WORKBENCH_APPEARANCE;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const record = value as Record<string, unknown>;
|
|
74
|
+
const themePreference = normalizeThemePreference(record.themePreference);
|
|
75
|
+
// Preset ids may belong to a contributed theme, which isn't known until extensions
|
|
76
|
+
// register, so we can only validate shape here; the appearance UI falls back to a
|
|
77
|
+
// default option if the persisted id no longer resolves to anything.
|
|
78
|
+
const lightPreset = normalizePresetId(
|
|
79
|
+
record.lightPreset,
|
|
80
|
+
DEFAULT_WORKBENCH_APPEARANCE.lightPreset,
|
|
81
|
+
);
|
|
82
|
+
const darkPreset = normalizePresetId(record.darkPreset, DEFAULT_WORKBENCH_APPEARANCE.darkPreset);
|
|
83
|
+
const shellPreset = normalizeShellPresetId(record.shellPreset);
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
darkPreset,
|
|
87
|
+
lightPreset,
|
|
88
|
+
shellPreset,
|
|
89
|
+
themePreference,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function normalizeShellPresetId(value: unknown): string {
|
|
94
|
+
return typeof value === 'string' && isShellPresetId(value) ? value : DEFAULT_SHELL_PRESET;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function normalizePresetId(value: unknown, fallback: string): string {
|
|
98
|
+
return typeof value === 'string' && value.length > 0 ? value : fallback;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeThemePreference(value: unknown): WorkbenchColorSchemePreference {
|
|
102
|
+
if (value === 'system' || value === 'light' || value === 'dark') {
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return DEFAULT_WORKBENCH_APPEARANCE.themePreference;
|
|
107
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCommandRegistryFromContributions,
|
|
3
|
+
type CommandRegistry,
|
|
4
|
+
} from '@workbench-kit/platform';
|
|
5
|
+
import {
|
|
6
|
+
WorkbenchCommandPalette,
|
|
7
|
+
WorkbenchShortcutCommandBridge,
|
|
8
|
+
createWorkbenchShellCommands,
|
|
9
|
+
type WorkbenchCommandDescriptor,
|
|
10
|
+
type WorkbenchCommandRunContext,
|
|
11
|
+
type WorkbenchShellCommandContext,
|
|
12
|
+
} from '@workbench-kit/react/workbench';
|
|
13
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
14
|
+
|
|
15
|
+
import { useWorkbench } from '../shell/provider.js';
|
|
16
|
+
import { registerWorkbenchShellCommandHandlers } from './shell-command-registration.js';
|
|
17
|
+
import {
|
|
18
|
+
buildWorkbenchPaletteCommands,
|
|
19
|
+
collectExtensionCommandFeaturesById,
|
|
20
|
+
matchesWorkbenchCommandPaletteShortcut,
|
|
21
|
+
matchesWorkbenchQuickAccessShortcut,
|
|
22
|
+
resolveShellCommandActivities,
|
|
23
|
+
} from './command-palette.js';
|
|
24
|
+
import { resolveExtensionKeybindingCommand } from './keybinding-bridge.js';
|
|
25
|
+
|
|
26
|
+
export interface WorkbenchCommandHostProps {
|
|
27
|
+
additionalCommands?: readonly WorkbenchCommandDescriptor[];
|
|
28
|
+
enableCommandPalette?: boolean;
|
|
29
|
+
enableExtensionKeybindings?: boolean;
|
|
30
|
+
enableShortcutBridge?: boolean;
|
|
31
|
+
onOpenSettings: () => void;
|
|
32
|
+
onRunCommand?: (
|
|
33
|
+
command: WorkbenchCommandDescriptor,
|
|
34
|
+
context: WorkbenchCommandRunContext,
|
|
35
|
+
) => boolean | void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function WorkbenchCommandHost({
|
|
39
|
+
additionalCommands = [],
|
|
40
|
+
enableCommandPalette = true,
|
|
41
|
+
enableExtensionKeybindings = true,
|
|
42
|
+
enableShortcutBridge = true,
|
|
43
|
+
onOpenSettings,
|
|
44
|
+
onRunCommand,
|
|
45
|
+
}: WorkbenchCommandHostProps) {
|
|
46
|
+
const { executeCommand, extensionRegistry, keybindingOverrides, layoutService } = useWorkbench();
|
|
47
|
+
const [paletteOpen, setPaletteOpen] = useState(false);
|
|
48
|
+
const [paletteQuery, setPaletteQuery] = useState('');
|
|
49
|
+
const [layout, setLayout] = useState(() => layoutService.getState());
|
|
50
|
+
const shellContextRef = useRef<WorkbenchShellCommandContext | undefined>(undefined);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const disposable = layoutService.onDidChangeLayout(({ state }) => {
|
|
54
|
+
setLayout(state);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return () => {
|
|
58
|
+
disposable.dispose();
|
|
59
|
+
};
|
|
60
|
+
}, [layoutService]);
|
|
61
|
+
|
|
62
|
+
const shellActivities = useMemo(
|
|
63
|
+
() => resolveShellCommandActivities(extensionRegistry),
|
|
64
|
+
[extensionRegistry],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const shellCommandDefinitions = useMemo(
|
|
68
|
+
() =>
|
|
69
|
+
createWorkbenchShellCommands({
|
|
70
|
+
activities: shellActivities,
|
|
71
|
+
includeSettings: true,
|
|
72
|
+
includeSidebarToggle: true,
|
|
73
|
+
}),
|
|
74
|
+
[shellActivities],
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const shellCommandRegistry = useMemo(
|
|
78
|
+
() =>
|
|
79
|
+
createCommandRegistryFromContributions<WorkbenchShellCommandContext>([
|
|
80
|
+
{ commands: shellCommandDefinitions },
|
|
81
|
+
]),
|
|
82
|
+
[shellCommandDefinitions],
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const shellContext = useMemo<WorkbenchShellCommandContext>(
|
|
86
|
+
() => ({
|
|
87
|
+
isPrimarySidebarVisible: layout.sideBar.visible,
|
|
88
|
+
openSettings: onOpenSettings,
|
|
89
|
+
showActivity: (activityId) => {
|
|
90
|
+
layoutService.setActiveViewContainer(activityId);
|
|
91
|
+
layoutService.setSideBarVisible(true);
|
|
92
|
+
},
|
|
93
|
+
togglePrimarySidebar: () => {
|
|
94
|
+
layoutService.setSideBarVisible(!layout.sideBar.visible);
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
[layout.sideBar.visible, layoutService, onOpenSettings],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
shellContextRef.current = shellContext;
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const registration = registerWorkbenchShellCommandHandlers(
|
|
104
|
+
extensionRegistry.commands,
|
|
105
|
+
shellCommandDefinitions,
|
|
106
|
+
() => {
|
|
107
|
+
const context = shellContextRef.current;
|
|
108
|
+
if (!context) {
|
|
109
|
+
throw new Error('Workbench shell command context is not available.');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return context;
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
return () => {
|
|
117
|
+
registration.dispose();
|
|
118
|
+
};
|
|
119
|
+
}, [extensionRegistry.commands, shellCommandDefinitions]);
|
|
120
|
+
|
|
121
|
+
const paletteCommands = useMemo(
|
|
122
|
+
() =>
|
|
123
|
+
buildWorkbenchPaletteCommands({
|
|
124
|
+
additionalCommands,
|
|
125
|
+
extensionCommandFeaturesById: collectExtensionCommandFeaturesById(extensionRegistry),
|
|
126
|
+
extensionCommands: extensionRegistry.commands.getCommands(),
|
|
127
|
+
shellCommands: shellCommandDefinitions,
|
|
128
|
+
shellContext,
|
|
129
|
+
}),
|
|
130
|
+
[additionalCommands, extensionRegistry, shellContext],
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const closePalette = useCallback(() => {
|
|
134
|
+
setPaletteOpen(false);
|
|
135
|
+
}, []);
|
|
136
|
+
|
|
137
|
+
const openPalette = useCallback((query = '') => {
|
|
138
|
+
setPaletteQuery(query);
|
|
139
|
+
setPaletteOpen(true);
|
|
140
|
+
}, []);
|
|
141
|
+
|
|
142
|
+
const runPaletteCommand = useCallback(
|
|
143
|
+
(command: WorkbenchCommandDescriptor, context: WorkbenchCommandRunContext) => {
|
|
144
|
+
const finish = () => {
|
|
145
|
+
closePalette();
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
if (onRunCommand?.(command, context)) {
|
|
149
|
+
finish();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
void executeCommand(command.id).finally(finish);
|
|
154
|
+
},
|
|
155
|
+
[closePalette, executeCommand, onRunCommand],
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (!enableCommandPalette) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
164
|
+
if (matchesWorkbenchCommandPaletteShortcut(event)) {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
openPalette('>');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (matchesWorkbenchQuickAccessShortcut(event)) {
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
openPalette();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
window.addEventListener('keydown', onKeyDown);
|
|
177
|
+
return () => {
|
|
178
|
+
window.removeEventListener('keydown', onKeyDown);
|
|
179
|
+
};
|
|
180
|
+
}, [enableCommandPalette, openPalette]);
|
|
181
|
+
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (!enableExtensionKeybindings) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
188
|
+
if (
|
|
189
|
+
matchesWorkbenchCommandPaletteShortcut(event) ||
|
|
190
|
+
matchesWorkbenchQuickAccessShortcut(event)
|
|
191
|
+
) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const match = resolveExtensionKeybindingCommand(
|
|
196
|
+
extensionRegistry.keybindings,
|
|
197
|
+
event,
|
|
198
|
+
{},
|
|
199
|
+
keybindingOverrides,
|
|
200
|
+
);
|
|
201
|
+
if (!match) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
void executeCommand(match.command, ...(match.args ?? []));
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
window.addEventListener('keydown', onKeyDown);
|
|
210
|
+
return () => {
|
|
211
|
+
window.removeEventListener('keydown', onKeyDown);
|
|
212
|
+
};
|
|
213
|
+
}, [
|
|
214
|
+
enableExtensionKeybindings,
|
|
215
|
+
executeCommand,
|
|
216
|
+
extensionRegistry.keybindings,
|
|
217
|
+
keybindingOverrides,
|
|
218
|
+
]);
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<>
|
|
222
|
+
{enableShortcutBridge ? (
|
|
223
|
+
<WorkbenchShortcutCommandBridge
|
|
224
|
+
context={shellContext}
|
|
225
|
+
preventDefault
|
|
226
|
+
registry={shellCommandRegistry as CommandRegistry<WorkbenchShellCommandContext>}
|
|
227
|
+
/>
|
|
228
|
+
) : null}
|
|
229
|
+
{enableCommandPalette ? (
|
|
230
|
+
<WorkbenchCommandPalette
|
|
231
|
+
commands={paletteCommands}
|
|
232
|
+
open={paletteOpen}
|
|
233
|
+
placeholder="Search commands"
|
|
234
|
+
query={paletteQuery}
|
|
235
|
+
title="Command Palette"
|
|
236
|
+
onClose={closePalette}
|
|
237
|
+
onQueryChange={setPaletteQuery}
|
|
238
|
+
onRunCommand={runPaletteCommand}
|
|
239
|
+
/>
|
|
240
|
+
) : null}
|
|
241
|
+
</>
|
|
242
|
+
);
|
|
243
|
+
}
|