@myst-theme/jupyter 0.3.4 → 0.3.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/cjs/controls/NotebookToolbar.js +1 -1
- package/dist/cjs/embed.d.ts +4 -0
- package/dist/cjs/embed.d.ts.map +1 -0
- package/dist/cjs/embed.js +24 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/jupyter.d.ts.map +1 -1
- package/dist/cjs/jupyter.js +7 -10
- package/dist/cjs/output.d.ts +1 -1
- package/dist/cjs/output.d.ts.map +1 -1
- package/dist/cjs/output.js +3 -6
- package/dist/esm/controls/NotebookToolbar.js +1 -1
- package/dist/esm/embed.d.ts +4 -0
- package/dist/esm/embed.d.ts.map +1 -0
- package/dist/esm/embed.js +20 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/jupyter.d.ts.map +1 -1
- package/dist/esm/jupyter.js +7 -10
- package/dist/esm/output.d.ts +1 -1
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +4 -7
- package/dist/types/embed.d.ts +4 -0
- package/dist/types/embed.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/jupyter.d.ts.map +1 -1
- package/dist/types/output.d.ts +1 -1
- package/dist/types/output.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -39,7 +39,7 @@ function NotebookToolbar({ showLaunch = false }) {
|
|
|
39
39
|
title = status;
|
|
40
40
|
}
|
|
41
41
|
if (computable)
|
|
42
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "sticky top-[60px] flex justify-end w-full z-20 pointer-events-none", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex p-1 m-1
|
|
42
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "sticky top-[60px] flex justify-end w-full z-20 pointer-events-none", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex p-1 m-1 border rounded-full shadow pointer-events-auto space-x-1 border-stone-300 bg-white/80 dark:bg-stone-900/80 backdrop-blur", children: [!ready && ((0, jsx_runtime_1.jsxs)("div", { className: "rounded", children: [(0, jsx_runtime_1.jsx)("button", { className: (0, classnames_1.default)('flex text-center rounded-full cursor-pointer text-stone-800 dark:text-white hover:opacity-100 opacity-60', {
|
|
43
43
|
'opacity-10 text-stone-100 dark:text-stone-700': connecting || building,
|
|
44
44
|
}), onClick: handleStart, disabled: building, "aria-label": "start compute environment", children: (0, jsx_runtime_1.jsx)(PowerIcon_1.default, { className: "inline-block w-6 h-6 align-top", title: "enable compute" }) }), (connecting || building) && !error && ((0, jsx_runtime_1.jsx)("span", { className: "absolute top-1 left-1 z-10 w-[22px] h-[22px] opacity-100", title: title, children: (0, jsx_runtime_1.jsx)(Spinner_1.Spinner, { size: 24 }) }))] })), ready && ((0, jsx_runtime_1.jsx)(Buttons_1.Run, { ready: ready, executing: busy.page(slug, 'execute'), onClick: handleRun, title: "Run all cells" })), ready && ((0, jsx_runtime_1.jsx)(Buttons_1.Reset, { ready: ready, resetting: busy.page(slug, 'reset'), onClick: handleReset, title: "Reset notebook and restart kernel" })), ready && ((0, jsx_runtime_1.jsx)(Buttons_1.Clear, { ready: ready, disabled: busy.page(slug, 'execute') || busy.page(slug, 'reset'), onClick: handleClear, title: "Clear all cells" })), showLaunch && ready && ((0, jsx_runtime_1.jsx)(Buttons_1.Launch, { ready: ready, disabled: false, onClick: handleLaunch, title: "Launch notebook in Jupyter" }))] }) }));
|
|
45
45
|
return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/embed.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAoD/D,wBAAgB,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,2CAajE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Embed = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const myst_common_1 = require("myst-common");
|
|
6
|
+
const execute_1 = require("./execute");
|
|
7
|
+
const ArticleCellControls_1 = require("./controls/ArticleCellControls");
|
|
8
|
+
const solid_1 = require("@scienceicons/react/24/solid");
|
|
9
|
+
const unist_util_select_1 = require("unist-util-select");
|
|
10
|
+
const providers_1 = require("@myst-theme/providers");
|
|
11
|
+
function EmbedWithControls({ outputKey, children, title = 'Jupyter Notebook', url, }) {
|
|
12
|
+
const { kind } = (0, execute_1.useCellExecution)(outputKey);
|
|
13
|
+
const Link = (0, providers_1.useLinkProvider)();
|
|
14
|
+
const showControls = kind === myst_common_1.SourceFileKind.Article;
|
|
15
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "shadow", children: [showControls && ((0, jsx_runtime_1.jsx)("div", { className: "sticky top-[60px] z-[2] w-full bg-gray-100/80 backdrop-blur dark:bg-neutral-800/80 py-1 px-2", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center", children: [(0, jsx_runtime_1.jsx)(solid_1.JupyterIcon, { className: "inline-block w-5 h-5" }), (0, jsx_runtime_1.jsx)("span", { className: "ml-2", children: "Source:" }), url && ((0, jsx_runtime_1.jsx)(Link, { to: url, className: "ml-2 no-underline text-normal hover:underline", children: title }))] }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow" }), (0, jsx_runtime_1.jsx)(ArticleCellControls_1.ArticleStatusBadge, { id: outputKey }), (0, jsx_runtime_1.jsx)(ArticleCellControls_1.ArticleRunNotebook, { id: outputKey }), (0, jsx_runtime_1.jsx)(ArticleCellControls_1.ArticleResetNotebook, { id: outputKey })] }) })), (0, jsx_runtime_1.jsx)("div", { className: "mt-2", children: children })] }));
|
|
16
|
+
}
|
|
17
|
+
function Embed(node, children) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const output = (0, unist_util_select_1.select)('output', node);
|
|
20
|
+
if (!output)
|
|
21
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(EmbedWithControls, { outputKey: output.key, title: (_a = node.source) === null || _a === void 0 ? void 0 : _a.title, url: (_b = node.source) === null || _b === void 0 ? void 0 : _b.url, children: children }, node.key));
|
|
23
|
+
}
|
|
24
|
+
exports.Embed = Embed;
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAA,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAA,MAAM,gBAAgB;;;CAGrB,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,eAAe,gBAAgB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,9 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const embed_1 = require("./embed");
|
|
17
18
|
const output_1 = require("./output");
|
|
18
19
|
const OUTPUT_RENDERERS = {
|
|
19
20
|
output: output_1.Output,
|
|
21
|
+
embed: embed_1.Embed,
|
|
20
22
|
};
|
|
21
23
|
__exportStar(require("./BinderBadge"), exports);
|
|
22
24
|
__exportStar(require("./ErrorTray"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAmE3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAmD1D,CAAC"}
|
package/dist/cjs/jupyter.js
CHANGED
|
@@ -33,11 +33,11 @@ const myst_common_1 = require("myst-common");
|
|
|
33
33
|
const providers_1 = require("@myst-theme/providers");
|
|
34
34
|
const thebe_react_1 = require("thebe-react");
|
|
35
35
|
const execute_1 = require("./execute");
|
|
36
|
-
function ActiveOutputRenderer({ id, initialData }) {
|
|
36
|
+
function ActiveOutputRenderer({ id, initialData, core, }) {
|
|
37
37
|
const exec = (0, execute_1.useCellExecution)(id);
|
|
38
38
|
const ref = (0, react_1.useRef)(null);
|
|
39
39
|
(0, react_1.useEffect)(() => {
|
|
40
|
-
var _a;
|
|
40
|
+
var _a, _b, _c;
|
|
41
41
|
if (!ref.current || !(exec === null || exec === void 0 ? void 0 : exec.cell)) {
|
|
42
42
|
console.debug(`Jupyter: No cell ref available for cell ${(_a = exec === null || exec === void 0 ? void 0 : exec.cell) === null || _a === void 0 ? void 0 : _a.id}`);
|
|
43
43
|
return;
|
|
@@ -46,14 +46,11 @@ function ActiveOutputRenderer({ id, initialData }) {
|
|
|
46
46
|
console.debug(`${verb} cell ${exec.cell.id} to DOM at:`, {
|
|
47
47
|
el: ref.current,
|
|
48
48
|
connected: ref.current.isConnected,
|
|
49
|
-
data: initialData,
|
|
49
|
+
data: (_b = core === null || core === void 0 ? void 0 : core.stripWidgets(initialData)) !== null && _b !== void 0 ? _b : initialData,
|
|
50
50
|
});
|
|
51
51
|
exec.cell.attachToDOM(ref.current);
|
|
52
52
|
if (exec.cell.executionCount == null) {
|
|
53
|
-
exec.cell.initOutputs(initialData);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
exec.cell.refresh();
|
|
53
|
+
exec.cell.initOutputs((_c = core === null || core === void 0 ? void 0 : core.stripWidgets(initialData)) !== null && _c !== void 0 ? _c : initialData);
|
|
57
54
|
}
|
|
58
55
|
}, [ref === null || ref === void 0 ? void 0 : ref.current, exec === null || exec === void 0 ? void 0 : exec.cell]);
|
|
59
56
|
return (0, jsx_runtime_1.jsx)("div", { ref: ref, "data-thebe-active-ref": "true", className: "relative" });
|
|
@@ -62,10 +59,11 @@ function PassiveOutputRenderer({ id, data, core, kind, }) {
|
|
|
62
59
|
const cell = (0, react_1.useRef)(new core.PassiveCellRenderer(id, undefined, undefined));
|
|
63
60
|
const ref = (0, react_1.useRef)(null);
|
|
64
61
|
(0, react_1.useEffect)(() => {
|
|
62
|
+
var _a;
|
|
65
63
|
if (!ref.current)
|
|
66
64
|
return;
|
|
67
65
|
cell.current.attachToDOM(ref.current, true);
|
|
68
|
-
cell.current.render(
|
|
66
|
+
cell.current.render((_a = core === null || core === void 0 ? void 0 : core.stripWidgets(data)) !== null && _a !== void 0 ? _a : data);
|
|
69
67
|
}, [ref]);
|
|
70
68
|
return (0, jsx_runtime_1.jsx)("div", { ref: ref, "data-thebe-passive-ref": "true" });
|
|
71
69
|
}
|
|
@@ -74,7 +72,6 @@ exports.JupyterOutputs = react_1.default.memo(({ id, outputs }) => {
|
|
|
74
72
|
const { inCrossRef } = (0, providers_1.useXRefState)();
|
|
75
73
|
const { data, error } = (0, hooks_1.useFetchAnyTruncatedContent)(outputs);
|
|
76
74
|
const [fullOutputs, setFullOutputs] = (0, react_1.useState)(null);
|
|
77
|
-
// const exec = useNotebookCellExecution(id);
|
|
78
75
|
const exec = (0, execute_1.useCellExecution)(id);
|
|
79
76
|
(0, react_1.useEffect)(() => {
|
|
80
77
|
if (core)
|
|
@@ -94,7 +91,7 @@ exports.JupyterOutputs = react_1.default.memo(({ id, outputs }) => {
|
|
|
94
91
|
return (0, jsx_runtime_1.jsxs)("div", { className: "text-red-500", children: ["Error rendering output: ", error.message] });
|
|
95
92
|
}
|
|
96
93
|
if (!inCrossRef && (exec === null || exec === void 0 ? void 0 : exec.ready)) {
|
|
97
|
-
return ((0, jsx_runtime_1.jsxs)("div", { children: [!fullOutputs && (0, jsx_runtime_1.jsx)("div", { className: "p-2.5", children: "
|
|
94
|
+
return ((0, jsx_runtime_1.jsxs)("div", { children: [!fullOutputs && (0, jsx_runtime_1.jsx)("div", { className: "p-2.5", children: "Fetching full output data..." }), core && fullOutputs && ((0, jsx_runtime_1.jsx)(ActiveOutputRenderer, { id: id, initialData: fullOutputs, core: core }, id))] }));
|
|
98
95
|
}
|
|
99
96
|
return ((0, jsx_runtime_1.jsxs)("div", { children: [!fullOutputs && (0, jsx_runtime_1.jsx)("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && core && ((0, jsx_runtime_1.jsx)(PassiveOutputRenderer, { id: id, data: fullOutputs, core: core, kind: myst_common_1.SourceFileKind.Notebook }))] }));
|
|
100
97
|
});
|
package/dist/cjs/output.d.ts
CHANGED
package/dist/cjs/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,MAAM,CAAC;AAO/D,eAAO,MAAM,mBAAmB,aAA+B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,aAMb,CAAC;AAElB,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,cAAc,EAAE,EACzB,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,EAC9B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,WAY7B;AA6CD,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,2CAYvC"}
|
package/dist/cjs/output.js
CHANGED
|
@@ -5,14 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Output = exports.allOutputsAreSafe = exports.DIRECT_MIME_TYPES = exports.DIRECT_OUTPUT_TYPES = void 0;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const myst_common_1 = require("myst-common");
|
|
9
8
|
const nbtx_1 = require("nbtx");
|
|
10
9
|
const classnames_1 = __importDefault(require("classnames"));
|
|
11
10
|
const safe_1 = require("./safe");
|
|
12
11
|
const jupyter_1 = require("./jupyter");
|
|
13
12
|
const react_1 = require("react");
|
|
14
13
|
const execute_1 = require("./execute");
|
|
15
|
-
const ArticleCellControls_1 = require("./controls/ArticleCellControls");
|
|
16
14
|
exports.DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);
|
|
17
15
|
exports.DIRECT_MIME_TYPES = new Set([
|
|
18
16
|
nbtx_1.KnownCellOutputMimeTypes.TextPlain,
|
|
@@ -35,7 +33,7 @@ function allOutputsAreSafe(outputs, directOutputTypes, directMimeTypes) {
|
|
|
35
33
|
}
|
|
36
34
|
exports.allOutputsAreSafe = allOutputsAreSafe;
|
|
37
35
|
function JupyterOutput({ nodeKey, nodeType, identifier, data, align, }) {
|
|
38
|
-
const {
|
|
36
|
+
const { ready } = (0, execute_1.useCellExecution)(nodeKey);
|
|
39
37
|
const outputs = data;
|
|
40
38
|
const allSafe = (0, react_1.useMemo)(() => allOutputsAreSafe(outputs, exports.DIRECT_OUTPUT_TYPES, exports.DIRECT_MIME_TYPES), [outputs]);
|
|
41
39
|
let component;
|
|
@@ -45,12 +43,11 @@ function JupyterOutput({ nodeKey, nodeType, identifier, data, align, }) {
|
|
|
45
43
|
else {
|
|
46
44
|
component = (0, jsx_runtime_1.jsx)(jupyter_1.JupyterOutputs, { id: nodeKey, outputs: outputs });
|
|
47
45
|
}
|
|
48
|
-
|
|
49
|
-
return ((0, jsx_runtime_1.jsxs)("figure", { id: identifier || undefined, "data-mdast-node-type": nodeType, "data-mdast-node-id": nodeKey, className: (0, classnames_1.default)('max-w-full overflow-visible m-0 group not-prose relative', {
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)("figure", { id: identifier || undefined, "data-mdast-node-type": nodeType, "data-mdast-node-id": nodeKey, className: (0, classnames_1.default)('max-w-full overflow-visible m-0 group not-prose relative', {
|
|
50
47
|
'text-left': !align || align === 'left',
|
|
51
48
|
'text-center': align === 'center',
|
|
52
49
|
'text-right': align === 'right',
|
|
53
|
-
}), children:
|
|
50
|
+
}), children: component }));
|
|
54
51
|
}
|
|
55
52
|
function Output(node) {
|
|
56
53
|
// Note, NodeRenderer's can't have hooks in it directly!
|
|
@@ -33,7 +33,7 @@ export function NotebookToolbar({ showLaunch = false }) {
|
|
|
33
33
|
title = status;
|
|
34
34
|
}
|
|
35
35
|
if (computable)
|
|
36
|
-
return (_jsx("div", { className: "sticky top-[60px] flex justify-end w-full z-20 pointer-events-none", children: _jsxs("div", { className: "flex p-1 m-1
|
|
36
|
+
return (_jsx("div", { className: "sticky top-[60px] flex justify-end w-full z-20 pointer-events-none", children: _jsxs("div", { className: "flex p-1 m-1 border rounded-full shadow pointer-events-auto space-x-1 border-stone-300 bg-white/80 dark:bg-stone-900/80 backdrop-blur", children: [!ready && (_jsxs("div", { className: "rounded", children: [_jsx("button", { className: classNames('flex text-center rounded-full cursor-pointer text-stone-800 dark:text-white hover:opacity-100 opacity-60', {
|
|
37
37
|
'opacity-10 text-stone-100 dark:text-stone-700': connecting || building,
|
|
38
38
|
}), onClick: handleStart, disabled: building, "aria-label": "start compute environment", children: _jsx(PowerIcon, { className: "inline-block w-6 h-6 align-top", title: "enable compute" }) }), (connecting || building) && !error && (_jsx("span", { className: "absolute top-1 left-1 z-10 w-[22px] h-[22px] opacity-100", title: title, children: _jsx(Spinner, { size: 24 }) }))] })), ready && (_jsx(Run, { ready: ready, executing: busy.page(slug, 'execute'), onClick: handleRun, title: "Run all cells" })), ready && (_jsx(Reset, { ready: ready, resetting: busy.page(slug, 'reset'), onClick: handleReset, title: "Reset notebook and restart kernel" })), ready && (_jsx(Clear, { ready: ready, disabled: busy.page(slug, 'execute') || busy.page(slug, 'reset'), onClick: handleClear, title: "Clear all cells" })), showLaunch && ready && (_jsx(Launch, { ready: ready, disabled: false, onClick: handleLaunch, title: "Launch notebook in Jupyter" }))] }) }));
|
|
39
39
|
return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/embed.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAoD/D,wBAAgB,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,2CAajE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { SourceFileKind } from 'myst-common';
|
|
3
|
+
import { useCellExecution } from './execute';
|
|
4
|
+
import { ArticleResetNotebook, ArticleRunNotebook, ArticleStatusBadge, } from './controls/ArticleCellControls';
|
|
5
|
+
import { JupyterIcon } from '@scienceicons/react/24/solid';
|
|
6
|
+
import { select } from 'unist-util-select';
|
|
7
|
+
import { useLinkProvider } from '@myst-theme/providers';
|
|
8
|
+
function EmbedWithControls({ outputKey, children, title = 'Jupyter Notebook', url, }) {
|
|
9
|
+
const { kind } = useCellExecution(outputKey);
|
|
10
|
+
const Link = useLinkProvider();
|
|
11
|
+
const showControls = kind === SourceFileKind.Article;
|
|
12
|
+
return (_jsxs("div", { className: "shadow", children: [showControls && (_jsx("div", { className: "sticky top-[60px] z-[2] w-full bg-gray-100/80 backdrop-blur dark:bg-neutral-800/80 py-1 px-2", children: _jsxs("div", { className: "flex items-center", children: [_jsxs("div", { className: "flex items-center", children: [_jsx(JupyterIcon, { className: "inline-block w-5 h-5" }), _jsx("span", { className: "ml-2", children: "Source:" }), url && (_jsx(Link, { to: url, className: "ml-2 no-underline text-normal hover:underline", children: title }))] }), _jsx("div", { className: "flex-grow" }), _jsx(ArticleStatusBadge, { id: outputKey }), _jsx(ArticleRunNotebook, { id: outputKey }), _jsx(ArticleResetNotebook, { id: outputKey })] }) })), _jsx("div", { className: "mt-2", children: children })] }));
|
|
13
|
+
}
|
|
14
|
+
export function Embed(node, children) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const output = select('output', node);
|
|
17
|
+
if (!output)
|
|
18
|
+
return _jsx(_Fragment, { children: children });
|
|
19
|
+
return (_jsx(EmbedWithControls, { outputKey: output.key, title: (_a = node.source) === null || _a === void 0 ? void 0 : _a.title, url: (_b = node.source) === null || _b === void 0 ? void 0 : _b.url, children: children }, node.key));
|
|
20
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAA,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAA,MAAM,gBAAgB;;;CAGrB,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,eAAe,gBAAgB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAmE3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAmD1D,CAAC"}
|
package/dist/esm/jupyter.js
CHANGED
|
@@ -7,11 +7,11 @@ import { SourceFileKind } from 'myst-common';
|
|
|
7
7
|
import { useXRefState } from '@myst-theme/providers';
|
|
8
8
|
import { useThebeLoader } from 'thebe-react';
|
|
9
9
|
import { useCellExecution } from './execute';
|
|
10
|
-
function ActiveOutputRenderer({ id, initialData }) {
|
|
10
|
+
function ActiveOutputRenderer({ id, initialData, core, }) {
|
|
11
11
|
const exec = useCellExecution(id);
|
|
12
12
|
const ref = useRef(null);
|
|
13
13
|
useEffect(() => {
|
|
14
|
-
var _a;
|
|
14
|
+
var _a, _b, _c;
|
|
15
15
|
if (!ref.current || !(exec === null || exec === void 0 ? void 0 : exec.cell)) {
|
|
16
16
|
console.debug(`Jupyter: No cell ref available for cell ${(_a = exec === null || exec === void 0 ? void 0 : exec.cell) === null || _a === void 0 ? void 0 : _a.id}`);
|
|
17
17
|
return;
|
|
@@ -20,14 +20,11 @@ function ActiveOutputRenderer({ id, initialData }) {
|
|
|
20
20
|
console.debug(`${verb} cell ${exec.cell.id} to DOM at:`, {
|
|
21
21
|
el: ref.current,
|
|
22
22
|
connected: ref.current.isConnected,
|
|
23
|
-
data: initialData,
|
|
23
|
+
data: (_b = core === null || core === void 0 ? void 0 : core.stripWidgets(initialData)) !== null && _b !== void 0 ? _b : initialData,
|
|
24
24
|
});
|
|
25
25
|
exec.cell.attachToDOM(ref.current);
|
|
26
26
|
if (exec.cell.executionCount == null) {
|
|
27
|
-
exec.cell.initOutputs(initialData);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
exec.cell.refresh();
|
|
27
|
+
exec.cell.initOutputs((_c = core === null || core === void 0 ? void 0 : core.stripWidgets(initialData)) !== null && _c !== void 0 ? _c : initialData);
|
|
31
28
|
}
|
|
32
29
|
}, [ref === null || ref === void 0 ? void 0 : ref.current, exec === null || exec === void 0 ? void 0 : exec.cell]);
|
|
33
30
|
return _jsx("div", { ref: ref, "data-thebe-active-ref": "true", className: "relative" });
|
|
@@ -36,10 +33,11 @@ function PassiveOutputRenderer({ id, data, core, kind, }) {
|
|
|
36
33
|
const cell = useRef(new core.PassiveCellRenderer(id, undefined, undefined));
|
|
37
34
|
const ref = useRef(null);
|
|
38
35
|
useEffect(() => {
|
|
36
|
+
var _a;
|
|
39
37
|
if (!ref.current)
|
|
40
38
|
return;
|
|
41
39
|
cell.current.attachToDOM(ref.current, true);
|
|
42
|
-
cell.current.render(
|
|
40
|
+
cell.current.render((_a = core === null || core === void 0 ? void 0 : core.stripWidgets(data)) !== null && _a !== void 0 ? _a : data);
|
|
43
41
|
}, [ref]);
|
|
44
42
|
return _jsx("div", { ref: ref, "data-thebe-passive-ref": "true" });
|
|
45
43
|
}
|
|
@@ -48,7 +46,6 @@ export const JupyterOutputs = React.memo(({ id, outputs }) => {
|
|
|
48
46
|
const { inCrossRef } = useXRefState();
|
|
49
47
|
const { data, error } = useFetchAnyTruncatedContent(outputs);
|
|
50
48
|
const [fullOutputs, setFullOutputs] = useState(null);
|
|
51
|
-
// const exec = useNotebookCellExecution(id);
|
|
52
49
|
const exec = useCellExecution(id);
|
|
53
50
|
useEffect(() => {
|
|
54
51
|
if (core)
|
|
@@ -68,7 +65,7 @@ export const JupyterOutputs = React.memo(({ id, outputs }) => {
|
|
|
68
65
|
return _jsxs("div", { className: "text-red-500", children: ["Error rendering output: ", error.message] });
|
|
69
66
|
}
|
|
70
67
|
if (!inCrossRef && (exec === null || exec === void 0 ? void 0 : exec.ready)) {
|
|
71
|
-
return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "
|
|
68
|
+
return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "Fetching full output data..." }), core && fullOutputs && (_jsx(ActiveOutputRenderer, { id: id, initialData: fullOutputs, core: core }, id))] }));
|
|
72
69
|
}
|
|
73
70
|
return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && core && (_jsx(PassiveOutputRenderer, { id: id, data: fullOutputs, core: core, kind: SourceFileKind.Notebook }))] }));
|
|
74
71
|
});
|
package/dist/esm/output.d.ts
CHANGED
package/dist/esm/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,MAAM,CAAC;AAO/D,eAAO,MAAM,mBAAmB,aAA+B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,aAMb,CAAC;AAElB,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,cAAc,EAAE,EACzB,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,EAC9B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,WAY7B;AA6CD,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,2CAYvC"}
|
package/dist/esm/output.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import { SourceFileKind } from 'myst-common';
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
2
|
import { KnownCellOutputMimeTypes } from 'nbtx';
|
|
4
3
|
import classNames from 'classnames';
|
|
5
4
|
import { SafeOutputs } from './safe';
|
|
6
5
|
import { JupyterOutputs } from './jupyter';
|
|
7
6
|
import { useMemo } from 'react';
|
|
8
7
|
import { useCellExecution } from './execute';
|
|
9
|
-
import { ArticleResetNotebook, ArticleRunNotebook, ArticleStatusBadge, } from './controls/ArticleCellControls';
|
|
10
8
|
export const DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);
|
|
11
9
|
export const DIRECT_MIME_TYPES = new Set([
|
|
12
10
|
KnownCellOutputMimeTypes.TextPlain,
|
|
@@ -28,7 +26,7 @@ export function allOutputsAreSafe(outputs, directOutputTypes, directMimeTypes) {
|
|
|
28
26
|
}, true);
|
|
29
27
|
}
|
|
30
28
|
function JupyterOutput({ nodeKey, nodeType, identifier, data, align, }) {
|
|
31
|
-
const {
|
|
29
|
+
const { ready } = useCellExecution(nodeKey);
|
|
32
30
|
const outputs = data;
|
|
33
31
|
const allSafe = useMemo(() => allOutputsAreSafe(outputs, DIRECT_OUTPUT_TYPES, DIRECT_MIME_TYPES), [outputs]);
|
|
34
32
|
let component;
|
|
@@ -38,12 +36,11 @@ function JupyterOutput({ nodeKey, nodeType, identifier, data, align, }) {
|
|
|
38
36
|
else {
|
|
39
37
|
component = _jsx(JupyterOutputs, { id: nodeKey, outputs: outputs });
|
|
40
38
|
}
|
|
41
|
-
|
|
42
|
-
return (_jsxs("figure", { id: identifier || undefined, "data-mdast-node-type": nodeType, "data-mdast-node-id": nodeKey, className: classNames('max-w-full overflow-visible m-0 group not-prose relative', {
|
|
39
|
+
return (_jsx("figure", { id: identifier || undefined, "data-mdast-node-type": nodeType, "data-mdast-node-id": nodeKey, className: classNames('max-w-full overflow-visible m-0 group not-prose relative', {
|
|
43
40
|
'text-left': !align || align === 'left',
|
|
44
41
|
'text-center': align === 'center',
|
|
45
42
|
'text-right': align === 'right',
|
|
46
|
-
}), children:
|
|
43
|
+
}), children: component }));
|
|
47
44
|
}
|
|
48
45
|
export function Output(node) {
|
|
49
46
|
// Note, NodeRenderer's can't have hooks in it directly!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/embed.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAoD/D,wBAAgB,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,2CAajE"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAA,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAA,MAAM,gBAAgB;;;CAGrB,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAmE3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAmD1D,CAAC"}
|
package/dist/types/output.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,MAAM,CAAC;AAO/D,eAAO,MAAM,mBAAmB,aAA+B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,aAMb,CAAC;AAElB,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,cAAc,EAAE,EACzB,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,EAC9B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,WAY7B;AA6CD,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,2CAYvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myst-theme/jupyter",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@headlessui/react": "^1.7.15",
|
|
25
25
|
"@heroicons/react": "^2.0.18",
|
|
26
|
-
"@myst-theme/providers": "^0.3.
|
|
26
|
+
"@myst-theme/providers": "^0.3.5",
|
|
27
27
|
"ansi-to-react": "^6.1.6",
|
|
28
28
|
"buffer": "^6.0.3",
|
|
29
29
|
"classnames": "^2.3.2",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"myst-config": "^1.0.0",
|
|
32
32
|
"myst-frontmatter": "^1.0.0",
|
|
33
33
|
"myst-spec": "^0.0.4",
|
|
34
|
-
"myst-to-react": "^0.3.
|
|
34
|
+
"myst-to-react": "^0.3.5",
|
|
35
35
|
"nanoid": "^4.0.2",
|
|
36
36
|
"nbtx": "^0.2.3",
|
|
37
37
|
"react-syntax-highlighter": "^15.5.0",
|
|
38
38
|
"swr": "^2.1.5",
|
|
39
|
-
"thebe-core": "^0.2.
|
|
40
|
-
"thebe-lite": "^0.2.
|
|
41
|
-
"thebe-react": "^0.2.
|
|
39
|
+
"thebe-core": "^0.2.9",
|
|
40
|
+
"thebe-lite": "^0.2.9",
|
|
41
|
+
"thebe-react": "^0.2.9",
|
|
42
42
|
"unist-util-select": "^4.0.3"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|