@innovatorved/code-lab 0.3.2 → 0.4.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 +20 -0
- package/README.md +70 -168
- 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 +246 -0
- package/dist/code-lab.d.ts +110 -15
- package/dist/code-lab.esm.js +34265 -18104
- package/dist/code-lab.js +33186 -17053
- package/dist/code-lab.umd.js +65502 -0
- package/dist/extensions/cpp.esm.js +19478 -3760
- package/dist/extensions/cpp.js +19475 -3757
- 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 +19576 -3766
- package/dist/extensions/python.js +19576 -3766
- 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 +100 -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 +89 -0
- package/dist/packages/ui/src/settings-dialog.d.ts +25 -0
- package/dist/packages/ui/src/themes.d.ts +35 -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/shell.d.ts +1 -1
- package/dist/shell.esm.js +364 -39
- package/dist/shell.js +364 -39
- package/dist/terminal.esm.js +62 -3
- package/dist/terminal.js +62 -3
- package/dist/workbench/diff-editor.d.ts +1 -0
- package/package.json +37 -8
- 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 +235 -0
- package/packages/settings/src/configuration-service.ts +543 -0
- package/packages/settings/src/index.ts +37 -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 +36 -0
- package/packages/ui/src/observability.ts +175 -0
- package/packages/ui/src/plugin-registry.ts +274 -0
- package/packages/ui/src/settings-dialog.ts +293 -0
- package/packages/ui/src/themes.ts +174 -0
- package/packages/ui/tsconfig.json +24 -0
- package/src/code-lab.css +246 -0
- package/src/extensions/cpp.ts +58 -15
- package/src/extensions/python.ts +156 -24
- 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/shell.ts +363 -39
- package/src/terminal.ts +60 -2
- package/src/workbench/diff-editor.ts +66 -6
- package/src/workbench/icons.ts +5 -2
- package/src/workbench.ts +2410 -220
- 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,274 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CommandDescriptor,
|
|
3
|
+
type ICommandRegistry,
|
|
4
|
+
type IKeybindingService,
|
|
5
|
+
type KeybindingRule
|
|
6
|
+
} from '@code-lab/commands';
|
|
7
|
+
import {
|
|
8
|
+
CodeLabError,
|
|
9
|
+
ContributionRegistry,
|
|
10
|
+
createServiceId,
|
|
11
|
+
DisposableStore,
|
|
12
|
+
Emitter,
|
|
13
|
+
type Event,
|
|
14
|
+
type IDisposable,
|
|
15
|
+
type ILogger
|
|
16
|
+
} from '@code-lab/core';
|
|
17
|
+
import type { IConfigurationService, SettingDescriptor } from '@code-lab/settings';
|
|
18
|
+
import type { IThemeService, ThemeDefinition } from './themes';
|
|
19
|
+
|
|
20
|
+
export interface PanelContribution {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly title: string;
|
|
23
|
+
readonly location: 'drawer' | 'sidebar';
|
|
24
|
+
readonly icon?: string;
|
|
25
|
+
readonly render: (container: HTMLElement) => void | IDisposable;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface LanguageContribution {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly extensions: readonly string[];
|
|
31
|
+
readonly aliases?: readonly string[];
|
|
32
|
+
readonly runFile?: (filePath: string, source: string) => Promise<{ ok: boolean; stdout: string; stderr: string }>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PluginContributions {
|
|
36
|
+
readonly commands?: readonly CommandDescriptor[];
|
|
37
|
+
readonly settings?: readonly SettingDescriptor[];
|
|
38
|
+
readonly keybindings?: readonly KeybindingRule[];
|
|
39
|
+
readonly themes?: readonly ThemeDefinition[];
|
|
40
|
+
readonly panels?: readonly PanelContribution[];
|
|
41
|
+
readonly languages?: readonly LanguageContribution[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface PluginActivationContext {
|
|
45
|
+
readonly subscriptions: DisposableStore;
|
|
46
|
+
readonly commands: ICommandRegistry;
|
|
47
|
+
readonly configuration: IConfigurationService;
|
|
48
|
+
readonly keybindings: IKeybindingService;
|
|
49
|
+
readonly themes: IThemeService;
|
|
50
|
+
readonly logger: ILogger;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface CodeLabPluginManifest {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly name: string;
|
|
56
|
+
readonly version: string;
|
|
57
|
+
readonly description?: string;
|
|
58
|
+
readonly activationEvents?: readonly string[];
|
|
59
|
+
readonly contributes?: PluginContributions;
|
|
60
|
+
readonly activate?: (ctx: PluginActivationContext) => void | Promise<void> | IDisposable;
|
|
61
|
+
readonly deactivate?: () => void | Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface RegisteredPluginInfo {
|
|
65
|
+
readonly manifest: CodeLabPluginManifest;
|
|
66
|
+
readonly active: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface IPluginRegistry extends IDisposable {
|
|
70
|
+
readonly panels: ContributionRegistry<string, PanelContribution>;
|
|
71
|
+
readonly languages: ContributionRegistry<string, LanguageContribution>;
|
|
72
|
+
readonly onDidChangePlugins: Event<string>;
|
|
73
|
+
registerPlugin(manifest: CodeLabPluginManifest): IDisposable;
|
|
74
|
+
activatePlugin(id: string): Promise<void>;
|
|
75
|
+
deactivatePlugin(id: string): Promise<void>;
|
|
76
|
+
fireActivationEvent(eventName: string): Promise<void>;
|
|
77
|
+
getPlugins(): RegisteredPluginInfo[];
|
|
78
|
+
resolveLanguageForFile(filePath: string): LanguageContribution | undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const IPluginRegistryId = createServiceId<IPluginRegistry>('code-lab.plugins');
|
|
82
|
+
|
|
83
|
+
interface PluginRecord {
|
|
84
|
+
manifest: CodeLabPluginManifest;
|
|
85
|
+
active: boolean;
|
|
86
|
+
manifestDisposables: DisposableStore;
|
|
87
|
+
runtimeDisposables: DisposableStore;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export class PluginRegistry implements IPluginRegistry {
|
|
91
|
+
public readonly panels = new ContributionRegistry<string, PanelContribution>('panels');
|
|
92
|
+
public readonly languages = new ContributionRegistry<string, LanguageContribution>('languages');
|
|
93
|
+
private readonly records = new Map<string, PluginRecord>();
|
|
94
|
+
private readonly changeEmitter = new Emitter<string>({ name: 'plugins.change' });
|
|
95
|
+
private readonly commands: ICommandRegistry;
|
|
96
|
+
private readonly configuration: IConfigurationService;
|
|
97
|
+
private readonly keybindings: IKeybindingService;
|
|
98
|
+
private readonly themes: IThemeService;
|
|
99
|
+
private readonly logger: ILogger;
|
|
100
|
+
|
|
101
|
+
public constructor(deps: {
|
|
102
|
+
commands: ICommandRegistry;
|
|
103
|
+
configuration: IConfigurationService;
|
|
104
|
+
keybindings: IKeybindingService;
|
|
105
|
+
themes: IThemeService;
|
|
106
|
+
logger: ILogger;
|
|
107
|
+
}) {
|
|
108
|
+
this.commands = deps.commands;
|
|
109
|
+
this.configuration = deps.configuration;
|
|
110
|
+
this.keybindings = deps.keybindings;
|
|
111
|
+
this.themes = deps.themes;
|
|
112
|
+
this.logger = deps.logger.child('plugins');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public get onDidChangePlugins(): Event<string> {
|
|
116
|
+
return this.changeEmitter.event;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public registerPlugin(manifest: CodeLabPluginManifest): IDisposable {
|
|
120
|
+
if (!manifest.id || !manifest.name) {
|
|
121
|
+
throw new CodeLabError('ERR_PLUGIN_INVALID', 'Plugin manifest requires non-empty id and name');
|
|
122
|
+
}
|
|
123
|
+
if (this.records.has(manifest.id)) {
|
|
124
|
+
void this.deactivatePlugin(manifest.id);
|
|
125
|
+
this.records.get(manifest.id)?.manifestDisposables.dispose();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const manifestDisposables = new DisposableStore();
|
|
129
|
+
const contributes = manifest.contributes;
|
|
130
|
+
|
|
131
|
+
// Declarative contributions are registered immediately without running plugin code
|
|
132
|
+
if (contributes?.settings) {
|
|
133
|
+
for (const s of contributes.settings) {
|
|
134
|
+
manifestDisposables.add(this.configuration.registerSetting(s));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (contributes?.themes) {
|
|
138
|
+
for (const t of contributes.themes) {
|
|
139
|
+
manifestDisposables.add(this.themes.registerTheme(t));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (contributes?.commands) {
|
|
143
|
+
for (const cmd of contributes.commands) {
|
|
144
|
+
manifestDisposables.add(
|
|
145
|
+
this.commands.registerCommand({
|
|
146
|
+
...cmd,
|
|
147
|
+
handler: async (...args: unknown[]) => {
|
|
148
|
+
await this.activatePlugin(manifest.id);
|
|
149
|
+
return cmd.handler(...args);
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (contributes?.keybindings) {
|
|
156
|
+
for (const kb of contributes.keybindings) {
|
|
157
|
+
manifestDisposables.add(this.keybindings.registerKeybinding({ ...kb, source: 'plugin' }));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (contributes?.panels) {
|
|
161
|
+
for (const panel of contributes.panels) {
|
|
162
|
+
manifestDisposables.add(this.panels.register(panel.id, panel));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (contributes?.languages) {
|
|
166
|
+
for (const lang of contributes.languages) {
|
|
167
|
+
manifestDisposables.add(this.languages.register(lang.id, lang));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const record: PluginRecord = {
|
|
172
|
+
manifest,
|
|
173
|
+
active: false,
|
|
174
|
+
manifestDisposables,
|
|
175
|
+
runtimeDisposables: new DisposableStore()
|
|
176
|
+
};
|
|
177
|
+
this.records.set(manifest.id, record);
|
|
178
|
+
this.changeEmitter.fire(manifest.id);
|
|
179
|
+
|
|
180
|
+
const events = manifest.activationEvents ?? ['*'];
|
|
181
|
+
if (events.includes('*') || events.includes('onStartupFinished')) {
|
|
182
|
+
void this.activatePlugin(manifest.id);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
dispose: (): void => {
|
|
187
|
+
void this.deactivatePlugin(manifest.id);
|
|
188
|
+
record.manifestDisposables.dispose();
|
|
189
|
+
this.records.delete(manifest.id);
|
|
190
|
+
this.changeEmitter.fire(manifest.id);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public async activatePlugin(id: string): Promise<void> {
|
|
196
|
+
const record = this.records.get(id);
|
|
197
|
+
if (!record || record.active) return;
|
|
198
|
+
record.active = true;
|
|
199
|
+
record.runtimeDisposables = new DisposableStore();
|
|
200
|
+
if (record.manifest.activate) {
|
|
201
|
+
try {
|
|
202
|
+
const ret = await record.manifest.activate({
|
|
203
|
+
subscriptions: record.runtimeDisposables,
|
|
204
|
+
commands: this.commands,
|
|
205
|
+
configuration: this.configuration,
|
|
206
|
+
keybindings: this.keybindings,
|
|
207
|
+
themes: this.themes,
|
|
208
|
+
logger: this.logger.child(id)
|
|
209
|
+
});
|
|
210
|
+
if (ret && typeof ret.dispose === 'function') {
|
|
211
|
+
record.runtimeDisposables.add(ret);
|
|
212
|
+
}
|
|
213
|
+
} catch (err) {
|
|
214
|
+
record.active = false;
|
|
215
|
+
this.logger.error(`Plugin "${id}" failed to activate`, err);
|
|
216
|
+
throw err;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
this.changeEmitter.fire(id);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public async deactivatePlugin(id: string): Promise<void> {
|
|
223
|
+
const record = this.records.get(id);
|
|
224
|
+
if (!record || !record.active) return;
|
|
225
|
+
record.active = false;
|
|
226
|
+
try {
|
|
227
|
+
await record.manifest.deactivate?.();
|
|
228
|
+
} catch (err) {
|
|
229
|
+
this.logger.warn(`Plugin "${id}" threw during deactivate`, err);
|
|
230
|
+
}
|
|
231
|
+
record.runtimeDisposables.dispose();
|
|
232
|
+
this.changeEmitter.fire(id);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public async fireActivationEvent(eventName: string): Promise<void> {
|
|
236
|
+
for (const [id, rec] of this.records.entries()) {
|
|
237
|
+
if (rec.active) continue;
|
|
238
|
+
const events = rec.manifest.activationEvents ?? [];
|
|
239
|
+
if (events.includes(eventName) || events.includes('*')) {
|
|
240
|
+
await this.activatePlugin(id);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public getPlugins(): RegisteredPluginInfo[] {
|
|
246
|
+
return Array.from(this.records.values()).map((r) => ({
|
|
247
|
+
manifest: r.manifest,
|
|
248
|
+
active: r.active
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public resolveLanguageForFile(filePath: string): LanguageContribution | undefined {
|
|
253
|
+
const dotIdx = filePath.lastIndexOf('.');
|
|
254
|
+
const ext = dotIdx !== -1 ? filePath.slice(dotIdx).toLowerCase() : '';
|
|
255
|
+
if (!ext) return undefined;
|
|
256
|
+
for (const lang of this.languages.values()) {
|
|
257
|
+
if (lang.extensions.some((e) => e.toLowerCase() === ext)) {
|
|
258
|
+
return lang;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public dispose(): void {
|
|
265
|
+
for (const rec of this.records.values()) {
|
|
266
|
+
rec.runtimeDisposables.dispose();
|
|
267
|
+
rec.manifestDisposables.dispose();
|
|
268
|
+
}
|
|
269
|
+
this.records.clear();
|
|
270
|
+
this.panels.dispose();
|
|
271
|
+
this.languages.dispose();
|
|
272
|
+
this.changeEmitter.dispose();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
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 interface SettingsDialogOptions {
|
|
13
|
+
readonly configuration: IConfigurationService;
|
|
14
|
+
readonly onOpenSettingsJson?: () => void;
|
|
15
|
+
readonly onExportSettings?: (json: string) => void;
|
|
16
|
+
readonly onImportSettings?: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const ALL_CATEGORIES: ReadonlyArray<'All' | SettingCategory> = [
|
|
20
|
+
'All',
|
|
21
|
+
'Editor',
|
|
22
|
+
'Workbench',
|
|
23
|
+
'Files',
|
|
24
|
+
'Terminal',
|
|
25
|
+
'Preview',
|
|
26
|
+
'Runtime',
|
|
27
|
+
'SQL'
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export class SettingsDialogController implements IDisposable {
|
|
31
|
+
private readonly disposables = new DisposableStore();
|
|
32
|
+
private readonly config: IConfigurationService;
|
|
33
|
+
private readonly options: SettingsDialogOptions;
|
|
34
|
+
private dialogEl: HTMLDialogElement | null = null;
|
|
35
|
+
private activeCategory: 'All' | SettingCategory = 'All';
|
|
36
|
+
private searchQuery = '';
|
|
37
|
+
|
|
38
|
+
public constructor(hostRoot: HTMLElement, options: SettingsDialogOptions) {
|
|
39
|
+
this.config = options.configuration;
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.mount(hostRoot);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private mount(hostRoot: HTMLElement): void {
|
|
45
|
+
const doc = hostRoot.ownerDocument ?? document;
|
|
46
|
+
const dialog = doc.createElement('dialog');
|
|
47
|
+
dialog.className = 'codelab-dialog cl-settings-dialog';
|
|
48
|
+
dialog.setAttribute('closedby', 'any');
|
|
49
|
+
dialog.setAttribute('aria-labelledby', 'cl-settings-dialog-title');
|
|
50
|
+
|
|
51
|
+
dialog.innerHTML =
|
|
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="cl-settings-dialog-title" style="margin:0;font-size:15px;font-weight:600;">Settings</h2>` +
|
|
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 settings.json</button>` +
|
|
56
|
+
`<button type="button" class="codelab-btn" data-settings-action="export" title="Export Settings JSON">Export</button>` +
|
|
57
|
+
`<button type="button" class="codelab-btn" data-settings-action="close" aria-label="Close Settings">✕</button>` +
|
|
58
|
+
`</div>` +
|
|
59
|
+
`</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;" />` +
|
|
62
|
+
`</div>` +
|
|
63
|
+
`<div class="cl-settings-body" style="display:grid;grid-template-columns:150px minmax(0,1fr);min-height:320px;max-height:62vh;">` +
|
|
64
|
+
`<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
|
+
`<div data-role="settings-list" style="padding:12px 16px;overflow-y:auto;display:flex;flex-direction:column;gap:12px;"></div>` +
|
|
66
|
+
`</div>`;
|
|
67
|
+
|
|
68
|
+
hostRoot.appendChild(dialog);
|
|
69
|
+
this.dialogEl = dialog;
|
|
70
|
+
|
|
71
|
+
// Reset returnValue on close + Safari fallback for `closedby="any"` light dismiss
|
|
72
|
+
const onClose = (): void => {
|
|
73
|
+
dialog.returnValue = '';
|
|
74
|
+
};
|
|
75
|
+
dialog.addEventListener('close', onClose);
|
|
76
|
+
this.disposables.addFn(() => dialog.removeEventListener('close', onClose));
|
|
77
|
+
|
|
78
|
+
if (typeof HTMLDialogElement !== 'undefined' && !('closedBy' in HTMLDialogElement.prototype)) {
|
|
79
|
+
const onBackdropClick = (evt: MouseEvent): void => {
|
|
80
|
+
if (evt.target !== dialog) return;
|
|
81
|
+
const rect = dialog.getBoundingClientRect();
|
|
82
|
+
const outside =
|
|
83
|
+
evt.clientX < rect.left ||
|
|
84
|
+
evt.clientX > rect.right ||
|
|
85
|
+
evt.clientY < rect.top ||
|
|
86
|
+
evt.clientY > rect.bottom;
|
|
87
|
+
if (outside) dialog.close();
|
|
88
|
+
};
|
|
89
|
+
dialog.addEventListener('click', onBackdropClick);
|
|
90
|
+
this.disposables.addFn(() => dialog.removeEventListener('click', onBackdropClick));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const searchInput = dialog.querySelector('[data-role="settings-search"]') as HTMLInputElement | null;
|
|
94
|
+
if (searchInput) {
|
|
95
|
+
const onInput = (): void => {
|
|
96
|
+
this.searchQuery = searchInput.value.trim().toLowerCase();
|
|
97
|
+
this.renderItems();
|
|
98
|
+
};
|
|
99
|
+
searchInput.addEventListener('input', onInput);
|
|
100
|
+
this.disposables.addFn(() => searchInput.removeEventListener('input', onInput));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const onClick = (evt: Event): void => {
|
|
104
|
+
const target = (evt.target as HTMLElement | null)?.closest?.(
|
|
105
|
+
'[data-settings-action],[data-settings-cat],[data-reset-key]'
|
|
106
|
+
);
|
|
107
|
+
if (!target) return;
|
|
108
|
+
const action = target.getAttribute('data-settings-action');
|
|
109
|
+
if (action === 'close') {
|
|
110
|
+
this.close();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (action === 'open-json') {
|
|
114
|
+
this.close();
|
|
115
|
+
this.options.onOpenSettingsJson?.();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (action === 'export') {
|
|
119
|
+
this.options.onExportSettings?.(this.config.exportProfile());
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const cat = target.getAttribute('data-settings-cat') as ('All' | SettingCategory) | null;
|
|
123
|
+
if (cat) {
|
|
124
|
+
this.activeCategory = cat;
|
|
125
|
+
this.renderCategories();
|
|
126
|
+
this.renderItems();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const resetKey = target.getAttribute('data-reset-key');
|
|
130
|
+
if (resetKey) {
|
|
131
|
+
this.config.resetSetting(resetKey);
|
|
132
|
+
this.renderItems();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
dialog.addEventListener('click', onClick);
|
|
136
|
+
this.disposables.addFn(() => dialog.removeEventListener('click', onClick));
|
|
137
|
+
|
|
138
|
+
const onChange = (evt: Event): void => {
|
|
139
|
+
const el = evt.target as HTMLInputElement | HTMLSelectElement | null;
|
|
140
|
+
if (!el) return;
|
|
141
|
+
const key = el.getAttribute('data-setting-key');
|
|
142
|
+
if (!key) return;
|
|
143
|
+
const desc = this.config.getDescriptors().find((d) => d.key === key);
|
|
144
|
+
if (!desc) return;
|
|
145
|
+
|
|
146
|
+
if (desc.schema.type === 'boolean' && el instanceof HTMLInputElement) {
|
|
147
|
+
this.config.setUserSetting(key, el.checked);
|
|
148
|
+
} else if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
|
|
149
|
+
const num = Number(el.value);
|
|
150
|
+
if (Number.isFinite(num)) {
|
|
151
|
+
this.config.setUserSetting(key, desc.schema.type === 'integer' ? Math.trunc(num) : num);
|
|
152
|
+
}
|
|
153
|
+
} else if (desc.schema.type === 'array') {
|
|
154
|
+
const items = el.value
|
|
155
|
+
.split(',')
|
|
156
|
+
.map((s) => s.trim())
|
|
157
|
+
.filter(Boolean);
|
|
158
|
+
this.config.setUserSetting(key, items);
|
|
159
|
+
} else {
|
|
160
|
+
this.config.setUserSetting(key, el.value);
|
|
161
|
+
}
|
|
162
|
+
this.renderItems();
|
|
163
|
+
};
|
|
164
|
+
dialog.addEventListener('change', onChange);
|
|
165
|
+
this.disposables.addFn(() => dialog.removeEventListener('change', onChange));
|
|
166
|
+
|
|
167
|
+
this.disposables.add(
|
|
168
|
+
this.config.onDidChangeConfiguration(() => {
|
|
169
|
+
if (this.isOpen) {
|
|
170
|
+
this.renderItems();
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public get isOpen(): boolean {
|
|
177
|
+
return Boolean(this.dialogEl && (this.dialogEl.open || this.dialogEl.hasAttribute('open')));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public open(): void {
|
|
181
|
+
if (!this.dialogEl) return;
|
|
182
|
+
this.renderCategories();
|
|
183
|
+
this.renderItems();
|
|
184
|
+
if (typeof this.dialogEl.showModal === 'function') {
|
|
185
|
+
if (!this.dialogEl.open) this.dialogEl.showModal();
|
|
186
|
+
} else {
|
|
187
|
+
this.dialogEl.setAttribute('open', '');
|
|
188
|
+
}
|
|
189
|
+
const searchInput = this.dialogEl.querySelector('[data-role="settings-search"]') as HTMLInputElement | null;
|
|
190
|
+
searchInput?.focus();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public close(): void {
|
|
194
|
+
if (!this.dialogEl) return;
|
|
195
|
+
if (typeof this.dialogEl.close === 'function' && this.dialogEl.open) {
|
|
196
|
+
this.dialogEl.close();
|
|
197
|
+
} else {
|
|
198
|
+
this.dialogEl.removeAttribute('open');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private renderCategories(): void {
|
|
203
|
+
const nav = this.dialogEl?.querySelector('[data-role="settings-categories"]');
|
|
204
|
+
if (!nav) return;
|
|
205
|
+
nav.innerHTML = ALL_CATEGORIES.map((cat) => {
|
|
206
|
+
const selected = cat === this.activeCategory;
|
|
207
|
+
return (
|
|
208
|
+
`<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,#0284c7)' : 'transparent'};background:${selected ? 'rgba(2,132,199,0.15)' : 'transparent'};color:var(--cl-fg,#f5f5f5);cursor:pointer;font-size:12.5px;">` +
|
|
210
|
+
`${escapeAttr(cat)}` +
|
|
211
|
+
`</button>`
|
|
212
|
+
);
|
|
213
|
+
}).join('');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private renderControl(desc: SettingDescriptor, currentVal: unknown): string {
|
|
217
|
+
const keyAttr = escapeAttr(desc.key);
|
|
218
|
+
if (desc.schema.enum && desc.schema.enum.length > 0) {
|
|
219
|
+
const opts = desc.schema.enum
|
|
220
|
+
.map((opt) => {
|
|
221
|
+
const str = String(opt);
|
|
222
|
+
const sel = String(currentVal) === str ? ' selected' : '';
|
|
223
|
+
return `<option value="${escapeAttr(str)}"${sel}>${escapeAttr(str)}</option>`;
|
|
224
|
+
})
|
|
225
|
+
.join('');
|
|
226
|
+
return `<select data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" style="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;">${opts}</select>`;
|
|
227
|
+
}
|
|
228
|
+
if (desc.schema.type === 'boolean') {
|
|
229
|
+
const checked = Boolean(currentVal) ? ' checked' : '';
|
|
230
|
+
return `<input type="checkbox" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}"${checked} />`;
|
|
231
|
+
}
|
|
232
|
+
if (desc.schema.type === 'integer' || desc.schema.type === 'number') {
|
|
233
|
+
const min = desc.schema.minimum !== undefined ? ` min="${desc.schema.minimum}"` : '';
|
|
234
|
+
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;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;" />`;
|
|
236
|
+
}
|
|
237
|
+
if (desc.schema.type === 'array') {
|
|
238
|
+
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;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;" />`;
|
|
240
|
+
}
|
|
241
|
+
return `<input type="text" data-setting-key="${keyAttr}" aria-label="${escapeAttr(desc.title)}" value="${escapeAttr(String(currentVal ?? ''))}" style="width:180px;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;" />`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private renderItems(): void {
|
|
245
|
+
const listEl = this.dialogEl?.querySelector('[data-role="settings-list"]');
|
|
246
|
+
if (!listEl) return;
|
|
247
|
+
const descriptors = this.config.getDescriptors().filter((d) => {
|
|
248
|
+
if (this.activeCategory !== 'All' && d.category !== this.activeCategory) return false;
|
|
249
|
+
if (!this.searchQuery) return true;
|
|
250
|
+
const hay = `${d.key} ${d.title} ${d.description} ${d.category}`.toLowerCase();
|
|
251
|
+
return hay.includes(this.searchQuery);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
if (descriptors.length === 0) {
|
|
255
|
+
listEl.innerHTML = `<div style="color:var(--cl-muted,#8e8e93);font-size:13px;">No matching settings found.</div>`;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
listEl.innerHTML = descriptors
|
|
260
|
+
.map((desc) => {
|
|
261
|
+
const insp = this.config.inspect(desc.key);
|
|
262
|
+
const isModified = insp.effectiveSource !== 'default';
|
|
263
|
+
return (
|
|
264
|
+
`<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
|
+
`<div style="min-width:0;">` +
|
|
266
|
+
`<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;opacity:0.75;">${escapeAttr(desc.key)}</code>` +
|
|
269
|
+
(isModified
|
|
270
|
+
? `<span style="font-size:10px;padding:1px 5px;border-radius:4px;background:rgba(2,132,199,0.2);color:var(--cl-accent,#0284c7);">${escapeAttr(insp.effectiveSource)}</span>`
|
|
271
|
+
: '') +
|
|
272
|
+
`</div>` +
|
|
273
|
+
`<div style="font-size:12px;color:var(--cl-muted,#8e8e93);margin-top:3px;">${escapeAttr(desc.description)}</div>` +
|
|
274
|
+
`</div>` +
|
|
275
|
+
`<div style="display:flex;align-items:center;gap:6px;flex-shrink:0;">` +
|
|
276
|
+
this.renderControl(desc, insp.effectiveValue) +
|
|
277
|
+
(isModified
|
|
278
|
+
? `<button type="button" class="codelab-btn" data-reset-key="${escapeAttr(desc.key)}" title="Reset to Default (${escapeAttr(JSON.stringify(desc.defaultValue))})">Reset</button>`
|
|
279
|
+
: '') +
|
|
280
|
+
`</div>` +
|
|
281
|
+
`</div>`
|
|
282
|
+
);
|
|
283
|
+
})
|
|
284
|
+
.join('');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public dispose(): void {
|
|
288
|
+
this.close();
|
|
289
|
+
this.disposables.dispose();
|
|
290
|
+
this.dialogEl?.remove();
|
|
291
|
+
this.dialogEl = null;
|
|
292
|
+
}
|
|
293
|
+
}
|