feat(notebooks): manage and author notebooks in the web UI (#9)
Add atomic, versioned notebook mutations, a searchable folder tree, and editor insertion forms. Validate notebook paths and symlink roots and retain drafts after external changes. Add yaml as a direct web dependency, reusing the existing workspace library for comment-preserving frontmatter edits.
This commit is contained in:
+28
-2
@@ -1,3 +1,4 @@
|
||||
import { AuthoringToolbar } from "./AuthoringToolbar";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { basicSetup } from "codemirror";
|
||||
@@ -10,6 +11,7 @@ export function Editor({
|
||||
source: string;
|
||||
onChange(source: string): void;
|
||||
}) {
|
||||
const editor = useRef<EditorView>();
|
||||
const root = useRef<HTMLDivElement>(null);
|
||||
const change = useRef(onChange);
|
||||
change.current = onChange;
|
||||
@@ -27,9 +29,33 @@ export function Editor({
|
||||
}),
|
||||
],
|
||||
});
|
||||
return () => view.destroy();
|
||||
editor.current = view;
|
||||
return () => {
|
||||
editor.current = undefined;
|
||||
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} />;
|
||||
return (
|
||||
<>
|
||||
<AuthoringToolbar
|
||||
source={source}
|
||||
insert={(text) => {
|
||||
const view = editor.current;
|
||||
if (!view) return;
|
||||
view.dispatch(view.state.replaceSelection(text));
|
||||
view.focus();
|
||||
}}
|
||||
replace={(text) => {
|
||||
const view = editor.current;
|
||||
if (!view) return;
|
||||
view.dispatch({
|
||||
changes: { from: 0, to: view.state.doc.length, insert: text },
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<div className="editor" ref={root} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user