@myst-theme/jupyter 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/dist/cjs/ConnectionStatusTray.d.ts.map +1 -1
  2. package/dist/cjs/ConnectionStatusTray.js +6 -4
  3. package/dist/cjs/ErrorTray.d.ts +5 -0
  4. package/dist/cjs/ErrorTray.d.ts.map +1 -0
  5. package/dist/cjs/ErrorTray.js +34 -0
  6. package/dist/cjs/controls/ArticleCellControls.d.ts +10 -0
  7. package/dist/cjs/controls/ArticleCellControls.d.ts.map +1 -0
  8. package/dist/cjs/controls/ArticleCellControls.js +33 -0
  9. package/dist/cjs/controls/Buttons.d.ts +47 -0
  10. package/dist/cjs/controls/Buttons.d.ts.map +1 -0
  11. package/dist/cjs/controls/Buttons.js +70 -0
  12. package/dist/cjs/controls/NotebookCellControls.d.ts +10 -0
  13. package/dist/cjs/controls/NotebookCellControls.d.ts.map +1 -0
  14. package/dist/cjs/controls/NotebookCellControls.js +27 -0
  15. package/dist/cjs/controls/NotebookToolbar.d.ts +4 -0
  16. package/dist/cjs/controls/NotebookToolbar.d.ts.map +1 -0
  17. package/dist/cjs/controls/NotebookToolbar.js +47 -0
  18. package/dist/cjs/controls/Spinner.d.ts +4 -0
  19. package/dist/cjs/controls/Spinner.d.ts.map +1 -0
  20. package/dist/cjs/controls/Spinner.js +8 -0
  21. package/dist/cjs/controls/index.d.ts +5 -0
  22. package/dist/cjs/controls/index.d.ts.map +1 -0
  23. package/dist/cjs/controls/index.js +20 -0
  24. package/dist/cjs/embed.d.ts +4 -0
  25. package/dist/cjs/embed.d.ts.map +1 -0
  26. package/dist/cjs/embed.js +24 -0
  27. package/dist/cjs/execute/actions.d.ts +55 -0
  28. package/dist/cjs/execute/actions.d.ts.map +1 -0
  29. package/dist/cjs/execute/actions.js +49 -0
  30. package/dist/cjs/execute/busy.d.ts +74 -0
  31. package/dist/cjs/execute/busy.d.ts.map +1 -0
  32. package/dist/cjs/execute/busy.js +182 -0
  33. package/dist/cjs/execute/hooks.d.ts +62 -0
  34. package/dist/cjs/execute/hooks.d.ts.map +1 -0
  35. package/dist/cjs/execute/hooks.js +308 -0
  36. package/dist/cjs/execute/index.d.ts +7 -0
  37. package/dist/cjs/execute/index.d.ts.map +1 -0
  38. package/dist/cjs/execute/index.js +22 -0
  39. package/dist/cjs/execute/leaf.d.ts +26 -0
  40. package/dist/cjs/execute/leaf.d.ts.map +1 -0
  41. package/dist/cjs/execute/leaf.js +154 -0
  42. package/dist/cjs/execute/provider.d.ts +29 -0
  43. package/dist/cjs/execute/provider.d.ts.map +1 -0
  44. package/dist/cjs/execute/provider.js +126 -0
  45. package/dist/cjs/execute/reducer.d.ts +4 -0
  46. package/dist/cjs/execute/reducer.d.ts.map +1 -0
  47. package/dist/cjs/execute/reducer.js +136 -0
  48. package/dist/cjs/execute/selectors.d.ts +22 -0
  49. package/dist/cjs/execute/selectors.d.ts.map +1 -0
  50. package/dist/cjs/execute/selectors.js +89 -0
  51. package/dist/cjs/execute/types.d.ts +49 -0
  52. package/dist/cjs/execute/types.d.ts.map +1 -0
  53. package/dist/cjs/execute/types.js +2 -0
  54. package/dist/cjs/execute/utils.d.ts +23 -0
  55. package/dist/cjs/execute/utils.d.ts.map +1 -0
  56. package/dist/cjs/execute/utils.js +62 -0
  57. package/dist/cjs/index.d.ts +6 -1
  58. package/dist/cjs/index.d.ts.map +1 -1
  59. package/dist/cjs/index.js +6 -1
  60. package/dist/cjs/jupyter.d.ts.map +1 -1
  61. package/dist/cjs/jupyter.js +18 -19
  62. package/dist/cjs/output.js +2 -2
  63. package/dist/cjs/providers.d.ts +1 -48
  64. package/dist/cjs/providers.d.ts.map +1 -1
  65. package/dist/cjs/providers.js +4 -155
  66. package/dist/esm/ConnectionStatusTray.d.ts.map +1 -1
  67. package/dist/esm/ConnectionStatusTray.js +7 -5
  68. package/dist/esm/ErrorTray.d.ts +5 -0
  69. package/dist/esm/ErrorTray.d.ts.map +1 -0
  70. package/dist/esm/ErrorTray.js +30 -0
  71. package/dist/esm/controls/ArticleCellControls.d.ts +10 -0
  72. package/dist/esm/controls/ArticleCellControls.d.ts.map +1 -0
  73. package/dist/esm/controls/ArticleCellControls.js +27 -0
  74. package/dist/esm/controls/Buttons.d.ts +47 -0
  75. package/dist/esm/controls/Buttons.d.ts.map +1 -0
  76. package/dist/esm/controls/Buttons.js +57 -0
  77. package/dist/esm/controls/NotebookCellControls.d.ts +10 -0
  78. package/dist/esm/controls/NotebookCellControls.d.ts.map +1 -0
  79. package/dist/esm/controls/NotebookCellControls.js +21 -0
  80. package/dist/esm/controls/NotebookToolbar.d.ts +4 -0
  81. package/dist/esm/controls/NotebookToolbar.d.ts.map +1 -0
  82. package/dist/esm/controls/NotebookToolbar.js +40 -0
  83. package/dist/esm/controls/Spinner.d.ts +4 -0
  84. package/dist/esm/controls/Spinner.d.ts.map +1 -0
  85. package/dist/esm/controls/Spinner.js +4 -0
  86. package/dist/esm/controls/index.d.ts +5 -0
  87. package/dist/esm/controls/index.d.ts.map +1 -0
  88. package/dist/esm/controls/index.js +4 -0
  89. package/dist/esm/embed.d.ts +4 -0
  90. package/dist/esm/embed.d.ts.map +1 -0
  91. package/dist/esm/embed.js +20 -0
  92. package/dist/esm/execute/actions.d.ts +55 -0
  93. package/dist/esm/execute/actions.d.ts.map +1 -0
  94. package/dist/esm/execute/actions.js +38 -0
  95. package/dist/esm/execute/busy.d.ts +74 -0
  96. package/dist/esm/execute/busy.d.ts.map +1 -0
  97. package/dist/esm/execute/busy.js +150 -0
  98. package/dist/esm/execute/hooks.d.ts +62 -0
  99. package/dist/esm/execute/hooks.d.ts.map +1 -0
  100. package/dist/esm/execute/hooks.js +277 -0
  101. package/dist/esm/execute/index.d.ts +7 -0
  102. package/dist/esm/execute/index.d.ts.map +1 -0
  103. package/dist/esm/execute/index.js +6 -0
  104. package/dist/esm/execute/leaf.d.ts +26 -0
  105. package/dist/esm/execute/leaf.d.ts.map +1 -0
  106. package/dist/esm/execute/leaf.js +147 -0
  107. package/dist/esm/execute/provider.d.ts +29 -0
  108. package/dist/esm/execute/provider.d.ts.map +1 -0
  109. package/dist/esm/execute/provider.js +99 -0
  110. package/dist/esm/execute/reducer.d.ts +4 -0
  111. package/dist/esm/execute/reducer.d.ts.map +1 -0
  112. package/dist/esm/execute/reducer.js +132 -0
  113. package/dist/esm/execute/selectors.d.ts +22 -0
  114. package/dist/esm/execute/selectors.d.ts.map +1 -0
  115. package/dist/esm/execute/selectors.js +77 -0
  116. package/dist/esm/execute/types.d.ts +49 -0
  117. package/dist/esm/execute/types.d.ts.map +1 -0
  118. package/dist/esm/execute/types.js +1 -0
  119. package/dist/esm/execute/utils.d.ts +23 -0
  120. package/dist/esm/execute/utils.d.ts.map +1 -0
  121. package/dist/esm/execute/utils.js +58 -0
  122. package/dist/esm/index.d.ts +6 -1
  123. package/dist/esm/index.d.ts.map +1 -1
  124. package/dist/esm/index.js +6 -1
  125. package/dist/esm/jupyter.d.ts.map +1 -1
  126. package/dist/esm/jupyter.js +16 -17
  127. package/dist/esm/output.js +2 -2
  128. package/dist/esm/providers.d.ts +1 -48
  129. package/dist/esm/providers.d.ts.map +1 -1
  130. package/dist/esm/providers.js +2 -126
  131. package/dist/types/ConnectionStatusTray.d.ts.map +1 -1
  132. package/dist/types/ErrorTray.d.ts +5 -0
  133. package/dist/types/ErrorTray.d.ts.map +1 -0
  134. package/dist/types/controls/ArticleCellControls.d.ts +10 -0
  135. package/dist/types/controls/ArticleCellControls.d.ts.map +1 -0
  136. package/dist/types/controls/Buttons.d.ts +47 -0
  137. package/dist/types/controls/Buttons.d.ts.map +1 -0
  138. package/dist/types/controls/NotebookCellControls.d.ts +10 -0
  139. package/dist/types/controls/NotebookCellControls.d.ts.map +1 -0
  140. package/dist/types/controls/NotebookToolbar.d.ts +4 -0
  141. package/dist/types/controls/NotebookToolbar.d.ts.map +1 -0
  142. package/dist/types/controls/Spinner.d.ts +4 -0
  143. package/dist/types/controls/Spinner.d.ts.map +1 -0
  144. package/dist/types/controls/index.d.ts +5 -0
  145. package/dist/types/controls/index.d.ts.map +1 -0
  146. package/dist/types/embed.d.ts +4 -0
  147. package/dist/types/embed.d.ts.map +1 -0
  148. package/dist/types/execute/actions.d.ts +55 -0
  149. package/dist/types/execute/actions.d.ts.map +1 -0
  150. package/dist/types/execute/busy.d.ts +74 -0
  151. package/dist/types/execute/busy.d.ts.map +1 -0
  152. package/dist/types/execute/hooks.d.ts +62 -0
  153. package/dist/types/execute/hooks.d.ts.map +1 -0
  154. package/dist/types/execute/index.d.ts +7 -0
  155. package/dist/types/execute/index.d.ts.map +1 -0
  156. package/dist/types/execute/leaf.d.ts +26 -0
  157. package/dist/types/execute/leaf.d.ts.map +1 -0
  158. package/dist/types/execute/provider.d.ts +29 -0
  159. package/dist/types/execute/provider.d.ts.map +1 -0
  160. package/dist/types/execute/reducer.d.ts +4 -0
  161. package/dist/types/execute/reducer.d.ts.map +1 -0
  162. package/dist/types/execute/selectors.d.ts +22 -0
  163. package/dist/types/execute/selectors.d.ts.map +1 -0
  164. package/dist/types/execute/types.d.ts +49 -0
  165. package/dist/types/execute/types.d.ts.map +1 -0
  166. package/dist/types/execute/utils.d.ts +23 -0
  167. package/dist/types/execute/utils.d.ts.map +1 -0
  168. package/dist/types/index.d.ts +6 -1
  169. package/dist/types/index.d.ts.map +1 -1
  170. package/dist/types/jupyter.d.ts.map +1 -1
  171. package/dist/types/providers.d.ts +1 -48
  172. package/dist/types/providers.d.ts.map +1 -1
  173. package/package.json +9 -8
@@ -0,0 +1,99 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { SourceFileKind } from 'myst-common';
3
+ import React, { useEffect, useReducer, useRef } from 'react';
4
+ import { selectAll } from 'unist-util-select';
5
+ import { reducer } from './reducer';
6
+ import { selectAreAllDependenciesReady, selectDependenciesToFetch, selectScopeNotebooksToBuild, selectSessionsToStart, } from './selectors';
7
+ import { MdastFetcher, NotebookBuilder, ServerMonitor, SessionStarter } from './leaf';
8
+ export const ExecuteScopeContext = React.createContext(undefined);
9
+ function useScopeNavigate({ contents: { slug, kind, mdast, dependencies }, state, dispatch, }) {
10
+ useEffect(() => {
11
+ if (state.pages[slug]) {
12
+ console.debug(`Jupyter: ExecuteScopeProvider - ${slug} is already in scope`);
13
+ return;
14
+ }
15
+ const computables = selectAll('container > embed', mdast).map((node) => {
16
+ const { key, label, source } = node;
17
+ const output = selectAll('output', node);
18
+ if (output.length === 0)
19
+ console.error(`embed must have exactly one output ${key}`);
20
+ if (output.length > 1)
21
+ console.warn(`embed has more than one output block ${key}}`);
22
+ return { embedKey: key, outputKey: output[0].key, label, source };
23
+ });
24
+ dispatch({
25
+ type: 'NAVIGATE',
26
+ payload: {
27
+ kind: kind,
28
+ slug: slug,
29
+ mdast: mdast,
30
+ dependencies: dependencies !== null && dependencies !== void 0 ? dependencies : [],
31
+ computables,
32
+ },
33
+ });
34
+ }, [slug]);
35
+ }
36
+ function useExecutionScopeFetcher({ slug, state, dispatch, }) {
37
+ useEffect(() => {
38
+ if (!state.builds[slug])
39
+ return;
40
+ // TODO could be moved to the leaf
41
+ if (state.builds[slug].status === 'pending') {
42
+ dispatch({ type: 'BUILD_STATUS', payload: { slug, status: 'fetching' } });
43
+ }
44
+ // TODO could be moved to the leaf
45
+ if (state.builds[slug].status === 'fetching') {
46
+ if (selectAreAllDependenciesReady(state, slug)) {
47
+ dispatch({ type: 'BUILD_STATUS', payload: { slug, status: 'build-notebooks' } });
48
+ }
49
+ }
50
+ }, [state.builds, state.mdast]);
51
+ }
52
+ /**
53
+ * The ExecuteScopeProvider is responsible for maintaining the state of the
54
+ * execution scope. It is also responsible for fetching the json for dependencies
55
+ * and adding them to the sources tree.
56
+ */
57
+ export function ExecuteScopeProvider({ children, contents, }) {
58
+ var _a;
59
+ // compute incoming for first render
60
+ const computables = selectAll('container > embed', contents.mdast).map((node) => {
61
+ const { key, label, source } = node;
62
+ const output = selectAll('output', node);
63
+ if (output.length === 0)
64
+ console.error(`embed must have exactly one output ${key}`);
65
+ if (output.length > 1)
66
+ console.warn(`embed has mpre than one output block ${key}}`);
67
+ return { embedKey: key, outputKey: output[0].key, label, source };
68
+ });
69
+ const initialState = {
70
+ mdast: {
71
+ [contents.slug]: { root: contents.mdast },
72
+ },
73
+ pages: {
74
+ [contents.slug]: {
75
+ computable: computables.length > 0 || contents.kind === SourceFileKind.Notebook,
76
+ kind: contents.kind,
77
+ slug: contents.slug,
78
+ dependencies: (_a = contents.dependencies) !== null && _a !== void 0 ? _a : [],
79
+ computables,
80
+ ready: false,
81
+ scopes: {},
82
+ },
83
+ },
84
+ builds: {},
85
+ };
86
+ const [state, dispatch] = useReducer(reducer, initialState);
87
+ const idkmap = useRef({});
88
+ useScopeNavigate({ contents, state: state, dispatch });
89
+ // TODO phase this out as it is based on the current slug only!
90
+ useExecutionScopeFetcher({ slug: contents.slug, state: state, dispatch });
91
+ const fetchTargets = selectDependenciesToFetch(state);
92
+ const notebookBuildTargets = selectScopeNotebooksToBuild(state);
93
+ const sessionStartTargets = selectSessionsToStart(state);
94
+ const memo = React.useMemo(() => ({ slug: contents.slug, state, dispatch, idkmap: idkmap.current }), [state, contents.slug]);
95
+ if (typeof window !== 'undefined') {
96
+ window.executeScope = memo;
97
+ }
98
+ return (_jsxs(ExecuteScopeContext.Provider, { value: memo, children: [_jsxs("div", { className: "hidden", children: [fetchTargets.length > 0 && (_jsx("div", { className: "p-1 pl-4", children: fetchTargets.map(({ slug, url }) => (_jsx(MdastFetcher, { slug: slug, url: url, dispatch: dispatch }, `fetch-${slug}`))) })), notebookBuildTargets.length > 0 && (_jsx("div", { className: "p-1 pl-4", children: notebookBuildTargets.map(({ pageSlug, notebookSlug }) => (_jsx(NotebookBuilder, { pageSlug: pageSlug, notebookSlug: notebookSlug, idkmap: idkmap.current, state: state, dispatch: dispatch }, `build-${pageSlug}-${notebookSlug}`))) })), sessionStartTargets.length > 0 && (_jsx("div", { className: "p-1 pl-4", children: sessionStartTargets.map(({ pageSlug, notebookSlug }) => (_jsx(SessionStarter, { pageSlug: pageSlug, notebookSlug: notebookSlug, state: state, dispatch: dispatch }, `session-${pageSlug}-${notebookSlug}`))) }))] }), _jsx(ServerMonitor, { state: state, dispatch: dispatch }), children] }));
99
+ }
@@ -0,0 +1,4 @@
1
+ import type { ExecuteScopeAction } from './actions';
2
+ import type { ExecuteScopeState } from './types';
3
+ export declare function reducer(state: ExecuteScopeState, action: ExecuteScopeAction): ExecuteScopeState;
4
+ //# sourceMappingURL=reducer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../../src/execute/reducer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AASpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,wBAAgB,OAAO,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,GAAG,iBAAiB,CAuL/F"}
@@ -0,0 +1,132 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { SourceFileKind } from 'myst-common';
13
+ import { isAddMdastPayload, isAddNotebookPayload, isAddSessionPayload, isBuildStatusPayload, isNavigatePayload, isSlugPayload, } from './actions';
14
+ export function reducer(state, action) {
15
+ switch (action.type) {
16
+ case 'NAVIGATE': {
17
+ if (!isNavigatePayload(action.payload)) {
18
+ console.error(action.payload);
19
+ throw new Error('invalid NAVIGATE payload');
20
+ }
21
+ const { kind, slug, mdast, dependencies, computables } = action.payload;
22
+ if (state.pages[slug])
23
+ return state;
24
+ return Object.assign(Object.assign({}, state), { mdast: Object.assign(Object.assign({}, state.mdast), { [slug]: { root: mdast } }), pages: Object.assign(Object.assign({}, state.pages), { [slug]: {
25
+ kind,
26
+ slug,
27
+ dependencies,
28
+ computables,
29
+ computable: computables.length > 0 || kind === SourceFileKind.Notebook,
30
+ ready: false,
31
+ scopes: {},
32
+ } }) });
33
+ }
34
+ case 'ADD_MDAST': {
35
+ if (!isAddMdastPayload(action.payload)) {
36
+ console.error(action.payload);
37
+ throw new Error('invalid ADD_MDAST payload');
38
+ }
39
+ const { slug, mdast } = action.payload;
40
+ if (state.mdast[slug])
41
+ return state;
42
+ return Object.assign(Object.assign({}, state), { mdast: Object.assign(Object.assign({}, state.mdast), { [slug]: { root: mdast } }) });
43
+ }
44
+ case 'REQUEST_BUILD': {
45
+ if (!isSlugPayload(action.payload)) {
46
+ console.error(action.payload);
47
+ throw new Error('invalid REQUEST_BUILD payload');
48
+ }
49
+ const { slug } = action.payload;
50
+ if (!!state.builds[slug] && state.builds[slug].status === 'pending')
51
+ return state;
52
+ return Object.assign(Object.assign({}, state), { builds: Object.assign(Object.assign({}, state.builds), { [slug]: {
53
+ status: 'pending',
54
+ } }) });
55
+ }
56
+ case 'BUILD_STATUS': {
57
+ if (!isBuildStatusPayload(action.payload)) {
58
+ console.error(action.payload);
59
+ throw new Error('invalid BUILD_STATUS payload');
60
+ }
61
+ const { slug } = action.payload;
62
+ if (!state.builds[slug]) {
63
+ console.error(state, action.payload);
64
+ throw new Error('Trying to set build status when there is no build state');
65
+ }
66
+ if (state.builds[slug].status === action.payload.status)
67
+ return state;
68
+ return Object.assign(Object.assign({}, state), { builds: Object.assign(Object.assign({}, state.builds), { [slug]: Object.assign(Object.assign({}, state.builds[slug]), { status: action.payload.status }) }) });
69
+ }
70
+ case 'CLEAR_BUILD': {
71
+ if (!isSlugPayload(action.payload)) {
72
+ console.error(action.payload);
73
+ throw new Error('invalid CLEAR_BUILD payload');
74
+ }
75
+ const { slug } = action.payload;
76
+ if (!state.builds[slug])
77
+ return state;
78
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
79
+ const _a = state.builds, _b = slug, _ = _a[_b], builds = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
80
+ return Object.assign(Object.assign({}, state), { builds });
81
+ }
82
+ case 'SET_RENDERING_READY': {
83
+ if (!isSlugPayload(action.payload)) {
84
+ console.error(action.payload);
85
+ throw new Error('invalid SET_READY payload');
86
+ }
87
+ const { slug } = action.payload;
88
+ if (state.pages[slug].ready)
89
+ return state;
90
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
91
+ const _c = state.builds, _d = slug, _ = _c[_d], builds = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
92
+ const newState = Object.assign(Object.assign({}, state), { builds, pages: Object.assign(Object.assign({}, state.pages), { [slug]: Object.assign(Object.assign({}, state.pages[slug]), { ready: true }) }) });
93
+ return newState;
94
+ }
95
+ case 'ADD_NOTEBOOK': {
96
+ if (!isAddNotebookPayload(action.payload)) {
97
+ console.error(action.payload);
98
+ throw new Error('invalid ADD_NOTEBOOK payload');
99
+ }
100
+ const { pageSlug, notebookSlug, notebook, rendermime } = action.payload;
101
+ if (!state.pages[pageSlug]) {
102
+ console.error(state, action.payload);
103
+ throw new Error('Trying to add notebook when there is no rendering state');
104
+ }
105
+ if (state.pages[pageSlug].scopes[notebookSlug]) {
106
+ console.warn('Trying to add notebook scope when rendering already has one', action.payload);
107
+ return state;
108
+ }
109
+ return Object.assign(Object.assign({}, state), { pages: Object.assign(Object.assign({}, state.pages), { [pageSlug]: Object.assign(Object.assign({}, state.pages[pageSlug]), { scopes: Object.assign(Object.assign({}, state.pages[pageSlug].scopes), { [notebookSlug]: {
110
+ notebook,
111
+ rendermime,
112
+ } }) }) }) });
113
+ }
114
+ case 'ADD_SESSION': {
115
+ if (!isAddSessionPayload(action.payload)) {
116
+ console.error(action.payload);
117
+ throw new Error('invalid ADD_SESSION payload');
118
+ }
119
+ const { pageSlug, notebookSlug, session } = action.payload;
120
+ if (!state.pages[pageSlug]) {
121
+ console.error(state, action.payload);
122
+ throw new Error('Trying to add session when there is no rendering state');
123
+ }
124
+ if (state.pages[pageSlug].scopes[notebookSlug].session) {
125
+ console.warn('Trying to add session scope when rendering already has one', action.payload);
126
+ return state;
127
+ }
128
+ return Object.assign(Object.assign({}, state), { pages: Object.assign(Object.assign({}, state.pages), { [pageSlug]: Object.assign(Object.assign({}, state.pages[pageSlug]), { scopes: Object.assign(Object.assign({}, state.pages[pageSlug].scopes), { [notebookSlug]: Object.assign(Object.assign({}, state.pages[pageSlug].scopes[notebookSlug]), { session }) }) }) }) });
129
+ }
130
+ }
131
+ return state;
132
+ }
@@ -0,0 +1,22 @@
1
+ import type { BuildStatus, ExecuteScopeState } from './types';
2
+ export declare function selectIsComputable(state: ExecuteScopeState, slug: string): boolean;
3
+ export declare function selectAreExecutionScopesReady(state: ExecuteScopeState, slug: string): boolean;
4
+ export declare function selectAreExecutionScopesBuilding(state: ExecuteScopeState, slug: string): boolean;
5
+ export declare function selectExecutionScopeStatus(state: ExecuteScopeState, slug: string): BuildStatus | "ready";
6
+ export declare function selectDependenciesToFetch(state: ExecuteScopeState): {
7
+ slug: string;
8
+ url: string;
9
+ }[];
10
+ export declare const selectScopeNotebooksToBuild: (state: ExecuteScopeState) => {
11
+ pageSlug: string;
12
+ notebookSlug: string;
13
+ }[];
14
+ export declare const selectSessionsToStart: (state: ExecuteScopeState) => {
15
+ pageSlug: string;
16
+ notebookSlug: string;
17
+ }[];
18
+ export declare function selectAreAllDependenciesReady(state: ExecuteScopeState, slug: string): boolean;
19
+ export declare function selectAreAllNotebookScopesBuilt(state: ExecuteScopeState, slug: string): boolean;
20
+ export declare function selectAreAllSessionsStarted(state: ExecuteScopeState, slug: string): boolean;
21
+ export declare function selectNotebookCellIds(state: ExecuteScopeState, pageSlug: string, notebookSlug: string): string[];
22
+ //# sourceMappingURL=selectors.d.ts.map
@@ -0,0 +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,IAAI,EAAE,MAAM,WAExE;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,WAEnF;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,WAEtF;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,yBAEhF;AAQD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,iBAAiB;UAKpD,MAAM;SACP,MAAM;IAclB;AAsBD,eAAO,MAAM,2BAA2B,UAlBvB,iBAAiB,KAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,EAkBS,CAAC;AACzF,eAAO,MAAM,qBAAqB,UAnBjB,iBAAiB,KAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,EAmBC,CAAC;AAEjF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,WAEnF;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,WAGrF;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,WAIjF;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,YAGrB"}
@@ -0,0 +1,77 @@
1
+ import { SourceFileKind } from 'myst-common';
2
+ export function selectIsComputable(state, slug) {
3
+ var _a, _b;
4
+ return (_b = (_a = state.pages[slug]) === null || _a === void 0 ? void 0 : _a.computable) !== null && _b !== void 0 ? _b : false;
5
+ }
6
+ export function selectAreExecutionScopesReady(state, slug) {
7
+ var _a;
8
+ return (_a = state.pages[slug]) === null || _a === void 0 ? void 0 : _a.ready;
9
+ }
10
+ export function selectAreExecutionScopesBuilding(state, slug) {
11
+ var _a;
12
+ return !((_a = state.pages[slug]) === null || _a === void 0 ? void 0 : _a.ready) && !!state.builds[slug];
13
+ }
14
+ export function selectExecutionScopeStatus(state, slug) {
15
+ var _a, _b, _c;
16
+ return ((_a = state.pages[slug]) === null || _a === void 0 ? void 0 : _a.ready) ? 'ready' : (_c = (_b = state.builds[slug]) === null || _b === void 0 ? void 0 : _b.status) !== null && _c !== void 0 ? _c : 'unknown';
17
+ }
18
+ //
19
+ // The following teo functions are ripe for generaizing but also it would be good to
20
+ // see if we can memoize them, potentially with reselect.
21
+ //
22
+ // TODO Memoize?
23
+ export function selectDependenciesToFetch(state) {
24
+ return Object.entries(state.builds)
25
+ .filter(([, { status }]) => status === 'fetching')
26
+ .reduce((targets, [slug]) => [
27
+ ...targets,
28
+ ...state.pages[slug].dependencies
29
+ .filter((d) => { var _a; return !state.mdast[(_a = d.slug) !== null && _a !== void 0 ? _a : d.url]; })
30
+ .map((d) => {
31
+ var _a;
32
+ return ({
33
+ slug: (_a = d.slug) !== null && _a !== void 0 ? _a : d.url,
34
+ url: d.url,
35
+ });
36
+ }),
37
+ ], []);
38
+ }
39
+ // // TODO Memoize?
40
+ function makeSelectScopeEventStatus(statusName) {
41
+ return (state) => {
42
+ return Object.entries(state.builds)
43
+ .filter(([, { status }]) => status === statusName)
44
+ .reduce((all, [slug]) => {
45
+ const targets = [];
46
+ if (state.pages[slug].kind === SourceFileKind.Notebook)
47
+ targets.push({ pageSlug: slug, notebookSlug: slug });
48
+ targets.push(...state.pages[slug].dependencies.map((d) => {
49
+ var _a;
50
+ return ({
51
+ pageSlug: slug,
52
+ notebookSlug: (_a = d.slug) !== null && _a !== void 0 ? _a : d.url,
53
+ });
54
+ }));
55
+ return [...all, ...targets];
56
+ }, []);
57
+ };
58
+ }
59
+ export const selectScopeNotebooksToBuild = makeSelectScopeEventStatus('build-notebooks');
60
+ export const selectSessionsToStart = makeSelectScopeEventStatus('start-session');
61
+ export function selectAreAllDependenciesReady(state, slug) {
62
+ var _a;
63
+ return (_a = state.pages[slug]) === null || _a === void 0 ? void 0 : _a.dependencies.every((dep) => { var _a; return !!state.mdast[(_a = dep.slug) !== null && _a !== void 0 ? _a : dep.url]; });
64
+ }
65
+ export function selectAreAllNotebookScopesBuilt(state, slug) {
66
+ const rendering = state.pages[slug];
67
+ return rendering === null || rendering === void 0 ? void 0 : rendering.dependencies.every((dep) => { var _a; return !!rendering.scopes[(_a = dep.slug) !== null && _a !== void 0 ? _a : dep.url]; });
68
+ }
69
+ export function selectAreAllSessionsStarted(state, slug) {
70
+ const rendering = state.pages[slug];
71
+ // TODO is this working??
72
+ return rendering === null || rendering === void 0 ? void 0 : rendering.dependencies.every((dep) => { var _a, _b; return !!((_b = rendering.scopes[(_a = dep.slug) !== null && _a !== void 0 ? _a : dep.url]) === null || _b === void 0 ? void 0 : _b.session); });
73
+ }
74
+ export function selectNotebookCellIds(state, pageSlug, notebookSlug) {
75
+ var _a, _b, _c, _d;
76
+ return (_d = (_c = (_b = (_a = state.pages[pageSlug]) === null || _a === void 0 ? void 0 : _a.scopes[notebookSlug]) === null || _b === void 0 ? void 0 : _b.notebook) === null || _c === void 0 ? void 0 : _c.cells.map(({ id }) => id)) !== null && _d !== void 0 ? _d : [];
77
+ }
@@ -0,0 +1,49 @@
1
+ import type { Root } from 'mdast';
2
+ import type { SourceFileKind, Dependency } from 'myst-common';
3
+ import type { IRenderMimeRegistry, ThebeNotebook, ThebeSession } from 'thebe-core';
4
+ export type BuildStatus = 'pending' | 'fetching' | 'build-notebooks' | 'wait-for-server' | 'start-session' | 'error';
5
+ export type IdOrKey = string;
6
+ export type CellId = string;
7
+ export type IdKeyMapTarget = {
8
+ pageSlug: string;
9
+ notebookSlug: string;
10
+ cellId: CellId;
11
+ };
12
+ export type IdKeyMap = Record<IdOrKey, IdKeyMapTarget>;
13
+ export interface ExecuteScopeState {
14
+ mdast: {
15
+ [slug: string]: {
16
+ root: Root;
17
+ };
18
+ };
19
+ pages: {
20
+ [pageSlug: string]: {
21
+ slug: string;
22
+ kind: SourceFileKind;
23
+ computable: boolean;
24
+ dependencies: Dependency[];
25
+ computables: Computable[];
26
+ ready: boolean;
27
+ scopes: {
28
+ [notebookSlug: string]: ExecutionScope;
29
+ };
30
+ };
31
+ };
32
+ builds: {
33
+ [pageSlug: string]: {
34
+ status: BuildStatus;
35
+ };
36
+ };
37
+ }
38
+ export interface ExecutionScope {
39
+ rendermime: IRenderMimeRegistry;
40
+ notebook: ThebeNotebook;
41
+ session?: ThebeSession;
42
+ }
43
+ export interface Computable {
44
+ embedKey: string;
45
+ outputKey: string;
46
+ label: string;
47
+ source: Dependency;
48
+ }
49
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/execute/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnF,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,UAAU,GACV,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,OAAO,CAAC;AAEZ,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAC7B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAC5B,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AACxF,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAEvD,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE;QACL,CAAC,IAAI,EAAE,MAAM,GAAG;YACd,IAAI,EAAE,IAAI,CAAC;SACZ,CAAC;KACH,CAAC;IACF,KAAK,EAAE;QACL,CAAC,QAAQ,EAAE,MAAM,GAAG;YAClB,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,cAAc,CAAC;YACrB,UAAU,EAAE,OAAO,CAAC;YACpB,YAAY,EAAE,UAAU,EAAE,CAAC;YAC3B,WAAW,EAAE,UAAU,EAAE,CAAC;YAC1B,KAAK,EAAE,OAAO,CAAC;YACf,MAAM,EAAE;gBACN,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,CAAC;aACxC,CAAC;SACH,CAAC;KACH,CAAC;IACF,MAAM,EAAE;QACN,CAAC,QAAQ,EAAE,MAAM,GAAG;YAClB,MAAM,EAAE,WAAW,CAAC;SACrB,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,mBAAmB,CAAC;IAChC,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,CAAC;CACpB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -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,58 @@
1
+ /**
2
+ * Use the mdast to create a ThebeNotebook from the mdast tree of a notebook.
3
+ * This is intended to be used to create an independent ThebeNotebook instance
4
+ * for each notebook in a rendering context.
5
+ *
6
+ * NOTE: there is no need to scope the keys at this point, as the ThebeNotebook
7
+ * instance will be scoped to the render context. All underlying cells will be
8
+ * identified by keys from the mdast - so there may be duplicate ids between different
9
+ * notebook instances, but that is ok as they came from the same mdast which is readonly.
10
+ *
11
+ * @param core
12
+ * @param config
13
+ * @param pageSlug - slug identifying the render context used for key decoration
14
+ * @param mdast - the notebook mdast
15
+ * @param idkmap - map of scoped block keys to keys for code and output cells
16
+ * @param rendermime
17
+ * @returns
18
+ */
19
+ export function notebookFromMdast(core, config, pageSlug, notebookSlug, mdast, idkmap, rendermime) {
20
+ // note the notebooks slug is used as the notebook id, this means accross pages
21
+ // mulitple notebooks with the same slug will be present but scoped to different pages
22
+ // the busyScope mecahnism relies on the notebookSlug as id
23
+ const notebook = new core.ThebeNotebook(notebookSlug, config, rendermime);
24
+ // no metadata included in mdast yet
25
+ //Object.assign(notebook.metadata, ipynb.metadata);
26
+ notebook.cells = mdast.children.map((block) => {
27
+ var _a, _b, _c;
28
+ if (block.type !== 'block')
29
+ console.warn(`Unexpected block type ${block.type}`);
30
+ if (block.children.length == 2 && block.children[0].type === 'code') {
31
+ const [codeCell, output] = block.children;
32
+ // use the block.key to identify the cell but maintain a mapping
33
+ // to allow code or output keys to look up cells and refs and idenifity
34
+ // the cell in the correct notebook
35
+ const target = {
36
+ pageSlug,
37
+ notebookSlug,
38
+ cellId: block.key,
39
+ };
40
+ idkmap[block.key] = target;
41
+ idkmap[codeCell.key] = target;
42
+ idkmap[output.key] = target;
43
+ // include block labels to enable lookup by from embedded blocks
44
+ if (block.label)
45
+ idkmap[block.label] = target;
46
+ if (block.identifier)
47
+ idkmap[block.identifier] = target;
48
+ 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);
49
+ }
50
+ else {
51
+ // assume content - concatenate it
52
+ // TODO inject cell metadata
53
+ 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);
54
+ return cell;
55
+ }
56
+ });
57
+ return notebook;
58
+ }
@@ -1,9 +1,14 @@
1
+ import { Embed } from './embed';
1
2
  import { Output } from './output';
2
3
  declare const OUTPUT_RENDERERS: {
3
4
  output: typeof Output;
5
+ embed: typeof Embed;
4
6
  };
5
7
  export * from './BinderBadge';
6
- export * from './providers';
8
+ export * from './ErrorTray';
7
9
  export * from './ConnectionStatusTray';
10
+ export * from './providers';
11
+ export * from './execute';
12
+ export * from './controls';
8
13
  export default OUTPUT_RENDERERS;
9
14
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAEvC,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAA,MAAM,gBAAgB;;;CAGrB,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,eAAe,gBAAgB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,8 +1,13 @@
1
+ import { Embed } from './embed';
1
2
  import { Output } from './output';
2
3
  const OUTPUT_RENDERERS = {
3
4
  output: Output,
5
+ embed: Embed,
4
6
  };
5
7
  export * from './BinderBadge';
6
- export * from './providers';
8
+ export * from './ErrorTray';
7
9
  export * from './ConnectionStatusTray';
10
+ export * from './providers';
11
+ export * from './execute';
12
+ export * from './controls';
8
13
  export 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;AAyD3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAiD1D,CAAC"}
1
+ {"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAmE3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAmD1D,CAAC"}
@@ -3,30 +3,29 @@ import React, { useEffect, useRef, useState } from 'react';
3
3
  import { useFetchAnyTruncatedContent } from './hooks';
4
4
  import { convertToIOutputs } from 'nbtx';
5
5
  import { fetchAndEncodeOutputImages } from './convertImages';
6
- import { useNotebookCellExecution } from './providers';
7
6
  import { SourceFileKind } from 'myst-common';
8
7
  import { useXRefState } from '@myst-theme/providers';
9
8
  import { useThebeLoader } from 'thebe-react';
10
- function ActiveOutputRenderer({ id, data }) {
11
- const exec = useNotebookCellExecution(id);
9
+ import { useCellExecution } from './execute';
10
+ function ActiveOutputRenderer({ id, initialData, core, }) {
11
+ const exec = useCellExecution(id);
12
12
  const ref = useRef(null);
13
13
  useEffect(() => {
14
- var _a;
14
+ var _a, _b, _c;
15
15
  if (!ref.current || !(exec === null || exec === void 0 ? void 0 : exec.cell)) {
16
- 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}`);
17
- return;
18
- }
19
- if (exec.cell.isAttachedToDOM) {
20
- console.debug(`Cell ${exec.cell.id} already attached to DOM`);
16
+ console.debug(`Jupyter: No cell ref available for cell ${(_a = exec === null || exec === void 0 ? void 0 : exec.cell) === null || _a === void 0 ? void 0 : _a.id}`);
21
17
  return;
22
18
  }
23
- console.debug(`Attaching cell ${exec.cell.id} to DOM at:`, {
19
+ const verb = exec.cell.isAttachedToDOM ? 'reattaching' : 'attaching';
20
+ console.debug(`${verb} cell ${exec.cell.id} to DOM at:`, {
24
21
  el: ref.current,
25
22
  connected: ref.current.isConnected,
26
- data,
23
+ data: (_b = core === null || core === void 0 ? void 0 : core.stripWidgets(initialData)) !== null && _b !== void 0 ? _b : initialData,
27
24
  });
28
25
  exec.cell.attachToDOM(ref.current);
29
- exec.cell.render(data);
26
+ if (exec.cell.executionCount == null) {
27
+ exec.cell.initOutputs((_c = core === null || core === void 0 ? void 0 : core.stripWidgets(initialData)) !== null && _c !== void 0 ? _c : initialData);
28
+ }
30
29
  }, [ref === null || ref === void 0 ? void 0 : ref.current, exec === null || exec === void 0 ? void 0 : exec.cell]);
31
30
  return _jsx("div", { ref: ref, "data-thebe-active-ref": "true", className: "relative" });
32
31
  }
@@ -34,20 +33,20 @@ function PassiveOutputRenderer({ id, data, core, kind, }) {
34
33
  const cell = useRef(new core.PassiveCellRenderer(id, undefined, undefined));
35
34
  const ref = useRef(null);
36
35
  useEffect(() => {
36
+ var _a;
37
37
  if (!ref.current)
38
38
  return;
39
39
  cell.current.attachToDOM(ref.current, true);
40
- cell.current.render(data, kind === SourceFileKind.Article);
40
+ cell.current.render((_a = core === null || core === void 0 ? void 0 : core.stripWidgets(data)) !== null && _a !== void 0 ? _a : data);
41
41
  }, [ref]);
42
42
  return _jsx("div", { ref: ref, "data-thebe-passive-ref": "true" });
43
43
  }
44
44
  export const JupyterOutputs = React.memo(({ id, outputs }) => {
45
- var _a;
46
45
  const { core, load } = useThebeLoader();
47
46
  const { inCrossRef } = useXRefState();
48
47
  const { data, error } = useFetchAnyTruncatedContent(outputs);
49
48
  const [fullOutputs, setFullOutputs] = useState(null);
50
- const exec = useNotebookCellExecution(id);
49
+ const exec = useCellExecution(id);
51
50
  useEffect(() => {
52
51
  if (core)
53
52
  return;
@@ -66,7 +65,7 @@ export const JupyterOutputs = React.memo(({ id, outputs }) => {
66
65
  return _jsxs("div", { className: "text-red-500", children: ["Error rendering output: ", error.message] });
67
66
  }
68
67
  if (!inCrossRef && (exec === null || exec === void 0 ? void 0 : exec.ready)) {
69
- return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && _jsx(ActiveOutputRenderer, { id: id, data: fullOutputs })] }));
68
+ return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "Fetching full output data..." }), core && fullOutputs && (_jsx(ActiveOutputRenderer, { id: id, initialData: fullOutputs, core: core }, id))] }));
70
69
  }
71
- return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && core && (_jsx(PassiveOutputRenderer, { id: id, data: fullOutputs, core: core, kind: (_a = exec === null || exec === void 0 ? void 0 : exec.kind) !== null && _a !== void 0 ? _a : SourceFileKind.Notebook }))] }));
70
+ return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && core && (_jsx(PassiveOutputRenderer, { id: id, data: fullOutputs, core: core, kind: SourceFileKind.Notebook }))] }));
72
71
  });
@@ -3,8 +3,8 @@ import { KnownCellOutputMimeTypes } from 'nbtx';
3
3
  import classNames from 'classnames';
4
4
  import { SafeOutputs } from './safe';
5
5
  import { JupyterOutputs } from './jupyter';
6
- import { useReadyToExecute } from './providers';
7
6
  import { useMemo } from 'react';
7
+ import { useCellExecution } from './execute';
8
8
  export const DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);
9
9
  export const DIRECT_MIME_TYPES = new Set([
10
10
  KnownCellOutputMimeTypes.TextPlain,
@@ -26,7 +26,7 @@ export function allOutputsAreSafe(outputs, directOutputTypes, directMimeTypes) {
26
26
  }, true);
27
27
  }
28
28
  function JupyterOutput({ nodeKey, nodeType, identifier, data, align, }) {
29
- const ready = useReadyToExecute();
29
+ const { ready } = useCellExecution(nodeKey);
30
30
  const outputs = data;
31
31
  const allSafe = useMemo(() => allOutputsAreSafe(outputs, DIRECT_OUTPUT_TYPES, DIRECT_MIME_TYPES), [outputs]);
32
32
  let component;