@hpcc-js/observablehq-compiler 1.1.4 → 1.2.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/bin/ojscc.mjs +4 -5
- package/dist/index.esm.js +132 -84
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +3 -3
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.js +132 -84
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +3 -3
- package/dist/index.min.js.map +1 -1
- package/package.json +3 -3
- package/src/__package__.ts +2 -2
- package/src/__tests__/node.ts +1 -1
- package/src/compiler.ts +130 -94
- package/src/index.ts +1 -1
- package/src/util.ts +8 -4
- package/types/__package__.d.ts +2 -2
- package/types/compiler.d.ts +108 -39
- package/types/compiler.d.ts.map +1 -1
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/util.d.ts +0 -1
- package/types/util.d.ts.map +1 -1
- package/types-3.4/__package__.d.ts +2 -2
- package/types-3.4/compiler.d.ts +108 -42
- package/types-3.4/index.d.ts +1 -1
- package/types-3.4/util.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/observablehq-compiler",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "hpcc-js - ObservableHQ Compiler (unoffical)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"observablehq",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"update": "npx --yes npm-check-updates -u -t minor"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@hpcc-js/observable-shim": "^2.
|
|
59
|
+
"@hpcc-js/observable-shim": "^2.4.0",
|
|
60
60
|
"node-fetch": "3.2.10",
|
|
61
61
|
"yargs": "17.5.1"
|
|
62
62
|
},
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"url": "https://github.com/hpcc-systems/Visualization/issues"
|
|
78
78
|
},
|
|
79
79
|
"homepage": "https://github.com/hpcc-systems/Visualization/tree/trunk/packages/observablehq-compiler",
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "e6a2073496de5b696e551bab0aa5a6ebd6207484"
|
|
81
81
|
}
|
package/src/__package__.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export const PKG_NAME = "@hpcc-js/observablehq-compiler";
|
|
2
|
-
export const PKG_VERSION = "1.
|
|
3
|
-
export const BUILD_VERSION = "2.104.
|
|
2
|
+
export const PKG_VERSION = "1.2.0";
|
|
3
|
+
export const BUILD_VERSION = "2.104.9";
|
package/src/__tests__/node.ts
CHANGED
package/src/compiler.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { ohq, splitModule } from "@hpcc-js/observable-shim";
|
|
2
|
-
|
|
3
2
|
import { endsWith, join } from "@hpcc-js/util";
|
|
4
3
|
import { parseCell, ParsedImportCell } from "./cst";
|
|
5
4
|
import { Writer } from "./writer";
|
|
6
5
|
import { encodeBacktick, fetchEx, obfuscatedImport, ojs2notebook, omd2notebook } from "./util";
|
|
7
6
|
|
|
7
|
+
// Inspector Factory ---
|
|
8
|
+
export type InspectorFactoryEx = (name: string | undefined, id: string | number) => Inspector;
|
|
9
|
+
|
|
10
|
+
export interface Inspector {
|
|
11
|
+
_node?: HTMLDivElement;
|
|
12
|
+
pending();
|
|
13
|
+
fulfilled(value);
|
|
14
|
+
rejected(error);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Module ---
|
|
18
|
+
|
|
8
19
|
const isRelativePath = (path: string) => path[0] === ".";
|
|
9
20
|
const fullUrl = (path: string, basePath: string) => isRelativePath(path) ? join(basePath, path) : path;
|
|
10
21
|
|
|
11
22
|
interface ImportDefine {
|
|
12
|
-
(runtime: ohq.Runtime, inspector?:
|
|
13
|
-
|
|
23
|
+
(runtime: ohq.Runtime, inspector?: InspectorFactoryEx): ohq.Module;
|
|
24
|
+
delete: () => void;
|
|
14
25
|
write: (w: Writer) => void;
|
|
15
26
|
}
|
|
16
27
|
|
|
@@ -25,19 +36,19 @@ async function importFile(relativePath: string, baseUrl: string) {
|
|
|
25
36
|
} else if (endsWith(relativePath, ".omd")) {
|
|
26
37
|
notebook = omd2notebook(content);
|
|
27
38
|
}
|
|
28
|
-
const retVal: ImportDefine = compile(notebook, baseUrl) as any;
|
|
29
|
-
retVal.
|
|
39
|
+
const retVal: ImportDefine = compile(notebook, { baseUrl }) as any;
|
|
40
|
+
retVal.delete = () => { };
|
|
30
41
|
retVal.write = (w: Writer) => {
|
|
31
42
|
w.import(path);
|
|
32
43
|
};
|
|
33
44
|
return retVal;
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
//
|
|
47
|
+
// Import precompiled notebook from observable ---
|
|
37
48
|
async function importCompiledNotebook(partial: string) {
|
|
38
49
|
const url = `https://api.observablehq.com/${partial[0] === "@" ? partial : `d/${partial}`}.js?v=3`;
|
|
39
50
|
let impMod = {
|
|
40
|
-
default: function (runtime: ohq.Runtime, inspector?:
|
|
51
|
+
default: function (runtime: ohq.Runtime, inspector?: InspectorFactoryEx): ohq.Module {
|
|
41
52
|
return undefined;
|
|
42
53
|
} as any
|
|
43
54
|
};
|
|
@@ -46,14 +57,14 @@ async function importCompiledNotebook(partial: string) {
|
|
|
46
57
|
} catch (e) {
|
|
47
58
|
}
|
|
48
59
|
const retVal: ImportDefine = impMod.default;
|
|
49
|
-
retVal.
|
|
60
|
+
retVal.delete = () => { };
|
|
50
61
|
retVal.write = (w: Writer) => {
|
|
51
62
|
w.import(url);
|
|
52
63
|
};
|
|
53
64
|
return retVal;
|
|
54
65
|
}
|
|
55
66
|
|
|
56
|
-
//
|
|
67
|
+
// Recursive notebook parsing and compiling
|
|
57
68
|
async function importNotebook(partial: string) {
|
|
58
69
|
const url = `https://api.observablehq.com/document/${partial}`;
|
|
59
70
|
const notebook = fetchEx(url)
|
|
@@ -64,20 +75,63 @@ async function importNotebook(partial: string) {
|
|
|
64
75
|
console.error(e);
|
|
65
76
|
});
|
|
66
77
|
const retVal: ImportDefine = compile(await notebook) as any;
|
|
67
|
-
retVal.
|
|
78
|
+
retVal.delete = () => { };
|
|
68
79
|
retVal.write = (w: Writer) => {
|
|
69
80
|
w.import(url);
|
|
70
81
|
};
|
|
71
82
|
return retVal;
|
|
72
83
|
}
|
|
73
84
|
|
|
74
|
-
function
|
|
85
|
+
async function createModule(node: ohq.Node, parsed: ParsedImportCell, text: string, { baseUrl, importMode }: CompileOptions) {
|
|
86
|
+
const otherModule = isRelativePath(parsed.src) ?
|
|
87
|
+
await importFile(parsed.src, baseUrl) :
|
|
88
|
+
importMode === "recursive" ?
|
|
89
|
+
await importNotebook(parsed.src) :
|
|
90
|
+
await importCompiledNotebook(parsed.src);
|
|
91
|
+
|
|
92
|
+
const importVariables: ImportVariableFunc[] = [];
|
|
93
|
+
const variables: VariableFunc[] = [];
|
|
94
|
+
parsed.specifiers.forEach(spec => {
|
|
95
|
+
const viewof = spec.view ? "viewof " : "";
|
|
96
|
+
importVariables.push(createImportVariable(viewof + spec.name, viewof + spec.alias));
|
|
97
|
+
if (spec.view) {
|
|
98
|
+
importVariables.push(createImportVariable(spec.name, spec.alias));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const retVal = (runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx) => {
|
|
103
|
+
|
|
104
|
+
let mod = runtime.module(otherModule);
|
|
105
|
+
if (parsed.injections.length) {
|
|
106
|
+
mod = mod.derive(parsed.injections, main);
|
|
107
|
+
}
|
|
108
|
+
variables.forEach(v => v(main, inspector));
|
|
109
|
+
importVariables.forEach(v => v(main, mod));
|
|
110
|
+
return mod;
|
|
111
|
+
};
|
|
112
|
+
retVal.importVariables = importVariables;
|
|
113
|
+
retVal.variables = variables;
|
|
114
|
+
retVal.delete = () => {
|
|
115
|
+
importVariables.forEach(v => v.delete());
|
|
116
|
+
variables.forEach(v => v.delete());
|
|
117
|
+
otherModule.delete();
|
|
118
|
+
};
|
|
119
|
+
retVal.write = (w: Writer) => {
|
|
120
|
+
otherModule.write(w);
|
|
121
|
+
w.importDefine(parsed);
|
|
122
|
+
};
|
|
123
|
+
return retVal;
|
|
124
|
+
}
|
|
125
|
+
type ModuleFunc = Awaited<ReturnType<typeof createModule>>;
|
|
126
|
+
|
|
127
|
+
// Variable ---
|
|
128
|
+
function createVariable(node: ohq.Node, inspect: boolean, name?: string, inputs?: string[], definition?: any, inline = false) {
|
|
75
129
|
|
|
76
130
|
let i: ohq.Inspector;
|
|
77
131
|
let v: ohq.Variable;
|
|
78
132
|
|
|
79
|
-
const retVal = (module: ohq.Module, inspector?:
|
|
80
|
-
i = inspect ? inspector(name) : undefined;
|
|
133
|
+
const retVal = (module: ohq.Module, inspector?: InspectorFactoryEx) => {
|
|
134
|
+
i = inspect ? inspector(name, node.id) : undefined;
|
|
81
135
|
v = module.variable(i);
|
|
82
136
|
if (arguments.length > 1) {
|
|
83
137
|
try {
|
|
@@ -86,9 +140,21 @@ function createVariable(inspect: boolean, name?: string, inputs?: string[], defi
|
|
|
86
140
|
console.error(e?.message);
|
|
87
141
|
}
|
|
88
142
|
}
|
|
143
|
+
if (node.pinned) {
|
|
144
|
+
v = module.variable(inspector(name, node.id));
|
|
145
|
+
try {
|
|
146
|
+
v.define(undefined, ["md"], md => {
|
|
147
|
+
return md`\`\`\`js
|
|
148
|
+
${node.value}
|
|
149
|
+
\`\`\``;
|
|
150
|
+
});
|
|
151
|
+
} catch (e: any) {
|
|
152
|
+
console.error(e?.message);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
89
155
|
return v;
|
|
90
156
|
};
|
|
91
|
-
retVal.
|
|
157
|
+
retVal.delete = () => {
|
|
92
158
|
try {
|
|
93
159
|
i?._node?.remove();
|
|
94
160
|
} catch (e) {
|
|
@@ -121,98 +187,54 @@ function createImportVariable(name?: string, alias?: string) {
|
|
|
121
187
|
v.import(name, alias, otherModule);
|
|
122
188
|
};
|
|
123
189
|
|
|
124
|
-
retVal.
|
|
190
|
+
retVal.delete = () => {
|
|
125
191
|
v?.delete();
|
|
126
192
|
};
|
|
127
193
|
return retVal;
|
|
128
194
|
}
|
|
129
195
|
type ImportVariableFunc = ReturnType<typeof createImportVariable>;
|
|
130
196
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
await importFile(parsed.src, baseUrl) :
|
|
134
|
-
await importCompiledNotebook(parsed.src);
|
|
135
|
-
|
|
136
|
-
const importVariables: ImportVariableFunc[] = [];
|
|
137
|
-
const variables: VariableFunc[] = [];
|
|
138
|
-
parsed.specifiers.forEach(spec => {
|
|
139
|
-
const viewof = spec.view ? "viewof " : "";
|
|
140
|
-
importVariables.push(createImportVariable(viewof + spec.name, viewof + spec.alias));
|
|
141
|
-
if (spec.view) {
|
|
142
|
-
importVariables.push(createImportVariable(spec.name, spec.alias));
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
variables.push(createVariable(true, undefined, ["md"], md => {
|
|
146
|
-
return md`\`\`\`JavaScript
|
|
147
|
-
${text}
|
|
148
|
-
\`\`\``;
|
|
149
|
-
}));
|
|
150
|
-
|
|
151
|
-
const retVal = (runtime: ohq.Runtime, main: ohq.Module, inspector?: ohq.InspectorFactory) => {
|
|
152
|
-
|
|
153
|
-
let mod = runtime.module(otherModule);
|
|
154
|
-
if (parsed.injections.length) {
|
|
155
|
-
mod = mod.derive(parsed.injections, main);
|
|
156
|
-
}
|
|
157
|
-
variables.forEach(v => v(main, inspector));
|
|
158
|
-
importVariables.forEach(v => v(main, mod));
|
|
159
|
-
return mod;
|
|
160
|
-
};
|
|
161
|
-
retVal.importVariables = importVariables;
|
|
162
|
-
retVal.variables = variables;
|
|
163
|
-
retVal.dispose = () => {
|
|
164
|
-
importVariables.forEach(v => v.dispose());
|
|
165
|
-
variables.forEach(v => v.dispose());
|
|
166
|
-
otherModule.dispose();
|
|
167
|
-
};
|
|
168
|
-
retVal.write = (w: Writer) => {
|
|
169
|
-
otherModule.write(w);
|
|
170
|
-
w.importDefine(parsed);
|
|
171
|
-
};
|
|
172
|
-
return retVal;
|
|
173
|
-
}
|
|
174
|
-
type ModuleFunc = Awaited<ReturnType<typeof createModule>>;
|
|
175
|
-
|
|
176
|
-
async function createCell(node: ohq.Node, baseUrl: string) {
|
|
197
|
+
// Cell ---
|
|
198
|
+
async function createCell(node: ohq.Node, options: CompileOptions) {
|
|
177
199
|
const modules: ModuleFunc[] = [];
|
|
178
200
|
const variables: VariableFunc[] = [];
|
|
179
201
|
try {
|
|
180
202
|
const text = node.mode && node.mode !== "js" ? `${node.mode}\`${encodeBacktick(node.value)}\`` : node.value;
|
|
181
203
|
const parsedModule = splitModule(text);
|
|
182
|
-
for (const
|
|
183
|
-
const parsed = parseCell(text);
|
|
204
|
+
for (const cell of parsedModule) {
|
|
205
|
+
const parsed = parseCell(cell.text);
|
|
184
206
|
switch (parsed.type) {
|
|
185
207
|
case "import":
|
|
186
|
-
modules.push(await createModule(parsed, text,
|
|
208
|
+
modules.push(await createModule(node, parsed, cell.text, options));
|
|
187
209
|
break;
|
|
188
210
|
case "viewof":
|
|
189
|
-
variables.push(createVariable(true, parsed.variable.id, parsed.variable.inputs, parsed.variable.func));
|
|
190
|
-
variables.push(createVariable(false, parsed.variableValue.id, parsed.variableValue.inputs, parsed.variableValue.func, true));
|
|
211
|
+
variables.push(createVariable(node, true, parsed.variable.id, parsed.variable.inputs, parsed.variable.func));
|
|
212
|
+
variables.push(createVariable(node, false, parsed.variableValue.id, parsed.variableValue.inputs, parsed.variableValue.func, true));
|
|
191
213
|
break;
|
|
192
214
|
case "mutable":
|
|
193
|
-
variables.push(createVariable(false, parsed.initial.id, parsed.initial.inputs, parsed.initial.func));
|
|
194
|
-
variables.push(createVariable(false, parsed.variable.id, parsed.variable.inputs, parsed.variable.func));
|
|
195
|
-
variables.push(createVariable(true, parsed.variableValue.id, parsed.variableValue.inputs, parsed.variableValue.func, true));
|
|
215
|
+
variables.push(createVariable(node, false, parsed.initial.id, parsed.initial.inputs, parsed.initial.func));
|
|
216
|
+
variables.push(createVariable(node, false, parsed.variable.id, parsed.variable.inputs, parsed.variable.func));
|
|
217
|
+
variables.push(createVariable(node, true, parsed.variableValue.id, parsed.variableValue.inputs, parsed.variableValue.func, true));
|
|
196
218
|
break;
|
|
197
219
|
case "variable":
|
|
198
|
-
variables.push(createVariable(true, parsed.id, parsed.inputs, parsed.func));
|
|
220
|
+
variables.push(createVariable(node, true, parsed.id, parsed.inputs, parsed.func));
|
|
199
221
|
break;
|
|
200
222
|
}
|
|
201
223
|
}
|
|
202
224
|
} catch (e) {
|
|
203
|
-
variables.push(createVariable(true, undefined, [], e.message));
|
|
225
|
+
variables.push(createVariable(node, true, undefined, [], e.message));
|
|
204
226
|
}
|
|
205
227
|
|
|
206
|
-
const retVal = (runtime: ohq.Runtime, main: ohq.Module, inspector?:
|
|
228
|
+
const retVal = (runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx) => {
|
|
207
229
|
modules.forEach(imp => imp(runtime, main, inspector));
|
|
208
230
|
variables.forEach(v => v(main, inspector));
|
|
209
231
|
};
|
|
210
|
-
retVal.id =
|
|
232
|
+
retVal.id = node.id;
|
|
211
233
|
retVal.modules = modules;
|
|
212
234
|
retVal.variables = variables;
|
|
213
|
-
retVal.
|
|
214
|
-
variables.forEach(v => v.
|
|
215
|
-
modules.forEach(mod => mod.
|
|
235
|
+
retVal.delete = () => {
|
|
236
|
+
variables.forEach(v => v.delete());
|
|
237
|
+
modules.forEach(mod => mod.delete());
|
|
216
238
|
};
|
|
217
239
|
retVal.write = (w: Writer) => {
|
|
218
240
|
modules.forEach(imp => imp.write(w));
|
|
@@ -222,20 +244,24 @@ async function createCell(node: ohq.Node, baseUrl: string) {
|
|
|
222
244
|
}
|
|
223
245
|
export type CellFunc = Awaited<ReturnType<typeof createCell>>;
|
|
224
246
|
|
|
225
|
-
|
|
247
|
+
// File ---
|
|
248
|
+
function createFile(file: ohq.File, options: CompileOptions): [string, any] {
|
|
226
249
|
function toString() { return globalThis.url; }
|
|
227
|
-
return [file.name, { url: new URL(fullUrl(file.url, baseUrl)), mimeType: file.mime_type, toString }];
|
|
250
|
+
return [file.name, { url: new URL(fullUrl(file.url, options.baseUrl)), mimeType: file.mime_type, toString }];
|
|
228
251
|
}
|
|
229
|
-
|
|
252
|
+
type FileFunc = ReturnType<typeof createFile>;
|
|
230
253
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
254
|
+
// Interpret ---
|
|
255
|
+
export interface CompileOptions {
|
|
256
|
+
baseUrl?: string;
|
|
257
|
+
importMode?: "recursive" | "precompiled";
|
|
258
|
+
}
|
|
259
|
+
export function notebook(_files: ohq.File[] = [], _cells: CellFunc[] = [], { baseUrl = ".", importMode = "precompiled" }: CompileOptions = {}) {
|
|
260
|
+
const files: FileFunc[] = _files.map(f => createFile(f, { baseUrl, importMode }));
|
|
234
261
|
const fileAttachments = new Map<string, any>(files);
|
|
235
|
-
const
|
|
236
|
-
const cells = new Map<string, CellFunc>(_cells.map(c => [c.id, c]));
|
|
262
|
+
const cells = new Map<string | number, CellFunc>(_cells.map(c => [c.id, c]));
|
|
237
263
|
|
|
238
|
-
const retVal = (runtime: ohq.Runtime, inspector?:
|
|
264
|
+
const retVal = (runtime: ohq.Runtime, inspector?: InspectorFactoryEx): ohq.Module => {
|
|
239
265
|
const main = runtime.module();
|
|
240
266
|
main.builtin("FileAttachment", runtime.fileAttachments(name => {
|
|
241
267
|
return fileAttachments.get(name) ?? { url: new URL(fullUrl(name, baseUrl)), mimeType: null };
|
|
@@ -249,25 +275,29 @@ export async function compile(notebook: ohq.Notebook, baseUrl: string = ".") {
|
|
|
249
275
|
};
|
|
250
276
|
retVal.fileAttachments = fileAttachments;
|
|
251
277
|
retVal.cells = cells;
|
|
252
|
-
retVal.
|
|
253
|
-
const cell = await createCell(n, baseUrl);
|
|
254
|
-
retVal.
|
|
278
|
+
retVal.set = async (n: ohq.Node): Promise<CellFunc> => {
|
|
279
|
+
const cell = await createCell(n, { baseUrl, importMode });
|
|
280
|
+
retVal.delete(cell.id);
|
|
255
281
|
cells.set(cell.id, cell);
|
|
256
282
|
return cell;
|
|
257
283
|
};
|
|
258
|
-
retVal.
|
|
284
|
+
retVal.get = (id: string | number): CellFunc => {
|
|
285
|
+
return cells.get(id);
|
|
286
|
+
};
|
|
287
|
+
retVal.delete = (id: string | number): boolean => {
|
|
259
288
|
const cell = cells.get(id);
|
|
260
289
|
if (cell) {
|
|
261
|
-
|
|
262
|
-
|
|
290
|
+
cell.delete();
|
|
291
|
+
return cells.delete(id);
|
|
263
292
|
}
|
|
293
|
+
return false;
|
|
264
294
|
};
|
|
265
|
-
retVal.
|
|
266
|
-
cells.forEach(cell => cell.
|
|
295
|
+
retVal.clear = () => {
|
|
296
|
+
cells.forEach(cell => cell.delete());
|
|
267
297
|
cells.clear();
|
|
268
298
|
};
|
|
269
299
|
retVal.write = (w: Writer) => {
|
|
270
|
-
w.files(
|
|
300
|
+
w.files(_files);
|
|
271
301
|
cells.forEach(cell => cell.write(w));
|
|
272
302
|
};
|
|
273
303
|
retVal.toString = (w = new Writer()) => {
|
|
@@ -276,4 +306,10 @@ export async function compile(notebook: ohq.Notebook, baseUrl: string = ".") {
|
|
|
276
306
|
};
|
|
277
307
|
return retVal;
|
|
278
308
|
}
|
|
309
|
+
|
|
310
|
+
export async function compile(notebookOrOjs: ohq.Notebook | string, { baseUrl = ".", importMode = "precompiled" }: CompileOptions = {}) {
|
|
311
|
+
const ojsNotebook = typeof notebookOrOjs === "string" ? ojs2notebook(notebookOrOjs) : notebookOrOjs;
|
|
312
|
+
const _cells: CellFunc[] = await Promise.all(ojsNotebook.nodes.map(n => createCell(n, { baseUrl, importMode })));
|
|
313
|
+
return notebook(ojsNotebook.files, _cells, { baseUrl, importMode });
|
|
314
|
+
}
|
|
279
315
|
export type compileFunc = Awaited<ReturnType<typeof compile>>;
|
package/src/index.ts
CHANGED
package/src/util.ts
CHANGED
|
@@ -77,7 +77,7 @@ function createParsedOJS(ojs: string, offset: number, inlineMD: boolean): Parsed
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
function splitOmd(_: string): ParsedOJS[] {
|
|
81
81
|
const retVal: ParsedOJS[] = [];
|
|
82
82
|
// Load Markdown ---
|
|
83
83
|
const re = /(```(?:\s|\S)[\s\S]*?```)/g;
|
|
@@ -119,21 +119,25 @@ export function ojs2notebook(ojs: string): ohq.Notebook {
|
|
|
119
119
|
return {
|
|
120
120
|
id: idx,
|
|
121
121
|
mode: "js",
|
|
122
|
-
value: cell
|
|
122
|
+
value: cell.text,
|
|
123
|
+
start: cell.start,
|
|
124
|
+
end: cell.end
|
|
123
125
|
};
|
|
124
126
|
})
|
|
125
127
|
} as ohq.Notebook;
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
export function omd2notebook(omd: string): ohq.Notebook {
|
|
129
|
-
const cells =
|
|
131
|
+
const cells = splitOmd(omd);
|
|
130
132
|
return {
|
|
131
133
|
files: [],
|
|
132
134
|
nodes: cells.map((cell, idx) => {
|
|
133
135
|
return {
|
|
134
136
|
id: idx,
|
|
135
137
|
mode: cell.inlineMD ? "md" : "js",
|
|
136
|
-
value: cell.ojs
|
|
138
|
+
value: cell.ojs,
|
|
139
|
+
start: cell.offset,
|
|
140
|
+
end: cell.offset + cell.ojs.length
|
|
137
141
|
};
|
|
138
142
|
})
|
|
139
143
|
} as ohq.Notebook;
|
package/types/__package__.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const PKG_NAME = "@hpcc-js/observablehq-compiler";
|
|
2
|
-
export declare const PKG_VERSION = "1.
|
|
3
|
-
export declare const BUILD_VERSION = "2.104.
|
|
2
|
+
export declare const PKG_VERSION = "1.2.0";
|
|
3
|
+
export declare const BUILD_VERSION = "2.104.9";
|
|
4
4
|
//# sourceMappingURL=__package__.d.ts.map
|
package/types/compiler.d.ts
CHANGED
|
@@ -1,88 +1,157 @@
|
|
|
1
1
|
import { ohq } from "@hpcc-js/observable-shim";
|
|
2
2
|
import { Writer } from "./writer";
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare type InspectorFactoryEx = (name: string | undefined, id: string | number) => Inspector;
|
|
4
|
+
export interface Inspector {
|
|
5
|
+
_node?: HTMLDivElement;
|
|
6
|
+
pending(): any;
|
|
7
|
+
fulfilled(value: any): any;
|
|
8
|
+
rejected(error: any): any;
|
|
9
|
+
}
|
|
10
|
+
declare function createCell(node: ohq.Node, options: CompileOptions): Promise<{
|
|
11
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): void;
|
|
12
|
+
id: string | number;
|
|
6
13
|
modules: {
|
|
7
|
-
(runtime: ohq.Runtime, main: ohq.Module, inspector?:
|
|
14
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): ohq.Module;
|
|
8
15
|
importVariables: {
|
|
9
16
|
(main: ohq.Module, otherModule: ohq.Module): void;
|
|
10
|
-
|
|
17
|
+
delete(): void;
|
|
11
18
|
}[];
|
|
12
19
|
variables: {
|
|
13
|
-
(module: ohq.Module, inspector?:
|
|
14
|
-
|
|
20
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
21
|
+
delete(): void;
|
|
15
22
|
write(w: Writer): void;
|
|
16
23
|
}[];
|
|
17
|
-
|
|
24
|
+
delete(): void;
|
|
18
25
|
write(w: Writer): void;
|
|
19
26
|
}[];
|
|
20
27
|
variables: {
|
|
21
|
-
(module: ohq.Module, inspector?:
|
|
22
|
-
|
|
28
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
29
|
+
delete(): void;
|
|
23
30
|
write(w: Writer): void;
|
|
24
31
|
}[];
|
|
25
|
-
|
|
32
|
+
delete(): void;
|
|
26
33
|
write(w: Writer): void;
|
|
27
34
|
}>;
|
|
28
35
|
export declare type CellFunc = Awaited<ReturnType<typeof createCell>>;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
export interface CompileOptions {
|
|
37
|
+
baseUrl?: string;
|
|
38
|
+
importMode?: "recursive" | "precompiled";
|
|
39
|
+
}
|
|
40
|
+
export declare function notebook(_files?: ohq.File[], _cells?: CellFunc[], { baseUrl, importMode }?: CompileOptions): {
|
|
41
|
+
(runtime: ohq.Runtime, inspector?: InspectorFactoryEx): ohq.Module;
|
|
33
42
|
fileAttachments: Map<string, any>;
|
|
34
|
-
cells: Map<string, {
|
|
35
|
-
(runtime: ohq.Runtime, main: ohq.Module, inspector?:
|
|
36
|
-
id: string;
|
|
43
|
+
cells: Map<string | number, {
|
|
44
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): void;
|
|
45
|
+
id: string | number;
|
|
37
46
|
modules: {
|
|
38
|
-
(runtime: ohq.Runtime, main: ohq.Module, inspector?:
|
|
47
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): ohq.Module;
|
|
39
48
|
importVariables: {
|
|
40
49
|
(main: ohq.Module, otherModule: ohq.Module): void;
|
|
41
|
-
|
|
50
|
+
delete(): void;
|
|
42
51
|
}[];
|
|
43
52
|
variables: {
|
|
44
|
-
(module: ohq.Module, inspector?:
|
|
45
|
-
|
|
53
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
54
|
+
delete(): void;
|
|
46
55
|
write(w: Writer): void;
|
|
47
56
|
}[];
|
|
48
|
-
|
|
57
|
+
delete(): void;
|
|
49
58
|
write(w: Writer): void;
|
|
50
59
|
}[];
|
|
51
60
|
variables: {
|
|
52
|
-
(module: ohq.Module, inspector?:
|
|
53
|
-
|
|
61
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
62
|
+
delete(): void;
|
|
54
63
|
write(w: Writer): void;
|
|
55
64
|
}[];
|
|
56
|
-
|
|
65
|
+
delete(): void;
|
|
57
66
|
write(w: Writer): void;
|
|
58
67
|
}>;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
set(n: ohq.Node): Promise<CellFunc>;
|
|
69
|
+
get(id: string | number): CellFunc;
|
|
70
|
+
delete(id: string | number): boolean;
|
|
71
|
+
clear(): void;
|
|
72
|
+
write(w: Writer): void;
|
|
73
|
+
toString(w?: Writer): string;
|
|
74
|
+
};
|
|
75
|
+
export declare function compile(notebookOrOjs: ohq.Notebook | string, { baseUrl, importMode }?: CompileOptions): Promise<{
|
|
76
|
+
(runtime: ohq.Runtime, inspector?: InspectorFactoryEx): ohq.Module;
|
|
77
|
+
fileAttachments: Map<string, any>;
|
|
78
|
+
cells: Map<string | number, {
|
|
79
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): void;
|
|
80
|
+
id: string | number;
|
|
81
|
+
modules: {
|
|
82
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): ohq.Module;
|
|
83
|
+
importVariables: {
|
|
84
|
+
(main: ohq.Module, otherModule: ohq.Module): void;
|
|
85
|
+
delete(): void;
|
|
86
|
+
}[];
|
|
87
|
+
variables: {
|
|
88
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
89
|
+
delete(): void;
|
|
90
|
+
write(w: Writer): void;
|
|
91
|
+
}[];
|
|
92
|
+
delete(): void;
|
|
93
|
+
write(w: Writer): void;
|
|
94
|
+
}[];
|
|
95
|
+
variables: {
|
|
96
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
97
|
+
delete(): void;
|
|
98
|
+
write(w: Writer): void;
|
|
99
|
+
}[];
|
|
100
|
+
delete(): void;
|
|
101
|
+
write(w: Writer): void;
|
|
102
|
+
}>;
|
|
103
|
+
set(n: ohq.Node): Promise<{
|
|
104
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): void;
|
|
105
|
+
id: string | number;
|
|
62
106
|
modules: {
|
|
63
|
-
(runtime: ohq.Runtime, main: ohq.Module, inspector?:
|
|
107
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): ohq.Module;
|
|
64
108
|
importVariables: {
|
|
65
109
|
(main: ohq.Module, otherModule: ohq.Module): void;
|
|
66
|
-
|
|
110
|
+
delete(): void;
|
|
67
111
|
}[];
|
|
68
112
|
variables: {
|
|
69
|
-
(module: ohq.Module, inspector?:
|
|
70
|
-
|
|
113
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
114
|
+
delete(): void;
|
|
71
115
|
write(w: Writer): void;
|
|
72
116
|
}[];
|
|
73
|
-
|
|
117
|
+
delete(): void;
|
|
74
118
|
write(w: Writer): void;
|
|
75
119
|
}[];
|
|
76
120
|
variables: {
|
|
77
|
-
(module: ohq.Module, inspector?:
|
|
78
|
-
|
|
121
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
122
|
+
delete(): void;
|
|
79
123
|
write(w: Writer): void;
|
|
80
124
|
}[];
|
|
81
|
-
|
|
125
|
+
delete(): void;
|
|
82
126
|
write(w: Writer): void;
|
|
83
127
|
}>;
|
|
84
|
-
|
|
85
|
-
|
|
128
|
+
get(id: string | number): {
|
|
129
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): void;
|
|
130
|
+
id: string | number;
|
|
131
|
+
modules: {
|
|
132
|
+
(runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): ohq.Module;
|
|
133
|
+
importVariables: {
|
|
134
|
+
(main: ohq.Module, otherModule: ohq.Module): void;
|
|
135
|
+
delete(): void;
|
|
136
|
+
}[];
|
|
137
|
+
variables: {
|
|
138
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
139
|
+
delete(): void;
|
|
140
|
+
write(w: Writer): void;
|
|
141
|
+
}[];
|
|
142
|
+
delete(): void;
|
|
143
|
+
write(w: Writer): void;
|
|
144
|
+
}[];
|
|
145
|
+
variables: {
|
|
146
|
+
(module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
|
|
147
|
+
delete(): void;
|
|
148
|
+
write(w: Writer): void;
|
|
149
|
+
}[];
|
|
150
|
+
delete(): void;
|
|
151
|
+
write(w: Writer): void;
|
|
152
|
+
};
|
|
153
|
+
delete(id: string | number): boolean;
|
|
154
|
+
clear(): void;
|
|
86
155
|
write(w: Writer): void;
|
|
87
156
|
toString(w?: Writer): string;
|
|
88
157
|
}>;
|
package/types/compiler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC,oBAAY,kBAAkB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,SAAS,CAAC;AAE9F,MAAM,WAAW,SAAS;IACtB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,OAAO,QAAG;IACV,SAAS,CAAC,KAAK,KAAA,OAAE;IACjB,QAAQ,CAAC,KAAK,KAAA,OAAE;CACnB;AAuLD,iBAAe,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,cAAc;cA8BpC,IAAI,OAAO,QAAQ,IAAI,MAAM,cAAc,kBAAkB;;;;;;;;;;;;;;;;;;;;;;aAWnE,MAAM;GAK5B;AACD,oBAAY,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC;AAU9D,MAAM,WAAW,cAAc;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC;CAC5C;AACD,wBAAgB,QAAQ,CAAC,MAAM,GAAE,GAAG,CAAC,IAAI,EAAO,EAAE,MAAM,GAAE,QAAQ,EAAO,EAAE,EAAE,OAAa,EAAE,UAA0B,EAAE,GAAE,cAAmB;cAKhH,IAAI,OAAO,cAAc,kBAAkB,GAAG,IAAI,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;WAc1D,QAAQ,GAAG,QAAQ,QAAQ,CAAC;YAMjC,MAAM,GAAG,MAAM,GAAG,QAAQ;eAGvB,MAAM,GAAG,MAAM,GAAG,OAAO;;aAY3B,MAAM;;EAS5B;AAED,wBAAsB,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,QAAQ,GAAG,MAAM,EAAE,EAAE,OAAa,EAAE,UAA0B,EAAE,GAAE,cAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIrI;AACD,oBAAY,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC"}
|