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/collections/board: add a quick gesture to drop a card at the top/bottom of a column
Adorian Doran3fba2c2088cf
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex c4e0709ab1..5797c81dd1 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3531,6 +3531,8 @@"sort-manually": "Manually","default-card-order": "Default card order","column-width": "Column width",+ "drop-as-first-item": "Drop as the first item",+ "drop-as-last-item": "Drop as the last item","column-width-narrow": "Narrow (default)","column-width-medium": "Medium","column-width-wide": "Wide",diff --git a/apps/client/src/widgets/collections/board/board_drag.spec.tsx b/apps/client/src/widgets/collections/board/board_drag.spec.tsxindex 9cfa974081..9a05ecc8c0 100644--- a/apps/client/src/widgets/collections/board/board_drag.spec.tsx+++ b/apps/client/src/widgets/collections/board/board_drag.spec.tsx@@ -7,6 +7,12 @@ import {type BoardDragCallbacks, type DraggedCard, type DropPosition, useBoardDrag} from "./board_drag";+// i18next is never initialised under test, so the overlay would be left saying nothing at all.+vi.mock("../../../services/i18n", () => ({+ t: (key: string) => key,+ translationsInitializedPromise: Promise.resolve()+}));+describe("useBoardDrag, carrying a card", () => {let container: HTMLElement | undefined;let board: HTMLElement;@@ -722,10 +728,146 @@ describe("useBoardDrag, carrying a card", () => {* Two 100px columns, 200 apart, each card 50 tall. The first holds two cards, the second one.* happy-dom lays nothing out, so every box is declared.*/- function setup({ disabled = false, carried }: {+ describe("carrying a card to one end of a column", () => {+ /** Ten cards in the first column, scrolled so that neither end of it is on screen. */+ const tall = {+ layout: [ Array.from({ length: 10 }, (_, index) => `c${index + 1}`), [ "n3" ] ],+ scrollTop: 120+ };++ /** Taken 25 below its own top edge, so the card and the pointer are never in one place. */+ function takeHold() {+ press(card("c3"), 50, 65);+ }++ /**+ * The column runs on above and below what it shows, so the places the two ends name are+ * nowhere near the ones the cards on screen give.+ */+ it("places the card at the head of the column, and at its foot", () => {+ setup(tall);++ takeHold();+ move(50, 225);+ act(() => { vi.advanceTimersByTime(20); });+ expect(calls.move.at(-1)?.position).toEqual({ column: "To Do", index: 5 });++ // Clear above the heading, which is the head of the column whatever it is scrolled to.+ move(50, -40);+ act(() => { vi.advanceTimersByTime(20); });+ expect(calls.move.at(-1)?.position).toEqual({ column: "To Do", index: 0 });++ // Clear below the button that adds a card, which is its foot.+ move(50, 440);+ act(() => { vi.advanceTimersByTime(20); });+ expect(calls.move.at(-1)?.position).toEqual({ column: "To Do", index: 10 });+ });++ /**+ * Both are where a card is held to walk the column along, which is how a reader reaches a+ * place in the middle of a long one.+ */+ it("leaves the heading and the button that adds a card out of both ends", () => {+ setup(tall);+ const showing = () => !!preview()?.classList.contains("showing-drop-hint");+ const area = board.querySelector<HTMLElement>(".board-column-content");++ takeHold();+ // On the heading, the card's own top edge standing above the column altogether.+ move(50, 20);+ act(() => { vi.advanceTimersByTime(100); });+ expect(showing()).toBe(false);+ // What the heading is for while a card is held over it: the column walks up under it,+ // and the card is placed against the cards that brings into view.+ expect(area?.scrollTop).toBeLessThan(120);++ // On the button at the foot, and in the band just past it.+ move(50, 360);+ act(() => { vi.advanceTimersByTime(20); });+ expect(showing()).toBe(false);+ expect(calls.move.at(-1)?.position).not.toEqual({ column: "To Do", index: 10 });++ move(50, 425);+ act(() => { vi.advanceTimersByTime(20); });+ expect(showing()).toBe(false);+ });++ it("says on the copy being carried what letting go would do", () => {+ setup(tall);+ const hint = () => preview()?.querySelector<HTMLElement>(".board-drop-hint");++ takeHold();+ move(50, -40);+ act(() => { vi.advanceTimersByTime(20); });+ expect(preview()?.classList.contains("showing-drop-hint")).toBe(true);+ expect(hint()?.textContent).toBe("board_view.drop-as-first-item");++ move(50, 440);+ act(() => { vi.advanceTimersByTime(20); });+ expect(hint()?.textContent).toBe("board_view.drop-as-last-item");++ // Back among the cards, where the card is placed against them and says nothing.+ move(50, 225);+ act(() => { vi.advanceTimersByTime(20); });+ expect(preview()?.classList.contains("showing-drop-hint")).toBe(false);+ });++ /**+ * A card taller than the board is cut off by it, and a label in the middle of the card is+ * cut off with it. The board runs 0 to 600 here and the window reaches further, so a label+ * placed against the window would land below what the reader can see.+ */+ it("keeps the label inside what the board shows of a tall card", () => {+ setup(tall);+ const shift = () => Number(preview()+ ?.querySelector<HTMLElement>(".board-drop-hint span")+ ?.style.transform.match(/-?[\d.]+/)?.[0]);++ takeHold();+ move(50, 440);+ act(() => { vi.advanceTimersByTime(20); });+ // Wholly inside the board, so the label stands in the middle of the card.+ expect(shift()).toBe(0);++ release(50, 440);+ place(card("c3"), 0, 40, 100, 2000);++ press(card("c3"), 50, 65);+ move(50, 440);+ act(() => { vi.advanceTimersByTime(20); });++ // Where the label lands: the middle of the card, moved by the shift, which the scale+ // the copy is drawn at takes a tenth off. The card was taken 25 below its own top.+ const middle = 440 - 25 + 2000 / 2;+ const label = middle + shift() * 0.9;+ expect(label).toBeGreaterThan(0);+ expect(label).toBeLessThan(600);+ });++ /** A sorted column places what it is given, so neither of its ends is on offer. */+ it("offers no end of a column that orders its own cards", () => {+ setup(tall);+ board.querySelectorAll<HTMLElement>(".board-column")[0].dataset.sorted = "true";++ takeHold();+ move(50, -40);+ act(() => { vi.advanceTimersByTime(20); });++ expect(preview()?.classList.contains("showing-drop-hint")).toBe(false);+ expect(calls.move.at(-1)?.position).toEqual({ column: "To Do", index: 0 });+ });+ });++ function setup({+ disabled = false, carried, layout = [ [ "n1", "n2" ], [ "n3" ] ], scrollTop = 0+ }: {disabled?: boolean,/** The cards a press answers with, for the tests about carrying a selection. */- carried?: string[]+ carried?: string[],+ /** What each column holds, for a test that needs more cards than a column can show. */+ layout?: string[][],+ /** How far each column is scrolled, its cards standing that much higher on screen. */+ scrollTop?: number} = {}) {const mountPoint = document.createElement("div");container = mountPoint;@@ -752,11 +894,11 @@ describe("useBoardDrag, carrying a card", () => {board.appendChild(Object.assign(document.createElement("div"), {className: "board-drag-layer"}));- place(board, 0, 0, 500, 400);+ place(board, 0, 0, 500, 600);// Writable: the board walks itself along while something is held at its edge.Object.defineProperty(board, "scrollLeft", { value: 0, configurable: true, writable: true });- for (const [ index, cards ] of [ [ "n1", "n2" ], [ "n3" ] ].entries()) {+ for (const [ index, cards ] of layout.entries()) {const column = document.createElement("div");column.className = "board-column";column.dataset.column = [ "To Do", "Doing" ][index];@@ -775,9 +917,9 @@ describe("useBoardDrag, carrying a card", () => {const area = document.createElement("div");area.className = "board-column-content";column.appendChild(area);- place(area, index * 200, 40, 100, 360);+ place(area, index * 200, 40, 100, 300);Object.defineProperty(area, "scrollTop", {- value: 0, configurable: true, writable: true+ value: scrollTop, configurable: true, writable: true});for (const [ position, noteId ] of cards.entries()) {@@ -788,8 +930,14 @@ describe("useBoardDrag, carrying a card", () => {className: "edit-icon"}));area.appendChild(note);- place(note, index * 200, 40 + position * 60, 100, 50);+ place(note, index * 200, 40 + position * 60 - scrollTop, 100, 50);}++ // The button that adds a card, which stands at the foot of every open column.+ const adder = document.createElement("div");+ adder.className = "board-new-item";+ column.appendChild(adder);+ place(adder, index * 200, 340, 100, 60);}// Attached from an effect, which Preact defers past the render.diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.tsindex c6a907c65b..8b5165479e 100644--- a/apps/client/src/widgets/collections/board/board_drag.ts+++ b/apps/client/src/widgets/collections/board/board_drag.ts@@ -1,9 +1,11 @@import { RefObject } from "preact";import { useCallback, useEffect, useRef, useState } from "preact/hooks";+import { t } from "../../../services/i18n";import { useTrackedElement } from "../../react/hooks";import {- type CardBox, cardInsertionIndex, columnAt, type ColumnBox, columnCovers, columnInsertionIndex+ type CardBox, cardInsertionIndex, columnAt, type ColumnBox, columnCovers, type ColumnEnd,+ columnEndAt, columnInsertionIndex} from "./drag_geometry";import {type BoardMeasurement, measureBoard, placeInModel, toAreaY, toBoardX@@ -199,6 +201,7 @@ export function useBoardDrag(});}held.preview = lifted.preview;+ held.hint = lifted.hint;held.grab = lifted.grab;container.classList.add("board-dragging");setDragging(true);@@ -237,12 +240,20 @@ 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.+ const end = column && area ? columnEndAt(column, held.lastY) : undefined;const edges: ScrollTarget[] = [ { element: container, axis: "x" } ];- if (area) {+ // 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.+ if (area && !end) {edges.push({ element: area, axis: "y" });}scroller.update(edges, held.lastX, held.lastY);+ markEnd(held, end);// A collapsed column draws no card area and holds no cards on screen, so a card carried// over it goes to the front of whatever it holds.@@ -250,7 +261,8 @@ export function useBoardDrag(? {column: column.value,index: area- ? placeAt(area, toAreaY(area, topY), held.card, column)+ ? endIndex(end, column)+ ?? placeAt(area, toAreaY(area, topY), held.card, column): 0}: null;@@ -274,6 +286,48 @@ export function useBoardDrag(report(held, position);};+ /**+ * 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.+ *+ * 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.+ */+ const markEnd = (held: Gesture, end: ColumnEnd | undefined) => {+ const hint = held.hint;+ const grab = held.grab;+ const view = held.measurement?.viewport;+ if (!hint || !grab || !view) return;++ const label = hint.firstElementChild;+ if (end !== held.end) {+ held.end = end;+ held.preview?.classList.toggle("showing-drop-hint", !!end);+ if (end && label instanceof HTMLElement) {+ label.textContent = t(end === "first"+ ? "board_view.drop-as-first-item"+ : "board_view.drop-as-last-item");+ // Read once, as the label is written: every move that follows works from+ // this rather than reading the page again.+ held.labelHeight = label.offsetHeight;+ }+ }++ if (!end || !(label instanceof HTMLElement)) return;++ const middle = held.lastY - grab.y + grab.height / 2;+ const drawn = grab.height * DRAG_SCALE / 2;+ const top = Math.max(middle - drawn, view.top);+ const bottom = Math.min(middle + drawn, view.bottom);+ // Outside the board altogether: there is no part of the copy to keep the label in.+ const shift = bottom > top ? ((top + bottom) / 2 - middle) / DRAG_SCALE : 0;+ // The label stands on the card, so it goes no further than the card's own edges.+ const room = Math.max(0, (grab.height - (held.labelHeight ?? 0)) / 2);+ label.style.transform =+ `translateY(${Math.max(-room, Math.min(room, shift))}px)`;+ };+/** Says where the card would land, and whether it has come to rest on that column. */const report = (held: Gesture, next?: DropPosition | null) => {if (held.kind !== "card") return;@@ -589,6 +643,20 @@ function placeIn(cards: CardBox[], y: number, card: DraggedCard, column: string)return index >= card.index ? index + 1 : index;}+/**+ * The place one end of a column names, or nothing where neither end is being asked for.+ *+ * The cards were counted with the carried one among them, which is the list a move is expressed+ * in, so the last place is that count rather than one less.+ */+function endIndex(end: ColumnEnd | undefined, column: ColumnBox) {+ if (!end) {+ return undefined;+ }++ return end === "first" ? 0 : column.cards.length;+}+/** Asks an element for its menu the way a right click does, at the place the tap landed. */function askForMenu(element: HTMLElement, clientX: number, clientY: number) {element.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, clientX, clientY }));@@ -691,6 +759,17 @@ function lift(held: Gesture, container: HTMLElement) {preview.querySelector(".edit-icon")?.remove();preview.querySelector(".board-new-item")?.remove();+ // The overlay saying the card would go to one end of a column, hidden until it would. Built+ // with the copy so a move only turns it on, and only for a card: a column is not placed this+ // way.+ let hint: HTMLElement | undefined;+ if (held.kind === "card") {+ hint = document.createElement("div");+ hint.className = "board-drop-hint";+ hint.appendChild(document.createElement("span"));+ preview.appendChild(hint);+ }+// The copy is carried in the drag layer rather than in the column it came from, where the rule// that tints a card no longer reaches it, so the column's hue is put on the copy itself.const hue = held.element.closest<HTMLElement>(".board-column.with-hue")@@ -717,6 +796,7 @@ function lift(held: Gesture, container: HTMLElement) {held.element.style.display = "none";return {preview,+ hint,size: { width: rect.width, height: rect.height },// Where inside it the reader took hold, so the middle can be found from the pointer.grab: {@@ -782,6 +862,12 @@ type Gesture = (CardSubject | ColumnSubject) & {active: boolean;/** The copy that follows the pointer, what it stands for staying where it is. */preview?: HTMLElement;+ /** The overlay on the copy saying the card would go to one end of a column. */+ hint?: HTMLElement;+ /** Which end that is, so the overlay is written only as it changes. */+ end?: ColumnEnd;+ /** What the label inside it measures, read when it is written rather than on every move. */+ labelHeight?: number;/** Where the press landed inside it, and how big it is, for finding its middle. */grab?: { x: number, y: number, width: number, height: number };measurement?: BoardMeasurement;diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex 399475fd6b..013e27a25c 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -596,6 +596,8 @@ export default function Column({return (<divdata-column={column}+ // Read by the drag, which offers neither end of a column that places its own cards.+ data-sorted={isSorted ? "true" : undefined}className={clsx("board-column", {"drag-over": isDropTarget && (isSorted || draggedCard?.fromColumn !== column),// The class the themes key a hue off, worn here as anywhere else that carries one.diff --git a/apps/client/src/widgets/collections/board/drag_geometry.spec.ts b/apps/client/src/widgets/collections/board/drag_geometry.spec.tsindex 534ef7a9f4..67259bce69 100644--- a/apps/client/src/widgets/collections/board/drag_geometry.spec.ts+++ b/apps/client/src/widgets/collections/board/drag_geometry.spec.ts@@ -1,11 +1,14 @@import { describe, expect, it } from "vitest";import {- type CardBox, cardInsertionIndex, columnAt, type ColumnBox, columnCovers,+ type CardBox, cardInsertionIndex, columnAt, type ColumnBox, columnCovers, columnEndAt,columnInsertionIndex, columnStandsAside, movesColumn} from "./drag_geometry";-/** Three 100px columns with a 20px gap, standing 400 tall from the top of the page. */+/**+ * Three 100px columns with a 20px gap, standing 400 tall from the top of the page. The heading+ * begins at the top of each and the button that adds a card ends at its foot.+ */function columns(cards: Record<string, CardBox[]> = {}): ColumnBox[] {return [ "To Do", "Doing", "Done" ].map((value, index) => ({value,@@ -14,6 +17,9 @@ function columns(cards: Record<string, CardBox[]> = {}): ColumnBox[] {top: 0,origin: 0,height: 400,+ headStart: 0,+ footEnd: 400,+ sorted: false,cards: cards[value] ?? []}));}@@ -80,7 +86,8 @@ describe("columnCovers", () => {*/it("tells the column from the empty space below a short one", () => {const strip: ColumnBox = {- value: "Parked", left: 0, width: 36, top: 0, height: 90, origin: 0, cards: []+ value: "Parked", left: 0, width: 36, top: 0, height: 90, origin: 0,+ headStart: 90, footEnd: 90, sorted: false, cards: []};expect(columnCovers(strip, 18, 0)).toBe(true);@@ -203,3 +210,45 @@ describe("columnStandsAside", () => {.toEqual([ 0, 0, 0, -266, -266, -266 ]);});});++describe("columnEndAt", () => {+ /**+ * The two ends stand 30px clear of the column, the heading and the add button being where a+ * card is held to walk the column along rather than to place it.+ */+ it("answers for what stands 30px above the heading and below the add button", () => {+ const [ column ] = columns();++ expect(columnEndAt(column, -31)).toBe("first");+ expect(columnEndAt(column, -200)).toBe("first");++ // The heading itself, the button at the foot, and the band past each of them.+ expect(columnEndAt(column, -30)).toBeUndefined();+ expect(columnEndAt(column, 0)).toBeUndefined();+ expect(columnEndAt(column, 200)).toBeUndefined();+ expect(columnEndAt(column, 400)).toBeUndefined();+ expect(columnEndAt(column, 429)).toBeUndefined();++ expect(columnEndAt(column, 430)).toBe("last");+ expect(columnEndAt(column, 900)).toBe("last");+ });++ /** A sorted column places what it is given, so neither of its ends is the reader's to pick. */+ it("offers neither end of a column that orders its own cards", () => {+ const [ column ] = columns();+ const sorted = { ...column, sorted: true };++ expect(columnEndAt(sorted, 0)).toBeUndefined();+ expect(columnEndAt(sorted, 900)).toBeUndefined();+ });++ /** A collapsed column is a heading and nothing else, and so is neither end of itself. */+ it("offers neither end of a column with no room between them", () => {+ const [ column ] = columns();+ const strip = { ...column, headStart: 40, footEnd: 40 };++ expect(columnEndAt(strip, 0)).toBeUndefined();+ expect(columnEndAt(strip, 40)).toBeUndefined();+ expect(columnEndAt(strip, 900)).toBeUndefined();+ });+});diff --git a/apps/client/src/widgets/collections/board/drag_geometry.ts b/apps/client/src/widgets/collections/board/drag_geometry.tsindex e892092c36..a882bb04b8 100644--- a/apps/client/src/widgets/collections/board/drag_geometry.ts+++ b/apps/client/src/widgets/collections/board/drag_geometry.ts@@ -35,6 +35,17 @@ export interface ColumnBox {* boundary falls into the slot below the one the gap is drawn at.*/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.+ */+ headStart: number;+ footEnd: number;+ /** Whether the column orders its own cards, so nothing can be placed at an end of it. */+ sorted: boolean;/*** The cards as drawn, in order, the dragged one included. Counting it keeps the index in the* same terms as the list the board holds, which is what a move is expressed in.@@ -42,6 +53,42 @@ export interface ColumnBox {cards: CardBox[];}+/** Which end of a column a card would be placed at. */+export type ColumnEnd = "first" | "last";++/**+ * How far past the heading or the button the pointer goes before that end is asked for, 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.+ */+const END_OFFSET = 30;++/**+ * The end of a column a point stands past: above its 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.+ *+ * @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.+ */+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.+ if (column.sorted || column.footEnd <= column.headStart) {+ return undefined;+ }++ if (y < column.headStart - END_OFFSET) {+ return "first";+ }++ return y >= column.footEnd + END_OFFSET ? "last" : undefined;+}+/*** The column a point falls in, or the nearest one where it falls between columns or past an end.*diff --git a/apps/client/src/widgets/collections/board/drag_measure.spec.ts b/apps/client/src/widgets/collections/board/drag_measure.spec.tsindex 7c4f861563..8952ef012c 100644--- a/apps/client/src/widgets/collections/board/drag_measure.spec.ts+++ b/apps/client/src/widgets/collections/board/drag_measure.spec.ts@@ -35,6 +35,12 @@ function buildBoard({ scrollLeft = 200, areaScrollTop = 20, cardCounts = [ 2, 1// On screen the columns have already been scrolled 200px to the left.place(column, { left: 50 + index * 120 - scrollLeft, top: 0, width: 100, height: 400 });+ // The column is padded, so neither its heading nor the button at its foot is flush with+ // it: the two ends are read from those rather than from the column's own box.+ const heading = document.createElement("h3");+ column.appendChild(heading);+ place(heading, { left: 0, top: 8, width: 100, height: 40 });+const area = document.createElement("div");area.className = "board-column-content";column.appendChild(area);@@ -57,6 +63,13 @@ function buildBoard({ scrollLeft = 200, areaScrollTop = 20, cardCounts = [ 2, 1}}+ for (const column of container.querySelectorAll<HTMLElement>(".board-column")) {+ const adder = document.createElement("div");+ adder.className = "board-new-item";+ column.appendChild(adder);+ place(adder, { left: 0, top: 352, width: 100, height: 40 });+ }+return container;}@@ -394,3 +407,39 @@ describe("measuring a windowed column", () => {expect(column.cards).toHaveLength(60);});});++describe("what a column offers a card carried past it", () => {+ it("reads the two ends from the heading and the button at the foot", () => {+ const [ first ] = measureBoard(buildBoard()).columns;++ // The column's own box runs 0 to 400; these are its heading and its button.+ expect(first.headStart).toBe(8);+ expect(first.footEnd).toBe(392);+ expect(first.sorted).toBe(false);+ });++ it("reads a column that orders its own cards off the column itself", () => {+ const board = buildBoard();+ board.querySelectorAll<HTMLElement>(".board-column")[1].dataset.sorted = "true";++ expect(measureBoard(board).columns.map((column) => column.sorted)).toEqual([ false, true ]);+ });+});++describe("what the reader sees of the board", () => {+ it("is the note list holding it, and the board itself where it stands outside one", () => {+ const board = buildBoard();++ expect(measureBoard(board).viewport).toEqual({ top: 0, bottom: 400 });++ // The note list is what scrolls and clips, so a board inside one is seen through it.+ const list = document.createElement("div");+ list.className = "note-list-widget-content";+ document.body.appendChild(list);+ place(list, { left: 0, top: 100, width: 600, height: 250 });+ list.appendChild(board);++ expect(measureBoard(board).viewport).toEqual({ top: 100, bottom: 350 });+ list.remove();+ });+});diff --git a/apps/client/src/widgets/collections/board/drag_measure.ts b/apps/client/src/widgets/collections/board/drag_measure.tsindex 65a53c2b10..ba4ac3fc3e 100644--- a/apps/client/src/widgets/collections/board/drag_measure.ts+++ b/apps/client/src/widgets/collections/board/drag_measure.ts@@ -7,6 +7,12 @@ export interface BoardMeasurement {columns: ColumnBox[];/** Each column's card area, which a point has to be read against to place a card in it. */areas: Map<string, HTMLElement>;+ /**+ * What the reader sees of the board, down the page: the box of the note list holding it, or+ * the board itself where it stands outside one. The copy being carried is clipped to this+ * rather than to the window, so it is what says how much of the copy can be seen.+ */+ viewport: { top: number, bottom: number };}/**@@ -20,7 +26,10 @@ export interface BoardMeasurement {* pass over the whole board that nothing goes on to look at.*/export function measureBoard(container: HTMLElement, withCards = true): BoardMeasurement {- const origin = container.getBoundingClientRect().left - container.scrollLeft;+ const box = container.getBoundingClientRect();+ const origin = box.left - container.scrollLeft;+ const clipped = (container.closest<HTMLElement>(".note-list-widget-content") ?? container)+ .getBoundingClientRect();const columns: ColumnBox[] = [];const areas = new Map<string, HTMLElement>();@@ -41,18 +50,24 @@ export function measureBoard(container: HTMLElement, withCards = true): BoardMeaareas.set(value, area);}+ const heading = element.querySelector<HTMLElement>(":scope > h3");+ const adder = element.querySelector<HTMLElement>(":scope > .board-new-item");+columns.push({value,left: rect.left - origin,width: rect.width,top: rect.top,height: rect.height,+ headStart: heading?.getBoundingClientRect().top ?? rect.top,+ footEnd: adder?.getBoundingClientRect().bottom ?? rect.bottom,+ sorted: element.dataset.sorted === "true",origin: withCards ? contentOrigin(area) : 0,cards: withCards ? measureCards(area) : []});}- return { columns, areas };+ return { columns, areas, viewport: { top: clipped.top, bottom: clipped.bottom } };}/**diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex 7267ba5b18..5a1da7c7c8 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -38,6 +38,9 @@--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. */+ --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 ratherthan hiding what is behind it. */--board-edit-backdrop: rgba(0, 0, 0, 0.15);@@ -579,6 +582,26 @@ 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. */+.board-view-container .board-drag-preview .board-drop-hint {+ display: none;+ position: absolute;+ inset: 0;+ align-items: center;+ justify-content: center;+ border-radius: inherit;+ padding: var(--card-padding);+ background-color: var(--board-drop-hint-background);+ text-align: center;+ font-weight: 600;+ color: var(--board-drop-hint-color);+}++.board-view-container .board-drag-preview.showing-drop-hint .board-drop-hint {+ display: flex;+}+/* What a carried selection is drawn as: one card-shaped block holding how many are on the move. */.board-view-container .board-note.board-drag-count {display: flex;