@innovatorved/code-lab 0.4.0 → 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 +2 -2
- package/CHANGELOG.md +21 -0
- package/README.md +4 -28
- package/dist/code-lab-sql.esm.js +1 -1
- package/dist/code-lab-sql.umd.js +2 -2
- package/dist/code-lab.css +1553 -98
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +11883 -1619
- package/dist/code-lab.js +11882 -1618
- package/dist/code-lab.umd.js +11882 -1618
- package/dist/diagnostics.d.ts +3 -0
- package/dist/extensions/cpp.esm.js +27 -29
- package/dist/extensions/cpp.js +27 -29
- package/dist/extensions/python.esm.js +27 -28
- package/dist/extensions/python.js +27 -28
- package/dist/index.d.ts +1 -1
- package/dist/packages/settings/src/configuration-service.d.ts +7 -0
- package/dist/packages/settings/src/index.d.ts +1 -1
- package/dist/packages/ui/src/index.d.ts +2 -2
- package/dist/packages/ui/src/plugin-registry.d.ts +1 -0
- package/dist/packages/ui/src/settings-dialog.d.ts +31 -3
- package/dist/packages/ui/src/themes.d.ts +5 -0
- package/dist/preview-sw.js +1 -1
- package/dist/runtime.esm.js +1 -1
- package/dist/runtime.js +1 -1
- package/dist/schemas.d.ts +1 -1
- package/dist/scm.d.ts +92 -11
- package/dist/shell.esm.js +937 -113
- package/dist/shell.js +937 -113
- package/dist/storage.d.ts +47 -0
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/dist/workbench/index.d.ts +1 -1
- package/dist/workbench/styles.d.ts +1 -1
- package/package.json +2 -2
- package/packages/commands/package.json +1 -1
- package/packages/core/package.json +1 -1
- package/packages/editor/package.json +1 -1
- package/packages/fs/package.json +1 -1
- package/packages/preview/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/settings/package.json +1 -1
- package/packages/settings/src/builtin-schemas.ts +17 -6
- package/packages/settings/src/configuration-service.ts +72 -6
- package/packages/settings/src/index.ts +1 -0
- package/packages/sql/package.json +1 -1
- package/packages/terminal/package.json +1 -1
- package/packages/ui/package.json +1 -1
- package/packages/ui/src/index.ts +4 -0
- package/packages/ui/src/plugin-registry.ts +17 -2
- package/packages/ui/src/settings-dialog.ts +374 -92
- package/packages/ui/src/themes.ts +105 -12
- package/src/code-lab.css +1553 -98
- package/src/diagnostics.ts +139 -7
- package/src/extensions/cpp.ts +33 -33
- package/src/extensions/python.ts +33 -32
- package/src/index.ts +1 -1
- package/src/schemas.ts +1 -1
- package/src/scm.ts +781 -58
- package/src/shell.ts +936 -112
- package/src/storage.ts +336 -3
- package/src/workbench/icons.ts +8 -1
- package/src/workbench/styles.ts +25 -19
- package/src/workbench.ts +12010 -3814
|
@@ -9,11 +9,25 @@ function escapeAttr(raw: string): string {
|
|
|
9
9
|
.replace(/"/g, '"');
|
|
10
10
|
}
|
|
11
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
|
+
|
|
12
23
|
export interface SettingsDialogOptions {
|
|
13
24
|
readonly configuration: IConfigurationService;
|
|
25
|
+
readonly scope?: SettingsScope;
|
|
14
26
|
readonly onOpenSettingsJson?: () => void;
|
|
27
|
+
readonly onOpenJson?: () => void;
|
|
15
28
|
readonly onExportSettings?: (json: string) => void;
|
|
16
29
|
readonly onImportSettings?: () => void;
|
|
30
|
+
readonly onWorkspaceSettingsMutated?: (nextWorkspaceSettings: Record<string, unknown>) => void;
|
|
17
31
|
}
|
|
18
32
|
|
|
19
33
|
const ALL_CATEGORIES: ReadonlyArray<'All' | SettingCategory> = [
|
|
@@ -27,160 +41,343 @@ const ALL_CATEGORIES: ReadonlyArray<'All' | SettingCategory> = [
|
|
|
27
41
|
'SQL'
|
|
28
42
|
];
|
|
29
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
|
+
|
|
30
58
|
export class SettingsDialogController implements IDisposable {
|
|
31
|
-
private readonly
|
|
59
|
+
private readonly dialogDisposables = new DisposableStore();
|
|
60
|
+
private readonly inlineDisposables = new DisposableStore();
|
|
32
61
|
private readonly config: IConfigurationService;
|
|
33
62
|
private readonly options: SettingsDialogOptions;
|
|
63
|
+
private hostRoot: HTMLElement | null = null;
|
|
34
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;
|
|
35
69
|
private activeCategory: 'All' | SettingCategory = 'All';
|
|
36
70
|
private searchQuery = '';
|
|
37
71
|
|
|
38
|
-
public constructor(hostRoot: HTMLElement, options: SettingsDialogOptions)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
}
|
|
42
90
|
}
|
|
43
91
|
|
|
44
|
-
private
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
: '';
|
|
50
102
|
|
|
51
|
-
|
|
52
|
-
`<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);">` +
|
|
53
|
-
`<h2 id="
|
|
54
|
-
`<div style="display:flex;align-items:center;gap:8px;">` +
|
|
55
|
-
`<button type="button" class="codelab-btn" data-settings-action="open-json" title="Open .codelab/settings.json">Open
|
|
56
|
-
`<button type="button" class="codelab-btn" data-settings-action="
|
|
57
|
-
`<button type="button" class="codelab-btn" data-settings-action="
|
|
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 +
|
|
58
111
|
`</div>` +
|
|
59
112
|
`</div>` +
|
|
60
|
-
`<div style="padding:10px 16px;border-bottom:1px solid var(--cl-border,#262626);">` +
|
|
61
|
-
`<input type="search" data-role="settings-search" aria-label="Search settings" 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;" />` +
|
|
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>` +
|
|
62
116
|
`</div>` +
|
|
63
|
-
`<div class="cl-settings-body" style="display:grid;grid-template-columns:150px minmax(0,1fr)
|
|
117
|
+
`<div class="cl-settings-body" style="display:grid;grid-template-columns:150px minmax(0,1fr);${bodyHeightStyle}">` +
|
|
64
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>` +
|
|
65
119
|
`<div data-role="settings-list" style="padding:12px 16px;overflow-y:auto;display:flex;flex-direction:column;gap:12px;"></div>` +
|
|
66
|
-
`</div
|
|
120
|
+
`</div>`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
67
123
|
|
|
68
|
-
|
|
69
|
-
this.
|
|
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
|
+
}
|
|
70
139
|
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
}
|
|
77
152
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
}
|
|
92
170
|
|
|
93
|
-
|
|
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;
|
|
94
177
|
if (searchInput) {
|
|
95
178
|
const onInput = (): void => {
|
|
96
179
|
this.searchQuery = searchInput.value.trim().toLowerCase();
|
|
97
|
-
this.
|
|
180
|
+
this.renderAllActiveSurfaces('items');
|
|
98
181
|
};
|
|
99
182
|
searchInput.addEventListener('input', onInput);
|
|
100
|
-
|
|
183
|
+
store.addFn(() => searchInput.removeEventListener('input', onInput));
|
|
101
184
|
}
|
|
102
185
|
|
|
103
186
|
const onClick = (evt: Event): void => {
|
|
104
187
|
const target = (evt.target as HTMLElement | null)?.closest?.(
|
|
105
|
-
'[data-settings-action],[data-settings-cat],[data-reset-key]'
|
|
188
|
+
'[data-settings-action],[data-settings-cat],[data-settings-scope],[data-reset-key]'
|
|
106
189
|
);
|
|
107
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
|
+
|
|
108
201
|
const action = target.getAttribute('data-settings-action');
|
|
109
202
|
if (action === 'close') {
|
|
110
203
|
this.close();
|
|
111
204
|
return;
|
|
112
205
|
}
|
|
113
206
|
if (action === 'open-json') {
|
|
114
|
-
|
|
115
|
-
|
|
207
|
+
if (mode === 'dialog') {
|
|
208
|
+
this.close();
|
|
209
|
+
}
|
|
210
|
+
this.invokeOpenJsonCallback(mode);
|
|
116
211
|
return;
|
|
117
212
|
}
|
|
118
213
|
if (action === 'export') {
|
|
119
214
|
this.options.onExportSettings?.(this.config.exportProfile());
|
|
120
215
|
return;
|
|
121
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
|
+
|
|
122
232
|
const cat = target.getAttribute('data-settings-cat') as ('All' | SettingCategory) | null;
|
|
123
233
|
if (cat) {
|
|
124
234
|
this.activeCategory = cat;
|
|
125
|
-
this.
|
|
126
|
-
this.renderItems();
|
|
235
|
+
this.renderAllActiveSurfaces('categories-and-items');
|
|
127
236
|
return;
|
|
128
237
|
}
|
|
238
|
+
|
|
129
239
|
const resetKey = target.getAttribute('data-reset-key');
|
|
130
240
|
if (resetKey) {
|
|
131
|
-
this.config.
|
|
132
|
-
this.
|
|
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');
|
|
133
254
|
}
|
|
134
255
|
};
|
|
135
|
-
|
|
136
|
-
|
|
256
|
+
surfaceEl.addEventListener('click', onClick);
|
|
257
|
+
store.addFn(() => surfaceEl.removeEventListener('click', onClick));
|
|
137
258
|
|
|
138
259
|
const onChange = (evt: Event): void => {
|
|
139
260
|
const el = evt.target as HTMLInputElement | HTMLSelectElement | null;
|
|
140
|
-
if (!el) return;
|
|
261
|
+
if (!el || typeof el.getAttribute !== 'function') return;
|
|
141
262
|
const key = el.getAttribute('data-setting-key');
|
|
142
263
|
if (!key) return;
|
|
143
264
|
const desc = this.config.getDescriptors().find((d) => d.key === key);
|
|
144
265
|
if (!desc) return;
|
|
145
266
|
|
|
146
|
-
|
|
147
|
-
|
|
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);
|
|
148
272
|
} else if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
|
|
149
273
|
const num = Number(el.value);
|
|
150
274
|
if (Number.isFinite(num)) {
|
|
151
|
-
|
|
275
|
+
nextValue = desc.schema.type === 'integer' ? Math.trunc(num) : num;
|
|
276
|
+
} else {
|
|
277
|
+
hasValidValue = false;
|
|
152
278
|
}
|
|
153
279
|
} else if (desc.schema.type === 'array') {
|
|
154
|
-
|
|
280
|
+
nextValue = el.value
|
|
155
281
|
.split(',')
|
|
156
282
|
.map((s) => s.trim())
|
|
157
283
|
.filter(Boolean);
|
|
158
|
-
this.config.setUserSetting(key, items);
|
|
159
284
|
} else {
|
|
160
|
-
|
|
285
|
+
nextValue = el.value;
|
|
161
286
|
}
|
|
162
|
-
|
|
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');
|
|
163
302
|
};
|
|
164
|
-
|
|
165
|
-
|
|
303
|
+
surfaceEl.addEventListener('change', onChange);
|
|
304
|
+
store.addFn(() => surfaceEl.removeEventListener('change', onChange));
|
|
166
305
|
|
|
167
|
-
|
|
306
|
+
store.add(
|
|
168
307
|
this.config.onDidChangeConfiguration(() => {
|
|
169
|
-
if (this.isOpen) {
|
|
170
|
-
this.renderItems();
|
|
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);
|
|
171
312
|
}
|
|
172
313
|
})
|
|
173
314
|
);
|
|
174
315
|
}
|
|
175
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
|
+
|
|
176
355
|
public get isOpen(): boolean {
|
|
177
356
|
return Boolean(this.dialogEl && (this.dialogEl.open || this.dialogEl.hasAttribute('open')));
|
|
178
357
|
}
|
|
179
358
|
|
|
180
|
-
public
|
|
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
|
+
}
|
|
181
377
|
if (!this.dialogEl) return;
|
|
182
|
-
this.
|
|
183
|
-
this.
|
|
378
|
+
this.renderScopes(this.dialogEl);
|
|
379
|
+
this.renderCategories(this.dialogEl);
|
|
380
|
+
this.renderItems(this.dialogEl);
|
|
184
381
|
if (typeof this.dialogEl.showModal === 'function') {
|
|
185
382
|
if (!this.dialogEl.open) this.dialogEl.showModal();
|
|
186
383
|
} else {
|
|
@@ -199,14 +396,84 @@ export class SettingsDialogController implements IDisposable {
|
|
|
199
396
|
}
|
|
200
397
|
}
|
|
201
398
|
|
|
202
|
-
|
|
203
|
-
|
|
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"]');
|
|
204
471
|
if (!nav) return;
|
|
205
472
|
nav.innerHTML = ALL_CATEGORIES.map((cat) => {
|
|
206
473
|
const selected = cat === this.activeCategory;
|
|
207
474
|
return (
|
|
208
475
|
`<button type="button" data-settings-cat="${cat}" aria-current="${selected ? 'true' : 'false'}" ` +
|
|
209
|
-
`style="text-align:left;padding:6px 10px;border-radius:5px;border:1px solid ${selected ? 'var(--cl-accent,#
|
|
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;">` +
|
|
210
477
|
`${escapeAttr(cat)}` +
|
|
211
478
|
`</button>`
|
|
212
479
|
);
|
|
@@ -223,7 +490,7 @@ export class SettingsDialogController implements IDisposable {
|
|
|
223
490
|
return `<option value="${escapeAttr(str)}"${sel}>${escapeAttr(str)}</option>`;
|
|
224
491
|
})
|
|
225
492
|
.join('');
|
|
226
|
-
return `<select data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" style="
|
|
493
|
+
return `<select data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" style="${CONTROL_STYLE}">${opts}</select>`;
|
|
227
494
|
}
|
|
228
495
|
if (desc.schema.type === 'boolean') {
|
|
229
496
|
const checked = Boolean(currentVal) ? ' checked' : '';
|
|
@@ -232,17 +499,17 @@ export class SettingsDialogController implements IDisposable {
|
|
|
232
499
|
if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
|
|
233
500
|
const min = desc.schema.minimum !== undefined ? ` min="${desc.schema.minimum}"` : '';
|
|
234
501
|
const max = desc.schema.maximum !== undefined ? ` max="${desc.schema.maximum}"` : '';
|
|
235
|
-
return `<input type="number" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(String(currentVal ?? ''))}"${min}${max} style="width:100px
|
|
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}" />`;
|
|
236
503
|
}
|
|
237
504
|
if (desc.schema.type === 'array') {
|
|
238
505
|
const joined = Array.isArray(currentVal) ? currentVal.join(', ') : '';
|
|
239
|
-
return `<input type="text" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(joined)}" style="width:260px
|
|
506
|
+
return `<input type="text" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(joined)}" style="width:260px;${CONTROL_STYLE}" />`;
|
|
240
507
|
}
|
|
241
|
-
return `<input type="text" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(String(currentVal ?? ''))}" style="width:180px
|
|
508
|
+
return `<input type="text" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(String(currentVal ?? ''))}" style="width:180px;${CONTROL_STYLE}" />`;
|
|
242
509
|
}
|
|
243
510
|
|
|
244
|
-
private renderItems(): void {
|
|
245
|
-
const listEl =
|
|
511
|
+
private renderItems(root: HTMLElement): void {
|
|
512
|
+
const listEl = root.querySelector('[data-role="settings-list"]');
|
|
246
513
|
if (!listEl) return;
|
|
247
514
|
const descriptors = this.config.getDescriptors().filter((d) => {
|
|
248
515
|
if (this.activeCategory !== 'All' && d.category !== this.activeCategory) return false;
|
|
@@ -252,30 +519,42 @@ export class SettingsDialogController implements IDisposable {
|
|
|
252
519
|
});
|
|
253
520
|
|
|
254
521
|
if (descriptors.length === 0) {
|
|
255
|
-
listEl.innerHTML = `<div style="color:var(--cl-muted,#
|
|
522
|
+
listEl.innerHTML = `<div style="color:var(--cl-fg-muted,var(--cl-muted,#64748b));font-size:13px;">No matching settings found.</div>`;
|
|
256
523
|
return;
|
|
257
524
|
}
|
|
258
525
|
|
|
259
526
|
listEl.innerHTML = descriptors
|
|
260
527
|
.map((desc) => {
|
|
261
528
|
const insp = this.config.inspect(desc.key);
|
|
262
|
-
const
|
|
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
|
+
|
|
263
542
|
return (
|
|
264
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;">` +
|
|
265
544
|
`<div style="min-width:0;">` +
|
|
266
545
|
`<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap;">` +
|
|
267
|
-
`<strong style="font-size:13px;">${escapeAttr(desc.title)}</strong>` +
|
|
268
|
-
`<code style="font-size:11px;
|
|
269
|
-
(
|
|
270
|
-
? `<span style="font-size:10px;padding:1px
|
|
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>`
|
|
271
550
|
: '') +
|
|
272
551
|
`</div>` +
|
|
273
|
-
`<div style="font-size:12px;color:var(--cl-muted,#
|
|
552
|
+
`<div style="font-size:12px;color:var(--cl-fg-muted,var(--cl-muted,#64748b));margin-top:3px;">${escapeAttr(desc.description)}</div>` +
|
|
274
553
|
`</div>` +
|
|
275
554
|
`<div style="display:flex;align-items:center;gap:6px;flex-shrink:0;">` +
|
|
276
|
-
this.renderControl(desc,
|
|
277
|
-
(
|
|
278
|
-
? `<button type="button" class="codelab-btn" data-reset-key="${escapeAttr(desc.key)}" title="Reset to Default (${escapeAttr(JSON.stringify(desc.defaultValue))})">Reset</button>`
|
|
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>`
|
|
279
558
|
: '') +
|
|
280
559
|
`</div>` +
|
|
281
560
|
`</div>`
|
|
@@ -286,8 +565,11 @@ export class SettingsDialogController implements IDisposable {
|
|
|
286
565
|
|
|
287
566
|
public dispose(): void {
|
|
288
567
|
this.close();
|
|
289
|
-
this.
|
|
568
|
+
this.unmountInline();
|
|
569
|
+
this.dialogDisposables.dispose();
|
|
570
|
+
this.inlineDisposables.dispose();
|
|
290
571
|
this.dialogEl?.remove();
|
|
291
572
|
this.dialogEl = null;
|
|
573
|
+
this.hostRoot = null;
|
|
292
574
|
}
|
|
293
575
|
}
|