@myst-theme/site 0.5.6 → 0.5.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myst-theme/site",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "main": "./src/index.ts",
5
5
  "types": "./src/index.ts",
6
6
  "files": [
@@ -16,18 +16,18 @@
16
16
  "dependencies": {
17
17
  "@headlessui/react": "^1.7.15",
18
18
  "@heroicons/react": "^2.0.18",
19
- "@myst-theme/diagrams": "^0.5.6",
20
- "@myst-theme/frontmatter": "^0.5.6",
21
- "@myst-theme/jupyter": "^0.5.6",
22
- "@myst-theme/common": "^0.5.6",
23
- "@myst-theme/providers": "^0.5.6",
19
+ "@myst-theme/diagrams": "^0.5.7",
20
+ "@myst-theme/frontmatter": "^0.5.7",
21
+ "@myst-theme/jupyter": "^0.5.7",
22
+ "@myst-theme/common": "^0.5.7",
23
+ "@myst-theme/providers": "^0.5.7",
24
24
  "classnames": "^2.3.2",
25
25
  "lodash.throttle": "^4.1.1",
26
- "myst-common": "^1.1.4",
27
- "myst-spec-ext": "^1.1.4",
28
- "myst-config": "^1.1.4",
29
- "myst-demo": "^0.5.6",
30
- "myst-to-react": "^0.5.6",
26
+ "myst-common": "^1.1.8",
27
+ "myst-spec-ext": "^1.1.8",
28
+ "myst-config": "^1.1.8",
29
+ "myst-demo": "^0.5.7",
30
+ "myst-to-react": "^0.5.7",
31
31
  "nbtx": "^0.2.3",
32
32
  "node-cache": "^5.1.2",
33
33
  "node-fetch": "^2.6.11",
@@ -1,12 +1,16 @@
1
1
  import type { GenericParent } from 'myst-common';
2
2
  import { ContentBlocks } from './ContentBlocks';
3
3
  import classNames from 'classnames';
4
+ import { HashLink } from 'myst-to-react';
4
5
 
5
6
  export function Abstract({ content }: { content: GenericParent }) {
6
- if (!content) return null;
7
+ if (!content) return <div className="hidden" aria-label="this article has no abstract" />;
7
8
  return (
8
9
  <>
9
- <span className="mb-3 font-semibold">Abstract</span>
10
+ <h2 id="abstract" className="mb-3 text-base font-semibold group">
11
+ Abstract
12
+ <HashLink id="abstract" title="Link to Abstract" hover className="ml-2" />
13
+ </h2>
10
14
  <div className="px-6 py-1 mb-3 rounded-sm bg-slate-50 dark:bg-slate-800">
11
15
  <ContentBlocks mdast={content} className="col-body" />
12
16
  </div>
@@ -21,9 +25,10 @@ export function Keywords({
21
25
  keywords?: string[];
22
26
  hideKeywords?: boolean;
23
27
  }) {
24
- if (hideKeywords || !keywords || keywords.length === 0) return null;
28
+ if (hideKeywords || !keywords || keywords.length === 0)
29
+ return <div className="hidden" aria-label="this article has no keywords" />;
25
30
  return (
26
- <div className="mb-10">
31
+ <div className="mb-10 group">
27
32
  <span className="mr-2 font-semibold">Keywords:</span>
28
33
  {keywords.map((k, i) => (
29
34
  <span
@@ -35,6 +40,7 @@ export function Keywords({
35
40
  {k}
36
41
  </span>
37
42
  ))}
43
+ <HashLink id="keywords" title="Link to Keywords" hover className="ml-2" />
38
44
  </div>
39
45
  );
40
46
  }
@@ -16,10 +16,13 @@ export function Navigation({
16
16
  }) {
17
17
  const [open, setOpen] = useNavOpen();
18
18
  const top = useThemeTop();
19
- if (hide_toc) return <>{children}</>;
19
+ if (children)
20
+ console.warn(
21
+ `Including children in Navigation can break keyboard accessbility and is deprecated. Please move children to the page component.`,
22
+ );
23
+ if (hide_toc) return children ? null : <>{children}</>;
20
24
  return (
21
25
  <>
22
- {children}
23
26
  {open && (
24
27
  <div
25
28
  className="fixed inset-0 z-30 bg-black opacity-50"
@@ -28,6 +31,7 @@ export function Navigation({
28
31
  ></div>
29
32
  )}
30
33
  <TableOfContents tocRef={tocRef} projectSlug={projectSlug} footer={footer} />
34
+ {children}
31
35
  </>
32
36
  );
33
37
  }
@@ -168,8 +168,7 @@ export const TableOfContents = ({
168
168
  'fixed',
169
169
  `xl:${grid}`, // for example, xl:article-grid
170
170
  'grid-gap xl:w-screen xl:pointer-events-none overflow-auto max-xl:min-w-[300px]',
171
- { hidden: !open },
172
- { 'z-30': open },
171
+ { hidden: !open, 'z-30': open, 'z-10': !open },
173
172
  )}
174
173
  style={{ top }}
175
174
  >
@@ -0,0 +1,52 @@
1
+ import { useCallback } from 'react';
2
+
3
+ function makeSkipClickHander(hash: string) {
4
+ return (e: React.UIEvent<HTMLElement, Event>) => {
5
+ e.preventDefault();
6
+ const el = document.querySelector(`#${hash}`);
7
+ if (!el) return;
8
+ el.scrollIntoView({ behavior: 'smooth' });
9
+ history.replaceState(undefined, '', `#${hash}`);
10
+ (el.nextSibling as HTMLElement).focus({ preventScroll: true });
11
+ (e.target as HTMLElement).blur();
12
+ };
13
+ }
14
+
15
+ export function SkipToArticle({
16
+ frontmatter = true,
17
+ article = true,
18
+ }: {
19
+ frontmatter?: boolean;
20
+ article?: boolean;
21
+ }) {
22
+ const fm = 'skip-to-frontmatter';
23
+ const art = 'skip-to-article';
24
+
25
+ const frontmatterHander = useCallback(() => makeSkipClickHander(fm), [frontmatter]);
26
+ const articleHandler = useCallback(() => makeSkipClickHander(art), [article]);
27
+ return (
28
+ <div
29
+ className="fixed top-1 left-1 h-[0px] w-[0px] focus-within:z-40 focus-within:h-auto focus-within:w-auto bg-white overflow-hidden focus-within:p-2 focus-within:ring-1"
30
+ aria-label="skip to content options"
31
+ >
32
+ {frontmatter && (
33
+ <a
34
+ href={`#${fm}`}
35
+ className="block px-2 py-1 text-black underline"
36
+ onClick={frontmatterHander}
37
+ >
38
+ Skip to article frontmatter
39
+ </a>
40
+ )}
41
+ {article && (
42
+ <a
43
+ href={`#${art}`}
44
+ className="block px-2 py-1 text-black underline"
45
+ onClick={articleHandler}
46
+ >
47
+ Skip to article content
48
+ </a>
49
+ )}
50
+ </div>
51
+ );
52
+ }
@@ -8,3 +8,4 @@ export { Abstract, Keywords } from './Abstract';
8
8
  export { ExternalOrInternalLink } from './ExternalOrInternalLink';
9
9
  export * from './Navigation';
10
10
  export { renderers } from './renderers';
11
+ export * from './SkipToArticle';
@@ -60,6 +60,7 @@ export const ArticlePage = React.memo(function ({
60
60
  )}
61
61
  {canCompute && article.kind === SourceFileKind.Notebook && <NotebookToolbar showLaunch />}
62
62
  <ErrorTray pageSlug={article.slug} />
63
+ <div id="skip-to-article" />
63
64
  <Abstract content={abstract as GenericParent} />
64
65
  {abstract && <Keywords keywords={keywords} hideKeywords={hideKeywords} />}
65
66
  <ContentBlocks pageKind={article.kind} mdast={tree as GenericParent} />