@innovatorved/code-lab 0.6.1 → 0.7.1

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 (131) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +35 -0
  3. package/README.md +38 -1
  4. package/dist/apps/web/src/index.d.ts +0 -9
  5. package/dist/code-lab-sql.esm.js +19 -19
  6. package/dist/code-lab-sql.umd.js +20 -20
  7. package/dist/code-lab.css +1 -1
  8. package/dist/code-lab.d.ts +19 -1
  9. package/dist/code-lab.esm.js +933 -1685
  10. package/dist/code-lab.js +932 -1684
  11. package/dist/extensions/cpp.esm.js +132 -8751
  12. package/dist/extensions/cpp.js +124 -8761
  13. package/dist/extensions/guided-lab.esm.js +33 -6827
  14. package/dist/extensions/guided-lab.js +33 -6845
  15. package/dist/extensions/javascript.esm.js +1 -36
  16. package/dist/extensions/javascript.js +1 -58
  17. package/dist/extensions/python.esm.js +79 -8109
  18. package/dist/extensions/python.js +79 -8127
  19. package/dist/extensions/typescript.esm.js +1 -55
  20. package/dist/extensions/typescript.js +1 -77
  21. package/dist/index.d.ts +1 -1
  22. package/dist/modular-kernel.d.ts +0 -4
  23. package/dist/preview-sw.js +1 -1
  24. package/dist/runtime.esm.js +79 -79
  25. package/dist/runtime.js +79 -79
  26. package/dist/schemas.d.ts +22 -1
  27. package/dist/schemas.esm.js +33 -6806
  28. package/dist/schemas.js +33 -6822
  29. package/dist/shell.esm.js +248 -242
  30. package/dist/shell.js +248 -242
  31. package/dist/terminal.esm.js +8 -6
  32. package/dist/terminal.js +6 -6
  33. package/dist/workbench/command-palette.d.ts +0 -4
  34. package/dist/workbench/index.d.ts +0 -20
  35. package/dist/workbench/intellisense.d.ts +1 -7
  36. package/package.json +3 -10
  37. package/src/code-lab.css +11 -503
  38. package/src/extensions/cpp.ts +11 -29
  39. package/src/extensions/guided-lab.ts +6 -2
  40. package/src/extensions/python.ts +9 -3
  41. package/src/index.ts +1 -1
  42. package/src/modular-kernel.ts +0 -4
  43. package/src/runtime.ts +153 -42
  44. package/src/schemas.ts +12 -3
  45. package/src/shell.ts +109 -16
  46. package/src/terminal.ts +4 -2
  47. package/src/workbench/command-palette.ts +22 -302
  48. package/src/workbench/diff-editor.ts +2 -0
  49. package/src/workbench/icons.ts +1 -1
  50. package/src/workbench/index.ts +0 -15
  51. package/src/workbench/intellisense.ts +17 -4
  52. package/src/workbench.ts +432 -456
  53. package/dist/code-lab.umd.js +0 -6109
  54. package/dist/packages/editor/src/index.d.ts +0 -118
  55. package/dist/packages/preview/src/index.d.ts +0 -34
  56. package/dist/packages/runtime/src/index.d.ts +0 -47
  57. package/dist/packages/terminal/src/index.d.ts +0 -54
  58. package/dist/workbench/drawer.d.ts +0 -18
  59. package/dist/workbench/file-tree.d.ts +0 -11
  60. package/dist/workbench/guided-pane.d.ts +0 -11
  61. package/dist/workbench/styles.d.ts +0 -4
  62. package/dist/workbench/toolbar.d.ts +0 -17
  63. package/packages/commands/README.md +0 -7
  64. package/packages/commands/package.json +0 -16
  65. package/packages/commands/src/index.ts +0 -467
  66. package/packages/commands/tsconfig.json +0 -22
  67. package/packages/core/README.md +0 -12
  68. package/packages/core/package.json +0 -13
  69. package/packages/core/src/di.ts +0 -147
  70. package/packages/core/src/disposable.ts +0 -112
  71. package/packages/core/src/errors.ts +0 -205
  72. package/packages/core/src/events.ts +0 -157
  73. package/packages/core/src/index.ts +0 -49
  74. package/packages/core/src/path.ts +0 -118
  75. package/packages/core/src/registry.ts +0 -61
  76. package/packages/core/tsconfig.json +0 -19
  77. package/packages/editor/README.md +0 -9
  78. package/packages/editor/package.json +0 -18
  79. package/packages/editor/src/index.ts +0 -344
  80. package/packages/editor/tsconfig.json +0 -24
  81. package/packages/fs/README.md +0 -7
  82. package/packages/fs/package.json +0 -16
  83. package/packages/fs/src/backends.ts +0 -301
  84. package/packages/fs/src/index.ts +0 -18
  85. package/packages/fs/src/types.ts +0 -44
  86. package/packages/fs/src/vfs-service.ts +0 -257
  87. package/packages/fs/tsconfig.json +0 -22
  88. package/packages/preview/README.md +0 -3
  89. package/packages/preview/package.json +0 -16
  90. package/packages/preview/src/index.ts +0 -125
  91. package/packages/preview/tsconfig.json +0 -22
  92. package/packages/runtime/README.md +0 -3
  93. package/packages/runtime/package.json +0 -17
  94. package/packages/runtime/src/index.ts +0 -134
  95. package/packages/runtime/tsconfig.json +0 -23
  96. package/packages/settings/README.md +0 -7
  97. package/packages/settings/package.json +0 -16
  98. package/packages/settings/src/builtin-schemas.ts +0 -246
  99. package/packages/settings/src/configuration-service.ts +0 -609
  100. package/packages/settings/src/index.ts +0 -38
  101. package/packages/settings/src/jsonc.ts +0 -189
  102. package/packages/settings/src/schema.ts +0 -164
  103. package/packages/settings/tsconfig.json +0 -22
  104. package/packages/sql/README.md +0 -12
  105. package/packages/sql/package.json +0 -13
  106. package/packages/sql/src/completions.ts +0 -359
  107. package/packages/sql/src/diagnostics.ts +0 -200
  108. package/packages/sql/src/formatter.ts +0 -271
  109. package/packages/sql/src/index.ts +0 -54
  110. package/packages/sql/src/sql-editor.ts +0 -802
  111. package/packages/sql/src/styles.ts +0 -524
  112. package/packages/sql/src/tokenizer.ts +0 -457
  113. package/packages/sql/src/types.ts +0 -148
  114. package/packages/sql/tsconfig.json +0 -19
  115. package/packages/terminal/README.md +0 -3
  116. package/packages/terminal/package.json +0 -16
  117. package/packages/terminal/src/index.ts +0 -183
  118. package/packages/terminal/tsconfig.json +0 -22
  119. package/packages/ui/README.md +0 -8
  120. package/packages/ui/package.json +0 -18
  121. package/packages/ui/src/index.ts +0 -40
  122. package/packages/ui/src/observability.ts +0 -173
  123. package/packages/ui/src/plugin-registry.ts +0 -289
  124. package/packages/ui/src/settings-dialog.ts +0 -911
  125. package/packages/ui/src/themes.ts +0 -333
  126. package/packages/ui/tsconfig.json +0 -24
  127. package/src/workbench/drawer.ts +0 -157
  128. package/src/workbench/file-tree.ts +0 -51
  129. package/src/workbench/guided-pane.ts +0 -43
  130. package/src/workbench/styles.ts +0 -211
  131. package/src/workbench/toolbar.ts +0 -182
@@ -1,911 +0,0 @@
1
- import { DisposableStore, type IDisposable } from '@code-lab/core';
2
- import type { IConfigurationService, SettingCategory, SettingDescriptor } from '@code-lab/settings';
3
-
4
- function escapeAttr(raw: string): string {
5
- return raw
6
- .replace(/&/g, '&')
7
- .replace(/</g, '&lt;')
8
- .replace(/>/g, '&gt;')
9
- .replace(/"/g, '&quot;');
10
- }
11
-
12
- export type SettingsScope = 'user' | 'workspace';
13
-
14
- export interface SettingsInlineMountOptions {
15
- readonly scope?: SettingsScope;
16
- readonly onOpenJson?: () => void;
17
- readonly onOpenSettingsJson?: () => void;
18
- readonly onWorkspaceSettingsMutated?: (nextWorkspaceSettings: Record<string, unknown>) => void;
19
- }
20
-
21
- export type SettingsOpenOptions = SettingsInlineMountOptions;
22
-
23
- export interface SettingsDialogOptions {
24
- readonly configuration: IConfigurationService;
25
- readonly scope?: SettingsScope;
26
- readonly onOpenSettingsJson?: () => void;
27
- readonly onOpenJson?: () => void;
28
- readonly onExportSettings?: (json: string) => void;
29
- readonly onImportSettings?: () => void;
30
- readonly onWorkspaceSettingsMutated?: (nextWorkspaceSettings: Record<string, unknown>) => void;
31
- }
32
-
33
- const ALL_CATEGORIES: ReadonlyArray<'All' | SettingCategory> = [
34
- 'All',
35
- 'Editor',
36
- 'Workbench',
37
- 'Files',
38
- 'Terminal',
39
- 'Preview',
40
- 'Runtime',
41
- 'SQL'
42
- ];
43
-
44
- const SETTINGS_STYLE_ID = 'codelab-ui-settings-styles';
45
-
46
- export const SETTINGS_COMPONENT_CSS = `/* @innovatorved/code-lab/ui — Tokenized Settings & Control Components */
47
- .cl-settings-dialog,
48
- .cl-settings-editor {
49
- --cl-ui-sans: var(--cl-font-sans, var(--ds-font-sans, var(--font-sans, "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif)));
50
- --cl-ui-mono: var(--cl-font-mono, var(--ds-font-mono, var(--font-mono, "Geist Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace)));
51
- --cl-ui-text-2xs: var(--cl-text-2xs, var(--ds-text-2xs, 0.6875rem));
52
- --cl-ui-text-xs: var(--cl-text-xs, var(--ds-text-xs, 0.75rem));
53
- --cl-ui-text-sm: var(--cl-text-sm, var(--ds-text-sm, 0.8125rem));
54
- --cl-ui-text-base: var(--cl-text-base, var(--ds-text-base, 0.875rem));
55
- font-family: var(--cl-ui-sans);
56
- color: var(--cl-fg, #f4f4f5);
57
- }
58
-
59
- .cl-settings-editor.cl-settings-inline {
60
- display: flex;
61
- flex-direction: column;
62
- height: 100%;
63
- min-height: 0;
64
- background: var(--cl-editor-bg, var(--cl-bg, #0f0f10));
65
- }
66
-
67
- .cl-settings-header {
68
- display: flex;
69
- align-items: center;
70
- justify-content: space-between;
71
- gap: 12px;
72
- padding: 12px 20px;
73
- border-bottom: 1px solid var(--cl-border, #27272a);
74
- background: var(--cl-surface, var(--cl-bg-elevated, #141415));
75
- flex-wrap: wrap;
76
- }
77
-
78
- .cl-settings-title {
79
- margin: 0;
80
- font-size: var(--cl-ui-text-base);
81
- font-weight: 600;
82
- letter-spacing: -0.015em;
83
- color: var(--cl-fg-active, var(--cl-fg, #f4f4f5));
84
- }
85
-
86
- .cl-settings-actions {
87
- display: flex;
88
- align-items: center;
89
- gap: 6px;
90
- flex-wrap: wrap;
91
- }
92
-
93
- .cl-settings-toolbar {
94
- padding: 12px 20px 0 20px;
95
- border-bottom: 1px solid var(--cl-border, #27272a);
96
- background: var(--cl-surface, var(--cl-bg-elevated, #141415));
97
- display: flex;
98
- flex-direction: column;
99
- gap: 10px;
100
- }
101
-
102
- .cl-settings-search {
103
- width: 100%;
104
- height: 32px;
105
- padding: 0 10px;
106
- border-radius: var(--cl-radius-md, 6px);
107
- border: 1px solid var(--cl-input-border, var(--cl-border, #27272a));
108
- background: var(--cl-input-bg, var(--cl-bg, #0f0f10));
109
- color: var(--cl-fg, #f4f4f5);
110
- font-family: var(--cl-ui-sans);
111
- font-size: var(--cl-ui-text-sm);
112
- outline: none;
113
- transition: border-color 120ms ease;
114
- }
115
-
116
- .cl-settings-search::placeholder {
117
- color: var(--cl-fg-faint, var(--cl-fg-muted, #8e8e97));
118
- }
119
-
120
- .cl-settings-search:focus {
121
- border-color: var(--cl-focus-border, #a1a1aa);
122
- }
123
-
124
- .cl-settings-scopes {
125
- display: flex;
126
- align-items: center;
127
- gap: 4px;
128
- overflow-x: auto;
129
- }
130
-
131
- .cl-settings-scope-tab {
132
- flex: none;
133
- padding: 6px 12px;
134
- border: none;
135
- border-bottom: 2px solid transparent;
136
- background: transparent;
137
- color: var(--cl-fg-muted, #a1a1aa);
138
- font-family: var(--cl-ui-sans);
139
- font-size: var(--cl-ui-text-xs);
140
- font-weight: 500;
141
- cursor: pointer;
142
- transition: color 120ms ease, border-color 120ms ease;
143
- }
144
-
145
- .cl-settings-scope-tab:hover {
146
- color: var(--cl-fg, #f4f4f5);
147
- }
148
-
149
- .cl-settings-scope-tab[aria-selected="true"] {
150
- color: var(--cl-fg-active, var(--cl-fg, #f4f4f5));
151
- font-weight: 600;
152
- border-bottom-color: var(--cl-accent, #f4f4f5);
153
- }
154
-
155
- .cl-settings-body {
156
- display: grid;
157
- grid-template-columns: 180px minmax(0, 1fr);
158
- }
159
-
160
- .cl-settings-body--dialog {
161
- min-height: 320px;
162
- max-height: 62vh;
163
- }
164
-
165
- .cl-settings-body--inline {
166
- flex: 1;
167
- min-height: 0;
168
- overflow: hidden;
169
- }
170
-
171
- .cl-settings-categories {
172
- border-right: 1px solid var(--cl-border, #27272a);
173
- background: var(--cl-surface, var(--cl-bg-elevated, #141415));
174
- padding: 10px 8px;
175
- display: flex;
176
- flex-direction: column;
177
- gap: 2px;
178
- overflow-y: auto;
179
- }
180
-
181
- .cl-settings-cat-btn {
182
- text-align: left;
183
- padding: 6px 10px;
184
- border: 1px solid transparent;
185
- border-radius: var(--cl-radius-md, 6px);
186
- background: transparent;
187
- color: var(--cl-fg-muted, #a1a1aa);
188
- font-family: var(--cl-ui-sans);
189
- font-size: var(--cl-ui-text-sm);
190
- font-weight: 500;
191
- line-height: 1.35;
192
- cursor: pointer;
193
- transition: background 120ms ease, color 120ms ease;
194
- }
195
-
196
- .cl-settings-cat-btn:hover {
197
- background: var(--cl-list-hover, var(--cl-bg-hover, #1f1f22));
198
- color: var(--cl-fg, #f4f4f5);
199
- }
200
-
201
- .cl-settings-cat-btn[aria-current="true"] {
202
- background: var(--cl-list-active, var(--cl-bg-active, #28282b));
203
- color: var(--cl-list-active-fg, var(--cl-fg, #f4f4f5));
204
- font-weight: 600;
205
- }
206
-
207
- .cl-settings-list {
208
- padding: 14px 24px 28px 20px;
209
- overflow-y: auto;
210
- display: flex;
211
- flex-direction: column;
212
- gap: 8px;
213
- }
214
-
215
- .cl-settings-empty {
216
- padding: 16px 4px;
217
- color: var(--cl-fg-muted, #a1a1aa);
218
- font-size: var(--cl-ui-text-sm);
219
- }
220
-
221
- .cl-setting-item {
222
- padding: 14px 16px;
223
- border: 1px solid var(--cl-border, #27272a);
224
- border-radius: var(--cl-radius-lg, 8px);
225
- background: var(--cl-widget-bg, var(--cl-bg-panel, #18181a));
226
- display: flex;
227
- flex-direction: column;
228
- gap: 6px;
229
- transition: border-color 120ms ease;
230
- }
231
-
232
- .cl-setting-item--modified {
233
- border-color: var(--cl-border-strong, #3a3a3e);
234
- }
235
-
236
- .cl-setting-item__top {
237
- display: flex;
238
- align-items: center;
239
- justify-content: space-between;
240
- gap: 12px;
241
- flex-wrap: wrap;
242
- }
243
-
244
- .cl-setting-item__heading {
245
- display: flex;
246
- align-items: center;
247
- gap: 6px;
248
- flex-wrap: wrap;
249
- min-width: 0;
250
- }
251
-
252
- .cl-setting-item__cat {
253
- font-size: var(--cl-ui-text-xs);
254
- color: var(--cl-fg-muted, #a1a1aa);
255
- font-weight: 500;
256
- }
257
-
258
- .cl-setting-item__title {
259
- font-size: var(--cl-ui-text-sm);
260
- font-weight: 600;
261
- color: var(--cl-fg-active, var(--cl-fg, #f4f4f5));
262
- }
263
-
264
- .cl-setting-item__key {
265
- font-family: var(--cl-ui-mono);
266
- font-size: var(--cl-ui-text-2xs);
267
- padding: 1px 5px;
268
- border-radius: var(--cl-radius-sm, 4px);
269
- border: 1px solid var(--cl-border, #27272a);
270
- background: var(--cl-input-bg, var(--cl-bg, #0f0f10));
271
- color: var(--cl-fg-muted, #a1a1aa);
272
- }
273
-
274
- .cl-setting-badge {
275
- font-family: var(--cl-ui-mono);
276
- font-size: var(--cl-ui-text-2xs);
277
- font-weight: 600;
278
- padding: 1px 6px;
279
- border-radius: 999px;
280
- background: var(--cl-btn-primary-bg, var(--cl-accent, #f4f4f5));
281
- color: var(--cl-btn-primary-fg, var(--cl-accent-fg, #0f0f10));
282
- }
283
-
284
- .cl-setting-item__desc {
285
- font-size: var(--cl-ui-text-xs);
286
- line-height: 1.5;
287
- color: var(--cl-fg-muted, #a1a1aa);
288
- }
289
-
290
- .cl-setting-item__control {
291
- display: flex;
292
- align-items: center;
293
- gap: 8px;
294
- margin-top: 2px;
295
- }
296
-
297
- .cl-ui-btn {
298
- display: inline-flex;
299
- align-items: center;
300
- justify-content: center;
301
- gap: 6px;
302
- height: 28px;
303
- padding: 0 10px;
304
- border-radius: var(--cl-radius-md, 6px);
305
- border: 1px solid var(--cl-input-border, var(--cl-border, #27272a));
306
- background: var(--cl-input-bg, var(--cl-bg, #0f0f10));
307
- color: var(--cl-fg, #f4f4f5);
308
- font-family: var(--cl-ui-sans);
309
- font-size: var(--cl-ui-text-xs);
310
- font-weight: 500;
311
- line-height: 1;
312
- cursor: pointer;
313
- transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
314
- }
315
-
316
- .cl-ui-btn:hover {
317
- background: var(--cl-list-hover, var(--cl-bg-hover, #1f1f22));
318
- border-color: var(--cl-border-strong, #3a3a3e);
319
- }
320
-
321
- .cl-ui-control {
322
- height: 30px;
323
- padding: 0 9px;
324
- border-radius: var(--cl-radius-md, 6px);
325
- border: 1px solid var(--cl-input-border, var(--cl-border, #27272a));
326
- background: var(--cl-input-bg, var(--cl-bg, #0f0f10));
327
- color: var(--cl-fg, #f4f4f5);
328
- font-family: var(--cl-ui-sans);
329
- font-size: var(--cl-ui-text-sm);
330
- outline: none;
331
- transition: border-color 120ms ease;
332
- }
333
-
334
- .cl-ui-control:focus {
335
- border-color: var(--cl-focus-border, #a1a1aa);
336
- }
337
-
338
- .cl-ui-control--num {
339
- width: 104px;
340
- font-family: var(--cl-ui-mono);
341
- font-variant-numeric: tabular-nums;
342
- }
343
-
344
- .cl-ui-control--array {
345
- width: min(280px, 100%);
346
- font-family: var(--cl-ui-mono);
347
- font-size: var(--cl-ui-text-xs);
348
- }
349
-
350
- .cl-ui-control--text {
351
- width: min(200px, 100%);
352
- }
353
-
354
- .cl-ui-checkbox {
355
- width: 16px;
356
- height: 16px;
357
- accent-color: var(--cl-accent, #f4f4f5);
358
- cursor: pointer;
359
- }
360
-
361
- @media (max-width: 640px) {
362
- .cl-settings-body {
363
- grid-template-columns: minmax(0, 1fr);
364
- }
365
- .cl-settings-categories {
366
- flex-direction: row;
367
- border-right: none;
368
- border-bottom: 1px solid var(--cl-border, #27272a);
369
- overflow-x: auto;
370
- }
371
- }
372
- `;
373
-
374
- export function ensureSettingsStylesInjected(doc?: Document): void {
375
- const targetDoc = doc ?? (typeof document !== 'undefined' ? document : undefined);
376
- if (!targetDoc || !targetDoc.head) return;
377
- const existing =
378
- typeof targetDoc.getElementById === 'function'
379
- ? targetDoc.getElementById(SETTINGS_STYLE_ID)
380
- : typeof targetDoc.head.querySelector === 'function'
381
- ? targetDoc.head.querySelector(`#${SETTINGS_STYLE_ID}`)
382
- : null;
383
- if (existing) return;
384
- if (typeof targetDoc.createElement !== 'function') return;
385
- const styleEl = targetDoc.createElement('style');
386
- styleEl.id = SETTINGS_STYLE_ID;
387
- styleEl.textContent = SETTINGS_COMPONENT_CSS;
388
- targetDoc.head.appendChild(styleEl);
389
- }
390
-
391
- function isDomHostElement(candidate: unknown): candidate is HTMLElement {
392
- return Boolean(
393
- candidate &&
394
- typeof candidate === 'object' &&
395
- typeof (candidate as HTMLElement).appendChild === 'function'
396
- );
397
- }
398
-
399
- export class SettingsDialogController implements IDisposable {
400
- private readonly dialogDisposables = new DisposableStore();
401
- private readonly inlineDisposables = new DisposableStore();
402
- private readonly config: IConfigurationService;
403
- private readonly options: SettingsDialogOptions;
404
- private hostRoot: HTMLElement | null = null;
405
- private dialogEl: HTMLDialogElement | null = null;
406
- private inlineRootEl: HTMLElement | null = null;
407
- private runtimeCallbacks: SettingsOpenOptions | undefined;
408
- private inlineCallbacks: SettingsInlineMountOptions | undefined;
409
- private activeScope: SettingsScope;
410
- private activeCategory: 'All' | SettingCategory = 'All';
411
- private searchQuery = '';
412
-
413
- public constructor(hostRoot: HTMLElement, options: SettingsDialogOptions);
414
- public constructor(options: SettingsDialogOptions);
415
- public constructor(
416
- hostRootOrOptions: HTMLElement | SettingsDialogOptions,
417
- maybeOptions?: SettingsDialogOptions
418
- ) {
419
- if (isDomHostElement(hostRootOrOptions) && maybeOptions) {
420
- this.hostRoot = hostRootOrOptions;
421
- this.options = maybeOptions;
422
- this.config = maybeOptions.configuration;
423
- this.activeScope = maybeOptions.scope ?? 'user';
424
- this.mountDialog(hostRootOrOptions);
425
- } else {
426
- const opts = hostRootOrOptions as SettingsDialogOptions;
427
- this.options = opts;
428
- this.config = opts.configuration;
429
- this.activeScope = opts.scope ?? 'user';
430
- }
431
- }
432
-
433
- private buildSurfaceInnerHtml(mode: 'dialog' | 'inline'): string {
434
- const titleId = mode === 'dialog' ? 'cl-settings-dialog-title' : 'cl-settings-inline-title';
435
- const bodyModeClass = mode === 'dialog' ? 'cl-settings-body--dialog' : 'cl-settings-body--inline';
436
- const closeBtnHtml =
437
- mode === 'dialog'
438
- ? `<button type="button" class="codelab-btn cl-ui-btn" data-settings-action="close" aria-label="Close Settings">✕</button>`
439
- : '';
440
-
441
- return (
442
- `<div class="cl-settings-header">` +
443
- `<h2 id="${titleId}" class="cl-settings-title">Settings</h2>` +
444
- `<div class="cl-settings-actions">` +
445
- `<button type="button" class="codelab-btn cl-ui-btn" data-settings-action="open-json" aria-label="Open Settings (JSON)" title="Open .codelab/settings.json">Open Settings (JSON)</button>` +
446
- `<button type="button" class="codelab-btn cl-ui-btn" data-settings-action="reset-all" aria-label="Reset All Settings" title="Reset all settings to defaults">Reset All Settings</button>` +
447
- `<button type="button" class="codelab-btn cl-ui-btn" data-settings-action="export" title="Export Settings JSON">Export</button>` +
448
- closeBtnHtml +
449
- `</div>` +
450
- `</div>` +
451
- `<div class="cl-settings-toolbar">` +
452
- `<input type="search" class="cl-settings-search" data-role="settings-search" aria-label="Search settings" value="${escapeAttr(this.searchQuery)}" placeholder="Search settings…" />` +
453
- `<div role="tablist" aria-label="Settings scope" class="cl-settings-scopes" data-role="settings-scopes"></div>` +
454
- `</div>` +
455
- `<div class="cl-settings-body ${bodyModeClass}">` +
456
- `<nav class="cl-settings-categories" data-role="settings-categories" aria-label="Setting categories"></nav>` +
457
- `<div class="cl-settings-list" data-role="settings-list"></div>` +
458
- `</div>`
459
- );
460
- }
461
-
462
- private getWorkspaceSnapshot(): Record<string, unknown> {
463
- if (typeof this.config.getWorkspaceSettings === 'function') {
464
- return this.config.getWorkspaceSettings();
465
- }
466
- try {
467
- const parsed = JSON.parse(this.config.toWorkspaceJsonString()) as unknown;
468
- if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
469
- return parsed as Record<string, unknown>;
470
- }
471
- } catch (err) {
472
- const _ignored = err;
473
- void _ignored;
474
- }
475
- return {};
476
- }
477
-
478
- private notifyWorkspaceMutated(mode: 'dialog' | 'inline'): void {
479
- const snapshot = this.getWorkspaceSnapshot();
480
- const cb =
481
- mode === 'inline'
482
- ? (this.inlineCallbacks?.onWorkspaceSettingsMutated ??
483
- this.runtimeCallbacks?.onWorkspaceSettingsMutated ??
484
- this.options.onWorkspaceSettingsMutated)
485
- : (this.runtimeCallbacks?.onWorkspaceSettingsMutated ??
486
- this.inlineCallbacks?.onWorkspaceSettingsMutated ??
487
- this.options.onWorkspaceSettingsMutated);
488
- cb?.(snapshot);
489
- }
490
-
491
- private invokeOpenJsonCallback(mode: 'dialog' | 'inline'): void {
492
- const cb =
493
- mode === 'inline'
494
- ? (this.inlineCallbacks?.onOpenJson ??
495
- this.inlineCallbacks?.onOpenSettingsJson ??
496
- this.runtimeCallbacks?.onOpenJson ??
497
- this.runtimeCallbacks?.onOpenSettingsJson ??
498
- this.options.onOpenJson ??
499
- this.options.onOpenSettingsJson)
500
- : (this.runtimeCallbacks?.onOpenJson ??
501
- this.runtimeCallbacks?.onOpenSettingsJson ??
502
- this.inlineCallbacks?.onOpenJson ??
503
- this.inlineCallbacks?.onOpenSettingsJson ??
504
- this.options.onOpenJson ??
505
- this.options.onOpenSettingsJson);
506
- cb?.();
507
- }
508
-
509
- private bindSurfaceEvents(
510
- surfaceEl: HTMLElement,
511
- mode: 'dialog' | 'inline',
512
- store: DisposableStore
513
- ): void {
514
- const searchInput = surfaceEl.querySelector('[data-role="settings-search"]') as HTMLInputElement | null;
515
- if (searchInput) {
516
- const onInput = (): void => {
517
- this.searchQuery = searchInput.value.trim().toLowerCase();
518
- this.renderAllActiveSurfaces('items');
519
- };
520
- searchInput.addEventListener('input', onInput);
521
- store.addFn(() => searchInput.removeEventListener('input', onInput));
522
- }
523
-
524
- const onClick = (evt: Event): void => {
525
- const target = (evt.target as HTMLElement | null)?.closest?.(
526
- '[data-settings-action],[data-settings-cat],[data-settings-scope],[data-reset-key]'
527
- );
528
- if (!target) return;
529
-
530
- const scopeAttr = target.getAttribute('data-settings-scope');
531
- if (scopeAttr === 'user' || scopeAttr === 'workspace') {
532
- if (this.activeScope !== scopeAttr) {
533
- this.activeScope = scopeAttr;
534
- this.renderAllActiveSurfaces('all');
535
- }
536
- return;
537
- }
538
-
539
- const action = target.getAttribute('data-settings-action');
540
- if (action === 'close') {
541
- this.close();
542
- return;
543
- }
544
- if (action === 'open-json') {
545
- if (mode === 'dialog') {
546
- this.close();
547
- }
548
- this.invokeOpenJsonCallback(mode);
549
- return;
550
- }
551
- if (action === 'export') {
552
- this.options.onExportSettings?.(this.config.exportProfile());
553
- return;
554
- }
555
- if (action === 'reset-all') {
556
- const hadWs = Object.keys(this.getWorkspaceSnapshot()).length > 0;
557
- if (this.activeScope === 'workspace') {
558
- void this.config.resetAllSettings('workspace');
559
- this.notifyWorkspaceMutated(mode);
560
- } else {
561
- void this.config.resetAllSettings('all');
562
- if (hadWs) {
563
- this.notifyWorkspaceMutated(mode);
564
- }
565
- }
566
- this.renderAllActiveSurfaces('items');
567
- return;
568
- }
569
-
570
- const cat = target.getAttribute('data-settings-cat') as ('All' | SettingCategory) | null;
571
- if (cat) {
572
- this.activeCategory = cat;
573
- this.renderAllActiveSurfaces('categories-and-items');
574
- return;
575
- }
576
-
577
- const resetKey = target.getAttribute('data-reset-key');
578
- if (resetKey) {
579
- const hadWs = this.config.inspect(resetKey).workspaceValue !== undefined;
580
- if (this.activeScope === 'workspace') {
581
- void this.config.resetScopedSetting(resetKey, 'workspace');
582
- if (hadWs) {
583
- this.notifyWorkspaceMutated(mode);
584
- }
585
- } else {
586
- void this.config.resetScopedSetting(resetKey, 'all');
587
- if (hadWs) {
588
- this.notifyWorkspaceMutated(mode);
589
- }
590
- }
591
- this.renderAllActiveSurfaces('items');
592
- }
593
- };
594
- surfaceEl.addEventListener('click', onClick);
595
- store.addFn(() => surfaceEl.removeEventListener('click', onClick));
596
-
597
- const onChange = (evt: Event): void => {
598
- const el = evt.target as HTMLInputElement | HTMLSelectElement | null;
599
- if (!el || typeof el.getAttribute !== 'function') return;
600
- const key = el.getAttribute('data-setting-key');
601
- if (!key) return;
602
- const desc = this.config.getDescriptors().find((d) => d.key === key);
603
- if (!desc) return;
604
-
605
- let nextValue: unknown;
606
- let hasValidValue = true;
607
-
608
- if (desc.schema.type === 'boolean' && el.getAttribute('type') === 'checkbox') {
609
- nextValue = Boolean((el as HTMLInputElement).checked);
610
- } else if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
611
- const num = Number(el.value);
612
- if (Number.isFinite(num)) {
613
- nextValue = desc.schema.type === 'integer' ? Math.trunc(num) : num;
614
- } else {
615
- hasValidValue = false;
616
- }
617
- } else if (desc.schema.type === 'array') {
618
- nextValue = el.value
619
- .split(',')
620
- .map((s) => s.trim())
621
- .filter(Boolean);
622
- } else {
623
- nextValue = el.value;
624
- }
625
-
626
- if (hasValidValue) {
627
- if (this.activeScope === 'workspace') {
628
- if (this.config.setWorkspaceSetting(key, nextValue)) {
629
- this.notifyWorkspaceMutated(mode);
630
- }
631
- } else {
632
- const hadWorkspaceOverride = this.config.inspect(key).workspaceValue !== undefined;
633
- if (this.config.setUserSetting(key, nextValue) && hadWorkspaceOverride) {
634
- this.config.setWorkspaceSetting(key, nextValue);
635
- this.notifyWorkspaceMutated(mode);
636
- }
637
- }
638
- }
639
- this.renderAllActiveSurfaces('items');
640
- };
641
- surfaceEl.addEventListener('change', onChange);
642
- store.addFn(() => surfaceEl.removeEventListener('change', onChange));
643
-
644
- store.add(
645
- this.config.onDidChangeConfiguration(() => {
646
- if (mode === 'dialog' && this.isOpen && this.dialogEl) {
647
- this.renderItems(this.dialogEl);
648
- } else if (mode === 'inline' && this.isInlineMounted && this.inlineRootEl) {
649
- this.renderItems(this.inlineRootEl);
650
- }
651
- })
652
- );
653
- }
654
-
655
- private mountDialog(hostRoot: HTMLElement): void {
656
- this.dialogDisposables.clear();
657
- this.dialogEl?.remove();
658
- const doc = hostRoot.ownerDocument ?? document;
659
- ensureSettingsStylesInjected(doc);
660
- const dialog = doc.createElement('dialog');
661
- dialog.className = 'codelab-dialog cl-settings-dialog';
662
- dialog.setAttribute('closedby', 'any');
663
- dialog.setAttribute('aria-labelledby', 'cl-settings-dialog-title');
664
- dialog.innerHTML = this.buildSurfaceInnerHtml('dialog');
665
-
666
- hostRoot.appendChild(dialog);
667
- this.dialogEl = dialog;
668
-
669
- const onClose = (): void => {
670
- dialog.returnValue = '';
671
- };
672
- dialog.addEventListener('close', onClose);
673
- this.dialogDisposables.addFn(() => dialog.removeEventListener('close', onClose));
674
-
675
- if (typeof HTMLDialogElement !== 'undefined' && !('closedBy' in HTMLDialogElement.prototype)) {
676
- const onBackdropClick = (evt: MouseEvent): void => {
677
- if (evt.target !== dialog) return;
678
- const rect = dialog.getBoundingClientRect();
679
- const outside =
680
- evt.clientX < rect.left ||
681
- evt.clientX > rect.right ||
682
- evt.clientY < rect.top ||
683
- evt.clientY > rect.bottom;
684
- if (outside) dialog.close();
685
- };
686
- dialog.addEventListener('click', onBackdropClick);
687
- this.dialogDisposables.addFn(() => dialog.removeEventListener('click', onBackdropClick));
688
- }
689
-
690
- this.bindSurfaceEvents(dialog, 'dialog', this.dialogDisposables);
691
- }
692
-
693
- public get isOpen(): boolean {
694
- return Boolean(this.dialogEl && (this.dialogEl.open || this.dialogEl.hasAttribute('open')));
695
- }
696
-
697
- public get isInlineMounted(): boolean {
698
- return Boolean(this.inlineRootEl && this.inlineRootEl.parentNode);
699
- }
700
-
701
- public open(options?: SettingsOpenOptions): void {
702
- if (options?.scope) {
703
- this.activeScope = options.scope;
704
- }
705
- if (options) {
706
- this.runtimeCallbacks = options;
707
- }
708
- if (!this.dialogEl) {
709
- const fallbackHost =
710
- this.hostRoot ?? (typeof document !== 'undefined' ? document.body : null);
711
- if (!fallbackHost) return;
712
- this.hostRoot = fallbackHost;
713
- this.mountDialog(fallbackHost);
714
- }
715
- if (!this.dialogEl) return;
716
- this.renderScopes(this.dialogEl);
717
- this.renderCategories(this.dialogEl);
718
- this.renderItems(this.dialogEl);
719
- if (typeof this.dialogEl.showModal === 'function') {
720
- if (!this.dialogEl.open) this.dialogEl.showModal();
721
- } else {
722
- this.dialogEl.setAttribute('open', '');
723
- }
724
- const searchInput = this.dialogEl.querySelector('[data-role="settings-search"]') as HTMLInputElement | null;
725
- searchInput?.focus();
726
- }
727
-
728
- public close(): void {
729
- if (!this.dialogEl) return;
730
- if (typeof this.dialogEl.close === 'function' && this.dialogEl.open) {
731
- this.dialogEl.close();
732
- } else {
733
- this.dialogEl.removeAttribute('open');
734
- }
735
- }
736
-
737
- public mountInline(container: HTMLElement, options?: SettingsInlineMountOptions): void {
738
- this.unmountInline();
739
- if (options?.scope) {
740
- this.activeScope = options.scope;
741
- }
742
- this.inlineCallbacks = options;
743
-
744
- const doc = container.ownerDocument ?? document;
745
- ensureSettingsStylesInjected(doc);
746
- const root = doc.createElement('div');
747
- root.className = 'cl-settings-editor cl-settings-inline';
748
- root.setAttribute('data-role', 'settings-inline-root');
749
- root.innerHTML = this.buildSurfaceInnerHtml('inline');
750
-
751
- container.appendChild(root);
752
- this.inlineRootEl = root;
753
-
754
- this.bindSurfaceEvents(root, 'inline', this.inlineDisposables);
755
- this.renderScopes(root);
756
- this.renderCategories(root);
757
- this.renderItems(root);
758
- }
759
-
760
- public unmountInline(): void {
761
- this.inlineDisposables.clear();
762
- this.inlineRootEl?.remove();
763
- this.inlineRootEl = null;
764
- }
765
-
766
- private renderAllActiveSurfaces(kind: 'all' | 'categories-and-items' | 'items'): void {
767
- const surfaces: HTMLElement[] = [];
768
- if (this.dialogEl) surfaces.push(this.dialogEl);
769
- if (this.inlineRootEl) surfaces.push(this.inlineRootEl);
770
- for (const root of surfaces) {
771
- if (kind === 'all') {
772
- this.renderScopes(root);
773
- this.renderCategories(root);
774
- this.renderItems(root);
775
- } else if (kind === 'categories-and-items') {
776
- this.renderCategories(root);
777
- this.renderItems(root);
778
- } else {
779
- this.renderItems(root);
780
- }
781
- }
782
- }
783
-
784
- private renderScopes(root: HTMLElement): void {
785
- const scopesEl = root.querySelector('[data-role="settings-scopes"]');
786
- if (!scopesEl) return;
787
- const tabs: ReadonlyArray<{ readonly id: SettingsScope; readonly label: string }> = [
788
- { id: 'user', label: 'User' },
789
- { id: 'workspace', label: 'Workspace (.codelab/settings.json)' }
790
- ];
791
- scopesEl.innerHTML = tabs
792
- .map((tab) => {
793
- const selected = this.activeScope === tab.id;
794
- return (
795
- `<button type="button" role="tab" class="cl-settings-scope-tab" data-settings-scope="${tab.id}" aria-selected="${selected ? 'true' : 'false'}">` +
796
- `${escapeAttr(tab.label)}` +
797
- `</button>`
798
- );
799
- })
800
- .join('');
801
- }
802
-
803
- private renderCategories(root: HTMLElement): void {
804
- const nav = root.querySelector('[data-role="settings-categories"]');
805
- if (!nav) return;
806
- nav.innerHTML = ALL_CATEGORIES.map((cat) => {
807
- const selected = cat === this.activeCategory;
808
- return (
809
- `<button type="button" class="cl-settings-cat-btn" data-settings-cat="${cat}" aria-current="${selected ? 'true' : 'false'}">` +
810
- `${escapeAttr(cat)}` +
811
- `</button>`
812
- );
813
- }).join('');
814
- }
815
-
816
- private renderControl(desc: SettingDescriptor, currentVal: unknown): string {
817
- const keyAttr = escapeAttr(desc.key);
818
- if (desc.schema.enum && desc.schema.enum.length > 0) {
819
- const opts = desc.schema.enum
820
- .map((opt) => {
821
- const str = String(opt);
822
- const sel = String(currentVal) === str ? ' selected' : '';
823
- return `<option value="${escapeAttr(str)}"${sel}>${escapeAttr(str)}</option>`;
824
- })
825
- .join('');
826
- return `<select class="cl-ui-control" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}">${opts}</select>`;
827
- }
828
- if (desc.schema.type === 'boolean') {
829
- const checked = Boolean(currentVal) ? ' checked' : '';
830
- return `<input type="checkbox" class="cl-ui-checkbox" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}"${checked} />`;
831
- }
832
- if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
833
- const min = desc.schema.minimum !== undefined ? ` min="${desc.schema.minimum}"` : '';
834
- const max = desc.schema.maximum !== undefined ? ` max="${desc.schema.maximum}"` : '';
835
- return `<input type="number" class="cl-ui-control cl-ui-control--num" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(String(currentVal ?? ''))}"${min}${max} />`;
836
- }
837
- if (desc.schema.type === 'array') {
838
- const joined = Array.isArray(currentVal) ? currentVal.join(', ') : '';
839
- return `<input type="text" class="cl-ui-control cl-ui-control--array" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(joined)}" />`;
840
- }
841
- return `<input type="text" class="cl-ui-control cl-ui-control--text" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(String(currentVal ?? ''))}" />`;
842
- }
843
-
844
- private renderItems(root: HTMLElement): void {
845
- const listEl = root.querySelector('[data-role="settings-list"]');
846
- if (!listEl) return;
847
- const descriptors = this.config.getDescriptors().filter((d) => {
848
- if (this.activeCategory !== 'All' && d.category !== this.activeCategory) return false;
849
- if (!this.searchQuery) return true;
850
- const hay = `${d.key} ${d.title} ${d.description} ${d.category}`.toLowerCase();
851
- return hay.includes(this.searchQuery);
852
- });
853
-
854
- if (descriptors.length === 0) {
855
- listEl.innerHTML = `<div class="cl-settings-empty">No matching settings found.</div>`;
856
- return;
857
- }
858
-
859
- listEl.innerHTML = descriptors
860
- .map((desc) => {
861
- const insp = this.config.inspect(desc.key);
862
- const displayedVal =
863
- this.activeScope === 'workspace'
864
- ? (insp.workspaceValue !== undefined ? insp.workspaceValue : insp.effectiveValue)
865
- : insp.effectiveValue;
866
- const canReset =
867
- this.activeScope === 'workspace'
868
- ? insp.workspaceValue !== undefined
869
- : insp.effectiveSource !== 'default' || insp.userValue !== undefined;
870
- const badgeLabel =
871
- this.activeScope === 'workspace'
872
- ? (insp.workspaceValue !== undefined ? 'workspace' : '')
873
- : (insp.effectiveSource !== 'default' ? insp.effectiveSource : '');
874
-
875
- const modClass = canReset ? ' cl-setting-item--modified' : '';
876
-
877
- return (
878
- `<div class="cl-setting-item${modClass}" data-setting-row="${escapeAttr(desc.key)}">` +
879
- `<div class="cl-setting-item__top">` +
880
- `<div class="cl-setting-item__heading">` +
881
- `<span class="cl-setting-item__cat">${escapeAttr(desc.category)}:</span>` +
882
- `<strong class="cl-setting-item__title">${escapeAttr(desc.title)}</strong>` +
883
- `<code class="cl-setting-item__key">${escapeAttr(desc.key)}</code>` +
884
- (badgeLabel
885
- ? `<span class="cl-setting-badge" data-role="setting-badge">${escapeAttr(badgeLabel)}</span>`
886
- : '') +
887
- `</div>` +
888
- (canReset
889
- ? `<button type="button" class="codelab-btn cl-ui-btn" data-reset-key="${escapeAttr(desc.key)}" title="Reset to Default (${escapeAttr(JSON.stringify(desc.defaultValue))})">Reset</button>`
890
- : '') +
891
- `</div>` +
892
- `<div class="cl-setting-item__desc">${escapeAttr(desc.description)}</div>` +
893
- `<div class="cl-setting-item__control">` +
894
- this.renderControl(desc, displayedVal) +
895
- `</div>` +
896
- `</div>`
897
- );
898
- })
899
- .join('');
900
- }
901
-
902
- public dispose(): void {
903
- this.close();
904
- this.unmountInline();
905
- this.dialogDisposables.dispose();
906
- this.inlineDisposables.dispose();
907
- this.dialogEl?.remove();
908
- this.dialogEl = null;
909
- this.hostRoot = null;
910
- }
911
- }