Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): edit a label's value straight in its row

Elian Doran91df3c3ed92f
diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.css
index 927fcfbf2a..ef20f4a05f 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.css
+++ b/apps/client/src/widgets/sidebar/AttributeList.css
@@ -23,7 +23,8 @@
}
.attribute-list-panel .attribute-row:hover,
-.attribute-list-panel .attribute-row.active {
+.attribute-list-panel .attribute-row.active,
+.attribute-list-panel .attribute-row.editing {
background-color: var(--hover-item-background-color);
}
@@ -101,6 +102,12 @@
opacity: 0.7;
}
+/* A label's value is edited in place, so the preview itself is a click target of its own: a text
+ cursor over it says as much, where the row around it — which opens the popup — points. */
+.attribute-list-panel .attribute-value.editable {
+ cursor: text;
+}
+
/* The settings of a definition, which are a summary and not a value: quieter than one, and never the
reason the row is as wide as it is. Lowercased, the settings being sentence-cased words of Trilium's
own read as a list where they read as a sentence otherwise. */
@@ -137,7 +144,8 @@
}
.attribute-list-panel .attribute-row:hover .attribute-delete-button,
-.attribute-list-panel .attribute-row.active .attribute-delete-button {
+.attribute-list-panel .attribute-row.active .attribute-delete-button,
+.attribute-list-panel .attribute-row.editing .attribute-delete-button {
visibility: visible;
}
diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
index 5eba51da20..48e0f6beff 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
@@ -336,6 +336,87 @@ describe("AttributeList", () => {
]);
});
+ it("edits an owned label's value in place, saving it once the field is left", async () => {
+ renderPanel(noteWithAttributes());
+
+ // The values offered for editing in place are exactly the owned labels': not a relation's
+ // (whose value is a link), not a definition's (whose value is a summary), not an inherited row's.
+ expect([ ...container.querySelectorAll(".attribute-value.editable") ]).toHaveLength(2);
+
+ act(() => firstRow().querySelector<HTMLElement>(".attribute-value")?.click());
+
+ // The press edits in place rather than opening the popup, in the field the value calls for.
+ expect(document.querySelector(".attr-detail")).toBeNull();
+ const input = container.querySelector<HTMLInputElement>(".attribute-value-editor input");
+ expect(input?.value).toBe("Elian");
+
+ act(() => {
+ if (input) {
+ input.value = "Someone else";
+ input.dispatchEvent(new Event("input", { bubbles: true }));
+ }
+ });
+ await act(async () => {
+ input?.dispatchEvent(new FocusEvent("focusout", { bubbles: true, relatedTarget: document.body }));
+ });
+
+ // Leaving the field ends the edit and saves it; the row shows the value again, as typed.
+ expect(container.querySelector(".attribute-value-editor")).toBeNull();
+ expect(put).toHaveBeenCalledOnce();
+ const [ url, saved ] = put.mock.calls[0] as [ string, { name: string; value: string }[] ];
+ expect(url).toBe("notes/subject/attributes");
+ expect(saved.find((attribute) => attribute.name === "author")?.value).toBe("Someone else");
+ expect(firstRow().querySelector(".attribute-value")?.textContent).toBe("Someone else");
+ });
+
+ it("puts the value back on escape, and saves nothing for an edit that changed nothing", async () => {
+ renderPanel(noteWithAttributes());
+
+ act(() => firstRow().querySelector<HTMLElement>(".attribute-value")?.click());
+ const input = container.querySelector<HTMLInputElement>(".attribute-value-editor input");
+ act(() => {
+ if (input) {
+ input.value = "discarded";
+ input.dispatchEvent(new Event("input", { bubbles: true }));
+ }
+ });
+ act(() => {
+ input?.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
+ });
+
+ expect(container.querySelector(".attribute-value-editor")).toBeNull();
+ expect(firstRow().querySelector(".attribute-value")?.textContent).toBe("Elian");
+
+ // Entered and left alone: nothing changed, so nothing is put to the server either way.
+ act(() => firstRow().querySelector<HTMLElement>(".attribute-value")?.click());
+ await act(async () => {
+ container.querySelector<HTMLInputElement>(".attribute-value-editor input")
+ ?.dispatchEvent(new FocusEvent("focusout", { bubbles: true, relatedTarget: document.body }));
+ });
+ expect(put).not.toHaveBeenCalled();
+ });
+
+ it("types the in-place field by what the label is: a closed set as a dropdown, a defined number by its definition", () => {
+ renderPanel(buildNote({ id: "sorted", title: "Sorted", "#sortDirection": "desc" }));
+ act(() => firstRow().querySelector<HTMLElement>(".attribute-value")?.click());
+
+ const select = container.querySelector<HTMLSelectElement>(".attribute-value-editor select");
+ expect(select?.value).toBe("desc");
+ expect([ ...(select?.options ?? []) ].map((option) => option.value)).toEqual([ "", "asc", "desc" ]);
+
+ render(null, container);
+ renderPanel(buildNote({
+ id: "scored", title: "Scored",
+ "#score": "3",
+ "#label:score": "promoted,single,number,precision=2"
+ }));
+ act(() => firstRow().querySelector<HTMLElement>(".attribute-value")?.click());
+
+ const input = container.querySelector<HTMLInputElement>(".attribute-value-editor input");
+ expect(input?.type).toBe("number");
+ expect(input?.step).toBe("0.01");
+ });
+
it("discards what the popup was told when it is closed rather than pressed away from", async () => {
renderPanel(noteWithAttributes());
diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsx
index abb395ae1d..23e6fcbd83 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx
@@ -27,13 +27,16 @@ import NoteLink from "../react/NoteLink";
import { ParentComponent } from "../react/react_utils";
import { ATTRIBUTE_HELP_PAGE } from "../ribbon/components/AttributeHelp";
import OptionsSection from "../type_widgets/options/components/OptionsSection";
+import AttributeValueEditor from "./AttributeValueEditor";
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
- * form the editor uses, which is where an attribute is actually edited.
+ * form the editor uses, which is where an attribute is actually edited — except an owned label's
+ * value, the edit that is made again and again: pressing the preview itself edits it in place,
+ * through the field its definition calls for (see {@link AttributeValueEditor}).
*
* 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
@@ -45,6 +48,9 @@ export default function AttributeList() {
const parentComponent = useContext(ParentComponent);
const containerRef = useRef<HTMLDivElement>(null);
const [ detail, setDetail ] = useState<AttributeDetailOpts | null>(null);
+ // The row whose value is being typed straight into it — the in-place alternative to the popup for
+ // a label — and the value to put back if the edit is thrown away rather than kept.
+ const [ valueEdit, setValueEdit ] = useState<{ attribute: Attribute; original: string } | null>(null);
const componentId = parentComponent?.componentId;
// The owned rows double as the detail popup's working copy: it edits the very objects it is handed,
@@ -63,10 +69,11 @@ export default function AttributeList() {
// attributes of the note navigated away from. The initial `undefined` is what collects the first.
const shownNoteId = useRef<string | null>();
if (shownNoteId.current !== (note?.noteId ?? null)) {
- // An attribute left open for editing is closed by the change of note, and closing keeps what
- // was typed into it — as a press outside does — rather than dropping it. Which the list cannot
- // do itself once it holds another note's attributes, hence the hand-over.
- if (detail?.isOwned && shownNoteId.current) {
+ // An attribute left open for editing — in the popup or in its own row — is closed by the
+ // change of note, and closing keeps what was typed into it — as a press outside does — rather
+ // than dropping it. Which the list cannot do itself once it holds another note's attributes,
+ // hence the hand-over.
+ if ((detail?.isOwned || valueEdit) && shownNoteId.current) {
draftToFlush.current = { noteId: shownNoteId.current, attributes: owned.current };
}
@@ -76,9 +83,10 @@ export default function AttributeList() {
internal.current = collectInternal(note);
}
- // The form edits one attribute of the note being left, so it closes with the note.
+ // Either editor works on one attribute of the note being left, so both close with the note.
useEffect(() => {
setDetail(null);
+ setValueEdit(null);
const draft = draftToFlush.current;
draftToFlush.current = null;
@@ -88,15 +96,22 @@ export default function AttributeList() {
}, [ note ]);
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
- // While the popup is open, the changes this widget itself made are skipped: its edits are the
- // freshest state, and reloading over them would discard what is being typed. Once it is closed
- // our own saves count too, which is how the list drops a row the server refused to keep (a
- // relation left without a target note).
- const changed = detail ? loadResults.getAttributeRows(componentId) : loadResults.getAttributeRows();
+ // While either editor is open, the changes this widget itself made are skipped: its edits are
+ // the freshest state, and reloading over them would discard what is being typed. Once both are
+ // closed our own saves count too, which is how the list drops a row the server refused to keep
+ // (a relation left without a target note).
+ const changed = detail || valueEdit ? loadResults.getAttributeRows(componentId) : loadResults.getAttributeRows();
if (note && changed.some((attr) => attributes.isAffecting(attr, note))) {
owned.current = collectOwned(note);
inherited.current = collectInherited(note);
internal.current = collectInternal(note);
+
+ // The rebuild replaced the row objects, so an in-place edit over one of the old ones has
+ // nothing left to write to; it is dropped rather than left dangling over the fresher state.
+ if (valueEdit && !owned.current.includes(valueEdit.attribute)) {
+ setValueEdit(null);
+ }
+
rerender();
}
});
@@ -163,6 +178,32 @@ export default function AttributeList() {
}
}
+ /** Opens the in-place editor over a row's value, taking over from the popup if one is open. */
+ function startValueEdit(attribute: Attribute) {
+ if (detail) {
+ commit();
+ }
+ setValueEdit({ attribute, original: attribute.value ?? "" });
+ }
+
+ /** Closes the in-place editor keeping what was typed, saved only where it changed anything. */
+ function commitValueEdit() {
+ const changed = valueEdit && valueEdit.attribute.value !== valueEdit.original;
+
+ setValueEdit(null);
+ if (changed) {
+ void save();
+ }
+ }
+
+ /** Closes the in-place editor putting the value back as it was, saving nothing. */
+ function revertValueEdit() {
+ if (valueEdit) {
+ valueEdit.attribute.value = valueEdit.original;
+ }
+ setValueEdit(null);
+ }
+
// 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);
@@ -186,9 +227,30 @@ export default function AttributeList() {
const sections = splitIntoSections(owned.current, inherited.current);
const internalRows = internal.current.map((attribute) => toEntry(attribute, true));
+ // Not built for an attribute the list no longer holds: a reload can rebuild the rows out from
+ // under the editor within this very render, before the state has caught up (see above).
+ const activeValueEdit = valueEdit && owned.current.includes(valueEdit.attribute) ? valueEdit : null;
+ const valueEditor = note && activeValueEdit ? {
+ attribute: activeValueEdit.attribute,
+ element: (
+ <AttributeValueEditor
+ note={note}
+ attribute={activeValueEdit.attribute}
+ // Written straight into the row's attribute, as the popup writes its edits; the rows
+ // are not redrawn for it, the field itself being the only thing showing the value.
+ onEdit={(value) => {
+ activeValueEdit.attribute.value = value;
+ }}
+ onCommit={commitValueEdit}
+ onRevert={revertValueEdit}
+ />
+ )
+ } : undefined;
const rowProps = {
activeAttribute: detail?.attribute,
+ valueEditor,
onOpen: openDetail,
+ 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.
@@ -364,6 +426,8 @@ interface AttributeRowListProps {
rows: AttributeEntry[];
/** The attribute the detail popup is showing, marked as such in the list. */
activeAttribute?: Attribute;
+ /** The in-place editor over one row's value, shown by that row in the value's place. */
+ valueEditor?: { attribute: Attribute; element: ComponentChildren };
/**
* 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
@@ -372,6 +436,8 @@ interface AttributeRowListProps {
*/
readOnly?: boolean;
onOpen: (attribute: Attribute, isOwned: boolean, anchor: HTMLElement | null, e: MouseEvent) => void;
+ /** Asks for the in-place editor over the attribute's value; wired to editable labels alone. */
+ onEditValue: (attribute: Attribute) => void;
onDelete: (attribute: Attribute) => void;
}
@@ -380,7 +446,7 @@ 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, activeAttribute, readOnly, onOpen, onDelete }: AttributeRowListProps) {
+function AttributeRowList({ rows, activeAttribute, valueEditor, readOnly, onOpen, 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
@@ -393,11 +459,18 @@ function AttributeRowList({ rows, activeAttribute, readOnly, onOpen, onDelete }:
key={attribute.attributeId ?? `new-${index}`}
attribute={attribute}
active={activeAttribute === attribute}
+ valueEditor={valueEditor?.attribute === attribute ? valueEditor.element : undefined}
isSystem={isSystem && !readOnly}
// An attribute of another note names it; the current note's own would name itself.
showOwner={!isOwned && !readOnly}
// A read-only row opens the popup as an inherited one does: to be read, not edited.
onOpen={(anchor, e) => onOpen(attribute, isOwned && !readOnly, anchor, e)}
+ // A label's value is typed straight into its row; everything else — relations,
+ // whose value press follows the link, definitions, whose value is a summary —
+ // keeps the popup. On a phone the row is a menu item and opens its page whole.
+ onEditValue={isOwned && !readOnly && !IS_MOBILE && getAttributeKind(attribute) === "label"
+ ? () => onEditValue(attribute)
+ : undefined}
onDelete={isOwned && !readOnly ? () => onDelete(attribute) : undefined}
/>
))}
@@ -423,20 +496,24 @@ interface AttributeRowProps {
attribute: Attribute;
/** Whether the detail popup is currently showing this attribute. */
active: boolean;
+ /** The in-place editor over this row's value, rendered in the value's place. */
+ valueEditor?: ComponentChildren;
/** Whether the name is one Trilium reads for itself rather than one the note was given. */
isSystem?: boolean;
/** Names the note the attribute is inherited from, for attributes not owned by the current note. */
showOwner?: boolean;
onOpen: (anchor: HTMLElement | null, e: MouseEvent) => void;
+ /** Starts the in-place edit of the value; absent for rows whose value is not edited in place. */
+ onEditValue?: () => void;
onDelete?: () => void;
}
-function AttributeRow({ attribute, active, isSystem, showOwner, onOpen, onDelete }: AttributeRowProps) {
+function AttributeRow({ attribute, active, valueEditor, isSystem, showOwner, onOpen, onEditValue, onDelete }: AttributeRowProps) {
const rowRef = useRef<HTMLLIElement>(null);
const attrType = getAttributeKind(attribute);
const marker = getKindMarker(attribute, attrType, isSystem);
const kindIcon = getKindIcon(attribute, attrType);
- const rowClass = clsx("attribute-row", active && "active");
+ const rowClass = clsx("attribute-row", active && "active", valueEditor && "editing");
function open(e: MouseEvent) {
// Keep the container's closing handler from undoing this.
@@ -448,7 +525,7 @@ function AttributeRow({ attribute, active, isSystem, showOwner, onOpen, onDelete
<>
<span class="attribute-name">{getDisplayName(attribute, attrType)}</span>
- <AttributeValue attribute={attribute} attrType={attrType} />
+ {valueEditor ?? <AttributeValue attribute={attribute} attrType={attrType} onEdit={onEditValue} />}
{attribute.isInheritable && (
<Icon
@@ -565,8 +642,17 @@ function getDefinitionType(attribute: Attribute, attrType: AttributeKind) {
return DEFINITION_TYPES.find((definitionType) => definitionType.value === value);
}
-/** A preview of what the attribute holds — the row stands for the attribute, the popup shows it in full. */
-function AttributeValue({ attribute, attrType }: { attribute: Attribute; attrType: AttributeKind }) {
+/**
+ * A preview of what the attribute holds — the row stands for the attribute, the popup shows it in
+ * full. A label's preview is also where its value is edited: pressing it swaps the text for the field
+ * (see {@link AttributeValueEditor}), where the row around it opens the popup.
+ */
+function AttributeValue({ attribute, attrType, onEdit }: {
+ attribute: Attribute;
+ attrType: AttributeKind;
+ /** Starts the in-place edit; only ever handed to a label's preview. */
+ onEdit?: () => void;
+}) {
if (attrType === "relation") {
// A relation just created from the add menu has no target yet.
return attribute.value
@@ -580,7 +666,19 @@ function AttributeValue({ attribute, attrType }: { attribute: Attribute; attrTyp
// A label with no value still gets its slot: it is what takes up the room between the name and what
// the row ends with, so a bare label lines its markers and its delete button up with every other row's.
- return <span class="attribute-value" title={attribute.value}>{attribute.value}</span>;
+ return (
+ <span
+ class={clsx("attribute-value", onEdit && "editable")}
+ title={attribute.value}
+ // Kept from the row, which would open the popup over the field this press asks for.
+ onClick={onEdit ? (e) => {
+ e.stopPropagation();
+ onEdit();
+ } : undefined}
+ >
+ {attribute.value}
+ </span>
+ );
}
/**
diff --git a/apps/client/src/widgets/sidebar/AttributeValueEditor.css b/apps/client/src/widgets/sidebar/AttributeValueEditor.css
new file mode 100644
index 0000000000..8b1a6962f2
--- /dev/null
+++ b/apps/client/src/widgets/sidebar/AttributeValueEditor.css
@@ -0,0 +1,35 @@
+.attribute-list-panel .attribute-value-editor {
+ flex: 1;
+ min-width: 0;
+ display: flex;
+ align-items: center;
+ gap: 4px;
+
+ /* Sized to sit in a row of text rather than in a form. */
+ & .form-control,
+ & .form-select {
+ min-width: 0;
+ height: auto;
+ padding: 0 6px;
+ font-size: inherit;
+ line-height: 1.5;
+ }
+
+ /* A checkbox is its own size; the field class would stretch it across the row. */
+ & input[type="checkbox"] {
+ flex: 0 0 auto;
+ width: auto;
+ height: auto;
+ }
+
+ /* The one field that grows, downwards only: sideways there is nothing to grow into. */
+ & textarea.form-control {
+ resize: vertical;
+ }
+
+ /* The buttons beside a field (a colour's reset, a link's open), trimmed to the row's height. */
+ & .input-group-text {
+ padding: 0 5px;
+ cursor: pointer;
+ }
+}
diff --git a/apps/client/src/widgets/sidebar/AttributeValueEditor.tsx b/apps/client/src/widgets/sidebar/AttributeValueEditor.tsx
new file mode 100644
index 0000000000..01f456b03a
--- /dev/null
+++ b/apps/client/src/widgets/sidebar/AttributeValueEditor.tsx
@@ -0,0 +1,144 @@
+import "./AttributeValueEditor.css";
+
+import type { LabelType } from "@triliumnext/commons";
+import { useEffect, useMemo, useRef } from "preact/hooks";
+
+import type FNote from "../../entities/fnote";
+import type { Attribute } from "../../services/attribute_parser";
+import { getBuiltinLabelSelectOptions, getBuiltinLabelValueType, isBuiltinAttribute } from "../../services/attributes";
+import { t } from "../../services/i18n";
+import LabelValueInput, { getTypedInputForLabel } from "../attribute_widgets/label_value_input";
+
+interface AttributeValueEditorProps {
+ /** The note the label belongs to, read for the definition that says what kind of field to offer. */
+ note: FNote;
+ attribute: Attribute;
+ /** Receives the value as it is typed; the host writes it into the row it holds, and saves on commit. */
+ onEdit(value: string): void;
+ /** Close keeping the edits, which the host saves. */
+ onCommit(): void;
+ /** Close putting the value back as it was. */
+ onRevert(): void;
+}
+
+/**
+ * A label's value edited in the row that previews it, without opening the detail form: the same field
+ * its promoted counterpart offers — a date picker for a date, a palette for a colour, a dropdown for a
+ * closed set — or a plain box where nothing says more about the value than that it is one.
+ *
+ * Leaving the field is what ends the edit and keeps it, matching the attributes editor's save-on-blur;
+ * escape puts the value back instead. Only the value is edited here — the name, the flags and the
+ * definitions stay with the form the rest of the row opens.
+ */
+export default function AttributeValueEditor({ note, attribute, onEdit, onCommit, onRevert }: AttributeValueEditorProps) {
+ const containerRef = useRef<HTMLSpanElement>(null);
+ const typed = useMemo(() => resolveValueField(note, attribute.name), [ note, attribute.name ]);
+
+ // The editor exists because its row was pressed, so the field is ready to type into at once — and
+ // what is there is selected, a short value being more often replaced than appended to.
+ useEffect(() => {
+ const field = containerRef.current?.querySelector<HTMLElement>("input:not([type=hidden]), textarea, select");
+ field?.focus();
+ if ((field instanceof HTMLInputElement && SELECT_ALL_TYPES.has(field.type)) || field instanceof HTMLTextAreaElement) {
+ field.select();
+ }
+ }, []);
+
+ useEffect(() => {
+ const editor = containerRef.current;
+ if (!editor) return;
+
+ const onFocusOut = (e: FocusEvent) => {
+ // Focus moving within the editor — the field to a button beside it — is not leaving it.
+ if (e.relatedTarget instanceof Node && editor.contains(e.relatedTarget)) return;
+
+ // Nothing in the page took the focus over, and either the editor still holds it or the
+ // window itself has lost it — which is what opening a native picker's dialog does. The
+ // row has not been left, and committing here would close the editor under the dialog.
+ if (!e.relatedTarget && (!document.hasFocus() || editor.contains(document.activeElement))) {
+ return;
+ }
+
+ onCommit();
+ };
+
+ editor.addEventListener("focusout", onFocusOut);
+ return () => editor.removeEventListener("focusout", onFocusOut);
+ }, [ onCommit ]);
+
+ return (
+ <span
+ ref={containerRef}
+ className="attribute-value-editor"
+ // Keep the press from reaching the row, which would open the popup over the edit.
+ onClick={(e) => e.stopPropagation()}
+ onMouseDown={(e) => {
+ // The buttons beside a field (a colour's reset, a link's open) take no focus of their
+ // own: letting the press blur the field would commit and unmount the editor before the
+ // click could land on them.
+ if (e.target instanceof Element && !e.target.closest("input, textarea, select")) {
+ e.preventDefault();
+ }
+ }}
+ onKeyDown={(e) => {
+ if (e.key === "Escape") {
+ e.stopPropagation();
+ onRevert();
+ } else if (e.key === "Enter" && (typed.labelType !== "textarea" || e.ctrlKey || e.metaKey)) {
+ e.preventDefault();
+ e.stopPropagation();
+ onCommit();
+ }
+ }}
+ >
+ <LabelValueInput
+ labelType={typed.labelType}
+ value={attribute.value ?? ""}
+ onCommit={onEdit}
+ commitOn="input"
+ numberPrecision={typed.numberPrecision}
+ selectOptions={typed.selectOptions}
+ inputProps={{
+ className: "form-control",
+ // Names the dropdown's empty entry, as the detail form does for the same field.
+ ...(typed.labelType === "select" && {
+ placeholder: t("promoted_attributes.unset-field-placeholder")
+ })
+ }}
+ />
+ </span>
+ );
+}
+
+/** 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" ]);
+
+/**
+ * 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
+ * checkbox over it); for the rest whatever definition reaches the note for the name, promoted or not,
+ * down to the plain text box a label defined by nothing is typed into.
+ */
+function resolveValueField(note: FNote, name: string): {
+ labelType: LabelType;
+ selectOptions?: readonly string[];
+ numberPrecision?: number;
+} {
+ if (isBuiltinAttribute("label", name)) {
+ const labelType = getTypedInputForLabel(getBuiltinLabelValueType(name));
+ return {
+ labelType: labelType ?? "text",
+ selectOptions: labelType ? getBuiltinLabelSelectOptions(name) : undefined
+ };
+ }
+
+ const definition = note.getAttributeDefinitions()
+ .find((definitionAttr) => definitionAttr.name === `label:${name}`)
+ ?.getDefinition();
+
+ return {
+ labelType: definition?.labelType ?? "text",
+ selectOptions: definition?.selectOptions,
+ numberPrecision: definition?.numberPrecision
+ };
+}