@astryxdesign/core 0.7.17 → 0.7.18-canary.g57306fd

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 (429) hide show
  1. package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
  2. package/dist/AlertDialog/AlertDialog.js +7 -0
  3. package/dist/AppShell/AppShell.d.ts.map +1 -1
  4. package/dist/AppShell/AppShell.js +5 -3
  5. package/dist/AppShell/observeMainOverflow.d.ts +5 -0
  6. package/dist/AppShell/observeMainOverflow.d.ts.map +1 -1
  7. package/dist/AppShell/observeMainOverflow.js +39 -9
  8. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  9. package/dist/BottomSheet/BottomSheet.js +8 -0
  10. package/dist/BottomSheet/useSheetGestures.d.ts +8 -0
  11. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
  12. package/dist/BottomSheet/useSheetGestures.js +16 -1
  13. package/dist/Button/Button.d.ts.map +1 -1
  14. package/dist/Button/Button.js +3 -16
  15. package/dist/Card/Card.d.ts.map +1 -1
  16. package/dist/Card/Card.js +5 -1
  17. package/dist/Citation/Citation.d.ts.map +1 -1
  18. package/dist/Citation/Citation.js +2 -2
  19. package/dist/ClickableCard/ClickableCard.d.ts.map +1 -1
  20. package/dist/ClickableCard/ClickableCard.js +7 -2
  21. package/dist/DateInput/DateInput.d.ts +0 -3
  22. package/dist/DateInput/DateInput.d.ts.map +1 -1
  23. package/dist/DateInput/DateInput.js +3 -5
  24. package/dist/DateInput/NativeDateField.d.ts.map +1 -1
  25. package/dist/DateInput/NativeDateField.js +3 -5
  26. package/dist/DateInput/TouchDateField.d.ts.map +1 -1
  27. package/dist/DateInput/TouchDateField.js +2 -4
  28. package/dist/DateInput/useTypedDate.d.ts.map +1 -1
  29. package/dist/DateInput/useTypedDate.js +9 -6
  30. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  31. package/dist/DateRangeInput/DateRangeInput.js +13 -9
  32. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  33. package/dist/DateTimeInput/DateTimeInput.js +3 -15
  34. package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
  35. package/dist/DateTimeInput/TouchDateTimeField.js +2 -14
  36. package/dist/Dialog/Dialog.d.ts.map +1 -1
  37. package/dist/Dialog/Dialog.js +7 -1
  38. package/dist/Drawer/Drawer.d.ts.map +1 -1
  39. package/dist/Drawer/Drawer.js +7 -0
  40. package/dist/Field/Field.d.ts.map +1 -1
  41. package/dist/Field/Field.js +2 -1
  42. package/dist/Field/FieldLabel.d.ts.map +1 -1
  43. package/dist/Field/FieldLabel.js +9 -2
  44. package/dist/Field/InputClearButton.d.ts.map +1 -1
  45. package/dist/Field/InputClearButton.js +23 -0
  46. package/dist/Field/inputStyles.stylex.d.ts +22 -6
  47. package/dist/Field/inputStyles.stylex.d.ts.map +1 -1
  48. package/dist/Field/inputStyles.stylex.js +32 -0
  49. package/dist/FieldStatus/FieldStatus.d.ts.map +1 -1
  50. package/dist/FieldStatus/FieldStatus.js +7 -2
  51. package/dist/FileInput/FileInput.d.ts.map +1 -1
  52. package/dist/FileInput/FileInput.js +4 -4
  53. package/dist/InputGroup/InputGroup.d.ts.map +1 -1
  54. package/dist/InputGroup/InputGroup.js +6 -16
  55. package/dist/InputGroup/InputGroupText.d.ts.map +1 -1
  56. package/dist/InputGroup/InputGroupText.js +2 -8
  57. package/dist/Kbd/Kbd.d.ts +3 -2
  58. package/dist/Kbd/Kbd.d.ts.map +1 -1
  59. package/dist/Kbd/Kbd.js +3 -2
  60. package/dist/Layer/gestureCounter.d.ts +5 -0
  61. package/dist/Layer/gestureCounter.d.ts.map +1 -1
  62. package/dist/Layer/gestureCounter.js +40 -4
  63. package/dist/Layer/layerHost.d.ts +3 -2
  64. package/dist/Layer/layerHost.d.ts.map +1 -1
  65. package/dist/Layer/layerHost.js +3 -2
  66. package/dist/Layer/outsidePanClaim.d.ts +17 -0
  67. package/dist/Layer/outsidePanClaim.d.ts.map +1 -1
  68. package/dist/Layer/outsidePanClaim.js +36 -8
  69. package/dist/Layer/outsidePress.d.ts +7 -1
  70. package/dist/Layer/outsidePress.d.ts.map +1 -1
  71. package/dist/Layer/outsidePress.js +9 -2
  72. package/dist/Layer/useLayer.d.ts +21 -5
  73. package/dist/Layer/useLayer.d.ts.map +1 -1
  74. package/dist/Layer/useLayer.js +63 -40
  75. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  76. package/dist/Lightbox/Lightbox.js +7 -0
  77. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  78. package/dist/MultiSelector/MultiSelector.js +22 -16
  79. package/dist/NavIcon/NavIcon.d.ts +2 -2
  80. package/dist/NavIcon/NavIcon.d.ts.map +1 -1
  81. package/dist/NavIcon/NavIcon.js +2 -2
  82. package/dist/NavMenu/NavHeadingMenuItem.d.ts.map +1 -1
  83. package/dist/NavMenu/NavHeadingMenuItem.js +4 -3
  84. package/dist/NumberInput/NumberInput.d.ts +13 -5
  85. package/dist/NumberInput/NumberInput.d.ts.map +1 -1
  86. package/dist/NumberInput/NumberInput.js +6 -17
  87. package/dist/NumberInput/numberParser.d.ts +9 -2
  88. package/dist/NumberInput/numberParser.d.ts.map +1 -1
  89. package/dist/NumberInput/numberParser.js +15 -2
  90. package/dist/Overlay/OverlayScrim.d.ts.map +1 -1
  91. package/dist/Overlay/OverlayScrim.js +13 -4
  92. package/dist/Overlay/useOverlay.d.ts +1 -1
  93. package/dist/Pagination/Pagination.d.ts +3 -2
  94. package/dist/Pagination/Pagination.d.ts.map +1 -1
  95. package/dist/Pagination/Pagination.js +9 -2
  96. package/dist/Popover/usePopover.d.ts +37 -6
  97. package/dist/Popover/usePopover.d.ts.map +1 -1
  98. package/dist/Popover/usePopover.js +103 -20
  99. package/dist/PowerSearch/PowerSearch.d.ts +4 -1
  100. package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
  101. package/dist/PowerSearch/PowerSearch.js +3 -4
  102. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +1 -2
  103. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -1
  104. package/dist/PowerSearch/PowerSearchBottomSheet.js +3 -12
  105. package/dist/PowerSearch/PowerSearchValueEditor.d.ts +0 -12
  106. package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
  107. package/dist/PowerSearch/PowerSearchValueEditor.js +1 -51
  108. package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
  109. package/dist/PowerSearch/formatFilterValue.js +6 -8
  110. package/dist/PowerSearch/formatTokenValue.d.ts +5 -10
  111. package/dist/PowerSearch/formatTokenValue.d.ts.map +1 -1
  112. package/dist/PowerSearch/formatTokenValue.js +21 -38
  113. package/dist/PowerSearch/relativeDateOptions.d.ts +30 -0
  114. package/dist/PowerSearch/relativeDateOptions.d.ts.map +1 -0
  115. package/dist/PowerSearch/relativeDateOptions.js +74 -0
  116. package/dist/ProgressBar/ProgressBar.d.ts +1 -1
  117. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  118. package/dist/ProgressBar/ProgressBar.js +20 -14
  119. package/dist/Resizable/createResizable.d.ts.map +1 -1
  120. package/dist/Resizable/createResizable.js +38 -4
  121. package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
  122. package/dist/SegmentedControl/SegmentedControlItem.js +5 -3
  123. package/dist/SelectableCard/SelectableCard.d.ts.map +1 -1
  124. package/dist/SelectableCard/SelectableCard.js +6 -2
  125. package/dist/Selector/Selector.d.ts.map +1 -1
  126. package/dist/Selector/Selector.js +2 -1
  127. package/dist/Slider/Slider.d.ts.map +1 -1
  128. package/dist/Slider/Slider.js +4 -1
  129. package/dist/Stepper/Step.d.ts.map +1 -1
  130. package/dist/Stepper/Step.js +2 -2
  131. package/dist/TabList/Tab.d.ts.map +1 -1
  132. package/dist/TabList/Tab.js +2 -0
  133. package/dist/TabList/TabMenu.d.ts.map +1 -1
  134. package/dist/TabList/TabMenu.js +2 -0
  135. package/dist/Table/BaseTable.d.ts.map +1 -1
  136. package/dist/Table/BaseTable.js +14 -5
  137. package/dist/Table/Table.d.ts +9 -4
  138. package/dist/Table/Table.d.ts.map +1 -1
  139. package/dist/Table/Table.js +9 -4
  140. package/dist/Table/TableHeaderCell.d.ts.map +1 -1
  141. package/dist/Table/TableHeaderCell.js +3 -7
  142. package/dist/Table/plugins/sortable/useTableSortable.d.ts.map +1 -1
  143. package/dist/Table/plugins/sortable/useTableSortable.js +18 -1
  144. package/dist/Table/plugins/stickyColumns/useTableStickyColumns.d.ts.map +1 -1
  145. package/dist/Table/plugins/stickyColumns/useTableStickyColumns.js +34 -24
  146. package/dist/Table/types.d.ts +5 -5
  147. package/dist/Text/Text.d.ts.map +1 -1
  148. package/dist/Text/Text.js +13 -8
  149. package/dist/Text/TruncationTooltip.d.ts +7 -39
  150. package/dist/Text/TruncationTooltip.d.ts.map +1 -1
  151. package/dist/Text/TruncationTooltip.js +47 -128
  152. package/dist/Text/cutText.d.ts +22 -0
  153. package/dist/Text/cutText.d.ts.map +1 -0
  154. package/dist/Text/cutText.js +92 -0
  155. package/dist/Text/cutTextOnKeyboardFocus.d.ts +41 -0
  156. package/dist/Text/cutTextOnKeyboardFocus.d.ts.map +1 -0
  157. package/dist/Text/cutTextOnKeyboardFocus.js +101 -0
  158. package/dist/Text/textClampContext.d.ts +1 -0
  159. package/dist/Text/textClampContext.d.ts.map +1 -1
  160. package/dist/Text/textClampContext.js +10 -5
  161. package/dist/Text/useTruncation.d.ts +23 -1
  162. package/dist/Text/useTruncation.d.ts.map +1 -1
  163. package/dist/Text/useTruncation.js +74 -28
  164. package/dist/TextInput/TextInput.d.ts +6 -6
  165. package/dist/Thumbnail/Thumbnail.js +4 -1
  166. package/dist/TimeInput/TimeInput.d.ts +0 -3
  167. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  168. package/dist/TimeInput/TimeInput.js +3 -5
  169. package/dist/TimeInput/TouchTimeField.d.ts.map +1 -1
  170. package/dist/TimeInput/TouchTimeField.js +3 -5
  171. package/dist/Timestamp/Timestamp.d.ts.map +1 -1
  172. package/dist/Timestamp/Timestamp.js +22 -16
  173. package/dist/Timestamp/TimestampHoverCard.d.ts +6 -3
  174. package/dist/Timestamp/TimestampHoverCard.d.ts.map +1 -1
  175. package/dist/Timestamp/TimestampHoverCard.js +30 -19
  176. package/dist/Timestamp/formatInstant.d.ts.map +1 -1
  177. package/dist/Timestamp/formatInstant.js +3 -3
  178. package/dist/Timestamp/tooltipEntries.d.ts.map +1 -1
  179. package/dist/Timestamp/tooltipEntries.js +4 -2
  180. package/dist/Toast/Toast.d.ts.map +1 -1
  181. package/dist/Toast/Toast.js +62 -31
  182. package/dist/Toast/ToastViewport.d.ts.map +1 -1
  183. package/dist/Toast/ToastViewport.js +35 -13
  184. package/dist/Toast/useToast.d.ts.map +1 -1
  185. package/dist/Toast/useToast.js +35 -14
  186. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  187. package/dist/Tooltip/useTooltip.js +3 -3
  188. package/dist/astryx.css +36 -8
  189. package/dist/hooks/useAnnounceRenderedText.d.ts +10 -3
  190. package/dist/hooks/useAnnounceRenderedText.d.ts.map +1 -1
  191. package/dist/hooks/useAnnounceRenderedText.js +11 -3
  192. package/dist/hooks/useFocusTrap.d.ts +12 -0
  193. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  194. package/dist/hooks/useFocusTrap.js +13 -6
  195. package/dist/hooks/useHotkeys.d.ts +9 -1
  196. package/dist/hooks/useHotkeys.d.ts.map +1 -1
  197. package/dist/hooks/useHotkeys.js +52 -2
  198. package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
  199. package/dist/hooks/useInputStatusIcon.js +2 -1
  200. package/dist/hooks/useKeyboardHint.d.ts.map +1 -1
  201. package/dist/hooks/useKeyboardHint.js +4 -3
  202. package/dist/i18n/generated-english/DateRangeInput/DateRangeInput.generated.d.ts.map +1 -1
  203. package/dist/i18n/generated-english/DateRangeInput/DateRangeInput.generated.js +2 -0
  204. package/dist/i18n/generated-english/MultiSelector/MultiSelector.generated.d.ts.map +1 -1
  205. package/dist/i18n/generated-english/MultiSelector/MultiSelector.generated.js +1 -0
  206. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
  207. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +0 -6
  208. package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.d.ts +8 -0
  209. package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.d.ts.map +1 -0
  210. package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.js +17 -0
  211. package/dist/i18n/generated-english/Slider/Slider.generated.d.ts.map +1 -1
  212. package/dist/i18n/generated-english/Slider/Slider.generated.js +1 -0
  213. package/dist/i18n/generated-english/Thumbnail/Thumbnail.generated.d.ts.map +1 -1
  214. package/dist/i18n/generated-english/Thumbnail/Thumbnail.generated.js +1 -0
  215. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  216. package/dist/i18n/generated-locales/en.generated.js +5 -0
  217. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  218. package/dist/i18n/generated-locales/pseudo.generated.js +5 -0
  219. package/dist/i18n/getLocaleDirection.d.ts +0 -16
  220. package/dist/i18n/getLocaleDirection.d.ts.map +1 -1
  221. package/dist/i18n/getLocaleDirection.js +16 -6
  222. package/dist/i18n/listFormat.d.ts +22 -0
  223. package/dist/i18n/listFormat.d.ts.map +1 -0
  224. package/dist/i18n/listFormat.js +29 -0
  225. package/dist/i18n/useListFormatter.d.ts +1 -3
  226. package/dist/i18n/useListFormatter.d.ts.map +1 -1
  227. package/dist/i18n/useListFormatter.js +5 -12
  228. package/dist/internal/module-loader.d.ts +15 -0
  229. package/dist/internal/module-loader.d.ts.map +1 -0
  230. package/dist/internal/module-loader.js +15 -0
  231. package/dist/motion/animatedLayout.d.ts +6 -0
  232. package/dist/motion/animatedLayout.d.ts.map +1 -1
  233. package/dist/motion/animatedLayout.js +201 -27
  234. package/dist/palette/color.d.ts +16 -0
  235. package/dist/palette/color.d.ts.map +1 -1
  236. package/dist/palette/color.js +37 -1
  237. package/dist/palette/derive-look.d.ts +235 -0
  238. package/dist/palette/derive-look.d.ts.map +1 -0
  239. package/dist/palette/derive-look.js +879 -0
  240. package/dist/palette/editor-look.d.ts +41 -0
  241. package/dist/palette/editor-look.d.ts.map +1 -0
  242. package/dist/palette/editor-look.js +401 -0
  243. package/dist/palette/mapping.d.ts +99 -6
  244. package/dist/palette/mapping.d.ts.map +1 -1
  245. package/dist/palette/mapping.js +68 -11
  246. package/dist/theme/tokens.d.ts +1 -1
  247. package/dist/theme/tokens.d.ts.map +1 -1
  248. package/dist/theme/tokens.js +1 -1
  249. package/dist/utils/characters.d.ts.map +1 -1
  250. package/dist/utils/characters.js +7 -0
  251. package/dist/utils/devWarning.d.ts +18 -0
  252. package/dist/utils/devWarning.d.ts.map +1 -1
  253. package/dist/utils/devWarning.js +30 -0
  254. package/dist/utils/focusReturn.d.ts +2 -0
  255. package/dist/utils/focusReturn.d.ts.map +1 -1
  256. package/dist/utils/focusReturn.js +3 -8
  257. package/dist/utils/hitArea.d.ts +4 -1
  258. package/dist/utils/hitArea.d.ts.map +1 -1
  259. package/dist/utils/hitArea.js +72 -9
  260. package/dist/utils/scrollView.d.ts +2 -2
  261. package/dist/utils/scrollView.d.ts.map +1 -1
  262. package/dist/utils/scrollView.js +3 -3
  263. package/dist/utils/textDirection.d.ts +15 -5
  264. package/dist/utils/textDirection.d.ts.map +1 -1
  265. package/dist/utils/textDirection.js +33 -4
  266. package/dist/utils/touchHitArea.d.ts.map +1 -1
  267. package/dist/utils/touchHitArea.js +4 -2
  268. package/dist/virtualization/useInlineListWindow.d.ts.map +1 -1
  269. package/dist/virtualization/useInlineListWindow.js +63 -4
  270. package/locales/en.json +26 -6
  271. package/locales/pseudo.json +15 -0
  272. package/package.json +10 -5
  273. package/src/AlertDialog/AlertDialog.tsx +15 -0
  274. package/src/AlertDialog/useImperativeAlertDialog.doc.mjs +7 -4
  275. package/src/AppShell/AppShell.tsx +6 -3
  276. package/src/AppShell/observeMainOverflow.ts +39 -9
  277. package/src/Badge/Badge.doc.mjs +3 -3
  278. package/src/BottomSheet/BottomSheet.tsx +15 -0
  279. package/src/BottomSheet/useSheetGestures.ts +26 -1
  280. package/src/Button/Button.tsx +3 -23
  281. package/src/Card/Card.doc.mjs +3 -3
  282. package/src/Card/Card.tsx +11 -6
  283. package/src/Chat/ChatSendButton.doc.mjs +6 -6
  284. package/src/Chat/ChatToolCalls.doc.mjs +1 -1
  285. package/src/CheckboxInput/CheckboxInput.doc.mjs +3 -3
  286. package/src/Citation/Citation.tsx +8 -2
  287. package/src/ClickableCard/ClickableCard.tsx +9 -2
  288. package/src/ComplexSelector/ComplexSelector.doc.mjs +3 -3
  289. package/src/ContextMenu/ContextMenuItem.doc.mjs +3 -3
  290. package/src/DateInput/DateInput.tsx +2 -4
  291. package/src/DateInput/NativeDateField.tsx +5 -4
  292. package/src/DateInput/TouchDateField.tsx +2 -3
  293. package/src/DateInput/useTypedDate.ts +13 -6
  294. package/src/DateRangeInput/DateRangeInput.tsx +14 -10
  295. package/src/DateTimeInput/DateTimeInput.tsx +2 -12
  296. package/src/DateTimeInput/TouchDateTimeField.tsx +2 -11
  297. package/src/Dialog/Dialog.tsx +15 -1
  298. package/src/Dialog/useImperativeDialog.doc.mjs +7 -4
  299. package/src/Drawer/Drawer.tsx +15 -0
  300. package/src/DropdownMenu/DropdownMenu.doc.mjs +1 -1
  301. package/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs +3 -3
  302. package/src/DropdownMenu/DropdownMenuItem.doc.mjs +3 -3
  303. package/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs +3 -3
  304. package/src/DropdownMenu/DropdownMenuSubMenu.doc.mjs +2 -2
  305. package/src/Field/Field.doc.mjs +1 -1
  306. package/src/Field/Field.tsx +2 -1
  307. package/src/Field/FieldLabel.doc.mjs +3 -3
  308. package/src/Field/FieldLabel.tsx +11 -3
  309. package/src/Field/InputClearButton.tsx +27 -0
  310. package/src/Field/inputStyles.stylex.ts +53 -6
  311. package/src/FieldStatus/FieldStatus.tsx +7 -2
  312. package/src/FileInput/FileInput.tsx +12 -2
  313. package/src/Icon/Icon.doc.mjs +17 -14
  314. package/src/Icon/useIcon.doc.mjs +6 -6
  315. package/src/IconButton/IconButton.doc.mjs +2 -2
  316. package/src/InfoTip/InfoTip.doc.mjs +1 -1
  317. package/src/InputGroup/InputGroup.tsx +5 -12
  318. package/src/InputGroup/InputGroupText.tsx +2 -3
  319. package/src/Kbd/Kbd.doc.mjs +5 -5
  320. package/src/Kbd/Kbd.tsx +3 -2
  321. package/src/Layer/gestureCounter.ts +39 -3
  322. package/src/Layer/layerHost.ts +3 -2
  323. package/src/Layer/outsidePanClaim.ts +50 -8
  324. package/src/Layer/outsidePress.ts +18 -4
  325. package/src/Layer/useLayer.tsx +128 -76
  326. package/src/Lightbox/Lightbox.tsx +15 -0
  327. package/src/MoreMenu/MoreMenu.doc.mjs +1 -1
  328. package/src/MultiSelector/MultiSelector.doc.mjs +2 -2
  329. package/src/MultiSelector/MultiSelector.tsx +24 -14
  330. package/src/NavIcon/NavIcon.doc.mjs +19 -10
  331. package/src/NavIcon/NavIcon.tsx +3 -2
  332. package/src/NavMenu/NavHeadingMenuItem.tsx +9 -3
  333. package/src/NumberInput/NumberInput.doc.mjs +12 -12
  334. package/src/NumberInput/NumberInput.tsx +12 -15
  335. package/src/NumberInput/numberParser.ts +15 -2
  336. package/src/Overlay/Overlay.doc.mjs +13 -1
  337. package/src/Overlay/OverlayScrim.tsx +45 -15
  338. package/src/Overlay/useOverlay.doc.mjs +7 -7
  339. package/src/Overlay/useOverlay.tsx +1 -1
  340. package/src/Pagination/Pagination.doc.mjs +9 -6
  341. package/src/Pagination/Pagination.tsx +15 -3
  342. package/src/Popover/usePopover.doc.mjs +14 -4
  343. package/src/Popover/usePopover.tsx +180 -23
  344. package/src/PowerSearch/PowerSearch.doc.mjs +165 -15
  345. package/src/PowerSearch/PowerSearch.tsx +6 -8
  346. package/src/PowerSearch/PowerSearchBottomSheet.tsx +13 -46
  347. package/src/PowerSearch/PowerSearchValueEditor.tsx +1 -51
  348. package/src/PowerSearch/formatFilterValue.ts +8 -9
  349. package/src/PowerSearch/formatTokenValue.ts +24 -42
  350. package/src/PowerSearch/relativeDateOptions.ts +84 -0
  351. package/src/ProgressBar/ProgressBar.doc.mjs +24 -5
  352. package/src/ProgressBar/ProgressBar.tsx +28 -18
  353. package/src/Resizable/createResizable.ts +46 -5
  354. package/src/SegmentedControl/SegmentedControlItem.tsx +4 -3
  355. package/src/SelectableCard/SelectableCard.tsx +8 -2
  356. package/src/Selector/Selector.doc.mjs +3 -3
  357. package/src/Selector/Selector.tsx +3 -1
  358. package/src/Selector/SelectorOption.doc.mjs +3 -3
  359. package/src/SideNav/SideNavItem.doc.mjs +6 -6
  360. package/src/Slider/Slider.tsx +4 -1
  361. package/src/Stepper/Step.tsx +7 -1
  362. package/src/Switch/Switch.doc.mjs +3 -3
  363. package/src/TabList/Tab.tsx +4 -0
  364. package/src/TabList/TabMenu.tsx +4 -0
  365. package/src/Table/BaseTable.tsx +14 -4
  366. package/src/Table/Table.doc.mjs +56 -6
  367. package/src/Table/Table.tsx +9 -4
  368. package/src/Table/TableHeaderCell.tsx +2 -8
  369. package/src/Table/plugins/sortable/useTableSortable.tsx +41 -2
  370. package/src/Table/plugins/stickyColumns/useTableStickyColumns.tsx +49 -20
  371. package/src/Table/types.ts +5 -5
  372. package/src/Text/Text.tsx +21 -7
  373. package/src/Text/TruncationTooltip.tsx +51 -184
  374. package/src/Text/cutText.tsx +126 -0
  375. package/src/Text/cutTextOnKeyboardFocus.tsx +148 -0
  376. package/src/Text/textClampContext.ts +14 -4
  377. package/src/Text/useTruncation.ts +85 -27
  378. package/src/TextArea/TextArea.doc.mjs +4 -4
  379. package/src/TextInput/TextInput.doc.mjs +3 -3
  380. package/src/Thumbnail/Thumbnail.tsx +1 -1
  381. package/src/TimeInput/TimeInput.tsx +3 -9
  382. package/src/TimeInput/TouchTimeField.tsx +6 -4
  383. package/src/Timestamp/Timestamp.tsx +29 -21
  384. package/src/Timestamp/TimestampHoverCard.tsx +44 -31
  385. package/src/Timestamp/formatInstant.ts +7 -3
  386. package/src/Timestamp/tooltipEntries.ts +4 -2
  387. package/src/Toast/Toast.doc.mjs +24 -37
  388. package/src/Toast/Toast.tsx +77 -29
  389. package/src/Toast/ToastViewport.tsx +33 -13
  390. package/src/Toast/useToast.tsx +42 -15
  391. package/src/Tokenizer/Tokenizer.doc.mjs +2 -2
  392. package/src/Tooltip/useTooltip.tsx +2 -1
  393. package/src/TopNav/TopNavMegaMenu.doc.mjs +13 -0
  394. package/src/TopNav/TopNavMenu.doc.mjs +2 -0
  395. package/src/Typeahead/Typeahead.doc.mjs +2 -2
  396. package/src/hooks/useAnnounceRenderedText.ts +15 -2
  397. package/src/hooks/useFocusTrap.ts +27 -4
  398. package/src/hooks/useHotkeys.doc.mjs +54 -11
  399. package/src/hooks/useHotkeys.ts +72 -3
  400. package/src/hooks/useInputStatusIcon.tsx +2 -1
  401. package/src/hooks/useKeyboardHint.tsx +3 -2
  402. package/src/i18n/generated-english/DateRangeInput/DateRangeInput.generated.ts +2 -0
  403. package/src/i18n/generated-english/MultiSelector/MultiSelector.generated.ts +1 -0
  404. package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +0 -6
  405. package/src/i18n/generated-english/PowerSearch/relativeDateOptions.generated.ts +18 -0
  406. package/src/i18n/generated-english/Slider/Slider.generated.ts +1 -0
  407. package/src/i18n/generated-english/Thumbnail/Thumbnail.generated.ts +1 -0
  408. package/src/i18n/generated-locales/en.generated.ts +5 -0
  409. package/src/i18n/generated-locales/pseudo.generated.ts +5 -0
  410. package/src/i18n/getLocaleDirection.ts +57 -7
  411. package/src/i18n/listFormat.ts +33 -0
  412. package/src/i18n/useListFormatter.ts +5 -12
  413. package/src/internal/module-loader.ts +15 -0
  414. package/src/motion/animatedLayout.ts +215 -28
  415. package/src/palette/color.ts +41 -1
  416. package/src/palette/derive-look.ts +1186 -0
  417. package/src/palette/editor-look.ts +480 -0
  418. package/src/palette/mapping.ts +129 -15
  419. package/src/theme/SyntaxTheme.doc.mjs +1 -1
  420. package/src/theme/tokens.ts +2 -1
  421. package/src/theme/useThemeName.doc.mjs +1 -1
  422. package/src/utils/characters.ts +11 -0
  423. package/src/utils/devWarning.ts +35 -0
  424. package/src/utils/focusReturn.ts +3 -11
  425. package/src/utils/hitArea.ts +87 -18
  426. package/src/utils/scrollView.ts +3 -2
  427. package/src/utils/textDirection.ts +33 -5
  428. package/src/utils/touchHitArea.ts +3 -2
  429. package/src/virtualization/useInlineListWindow.ts +102 -11
@@ -144,27 +144,44 @@ function countPinnedRuns(columns, startKeys, endKeys) {
144
144
  };
145
145
  }
146
146
  /**
147
- * Resolve how a single column should be pinned given the start/end configs and
148
- * the full column list. A key (mis)configured on both edges resolves to start.
149
- * Returns `null` for columns that should not be pinned.
147
+ * Resolves how one column is pinned from the precomputed offsets. A key on
148
+ * both edges resolves to start. Returns `null` for a column that is not
149
+ * pinned.
150
150
  */
151
- function resolveStickySide(columns, columnKey, startKeys, endKeys) {
152
- const startOffsets = computeStartOffsets(columns, startKeys);
153
- if (startOffsets?.has(columnKey)) {
151
+ function resolveStickySide(offsets, columnKey) {
152
+ if (offsets.start?.has(columnKey)) {
154
153
  return {
155
154
  edge: 'start',
156
- offset: startOffsets.get(columnKey) ?? '0px'
155
+ offset: offsets.start.get(columnKey) ?? '0px'
157
156
  };
158
157
  }
159
- const endOffsets = computeEndOffsets(columns, endKeys);
160
- if (endOffsets?.has(columnKey)) {
158
+ if (offsets.end?.has(columnKey)) {
161
159
  return {
162
160
  edge: 'end',
163
- offset: endOffsets.get(columnKey) ?? '0px'
161
+ offset: offsets.end.get(columnKey) ?? '0px'
164
162
  };
165
163
  }
166
164
  return null;
167
165
  }
166
+ /**
167
+ * Returns a reader of the pinned offsets for a column list. The offsets
168
+ * depend only on the columns and the pinned keys. Each cell of a render reads
169
+ * one result.
170
+ */
171
+ function createPinnedOffsetsReader(startKeys, endKeys) {
172
+ let lastColumns;
173
+ let last;
174
+ return columns => {
175
+ if (last === undefined || columns !== lastColumns) {
176
+ lastColumns = columns;
177
+ last = {
178
+ start: computeStartOffsets(columns, startKeys),
179
+ end: computeEndOffsets(columns, endKeys)
180
+ };
181
+ }
182
+ return last;
183
+ };
184
+ }
168
185
 
169
186
  // =============================================================================
170
187
  // Styles
@@ -550,6 +567,7 @@ export function useTableStickyColumns(config) {
550
567
  useLayoutEffect(() => {
551
568
  refreshRef.current?.();
552
569
  });
570
+ const readOffsets = useMemo(() => createPinnedOffsetsReader(pinned.start, pinned.end), [pinned]);
553
571
  const plugin = useMemo(() => ({
554
572
  rowModel: 'flat',
555
573
  transformTableContext(children) {
@@ -560,11 +578,7 @@ export function useTableStickyColumns(config) {
560
578
  });
561
579
  },
562
580
  transformHeaderCell(props, column) {
563
- const {
564
- start: s,
565
- end: e
566
- } = pinned;
567
- const side = resolveStickySide(props.columns, column.key, s, e);
581
+ const side = resolveStickySide(readOffsets(props.columns), column.key);
568
582
  if (!side) {
569
583
  return props;
570
584
  }
@@ -601,11 +615,7 @@ export function useTableStickyColumns(config) {
601
615
  };
602
616
  },
603
617
  transformBodyCell(props, column) {
604
- const {
605
- start: s,
606
- end: e
607
- } = pinned;
608
- const side = resolveStickySide(props.columns, column.key, s, e);
618
+ const side = resolveStickySide(readOffsets(props.columns), column.key);
609
619
  if (!side) {
610
620
  return props;
611
621
  }
@@ -665,10 +675,10 @@ export function useTableStickyColumns(config) {
665
675
  };
666
676
  }
667
677
  }),
668
- // `pinned` keeps its identity while the pinned keys keep their values, and
669
- // `attachScrollShadow` is stable, so the plugin object is reused until the
670
- // pinned keys change.
671
- [attachScrollShadow, pinned]);
678
+ // `attachScrollShadow` is stable, and `readOffsets` changes only with the
679
+ // pinned keys. So the plugin object changes only when the pinned keys
680
+ // change.
681
+ [attachScrollShadow, readOffsets]);
672
682
  registerPinnedColumnRuns(plugin, columns => countPinnedRuns(columns, pinned.start, pinned.end));
673
683
  return registerCountIndependentPlugin(plugin);
674
684
  }
@@ -164,18 +164,18 @@ export interface TableColumn<T extends Record<string, unknown>> {
164
164
  * badges, status dots, formatted text, icons, or composed layouts.
165
165
  *
166
166
  * @compositionHint Use renderCell to compose rich table cells:
167
- * - Badge for status labels (success/warning/error variants)
168
- * - StatusDot for colored indicators
167
+ * - StatusDot beside a Text label for a status column
169
168
  * - Text with color="success"|"error" for formatted values
170
169
  * - HStack to combine multiple elements in a cell
171
170
  * - Avatar for user/entity cells
171
+ * - Badge only for a rare state that needs action, not in every row
172
172
  *
173
173
  * @example
174
- * ```tsx
174
+ * ```
175
175
  * renderCell: (item) => (
176
176
  * <HStack gap={2} align="center">
177
- * <StatusDot status={item.isActive ? 'success' : 'error'} />
178
- * <Badge variant={item.isActive ? 'success' : 'error'} label={item.isActive ? 'Active' : 'Inactive'} />
177
+ * <StatusDot variant={item.isActive ? 'success' : 'neutral'} label={item.isActive ? 'Active' : 'Inactive'} />
178
+ * <Text>{item.isActive ? 'Active' : 'Inactive'}</Text>
179
179
  * </HStack>
180
180
  * )
181
181
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../src/Text/Text.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAc,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAElD,OAAO,KAAK,EACV,QAAQ,EAER,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,WAAW,EACX,SAAS,EACT,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAuBxB,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAG7C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAI5C,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C,EAAE,OAAO,GAAG,cAAc,CAAC;IAE9C;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;IAEtB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CAC1D;AA2BD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,gBAAgB,CAQpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,EACnB,IAAa,EACb,IAAI,EACJ,KAAK,EACL,MAAM,EACN,OAAkB,EAClB,QAAY,EACZ,kBAAyB,EACzB,SAAS,EACT,QAAQ,EACR,OAAiB,EACjB,UAAkB,EAClB,gBAAwB,EACxB,iBAAyB,EACzB,MAAM,EACN,SAAS,EACT,KAAK,EACL,EAAE,EAAE,SAAkB,EACtB,QAAQ,EACR,GAAG,EACH,GAAG,KAAK,EACT,EAAE,SAAS,+BA8HX;yBAnJe,IAAI"}
package/dist/Text/Text.js CHANGED
@@ -18,13 +18,13 @@
18
18
  import { use, useRef } from 'react';
19
19
  import * as stylex from '@stylexjs/stylex';
20
20
  import { colorStyles, defaultWeightByTypeStyles, sizeStyles, sizeByTypeStyles, weightStyles, displayStyles, justifyStyles, truncationStyles, wordBreakStyles, textWrapStyles, capsizeStyles, decorationStyles, tabularNumbersStyle, truncationTooltipStyles } from "./text.stylex.js";
21
- import { useTruncation } from "./useTruncation.js";
21
+ import { useTruncationMeasure } from "./useTruncation.js";
22
22
  import { TruncationTooltip, useTruncationTooltipInterest } from "./TruncationTooltip.js";
23
23
  import { composeEventHandlers } from "../utils/composeEventHandlers.js";
24
24
  import { mergeProps } from "../utils/mergeProps.js";
25
25
  import { useMergedRefs } from "../hooks/useMergedRefs.js";
26
26
  import { themeProps } from "../utils/themeProps.js";
27
- import { TextClampContext } from "./textClampContext.js";
27
+ import { TextClampContext, TextMeasureOnInterestContext } from "./textClampContext.js";
28
28
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
29
29
  // Default color by text type — custom types fall back to 'primary'
30
30
  const defaultColorByType = {
@@ -123,21 +123,26 @@ export function Text({
123
123
  // Resolve display - force block when maxLines > 0 or hasCapsize
124
124
  const resolvedDisplay = maxLines > 0 || hasCapsize ? 'block' : display;
125
125
 
126
+ // A Table's default cells mount many texts at once. Text in them measures at
127
+ // each hover, tap or focus, not at mount.
128
+ const measuresOnInterest = use(TextMeasureOnInterestContext) && maxLines > 0 && hasTruncateTooltip !== false;
129
+
126
130
  // Truncation detection. Only the tooltip reads the measured overflow, so
127
131
  // with the tooltip off the text is clipped by CSS alone and nothing is
128
132
  // measured or observed.
129
- const truncation = useTruncation({
130
- maxLines: hasTruncateTooltip === false ? 0 : maxLines
133
+ const truncation = useTruncationMeasure({
134
+ maxLines: hasTruncateTooltip === false ? 0 : maxLines,
135
+ measuresOnInterest
131
136
  });
132
137
 
138
+ // Ref for the text element (used as tooltip anchor)
139
+ const textRef = useRef(null);
140
+
133
141
  // Tooltip for truncated text
134
142
  const tooltipPlacement = typeof hasTruncateTooltip === 'string' ? hasTruncateTooltip : 'above';
135
143
  const tooltipEnabled = maxLines > 0 && hasTruncateTooltip !== false && truncation.isTruncated;
136
144
  // The tooltip mounts on the first hover, tap or focus, not with the text.
137
- const tooltipInterest = useTruncationTooltipInterest(tooltipEnabled);
138
-
139
- // Ref for the text element (used as tooltip anchor)
140
- const textRef = useRef(null);
145
+ const tooltipInterest = useTruncationTooltipInterest(tooltipEnabled, truncation.measure);
141
146
 
142
147
  // Keep the merged ref stable across rerenders.
143
148
  const mergedRef = useMergedRefs(ref, truncation.ref, textRef);
@@ -2,8 +2,9 @@
2
2
  * @file TruncationTooltip.tsx
3
3
  * @input A truncated element's ref, its full text and the tooltip placement
4
4
  * @output Exports `useTruncationTooltipInterest`, which loads the Tooltip
5
- * module once text is truncated and tracks the first hover, tap or focus on
6
- * it, and `TruncationTooltip`, the Tooltip that mounts on that interaction
5
+ * module once text is truncated, or after the page's first paint for text
6
+ * that measures on interest, and tracks the first hover, tap or focus on it,
7
+ * and `TruncationTooltip`, the Tooltip that mounts on that interaction
7
8
  * @position Shared by Text, Heading and Lab's LineClamp (through Core's internal
8
9
  * line-clamp entry). Until the first interaction a page of
9
10
  * truncated text mounts no tooltip layers, and the tooltip that then mounts
@@ -11,7 +12,7 @@
11
12
  */
12
13
  import { type FocusEvent, type PointerEvent, type ReactNode, type RefObject } from 'react';
13
14
  import type { LayerPlacement } from '../Layer/index.js';
14
- import type { Tooltip as TooltipType, UndescribedTooltip as UndescribedTooltipType } from '../Tooltip/Tooltip.js';
15
+ import type { Tooltip as TooltipType } from '../Tooltip/Tooltip.js';
15
16
  import { type TooltipPresentInterestState } from '../Tooltip/tooltipPresentInterest.js';
16
17
  type TooltipComponent = typeof TooltipType;
17
18
  export interface TruncationTooltipInterest {
@@ -29,12 +30,13 @@ export interface TruncationTooltipInterest {
29
30
  }
30
31
  /**
31
32
  * Tracks the interaction that mounts a truncated element's tooltip, while
32
- * `isEnabled`, until the mounted tooltip reads it. A finger's arrival does not
33
+ * `isEnabled` or, with `measure`, while the interaction measures the text
34
+ * truncated, until the mounted tooltip reads it. A finger's arrival does not
33
35
  * count: only a press that the touch trigger's recognizer takes for a tap
34
36
  * does. Once the tooltip has read the interaction, its own listeners take
35
37
  * over.
36
38
  */
37
- export declare function useTruncationTooltipInterest(isEnabled: boolean): TruncationTooltipInterest;
39
+ export declare function useTruncationTooltipInterest(isEnabled: boolean, measure?: () => boolean): TruncationTooltipInterest;
38
40
  /** The truncated element's Tooltip, given the interaction that mounted it. */
39
41
  export declare function TruncationTooltip({ anchorRef, content, placement, interest, }: {
40
42
  anchorRef: RefObject<HTMLElement | null>;
@@ -42,39 +44,5 @@ export declare function TruncationTooltip({ anchorRef, content, placement, inter
42
44
  placement: LayerPlacement;
43
45
  interest: TruncationTooltipInterest;
44
46
  }): ReactNode;
45
- type UndescribedTooltipComponent = typeof UndescribedTooltipType;
46
- export interface CutTextOnKeyboardFocus {
47
- /** The full text while keyboard focus is inside and the text is cut. */
48
- readonly cutText: string | null;
49
- /**
50
- * The tooltip that shows `cutText` with no description, once its module
51
- * has loaded (after the first render, as tooltip code loads).
52
- */
53
- readonly Tooltip: UndescribedTooltipComponent | null;
54
- /** Closes the tooltip; pass it as the tooltip's `onHide` (Escape). */
55
- readonly hide: () => void;
56
- readonly onFocus: (event: FocusEvent<HTMLElement>) => void;
57
- readonly onBlur: (event: FocusEvent<HTMLElement>) => void;
58
- /** A press closes it, as a press closes a tooltip. */
59
- readonly onPointerDown: () => void;
60
- }
61
- /**
62
- * Shows a component's cut text in an undescribed tooltip on keyboard focus:
63
- * a Button's cut label, a table header cell's cut heading. When keyboard focus
64
- * reaches the anchor (or an element inside it), it measures `measureRef`'s
65
- * text; if the text is cut, `cutText` holds it until focus leaves the anchor,
66
- * Escape, or a press. A hover, a pointer-focused field and a touch tap show
67
- * nothing, and nothing is measured at rest. Internal: the package does not
68
- * export it.
69
- */
70
- export declare function useCutTextOnKeyboardFocus({ anchorRef, measureRef, isEnabled, isSuppressed, }: {
71
- /** The element focus reaches and the tooltip attaches to. */
72
- anchorRef: RefObject<HTMLElement | null>;
73
- /** The element whose text is cut; the anchor itself when omitted. */
74
- measureRef?: RefObject<HTMLElement | null>;
75
- isEnabled: boolean;
76
- /** Returns true when another tooltip already describes the anchor. */
77
- isSuppressed?: (anchor: HTMLElement) => boolean;
78
- }): CutTextOnKeyboardFocus;
79
47
  export {};
80
48
  //# sourceMappingURL=TruncationTooltip.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TruncationTooltip.d.ts","sourceRoot":"","sources":["../../src/Text/TruncationTooltip.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH,OAAO,EAKL,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EACV,OAAO,IAAI,WAAW,EACtB,kBAAkB,IAAI,sBAAsB,EAC7C,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,mCAAmC,CAAC;AAE3C,KAAK,gBAAgB,GAAG,OAAO,WAAW,CAAC;AAQ3C,MAAM,WAAW,yBAAyB;IACxC,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC1C,4EAA4E;IAC5E,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAC7D,QAAQ,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACpE,QAAQ,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACpE,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACnE,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,UA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C,WAAW,CAAC,KAAK,IAAI,CAAC;CAC3D;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,OAAO,EAIlB,OAAO,CAAC,EAAE,MAAM,OAAO,GACtB,yBAAyB,CAqH3B;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,EAChC,SAAS,EACT,OAAO,EACP,SAAS,EACT,QAAQ,GACT,EAAE;IACD,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACzC,OAAO,EAAE,SAAS,CAAC;IACnB,SAAS,EAAE,cAAc,CAAC;IAC1B,QAAQ,EAAE,yBAAyB,CAAC;CACrC,GAAG,SAAS,CAYZ"}
@@ -6,8 +6,9 @@
6
6
  * @file TruncationTooltip.tsx
7
7
  * @input A truncated element's ref, its full text and the tooltip placement
8
8
  * @output Exports `useTruncationTooltipInterest`, which loads the Tooltip
9
- * module once text is truncated and tracks the first hover, tap or focus on
10
- * it, and `TruncationTooltip`, the Tooltip that mounts on that interaction
9
+ * module once text is truncated, or after the page's first paint for text
10
+ * that measures on interest, and tracks the first hover, tap or focus on it,
11
+ * and `TruncationTooltip`, the Tooltip that mounts on that interaction
11
12
  * @position Shared by Text, Heading and Lab's LineClamp (through Core's internal
12
13
  * line-clamp entry). Until the first interaction a page of
13
14
  * truncated text mounts no tooltip layers, and the tooltip that then mounts
@@ -15,7 +16,6 @@
15
16
  */
16
17
  import { useCallback, useEffect, useRef, useState } from 'react';
17
18
  import { createModuleLoader } from "../utils/moduleLoader.js";
18
- import { useInteractionModalityTrackingFor } from "../utils/interactionModality.js";
19
19
  import { useTapRecognizer } from "../Layer/gestureCounter.js";
20
20
  import { isElement } from "../utils/nodeType.js";
21
21
  import { TooltipPresentInterestContext } from "../Tooltip/tooltipPresentInterest.js";
@@ -23,47 +23,80 @@ import { jsx as _jsx } from "react/jsx-runtime";
23
23
  // The Tooltip module. Once loaded, a tooltip renders from it at once: no
24
24
  // boundary suspends, so the first hover's delay starts on the hover.
25
25
  const tooltipModule = createModuleLoader(async () => import("../Tooltip/Tooltip.js"));
26
+
27
+ // The page's texts share one preload. It waits a frame and a task for the
28
+ // paint, then loads the module once. The shared loader keeps no failed load,
29
+ // so the next text tries again.
30
+ const afterPaintModule = createModuleLoader(async () => {
31
+ await new Promise(resolve => {
32
+ requestAnimationFrame(() => {
33
+ setTimeout(resolve, 0);
34
+ });
35
+ });
36
+ return tooltipModule.load();
37
+ });
38
+ const loadAfterNextPaint = afterPaintModule.load;
26
39
  /**
27
40
  * Tracks the interaction that mounts a truncated element's tooltip, while
28
- * `isEnabled`, until the mounted tooltip reads it. A finger's arrival does not
41
+ * `isEnabled` or, with `measure`, while the interaction measures the text
42
+ * truncated, until the mounted tooltip reads it. A finger's arrival does not
29
43
  * count: only a press that the touch trigger's recognizer takes for a tap
30
44
  * does. Once the tooltip has read the interaction, its own listeners take
31
45
  * over.
32
46
  */
33
- export function useTruncationTooltipInterest(isEnabled) {
47
+ export function useTruncationTooltipInterest(isEnabled,
48
+ // For text that measures on interest: measures now and returns whether the
49
+ // text is truncated, so the interaction that measures it can mount the
50
+ // tooltip.
51
+ measure) {
34
52
  const [isWanted, setIsWanted] = useState(false);
35
53
  const [tooltip, setTooltip] = useState(() => tooltipModule.loaded()?.Tooltip ?? null);
36
54
  // Syncs with the module loader: truncated text loads the Tooltip module, so
37
- // the first interaction mounts the tooltip at once.
55
+ // the first interaction mounts the tooltip at once. Text that measures on
56
+ // interest has no answer yet. It joins the page's one after-paint preload,
57
+ // so the page shows first, and a hover never hurries the load.
38
58
  useEffect(() => {
39
- if (!isEnabled || tooltip != null) {
59
+ if (!isEnabled && measure == null || tooltip != null) {
40
60
  return;
41
61
  }
42
62
  let isCurrent = true;
43
- tooltipModule.load().then(loaded => {
63
+ const show = loaded => {
44
64
  if (isCurrent) {
45
65
  setTooltip(() => loaded.Tooltip);
46
66
  }
47
- }, () => {});
67
+ };
68
+ (measure == null ? tooltipModule.load() : loadAfterNextPaint()).then(show, () => {});
48
69
  return () => {
49
70
  isCurrent = false;
50
71
  };
51
- }, [isEnabled, tooltip]);
72
+ }, [isEnabled, measure, tooltip]);
52
73
  const interestRef = useRef({
53
74
  interest: null,
54
75
  tapEvent: null,
55
76
  isRead: false
56
77
  });
57
78
  const tapRecognizer = useTapRecognizer();
79
+ // A tooltip that read an interaction unmounts while the text fits. When the
80
+ // text is cut off again, the next tooltip reads the next interaction.
81
+ const measureInterest = useCallback(() => {
82
+ if (measure == null) {
83
+ return isEnabled;
84
+ }
85
+ const isTruncated = measure();
86
+ if (isTruncated && !isEnabled) {
87
+ interestRef.current.isRead = false;
88
+ }
89
+ return isTruncated;
90
+ }, [isEnabled, measure]);
58
91
  const want = useCallback((interest, tapEvent = null) => {
59
92
  const state = interestRef.current;
60
- if (!isEnabled || state.isRead) {
93
+ if (!measureInterest() || state.isRead) {
61
94
  return;
62
95
  }
63
96
  state.interest = interest;
64
97
  state.tapEvent = tapEvent;
65
98
  setIsWanted(true);
66
- }, [isEnabled]);
99
+ }, [measureInterest]);
67
100
  const forget = useCallback(interest => {
68
101
  const state = interestRef.current;
69
102
  if (!state.isRead && state.interest === interest) {
@@ -77,7 +110,7 @@ export function useTruncationTooltipInterest(isEnabled) {
77
110
  }, [want]);
78
111
  const onPointerLeave = useCallback(() => forget('hover'), [forget]);
79
112
  const onPointerDown = useCallback(event => {
80
- if (!isEnabled || interestRef.current.isRead) {
113
+ if (!measureInterest() || interestRef.current.isRead) {
81
114
  tapRecognizer.forget();
82
115
  return;
83
116
  }
@@ -87,7 +120,7 @@ export function useTruncationTooltipInterest(isEnabled) {
87
120
  if (!isTouch) {
88
121
  forget('hover');
89
122
  }
90
- }, [isEnabled, tapRecognizer, want, forget]);
123
+ }, [measureInterest, tapRecognizer, want, forget]);
91
124
  const onFocus = useCallback(event => {
92
125
  const target = event.target;
93
126
  if (isElement(target) && target.matches(':focus-visible') &&
@@ -131,118 +164,4 @@ export function TruncationTooltip({
131
164
  placement: placement
132
165
  })
133
166
  });
134
- }
135
-
136
- /** Whether a box clips its content. */
137
- function overflows(element) {
138
- const box = element.clientWidth || (element instanceof HTMLElement ? element.offsetWidth : 0);
139
- return box > 0 && element.scrollWidth > box;
140
- }
141
-
142
- /** Whether an element is visually hidden: a screen-reader-only label. */
143
- function isVisuallyHidden(element) {
144
- const style = element.ownerDocument.defaultView?.getComputedStyle(element);
145
- return style != null && style.position === 'absolute' && (style.clip !== '' && style.clip !== 'auto' || style.clipPath !== '' && style.clipPath !== 'none');
146
- }
147
-
148
- // A field and its value: an input, or a widget that shows a chosen value (a
149
- // Selector's combobox). Its value is not the component's text.
150
- const FIELD_SELECTOR = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role="combobox"], [role="listbox"], [role="searchbox"], [role="spinbutton"], [role="slider"], [role="textbox"]';
151
-
152
- /**
153
- * Whether an element is left out of the measured text: hidden, a hidden copy
154
- * (ToggleButton's bold-width reservation), visually hidden, or a field, whose
155
- * value clips inside its own box and is not the cut text.
156
- */
157
- function isLeftOut(element) {
158
- return element.closest(`[hidden], [aria-hidden="true"], ${FIELD_SELECTOR}`) != null || isVisuallyHidden(element);
159
- }
160
-
161
- /** Whether text is cut: its box, or a box inside it that a reader sees, clips it. */
162
- function isTextCut(element) {
163
- return overflows(element) || [...element.querySelectorAll('*')].some(child => !isLeftOut(child) && overflows(child));
164
- }
165
-
166
- /**
167
- * The text a sighted reader sees, without hidden, visually hidden and field
168
- * text: the label or heading itself.
169
- */
170
- function visibleText(root) {
171
- let text = '';
172
- const walk = node => {
173
- if (node.nodeType === Node.TEXT_NODE) {
174
- text += node.textContent ?? '';
175
- } else if (node instanceof Element && !isLeftOut(node)) {
176
- node.childNodes.forEach(walk);
177
- }
178
- };
179
- walk(root);
180
- return text.replace(/\s+/g, ' ').trim();
181
- }
182
- /**
183
- * Shows a component's cut text in an undescribed tooltip on keyboard focus:
184
- * a Button's cut label, a table header cell's cut heading. When keyboard focus
185
- * reaches the anchor (or an element inside it), it measures `measureRef`'s
186
- * text; if the text is cut, `cutText` holds it until focus leaves the anchor,
187
- * Escape, or a press. A hover, a pointer-focused field and a touch tap show
188
- * nothing, and nothing is measured at rest. Internal: the package does not
189
- * export it.
190
- */
191
- export function useCutTextOnKeyboardFocus({
192
- anchorRef,
193
- measureRef,
194
- isEnabled,
195
- isSuppressed
196
- }) {
197
- const [cutText, setCutText] = useState(null);
198
- const [Tooltip, setTooltip] = useState(() => tooltipModule.loaded()?.UndescribedTooltip ?? null);
199
- const readModality = useInteractionModalityTrackingFor(anchorRef, isEnabled);
200
- // Syncs with the module loader: the tooltip loads after the first render,
201
- // so keyboard focus shows it at once.
202
- useEffect(() => {
203
- if (!isEnabled || Tooltip != null) {
204
- return;
205
- }
206
- let isCurrent = true;
207
- tooltipModule.load().then(loaded => {
208
- if (isCurrent) {
209
- setTooltip(() => loaded.UndescribedTooltip);
210
- }
211
- }, () => {});
212
- return () => {
213
- isCurrent = false;
214
- };
215
- }, [isEnabled, Tooltip]);
216
- const hide = useCallback(() => setCutText(null), []);
217
- const onFocus = event => {
218
- const anchor = anchorRef.current;
219
- const measured = measureRef?.current ?? anchor;
220
- const target = event.target;
221
- // `:focus-visible` also matches a text field a pointer focused, so the
222
- // modality reader decides: only keyboard focus counts.
223
- if (!isEnabled || anchor == null || measured == null || !isElement(target) ||
224
- // React delivers focus from a portal (a header's filter popover) to the
225
- // anchor's handlers; only focus inside the anchor counts.
226
- !anchor.contains(target) || !target.matches(':focus-visible') || readModality() !== 'keyboard') {
227
- return;
228
- }
229
- const text = visibleText(measured);
230
- const isCut = text !== '' && !(isSuppressed?.(anchor) ?? false) && isTextCut(measured);
231
- setCutText(isCut ? text : null);
232
- };
233
- const onBlur = event => {
234
- const next = event.relatedTarget;
235
- if (isElement(next) && anchorRef.current?.contains(next)) {
236
- return;
237
- }
238
- setCutText(null);
239
- };
240
- return {
241
- cutText,
242
- Tooltip,
243
- hide,
244
- onFocus,
245
- onBlur,
246
- onPointerDown: hide
247
- };
248
167
  }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file cutText.tsx
3
+ * @input The anchor keyboard focus reached, the element whose text a box may
4
+ * cut short, and the focused element
5
+ * @output Exports `cutTextFor`, which measures that text, and
6
+ * `UndescribedTooltip`, which shows it in full
7
+ * @position Loaded by Text/cutTextOnKeyboardFocus.tsx after the page's first
8
+ * paint, so neither the measurement nor the tooltip is in a page's first
9
+ * load
10
+ */
11
+ import type { RefObject } from 'react';
12
+ import { UndescribedTooltip } from '../Tooltip/Tooltip.js';
13
+ /**
14
+ * The text keyboard focus on `target` should show for the anchor: the
15
+ * measured element's text (the anchor's own without `measureRef`) when a box
16
+ * cuts it short and focus is inside the anchor; otherwise `null`. With
17
+ * `yieldsToCallerTooltip` (a Button), a caller tooltip that describes the
18
+ * anchor also gives `null`.
19
+ */
20
+ export declare function cutTextFor(anchorRef: RefObject<HTMLElement | null>, measureRef: RefObject<HTMLElement | null> | undefined, target: Element, yieldsToCallerTooltip: boolean): string | null;
21
+ export { UndescribedTooltip };
22
+ //# sourceMappingURL=cutText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cutText.d.ts","sourceRoot":"","sources":["../../src/Text/cutText.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAgFtD;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EACxC,UAAU,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,SAAS,EACrD,MAAM,EAAE,OAAO,EACf,qBAAqB,EAAE,OAAO,GAC7B,MAAM,GAAG,IAAI,CAef;AAED,OAAO,EAAC,kBAAkB,EAAC,CAAC"}
@@ -0,0 +1,92 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file cutText.tsx
7
+ * @input The anchor keyboard focus reached, the element whose text a box may
8
+ * cut short, and the focused element
9
+ * @output Exports `cutTextFor`, which measures that text, and
10
+ * `UndescribedTooltip`, which shows it in full
11
+ * @position Loaded by Text/cutTextOnKeyboardFocus.tsx after the page's first
12
+ * paint, so neither the measurement nor the tooltip is in a page's first
13
+ * load
14
+ */
15
+ import { UndescribedTooltip } from "../Tooltip/Tooltip.js";
16
+
17
+ /** Whether a box clips its content. */
18
+ function overflows(element) {
19
+ const box = element.clientWidth || (element instanceof HTMLElement ? element.offsetWidth : 0);
20
+ return box > 0 && element.scrollWidth > box;
21
+ }
22
+
23
+ /** Whether an element is visually hidden: a screen-reader-only label. */
24
+ function isVisuallyHidden(element) {
25
+ const style = element.ownerDocument.defaultView?.getComputedStyle(element);
26
+ return style != null && style.position === 'absolute' && (style.clip !== '' && style.clip !== 'auto' || style.clipPath !== '' && style.clipPath !== 'none');
27
+ }
28
+
29
+ // A field and its value: an input, or a widget that shows a chosen value (a
30
+ // Selector's combobox). Its value is not the component's text.
31
+ const FIELD_SELECTOR = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role="combobox"], [role="listbox"], [role="searchbox"], [role="spinbutton"], [role="slider"], [role="textbox"]';
32
+
33
+ /**
34
+ * Whether an element is left out of the measured text: hidden, a hidden copy
35
+ * (ToggleButton's bold-width reservation), visually hidden, or a field, whose
36
+ * value clips inside its own box and is not the cut text.
37
+ */
38
+ function isLeftOut(element) {
39
+ return element.closest(`[hidden], [aria-hidden="true"], ${FIELD_SELECTOR}`) != null || isVisuallyHidden(element);
40
+ }
41
+
42
+ /** Whether text is cut: its box, or a box inside it that a reader sees, clips it. */
43
+ function isTextCut(element) {
44
+ return overflows(element) || [...element.querySelectorAll('*')].some(child => !isLeftOut(child) && overflows(child));
45
+ }
46
+
47
+ /**
48
+ * The text a sighted reader sees, without hidden, visually hidden and field
49
+ * text: the label or heading itself.
50
+ */
51
+ function visibleText(root) {
52
+ let text = '';
53
+ const walk = node => {
54
+ if (node.nodeType === Node.TEXT_NODE) {
55
+ text += node.textContent ?? '';
56
+ } else if (node instanceof Element && !isLeftOut(node)) {
57
+ node.childNodes.forEach(walk);
58
+ }
59
+ };
60
+ walk(root);
61
+ return text.replace(/\s+/g, ' ').trim();
62
+ }
63
+
64
+ /**
65
+ * Whether a caller's tooltip already describes the anchor (a Button's
66
+ * `tooltip` prop or a wrapping Tooltip). Its tooltip replaces this one, so one
67
+ * tooltip shows at one spot.
68
+ */
69
+ function hasCallerTooltip(anchor) {
70
+ const ids = anchor.getAttribute('aria-describedby')?.split(/\s+/) ?? [];
71
+ return ids.some(id => id !== '' && anchor.ownerDocument.getElementById(id)?.getAttribute('role') === 'tooltip');
72
+ }
73
+
74
+ /**
75
+ * The text keyboard focus on `target` should show for the anchor: the
76
+ * measured element's text (the anchor's own without `measureRef`) when a box
77
+ * cuts it short and focus is inside the anchor; otherwise `null`. With
78
+ * `yieldsToCallerTooltip` (a Button), a caller tooltip that describes the
79
+ * anchor also gives `null`.
80
+ */
81
+ export function cutTextFor(anchorRef, measureRef, target, yieldsToCallerTooltip) {
82
+ const anchor = anchorRef.current;
83
+ const measured = measureRef?.current ?? anchor;
84
+ // React delivers focus from a portal (a header's filter popover) to the
85
+ // anchor's handlers; only focus inside the anchor counts.
86
+ if (anchor == null || measured == null || !anchor.contains(target) || yieldsToCallerTooltip && hasCallerTooltip(anchor)) {
87
+ return null;
88
+ }
89
+ const text = visibleText(measured);
90
+ return text !== '' && isTextCut(measured) ? text : null;
91
+ }
92
+ export { UndescribedTooltip };