@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,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.selectPageIsBusy = exports.selectNotebookIsBusy = exports.selectCellIsBusy = exports.useBusyScope = exports.BusyScopeProvider = exports.reducer = void 0;
|
|
38
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
40
|
+
const BusyScopeContext = react_1.default.createContext(undefined);
|
|
41
|
+
function isSlugPayload(payload) {
|
|
42
|
+
return (typeof payload.pageSlug === 'string' &&
|
|
43
|
+
typeof payload.notebookSlug === 'string' &&
|
|
44
|
+
typeof payload.kind === 'string');
|
|
45
|
+
}
|
|
46
|
+
function isCellPayload(payload) {
|
|
47
|
+
return (isSlugPayload(payload) &&
|
|
48
|
+
typeof payload.cellId === 'string' &&
|
|
49
|
+
typeof payload.kind === 'string');
|
|
50
|
+
}
|
|
51
|
+
function isNotebookPayload(payload) {
|
|
52
|
+
return (isSlugPayload(payload) &&
|
|
53
|
+
Array.isArray(payload.cellIds) &&
|
|
54
|
+
payload.cellIds.every((id) => typeof id === 'string') &&
|
|
55
|
+
typeof payload.kind === 'string');
|
|
56
|
+
}
|
|
57
|
+
function reducer(state, action) {
|
|
58
|
+
var _a, _b, _c, _d, _e;
|
|
59
|
+
switch (action.type) {
|
|
60
|
+
case 'SET_CELL_BUSY': {
|
|
61
|
+
if (!isCellPayload(action.payload)) {
|
|
62
|
+
console.error('SET_CELL_BUSY payload must be a cell payload', action.payload);
|
|
63
|
+
return state;
|
|
64
|
+
}
|
|
65
|
+
const { pageSlug, notebookSlug, cellId, kind } = action.payload;
|
|
66
|
+
if ((_b = (_a = state[kind][pageSlug]) === null || _a === void 0 ? void 0 : _a[notebookSlug]) === null || _b === void 0 ? void 0 : _b[cellId])
|
|
67
|
+
return state;
|
|
68
|
+
return Object.assign(Object.assign({}, state), { [kind]: Object.assign(Object.assign({}, state[kind]), { [pageSlug]: Object.assign(Object.assign({}, state[kind][pageSlug]), { [notebookSlug]: Object.assign(Object.assign({}, (_c = state[kind][pageSlug]) === null || _c === void 0 ? void 0 : _c[notebookSlug]), { [cellId]: true }) }) }) });
|
|
69
|
+
}
|
|
70
|
+
case 'CLEAR_CELL_BUSY': {
|
|
71
|
+
if (!isCellPayload(action.payload)) {
|
|
72
|
+
console.error('CLEAR_CELL_BUSY payload must be a cell payload', action.payload);
|
|
73
|
+
return state;
|
|
74
|
+
}
|
|
75
|
+
const { pageSlug, notebookSlug, cellId, kind } = action.payload;
|
|
76
|
+
const _f = state[kind], _g = pageSlug, renderBusy = _f[_g], otherRenders = __rest(_f, [typeof _g === "symbol" ? _g : _g + ""]);
|
|
77
|
+
if (!renderBusy)
|
|
78
|
+
return state;
|
|
79
|
+
const _h = renderBusy, _j = notebookSlug, notebookBusy = _h[_j], otherNotebooks = __rest(_h, [typeof _j === "symbol" ? _j : _j + ""]);
|
|
80
|
+
if (!notebookBusy)
|
|
81
|
+
return state;
|
|
82
|
+
if (!notebookBusy[cellId])
|
|
83
|
+
return state;
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
|
+
const _k = notebookBusy, _l = cellId, cellBusy = _k[_l], otherCells = __rest(_k, [typeof _l === "symbol" ? _l : _l + ""]);
|
|
86
|
+
// remove the render if it's empty
|
|
87
|
+
if (Object.keys(otherCells).length === 0 && Object.keys(otherNotebooks).length === 0) {
|
|
88
|
+
return Object.assign(Object.assign({}, state), { [kind]: otherRenders });
|
|
89
|
+
}
|
|
90
|
+
// remove the notebook if it's empty
|
|
91
|
+
if (Object.keys(otherCells).length === 0) {
|
|
92
|
+
return Object.assign(Object.assign({}, state), { [kind]: Object.assign(Object.assign({}, state[kind]), { [pageSlug]: Object.assign({}, otherNotebooks) }) });
|
|
93
|
+
}
|
|
94
|
+
return Object.assign(Object.assign({}, state), { [kind]: Object.assign(Object.assign({}, state[kind]), { [action.payload.pageSlug]: Object.assign(Object.assign({}, otherNotebooks), { [notebookSlug]: Object.assign({}, otherCells) }) }) });
|
|
95
|
+
}
|
|
96
|
+
case 'SET_NOTEBOOK_BUSY': {
|
|
97
|
+
if (!isNotebookPayload(action.payload)) {
|
|
98
|
+
console.error('SET_NOTEBOOK_BUSY payload must be a notebook payload', action.payload);
|
|
99
|
+
return state;
|
|
100
|
+
}
|
|
101
|
+
const { pageSlug, notebookSlug, cellIds, kind } = action.payload;
|
|
102
|
+
return Object.assign(Object.assign({}, state), { [kind]: Object.assign(Object.assign({}, state[kind]), { [pageSlug]: Object.assign(Object.assign({}, state[kind][pageSlug]), { [notebookSlug]: Object.assign(Object.assign({}, (_d = state[kind][pageSlug]) === null || _d === void 0 ? void 0 : _d[notebookSlug]), cellIds.reduce((acc, cellId) => (Object.assign(Object.assign({}, acc), { [cellId]: true })), {})) }) }) });
|
|
103
|
+
}
|
|
104
|
+
case 'CLEAR_NOTEBOOK_BUSY': {
|
|
105
|
+
if (!isSlugPayload(action.payload)) {
|
|
106
|
+
console.error('CLEAR_NOTEBOOK_BUSY payload must be a notebook payload', action.payload);
|
|
107
|
+
return state;
|
|
108
|
+
}
|
|
109
|
+
const { pageSlug, notebookSlug, kind } = action.payload;
|
|
110
|
+
if (!state[kind][pageSlug])
|
|
111
|
+
return state;
|
|
112
|
+
if (!((_e = state[kind][pageSlug]) === null || _e === void 0 ? void 0 : _e[notebookSlug]))
|
|
113
|
+
return state;
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
115
|
+
const _m = state[kind][pageSlug], _o = notebookSlug, notebookBusy = _m[_o], otherNotebooks = __rest(_m, [typeof _o === "symbol" ? _o : _o + ""]);
|
|
116
|
+
if (Object.keys(otherNotebooks).length === 0) {
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
118
|
+
const _p = state[kind], _q = pageSlug, renderBusy = _p[_q], otherRenders = __rest(_p, [typeof _q === "symbol" ? _q : _q + ""]);
|
|
119
|
+
return Object.assign(Object.assign({}, state), { [kind]: otherRenders });
|
|
120
|
+
}
|
|
121
|
+
return Object.assign(Object.assign({}, state), { [kind]: Object.assign(Object.assign({}, state[kind]), { [pageSlug]: Object.assign({}, otherNotebooks) }) });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return state;
|
|
125
|
+
}
|
|
126
|
+
exports.reducer = reducer;
|
|
127
|
+
function BusyScopeProvider({ children }) {
|
|
128
|
+
const [state, dispatch] = (0, react_1.useReducer)(reducer, { execute: {}, reset: {} });
|
|
129
|
+
const memo = react_1.default.useMemo(() => ({ state, dispatch }), [state]);
|
|
130
|
+
if (typeof window !== 'undefined') {
|
|
131
|
+
window.busyScopeState = memo.state;
|
|
132
|
+
}
|
|
133
|
+
return (0, jsx_runtime_1.jsx)(BusyScopeContext.Provider, { value: memo, children: children });
|
|
134
|
+
}
|
|
135
|
+
exports.BusyScopeProvider = BusyScopeProvider;
|
|
136
|
+
function useBusyScope() {
|
|
137
|
+
const context = react_1.default.useContext(BusyScopeContext);
|
|
138
|
+
if (context === undefined) {
|
|
139
|
+
throw new Error('useBusyScope must be used within a BusyScopeProvider');
|
|
140
|
+
}
|
|
141
|
+
const { dispatch, state } = context;
|
|
142
|
+
const cell = (0, react_1.useCallback)((pageSlug, notebookSlug, cellId, kind) => selectCellIsBusy(state, pageSlug, notebookSlug, cellId, kind), [state]);
|
|
143
|
+
const notebook = (0, react_1.useCallback)((pageSlug, notebookSlug, kind) => selectNotebookIsBusy(state, pageSlug, notebookSlug, kind), [state]);
|
|
144
|
+
const page = (0, react_1.useCallback)((pageSlug, kind) => selectPageIsBusy(state, pageSlug, kind), [state]);
|
|
145
|
+
const setCell = (0, react_1.useCallback)((pageSlug, notebookSlug, cellId, kind) => {
|
|
146
|
+
dispatch({ type: 'SET_CELL_BUSY', payload: { pageSlug, notebookSlug, cellId, kind } });
|
|
147
|
+
}, [dispatch]);
|
|
148
|
+
const clearCell = (0, react_1.useCallback)((pageSlug, notebookSlug, cellId, kind) => dispatch({ type: 'CLEAR_CELL_BUSY', payload: { pageSlug, notebookSlug, cellId, kind } }), [dispatch]);
|
|
149
|
+
const setNotebook = (0, react_1.useCallback)((pageSlug, notebookSlug, cellIds, kind) => dispatch({ type: 'SET_NOTEBOOK_BUSY', payload: { pageSlug, notebookSlug, cellIds, kind } }), [dispatch]);
|
|
150
|
+
const clearNotebook = (0, react_1.useCallback)((pageSlug, notebookSlug, kind) => dispatch({ type: 'CLEAR_NOTEBOOK_BUSY', payload: { pageSlug, notebookSlug, kind } }), [dispatch]);
|
|
151
|
+
return { cell, notebook, page, setCell, clearCell, setNotebook, clearNotebook };
|
|
152
|
+
}
|
|
153
|
+
exports.useBusyScope = useBusyScope;
|
|
154
|
+
function selectCellIsBusy(state, pageSlug, notebookSlug, cellId, kind) {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
return !!((_b = (_a = state[kind][pageSlug]) === null || _a === void 0 ? void 0 : _a[notebookSlug]) === null || _b === void 0 ? void 0 : _b[cellId]);
|
|
157
|
+
}
|
|
158
|
+
exports.selectCellIsBusy = selectCellIsBusy;
|
|
159
|
+
/**
|
|
160
|
+
* a fast selector relying on the fact that if at least one cell is present, the notebook is busy
|
|
161
|
+
*
|
|
162
|
+
* @param state
|
|
163
|
+
* @param pageSlug
|
|
164
|
+
* @param notebookSlug
|
|
165
|
+
* @returns
|
|
166
|
+
*/
|
|
167
|
+
function selectNotebookIsBusy(state, pageSlug, notebookSlug, kind) {
|
|
168
|
+
var _a;
|
|
169
|
+
return !!((_a = state[kind][pageSlug]) === null || _a === void 0 ? void 0 : _a[notebookSlug]);
|
|
170
|
+
}
|
|
171
|
+
exports.selectNotebookIsBusy = selectNotebookIsBusy;
|
|
172
|
+
/**
|
|
173
|
+
* a fast selector relying on the fact that if at least one notebook is present, the render is busy
|
|
174
|
+
*
|
|
175
|
+
* @param state
|
|
176
|
+
* @param pageSlug
|
|
177
|
+
* @returns
|
|
178
|
+
*/
|
|
179
|
+
function selectPageIsBusy(state, pageSlug, kind) {
|
|
180
|
+
return !!state[kind][pageSlug];
|
|
181
|
+
}
|
|
182
|
+
exports.selectPageIsBusy = selectPageIsBusy;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { IdOrKey } from './types';
|
|
3
|
+
import type { IThebeCell } from 'thebe-core';
|
|
4
|
+
import { SourceFileKind } from 'myst-common';
|
|
5
|
+
export declare function useExecutionScope({ clearOutputsOnExecute, }?: {
|
|
6
|
+
clearOutputsOnExecute?: boolean;
|
|
7
|
+
}): {
|
|
8
|
+
ready: boolean;
|
|
9
|
+
start: (slug: string) => void;
|
|
10
|
+
clearAll: (pageSlug: string) => void;
|
|
11
|
+
resetAll: (pageSlug: string) => void;
|
|
12
|
+
execute: (slug: string) => void;
|
|
13
|
+
slug: string;
|
|
14
|
+
state: import("./types").ExecuteScopeState;
|
|
15
|
+
dispatch: React.Dispatch<import("./actions").ExecuteScopeAction>;
|
|
16
|
+
idkmap: import("./types").IdKeyMap;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* useNotebookExecution a hook to govern notebook execution in the context of a single
|
|
20
|
+
* cell embedded in an article
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export declare function useNotebookExecution(id: IdOrKey, clearOutputsOnExecute?: boolean): {
|
|
24
|
+
ready: boolean;
|
|
25
|
+
start: () => void;
|
|
26
|
+
clear: () => void;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
execute: () => void;
|
|
29
|
+
cellIsExecuting: boolean;
|
|
30
|
+
notebookIsExecuting: boolean;
|
|
31
|
+
notebookIsResetting: boolean;
|
|
32
|
+
notebookIsBusy: boolean;
|
|
33
|
+
executionCount: number | null | undefined;
|
|
34
|
+
slug: string;
|
|
35
|
+
state: import("./types").ExecuteScopeState;
|
|
36
|
+
dispatch: React.Dispatch<import("./actions").ExecuteScopeAction>;
|
|
37
|
+
idkmap: import("./types").IdKeyMap;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* useCellExecution a hook to govern the execute status and actions for a single cell
|
|
41
|
+
*
|
|
42
|
+
* @param id
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export declare function useCellExecution(id: IdOrKey): {
|
|
46
|
+
kind: SourceFileKind;
|
|
47
|
+
ready: boolean;
|
|
48
|
+
execute: () => void;
|
|
49
|
+
clear: () => void;
|
|
50
|
+
cellIsExecuting: boolean;
|
|
51
|
+
notebookIsExecuting: boolean;
|
|
52
|
+
notebookIsResetting: boolean;
|
|
53
|
+
notebookIsBusy: boolean;
|
|
54
|
+
cell: IThebeCell | undefined;
|
|
55
|
+
};
|
|
56
|
+
export declare function useIsAComputableCell(id: IdOrKey): {
|
|
57
|
+
slug: string;
|
|
58
|
+
computable: boolean;
|
|
59
|
+
ready: boolean;
|
|
60
|
+
};
|
|
61
|
+
export declare function useReadyToExecute(): boolean;
|
|
62
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +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,EAA0C,MAAM,YAAY,CAAC;AAGrF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,wBAAgB,iBAAiB,CAAC,EAChC,qBAA6B,GAC9B,GAAE;IAAE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAAO;;kBAUR,MAAM;yBAsD1B,MAAM;yBAYN,MAAM;oBAxDI,MAAM;;;;;EAgF9B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,EAAE,qBAAqB,UAAQ;;;;;;;;;;;;;;;EA4G9E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO;;;;;;;;;;EAiE3C;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO;;;;EAc/C;AAED,wBAAgB,iBAAiB,YAOhC"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.useReadyToExecute = exports.useIsAComputableCell = exports.useCellExecution = exports.useNotebookExecution = exports.useExecutionScope = void 0;
|
|
36
|
+
const react_1 = __importStar(require("react"));
|
|
37
|
+
const provider_1 = require("./provider");
|
|
38
|
+
const busy_1 = require("./busy");
|
|
39
|
+
const thebe_react_1 = require("thebe-react");
|
|
40
|
+
const myst_common_1 = require("myst-common");
|
|
41
|
+
function useExecutionScope({ clearOutputsOnExecute = false, } = {}) {
|
|
42
|
+
var _a;
|
|
43
|
+
const context = react_1.default.useContext(provider_1.ExecuteScopeContext);
|
|
44
|
+
const { config } = (0, thebe_react_1.useThebeConfig)();
|
|
45
|
+
const busy = (0, busy_1.useBusyScope)();
|
|
46
|
+
if (context === undefined) {
|
|
47
|
+
throw new Error('useExecuteScope must be used within a ExecuteScopeProvider');
|
|
48
|
+
}
|
|
49
|
+
const { state, dispatch } = context;
|
|
50
|
+
const start = (0, react_1.useCallback)((slug) => {
|
|
51
|
+
console.debug(`Jupyter: Starting ${slug}`);
|
|
52
|
+
dispatch({
|
|
53
|
+
type: 'REQUEST_BUILD',
|
|
54
|
+
payload: {
|
|
55
|
+
slug,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}, []);
|
|
59
|
+
const execute = (slug) => {
|
|
60
|
+
// set busy
|
|
61
|
+
Object.entries(state.pages[slug].scopes).forEach(([notebookSlug, { notebook }]) => {
|
|
62
|
+
busy.setNotebook(slug, notebookSlug, notebook.cells.map((c) => c.id), 'execute');
|
|
63
|
+
});
|
|
64
|
+
if (clearOutputsOnExecute) {
|
|
65
|
+
// clear all notebook cell outputs
|
|
66
|
+
Object.values(state.pages[slug].scopes).forEach(({ notebook }) => {
|
|
67
|
+
notebook.clear();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// let busy state update prior to launching execute
|
|
71
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const handler = (_, data) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
if (data.subject === 'cell' && data.status === 'idle') {
|
|
75
|
+
const notebookSlug = (_a = data.object.notebookId) !== null && _a !== void 0 ? _a : 'unknown';
|
|
76
|
+
busy.clearCell(slug, notebookSlug, (_b = data.id) !== null && _b !== void 0 ? _b : 'unknown', 'execute');
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
config === null || config === void 0 ? void 0 : config.events.on('status', handler);
|
|
80
|
+
// execute all cells on all notebooks
|
|
81
|
+
yield Promise.all(Object.entries(state.pages[slug].scopes).map(([, { notebook }]) => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const execReturns = yield notebook.executeAll(true);
|
|
83
|
+
const errs = (0, thebe_react_1.findErrors)(execReturns);
|
|
84
|
+
if (errs != null)
|
|
85
|
+
console.error('errors', errs);
|
|
86
|
+
})));
|
|
87
|
+
config === null || config === void 0 ? void 0 : config.events.off('status', handler);
|
|
88
|
+
}), 100);
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* clearAll clears all cells in all notebooks for a given rendering
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
const clearAll = (0, react_1.useCallback)((pageSlug) => {
|
|
95
|
+
Object.entries(state.pages[pageSlug].scopes).forEach(([, { notebook }]) => {
|
|
96
|
+
notebook.clear();
|
|
97
|
+
});
|
|
98
|
+
}, [state]);
|
|
99
|
+
/**
|
|
100
|
+
* resetAll resets all cells in all notebooks for a given rendering
|
|
101
|
+
*/
|
|
102
|
+
const resetAll = (0, react_1.useCallback)((pageSlug) => {
|
|
103
|
+
Object.entries(state.pages[pageSlug].scopes).forEach(([notebookSlug, { notebook, session }]) => {
|
|
104
|
+
busy.setNotebook(pageSlug, notebookSlug, notebook.cells.map((c) => c.id), 'reset');
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
var _a;
|
|
107
|
+
notebook.reset();
|
|
108
|
+
(_a = session === null || session === void 0 ? void 0 : session.kernel) === null || _a === void 0 ? void 0 : _a.restart().finally(() => {
|
|
109
|
+
busy.clearNotebook(pageSlug, notebookSlug, 'reset');
|
|
110
|
+
});
|
|
111
|
+
}, 300);
|
|
112
|
+
});
|
|
113
|
+
}, [state]);
|
|
114
|
+
const ready = (_a = context.state.pages[context.slug]) === null || _a === void 0 ? void 0 : _a.ready;
|
|
115
|
+
return Object.assign(Object.assign({}, context), { ready, start, clearAll, resetAll, execute });
|
|
116
|
+
}
|
|
117
|
+
exports.useExecutionScope = useExecutionScope;
|
|
118
|
+
/**
|
|
119
|
+
* useNotebookExecution a hook to govern notebook execution in the context of a single
|
|
120
|
+
* cell embedded in an article
|
|
121
|
+
*
|
|
122
|
+
*/
|
|
123
|
+
function useNotebookExecution(id, clearOutputsOnExecute = false) {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
const context = react_1.default.useContext(provider_1.ExecuteScopeContext);
|
|
126
|
+
const { config } = (0, thebe_react_1.useThebeConfig)();
|
|
127
|
+
const busy = (0, busy_1.useBusyScope)();
|
|
128
|
+
if (context === undefined) {
|
|
129
|
+
throw new Error('useExecuteScope must be used within a ExecuteScopeProvider');
|
|
130
|
+
}
|
|
131
|
+
const { state, dispatch, idkmap } = context;
|
|
132
|
+
const target = (_a = idkmap[id]) !== null && _a !== void 0 ? _a : {};
|
|
133
|
+
const { pageSlug, notebookSlug, cellId } = target;
|
|
134
|
+
// TODO consider extending this to start only the notebook requested, currently this will
|
|
135
|
+
// execute all connected notebooks
|
|
136
|
+
const start = (0, react_1.useCallback)(() => {
|
|
137
|
+
dispatch({
|
|
138
|
+
type: 'REQUEST_BUILD',
|
|
139
|
+
payload: {
|
|
140
|
+
slug: context.slug,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}, [target]);
|
|
144
|
+
let cell;
|
|
145
|
+
let notebook;
|
|
146
|
+
if (target && state.pages[pageSlug]) {
|
|
147
|
+
notebook = state.pages[pageSlug].scopes[notebookSlug].notebook;
|
|
148
|
+
if (!notebook)
|
|
149
|
+
console.error('no notebook for', { pageSlug, notebookSlug, cellId });
|
|
150
|
+
cell = notebook === null || notebook === void 0 ? void 0 : notebook.getCellById(cellId);
|
|
151
|
+
if (!cell)
|
|
152
|
+
console.error('no cell found', { pageSlug, notebookSlug, cellId });
|
|
153
|
+
}
|
|
154
|
+
const execute = () => {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
const nb = (_b = (_a = state.pages[pageSlug]) === null || _a === void 0 ? void 0 : _a.scopes[notebookSlug]) === null || _b === void 0 ? void 0 : _b.notebook;
|
|
157
|
+
// set busy
|
|
158
|
+
busy.setNotebook(pageSlug, notebookSlug, nb.cells.map((c) => c.id), 'execute');
|
|
159
|
+
if (clearOutputsOnExecute)
|
|
160
|
+
nb.clear();
|
|
161
|
+
// let busy state update prior to launching execute
|
|
162
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
const handler = (_, data) => {
|
|
164
|
+
var _a;
|
|
165
|
+
if (data.subject === 'cell' && data.status === 'idle') {
|
|
166
|
+
busy.clearCell(pageSlug, notebookSlug, (_a = data.id) !== null && _a !== void 0 ? _a : 'unknown', 'execute');
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
config === null || config === void 0 ? void 0 : config.events.on('status', handler);
|
|
170
|
+
// execute all cells on the notebooks
|
|
171
|
+
const execReturns = yield nb.executeAll(true);
|
|
172
|
+
const errs = (0, thebe_react_1.findErrors)(execReturns);
|
|
173
|
+
if (errs != null)
|
|
174
|
+
console.error('errors', errs); // TODO: handle errors
|
|
175
|
+
config === null || config === void 0 ? void 0 : config.events.off('status', handler);
|
|
176
|
+
}), 100);
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* clearAll clears all cells in all notebooks for a given rendering
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
const clear = (0, react_1.useCallback)(() => {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
const nb = (_b = (_a = state.pages[pageSlug]) === null || _a === void 0 ? void 0 : _a.scopes[notebookSlug]) === null || _b === void 0 ? void 0 : _b.notebook;
|
|
185
|
+
nb.clear();
|
|
186
|
+
}, [state]);
|
|
187
|
+
/**
|
|
188
|
+
* resetAll resets all cells in all notebooks for a given rendering
|
|
189
|
+
*/
|
|
190
|
+
const reset = (0, react_1.useCallback)(() => {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
const { notebook: nb, session } = (_b = (_a = state.pages[pageSlug]) === null || _a === void 0 ? void 0 : _a.scopes[notebookSlug]) !== null && _b !== void 0 ? _b : {};
|
|
193
|
+
busy.setNotebook(pageSlug, notebookSlug, nb.cells.map((c) => c.id), 'reset');
|
|
194
|
+
setTimeout(() => {
|
|
195
|
+
var _a;
|
|
196
|
+
nb.reset();
|
|
197
|
+
(_a = session === null || session === void 0 ? void 0 : session.kernel) === null || _a === void 0 ? void 0 : _a.restart().finally(() => {
|
|
198
|
+
busy.clearNotebook(pageSlug, notebookSlug, 'reset');
|
|
199
|
+
});
|
|
200
|
+
}, 300);
|
|
201
|
+
}, [state]);
|
|
202
|
+
const ready = (_b = context.state.pages[context.slug]) === null || _b === void 0 ? void 0 : _b.ready;
|
|
203
|
+
const notebookIsExecuting = busy.notebook(pageSlug, notebookSlug, 'execute');
|
|
204
|
+
const notebookIsResetting = busy.notebook(pageSlug, notebookSlug, 'reset');
|
|
205
|
+
const notebookIsBusy = notebookIsExecuting || notebookIsResetting;
|
|
206
|
+
return Object.assign(Object.assign({}, context), { ready,
|
|
207
|
+
start,
|
|
208
|
+
clear,
|
|
209
|
+
reset,
|
|
210
|
+
execute, cellIsExecuting: cell ? busy.cell(pageSlug, notebookSlug, cell === null || cell === void 0 ? void 0 : cell.id, 'execute') : false, notebookIsExecuting,
|
|
211
|
+
notebookIsResetting,
|
|
212
|
+
notebookIsBusy, executionCount: cell === null || cell === void 0 ? void 0 : cell.executionCount });
|
|
213
|
+
}
|
|
214
|
+
exports.useNotebookExecution = useNotebookExecution;
|
|
215
|
+
/**
|
|
216
|
+
* useCellExecution a hook to govern the execute status and actions for a single cell
|
|
217
|
+
*
|
|
218
|
+
* @param id
|
|
219
|
+
* @returns
|
|
220
|
+
*/
|
|
221
|
+
function useCellExecution(id) {
|
|
222
|
+
var _a, _b, _c, _d;
|
|
223
|
+
const busy = (0, busy_1.useBusyScope)();
|
|
224
|
+
const context = react_1.default.useContext(provider_1.ExecuteScopeContext);
|
|
225
|
+
if (context === undefined) {
|
|
226
|
+
throw new Error('useExecuteScope must be used within a ExecuteScopeProvider');
|
|
227
|
+
}
|
|
228
|
+
const { state, idkmap } = context;
|
|
229
|
+
const target = (_a = idkmap[id]) !== null && _a !== void 0 ? _a : {};
|
|
230
|
+
const { pageSlug, notebookSlug, cellId } = target;
|
|
231
|
+
let cell;
|
|
232
|
+
let notebook;
|
|
233
|
+
if (target && state.pages[pageSlug]) {
|
|
234
|
+
notebook = state.pages[pageSlug].scopes[notebookSlug].notebook;
|
|
235
|
+
if (!notebook)
|
|
236
|
+
console.error('no notebook for', { pageSlug, notebookSlug, cellId });
|
|
237
|
+
cell = notebook === null || notebook === void 0 ? void 0 : notebook.getCellById(cellId);
|
|
238
|
+
if (!cell)
|
|
239
|
+
console.error('no cell found', { pageSlug, notebookSlug, cellId });
|
|
240
|
+
}
|
|
241
|
+
const ready = (_b = context.state.pages[context.slug]) === null || _b === void 0 ? void 0 : _b.ready;
|
|
242
|
+
const kind = (_d = (_c = context.state.pages[context.slug]) === null || _c === void 0 ? void 0 : _c.kind) !== null && _d !== void 0 ? _d : myst_common_1.SourceFileKind.Article;
|
|
243
|
+
const execute = (0, react_1.useCallback)(() => {
|
|
244
|
+
if (!cell) {
|
|
245
|
+
console.error('no cell found on execute', { pageSlug, notebookSlug, cellId });
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
// set busy
|
|
249
|
+
busy.setCell(pageSlug, notebookSlug, cell.id, 'execute');
|
|
250
|
+
cell.clear();
|
|
251
|
+
// let busy state update prior to launching execute
|
|
252
|
+
setTimeout(() => {
|
|
253
|
+
if (!cell)
|
|
254
|
+
throw new Error('no cell found on execute');
|
|
255
|
+
cell.execute().then(() => {
|
|
256
|
+
if (!cell)
|
|
257
|
+
throw new Error('no cell found after execute');
|
|
258
|
+
busy.clearCell(pageSlug, notebookSlug, cell === null || cell === void 0 ? void 0 : cell.id, 'execute');
|
|
259
|
+
});
|
|
260
|
+
}, 100);
|
|
261
|
+
}, [state, cell]);
|
|
262
|
+
const clear = (0, react_1.useCallback)(() => {
|
|
263
|
+
if (!cell) {
|
|
264
|
+
console.error('no cell found on clear', { pageSlug, notebookSlug, cellId });
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
cell.clear();
|
|
268
|
+
}, [state, cell]);
|
|
269
|
+
const notebookIsExecuting = busy.notebook(pageSlug, notebookSlug, 'execute');
|
|
270
|
+
const notebookIsResetting = busy.notebook(pageSlug, notebookSlug, 'reset');
|
|
271
|
+
const notebookIsBusy = notebookIsExecuting || notebookIsResetting;
|
|
272
|
+
return {
|
|
273
|
+
kind,
|
|
274
|
+
ready,
|
|
275
|
+
execute,
|
|
276
|
+
clear,
|
|
277
|
+
cellIsExecuting: cell ? busy.cell(pageSlug, notebookSlug, cell === null || cell === void 0 ? void 0 : cell.id, 'execute') : false,
|
|
278
|
+
notebookIsExecuting,
|
|
279
|
+
notebookIsResetting,
|
|
280
|
+
notebookIsBusy,
|
|
281
|
+
cell,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
exports.useCellExecution = useCellExecution;
|
|
285
|
+
function useIsAComputableCell(id) {
|
|
286
|
+
var _a, _b, _c;
|
|
287
|
+
const context = react_1.default.useContext(provider_1.ExecuteScopeContext);
|
|
288
|
+
if (context === undefined) {
|
|
289
|
+
throw new Error('useExecuteScope must be used within a ExecuteScopeProvider');
|
|
290
|
+
}
|
|
291
|
+
const { idkmap } = context;
|
|
292
|
+
const target = (_a = idkmap[id]) !== null && _a !== void 0 ? _a : {};
|
|
293
|
+
return {
|
|
294
|
+
slug: context.slug,
|
|
295
|
+
computable: !!target,
|
|
296
|
+
ready: (_c = (_b = context.state.pages[context.slug]) === null || _b === void 0 ? void 0 : _b.ready) !== null && _c !== void 0 ? _c : false,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
exports.useIsAComputableCell = useIsAComputableCell;
|
|
300
|
+
function useReadyToExecute() {
|
|
301
|
+
var _a, _b;
|
|
302
|
+
const context = react_1.default.useContext(provider_1.ExecuteScopeContext);
|
|
303
|
+
if (context === undefined) {
|
|
304
|
+
throw new Error('useExecuteScope must be used within a ExecuteScopeProvider');
|
|
305
|
+
}
|
|
306
|
+
return (_b = (_a = context.state.pages[context.slug]) === null || _a === void 0 ? void 0 : _a.ready) !== null && _b !== void 0 ? _b : false;
|
|
307
|
+
}
|
|
308
|
+
exports.useReadyToExecute = useReadyToExecute;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/execute/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./hooks"), exports);
|
|
18
|
+
__exportStar(require("./actions"), exports);
|
|
19
|
+
__exportStar(require("./provider"), exports);
|
|
20
|
+
__exportStar(require("./selectors"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
__exportStar(require("./busy"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExecuteScopeAction } from './actions';
|
|
3
|
+
import type { IdKeyMap, ExecuteScopeState } from './types';
|
|
4
|
+
export declare function MdastFetcher({ slug, url, dispatch, }: {
|
|
5
|
+
slug: string;
|
|
6
|
+
url: string;
|
|
7
|
+
dispatch: React.Dispatch<ExecuteScopeAction>;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
9
|
+
export declare function NotebookBuilder({ pageSlug, notebookSlug, idkmap, state, dispatch, }: {
|
|
10
|
+
pageSlug: string;
|
|
11
|
+
notebookSlug: string;
|
|
12
|
+
idkmap: IdKeyMap;
|
|
13
|
+
state: ExecuteScopeState;
|
|
14
|
+
dispatch: React.Dispatch<ExecuteScopeAction>;
|
|
15
|
+
}): null;
|
|
16
|
+
export declare function SessionStarter({ pageSlug, notebookSlug, state, dispatch, }: {
|
|
17
|
+
pageSlug: string;
|
|
18
|
+
notebookSlug: string;
|
|
19
|
+
state: ExecuteScopeState;
|
|
20
|
+
dispatch: React.Dispatch<ExecuteScopeAction>;
|
|
21
|
+
}): null;
|
|
22
|
+
export declare function ServerMonitor({ state, dispatch, }: {
|
|
23
|
+
state: ExecuteScopeState;
|
|
24
|
+
dispatch: React.Dispatch<ExecuteScopeAction>;
|
|
25
|
+
}): null;
|
|
26
|
+
//# sourceMappingURL=leaf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leaf.d.ts","sourceRoot":"","sources":["../../../src/execute/leaf.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAO3D,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,GAAG,EACH,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;CAC9C,kDAkBA;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,KAAK,EACL,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;CAC9C,QA8CA;AAED,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;CAC9C,QAoEA;AAED,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;CAC9C,QA4BA"}
|