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: use a proper card multi-selection mode for mobile devices
Adorian Doran28a0c13cf7b7
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 758a24d7fa..e95ac4d688 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3570,7 +3570,12 @@"reset-column-sorting": "Reset sorting options to default for all columns","reset-column-sorting-confirm": "Do you want to reset the sorting options for all columns from the current view to default?","sorted-no-reorder": "Cards cannot be reordered, since this is a sorted column.",- "more-actions": "More actions"+ "more-actions": "More actions",+ "selection-mode": "Select cards",+ "cards-selected_one": "{{count}} card selected",+ "cards-selected_other": "{{count}} cards selected",+ "select-column-cards": "Select every card in the column",+ "reset-selection": "Reset the selection"},"dashboard_view": {"refresh-widget": "Refresh",diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.tsindex 8e4e02e71b..2e0ee4b14b 100644--- a/apps/client/src/widgets/collections/board/board_drag.ts+++ b/apps/client/src/widgets/collections/board/board_drag.ts@@ -702,8 +702,8 @@ function endIndex(end: ColumnEnd | undefined, column: ColumnBox) {return end === "first" ? 0 : column.count;}-/** Asks an element for its menu the way a right click does, at the place the tap landed. */-function askForMenu(element: HTMLElement, clientX: number, clientY: number) {+/** Asks an element for its menu the way a right click does, at the place the press landed. */+export function askForMenu(element: HTMLElement, clientX: number, clientY: number) {element.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, clientX, clientY }));}diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsxindex 1c72247f03..2cc7c05fa0 100644--- a/apps/client/src/widgets/collections/board/card.tsx+++ b/apps/client/src/widgets/collections/board/card.tsx@@ -9,7 +9,7 @@ import FNote from "../../../entities/fnote";import BoardApi, { CARD_REDIRECT_RELATION } from "./api";import {BoardActionsContext, BoardHighlightTokensContext, BoardKeptCardsContext,- BoardOverlayHostContext, BoardPromotedAttributesContext, TitleEditor+ BoardOverlayHostContext, BoardPromotedAttributesContext, BoardSelectionModeContext, TitleEditor} from ".";import { ContextMenuEvent } from "../../../menus/context_menu";import { cardFollows } from "./columns";@@ -99,6 +99,7 @@ function Card({// here leaves the memo below intact.const selection = useSelection();const overlayHost = useContext(BoardOverlayHostContext);+ const isSelecting = useContext(BoardSelectionModeContext);/** Whether the card holds the focus, which on mobile floats its toolbar over the board. */const [ isFocused, setIsFocused ] = useState(false);// Focus moving within the card or onto the toolbar keeps the toolbar; anywhere else takes it.@@ -149,6 +150,12 @@ function Card({// popup already standing is taken as the one to stack on, and closing that leaves neither.if (e.detail > 1) return;+ // In selection mode a tap picks the card out or puts it back, and opens nothing.+ if (isSelecting) {+ selection.toggle(note.noteId);+ return;+ }+// A link to a note, such as a relation's target, opens in the popup. Cancelled here so that// `goToLink` does not open a tab for it as well; a link naming no note is left alone.// Checked before the modifiers below, so Ctrl on a link still means what it means anywhere.@@ -181,7 +188,7 @@ function Card({selection.clear();api.openCard(note);- }, [ api, note, column, selection ]);+ }, [ api, note, column, selection, isSelecting ]);/*** Fills the drag with what the note tree reads, for the native drag a Ctrl press arms in@@ -333,9 +340,11 @@ function Card({badges={isOutsideFilter && <OutsideFilterBadge />}/></div>- {/* Off the card while its title is edited, since the rename it offers is under way, and- while it is carried, since the board is being rearranged under the finger. */}- {isMobile() && isFocused && !isEditing && !isDragging && overlayHost.current && (+ {/* Off the card while its title is edited, since the rename it offers is under way, while+ it is carried, since the board is being rearranged under the finger, and in selection+ mode, where the board's own rail acts on the selection instead. */}+ {isMobile() && isFocused && !isEditing && !isDragging && !isSelecting+ && overlayHost.current && (<CardToolbarhost={overlayHost.current}isSorted={api.isColumnSorted(column)}diff --git a/apps/client/src/widgets/collections/board/card_toolbar.tsx b/apps/client/src/widgets/collections/board/card_toolbar.tsxindex 0eb78d3809..4ed7dd68b1 100644--- a/apps/client/src/widgets/collections/board/card_toolbar.tsx+++ b/apps/client/src/widgets/collections/board/card_toolbar.tsx@@ -1,5 +1,6 @@import "./card_toolbar.css";+import { type ComponentChildren } from "preact";import { createPortal } from "preact/compat";import { t } from "../../../services/i18n";@@ -37,62 +38,112 @@ export default function CardToolbar({host, isSorted, removal, onRename, onInsertAbove, onInsertBelow, onInsertNew, onRemove,onMore, onFocusOut}: CardToolbarProps) {+ return (+ <Rail host={host} onFocusOut={onFocusOut}>+ <OverlayControlButton+ title={t("board_view.edit-title")}+ icon="bx-rename"+ onClick={onRename}+ />+ {isSorted ? (+ <OverlayControlButton+ title={t("board_view.insert-new")}+ icon="bx-plus"+ onClick={onInsertNew}+ />+ ) : (<>+ <OverlayControlButton+ title={t("board_view.insert-above")}+ icon="bx-list-plus"+ onClick={onInsertAbove}+ />+ <OverlayControlButton+ title={t("board_view.insert-below")}+ icon="bx-list-plus"+ className="board-insert-below-button"+ onClick={onInsertBelow}+ />+ </>)}+ {removal === "board" ? (+ <OverlayControlButton+ title={t("board_view.remove-from-board")}+ icon="bx-task-x"+ className="board-remove-button"+ onClick={onRemove}+ />+ ) : (+ <OverlayControlButton+ title={t("board_view.delete-note")}+ icon="bx-trash"+ className="board-remove-button"+ onClick={onRemove}+ />+ )}+ <OverlayControlButton+ title={t("board_view.more-actions")}+ icon="bx-dots-vertical-rounded"+ onClick={onMore}+ />+ </Rail>+ );+}++interface SelectionToolbarProps {+ host: HTMLElement;+ /** How many cards are picked out. With none, there is nothing to press. */+ count: number;+ onDelete: () => void;+ /** Opens the context menu for the selection, at the button. */+ onMore: (event: MouseEvent) => void;+}++/**+ * What can be done with the cards picked out in selection mode: deleting them, or opening the+ * menu for all of them. Stands in for the focused card's rail while the mode lasts.+ */+export function SelectionToolbar({ host, count, onDelete, onMore }: SelectionToolbarProps) {+ return (+ <Rail host={host}>+ <OverlayControlButton+ title={t("board_view.delete-note")}+ icon="bx-trash"+ className="board-remove-button"+ disabled={count === 0}+ onClick={onDelete}+ />+ <OverlayControlButton+ title={t("board_view.more-actions")}+ icon="bx-dots-vertical-rounded"+ disabled={count === 0}+ onClick={onMore}+ />+ </Rail>+ );+}++interface RailProps {+ host: HTMLElement;+ onFocusOut?: (event: FocusEvent) => void;+ children: ComponentChildren;+}++/** The rail itself, flush with the board's trailing edge; what stands on it is the caller's. */+function Rail({ host, onFocusOut, children }: RailProps) {return createPortal(<divclassName="board-card-toolbar"// A press must not move the focus off the card, which would close the toolbar under- // the finger, nor reach the board, which would take it for the start of a pan.+ // the finger, nor reach the board, which would take it for the start of a pan. Nor+ // the click: to the board, a click outside a card gives the selection up.onPointerDown={(e) => {e.preventDefault();e.stopPropagation();}}+ onClick={(e) => e.stopPropagation()}onFocusOut={onFocusOut}><OverlayControlGroup placement="middle-end" vertical overCanvas>- <OverlayControlButton- title={t("board_view.edit-title")}- icon="bx-rename"- onClick={onRename}- />- {isSorted ? (- <OverlayControlButton- title={t("board_view.insert-new")}- icon="bx-plus"- onClick={onInsertNew}- />- ) : (<>- <OverlayControlButton- title={t("board_view.insert-above")}- icon="bx-list-plus"- onClick={onInsertAbove}- />- <OverlayControlButton- title={t("board_view.insert-below")}- icon="bx-list-plus"- className="board-insert-below-button"- onClick={onInsertBelow}- />- </>)}- {removal === "board" ? (- <OverlayControlButton- title={t("board_view.remove-from-board")}- icon="bx-task-x"- className="board-remove-button"- onClick={onRemove}- />- ) : (- <OverlayControlButton- title={t("board_view.delete-note")}- icon="bx-trash"- className="board-remove-button"- onClick={onRemove}- />- )}- <OverlayControlButton- title={t("board_view.more-actions")}- icon="bx-dots-vertical-rounded"- onClick={onMore}- />+ {children}</OverlayControlGroup></div>,hostdiff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex 820ba848f8..4e3137e0ea 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -42,6 +42,9 @@--board-drag-ring-width: 3px;/* The ring a picked-out card carries. */--board-selected-ring-color: var(--link-color);+ /* The wedge in a card's foot corner while cards are being selected, until the card is. */+ --board-selection-wedge-size: 14px;+ --board-selection-wedge-color: var(--main-border-color);/* The overlay on a carried card while it would drop at one end of a column, painted in the huethe card itself is. */--board-drop-hint-background-saturation: 35%;@@ -523,6 +526,27 @@ body.mobile .board-view-container .board-add-column {var(--board-item-hover-shadow);}+/* Selection mode: every card wears a wedge in its foot corner saying a tap picks it out, painted+ in the ring's colour once it is. */+.board-view-container.selecting .board-note {+ position: relative;+}++.board-view-container.selecting .board-note::after {+ content: "";+ position: absolute;+ inset-inline-end: 0;+ bottom: 0;+ border-style: solid;+ border-width: 0 0 var(--board-selection-wedge-size) var(--board-selection-wedge-size);+ border-color: transparent transparent var(--board-selection-wedge-color) transparent;+ pointer-events: none;+}++.board-view-container.selecting .board-note.selected::after {+ border-bottom-color: var(--board-selected-ring-color);+}+/* A card travelling with the one under the pointer. That one is taken out of the flow by thegesture; the rest stay where they are drawn. */.board-view-container .board-note.dragging {diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex cfbeb35efa..87f809f94e 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -4753,6 +4753,39 @@ describe("what the board hands the right pane", () => {});});+/**+ * Disposes every modal an earlier test left shown. Such a dialog can be mounted only after that+ * test's teardown, and a modal Bootstrap believes shown pulls the focus back into itself from+ * anything focused later. The mobile rails follow the focus, so the page is cleared of them first.+ */+function disposeShownModals() {+ for (const modal of document.querySelectorAll<HTMLElement>(".modal.show")) {+ BootstrapModal.getInstance(modal)?.dispose();+ modal.remove();+ }+ document.querySelector(".modal-backdrop")?.remove();+ document.body.classList.remove("modal-open");+}++/**+ * Runs a step with a tab manager standing in for the app's, which the card's menu and the reveal+ * after a drop ask for the active pane. Only for that step: the board's own hooks read the manager+ * while it renders, and answer differently to a stand-in than to none.+ */+async function withTabManager(step: () => Promise<void>) {+ const previous = appContext.tabManager;+ appContext.tabManager = {+ getActiveContext: () => undefined,+ // The menu on mobile asks whether the pane is split, which one with no splits is not.+ getNoteContextById: () => ({ getMainContext: () => ({ getSubContexts: () => [] }) })+ } as never;+ try {+ await step();+ } finally {+ appContext.tabManager = previous;+ }+}+describe("Card toolbar on mobile", () => {let container: HTMLElement;let host: Component;@@ -4771,15 +4804,7 @@ describe("Card toolbar on mobile", () => {/** A board of two columns, three cards, nothing sorted, and an inbox only when asked for. */async function setup({ withInbox = false } = {}) {- // A dialog an earlier test opened can be mounted only after that test's teardown, and a- // modal Bootstrap believes shown pulls the focus back into itself from anything focused- // later. The toolbar follows the focus, so the page is cleared of them first.- for (const modal of document.querySelectorAll<HTMLElement>(".modal.show")) {- BootstrapModal.getInstance(modal)?.dispose();- modal.remove();- }- document.querySelector(".modal-backdrop")?.remove();- document.body.classList.remove("modal-open");+ disposeShownModals();const note = buildNote({title: "Board",@@ -4835,25 +4860,6 @@ describe("Card toolbar on mobile", () => {await act(async () => { card(noteId).focus(); });}- /**- * Runs a step with a tab manager standing in for the app's, which the card's menu and the- * reveal after a drop ask for the active pane. Only for that step: the board's own hooks read- * the manager while it renders, and answer differently to a stand-in than to none.- */- async function withTabManager(step: () => Promise<void>) {- const previous = appContext.tabManager;- appContext.tabManager = {- getActiveContext: () => undefined,- // The menu on mobile asks whether the pane is split, which one with no splits is not.- getNoteContextById: () => ({ getMainContext: () => ({ getSubContexts: () => [] }) })- } as never;- try {- await step();- } finally {- appContext.tabManager = previous;- }- }-it("follows the focus onto a card and leaves with it, over the board", async () => {await setup();expect(toolbar()).toBeNull();@@ -4970,3 +4976,174 @@ describe("Card toolbar on mobile", () => {expect(toolbar()).not.toBeNull();});});++describe("Selection mode on mobile", () => {+ let container: HTMLElement;+ let host: Component;++ beforeEach(() => {+ layout.onMobile = true;+ });++ afterEach(() => {+ layout.onMobile = false;+ saved.length = 0;+ render(null, container);+ container.remove();+ });++ /** A collection note, so the header the mode is switched on from is drawn. */+ async function setup() {+ disposeShownModals();++ const note = buildNote({+ title: "Board",+ type: "book",+ "#collection": "",+ "#viewType": "board",+ children: [+ { id: "pick1", title: "First", "#status": "To Do" },+ { id: "pick2", title: "Second", "#status": "To Do" },+ { id: "pick3", title: "Third", "#status": "Done" }+ ]+ });++ host = new Component();+ container = document.body.appendChild(document.createElement("div"));+ await act(async () => {+ render(+ <ParentComponent.Provider value={host}>+ <Harness+ note={note}+ noteIds={[ ...note.getChildNoteIds() ]}+ initialConfig={{ columns: [ { value: "To Do" }, { value: "Done" } ] }}+ />+ </ParentComponent.Provider>,+ container+ );+ });+ await act(async () => { await flush(); });++ return note;+ }++ function card(noteId: string) {+ const element = container.querySelector<HTMLElement>(+ `.board-note[data-note-id="${noteId}"]`);+ if (!element) throw new Error(`expected the card ${noteId}`);+ return element;+ }++ const board = () => container.querySelector(".board-view-container");+ const bar = () => container.querySelector<HTMLElement>(".board-selection-bar");+ const selected = () => [ ...container.querySelectorAll(".board-note.selected") ]+ .map(element => element.getAttribute("data-note-id"));++ function headerButton(icon: string) {+ const element = container.querySelector<HTMLElement>(`.board-header-tools button.${icon}`);+ if (!element) throw new Error(`expected a ${icon} button in the header`);+ return element;+ }++ function railButton(icon: string) {+ const element = container.querySelector<HTMLElement>(`.board-card-toolbar button.${icon}`);+ if (!element) throw new Error(`expected a ${icon} button on the rail`);+ return element;+ }++ async function startSelecting() {+ await act(async () => { headerButton("bx-select-multiple").click(); });+ }++ async function tap(noteId: string) {+ await act(async () => {+ card(noteId).focus();+ card(noteId).click();+ });+ }++ it("is switched on from the header and covers that row while it lasts", async () => {+ await setup();+ expect(bar()).toBeNull();+ expect(board()?.classList.contains("selecting")).toBe(false);++ await startSelecting();+ expect(board()?.classList.contains("selecting")).toBe(true);+ expect(bar()?.querySelector(".board-selection-count")?.textContent)+ .toBe('board_view.cards-selected:{"count":0}');+ // Over the grouping and the filter, which stay in the page beneath it.+ expect(bar()?.parentElement?.querySelector(".board-group-by")).toBeTruthy();++ await act(async () => { headerButton("bx-x").click(); });+ expect(bar()).toBeNull();+ expect(board()?.classList.contains("selecting")).toBe(false);+ });++ it("is left out off mobile", async () => {+ layout.onMobile = false;+ await setup();++ expect(container.querySelector(".board-selection-toggle")).toBeNull();+ });++ /**+ * A tap picks a card out or puts it back, and opens nothing. The focused card's own rail+ * stands aside for the selection's, which has nothing to offer until a card is picked.+ */+ it("picks cards out with a tap instead of opening them", async () => {+ await setup();+ const openCard = vi.spyOn(BoardApi.prototype, "openCard").mockImplementation(() => {});+ await startSelecting();++ expect(railButton("bx-trash").hasAttribute("disabled")).toBe(true);+ expect(container.querySelector(".board-card-toolbar button.bx-rename")).toBeNull();++ await tap("pick1");+ expect(selected()).toEqual([ "pick1" ]);+ expect(openCard).not.toHaveBeenCalled();+ expect(bar()?.querySelector(".board-selection-count")?.textContent)+ .toBe('board_view.cards-selected:{"count":1}');+ expect(railButton("bx-trash").hasAttribute("disabled")).toBe(false);+ expect(container.querySelector(".board-card-toolbar button.bx-rename")).toBeNull();++ await tap("pick1");+ expect(selected()).toEqual([]);++ // Off again, a tap opens the card as before.+ await act(async () => { headerButton("bx-x").click(); });+ await tap("pick1");+ expect(openCard).toHaveBeenCalledTimes(1);+ expect(selected()).toEqual([]);++ openCard.mockRestore();+ });++ it("selects the column of the last picked card, and acts on the whole selection", async () => {+ await setup();+ const deleteNotes = vi.spyOn(branches, "deleteNotes").mockResolvedValue(false);+ const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});+ await startSelecting();++ await tap("pick1");+ await act(async () => { headerButton("bx-list-check").click(); });+ expect(selected().sort()).toEqual([ "pick1", "pick2" ]);++ // The menu is the one the cards offer, carrying every picked card.+ await withTabManager(async () => {+ await act(async () => { railButton("bx-dots-vertical-rounded").click(); });+ });+ expect(show).toHaveBeenCalledTimes(1);++ await act(async () => { railButton("bx-trash").click(); });+ expect(deleteNotes).toHaveBeenCalledTimes(1);+ expect(deleteNotes.mock.calls[0][0]).toHaveLength(2);++ // Reset gives the selection up and ends the mode with it.+ await act(async () => { headerButton("bx-x").click(); });+ expect(selected()).toEqual([]);+ expect(bar()).toBeNull();++ deleteNotes.mockRestore();+ show.mockRestore();+ });+});diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex b2a26eb82c..1c09aa0b7a 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -4,7 +4,7 @@ import clsx from "clsx";import { ComponentChildren, createContext, Fragment, TargetedKeyboardEvent } from "preact";import { JSX } from "preact/jsx-runtime";-import { createPortal, RefObject } from "preact/compat";+import { createPortal, RefObject, useSyncExternalStore } from "preact/compat";import {Dispatch, StateUpdater, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState} from "preact/hooks";@@ -14,6 +14,7 @@ import { type HighlightedTokenInfo, normalizeBoardGroupBy } from "@triliumnext/cimport appContext from "../../../components/app_context";import FNote from "../../../entities/fnote";import attributes from "../../../services/attributes";+import branches from "../../../services/branches";import froca from "../../../services/froca";import { t } from "../../../services/i18n";import { getCreationDate, loadCreationDates } from "../../../services/note_dates";@@ -46,9 +47,11 @@ import { useDragPan } from "../../react/drag_pan";import { FLIP_SETTLE_MS, useFlip } from "../../react/flip";import { SelectionContext, SelectionStore } from "../../react/selection";import { CollectionFilterInput, useCollectionFilter } from "../collection_filter";+import { SelectionToolbar } from "./card_toolbar";+import BoardHeaderTools from "./selection_bar";import { ViewModeProps } from "../interface";import Api, { getPendingWrites, PendingColumnWrites, settleColumn } from "./api";-import { useBoardDrag } from "./board_drag";+import { askForMenu, useBoardDrag } from "./board_drag";import { columnGapStandsAside, columnStandsAside, movesColumn } from "./drag_geometry";import { forgetCardHeights } from "./drag_measure";import { forgetWindowHeights } from "./windowing";@@ -269,6 +272,9 @@ export const BoardKeptCardsContext = createContext<Set<string>>(new Set());/** The board's own element, which what a card floats over the board is portaled into. */export const BoardOverlayHostContext = createContext<RefObject<HTMLElement>>({ current: null });+/** Whether a tap picks a card out instead of opening it, which the mobile header switches on. */+export const BoardSelectionModeContext = createContext(false);+/*** What the board answers with when asked for contextual keyboard help. Every entry is a key the* board handles itself (see `keyboard.ts` and the card and column handlers), none of them@@ -394,6 +400,23 @@ export default function BoardView({* card must wake that card and no other.*/const selection = useMemo(() => new SelectionStore(), []);+ /**+ * Whether a tap picks a card out instead of opening it. Mobile only: a finger has no Ctrl to+ * pick cards out with. Leaving the mode gives the selection up as well.+ */+ const [ isSelecting, setIsSelecting ] = useState(false);+ // Read here rather than through `useSelectionCount`, which reads the context this board+ // provides and would find the default store instead.+ const subscribeToSelection = useCallback(+ (listener: () => void) => selection.subscribe(listener), [ selection ]);+ const selectionCount = useSyncExternalStore(+ subscribeToSelection, useCallback(() => selection.size, [ selection ]));+ const selectionAnchor = useSyncExternalStore(+ subscribeToSelection, useCallback(() => selection.anchor, [ selection ]));+ const stopSelecting = useCallback(() => {+ setIsSelecting(false);+ selection.clear();+ }, [ selection ]);const setDropPosition = useCallback((position: ColumnDrag | null) => {dropState.set({ ...dropState.get(), position });}, [ dropState ]);@@ -1124,6 +1147,8 @@ export default function BoardView({// still be open on the next, over whatever that board stores for a column of the same name.// The same holds across a grouping, whose columns are a different set entirely.useEffect(() => selectColumn(undefined), [ parentNote, groupBy, selectColumn ]);+ // Another board starts outside selection mode: the board is not remounted between notes.+ useEffect(() => setIsSelecting(false), [ parentNote ]);// Stored once, and only for a board still carrying a pre-switching column list.useEffect(() => {@@ -1343,18 +1368,39 @@ export default function BoardView({onClick={() => setIsEditingProperties(true)}>{t("board_view.properties")}</FormListItem>}- rightChildren={<>- <BoardGroupBy- note={parentNote}- options={groupingChoices}- current={currentGrouping}- onSelect={setRequestedGroupBy}- />- <CollectionFilterInput- filter={filter}- placeholder={t("board_view.filter-placeholder")}- />- </>}+ rightChildren={+ <BoardHeaderTools+ isSelecting={isSelecting}+ onToggleSelecting={() => (isSelecting+ ? stopSelecting()+ : setIsSelecting(true))}+ count={selectionCount}+ canSelectColumn={selectionAnchor !== null}+ onSelectColumn={() => {+ // The column of the card last picked out, added to what is picked.+ const column = selectionAnchor === null+ ? undefined+ : api.getCardColumn(selectionAnchor);+ if (column !== undefined) {+ selection.selectAll([+ ...selection.keys, ...api.getColumnNoteIds(column)+ ]);+ }+ }}+ onReset={stopSelecting}+ >+ <BoardGroupBy+ note={parentNote}+ options={groupingChoices}+ current={currentGrouping}+ onSelect={setRequestedGroupBy}+ />+ <CollectionFilterInput+ filter={filter}+ placeholder={t("board_view.filter-placeholder")}+ />+ </BoardHeaderTools>+ }/><BoardActionsContext.Provider value={boardActions}><BoardPromotedAttributesContext.Provider value={shownAttributes}>@@ -1364,12 +1410,14 @@ export default function BoardView({<BoardDragStateContext.Provider value={boardDragState}><SelectionContext.Provider value={selection}><BoardOverlayHostContext.Provider value={containerRef}>+ <BoardSelectionModeContext.Provider value={isSelecting}>{byColumn && columns && <divref={containerRef}className={clsx("board-view-container", {pannable: isPannable,panning: isPanning,- dragging: isDraggingItem+ dragging: isDraggingItem,+ selecting: isSelecting})}onKeyDown={handleKeyDown}onClick={clearSelectionOutsideCards}@@ -1491,6 +1539,28 @@ export default function BoardView({</OverlayControlGroup>)}</div>}+ {/* Acts on the selection in place of the focused card's rail. The menu is+ asked of the card first picked out, whose own handler carries the whole+ selection, the way a tap on a heading asks for a column's. */}+ {isMobile() && isSelecting && containerRef.current && (+ <SelectionToolbar+ host={containerRef.current}+ count={selectionCount}+ onDelete={() => branches.deleteNotes(+ api.getCards(selection.keys).map((card) => card.branch.branchId),+ false, false)}+ onMore={(e) => {+ const [ first ] = selection.keys;+ const card = [ ...containerRef.current+ ?.querySelectorAll<HTMLElement>(".board-note") ?? [] ]+ .find((element) => element.dataset.noteId === first);+ if (card) {+ askForMenu(card, e.clientX, e.clientY);+ }+ }}+ />+ )}+ </BoardSelectionModeContext.Provider></BoardOverlayHostContext.Provider></SelectionContext.Provider></BoardDragStateContext.Provider>diff --git a/apps/client/src/widgets/collections/board/selection_bar.css b/apps/client/src/widgets/collections/board/selection_bar.cssnew file mode 100644index 0000000000..e970473f16--- /dev/null+++ b/apps/client/src/widgets/collections/board/selection_bar.css@@ -0,0 +1,26 @@+:where(:root) {+ --board-selection-bar-background: var(--main-background-color);+}++.board-header-tools {+ display: flex;+ position: relative;+ flex: 1;+ justify-content: flex-end;+ align-items: center;+ gap: 0.5em;+}++/* Over the grouping, the filter and the toggle, all of which the selection replaces meanwhile. */+.board-header-tools .board-selection-bar {+ display: flex;+ position: absolute;+ inset: 0;+ align-items: center;+ gap: 0.5em;+ background-color: var(--board-selection-bar-background);+}++.board-header-tools .board-selection-count {+ flex: 1;+}diff --git a/apps/client/src/widgets/collections/board/selection_bar.tsx b/apps/client/src/widgets/collections/board/selection_bar.tsxnew file mode 100644index 0000000000..ceb758b996--- /dev/null+++ b/apps/client/src/widgets/collections/board/selection_bar.tsx@@ -0,0 +1,66 @@+import "./selection_bar.css";++import { type ComponentChildren } from "preact";++import { t } from "../../../services/i18n";+import { isMobile } from "../../../services/utils";+import ActionButton from "../../react/ActionButton";++interface BoardHeaderToolsProps {+ /** The grouping and the filter, after the toggle, which the selection bar covers meanwhile. */+ children: ComponentChildren;+ isSelecting: boolean;+ onToggleSelecting: () => void;+ /** How many cards are picked out. */+ count: number;+ /** Whether a column can be selected whole, which needs a picked card to name it. */+ canSelectColumn: boolean;+ onSelectColumn: () => void;+ /** Drops the selection and ends selection mode, the bar covering the button that started it. */+ onReset: () => void;+}++/**+ * The trailing end of the board's header: the grouping and the filter, and on mobile the button+ * that starts selection mode, where a tap picks a card out instead of opening it. While the mode+ * lasts a bar stands over all of it, with the count and what can be done with the selection.+ */+export default function BoardHeaderTools({+ children, isSelecting, onToggleSelecting, count, canSelectColumn, onSelectColumn, onReset+}: BoardHeaderToolsProps) {+ return (+ <div className="board-header-tools">+ {isMobile() && (+ <ActionButton+ className="board-selection-toggle"+ icon="bx bx-select-multiple"+ text={t("board_view.selection-mode")}+ active={isSelecting}+ noTooltipOnTouch+ onClick={onToggleSelecting}+ />+ )}+ {children}+ {isMobile() && isSelecting && (+ <div className="board-selection-bar" role="toolbar">+ <span className="board-selection-count">+ {t("board_view.cards-selected", { count })}+ </span>+ <ActionButton+ icon="bx bx-list-check"+ text={t("board_view.select-column-cards")}+ disabled={!canSelectColumn}+ noTooltipOnTouch+ onClick={onSelectColumn}+ />+ <ActionButton+ icon="bx bx-x"+ text={t("board_view.reset-selection")}+ noTooltipOnTouch+ onClick={onReset}+ />+ </div>+ )}+ </div>+ );+}