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
client: fix some issues
Adorian Doranc569934de25f
diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.tsindex 8b5165479e..57cf5fb531 100644--- a/apps/client/src/widgets/collections/board/board_drag.ts+++ b/apps/client/src/widgets/collections/board/board_drag.ts@@ -240,14 +240,14 @@ export function useBoardDrag(const column = columnAt(measurement.columns, x);const area = column && measurement.areas.get(column.value);- // Standing at one end of the column places the card there whatever the column is- // scrolled to, which saves carrying it the length of a long one. Read from the pointer- // rather than from the card's top edge, as the scrolling is: the ends lie outside the- // column, and a card held anywhere but its very top could not reach below the button.+ // A pointer past either end places the card at that end whatever the column is+ // scrolled to, which saves dragging it the length of a long column. Read from the+ // pointer rather than the card's top edge, as auto-scrolling is: both ends lie outside+ // the column, and a card held below its top edge cannot reach past the button.const end = column && area ? columnEndAt(column, held.lastY) : undefined;const edges: ScrollTarget[] = [ { element: container, axis: "x" } ];- // The column is left where it stands while one of its ends is being asked for: the- // place is fixed, and a column walking to its top or bottom under it says otherwise.+ // No vertical auto-scroll while an end is the target: the index is already decided,+ // and scrolling would suggest the card is being placed where it passes.if (area && !end) {edges.push({ element: area, axis: "y" });}@@ -287,12 +287,12 @@ export function useBoardDrag(};/**- * Puts the overlay on the copy being carried, naming the end of the column the card would- * go to, and takes it off again for a card placed among the cards.+ * Shows the overlay on the carried copy, naming the end of the column the card would go to,+ * and hides it again for a position among the cards.*- * The label moves towards whatever of the copy the board shows, so a card taller than the- * board still shows it. Both the copy and the board were measured when the card was picked- * up, so this reads nothing from the page.+ * Shifts the label towards the part of the copy still inside the board, so that a card+ * taller than the board keeps it visible. `grab` and `viewport` were both measured when the+ * card was picked up, so this reads no layout.*/const markEnd = (held: Gesture, end: ColumnEnd | undefined) => {const hint = held.hint;diff --git a/apps/client/src/widgets/collections/board/columns.spec.ts b/apps/client/src/widgets/collections/board/columns.spec.tsindex eb26bb02c0..e35699c6fa 100644--- a/apps/client/src/widgets/collections/board/columns.spec.ts+++ b/apps/client/src/widgets/collections/board/columns.spec.ts@@ -8,6 +8,7 @@ import { buildNote } from "../../../test/easy-froca";import {BOARD_TEMPLATE_ID,canStoreColumnsInDefinition,+ columnWidthClass,getStatusDefinition,parseColumnWidth,resolveBoardColumns@@ -220,3 +221,18 @@ describe("parseColumnWidth", () => {expect(parseColumnWidth(undefined)).toBe("narrow");});});++describe("columnWidthClass", () => {+ it("names a class only for a width the board names itself", () => {+ expect(columnWidthClass("narrow")).toBe("board-narrow-columns");+ expect(columnWidthClass("medium")).toBe("board-medium-columns");+ expect(columnWidthClass("wide")).toBe("board-wide-columns");++ // Nothing to wear, so `--board-column-width` keeps the value it inherits. A theme setting+ // that variable is what this leaves room for.+ expect(columnWidthClass("enormous")).toBeUndefined();+ expect(columnWidthClass("")).toBeUndefined();+ expect(columnWidthClass(null)).toBeUndefined();+ expect(columnWidthClass(undefined)).toBeUndefined();+ });+});diff --git a/apps/client/src/widgets/collections/board/columns.ts b/apps/client/src/widgets/collections/board/columns.tsindex 1c1d65935b..2dd338fac6 100644--- a/apps/client/src/widgets/collections/board/columns.ts+++ b/apps/client/src/widgets/collections/board/columns.ts@@ -51,6 +51,18 @@ export function parseColumnWidth(value: string | null | undefined) {return COLUMN_WIDTHS.find(width => width === value) ?? DEFAULT_COLUMN_WIDTH;}+/**+ * The class a board wears for the width it names, or nothing where it names none.+ *+ * A board that names no width wears no class, so `--board-column-width` keeps whatever value it+ * inherits: the default in this stylesheet, or a theme's own if one sets it.+ */+export function columnWidthClass(value: string | null | undefined) {+ const width = COLUMN_WIDTHS.find(candidate => candidate === value);++ return width ? `board-${width}-columns` : undefined;+}+export interface BoardStatusDefinition {/** The definition attribute, wherever it is owned. */attribute: FAttribute;diff --git a/apps/client/src/widgets/collections/board/drag_geometry.ts b/apps/client/src/widgets/collections/board/drag_geometry.tsindex a882bb04b8..ffdc44eb1c 100644--- a/apps/client/src/widgets/collections/board/drag_geometry.ts+++ b/apps/client/src/widgets/collections/board/drag_geometry.ts@@ -36,15 +36,14 @@ export interface ColumnBox {*/origin: number;/**- * Where the heading begins and where the button that adds a card ends, down the page. A card- * carried past either one is placed at that end of the column. The heading and the button are- * left out of both: a card held over one walks the column along instead, which is how a place- * in the middle is reached. These hold for the length of a drag for the same reason- * {@link top} does.+ * Where the heading begins and where the button that adds a card ends, down the page. A pointer+ * past either one places the card at that end of the column. Neither the heading nor the button+ * counts as past: over them the column auto-scrolls instead, which is how a position in the+ * middle is reached. These hold for the length of a drag for the same reason {@link top} does.*/headStart: number;footEnd: number;- /** Whether the column orders its own cards, so nothing can be placed at an end of it. */+ /** Whether the column sorts its own cards, in which case the drop position is not chosen. */sorted: boolean;/*** The cards as drawn, in order, the dragged one included. Counting it keeps the index in the@@ -57,27 +56,27 @@ export interface ColumnBox {export type ColumnEnd = "first" | "last";/**- * How far past the heading or the button the pointer goes before that end is asked for, in pixels.+ * How far past the heading or the button the pointer must go for that end to count, in pixels.*- * The band between the two is where a card held over the column walks it along, and a pointer that- * has only just left it is on its way somewhere rather than asking for an end.+ * Between the two the column auto-scrolls, and a pointer that has only just left that band is+ * usually crossing it rather than aiming at an end.*/const END_OFFSET = 30;/**- * The end of a column a point stands past: above its heading, or below the button that adds a card,+ * The end of a column a point lies past: above the heading, or below the button that adds a card,* by {@link END_OFFSET} in either case.*- * A card placed there goes to that end of the column however far the column is scrolled, which- * saves dragging it the length of a long one. A column that orders its own cards answers with- * nothing: it places what it is given, so neither end is the reader's to choose.+ * A card dropped there goes to that end whatever the column is scrolled to, which saves dragging it+ * the length of a long column. Returns `undefined` for a sorted column, where the drop position is+ * not chosen.*- * @param y the pointer, down the page. Unlike a place among the cards, which is read from the- * carried card's top edge, both ends stand outside the column and only the pointer reaches them.+ * @param y the pointer, down the page. A position among the cards is read from the carried card's+ * top edge instead; both ends lie outside the column, which only the pointer reaches.*/export function columnEndAt(column: ColumnBox, y: number): ColumnEnd | undefined {- // A column with nothing between its two ends has no middle for a card to be placed in, so- // every point would read as one end or the other.+ // With no space between the two ends there is no middle, and every point would match one of+ // them.if (column.sorted || column.footEnd <= column.headStart) {return undefined;}diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex a3aca3538c..a4cf187813 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -38,7 +38,7 @@--board-drag-ring-width: 3px;/* The ring a picked-out card carries. */--board-selected-ring-color: var(--link-color);- /* The overlay a carried card wears while it would go to one end of a column. */+ /* The overlay on a carried card while it would drop at one end of a column. */--board-drop-hint-background: #1f2933;--board-drop-hint-color: #ffffff;/* Dims the board while a card is being named. Kept light: it draws the eye to the field rather@@ -127,8 +127,9 @@ body.mobile .board-view-container.board-dragging {cursor: grabbing !important;}-/* Set from `#boardCardWidth`. The columns and everything measured against them read the width off- this one variable, so only the board itself names which of the three is in use. */+/* Set from `#boardCardWidth`, and only while the board carries it: without one of these classes+ `--board-column-width` keeps the value it inherits, which a theme can set. The columns and+ everything measured against them read the width off that one variable. */.board-view.board-narrow-columns {--board-column-width: var(--board-column-width-narrow);}@@ -596,8 +597,7 @@ body.mobile .board-view-container .board-add-column {box-shadow: var(--board-drag-shadow);}-/* Covers the card being carried with what dropping it there does, which is why it is opaque: what- the card itself says is beside the point while it reads. */+/* Opaque rather than tinted: while it is up, the message replaces the card's own content. */.board-view-container .board-drag-preview .board-drop-hint {display: none;position: absolute;diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex 757e9b99a1..a5e0f0a72a 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -4379,11 +4379,14 @@ describe("how wide the board draws its columns", () => {* The width itself is CSS, which happy-dom does not resolve. What the board answers for is the* class it carries, off which the stylesheet picks one of the three widths.*/- it("carries the width its label names, and the default where it names none", async () => {- expect((await draw(undefined)).className).toContain("board-narrow-columns");+ it("carries the width its label names, and no class where it names none", async () => {expect((await draw("wide")).className).toContain("board-wide-columns");- // A width nobody offers is drawn at the default rather than given a class of its own.- expect((await draw("enormous")).className).toContain("board-narrow-columns");+ expect((await draw("narrow")).className).toContain("board-narrow-columns");++ // Without a class the width is whatever is inherited, which is the stylesheet's own+ // default or a theme's if one sets it.+ expect((await draw(undefined)).className).not.toMatch(/board-\w+-columns/);+ expect((await draw("enormous")).className).not.toMatch(/board-\w+-columns/);});async function draw(width: string | undefined) {diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 973019d2a0..2941ad830b 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -31,8 +31,8 @@ import CollectionProperties from "../../note_bars/CollectionProperties";import FormTextArea from "../../react/FormTextArea";import FormTextBox from "../../react/FormTextBox";import {- useContextualShortcutHints, useNoteContext, useNoteLabelBoolean, useNoteLabelWithDefault,- useNoteTypeOptions, useSetContextData, useTrackedElement, useTriliumEvent+ useContextualShortcutHints, useNoteContext, useNoteLabel, useNoteLabelBoolean,+ useNoteLabelWithDefault, useNoteTypeOptions, useSetContextData, useTrackedElement, useTriliumEvent} from "../../react/hooks";import Icon from "../../react/Icon";import NoteAutocomplete from "../../react/NoteAutocomplete";@@ -54,8 +54,8 @@ import { BoardDropStateContext, DropStateStore } from "./drop_state";import BoardApi from "./api";import { adoptLegacyColumns, readColumns } from "./column_storage";import {- COLUMN_WIDTH_LABEL, DEFAULT_COLUMN_ICON, DEFAULT_COLUMN_WIDTH, DEFAULT_GROUP_BY,- getStatusDefinition, INBOX_COLUMN, parseColumnWidth+ COLUMN_WIDTH_LABEL, columnWidthClass, DEFAULT_COLUMN_ICON, DEFAULT_GROUP_BY,+ getStatusDefinition, INBOX_COLUMN} from "./columns";import Column, { EXPAND_MS, placeCard, settleCards } from "./column";import { currentCardTemplate, DEFAULT_CARD_TEMPLATES } from "./card_templates";@@ -354,8 +354,9 @@ export default function BoardView({let viewConfig = adoptedConfig ?? storedConfig;const [ includeArchived ] = useNoteLabelBoolean(parentNote, "includeArchived");const [ inboxEnabled ] = useNoteLabelBoolean(parentNote, "enableInboxColumn");- const [ storedColumnWidth ] =- useNoteLabelWithDefault(parentNote, COLUMN_WIDTH_LABEL, DEFAULT_COLUMN_WIDTH);+ // Read undefaulted: a board naming no width wears no class, so `--board-column-width` keeps+ // whatever it inherits.+ const [ storedColumnWidth ] = useNoteLabel(parentNote, COLUMN_WIDTH_LABEL);/** Every card the board holds, which an active filter narrows before the cards are drawn. */const [ allByColumn, setAllByColumn ] = useState<ColumnMap>();const [ columns, setColumns ] = useState<string[]>();@@ -1216,7 +1217,7 @@ export default function BoardView({: undefined;return (- <div className={clsx("board-view", `board-${parseColumnWidth(storedColumnWidth)}-columns`, {+ <div className={clsx("board-view", columnWidthClass(storedColumnWidth), {frozen: isFrozen,"editing-open": branchIdToEdit !== undefined || insertingColumns.size > 0})}>diff --git a/apps/client/src/widgets/collections/board/properties.tsx b/apps/client/src/widgets/collections/board/properties.tsxindex da95f94ed3..6b28ad74aa 100644--- a/apps/client/src/widgets/collections/board/properties.tsx+++ b/apps/client/src/widgets/collections/board/properties.tsx@@ -103,7 +103,8 @@ function General({ api, note }: { api: BoardApi, note: FNote }) {/></OptionCardSection>- {/* A phone draws the columns at a width of its own, so there is nothing to pick. */}+ {/* `body.mobile` in index.css fixes the column width against the viewport, which is+ what the three widths here would otherwise set. */}{!isMobile() && (<OptionCardSectionname="board-column-width"diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsxindex bab2cc28c2..3bddb9266a 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx@@ -273,7 +273,9 @@ function useItems(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent):},{el: <BoardColumns />,- enabled: (boardColumns?.columns.length ?? 0) > 0,+ // Gated on being a board rather than on having columns, so that a board with none of+ // them shows the card's own empty state.+ enabled: boardColumns !== undefined,tab: "outline"},{diff --git a/packages/commons/src/lib/icon_font_metrics.spec.ts b/packages/commons/src/lib/icon_font_metrics.spec.tsindex 49cb6e7bc0..a1d52070a3 100644--- a/packages/commons/src/lib/icon_font_metrics.spec.ts+++ b/packages/commons/src/lib/icon_font_metrics.spec.ts@@ -17,6 +17,9 @@ describe("measureIconFont", () => {// Material Design Icons: 512 units to the em, 192 above the baseline.expect(measureIconFont(512, pack(192))).toEqual({ ascent: 0.875, descent: 0.125 });++ // A pack of an odd number of glyphs, where the middle one is the median outright.+ expect(measureIconFont(1024, pack(448, 21))).toEqual({ ascent: 0.9375, descent: 0.0625 });});it("takes the middle of the pack, not the icons drawn off centre on purpose", () => {