@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.
Files changed (156) hide show
  1. package/dist/Button/Button.d.ts.map +1 -1
  2. package/dist/Button/Button.js +10 -3
  3. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  4. package/dist/CheckboxInput/CheckboxInput.js +5 -2
  5. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  6. package/dist/ComplexSelector/ComplexSelector.js +10 -4
  7. package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
  8. package/dist/ContextMenu/ContextMenu.js +20 -8
  9. package/dist/DropdownMenu/menuItemRoles.d.ts.map +1 -1
  10. package/dist/DropdownMenu/menuItemRoles.js +5 -2
  11. package/dist/Icon/Icon.js +4 -4
  12. package/dist/Icon/globalIconRegistry.d.ts.map +1 -1
  13. package/dist/Icon/globalIconRegistry.js +16 -6
  14. package/dist/Icon/useIcon.js +5 -5
  15. package/dist/Item/Item.d.ts +49 -67
  16. package/dist/Item/Item.d.ts.map +1 -1
  17. package/dist/Item/Item.js +91 -99
  18. package/dist/Link/Link.d.ts.map +1 -1
  19. package/dist/Link/Link.js +6 -1
  20. package/dist/List/ListItem.d.ts +5 -7
  21. package/dist/List/ListItem.d.ts.map +1 -1
  22. package/dist/List/ListItem.js +11 -1
  23. package/dist/MetadataList/MetadataListItem.d.ts +7 -2
  24. package/dist/MetadataList/MetadataListItem.d.ts.map +1 -1
  25. package/dist/MetadataList/MetadataListItem.js +3 -1
  26. package/dist/MobileNav/MobileNav.d.ts.map +1 -1
  27. package/dist/MobileNav/MobileNav.js +32 -23
  28. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  29. package/dist/MultiSelector/MultiSelector.js +15 -7
  30. package/dist/Pagination/Pagination.d.ts +25 -2
  31. package/dist/Pagination/Pagination.d.ts.map +1 -1
  32. package/dist/Pagination/Pagination.js +87 -47
  33. package/dist/Selector/Selector.d.ts.map +1 -1
  34. package/dist/Selector/Selector.js +11 -5
  35. package/dist/Swipe/SwipeActionsLayer.d.ts +11 -0
  36. package/dist/Swipe/SwipeActionsLayer.d.ts.map +1 -0
  37. package/dist/Swipe/SwipeActionsLayer.js +358 -0
  38. package/dist/Swipe/createSwipe.d.ts +26 -0
  39. package/dist/Swipe/createSwipe.d.ts.map +1 -0
  40. package/dist/Swipe/createSwipe.js +97 -0
  41. package/dist/Swipe/index.d.ts +3 -0
  42. package/dist/Swipe/index.d.ts.map +1 -0
  43. package/dist/Swipe/index.js +5 -0
  44. package/dist/Swipe/swipeHost.d.ts +208 -0
  45. package/dist/Swipe/swipeHost.d.ts.map +1 -0
  46. package/dist/Swipe/swipeHost.js +122 -0
  47. package/dist/Swipe/swipeHost.stylex.d.ts +21 -0
  48. package/dist/Swipe/swipeHost.stylex.d.ts.map +1 -0
  49. package/dist/Swipe/swipeHost.stylex.js +27 -0
  50. package/dist/Swipe/useSwipeAction.d.ts +219 -0
  51. package/dist/Swipe/useSwipeAction.d.ts.map +1 -0
  52. package/dist/Swipe/useSwipeAction.js +1120 -0
  53. package/dist/Table/TableCell.d.ts.map +1 -1
  54. package/dist/Table/TableCell.js +2 -2
  55. package/dist/Table/TableHeaderCell.d.ts.map +1 -1
  56. package/dist/Table/TableHeaderCell.js +25 -3
  57. package/dist/Table/plugins/selection/useTableSelection.d.ts.map +1 -1
  58. package/dist/Table/plugins/selection/useTableSelection.js +20 -2
  59. package/dist/Table/tableContextMenu.d.ts +6 -0
  60. package/dist/Table/tableContextMenu.d.ts.map +1 -1
  61. package/dist/Table/tableContextMenu.js +10 -1
  62. package/dist/Toast/Toast.d.ts.map +1 -1
  63. package/dist/Toast/Toast.js +10 -5
  64. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  65. package/dist/Tokenizer/Tokenizer.js +6 -1
  66. package/dist/TopNav/TopNav.d.ts.map +1 -1
  67. package/dist/TopNav/TopNav.js +6 -1
  68. package/dist/astryx.css +29 -18
  69. package/dist/dragToSnapPoints/compositorSettle.d.ts +38 -0
  70. package/dist/dragToSnapPoints/compositorSettle.d.ts.map +1 -0
  71. package/dist/dragToSnapPoints/compositorSettle.js +140 -0
  72. package/dist/dragToSnapPoints/createDragToSnapPoints.d.ts +29 -5
  73. package/dist/dragToSnapPoints/createDragToSnapPoints.d.ts.map +1 -1
  74. package/dist/dragToSnapPoints/createDragToSnapPoints.js +123 -7
  75. package/dist/hooks/useHotkeys.d.ts +1 -1
  76. package/dist/index.d.ts +1 -0
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +1 -0
  79. package/dist/motion/uikit/swipeActions.d.ts +148 -0
  80. package/dist/motion/uikit/swipeActions.d.ts.map +1 -0
  81. package/dist/motion/uikit/swipeActions.js +150 -0
  82. package/dist/privateAttributes/pressHeld.stylex.d.ts +5 -0
  83. package/dist/privateAttributes/pressHeld.stylex.d.ts.map +1 -0
  84. package/dist/privateAttributes/pressHeld.stylex.js +31 -0
  85. package/dist/theme/defineTheme.d.ts +19 -1
  86. package/dist/theme/defineTheme.d.ts.map +1 -1
  87. package/dist/theme/defineTheme.js +18 -0
  88. package/dist/theme/generateThemeRules.d.ts.map +1 -1
  89. package/dist/theme/generateThemeRules.js +121 -76
  90. package/dist/theme/index.d.ts +1 -1
  91. package/dist/theme/index.d.ts.map +1 -1
  92. package/dist/theme/mergeComponents.d.ts +2 -1
  93. package/dist/theme/mergeComponents.d.ts.map +1 -1
  94. package/dist/theme/mergeComponents.js +18 -2
  95. package/dist/utils/pressFeedback.d.ts.map +1 -1
  96. package/dist/utils/pressFeedback.js +4 -1
  97. package/package.json +10 -5
  98. package/src/Button/Button.tsx +16 -5
  99. package/src/Chat/useChatDictation.doc.mjs +246 -0
  100. package/src/CheckboxInput/CheckboxInput.tsx +5 -1
  101. package/src/ComplexSelector/ComplexSelector.tsx +20 -8
  102. package/src/ContextMenu/ContextMenu.tsx +22 -12
  103. package/src/DropdownMenu/menuItemRoles.ts +9 -6
  104. package/src/Icon/Icon.tsx +4 -4
  105. package/src/Icon/globalIconRegistry.tsx +27 -15
  106. package/src/Icon/useIcon.ts +5 -5
  107. package/src/Item/Item.doc.mjs +8 -2
  108. package/src/Item/Item.tsx +143 -158
  109. package/src/Link/Link.tsx +14 -6
  110. package/src/List/ListItem.doc.mjs +21 -6
  111. package/src/List/ListItem.tsx +16 -7
  112. package/src/MetadataList/MetadataListItem.doc.mjs +36 -1
  113. package/src/MetadataList/MetadataListItem.tsx +7 -2
  114. package/src/MobileNav/MobileNav.tsx +45 -28
  115. package/src/MultiSelector/MultiSelector.tsx +28 -11
  116. package/src/Pagination/Pagination.doc.mjs +39 -3
  117. package/src/Pagination/Pagination.tsx +122 -55
  118. package/src/Selector/Selector.tsx +21 -9
  119. package/src/Swipe/SwipeActionsLayer.tsx +438 -0
  120. package/src/Swipe/createSwipe.doc.mjs +118 -0
  121. package/src/Swipe/createSwipe.ts +112 -0
  122. package/src/Swipe/index.ts +6 -0
  123. package/src/Swipe/swipeHost.stylex.ts +27 -0
  124. package/src/Swipe/swipeHost.ts +255 -0
  125. package/src/Swipe/useSwipeAction.ts +1413 -0
  126. package/src/Table/Table.doc.mjs +1 -1
  127. package/src/Table/TableCell.tsx +5 -4
  128. package/src/Table/TableHeaderCell.tsx +31 -3
  129. package/src/Table/plugins/selection/useTableSelection.tsx +18 -2
  130. package/src/Table/tableContextMenu.tsx +15 -1
  131. package/src/Toast/Toast.tsx +28 -5
  132. package/src/Tokenizer/Tokenizer.tsx +18 -5
  133. package/src/TopNav/TopNav.tsx +17 -1
  134. package/src/dragToSnapPoints/compositorSettle.ts +175 -0
  135. package/src/dragToSnapPoints/createDragToSnapPoints.ts +146 -11
  136. package/src/hooks/useHotkeys.doc.mjs +4 -4
  137. package/src/hooks/useHotkeys.ts +1 -1
  138. package/src/index.ts +1 -0
  139. package/src/motion/MEASUREMENTS.md +16 -0
  140. package/src/motion/README.md +1 -0
  141. package/src/motion/uikit/swipeActions.ts +142 -0
  142. package/src/privateAttributes/pressHeld.stylex.ts +31 -0
  143. package/src/theme/defineTheme.ts +23 -1
  144. package/src/theme/generateThemeRules.ts +194 -116
  145. package/src/theme/index.ts +1 -0
  146. package/src/theme/mergeComponents.ts +15 -5
  147. package/src/theme/syntax/useSyntaxTheme.doc.mjs +95 -0
  148. package/src/utils/pressFeedback.ts +8 -1
  149. package/dist/Item/ItemSwipeLayer.d.ts +0 -51
  150. package/dist/Item/ItemSwipeLayer.d.ts.map +0 -1
  151. package/dist/Item/ItemSwipeLayer.js +0 -282
  152. package/dist/Item/useSwipeAction.d.ts +0 -77
  153. package/dist/Item/useSwipeAction.d.ts.map +0 -1
  154. package/dist/Item/useSwipeAction.js +0 -551
  155. package/src/Item/ItemSwipeLayer.tsx +0 -400
  156. package/src/Item/useSwipeAction.ts +0 -752
@@ -0,0 +1,358 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file SwipeActionsLayer.tsx
7
+ * @input The swipe entries per side, the behavior; useSwipeAction,
8
+ * theme tokens
9
+ * @output Exports SwipeActionsLayer (default): the panels of a row's swipe
10
+ * actions and the gesture that uncovers them
11
+ * @position Brought by createSwipe.ts, which hands it to a row the swipe
12
+ * serves; Item.tsx's deprecated path loads it with `import()`. Tested
13
+ * through Item.test.tsx and Item.source-build.test.mjs.
14
+ *
15
+ * The row's root stays the row's: it takes the root style the swipe brings, and
16
+ * forwards its key events into the bridge this layer fills. The gesture
17
+ * attaches to the root itself, and the layer holds
18
+ * the root's press while the row is open. This layer renders the two panels as
19
+ * out-of-flow children of that root. So no element is added to the row for the
20
+ * swipe.
21
+ *
22
+ * A panel is two boxes and the entries themselves. Transforms move all three,
23
+ * reading the travel the gesture writes on the root (see useSwipeAction). The
24
+ * window sits over the row's resting box, reads the travel's negation, and
25
+ * clips to that box. The track inside it moves with the row, and clips the
26
+ * entries to the space the row vacates. Each entry is translated back from the
27
+ * side's pin. So the entries stay at the outer edge until the row has uncovered
28
+ * them all, then ride the row. Past the open width the outermost entry's
29
+ * colour, painted beside it, fills the rest out to that edge. On a confirmed
30
+ * full swipe it slides to the row's edge. While an entry covers the panel, its
31
+ * colour fills the track and the others hide. So no entry's colour shows behind
32
+ * or between other entries. No wrapper holds the entries, and the colours are
33
+ * pseudo-elements.
34
+ *
35
+ * SYNC: the property names are useSwipeAction.ts's.
36
+ */
37
+ import { useEffect, useRef } from 'react';
38
+ import * as stylex from '@stylexjs/stylex';
39
+ import "../theme/tokens.stylex.js";
40
+ import { fontWeightVars, typographyVars, colorVars, spacingVars, typeScaleVars } from "../theme/tokens.stylex.js";
41
+ import { mergeProps } from "../utils/mergeProps.js";
42
+ import { themeProps } from "../utils/themeProps.js";
43
+ import { disabledInteractionProps } from "../utils/disabledInteraction.js";
44
+ import { focusOutlineProps } from "../utils/focusOutline.stylex.js";
45
+ import { isSwipeOpen, useSwipeAction } from "./useSwipeAction.js";
46
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
47
+ // =============================================================================
48
+ // Styles
49
+ // =============================================================================
50
+
51
+ /** The travel the gesture writes on the root, physical px (useSwipeAction.ts). */
52
+ const SWIPE_TRAVEL = 'var(--_item-swipe-travel, 0px)';
53
+ /** How far a full swipe has confirmed, 0 to 1 (useSwipeAction.ts). */
54
+ const SWIPE_CONFIRM = 'var(--_item-swipe-confirm, 0)';
55
+ // The side's geometry the gesture writes on its window (useSwipeAction.ts):
56
+ // the pin, its physical sign, its open width and the outermost entry's slide.
57
+ const SWIPE_PIN = 'var(--_item-swipe-pin, 0px)';
58
+ const SWIPE_SIGN = 'var(--_item-swipe-sign, 1)';
59
+ const SWIPE_OPEN = 'var(--_item-swipe-open, 0px)';
60
+ const SWIPE_SLIDE = 'var(--_item-swipe-slide, 0px)';
61
+ /**
62
+ * Where the entries sit against the track. They move back by the travel the
63
+ * track moves, so they stay pinned at the outer edge. That holds until the row
64
+ * has uncovered them all, at the open width; past it they ride the row.
65
+ */
66
+ const SWIPE_ENTRIES_X = `calc(${SWIPE_PIN} - ${SWIPE_SIGN} * min(${SWIPE_SIGN} * ${SWIPE_TRAVEL}, ${SWIPE_OPEN}))`;
67
+ const styles = {
68
+ swipeTrack: {
69
+ kVAEAm: "x10l6tqk",
70
+ kYYq5F: "x10no89f",
71
+ kzqmXN: "x75ztot",
72
+ kVQacm: "x7giv3",
73
+ kaIpWk: "x1pjcqnp",
74
+ k1xSpc: "x78zum5",
75
+ kHBbk8: "xc8icb0",
76
+ kWkggS: "x10xzikg",
77
+ k3aq6I: "x1kncwj0",
78
+ kgeoSG: "x1cpjm7i",
79
+ kEoFBp: "x1hmns74",
80
+ kFcpXp: "xxx281p",
81
+ kxmVGU: "xy5mcqj",
82
+ k5QlbN: "x124lp2h",
83
+ km8f2m: "xkk1bqk",
84
+ $$css: true
85
+ },
86
+ swipeTrackCovered: {
87
+ k5QlbN: "xfbg1o9",
88
+ $$css: true
89
+ },
90
+ swipeTrackLeading: {
91
+ kt4wiu: "x1eu7cjg",
92
+ kXwgrk: "x15zctf7",
93
+ $$css: true
94
+ },
95
+ swipeTrackTrailing: {
96
+ kLqNvP: "x2hswfz",
97
+ $$css: true
98
+ },
99
+ swipeEntry: {
100
+ k3aq6I: "x1bdunyo",
101
+ kmuXW: "x2lah0s",
102
+ kfzvcC: "x67bb7w",
103
+ k1xSpc: "x78zum5",
104
+ kXwgrk: "xdt5ytf",
105
+ kGNEyG: "x6s0dn4",
106
+ kjj79g: "xl56j7k",
107
+ kOIVth: "xzye2dw",
108
+ k7Eaqz: "x187xtus",
109
+ kZKoxP: "x5yr21d",
110
+ kg3NbH: "xrrkdod",
111
+ kB7OPa: "x9f619",
112
+ kogj98: "x1ghz6dp",
113
+ kMzoRj: "xc342km",
114
+ ksu8eU: "xng3xce",
115
+ kysU6D: "xjyslct",
116
+ kkrTdU: "x1ypdohk x16khyan",
117
+ kMv6JI: "x9ynric",
118
+ kGuDYH: "x141an7d",
119
+ k63SB2: "x1e4wzip",
120
+ kLWn49: "x1ltkj2j",
121
+ khDVqt: "xuxw1ft",
122
+ $$css: true
123
+ },
124
+ swipeEntryCovered: {
125
+ kSiTet: "xg01cxk",
126
+ $$css: true
127
+ },
128
+ swipeEntryDisabled: {
129
+ ku685b: "xj12m9j",
130
+ $$css: true
131
+ },
132
+ swipeOuterEntry: {
133
+ kVAEAm: "x1n2onr6",
134
+ k3aq6I: "xj2142y",
135
+ $$css: true
136
+ },
137
+ swipeOuterEntryLeading: {
138
+ k5JduY: "x1s928wv",
139
+ kwXMNM: "x1j6awrg",
140
+ kSy8m5: "xd54j2p",
141
+ kH8aOt: "x8m5ogj",
142
+ kkgrvl: "x1ng0ck5",
143
+ ks3ayO: "x1pvq41x",
144
+ kloYau: "x2q1x1w",
145
+ $$css: true
146
+ },
147
+ swipeOuterEntryTrailing: {
148
+ k5JduY: "x1s928wv",
149
+ kwXMNM: "x1j6awrg",
150
+ kSy8m5: "xd54j2p",
151
+ kc1e00: "x1qyz1mp",
152
+ kkgrvl: "x1ng0ck5",
153
+ ks3ayO: "x1pvq41x",
154
+ kloYau: "x2q1x1w",
155
+ $$css: true
156
+ }
157
+ };
158
+
159
+ // A verb's colour: ordinary, the one you mean, the dangerous one. The
160
+ // outermost entry's fills the row on a slide-out (swipeOuterEntry).
161
+ const swipeVariantStyles = {
162
+ neutral: {
163
+ kWkggS: "x17x4s8c",
164
+ kMwMTN: "x1tgivj0",
165
+ $$css: true
166
+ },
167
+ accent: {
168
+ kWkggS: "x1ewilqj",
169
+ kMwMTN: "x17wrial",
170
+ $$css: true
171
+ },
172
+ destructive: {
173
+ kWkggS: "x1pjz0fi",
174
+ kMwMTN: "x1m024r3",
175
+ kMzoRj: "xc342km x13rsnn2",
176
+ ksu8eU: "xng3xce xx61lck",
177
+ kVAM5u: "x1w1tqly",
178
+ $$css: true
179
+ }
180
+ };
181
+
182
+ // The track's cover fill: the covering entry's colour.
183
+ const swipeTrackFillStyles = {
184
+ neutral: {
185
+ kLkRvE: "xgpd5ji",
186
+ $$css: true
187
+ },
188
+ accent: {
189
+ kLkRvE: "x1tzqye7",
190
+ $$css: true
191
+ },
192
+ destructive: {
193
+ kLkRvE: "x177gpuc",
194
+ $$css: true
195
+ }
196
+ };
197
+
198
+ // =============================================================================
199
+ // Component
200
+ // =============================================================================
201
+
202
+ /** A row's actions as their ids, side by side: what tells a change of actions. */
203
+ function idsKeyOf(leading, trailing) {
204
+ const ids = entries => entries.map(entry => entry.id ?? '').join('\u0000');
205
+ return `${ids(leading)}\u0001${ids(trailing)}`;
206
+ }
207
+
208
+ /**
209
+ * The swipe half of a row with swipe actions: both panels, rendered into the
210
+ * root the row owns, and the gesture that drives that root.
211
+ */
212
+ export default function SwipeActionsLayer({
213
+ onBridge,
214
+ leading,
215
+ trailing,
216
+ behavior,
217
+ itemKey
218
+ }) {
219
+ // The hook keeps the newest of these callbacks, so each reads the entries
220
+ // of the render it came from.
221
+ const outermostOf = side => {
222
+ const entries = side === 'leading' ? leading : trailing;
223
+ return entries[entries.length - 1];
224
+ };
225
+ const swipe = useSwipeAction({
226
+ behavior,
227
+ // A disabled outermost entry cannot fire, so a full swipe never confirms
228
+ // toward it.
229
+ canConfirm: side => {
230
+ const entry = outermostOf(side);
231
+ return entry != null && entry.isDisabled !== true;
232
+ },
233
+ fireOutermost: side => {
234
+ const entry = outermostOf(side);
235
+ if (entry == null || entry.isDisabled === true) {
236
+ return false;
237
+ }
238
+ void entry.onActivate({
239
+ id: entry.id ?? '',
240
+ itemKey
241
+ });
242
+ return entry.hasRemoval === true;
243
+ },
244
+ sides: {
245
+ leading: leading.length,
246
+ trailing: trailing.length
247
+ }
248
+ });
249
+ const {
250
+ onKeyDown
251
+ } = swipe;
252
+ // The Effect publishes the layer's key handler to the row's bridge and clears
253
+ // it when the layer leaves. Both are stable, so it runs once per layer.
254
+ useEffect(() => {
255
+ onBridge?.({
256
+ onKeyDown
257
+ });
258
+ return () => onBridge?.(null);
259
+ }, [onBridge, onKeyDown]);
260
+ // A new swipe value with the same ids keeps the row as it is. One with
261
+ // other ids shows other actions, so an open row closes.
262
+ const idsKey = idsKeyOf(leading, trailing);
263
+ const idsRef = useRef(idsKey);
264
+ const {
265
+ close
266
+ } = swipe;
267
+ // The Effect settles the row's snap-point drag to rest when the actions'
268
+ // ids change.
269
+ useEffect(() => {
270
+ if (idsRef.current !== idsKey) {
271
+ idsRef.current = idsKey;
272
+ close();
273
+ }
274
+ }, [close, idsKey]);
275
+ // Open from the release that opens it (`isSwipeOpen`), as UIKit counts it:
276
+ // an entry the finger can see while the row springs open is tappable.
277
+ const isOpen = isSwipeOpen(swipe.state);
278
+
279
+ // A side's panel: entries as real buttons under `reveal`, presentational
280
+ // blocks under `commit`. It is out of the accessibility tree and the tab
281
+ // order except while the row is open on its side. So the row keeps one tab
282
+ // stop, and the other side's entries, out of sight behind the row, are never
283
+ // reached. A mouse drag never opens it.
284
+ const renderSwipePanel = (side, entries) => {
285
+ if (entries.length === 0) {
286
+ return null;
287
+ }
288
+ const outer = entries[entries.length - 1];
289
+ const isCommit = behavior === 'commit';
290
+ const isLive = isOpen && swipe.state.side === side && !isCommit;
291
+ const refs = swipe.panelRefs[side];
292
+ const {
293
+ cover
294
+ } = swipe.state;
295
+ const coverIndex = swipe.state.side === side && cover != null && cover < entries.length ? cover : null;
296
+ const renderEntry = (entry, index) => {
297
+ const variant = entry.variant ?? 'accent';
298
+ const key = entry.id ?? entry.label;
299
+ // The outermost entry is the full swipe's moving part itself.
300
+ const isOuter = entry === outer;
301
+ const ref = isOuter ? refs.outer : refs.entry(key);
302
+ const content = /*#__PURE__*/_jsxs(_Fragment, {
303
+ children: [entry.icon, /*#__PURE__*/_jsx("span", {
304
+ children: entry.label
305
+ })]
306
+ });
307
+ const entryStyles = [styles.swipeEntry, swipeVariantStyles[variant], entry.isDisabled === true && styles.swipeEntryDisabled, coverIndex != null && index !== coverIndex && styles.swipeEntryCovered, isOuter && styles.swipeOuterEntry, isOuter && (side === 'leading' ? styles.swipeOuterEntryLeading : styles.swipeOuterEntryTrailing)];
308
+ if (isCommit) {
309
+ return /*#__PURE__*/_jsx("span", {
310
+ ref: ref,
311
+ ...mergeProps(themeProps('item-swipe-action', {
312
+ variant
313
+ }), stylex.props(...entryStyles)),
314
+ children: content
315
+ }, key);
316
+ }
317
+ return /*#__PURE__*/_jsx("button", {
318
+ ref: ref,
319
+ type: "button",
320
+ "aria-disabled": entry.isDisabled === true ? true : undefined,
321
+ onClick: () => swipe.activateEntry(() => {
322
+ void entry.onActivate({
323
+ id: entry.id ?? '',
324
+ itemKey
325
+ });
326
+ }, entry.hasRemoval === true, index)
327
+ // A disabled entry stays focusable while the row rests open but is
328
+ // inert: it runs no `onActivate` and its click does not reach the
329
+ // row.
330
+ ,
331
+ ...(entry.isDisabled === true ? disabledInteractionProps() : null),
332
+ ...mergeProps(themeProps('item-swipe-action', {
333
+ variant
334
+ }), focusOutlineProps.focusVisible(...entryStyles)),
335
+ children: content
336
+ }, key);
337
+ };
338
+ return /*#__PURE__*/_jsx("div", {
339
+ ref: refs.panel,
340
+ "data-swipe-panel": side,
341
+ inert: isLive ? undefined : true,
342
+ "aria-hidden": isCommit ? true : undefined,
343
+ ...{
344
+ className: "x10l6tqk x10no89f x17y0mx6 x7giv3 x1pjcqnp x47corl x145au52"
345
+ },
346
+ children: /*#__PURE__*/_jsx("div", {
347
+ ...mergeProps(themeProps('item-swipe-panel', {
348
+ side
349
+ }), stylex.props(styles.swipeTrack, side === 'leading' ? styles.swipeTrackLeading : styles.swipeTrackTrailing, coverIndex != null && styles.swipeTrackCovered, swipeTrackFillStyles[(coverIndex != null ? entries[coverIndex] : outer).variant ?? 'accent'])),
350
+ children: entries.map((entry, index) => renderEntry(entry, index))
351
+ })
352
+ }, side);
353
+ };
354
+ return /*#__PURE__*/_jsxs(_Fragment, {
355
+ children: [renderSwipePanel('leading', leading), renderSwipePanel('trailing', trailing)]
356
+ });
357
+ }
358
+ SwipeActionsLayer.displayName = 'SwipeActionsLayer';
@@ -0,0 +1,26 @@
1
+ import { type CreateSwipeOptions, type Swipe } from './swipeHost.js';
2
+ /**
3
+ * Makes a row's swipe actions: the verbs a sideways drag uncovers on each side,
4
+ * declared as data, and what a swipe does. Pass the result as `swipe` on `Item`
5
+ * or `ListItem`. A plain function, not a hook, pure and cheap: callable at
6
+ * module scope, outside a render, and on the server. It does no DOM work when
7
+ * imported or called. Each action's `onActivate` receives the action's `id`
8
+ * and the row's `itemKey`. So one definition at module scope serves every
9
+ * row. A definition whose handlers need component state goes in `useMemo`.
10
+ * The swipe carries no built-in text: every name it exposes is a caller's
11
+ * `label`.
12
+ *
13
+ * @example
14
+ * ```
15
+ * const mailSwipe = createSwipe({
16
+ * trailing: [
17
+ * {id: 'archive', label: 'Archive', onActivate: ({itemKey}) => archive(itemKey)},
18
+ * {id: 'delete', label: 'Delete', onActivate: ({itemKey}) => remove(itemKey), variant: 'destructive', hasRemoval: true},
19
+ * ],
20
+ * });
21
+ *
22
+ * <ListItem label="Inbox" itemKey={message.id} swipe={mailSwipe} />
23
+ * ```
24
+ */
25
+ export declare function createSwipe<const Id extends string>(options: CreateSwipeOptions<Id>): Swipe<Id>;
26
+ //# sourceMappingURL=createSwipe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSwipe.d.ts","sourceRoot":"","sources":["../../src/Swipe/createSwipe.ts"],"names":[],"mappings":"AAoBA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,KAAK,EAEX,MAAM,aAAa,CAAC;AAwBrB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EACjD,OAAO,EAAE,kBAAkB,CAAC,EAAE,CAAC,GAC9B,KAAK,CAAC,EAAE,CAAC,CAqCX"}
@@ -0,0 +1,97 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file createSwipe.ts
7
+ * @input The declared actions per side and the behavior; SwipeActionsLayer
8
+ * (the panels and the gesture), and the row root's style
9
+ * @output Exports createSwipe, which makes the Swipe value a row takes as
10
+ * `swipe`, carrying the runtime a row hands its root to
11
+ * @position The public entry of swipe actions. The module brings the gesture
12
+ * core, the animator pieces, the panels and the rules for which rows the
13
+ * swipe serves. So a row ships them only when its caller uses swipe actions.
14
+ * Tested by createSwipe.test.ts and through Item.test.tsx.
15
+ */
16
+ import { createElement } from 'react';
17
+ import { devWarn } from "../utils/devWarning.js";
18
+ import SwipeActionsLayer from "./SwipeActionsLayer.js";
19
+ import { swipeHostStyles } from "./swipeHost.stylex.js";
20
+ import { makeSwipe } from "./swipeHost.js";
21
+
22
+ /**
23
+ * Roles whose content model permits interactive descendants, so a swipe
24
+ * panel's buttons may live inside the row. A row with no role at all
25
+ * qualifies too; `option`, the `menuitem*` roles and the rest do not.
26
+ */
27
+ const SWIPE_ROLES = new Set(['listitem']);
28
+
29
+ /**
30
+ * Whether swipe actions serve a row. They do where its role permits interactive
31
+ * descendants, since a panel's buttons are such descendants. They do not serve
32
+ * a disabled row, a row that is a nested control's enlarged target, or a root
33
+ * that is itself a link.
34
+ */
35
+ function serves({
36
+ role,
37
+ isDisabled,
38
+ isDelegate,
39
+ isLinkRoot
40
+ }) {
41
+ return !isDisabled && !isDelegate && !isLinkRoot && (role == null || SWIPE_ROLES.has(role));
42
+ }
43
+
44
+ /**
45
+ * Makes a row's swipe actions: the verbs a sideways drag uncovers on each side,
46
+ * declared as data, and what a swipe does. Pass the result as `swipe` on `Item`
47
+ * or `ListItem`. A plain function, not a hook, pure and cheap: callable at
48
+ * module scope, outside a render, and on the server. It does no DOM work when
49
+ * imported or called. Each action's `onActivate` receives the action's `id`
50
+ * and the row's `itemKey`. So one definition at module scope serves every
51
+ * row. A definition whose handlers need component state goes in `useMemo`.
52
+ * The swipe carries no built-in text: every name it exposes is a caller's
53
+ * `label`.
54
+ *
55
+ * @example
56
+ * ```
57
+ * const mailSwipe = createSwipe({
58
+ * trailing: [
59
+ * {id: 'archive', label: 'Archive', onActivate: ({itemKey}) => archive(itemKey)},
60
+ * {id: 'delete', label: 'Delete', onActivate: ({itemKey}) => remove(itemKey), variant: 'destructive', hasRemoval: true},
61
+ * ],
62
+ * });
63
+ *
64
+ * <ListItem label="Inbox" itemKey={message.id} swipe={mailSwipe} />
65
+ * ```
66
+ */
67
+ export function createSwipe(options) {
68
+ const leading = Object.freeze([...(options.leading ?? [])]);
69
+ const trailing = Object.freeze([...(options.trailing ?? [])]);
70
+ const behavior = options.swipeBehavior ?? 'reveal';
71
+ if (behavior === 'commit' && (leading.length > 1 || trailing.length > 1)) {
72
+ // A committing side never rests open, so a full swipe confirms from no
73
+ // open row.
74
+ devWarn('createSwipe', "`swipeBehavior: 'commit'` fires no entry on a side with two or more " + "entries. Give a committing side one entry, or use `swipeBehavior: 'reveal'`.");
75
+ }
76
+ const hasEntries = leading.length > 0 || trailing.length > 0;
77
+ return makeSwipe({
78
+ leading,
79
+ trailing,
80
+ behavior,
81
+ serves: facts => hasEntries && serves(facts),
82
+ // A row hands its facts and its key bridge: the swipe serves it or not, and
83
+ // brings everything it serves it with. Every value uses the same layer type,
84
+ // so a new value from an inline call keeps the gesture and an open row as
85
+ // they are.
86
+ attach: (facts, onBridge) => hasEntries && serves(facts) ? {
87
+ rootStyle: swipeHostStyles.root,
88
+ layer: /*#__PURE__*/createElement(SwipeActionsLayer, {
89
+ leading,
90
+ trailing,
91
+ behavior,
92
+ itemKey: facts.itemKey,
93
+ onBridge
94
+ })
95
+ } : null
96
+ });
97
+ }
@@ -0,0 +1,3 @@
1
+ export { createSwipe } from './createSwipe.js';
2
+ export type { CreateSwipeOptions, SwipeAction, Swipe } from './swipeHost.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Swipe/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAC,kBAAkB,EAAE,WAAW,EAAE,KAAK,EAAC,MAAM,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ export { createSwipe } from "./createSwipe.js";