Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/thebe v2 - interactive figures in articles #136

Merged
merged 56 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ca326e2
🤔wip
stevejpurves Jun 29, 2023
64b6a32
🤺 basic scope persisted across navigation
stevejpurves Jun 29, 2023
00a9460
👷🏽build requests
stevejpurves Jun 29, 2023
b5c57eb
🛤 parallel builds
stevejpurves Jun 29, 2023
f52df10
📡 fetching dependency mdast on demand
stevejpurves Jun 29, 2023
74f22e5
🗺fix navigation logic
stevejpurves Jun 29, 2023
a5efd80
🍱 prepping for notebook build step
stevejpurves Jun 29, 2023
2e32add
🔧 use standard selector arg ordering
stevejpurves Jun 29, 2023
5741d21
🪐 move to jupyter package
stevejpurves Jun 29, 2023
09e4e11
🎥📒 notebook and rendermime added to scope
stevejpurves Jun 29, 2023
efde2c1
🐐ready for session start
stevejpurves Jun 29, 2023
9ae03d8
🖥 server started & beginning session startup
stevejpurves Jun 29, 2023
b67ac7d
🚀 sessions are started
stevejpurves Jun 29, 2023
0dad078
🧲 cells attach to the DOM in articles
stevejpurves Jun 29, 2023
bf3fa3e
⚡️ execution
stevejpurves Jun 29, 2023
c6cd741
🙏 session creation happening as expected
stevejpurves Jun 29, 2023
0ba558b
🏗 loading core on demand
stevejpurves Jun 29, 2023
f341a1d
🛟 outputs from execution are preserved across navigation
stevejpurves Jun 29, 2023
8b1e7f3
🎚reset all
stevejpurves Jun 29, 2023
cbd6654
🪝extended execution hooks
stevejpurves Jun 29, 2023
7f9a39a
🚥 start of toolbar UI
stevejpurves Jun 29, 2023
376b86d
🎛 notebook UI controls
stevejpurves Jun 29, 2023
52d6e16
🏃‍♀️autorun
stevejpurves Jun 29, 2023
dbbde15
♻️ session restarts on reconnect
stevejpurves Jun 29, 2023
0a6eb0e
🕵️‍♀️ debug not log
stevejpurves Jun 29, 2023
1052db1
🎒port to new exec scope provider
stevejpurves Jun 29, 2023
428731d
☎️ button uniformity
stevejpurves Jun 29, 2023
f255251
📤 adding connection tray back in
stevejpurves Jun 29, 2023
db667a3
⏭towards immediate execution
stevejpurves Jun 29, 2023
deec502
📚z index change for toc
stevejpurves Jun 30, 2023
ae21e3c
⏳busy status 1
stevejpurves Jun 30, 2023
0d187dd
🚀 launch is back
stevejpurves Jun 30, 2023
7ce280c
🕹some controls available on figures
stevejpurves Jun 30, 2023
b4e5b05
☎️ meaningful article controls
stevejpurves Jun 30, 2023
455ec5e
🎛 buttons
stevejpurves Jun 30, 2023
fcee577
🛠 fix bad var name
stevejpurves Jul 3, 2023
afd973d
🧥load thebe styles again
stevejpurves Jul 3, 2023
45b3778
👊🏽 📦🔒pumb `thebe` packages to get unpatched styles
stevejpurves Jul 3, 2023
94a0ba7
🔧 fixed power in individual figures
stevejpurves Jul 3, 2023
66c2bbe
🔧 fix reset behaviour
stevejpurves Jul 3, 2023
2607ff7
🛠fix resetall
stevejpurves Jul 3, 2023
60df62b
💭renaming
stevejpurves Jul 3, 2023
c526827
👔 final styles
stevejpurves Jul 3, 2023
0ec804c
♻ busy status on restarts
stevejpurves Jul 3, 2023
8d5be08
🌗dark mode
stevejpurves Jul 3, 2023
d835a1e
🐑 lint
stevejpurves Jul 3, 2023
2e5a7b5
🌀 reinstate binder badge and frontmatter block
stevejpurves Jul 3, 2023
59cfc66
⚠️ added error tray component
stevejpurves Jul 3, 2023
c20e74d
💚 tests green
stevejpurves Jul 3, 2023
3eeb188
📖 Table of contents indent for index page
rowanc1 Jul 3, 2023
2fcb4b8
👆 `pointer-events-none` on execute controls
rowanc1 Jul 3, 2023
705088a
📦 Fix tsconfig
rowanc1 Jul 3, 2023
2e9e504
📦 Make vitest stop when running `test`.
rowanc1 Jul 3, 2023
6292f0a
🤫 Remove console logs
rowanc1 Jul 3, 2023
9067da0
⎌ Revert z-index change
rowanc1 Jul 3, 2023
d44ea52
📖 Update error message
rowanc1 Jul 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-trees-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@myst-theme/site': patch
---

Fix the table of contents indentation
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions packages/jupyter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"build:esm": "tsc --module es2020 --outDir dist/esm",
"build:types": "tsc --declaration --emitDeclarationOnly --declarationMap --outDir dist/types",
"build": "npm-run-all -l clean -p build:cjs build:esm build:types",
"test": "vitest run"
"test": "vitest",
"test:ci": "vitest --ci"
},
"dependencies": {
"@headlessui/react": "^1.7.15",
Expand All @@ -30,20 +31,20 @@
"myst-config": "^1.0.0",
"myst-frontmatter": "^1.0.0",
"myst-spec": "^0.0.4",
"myst-to-react": "^0.3.2",
"nanoid": "^4.0.2",
"nbtx": "^0.2.3",
"react-syntax-highlighter": "^15.5.0",
"swr": "^2.1.5",
"thebe-core": "^0.2.5",
"thebe-lite": "^0.2.5",
"thebe-react": "^0.2.5",
"thebe-core": "^0.2.6",
"thebe-lite": "^0.2.6",
"thebe-react": "^0.2.6",
"unist-util-select": "^4.0.3"
},
"peerDependencies": {
"@types/react": "^16.8 || ^17.0 || ^18.0",
"@types/react-dom": "^16.8 || ^17.0 || ^18.0",
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0"
},
"devDependencies": {}
}
}
12 changes: 7 additions & 5 deletions packages/jupyter/src/ConnectionStatusTray.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { useEffect, useState } from 'react';
import { useThebeServer, useThebeSession } from 'thebe-react';
import { useThebeServer } from 'thebe-react';
import { useComputeOptions } from './providers';
import type { ThebeEventData, ThebeEventType } from 'thebe-core';
import { selectAreExecutionScopesBuilding, useExecutionScope } from './execute';

export function ConnectionStatusTray() {
const { thebe } = useComputeOptions();
const { connecting, ready: serverReady, error: serverError, events } = useThebeServer();
const { starting, ready: sessionReady, error: sessionError } = useThebeSession();
const { slug, ready: scopeReady, state } = useExecutionScope();
const [show, setShow] = useState(false);
const [unsub, setUnsub] = useState<() => void | undefined>();
const [status, setStatus] = useState<string>('[client] Connecting...');

const error = serverError || sessionError;
const ready = serverReady && sessionReady;
const busy = connecting || starting;
const error = serverError; // TODO scope bulding error handling || sessionError;
const ready = serverReady && scopeReady;
const busy = connecting || selectAreExecutionScopesBuilding(state, slug);

const handleStatus = (event: any, data: ThebeEventData) => {
setStatus(`[${data.subject}]: ${data.message}`);
Expand Down Expand Up @@ -44,6 +45,7 @@ export function ConnectionStatusTray() {

const host = thebe?.useBinder ? 'Binder' : thebe?.useJupyterLite ? 'JupyterLite' : 'Local Server';

// TODO radix ui toast!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward to this. :)

if (show && error) {
return (
<div className="fixed p-3 text-sm text-gray-700 bg-white border rounded shadow-lg bottom-2 sm:right-2 max-w-[90%] md:max-w-[300px] min-w-0">
Expand Down
62 changes: 62 additions & 0 deletions packages/jupyter/src/ErrorTray.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { useEffect, useState } from 'react';
import type { PassiveCellRenderer } from 'thebe-core';
import type { IThebeNotebookError } from 'thebe-react';
import { useThebeLoader } from 'thebe-react';

function ErrorDecoration({ children, idx }: React.PropsWithChildren<{ idx?: number }>) {
return (
<div className="relative py-3 mx-2 my-8 border rounded">
<div className="absolute z-10 flex items-center bg-white -top-3 -left-2">
{idx && <div className="ml-1 text-sm text-gray-500">cell #: {idx}</div>}
</div>
<div className="mx-3">{children}</div>
</div>
);
}

function ErrorTrayMessage({ errors }: { errors: IThebeNotebookError[] }) {
const { core } = useThebeLoader();

const [cells, setCells] = useState<PassiveCellRenderer[]>([]);
const [refs, setRefs] = useState<((node: HTMLDivElement) => void)[]>([]);

useEffect(() => {
if (!core) return;
const cs = errors.map(() => new core.PassiveCellRenderer('any'));
setRefs(
errors.map((_, idx) => (node: any) => {
if (node) {
cs[idx].attachToDOM(node);
cs[idx].render(errors[idx].error ?? []);
}
}),
);
setCells(cells);
}, [core, errors]);

if (!core) return null;
return (
<div>
{errors.map((error, idx) => (
<div className="min-w-[400px]">
<ErrorDecoration idx={error.index}>
<div className="z-100" key={error.id} ref={refs[idx]}></div>
</ErrorDecoration>
</div>
))}
</div>
);
}

export function ErrorTray({ errors }: { errors: IThebeNotebookError[] }) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should also be radix in the future.

return (
<div className="relative px-4 pt-3 mt-8 text-sm text-red-600 border border-red-400 rounded border-1">
<div>
<span className="font-bold">Error</span> - a page refresh may resolve this. If not, shutdown
this simulation and start another. If the error persists please contact support with a
screenshot of this page, including the error message below.
</div>
<ErrorTrayMessage errors={errors} />
</div>
);
}
54 changes: 54 additions & 0 deletions packages/jupyter/src/controls/ArticleCellControls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useThebeServer } from 'thebe-react';
import { useNotebookExecution } from '../execute/hooks';
import { Reset, Run, SpinnerStatusButton } from './Buttons';

import { selectAreExecutionScopesBuilding } from '../execute';

export function ArticleStatusBadge({ id }: { id: string }) {
const { connect, connecting } = useThebeServer();
const { slug, state, start, ready, executionCount } = useNotebookExecution(id);

const building = selectAreExecutionScopesBuilding(state, slug);

const handleStart = () => {
connect();
start();
};

return (
<SpinnerStatusButton
ready={ready}
busy={building || connecting}
modified={executionCount != null}
onClick={handleStart}
/>
);
}

export function ArticleRunNotebook({ id }: { id: string }) {
const { ready, cellIsExecuting, notebookIsBusy, execute } = useNotebookExecution(id);
if (!ready) return null;
return (
<Run
ready={ready}
executing={cellIsExecuting}
disabled={notebookIsBusy}
onClick={execute}
title="Run the notebook that creates this figure"
/>
);
}

export function ArticleResetNotebook({ id }: { id: string }) {
const { ready, notebookIsResetting, notebookIsBusy, reset } = useNotebookExecution(id);
if (!ready) return null;
return (
<Reset
ready={ready}
resetting={notebookIsResetting}
disabled={notebookIsBusy}
onClick={reset}
title="Reset the figure to its original state and restart the kernel"
/>
);
}
Loading