myst-to-react 0.9.0 → 0.9.2
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/cite.d.ts +2 -1
- package/dist/cite.d.ts.map +1 -1
- package/dist/cite.js +17 -6
- package/dist/crossReference.js +1 -1
- package/package.json +4 -4
package/dist/cite.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NodeRenderer } from '@myst-theme/providers';
|
|
2
|
-
|
|
2
|
+
import type { GenericParent } from 'myst-common';
|
|
3
|
+
export declare const CiteGroup: NodeRenderer<GenericParent>;
|
|
3
4
|
export declare const Cite: ({ label, error, children, }: {
|
|
4
5
|
label?: string | undefined;
|
|
5
6
|
error?: boolean | undefined;
|
package/dist/cite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cite.d.ts","sourceRoot":"","sources":["../src/cite.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"cite.d.ts","sourceRoot":"","sources":["../src/cite.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAK1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAiBjD,eAAO,MAAM,SAAS,EAAE,YAAY,CAAC,aAAa,CAcjD,CAAC;AAEF,eAAO,MAAM,IAAI;;;cAOL,MAAM,SAAS;6CAuB1B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,YAO1B,CAAC;AAEF,QAAA,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAGhD,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/dist/cite.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import { useReferences } from '@myst-theme/providers';
|
|
3
|
+
import { useReferences, useSiteManifest } from '@myst-theme/providers';
|
|
4
4
|
import { doi } from 'doi-utils';
|
|
5
5
|
import { InlineError } from './inlineError.js';
|
|
6
6
|
import { HoverPopover } from './components/index.js';
|
|
7
7
|
import { MyST } from './MyST.js';
|
|
8
|
+
function useNumberedReferences() {
|
|
9
|
+
var _a;
|
|
10
|
+
const config = useSiteManifest();
|
|
11
|
+
const numbered_references = !!((_a = config === null || config === void 0 ? void 0 : config.options) === null || _a === void 0 ? void 0 : _a.numbered_references);
|
|
12
|
+
return numbered_references;
|
|
13
|
+
}
|
|
8
14
|
function CiteChild({ html }) {
|
|
9
15
|
return (_jsx("div", { className: "hover-document article w-[500px] sm:max-w-[500px] p-3", dangerouslySetInnerHTML: { __html: html || '' } }));
|
|
10
16
|
}
|
|
11
17
|
export const CiteGroup = ({ node }) => {
|
|
12
|
-
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const allCite = (_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a.every((child) => child.type === 'cite')) !== null && _b !== void 0 ? _b : false;
|
|
20
|
+
return (_jsx("span", { className: classNames({
|
|
21
|
+
'cite-group': allCite,
|
|
22
|
+
'xref-group': !allCite,
|
|
13
23
|
narrative: node.kind === 'narrative',
|
|
14
24
|
parenthetical: node.kind === 'parenthetical',
|
|
15
25
|
}), children: _jsx(MyST, { ast: node.children }) }));
|
|
@@ -20,15 +30,16 @@ export const Cite = ({ label, error, children, }) => {
|
|
|
20
30
|
if (!label) {
|
|
21
31
|
return _jsx(InlineError, { value: "cite (no label)", message: 'Citation Has No Label' });
|
|
22
32
|
}
|
|
23
|
-
const { html, doi: doiString } = (_b = (_a = references === null || references === void 0 ? void 0 : references.cite) === null || _a === void 0 ? void 0 : _a.data[label]) !== null && _b !== void 0 ? _b : {};
|
|
33
|
+
const { html, doi: doiString, url: refUrl } = (_b = (_a = references === null || references === void 0 ? void 0 : references.cite) === null || _a === void 0 ? void 0 : _a.data[label]) !== null && _b !== void 0 ? _b : {};
|
|
24
34
|
if (error) {
|
|
25
35
|
return _jsx(InlineError, { value: label, message: 'Citation Not Found' });
|
|
26
36
|
}
|
|
27
|
-
const
|
|
28
|
-
return (_jsx(HoverPopover, { openDelay: 300, card: _jsx(CiteChild, { html: html }), children: _jsxs("cite", { children: [
|
|
37
|
+
const url = doiString ? doi.buildUrl(doiString) : refUrl;
|
|
38
|
+
return (_jsx(HoverPopover, { openDelay: 300, card: _jsx(CiteChild, { html: html }), children: _jsxs("cite", { children: [url && (_jsx("a", { href: url, target: "_blank", rel: "noreferrer", className: "hover-link", children: children })), !url && _jsx("span", { className: "hover-link", children: children })] }) }));
|
|
29
39
|
};
|
|
30
40
|
export const CiteRenderer = ({ node }) => {
|
|
31
|
-
|
|
41
|
+
const numbered = useNumberedReferences();
|
|
42
|
+
return (_jsx(Cite, { label: node.label, error: node.error, children: numbered && node.kind === 'parenthetical' ? node.enumerator : _jsx(MyST, { ast: node.children }) }));
|
|
32
43
|
};
|
|
33
44
|
const CITE_RENDERERS = {
|
|
34
45
|
citeGroup: CiteGroup,
|
package/dist/crossReference.js
CHANGED
|
@@ -104,7 +104,7 @@ export function useFetchMdast({ remote, url, dataUrl, }) {
|
|
|
104
104
|
const baseurl = useBaseurl();
|
|
105
105
|
const external = (_a = url === null || url === void 0 ? void 0 : url.startsWith('http')) !== null && _a !== void 0 ? _a : false;
|
|
106
106
|
const lookupUrl = external
|
|
107
|
-
?
|
|
107
|
+
? dataUrl !== null && dataUrl !== void 0 ? dataUrl : `${url}.json`
|
|
108
108
|
: dataUrl
|
|
109
109
|
? `${withBaseurl(dataUrl, baseurl)}`
|
|
110
110
|
: `${withBaseurl(url, baseurl)}.json`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "myst-to-react",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@heroicons/react": "^2.0.18",
|
|
24
|
-
"@myst-theme/providers": "^0.9.
|
|
24
|
+
"@myst-theme/providers": "^0.9.2",
|
|
25
25
|
"@radix-ui/react-hover-card": "^1.0.6",
|
|
26
26
|
"buffer": "^6.0.3",
|
|
27
27
|
"classnames": "^2.3.2",
|
|
28
|
-
"myst-common": "^1.
|
|
29
|
-
"myst-config": "^1.
|
|
28
|
+
"myst-common": "^1.4.0",
|
|
29
|
+
"myst-config": "^1.4.0",
|
|
30
30
|
"myst-spec": "^0.0.5",
|
|
31
31
|
"nanoid": "^4.0.2",
|
|
32
32
|
"react-syntax-highlighter": "^15.5.0",
|