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(note_map): put the map's controls on overlay control groups
Elian Doraned2f97631efe
diff --git a/apps/client/src/stylesheets/theme-next/pages.css b/apps/client/src/stylesheets/theme-next/pages.cssindex 41ea3e8d9f..be0ea5c2c1 100644--- a/apps/client/src/stylesheets/theme-next/pages.css+++ b/apps/client/src/stylesheets/theme-next/pages.css@@ -80,19 +80,6 @@--color: var(--main-text-color);}-/*- * NOTE MAP- */--.note-detail-note-map .fixnodes-type-switcher .tn-tool-button,-.note-map-widget .fixnodes-type-switcher .tn-tool-button {- padding: unset;-}-- .note-detail-note-map .fixnodes-type-switcher .tn-tool-button.toggled {- color: var(--tab-close-button-hover-background);-}-/** EMPTY NOTE PAGE*/diff --git a/apps/client/src/widgets/note_map/MapTypeSwitcher.tsx b/apps/client/src/widgets/note_map/MapTypeSwitcher.tsxindex 4c4f7eddeb..bcc89fafee 100644--- a/apps/client/src/widgets/note_map/MapTypeSwitcher.tsx+++ b/apps/client/src/widgets/note_map/MapTypeSwitcher.tsx@@ -1,57 +1,50 @@-import clsx from "clsx";-import { t } from "../../services/i18n";import ActionButton from "../react/ActionButton";+import { OverlayControlButton } from "../react/OverlayControlGroup";import { MapType } from "./utils";interface MapTypeSwitcherProps {mapType: MapType;setMapType: (mapType: MapType) => void;- /**- * Raised buttons, for the map's own floating overlay where they stand over the graph. The pane's- * header wants them flat, as the tab strip above it is.- */- frame?: boolean;- className?: string;}/*** The choice between the two maps a note can be drawn as, drawn the way Trilium draws a choice* between several things: a button group, a recessed track with the one on show raised out of it —- * the same the right pane's tab strip is built from.+ * the same the right pane's tab strip is built from. The map's own overlay offers the same choice+ * with {@link MapTypeOverlayButtons}.** Kept in a module of its own so that the pane can offer the choice in a card's header without* pulling in the map (and force-graph with it) to do so.*/-export default function MapTypeSwitcher({ mapType, setMapType, frame, className }: MapTypeSwitcherProps) {+export default function MapTypeSwitcher({ mapType, setMapType }: MapTypeSwitcherProps) {return (- <div class={clsx("btn-group map-type-switcher", className)} role="group">- <MapTypeButton- type="link" icon="bx bx-network-chart" text={t("note-map.button-link-map")}- currentMapType={mapType} setMapType={setMapType} frame={frame}- />- <MapTypeButton- type="tree" icon="bx bx-sitemap" text={t("note-map.button-tree-map")}- currentMapType={mapType} setMapType={setMapType} frame={frame}- />+ <div class="btn-group map-type-switcher" role="group">+ {MAP_TYPES.map(({ type, icon, text }) => (+ <ActionButton+ key={type}+ icon={`bx ${icon}`} text={t(text)}+ active={mapType === type}+ onClick={() => setMapType(type)}+ />+ ))}</div>);}-function MapTypeButton({ icon, text, type, currentMapType, setMapType, frame }: {- icon: string;- text: string;- type: MapType;- currentMapType: MapType;- setMapType: (mapType: MapType) => void;- frame?: boolean;-}) {- return (- <ActionButton- icon={icon} text={text}- active={currentMapType === type}+/** The same choice as {@link MapTypeSwitcher}, as buttons of an `OverlayControlGroup` over the map. */+export function MapTypeOverlayButtons({ mapType, setMapType }: MapTypeSwitcherProps) {+ return MAP_TYPES.map(({ type, icon, text }) => (+ <OverlayControlButton+ key={type}+ icon={icon} title={t(text)}+ active={mapType === type}onClick={() => setMapType(type)}- frame={frame}/>- );+ ));}++const MAP_TYPES: { type: MapType; icon: string; text: string }[] = [+ { type: "link", icon: "bx-network-chart", text: "note-map.button-link-map" },+ { type: "tree", icon: "bx-sitemap", text: "note-map.button-tree-map" }+];diff --git a/apps/client/src/widgets/note_map/NoteMap.css b/apps/client/src/widgets/note_map/NoteMap.cssindex 2c9a28e7c2..06a53d0f0f 100644--- a/apps/client/src/widgets/note_map/NoteMap.css+++ b/apps/client/src/widgets/note_map/NoteMap.css@@ -3,59 +3,51 @@overflow: hidden;}-/* Style Ui Element to Drag Nodes */-.fixnodes-type-switcher {- display: flex;- align-items: center;- z-index: 10; /* should be below dropdown (note actions) */- border-radius: .2rem;-}+.note-map-widget {+ .tn-overlay-control-group {+ z-index: 10;+ }-/* Start of styling the slider */-.fixnodes-type-switcher input[type="range"] {+ .note-map-link-distance {+ padding-inline: 10px;+ }- /* removing default appearance */- -webkit-appearance: none;- appearance: none;- margin-inline-start: 15px;- width: 150px;-}+ .note-map-link-distance input[type="range"] {+ -webkit-appearance: none;+ appearance: none;+ width: 150px;+ }-/* Changing slider tracker */-.fixnodes-type-switcher input[type="range"]::-webkit-slider-runnable-track {- height: 4px;- background-color: var(--main-border-color);- border-radius: 4px;-}+ .note-map-link-distance input[type="range"]::-webkit-slider-runnable-track {+ height: 4px;+ background-color: var(--main-border-color);+ border-radius: 4px;+ }-/* Changing Slider Thumb */-.fixnodes-type-switcher input[type="range"]::-webkit-slider-thumb {- /* removing default appearance */- -webkit-appearance: none;- appearance: none;- /* creating a custom design */- height: 15px;- width: 15px;- margin-top:-5px;- background-color: var(--accented-background-color);- border: 1px solid var(--main-text-color);- border-radius: 50%;-}+ .note-map-link-distance input[type="range"]::-webkit-slider-thumb {+ -webkit-appearance: none;+ appearance: none;+ height: 15px;+ width: 15px;+ margin-top: -5px;+ background-color: var(--accented-background-color);+ border: 1px solid var(--main-text-color);+ border-radius: 50%;+ }-.fixnodes-type-switcher input[type="range"]::-moz-range-track {- background-color: var(--main-border-color);- border-radius: 4px;-}+ .note-map-link-distance input[type="range"]::-moz-range-track {+ background-color: var(--main-border-color);+ border-radius: 4px;+ }-.fixnodes-type-switcher input[type="range"]::-moz-range-thumb {- background-color: var(--accented-background-color);- border-color: var(--main-text-color);- height: 10px;- width: 10px;+ .note-map-link-distance input[type="range"]::-moz-range-thumb {+ background-color: var(--accented-background-color);+ border-color: var(--main-text-color);+ height: 10px;+ width: 10px;+ }}-/* End of styling the slider */-/** The tooltip standing over the note or relation being hovered, dressed as the app's own tooltips* are. The graph brings its own (float-tooltip), styled from a stylesheet it injects itself, whichdiff --git a/apps/client/src/widgets/note_map/NoteMap.tsx b/apps/client/src/widgets/note_map/NoteMap.tsxindex 120b255021..904f8a1a2c 100644--- a/apps/client/src/widgets/note_map/NoteMap.tsx+++ b/apps/client/src/widgets/note_map/NoteMap.tsx@@ -10,13 +10,13 @@ import link_context_menu from "../../menus/link_context_menu";import hoisted_note from "../../services/hoisted_note";import { resolveIconGlyphs, warmIconFonts } from "../../services/icon_glyphs";import { t } from "../../services/i18n";-import ActionButton from "../react/ActionButton";import Button from "../react/Button";import { useColorScheme, useElementSize, useNoteLabel, useTriliumOption } from "../react/hooks";import NoItems from "../react/NoItems";+import OverlayControlGroup, { OverlayControlButton } from "../react/OverlayControlGroup";import Slider from "../react/Slider";import { loadNotesAndRelations, NoteMapLinkObject, NoteMapNodeObject, NotesAndRelationsData } from "./data";-import MapTypeSwitcher from "./MapTypeSwitcher";+import { MapTypeOverlayButtons } from "./MapTypeSwitcher";import { CssData, setupRendering } from "./rendering";import { isRootedAtCurrentNote, MapType, NOTE_MAP_TYPE_OPTION, NoteMapWidgetMode, rgb2hex, toMapType, usesReaderPreference } from "./utils";@@ -203,35 +203,31 @@ export default function NoteMap({ note, widgetMode, parentRef, defaultRootNoteIdreturn (<div className="note-map-widget">- {/* The sidebar offers the choice in its card's header instead, where the pane keeps the- controls of a widget — see sidebar/NoteMap.tsx. */}+ {/* The sidebar offers the map type in its card's header instead, where the pane keeps the+ controls of a widget (see sidebar/NoteMap.tsx), and neither pinning nor link distance:+ its map is rebuilt for every note it is read for, so both would be gone by the next. */}{widgetMode !== "sidebar" && (- <MapTypeSwitcher- mapType={mapType} setMapType={setMapType}- className="btn-group-sm content-floating-buttons top-left" frame- />- )}-- {/* Not in the sidebar, where neither has anything to hold on to: a map that small is not- one to arrange by hand, and it is rebuilt from scratch on every note it is read for,- which is what a connections panel is for — so a pinned node and a chosen link distance- are both gone by the next note. */}- {widgetMode !== "sidebar" && (- <div class="btn-group-sm fixnodes-type-switcher content-floating-buttons bottom-left" role="group">- <ActionButton- icon="bx bx-lock-alt"- text={t("note_map.fix-nodes")}- className={fixNodes ? "active" : ""}- onClick={() => setFixNodes(!fixNodes)}- frame- />+ <>+ <OverlayControlGroup className="note-map-type-controls" placement="top-start" overCanvas>+ <MapTypeOverlayButtons mapType={mapType} setMapType={setMapType} />+ </OverlayControlGroup>- <Slider- min={1} max={100}- value={linkDistance} onChange={setLinkDistance}- title={t("note_map.link-distance")}- />- </div>+ <OverlayControlGroup className="note-map-layout-controls" placement="bottom-start" overCanvas>+ <OverlayControlButton+ icon="bx-lock-alt"+ title={t("note_map.fix-nodes")}+ active={fixNodes}+ onClick={() => setFixNodes(!fixNodes)}+ />+ <div className="note-map-link-distance">+ <Slider+ min={1} max={100}+ value={linkDistance} onChange={setLinkDistance}+ title={t("note_map.link-distance")}+ />+ </div>+ </OverlayControlGroup>+ </>)}{/* What the map is drawn in, asked of the theme — see getCssData. */}diff --git a/apps/client/src/widgets/react/OverlayControlGroup.css b/apps/client/src/widgets/react/OverlayControlGroup.cssindex 4883376906..77157335b8 100644--- a/apps/client/src/widgets/react/OverlayControlGroup.css+++ b/apps/client/src/widgets/react/OverlayControlGroup.css@@ -104,6 +104,25 @@pointer-events: none;}}++ > :where(:not(button)) {+ display: flex;+ align-items: center;+ height: var(--_overlay-height);+ backdrop-filter: var(--overlay-button-backdrop-filter, none);+ background-color: var(--_overlay-surface);+ color: var(--_overlay-ink);++ &:first-child {+ border-start-start-radius: var(--_overlay-radius);+ border-end-start-radius: var(--_overlay-radius);+ }++ &:last-child {+ border-start-end-radius: var(--_overlay-radius);+ border-end-end-radius: var(--_overlay-radius);+ }+ }}/* A rail down one side of the content instead of a bar across it (see `vertical` ondiff --git a/packages/share-theme/src/base.css b/packages/share-theme/src/base.cssindex 8616ca91a2..7e90f75387 100644--- a/packages/share-theme/src/base.css+++ b/packages/share-theme/src/base.css@@ -56,6 +56,8 @@ html.theme-light {--quick-search-button-active-color: #383838;/* The right pane colors of `theme-next-light.css`. */--main-border-color: #dbdbdb;+ --tooltip-background-color: rgba(0, 0, 0, 0.818);+ --tooltip-foreground-color: #ffffffeb;--muted-text-color: #666;--card-background-color: #0000000d;--card-background-hover-color: #0000001c;@@ -121,6 +123,8 @@ html.theme-dark {--quick-search-button-active-color: #000000;/* The right pane colors of `theme-next-dark.css`. */--main-border-color: #454545;+ --tooltip-background-color: rgba(67, 67, 67, 0.86);+ --tooltip-foreground-color: #ffffffeb;--muted-text-color: #bbb;--card-background-color: #ffffff12;--card-background-hover-color: #ffffff20;@@ -147,9 +151,10 @@ html.theme-dark {color-scheme: dark;}-/* The page background under the name the content styles shared with the app read it by. */+/* The page's colors under the names the styles shared with the app read them by. */:root {--main-background-color: var(--background-primary);+ --main-text-color: var(--text-primary);/* The frosting of `theme-next/shell.css` behind the translucent menus. */--dropdown-backdrop-filter: blur(20px) saturate(6);}