@myst-theme/jupyter 0.3.8 → 0.4.1
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/ErrorTray.d.ts +4 -4
- package/dist/cjs/ErrorTray.d.ts.map +1 -1
- package/dist/cjs/ErrorTray.js +11 -3
- package/dist/cjs/decoration.d.ts +11 -0
- package/dist/cjs/decoration.d.ts.map +1 -0
- package/dist/cjs/decoration.js +39 -0
- package/dist/cjs/embed.d.ts +3 -2
- package/dist/cjs/embed.d.ts.map +1 -1
- package/dist/cjs/embed.js +8 -22
- package/dist/cjs/execute/actions.d.ts +1 -1
- package/dist/cjs/execute/actions.d.ts.map +1 -1
- package/dist/cjs/execute/busy.d.ts +24 -2
- package/dist/cjs/execute/busy.d.ts.map +1 -1
- package/dist/cjs/execute/busy.js +86 -9
- package/dist/cjs/execute/hooks.d.ts +2 -2
- package/dist/cjs/execute/hooks.d.ts.map +1 -1
- package/dist/cjs/execute/hooks.js +14 -6
- package/dist/cjs/execute/provider.d.ts +2 -2
- package/dist/cjs/execute/provider.d.ts.map +1 -1
- package/dist/cjs/execute/provider.js +4 -4
- package/dist/cjs/execute/reducer.js +2 -2
- package/dist/cjs/execute/selectors.d.ts.map +1 -1
- package/dist/cjs/execute/selectors.js +8 -8
- package/dist/cjs/execute/types.d.ts +1 -1
- package/dist/cjs/execute/types.d.ts.map +1 -1
- package/dist/cjs/execute/utils.d.ts.map +1 -1
- package/dist/cjs/execute/utils.js +8 -7
- package/dist/cjs/figure.d.ts +5 -0
- package/dist/cjs/figure.d.ts.map +1 -0
- package/dist/cjs/figure.js +20 -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 +20 -6
- package/dist/cjs/output.d.ts +9 -1
- package/dist/cjs/output.d.ts.map +1 -1
- package/dist/cjs/output.js +17 -9
- package/dist/cjs/providers.d.ts +1 -1
- package/dist/cjs/providers.d.ts.map +1 -1
- package/dist/cjs/utils.js +2 -2
- package/dist/esm/ErrorTray.d.ts +4 -4
- package/dist/esm/ErrorTray.d.ts.map +1 -1
- package/dist/esm/ErrorTray.js +11 -3
- package/dist/esm/decoration.d.ts +11 -0
- package/dist/esm/decoration.d.ts.map +1 -0
- package/dist/esm/decoration.js +31 -0
- package/dist/esm/embed.d.ts +3 -2
- package/dist/esm/embed.d.ts.map +1 -1
- package/dist/esm/embed.js +9 -23
- package/dist/esm/execute/actions.d.ts +1 -1
- package/dist/esm/execute/actions.d.ts.map +1 -1
- package/dist/esm/execute/busy.d.ts +24 -2
- package/dist/esm/execute/busy.d.ts.map +1 -1
- package/dist/esm/execute/busy.js +84 -8
- package/dist/esm/execute/hooks.d.ts +2 -2
- package/dist/esm/execute/hooks.d.ts.map +1 -1
- package/dist/esm/execute/hooks.js +13 -5
- package/dist/esm/execute/provider.d.ts +2 -2
- package/dist/esm/execute/provider.d.ts.map +1 -1
- package/dist/esm/execute/provider.js +2 -2
- package/dist/esm/execute/reducer.js +1 -1
- package/dist/esm/execute/selectors.d.ts.map +1 -1
- package/dist/esm/execute/selectors.js +7 -7
- package/dist/esm/execute/types.d.ts +1 -1
- package/dist/esm/execute/types.d.ts.map +1 -1
- package/dist/esm/execute/utils.d.ts.map +1 -1
- package/dist/esm/execute/utils.js +8 -7
- package/dist/esm/figure.d.ts +5 -0
- package/dist/esm/figure.d.ts.map +1 -0
- package/dist/esm/figure.js +16 -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 +16 -5
- package/dist/esm/output.d.ts +9 -1
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +15 -8
- package/dist/esm/providers.d.ts +1 -1
- package/dist/esm/providers.d.ts.map +1 -1
- package/dist/esm/utils.js +2 -2
- package/dist/types/ErrorTray.d.ts +4 -4
- package/dist/types/ErrorTray.d.ts.map +1 -1
- package/dist/types/decoration.d.ts +11 -0
- package/dist/types/decoration.d.ts.map +1 -0
- package/dist/types/embed.d.ts +3 -2
- package/dist/types/embed.d.ts.map +1 -1
- package/dist/types/execute/actions.d.ts +1 -1
- package/dist/types/execute/actions.d.ts.map +1 -1
- package/dist/types/execute/busy.d.ts +24 -2
- package/dist/types/execute/busy.d.ts.map +1 -1
- package/dist/types/execute/hooks.d.ts +2 -2
- package/dist/types/execute/hooks.d.ts.map +1 -1
- package/dist/types/execute/provider.d.ts +2 -2
- package/dist/types/execute/provider.d.ts.map +1 -1
- package/dist/types/execute/selectors.d.ts.map +1 -1
- package/dist/types/execute/types.d.ts +1 -1
- package/dist/types/execute/types.d.ts.map +1 -1
- package/dist/types/execute/utils.d.ts.map +1 -1
- package/dist/types/figure.d.ts +5 -0
- package/dist/types/figure.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 +9 -1
- package/dist/types/output.d.ts.map +1 -1
- package/dist/types/providers.d.ts +1 -1
- package/dist/types/providers.d.ts.map +1 -1
- package/package.json +11 -9
package/dist/cjs/ErrorTray.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
export declare function ErrorTray({ pageSlug, index }: {
|
|
2
|
+
pageSlug: string;
|
|
3
|
+
index?: string;
|
|
4
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
5
5
|
//# sourceMappingURL=ErrorTray.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorTray.d.ts","sourceRoot":"","sources":["../../src/ErrorTray.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ErrorTray.d.ts","sourceRoot":"","sources":["../../src/ErrorTray.tsx"],"names":[],"mappings":"AAmDA,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,kDAkBlF"}
|
package/dist/cjs/ErrorTray.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.ErrorTray = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const thebe_react_1 = require("thebe-react");
|
|
7
|
+
const busy_1 = require("./execute/busy");
|
|
7
8
|
function ErrorDecoration({ children, idx }) {
|
|
8
9
|
return ((0, jsx_runtime_1.jsxs)("div", { className: "relative py-3 mx-2 my-8 border rounded", children: [(0, jsx_runtime_1.jsx)("div", { className: "absolute z-10 flex items-center bg-white -top-3 -left-2", children: idx && (0, jsx_runtime_1.jsxs)("div", { className: "ml-1 text-sm text-gray-500", children: ["cell #: ", idx] }) }), (0, jsx_runtime_1.jsx)("div", { className: "mx-3", children: children })] }));
|
|
9
10
|
}
|
|
@@ -26,9 +27,16 @@ function ErrorTrayMessage({ errors }) {
|
|
|
26
27
|
}, [core, errors]);
|
|
27
28
|
if (!core)
|
|
28
29
|
return null;
|
|
29
|
-
return ((0, jsx_runtime_1.jsx)("div", { children: errors.map((error, idx) => ((0, jsx_runtime_1.jsx)("div", { className: "min-w-[400px]", children: (0, jsx_runtime_1.jsx)(ErrorDecoration, { idx: error.index, children: (0, jsx_runtime_1.jsx)("div", { className: "z-100", ref: refs[idx] }, error.id) }) }))) }));
|
|
30
|
+
return ((0, jsx_runtime_1.jsx)("div", { children: errors.map((error, idx) => ((0, jsx_runtime_1.jsx)("div", { className: "not-prose min-w-[400px]", children: (0, jsx_runtime_1.jsx)(ErrorDecoration, { idx: error.index, children: (0, jsx_runtime_1.jsx)("div", { className: "z-100", ref: refs[idx] }, error.id) }) }))) }));
|
|
30
31
|
}
|
|
31
|
-
function ErrorTray({
|
|
32
|
-
|
|
32
|
+
function ErrorTray({ pageSlug, index }) {
|
|
33
|
+
const { items } = (0, busy_1.useBusyErrors)(pageSlug);
|
|
34
|
+
if (!items || items.length === 0)
|
|
35
|
+
return null;
|
|
36
|
+
if (index && index)
|
|
37
|
+
return null;
|
|
38
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "relative px-4 pt-3 mt-8 text-sm text-red-600 border border-red-400 rounded border-1", children: items.map(({ notebookSlug, errors }) => {
|
|
39
|
+
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("span", { className: "font-bold", children: "Error" }), " in notebook ", (0, jsx_runtime_1.jsxs)("span", { children: ["\"", notebookSlug, "\""] })] }), (0, jsx_runtime_1.jsx)(ErrorTrayMessage, { errors: errors })] }));
|
|
40
|
+
}) }));
|
|
33
41
|
}
|
|
34
42
|
exports.ErrorTray = ErrorTray;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { GenericNode } from 'myst-common';
|
|
3
|
+
export declare function usePlaceholder(): GenericNode | undefined;
|
|
4
|
+
export declare function OutputDecoration({ outputId, placeholder, children, title, url, }: {
|
|
5
|
+
outputId: string;
|
|
6
|
+
placeholder?: GenericNode;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
title?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
//# sourceMappingURL=decoration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoration.d.ts","sourceRoot":"","sources":["../../src/decoration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAqB/C,wBAAgB,cAAc,4BAG7B;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,KAA0B,EAC1B,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,2CAyDA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OutputDecoration = exports.usePlaceholder = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const myst_spec_ext_1 = require("myst-spec-ext");
|
|
10
|
+
const execute_1 = require("./execute");
|
|
11
|
+
const ArticleCellControls_1 = require("./controls/ArticleCellControls");
|
|
12
|
+
const solid_1 = require("@scienceicons/react/24/solid");
|
|
13
|
+
const providers_1 = require("@myst-theme/providers");
|
|
14
|
+
const PlaceholderContext = react_1.default.createContext({});
|
|
15
|
+
function PlaceholderProvider({ placeholder, children, }) {
|
|
16
|
+
const value = react_1.default.useMemo(() => ({ placeholder }), [placeholder]);
|
|
17
|
+
return (0, jsx_runtime_1.jsx)(PlaceholderContext.Provider, { value: value, children: children });
|
|
18
|
+
}
|
|
19
|
+
function usePlaceholder() {
|
|
20
|
+
const context = react_1.default.useContext(PlaceholderContext);
|
|
21
|
+
return context.placeholder;
|
|
22
|
+
}
|
|
23
|
+
exports.usePlaceholder = usePlaceholder;
|
|
24
|
+
function OutputDecoration({ outputId, placeholder, children, title = 'Jupyter Notebook', url, }) {
|
|
25
|
+
const { canCompute, kind } = (0, execute_1.useCellExecution)(outputId);
|
|
26
|
+
const Link = (0, providers_1.useLinkProvider)();
|
|
27
|
+
const baseurl = (0, providers_1.useBaseurl)();
|
|
28
|
+
const showComputeControls = canCompute && kind === myst_spec_ext_1.SourceFileKind.Article;
|
|
29
|
+
if (showComputeControls) {
|
|
30
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mb-4 shadow", children: [(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: (0, providers_1.withBaseurl)(url, baseurl), 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: outputId }), (0, jsx_runtime_1.jsx)(ArticleCellControls_1.ArticleRunNotebook, { id: outputId }), (0, jsx_runtime_1.jsx)(ArticleCellControls_1.ArticleResetNotebook, { id: outputId })] }) }), (0, jsx_runtime_1.jsx)(PlaceholderProvider, { placeholder: placeholder, children: children })] }));
|
|
31
|
+
}
|
|
32
|
+
// light
|
|
33
|
+
if (kind === myst_spec_ext_1.SourceFileKind.Article) {
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-end text-xs", children: [(0, jsx_runtime_1.jsx)(solid_1.JupyterIcon, { className: "inline-block w-3 h-3" }), (0, jsx_runtime_1.jsx)("div", { className: "ml-1", children: "Source:" }), url && ((0, jsx_runtime_1.jsx)(Link, { to: (0, providers_1.withBaseurl)(url, baseurl), className: "ml-1 no-underline text-normal hover:underline", children: title }))] }), (0, jsx_runtime_1.jsx)(PlaceholderProvider, { placeholder: placeholder, children: children })] }));
|
|
35
|
+
}
|
|
36
|
+
// Notebook outputs do not need any decoration
|
|
37
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
38
|
+
}
|
|
39
|
+
exports.OutputDecoration = OutputDecoration;
|
package/dist/cjs/embed.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type GenericNode } from 'myst-common';
|
|
3
|
-
export declare function Embed(node
|
|
2
|
+
export declare function Embed({ node }: {
|
|
3
|
+
node: GenericNode;
|
|
4
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
4
5
|
//# sourceMappingURL=embed.d.ts.map
|
package/dist/cjs/embed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/embed.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/embed.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAK/C,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,2CAkBpD"}
|
package/dist/cjs/embed.js
CHANGED
|
@@ -2,28 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Embed = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
function EmbedWithControls({ outputKey, children, title = 'Jupyter Notebook', url, }) {
|
|
12
|
-
const { canCompute, kind } = (0, execute_1.useCellExecution)(outputKey);
|
|
13
|
-
const Link = (0, providers_1.useLinkProvider)();
|
|
14
|
-
const baseurl = (0, providers_1.useBaseurl)();
|
|
15
|
-
const showComputeControls = canCompute && kind === myst_common_1.SourceFileKind.Article;
|
|
16
|
-
if (showComputeControls) {
|
|
17
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "shadow", children: [(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: (0, providers_1.withBaseurl)(url, baseurl), 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 })] }));
|
|
18
|
-
}
|
|
19
|
-
// light
|
|
20
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [children, (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-end text-xs", children: [(0, jsx_runtime_1.jsx)(solid_1.JupyterIcon, { className: "inline-block w-3 h-3" }), (0, jsx_runtime_1.jsx)("div", { className: "ml-1", children: "Source:" }), url && ((0, jsx_runtime_1.jsx)(Link, { to: (0, providers_1.withBaseurl)(url, baseurl), className: "ml-1 no-underline text-normal hover:underline", children: title }))] })] }));
|
|
21
|
-
}
|
|
22
|
-
function Embed(node, children) {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
const output = (0, unist_util_select_1.select)('output', node);
|
|
5
|
+
const output_1 = require("./output");
|
|
6
|
+
const decoration_1 = require("./decoration");
|
|
7
|
+
const myst_to_react_1 = require("myst-to-react");
|
|
8
|
+
function Embed({ node }) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
const output = (_a = node.children) === null || _a === void 0 ? void 0 : _a.find((child) => child.type === 'output');
|
|
25
11
|
if (!output)
|
|
26
|
-
return (0, jsx_runtime_1.jsx)(
|
|
27
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
12
|
+
return (0, jsx_runtime_1.jsx)(myst_to_react_1.MyST, { ast: node.children });
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(decoration_1.OutputDecoration, { outputId: output.id, title: (_b = node.source) === null || _b === void 0 ? void 0 : _b.title, url: (_c = node.source) === null || _c === void 0 ? void 0 : _c.url, children: (0, jsx_runtime_1.jsx)(output_1.JupyterOutput, { outputId: output.id, identifier: output.identifier, align: node.align, data: node.data }) }, node.key));
|
|
28
14
|
}
|
|
29
15
|
exports.Embed = Embed;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceFileKind, Dependency } from 'myst-spec-ext';
|
|
2
2
|
import type { Root } from 'mdast';
|
|
3
3
|
import type { BuildStatus, Computable } from './types';
|
|
4
4
|
import type { IRenderMimeRegistry, ThebeNotebook, ThebeSession } from 'thebe-core';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/execute/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/execute/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,KAA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;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,kBAAkB,CAQpF;AAED,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,aAAa,CAAC;IACxB,UAAU,EAAE,mBAAmB,CAAC;CACjC;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,iBAAiB,CAOlF;AAED,UAAU,iBAAiB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EACA,UAAU,GACV,eAAe,GACf,cAAc,GACd,aAAa,GACb,WAAW,GACX,cAAc,GACd,aAAa,GACb,qBAAqB,GACrB,qBAAqB,CAAC;IAC1B,OAAO,EACH,eAAe,GACf,WAAW,GACX,iBAAiB,GACjB,kBAAkB,GAClB,eAAe,GACf,kBAAkB,GAClB,iBAAiB,CAAC;CACvB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { IThebeNotebookError } from 'thebe-react';
|
|
2
3
|
export type BusyKind = 'execute' | 'reset';
|
|
3
4
|
export interface BusyScopeState {
|
|
4
5
|
execute: {
|
|
@@ -15,6 +16,11 @@ export interface BusyScopeState {
|
|
|
15
16
|
};
|
|
16
17
|
};
|
|
17
18
|
};
|
|
19
|
+
error: {
|
|
20
|
+
[pageSlug: string]: {
|
|
21
|
+
[notebookSlug: string]: IThebeNotebookError[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
18
24
|
}
|
|
19
25
|
export interface BusyScopeContext {
|
|
20
26
|
state: BusyScopeState;
|
|
@@ -37,9 +43,14 @@ export interface NotebookPayload {
|
|
|
37
43
|
cellIds: string[];
|
|
38
44
|
kind: BusyKind;
|
|
39
45
|
}
|
|
46
|
+
export interface ErrorPayload {
|
|
47
|
+
pageSlug: string;
|
|
48
|
+
notebookSlug: string;
|
|
49
|
+
errors?: IThebeNotebookError[];
|
|
50
|
+
}
|
|
40
51
|
type BusyScopeAction = {
|
|
41
|
-
type: 'SET_CELL_BUSY' | 'CLEAR_CELL_BUSY' | 'SET_NOTEBOOK_BUSY' | 'CLEAR_NOTEBOOK_BUSY';
|
|
42
|
-
payload: SlugPayload | CellPayload | NotebookPayload;
|
|
52
|
+
type: 'SET_CELL_BUSY' | 'CLEAR_CELL_BUSY' | 'SET_NOTEBOOK_BUSY' | 'CLEAR_NOTEBOOK_BUSY' | 'SET_ERROR' | 'CLEAR_ERROR';
|
|
53
|
+
payload: SlugPayload | CellPayload | NotebookPayload | ErrorPayload;
|
|
43
54
|
};
|
|
44
55
|
export declare function reducer(state: BusyScopeState, action: BusyScopeAction): BusyScopeState;
|
|
45
56
|
export declare function BusyScopeProvider({ children }: React.PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -51,6 +62,17 @@ export declare function useBusyScope(): {
|
|
|
51
62
|
clearCell: (pageSlug: string, notebookSlug: string, cellId: string, kind: BusyKind) => void;
|
|
52
63
|
setNotebook: (pageSlug: string, notebookSlug: string, cellIds: string[], kind: BusyKind) => void;
|
|
53
64
|
clearNotebook: (pageSlug: string, notebookSlug: string, kind: BusyKind) => void;
|
|
65
|
+
setError: (pageSlug: string, notebookSlug: string, errors: IThebeNotebookError[]) => void;
|
|
66
|
+
clearError: (pageSlug: string, notebookSlug: string) => void;
|
|
67
|
+
};
|
|
68
|
+
interface ErrorItem {
|
|
69
|
+
pageSlug: string;
|
|
70
|
+
notebookSlug: string;
|
|
71
|
+
errors: IThebeNotebookError[];
|
|
72
|
+
}
|
|
73
|
+
export declare function useBusyErrors(pageSlug: string): {
|
|
74
|
+
items: ErrorItem[] | undefined;
|
|
75
|
+
clearErrors: () => void;
|
|
54
76
|
};
|
|
55
77
|
export declare function selectCellIsBusy(state: BusyScopeState, pageSlug: string, notebookSlug: string, cellId: string, kind: BusyKind): boolean;
|
|
56
78
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"busy.d.ts","sourceRoot":"","sources":["../../../src/execute/busy.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAC;AAEvD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;AAE3C,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE;QACP,CAAC,QAAQ,EAAE,MAAM,GAAG;YAClB,CAAC,YAAY,EAAE,MAAM,GAAG;gBACtB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;aAC3B,CAAC;SACH,CAAC;KACH,CAAC;IACF,KAAK,EAAE;QACL,CAAC,QAAQ,EAAE,MAAM,GAAG;YAClB,CAAC,YAAY,EAAE,MAAM,GAAG;gBACtB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;aAC3B,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;CAC3C;AAYD,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,QAAQ,CAAC;CAChB;AAUD,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;CAChB;AAWD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;CAChB;AAGD,KAAK,eAAe,GAAG;IACrB,IA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AC9B,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,WAGf;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,QAAQ,WAGf;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,WAEvF"}
|
package/dist/cjs/execute/busy.js
CHANGED
|
@@ -34,7 +34,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
34
34
|
return t;
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.selectPageIsBusy = exports.selectNotebookIsBusy = exports.selectCellIsBusy = exports.useBusyScope = exports.BusyScopeProvider = exports.reducer = void 0;
|
|
37
|
+
exports.selectPageIsBusy = exports.selectNotebookIsBusy = exports.selectCellIsBusy = exports.useBusyErrors = exports.useBusyScope = exports.BusyScopeProvider = exports.reducer = void 0;
|
|
38
38
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
39
39
|
const react_1 = __importStar(require("react"));
|
|
40
40
|
const BusyScopeContext = react_1.default.createContext(undefined);
|
|
@@ -54,8 +54,16 @@ function isNotebookPayload(payload) {
|
|
|
54
54
|
payload.cellIds.every((id) => typeof id === 'string') &&
|
|
55
55
|
typeof payload.kind === 'string');
|
|
56
56
|
}
|
|
57
|
+
function isErrorPayload(payload) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
return ((typeof payload.pageSlug === 'string' &&
|
|
60
|
+
typeof payload.notebookSlug === 'string' &&
|
|
61
|
+
payload.errors === undefined) ||
|
|
62
|
+
((_b = (Array.isArray(payload.errors) &&
|
|
63
|
+
((_a = payload.errors) === null || _a === void 0 ? void 0 : _a.every((error) => typeof error === 'object')))) !== null && _b !== void 0 ? _b : false));
|
|
64
|
+
}
|
|
57
65
|
function reducer(state, action) {
|
|
58
|
-
var _a, _b, _c, _d, _e;
|
|
66
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
59
67
|
switch (action.type) {
|
|
60
68
|
case 'SET_CELL_BUSY': {
|
|
61
69
|
if (!isCellPayload(action.payload)) {
|
|
@@ -73,16 +81,16 @@ function reducer(state, action) {
|
|
|
73
81
|
return state;
|
|
74
82
|
}
|
|
75
83
|
const { pageSlug, notebookSlug, cellId, kind } = action.payload;
|
|
76
|
-
const
|
|
84
|
+
const _h = state[kind], _j = pageSlug, renderBusy = _h[_j], otherRenders = __rest(_h, [typeof _j === "symbol" ? _j : _j + ""]);
|
|
77
85
|
if (!renderBusy)
|
|
78
86
|
return state;
|
|
79
|
-
const
|
|
87
|
+
const _k = renderBusy, _l = notebookSlug, notebookBusy = _k[_l], otherNotebooks = __rest(_k, [typeof _l === "symbol" ? _l : _l + ""]);
|
|
80
88
|
if (!notebookBusy)
|
|
81
89
|
return state;
|
|
82
90
|
if (!notebookBusy[cellId])
|
|
83
91
|
return state;
|
|
84
92
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
|
-
const
|
|
93
|
+
const _m = notebookBusy, _o = cellId, cellBusy = _m[_o], otherCells = __rest(_m, [typeof _o === "symbol" ? _o : _o + ""]);
|
|
86
94
|
// remove the render if it's empty
|
|
87
95
|
if (Object.keys(otherCells).length === 0 && Object.keys(otherNotebooks).length === 0) {
|
|
88
96
|
return Object.assign(Object.assign({}, state), { [kind]: otherRenders });
|
|
@@ -112,20 +120,55 @@ function reducer(state, action) {
|
|
|
112
120
|
if (!((_e = state[kind][pageSlug]) === null || _e === void 0 ? void 0 : _e[notebookSlug]))
|
|
113
121
|
return state;
|
|
114
122
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
115
|
-
const
|
|
123
|
+
const _p = state[kind][pageSlug], _q = notebookSlug, notebookBusy = _p[_q], otherNotebooks = __rest(_p, [typeof _q === "symbol" ? _q : _q + ""]);
|
|
116
124
|
if (Object.keys(otherNotebooks).length === 0) {
|
|
117
125
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
118
|
-
const
|
|
126
|
+
const _r = state[kind], _s = pageSlug, renderBusy = _r[_s], otherRenders = __rest(_r, [typeof _s === "symbol" ? _s : _s + ""]);
|
|
119
127
|
return Object.assign(Object.assign({}, state), { [kind]: otherRenders });
|
|
120
128
|
}
|
|
121
129
|
return Object.assign(Object.assign({}, state), { [kind]: Object.assign(Object.assign({}, state[kind]), { [pageSlug]: Object.assign({}, otherNotebooks) }) });
|
|
122
130
|
}
|
|
131
|
+
case 'SET_ERROR': {
|
|
132
|
+
if (!isErrorPayload(action.payload)) {
|
|
133
|
+
console.error('SET_ERROR payload must be an error payload', action.payload);
|
|
134
|
+
return state;
|
|
135
|
+
}
|
|
136
|
+
const { pageSlug, notebookSlug, errors } = action.payload;
|
|
137
|
+
if (!errors) {
|
|
138
|
+
console.error('SET_ERROR payload must have errors', action.payload);
|
|
139
|
+
return state;
|
|
140
|
+
}
|
|
141
|
+
if (state.error[pageSlug])
|
|
142
|
+
return state;
|
|
143
|
+
if ((_f = state.error[pageSlug]) === null || _f === void 0 ? void 0 : _f[notebookSlug])
|
|
144
|
+
return state;
|
|
145
|
+
return Object.assign(Object.assign({}, state), { error: Object.assign(Object.assign({}, state.error), { [pageSlug]: Object.assign(Object.assign({}, state.error[pageSlug]), { [notebookSlug]: errors }) }) });
|
|
146
|
+
}
|
|
147
|
+
case 'CLEAR_ERROR': {
|
|
148
|
+
if (!isErrorPayload(action.payload)) {
|
|
149
|
+
console.error('CLEAR_ERROR payload must be a error payload', action.payload);
|
|
150
|
+
return state;
|
|
151
|
+
}
|
|
152
|
+
const { pageSlug, notebookSlug } = action.payload;
|
|
153
|
+
if (!state.error[pageSlug])
|
|
154
|
+
return state;
|
|
155
|
+
if (!((_g = state.error[pageSlug]) === null || _g === void 0 ? void 0 : _g[notebookSlug]))
|
|
156
|
+
return state;
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
158
|
+
const _t = state.error[pageSlug], _u = notebookSlug, notebookErrors = _t[_u], otherNotebooks = __rest(_t, [typeof _u === "symbol" ? _u : _u + ""]);
|
|
159
|
+
if (Object.keys(otherNotebooks).length > 0) {
|
|
160
|
+
return Object.assign(Object.assign({}, state), { error: Object.assign(Object.assign({}, state.error), { [pageSlug]: Object.assign({}, otherNotebooks) }) });
|
|
161
|
+
}
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
163
|
+
const _v = state.error, _w = pageSlug, renderErrors = _v[_w], otherRenders = __rest(_v, [typeof _w === "symbol" ? _w : _w + ""]);
|
|
164
|
+
return Object.assign(Object.assign({}, state), { error: otherRenders });
|
|
165
|
+
}
|
|
123
166
|
}
|
|
124
167
|
return state;
|
|
125
168
|
}
|
|
126
169
|
exports.reducer = reducer;
|
|
127
170
|
function BusyScopeProvider({ children }) {
|
|
128
|
-
const [state, dispatch] = (0, react_1.useReducer)(reducer, { execute: {}, reset: {} });
|
|
171
|
+
const [state, dispatch] = (0, react_1.useReducer)(reducer, { execute: {}, reset: {}, error: {} });
|
|
129
172
|
const memo = react_1.default.useMemo(() => ({ state, dispatch }), [state]);
|
|
130
173
|
if (typeof window !== 'undefined') {
|
|
131
174
|
window.busyScopeState = memo.state;
|
|
@@ -148,9 +191,43 @@ function useBusyScope() {
|
|
|
148
191
|
const clearCell = (0, react_1.useCallback)((pageSlug, notebookSlug, cellId, kind) => dispatch({ type: 'CLEAR_CELL_BUSY', payload: { pageSlug, notebookSlug, cellId, kind } }), [dispatch]);
|
|
149
192
|
const setNotebook = (0, react_1.useCallback)((pageSlug, notebookSlug, cellIds, kind) => dispatch({ type: 'SET_NOTEBOOK_BUSY', payload: { pageSlug, notebookSlug, cellIds, kind } }), [dispatch]);
|
|
150
193
|
const clearNotebook = (0, react_1.useCallback)((pageSlug, notebookSlug, kind) => dispatch({ type: 'CLEAR_NOTEBOOK_BUSY', payload: { pageSlug, notebookSlug, kind } }), [dispatch]);
|
|
151
|
-
|
|
194
|
+
const setError = (0, react_1.useCallback)((pageSlug, notebookSlug, errors) => dispatch({ type: 'SET_ERROR', payload: { pageSlug, notebookSlug, errors } }), [dispatch]);
|
|
195
|
+
const clearError = (0, react_1.useCallback)((pageSlug, notebookSlug) => dispatch({ type: 'CLEAR_ERROR', payload: { pageSlug, notebookSlug } }), [dispatch]);
|
|
196
|
+
return {
|
|
197
|
+
cell,
|
|
198
|
+
notebook,
|
|
199
|
+
page,
|
|
200
|
+
setCell,
|
|
201
|
+
clearCell,
|
|
202
|
+
setNotebook,
|
|
203
|
+
clearNotebook,
|
|
204
|
+
setError,
|
|
205
|
+
clearError,
|
|
206
|
+
};
|
|
152
207
|
}
|
|
153
208
|
exports.useBusyScope = useBusyScope;
|
|
209
|
+
function useBusyErrors(pageSlug) {
|
|
210
|
+
const context = react_1.default.useContext(BusyScopeContext);
|
|
211
|
+
if (context === undefined) {
|
|
212
|
+
throw new Error('useBusyScope must be used within a BusyScopeProvider');
|
|
213
|
+
}
|
|
214
|
+
const { state, dispatch } = context;
|
|
215
|
+
const clearErrors = () => {
|
|
216
|
+
Object.keys(state.error[pageSlug]).forEach((notebookSlug) => {
|
|
217
|
+
dispatch({ type: 'CLEAR_ERROR', payload: { pageSlug, notebookSlug } });
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
let items;
|
|
221
|
+
if (Object.keys(state.error).length > 0 && state.error[pageSlug]) {
|
|
222
|
+
items = Object.entries(state.error[pageSlug]).map(([notebookSlug, errors]) => ({
|
|
223
|
+
pageSlug,
|
|
224
|
+
notebookSlug,
|
|
225
|
+
errors,
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
return { items, clearErrors };
|
|
229
|
+
}
|
|
230
|
+
exports.useBusyErrors = useBusyErrors;
|
|
154
231
|
function selectCellIsBusy(state, pageSlug, notebookSlug, cellId, kind) {
|
|
155
232
|
var _a, _b;
|
|
156
233
|
return !!((_b = (_a = state[kind][pageSlug]) === null || _a === void 0 ? void 0 : _a[notebookSlug]) === null || _b === void 0 ? void 0 : _b[cellId]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { IdOrKey } from './types';
|
|
3
3
|
import type { IThebeCell } from 'thebe-core';
|
|
4
|
-
import { SourceFileKind } from 'myst-
|
|
4
|
+
import { SourceFileKind } from 'myst-spec-ext';
|
|
5
5
|
export declare function useExecutionScope({ clearOutputsOnExecute, }?: {
|
|
6
6
|
clearOutputsOnExecute?: boolean;
|
|
7
7
|
}): {
|
|
@@ -44,7 +44,7 @@ export declare function useNotebookExecution(id: IdOrKey, clearOutputsOnExecute?
|
|
|
44
44
|
* @param id
|
|
45
45
|
* @returns
|
|
46
46
|
*/
|
|
47
|
-
export declare function useCellExecution(id: IdOrKey): {
|
|
47
|
+
export declare function useCellExecution(id: IdOrKey, clearOutputsOnExecute?: boolean): {
|
|
48
48
|
canCompute: boolean;
|
|
49
49
|
kind: SourceFileKind;
|
|
50
50
|
ready: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/execute/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,KAAK,EAAE,UAAU,EAA8C,MAAM,YAAY,CAAC;AAGzF,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/execute/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,KAAK,EAAE,UAAU,EAA8C,MAAM,YAAY,CAAC;AAGzF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C,wBAAgB,iBAAiB,CAAC,EAChC,qBAA6B,GAC9B,GAAE;IAAE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAAO;;kBAUR,MAAM;yBAuD1B,MAAM;yBAYN,MAAM;oBAzDI,MAAM;;;;;;EAkF9B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,EAAE,qBAAqB,UAAQ;;;;;;;;;;;;;;;;EAgH9E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO,EAAE,qBAAqB,UAAQ;;;;;;;;;;;EAgE1E;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO;;;;EAc/C;AAED,wBAAgB,iBAAiB,YAOhC"}
|
|
@@ -37,7 +37,7 @@ const react_1 = __importStar(require("react"));
|
|
|
37
37
|
const provider_1 = require("./provider");
|
|
38
38
|
const busy_1 = require("./busy");
|
|
39
39
|
const thebe_react_1 = require("thebe-react");
|
|
40
|
-
const
|
|
40
|
+
const myst_spec_ext_1 = require("myst-spec-ext");
|
|
41
41
|
const selectors_1 = require("./selectors");
|
|
42
42
|
function useExecutionScope({ clearOutputsOnExecute = false, } = {}) {
|
|
43
43
|
var _a;
|
|
@@ -60,6 +60,7 @@ function useExecutionScope({ clearOutputsOnExecute = false, } = {}) {
|
|
|
60
60
|
const execute = (slug) => {
|
|
61
61
|
// set busy
|
|
62
62
|
Object.entries(state.pages[slug].scopes).forEach(([notebookSlug, { notebook }]) => {
|
|
63
|
+
busy.clearError(slug, notebookSlug);
|
|
63
64
|
busy.setNotebook(slug, notebookSlug, notebook.code.map((c) => c.id), 'execute');
|
|
64
65
|
});
|
|
65
66
|
if (clearOutputsOnExecute) {
|
|
@@ -104,6 +105,7 @@ function useExecutionScope({ clearOutputsOnExecute = false, } = {}) {
|
|
|
104
105
|
const resetAll = (0, react_1.useCallback)((pageSlug) => {
|
|
105
106
|
var _a;
|
|
106
107
|
Object.entries((_a = state.pages[pageSlug]) === null || _a === void 0 ? void 0 : _a.scopes).forEach(([notebookSlug, { notebook, session }]) => {
|
|
108
|
+
busy.clearError(pageSlug, notebookSlug);
|
|
107
109
|
busy.setNotebook(pageSlug, notebookSlug, notebook.code.map((c) => c.id), 'reset');
|
|
108
110
|
setTimeout(() => {
|
|
109
111
|
var _a;
|
|
@@ -153,6 +155,7 @@ function useNotebookExecution(id, clearOutputsOnExecute = false) {
|
|
|
153
155
|
}
|
|
154
156
|
const execute = () => {
|
|
155
157
|
const nb = (0, selectors_1.selectNotebookForPage)(state, pageSlug, notebookSlug);
|
|
158
|
+
busy.clearError(pageSlug, notebookSlug);
|
|
156
159
|
// set busy
|
|
157
160
|
busy.setNotebook(pageSlug, notebookSlug, nb.code.map((c) => c.id), 'execute');
|
|
158
161
|
if (clearOutputsOnExecute)
|
|
@@ -169,8 +172,11 @@ function useNotebookExecution(id, clearOutputsOnExecute = false) {
|
|
|
169
172
|
// execute all cells on the notebooks
|
|
170
173
|
const execReturns = yield nb.executeAll(true);
|
|
171
174
|
const errs = (0, thebe_react_1.findErrors)(execReturns);
|
|
172
|
-
if (errs != null)
|
|
173
|
-
console.error('
|
|
175
|
+
if (errs != null) {
|
|
176
|
+
console.error('an error occurred during notebook execution');
|
|
177
|
+
busy.setError(pageSlug, notebookSlug, errs);
|
|
178
|
+
busy.clearNotebook(pageSlug, notebookSlug, 'execute');
|
|
179
|
+
}
|
|
174
180
|
config === null || config === void 0 ? void 0 : config.events.off('status', handler);
|
|
175
181
|
}), 100);
|
|
176
182
|
};
|
|
@@ -187,6 +193,7 @@ function useNotebookExecution(id, clearOutputsOnExecute = false) {
|
|
|
187
193
|
*/
|
|
188
194
|
const reset = (0, react_1.useCallback)(() => {
|
|
189
195
|
const nb = (0, selectors_1.selectNotebookForPage)(state, pageSlug, notebookSlug);
|
|
196
|
+
busy.clearError(pageSlug, notebookSlug);
|
|
190
197
|
busy.setNotebook(pageSlug, notebookSlug, nb.code.map((c) => c.id), 'reset');
|
|
191
198
|
setTimeout(() => {
|
|
192
199
|
var _a, _b;
|
|
@@ -215,7 +222,7 @@ exports.useNotebookExecution = useNotebookExecution;
|
|
|
215
222
|
* @param id
|
|
216
223
|
* @returns
|
|
217
224
|
*/
|
|
218
|
-
function useCellExecution(id) {
|
|
225
|
+
function useCellExecution(id, clearOutputsOnExecute = false) {
|
|
219
226
|
var _a, _b, _c, _d;
|
|
220
227
|
const busy = (0, busy_1.useBusyScope)();
|
|
221
228
|
const context = react_1.default.useContext(provider_1.ExecuteScopeContext);
|
|
@@ -233,7 +240,7 @@ function useCellExecution(id) {
|
|
|
233
240
|
cell = notebook === null || notebook === void 0 ? void 0 : notebook.getCellById(cellId);
|
|
234
241
|
}
|
|
235
242
|
const ready = (_b = context.state.pages[context.slug]) === null || _b === void 0 ? void 0 : _b.ready;
|
|
236
|
-
const kind = (_d = (_c = context.state.pages[context.slug]) === null || _c === void 0 ? void 0 : _c.kind) !== null && _d !== void 0 ? _d :
|
|
243
|
+
const kind = (_d = (_c = context.state.pages[context.slug]) === null || _c === void 0 ? void 0 : _c.kind) !== null && _d !== void 0 ? _d : myst_spec_ext_1.SourceFileKind.Article;
|
|
237
244
|
const execute = (0, react_1.useCallback)(() => {
|
|
238
245
|
if (!cell) {
|
|
239
246
|
console.error('no cell found on execute', { pageSlug, notebookSlug, cellId });
|
|
@@ -241,7 +248,8 @@ function useCellExecution(id) {
|
|
|
241
248
|
}
|
|
242
249
|
// set busy
|
|
243
250
|
busy.setCell(pageSlug, notebookSlug, cell.id, 'execute');
|
|
244
|
-
|
|
251
|
+
if (clearOutputsOnExecute)
|
|
252
|
+
cell.clear();
|
|
245
253
|
// let busy state update prior to launching execute
|
|
246
254
|
setTimeout(() => {
|
|
247
255
|
if (!cell)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Dependency } from 'myst-
|
|
2
|
-
import { SourceFileKind } from 'myst-
|
|
1
|
+
import type { Dependency } from 'myst-spec-ext';
|
|
2
|
+
import { SourceFileKind } from 'myst-spec-ext';
|
|
3
3
|
import type { Root } from 'mdast';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import type { ExecuteScopeAction } from './actions';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/execute/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/execute/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,KAAwC,MAAM,OAAO,CAAC;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAc,iBAAiB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AASvE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAC7C,MAAM,EAAE,QAAQ,CAAC;CAClB;AAED,eAAO,MAAM,mBAAmB,6CAA+D,CAAC;AAEhG,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,IAAI,CAAC;IACZ,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;IAC5B,WAAW,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;KAAE,CAAC;CAC1C,CAAC;AA8DF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,QAAQ,EACR,QAAQ,GACT,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAAE,QAAQ,EAAE,eAAe,CAAA;CAAE,CAAC,2CAiGxD"}
|
|
@@ -25,13 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ExecuteScopeProvider = exports.ExecuteScopeContext = void 0;
|
|
27
27
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
|
-
const
|
|
28
|
+
const myst_spec_ext_1 = require("myst-spec-ext");
|
|
29
29
|
const react_1 = __importStar(require("react"));
|
|
30
30
|
const unist_util_select_1 = require("unist-util-select");
|
|
31
31
|
const reducer_1 = require("./reducer");
|
|
32
32
|
const selectors_1 = require("./selectors");
|
|
33
33
|
const leaf_1 = require("./leaf");
|
|
34
|
-
const
|
|
34
|
+
const providers_1 = require("../providers");
|
|
35
35
|
exports.ExecuteScopeContext = react_1.default.createContext(undefined);
|
|
36
36
|
function useScopeNavigate({ contents: { slug, kind, mdast, dependencies }, state, dispatch, }) {
|
|
37
37
|
(0, react_1.useEffect)(() => {
|
|
@@ -83,7 +83,7 @@ function useExecutionScopeFetcher({ slug, state, dispatch, }) {
|
|
|
83
83
|
*/
|
|
84
84
|
function ExecuteScopeProvider({ children, contents, }) {
|
|
85
85
|
var _a;
|
|
86
|
-
const canCompute = (0,
|
|
86
|
+
const canCompute = (0, providers_1.useCanCompute)(contents);
|
|
87
87
|
// compute incoming for first render
|
|
88
88
|
const computables = (0, unist_util_select_1.selectAll)('container > embed', contents.mdast).map((node) => {
|
|
89
89
|
const { key, label, source } = node;
|
|
@@ -100,7 +100,7 @@ function ExecuteScopeProvider({ children, contents, }) {
|
|
|
100
100
|
},
|
|
101
101
|
pages: {
|
|
102
102
|
[contents.slug]: {
|
|
103
|
-
computable: computables.length > 0 || contents.kind ===
|
|
103
|
+
computable: computables.length > 0 || contents.kind === myst_spec_ext_1.SourceFileKind.Notebook,
|
|
104
104
|
kind: contents.kind,
|
|
105
105
|
slug: contents.slug,
|
|
106
106
|
dependencies: (_a = contents.dependencies) !== null && _a !== void 0 ? _a : [],
|
|
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.reducer = void 0;
|
|
15
|
-
const
|
|
15
|
+
const myst_spec_ext_1 = require("myst-spec-ext");
|
|
16
16
|
const actions_1 = require("./actions");
|
|
17
17
|
function reducer(state, action) {
|
|
18
18
|
var _a;
|
|
@@ -30,7 +30,7 @@ function reducer(state, action) {
|
|
|
30
30
|
slug,
|
|
31
31
|
dependencies,
|
|
32
32
|
computables,
|
|
33
|
-
computable: computables.length > 0 || kind ===
|
|
33
|
+
computable: computables.length > 0 || kind === myst_spec_ext_1.SourceFileKind.Notebook,
|
|
34
34
|
ready: false,
|
|
35
35
|
scopes: {},
|
|
36
36
|
} }) });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../../src/execute/selectors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE9D,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM;;EAE5E;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,oDAGrB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,WAExE;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,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