@curvenote/renderers 0.2.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/README.md +6 -0
- package/dist/cite.d.ts +17 -0
- package/dist/cite.d.ts.map +1 -0
- package/dist/cite.js +94 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/pdbLink.d.ts +6 -0
- package/dist/pdbLink.d.ts.map +1 -0
- package/dist/pdbLink.js +30 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# @curvenote/renderers
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@curvenote/renderers)
|
|
4
|
+
[](https://github.com/curvenote/curvenote/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
Add Curvenote renderers to a site.
|
package/dist/cite.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NodeRenderer } from '@myst-theme/providers';
|
|
2
|
+
import type { GenericParent } from 'myst-common';
|
|
3
|
+
interface Props {
|
|
4
|
+
value: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function InlineError({ value, message }: Props): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const CiteGroup: NodeRenderer<GenericParent>;
|
|
9
|
+
export declare const Cite: ({ label, error, children, }: {
|
|
10
|
+
label?: string;
|
|
11
|
+
error?: boolean;
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const CiteRenderer: NodeRenderer;
|
|
15
|
+
declare const CITE_RENDERERS: Record<string, NodeRenderer>;
|
|
16
|
+
export default CITE_RENDERERS;
|
|
17
|
+
//# sourceMappingURL=cite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cite.d.ts","sourceRoot":"","sources":["../src/cite.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAI1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,UAAU,KAAK;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,2CAOpD;AAgCD,eAAO,MAAM,SAAS,EAAE,YAAY,CAAC,aAAa,CAkDjD,CAAC;AAEF,eAAO,MAAM,IAAI,gCAId;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,4CAsBA,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
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// This code was forked from `myst-to-react`.
|
|
3
|
+
// https://github.com/jupyter-book/myst-theme/commit/61e24acebfb79dbe532088ce4f654ae8deb4de8b
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright (c) 2024 Project Jupyter - Distributed under the terms of the MIT License
|
|
7
|
+
*/
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import { useReferences, useSiteManifest } from '@myst-theme/providers';
|
|
10
|
+
import { doi } from 'doi-utils';
|
|
11
|
+
import { ExclamationCircleIcon } from '@heroicons/react/24/outline';
|
|
12
|
+
import { HoverPopover, MyST } from 'myst-to-react';
|
|
13
|
+
import { Fragment } from 'react/jsx-runtime';
|
|
14
|
+
export function InlineError({ value, message }) {
|
|
15
|
+
return (_jsxs("span", { className: "text-yellow-600", title: message || value, children: [_jsx(ExclamationCircleIcon, { width: "1rem", height: "1rem", className: "inline mr-1" }), value] }));
|
|
16
|
+
}
|
|
17
|
+
function useNumberedReferences() {
|
|
18
|
+
var _a;
|
|
19
|
+
const config = useSiteManifest();
|
|
20
|
+
const numbered_references = !!((_a = config === null || config === void 0 ? void 0 : config.options) === null || _a === void 0 ? void 0 : _a.numbered_references);
|
|
21
|
+
return numbered_references;
|
|
22
|
+
}
|
|
23
|
+
function CiteChild({ html }) {
|
|
24
|
+
return (_jsx("div", { className: "hover-document article w-[500px] sm:max-w-[500px] p-3", dangerouslySetInnerHTML: { __html: html || '' } }));
|
|
25
|
+
}
|
|
26
|
+
// function CiteChildren({ citations }: { citations?: { enumerator: string; html: string }[] }) {
|
|
27
|
+
// return (
|
|
28
|
+
// <div className="hover-document article w-[500px] max-h-[500px] overflow-auto sm:max-w-[500px] p-3">
|
|
29
|
+
// {citations?.map((c) => (
|
|
30
|
+
// <div className="grid grid-cols-[35px_1fr] gap-2 my-1" key={c.enumerator}>
|
|
31
|
+
// <div className="text-right select-none text-stone-500 dark:text-stone-300">
|
|
32
|
+
// {c.enumerator}.
|
|
33
|
+
// </div>
|
|
34
|
+
// <div dangerouslySetInnerHTML={{ __html: c.html || '' }} />
|
|
35
|
+
// </div>
|
|
36
|
+
// ))}
|
|
37
|
+
// </div>
|
|
38
|
+
// );
|
|
39
|
+
// }
|
|
40
|
+
export const CiteGroup = ({ node }) => {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const numbered = useNumberedReferences();
|
|
43
|
+
// const references = useReferences();
|
|
44
|
+
const allCite = (_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a.every((child) => child.type === 'cite')) !== null && _b !== void 0 ? _b : false;
|
|
45
|
+
if (numbered && allCite && node.kind === 'parenthetical') {
|
|
46
|
+
// const citations =
|
|
47
|
+
// node.children?.map((child) => {
|
|
48
|
+
// const label = child.label;
|
|
49
|
+
// const {
|
|
50
|
+
// html,
|
|
51
|
+
// enumerator,
|
|
52
|
+
// doi: doiString,
|
|
53
|
+
// url: refUrl,
|
|
54
|
+
// } = references?.cite?.data[label ?? ''] ?? {};
|
|
55
|
+
// return { label, html, enumerator, doi: doiString, url: refUrl };
|
|
56
|
+
// }) ?? [];
|
|
57
|
+
// return (
|
|
58
|
+
// <HoverPopover openDelay={300} card={<CiteChildren citations={citations as any} />}>
|
|
59
|
+
// <sup className="cite-group hover-link">
|
|
60
|
+
// <cite>{citations.map((c) => c.enumerator).join(', ')}</cite>
|
|
61
|
+
// </sup>
|
|
62
|
+
// </HoverPopover>
|
|
63
|
+
// );
|
|
64
|
+
return (_jsx("sup", { className: "cite-group", children: _jsx("cite", { children: node.children.map((c, i) => (_jsxs(Fragment, { children: [_jsx(MyST, { ast: c }), i < node.children.length - 1 ? ', ' : null] }, c.key + 'wrap'))) }) }));
|
|
65
|
+
}
|
|
66
|
+
return (_jsx("span", { className: classNames({
|
|
67
|
+
'cite-group': allCite,
|
|
68
|
+
'xref-group': !allCite,
|
|
69
|
+
narrative: node.kind === 'narrative',
|
|
70
|
+
parenthetical: node.kind === 'parenthetical',
|
|
71
|
+
}), children: _jsx(MyST, { ast: node.children }) }));
|
|
72
|
+
};
|
|
73
|
+
export const Cite = ({ label, error, children, }) => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
const references = useReferences();
|
|
76
|
+
if (!label) {
|
|
77
|
+
return _jsx(InlineError, { value: "cite (no label)", message: 'Citation Has No Label' });
|
|
78
|
+
}
|
|
79
|
+
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 : {};
|
|
80
|
+
if (error) {
|
|
81
|
+
return _jsx(InlineError, { value: label, message: 'Citation Not Found' });
|
|
82
|
+
}
|
|
83
|
+
const url = doiString ? doi.buildUrl(doiString) : refUrl;
|
|
84
|
+
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 })] }) }));
|
|
85
|
+
};
|
|
86
|
+
export const CiteRenderer = ({ node }) => {
|
|
87
|
+
const numbered = useNumberedReferences();
|
|
88
|
+
return (_jsx(Cite, { label: node.label, error: node.error, children: numbered && node.kind === 'parenthetical' ? node.enumerator : _jsx(MyST, { ast: node.children }) }));
|
|
89
|
+
};
|
|
90
|
+
const CITE_RENDERERS = {
|
|
91
|
+
citeGroup: CiteGroup,
|
|
92
|
+
cite: CiteRenderer,
|
|
93
|
+
};
|
|
94
|
+
export default CITE_RENDERERS;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,+CAG7B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { mergeRenderers } from '@myst-theme/providers';
|
|
2
|
+
import CITE_RENDERERS from './cite.js';
|
|
3
|
+
import PERSON_CARD_RENDERERS from '@curvenote/ext-person/react';
|
|
4
|
+
export const curvenoteRenderers = mergeRenderers([
|
|
5
|
+
CITE_RENDERERS,
|
|
6
|
+
PERSON_CARD_RENDERERS, //
|
|
7
|
+
]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdbLink.d.ts","sourceRoot":"","sources":["../src/pdbLink.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA8D/C,wBAAgB,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,2CAQxE"}
|
package/dist/pdbLink.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { default as useSWR } from 'swr';
|
|
3
|
+
import { HoverPopover, LinkCard, MyST } from 'myst-to-react';
|
|
4
|
+
const createQuery = (id) => `{"query":"query structure ($id: String!) {\n entry(entry_id:$id){\n rcsb_id\n struct {\n title\n }\n pubmed {\n rcsb_pubmed_container_identifiers {\n pubmed_id\n }\n rcsb_pubmed_central_id\n rcsb_pubmed_doi\n rcsb_pubmed_abstract_text\n rcsb_pubmed_affiliation_info\n }\n }\n}\n","variables":{"id":"${id}"},"operationName":"structure"}`;
|
|
5
|
+
const fetcher = (id) => fetch('https://data.rcsb.org/graphql', {
|
|
6
|
+
method: 'post',
|
|
7
|
+
headers: [['Content-Type', 'application/json']],
|
|
8
|
+
body: createQuery(id),
|
|
9
|
+
}).then((res) => {
|
|
10
|
+
if (res.status === 200)
|
|
11
|
+
return res.json();
|
|
12
|
+
throw new Error(`Content returned with status ${res.status}.`);
|
|
13
|
+
});
|
|
14
|
+
function PDBChild({ pdb }) {
|
|
15
|
+
const { data, error } = useSWR(pdb, fetcher);
|
|
16
|
+
if (!data && !error) {
|
|
17
|
+
return (_jsx("div", { className: "hover-document article w-[500px] sm:max-w-[500px] animate-pulse", children: "Loading..." }));
|
|
18
|
+
}
|
|
19
|
+
if (error) {
|
|
20
|
+
return (_jsxs("div", { className: "hover-document article w-[500px] sm:max-w-[500px]", children: ["Error loading ", pdb, "."] }));
|
|
21
|
+
}
|
|
22
|
+
// return <div>{JSON.stringify(data)}</div>;
|
|
23
|
+
const rcsb_id = data.data.entry.rcsb_id;
|
|
24
|
+
const title = data.data.entry.struct.title;
|
|
25
|
+
const abstract = data.data.entry.pubmed.rcsb_pubmed_abstract_text;
|
|
26
|
+
return (_jsx(LinkCard, { loading: !data, url: `https://www.rcsb.org/structure/${pdb}`, title: _jsxs("p", { className: "flex items-stretch gap-2 text-sm font-light", children: [_jsx("span", { children: "PDB: " }), _jsx("a", { href: `https://www.rcsb.org/structure/${pdb}`, className: "self-center", target: "_blank", rel: "noopener noreferrer", children: _jsx("code", { children: rcsb_id }) })] }), thumbnail: 'https://cdn.rcsb.org/images/structures/4n3b_assembly-1.jpeg', description: _jsxs(_Fragment, { children: [_jsx("div", { className: "mb-4 font-bold", children: title }), _jsx("p", { className: "mb-4 text-sm", children: abstract })] }) }));
|
|
27
|
+
}
|
|
28
|
+
export function PDBLink({ node, pdb }) {
|
|
29
|
+
return (_jsx(HoverPopover, { card: _jsx(PDBChild, { pdb: pdb }), children: _jsx("a", { href: `https://www.rcsb.org/structure/${pdb}`, target: "_blank", rel: "noopener noreferrer", children: _jsx(MyST, { ast: node.children }) }) }));
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@curvenote/renderers",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=16"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "rimraf dist",
|
|
17
|
+
"lint": "eslint \"src/**/*.ts*\" \"src/**/*.tsx\" -c ./.eslintrc.cjs",
|
|
18
|
+
"lint:format": "prettier --check \"src/**/*.{ts,tsx,md}\"",
|
|
19
|
+
"dev": "npm-run-all --parallel \"build:* -- --watch\"",
|
|
20
|
+
"build:esm": "tsc",
|
|
21
|
+
"build": "npm-run-all -l clean -p build:esm"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@curvenote/ext-person": "^0.2.1",
|
|
25
|
+
"@heroicons/react": "^2.1.5",
|
|
26
|
+
"@myst-theme/providers": "^0.11.0",
|
|
27
|
+
"classnames": "^2.5.1",
|
|
28
|
+
"myst-to-react": "^0.11.0",
|
|
29
|
+
"swr": "^2.1.5"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "^16.8 || ^17.0 || ^18.0",
|
|
33
|
+
"react-dom": "^16.8 || ^17.0 || ^18.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "latest"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|