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.
Files changed (242) hide show
  1. package/dist/cjs/admonitions.d.ts +32 -0
  2. package/dist/cjs/admonitions.d.ts.map +1 -0
  3. package/dist/cjs/admonitions.js +126 -0
  4. package/dist/cjs/basic.d.ts +62 -0
  5. package/dist/cjs/basic.d.ts.map +1 -0
  6. package/dist/cjs/basic.js +125 -0
  7. package/dist/cjs/card.d.ts +27 -0
  8. package/dist/cjs/card.d.ts.map +1 -0
  9. package/dist/cjs/card.js +64 -0
  10. package/dist/cjs/cite.d.ts +6 -0
  11. package/dist/cjs/cite.d.ts.map +1 -0
  12. package/dist/cjs/cite.js +36 -0
  13. package/dist/cjs/code.d.ts +20 -0
  14. package/dist/cjs/code.d.ts.map +1 -0
  15. package/dist/cjs/code.js +63 -0
  16. package/dist/cjs/components/ClickPopover.d.ts +11 -0
  17. package/dist/cjs/components/ClickPopover.d.ts.map +1 -0
  18. package/dist/cjs/components/ClickPopover.js +18 -0
  19. package/dist/cjs/components/CopyIcon.d.ts +5 -0
  20. package/dist/cjs/components/CopyIcon.d.ts.map +1 -0
  21. package/dist/cjs/components/CopyIcon.js +28 -0
  22. package/dist/cjs/components/HoverPopover.d.ts +9 -0
  23. package/dist/cjs/components/HoverPopover.d.ts.map +1 -0
  24. package/dist/cjs/components/HoverPopover.js +32 -0
  25. package/dist/cjs/components/LinkCard.d.ts +11 -0
  26. package/dist/cjs/components/LinkCard.d.ts.map +1 -0
  27. package/dist/cjs/components/LinkCard.js +15 -0
  28. package/dist/cjs/convertToReact.d.ts +6 -0
  29. package/dist/cjs/convertToReact.d.ts.map +1 -0
  30. package/dist/cjs/convertToReact.js +30 -0
  31. package/dist/cjs/crossReference.d.ts +13 -0
  32. package/dist/cjs/crossReference.d.ts.map +1 -0
  33. package/dist/cjs/crossReference.js +91 -0
  34. package/dist/cjs/dropdown.d.ts +16 -0
  35. package/dist/cjs/dropdown.d.ts.map +1 -0
  36. package/dist/cjs/dropdown.js +27 -0
  37. package/dist/cjs/extensions/chemicalFormula.d.ts +7 -0
  38. package/dist/cjs/extensions/chemicalFormula.d.ts.map +1 -0
  39. package/dist/cjs/extensions/chemicalFormula.js +39 -0
  40. package/dist/cjs/extensions/index.d.ts +4 -0
  41. package/dist/cjs/extensions/index.d.ts.map +1 -0
  42. package/dist/cjs/extensions/index.js +9 -0
  43. package/dist/cjs/extensions/siunits.d.ts +7 -0
  44. package/dist/cjs/extensions/siunits.d.ts.map +1 -0
  45. package/dist/cjs/extensions/siunits.js +12 -0
  46. package/dist/cjs/footnotes.d.ts +11 -0
  47. package/dist/cjs/footnotes.d.ts.map +1 -0
  48. package/dist/cjs/footnotes.js +24 -0
  49. package/dist/cjs/grid.d.ts +11 -0
  50. package/dist/cjs/grid.d.ts.map +1 -0
  51. package/dist/cjs/grid.js +117 -0
  52. package/dist/cjs/heading.d.ts +14 -0
  53. package/dist/cjs/heading.d.ts.map +1 -0
  54. package/dist/cjs/heading.js +40 -0
  55. package/dist/cjs/iframe.d.ts +7 -0
  56. package/dist/cjs/iframe.d.ts.map +1 -0
  57. package/dist/cjs/iframe.js +24 -0
  58. package/dist/cjs/image.d.ts +11 -0
  59. package/dist/cjs/image.d.ts.map +1 -0
  60. package/dist/cjs/image.js +52 -0
  61. package/dist/cjs/index.d.ts +10 -0
  62. package/dist/cjs/index.d.ts.map +1 -0
  63. package/dist/cjs/index.js +46 -0
  64. package/dist/cjs/inlineError.d.ts +8 -0
  65. package/dist/cjs/inlineError.d.ts.map +1 -0
  66. package/dist/cjs/inlineError.js +9 -0
  67. package/dist/cjs/links/github.d.ts +12 -0
  68. package/dist/cjs/links/github.d.ts.map +1 -0
  69. package/dist/cjs/links/github.js +63 -0
  70. package/dist/cjs/links/index.d.ts +14 -0
  71. package/dist/cjs/links/index.d.ts.map +1 -0
  72. package/dist/cjs/links/index.js +68 -0
  73. package/dist/cjs/links/rrid.d.ts +5 -0
  74. package/dist/cjs/links/rrid.d.ts.map +1 -0
  75. package/dist/cjs/links/rrid.js +35 -0
  76. package/dist/cjs/links/wiki.d.ts +8 -0
  77. package/dist/cjs/links/wiki.d.ts.map +1 -0
  78. package/dist/cjs/links/wiki.js +39 -0
  79. package/dist/cjs/math.d.ts +13 -0
  80. package/dist/cjs/math.d.ts.map +1 -0
  81. package/dist/cjs/math.js +29 -0
  82. package/dist/cjs/output/components.d.ts +10 -0
  83. package/dist/cjs/output/components.d.ts.map +1 -0
  84. package/dist/cjs/output/components.js +41 -0
  85. package/dist/cjs/output/error.d.ts +6 -0
  86. package/dist/cjs/output/error.d.ts.map +1 -0
  87. package/dist/cjs/output/error.js +15 -0
  88. package/dist/cjs/output/hooks.d.ts +67 -0
  89. package/dist/cjs/output/hooks.d.ts.map +1 -0
  90. package/dist/cjs/output/hooks.js +85 -0
  91. package/dist/cjs/output/index.d.ts +6 -0
  92. package/dist/cjs/output/index.d.ts.map +1 -0
  93. package/dist/cjs/output/index.js +7 -0
  94. package/dist/cjs/output/jupyter.d.ts +7 -0
  95. package/dist/cjs/output/jupyter.d.ts.map +1 -0
  96. package/dist/cjs/output/jupyter.js +75 -0
  97. package/dist/cjs/output/output.d.ts +7 -0
  98. package/dist/cjs/output/output.d.ts.map +1 -0
  99. package/dist/cjs/output/output.js +66 -0
  100. package/dist/cjs/output/outputBlock.d.ts +10 -0
  101. package/dist/cjs/output/outputBlock.d.ts.map +1 -0
  102. package/dist/cjs/output/outputBlock.js +13 -0
  103. package/dist/cjs/output/safe.d.ts +7 -0
  104. package/dist/cjs/output/safe.d.ts.map +1 -0
  105. package/dist/cjs/output/safe.js +77 -0
  106. package/dist/cjs/output/selectors.d.ts +10 -0
  107. package/dist/cjs/output/selectors.d.ts.map +1 -0
  108. package/dist/cjs/output/selectors.js +10 -0
  109. package/dist/cjs/output/stream.d.ts +6 -0
  110. package/dist/cjs/output/stream.d.ts.map +1 -0
  111. package/dist/cjs/output/stream.js +13 -0
  112. package/dist/cjs/reactive.d.ts +88 -0
  113. package/dist/cjs/reactive.d.ts.map +1 -0
  114. package/dist/cjs/reactive.js +64 -0
  115. package/dist/cjs/tabs.d.ts +12 -0
  116. package/dist/cjs/tabs.d.ts.map +1 -0
  117. package/dist/cjs/tabs.js +38 -0
  118. package/dist/cjs/types.d.ts +7 -0
  119. package/dist/cjs/types.d.ts.map +1 -0
  120. package/dist/cjs/types.js +2 -0
  121. package/dist/types/admonitions.d.ts +32 -0
  122. package/dist/types/admonitions.d.ts.map +1 -0
  123. package/dist/types/basic.d.ts +62 -0
  124. package/dist/types/basic.d.ts.map +1 -0
  125. package/dist/types/card.d.ts +27 -0
  126. package/dist/types/card.d.ts.map +1 -0
  127. package/dist/types/cite.d.ts +6 -0
  128. package/dist/types/cite.d.ts.map +1 -0
  129. package/dist/types/code.d.ts +20 -0
  130. package/dist/types/code.d.ts.map +1 -0
  131. package/dist/types/components/ClickPopover.d.ts +11 -0
  132. package/dist/types/components/ClickPopover.d.ts.map +1 -0
  133. package/dist/types/components/CopyIcon.d.ts +5 -0
  134. package/dist/types/components/CopyIcon.d.ts.map +1 -0
  135. package/dist/types/components/HoverPopover.d.ts +9 -0
  136. package/dist/types/components/HoverPopover.d.ts.map +1 -0
  137. package/dist/types/components/LinkCard.d.ts +11 -0
  138. package/dist/types/components/LinkCard.d.ts.map +1 -0
  139. package/dist/types/convertToReact.d.ts +6 -0
  140. package/dist/types/convertToReact.d.ts.map +1 -0
  141. package/dist/types/crossReference.d.ts +13 -0
  142. package/dist/types/crossReference.d.ts.map +1 -0
  143. package/dist/types/dropdown.d.ts +16 -0
  144. package/dist/types/dropdown.d.ts.map +1 -0
  145. package/dist/types/extensions/chemicalFormula.d.ts +7 -0
  146. package/dist/types/extensions/chemicalFormula.d.ts.map +1 -0
  147. package/dist/types/extensions/index.d.ts +4 -0
  148. package/dist/types/extensions/index.d.ts.map +1 -0
  149. package/dist/types/extensions/siunits.d.ts +7 -0
  150. package/dist/types/extensions/siunits.d.ts.map +1 -0
  151. package/dist/types/footnotes.d.ts +11 -0
  152. package/dist/types/footnotes.d.ts.map +1 -0
  153. package/dist/types/grid.d.ts +11 -0
  154. package/dist/types/grid.d.ts.map +1 -0
  155. package/dist/types/heading.d.ts +14 -0
  156. package/dist/types/heading.d.ts.map +1 -0
  157. package/dist/types/iframe.d.ts +7 -0
  158. package/dist/types/iframe.d.ts.map +1 -0
  159. package/dist/types/image.d.ts +11 -0
  160. package/dist/types/image.d.ts.map +1 -0
  161. package/dist/types/index.d.ts +10 -0
  162. package/dist/types/index.d.ts.map +1 -0
  163. package/dist/types/inlineError.d.ts +8 -0
  164. package/dist/types/inlineError.d.ts.map +1 -0
  165. package/dist/types/links/github.d.ts +12 -0
  166. package/dist/types/links/github.d.ts.map +1 -0
  167. package/dist/types/links/index.d.ts +14 -0
  168. package/dist/types/links/index.d.ts.map +1 -0
  169. package/dist/types/links/rrid.d.ts +5 -0
  170. package/dist/types/links/rrid.d.ts.map +1 -0
  171. package/dist/types/links/wiki.d.ts +8 -0
  172. package/dist/types/links/wiki.d.ts.map +1 -0
  173. package/dist/types/math.d.ts +13 -0
  174. package/dist/types/math.d.ts.map +1 -0
  175. package/dist/types/output/components.d.ts +10 -0
  176. package/dist/types/output/components.d.ts.map +1 -0
  177. package/dist/types/output/error.d.ts +6 -0
  178. package/dist/types/output/error.d.ts.map +1 -0
  179. package/dist/types/output/hooks.d.ts +67 -0
  180. package/dist/types/output/hooks.d.ts.map +1 -0
  181. package/dist/types/output/index.d.ts +6 -0
  182. package/dist/types/output/index.d.ts.map +1 -0
  183. package/dist/types/output/jupyter.d.ts +7 -0
  184. package/dist/types/output/jupyter.d.ts.map +1 -0
  185. package/dist/types/output/output.d.ts +7 -0
  186. package/dist/types/output/output.d.ts.map +1 -0
  187. package/dist/types/output/outputBlock.d.ts +10 -0
  188. package/dist/types/output/outputBlock.d.ts.map +1 -0
  189. package/dist/types/output/safe.d.ts +7 -0
  190. package/dist/types/output/safe.d.ts.map +1 -0
  191. package/dist/types/output/selectors.d.ts +10 -0
  192. package/dist/types/output/selectors.d.ts.map +1 -0
  193. package/dist/types/output/stream.d.ts +6 -0
  194. package/dist/types/output/stream.d.ts.map +1 -0
  195. package/dist/types/reactive.d.ts +88 -0
  196. package/dist/types/reactive.d.ts.map +1 -0
  197. package/dist/types/tabs.d.ts +12 -0
  198. package/dist/types/tabs.d.ts.map +1 -0
  199. package/dist/types/types.d.ts +7 -0
  200. package/dist/types/types.d.ts.map +1 -0
  201. package/package.json +36 -23
  202. package/src/admonitions.tsx +0 -183
  203. package/src/basic.tsx +0 -224
  204. package/src/card.tsx +0 -153
  205. package/src/cite.tsx +0 -94
  206. package/src/code.tsx +0 -119
  207. package/src/components/ClickPopover.tsx +0 -56
  208. package/src/components/CopyIcon.tsx +0 -40
  209. package/src/components/HoverPopover.tsx +0 -60
  210. package/src/components/LinkCard.tsx +0 -42
  211. package/src/convertToReact.ts +0 -33
  212. package/src/crossReference.tsx +0 -139
  213. package/src/dropdown.tsx +0 -69
  214. package/src/extensions/chemicalFormula.tsx +0 -42
  215. package/src/extensions/index.tsx +0 -10
  216. package/src/extensions/siunits.tsx +0 -15
  217. package/src/footnotes.tsx +0 -30
  218. package/src/grid.tsx +0 -127
  219. package/src/heading.tsx +0 -68
  220. package/src/iframe.tsx +0 -42
  221. package/src/image.tsx +0 -97
  222. package/src/index.tsx +0 -65
  223. package/src/inlineError.tsx +0 -15
  224. package/src/links/index.tsx +0 -132
  225. package/src/links/rrid.tsx +0 -81
  226. package/src/links/wiki.tsx +0 -119
  227. package/src/math.tsx +0 -81
  228. package/src/mermaid.tsx +0 -49
  229. package/src/myst.tsx +0 -221
  230. package/src/output/components.tsx +0 -34
  231. package/src/output/error.tsx +0 -20
  232. package/src/output/hooks.ts +0 -127
  233. package/src/output/index.tsx +0 -7
  234. package/src/output/jupyter.tsx +0 -86
  235. package/src/output/output.tsx +0 -79
  236. package/src/output/outputBlock.tsx +0 -21
  237. package/src/output/safe.tsx +0 -84
  238. package/src/output/selectors.ts +0 -15
  239. package/src/output/stream.tsx +0 -18
  240. package/src/reactive.tsx +0 -64
  241. package/src/tabs.tsx +0 -63
  242. package/src/types.ts +0 -6
@@ -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
- };
@@ -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
- }
@@ -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
- }
@@ -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);
@@ -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;
package/src/types.ts DELETED
@@ -1,6 +0,0 @@
1
- import type React from 'react';
2
-
3
- export type NodeRenderer<T = any> = (
4
- node: T & { type: string; key: string; html_id?: string },
5
- children?: React.ReactNode,
6
- ) => React.ReactNode;