@observablehq/notebook-kit 2.6.4 → 2.6.5

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
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "2.6.4",
8
+ "version": "2.6.5",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "TZ=America/Los_Angeles vitest",
@@ -23,9 +23,9 @@ export type ImportOptions = {
23
23
  /** If specified, allows renaming of imported variables such as viewof$foo for backwards compatibility. */
24
24
  renameObservableImport?: (name: string) => string;
25
25
  };
26
- export declare function rewriteImportExpressions(output: Sourcemap, body: Node, { resolveImport, resolveLocalImports }?: ImportOptions): void;
26
+ export declare function rewriteImportExpressions(output: Sourcemap, body: Node, { resolveImport, resolveLocalImports }?: ImportOptions): Set<string>;
27
27
  /** Note: mutates inputs! */
28
- export declare function rewriteImportDeclarations(output: Sourcemap, body: Node, inputs: string[], { resolveImport, resolveLocalImports, renameObservableImport }?: ImportOptions): void;
28
+ export declare function rewriteImportDeclarations(output: Sourcemap, body: Node, inputs: string[], { resolveImport, resolveLocalImports, renameObservableImport }?: ImportOptions): Set<string>;
29
29
  export declare function getLocalName(node: NamedImportSpecifier): string;
30
30
  export declare function getImportedName(node: NamedImportSpecifier): string;
31
31
  export declare function flatMapImportSpecifiers<T>(node: ImportDeclaration, f: (node: NamedImportSpecifier) => T): T[];
@@ -51,8 +51,10 @@ export function resolveImportDefault(specifier) {
51
51
  return resolveObservableImport(resolveJsrImport(resolveNpmImport(specifier)));
52
52
  }
53
53
  export function rewriteImportExpressions(output, body, { resolveImport = resolveImportDefault, resolveLocalImports } = {}) {
54
+ const sources = new Set();
54
55
  function rewriteImportSource(source, node = source) {
55
56
  const value = getStringLiteralValue(source);
57
+ sources.add(value);
56
58
  const resolution = resolveImport(value);
57
59
  output.replaceLeft(node.start, node.end, resolveLocalImports && isLocalImport(resolution)
58
60
  ? `new URL(${JSON.stringify(resolution)}, document.baseURI).href`
@@ -77,9 +79,11 @@ export function rewriteImportExpressions(output, body, { resolveImport = resolve
77
79
  }
78
80
  }
79
81
  });
82
+ return sources;
80
83
  }
81
84
  /** Note: mutates inputs! */
82
85
  export function rewriteImportDeclarations(output, body, inputs, { resolveImport = resolveImportDefault, resolveLocalImports, renameObservableImport = dedollar } = {}) {
86
+ const sources = new Set();
83
87
  const declarations = [];
84
88
  simple(body, {
85
89
  ImportDeclaration(node) {
@@ -97,6 +101,7 @@ export function rewriteImportDeclarations(output, body, inputs, { resolveImport
97
101
  output.delete(node.start, node.end + +(output.input[node.end] === "\n"));
98
102
  specifiers.push(rewriteImportSpecifiers(node));
99
103
  const value = getStringLiteralValue(literal);
104
+ sources.add(value);
100
105
  const resolution = resolveImport(value);
101
106
  const source = resolveLocalImports && isLocalImport(resolution)
102
107
  ? `new URL(${JSON.stringify(resolution)}, document.baseURI)`
@@ -111,6 +116,7 @@ export function rewriteImportDeclarations(output, body, inputs, { resolveImport
111
116
  else if (declarations.length === 1) {
112
117
  output.insertLeft(0, `const ${specifiers[0]} = await ${imports[0]};\n`);
113
118
  }
119
+ return sources;
114
120
  }
115
121
  function renderImport(source, node, input) {
116
122
  const names = node.specifiers
@@ -53,7 +53,7 @@ function transpileObservableImport(input, cell, options) {
53
53
  const declarations = flatMapImportSpecifiers(cell.body, (s) => s.local);
54
54
  const outputs = Array.from(new Set(declarations.map(asDeclaration)));
55
55
  transformObservableImport(cell.body);
56
- rewriteImportDeclarations(output, cell.body, inputs, options);
56
+ const imports = rewriteImportDeclarations(output, cell.body, inputs, options);
57
57
  output.insertLeft(0, `async (__variable) => {\n`);
58
58
  if (outputs.length > 0)
59
59
  output.insertRight(input.length, `\nreturn {${outputs}};`);
@@ -66,7 +66,8 @@ function transpileObservableImport(input, cell, options) {
66
66
  autodisplay: false,
67
67
  files: new Set(),
68
68
  secrets: new Set(),
69
- databases: new Set()
69
+ databases: new Set(),
70
+ imports
70
71
  };
71
72
  }
72
73
  /** Mutates the given import declaration to be an Observable import. */
@@ -21,6 +21,8 @@ export type TranspiledJavaScript = {
21
21
  databases?: Set<string>;
22
22
  /** the names of any referenced secrets */
23
23
  secrets?: Set<string>;
24
+ /** the module specifiers of any (statically analyzable) imports */
25
+ imports?: Set<string>;
24
26
  };
25
27
  export interface TranspileOptions extends ImportOptions {
26
28
  /** If true, resolve file using import.meta.url (so Vite treats it as an asset). */
@@ -50,8 +50,8 @@ function transpileCell(cell, output, options) {
50
50
  async = true;
51
51
  const outputs = Array.from(new Set(cell.declarations?.map((r) => r.name)));
52
52
  output.trim();
53
- rewriteImportDeclarations(output, cell.body, inputs, options);
54
- rewriteImportExpressions(output, cell.body, options);
53
+ const importDeclarations = rewriteImportDeclarations(output, cell.body, inputs, options);
54
+ const importExpressions = rewriteImportExpressions(output, cell.body, options);
55
55
  if (options?.resolveFiles)
56
56
  rewriteFileExpressions(output, cell.body);
57
57
  if (cell.expression)
@@ -67,7 +67,8 @@ function transpileCell(cell, output, options) {
67
67
  const files = new Set(cell.files.map((f) => f.argument));
68
68
  const databases = new Set(cell.databases.map((f) => f.argument));
69
69
  const secrets = new Set(cell.secrets.map((f) => f.argument));
70
- return { body, inputs, outputs, autodisplay, files, databases, secrets };
70
+ const imports = new Set([...importDeclarations, ...importExpressions]);
71
+ return { body, inputs, outputs, autodisplay, files, databases, secrets, imports };
71
72
  }
72
73
  function deat(input) {
73
74
  return input.replace(/^@/, "__"); // @variable to __variable
@@ -128,11 +128,15 @@ h2,
128
128
  h3,
129
129
  h4,
130
130
  h5,
131
- h6,
132
- .katex-display {
131
+ h6 {
133
132
  max-width: 640px;
134
133
  }
135
134
 
135
+ .katex-display {
136
+ overflow-x: auto;
137
+ overflow-y: hidden;
138
+ }
139
+
136
140
  blockquote,
137
141
  ol,
138
142
  ul {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "2.6.4",
8
+ "version": "2.6.5",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "TZ=America/Los_Angeles vitest",