@myst-theme/site 0.2.7 → 0.2.9
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.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"main": "./src/index.ts",
|
|
5
5
|
"types": "./src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@headlessui/react": "^1.7.13",
|
|
18
18
|
"@heroicons/react": "^2.0.14",
|
|
19
|
-
"@myst-theme/diagrams": "^0.2.
|
|
20
|
-
"@myst-theme/frontmatter": "^0.2.
|
|
21
|
-
"@myst-theme/jupyter": "^0.2.
|
|
22
|
-
"@myst-theme/providers": "^0.2.
|
|
19
|
+
"@myst-theme/diagrams": "^0.2.9",
|
|
20
|
+
"@myst-theme/frontmatter": "^0.2.9",
|
|
21
|
+
"@myst-theme/jupyter": "^0.2.9",
|
|
22
|
+
"@myst-theme/providers": "^0.2.9",
|
|
23
23
|
"classnames": "^2.3.2",
|
|
24
24
|
"lodash.throttle": "^4.1.1",
|
|
25
25
|
"myst-common": "^0.0.16",
|
|
26
26
|
"myst-config": "^0.0.14",
|
|
27
|
-
"myst-demo": "^0.2.
|
|
28
|
-
"myst-to-react": "^0.2.
|
|
27
|
+
"myst-demo": "^0.2.9",
|
|
28
|
+
"myst-to-react": "^0.2.9",
|
|
29
29
|
"nbtx": "^0.2.3",
|
|
30
30
|
"node-cache": "^5.1.2",
|
|
31
31
|
"node-fetch": "^2.6.7",
|
|
@@ -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
|
|
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,
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
5
|
|
|
6
|
-
const SELECTOR = [1, 2, 3, 4
|
|
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
|
|
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(
|
|
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
|
};
|
|
@@ -32,7 +32,7 @@ const FooterLink = ({ title, url, group, right }: NavigationLink & { right?: boo
|
|
|
32
32
|
export function FooterLinksBlock({ links }: { links?: FooterLinks }) {
|
|
33
33
|
if (!links) return null;
|
|
34
34
|
return (
|
|
35
|
-
<div className="flex space-x-4
|
|
35
|
+
<div className="flex space-x-4 pt-10 mb-10">
|
|
36
36
|
{links.navigation?.prev && <FooterLink {...links.navigation?.prev} right />}
|
|
37
37
|
{links.navigation?.next && <FooterLink {...links.navigation?.next} />}
|
|
38
38
|
</div>
|