@observablehq/notebook-kit 1.9.2 → 2.1.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 +1 -1
- package/dist/src/runtime/define.js +1 -1
- package/dist/src/runtime/display.d.ts +2 -2
- package/dist/src/runtime/display.js +7 -7
- package/dist/src/runtime/inspect.d.ts +2 -2
- package/dist/src/runtime/inspect.js +4 -4
- package/dist/src/runtime/stdlib/index.d.ts +0 -9
- package/dist/src/runtime/stdlib/index.js +0 -2
- package/package.json +1 -1
- package/dist/src/runtime/stdlib/require.d.ts +0 -11
- package/dist/src/runtime/stdlib/require.js +0 -73
package/dist/package.json
CHANGED
|
@@ -7,9 +7,9 @@ export type DisplayState = {
|
|
|
7
7
|
/** for inspected values, any expanded paths; see getExpanded */
|
|
8
8
|
expanded: (number[][] | undefined)[];
|
|
9
9
|
};
|
|
10
|
-
export declare function display(state: DisplayState, value: unknown): void;
|
|
10
|
+
export declare function display(state: DisplayState, value: unknown, name?: string): void;
|
|
11
11
|
export declare function clear(state: DisplayState): void;
|
|
12
|
-
export declare function observe(state: DisplayState, { autodisplay, assets }: Definition): {
|
|
12
|
+
export declare function observe(state: DisplayState, { autodisplay, assets, output }: Definition): {
|
|
13
13
|
_error: boolean;
|
|
14
14
|
_node: HTMLDivElement;
|
|
15
15
|
pending(): void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { inspect, inspectError, getExpanded } from "./inspect.js";
|
|
2
2
|
import { mapAssets } from "./stdlib/assets.js";
|
|
3
|
-
export function display(state, value) {
|
|
3
|
+
export function display(state, value, name) {
|
|
4
4
|
const { root, expanded } = state;
|
|
5
|
-
const node = isDisplayable(value, root) ? value : inspect(value, expanded[root.childNodes.length]); // prettier-ignore
|
|
5
|
+
const node = isDisplayable(value, root) ? value : inspect(value, expanded[root.childNodes.length], name); // prettier-ignore
|
|
6
6
|
displayNode(state, node);
|
|
7
7
|
}
|
|
8
8
|
function displayNode(state, node) {
|
|
@@ -16,8 +16,8 @@ function displayNode(state, node) {
|
|
|
16
16
|
state.root.appendChild(node);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
function displayError(state, value) {
|
|
20
|
-
displayNode(state, inspectError(value));
|
|
19
|
+
function displayError(state, value, name) {
|
|
20
|
+
displayNode(state, inspectError(value, name));
|
|
21
21
|
}
|
|
22
22
|
// Note: Element.prototype is instanceof Node, but cannot be inserted! This
|
|
23
23
|
// excludes DocumentFragment since appending a fragment “dissolves” (mutates)
|
|
@@ -33,7 +33,7 @@ export function clear(state) {
|
|
|
33
33
|
while (state.root.lastChild)
|
|
34
34
|
state.root.lastChild.remove();
|
|
35
35
|
}
|
|
36
|
-
export function observe(state, { autodisplay, assets }) {
|
|
36
|
+
export function observe(state, { autodisplay, assets, output }) {
|
|
37
37
|
return {
|
|
38
38
|
_error: false,
|
|
39
39
|
_node: state.root, // _node for visibility promise
|
|
@@ -48,7 +48,7 @@ export function observe(state, { autodisplay, assets }) {
|
|
|
48
48
|
if (assets && value instanceof Element)
|
|
49
49
|
mapAssets(value, assets);
|
|
50
50
|
clear(state);
|
|
51
|
-
display(state, value);
|
|
51
|
+
display(state, value, output);
|
|
52
52
|
}
|
|
53
53
|
else if (state.autoclear) {
|
|
54
54
|
clear(state);
|
|
@@ -58,7 +58,7 @@ export function observe(state, { autodisplay, assets }) {
|
|
|
58
58
|
console.error(error);
|
|
59
59
|
this._error = true;
|
|
60
60
|
clear(state);
|
|
61
|
-
displayError(state, error);
|
|
61
|
+
displayError(state, error, output);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function inspect(value: unknown, expanded?: number[][]): HTMLDivElement;
|
|
2
|
-
export declare function inspectError(value: unknown): HTMLDivElement;
|
|
1
|
+
export declare function inspect(value: unknown, expanded?: number[][], name?: string): HTMLDivElement;
|
|
2
|
+
export declare function inspectError(value: unknown, name?: string): HTMLDivElement;
|
|
3
3
|
export declare function getExpanded(node: Node): number[][] | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Inspector } from "@observablehq/inspector";
|
|
2
|
-
export function inspect(value, expanded) {
|
|
2
|
+
export function inspect(value, expanded, name) {
|
|
3
3
|
const node = document.createElement("div");
|
|
4
|
-
new Inspector(node).fulfilled(value);
|
|
4
|
+
new Inspector(node).fulfilled(value, name);
|
|
5
5
|
if (expanded) {
|
|
6
6
|
for (const path of expanded) {
|
|
7
7
|
let child = node;
|
|
@@ -12,9 +12,9 @@ export function inspect(value, expanded) {
|
|
|
12
12
|
}
|
|
13
13
|
return node;
|
|
14
14
|
}
|
|
15
|
-
export function inspectError(value) {
|
|
15
|
+
export function inspectError(value, name) {
|
|
16
16
|
const node = document.createElement("div");
|
|
17
|
-
new Inspector(node).rejected(value);
|
|
17
|
+
new Inspector(node).rejected(value, name);
|
|
18
18
|
return node;
|
|
19
19
|
}
|
|
20
20
|
export function getExpanded(node) {
|
|
@@ -104,14 +104,5 @@ export declare const library: {
|
|
|
104
104
|
Promises: () => typeof Promises;
|
|
105
105
|
Files: () => typeof Files;
|
|
106
106
|
DOM: () => typeof DOM;
|
|
107
|
-
require: () => {
|
|
108
|
-
(...specifiers: unknown[]): Promise<unknown>;
|
|
109
|
-
resolve: (specifier: unknown) => string;
|
|
110
|
-
} & {
|
|
111
|
-
alias: (aliases: Record<string, string>) => {
|
|
112
|
-
(...specifiers: unknown[]): Promise<unknown>;
|
|
113
|
-
resolve: (specifier: unknown) => string;
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
107
|
__ojs_observer: () => () => Observer;
|
|
117
108
|
};
|
|
@@ -8,7 +8,6 @@ import { Mutable } from "./mutable.js";
|
|
|
8
8
|
import { Observer } from "./observer.js";
|
|
9
9
|
import * as Promises from "./promises/index.js";
|
|
10
10
|
import * as recommendedLibraries from "./recommendedLibraries.js";
|
|
11
|
-
import { require } from "./require.js";
|
|
12
11
|
import * as sampleDatasets from "./sampleDatasets.js";
|
|
13
12
|
export const root = document.querySelector("main") ?? document.body;
|
|
14
13
|
export const library = {
|
|
@@ -23,7 +22,6 @@ export const library = {
|
|
|
23
22
|
Promises: () => Promises, // deprecated!
|
|
24
23
|
Files: () => Files, // deprecated!
|
|
25
24
|
DOM: () => DOM, // deprecated!
|
|
26
|
-
require: () => require, // deprecated!
|
|
27
25
|
__ojs_observer: () => () => new Observer(),
|
|
28
26
|
...recommendedLibraries,
|
|
29
27
|
...sampleDatasets
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const require: {
|
|
2
|
-
(...specifiers: unknown[]): Promise<unknown>;
|
|
3
|
-
resolve: (specifier: unknown) => string;
|
|
4
|
-
} & {
|
|
5
|
-
alias: typeof alias;
|
|
6
|
-
};
|
|
7
|
-
declare function alias(aliases: Record<string, string>): {
|
|
8
|
-
(...specifiers: unknown[]): Promise<unknown>;
|
|
9
|
-
resolve: (specifier: unknown) => string;
|
|
10
|
-
};
|
|
11
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const cache = new WeakMap();
|
|
2
|
-
export const require = Object.assign(Requirer(resolve), { alias });
|
|
3
|
-
function Requirer(resolve) {
|
|
4
|
-
async function require(...specifiers) {
|
|
5
|
-
return specifiers.length === 1
|
|
6
|
-
? import(/* @vite-ignore */ resolve(specifiers[0])).then(objectify)
|
|
7
|
-
: Promise.all(specifiers.map((s) => require(s))).then(merge);
|
|
8
|
-
}
|
|
9
|
-
require.resolve = resolve;
|
|
10
|
-
return require;
|
|
11
|
-
}
|
|
12
|
-
function parseNpmSpecifier(specifier) {
|
|
13
|
-
const parts = specifier.split("/");
|
|
14
|
-
const namerange = specifier.startsWith("@")
|
|
15
|
-
? [parts.shift(), parts.shift()].join("/")
|
|
16
|
-
: parts.shift();
|
|
17
|
-
const ranged = namerange.indexOf("@", 1);
|
|
18
|
-
const name = ranged > 0 ? namerange.slice(0, ranged) : namerange;
|
|
19
|
-
const range = ranged > 0 ? namerange.slice(ranged) : "";
|
|
20
|
-
const path = parts.length > 0 ? `/${parts.join("/")}` : "";
|
|
21
|
-
return { name, range, path };
|
|
22
|
-
}
|
|
23
|
-
function alias(aliases) {
|
|
24
|
-
return Requirer((specifier) => {
|
|
25
|
-
if (specifier in aliases)
|
|
26
|
-
specifier = aliases[specifier];
|
|
27
|
-
return resolve(specifier);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function resolve(_specifier) {
|
|
31
|
-
const specifier = String(_specifier);
|
|
32
|
-
if (isProtocol(specifier) || isLocal(specifier))
|
|
33
|
-
return specifier;
|
|
34
|
-
const { name, range, path } = parseNpmSpecifier(specifier);
|
|
35
|
-
return `https://cdn.jsdelivr.net/npm/${name}${range}${path + ((isFile(path) && !isJavaScript(path)) || isDirectory(path) ? "" : "/+esm")}`;
|
|
36
|
-
}
|
|
37
|
-
/** Promote exclusive default export to module. */
|
|
38
|
-
function defaultify(module) {
|
|
39
|
-
for (const key in module)
|
|
40
|
-
if (key !== "default")
|
|
41
|
-
return { ...module }; // any named export
|
|
42
|
-
return "default" in module ? module.default : { ...module }; // promote exclusive default export
|
|
43
|
-
}
|
|
44
|
-
/** Allow mutation of required modules while maintaining a canonical instance; ugly! */
|
|
45
|
-
function objectify(module) {
|
|
46
|
-
let object = cache.get(module);
|
|
47
|
-
if (!object)
|
|
48
|
-
cache.set(module, (object = defaultify(module)));
|
|
49
|
-
return object;
|
|
50
|
-
}
|
|
51
|
-
function merge(modules) {
|
|
52
|
-
return Object.assign({}, ...modules);
|
|
53
|
-
}
|
|
54
|
-
/** Returns true for e.g. https://example.com/ */
|
|
55
|
-
function isProtocol(specifier) {
|
|
56
|
-
return /^\w+:/.test(specifier);
|
|
57
|
-
}
|
|
58
|
-
/** Returns true for e.g. ./foo.js */
|
|
59
|
-
function isLocal(specifier) {
|
|
60
|
-
return /^(\.\/|\.\.\/|\/)/.test(specifier);
|
|
61
|
-
}
|
|
62
|
-
/** Returns true for e.g. foo/bar.js */
|
|
63
|
-
function isJavaScript(specifier) {
|
|
64
|
-
return /\.js$/i.test(specifier);
|
|
65
|
-
}
|
|
66
|
-
/** Returns true for e.g. foo/bar.txt */
|
|
67
|
-
function isFile(specifier) {
|
|
68
|
-
return /\.\w*$/.test(specifier);
|
|
69
|
-
}
|
|
70
|
-
/** Returns true for e.g. foo/bar/ */
|
|
71
|
-
function isDirectory(specifier) {
|
|
72
|
-
return /\/$/.test(specifier);
|
|
73
|
-
}
|