Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): restore mobile server rail drag (#646)

Generb38de538fc89
diff --git a/src/web/src/components/community/shell/rail-folder.tsx b/src/web/src/components/community/shell/rail-folder.tsx
index 44de602eb..357d35ebc 100644
--- a/src/web/src/components/community/shell/rail-folder.tsx
+++ b/src/web/src/components/community/shell/rail-folder.tsx
@@ -70,9 +70,9 @@ function RailFolderImpl({
aria-describedby={dragDescriptionId}
aria-keyshortcuts="Space ArrowUp ArrowDown Escape"
onClick={onToggle}
- className="group/folder grid size-11 cursor-pointer place-items-center focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none active:cursor-grabbing"
+ className="group/folder grid size-11 cursor-pointer place-items-center focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none active:cursor-grabbing [-webkit-touch-callout:none]"
>
- <span className={[
+ <span data-rail-drag-preview className={[
"pointer-events-none grid size-10 grid-cols-2 gap-1 p-2 transition-[border-radius,background-color] duration-150",
open ? "rounded-xl bg-primary/15" : "rounded-[18px] bg-accent group-hover/folder:rounded-xl group-hover/folder:bg-primary/20",
preview === "combine" ? "bg-primary/10 outline outline-2! outline-primary" : "",
diff --git a/src/web/src/components/community/shell/server-rail-pdd-contract.test.ts b/src/web/src/components/community/shell/server-rail-pdd-contract.test.ts
index 2c540a015..e5649df31 100644
--- a/src/web/src/components/community/shell/server-rail-pdd-contract.test.ts
+++ b/src/web/src/components/community/shell/server-rail-pdd-contract.test.ts
@@ -59,6 +59,9 @@ describe("server rail PDD component contract", () => {
expect(preArmScroll).toContain("clearTouch()")
expect(preArmScroll).not.toContain("preventDefault")
expect(adapter).toContain('addEventListener("touchstart", onTouchStart, { passive: true })')
+ expect(adapter).toContain('element.addEventListener("touchstart", suppressTouchMenu, { passive: true })')
+ expect(adapter).toContain('dragHandle.addEventListener("touchstart", suppressTouchMenu, { passive: true })')
+ expect(adapter).toContain("event.stopPropagation()")
expect(adapter).toContain("event.preventDefault()")
expect(adapter).toContain('addEventListener("touchmove", onTouchMove, { passive: false })')
expect(adapter).toContain('addEventListener("touchend", onTouchEnd, { passive: false })')
@@ -67,7 +70,16 @@ describe("server rail PDD component contract", () => {
expect(adapter).toContain('addEventListener("scroll", cancelPendingTouchForNativeScroll')
expect(server).not.toContain("touch-none")
expect(folder).not.toContain("touch-none")
+ expect(server).toContain("[-webkit-touch-callout:none]")
+ expect(folder).toContain("[-webkit-touch-callout:none]")
+ expect(server).toContain("data-rail-drag-preview")
+ expect(folder).toContain("data-rail-drag-preview")
+ expect(adapter).toContain("data-rail-floating-preview")
+ expect(adapter).toContain("positionTouchDragPreview")
+ expect(adapter).toContain("document.body.appendChild(element)")
expect(adapter).toContain("requestAnimationFrame(runTouchFrame)")
+ expect(adapter).toContain('begin(entity, "touch")')
+ expect(adapter).not.toContain('new MouseEvent("contextmenu"')
expect(adapter).not.toContain("matchMedia")
expect(rail).toContain("Press Space to pick up a server or group")
expect(rail).toContain("onAnnounce: announce")
diff --git a/src/web/src/components/community/shell/sortable-server.focus.test.ts b/src/web/src/components/community/shell/sortable-server.focus.test.ts
index 97cdeadfa..611af2475 100644
--- a/src/web/src/components/community/shell/sortable-server.focus.test.ts
+++ b/src/web/src/components/community/shell/sortable-server.focus.test.ts
@@ -2,6 +2,7 @@ import { createElement, Fragment, type ReactNode } from "react"
import TestRenderer, { act } from "react-test-renderer"
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
import { SortableServer } from "./sortable-server"
+import { tid } from "@/lib/community/testids"
vi.mock("@/components/ui/context-menu", () => ({
ContextMenu: ({ children }: { children: ReactNode }) => createElement(Fragment, null, children),
@@ -31,10 +32,10 @@ const server = {
mentions: 0,
}
-function renderServer(active = false) {
+function renderServer(active = false, mentions = 0) {
const buttonNodes: Array<{ focus: ReturnType<typeof vi.fn> }> = []
const renderer = TestRenderer.create(createElement(SortableServer, {
- server,
+ server: { ...server, mentions },
active,
onClick: vi.fn(),
dragDescriptionId: "rail-help",
@@ -98,4 +99,20 @@ describe("SortableServer lazy menu focus", () => {
expect(active.renderer.root.findByType("button").props.className).toContain("cursor-default")
expect(inactive.renderer.root.findByType("button").props.className).toContain("cursor-pointer")
})
+
+ it("stacks the numeric mention badge above the icon without changing its presentation", async () => {
+ let result!: ReturnType<typeof renderServer>
+ await act(async () => { result = renderServer(false, 12) })
+
+ const button = result.renderer.root.findByType("button")
+ const badge = result.renderer.root.findByProps({ "data-testid": tid.railUnreadBadge("a") })
+ const dragPreview = result.renderer.root.findByProps({ "data-rail-drag-preview": true })
+ expect(button.props.className).toContain("z-1")
+ expect(badge.props.className).toContain("z-2")
+ expect(badge.props.className).toContain("bg-primary")
+ expect(badge.props.className).toContain("min-w-5")
+ expect(badge.props.className).toContain("px-1")
+ expect(dragPreview.props.className).toContain("size-10")
+ expect(dragPreview.findAllByProps({ "data-testid": tid.railUnreadBadge("a") })).toHaveLength(0)
+ })
})
diff --git a/src/web/src/components/community/shell/sortable-server.tsx b/src/web/src/components/community/shell/sortable-server.tsx
index 030d82b30..0b9728ccf 100644
--- a/src/web/src/components/community/shell/sortable-server.tsx
+++ b/src/web/src/components/community/shell/sortable-server.tsx
@@ -128,11 +128,11 @@ function SortableServerImpl({
aria-keyshortcuts="Space ArrowUp ArrowDown ArrowLeft ArrowRight Escape"
onClick={active ? undefined : onClick}
className={[
- "group/server absolute left-1/2 top-1/2 z-1 grid size-11 -translate-x-1/2 -translate-y-1/2 place-items-center focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none active:cursor-grabbing",
+ "group/server absolute left-1/2 top-1/2 z-1 grid size-11 -translate-x-1/2 -translate-y-1/2 place-items-center focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none active:cursor-grabbing [-webkit-touch-callout:none]",
active ? "cursor-default" : "cursor-pointer",
].join(" ")}
>
- <span className={[
+ <span data-rail-drag-preview className={[
"pointer-events-none relative grid size-10 place-items-center overflow-hidden font-brand text-xl font-bold transition-all duration-150",
active
? "cursor-default rounded-xl"
@@ -163,7 +163,7 @@ function SortableServerImpl({
{server.mentions > 0 && (
<span
data-testid={tid.railUnreadBadge(server.id)}
- className="pointer-events-none absolute -bottom-1 -right-1 grid h-5 min-w-5 place-items-center rounded-full bg-primary px-1 text-[11px] font-bold text-primary-foreground ring-2 ring-(--d-rail)"
+ className="pointer-events-none absolute -bottom-1 -right-1 z-2 grid h-5 min-w-5 place-items-center rounded-full bg-primary px-1 text-[11px] font-bold text-primary-foreground ring-2 ring-(--d-rail)"
>
<NumberTicker value={server.mentions} />
</span>
diff --git a/src/web/src/components/community/shell/use-server-rail-pdd.behavior.test.ts b/src/web/src/components/community/shell/use-server-rail-pdd.behavior.test.ts
index 1bd5cf6cd..6da135286 100644
--- a/src/web/src/components/community/shell/use-server-rail-pdd.behavior.test.ts
+++ b/src/web/src/components/community/shell/use-server-rail-pdd.behavior.test.ts
@@ -114,6 +114,11 @@ class FakeElement extends FakeEventTarget {
isConnected = true
clickCount = 0
lastClickEvent: FakeMouseEvent | null = null
+ dragPreview: FakeElement | null = null
+ cloneCount = 0
+ removed = false
+ readonly style: Record<string, string> = {}
+ readonly attributes = new Map<string, string>()
readonly focus = vi.fn()
constructor(public bounds: Rect) {
@@ -122,6 +127,21 @@ class FakeElement extends FakeEventTarget {
getBoundingClientRect() { return this.bounds }
+ querySelector(selector: string) {
+ return selector === "[data-rail-drag-preview]" ? this.dragPreview : null
+ }
+
+ cloneNode() {
+ this.cloneCount += 1
+ const clone = new FakeElement({ ...this.bounds })
+ for (const [name, value] of this.attributes) clone.attributes.set(name, value)
+ return clone
+ }
+
+ setAttribute(name: string, value: string) { this.attributes.set(name, value) }
+ removeAttribute(name: string) { this.attributes.delete(name) }
+ remove() { this.removed = true }
+
click() {
this.clickCount += 1
this.lastClickEvent = new FakeMouseEvent("click")
@@ -134,6 +154,22 @@ class FakeDocument extends FakeEventTarget {
points: FakeElement[] = []
readonly documentElement = { style: { userSelect: "text" } }
readonly removeAllRanges = vi.fn()
+ readonly body: {
+ children: FakeElement[]
+ appendChild: ReturnType<typeof vi.fn>
+ }
+
+ constructor() {
+ super()
+ const children: FakeElement[] = []
+ this.body = {
+ children,
+ appendChild: vi.fn((element: FakeElement) => {
+ children.push(element)
+ return element
+ }),
+ }
+ }
elementsFromPoint() { return this.points }
getSelection() { return { removeAllRanges: this.removeAllRanges } }
@@ -243,12 +279,15 @@ function register(
) {
const element = new FakeElement(bounds)
const handle = new FakeElement(bounds)
+ const dragPreview = new FakeElement(rect(0, 40, 0, 40))
+ dragPreview.setAttribute("data-rail-drag-preview", "")
+ handle.dragPreview = dragPreview
const cleanup = api.registerItem(
entity,
element as unknown as HTMLElement,
handle as unknown as HTMLElement,
)
- return { entity, element, handle, cleanup }
+ return { entity, element, handle, dragPreview, cleanup }
}
function point(identifier: number, clientX: number, clientY: number) {
@@ -485,8 +524,13 @@ describe("useServerRailPdd behavior", () => {
it("separates taps, scroll, context menu, multi-touch, and cancellation", async () => {
const hook = await renderHook()
const a = register(hook.current, { kind: "server", id: "a" }, rect(0, 40))
+ const desktopContext = a.handle.dispatch("contextmenu", testEvent("contextmenu"))
+ expect(desktopContext.defaultPrevented).toBe(false)
+ expect(desktopContext.propagationStopped).toBe(false)
- touch(a.handle, "touchstart", [point(1, 10, 10)])
+ const tapStart = touch(a.handle, "touchstart", [point(1, 10, 10)])
+ expect(tapStart.defaultPrevented).toBe(false)
+ expect(tapStart.propagationStopped).toBe(true)
const tapEnd = touch(a.handle, "touchend", [], [point(1, 10, 10)])
expect(tapEnd.defaultPrevented).toBe(true)
expect(a.handle.clickCount).toBe(1)
@@ -512,25 +556,50 @@ describe("useServerRailPdd behavior", () => {
touch(a.handle, "touchstart", [point(8, 10, 10)])
touch(a.handle, "touchcancel", [])
+ const dragStartCount = hook.callbacks.onDragStart.mock.calls.length
touch(a.handle, "touchstart", [point(9, 10, 10)])
- await act(async () => vi.advanceTimersByTime(650))
- a.handle.click()
- expect(a.handle.lastClickEvent?.defaultPrevented).toBe(true)
- expect(a.handle.lastClickEvent?.propagationStopped).toBe(true)
-
- touch(a.handle, "touchstart", [point(10, 10, 10)])
- await act(async () => vi.advanceTimersByTime(SERVER_RAIL_TOUCH_HOLD_MS))
+ await act(async () => vi.advanceTimersByTime(SERVER_RAIL_TOUCH_HOLD_MS - 1))
+ expect(hook.callbacks.onDragStart).toHaveBeenCalledTimes(dragStartCount)
+ expect(fakeDocument.body.children).toHaveLength(0)
+ const context = a.handle.dispatch("contextmenu", testEvent("contextmenu"))
+ expect(context.defaultPrevented).toBe(true)
+ expect(context.propagationStopped).toBe(true)
+ await act(async () => vi.advanceTimersByTime(1))
+ expect(hook.callbacks.onDragStart).toHaveBeenCalledTimes(dragStartCount + 1)
+ expect(hook.callbacks.onDragStart).toHaveBeenLastCalledWith(a.entity)
+ expect(fakeDocument.documentElement.style.userSelect).toBe("none")
+ const floating = fakeDocument.body.children.at(-1)!
+ expect(a.dragPreview.cloneCount).toBe(1)
+ expect(floating.attributes.get("data-rail-floating-preview")).toBe("server")
+ expect(floating.attributes.get("aria-hidden")).toBe("true")
+ expect(floating.attributes.has("data-rail-drag-preview")).toBe(false)
+ expect(floating.style.width).toBe("40px")
+ expect(floating.style.height).toBe("40px")
+ expect(floating.style.pointerEvents).toBe("none")
+ expect(floating.style.transform).toBe("translate3d(-10px, -10px, 0)")
+ const dragMove = touch(a.handle, "touchmove", [point(9, 30, 50)])
+ expect(dragMove.defaultPrevented).toBe(true)
+ expect(floating.style.transform).toBe("translate3d(10px, 30px, 0)")
const clickCount = a.handle.clickCount
- touch(a.handle, "touchend", [], [point(10, 10, 10)])
+ touch(a.handle, "touchend", [], [point(9, 30, 50)])
expect(a.handle.clickCount).toBe(clickCount)
+ expect(floating.removed).toBe(true)
+ expect(fakeDocument.documentElement.style.userSelect).toBe("text")
a.handle.click()
expect(a.handle.lastClickEvent?.defaultPrevented).toBe(true)
+ expect(a.handle.lastClickEvent?.propagationStopped).toBe(true)
+
+ const triggerTouch = a.element.dispatch(
+ "touchstart",
+ testEvent("touchstart", { touches: [point(90, 10, 10)] }),
+ )
+ expect(triggerTouch.defaultPrevented).toBe(false)
+ expect(triggerTouch.propagationStopped).toBe(true)
hook.callbacks.canStart.mockReturnValueOnce(true)
- touch(a.handle, "touchstart", [point(11, 10, 10)])
- await act(async () => vi.advanceTimersByTime(SERVER_RAIL_TOUCH_HOLD_MS))
+ touch(a.handle, "touchstart", [point(10, 10, 10)])
hook.callbacks.canStart.mockReturnValue(false)
- touch(a.handle, "touchmove", [point(11, 10, 30)])
+ await act(async () => vi.advanceTimersByTime(SERVER_RAIL_TOUCH_HOLD_MS))
expect(hook.callbacks.onAnnounce).toHaveBeenCalledWith(
"A server rail move is already being saved",
)
@@ -555,9 +624,15 @@ describe("useServerRailPdd behavior", () => {
) {
touch(source.handle, "touchstart", [point(identifier, 20, startY)])
await act(async () => vi.advanceTimersByTime(SERVER_RAIL_TOUCH_HOLD_MS))
+ const floating = fakeDocument.body.children.at(-1)!
+ expect(floating.attributes.get("data-rail-floating-preview")).toBe(source.entity.kind)
+ expect(floating.style.width).toBe("40px")
+ expect(floating.style.height).toBe("40px")
+ expect(floating.style.transform).toBe(`translate3d(0px, ${startY - 20}px, 0)`)
fakeDocument.points = [target.element]
const move = touch(source.handle, "touchmove", [point(identifier, 20, endY)])
expect(move.defaultPrevented).toBe(true)
+ expect(floating.style.transform).toBe(`translate3d(0px, ${endY - 20}px, 0)`)
touch(source.handle, "touchmove", [point(identifier, 20, endY)])
flushAnimationFrame()
touch(
@@ -566,6 +641,7 @@ describe("useServerRailPdd behavior", () => {
[],
includeChangedTouch ? [point(identifier, 20, endY)] : [],
)
+ expect(floating.removed).toBe(true)
}
await drag(b, a, 1, 100, 5)
diff --git a/src/web/src/components/community/shell/use-server-rail-pdd.test.ts b/src/web/src/components/community/shell/use-server-rail-pdd.test.ts
index 0ef21c425..c87388b5f 100644
--- a/src/web/src/components/community/shell/use-server-rail-pdd.test.ts
+++ b/src/web/src/components/community/shell/use-server-rail-pdd.test.ts
@@ -51,31 +51,21 @@ describe("server rail PDD record adapter", () => {
expect(SERVER_RAIL_TOUCH_HOLD_MS).toBe(450)
expect(SERVER_RAIL_TOUCH_DRIFT_PX).toBe(10)
expect(railTouchMoveIntent({
- armed: false,
dragging: false,
distance: 10,
touchCount: 1,
})).toBe("wait")
expect(railTouchMoveIntent({
- armed: false,
dragging: false,
distance: 10.1,
touchCount: 1,
})).toBe("scroll")
expect(railTouchMoveIntent({
- armed: true,
- dragging: false,
- distance: 10.1,
- touchCount: 1,
- })).toBe("start-drag")
- expect(railTouchMoveIntent({
- armed: true,
dragging: true,
distance: 30,
touchCount: 1,
})).toBe("drag")
expect(railTouchMoveIntent({
- armed: true,
dragging: true,
distance: 30,
touchCount: 2,
diff --git a/src/web/src/components/community/shell/use-server-rail-pdd.ts b/src/web/src/components/community/shell/use-server-rail-pdd.ts
index 1481c6fac..f640c7aaa 100644
--- a/src/web/src/components/community/shell/use-server-rail-pdd.ts
+++ b/src/web/src/components/community/shell/use-server-rail-pdd.ts
@@ -25,22 +25,65 @@ type RailData = Record<string | symbol, unknown>
export const SERVER_RAIL_TOUCH_HOLD_MS = 450
export const SERVER_RAIL_TOUCH_DRIFT_PX = 10
+const TOUCH_DRAG_PREVIEW_SELECTOR = "[data-rail-drag-preview]"
+
+type TouchDragPreview = {
+ element: HTMLElement
+ width: number
+ height: number
+}
+
+function positionTouchDragPreview(
+ preview: TouchDragPreview,
+ clientX: number,
+ clientY: number,
+) {
+ preview.element.style.transform = `translate3d(${clientX - preview.width / 2}px, ${clientY - preview.height / 2}px, 0)`
+}
+
+function createTouchDragPreview(
+ dragHandle: HTMLElement,
+ entity: RailEntity,
+ clientX: number,
+ clientY: number,
+): TouchDragPreview | null {
+ const source = dragHandle.querySelector<HTMLElement>(TOUCH_DRAG_PREVIEW_SELECTOR)
+ if (!source) return null
+ const rect = source.getBoundingClientRect()
+ const element = source.cloneNode(true) as HTMLElement
+ element.removeAttribute("data-rail-drag-preview")
+ element.setAttribute("data-rail-floating-preview", entity.kind)
+ element.setAttribute("aria-hidden", "true")
+ Object.assign(element.style, {
+ position: "fixed",
+ left: "0",
+ top: "0",
+ zIndex: "100",
+ width: `${rect.width}px`,
+ height: `${rect.height}px`,
+ margin: "0",
+ pointerEvents: "none",
+ transition: "none",
+ willChange: "transform",
+ })
+ const preview = { element, width: rect.width, height: rect.height }
+ positionTouchDragPreview(preview, clientX, clientY)
+ document.body.appendChild(element)
+ return preview
+}
export function railTouchMoveIntent({
- armed,
dragging,
distance,
touchCount,
}: {
- armed: boolean
dragging: boolean
distance: number
touchCount: number
-}): "wait" | "scroll" | "start-drag" | "drag" | "cancel" {
+}): "wait" | "scroll" | "drag" | "cancel" {
if (touchCount !== 1) return "cancel"
if (dragging) return "drag"
- if (!armed) return distance > SERVER_RAIL_TOUCH_DRIFT_PX ? "scroll" : "wait"
- return distance > SERVER_RAIL_TOUCH_DRIFT_PX ? "start-drag" : "wait"
+ return distance > SERVER_RAIL_TOUCH_DRIFT_PX ? "scroll" : "wait"
}
function sameEntity(left: RailEntity | null, right: RailEntity | null): boolean {
@@ -147,11 +190,10 @@ export function useServerRailPdd({
startY: number
clientX: number
clientY: number
- armed: boolean
dragging: boolean
timer: ReturnType<typeof setTimeout> | null
- contextTimer: ReturnType<typeof setTimeout> | null
frame: number | null
+ preview: TouchDragPreview | null
} | null>(null)
const clearHover = useCallback(() => {
@@ -189,8 +231,8 @@ export function useServerRailPdd({
const clearTouch = useCallback(() => {
const touch = touchRef.current
if (touch?.timer) clearTimeout(touch.timer)
- if (touch?.contextTimer) clearTimeout(touch.contextTimer)
if (touch?.frame !== null && touch?.frame !== undefined) cancelAnimationFrame(touch.frame)
+ touch?.preview?.element.remove()
touchRef.current = null
restoreSelection()
}, [restoreSelection])
@@ -396,6 +438,12 @@ export function useServerRailPdd({
),
})
+ const suppressTouchMenu = (event: TouchEvent) => {
+ // Base UI owns a separate 500 ms touch timer on ContextMenuTrigger.
+ // Keep the event native (and therefore scrollable), but do not let it
+ // reach that trigger: the rail's 450 ms hold is exclusively drag pickup.
+ event.stopPropagation()
+ }
const onTouchStart = (event: TouchEvent) => {
if (event.touches.length !== 1) {
if (touchRef.current || activeRef.current?.sensor === "touch") cancelActive()
@@ -412,28 +460,30 @@ export function useServerRailPdd({
startY: touch.clientY,
clientX: touch.clientX,
clientY: touch.clientY,
- armed: false,
dragging: false,
timer: null as ReturnType<typeof setTimeout> | null,
- contextTimer: null as ReturnType<typeof setTimeout> | null,
frame: null as number | null,
+ preview: null as TouchDragPreview | null,
}
pending.timer = setTimeout(() => {
- if (touchRef.current === pending) {
- pending.armed = true
- pending.timer = null
+ if (touchRef.current !== pending) return
+ pending.timer = null
+ if (!begin(entity, "touch")) {
+ clearTouch()
+ return
}
+ pending.dragging = true
+ pending.preview = createTouchDragPreview(
+ dragHandle,
+ entity,
+ pending.clientX,
+ pending.clientY,
+ )
+ selectionStyleRef.current = document.documentElement.style.userSelect
+ document.documentElement.style.userSelect = "none"
+ document.getSelection()?.removeAllRanges()
+ pending.frame = requestAnimationFrame(runTouchFrame)
}, SERVER_RAIL_TOUCH_HOLD_MS)
- pending.contextTimer = setTimeout(() => {
- if (touchRef.current !== pending || pending.dragging) return
- dragHandle.dispatchEvent(new MouseEvent("contextmenu", {
- bubbles: true,
- cancelable: true,
- button: 2,
- clientX: pending.clientX,
- clientY: pending.clientY,
- }))
- }, 650)
touchRef.current = pending
}
const onTouchMove = (event: TouchEvent) => {
@@ -450,9 +500,11 @@ export function useServerRailPdd({
}
pending.clientX = touch.clientX
pending.clientY = touch.clientY
+ if (pending.preview) {
+ positionTouchDragPreview(pending.preview, touch.clientX, touch.clientY)
+ }
const exactDistance = Math.hypot(touch.clientX - pending.startX, touch.clientY - pending.startY)
const exactIntent = railTouchMoveIntent({
- armed: pending.armed,
dragging: pending.dragging,
distance: exactDistance,
touchCount: event.touches.length,
@@ -462,19 +514,6 @@ export function useServerRailPdd({
return
}
if (exactIntent === "wait") return
- if (exactIntent === "start-drag") {
- if (!begin(entity, "touch")) {
- clearTouch()
- return
- }
- if (pending.contextTimer) clearTimeout(pending.contextTimer)
- pending.contextTimer = null
- pending.dragging = true
- selectionStyleRef.current = document.documentElement.style.userSelect
- document.documentElement.style.userSelect = "none"
- document.getSelection()?.removeAllRanges()
- pending.frame = requestAnimationFrame(runTouchFrame)
- }
event.preventDefault()
setPreview(itemAtPoint(entity, touch.clientX, touch.clientY))
}
@@ -489,22 +528,23 @@ export function useServerRailPdd({
suppressClickUntilRef.current = Date.now() + 800
finishDrop(itemAtPoint(entity, clientX, clientY))
} else {
- const shouldClick = !pending.armed
- if (shouldClick) event.preventDefault()
- else suppressClickUntilRef.current = Date.now() + 800
+ event.preventDefault()
clearTouch()
- if (shouldClick) dragHandle.click()
+ dragHandle.click()
}
}
const onTouchCancel = () => cancelActive()
const onContextMenu = (event: MouseEvent) => {
const pending = touchRef.current
- if (pending && sameEntity(pending.entity, entity) && !pending.dragging) {
+ if (
+ (pending && sameEntity(pending.entity, entity))
+ || (activeRef.current?.sensor === "touch" && sameEntity(activeRef.current.source, entity))
+ || Date.now() < suppressClickUntilRef.current
+ ) {
+ event.preventDefault()
+ event.stopPropagation()
suppressClickUntilRef.current = Date.now() + 800
- clearTouch()
- return
}
- if (activeRef.current?.sensor === "touch") event.preventDefault()
}
const onClickCapture = (event: MouseEvent) => {
if (Date.now() >= suppressClickUntilRef.current) return
@@ -526,6 +566,8 @@ export function useServerRailPdd({
if (active.sensor !== "keyboard" || !sameEntity(active.source, entity)) return
handleKeyboardCommand(event, entity)
}
+ element.addEventListener("touchstart", suppressTouchMenu, { passive: true })
+ dragHandle.addEventListener("touchstart", suppressTouchMenu, { passive: true })
dragHandle.addEventListener("touchstart", onTouchStart, { passive: true })
dragHandle.addEventListener("touchmove", onTouchMove, { passive: false })
dragHandle.addEventListener("touchend", onTouchEnd, { passive: false })
@@ -534,6 +576,8 @@ export function useServerRailPdd({
dragHandle.addEventListener("click", onClickCapture, true)
dragHandle.addEventListener("keydown", onKeyDown)
return () => {
+ element.removeEventListener("touchstart", suppressTouchMenu)
+ dragHandle.removeEventListener("touchstart", suppressTouchMenu)
dragHandle.removeEventListener("touchstart", onTouchStart)
dragHandle.removeEventListener("touchmove", onTouchMove)
dragHandle.removeEventListener("touchend", onTouchEnd)
diff --git a/src/web/src/test/e2e-ui/37-server-rail-pdd.spec.ts b/src/web/src/test/e2e-ui/37-server-rail-pdd.spec.ts
index f3e37e7e2..5bf82af3c 100644
--- a/src/web/src/test/e2e-ui/37-server-rail-pdd.spec.ts
+++ b/src/web/src/test/e2e-ui/37-server-rail-pdd.spec.ts
@@ -93,6 +93,10 @@ async function dispatchTouchGesture(
if (holdMs > 0) await page.waitForTimeout(holdMs)
let sawDragging = false
let sawPreview = false
+ let sawFloatingPreview = false
+ let sawFloatingPreviewFollowTouch = false
+ let floatingPreviewKind: string | null = null
+ let floatingPreviewSize: { width: number; height: number } | null = null
let capturedPreview = false
let currentEnd = end
for (let step = 1; step <= 8; step += 1) {
@@ -106,11 +110,25 @@ async function dispatchTouchGesture(
}
}
}
- await dispatch("touchmove", {
+ const currentPoint = {
x: start.x + (currentEnd.x - start.x) * ratio,
y: start.y + (currentEnd.y - start.y) * ratio,
- })
+ }
+ await dispatch("touchmove", currentPoint)
await page.waitForTimeout(20)
+ const floatingPreview = page.locator("[data-rail-floating-preview]")
+ if (await floatingPreview.count() === 1) {
+ sawFloatingPreview = true
+ floatingPreviewKind = await floatingPreview.getAttribute("data-rail-floating-preview")
+ const box = await floatingPreview.boundingBox()
+ if (box) {
+ floatingPreviewSize = { width: box.width, height: box.height }
+ sawFloatingPreviewFollowTouch ||= (
+ Math.abs(box.x + box.width / 2 - currentPoint.x) <= 0.5
+ && Math.abs(box.y + box.height / 2 - currentPoint.y) <= 0.5
+ )
+ }
+ }
if (probe) {
sawDragging ||= await probe.source.getAttribute("data-dragging") === "true"
sawPreview ||= await probe.target.getAttribute("data-rail-preview") !== null
@@ -122,10 +140,15 @@ async function dispatchTouchGesture(
}
await dispatch("touchend", currentEnd)
await page.waitForTimeout(20)
+ await expect(page.locator("[data-rail-floating-preview]")).toHaveCount(0)
return {
events: await page.evaluate(() => Reflect.get(window, "__railTouchEvents") as string[]),
sawDragging,
sawPreview,
+ sawFloatingPreview,
+ sawFloatingPreviewFollowTouch,
+ floatingPreviewKind,
+ floatingPreviewSize,
}
}
@@ -205,6 +228,13 @@ async function touchDrag(
targetRatio,
previewScreenshotPath,
)
+ const expectedPreviewKind = sourceTestId?.startsWith(tid.serverRailFolder(""))
+ ? "folder"
+ : "server"
+ expect(result.sawFloatingPreview).toBe(true)
+ expect(result.sawFloatingPreviewFollowTouch).toBe(true)
+ expect(result.floatingPreviewKind).toBe(expectedPreviewKind)
+ expect(result.floatingPreviewSize).toEqual({ width: 40, height: 40 })
return { ...result, sourceTestId }
}
@@ -492,14 +522,17 @@ test("server rail keeps scroll separate from native, touch, and keyboard drag",
const beforeLongPress = railRequests.length
await firstFolder.scrollIntoViewIfNeeded()
const endLongPress = await startStationaryTouch(page, firstFolder)
+ await expect(firstFolder).toHaveAttribute("data-dragging", "true")
+ const stationaryFolderPreview = page.locator('[data-rail-floating-preview="folder"]')
+ await expect(stationaryFolderPreview).toHaveCount(1)
+ expect(await stationaryFolderPreview.boundingBox()).toMatchObject({ width: 40, height: 40 })
await page.waitForTimeout(700)
- await expect(page.getByRole("menuitem", { name: "Ungroup" })).toBeVisible()
+ await expect(page.getByRole("menuitem", { name: "Ungroup" })).toHaveCount(0)
await expect(page.getByRole("menuitem", { name: "Move…" })).toHaveCount(0)
await expect(page.getByRole("menuitem", { name: "Create group" })).toHaveCount(0)
await endLongPress()
+ await expect(stationaryFolderPreview).toHaveCount(0)
expect(railRequests).toHaveLength(beforeLongPress)
- await page.keyboard.press("Escape")
- await expect(page.getByRole("menuitem", { name: "Ungroup" })).toHaveCount(0)
await page.getByTestId(tid.serverIcon(tail)).scrollIntoViewIfNeeded()
await expect.poll(async () => (await railGeometry(page, tail)).targetOwnsCenter)
.toBe(true)