@innovatorved/code-lab 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +5 -3
- package/CHANGELOG.md +41 -0
- package/README.md +53 -175
- package/dist/apps/web/src/index.d.ts +34 -0
- package/dist/code-lab-sql.css +482 -0
- package/dist/code-lab-sql.d.ts +179 -0
- package/dist/code-lab-sql.esm.js +542 -0
- package/dist/code-lab-sql.umd.js +531 -0
- package/dist/code-lab.css +1799 -98
- package/dist/code-lab.d.ts +110 -15
- package/dist/code-lab.esm.js +49678 -23253
- package/dist/code-lab.js +49648 -23251
- package/dist/code-lab.umd.js +75766 -0
- package/dist/diagnostics.d.ts +3 -0
- package/dist/extensions/cpp.esm.js +19504 -3788
- package/dist/extensions/cpp.js +19501 -3785
- package/dist/extensions/guided-lab.esm.js +19401 -3725
- package/dist/extensions/guided-lab.js +19400 -3724
- package/dist/extensions/python.d.ts +1 -0
- package/dist/extensions/python.esm.js +19597 -3788
- package/dist/extensions/python.js +19597 -3788
- package/dist/extensions/umbrella.d.ts +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/modular-kernel.d.ts +11 -0
- package/dist/packages/commands/src/index.d.ts +96 -0
- package/dist/packages/core/src/di.d.ts +36 -0
- package/dist/packages/core/src/disposable.d.ts +27 -0
- package/dist/packages/core/src/errors.d.ts +69 -0
- package/dist/packages/core/src/events.d.ts +38 -0
- package/dist/packages/core/src/index.d.ts +6 -0
- package/dist/packages/core/src/path.d.ts +14 -0
- package/dist/packages/core/src/registry.d.ts +23 -0
- package/dist/packages/editor/src/index.d.ts +118 -0
- package/dist/packages/fs/src/backends.d.ts +37 -0
- package/dist/packages/fs/src/index.d.ts +3 -0
- package/dist/packages/fs/src/types.d.ts +40 -0
- package/dist/packages/fs/src/vfs-service.d.ts +33 -0
- package/dist/packages/preview/src/index.d.ts +34 -0
- package/dist/packages/runtime/src/index.d.ts +47 -0
- package/dist/packages/settings/src/builtin-schemas.d.ts +15 -0
- package/dist/packages/settings/src/configuration-service.d.ts +107 -0
- package/dist/packages/settings/src/index.d.ts +4 -0
- package/dist/packages/settings/src/jsonc.d.ts +20 -0
- package/dist/packages/settings/src/schema.d.ts +28 -0
- package/dist/packages/sql/src/completions.d.ts +8 -0
- package/dist/packages/sql/src/diagnostics.d.ts +2 -0
- package/dist/packages/sql/src/formatter.d.ts +2 -0
- package/dist/packages/sql/src/index.d.ts +7 -0
- package/dist/packages/sql/src/sql-editor.d.ts +2 -0
- package/dist/packages/sql/src/styles.d.ts +2 -0
- package/dist/packages/sql/src/tokenizer.d.ts +13 -0
- package/dist/packages/sql/src/types.d.ts +130 -0
- package/dist/packages/terminal/src/index.d.ts +54 -0
- package/dist/packages/ui/src/index.d.ts +4 -0
- package/dist/packages/ui/src/observability.d.ts +22 -0
- package/dist/packages/ui/src/plugin-registry.d.ts +90 -0
- package/dist/packages/ui/src/settings-dialog.d.ts +53 -0
- package/dist/packages/ui/src/themes.d.ts +40 -0
- package/dist/preview-sw.js +53 -12
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.esm.js +467 -44
- package/dist/runtime.js +465 -44
- package/dist/schemas.d.ts +234 -814
- package/dist/schemas.esm.js +19401 -3725
- package/dist/schemas.js +19404 -3728
- package/dist/scm.d.ts +92 -11
- package/dist/shell.d.ts +1 -1
- package/dist/shell.esm.js +1300 -151
- package/dist/shell.js +1300 -151
- package/dist/storage.d.ts +47 -0
- package/dist/terminal.esm.js +62 -3
- package/dist/terminal.js +62 -3
- package/dist/workbench/diff-editor.d.ts +1 -0
- package/dist/workbench/index.d.ts +1 -1
- package/dist/workbench/styles.d.ts +1 -1
- package/package.json +38 -9
- package/packages/commands/README.md +7 -0
- package/packages/commands/package.json +16 -0
- package/packages/commands/src/index.ts +467 -0
- package/packages/commands/tsconfig.json +22 -0
- package/packages/core/README.md +12 -0
- package/packages/core/package.json +13 -0
- package/packages/core/src/di.ts +147 -0
- package/packages/core/src/disposable.ts +112 -0
- package/packages/core/src/errors.ts +205 -0
- package/packages/core/src/events.ts +157 -0
- package/packages/core/src/index.ts +49 -0
- package/packages/core/src/path.ts +118 -0
- package/packages/core/src/registry.ts +61 -0
- package/packages/core/tsconfig.json +19 -0
- package/packages/editor/README.md +9 -0
- package/packages/editor/package.json +18 -0
- package/packages/editor/src/index.ts +344 -0
- package/packages/editor/tsconfig.json +24 -0
- package/packages/fs/README.md +7 -0
- package/packages/fs/package.json +16 -0
- package/packages/fs/src/backends.ts +301 -0
- package/packages/fs/src/index.ts +18 -0
- package/packages/fs/src/types.ts +44 -0
- package/packages/fs/src/vfs-service.ts +257 -0
- package/packages/fs/tsconfig.json +22 -0
- package/packages/preview/README.md +3 -0
- package/packages/preview/package.json +16 -0
- package/packages/preview/src/index.ts +125 -0
- package/packages/preview/tsconfig.json +22 -0
- package/packages/runtime/README.md +3 -0
- package/packages/runtime/package.json +17 -0
- package/packages/runtime/src/index.ts +134 -0
- package/packages/runtime/tsconfig.json +23 -0
- package/packages/settings/README.md +7 -0
- package/packages/settings/package.json +16 -0
- package/packages/settings/src/builtin-schemas.ts +246 -0
- package/packages/settings/src/configuration-service.ts +609 -0
- package/packages/settings/src/index.ts +38 -0
- package/packages/settings/src/jsonc.ts +189 -0
- package/packages/settings/src/schema.ts +164 -0
- package/packages/settings/tsconfig.json +22 -0
- package/packages/sql/README.md +12 -0
- package/packages/sql/package.json +13 -0
- package/packages/sql/src/completions.ts +359 -0
- package/packages/sql/src/diagnostics.ts +200 -0
- package/packages/sql/src/formatter.ts +271 -0
- package/packages/sql/src/index.ts +54 -0
- package/packages/sql/src/sql-editor.ts +802 -0
- package/packages/sql/src/styles.ts +501 -0
- package/packages/sql/src/tokenizer.ts +457 -0
- package/packages/sql/src/types.ts +148 -0
- package/packages/sql/tsconfig.json +19 -0
- package/packages/terminal/README.md +3 -0
- package/packages/terminal/package.json +16 -0
- package/packages/terminal/src/index.ts +183 -0
- package/packages/terminal/tsconfig.json +22 -0
- package/packages/ui/README.md +8 -0
- package/packages/ui/package.json +18 -0
- package/packages/ui/src/index.ts +40 -0
- package/packages/ui/src/observability.ts +175 -0
- package/packages/ui/src/plugin-registry.ts +289 -0
- package/packages/ui/src/settings-dialog.ts +575 -0
- package/packages/ui/src/themes.ts +267 -0
- package/packages/ui/tsconfig.json +24 -0
- package/src/code-lab.css +1799 -98
- package/src/diagnostics.ts +139 -7
- package/src/extensions/cpp.ts +88 -45
- package/src/extensions/python.ts +186 -53
- package/src/extensions/umbrella.ts +5 -0
- package/src/index.ts +1 -1
- package/src/modular-kernel.ts +11 -0
- package/src/preview-sw.js +52 -11
- package/src/runtime.ts +466 -46
- package/src/schemas.ts +62 -62
- package/src/scm.ts +781 -58
- package/src/shell.ts +1299 -151
- package/src/storage.ts +336 -3
- package/src/terminal.ts +60 -2
- package/src/workbench/diff-editor.ts +66 -6
- package/src/workbench/icons.ts +12 -2
- package/src/workbench/styles.ts +25 -19
- package/src/workbench.ts +17059 -6673
- package/dist/runtime/index.d.ts +0 -4
- package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
- package/dist/shell/index.d.ts +0 -4
- package/src/runtime/index.ts +0 -5
- package/src/shell/coreutils/compilers-cli.ts +0 -103
- package/src/shell/index.ts +0 -5
|
@@ -0,0 +1,575 @@
|
|
|
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, '<')
|
|
8
|
+
.replace(/>/g, '>')
|
|
9
|
+
.replace(/"/g, '"');
|
|
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 BTN_STYLE =
|
|
45
|
+
'padding:5px 10px;border-radius:5px;border:1px solid var(--cl-border,#262626);background:var(--cl-surface,#0a0a0a);color:var(--cl-fg,#f5f5f5);cursor:pointer;font-size:12px;';
|
|
46
|
+
|
|
47
|
+
const CONTROL_STYLE =
|
|
48
|
+
'padding:5px 8px;border-radius:5px;border:1px solid var(--cl-border,#262626);background:var(--cl-surface,#0a0a0a);color:var(--cl-fg,#f5f5f5);font-size:12.5px;';
|
|
49
|
+
|
|
50
|
+
function isDomHostElement(candidate: unknown): candidate is HTMLElement {
|
|
51
|
+
return Boolean(
|
|
52
|
+
candidate &&
|
|
53
|
+
typeof candidate === 'object' &&
|
|
54
|
+
typeof (candidate as HTMLElement).appendChild === 'function'
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class SettingsDialogController implements IDisposable {
|
|
59
|
+
private readonly dialogDisposables = new DisposableStore();
|
|
60
|
+
private readonly inlineDisposables = new DisposableStore();
|
|
61
|
+
private readonly config: IConfigurationService;
|
|
62
|
+
private readonly options: SettingsDialogOptions;
|
|
63
|
+
private hostRoot: HTMLElement | null = null;
|
|
64
|
+
private dialogEl: HTMLDialogElement | null = null;
|
|
65
|
+
private inlineRootEl: HTMLElement | null = null;
|
|
66
|
+
private runtimeCallbacks: SettingsOpenOptions | undefined;
|
|
67
|
+
private inlineCallbacks: SettingsInlineMountOptions | undefined;
|
|
68
|
+
private activeScope: SettingsScope;
|
|
69
|
+
private activeCategory: 'All' | SettingCategory = 'All';
|
|
70
|
+
private searchQuery = '';
|
|
71
|
+
|
|
72
|
+
public constructor(hostRoot: HTMLElement, options: SettingsDialogOptions);
|
|
73
|
+
public constructor(options: SettingsDialogOptions);
|
|
74
|
+
public constructor(
|
|
75
|
+
hostRootOrOptions: HTMLElement | SettingsDialogOptions,
|
|
76
|
+
maybeOptions?: SettingsDialogOptions
|
|
77
|
+
) {
|
|
78
|
+
if (isDomHostElement(hostRootOrOptions) && maybeOptions) {
|
|
79
|
+
this.hostRoot = hostRootOrOptions;
|
|
80
|
+
this.options = maybeOptions;
|
|
81
|
+
this.config = maybeOptions.configuration;
|
|
82
|
+
this.activeScope = maybeOptions.scope ?? 'user';
|
|
83
|
+
this.mountDialog(hostRootOrOptions);
|
|
84
|
+
} else {
|
|
85
|
+
const opts = hostRootOrOptions as SettingsDialogOptions;
|
|
86
|
+
this.options = opts;
|
|
87
|
+
this.config = opts.configuration;
|
|
88
|
+
this.activeScope = opts.scope ?? 'user';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private buildSurfaceInnerHtml(mode: 'dialog' | 'inline'): string {
|
|
93
|
+
const titleId = mode === 'dialog' ? 'cl-settings-dialog-title' : 'cl-settings-inline-title';
|
|
94
|
+
const bodyHeightStyle =
|
|
95
|
+
mode === 'dialog'
|
|
96
|
+
? 'min-height:320px;max-height:62vh;'
|
|
97
|
+
: 'flex:1;min-height:0;overflow:hidden;';
|
|
98
|
+
const closeBtnHtml =
|
|
99
|
+
mode === 'dialog'
|
|
100
|
+
? `<button type="button" class="codelab-btn" data-settings-action="close" aria-label="Close Settings" style="${BTN_STYLE}">✕</button>`
|
|
101
|
+
: '';
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
`<div class="cl-settings-header" style="display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 16px;border-bottom:1px solid var(--cl-border,#262626);flex-wrap:wrap;">` +
|
|
105
|
+
`<h2 id="${titleId}" style="margin:0;font-size:15px;font-weight:600;color:var(--cl-fg,#f5f5f5);">Settings</h2>` +
|
|
106
|
+
`<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">` +
|
|
107
|
+
`<button type="button" class="codelab-btn" data-settings-action="open-json" aria-label="Open Settings (JSON)" title="Open .codelab/settings.json" style="${BTN_STYLE}">Open Settings (JSON)</button>` +
|
|
108
|
+
`<button type="button" class="codelab-btn" data-settings-action="reset-all" aria-label="Reset All Settings" title="Reset all settings to defaults" style="${BTN_STYLE}">Reset All Settings</button>` +
|
|
109
|
+
`<button type="button" class="codelab-btn" data-settings-action="export" title="Export Settings JSON" style="${BTN_STYLE}">Export</button>` +
|
|
110
|
+
closeBtnHtml +
|
|
111
|
+
`</div>` +
|
|
112
|
+
`</div>` +
|
|
113
|
+
`<div style="padding:10px 16px 0 16px;border-bottom:1px solid var(--cl-border,#262626);display:flex;flex-direction:column;gap:8px;">` +
|
|
114
|
+
`<input type="search" data-role="settings-search" aria-label="Search settings" value="${escapeAttr(this.searchQuery)}" placeholder="Search settings (e.g. fontSize, theme, wordWrap, autoSave)..." style="width:100%;padding:7px 10px;border-radius:6px;border:1px solid var(--cl-border,#262626);background:var(--cl-surface,#0a0a0a);color:var(--cl-fg,#f5f5f5);font-size:13px;" />` +
|
|
115
|
+
`<div role="tablist" aria-label="Settings scope" data-role="settings-scopes" style="display:flex;align-items:center;gap:4px;overflow-x:auto;"></div>` +
|
|
116
|
+
`</div>` +
|
|
117
|
+
`<div class="cl-settings-body" style="display:grid;grid-template-columns:150px minmax(0,1fr);${bodyHeightStyle}">` +
|
|
118
|
+
`<nav data-role="settings-categories" aria-label="Setting categories" style="border-right:1px solid var(--cl-border,#262626);padding:8px;display:flex;flex-direction:column;gap:4px;overflow-y:auto;"></nav>` +
|
|
119
|
+
`<div data-role="settings-list" style="padding:12px 16px;overflow-y:auto;display:flex;flex-direction:column;gap:12px;"></div>` +
|
|
120
|
+
`</div>`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private getWorkspaceSnapshot(): Record<string, unknown> {
|
|
125
|
+
if (typeof this.config.getWorkspaceSettings === 'function') {
|
|
126
|
+
return this.config.getWorkspaceSettings();
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const parsed = JSON.parse(this.config.toWorkspaceJsonString()) as unknown;
|
|
130
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
131
|
+
return parsed as Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
} catch (err) {
|
|
134
|
+
const _ignored = err;
|
|
135
|
+
void _ignored;
|
|
136
|
+
}
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private notifyWorkspaceMutated(mode: 'dialog' | 'inline'): void {
|
|
141
|
+
const snapshot = this.getWorkspaceSnapshot();
|
|
142
|
+
const cb =
|
|
143
|
+
mode === 'inline'
|
|
144
|
+
? (this.inlineCallbacks?.onWorkspaceSettingsMutated ??
|
|
145
|
+
this.runtimeCallbacks?.onWorkspaceSettingsMutated ??
|
|
146
|
+
this.options.onWorkspaceSettingsMutated)
|
|
147
|
+
: (this.runtimeCallbacks?.onWorkspaceSettingsMutated ??
|
|
148
|
+
this.inlineCallbacks?.onWorkspaceSettingsMutated ??
|
|
149
|
+
this.options.onWorkspaceSettingsMutated);
|
|
150
|
+
cb?.(snapshot);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private invokeOpenJsonCallback(mode: 'dialog' | 'inline'): void {
|
|
154
|
+
const cb =
|
|
155
|
+
mode === 'inline'
|
|
156
|
+
? (this.inlineCallbacks?.onOpenJson ??
|
|
157
|
+
this.inlineCallbacks?.onOpenSettingsJson ??
|
|
158
|
+
this.runtimeCallbacks?.onOpenJson ??
|
|
159
|
+
this.runtimeCallbacks?.onOpenSettingsJson ??
|
|
160
|
+
this.options.onOpenJson ??
|
|
161
|
+
this.options.onOpenSettingsJson)
|
|
162
|
+
: (this.runtimeCallbacks?.onOpenJson ??
|
|
163
|
+
this.runtimeCallbacks?.onOpenSettingsJson ??
|
|
164
|
+
this.inlineCallbacks?.onOpenJson ??
|
|
165
|
+
this.inlineCallbacks?.onOpenSettingsJson ??
|
|
166
|
+
this.options.onOpenJson ??
|
|
167
|
+
this.options.onOpenSettingsJson);
|
|
168
|
+
cb?.();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private bindSurfaceEvents(
|
|
172
|
+
surfaceEl: HTMLElement,
|
|
173
|
+
mode: 'dialog' | 'inline',
|
|
174
|
+
store: DisposableStore
|
|
175
|
+
): void {
|
|
176
|
+
const searchInput = surfaceEl.querySelector('[data-role="settings-search"]') as HTMLInputElement | null;
|
|
177
|
+
if (searchInput) {
|
|
178
|
+
const onInput = (): void => {
|
|
179
|
+
this.searchQuery = searchInput.value.trim().toLowerCase();
|
|
180
|
+
this.renderAllActiveSurfaces('items');
|
|
181
|
+
};
|
|
182
|
+
searchInput.addEventListener('input', onInput);
|
|
183
|
+
store.addFn(() => searchInput.removeEventListener('input', onInput));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const onClick = (evt: Event): void => {
|
|
187
|
+
const target = (evt.target as HTMLElement | null)?.closest?.(
|
|
188
|
+
'[data-settings-action],[data-settings-cat],[data-settings-scope],[data-reset-key]'
|
|
189
|
+
);
|
|
190
|
+
if (!target) return;
|
|
191
|
+
|
|
192
|
+
const scopeAttr = target.getAttribute('data-settings-scope');
|
|
193
|
+
if (scopeAttr === 'user' || scopeAttr === 'workspace') {
|
|
194
|
+
if (this.activeScope !== scopeAttr) {
|
|
195
|
+
this.activeScope = scopeAttr;
|
|
196
|
+
this.renderAllActiveSurfaces('all');
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const action = target.getAttribute('data-settings-action');
|
|
202
|
+
if (action === 'close') {
|
|
203
|
+
this.close();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (action === 'open-json') {
|
|
207
|
+
if (mode === 'dialog') {
|
|
208
|
+
this.close();
|
|
209
|
+
}
|
|
210
|
+
this.invokeOpenJsonCallback(mode);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (action === 'export') {
|
|
214
|
+
this.options.onExportSettings?.(this.config.exportProfile());
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (action === 'reset-all') {
|
|
218
|
+
const hadWs = Object.keys(this.getWorkspaceSnapshot()).length > 0;
|
|
219
|
+
if (this.activeScope === 'workspace') {
|
|
220
|
+
void this.config.resetAllSettings('workspace');
|
|
221
|
+
this.notifyWorkspaceMutated(mode);
|
|
222
|
+
} else {
|
|
223
|
+
void this.config.resetAllSettings('all');
|
|
224
|
+
if (hadWs) {
|
|
225
|
+
this.notifyWorkspaceMutated(mode);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
this.renderAllActiveSurfaces('items');
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const cat = target.getAttribute('data-settings-cat') as ('All' | SettingCategory) | null;
|
|
233
|
+
if (cat) {
|
|
234
|
+
this.activeCategory = cat;
|
|
235
|
+
this.renderAllActiveSurfaces('categories-and-items');
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const resetKey = target.getAttribute('data-reset-key');
|
|
240
|
+
if (resetKey) {
|
|
241
|
+
const hadWs = this.config.inspect(resetKey).workspaceValue !== undefined;
|
|
242
|
+
if (this.activeScope === 'workspace') {
|
|
243
|
+
void this.config.resetScopedSetting(resetKey, 'workspace');
|
|
244
|
+
if (hadWs) {
|
|
245
|
+
this.notifyWorkspaceMutated(mode);
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
void this.config.resetScopedSetting(resetKey, 'all');
|
|
249
|
+
if (hadWs) {
|
|
250
|
+
this.notifyWorkspaceMutated(mode);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
this.renderAllActiveSurfaces('items');
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
surfaceEl.addEventListener('click', onClick);
|
|
257
|
+
store.addFn(() => surfaceEl.removeEventListener('click', onClick));
|
|
258
|
+
|
|
259
|
+
const onChange = (evt: Event): void => {
|
|
260
|
+
const el = evt.target as HTMLInputElement | HTMLSelectElement | null;
|
|
261
|
+
if (!el || typeof el.getAttribute !== 'function') return;
|
|
262
|
+
const key = el.getAttribute('data-setting-key');
|
|
263
|
+
if (!key) return;
|
|
264
|
+
const desc = this.config.getDescriptors().find((d) => d.key === key);
|
|
265
|
+
if (!desc) return;
|
|
266
|
+
|
|
267
|
+
let nextValue: unknown;
|
|
268
|
+
let hasValidValue = true;
|
|
269
|
+
|
|
270
|
+
if (desc.schema.type === 'boolean' && el.getAttribute('type') === 'checkbox') {
|
|
271
|
+
nextValue = Boolean((el as HTMLInputElement).checked);
|
|
272
|
+
} else if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
|
|
273
|
+
const num = Number(el.value);
|
|
274
|
+
if (Number.isFinite(num)) {
|
|
275
|
+
nextValue = desc.schema.type === 'integer' ? Math.trunc(num) : num;
|
|
276
|
+
} else {
|
|
277
|
+
hasValidValue = false;
|
|
278
|
+
}
|
|
279
|
+
} else if (desc.schema.type === 'array') {
|
|
280
|
+
nextValue = el.value
|
|
281
|
+
.split(',')
|
|
282
|
+
.map((s) => s.trim())
|
|
283
|
+
.filter(Boolean);
|
|
284
|
+
} else {
|
|
285
|
+
nextValue = el.value;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (hasValidValue) {
|
|
289
|
+
if (this.activeScope === 'workspace') {
|
|
290
|
+
if (this.config.setWorkspaceSetting(key, nextValue)) {
|
|
291
|
+
this.notifyWorkspaceMutated(mode);
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
const hadWorkspaceOverride = this.config.inspect(key).workspaceValue !== undefined;
|
|
295
|
+
if (this.config.setUserSetting(key, nextValue) && hadWorkspaceOverride) {
|
|
296
|
+
this.config.setWorkspaceSetting(key, nextValue);
|
|
297
|
+
this.notifyWorkspaceMutated(mode);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
this.renderAllActiveSurfaces('items');
|
|
302
|
+
};
|
|
303
|
+
surfaceEl.addEventListener('change', onChange);
|
|
304
|
+
store.addFn(() => surfaceEl.removeEventListener('change', onChange));
|
|
305
|
+
|
|
306
|
+
store.add(
|
|
307
|
+
this.config.onDidChangeConfiguration(() => {
|
|
308
|
+
if (mode === 'dialog' && this.isOpen && this.dialogEl) {
|
|
309
|
+
this.renderItems(this.dialogEl);
|
|
310
|
+
} else if (mode === 'inline' && this.isInlineMounted && this.inlineRootEl) {
|
|
311
|
+
this.renderItems(this.inlineRootEl);
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private mountDialog(hostRoot: HTMLElement): void {
|
|
318
|
+
this.dialogDisposables.clear();
|
|
319
|
+
this.dialogEl?.remove();
|
|
320
|
+
const doc = hostRoot.ownerDocument ?? document;
|
|
321
|
+
const dialog = doc.createElement('dialog');
|
|
322
|
+
dialog.className = 'codelab-dialog cl-settings-dialog';
|
|
323
|
+
dialog.setAttribute('closedby', 'any');
|
|
324
|
+
dialog.setAttribute('aria-labelledby', 'cl-settings-dialog-title');
|
|
325
|
+
dialog.innerHTML = this.buildSurfaceInnerHtml('dialog');
|
|
326
|
+
|
|
327
|
+
hostRoot.appendChild(dialog);
|
|
328
|
+
this.dialogEl = dialog;
|
|
329
|
+
|
|
330
|
+
// Reset returnValue on close + Safari fallback for `closedby="any"` light dismiss
|
|
331
|
+
const onClose = (): void => {
|
|
332
|
+
dialog.returnValue = '';
|
|
333
|
+
};
|
|
334
|
+
dialog.addEventListener('close', onClose);
|
|
335
|
+
this.dialogDisposables.addFn(() => dialog.removeEventListener('close', onClose));
|
|
336
|
+
|
|
337
|
+
if (typeof HTMLDialogElement !== 'undefined' && !('closedBy' in HTMLDialogElement.prototype)) {
|
|
338
|
+
const onBackdropClick = (evt: MouseEvent): void => {
|
|
339
|
+
if (evt.target !== dialog) return;
|
|
340
|
+
const rect = dialog.getBoundingClientRect();
|
|
341
|
+
const outside =
|
|
342
|
+
evt.clientX < rect.left ||
|
|
343
|
+
evt.clientX > rect.right ||
|
|
344
|
+
evt.clientY < rect.top ||
|
|
345
|
+
evt.clientY > rect.bottom;
|
|
346
|
+
if (outside) dialog.close();
|
|
347
|
+
};
|
|
348
|
+
dialog.addEventListener('click', onBackdropClick);
|
|
349
|
+
this.dialogDisposables.addFn(() => dialog.removeEventListener('click', onBackdropClick));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
this.bindSurfaceEvents(dialog, 'dialog', this.dialogDisposables);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
public get isOpen(): boolean {
|
|
356
|
+
return Boolean(this.dialogEl && (this.dialogEl.open || this.dialogEl.hasAttribute('open')));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
public get isInlineMounted(): boolean {
|
|
360
|
+
return Boolean(this.inlineRootEl && this.inlineRootEl.parentNode);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
public open(options?: SettingsOpenOptions): void {
|
|
364
|
+
if (options?.scope) {
|
|
365
|
+
this.activeScope = options.scope;
|
|
366
|
+
}
|
|
367
|
+
if (options) {
|
|
368
|
+
this.runtimeCallbacks = options;
|
|
369
|
+
}
|
|
370
|
+
if (!this.dialogEl) {
|
|
371
|
+
const fallbackHost =
|
|
372
|
+
this.hostRoot ?? (typeof document !== 'undefined' ? document.body : null);
|
|
373
|
+
if (!fallbackHost) return;
|
|
374
|
+
this.hostRoot = fallbackHost;
|
|
375
|
+
this.mountDialog(fallbackHost);
|
|
376
|
+
}
|
|
377
|
+
if (!this.dialogEl) return;
|
|
378
|
+
this.renderScopes(this.dialogEl);
|
|
379
|
+
this.renderCategories(this.dialogEl);
|
|
380
|
+
this.renderItems(this.dialogEl);
|
|
381
|
+
if (typeof this.dialogEl.showModal === 'function') {
|
|
382
|
+
if (!this.dialogEl.open) this.dialogEl.showModal();
|
|
383
|
+
} else {
|
|
384
|
+
this.dialogEl.setAttribute('open', '');
|
|
385
|
+
}
|
|
386
|
+
const searchInput = this.dialogEl.querySelector('[data-role="settings-search"]') as HTMLInputElement | null;
|
|
387
|
+
searchInput?.focus();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
public close(): void {
|
|
391
|
+
if (!this.dialogEl) return;
|
|
392
|
+
if (typeof this.dialogEl.close === 'function' && this.dialogEl.open) {
|
|
393
|
+
this.dialogEl.close();
|
|
394
|
+
} else {
|
|
395
|
+
this.dialogEl.removeAttribute('open');
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
public mountInline(container: HTMLElement, options?: SettingsInlineMountOptions): void {
|
|
400
|
+
this.unmountInline();
|
|
401
|
+
if (options?.scope) {
|
|
402
|
+
this.activeScope = options.scope;
|
|
403
|
+
}
|
|
404
|
+
this.inlineCallbacks = options;
|
|
405
|
+
|
|
406
|
+
const doc = container.ownerDocument ?? document;
|
|
407
|
+
const root = doc.createElement('div');
|
|
408
|
+
root.className = 'cl-settings-editor cl-settings-inline';
|
|
409
|
+
root.setAttribute('data-role', 'settings-inline-root');
|
|
410
|
+
root.setAttribute(
|
|
411
|
+
'style',
|
|
412
|
+
'display:flex;flex-direction:column;height:100%;min-height:0;background:var(--cl-bg,#000000);color:var(--cl-fg,#f5f5f5);'
|
|
413
|
+
);
|
|
414
|
+
root.innerHTML = this.buildSurfaceInnerHtml('inline');
|
|
415
|
+
|
|
416
|
+
container.appendChild(root);
|
|
417
|
+
this.inlineRootEl = root;
|
|
418
|
+
|
|
419
|
+
this.bindSurfaceEvents(root, 'inline', this.inlineDisposables);
|
|
420
|
+
this.renderScopes(root);
|
|
421
|
+
this.renderCategories(root);
|
|
422
|
+
this.renderItems(root);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
public unmountInline(): void {
|
|
426
|
+
this.inlineDisposables.clear();
|
|
427
|
+
this.inlineRootEl?.remove();
|
|
428
|
+
this.inlineRootEl = null;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
private renderAllActiveSurfaces(kind: 'all' | 'categories-and-items' | 'items'): void {
|
|
432
|
+
const surfaces: HTMLElement[] = [];
|
|
433
|
+
if (this.dialogEl) surfaces.push(this.dialogEl);
|
|
434
|
+
if (this.inlineRootEl) surfaces.push(this.inlineRootEl);
|
|
435
|
+
for (const root of surfaces) {
|
|
436
|
+
if (kind === 'all') {
|
|
437
|
+
this.renderScopes(root);
|
|
438
|
+
this.renderCategories(root);
|
|
439
|
+
this.renderItems(root);
|
|
440
|
+
} else if (kind === 'categories-and-items') {
|
|
441
|
+
this.renderCategories(root);
|
|
442
|
+
this.renderItems(root);
|
|
443
|
+
} else {
|
|
444
|
+
this.renderItems(root);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
private renderScopes(root: HTMLElement): void {
|
|
450
|
+
const scopesEl = root.querySelector('[data-role="settings-scopes"]');
|
|
451
|
+
if (!scopesEl) return;
|
|
452
|
+
const tabs: ReadonlyArray<{ readonly id: SettingsScope; readonly label: string }> = [
|
|
453
|
+
{ id: 'user', label: 'User' },
|
|
454
|
+
{ id: 'workspace', label: 'Workspace (.codelab/settings.json)' }
|
|
455
|
+
];
|
|
456
|
+
scopesEl.innerHTML = tabs
|
|
457
|
+
.map((tab) => {
|
|
458
|
+
const selected = this.activeScope === tab.id;
|
|
459
|
+
return (
|
|
460
|
+
`<button type="button" role="tab" data-settings-scope="${tab.id}" aria-selected="${selected ? 'true' : 'false'}" ` +
|
|
461
|
+
`style="flex:none;padding:6px 12px;border-top:1px solid transparent;border-left:1px solid transparent;border-right:1px solid transparent;border-bottom:2px solid ${selected ? 'var(--cl-accent,#0369a1)' : 'transparent'};background:${selected ? 'var(--cl-surface,#0a0a0a)' : 'transparent'};color:${selected ? 'var(--cl-fg,#f5f5f5)' : 'var(--cl-fg-muted,var(--cl-muted,#64748b))'};cursor:pointer;font-size:12.5px;font-weight:500;">` +
|
|
462
|
+
`${escapeAttr(tab.label)}` +
|
|
463
|
+
`</button>`
|
|
464
|
+
);
|
|
465
|
+
})
|
|
466
|
+
.join('');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
private renderCategories(root: HTMLElement): void {
|
|
470
|
+
const nav = root.querySelector('[data-role="settings-categories"]');
|
|
471
|
+
if (!nav) return;
|
|
472
|
+
nav.innerHTML = ALL_CATEGORIES.map((cat) => {
|
|
473
|
+
const selected = cat === this.activeCategory;
|
|
474
|
+
return (
|
|
475
|
+
`<button type="button" data-settings-cat="${cat}" aria-current="${selected ? 'true' : 'false'}" ` +
|
|
476
|
+
`style="text-align:left;padding:6px 10px;border-radius:5px;border:1px solid ${selected ? 'var(--cl-accent,#0369a1)' : 'transparent'};background:${selected ? 'var(--cl-accent,#0369a1)' : 'transparent'};color:${selected ? 'var(--cl-accent-fg,#ffffff)' : 'var(--cl-fg,#f5f5f5)'};cursor:pointer;font-size:12.5px;font-weight:500;">` +
|
|
477
|
+
`${escapeAttr(cat)}` +
|
|
478
|
+
`</button>`
|
|
479
|
+
);
|
|
480
|
+
}).join('');
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
private renderControl(desc: SettingDescriptor, currentVal: unknown): string {
|
|
484
|
+
const keyAttr = escapeAttr(desc.key);
|
|
485
|
+
if (desc.schema.enum && desc.schema.enum.length > 0) {
|
|
486
|
+
const opts = desc.schema.enum
|
|
487
|
+
.map((opt) => {
|
|
488
|
+
const str = String(opt);
|
|
489
|
+
const sel = String(currentVal) === str ? ' selected' : '';
|
|
490
|
+
return `<option value="${escapeAttr(str)}"${sel}>${escapeAttr(str)}</option>`;
|
|
491
|
+
})
|
|
492
|
+
.join('');
|
|
493
|
+
return `<select data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" style="${CONTROL_STYLE}">${opts}</select>`;
|
|
494
|
+
}
|
|
495
|
+
if (desc.schema.type === 'boolean') {
|
|
496
|
+
const checked = Boolean(currentVal) ? ' checked' : '';
|
|
497
|
+
return `<input type="checkbox" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}"${checked} />`;
|
|
498
|
+
}
|
|
499
|
+
if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
|
|
500
|
+
const min = desc.schema.minimum !== undefined ? ` min="${desc.schema.minimum}"` : '';
|
|
501
|
+
const max = desc.schema.maximum !== undefined ? ` max="${desc.schema.maximum}"` : '';
|
|
502
|
+
return `<input type="number" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(String(currentVal ?? ''))}"${min}${max} style="width:100px;${CONTROL_STYLE}" />`;
|
|
503
|
+
}
|
|
504
|
+
if (desc.schema.type === 'array') {
|
|
505
|
+
const joined = Array.isArray(currentVal) ? currentVal.join(', ') : '';
|
|
506
|
+
return `<input type="text" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(joined)}" style="width:260px;${CONTROL_STYLE}" />`;
|
|
507
|
+
}
|
|
508
|
+
return `<input type="text" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(String(currentVal ?? ''))}" style="width:180px;${CONTROL_STYLE}" />`;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
private renderItems(root: HTMLElement): void {
|
|
512
|
+
const listEl = root.querySelector('[data-role="settings-list"]');
|
|
513
|
+
if (!listEl) return;
|
|
514
|
+
const descriptors = this.config.getDescriptors().filter((d) => {
|
|
515
|
+
if (this.activeCategory !== 'All' && d.category !== this.activeCategory) return false;
|
|
516
|
+
if (!this.searchQuery) return true;
|
|
517
|
+
const hay = `${d.key} ${d.title} ${d.description} ${d.category}`.toLowerCase();
|
|
518
|
+
return hay.includes(this.searchQuery);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
if (descriptors.length === 0) {
|
|
522
|
+
listEl.innerHTML = `<div style="color:var(--cl-fg-muted,var(--cl-muted,#64748b));font-size:13px;">No matching settings found.</div>`;
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
listEl.innerHTML = descriptors
|
|
527
|
+
.map((desc) => {
|
|
528
|
+
const insp = this.config.inspect(desc.key);
|
|
529
|
+
const displayedVal =
|
|
530
|
+
this.activeScope === 'workspace'
|
|
531
|
+
? (insp.workspaceValue !== undefined ? insp.workspaceValue : insp.effectiveValue)
|
|
532
|
+
: insp.effectiveValue;
|
|
533
|
+
const canReset =
|
|
534
|
+
this.activeScope === 'workspace'
|
|
535
|
+
? insp.workspaceValue !== undefined
|
|
536
|
+
: insp.effectiveSource !== 'default' || insp.userValue !== undefined;
|
|
537
|
+
const badgeLabel =
|
|
538
|
+
this.activeScope === 'workspace'
|
|
539
|
+
? (insp.workspaceValue !== undefined ? 'workspace' : '')
|
|
540
|
+
: (insp.effectiveSource !== 'default' ? insp.effectiveSource : '');
|
|
541
|
+
|
|
542
|
+
return (
|
|
543
|
+
`<div class="cl-setting-item" data-setting-row="${escapeAttr(desc.key)}" style="padding:10px 12px;border:1px solid var(--cl-border,#262626);border-radius:7px;display:flex;align-items:flex-start;justify-content:space-between;gap:12px;">` +
|
|
544
|
+
`<div style="min-width:0;">` +
|
|
545
|
+
`<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap;">` +
|
|
546
|
+
`<strong style="font-size:13px;color:var(--cl-fg,#f5f5f5);">${escapeAttr(desc.title)}</strong>` +
|
|
547
|
+
`<code style="font-size:11px;color:var(--cl-fg-muted,var(--cl-muted,#64748b));">${escapeAttr(desc.key)}</code>` +
|
|
548
|
+
(badgeLabel
|
|
549
|
+
? `<span data-role="setting-badge" style="font-size:10px;padding:1px 6px;border-radius:4px;background:var(--cl-accent,#0369a1);color:var(--cl-accent-fg,#ffffff);font-weight:600;">${escapeAttr(badgeLabel)}</span>`
|
|
550
|
+
: '') +
|
|
551
|
+
`</div>` +
|
|
552
|
+
`<div style="font-size:12px;color:var(--cl-fg-muted,var(--cl-muted,#64748b));margin-top:3px;">${escapeAttr(desc.description)}</div>` +
|
|
553
|
+
`</div>` +
|
|
554
|
+
`<div style="display:flex;align-items:center;gap:6px;flex-shrink:0;">` +
|
|
555
|
+
this.renderControl(desc, displayedVal) +
|
|
556
|
+
(canReset
|
|
557
|
+
? `<button type="button" class="codelab-btn" data-reset-key="${escapeAttr(desc.key)}" title="Reset to Default (${escapeAttr(JSON.stringify(desc.defaultValue))})" style="${BTN_STYLE}">Reset</button>`
|
|
558
|
+
: '') +
|
|
559
|
+
`</div>` +
|
|
560
|
+
`</div>`
|
|
561
|
+
);
|
|
562
|
+
})
|
|
563
|
+
.join('');
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
public dispose(): void {
|
|
567
|
+
this.close();
|
|
568
|
+
this.unmountInline();
|
|
569
|
+
this.dialogDisposables.dispose();
|
|
570
|
+
this.inlineDisposables.dispose();
|
|
571
|
+
this.dialogEl?.remove();
|
|
572
|
+
this.dialogEl = null;
|
|
573
|
+
this.hostRoot = null;
|
|
574
|
+
}
|
|
575
|
+
}
|