@myst-theme/jupyter 0.3.2 → 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.
Files changed (176) hide show
  1. package/dist/cjs/ConnectionStatusTray.d.ts +2 -0
  2. package/dist/cjs/ConnectionStatusTray.d.ts.map +1 -0
  3. package/dist/cjs/ConnectionStatusTray.js +56 -0
  4. package/dist/cjs/ErrorTray.d.ts +5 -0
  5. package/dist/cjs/ErrorTray.d.ts.map +1 -0
  6. package/dist/cjs/ErrorTray.js +34 -0
  7. package/dist/cjs/controls/ArticleCellControls.d.ts +10 -0
  8. package/dist/cjs/controls/ArticleCellControls.d.ts.map +1 -0
  9. package/dist/cjs/controls/ArticleCellControls.js +33 -0
  10. package/dist/cjs/controls/Buttons.d.ts +47 -0
  11. package/dist/cjs/controls/Buttons.d.ts.map +1 -0
  12. package/dist/cjs/controls/Buttons.js +70 -0
  13. package/dist/cjs/controls/NotebookCellControls.d.ts +10 -0
  14. package/dist/cjs/controls/NotebookCellControls.d.ts.map +1 -0
  15. package/dist/cjs/controls/NotebookCellControls.js +27 -0
  16. package/dist/cjs/controls/NotebookToolbar.d.ts +4 -0
  17. package/dist/cjs/controls/NotebookToolbar.d.ts.map +1 -0
  18. package/dist/cjs/controls/NotebookToolbar.js +47 -0
  19. package/dist/cjs/controls/Spinner.d.ts +4 -0
  20. package/dist/cjs/controls/Spinner.d.ts.map +1 -0
  21. package/dist/cjs/controls/Spinner.js +8 -0
  22. package/dist/cjs/controls/index.d.ts +5 -0
  23. package/dist/cjs/controls/index.d.ts.map +1 -0
  24. package/dist/cjs/controls/index.js +20 -0
  25. package/dist/cjs/execute/actions.d.ts +55 -0
  26. package/dist/cjs/execute/actions.d.ts.map +1 -0
  27. package/dist/cjs/execute/actions.js +49 -0
  28. package/dist/cjs/execute/busy.d.ts +74 -0
  29. package/dist/cjs/execute/busy.d.ts.map +1 -0
  30. package/dist/cjs/execute/busy.js +182 -0
  31. package/dist/cjs/execute/hooks.d.ts +62 -0
  32. package/dist/cjs/execute/hooks.d.ts.map +1 -0
  33. package/dist/cjs/execute/hooks.js +308 -0
  34. package/dist/cjs/execute/index.d.ts +7 -0
  35. package/dist/cjs/execute/index.d.ts.map +1 -0
  36. package/dist/cjs/execute/index.js +22 -0
  37. package/dist/cjs/execute/leaf.d.ts +26 -0
  38. package/dist/cjs/execute/leaf.d.ts.map +1 -0
  39. package/dist/cjs/execute/leaf.js +154 -0
  40. package/dist/cjs/execute/provider.d.ts +29 -0
  41. package/dist/cjs/execute/provider.d.ts.map +1 -0
  42. package/dist/cjs/execute/provider.js +126 -0
  43. package/dist/cjs/execute/reducer.d.ts +4 -0
  44. package/dist/cjs/execute/reducer.d.ts.map +1 -0
  45. package/dist/cjs/execute/reducer.js +136 -0
  46. package/dist/cjs/execute/selectors.d.ts +22 -0
  47. package/dist/cjs/execute/selectors.d.ts.map +1 -0
  48. package/dist/cjs/execute/selectors.js +89 -0
  49. package/dist/cjs/execute/types.d.ts +49 -0
  50. package/dist/cjs/execute/types.d.ts.map +1 -0
  51. package/dist/cjs/execute/types.js +2 -0
  52. package/dist/cjs/execute/utils.d.ts +23 -0
  53. package/dist/cjs/execute/utils.d.ts.map +1 -0
  54. package/dist/cjs/execute/utils.js +62 -0
  55. package/dist/cjs/index.d.ts +4 -0
  56. package/dist/cjs/index.d.ts.map +1 -1
  57. package/dist/cjs/index.js +4 -0
  58. package/dist/cjs/jupyter.d.ts.map +1 -1
  59. package/dist/cjs/jupyter.js +19 -17
  60. package/dist/cjs/output.d.ts +1 -1
  61. package/dist/cjs/output.d.ts.map +1 -1
  62. package/dist/cjs/output.js +7 -4
  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/cjs/safe.js +1 -1
  67. package/dist/esm/ConnectionStatusTray.d.ts +2 -0
  68. package/dist/esm/ConnectionStatusTray.d.ts.map +1 -0
  69. package/dist/esm/ConnectionStatusTray.js +52 -0
  70. package/dist/esm/ErrorTray.d.ts +5 -0
  71. package/dist/esm/ErrorTray.d.ts.map +1 -0
  72. package/dist/esm/ErrorTray.js +30 -0
  73. package/dist/esm/controls/ArticleCellControls.d.ts +10 -0
  74. package/dist/esm/controls/ArticleCellControls.d.ts.map +1 -0
  75. package/dist/esm/controls/ArticleCellControls.js +27 -0
  76. package/dist/esm/controls/Buttons.d.ts +47 -0
  77. package/dist/esm/controls/Buttons.d.ts.map +1 -0
  78. package/dist/esm/controls/Buttons.js +57 -0
  79. package/dist/esm/controls/NotebookCellControls.d.ts +10 -0
  80. package/dist/esm/controls/NotebookCellControls.d.ts.map +1 -0
  81. package/dist/esm/controls/NotebookCellControls.js +21 -0
  82. package/dist/esm/controls/NotebookToolbar.d.ts +4 -0
  83. package/dist/esm/controls/NotebookToolbar.d.ts.map +1 -0
  84. package/dist/esm/controls/NotebookToolbar.js +40 -0
  85. package/dist/esm/controls/Spinner.d.ts +4 -0
  86. package/dist/esm/controls/Spinner.d.ts.map +1 -0
  87. package/dist/esm/controls/Spinner.js +4 -0
  88. package/dist/esm/controls/index.d.ts +5 -0
  89. package/dist/esm/controls/index.d.ts.map +1 -0
  90. package/dist/esm/controls/index.js +4 -0
  91. package/dist/esm/execute/actions.d.ts +55 -0
  92. package/dist/esm/execute/actions.d.ts.map +1 -0
  93. package/dist/esm/execute/actions.js +38 -0
  94. package/dist/esm/execute/busy.d.ts +74 -0
  95. package/dist/esm/execute/busy.d.ts.map +1 -0
  96. package/dist/esm/execute/busy.js +150 -0
  97. package/dist/esm/execute/hooks.d.ts +62 -0
  98. package/dist/esm/execute/hooks.d.ts.map +1 -0
  99. package/dist/esm/execute/hooks.js +277 -0
  100. package/dist/esm/execute/index.d.ts +7 -0
  101. package/dist/esm/execute/index.d.ts.map +1 -0
  102. package/dist/esm/execute/index.js +6 -0
  103. package/dist/esm/execute/leaf.d.ts +26 -0
  104. package/dist/esm/execute/leaf.d.ts.map +1 -0
  105. package/dist/esm/execute/leaf.js +147 -0
  106. package/dist/esm/execute/provider.d.ts +29 -0
  107. package/dist/esm/execute/provider.d.ts.map +1 -0
  108. package/dist/esm/execute/provider.js +99 -0
  109. package/dist/esm/execute/reducer.d.ts +4 -0
  110. package/dist/esm/execute/reducer.d.ts.map +1 -0
  111. package/dist/esm/execute/reducer.js +132 -0
  112. package/dist/esm/execute/selectors.d.ts +22 -0
  113. package/dist/esm/execute/selectors.d.ts.map +1 -0
  114. package/dist/esm/execute/selectors.js +77 -0
  115. package/dist/esm/execute/types.d.ts +49 -0
  116. package/dist/esm/execute/types.d.ts.map +1 -0
  117. package/dist/esm/execute/types.js +1 -0
  118. package/dist/esm/execute/utils.d.ts +23 -0
  119. package/dist/esm/execute/utils.d.ts.map +1 -0
  120. package/dist/esm/execute/utils.js +58 -0
  121. package/dist/esm/index.d.ts +4 -0
  122. package/dist/esm/index.d.ts.map +1 -1
  123. package/dist/esm/index.js +4 -0
  124. package/dist/esm/jupyter.d.ts.map +1 -1
  125. package/dist/esm/jupyter.js +17 -15
  126. package/dist/esm/output.d.ts +1 -1
  127. package/dist/esm/output.d.ts.map +1 -1
  128. package/dist/esm/output.js +8 -5
  129. package/dist/esm/providers.d.ts +1 -48
  130. package/dist/esm/providers.d.ts.map +1 -1
  131. package/dist/esm/providers.js +2 -126
  132. package/dist/esm/safe.js +1 -1
  133. package/dist/types/ConnectionStatusTray.d.ts +2 -0
  134. package/dist/types/ConnectionStatusTray.d.ts.map +1 -0
  135. package/dist/types/ErrorTray.d.ts +5 -0
  136. package/dist/types/ErrorTray.d.ts.map +1 -0
  137. package/dist/types/controls/ArticleCellControls.d.ts +10 -0
  138. package/dist/types/controls/ArticleCellControls.d.ts.map +1 -0
  139. package/dist/types/controls/Buttons.d.ts +47 -0
  140. package/dist/types/controls/Buttons.d.ts.map +1 -0
  141. package/dist/types/controls/NotebookCellControls.d.ts +10 -0
  142. package/dist/types/controls/NotebookCellControls.d.ts.map +1 -0
  143. package/dist/types/controls/NotebookToolbar.d.ts +4 -0
  144. package/dist/types/controls/NotebookToolbar.d.ts.map +1 -0
  145. package/dist/types/controls/Spinner.d.ts +4 -0
  146. package/dist/types/controls/Spinner.d.ts.map +1 -0
  147. package/dist/types/controls/index.d.ts +5 -0
  148. package/dist/types/controls/index.d.ts.map +1 -0
  149. package/dist/types/execute/actions.d.ts +55 -0
  150. package/dist/types/execute/actions.d.ts.map +1 -0
  151. package/dist/types/execute/busy.d.ts +74 -0
  152. package/dist/types/execute/busy.d.ts.map +1 -0
  153. package/dist/types/execute/hooks.d.ts +62 -0
  154. package/dist/types/execute/hooks.d.ts.map +1 -0
  155. package/dist/types/execute/index.d.ts +7 -0
  156. package/dist/types/execute/index.d.ts.map +1 -0
  157. package/dist/types/execute/leaf.d.ts +26 -0
  158. package/dist/types/execute/leaf.d.ts.map +1 -0
  159. package/dist/types/execute/provider.d.ts +29 -0
  160. package/dist/types/execute/provider.d.ts.map +1 -0
  161. package/dist/types/execute/reducer.d.ts +4 -0
  162. package/dist/types/execute/reducer.d.ts.map +1 -0
  163. package/dist/types/execute/selectors.d.ts +22 -0
  164. package/dist/types/execute/selectors.d.ts.map +1 -0
  165. package/dist/types/execute/types.d.ts +49 -0
  166. package/dist/types/execute/types.d.ts.map +1 -0
  167. package/dist/types/execute/utils.d.ts +23 -0
  168. package/dist/types/execute/utils.d.ts.map +1 -0
  169. package/dist/types/index.d.ts +4 -0
  170. package/dist/types/index.d.ts.map +1 -1
  171. package/dist/types/jupyter.d.ts.map +1 -1
  172. package/dist/types/output.d.ts +1 -1
  173. package/dist/types/output.d.ts.map +1 -1
  174. package/dist/types/providers.d.ts +1 -48
  175. package/dist/types/providers.d.ts.map +1 -1
  176. 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;
@@ -3,6 +3,10 @@ declare const OUTPUT_RENDERERS: {
3
3
  output: typeof Output;
4
4
  };
5
5
  export * from './BinderBadge';
6
+ export * from './ErrorTray';
7
+ export * from './ConnectionStatusTray';
6
8
  export * from './providers';
9
+ export * from './execute';
10
+ export * from './controls';
7
11
  export default OUTPUT_RENDERERS;
8
12
  //# 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;AAE5B,eAAe,gBAAgB,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,5 +19,9 @@ const OUTPUT_RENDERERS = {
19
19
  output: output_1.Output,
20
20
  };
21
21
  __exportStar(require("./BinderBadge"), exports);
22
+ __exportStar(require("./ErrorTray"), exports);
23
+ __exportStar(require("./ConnectionStatusTray"), exports);
22
24
  __exportStar(require("./providers"), exports);
25
+ __exportStar(require("./execute"), exports);
26
+ __exportStar(require("./controls"), exports);
23
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;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;AA6D3C,eAAO,MAAM,cAAc;QACD,MAAM;aAAW,cAAc,EAAE;8CAkD1D,CAAC"}
@@ -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 providers_2 = require("@myst-theme/providers");
33
+ const providers_1 = require("@myst-theme/providers");
35
34
  const thebe_react_1 = require("thebe-react");
36
- function ActiveOutputRenderer({ id, data }) {
37
- const exec = (0, providers_1.useNotebookCellExecution)(id);
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
- if (exec.cell.isAttachedToDOM) {
46
- console.debug(`Cell ${exec.cell.id} already attached to DOM`);
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.render(data);
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, providers_2.useXRefState)();
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 = (0, providers_1.useNotebookCellExecution)(id);
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, data: fullOutputs })] }));
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: (_a = exec === null || exec === void 0 ? void 0 : exec.kind) !== null && _a !== void 0 ? _a : myst_common_1.SourceFileKind.Notebook }))] }));
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
  });
@@ -1,4 +1,4 @@
1
- import type { GenericNode } from 'myst-common';
1
+ import { type GenericNode } from 'myst-common';
2
2
  import type { MinifiedOutput } from 'nbtx';
3
3
  export declare const DIRECT_OUTPUT_TYPES: Set<string>;
4
4
  export declare const DIRECT_MIME_TYPES: Set<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,MAAM,CAAC;AAO/D,eAAO,MAAM,mBAAmB,aAA+B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,aAMb,CAAC;AAElB,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,cAAc,EAAE,EACzB,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,EAC9B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,WAY7B;AA6CD,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,2CAYvC"}
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"}
@@ -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, providers_1.useReadyToExecute)();
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
- return ((0, jsx_runtime_1.jsx)("figure", { id: identifier || undefined, "data-mdast-node-type": nodeType, "data-mdast-node-id": nodeKey, className: (0, classnames_1.default)('max-w-full overflow-visible m-0 group not-prose relative', {
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!
@@ -1,8 +1,5 @@
1
- import type { GenericParent } from 'myst-common';
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,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,EACV,MAAM,EACN,mBAAmB,EACnB,UAAU,EACV,uBAAuB,EACvB,SAAS,EACT,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAQ/E,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;AAEF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,UAAU,EAAE,mBAAmB,iBAuChC;AAED,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEvC,UAAU,mBAAmB;IAC3B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,mBAAmB,EAAE,GAAG,IAAI,CAAC;IACrC,UAAU,EAAE,CACV,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,KACzC,OAAO,CAAC,CAAC,uBAAuB,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IACjD,WAAW,EAAE,CACX,SAAS,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,EACxC,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,KACzC,OAAO,CAAC,CAAC,uBAAuB,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IACjD,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,MAAM,EAAE,QAAQ,CAAC;IACjB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAID,wBAAgB,gBAAgB,CAAC,EAC/B,UAAU,EACV,IAAI,EACJ,QAAQ,GACT,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,2CA8DrE;AAED,wBAAgB,sBAAsB,YAGrC;AAED,wBAAgB,gBAAgB,oCAG/B;AAED,wBAAgB,oBAAoB;;;;;;;;;cAQnC;AAED,wBAAgB,iBAAiB,YAGhC;AAED,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,MAAM;;;;;;wBAiBhB,sBAAsB;;;cAmBxD"}
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"}
@@ -1,41 +1,11 @@
1
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
- });
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.useNotebookCellExecution = exports.useReadyToExecute = exports.useNotebookExecution = exports.useMDASTNotebook = exports.useHasNotebookProvider = exports.NotebookProvider = exports.notebookFromMdast = exports.ConfiguredThebeServerProvider = exports.useComputeOptions = void 0;
6
+ exports.ConfiguredThebeServerProvider = exports.useComputeOptions = void 0;
36
7
  const jsx_runtime_1 = require("react/jsx-runtime");
37
- const myst_common_1 = require("myst-common");
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;
76
- if (block.type !== 'block')
77
- console.warn(`Unexpected block type ${block.type}`);
78
- if (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, 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);
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;
package/dist/cjs/safe.js CHANGED
@@ -61,7 +61,7 @@ function SafeOutput({ output }) {
61
61
  if (image)
62
62
  return (0, jsx_runtime_1.jsx)(OutputImage, { image: image, text: text });
63
63
  if (text)
64
- return ((0, jsx_runtime_1.jsx)("div", { className: "whitespace-pre-wrap font-mono text-sm", children: (0, jsx_runtime_1.jsx)(ansi_to_react_1.default, { children: text.content }) }));
64
+ return ((0, jsx_runtime_1.jsx)("div", { className: "font-mono text-sm whitespace-pre-wrap", children: (0, jsx_runtime_1.jsx)(ansi_to_react_1.default, { children: text.content }) }));
65
65
  return null;
66
66
  }
67
67
  default:
@@ -0,0 +1,2 @@
1
+ export declare function ConnectionStatusTray(): import("react/jsx-runtime").JSX.Element | null;
2
+ //# sourceMappingURL=ConnectionStatusTray.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionStatusTray.d.ts","sourceRoot":"","sources":["../../src/ConnectionStatusTray.tsx"],"names":[],"mappings":"AAMA,wBAAgB,oBAAoB,mDAoFnC"}
@@ -0,0 +1,52 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { useThebeServer } from 'thebe-react';
4
+ import { useComputeOptions } from './providers';
5
+ import { selectAreExecutionScopesBuilding, useExecutionScope } from './execute';
6
+ export function ConnectionStatusTray() {
7
+ const { thebe } = useComputeOptions();
8
+ const { connecting, ready: serverReady, error: serverError, events } = useThebeServer();
9
+ const { slug, ready: scopeReady, state } = useExecutionScope();
10
+ const [show, setShow] = useState(false);
11
+ const [unsub, setUnsub] = useState();
12
+ const [status, setStatus] = useState('[client] Connecting...');
13
+ const error = serverError; // TODO scope bulding error handling || sessionError;
14
+ const ready = serverReady && scopeReady;
15
+ const busy = connecting || selectAreExecutionScopesBuilding(state, slug);
16
+ const handleStatus = (event, data) => {
17
+ setStatus(`[${data.subject}]: ${data.message}`);
18
+ };
19
+ useEffect(() => {
20
+ if (!events)
21
+ return;
22
+ events.on('status', handleStatus);
23
+ }, [events]);
24
+ useEffect(() => {
25
+ if (!thebe)
26
+ return;
27
+ if ((thebe === null || thebe === void 0 ? void 0 : thebe.useBinder) || (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite)) {
28
+ if (busy || error) {
29
+ setShow(true);
30
+ }
31
+ else if (ready) {
32
+ setTimeout(() => {
33
+ setShow(false);
34
+ unsub === null || unsub === void 0 ? void 0 : unsub();
35
+ setUnsub(undefined);
36
+ }, (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite) ? 3000 : 500);
37
+ }
38
+ }
39
+ }, [thebe, busy, ready, error]);
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!
42
+ if (show && error) {
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" }) })] }));
44
+ }
45
+ if (show && (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite)) {
46
+ 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-1 font-semibold text-center", children: ["\u26A1\uFE0F Connecting to ", host, " \u26A1\uFE0F"] }), !ready && _jsx("div", { className: "max-h-[5rem] mono overflow-hidden text-ellipsis", children: status }), ready && (_jsx("div", { className: "max-h-[15rem] mono overflow-hidden text-ellipsis", children: "The in-browser JupyterLite server is ready, press run anytime." }))] }));
47
+ }
48
+ if (show) {
49
+ 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-1 font-semibold text-center", children: ["\u26A1\uFE0F Connecting to ", host, " \u26A1\uFE0F"] }), _jsx("div", { className: "max-h-[15rem] mono overflow-hidden text-ellipsis", children: status })] }));
50
+ }
51
+ return null;
52
+ }
@@ -0,0 +1,5 @@
1
+ import type { IThebeNotebookError } from 'thebe-react';
2
+ export declare function ErrorTray({ errors }: {
3
+ errors: IThebeNotebookError[];
4
+ }): import("react/jsx-runtime").JSX.Element;
5
+ //# sourceMappingURL=ErrorTray.d.ts.map
@@ -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"}