@astryxdesign/core 0.7.7-canary.bf14580 → 0.7.7-canary.c19ca12

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 (266) hide show
  1. package/dist/AlertDialog/AlertDialog.d.ts +4 -1
  2. package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
  3. package/dist/AlertDialog/AlertDialog.js +36 -6
  4. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  5. package/dist/BottomSheet/BottomSheet.js +76 -6
  6. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  7. package/dist/BottomSheet/BottomSheetPanel.js +23 -4
  8. package/dist/BottomSheet/bottomSheetStack.d.ts.map +1 -1
  9. package/dist/BottomSheet/bottomSheetStack.js +5 -4
  10. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
  11. package/dist/BottomSheet/useSheetGestures.js +3 -1
  12. package/dist/Button/Button.d.ts.map +1 -1
  13. package/dist/Button/Button.js +47 -3
  14. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  15. package/dist/CheckboxInput/CheckboxInput.js +13 -2
  16. package/dist/ComplexSelector/ComplexSelector.d.ts +4 -1
  17. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  18. package/dist/ComplexSelector/ComplexSelector.js +14 -4
  19. package/dist/ContextMenu/ContextMenu.js +2 -2
  20. package/dist/DateInput/MonthScroller.d.ts.map +1 -1
  21. package/dist/DateInput/MonthScroller.js +13 -27
  22. package/dist/DateInput/Wheel.d.ts.map +1 -1
  23. package/dist/DateInput/Wheel.js +22 -41
  24. package/dist/Dialog/Dialog.d.ts.map +1 -1
  25. package/dist/Dialog/Dialog.js +7 -31
  26. package/dist/Field/Field.js +2 -2
  27. package/dist/HoverCard/HoverCard.d.ts +4 -3
  28. package/dist/HoverCard/HoverCard.d.ts.map +1 -1
  29. package/dist/HoverCard/HoverCard.js +27 -2
  30. package/dist/HoverCard/useHoverCard.d.ts +5 -4
  31. package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
  32. package/dist/HoverCard/useHoverCard.js +17 -31
  33. package/dist/Icon/Icon.d.ts +5 -1
  34. package/dist/Icon/Icon.d.ts.map +1 -1
  35. package/dist/Icon/Icon.js +5 -2
  36. package/dist/Layer/layerAnimations.stylex.d.ts +7 -8
  37. package/dist/Layer/layerAnimations.stylex.d.ts.map +1 -1
  38. package/dist/Layer/layerAnimations.stylex.js +25 -20
  39. package/dist/Layer/usePressPin.d.ts +17 -5
  40. package/dist/Layer/usePressPin.d.ts.map +1 -1
  41. package/dist/Layer/usePressPin.js +62 -12
  42. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  43. package/dist/Lightbox/Lightbox.js +18 -0
  44. package/dist/PowerSearch/PowerSearch.d.ts +36 -3
  45. package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
  46. package/dist/PowerSearch/PowerSearch.js +522 -269
  47. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +100 -0
  48. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -0
  49. package/dist/PowerSearch/PowerSearchBottomSheet.js +1913 -0
  50. package/dist/PowerSearch/PowerSearchEditPopover.d.ts +32 -1
  51. package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
  52. package/dist/PowerSearch/PowerSearchEditPopover.js +17 -6
  53. package/dist/PowerSearch/PowerSearchValueEditor.d.ts +38 -3
  54. package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
  55. package/dist/PowerSearch/PowerSearchValueEditor.js +170 -61
  56. package/dist/PowerSearch/formatFilterValue.d.ts +7 -0
  57. package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
  58. package/dist/PowerSearch/formatFilterValue.js +11 -1
  59. package/dist/PowerSearch/formatTokenValue.d.ts +28 -0
  60. package/dist/PowerSearch/formatTokenValue.d.ts.map +1 -0
  61. package/dist/PowerSearch/formatTokenValue.js +160 -0
  62. package/dist/PowerSearch/powerSearchSheetUtils.d.ts +65 -0
  63. package/dist/PowerSearch/powerSearchSheetUtils.d.ts.map +1 -0
  64. package/dist/PowerSearch/powerSearchSheetUtils.js +168 -0
  65. package/dist/RadioList/RadioList.d.ts.map +1 -1
  66. package/dist/RadioList/RadioList.js +3 -2
  67. package/dist/RadioList/RadioListItem.d.ts +1 -1
  68. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  69. package/dist/RadioList/RadioListItem.js +5 -3
  70. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -1
  71. package/dist/SegmentedControl/useSegmentedSelectionMotion.js +3 -3
  72. package/dist/Slider/sliderTouchController.js +2 -2
  73. package/dist/Spinner/Spinner.d.ts +1 -1
  74. package/dist/Spinner/Spinner.d.ts.map +1 -1
  75. package/dist/Spinner/Spinner.js +60 -58
  76. package/dist/Switch/useSwitchTouch.js +4 -4
  77. package/dist/Table/BaseTable.d.ts.map +1 -1
  78. package/dist/Table/BaseTable.js +29 -8
  79. package/dist/TextInput/TextInput.d.ts +2 -2
  80. package/dist/TextInput/TextInput.d.ts.map +1 -1
  81. package/dist/TextInput/TextInput.js +10 -7
  82. package/dist/Toast/Toast.d.ts +11 -1
  83. package/dist/Toast/Toast.d.ts.map +1 -1
  84. package/dist/Toast/Toast.js +25 -15
  85. package/dist/Toast/ToastViewport.d.ts.map +1 -1
  86. package/dist/Toast/ToastViewport.js +94 -34
  87. package/dist/Toast/types.d.ts +9 -3
  88. package/dist/Toast/types.d.ts.map +1 -1
  89. package/dist/Token/Token.d.ts +2 -2
  90. package/dist/Token/Token.d.ts.map +1 -1
  91. package/dist/Token/Token.js +12 -4
  92. package/dist/Token/TokenNamingContext.d.ts +14 -0
  93. package/dist/Token/TokenNamingContext.d.ts.map +1 -0
  94. package/dist/Token/TokenNamingContext.js +23 -0
  95. package/dist/Tooltip/useTooltip.d.ts +19 -1
  96. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  97. package/dist/Tooltip/useTooltip.js +34 -53
  98. package/dist/Typeahead/TypeaheadItem.d.ts +2 -1
  99. package/dist/Typeahead/TypeaheadItem.d.ts.map +1 -1
  100. package/dist/animator/createAnimator.d.ts +98 -0
  101. package/dist/animator/createAnimator.d.ts.map +1 -0
  102. package/dist/animator/createAnimator.js +259 -0
  103. package/dist/astryx.css +22 -6
  104. package/dist/gestures/GestureHost.d.ts +27 -1
  105. package/dist/gestures/GestureHost.d.ts.map +1 -1
  106. package/dist/gestures/GestureHost.js +90 -8
  107. package/dist/gestures/PressTracker.d.ts.map +1 -1
  108. package/dist/gestures/PressTracker.js +4 -3
  109. package/dist/hooks/actionGroupTracker.d.ts +4 -1
  110. package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
  111. package/dist/hooks/actionGroupTracker.js +13 -3
  112. package/dist/hooks/index.d.ts +1 -0
  113. package/dist/hooks/index.d.ts.map +1 -1
  114. package/dist/hooks/index.js +1 -0
  115. package/dist/hooks/pressGroupContext.d.ts +6 -0
  116. package/dist/hooks/pressGroupContext.d.ts.map +1 -0
  117. package/dist/hooks/pressGroupContext.js +20 -0
  118. package/dist/hooks/useActionGroupTracking.d.ts +53 -0
  119. package/dist/hooks/useActionGroupTracking.d.ts.map +1 -0
  120. package/dist/hooks/useActionGroupTracking.js +174 -0
  121. package/dist/hooks/useAnimator.d.ts +41 -0
  122. package/dist/hooks/useAnimator.d.ts.map +1 -0
  123. package/dist/hooks/useAnimator.js +70 -0
  124. package/dist/hooks/useAttachment.d.ts +1 -1
  125. package/dist/hooks/useAttachment.js +1 -1
  126. package/dist/hooks/useInputStatusIcon.d.ts +1 -1
  127. package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
  128. package/dist/hooks/useInputStatusIcon.js +2 -2
  129. package/dist/hooks/useLongPress.d.ts +6 -2
  130. package/dist/hooks/useLongPress.d.ts.map +1 -1
  131. package/dist/hooks/useLongPress.js +95 -15
  132. package/dist/hooks/useMenuPress.d.ts.map +1 -1
  133. package/dist/hooks/useMenuPress.js +4 -2
  134. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts +8 -0
  135. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts.map +1 -0
  136. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.js +42 -0
  137. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
  138. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +6 -0
  139. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts +8 -0
  140. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts.map +1 -0
  141. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.js +14 -0
  142. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  143. package/dist/i18n/generated-locales/en.generated.js +30 -0
  144. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  145. package/dist/i18n/generated-locales/pseudo.generated.js +30 -0
  146. package/dist/index.d.ts +1 -0
  147. package/dist/index.d.ts.map +1 -1
  148. package/dist/index.js +4 -0
  149. package/dist/internal/indicatorPress.stylex.d.ts +20 -0
  150. package/dist/internal/indicatorPress.stylex.d.ts.map +1 -0
  151. package/dist/internal/indicatorPress.stylex.js +26 -0
  152. package/dist/motion/animator.d.ts +14 -14
  153. package/dist/motion/animator.d.ts.map +1 -1
  154. package/dist/motion/animator.js +41 -18
  155. package/dist/motion/reducedMotion.d.ts +24 -0
  156. package/dist/motion/reducedMotion.d.ts.map +1 -1
  157. package/dist/motion/reducedMotion.js +78 -1
  158. package/dist/motion/uikit/alert.d.ts +41 -0
  159. package/dist/motion/uikit/alert.d.ts.map +1 -0
  160. package/dist/motion/uikit/alert.js +43 -0
  161. package/dist/privateAttributes/pressGroupItem.stylex.d.ts +15 -0
  162. package/dist/privateAttributes/pressGroupItem.stylex.d.ts.map +1 -0
  163. package/dist/privateAttributes/pressGroupItem.stylex.js +23 -0
  164. package/dist/utils/clickGuard.d.ts +8 -1
  165. package/dist/utils/clickGuard.d.ts.map +1 -1
  166. package/dist/utils/clickGuard.js +24 -1
  167. package/dist/utils/dateParser.d.ts.map +1 -1
  168. package/dist/utils/dateParser.js +12 -0
  169. package/dist/utils/focusReturn.d.ts +15 -0
  170. package/dist/utils/focusReturn.d.ts.map +1 -1
  171. package/dist/utils/focusReturn.js +28 -0
  172. package/dist/utils/interactionOverlay.stylex.d.ts +3 -2
  173. package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
  174. package/dist/utils/interactionOverlay.stylex.js +3 -2
  175. package/dist/utils/pressFeedback.d.ts.map +1 -1
  176. package/dist/utils/pressFeedback.js +19 -6
  177. package/dist/utils/triggerFocus.d.ts +36 -0
  178. package/dist/utils/triggerFocus.d.ts.map +1 -0
  179. package/dist/utils/triggerFocus.js +65 -0
  180. package/locales/en.json +120 -0
  181. package/locales/pseudo.json +90 -0
  182. package/package.json +9 -4
  183. package/src/AlertDialog/AlertDialog.doc.mjs +2 -2
  184. package/src/AlertDialog/AlertDialog.tsx +37 -5
  185. package/src/BottomSheet/BottomSheet.tsx +85 -5
  186. package/src/BottomSheet/BottomSheetPanel.tsx +40 -5
  187. package/src/BottomSheet/bottomSheetStack.ts +8 -4
  188. package/src/BottomSheet/useSheetGestures.ts +3 -1
  189. package/src/Button/Button.tsx +63 -5
  190. package/src/CheckboxInput/CheckboxInput.doc.mjs +18 -0
  191. package/src/CheckboxInput/CheckboxInput.tsx +36 -9
  192. package/src/ComplexSelector/ComplexSelector.tsx +20 -5
  193. package/src/ContextMenu/ContextMenu.tsx +2 -2
  194. package/src/DateInput/MonthScroller.tsx +18 -22
  195. package/src/DateInput/Wheel.tsx +30 -32
  196. package/src/Dialog/Dialog.tsx +10 -31
  197. package/src/Field/Field.tsx +2 -2
  198. package/src/HoverCard/HoverCard.doc.mjs +4 -2
  199. package/src/HoverCard/HoverCard.tsx +35 -4
  200. package/src/HoverCard/useHoverCard.doc.mjs +178 -36
  201. package/src/HoverCard/useHoverCard.tsx +46 -52
  202. package/src/Icon/Icon.doc.mjs +49 -8
  203. package/src/Icon/Icon.tsx +15 -7
  204. package/src/Layer/layerAnimations.stylex.ts +24 -16
  205. package/src/Layer/usePressPin.ts +81 -15
  206. package/src/Lightbox/Lightbox.tsx +18 -0
  207. package/src/PowerSearch/PowerSearch.doc.mjs +54 -5
  208. package/src/PowerSearch/PowerSearch.tsx +734 -288
  209. package/src/PowerSearch/PowerSearchBottomSheet.tsx +2515 -0
  210. package/src/PowerSearch/PowerSearchEditPopover.tsx +28 -6
  211. package/src/PowerSearch/PowerSearchValueEditor.tsx +203 -38
  212. package/src/PowerSearch/formatFilterValue.ts +18 -1
  213. package/src/PowerSearch/formatTokenValue.ts +215 -0
  214. package/src/PowerSearch/powerSearchSheetUtils.ts +224 -0
  215. package/src/RadioList/RadioList.tsx +3 -2
  216. package/src/RadioList/RadioListItem.tsx +5 -3
  217. package/src/SegmentedControl/useSegmentedSelectionMotion.ts +6 -3
  218. package/src/Slider/sliderTouchController.ts +2 -2
  219. package/src/Spinner/Spinner.tsx +77 -63
  220. package/src/Switch/useSwitchTouch.ts +4 -4
  221. package/src/Table/BaseTable.tsx +46 -12
  222. package/src/TextInput/TextInput.tsx +11 -10
  223. package/src/Toast/Toast.doc.mjs +4 -3
  224. package/src/Toast/Toast.tsx +52 -32
  225. package/src/Toast/ToastViewport.tsx +121 -35
  226. package/src/Toast/types.ts +9 -3
  227. package/src/Token/Token.tsx +13 -4
  228. package/src/Token/TokenNamingContext.ts +28 -0
  229. package/src/Tooltip/useTooltip.doc.mjs +24 -0
  230. package/src/Tooltip/useTooltip.tsx +61 -56
  231. package/src/Typeahead/TypeaheadItem.doc.mjs +6 -3
  232. package/src/Typeahead/TypeaheadItem.tsx +2 -1
  233. package/src/animator/createAnimator.doc.mjs +153 -0
  234. package/src/animator/createAnimator.ts +324 -0
  235. package/src/gestures/GestureHost.ts +105 -10
  236. package/src/gestures/PressTracker.ts +4 -3
  237. package/src/gestures/README.md +7 -1
  238. package/src/hooks/actionGroupTracker.ts +20 -5
  239. package/src/hooks/index.ts +2 -0
  240. package/src/hooks/pressGroupContext.ts +21 -0
  241. package/src/hooks/useActionGroupTracking.ts +224 -0
  242. package/src/hooks/useAnimator.doc.mjs +109 -0
  243. package/src/hooks/useAnimator.ts +67 -0
  244. package/src/hooks/useAttachment.ts +1 -1
  245. package/src/hooks/useInputStatusIcon.tsx +3 -2
  246. package/src/hooks/useLongPress.doc.mjs +2 -2
  247. package/src/hooks/useLongPress.ts +136 -15
  248. package/src/hooks/useMenuPress.ts +8 -2
  249. package/src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts +43 -0
  250. package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +6 -0
  251. package/src/i18n/generated-english/PowerSearch/formatTokenValue.generated.ts +15 -0
  252. package/src/i18n/generated-locales/en.generated.ts +41 -0
  253. package/src/i18n/generated-locales/pseudo.generated.ts +42 -0
  254. package/src/index.ts +13 -0
  255. package/src/internal/indicatorPress.stylex.ts +24 -0
  256. package/src/motion/README.md +8 -5
  257. package/src/motion/animator.ts +61 -29
  258. package/src/motion/reducedMotion.ts +79 -1
  259. package/src/motion/uikit/alert.ts +43 -0
  260. package/src/privateAttributes/pressGroupItem.stylex.ts +23 -0
  261. package/src/utils/clickGuard.ts +37 -1
  262. package/src/utils/dateParser.ts +16 -0
  263. package/src/utils/focusReturn.ts +30 -0
  264. package/src/utils/interactionOverlay.stylex.ts +3 -2
  265. package/src/utils/pressFeedback.ts +19 -6
  266. package/src/utils/triggerFocus.ts +80 -0
@@ -0,0 +1,215 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @fileoverview The text a PowerSearch filter token shows for a value.
5
+ *
6
+ * @input `OperatorValue`, `FilterValue`, a width budget, and the locale.
7
+ * @output `formatTokenValueText` — one string, or null for an empty value.
8
+ * @position Shared by the token itself (`PowerSearch.tsx`) and the sheet
9
+ * presentation's Filters rows and removal announcement
10
+ * (`PowerSearchBottomSheet.tsx`), so every reading of a value on the field
11
+ * uses the same words and the same zone handling.
12
+ */
13
+
14
+ import type {OperatorValue, FilterValue, EnumItem} from './types';
15
+ import type {Locale, TranslatorFn} from '../i18n';
16
+ import {truncateCharacters} from '../utils/characters';
17
+ import {
18
+ formatDateAbsoluteCompact,
19
+ formatSharedNumber,
20
+ } from './formatFilterValue';
21
+ import {registerEnglishFallback} from '../i18n/englishFallback';
22
+ import english from '../i18n/generated-english/PowerSearch/formatTokenValue.generated';
23
+
24
+ registerEnglishFallback(english);
25
+
26
+ type ListFormatFn = (items: ReadonlyArray<string>) => string;
27
+
28
+ function truncateString(value: string, limit: number): string {
29
+ // Same semantics as before — strings within limit + 3 pass through, longer
30
+ // ones cut to limit + '...' — but counted in characters, not code units.
31
+ return truncateCharacters(value, limit + 3, '...');
32
+ }
33
+
34
+ function getEnumLabel(values: ReadonlyArray<EnumItem>, value: string): string {
35
+ return values.find(v => v.value === value)?.label ?? value;
36
+ }
37
+
38
+ // Intl's maximum fraction cap: no number the row formats is rounded.
39
+ const MAX_FRACTION_DIGITS = 100;
40
+
41
+ // Whether a locale writes a number with the token's own numerals: Latin
42
+ // digits and a `.` decimal mark, so `String(value)` is already the locale's
43
+ // reading. Probed once per locale through the shared number helper.
44
+ const tokenNumeralLocales = new Map<string, boolean>();
45
+ function usesTokenNumerals(locale: Locale): boolean {
46
+ let uses = tokenNumeralLocales.get(locale);
47
+ if (uses == null) {
48
+ uses =
49
+ formatSharedNumber(1234567.5, locale, {
50
+ useGrouping: false,
51
+ maximumFractionDigits: MAX_FRACTION_DIGITS,
52
+ }) === '1234567.5';
53
+ tokenNumeralLocales.set(locale, uses);
54
+ }
55
+ return uses;
56
+ }
57
+
58
+ // A number as the token reads it. Where the locale writes Latin digits and a
59
+ // `.` decimal mark, use the token's own text, `String(value)`. Elsewhere, use
60
+ // the locale's digits and decimal mark, with no grouping and no rounding: the
61
+ // fraction cap is Intl's maximum, so `1e-21` keeps its digits.
62
+ function formatNumberAsToken(value: number, locale: Locale): string {
63
+ return usesTokenNumerals(locale)
64
+ ? String(value)
65
+ : formatSharedNumber(value, locale, {
66
+ useGrouping: false,
67
+ maximumFractionDigits: MAX_FRACTION_DIGITS,
68
+ });
69
+ }
70
+
71
+ // The summaries, lists, and numbers the token writes as English literals, and
72
+ // the locale-aware readings of the same: with a translator (the sheet
73
+ // presentation's rows and announcements) the summaries resolve through the
74
+ // catalog, lists through the provider locale's list format, and numbers
75
+ // through its number format; without one they stay the token's own literals,
76
+ // the released popover token's text. In English the two read identically.
77
+ function itemsSummary(count: number, t: TranslatorFn | undefined): string {
78
+ return t
79
+ ? t('@astryx.powersearch.valueEditor.itemsCount', {count})
80
+ : // eslint-disable-next-line @astryx/no-hardcoded-i18n-string -- the popover token's released English text; translating it is a separate stable change
81
+ `${count} items`;
82
+ }
83
+
84
+ function formatListText(
85
+ labels: ReadonlyArray<string>,
86
+ maxLength: number,
87
+ t: TranslatorFn | undefined,
88
+ formatList: ListFormatFn | undefined,
89
+ ): string | null {
90
+ if (labels.length === 0) {
91
+ return null;
92
+ }
93
+ if (labels.length === 1) {
94
+ return truncateString(labels[0], maxLength);
95
+ }
96
+ const totalLength = labels.reduce((sum, s) => sum + s.length, 0);
97
+ if (totalLength > maxLength) {
98
+ return itemsSummary(labels.length, t);
99
+ }
100
+ return formatList ? formatList(labels) : labels.join(', ');
101
+ }
102
+
103
+ /**
104
+ * The text a filter token shows for a value: the one place that decides how
105
+ * a value reads on the field, so every other reading of the same value —
106
+ * the sheet presentation's Filters rows and its removal announcement — can
107
+ * use the same words and the same zone handling. `maxLength` is the token's
108
+ * width budget; pass `Number.MAX_SAFE_INTEGER` for the untruncated text.
109
+ * With `t`, the list, date-range and nested summaries resolve through the
110
+ * catalog (`@astryx.powersearch.valueEditor.*`); without it they are the
111
+ * token's own literals. With `formatList` (the provider's list formatter),
112
+ * several labels join as a list in the locale; without it they join with
113
+ * the token's literal ", ".
114
+ */
115
+ export function formatTokenValueText(
116
+ operatorValue: OperatorValue,
117
+ filterValue: FilterValue,
118
+ maxLength: number,
119
+ locale: Locale,
120
+ t?: TranslatorFn,
121
+ formatList?: ListFormatFn,
122
+ ): string | null {
123
+ switch (filterValue.type) {
124
+ case 'empty':
125
+ return null;
126
+
127
+ case 'string':
128
+ return truncateString(filterValue.value, maxLength);
129
+
130
+ case 'integer':
131
+ case 'float':
132
+ return t
133
+ ? formatNumberAsToken(filterValue.value, locale)
134
+ : String(filterValue.value);
135
+
136
+ case 'enum':
137
+ if (operatorValue.type === 'enum') {
138
+ return truncateString(
139
+ getEnumLabel(operatorValue.values, filterValue.value),
140
+ maxLength,
141
+ );
142
+ }
143
+ return truncateString(filterValue.value, maxLength);
144
+
145
+ case 'string_list':
146
+ return formatListText(filterValue.value, maxLength, t, formatList);
147
+
148
+ case 'enum_list': {
149
+ const items = filterValue.value;
150
+ if (items.length === 0) {
151
+ return null;
152
+ }
153
+ if (operatorValue.type === 'enum_list') {
154
+ return formatListText(
155
+ items.map(v => getEnumLabel(operatorValue.values, v)),
156
+ maxLength,
157
+ t,
158
+ formatList,
159
+ );
160
+ }
161
+ if (items.length === 1) {
162
+ return truncateString(items[0], maxLength);
163
+ }
164
+ return itemsSummary(items.length, t);
165
+ }
166
+
167
+ case 'entity_list':
168
+ return formatListText(
169
+ filterValue.value.map(e => e.label),
170
+ maxLength,
171
+ t,
172
+ formatList,
173
+ );
174
+
175
+ case 'time':
176
+ return filterValue.value;
177
+
178
+ case 'date_absolute':
179
+ return truncateString(
180
+ formatDateAbsoluteCompact(filterValue.unixSeconds, locale),
181
+ maxLength,
182
+ );
183
+
184
+ case 'date_relative':
185
+ return truncateString(filterValue.value, maxLength);
186
+
187
+ case 'date_range':
188
+ if (t) {
189
+ return t('@astryx.powersearch.valueEditor.dateRange');
190
+ }
191
+ // eslint-disable-next-line @astryx/no-hardcoded-i18n-string -- the popover token's released English text; translating it is a separate stable change
192
+ return 'date range';
193
+
194
+ case 'custom':
195
+ if (operatorValue.type === 'custom') {
196
+ return truncateString(
197
+ operatorValue.getString(filterValue.value),
198
+ maxLength,
199
+ );
200
+ }
201
+ return filterValue.value;
202
+
203
+ case 'nested': {
204
+ const count = filterValue.value.length;
205
+ if (t) {
206
+ return t('@astryx.powersearch.valueEditor.filtersCount', {count});
207
+ }
208
+ // eslint-disable-next-line @astryx/no-hardcoded-i18n-string -- the popover token's released English text; translating it is a separate stable change
209
+ return count === 1 ? '1 filter' : `${count} filters`;
210
+ }
211
+
212
+ default:
213
+ return null;
214
+ }
215
+ }
@@ -0,0 +1,224 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file powerSearchSheetUtils.ts
5
+ * @input PowerSearch config/filter types and the field typeahead source
6
+ * @output Pure helpers for the sheet presentation: which operators the
7
+ * sheet's own controls edit, field matching, filter identity tracking
8
+ * across controlled re-renders, the focus target after a removal, and the
9
+ * content search's suggestion source over the field typeahead
10
+ * @position Helper module; consumed by PowerSearchBottomSheet.tsx and its
11
+ * tests
12
+ */
13
+
14
+ import type {SearchSource} from '../Typeahead/types';
15
+ import type {InternalConfig} from './useInternalConfig';
16
+ import type {
17
+ PowerSearchField,
18
+ PowerSearchFilter,
19
+ PowerSearchItem,
20
+ PowerSearchOperator,
21
+ } from './types';
22
+
23
+ // =============================================================================
24
+ // Operators and fields
25
+ // =============================================================================
26
+
27
+ /**
28
+ * Whether the value step edits an operator's value with a sheet-native
29
+ * control (choice rows, or the popover's editor in its sheet presentation).
30
+ * A `nested` value is the exception: it is edited by the popover's built-in
31
+ * NestedEditor, rendered in the step's body,
32
+ * so every operator opens an editable step and no field is left out.
33
+ */
34
+ export function isSupportedOperator(operator: PowerSearchOperator): boolean {
35
+ return operator.value.type !== 'nested';
36
+ }
37
+
38
+ export function fieldMatchesQuery(
39
+ field: PowerSearchField,
40
+ normalizedQuery: string,
41
+ ): boolean {
42
+ if (normalizedQuery === '') {
43
+ return true;
44
+ }
45
+ if (field.label.toLowerCase().includes(normalizedQuery)) {
46
+ return true;
47
+ }
48
+ return (
49
+ field.typeaheadAliases?.some(alias =>
50
+ alias.toLowerCase().includes(normalizedQuery),
51
+ ) ?? false
52
+ );
53
+ }
54
+
55
+ /** Synchronous suggestion source; the sheet renders results inline. */
56
+ export interface SheetSuggestionSource {
57
+ search(query: string): PowerSearchItem[];
58
+ bootstrap(): PowerSearchItem[];
59
+ }
60
+
61
+ /**
62
+ * The field typeahead source as the content search's rows: the popover
63
+ * presentation's own suggestions, minus any whose field the config no longer
64
+ * knows. That source resolves synchronously from the config; a promise (none
65
+ * today) yields no rows rather than a stale list.
66
+ */
67
+ export function createSheetSuggestionSource(
68
+ config: InternalConfig,
69
+ source: SearchSource<PowerSearchItem>,
70
+ ): SheetSuggestionSource {
71
+ // Every suggestion whose field the config knows is offered: the value step
72
+ // edits every operator, `nested` included.
73
+ const isEditable = (item: PowerSearchItem): boolean => {
74
+ const aux = item.auxiliaryData;
75
+ return aux != null && config.getField(aux.fieldKey) != null;
76
+ };
77
+ const settle = (
78
+ results: PowerSearchItem[] | Promise<PowerSearchItem[]>,
79
+ ): PowerSearchItem[] =>
80
+ Array.isArray(results) ? results.filter(isEditable) : [];
81
+ return {
82
+ search: query => settle(source.search(query)),
83
+ bootstrap: () => settle(source.bootstrap()),
84
+ };
85
+ }
86
+
87
+ // =============================================================================
88
+ // Filter identity across controlled updates
89
+ // =============================================================================
90
+
91
+ function stableSerialize(value: unknown): string {
92
+ if (Array.isArray(value)) {
93
+ return `[${value.map(stableSerialize).join(',')}]`;
94
+ }
95
+ if (value != null && typeof value === 'object') {
96
+ return `{${Object.entries(value)
97
+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
98
+ .map(([key, entry]) => `${JSON.stringify(key)}:${stableSerialize(entry)}`)
99
+ .join(',')}}`;
100
+ }
101
+ return JSON.stringify(value) ?? 'undefined';
102
+ }
103
+
104
+ /**
105
+ * Stable identities for the Filters rows across controlled updates, so a row
106
+ * keeps its element — and its focus — when the parent reorders the filters or
107
+ * removes one above it. A filter object seen before keeps its
108
+ * id; a new object takes the id of a filter from the previous update with the
109
+ * same signature that no present object claims (a parent that clones its
110
+ * values on every change); anything else mints a new id. Two equal filters
111
+ * are told apart by order. Call `next` once per render with the current list.
112
+ */
113
+ export function createFilterIdentities(): {
114
+ next: (filters: ReadonlyArray<PowerSearchFilter>) => number[];
115
+ } {
116
+ const byObject = new WeakMap<PowerSearchFilter, number>();
117
+ let previousBySignature = new Map<string, number[]>();
118
+ let nextId = 0;
119
+ return {
120
+ next(filters) {
121
+ const used = new Set<number>();
122
+ const ids: (number | null)[] = filters.map(filter => {
123
+ const known = byObject.get(filter);
124
+ if (known == null || used.has(known)) {
125
+ return null;
126
+ }
127
+ used.add(known);
128
+ return known;
129
+ });
130
+ const bySignature = new Map<string, number[]>();
131
+ filters.forEach((filter, index) => {
132
+ const signature = filterSignature(filter);
133
+ let id = ids[index];
134
+ if (id == null) {
135
+ id =
136
+ previousBySignature
137
+ .get(signature)
138
+ ?.find(candidate => !used.has(candidate)) ?? nextId++;
139
+ used.add(id);
140
+ byObject.set(filter, id);
141
+ ids[index] = id;
142
+ }
143
+ bySignature.set(signature, [...(bySignature.get(signature) ?? []), id]);
144
+ });
145
+ previousBySignature = bySignature;
146
+ return ids as number[];
147
+ },
148
+ };
149
+ }
150
+
151
+ /** Structural snapshot of a filter, for parents that clone their values. */
152
+ export function filterSignature(filter: PowerSearchFilter): string {
153
+ return stableSerialize({
154
+ field: filter.field,
155
+ operator: filter.operator,
156
+ value: filter.value,
157
+ isReadOnly: filter.isReadOnly ?? false,
158
+ });
159
+ }
160
+
161
+ /**
162
+ * Finds the filter a step was opened on after the controlled parent may have
163
+ * reordered, cloned, or removed it: object identity first, then the original
164
+ * slot when it still holds a structurally equal filter, then a unique
165
+ * structural match anywhere. Returns null when the target is gone or
166
+ * ambiguous, so an edit never lands on a different filter.
167
+ */
168
+ export function resolveFilterIdentityIndex(
169
+ filters: ReadonlyArray<PowerSearchFilter>,
170
+ sourceFilter: PowerSearchFilter,
171
+ sourceSignature: string,
172
+ preferredIndex: number,
173
+ ): number | null {
174
+ const identityIndex = filters.indexOf(sourceFilter);
175
+ if (identityIndex >= 0) {
176
+ return identityIndex;
177
+ }
178
+ if (
179
+ filters[preferredIndex] != null &&
180
+ filterSignature(filters[preferredIndex]) === sourceSignature
181
+ ) {
182
+ return preferredIndex;
183
+ }
184
+ const matchingIndices = filters.flatMap((filter, index) =>
185
+ filterSignature(filter) === sourceSignature ? [index] : [],
186
+ );
187
+ return matchingIndices.length === 1 ? matchingIndices[0] : null;
188
+ }
189
+
190
+ /**
191
+ * After removing the filter at `removedIndex`, focus should land on the
192
+ * nearest remaining row that is a button, preferring the one after it.
193
+ * `isRowButton` is the Filters sheet's own rule for which rows are buttons:
194
+ * the field interactive and the filter not read-only (a `nested` or stale
195
+ * filter's row is a button too).
196
+ */
197
+ export function nearestEditableIndex(
198
+ nextFilters: ReadonlyArray<PowerSearchFilter>,
199
+ removedIndex: number,
200
+ isRowButton: (filter: PowerSearchFilter) => boolean = filter =>
201
+ !filter.isReadOnly,
202
+ ): number | undefined {
203
+ const editableIndices = nextFilters.flatMap((candidate, candidateIndex) =>
204
+ isRowButton(candidate) ? [candidateIndex] : [],
205
+ );
206
+ return editableIndices.reduce<number | undefined>((nearest, candidate) => {
207
+ if (nearest == null) {
208
+ return candidate;
209
+ }
210
+ const candidateDistance = Math.abs(candidate - removedIndex);
211
+ const nearestDistance = Math.abs(nearest - removedIndex);
212
+ if (candidateDistance < nearestDistance) {
213
+ return candidate;
214
+ }
215
+ if (
216
+ candidateDistance === nearestDistance &&
217
+ candidate >= removedIndex &&
218
+ nearest < removedIndex
219
+ ) {
220
+ return candidate;
221
+ }
222
+ return nearest;
223
+ }, undefined);
224
+ }
@@ -29,9 +29,10 @@ import * as stylex from '@stylexjs/stylex';
29
29
  import {spacingVars} from '../theme/tokens.stylex';
30
30
  import {Field} from '../Field/Field';
31
31
  import type {InputStatus} from '../Field/types';
32
- import {useTooltip} from '../Tooltip';
32
+ import {useTooltip} from '../Tooltip/useTooltip';
33
33
  import {useResolvedRequired} from '../hooks/useResolvedRequired';
34
- import {composeEventHandlers, mergeProps} from '../utils';
34
+ import {composeEventHandlers} from '../utils/composeEventHandlers';
35
+ import {mergeProps} from '../utils/mergeProps';
35
36
  import {joinAriaIDs} from '../utils/inputAria';
36
37
  import {
37
38
  type FieldInputBaseProps,
@@ -26,12 +26,14 @@ import {RadioListContext} from './RadioList';
26
26
  import {RadioListReasonContext} from './RadioListReasonContext';
27
27
  import {joinAriaIDs} from '../utils/inputAria';
28
28
  import {colorVars, radiusVars} from '../theme/tokens.stylex';
29
- import {mergeProps, isRenderable, rtlStyles} from '../utils';
29
+ import {isRenderable} from '../utils/isRenderable';
30
+ import {mergeProps} from '../utils/mergeProps';
31
+ import {rtlStyles} from '../utils/rtlStyles';
30
32
  import {indicatorScope} from '../Indicator/indicator.markers.stylex';
31
33
  import {useIndicatorFocusRing} from '../hooks/useIndicatorFocusRing';
32
34
  import {usePressFeedback} from '../hooks/usePressFeedback';
33
- import {useIndicator} from '../Indicator';
34
- import {Item, type ItemAlign} from '../Item';
35
+ import {useIndicator} from '../Indicator/useIndicator';
36
+ import {Item, type ItemAlign} from '../Item/Item';
35
37
  import {themeProps} from '../utils/themeProps';
36
38
 
37
39
  // The touch press's paint, declared by the shared overlay styles on the
@@ -25,7 +25,7 @@ import {
25
25
  type RefObject,
26
26
  } from 'react';
27
27
  import {
28
- createAnimator,
28
+ createMotionAnimator,
29
29
  type AnimateOptions,
30
30
  type Animator,
31
31
  type MotionCurve,
@@ -539,7 +539,7 @@ export class SegmentedSelectionMotion {
539
539
  private readonly after: Animator;
540
540
 
541
541
  constructor(
542
- private readonly animator: Animator = createAnimator(null, {
542
+ private readonly animator: Animator = createMotionAnimator(null, {
543
543
  pseudoElement: '::before',
544
544
  }),
545
545
  options: SegmentedSelectionMotionOptions = {},
@@ -552,7 +552,10 @@ export class SegmentedSelectionMotion {
552
552
  this.now = options.now ?? defaultNow;
553
553
  this.after =
554
554
  options.afterAnimator ??
555
- createAnimator(null, {pseudoElement: '::after', initial: {opacity: 0}});
555
+ createMotionAnimator(null, {
556
+ pseudoElement: '::after',
557
+ initial: {opacity: 0},
558
+ });
556
559
  }
557
560
 
558
561
  /** Attaches the radiogroup whose pseudo-elements are the lens (null detaches). */
@@ -29,7 +29,7 @@ import {TapGestureRecognizer} from '../gestures/TapGestureRecognizer';
29
29
  import type {PointerKind} from '../gestures/types';
30
30
  import {isRtlElement} from '../hooks/isRtlElement';
31
31
  import {
32
- createAnimator,
32
+ createMotionAnimator,
33
33
  type Animator,
34
34
  type MotionCurve,
35
35
  type MotionHandle,
@@ -1186,7 +1186,7 @@ export class SliderTouchController {
1186
1186
  private animatorFor(element: HTMLElement): Animator {
1187
1187
  let animator = this.animators.get(element);
1188
1188
  if (animator == null) {
1189
- animator = createAnimator(element);
1189
+ animator = createMotionAnimator(element);
1190
1190
  this.animators.set(element, animator);
1191
1191
  }
1192
1192
  return animator;