myst-to-react 0.1.14
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/README.md +6 -0
- package/package.json +48 -0
- package/src/admonitions.tsx +183 -0
- package/src/basic.tsx +217 -0
- package/src/cite.tsx +94 -0
- package/src/code.tsx +119 -0
- package/src/components/ClickPopover.tsx +56 -0
- package/src/components/CopyIcon.tsx +40 -0
- package/src/components/HoverPopover.tsx +60 -0
- package/src/components/LinkCard.tsx +42 -0
- package/src/convertToReact.ts +33 -0
- package/src/crossReference.tsx +139 -0
- package/src/extensions/chemicalFormula.tsx +42 -0
- package/src/extensions/index.tsx +10 -0
- package/src/extensions/siunits.tsx +15 -0
- package/src/footnotes.tsx +30 -0
- package/src/heading.tsx +68 -0
- package/src/iframe.tsx +42 -0
- package/src/image.tsx +72 -0
- package/src/index.tsx +59 -0
- package/src/inlineError.tsx +15 -0
- package/src/links/index.tsx +132 -0
- package/src/links/rrid.tsx +81 -0
- package/src/links/wiki.tsx +119 -0
- package/src/math.tsx +81 -0
- package/src/mermaid.tsx +49 -0
- package/src/myst.tsx +185 -0
- package/src/output/components.tsx +34 -0
- package/src/output/error.tsx +20 -0
- package/src/output/hooks.ts +127 -0
- package/src/output/index.tsx +7 -0
- package/src/output/jupyter.tsx +86 -0
- package/src/output/output.tsx +79 -0
- package/src/output/outputBlock.tsx +21 -0
- package/src/output/safe.tsx +84 -0
- package/src/output/selectors.ts +15 -0
- package/src/output/stream.tsx +18 -0
- package/src/reactive.tsx +64 -0
- package/src/tabs.tsx +58 -0
- package/src/types.ts +6 -0
package/src/reactive.tsx
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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 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
|
+
className={classNames('flex-none px-3 py-1 font-semibold cursor-pointer', {
|
|
29
|
+
'text-blue-600 border-b-2 border-b-blue-600 dark:border-b-white dark:text-white':
|
|
30
|
+
active[key],
|
|
31
|
+
'text-gray-500 dark:text-gray-300 hover:text-gray-700 dark:hover:text-gray-100':
|
|
32
|
+
!active[key],
|
|
33
|
+
})}
|
|
34
|
+
onClick={() => onClick(key)}
|
|
35
|
+
>
|
|
36
|
+
{item.title}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
})}
|
|
40
|
+
</div>
|
|
41
|
+
<div className="shadow flex">
|
|
42
|
+
<div className="w-full px-6">{children}</div>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const TabItemRenderer: NodeRenderer<TabItem> = (node, children) => {
|
|
49
|
+
const open = useIsTabOpen(node.sync || node.key);
|
|
50
|
+
return <div className={classNames({ hidden: !open })}>{children}</div>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const TAB_RENDERERS: Record<string, NodeRenderer> = {
|
|
54
|
+
tabSet: TabSetRenderer,
|
|
55
|
+
tabItem: TabItemRenderer,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default TAB_RENDERERS;
|