myst-to-react 1.1.0 → 1.1.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.
@@ -3,6 +3,7 @@ import type { NodeRenderer, NodeRenderers } from '@myst-theme/providers';
3
3
  type TransformedLink = Link & {
4
4
  internal?: boolean;
5
5
  protocol?: string;
6
+ static?: boolean;
6
7
  };
7
8
  export declare const WikiLinkRenderer: NodeRenderer<TransformedLink>;
8
9
  export declare const GithubLinkRenderer: NodeRenderer<TransformedLink>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/links/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAatC,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AASzE,KAAK,eAAe,GAAG,IAAI,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA0DxE,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,eAAe,CAW1D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,eAAe,CAiB5D,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,eAAe,CAI1D,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC,eAAe,CAQzD,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,eAAe,CAoBpD,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,YAAY,CAAC,eAAe,CAmCnD,CAAC;AAEF,QAAA,MAAM,cAAc,EAAE,aAerB,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/links/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AActC,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAUzE,KAAK,eAAe,GAAG,IAAI,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AA+D1F,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,eAAe,CAW1D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,eAAe,CAiB5D,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,eAAe,CAI1D,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC,eAAe,CAQzD,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,eAAe,CA6BpD,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,YAAY,CAAC,eAAe,CAmCnD,CAAC;AAEF,QAAA,MAAM,cAAc,EAAE,aAerB,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ArrowTopRightOnSquareIcon as ExternalLinkIcon, LinkIcon, } from '@heroicons/react/24/outline';
2
+ import { ArrowTopRightOnSquareIcon as ExternalLinkIcon, LinkIcon, ArrowDownTrayIcon, } from '@heroicons/react/24/outline';
3
3
  import { isExternalUrl, useLinkProvider, useSiteManifest, useBaseurl, withBaseurl, } from '@myst-theme/providers';
4
4
  import { HoverPopover, LinkCard } from '../components/index.js';
5
5
  import { WikiLink } from './wiki.js';
@@ -27,7 +27,15 @@ function InternalLink({ url, children, className, }) {
27
27
  if (!page || skipPreview) {
28
28
  return (_jsx(Link, { to: withBaseurl(url, baseurl), prefetch: "intent", className: classNames('link', className), children: children }));
29
29
  }
30
- return (_jsx(HoverPopover, { card: _jsx(LinkCard, { internal: true, url: url, title: page.title, description: page.description, thumbnail: page.thumbnailOptimized || page.thumbnail }), children: _jsx(Link, { to: withBaseurl(url, baseurl), prefetch: "intent", className: classNames('hover-link', className), children: children }) }));
30
+ return (_jsx(HoverPopover
31
+ // Use a () function rather than directly loading the component.
32
+ // This avoids hydration errors in static builds so that card display works
33
+ // See: https://github.com/jupyter-book/myst-theme/issues/771
34
+ , {
35
+ // Use a () function rather than directly loading the component.
36
+ // This avoids hydration errors in static builds so that card display works
37
+ // See: https://github.com/jupyter-book/myst-theme/issues/771
38
+ card: () => (_jsx(LinkCard, { internal: true, url: url, title: page.title, description: page.description, thumbnail: page.thumbnailOptimized || page.thumbnail })), children: _jsx("span", { children: _jsx(Link, { to: withBaseurl(url, baseurl), prefetch: "intent", className: classNames('hover-link', className), children: children }) }) }));
31
39
  }
32
40
  export const WikiLinkRenderer = ({ node, className }) => {
33
41
  var _a, _b;
@@ -46,12 +54,19 @@ export const RORLinkRenderer = ({ node, className }) => {
46
54
  return (_jsx(RORLink, { node: node, ror: (_a = node.data) === null || _a === void 0 ? void 0 : _a.ror, className: classNames(node.class, className) }));
47
55
  };
48
56
  export const SimpleLink = ({ node, className }) => {
49
- var _a;
57
+ var _a, _b;
58
+ // Internal links will need to be modified by a baseURL (e.g. in static sites).
50
59
  const internal = (_a = node.internal) !== null && _a !== void 0 ? _a : !isExternalUrl(node.url);
51
- if (internal) {
60
+ // If the link is static (a link to a document/asset), we can just use the regular link.
61
+ const isStatic = (_b = node.static) !== null && _b !== void 0 ? _b : false;
62
+ if (internal && !isStatic) {
52
63
  return (_jsx(InternalLink, { url: node.url, className: classNames(node.class, className), children: _jsx(MyST, { ast: node.children }) }));
53
64
  }
54
- return (_jsxs("a", { target: "_blank", rel: "noreferrer", href: node.url, className: classNames('link', node.class, className), children: [_jsx(MyST, { ast: node.children }), _jsx(ExternalLinkIcon, { className: "external-link-icon" })] }));
65
+ return (
66
+ // External or download links get a little icon.
67
+ // We wrap the link text in an extra span so that we can control its whitespace handling
68
+ // We want the text in the link to wrap, but the icon *not* to wrap so it stays on the same line
69
+ _jsxs("a", { target: "_blank", rel: "noreferrer", href: node.url, className: classNames('link whitespace-nowrap', node.class, className), children: [_jsx("span", { className: "link-text whitespace-normal", children: _jsx(MyST, { ast: node.children }) }), isStatic && _jsx(ArrowDownTrayIcon, { className: "link-icon" }), !isStatic && _jsx(ExternalLinkIcon, { className: "link-icon" })] }));
55
70
  };
56
71
  export const linkBlock = ({ node, className }) => {
57
72
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myst-to-react",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@heroicons/react": "^2.0.18",
30
- "@myst-theme/providers": "^1.1.0",
30
+ "@myst-theme/providers": "^1.1.2",
31
31
  "@radix-ui/react-hover-card": "^1.0.6",
32
32
  "@scienceicons/react": "^0.0.13",
33
33
  "buffer": "^6.0.3",