@myst-theme/site 0.1.36 → 0.1.38

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.1.36",
3
+ "version": "0.1.38",
4
4
  "main": "./src/index.ts",
5
5
  "types": "./src/index.ts",
6
6
  "files": [
@@ -16,20 +16,21 @@
16
16
  "dependencies": {
17
17
  "@headlessui/react": "^1.7.13",
18
18
  "@heroicons/react": "^2.0.14",
19
- "@myst-theme/diagrams": "^0.1.36",
20
- "@myst-theme/frontmatter": "^0.1.36",
21
- "@myst-theme/jupyter": "^0.1.36",
22
- "@myst-theme/providers": "^0.1.36",
19
+ "@myst-theme/diagrams": "^0.1.38",
20
+ "@myst-theme/frontmatter": "^0.1.38",
21
+ "@myst-theme/jupyter": "^0.1.38",
22
+ "@myst-theme/providers": "^0.1.38",
23
23
  "classnames": "^2.3.2",
24
24
  "lodash.throttle": "^4.1.1",
25
25
  "myst-common": "^0.0.16",
26
- "myst-config": "^0.0.12",
27
- "myst-demo": "^0.1.36",
28
- "myst-to-react": "^0.1.36",
26
+ "myst-config": "^0.0.14",
27
+ "myst-demo": "^0.1.38",
28
+ "myst-to-react": "^0.1.38",
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"
32
+ "unist-util-select": "^4.0.1",
33
+ "thebe-react": "^0.0.7"
33
34
  },
34
35
  "peerDependencies": {
35
36
  "@remix-run/node": "^1.12.0",
@@ -0,0 +1,124 @@
1
+ import { Spinner } from './Spinner';
2
+ import PlayCircleIcon from '@heroicons/react/24/outline/PlayCircleIcon';
3
+ import ArrowPathIcon from '@heroicons/react/24/outline/ArrowPathIcon';
4
+ import MinusCircleIcon from '@heroicons/react/24/outline/MinusCircleIcon';
5
+ import ArrowTopRightOnSquareIcon from '@heroicons/react/24/outline/ArrowTopRightOnSquareIcon';
6
+ import classNames from 'classnames';
7
+ import type { NotebookExecuteOptions } from 'thebe-react';
8
+ import { useThebeServer } from 'thebe-react';
9
+ import type { IThebeCellExecuteReturn } from 'thebe-core';
10
+ import { useMDASTNotebook, useNotebookCellExecution } from '@myst-theme/jupyter';
11
+
12
+ export function Run({
13
+ ready,
14
+ executing,
15
+ disabled,
16
+ execute,
17
+ }: {
18
+ ready: boolean;
19
+ executing: boolean;
20
+ disabled?: boolean;
21
+ execute: (
22
+ options?: NotebookExecuteOptions | undefined,
23
+ ) => Promise<(IThebeCellExecuteReturn | null)[]>;
24
+ }) {
25
+ return (
26
+ <div className="flex relative text-sm">
27
+ <button
28
+ className={classNames(
29
+ 'cursor-pointer text-gray-700 active:text-green-700 hover:opacity-100',
30
+ {
31
+ 'opacity-10 hover:opacity-10': executing,
32
+ 'opacity-60': !executing,
33
+ },
34
+ )}
35
+ disabled={disabled || !ready || executing}
36
+ onClick={() => execute()}
37
+ >
38
+ <PlayCircleIcon className="h-6 w-6 inline-block align-top" title="run all cells" />
39
+ </button>
40
+ {executing && (
41
+ <span className="absolute top-0 left-0 z-10 w-[22px] h-[22px] opacity-100">
42
+ <Spinner size={24} />
43
+ </span>
44
+ )}
45
+ </div>
46
+ );
47
+ }
48
+
49
+ export function Clear({
50
+ ready,
51
+ executing,
52
+ disabled,
53
+ clear,
54
+ }: {
55
+ ready: boolean;
56
+ executing: boolean;
57
+ disabled?: boolean;
58
+ clear: () => void;
59
+ }) {
60
+ return (
61
+ <button
62
+ className="flex cursor-pointer text-gray-700 active:text-green-700 opacity-60 hover:opacity-100"
63
+ disabled={disabled || !ready || executing}
64
+ onClick={() => clear()}
65
+ >
66
+ <MinusCircleIcon className="h-6 w-6 inline-block align-top" title="clear all outputs" />
67
+ </button>
68
+ );
69
+ }
70
+
71
+ export function RunCell({ id }: { id: string }) {
72
+ const exec = useNotebookCellExecution(id);
73
+ if (!exec?.ready) return null;
74
+ const { ready, executing, notebookIsExecuting, execute } = exec;
75
+ return (
76
+ <Run ready={ready} executing={executing} disabled={notebookIsExecuting} execute={execute} />
77
+ );
78
+ }
79
+
80
+ export function ClearCell({ id }: { id: string }) {
81
+ const exec = useNotebookCellExecution(id);
82
+ if (!exec?.ready) return null;
83
+ const { ready, executing, notebookIsExecuting, clear } = exec;
84
+ return <Clear ready={ready} executing={executing} disabled={notebookIsExecuting} clear={clear} />;
85
+ }
86
+
87
+ export function NotebookRunAll() {
88
+ const { ready: serverReady, server } = useThebeServer();
89
+ const exec = useMDASTNotebook();
90
+
91
+ if (!exec?.ready) return null;
92
+ const { ready, executing, executeAll, restart, clear } = exec;
93
+
94
+ const clickLaunchInJupyter = () => {
95
+ if (!serverReady || !server?.settings) return;
96
+ window.open(server.settings.baseUrl, '_blank');
97
+ };
98
+
99
+ return (
100
+ <div className="flex">
101
+ <div className="group flex relative space-x-1">
102
+ <Run ready={ready} executing={executing} execute={executeAll} />
103
+ <button
104
+ className="flex items-center cursor-pointer text-gray-700 active:text-green-700 opacity-60 hover:opacity-100"
105
+ disabled={!ready || executing}
106
+ onClick={() => restart()}
107
+ >
108
+ <ArrowPathIcon className="h-6 w-6" title="restart kernel" />
109
+ </button>
110
+ <Clear ready={ready} executing={executing} clear={clear} />
111
+ <button
112
+ className="flex items-center cursor-pointer text-gray-700 active:text-green-700 opacity-60 hover:opacity-100"
113
+ disabled={!ready}
114
+ onClick={clickLaunchInJupyter}
115
+ >
116
+ <ArrowTopRightOnSquareIcon
117
+ className="h-6 w-6 inline-block align-top"
118
+ title="launch in juptyer"
119
+ />
120
+ </button>
121
+ </div>
122
+ </div>
123
+ );
124
+ }
@@ -1,9 +1,31 @@
1
1
  import { useParse, DEFAULT_RENDERERS } from 'myst-to-react';
2
- import type { Parent } from 'myst-spec';
2
+ import { SourceFileKind } from 'myst-common';
3
+ import type { GenericParent } from 'myst-common';
3
4
  import { useNodeRenderers } from '@myst-theme/providers';
4
5
  import classNames from 'classnames';
6
+ import { ClearCell, RunCell } from './ComputeControls';
5
7
 
6
- function Block({ id, node, className }: { id: string; node: Parent; className?: string }) {
8
+ function isACodeCell(node: GenericParent) {
9
+ return (
10
+ node &&
11
+ node.type === 'block' &&
12
+ node.children &&
13
+ node.children?.length === 2 &&
14
+ node.children[0].type === 'code' &&
15
+ node.children[1].type === 'output'
16
+ );
17
+ }
18
+
19
+ function Block({
20
+ id,
21
+ node,
22
+ className,
23
+ }: {
24
+ id: string;
25
+ pageKind: SourceFileKind;
26
+ node: GenericParent;
27
+ className?: string;
28
+ }) {
7
29
  const renderers = useNodeRenderers() ?? DEFAULT_RENDERERS;
8
30
  const children = useParse(node, renderers);
9
31
  const subGrid = 'article-grid article-subgrid-gap col-screen';
@@ -13,23 +35,39 @@ function Block({ id, node, className }: { id: string; node: Parent; className?:
13
35
  (dataClassName && dataClassName.includes('col-')) || (className && className.includes('col-'));
14
36
  return (
15
37
  <div
38
+ key={id}
16
39
  id={id}
17
- className={classNames(className, dataClassName, {
40
+ className={classNames('relative group/block', className, dataClassName, {
18
41
  [subGrid]: !noSubGrid,
19
42
  })}
20
43
  >
21
44
  {children}
45
+ {isACodeCell(node) && (
46
+ <div className="hidden group-hover/block:flex md:flex-col absolute -top-[28px] md:top-0 right-0 md:-right-[28px] mt-8">
47
+ <RunCell id={id} />
48
+ <ClearCell id={id} />
49
+ </div>
50
+ )}
22
51
  </div>
23
52
  );
24
53
  }
25
54
 
26
- export function ContentBlocks({ mdast, className }: { mdast: Parent; className?: string }) {
27
- const blocks = mdast.children as Parent[];
55
+ export function ContentBlocks({
56
+ mdast,
57
+ pageKind = SourceFileKind.Article,
58
+ className,
59
+ }: {
60
+ mdast: GenericParent;
61
+ pageKind?: SourceFileKind;
62
+ className?: string;
63
+ }) {
64
+ if (!mdast) return null;
65
+ const blocks = mdast.children as GenericParent[];
28
66
  return (
29
67
  <>
30
- {blocks.map((node, index) => {
31
- return <Block key={(node as any).key} id={`${index}`} node={node} className={className} />;
32
- })}
68
+ {blocks.map((node) => (
69
+ <Block key={node.key} id={node.key} pageKind={pageKind} node={node} className={className} />
70
+ ))}
33
71
  </>
34
72
  );
35
73
  }
@@ -55,12 +55,9 @@ async function mystLiveReloadConnect(config: { onOpen?: () => void; port?: strin
55
55
  }
56
56
 
57
57
  // Inspired by the LiveReload component in Remix
58
- export const ContentReload =
59
- process.env.NODE_ENV !== 'development'
60
- ? () => null
61
- : ({ port }: { port?: string | number }) => {
62
- useEffect(() => {
63
- mystLiveReloadConnect({ port });
64
- }, []);
65
- return null;
66
- };
58
+ export function ContentReload({ port }: { port?: string | number }) {
59
+ useEffect(() => {
60
+ mystLiveReloadConnect({ port });
61
+ }, []);
62
+ return null;
63
+ }
@@ -1,7 +1,7 @@
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, useRef, useState } from 'react';
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
5
 
6
6
  const SELECTOR = [1, 2, 3, 4, 5, 6].map((n) => `main h${n}`).join(', ');
7
7
  const HIGHLIGHT_CLASS = 'highlight';
@@ -176,7 +176,7 @@ export function useOutlineHeight<T extends HTMLElement = HTMLElement>() {
176
176
  return () => {
177
177
  window.removeEventListener('scroll', handleScroll);
178
178
  };
179
- }, [container, outline, transitionState]);
179
+ }, [container.current, outline.current, transitionState]);
180
180
  return { container, outline };
181
181
  }
182
182
 
@@ -191,13 +191,18 @@ export const DocumentOutline = ({
191
191
  className?: string;
192
192
  }) => {
193
193
  const { activeId, headings, highlight } = useHeaders();
194
- if (headings.length <= 1) return <nav suppressHydrationWarning />;
194
+ if (headings.length <= 1 || !onClient) {
195
+ return <nav suppressHydrationWarning />;
196
+ }
195
197
  return (
196
198
  <nav
197
199
  ref={outlineRef}
198
200
  aria-label="Document Outline"
199
- suppressHydrationWarning
200
- className={classNames('not-prose transition-opacity overflow-y-auto', className)}
201
+ className={classNames(
202
+ 'not-prose overflow-y-auto hidden',
203
+ 'transition-opacity duration-700', // Animation on load
204
+ className,
205
+ )}
201
206
  style={{
202
207
  top: top ?? 0,
203
208
  maxHeight: `calc(100vh - ${(top ?? 0) + 20}px)`,
@@ -206,7 +211,7 @@ export const DocumentOutline = ({
206
211
  <div className="text-slate-900 mb-4 text-sm leading-6 dark:text-slate-100 uppercase">
207
212
  In this article
208
213
  </div>
209
- {onClient && <Headings headings={headings} activeId={activeId} highlight={highlight} />}
214
+ <Headings headings={headings} activeId={activeId} highlight={highlight} />
210
215
  </nav>
211
216
  );
212
217
  };
@@ -0,0 +1,64 @@
1
+ import { useThebeCore, useThebeServer, useThebeSession } from 'thebe-react';
2
+ import PowerIcon from '@heroicons/react/24/outline/PowerIcon';
3
+ import { useHasNotebookProvider } from '@myst-theme/jupyter';
4
+ import { useNavigation } from '@remix-run/react';
5
+ import { useEffect, useState } from 'react';
6
+
7
+ export function EnableCompute({
8
+ canCompute,
9
+ children,
10
+ }: React.PropsWithChildren<{ canCompute: boolean }>) {
11
+ const { load, loading, core } = useThebeCore();
12
+ const { connect, connecting, ready: serverReady, error: serverError } = useThebeServer();
13
+ const {
14
+ start,
15
+ starting,
16
+ shutdown,
17
+ session,
18
+ ready: sessionReady,
19
+ error: sessionError,
20
+ } = useThebeSession();
21
+ const hasNotebookProvider = useHasNotebookProvider();
22
+ const navigation = useNavigation();
23
+ const [enabling, setEnabling] = useState(false);
24
+ const [enabled, setEnabled] = useState(false);
25
+ const busy = enabling || loading || connecting || starting;
26
+
27
+ useEffect(() => {
28
+ if (!enabling) return;
29
+ if (!core) return load();
30
+ if (!serverReady) return connect();
31
+ if (!sessionReady) start();
32
+ if (sessionReady) {
33
+ setEnabled(true);
34
+ setEnabling(false);
35
+ }
36
+ }, [enabling, core, serverReady, sessionReady]);
37
+
38
+ if (!canCompute || !hasNotebookProvider) return null;
39
+ let classes = 'flex text-center mr-1 cursor-pointer rounded-full';
40
+ const idleClasses = 'text-blue-700 hover:opacity-100 opacity-60';
41
+ const busyClasses = 'bg-yellow-700 text-yellow-700 opacity-100 font-semibold';
42
+ const readyClasses = 'bg-green-700 text-green-700 opacity-100 font-semibold';
43
+ const errorClasses = 'bg-red-700 text-red-700 opacity-100';
44
+
45
+ if (busy) classes += busyClasses;
46
+ else if (serverReady && sessionReady) classes += readyClasses;
47
+ else if (serverError || sessionError) classes += errorClasses;
48
+ else classes += idleClasses;
49
+
50
+ useEffect(() => {
51
+ if (navigation.state === 'loading') {
52
+ shutdown();
53
+ }
54
+ }, [shutdown, navigation]);
55
+
56
+ return (
57
+ <div className="flex mx-1 items-center">
58
+ <button className={classes} onClick={() => setEnabling(true)} disabled={enabling || enabled}>
59
+ <PowerIcon className="h-6 w-6 mx-1 inline-block align-top" title="enable compute" />
60
+ </button>
61
+ {enabled && <>{children}</>}
62
+ </div>
63
+ );
64
+ }
@@ -1,4 +1,4 @@
1
- import { Link } from '@remix-run/react';
1
+ import { useLinkProvider } from '@myst-theme/providers';
2
2
 
3
3
  export function ExternalOrInternalLink({
4
4
  to,
@@ -15,6 +15,7 @@ export function ExternalOrInternalLink({
15
15
  title?: string;
16
16
  children: React.ReactNode;
17
17
  }) {
18
+ const Link = useLinkProvider();
18
19
  if (to.startsWith('http') || isStatic) {
19
20
  return (
20
21
  <a href={to} className={className} target="_blank" rel="noopener noreferrer" title={title}>
@@ -1,12 +1,12 @@
1
1
  import classNames from 'classnames';
2
- import { Link } from '@remix-run/react';
3
2
  import ArrowLeftIcon from '@heroicons/react/24/outline/ArrowLeftIcon';
4
3
  import ArrowRightIcon from '@heroicons/react/24/outline/ArrowRightIcon';
5
4
  import type { FooterLinks, NavigationLink } from '../types';
6
- import { useUrlbase, withUrlbase } from '@myst-theme/providers';
5
+ import { useLinkProvider, useUrlbase, withUrlbase } from '@myst-theme/providers';
7
6
 
8
7
  const FooterLink = ({ title, url, group, right }: NavigationLink & { right?: boolean }) => {
9
8
  const urlbase = useUrlbase();
9
+ const Link = useLinkProvider();
10
10
  return (
11
11
  <Link
12
12
  prefetch="intent"
@@ -1,4 +1,4 @@
1
- import { useTransition } from '@remix-run/react';
1
+ import { useNavigation } from '@remix-run/react';
2
2
  import { useEffect, useMemo, useState } from 'react';
3
3
  import classNames from 'classnames';
4
4
 
@@ -6,7 +6,7 @@ import classNames from 'classnames';
6
6
  * Show a loading progess bad if the load takes more than 150ms
7
7
  */
8
8
  function useLoading() {
9
- const transitionState = useTransition().state;
9
+ const transitionState = useNavigation().state;
10
10
  const ref = useMemo<{ start?: NodeJS.Timeout; finish?: NodeJS.Timeout }>(() => ({}), []);
11
11
  const [showLoading, setShowLoading] = useState(false);
12
12
 
@@ -138,6 +138,7 @@ export const TableOfContents = ({
138
138
  projectSlug?: string;
139
139
  footer?: React.ReactNode;
140
140
  }) => {
141
+ const footerRef = useRef<HTMLDivElement>(null);
141
142
  const [open] = useNavOpen();
142
143
  const config = useSiteManifest();
143
144
  const { folder, project } = useParams();
@@ -146,6 +147,13 @@ export const TableOfContents = ({
146
147
  const headings = getProjectHeadings(config, resolvedProjectSlug, {
147
148
  addGroups: false,
148
149
  });
150
+ useEffect(() => {
151
+ setTimeout(() => {
152
+ if (!footerRef.current) return;
153
+ footerRef.current.style.opacity = '1';
154
+ footerRef.current.style.transform = 'none';
155
+ }, 500);
156
+ }, [footerRef]);
149
157
  if (!headings) return null;
150
158
  return (
151
159
  <div
@@ -177,7 +185,14 @@ export const TableOfContents = ({
177
185
  >
178
186
  <Headings folder={resolvedProjectSlug} headings={headings} sections={config?.projects} />
179
187
  </nav>
180
- {footer && <div className="flex-none py-4">{footer}</div>}
188
+ {footer && (
189
+ <div
190
+ className="flex-none py-4 opacity-0 transition-all duration-700 translate-y-6"
191
+ ref={footerRef}
192
+ >
193
+ {footer}
194
+ </div>
195
+ )}
181
196
  </div>
182
197
  </div>
183
198
  );
@@ -1,4 +1,4 @@
1
- import { Link, NavLink } from '@remix-run/react';
1
+ import { NavLink } from '@remix-run/react';
2
2
  import { Fragment } from 'react';
3
3
  import classNames from 'classnames';
4
4
  import { Menu, Transition } from '@headlessui/react';
@@ -7,7 +7,7 @@ import MenuIcon from '@heroicons/react/24/solid/Bars3Icon';
7
7
  import ChevronDownIcon from '@heroicons/react/24/solid/ChevronDownIcon';
8
8
  import type { SiteManifest, SiteNavItem } from 'myst-config';
9
9
  import { ThemeButton } from './ThemeButton';
10
- import { useNavOpen, useSiteManifest } from '@myst-theme/providers';
10
+ import { useLinkProvider, useNavOpen, useSiteManifest } from '@myst-theme/providers';
11
11
  import { LoadingBar } from './Loading';
12
12
 
13
13
  export const DEFAULT_NAV_HEIGHT = 60;
@@ -25,6 +25,7 @@ function ExternalOrInternalLink({
25
25
  nav?: boolean;
26
26
  prefetch?: 'intent' | 'render' | 'none';
27
27
  }) {
28
+ const Link = useLinkProvider();
28
29
  const staticClass = typeof className === 'function' ? className({ isActive: false }) : className;
29
30
  if (to.startsWith('http') || to.startsWith('mailto:')) {
30
31
  return (
@@ -176,6 +177,7 @@ function ActionMenu({ actions }: { actions?: SiteManifest['actions'] }) {
176
177
  }
177
178
 
178
179
  function HomeLink({ logo, logoText, name }: { logo?: string; logoText?: string; name?: string }) {
180
+ const Link = useLinkProvider();
179
181
  const nothingSet = !logo && !logoText;
180
182
  return (
181
183
  <Link
@@ -0,0 +1,23 @@
1
+ export function Spinner({ size }: { size: number }) {
2
+ return (
3
+ <div role="status">
4
+ <svg
5
+ aria-hidden="true"
6
+ className={`w-[${size}px] h-[${size}px] mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-green-600`}
7
+ viewBox="0 0 100 101"
8
+ fill="none"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ >
11
+ <path
12
+ d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
13
+ fill="currentColor"
14
+ />
15
+ <path
16
+ d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
17
+ fill="currentFill"
18
+ />
19
+ </svg>
20
+ <span className="sr-only">Loading...</span>
21
+ </div>
22
+ );
23
+ }
@@ -1,26 +1,50 @@
1
- import { ReferencesProvider } from '@myst-theme/providers';
1
+ import React from 'react';
2
+ import { ReferencesProvider, useComputeOptions } from '@myst-theme/providers';
2
3
  import { FrontmatterBlock } from '@myst-theme/frontmatter';
3
4
  import { Bibliography, ContentBlocks, FooterLinksBlock } from '../components';
4
5
  import { ErrorDocumentNotFound } from './ErrorDocumentNotFound';
5
6
  import { ErrorProjectNotFound } from './ErrorProjectNotFound';
6
7
  import type { PageLoader } from '../types';
8
+ import { ThebeSessionProvider } from 'thebe-react';
9
+ import type { GenericParent } from 'myst-common';
10
+ import { SourceFileKind } from 'myst-common';
11
+ import { EnableCompute } from '../components/EnableCompute';
12
+ import { NotebookRunAll } from '../components/ComputeControls';
13
+ import { NotebookProvider, BinderBadge } from '@myst-theme/jupyter';
7
14
 
8
- export function ArticlePage({ article }: { article: PageLoader }) {
9
- const { hide_title_block, hide_footer_links } = (article.frontmatter as any)?.design ?? {};
15
+ export const ArticlePage = React.memo(function ({ article }: { article: PageLoader }) {
16
+ const computeOptions = useComputeOptions();
17
+ const canCompute = computeOptions.canCompute && (article.frontmatter as any)?.thebe !== false;
18
+ const { hide_title_block, hide_footer_links, binder } =
19
+ (article.frontmatter as any)?.design ?? {};
20
+ const isJupyter = article?.kind && article.kind === SourceFileKind.Notebook;
10
21
  return (
11
22
  <ReferencesProvider
12
23
  references={{ ...article.references, article: article.mdast }}
13
24
  frontmatter={article.frontmatter}
14
25
  >
15
- {!hide_title_block && (
16
- <FrontmatterBlock kind={article.kind} frontmatter={article.frontmatter} />
17
- )}
18
- <ContentBlocks mdast={article.mdast} />
19
- <Bibliography />
20
- {!hide_footer_links && <FooterLinksBlock links={article.footer} />}
26
+ <ThebeSessionProvider start={false} name={article.slug}>
27
+ {!hide_title_block && (
28
+ <FrontmatterBlock kind={article.kind} frontmatter={article.frontmatter} />
29
+ )}
30
+ <NotebookProvider siteConfig={false} page={article}>
31
+ <div className="flex items-center">
32
+ <div className="flex-grow"></div>
33
+ {binder && <BinderBadge binder={binder} />}
34
+ {canCompute && isJupyter && (
35
+ <EnableCompute canCompute={true} key={article.slug}>
36
+ <NotebookRunAll />
37
+ </EnableCompute>
38
+ )}
39
+ </div>
40
+ <ContentBlocks pageKind={article.kind} mdast={article.mdast as GenericParent} />
41
+ <Bibliography />
42
+ {!hide_footer_links && <FooterLinksBlock links={article.footer} />}
43
+ </NotebookProvider>
44
+ </ThebeSessionProvider>
21
45
  </ReferencesProvider>
22
46
  );
23
- }
47
+ });
24
48
 
25
49
  export function ProjectPageCatchBoundary() {
26
50
  return <ErrorProjectNotFound />;
@@ -16,20 +16,22 @@ import { ContentReload, renderers } from '../components';
16
16
  import { Analytics } from '../seo';
17
17
  import { ErrorSiteNotFound } from './ErrorSiteNotFound';
18
18
  import classNames from 'classnames';
19
+ import { ThebeCoreProvider } from 'thebe-react';
20
+ import { ConfiguredThebeServerProvider } from '@myst-theme/jupyter';
19
21
 
20
22
  export function Document({
21
23
  children,
24
+ scripts,
22
25
  theme,
23
26
  config,
24
27
  title,
25
- CONTENT_CDN_PORT,
26
28
  scrollTopClass = 'scroll-p-20',
27
29
  }: {
28
30
  children: React.ReactNode;
31
+ scripts?: React.ReactNode;
29
32
  theme: Theme;
30
33
  config?: SiteManifest;
31
34
  title?: string;
32
- CONTENT_CDN_PORT?: number | string;
33
35
  scrollTopClass?: string;
34
36
  }) {
35
37
  return (
@@ -47,21 +49,34 @@ export function Document({
47
49
  </head>
48
50
  <body className="m-0 transition-colors duration-500 bg-white dark:bg-stone-900">
49
51
  <ThemeProvider theme={theme} renderers={renderers} Link={RemixLink as any}>
50
- <SiteProvider config={config}>{children}</SiteProvider>
52
+ <ThebeCoreProvider>
53
+ <SiteProvider config={config}>
54
+ <ConfiguredThebeServerProvider>{children}</ConfiguredThebeServerProvider>
55
+ </SiteProvider>
56
+ </ThebeCoreProvider>
51
57
  </ThemeProvider>
52
58
  <ScrollRestoration />
53
59
  <Scripts />
54
60
  <LiveReload />
55
- <ContentReload port={CONTENT_CDN_PORT} />
61
+ {scripts}
56
62
  </body>
57
63
  </html>
58
64
  );
59
65
  }
60
66
 
61
67
  export function App() {
68
+ const { theme, config } = useLoaderData<SiteLoader>();
69
+ return (
70
+ <Document theme={theme} config={config}>
71
+ <Outlet />
72
+ </Document>
73
+ );
74
+ }
75
+
76
+ export function AppWithReload() {
62
77
  const { theme, config, CONTENT_CDN_PORT } = useLoaderData<SiteLoader>();
63
78
  return (
64
- <Document theme={theme} config={config} CONTENT_CDN_PORT={CONTENT_CDN_PORT}>
79
+ <Document theme={theme} config={config} scripts={<ContentReload port={CONTENT_CDN_PORT} />}>
65
80
  <Outlet />
66
81
  </Document>
67
82
  );
@@ -2,4 +2,4 @@ export { ErrorProjectNotFound } from './ErrorProjectNotFound';
2
2
  export { ErrorDocumentNotFound } from './ErrorDocumentNotFound';
3
3
  export { ErrorSiteNotFound } from './ErrorSiteNotFound';
4
4
  export { ArticlePage, ArticlePageCatchBoundary, ProjectPageCatchBoundary } from './Article';
5
- export { App, Document, AppCatchBoundary, AppDebugErrorBoundary } from './Root';
5
+ export { App, AppWithReload, Document, AppCatchBoundary, AppDebugErrorBoundary } from './Root';