/** The top bar (where the reader is, and whether it is saved) and the documents menu it opens (m). */
import { useLayoutEffect, useRef, useState } from "preact/hooks";
import { clip } from "../core/text";
import { topEntries } from "./actions";
import { Hints, act, showMenu } from "./Mouse";
import { press } from "./press";
import { store } from "./store";
/** A press on a tool keeps the focus where it was (the keys stay with the page). */
const keep = (e: MouseEvent) => e.preventDefault();
const SAVE_LABEL = { saved: "saved", saving: "saving…", offline: "offline · kept in this browser", foreign: "not saved · reload the page" };
const SAVE_TITLE = {
saved: "Every edit is saved as you make it. The server has all of them.",
saving: "Every edit is saved as you make it. The latest are on their way to the server.",
offline: "The server cannot be reached. Edits are kept in this browser and sent when it can.",
foreign: "The server now holds a different library than this page.",
};
export function DocBar() {
const state = store.saveState();
const here = store.currentDoc;
const snap = store.snap;
return (
);
}
function TitlePrompt() {
const p = store.menu.prompt!;
const label = { new: "New document, titled", rename: "Rename to", duplicate: "Save a copy as" }[p.kind];
return (
);
}
export function DocsPanel() {
const m = store.menu;
const items = store.menuItems();
const sel = store.menuSelected();
const current = store.currentDoc;
const ref = useRef(null);
const [dropping, setDropping] = useState(false);
useLayoutEffect(() => {
ref.current?.querySelector(".doc.selected")?.scrollIntoView({ block: "nearest" });
});
const typing = m.focus === "filter" && !m.prompt && !m.confirm;
const act = (fn: () => void) => (e: MouseEvent) => {
e.stopPropagation();
fn();
};
return (
);
}