Skip to content

Build your personal knowledge base with Trilium Notes

perf(client): load the ribbon lazily so the new layout skips its module graph

Elian Doran8d86cea726be
diff --git a/apps/client/src/layouts/desktop_layout.tsx b/apps/client/src/layouts/desktop_layout.tsx
index eda2a56cc9..3251588638 100644
--- a/apps/client/src/layouts/desktop_layout.tsx
+++ b/apps/client/src/layouts/desktop_layout.tsx
@@ -40,8 +40,8 @@ import PromotedAttributes from "../widgets/PromotedAttributes.jsx";
import QuickSearchWidget from "../widgets/quick_search.js";
import ReadOnlyNoteInfoBar from "../widgets/ReadOnlyNoteInfoBar.jsx";
import { FixedFormattingToolbar } from "../widgets/ribbon/FormattingToolbar.jsx";
+import LazyComponent from "../widgets/react/LazyComponent.jsx";
import NoteActions from "../widgets/ribbon/NoteActions.jsx";
-import Ribbon from "../widgets/ribbon/Ribbon.jsx";
import ScrollPadding from "../widgets/scroll_padding.js";
import SearchResult from "../widgets/search_result.jsx";
import SharedInfo from "../widgets/shared_info.jsx";
@@ -148,7 +148,7 @@ export default class DesktopLayout {
.optChild(!isNewLayout, <ClosePaneButton />)
.optChild(!isNewLayout, <CreatePaneButton />)
.optChild(isNewLayout, <NoteActions />))
- .optChild(!isNewLayout, <Ribbon />)
+ .optChild(!isNewLayout, <LazyComponent loader={() => import("../widgets/ribbon/Ribbon.jsx")} />)
.child(new WatchedFileUpdateStatusWidget())
.optChild(!isNewLayout, <FloatingButtons items={DESKTOP_FLOATING_BUTTONS} />)
.child(
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsx
index 8fef7674e8..8a39300da9 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx
+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx
@@ -23,7 +23,7 @@ import Modal from "../react/Modal";
import { NoteContextContext, ParentComponent } from "../react/react_utils";
import ReadOnlyNoteInfoBar from "../ReadOnlyNoteInfoBar";
import StandaloneRibbonAdapter from "../ribbon/components/StandaloneRibbonAdapter";
-import FormattingToolbar from "../ribbon/FormattingToolbar";
+import FormattingToolbar, { showFormattingToolbar } from "../ribbon/FormattingToolbar";
import MobileEditorToolbar from "../type_widgets/text/mobile_editor_toolbar";
const isNewLayout = isExperimentalFeatureEnabled("new-layout");
@@ -129,7 +129,7 @@ export default function PopupEditor() {
{isMobile
? <MobileEditorToolbar inPopupEditor />
- : <StandaloneRibbonAdapter component={FormattingToolbar} />}
+ : <StandaloneRibbonAdapter component={FormattingToolbar} show={showFormattingToolbar} />}
<FloatingButtons items={items} />
<NoteDetail />
diff --git a/apps/client/src/widgets/note_map/NoteMap.css b/apps/client/src/widgets/note_map/NoteMap.css
index 3188f09439..15955713a8 100644
--- a/apps/client/src/widgets/note_map/NoteMap.css
+++ b/apps/client/src/widgets/note_map/NoteMap.css
@@ -55,3 +55,8 @@
}
/* End of styling the slider */
+
+.style-resolver {
+ color: var(--muted-text-color);
+ display: none;
+}
diff --git a/apps/client/src/widgets/react/LazyComponent.css b/apps/client/src/widgets/react/LazyComponent.css
new file mode 100644
index 0000000000..627468d7a2
--- /dev/null
+++ b/apps/client/src/widgets/react/LazyComponent.css
@@ -0,0 +1,3 @@
+.lazy-component {
+ display: contents;
+}
diff --git a/apps/client/src/widgets/react/LazyComponent.tsx b/apps/client/src/widgets/react/LazyComponent.tsx
new file mode 100644
index 0000000000..0fff1ed1e8
--- /dev/null
+++ b/apps/client/src/widgets/react/LazyComponent.tsx
@@ -0,0 +1,40 @@
+import "./LazyComponent.css";
+
+import { ComponentType } from "preact";
+import { useEffect, useState } from "preact/hooks";
+
+interface LazyComponentProps {
+ /** Loader returning the module whose default export is the component to render, e.g. `() => import("./MyComponent.jsx")`. */
+ loader: () => Promise<{ default: ComponentType }>;
+}
+
+/**
+ * Renders a component that is loaded on demand via a dynamic import, keeping its module
+ * graph out of the initial bundle. The loader runs on first mount.
+ *
+ * The component is rendered inside a stable `display: contents` wrapper: the legacy widget
+ * adapter extracts the rendered root node out of Preact's render container, so the root
+ * element must never change identity across re-renders — swapping it (or rendering nothing)
+ * would make subsequent renders go to the discarded container instead of the live DOM.
+ */
+export default function LazyComponent({ loader }: LazyComponentProps) {
+ const [ Component, setComponent ] = useState<ComponentType | null>(null);
+
+ useEffect(() => {
+ let cancelled = false;
+ void loader().then(({ default: component }) => {
+ if (!cancelled) {
+ setComponent(() => component);
+ }
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [ loader ]);
+
+ return (
+ <div className="lazy-component">
+ {Component && <Component />}
+ </div>
+ );
+}
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index 672922d012..a4a8cfb07e 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -375,10 +375,14 @@ export function useUniqueName(prefix?: string) {
}
export function useNoteContext() {
+ const parentComponent = useContext(ParentComponent) as ReactWrappedWidget;
const noteContextContext = useContext(NoteContextContext);
- const [ noteContext, setNoteContext ] = useState<NoteContext | undefined>(noteContextContext ?? undefined);
- const [ notePath, setNotePath ] = useState<string | null | undefined>();
- const [ note, setNote ] = useState<FNote | null | undefined>();
+ // Components can mount after the initial setNoteContext event has already been dispatched
+ // (e.g. when rendered via LazyComponent), so fall back to the note context held by the
+ // closest legacy ancestor instead of waiting for the next note switch.
+ const [ noteContext, setNoteContext ] = useState<NoteContext | undefined>(() => noteContextContext ?? findClosestNoteContext(parentComponent));
+ const [ notePath, setNotePath ] = useState<string | null | undefined>(noteContext?.notePath);
+ const [ note, setNote ] = useState<FNote | null | undefined>(noteContext?.note);
const [ hoistedNoteId, setHoistedNoteId ] = useState(noteContext?.hoistedNoteId);
const [ , setViewScope ] = useState<ViewScope>();
const [ isReadOnlyTemporarilyDisabled, setIsReadOnlyTemporarilyDisabled ] = useState<boolean | null | undefined>(noteContext?.viewScope?.isReadOnly);
@@ -432,7 +436,6 @@ export function useNoteContext() {
}
});
- const parentComponent = useContext(ParentComponent) as ReactWrappedWidget;
useDebugValue(() => `notePath=${notePath}, ntxId=${noteContext?.ntxId}`);
return {
@@ -449,6 +452,26 @@ export function useNoteContext() {
};
}
+/**
+ * Finds the note context held by the closest legacy ancestor component (e.g. the note split's
+ * `NoteWrapperWidget`). Used to initialize {@link useNoteContext} for components that mount after
+ * the initial `setNoteContext` event has been dispatched (e.g. components rendered via
+ * `LazyComponent`), which would otherwise not know their context until the next note switch.
+ */
+function findClosestNoteContext(component: Component | null): NoteContext | undefined {
+ let current: Component | undefined = component ?? undefined;
+ while (current) {
+ if ("noteContext" in current) {
+ const { noteContext } = current as { noteContext?: NoteContext };
+ if (noteContext) {
+ return noteContext;
+ }
+ }
+ current = current.parent as Component | undefined;
+ }
+ return undefined;
+}
+
/**
* Similar to {@link useNoteContext}, but instead of using the note context from the split container that the component is part of, it uses the active note context instead
* (the note currently focused by the user).
diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.css b/apps/client/src/widgets/ribbon/BasicPropertiesTab.css
new file mode 100644
index 0000000000..9954a32c57
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/BasicPropertiesTab.css
@@ -0,0 +1,29 @@
+.basic-properties-widget {
+ padding: 0px 12px 6px 12px;
+ display: flex;
+ align-items: baseline;
+ flex-wrap: wrap;
+}
+
+.basic-properties-widget > * {
+ margin-top: 9px;
+ margin-bottom: 2px;
+ margin-inline-end: 30px;
+}
+
+.note-type-container,
+.editability-select-container,
+.note-language-container {
+ display: flex;
+ align-items: center;
+}
+
+.note-type-dropdown {
+ max-height: 500px;
+ overflow-y: auto;
+ overflow-x: hidden;
+}
+
+.editability-dropdown {
+ width: 300px;
+}
diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx
index 00daae89e5..21c77243c3 100644
--- a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx
+++ b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx
@@ -1,3 +1,5 @@
+import "./BasicPropertiesTab.css";
+
import { MimeType, NoteType, ToggleInParentResponse } from "@triliumnext/commons";
import { createPortal } from "preact/compat";
import { Dispatch, StateUpdater, useCallback, useEffect, useMemo, useState } from "preact/hooks";
diff --git a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.css b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.css
new file mode 100644
index 0000000000..d3088992ff
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.css
@@ -0,0 +1,29 @@
+.book-properties-widget {
+ padding: 12px 12px 6px 12px;
+ display: flex;
+ flex-wrap: wrap;
+ gap: 15px;
+ overflow: visible;
+ align-items: center;
+}
+
+.book-properties-widget > * {
+ flex-shrink: 0;
+}
+
+.book-properties-widget > .type-number > label {
+ display: flex;
+ align-items: baseline;
+}
+
+.book-properties-widget input[type="checkbox"] {
+ margin-inline-end: 5px;
+}
+
+.book-properties-widget label {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ text-overflow: clip;
+ white-space: nowrap;
+}
diff --git a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx
index 7a0f9080d9..3055388e5d 100644
--- a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx
+++ b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx
@@ -1,3 +1,5 @@
+import "./CollectionPropertiesTab.css";
+
import { ComponentChildren } from "preact";
import { useContext, useMemo } from "preact/hooks";
diff --git a/apps/client/src/widgets/ribbon/FilePropertiesTab.css b/apps/client/src/widgets/ribbon/FilePropertiesTab.css
new file mode 100644
index 0000000000..c0e62cf1b1
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/FilePropertiesTab.css
@@ -0,0 +1,15 @@
+.file-table {
+ width: 100%;
+ margin-top: 10px;
+}
+
+.file-table th, .file-table td {
+ padding: 5px;
+ overflow-wrap: anywhere;
+}
+
+.file-buttons {
+ padding: 10px;
+ display: flex;
+ justify-content: space-evenly;
+}
diff --git a/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx b/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx
index 2d93b29f54..0325a9a2fd 100644
--- a/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx
+++ b/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx
@@ -1,3 +1,5 @@
+import "./FilePropertiesTab.css";
+
import { useContext } from "preact/hooks";
import FNote from "../../entities/fnote";
diff --git a/apps/client/src/widgets/ribbon/FormattingToolbar.css b/apps/client/src/widgets/ribbon/FormattingToolbar.css
new file mode 100644
index 0000000000..750646595b
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/FormattingToolbar.css
@@ -0,0 +1,23 @@
+.classic-toolbar-widget {
+ --ck-color-toolbar-background: transparent;
+ --ck-color-button-default-background: transparent;
+ --ck-color-button-default-disabled-background: transparent;
+ min-height: 39px;
+}
+
+.classic-toolbar-widget .ck.ck-toolbar {
+ border: none;
+}
+
+.classic-toolbar-widget .ck.ck-button.ck-disabled {
+ opacity: 0.3;
+}
+
+body.experimental-feature-new-layout .classic-toolbar-widget {
+ transition: opacity 250ms ease-in;
+
+ &.disabled {
+ opacity: 0.3;
+ pointer-events: none;
+ }
+}
diff --git a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx b/apps/client/src/widgets/ribbon/FormattingToolbar.tsx
index 0225a74bcf..c2afce18f7 100644
--- a/apps/client/src/widgets/ribbon/FormattingToolbar.tsx
+++ b/apps/client/src/widgets/ribbon/FormattingToolbar.tsx
@@ -1,10 +1,13 @@
+import "./FormattingToolbar.css";
+
import clsx from "clsx";
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 { TabContext } from "./ribbon-interface";
+import { TabConfiguration, TabContext } from "./ribbon-interface";
/**
* Handles the editing toolbar when the CKEditor is in decoupled mode.
@@ -40,6 +43,12 @@ export default function FormattingToolbar({ hidden, ntxId }: TabContext) {
);
};
+/** Visibility predicate for the formatting toolbar, shared by the ribbon tab definition and the standalone usages (e.g. the popup editor). */
+export const showFormattingToolbar: TabConfiguration["show"] = async ({ note, noteContext }) =>
+ note?.type === "text" && noteContext?.viewScope?.viewMode === "default"
+ && options.get("textNoteEditorType") === "ckeditor-classic"
+ && !(await noteContext?.isReadOnly());
+
const toolbarCache = new Map<string, HTMLElement | null | undefined>();
export function FixedFormattingToolbar() {
diff --git a/apps/client/src/widgets/ribbon/InheritedAttributesTab.css b/apps/client/src/widgets/ribbon/InheritedAttributesTab.css
new file mode 100644
index 0000000000..b9750e7182
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/InheritedAttributesTab.css
@@ -0,0 +1,18 @@
+.inherited-attributes-widget {
+ position: relative;
+}
+
+.inherited-attributes-widget .attr-detail {
+ contain: none;
+}
+
+.inherited-attributes-container {
+ color: var(--muted-text-color);
+ max-height: 200px;
+ overflow: auto;
+ padding: 14px 12px 13px 12px;
+
+ a.reference-link {
+ text-decoration: underline;
+ }
+}
diff --git a/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx b/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx
index 4e2257c146..5aa4943af6 100644
--- a/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx
+++ b/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx
@@ -1,3 +1,5 @@
+import "./InheritedAttributesTab.css";
+
import { createPortal } from "preact/compat";
import { useEffect, useState } from "preact/hooks";
diff --git a/apps/client/src/widgets/ribbon/NoteActions.css b/apps/client/src/widgets/ribbon/NoteActions.css
new file mode 100644
index 0000000000..63c6540648
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/NoteActions.css
@@ -0,0 +1,52 @@
+.ribbon-button-container {
+ display: flex;
+ border-bottom: 1px solid var(--main-border-color);
+ margin-inline-end: 5px;
+ align-items: center;
+ height: 36px;
+ gap: 10px;
+}
+
+.note-actions {
+ width: 35px;
+ height: 35px;
+ display: flex;
+ align-items: center;
+}
+
+.note-actions .dropdown-menu {
+ min-width: 15em;
+}
+
+.note-actions .dropdown-item[disabled], .note-actions .dropdown-item[disabled]:hover {
+ color: var(--muted-text-color) !important;
+ 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;
+ }
+ }
+
+ .note-actions-custom {
+ display: flex;
+ align-items: center;
+ height: 36px;
+ gap: var(--button-gap);
+
+ &> 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.tsx
index fcf8b4d193..a841001aa3 100644
--- a/apps/client/src/widgets/ribbon/NoteActions.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx
@@ -1,3 +1,5 @@
+import "./NoteActions.css";
+
import { ConvertToAttachmentResponse } from "@triliumnext/commons";
import { Dropdown as BootstrapDropdown } from "bootstrap";
import { ComponentChildren, RefObject } from "preact";
diff --git a/apps/client/src/widgets/ribbon/NoteInfoTab.css b/apps/client/src/widgets/ribbon/NoteInfoTab.css
new file mode 100644
index 0000000000..7f927b8018
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/NoteInfoTab.css
@@ -0,0 +1,31 @@
+.note-info-widget {
+ padding: 12px;
+ display: flex;
+ flex-wrap: wrap;
+ align-items: baseline;
+}
+
+.note-info-item {
+ display: flex;
+ align-items: baseline;
+ padding-inline-end: 15px;
+ padding-block: 5px;
+}
+
+.note-info-item > span:first-child {
+ padding-inline-end: 5px;
+}
+
+.note-info-mime {
+ max-width: 13em;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.note-info-id {
+ font-variant: none;
+ font-family: var(--monospace-font-family);
+ font-size: 0.8em;
+ vertical-align: middle !important;
+}
diff --git a/apps/client/src/widgets/ribbon/NoteInfoTab.tsx b/apps/client/src/widgets/ribbon/NoteInfoTab.tsx
index 14888042e9..90427ef5da 100644
--- a/apps/client/src/widgets/ribbon/NoteInfoTab.tsx
+++ b/apps/client/src/widgets/ribbon/NoteInfoTab.tsx
@@ -1,3 +1,5 @@
+import "./NoteInfoTab.css";
+
import { MetadataResponse, NoteSizeResponse, SubtreeSizeResponse } from "@triliumnext/commons";
import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
diff --git a/apps/client/src/widgets/ribbon/NoteMapTab.css b/apps/client/src/widgets/ribbon/NoteMapTab.css
new file mode 100644
index 0000000000..2300b7e03a
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/NoteMapTab.css
@@ -0,0 +1,13 @@
+.note-map-ribbon-widget {
+ position: relative;
+}
+
+.note-map-ribbon-widget .note-map-container {
+ height: 100%;
+}
+
+.note-map-ribbon-widget .open-full-button, .note-map-ribbon-widget .collapse-button {
+ position: absolute;
+ inset-inline-end: 5px;
+ bottom: 5px;
+}
diff --git a/apps/client/src/widgets/ribbon/NoteMapTab.tsx b/apps/client/src/widgets/ribbon/NoteMapTab.tsx
index c803dfa021..c977532205 100644
--- a/apps/client/src/widgets/ribbon/NoteMapTab.tsx
+++ b/apps/client/src/widgets/ribbon/NoteMapTab.tsx
@@ -1,3 +1,5 @@
+import "./NoteMapTab.css";
+
import { TabContext } from "./ribbon-interface";
import { useElementSize, useWindowSize } from "../react/hooks";
import ActionButton from "../react/ActionButton";
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.css b/apps/client/src/widgets/ribbon/NotePathsTab.css
index 201117cce9..a47a8e174d 100644
--- a/apps/client/src/widgets/ribbon/NotePathsTab.css
+++ b/apps/client/src/widgets/ribbon/NotePathsTab.css
@@ -63,3 +63,25 @@ body.experimental-feature-new-layout .note-paths-widget {
}
}
+
+.note-paths-widget {
+ padding: 12px;
+ max-height: 300px;
+ overflow-y: auto;
+}
+
+.note-path-list {
+ margin-top: 10px;
+}
+
+.note-path-list .path-current a {
+ font-weight: bold;
+}
+
+.note-path-list .path-archived a {
+ color: var(--muted-text-color) !important;
+}
+
+.note-path-list .path-search a {
+ font-style: italic;
+}
diff --git a/apps/client/src/widgets/ribbon/Ribbon.css b/apps/client/src/widgets/ribbon/Ribbon.css
new file mode 100644
index 0000000000..72e11fb50f
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/Ribbon.css
@@ -0,0 +1,111 @@
+.ribbon-container {
+ margin-bottom: 5px;
+ position: relative;
+ z-index: 998;
+}
+
+/* When content header is floating, ribbon sticks below it */
+.scrolling-container:has(.content-header-widget.floating) .ribbon-container {
+ position: sticky;
+ top: var(--content-header-height, 100px);
+}
+
+.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.tsx
index 71f6a0dbdc..b84f21969e 100644
--- a/apps/client/src/widgets/ribbon/Ribbon.tsx
+++ b/apps/client/src/widgets/ribbon/Ribbon.tsx
@@ -1,4 +1,4 @@
-import "./style.css";
+import "./Ribbon.css";
import { KeyboardActionNames } from "@triliumnext/commons";
import clsx from "clsx";
@@ -8,7 +8,7 @@ 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 { TabConfiguration, TitleContext } from "./ribbon-interface";
+import { shouldShowTab, TabConfiguration, TitleContext } from "./ribbon-interface";
import { RIBBON_TAB_DEFINITIONS } from "./RibbonDefinition";
const TAB_CONFIGURATION = numberObjectsInPlace<TabConfiguration>(RIBBON_TAB_DEFINITIONS);
@@ -145,10 +145,3 @@ function RibbonTab({ icon, title, active, onClick, toggleCommand }: { icon: stri
</>
);
}
-
-export async function shouldShowTab(showConfig: boolean | ((context: TitleContext) => Promise<boolean | null | undefined> | boolean | null | undefined), 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);
-}
diff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
index 2adf748b35..c50b2bac09 100644
--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts
+++ b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
@@ -4,7 +4,7 @@ import BasicPropertiesTab from "./BasicPropertiesTab";
import CollectionPropertiesTab from "./CollectionPropertiesTab";
import EditedNotesTab from "./EditedNotesTab";
import FilePropertiesTab from "./FilePropertiesTab";
-import FormattingToolbar from "./FormattingToolbar";
+import FormattingToolbar, { showFormattingToolbar } from "./FormattingToolbar";
import ImagePropertiesTab from "./ImagePropertiesTab";
import InheritedAttributesTab from "./InheritedAttributesTab";
import NoteInfoTab from "./NoteInfoTab";
@@ -21,9 +21,7 @@ export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [
{
title: t("classic_editor_toolbar.title"),
icon: "bx bx-text",
- show: async ({ note, noteContext }) => note?.type === "text" && noteContext?.viewScope?.viewMode === "default"
- && options.get("textNoteEditorType") === "ckeditor-classic"
- && !(await noteContext?.isReadOnly()),
+ show: showFormattingToolbar,
toggleCommand: "toggleRibbonTabClassicEditor",
content: FormattingToolbar,
activate: ({ note }) => !options.is("editedNotesOpenInRibbon") || !note?.hasOwnedLabel("dateNote"),
diff --git a/apps/client/src/widgets/ribbon/ScriptTab.css b/apps/client/src/widgets/ribbon/ScriptTab.css
new file mode 100644
index 0000000000..1b2236ca28
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/ScriptTab.css
@@ -0,0 +1,8 @@
+.script-runner-widget {
+ padding: 12px;
+ color: var(--muted-text-color);
+}
+
+.execute-description {
+ margin-bottom: 10px;
+}
diff --git a/apps/client/src/widgets/ribbon/ScriptTab.tsx b/apps/client/src/widgets/ribbon/ScriptTab.tsx
index dbdd49a0b1..a744bb787c 100644
--- a/apps/client/src/widgets/ribbon/ScriptTab.tsx
+++ b/apps/client/src/widgets/ribbon/ScriptTab.tsx
@@ -1,3 +1,5 @@
+import "./ScriptTab.css";
+
import { t } from "../../services/i18n";
import Button from "../react/Button";
import { useNoteLabel } from "../react/hooks";
diff --git a/apps/client/src/widgets/ribbon/SimilarNotesTab.css b/apps/client/src/widgets/ribbon/SimilarNotesTab.css
index 560f2da0ce..753fa879fd 100644
--- a/apps/client/src/widgets/ribbon/SimilarNotesTab.css
+++ b/apps/client/src/widgets/ribbon/SimilarNotesTab.css
@@ -1,4 +1,22 @@
.similar-notes-widget > .similar-notes-wrapper {
/* The font size of the links with the highest similarity score */
font-size: 17px;
-}
\ No newline at end of file
+}
+.similar-notes-wrapper {
+ max-height: 200px;
+ overflow: auto;
+ padding: 12px;
+}
+
+.similar-notes-wrapper a {
+ display: inline-block;
+ border: 1px dotted var(--main-border-color);
+ border-radius: 20px;
+ background-color: var(--accented-background-color);
+ padding: 0 10px 0 10px;
+ margin: 0 3px 0 3px;
+ max-width: 10em;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ overflow: hidden;
+}
diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.css b/apps/client/src/widgets/ribbon/components/AttributeEditor.css
new file mode 100644
index 0000000000..617f2349cb
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.css
@@ -0,0 +1,52 @@
+/* Wrapper around the attribute editor, rendered by its consumers (e.g. the owned attributes tab, the status bar). */
+.attribute-list {
+ margin-inline-start: 7px;
+ margin-inline-end: 7px;
+ margin-top: 5px;
+ margin-bottom: 2px;
+ position: relative;
+}
+
+.attribute-list .attr-detail {
+ contain: none;
+}
+
+.attribute-list-editor {
+ border: 0 !important;
+ outline: 0 !important;
+ box-shadow: none !important;
+ padding: 0 100px 0 5px !important;
+ margin: 0 !important;
+ max-height: 100px;
+ overflow: auto;
+ transition: opacity .1s linear;
+}
+
+body[dir=rtl] .attribute-list-editor {
+ padding: 0 5px 0 100px !important;
+ text-align: right !important;
+}
+
+.attribute-list-editor p {
+ margin: 0 !important;
+}
+
+.attribute-list-editor.ck-content .mention {
+ color: var(--muted-text-color) !important;
+ background: transparent !important;
+}
+
+.attribute-editor-buttons {
+ display: flex;
+ position: absolute;
+ top: 0;
+ inset-inline-end: 0;
+ bottom: 0;
+ align-items: center;
+ gap: 10px;
+}
+
+.attribute-errors {
+ color: red;
+ padding: 5px 100px 0px 5px; /* large right padding to avoid buttons */
+}
diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx
index 1bc9f7ebf0..c8e8570a8d 100644
--- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx
+++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx
@@ -1,3 +1,5 @@
+import "./AttributeEditor.css";
+
import { AttributeEditor as CKEditorAttributeEditor, MentionFeed, ModelElement, ModelNode, ModelPosition } from "@triliumnext/ckeditor5";
import { AttributeType } from "@triliumnext/commons";
import type { Tooltip } from "bootstrap";
diff --git a/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx b/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx
index 1fbdd5d630..e5fed5220d 100644
--- a/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx
+++ b/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx
@@ -1,27 +1,26 @@
import { ComponentChildren } from "preact";
+import { useEffect, useState } from "preact/hooks";
+
import { useNoteContext } from "../../react/hooks";
-import { TabContext } from "../ribbon-interface";
-import { useEffect, useMemo, useState } from "preact/hooks";
-import { RIBBON_TAB_DEFINITIONS } from "../RibbonDefinition";
-import { shouldShowTab } from "../Ribbon";
+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 }: StandaloneRibbonAdapterProps) {
+export default function StandaloneRibbonAdapter({ component, show }: StandaloneRibbonAdapterProps) {
const Component = component;
const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId } = useNoteContext();
- const definition = useMemo(() => RIBBON_TAB_DEFINITIONS.find(def => def.content === component), [ component ]);
const [ shown, setShown ] = useState<boolean | null | undefined>(false);
useEffect(() => {
- if (!definition) return;
- shouldShowTab(definition.show, { note, noteContext }).then(setShown);
+ void shouldShowTab(show, { note, noteContext }).then(setShown);
}, [ note ]);
return (
diff --git a/apps/client/src/widgets/ribbon/ribbon-interface.ts b/apps/client/src/widgets/ribbon/ribbon-interface.ts
index 77543994d3..b6407b7506 100644
--- a/apps/client/src/widgets/ribbon/ribbon-interface.ts
+++ b/apps/client/src/widgets/ribbon/ribbon-interface.ts
@@ -32,3 +32,10 @@ export interface TabConfiguration {
*/
stayInDom?: 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);
+}
diff --git a/apps/client/src/widgets/ribbon/style.css b/apps/client/src/widgets/ribbon/style.css
deleted file mode 100644
index 71c865ebad..0000000000
--- a/apps/client/src/widgets/ribbon/style.css
+++ /dev/null
@@ -1,467 +0,0 @@
-.ribbon-container {
- margin-bottom: 5px;
- position: relative;
- z-index: 998;
-}
-
-/* When content header is floating, ribbon sticks below it */
-.scrolling-container:has(.content-header-widget.floating) .ribbon-container {
- position: sticky;
- top: var(--content-header-height, 100px);
-}
-
-.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-button-container {
- display: flex;
- border-bottom: 1px solid var(--main-border-color);
- margin-inline-end: 5px;
- align-items: center;
- height: 36px;
- gap: 10px;
-}
-
-.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;
-}
-
-/* #region Basic Properties */
-
-.basic-properties-widget {
- padding: 0px 12px 6px 12px;
- display: flex;
- align-items: baseline;
- flex-wrap: wrap;
-}
-
-.basic-properties-widget > * {
- margin-top: 9px;
- margin-bottom: 2px;
- margin-inline-end: 30px;
-}
-
-.note-type-container,
-.editability-select-container,
-.note-language-container {
- display: flex;
- align-items: center;
-}
-
-.note-type-dropdown {
- max-height: 500px;
- overflow-y: auto;
- overflow-x: hidden;
-}
-
-.editability-dropdown {
- width: 300px;
-}
-
-/* #endregion */
-
-/* #region Formatting Toolbar */
-
-.classic-toolbar-widget {
- --ck-color-toolbar-background: transparent;
- --ck-color-button-default-background: transparent;
- --ck-color-button-default-disabled-background: transparent;
- min-height: 39px;
-}
-
-.classic-toolbar-widget .ck.ck-toolbar {
- border: none;
-}
-
-.classic-toolbar-widget .ck.ck-button.ck-disabled {
- opacity: 0.3;
-}
-
-body.experimental-feature-new-layout .classic-toolbar-widget {
- transition: opacity 250ms ease-in;
-
- &.disabled {
- opacity: 0.3;
- pointer-events: none;
- }
-}
-
-/* #endregion */
-
-/* #region Script Tab */
-.script-runner-widget {
- padding: 12px;
- color: var(--muted-text-color);
-}
-
-.execute-description {
- margin-bottom: 10px;
-}
-/* #endregion */
-
-/* #region Note info */
-.note-info-widget {
- padding: 12px;
- display: flex;
- flex-wrap: wrap;
- align-items: baseline;
-}
-
-.note-info-item {
- display: flex;
- align-items: baseline;
- padding-inline-end: 15px;
- padding-block: 5px;
-}
-
-.note-info-item > span:first-child {
- padding-inline-end: 5px;
-}
-
-.note-info-mime {
- max-width: 13em;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-
-.note-info-id {
- font-variant: none;
- font-family: var(--monospace-font-family);
- font-size: 0.8em;
- vertical-align: middle !important;
-}
-
-/* #endregion */
-
-/* #region Similar Notes */
-.similar-notes-wrapper {
- max-height: 200px;
- overflow: auto;
- padding: 12px;
-}
-
-.similar-notes-wrapper a {
- display: inline-block;
- border: 1px dotted var(--main-border-color);
- border-radius: 20px;
- background-color: var(--accented-background-color);
- padding: 0 10px 0 10px;
- margin: 0 3px 0 3px;
- max-width: 10em;
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
-}
-/* #endregion */
-
-/* #region File Properties */
-.file-table {
- width: 100%;
- margin-top: 10px;
-}
-
-.file-table th, .file-table td {
- padding: 5px;
- overflow-wrap: anywhere;
-}
-
-.file-buttons {
- padding: 10px;
- display: flex;
- justify-content: space-evenly;
-}
-/* #endregion */
-
-/* #region Note paths */
-.note-paths-widget {
- padding: 12px;
- max-height: 300px;
- overflow-y: auto;
-}
-
-.note-path-list {
- margin-top: 10px;
-}
-
-.note-path-list .path-current a {
- font-weight: bold;
-}
-
-.note-path-list .path-archived a {
- color: var(--muted-text-color) !important;
-}
-
-.note-path-list .path-search a {
- font-style: italic;
-}
-/* #endregion */
-
-/* #region Note map */
-.note-map-ribbon-widget {
- position: relative;
-}
-
-.note-map-ribbon-widget .note-map-container {
- height: 100%;
-}
-
-.note-map-ribbon-widget .open-full-button, .note-map-ribbon-widget .collapse-button {
- position: absolute;
- inset-inline-end: 5px;
- bottom: 5px;
-}
-
-.style-resolver {
- color: var(--muted-text-color);
- display: none;
-}
-/* #endregion */
-
-/* #region Attribute editor */
-.attribute-list-editor {
- border: 0 !important;
- outline: 0 !important;
- box-shadow: none !important;
- padding: 0 100px 0 5px !important;
- margin: 0 !important;
- max-height: 100px;
- overflow: auto;
- transition: opacity .1s linear;
-}
-
-body[dir=rtl] .attribute-list-editor {
- padding: 0 5px 0 100px !important;
- text-align: right !important;
-}
-
-.attribute-list-editor.ck-content .mention {
- color: var(--muted-text-color) !important;
- background: transparent !important;
-}
-
-.attribute-editor-buttons {
- display: flex;
- position: absolute;
- top: 0;
- inset-inline-end: 0;
- bottom: 0;
- align-items: center;
- gap: 10px;
-}
-
-.attribute-errors {
- color: red;
- padding: 5px 100px 0px 5px; /* large right padding to avoid buttons */
-}
-/* #endregion */
-
-/* #region Owned Attributes */
-.attribute-list {
- margin-inline-start: 7px;
- margin-inline-end: 7px;
- margin-top: 5px;
- margin-bottom: 2px;
- position: relative;
-}
-
-.attribute-list-editor p {
- margin: 0 !important;
-}
-
-.attribute-list .attr-detail,
-.inherited-attributes-widget .attr-detail {
- contain: none;
-}
-
-/* #endregion */
-
-/* #region Inherited attributes */
-.inherited-attributes-widget {
- position: relative;
-}
-
-.inherited-attributes-container {
- color: var(--muted-text-color);
- max-height: 200px;
- overflow: auto;
- padding: 14px 12px 13px 12px;
-
- a.reference-link {
- text-decoration: underline;
- }
-}
-/* #endregion */
-
-/* #region Book properties */
-.book-properties-widget {
- padding: 12px 12px 6px 12px;
- display: flex;
- flex-wrap: wrap;
- gap: 15px;
- overflow: visible;
- align-items: center;
-}
-
-.book-properties-widget > * {
- flex-shrink: 0;
-}
-
-.book-properties-widget > .type-number > label {
- display: flex;
- align-items: baseline;
-}
-
-.book-properties-widget input[type="checkbox"] {
- margin-inline-end: 5px;
-}
-
-.book-properties-widget label {
- display: flex;
- justify-content: center;
- align-items: center;
- text-overflow: clip;
- white-space: nowrap;
-}
-/* #endregion */
-
-/* #region Note actions */
-.note-actions {
- width: 35px;
- height: 35px;
- display: flex;
- align-items: center;
-}
-
-.note-actions .dropdown-menu {
- min-width: 15em;
-}
-
-.note-actions .dropdown-item[disabled], .note-actions .dropdown-item[disabled]:hover {
- color: var(--muted-text-color) !important;
- background-color: transparent !important;
- pointer-events: none; /* makes it unclickable */
-}
-/* #endregion */
-
-/* #region Experimental layout */
-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;
- }
- }
-
- .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;
- }
- }
-
- .note-actions-custom {
- display: flex;
- align-items: center;
- height: 36px;
- gap: var(--button-gap);
-
- &> button:last-of-type {
- margin-right: 0.5em;
- }
- }
- }
-}
-/* #endregion */