@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,313 @@
1
+ import {
2
+ BUILTIN_WORKBENCH_EXTENSIONS,
3
+ SAMPLE_WORKBENCH_EXTENSIONS,
4
+ createExtensionFeatureSpec,
5
+ createExtensionInstallPlan,
6
+ resolveBundledExtensionByManifestUrl,
7
+ type ExtensionCatalogEntry,
8
+ type ExtensionFeatureInspection,
9
+ type ExtensionFeatureSpec,
10
+ type ExtensionInstallPlan,
11
+ type ExtensionInstallPlanInstallSource,
12
+ type ExtensionRegistry,
13
+ type InstalledExtensionRecord,
14
+ type WorkbenchExtensionDescription,
15
+ } from '@workbench-kit/workbench-core';
16
+ import type {
17
+ ExtensionCatalogBrowseEntry,
18
+ ExtensionManagementDiagnosticSummary,
19
+ ExtensionManagementEntry,
20
+ ExtensionManagementFeatureSummary,
21
+ } from '@workbench-kit/react/workbench/management';
22
+
23
+ export const BUNDLED_EXTENSIONS = [
24
+ ...BUILTIN_WORKBENCH_EXTENSIONS,
25
+ ...SAMPLE_WORKBENCH_EXTENSIONS,
26
+ ] as const;
27
+
28
+ export interface CreateExtensionManagementEntriesInput {
29
+ readonly extensionRegistry: ExtensionRegistry;
30
+ readonly installedRecords: readonly InstalledExtensionRecord[];
31
+ }
32
+
33
+ export interface CreateExtensionCatalogBrowseEntriesInput extends CreateExtensionManagementEntriesInput {
34
+ readonly catalogEntries: readonly ExtensionCatalogEntry[];
35
+ }
36
+
37
+ export interface ExtensionInstallPlanningContext extends CreateExtensionManagementEntriesInput {
38
+ readonly availableExtensions: readonly WorkbenchExtensionDescription[];
39
+ readonly enabledExtensionIds: readonly string[];
40
+ readonly hostCapabilityIds: readonly string[];
41
+ readonly installSources: readonly ExtensionInstallPlanInstallSource[];
42
+ }
43
+
44
+ export function createExtensionManagementEntries({
45
+ extensionRegistry,
46
+ installedRecords,
47
+ }: CreateExtensionManagementEntriesInput): readonly ExtensionManagementEntry[] {
48
+ const installedById = new Map(installedRecords.map((record) => [record.id, record]));
49
+ const extensionFeatures = createExtensionManagementFeatureMaps(extensionRegistry);
50
+ const bundledEntries = BUNDLED_EXTENSIONS.map((extension) => {
51
+ const installed = installedById.get(extension.manifest.id);
52
+ const isBuiltin = extension.manifest.id.startsWith('workbench-kit.builtin.');
53
+ const featureState = resolveExtensionManagementFeatureState(
54
+ extension.manifest.id,
55
+ extensionFeatures,
56
+ );
57
+
58
+ return {
59
+ category: installed?.category ?? (isBuiltin ? 'builtin' : 'sample'),
60
+ description: extension.manifest.displayName,
61
+ diagnostics: featureState.diagnostics,
62
+ displayName: extension.manifest.displayName,
63
+ enabled: isBuiltin ? true : (installed?.enabled ?? false),
64
+ features: featureState.features,
65
+ id: extension.manifest.id,
66
+ installedAt: installed?.installedAt,
67
+ manifestUrl: installed?.manifestUrl,
68
+ source: isBuiltin ? ('bundled' as const) : ('installed' as const),
69
+ } satisfies ExtensionManagementEntry;
70
+ }).filter((entry) => entry.source === 'bundled' || installedById.has(entry.id));
71
+
72
+ const activeExtensions = extensionRegistry
73
+ .getExtensions()
74
+ .filter(
75
+ (extension) =>
76
+ !BUNDLED_EXTENSIONS.some((bundled) => bundled.manifest.id === extension.manifest.id),
77
+ )
78
+ .map((extension) => {
79
+ const installed = installedById.get(extension.manifest.id);
80
+ const featureState = resolveExtensionManagementFeatureState(
81
+ extension.manifest.id,
82
+ extensionFeatures,
83
+ );
84
+
85
+ return {
86
+ category: installed?.category ?? 'installed',
87
+ description: extension.manifest.displayName,
88
+ diagnostics: featureState.diagnostics,
89
+ displayName: extension.manifest.displayName,
90
+ enabled: installed?.enabled ?? true,
91
+ features: featureState.features,
92
+ id: extension.manifest.id,
93
+ installedAt: installed?.installedAt,
94
+ manifestUrl: installed?.manifestUrl,
95
+ source: 'installed',
96
+ } satisfies ExtensionManagementEntry;
97
+ });
98
+
99
+ return [...bundledEntries, ...activeExtensions].sort((left, right) =>
100
+ left.displayName.localeCompare(right.displayName),
101
+ );
102
+ }
103
+
104
+ export function createExtensionCatalogBrowseEntries({
105
+ catalogEntries,
106
+ extensionRegistry,
107
+ installedRecords,
108
+ }: CreateExtensionCatalogBrowseEntriesInput): readonly ExtensionCatalogBrowseEntry[] {
109
+ const installedIds = new Set(installedRecords.map((record) => record.id));
110
+ const installContext = createExtensionInstallPlanningContext({
111
+ catalogEntries,
112
+ extensionRegistry,
113
+ installedRecords,
114
+ });
115
+
116
+ return catalogEntries.map((entry) => {
117
+ const bundledExtension = resolveBundledExtensionByManifestUrl(
118
+ entry.manifestUrl,
119
+ installContext.availableExtensions,
120
+ );
121
+ const extensionId = bundledExtension?.manifest.id ?? entry.id;
122
+ const plan = createCatalogEntryInstallPlan(entry, installContext);
123
+
124
+ return {
125
+ category: entry.category,
126
+ description: entry.description,
127
+ displayName: entry.displayName,
128
+ icon: entry.icon,
129
+ id: extensionId,
130
+ installPlan: plan ? toExtensionInstallPlanSummary(plan) : undefined,
131
+ installed: installedIds.has(extensionId),
132
+ manifestUrl: entry.manifestUrl,
133
+ };
134
+ });
135
+ }
136
+
137
+ export function createExtensionInstallPlanningContext({
138
+ catalogEntries,
139
+ extensionRegistry,
140
+ installedRecords,
141
+ }: CreateExtensionCatalogBrowseEntriesInput): ExtensionInstallPlanningContext {
142
+ const availableExtensions = mergeUniqueExtensionDescriptions([
143
+ ...BUNDLED_EXTENSIONS,
144
+ ...extensionRegistry.getExtensions(),
145
+ ]);
146
+
147
+ return {
148
+ availableExtensions,
149
+ enabledExtensionIds: extensionRegistry
150
+ .getExtensions()
151
+ .map((extension) => extension.manifest.id),
152
+ extensionRegistry,
153
+ hostCapabilityIds: extensionRegistry.capabilityRegistry.listProviderIds(),
154
+ installSources: createExtensionInstallSources(catalogEntries, availableExtensions),
155
+ installedRecords,
156
+ };
157
+ }
158
+
159
+ export function createCatalogEntryInstallPlan(
160
+ entry: Pick<ExtensionCatalogBrowseEntry, 'manifestUrl'>,
161
+ {
162
+ availableExtensions,
163
+ enabledExtensionIds,
164
+ hostCapabilityIds,
165
+ installedRecords,
166
+ installSources,
167
+ }: ExtensionInstallPlanningContext,
168
+ ): ExtensionInstallPlan | undefined {
169
+ const bundledExtension = resolveBundledExtensionByManifestUrl(
170
+ entry.manifestUrl,
171
+ availableExtensions,
172
+ );
173
+ if (!bundledExtension) {
174
+ return undefined;
175
+ }
176
+
177
+ return createExtensionInstallPlan({
178
+ availableExtensions,
179
+ enabledExtensionIds,
180
+ hostCapabilityIds,
181
+ installSources,
182
+ installedRecords,
183
+ targetExtensionId: bundledExtension.manifest.id,
184
+ });
185
+ }
186
+
187
+ function createExtensionInstallSources(
188
+ catalogEntries: readonly ExtensionCatalogEntry[],
189
+ availableExtensions: readonly WorkbenchExtensionDescription[],
190
+ ): readonly ExtensionInstallPlanInstallSource[] {
191
+ const byId = new Map<string, ExtensionInstallPlanInstallSource>();
192
+ for (const entry of catalogEntries) {
193
+ const bundledExtension = resolveBundledExtensionByManifestUrl(
194
+ entry.manifestUrl,
195
+ availableExtensions,
196
+ );
197
+ const extensionId = bundledExtension?.manifest.id ?? entry.id;
198
+ byId.set(extensionId, {
199
+ category: entry.category,
200
+ id: extensionId,
201
+ manifestUrl: entry.manifestUrl,
202
+ });
203
+ }
204
+
205
+ return [...byId.values()];
206
+ }
207
+
208
+ function mergeUniqueExtensionDescriptions(
209
+ descriptions: readonly WorkbenchExtensionDescription[],
210
+ ): readonly WorkbenchExtensionDescription[] {
211
+ const byId = new Map<string, WorkbenchExtensionDescription>();
212
+ for (const description of descriptions) {
213
+ byId.set(description.manifest.id, description);
214
+ }
215
+ return [...byId.values()];
216
+ }
217
+
218
+ function createExtensionManagementFeatureMaps(extensionRegistry: ExtensionRegistry) {
219
+ return {
220
+ bundledFeaturesById: new Map(
221
+ BUNDLED_EXTENSIONS.map((extension) => [
222
+ extension.manifest.id,
223
+ createExtensionFeatureSpec(extension),
224
+ ]),
225
+ ),
226
+ inspectionsById: new Map(
227
+ extensionRegistry
228
+ .getFeatureInspections()
229
+ .map((inspection) => [inspection.feature.id, inspection]),
230
+ ),
231
+ };
232
+ }
233
+
234
+ function resolveExtensionManagementFeatureState(
235
+ extensionId: string,
236
+ {
237
+ bundledFeaturesById,
238
+ inspectionsById,
239
+ }: {
240
+ bundledFeaturesById: ReadonlyMap<string, ExtensionFeatureSpec>;
241
+ inspectionsById: ReadonlyMap<string, ExtensionFeatureInspection>;
242
+ },
243
+ ): {
244
+ readonly diagnostics?: readonly ExtensionManagementDiagnosticSummary[] | undefined;
245
+ readonly features?: ExtensionManagementFeatureSummary | undefined;
246
+ } {
247
+ const inspection = inspectionsById.get(extensionId);
248
+ const feature = inspection?.feature ?? bundledFeaturesById.get(extensionId);
249
+
250
+ return {
251
+ diagnostics: inspection?.diagnostics.map(({ message, severity }) => ({ message, severity })),
252
+ features: feature ? toExtensionManagementFeatureSummary(feature) : undefined,
253
+ };
254
+ }
255
+
256
+ function toExtensionManagementFeatureSummary(
257
+ feature: ExtensionFeatureSpec,
258
+ ): ExtensionManagementFeatureSummary {
259
+ const commandTitlesById = new Map(feature.commands.map((command) => [command.id, command.title]));
260
+
261
+ return {
262
+ capabilities: feature.capabilities,
263
+ commands: feature.commands.map((command) => ({
264
+ description: command.description,
265
+ id: command.id,
266
+ label: command.title,
267
+ })),
268
+ documentViews: feature.documentViews.map((view) => ({
269
+ id: view.id,
270
+ label: view.label,
271
+ })),
272
+ menus: feature.menus.map((menu) => ({
273
+ description: formatMenuContributionDescription(menu.group, menu.order),
274
+ id: `${menu.menu}:${menu.command}`,
275
+ label: `${menu.menu}: ${commandTitlesById.get(menu.command) ?? menu.command}`,
276
+ })),
277
+ permissions: feature.permissions,
278
+ settings: feature.settings.map((setting) => ({
279
+ description: setting.description,
280
+ id: setting.key,
281
+ label: setting.key,
282
+ })),
283
+ views: feature.views.map((view) => ({
284
+ id: view.id,
285
+ label: view.name,
286
+ })),
287
+ };
288
+ }
289
+
290
+ function toExtensionInstallPlanSummary(
291
+ plan: ExtensionInstallPlan,
292
+ ): ExtensionCatalogBrowseEntry['installPlan'] {
293
+ return {
294
+ blocked: plan.blocked,
295
+ diagnostics: plan.diagnostics.map(({ message, severity }) => ({ message, severity })),
296
+ enableExtensionIds: plan.enableExtensionIds,
297
+ installExtensionIds: plan.installExtensionIds,
298
+ permissions: plan.permissions,
299
+ requiresApproval: plan.requiresApproval,
300
+ };
301
+ }
302
+
303
+ function formatMenuContributionDescription(
304
+ group: string | undefined,
305
+ order: number | undefined,
306
+ ): string | undefined {
307
+ const parts = [
308
+ group ? `group: ${group}` : undefined,
309
+ order !== undefined ? `order: ${order}` : undefined,
310
+ ].filter((part): part is string => part !== undefined);
311
+
312
+ return parts.length > 0 ? parts.join(', ') : undefined;
313
+ }
@@ -0,0 +1,241 @@
1
+ import { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import {
3
+ DEFAULT_EXTENSION_CATALOG_TRUST_POLICY,
4
+ DEFAULT_EXTENSION_INSTALL_TRUST_STORAGE_KEY,
5
+ DEFAULT_INSTALLED_EXTENSIONS_STORAGE_KEY,
6
+ ExtensionInstallApprovalRequiredError,
7
+ applyExtensionInstallPlanToRecords,
8
+ assertExtensionCatalogUrlAllowed,
9
+ loadExtensionInstallTrustRecords,
10
+ loadInstalledExtensions,
11
+ parseExtensionCatalog,
12
+ recordExtensionInstallTrust,
13
+ saveExtensionInstallTrustRecords,
14
+ saveInstalledExtensions,
15
+ toggleInstalledExtensionEnabled,
16
+ type ExtensionCatalogEntry,
17
+ type ExtensionCatalogTrustPolicy,
18
+ type ExtensionInstallTrustRecord,
19
+ type InstalledExtensionRecord,
20
+ } from '@workbench-kit/workbench-core';
21
+ import type {
22
+ ExtensionCatalogBrowseEntry,
23
+ ExtensionInstallOptions,
24
+ ExtensionManagementEntry,
25
+ ExtensionManagementPendingAction,
26
+ } from '@workbench-kit/react/workbench/management';
27
+
28
+ import {
29
+ createCatalogEntryInstallPlan,
30
+ createExtensionCatalogBrowseEntries,
31
+ createExtensionInstallPlanningContext,
32
+ createExtensionManagementEntries,
33
+ } from './management-model.js';
34
+ import { useWorkbench, type WorkbenchStorageAdapter } from '../shell/provider.js';
35
+
36
+ export interface UseExtensionManagementModelOptions {
37
+ catalogTrustPolicy?: ExtensionCatalogTrustPolicy | undefined;
38
+ catalogUrl?: string | undefined;
39
+ installedExtensionsStorage?: WorkbenchStorageAdapter | undefined;
40
+ installedExtensionsStorageKey?: string | undefined;
41
+ installTrustStorage?: WorkbenchStorageAdapter | undefined;
42
+ installTrustStorageKey?: string | undefined;
43
+ }
44
+
45
+ export function useExtensionManagementModel({
46
+ catalogTrustPolicy = DEFAULT_EXTENSION_CATALOG_TRUST_POLICY,
47
+ catalogUrl = '/extension-catalog.json',
48
+ installedExtensionsStorage,
49
+ installedExtensionsStorageKey,
50
+ installTrustStorage,
51
+ installTrustStorageKey = DEFAULT_EXTENSION_INSTALL_TRUST_STORAGE_KEY,
52
+ }: UseExtensionManagementModelOptions = {}) {
53
+ const workbench = useWorkbench();
54
+ const { extensionRegistry } = workbench;
55
+ const resolvedInstalledExtensionsStorage =
56
+ installedExtensionsStorage ?? workbench.installedExtensionsStorage;
57
+ const resolvedInstalledExtensionsStorageKey =
58
+ installedExtensionsStorageKey ??
59
+ workbench.installedExtensionsStorageKey ??
60
+ DEFAULT_INSTALLED_EXTENSIONS_STORAGE_KEY;
61
+ const resolvedInstallTrustStorage = installTrustStorage ?? resolvedInstalledExtensionsStorage;
62
+ const [catalogEntries, setCatalogEntries] = useState<readonly ExtensionCatalogEntry[]>([]);
63
+ const [catalogLoading, setCatalogLoading] = useState(Boolean(catalogUrl));
64
+ const [catalogError, setCatalogError] = useState<string | undefined>();
65
+ const [pendingAction, setPendingAction] = useState<
66
+ ExtensionManagementPendingAction | undefined
67
+ >();
68
+ const [installedRecords, setInstalledRecords] = useState<readonly InstalledExtensionRecord[]>(
69
+ () =>
70
+ loadInstalledExtensions(
71
+ resolvedInstalledExtensionsStorageKey,
72
+ resolvedInstalledExtensionsStorage,
73
+ ),
74
+ );
75
+ const [installTrustRecords, setInstallTrustRecords] = useState<
76
+ readonly ExtensionInstallTrustRecord[]
77
+ >(() => loadExtensionInstallTrustRecords(installTrustStorageKey, resolvedInstallTrustStorage));
78
+
79
+ useEffect(() => {
80
+ setInstalledRecords(
81
+ loadInstalledExtensions(
82
+ resolvedInstalledExtensionsStorageKey,
83
+ resolvedInstalledExtensionsStorage,
84
+ ),
85
+ );
86
+ }, [resolvedInstalledExtensionsStorage, resolvedInstalledExtensionsStorageKey]);
87
+
88
+ useEffect(() => {
89
+ setInstallTrustRecords(
90
+ loadExtensionInstallTrustRecords(installTrustStorageKey, resolvedInstallTrustStorage),
91
+ );
92
+ }, [installTrustStorageKey, resolvedInstallTrustStorage]);
93
+
94
+ useEffect(() => {
95
+ if (!catalogUrl) {
96
+ setCatalogEntries([]);
97
+ setCatalogLoading(false);
98
+ setCatalogError(undefined);
99
+ return;
100
+ }
101
+
102
+ let cancelled = false;
103
+ setCatalogLoading(true);
104
+ setCatalogError(undefined);
105
+
106
+ void Promise.resolve()
107
+ .then(() => {
108
+ assertExtensionCatalogUrlAllowed(catalogUrl, catalogTrustPolicy);
109
+ return fetch(catalogUrl);
110
+ })
111
+ .then(async (response) => {
112
+ if (!response.ok) {
113
+ throw new Error(`Catalog request failed with status ${response.status}.`);
114
+ }
115
+
116
+ const catalog = parseExtensionCatalog(await response.json());
117
+ if (!cancelled) {
118
+ setCatalogEntries(catalog.entries);
119
+ }
120
+ })
121
+ .catch((error: unknown) => {
122
+ if (!cancelled) {
123
+ setCatalogEntries([]);
124
+ setCatalogError(
125
+ error instanceof Error ? error.message : 'Failed to load extension catalog.',
126
+ );
127
+ }
128
+ })
129
+ .finally(() => {
130
+ if (!cancelled) {
131
+ setCatalogLoading(false);
132
+ }
133
+ });
134
+
135
+ return () => {
136
+ cancelled = true;
137
+ };
138
+ }, [catalogTrustPolicy, catalogUrl]);
139
+
140
+ const installedEntries = useMemo<readonly ExtensionManagementEntry[]>(() => {
141
+ return createExtensionManagementEntries({ extensionRegistry, installedRecords });
142
+ }, [extensionRegistry, installedRecords]);
143
+
144
+ const browseEntries = useMemo<readonly ExtensionCatalogBrowseEntry[]>(() => {
145
+ return createExtensionCatalogBrowseEntries({
146
+ catalogEntries,
147
+ extensionRegistry,
148
+ installedRecords,
149
+ });
150
+ }, [catalogEntries, extensionRegistry, installedRecords]);
151
+
152
+ const installCatalogEntry = useCallback(
153
+ (entry: ExtensionCatalogBrowseEntry, options?: ExtensionInstallOptions) => {
154
+ const installContext = createExtensionInstallPlanningContext({
155
+ catalogEntries,
156
+ extensionRegistry,
157
+ installedRecords,
158
+ });
159
+ const plan = createCatalogEntryInstallPlan(entry, installContext);
160
+ if (!plan || plan.blocked) {
161
+ return;
162
+ }
163
+
164
+ // Align with core hard gate: unapproved privileged installs must not persist.
165
+ if (plan.requiresApproval && options?.approved !== true) {
166
+ throw new ExtensionInstallApprovalRequiredError();
167
+ }
168
+
169
+ const next = applyExtensionInstallPlanToRecords({
170
+ approved: options?.approved === true,
171
+ currentRecords: installedRecords,
172
+ installSources: installContext.installSources,
173
+ plan,
174
+ });
175
+ saveInstalledExtensions(
176
+ next,
177
+ resolvedInstalledExtensionsStorageKey,
178
+ resolvedInstalledExtensionsStorage,
179
+ );
180
+ setInstalledRecords(next);
181
+ setPendingAction({ entryId: entry.id, kind: 'install' });
182
+ if (typeof window !== 'undefined') {
183
+ window.requestAnimationFrame(() => {
184
+ window.location.reload();
185
+ });
186
+ }
187
+ },
188
+ [
189
+ catalogEntries,
190
+ extensionRegistry,
191
+ installedRecords,
192
+ resolvedInstalledExtensionsStorage,
193
+ resolvedInstalledExtensionsStorageKey,
194
+ ],
195
+ );
196
+
197
+ const toggleInstalledEntry = useCallback(
198
+ (entry: ExtensionManagementEntry, enabled: boolean) => {
199
+ if (entry.source === 'bundled' && entry.id.startsWith('workbench-kit.builtin.')) {
200
+ return;
201
+ }
202
+
203
+ const next = toggleInstalledExtensionEnabled(
204
+ entry.id,
205
+ enabled,
206
+ resolvedInstalledExtensionsStorageKey,
207
+ resolvedInstalledExtensionsStorage,
208
+ );
209
+ setInstalledRecords(next);
210
+ setPendingAction({ entryId: entry.id, kind: 'toggle' });
211
+ if (typeof window !== 'undefined') {
212
+ window.requestAnimationFrame(() => {
213
+ window.location.reload();
214
+ });
215
+ }
216
+ },
217
+ [resolvedInstalledExtensionsStorage, resolvedInstalledExtensionsStorageKey],
218
+ );
219
+
220
+ const rememberInstallTrust = useCallback(
221
+ (entry: ExtensionCatalogBrowseEntry) => {
222
+ const permissions = entry.installPlan?.permissions ?? [];
223
+ const next = recordExtensionInstallTrust(entry.id, permissions, installTrustRecords);
224
+ saveExtensionInstallTrustRecords(next, installTrustStorageKey, resolvedInstallTrustStorage);
225
+ setInstallTrustRecords(next);
226
+ },
227
+ [installTrustRecords, installTrustStorageKey, resolvedInstallTrustStorage],
228
+ );
229
+
230
+ return {
231
+ browseEntries,
232
+ catalogError,
233
+ catalogLoading,
234
+ installCatalogEntry,
235
+ installedEntries,
236
+ installTrustRecords,
237
+ pendingAction,
238
+ rememberInstallTrust,
239
+ toggleInstalledEntry,
240
+ };
241
+ }
@@ -0,0 +1,19 @@
1
+ export const BUILTIN_EXTENSIONS_VIEW_RENDER_KIND = 'workbench-kit.builtin.extensions.view' as const;
2
+ export const BUILTIN_EXTENSIONS_VIEW_CONTAINER_ID = 'extensions' as const;
3
+ export const BUILTIN_EXTENSIONS_FOCUS_COMMAND_ID =
4
+ 'workbench-kit.builtin.extensions.focus' as const;
5
+
6
+ export interface BuiltinExtensionsViewRenderData {
7
+ readonly kind: typeof BUILTIN_EXTENSIONS_VIEW_RENDER_KIND;
8
+ }
9
+
10
+ export function isBuiltinExtensionsViewRenderData(
11
+ value: unknown,
12
+ ): value is BuiltinExtensionsViewRenderData {
13
+ return (
14
+ typeof value === 'object' &&
15
+ value !== null &&
16
+ 'kind' in value &&
17
+ (value as BuiltinExtensionsViewRenderData).kind === BUILTIN_EXTENSIONS_VIEW_RENDER_KIND
18
+ );
19
+ }
@@ -0,0 +1,63 @@
1
+ import { useCallback } from 'react';
2
+ import { ExtensionManagementSidebar } from '@workbench-kit/react/workbench/management';
3
+ import {
4
+ isExtensionInstallTrusted,
5
+ type ExtensionCatalogTrustPolicy,
6
+ } from '@workbench-kit/workbench-core';
7
+
8
+ import {
9
+ BUILTIN_EXTENSIONS_VIEW_RENDER_KIND,
10
+ isBuiltinExtensionsViewRenderData,
11
+ type BuiltinExtensionsViewRenderData,
12
+ } from './view-data.js';
13
+ import { useExtensionManagementModel } from './use-extension-management.js';
14
+ import { useWorkbench } from '../shell/provider.js';
15
+
16
+ export type { BuiltinExtensionsViewRenderData };
17
+ export { BUILTIN_EXTENSIONS_VIEW_RENDER_KIND, isBuiltinExtensionsViewRenderData };
18
+
19
+ export function BuiltinExtensionsView({
20
+ catalogTrustPolicy,
21
+ catalogUrl,
22
+ }: {
23
+ catalogTrustPolicy?: ExtensionCatalogTrustPolicy | undefined;
24
+ catalogUrl?: string | undefined;
25
+ }) {
26
+ const { missingExtensionIds } = useWorkbench();
27
+ const {
28
+ browseEntries,
29
+ catalogError,
30
+ catalogLoading,
31
+ installCatalogEntry,
32
+ installedEntries,
33
+ installTrustRecords,
34
+ pendingAction,
35
+ rememberInstallTrust,
36
+ toggleInstalledEntry,
37
+ } = useExtensionManagementModel({ catalogTrustPolicy, catalogUrl });
38
+
39
+ const isInstallTrusted = useCallback(
40
+ (entry: (typeof browseEntries)[number]) =>
41
+ isExtensionInstallTrusted(
42
+ entry.id,
43
+ entry.installPlan?.permissions ?? [],
44
+ installTrustRecords,
45
+ ),
46
+ [installTrustRecords],
47
+ );
48
+
49
+ return (
50
+ <ExtensionManagementSidebar
51
+ browseEntries={browseEntries}
52
+ catalogError={catalogError}
53
+ catalogLoading={catalogLoading}
54
+ installedEntries={installedEntries}
55
+ isInstallTrusted={isInstallTrusted}
56
+ missingExtensionIds={missingExtensionIds}
57
+ pendingAction={pendingAction}
58
+ onInstall={installCatalogEntry}
59
+ onRememberInstallTrust={rememberInstallTrust}
60
+ onToggleEnabled={toggleInstalledEntry}
61
+ />
62
+ );
63
+ }