@myst-theme/site 0.2.8 → 0.2.10

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.2.8",
3
+ "version": "0.2.10",
4
4
  "main": "./src/index.ts",
5
5
  "types": "./src/index.ts",
6
6
  "files": [
@@ -16,21 +16,21 @@
16
16
  "dependencies": {
17
17
  "@headlessui/react": "^1.7.13",
18
18
  "@heroicons/react": "^2.0.14",
19
- "@myst-theme/diagrams": "^0.2.8",
20
- "@myst-theme/frontmatter": "^0.2.8",
21
- "@myst-theme/jupyter": "^0.2.8",
22
- "@myst-theme/providers": "^0.2.8",
19
+ "@myst-theme/diagrams": "^0.2.10",
20
+ "@myst-theme/frontmatter": "^0.2.10",
21
+ "@myst-theme/jupyter": "^0.2.10",
22
+ "@myst-theme/providers": "^0.2.10",
23
23
  "classnames": "^2.3.2",
24
24
  "lodash.throttle": "^4.1.1",
25
- "myst-common": "^0.0.16",
26
- "myst-config": "^0.0.14",
27
- "myst-demo": "^0.2.8",
28
- "myst-to-react": "^0.2.8",
25
+ "myst-common": "^0.0.17",
26
+ "myst-config": "^0.0.16",
27
+ "myst-demo": "^0.2.10",
28
+ "myst-to-react": "^0.2.10",
29
29
  "nbtx": "^0.2.3",
30
30
  "node-cache": "^5.1.2",
31
31
  "node-fetch": "^2.6.7",
32
- "unist-util-select": "^4.0.1",
33
- "thebe-react": "^0.0.7"
32
+ "thebe-react": "^0.0.7",
33
+ "unist-util-select": "^4.0.1"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@remix-run/node": "^1.12.0",
@@ -28,7 +28,7 @@ function Block({
28
28
  }) {
29
29
  const renderers = useNodeRenderers() ?? DEFAULT_RENDERERS;
30
30
  const children = useParse(node, renderers);
31
- const subGrid = 'article-grid article-subgrid-gap col-screen mb-10';
31
+ const subGrid = 'article-grid article-subgrid-gap col-screen';
32
32
  const dataClassName = typeof node.data?.class === 'string' ? node.data?.class : undefined;
33
33
  // Hide the subgrid if either the dataClass or the className exists and includes `col-`
34
34
  const noSubGrid =
@@ -1,9 +1,9 @@
1
1
  import { useNavigation } from '@remix-run/react';
2
2
  import classNames from 'classnames';
3
3
  import throttle from 'lodash.throttle';
4
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { useCallback, useEffect, useRef, useState } from 'react';
5
5
 
6
- const SELECTOR = [1, 2, 3, 4, 5, 6].map((n) => `main h${n}`).join(', ');
6
+ const SELECTOR = [1, 2, 3, 4].map((n) => `main h${n}`).join(', ');
7
7
  const HIGHLIGHT_CLASS = 'highlight';
8
8
 
9
9
  const onClient = typeof document !== 'undefined';
@@ -14,8 +14,10 @@ type Heading = {
14
14
  titleHTML: string;
15
15
  level: number;
16
16
  };
17
+
17
18
  type Props = {
18
19
  headings: Heading[];
20
+ selector: string;
19
21
  activeId?: string;
20
22
  highlight?: () => void;
21
23
  };
@@ -23,7 +25,7 @@ type Props = {
23
25
  * This renders an item in the table of contents list.
24
26
  * scrollIntoView is used to ensure that when a user clicks on an item, it will smoothly scroll.
25
27
  */
26
- const Headings = ({ headings, activeId, highlight }: Props) => (
28
+ const Headings = ({ headings, activeId, highlight, selector }: Props) => (
27
29
  <ul className="text-slate-400 text-sm leading-6">
28
30
  {headings.map((heading) => (
29
31
  <li
@@ -36,11 +38,11 @@ const Headings = ({ headings, activeId, highlight }: Props) => (
36
38
  })}
37
39
  >
38
40
  <a
39
- className={classNames('block p-1 pl-2', {
41
+ className={classNames('block p-1', {
40
42
  'text-slate-900 dark:text-slate-50': heading.level < 3 && heading.id !== activeId,
41
43
  'text-slate-500 dark:text-slate-300': heading.level >= 3 && heading.id !== activeId,
42
44
  'text-blue-600 dark:text-white font-bold': heading.id === activeId,
43
- 'pr-2': heading.id !== activeId,
45
+ 'pr-2': heading.id !== activeId, // Allows for bold to change length
44
46
  'pl-2': heading.level === 2,
45
47
  'pl-4': heading.level === 3,
46
48
  'pl-8 text-xs': heading.level === 4,
@@ -52,7 +54,7 @@ const Headings = ({ headings, activeId, highlight }: Props) => (
52
54
  e.preventDefault();
53
55
  const el = document.querySelector(`#${heading.id}`);
54
56
  if (!el) return;
55
- getHeaders().forEach((h) => {
57
+ getHeaders(selector).forEach((h) => {
56
58
  h.classList.remove(HIGHLIGHT_CLASS);
57
59
  });
58
60
  el.classList.add(HIGHLIGHT_CLASS);
@@ -68,15 +70,15 @@ const Headings = ({ headings, activeId, highlight }: Props) => (
68
70
  </ul>
69
71
  );
70
72
 
71
- function getHeaders(): HTMLHeadingElement[] {
72
- const headers = Array.from(document.querySelectorAll(SELECTOR)).filter((e) => {
73
+ function getHeaders(selector: string): HTMLHeadingElement[] {
74
+ const headers = Array.from(document.querySelectorAll(selector)).filter((e) => {
73
75
  const parent = e.closest('.exclude-from-outline');
74
76
  return !(e.classList.contains('title') || parent);
75
77
  });
76
78
  return headers as HTMLHeadingElement[];
77
79
  }
78
80
 
79
- function useHeaders() {
81
+ function useHeaders(selector: string) {
80
82
  if (!onClient) return { activeId: '', headings: [] };
81
83
  const onScreen = useRef<Set<HTMLHeadingElement>>(new Set());
82
84
  const [activeId, setActiveId] = useState<string>();
@@ -96,7 +98,7 @@ function useHeaders() {
96
98
  const { observer } = useIntersectionObserver(highlight, onScreen.current);
97
99
  const [elements, setElements] = useState<HTMLHeadingElement[]>([]);
98
100
 
99
- const render = throttle(() => setElements(getHeaders()), 500);
101
+ const render = throttle(() => setElements(getHeaders(selector)), 500);
100
102
  useEffect(() => {
101
103
  // We have to look at the document changes for reloads/mutations
102
104
  const main = document.querySelector('main');
@@ -185,13 +187,15 @@ export const DocumentOutline = ({
185
187
  outlineRef,
186
188
  top,
187
189
  className = DOC_OUTLINE_CLASS,
190
+ selector = SELECTOR,
188
191
  }: {
189
192
  outlineRef?: React.RefObject<HTMLElement>;
190
193
  top?: number;
191
194
  height?: number;
192
195
  className?: string;
196
+ selector?: string;
193
197
  }) => {
194
- const { activeId, headings, highlight } = useHeaders();
198
+ const { activeId, headings, highlight } = useHeaders(selector);
195
199
  if (headings.length <= 1 || !onClient) {
196
200
  return <nav suppressHydrationWarning style={{ display: 'none' }} />;
197
201
  }
@@ -212,7 +216,7 @@ export const DocumentOutline = ({
212
216
  <div className="text-slate-900 mb-4 text-sm leading-6 dark:text-slate-100 uppercase">
213
217
  In this article
214
218
  </div>
215
- <Headings headings={headings} activeId={activeId} highlight={highlight} />
219
+ <Headings headings={headings} activeId={activeId} highlight={highlight} selector={selector} />
216
220
  </nav>
217
221
  );
218
222
  };
@@ -4,7 +4,13 @@ import ArrowRightIcon from '@heroicons/react/24/outline/ArrowRightIcon';
4
4
  import type { FooterLinks, NavigationLink } from '../types';
5
5
  import { useLinkProvider, useBaseurl, withBaseurl } from '@myst-theme/providers';
6
6
 
7
- const FooterLink = ({ title, url, group, right }: NavigationLink & { right?: boolean }) => {
7
+ const FooterLink = ({
8
+ title,
9
+ short_title,
10
+ url,
11
+ group,
12
+ right,
13
+ }: NavigationLink & { right?: boolean }) => {
8
14
  const baseurl = useBaseurl();
9
15
  const Link = useLinkProvider();
10
16
  return (
@@ -15,14 +21,14 @@ const FooterLink = ({ title, url, group, right }: NavigationLink & { right?: boo
15
21
  >
16
22
  <div className="flex align-middle h-full">
17
23
  {right && (
18
- <ArrowLeftIcon className="w-6 h-6 self-center transition-transform group-hover:-translate-x-1" />
24
+ <ArrowLeftIcon className="w-6 h-6 self-center transition-transform group-hover:-translate-x-1 shrink-0" />
19
25
  )}
20
26
  <div className={classNames('flex-grow', { 'text-right': right })}>
21
27
  <div className="text-xs text-gray-500 dark:text-gray-400">{group || ' '}</div>
22
- {title}
28
+ {short_title || title}
23
29
  </div>
24
30
  {!right && (
25
- <ArrowRightIcon className="w-6 h-6 self-center transition-transform group-hover:translate-x-1" />
31
+ <ArrowRightIcon className="w-6 h-6 self-center transition-transform group-hover:translate-x-1 shrink-0" />
26
32
  )}
27
33
  </div>
28
34
  </Link>
@@ -32,7 +38,7 @@ const FooterLink = ({ title, url, group, right }: NavigationLink & { right?: boo
32
38
  export function FooterLinksBlock({ links }: { links?: FooterLinks }) {
33
39
  if (!links) return null;
34
40
  return (
35
- <div className="flex space-x-4 my-10">
41
+ <div className="flex space-x-4 pt-10 mb-10">
36
42
  {links.navigation?.prev && <FooterLink {...links.navigation?.prev} right />}
37
43
  {links.navigation?.next && <FooterLink {...links.navigation?.next} />}
38
44
  </div>
@@ -32,6 +32,7 @@ export function getProjectHeadings(
32
32
  const headings: Heading[] = [
33
33
  {
34
34
  title: project.title,
35
+ short_title: project.short_title,
35
36
  slug: project.index,
36
37
  path: project.slug ? `/${project.slug}` : '/',
37
38
  level: 'index',
@@ -42,10 +43,10 @@ export function getProjectHeadings(
42
43
  }),
43
44
  ];
44
45
  if (opts.addGroups) {
45
- let lastTitle = project.title;
46
+ let lastTitle = project.short_title || project.title;
46
47
  return headings.map((heading) => {
47
48
  if (!heading.slug || heading.level === 'index') {
48
- lastTitle = heading.title;
49
+ lastTitle = heading.short_title || heading.title;
49
50
  }
50
51
  return { ...heading, group: lastTitle };
51
52
  });
@@ -60,6 +61,7 @@ function getHeadingLink(currentSlug: string, headings?: Heading[]): NavigationLi
60
61
  if (!link?.path) return undefined;
61
62
  return {
62
63
  title: link.title,
64
+ short_title: link.short_title,
63
65
  url: link.path,
64
66
  group: link.group,
65
67
  };
package/src/types.ts CHANGED
@@ -25,6 +25,7 @@ export type NavigationLink = {
25
25
  group?: string;
26
26
  title: string;
27
27
  url: string;
28
+ short_title?: string;
28
29
  };
29
30
 
30
31
  export type FooterLinks = {