@myst-theme/jupyter 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BinderBadge.js +2 -2
- package/dist/cjs/components.js +1 -1
- package/dist/cjs/error.js +1 -1
- package/dist/cjs/hooks.js +1 -1
- package/dist/cjs/jupyter.d.ts +3 -2
- package/dist/cjs/jupyter.d.ts.map +1 -1
- package/dist/cjs/jupyter.js +27 -26
- package/dist/cjs/output.d.ts.map +1 -1
- package/dist/cjs/output.js +6 -5
- package/dist/cjs/providers.d.ts +15 -12
- package/dist/cjs/providers.d.ts.map +1 -1
- package/dist/cjs/providers.js +48 -90
- package/dist/cjs/safe.js +1 -1
- package/dist/cjs/stream.js +1 -1
- package/dist/cjs/utils.d.ts +8 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +179 -0
- package/dist/esm/BinderBadge.js +2 -2
- package/dist/esm/components.js +1 -1
- package/dist/esm/error.js +1 -1
- package/dist/esm/hooks.js +1 -1
- package/dist/esm/jupyter.d.ts +3 -2
- package/dist/esm/jupyter.d.ts.map +1 -1
- package/dist/esm/jupyter.js +29 -27
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +7 -6
- package/dist/esm/providers.d.ts +15 -12
- package/dist/esm/providers.d.ts.map +1 -1
- package/dist/esm/providers.js +47 -89
- package/dist/esm/safe.js +1 -1
- package/dist/esm/stream.js +1 -1
- package/dist/esm/utils.d.ts +8 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +175 -0
- package/dist/types/jupyter.d.ts +3 -2
- package/dist/types/jupyter.d.ts.map +1 -1
- package/dist/types/output.d.ts.map +1 -1
- package/dist/types/providers.d.ts +15 -12
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/utils.d.ts +8 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +13 -17
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.thebeFrontmatterToOptions = void 0;
|
|
4
|
+
function extractGithubRepoInfo(url) {
|
|
5
|
+
const pattern = /https?:\/\/github\.com\/([^/]+)\/([^/]+)/;
|
|
6
|
+
const match = url.match(pattern);
|
|
7
|
+
if (match) {
|
|
8
|
+
return {
|
|
9
|
+
owner: match[1],
|
|
10
|
+
repo: match[2],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
function extractBinderRepoInfo(url) {
|
|
16
|
+
const pattern = /(https?:\/\/[^/]+(?:\/[^/]+)*?)\/(v\d+)\/([^/]+)\/([^/]+)\/([^/]+)\/([^/]+)/;
|
|
17
|
+
const match = url.match(pattern);
|
|
18
|
+
if (match) {
|
|
19
|
+
const repoProviderAbbreviation = match[3];
|
|
20
|
+
let repoProvider;
|
|
21
|
+
switch (repoProviderAbbreviation) {
|
|
22
|
+
case 'gh':
|
|
23
|
+
repoProvider = 'github';
|
|
24
|
+
break;
|
|
25
|
+
case 'gl':
|
|
26
|
+
repoProvider = 'gitlab';
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
repoProvider = repoProviderAbbreviation;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
binderUrl: match[1],
|
|
33
|
+
repoProvider: repoProvider,
|
|
34
|
+
owner: match[4],
|
|
35
|
+
repo: match[5],
|
|
36
|
+
ref: match[6],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
function isObject(maybeObject) {
|
|
42
|
+
return typeof maybeObject === 'object' && maybeObject !== null;
|
|
43
|
+
}
|
|
44
|
+
function thebeFrontmatterToOptions(fm, githubBadgeUrl, binderBadgeUrl) {
|
|
45
|
+
var _a;
|
|
46
|
+
if (fm === undefined || fm === false)
|
|
47
|
+
return undefined;
|
|
48
|
+
const { binder, server, lite, local, kernelName, disableSessionSaving, mathjaxConfig, mathjaxUrl, } = (_a = fm) !== null && _a !== void 0 ? _a : {};
|
|
49
|
+
const thebeOptions = { mathjaxConfig, mathjaxUrl };
|
|
50
|
+
if (disableSessionSaving) {
|
|
51
|
+
thebeOptions.savedSessionOptions = { enabled: false };
|
|
52
|
+
}
|
|
53
|
+
// handle thebe.local.*
|
|
54
|
+
// as local OVERIDES other binder and server settings, handle these first
|
|
55
|
+
// TODO need to expose NODE_ENV somehow via a loader
|
|
56
|
+
let NODE_ENV = 'development';
|
|
57
|
+
if (typeof window !== 'undefined') {
|
|
58
|
+
NODE_ENV = window.NODE_ENV;
|
|
59
|
+
}
|
|
60
|
+
if (NODE_ENV !== 'production' && local) {
|
|
61
|
+
if (isObject(local)) {
|
|
62
|
+
const { url, token, kernelName: localKernelName } = local;
|
|
63
|
+
if (url || token) {
|
|
64
|
+
thebeOptions.serverSettings = {};
|
|
65
|
+
if (url)
|
|
66
|
+
thebeOptions.serverSettings.baseUrl = url;
|
|
67
|
+
if (token)
|
|
68
|
+
thebeOptions.serverSettings.token = token;
|
|
69
|
+
}
|
|
70
|
+
if (localKernelName) {
|
|
71
|
+
thebeOptions.kernelOptions = { kernelName: localKernelName };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return thebeOptions;
|
|
75
|
+
// else just fall through & return - TODO return early?
|
|
76
|
+
}
|
|
77
|
+
// handle additional optons
|
|
78
|
+
if (kernelName) {
|
|
79
|
+
thebeOptions.kernelOptions = {
|
|
80
|
+
kernelName: kernelName,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// handle shortcut options for binder
|
|
84
|
+
/**
|
|
85
|
+
* github: owner/repo | url
|
|
86
|
+
* binder: url
|
|
87
|
+
* thebe: true
|
|
88
|
+
*
|
|
89
|
+
* OR
|
|
90
|
+
*
|
|
91
|
+
* github: owner/repo | url
|
|
92
|
+
* binder: url
|
|
93
|
+
* thebe:
|
|
94
|
+
* binder: true
|
|
95
|
+
*/
|
|
96
|
+
if (binder === true || (fm === true && (githubBadgeUrl || binderBadgeUrl))) {
|
|
97
|
+
thebeOptions.useBinder = true;
|
|
98
|
+
if (githubBadgeUrl || binderBadgeUrl) {
|
|
99
|
+
const isValidBinderUrl = binderBadgeUrl ? extractBinderRepoInfo(binderBadgeUrl) : false;
|
|
100
|
+
if (isValidBinderUrl) {
|
|
101
|
+
const { binderUrl, owner, repo, ref } = isValidBinderUrl;
|
|
102
|
+
thebeOptions.binderOptions = {
|
|
103
|
+
binderUrl,
|
|
104
|
+
repo: `${owner}/${repo}`,
|
|
105
|
+
ref,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
else if (githubBadgeUrl) {
|
|
109
|
+
// TODO test for owner/repo vs url
|
|
110
|
+
const isUrl = extractGithubRepoInfo(githubBadgeUrl);
|
|
111
|
+
if (isUrl != null) {
|
|
112
|
+
const { owner, repo } = isUrl;
|
|
113
|
+
thebeOptions.binderOptions = {
|
|
114
|
+
repo: `${owner}/${repo}`,
|
|
115
|
+
ref: 'HEAD',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
else if (githubBadgeUrl.split('/').length === 2) {
|
|
119
|
+
// assume owner/repo
|
|
120
|
+
thebeOptions.binderOptions = {
|
|
121
|
+
repo: githubBadgeUrl,
|
|
122
|
+
ref: 'HEAD',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.debug('myst-theme:thebeFrontmatterToOptions looks like an invalid github frontmatter value', githubBadgeUrl);
|
|
127
|
+
console.debug('myst-theme:thebeFrontmatterToOptions cannot connect to binder');
|
|
128
|
+
thebeOptions.useBinder = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (isObject(binder)) {
|
|
134
|
+
// handle fully specified binder options
|
|
135
|
+
thebeOptions.useBinder = true;
|
|
136
|
+
const { url, ref, provider, repo } = binder;
|
|
137
|
+
thebeOptions.binderOptions = {
|
|
138
|
+
ref,
|
|
139
|
+
repo,
|
|
140
|
+
};
|
|
141
|
+
if (url)
|
|
142
|
+
thebeOptions.binderOptions.binderUrl = url;
|
|
143
|
+
if (provider)
|
|
144
|
+
thebeOptions.binderOptions.repoProvider = provider; // ffs
|
|
145
|
+
}
|
|
146
|
+
// handle jupyterlite
|
|
147
|
+
/**
|
|
148
|
+
* thebe:
|
|
149
|
+
* lite: true
|
|
150
|
+
*/
|
|
151
|
+
if (lite === true) {
|
|
152
|
+
thebeOptions.useJupyterLite = true;
|
|
153
|
+
}
|
|
154
|
+
// handle shortcut options for direct server, which really is the fallback for any shortcut option
|
|
155
|
+
/**
|
|
156
|
+
* github: undefined
|
|
157
|
+
* binder: undefined
|
|
158
|
+
* thebe: true
|
|
159
|
+
*
|
|
160
|
+
* OR
|
|
161
|
+
*
|
|
162
|
+
* github: undefined
|
|
163
|
+
* binder: undefined
|
|
164
|
+
* thebe:
|
|
165
|
+
* server: true
|
|
166
|
+
*/
|
|
167
|
+
if (isObject(server)) {
|
|
168
|
+
// handle fully specified server object
|
|
169
|
+
const { url, token } = server;
|
|
170
|
+
thebeOptions.serverSettings = {};
|
|
171
|
+
if (url)
|
|
172
|
+
thebeOptions.serverSettings.baseUrl = url;
|
|
173
|
+
if (token)
|
|
174
|
+
thebeOptions.serverSettings.token = token;
|
|
175
|
+
}
|
|
176
|
+
// else if (fm === true || server === true || !server) => do nothing - just return / fall though for defaults
|
|
177
|
+
return thebeOptions;
|
|
178
|
+
}
|
|
179
|
+
exports.thebeFrontmatterToOptions = thebeFrontmatterToOptions;
|
package/dist/esm/BinderBadge.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
function BinderBadgeLogo() {
|
|
3
|
-
return (_jsxs("svg",
|
|
3
|
+
return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "109", height: "20", children: [_jsxs("linearGradient", { id: "b", x2: "0", y2: "100%", children: [_jsx("stop", { offset: "0", stopColor: "#bbb", stopOpacity: ".1" }), _jsx("stop", { offset: "1", stopOpacity: ".1" })] }), _jsx("clipPath", { id: "a", children: _jsx("rect", { width: "109", height: "20", fill: "#fff", rx: "3" }) }), _jsxs("g", { clipPath: "url(#a)", children: [_jsx("path", { fill: "#555", d: "M0 0h64v20H0z" }), _jsx("path", { fill: "#579aca", d: "M64 0h45v20H64z" }), _jsx("path", { fill: "url(#b)", d: "M0 0h109v20H0z" })] }), _jsxs("g", { fill: "#fff", fontFamily: "DejaVu Sans,Verdana,Geneva,sans-serif", fontSize: "110", textAnchor: "middle", children: [_jsx("image", { width: "14", height: "14", x: "5", y: "3", href: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJXmsr1olJXmsrmZYH1olL1olKkfaPobXvviGabgadXmsqThKuofKHmZ4Dobnr1olJXmsr1olJXmspXmsr1olJXmsrfZ4TuhWn1olL1olJXmsqBi7X1olJXmspZmslbmMhbmsdemsVfl8ZgmsNim8Jpk8F0m7R4m7F5nLB6jbh7jbiDirOEibOGnKaMhq+PnaCVg6qWg6qegKaff6WhnpKofKGtnomxeZy3noG6dZi+n3vCcpPDcpPGn3bLb4/Mb47UbIrVa4rYoGjdaIbeaIXhoWHmZYHobXvpcHjqdHXreHLroVrsfG/uhGnuh2bwj2Hxk17yl1vzmljzm1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GaVuj0d9zy05PPK3QzBamxdwtTCrzyg/2Rvf2EstUjordGwa/kx9mSJLr8mLLtCW8HHGJc2R5hS219IiF6PnTusOqcMl57gm0Z8kanKMAQg0qSyuZfn7zItsbGyO9QlnxY0eCuD1XL2ys/MsrQhltE7Ug0uFOzufJFE2PxBo/YAx8XPPdDwWN0MrDRYIZF0mSMKCNHgaIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC" }), _jsx("text", { x: "415", y: "150", fill: "#010101", fillOpacity: ".3", textLength: "370", transform: "scale(.1)", children: "launch" }), _jsx("text", { x: "415", y: "140", textLength: "370", transform: "scale(.1)", children: "launch" }), _jsx("text", { x: "855", y: "150", fill: "#010101", fillOpacity: ".3", textLength: "350", transform: "scale(.1)", children: "binder" }), _jsx("text", { x: "855", y: "140", textLength: "350", transform: "scale(.1)", children: "binder" })] })] }));
|
|
4
4
|
}
|
|
5
5
|
export function BinderBadge({ binder }) {
|
|
6
6
|
if (!binder)
|
|
7
7
|
return null;
|
|
8
|
-
return (_jsx("div",
|
|
8
|
+
return (_jsx("div", { className: "inline-block mr-1 opacity-80 hover:opacity-100", children: _jsx("a", { href: binder, title: `Launch Binder Session: ${binder}`, target: "_blank", rel: "noopener noreferrer", className: "text-inherit hover:text-inherit", children: _jsx(BinderBadgeLogo, {}) }) }));
|
|
9
9
|
}
|
package/dist/esm/components.js
CHANGED
|
@@ -15,7 +15,7 @@ import { useLongContent } from './hooks';
|
|
|
15
15
|
export const MaybeLongContent = ({ content, path, render, }) => {
|
|
16
16
|
const { error, data } = useLongContent(content, path);
|
|
17
17
|
if (error) {
|
|
18
|
-
return _jsxs("div",
|
|
18
|
+
return _jsxs("div", { className: "text-red-500", children: ["Error loading content: ", error.message] });
|
|
19
19
|
}
|
|
20
20
|
if (!data) {
|
|
21
21
|
return _jsx("div", { children: "Fetching long content...." });
|
package/dist/esm/error.js
CHANGED
|
@@ -4,6 +4,6 @@ import { ensureString } from 'nbtx';
|
|
|
4
4
|
import { MaybeLongContent } from './components';
|
|
5
5
|
export default function Error({ output }) {
|
|
6
6
|
return (_jsx(MaybeLongContent, { content: ensureString(output.traceback), path: output.path, render: (content) => {
|
|
7
|
-
return (_jsx("pre",
|
|
7
|
+
return (_jsx("pre", { className: "text-sm font-thin font-system jupyter-error", children: _jsx(Ansi, { children: content !== null && content !== void 0 ? content : '' }) }));
|
|
8
8
|
} }));
|
|
9
9
|
}
|
package/dist/esm/hooks.js
CHANGED
|
@@ -47,7 +47,7 @@ export function useLongContent(content, url) {
|
|
|
47
47
|
return { data, error };
|
|
48
48
|
}
|
|
49
49
|
const arrayFetcher = (...urls) => {
|
|
50
|
-
return Promise.all(urls.map((url) => fetcher(url)));
|
|
50
|
+
return Promise.all(urls.map((url) => fetcher(url[0])));
|
|
51
51
|
};
|
|
52
52
|
function shallowCloneOutputs(outputs) {
|
|
53
53
|
return outputs.map((output) => {
|
package/dist/esm/jupyter.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import type { MinifiedOutput } from 'nbtx';
|
|
2
|
-
export declare const JupyterOutputs: ({ id, outputs }: {
|
|
3
|
+
export declare const JupyterOutputs: React.MemoExoticComponent<({ id, outputs }: {
|
|
3
4
|
id: string;
|
|
4
5
|
outputs: MinifiedOutput[];
|
|
5
|
-
}) => import("react/jsx-runtime").JSX.Element
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element>;
|
|
6
7
|
//# sourceMappingURL=jupyter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jupyter.d.ts","sourceRoot":"","sources":["../../src/jupyter.tsx"],"names":[],"mappings":"
|
|
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"}
|
package/dist/esm/jupyter.js
CHANGED
|
@@ -1,50 +1,52 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } 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 {
|
|
7
|
-
import { useCellRef, useCellRefRegistry, useNotebookCellExecution } from './providers';
|
|
6
|
+
import { useNotebookCellExecution } from './providers';
|
|
8
7
|
import { SourceFileKind } from 'myst-common';
|
|
9
8
|
import { useXRefState } from '@myst-theme/providers';
|
|
9
|
+
import { useThebeLoader } from 'thebe-react';
|
|
10
10
|
function ActiveOutputRenderer({ id, data }) {
|
|
11
|
-
const ref = useCellRef(id);
|
|
12
11
|
const exec = useNotebookCellExecution(id);
|
|
12
|
+
const ref = useRef(null);
|
|
13
13
|
useEffect(() => {
|
|
14
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
if (!ref.current || !(exec === null || exec === void 0 ? void 0 : exec.cell)) {
|
|
16
|
+
console.debug(`No cell ref available for cell ${(_a = exec === null || exec === void 0 ? void 0 : exec.cell) === null || _a === void 0 ? void 0 : _a.id}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (exec.cell.isAttachedToDOM) {
|
|
20
|
+
console.debug(`Cell ${exec.cell.id} already attached to DOM`);
|
|
15
21
|
return;
|
|
22
|
+
}
|
|
16
23
|
console.debug(`Attaching cell ${exec.cell.id} to DOM at:`, {
|
|
17
|
-
el: ref.
|
|
18
|
-
connected: ref.
|
|
24
|
+
el: ref.current,
|
|
25
|
+
connected: ref.current.isConnected,
|
|
19
26
|
data,
|
|
20
27
|
});
|
|
21
|
-
exec.cell.attachToDOM(ref.
|
|
28
|
+
exec.cell.attachToDOM(ref.current);
|
|
22
29
|
exec.cell.render(data);
|
|
23
|
-
}, [ref === null || ref === void 0 ? void 0 : ref.
|
|
24
|
-
return
|
|
30
|
+
}, [ref === null || ref === void 0 ? void 0 : ref.current, exec === null || exec === void 0 ? void 0 : exec.cell]);
|
|
31
|
+
return _jsx("div", { ref: ref, "data-thebe-active-ref": "true", className: "relative" });
|
|
25
32
|
}
|
|
26
33
|
function PassiveOutputRenderer({ id, data, core, kind, }) {
|
|
27
|
-
const
|
|
34
|
+
const cell = useRef(new core.PassiveCellRenderer(id, undefined, undefined));
|
|
28
35
|
const ref = useRef(null);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
cell.render(data, kind === SourceFileKind.Article);
|
|
31
|
-
}, [data, cell]);
|
|
32
36
|
useEffect(() => {
|
|
33
37
|
if (!ref.current)
|
|
34
38
|
return;
|
|
35
|
-
cell.attachToDOM(ref.current, true);
|
|
39
|
+
cell.current.attachToDOM(ref.current, true);
|
|
40
|
+
cell.current.render(data, kind === SourceFileKind.Article);
|
|
36
41
|
}, [ref]);
|
|
37
42
|
return _jsx("div", { ref: ref, "data-thebe-passive-ref": "true" });
|
|
38
43
|
}
|
|
39
|
-
const
|
|
40
|
-
export const JupyterOutputs = ({ id, outputs }) => {
|
|
44
|
+
export const JupyterOutputs = React.memo(({ id, outputs }) => {
|
|
41
45
|
var _a;
|
|
42
|
-
const { core, load } =
|
|
46
|
+
const { core, load } = useThebeLoader();
|
|
43
47
|
const { inCrossRef } = useXRefState();
|
|
44
48
|
const { data, error } = useFetchAnyTruncatedContent(outputs);
|
|
45
|
-
const [loaded, setLoaded] = useState(false);
|
|
46
49
|
const [fullOutputs, setFullOutputs] = useState(null);
|
|
47
|
-
const registry = useCellRefRegistry();
|
|
48
50
|
const exec = useNotebookCellExecution(id);
|
|
49
51
|
useEffect(() => {
|
|
50
52
|
if (core)
|
|
@@ -52,19 +54,19 @@ export const JupyterOutputs = ({ id, outputs }) => {
|
|
|
52
54
|
load();
|
|
53
55
|
}, [core, load]);
|
|
54
56
|
useEffect(() => {
|
|
55
|
-
if (!data ||
|
|
57
|
+
if (!data || fullOutputs != null)
|
|
56
58
|
return;
|
|
57
|
-
setLoaded(true);
|
|
58
59
|
fetchAndEncodeOutputImages(data).then((out) => {
|
|
59
60
|
const compactOutputs = convertToIOutputs(out, {});
|
|
60
61
|
setFullOutputs(compactOutputs);
|
|
61
62
|
});
|
|
62
63
|
}, [id, data, fullOutputs]);
|
|
63
64
|
if (error) {
|
|
64
|
-
|
|
65
|
+
console.error(error);
|
|
66
|
+
return _jsxs("div", { className: "text-red-500", children: ["Error rendering output: ", error.message] });
|
|
65
67
|
}
|
|
66
|
-
if (!inCrossRef &&
|
|
67
|
-
return (_jsxs("div",
|
|
68
|
+
if (!inCrossRef && (exec === null || exec === void 0 ? void 0 : exec.ready)) {
|
|
69
|
+
return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && _jsx(ActiveOutputRenderer, { id: id, data: fullOutputs })] }));
|
|
68
70
|
}
|
|
69
|
-
return (_jsxs(
|
|
70
|
-
};
|
|
71
|
+
return (_jsxs("div", { children: [!fullOutputs && _jsx("div", { className: "p-2.5", children: "Loading..." }), fullOutputs && core && (_jsx(PassiveOutputRenderer, { id: id, data: fullOutputs, core: core, kind: (_a = exec === null || exec === void 0 ? void 0 : exec.kind) !== null && _a !== void 0 ? _a : SourceFileKind.Notebook }))] }));
|
|
72
|
+
});
|
package/dist/esm/output.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/esm/output.js
CHANGED
|
@@ -3,7 +3,8 @@ import { KnownCellOutputMimeTypes } from 'nbtx';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { SafeOutputs } from './safe';
|
|
5
5
|
import { JupyterOutputs } from './jupyter';
|
|
6
|
-
import {
|
|
6
|
+
import { useReadyToExecute } from './providers';
|
|
7
|
+
import { useMemo } from 'react';
|
|
7
8
|
export const DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);
|
|
8
9
|
export const DIRECT_MIME_TYPES = new Set([
|
|
9
10
|
KnownCellOutputMimeTypes.TextPlain,
|
|
@@ -25,21 +26,21 @@ export function allOutputsAreSafe(outputs, directOutputTypes, directMimeTypes) {
|
|
|
25
26
|
}, true);
|
|
26
27
|
}
|
|
27
28
|
function JupyterOutput({ nodeKey, nodeType, identifier, data, align, }) {
|
|
28
|
-
const
|
|
29
|
+
const ready = useReadyToExecute();
|
|
29
30
|
const outputs = data;
|
|
30
|
-
const allSafe = allOutputsAreSafe(outputs, DIRECT_OUTPUT_TYPES, DIRECT_MIME_TYPES);
|
|
31
|
+
const allSafe = useMemo(() => allOutputsAreSafe(outputs, DIRECT_OUTPUT_TYPES, DIRECT_MIME_TYPES), [outputs]);
|
|
31
32
|
let component;
|
|
32
|
-
if (allSafe && !
|
|
33
|
+
if (allSafe && !ready) {
|
|
33
34
|
component = _jsx(SafeOutputs, { keyStub: nodeKey, outputs: outputs });
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
36
37
|
component = _jsx(JupyterOutputs, { id: nodeKey, outputs: outputs });
|
|
37
38
|
}
|
|
38
|
-
return (_jsx("figure",
|
|
39
|
+
return (_jsx("figure", { id: identifier || undefined, "data-mdast-node-type": nodeType, "data-mdast-node-id": nodeKey, className: classNames('max-w-full overflow-visible m-0 group not-prose relative', {
|
|
39
40
|
'text-left': !align || align === 'left',
|
|
40
41
|
'text-center': align === 'center',
|
|
41
42
|
'text-right': align === 'right',
|
|
42
|
-
})
|
|
43
|
+
}), children: component }));
|
|
43
44
|
}
|
|
44
45
|
export function Output(node) {
|
|
45
46
|
// Note, NodeRenderer's can't have hooks in it directly!
|
package/dist/esm/providers.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { GenericParent } from 'myst-common';
|
|
2
2
|
import { SourceFileKind } from 'myst-common';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import type { Config, IThebeCell, IThebeCellExecuteReturn, ThebeCore, ThebeNotebook } from 'thebe-core';
|
|
4
|
+
import type { Config, IRenderMimeRegistry, IThebeCell, IThebeCellExecuteReturn, ThebeCore, ThebeNotebook } from 'thebe-core';
|
|
5
5
|
import type { IThebeNotebookError, NotebookExecuteOptions } from 'thebe-react';
|
|
6
6
|
import type { Root } from 'mdast';
|
|
7
|
+
export declare function useComputeOptions(): {
|
|
8
|
+
canCompute: boolean;
|
|
9
|
+
thebe?: undefined;
|
|
10
|
+
githubBadgeUrl?: undefined;
|
|
11
|
+
binderBadgeUrl?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
canCompute: boolean;
|
|
14
|
+
thebe: import("./utils").ExtendedCoreOptions | undefined;
|
|
15
|
+
githubBadgeUrl: string | undefined;
|
|
16
|
+
binderBadgeUrl: string | undefined;
|
|
17
|
+
};
|
|
7
18
|
export declare function ConfiguredThebeServerProvider({ children }: React.PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
8
19
|
export type PartialPage = {
|
|
9
20
|
kind: SourceFileKind;
|
|
@@ -12,8 +23,7 @@ export type PartialPage = {
|
|
|
12
23
|
slug: string;
|
|
13
24
|
mdast: Root;
|
|
14
25
|
};
|
|
15
|
-
export declare function notebookFromMdast(core: ThebeCore, config: Config, mdast: GenericParent, idkMap: Record<string, string
|
|
16
|
-
type CellRefRegistry = Record<string, HTMLDivElement>;
|
|
26
|
+
export declare function notebookFromMdast(core: ThebeCore, config: Config, mdast: GenericParent, idkMap: Record<string, string>, rendermime: IRenderMimeRegistry): ThebeNotebook;
|
|
17
27
|
type IdKeyMap = Record<string, string>;
|
|
18
28
|
interface NotebookContextType {
|
|
19
29
|
kind: SourceFileKind;
|
|
@@ -25,9 +35,7 @@ interface NotebookContextType {
|
|
|
25
35
|
executeAll: (options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
|
|
26
36
|
executeSome: (predicate: (cell: IThebeCell) => boolean, options?: NotebookExecuteOptions | undefined) => Promise<(IThebeCellExecuteReturn | null)[]>;
|
|
27
37
|
notebook: ThebeNotebook | undefined;
|
|
28
|
-
registry: CellRefRegistry;
|
|
29
38
|
idkMap: IdKeyMap;
|
|
30
|
-
register: (id: string) => (el: HTMLDivElement) => void;
|
|
31
39
|
restart: () => Promise<void>;
|
|
32
40
|
clear: () => void;
|
|
33
41
|
}
|
|
@@ -36,12 +44,6 @@ export declare function NotebookProvider({ siteConfig, page, children, }: React.
|
|
|
36
44
|
page: PartialPage;
|
|
37
45
|
}>): import("react/jsx-runtime").JSX.Element;
|
|
38
46
|
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
47
|
export declare function useMDASTNotebook(): NotebookContextType | undefined;
|
|
46
48
|
export declare function useNotebookExecution(): {
|
|
47
49
|
ready: boolean;
|
|
@@ -53,6 +55,7 @@ export declare function useNotebookExecution(): {
|
|
|
53
55
|
notebook: ThebeNotebook | undefined;
|
|
54
56
|
clear: () => void;
|
|
55
57
|
} | undefined;
|
|
58
|
+
export declare function useReadyToExecute(): boolean;
|
|
56
59
|
export declare function useNotebookCellExecution(id: string): {
|
|
57
60
|
kind: SourceFileKind;
|
|
58
61
|
ready: boolean;
|
|
@@ -61,7 +64,7 @@ export declare function useNotebookCellExecution(id: string): {
|
|
|
61
64
|
notebookIsExecuting: boolean;
|
|
62
65
|
execute: (options?: NotebookExecuteOptions) => Promise<(IThebeCellExecuteReturn | null)[]>;
|
|
63
66
|
clear: () => void | undefined;
|
|
64
|
-
notebook: ThebeNotebook
|
|
67
|
+
notebook: ThebeNotebook;
|
|
65
68
|
} | undefined;
|
|
66
69
|
export {};
|
|
67
70
|
//# 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,C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