@observablehq/notebook-kit 2.4.0 → 2.5.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/dist/package.json
CHANGED
|
@@ -20,7 +20,7 @@ function getImportAttributeKey(node) {
|
|
|
20
20
|
export function renderObservableImport(source, node, inputs) {
|
|
21
21
|
if (!inputs.includes("@variable"))
|
|
22
22
|
inputs.push("@variable");
|
|
23
|
-
return `(import(${
|
|
23
|
+
return `(import(${source}).then((_) => {
|
|
24
24
|
const module = __variable._module._runtime.module(_.default)${"injections" in node ? `.derive([${renderObservableInjections(node)}], __variable._module)` : ""};
|
|
25
25
|
const outputs = new Map(Array.from(__variable._outputs, (v) => [v._name, v]));${flatMapImportSpecifiers(node, (specifier) => {
|
|
26
26
|
const i = dedollar(getImportedName(specifier));
|
|
@@ -93,16 +93,17 @@ export function rewriteImportDeclarations(output, body, inputs, { resolveImport
|
|
|
93
93
|
});
|
|
94
94
|
const specifiers = [];
|
|
95
95
|
const imports = [];
|
|
96
|
-
for (const [node,
|
|
96
|
+
for (const [node, literal] of declarations) {
|
|
97
97
|
output.delete(node.start, node.end + +(output.input[node.end] === "\n"));
|
|
98
98
|
specifiers.push(rewriteImportSpecifiers(node));
|
|
99
|
-
const value = getStringLiteralValue(
|
|
99
|
+
const value = getStringLiteralValue(literal);
|
|
100
100
|
const resolution = resolveImport(value);
|
|
101
|
+
const source = resolveLocalImports && isLocalImport(resolution)
|
|
102
|
+
? `new URL(${JSON.stringify(resolution)}, document.baseURI)`
|
|
103
|
+
: JSON.stringify(resolution);
|
|
101
104
|
imports.push(isObservableImport(node, value)
|
|
102
|
-
? renderObservableImport(
|
|
103
|
-
: renderImport(
|
|
104
|
-
? `new URL(${JSON.stringify(resolution)}, document.baseURI)`
|
|
105
|
-
: JSON.stringify(resolution), node, output.input));
|
|
105
|
+
? renderObservableImport(source, node, inputs)
|
|
106
|
+
: renderImport(source, node, output.input));
|
|
106
107
|
}
|
|
107
108
|
if (declarations.length > 1) {
|
|
108
109
|
output.insertLeft(0, `const [${specifiers.join(", ")}] = await Promise.all([${imports.join(", ")}]);\n`); // prettier-ignore
|
|
@@ -103,8 +103,8 @@ export function transpileTemplate(input, tag = "", raw = false) {
|
|
|
103
103
|
(raw ? escapeRawTemplateElements : escapeTemplateElements)(source, template);
|
|
104
104
|
node = template;
|
|
105
105
|
}
|
|
106
|
-
source.insertLeft(node.start, `${prefix}\``);
|
|
107
|
-
source.insertRight(node.end, `\`${suffix}`);
|
|
106
|
+
source.insertLeft(node.start, `${cell?.output ? `const ${cell.output} = ` : ""}${prefix}\``);
|
|
107
|
+
source.insertRight(node.end, `\`${suffix}${cell?.output ? ";" : ""}`);
|
|
108
108
|
return String(source);
|
|
109
109
|
}
|
|
110
110
|
function getRaw(cell) {
|
|
@@ -128,10 +128,10 @@ function getDatabase(cell) {
|
|
|
128
128
|
: `DatabaseClient(${JSON.stringify(database)}, {id: ${id}${since === undefined ? "" : `, since: ${JSON.stringify(since)}`}})`;
|
|
129
129
|
}
|
|
130
130
|
function getSqlPrefix(cell) {
|
|
131
|
-
return `${getDatabase(cell)}.sql`;
|
|
131
|
+
return `${cell.hidden ? "" : cell.output ? "((_) => (display(Inputs.table(_)), _))(" : "Inputs.table("}await ${getDatabase(cell)}.sql`;
|
|
132
132
|
}
|
|
133
133
|
function getSqlSuffix(cell) {
|
|
134
|
-
return cell.hidden ? "" : "
|
|
134
|
+
return cell.hidden ? "" : ")";
|
|
135
135
|
}
|
|
136
136
|
function getSqlViewSuffix(cell) {
|
|
137
137
|
return `.bind(${getDatabase(cell)})`;
|
|
@@ -30,12 +30,6 @@ export function transpile(input, mode, options) {
|
|
|
30
30
|
transpiled.output = cell.output;
|
|
31
31
|
if (cell.hidden)
|
|
32
32
|
transpiled.autodisplay = false;
|
|
33
|
-
else if (mode !== "js" && mode !== "ts" && mode !== "ojs") {
|
|
34
|
-
transpiled.autodisplay = !!input;
|
|
35
|
-
transpiled.autoview = mode === "sql" && transpiled.autodisplay && !!transpiled.output;
|
|
36
|
-
if (transpiled.autoview)
|
|
37
|
-
transpiled.output = `viewof$${transpiled.output}`;
|
|
38
|
-
}
|
|
39
33
|
return transpiled;
|
|
40
34
|
}
|
|
41
35
|
export function transpileTypeScript(input, options) {
|