myst-to-react 0.12.0 → 0.13.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/code.d.ts.map +1 -1
- package/dist/code.js +35 -24
- package/dist/crossReference.d.ts.map +1 -1
- package/dist/crossReference.js +13 -3
- package/dist/footnotes.js +1 -1
- package/package.json +4 -4
package/dist/code.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../src/code.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../src/code.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAS1D,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAaF,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,2CAiFrC;AAuDD,QAAA,MAAM,cAAc;;;CAGnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/dist/code.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useThemeSwitcher } from '@myst-theme/providers';
|
|
3
2
|
import { LightAsync as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
4
|
-
import light from 'react-syntax-highlighter/dist/esm/styles/hljs/xcode.js';
|
|
5
|
-
import dark from 'react-syntax-highlighter/dist/esm/styles/hljs/vs2015.js';
|
|
6
3
|
import { DocumentIcon } from '@heroicons/react/24/outline';
|
|
7
4
|
import classNames from 'classnames';
|
|
8
5
|
import { CopyIcon } from './components/index.js';
|
|
9
6
|
import { MyST } from './MyST.js';
|
|
7
|
+
import { useMemo } from 'react';
|
|
10
8
|
function normalizeLanguage(lang) {
|
|
11
9
|
switch (lang) {
|
|
12
10
|
case 'html':
|
|
@@ -16,32 +14,45 @@ function normalizeLanguage(lang) {
|
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
export function CodeBlock(props) {
|
|
19
|
-
const { isLight } = useThemeSwitcher();
|
|
20
17
|
const { value, lang, identifier, emphasizeLines, showLineNumbers, className, showCopy = true, startingLineNumber = 1, filename, shadow, background, border, } = props;
|
|
21
|
-
const
|
|
18
|
+
const highlighterProps = useMemo(() => {
|
|
19
|
+
const highlightLines = new Set(emphasizeLines);
|
|
20
|
+
return {
|
|
21
|
+
language: normalizeLanguage(lang),
|
|
22
|
+
startingLineNumber,
|
|
23
|
+
showLineNumbers,
|
|
24
|
+
useInlineStyles: true,
|
|
25
|
+
wrapLines: true,
|
|
26
|
+
lineNumberContainerStyle: {
|
|
27
|
+
// This stops page content shifts
|
|
28
|
+
display: 'inline-block',
|
|
29
|
+
float: 'left',
|
|
30
|
+
minWidth: '1.25em',
|
|
31
|
+
paddingRight: '1em',
|
|
32
|
+
textAlign: 'right',
|
|
33
|
+
userSelect: 'none',
|
|
34
|
+
borderLeft: '4px solid transparent',
|
|
35
|
+
},
|
|
36
|
+
lineProps: (line) => {
|
|
37
|
+
if (typeof line === 'boolean')
|
|
38
|
+
return {};
|
|
39
|
+
return highlightLines.has(line)
|
|
40
|
+
? {
|
|
41
|
+
'data-line-number': `${line}`,
|
|
42
|
+
'data-highlight': 'true',
|
|
43
|
+
}
|
|
44
|
+
: { 'data-line-number': `${line}` };
|
|
45
|
+
},
|
|
46
|
+
customStyle: {
|
|
47
|
+
backgroundColor: 'unset',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}, [emphasizeLines]);
|
|
22
51
|
return (_jsxs("div", { id: identifier, className: classNames('relative group not-prose overflow-auto', className, {
|
|
23
52
|
'shadow hover:shadow-md dark:shadow-2xl dark:shadow-neutral-900 my-5 text-sm': shadow,
|
|
24
53
|
'bg-stone-200/10': background,
|
|
25
54
|
'border border-l-4 border-l-blue-400 border-gray-200 dark:border-l-blue-400 dark:border-gray-800': border,
|
|
26
|
-
}), children: [filename && (_jsxs("div", { className: "flex flex-row pl-2 bg-white border-b dark:bg-slate-600 dark:border-slate-300", children: [_jsx(DocumentIcon, { width: "16px", height: "16px", className: "self-center flex-none inline-block text-gray-500 dark:text-gray-100" }), _jsx("div", { className: "self-center p-2 text-sm leading-3 prose text-slate-600 dark:text-white", children: filename })] })), _jsx(SyntaxHighlighter, {
|
|
27
|
-
// This stops page content shifts
|
|
28
|
-
display: 'inline-block',
|
|
29
|
-
float: 'left',
|
|
30
|
-
minWidth: '1.25em',
|
|
31
|
-
paddingRight: '1em',
|
|
32
|
-
textAlign: 'right',
|
|
33
|
-
userSelect: 'none',
|
|
34
|
-
borderLeft: '4px solid transparent',
|
|
35
|
-
}, lineProps: (line) => {
|
|
36
|
-
if (typeof line === 'boolean')
|
|
37
|
-
return {};
|
|
38
|
-
return highlightLines.has(line)
|
|
39
|
-
? {
|
|
40
|
-
'data-line-number': `${line}`,
|
|
41
|
-
'data-highlight': 'true',
|
|
42
|
-
}
|
|
43
|
-
: { 'data-line-number': `${line}` };
|
|
44
|
-
}, customStyle: { padding: '0.8rem' }, children: value }), showCopy && (_jsx(CopyIcon, { text: value, className: classNames('absolute right-1', { 'top-[32px]': filename, 'top-1': !filename }) }))] }));
|
|
55
|
+
}), children: [filename && (_jsxs("div", { className: "flex flex-row pl-2 bg-white border-b dark:bg-slate-600 dark:border-slate-300", children: [_jsx(DocumentIcon, { width: "16px", height: "16px", className: "self-center flex-none inline-block text-gray-500 dark:text-gray-100" }), _jsx("div", { className: "self-center p-2 text-sm leading-3 prose text-slate-600 dark:text-white", children: filename })] })), _jsx(SyntaxHighlighter, Object.assign({}, highlighterProps, { className: "block hljs", children: value })), showCopy && (_jsx(CopyIcon, { text: value, className: classNames('absolute right-1', { 'top-[32px]': filename, 'top-1': !filename }) }))] }));
|
|
45
56
|
}
|
|
46
57
|
const code = ({ node }) => {
|
|
47
58
|
return (_jsx(CodeBlock, { identifier: node.html_id, "data-mdast-node-type": node.type, "data-mdast-node-id": node.key, value: node.value || '', lang: node.lang, filename: node.filename, emphasizeLines: node.emphasizeLines, showLineNumbers: node.showLineNumbers, startingLineNumber: node.startingLineNumber, shadow: true, border: node.executable, background: !node.executable, className: classNames({ hidden: node.visibility === 'remove' }, node.class) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crossReference.d.ts","sourceRoot":"","sources":["../src/crossReference.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAOL,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"crossReference.d.ts","sourceRoot":"","sources":["../src/crossReference.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAOL,KAAK,YAAY,EAElB,MAAM,uBAAuB,CAAC;AA4E/B,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,GAAG,EACH,aAAa,EACb,OAAO,GACR,EAAE;IACD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,4CAIA;AAqBD,wBAAgB,mBAAmB,CAAC,EAClC,GAAG,EAAE,KAAK,EACV,OAAO,EAAE,SAAS,EAClB,MAAM,EAAE,QAAQ,EAChB,aAAa,EAAE,eAAe,EAC9B,QAAQ,EACR,UAAU,EACV,MAAW,GACZ,EAAE;IACD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAkEA;AAED,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,cAAc,CAwB3D,CAAC;AAEF,QAAA,MAAM,yBAAyB;;CAE9B,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
package/dist/crossReference.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useLinkProvider, useReferences, useBaseurl, withBaseurl, XRefProvider, useXRefState, } from '@myst-theme/providers';
|
|
2
|
+
import { useLinkProvider, useReferences, useBaseurl, withBaseurl, XRefProvider, useXRefState, useFrontmatter, } from '@myst-theme/providers';
|
|
3
3
|
import { InlineError } from './inlineError.js';
|
|
4
4
|
import { default as useSWR } from 'swr';
|
|
5
5
|
import { HoverPopover } from './components/index.js';
|
|
@@ -63,12 +63,22 @@ export function useFetchMdast({ remote, url, remoteBaseUrl, dataUrl, }) {
|
|
|
63
63
|
function useSelectNodes({ load, identifier }) {
|
|
64
64
|
var _a;
|
|
65
65
|
const references = useReferences();
|
|
66
|
+
const frontmatter = useFrontmatter();
|
|
66
67
|
const { remote, url, remoteBaseUrl, dataUrl } = useXRefState();
|
|
67
68
|
if (!load)
|
|
68
69
|
return;
|
|
69
70
|
const { data, error } = useFetchMdast({ remote, url, remoteBaseUrl, dataUrl });
|
|
70
|
-
const mdast =
|
|
71
|
-
const
|
|
71
|
+
const mdast = data ? data.mdast : references === null || references === void 0 ? void 0 : references.article;
|
|
72
|
+
const parts = data ? (_a = data.frontmatter) === null || _a === void 0 ? void 0 : _a.parts : frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.parts;
|
|
73
|
+
let nodes = [];
|
|
74
|
+
let htmlId;
|
|
75
|
+
[{ mdast }, ...Object.values(parts !== null && parts !== void 0 ? parts : {})].forEach(({ mdast: tree }) => {
|
|
76
|
+
if (!tree || nodes.length > 0)
|
|
77
|
+
return;
|
|
78
|
+
const selected = selectMdastNodes(tree, identifier, 3);
|
|
79
|
+
nodes = selected.nodes;
|
|
80
|
+
htmlId = selected.htmlId;
|
|
81
|
+
});
|
|
72
82
|
return { htmlId, nodes, loading: remote && !data, error: remote && error };
|
|
73
83
|
}
|
|
74
84
|
export function CrossReferenceHover({ url: urlIn, dataUrl: dataUrlIn, remote: remoteIn, remoteBaseUrl: remoteBaseUrlIn, children, identifier, htmlId = '', }) {
|
package/dist/footnotes.js
CHANGED
|
@@ -8,7 +8,7 @@ function FootnoteDefinition({ identifier }) {
|
|
|
8
8
|
var _a, _b;
|
|
9
9
|
const references = useReferences();
|
|
10
10
|
const node = (_b = (_a = references === null || references === void 0 ? void 0 : references.footnotes) === null || _a === void 0 ? void 0 : _a[identifier]) !== null && _b !== void 0 ? _b : select(`footnoteDefinition[identifier=${identifier}]`, references === null || references === void 0 ? void 0 : references.article);
|
|
11
|
-
return (_jsx(XRefProvider, { children: _jsx("div", { className: "hover-document article w-[500px] sm:max-w-[500px] px-3 text-sm", children: _jsx(MyST, { ast: node.children }) }) }));
|
|
11
|
+
return (_jsx(XRefProvider, { children: _jsx("div", { className: "hover-document article w-[500px] sm:max-w-[500px] px-3 text-sm", children: _jsx(MyST, { ast: node === null || node === void 0 ? void 0 : node.children }) }) }));
|
|
12
12
|
}
|
|
13
13
|
export const FootnoteReference = ({ node }) => {
|
|
14
14
|
var _a, _b;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "myst-to-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@heroicons/react": "^2.0.18",
|
|
24
|
-
"@myst-theme/providers": "^0.
|
|
24
|
+
"@myst-theme/providers": "^0.13.1",
|
|
25
25
|
"@scienceicons/react": "^0.0.6",
|
|
26
26
|
"@radix-ui/react-hover-card": "^1.0.6",
|
|
27
27
|
"buffer": "^6.0.3",
|
|
28
28
|
"classnames": "^2.3.2",
|
|
29
|
-
"myst-common": "^1.
|
|
30
|
-
"myst-config": "^1.
|
|
29
|
+
"myst-common": "^1.7.0",
|
|
30
|
+
"myst-config": "^1.7.0",
|
|
31
31
|
"myst-spec": "^0.0.5",
|
|
32
32
|
"nanoid": "^4.0.2",
|
|
33
33
|
"react-syntax-highlighter": "15.5.0",
|