@myst-theme/jupyter 0.3.1 → 0.3.3

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.
@@ -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":"AAKA,wBAAgB,oBAAoB,mDAmFnC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionStatusTray = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const thebe_react_1 = require("thebe-react");
7
+ const providers_1 = require("./providers");
8
+ function ConnectionStatusTray() {
9
+ const { thebe } = (0, providers_1.useComputeOptions)();
10
+ const { connecting, ready: serverReady, error: serverError, events } = (0, thebe_react_1.useThebeServer)();
11
+ const { starting, ready: sessionReady, error: sessionError } = (0, thebe_react_1.useThebeSession)();
12
+ const [show, setShow] = (0, react_1.useState)(false);
13
+ const [unsub, setUnsub] = (0, react_1.useState)();
14
+ const [status, setStatus] = (0, react_1.useState)('[client] Connecting...');
15
+ const error = serverError || sessionError;
16
+ const ready = serverReady && sessionReady;
17
+ const busy = connecting || starting;
18
+ const handleStatus = (event, data) => {
19
+ setStatus(`[${data.subject}]: ${data.message}`);
20
+ };
21
+ (0, react_1.useEffect)(() => {
22
+ if (!events)
23
+ return;
24
+ events.on('status', handleStatus);
25
+ }, [events]);
26
+ (0, react_1.useEffect)(() => {
27
+ if (!thebe)
28
+ return;
29
+ if ((thebe === null || thebe === void 0 ? void 0 : thebe.useBinder) || (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite)) {
30
+ if (busy || error) {
31
+ setShow(true);
32
+ }
33
+ else if (ready) {
34
+ setTimeout(() => {
35
+ setShow(false);
36
+ unsub === null || unsub === void 0 ? void 0 : unsub();
37
+ setUnsub(undefined);
38
+ }, (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite) ? 3000 : 500);
39
+ }
40
+ }
41
+ }, [thebe, busy, ready, error]);
42
+ const host = (thebe === null || thebe === void 0 ? void 0 : thebe.useBinder) ? 'Binder' : (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite) ? 'JupyterLite' : 'Local Server';
43
+ if (show && error) {
44
+ return ((0, jsx_runtime_1.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: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-2 font-semibold text-center", children: ["\u26D4\uFE0F Error connecting to ", host, " \u26D4\uFE0F"] }), (0, jsx_runtime_1.jsx)("div", { className: "my-1 max-h-[15rem] mono overflow-hidden text-ellipsis", children: error }), (0, jsx_runtime_1.jsx)("div", { className: "flex justify-end", children: (0, jsx_runtime_1.jsx)("div", { className: "text-xs cursor-pointer hover:underline", role: "button", onClick: () => setShow(false), children: "dismiss" }) })] }));
45
+ }
46
+ if (show && (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite)) {
47
+ return ((0, jsx_runtime_1.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: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-1 font-semibold text-center", children: ["\u26A1\uFE0F Connecting to ", host, " \u26A1\uFE0F"] }), !ready && (0, jsx_runtime_1.jsx)("div", { className: "max-h-[5rem] mono overflow-hidden text-ellipsis", children: status }), ready && ((0, jsx_runtime_1.jsx)("div", { className: "max-h-[15rem] mono overflow-hidden text-ellipsis", children: "The in-browser JupyterLite server is ready, press run anytime." }))] }));
48
+ }
49
+ if (show) {
50
+ return ((0, jsx_runtime_1.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: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-1 font-semibold text-center", children: ["\u26A1\uFE0F Connecting to ", host, " \u26A1\uFE0F"] }), (0, jsx_runtime_1.jsx)("div", { className: "max-h-[15rem] mono overflow-hidden text-ellipsis", children: status })] }));
51
+ }
52
+ return null;
53
+ }
54
+ exports.ConnectionStatusTray = ConnectionStatusTray;
@@ -4,5 +4,6 @@ declare const OUTPUT_RENDERERS: {
4
4
  };
5
5
  export * from './BinderBadge';
6
6
  export * from './providers';
7
+ export * from './ConnectionStatusTray';
7
8
  export default OUTPUT_RENDERERS;
8
9
  //# 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;AAEvC,eAAe,gBAAgB,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -20,4 +20,5 @@ const OUTPUT_RENDERERS = {
20
20
  };
21
21
  __exportStar(require("./BinderBadge"), exports);
22
22
  __exportStar(require("./providers"), exports);
23
+ __exportStar(require("./ConnectionStatusTray"), exports);
23
24
  exports.default = OUTPUT_RENDERERS;
@@ -70,12 +70,12 @@ exports.ConfiguredThebeServerProvider = ConfiguredThebeServerProvider;
70
70
  function notebookFromMdast(core, config, mdast, idkMap, rendermime) {
71
71
  const notebook = new core.ThebeNotebook(mdast.key, config, rendermime);
72
72
  // no metadata included in mdast yet
73
- //Object.assign(notebook.metadata, ipynb.metadata);
73
+ // Object.assign(notebook.metadata, ipynb.metadata);
74
74
  notebook.cells = mdast.children.map((block) => {
75
- var _a, _b, _c;
75
+ var _a, _b, _c, _d, _e;
76
76
  if (block.type !== 'block')
77
77
  console.warn(`Unexpected block type ${block.type}`);
78
- if (block.children.length == 2 && block.children[0].type === 'code') {
78
+ if (block.children && block.children.length == 2 && block.children[0].type === 'code') {
79
79
  const [codeCell, output] = block.children;
80
80
  // use the block.key to identify the cell but maintain a mapping
81
81
  // to allow code or output keys to look up cells and refs
@@ -87,7 +87,7 @@ function notebookFromMdast(core, config, mdast, idkMap, rendermime) {
87
87
  else {
88
88
  // assume content - concatenate it
89
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);
90
+ const cell = new core.ThebeNonExecutableCell(block.key, notebook.id, (_d = (_c = block.children) === null || _c === void 0 ? void 0 : _c.reduce((acc, child) => { var _a; return acc + '\n' + ((_a = child.value) !== null && _a !== void 0 ? _a : ''); }, '')) !== null && _d !== void 0 ? _d : '', (_e = block.data) !== null && _e !== void 0 ? _e : {}, notebook.rendermime);
91
91
  return cell;
92
92
  }
93
93
  });
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":"AAKA,wBAAgB,oBAAoB,mDAmFnC"}
@@ -0,0 +1,50 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { useThebeServer, useThebeSession } from 'thebe-react';
4
+ import { useComputeOptions } from './providers';
5
+ export function ConnectionStatusTray() {
6
+ const { thebe } = useComputeOptions();
7
+ const { connecting, ready: serverReady, error: serverError, events } = useThebeServer();
8
+ const { starting, ready: sessionReady, error: sessionError } = useThebeSession();
9
+ const [show, setShow] = useState(false);
10
+ const [unsub, setUnsub] = useState();
11
+ const [status, setStatus] = useState('[client] Connecting...');
12
+ const error = serverError || sessionError;
13
+ const ready = serverReady && sessionReady;
14
+ const busy = connecting || starting;
15
+ const handleStatus = (event, data) => {
16
+ setStatus(`[${data.subject}]: ${data.message}`);
17
+ };
18
+ useEffect(() => {
19
+ if (!events)
20
+ return;
21
+ events.on('status', handleStatus);
22
+ }, [events]);
23
+ useEffect(() => {
24
+ if (!thebe)
25
+ return;
26
+ if ((thebe === null || thebe === void 0 ? void 0 : thebe.useBinder) || (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite)) {
27
+ if (busy || error) {
28
+ setShow(true);
29
+ }
30
+ else if (ready) {
31
+ setTimeout(() => {
32
+ setShow(false);
33
+ unsub === null || unsub === void 0 ? void 0 : unsub();
34
+ setUnsub(undefined);
35
+ }, (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite) ? 3000 : 500);
36
+ }
37
+ }
38
+ }, [thebe, busy, ready, error]);
39
+ const host = (thebe === null || thebe === void 0 ? void 0 : thebe.useBinder) ? 'Binder' : (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite) ? 'JupyterLite' : 'Local Server';
40
+ if (show && error) {
41
+ return (_jsxs("div", { className: "fixed p-3 text-sm text-gray-700 bg-white border rounded shadow-lg bottom-2 sm:right-2 max-w-[90%] md:max-w-[300px] min-w-0", children: [_jsxs("div", { className: "mb-2 font-semibold text-center", children: ["\u26D4\uFE0F Error connecting to ", host, " \u26D4\uFE0F"] }), _jsx("div", { className: "my-1 max-h-[15rem] mono overflow-hidden text-ellipsis", children: error }), _jsx("div", { className: "flex justify-end", children: _jsx("div", { className: "text-xs cursor-pointer hover:underline", role: "button", onClick: () => setShow(false), children: "dismiss" }) })] }));
42
+ }
43
+ if (show && (thebe === null || thebe === void 0 ? void 0 : thebe.useJupyterLite)) {
44
+ 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." }))] }));
45
+ }
46
+ if (show) {
47
+ 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 })] }));
48
+ }
49
+ return null;
50
+ }
@@ -4,5 +4,6 @@ declare const OUTPUT_RENDERERS: {
4
4
  };
5
5
  export * from './BinderBadge';
6
6
  export * from './providers';
7
+ export * from './ConnectionStatusTray';
7
8
  export default OUTPUT_RENDERERS;
8
9
  //# 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;AAEvC,eAAe,gBAAgB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -4,4 +4,5 @@ const OUTPUT_RENDERERS = {
4
4
  };
5
5
  export * from './BinderBadge';
6
6
  export * from './providers';
7
+ export * from './ConnectionStatusTray';
7
8
  export default OUTPUT_RENDERERS;
@@ -42,12 +42,12 @@ export function ConfiguredThebeServerProvider({ children }) {
42
42
  export function notebookFromMdast(core, config, mdast, idkMap, rendermime) {
43
43
  const notebook = new core.ThebeNotebook(mdast.key, config, rendermime);
44
44
  // no metadata included in mdast yet
45
- //Object.assign(notebook.metadata, ipynb.metadata);
45
+ // Object.assign(notebook.metadata, ipynb.metadata);
46
46
  notebook.cells = mdast.children.map((block) => {
47
- var _a, _b, _c;
47
+ var _a, _b, _c, _d, _e;
48
48
  if (block.type !== 'block')
49
49
  console.warn(`Unexpected block type ${block.type}`);
50
- if (block.children.length == 2 && block.children[0].type === 'code') {
50
+ if (block.children && block.children.length == 2 && block.children[0].type === 'code') {
51
51
  const [codeCell, output] = block.children;
52
52
  // use the block.key to identify the cell but maintain a mapping
53
53
  // to allow code or output keys to look up cells and refs
@@ -59,7 +59,7 @@ export function notebookFromMdast(core, config, mdast, idkMap, rendermime) {
59
59
  else {
60
60
  // assume content - concatenate it
61
61
  // TODO inject cell metadata
62
- 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);
62
+ const cell = new core.ThebeNonExecutableCell(block.key, notebook.id, (_d = (_c = block.children) === null || _c === void 0 ? void 0 : _c.reduce((acc, child) => { var _a; return acc + '\n' + ((_a = child.value) !== null && _a !== void 0 ? _a : ''); }, '')) !== null && _d !== void 0 ? _d : '', (_e = block.data) !== null && _e !== void 0 ? _e : {}, notebook.rendermime);
63
63
  return cell;
64
64
  }
65
65
  });
package/dist/esm/safe.js CHANGED
@@ -55,7 +55,7 @@ function SafeOutput({ output }) {
55
55
  if (image)
56
56
  return _jsx(OutputImage, { image: image, text: text });
57
57
  if (text)
58
- return (_jsx("div", { className: "whitespace-pre-wrap font-mono text-sm", children: _jsx(Ansi, { children: text.content }) }));
58
+ return (_jsx("div", { className: "font-mono text-sm whitespace-pre-wrap", children: _jsx(Ansi, { children: text.content }) }));
59
59
  return null;
60
60
  }
61
61
  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":"AAKA,wBAAgB,oBAAoB,mDAmFnC"}
@@ -4,5 +4,6 @@ declare const OUTPUT_RENDERERS: {
4
4
  };
5
5
  export * from './BinderBadge';
6
6
  export * from './providers';
7
+ export * from './ConnectionStatusTray';
7
8
  export default OUTPUT_RENDERERS;
8
9
  //# 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;AAEvC,eAAe,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myst-theme/jupyter",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@headlessui/react": "^1.7.15",
24
24
  "@heroicons/react": "^2.0.18",
25
- "@myst-theme/providers": "^0.3.1",
25
+ "@myst-theme/providers": "^0.3.3",
26
26
  "ansi-to-react": "^6.1.6",
27
27
  "buffer": "^6.0.3",
28
28
  "classnames": "^2.3.2",
@@ -34,9 +34,9 @@
34
34
  "nbtx": "^0.2.3",
35
35
  "react-syntax-highlighter": "^15.5.0",
36
36
  "swr": "^2.1.5",
37
- "thebe-core": "^0.2.3",
38
- "thebe-lite": "^0.2.3",
39
- "thebe-react": "^0.2.3",
37
+ "thebe-core": "^0.2.5",
38
+ "thebe-lite": "^0.2.5",
39
+ "thebe-react": "^0.2.5",
40
40
  "unist-util-select": "^4.0.3"
41
41
  },
42
42
  "peerDependencies": {