mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
fix(bases): widen kanban auto-scroll hitbox and allow cursor overflow
This commit is contained in:
@@ -1,17 +1,41 @@
|
|||||||
import { useEffect, RefObject } from "react";
|
import { useEffect, RefObject } from "react";
|
||||||
|
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
||||||
import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
|
import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
|
||||||
|
import { unsafeOverflowAutoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element";
|
||||||
|
|
||||||
|
type CanScrollArgs = {
|
||||||
|
source: { data: Record<string, unknown> };
|
||||||
|
};
|
||||||
|
|
||||||
|
// How far past each edge the cursor can roam and still drive scroll.
|
||||||
|
// 120px gives users a generous "drag past the column" affordance before
|
||||||
|
// scrolling stops — matches what other kanbans (Linear, Notion) do.
|
||||||
|
const OVERFLOW_PX = 120;
|
||||||
|
|
||||||
export function useKanbanAutoScroll(
|
export function useKanbanAutoScroll(
|
||||||
ref: RefObject<HTMLElement | null>,
|
ref: RefObject<HTMLElement | null>,
|
||||||
canScroll: ({
|
canScroll: (args: CanScrollArgs) => boolean = () => true,
|
||||||
source,
|
|
||||||
}: {
|
|
||||||
source: { data: Record<string, unknown> };
|
|
||||||
}) => boolean = () => true,
|
|
||||||
) {
|
) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const el = ref.current;
|
const el = ref.current;
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
return autoScrollForElements({ element: el, canScroll });
|
return combine(
|
||||||
|
autoScrollForElements({
|
||||||
|
element: el,
|
||||||
|
canScroll,
|
||||||
|
getConfiguration: () => ({ maxScrollSpeed: "fast" }),
|
||||||
|
}),
|
||||||
|
unsafeOverflowAutoScrollForElements({
|
||||||
|
element: el,
|
||||||
|
canScroll,
|
||||||
|
getConfiguration: () => ({ maxScrollSpeed: "fast" }),
|
||||||
|
getOverflow: () => ({
|
||||||
|
forTopEdge: { top: OVERFLOW_PX },
|
||||||
|
forBottomEdge: { bottom: OVERFLOW_PX },
|
||||||
|
forLeftEdge: { left: OVERFLOW_PX },
|
||||||
|
forRightEdge: { right: OVERFLOW_PX },
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
}, [ref, canScroll]);
|
}, [ref, canScroll]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user