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: tweak the drop hint
Adorian Doran1f3e72fdf05b
diff --git a/apps/client/src/stylesheets/theme-next-dark.css b/apps/client/src/stylesheets/theme-next-dark.cssindex 96cdf8e3df..63fea5dce5 100644--- a/apps/client/src/stylesheets/theme-next-dark.css+++ b/apps/client/src/stylesheets/theme-next-dark.css@@ -411,6 +411,10 @@--board-item-hover-background-saturation: 25%;--board-item-hover-background-lightness: 35%;+ --board-drop-hint-background-saturation: 20%;+ --board-drop-hint-background-lightness: 45%;+ --board-drop-hint-color: #ffffffc9;+--board-focus-outline-saturation: 60%;--board-focus-outline-lightness: 70%;diff --git a/apps/client/src/stylesheets/theme-next-light.css b/apps/client/src/stylesheets/theme-next-light.cssindex 4f1548af44..8c283ad6e7 100644--- a/apps/client/src/stylesheets/theme-next-light.css+++ b/apps/client/src/stylesheets/theme-next-light.css@@ -410,6 +410,10 @@--board-item-hover-background-saturation: 100%;--board-item-hover-background-lightness: 98.5%;+ --board-drop-hint-background-saturation: 50%;+ --board-drop-hint-background-lightness: 75%;+ --board-drop-hint-color: #000000bf;+--board-focus-outline-saturation: 50%;--board-focus-outline-lightness: 34%;diff --git a/apps/client/src/widgets/collections/board/board_drag.spec.tsx b/apps/client/src/widgets/collections/board/board_drag.spec.tsxindex 9a05ecc8c0..1b3e4a6d7a 100644--- a/apps/client/src/widgets/collections/board/board_drag.spec.tsx+++ b/apps/client/src/widgets/collections/board/board_drag.spec.tsx@@ -817,29 +817,52 @@ describe("useBoardDrag, carrying a card", () => {* 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", () => {+ it("lets the copy leave the board, but not past a sliver of itself", () => {setup(tall);- const shift = () => Number(preview()- ?.querySelector<HTMLElement>(".board-drop-hint span")- ?.style.transform.match(/-?[\d.]+/)?.[0]);-+ const labelEl = () => preview()+ ?.querySelector<HTMLElement>(".board-drop-hint span") as HTMLElement;+ const shift = () => Number(labelEl()?.style.transform.match(/-?[\d.]+/)?.[0]);+ const visible = () =>+ Number(preview()?.style.getPropertyValue("--board-drag-visible"));+ /** How far down the page the copy has been moved, off its own transform. */+ const moved = () =>+ Number(preview()?.style.transform.match(/translate3d\([^,]+,\s*(-?[\d.]+)px/)?.[1]);+ const showing = parseFloat(getComputedStyle(card("c3")).fontSize) * 1.5;++ // A card of its own height, carried above the board's head. Above the page here, as+ // the board's own head is below the window's in the app.takeHold();- move(50, 440);+ move(50, -60);act(() => { vi.advanceTimersByTime(20); });- // Wholly inside the board, so the label stands in the middle of the card.- expect(shift()).toBe(0);+ // Drawn 45 tall about a middle that starts 40 below the page's top, so this is where+ // its foot stands: a sliver of it inside the board's head at 0.+ expect(40 + moved() + 50 / 2 + 45 / 2).toBeCloseTo(showing, 5);+ release(50, -60);- release(50, 440);+ // A card taller than the board, carried past the foot but still short of leaving it.place(card("c3"), 0, 40, 100, 2000);-press(card("c3"), 50, 65);move(50, 440);act(() => { vi.advanceTimersByTime(20); });+ const head = () => 40 + moved() + 2000 / 2 - 1800 / 2;+ expect(head()).toBeCloseTo(515, 5);+ expect(visible()).toBeCloseTo(0.034, 3);++ // Carried on out, it stops with the same sliver against the board's foot.+ move(50, 1400);+ act(() => { vi.advanceTimersByTime(20); });+ const stood = moved();+ expect(head()).toBeCloseTo(600 - showing, 5);+ // Against the edge, where the fade has run its course.+ expect(visible()).toBe(0);++ // And stands still however far past the board the pointer goes.+ move(50, 1500);+ act(() => { vi.advanceTimersByTime(20); });+ expect(moved()).toBe(stood);- // 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;+ // The label keeps to the middle of what the board shows of the copy.+ const label = 40 + moved() + 2000 / 2 + shift() * 0.9;expect(label).toBeGreaterThan(0);expect(label).toBeLessThan(600);});diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.tsindex 57cf5fb531..05368bdb33 100644--- a/apps/client/src/widgets/collections/board/board_drag.ts+++ b/apps/client/src/widgets/collections/board/board_drag.ts@@ -25,6 +25,9 @@ const TOUCH_TOLERANCE = 8;/** How much a carried card shrinks. Written with the movement, a class could not add to it. */const DRAG_SCALE = 0.9;+/** How much of a copy put against the board's edge is left showing, in em of the card. */+const EDGE_SHOWING = 1.5;+/*** How many cards a carried selection is drawn as, however many are on the move: the one holding the* count and the two behind it. `index.css` draws the ones behind from `data-layers`.@@ -203,6 +206,8 @@ export function useBoardDrag(held.preview = lifted.preview;held.hint = lifted.hint;held.grab = lifted.grab;+ held.ownHue = lifted.ownHue;+ held.showing = lifted.showing;container.classList.add("board-dragging");setDragging(true);@@ -253,7 +258,7 @@ export function useBoardDrag(}scroller.update(edges, held.lastX, held.lastY);- markEnd(held, end);+ 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.@@ -290,11 +295,14 @@ export function useBoardDrag(* 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.*+ * Paints it in the card's own colour, or in the hue of `over` where the card has none.+ ** 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.+ * taller than the board keeps it visible, and fades the copy by how much of it the board+ * no longer shows. `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 markEnd = (held: Gesture, end: ColumnEnd | undefined, over?: ColumnBox) => {const hint = held.hint;const grab = held.grab;const view = held.measurement?.viewport;@@ -316,10 +324,26 @@ export function useBoardDrag(if (!end || !(label instanceof HTMLElement)) return;- const middle = held.lastY - grab.y + grab.height / 2;+ const hue = held.ownHue || over?.hue;+ held.preview?.classList.toggle("hint-tinted", !!hue);+ if (hue) {+ held.preview?.style.setProperty("--board-drop-hint-hue", hue);+ }++ const middle = held.lastY - grab.y + grab.height / 2 + holdBack(held);const drawn = grab.height * DRAG_SCALE / 2;const top = Math.max(middle - drawn, view.top);const bottom = Math.min(middle + drawn, view.bottom);+ // How much of the copy the board still shows, of what it can show at all: it stops+ // with a sliver of itself in view, so that sliver is where the fade ends rather than+ // nothing at all. One while the copy is wholly in view, zero once it is against the+ // edge, whatever the card's height.+ const height = drawn * 2;+ const least = height > 0 ? Math.min(1, (held.showing ?? 0) / height) : 1;+ const shown = height > 0 ? Math.max(0, Math.min(1, (bottom - top) / height)) : 1;+ const visible = least < 1 ? Math.max(0, (shown - least) / (1 - least)) : 1;+ held.preview?.style.setProperty("--board-drag-visible", visible.toFixed(3));+// 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.@@ -329,6 +353,30 @@ export function useBoardDrag(};/** Says where the card would land, and whether it has come to rest on that column. */+ /**+ * How far the copy stands back from the pointer while an end is being asked for: it follows+ * the pointer out of the board only until {@link EDGE_SHOWING} of it is left in view, and+ * goes no further however far past that the pointer goes.+ *+ * The far edge is the one left showing: the copy's foot at the board's head, its head at+ * the board's foot. Nothing to stand back while no end is being asked for, where the copy+ * follows the pointer wherever it goes.+ */+ const holdBack = (held: Gesture) => {+ const grab = held.grab;+ const view = held.measurement?.viewport;+ if (!held.end || !grab || !view) return 0;++ const middle = held.lastY - grab.y + grab.height / 2;+ const drawn = grab.height * DRAG_SCALE / 2;+ const inset = held.showing ?? 0;+ const wanted = held.end === "first"+ ? Math.max(middle, view.top + inset - drawn)+ : Math.min(middle, view.bottom - inset + drawn);++ return wanted - middle;+ };+const report = (held: Gesture, next?: DropPosition | null) => {if (held.kind !== "card") return;@@ -412,11 +460,14 @@ export function useBoardDrag(held.frame = undefined;if (!gesture.current || !held.preview) return;+ // Resolved first: where the copy stands depends on whether an end is being+ // asked for, which is what this works out.+ resolve(held);+const dx = held.lastX - held.startX;- const dy = held.lastY - held.startY;+ const dy = held.lastY - held.startY + holdBack(held);const scale = held.kind === "card" ? ` scale(${DRAG_SCALE})` : "";held.preview.style.transform = `translate3d(${dx}px, ${dy}px, 0)${scale}`;- resolve(held);});}};@@ -779,6 +830,14 @@ function lift(held: Gesture, container: HTMLElement) {preview.style.setProperty("--board-column-custom-hue", hue);}+ // A colour of the card's own, which the overlay takes before the hue of whatever column it is+ // held over, and the card's own em. Read here rather than on every move: both take a page read.+ const style = getComputedStyle(held.element);+ const ownHue = held.element.classList.contains("with-hue")+ ? style.getPropertyValue("--custom-color-hue").trim()+ : undefined;+ const showing = (parseFloat(style.fontSize) || 0) * EDGE_SHOWING;+for (const [ property, value ] of Object.entries({left: `${rect.left}px`,top: `${rect.top}px`,@@ -797,6 +856,8 @@ function lift(held: Gesture, container: HTMLElement) {return {preview,hint,+ ownHue,+ showing,size: { width: rect.width, height: rect.height },// Where inside it the reader took hold, so the middle can be found from the pointer.grab: {@@ -866,8 +927,12 @@ type Gesture = (CardSubject | ColumnSubject) & {hint?: HTMLElement;/** Which end that is, so the overlay is written only as it changes. */end?: ColumnEnd;+ /** The carried card's own colour as a hue, which the overlay takes before a column's. */+ ownHue?: string;/** What the label inside it measures, read when it is written rather than on every move. */labelHeight?: number;+ /** How much of the copy is left in view once it stands against the board's edge. */+ showing?: 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/drag_geometry.ts b/apps/client/src/widgets/collections/board/drag_geometry.tsindex ffdc44eb1c..66d5ab471d 100644--- a/apps/client/src/widgets/collections/board/drag_geometry.ts+++ b/apps/client/src/widgets/collections/board/drag_geometry.ts@@ -45,6 +45,8 @@ export interface ColumnBox {footEnd: number;/** Whether the column sorts its own cards, in which case the drop position is not chosen. */sorted: boolean;+ /** The column's own colour as a hue, or nothing where it has none. */+ hue?: string;/*** 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.diff --git a/apps/client/src/widgets/collections/board/drag_measure.ts b/apps/client/src/widgets/collections/board/drag_measure.tsindex ba4ac3fc3e..a9e0961ccf 100644--- a/apps/client/src/widgets/collections/board/drag_measure.ts+++ b/apps/client/src/widgets/collections/board/drag_measure.ts@@ -62,6 +62,9 @@ export function measureBoard(container: HTMLElement, withCards = true): BoardMeaheadStart: heading?.getBoundingClientRect().top ?? rect.top,footEnd: adder?.getBoundingClientRect().bottom ?? rect.bottom,sorted: element.dataset.sorted === "true",+ hue: element.classList.contains("with-hue")+ ? element.style.getPropertyValue("--board-column-custom-hue")+ : undefined,origin: withCards ? contentOrigin(area) : 0,cards: withCards ? measureCards(area) : []});diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex a4cf187813..285b055e6e 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -32,14 +32,20 @@--board-item-hover-shadow: 2px 4px 8px rgba(0, 0, 0, 0.1);/* What a carried card casts, which the stack of a carried selection is drawn behind. */--board-drag-shadow: 4px 8px 16px rgba(0, 0, 0, 0.5);+ /* What a carried copy is drawn at, and what it fades to once it stands against the board's+ edge with only a sliver of itself in view. */+ --board-drag-opacity: 0.85;+ --board-drag-opacity-faded: 0.4;/* How far each card of a carried stack stands out from the one in front of it. */--board-drag-stack-offset: 4px;/* The ring a carried card wears, which the stack behind it starts clear of. */--board-drag-ring-width: 3px;/* The ring a picked-out card carries. */--board-selected-ring-color: var(--link-color);- /* The overlay on a carried card while it would drop at one end of a column. */- --board-drop-hint-background: #1f2933;+ /* The overlay on a carried card while it would drop at one end of a column, painted in the hue+ the card itself is. */+ --board-drop-hint-background-saturation: 35%;+ --board-drop-hint-background-lightness: 25%;--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. */@@ -593,7 +599,7 @@ body.mobile .board-view-container .board-add-column {will-change: transform;z-index: 1000;pointer-events: none;- opacity: 0.85;+ opacity: var(--board-drag-opacity);box-shadow: var(--board-drag-shadow);}@@ -606,10 +612,38 @@ body.mobile .board-view-container .board-add-column {justify-content: center;border-radius: inherit;padding: var(--card-padding);- background-color: var(--board-drop-hint-background);+ /* Drained of colour until a hue is named, so a card with none of its own held over a plain+ column reads as grey rather than red. */+ background-color: hsl(+ var(--board-drop-hint-hue, 0),+ 0%,+ var(--board-drop-hint-background-lightness)+ );text-align: center;font-weight: 600;color: var(--board-drop-hint-color);+ transition: background-color 250ms ease, color 250ms ease;+}++/* The card's own hue, or the hue of the column it is held over. */+.board-view-container .board-drag-preview.hint-tinted .board-drop-hint {+ background-color: hsl(+ var(--board-drop-hint-hue),+ var(--board-drop-hint-background-saturation),+ var(--board-drop-hint-background-lightness)+ );+}++/* The focus ring the copy carries would stand around the overlay, which reads on its own. The copy+ fades as it leaves the board, `--board-drag-visible` running from one while it is wholly in view+ to zero once it stands against the edge. */+.board-view-container .board-drag-preview.showing-drop-hint {+ outline: none;+ opacity: calc(+ var(--board-drag-opacity-faded)+ + (var(--board-drag-opacity) - var(--board-drag-opacity-faded))+ * var(--board-drag-visible, 1)+ );}.board-view-container .board-drag-preview.showing-drop-hint .board-drop-hint {