Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): let a panel over a canvas stand on the surface a bar does

Elian Doran434cf87b81c3
diff --git a/apps/client/src/widgets/react/OverlayPanel.css b/apps/client/src/widgets/react/OverlayPanel.css
new file mode 100644
index 0000000000..d7f9e79cb9
--- /dev/null
+++ b/apps/client/src/widgets/react/OverlayPanel.css
@@ -0,0 +1,130 @@
+/*
+ * The surface a panel standing over a canvas is drawn on, and the geometry of what heads it.
+ *
+ * Where the panel stands, how wide it is and how tall it may grow are the caller's — those are what
+ * differ between one canvas and the next (see NodePanel.css, DetailPane.css). What is settled here
+ * is everything the two share: the sheet itself, the header row, and the bodies under it.
+ */
+.tn-overlay-panel {
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+ box-sizing: border-box;
+ background: var(--menu-background-color);
+ color: var(--menu-text-color);
+ border: 1px solid var(--dropdown-border-color);
+ /* A panel that stands away from the edges is a card; one flush against them is not, and squares
+ its corners off (see DetailPane.css). */
+ border-radius: var(--overlay-panel-radius, 8px);
+ box-shadow: 0 2px 8px #0003;
+ /* The frosting the bars beside it wear, which is a menu's (see OverlayToolbar.css). */
+ backdrop-filter: var(--dropdown-backdrop-filter, blur(10px));
+}
+
+/*
+ * The head of the panel: a strip of tabs or a heading of one line, and beside either of them the
+ * button that sends the panel away. Only the placing of that button is this row's business — what
+ * heads the panel keeps its own padding and the line under it (see below), the two headers standing
+ * at different heights.
+ */
+.tn-overlay-panel .tn-overlay-panel-header {
+ position: relative;
+ /* The head of a full panel keeps its height; what gives way is the body under it, which scrolls. */
+ flex-shrink: 0;
+}
+
+/*
+ * At the end of the row and centred on it, whichever header it is standing at. What it looks like
+ * is the theme's — an "x" icon button is dressed as the one closing a tab is, here as everywhere.
+ *
+ * Laid over the row rather than standing in it: a strip of tabs is centred on the panel, and a
+ * button taking its own place beside it would push it off centre. There is room to spare next to
+ * two tabs and next to one word, so the two never meet.
+ */
+.tn-overlay-panel .tn-overlay-panel-close {
+ position: absolute;
+ inset-inline-end: 6px;
+ top: 50%;
+ transform: translateY(-50%);
+}
+
+/*
+ * The strip is the right pane's, at the size it stands there (see TabStrip.css); what is left here
+ * is the row it heads. It parts from the body under it by a line the width of the panel, so that it
+ * reads as the panel's header rather than as one more choice among the fields — which is what a
+ * button group means everywhere else inside a panel.
+ */
+.tn-overlay-panel .tn-overlay-panel-header > .tab-strip {
+ padding: 8px;
+ border-bottom: 1px solid var(--main-border-color);
+}
+
+/*
+ * A heading of one line, dressed as the strip is: the same line under it, and the same room —
+ * reckoned from a body's own padding, so that the heading stands over what is under it rather than
+ * beside it.
+ */
+.tn-overlay-panel .tn-overlay-panel-title {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ padding: 10px 15px;
+ /* Clear of the button laid over the end of the row, for a heading longer than English gives it. */
+ padding-inline-end: 36px;
+ border-bottom: 1px solid var(--main-border-color);
+ font-weight: 550;
+}
+
+/* A heading is as long as whatever it names, and cutting it short is kinder than letting it push
+ the panel wider than the canvas can spare. */
+.tn-overlay-panel .tn-overlay-panel-title-text {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+/*
+ * Every body is laid into the same cell, so the panel stands as tall as the tallest of them and
+ * keeps that height whichever is on show. Were each to size the panel in turn, switching tabs would
+ * collapse the panel to the height of one field — pulling the strip up the screen, out from under
+ * the pointer that had just pressed a tab.
+ */
+.tn-overlay-panel .tn-overlay-panel-bodies {
+ display: grid;
+ /* Without it a grid refuses to shrink past its content, and the panel scrolls as a whole. */
+ min-height: 0;
+}
+
+/*
+ * Each body holds the padding rather than the panel, so that one filled edge to edge by what it
+ * holds can give that padding up on its own (see the memo in NodePanel.css).
+ */
+.tn-overlay-panel .tn-overlay-panel-body {
+ grid-area: 1 / 1;
+ padding: var(--overlay-panel-body-padding, 15px);
+ overflow: auto;
+ /* As above, for the body within the cell. */
+ min-height: 0;
+}
+
+/*
+ * The tab not on show keeps its place in the cell rather than leaving it, which is what holds the
+ * height of the panel still. `visibility` and not `display`, whose `none` would give the place up —
+ * it takes the tab out of reach of the pointer, the keyboard and a screen reader all the same.
+ */
+.tn-overlay-panel .tn-overlay-panel-body[aria-hidden="true"] {
+ visibility: hidden;
+}
+
+.tn-overlay-panel .tn-overlay-panel-section + .tn-overlay-panel-section {
+ margin-top: 16px;
+}
+
+.tn-overlay-panel .tn-overlay-panel-section-label {
+ margin-bottom: 8px;
+ font-size: .85em;
+ font-weight: 550;
+ text-transform: uppercase;
+ letter-spacing: .75pt;
+ opacity: .75;
+}
diff --git a/apps/client/src/widgets/react/OverlayPanel.tsx b/apps/client/src/widgets/react/OverlayPanel.tsx
new file mode 100644
index 0000000000..5b051f0840
--- /dev/null
+++ b/apps/client/src/widgets/react/OverlayPanel.tsx
@@ -0,0 +1,125 @@
+import "./OverlayPanel.css";
+
+import clsx from "clsx";
+import { ComponentChildren } from "preact";
+
+import ActionButton from "./ActionButton";
+import Icon from "./Icon";
+
+interface OverlayPanelProps {
+ /** Where the panel stands, how wide it is and whatever else is peculiar to it, styled by
+ * whoever puts it there. */
+ className?: string;
+ /**
+ * What heads the panel: a {@link TabStrip} where it is divided into tabs, or an
+ * {@link OverlayPanelTitle} where there is only the one thing to show.
+ */
+ header: ComponentChildren;
+ /** The way to send the panel away, offered at the end of the header row. Left out, the panel
+ * has no way of dismissing itself. */
+ close?: {
+ /** What the button is named — its tooltip, and what a screen reader reads. */
+ text: string;
+ onClick(): void;
+ };
+ /** One or more {@link OverlayPanelBody}, laid one over the other. */
+ children: ComponentChildren;
+}
+
+/**
+ * A panel standing over a canvas that is dragged and zoomed — a mind map, a geo map — holding what
+ * is to be done with whatever is selected on it.
+ *
+ * It brings the surface (see OverlayPanel.css), the header row and the button that sends it away,
+ * and keeps itself out of the canvas's reach; where it stands, how wide it is and what it holds are
+ * left to the caller, which is what differs between two of them. The same division
+ * {@link OverlayToolbar} makes for the bars those canvases carry.
+ */
+export default function OverlayPanel({ className, header, close, children }: OverlayPanelProps) {
+ return (
+ <div
+ className={clsx("tn-overlay-panel", className)}
+ /* Keep interactions inside the panel from reaching the canvas underneath. */
+ onMouseDown={(e) => e.stopPropagation()}
+ onKeyDown={(e) => e.stopPropagation()}
+ >
+ {/* What heads the panel, and the way to send it away — laid over the head of it rather
+ than beside what is there, so that a strip of tabs stays centred on the panel (see
+ the CSS). */}
+ <div className="tn-overlay-panel-header">
+ {header}
+
+ {close && (
+ <ActionButton
+ className="tn-overlay-panel-close"
+ icon="bx bx-x"
+ text={close.text}
+ onClick={close.onClick}
+ />
+ )}
+ </div>
+
+ {/* The bodies are stacked one over the other rather than shown one at a time, so that
+ the panel keeps the height of the tallest of them whichever is on show. */}
+ <div className="tn-overlay-panel-bodies">
+ {children}
+ </div>
+ </div>
+ );
+}
+
+/**
+ * A heading of one line, for a panel that is not divided into tabs — dressed as a strip of tabs is,
+ * so that the two head a panel at the same height.
+ */
+export function OverlayPanelTitle({ icon, text }: { icon: string; text: string }) {
+ return (
+ <div className="tn-overlay-panel-title">
+ <Icon icon={icon} />
+ <span className="tn-overlay-panel-title-text">{text}</span>
+ </div>
+ );
+}
+
+/**
+ * One body of a panel: the whole of it where there is only one, or one tab of it where there are
+ * several.
+ */
+export function OverlayPanelBody({ className, isTab, hidden, title, children }: {
+ /** What is peculiar to this body — the padding it keeps, most often (see the CSS). */
+ className?: string;
+ /**
+ * The body is one tab among several, which is what makes it a tab panel and what has it say
+ * whether it is the one on show. A panel holding a single body is not a tab and says neither.
+ */
+ isTab?: boolean;
+ /** Another tab is the one on show. */
+ hidden?: boolean;
+ title?: string;
+ children: ComponentChildren;
+}) {
+ return (
+ <div
+ role={isTab ? "tabpanel" : undefined}
+ className={clsx("tn-overlay-panel-body", className)}
+ aria-hidden={isTab ? hidden : undefined}
+ title={title}
+ >
+ {children}
+ </div>
+ );
+}
+
+/** A field of a panel: what it stands for, and the control that sets it. */
+export function OverlayPanelSection({ label, title, children }: {
+ label: string;
+ title?: string;
+ children: ComponentChildren;
+}) {
+ return (
+ <div className="tn-overlay-panel-section" title={title}>
+ <div className="tn-overlay-panel-section-label">{label}</div>
+ {children}
+ </div>
+ );
+}
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
index dec1df0a69..f49ad6bf28 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
@@ -9,23 +9,13 @@
*/
--node-panel-foot: calc(var(--mind-map-inset-bottom) + var(--mind-map-toolbar-height) + var(--mind-map-inset));
+ /* Everything the panel is made of — the sheet, the header row, the tabs under it — is the shared
+ panel's (see OverlayPanel.css). What is left here is where this one stands over the map. */
position: absolute;
top: var(--node-panel-top);
inset-inline-end: var(--mind-map-inset);
width: 240px;
max-height: calc(100% - var(--node-panel-top) - var(--node-panel-foot));
- /* The tab strip is the panel's header and stays put; only the tab under it scrolls. */
- display: flex;
- flex-direction: column;
- overflow: hidden;
- box-sizing: border-box;
- background: var(--menu-background-color);
- color: var(--menu-text-color);
- border: 1px solid var(--dropdown-border-color);
- border-radius: 8px;
- box-shadow: 0 2px 8px #0003;
- /* The frosting the bars beside it wear, which is a menu's (see OverlayToolbar.css). */
- backdrop-filter: var(--dropdown-backdrop-filter, blur(10px));
}
/* On a screen of its own the panel starts where the map does, there being no note buttons over it
@@ -41,118 +31,26 @@ body.experimental-feature-new-layout .mind-map-node-panel {
--node-panel-top: var(--mind-map-inset-top);
}
-/*
- * The head of the panel: a strip of tabs or a heading of one line, and beside either of them the
- * button that sends the panel away. Only the placing of that button is this row's business — what
- * heads the panel keeps its own padding and the line under it (see below), the two headers standing
- * at different heights.
- */
-.mind-map-node-panel .mind-map-node-panel-header {
- position: relative;
- /* The head of a full panel keeps its height; what gives way is the tab under it, which scrolls. */
- flex-shrink: 0;
-}
-
-/*
- * At the end of the row and centred on it, whichever header it is standing at. What it looks like
- * is the theme's — an "x" icon button is dressed as the one closing a tab is, here as everywhere.
- *
- * Laid over the row rather than standing in it: the tabs are centred on the panel, and a button
- * taking its own place beside them would push them off it. There is room to spare next to two tabs
- * and next to one word, so the two never meet.
- */
-.mind-map-node-panel .mind-map-node-panel-close {
- position: absolute;
- inset-inline-end: 6px;
- top: 50%;
- transform: translateY(-50%);
-}
-
-/*
- * The strip is the right pane's, at the size it stands there (see TabStrip.css); what is left here
- * is the row it heads. It parts from the tab under it by a line the width of the panel, so that it
- * reads as the panel's header rather than as one more choice among the fields — which is what a
- * button group means everywhere else in here (the font sizes, the picture's shapes).
- */
-.mind-map-node-panel .mind-map-node-panel-tabs {
- padding: 8px;
- border-bottom: 1px solid var(--main-border-color);
-}
-
-/*
- * Where the memo is all there is (a map that can only be read), the strip gives way to a heading,
- * dressed as the strip was: the same line under it, and the same room — reckoned from the memo's own
- * padding, so that the heading stands over the writing rather than beside it.
- */
-.mind-map-node-panel .mind-map-node-panel-title {
- display: flex;
- align-items: center;
- gap: 6px;
- padding: 10px 15px;
- /* Clear of the button laid over the end of the row, for a heading longer than English gives it. */
- padding-inline-end: 36px;
- border-bottom: 1px solid var(--main-border-color);
- font-weight: 550;
-}
-
-/*
- * Every tab is laid into the same cell, so the panel stands as tall as the tallest of them and
- * keeps that height whichever is on show. Were each tab to size the panel in turn, switching to the
- * memo would collapse the panel to the height of one field — pulling the strip up the screen, out
- * from under the pointer that had just pressed a tab.
- */
-.mind-map-node-panel .mind-map-node-panel-bodies {
- display: grid;
- /* Without it a grid refuses to shrink past its content, and the panel scrolls as a whole. */
- min-height: 0;
-}
-
-/* Each tab holds the padding, rather than the panel: the memo's is its own (see below). */
-.mind-map-node-panel .mind-map-node-panel-body {
- grid-area: 1 / 1;
- padding: 15px;
- overflow: auto;
- /* As above, for the tab within the cell. */
- min-height: 0;
-}
-
-/*
- * The tab not on show keeps its place in the cell rather than leaving it, which is what holds the
- * height of the panel still. `visibility` and not `display`, whose `none` would give the place up —
- * it takes the tab out of reach of the pointer, the keyboard and a screen reader all the same.
- */
-.mind-map-node-panel .mind-map-node-panel-body[aria-hidden="true"] {
- visibility: hidden;
-}
-
/*
* The memo is the whole of its tab, so it fills the height the panel took from the fields — and the
* width edge to edge, the tab keeping none of the padding for itself. What insets the writing is
* the memo's own padding (see NodeMemo.css), so that the two read as one surface rather than as a
* sheet laid on a tab.
+ *
+ * The padding is given up through the variable the shared body reads it from rather than by setting
+ * `padding` over it: the two rules carry the same weight, and which of the two stylesheets is loaded
+ * last is not this file's to say.
*/
.mind-map-node-panel .mind-map-node-panel-memo-body {
+ --overlay-panel-body-padding: 0;
+
display: flex;
- padding: 0;
.mind-map-node-memo {
flex: 1;
}
}
-.mind-map-node-panel .mind-map-node-panel-section + .mind-map-node-panel-section {
- margin-top: 16px;
-}
-
-.mind-map-node-panel .mind-map-node-panel-section-label {
- margin-bottom: 8px;
- font-size: .85em;
- font-weight: 550;
- text-transform: uppercase;
- letter-spacing: .75pt;
- opacity: .75;
-}
-
/* The icons of a node stand side by side, the button adding one more after them. */
.mind-map-node-panel .mind-map-node-icons {
display: flex;
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
index f77b1e0093..8341746897 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
@@ -87,7 +87,7 @@ const LINK = 6;
const TAGS = 7;
function section(container: HTMLElement, index: number) {
- const sections = container.querySelectorAll<HTMLElement>(".mind-map-node-panel-section");
+ const sections = container.querySelectorAll<HTMLElement>(".tn-overlay-panel-section");
return sections[index];
}
@@ -467,9 +467,9 @@ describe("the memo field of the panel", () => {
// through: with the fields gone there is nothing left to choose between.
expect(shownMemo(panel)).toBe("<p>About A</p>");
expect(panel.querySelectorAll('[role="tab"]')).toHaveLength(0);
- expect(panel.querySelector(".mind-map-node-panel-title")).toBeTruthy();
+ expect(panel.querySelector(".tn-overlay-panel-title")).toBeTruthy();
// None of the fields, every one of which edits — and what they stand for is on the node.
- expect(panel.querySelectorAll(".mind-map-node-panel-section")).toHaveLength(0);
+ expect(panel.querySelectorAll(".tn-overlay-panel-section")).toHaveLength(0);
});
it("stands aside where there is no one memo to read", async () => {
@@ -914,7 +914,7 @@ describe("NodePanel", () => {
const shown = () => !!panel.querySelector(".mind-map-node-panel");
/** Presses the button that sends the panel away, the way it is pressed on the map. */
const dismiss = async () => act(async () => {
- panel.querySelector<HTMLButtonElement>(".mind-map-node-panel-close")?.click();
+ panel.querySelector<HTMLButtonElement>(".tn-overlay-panel-close")?.click();
});
await dismiss();
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
index 269be958e7..14e9e9246f 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
@@ -2,7 +2,6 @@ import "./NodePanel.css";
import { parseMindMapNoteLink } from "@triliumnext/commons";
import type { MindElixirInstance, NodeObj, TagObj } from "mind-elixir";
-import { ComponentChildren } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
import appContext from "../../../components/app_context";
@@ -16,6 +15,7 @@ import { FormFileUploadActionButton } from "../../react/FormFileUpload";
import { useNote, useNoteIcon, useNoteTitle } from "../../react/hooks";
import Icon from "../../react/Icon";
import { IconPickerButton } from "../../react/IconPicker";
+import OverlayPanel, { OverlayPanelBody, OverlayPanelSection, OverlayPanelTitle } from "../../react/OverlayPanel";
import SegmentedChoice from "../../react/SegmentedChoice";
import TabStrip, { type TabStripTabDefinition } from "../../react/TabStrip";
import { fitNodeImage, getNodeImageShape, nearestNodeImageWidth, NODE_IMAGE_SHAPES, NODE_IMAGE_WIDTHS, type NodeImage as NodeImageData, type NodeImageShape, shapeNodeImage, uploadNodeImage } from "./images";
@@ -148,167 +148,142 @@ export default function NodePanel({ mind, noteId, nodes, readOnly }: NodePanelPr
}
return (
- <div
+ <OverlayPanel
className="mind-map-node-panel"
- /* Keep interactions inside the panel from reaching the map underneath. */
- onMouseDown={(e) => e.stopPropagation()}
- onKeyDown={(e) => e.stopPropagation()}
+ /* With the memo the only thing on show there is no choice to offer, so the strip gives
+ way to a plain heading — the panel still says what it is holding. */
+ header={readOnly ? (
+ <OverlayPanelTitle icon="bx bx-notepad" text={t("mind-map.memo")} />
+ ) : (
+ <TabStrip
+ // A selection whose memos differ carries one all the same, which is what the
+ // tab is saying: that there is something written to go and read.
+ tabs={buildTabs(memo !== null)}
+ activeTabId={activeTabId}
+ onSelect={setActiveTabId}
+ />
+ )}
+ close={{ text: t("mind-map.hide-panel"), onClick: () => setDismissed(true) }}
>
- {/* What heads the panel, and the way to send it away — laid over the head of it rather
- than beside what is there, so that the tabs stay centred on the panel (see the CSS). */}
- <div className="mind-map-node-panel-header">
- {/* With the memo the only thing on show there is no choice to offer, so the strip
- gives way to a plain heading — the panel still says what it is holding. */}
- {readOnly ? (
- <div className="mind-map-node-panel-title">
- <Icon icon="bx bx-notepad" />{t("mind-map.memo")}
- </div>
- ) : (
- <TabStrip
- className="mind-map-node-panel-tabs"
- // A selection whose memos differ carries one all the same, which is what the
- // tab is saying: that there is something written to go and read.
- tabs={buildTabs(memo !== null)}
- activeTabId={activeTabId}
- onSelect={setActiveTabId}
+ {!readOnly && <OverlayPanelBody isTab hidden={activeTabId !== "format"}>
+ <OverlayPanelSection label={t("mind-map.font-size")}>
+ <SegmentedChoice
+ options={buildFontSizeOptions()}
+ currentValue={fontSize !== MIXED ? fontSize ?? DEFAULT_FONT_SIZE : MIXED_FONT_SIZE}
+ onChange={(fontSize) => patchSelectedNodes({ style: { fontSize } })}
/>
- )}
+ </OverlayPanelSection>
+
+ <OverlayPanelSection label={t("mind-map.text-color")}>
+ <ColorPicker
+ presets={NODE_COLORS}
+ {...toPickerValue(textColor)}
+ // Mind Elixir only ever assigns the style properties it is given and never
+ // resets the ones it isn't, so clearing has to blank the property explicitly.
+ onChange={(color) => patchSelectedNodes({ style: { color: color ?? "" } })}
+ />
+ </OverlayPanelSection>
- <ActionButton
- className="mind-map-node-panel-close"
- icon="bx bx-x"
- text={t("mind-map.hide-panel")}
- onClick={() => setDismissed(true)}
- />
- </div>
+ <OverlayPanelSection label={t("mind-map.background-color")}>
+ <ColorPicker
+ presets={NODE_BACKGROUND_COLORS}
+ {...toPickerValue(backgroundColor)}
+ onChange={(color) => patchSelectedNodes({ style: { background: color ?? "" } })}
+ />
+ </OverlayPanelSection>
+
+ <OverlayPanelSection label={t("mind-map.branch-color")}>
+ <ColorPicker
+ presets={NODE_COLORS}
+ {...toPickerValue(branchColor)}
+ onChange={(color) => patchSelectedNodes({ branchColor: color ?? "" })}
+ />
+ </OverlayPanelSection>
- {/* The tabs are stacked one over the other rather than shown one at a time, so that
- the panel keeps the height of the tallest of them whichever is on show. */}
- <div className="mind-map-node-panel-bodies">
- {!readOnly && <div
- role="tabpanel"
- className="mind-map-node-panel-body"
- aria-hidden={activeTabId !== "format"}
+ <OverlayPanelSection
+ label={t("mind-map.icons")}
+ title={icons.readOnly ? t("mind-map.icons-differ") : undefined}
>
- <PanelSection label={t("mind-map.font-size")}>
- <SegmentedChoice
- options={buildFontSizeOptions()}
- currentValue={fontSize !== MIXED ? fontSize ?? DEFAULT_FONT_SIZE : MIXED_FONT_SIZE}
- onChange={(fontSize) => patchSelectedNodes({ style: { fontSize } })}
- />
- </PanelSection>
-
- <PanelSection label={t("mind-map.text-color")}>
- <ColorPicker
- presets={NODE_COLORS}
- {...toPickerValue(textColor)}
- // Mind Elixir only ever assigns the style properties it is given and never
- // resets the ones it isn't, so clearing has to blank the property explicitly.
- onChange={(color) => patchSelectedNodes({ style: { color: color ?? "" } })}
- />
- </PanelSection>
-
- <PanelSection label={t("mind-map.background-color")}>
- <ColorPicker
- presets={NODE_BACKGROUND_COLORS}
- {...toPickerValue(backgroundColor)}
- onChange={(color) => patchSelectedNodes({ style: { background: color ?? "" } })}
- />
- </PanelSection>
-
- <PanelSection label={t("mind-map.branch-color")}>
- <ColorPicker
- presets={NODE_COLORS}
- {...toPickerValue(branchColor)}
- onChange={(color) => patchSelectedNodes({ branchColor: color ?? "" })}
- />
- </PanelSection>
-
- <PanelSection
- label={t("mind-map.icons")}
- title={icons.readOnly ? t("mind-map.icons-differ") : undefined}
- >
- <NodeIcons
- icons={icons.values}
- readOnly={icons.readOnly}
- onChange={(icons) => patchSelectedNodes({ icons })}
- />
- </PanelSection>
-
- <PanelSection
- label={t("mind-map.image")}
- title={image === MIXED ? t("mind-map.images-differ") : undefined}
- >
- <NodeImage
- hasImage={!!image}
- indeterminate={image === MIXED}
- width={imageWidth !== MIXED && imageWidth ? Number(imageWidth) : null}
- shape={imageShape !== MIXED ? imageShape : null}
- onShape={(shape) => void shapeImages(shape)}
- // A node carries one picture, so what is taken in takes the place of what was
- // there, at the size it comes in at.
- onPick={(file) => void takeInImage(file)}
- // Derived per node: the nodes are set to the same width, but each keeps the
- // proportions of the picture it carries.
- onResize={(width) => patchSelectedNodes((node) => ({
- image: node.image && fitNodeImage(node.image, width)
- }))}
- onRemove={() => patchSelectedNodes({ image: undefined })}
- />
- </PanelSection>
-
- <PanelSection
- label={t("mind-map.node-link")}
- title={link === MIXED ? t("mind-map.links-differ") : undefined}
- >
- <NodeLink
- currentValue={link !== MIXED ? link : null}
- indeterminate={link === MIXED}
- // A node carries one link, so what is picked takes the place of what was there.
- // Clearing blanks the property, Mind Elixir only ever assigning the ones it is
- // given (see the colors above).
- onChange={(link) => patchGivenNodes({ hyperLink: link ?? "" })}
- />
- </PanelSection>
-
- <PanelSection
- label={t("mind-map.tags")}
- title={tags.readOnly ? t("mind-map.tags-differ") : undefined}
- >
- <ValuesInput
- labelType="text"
- values={tags.texts}
- placeholder={t("mind-map.tags-placeholder")}
- addButtonText={t("mind-map.add-tag")}
- removeButtonText={t("mind-map.remove-tag")}
- disabled={tags.readOnly}
- // Derived per node: the nodes agree on the texts, but each may dress its own
- // tags differently, and that is kept by reading from the node being written to.
- onCommit={(texts) => patchSelectedNodes((node) => ({ tags: applyTagTexts(node.tags, texts) }))}
- />
- </PanelSection>
- </div>}
-
- {/* The memo goes without a label of its own: what stands above it says what it is —
- the tab it fills, or the heading where there are no tabs — and the editor is the
- whole of the tab rather than a field within it. */}
- {(readOnly || openedTabs.current.has("memo")) && (
- <div
- role={!readOnly ? "tabpanel" : undefined}
- className="mind-map-node-panel-body mind-map-node-panel-memo-body"
- aria-hidden={!readOnly ? activeTabId !== "memo" : undefined}
- title={memo === MIXED ? t("mind-map.memos-differ") : undefined}
- >
- <NodeMemo
- selectionKey={selectionKey}
- memo={memo !== MIXED ? memo : null}
- readOnly={readOnly || memo === MIXED}
- onCommit={(memo) => patchGivenNodes({ memo } as Partial<NodeObj>)}
- />
- </div>
- )}
- </div>
- </div>
+ <NodeIcons
+ icons={icons.values}
+ readOnly={icons.readOnly}
+ onChange={(icons) => patchSelectedNodes({ icons })}
+ />
+ </OverlayPanelSection>
+
+ <OverlayPanelSection
+ label={t("mind-map.image")}
+ title={image === MIXED ? t("mind-map.images-differ") : undefined}
+ >
+ <NodeImage
+ hasImage={!!image}
+ indeterminate={image === MIXED}
+ width={imageWidth !== MIXED && imageWidth ? Number(imageWidth) : null}
+ shape={imageShape !== MIXED ? imageShape : null}
+ onShape={(shape) => void shapeImages(shape)}
+ // A node carries one picture, so what is taken in takes the place of what was
+ // there, at the size it comes in at.
+ onPick={(file) => void takeInImage(file)}
+ // Derived per node: the nodes are set to the same width, but each keeps the
+ // proportions of the picture it carries.
+ onResize={(width) => patchSelectedNodes((node) => ({
+ image: node.image && fitNodeImage(node.image, width)
+ }))}
+ onRemove={() => patchSelectedNodes({ image: undefined })}
+ />
+ </OverlayPanelSection>
+
+ <OverlayPanelSection
+ label={t("mind-map.node-link")}
+ title={link === MIXED ? t("mind-map.links-differ") : undefined}
+ >
+ <NodeLink
+ currentValue={link !== MIXED ? link : null}
+ indeterminate={link === MIXED}
+ // A node carries one link, so what is picked takes the place of what was there.
+ // Clearing blanks the property, Mind Elixir only ever assigning the ones it is
+ // given (see the colors above).
+ onChange={(link) => patchGivenNodes({ hyperLink: link ?? "" })}
+ />
+ </OverlayPanelSection>
+
+ <OverlayPanelSection
+ label={t("mind-map.tags")}
+ title={tags.readOnly ? t("mind-map.tags-differ") : undefined}
+ >
+ <ValuesInput
+ labelType="text"
+ values={tags.texts}
+ placeholder={t("mind-map.tags-placeholder")}
+ addButtonText={t("mind-map.add-tag")}
+ removeButtonText={t("mind-map.remove-tag")}
+ disabled={tags.readOnly}
+ // Derived per node: the nodes agree on the texts, but each may dress its own
+ // tags differently, and that is kept by reading from the node being written to.
+ onCommit={(texts) => patchSelectedNodes((node) => ({ tags: applyTagTexts(node.tags, texts) }))}
+ />
+ </OverlayPanelSection>
+ </OverlayPanelBody>}
+
+ {/* The memo goes without a label of its own: what stands above it says what it is —
+ the tab it fills, or the heading where there are no tabs — and the editor is the
+ whole of the tab rather than a field within it. */}
+ {(readOnly || openedTabs.current.has("memo")) && (
+ <OverlayPanelBody
+ className="mind-map-node-panel-memo-body"
+ isTab={!readOnly}
+ hidden={activeTabId !== "memo"}
+ title={memo === MIXED ? t("mind-map.memos-differ") : undefined}
+ >
+ <NodeMemo
+ selectionKey={selectionKey}
+ memo={memo !== MIXED ? memo : null}
+ readOnly={readOnly || memo === MIXED}
+ onCommit={(memo) => patchGivenNodes({ memo } as Partial<NodeObj>)}
+ />
+ </OverlayPanelBody>
+ )}
+ </OverlayPanel>
);
}
@@ -671,15 +646,6 @@ function LinkedNoteFace({ notePath }: { notePath: string }) {
return <><Icon icon={icon} /><span className="mind-map-node-link-label">{title ?? note?.title ?? ""}</span></>;
}
-function PanelSection({ label, title, children }: { label: string, title?: string, children: ComponentChildren }) {
- return (
- <div className="mind-map-node-panel-section" title={title}>
- <div className="mind-map-node-panel-section-label">{label}</div>
- {children}
- </div>
- );
-}
-
/** Returned instead of a value when the selected nodes don't agree on one. */
export const MIXED = Symbol("mixed");