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
refactor(attributes): gather the sections into one list of folding runs
Elian Doran32a85ae99f80
diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.cssindex ad0180ba76..038b4e4ebc 100644--- a/apps/client/src/widgets/sidebar/AttributeList.css+++ b/apps/client/src/widgets/sidebar/AttributeList.css@@ -212,6 +212,62 @@border-radius: 50%;}+/*+ * The heading a run of rows folds away under, where a card and its own header stood before. Dressed+ * as those headers were — the pane's heading colour at its weight, its size and its letter spacing+ * (see shell.css) — so that the runs still read as the sections they were, one notch quieter for+ * standing inside a card rather than being one.+ *+ * Held at the top of what can be seen while its rows are scrolled past, so that a row is never read+ * without the heading that says what it is; the heading of the run below pushes it out of the way in+ * its turn. Opaque for the same reason the selection's island is, the rows passing under it — but+ * the app's surface plainly, not the card's fill over it: a right-pane card paints no ground of its+ * own, so its rows lie on that same surface, and a heading carrying the fill besides would read as+ * a band laid across them rather than as words above them.+ *+ * The room above it is padding rather than margin, which a sticky box is held off its edge by: the+ * rows would then be read through the gap that opened above the heading as they passed under it.+ */+.attribute-list-panel .attribute-group-header {+ position: sticky;+ top: 0;+ z-index: 1;+ display: flex;+ align-items: center;+ gap: 3px;+ padding: 14px 4px 6px;+ cursor: pointer;+ color: var(--right-pane-heading-color, var(--muted-text-color));+ font-weight: 600;+ font-size: 0.85em;+ letter-spacing: 0.3pt;+ text-transform: uppercase;+ background-color: var(--main-background-color);+}++/* The room above a heading sets its run apart from the one before it. The first has none before it,+ only the card's own header, which has set it apart already. */+.attribute-list-panel .attribute-group:first-child .attribute-group-header {+ padding-top: 4px;+}++/* Turned as the cards turned theirs (see RightPanelContainer.css), so that folding a run away reads+ as folding a card away did. */+.attribute-list-panel .attribute-group-chevron {+ flex-shrink: 0;+ transition: transform 100ms ease;+}++.attribute-list-panel .attribute-group.collapsed .attribute-group-chevron {+ transform: rotate(-90deg);+}++.attribute-list-panel .attribute-group-title {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}+/* What separates the note's own vocabulary from the names Trilium reads for itself. Quiet: the sort iswhat carries the split, the rule only marks where it falls. */.attribute-list-panel .attribute-rows-divider {@@ -242,10 +298,10 @@/* Set against the row's trailing edge rather than trailing the name, so the values line up in acolumn of their own: name reads from the one edge, value from the other, and the gap between them- says how much room is left rather than being dead space after every short value. Where the card- asks for it — the two lists of plain attributes, owned and inherited (see AttributeList.tsx);- the definitions' summaries keep prose order. */-.attribute-list-panel.align-values-end .attribute-value {+ says how much room is left rather than being dead space after every short value. Where the run of+ rows asks for it — the two runs of plain attributes, the note's own and the inherited ones (see+ AttributeList.tsx); the definitions' summaries keep prose order. */+.attribute-list-panel .attribute-rows.align-values-end .attribute-value {text-align: end;}@@ -307,8 +363,8 @@width: fit-content;}-/* Being a box rather than text, the chip follows the card's alignment by margin instead. */-.attribute-list-panel.align-values-end .attribute-value > .label-color-chip {+/* Being a box rather than text, the chip follows the run's alignment by margin instead. */+.attribute-list-panel .attribute-rows.align-values-end .attribute-value > .label-color-chip {margin-inline-start: auto;}diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsxindex 9e1e92fbe2..83e9217f5c 100644--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx@@ -184,53 +184,67 @@ describe("AttributeList", () => {}});- it("gives the note's own attributes, the inherited ones and the definitions of either a card each", () => {+ it("holds the note's own attributes, the inherited ones and the definitions of either in one list", () => {renderPanel(noteWithAttributes());- // Three cards, each listing what its section holds.- const cards = [ ...container.querySelectorAll(".card") ];- expect(cards.map((card) => card.id)).toEqual([ "attributes", "attributes-inherited", "attributes-definitions" ]);- expect(namesIn(cards[0])).toEqual([ "author", "cssClass", "template" ]);- expect(namesIn(cards[1])).toEqual([ "inheritedLabel", "archived" ]);- // The definitions of both notes share a card, the note's own first, and lose their prefix.- expect(namesIn(cards[2])).toEqual([ "priority", "status" ]);+ // One card for the lot, every run of it under a heading of its own — the card names the+ // panel, so the note's own attributes need one as much as the rest do.+ expect(container.querySelectorAll(".card")).toHaveLength(1);+ expect(groupIds()).toEqual([ "attributes-owned", "attributes-inherited", "attributes-definitions" ]);+ expect(namesIn(group("attributes-owned"))).toEqual([ "author", "cssClass", "template" ]);+ expect(namesIn(group("attributes-inherited"))).toEqual([ "inheritedLabel", "archived" ]);+ // The definitions of both notes share a group, the note's own first, and lose their prefix.+ expect(namesIn(group("attributes-definitions"))).toEqual([ "priority", "status" ]);// The kind is carried by the icon; a definition takes the icon of the field it sets up.- expect(iconsIn(cards[0])).toEqual([ "bx bx-hash", "bx bx-hash", "bx bx-transfer" ]);+ expect(iconsIn(group("attributes-owned"))).toEqual([ "bx bx-hash", "bx bx-hash", "bx bx-transfer" ]);// The icon also carries the row's one tooltip — the row itself has none to compete with it.// Only its presence: the wording is translated, and translations stay unloaded here.- expect(cards[0].querySelector(".attribute-row")?.hasAttribute("title")).toBe(false);- expect(cards[0].querySelector(".attribute-kind")?.hasAttribute("title")).toBe(true);+ expect(container.querySelector(".attribute-row")?.hasAttribute("title")).toBe(false);+ expect(container.querySelector(".attribute-kind")?.hasAttribute("title")).toBe(true);// A definition that names no type sets up a text field, and takes that field's icon.- expect(iconsIn(cards[2])).toEqual([ "bx bx-calendar", "bx bx-text" ]);+ expect(iconsIn(group("attributes-definitions"))).toEqual([ "bx bx-calendar", "bx bx-text" ]);// The names Trilium reads for itself come last, below a rule, and are marked as such.- expect(cards[0].querySelectorAll("hr.attribute-rows-divider")).toHaveLength(1);- expect([ ...cards[0].querySelectorAll(".attribute-kind") ].map((kind) => kind.className.includes("marker-system")))+ expect(group("attributes-owned").querySelectorAll("hr.attribute-rows-divider")).toHaveLength(1);+ expect([ ...group("attributes-owned").querySelectorAll(".attribute-kind") ]+ .map((kind) => kind.className.includes("marker-system"))).toEqual([ false, true, true ]);// A row of the note's own is deletable and unattributed; an inherited one names its note instead.- expect(cards[0].querySelectorAll(".attribute-delete-button")).toHaveLength(3);- expect(cards[0].querySelectorAll(".attribute-owner")).toHaveLength(0);- expect(cards[1].querySelectorAll(".attribute-delete-button")).toHaveLength(0);- expect(cards[1].querySelectorAll(".attribute-owner")).toHaveLength(2);- // Only what the note may edit is deletable, whichever card it is in.- expect(cards[2].querySelectorAll(".attribute-delete-button")).toHaveLength(1);+ expect(group("attributes-owned").querySelectorAll(".attribute-delete-button")).toHaveLength(3);+ expect(group("attributes-owned").querySelectorAll(".attribute-owner")).toHaveLength(0);+ expect(group("attributes-inherited").querySelectorAll(".attribute-delete-button")).toHaveLength(0);+ expect(group("attributes-inherited").querySelectorAll(".attribute-owner")).toHaveLength(2);+ // Only what the note may edit is deletable, whichever run it is in.+ expect(group("attributes-definitions").querySelectorAll(".attribute-delete-button")).toHaveLength(1);// An inheritable attribute is marked, and every definition previews what it sets up — a// set-holding one (label:status, "multi") by a mark of its own rather than by words.- expect(cards[1].querySelectorAll(".attribute-marker")).toHaveLength(2);- expect(cards[2].querySelectorAll(".attribute-value.definition")).toHaveLength(2);- expect(cards[2].querySelectorAll(".definition-marker")).toHaveLength(1);+ expect(group("attributes-inherited").querySelectorAll(".attribute-marker")).toHaveLength(2);+ expect(group("attributes-definitions").querySelectorAll(".attribute-value.definition")).toHaveLength(2);+ expect(group("attributes-definitions").querySelectorAll(".definition-marker")).toHaveLength(1);});- it("keeps to one card, collapsing and all, for a note with nothing but its own attributes", () => {- renderPanel(buildNote({ id: "bare", title: "Bare", "#author": "Elian" }));+ it("folds a run of rows away by its heading, and remembers it folded", async () => {+ options.set("rightPaneCollapsedItems", JSON.stringify([ "attributes-inherited" ]));+ renderPanel(noteWithAttributes());- expect(container.querySelectorAll(".card")).toHaveLength(1);- // Down to a single card there is nothing to put away, so no chevron is offered.+ // Remembered from before, so the run arrives folded and its rows are not drawn at all.+ expect(group("attributes-inherited").className).toContain("collapsed");+ expect(namesIn(group("attributes-inherited"))).toEqual([]);+ // The card is the only one its tab has, so it is not itself something to fold away.expect(container.querySelector(".card")?.className).toContain("not-collapsible");++ await act(async () => groupHeader("attributes-inherited").click());+ expect(group("attributes-inherited").className).not.toContain("collapsed");+ expect(namesIn(group("attributes-inherited"))).toEqual([ "inheritedLabel", "archived" ]);+ expect(JSON.parse(options.get("rightPaneCollapsedItems") ?? "[]")).not.toContain("attributes-inherited");++ // And folding one back up is remembered the same way.+ await act(async () => groupHeader("attributes-definitions").click());+ expect(JSON.parse(options.get("rightPaneCollapsedItems") ?? "[]")).toContain("attributes-definitions");});it("says so, rather than showing an empty list, for a note carrying no attributes at all", () => {@@ -240,27 +254,27 @@ describe("AttributeList", () => {expect(container.querySelector(".no-items")).not.toBeNull();});- it("leaves what Trilium wrote for itself out of a release build, and gives it its own card in a development one", () => {+ it("leaves what Trilium wrote for itself out of a release build, and gives it its own run in a development one", () => {buildNote({ id: "target", title: "Target" });const note = buildNote({ id: "linking", title: "Linking", "#author": "Elian", "~internalLink": "target" });renderPanel(note);- expect(cardIds()).toEqual([ "attributes" ]);+ expect(groupIds()).toEqual([ "attributes-owned" ]);// Unmounted first, the panel collecting the attributes of the note it is handed as it mounts.setDevBuild(true);render(null, container);renderPanel(note);- const cards = [ ...container.querySelectorAll(".card") ];- expect(cardIds()).toEqual([ "attributes", "attributes-internal" ]);- expect(namesIn(cards[1])).toEqual([ "internalLink" ]);+ expect(groupIds()).toEqual([ "attributes-owned", "attributes-internal" ]);+ const internal = group("attributes-internal");+ expect(namesIn(internal)).toEqual([ "internalLink" ]);// Nothing on such a row is the note's to change, and nothing marks it as Trilium's own: the- // card it is in says as much of every row it holds.- expect(cards[1].querySelectorAll(".attribute-delete-button")).toHaveLength(0);- expect(cards[1].querySelectorAll(".attribute-owner")).toHaveLength(0);- expect(cards[1].querySelector(".attribute-kind")?.className).not.toContain("marker-system");- expect(cards[1].querySelectorAll("hr.attribute-rows-divider")).toHaveLength(0);+ // heading it is under says as much of every row it holds.+ expect(internal.querySelectorAll(".attribute-delete-button")).toHaveLength(0);+ expect(internal.querySelectorAll(".attribute-owner")).toHaveLength(0);+ expect(internal.querySelector(".attribute-kind")?.className).not.toContain("marker-system");+ expect(internal.querySelectorAll("hr.attribute-rows-divider")).toHaveLength(0);});it("opens the detail popup on a row and closes it again on a press beside the rows", () => {@@ -331,18 +345,19 @@ describe("AttributeList", () => {it("adds a definition through the popup, saving it once the popup is closed", async () => {renderPanel(noteWithAttributes());- // The panel's own button offers every kind; the definitions card offers the two definitions.- const [ ownedMenu, definitionsMenu ] = [ ...container.querySelectorAll<HTMLElement>(".card-header-buttons .bx-plus") ];- act(() => ownedMenu.click());- act(() => definitionsMenu.click());+ // One list, so one button, and it offers every kind: the definitions had a button of their+ // own while they had a card of their own, which offered nothing this one does not.+ const addButton = container.querySelector<HTMLElement>(".card-header-buttons .bx-plus");+ act(() => addButton?.click());- const offered = showContextMenu.mock.calls.map(([ { items } ]) => items.length);- // Four kinds and the rule setting the definitions apart, against the two definitions on their own.- expect(offered).toEqual([ 5, 2 ]);+ // Four kinds and the rule setting the definitions apart from what they define.+ const { items } = showContextMenu.mock.calls[0][0];+ expect(items).toHaveLength(5);+ expect(items[2].kind).toBe("separator");// A definition still goes through the form, its settings needing one; nothing is saved until// it is closed, and a press beside it keeps the edits — which for a list of rows means saving.- act(() => showContextMenu.mock.calls[1][0].items[0].handler?.());+ act(() => items[3].handler?.());expect(document.querySelector(".attr-detail")).not.toBeNull();expect(put).not.toHaveBeenCalled();@@ -617,8 +632,7 @@ describe("AttributeList", () => {// hold open — and an inherited flag with no value is not something the note lacks.render(null, container);renderPanel(noteWithAttributes());- const inherited = container.querySelector("#attributes-inherited");- const archived = [ ...(inherited?.querySelectorAll(".attribute-row") ?? []) ]+ const archived = [ ...group("attributes-inherited").querySelectorAll(".attribute-row") ].find((row) => row.querySelector(".attribute-name")?.textContent === "archived");expect(archived?.querySelector(".attribute-value")?.className).not.toContain("value-placeholder");expect(archived?.querySelector(".attribute-value")?.textContent).toBe("");@@ -1021,20 +1035,24 @@ describe("AttributeList", () => {expect(selectedNames()).toEqual([ "template" ]);});- it("turns the card's foot over to what can be done to the rows picked out", async () => {+ it("stands a bar at the foot of the list saying what can be done to the rows picked out", async () => {renderPanel(noteWithAttributes());- // Nothing picked out: the foot is the way into adding an attribute, as it always was.- expect(container.querySelector(".attribute-add-row")).not.toBeNull();+ // Nothing picked out: no bar, and the list says it is not picking rows out — which is what+ // draws the checkboxes.expect(container.querySelector(".attribute-selection-bar")).toBeNull();- // The cards say they are not picking rows out, which is what draws the checkboxes.expect(firstPanel().className).not.toContain("selecting");checkbox(0).click();const bar = container.querySelector(".attribute-selection-bar");expect(bar).not.toBeNull();- expect(container.querySelector(".attribute-add-row")).toBeNull();expect(firstPanel().className).toContain("selecting");+ // The bar belongs to the whole list rather than to a run of it, the rows it acts on being+ // picked out anywhere: it stands at the list's own foot, outside every folding run.+ expect(bar?.closest(".attribute-group")).toBeNull();+ expect(bar?.closest(".attribute-list-panel")).not.toBeNull();+ // Adding an attribute stays on offer beside the note's own rows; the bar took nothing over.+ expect(container.querySelector(".attribute-add-row")).not.toBeNull();// Only that the count has a slot: the wording is translated, and translations stay unloaded.expect(bar?.querySelector(".attribute-selection-count")).not.toBeNull();@@ -1051,11 +1069,11 @@ describe("AttributeList", () => {checkbox(3).click();expect(barIcons()).not.toContain("bx bx-trash");- // The way out is letting every row go, which puts the add row back.+ // The way out is letting every row go, which takes the bar with it.act(() => barButton("bx bx-x")?.click());expect(selectedNames()).toEqual([]);expect(container.querySelector(".attribute-selection-bar")).toBeNull();- expect(container.querySelector(".attribute-add-row")).not.toBeNull();+ expect(firstPanel().className).not.toContain("selecting");});function rows() {@@ -1187,10 +1205,24 @@ describe("AttributeList", () => {});}- function cardIds() {- return [ ...container.querySelectorAll(".card") ].map((card) => card.id);+ function groupIds() {+ return [ ...container.querySelectorAll(".attribute-group") ]+ .map((el) => [ ...el.classList ].find((name) => name.startsWith("attributes-")));+ }++ function group(id: string) {+ const el = container.querySelector<HTMLElement>(`.attribute-group.${id}`);+ expect(el, id).not.toBeNull();+ return el as HTMLElement;}+ function groupHeader(id: string) {+ const header = group(id).querySelector<HTMLElement>(".attribute-group-header");+ expect(header, id).not.toBeNull();+ return header as HTMLElement;+ }++function firstRow() {const row = container.querySelector<HTMLElement>(".attribute-row");expect(row).not.toBeNull();diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsxindex a256a39daf..1de5f1edaa 100644--- a/apps/client/src/widgets/sidebar/AttributeList.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx@@ -22,7 +22,7 @@ import { ColorChip, renderLabelValue } from "../attribute_widgets/label_value_diimport ActionButton from "../react/ActionButton";import { FormListItem } from "../react/FormList";import HelpButton from "../react/HelpButton";-import { useActiveNoteContext, useTriliumEvent } from "../react/hooks";+import { useActiveNoteContext, useTriliumEvent, useTriliumOptionJson } from "../react/hooks";import Icon from "../react/Icon";import { DetailPane, MasterPane, useMasterDetail, useMasterDetailPage } from "../react/master_detail";import NoItems from "../react/NoItems";@@ -643,11 +643,6 @@ export default function AttributeList() {onEditValue: startValueEdit,onDelete: (attribute: Attribute) => void deleteAttribute(attribute)};- // The cards a section has nothing for are left out, so an ordinary note sees one or two of the four.- const shownCards = 1- + (sections.inherited.length ? 1 : 0)- + (sections.definitions.length ? 1 : 0)- + (internalRows.length ? 1 : 0);// The same callbacks whichever of the two the form is shown in.const formCallbacks = {@@ -668,116 +663,106 @@ export default function AttributeList() {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.- Which is also why the collapsing is offered here rather than left to the tab: the tab- counts this whole panel as one widget (see RightPanelContainer), being one entry in its- list. Down to a single card, collapsing it away is not on offer. */}- <CollapsibleWidgets.Provider value={shownCards > 1}>- <AttributeSection- id="attributes"- title={t("attribute_list_panel.owned", { count: sections.owned.length })}- grow- buttons={note && (- <>- <HelpButton helpPage={ATTRIBUTE_HELP_PAGE} />- <AddAttributeButton- text={t("attribute_editor.add_a_new_attribute")}- attrTypes={ALL_ATTRIBUTE_KINDS}- onSelect={addAttribute}- />- </>- )}+ // One card holding the lot, the sections being headings within it rather than cards of their+ // own: they are one list to the eye and one list to a selection — a range runs from any row to+ // any other — and four headers is a great deal of a hand-wide pane to spend on saying which+ // run is which. It also leaves the selection's own bar somewhere to belong: a bar at the foot+ // of one card among several belonged to a card the picked rows need not have been in at all.+ //+ // Collapsing moves to the headings with it. The card cannot be collapsed away, being all its+ // tab has (see RightPanelWidget), which is what the context below says.+ <CollapsibleWidgets.Provider value={false}>+ <AttributeSection+ id="attributes"+ title={t("attributes_panel.title")}+ grow+ buttons={note && (+ <>+ <HelpButton helpPage={ATTRIBUTE_HELP_PAGE} />+ <AddAttributeButton+ text={t("attribute_editor.add_a_new_attribute")}+ attrTypes={ALL_ATTRIBUTE_KINDS}+ onSelect={addAttribute}+ />+ </>+ )}+ >+ {/* Presses inside the list do not dismiss the popup (see `parent` above), which leaves+ closing on a press next to a row up to this handler. The whole list is what the+ note's own attributes are pasted onto, so it offers pasting beside its rows too. */}+ <div+ class={clsx("attribute-list-panel", isSelecting && "selecting")}+ ref={containerRef}+ onClick={commit}+ onContextMenu={showPanelMenu}+ {...clipboardProps}>- {/* Presses inside the sections do not dismiss the popup (see `parent` above), which- leaves closing on a press next to a row up to this handler. */}- {/* The values read from the trailing edge here and in the inherited card below,- the two lists of plain attributes reading as one ledger. The definitions keep- prose order: their "value" is a summary of settings, not a value. */}- {/* The card the note's own attributes are pasted onto, so it is the one that- offers pasting beside its rows as well as on them. */}- <div- class={clsx("attribute-list-panel align-values-end", isSelecting && "selecting")}- ref={containerRef}- onClick={commit}- onContextMenu={showPanelMenu}- {...clipboardProps}+ {/* A heading of their own, as every other run has: the card names the panel+ rather than this run, so without one the note's own attributes read as+ belonging to no run at all. Their values read from the trailing edge, as the+ inherited ones' do — the two runs of plain attributes reading as one ledger. */}+ <AttributeGroup+ id="attributes-owned"+ title={t("attribute_list_panel.owned", { count: sections.owned.length })}>{sections.owned.length > 0 ? (- <AttributeRowList rows={sections.owned} {...rowProps} />+ <AttributeRowList rows={sections.owned} alignValuesEnd {...rowProps} />) : (<NoItems icon="bx bx-hash" text={t("attribute_list_panel.no_attributes")} />)}- {/* What the foot of the card offers follows from what is being done at it:- while rows are picked out, what can be done to them, and otherwise the way- into adding one — which a phone reaches from the header, page flow and all. */}- {note && (isSelecting ? (- <AttributeSelectionBar- count={selection.size}- canDelete={selectedAttributes().every((candidate) => owned.current.includes(candidate))}- canPaste={getHeldAttributes().length > 0}- onCopy={() => void copyPickedAttributes(selectedAttributes())}- onPaste={() => void applyPaste(getHeldAttributes())}- onDelete={() => void deleteSelection(selectedAttributes())}- onClear={clearSelection}- />- ) : !IS_MOBILE && (+ {/* Inside the run it adds to rather than at the foot of everything, and put+ away with it. A phone adds from the header, page flow and all. */}+ {!IS_MOBILE && note && (<AddAttributeRow onAdd={(e) => addAttribute("label", e)} />- ))}- </div>- </AttributeSection>-- {sections.inherited.length > 0 && (- <AttributeSection- id="attributes-inherited"- title={t("attribute_list_panel.inherited", { count: sections.inherited.length })}- >- <div- class={clsx("attribute-list-panel align-values-end", isSelecting && "selecting")}- onClick={commit}- {...clipboardProps}+ )}+ </AttributeGroup>++ {sections.inherited.length > 0 && (+ <AttributeGroup+ id="attributes-inherited"+ title={t("attribute_list_panel.inherited", { count: sections.inherited.length })}>- <AttributeRowList rows={sections.inherited} {...rowProps} />- </div>- </AttributeSection>- )}+ <AttributeRowList rows={sections.inherited} alignValuesEnd {...rowProps} />+ </AttributeGroup>+ )}- {sections.definitions.length > 0 && (- <AttributeSection- id="attributes-definitions"- title={t("attribute_list_panel.definitions", { count: sections.definitions.length })}- buttons={note && (- <AddAttributeButton- text={t("attribute_list_panel.add_definition")}- attrTypes={DEFINITION_KINDS}- onSelect={addAttribute}- />- )}- >- <div- class={clsx("attribute-list-panel", isSelecting && "selecting")}- onClick={commit}- {...clipboardProps}+ {sections.definitions.length > 0 && (+ // The definitions keep prose order: their "value" is a summary of settings+ // rather than a value, so there is no column of values for it to line up in.+ <AttributeGroup+ id="attributes-definitions"+ title={t("attribute_list_panel.definitions", { count: sections.definitions.length })}><AttributeRowList rows={sections.definitions} {...rowProps} />- </div>- </AttributeSection>- )}+ </AttributeGroup>+ )}- {internalRows.length > 0 && (- <AttributeSection- id="attributes-internal"- title={t("attribute_list_panel.internal", { count: internalRows.length })}- >- <div class="attribute-list-panel" onClick={commit}>+ {internalRows.length > 0 && (+ <AttributeGroup+ id="attributes-internal"+ title={t("attribute_list_panel.internal", { count: internalRows.length })}+ ><AttributeRowList rows={internalRows} readOnly {...rowProps} />- </div>- </AttributeSection>- )}- </CollapsibleWidgets.Provider>- </>+ </AttributeGroup>+ )}++ {/* At the foot of the whole list, the rows it acts on being picked out anywhere+ in it. It holds there while the list is scrolled (see the stylesheet). */}+ {note && isSelecting && (+ <AttributeSelectionBar+ count={selection.size}+ canDelete={selectedAttributes().every((candidate) => owned.current.includes(candidate))}+ canPaste={getHeldAttributes().length > 0}+ onCopy={() => void copyPickedAttributes(selectedAttributes())}+ onPaste={() => void applyPaste(getHeldAttributes())}+ onDelete={() => void deleteSelection(selectedAttributes())}+ onClear={clearSelection}+ />+ )}+ </div>+ </AttributeSection>+ </CollapsibleWidgets.Provider>);// Inside a master-detail host the list and the form are its two panes, which it slides over each@@ -848,6 +833,53 @@ function AttributeSection({ id, title, children, buttons, grow }: AttributeSecti);}+/**+ * One run of rows under a heading that folds it away: the note's own attributes, what reaches it+ * from elsewhere, the definitions behind either, and — in a development build — what Trilium wrote+ * for itself. The card names the panel rather than any one of them, so each says what it is itself.+ *+ * A card each is what they were before, which spent four headers' worth of a hand-wide pane on+ * saying which run was which. What is kept from those cards is the folding — a template's dozens of+ * inherited attributes can still be put away — and what it is remembered under, so a pane that had+ * them put away has them put away still.+ */+function AttributeGroup({ id, title, children }: { id: string; title: string; children: ComponentChildren }) {+ const [ collapsedItems, setCollapsedItems ] = useTriliumOptionJson<string[]>("rightPaneCollapsedItems");+ const [ collapsed, setCollapsed ] = useState(collapsedItems.includes(id));++ function toggle() {+ const remembered = new Set(collapsedItems);+ if (collapsed) {+ remembered.delete(id);+ } else {+ remembered.add(id);+ }++ setCollapsed(!collapsed);+ void setCollapsedItems([ ...remembered ]);+ }++ return (+ // Named by its id as the card it stands in for was, which is what a stylesheet — or a test —+ // knows the run by.+ <div class={clsx("attribute-group", id, collapsed && "collapsed")}>+ <div+ class="attribute-group-header"+ onClick={(e) => {+ // Kept from the list, whose handler would close a form this press is not about.+ e.stopPropagation();+ toggle();+ }}+ >+ <Icon className="attribute-group-chevron" icon="bx bx-chevron-down" />+ <span class="attribute-group-title">{title}</span>+ </div>++ {!collapsed && children}+ </div>+ );+}+interface AttributeRowListProps {rows: AttributeEntry[];/** The note the rows belong to, read for the definitions that type their values. */@@ -860,6 +892,13 @@ interface AttributeRowListProps {selection: ReadonlySet<string>;/** Whether rows are being picked out, which every row is drawn for rather than only the picked. */selecting: boolean;+ /**+ * Set the values against the rows' trailing edge, so that they line up in a column of their own:+ * the name reads from the one edge and the value from the other, and the gap between them says+ * how much room is left rather than being dead space after every short value. For the runs of+ * plain attributes; a definition's summary keeps prose order, having no value to line up.+ */+ alignValuesEnd?: boolean;/*** The rows stand for attributes Trilium writes and keeps up to date itself, which leaves them* nothing to offer: nothing to edit, nothing to delete, no note to name as their source (they are@@ -882,14 +921,18 @@ interface AttributeRowListProps {* Trilium reads for itself. What a row offers follows from whether the note owns its attribute rather* than from the card it is in: the definitions card holds the note's own alongside a template's.*/-function AttributeRowList({ rows, note, activeAttribute, valueEditor, selection, selecting, readOnly, onOpen, onSelect, onShowMenu, onEditValue, onDelete }: AttributeRowListProps) {+function AttributeRowList({ rows, note, activeAttribute, valueEditor, selection, selecting, readOnly, alignValuesEnd, onOpen, onSelect, onShowMenu, onEditValue, onDelete }: AttributeRowListProps) {function renderRows(group: AttributeEntry[]) {return (// The rows are menu items on a phone (see AttributeRow), and the theme dresses a menu item// through the menu around it — so the list stands in as that menu, the way the other lists// of menu items outside a dropdown do (`dropdown-menu static show`, as in the code-note// switcher). Static: it opens nowhere and is positioned by nothing.- <ul class={clsx("attribute-rows", IS_MOBILE && "dropdown-menu tn-dropdown-menu static show")}>+ <ul class={clsx(+ "attribute-rows",+ alignValuesEnd && "align-values-end",+ IS_MOBILE && "dropdown-menu tn-dropdown-menu static show"+ )}>{group.map(({ attribute, isOwned, isSystem }, index) => (<AttributeRowkey={attribute.attributeId ?? `new-${index}`}@@ -1559,9 +1602,6 @@ const ADD_MENU_ENTRIES: { attrType: AttributeKind; title: string; icon: string }const ALL_ATTRIBUTE_KINDS = ADD_MENU_ENTRIES.map((entry) => entry.attrType);-/** The kinds the definitions card can add: the last two of the menu above, on their own. */-const DEFINITION_KINDS: AttributeKind[] = [ "label-definition", "relation-definition" ];-function showAddMenu(e: MouseEvent, attrTypes: AttributeKind[], onSelect: (attrType: AttributeKind) => void) {const offered = ADD_MENU_ENTRIES.filter((entry) => attrTypes.includes(entry.attrType));const items: MenuItem<never>[] = [];