import "./Breadcrumb.css"; import { useMemo } from "preact/hooks"; import { Fragment } from "preact/jsx-runtime"; import NoteContext from "../components/note_context"; import froca from "../services/froca"; import ActionButton from "./react/ActionButton"; import Dropdown from "./react/Dropdown"; import { FormListItem } from "./react/FormList"; import { useChildNotes, useNoteContext, useNoteLabel, useNoteProperty } from "./react/hooks"; import Icon from "./react/Icon"; import NoteLink from "./react/NoteLink"; import link_context_menu from "../menus/link_context_menu"; const COLLAPSE_THRESHOLD = 5; const INITIAL_ITEMS = 2; const FINAL_ITEMS = 2; export default function Breadcrumb() { const { note, noteContext } = useNoteContext(); const notePath = buildNotePaths(noteContext?.notePathArray); return (
{notePath.length > COLLAPSE_THRESHOLD ? ( <> {notePath.slice(0, INITIAL_ITEMS).map((item, index) => ( {index === 0 ? : } ))} {notePath.slice(-FINAL_ITEMS).map((item, index) => ( ))} ) : ( notePath.map((item, index) => ( {index === 0 ? : } {(index < notePath.length - 1 || note?.hasChildren()) && } )) )}
); } function BreadcrumbRoot({ noteContext }: { noteContext: NoteContext | undefined }) { const note = useMemo(() => froca.getNoteFromCache("root"), []); useNoteLabel(note, "iconClass"); const title = useNoteProperty(note, "title"); return (note && noteContext?.setNote("root")} onContextMenu={(e) => { e.preventDefault(); link_context_menu.openContextMenu(note.noteId, e); }} /> ); } function BreadcrumbItem({ notePath }: { notePath: string }) { return ( ); } function BreadcrumbSeparator({ notePath, noteContext, activeNotePath }: { notePath: string, activeNotePath: string, noteContext: NoteContext | undefined }) { return ( } noSelectButtonStyle buttonClassName="icon-action" hideToggleArrow dropdownOptions={{ popperConfig: { strategy: "fixed" } }} > ); } function BreadcrumbSeparatorDropdownContent({ notePath, noteContext, activeNotePath }: { notePath: string, activeNotePath: string, noteContext: NoteContext | undefined }) { const notePathComponents = notePath.split("/"); const parentNoteId = notePathComponents.at(-1); const childNotes = useChildNotes(parentNoteId); return ( ); } function BreadcrumbCollapsed({ items, noteContext }: { items: string[], noteContext: NoteContext | undefined }) { return ( } noSelectButtonStyle buttonClassName="icon-action" hideToggleArrow dropdownOptions={{ popperConfig: { strategy: "fixed" } }} >
    {items.map((notePath) => { const notePathComponents = notePath.split("/"); const noteId = notePathComponents[notePathComponents.length - 1]; const note = froca.getNoteFromCache(noteId); if (!note) return null; return
  • noteContext?.setNote(notePath)} > {note.title}
  • ; })}
); } function buildNotePaths(notePathArray: string[] | undefined) { if (!notePathArray) return []; let prefix = ""; const output: string[] = []; for (const notePath of notePathArray) { output.push(`${prefix}${notePath}`); prefix += `${notePath}/`; } return output; }