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 ribbon
Elian Doran7cebdd622d7d
diff --git a/apps/client/src/layouts/desktop_layout.tsx b/apps/client/src/layouts/desktop_layout.tsxindex 650d924b35..b61de77fb2 100644--- a/apps/client/src/layouts/desktop_layout.tsx+++ b/apps/client/src/layouts/desktop_layout.tsx@@ -4,11 +4,8 @@ import { isExperimentalFeatureEnabled } from "../services/experimental_features.import options from "../services/options.js";import utils from "../services/utils.js";import ApiLog from "../widgets/api_log.jsx";-import ClosePaneButton from "../widgets/buttons/close_pane_button.js";-import CreatePaneButton from "../widgets/buttons/create_pane_button.js";import GlobalMenu from "../widgets/buttons/global_menu.jsx";import LeftPaneToggle from "../widgets/buttons/left_pane_toggle.js";-import MovePaneButton from "../widgets/buttons/move_pane_button.js";import RightPaneToggle from "../widgets/buttons/right_pane_toggle.jsx";import CloseZenModeButton from "../widgets/close_zen_button.jsx";import NoteList from "../widgets/collections/NoteList.jsx";@@ -35,7 +32,6 @@ import NoteWrapperWidget from "../widgets/note_wrapper.js";import NoteDetail from "../widgets/NoteDetail.jsx";import QuickSearch from "../widgets/quick_search.jsx";import { FixedFormattingToolbar } from "../widgets/ribbon/FormattingToolbar.jsx";-import LazyComponent from "../widgets/react/LazyComponent.jsx";import NoteActions from "../widgets/ribbon/NoteActions.jsx";import ScrollPadding from "../widgets/scroll_padding.js";import SearchResult from "../widgets/search_result.jsx";@@ -132,12 +128,7 @@ export default class DesktopLayout {.child(<NoteTitleWidget />).child(<NoteBadges />).child(<SpacerWidget baseSize={0} growthFactor={1} />)- .optChild(!isNewLayout, <MovePaneButton direction="left" />)- .optChild(!isNewLayout, <MovePaneButton direction="right" />)- .optChild(!isNewLayout, <ClosePaneButton />)- .optChild(!isNewLayout, <CreatePaneButton />)- .optChild(isNewLayout, <NoteActions />))- .optChild(!isNewLayout, <LazyComponent loader={() => import("../widgets/ribbon/Ribbon.jsx")} />)+ .child(<NoteActions />)).child(new WatchedFileUpdateStatusWidget()).optChild(!isNewLayout, <FloatingButtons items={DESKTOP_FLOATING_BUTTONS} />).child(diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex a5c8e03f09..3a250a3fc0 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -2407,7 +2407,6 @@ body.zen .right-pane-peek-button,body.zen #mobile-sidebar-wrapper,body.zen .tab-row-container,body.zen .tab-row-widget,-body.zen .ribbon-container,body.zen .title-row .icon-action,body.zen .note-badges > *:not(.read-only-badge),body.zen .ribbon-button-container,diff --git a/apps/client/src/stylesheets/theme-next/ribbon.css b/apps/client/src/stylesheets/theme-next/ribbon.cssindex c46c5da75d..be594d2e80 100644--- a/apps/client/src/stylesheets/theme-next/ribbon.css+++ b/apps/client/src/stylesheets/theme-next/ribbon.css@@ -1,32 +1,3 @@-@container info-section (max-width: 800px) {- table, tbody, tr, td, th {- display: block;- padding: 0 !important;- }-- tbody {- display: flex;- flex-wrap: wrap;- gap: 10px;- }-- tr {- flex-grow: 1;- }-- tr:has(.file-buttons) {- width: 100%;- }-- th {- font-size: .85em;- }-- td {- margin-bottom: .5em;- }-}-/** Promoted attributes*/diff --git a/apps/client/src/stylesheets/theme-next/shell.css b/apps/client/src/stylesheets/theme-next/shell.cssindex 8100c0ad8b..6eef158cd7 100644--- a/apps/client/src/stylesheets/theme-next/shell.css+++ b/apps/client/src/stylesheets/theme-next/shell.css@@ -1272,14 +1272,6 @@ body:not(.background-effects) #center-pane .note-split {animation: note-entrance 100ms linear;}-/*- * Ribbon & note header- */--.ribbon-container {- margin-bottom: 0 !important;-}-@keyframes note-entrance {from {filter: opacity(0);diff --git a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsxindex 4f1d299e53..958f544810 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx@@ -110,8 +110,7 @@ vi.mock("../layout/NoteBadges", () => ({ default: () => null }));vi.mock("../layout/NoteTypeSwitcher", () => ({default: () => <div className="note-type-switcher-stub" />}));-vi.mock("../ribbon/components/StandaloneRibbonAdapter", () => ({ default: () => null }));-vi.mock("../ribbon/FormattingToolbar", () => ({ default: () => null, showFormattingToolbar: () => false }));+vi.mock("../ribbon/FormattingToolbar", () => ({ default: () => null }));vi.mock("../type_widgets/text/mobile_editor_toolbar", () => ({ default: () => <div className="mobile-toolbar-stub" /> }));vi.mock("../note_icon", () => ({ default: () => <div className="note-icon-stub" /> }));vi.mock("../note_title", () => ({ default: () => <div className="note-title-stub" /> }));diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsxindex 7c0f8a125b..4f35d5ad0c 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx@@ -19,8 +19,7 @@ import PromotedAttributes from "../PromotedAttributes";import { useContainedLinkNavigation, useNoteContext, useNoteLabel, useTriliumEvent } from "../react/hooks";import Modal from "../react/Modal";import { NoteContextContext, ParentComponent } from "../react/react_utils";-import StandaloneRibbonAdapter from "../ribbon/components/StandaloneRibbonAdapter";-import FormattingToolbar, { showFormattingToolbar } from "../ribbon/FormattingToolbar";+import FormattingToolbar from "../ribbon/FormattingToolbar";import MobileEditorToolbar from "../type_widgets/text/mobile_editor_toolbar";/** The layer the stylesheet gives this popup while it stands over another modal. */@@ -184,7 +183,7 @@ export default function PopupEditor() {{isMobile? <MobileEditorToolbar inPopupEditor />- : <StandaloneRibbonAdapter component={FormattingToolbar} show={showFormattingToolbar} />}+ : <FormattingToolbar />}<FloatingButtons items={items} /><NoteDetail />diff --git a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx b/apps/client/src/widgets/ribbon/FormattingToolbar.tsxindex ef62476bb1..309133dd53 100644--- a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx+++ b/apps/client/src/widgets/ribbon/FormattingToolbar.tsx@@ -6,8 +6,7 @@ import { useEffect, useRef, useState } from "preact/hooks";import NoteContext from "../../components/note_context";import FNote from "../../entities/fnote";import options from "../../services/options";-import { useActiveNoteContext, useNoteProperty, useTriliumEvent, useTriliumEvents, useTriliumOption } from "../react/hooks";-import { TabConfiguration, TabContext } from "./ribbon-interface";+import { useActiveNoteContext, useNoteContext, useNoteProperty, useTriliumEvent, useTriliumEvents, useTriliumOption } from "../react/hooks";/*** Handles the editing toolbar of a single note context when the CKEditor is in decoupled mode, as@@ -17,9 +16,24 @@ import { TabConfiguration, TabContext } from "./ribbon-interface";** The mobile toolbar is handled separately (see `MobileEditorToolbar`).*/-export default function FormattingToolbar({ hidden, ntxId }: TabContext) {+export default function FormattingToolbar() {const containerRef = useRef<HTMLDivElement>(null);+ const { note, noteContext, ntxId } = useNoteContext();const [ textNoteEditorType ] = useTriliumOption("textNoteEditorType");+ const [ shown, setShown ] = useState(false);++ useEffect(() => {+ let active = true;+ void showFormattingToolbar(note, noteContext).then((result) => {+ // Ignore a stale resolution if the note changed while the check was pending.+ if (active) {+ setShown(result);+ }+ });+ return () => {+ active = false;+ };+ }, [ note, noteContext ]);// Attach the toolbar from the CKEditor.useTriliumEvent("textEditorRefreshed", ({ ntxId: eventNtxId, editor }) => {@@ -36,16 +50,16 @@ export default function FormattingToolbar({ hidden, ntxId }: TabContext) {return (textNoteEditorType === "ckeditor-classic" &&<divref={containerRef}- className={`classic-toolbar-widget ${hidden ? "hidden-ext" : ""}`}+ className={`classic-toolbar-widget ${!shown ? "hidden-ext" : ""}`}/>);};-/** Visibility predicate for the quick edit popup's formatting toolbar. */-export const showFormattingToolbar: TabConfiguration["show"] = async ({ note, noteContext }) =>- note?.type === "text" && noteContext?.viewScope?.viewMode === "default"- && options.get("textNoteEditorType") === "ckeditor-classic"- && !(await noteContext?.isReadOnly());+async function showFormattingToolbar(note: FNote | null | undefined, noteContext: NoteContext | undefined) {+ return note?.type === "text" && noteContext?.viewScope?.viewMode === "default"+ && options.get("textNoteEditorType") === "ckeditor-classic"+ && !(await noteContext?.isReadOnly());+}const toolbarCache = new Map<string, HTMLElement | null | undefined>();diff --git a/apps/client/src/widgets/ribbon/NoteActions.css b/apps/client/src/widgets/ribbon/NoteActions.cssindex c24c1a3005..ab5aa43cf0 100644--- a/apps/client/src/widgets/ribbon/NoteActions.css+++ b/apps/client/src/widgets/ribbon/NoteActions.css@@ -1,10 +1,30 @@-.ribbon-button-container {+.title-row > .ribbon-button-container {+ --button-gap: 5px;+display: flex;- border-bottom: 1px solid var(--main-border-color);- margin-inline-end: 5px;align-items: center;height: 36px;- gap: 10px;+ margin: 0;+ gap: var(--button-gap);++ button {+ transition: opacity 250ms ease-in;++ &.disabled {+ opacity: 0.4;+ }+ }++ .note-actions-custom {+ display: flex;+ align-items: center;+ height: 36px;+ gap: var(--button-gap);++ &> button:last-of-type {+ margin-inline-end: 0.5em;+ }+ }}.note-actions {@@ -23,30 +43,3 @@background-color: transparent !important;pointer-events: none; /* makes it unclickable */}--body.experimental-feature-new-layout .ribbon-button-container {- --button-gap: 5px;-- border-bottom: 0 !important;- margin: 0;- gap: var(--button-gap);-- button {- transition: opacity 250ms ease-in;-- &.disabled {- opacity: 0.4;- }- }-}--.ribbon-button-container .note-actions-custom {- display: flex;- align-items: center;- height: 36px;- gap: var(--button-gap, 10px);-- &> button:last-of-type {- margin-inline-end: 0.5em;- }-}diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsxindex 56c0af9874..e211a927cd 100644--- a/apps/client/src/widgets/ribbon/NoteActions.tsx+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx@@ -37,17 +37,12 @@ export default function NoteActions() {const { note, ntxId, noteContext } = useNoteContext();return (<div className="ribbon-button-container" style={{ contain: "none" }}>- {isNewLayout && (- <>- {note && ntxId && noteContext && <NoteActionsCustom note={note} ntxId={ntxId} noteContext={noteContext} />}- <MovePaneButton direction="left" />- <MovePaneButton direction="right" />- <ClosePaneButton />- <CreatePaneButton />- </>- )}- {!isNewLayout && note && ntxId && noteContext && <NoteActionsCustom note={note} ntxId={ntxId} noteContext={noteContext} typeActionsOnly />}+ {note && ntxId && noteContext && <NoteActionsCustom note={note} ntxId={ntxId} noteContext={noteContext} typeActionsOnly={!isNewLayout} />}{note && !isNewLayout && <RevisionsButton note={note} />}+ <MovePaneButton direction="left" />+ <MovePaneButton direction="right" />+ <ClosePaneButton />+ <CreatePaneButton />{note && note.type !== "launcher" && <NoteContextMenu note={note as FNote} noteContext={noteContext} />}</div>);diff --git a/apps/client/src/widgets/ribbon/Ribbon.css b/apps/client/src/widgets/ribbon/Ribbon.cssdeleted file mode 100644index 871dd94a60..0000000000--- a/apps/client/src/widgets/ribbon/Ribbon.css+++ /dev/null@@ -1,105 +0,0 @@-.ribbon-container {- margin-bottom: 5px;- position: relative;- z-index: 998;-}--.ribbon-top-row {- display: flex;- min-height: 36px;-}--.ribbon-tab-container {- display: flex;- flex-direction: row;- justify-content: center;- margin-inline-start: 10px;- flex-grow: 1;- flex-flow: row wrap;-}--.ribbon-tab-title {- color: var(--muted-text-color);- border-bottom: 1px solid var(--main-border-color);- min-width: 24px;- flex-basis: 24px;- max-width: max-content;- flex-grow: 10;- user-select: none;- display: flex;- align-items: center;- font-size: 0.9em;- padding-top: 2px;-}--.ribbon-tab-title .tn-icon {- font-size: 150%;- position: relative;-}--.ribbon-tab-title.active {- color: var(--main-text-color);- border-bottom: 3px solid var(--main-text-color);- white-space: nowrap;- overflow: hidden;- text-overflow: ellipsis;-}--.ribbon-tab-title:hover {- cursor: pointer;-}--.ribbon-tab-title:hover {- color: var(--main-text-color);-}--.ribbon-tab-title:first-of-type {- padding-inline-start: 10px;-}--.ribbon-tab-spacer {- flex-basis: 0;- min-width: 0;- max-width: 35px;- flex-grow: 1;- border-bottom: 1px solid var(--main-border-color);-}--.ribbon-tab-spacer:last-of-type {- flex-grow: 1;- flex-basis: 0;- min-width: 0;- max-width: 10000px;-}--.ribbon-body {- border-bottom: 1px solid var(--main-border-color);- margin-inline-start: 10px;- margin-inline-end: 5px; /* needs to have this value so that the bottom border is the same width as the top one */-}--.ribbon-body.active {- display: block;-}--.ribbon-tab-title.active .ribbon-tab-title-label {- display: inline;-}--body.experimental-feature-new-layout {- .ribbon-top-row {- min-height: 0;- }-- .ribbon-container {- display: flex;- flex-direction: column-reverse;- border: 0;-- .ribbon-tab-spacer,- .ribbon-tab-title,- .ribbon-body {- border-bottom: 0 !important;- }- }-}diff --git a/apps/client/src/widgets/ribbon/Ribbon.tsx b/apps/client/src/widgets/ribbon/Ribbon.tsxdeleted file mode 100644index c282be24f7..0000000000--- a/apps/client/src/widgets/ribbon/Ribbon.tsx+++ /dev/null@@ -1,147 +0,0 @@-import "./Ribbon.css";--import { KeyboardActionNames } from "@triliumnext/commons";-import clsx from "clsx";-import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";--import { EventNames } from "../../components/app_context";-import { Indexed, numberObjectsInPlace } from "../../services/utils";-import { useNoteContext, useNoteProperty, useStaticTooltipWithKeyboardShortcut, useTriliumEvents } from "../react/hooks";-import NoteActions from "./NoteActions";-import { shouldShowTab, TabConfiguration, TitleContext } from "./ribbon-interface";-import { RIBBON_TAB_DEFINITIONS } from "./RibbonDefinition";--const TAB_CONFIGURATION = numberObjectsInPlace<TabConfiguration>(RIBBON_TAB_DEFINITIONS);--interface ComputedTab extends Indexed<TabConfiguration> {- shouldShow: boolean;-}--export default function Ribbon() {- const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId, isReadOnlyTemporarilyDisabled } = useNoteContext();- const noteType = useNoteProperty(note, "type");- const [ activeTabIndex, setActiveTabIndex ] = useState<number | undefined>();- const [ computedTabs, setComputedTabs ] = useState<ComputedTab[]>();- const titleContext: TitleContext = useMemo(() => ({- note,- noteContext- }), [ note, noteContext ]);-- async function refresh() {- const computedTabs: ComputedTab[] = [];- for (const tab of TAB_CONFIGURATION) {- const shouldShow = await shouldShowTab(tab.show, titleContext);- computedTabs.push({- ...tab,- shouldShow: !!shouldShow- });- }- setComputedTabs(computedTabs);- }-- useEffect(() => {- refresh();- }, [ note, noteType, isReadOnlyTemporarilyDisabled ]);-- // Automatically activate the first ribbon tab that needs to be activated whenever a note changes.- useEffect(() => {- if (!computedTabs) return;- const tabToActivate = computedTabs.find(tab => tab.shouldShow && (typeof tab.activate === "boolean" ? tab.activate : tab.activate?.(titleContext)));- setActiveTabIndex(tabToActivate?.index);- }, [ computedTabs, note?.noteId ]);-- // Register keyboard shortcuts.- const eventsToListenTo = useMemo(() => TAB_CONFIGURATION.filter(config => config.toggleCommand).map(config => config.toggleCommand) as EventNames[], []);- useTriliumEvents(eventsToListenTo, useCallback((e, toggleCommand) => {- if (!computedTabs) return;- const correspondingTab = computedTabs.find(tab => tab.toggleCommand === toggleCommand);- if (correspondingTab?.shouldShow) {- if (activeTabIndex !== correspondingTab.index) {- setActiveTabIndex(correspondingTab.index);- } else {- setActiveTabIndex(undefined);- }- }- }, [ computedTabs, activeTabIndex ]));-- const shouldShowRibbon = (noteContext?.viewScope?.viewMode === "default" && !noteContext.noteId?.startsWith("_options"));- return (- <div- className={clsx("ribbon-container", !shouldShowRibbon && "hidden-ext")}- style={{ contain: "none" }}- >- <div className="ribbon-top-row">- <div className="ribbon-tab-container">- {computedTabs && computedTabs.map(({ title, icon, index, toggleCommand, shouldShow }) => (- shouldShow && <RibbonTab- icon={icon}- title={typeof title === "string" ? title : title(titleContext)}- active={index === activeTabIndex}- toggleCommand={toggleCommand}- onClick={() => {- if (activeTabIndex !== index) {- setActiveTabIndex(index);- } else {- // Collapse- setActiveTabIndex(undefined);- }- }}- />- ))}- </div>- <NoteActions />- </div>-- <div className="ribbon-body-container">- {computedTabs && computedTabs.map(tab => {- const isActive = tab.index === activeTabIndex;- if (!isActive) {- return;- }-- const TabContent = tab.content;-- return (- <div className={`ribbon-body ${!isActive ? "hidden-ext" : ""}`}>- <TabContent- note={note}- hidden={!isActive}- ntxId={ntxId}- hoistedNoteId={hoistedNoteId}- notePath={notePath}- noteContext={noteContext}- componentId={componentId}- activate={useCallback(() => {- setActiveTabIndex(tab.index);- }, [setActiveTabIndex])}- />- </div>- );- })}- </div>- </div>- );-}--function RibbonTab({ icon, title, active, onClick, toggleCommand }: { icon: string; title: string; active: boolean, onClick: () => void, toggleCommand?: KeyboardActionNames }) {- const iconRef = useRef<HTMLDivElement>(null);- useStaticTooltipWithKeyboardShortcut(iconRef, title, toggleCommand);-- return (- <>- <div- className={`ribbon-tab-title ${active ? "active" : ""}`}- onClick={onClick}- >- <span- ref={iconRef}- className={`ribbon-tab-title-icon tn-icon ${icon}`}- />- - { active && <span class="ribbon-tab-title-label">{title}</span> }- </div>-- <div class="ribbon-tab-spacer" />- </>- );-}diff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.tsdeleted file mode 100644index 35b57ff167..0000000000--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts+++ /dev/null@@ -1,3 +0,0 @@-import { TabConfiguration } from "./ribbon-interface";--export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [];diff --git a/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx b/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsxdeleted file mode 100644index 62158c3c90..0000000000--- a/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx+++ /dev/null@@ -1,47 +0,0 @@-import { ComponentChildren } from "preact";-import { useEffect, useState } from "preact/hooks";--import { useNoteContext } from "../../react/hooks";-import { shouldShowTab, TabConfiguration, TabContext } from "../ribbon-interface";--interface StandaloneRibbonAdapterProps {- component: (props: TabContext) => ComponentChildren;- /** The visibility predicate of the component, normally defined in the ribbon tab configuration. */- show: TabConfiguration["show"];-}--/**- * Takes in any ribbon tab component and renders it in standalone mod using the note context, thus requiring no inputs.- * Especially useful on mobile to detach components that would normally fit in the ribbon.- */-export default function StandaloneRibbonAdapter({ component, show }: StandaloneRibbonAdapterProps) {- const Component = component;- const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId } = useNoteContext();- const [ shown, setShown ] = useState<boolean | null | undefined>(false);-- useEffect(() => {- let active = true;- void shouldShowTab(show, { note, noteContext }).then((result) => {- // Ignore a stale resolution if the note changed while the predicate was pending.- if (active) {- setShown(result);- }- });- return () => {- active = false;- };- }, [ note, noteContext, show ]);-- return (- <Component- note={note}- hidden={!shown}- ntxId={ntxId}- hoistedNoteId={hoistedNoteId}- notePath={notePath}- noteContext={noteContext}- componentId={componentId}- activate={() => {}}- />- );-}diff --git a/apps/client/src/widgets/ribbon/ribbon-interface.ts b/apps/client/src/widgets/ribbon/ribbon-interface.tsdeleted file mode 100644index 7e8365ead2..0000000000--- a/apps/client/src/widgets/ribbon/ribbon-interface.ts+++ /dev/null@@ -1,37 +0,0 @@-import { KeyboardActionNames } from "@triliumnext/commons";-import { VNode } from "preact";--import NoteContext from "../../components/note_context";-import FNote from "../../entities/fnote";--export interface TabContext {- note: FNote | null | undefined;- hidden: boolean;- ntxId?: string | null;- hoistedNoteId?: string;- notePath?: string | null;- noteContext?: NoteContext;- componentId: string;- activate(): void;-}--export interface TitleContext {- note: FNote | null | undefined;- noteContext: NoteContext | undefined;-}--export interface TabConfiguration {- title: string | ((context: TitleContext) => string);- icon: string;- content: (context: TabContext) => VNode | false;- show: boolean | ((context: TitleContext) => Promise<boolean | null | undefined> | boolean | null | undefined);- toggleCommand?: KeyboardActionNames;- activate?: boolean | ((context: TitleContext) => boolean);-}--export async function shouldShowTab(showConfig: TabConfiguration["show"], context: TitleContext) {- if (showConfig === null || showConfig === undefined) return true;- if (typeof showConfig === "boolean") return showConfig;- if ("then" in showConfig) return await showConfig(context);- return showConfig(context);-}