Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix some issues

Adorian Doranc728c5a54aee
diff --git a/apps/client/src/widgets/collections/board/drag.spec.tsx b/apps/client/src/widgets/collections/board/drag.spec.tsx
index 56d4095a13..587e962eaa 100644
--- a/apps/client/src/widgets/collections/board/drag.spec.tsx
+++ b/apps/client/src/widgets/collections/board/drag.spec.tsx
@@ -309,6 +309,45 @@ describe("Board drag and drop", () => {
expect(gap?.style.height).toBe("100px");
});
+ /**
+ * The card leaves the flow as it is lifted, and the gap opens in its place by pushing the cards
+ * below it down again. Under their transition that reads as the column closing up and then
+ * sliding back open, where nothing has actually moved.
+ */
+ it("opens the gap without a transition as a card is lifted", async () => {
+ const { columns, board } = await renderBoard();
+ await act(async () => { await settle(); });
+ const second = columns[0].querySelectorAll<HTMLElement>(".board-note")[1];
+
+ // Watched rather than read afterwards: the frame that puts the transitions back has run by
+ // the time the gesture returns.
+ expect(await classesWhile(board, async () => {
+ await pointer(second, "pointerdown", 50, 150);
+ await pointer(columns[0], "pointermove", 50, 60);
+ })).toContain("board-still");
+ });
+
+ /**
+ * Cards below the gap carry a `translateY` that the drop replaces with the layout the reorder
+ * gives them. Cleared under their transition they slide up from a place they never stood in,
+ * which reads as the column settling after the card has landed.
+ */
+ it("takes the transforms off without a transition once a card has landed", async () => {
+ const { columns, board } = await renderBoard();
+ await act(async () => { await settle(); });
+ const second = columns[0].querySelectorAll<HTMLElement>(".board-note")[1];
+
+ await pointer(second, "pointerdown", 50, 150);
+ await pointer(columns[0], "pointermove", 50, 60);
+ await act(async () => { await frames(); });
+ // The lift suppresses transitions too, so the release is watched on its own: left running,
+ // this would pass on what the lift did.
+ expect(board.classList.contains("board-still")).toBe(false);
+
+ expect(await classesWhile(board, () => pointer(columns[0], "pointerup", 50, 60)))
+ .toContain("board-still");
+ });
+
function place(
element: HTMLElement | null,
box: { left: number, top: number, width: number, height: number }
@@ -392,7 +431,9 @@ describe("Board drag and drop", () => {
const cards = note.getChildBranches()
.map(branch => ({ noteId: branch.noteId, branchId: branch.branchId }));
- return { note, columns, cards };
+ if (!board) throw new Error("expected the board container");
+
+ return { note, columns, cards, board };
}
/** Dispatches one of the drag events, with the clipboard the board reads its payload from. */
@@ -431,6 +472,12 @@ describe("Board drag and drop", () => {
function settle() {
return new Promise((resolve) => setTimeout(resolve));
}
+
+ /** Waits out the two frames a suppressed transition is put back after. */
+ function frames() {
+ return new Promise<void>(resolve => requestAnimationFrame(
+ () => requestAnimationFrame(() => setTimeout(resolve))));
+ }
});
describe("Board column reordering", () => {
@@ -529,7 +576,7 @@ describe("Board column reordering", () => {
// Watched rather than read afterwards: the frame that puts the transition back has run by
// the time the gesture returns.
expect(await classesWhile(board, () => carryColumn(columns[0], 280)))
- .toContain("board-landing");
+ .toContain("board-still");
});
it("eases the columns back where the drag is called off, having moved nothing", async () => {
@@ -538,7 +585,7 @@ describe("Board column reordering", () => {
// Let go where it started, which places the column back where it came from: the columns
// that stepped aside slide back, so the transition has to stay on.
expect(await classesWhile(board, () => carryColumn(columns[0], 20)))
- .not.toContain("board-landing");
+ .not.toContain("board-still");
});
it("puts the columns back once the gesture is over", async () => {
@@ -659,20 +706,6 @@ describe("Board column reordering", () => {
});
/** Takes hold of a column by its heading, carries it to `clientX` and lets it go there. */
- /** Every class the element wears at any point while `run` is going on. */
- async function classesWhile(element: HTMLElement, run: () => Promise<void>) {
- const seen = new Set<string>();
- const watch = new MutationObserver(() => {
- for (const name of element.classList) {
- seen.add(name);
- }
- });
- watch.observe(element, { attributes: true, attributeFilter: [ "class" ] });
- await run();
- watch.disconnect();
- return [ ...seen ];
- }
-
async function carryColumn(
column: HTMLElement,
clientX: number,
@@ -812,3 +845,17 @@ describe("Board column reordering", () => {
return new Promise((resolve) => setTimeout(resolve));
}
});
+
+/** Every class the element wears at any point while `run` is going on. */
+async function classesWhile(element: HTMLElement, run: () => Promise<void>) {
+ const seen = new Set<string>();
+ const watch = new MutationObserver(() => {
+ for (const name of element.classList) {
+ seen.add(name);
+ }
+ });
+ watch.observe(element, { attributes: true, attributeFilter: [ "class" ] });
+ await run();
+ watch.disconnect();
+ return [ ...seen ];
+}
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index 4bc2aaf677..ab7efe4356 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -946,13 +946,17 @@ body.mobile .column-drop-placeholder {
width var(--board-expand-duration) ease;
}
-/* The one frame the board is drawn in after something is dropped. Whatever was carried aside by a
- transform already stands where the new order puts it, so taking the transform off has nothing
- left to ease: given a transition it would carry the element a full width, or a card's height,
- from a place it never stood in. Written against the selectors above, which it has to outweigh. */
-.board-view-container.board-landing .board-column,
-.board-view-container.board-landing .board-column.collapsed:not(.board-drag-preview),
-.board-view-container.board-landing .board-column.quick-expand:not(.board-drag-preview) {
+/* The one frame the board is drawn in as a drag lifts something or lets it go. What the drag
+ carried aside by a transform already stands where the gap, or the new order, puts it, so the
+ transform has nothing left to ease: given a transition it would carry the element a full width,
+ or a card's height, from a place it never stood in. The gap is included so that it takes the
+ place of the card at once rather than fading into it. Written against the selectors above, which
+ it has to outweigh. */
+.board-view-container.board-still .board-note,
+.board-view-container.board-still .board-drop-placeholder,
+.board-view-container.board-still .board-column,
+.board-view-container.board-still .board-column.collapsed:not(.board-drag-preview),
+.board-view-container.board-still .board-column.quick-expand:not(.board-drag-preview) {
transition: none;
}
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index f0a126f25e..d1798fee4c 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -591,13 +591,20 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
// The gesture drives the same state a drag from the note tree does, so the placeholders and the
// card's own dimming are drawn from one place whichever brought the card here.
const { isDragging: isDraggingItem, remeasure } = useBoardDrag(containerRef, {
- onCardStart: (card) => setDraggedCard({
- noteId: card.noteId,
- branchId: byColumn?.get(card.fromColumn)?.[card.index]?.branch.branchId ?? "",
- fromColumn: card.fromColumn,
- index: card.index,
- height: card.height
- }),
+ onCardStart: (card) => {
+ // The card leaves the flow as it is lifted, and the gap opens in its place by pushing
+ // the cards below it down again. Under their transition that reads as the column
+ // closing up and then sliding back open, so the frame the gap opens in runs without
+ // one and the column is left looking untouched.
+ holdStill();
+ setDraggedCard({
+ noteId: card.noteId,
+ branchId: byColumn?.get(card.fromColumn)?.[card.index]?.branch.branchId ?? "",
+ fromColumn: card.fromColumn,
+ index: card.index,
+ height: card.height
+ });
+ },
onCardMove: (position, inside) => {
// Written together: two writes would wake every column watching the gap twice over.
dropState.set({ position, target: position?.column ?? null });
@@ -609,6 +616,10 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
}
},
onCardEnd: (card, position) => {
+ // The cards below the gap carry a `translateY` that the drop replaces with the layout
+ // the reorder gives them. Cleared under their transition, they slide up from a place
+ // they never stood in, so the frame the new order is drawn in runs without one.
+ holdStill();
// Put back here rather than left to the columns to draw: the board is about to move a
// card, hide the gap and close the room it took, and if those reach the screen in
// separate frames the reader sees a gap open where nothing is being carried any more.
@@ -659,7 +670,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
// where each column already stands where that order puts it. Eased to zero they
// would carry it a column's width from a place it never stood in, so the frame
// that takes them off runs without a transition.
- land();
+ holdStill();
// Not animated either: the row puts the columns exactly where they already are.
handleColumnDrop(from, to, false);
}
@@ -757,16 +768,17 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
/**
* Draws the next frame without transitions.
*
- * What a drag carried aside it carried by a transform, and the board is about to draw it where
- * that transform already had it. Eased instead, each element would set off from a place it
- * never stood in. Taken off a frame later than the one that draws it, since a frame's
- * callbacks run before the styles it paints are worked out.
+ * A drag opens its gap with transforms, and the board draws the elements those transforms
+ * already moved: at the lift the gap replaces the card that has left the flow, and at the drop
+ * the reorder replaces the gap. Eased, each element would set off from a place it never stood
+ * in. Taken off a frame later than the one that draws it, since a frame's callbacks run before
+ * the styles it paints are worked out.
*/
- const land = useCallback(() => {
+ const holdStill = useCallback(() => {
const container = containerRef.current;
- container?.classList.add("board-landing");
+ container?.classList.add("board-still");
requestAnimationFrame(() => requestAnimationFrame(
- () => container?.classList.remove("board-landing")));
+ () => container?.classList.remove("board-still")));
}, []);
const handleColumnDrop = useCallback((fromIndex: number, toIndex: number, animate = true) => {