Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): edit an attribute on a page of its own on a phone

Elian Doran84c72bd86441
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index abd914a8ff..600c5aaaf4 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -798,6 +798,7 @@
"definitions_other": "{{count}} definitions",
"internal_one": "{{count}} internal system attribute",
"internal_other": "{{count}} internal system attributes",
+ "back": "Back to the attributes",
"inheritable": "Inheritable: applies to this note and to its whole subtree",
"delete": "Delete this attribute",
"delete_confirm": "Delete the attribute \"{{name}}\"?",
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
index 6e18924da3..a351c918b1 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
@@ -327,10 +327,12 @@ interface AttributeFormCallbacks {
}
/**
- * The editable part of the popup. Remounted per show (keyed on `showId`) so the field state is
- * simply seeded from the attribute instead of being synchronized to it on every change.
+ * The editable part of the popup, and of whatever else edits an attribute — a pane of a master-detail
+ * modal shows the same form, having no room to float one over itself. Remounted per show (keyed on
+ * `showId`) so the field state is simply seeded from the attribute instead of being synchronized to it
+ * on every change.
*/
-function AttributeForm({ opts, attrType: initialAttrType, currentNoteId, onCancel, onAttributesChanged, onSaveAndClose, onDelete }: AttributeFormCallbacks & {
+export function AttributeForm({ opts, attrType: initialAttrType, currentNoteId, onCancel, onAttributesChanged, onSaveAndClose, onDelete }: AttributeFormCallbacks & {
opts: AttributeDetailOpts;
attrType: AttrType;
currentNoteId?: string | null;
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.css b/apps/client/src/widgets/dialogs/OptionsDialog.css
index d8a1c33ada..c07f05e66e 100644
--- a/apps/client/src/widgets/dialogs/OptionsDialog.css
+++ b/apps/client/src/widgets/dialogs/OptionsDialog.css
@@ -63,151 +63,25 @@ body.mobile .modal.options-dialog:not(.mobile-master-detail) .modal-dialog {
height: 90vh;
}
-/* On narrow mobile viewports the dialog becomes a master-detail flow instead of the sidebar
- layout (the `mobile-master-detail` class tracks this): the page selector is rendered as a pane
- inside the modal body (the Modal sidebar is unused), so the list and the page can slide over
- each other when switching between them. */
-body.mobile .modal.options-dialog.mobile-master-detail .modal-content .modal-body {
- position: relative;
- padding: 0;
- /* The panes scroll themselves; this also keeps the sliding panes contained. */
- overflow: hidden;
-}
-
-body.mobile .modal.options-dialog .options-mobile-nav {
- height: 100%;
- overflow: auto;
- padding: 8px 25px;
-}
-
-body.mobile .modal.options-dialog.mobile-master-detail .note-detail {
- height: 100%;
- overflow: auto;
-}
-
-/* At rest only the active pane is displayed; during a transition both stay visible so the
- outgoing pane can slide away as the incoming one slides in. */
-body.mobile .modal.options-dialog.mobile-master-detail.mobile-view-list:not(.mobile-transition-to-list) .note-detail {
- display: none;
-}
-
-body.mobile .modal.options-dialog.mobile-master-detail.mobile-view-page:not(.mobile-transition-to-page) .options-mobile-nav {
- display: none;
-}
-
-body.mobile .modal.options-dialog .modal-header {
- border-bottom: 1px solid var(--main-border-color);
-}
-
-/* The back button + page title in the custom header replace the static "Options" title. */
-body.mobile .modal.options-dialog.mobile-master-detail .modal-header > .modal-title {
- display: none;
-}
-
-/* Directional slide mirroring the setup wizard's page animation: opening a page, the list slides
- out towards the start side while the page slides in from the end side; going back reverses the
- directions. The page pane stacks above the list, and `forwards` holds the outgoing pane at its
- off-screen position until the transition classes are removed after animationend. The global
- `motion-disabled` rule suppresses the animations entirely; the dialog then switches views
- directly without entering a transition. */
-body.mobile .modal.options-dialog.mobile-master-detail.mobile-transition-to-page,
-body.mobile .modal.options-dialog.mobile-master-detail.mobile-transition-to-list {
- .options-mobile-nav,
- .note-detail {
- position: absolute;
- inset: 0;
- background-color: var(--modal-background-color);
- }
-
- .note-detail {
- z-index: 1;
- }
-}
-
-body.mobile .modal.options-dialog.mobile-master-detail.mobile-transition-to-page {
- .note-detail {
- animation: options-slide-in-end 0.35s ease-in-out forwards;
+/* The master-detail flow itself is the shared one (master_detail.css); what is particular here is the
+ page selector's own padding, and the settings page filling the pane it is wrapped in. */
+body.mobile .modal.options-dialog.mobile-master-detail {
+ .modal-body {
+ padding: 0;
}
.options-mobile-nav {
- animation: options-slide-out-start 0.35s ease-in-out forwards;
+ padding: 8px 25px;
}
-}
-body.mobile .modal.options-dialog.mobile-master-detail.mobile-transition-to-list {
.note-detail {
- animation: options-slide-out-end 0.35s ease-in-out forwards;
- }
-
- .options-mobile-nav {
- animation: options-slide-in-start 0.35s ease-in-out forwards;
- }
-}
-
-body[dir=rtl].mobile .modal.options-dialog.mobile-master-detail.mobile-transition-to-page {
- .note-detail {
- animation-name: options-slide-in-start;
- }
-
- .options-mobile-nav {
- animation-name: options-slide-out-end;
- }
-}
-
-body[dir=rtl].mobile .modal.options-dialog.mobile-master-detail.mobile-transition-to-list {
- .note-detail {
- animation-name: options-slide-out-start;
- }
-
- .options-mobile-nav {
- animation-name: options-slide-in-end;
+ height: 100%;
+ overflow: auto;
}
}
-@keyframes options-slide-in-end {
- from { transform: translateX(100%); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
-}
-
-@keyframes options-slide-in-start {
- from { transform: translateX(-100%); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
-}
-
-@keyframes options-slide-out-end {
- from { transform: translateX(0); opacity: 1; }
- to { transform: translateX(100%); opacity: 0; }
-}
-
-@keyframes options-slide-out-start {
- from { transform: translateX(0); opacity: 1; }
- to { transform: translateX(-100%); opacity: 0; }
-}
-
-.options-mobile-page-header {
- display: flex;
- align-items: center;
- gap: 4px;
- flex-grow: 1;
- min-width: 0;
-}
-
-/* Decorative settings icon shown in the list view. It borrows the `icon-action` class so it keeps
- exactly the back button's footprint (the title doesn't shift between views), with the
- interactive affordances neutralized. */
-.options-mobile-page-header .options-header-icon {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- pointer-events: none;
- cursor: default;
-}
-
-.options-mobile-page-header .options-mobile-page-title {
- margin: 0;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
+body.mobile .modal.options-dialog .modal-header {
+ border-bottom: 1px solid var(--main-border-color);
}
.modal.options-dialog .options-page-header {
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
index 71897e916f..99f0a560de 100644
--- a/apps/client/src/widgets/dialogs/OptionsDialog.tsx
+++ b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
@@ -9,9 +9,9 @@ import type FNote from "../../entities/fnote";
import { t } from "../../services/i18n";
import utils, { isElectron } from "../../services/utils";
import NoteDetail from "../NoteDetail";
-import ActionButton from "../react/ActionButton";
import FormList, { FormListItem } from "../react/FormList";
-import { useChildNotes, useContainedLinkNavigation, useMobileMasterDetail, useNoteContext, useTriliumEvent } from "../react/hooks";
+import { useChildNotes, useContainedLinkNavigation, useNoteContext, useTriliumEvent } from "../react/hooks";
+import { DetailPane, MasterDetailHeader, MasterPane, useMobileMasterDetail } from "../react/master_detail";
import Modal from "../react/Modal";
import { NoteContextContext, ParentComponent } from "../react/react_utils";
import SettingsNavigation from "../type_widgets/options/components/SettingsNavigation";
@@ -36,7 +36,7 @@ export default function OptionsDialog() {
const [ lastSection, setLastSection ] = useState<string | null>(null);
const modalRef = useRef<HTMLDivElement>(null);
const isMobile = utils.isMobile();
- const { isMasterDetail, mobileView, switchMobileView, resetMobileView } = useMobileMasterDetail(modalRef, "options-slide");
+ const { isMasterDetail, mobileView, switchMobileView, resetMobileView } = useMobileMasterDetail(modalRef);
useTriliumEvent("showOptions", async ({ section }) => {
const noteContext = new NoteContext("_options-dialog");
@@ -66,7 +66,15 @@ export default function OptionsDialog() {
<Modal
modalRef={modalRef}
title={t("options.title")}
- header={isMasterDetail && (mobileView === "page" ? <MobilePageHeader onBack={() => switchMobileView("list")} /> : <MobilePageHeader />)}
+ header={isMasterDetail && (
+ <MasterDetailHeader
+ inPage={mobileView === "page"}
+ onBack={() => switchMobileView("list")}
+ backTitle={t("options.back")}
+ listTitle={t("options.title")}
+ listIcon="bx bx-cog"
+ />
+ )}
sidebar={isMasterDetail ? undefined : <SettingsSidebar />}
isFullPageOnMobile
customTitleBarButtons={!isMobile ? [{
@@ -91,15 +99,18 @@ export default function OptionsDialog() {
}}
>
{isMasterDetail && (
- <div className="options-mobile-nav">
+ <MasterPane className="options-mobile-nav">
<MobileSettingsList onSelect={(noteId) => {
void noteContext.setNote(noteId, { keepActiveDialog: true });
switchMobileView("page");
}} />
- </div>
+ </MasterPane>
)}
<SettingsScrollReset modalRef={modalRef} />
- <NoteDetail />
+ {/* The settings page is the detail half of the flow, and is wrapped as a pane only where
+ there is a flow for it to be half of: the sidebar layout expects it as the body's own
+ child. */}
+ {isMasterDetail ? <DetailPane><NoteDetail /></DetailPane> : <NoteDetail />}
</Modal>
</NoteContextContext.Provider>
);
@@ -192,29 +203,3 @@ function MobileSettingsList({ onSelect }: { onSelect: (noteId: string) => void }
);
}
-/**
- * Replaces the static "Options" title on mobile. In the page view it shows just a back button
- * returning to the master list — the page title itself is rendered by the page's own
- * {@link OptionsPageHeader} below. In the list view a decorative settings icon and the dialog title
- * take its place.
- */
-function MobilePageHeader({ onBack }: { onBack?: () => void }) {
- if (onBack) {
- return (
- <div className="options-mobile-page-header">
- <ActionButton
- icon="bx bx-chevron-left"
- text={t("options.back")}
- onClick={onBack}
- />
- </div>
- );
- }
-
- return (
- <div className="options-mobile-page-header">
- <span className="options-header-icon icon-action bx bx-cog" aria-hidden="true" />
- <h5 className="options-mobile-page-title">{t("options.title")}</h5>
- </div>
- );
-}
diff --git a/apps/client/src/widgets/dialogs/note_attributes.css b/apps/client/src/widgets/dialogs/note_attributes.css
index b84dab3d1c..e7a1da29f9 100644
--- a/apps/client/src/widgets/dialogs/note_attributes.css
+++ b/apps/client/src/widgets/dialogs/note_attributes.css
@@ -146,3 +146,19 @@ body.mobile .modal.note-attributes-modal {
overflow-y: auto;
}
}
+
+/*
+ * Editing one attribute is a page of its own on a narrow screen rather than a form floating over the
+ * list: a popup wide enough for the fields would cover the whole of it anyway, and it would be a page
+ * over a page — a modal over a modal. The flow itself is the shared one (master_detail.css); what is
+ * particular to this dialog is what the page holds.
+ */
+.attribute-detail-page {
+ /* The form was drawn as a popup, and a page needs neither of the two things a popup has to carry: a
+ heading naming what is being edited (the page is headed with its name, and the badges beside it say
+ the rest) and a button to close itself with (the way back is in that header). */
+ .attr-detail-title,
+ .close-attr-detail-button {
+ display: none;
+ }
+}
diff --git a/apps/client/src/widgets/dialogs/note_attributes.tsx b/apps/client/src/widgets/dialogs/note_attributes.tsx
index 982065697e..0421fcc325 100644
--- a/apps/client/src/widgets/dialogs/note_attributes.tsx
+++ b/apps/client/src/widgets/dialogs/note_attributes.tsx
@@ -4,13 +4,17 @@ import { useState } from "preact/hooks";
import { t } from "../../services/i18n";
import { useTriliumEvent } from "../react/hooks";
-import Modal from "../react/Modal";
+import { MasterDetailModal } from "../react/master_detail";
import AttributeList from "../sidebar/AttributeList";
/**
* The attributes panel as a modal, for the layouts with no right pane to put it in — the mobile one,
* where it is summoned from the note's own menu. The panel follows the note being read, so the modal is
* summoned without being told which note it is about.
+ *
+ * A master-detail modal: on a screen too narrow to hold a form beside the list, the attribute being
+ * edited is a page of its own that slides in over it. The panel announces that page itself (see
+ * useMasterDetailPage), so all that is left here is the modal it happens in.
*/
export default function NoteAttributesDialog() {
const [ shown, setShown ] = useState(false);
@@ -18,10 +22,12 @@ export default function NoteAttributesDialog() {
useTriliumEvent("showNoteAttributes", () => setShown(true));
return (
- <Modal
+ <MasterDetailModal
className="note-attributes-modal"
- // Named as the menu entry that summons it names it.
+ // Named as the menu entry that summons it names it; a page of its own is named by the
+ // attribute on it instead.
title={t("note_actions.note_attributes")}
+ backTitle={t("attribute_list_panel.back")}
size="md"
show={shown}
onHidden={() => setShown(false)}
@@ -29,6 +35,6 @@ export default function NoteAttributesDialog() {
isFullPageOnMobile
>
<AttributeList />
- </Modal>
+ </MasterDetailModal>
);
}
diff --git a/apps/client/src/widgets/dialogs/revisions.css b/apps/client/src/widgets/dialogs/revisions.css
index 8ffe32dfe5..0f06503678 100644
--- a/apps/client/src/widgets/dialogs/revisions.css
+++ b/apps/client/src/widgets/dialogs/revisions.css
@@ -292,146 +292,14 @@ body.desktop .revisions-dialog {
}
-/* On narrow mobile viewports the dialog becomes a master-detail flow instead of the bottom-strip
- sidebar layout (the `mobile-master-detail` class, toggled by useMobileMasterDetail, tracks this):
- the revision list is rendered as a pane inside the modal body (the Modal sidebar is unused) so the
- list and the selected revision can slide over each other when switching between them. */
+/* The master-detail flow itself is the shared one (master_detail.css); what is particular here is that
+ the revision fills its pane and scrolls inside itself rather than as a pane. */
body.mobile .revisions-dialog.mobile-master-detail {
.modal-body {
- position: relative;
padding: 0;
- /* The panes scroll themselves; this also keeps the sliding panes contained. */
- overflow: hidden;
- }
-
- .revision-mobile-nav {
- height: 100%;
- overflow: auto;
}
.revision-detail {
- height: 100%;
overflow: hidden;
}
-
- /* The back button + revision date in the custom header replace the static "Note revisions" title. */
- .modal-header > .modal-title {
- display: none;
- }
-
- /* At rest only the active pane is displayed; during a transition both stay visible so the
- outgoing pane can slide away as the incoming one slides in. */
- &.mobile-view-list:not(.mobile-transition-to-list) .revision-detail {
- display: none;
- }
-
- &.mobile-view-page:not(.mobile-transition-to-page) .revision-mobile-nav {
- display: none;
- }
-
- /* Directional slide: opening a revision, the list slides out towards the start side while the
- detail slides in from the end side; going back reverses the directions. The detail pane stacks
- above the list, and `forwards` holds the outgoing pane off-screen until the transition classes
- are removed after animationend. The global `motion-disabled` rule suppresses the animations;
- the dialog then switches views directly without entering a transition. */
- &.mobile-transition-to-page,
- &.mobile-transition-to-list {
- .revision-mobile-nav,
- .revision-detail {
- position: absolute;
- inset: 0;
- background-color: var(--modal-background-color);
- }
-
- .revision-detail {
- z-index: 1;
- }
- }
-
- &.mobile-transition-to-page {
- .revision-detail {
- animation: revision-slide-in-end 0.35s ease-in-out forwards;
- }
-
- .revision-mobile-nav {
- animation: revision-slide-out-start 0.35s ease-in-out forwards;
- }
- }
-
- &.mobile-transition-to-list {
- .revision-detail {
- animation: revision-slide-out-end 0.35s ease-in-out forwards;
- }
-
- .revision-mobile-nav {
- animation: revision-slide-in-start 0.35s ease-in-out forwards;
- }
- }
-}
-
-body[dir=rtl].mobile .revisions-dialog.mobile-master-detail.mobile-transition-to-page {
- .revision-detail {
- animation-name: revision-slide-in-start;
- }
-
- .revision-mobile-nav {
- animation-name: revision-slide-out-end;
- }
-}
-
-body[dir=rtl].mobile .revisions-dialog.mobile-master-detail.mobile-transition-to-list {
- .revision-detail {
- animation-name: revision-slide-out-start;
- }
-
- .revision-mobile-nav {
- animation-name: revision-slide-in-end;
- }
-}
-
-.revision-mobile-header {
- display: flex;
- align-items: center;
- gap: 4px;
- flex-grow: 1;
- min-width: 0;
-
- /* Decorative history icon shown in the list view. It borrows `icon-action` so it keeps exactly
- the back button's footprint (the title doesn't shift between views), with the interactive
- affordances neutralized. */
- .revision-header-icon {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- pointer-events: none;
- cursor: default;
- }
-
- .revision-mobile-title {
- margin: 0;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- flex-grow: 1;
- }
-}
-
-@keyframes revision-slide-in-end {
- from { transform: translateX(100%); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
-}
-
-@keyframes revision-slide-in-start {
- from { transform: translateX(-100%); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
-}
-
-@keyframes revision-slide-out-end {
- from { transform: translateX(0); opacity: 1; }
- to { transform: translateX(100%); opacity: 0; }
-}
-
-@keyframes revision-slide-out-start {
- from { transform: translateX(0); opacity: 1; }
- to { transform: translateX(-100%); opacity: 0; }
}
diff --git a/apps/client/src/widgets/dialogs/revisions.tsx b/apps/client/src/widgets/dialogs/revisions.tsx
index d7a81f12a0..80feba96a2 100644
--- a/apps/client/src/widgets/dialogs/revisions.tsx
+++ b/apps/client/src/widgets/dialogs/revisions.tsx
@@ -4,7 +4,7 @@ import { dayjs, type RevisionItem, type RevisionPojo } from "@triliumnext/common
import clsx from "clsx";
import { diffWords } from "diff";
import HtmlDiff from "htmldiff-js";
-import { ComponentChildren, Fragment } from "preact";
+import { Fragment } from "preact";
import type { CSSProperties } from "preact/compat";
import { Dispatch, StateUpdater, useEffect, useRef, useState } from "preact/hooks";
@@ -25,7 +25,8 @@ import Button from "../react/Button";
import Dropdown from "../react/Dropdown";
import FormList, { FormDropdownDivider, FormListItem } from "../react/FormList";
import FormToggle from "../react/FormToggle";
-import { useMobileMasterDetail, useTriliumEvent } from "../react/hooks";
+import { useTriliumEvent } from "../react/hooks";
+import { DetailPane, MasterDetailHeader, MasterPane, useMobileMasterDetail } from "../react/master_detail";
import Modal from "../react/Modal";
import NoItems from "../react/NoItems";
import { RawHtmlBlock, SanitizedHtml } from "../react/RawHtml";
@@ -42,7 +43,7 @@ export default function RevisionsDialog() {
const [ showDiff, setShowDiff ] = useState(true);
const [ refreshCounter, setRefreshCounter ] = useState(0);
const modalRef = useRef<HTMLDivElement>(null);
- const { isMasterDetail, mobileView, switchMobileView, resetMobileView } = useMobileMasterDetail(modalRef, "revision-slide");
+ const { isMasterDetail, mobileView, switchMobileView, resetMobileView } = useMobileMasterDetail(modalRef);
const isMobile = utils.isMobile();
useTriliumEvent("showRevisions", async ({ noteId }) => {
@@ -157,11 +158,14 @@ export default function RevisionsDialog() {
helpPageId="vZWERwf8U3nx"
header={isMasterDetail
? (
- <RevisionsMobileHeader
+ <MasterDetailHeader
inPage={mobileView === "page"}
onBack={() => switchMobileView("list")}
- revisionItem={currentRevision}
- menu={menu}
+ backTitle={t("revisions.back")}
+ pageTitle={revisionTitle(currentRevision)}
+ listTitle={t("revisions.note_revisions")}
+ listIcon="bx bx-history"
+ listActions={menu}
/>
)
: menu}
@@ -169,12 +173,8 @@ export default function RevisionsDialog() {
onHidden={onHidden}
show={shown}
>
- {isMasterDetail && (
- <div className="revision-mobile-nav">
- {revisionsList}
- </div>
- )}
- <div className="revision-detail">
+ {isMasterDetail && <MasterPane className="revision-mobile-nav">{revisionsList}</MasterPane>}
+ <DetailPane className="revision-detail">
<RevisionToolbar
revisionItem={currentRevision}
showDiff={showDiff}
@@ -209,37 +209,16 @@ export default function RevisionsDialog() {
/>
</div>
)}
- </div>
+ </DetailPane>
</Modal>
);
}
-/**
- * Replaces the static "Note revisions" title on narrow mobile (the master-detail flow). In the list
- * view a decorative history icon precedes the dialog title and the actions menu stays available; in
- * the page view a back button returns to the list, followed by the revision's date.
- */
-function RevisionsMobileHeader({ inPage, onBack, revisionItem, menu }: {
- inPage: boolean,
- onBack: () => void,
- revisionItem?: RevisionItem,
- menu?: ComponentChildren
-}) {
- const pageTitle = revisionItem?.dateCreated
+/** How the page showing one revision is headed: the moment it was taken. */
+function revisionTitle(revisionItem?: RevisionItem) {
+ return revisionItem?.dateCreated
? dayjs(revisionItem.dateCreated).format("MMM D, YYYY · HH:mm")
: t("revisions.note_revisions");
-
- return (
- <div className="revision-mobile-header">
- {inPage ? (
- <ActionButton icon="bx bx-chevron-left" text={t("revisions.back")} onClick={onBack} />
- ) : (
- <span className="revision-header-icon icon-action bx bx-history" aria-hidden="true" />
- )}
- <h5 className="revision-mobile-title">{inPage ? pageTitle : t("revisions.note_revisions")}</h5>
- {!inPage && menu}
- </div>
- );
}
function RevisionsMenu({ note, onRevisionSaved, onAllDeleted, hasRevisions }: {
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index ab163db788..2b7cc7d265 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -972,79 +972,6 @@ export function useWindowSize() {
return size;
}
-/** Mobile viewports at least this wide (tablets) keep a side-by-side layout; narrower ones get the
- * master-detail flow. */
-export const MASTER_DETAIL_TABLET_MIN_WIDTH = 768;
-
-export interface MobileMasterDetail {
- /** True on narrow mobile viewports where the list and detail collapse into a master-detail flow. */
- isMasterDetail: boolean;
- /** Which half of the master-detail flow is currently visible. */
- mobileView: "list" | "page";
- /** Switch between the two views with a slide animation. */
- switchMobileView: (view: "list" | "page") => void;
- /** Set the view directly without animating (e.g. when (re)opening the dialog). */
- resetMobileView: (view: "list" | "page") => void;
-}
-
-/**
- * Drives the mobile master-detail flow shared by dialogs that pair a list with a detail pane (e.g.
- * the settings and revisions dialogs): it tracks which pane is visible, animates the slide between
- * them, and toggles the corresponding classes on the modal element (`mobile-master-detail`,
- * `mobile-view-{list,page}`, `mobile-transition-to-{list,page}`). The dialog supplies the layout and
- * slide keyframes in CSS; the keyframe names must start with `slideAnimationPrefix` so the in-flight
- * transition can be cleared once the slide finishes.
- */
-export function useMobileMasterDetail(modalRef: RefObject<HTMLElement>, slideAnimationPrefix: string): MobileMasterDetail {
- const [ mobileView, setMobileView ] = useState<"list" | "page">("list");
- // Direction of the in-flight slide between the two views, or null when at rest. While set, both
- // panes stay rendered so the outgoing one can slide away as the incoming one slides in.
- const [ mobileTransition, setMobileTransition ] = useState<"to-list" | "to-page" | null>(null);
- const isMobile = utils.isMobile();
- const { windowWidth } = useWindowSize();
- const isMasterDetail = isMobile && windowWidth < MASTER_DETAIL_TABLET_MIN_WIDTH;
-
- const switchMobileView = useCallback((view: "list" | "page") => {
- if (view === mobileView) return;
- setMobileView(view);
- // With animations globally disabled there is no animationend to clear the transition, so
- // switch directly. Outside the master-detail flow there is nothing to animate.
- if (isMasterDetail && !document.body.classList.contains("motion-disabled")) {
- setMobileTransition(view === "page" ? "to-page" : "to-list");
- }
- }, [ mobileView, isMasterDetail ]);
-
- const resetMobileView = useCallback((view: "list" | "page") => {
- setMobileView(view);
- setMobileTransition(null);
- }, []);
-
- // Bootstrap adds its own classes (e.g. `show`) to the modal element at runtime, so the className
- // prop must stay static; toggle the mobile view classes directly on the element instead.
- useEffect(() => {
- modalRef.current?.classList.toggle("mobile-master-detail", isMasterDetail);
- modalRef.current?.classList.toggle("mobile-view-list", mobileView === "list");
- modalRef.current?.classList.toggle("mobile-view-page", mobileView === "page");
- modalRef.current?.classList.toggle("mobile-transition-to-list", mobileTransition === "to-list");
- modalRef.current?.classList.toggle("mobile-transition-to-page", mobileTransition === "to-page");
- }, [ isMasterDetail, mobileView, mobileTransition ]);
-
- // End the view transition once the slide finishes (animationend bubbles up from the panes).
- useEffect(() => {
- const modalElement = modalRef.current;
- if (!modalElement) return;
- function onAnimationEnd(e: AnimationEvent) {
- if (e.animationName.startsWith(slideAnimationPrefix)) {
- setMobileTransition(null);
- }
- }
- modalElement.addEventListener("animationend", onAnimationEnd);
- return () => modalElement.removeEventListener("animationend", onAnimationEnd);
- }, [ slideAnimationPrefix ]);
-
- return { isMasterDetail, mobileView, switchMobileView, resetMobileView };
-}
-
// Workaround for https://github.com/twbs/bootstrap/issues/37474
// Bootstrap's dispose() sets ALL properties to null. But pending animation callbacks
// (scheduled via setTimeout) can still fire and crash when accessing null properties.
diff --git a/apps/client/src/widgets/react/master_detail.css b/apps/client/src/widgets/react/master_detail.css
new file mode 100644
index 0000000000..a4ac79cea0
--- /dev/null
+++ b/apps/client/src/widgets/react/master_detail.css
@@ -0,0 +1,139 @@
+/*
+ * The mobile master-detail flow: one pane at a time, the detail sliding in over the list. Driven by
+ * useMobileMasterDetail, which toggles every class matched here on the modal element; a dialog opts in by
+ * wrapping its two halves in MasterPane and DetailPane, and is left with whatever is particular to what
+ * is in them (its own padding, what scrolls, a footer).
+ */
+body.mobile .modal.mobile-master-detail {
+ .modal-body {
+ position: relative;
+ /* Each pane scrolls itself, which is also what keeps the sliding ones contained. */
+ overflow: hidden;
+ }
+
+ .tn-master-pane,
+ .tn-detail-pane {
+ height: 100%;
+ overflow: auto;
+ }
+
+ /* The header carries the way back and the name of what is on show (see MasterDetailHeader), in
+ place of the dialog's own title. */
+ .modal-header > .modal-title {
+ display: none;
+ }
+
+ /* At rest only the pane being read is drawn; through a transition both are, so that the one being
+ left can slide away as the other slides in. */
+ &.mobile-view-list:not(.mobile-transition-to-list) .tn-detail-pane {
+ display: none;
+ }
+
+ &.mobile-view-page:not(.mobile-transition-to-page) .tn-master-pane {
+ display: none;
+ }
+
+ /* Opening a page, the list slides out towards the start side as the page slides in from the end
+ side; going back reverses both. The page is drawn over the list, and `forwards` holds the pane
+ being left off-screen until the transition classes come off after animationend. The global
+ `motion-disabled` rule suppresses the animations; the flow then switches views directly, without
+ entering a transition at all. */
+ &.mobile-transition-to-page,
+ &.mobile-transition-to-list {
+ .tn-master-pane,
+ .tn-detail-pane {
+ position: absolute;
+ inset: 0;
+ background-color: var(--modal-background-color);
+ }
+
+ .tn-detail-pane {
+ z-index: 1;
+ }
+ }
+
+ &.mobile-transition-to-page {
+ .tn-detail-pane {
+ animation: tn-master-detail-in-end 0.35s ease-in-out forwards;
+ }
+
+ .tn-master-pane {
+ animation: tn-master-detail-out-start 0.35s ease-in-out forwards;
+ }
+ }
+
+ &.mobile-transition-to-list {
+ .tn-detail-pane {
+ animation: tn-master-detail-out-end 0.35s ease-in-out forwards;
+ }
+
+ .tn-master-pane {
+ animation: tn-master-detail-in-start 0.35s ease-in-out forwards;
+ }
+ }
+}
+
+body[dir="rtl"].mobile .modal.mobile-master-detail.mobile-transition-to-page {
+ .tn-detail-pane {
+ animation-name: tn-master-detail-in-start;
+ }
+
+ .tn-master-pane {
+ animation-name: tn-master-detail-out-end;
+ }
+}
+
+body[dir="rtl"].mobile .modal.mobile-master-detail.mobile-transition-to-list {
+ .tn-detail-pane {
+ animation-name: tn-master-detail-out-start;
+ }
+
+ .tn-master-pane {
+ animation-name: tn-master-detail-in-end;
+ }
+}
+
+.tn-master-detail-header {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ flex-grow: 1;
+ min-width: 0;
+
+ /* Decorative, and pointed at nothing: it stands where the back button stands in the other view. */
+ .tn-master-detail-icon {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ pointer-events: none;
+ cursor: default;
+ }
+
+ .tn-master-detail-title {
+ margin: 0;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ flex-grow: 1;
+ }
+}
+
+@keyframes tn-master-detail-in-end {
+ from { transform: translateX(100%); opacity: 0; }
+ to { transform: translateX(0); opacity: 1; }
+}
+
+@keyframes tn-master-detail-in-start {
+ from { transform: translateX(-100%); opacity: 0; }
+ to { transform: translateX(0); opacity: 1; }
+}
+
+@keyframes tn-master-detail-out-end {
+ from { transform: translateX(0); opacity: 1; }
+ to { transform: translateX(100%); opacity: 0; }
+}
+
+@keyframes tn-master-detail-out-start {
+ from { transform: translateX(0); opacity: 1; }
+ to { transform: translateX(-100%); opacity: 0; }
+}
diff --git a/apps/client/src/widgets/react/master_detail.tsx b/apps/client/src/widgets/react/master_detail.tsx
new file mode 100644
index 0000000000..987670bcd8
--- /dev/null
+++ b/apps/client/src/widgets/react/master_detail.tsx
@@ -0,0 +1,231 @@
+import "./master_detail.css";
+
+import clsx from "clsx";
+import { ComponentChildren, createContext, RefObject } from "preact";
+import { useCallback, useContext, useEffect, useRef, useState } from "preact/hooks";
+
+import utils from "../../services/utils";
+import ActionButton from "./ActionButton";
+import { useWindowSize } from "./hooks";
+import Modal, { ModalProps } from "./Modal";
+
+/**
+ * The flow a dialog that pairs a list with a detail takes on a screen too narrow to hold both: one at a
+ * time, the detail sliding in over the list and a way back in its header. Everything a dialog needs for
+ * it lives here — the state and the classes ({@link useMobileMasterDetail}), the two panes
+ * ({@link MasterPane}, {@link DetailPane}), the header ({@link MasterDetailHeader}) and their styling
+ * (master_detail.css) — so that three dialogs do not each carry their own copy of the same slide.
+ */
+
+/** Mobile viewports at least this wide (tablets) keep a side-by-side layout; narrower ones get the
+ * master-detail flow. */
+export const MASTER_DETAIL_TABLET_MIN_WIDTH = 768;
+
+/** What every slide of the flow is named with, which is how a finished one is recognised. */
+const SLIDE_ANIMATION_PREFIX = "tn-master-detail-";
+
+export interface MobileMasterDetail {
+ /** True on narrow mobile viewports where the list and detail collapse into a master-detail flow. */
+ isMasterDetail: boolean;
+ /** Which half of the master-detail flow is currently visible. */
+ mobileView: "list" | "page";
+ /** Switch between the two views with a slide animation. */
+ switchMobileView: (view: "list" | "page") => void;
+ /** Set the view directly without animating (e.g. when (re)opening the dialog). */
+ resetMobileView: (view: "list" | "page") => void;
+}
+
+/**
+ * Drives the mobile master-detail flow: it tracks which pane is visible, animates the slide between
+ * them, and toggles the corresponding classes on the modal element (`mobile-master-detail`,
+ * `mobile-view-{list,page}`, `mobile-transition-to-{list,page}`), which master_detail.css lays out and
+ * slides. The dialog's own stylesheet is left with whatever is particular to its panes.
+ */
+export function useMobileMasterDetail(modalRef: RefObject<HTMLElement>): MobileMasterDetail {
+ const [ mobileView, setMobileView ] = useState<"list" | "page">("list");
+ // Direction of the in-flight slide between the two views, or null when at rest. While set, both
+ // panes stay rendered so the outgoing one can slide away as the incoming one slides in.
+ const [ mobileTransition, setMobileTransition ] = useState<"to-list" | "to-page" | null>(null);
+ const isMobile = utils.isMobile();
+ const { windowWidth } = useWindowSize();
+ const isMasterDetail = isMobile && windowWidth < MASTER_DETAIL_TABLET_MIN_WIDTH;
+
+ const switchMobileView = useCallback((view: "list" | "page") => {
+ if (view === mobileView) return;
+ setMobileView(view);
+ // With animations globally disabled there is no animationend to clear the transition, so
+ // switch directly. Outside the master-detail flow there is nothing to animate.
+ if (isMasterDetail && !document.body.classList.contains("motion-disabled")) {
+ setMobileTransition(view === "page" ? "to-page" : "to-list");
+ }
+ }, [ mobileView, isMasterDetail ]);
+
+ const resetMobileView = useCallback((view: "list" | "page") => {
+ setMobileView(view);
+ setMobileTransition(null);
+ }, []);
+
+ // Bootstrap adds its own classes (e.g. `show`) to the modal element at runtime, so the className
+ // prop must stay static; toggle the mobile view classes directly on the element instead.
+ useEffect(() => {
+ modalRef.current?.classList.toggle("mobile-master-detail", isMasterDetail);
+ modalRef.current?.classList.toggle("mobile-view-list", mobileView === "list");
+ modalRef.current?.classList.toggle("mobile-view-page", mobileView === "page");
+ modalRef.current?.classList.toggle("mobile-transition-to-list", mobileTransition === "to-list");
+ modalRef.current?.classList.toggle("mobile-transition-to-page", mobileTransition === "to-page");
+ }, [ isMasterDetail, mobileView, mobileTransition ]);
+
+ // End the view transition once the slide finishes (animationend bubbles up from the panes).
+ useEffect(() => {
+ const modalElement = modalRef.current;
+ if (!modalElement) return;
+ function onAnimationEnd(e: AnimationEvent) {
+ if (e.animationName.startsWith(SLIDE_ANIMATION_PREFIX)) {
+ setMobileTransition(null);
+ }
+ }
+ modalElement.addEventListener("animationend", onAnimationEnd);
+ return () => modalElement.removeEventListener("animationend", onAnimationEnd);
+ }, []);
+
+ return { isMasterDetail, mobileView, switchMobileView, resetMobileView };
+}
+
+interface PaneProps {
+ /** The dialog's own class for the pane, for whatever is particular to what is in it. */
+ className?: string;
+ children: ComponentChildren;
+}
+
+/** The list half of the flow. Rendered inside the modal body, the Modal sidebar being unused there. */
+export function MasterPane({ className, children }: PaneProps) {
+ return <div class={clsx("tn-master-pane", className)}>{children}</div>;
+}
+
+/** The half the list leads to, which slides in over it. */
+export function DetailPane({ className, children }: PaneProps) {
+ return <div class={clsx("tn-detail-pane", className)}>{children}</div>;
+}
+
+interface MasterDetailHeaderProps {
+ /** Whether the detail is what is on show, which is what the header is a way back from. */
+ inPage: boolean;
+ onBack: () => void;
+ /** The back button's tooltip: where it goes back to, in the dialog's own words. */
+ backTitle: string;
+ /** What the detail on show is called. */
+ pageTitle?: ComponentChildren;
+ /** What the dialog is called, shown while the list is. */
+ listTitle: ComponentChildren;
+ /** A decorative icon for the list view, standing where the back button stands in the other. */
+ listIcon?: string;
+ /** The dialog's own actions, which belong to the list rather than to one page of it. */
+ listActions?: ComponentChildren;
+}
+
+/**
+ * The header of a master-detail modal, in place of its static title (which master_detail.css hides):
+ * the way back and the name of what is on show, or the dialog's own name while the list is.
+ */
+export function MasterDetailHeader({ inPage, onBack, backTitle, pageTitle, listTitle, listIcon, listActions }: MasterDetailHeaderProps) {
+ return (
+ <div class="tn-master-detail-header">
+ {inPage ? (
+ <ActionButton icon="bx bx-chevron-left" text={backTitle} onClick={onBack} />
+ ) : (
+ // Borrows `icon-action` so it keeps exactly the back button's footprint, and the title
+ // does not shift as the views change.
+ listIcon && <span class={clsx("tn-master-detail-icon icon-action", listIcon)} aria-hidden="true" />
+ )}
+ {/* A page that names itself (the settings pages do) passes no title, and gets no room
+ taken for one. */}
+ {(inPage ? pageTitle : listTitle) && (
+ <h5 class="tn-master-detail-title">{inPage ? pageTitle : listTitle}</h5>
+ )}
+ {!inPage && listActions}
+ </div>
+ );
+}
+
+interface MasterDetailState {
+ /** Whether the host is showing one pane at a time, with the other sliding in over it. */
+ isMasterDetail: boolean;
+ /**
+ * Announces the page being shown to the host, so that it can head it and slide to it: its title,
+ * and how to leave it. A `null` title means the list is what is on show.
+ */
+ showPage: (title: string | null, close: () => void) => void;
+}
+
+const MasterDetailContext = createContext<MasterDetailState>({
+ isMasterDetail: false,
+ showPage: () => {}
+});
+
+/** What a component nested in a master-detail modal knows of the flow it is part of. */
+export function useMasterDetail() {
+ return useContext(MasterDetailContext);
+}
+
+/**
+ * Hands the page a component is showing to the master-detail host around it — the host heads it with the
+ * title and slides to it, and its back button calls `close`. Outside such a host this does nothing, so a
+ * component that can be shown in either place needs no second version of itself.
+ */
+export function useMasterDetailPage(title: string | null, close: () => void) {
+ const { showPage } = useMasterDetail();
+ // Read at press time rather than captured: what closing the page means changes as it is edited.
+ const closeRef = useRef(close);
+ closeRef.current = close;
+
+ useEffect(() => showPage(title, () => closeRef.current()), [ title, showPage ]);
+}
+
+/**
+ * A modal whose contents are a master-detail flow: it drives the flow, heads the page on show with a way
+ * back, and lets whatever is inside it announce that page ({@link useMasterDetailPage}) rather than
+ * having to be handed down to the pieces that draw it.
+ */
+export function MasterDetailModal({ backTitle, listIcon, listActions, children, ...modalProps }: ModalProps & {
+ backTitle: string;
+ listIcon?: string;
+ listActions?: ComponentChildren;
+}) {
+ const modalRef = useRef<HTMLDivElement>(null);
+ const [ page, setPage ] = useState<{ title: string; close: () => void } | null>(null);
+ const { isMasterDetail, mobileView, switchMobileView, resetMobileView } = useMobileMasterDetail(modalRef);
+
+ const showPage = useCallback((title: string | null, close: () => void) => {
+ setPage((current) => title === null ? null : (current?.title === title ? current : { title, close }));
+ switchMobileView(title === null ? "list" : "page");
+ }, [ switchMobileView ]);
+
+ // Opens on the list, whatever page a previous show was left on.
+ useEffect(() => {
+ if (modalProps.show) {
+ resetMobileView("list");
+ }
+ }, [ modalProps.show, resetMobileView ]);
+
+ return (
+ <Modal
+ {...modalProps}
+ modalRef={modalRef}
+ header={isMasterDetail ? (
+ <MasterDetailHeader
+ inPage={mobileView === "page"}
+ onBack={() => page?.close()}
+ backTitle={backTitle}
+ pageTitle={page?.title}
+ listTitle={modalProps.title}
+ listIcon={listIcon}
+ listActions={listActions}
+ />
+ ) : modalProps.header}
+ >
+ <MasterDetailContext.Provider value={{ isMasterDetail, showPage }}>
+ {children}
+ </MasterDetailContext.Provider>
+ </Modal>
+ );
+}
diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsx
index 1af0b56801..d8dc1338e1 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx
@@ -15,12 +15,13 @@ import dialog from "../../services/dialog";
import { t } from "../../services/i18n";
import server from "../../services/server";
import { isMobile } from "../../services/utils";
-import { AttributeDetail, AttributeDetailOpts, AttrType, DEFINITION_TYPES, getAttrType, RELATION_DEFINITION_TYPE } from "../attribute_widgets/attribute_detail";
+import { AttributeDetail, AttributeDetailOpts, AttributeForm, AttrType, DEFINITION_TYPES, getAttrType, RELATION_DEFINITION_TYPE } from "../attribute_widgets/attribute_detail";
import ActionButton from "../react/ActionButton";
import { FormListItem } from "../react/FormList";
import HelpButton from "../react/HelpButton";
import { useActiveNoteContext, useTriliumEvent } from "../react/hooks";
import Icon from "../react/Icon";
+import { DetailPane, MasterPane, useMasterDetail, useMasterDetailPage } from "../react/master_detail";
import NoItems from "../react/NoItems";
import NoteLink from "../react/NoteLink";
import { ParentComponent } from "../react/react_utils";
@@ -32,10 +33,15 @@ import RightPanelWidget, { CollapsibleWidgets } from "./RightPanelWidget";
* The note's attributes as a list, one row per attribute: the kind (label, relation, or either's
* definition) is carried by an icon instead of by the `#`/`~`/`label:` syntax the attributes editor
* spells out, and the value is shown as a preview rather than in full. Rows open the same detail
- * popup the editor uses, which is where an attribute is actually edited.
+ * form the editor uses, which is where an attribute is actually edited.
+ *
+ * The form floats beside its row where there is room for it — a panel with a note's width beside it —
+ * and is a page of its own inside a master-detail host (a modal on a phone), which slides it in over
+ * the list and heads it with a way back.
*/
export default function AttributeList() {
const { note } = useActiveNoteContext();
+ const { isMasterDetail } = useMasterDetail();
const parentComponent = useContext(ParentComponent);
const containerRef = useRef<HTMLDivElement>(null);
const [ detail, setDetail ] = useState<AttributeDetailOpts | null>(null);
@@ -122,7 +128,7 @@ export default function AttributeList() {
});
}
- /** Closes the popup keeping its edits: a list of rows has no save step of its own. */
+ /** Closes the form keeping its edits: a list of rows has no save step of its own. */
function commit() {
const isOwned = detail?.isOwned;
@@ -132,6 +138,10 @@ export default function AttributeList() {
}
}
+ // A master-detail host heads the page it shows the form on with the attribute's name, and goes back
+ // to the list by closing it. Nothing happens outside such a host, where the form is a popup.
+ useMasterDetailPage(detail ? getDisplayName(detail.attribute, getAttributeKind(detail.attribute)) : null, commit);
+
/**
* Deleting is a press away in every row, and the row is all there is to tell one attribute from
* another, so it is confirmed first — from the popup too, which deletes the very same thing.
@@ -162,7 +172,25 @@ export default function AttributeList() {
+ (sections.definitions.length ? 1 : 0)
+ (internalRows.length ? 1 : 0);
- return (
+ // The same callbacks whichever of the two the form is shown in.
+ const formCallbacks = {
+ // A press outside keeps the edits, matching the attributes editor (which saves on blur); the
+ // close button and escape go through onCancel and revert instead.
+ onCancel: () => {
+ if (note) {
+ owned.current = collectOwned(note);
+ }
+ setDetail(null);
+ rerender();
+ },
+ // The form edits the attribute in place, so there is nothing to apply here: the rows only need
+ // to be redrawn to follow along as it is typed into.
+ onAttributesChanged: rerender,
+ // An inherited attribute is shown read-only, so it has neither of the two.
+ onSaveAndClose: detail?.isOwned ? commit : undefined,
+ onDelete: detail?.isOwned ? () => void deleteAttribute(detail.attribute) : undefined
+ };
+ const sectionList = (
<>
{/* A card each, so a section is collapsed on its own and the inherited attributes — which a
template can run to dozens of — can be put away without taking the note's own with them.
@@ -236,27 +264,42 @@ export default function AttributeList() {
</AttributeSection>
)}
</CollapsibleWidgets.Provider>
+ </>
+ );
+
+ // Inside a master-detail host the list and the form are its two panes, which it slides over each
+ // other — so they are handed over as siblings rather than nested in a wrapper of ours.
+ if (isMasterDetail) {
+ return (
+ <>
+ <MasterPane>{sectionList}</MasterPane>
+ <DetailPane className="attribute-detail-page">
+ {detail && (
+ <AttributeForm
+ // Reseeded from whichever attribute the page is showing, the fields being
+ // seeded once per show (see AttributeForm).
+ key={detail.attribute.attributeId ?? "new"}
+ opts={detail}
+ attrType={getAttrType(detail.attribute)}
+ currentNoteId={note?.noteId}
+ {...formCallbacks}
+ />
+ )}
+ </DetailPane>
+ </>
+ );
+ }
+
+ return (
+ <>
+ {sectionList}
{createPortal(
<AttributeDetail
opts={detail}
currentNoteId={note?.noteId}
- // A press outside keeps the edits, matching the attributes editor (which saves on
- // blur); the close button and escape go through onCancel and revert instead.
onDismiss={commit}
- onCancel={() => {
- if (note) {
- owned.current = collectOwned(note);
- }
- setDetail(null);
- rerender();
- }}
- // The popup edits the attribute in place, so there is nothing to apply here: the
- // rows only need to be redrawn to follow along as it is typed into.
- onAttributesChanged={rerender}
- // An inherited attribute is shown read-only, so it has neither of the two.
- onSaveAndClose={detail?.isOwned ? commit : undefined}
- onDelete={detail?.isOwned ? () => void deleteAttribute(detail.attribute) : undefined}
+ {...formCallbacks}
/>,
document.body)}
</>