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(client): remove the floating buttons
Elian Doran4b00f6c8f63e
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex 6226d07f0e..edbdcbe2c7 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -180,7 +180,6 @@ export type CommandMappings = {openNoteInNewSplit: CommandData;openNoteInNewWindow: CommandData;openAboutDialog: CommandData;- hideFloatingButtons: {};hideLeftPane: CommandData;showCpuArchWarning: CommandData;showLeftPane: CommandData;diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 600501c238..4f7aa3b7de 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -2388,12 +2388,6 @@ body.electron:not(.platform-darwin) .tab-row-container {color: var(--hover-item-text-color);}-.note-split.type-geoMap .floating-buttons-children {- background: var(--main-background-color);- box-shadow: 0px 10px 20px rgba(0, 0, 0, var(--dropdown-shadow-opacity));- border-radius: 4px;-}-body.zen {--tab-bar-height: 0;}@@ -2412,7 +2406,6 @@ body.zen .note-badges > *:not(.read-only-badge),body.zen .note-actions-bar,body.zen .inline-title,body.zen .promoted-attributes-widget,-body.zen .floating-buttons-children > *,body.zen .action-button,body.zen .tooltip.content-hint, /* content-area hints (task states, collapsible summaries, drag handles) */body.zen .note-split:not(.type-book) .note-list-widget {@@ -2446,20 +2439,6 @@ body.zen .title-row {border-bottom: none !important;}-body.zen .floating-buttons {- top: -10px;-}--body.zen .floating-buttons-children {- inset-inline-end: 0;-}--body.zen .floating-buttons-children .button-widget {- width: var(--zen-button-size);- height: var(--zen-button-size);- padding: 0;-}-body.zen .note-title-widget,body.zen .note-title-widget input {font-size: 1rem !important;diff --git a/apps/client/src/stylesheets/theme-next-dark.css b/apps/client/src/stylesheets/theme-next-dark.cssindex cc77b2ed58..94f29d8a77 100644--- a/apps/client/src/stylesheets/theme-next-dark.css+++ b/apps/client/src/stylesheets/theme-next-dark.css@@ -239,16 +239,6 @@--floating-button-shadow-color: #00000080;--floating-button-background-color: #494949d2;- --floating-button-color: var(--button-text-color);- --floating-button-hover-background: #ffffff20;- --floating-button-hover-color: white;- --floating-button-show-button-background: var(--left-pane-item-action-button-background);- --floating-button-show-button-color: var(--left-pane-item-action-button-color);- --floating-button-show-button-shadow: none;- --floating-button-show-button-hover-background: var(--left-pane-item-action-button-hover-background);- --floating-button-show-button-hover-shadow: 0 2px 4px #0000007b;- --floating-button-hide-button-background: #00000029;- --floating-button-hide-button-color: #ffffff63;--overlay-button-shadow-color: #00000048;diff --git a/apps/client/src/stylesheets/theme-next-light.css b/apps/client/src/stylesheets/theme-next-light.cssindex 02e7bbb61c..eb5d10a0d9 100644--- a/apps/client/src/stylesheets/theme-next-light.css+++ b/apps/client/src/stylesheets/theme-next-light.css@@ -231,16 +231,6 @@--floating-button-shadow-color: #00000042;--floating-button-background-color: #eaeaeacc;- --floating-button-color: #454545;- --floating-button-hover-background: #00000017;- --floating-button-hover-color: black;- --floating-button-show-button-background: var(--left-pane-item-action-button-background);- --floating-button-show-button-color: var(--left-pane-item-action-button-color);- --floating-button-show-button-shadow: none;- --floating-button-show-button-hover-background: var(--left-pane-item-action-button-hover-background);- --floating-button-show-button-hover-shadow: 0 2px 4px #00000068;- --floating-button-hide-button-background: #0000000d;- --floating-button-hide-button-color: gray;--overlay-button-shadow-color: #00000048;diff --git a/apps/client/src/stylesheets/theme-next/base.css b/apps/client/src/stylesheets/theme-next/base.cssindex 31479cc559..1d7334356d 100644--- a/apps/client/src/stylesheets/theme-next/base.css+++ b/apps/client/src/stylesheets/theme-next/base.css@@ -66,11 +66,6 @@--center-pane-border-radius: 10px;- --floating-button-height: 34px;- --floating-button-width: 40px;- --floating-button-icon-size: 20px;- --floating-button-show-hide-button-size: 26px;---overlay-button-height: 28px;--overlay-button-border-radius: 6px;--overlay-button-background: var(--opaque-icon-button-background);diff --git a/apps/client/src/stylesheets/theme-next/notes/canvas.css b/apps/client/src/stylesheets/theme-next/notes/canvas.cssindex 4ef2e65bef..ffd05ed484 100644--- a/apps/client/src/stylesheets/theme-next/notes/canvas.css+++ b/apps/client/src/stylesheets/theme-next/notes/canvas.css@@ -63,13 +63,6 @@z-index: -1;}-/* Note's root */--:root .type-canvas {- --floating-buttons-vert-offset: 20px;-}--/* Context menus *//* Context menu - outer wrapper */@@ -250,13 +243,6 @@ body[dir=rtl] .excalidraw .exc-stats {right: 0;}-/* Sidebar */--.split-note-container-widget > .component.type-canvas:has(.excalidraw-container > .Island.default-sidebar) > .floating-buttons {- /* Hide the floating buttons when the sidebar is open */- display: none;-}-/* Pickers */.excalidraw .picker {diff --git a/apps/client/src/stylesheets/theme-next/shell.css b/apps/client/src/stylesheets/theme-next/shell.cssindex e572be8475..ecfe02f93b 100644--- a/apps/client/src/stylesheets/theme-next/shell.css+++ b/apps/client/src/stylesheets/theme-next/shell.css@@ -1492,185 +1492,6 @@ div.promoted-attribute-cell.promoted-attribute-label-color .input-group {width: auto;}-/*- * Floating buttons- */-- /* Floating buttons container */-.floating-buttons-children {- opacity: 1;- min-height: var(--floating-button-height);- transform-origin: right;- box-shadow: 1px 1px 1px var(--floating-button-shadow-color);- background: var(--floating-button-background-color);- backdrop-filter: blur(10px) saturate(6);- border-radius: 6px;- transition: transform 250ms ease-out,- opacity 250ms ease-out;-}--body[dir=rtl] .floating-buttons-children {- transform-origin: left;-}-- /* Floating buttons container (collapsed) */- .floating-buttons-children.temporarily-hidden {- display: flex !important;- opacity: 0;- transform: scaleX(0);- pointer-events: none;-}--/* Floating buttons */--.floating-buttons-children {- --border-radius-size: 6px;-}--.floating-buttons-children > * {- margin: 0 !important;-}--div.floating-buttons-children > button,-div.floating-buttons-children .floating-button {- width: var(--floating-button-width);- height: var(--floating-button-height);- padding: 0;- border: 0;- border-radius: 0;- font-size: var(--floating-button-icon-size);- align-items: center;- color: var(--floating-button-color);-}--div.floating-buttons-children > button:hover,-div.floating-buttons-children .floating-button:hover {- background: var(--floating-button-hover-background);- color: var(--floating-button-hover-color);-}--div.floating-buttons-children > button:active,-div.floating-buttons-children .floating-button:active {- font-size: calc(var(--floating-button-icon-size) * 0.85);-}--/* The first visible floating button */-div.floating-buttons-children > *:first-child {- --border-radius: var(--border-radius-size) 0 0 var(--border-radius-size);- border-radius: var(--border-radius);-}-- /* "Show / hide floating buttons" buttons */-- @keyframes floating-buttons-show-hide-button-animation {- from {- transform: rotate(180deg);- } to {- transform: rotate(0);- }-}--div.floating-buttons-children .close-floating-buttons-button,-div.floating-buttons .show-floating-buttons-button {- margin-top: calc((var(--floating-button-height) - var(--floating-button-show-hide-button-size)) / 2);- width: var(--floating-button-show-hide-button-size);- height: var(--floating-button-show-hide-button-size);- padding: 0;- border: 0;- font-size: calc(var(--floating-button-show-hide-button-size) * .8);-}--div.floating-buttons-children .close-floating-buttons-button:active,-div.floating-buttons .show-floating-buttons-button:active {- font-size: calc(var(--floating-button-show-hide-button-size) * .65);- background: transparent!important;-}--div.floating-buttons-children .close-floating-buttons-button::before,-div.floating-buttons .show-floating-buttons-button::before {- display: block;- line-height: 1;-}--/* "Show buttons" button */--div.floating-buttons .show-floating-buttons-button {- box-shadow: var(--floating-button-show-button-shadow);- background: var(--floating-button-show-button-background);- color: var(--floating-button-show-button-color);- backdrop-filter: blur(10px);-}--div.floating-buttons .show-floating-buttons-button::before {- animation: floating-buttons-show-hide-button-animation 400ms ease-out;-}--div.floating-buttons .show-floating-buttons-button:hover,-div.floating-buttons .show-floating-buttons-button:active {- box-shadow: var(--floating-button-show-button-hover-shadow);- background: var(--floating-button-show-button-hover-background) !important;- color: var(--floating-button-show-button-color) !important;-}--/* "Hide buttons" button */--div.floating-buttons-children:not(.temporarily-hidden) .close-floating-buttons-button::before {- animation: floating-buttons-show-hide-button-animation 400ms ease-out;-}--div.floating-buttons-children .close-floating-buttons {- border-radius: 0 var(--border-radius-size) var(--border-radius-size) 0;- overflow: hidden;-}--div.floating-buttons-children .close-floating-buttons {- margin-inline-start: 0 !important;- background: var(--floating-button-hide-button-background);- color: var(--floating-button-hide-button-color);-}--div.floating-buttons-children .close-floating-buttons:has(.close-floating-buttons-button:hover) {- background: var(--floating-button-hover-background);- color: var(--floating-button-hover-color);-}--/* Backlink count */--.backlinks-widget .backlinks-ticker {- height: 100%;- padding: 0 10px;- border-radius: var(--border-radius);- background: transparent;- user-select: none;-}--.backlinks-widget .backlinks-ticker:hover {- background: var(--floating-button-hover-background);-}--.backlinks-widget .backlinks-items {- --menu-padding-size: 20px;-}--/* TODO: Restyle the path */-.backlinks-widget .backlinks-items .note-path {- padding-inline-start: 8px;-}--/* Button groups */-:root .floating-buttons .btn-group {- --button-group-active-button-background-color: var(--low-profile-button-active-background-color);- --button-group-active-button-color: var(--low-profile-button-active-color);-- background: transparent;- padding: 0;-- button.btn.floating-button.btn {- border-radius: 0;- box-shadow: unset;- }-}-/** Find and replace bar*/diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 5307fc9652..99e2f89840 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1239,9 +1239,6 @@"esc_hint": "to close"},"zpetne_odkazy": {- "backlink_one": "{{count}} Backlink",- "backlink_other": "{{count}} Backlinks",- "relation": "relation","no_backlinks": "No notes link to this one."},"mobile_detail_menu": {diff --git a/apps/client/src/widgets/FloatingButtons.css b/apps/client/src/widgets/FloatingButtons.cssdeleted file mode 100644index 1a606c237c..0000000000--- a/apps/client/src/widgets/FloatingButtons.css+++ /dev/null@@ -1,160 +0,0 @@-/* #region Generic floating buttons styles */-.floating-buttons {- position: relative;-}--.floating-buttons-children,-.show-floating-buttons {- position: absolute;- top: var(--floating-buttons-vert-offset, 14px);- inset-inline-end: var(--floating-buttons-horiz-offset, 10px);- display: flex;- flex-direction: row;- z-index: 100;-}--.note-split.rtl .floating-buttons-children,-.note-split.rtl .show-floating-buttons {- inset-inline-end: 10px;-}--.note-split.rtl .close-floating-buttons {- order: -1;-}--.note-split.rtl .close-floating-buttons,-.note-split.rtl .show-floating-buttons {- transform: rotate(180deg);-}--.type-canvas {- --floating-buttons-vert-offset: 70px;-}--.type-canvas .floating-buttons-children > * {- --border-radius: 0; /* Overridden by themes */-}--.floating-buttons-children > *:not(.hidden-int):not(.no-content-hidden) {- margin: 2px;-}--.floating-buttons-children > *:not(.has-overflow) {- overflow: hidden;-}--.floating-buttons-children > button, .floating-buttons-children .floating-button {- font-size: 150%;- padding: 5px 10px 4px 10px;- width: 40px;- cursor: pointer;- color: var(--button-text-color);- background: var(--button-background-color);- border-radius: var(--button-border-radius);- border: 1px solid transparent;- display: flex;- justify-content: space-around;-}--.floating-buttons-children > button:hover, .floating-buttons-children .floating-button:hover {- text-decoration: none;- border-color: var(--button-border-color);-}--.floating-buttons .floating-buttons-children.temporarily-hidden {- display: none;-}-/* #endregion */--/* #region Show floating button */-.floating-buttons-children.temporarily-hidden+.show-floating-buttons {- display: block;-}--.show-floating-buttons {- /* display: none;*/- margin-inline-start: 5px !important;-}--.show-floating-buttons-button {- border: 1px solid transparent;- color: var(--button-text-color);- padding: 6px;- border-radius: 100px !important;-}--.show-floating-buttons-button:hover {- border: 1px solid var(--button-border-color);-}-/* #endregion */--/* #region Close floating buttons */-.close-floating-buttons {- margin-inline-start: 5px !important;-}--.close-floating-buttons:first-child {- display: none !important;-}--.close-floating-buttons-button {- border: 1px solid transparent;- color: var(--button-text-color);- padding: 6px;- border-radius: 100px;-}--.close-floating-buttons-button:hover {- border: 1px solid var(--button-border-color);-}-/* #endregion */--/* #region Backlinks */-/* The floating button's popup, and its alone: the list within it is the same markup the sidebar's- backlinks and the mobile modal show (see Backlinks.css), which frame it their own way — so nothing- here is left loose to reach them. */-.backlinks-widget {- position: relative;-- .backlinks-ticker {- border-radius: 10px;- border-color: var(--main-border-color);- background-color: var(--more-accented-background-color);- padding: 4px 10px 4px 10px;- opacity: 90%;- display: flex;- justify-content: space-between;- align-items: center;- }-- .backlinks-count {- cursor: pointer;- }-- .backlinks-items {- z-index: 10;- position: absolute;- top: 50px;- inset-inline-end: 10px;- width: 400px;- border-radius: 10px;- background-color: var(--accented-background-color);- color: var(--main-text-color);- padding: 20px;- overflow-y: auto;- }-- .backlink-excerpt {- border-inline-start: 2px solid var(--main-border-color);- padding-inline-start: 10px;- opacity: 80%;- font-size: 90%;-- /* The link the excerpt is quoted for. */- .backlink-link {- font-weight: bold;- background-color: yellow;- }- }-}-/* #endregion */diff --git a/apps/client/src/widgets/FloatingButtons.tsx b/apps/client/src/widgets/FloatingButtons.tsxdeleted file mode 100644index 2b8e12223d..0000000000--- a/apps/client/src/widgets/FloatingButtons.tsx+++ /dev/null@@ -1,78 +0,0 @@-import { t } from "i18next";-import "./FloatingButtons.css";-import { useNoteContext } from "./react/hooks";-import { useEffect, useMemo, useState } from "preact/hooks";-import { type FloatingButtonsList, type FloatingButtonContext } from "./FloatingButtonsDefinitions";-import ActionButton from "./react/ActionButton";--interface FloatingButtonsProps {- items: FloatingButtonsList;-}--/*- * Note:- *- * For floating button widgets that require content to overflow, the has-overflow CSS class should- * be applied to the root element of the widget. Additionally, this root element may need to- * properly handle rounded corners, as defined by the --border-radius CSS variable.- */-export default function FloatingButtons({ items }: FloatingButtonsProps) {- const { note, noteContext } = useNoteContext();- const context = useMemo<FloatingButtonContext | null>(() => {- if (!note || !noteContext) return null;-- return {- note,- isDefaultViewMode: noteContext.viewScope?.viewMode === "default"- };- }, [ note, noteContext ]);-- // Manage the user-adjustable visibility of the floating buttons.- const [ visible, setVisible ] = useState(true);- useEffect(() => setVisible(true), [ note ]);-- return (- <div className="floating-buttons no-print">- <div className={`floating-buttons-children ${!visible ? "temporarily-hidden" : ""}`}>- {context && items.map((Component) => (- <Component {...context} />- ))}-- {visible && <CloseFloatingButton setVisible={setVisible} />}- </div>-- {!visible && <ShowFloatingButton setVisible={setVisible} /> }- </div>- )-}--/**- * Show button that displays floating button after click on close button- */-function ShowFloatingButton({ setVisible }: { setVisible(visible: boolean): void }) {- return (- <div className="show-floating-buttons">- <ActionButton- className="show-floating-buttons-button"- icon="bx bx-chevrons-left"- text={t("show_floating_buttons_button.button_title")}- onClick={() => setVisible(true)}- noIconActionClass- />- </div>- );-}--function CloseFloatingButton({ setVisible }: { setVisible(visible: boolean): void }) {- return (- <div className="close-floating-buttons">- <ActionButton- className="close-floating-buttons-button"- icon="bx bx-chevrons-right"- text={t("hide_floating_buttons_button.button_title")}- onClick={() => setVisible(false)}- noIconActionClass- />- </div>- );-}\ No newline at end of filediff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx b/apps/client/src/widgets/FloatingButtonsDefinitions.tsxdeleted file mode 100644index ac6f9ab0ba..0000000000--- a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx+++ /dev/null@@ -1,160 +0,0 @@-import "./Backlinks.css";--import { BacklinkCountResponse, BacklinksResponse } from "@triliumnext/commons";-import { VNode } from "preact";-import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";--import FNote from "../entities/fnote";-import attributes from "../services/attributes";-import froca from "../services/froca";-import { t } from "../services/i18n";-import LoadResults from "../services/load_results";-import { sanitizeNoteContentHtml } from "../services/sanitize_content";-import server from "../services/server";-import { useTriliumEvent, useWindowSize } from "./react/hooks";-import NoItems from "./react/NoItems";-import NoteLink from "./react/NoteLink";-import RawHtml from "./react/RawHtml";--export interface FloatingButtonContext {- note: FNote;- isDefaultViewMode: boolean;-}--export type FloatingButtonsList = ((context: FloatingButtonContext) => false | VNode)[];--export const DESKTOP_FLOATING_BUTTONS: FloatingButtonsList = [- Backlinks-];--function Backlinks({ note, isDefaultViewMode }: FloatingButtonContext) {- const [ popupOpen, setPopupOpen ] = useState(false);- const backlinksContainerRef = useRef<HTMLDivElement>(null);- const backlinkCount = useBacklinkCount(note, isDefaultViewMode);-- // Determine the max height of the container.- const { windowHeight } = useWindowSize();- useLayoutEffect(() => {- const el = backlinksContainerRef.current;- if (popupOpen && el) {- const box = el.getBoundingClientRect();- const maxHeight = windowHeight - box.top - 10;- el.style.maxHeight = `${maxHeight}px`;- }- }, [ popupOpen, windowHeight ]);-- const isEnabled = isDefaultViewMode && backlinkCount > 0;- return (isEnabled &&- <div className="backlinks-widget has-overflow">- <div- className="backlinks-ticker"- onClick={() => setPopupOpen(!popupOpen)}- >- <span className="backlinks-count">{t("zpetne_odkazy.backlink", { count: backlinkCount })}</span>- </div>-- {popupOpen && (- <div ref={backlinksContainerRef} className="backlinks-items dropdown-menu" style={{ display: "block" }}>- <BacklinksList note={note} />- </div>- )}- </div>- );-}--export function useBacklinkCount(note: FNote | null | undefined, isDefaultViewMode: boolean) {- const [ backlinkCount, setBacklinkCount ] = useState(0);-- const refresh = useCallback(() => {- if (!note || !isDefaultViewMode) return;-- server.get<BacklinkCountResponse>(`note-map/${note.noteId}/backlink-count`).then(resp => {- setBacklinkCount(resp.count);- });- }, [ isDefaultViewMode, note ]);-- useEffect(() => refresh(), [ refresh ]);- useTriliumEvent("entitiesReloaded", ({ loadResults }) => {- if (note && needsRefresh(note, loadResults)) refresh();- });-- return backlinkCount;-}--export function BacklinksList({ note }: { note: FNote }) {- const [ backlinks, setBacklinks ] = useState<BacklinksResponse>();-- function refresh() {- server.get<BacklinksResponse>(`note-map/${note.noteId}/backlinks`).then(async (backlinks) => {- // prefetch all- const noteIds = backlinks- .filter(bl => "noteId" in bl)- .map((bl) => bl.noteId);- await froca.getNotes(noteIds);- setBacklinks(backlinks);- });- }-- useEffect(() => refresh(), [ note ]);- useTriliumEvent("entitiesReloaded", ({ loadResults }) => {- if (needsRefresh(note, loadResults)) refresh();- });-- // Nothing at all until the request has answered, so that the placeholder below doesn't show for- // as long as it takes — the note usually has backlinks, this list being what says it has.- if (!backlinks) return null;-- if (!backlinks.length) {- return (- // An item of the list it stands in for: what holds it is a <ul> everywhere but the- // floating button's dropdown, which only opens once there is something to list anyway.- <li className="backlinks-empty">- <NoItems size="small" icon="bx bx-link" text={t("zpetne_odkazy.no_backlinks")} />- </li>- );- }-- // Keyed by position: one source note takes a row per relation it points with, so a note ID names- // no single row, and the whole list is rebuilt at once anyway.- return backlinks.map((backlink, index) => (- <li key={index}>- {/* Named so that the styling has something to hang off other than the position of the- link within the item (see Backlinks.css). */}- <NoteLink- notePath={backlink.noteId}- containerClassName="backlink-header"- showNotePath showNoteIcon- noPreview- />-- {"relationName" in backlink ? (- <p className="backlink-relation">{backlink.relationName}</p>- ) : (- backlink.excerpts.map((excerpt, excerptIndex) => (- <RawHtml key={excerptIndex} html={sanitizeNoteContentHtml(excerpt)} />- ))- )}- </li>- ));-}--/**- * {@link BacklinksList} in the markup its styling hangs off (see Backlinks.css), for the places that- * frame the list rather than build it: the sidebar's card, the mobile note menu's modal, the status- * bar's dropdown. The floating button keeps its own container, being a popup it also sizes by hand.- */-export function BacklinksWidget({ note }: { note: FNote }) {- return (- <div class="tn-backlinks-widget">- <ul class="backlinks-items">- <BacklinksList note={note} />- </ul>- </div>- );-}--function needsRefresh(note: FNote, loadResults: LoadResults) {- return loadResults.getAttributeRows().some(attr =>- attr.type === "relation" &&- attributes.isAffecting(attr, note));-}diff --git a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsxindex b00366664f..384178d428 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx@@ -100,10 +100,6 @@ vi.mock("../react/Modal", () => ({// The popup's body: each is exercised by its own spec, and none of it decides what the popup shows.vi.mock("../NoteDetail", () => ({ default: () => <div className="note-detail-stub" /> }));vi.mock("../collections/NoteList", () => ({ default: () => null }));-vi.mock("../FloatingButtons", () => ({ default: () => null }));-vi.mock("../FloatingButtonsDefinitions", () => ({- DESKTOP_FLOATING_BUTTONS: []-}));vi.mock("../PromotedAttributes", () => ({ default: () => null }));vi.mock("../layout/NoteBadges", () => ({ default: () => null }));vi.mock("../layout/NoteTypeSwitcher", () => ({diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsxindex 1d69db5b2f..8466f0aa6e 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx@@ -10,8 +10,6 @@ import { t } from "../../services/i18n";import tree from "../../services/tree";import utils from "../../services/utils";import NoteList from "../collections/NoteList";-import FloatingButtons from "../FloatingButtons";-import { DESKTOP_FLOATING_BUTTONS } from "../FloatingButtonsDefinitions";import FormattingToolbar from "../layout/FormattingToolbar";import NoteTypeSwitcher from "../layout/NoteTypeSwitcher";import TitleRow from "../layout/TitleRow";@@ -181,7 +179,6 @@ export default function PopupEditor() {? <MobileEditorToolbar inPopupEditor />: <FormattingToolbar />}- <FloatingButtons items={isMobile ? [] : DESKTOP_FLOATING_BUTTONS} /><NoteDetail /><NoteList media="screen" displayOnlyCollections />{switchable && <NoteTypeSwitcher note={noteContext.note} />}diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsxindex c078a329fc..cce8dfa8de 100644--- a/apps/client/src/widgets/layout/StatusBar.tsx+++ b/apps/client/src/widgets/layout/StatusBar.tsx@@ -21,7 +21,6 @@ import AttributeEditor, { AttributeEditorImperativeHandlers } from "../attributeimport AttributeHelp from "../attribute_widgets/AttributeHelp";import InheritedAttributes from "../attribute_widgets/InheritedAttributes";import { ContentLanguagesModal, useLanguageSwitcher } from "../dialogs/content_languages";-import { BacklinksWidget, useBacklinkCount } from "../FloatingButtonsDefinitions";import Dropdown, { type DropdownHandle, DropdownPanel, type DropdownPanelProps } from "../react/Dropdown";import { FormDropdownDivider, FormListHeader, FormListItem } from "../react/FormList";import HelpDropdown from "../react/HelpDropdown";@@ -31,6 +30,7 @@ import LinkButton from "../react/LinkButton";import NoItems from "../react/NoItems";import NoteLink from "../react/NoteLink";import { ParentComponent } from "../react/react_utils";+import { BacklinksWidget, useBacklinkCount } from "../sidebar/Backlinks";import { NotePathsWidget, useSortedNotePaths } from "../sidebar/NotePaths";import type { RightPaneTabId } from "../sidebar/RightPaneTabs";import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsxindex 5b8c012f20..09baa34da1 100644--- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx+++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx@@ -8,7 +8,6 @@ import { t } from "../../services/i18n";import note_create from "../../services/note_create";import server from "../../services/server";import { useLanguageSwitcher } from "../dialogs/content_languages";-import { BacklinksWidget, useBacklinkCount } from "../FloatingButtonsDefinitions";import { NoteContextMenu } from "../layout/NoteActions";import NoteActionsCustom from "../layout/NoteActionsCustom";import { codeLanguageItems, useMimeTypes } from "../layout/NoteTypeSwitcher";@@ -19,6 +18,7 @@ import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../reactimport { useNoteContext, useNoteProperty } from "../react/hooks";import { MenuItemRows } from "../react/Menu";import Modal from "../react/Modal";+import { BacklinksWidget, useBacklinkCount } from "../sidebar/Backlinks";import { NotePathsWidget, useSortedNotePaths } from "../sidebar/NotePaths";import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.css b/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.cssindex 8e04c5d29f..277c74fdf7 100644--- a/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.css+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hint_button.css@@ -18,13 +18,3 @@z-index: 2;transition: opacity .3s;}--/* If the floating buttons are displayed, the group keeps further from the head of the note so as not- * to overlap them on the old layout or popup editor — said as the room it keeps rather than as a- * placement of its own, so that where it stands is still the one thing the group itself says. */-:is(.note-split, .popup-editor-dialog > .modal-dialog > .modal-content > .modal-body):has(- > .floating-buttons > .floating-buttons-children.temporarily-hidden,- > .floating-buttons > .floating-buttons-children > .close-floating-buttons:not(:first-child)-) .shortcut-hint-button-group {- --overlay-group-inset-top: 60px;-}diff --git a/apps/client/src/widgets/Backlinks.css b/apps/client/src/widgets/sidebar/Backlinks.csssimilarity index 100%rename from apps/client/src/widgets/Backlinks.cssrename to apps/client/src/widgets/sidebar/Backlinks.cssdiff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.spec.tsx b/apps/client/src/widgets/sidebar/Backlinks.spec.tsxsimilarity index 93%rename from apps/client/src/widgets/FloatingButtonsDefinitions.spec.tsxrename to apps/client/src/widgets/sidebar/Backlinks.spec.tsxindex e28fba1f34..e6f267a73b 100644--- a/apps/client/src/widgets/FloatingButtonsDefinitions.spec.tsx+++ b/apps/client/src/widgets/sidebar/Backlinks.spec.tsx@@ -5,10 +5,10 @@ import { render } from "preact";import { act } from "preact/test-utils";import { afterEach, describe, expect, it, vi } from "vitest";-import froca from "../services/froca.js";-import server from "../services/server.js";-import { buildNote } from "../test/easy-froca.js";-import { BacklinksList } from "./FloatingButtonsDefinitions.js";+import froca from "../../services/froca.js";+import server from "../../services/server.js";+import { buildNote } from "../../test/easy-froca.js";+import { BacklinksList } from "./Backlinks.js";let container: HTMLDivElement;diff --git a/apps/client/src/widgets/sidebar/Backlinks.tsx b/apps/client/src/widgets/sidebar/Backlinks.tsxindex cef117fbc4..9943de2cea 100644--- a/apps/client/src/widgets/sidebar/Backlinks.tsx+++ b/apps/client/src/widgets/sidebar/Backlinks.tsx@@ -1,8 +1,19 @@+import "./Backlinks.css";++import { BacklinkCountResponse, BacklinksResponse } from "@triliumnext/commons";+import { useCallback, useEffect, useState } from "preact/hooks";++import FNote from "../../entities/fnote";+import attributes from "../../services/attributes";+import froca from "../../services/froca";import { t } from "../../services/i18n";-// The list itself is shared with the floating backlinks button, the status bar's badge and the mobile-// menu; only the framing differs here.-import { BacklinksWidget } from "../FloatingButtonsDefinitions";-import { useActiveNoteContext } from "../react/hooks";+import LoadResults from "../../services/load_results";+import { sanitizeNoteContentHtml } from "../../services/sanitize_content";+import server from "../../services/server";+import { useActiveNoteContext, useTriliumEvent } from "../react/hooks";+import NoItems from "../react/NoItems";+import NoteLink from "../react/NoteLink";+import RawHtml from "../react/RawHtml";import RightPanelWidget from "./RightPanelWidget";import SidebarHelp from "./SidebarHelp";@@ -19,3 +30,98 @@ export default function Backlinks() {</RightPanelWidget>);}++/**+ * {@link BacklinksList} in the markup its styling hangs off (see Backlinks.css), for the places that+ * frame the list: this card, the mobile note menu's modal and the status bar's dropdown.+ */+export function BacklinksWidget({ note }: { note: FNote }) {+ return (+ <div class="tn-backlinks-widget">+ <ul class="backlinks-items">+ <BacklinksList note={note} />+ </ul>+ </div>+ );+}++export function BacklinksList({ note }: { note: FNote }) {+ const [ backlinks, setBacklinks ] = useState<BacklinksResponse>();++ function refresh() {+ server.get<BacklinksResponse>(`note-map/${note.noteId}/backlinks`).then(async (backlinks) => {+ // prefetch all+ const noteIds = backlinks+ .filter(bl => "noteId" in bl)+ .map((bl) => bl.noteId);+ await froca.getNotes(noteIds);+ setBacklinks(backlinks);+ });+ }++ useEffect(() => refresh(), [ note ]);+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {+ if (needsRefresh(note, loadResults)) refresh();+ });++ // Nothing at all until the request has answered, so that the placeholder below doesn't show for+ // as long as it takes — the note usually has backlinks, this list being what says it has.+ if (!backlinks) return null;++ if (!backlinks.length) {+ return (+ // An item of the `<ul>` that `BacklinksWidget` renders the list into.+ <li className="backlinks-empty">+ <NoItems size="small" icon="bx bx-link" text={t("zpetne_odkazy.no_backlinks")} />+ </li>+ );+ }++ // Keyed by position: one source note takes a row per relation it points with, so a note ID names+ // no single row, and the whole list is rebuilt at once anyway.+ return backlinks.map((backlink, index) => (+ <li key={index}>+ {/* Named so that the styling has something to hang off other than the position of the+ link within the item (see Backlinks.css). */}+ <NoteLink+ notePath={backlink.noteId}+ containerClassName="backlink-header"+ showNotePath showNoteIcon+ noPreview+ />++ {"relationName" in backlink ? (+ <p className="backlink-relation">{backlink.relationName}</p>+ ) : (+ backlink.excerpts.map((excerpt, excerptIndex) => (+ <RawHtml key={excerptIndex} html={sanitizeNoteContentHtml(excerpt)} />+ ))+ )}+ </li>+ ));+}++export function useBacklinkCount(note: FNote | null | undefined, isDefaultViewMode: boolean) {+ const [ backlinkCount, setBacklinkCount ] = useState(0);++ const refresh = useCallback(() => {+ if (!note || !isDefaultViewMode) return;++ server.get<BacklinkCountResponse>(`note-map/${note.noteId}/backlink-count`).then(resp => {+ setBacklinkCount(resp.count);+ });+ }, [ isDefaultViewMode, note ]);++ useEffect(() => refresh(), [ refresh ]);+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {+ if (note && needsRefresh(note, loadResults)) refresh();+ });++ return backlinkCount;+}++function needsRefresh(note: FNote, loadResults: LoadResults) {+ return loadResults.getAttributeRows().some(attr =>+ attr.type === "relation" &&+ attributes.isAffecting(attr, note));+}