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): mark attribute name suggestions with the panel's kind icon
Elian Doran1e242187331e
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsxindex 305a6460de..8182851f98 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx@@ -145,6 +145,33 @@ describe("attribute detail popup positioning", () => {});describe("attribute detail popup naming", () => {+ it("lists a name behind its kind icon, with the cog on a name Trilium reads for itself", async () => {+ const { AttributeNameSuggestion } = await import("./attribute_detail");+ const row = (type: "label" | "relation", name: string) => {+ const host = document.createElement("div");+ render(<AttributeNameSuggestion type={type} name={name} />, host);+ const kind = host.querySelector(".attr-name-suggestion > .attribute-kind");+ if (!kind) throw new Error("no kind icon rendered");+ return { kind, host };+ };++ const builtin = row("label", "archived");+ expect(builtin.kind.querySelector(".bx-hash")).not.toBeNull();+ expect(builtin.kind.classList.contains("marker-system")).toBe(true);+ expect(builtin.kind.getAttribute("title")).toBe("attribute_list_panel.system_hint");+ expect(builtin.host.querySelector(".attribute-kind + .attr-name-suggestion-name")?.textContent).toBe("archived");+ expect(builtin.host.querySelector(".ext-badge")).toBeNull();++ const invented = row("label", "myOwnLabel");+ expect(invented.kind.classList.contains("marker-system")).toBe(false);+ expect(invented.kind.hasAttribute("title")).toBe(false);++ // A name that is a built-in of the other type is not one here.+ const relation = row("relation", "archived");+ expect(relation.kind.querySelector(".bx-transfer")).not.toBeNull();+ expect(relation.kind.classList.contains("marker-system")).toBe(false);+ });+it("edits a definition under its bare name and stores it back under its prefix", async () => {const { addDefinitionPrefix, stripDefinitionPrefix } = await import("./attribute_detail");diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsxindex 74b5a9da0a..51a271d947 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx@@ -1,7 +1,8 @@import "./attribute_detail.css";-import "./attribute_name_suggestion.css";+import "./attribute_kind.css";import { type DefinitionObject, type LabelType, promotedAttributeDefinitionParser } from "@triliumnext/commons";+import clsx from "clsx";import { ComponentChildren, ComponentProps } from "preact";import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";@@ -26,13 +27,14 @@ import FormDropdownList from "../react/FormDropdownList.jsx";import { FormDropdownDivider, FormListItem } from "../react/FormList.jsx";import FormTextBox, { FormTextBoxWithUnit } from "../react/FormTextBox.jsx";import HelpTooltipButton from "../react/HelpTooltipButton.jsx";+import Icon from "../react/Icon.jsx";import { suspendModalFocusTraps } from "../react/modal_focustrap.js";import NoteAutocomplete from "../react/NoteAutocomplete.jsx";import NoteLink, { NewNoteLink } from "../react/NoteLink.jsx";import { disposeReactWidget, ParentComponent, renderReactWidgetAtElement } from "../react/react_utils.jsx";import OptionsRow, { OptionsRowWithToggle } from "../type_widgets/options/components/OptionsRow.jsx";import { ATTR_HELP, AttrHelpEntry } from "./attr_help.js";-import { DEFINITION_TYPE_ICONS, RELATION_DEFINITION_TYPE } from "./attribute_types.js";+import { attributeKindIcon, DEFINITION_TYPE_ICONS, RELATION_DEFINITION_TYPE } from "./attribute_types.js";import LabelValueInput, { getTypedInputForLabel, useLabelValueSuggestions } from "./label_value_input.js";import ValuesInput from "./values_input.jsx";@@ -779,18 +781,25 @@ function AttributeNameField({ help, ...autocompleteProps }: { help?: AttrHelpEnt}/**- * One row of an attribute name completion, marking the names Trilium itself attaches a meaning to.- * The mark answers what a list of bare names cannot: whether picking one buys behaviour, or is only- * a name. The inline editor's `#`/`~` completion lists the same names and marks them the same way.+ * One row of an attribute name completion: the name behind the kind icon the attributes panel gives+ * it, with the cog that panel marks the names Trilium itself attaches a meaning to. The mark answers+ * what a list of bare names cannot: whether picking one buys behaviour, or is only a name.** Exported, with {@link fetchAttributeNames}, for whatever else completes an attribute name — the* attribute panel's in-row creation — so every name box offers the same list the same way.*/export function AttributeNameSuggestion({ type, name }: { type: "label" | "relation"; name: string }) {+ const isSystem = isBuiltinAttribute(type, name);+return (<span class="attr-name-suggestion">+ <span+ class={clsx("attribute-kind", isSystem && "marker-system")}+ title={isSystem ? t("attribute_list_panel.system_hint") : undefined}+ >+ <Icon icon={attributeKindIcon(type, name, "")} />+ </span><span class="attr-name-suggestion-name">{name}</span>- {isBuiltinAttribute(type, name) && <Badge outline text={t("attribute_names.system")} />}</span>);}diff --git a/apps/client/src/widgets/attribute_widgets/attribute_kind.css b/apps/client/src/widgets/attribute_widgets/attribute_kind.cssnew file mode 100644index 0000000000..02bfd79c5b--- /dev/null+++ b/apps/client/src/widgets/attribute_widgets/attribute_kind.css@@ -0,0 +1,67 @@+/*+ * The kind of an attribute, as the icon of what it is (a label or a relation), worn by the rows of+ * the attributes panel and by the rows of every list of attribute names, which are portalled to the+ * body and so scoped by the row rather than by a widget root.+ */+:is(.attribute-list-panel, .attr-name-suggestion) .attribute-kind {+ /* What the badge on the corner is punched out of: the surface the icon stands on. */+ --attribute-kind-cutout: var(--card-background-color, var(--main-background-color));+ position: relative;+ display: flex;+ flex-shrink: 0;+ color: var(--muted-text-color);+}++/*+ * A badge on the corner of the icon: a cog for the names Trilium reads for itself (settings of the note+ * rather than a word for it), a chevron for a definition of a promoted field (one lifted out of the+ * attributes and into the note's own ribbon). A second glyph rather than an icon of its own, so+ * `cssClass` still reads as the label it is, and a promoted date field as the date field it defines.+ */+:is(.attribute-list-panel, .attr-name-suggestion) .attribute-kind.marker-system::after,+:is(.attribute-list-panel, .attr-name-suggestion) .attribute-kind.marker-promoted::after {+ position: absolute;+ inset-inline-end: -3px;+ bottom: -2px;+ font-family: boxicons;+ font-size: 0.62em;+ font-weight: normal;+ line-height: 1;+ /* Punched out of the icon it sits on, so the two glyphs stay legible where they overlap. */+ text-shadow:+ 0 0 2px var(--attribute-kind-cutout),+ 0 0 2px var(--attribute-kind-cutout);+}++:is(.attribute-list-panel, .attr-name-suggestion) .attribute-kind.marker-system::after {+ content: "\ea6e"; /* lookup code for "cog" in boxicons.css */+}++:is(.attribute-list-panel, .attr-name-suggestion) .attribute-kind.marker-promoted::after {+ content: "\ea57"; /* lookup code for "chevron-up" in boxicons.css */+ /* A single stroke where the cog is a whole shape, so it is drawn a size up to weigh the same. */+ font-size: 0.8em;+ inset-inline-end: -4px;+ bottom: -4px;+}++/* One row of an attribute name completion: the kind, then the name. */+.attr-name-suggestion {+ display: flex;+ align-items: center;+ gap: 8px;+}++.attr-name-suggestion .attr-name-suggestion-name {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}++.form-autocomplete-dropdown .attr-name-suggestion .attribute-kind {+ --attribute-kind-cutout: var(--menu-background-color);+}++.form-autocomplete-dropdown .form-autocomplete-item.active .attr-name-suggestion .attribute-kind {+ --attribute-kind-cutout: var(--suggestion-active-background-color);+}diff --git a/apps/client/src/widgets/attribute_widgets/attribute_name_suggestion.css b/apps/client/src/widgets/attribute_widgets/attribute_name_suggestion.cssdeleted file mode 100644index ff7ee5a8a0..0000000000--- a/apps/client/src/widgets/attribute_widgets/attribute_name_suggestion.css+++ /dev/null@@ -1,32 +0,0 @@-/*- * One row of an attribute name completion, shared by every list of attribute names: the detail- * popup's name field, the attributes panel's name box and the `#`/`~` completion in the inline- * attribute editor. All of them mark the names Trilium attaches a meaning to in the same way.- *- * Not nested under a widget root: each list is portalled to the body, so no row shares an ancestor- * with the widget that spawned it.- */--.attr-name-suggestion {- display: flex;- width: 100%;- align-items: center;- justify-content: space-between;- gap: 8px;-}--.attr-name-suggestion .attr-name-suggestion-name {- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;-}--.attr-name-suggestion .ext-badge {- --color: var(--muted-text-color);- flex-shrink: 0;-}--/* The badge is sized relative to the row, whose font the dropdown sets. */-.form-autocomplete-dropdown .attr-name-suggestion .ext-badge {- font-size: 0.65em;-}diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.cssindex 22fd266f48..1e5dd1c5af 100644--- a/apps/client/src/widgets/sidebar/AttributeList.css+++ b/apps/client/src/widgets/sidebar/AttributeList.css@@ -38,50 +38,6 @@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.- */-.attribute-list-panel .attribute-kind {- position: relative;- display: flex;- flex-shrink: 0;- color: var(--muted-text-color);-}--/*- * A badge on the corner of the icon: a cog for the names Trilium reads for itself (settings of the note- * rather than a word for it), a chevron for a definition of a promoted field (one lifted out of the- * attributes and into the note's own ribbon). A second glyph rather than an icon of its own, so- * `cssClass` still reads as the label it is, and a promoted date field as the date field it defines.- */-.attribute-list-panel .attribute-kind.marker-system::after,-.attribute-list-panel .attribute-kind.marker-promoted::after {- position: absolute;- inset-inline-end: -3px;- bottom: -2px;- font-family: boxicons;- font-size: 0.62em;- font-weight: normal;- line-height: 1;- /* Punched out of the icon it sits on, so the two glyphs stay legible where they overlap. */- text-shadow:- 0 0 2px var(--card-background-color, var(--main-background-color)),- 0 0 2px var(--card-background-color, var(--main-background-color));-}--.attribute-list-panel .attribute-kind.marker-system::after {- content: "\ea6e"; /* lookup code for "cog" in boxicons.css */-}--.attribute-list-panel .attribute-kind.marker-promoted::after {- content: "\ea57"; /* lookup code for "chevron-up" in boxicons.css */- /* A single stroke where the cog is a whole shape, so it is drawn a size up to weigh the same. */- font-size: 0.8em;- inset-inline-end: -4px;- bottom: -4px;-}-/* 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 {diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsxindex 606bcdd081..729e4cd5f7 100644--- a/apps/client/src/widgets/sidebar/AttributeList.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx@@ -1,3 +1,4 @@+import "../attribute_widgets/attribute_kind.css";import "./AttributeList.css";import { promotedAttributeDefinitionParser } from "@triliumnext/commons";