@astryxdesign/core 0.7.16 → 0.7.17-canary.g49a475f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Button/Button.d.ts.map +1 -1
- package/dist/Button/Button.js +10 -3
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +5 -2
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +10 -4
- package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
- package/dist/ContextMenu/ContextMenu.js +20 -8
- package/dist/DropdownMenu/menuItemRoles.d.ts.map +1 -1
- package/dist/DropdownMenu/menuItemRoles.js +5 -2
- package/dist/Icon/Icon.js +4 -4
- package/dist/Icon/globalIconRegistry.d.ts.map +1 -1
- package/dist/Icon/globalIconRegistry.js +16 -6
- package/dist/Icon/useIcon.js +5 -5
- package/dist/Item/Item.d.ts +49 -67
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +91 -99
- package/dist/Link/Link.d.ts.map +1 -1
- package/dist/Link/Link.js +6 -1
- package/dist/List/ListItem.d.ts +5 -7
- package/dist/List/ListItem.d.ts.map +1 -1
- package/dist/List/ListItem.js +11 -1
- package/dist/MetadataList/MetadataListItem.d.ts +7 -2
- package/dist/MetadataList/MetadataListItem.d.ts.map +1 -1
- package/dist/MetadataList/MetadataListItem.js +3 -1
- package/dist/MobileNav/MobileNav.d.ts.map +1 -1
- package/dist/MobileNav/MobileNav.js +32 -23
- package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
- package/dist/MultiSelector/MultiSelector.js +15 -7
- package/dist/Pagination/Pagination.d.ts +25 -2
- package/dist/Pagination/Pagination.d.ts.map +1 -1
- package/dist/Pagination/Pagination.js +87 -47
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +11 -5
- package/dist/Swipe/SwipeActionsLayer.d.ts +11 -0
- package/dist/Swipe/SwipeActionsLayer.d.ts.map +1 -0
- package/dist/Swipe/SwipeActionsLayer.js +358 -0
- package/dist/Swipe/createSwipe.d.ts +26 -0
- package/dist/Swipe/createSwipe.d.ts.map +1 -0
- package/dist/Swipe/createSwipe.js +97 -0
- package/dist/Swipe/index.d.ts +3 -0
- package/dist/Swipe/index.d.ts.map +1 -0
- package/dist/Swipe/index.js +5 -0
- package/dist/Swipe/swipeHost.d.ts +208 -0
- package/dist/Swipe/swipeHost.d.ts.map +1 -0
- package/dist/Swipe/swipeHost.js +122 -0
- package/dist/Swipe/swipeHost.stylex.d.ts +21 -0
- package/dist/Swipe/swipeHost.stylex.d.ts.map +1 -0
- package/dist/Swipe/swipeHost.stylex.js +27 -0
- package/dist/Swipe/useSwipeAction.d.ts +219 -0
- package/dist/Swipe/useSwipeAction.d.ts.map +1 -0
- package/dist/Swipe/useSwipeAction.js +1120 -0
- package/dist/Table/TableCell.d.ts.map +1 -1
- package/dist/Table/TableCell.js +2 -2
- package/dist/Table/TableHeaderCell.d.ts.map +1 -1
- package/dist/Table/TableHeaderCell.js +25 -3
- package/dist/Table/plugins/selection/useTableSelection.d.ts.map +1 -1
- package/dist/Table/plugins/selection/useTableSelection.js +20 -2
- package/dist/Table/tableContextMenu.d.ts +6 -0
- package/dist/Table/tableContextMenu.d.ts.map +1 -1
- package/dist/Table/tableContextMenu.js +10 -1
- package/dist/Toast/Toast.d.ts.map +1 -1
- package/dist/Toast/Toast.js +10 -5
- package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
- package/dist/Tokenizer/Tokenizer.js +6 -1
- package/dist/TopNav/TopNav.d.ts.map +1 -1
- package/dist/TopNav/TopNav.js +6 -1
- package/dist/astryx.css +29 -18
- package/dist/dragToSnapPoints/compositorSettle.d.ts +38 -0
- package/dist/dragToSnapPoints/compositorSettle.d.ts.map +1 -0
- package/dist/dragToSnapPoints/compositorSettle.js +140 -0
- package/dist/dragToSnapPoints/createDragToSnapPoints.d.ts +29 -5
- package/dist/dragToSnapPoints/createDragToSnapPoints.d.ts.map +1 -1
- package/dist/dragToSnapPoints/createDragToSnapPoints.js +123 -7
- package/dist/hooks/useHotkeys.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/motion/uikit/swipeActions.d.ts +148 -0
- package/dist/motion/uikit/swipeActions.d.ts.map +1 -0
- package/dist/motion/uikit/swipeActions.js +150 -0
- package/dist/privateAttributes/pressHeld.stylex.d.ts +5 -0
- package/dist/privateAttributes/pressHeld.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/pressHeld.stylex.js +31 -0
- package/dist/theme/defineTheme.d.ts +19 -1
- package/dist/theme/defineTheme.d.ts.map +1 -1
- package/dist/theme/defineTheme.js +18 -0
- package/dist/theme/generateThemeRules.d.ts.map +1 -1
- package/dist/theme/generateThemeRules.js +121 -76
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/mergeComponents.d.ts +2 -1
- package/dist/theme/mergeComponents.d.ts.map +1 -1
- package/dist/theme/mergeComponents.js +18 -2
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +4 -1
- package/package.json +10 -5
- package/src/Button/Button.tsx +16 -5
- package/src/Chat/useChatDictation.doc.mjs +246 -0
- package/src/CheckboxInput/CheckboxInput.tsx +5 -1
- package/src/ComplexSelector/ComplexSelector.tsx +20 -8
- package/src/ContextMenu/ContextMenu.tsx +22 -12
- package/src/DropdownMenu/menuItemRoles.ts +9 -6
- package/src/Icon/Icon.tsx +4 -4
- package/src/Icon/globalIconRegistry.tsx +27 -15
- package/src/Icon/useIcon.ts +5 -5
- package/src/Item/Item.doc.mjs +8 -2
- package/src/Item/Item.tsx +143 -158
- package/src/Link/Link.tsx +14 -6
- package/src/List/ListItem.doc.mjs +21 -6
- package/src/List/ListItem.tsx +16 -7
- package/src/MetadataList/MetadataListItem.doc.mjs +36 -1
- package/src/MetadataList/MetadataListItem.tsx +7 -2
- package/src/MobileNav/MobileNav.tsx +45 -28
- package/src/MultiSelector/MultiSelector.tsx +28 -11
- package/src/Pagination/Pagination.doc.mjs +39 -3
- package/src/Pagination/Pagination.tsx +122 -55
- package/src/Selector/Selector.tsx +21 -9
- package/src/Swipe/SwipeActionsLayer.tsx +438 -0
- package/src/Swipe/createSwipe.doc.mjs +118 -0
- package/src/Swipe/createSwipe.ts +112 -0
- package/src/Swipe/index.ts +6 -0
- package/src/Swipe/swipeHost.stylex.ts +27 -0
- package/src/Swipe/swipeHost.ts +255 -0
- package/src/Swipe/useSwipeAction.ts +1413 -0
- package/src/Table/Table.doc.mjs +1 -1
- package/src/Table/TableCell.tsx +5 -4
- package/src/Table/TableHeaderCell.tsx +31 -3
- package/src/Table/plugins/selection/useTableSelection.tsx +18 -2
- package/src/Table/tableContextMenu.tsx +15 -1
- package/src/Toast/Toast.tsx +28 -5
- package/src/Tokenizer/Tokenizer.tsx +18 -5
- package/src/TopNav/TopNav.tsx +17 -1
- package/src/dragToSnapPoints/compositorSettle.ts +175 -0
- package/src/dragToSnapPoints/createDragToSnapPoints.ts +146 -11
- package/src/hooks/useHotkeys.doc.mjs +4 -4
- package/src/hooks/useHotkeys.ts +1 -1
- package/src/index.ts +1 -0
- package/src/motion/MEASUREMENTS.md +16 -0
- package/src/motion/README.md +1 -0
- package/src/motion/uikit/swipeActions.ts +142 -0
- package/src/privateAttributes/pressHeld.stylex.ts +31 -0
- package/src/theme/defineTheme.ts +23 -1
- package/src/theme/generateThemeRules.ts +194 -116
- package/src/theme/index.ts +1 -0
- package/src/theme/mergeComponents.ts +15 -5
- package/src/theme/syntax/useSyntaxTheme.doc.mjs +95 -0
- package/src/utils/pressFeedback.ts +8 -1
- package/dist/Item/ItemSwipeLayer.d.ts +0 -51
- package/dist/Item/ItemSwipeLayer.d.ts.map +0 -1
- package/dist/Item/ItemSwipeLayer.js +0 -282
- package/dist/Item/useSwipeAction.d.ts +0 -77
- package/dist/Item/useSwipeAction.d.ts.map +0 -1
- package/dist/Item/useSwipeAction.js +0 -551
- package/src/Item/ItemSwipeLayer.tsx +0 -400
- package/src/Item/useSwipeAction.ts +0 -752
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file swipeHost.ts
|
|
3
|
+
* @input Nothing at runtime
|
|
4
|
+
* @output Exports the public swipe-action types: SwipeAction,
|
|
5
|
+
* ItemSwipeActionVariant, ItemSwipeBehavior, CreateSwipeOptions and the
|
|
6
|
+
* opaque Swipe.
|
|
7
|
+
* Also the contract between a row and the runtime a Swipe value carries
|
|
8
|
+
* (SwipeHost, SwipeRowFacts, SwipeAttachment), and the layer contract
|
|
9
|
+
* (SwipeBridge, SwipeLayerProps). makeSwipe makes a Swipe
|
|
10
|
+
* value for a host, swipeHostOf finds it again, and swipeWithItemKey keys
|
|
11
|
+
* one for a ListItem
|
|
12
|
+
* @position The one swipe module a row imports at runtime: it holds no
|
|
13
|
+
* gesture, animation or rendering code, and no swipe rule. createSwipe.ts
|
|
14
|
+
* brings those, so they ship only with a caller that uses swipe actions.
|
|
15
|
+
*/
|
|
16
|
+
import type { KeyboardEvent, ReactNode } from 'react';
|
|
17
|
+
import type { StyleXStyles } from '@stylexjs/stylex';
|
|
18
|
+
/**
|
|
19
|
+
* How the action looks: ordinary, the one you mean, the dangerous one. Not a
|
|
20
|
+
* status set: a verb is not a state.
|
|
21
|
+
*/
|
|
22
|
+
export type ItemSwipeActionVariant = 'neutral' | 'accent' | 'destructive';
|
|
23
|
+
/**
|
|
24
|
+
* One verb. The row renders it as a filled surface in its `variant`'s colour
|
|
25
|
+
* with the icon above the label. Every field is known before the gesture
|
|
26
|
+
* begins, so a definition can live at module scope.
|
|
27
|
+
*/
|
|
28
|
+
export interface SwipeAction<Id extends string = string> {
|
|
29
|
+
/**
|
|
30
|
+
* Names the action. `onActivate` receives it, and a row keys its panel on
|
|
31
|
+
* its actions' ids. A new `swipe` value with the same ids keeps an open row
|
|
32
|
+
* open; one with other ids closes it.
|
|
33
|
+
*/
|
|
34
|
+
id: Id;
|
|
35
|
+
/**
|
|
36
|
+
* The verb's name, and the button's accessible name while the row rests
|
|
37
|
+
* open. Names the state the verb reaches ("Unread"), since the gesture
|
|
38
|
+
* already supplies the verb.
|
|
39
|
+
*/
|
|
40
|
+
label: string;
|
|
41
|
+
/** Drawn above the label. */
|
|
42
|
+
icon?: ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* Fires on a tap on a resting entry, on the full-swipe accelerator, or on a
|
|
45
|
+
* `commit` release. When the row slides out (a full swipe, a commit, a tapped
|
|
46
|
+
* entry with `hasRemoval`), it fires once the row's content has left its box.
|
|
47
|
+
* A tapped entry without `hasRemoval` fires at the tap. It receives the
|
|
48
|
+
* action's `id` and the row's `itemKey`: a `ListItem`'s, or `undefined` on a
|
|
49
|
+
* plain `Item`. So one handler serves every row, with no closure over a row.
|
|
50
|
+
* May return a Promise; the row waits for nothing. Not `onClick`: a commit
|
|
51
|
+
* fires with no click.
|
|
52
|
+
*/
|
|
53
|
+
onActivate: (event: {
|
|
54
|
+
id: Id;
|
|
55
|
+
itemKey: string | number | undefined;
|
|
56
|
+
}) => void;
|
|
57
|
+
isDisabled?: boolean;
|
|
58
|
+
/** @default 'accent' */
|
|
59
|
+
variant?: ItemSwipeActionVariant;
|
|
60
|
+
/**
|
|
61
|
+
* After this action activates, the row holds out rather than springing
|
|
62
|
+
* back. Only that: not a promise the caller removes the row, not an
|
|
63
|
+
* animation, not a timing rule. Independent of `swipeBehavior` and of
|
|
64
|
+
* `variant`; all combinations occur.
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
hasRemoval?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `reveal`: a fast release goes the way it moves, and a slow one rests the
|
|
71
|
+
* row open past half the panel. The open row's entries are real buttons. A
|
|
72
|
+
* fling never fires an entry. A long drag fires the outermost: past the
|
|
73
|
+
* confirm point the row runs ahead and the outermost entry covers its place.
|
|
74
|
+
* Backing out closes the row. On a side with two or more entries, only a
|
|
75
|
+
* drag that starts on the open row fires. `commit`: a release past the
|
|
76
|
+
* confirm point slides the row out and fires the one entry of a side.
|
|
77
|
+
* Nothing rests, and the panel is presentational. On a side with two or more
|
|
78
|
+
* entries, `commit` fires none.
|
|
79
|
+
*/
|
|
80
|
+
export type ItemSwipeBehavior = 'reveal' | 'commit';
|
|
81
|
+
/**
|
|
82
|
+
* The verbs a sideways drag uncovers on each side, outermost last, and what a
|
|
83
|
+
* swipe does on both sides. `leading` is uncovered by a drag toward the inline
|
|
84
|
+
* end, `trailing` by one toward the inline start.
|
|
85
|
+
*/
|
|
86
|
+
export interface CreateSwipeOptions<Id extends string = string> {
|
|
87
|
+
/** Uncovered by a drag toward the inline end (rightward in LTR); outermost last. */
|
|
88
|
+
leading?: ReadonlyArray<SwipeAction<Id>>;
|
|
89
|
+
/** Uncovered by a drag toward the inline start (leftward in LTR); outermost last. */
|
|
90
|
+
trailing?: ReadonlyArray<SwipeAction<Id>>;
|
|
91
|
+
/**
|
|
92
|
+
* What a swipe does; applies to both sides. `reveal`: a release opens or
|
|
93
|
+
* closes the row by its speed, then by half the panel's width. The open
|
|
94
|
+
* row rests with every entry a real button. A fling never fires an entry,
|
|
95
|
+
* and a long drag fires the outermost. On a side with two or more entries,
|
|
96
|
+
* only a drag from the open row fires it. `commit`: a lift past the confirm
|
|
97
|
+
* point slides the row out and fires the one entry of a side. Nothing
|
|
98
|
+
* rests, and the panel is presentational. On a side with two or more
|
|
99
|
+
* entries, `commit` fires none and warns in development. A commit is not a
|
|
100
|
+
* removal: the row springs back unless the entry has `hasRemoval`.
|
|
101
|
+
* @default 'reveal'
|
|
102
|
+
*/
|
|
103
|
+
swipeBehavior?: ItemSwipeBehavior;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The configured swipe actions. Callers create it only through `createSwipe`
|
|
107
|
+
* and pass it only to `swipe`; its contents are not public. Its type carries
|
|
108
|
+
* its actions' ids.
|
|
109
|
+
*/
|
|
110
|
+
export interface Swipe<Id extends string = string> {
|
|
111
|
+
/**
|
|
112
|
+
* A brand that is never present, so the swipe types of the package and a
|
|
113
|
+
* swizzled copy match.
|
|
114
|
+
*/
|
|
115
|
+
readonly '@astryxdesign/core/swipe/v1'?: never;
|
|
116
|
+
/** The actions' ids, for the type only: never present. */
|
|
117
|
+
readonly '@astryxdesign/core/swipe/ids'?: Id;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* An action as a row runs it: one `createSwipe` made, or an entry of the
|
|
121
|
+
* deprecated `swipeActions`. Such an entry's `id` is optional, and its
|
|
122
|
+
* handler takes nothing. The row calls `onActivate` with the entry's `id` and
|
|
123
|
+
* its key.
|
|
124
|
+
*/
|
|
125
|
+
export interface SwipeEntry {
|
|
126
|
+
readonly id?: string;
|
|
127
|
+
readonly label: string;
|
|
128
|
+
readonly icon?: ReactNode;
|
|
129
|
+
onActivate(event: {
|
|
130
|
+
id: string;
|
|
131
|
+
itemKey: string | number | undefined;
|
|
132
|
+
}): unknown;
|
|
133
|
+
readonly isDisabled?: boolean;
|
|
134
|
+
readonly variant?: ItemSwipeActionVariant;
|
|
135
|
+
readonly hasRemoval?: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* What a row knows about itself that decides whether swipe actions serve it,
|
|
139
|
+
* handed to the runtime with its root. The runtime decides.
|
|
140
|
+
*/
|
|
141
|
+
export interface SwipeRowFacts {
|
|
142
|
+
/** The root's role, if it has one. */
|
|
143
|
+
readonly role: string | undefined;
|
|
144
|
+
readonly isDisabled: boolean;
|
|
145
|
+
/** The row is the enlarged target of a control inside it. */
|
|
146
|
+
readonly isDelegate: boolean;
|
|
147
|
+
/** The root is itself a link. */
|
|
148
|
+
readonly isLinkRoot: boolean;
|
|
149
|
+
/** The `itemKey` of the `ListItem` the row is; a plain `Item` has none. */
|
|
150
|
+
readonly itemKey?: string | number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* What the runtime gives a row it serves. The row's root takes its style: the
|
|
154
|
+
* travel it moves by, and the touch it leaves the browser. Inside its root, the
|
|
155
|
+
* row renders the layer: the panels and the gesture, which attaches to the root
|
|
156
|
+
* itself. The root forwards its key events into the bridge the layer fills.
|
|
157
|
+
*/
|
|
158
|
+
export interface SwipeAttachment {
|
|
159
|
+
readonly rootStyle: StyleXStyles;
|
|
160
|
+
readonly layer: ReactNode;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* A Swipe value as a row reads it: the declared actions, and the runtime the
|
|
164
|
+
* value carries. A row hands that runtime its facts and its root.
|
|
165
|
+
*/
|
|
166
|
+
export interface SwipeHost {
|
|
167
|
+
readonly leading: ReadonlyArray<SwipeEntry>;
|
|
168
|
+
readonly trailing: ReadonlyArray<SwipeEntry>;
|
|
169
|
+
readonly behavior: ItemSwipeBehavior;
|
|
170
|
+
/** Whether swipe actions serve a row with these facts. */
|
|
171
|
+
readonly serves: (facts: SwipeRowFacts) => boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Whether the row is served, and if so, how (createSwipe.ts). The row passes
|
|
174
|
+
* the setter of the bridge its root forwards key events into.
|
|
175
|
+
*/
|
|
176
|
+
readonly attach: (facts: SwipeRowFacts, onBridge?: (bridge: SwipeBridge | null) => void) => SwipeAttachment | null;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The bridge a row's root forwards its key events into (Escape closes a
|
|
180
|
+
* resting row). The layer writes it when it mounts and clears it when it
|
|
181
|
+
* leaves; the root reads it on every event.
|
|
182
|
+
*/
|
|
183
|
+
export interface SwipeBridge {
|
|
184
|
+
onKeyDown: (event: KeyboardEvent) => void;
|
|
185
|
+
}
|
|
186
|
+
/** What the swipe layer takes. */
|
|
187
|
+
export interface SwipeLayerProps {
|
|
188
|
+
/**
|
|
189
|
+
* Called when the layer mounts, with the gesture for the row's root to
|
|
190
|
+
* forward its key events into, and with `null` when the layer leaves.
|
|
191
|
+
*/
|
|
192
|
+
onBridge?: (bridge: SwipeBridge | null) => void;
|
|
193
|
+
leading: ReadonlyArray<SwipeEntry>;
|
|
194
|
+
trailing: ReadonlyArray<SwipeEntry>;
|
|
195
|
+
behavior: ItemSwipeBehavior;
|
|
196
|
+
/** The row's key, handed to each `onActivate`. */
|
|
197
|
+
itemKey?: string | number;
|
|
198
|
+
}
|
|
199
|
+
/** Makes a Swipe value for a host (createSwipe.ts). */
|
|
200
|
+
export declare function makeSwipe<Id extends string = string>(host: SwipeHost): Swipe<Id>;
|
|
201
|
+
/** The host of a Swipe value, or null for a value it did not make. */
|
|
202
|
+
export declare function swipeHostOf(swipe: Swipe): SwipeHost | null;
|
|
203
|
+
/**
|
|
204
|
+
* The Swipe value a `ListItem` hands its `Item`: the same actions and runtime,
|
|
205
|
+
* attached with the row's key.
|
|
206
|
+
*/
|
|
207
|
+
export declare function swipeWithItemKey(swipe: Swipe, itemKey: string | number | undefined): Swipe;
|
|
208
|
+
//# sourceMappingURL=swipeHost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swipeHost.d.ts","sourceRoot":"","sources":["../../src/Swipe/swipeHost.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAC,aAAa,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,CAAC;AAE1E;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM;IACrD;;;;OAIG;IACH,EAAE,EAAE,EAAE,CAAC;IACP;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;;;;;;;O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AED,kCAAkC;AAClC,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACpC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B;AAYD,uDAAuD;AACvD,wBAAgB,SAAS,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,EAClD,IAAI,EAAE,SAAS,GACd,KAAK,CAAC,EAAE,CAAC,CAKX;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAE1D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GACnC,KAAK,CASP"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file swipeHost.ts
|
|
5
|
+
* @input Nothing at runtime
|
|
6
|
+
* @output Exports the public swipe-action types: SwipeAction,
|
|
7
|
+
* ItemSwipeActionVariant, ItemSwipeBehavior, CreateSwipeOptions and the
|
|
8
|
+
* opaque Swipe.
|
|
9
|
+
* Also the contract between a row and the runtime a Swipe value carries
|
|
10
|
+
* (SwipeHost, SwipeRowFacts, SwipeAttachment), and the layer contract
|
|
11
|
+
* (SwipeBridge, SwipeLayerProps). makeSwipe makes a Swipe
|
|
12
|
+
* value for a host, swipeHostOf finds it again, and swipeWithItemKey keys
|
|
13
|
+
* one for a ListItem
|
|
14
|
+
* @position The one swipe module a row imports at runtime: it holds no
|
|
15
|
+
* gesture, animation or rendering code, and no swipe rule. createSwipe.ts
|
|
16
|
+
* brings those, so they ship only with a caller that uses swipe actions.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* How the action looks: ordinary, the one you mean, the dangerous one. Not a
|
|
21
|
+
* status set: a verb is not a state.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* One verb. The row renders it as a filled surface in its `variant`'s colour
|
|
26
|
+
* with the icon above the label. Every field is known before the gesture
|
|
27
|
+
* begins, so a definition can live at module scope.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `reveal`: a fast release goes the way it moves, and a slow one rests the
|
|
32
|
+
* row open past half the panel. The open row's entries are real buttons. A
|
|
33
|
+
* fling never fires an entry. A long drag fires the outermost: past the
|
|
34
|
+
* confirm point the row runs ahead and the outermost entry covers its place.
|
|
35
|
+
* Backing out closes the row. On a side with two or more entries, only a
|
|
36
|
+
* drag that starts on the open row fires. `commit`: a release past the
|
|
37
|
+
* confirm point slides the row out and fires the one entry of a side.
|
|
38
|
+
* Nothing rests, and the panel is presentational. On a side with two or more
|
|
39
|
+
* entries, `commit` fires none.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The verbs a sideways drag uncovers on each side, outermost last, and what a
|
|
44
|
+
* swipe does on both sides. `leading` is uncovered by a drag toward the inline
|
|
45
|
+
* end, `trailing` by one toward the inline start.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The configured swipe actions. Callers create it only through `createSwipe`
|
|
50
|
+
* and pass it only to `swipe`; its contents are not public. Its type carries
|
|
51
|
+
* its actions' ids.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* An action as a row runs it: one `createSwipe` made, or an entry of the
|
|
56
|
+
* deprecated `swipeActions`. Such an entry's `id` is optional, and its
|
|
57
|
+
* handler takes nothing. The row calls `onActivate` with the entry's `id` and
|
|
58
|
+
* its key.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* What a row knows about itself that decides whether swipe actions serve it,
|
|
63
|
+
* handed to the runtime with its root. The runtime decides.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* What the runtime gives a row it serves. The row's root takes its style: the
|
|
68
|
+
* travel it moves by, and the touch it leaves the browser. Inside its root, the
|
|
69
|
+
* row renders the layer: the panels and the gesture, which attaches to the root
|
|
70
|
+
* itself. The root forwards its key events into the bridge the layer fills.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A Swipe value as a row reads it: the declared actions, and the runtime the
|
|
75
|
+
* value carries. A row hands that runtime its facts and its root.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The bridge a row's root forwards its key events into (Escape closes a
|
|
80
|
+
* resting row). The layer writes it when it mounts and clears it when it
|
|
81
|
+
* leaves; the root reads it on every event.
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/** What the swipe layer takes. */
|
|
85
|
+
|
|
86
|
+
// Each Swipe value carries its host under this key, not enumerable and not
|
|
87
|
+
// writable. Every copy of the package makes the same key, so a swizzled Item
|
|
88
|
+
// finds the host of the package's value. A value built by hand has none.
|
|
89
|
+
const HOST = Symbol.for('@astryxdesign/core/swipe/host');
|
|
90
|
+
|
|
91
|
+
/** A Swipe value as its makers read it. */
|
|
92
|
+
|
|
93
|
+
/** Makes a Swipe value for a host (createSwipe.ts). */
|
|
94
|
+
export function makeSwipe(host) {
|
|
95
|
+
const swipe = Object.freeze(Object.defineProperty({}, HOST, {
|
|
96
|
+
value: host
|
|
97
|
+
}));
|
|
98
|
+
return swipe;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The host of a Swipe value, or null for a value it did not make. */
|
|
102
|
+
export function swipeHostOf(swipe) {
|
|
103
|
+
return swipe[HOST] ?? null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The Swipe value a `ListItem` hands its `Item`: the same actions and runtime,
|
|
108
|
+
* attached with the row's key.
|
|
109
|
+
*/
|
|
110
|
+
export function swipeWithItemKey(swipe, itemKey) {
|
|
111
|
+
const host = swipeHostOf(swipe);
|
|
112
|
+
if (host == null || itemKey == null) {
|
|
113
|
+
return swipe;
|
|
114
|
+
}
|
|
115
|
+
return makeSwipe({
|
|
116
|
+
...host,
|
|
117
|
+
attach: (facts, onBridge) => host.attach({
|
|
118
|
+
...facts,
|
|
119
|
+
itemKey
|
|
120
|
+
}, onBridge)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file swipeHost.stylex.ts
|
|
3
|
+
* @input Uses StyleX
|
|
4
|
+
* @output Exports swipeHostStyles: the style a swipeable row's root takes
|
|
5
|
+
* @position Shared by createSwipe.ts, which hands it to the row with the swipe
|
|
6
|
+
* actions. Also by Item.tsx's released `swipeActions` path, which applies it
|
|
7
|
+
* from the row's first render, as before
|
|
8
|
+
*
|
|
9
|
+
* The root translates by the travel the gesture writes on it every frame (see
|
|
10
|
+
* useSwipeAction). `pan-y` lets the browser keep scrolling the list while the
|
|
11
|
+
* row owns horizontal movement. `pinch-zoom` leaves a two-finger pinch that
|
|
12
|
+
* starts on the row to the browser, so the page stays zoomable (WCAG 1.4.4).
|
|
13
|
+
*/
|
|
14
|
+
import * as stylex from '@stylexjs/stylex';
|
|
15
|
+
export declare const swipeHostStyles: Readonly<{
|
|
16
|
+
readonly root: Readonly<{
|
|
17
|
+
readonly touchAction: stylex.StyleXClassNameFor<"touchAction", "pan-y pinch-zoom">;
|
|
18
|
+
readonly transform: stylex.StyleXClassNameFor<"transform", "translate3d(var(--_item-swipe-travel, 0px), 0, 0)">;
|
|
19
|
+
}>;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=swipeHost.stylex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swipeHost.stylex.d.ts","sourceRoot":"","sources":["../../src/Swipe/swipeHost.stylex.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAK3C,eAAO,MAAM,eAAe;;;;;EAK1B,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file swipeHost.stylex.ts
|
|
5
|
+
* @input Uses StyleX
|
|
6
|
+
* @output Exports swipeHostStyles: the style a swipeable row's root takes
|
|
7
|
+
* @position Shared by createSwipe.ts, which hands it to the row with the swipe
|
|
8
|
+
* actions. Also by Item.tsx's released `swipeActions` path, which applies it
|
|
9
|
+
* from the row's first render, as before
|
|
10
|
+
*
|
|
11
|
+
* The root translates by the travel the gesture writes on it every frame (see
|
|
12
|
+
* useSwipeAction). `pan-y` lets the browser keep scrolling the list while the
|
|
13
|
+
* row owns horizontal movement. `pinch-zoom` leaves a two-finger pinch that
|
|
14
|
+
* starts on the row to the browser, so the page stays zoomable (WCAG 1.4.4).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import * as stylex from '@stylexjs/stylex';
|
|
18
|
+
|
|
19
|
+
/** The travel the swipe writes on the row root, physical px (useSwipeAction.ts). */
|
|
20
|
+
const SWIPE_TRAVEL = 'var(--_item-swipe-travel, 0px)';
|
|
21
|
+
export const swipeHostStyles = {
|
|
22
|
+
root: {
|
|
23
|
+
kFalU9: "xge0x1e",
|
|
24
|
+
k3aq6I: "x1kncwj0",
|
|
25
|
+
$$css: true
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file useSwipeAction.ts
|
|
3
|
+
* @input Per side, the panel window and its entries (callback refs; the row
|
|
4
|
+
* root is the window's parent). The shared drag path (createSnapDrag, in
|
|
5
|
+
* createDragToSnapPoints.ts: the trackpad splitter, the pan, the snap-point
|
|
6
|
+
* drag and the animator). The UIKit constants table
|
|
7
|
+
* @output Exports useSwipeAction — the stops, the actions and the finger's
|
|
8
|
+
* model behind a row's swipe actions (where each part sits for the travel
|
|
9
|
+
* is SwipeActionsLayer's styles). Also the release rules: resolveRelease,
|
|
10
|
+
* confirmPoint and confirmedOffset
|
|
11
|
+
* @position Internal to swipe actions, through SwipeActionsLayer (the only
|
|
12
|
+
* module that imports it); tested through Item.test.tsx, the interaction
|
|
13
|
+
* proofs, and swipeRelease.test.ts for the release rules
|
|
14
|
+
*
|
|
15
|
+
* A row's swipe runs the shared drag path every followed pan runs: the
|
|
16
|
+
* splitter, the pan, the snap-point drag and the animator. The row declares its
|
|
17
|
+
* stops per side: rest, the open width, and out past the row's edge for a full
|
|
18
|
+
* swipe. It also declares its actions. The drag draws the row's travel into one
|
|
19
|
+
* custom property on the root, which every part of the panel reads
|
|
20
|
+
* (SwipeActionsLayer). A settle writes its end there at once, and each part
|
|
21
|
+
* plays the way there on the compositor, all on one clock.
|
|
22
|
+
*
|
|
23
|
+
* What a drag does depends on what drives it:
|
|
24
|
+
*
|
|
25
|
+
* - A trackpad's horizontal swipe follows the fingers one for one from its
|
|
26
|
+
* first event past the pan's 8 px start. Its release settles to the nearest
|
|
27
|
+
* stop by position and velocity (Core's one release policy), from the
|
|
28
|
+
* fingers' speed at their last move.
|
|
29
|
+
* - A finger's or a pen's drag begins at the row's 8 px claim. From then until
|
|
30
|
+
* the release, the row is at the finger's travel since touch-down. The full
|
|
31
|
+
* swipe confirms on UIKit's measure, from UIKit's 25 px dead zone. The row
|
|
32
|
+
* then runs ahead to the confirmation offset and keeps that lead. The
|
|
33
|
+
* release goes by UIKit's rule (resolveRelease, below), on UIKit's settle spring
|
|
34
|
+
* from the row's own velocity.
|
|
35
|
+
*
|
|
36
|
+
* Either way a drag stays on its side: within one gesture an open row only
|
|
37
|
+
* closes, never passing rest to its other side. Dragged past the confirm point,
|
|
38
|
+
* when the side's outermost entry can fire, a full swipe confirms. On a side
|
|
39
|
+
* with two or more entries, only a drag from the open row confirms, or one
|
|
40
|
+
* that lands on its outermost entry. The row
|
|
41
|
+
* runs ahead to UIKit's confirmation offset, and the outermost entry covers the
|
|
42
|
+
* space. The panel reads that from a second custom property, the confirm;
|
|
43
|
+
* backing out undoes it. A lift still confirmed slides the row out and fires
|
|
44
|
+
* the outermost entry, at any speed. Speed alone never fires one, so a full
|
|
45
|
+
* swipe is the one stop a flick never reaches. Whenever the row slides out (a
|
|
46
|
+
* full swipe, or a tapped entry with `hasRemoval`), the entry fires once the
|
|
47
|
+
* row's content has left its box. Then the row springs back, or holds out when
|
|
48
|
+
* the entry has `hasRemoval`.
|
|
49
|
+
*
|
|
50
|
+
* A mouse drag and a mouse wheel's notches never swipe a row: the pan takes
|
|
51
|
+
* touches, pens and a trackpad's scroll. A finger that lands while another is
|
|
52
|
+
* down, on the row or anywhere else, never starts the pan: the page pinches.
|
|
53
|
+
*
|
|
54
|
+
* An open row closes on a pointer landing outside it. It counts as open while
|
|
55
|
+
* resting, or while settling to rest open: UIKit counts a row open from the
|
|
56
|
+
* release that opens it. It also closes on a scroll of anything that holds it
|
|
57
|
+
* while focus is outside its open panel. Escape closes it with focus inside it.
|
|
58
|
+
* A touch tap on its own content closes it too, and activates nothing on the
|
|
59
|
+
* row. A mouse's or a pen's press on it reaches the row.
|
|
60
|
+
*
|
|
61
|
+
* Under Reduce Motion the drag itself is direct manipulation and follows one
|
|
62
|
+
* for one. But what a release, a confirm or a close starts never travels or
|
|
63
|
+
* springs. After a finger, the row lands at the bottom of an opacity dip. A
|
|
64
|
+
* pen's or a trackpad's lands at once on a fine primary pointer.
|
|
65
|
+
*
|
|
66
|
+
* Directions are logical: `leading` is uncovered by a drag toward the inline
|
|
67
|
+
* end, and sits at the inline start. `trailing` is the reverse. Both are read
|
|
68
|
+
* against the root's computed `direction` when the drag begins.
|
|
69
|
+
*/
|
|
70
|
+
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
71
|
+
/** What a swipe does (`createSwipe`'s `behavior`). */
|
|
72
|
+
export type SwipeReleaseBehavior = 'reveal' | 'commit';
|
|
73
|
+
/** Where a release lands. */
|
|
74
|
+
export type SwipeRelease = 'closed' | 'open' | 'perform';
|
|
75
|
+
/**
|
|
76
|
+
* Where a release lands. `travel` (px, ≥ 0) and `velocity` (px/s) are logical:
|
|
77
|
+
* positive toward the side being uncovered. `isConfirmed`: the finger is past
|
|
78
|
+
* the confirm point as it lifts. `wasConfirmed`: it was past it at some point
|
|
79
|
+
* during this swipe. A confirmed release fires the outermost entry, whatever
|
|
80
|
+
* its velocity. Under `commit`, nothing else fires and nothing rests. A swipe
|
|
81
|
+
* that confirmed and backed out closes under either model. Otherwise, under
|
|
82
|
+
* `reveal`, a release at `releaseVelocity` or faster opens the row if it is
|
|
83
|
+
* opening, and closes it if it is closing. A slower one opens it past
|
|
84
|
+
* `openFraction` of its open width, and closes it short of that.
|
|
85
|
+
*/
|
|
86
|
+
export declare function resolveRelease({ travel, velocity, openWidth, isConfirmed, wasConfirmed, behavior, }: {
|
|
87
|
+
travel: number;
|
|
88
|
+
velocity: number;
|
|
89
|
+
openWidth: number;
|
|
90
|
+
isConfirmed: boolean;
|
|
91
|
+
wasConfirmed: boolean;
|
|
92
|
+
behavior: SwipeReleaseBehavior;
|
|
93
|
+
}): SwipeRelease;
|
|
94
|
+
/**
|
|
95
|
+
* The swipe at which a full swipe confirms. It is `confirmFraction` of the way
|
|
96
|
+
* from the open width to the confirmation offset, and never short of the open
|
|
97
|
+
* width. The confirmation offset is the row width less `confirmInset`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function confirmPoint(openWidth: number, rowWidth: number): number;
|
|
100
|
+
/** The row's offset once a full swipe has confirmed (UIKit's `confirmationThreshold`). */
|
|
101
|
+
export declare function confirmedOffset(rowWidth: number): number;
|
|
102
|
+
export type SwipeSide = 'leading' | 'trailing';
|
|
103
|
+
export type SwipeBehavior = 'reveal' | 'commit';
|
|
104
|
+
export type SwipePhase =
|
|
105
|
+
/** At rest, closed. */
|
|
106
|
+
'idle'
|
|
107
|
+
/** A drag drives the row. */
|
|
108
|
+
| 'dragging'
|
|
109
|
+
/** Settling where the release, a tap or a close sent it. */
|
|
110
|
+
| 'settling'
|
|
111
|
+
/** Resting open with the side's panel tappable (`reveal` only). */
|
|
112
|
+
| 'resting'
|
|
113
|
+
/** Out, after an entry with `hasRemoval` fired. */
|
|
114
|
+
| 'held';
|
|
115
|
+
export interface SwipeState {
|
|
116
|
+
phase: SwipePhase;
|
|
117
|
+
/** The side whose panel is uncovered, or will be. */
|
|
118
|
+
side: SwipeSide;
|
|
119
|
+
/** A confirmed full swipe: letting go now fires the outermost entry. */
|
|
120
|
+
isArmed: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* The entry that covers the side's panel, by its index on that side. From a
|
|
123
|
+
* full swipe's confirm, it is the outermost until the row is home or held
|
|
124
|
+
* out. For a tapped entry, it is that entry while its row returns or holds
|
|
125
|
+
* out.
|
|
126
|
+
*/
|
|
127
|
+
cover: number | null;
|
|
128
|
+
/** Where the settle in progress lands (`settling` only). */
|
|
129
|
+
landing?: 'idle' | 'resting' | 'held';
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The row is open: resting, or settling to rest open. UIKit counts a row open
|
|
133
|
+
* from the release that opens it, not from when it comes to rest. An open row
|
|
134
|
+
* closes on a tap on its content, a pointer outside it, a scroll or Escape.
|
|
135
|
+
* Its root takes no press.
|
|
136
|
+
*/
|
|
137
|
+
export declare function isSwipeOpen(state: SwipeState): boolean;
|
|
138
|
+
/** The row's travel, physical px, on the root: every part reads it. */
|
|
139
|
+
export declare const SWIPE_TRAVEL_PROPERTY = "--_item-swipe-travel";
|
|
140
|
+
/** How far a full swipe has confirmed, 0 to 1, on the root. */
|
|
141
|
+
export declare const SWIPE_CONFIRM_PROPERTY = "--_item-swipe-confirm";
|
|
142
|
+
/**
|
|
143
|
+
* A side's geometry, written on its window when a drag begins. The pin
|
|
144
|
+
* (physical px) is where the entries sit against the track, so they stay at the
|
|
145
|
+
* outer edge. The side's physical sign is +1 on the left. Then its open width
|
|
146
|
+
* (px), and the outermost entry's slide on a confirmed full swipe (physical
|
|
147
|
+
* px). The entries' and the outermost entry's transforms read them.
|
|
148
|
+
*/
|
|
149
|
+
export declare const SWIPE_PIN_PROPERTY = "--_item-swipe-pin";
|
|
150
|
+
export declare const SWIPE_SIGN_PROPERTY = "--_item-swipe-sign";
|
|
151
|
+
export declare const SWIPE_OPEN_PROPERTY = "--_item-swipe-open";
|
|
152
|
+
export declare const SWIPE_SLIDE_PROPERTY = "--_item-swipe-slide";
|
|
153
|
+
/** Callback refs for the elements of one side's panel the gesture reads. */
|
|
154
|
+
export interface SwipePanelRefs {
|
|
155
|
+
/** The window over the row's resting box; the side's pin is written on it. */
|
|
156
|
+
panel: (element: HTMLElement | null) => void;
|
|
157
|
+
/**
|
|
158
|
+
* Each entry other than the outermost: the ref for the entry with `key`
|
|
159
|
+
* (its React key), stable per key. Their natural widths together, the
|
|
160
|
+
* outermost entry's included, are how far the row opens.
|
|
161
|
+
*/
|
|
162
|
+
entry: (key: string) => (element: HTMLElement | null) => void;
|
|
163
|
+
/** The outermost entry, which slides to the row's edge on a full swipe. */
|
|
164
|
+
outer: (element: HTMLElement | null) => void;
|
|
165
|
+
}
|
|
166
|
+
export interface UseSwipeActionOptions {
|
|
167
|
+
behavior: SwipeBehavior;
|
|
168
|
+
/**
|
|
169
|
+
* How many entries each side has. A drag toward a side without any never
|
|
170
|
+
* begins. A side with two or more confirms a full swipe only from the row
|
|
171
|
+
* open on that side.
|
|
172
|
+
*/
|
|
173
|
+
sides: {
|
|
174
|
+
leading: number;
|
|
175
|
+
trailing: number;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Fire the side's outermost entry. Returns whether the row holds out
|
|
179
|
+
* afterwards (the entry's `hasRemoval`).
|
|
180
|
+
*/
|
|
181
|
+
fireOutermost: (side: SwipeSide) => boolean;
|
|
182
|
+
/** Whether the side's outermost entry can fire: a disabled one never confirms a full swipe. */
|
|
183
|
+
canConfirm: (side: SwipeSide) => boolean;
|
|
184
|
+
}
|
|
185
|
+
export interface UseSwipeActionResult {
|
|
186
|
+
state: SwipeState;
|
|
187
|
+
/** Attach each side's moving panel parts. */
|
|
188
|
+
panelRefs: Record<SwipeSide, SwipePanelRefs>;
|
|
189
|
+
/**
|
|
190
|
+
* A resting panel's entry was tapped. Without `hasRemoval` (`holdsOut`), it
|
|
191
|
+
* fires at once and the row closes. With it, the row slides out, the entry
|
|
192
|
+
* fires once the row's content has left its box, and the row holds out. The
|
|
193
|
+
* tapped entry, at index `cover` on its side, covers the panel meanwhile.
|
|
194
|
+
*/
|
|
195
|
+
activateEntry: (fire: () => void, holdsOut: boolean, cover: number) => void;
|
|
196
|
+
/** Close an open row. */
|
|
197
|
+
close: () => void;
|
|
198
|
+
/** Escape closes an open row with focus inside it. */
|
|
199
|
+
onKeyDown: (event: ReactKeyboardEvent) => void;
|
|
200
|
+
/** The row root the gesture attaches to, once the panels have mounted. */
|
|
201
|
+
rootRef: {
|
|
202
|
+
readonly current: HTMLElement | null;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export interface SwipeLayout {
|
|
206
|
+
side: SwipeSide;
|
|
207
|
+
/** +1 when the inline end is to the right (LTR), −1 under RTL. */
|
|
208
|
+
inlineSign: 1 | -1;
|
|
209
|
+
/** The side's entries at their natural widths together: how far the row opens. */
|
|
210
|
+
openWidth: number;
|
|
211
|
+
/** The outermost entry's width. */
|
|
212
|
+
outerWidth: number;
|
|
213
|
+
/** The row's width. */
|
|
214
|
+
rowWidth: number;
|
|
215
|
+
}
|
|
216
|
+
/** +1 when the side's panel is on the physical left, −1 on the right. */
|
|
217
|
+
export declare function physicalSign(side: SwipeSide, inlineSign: 1 | -1): 1 | -1;
|
|
218
|
+
export declare function useSwipeAction({ behavior, sides, fireOutermost, canConfirm, }: UseSwipeActionOptions): UseSwipeActionResult;
|
|
219
|
+
//# sourceMappingURL=useSwipeAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSwipeAction.d.ts","sourceRoot":"","sources":["../../src/Swipe/useSwipeAction.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAEH,OAAO,KAAK,EAAC,aAAa,IAAI,kBAAkB,EAAC,MAAM,OAAO,CAAC;AA4C/D,sDAAsD;AACtD,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEvD,6BAA6B;AAC7B,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,EACX,YAAY,EACZ,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,oBAAoB,CAAC;CAChC,GAAG,YAAY,CAcf;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMxE;AAED,0FAA0F;AAC1F,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExD;AAMD,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AAC/C,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAChD,MAAM,MAAM,UAAU;AACpB,uBAAuB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