Skip to content

Commit 06b7e61

Browse files
authored
feat(core): the shared drag path takes a component's own drag (#9720)
* feat(core): the shared drag path takes a component's own drag The public pan and snap-point drag keep their behavior (spec:AST-107 FR1, FR2). They now run on internal factories that a Core component can use for a job the public layer does not expose (spec:AST-107 FR7): - createPan, under createPanGesture: the recognizer's own options (which pointers and scrolls start the drag, its claim distance, a begin gate, a selection lock), and what drove the drag and its travel from where the touch began in each report. - createSnapDrag, under createDragToSnapPoints: a model of where a drag draws its element (one for one, a spring, or nothing yet inside a dead zone, the first target catching a settle in flight) and where a release or a cancel lands; a custom property an x drag draws into (a y drag that asks for one warns); settleTo with a spring, a velocity and a touch release, returning the settle's motion; and an onPass callback on the first frame the settle's curve passes an offset (no timer). - The animator draws x into a registered custom property (a length or a number), on the main thread, for a component whose parts all read one value, with an optional companion property drawn from x in the same keyframes. Those keyframes are never shared with another call's. architecture:react-component-runtime INV13 names these jobs among the known public-API gaps, and spec:AST-107's path applicability links the two internal factories. * refactor(core): createPan and createSnapDrag live in the public modules createPan moves into createPanGesture.ts, and createSnapDrag into createDragToSnapPoints.ts, as internal named exports beside the public factories. No package entry exports them, and no behavior changes. The animator registers a custom property with no state of its own. It catches only a second registration's InvalidModificationError, and throws any other error. The change gains its changeset, an internal chore: Core ships it, and no consumer sees it. * docs(AST-107): name the internal pan and snap-point drag FR7 names createPan and createSnapDrag and the modules that hold them. The path list follows them into those modules. * docs(AST-107): say what the internal pan and snap-point drag add FR7 says what each internal takes that its public factory does not. createPan takes the recognizer's own options and reports the claim's travel and the input; createPanGesture starts on every pointer and no scroll. createSnapDrag takes a model, the pan's options and a custom property; createDragToSnapPoints keeps Core's one release policy. * Merge main * Merge main
1 parent a4fe015 commit 06b7e61

9 files changed

Lines changed: 1410 additions & 197 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[chore] Internal: a Core component's own drag runs on the shared drag path. `createPan` and `createSnapDrag` take a begin gate, a drag model and a custom property to draw into, beside the public `createPanGesture` and `createDragToSnapPoints`. The animator draws `x` into a registered custom property. Not exported from the package entry point.
6+
7+
@vjeux

‎docs/architecture/react-component-runtime.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,13 @@ those contracts.
311311
(`spec:AST-105` FR1); a pull that a scroll area hands over only at its
312312
edge (`spec:AST-094` FR14, FR19); a snap-point drag whose release can
313313
dismiss its surface, judged by the use's measured projection (`spec:AST-094`
314-
FR36); a drag on one element that moves another (a sheet's handle and
314+
FR36); a drag's own pointer and scroll filter, claim distance and begin
315+
gate, and a snap-point drag's own model of where a drag draws its element
316+
and where a release lands (a row's swipe: no mouse drag, UIKit's dead zone,
317+
tracking spring and release rule for a finger, and a full swipe reached by
318+
position only, `spec:AST-057` AR2, FR5); a drag drawn into one custom
319+
property that every part of its component reads (`spec:AST-057` FR2); a
320+
drag on one element that moves another (a sheet's handle and
315321
scrolling body move the sheet; its dim is the layer runtime's backdrop
316322
tint, `architecture:layer-runtime` INV14); the animator's jobs beyond the
317323
public handle: a motion role other than `springs.stateChange`

‎docs/specs/AST-107-public-gesture-hooks/spec.md‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ affects_consumer_docs:
3333

3434
```json
3535
{
36-
"paths": ["packages/core/src/hooks/**"]
36+
"paths": [
37+
"packages/core/src/hooks/**",
38+
"packages/core/src/dragToSnapPoints/createDragToSnapPoints.ts",
39+
"packages/core/src/gestures/createPanGesture.ts"
40+
]
3741
}
3842
```
3943

@@ -182,7 +186,18 @@ onSettle}) → {settleTo(index), destroy}`, and `createAnimator(element) →
182186
only for a job the public layer does not expose; those jobs are listed as
183187
known public-API gaps in `architecture:react-component-runtime` INV13.
184188
`createReorderable`'s plain-element attach path (`spec:AST-103`) covers
185-
collections that are not List.
189+
collections that are not List. The internals beneath the public pan and
190+
snap-point drag are `createPan`, in `createPanGesture.ts`, and
191+
`createSnapDrag`, in `createDragToSnapPoints.ts`. No package entry exports
192+
them. `createPan` takes the recognizer's own options: which pointers and
193+
scrolls start the drag, its claim distance and a gate on its begin. Its
194+
reports add the claim's travel and what drives the drag. `createPanGesture`
195+
has none of these: it starts on every pointer and no scroll.
196+
`createSnapDrag` takes a model of where a drag draws its element and where
197+
a release lands. It also takes the pan's own options and draws into a
198+
custom property when given one. `createDragToSnapPoints` has neither: it
199+
follows the finger one for one, draws `translate`, and lands each release
200+
by Core's one release policy.
186201

187202
- **FR8 — A headless context menu.** `createContextMenu(element, {items | render, label?, isDisabled?,
188203
onOpenChange?, presentation?}) → {open(at?), close(), destroy()}`

‎packages/core/src/dragToSnapPoints/createDragToSnapPoints.reducedMotion.test.ts‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
/**
44
* @file createDragToSnapPoints.reducedMotion.test.ts
55
* @input vitest (jsdom, fake clock) and a recording stand-in for
6-
* Element.animate. A stand-in for the public pan hands its events to the
7-
* test, with Reduce Motion on and a fine primary pointer.
6+
* Element.animate. A stand-in for the drag's pan (createPan, gestures/createPanGesture.ts)
7+
* hands its events to the test. Each event names the input that drives
8+
* it. Reduce Motion is on, with a fine primary pointer.
89
* @output Checks `design:reduced-motion` DR2 and DR3 for the snap-point
910
* drag's release. A touch drag's release cross-fades into the snap point.
1011
* A mouse or pen drag's release lands at once, and so does `settleTo` on a
@@ -13,15 +14,12 @@
1314
*/
1415

1516
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
16-
import type {
17-
PanGestureEvent,
18-
PanGestureOptions,
19-
} from '../gestures/createPanGesture';
17+
import type {PanEvent, PanOptions} from '../gestures/createPanGesture';
2018

21-
let onPan: ((event: PanGestureEvent) => void) | null = null;
19+
let onPan: ((event: PanEvent) => void) | null = null;
2220

2321
vi.mock('../gestures/createPanGesture', () => ({
24-
createPanGesture: (_element: Element, options: PanGestureOptions) => {
22+
createPan: (_element: Element, options: PanOptions) => {
2523
onPan = options.onPan;
2624
return {destroy: () => {}};
2725
},
@@ -102,24 +100,22 @@ function drawer() {
102100
}
103101

104102
/**
105-
* A press by `pointerType` on `element`, then a drag down by `dy` released
106-
* at `vy` px/s. The pan reports values only, so the factory reads the
107-
* pointer from the press.
103+
* A drag down by `dy` on `element` by `pointerType`, released at `vy` px/s.
104+
* The pan says which pointer drove it.
108105
*/
109106
function release(
110-
element: HTMLElement,
107+
_element: HTMLElement,
111108
dy: number,
112109
vy: number,
113110
pointerType: 'touch' | 'mouse' | 'pen',
114111
): void {
115-
element.dispatchEvent(
116-
new PointerEvent('pointerdown', {bubbles: true, pointerType}),
117-
);
118-
const at = (state: PanGestureEvent['state'], y: number, v: number) =>
112+
const at = (state: PanEvent['state'], y: number, v: number) =>
119113
onPan?.({
120114
state,
121115
translation: {x: 0, y},
116+
totalTranslation: {x: 0, y},
122117
velocity: {x: 0, y: v},
118+
input: pointerType,
123119
});
124120
at('began', 0, 0);
125121
at('changed', dy, 0);

0 commit comments

Comments
 (0)