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 the board to be horizontally panned by dragging its background with the mouse cursor
Adorian Doran72f37f645e63
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex e6883d3333..0568a2e7a1 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -45,6 +45,21 @@overflow-x: auto;}+/* Only where there is somewhere to pan. The columns set their own, so the grab hand shows over the+ board's background alone. */+.board-view-container.pannable {+ cursor: grab;+}++.board-view-container.panning {+ cursor: grabbing;+}++.board-view-container.pannable > .board-column,+.board-view-container.pannable > .board-add-column {+ cursor: auto;+}+body.mobile .board-view-container {scroll-snap-type: x mandatory;-webkit-overflow-scrolling: touch;diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 810c442427..d00006ba47 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -1,5 +1,7 @@import "./index.css";+import clsx from "clsx";+import { createContext, TargetedKeyboardEvent } from "preact";import { createPortal } from "preact/compat";import { Dispatch, StateUpdater, useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";@@ -21,6 +23,7 @@ import Icon from "../../react/Icon";import NoteAutocomplete from "../../react/NoteAutocomplete";import ShortcutHintButton from "../../shortcut_hints/shortcut_hint_button";import { onWheelHorizontalScroll } from "../../widget_utils";+import { useDragPan } from "../../react/drag_pan";import { ViewModeProps } from "../interface";import Api, { getPendingWrites, PendingColumnWrites, settleColumn } from "./api";import BoardApi from "./api";@@ -330,6 +333,10 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC});}+ // Only the board's own background, so a press on a column, a card or the button that adds one+ // is left to whatever it belongs to.+ const { isPannable, isPanning } = useDragPan(containerRef);+// The board is not drawn afresh for another note, so the column opened on one would otherwise// still be open on the next, over whatever that board stores for a column of the same name.useEffect(() => setActiveColumn(undefined), [ parentNote ]);@@ -422,7 +429,10 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC<BoardDragStateContext.Provider value={boardDragState}>{byColumn && columns && <divref={containerRef}- className="board-view-container"+ className={clsx("board-view-container", {+ pannable: isPannable,+ panning: isPanning+ })}onKeyDown={handleKeyDown}onDragOver={handleColumnDragOver}onDrop={handleContainerDrop}