Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): reach the attributes panel from a phone

Elian Dorand0dd84280121
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 1061b7cd0c..597dcd4e20 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -159,6 +159,7 @@ export type CommandMappings = {
showCpuArchWarning: CommandData;
showLeftPane: CommandData;
showAttachments: CommandData;
+ showNoteAttributes: CommandData;
showSearchHistory: CommandData;
showShareSubtree: CommandData;
hoistNote: CommandData & { noteId: string };
diff --git a/apps/client/src/layouts/layout_commons.tsx b/apps/client/src/layouts/layout_commons.tsx
index 75f1fd45bf..907197bb46 100644
--- a/apps/client/src/layouts/layout_commons.tsx
+++ b/apps/client/src/layouts/layout_commons.tsx
@@ -37,6 +37,7 @@ export function applyModals(rootContainer: RootContainer) {
.child(<LazyDialog triggerEvents={["showCpuArchWarning"]} loader={() => import("../widgets/dialogs/incorrect_cpu_arch.js")} />)
.child(<LazyDialog triggerEvents={["showOptions"]} loader={() => import("../widgets/dialogs/OptionsDialog.jsx")} />)
.child(<LazyDialog triggerEvents={["showOcrTextDialog"]} loader={() => import("../widgets/dialogs/ocr_text.js")} />)
+ .child(<LazyDialog triggerEvents={["showNoteAttributes"]} loader={() => import("../widgets/dialogs/note_attributes.jsx")} />)
.child(<LazyDialog triggerEvents={["showUploadAttachmentsDialog"]} loader={() => import("../widgets/dialogs/upload_attachments.js")} />)
.child(<LazyDialog triggerEvents={["openInTreePopup"]} loader={() => import("../widgets/dialogs/TreePopupEditor.jsx")} />)
// The following three are deliberately eager (not wrapped in LazyDialog):
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index eb4f908caa..2af81f07b0 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -565,7 +565,7 @@
"run_at_hour": "On which hour should this run. Should be used together with <code>#run=hourly</code>. Can be defined multiple times for more runs during the day.",
"disable_inclusion": "Scripts with this label won't be included into parent script execution.",
"sorted": "Keeps child notes sorted by title alphabetically.",
- "sort_direction": "ASC (the default) or DESC.",
+ "sort_direction": "Direction <code>#sorted</code> orders the child notes in: <code>desc</code> for descending, anything else for ascending. Ignored unless <code>#sorted</code> is set.",
"sort_folders_first": "Folders (notes with children) should be sorted on top.",
"top": "Keep given note on top in its parent (applies only on sorted parents).",
"hide_promoted_attributes": "Hide promoted attributes on this note.",
@@ -577,8 +577,8 @@
"css_class": "Value of this label is then added as CSS class to the node representing given note in the tree. This can be useful for advanced theming. Can be used in template notes.",
"icon_class": "Value of this label is added as a CSS class to the icon on the tree which can help visually distinguish the notes in the tree. Example might be bx bx-home - icons are taken from boxicons. Can be used in template notes.",
"page_size": "Number of items per page in note listing.",
- "custom_request_handler": "Custom request handler.",
- "custom_resource_provider": "Custom resource provider.",
+ "custom_request_handler": "Serves this backend script over HTTP at <code>/custom/</code> followed by this value, which is matched against the path as a regular expression. The script reads the request from <code>api.req</code> and writes the response to <code>api.res</code>, with whatever the expression captured in <code>api.pathParams</code>.",
+ "custom_resource_provider": "Serves this note's content over HTTP at <code>/custom/</code> followed by this value, which is matched against the path as a regular expression. No script runs — the note is sent as it is, which is how a file such as a font or an image is given a stable URL.",
"widget": "Marks this note as a custom widget which will be added to the Trilium component tree.",
"workspace": "Marks this note as a workspace which allows easy hoisting.",
"workspace_icon_class": "Defines box icon CSS class which will be used in tab when hoisted to this note.",
@@ -613,7 +613,7 @@
"execute_description": "Longer description of the current code note displayed together with the execute button.",
"exclude_from_note_map": "Notes with this label will be hidden from the Note Map.",
"new_notes_on_top": "New notes will be created at the top of the parent note, not on the bottom.",
- "hide_highlight_widget": "Hide Highlight List widget.",
+ "hide_highlight_widget": "Hides the Highlights List for this note, leaving it shown on every other.",
"run_on_note_creation": "Executes when note is created on backend. Use this relation if you want to run the script for all notes created under a specific subtree. In that case, create it on the subtree root note and make it inheritable. A new note created within the subtree (any depth) will trigger the script.",
"run_on_child_note_creation": "Executes when new note is created under the note where this relation is defined.",
"run_on_note_title_change": "Executes when note title is changed (includes note creation as well).",
@@ -944,6 +944,7 @@
"search_in_note": "Search in note",
"note_source": "Note source",
"note_attachments": "Note attachments",
+ "note_attributes": "Note attributes",
"view_ocr_text": "View OCR text",
"open_note_externally": "Open note externally",
"open_note_externally_title": "File will be open in an external application and watched for changes. You'll then be able to upload the modified version back to Trilium.",
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.css b/apps/client/src/widgets/attribute_widgets/attribute_detail.css
index 4b08313fba..17a3a166a5 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.css
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.css
@@ -3,10 +3,17 @@
background-color: var(--accented-background-color);
border: 1px solid var(--main-border-color);
border-radius: 4px;
- z-index: 1000;
+ /* Above a modal (1055): the attributes it is editing may well be listed in one, and the popup is
+ always the topmost thing while it is open. Below the confirmations and prompts it summons itself
+ (2000), which have to come out above it in turn. */
+ z-index: 1060;
padding: 15px;
position: absolute;
width: 600px;
+ /* Narrower than that on a phone, where the popup is wider than the screen it is being placed on:
+ its host measures it to place it (see positionPopupBesideAnchor), so capping the width here is
+ what keeps it on screen. */
+ max-width: calc(100vw - 20px);
max-height: 600px;
overflow: auto;
box-shadow: 10px 10px 93px -25px black;
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
index 1c7212a2cb..6e18924da3 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
@@ -25,6 +25,7 @@ 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 { 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";
@@ -233,6 +234,17 @@ export function AttributeDetail({ opts, currentNoteId, onDismiss, onCancel, ...f
return () => window.removeEventListener("mousedown", onMouseDown);
}, [ shown, spawner, onDismiss ]);
+ // The popup is rendered outside whatever modal it was opened from (its host portals it to the body,
+ // and a modal counts as belonging to it — see above), which Bootstrap's focus-trap would otherwise
+ // keep pulling focus back out of, leaving the fields unusable. Suspended while the popup is shown.
+ useEffect(() => {
+ if (!shown) {
+ return;
+ }
+
+ return suspendModalFocusTraps();
+ }, [ shown ]);
+
if (!opts) {
return null;
}
diff --git a/apps/client/src/widgets/dialogs/note_attributes.css b/apps/client/src/widgets/dialogs/note_attributes.css
new file mode 100644
index 0000000000..a0c9f89c52
--- /dev/null
+++ b/apps/client/src/widgets/dialogs/note_attributes.css
@@ -0,0 +1,70 @@
+/*
+ * The panel lays its sections out in cards, which the right pane is what dresses (`#right-pane .card`
+ * in style.css, and RightPanelContainer.css over it) — none of which reaches a modal, where the cards
+ * would otherwise come out as Bootstrap draws them: bordered, rounded boxes of their own. Dressed here
+ * as the pane dresses them, one section under the next, each headed by a line that is pressed to put it
+ * away.
+ */
+.modal.note-attributes-modal {
+ .modal-body {
+ padding-block: 0;
+ }
+
+ .card {
+ border: 0;
+ border-bottom: 1px solid var(--main-border-color);
+ border-radius: 0;
+ background: transparent;
+
+ &:last-of-type {
+ border-bottom: 0;
+ }
+ }
+
+ .card-header {
+ display: flex;
+ align-items: center;
+ justify-content: flex-start;
+ padding: 4px 0;
+ border: 0;
+ background: transparent;
+ cursor: pointer;
+ --icon-button-size: 26px;
+
+ .icon-action {
+ flex-shrink: 0;
+ transition: transform 0.15s ease;
+ }
+ }
+
+ /* Read as the sentences they are ("3 owned attributes"), rather than uppercased as the right pane
+ heads its own cards: this is a page of its own on a phone, not a column of headings beside one. */
+ .card-header-title {
+ flex-grow: 1;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ font-weight: 600;
+ color: var(--muted-text-color);
+ }
+
+ .card-header-buttons {
+ display: flex;
+ align-items: center;
+ }
+
+ .card.collapsed .card-header > .icon-action {
+ transform: rotate(-90deg);
+ }
+
+ /* The one section a note has, having nothing to be put away in favour of (see RightPanelWidget),
+ has no chevron either — so its title starts where the others' do. */
+ .card.not-collapsible .card-header {
+ cursor: default;
+ padding-inline-start: 8px;
+ }
+
+ .card-body {
+ padding: 0 0 8px;
+ }
+}
diff --git a/apps/client/src/widgets/dialogs/note_attributes.tsx b/apps/client/src/widgets/dialogs/note_attributes.tsx
new file mode 100644
index 0000000000..982065697e
--- /dev/null
+++ b/apps/client/src/widgets/dialogs/note_attributes.tsx
@@ -0,0 +1,34 @@
+import "./note_attributes.css";
+
+import { useState } from "preact/hooks";
+
+import { t } from "../../services/i18n";
+import { useTriliumEvent } from "../react/hooks";
+import Modal from "../react/Modal";
+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.
+ */
+export default function NoteAttributesDialog() {
+ const [ shown, setShown ] = useState(false);
+
+ useTriliumEvent("showNoteAttributes", () => setShown(true));
+
+ return (
+ <Modal
+ className="note-attributes-modal"
+ // Named as the menu entry that summons it names it.
+ title={t("note_actions.note_attributes")}
+ size="md"
+ show={shown}
+ onHidden={() => setShown(false)}
+ scrollable
+ isFullPageOnMobile
+ >
+ <AttributeList />
+ </Modal>
+ );
+}
diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx
index 9f57919be8..4b50eb2efa 100644
--- a/apps/client/src/widgets/ribbon/NoteActions.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx
@@ -16,7 +16,7 @@ import { t } from "../../services/i18n";
import protected_session from "../../services/protected_session";
import server from "../../services/server";
import toast from "../../services/toast";
-import { isDesktop,isElectron as getIsElectron, isMac as getIsMac } from "../../services/utils";
+import { isElectron as getIsElectron, isMac as getIsMac, isMobile as getIsMobile } from "../../services/utils";
import ws from "../../services/ws";
import ClosePaneButton from "../buttons/close_pane_button";
import CreatePaneButton from "../buttons/create_pane_button";
@@ -94,6 +94,7 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
);
const isElectron = getIsElectron();
const isMac = getIsMac();
+ const isMobile = getIsMobile();
const hasSource = ["text", "code", "relationMap", "mermaid", "canvas", "mindMap", "spreadsheet", "llmChat"].includes(noteType) || note.isSvg();
const isSearchOrBook = ["search", "book"].includes(noteType);
const isHelpPage = note.noteId.startsWith("_help");
@@ -135,6 +136,9 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
<CommandItem command="findInText" icon="bx bx-search" disabled={!isSearchable} text={t("note_actions.search_in_note")} />
<CommandItem command="showAttachments" icon="bx bx-paperclip" disabled={isInOptionsOrHelp} text={t("note_actions.note_attachments")} />
{isNewLayout && <CommandItem command="toggleRibbonTabNoteMap" icon="bx bxs-network-chart" disabled={isInOptionsOrHelp} text={t("note_actions.note_map")} />}
+ {/* The attributes panel is a right pane tab where there is a right pane; on a phone the
+ menu is where it is reached, and a modal is where it is shown. */}
+ {isMobile && <CommandItem command="showNoteAttributes" icon="bx bx-list-check" disabled={isInOptionsOrHelp} text={t("note_actions.note_attributes")} />}
<FormDropdownDivider />