@innovatorved/code-lab 0.1.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.
@@ -0,0 +1,348 @@
1
+ /**
2
+ * TypeScript Definitions for @innovatorved/code-lab v1.4.0
3
+ */
4
+
5
+ export interface CodeLabStep {
6
+ id: string;
7
+ title: string;
8
+ concept?: string;
9
+ targetFile?: string;
10
+ targetSymbol?: string;
11
+ instructions: string | string[];
12
+ hint?: string;
13
+ testNames?: string[];
14
+ }
15
+
16
+ export interface CodeLabTestError {
17
+ name: string;
18
+ message: string;
19
+ stack: string;
20
+ actual?: string;
21
+ expected?: string;
22
+ operator?: string;
23
+ }
24
+
25
+ export interface CodeLabTestResultItem {
26
+ index: number;
27
+ name: string;
28
+ status: 'pass' | 'fail';
29
+ passed: boolean;
30
+ durationMs: number;
31
+ error: CodeLabTestError | null;
32
+ }
33
+
34
+ export interface CodeLabFsSnapshotItem {
35
+ path: string;
36
+ size: number;
37
+ isDirectory: boolean;
38
+ mtimeMs: number;
39
+ preview?: string;
40
+ hexPreview?: string;
41
+ }
42
+
43
+ export interface CodeLabHttpTraceItem {
44
+ protocol?: string;
45
+ method?: string;
46
+ port: number;
47
+ url?: string;
48
+ status?: number;
49
+ durationMs: number;
50
+ }
51
+
52
+ export interface CodeLabExecutionOptions {
53
+ files?: Record<string, string>;
54
+ entry?: string;
55
+ mode?: 'run' | 'test' | 'repl';
56
+ replCode?: string;
57
+ printReplResult?: boolean;
58
+ testFilter?: string | string[] | null;
59
+ timeoutMs?: number;
60
+ maxOutputBytes?: number;
61
+ maxConsoleCalls?: number;
62
+ instanceId?: string;
63
+ concurrent?: boolean;
64
+ argv?: string[] | null;
65
+ pid?: number;
66
+ isBackground?: boolean;
67
+ vfs?: any;
68
+ activePortTable?: any;
69
+ packages?: Record<string, any>;
70
+ npmModules?: Record<string, any>;
71
+ onStdout?: (text: string) => void;
72
+ onStderr?: (text: string) => void;
73
+ onTestResult?: (testResult: CodeLabTestResultItem) => void;
74
+ }
75
+
76
+ export interface CodeLabExecutionResult {
77
+ ok: boolean;
78
+ exitCode: number;
79
+ durationMs: number;
80
+ stdout: string;
81
+ stderr: string;
82
+ outputTruncated?: boolean;
83
+ timedOut?: boolean;
84
+ cancelled?: boolean;
85
+ error?: { message: string; stack?: string };
86
+ testResults: CodeLabTestResultItem[];
87
+ testSummary?: {
88
+ total: number;
89
+ passed: number;
90
+ failed: number;
91
+ };
92
+ fsSnapshot: CodeLabFsSnapshotItem[];
93
+ httpTrace: CodeLabHttpTraceItem[];
94
+ replValue?: string;
95
+ replResult?: string;
96
+ }
97
+
98
+ export interface CodeLabCloneOptions {
99
+ intoRoot?: boolean;
100
+ targetDir?: string;
101
+ branch?: string;
102
+ depth?: number;
103
+ maxFiles?: number;
104
+ maxFileSize?: number;
105
+ concurrency?: number;
106
+ clearExisting?: boolean;
107
+ }
108
+
109
+ export interface CodeLabOptions {
110
+ /** Unique identifier used for localStorage persistence */
111
+ id?: string;
112
+ labId?: string;
113
+ buildId?: string;
114
+ /** Title displayed in the IDE header */
115
+ title?: string;
116
+ /** Subtitle / summary displayed in the guide panel when README.md is absent */
117
+ summary?: string;
118
+ /** Initial workbench mode ('guided' | 'sandbox') */
119
+ mode?: 'guided' | 'sandbox';
120
+ /** Initial workspace language ('js' | 'ts') */
121
+ language?: 'js' | 'ts';
122
+ lang?: 'js' | 'ts';
123
+ /** Explicit theme override ('dark' | 'light' | 'auto') */
124
+ theme?: 'dark' | 'light' | 'auto';
125
+ /** Set to false to disable localStorage persistence and use in-memory state only */
126
+ persistState?: boolean;
127
+ /** Public GitHub repository URL or owner/repo shorthand to automatically clone on mount */
128
+ repo?: string;
129
+ githubRepo?: string;
130
+ /** Optional GitHub branch/tag/SHA to clone when repo is specified */
131
+ branch?: string;
132
+ /** Reference/solution files map (filename -> source content) */
133
+ files?: Record<string, string>;
134
+ /** Explicit reference solution files map (JavaScript) */
135
+ solutionFiles?: Record<string, string>;
136
+ /** Initial starter files map for guided mode (JavaScript) */
137
+ starterFiles?: Record<string, string>;
138
+ /** Explicit TypeScript files map for sandbox mode */
139
+ tsFiles?: Record<string, string>;
140
+ tsSolutionFiles?: Record<string, string>;
141
+ /** Explicit TypeScript starter files map for guided mode */
142
+ tsStarterFiles?: Record<string, string>;
143
+ /** Ordered guided steps */
144
+ steps?: CodeLabStep[];
145
+ /** Guided configuration object */
146
+ guided?: {
147
+ starterFiles?: Record<string, string>;
148
+ tsStarterFiles?: Record<string, string>;
149
+ steps?: CodeLabStep[];
150
+ };
151
+ /** Initial active step index (0-based) */
152
+ stepIndex?: number;
153
+ /** Demo entry point file to execute on runDemo() (default: 'demo.js' / 'demo.ts') */
154
+ entry?: string;
155
+ /** Test suite entry point file to execute on runTests() (default: 'test.js' / 'test.ts') */
156
+ testEntry?: string;
157
+ testFile?: string;
158
+ /** Label for the back button when onClose is provided */
159
+ backLabel?: string;
160
+ /** Custom Monaco AMD loader base URL */
161
+ monacoUrl?: string;
162
+ /** Callback fired when the back/close button is clicked */
163
+ onClose?: () => void;
164
+ /** Callback fired when a guided step passes all its testNames */
165
+ onStepComplete?: (step: CodeLabStep, stepIndex: number) => void;
166
+ /** Callback fired when all guided steps in the lab are completed */
167
+ onLabComplete?: (labId: string) => void;
168
+ /** Callback fired whenever runDemo() or runTests() finishes */
169
+ onRun?: (result: CodeLabExecutionResult) => void;
170
+ /** Callback fired when runTests() finishes */
171
+ onTestResult?: (result: CodeLabExecutionResult) => void;
172
+ /** Callback fired whenever a file is edited */
173
+ onCodeChange?: (filename: string, code: string) => void;
174
+ }
175
+
176
+ export declare class CodeLabWorkbench {
177
+ instanceId: string;
178
+ container: HTMLElement;
179
+ labId: string;
180
+ title: string;
181
+ summary: string;
182
+ options: CodeLabOptions;
183
+ files: Record<string, string>;
184
+ openTabs: string[];
185
+ activeFile: string | null;
186
+ mode: 'guided' | 'sandbox';
187
+ lang: 'js' | 'ts';
188
+ activeStepIndex: number;
189
+ completedSteps: Set<string>;
190
+ steps: CodeLabStep[];
191
+ cursorPos: { lineNumber: number; column: number; ln: number; col: number };
192
+ isRunning: boolean;
193
+ isFullscreen: boolean;
194
+ constructor(container: HTMLElement | string, options?: CodeLabOptions);
195
+ runDemo(): Promise<void>;
196
+ runTests(filterTestNames?: string | string[] | null): Promise<void>;
197
+ verifyCurrentStep(): Promise<void>;
198
+ stopExecution(): void;
199
+ cancelExecution(): void;
200
+ selectStep(idx: number, shouldJump?: boolean): void;
201
+ openFile(filename: string, symbolToFind?: string): void;
202
+ closeTab(filename: string): void;
203
+ closeOtherTabs(keepPath: string): void;
204
+ closeAllTabs(): void;
205
+ createFile(rawName: string): string | null;
206
+ createFolder(rawFolderPath: string): boolean;
207
+ renameFile(oldPath: string, newPath: string): boolean;
208
+ renameFolder(oldPrefix: string, newPrefix: string): boolean;
209
+ duplicateFile(path: string): string | null;
210
+ moveFile(oldPath: string, newPath: string): boolean;
211
+ movePath(sourcePath: string, targetFolder: string): boolean;
212
+ startInlineCreate(type: 'file' | 'folder', folderPrefix?: string): void;
213
+ startInlineRename(oldPath: string, isFolder?: boolean): void;
214
+ promptNewFile(folderPrefix?: string): void;
215
+ promptNewFolder(folderPrefix?: string): void;
216
+ deleteFile(filename: string): boolean;
217
+ deleteFolder(folderPrefix: string): boolean;
218
+ setMode(newMode: 'guided' | 'sandbox'): void;
219
+ setLanguage(newLang: 'js' | 'ts'): void;
220
+ switchDrawerTab(tabName: 'tests' | 'terminal' | 'ports' | 'network' | 'inspector'): void;
221
+ configure(opts?: { mode?: 'guided' | 'sandbox'; lang?: 'js' | 'ts'; stepIndex?: number }): void;
222
+ openCommandPalette(mode?: 'commands' | 'files'): void;
223
+ closeCommandPalette(): void;
224
+ openContextMenu(x: number, y: number, items: Array<{ label?: string; action?: () => void; danger?: boolean; separator?: boolean }>): void;
225
+ closeContextMenu(): void;
226
+ showPackagesModal(): void;
227
+ addNpmPackage(rawSpec: string): void;
228
+ showCloneRepoModal(): void;
229
+ cloneRepo(repoUrlOrSlug: string, options?: CodeLabCloneOptions): Promise<any>;
230
+ showSolutionModal(): void;
231
+ showDiffModal(targetFile?: string, compareTarget?: 'solution' | 'starter'): void;
232
+ applyReferenceSolution(): void;
233
+ downloadFile(path?: string): { filename: string; content: string } | null;
234
+ exportWorkspace(options?: { download?: boolean }): Record<string, any>;
235
+ importWorkspace(snapshotOrJson: string | Record<string, any>): boolean;
236
+ getFiles(): Record<string, string>;
237
+ setFiles(filesMap: Record<string, string>, options?: { merge?: boolean }): this;
238
+ getFile(path: string): string | null;
239
+ setFile(path: string, content: string, options?: { open?: boolean }): this;
240
+ getOpenTabs(): string[];
241
+ reset(): this;
242
+ on(event: string, handler: (detail: any) => void): () => void;
243
+ off(event: string, handler: (detail: any) => void): this;
244
+ use(plugin: (workbench: CodeLabWorkbench, options?: any) => any, options?: any): this;
245
+ closeModal(): void;
246
+ resetLab(): void;
247
+ toggleFullscreen(): void;
248
+ destroy(): void;
249
+ }
250
+
251
+ export declare class CodeLabElement extends HTMLElement {
252
+ static observedAttributes: string[];
253
+ _instance: CodeLabWorkbench | null;
254
+ getFiles(): Record<string, string>;
255
+ setFiles(filesMap: Record<string, string>, options?: { merge?: boolean }): CodeLabWorkbench | undefined;
256
+ getFile(path: string): string | null;
257
+ setFile(path: string, content: string, options?: { open?: boolean }): CodeLabWorkbench | undefined;
258
+ deleteFile(path: string): boolean;
259
+ getOpenTabs(): string[];
260
+ reset(): CodeLabWorkbench | undefined;
261
+ on(event: string, handler: (detail: any) => void): (() => void) | undefined;
262
+ off(event: string, handler: (detail: any) => void): CodeLabWorkbench | undefined;
263
+ use(plugin: (workbench: CodeLabWorkbench, options?: any) => any, options?: any): CodeLabWorkbench | undefined;
264
+ openCommandPalette(mode?: 'commands' | 'files'): void;
265
+ showDiffModal(targetFile?: string, compareTarget?: 'solution' | 'starter'): void;
266
+ exportWorkspace(options?: { download?: boolean }): Record<string, any> | null;
267
+ importWorkspace(snapshotOrJson: string | Record<string, any>): boolean;
268
+ cloneRepo(repoUrlOrSlug: string, options?: CodeLabCloneOptions): Promise<any>;
269
+ }
270
+
271
+ export interface CodeLabRuntimeAPI {
272
+ executeInVirtualRuntime(options?: CodeLabExecutionOptions): Promise<CodeLabExecutionResult>;
273
+ executeInWorker(options?: CodeLabExecutionOptions): Promise<CodeLabExecutionResult>;
274
+ cancelWorkerExecution(reason?: string, instanceId?: string): boolean;
275
+ preloadNpmPackages(files?: Record<string, string>, existingCache?: Map<string, string>): Promise<Record<string, string>>;
276
+ transpileTS(source: string, filename?: string): string;
277
+ createVirtualFs(initialFiles?: Record<string, string>): any;
278
+ createVirtualHttp(resourceTracker?: any, sharedTrace?: any[], activePortTable?: any): any;
279
+ createVirtualNet(resourceTracker?: any, sharedTrace?: any[], activePortTable?: any): any;
280
+ createVirtualPortTable(): any;
281
+ }
282
+
283
+ export declare const CodeLabRuntime: CodeLabRuntimeAPI;
284
+ export declare const executeInVirtualRuntime: CodeLabRuntimeAPI['executeInVirtualRuntime'];
285
+ export declare const executeInWorker: CodeLabRuntimeAPI['executeInWorker'];
286
+ export declare const cancelWorkerExecution: CodeLabRuntimeAPI['cancelWorkerExecution'];
287
+ export declare const preloadNpmPackages: CodeLabRuntimeAPI['preloadNpmPackages'];
288
+ export declare const transpileTS: CodeLabRuntimeAPI['transpileTS'];
289
+ export declare const createVirtualFs: CodeLabRuntimeAPI['createVirtualFs'];
290
+ export declare const createVirtualHttp: CodeLabRuntimeAPI['createVirtualHttp'];
291
+ export declare const createVirtualNet: CodeLabRuntimeAPI['createVirtualNet'];
292
+ export declare const createVirtualPortTable: CodeLabRuntimeAPI['createVirtualPortTable'];
293
+
294
+ export interface CodeLabShellAPI {
295
+ createPosixShell(options?: any): any;
296
+ PosixShell: any;
297
+ parseShellCommand(cmd: string): any;
298
+ tokenizeShell(cmd: string): any;
299
+ COREUTILS: Record<string, any>;
300
+ PosixPath: any;
301
+ expandGlob(pattern: string, cwd: string, vfs: any): string[];
302
+ createVirtualPortTable(): any;
303
+ parseGitHubRepoUrl(input: string): {
304
+ owner: string;
305
+ repo: string;
306
+ branch: string | null;
307
+ subpath: string;
308
+ fullName: string;
309
+ httpsUrl: string;
310
+ gitUrl: string;
311
+ } | null;
312
+ cloneGitHubRepository(repoInput: string, vfs: any, options?: CodeLabCloneOptions): Promise<any>;
313
+ }
314
+
315
+ export interface CodeLabTerminalAPI {
316
+ PTYTerminalEngine: any;
317
+ createTerminal(container?: HTMLElement | string | Record<string, any>, options?: any): any;
318
+ createPTYTerminalEngine(container?: HTMLElement | string | Record<string, any>, options?: any): any;
319
+ ansiToHtml(text: string): string;
320
+ parseAnsiToHtml(text: string): string;
321
+ }
322
+
323
+ export declare const CodeLabShell: CodeLabShellAPI;
324
+ export declare const CodeLabTerminal: CodeLabTerminalAPI;
325
+ export declare const createPosixShell: CodeLabShellAPI['createPosixShell'];
326
+ export declare const parseGitHubRepoUrl: CodeLabShellAPI['parseGitHubRepoUrl'];
327
+ export declare const cloneGitHubRepository: CodeLabShellAPI['cloneGitHubRepository'];
328
+ export declare const createTerminal: CodeLabTerminalAPI['createTerminal'];
329
+ export declare const createPTYTerminalEngine: CodeLabTerminalAPI['createPTYTerminalEngine'];
330
+ export declare const PTYTerminalEngine: any;
331
+
332
+ export interface CodeLabStatic {
333
+ version: string;
334
+ Workbench: typeof CodeLabWorkbench;
335
+ CodeLabWorkbench: typeof CodeLabWorkbench;
336
+ CodeLabElement: typeof CodeLabElement;
337
+ Runtime: CodeLabRuntimeAPI;
338
+ Shell: CodeLabShellAPI;
339
+ Terminal: CodeLabTerminalAPI;
340
+ create(container: HTMLElement | string, options?: CodeLabOptions): CodeLabWorkbench | null;
341
+ mount(container: HTMLElement | string, options?: CodeLabOptions): CodeLabWorkbench | null;
342
+ unmount(container: HTMLElement | string): void;
343
+ cloneRepo(vfsOrWorkbench: any, repoInput: string, options?: CodeLabCloneOptions): Promise<any>;
344
+ parseGitHubRepoUrl: CodeLabShellAPI['parseGitHubRepoUrl'];
345
+ }
346
+
347
+ export declare const CodeLab: CodeLabStatic;
348
+ export default CodeLab;