@innovatorved/code-lab 0.7.0 → 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 (129) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +20 -0
  3. package/README.md +2 -2
  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 +1 -1
  9. package/dist/code-lab.esm.js +679 -1439
  10. package/dist/code-lab.js +678 -1438
  11. package/dist/extensions/cpp.esm.js +132 -8760
  12. package/dist/extensions/cpp.js +124 -8770
  13. package/dist/extensions/guided-lab.esm.js +33 -6836
  14. package/dist/extensions/guided-lab.js +33 -6854
  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 -8118
  18. package/dist/extensions/python.js +79 -8136
  19. package/dist/extensions/typescript.esm.js +1 -55
  20. package/dist/extensions/typescript.js +1 -77
  21. package/dist/modular-kernel.d.ts +0 -4
  22. package/dist/preview-sw.js +1 -1
  23. package/dist/runtime.esm.js +77 -77
  24. package/dist/runtime.js +77 -77
  25. package/dist/schemas.d.ts +9 -0
  26. package/dist/schemas.esm.js +33 -6815
  27. package/dist/schemas.js +33 -6831
  28. package/dist/shell.esm.js +33 -33
  29. package/dist/shell.js +33 -33
  30. package/dist/terminal.esm.js +8 -6
  31. package/dist/terminal.js +6 -6
  32. package/dist/workbench/command-palette.d.ts +0 -4
  33. package/dist/workbench/index.d.ts +0 -20
  34. package/dist/workbench/intellisense.d.ts +1 -7
  35. package/package.json +3 -10
  36. package/src/code-lab.css +4 -502
  37. package/src/extensions/cpp.ts +11 -29
  38. package/src/extensions/guided-lab.ts +6 -2
  39. package/src/extensions/python.ts +9 -3
  40. package/src/modular-kernel.ts +0 -4
  41. package/src/runtime.ts +124 -39
  42. package/src/schemas.ts +2 -2
  43. package/src/shell.ts +3 -0
  44. package/src/terminal.ts +4 -2
  45. package/src/workbench/command-palette.ts +22 -302
  46. package/src/workbench/diff-editor.ts +2 -0
  47. package/src/workbench/icons.ts +1 -1
  48. package/src/workbench/index.ts +0 -15
  49. package/src/workbench/intellisense.ts +17 -4
  50. package/src/workbench.ts +68 -375
  51. package/dist/code-lab.umd.js +0 -6117
  52. package/dist/packages/editor/src/index.d.ts +0 -118
  53. package/dist/packages/preview/src/index.d.ts +0 -34
  54. package/dist/packages/runtime/src/index.d.ts +0 -47
  55. package/dist/packages/terminal/src/index.d.ts +0 -54
  56. package/dist/workbench/drawer.d.ts +0 -18
  57. package/dist/workbench/file-tree.d.ts +0 -11
  58. package/dist/workbench/guided-pane.d.ts +0 -11
  59. package/dist/workbench/styles.d.ts +0 -4
  60. package/dist/workbench/toolbar.d.ts +0 -17
  61. package/packages/commands/README.md +0 -7
  62. package/packages/commands/package.json +0 -16
  63. package/packages/commands/src/index.ts +0 -467
  64. package/packages/commands/tsconfig.json +0 -22
  65. package/packages/core/README.md +0 -12
  66. package/packages/core/package.json +0 -13
  67. package/packages/core/src/di.ts +0 -147
  68. package/packages/core/src/disposable.ts +0 -112
  69. package/packages/core/src/errors.ts +0 -205
  70. package/packages/core/src/events.ts +0 -157
  71. package/packages/core/src/index.ts +0 -49
  72. package/packages/core/src/path.ts +0 -118
  73. package/packages/core/src/registry.ts +0 -61
  74. package/packages/core/tsconfig.json +0 -19
  75. package/packages/editor/README.md +0 -9
  76. package/packages/editor/package.json +0 -18
  77. package/packages/editor/src/index.ts +0 -344
  78. package/packages/editor/tsconfig.json +0 -24
  79. package/packages/fs/README.md +0 -7
  80. package/packages/fs/package.json +0 -16
  81. package/packages/fs/src/backends.ts +0 -301
  82. package/packages/fs/src/index.ts +0 -18
  83. package/packages/fs/src/types.ts +0 -44
  84. package/packages/fs/src/vfs-service.ts +0 -257
  85. package/packages/fs/tsconfig.json +0 -22
  86. package/packages/preview/README.md +0 -3
  87. package/packages/preview/package.json +0 -16
  88. package/packages/preview/src/index.ts +0 -125
  89. package/packages/preview/tsconfig.json +0 -22
  90. package/packages/runtime/README.md +0 -3
  91. package/packages/runtime/package.json +0 -17
  92. package/packages/runtime/src/index.ts +0 -134
  93. package/packages/runtime/tsconfig.json +0 -23
  94. package/packages/settings/README.md +0 -7
  95. package/packages/settings/package.json +0 -16
  96. package/packages/settings/src/builtin-schemas.ts +0 -262
  97. package/packages/settings/src/configuration-service.ts +0 -609
  98. package/packages/settings/src/index.ts +0 -38
  99. package/packages/settings/src/jsonc.ts +0 -189
  100. package/packages/settings/src/schema.ts +0 -164
  101. package/packages/settings/tsconfig.json +0 -22
  102. package/packages/sql/README.md +0 -12
  103. package/packages/sql/package.json +0 -13
  104. package/packages/sql/src/completions.ts +0 -359
  105. package/packages/sql/src/diagnostics.ts +0 -200
  106. package/packages/sql/src/formatter.ts +0 -271
  107. package/packages/sql/src/index.ts +0 -54
  108. package/packages/sql/src/sql-editor.ts +0 -802
  109. package/packages/sql/src/styles.ts +0 -524
  110. package/packages/sql/src/tokenizer.ts +0 -457
  111. package/packages/sql/src/types.ts +0 -148
  112. package/packages/sql/tsconfig.json +0 -19
  113. package/packages/terminal/README.md +0 -3
  114. package/packages/terminal/package.json +0 -16
  115. package/packages/terminal/src/index.ts +0 -183
  116. package/packages/terminal/tsconfig.json +0 -22
  117. package/packages/ui/README.md +0 -8
  118. package/packages/ui/package.json +0 -18
  119. package/packages/ui/src/index.ts +0 -40
  120. package/packages/ui/src/observability.ts +0 -173
  121. package/packages/ui/src/plugin-registry.ts +0 -289
  122. package/packages/ui/src/settings-dialog.ts +0 -939
  123. package/packages/ui/src/themes.ts +0 -333
  124. package/packages/ui/tsconfig.json +0 -24
  125. package/src/workbench/drawer.ts +0 -157
  126. package/src/workbench/file-tree.ts +0 -51
  127. package/src/workbench/guided-pane.ts +0 -43
  128. package/src/workbench/styles.ts +0 -211
  129. package/src/workbench/toolbar.ts +0 -182
@@ -1,939 +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
- let applied = false;
627
- if (hasValidValue) {
628
- if (this.activeScope === 'workspace') {
629
- applied = this.config.setWorkspaceSetting(key, nextValue);
630
- if (applied) {
631
- this.notifyWorkspaceMutated(mode);
632
- }
633
- } else {
634
- const hadWorkspaceOverride = this.config.inspect(key).workspaceValue !== undefined;
635
- applied = this.config.setUserSetting(key, nextValue);
636
- if (applied && hadWorkspaceOverride) {
637
- this.config.setWorkspaceSetting(key, nextValue);
638
- this.notifyWorkspaceMutated(mode);
639
- }
640
- }
641
- }
642
- if (!applied) {
643
- const min = desc.schema.minimum;
644
- const max = desc.schema.maximum;
645
- const rangeHint =
646
- min !== undefined && max !== undefined
647
- ? `Value must be between ${min} and ${max}.`
648
- : min !== undefined
649
- ? `Value must be at least ${min}.`
650
- : max !== undefined
651
- ? `Value must be at most ${max}.`
652
- : 'Invalid setting value.';
653
- if ('setCustomValidity' in el && typeof (el as HTMLInputElement).setCustomValidity === 'function') {
654
- (el as HTMLInputElement).setCustomValidity(rangeHint);
655
- if (typeof (el as HTMLInputElement).reportValidity === 'function') {
656
- (el as HTMLInputElement).reportValidity();
657
- }
658
- (el as HTMLInputElement).setCustomValidity('');
659
- }
660
- }
661
- this.renderAllActiveSurfaces('items');
662
- };
663
- surfaceEl.addEventListener('change', onChange);
664
- store.addFn(() => surfaceEl.removeEventListener('change', onChange));
665
-
666
- store.add(
667
- this.config.onDidChangeConfiguration(() => {
668
- if (mode === 'dialog' && this.isOpen && this.dialogEl) {
669
- this.renderItems(this.dialogEl);
670
- } else if (mode === 'inline' && this.isInlineMounted && this.inlineRootEl) {
671
- this.renderItems(this.inlineRootEl);
672
- }
673
- })
674
- );
675
- }
676
-
677
- private mountDialog(hostRoot: HTMLElement): void {
678
- this.dialogDisposables.clear();
679
- this.dialogEl?.remove();
680
- const doc = hostRoot.ownerDocument ?? document;
681
- ensureSettingsStylesInjected(doc);
682
- const dialog = doc.createElement('dialog');
683
- dialog.className = 'codelab-dialog cl-settings-dialog';
684
- dialog.setAttribute('closedby', 'any');
685
- dialog.setAttribute('aria-labelledby', 'cl-settings-dialog-title');
686
- dialog.innerHTML = this.buildSurfaceInnerHtml('dialog');
687
-
688
- hostRoot.appendChild(dialog);
689
- this.dialogEl = dialog;
690
-
691
- const onClose = (): void => {
692
- dialog.returnValue = '';
693
- };
694
- dialog.addEventListener('close', onClose);
695
- this.dialogDisposables.addFn(() => dialog.removeEventListener('close', onClose));
696
-
697
- if (typeof HTMLDialogElement !== 'undefined' && !('closedBy' in HTMLDialogElement.prototype)) {
698
- const onBackdropClick = (evt: MouseEvent): void => {
699
- if (evt.target !== dialog) return;
700
- const rect = dialog.getBoundingClientRect();
701
- const outside =
702
- evt.clientX < rect.left ||
703
- evt.clientX > rect.right ||
704
- evt.clientY < rect.top ||
705
- evt.clientY > rect.bottom;
706
- if (outside) dialog.close();
707
- };
708
- dialog.addEventListener('click', onBackdropClick);
709
- this.dialogDisposables.addFn(() => dialog.removeEventListener('click', onBackdropClick));
710
- }
711
-
712
- this.bindSurfaceEvents(dialog, 'dialog', this.dialogDisposables);
713
- }
714
-
715
- public get isOpen(): boolean {
716
- return Boolean(this.dialogEl && (this.dialogEl.open || this.dialogEl.hasAttribute('open')));
717
- }
718
-
719
- public get isInlineMounted(): boolean {
720
- return Boolean(this.inlineRootEl && this.inlineRootEl.parentNode);
721
- }
722
-
723
- public open(options?: SettingsOpenOptions): void {
724
- if (options?.scope) {
725
- this.activeScope = options.scope;
726
- }
727
- if (options) {
728
- this.runtimeCallbacks = options;
729
- }
730
- if (!this.dialogEl) {
731
- const fallbackHost =
732
- this.hostRoot ?? (typeof document !== 'undefined' ? document.body : null);
733
- if (!fallbackHost) return;
734
- this.hostRoot = fallbackHost;
735
- this.mountDialog(fallbackHost);
736
- }
737
- if (!this.dialogEl) return;
738
- this.renderScopes(this.dialogEl);
739
- this.renderCategories(this.dialogEl);
740
- this.renderItems(this.dialogEl);
741
- if (typeof this.dialogEl.showModal === 'function') {
742
- if (!this.dialogEl.open) this.dialogEl.showModal();
743
- } else {
744
- this.dialogEl.setAttribute('open', '');
745
- }
746
- const searchInput = this.dialogEl.querySelector('[data-role="settings-search"]') as HTMLInputElement | null;
747
- searchInput?.focus();
748
- }
749
-
750
- public close(): void {
751
- if (!this.dialogEl) return;
752
- if (typeof this.dialogEl.close === 'function' && this.dialogEl.open) {
753
- this.dialogEl.close();
754
- } else {
755
- this.dialogEl.removeAttribute('open');
756
- }
757
- }
758
-
759
- public mountInline(container: HTMLElement, options?: SettingsInlineMountOptions): void {
760
- this.unmountInline();
761
- if (options?.scope) {
762
- this.activeScope = options.scope;
763
- }
764
- this.inlineCallbacks = options;
765
-
766
- const doc = container.ownerDocument ?? document;
767
- ensureSettingsStylesInjected(doc);
768
- const root = doc.createElement('div');
769
- root.className = 'cl-settings-editor cl-settings-inline';
770
- root.setAttribute('data-role', 'settings-inline-root');
771
- root.innerHTML = this.buildSurfaceInnerHtml('inline');
772
-
773
- container.appendChild(root);
774
- this.inlineRootEl = root;
775
-
776
- this.bindSurfaceEvents(root, 'inline', this.inlineDisposables);
777
- this.renderScopes(root);
778
- this.renderCategories(root);
779
- this.renderItems(root);
780
- }
781
-
782
- public unmountInline(): void {
783
- this.inlineDisposables.clear();
784
- this.inlineRootEl?.remove();
785
- this.inlineRootEl = null;
786
- }
787
-
788
- private renderAllActiveSurfaces(kind: 'all' | 'categories-and-items' | 'items'): void {
789
- const surfaces: HTMLElement[] = [];
790
- if (this.dialogEl) surfaces.push(this.dialogEl);
791
- if (this.inlineRootEl) surfaces.push(this.inlineRootEl);
792
- for (const root of surfaces) {
793
- if (kind === 'all') {
794
- this.renderScopes(root);
795
- this.renderCategories(root);
796
- this.renderItems(root);
797
- } else if (kind === 'categories-and-items') {
798
- this.renderCategories(root);
799
- this.renderItems(root);
800
- } else {
801
- this.renderItems(root);
802
- }
803
- }
804
- }
805
-
806
- private renderScopes(root: HTMLElement): void {
807
- const scopesEl = root.querySelector('[data-role="settings-scopes"]');
808
- if (!scopesEl) return;
809
- const tabs: ReadonlyArray<{ readonly id: SettingsScope; readonly label: string }> = [
810
- { id: 'user', label: 'User' },
811
- { id: 'workspace', label: 'Workspace (.codelab/settings.json)' }
812
- ];
813
- scopesEl.innerHTML = tabs
814
- .map((tab) => {
815
- const selected = this.activeScope === tab.id;
816
- return (
817
- `<button type="button" role="tab" class="cl-settings-scope-tab" data-settings-scope="${tab.id}" aria-selected="${selected ? 'true' : 'false'}">` +
818
- `${escapeAttr(tab.label)}` +
819
- `</button>`
820
- );
821
- })
822
- .join('');
823
- }
824
-
825
- private renderCategories(root: HTMLElement): void {
826
- const nav = root.querySelector('[data-role="settings-categories"]');
827
- if (!nav) return;
828
- nav.innerHTML = ALL_CATEGORIES.map((cat) => {
829
- const selected = cat === this.activeCategory;
830
- return (
831
- `<button type="button" class="cl-settings-cat-btn" data-settings-cat="${cat}" aria-current="${selected ? 'true' : 'false'}">` +
832
- `${escapeAttr(cat)}` +
833
- `</button>`
834
- );
835
- }).join('');
836
- }
837
-
838
- private renderControl(desc: SettingDescriptor, currentVal: unknown): string {
839
- const keyAttr = escapeAttr(desc.key);
840
- if (desc.schema.enum && desc.schema.enum.length > 0) {
841
- const opts = desc.schema.enum
842
- .map((opt) => {
843
- const str = String(opt);
844
- const sel = String(currentVal) === str ? ' selected' : '';
845
- return `<option value="${escapeAttr(str)}"${sel}>${escapeAttr(str)}</option>`;
846
- })
847
- .join('');
848
- return `<select class="cl-ui-control" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}">${opts}</select>`;
849
- }
850
- if (desc.schema.type === 'boolean') {
851
- const checked = Boolean(currentVal) ? ' checked' : '';
852
- return `<input type="checkbox" class="cl-ui-checkbox" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}"${checked} />`;
853
- }
854
- if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
855
- const min = desc.schema.minimum !== undefined ? ` min="${desc.schema.minimum}"` : '';
856
- const max = desc.schema.maximum !== undefined ? ` max="${desc.schema.maximum}"` : '';
857
- 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} />`;
858
- }
859
- if (desc.schema.type === 'array') {
860
- const joined = Array.isArray(currentVal) ? currentVal.join(', ') : '';
861
- return `<input type="text" class="cl-ui-control cl-ui-control--array" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(joined)}" />`;
862
- }
863
- 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 ?? ''))}" />`;
864
- }
865
-
866
- private renderItems(root: HTMLElement): void {
867
- const listEl = root.querySelector('[data-role="settings-list"]');
868
- if (!listEl) return;
869
- const descriptors = this.config.getDescriptors().filter((d) => {
870
- if (this.activeCategory !== 'All' && d.category !== this.activeCategory) return false;
871
- if (!this.searchQuery) return true;
872
- const hay = `${d.key} ${d.title} ${d.description} ${d.category}`.toLowerCase();
873
- return hay.includes(this.searchQuery);
874
- });
875
-
876
- if (descriptors.length === 0) {
877
- listEl.innerHTML = `<div class="cl-settings-empty">No matching settings found.</div>`;
878
- return;
879
- }
880
-
881
- listEl.innerHTML = descriptors
882
- .map((desc) => {
883
- const insp = this.config.inspect(desc.key);
884
- const displayedVal =
885
- this.activeScope === 'workspace'
886
- ? (insp.workspaceValue !== undefined ? insp.workspaceValue : insp.effectiveValue)
887
- : insp.effectiveValue;
888
- const canReset =
889
- this.activeScope === 'workspace'
890
- ? insp.workspaceValue !== undefined
891
- : insp.effectiveSource !== 'default' || insp.userValue !== undefined;
892
- const badgeLabel =
893
- this.activeScope === 'workspace'
894
- ? (insp.workspaceValue !== undefined ? 'workspace' : '')
895
- : (insp.effectiveSource !== 'default' ? insp.effectiveSource : '');
896
-
897
- const hasWorkspaceOverrideNotice =
898
- this.activeScope === 'user' && insp.workspaceValue !== undefined;
899
-
900
- const modClass = canReset ? ' cl-setting-item--modified' : '';
901
-
902
- return (
903
- `<div class="cl-setting-item${modClass}" data-setting-row="${escapeAttr(desc.key)}">` +
904
- `<div class="cl-setting-item__top">` +
905
- `<div class="cl-setting-item__heading">` +
906
- `<span class="cl-setting-item__cat">${escapeAttr(desc.category)}:</span>` +
907
- `<strong class="cl-setting-item__title">${escapeAttr(desc.title)}</strong>` +
908
- `<code class="cl-setting-item__key">${escapeAttr(desc.key)}</code>` +
909
- (badgeLabel
910
- ? `<span class="cl-setting-badge" data-role="setting-badge">${escapeAttr(badgeLabel)}</span>`
911
- : '') +
912
- (hasWorkspaceOverrideNotice
913
- ? `<span class="cl-setting-badge" data-role="setting-workspace-override" title="Overridden in .codelab/settings.json">Modified in Workspace</span>`
914
- : '') +
915
- `</div>` +
916
- (canReset
917
- ? `<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>`
918
- : '') +
919
- `</div>` +
920
- `<div class="cl-setting-item__desc">${escapeAttr(desc.description)}</div>` +
921
- `<div class="cl-setting-item__control">` +
922
- this.renderControl(desc, displayedVal) +
923
- `</div>` +
924
- `</div>`
925
- );
926
- })
927
- .join('');
928
- }
929
-
930
- public dispose(): void {
931
- this.close();
932
- this.unmountInline();
933
- this.dialogDisposables.dispose();
934
- this.inlineDisposables.dispose();
935
- this.dialogEl?.remove();
936
- this.dialogEl = null;
937
- this.hostRoot = null;
938
- }
939
- }