Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(launcher): open launch bar config subtree in a tree popup
Elian Dorand48173a1060c
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex 71d5a76f4f..f44b192743 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -139,6 +139,7 @@ export type CommandMappings = {openNewNoteSplit: NoteCommandData;openInWindow: NoteCommandData;openInPopup: CommandData & { noteIdOrPath: string; };+ openInTreePopup: CommandData & { noteIdOrPath: string; hoistedNoteId: string; };openNoteInNewTab: CommandData;openNoteInNewSplit: CommandData;openNoteInNewWindow: CommandData;diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.tsindex a62c092cd5..aaaa09493e 100644--- a/apps/client/src/components/root_command_executor.ts+++ b/apps/client/src/components/root_command_executor.ts@@ -101,8 +101,7 @@ export default class RootCommandExecutor extends Component {async showLaunchBarSubtreeCommand() {const rootNote = utils.isMobile() ? "_lbMobileRoot" : "_lbRoot";- await this.showAndHoistSubtree(rootNote);- this.showLeftPaneCommand();+ appContext.triggerCommand("openInTreePopup", { noteIdOrPath: rootNote, hoistedNoteId: rootNote });}async showShareSubtreeCommand() {diff --git a/apps/client/src/layouts/layout_commons.tsx b/apps/client/src/layouts/layout_commons.tsxindex 4f527e56a8..176a08b31f 100644--- a/apps/client/src/layouts/layout_commons.tsx+++ b/apps/client/src/layouts/layout_commons.tsx@@ -38,6 +38,7 @@ export function applyModals(rootContainer: RootContainer) {.child(<LazyDialog triggerEvents={["showOptions"]} loader={() => import("../widgets/dialogs/OptionsDialog.jsx")} />).child(<LazyDialog triggerEvents={["showOcrTextDialog"]} loader={() => import("../widgets/dialogs/ocr_text.js")} />).child(<LazyDialog triggerEvents={["showUploadAttachmentsDialog"]} loader={() => import("../widgets/dialogs/upload_attachments.js")} />)+ .child(<LazyDialog triggerEvents={["openInTreePopup"]} loader={() => import("../widgets/dialogs/TreePopupEditor.jsx")} />)// The following three are deliberately eager (not wrapped in LazyDialog):// - PopupEditor keeps itself in the DOM (`keepInDom`) for fast hover-preview latency, so deferring its module would defeat the purpose.// - CallToAction has no summon event; it decides whether to show itself on startup, so there is nothing to lazily mount against.diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 749daa282c..2e2fb0f8a3 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2456,6 +2456,9 @@"popup-editor": {"maximize": "Switch to full editor"},+ "tree-popup": {+ "title": "Configure"+ },"server": {"unknown_http_error_title": "Communication error with the server","unknown_http_error_content": "Status code: {{statusCode}}\nURL: {{method}} {{url}}\nMessage: {{message}}",diff --git a/apps/client/src/widgets/dialogs/TreePopupEditor.css b/apps/client/src/widgets/dialogs/TreePopupEditor.cssnew file mode 100644index 0000000000..c0a5f3e1f7--- /dev/null+++ b/apps/client/src/widgets/dialogs/TreePopupEditor.css@@ -0,0 +1,31 @@+.modal.tree-popup-editor-dialog .modal-dialog {+ width: 90vw;+ max-width: 1100px;+ height: 80vh;+}++.modal.tree-popup-editor-dialog .modal-content {+ height: 80vh;+}++/* Sidebar holding the hoisted note tree. */+.modal.tree-popup-editor-dialog .modal-sidebar {+ width: 300px;+}++.modal.tree-popup-editor-dialog .tree-popup-sidebar {+ flex-grow: 1;+ min-height: 0;+ overflow: auto;+}++.modal.tree-popup-editor-dialog .tree-popup-sidebar .fancytree-container {+ height: 100%;+}++.modal.tree-popup-editor-dialog .tree-popup-editor-title {+ display: flex;+ align-items: center;+ gap: 0.35em;+ margin-bottom: 0.5em;+}diff --git a/apps/client/src/widgets/dialogs/TreePopupEditor.tsx b/apps/client/src/widgets/dialogs/TreePopupEditor.tsxnew file mode 100644index 0000000000..0131a7fe2f--- /dev/null+++ b/apps/client/src/widgets/dialogs/TreePopupEditor.tsx@@ -0,0 +1,79 @@+import "./TreePopupEditor.css";++import { useCallback, useContext, useRef, useState } from "preact/hooks";++import appContext from "../../components/app_context";+import NoteContext from "../../components/note_context";+import { t } from "../../services/i18n";+import NoteTreeWidget from "../note_tree";+import NoteDetail from "../NoteDetail";+import PromotedAttributes from "../PromotedAttributes";+import { useContainedLinkNavigation, useLegacyWidget, useTriliumEvent } from "../react/hooks";+import Modal from "../react/Modal";+import { NoteContextContext, ParentComponent } from "../react/react_utils";+import { TitleRow } from "./PopupEditor";++/**+ * PoC: a quick-edit-style popup whose sidebar is a hoisted note tree.+ *+ * Summoned via the `openInTreePopup` command with a `noteIdOrPath` to open and a `hoistedNoteId`+ * to scope the sidebar tree to. Used to open the launch-bar configuration subtree in a modal+ * (with the same hoisting it would get in a dedicated tab) instead of a separate tab.+ */+export default function TreePopupEditor() {+ const [ shown, setShown ] = useState(false);+ const parentComponent = useContext(ParentComponent);+ const [ noteContext, setNoteContext ] = useState(() => new NoteContext("_tree-popup"));+ const modalRef = useRef<HTMLDivElement>(null);++ useTriliumEvent("openInTreePopup", async ({ noteIdOrPath, hoistedNoteId }) => {+ // Fresh context per open so the sidebar tree is hoisted to the requested subtree.+ const newContext = new NoteContext("_tree-popup", hoistedNoteId);+ await newContext.setNote(noteIdOrPath, { keepActiveDialog: true });++ // Events triggered at note-context level (e.g. the save indicator) would not work since this+ // context has no parent component. Propagate them so they can be handled properly.+ newContext.triggerEvent = (name, data) => parentComponent?.handleEventInChildren(name, data);++ setNoteContext(newContext);+ setShown(true);+ });++ // Keep navigation that follows internal links inside the popup, rather than letting the global+ // link handler open the target in the background tab. Links that stay within the hoisted subtree+ // navigate the modal's own context; links pointing outside it can't be shown in the hoisted+ // context, so they fall back to the quick-edit popup.+ useContainedLinkNavigation(modalRef, useCallback((notePath, viewScope) => {+ if (notePath.split("/").includes(noteContext.hoistedNoteId)) {+ void noteContext.setNote(notePath, { viewScope, keepActiveDialog: true });+ } else {+ void appContext.triggerCommand("openInPopup", { noteIdOrPath: notePath });+ }+ }, [ noteContext ]));++ return (+ <NoteContextContext.Provider value={noteContext}>+ <Modal+ modalRef={modalRef}+ title={t("tree-popup.title")}+ className="tree-popup-editor-dialog"+ size="xl"+ sidebar={<TreeSidebar noteContext={noteContext} />}+ show={shown}+ onShown={() => parentComponent?.handleEvent("focusOnDetail", { ntxId: noteContext.ntxId })}+ onHidden={() => setShown(false)}+ scrollable+ stackable+ >+ <div className="tree-popup-editor-title"><TitleRow /></div>+ <PromotedAttributes />+ <NoteDetail />+ </Modal>+ </NoteContextContext.Provider>+ );+}++function TreeSidebar({ noteContext }: { noteContext: NoteContext }) {+ const [ treeEl ] = useLegacyWidget(() => new NoteTreeWidget(), { noteContext });+ return <div className="tree-popup-sidebar">{treeEl}</div>;+}diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.tsindex e1a3c9dc8c..4314ee4df7 100644--- a/apps/client/src/widgets/note_tree.ts+++ b/apps/client/src/widgets/note_tree.ts@@ -457,11 +457,19 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {const notePath = treeService.getNotePath(data.node);- const activeNoteContext = appContext.tabManager.getActiveContext();+ // Prefer the context this tree is bound to (e.g. a popup editor with its own+ // hoisted context) over the globally active tab. For the main sidebar tree the+ // bound context already is the active context, so behaviour is unchanged there.+ const activeNoteContext = this.noteContext ?? appContext.tabManager.getActiveContext();const opts: SetNoteOpts = {};if (activeNoteContext?.viewScope?.viewMode === "contextual-help") {opts.viewScope = activeNoteContext.viewScope;}+ // When this tree drives a context other than the active tab (e.g. one embedded in a+ // popup editor), keep any open dialog so navigating the tree doesn't dismiss the popup.+ if (activeNoteContext && activeNoteContext !== appContext.tabManager.getActiveContext()) {+ opts.keepActiveDialog = true;+ }await activeNoteContext?.setNote(notePath, opts);},expand: (event, data) => this.setExpanded(data.node.data.branchId, true),