@panyam/tsappkit 0.0.3 → 0.0.4
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/dist/docs/DocsPage.css +471 -0
- package/dist/docs/DocsPage.css.map +1 -0
- package/dist/docs/DocsPage.min.css +1 -0
- package/dist/docs/DocsPage.min.css.map +1 -0
- package/dist/docs/index.d.mts +91 -0
- package/dist/docs/index.d.ts +91 -0
- package/dist/docs/index.js +232 -0
- package/dist/docs/index.js.map +1 -0
- package/dist/docs/index.mjs +226 -0
- package/dist/docs/index.mjs.map +1 -0
- package/package.json +34 -13
- package/src/docs/ActionCompiler.ts +186 -0
- package/src/docs/CodeBlock.ts +103 -0
- package/src/docs/index.ts +13 -0
- package/src/docs/pageSetup.ts +32 -0
- package/styles/docs/DocsPage.scss +22 -0
- package/styles/docs/_base.scss +39 -0
- package/styles/docs/_content.scss +122 -0
- package/styles/docs/_footer.scss +56 -0
- package/styles/docs/_header.scss +157 -0
- package/styles/docs/_layout.scss +77 -0
- package/styles/docs/_responsive.scss +37 -0
- package/styles/docs/_variables.scss +71 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/docs/CodeBlock.ts
|
|
4
|
+
var CodeBlock = class {
|
|
5
|
+
constructor(preElement) {
|
|
6
|
+
this.codeElement = preElement.querySelector("code") || preElement;
|
|
7
|
+
this.container = document.createElement("div");
|
|
8
|
+
this.container.className = "code-block";
|
|
9
|
+
preElement.parentNode?.insertBefore(this.container, preElement);
|
|
10
|
+
this.container.appendChild(preElement);
|
|
11
|
+
this.copyButton = document.createElement("button");
|
|
12
|
+
this.copyButton.className = "code-block-copy";
|
|
13
|
+
this.copyButton.setAttribute("aria-label", "Copy code");
|
|
14
|
+
this.copyButton.innerHTML = this.getCopyIcon();
|
|
15
|
+
this.copyButton.addEventListener("click", () => this.copyCode());
|
|
16
|
+
this.container.appendChild(this.copyButton);
|
|
17
|
+
}
|
|
18
|
+
getCopyIcon() {
|
|
19
|
+
return `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
20
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
|
21
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
|
22
|
+
</svg>`;
|
|
23
|
+
}
|
|
24
|
+
getCheckIcon() {
|
|
25
|
+
return `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
26
|
+
<polyline points="20 6 9 17 4 12"></polyline>
|
|
27
|
+
</svg>`;
|
|
28
|
+
}
|
|
29
|
+
async copyCode() {
|
|
30
|
+
const text = this.codeElement.textContent || "";
|
|
31
|
+
try {
|
|
32
|
+
await navigator.clipboard.writeText(text);
|
|
33
|
+
this.showSuccess();
|
|
34
|
+
} catch (err) {
|
|
35
|
+
this.fallbackCopy(text);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
fallbackCopy(text) {
|
|
39
|
+
const textarea = document.createElement("textarea");
|
|
40
|
+
textarea.value = text;
|
|
41
|
+
textarea.style.position = "fixed";
|
|
42
|
+
textarea.style.opacity = "0";
|
|
43
|
+
document.body.appendChild(textarea);
|
|
44
|
+
textarea.select();
|
|
45
|
+
try {
|
|
46
|
+
document.execCommand("copy");
|
|
47
|
+
this.showSuccess();
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error("Failed to copy:", err);
|
|
50
|
+
}
|
|
51
|
+
document.body.removeChild(textarea);
|
|
52
|
+
}
|
|
53
|
+
showSuccess() {
|
|
54
|
+
this.copyButton.innerHTML = this.getCheckIcon();
|
|
55
|
+
this.copyButton.classList.add("copied");
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
this.copyButton.innerHTML = this.getCopyIcon();
|
|
58
|
+
this.copyButton.classList.remove("copied");
|
|
59
|
+
}, 2e3);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
function initCodeBlocks(selector = ".content-body pre") {
|
|
63
|
+
const preElements = document.querySelectorAll(selector);
|
|
64
|
+
preElements.forEach((pre) => {
|
|
65
|
+
if (pre.parentElement?.classList.contains("code-block")) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (pre.querySelector("pre")) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
new CodeBlock(pre);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/docs/pageSetup.ts
|
|
76
|
+
function highlightActiveSidebarLink(sidebarSelector = ".sidebar .section-nav a") {
|
|
77
|
+
const currentPath = window.location.pathname;
|
|
78
|
+
const sidebarLinks = document.querySelectorAll(sidebarSelector);
|
|
79
|
+
sidebarLinks.forEach((link) => {
|
|
80
|
+
const href = link.getAttribute("href");
|
|
81
|
+
if (href && currentPath.endsWith(href.replace(/\/$/, "") + "/")) {
|
|
82
|
+
link.classList.add("active");
|
|
83
|
+
} else if (href && currentPath === href) {
|
|
84
|
+
link.classList.add("active");
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function initPageSetup(options = {}) {
|
|
89
|
+
highlightActiveSidebarLink(options.sidebarSelector);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/docs/ActionCompiler.ts
|
|
93
|
+
var ActionCompiler = class {
|
|
94
|
+
constructor(editor, statusEl = null, onCompile = null) {
|
|
95
|
+
this.editor = null;
|
|
96
|
+
this.compiledFn = null;
|
|
97
|
+
this.compileError = null;
|
|
98
|
+
this.statusEl = null;
|
|
99
|
+
this.onCompile = null;
|
|
100
|
+
this.editor = editor;
|
|
101
|
+
this.statusEl = statusEl;
|
|
102
|
+
this.onCompile = onCompile;
|
|
103
|
+
let compileTimeout = null;
|
|
104
|
+
this.editor.session.on("change", () => {
|
|
105
|
+
if (compileTimeout) clearTimeout(compileTimeout);
|
|
106
|
+
compileTimeout = window.setTimeout(() => this.compile(), 300);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Compile the current editor content
|
|
111
|
+
*/
|
|
112
|
+
compile() {
|
|
113
|
+
if (!this.editor) {
|
|
114
|
+
return { success: false, fn: null, error: "No editor", line: null };
|
|
115
|
+
}
|
|
116
|
+
const code = this.editor.getValue().trim();
|
|
117
|
+
const session = this.editor.session;
|
|
118
|
+
session.clearAnnotations();
|
|
119
|
+
this.compiledFn = null;
|
|
120
|
+
this.compileError = null;
|
|
121
|
+
if (!code) {
|
|
122
|
+
this.updateStatus("", "");
|
|
123
|
+
const result = { success: true, fn: null, error: null, line: null };
|
|
124
|
+
this.onCompile?.(result);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
this.compiledFn = new Function("node", code);
|
|
129
|
+
this.updateStatus("\u2713", "success");
|
|
130
|
+
const result = { success: true, fn: this.compiledFn, error: null, line: null };
|
|
131
|
+
this.onCompile?.(result);
|
|
132
|
+
return result;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
this.compileError = e.message;
|
|
135
|
+
this.updateStatus("\u2717 Compile Error", "error");
|
|
136
|
+
const lineMatch = e.message.match(/(?:at line |line |:|\()(\d+)(?::|,|\))/i);
|
|
137
|
+
const line = lineMatch ? parseInt(lineMatch[1], 10) - 1 : 0;
|
|
138
|
+
session.setAnnotations([
|
|
139
|
+
{
|
|
140
|
+
row: line,
|
|
141
|
+
column: 0,
|
|
142
|
+
text: e.message,
|
|
143
|
+
type: "error"
|
|
144
|
+
}
|
|
145
|
+
]);
|
|
146
|
+
const result = { success: false, fn: null, error: e.message, line };
|
|
147
|
+
this.onCompile?.(result);
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Run the compiled action on a parse tree node
|
|
153
|
+
*/
|
|
154
|
+
run(node) {
|
|
155
|
+
if (!node) {
|
|
156
|
+
return { success: false, result: null, error: "No parse result available", line: null };
|
|
157
|
+
}
|
|
158
|
+
if (this.compileError) {
|
|
159
|
+
return { success: false, result: null, error: `Compile Error: ${this.compileError}`, line: null };
|
|
160
|
+
}
|
|
161
|
+
if (!this.compiledFn) {
|
|
162
|
+
return { success: true, result: null, error: null, line: null };
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const result = this.compiledFn(node);
|
|
166
|
+
if (this.editor) {
|
|
167
|
+
this.editor.session.clearAnnotations();
|
|
168
|
+
}
|
|
169
|
+
this.updateStatus("\u2713", "success");
|
|
170
|
+
return { success: true, result, error: null, line: null };
|
|
171
|
+
} catch (e) {
|
|
172
|
+
const stack = e.stack || "";
|
|
173
|
+
const lineMatch = stack.match(/<anonymous>:(\d+):/);
|
|
174
|
+
const line = lineMatch ? parseInt(lineMatch[1], 10) - 1 : null;
|
|
175
|
+
if (this.editor && line !== null) {
|
|
176
|
+
this.editor.session.setAnnotations([
|
|
177
|
+
{
|
|
178
|
+
row: line,
|
|
179
|
+
column: 0,
|
|
180
|
+
text: e.message,
|
|
181
|
+
type: "error"
|
|
182
|
+
}
|
|
183
|
+
]);
|
|
184
|
+
}
|
|
185
|
+
this.updateStatus("\u2717 Runtime Error", "error");
|
|
186
|
+
return { success: false, result: null, error: e.message, line };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get the current compile error (if any)
|
|
191
|
+
*/
|
|
192
|
+
getCompileError() {
|
|
193
|
+
return this.compileError;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Check if there's a compiled action function
|
|
197
|
+
*/
|
|
198
|
+
hasCompiledAction() {
|
|
199
|
+
return this.compiledFn !== null;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Update status element
|
|
203
|
+
*/
|
|
204
|
+
updateStatus(text, statusClass) {
|
|
205
|
+
if (this.statusEl) {
|
|
206
|
+
this.statusEl.textContent = text;
|
|
207
|
+
this.statusEl.classList.remove("success", "error");
|
|
208
|
+
if (statusClass) {
|
|
209
|
+
this.statusEl.classList.add(statusClass);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Clear annotations and status
|
|
215
|
+
*/
|
|
216
|
+
clear() {
|
|
217
|
+
if (this.editor) {
|
|
218
|
+
this.editor.session.clearAnnotations();
|
|
219
|
+
}
|
|
220
|
+
this.compiledFn = null;
|
|
221
|
+
this.compileError = null;
|
|
222
|
+
this.updateStatus("", "");
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
exports.ActionCompiler = ActionCompiler;
|
|
227
|
+
exports.CodeBlock = CodeBlock;
|
|
228
|
+
exports.highlightActiveSidebarLink = highlightActiveSidebarLink;
|
|
229
|
+
exports.initCodeBlocks = initCodeBlocks;
|
|
230
|
+
exports.initPageSetup = initPageSetup;
|
|
231
|
+
//# sourceMappingURL=index.js.map
|
|
232
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/docs/CodeBlock.ts","../../src/docs/pageSetup.ts","../../src/docs/ActionCompiler.ts"],"names":[],"mappings":";;;AAKO,IAAM,YAAN,MAAgB;AAAA,EAKrB,YAAY,UAAA,EAA4B;AACtC,IAAA,IAAA,CAAK,WAAA,GAAc,UAAA,CAAW,aAAA,CAAc,MAAM,CAAA,IAAK,UAAA;AAGvD,IAAA,IAAA,CAAK,SAAA,GAAY,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC7C,IAAA,IAAA,CAAK,UAAU,SAAA,GAAY,YAAA;AAC3B,IAAA,UAAA,CAAW,UAAA,EAAY,YAAA,CAAa,IAAA,CAAK,SAAA,EAAW,UAAU,CAAA;AAC9D,IAAA,IAAA,CAAK,SAAA,CAAU,YAAY,UAAU,CAAA;AAGrC,IAAA,IAAA,CAAK,UAAA,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AAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,iBAAA,GAA6B;AAC3B,IAAA,OAAO,KAAK,UAAA,KAAe,IAAA;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKQ,YAAA,CAAa,MAAc,WAAA,EAA2B;AAC5D,IAAA,IAAI,KAAK,QAAA,EAAU;AACjB,MAAA,IAAA,CAAK,SAAS,WAAA,GAAc,IAAA;AAE5B,MAAA,IAAA,CAAK,QAAA,CAAS,SAAA,CAAU,MAAA,CAAO,SAAA,EAAW,OAAO,CAAA;AACjD,MAAA,IAAI,WAAA,EAAa;AACf,QAAA,IAAA,CAAK,QAAA,CAAS,SAAA,CAAU,GAAA,CAAI,WAAW,CAAA;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,KAAA,GAAc;AACZ,IAAA,IAAI,KAAK,MAAA,EAAQ;AACf,MAAA,IAAA,CAAK,MAAA,CAAO,QAAQ,gBAAA,EAAiB;AAAA,IACvC;AACA,IAAA,IAAA,CAAK,UAAA,GAAa,IAAA;AAClB,IAAA,IAAA,CAAK,YAAA,GAAe,IAAA;AACpB,IAAA,IAAA,CAAK,YAAA,CAAa,IAAI,EAAE,CAAA;AAAA,EAC1B;AACF","file":"index.js","sourcesContent":["/**\n * CodeBlock.ts - Enhances pre/code blocks with copy functionality\n * Automatically finds all pre>code elements and adds a copy button\n */\n\nexport class CodeBlock {\n private container: HTMLElement;\n private copyButton: HTMLButtonElement;\n private codeElement: HTMLElement;\n\n constructor(preElement: HTMLPreElement) {\n this.codeElement = preElement.querySelector('code') || preElement;\n\n // Wrap pre in a container for positioning\n this.container = document.createElement('div');\n this.container.className = 'code-block';\n preElement.parentNode?.insertBefore(this.container, preElement);\n this.container.appendChild(preElement);\n\n // Create copy button\n this.copyButton = document.createElement('button');\n this.copyButton.className = 'code-block-copy';\n this.copyButton.setAttribute('aria-label', 'Copy code');\n this.copyButton.innerHTML = this.getCopyIcon();\n this.copyButton.addEventListener('click', () => this.copyCode());\n\n this.container.appendChild(this.copyButton);\n }\n\n private getCopyIcon(): string {\n return `<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"9\" y=\"9\" width=\"13\" height=\"13\" rx=\"2\" ry=\"2\"></rect>\n <path d=\"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1\"></path>\n </svg>`;\n }\n\n private getCheckIcon(): string {\n return `<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <polyline points=\"20 6 9 17 4 12\"></polyline>\n </svg>`;\n }\n\n private async copyCode(): Promise<void> {\n const text = this.codeElement.textContent || '';\n\n try {\n await navigator.clipboard.writeText(text);\n this.showSuccess();\n } catch (err) {\n // Fallback for older browsers\n this.fallbackCopy(text);\n }\n }\n\n private fallbackCopy(text: string): void {\n const textarea = document.createElement('textarea');\n textarea.value = text;\n textarea.style.position = 'fixed';\n textarea.style.opacity = '0';\n document.body.appendChild(textarea);\n textarea.select();\n\n try {\n document.execCommand('copy');\n this.showSuccess();\n } catch (err) {\n console.error('Failed to copy:', err);\n }\n\n document.body.removeChild(textarea);\n }\n\n private showSuccess(): void {\n this.copyButton.innerHTML = this.getCheckIcon();\n this.copyButton.classList.add('copied');\n\n setTimeout(() => {\n this.copyButton.innerHTML = this.getCopyIcon();\n this.copyButton.classList.remove('copied');\n }, 2000);\n }\n}\n\n/**\n * Initialize all code blocks on the page\n * @param selector - CSS selector for finding pre elements (default: '.content-body pre')\n */\nexport function initCodeBlocks(selector: string = '.content-body pre'): void {\n const preElements = document.querySelectorAll(selector);\n\n preElements.forEach((pre) => {\n // Skip if already initialized\n if (pre.parentElement?.classList.contains('code-block')) {\n return;\n }\n // Skip if this pre contains another pre (outer wrapper of double-wrapped code blocks)\n // We only want to process the innermost pre that has the actual code\n if (pre.querySelector('pre')) {\n return;\n }\n new CodeBlock(pre as HTMLPreElement);\n });\n}\n","/**\n * pageSetup.ts - Common page initialization shared across all doc pages\n */\n\n/**\n * Highlights the currently active link in the sidebar navigation\n * @param sidebarSelector - CSS selector for sidebar links (default: '.sidebar .section-nav a')\n */\nexport function highlightActiveSidebarLink(sidebarSelector: string = '.sidebar .section-nav a'): void {\n const currentPath = window.location.pathname;\n const sidebarLinks = document.querySelectorAll(sidebarSelector);\n\n sidebarLinks.forEach((link) => {\n const href = link.getAttribute('href');\n if (href && currentPath.endsWith(href.replace(/\\/$/, '') + '/')) {\n link.classList.add('active');\n } else if (href && currentPath === href) {\n link.classList.add('active');\n }\n });\n}\n\n/**\n * Initialize common page features\n * Call this on DOMContentLoaded for all doc pages\n * @param options - Configuration options for page setup\n */\nexport function initPageSetup(options: {\n sidebarSelector?: string;\n} = {}): void {\n highlightActiveSidebarLink(options.sidebarSelector);\n}\n","/**\n * ActionCompiler - Shared action code compilation and execution\n * Used by docs components like ExampleRunner and PlaygroundPage\n */\n\nimport ace from \"ace-builds\";\n\nexport interface ActionCompileResult {\n success: boolean;\n fn: ((node: any) => any) | null;\n error: string | null;\n line: number | null; // 0-indexed line number for error\n}\n\nexport interface ActionRunResult {\n success: boolean;\n result: any;\n error: string | null;\n line: number | null; // 0-indexed line number for runtime error\n}\n\nexport class ActionCompiler {\n private editor: ace.Ace.Editor | null = null;\n private compiledFn: ((node: any) => any) | null = null;\n private compileError: string | null = null;\n private statusEl: HTMLElement | null = null;\n private onCompile: ((result: ActionCompileResult) => void) | null = null;\n\n constructor(\n editor: ace.Ace.Editor,\n statusEl: HTMLElement | null = null,\n onCompile: ((result: ActionCompileResult) => void) | null = null,\n ) {\n this.editor = editor;\n this.statusEl = statusEl;\n this.onCompile = onCompile;\n\n // Setup change listener with debounce\n let compileTimeout: number | null = null;\n this.editor.session.on(\"change\", () => {\n if (compileTimeout) clearTimeout(compileTimeout);\n compileTimeout = window.setTimeout(() => this.compile(), 300);\n });\n }\n\n /**\n * Compile the current editor content\n */\n compile(): ActionCompileResult {\n if (!this.editor) {\n return { success: false, fn: null, error: \"No editor\", line: null };\n }\n\n const code = this.editor.getValue().trim();\n const session = this.editor.session;\n\n // Clear previous annotations\n session.clearAnnotations();\n this.compiledFn = null;\n this.compileError = null;\n\n if (!code) {\n this.updateStatus(\"\", \"\");\n const result = { success: true, fn: null, error: null, line: null };\n this.onCompile?.(result);\n return result;\n }\n\n try {\n // Compile using new Function\n this.compiledFn = new Function(\"node\", code) as (node: any) => any;\n this.updateStatus(\"✓\", \"success\");\n const result = { success: true, fn: this.compiledFn, error: null, line: null };\n this.onCompile?.(result);\n return result;\n } catch (e: any) {\n this.compileError = e.message;\n this.updateStatus(\"✗ Compile Error\", \"error\");\n\n // Try to extract line number from error message\n // Common patterns: \"at line 5\", \"line 5\", \":5:\", \"(5:\"\n const lineMatch = e.message.match(/(?:at line |line |:|\\()(\\d+)(?::|,|\\))/i);\n const line = lineMatch ? parseInt(lineMatch[1], 10) - 1 : 0; // 0-indexed\n\n session.setAnnotations([\n {\n row: line,\n column: 0,\n text: e.message,\n type: \"error\",\n },\n ]);\n\n const result = { success: false, fn: null, error: e.message, line };\n this.onCompile?.(result);\n return result;\n }\n }\n\n /**\n * Run the compiled action on a parse tree node\n */\n run(node: any): ActionRunResult {\n if (!node) {\n return { success: false, result: null, error: \"No parse result available\", line: null };\n }\n\n if (this.compileError) {\n return { success: false, result: null, error: `Compile Error: ${this.compileError}`, line: null };\n }\n\n if (!this.compiledFn) {\n return { success: true, result: null, error: null, line: null }; // No action code\n }\n\n try {\n const result = this.compiledFn(node);\n // Clear runtime error annotations\n if (this.editor) {\n this.editor.session.clearAnnotations();\n }\n this.updateStatus(\"✓\", \"success\");\n return { success: true, result, error: null, line: null };\n } catch (e: any) {\n // Try to extract line number from runtime error stack\n const stack = e.stack || \"\";\n const lineMatch = stack.match(/<anonymous>:(\\d+):/);\n const line = lineMatch ? parseInt(lineMatch[1], 10) - 1 : null; // 0-indexed\n\n // Set runtime error annotation\n if (this.editor && line !== null) {\n this.editor.session.setAnnotations([\n {\n row: line,\n column: 0,\n text: e.message,\n type: \"error\",\n },\n ]);\n }\n\n this.updateStatus(\"✗ Runtime Error\", \"error\");\n return { success: false, result: null, error: e.message, line };\n }\n }\n\n /**\n * Get the current compile error (if any)\n */\n getCompileError(): string | null {\n return this.compileError;\n }\n\n /**\n * Check if there's a compiled action function\n */\n hasCompiledAction(): boolean {\n return this.compiledFn !== null;\n }\n\n /**\n * Update status element\n */\n private updateStatus(text: string, statusClass: string): void {\n if (this.statusEl) {\n this.statusEl.textContent = text;\n // Clear and set status classes without removing base class\n this.statusEl.classList.remove(\"success\", \"error\");\n if (statusClass) {\n this.statusEl.classList.add(statusClass);\n }\n }\n }\n\n /**\n * Clear annotations and status\n */\n clear(): void {\n if (this.editor) {\n this.editor.session.clearAnnotations();\n }\n this.compiledFn = null;\n this.compileError = null;\n this.updateStatus(\"\", \"\");\n }\n}\n"]}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// src/docs/CodeBlock.ts
|
|
2
|
+
var CodeBlock = class {
|
|
3
|
+
constructor(preElement) {
|
|
4
|
+
this.codeElement = preElement.querySelector("code") || preElement;
|
|
5
|
+
this.container = document.createElement("div");
|
|
6
|
+
this.container.className = "code-block";
|
|
7
|
+
preElement.parentNode?.insertBefore(this.container, preElement);
|
|
8
|
+
this.container.appendChild(preElement);
|
|
9
|
+
this.copyButton = document.createElement("button");
|
|
10
|
+
this.copyButton.className = "code-block-copy";
|
|
11
|
+
this.copyButton.setAttribute("aria-label", "Copy code");
|
|
12
|
+
this.copyButton.innerHTML = this.getCopyIcon();
|
|
13
|
+
this.copyButton.addEventListener("click", () => this.copyCode());
|
|
14
|
+
this.container.appendChild(this.copyButton);
|
|
15
|
+
}
|
|
16
|
+
getCopyIcon() {
|
|
17
|
+
return `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
18
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
|
19
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
|
20
|
+
</svg>`;
|
|
21
|
+
}
|
|
22
|
+
getCheckIcon() {
|
|
23
|
+
return `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
24
|
+
<polyline points="20 6 9 17 4 12"></polyline>
|
|
25
|
+
</svg>`;
|
|
26
|
+
}
|
|
27
|
+
async copyCode() {
|
|
28
|
+
const text = this.codeElement.textContent || "";
|
|
29
|
+
try {
|
|
30
|
+
await navigator.clipboard.writeText(text);
|
|
31
|
+
this.showSuccess();
|
|
32
|
+
} catch (err) {
|
|
33
|
+
this.fallbackCopy(text);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
fallbackCopy(text) {
|
|
37
|
+
const textarea = document.createElement("textarea");
|
|
38
|
+
textarea.value = text;
|
|
39
|
+
textarea.style.position = "fixed";
|
|
40
|
+
textarea.style.opacity = "0";
|
|
41
|
+
document.body.appendChild(textarea);
|
|
42
|
+
textarea.select();
|
|
43
|
+
try {
|
|
44
|
+
document.execCommand("copy");
|
|
45
|
+
this.showSuccess();
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error("Failed to copy:", err);
|
|
48
|
+
}
|
|
49
|
+
document.body.removeChild(textarea);
|
|
50
|
+
}
|
|
51
|
+
showSuccess() {
|
|
52
|
+
this.copyButton.innerHTML = this.getCheckIcon();
|
|
53
|
+
this.copyButton.classList.add("copied");
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
this.copyButton.innerHTML = this.getCopyIcon();
|
|
56
|
+
this.copyButton.classList.remove("copied");
|
|
57
|
+
}, 2e3);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
function initCodeBlocks(selector = ".content-body pre") {
|
|
61
|
+
const preElements = document.querySelectorAll(selector);
|
|
62
|
+
preElements.forEach((pre) => {
|
|
63
|
+
if (pre.parentElement?.classList.contains("code-block")) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (pre.querySelector("pre")) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
new CodeBlock(pre);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/docs/pageSetup.ts
|
|
74
|
+
function highlightActiveSidebarLink(sidebarSelector = ".sidebar .section-nav a") {
|
|
75
|
+
const currentPath = window.location.pathname;
|
|
76
|
+
const sidebarLinks = document.querySelectorAll(sidebarSelector);
|
|
77
|
+
sidebarLinks.forEach((link) => {
|
|
78
|
+
const href = link.getAttribute("href");
|
|
79
|
+
if (href && currentPath.endsWith(href.replace(/\/$/, "") + "/")) {
|
|
80
|
+
link.classList.add("active");
|
|
81
|
+
} else if (href && currentPath === href) {
|
|
82
|
+
link.classList.add("active");
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function initPageSetup(options = {}) {
|
|
87
|
+
highlightActiveSidebarLink(options.sidebarSelector);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/docs/ActionCompiler.ts
|
|
91
|
+
var ActionCompiler = class {
|
|
92
|
+
constructor(editor, statusEl = null, onCompile = null) {
|
|
93
|
+
this.editor = null;
|
|
94
|
+
this.compiledFn = null;
|
|
95
|
+
this.compileError = null;
|
|
96
|
+
this.statusEl = null;
|
|
97
|
+
this.onCompile = null;
|
|
98
|
+
this.editor = editor;
|
|
99
|
+
this.statusEl = statusEl;
|
|
100
|
+
this.onCompile = onCompile;
|
|
101
|
+
let compileTimeout = null;
|
|
102
|
+
this.editor.session.on("change", () => {
|
|
103
|
+
if (compileTimeout) clearTimeout(compileTimeout);
|
|
104
|
+
compileTimeout = window.setTimeout(() => this.compile(), 300);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Compile the current editor content
|
|
109
|
+
*/
|
|
110
|
+
compile() {
|
|
111
|
+
if (!this.editor) {
|
|
112
|
+
return { success: false, fn: null, error: "No editor", line: null };
|
|
113
|
+
}
|
|
114
|
+
const code = this.editor.getValue().trim();
|
|
115
|
+
const session = this.editor.session;
|
|
116
|
+
session.clearAnnotations();
|
|
117
|
+
this.compiledFn = null;
|
|
118
|
+
this.compileError = null;
|
|
119
|
+
if (!code) {
|
|
120
|
+
this.updateStatus("", "");
|
|
121
|
+
const result = { success: true, fn: null, error: null, line: null };
|
|
122
|
+
this.onCompile?.(result);
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
this.compiledFn = new Function("node", code);
|
|
127
|
+
this.updateStatus("\u2713", "success");
|
|
128
|
+
const result = { success: true, fn: this.compiledFn, error: null, line: null };
|
|
129
|
+
this.onCompile?.(result);
|
|
130
|
+
return result;
|
|
131
|
+
} catch (e) {
|
|
132
|
+
this.compileError = e.message;
|
|
133
|
+
this.updateStatus("\u2717 Compile Error", "error");
|
|
134
|
+
const lineMatch = e.message.match(/(?:at line |line |:|\()(\d+)(?::|,|\))/i);
|
|
135
|
+
const line = lineMatch ? parseInt(lineMatch[1], 10) - 1 : 0;
|
|
136
|
+
session.setAnnotations([
|
|
137
|
+
{
|
|
138
|
+
row: line,
|
|
139
|
+
column: 0,
|
|
140
|
+
text: e.message,
|
|
141
|
+
type: "error"
|
|
142
|
+
}
|
|
143
|
+
]);
|
|
144
|
+
const result = { success: false, fn: null, error: e.message, line };
|
|
145
|
+
this.onCompile?.(result);
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Run the compiled action on a parse tree node
|
|
151
|
+
*/
|
|
152
|
+
run(node) {
|
|
153
|
+
if (!node) {
|
|
154
|
+
return { success: false, result: null, error: "No parse result available", line: null };
|
|
155
|
+
}
|
|
156
|
+
if (this.compileError) {
|
|
157
|
+
return { success: false, result: null, error: `Compile Error: ${this.compileError}`, line: null };
|
|
158
|
+
}
|
|
159
|
+
if (!this.compiledFn) {
|
|
160
|
+
return { success: true, result: null, error: null, line: null };
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const result = this.compiledFn(node);
|
|
164
|
+
if (this.editor) {
|
|
165
|
+
this.editor.session.clearAnnotations();
|
|
166
|
+
}
|
|
167
|
+
this.updateStatus("\u2713", "success");
|
|
168
|
+
return { success: true, result, error: null, line: null };
|
|
169
|
+
} catch (e) {
|
|
170
|
+
const stack = e.stack || "";
|
|
171
|
+
const lineMatch = stack.match(/<anonymous>:(\d+):/);
|
|
172
|
+
const line = lineMatch ? parseInt(lineMatch[1], 10) - 1 : null;
|
|
173
|
+
if (this.editor && line !== null) {
|
|
174
|
+
this.editor.session.setAnnotations([
|
|
175
|
+
{
|
|
176
|
+
row: line,
|
|
177
|
+
column: 0,
|
|
178
|
+
text: e.message,
|
|
179
|
+
type: "error"
|
|
180
|
+
}
|
|
181
|
+
]);
|
|
182
|
+
}
|
|
183
|
+
this.updateStatus("\u2717 Runtime Error", "error");
|
|
184
|
+
return { success: false, result: null, error: e.message, line };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get the current compile error (if any)
|
|
189
|
+
*/
|
|
190
|
+
getCompileError() {
|
|
191
|
+
return this.compileError;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Check if there's a compiled action function
|
|
195
|
+
*/
|
|
196
|
+
hasCompiledAction() {
|
|
197
|
+
return this.compiledFn !== null;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Update status element
|
|
201
|
+
*/
|
|
202
|
+
updateStatus(text, statusClass) {
|
|
203
|
+
if (this.statusEl) {
|
|
204
|
+
this.statusEl.textContent = text;
|
|
205
|
+
this.statusEl.classList.remove("success", "error");
|
|
206
|
+
if (statusClass) {
|
|
207
|
+
this.statusEl.classList.add(statusClass);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Clear annotations and status
|
|
213
|
+
*/
|
|
214
|
+
clear() {
|
|
215
|
+
if (this.editor) {
|
|
216
|
+
this.editor.session.clearAnnotations();
|
|
217
|
+
}
|
|
218
|
+
this.compiledFn = null;
|
|
219
|
+
this.compileError = null;
|
|
220
|
+
this.updateStatus("", "");
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export { ActionCompiler, CodeBlock, highlightActiveSidebarLink, initCodeBlocks, initPageSetup };
|
|
225
|
+
//# sourceMappingURL=index.mjs.map
|
|
226
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/docs/CodeBlock.ts","../../src/docs/pageSetup.ts","../../src/docs/ActionCompiler.ts"],"names":[],"mappings":";AAKO,IAAM,YAAN,MAAgB;AAAA,EAKrB,YAAY,UAAA,EAA4B;AACtC,IAAA,IAAA,CAAK,WAAA,GAAc,UAAA,CAAW,aAAA,CAAc,MAAM,CAAA,IAAK,UAAA;AAGvD,IAAA,IAAA,CAAK,SAAA,GAAY,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC7C,IAAA,IAAA,CAAK,UAAU,SAAA,GAAY,YAAA;AAC3B,IAAA,UAAA,CAAW,UAAA,EAAY,YAAA,CAAa,IAAA,CAAK,SAAA,EAAW,UAAU,CAAA;AAC9D,IAAA,IAAA,CAAK,SAAA,CAAU,YAAY,UAAU,CAAA;AAGrC,IAAA,IAAA,CAAK,UAAA,GAAa,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AACjD,IAAA,IAAA,CAAK,WAAW,SAAA,GAAY,iBAAA;AAC5B,IAAA,IAAA,CAAK,UAAA,CAAW,YAAA,CAAa,YAAA,EAAc,WAAW,CAAA;AACtD,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;AAC5D,IAAA,IAAI,KAAK,QAAA,EAAU;AACjB,MAAA,IAAA,CAAK,SAAS,WAAA,GAAc,IAAA;AAE5B,MAAA,IAAA,CAAK,QAAA,CAAS,SAAA,CAAU,MAAA,CAAO,SAAA,EAAW,OAAO,CAAA;AACjD,MAAA,IAAI,WAAA,EAAa;AACf,QAAA,IAAA,CAAK,QAAA,CAAS,SAAA,CAAU,GAAA,CAAI,WAAW,CAAA;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,KAAA,GAAc;AACZ,IAAA,IAAI,KAAK,MAAA,EAAQ;AACf,MAAA,IAAA,CAAK,MAAA,CAAO,QAAQ,gBAAA,EAAiB;AAAA,IACvC;AACA,IAAA,IAAA,CAAK,UAAA,GAAa,IAAA;AAClB,IAAA,IAAA,CAAK,YAAA,GAAe,IAAA;AACpB,IAAA,IAAA,CAAK,YAAA,CAAa,IAAI,EAAE,CAAA;AAAA,EAC1B;AACF","file":"index.mjs","sourcesContent":["/**\n * CodeBlock.ts - Enhances pre/code blocks with copy functionality\n * Automatically finds all pre>code elements and adds a copy button\n */\n\nexport class CodeBlock {\n private container: HTMLElement;\n private copyButton: HTMLButtonElement;\n private codeElement: HTMLElement;\n\n constructor(preElement: HTMLPreElement) {\n this.codeElement = preElement.querySelector('code') || preElement;\n\n // Wrap pre in a container for positioning\n this.container = document.createElement('div');\n this.container.className = 'code-block';\n preElement.parentNode?.insertBefore(this.container, preElement);\n this.container.appendChild(preElement);\n\n // Create copy button\n this.copyButton = document.createElement('button');\n this.copyButton.className = 'code-block-copy';\n this.copyButton.setAttribute('aria-label', 'Copy code');\n this.copyButton.innerHTML = this.getCopyIcon();\n this.copyButton.addEventListener('click', () => this.copyCode());\n\n this.container.appendChild(this.copyButton);\n }\n\n private getCopyIcon(): string {\n return `<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"9\" y=\"9\" width=\"13\" height=\"13\" rx=\"2\" ry=\"2\"></rect>\n <path d=\"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1\"></path>\n </svg>`;\n }\n\n private getCheckIcon(): string {\n return `<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <polyline points=\"20 6 9 17 4 12\"></polyline>\n </svg>`;\n }\n\n private async copyCode(): Promise<void> {\n const text = this.codeElement.textContent || '';\n\n try {\n await navigator.clipboard.writeText(text);\n this.showSuccess();\n } catch (err) {\n // Fallback for older browsers\n this.fallbackCopy(text);\n }\n }\n\n private fallbackCopy(text: string): void {\n const textarea = document.createElement('textarea');\n textarea.value = text;\n textarea.style.position = 'fixed';\n textarea.style.opacity = '0';\n document.body.appendChild(textarea);\n textarea.select();\n\n try {\n document.execCommand('copy');\n this.showSuccess();\n } catch (err) {\n console.error('Failed to copy:', err);\n }\n\n document.body.removeChild(textarea);\n }\n\n private showSuccess(): void {\n this.copyButton.innerHTML = this.getCheckIcon();\n this.copyButton.classList.add('copied');\n\n setTimeout(() => {\n this.copyButton.innerHTML = this.getCopyIcon();\n this.copyButton.classList.remove('copied');\n }, 2000);\n }\n}\n\n/**\n * Initialize all code blocks on the page\n * @param selector - CSS selector for finding pre elements (default: '.content-body pre')\n */\nexport function initCodeBlocks(selector: string = '.content-body pre'): void {\n const preElements = document.querySelectorAll(selector);\n\n preElements.forEach((pre) => {\n // Skip if already initialized\n if (pre.parentElement?.classList.contains('code-block')) {\n return;\n }\n // Skip if this pre contains another pre (outer wrapper of double-wrapped code blocks)\n // We only want to process the innermost pre that has the actual code\n if (pre.querySelector('pre')) {\n return;\n }\n new CodeBlock(pre as HTMLPreElement);\n });\n}\n","/**\n * pageSetup.ts - Common page initialization shared across all doc pages\n */\n\n/**\n * Highlights the currently active link in the sidebar navigation\n * @param sidebarSelector - CSS selector for sidebar links (default: '.sidebar .section-nav a')\n */\nexport function highlightActiveSidebarLink(sidebarSelector: string = '.sidebar .section-nav a'): void {\n const currentPath = window.location.pathname;\n const sidebarLinks = document.querySelectorAll(sidebarSelector);\n\n sidebarLinks.forEach((link) => {\n const href = link.getAttribute('href');\n if (href && currentPath.endsWith(href.replace(/\\/$/, '') + '/')) {\n link.classList.add('active');\n } else if (href && currentPath === href) {\n link.classList.add('active');\n }\n });\n}\n\n/**\n * Initialize common page features\n * Call this on DOMContentLoaded for all doc pages\n * @param options - Configuration options for page setup\n */\nexport function initPageSetup(options: {\n sidebarSelector?: string;\n} = {}): void {\n highlightActiveSidebarLink(options.sidebarSelector);\n}\n","/**\n * ActionCompiler - Shared action code compilation and execution\n * Used by docs components like ExampleRunner and PlaygroundPage\n */\n\nimport ace from \"ace-builds\";\n\nexport interface ActionCompileResult {\n success: boolean;\n fn: ((node: any) => any) | null;\n error: string | null;\n line: number | null; // 0-indexed line number for error\n}\n\nexport interface ActionRunResult {\n success: boolean;\n result: any;\n error: string | null;\n line: number | null; // 0-indexed line number for runtime error\n}\n\nexport class ActionCompiler {\n private editor: ace.Ace.Editor | null = null;\n private compiledFn: ((node: any) => any) | null = null;\n private compileError: string | null = null;\n private statusEl: HTMLElement | null = null;\n private onCompile: ((result: ActionCompileResult) => void) | null = null;\n\n constructor(\n editor: ace.Ace.Editor,\n statusEl: HTMLElement | null = null,\n onCompile: ((result: ActionCompileResult) => void) | null = null,\n ) {\n this.editor = editor;\n this.statusEl = statusEl;\n this.onCompile = onCompile;\n\n // Setup change listener with debounce\n let compileTimeout: number | null = null;\n this.editor.session.on(\"change\", () => {\n if (compileTimeout) clearTimeout(compileTimeout);\n compileTimeout = window.setTimeout(() => this.compile(), 300);\n });\n }\n\n /**\n * Compile the current editor content\n */\n compile(): ActionCompileResult {\n if (!this.editor) {\n return { success: false, fn: null, error: \"No editor\", line: null };\n }\n\n const code = this.editor.getValue().trim();\n const session = this.editor.session;\n\n // Clear previous annotations\n session.clearAnnotations();\n this.compiledFn = null;\n this.compileError = null;\n\n if (!code) {\n this.updateStatus(\"\", \"\");\n const result = { success: true, fn: null, error: null, line: null };\n this.onCompile?.(result);\n return result;\n }\n\n try {\n // Compile using new Function\n this.compiledFn = new Function(\"node\", code) as (node: any) => any;\n this.updateStatus(\"✓\", \"success\");\n const result = { success: true, fn: this.compiledFn, error: null, line: null };\n this.onCompile?.(result);\n return result;\n } catch (e: any) {\n this.compileError = e.message;\n this.updateStatus(\"✗ Compile Error\", \"error\");\n\n // Try to extract line number from error message\n // Common patterns: \"at line 5\", \"line 5\", \":5:\", \"(5:\"\n const lineMatch = e.message.match(/(?:at line |line |:|\\()(\\d+)(?::|,|\\))/i);\n const line = lineMatch ? parseInt(lineMatch[1], 10) - 1 : 0; // 0-indexed\n\n session.setAnnotations([\n {\n row: line,\n column: 0,\n text: e.message,\n type: \"error\",\n },\n ]);\n\n const result = { success: false, fn: null, error: e.message, line };\n this.onCompile?.(result);\n return result;\n }\n }\n\n /**\n * Run the compiled action on a parse tree node\n */\n run(node: any): ActionRunResult {\n if (!node) {\n return { success: false, result: null, error: \"No parse result available\", line: null };\n }\n\n if (this.compileError) {\n return { success: false, result: null, error: `Compile Error: ${this.compileError}`, line: null };\n }\n\n if (!this.compiledFn) {\n return { success: true, result: null, error: null, line: null }; // No action code\n }\n\n try {\n const result = this.compiledFn(node);\n // Clear runtime error annotations\n if (this.editor) {\n this.editor.session.clearAnnotations();\n }\n this.updateStatus(\"✓\", \"success\");\n return { success: true, result, error: null, line: null };\n } catch (e: any) {\n // Try to extract line number from runtime error stack\n const stack = e.stack || \"\";\n const lineMatch = stack.match(/<anonymous>:(\\d+):/);\n const line = lineMatch ? parseInt(lineMatch[1], 10) - 1 : null; // 0-indexed\n\n // Set runtime error annotation\n if (this.editor && line !== null) {\n this.editor.session.setAnnotations([\n {\n row: line,\n column: 0,\n text: e.message,\n type: \"error\",\n },\n ]);\n }\n\n this.updateStatus(\"✗ Runtime Error\", \"error\");\n return { success: false, result: null, error: e.message, line };\n }\n }\n\n /**\n * Get the current compile error (if any)\n */\n getCompileError(): string | null {\n return this.compileError;\n }\n\n /**\n * Check if there's a compiled action function\n */\n hasCompiledAction(): boolean {\n return this.compiledFn !== null;\n }\n\n /**\n * Update status element\n */\n private updateStatus(text: string, statusClass: string): void {\n if (this.statusEl) {\n this.statusEl.textContent = text;\n // Clear and set status classes without removing base class\n this.statusEl.classList.remove(\"success\", \"error\");\n if (statusClass) {\n this.statusEl.classList.add(statusClass);\n }\n }\n }\n\n /**\n * Clear annotations and status\n */\n clear(): void {\n if (this.editor) {\n this.editor.session.clearAnnotations();\n }\n this.compiledFn = null;\n this.compileError = null;\n this.updateStatus(\"\", \"\");\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panyam/tsappkit",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "TypeScript application toolkit with component lifecycle management, event system, and
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "TypeScript application toolkit with component lifecycle management, event system, UI utilities, and documentation site components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -10,34 +10,55 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.js"
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
"./docs": {
|
|
15
|
+
"types": "./dist/docs/index.d.ts",
|
|
16
|
+
"import": "./dist/docs/index.mjs",
|
|
17
|
+
"require": "./dist/docs/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./styles/*": "./styles/*",
|
|
20
|
+
"./dist/*": "./dist/*"
|
|
14
21
|
},
|
|
15
22
|
"files": [
|
|
16
23
|
"dist",
|
|
17
|
-
"src"
|
|
24
|
+
"src",
|
|
25
|
+
"styles"
|
|
18
26
|
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup && npm run build:css",
|
|
29
|
+
"build:css": "sass styles/docs/DocsPage.scss dist/docs/DocsPage.css --style=expanded && sass styles/docs/DocsPage.scss dist/docs/DocsPage.min.css --style=compressed",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"clean": "rm -rf dist",
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
|
+
"typecheck": "tsc --noEmit"
|
|
34
|
+
},
|
|
19
35
|
"keywords": [
|
|
20
36
|
"typescript",
|
|
21
37
|
"component",
|
|
22
38
|
"lifecycle",
|
|
23
39
|
"event-bus",
|
|
24
|
-
"ui-toolkit"
|
|
40
|
+
"ui-toolkit",
|
|
41
|
+
"documentation",
|
|
42
|
+
"docs-components"
|
|
25
43
|
],
|
|
26
44
|
"author": "panyam",
|
|
27
45
|
"license": "MIT",
|
|
28
46
|
"devDependencies": {
|
|
47
|
+
"ace-builds": "^1.43.0",
|
|
48
|
+
"sass": "^1.77.0",
|
|
29
49
|
"tsup": "^8.0.0",
|
|
30
50
|
"typescript": "^5.0.0"
|
|
31
51
|
},
|
|
32
|
-
"peerDependencies": {
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"ace-builds": "^1.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"ace-builds": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
33
60
|
"repository": {
|
|
34
61
|
"type": "git",
|
|
35
62
|
"url": ""
|
|
36
|
-
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "tsup",
|
|
39
|
-
"dev": "tsup --watch",
|
|
40
|
-
"clean": "rm -rf dist",
|
|
41
|
-
"typecheck": "tsc --noEmit"
|
|
42
63
|
}
|
|
43
|
-
}
|
|
64
|
+
}
|