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(attributes): stand the in-place editor over its row
Elian Doran870b44613f3a
diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsxindex 19a626ec43..dc6d0fd7de 100644--- a/apps/client/src/widgets/collections/table/columns.tsx+++ b/apps/client/src/widgets/collections/table/columns.tsx@@ -12,10 +12,10 @@ import { applyLinkScheme, asLabelValues, formatLabelDate, LabelValueChips } fromimport LabelValueInput from "../../attribute_widgets/label_value_input.jsx";import MultiValueInput from "../../attribute_widgets/multi_value_input.jsx";import RelationValuesInput, { RelationValueChips } from "../../attribute_widgets/relation_values_input.jsx";+import { useGrowsUpwards } from "../../react/grows_upwards.js";import Icon from "../../react/Icon.jsx";import NoteAutocomplete from "../../react/NoteAutocomplete.jsx";import { renderReactWidget } from "../../react/react_utils.jsx";-import { useGrowsUpwards } from "./grows_upwards.js";import type { TableData } from "./rows.js";type ColumnType = LabelType | "relation";diff --git a/apps/client/src/widgets/collections/table/grows_upwards.spec.tsx b/apps/client/src/widgets/react/grows_upwards.spec.tsxsimilarity index 100%rename from apps/client/src/widgets/collections/table/grows_upwards.spec.tsxrename to apps/client/src/widgets/react/grows_upwards.spec.tsxdiff --git a/apps/client/src/widgets/collections/table/grows_upwards.ts b/apps/client/src/widgets/react/grows_upwards.tssimilarity index 100%rename from apps/client/src/widgets/collections/table/grows_upwards.tsrename to apps/client/src/widgets/react/grows_upwards.tsdiff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.cssindex 426656b70a..43e387e933 100644--- a/apps/client/src/widgets/sidebar/AttributeList.css+++ b/apps/client/src/widgets/sidebar/AttributeList.css@@ -28,6 +28,15 @@background-color: var(--hover-item-background-color);}+/* While its value is edited, the row is what the editor stands over (see AttributeValueEditor.css):+ it anchors the overlay, lets it spill past the one line the row keeps to, and comes forward so the+ editor is drawn over the rows below rather than under them. */+.attribute-list-panel .attribute-row.editing {+ position: relative;+ overflow: visible;+ z-index: 10;+}+/** The kind of the attribute, as the icon of what it is (a label or a relation). It is the only thing* saying so, the row carrying neither the `#`/`~` prefix nor the type as a word.diff --git a/apps/client/src/widgets/sidebar/AttributeValueEditor.css b/apps/client/src/widgets/sidebar/AttributeValueEditor.cssindex c23ecef29d..98b79f1e52 100644--- a/apps/client/src/widgets/sidebar/AttributeValueEditor.css+++ b/apps/client/src/widgets/sidebar/AttributeValueEditor.css@@ -1,6 +1,30 @@+/*+ * The editor opens over its row rather than in it — the turn the table's cell editor takes (see+ * columns.css): a row is one line of a hand-wide pane, which a field with room to type in outgrows+ * at once. Laid out within, the field got only what was left after the name; standing over the row+ * it takes all of it past the name — which keeps saying what is being edited, out from under the+ * surface — though never more than the row's leading fifth is spared for one: past the cap a long+ * name is cut at the overlay's edge rather than the field squeezed for its sake.+ *+ * The row it belongs to therefore stops clipping while it is edited (see AttributeList.css), and+ * comes forward so the editor is drawn over the rows below rather than under them.+ */.attribute-list-panel .attribute-value-editor {- flex: 1;- min-width: 0;+ position: absolute;+ /* A hair past the row block-wise and at its trailing edge, so the surface reads as standing+ over the row rather than cut to its shape; held off the name's own reach (measured by the+ editor, which hands it over in the variable), the cap catching where there is none to hold. */+ inset-block-start: -2px;+ inset-inline-start: min(var(--value-editor-name-end, 20%), 20%);+ inset-inline-end: -2px;++ /* The surface of its own it stands on: opaque, because a field's background is a translucent+ film meant for the page behind it, through which the row would otherwise be read along. */+ padding: 2px;+ background-color: var(--main-background-color);+ border-radius: 8px;+ box-shadow: 0 4px 12px rgba(0, 0, 0, var(--dropdown-shadow-opacity, 0.2));+display: flex;align-items: center;gap: 4px;@@ -41,3 +65,11 @@min-width: 0;}}++/* Anchored by its foot instead, so that what it outgrows the row by rises over what has been read+ already rather than pressing past the foot of the pane. Applied from the editor, which is what+ can tell the room is short (see useGrowsUpwards). */+.attribute-list-panel .attribute-value-editor.grows-upwards {+ inset-block-start: auto;+ inset-block-end: -2px;+}diff --git a/apps/client/src/widgets/sidebar/AttributeValueEditor.tsx b/apps/client/src/widgets/sidebar/AttributeValueEditor.tsxindex 54ed246c68..fe3443c127 100644--- a/apps/client/src/widgets/sidebar/AttributeValueEditor.tsx+++ b/apps/client/src/widgets/sidebar/AttributeValueEditor.tsx@@ -1,7 +1,8 @@import "./AttributeValueEditor.css";import type { LabelType } from "@triliumnext/commons";-import { useEffect, useMemo, useRef } from "preact/hooks";+import clsx from "clsx";+import { useEffect, useLayoutEffect, useMemo, useRef } from "preact/hooks";import type FNote from "../../entities/fnote";import type { Attribute } from "../../services/attribute_parser";@@ -9,6 +10,7 @@ import { getBuiltinLabelSelectOptions, getBuiltinLabelValueType, isBuiltinAttribimport { t } from "../../services/i18n";import LabelValueInput, { getTypedInputForLabel } from "../attribute_widgets/label_value_input";import { AUTOCOMPLETE_DROPDOWN_SELECTOR } from "../react/FormAutocomplete";+import { useGrowsUpwards } from "../react/grows_upwards";import NoteAutocomplete from "../react/NoteAutocomplete";interface AttributeValueEditorProps {@@ -35,7 +37,29 @@ interface AttributeValueEditorProps {*/export default function AttributeValueEditor({ note, attribute, onEdit, onCommit, onRevert }: AttributeValueEditorProps) {const containerRef = useRef<HTMLSpanElement>(null);+ // The editor stands over its row rather than in it (see the stylesheet), so near the foot of the+ // pane it is anchored by its foot instead, what it outgrows the row by rising over what has been+ // read already — the same turn the table's cell editor takes, through the same measure.+ const growsUpwards = useGrowsUpwards(containerRef);const isRelation = attribute.type === "relation";++ // The overlay is held off the row's leading edge so the name stays readable (see the stylesheet)+ // — but only as far as the name actually reaches, told to the stylesheet here: a short name would+ // otherwise sit apart from its editor, with an odd gap where the cap had room to spare. Measured+ // once, before the paint that would show the gap: nothing here edits the name.+ useLayoutEffect(() => {+ const editor = containerRef.current;+ const row = editor?.parentElement;+ const name = row?.querySelector<HTMLElement>(".attribute-name");+ if (!editor || !row || !name) return;++ const rowRect = row.getBoundingClientRect();+ const nameRect = name.getBoundingClientRect();+ const nameEnd = getComputedStyle(row).direction === "rtl"+ ? rowRect.right - nameRect.left+ : nameRect.right - rowRect.left;+ editor.style.setProperty("--value-editor-name-end", `${Math.ceil(nameEnd) + ROW_GAP}px`);+ }, []);// What a label is typed as; a relation's field follows from being one.const typed = useMemo(() => isRelation ? undefined : resolveValueField(note, attribute.name),@@ -94,7 +118,7 @@ export default function AttributeValueEditor({ note, attribute, onEdit, onCommitreturn (<spanref={containerRef}- className="attribute-value-editor"+ className={clsx("attribute-value-editor", growsUpwards && "grows-upwards")}// Keep the press from reaching the row, which would open the popup over the edit.onClick={(e) => e.stopPropagation()}onMouseDown={(e) => {@@ -156,6 +180,9 @@ const TARGET_NOTE_OPTS = { allowCreatingNotes: true, hideAllButtons: true };/** The input types whose content `select()` applies to; the pickers select nothing and mind nothing. */const SELECT_ALL_TYPES = new Set([ "text", "number", "url", "email", "tel" ]);+/** The breath between the name and the overlay's edge: the gap the row lays its items out with. */+const ROW_GAP = 6;+/*** What kind of field the label's value is edited through: for a system label the same closed sets and* kinds the detail form offers, exclusions included (a flag means what its presence means, so no