myst-to-react 0.1.17 → 0.1.19
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/admonitions.d.ts +32 -0
- package/dist/cjs/admonitions.d.ts.map +1 -0
- package/dist/cjs/admonitions.js +126 -0
- package/dist/cjs/basic.d.ts +62 -0
- package/dist/cjs/basic.d.ts.map +1 -0
- package/dist/cjs/basic.js +125 -0
- package/dist/cjs/card.d.ts +27 -0
- package/dist/cjs/card.d.ts.map +1 -0
- package/dist/cjs/card.js +64 -0
- package/dist/cjs/cite.d.ts +6 -0
- package/dist/cjs/cite.d.ts.map +1 -0
- package/dist/cjs/cite.js +36 -0
- package/dist/cjs/code.d.ts +20 -0
- package/dist/cjs/code.d.ts.map +1 -0
- package/dist/cjs/code.js +63 -0
- package/dist/cjs/components/ClickPopover.d.ts +11 -0
- package/dist/cjs/components/ClickPopover.d.ts.map +1 -0
- package/dist/cjs/components/ClickPopover.js +18 -0
- package/dist/cjs/components/CopyIcon.d.ts +5 -0
- package/dist/cjs/components/CopyIcon.d.ts.map +1 -0
- package/dist/cjs/components/CopyIcon.js +28 -0
- package/dist/cjs/components/HoverPopover.d.ts +9 -0
- package/dist/cjs/components/HoverPopover.d.ts.map +1 -0
- package/dist/cjs/components/HoverPopover.js +32 -0
- package/dist/cjs/components/LinkCard.d.ts +11 -0
- package/dist/cjs/components/LinkCard.d.ts.map +1 -0
- package/dist/cjs/components/LinkCard.js +15 -0
- package/dist/cjs/convertToReact.d.ts +6 -0
- package/dist/cjs/convertToReact.d.ts.map +1 -0
- package/dist/cjs/convertToReact.js +30 -0
- package/dist/cjs/crossReference.d.ts +13 -0
- package/dist/cjs/crossReference.d.ts.map +1 -0
- package/dist/cjs/crossReference.js +91 -0
- package/dist/cjs/dropdown.d.ts +16 -0
- package/dist/cjs/dropdown.d.ts.map +1 -0
- package/dist/cjs/dropdown.js +27 -0
- package/dist/cjs/extensions/chemicalFormula.d.ts +7 -0
- package/dist/cjs/extensions/chemicalFormula.d.ts.map +1 -0
- package/dist/cjs/extensions/chemicalFormula.js +39 -0
- package/dist/cjs/extensions/index.d.ts +4 -0
- package/dist/cjs/extensions/index.d.ts.map +1 -0
- package/dist/cjs/extensions/index.js +9 -0
- package/dist/cjs/extensions/siunits.d.ts +7 -0
- package/dist/cjs/extensions/siunits.d.ts.map +1 -0
- package/dist/cjs/extensions/siunits.js +12 -0
- package/dist/cjs/footnotes.d.ts +11 -0
- package/dist/cjs/footnotes.d.ts.map +1 -0
- package/dist/cjs/footnotes.js +24 -0
- package/dist/cjs/grid.d.ts +11 -0
- package/dist/cjs/grid.d.ts.map +1 -0
- package/dist/cjs/grid.js +117 -0
- package/dist/cjs/heading.d.ts +14 -0
- package/dist/cjs/heading.d.ts.map +1 -0
- package/dist/cjs/heading.js +40 -0
- package/dist/cjs/iframe.d.ts +7 -0
- package/dist/cjs/iframe.d.ts.map +1 -0
- package/dist/cjs/iframe.js +24 -0
- package/dist/cjs/image.d.ts +11 -0
- package/dist/cjs/image.d.ts.map +1 -0
- package/dist/cjs/image.js +52 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/inlineError.d.ts +8 -0
- package/dist/cjs/inlineError.d.ts.map +1 -0
- package/dist/cjs/inlineError.js +9 -0
- package/dist/cjs/links/github.d.ts +12 -0
- package/dist/cjs/links/github.d.ts.map +1 -0
- package/dist/cjs/links/github.js +63 -0
- package/dist/cjs/links/index.d.ts +14 -0
- package/dist/cjs/links/index.d.ts.map +1 -0
- package/dist/cjs/links/index.js +68 -0
- package/dist/cjs/links/rrid.d.ts +5 -0
- package/dist/cjs/links/rrid.d.ts.map +1 -0
- package/dist/cjs/links/rrid.js +35 -0
- package/dist/cjs/links/wiki.d.ts +8 -0
- package/dist/cjs/links/wiki.d.ts.map +1 -0
- package/dist/cjs/links/wiki.js +39 -0
- package/dist/cjs/math.d.ts +13 -0
- package/dist/cjs/math.d.ts.map +1 -0
- package/dist/cjs/math.js +29 -0
- package/dist/cjs/output/components.d.ts +10 -0
- package/dist/cjs/output/components.d.ts.map +1 -0
- package/dist/cjs/output/components.js +41 -0
- package/dist/cjs/output/error.d.ts +6 -0
- package/dist/cjs/output/error.d.ts.map +1 -0
- package/dist/cjs/output/error.js +15 -0
- package/dist/cjs/output/hooks.d.ts +67 -0
- package/dist/cjs/output/hooks.d.ts.map +1 -0
- package/dist/cjs/output/hooks.js +85 -0
- package/dist/cjs/output/index.d.ts +6 -0
- package/dist/cjs/output/index.d.ts.map +1 -0
- package/dist/cjs/output/index.js +7 -0
- package/dist/cjs/output/jupyter.d.ts +7 -0
- package/dist/cjs/output/jupyter.d.ts.map +1 -0
- package/dist/cjs/output/jupyter.js +75 -0
- package/dist/cjs/output/output.d.ts +7 -0
- package/dist/cjs/output/output.d.ts.map +1 -0
- package/dist/cjs/output/output.js +66 -0
- package/dist/cjs/output/outputBlock.d.ts +10 -0
- package/dist/cjs/output/outputBlock.d.ts.map +1 -0
- package/dist/cjs/output/outputBlock.js +13 -0
- package/dist/cjs/output/safe.d.ts +7 -0
- package/dist/cjs/output/safe.d.ts.map +1 -0
- package/dist/cjs/output/safe.js +77 -0
- package/dist/cjs/output/selectors.d.ts +10 -0
- package/dist/cjs/output/selectors.d.ts.map +1 -0
- package/dist/cjs/output/selectors.js +10 -0
- package/dist/cjs/output/stream.d.ts +6 -0
- package/dist/cjs/output/stream.d.ts.map +1 -0
- package/dist/cjs/output/stream.js +13 -0
- package/dist/cjs/reactive.d.ts +88 -0
- package/dist/cjs/reactive.d.ts.map +1 -0
- package/dist/cjs/reactive.js +64 -0
- package/dist/cjs/tabs.d.ts +12 -0
- package/dist/cjs/tabs.d.ts.map +1 -0
- package/dist/cjs/tabs.js +38 -0
- package/dist/cjs/types.d.ts +7 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +2 -0
- package/dist/types/admonitions.d.ts +32 -0
- package/dist/types/admonitions.d.ts.map +1 -0
- package/dist/types/basic.d.ts +62 -0
- package/dist/types/basic.d.ts.map +1 -0
- package/dist/types/card.d.ts +27 -0
- package/dist/types/card.d.ts.map +1 -0
- package/dist/types/cite.d.ts +6 -0
- package/dist/types/cite.d.ts.map +1 -0
- package/dist/types/code.d.ts +20 -0
- package/dist/types/code.d.ts.map +1 -0
- package/dist/types/components/ClickPopover.d.ts +11 -0
- package/dist/types/components/ClickPopover.d.ts.map +1 -0
- package/dist/types/components/CopyIcon.d.ts +5 -0
- package/dist/types/components/CopyIcon.d.ts.map +1 -0
- package/dist/types/components/HoverPopover.d.ts +9 -0
- package/dist/types/components/HoverPopover.d.ts.map +1 -0
- package/dist/types/components/LinkCard.d.ts +11 -0
- package/dist/types/components/LinkCard.d.ts.map +1 -0
- package/dist/types/convertToReact.d.ts +6 -0
- package/dist/types/convertToReact.d.ts.map +1 -0
- package/dist/types/crossReference.d.ts +13 -0
- package/dist/types/crossReference.d.ts.map +1 -0
- package/dist/types/dropdown.d.ts +16 -0
- package/dist/types/dropdown.d.ts.map +1 -0
- package/dist/types/extensions/chemicalFormula.d.ts +7 -0
- package/dist/types/extensions/chemicalFormula.d.ts.map +1 -0
- package/dist/types/extensions/index.d.ts +4 -0
- package/dist/types/extensions/index.d.ts.map +1 -0
- package/dist/types/extensions/siunits.d.ts +7 -0
- package/dist/types/extensions/siunits.d.ts.map +1 -0
- package/dist/types/footnotes.d.ts +11 -0
- package/dist/types/footnotes.d.ts.map +1 -0
- package/dist/types/grid.d.ts +11 -0
- package/dist/types/grid.d.ts.map +1 -0
- package/dist/types/heading.d.ts +14 -0
- package/dist/types/heading.d.ts.map +1 -0
- package/dist/types/iframe.d.ts +7 -0
- package/dist/types/iframe.d.ts.map +1 -0
- package/dist/types/image.d.ts +11 -0
- package/dist/types/image.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/inlineError.d.ts +8 -0
- package/dist/types/inlineError.d.ts.map +1 -0
- package/dist/types/links/github.d.ts +12 -0
- package/dist/types/links/github.d.ts.map +1 -0
- package/dist/types/links/index.d.ts +14 -0
- package/dist/types/links/index.d.ts.map +1 -0
- package/dist/types/links/rrid.d.ts +5 -0
- package/dist/types/links/rrid.d.ts.map +1 -0
- package/dist/types/links/wiki.d.ts +8 -0
- package/dist/types/links/wiki.d.ts.map +1 -0
- package/dist/types/math.d.ts +13 -0
- package/dist/types/math.d.ts.map +1 -0
- package/dist/types/output/components.d.ts +10 -0
- package/dist/types/output/components.d.ts.map +1 -0
- package/dist/types/output/error.d.ts +6 -0
- package/dist/types/output/error.d.ts.map +1 -0
- package/dist/types/output/hooks.d.ts +67 -0
- package/dist/types/output/hooks.d.ts.map +1 -0
- package/dist/types/output/index.d.ts +6 -0
- package/dist/types/output/index.d.ts.map +1 -0
- package/dist/types/output/jupyter.d.ts +7 -0
- package/dist/types/output/jupyter.d.ts.map +1 -0
- package/dist/types/output/output.d.ts +7 -0
- package/dist/types/output/output.d.ts.map +1 -0
- package/dist/types/output/outputBlock.d.ts +10 -0
- package/dist/types/output/outputBlock.d.ts.map +1 -0
- package/dist/types/output/safe.d.ts +7 -0
- package/dist/types/output/safe.d.ts.map +1 -0
- package/dist/types/output/selectors.d.ts +10 -0
- package/dist/types/output/selectors.d.ts.map +1 -0
- package/dist/types/output/stream.d.ts +6 -0
- package/dist/types/output/stream.d.ts.map +1 -0
- package/dist/types/reactive.d.ts +88 -0
- package/dist/types/reactive.d.ts.map +1 -0
- package/dist/types/tabs.d.ts +12 -0
- package/dist/types/tabs.d.ts.map +1 -0
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +36 -23
- package/src/admonitions.tsx +0 -183
- package/src/basic.tsx +0 -224
- package/src/card.tsx +0 -153
- package/src/cite.tsx +0 -94
- package/src/code.tsx +0 -119
- package/src/components/ClickPopover.tsx +0 -56
- package/src/components/CopyIcon.tsx +0 -40
- package/src/components/HoverPopover.tsx +0 -60
- package/src/components/LinkCard.tsx +0 -42
- package/src/convertToReact.ts +0 -33
- package/src/crossReference.tsx +0 -139
- package/src/dropdown.tsx +0 -69
- package/src/extensions/chemicalFormula.tsx +0 -42
- package/src/extensions/index.tsx +0 -10
- package/src/extensions/siunits.tsx +0 -15
- package/src/footnotes.tsx +0 -30
- package/src/grid.tsx +0 -127
- package/src/heading.tsx +0 -68
- package/src/iframe.tsx +0 -42
- package/src/image.tsx +0 -97
- package/src/index.tsx +0 -65
- package/src/inlineError.tsx +0 -15
- package/src/links/index.tsx +0 -132
- package/src/links/rrid.tsx +0 -81
- package/src/links/wiki.tsx +0 -119
- package/src/math.tsx +0 -81
- package/src/mermaid.tsx +0 -49
- package/src/myst.tsx +0 -221
- package/src/output/components.tsx +0 -34
- package/src/output/error.tsx +0 -20
- package/src/output/hooks.ts +0 -127
- package/src/output/index.tsx +0 -7
- package/src/output/jupyter.tsx +0 -86
- package/src/output/output.tsx +0 -79
- package/src/output/outputBlock.tsx +0 -21
- package/src/output/safe.tsx +0 -84
- package/src/output/selectors.ts +0 -15
- package/src/output/stream.tsx +0 -18
- package/src/reactive.tsx +0 -64
- package/src/tabs.tsx +0 -63
- package/src/types.ts +0 -6
package/src/output/jupyter.tsx
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import useWindowSize, { useFetchAnyTruncatedContent } from './hooks';
|
|
3
|
-
import { nanoid } from 'nanoid';
|
|
4
|
-
import { useSelector } from 'react-redux';
|
|
5
|
-
import { host, actions } from '@curvenote/connect';
|
|
6
|
-
import type { MinifiedOutput } from '@curvenote/nbtx';
|
|
7
|
-
import { convertToIOutputs, fetchAndEncodeOutputImages } from '@curvenote/nbtx';
|
|
8
|
-
import { ChevronDoubleDownIcon } from '@heroicons/react/outline';
|
|
9
|
-
import type { State } from './selectors';
|
|
10
|
-
import { selectIFrameHeight, selectIFrameReady } from './selectors';
|
|
11
|
-
|
|
12
|
-
const PERCENT_OF_WINDOW = 0.9;
|
|
13
|
-
|
|
14
|
-
export const NativeJupyterOutputs = ({
|
|
15
|
-
id,
|
|
16
|
-
outputs,
|
|
17
|
-
}: {
|
|
18
|
-
id: string;
|
|
19
|
-
outputs: MinifiedOutput[];
|
|
20
|
-
}) => {
|
|
21
|
-
const windowSize = useWindowSize();
|
|
22
|
-
|
|
23
|
-
const { data, error } = useFetchAnyTruncatedContent(outputs);
|
|
24
|
-
|
|
25
|
-
const [loading, setLoading] = useState(true);
|
|
26
|
-
const [frameHeight, setFrameHeight] = useState(0);
|
|
27
|
-
const [clamped, setClamped] = useState(false);
|
|
28
|
-
|
|
29
|
-
const uid = useMemo(nanoid, []);
|
|
30
|
-
|
|
31
|
-
const height = useSelector((state: State) => selectIFrameHeight(state, uid));
|
|
32
|
-
const rendererReady = useSelector((state: State) => selectIFrameReady(state, uid));
|
|
33
|
-
|
|
34
|
-
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (iframeRef.current == null || !rendererReady || !data) return;
|
|
38
|
-
fetchAndEncodeOutputImages(convertToIOutputs(data)).then((out) => {
|
|
39
|
-
host.commsDispatch(iframeRef.current, actions.connectHostSendContent(uid, out));
|
|
40
|
-
});
|
|
41
|
-
}, [id, iframeRef.current, rendererReady]);
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (height == null) return;
|
|
45
|
-
if (height > PERCENT_OF_WINDOW * windowSize.height) {
|
|
46
|
-
setFrameHeight(PERCENT_OF_WINDOW * windowSize.height);
|
|
47
|
-
setClamped(true);
|
|
48
|
-
} else {
|
|
49
|
-
setFrameHeight(height + 25);
|
|
50
|
-
setClamped(false);
|
|
51
|
-
}
|
|
52
|
-
setLoading(false);
|
|
53
|
-
}, [height]);
|
|
54
|
-
|
|
55
|
-
if (error) {
|
|
56
|
-
return <div className="text-red-500">Error rendering output: {error.message}</div>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<div>
|
|
61
|
-
{loading && <div className="p-2.5">Loading...</div>}
|
|
62
|
-
<iframe
|
|
63
|
-
ref={iframeRef}
|
|
64
|
-
id={uid}
|
|
65
|
-
name={uid}
|
|
66
|
-
title={uid}
|
|
67
|
-
src="https://next.curvenote.run"
|
|
68
|
-
width={'100%'}
|
|
69
|
-
height={frameHeight}
|
|
70
|
-
sandbox="allow-scripts"
|
|
71
|
-
></iframe>
|
|
72
|
-
{clamped && (
|
|
73
|
-
<div
|
|
74
|
-
className="cursor-pointer p-1 pb-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-center text-gray-500 hover:text-gray-600 dark:text-gray-200 dark:hover:text-gray-50"
|
|
75
|
-
title="Expand"
|
|
76
|
-
onClick={() => {
|
|
77
|
-
setFrameHeight(height ?? 0);
|
|
78
|
-
setClamped(false);
|
|
79
|
-
}}
|
|
80
|
-
>
|
|
81
|
-
<ChevronDoubleDownIcon className="w-5 h-5 inline"></ChevronDoubleDownIcon>
|
|
82
|
-
</div>
|
|
83
|
-
)}
|
|
84
|
-
</div>
|
|
85
|
-
);
|
|
86
|
-
};
|
package/src/output/output.tsx
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { GenericNode } from 'mystjs';
|
|
2
|
-
import { KnownCellOutputMimeTypes } from '@curvenote/blocks';
|
|
3
|
-
import type { MinifiedMimeOutput, MinifiedOutput } from '@curvenote/nbtx/dist/minify/types';
|
|
4
|
-
import classNames from 'classnames';
|
|
5
|
-
import { SafeOutputs } from './safe';
|
|
6
|
-
import { NativeJupyterOutputs as JupyterOutputs } from './jupyter';
|
|
7
|
-
import { OutputBlock } from './outputBlock';
|
|
8
|
-
|
|
9
|
-
const DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);
|
|
10
|
-
|
|
11
|
-
const DIRECT_MIME_TYPES = new Set([
|
|
12
|
-
KnownCellOutputMimeTypes.TextPlain,
|
|
13
|
-
KnownCellOutputMimeTypes.ImagePng,
|
|
14
|
-
KnownCellOutputMimeTypes.ImageGif,
|
|
15
|
-
KnownCellOutputMimeTypes.ImageJpeg,
|
|
16
|
-
KnownCellOutputMimeTypes.ImageBmp,
|
|
17
|
-
]) as Set<string>;
|
|
18
|
-
|
|
19
|
-
export function allOutputsAreSafe(
|
|
20
|
-
outputs: MinifiedOutput[],
|
|
21
|
-
directOutputTypes: Set<string>,
|
|
22
|
-
directMimeTypes: Set<string>,
|
|
23
|
-
) {
|
|
24
|
-
return outputs.reduce((flag, output) => {
|
|
25
|
-
if (directOutputTypes.has(output.output_type)) return true;
|
|
26
|
-
const data = (output as MinifiedMimeOutput).data;
|
|
27
|
-
const mimetypes = data ? Object.keys(data) : [];
|
|
28
|
-
const safe =
|
|
29
|
-
'data' in output &&
|
|
30
|
-
Boolean(output.data) &&
|
|
31
|
-
mimetypes.every((mimetype) => directMimeTypes.has(mimetype));
|
|
32
|
-
return flag && safe;
|
|
33
|
-
}, true);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function listMimetypes(outputs: MinifiedOutput[], directOutputTypes: Set<string>) {
|
|
37
|
-
return outputs.map((output) => {
|
|
38
|
-
if (directOutputTypes.has(output.output_type)) return [output.output_type];
|
|
39
|
-
const data = (output as MinifiedMimeOutput).data;
|
|
40
|
-
const mimetypes = data ? Object.keys(data) : [];
|
|
41
|
-
return [output.output_type, mimetypes];
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function anyErrors(outputs: MinifiedOutput[]) {
|
|
46
|
-
return outputs.reduce((flag, output) => flag || output.output_type === 'error', false);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function Output(node: GenericNode) {
|
|
50
|
-
const outputs: MinifiedOutput[] = node.data;
|
|
51
|
-
const allSafe = allOutputsAreSafe(outputs, DIRECT_OUTPUT_TYPES, DIRECT_MIME_TYPES);
|
|
52
|
-
const hasError = anyErrors(outputs);
|
|
53
|
-
|
|
54
|
-
let component;
|
|
55
|
-
if (allSafe) {
|
|
56
|
-
component = <SafeOutputs keyStub={node.key} outputs={outputs} />;
|
|
57
|
-
} else {
|
|
58
|
-
// Hide the iframe if rendering on the server
|
|
59
|
-
component =
|
|
60
|
-
typeof document === 'undefined' ? null : <JupyterOutputs id={node.key} outputs={outputs} />;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<figure
|
|
65
|
-
suppressHydrationWarning={!allSafe}
|
|
66
|
-
key={node.key}
|
|
67
|
-
id={node.identifier || undefined}
|
|
68
|
-
className={classNames('max-w-full overflow-auto m-0', {
|
|
69
|
-
'text-left': !node.align || node.align === 'left',
|
|
70
|
-
'text-center': node.align === 'center',
|
|
71
|
-
'text-right': node.align === 'right',
|
|
72
|
-
})}
|
|
73
|
-
>
|
|
74
|
-
<OutputBlock allSafe={allSafe} hasError={hasError}>
|
|
75
|
-
{component}
|
|
76
|
-
</OutputBlock>
|
|
77
|
-
</figure>
|
|
78
|
-
);
|
|
79
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
children?: React.ReactNode;
|
|
5
|
-
allSafe?: boolean;
|
|
6
|
-
hasError?: boolean;
|
|
7
|
-
className?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function OutputBlock(props: Props) {
|
|
11
|
-
const { children, allSafe, className } = props;
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<div
|
|
15
|
-
suppressHydrationWarning={!allSafe}
|
|
16
|
-
className={classNames('relative group not-prose overflow-auto mb-4 pl-0.5', className)}
|
|
17
|
-
>
|
|
18
|
-
{children}
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
}
|
package/src/output/safe.tsx
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { KnownCellOutputMimeTypes } from '@curvenote/blocks/dist/blocks/types/jupyter';
|
|
2
|
-
import type {
|
|
3
|
-
MinifiedMimeBundle,
|
|
4
|
-
MinifiedMimePayload,
|
|
5
|
-
MinifiedOutput,
|
|
6
|
-
} from '@curvenote/nbtx/dist/minify/types';
|
|
7
|
-
import Stream from './stream';
|
|
8
|
-
import Error from './error';
|
|
9
|
-
import Ansi from 'ansi-to-react';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* https://jupyterbook.org/content/code-outputs.html#render-priority
|
|
13
|
-
*
|
|
14
|
-
* nb_render_priority:
|
|
15
|
-
html:
|
|
16
|
-
- "application/vnd.jupyter.widget-view+json"
|
|
17
|
-
- "application/javascript"
|
|
18
|
-
- "text/html"
|
|
19
|
-
- "image/svg+xml"
|
|
20
|
-
- "image/png"
|
|
21
|
-
- "image/jpeg"
|
|
22
|
-
- "text/markdown"
|
|
23
|
-
- "text/latex"
|
|
24
|
-
- "text/plain"
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const RENDER_PRIORITY = [
|
|
28
|
-
KnownCellOutputMimeTypes.ImagePng,
|
|
29
|
-
KnownCellOutputMimeTypes.ImageJpeg,
|
|
30
|
-
KnownCellOutputMimeTypes.ImageGif,
|
|
31
|
-
KnownCellOutputMimeTypes.ImageBmp,
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
function findSafeMimeOutputs(output: MinifiedOutput): {
|
|
35
|
-
image?: MinifiedMimePayload;
|
|
36
|
-
text?: MinifiedMimePayload;
|
|
37
|
-
} {
|
|
38
|
-
const data: MinifiedMimeBundle = output.data as MinifiedMimeBundle;
|
|
39
|
-
const image = RENDER_PRIORITY.reduce((acc: MinifiedMimePayload | undefined, mimetype) => {
|
|
40
|
-
if (acc) return acc;
|
|
41
|
-
if (data && data[mimetype]) return data[mimetype];
|
|
42
|
-
return undefined;
|
|
43
|
-
}, undefined);
|
|
44
|
-
const text = data && data['text/plain'];
|
|
45
|
-
return { image, text };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function OutputImage({ image, text }: { image: MinifiedMimePayload; text?: MinifiedMimePayload }) {
|
|
49
|
-
return <img src={image?.path} alt={text?.content ?? 'Image produced in Jupyter'} />;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function SafeOutput({ output }: { output: MinifiedOutput }) {
|
|
53
|
-
switch (output.output_type) {
|
|
54
|
-
case 'stream':
|
|
55
|
-
return <Stream output={output} />;
|
|
56
|
-
case 'error':
|
|
57
|
-
return <Error output={output} />;
|
|
58
|
-
case 'display_data':
|
|
59
|
-
case 'execute_result':
|
|
60
|
-
case 'update_display_data': {
|
|
61
|
-
const { image, text } = findSafeMimeOutputs(output);
|
|
62
|
-
if (!image && !text) return null;
|
|
63
|
-
if (image) return <OutputImage image={image} text={text} />;
|
|
64
|
-
if (text)
|
|
65
|
-
return (
|
|
66
|
-
<div>
|
|
67
|
-
<Ansi>{text.content}</Ansi>
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
default:
|
|
73
|
-
console.warn(`Unknown output_type ${output['output_type']}`);
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function SafeOutputs({ keyStub, outputs }: { keyStub: string; outputs: MinifiedOutput[] }) {
|
|
79
|
-
// TODO better key - add keys during content creation?
|
|
80
|
-
const components = outputs.map((output, idx) => (
|
|
81
|
-
<SafeOutput key={`${keyStub}-${idx}`} output={output} />
|
|
82
|
-
));
|
|
83
|
-
return <>{components}</>;
|
|
84
|
-
}
|
package/src/output/selectors.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { HostState } from '@curvenote/connect';
|
|
2
|
-
import { host } from '@curvenote/connect';
|
|
3
|
-
|
|
4
|
-
export interface State {
|
|
5
|
-
app: HostState;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const selectIFrameHeight = (state: State, id: string) =>
|
|
9
|
-
host.selectors.selectIFrameSize(state.app, id);
|
|
10
|
-
|
|
11
|
-
export const selectIFrameReady = (state: State, id: string) =>
|
|
12
|
-
host.selectors.selectIFrameReady(state.app, id);
|
|
13
|
-
|
|
14
|
-
export const selectIFrameSendFailed = (state: State, id: string) =>
|
|
15
|
-
host.selectors.selectIFrameFailed(state.app, id);
|
package/src/output/stream.tsx
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import Ansi from 'ansi-to-react';
|
|
2
|
-
import { ensureString } from '@curvenote/blocks';
|
|
3
|
-
import type { MinifiedStreamOutput } from '@curvenote/nbtx';
|
|
4
|
-
import { MaybeLongContent } from './components';
|
|
5
|
-
|
|
6
|
-
export default function Stream({ output }: { output: MinifiedStreamOutput }) {
|
|
7
|
-
return (
|
|
8
|
-
<MaybeLongContent
|
|
9
|
-
content={ensureString(output.text)}
|
|
10
|
-
path={output.path}
|
|
11
|
-
render={(content?: string) => (
|
|
12
|
-
<pre className="text-sm font-thin font-system">
|
|
13
|
-
<Ansi>{content ?? ''}</Ansi>
|
|
14
|
-
</pre>
|
|
15
|
-
)}
|
|
16
|
-
/>
|
|
17
|
-
);
|
|
18
|
-
}
|
package/src/reactive.tsx
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { GenericNode } from 'mystjs';
|
|
2
|
-
import { createElement as e } from 'react';
|
|
3
|
-
|
|
4
|
-
export const RVar = (node: GenericNode) => {
|
|
5
|
-
return e('r-var', {
|
|
6
|
-
key: node.key,
|
|
7
|
-
name: node.name,
|
|
8
|
-
value: node.value,
|
|
9
|
-
':value': node.valueFunction,
|
|
10
|
-
format: node.format,
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const RDisplay = (node: GenericNode) => {
|
|
15
|
-
return e('r-display', {
|
|
16
|
-
key: node.key,
|
|
17
|
-
name: node.name,
|
|
18
|
-
value: node.value,
|
|
19
|
-
':value': node.valueFunction,
|
|
20
|
-
format: node.format,
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const RDynamic = (node: GenericNode) => {
|
|
25
|
-
return e('r-dynamic', {
|
|
26
|
-
key: node.key,
|
|
27
|
-
name: node.name,
|
|
28
|
-
value: node.value,
|
|
29
|
-
':value': node.valueFunction,
|
|
30
|
-
max: node.max,
|
|
31
|
-
':max': node.maxFunction,
|
|
32
|
-
min: node.min,
|
|
33
|
-
':min': node.minFunction,
|
|
34
|
-
step: node.step,
|
|
35
|
-
':step': node.stepFunction,
|
|
36
|
-
':change': node.changeFunction,
|
|
37
|
-
format: node.format,
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const RRange = (node: GenericNode) => {
|
|
42
|
-
return e('r-range', {
|
|
43
|
-
key: node.key,
|
|
44
|
-
name: node.name,
|
|
45
|
-
value: node.value,
|
|
46
|
-
':value': node.valueFunction,
|
|
47
|
-
max: node.max,
|
|
48
|
-
':max': node.maxFunction,
|
|
49
|
-
min: node.min,
|
|
50
|
-
':min': node.minFunction,
|
|
51
|
-
step: node.step,
|
|
52
|
-
':step': node.stepFunction,
|
|
53
|
-
':change': node.changeFunction,
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const REACTIVE_RENDERERS = {
|
|
58
|
-
'r:var': RVar,
|
|
59
|
-
'r:display': RDisplay,
|
|
60
|
-
'r:dynamic': RDynamic,
|
|
61
|
-
'r:range': RRange,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export default REACTIVE_RENDERERS;
|
package/src/tabs.tsx
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { useIsTabOpen, useTabSet } from '@curvenote/ui-providers';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import type { GenericNode } from 'mystjs';
|
|
4
|
-
import { useEffect } from 'react';
|
|
5
|
-
import { selectAll } from 'unist-util-select';
|
|
6
|
-
import type { NodeRenderer } from './types';
|
|
7
|
-
|
|
8
|
-
interface TabItem extends GenericNode {
|
|
9
|
-
key: string;
|
|
10
|
-
title: string;
|
|
11
|
-
sync?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const TabSetRenderer: NodeRenderer = (node, children) => {
|
|
15
|
-
const items = selectAll('tabItem', node) as TabItem[];
|
|
16
|
-
const keys = items.map((item) => item.sync || item.key);
|
|
17
|
-
const { onClick, active } = useTabSet(keys);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
onClick(items[0]?.sync || items[0]?.key);
|
|
20
|
-
}, []);
|
|
21
|
-
return (
|
|
22
|
-
<div key={node.key} className="">
|
|
23
|
-
<div className="flex flex-row border-b border-b-gray-100 overflow-x-auto">
|
|
24
|
-
{items.map((item) => {
|
|
25
|
-
const key = item.sync || item.key;
|
|
26
|
-
return (
|
|
27
|
-
<div
|
|
28
|
-
key={item.key}
|
|
29
|
-
className={classNames('flex-none px-3 py-1 font-semibold cursor-pointer', {
|
|
30
|
-
'text-blue-600 border-b-2 border-b-blue-600 dark:border-b-white dark:text-white':
|
|
31
|
-
active[key],
|
|
32
|
-
'text-gray-500 dark:text-gray-300 hover:text-gray-700 dark:hover:text-gray-100':
|
|
33
|
-
!active[key],
|
|
34
|
-
})}
|
|
35
|
-
onClick={() => onClick(key)}
|
|
36
|
-
>
|
|
37
|
-
{item.title}
|
|
38
|
-
</div>
|
|
39
|
-
);
|
|
40
|
-
})}
|
|
41
|
-
</div>
|
|
42
|
-
<div className="shadow flex">
|
|
43
|
-
<div className="w-full px-6">{children}</div>
|
|
44
|
-
</div>
|
|
45
|
-
</div>
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const TabItemRenderer: NodeRenderer<TabItem> = (node, children) => {
|
|
50
|
-
const open = useIsTabOpen(node.sync || node.key);
|
|
51
|
-
return (
|
|
52
|
-
<div key={node.key} className={classNames({ hidden: !open })}>
|
|
53
|
-
{children}
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const TAB_RENDERERS: Record<string, NodeRenderer> = {
|
|
59
|
-
tabSet: TabSetRenderer,
|
|
60
|
-
tabItem: TabItemRenderer,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export default TAB_RENDERERS;
|