feat(web): add shell-first runbook UI and mock demo (#2)
Add notebook parameters, literal highlighted scripts, copy helpers, streamed runs, host-key confirmation, artifacts, conditional notes, login and optimistic Markdown editing. Keep the temporary core renderer isolated to mock mode. Use React and Vite for the UI, react-markdown for safe Markdown rendering, highlight.js for shell syntax, and CodeMirror 6 for Markdown editing. Add Testing Library, jsdom and Vitest for component and event-state coverage. Validate pnpm install, root typecheck and test (29 web tests, 1 server test), plus normal and mock web builds. Core contracts remain unchanged; real backend execution awaits the parallel core/server implementations.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { basicSetup } from "codemirror";
|
||||
import { markdown } from "@codemirror/lang-markdown";
|
||||
|
||||
export function Editor({
|
||||
source,
|
||||
onChange,
|
||||
}: {
|
||||
source: string;
|
||||
onChange(source: string): void;
|
||||
}) {
|
||||
const root = useRef<HTMLDivElement>(null);
|
||||
const change = useRef(onChange);
|
||||
change.current = onChange;
|
||||
useEffect(() => {
|
||||
const view = new EditorView({
|
||||
doc: source,
|
||||
parent: root.current!,
|
||||
extensions: [
|
||||
basicSetup,
|
||||
markdown(),
|
||||
EditorView.lineWrapping,
|
||||
EditorView.contentAttributes.of({ "aria-label": "Notebook Markdown" }),
|
||||
EditorView.updateListener.of((update) => {
|
||||
if (update.docChanged) change.current(update.state.doc.toString());
|
||||
}),
|
||||
],
|
||||
});
|
||||
return () => view.destroy();
|
||||
// Editor lifetime matches edit mode. Parent remounts after reload.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
return <div className="editor" ref={root} />;
|
||||
}
|
||||
Reference in New Issue
Block a user