@observablehq/notebook-kit 1.5.0 → 1.5.2

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.
Files changed (56) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/runtime/index.d.ts +1 -1
  3. package/dist/src/runtime/stdlib/dot.js +1 -1
  4. package/dist/src/runtime/stdlib/duckdb.js +5 -5
  5. package/dist/src/runtime/stdlib/fileAttachment.d.ts +1 -1
  6. package/dist/src/runtime/stdlib/fileAttachment.js +4 -4
  7. package/dist/src/runtime/stdlib/generators/input.d.ts +1 -1
  8. package/dist/src/runtime/stdlib/generators/observe.d.ts +1 -1
  9. package/dist/src/runtime/stdlib/generators/observe.js +37 -13
  10. package/dist/src/runtime/stdlib/generators/queue.d.ts +1 -1
  11. package/dist/src/runtime/stdlib/generators/queue.js +36 -12
  12. package/dist/src/runtime/stdlib/generators/width.d.ts +1 -1
  13. package/dist/src/runtime/stdlib/index.d.ts +1 -1
  14. package/dist/src/runtime/stdlib/inputs.d.ts +1 -1
  15. package/dist/src/runtime/stdlib/inputs.js +1 -1
  16. package/dist/src/runtime/stdlib/leaflet.d.ts +1 -1
  17. package/dist/src/runtime/stdlib/leaflet.js +9 -3
  18. package/dist/src/runtime/stdlib/mapboxgl.d.ts +1 -1
  19. package/dist/src/runtime/stdlib/mapboxgl.js +1 -1
  20. package/dist/src/runtime/stdlib/mermaid.js +1 -1
  21. package/dist/src/runtime/stdlib/mutable.d.ts +2 -2
  22. package/dist/src/runtime/stdlib/recommendedLibraries.js +13 -13
  23. package/dist/src/runtime/stdlib/sampleDatasets.js +1 -1
  24. package/dist/src/runtime/stdlib/tex.js +1 -1
  25. package/dist/src/runtime/stdlib/vega-lite.js +3 -3
  26. package/package.json +1 -1
  27. package/dist/src/javascript/assignments.test.d.ts +0 -1
  28. package/dist/src/javascript/assignments.test.js +0 -46
  29. package/dist/src/javascript/awaits.test.d.ts +0 -1
  30. package/dist/src/javascript/awaits.test.js +0 -22
  31. package/dist/src/javascript/imports/npm.test.d.ts +0 -1
  32. package/dist/src/javascript/imports/npm.test.js +0 -32
  33. package/dist/src/javascript/imports/observable.test.d.ts +0 -1
  34. package/dist/src/javascript/imports/observable.test.js +0 -13
  35. package/dist/src/javascript/references.test.d.ts +0 -1
  36. package/dist/src/javascript/references.test.js +0 -38
  37. package/dist/src/javascript/sourcemap.test.d.ts +0 -1
  38. package/dist/src/javascript/sourcemap.test.js +0 -88
  39. package/dist/src/javascript/strings.test.d.ts +0 -1
  40. package/dist/src/javascript/strings.test.js +0 -31
  41. package/dist/src/javascript/template.test.d.ts +0 -1
  42. package/dist/src/javascript/template.test.js +0 -60
  43. package/dist/src/javascript/transpile.test.d.ts +0 -1
  44. package/dist/src/javascript/transpile.test.js +0 -52
  45. package/dist/src/javascript/typescript.test.d.ts +0 -1
  46. package/dist/src/javascript/typescript.test.js +0 -34
  47. package/dist/src/lib/hash.test.d.ts +0 -1
  48. package/dist/src/lib/hash.test.js +0 -28
  49. package/dist/src/lib/notebook.test.d.ts +0 -1
  50. package/dist/src/lib/notebook.test.js +0 -36
  51. package/dist/src/lib/serialize.test.d.ts +0 -1
  52. package/dist/src/lib/serialize.test.js +0 -132
  53. package/dist/src/lib/sluggify.test.d.ts +0 -1
  54. package/dist/src/lib/sluggify.test.js +0 -51
  55. package/dist/src/runtime/stdlib/assets.test.d.ts +0 -1
  56. package/dist/src/runtime/stdlib/assets.test.js +0 -78
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": "1.5.0",
8
+ "version": "1.5.2",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -57,7 +57,7 @@ export declare class NotebookRuntime {
57
57
  topojson: () => Promise<any>;
58
58
  vl: () => Promise<any>;
59
59
  now: () => AsyncGenerator<number, void, unknown>;
60
- width: () => AsyncGenerator<number, void, unknown>;
60
+ width: () => ObservableAsyncGenerator<number>;
61
61
  DatabaseClient: () => {
62
62
  (name: string, options?: import("./stdlib/databaseClient.js").QueryOptionsSpec): import("./stdlib/databaseClient.js").DatabaseClient;
63
63
  revive: ({ rows, schema, date, ...meta }: import("../databases/index.js").SerializableQueryResult) => import("./stdlib/databaseClient.js").QueryResult;
@@ -1,4 +1,4 @@
1
- import { instance } from "npm:@viz-js/viz";
1
+ import { instance } from "https://cdn.jsdelivr.net/npm/@viz-js/viz/+esm";
2
2
  const viz = await instance();
3
3
  export const dot = (template, ...values) => {
4
4
  const source = String.raw.call(String, template, ...values);
@@ -1,4 +1,4 @@
1
- import * as duckdb from "npm:@duckdb/duckdb-wasm";
1
+ import * as duckdb from "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm";
2
2
  // Adapted from https://observablehq.com/@cmudig/duckdb-client
3
3
  // Copyright 2021 CMU Data Interaction Group
4
4
  //
@@ -30,11 +30,11 @@ import * as duckdb from "npm:@duckdb/duckdb-wasm";
30
30
  const bundles = {
31
31
  mvp: {
32
32
  mainModule: "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-mvp.wasm",
33
- mainWorker: "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-mvp.worker.js"
33
+ mainWorker: "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-mvp.worker.js" // prettier-ignore
34
34
  },
35
35
  eh: {
36
36
  mainModule: "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-eh.wasm",
37
- mainWorker: "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-eh.worker.js"
37
+ mainWorker: "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-browser-eh.worker.js" // prettier-ignore
38
38
  }
39
39
  };
40
40
  const bundle = duckdb.selectBundle(bundles);
@@ -306,12 +306,12 @@ async function insertArrowTable(database, name, table, options) {
306
306
  async function insertArqueroTable(database, name, source) {
307
307
  // TODO When we have stdlib versioning and can upgrade Arquero to version 5,
308
308
  // we can then call source.toArrow() directly, with insertArrowTable()
309
- const arrow = await import("npm:apache-arrow");
309
+ const arrow = await import("https://cdn.jsdelivr.net/npm/apache-arrow@17.0.0/+esm");
310
310
  const table = arrow.tableFromIPC(source.toArrowBuffer());
311
311
  return await insertArrowTable(database, name, table);
312
312
  }
313
313
  async function insertArray(database, name, array, options) {
314
- const arrow = await import("npm:apache-arrow");
314
+ const arrow = await import("https://cdn.jsdelivr.net/npm/apache-arrow@17.0.0/+esm");
315
315
  const table = arrow.tableFromJSON(array);
316
316
  return await insertArrowTable(database, name, table, options);
317
317
  }
@@ -58,7 +58,7 @@ export interface FileInfo {
58
58
  lastModified?: number;
59
59
  size?: number;
60
60
  }
61
- export declare function registerFile(name: string, info: FileInfo, base?: string | URL): FileAttachmentImpl | undefined;
61
+ export declare function registerFile(name: string, info: FileInfo | null, base?: string | URL): FileAttachmentImpl | undefined;
62
62
  export declare abstract class AbstractFile implements FileAttachment {
63
63
  name: string;
64
64
  mimeType: string;
@@ -82,7 +82,7 @@ export class AbstractFile {
82
82
  return (await fetchFile(this)).body;
83
83
  }
84
84
  async dsv({ delimiter = ",", array = false, typed = false } = {}) {
85
- const [text, d3] = await Promise.all([this.text(), import("npm:d3-dsv")]);
85
+ const [text, d3] = await Promise.all([this.text(), import("https://cdn.jsdelivr.net/npm/d3-dsv/+esm")]); // prettier-ignore
86
86
  const format = d3.dsvFormat(delimiter);
87
87
  const parse = array ? format.parseRows : format.parse;
88
88
  return parse(text, typed && d3.autoType);
@@ -106,7 +106,7 @@ export class AbstractFile {
106
106
  });
107
107
  }
108
108
  async arrow() {
109
- const [Arrow, response] = await Promise.all([import("npm:apache-arrow"), fetchFile(this)]);
109
+ const [Arrow, response] = await Promise.all([import("https://cdn.jsdelivr.net/npm/apache-arrow@17.0.0/+esm"), fetchFile(this)]); // prettier-ignore
110
110
  return Arrow.tableFromIPC(response);
111
111
  }
112
112
  async arquero(options) {
@@ -140,11 +140,11 @@ export class AbstractFile {
140
140
  }
141
141
  break;
142
142
  }
143
- const [aq, body] = await Promise.all([import("npm:arquero"), request]);
143
+ const [aq, body] = await Promise.all([import("https://cdn.jsdelivr.net/npm/arquero/+esm"), request]); // prettier-ignore
144
144
  return aq[from](body, options);
145
145
  }
146
146
  async parquet() {
147
- const [Arrow, Parquet, buffer] = await Promise.all([import("npm:apache-arrow"), import("npm:parquet-wasm").then(async (Parquet) => (await Parquet.default("https://cdn.jsdelivr.net/npm/parquet-wasm/esm/parquet_wasm_bg.wasm"), Parquet)), this.arrayBuffer()]); // prettier-ignore
147
+ const [Arrow, Parquet, buffer] = await Promise.all([import("https://cdn.jsdelivr.net/npm/apache-arrow@17.0.0/+esm"), import("https://cdn.jsdelivr.net/npm/parquet-wasm/+esm").then(async (Parquet) => (await Parquet.default("https://cdn.jsdelivr.net/npm/parquet-wasm/esm/parquet_wasm_bg.wasm"), Parquet)), this.arrayBuffer()]); // prettier-ignore
148
148
  return Arrow.tableFromIPC(Parquet.readParquet(new Uint8Array(buffer)).intoIPCStream());
149
149
  }
150
150
  async xml(mimeType = "application/xml") {
@@ -1 +1 @@
1
- export declare function input(element: Element): AsyncGenerator<string | number | boolean | string[] | Date | FileList | File | null, void, unknown>;
1
+ export declare function input(element: Element): ObservableAsyncGenerator<string | number | boolean | string[] | Date | FileList | File | null>;
@@ -1 +1 @@
1
- export declare function observe<T>(initialize: (change: (value: T) => void) => unknown): AsyncGenerator<Awaited<T>, void, unknown>;
1
+ export declare function observe<T>(initialize: (change: (value: T) => void) => (() => void) | void | null | undefined): ObservableAsyncGenerator<Awaited<T>>;
@@ -1,12 +1,13 @@
1
- export async function* observe(initialize) {
1
+ export function observe(initialize) {
2
2
  let resolve;
3
+ let reject;
3
4
  let value;
4
5
  let stale = false;
5
6
  const dispose = initialize((x) => {
6
7
  value = x;
7
- if (resolve) {
8
+ if (resolve != null) {
8
9
  resolve(x);
9
- resolve = undefined;
10
+ resolve = reject = undefined;
10
11
  }
11
12
  else {
12
13
  stale = true;
@@ -14,18 +15,41 @@ export async function* observe(initialize) {
14
15
  return x;
15
16
  });
16
17
  if (dispose != null && typeof dispose !== "function") {
17
- throw new Error(typeof dispose === "object" && "then" in dispose && typeof dispose.then === "function"
18
+ throw new Error(typeof dispose === "object" && typeof dispose["then"] === "function"
18
19
  ? "async initializers are not supported"
19
20
  : "initializer returned something, but not a dispose function");
20
21
  }
21
- try {
22
- while (true) {
23
- yield stale ? ((stale = false), value) : new Promise((_) => (resolve = _));
22
+ return {
23
+ async next() {
24
+ return {
25
+ done: false,
26
+ value: await (stale
27
+ ? ((stale = false), value)
28
+ : new Promise((res, rej) => ((resolve = res), (reject = rej))))
29
+ };
30
+ },
31
+ async return() {
32
+ if (reject != null) {
33
+ reject(new Error("Generator returned"));
34
+ resolve = reject = undefined;
35
+ }
36
+ if (dispose != null) {
37
+ dispose();
38
+ }
39
+ return { done: true, value: undefined };
40
+ },
41
+ async throw(e) {
42
+ if (reject != null) {
43
+ reject(e);
44
+ resolve = reject = undefined;
45
+ }
46
+ if (dispose != null) {
47
+ dispose();
48
+ }
49
+ return { done: true, value: undefined };
50
+ },
51
+ [Symbol.asyncIterator]() {
52
+ return this;
24
53
  }
25
- }
26
- finally {
27
- if (dispose != null) {
28
- dispose();
29
- }
30
- }
54
+ };
31
55
  }
@@ -1 +1 @@
1
- export declare function queue<T>(initialize: (change: (value: T) => void) => unknown): AsyncGenerator<Awaited<T>, void, unknown>;
1
+ export declare function queue<T>(initialize: (change: (value: T) => void) => (() => void) | void | null | undefined): ObservableAsyncGenerator<Awaited<T>>;
@@ -1,27 +1,51 @@
1
- export async function* queue(initialize) {
1
+ export function queue(initialize) {
2
2
  let resolve;
3
+ let reject;
3
4
  const values = [];
4
5
  const dispose = initialize((x) => {
5
6
  values.push(x);
6
- if (resolve) {
7
+ if (resolve != null) {
7
8
  resolve(values.shift());
8
9
  resolve = undefined;
9
10
  }
10
11
  return x;
11
12
  });
12
13
  if (dispose != null && typeof dispose !== "function") {
13
- throw new Error(typeof dispose === "object" && "then" in dispose && typeof dispose.then === "function"
14
+ throw new Error(typeof dispose === "object" && typeof dispose["then"] === "function"
14
15
  ? "async initializers are not supported"
15
16
  : "initializer returned something, but not a dispose function");
16
17
  }
17
- try {
18
- while (true) {
19
- yield values.length ? values.shift() : new Promise((_) => (resolve = _));
18
+ return {
19
+ async next() {
20
+ return {
21
+ done: false,
22
+ value: await (values.length
23
+ ? values.shift()
24
+ : new Promise((res, rej) => ((resolve = res), (reject = rej))))
25
+ };
26
+ },
27
+ async return() {
28
+ if (reject != null) {
29
+ reject(new Error("Generator returned"));
30
+ resolve = reject = undefined;
31
+ }
32
+ if (dispose != null) {
33
+ dispose();
34
+ }
35
+ return { done: true, value: undefined };
36
+ },
37
+ async throw(e) {
38
+ if (reject != null) {
39
+ reject(e);
40
+ resolve = reject = undefined;
41
+ }
42
+ if (dispose != null) {
43
+ dispose();
44
+ }
45
+ return { done: true, value: undefined };
46
+ },
47
+ [Symbol.asyncIterator]() {
48
+ return this;
20
49
  }
21
- }
22
- finally {
23
- if (dispose != null) {
24
- dispose();
25
- }
26
- }
50
+ };
27
51
  }
@@ -1 +1 @@
1
- export declare function width(target: Element, options?: ResizeObserverOptions): AsyncGenerator<number, void, unknown>;
1
+ export declare function width(target: Element, options?: ResizeObserverOptions): ObservableAsyncGenerator<number>;
@@ -46,7 +46,7 @@ export declare const library: {
46
46
  topojson: () => Promise<any>;
47
47
  vl: () => Promise<any>;
48
48
  now: () => AsyncGenerator<number, void, unknown>;
49
- width: () => AsyncGenerator<number, void, unknown>;
49
+ width: () => ObservableAsyncGenerator<number>;
50
50
  DatabaseClient: () => {
51
51
  (name: string, options?: import("./databaseClient.js").QueryOptionsSpec): DatabaseClient;
52
52
  revive: ({ rows, schema, date, ...meta }: import("../../databases/index.js").SerializableQueryResult) => import("./databaseClient.js").QueryResult;
@@ -1,2 +1,2 @@
1
- export * from "npm:@observablehq/inputs";
1
+ export * from "https://cdn.jsdelivr.net/npm/@observablehq/inputs/+esm";
2
2
  import "./inputs.css";
@@ -1,2 +1,2 @@
1
- export * from "npm:@observablehq/inputs";
1
+ export * from "https://cdn.jsdelivr.net/npm/@observablehq/inputs/+esm";
2
2
  import "./inputs.css";
@@ -1 +1 @@
1
- export * from "npm:leaflet";
1
+ export * from "https://cdn.jsdelivr.net/npm/leaflet/+esm";
@@ -1,7 +1,13 @@
1
- import { Icon } from "npm:leaflet";
2
- export * from "npm:leaflet";
1
+ import { Icon } from "https://cdn.jsdelivr.net/npm/leaflet/+esm";
2
+ export * from "https://cdn.jsdelivr.net/npm/leaflet/+esm";
3
3
  Icon.Default.imagePath = "https://cdn.jsdelivr.net/npm/leaflet/dist/images/";
4
4
  const link = document.createElement("link");
5
- link.href = "https://cdn.jsdelivr.net/npm/leaflet/dist/leaflet.css";
6
5
  link.rel = "stylesheet";
6
+ link.type = "text/css";
7
+ link.href = "https://cdn.jsdelivr.net/npm/leaflet/dist/leaflet.css";
8
+ const loaded = new Promise((resolve, reject) => {
9
+ link.onload = resolve;
10
+ link.onerror = reject;
11
+ });
7
12
  document.head.appendChild(link);
13
+ await loaded;
@@ -1 +1 @@
1
- export { default } from "npm:mapbox-gl";
1
+ export { default } from "https://cdn.jsdelivr.net/npm/mapbox-gl/+esm";
@@ -1,4 +1,4 @@
1
- export { default } from "npm:mapbox-gl";
1
+ export { default } from "https://cdn.jsdelivr.net/npm/mapbox-gl/+esm";
2
2
  const link = document.createElement("link");
3
3
  link.href = "https://cdn.jsdelivr.net/npm/mapbox-gl/dist/mapbox-gl.css";
4
4
  link.rel = "stylesheet";
@@ -1,4 +1,4 @@
1
- import mer from "npm:mermaid";
1
+ import mer from "https://cdn.jsdelivr.net/npm/mermaid/+esm";
2
2
  let nextId = 0;
3
3
  const scheme = getComputedStyle(document.body).getPropertyValue("color-scheme");
4
4
  const theme = scheme === "dark" ? "dark" : "neutral";
@@ -1,7 +1,7 @@
1
- export declare function Mutable<T>(value: T): AsyncGenerator<Awaited<T>, void, unknown> & {
1
+ export declare function Mutable<T>(value: T): ObservableAsyncGenerator<Awaited<T>> & {
2
2
  value: T;
3
3
  };
4
- export declare function Mutator<T>(value: T): ((AsyncGenerator<Awaited<T>, void, unknown> & {
4
+ export declare function Mutator<T>(value: T): ((ObservableAsyncGenerator<Awaited<T>> & {
5
5
  value: T;
6
6
  }) | {
7
7
  value: T;
@@ -1,26 +1,26 @@
1
- export const _ = () => import("npm:lodash").then((_) => _.default);
2
- export const aq = () => import("npm:arquero");
3
- export const Arrow = () => import("npm:apache-arrow");
4
- export const d3 = () => import("npm:d3");
1
+ export const _ = () => import("https://cdn.jsdelivr.net/npm/lodash/+esm").then((_) => _.default);
2
+ export const aq = () => import("https://cdn.jsdelivr.net/npm/arquero/+esm");
3
+ export const Arrow = () => import("https://cdn.jsdelivr.net/npm/apache-arrow@17.0.0/+esm");
4
+ export const d3 = () => import("https://cdn.jsdelivr.net/npm/d3/+esm");
5
5
  export const dot = () => import("./dot.js").then((_) => _.dot);
6
- export const duckdb = () => import("npm:@duckdb/duckdb-wasm");
6
+ export const duckdb = () => import("https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm");
7
7
  export const DuckDBClient = () => import("./duckdb.js").then((_) => _.DuckDBClient);
8
- export const echarts = () => import("npm:echarts");
9
- export const htl = () => import("npm:htl");
10
- export const html = () => import("npm:htl").then((_) => _.html);
11
- export const svg = () => import("npm:htl").then((_) => _.svg);
8
+ export const echarts = () => import("https://cdn.jsdelivr.net/npm/echarts/+esm");
9
+ export const htl = () => import("https://cdn.jsdelivr.net/npm/htl/+esm");
10
+ export const html = () => import("https://cdn.jsdelivr.net/npm/htl/+esm").then((_) => _.html);
11
+ export const svg = () => import("https://cdn.jsdelivr.net/npm/htl/+esm").then((_) => _.svg);
12
12
  export const Inputs = () => import("./inputs.js");
13
13
  export const L = () => import("./leaflet.js");
14
14
  export const mapboxgl = () => import("./mapboxgl.js").then((_) => _.default);
15
15
  export const md = () => import("./md.js").then((_) => _.md);
16
16
  export const mermaid = () => import("./mermaid.js").then((_) => _.mermaid);
17
- export const Plot = () => import("npm:@observablehq/plot");
18
- export const React = () => import("npm:react");
19
- export const ReactDOM = () => import("npm:react-dom");
17
+ export const Plot = () => import("https://cdn.jsdelivr.net/npm/@observablehq/plot/+esm");
18
+ export const React = () => import("https://cdn.jsdelivr.net/npm/react/+esm");
19
+ export const ReactDOM = () => import("https://cdn.jsdelivr.net/npm/react-dom/+esm");
20
20
  // export const sql = () => import("observablehq:stdlib/duckdb").then((_) => _.sql);
21
21
  // export const SQLite = () => import("observablehq:stdlib/sqlite").then((_) => _.default);
22
22
  // export const SQLiteDatabaseClient = () => import("observablehq:stdlib/sqlite").then((_) => _.SQLiteDatabaseClient);
23
23
  export const tex = () => import("./tex.js").then((_) => _.tex);
24
- export const topojson = () => import("npm:topojson-client");
24
+ export const topojson = () => import("https://cdn.jsdelivr.net/npm/topojson-client/+esm");
25
25
  // export const vg = () => import("observablehq:stdlib/vgplot").then((_) => _.default());
26
26
  export const vl = () => import("./vega-lite.js").then((_) => _.vl);
@@ -26,6 +26,6 @@ async function text(url) {
26
26
  return response.text();
27
27
  }
28
28
  async function csv(url, typed) {
29
- const [contents, d3] = await Promise.all([text(url), import("npm:d3-dsv")]);
29
+ const [contents, d3] = await Promise.all([text(url), import("https://cdn.jsdelivr.net/npm/d3-dsv/+esm")]); // prettier-ignore
30
30
  return d3.csvParse(contents, typed && d3.autoType);
31
31
  }
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import katex from "npm:katex";
2
+ import katex from "https://cdn.jsdelivr.net/npm/katex/+esm";
3
3
  const link = document.createElement("link");
4
4
  link.href = "https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css";
5
5
  link.rel = "stylesheet";
@@ -1,4 +1,4 @@
1
- import * as vega from "npm:vega";
2
- import * as vegaLite from "npm:vega-lite";
3
- import * as vegaLiteApi from "npm:vega-lite-api";
1
+ import * as vega from "https://cdn.jsdelivr.net/npm/vega/+esm";
2
+ import * as vegaLite from "https://cdn.jsdelivr.net/npm/vega-lite/+esm";
3
+ import * as vegaLiteApi from "https://cdn.jsdelivr.net/npm/vega-lite-api/+esm";
4
4
  export const vl = vegaLiteApi.register(vega, vegaLite);
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": "1.5.0",
8
+ "version": "1.5.2",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -1 +0,0 @@
1
- export {};
@@ -1,46 +0,0 @@
1
- import { assert, test } from "vitest";
2
- import { parseJavaScript } from "./parse.js";
3
- import { findReferences } from "./references.js";
4
- function check(input) {
5
- const cell = parseJavaScript(input);
6
- findReferences(cell.body, { input });
7
- }
8
- test("allows non-external assignments", () => {
9
- assert.doesNotThrow(() => check("let foo = 1;\nfoo = 2;"));
10
- assert.doesNotThrow(() => check("let foo = 1;\nfor (foo of []);"));
11
- });
12
- test("allows external references", () => {
13
- assert.doesNotThrow(() => check("foo + 1;"));
14
- });
15
- test("does not allow external assignments", () => {
16
- assert.throws(() => check("foo = 1;"), /external variable 'foo'/);
17
- assert.throws(() => check("foo++;"), /external variable 'foo'/);
18
- assert.throws(() => check("++foo;"), /external variable 'foo'/);
19
- assert.throws(() => check("({foo} = {});"), /external variable 'foo'/);
20
- assert.throws(() => check("({foo: bar} = {});"), /external variable 'bar'/);
21
- assert.throws(() => check("([foo] = []);"), /external variable 'foo'/);
22
- assert.throws(() => check("let foo = 1;\n({...bar} = {});"), /external variable 'bar'/);
23
- assert.throws(() => check("let foo = 1;\n([...bar] = []);"), /external variable 'bar'/);
24
- assert.throws(() => check("let foo = 1;\nbar = 1;"), /external variable 'bar'/);
25
- assert.throws(() => check("function f() { foo = 1; }"), /external variable 'foo'/);
26
- });
27
- test("does not allow external assignments via for…of or for…in", () => {
28
- assert.throws(() => check("for (foo of []);"), /external variable 'foo'/);
29
- assert.throws(() => check("for (foo in {});"), /external variable 'foo'/);
30
- });
31
- test("does not allow global assignments", () => {
32
- assert.throws(() => check("window = 1;"), /Assignment to global 'window'/);
33
- assert.throws(() => check("const foo = (window = 1);"), /Assignment to global 'window'/);
34
- });
35
- test("does not allow conflicting top-level variables", () => {
36
- assert.throws(() => check("const window = 1;"), /Global 'window' cannot be redefined/);
37
- assert.throws(() => check("const foo = 1, window = 2;"), /Global 'window' cannot be redefined/);
38
- assert.throws(() => check("const {window} = {};"), /Global 'window' cannot be redefined/);
39
- assert.throws(() => check("const {window = 1} = {};"), /Global 'window' cannot be redefined/);
40
- });
41
- test("allows conflicting non-top-level variables", () => {
42
- assert.doesNotThrow(() => check("{ const window = 1; }"));
43
- assert.doesNotThrow(() => check("{ let window; window = 2; }"));
44
- assert.doesNotThrow(() => check("{ const {window} = {}; }"));
45
- assert.doesNotThrow(() => check("{ const {window = 1} = {}; }"));
46
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- import { assert, expect, test } from "vitest";
2
- import { findAwaits } from "./awaits.js";
3
- import { parseJavaScript } from "./parse.js";
4
- function find(input) {
5
- return findAwaits(parseJavaScript(input).body);
6
- }
7
- test("finds top-level awaits", () => {
8
- expect(find("await 1;")).toMatchSnapshot();
9
- expect(find("(1, await 2);")).toMatchSnapshot();
10
- expect(find("1 + await 2;")).toMatchSnapshot();
11
- expect(find("if (true) { await 3; }")).toMatchSnapshot();
12
- expect(find("for await (const f of []);")).toMatchSnapshot();
13
- expect(find("for (const f of await []);")).toMatchSnapshot();
14
- expect(find("let f, g; for ({[await f]: g} of await []);")).toMatchSnapshot();
15
- expect(find("for (const f of []) await f;")).toMatchSnapshot();
16
- expect(find("for (const f in await {});")).toMatchSnapshot();
17
- });
18
- test("ignores awaits within functions", () => {
19
- assert.deepStrictEqual(find("async function f() { await 1; }"), []);
20
- assert.deepStrictEqual(find("let f = (async function () { await 1; });"), []);
21
- assert.deepStrictEqual(find("let f = (async () => { await 1; });"), []);
22
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,32 +0,0 @@
1
- import { assert, test } from "vitest";
2
- import { resolveNpmImport } from "./npm.js";
3
- test("adds /+esm as expected", () => {
4
- assert.strictEqual(resolveNpmImport("npm:prettier"), "https://cdn.jsdelivr.net/npm/prettier/+esm" // defaults to /+esm
5
- );
6
- assert.strictEqual(resolveNpmImport("npm:prettier/"), "https://cdn.jsdelivr.net/npm/prettier/" // no /+esm because trailing slash
7
- );
8
- assert.strictEqual(resolveNpmImport("npm:prettier/+esm"), "https://cdn.jsdelivr.net/npm/prettier/+esm" // preserve existing /+esm
9
- );
10
- assert.strictEqual(resolveNpmImport("npm:prettier/plugins/acorn"), "https://cdn.jsdelivr.net/npm/prettier/plugins/acorn/+esm");
11
- assert.strictEqual(resolveNpmImport("npm:prettier/plugins/acorn/+esm"), "https://cdn.jsdelivr.net/npm/prettier/plugins/acorn/+esm" // preserve existing /+esm
12
- );
13
- assert.strictEqual(resolveNpmImport("npm:prettier/plugins/acorn/"), "https://cdn.jsdelivr.net/npm/prettier/plugins/acorn/" // no /+esm because trailing slash
14
- );
15
- assert.strictEqual(resolveNpmImport("npm:prettier/plugins/acorn.js"), "https://cdn.jsdelivr.net/npm/prettier/plugins/acorn.js" // no /+esm because file extension
16
- );
17
- assert.strictEqual(resolveNpmImport("npm:prettier/plugins/acorn.js/+esm"), "https://cdn.jsdelivr.net/npm/prettier/plugins/acorn.js/+esm" // preserve existing /+esm
18
- );
19
- assert.strictEqual(resolveNpmImport("npm:prettier/plugins/estree"), "https://cdn.jsdelivr.net/npm/prettier/plugins/estree/+esm");
20
- });
21
- test("sets the default version of @duckdb/duckdb-wasm", () => {
22
- assert.strictEqual(resolveNpmImport("npm:@duckdb/duckdb-wasm"), "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm");
23
- assert.strictEqual(resolveNpmImport("npm:@duckdb/duckdb-wasm/+esm"), "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm");
24
- assert.strictEqual(resolveNpmImport("npm:@duckdb/duckdb-wasm/dist/duckdb-mvp.wasm"), "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-mvp.wasm");
25
- });
26
- test("sets the default path for various libraries", () => {
27
- assert.strictEqual(resolveNpmImport("npm:mermaid"), "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs/+esm");
28
- assert.strictEqual(resolveNpmImport("npm:echarts"), "https://cdn.jsdelivr.net/npm/echarts/dist/echarts.esm.min.js/+esm");
29
- assert.strictEqual(resolveNpmImport("npm:jquery-ui"), "https://cdn.jsdelivr.net/npm/jquery-ui/dist/jquery-ui.js/+esm");
30
- assert.strictEqual(resolveNpmImport("npm:deck.gl"), "https://cdn.jsdelivr.net/npm/deck.gl/dist.min.js/+esm");
31
- assert.strictEqual(resolveNpmImport("npm:react-dom"), "https://cdn.jsdelivr.net/npm/react-dom/client/+esm");
32
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { assert, test } from "vitest";
2
- import { dedollar } from "./observable.js";
3
- test("unescapes dollar signs in imported symbols", () => {
4
- assert.strictEqual(dedollar("viewof$foo"), "viewof foo");
5
- assert.strictEqual(dedollar("viewof$"), "viewof ");
6
- assert.strictEqual(dedollar("$viewof"), " viewof");
7
- assert.strictEqual(dedollar("viewof$$foo"), "viewof$foo");
8
- assert.strictEqual(dedollar("viewof$$$foo"), "viewof$$foo");
9
- assert.strictEqual(dedollar("$"), " ");
10
- assert.strictEqual(dedollar("$$"), "$");
11
- assert.strictEqual(dedollar("$$$"), "$$");
12
- assert.strictEqual(dedollar("$$_"), "$_");
13
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,38 +0,0 @@
1
- import { expect, test } from "vitest";
2
- import { parseJavaScript } from "./parse.js";
3
- function find(input) {
4
- return parseJavaScript(input).references;
5
- }
6
- test("finds references in expressions", () => {
7
- expect(find(`foo + bar`)).toMatchSnapshot();
8
- });
9
- test("finds references in statements", () => {
10
- expect(find(`foo + bar;`)).toMatchSnapshot();
11
- });
12
- test("finds multiple references", () => {
13
- expect(find(`const a = b + c;\nconst d = c - b;`)).toMatchSnapshot();
14
- });
15
- test("doesn’t consider the identifier a reference", () => {
16
- expect(find(`function foo() { return bar; }`)).toMatchSnapshot();
17
- });
18
- test("local variables can mask references", () => {
19
- expect(find(`{ let foo; foo + bar; }`)).toMatchSnapshot();
20
- });
21
- test("local variables can not mask references", () => {
22
- expect(find(`{ foo + bar; { let foo; } }`)).toMatchSnapshot();
23
- });
24
- test("function parameters can mask references", () => {
25
- expect(find(`foo => foo + bar`)).toMatchSnapshot();
26
- });
27
- test("function rest parameters can mask references", () => {
28
- expect(find(`(...foo) => foo + bar`)).toMatchSnapshot();
29
- });
30
- test("destructured variables can mask references", () => {
31
- expect(find(`{ let {foo} = null; foo + bar; }`)).toMatchSnapshot();
32
- });
33
- test("destructured rest variables can mask references", () => {
34
- expect(find(`{ let {...foo} = null; foo + bar; }`)).toMatchSnapshot();
35
- });
36
- test("ignores globals", () => {
37
- expect(find(`window + bar`)).toMatchSnapshot();
38
- });
@@ -1 +0,0 @@
1
- export {};