@myst-theme/jupyter 0.1.36 → 0.1.37

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 (54) hide show
  1. package/dist/cjs/BinderBadge.d.ts +4 -0
  2. package/dist/cjs/BinderBadge.d.ts.map +1 -0
  3. package/dist/cjs/BinderBadge.js +13 -0
  4. package/dist/cjs/ClientOnly.d.ts +1 -1
  5. package/dist/cjs/ClientOnly.d.ts.map +1 -1
  6. package/dist/cjs/ClientOnly.js +2 -1
  7. package/dist/cjs/index.d.ts +2 -0
  8. package/dist/cjs/index.d.ts.map +1 -1
  9. package/dist/cjs/index.js +16 -0
  10. package/dist/cjs/jupyter.d.ts +1 -1
  11. package/dist/cjs/jupyter.d.ts.map +1 -1
  12. package/dist/cjs/jupyter.js +41 -12
  13. package/dist/cjs/output.d.ts.map +1 -1
  14. package/dist/cjs/output.js +5 -6
  15. package/dist/cjs/providers.d.ts +67 -0
  16. package/dist/cjs/providers.d.ts.map +1 -0
  17. package/dist/cjs/providers.js +232 -0
  18. package/dist/esm/BinderBadge.d.ts +4 -0
  19. package/dist/esm/BinderBadge.d.ts.map +1 -0
  20. package/dist/esm/BinderBadge.js +9 -0
  21. package/dist/esm/ClientOnly.d.ts +1 -1
  22. package/dist/esm/ClientOnly.d.ts.map +1 -1
  23. package/dist/esm/ClientOnly.js +1 -1
  24. package/dist/esm/index.d.ts +2 -0
  25. package/dist/esm/index.d.ts.map +1 -1
  26. package/dist/esm/index.js +2 -0
  27. package/dist/esm/jupyter.d.ts +1 -1
  28. package/dist/esm/jupyter.d.ts.map +1 -1
  29. package/dist/esm/jupyter.js +40 -11
  30. package/dist/esm/output.d.ts.map +1 -1
  31. package/dist/esm/output.js +6 -7
  32. package/dist/esm/providers.d.ts +67 -0
  33. package/dist/esm/providers.d.ts.map +1 -0
  34. package/dist/esm/providers.js +197 -0
  35. package/dist/types/BinderBadge.d.ts +4 -0
  36. package/dist/types/BinderBadge.d.ts.map +1 -0
  37. package/dist/types/ClientOnly.d.ts +1 -1
  38. package/dist/types/ClientOnly.d.ts.map +1 -1
  39. package/dist/types/index.d.ts +2 -0
  40. package/dist/types/index.d.ts.map +1 -1
  41. package/dist/types/jupyter.d.ts +1 -1
  42. package/dist/types/jupyter.d.ts.map +1 -1
  43. package/dist/types/output.d.ts.map +1 -1
  44. package/dist/types/providers.d.ts +67 -0
  45. package/dist/types/providers.d.ts.map +1 -0
  46. package/package.json +7 -6
  47. package/dist/cjs/thebe-provider.d.ts +0 -7
  48. package/dist/cjs/thebe-provider.d.ts.map +0 -1
  49. package/dist/cjs/thebe-provider.js +0 -53
  50. package/dist/esm/thebe-provider.d.ts +0 -7
  51. package/dist/esm/thebe-provider.d.ts.map +0 -1
  52. package/dist/esm/thebe-provider.js +0 -26
  53. package/dist/types/thebe-provider.d.ts +0 -7
  54. package/dist/types/thebe-provider.d.ts.map +0 -1
@@ -1,28 +1,54 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  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 { useThebeCore } from './thebe-provider';
7
- function OutputRenderer({ id, data, core }) {
8
- const [cell] = useState(new core.PassiveCellRenderer(id));
6
+ import { useThebeCore } from 'thebe-react';
7
+ import { useCellRef, useCellRefRegistry, useNotebookCellExecution } from './providers';
8
+ import { SourceFileKind } from 'myst-common';
9
+ function ActiveOutputRenderer({ id, data }) {
10
+ const ref = useCellRef(id);
11
+ const exec = useNotebookCellExecution(id);
12
+ useEffect(() => {
13
+ if (!(ref === null || ref === void 0 ? void 0 : ref.el) || !(exec === null || exec === void 0 ? void 0 : exec.cell))
14
+ return;
15
+ console.debug(`Attaching cell ${exec.cell.id} to DOM at:`, {
16
+ el: ref.el,
17
+ connected: ref.el.isConnected,
18
+ data,
19
+ });
20
+ exec.cell.attachToDOM(ref.el);
21
+ exec.cell.render(data);
22
+ }, [ref === null || ref === void 0 ? void 0 : ref.el, exec === null || exec === void 0 ? void 0 : exec.cell]);
23
+ return null;
24
+ }
25
+ function PassiveOutputRenderer({ id, data, core, kind, }) {
26
+ const [cell] = useState(new core.PassiveCellRenderer(id, undefined, undefined));
9
27
  const ref = useRef(null);
10
28
  useEffect(() => {
11
- cell.render(data);
29
+ cell.render(data, kind === SourceFileKind.Article);
12
30
  }, [data, cell]);
13
31
  useEffect(() => {
14
32
  if (!ref.current)
15
33
  return;
16
- cell.attachToDOM(ref.current);
34
+ cell.attachToDOM(ref.current, true);
17
35
  }, [ref]);
18
- return _jsx("div", { ref: ref });
36
+ return _jsx("div", { ref: ref, "data-thebe-passive-ref": "true" });
19
37
  }
20
- const MemoOutputRenderer = React.memo(OutputRenderer);
21
- export const NativeJupyterOutputs = ({ id, outputs, }) => {
22
- const { core } = useThebeCore();
38
+ const MemoPassiveOutputRenderer = React.memo(PassiveOutputRenderer);
39
+ export const JupyterOutputs = ({ id, outputs }) => {
40
+ var _a;
41
+ const { core, load } = useThebeCore();
23
42
  const { data, error } = useFetchAnyTruncatedContent(outputs);
24
43
  const [loaded, setLoaded] = useState(false);
25
44
  const [fullOutputs, setFullOutputs] = useState(null);
45
+ const registry = useCellRefRegistry();
46
+ const exec = useNotebookCellExecution(id);
47
+ useEffect(() => {
48
+ if (core)
49
+ return;
50
+ load();
51
+ }, [core, load]);
26
52
  useEffect(() => {
27
53
  if (!data || loaded)
28
54
  return;
@@ -35,5 +61,8 @@ export const NativeJupyterOutputs = ({ id, outputs, }) => {
35
61
  if (error) {
36
62
  return _jsxs("div", Object.assign({ className: "text-red-500" }, { children: ["Error rendering output: ", error.message] }));
37
63
  }
38
- return (_jsxs("div", { children: [!fullOutputs && _jsx("div", Object.assign({ className: "p-2.5" }, { children: "Loading..." })), fullOutputs && core && _jsx(MemoOutputRenderer, { id: id, core: core, data: fullOutputs })] }));
64
+ if (registry && (exec === null || exec === void 0 ? void 0 : exec.cell)) {
65
+ return (_jsxs("div", Object.assign({ ref: registry === null || registry === void 0 ? void 0 : registry.register(id), "data-thebe-active-ref": "true" }, { children: [!fullOutputs && _jsx("div", Object.assign({ className: "p-2.5" }, { children: "Loading..." })), fullOutputs && _jsx(ActiveOutputRenderer, { id: id, data: fullOutputs })] })));
66
+ }
67
+ return (_jsxs(_Fragment, { children: [!fullOutputs && _jsx("div", Object.assign({ className: "p-2.5" }, { children: "Loading..." })), fullOutputs && core && (_jsx(MemoPassiveOutputRenderer, { id: id, data: fullOutputs, core: core, kind: (_a = exec === null || exec === void 0 ? void 0 : exec.kind) !== null && _a !== void 0 ? _a : SourceFileKind.Notebook }))] }));
39
68
  };
@@ -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;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,eA+BvC"}
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;AAM/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;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,eA2BvC"}
@@ -2,9 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { KnownCellOutputMimeTypes } from 'nbtx';
3
3
  import classNames from 'classnames';
4
4
  import { SafeOutputs } from './safe';
5
- import { NativeJupyterOutputs as JupyterOutputs } from './jupyter';
6
- import ClientOnly from './ClientOnly';
7
- import { ThebeCoreProvider } from './thebe-provider';
5
+ import { JupyterOutputs } from './jupyter';
6
+ import { useNotebookCellExecution } from './providers';
8
7
  export const DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);
9
8
  export const DIRECT_MIME_TYPES = new Set([
10
9
  KnownCellOutputMimeTypes.TextPlain,
@@ -26,17 +25,17 @@ export function allOutputsAreSafe(outputs, directOutputTypes, directMimeTypes) {
26
25
  }, true);
27
26
  }
28
27
  export function Output(node) {
28
+ const exec = useNotebookCellExecution(node.key);
29
29
  const outputs = node.data;
30
30
  const allSafe = allOutputsAreSafe(outputs, DIRECT_OUTPUT_TYPES, DIRECT_MIME_TYPES);
31
31
  let component;
32
- if (allSafe) {
32
+ if (allSafe && !(exec === null || exec === void 0 ? void 0 : exec.ready)) {
33
33
  component = _jsx(SafeOutputs, { keyStub: node.key, outputs: outputs });
34
34
  }
35
35
  else {
36
- // Hide the iframe if rendering on the server
37
- component = (_jsx(ClientOnly, { children: _jsx(ThebeCoreProvider, { children: _jsx(JupyterOutputs, { id: node.key, outputs: outputs }) }) }));
36
+ component = _jsx(JupyterOutputs, { id: node.key, outputs: outputs });
38
37
  }
39
- return (_jsx("figure", Object.assign({ id: node.identifier || undefined, className: classNames('max-w-full overflow-auto m-0 group not-prose relative', {
38
+ return (_jsx("figure", Object.assign({ id: node.identifier || undefined, "data-mdast-node-type": node.type, "data-mdast-node-id": node.key, className: classNames('max-w-full overflow-auto m-0 group not-prose relative', {
40
39
  'text-left': !node.align || node.align === 'left',
41
40
  'text-center': node.align === 'center',
42
41
  'text-right': node.align === 'right',
@@ -0,0 +1,67 @@
1
+ import type { GenericParent } from 'myst-common';
2
+ import { SourceFileKind } from 'myst-common';
3
+ import React from 'react';
4
+ import type { Config, IThebeCell, IThebeCellExecuteReturn, ThebeCore, ThebeNotebook } from 'thebe-core';
5
+ import type { IThebeNotebookError, NotebookExecuteOptions } from 'thebe-react';
6
+ import type { Root } from 'mdast';
7
+ export declare function ConfiguredThebeServerProvider({ children }: React.PropsWithChildren): JSX.Element;
8
+ export type PartialPage = {
9
+ kind: SourceFileKind;
10
+ file: string;
11
+ sha256: string;
12
+ slug: string;
13
+ mdast: Root;
14
+ };
15
+ export declare function notebookFromMdast(core: ThebeCore, config: Config, mdast: GenericParent, idkMap: Record<string, string>): ThebeNotebook;
16
+ type CellRefRegistry = Record<string, HTMLDivElement>;
17
+ type IdKeyMap = Record<string, string>;
18
+ interface NotebookContextType {
19
+ kind: SourceFileKind;
20
+ ready: boolean;
21
+ attached: boolean;
22
+ executing: boolean;
23
+ executed: boolean;
24
+ errors: IThebeNotebookError[] | null;
25
+ executeAll: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
26
+ executeSome: (predicate: (cell: IThebeCell) => boolean, options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
27
+ notebook: ThebeNotebook | undefined;
28
+ registry: CellRefRegistry;
29
+ idkMap: IdKeyMap;
30
+ register: (id: string) => (el: HTMLDivElement) => void;
31
+ restart: () => Promise<void>;
32
+ clear: () => void;
33
+ }
34
+ export declare function NotebookProvider({ siteConfig, page, children, }: React.PropsWithChildren<{
35
+ siteConfig: boolean;
36
+ page: PartialPage;
37
+ }>): JSX.Element;
38
+ export declare function useHasNotebookProvider(): boolean;
39
+ export declare function useCellRefRegistry(): {
40
+ register: (id: string) => (el: HTMLDivElement) => void;
41
+ } | undefined;
42
+ export declare function useCellRef(id: string): {
43
+ el: HTMLDivElement | null;
44
+ } | undefined;
45
+ export declare function useMDASTNotebook(): NotebookContextType | undefined;
46
+ export declare function useNotebookExecution(): {
47
+ ready: boolean;
48
+ attached: boolean;
49
+ executing: boolean;
50
+ executed: boolean;
51
+ errors: IThebeNotebookError[] | null;
52
+ execute: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
53
+ notebook: ThebeNotebook | undefined;
54
+ clear: () => void;
55
+ } | undefined;
56
+ export declare function useNotebookCellExecution(id: string): {
57
+ kind: SourceFileKind;
58
+ ready: boolean;
59
+ cell: IThebeCell | undefined;
60
+ executing: boolean;
61
+ notebookIsExecuting: boolean;
62
+ execute: (options?: NotebookExecuteOptions) => Promise<(IThebeCellExecuteReturn | null)[]>;
63
+ clear: () => void | undefined;
64
+ notebook: ThebeNotebook | undefined;
65
+ } | undefined;
66
+ export {};
67
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +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,EAEN,UAAU,EACV,uBAAuB,EAEvB,SAAS,EACT,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAoDlC,wBAAgB,6BAA6B,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,iBAAiB,eAOlF;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,iBAwC/B;AAGD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACtD,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,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,EAAE,EAAE,cAAc,KAAK,IAAI,CAAC;IACvD,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,eAwErE;AAED,wBAAgB,sBAAsB,YAGrC;AAED,wBAAgB,kBAAkB;;cAIjC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM;;cAQpC;AAED,wBAAgB,gBAAgB,oCAG/B;AAED,wBAAgB,oBAAoB;;;;;;;;;cAQnC;AAED,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,MAAM;;;;;;wBAiBhB,sBAAsB;;;cAiBxD"}
@@ -0,0 +1,197 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { SourceFileKind } from 'myst-common';
12
+ import React, { useContext, useEffect, useRef, useState } from 'react';
13
+ import { useNotebookBase, useThebeConfig, useThebeCore, ThebeServerProvider } from 'thebe-react';
14
+ import { useComputeOptions } from '@myst-theme/providers';
15
+ function getThebeOptions() {
16
+ var _a, _b, _c;
17
+ const { thebe, binderUrl } = useComputeOptions();
18
+ const { mathjaxUrl, mathjaxConfig, binder, server, kernelName, sessionName, disableSessionSaving, local, } = (_a = thebe) !== null && _a !== void 0 ? _a : {};
19
+ const output = { mathjaxUrl, mathjaxConfig };
20
+ if (binder) {
21
+ const useBinder = binder === true ? {} : binder;
22
+ output.binderOptions = {
23
+ binderUrl: (_b = useBinder.url) !== null && _b !== void 0 ? _b : binderUrl,
24
+ ref: useBinder.ref,
25
+ repo: useBinder.repo,
26
+ repoProvider: useBinder.provider,
27
+ };
28
+ }
29
+ const useServer = (local !== null && local !== void 0 ? local : server);
30
+ if (server) {
31
+ const splitUrl = (_c = useServer.url) === null || _c === void 0 ? void 0 : _c.split('://');
32
+ const wsUrl = (splitUrl === null || splitUrl === void 0 ? void 0 : splitUrl.length) === 2 ? `ws://${splitUrl[1]}` : undefined;
33
+ output.serverSettings = {
34
+ baseUrl: useServer.url,
35
+ token: useServer.token,
36
+ wsUrl,
37
+ appendToken: true,
38
+ };
39
+ }
40
+ output.kernelOptions = {
41
+ kernelName: kernelName,
42
+ name: kernelName,
43
+ path: sessionName,
44
+ };
45
+ if (!disableSessionSaving) {
46
+ output.savedSessionOptions = {
47
+ enabled: true,
48
+ maxAge: 38300,
49
+ storagePrefix: 'thebe',
50
+ };
51
+ }
52
+ return output;
53
+ }
54
+ export function ConfiguredThebeServerProvider({ children }) {
55
+ const thebe = getThebeOptions();
56
+ return (_jsx(ThebeServerProvider, Object.assign({ connect: false, options: thebe }, { children: children })));
57
+ }
58
+ export function notebookFromMdast(core, config, mdast, idkMap) {
59
+ const rendermime = undefined; // share rendermime beyond notebook scope?
60
+ const notebook = new core.ThebeNotebook(mdast.key, config, rendermime);
61
+ // no metadata included in mdast yet
62
+ //Object.assign(notebook.metadata, ipynb.metadata);
63
+ notebook.cells = mdast.children.map((block) => {
64
+ var _a, _b, _c;
65
+ if (block.type !== 'block')
66
+ console.warn(`Unexpected block type ${block.type}`);
67
+ if (block.children.length == 2 && block.children[0].type === 'code') {
68
+ const [codeCell, output] = block.children;
69
+ // use the block.key to identify the cell but maintain a mapping
70
+ // to allow code or output keys to look up cells and refs
71
+ idkMap[block.key] = block.key;
72
+ idkMap[codeCell.key] = block.key;
73
+ idkMap[output.key] = block.key;
74
+ 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);
75
+ }
76
+ else {
77
+ // assume content - concatenate it
78
+ // TODO inject cell metadata
79
+ 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);
80
+ return cell;
81
+ }
82
+ });
83
+ return notebook;
84
+ }
85
+ const NotebookContext = React.createContext(undefined);
86
+ export function NotebookProvider({ siteConfig, page, children, }) {
87
+ // so at some point this gets the whole site config and can
88
+ // be use to lookup notebooks and recover ThebeNotebooks that
89
+ // can be used to execute notebook pages or blocks in articles
90
+ const { core } = useThebeCore();
91
+ const { config } = useThebeConfig();
92
+ const { ready, attached, executing, executed, errors, executeAll, executeSome, clear, session, notebook, setNotebook, } = useNotebookBase();
93
+ const registry = useRef({});
94
+ const idkMap = useRef({});
95
+ useEffect(() => {
96
+ if (!core || !config)
97
+ return;
98
+ registry.current = {};
99
+ idkMap.current = {};
100
+ if (page.kind === SourceFileKind.Notebook) {
101
+ const nb = notebookFromMdast(core, config, page.mdast, idkMap.current);
102
+ setNotebook(nb);
103
+ }
104
+ else {
105
+ // TODO will need do article relative notebook loading as appropriate once that is supported
106
+ setNotebook(undefined);
107
+ }
108
+ }, [core, config, page]);
109
+ function register(id) {
110
+ return (el) => {
111
+ if (el != null && registry.current[idkMap.current[id]] !== el) {
112
+ if (!el.isConnected) {
113
+ console.debug(`skipping ref for cell ${id} as host is not connected`);
114
+ }
115
+ else {
116
+ console.debug(`new ref for cell ${id} registered`);
117
+ registry.current[idkMap.current[id]] = el;
118
+ }
119
+ }
120
+ };
121
+ }
122
+ return (_jsx(NotebookContext.Provider, Object.assign({ value: {
123
+ kind: page.kind,
124
+ ready,
125
+ attached,
126
+ executing,
127
+ executed,
128
+ errors,
129
+ executeAll,
130
+ executeSome,
131
+ notebook,
132
+ registry: registry.current,
133
+ idkMap: idkMap.current,
134
+ register,
135
+ restart: () => { var _a; return (_a = session === null || session === void 0 ? void 0 : session.restart()) !== null && _a !== void 0 ? _a : Promise.resolve(); },
136
+ clear,
137
+ } }, { children: children })));
138
+ }
139
+ export function useHasNotebookProvider() {
140
+ const notebookState = useContext(NotebookContext);
141
+ return notebookState !== undefined;
142
+ }
143
+ export function useCellRefRegistry() {
144
+ const notebookState = useContext(NotebookContext);
145
+ if (notebookState === undefined)
146
+ return undefined;
147
+ return { register: notebookState.register };
148
+ }
149
+ export function useCellRef(id) {
150
+ var _a;
151
+ const notebookState = useContext(NotebookContext);
152
+ if (notebookState === undefined)
153
+ return undefined;
154
+ const { registry, idkMap } = notebookState;
155
+ const entry = Object.entries(notebookState.registry).find(([cellId]) => cellId === idkMap[id]);
156
+ console.debug('useCellRef', { id, registry, idkMap, entry });
157
+ return { el: (_a = entry === null || entry === void 0 ? void 0 : entry[1]) !== null && _a !== void 0 ? _a : null };
158
+ }
159
+ export function useMDASTNotebook() {
160
+ const notebookState = useContext(NotebookContext);
161
+ return notebookState;
162
+ }
163
+ export function useNotebookExecution() {
164
+ const notebookState = useContext(NotebookContext);
165
+ if (!notebookState)
166
+ return undefined;
167
+ const { ready, attached, executing, executed, errors, executeAll, notebook, clear } = notebookState;
168
+ return { ready, attached, executing, executed, errors, execute: executeAll, notebook, clear };
169
+ }
170
+ export function useNotebookCellExecution(id) {
171
+ // setup a cell only executing state
172
+ const [executing, setExecuting] = useState(false);
173
+ const notebookState = useContext(NotebookContext);
174
+ if (!notebookState)
175
+ return undefined;
176
+ const { kind, ready, notebook, executing: notebookIsExecuting, executeSome, idkMap, } = notebookState;
177
+ const cellId = idkMap[id];
178
+ function execute(options) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ setExecuting(true);
181
+ const execReturn = yield executeSome((cell) => cell.id === cellId, options);
182
+ setExecuting(false);
183
+ return execReturn;
184
+ });
185
+ }
186
+ const cell = notebook === null || notebook === void 0 ? void 0 : notebook.getCellById(cellId);
187
+ return {
188
+ kind,
189
+ ready,
190
+ cell,
191
+ executing,
192
+ notebookIsExecuting,
193
+ execute,
194
+ clear: () => cell === null || cell === void 0 ? void 0 : cell.clear(),
195
+ notebook,
196
+ };
197
+ }
@@ -0,0 +1,4 @@
1
+ export declare function BinderBadge({ binder }: {
2
+ binder?: string;
3
+ }): JSX.Element | null;
4
+ //# sourceMappingURL=BinderBadge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BinderBadge.d.ts","sourceRoot":"","sources":["../../src/BinderBadge.tsx"],"names":[],"mappings":"AA2DA,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,sBAe1D"}
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
- export default function ClientOnly({ children }: {
2
+ export declare function ClientOnly({ children }: {
3
3
  children: ReactNode;
4
4
  }): JSX.Element | null;
5
5
  //# sourceMappingURL=ClientOnly.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClientOnly.d.ts","sourceRoot":"","sources":["../../src/ClientOnly.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,sBAMvE"}
1
+ {"version":3,"file":"ClientOnly.d.ts","sourceRoot":"","sources":["../../src/ClientOnly.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,sBAM/D"}
@@ -2,5 +2,7 @@ import { Output } from './output';
2
2
  declare const OUTPUT_RENDERERS: {
3
3
  output: typeof Output;
4
4
  };
5
+ export * from './BinderBadge';
6
+ export * from './providers';
5
7
  export default OUTPUT_RENDERERS;
6
8
  //# 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,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;AAE5B,eAAe,gBAAgB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { MinifiedOutput } from 'nbtx';
2
- export declare const NativeJupyterOutputs: ({ id, outputs, }: {
2
+ export declare const JupyterOutputs: ({ id, outputs }: {
3
3
  id: string;
4
4
  outputs: MinifiedOutput[];
5
5
  }) => JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAqB3C,eAAO,MAAM,oBAAoB;QAI3B,MAAM;aACD,cAAc,EAAE;iBA0B1B,CAAC"}
1
+ {"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAmD3C,eAAO,MAAM,cAAc;QAA2B,MAAM;aAAW,cAAc,EAAE;iBAgDtF,CAAC"}
@@ -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;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,eA+BvC"}
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;AAM/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;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,eA2BvC"}
@@ -0,0 +1,67 @@
1
+ import type { GenericParent } from 'myst-common';
2
+ import { SourceFileKind } from 'myst-common';
3
+ import React from 'react';
4
+ import type { Config, IThebeCell, IThebeCellExecuteReturn, ThebeCore, ThebeNotebook } from 'thebe-core';
5
+ import type { IThebeNotebookError, NotebookExecuteOptions } from 'thebe-react';
6
+ import type { Root } from 'mdast';
7
+ export declare function ConfiguredThebeServerProvider({ children }: React.PropsWithChildren): JSX.Element;
8
+ export type PartialPage = {
9
+ kind: SourceFileKind;
10
+ file: string;
11
+ sha256: string;
12
+ slug: string;
13
+ mdast: Root;
14
+ };
15
+ export declare function notebookFromMdast(core: ThebeCore, config: Config, mdast: GenericParent, idkMap: Record<string, string>): ThebeNotebook;
16
+ type CellRefRegistry = Record<string, HTMLDivElement>;
17
+ type IdKeyMap = Record<string, string>;
18
+ interface NotebookContextType {
19
+ kind: SourceFileKind;
20
+ ready: boolean;
21
+ attached: boolean;
22
+ executing: boolean;
23
+ executed: boolean;
24
+ errors: IThebeNotebookError[] | null;
25
+ executeAll: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
26
+ executeSome: (predicate: (cell: IThebeCell) => boolean, options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
27
+ notebook: ThebeNotebook | undefined;
28
+ registry: CellRefRegistry;
29
+ idkMap: IdKeyMap;
30
+ register: (id: string) => (el: HTMLDivElement) => void;
31
+ restart: () => Promise<void>;
32
+ clear: () => void;
33
+ }
34
+ export declare function NotebookProvider({ siteConfig, page, children, }: React.PropsWithChildren<{
35
+ siteConfig: boolean;
36
+ page: PartialPage;
37
+ }>): JSX.Element;
38
+ export declare function useHasNotebookProvider(): boolean;
39
+ export declare function useCellRefRegistry(): {
40
+ register: (id: string) => (el: HTMLDivElement) => void;
41
+ } | undefined;
42
+ export declare function useCellRef(id: string): {
43
+ el: HTMLDivElement | null;
44
+ } | undefined;
45
+ export declare function useMDASTNotebook(): NotebookContextType | undefined;
46
+ export declare function useNotebookExecution(): {
47
+ ready: boolean;
48
+ attached: boolean;
49
+ executing: boolean;
50
+ executed: boolean;
51
+ errors: IThebeNotebookError[] | null;
52
+ execute: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
53
+ notebook: ThebeNotebook | undefined;
54
+ clear: () => void;
55
+ } | undefined;
56
+ export declare function useNotebookCellExecution(id: string): {
57
+ kind: SourceFileKind;
58
+ ready: boolean;
59
+ cell: IThebeCell | undefined;
60
+ executing: boolean;
61
+ notebookIsExecuting: boolean;
62
+ execute: (options?: NotebookExecuteOptions) => Promise<(IThebeCellExecuteReturn | null)[]>;
63
+ clear: () => void | undefined;
64
+ notebook: ThebeNotebook | undefined;
65
+ } | undefined;
66
+ export {};
67
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +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,EAEN,UAAU,EACV,uBAAuB,EAEvB,SAAS,EACT,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAoDlC,wBAAgB,6BAA6B,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,iBAAiB,eAOlF;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,iBAwC/B;AAGD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACtD,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,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,EAAE,EAAE,cAAc,KAAK,IAAI,CAAC;IACvD,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,eAwErE;AAED,wBAAgB,sBAAsB,YAGrC;AAED,wBAAgB,kBAAkB;;cAIjC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM;;cAQpC;AAED,wBAAgB,gBAAgB,oCAG/B;AAED,wBAAgB,oBAAoB;;;;;;;;;cAQnC;AAED,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,MAAM;;;;;;wBAiBhB,sBAAsB;;;cAiBxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myst-theme/jupyter",
3
- "version": "0.1.36",
3
+ "version": "0.1.37",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -16,26 +16,27 @@
16
16
  "build:cjs": "tsc --module commonjs --outDir dist/cjs",
17
17
  "build:esm": "tsc --module es2020 --outDir dist/esm",
18
18
  "build:types": "tsc --declaration --emitDeclarationOnly --declarationMap --outDir dist/types",
19
- "build": "npm-run-all -l clean -p build:cjs build:esm build:types",
20
- "test": "jest"
19
+ "build": "npm-run-all -l clean -p build:cjs build:esm build:types"
21
20
  },
22
21
  "dependencies": {
23
22
  "@headlessui/react": "^1.7.13",
24
23
  "@heroicons/react": "^2.0.13",
25
- "@myst-theme/providers": "^0.1.36",
24
+ "@myst-theme/providers": "^0.1.37",
26
25
  "@popperjs/core": "^2.11.6",
27
26
  "ansi-to-react": "^6.1.6",
28
27
  "buffer": "^6.0.3",
29
28
  "classnames": "^2.3.2",
30
29
  "myst-common": "^0.0.16",
31
- "myst-config": "^0.0.12",
30
+ "myst-config": "^0.0.14",
31
+ "myst-frontmatter": "^0.0.13",
32
32
  "myst-spec": "^0.0.4",
33
33
  "nanoid": "^4.0.0",
34
34
  "nbtx": "^0.2.3",
35
35
  "react-popper": "^2.3.0",
36
36
  "react-syntax-highlighter": "^15.5.0",
37
37
  "swr": "^1.3.0",
38
- "thebe-core": "^0.1.1",
38
+ "thebe-core": "^0.1.6",
39
+ "thebe-react": "^0.0.7",
39
40
  "unist-util-select": "^4.0.1"
40
41
  },
41
42
  "peerDependencies": {
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- export type ThebeCore = typeof import('thebe-core');
3
- export declare function ThebeCoreProvider({ children }: React.PropsWithChildren): JSX.Element;
4
- export declare function useThebeCore(): {
5
- core?: typeof import("thebe-core") | undefined;
6
- };
7
- //# sourceMappingURL=thebe-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"thebe-provider.d.ts","sourceRoot":"","sources":["../../src/thebe-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,MAAM,MAAM,SAAS,GAAG,cAAc,YAAY,CAAC,CAAC;AAKpD,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,iBAAiB,eAoBtE;AAED,wBAAgB,YAAY;;EAM3B"}
@@ -1,53 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.useThebeCore = exports.ThebeCoreProvider = void 0;
27
- const jsx_runtime_1 = require("react/jsx-runtime");
28
- const react_1 = __importStar(require("react"));
29
- // Don't know how to get rid of the undefined here in the case of an async provider
30
- const ThebeCoreContext = react_1.default.createContext(undefined);
31
- function ThebeCoreProvider({ children }) {
32
- const [core, setCore] = (0, react_1.useState)();
33
- (0, react_1.useEffect)(() => {
34
- console.debug('importing thebe-core...');
35
- Promise.resolve().then(() => __importStar(require('thebe-core'))).then((thebeCore) => {
36
- console.debug('thebe-core loaded');
37
- setCore(thebeCore);
38
- })
39
- .catch(({ reason }) => {
40
- console.error(`thebe-core load failed ${reason}`);
41
- });
42
- }, []);
43
- return ((0, jsx_runtime_1.jsx)(ThebeCoreContext.Provider, Object.assign({ value: { core } }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }) })));
44
- }
45
- exports.ThebeCoreProvider = ThebeCoreProvider;
46
- function useThebeCore() {
47
- const context = react_1.default.useContext(ThebeCoreContext);
48
- if (context === undefined) {
49
- throw new Error('useThebeCore must be used inside a ThebeCoreProvider');
50
- }
51
- return context;
52
- }
53
- exports.useThebeCore = useThebeCore;
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- export type ThebeCore = typeof import('thebe-core');
3
- export declare function ThebeCoreProvider({ children }: React.PropsWithChildren): JSX.Element;
4
- export declare function useThebeCore(): {
5
- core?: typeof import("thebe-core") | undefined;
6
- };
7
- //# sourceMappingURL=thebe-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"thebe-provider.d.ts","sourceRoot":"","sources":["../../src/thebe-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,MAAM,MAAM,SAAS,GAAG,cAAc,YAAY,CAAC,CAAC;AAKpD,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,iBAAiB,eAoBtE;AAED,wBAAgB,YAAY;;EAM3B"}