@innovatorved/code-lab 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +30 -0
  3. package/README.md +6 -6
  4. package/dist/code-lab-sql.esm.js +19 -19
  5. package/dist/code-lab-sql.umd.js +20 -20
  6. package/dist/code-lab.css +1 -1
  7. package/dist/code-lab.d.ts +47 -38
  8. package/dist/code-lab.esm.js +1183 -1909
  9. package/dist/code-lab.js +1182 -1906
  10. package/dist/extensions/cpp.esm.js +132 -8760
  11. package/dist/extensions/cpp.js +124 -8770
  12. package/dist/extensions/guided-lab.esm.js +33 -6836
  13. package/dist/extensions/guided-lab.js +33 -6854
  14. package/dist/extensions/javascript.esm.js +1 -36
  15. package/dist/extensions/javascript.js +1 -58
  16. package/dist/extensions/python.esm.js +113 -8122
  17. package/dist/extensions/python.js +113 -8140
  18. package/dist/extensions/typescript.esm.js +1 -55
  19. package/dist/extensions/typescript.js +1 -77
  20. package/dist/index.d.ts +1 -1
  21. package/dist/logger.d.ts +4 -20
  22. package/dist/modular-kernel.d.ts +0 -5
  23. package/dist/packages/core/src/errors.d.ts +5 -1
  24. package/dist/packages/fs/src/backends.d.ts +0 -27
  25. package/dist/packages/fs/src/index.d.ts +1 -1
  26. package/dist/packages/ui/src/html.d.ts +1 -0
  27. package/dist/packages/ui/src/index.d.ts +1 -0
  28. package/dist/{apps/web/src/index.d.ts → packages/ui/src/kernel.d.ts} +3 -11
  29. package/dist/packages/ui/src/observability.d.ts +1 -1
  30. package/dist/packages/ui/src/settings-dialog.d.ts +0 -1
  31. package/dist/preview-sw.js +1 -1
  32. package/dist/runtime.d.ts +3 -0
  33. package/dist/runtime.esm.js +78 -78
  34. package/dist/runtime.js +78 -78
  35. package/dist/schemas.d.ts +10 -1
  36. package/dist/schemas.esm.js +33 -6815
  37. package/dist/schemas.js +33 -6831
  38. package/dist/shell.esm.js +277 -285
  39. package/dist/shell.js +277 -285
  40. package/dist/terminal.esm.js +9 -7
  41. package/dist/terminal.js +7 -7
  42. package/dist/workbench/command-palette.d.ts +0 -4
  43. package/dist/workbench/editor.d.ts +0 -4
  44. package/dist/workbench/index.d.ts +0 -22
  45. package/dist/workbench/intellisense.d.ts +1 -8
  46. package/dist/workbench/xterm-adapter.d.ts +0 -1
  47. package/package.json +4 -13
  48. package/dist/code-lab.umd.js +0 -6117
  49. package/dist/packages/editor/src/index.d.ts +0 -118
  50. package/dist/packages/preview/src/index.d.ts +0 -34
  51. package/dist/packages/runtime/src/index.d.ts +0 -47
  52. package/dist/packages/terminal/src/index.d.ts +0 -54
  53. package/dist/workbench/drawer.d.ts +0 -18
  54. package/dist/workbench/file-tree.d.ts +0 -11
  55. package/dist/workbench/guided-pane.d.ts +0 -11
  56. package/dist/workbench/styles.d.ts +0 -4
  57. package/dist/workbench/toolbar.d.ts +0 -17
  58. package/packages/commands/README.md +0 -7
  59. package/packages/commands/package.json +0 -16
  60. package/packages/commands/src/index.ts +0 -467
  61. package/packages/commands/tsconfig.json +0 -22
  62. package/packages/core/README.md +0 -12
  63. package/packages/core/package.json +0 -13
  64. package/packages/core/src/di.ts +0 -147
  65. package/packages/core/src/disposable.ts +0 -112
  66. package/packages/core/src/errors.ts +0 -205
  67. package/packages/core/src/events.ts +0 -157
  68. package/packages/core/src/index.ts +0 -49
  69. package/packages/core/src/path.ts +0 -118
  70. package/packages/core/src/registry.ts +0 -61
  71. package/packages/core/tsconfig.json +0 -19
  72. package/packages/editor/README.md +0 -9
  73. package/packages/editor/package.json +0 -18
  74. package/packages/editor/src/index.ts +0 -344
  75. package/packages/editor/tsconfig.json +0 -24
  76. package/packages/fs/README.md +0 -7
  77. package/packages/fs/package.json +0 -16
  78. package/packages/fs/src/backends.ts +0 -301
  79. package/packages/fs/src/index.ts +0 -18
  80. package/packages/fs/src/types.ts +0 -44
  81. package/packages/fs/src/vfs-service.ts +0 -257
  82. package/packages/fs/tsconfig.json +0 -22
  83. package/packages/preview/README.md +0 -3
  84. package/packages/preview/package.json +0 -16
  85. package/packages/preview/src/index.ts +0 -125
  86. package/packages/preview/tsconfig.json +0 -22
  87. package/packages/runtime/README.md +0 -3
  88. package/packages/runtime/package.json +0 -17
  89. package/packages/runtime/src/index.ts +0 -134
  90. package/packages/runtime/tsconfig.json +0 -23
  91. package/packages/settings/README.md +0 -7
  92. package/packages/settings/package.json +0 -16
  93. package/packages/settings/src/builtin-schemas.ts +0 -262
  94. package/packages/settings/src/configuration-service.ts +0 -609
  95. package/packages/settings/src/index.ts +0 -38
  96. package/packages/settings/src/jsonc.ts +0 -189
  97. package/packages/settings/src/schema.ts +0 -164
  98. package/packages/settings/tsconfig.json +0 -22
  99. package/packages/sql/README.md +0 -12
  100. package/packages/sql/package.json +0 -13
  101. package/packages/sql/src/completions.ts +0 -359
  102. package/packages/sql/src/diagnostics.ts +0 -200
  103. package/packages/sql/src/formatter.ts +0 -271
  104. package/packages/sql/src/index.ts +0 -54
  105. package/packages/sql/src/sql-editor.ts +0 -802
  106. package/packages/sql/src/styles.ts +0 -524
  107. package/packages/sql/src/tokenizer.ts +0 -457
  108. package/packages/sql/src/types.ts +0 -148
  109. package/packages/sql/tsconfig.json +0 -19
  110. package/packages/terminal/README.md +0 -3
  111. package/packages/terminal/package.json +0 -16
  112. package/packages/terminal/src/index.ts +0 -183
  113. package/packages/terminal/tsconfig.json +0 -22
  114. package/packages/ui/README.md +0 -8
  115. package/packages/ui/package.json +0 -18
  116. package/packages/ui/src/index.ts +0 -40
  117. package/packages/ui/src/observability.ts +0 -173
  118. package/packages/ui/src/plugin-registry.ts +0 -289
  119. package/packages/ui/src/settings-dialog.ts +0 -939
  120. package/packages/ui/src/themes.ts +0 -333
  121. package/packages/ui/tsconfig.json +0 -24
  122. package/src/code-lab.css +0 -8584
  123. package/src/csp.ts +0 -590
  124. package/src/diagnostics.ts +0 -287
  125. package/src/extensions/cpp.ts +0 -2389
  126. package/src/extensions/guided-lab.ts +0 -64
  127. package/src/extensions/javascript.ts +0 -54
  128. package/src/extensions/python.ts +0 -1737
  129. package/src/extensions/typescript.ts +0 -85
  130. package/src/extensions/umbrella.ts +0 -5
  131. package/src/html.ts +0 -88
  132. package/src/index.ts +0 -129
  133. package/src/logger.ts +0 -139
  134. package/src/modular-kernel.ts +0 -11
  135. package/src/preview-sw.js +0 -296
  136. package/src/runtime/test-harness.ts +0 -57
  137. package/src/runtime.ts +0 -10480
  138. package/src/sample.html +0 -304
  139. package/src/schemas.ts +0 -366
  140. package/src/scm.ts +0 -2453
  141. package/src/search.ts +0 -433
  142. package/src/shell.ts +0 -10987
  143. package/src/storage.ts +0 -773
  144. package/src/terminal.ts +0 -1400
  145. package/src/workbench/command-palette.ts +0 -381
  146. package/src/workbench/diff-editor.ts +0 -470
  147. package/src/workbench/drawer.ts +0 -157
  148. package/src/workbench/editor.ts +0 -49
  149. package/src/workbench/file-tree.ts +0 -51
  150. package/src/workbench/guided-pane.ts +0 -43
  151. package/src/workbench/icons.ts +0 -255
  152. package/src/workbench/index.ts +0 -44
  153. package/src/workbench/intellisense.ts +0 -1871
  154. package/src/workbench/share.ts +0 -128
  155. package/src/workbench/styles.ts +0 -211
  156. package/src/workbench/toolbar.ts +0 -182
  157. package/src/workbench/xterm-adapter.ts +0 -1571
  158. package/src/workbench.ts +0 -22132
  159. package/src/zip.ts +0 -348
@@ -1,183 +0,0 @@
1
- import {
2
- CodeLabError,
3
- createServiceId,
4
- Emitter,
5
- type Event,
6
- type IDisposable
7
- } from '@code-lab/core';
8
-
9
- export interface AnsiSegment {
10
- readonly text: string;
11
- readonly fg?: string;
12
- readonly bold?: boolean;
13
- }
14
-
15
- const SGR_COLORS: Readonly<Record<number, string>> = {
16
- 30: '#525252',
17
- 31: '#ef4444',
18
- 32: '#22c55e',
19
- 33: '#eab308',
20
- 34: '#3b82f6',
21
- 35: '#a855f7',
22
- 36: '#06b6d4',
23
- 37: '#e5e5e5',
24
- 90: '#737373',
25
- 91: '#f87171',
26
- 92: '#4ade80',
27
- 93: '#facc15',
28
- 94: '#60a5fa',
29
- 95: '#c084fc',
30
- 96: '#22d3ee',
31
- 97: '#ffffff'
32
- };
33
-
34
- export function parseAnsiSegments(input: string): AnsiSegment[] {
35
- const segments: AnsiSegment[] = [];
36
- // eslint-disable-next-line no-control-regex
37
- const sgrRegex = /\x1b\[([0-9;]*)m/g;
38
- let lastIdx = 0;
39
- let fg: string | undefined;
40
- let bold = false;
41
- let match: RegExpExecArray | null;
42
-
43
- while ((match = sgrRegex.exec(input)) !== null) {
44
- if (match.index > lastIdx) {
45
- segments.push({
46
- text: input.slice(lastIdx, match.index),
47
- ...(fg ? { fg } : {}),
48
- ...(bold ? { bold: true } : {})
49
- });
50
- }
51
- const codes = match[1] ? match[1].split(';').map((n) => Number(n)) : [0];
52
- for (const code of codes) {
53
- if (code === 0) {
54
- fg = undefined;
55
- bold = false;
56
- } else if (code === 1) {
57
- bold = true;
58
- } else if (code === 22) {
59
- bold = false;
60
- } else if (code === 39) {
61
- fg = undefined;
62
- } else if (SGR_COLORS[code]) {
63
- fg = SGR_COLORS[code];
64
- }
65
- }
66
- lastIdx = sgrRegex.lastIndex;
67
- }
68
-
69
- if (lastIdx < input.length) {
70
- segments.push({
71
- text: input.slice(lastIdx),
72
- ...(fg ? { fg } : {}),
73
- ...(bold ? { bold: true } : {})
74
- });
75
- }
76
- return segments;
77
- }
78
-
79
- export interface TerminalSession {
80
- readonly id: string;
81
- readonly title: string;
82
- readonly cwd: string;
83
- readonly lines: readonly string[];
84
- write(chunk: string): void;
85
- clear(): void;
86
- }
87
-
88
- export interface ITerminalService extends IDisposable {
89
- readonly activeSessionId: string | undefined;
90
- readonly onDidWrite: Event<{ sessionId: string; chunk: string }>;
91
- readonly onDidChangeSessions: Event<void>;
92
- createSession(options?: { title?: string; cwd?: string; maxScrollback?: number }): TerminalSession;
93
- getSessions(): TerminalSession[];
94
- setActiveSession(id: string): void;
95
- closeSession(id: string): void;
96
- }
97
-
98
- export const ITerminalServiceId = createServiceId<ITerminalService>('code-lab.terminal');
99
-
100
- export class TerminalService implements ITerminalService {
101
- private readonly sessions = new Map<string, TerminalSession & { _setLines: (l: string[]) => void }>();
102
- private currentSessionId: string | undefined;
103
- private seq = 0;
104
- private readonly writeEmitter = new Emitter<{ sessionId: string; chunk: string }>({ name: 'terminal.write' });
105
- private readonly sessionsEmitter = new Emitter<void>({ name: 'terminal.sessions' });
106
-
107
- public get activeSessionId(): string | undefined {
108
- return this.currentSessionId;
109
- }
110
-
111
- public get onDidWrite(): Event<{ sessionId: string; chunk: string }> {
112
- return this.writeEmitter.event;
113
- }
114
-
115
- public get onDidChangeSessions(): Event<void> {
116
- return this.sessionsEmitter.event;
117
- }
118
-
119
- public createSession(
120
- options: { title?: string; cwd?: string; maxScrollback?: number } = {}
121
- ): TerminalSession {
122
- const id = `term-${++this.seq}`;
123
- const title = options.title ?? `zsh ${this.seq}`;
124
- const cwd = options.cwd ?? '/workspace';
125
- const maxScrollback = Math.max(50, options.maxScrollback ?? 1000);
126
- let buffer: string[] = [];
127
-
128
- const session: TerminalSession & { _setLines: (l: string[]) => void } = {
129
- id,
130
- title,
131
- cwd,
132
- get lines(): readonly string[] {
133
- return buffer;
134
- },
135
- write: (chunk: string): void => {
136
- const incoming = chunk.split('\n');
137
- buffer.push(...incoming);
138
- if (buffer.length > maxScrollback) {
139
- buffer = buffer.slice(buffer.length - maxScrollback);
140
- }
141
- this.writeEmitter.fire({ sessionId: id, chunk });
142
- },
143
- clear: (): void => {
144
- buffer = [];
145
- },
146
- _setLines: (l: string[]): void => {
147
- buffer = l;
148
- }
149
- };
150
-
151
- this.sessions.set(id, session);
152
- this.currentSessionId = id;
153
- this.sessionsEmitter.fire();
154
- return session;
155
- }
156
-
157
- public getSessions(): TerminalSession[] {
158
- return Array.from(this.sessions.values());
159
- }
160
-
161
- public setActiveSession(id: string): void {
162
- if (!this.sessions.has(id)) {
163
- throw new CodeLabError('ERR_INVALID_ARGUMENT', `Terminal session "${id}" does not exist`);
164
- }
165
- this.currentSessionId = id;
166
- this.sessionsEmitter.fire();
167
- }
168
-
169
- public closeSession(id: string): void {
170
- if (!this.sessions.delete(id)) return;
171
- if (this.currentSessionId === id) {
172
- this.currentSessionId = this.sessions.keys().next().value;
173
- }
174
- this.sessionsEmitter.fire();
175
- }
176
-
177
- public dispose(): void {
178
- this.sessions.clear();
179
- this.currentSessionId = undefined;
180
- this.writeEmitter.dispose();
181
- this.sessionsEmitter.dispose();
182
- }
183
- }
@@ -1,22 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "lib": ["ES2022", "DOM"],
7
- "strict": true,
8
- "noImplicitAny": true,
9
- "strictNullChecks": true,
10
- "noUnusedLocals": true,
11
- "noUnusedParameters": true,
12
- "noImplicitReturns": true,
13
- "noFallthroughCasesInSwitch": true,
14
- "noEmit": true,
15
- "skipLibCheck": true,
16
- "forceConsistentCasingInFileNames": true,
17
- "paths": {
18
- "@code-lab/core": ["../core/src/index.ts"]
19
- }
20
- },
21
- "include": ["src/**/*.ts"]
22
- }
@@ -1,8 +0,0 @@
1
- # `@code-lab/ui`
2
-
3
- Layer 3 (`workbench`) UI controllers, theming, plugin contribution points, and developer observability for **CodeLab**:
4
-
5
- - `ThemeService` — built-in `dark`, `light`, and `high-contrast` themes plus JSON custom theme loader (`parseCustomTheme`).
6
- - `SettingsDialogController` — searchable modal `<dialog closedby="any">` Settings UI with category filters, Reset to Default, Export, and Open `.codelab/settings.json`.
7
- - `PluginRegistry` — VS Code-inspired declarative contribution points (`commands`, `settings`, `keybindings`, `themes`, `panels`, `languages`) with lazy activation events and clean `IDisposable` deactivation.
8
- - `renderObservabilityPanelHtml` & `WorkbenchErrorBoundary` — Dev Observability Inspector and user-visible error boundary.
@@ -1,18 +0,0 @@
1
- {
2
- "name": "@code-lab/ui",
3
- "version": "0.7.0",
4
- "description": "Workbench UI services and components for CodeLab: ThemeService (dark/light/high-contrast/custom), Searchable Settings Dialog, Quick Open, PluginRegistry, ErrorBoundary, and Dev Observability Inspector.",
5
- "type": "module",
6
- "main": "./src/index.ts",
7
- "types": "./src/index.ts",
8
- "exports": {
9
- ".": "./src/index.ts"
10
- },
11
- "dependencies": {
12
- "@code-lab/core": "workspace:*",
13
- "@code-lab/settings": "workspace:*",
14
- "@code-lab/commands": "workspace:*"
15
- },
16
- "sideEffects": false,
17
- "license": "MIT"
18
- }
@@ -1,40 +0,0 @@
1
- export {
2
- type ThemeKind,
3
- type ThemeDefinition,
4
- type IThemeService,
5
- DARK_THEME,
6
- LIGHT_THEME,
7
- HIGH_CONTRAST_THEME,
8
- IThemeServiceId,
9
- pickContrastingFg,
10
- parseCustomTheme,
11
- ThemeService
12
- } from './themes';
13
-
14
- export {
15
- type PanelContribution,
16
- type LanguageContribution,
17
- type PluginContributions,
18
- type PluginActivationContext,
19
- type CodeLabPluginManifest,
20
- type RegisteredPluginInfo,
21
- type IPluginRegistry,
22
- IPluginRegistryId,
23
- PluginRegistry
24
- } from './plugin-registry';
25
-
26
- export {
27
- type SettingsScope,
28
- type SettingsInlineMountOptions,
29
- type SettingsOpenOptions,
30
- type SettingsDialogOptions,
31
- SettingsDialogController
32
- } from './settings-dialog';
33
-
34
- export {
35
- type ObservabilitySnapshotInput,
36
- scoreFuzzyFileMatch,
37
- rankWorkspaceFiles,
38
- renderObservabilityPanelHtml,
39
- WorkbenchErrorBoundary
40
- } from './observability';
@@ -1,173 +0,0 @@
1
- import type { EventTraceRecord, ILogger, IServiceContainer, LogEntry } from '@code-lab/core';
2
- import type { IConfigurationService } from '@code-lab/settings';
3
- import type { IPluginRegistry } from './plugin-registry';
4
-
5
- function escapeHtml(raw: string): string {
6
- return raw
7
- .replace(/&/g, '&amp;')
8
- .replace(/</g, '&lt;')
9
- .replace(/>/g, '&gt;')
10
- .replace(/"/g, '&quot;');
11
- }
12
-
13
- export function scoreFuzzyFileMatch(candidatePath: string, query: string): number {
14
- if (!query) return 1;
15
- const cleanQuery = query.toLowerCase().replace(/\s+/g, '');
16
- const lowerPath = candidatePath.toLowerCase();
17
- if (lowerPath === cleanQuery) return 1000;
18
- const baseIdx = lowerPath.lastIndexOf('/');
19
- const baseName = baseIdx === -1 ? lowerPath : lowerPath.slice(baseIdx + 1);
20
- if (baseName.startsWith(cleanQuery)) return 500 - baseName.length;
21
- if (lowerPath.includes(cleanQuery)) return 300 - lowerPath.length;
22
-
23
- let qIdx = 0;
24
- let score = 0;
25
- let streak = 0;
26
- for (let i = 0; i < lowerPath.length && qIdx < cleanQuery.length; i++) {
27
- if (lowerPath[i] === cleanQuery[qIdx]) {
28
- qIdx++;
29
- streak++;
30
- score += 10 + streak * 4;
31
- } else {
32
- streak = 0;
33
- }
34
- }
35
- return qIdx === cleanQuery.length ? score : -1;
36
- }
37
-
38
- export function rankWorkspaceFiles(
39
- filePaths: readonly string[],
40
- query: string,
41
- excludePatterns: readonly string[] = []
42
- ): string[] {
43
- const filtered = filePaths.filter((p) => {
44
- for (const ex of excludePatterns) {
45
- const token = ex.replace(/\*\*/g, '').replace(/\*/g, '').replace(/^\/+|\/+$/g, '');
46
- if (token && p.includes(token)) return false;
47
- }
48
- return true;
49
- });
50
- const scored: Array<{ path: string; score: number }> = [];
51
- for (const p of filtered) {
52
- const score = scoreFuzzyFileMatch(p, query);
53
- if (score >= 0) scored.push({ path: p, score });
54
- }
55
- scored.sort((a, b) => b.score - a.score || a.path.localeCompare(b.path));
56
- return scored.map((s) => s.path);
57
- }
58
-
59
- export interface ObservabilitySnapshotInput {
60
- readonly container: IServiceContainer;
61
- readonly configuration: IConfigurationService;
62
- readonly plugins: IPluginRegistry;
63
- readonly logger: ILogger;
64
- readonly recentEvents: readonly EventTraceRecord[];
65
- readonly workerStatus?: string;
66
- }
67
-
68
- export function renderObservabilityPanelHtml(input: ObservabilitySnapshotInput): string {
69
- const serviceIds = input.container.listRegisteredIds();
70
- const plugins = input.plugins.getPlugins();
71
- const logs: readonly LogEntry[] = input.logger.getRecentEntries().slice(-15).reverse();
72
- const events = input.recentEvents.slice(-15).reverse();
73
- const configDiags = input.configuration.getDiagnostics();
74
-
75
- return (
76
- `<div class="cl-observability-panel">` +
77
- `<section class="cl-observability-card">` +
78
- `<strong>Services & Runtime (${serviceIds.length})</strong>` +
79
- `<div class="cl-observability-meta">Worker Host: <code>${escapeHtml(input.workerStatus ?? 'ready')}</code></div>` +
80
- `<ul class="cl-observability-list">` +
81
- serviceIds.map((id) => `<li><code>${escapeHtml(id)}</code></li>`).join('') +
82
- `</ul>` +
83
- `</section>` +
84
- `<section class="cl-observability-card">` +
85
- `<strong>Plugins (${plugins.length}) & Config Diagnostics (${configDiags.length})</strong>` +
86
- `<ul class="cl-observability-list">` +
87
- (plugins.length > 0
88
- ? plugins
89
- .map(
90
- (p) =>
91
- `<li><code>${escapeHtml(p.manifest.id)}</code> v${escapeHtml(p.manifest.version)} — ${p.active ? 'active' : 'lazy'}</li>`
92
- )
93
- .join('')
94
- : `<li>No external plugins registered</li>`) +
95
- `</ul>` +
96
- (configDiags.length > 0
97
- ? `<div class="cl-observability-warn">` +
98
- configDiags.map((d) => `<div>⚠ ${escapeHtml(d.message)}</div>`).join('') +
99
- `</div>`
100
- : '') +
101
- `</section>` +
102
- `<section class="cl-observability-card">` +
103
- `<strong>Recent Event Bus (${events.length})</strong>` +
104
- `<ul class="cl-observability-list cl-observability-list--scroll">` +
105
- (events.length > 0
106
- ? events
107
- .map(
108
- (e) =>
109
- `<li><code>${escapeHtml(e.channel)}</code> (${e.listenerCount}) — ${escapeHtml(e.payloadSummary)}</li>`
110
- )
111
- .join('')
112
- : `<li>No events recorded yet</li>`) +
113
- `</ul>` +
114
- `</section>` +
115
- `<section class="cl-observability-card">` +
116
- `<strong>Recent Logs (${logs.length})</strong>` +
117
- `<ul class="cl-observability-list cl-observability-list--scroll">` +
118
- (logs.length > 0
119
- ? logs
120
- .map(
121
- (l) =>
122
- `<li><strong>[${escapeHtml(l.level)}]</strong> <code>${escapeHtml(l.scope)}</code>: ${escapeHtml(l.message)}</li>`
123
- )
124
- .join('')
125
- : `<li>No log entries</li>`) +
126
- `</ul>` +
127
- `</section>` +
128
- `</div>`
129
- );
130
- }
131
-
132
- export class WorkbenchErrorBoundary {
133
- private readonly host: HTMLElement;
134
- private readonly logger: ILogger;
135
- private bannerEl: HTMLElement | null = null;
136
-
137
- public constructor(host: HTMLElement, logger: ILogger) {
138
- this.host = host;
139
- this.logger = logger.child('error-boundary');
140
- }
141
-
142
- public capture(error: unknown, contextLabel = 'Workbench operation'): void {
143
- const msg = error instanceof Error ? error.message : String(error);
144
- this.logger.error(`${contextLabel} failed: ${msg}`, error);
145
- const doc = this.host.ownerDocument ?? document;
146
- if (!this.bannerEl) {
147
- this.bannerEl = doc.createElement('div');
148
- this.bannerEl.className = 'cl-error-boundary-banner';
149
- this.bannerEl.setAttribute('role', 'alert');
150
- if (typeof this.host.prepend === 'function') {
151
- this.host.prepend(this.bannerEl);
152
- } else {
153
- this.host.appendChild(this.bannerEl);
154
- }
155
- }
156
- this.bannerEl.innerHTML =
157
- `<span><strong>${escapeHtml(contextLabel)}:</strong> ${escapeHtml(msg)}</span>` +
158
- `<button type="button" class="codelab-btn cl-ui-btn" data-dismiss-error="1">Dismiss</button>`;
159
- const dismissBtn = this.bannerEl.querySelector('[data-dismiss-error]');
160
- dismissBtn?.addEventListener(
161
- 'click',
162
- () => {
163
- this.clear();
164
- },
165
- { once: true }
166
- );
167
- }
168
-
169
- public clear(): void {
170
- this.bannerEl?.remove();
171
- this.bannerEl = null;
172
- }
173
- }