@myst-theme/jupyter 0.2.10 → 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 +15 -19
package/dist/esm/providers.js
CHANGED
|
@@ -10,53 +10,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { SourceFileKind } from 'myst-common';
|
|
12
12
|
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
13
|
-
import { useNotebookBase, useThebeConfig,
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
import { useThebeLoader, useRenderMimeRegistry, useNotebookBase, useThebeConfig, ThebeServerProvider, } from 'thebe-react';
|
|
14
|
+
import { useSiteManifest } from '@myst-theme/providers';
|
|
15
|
+
import { thebeFrontmatterToOptions } from './utils';
|
|
16
|
+
export function useComputeOptions() {
|
|
17
|
+
const config = useSiteManifest();
|
|
18
|
+
const makeOptions = () => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (!config)
|
|
21
|
+
return { canCompute: false };
|
|
22
|
+
// TODO there may be multiple projects?
|
|
23
|
+
// useProjectManifest?
|
|
24
|
+
const mainProject = (_a = config === null || config === void 0 ? void 0 : config.projects) === null || _a === void 0 ? void 0 : _a[0];
|
|
25
|
+
const thebeFrontmatter = mainProject === null || mainProject === void 0 ? void 0 : mainProject.thebe;
|
|
26
|
+
const githubBadgeUrl = mainProject === null || mainProject === void 0 ? void 0 : mainProject.github;
|
|
27
|
+
const binderBadgeUrl = mainProject === null || mainProject === void 0 ? void 0 : mainProject.binder;
|
|
28
|
+
const thebeOptions = thebeFrontmatterToOptions(thebeFrontmatter, githubBadgeUrl, binderBadgeUrl);
|
|
29
|
+
return {
|
|
30
|
+
canCompute: thebeFrontmatter !== undefined && thebeFrontmatter !== false,
|
|
31
|
+
thebe: thebeOptions,
|
|
32
|
+
githubBadgeUrl,
|
|
33
|
+
binderBadgeUrl,
|
|
27
34
|
};
|
|
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
35
|
};
|
|
45
|
-
|
|
46
|
-
output.savedSessionOptions = {
|
|
47
|
-
enabled: true,
|
|
48
|
-
maxAge: 38300,
|
|
49
|
-
storagePrefix: 'thebe',
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return output;
|
|
36
|
+
return React.useMemo(makeOptions, [config]);
|
|
53
37
|
}
|
|
54
38
|
export function ConfiguredThebeServerProvider({ children }) {
|
|
55
|
-
const thebe =
|
|
56
|
-
return (_jsx(ThebeServerProvider,
|
|
39
|
+
const { thebe } = useComputeOptions();
|
|
40
|
+
return (_jsx(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 }));
|
|
57
41
|
}
|
|
58
|
-
export function notebookFromMdast(core, config, mdast, idkMap) {
|
|
59
|
-
const rendermime = undefined; // share rendermime beyond notebook scope?
|
|
42
|
+
export function notebookFromMdast(core, config, mdast, idkMap, rendermime) {
|
|
60
43
|
const notebook = new core.ThebeNotebook(mdast.key, config, rendermime);
|
|
61
44
|
// no metadata included in mdast yet
|
|
62
45
|
//Object.assign(notebook.metadata, ipynb.metadata);
|
|
@@ -87,18 +70,17 @@ export function NotebookProvider({ siteConfig, page, children, }) {
|
|
|
87
70
|
// so at some point this gets the whole site config and can
|
|
88
71
|
// be use to lookup notebooks and recover ThebeNotebooks that
|
|
89
72
|
// can be used to execute notebook pages or blocks in articles
|
|
90
|
-
const { core } =
|
|
73
|
+
const { core } = useThebeLoader();
|
|
91
74
|
const { config } = useThebeConfig();
|
|
75
|
+
const rendermime = useRenderMimeRegistry();
|
|
92
76
|
const { ready, attached, executing, executed, errors, executeAll, executeSome, clear, session, notebook, setNotebook, } = useNotebookBase();
|
|
93
|
-
const registry = useRef({});
|
|
94
77
|
const idkMap = useRef({});
|
|
95
78
|
useEffect(() => {
|
|
96
79
|
if (!core || !config)
|
|
97
80
|
return;
|
|
98
|
-
registry.current = {};
|
|
99
81
|
idkMap.current = {};
|
|
100
82
|
if (page.kind === SourceFileKind.Notebook) {
|
|
101
|
-
const nb = notebookFromMdast(core, config, page.mdast, idkMap.current);
|
|
83
|
+
const nb = notebookFromMdast(core, config, page.mdast, idkMap.current, rendermime);
|
|
102
84
|
setNotebook(nb);
|
|
103
85
|
}
|
|
104
86
|
else {
|
|
@@ -106,20 +88,7 @@ export function NotebookProvider({ siteConfig, page, children, }) {
|
|
|
106
88
|
setNotebook(undefined);
|
|
107
89
|
}
|
|
108
90
|
}, [core, config, page]);
|
|
109
|
-
|
|
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: {
|
|
91
|
+
return (_jsx(NotebookContext.Provider, { value: {
|
|
123
92
|
kind: page.kind,
|
|
124
93
|
ready,
|
|
125
94
|
attached,
|
|
@@ -129,33 +98,15 @@ export function NotebookProvider({ siteConfig, page, children, }) {
|
|
|
129
98
|
executeAll,
|
|
130
99
|
executeSome,
|
|
131
100
|
notebook,
|
|
132
|
-
registry: registry.current,
|
|
133
101
|
idkMap: idkMap.current,
|
|
134
|
-
register,
|
|
135
102
|
restart: () => { var _a; return (_a = session === null || session === void 0 ? void 0 : session.restart()) !== null && _a !== void 0 ? _a : Promise.resolve(); },
|
|
136
103
|
clear,
|
|
137
|
-
}
|
|
104
|
+
}, children: children }));
|
|
138
105
|
}
|
|
139
106
|
export function useHasNotebookProvider() {
|
|
140
107
|
const notebookState = useContext(NotebookContext);
|
|
141
108
|
return notebookState !== undefined;
|
|
142
109
|
}
|
|
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
110
|
export function useMDASTNotebook() {
|
|
160
111
|
const notebookState = useContext(NotebookContext);
|
|
161
112
|
return notebookState;
|
|
@@ -167,6 +118,11 @@ export function useNotebookExecution() {
|
|
|
167
118
|
const { ready, attached, executing, executed, errors, executeAll, notebook, clear } = notebookState;
|
|
168
119
|
return { ready, attached, executing, executed, errors, execute: executeAll, notebook, clear };
|
|
169
120
|
}
|
|
121
|
+
export function useReadyToExecute() {
|
|
122
|
+
var _a;
|
|
123
|
+
const notebookState = useContext(NotebookContext);
|
|
124
|
+
return (_a = notebookState === null || notebookState === void 0 ? void 0 : notebookState.ready) !== null && _a !== void 0 ? _a : false;
|
|
125
|
+
}
|
|
170
126
|
export function useNotebookCellExecution(id) {
|
|
171
127
|
// setup a cell only executing state
|
|
172
128
|
const [executing, setExecuting] = useState(false);
|
|
@@ -184,14 +140,16 @@ export function useNotebookCellExecution(id) {
|
|
|
184
140
|
});
|
|
185
141
|
}
|
|
186
142
|
const cell = notebook === null || notebook === void 0 ? void 0 : notebook.getCellById(cellId);
|
|
187
|
-
return
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
143
|
+
return notebook
|
|
144
|
+
? {
|
|
145
|
+
kind,
|
|
146
|
+
ready,
|
|
147
|
+
cell,
|
|
148
|
+
executing,
|
|
149
|
+
notebookIsExecuting,
|
|
150
|
+
execute,
|
|
151
|
+
clear: () => cell === null || cell === void 0 ? void 0 : cell.clear(),
|
|
152
|
+
notebook,
|
|
153
|
+
}
|
|
154
|
+
: undefined;
|
|
197
155
|
}
|
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",
|
|
58
|
+
return (_jsx("div", { className: "whitespace-pre-wrap font-mono text-sm", children: _jsx(Ansi, { children: text.content }) }));
|
|
59
59
|
return null;
|
|
60
60
|
}
|
|
61
61
|
default:
|
package/dist/esm/stream.js
CHANGED
|
@@ -3,5 +3,5 @@ import Ansi from 'ansi-to-react';
|
|
|
3
3
|
import { ensureString } from 'nbtx';
|
|
4
4
|
import { MaybeLongContent } from './components';
|
|
5
5
|
export default function Stream({ output }) {
|
|
6
|
-
return (_jsx(MaybeLongContent, { content: ensureString(output.text), path: output.path, render: (content) => (_jsx("pre",
|
|
6
|
+
return (_jsx(MaybeLongContent, { content: ensureString(output.text), path: output.path, render: (content) => (_jsx("pre", { className: "text-sm font-thin font-system", children: _jsx(Ansi, { children: content !== null && content !== void 0 ? content : '' }) })) }));
|
|
7
7
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Thebe } from 'myst-frontmatter';
|
|
2
|
+
import type { CoreOptions } from 'thebe-core';
|
|
3
|
+
export type ExtendedCoreOptions = CoreOptions & {
|
|
4
|
+
useBinder?: boolean;
|
|
5
|
+
useJupyterLite?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function thebeFrontmatterToOptions(fm: boolean | Thebe | undefined, githubBadgeUrl: string | undefined, binderBadgeUrl: string | undefined): ExtendedCoreOptions | undefined;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EAIN,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,YAAY,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAqDF,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,EAC/B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,mBAAmB,GAAG,SAAS,CA+IjC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
function extractGithubRepoInfo(url) {
|
|
2
|
+
const pattern = /https?:\/\/github\.com\/([^/]+)\/([^/]+)/;
|
|
3
|
+
const match = url.match(pattern);
|
|
4
|
+
if (match) {
|
|
5
|
+
return {
|
|
6
|
+
owner: match[1],
|
|
7
|
+
repo: match[2],
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
function extractBinderRepoInfo(url) {
|
|
13
|
+
const pattern = /(https?:\/\/[^/]+(?:\/[^/]+)*?)\/(v\d+)\/([^/]+)\/([^/]+)\/([^/]+)\/([^/]+)/;
|
|
14
|
+
const match = url.match(pattern);
|
|
15
|
+
if (match) {
|
|
16
|
+
const repoProviderAbbreviation = match[3];
|
|
17
|
+
let repoProvider;
|
|
18
|
+
switch (repoProviderAbbreviation) {
|
|
19
|
+
case 'gh':
|
|
20
|
+
repoProvider = 'github';
|
|
21
|
+
break;
|
|
22
|
+
case 'gl':
|
|
23
|
+
repoProvider = 'gitlab';
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
repoProvider = repoProviderAbbreviation;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
binderUrl: match[1],
|
|
30
|
+
repoProvider: repoProvider,
|
|
31
|
+
owner: match[4],
|
|
32
|
+
repo: match[5],
|
|
33
|
+
ref: match[6],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function isObject(maybeObject) {
|
|
39
|
+
return typeof maybeObject === 'object' && maybeObject !== null;
|
|
40
|
+
}
|
|
41
|
+
export function thebeFrontmatterToOptions(fm, githubBadgeUrl, binderBadgeUrl) {
|
|
42
|
+
var _a;
|
|
43
|
+
if (fm === undefined || fm === false)
|
|
44
|
+
return undefined;
|
|
45
|
+
const { binder, server, lite, local, kernelName, disableSessionSaving, mathjaxConfig, mathjaxUrl, } = (_a = fm) !== null && _a !== void 0 ? _a : {};
|
|
46
|
+
const thebeOptions = { mathjaxConfig, mathjaxUrl };
|
|
47
|
+
if (disableSessionSaving) {
|
|
48
|
+
thebeOptions.savedSessionOptions = { enabled: false };
|
|
49
|
+
}
|
|
50
|
+
// handle thebe.local.*
|
|
51
|
+
// as local OVERIDES other binder and server settings, handle these first
|
|
52
|
+
// TODO need to expose NODE_ENV somehow via a loader
|
|
53
|
+
let NODE_ENV = 'development';
|
|
54
|
+
if (typeof window !== 'undefined') {
|
|
55
|
+
NODE_ENV = window.NODE_ENV;
|
|
56
|
+
}
|
|
57
|
+
if (NODE_ENV !== 'production' && local) {
|
|
58
|
+
if (isObject(local)) {
|
|
59
|
+
const { url, token, kernelName: localKernelName } = local;
|
|
60
|
+
if (url || token) {
|
|
61
|
+
thebeOptions.serverSettings = {};
|
|
62
|
+
if (url)
|
|
63
|
+
thebeOptions.serverSettings.baseUrl = url;
|
|
64
|
+
if (token)
|
|
65
|
+
thebeOptions.serverSettings.token = token;
|
|
66
|
+
}
|
|
67
|
+
if (localKernelName) {
|
|
68
|
+
thebeOptions.kernelOptions = { kernelName: localKernelName };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return thebeOptions;
|
|
72
|
+
// else just fall through & return - TODO return early?
|
|
73
|
+
}
|
|
74
|
+
// handle additional optons
|
|
75
|
+
if (kernelName) {
|
|
76
|
+
thebeOptions.kernelOptions = {
|
|
77
|
+
kernelName: kernelName,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// handle shortcut options for binder
|
|
81
|
+
/**
|
|
82
|
+
* github: owner/repo | url
|
|
83
|
+
* binder: url
|
|
84
|
+
* thebe: true
|
|
85
|
+
*
|
|
86
|
+
* OR
|
|
87
|
+
*
|
|
88
|
+
* github: owner/repo | url
|
|
89
|
+
* binder: url
|
|
90
|
+
* thebe:
|
|
91
|
+
* binder: true
|
|
92
|
+
*/
|
|
93
|
+
if (binder === true || (fm === true && (githubBadgeUrl || binderBadgeUrl))) {
|
|
94
|
+
thebeOptions.useBinder = true;
|
|
95
|
+
if (githubBadgeUrl || binderBadgeUrl) {
|
|
96
|
+
const isValidBinderUrl = binderBadgeUrl ? extractBinderRepoInfo(binderBadgeUrl) : false;
|
|
97
|
+
if (isValidBinderUrl) {
|
|
98
|
+
const { binderUrl, owner, repo, ref } = isValidBinderUrl;
|
|
99
|
+
thebeOptions.binderOptions = {
|
|
100
|
+
binderUrl,
|
|
101
|
+
repo: `${owner}/${repo}`,
|
|
102
|
+
ref,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
else if (githubBadgeUrl) {
|
|
106
|
+
// TODO test for owner/repo vs url
|
|
107
|
+
const isUrl = extractGithubRepoInfo(githubBadgeUrl);
|
|
108
|
+
if (isUrl != null) {
|
|
109
|
+
const { owner, repo } = isUrl;
|
|
110
|
+
thebeOptions.binderOptions = {
|
|
111
|
+
repo: `${owner}/${repo}`,
|
|
112
|
+
ref: 'HEAD',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
else if (githubBadgeUrl.split('/').length === 2) {
|
|
116
|
+
// assume owner/repo
|
|
117
|
+
thebeOptions.binderOptions = {
|
|
118
|
+
repo: githubBadgeUrl,
|
|
119
|
+
ref: 'HEAD',
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
console.debug('myst-theme:thebeFrontmatterToOptions looks like an invalid github frontmatter value', githubBadgeUrl);
|
|
124
|
+
console.debug('myst-theme:thebeFrontmatterToOptions cannot connect to binder');
|
|
125
|
+
thebeOptions.useBinder = false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (isObject(binder)) {
|
|
131
|
+
// handle fully specified binder options
|
|
132
|
+
thebeOptions.useBinder = true;
|
|
133
|
+
const { url, ref, provider, repo } = binder;
|
|
134
|
+
thebeOptions.binderOptions = {
|
|
135
|
+
ref,
|
|
136
|
+
repo,
|
|
137
|
+
};
|
|
138
|
+
if (url)
|
|
139
|
+
thebeOptions.binderOptions.binderUrl = url;
|
|
140
|
+
if (provider)
|
|
141
|
+
thebeOptions.binderOptions.repoProvider = provider; // ffs
|
|
142
|
+
}
|
|
143
|
+
// handle jupyterlite
|
|
144
|
+
/**
|
|
145
|
+
* thebe:
|
|
146
|
+
* lite: true
|
|
147
|
+
*/
|
|
148
|
+
if (lite === true) {
|
|
149
|
+
thebeOptions.useJupyterLite = true;
|
|
150
|
+
}
|
|
151
|
+
// handle shortcut options for direct server, which really is the fallback for any shortcut option
|
|
152
|
+
/**
|
|
153
|
+
* github: undefined
|
|
154
|
+
* binder: undefined
|
|
155
|
+
* thebe: true
|
|
156
|
+
*
|
|
157
|
+
* OR
|
|
158
|
+
*
|
|
159
|
+
* github: undefined
|
|
160
|
+
* binder: undefined
|
|
161
|
+
* thebe:
|
|
162
|
+
* server: true
|
|
163
|
+
*/
|
|
164
|
+
if (isObject(server)) {
|
|
165
|
+
// handle fully specified server object
|
|
166
|
+
const { url, token } = server;
|
|
167
|
+
thebeOptions.serverSettings = {};
|
|
168
|
+
if (url)
|
|
169
|
+
thebeOptions.serverSettings.baseUrl = url;
|
|
170
|
+
if (token)
|
|
171
|
+
thebeOptions.serverSettings.token = token;
|
|
172
|
+
}
|
|
173
|
+
// else if (fm === true || server === true || !server) => do nothing - just return / fall though for defaults
|
|
174
|
+
return thebeOptions;
|
|
175
|
+
}
|
package/dist/types/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"}
|
|
@@ -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"}
|
|
@@ -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,CAAC;AAC7C,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,EACV,MAAM,
|
|
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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Thebe } from 'myst-frontmatter';
|
|
2
|
+
import type { CoreOptions } from 'thebe-core';
|
|
3
|
+
export type ExtendedCoreOptions = CoreOptions & {
|
|
4
|
+
useBinder?: boolean;
|
|
5
|
+
useJupyterLite?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function thebeFrontmatterToOptions(fm: boolean | Thebe | undefined, githubBadgeUrl: string | undefined, binderBadgeUrl: string | undefined): ExtendedCoreOptions | undefined;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EAIN,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,YAAY,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAqDF,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,EAC/B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,mBAAmB,GAAG,SAAS,CA+IjC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myst-theme/jupyter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -16,25 +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"
|
|
19
|
+
"build": "npm-run-all -l clean -p build:cjs build:esm build:types",
|
|
20
|
+
"test": "vitest run"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@headlessui/react": "^1.7.
|
|
23
|
-
"@heroicons/react": "^2.0.
|
|
24
|
-
"@myst-theme/providers": "^0.
|
|
23
|
+
"@headlessui/react": "^1.7.15",
|
|
24
|
+
"@heroicons/react": "^2.0.18",
|
|
25
|
+
"@myst-theme/providers": "^0.3.1",
|
|
25
26
|
"ansi-to-react": "^6.1.6",
|
|
26
27
|
"buffer": "^6.0.3",
|
|
27
28
|
"classnames": "^2.3.2",
|
|
28
|
-
"myst-common": "^
|
|
29
|
-
"myst-config": "^0.0
|
|
30
|
-
"myst-frontmatter": "^0.0
|
|
29
|
+
"myst-common": "^1.0.1",
|
|
30
|
+
"myst-config": "^1.0.0",
|
|
31
|
+
"myst-frontmatter": "^1.0.0",
|
|
31
32
|
"myst-spec": "^0.0.4",
|
|
32
|
-
"nanoid": "^4.0.
|
|
33
|
+
"nanoid": "^4.0.2",
|
|
33
34
|
"nbtx": "^0.2.3",
|
|
34
35
|
"react-syntax-highlighter": "^15.5.0",
|
|
35
|
-
"swr": "^1.
|
|
36
|
-
"thebe-core": "^0.
|
|
37
|
-
"thebe-
|
|
36
|
+
"swr": "^2.1.5",
|
|
37
|
+
"thebe-core": "^0.2.3",
|
|
38
|
+
"thebe-lite": "^0.2.3",
|
|
39
|
+
"thebe-react": "^0.2.3",
|
|
38
40
|
"unist-util-select": "^4.0.3"
|
|
39
41
|
},
|
|
40
42
|
"peerDependencies": {
|
|
@@ -43,11 +45,5 @@
|
|
|
43
45
|
"react": "^16.8 || ^17.0 || ^18.0",
|
|
44
46
|
"react-dom": "^16.8 || ^17.0 || ^18.0"
|
|
45
47
|
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"eslint": "^8.21.0",
|
|
48
|
-
"eslint-config-curvenote": "latest",
|
|
49
|
-
"npm-run-all": "^4.1.5",
|
|
50
|
-
"tsconfig": "latest",
|
|
51
|
-
"typescript": "latest"
|
|
52
|
-
}
|
|
48
|
+
"devDependencies": {}
|
|
53
49
|
}
|