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: allow quick drop gesture for collapsed cards too
Adorian Doranda088772f434
diff --git a/apps/client/src/widgets/collections/board/board_drag.spec.tsx b/apps/client/src/widgets/collections/board/board_drag.spec.tsxindex 1b3e4a6d7a..4cf0af9d78 100644--- a/apps/client/src/widgets/collections/board/board_drag.spec.tsx+++ b/apps/client/src/widgets/collections/board/board_drag.spec.tsx@@ -867,6 +867,34 @@ describe("useBoardDrag, carrying a card", () => {expect(label).toBeLessThan(600);});+ it("offers both ends of a collapsed column, which draws none of its cards", () => {+ setup();+ // Collapsed before the board opened, so its cards were never drawn: the strip is its+ // heading alone, and how many it holds is read off the column itself.+ const strip = board.querySelectorAll<HTMLElement>(".board-column")[1];+ strip.classList.add("collapsed");+ strip.dataset.count = "7";+ strip.querySelector(".board-column-content")?.remove();+ strip.querySelector(".board-new-item")?.remove();+ place(strip, 200, 0, 40, 400);+ place(strip.querySelector("h3") as HTMLElement, 200, 0, 40, 400);++ press(card("n1"), 10, 10);+ move(210, 440);+ act(() => { vi.advanceTimersByTime(20); });+ expect(calls.move.at(-1)?.position).toEqual({ column: "Doing", index: 7 });++ move(210, -40);+ act(() => { vi.advanceTimersByTime(20); });+ expect(calls.move.at(-1)?.position).toEqual({ column: "Doing", index: 0 });++ // Over the strip itself it goes to the front, as it did before either end was offered.+ move(210, 200);+ act(() => { vi.advanceTimersByTime(20); });+ expect(calls.move.at(-1)?.position).toEqual({ column: "Doing", index: 0 });+ release(210, 200);+ });+/** 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);diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.tsindex 05368bdb33..36a2507323 100644--- a/apps/client/src/widgets/collections/board/board_drag.ts+++ b/apps/client/src/widgets/collections/board/board_drag.ts@@ -249,7 +249,7 @@ export function useBoardDrag(// 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 end = column ? columnEndAt(column, held.lastY) : undefined;const edges: ScrollTarget[] = [ { element: container, axis: "x" } ];// 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.@@ -260,15 +260,15 @@ export function useBoardDrag(markEnd(held, end, column);- // 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.+ // 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. Either of its ends can still+ // be asked for, which is what saves opening it to place a card there.const position = column? {column: column.value,- index: area- ? endIndex(end, column)- ?? placeAt(area, toAreaY(area, topY), held.card, column)- : 0+ index: endIndex(end, column) ?? (area+ ? placeAt(area, toAreaY(area, topY), held.card, column)+ : 0)}: null;// Standing on the column itself, which for a collapsed one is its heading alone: the@@ -705,7 +705,7 @@ function endIndex(end: ColumnEnd | undefined, column: ColumnBox) {return undefined;}- return end === "first" ? 0 : column.cards.length;+ return end === "first" ? 0 : column.count;}/** Asks an element for its menu the way a right click does, at the place the tap landed. */diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex 013e27a25c..2755e6eebc 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -729,6 +729,7 @@ export default function Column({className={clsx("board-column-content", scrollFade.className)}style={scrollFade.style}onWheel={handleScroll}+ data-count={noteIds.length}data-window-from={isWindowed ? windowFrom : undefined}data-window-count={isWindowed ? noteIds.length : undefined}>diff --git a/apps/client/src/widgets/collections/board/drag_geometry.spec.ts b/apps/client/src/widgets/collections/board/drag_geometry.spec.tsindex 67259bce69..8adb61f8e2 100644--- a/apps/client/src/widgets/collections/board/drag_geometry.spec.ts+++ b/apps/client/src/widgets/collections/board/drag_geometry.spec.ts@@ -20,7 +20,8 @@ function columns(cards: Record<string, CardBox[]> = {}): ColumnBox[] {headStart: 0,footEnd: 400,sorted: false,- cards: cards[value] ?? []+ cards: cards[value] ?? [],+ count: (cards[value] ?? []).length}));}@@ -87,7 +88,7 @@ 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,- headStart: 90, footEnd: 90, sorted: false, cards: []+ headStart: 90, footEnd: 90, sorted: false, cards: [], count: 0};expect(columnCovers(strip, 18, 0)).toBe(true);diff --git a/apps/client/src/widgets/collections/board/drag_geometry.ts b/apps/client/src/widgets/collections/board/drag_geometry.tsindex 66d5ab471d..f4d0e6f082 100644--- a/apps/client/src/widgets/collections/board/drag_geometry.ts+++ b/apps/client/src/widgets/collections/board/drag_geometry.ts@@ -52,6 +52,11 @@ export interface ColumnBox {* same terms as the list the board holds, which is what a move is expressed in.*/cards: CardBox[];+ /**+ * How many cards the column holds, the dragged one included. Read off the column rather than+ * counted here: a collapsed one draws none of them, and a windowed one only a slice.+ */+ count: number;}/** Which end of a column a card would be placed at. */diff --git a/apps/client/src/widgets/collections/board/drag_measure.ts b/apps/client/src/widgets/collections/board/drag_measure.tsindex a9e0961ccf..47b0e3ab7e 100644--- a/apps/client/src/widgets/collections/board/drag_measure.ts+++ b/apps/client/src/widgets/collections/board/drag_measure.ts@@ -53,6 +53,9 @@ export function measureBoard(container: HTMLElement, withCards = true): BoardMeaconst heading = element.querySelector<HTMLElement>(":scope > h3");const adder = element.querySelector<HTMLElement>(":scope > .board-new-item");+ const cards = withCards ? measureCards(area) : [];+ const stated = Number(element.dataset.count);+columns.push({value,left: rect.left - origin,@@ -66,7 +69,8 @@ export function measureBoard(container: HTMLElement, withCards = true): BoardMea? element.style.getPropertyValue("--board-column-custom-hue"): undefined,origin: withCards ? contentOrigin(area) : 0,- cards: withCards ? measureCards(area) : []+ cards,+ count: Number.isFinite(stated) ? stated : cards.length});}