@myst-theme/jupyter 0.3.3 → 0.3.4
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/ConnectionStatusTray.d.ts.map +1 -1
- package/dist/cjs/ConnectionStatusTray.js +6 -4
- package/dist/cjs/ErrorTray.d.ts +5 -0
- package/dist/cjs/ErrorTray.d.ts.map +1 -0
- package/dist/cjs/ErrorTray.js +34 -0
- package/dist/cjs/controls/ArticleCellControls.d.ts +10 -0
- package/dist/cjs/controls/ArticleCellControls.d.ts.map +1 -0
- package/dist/cjs/controls/ArticleCellControls.js +33 -0
- package/dist/cjs/controls/Buttons.d.ts +47 -0
- package/dist/cjs/controls/Buttons.d.ts.map +1 -0
- package/dist/cjs/controls/Buttons.js +70 -0
- package/dist/cjs/controls/NotebookCellControls.d.ts +10 -0
- package/dist/cjs/controls/NotebookCellControls.d.ts.map +1 -0
- package/dist/cjs/controls/NotebookCellControls.js +27 -0
- package/dist/cjs/controls/NotebookToolbar.d.ts +4 -0
- package/dist/cjs/controls/NotebookToolbar.d.ts.map +1 -0
- package/dist/cjs/controls/NotebookToolbar.js +47 -0
- package/dist/cjs/controls/Spinner.d.ts +4 -0
- package/dist/cjs/controls/Spinner.d.ts.map +1 -0
- package/dist/cjs/controls/Spinner.js +8 -0
- package/dist/cjs/controls/index.d.ts +5 -0
- package/dist/cjs/controls/index.d.ts.map +1 -0
- package/dist/cjs/controls/index.js +20 -0
- package/dist/cjs/execute/actions.d.ts +55 -0
- package/dist/cjs/execute/actions.d.ts.map +1 -0
- package/dist/cjs/execute/actions.js +49 -0
- package/dist/cjs/execute/busy.d.ts +74 -0
- package/dist/cjs/execute/busy.d.ts.map +1 -0
- package/dist/cjs/execute/busy.js +182 -0
- package/dist/cjs/execute/hooks.d.ts +62 -0
- package/dist/cjs/execute/hooks.d.ts.map +1 -0
- package/dist/cjs/execute/hooks.js +308 -0
- package/dist/cjs/execute/index.d.ts +7 -0
- package/dist/cjs/execute/index.d.ts.map +1 -0
- package/dist/cjs/execute/index.js +22 -0
- package/dist/cjs/execute/leaf.d.ts +26 -0
- package/dist/cjs/execute/leaf.d.ts.map +1 -0
- package/dist/cjs/execute/leaf.js +154 -0
- package/dist/cjs/execute/provider.d.ts +29 -0
- package/dist/cjs/execute/provider.d.ts.map +1 -0
- package/dist/cjs/execute/provider.js +126 -0
- package/dist/cjs/execute/reducer.d.ts +4 -0
- package/dist/cjs/execute/reducer.d.ts.map +1 -0
- package/dist/cjs/execute/reducer.js +136 -0
- package/dist/cjs/execute/selectors.d.ts +22 -0
- package/dist/cjs/execute/selectors.d.ts.map +1 -0
- package/dist/cjs/execute/selectors.js +89 -0
- package/dist/cjs/execute/types.d.ts +49 -0
- package/dist/cjs/execute/types.d.ts.map +1 -0
- package/dist/cjs/execute/types.js +2 -0
- package/dist/cjs/execute/utils.d.ts +23 -0
- package/dist/cjs/execute/utils.d.ts.map +1 -0
- package/dist/cjs/execute/utils.js +62 -0
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/jupyter.d.ts.map +1 -1
- package/dist/cjs/jupyter.js +19 -17
- package/dist/cjs/output.d.ts +1 -1
- package/dist/cjs/output.d.ts.map +1 -1
- package/dist/cjs/output.js +7 -4
- package/dist/cjs/providers.d.ts +1 -48
- package/dist/cjs/providers.d.ts.map +1 -1
- package/dist/cjs/providers.js +4 -155
- package/dist/esm/ConnectionStatusTray.d.ts.map +1 -1
- package/dist/esm/ConnectionStatusTray.js +7 -5
- package/dist/esm/ErrorTray.d.ts +5 -0
- package/dist/esm/ErrorTray.d.ts.map +1 -0
- package/dist/esm/ErrorTray.js +30 -0
- package/dist/esm/controls/ArticleCellControls.d.ts +10 -0
- package/dist/esm/controls/ArticleCellControls.d.ts.map +1 -0
- package/dist/esm/controls/ArticleCellControls.js +27 -0
- package/dist/esm/controls/Buttons.d.ts +47 -0
- package/dist/esm/controls/Buttons.d.ts.map +1 -0
- package/dist/esm/controls/Buttons.js +57 -0
- package/dist/esm/controls/NotebookCellControls.d.ts +10 -0
- package/dist/esm/controls/NotebookCellControls.d.ts.map +1 -0
- package/dist/esm/controls/NotebookCellControls.js +21 -0
- package/dist/esm/controls/NotebookToolbar.d.ts +4 -0
- package/dist/esm/controls/NotebookToolbar.d.ts.map +1 -0
- package/dist/esm/controls/NotebookToolbar.js +40 -0
- package/dist/esm/controls/Spinner.d.ts +4 -0
- package/dist/esm/controls/Spinner.d.ts.map +1 -0
- package/dist/esm/controls/Spinner.js +4 -0
- package/dist/esm/controls/index.d.ts +5 -0
- package/dist/esm/controls/index.d.ts.map +1 -0
- package/dist/esm/controls/index.js +4 -0
- package/dist/esm/execute/actions.d.ts +55 -0
- package/dist/esm/execute/actions.d.ts.map +1 -0
- package/dist/esm/execute/actions.js +38 -0
- package/dist/esm/execute/busy.d.ts +74 -0
- package/dist/esm/execute/busy.d.ts.map +1 -0
- package/dist/esm/execute/busy.js +150 -0
- package/dist/esm/execute/hooks.d.ts +62 -0
- package/dist/esm/execute/hooks.d.ts.map +1 -0
- package/dist/esm/execute/hooks.js +277 -0
- package/dist/esm/execute/index.d.ts +7 -0
- package/dist/esm/execute/index.d.ts.map +1 -0
- package/dist/esm/execute/index.js +6 -0
- package/dist/esm/execute/leaf.d.ts +26 -0
- package/dist/esm/execute/leaf.d.ts.map +1 -0
- package/dist/esm/execute/leaf.js +147 -0
- package/dist/esm/execute/provider.d.ts +29 -0
- package/dist/esm/execute/provider.d.ts.map +1 -0
- package/dist/esm/execute/provider.js +99 -0
- package/dist/esm/execute/reducer.d.ts +4 -0
- package/dist/esm/execute/reducer.d.ts.map +1 -0
- package/dist/esm/execute/reducer.js +132 -0
- package/dist/esm/execute/selectors.d.ts +22 -0
- package/dist/esm/execute/selectors.d.ts.map +1 -0
- package/dist/esm/execute/selectors.js +77 -0
- package/dist/esm/execute/types.d.ts +49 -0
- package/dist/esm/execute/types.d.ts.map +1 -0
- package/dist/esm/execute/types.js +1 -0
- package/dist/esm/execute/utils.d.ts +23 -0
- package/dist/esm/execute/utils.d.ts.map +1 -0
- package/dist/esm/execute/utils.js +58 -0
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/jupyter.d.ts.map +1 -1
- package/dist/esm/jupyter.js +17 -15
- package/dist/esm/output.d.ts +1 -1
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +8 -5
- package/dist/esm/providers.d.ts +1 -48
- package/dist/esm/providers.d.ts.map +1 -1
- package/dist/esm/providers.js +2 -126
- package/dist/types/ConnectionStatusTray.d.ts.map +1 -1
- package/dist/types/ErrorTray.d.ts +5 -0
- package/dist/types/ErrorTray.d.ts.map +1 -0
- package/dist/types/controls/ArticleCellControls.d.ts +10 -0
- package/dist/types/controls/ArticleCellControls.d.ts.map +1 -0
- package/dist/types/controls/Buttons.d.ts +47 -0
- package/dist/types/controls/Buttons.d.ts.map +1 -0
- package/dist/types/controls/NotebookCellControls.d.ts +10 -0
- package/dist/types/controls/NotebookCellControls.d.ts.map +1 -0
- package/dist/types/controls/NotebookToolbar.d.ts +4 -0
- package/dist/types/controls/NotebookToolbar.d.ts.map +1 -0
- package/dist/types/controls/Spinner.d.ts +4 -0
- package/dist/types/controls/Spinner.d.ts.map +1 -0
- package/dist/types/controls/index.d.ts +5 -0
- package/dist/types/controls/index.d.ts.map +1 -0
- package/dist/types/execute/actions.d.ts +55 -0
- package/dist/types/execute/actions.d.ts.map +1 -0
- package/dist/types/execute/busy.d.ts +74 -0
- package/dist/types/execute/busy.d.ts.map +1 -0
- package/dist/types/execute/hooks.d.ts +62 -0
- package/dist/types/execute/hooks.d.ts.map +1 -0
- package/dist/types/execute/index.d.ts +7 -0
- package/dist/types/execute/index.d.ts.map +1 -0
- package/dist/types/execute/leaf.d.ts +26 -0
- package/dist/types/execute/leaf.d.ts.map +1 -0
- package/dist/types/execute/provider.d.ts +29 -0
- package/dist/types/execute/provider.d.ts.map +1 -0
- package/dist/types/execute/reducer.d.ts +4 -0
- package/dist/types/execute/reducer.d.ts.map +1 -0
- package/dist/types/execute/selectors.d.ts +22 -0
- package/dist/types/execute/selectors.d.ts.map +1 -0
- package/dist/types/execute/types.d.ts +49 -0
- package/dist/types/execute/types.d.ts.map +1 -0
- package/dist/types/execute/utils.d.ts +23 -0
- package/dist/types/execute/utils.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -1
- 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/dist/types/providers.d.ts +1 -48
- package/dist/types/providers.d.ts.map +1 -1
- package/package.json +9 -8
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GenericParent } from 'myst-common';
|
|
2
|
+
import type { Config, IRenderMimeRegistry, ThebeCore } from 'thebe-core';
|
|
3
|
+
import type { IdKeyMap } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Use the mdast to create a ThebeNotebook from the mdast tree of a notebook.
|
|
6
|
+
* This is intended to be used to create an independent ThebeNotebook instance
|
|
7
|
+
* for each notebook in a rendering context.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: there is no need to scope the keys at this point, as the ThebeNotebook
|
|
10
|
+
* instance will be scoped to the render context. All underlying cells will be
|
|
11
|
+
* identified by keys from the mdast - so there may be duplicate ids between different
|
|
12
|
+
* notebook instances, but that is ok as they came from the same mdast which is readonly.
|
|
13
|
+
*
|
|
14
|
+
* @param core
|
|
15
|
+
* @param config
|
|
16
|
+
* @param pageSlug - slug identifying the render context used for key decoration
|
|
17
|
+
* @param mdast - the notebook mdast
|
|
18
|
+
* @param idkmap - map of scoped block keys to keys for code and output cells
|
|
19
|
+
* @param rendermime
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function notebookFromMdast(core: ThebeCore, config: Config, pageSlug: string, notebookSlug: string, mdast: GenericParent, idkmap: IdKeyMap, rendermime: IRenderMimeRegistry): import("thebe-core/dist/types/notebook").default;
|
|
23
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/execute/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,SAAS,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,QAAQ,EAChB,UAAU,EAAE,mBAAmB,oDAoDhC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.notebookFromMdast = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Use the mdast to create a ThebeNotebook from the mdast tree of a notebook.
|
|
6
|
+
* This is intended to be used to create an independent ThebeNotebook instance
|
|
7
|
+
* for each notebook in a rendering context.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: there is no need to scope the keys at this point, as the ThebeNotebook
|
|
10
|
+
* instance will be scoped to the render context. All underlying cells will be
|
|
11
|
+
* identified by keys from the mdast - so there may be duplicate ids between different
|
|
12
|
+
* notebook instances, but that is ok as they came from the same mdast which is readonly.
|
|
13
|
+
*
|
|
14
|
+
* @param core
|
|
15
|
+
* @param config
|
|
16
|
+
* @param pageSlug - slug identifying the render context used for key decoration
|
|
17
|
+
* @param mdast - the notebook mdast
|
|
18
|
+
* @param idkmap - map of scoped block keys to keys for code and output cells
|
|
19
|
+
* @param rendermime
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
function notebookFromMdast(core, config, pageSlug, notebookSlug, mdast, idkmap, rendermime) {
|
|
23
|
+
// note the notebooks slug is used as the notebook id, this means accross pages
|
|
24
|
+
// mulitple notebooks with the same slug will be present but scoped to different pages
|
|
25
|
+
// the busyScope mecahnism relies on the notebookSlug as id
|
|
26
|
+
const notebook = new core.ThebeNotebook(notebookSlug, config, rendermime);
|
|
27
|
+
// no metadata included in mdast yet
|
|
28
|
+
//Object.assign(notebook.metadata, ipynb.metadata);
|
|
29
|
+
notebook.cells = mdast.children.map((block) => {
|
|
30
|
+
var _a, _b, _c;
|
|
31
|
+
if (block.type !== 'block')
|
|
32
|
+
console.warn(`Unexpected block type ${block.type}`);
|
|
33
|
+
if (block.children.length == 2 && block.children[0].type === 'code') {
|
|
34
|
+
const [codeCell, output] = block.children;
|
|
35
|
+
// use the block.key to identify the cell but maintain a mapping
|
|
36
|
+
// to allow code or output keys to look up cells and refs and idenifity
|
|
37
|
+
// the cell in the correct notebook
|
|
38
|
+
const target = {
|
|
39
|
+
pageSlug,
|
|
40
|
+
notebookSlug,
|
|
41
|
+
cellId: block.key,
|
|
42
|
+
};
|
|
43
|
+
idkmap[block.key] = target;
|
|
44
|
+
idkmap[codeCell.key] = target;
|
|
45
|
+
idkmap[output.key] = target;
|
|
46
|
+
// include block labels to enable lookup by from embedded blocks
|
|
47
|
+
if (block.label)
|
|
48
|
+
idkmap[block.label] = target;
|
|
49
|
+
if (block.identifier)
|
|
50
|
+
idkmap[block.identifier] = target;
|
|
51
|
+
return new core.ThebeCell(target.cellId, notebook.id, (_a = codeCell.value) !== null && _a !== void 0 ? _a : '', config, (_b = block.data) !== null && _b !== void 0 ? _b : {}, notebook.rendermime);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// assume content - concatenate it
|
|
55
|
+
// TODO inject cell metadata
|
|
56
|
+
const cell = new core.ThebeNonExecutableCell(block.key, notebook.id, block.children.reduce((acc, child) => { var _a; return acc + '\n' + ((_a = child.value) !== null && _a !== void 0 ? _a : ''); }, ''), (_c = block.data) !== null && _c !== void 0 ? _c : {}, notebook.rendermime);
|
|
57
|
+
return cell;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return notebook;
|
|
61
|
+
}
|
|
62
|
+
exports.notebookFromMdast = notebookFromMdast;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -3,7 +3,10 @@ declare const OUTPUT_RENDERERS: {
|
|
|
3
3
|
output: typeof Output;
|
|
4
4
|
};
|
|
5
5
|
export * from './BinderBadge';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './ErrorTray';
|
|
7
7
|
export * from './ConnectionStatusTray';
|
|
8
|
+
export * from './providers';
|
|
9
|
+
export * from './execute';
|
|
10
|
+
export * from './controls';
|
|
8
11
|
export default OUTPUT_RENDERERS;
|
|
9
12
|
//# sourceMappingURL=index.d.ts.map
|
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;;CAErB,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;
|
|
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;;CAErB,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
|
@@ -19,6 +19,9 @@ const OUTPUT_RENDERERS = {
|
|
|
19
19
|
output: output_1.Output,
|
|
20
20
|
};
|
|
21
21
|
__exportStar(require("./BinderBadge"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./ErrorTray"), exports);
|
|
23
23
|
__exportStar(require("./ConnectionStatusTray"), exports);
|
|
24
|
+
__exportStar(require("./providers"), exports);
|
|
25
|
+
__exportStar(require("./execute"), exports);
|
|
26
|
+
__exportStar(require("./controls"), exports);
|
|
24
27
|
exports.default = OUTPUT_RENDERERS;
|
|
@@ -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;AA6D3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAkD1D,CAAC"}
|
package/dist/cjs/jupyter.js
CHANGED
|
@@ -29,30 +29,32 @@ const react_1 = __importStar(require("react"));
|
|
|
29
29
|
const hooks_1 = require("./hooks");
|
|
30
30
|
const nbtx_1 = require("nbtx");
|
|
31
31
|
const convertImages_1 = require("./convertImages");
|
|
32
|
-
const providers_1 = require("./providers");
|
|
33
32
|
const myst_common_1 = require("myst-common");
|
|
34
|
-
const
|
|
33
|
+
const providers_1 = require("@myst-theme/providers");
|
|
35
34
|
const thebe_react_1 = require("thebe-react");
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const execute_1 = require("./execute");
|
|
36
|
+
function ActiveOutputRenderer({ id, initialData }) {
|
|
37
|
+
const exec = (0, execute_1.useCellExecution)(id);
|
|
38
38
|
const ref = (0, react_1.useRef)(null);
|
|
39
39
|
(0, react_1.useEffect)(() => {
|
|
40
40
|
var _a;
|
|
41
41
|
if (!ref.current || !(exec === null || exec === void 0 ? void 0 : exec.cell)) {
|
|
42
|
-
console.debug(`No cell ref available for cell ${(_a = exec === null || exec === void 0 ? void 0 : exec.cell) === null || _a === void 0 ? void 0 : _a.id}`);
|
|
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;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
console.debug(`Attaching cell ${exec.cell.id} to DOM at:`, {
|
|
45
|
+
const verb = exec.cell.isAttachedToDOM ? 'reattaching' : 'attaching';
|
|
46
|
+
console.debug(`${verb} cell ${exec.cell.id} to DOM at:`, {
|
|
50
47
|
el: ref.current,
|
|
51
48
|
connected: ref.current.isConnected,
|
|
52
|
-
data,
|
|
49
|
+
data: initialData,
|
|
53
50
|
});
|
|
54
51
|
exec.cell.attachToDOM(ref.current);
|
|
55
|
-
exec.cell.
|
|
52
|
+
if (exec.cell.executionCount == null) {
|
|
53
|
+
exec.cell.initOutputs(initialData);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
exec.cell.refresh();
|
|
57
|
+
}
|
|
56
58
|
}, [ref === null || ref === void 0 ? void 0 : ref.current, exec === null || exec === void 0 ? void 0 : exec.cell]);
|
|
57
59
|
return (0, jsx_runtime_1.jsx)("div", { ref: ref, "data-thebe-active-ref": "true", className: "relative" });
|
|
58
60
|
}
|
|
@@ -68,12 +70,12 @@ function PassiveOutputRenderer({ id, data, core, kind, }) {
|
|
|
68
70
|
return (0, jsx_runtime_1.jsx)("div", { ref: ref, "data-thebe-passive-ref": "true" });
|
|
69
71
|
}
|
|
70
72
|
exports.JupyterOutputs = react_1.default.memo(({ id, outputs }) => {
|
|
71
|
-
var _a;
|
|
72
73
|
const { core, load } = (0, thebe_react_1.useThebeLoader)();
|
|
73
|
-
const { inCrossRef } = (0,
|
|
74
|
+
const { inCrossRef } = (0, providers_1.useXRefState)();
|
|
74
75
|
const { data, error } = (0, hooks_1.useFetchAnyTruncatedContent)(outputs);
|
|
75
76
|
const [fullOutputs, setFullOutputs] = (0, react_1.useState)(null);
|
|
76
|
-
const exec =
|
|
77
|
+
// const exec = useNotebookCellExecution(id);
|
|
78
|
+
const exec = (0, execute_1.useCellExecution)(id);
|
|
77
79
|
(0, react_1.useEffect)(() => {
|
|
78
80
|
if (core)
|
|
79
81
|
return;
|
|
@@ -92,7 +94,7 @@ exports.JupyterOutputs = react_1.default.memo(({ id, outputs }) => {
|
|
|
92
94
|
return (0, jsx_runtime_1.jsxs)("div", { className: "text-red-500", children: ["Error rendering output: ", error.message] });
|
|
93
95
|
}
|
|
94
96
|
if (!inCrossRef && (exec === null || exec === void 0 ? void 0 : exec.ready)) {
|
|
95
|
-
return ((0, jsx_runtime_1.jsxs)("div", { children: [!fullOutputs && (0, jsx_runtime_1.jsx)("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && (0, jsx_runtime_1.jsx)(ActiveOutputRenderer, { id: id,
|
|
97
|
+
return ((0, jsx_runtime_1.jsxs)("div", { children: [!fullOutputs && (0, jsx_runtime_1.jsx)("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && (0, jsx_runtime_1.jsx)(ActiveOutputRenderer, { id: id, initialData: fullOutputs }, id)] }));
|
|
96
98
|
}
|
|
97
|
-
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:
|
|
99
|
+
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 }))] }));
|
|
98
100
|
});
|
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,KAAK,
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,MAAM,CAAC;AAY/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;AAwDD,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,2CAYvC"}
|
package/dist/cjs/output.js
CHANGED
|
@@ -5,12 +5,14 @@ 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");
|
|
8
9
|
const nbtx_1 = require("nbtx");
|
|
9
10
|
const classnames_1 = __importDefault(require("classnames"));
|
|
10
11
|
const safe_1 = require("./safe");
|
|
11
12
|
const jupyter_1 = require("./jupyter");
|
|
12
|
-
const providers_1 = require("./providers");
|
|
13
13
|
const react_1 = require("react");
|
|
14
|
+
const execute_1 = require("./execute");
|
|
15
|
+
const ArticleCellControls_1 = require("./controls/ArticleCellControls");
|
|
14
16
|
exports.DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);
|
|
15
17
|
exports.DIRECT_MIME_TYPES = new Set([
|
|
16
18
|
nbtx_1.KnownCellOutputMimeTypes.TextPlain,
|
|
@@ -33,7 +35,7 @@ function allOutputsAreSafe(outputs, directOutputTypes, directMimeTypes) {
|
|
|
33
35
|
}
|
|
34
36
|
exports.allOutputsAreSafe = allOutputsAreSafe;
|
|
35
37
|
function JupyterOutput({ nodeKey, nodeType, identifier, data, align, }) {
|
|
36
|
-
const ready = (0,
|
|
38
|
+
const { kind, ready } = (0, execute_1.useCellExecution)(nodeKey);
|
|
37
39
|
const outputs = data;
|
|
38
40
|
const allSafe = (0, react_1.useMemo)(() => allOutputsAreSafe(outputs, exports.DIRECT_OUTPUT_TYPES, exports.DIRECT_MIME_TYPES), [outputs]);
|
|
39
41
|
let component;
|
|
@@ -43,11 +45,12 @@ function JupyterOutput({ nodeKey, nodeType, identifier, data, align, }) {
|
|
|
43
45
|
else {
|
|
44
46
|
component = (0, jsx_runtime_1.jsx)(jupyter_1.JupyterOutputs, { id: nodeKey, outputs: outputs });
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
const showControls = kind === myst_common_1.SourceFileKind.Article;
|
|
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', {
|
|
47
50
|
'text-left': !align || align === 'left',
|
|
48
51
|
'text-center': align === 'center',
|
|
49
52
|
'text-right': align === 'right',
|
|
50
|
-
}), children: component }));
|
|
53
|
+
}), children: [showControls && ((0, jsx_runtime_1.jsx)("div", { className: "sticky top-[60px]", children: (0, jsx_runtime_1.jsxs)("div", { className: "absolute -top-[28px] md:top-[30px] right-0 md:-right-[28px]", children: [(0, jsx_runtime_1.jsx)(ArticleCellControls_1.ArticleStatusBadge, { id: nodeKey }), (0, jsx_runtime_1.jsx)(ArticleCellControls_1.ArticleRunNotebook, { id: nodeKey }), (0, jsx_runtime_1.jsx)(ArticleCellControls_1.ArticleResetNotebook, { id: nodeKey })] }) })), component] }));
|
|
51
54
|
}
|
|
52
55
|
function Output(node) {
|
|
53
56
|
// Note, NodeRenderer's can't have hooks in it directly!
|
package/dist/cjs/providers.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { SourceFileKind } from 'myst-common';
|
|
1
|
+
import type { SourceFileKind } from 'myst-common';
|
|
3
2
|
import React from 'react';
|
|
4
|
-
import type { Config, IRenderMimeRegistry, IThebeCell, IThebeCellExecuteReturn, ThebeCore, ThebeNotebook } from 'thebe-core';
|
|
5
|
-
import type { IThebeNotebookError, NotebookExecuteOptions } from 'thebe-react';
|
|
6
3
|
import type { Root } from 'mdast';
|
|
7
4
|
export declare function useComputeOptions(): {
|
|
8
5
|
canCompute: boolean;
|
|
@@ -23,48 +20,4 @@ export type PartialPage = {
|
|
|
23
20
|
slug: string;
|
|
24
21
|
mdast: Root;
|
|
25
22
|
};
|
|
26
|
-
export declare function notebookFromMdast(core: ThebeCore, config: Config, mdast: GenericParent, idkMap: Record<string, string>, rendermime: IRenderMimeRegistry): ThebeNotebook;
|
|
27
|
-
type IdKeyMap = Record<string, string>;
|
|
28
|
-
interface NotebookContextType {
|
|
29
|
-
kind: SourceFileKind;
|
|
30
|
-
ready: boolean;
|
|
31
|
-
attached: boolean;
|
|
32
|
-
executing: boolean;
|
|
33
|
-
executed: boolean;
|
|
34
|
-
errors: IThebeNotebookError[] | null;
|
|
35
|
-
executeAll: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
|
|
36
|
-
executeSome: (predicate: (cell: IThebeCell) => boolean, options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
|
|
37
|
-
notebook: ThebeNotebook | undefined;
|
|
38
|
-
idkMap: IdKeyMap;
|
|
39
|
-
restart: () => Promise<void>;
|
|
40
|
-
clear: () => void;
|
|
41
|
-
}
|
|
42
|
-
export declare function NotebookProvider({ siteConfig, page, children, }: React.PropsWithChildren<{
|
|
43
|
-
siteConfig: boolean;
|
|
44
|
-
page: PartialPage;
|
|
45
|
-
}>): import("react/jsx-runtime").JSX.Element;
|
|
46
|
-
export declare function useHasNotebookProvider(): boolean;
|
|
47
|
-
export declare function useMDASTNotebook(): NotebookContextType | undefined;
|
|
48
|
-
export declare function useNotebookExecution(): {
|
|
49
|
-
ready: boolean;
|
|
50
|
-
attached: boolean;
|
|
51
|
-
executing: boolean;
|
|
52
|
-
executed: boolean;
|
|
53
|
-
errors: IThebeNotebookError[] | null;
|
|
54
|
-
execute: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
|
|
55
|
-
notebook: ThebeNotebook | undefined;
|
|
56
|
-
clear: () => void;
|
|
57
|
-
} | undefined;
|
|
58
|
-
export declare function useReadyToExecute(): boolean;
|
|
59
|
-
export declare function useNotebookCellExecution(id: string): {
|
|
60
|
-
kind: SourceFileKind;
|
|
61
|
-
ready: boolean;
|
|
62
|
-
cell: IThebeCell | undefined;
|
|
63
|
-
executing: boolean;
|
|
64
|
-
notebookIsExecuting: boolean;
|
|
65
|
-
execute: (options?: NotebookExecuteOptions) => Promise<(IThebeCellExecuteReturn | null)[]>;
|
|
66
|
-
clear: () => void | undefined;
|
|
67
|
-
notebook: ThebeNotebook;
|
|
68
|
-
} | undefined;
|
|
69
|
-
export {};
|
|
70
23
|
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/providers.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/providers.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAIlC,wBAAgB,iBAAiB;;;;;;;;;;EAwBhC;AAED,wBAAgB,6BAA6B,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,iBAAiB,2CAalF;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,IAAI,CAAC;CACb,CAAC"}
|
package/dist/cjs/providers.js
CHANGED
|
@@ -1,41 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
4
|
};
|
|
34
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
6
|
+
exports.ConfiguredThebeServerProvider = exports.useComputeOptions = void 0;
|
|
36
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
37
|
-
const
|
|
38
|
-
const react_1 = __importStar(require("react"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
39
9
|
const thebe_react_1 = require("thebe-react");
|
|
40
10
|
const providers_1 = require("@myst-theme/providers");
|
|
41
11
|
const utils_1 = require("./utils");
|
|
@@ -67,124 +37,3 @@ function ConfiguredThebeServerProvider({ children }) {
|
|
|
67
37
|
return ((0, jsx_runtime_1.jsx)(thebe_react_1.ThebeServerProvider, { connect: false, options: thebe, useBinder: thebe === null || thebe === void 0 ? void 0 : thebe.useBinder, useJupyterLite: thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite, children: children }));
|
|
68
38
|
}
|
|
69
39
|
exports.ConfiguredThebeServerProvider = ConfiguredThebeServerProvider;
|
|
70
|
-
function notebookFromMdast(core, config, mdast, idkMap, rendermime) {
|
|
71
|
-
const notebook = new core.ThebeNotebook(mdast.key, config, rendermime);
|
|
72
|
-
// no metadata included in mdast yet
|
|
73
|
-
// Object.assign(notebook.metadata, ipynb.metadata);
|
|
74
|
-
notebook.cells = mdast.children.map((block) => {
|
|
75
|
-
var _a, _b, _c, _d, _e;
|
|
76
|
-
if (block.type !== 'block')
|
|
77
|
-
console.warn(`Unexpected block type ${block.type}`);
|
|
78
|
-
if (block.children && block.children.length == 2 && block.children[0].type === 'code') {
|
|
79
|
-
const [codeCell, output] = block.children;
|
|
80
|
-
// use the block.key to identify the cell but maintain a mapping
|
|
81
|
-
// to allow code or output keys to look up cells and refs
|
|
82
|
-
idkMap[block.key] = block.key;
|
|
83
|
-
idkMap[codeCell.key] = block.key;
|
|
84
|
-
idkMap[output.key] = block.key;
|
|
85
|
-
return new core.ThebeCell(block.key, notebook.id, (_a = codeCell.value) !== null && _a !== void 0 ? _a : '', config, (_b = block.data) !== null && _b !== void 0 ? _b : {}, notebook.rendermime);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
// assume content - concatenate it
|
|
89
|
-
// TODO inject cell metadata
|
|
90
|
-
const cell = new core.ThebeNonExecutableCell(block.key, notebook.id, (_d = (_c = block.children) === null || _c === void 0 ? void 0 : _c.reduce((acc, child) => { var _a; return acc + '\n' + ((_a = child.value) !== null && _a !== void 0 ? _a : ''); }, '')) !== null && _d !== void 0 ? _d : '', (_e = block.data) !== null && _e !== void 0 ? _e : {}, notebook.rendermime);
|
|
91
|
-
return cell;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return notebook;
|
|
95
|
-
}
|
|
96
|
-
exports.notebookFromMdast = notebookFromMdast;
|
|
97
|
-
const NotebookContext = react_1.default.createContext(undefined);
|
|
98
|
-
function NotebookProvider({ siteConfig, page, children, }) {
|
|
99
|
-
// so at some point this gets the whole site config and can
|
|
100
|
-
// be use to lookup notebooks and recover ThebeNotebooks that
|
|
101
|
-
// can be used to execute notebook pages or blocks in articles
|
|
102
|
-
const { core } = (0, thebe_react_1.useThebeLoader)();
|
|
103
|
-
const { config } = (0, thebe_react_1.useThebeConfig)();
|
|
104
|
-
const rendermime = (0, thebe_react_1.useRenderMimeRegistry)();
|
|
105
|
-
const { ready, attached, executing, executed, errors, executeAll, executeSome, clear, session, notebook, setNotebook, } = (0, thebe_react_1.useNotebookBase)();
|
|
106
|
-
const idkMap = (0, react_1.useRef)({});
|
|
107
|
-
(0, react_1.useEffect)(() => {
|
|
108
|
-
if (!core || !config)
|
|
109
|
-
return;
|
|
110
|
-
idkMap.current = {};
|
|
111
|
-
if (page.kind === myst_common_1.SourceFileKind.Notebook) {
|
|
112
|
-
const nb = notebookFromMdast(core, config, page.mdast, idkMap.current, rendermime);
|
|
113
|
-
setNotebook(nb);
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
// TODO will need do article relative notebook loading as appropriate once that is supported
|
|
117
|
-
setNotebook(undefined);
|
|
118
|
-
}
|
|
119
|
-
}, [core, config, page]);
|
|
120
|
-
return ((0, jsx_runtime_1.jsx)(NotebookContext.Provider, { value: {
|
|
121
|
-
kind: page.kind,
|
|
122
|
-
ready,
|
|
123
|
-
attached,
|
|
124
|
-
executing,
|
|
125
|
-
executed,
|
|
126
|
-
errors,
|
|
127
|
-
executeAll,
|
|
128
|
-
executeSome,
|
|
129
|
-
notebook,
|
|
130
|
-
idkMap: idkMap.current,
|
|
131
|
-
restart: () => { var _a; return (_a = session === null || session === void 0 ? void 0 : session.restart()) !== null && _a !== void 0 ? _a : Promise.resolve(); },
|
|
132
|
-
clear,
|
|
133
|
-
}, children: children }));
|
|
134
|
-
}
|
|
135
|
-
exports.NotebookProvider = NotebookProvider;
|
|
136
|
-
function useHasNotebookProvider() {
|
|
137
|
-
const notebookState = (0, react_1.useContext)(NotebookContext);
|
|
138
|
-
return notebookState !== undefined;
|
|
139
|
-
}
|
|
140
|
-
exports.useHasNotebookProvider = useHasNotebookProvider;
|
|
141
|
-
function useMDASTNotebook() {
|
|
142
|
-
const notebookState = (0, react_1.useContext)(NotebookContext);
|
|
143
|
-
return notebookState;
|
|
144
|
-
}
|
|
145
|
-
exports.useMDASTNotebook = useMDASTNotebook;
|
|
146
|
-
function useNotebookExecution() {
|
|
147
|
-
const notebookState = (0, react_1.useContext)(NotebookContext);
|
|
148
|
-
if (!notebookState)
|
|
149
|
-
return undefined;
|
|
150
|
-
const { ready, attached, executing, executed, errors, executeAll, notebook, clear } = notebookState;
|
|
151
|
-
return { ready, attached, executing, executed, errors, execute: executeAll, notebook, clear };
|
|
152
|
-
}
|
|
153
|
-
exports.useNotebookExecution = useNotebookExecution;
|
|
154
|
-
function useReadyToExecute() {
|
|
155
|
-
var _a;
|
|
156
|
-
const notebookState = (0, react_1.useContext)(NotebookContext);
|
|
157
|
-
return (_a = notebookState === null || notebookState === void 0 ? void 0 : notebookState.ready) !== null && _a !== void 0 ? _a : false;
|
|
158
|
-
}
|
|
159
|
-
exports.useReadyToExecute = useReadyToExecute;
|
|
160
|
-
function useNotebookCellExecution(id) {
|
|
161
|
-
// setup a cell only executing state
|
|
162
|
-
const [executing, setExecuting] = (0, react_1.useState)(false);
|
|
163
|
-
const notebookState = (0, react_1.useContext)(NotebookContext);
|
|
164
|
-
if (!notebookState)
|
|
165
|
-
return undefined;
|
|
166
|
-
const { kind, ready, notebook, executing: notebookIsExecuting, executeSome, idkMap, } = notebookState;
|
|
167
|
-
const cellId = idkMap[id];
|
|
168
|
-
function execute(options) {
|
|
169
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
setExecuting(true);
|
|
171
|
-
const execReturn = yield executeSome((cell) => cell.id === cellId, options);
|
|
172
|
-
setExecuting(false);
|
|
173
|
-
return execReturn;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
const cell = notebook === null || notebook === void 0 ? void 0 : notebook.getCellById(cellId);
|
|
177
|
-
return notebook
|
|
178
|
-
? {
|
|
179
|
-
kind,
|
|
180
|
-
ready,
|
|
181
|
-
cell,
|
|
182
|
-
executing,
|
|
183
|
-
notebookIsExecuting,
|
|
184
|
-
execute,
|
|
185
|
-
clear: () => cell === null || cell === void 0 ? void 0 : cell.clear(),
|
|
186
|
-
notebook,
|
|
187
|
-
}
|
|
188
|
-
: undefined;
|
|
189
|
-
}
|
|
190
|
-
exports.useNotebookCellExecution = useNotebookCellExecution;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionStatusTray.d.ts","sourceRoot":"","sources":["../../src/ConnectionStatusTray.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConnectionStatusTray.d.ts","sourceRoot":"","sources":["../../src/ConnectionStatusTray.tsx"],"names":[],"mappings":"AAMA,wBAAgB,oBAAoB,mDAoFnC"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
|
-
import { useThebeServer
|
|
3
|
+
import { useThebeServer } from 'thebe-react';
|
|
4
4
|
import { useComputeOptions } from './providers';
|
|
5
|
+
import { selectAreExecutionScopesBuilding, useExecutionScope } from './execute';
|
|
5
6
|
export function ConnectionStatusTray() {
|
|
6
7
|
const { thebe } = useComputeOptions();
|
|
7
8
|
const { connecting, ready: serverReady, error: serverError, events } = useThebeServer();
|
|
8
|
-
const {
|
|
9
|
+
const { slug, ready: scopeReady, state } = useExecutionScope();
|
|
9
10
|
const [show, setShow] = useState(false);
|
|
10
11
|
const [unsub, setUnsub] = useState();
|
|
11
12
|
const [status, setStatus] = useState('[client] Connecting...');
|
|
12
|
-
const error = serverError || sessionError;
|
|
13
|
-
const ready = serverReady &&
|
|
14
|
-
const busy = connecting ||
|
|
13
|
+
const error = serverError; // TODO scope bulding error handling || sessionError;
|
|
14
|
+
const ready = serverReady && scopeReady;
|
|
15
|
+
const busy = connecting || selectAreExecutionScopesBuilding(state, slug);
|
|
15
16
|
const handleStatus = (event, data) => {
|
|
16
17
|
setStatus(`[${data.subject}]: ${data.message}`);
|
|
17
18
|
};
|
|
@@ -37,6 +38,7 @@ export function ConnectionStatusTray() {
|
|
|
37
38
|
}
|
|
38
39
|
}, [thebe, busy, ready, error]);
|
|
39
40
|
const host = (thebe === null || thebe === void 0 ? void 0 : thebe.useBinder) ? 'Binder' : (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite) ? 'JupyterLite' : 'Local Server';
|
|
41
|
+
// TODO radix ui toast!
|
|
40
42
|
if (show && error) {
|
|
41
43
|
return (_jsxs("div", { className: "fixed p-3 text-sm text-gray-700 bg-white border rounded shadow-lg bottom-2 sm:right-2 max-w-[90%] md:max-w-[300px] min-w-0", children: [_jsxs("div", { className: "mb-2 font-semibold text-center", children: ["\u26D4\uFE0F Error connecting to ", host, " \u26D4\uFE0F"] }), _jsx("div", { className: "my-1 max-h-[15rem] mono overflow-hidden text-ellipsis", children: error }), _jsx("div", { className: "flex justify-end", children: _jsx("div", { className: "text-xs cursor-pointer hover:underline", role: "button", onClick: () => setShow(false), children: "dismiss" }) })] }));
|
|
42
44
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorTray.d.ts","sourceRoot":"","sources":["../../src/ErrorTray.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAgDvD,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,mBAAmB,EAAE,CAAA;CAAE,2CAStE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useThebeLoader } from 'thebe-react';
|
|
4
|
+
function ErrorDecoration({ children, idx }) {
|
|
5
|
+
return (_jsxs("div", { className: "relative py-3 mx-2 my-8 border rounded", children: [_jsx("div", { className: "absolute z-10 flex items-center bg-white -top-3 -left-2", children: idx && _jsxs("div", { className: "ml-1 text-sm text-gray-500", children: ["cell #: ", idx] }) }), _jsx("div", { className: "mx-3", children: children })] }));
|
|
6
|
+
}
|
|
7
|
+
function ErrorTrayMessage({ errors }) {
|
|
8
|
+
const { core } = useThebeLoader();
|
|
9
|
+
const [cells, setCells] = useState([]);
|
|
10
|
+
const [refs, setRefs] = useState([]);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!core)
|
|
13
|
+
return;
|
|
14
|
+
const cs = errors.map(() => new core.PassiveCellRenderer('any'));
|
|
15
|
+
setRefs(errors.map((_, idx) => (node) => {
|
|
16
|
+
var _a;
|
|
17
|
+
if (node) {
|
|
18
|
+
cs[idx].attachToDOM(node);
|
|
19
|
+
cs[idx].render((_a = errors[idx].error) !== null && _a !== void 0 ? _a : []);
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
setCells(cells);
|
|
23
|
+
}, [core, errors]);
|
|
24
|
+
if (!core)
|
|
25
|
+
return null;
|
|
26
|
+
return (_jsx("div", { children: errors.map((error, idx) => (_jsx("div", { className: "min-w-[400px]", children: _jsx(ErrorDecoration, { idx: error.index, children: _jsx("div", { className: "z-100", ref: refs[idx] }, error.id) }) }))) }));
|
|
27
|
+
}
|
|
28
|
+
export function ErrorTray({ errors }) {
|
|
29
|
+
return (_jsxs("div", { className: "relative px-4 pt-3 mt-8 text-sm text-red-600 border border-red-400 rounded border-1", children: [_jsxs("div", { children: [_jsx("span", { className: "font-bold", children: "Error" }), " - a page refresh may resolve this."] }), _jsx(ErrorTrayMessage, { errors: errors })] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function ArticleStatusBadge({ id }: {
|
|
2
|
+
id: string;
|
|
3
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export declare function ArticleRunNotebook({ id }: {
|
|
5
|
+
id: string;
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
7
|
+
export declare function ArticleResetNotebook({ id }: {
|
|
8
|
+
id: string;
|
|
9
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
//# sourceMappingURL=ArticleCellControls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArticleCellControls.d.ts","sourceRoot":"","sources":["../../../src/controls/ArticleCellControls.tsx"],"names":[],"mappings":"AAMA,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,2CAmBxD;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,kDAYxD;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,kDAY1D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useThebeServer } from 'thebe-react';
|
|
3
|
+
import { useNotebookExecution } from '../execute/hooks';
|
|
4
|
+
import { Reset, Run, SpinnerStatusButton } from './Buttons';
|
|
5
|
+
import { selectAreExecutionScopesBuilding } from '../execute';
|
|
6
|
+
export function ArticleStatusBadge({ id }) {
|
|
7
|
+
const { connect, connecting } = useThebeServer();
|
|
8
|
+
const { slug, state, start, ready, executionCount } = useNotebookExecution(id);
|
|
9
|
+
const building = selectAreExecutionScopesBuilding(state, slug);
|
|
10
|
+
const handleStart = () => {
|
|
11
|
+
connect();
|
|
12
|
+
start();
|
|
13
|
+
};
|
|
14
|
+
return (_jsx(SpinnerStatusButton, { ready: ready, busy: building || connecting, modified: executionCount != null, onClick: handleStart }));
|
|
15
|
+
}
|
|
16
|
+
export function ArticleRunNotebook({ id }) {
|
|
17
|
+
const { ready, cellIsExecuting, notebookIsBusy, execute } = useNotebookExecution(id);
|
|
18
|
+
if (!ready)
|
|
19
|
+
return null;
|
|
20
|
+
return (_jsx(Run, { ready: ready, executing: cellIsExecuting, disabled: notebookIsBusy, onClick: execute, title: "Run the notebook that creates this figure" }));
|
|
21
|
+
}
|
|
22
|
+
export function ArticleResetNotebook({ id }) {
|
|
23
|
+
const { ready, notebookIsResetting, notebookIsBusy, reset } = useNotebookExecution(id);
|
|
24
|
+
if (!ready)
|
|
25
|
+
return null;
|
|
26
|
+
return (_jsx(Reset, { ready: ready, resetting: notebookIsResetting, disabled: notebookIsBusy, onClick: reset, title: "Reset the figure to its original state and restart the kernel" }));
|
|
27
|
+
}
|