@observablehq/notebook-kit 2.1.0 → 2.1.1
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/package.json +1 -1
- package/dist/src/javascript/imports/observable.js +9 -13
- package/dist/src/javascript/imports.d.ts +1 -0
- package/dist/src/javascript/imports.js +2 -2
- package/dist/src/javascript/transpile.js +4 -1
- package/dist/src/runtime/index.js +2 -2
- package/dist/src/runtime/stdlib/index.d.ts +0 -2
- package/dist/src/runtime/stdlib/index.js +0 -2
- package/package.json +1 -1
- package/dist/src/runtime/stdlib/observer.d.ts +0 -16
- package/dist/src/runtime/stdlib/observer.js +0 -42
package/dist/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getImportedName } from "../imports.js";
|
|
1
|
+
import { getImportedName, getLocalName } from "../imports.js";
|
|
2
2
|
const CODE_DOLLAR = 36;
|
|
3
3
|
/** If specifier is an observable: protocol import, resolves it. */
|
|
4
4
|
export function resolveObservableImport(specifier) {
|
|
@@ -18,25 +18,21 @@ function getImportAttributeKey(node) {
|
|
|
18
18
|
}
|
|
19
19
|
/** Note: mutates inputs! */
|
|
20
20
|
export function renderObservableImport(source, node, inputs) {
|
|
21
|
-
if (!inputs.includes("
|
|
22
|
-
inputs.push("
|
|
23
|
-
if (!inputs.includes("__ojs_observer"))
|
|
24
|
-
inputs.push("__ojs_observer");
|
|
21
|
+
if (!inputs.includes("@variable"))
|
|
22
|
+
inputs.push("@variable");
|
|
25
23
|
return `(import(${JSON.stringify(source)}).then((_) => {
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const main = __ojs_runtime.module();${node.specifiers
|
|
24
|
+
const module = __variable._module._runtime.module(_.default);
|
|
25
|
+
const outputs = new Map(Array.from(__variable._outputs, (v) => [v._name, v]));${node.specifiers
|
|
29
26
|
.map((specifier) => {
|
|
30
27
|
if (specifier.type === "ImportNamespaceSpecifier")
|
|
31
28
|
throw new SyntaxError("observable namespace imports are not supported");
|
|
32
|
-
const iname = getImportedName(specifier);
|
|
33
|
-
const
|
|
29
|
+
const iname = dedollar(getImportedName(specifier));
|
|
30
|
+
const lname = getLocalName(specifier);
|
|
34
31
|
return `
|
|
35
|
-
|
|
36
|
-
main.variable(observers.${iname} = __ojs_observer()).import("${vname}", module);`;
|
|
32
|
+
outputs.get(${JSON.stringify(lname)})?.import(${JSON.stringify(iname)}${iname === lname ? "" : `, ${JSON.stringify(lname)}`}, module);`;
|
|
37
33
|
})
|
|
38
34
|
.join("")}
|
|
39
|
-
return
|
|
35
|
+
return {};
|
|
40
36
|
}))`;
|
|
41
37
|
}
|
|
42
38
|
/** Turns e.g. "viewof$foo" into "viewof foo", and "$$" into "$". */
|
|
@@ -19,5 +19,6 @@ export type RewriteImportOptions = {
|
|
|
19
19
|
export declare function rewriteImportExpressions(output: Sourcemap, body: Node, { resolveLocalImports }?: RewriteImportOptions): void;
|
|
20
20
|
/** Note: mutates inputs! */
|
|
21
21
|
export declare function rewriteImportDeclarations(output: Sourcemap, body: Node, inputs: string[], { resolveLocalImports }?: RewriteImportOptions): void;
|
|
22
|
+
export declare function getLocalName(node: NamedImportSpecifier): string;
|
|
22
23
|
export declare function getImportedName(node: NamedImportSpecifier): string;
|
|
23
24
|
export {};
|
|
@@ -98,7 +98,7 @@ export function rewriteImportDeclarations(output, body, inputs, { resolveLocalIm
|
|
|
98
98
|
: JSON.stringify(resolution), node, output.input));
|
|
99
99
|
}
|
|
100
100
|
if (declarations.length > 1) {
|
|
101
|
-
output.insertLeft(0, `const [${specifiers.join(", ")}] = await Promise.all([${imports.join(", ")}]);\n`);
|
|
101
|
+
output.insertLeft(0, `const [${specifiers.join(", ")}] = await Promise.all([${imports.join(", ")}]);\n`); // prettier-ignore
|
|
102
102
|
}
|
|
103
103
|
else if (declarations.length === 1) {
|
|
104
104
|
output.insertLeft(0, `const ${specifiers[0]} = await ${imports[0]};\n`);
|
|
@@ -117,7 +117,7 @@ function renderImport(source, node, input) {
|
|
|
117
117
|
})`
|
|
118
118
|
: ""}`;
|
|
119
119
|
}
|
|
120
|
-
function getLocalName(node) {
|
|
120
|
+
export function getLocalName(node) {
|
|
121
121
|
return node.local.name;
|
|
122
122
|
}
|
|
123
123
|
export function getImportedName(node) {
|
|
@@ -52,7 +52,7 @@ export function transpileJavaScript(input, options) {
|
|
|
52
52
|
rewriteFileExpressions(output, cell.body);
|
|
53
53
|
if (cell.expression)
|
|
54
54
|
output.insertLeft(0, `return (\n`);
|
|
55
|
-
output.insertLeft(0, `${async ? "async " : ""}(${inputs}) => {\n`);
|
|
55
|
+
output.insertLeft(0, `${async ? "async " : ""}(${inputs.map(deat)}) => {\n`);
|
|
56
56
|
if (outputs.length > 0)
|
|
57
57
|
output.insertRight(input.length, `\nreturn {${outputs}};`);
|
|
58
58
|
if (cell.expression)
|
|
@@ -65,3 +65,6 @@ export function transpileJavaScript(input, options) {
|
|
|
65
65
|
const secrets = new Set(cell.secrets.map((f) => f.argument));
|
|
66
66
|
return { body, inputs, outputs, autodisplay, files, databases, secrets };
|
|
67
67
|
}
|
|
68
|
+
function deat(input) {
|
|
69
|
+
return input.replace(/^@/, "__"); // @variable to __variable
|
|
70
|
+
}
|
|
@@ -22,7 +22,7 @@ export class NotebookRuntime {
|
|
|
22
22
|
writable: true,
|
|
23
23
|
value: void 0
|
|
24
24
|
});
|
|
25
|
-
const runtime = new Runtime(
|
|
25
|
+
const runtime = new Runtime(builtins);
|
|
26
26
|
this.runtime = Object.assign(runtime, { fileAttachments });
|
|
27
27
|
this.main = runtime.module();
|
|
28
28
|
}
|
|
@@ -35,7 +35,7 @@ export const runtime = defaultNotebook.runtime;
|
|
|
35
35
|
export const main = defaultNotebook.main;
|
|
36
36
|
export const define = defaultNotebook.define.bind(defaultNotebook);
|
|
37
37
|
main.constructor.prototype.defines = function (name) {
|
|
38
|
-
return (this._scope.has(name) ||
|
|
38
|
+
return (this._scope.has(name) || // prettier
|
|
39
39
|
this._builtins.has(name) ||
|
|
40
40
|
this._runtime._builtin._scope.has(name));
|
|
41
41
|
};
|
|
@@ -5,7 +5,6 @@ import { FileAttachment } from "./fileAttachment.js";
|
|
|
5
5
|
import * as Generators from "./generators/index.js";
|
|
6
6
|
import { Interpreter } from "./interpreter.js";
|
|
7
7
|
import { Mutable } from "./mutable.js";
|
|
8
|
-
import { Observer } from "./observer.js";
|
|
9
8
|
import * as Promises from "./promises/index.js";
|
|
10
9
|
export declare const root: HTMLElement;
|
|
11
10
|
export declare const library: {
|
|
@@ -104,5 +103,4 @@ export declare const library: {
|
|
|
104
103
|
Promises: () => typeof Promises;
|
|
105
104
|
Files: () => typeof Files;
|
|
106
105
|
DOM: () => typeof DOM;
|
|
107
|
-
__ojs_observer: () => () => Observer;
|
|
108
106
|
};
|
|
@@ -5,7 +5,6 @@ import { FileAttachment } from "./fileAttachment.js";
|
|
|
5
5
|
import * as Generators from "./generators/index.js";
|
|
6
6
|
import { Interpreter } from "./interpreter.js";
|
|
7
7
|
import { Mutable } from "./mutable.js";
|
|
8
|
-
import { Observer } from "./observer.js";
|
|
9
8
|
import * as Promises from "./promises/index.js";
|
|
10
9
|
import * as recommendedLibraries from "./recommendedLibraries.js";
|
|
11
10
|
import * as sampleDatasets from "./sampleDatasets.js";
|
|
@@ -22,7 +21,6 @@ export const library = {
|
|
|
22
21
|
Promises: () => Promises, // deprecated!
|
|
23
22
|
Files: () => Files, // deprecated!
|
|
24
23
|
DOM: () => DOM, // deprecated!
|
|
25
|
-
__ojs_observer: () => () => new Observer(),
|
|
26
24
|
...recommendedLibraries,
|
|
27
25
|
...sampleDatasets
|
|
28
26
|
};
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare class Observer {
|
|
2
|
-
#private;
|
|
3
|
-
fulfilled?: (value: unknown) => void;
|
|
4
|
-
rejected?: (error: unknown) => void;
|
|
5
|
-
constructor();
|
|
6
|
-
next(): Promise<{
|
|
7
|
-
done: boolean;
|
|
8
|
-
value: unknown;
|
|
9
|
-
}>;
|
|
10
|
-
throw(): {
|
|
11
|
-
done: boolean;
|
|
12
|
-
};
|
|
13
|
-
return(): {
|
|
14
|
-
done: boolean;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _Observer_promise;
|
|
13
|
-
export class Observer {
|
|
14
|
-
constructor() {
|
|
15
|
-
_Observer_promise.set(this, void 0);
|
|
16
|
-
Object.defineProperty(this, "fulfilled", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true,
|
|
20
|
-
value: void 0
|
|
21
|
-
});
|
|
22
|
-
Object.defineProperty(this, "rejected", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true,
|
|
26
|
-
value: void 0
|
|
27
|
-
});
|
|
28
|
-
this.next();
|
|
29
|
-
}
|
|
30
|
-
async next() {
|
|
31
|
-
const value = await __classPrivateFieldGet(this, _Observer_promise, "f");
|
|
32
|
-
__classPrivateFieldSet(this, _Observer_promise, new Promise((res, rej) => ((this.fulfilled = res), (this.rejected = rej))), "f");
|
|
33
|
-
return { done: false, value };
|
|
34
|
-
}
|
|
35
|
-
throw() {
|
|
36
|
-
return { done: true };
|
|
37
|
-
}
|
|
38
|
-
return() {
|
|
39
|
-
return { done: true };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
_Observer_promise = new WeakMap();
|