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: preserve the parent column tint when dragging a note
Adorian Dorancdee8a4c2674
diff --git a/apps/client/src/widgets/collections/board/board_drag.spec.tsx b/apps/client/src/widgets/collections/board/board_drag.spec.tsxindex 2303a11998..0dd2f08596 100644--- a/apps/client/src/widgets/collections/board/board_drag.spec.tsx+++ b/apps/client/src/widgets/collections/board/board_drag.spec.tsx@@ -508,6 +508,23 @@ describe("useBoardDrag, carrying a card", () => {expect(column?.style.display).toBe("none");});+ it("carries the tint of the column a card came from, and none where there is none", () => {+ setup();++ press(card("n1"), 10, 10);+ move(60, 10);+ const tinted = board.querySelector<HTMLElement>(".board-note.board-drag-preview");+ expect(tinted?.classList.contains("column-tinted")).toBe(true);+ expect(tinted?.style.getPropertyValue("--board-column-custom-hue")).toBe("210");+ release(60, 10);++ press(card("n3"), 210, 10);+ move(260, 10);+ const plain = board.querySelector<HTMLElement>(".board-note.board-drag-preview");+ expect(plain?.classList.contains("column-tinted")).toBe(false);+ release(260, 10);+ });+it("reports the place it would take, counting the columns as they stand", () => {setup();@@ -583,6 +600,11 @@ describe("useBoardDrag, carrying a card", () => {const column = document.createElement("div");column.className = "board-column";column.dataset.column = [ "To Do", "Doing" ][index];+ // The first column is tinted, the second is not, so a copy can be checked against both.+ if (index === 0) {+ column.classList.add("with-hue");+ column.style.setProperty("--board-column-custom-hue", "210");+ }board.appendChild(column);place(column, index * 200, 0, 100, 400);diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.tsindex b0bf5e69ed..2bd80fe0f0 100644--- a/apps/client/src/widgets/collections/board/board_drag.ts+++ b/apps/client/src/widgets/collections/board/board_drag.ts@@ -493,6 +493,15 @@ function lift(held: Gesture, container: HTMLElement) {preview.querySelector(".edit-icon")?.remove();preview.querySelector(".board-new-item")?.remove();+ // 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")+ ?.style.getPropertyValue("--board-column-custom-hue");+ if (held.kind === "card" && hue) {+ preview.classList.add("column-tinted");+ preview.style.setProperty("--board-column-custom-hue", hue);+ }+for (const [ property, value ] of Object.entries({left: `${rect.left}px`,top: `${rect.top}px`,diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex ac51f2fd80..106c7b7035 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -269,6 +269,14 @@ body.mobile .board-view-container .board-add-column {--board-item-hue: var(--board-column-custom-hue);}+/* A carried copy stands in the drag layer rather than in its column, so it is tinted directly. Left+ above the rules below, which a card with a colour of its own is painted by instead. */+.board-view-container .board-drag-preview.column-tinted {+ --board-item-hue: var(--board-column-custom-hue);+ --board-item-saturation: var(--board-item-background-saturation);+ --board-item-hover-saturation: var(--board-item-hover-background-saturation);+}+/* ...and its own wherever it has one, the second selector outweighing the column's rule aboverather than merely following it. A card wears `with-hue` only for a colour of its own, which iswhat tells it apart from one inheriting the hue of the note the board is shown in. */