@astryxdesign/core 0.7.17 → 0.7.18-canary.g170df15

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 (457) 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/Item/Item.d.ts.map +1 -1
  58. package/dist/Item/Item.js +8 -2
  59. package/dist/Kbd/Kbd.d.ts +3 -2
  60. package/dist/Kbd/Kbd.d.ts.map +1 -1
  61. package/dist/Kbd/Kbd.js +3 -2
  62. package/dist/Layer/gestureCounter.d.ts +5 -0
  63. package/dist/Layer/gestureCounter.d.ts.map +1 -1
  64. package/dist/Layer/gestureCounter.js +40 -4
  65. package/dist/Layer/inputHold.d.ts +13 -0
  66. package/dist/Layer/inputHold.d.ts.map +1 -1
  67. package/dist/Layer/inputHold.js +203 -14
  68. package/dist/Layer/layerHost.d.ts +3 -2
  69. package/dist/Layer/layerHost.d.ts.map +1 -1
  70. package/dist/Layer/layerHost.js +3 -2
  71. package/dist/Layer/outsidePanClaim.d.ts +17 -0
  72. package/dist/Layer/outsidePanClaim.d.ts.map +1 -1
  73. package/dist/Layer/outsidePanClaim.js +36 -8
  74. package/dist/Layer/outsidePress.d.ts +7 -1
  75. package/dist/Layer/outsidePress.d.ts.map +1 -1
  76. package/dist/Layer/outsidePress.js +9 -2
  77. package/dist/Layer/useLayer.d.ts +21 -5
  78. package/dist/Layer/useLayer.d.ts.map +1 -1
  79. package/dist/Layer/useLayer.js +63 -40
  80. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  81. package/dist/Lightbox/Lightbox.js +7 -0
  82. package/dist/MetadataList/MetadataList.d.ts +1 -1
  83. package/dist/MetadataList/MetadataList.d.ts.map +1 -1
  84. package/dist/MetadataList/MetadataList.js +8 -0
  85. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  86. package/dist/MultiSelector/MultiSelector.js +37 -17
  87. package/dist/NavIcon/NavIcon.d.ts +2 -2
  88. package/dist/NavIcon/NavIcon.d.ts.map +1 -1
  89. package/dist/NavIcon/NavIcon.js +2 -2
  90. package/dist/NavMenu/NavHeadingMenuItem.d.ts.map +1 -1
  91. package/dist/NavMenu/NavHeadingMenuItem.js +4 -3
  92. package/dist/NumberInput/NumberInput.d.ts +13 -5
  93. package/dist/NumberInput/NumberInput.d.ts.map +1 -1
  94. package/dist/NumberInput/NumberInput.js +6 -17
  95. package/dist/NumberInput/numberParser.d.ts +9 -2
  96. package/dist/NumberInput/numberParser.d.ts.map +1 -1
  97. package/dist/NumberInput/numberParser.js +15 -2
  98. package/dist/Overlay/OverlayScrim.d.ts.map +1 -1
  99. package/dist/Overlay/OverlayScrim.js +13 -4
  100. package/dist/Overlay/useOverlay.d.ts +1 -1
  101. package/dist/Pagination/Pagination.d.ts +3 -2
  102. package/dist/Pagination/Pagination.d.ts.map +1 -1
  103. package/dist/Pagination/Pagination.js +9 -2
  104. package/dist/Popover/usePopover.d.ts +37 -6
  105. package/dist/Popover/usePopover.d.ts.map +1 -1
  106. package/dist/Popover/usePopover.js +103 -20
  107. package/dist/PowerSearch/PowerSearch.d.ts +4 -1
  108. package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
  109. package/dist/PowerSearch/PowerSearch.js +3 -4
  110. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +1 -2
  111. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -1
  112. package/dist/PowerSearch/PowerSearchBottomSheet.js +173 -185
  113. package/dist/PowerSearch/PowerSearchValueEditor.d.ts +0 -12
  114. package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
  115. package/dist/PowerSearch/PowerSearchValueEditor.js +1 -51
  116. package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
  117. package/dist/PowerSearch/formatFilterValue.js +6 -8
  118. package/dist/PowerSearch/formatTokenValue.d.ts +5 -10
  119. package/dist/PowerSearch/formatTokenValue.d.ts.map +1 -1
  120. package/dist/PowerSearch/formatTokenValue.js +21 -38
  121. package/dist/PowerSearch/relativeDateOptions.d.ts +30 -0
  122. package/dist/PowerSearch/relativeDateOptions.d.ts.map +1 -0
  123. package/dist/PowerSearch/relativeDateOptions.js +74 -0
  124. package/dist/ProgressBar/ProgressBar.d.ts +1 -1
  125. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  126. package/dist/ProgressBar/ProgressBar.js +20 -14
  127. package/dist/Resizable/createResizable.d.ts.map +1 -1
  128. package/dist/Resizable/createResizable.js +38 -4
  129. package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
  130. package/dist/SegmentedControl/SegmentedControlItem.js +5 -3
  131. package/dist/SelectableCard/SelectableCard.d.ts.map +1 -1
  132. package/dist/SelectableCard/SelectableCard.js +6 -2
  133. package/dist/Selector/Selector.d.ts.map +1 -1
  134. package/dist/Selector/Selector.js +2 -1
  135. package/dist/SideNav/SideNavItem.d.ts.map +1 -1
  136. package/dist/SideNav/SideNavItem.js +1 -1
  137. package/dist/Slider/Slider.d.ts.map +1 -1
  138. package/dist/Slider/Slider.js +53 -8
  139. package/dist/Stepper/Step.d.ts.map +1 -1
  140. package/dist/Stepper/Step.js +2 -2
  141. package/dist/TabList/Tab.d.ts.map +1 -1
  142. package/dist/TabList/Tab.js +2 -0
  143. package/dist/TabList/TabMenu.d.ts.map +1 -1
  144. package/dist/TabList/TabMenu.js +2 -0
  145. package/dist/Table/BaseTable.d.ts.map +1 -1
  146. package/dist/Table/BaseTable.js +30 -8
  147. package/dist/Table/Table.d.ts +9 -4
  148. package/dist/Table/Table.d.ts.map +1 -1
  149. package/dist/Table/Table.js +9 -4
  150. package/dist/Table/TableHeaderCell.d.ts.map +1 -1
  151. package/dist/Table/TableHeaderCell.js +3 -7
  152. package/dist/Table/plugins/rowIndex/useTableRowIndex.d.ts.map +1 -1
  153. package/dist/Table/plugins/rowIndex/useTableRowIndex.js +4 -1
  154. package/dist/Table/plugins/rowStatus/useTableRowStatus.d.ts.map +1 -1
  155. package/dist/Table/plugins/rowStatus/useTableRowStatus.js +2 -0
  156. package/dist/Table/plugins/sortable/useTableSortable.d.ts.map +1 -1
  157. package/dist/Table/plugins/sortable/useTableSortable.js +18 -1
  158. package/dist/Table/plugins/stickyColumns/useTableStickyColumns.d.ts.map +1 -1
  159. package/dist/Table/plugins/stickyColumns/useTableStickyColumns.js +34 -24
  160. package/dist/Table/tableColumnAdmission.d.ts +7 -0
  161. package/dist/Table/tableColumnAdmission.d.ts.map +1 -1
  162. package/dist/Table/tableColumnAdmission.js +15 -0
  163. package/dist/Table/types.d.ts +5 -5
  164. package/dist/Text/Text.d.ts.map +1 -1
  165. package/dist/Text/Text.js +13 -8
  166. package/dist/Text/TruncationTooltip.d.ts +7 -39
  167. package/dist/Text/TruncationTooltip.d.ts.map +1 -1
  168. package/dist/Text/TruncationTooltip.js +47 -128
  169. package/dist/Text/cutText.d.ts +22 -0
  170. package/dist/Text/cutText.d.ts.map +1 -0
  171. package/dist/Text/cutText.js +92 -0
  172. package/dist/Text/cutTextOnKeyboardFocus.d.ts +41 -0
  173. package/dist/Text/cutTextOnKeyboardFocus.d.ts.map +1 -0
  174. package/dist/Text/cutTextOnKeyboardFocus.js +112 -0
  175. package/dist/Text/textClampContext.d.ts +1 -0
  176. package/dist/Text/textClampContext.d.ts.map +1 -1
  177. package/dist/Text/textClampContext.js +10 -5
  178. package/dist/Text/useTruncation.d.ts +23 -1
  179. package/dist/Text/useTruncation.d.ts.map +1 -1
  180. package/dist/Text/useTruncation.js +74 -28
  181. package/dist/TextInput/TextInput.d.ts +6 -6
  182. package/dist/Thumbnail/Thumbnail.js +4 -1
  183. package/dist/TimeInput/TimeInput.d.ts +0 -3
  184. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  185. package/dist/TimeInput/TimeInput.js +3 -5
  186. package/dist/TimeInput/TouchTimeField.d.ts.map +1 -1
  187. package/dist/TimeInput/TouchTimeField.js +3 -5
  188. package/dist/Timestamp/Timestamp.d.ts.map +1 -1
  189. package/dist/Timestamp/Timestamp.js +22 -16
  190. package/dist/Timestamp/TimestampHoverCard.d.ts +6 -3
  191. package/dist/Timestamp/TimestampHoverCard.d.ts.map +1 -1
  192. package/dist/Timestamp/TimestampHoverCard.js +30 -19
  193. package/dist/Timestamp/formatInstant.d.ts.map +1 -1
  194. package/dist/Timestamp/formatInstant.js +3 -3
  195. package/dist/Timestamp/tooltipEntries.d.ts.map +1 -1
  196. package/dist/Timestamp/tooltipEntries.js +4 -2
  197. package/dist/Toast/Toast.d.ts.map +1 -1
  198. package/dist/Toast/Toast.js +62 -31
  199. package/dist/Toast/ToastViewport.d.ts.map +1 -1
  200. package/dist/Toast/ToastViewport.js +35 -13
  201. package/dist/Toast/useToast.d.ts.map +1 -1
  202. package/dist/Toast/useToast.js +35 -14
  203. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  204. package/dist/Tooltip/useTooltip.js +3 -3
  205. package/dist/astryx.css +38 -8
  206. package/dist/hooks/useAnnounceRenderedText.d.ts +10 -3
  207. package/dist/hooks/useAnnounceRenderedText.d.ts.map +1 -1
  208. package/dist/hooks/useAnnounceRenderedText.js +11 -3
  209. package/dist/hooks/useFocusTrap.d.ts +12 -0
  210. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  211. package/dist/hooks/useFocusTrap.js +13 -6
  212. package/dist/hooks/useHotkeys.d.ts +9 -1
  213. package/dist/hooks/useHotkeys.d.ts.map +1 -1
  214. package/dist/hooks/useHotkeys.js +52 -2
  215. package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
  216. package/dist/hooks/useInputStatusIcon.js +2 -1
  217. package/dist/hooks/useKeyboardHint.d.ts.map +1 -1
  218. package/dist/hooks/useKeyboardHint.js +4 -3
  219. package/dist/i18n/generated-english/DateRangeInput/DateRangeInput.generated.d.ts.map +1 -1
  220. package/dist/i18n/generated-english/DateRangeInput/DateRangeInput.generated.js +2 -0
  221. package/dist/i18n/generated-english/MultiSelector/MultiSelector.generated.d.ts.map +1 -1
  222. package/dist/i18n/generated-english/MultiSelector/MultiSelector.generated.js +1 -0
  223. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
  224. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +0 -6
  225. package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.d.ts +8 -0
  226. package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.d.ts.map +1 -0
  227. package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.js +17 -0
  228. package/dist/i18n/generated-english/Slider/Slider.generated.d.ts.map +1 -1
  229. package/dist/i18n/generated-english/Slider/Slider.generated.js +1 -0
  230. package/dist/i18n/generated-english/Thumbnail/Thumbnail.generated.d.ts.map +1 -1
  231. package/dist/i18n/generated-english/Thumbnail/Thumbnail.generated.js +1 -0
  232. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  233. package/dist/i18n/generated-locales/en.generated.js +5 -0
  234. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  235. package/dist/i18n/generated-locales/pseudo.generated.js +5 -0
  236. package/dist/i18n/getLocaleDirection.d.ts +0 -16
  237. package/dist/i18n/getLocaleDirection.d.ts.map +1 -1
  238. package/dist/i18n/getLocaleDirection.js +16 -6
  239. package/dist/i18n/listFormat.d.ts +34 -0
  240. package/dist/i18n/listFormat.d.ts.map +1 -0
  241. package/dist/i18n/listFormat.js +45 -0
  242. package/dist/i18n/useListFormatter.d.ts +7 -3
  243. package/dist/i18n/useListFormatter.d.ts.map +1 -1
  244. package/dist/i18n/useListFormatter.js +16 -13
  245. package/dist/internal/module-loader.d.ts +15 -0
  246. package/dist/internal/module-loader.d.ts.map +1 -0
  247. package/dist/internal/module-loader.js +15 -0
  248. package/dist/motion/animatedLayout.d.ts +6 -0
  249. package/dist/motion/animatedLayout.d.ts.map +1 -1
  250. package/dist/motion/animatedLayout.js +201 -27
  251. package/dist/palette/color.d.ts +16 -0
  252. package/dist/palette/color.d.ts.map +1 -1
  253. package/dist/palette/color.js +37 -1
  254. package/dist/palette/derive-look.d.ts +235 -0
  255. package/dist/palette/derive-look.d.ts.map +1 -0
  256. package/dist/palette/derive-look.js +879 -0
  257. package/dist/palette/editor-look.d.ts +41 -0
  258. package/dist/palette/editor-look.d.ts.map +1 -0
  259. package/dist/palette/editor-look.js +401 -0
  260. package/dist/palette/mapping.d.ts +99 -6
  261. package/dist/palette/mapping.d.ts.map +1 -1
  262. package/dist/palette/mapping.js +68 -11
  263. package/dist/theme/tokens.d.ts +1 -1
  264. package/dist/theme/tokens.d.ts.map +1 -1
  265. package/dist/theme/tokens.js +1 -1
  266. package/dist/utils/characters.d.ts.map +1 -1
  267. package/dist/utils/characters.js +7 -0
  268. package/dist/utils/devWarning.d.ts +18 -0
  269. package/dist/utils/devWarning.d.ts.map +1 -1
  270. package/dist/utils/devWarning.js +30 -0
  271. package/dist/utils/focusReturn.d.ts +2 -0
  272. package/dist/utils/focusReturn.d.ts.map +1 -1
  273. package/dist/utils/focusReturn.js +3 -8
  274. package/dist/utils/hitArea.d.ts +4 -1
  275. package/dist/utils/hitArea.d.ts.map +1 -1
  276. package/dist/utils/hitArea.js +72 -9
  277. package/dist/utils/mergeProps.d.ts.map +1 -1
  278. package/dist/utils/mergeProps.js +53 -38
  279. package/dist/utils/scrollView.d.ts +2 -2
  280. package/dist/utils/scrollView.d.ts.map +1 -1
  281. package/dist/utils/scrollView.js +3 -3
  282. package/dist/utils/textDirection.d.ts +29 -5
  283. package/dist/utils/textDirection.d.ts.map +1 -1
  284. package/dist/utils/textDirection.js +56 -4
  285. package/dist/utils/touchHitArea.d.ts.map +1 -1
  286. package/dist/utils/touchHitArea.js +4 -2
  287. package/dist/virtualization/useInlineListWindow.d.ts.map +1 -1
  288. package/dist/virtualization/useInlineListWindow.js +63 -4
  289. package/locales/en.json +26 -6
  290. package/locales/pseudo.json +15 -0
  291. package/package.json +10 -5
  292. package/src/AlertDialog/AlertDialog.tsx +15 -0
  293. package/src/AlertDialog/useImperativeAlertDialog.doc.mjs +7 -4
  294. package/src/AppShell/AppShell.tsx +6 -3
  295. package/src/AppShell/observeMainOverflow.ts +39 -9
  296. package/src/Badge/Badge.doc.mjs +3 -3
  297. package/src/BottomSheet/BottomSheet.tsx +15 -0
  298. package/src/BottomSheet/useSheetGestures.ts +26 -1
  299. package/src/Button/Button.tsx +3 -23
  300. package/src/Card/Card.doc.mjs +3 -3
  301. package/src/Card/Card.tsx +11 -6
  302. package/src/Chat/ChatSendButton.doc.mjs +6 -6
  303. package/src/Chat/ChatToolCalls.doc.mjs +1 -1
  304. package/src/CheckboxInput/CheckboxInput.doc.mjs +3 -3
  305. package/src/Citation/Citation.tsx +8 -2
  306. package/src/ClickableCard/ClickableCard.tsx +9 -2
  307. package/src/ComplexSelector/ComplexSelector.doc.mjs +3 -3
  308. package/src/ContextMenu/ContextMenuItem.doc.mjs +3 -3
  309. package/src/DateInput/DateInput.tsx +2 -4
  310. package/src/DateInput/NativeDateField.tsx +5 -4
  311. package/src/DateInput/TouchDateField.tsx +2 -3
  312. package/src/DateInput/useTypedDate.ts +13 -6
  313. package/src/DateRangeInput/DateRangeInput.tsx +14 -10
  314. package/src/DateTimeInput/DateTimeInput.tsx +2 -12
  315. package/src/DateTimeInput/TouchDateTimeField.tsx +2 -11
  316. package/src/Dialog/Dialog.tsx +15 -1
  317. package/src/Dialog/useImperativeDialog.doc.mjs +7 -4
  318. package/src/Drawer/Drawer.tsx +15 -0
  319. package/src/DropdownMenu/DropdownMenu.doc.mjs +1 -1
  320. package/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs +3 -3
  321. package/src/DropdownMenu/DropdownMenuItem.doc.mjs +3 -3
  322. package/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs +3 -3
  323. package/src/DropdownMenu/DropdownMenuSubMenu.doc.mjs +2 -2
  324. package/src/Field/Field.doc.mjs +1 -1
  325. package/src/Field/Field.tsx +2 -1
  326. package/src/Field/FieldLabel.doc.mjs +3 -3
  327. package/src/Field/FieldLabel.tsx +11 -3
  328. package/src/Field/InputClearButton.tsx +27 -0
  329. package/src/Field/inputStyles.stylex.ts +53 -6
  330. package/src/FieldStatus/FieldStatus.tsx +7 -2
  331. package/src/FileInput/FileInput.tsx +12 -2
  332. package/src/Icon/Icon.doc.mjs +17 -14
  333. package/src/Icon/useIcon.doc.mjs +6 -6
  334. package/src/IconButton/IconButton.doc.mjs +2 -2
  335. package/src/InfoTip/InfoTip.doc.mjs +1 -1
  336. package/src/InputGroup/InputGroup.tsx +5 -12
  337. package/src/InputGroup/InputGroupText.tsx +2 -3
  338. package/src/Item/Item.tsx +10 -1
  339. package/src/Kbd/Kbd.doc.mjs +5 -5
  340. package/src/Kbd/Kbd.tsx +3 -2
  341. package/src/Layer/gestureCounter.ts +39 -3
  342. package/src/Layer/inputHold.ts +241 -18
  343. package/src/Layer/layerHost.ts +3 -2
  344. package/src/Layer/outsidePanClaim.ts +50 -8
  345. package/src/Layer/outsidePress.ts +18 -4
  346. package/src/Layer/useLayer.tsx +128 -76
  347. package/src/Lightbox/Lightbox.tsx +15 -0
  348. package/src/MetadataList/MetadataList.tsx +8 -0
  349. package/src/MoreMenu/MoreMenu.doc.mjs +1 -1
  350. package/src/MultiSelector/MultiSelector.doc.mjs +2 -2
  351. package/src/MultiSelector/MultiSelector.tsx +45 -15
  352. package/src/NavIcon/NavIcon.doc.mjs +19 -10
  353. package/src/NavIcon/NavIcon.tsx +3 -2
  354. package/src/NavMenu/NavHeadingMenuItem.tsx +9 -3
  355. package/src/NumberInput/NumberInput.doc.mjs +12 -12
  356. package/src/NumberInput/NumberInput.tsx +12 -15
  357. package/src/NumberInput/numberParser.ts +15 -2
  358. package/src/Overlay/Overlay.doc.mjs +13 -1
  359. package/src/Overlay/OverlayScrim.tsx +45 -15
  360. package/src/Overlay/useOverlay.doc.mjs +7 -7
  361. package/src/Overlay/useOverlay.tsx +1 -1
  362. package/src/Pagination/Pagination.doc.mjs +9 -6
  363. package/src/Pagination/Pagination.tsx +15 -3
  364. package/src/Popover/usePopover.doc.mjs +14 -4
  365. package/src/Popover/usePopover.tsx +180 -23
  366. package/src/PowerSearch/PowerSearch.doc.mjs +165 -15
  367. package/src/PowerSearch/PowerSearch.tsx +6 -8
  368. package/src/PowerSearch/PowerSearchBottomSheet.tsx +182 -223
  369. package/src/PowerSearch/PowerSearchValueEditor.tsx +1 -51
  370. package/src/PowerSearch/formatFilterValue.ts +8 -9
  371. package/src/PowerSearch/formatTokenValue.ts +24 -42
  372. package/src/PowerSearch/relativeDateOptions.ts +84 -0
  373. package/src/ProgressBar/ProgressBar.doc.mjs +24 -5
  374. package/src/ProgressBar/ProgressBar.tsx +28 -18
  375. package/src/Resizable/createResizable.ts +46 -5
  376. package/src/SegmentedControl/SegmentedControlItem.tsx +4 -3
  377. package/src/SelectableCard/SelectableCard.tsx +8 -2
  378. package/src/Selector/Selector.doc.mjs +3 -3
  379. package/src/Selector/Selector.tsx +3 -1
  380. package/src/Selector/SelectorOption.doc.mjs +3 -3
  381. package/src/SideNav/SideNavItem.doc.mjs +6 -6
  382. package/src/SideNav/SideNavItem.tsx +3 -0
  383. package/src/Slider/Slider.tsx +48 -6
  384. package/src/Stepper/Step.tsx +7 -1
  385. package/src/Switch/Switch.doc.mjs +3 -3
  386. package/src/TabList/Tab.tsx +4 -0
  387. package/src/TabList/TabMenu.tsx +4 -0
  388. package/src/Table/BaseTable.tsx +35 -7
  389. package/src/Table/Table.doc.mjs +56 -6
  390. package/src/Table/Table.tsx +9 -4
  391. package/src/Table/TableHeaderCell.tsx +2 -8
  392. package/src/Table/plugins/rowIndex/useTableRowIndex.tsx +10 -1
  393. package/src/Table/plugins/rowStatus/useTableRowStatus.tsx +5 -0
  394. package/src/Table/plugins/sortable/useTableSortable.tsx +41 -2
  395. package/src/Table/plugins/stickyColumns/useTableStickyColumns.tsx +49 -20
  396. package/src/Table/tableColumnAdmission.ts +23 -0
  397. package/src/Table/types.ts +5 -5
  398. package/src/Table/useTableRowsVirtualization.doc.mjs +2 -2
  399. package/src/Text/Text.tsx +21 -7
  400. package/src/Text/TruncationTooltip.tsx +51 -184
  401. package/src/Text/cutText.tsx +126 -0
  402. package/src/Text/cutTextOnKeyboardFocus.tsx +158 -0
  403. package/src/Text/textClampContext.ts +14 -4
  404. package/src/Text/useTruncation.ts +85 -27
  405. package/src/TextArea/TextArea.doc.mjs +4 -4
  406. package/src/TextInput/TextInput.doc.mjs +3 -3
  407. package/src/Thumbnail/Thumbnail.tsx +1 -1
  408. package/src/TimeInput/TimeInput.tsx +3 -9
  409. package/src/TimeInput/TouchTimeField.tsx +6 -4
  410. package/src/Timestamp/Timestamp.tsx +29 -21
  411. package/src/Timestamp/TimestampHoverCard.tsx +44 -31
  412. package/src/Timestamp/formatInstant.ts +7 -3
  413. package/src/Timestamp/tooltipEntries.ts +4 -2
  414. package/src/Toast/Toast.doc.mjs +24 -37
  415. package/src/Toast/Toast.tsx +77 -29
  416. package/src/Toast/ToastViewport.tsx +33 -13
  417. package/src/Toast/useToast.tsx +42 -15
  418. package/src/Tokenizer/Tokenizer.doc.mjs +2 -2
  419. package/src/Tooltip/useTooltip.tsx +2 -1
  420. package/src/TopNav/TopNavMegaMenu.doc.mjs +13 -0
  421. package/src/TopNav/TopNavMenu.doc.mjs +2 -0
  422. package/src/Typeahead/Typeahead.doc.mjs +2 -2
  423. package/src/hooks/useAnnounceRenderedText.ts +15 -2
  424. package/src/hooks/useFocusTrap.ts +27 -4
  425. package/src/hooks/useHotkeys.doc.mjs +54 -11
  426. package/src/hooks/useHotkeys.ts +72 -3
  427. package/src/hooks/useInputStatusIcon.tsx +2 -1
  428. package/src/hooks/useKeyboardHint.tsx +3 -2
  429. package/src/i18n/generated-english/DateRangeInput/DateRangeInput.generated.ts +2 -0
  430. package/src/i18n/generated-english/MultiSelector/MultiSelector.generated.ts +1 -0
  431. package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +0 -6
  432. package/src/i18n/generated-english/PowerSearch/relativeDateOptions.generated.ts +18 -0
  433. package/src/i18n/generated-english/Slider/Slider.generated.ts +1 -0
  434. package/src/i18n/generated-english/Thumbnail/Thumbnail.generated.ts +1 -0
  435. package/src/i18n/generated-locales/en.generated.ts +5 -0
  436. package/src/i18n/generated-locales/pseudo.generated.ts +5 -0
  437. package/src/i18n/getLocaleDirection.ts +57 -7
  438. package/src/i18n/listFormat.ts +55 -0
  439. package/src/i18n/useListFormatter.ts +22 -13
  440. package/src/internal/module-loader.ts +15 -0
  441. package/src/motion/animatedLayout.ts +215 -28
  442. package/src/palette/color.ts +41 -1
  443. package/src/palette/derive-look.ts +1186 -0
  444. package/src/palette/editor-look.ts +480 -0
  445. package/src/palette/mapping.ts +129 -15
  446. package/src/theme/SyntaxTheme.doc.mjs +1 -1
  447. package/src/theme/tokens.ts +2 -1
  448. package/src/theme/useThemeName.doc.mjs +1 -1
  449. package/src/utils/characters.ts +11 -0
  450. package/src/utils/devWarning.ts +35 -0
  451. package/src/utils/focusReturn.ts +3 -11
  452. package/src/utils/hitArea.ts +87 -18
  453. package/src/utils/mergeProps.ts +57 -34
  454. package/src/utils/scrollView.ts +3 -2
  455. package/src/utils/textDirection.ts +65 -5
  456. package/src/utils/touchHitArea.ts +3 -2
  457. package/src/virtualization/useInlineListWindow.ts +102 -11
@@ -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
@@ -26,11 +27,7 @@ import {
26
27
  } from 'react';
27
28
  import type {LayerPlacement} from '../Layer';
28
29
  import {createModuleLoader} from '../utils/moduleLoader';
29
- import type {
30
- Tooltip as TooltipType,
31
- UndescribedTooltip as UndescribedTooltipType,
32
- } from '../Tooltip/Tooltip';
33
- import {useInteractionModalityTrackingFor} from '../utils/interactionModality';
30
+ import type {Tooltip as TooltipType} from '../Tooltip/Tooltip';
34
31
  import {useTapRecognizer} from '../Layer/gestureCounter';
35
32
  import {isElement} from '../utils/nodeType';
36
33
  import {
@@ -46,6 +43,19 @@ const tooltipModule = createModuleLoader(
46
43
  async () => import('../Tooltip/Tooltip'),
47
44
  );
48
45
 
46
+ // The page's texts share one preload. It waits a frame and a task for the
47
+ // paint, then loads the module once. The shared loader keeps no failed load,
48
+ // so the next text tries again.
49
+ const afterPaintModule = createModuleLoader(async () => {
50
+ await new Promise<void>(resolve => {
51
+ requestAnimationFrame(() => {
52
+ setTimeout(resolve, 0);
53
+ });
54
+ });
55
+ return tooltipModule.load();
56
+ });
57
+ const loadAfterNextPaint = afterPaintModule.load;
58
+
49
59
  export interface TruncationTooltipInterest {
50
60
  /** Whether a hover, tap or focus has reached the element. It stays true. */
51
61
  readonly isWanted: boolean;
@@ -62,54 +72,74 @@ export interface TruncationTooltipInterest {
62
72
 
63
73
  /**
64
74
  * Tracks the interaction that mounts a truncated element's tooltip, while
65
- * `isEnabled`, until the mounted tooltip reads it. A finger's arrival does not
75
+ * `isEnabled` or, with `measure`, while the interaction measures the text
76
+ * truncated, until the mounted tooltip reads it. A finger's arrival does not
66
77
  * count: only a press that the touch trigger's recognizer takes for a tap
67
78
  * does. Once the tooltip has read the interaction, its own listeners take
68
79
  * over.
69
80
  */
70
81
  export function useTruncationTooltipInterest(
71
82
  isEnabled: boolean,
83
+ // For text that measures on interest: measures now and returns whether the
84
+ // text is truncated, so the interaction that measures it can mount the
85
+ // tooltip.
86
+ measure?: () => boolean,
72
87
  ): TruncationTooltipInterest {
73
88
  const [isWanted, setIsWanted] = useState(false);
74
89
  const [tooltip, setTooltip] = useState<TooltipComponent | null>(
75
90
  () => tooltipModule.loaded()?.Tooltip ?? null,
76
91
  );
77
92
  // Syncs with the module loader: truncated text loads the Tooltip module, so
78
- // the first interaction mounts the tooltip at once.
93
+ // the first interaction mounts the tooltip at once. Text that measures on
94
+ // interest has no answer yet. It joins the page's one after-paint preload,
95
+ // so the page shows first, and a hover never hurries the load.
79
96
  useEffect(() => {
80
- if (!isEnabled || tooltip != null) {
97
+ if ((!isEnabled && measure == null) || tooltip != null) {
81
98
  return;
82
99
  }
83
100
  let isCurrent = true;
84
- tooltipModule.load().then(
85
- loaded => {
86
- if (isCurrent) {
87
- setTooltip(() => loaded.Tooltip);
88
- }
89
- },
101
+ const show = (loaded: {Tooltip: TooltipComponent}) => {
102
+ if (isCurrent) {
103
+ setTooltip(() => loaded.Tooltip);
104
+ }
105
+ };
106
+ (measure == null ? tooltipModule.load() : loadAfterNextPaint()).then(
107
+ show,
90
108
  () => {},
91
109
  );
92
110
  return () => {
93
111
  isCurrent = false;
94
112
  };
95
- }, [isEnabled, tooltip]);
113
+ }, [isEnabled, measure, tooltip]);
96
114
  const interestRef = useRef<TooltipPresentInterestState>({
97
115
  interest: null,
98
116
  tapEvent: null,
99
117
  isRead: false,
100
118
  });
101
119
  const tapRecognizer = useTapRecognizer();
120
+ // A tooltip that read an interaction unmounts while the text fits. When the
121
+ // text is cut off again, the next tooltip reads the next interaction.
122
+ const measureInterest = useCallback((): boolean => {
123
+ if (measure == null) {
124
+ return isEnabled;
125
+ }
126
+ const isTruncated = measure();
127
+ if (isTruncated && !isEnabled) {
128
+ interestRef.current.isRead = false;
129
+ }
130
+ return isTruncated;
131
+ }, [isEnabled, measure]);
102
132
  const want = useCallback(
103
133
  (interest: 'hover' | 'tap' | 'focus', tapEvent: Event | null = null) => {
104
134
  const state = interestRef.current;
105
- if (!isEnabled || state.isRead) {
135
+ if (!measureInterest() || state.isRead) {
106
136
  return;
107
137
  }
108
138
  state.interest = interest;
109
139
  state.tapEvent = tapEvent;
110
140
  setIsWanted(true);
111
141
  },
112
- [isEnabled],
142
+ [measureInterest],
113
143
  );
114
144
  const forget = useCallback((interest: 'hover' | 'focus') => {
115
145
  const state = interestRef.current;
@@ -128,7 +158,7 @@ export function useTruncationTooltipInterest(
128
158
  const onPointerLeave = useCallback(() => forget('hover'), [forget]);
129
159
  const onPointerDown = useCallback(
130
160
  (event: PointerEvent<HTMLElement>) => {
131
- if (!isEnabled || interestRef.current.isRead) {
161
+ if (!measureInterest() || interestRef.current.isRead) {
132
162
  tapRecognizer.forget();
133
163
  return;
134
164
  }
@@ -143,7 +173,7 @@ export function useTruncationTooltipInterest(
143
173
  forget('hover');
144
174
  }
145
175
  },
146
- [isEnabled, tapRecognizer, want, forget],
176
+ [measureInterest, tapRecognizer, want, forget],
147
177
  );
148
178
  const onFocus = useCallback(
149
179
  (event: FocusEvent<HTMLElement>) => {
@@ -197,166 +227,3 @@ export function TruncationTooltip({
197
227
  </TooltipPresentInterestContext>
198
228
  );
199
229
  }
200
-
201
- /** Whether a box clips its content. */
202
- function overflows(element: Element): boolean {
203
- const box =
204
- element.clientWidth ||
205
- (element instanceof HTMLElement ? element.offsetWidth : 0);
206
- return box > 0 && element.scrollWidth > box;
207
- }
208
-
209
- /** Whether an element is visually hidden: a screen-reader-only label. */
210
- function isVisuallyHidden(element: Element): boolean {
211
- const style = element.ownerDocument.defaultView?.getComputedStyle(element);
212
- return (
213
- style != null &&
214
- style.position === 'absolute' &&
215
- ((style.clip !== '' && style.clip !== 'auto') ||
216
- (style.clipPath !== '' && style.clipPath !== 'none'))
217
- );
218
- }
219
-
220
- // A field and its value: an input, or a widget that shows a chosen value (a
221
- // Selector's combobox). Its value is not the component's text.
222
- const FIELD_SELECTOR =
223
- 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role="combobox"], [role="listbox"], [role="searchbox"], [role="spinbutton"], [role="slider"], [role="textbox"]';
224
-
225
- /**
226
- * Whether an element is left out of the measured text: hidden, a hidden copy
227
- * (ToggleButton's bold-width reservation), visually hidden, or a field, whose
228
- * value clips inside its own box and is not the cut text.
229
- */
230
- function isLeftOut(element: Element): boolean {
231
- return (
232
- element.closest(`[hidden], [aria-hidden="true"], ${FIELD_SELECTOR}`) !=
233
- null || isVisuallyHidden(element)
234
- );
235
- }
236
-
237
- /** Whether text is cut: its box, or a box inside it that a reader sees, clips it. */
238
- function isTextCut(element: HTMLElement): boolean {
239
- return (
240
- overflows(element) ||
241
- [...element.querySelectorAll('*')].some(
242
- child => !isLeftOut(child) && overflows(child),
243
- )
244
- );
245
- }
246
-
247
- /**
248
- * The text a sighted reader sees, without hidden, visually hidden and field
249
- * text: the label or heading itself.
250
- */
251
- function visibleText(root: HTMLElement): string {
252
- let text = '';
253
- const walk = (node: Node) => {
254
- if (node.nodeType === Node.TEXT_NODE) {
255
- text += node.textContent ?? '';
256
- } else if (node instanceof Element && !isLeftOut(node)) {
257
- node.childNodes.forEach(walk);
258
- }
259
- };
260
- walk(root);
261
- return text.replace(/\s+/g, ' ').trim();
262
- }
263
-
264
- type UndescribedTooltipComponent = typeof UndescribedTooltipType;
265
-
266
- export interface CutTextOnKeyboardFocus {
267
- /** The full text while keyboard focus is inside and the text is cut. */
268
- readonly cutText: string | null;
269
- /**
270
- * The tooltip that shows `cutText` with no description, once its module
271
- * has loaded (after the first render, as tooltip code loads).
272
- */
273
- readonly Tooltip: UndescribedTooltipComponent | null;
274
- /** Closes the tooltip; pass it as the tooltip's `onHide` (Escape). */
275
- readonly hide: () => void;
276
- readonly onFocus: (event: FocusEvent<HTMLElement>) => void;
277
- readonly onBlur: (event: FocusEvent<HTMLElement>) => void;
278
- /** A press closes it, as a press closes a tooltip. */
279
- readonly onPointerDown: () => void;
280
- }
281
-
282
- /**
283
- * Shows a component's cut text in an undescribed tooltip on keyboard focus:
284
- * a Button's cut label, a table header cell's cut heading. When keyboard focus
285
- * reaches the anchor (or an element inside it), it measures `measureRef`'s
286
- * text; if the text is cut, `cutText` holds it until focus leaves the anchor,
287
- * Escape, or a press. A hover, a pointer-focused field and a touch tap show
288
- * nothing, and nothing is measured at rest. Internal: the package does not
289
- * export it.
290
- */
291
- export function useCutTextOnKeyboardFocus({
292
- anchorRef,
293
- measureRef,
294
- isEnabled,
295
- isSuppressed,
296
- }: {
297
- /** The element focus reaches and the tooltip attaches to. */
298
- anchorRef: RefObject<HTMLElement | null>;
299
- /** The element whose text is cut; the anchor itself when omitted. */
300
- measureRef?: RefObject<HTMLElement | null>;
301
- isEnabled: boolean;
302
- /** Returns true when another tooltip already describes the anchor. */
303
- isSuppressed?: (anchor: HTMLElement) => boolean;
304
- }): CutTextOnKeyboardFocus {
305
- const [cutText, setCutText] = useState<string | null>(null);
306
- const [Tooltip, setTooltip] = useState<UndescribedTooltipComponent | null>(
307
- () => tooltipModule.loaded()?.UndescribedTooltip ?? null,
308
- );
309
- const readModality = useInteractionModalityTrackingFor(anchorRef, isEnabled);
310
- // Syncs with the module loader: the tooltip loads after the first render,
311
- // so keyboard focus shows it at once.
312
- useEffect(() => {
313
- if (!isEnabled || Tooltip != null) {
314
- return;
315
- }
316
- let isCurrent = true;
317
- tooltipModule.load().then(
318
- loaded => {
319
- if (isCurrent) {
320
- setTooltip(() => loaded.UndescribedTooltip);
321
- }
322
- },
323
- () => {},
324
- );
325
- return () => {
326
- isCurrent = false;
327
- };
328
- }, [isEnabled, Tooltip]);
329
- const hide = useCallback(() => setCutText(null), []);
330
- const onFocus = (event: FocusEvent<HTMLElement>) => {
331
- const anchor = anchorRef.current;
332
- const measured = measureRef?.current ?? anchor;
333
- const target = event.target;
334
- // `:focus-visible` also matches a text field a pointer focused, so the
335
- // modality reader decides: only keyboard focus counts.
336
- if (
337
- !isEnabled ||
338
- anchor == null ||
339
- measured == null ||
340
- !isElement(target) ||
341
- // React delivers focus from a portal (a header's filter popover) to the
342
- // anchor's handlers; only focus inside the anchor counts.
343
- !anchor.contains(target) ||
344
- !target.matches(':focus-visible') ||
345
- readModality() !== 'keyboard'
346
- ) {
347
- return;
348
- }
349
- const text = visibleText(measured);
350
- const isCut =
351
- text !== '' && !(isSuppressed?.(anchor) ?? false) && isTextCut(measured);
352
- setCutText(isCut ? text : null);
353
- };
354
- const onBlur = (event: FocusEvent<HTMLElement>) => {
355
- const next = event.relatedTarget;
356
- if (isElement(next) && anchorRef.current?.contains(next)) {
357
- return;
358
- }
359
- setCutText(null);
360
- };
361
- return {cutText, Tooltip, hide, onFocus, onBlur, onPointerDown: hide};
362
- }
@@ -0,0 +1,126 @@
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
+
16
+ import type {RefObject} from 'react';
17
+ import {UndescribedTooltip} from '../Tooltip/Tooltip';
18
+
19
+ /** Whether a box clips its content. */
20
+ function overflows(element: Element): boolean {
21
+ const box =
22
+ element.clientWidth ||
23
+ (element instanceof HTMLElement ? element.offsetWidth : 0);
24
+ return box > 0 && element.scrollWidth > box;
25
+ }
26
+
27
+ /** Whether an element is visually hidden: a screen-reader-only label. */
28
+ function isVisuallyHidden(element: Element): boolean {
29
+ const style = element.ownerDocument.defaultView?.getComputedStyle(element);
30
+ return (
31
+ style != null &&
32
+ style.position === 'absolute' &&
33
+ ((style.clip !== '' && style.clip !== 'auto') ||
34
+ (style.clipPath !== '' && style.clipPath !== 'none'))
35
+ );
36
+ }
37
+
38
+ // A field and its value: an input, or a widget that shows a chosen value (a
39
+ // Selector's combobox). Its value is not the component's text.
40
+ const FIELD_SELECTOR =
41
+ 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role="combobox"], [role="listbox"], [role="searchbox"], [role="spinbutton"], [role="slider"], [role="textbox"]';
42
+
43
+ /**
44
+ * Whether an element is left out of the measured text: hidden, a hidden copy
45
+ * (ToggleButton's bold-width reservation), visually hidden, or a field, whose
46
+ * value clips inside its own box and is not the cut text.
47
+ */
48
+ function isLeftOut(element: Element): boolean {
49
+ return (
50
+ element.closest(`[hidden], [aria-hidden="true"], ${FIELD_SELECTOR}`) !=
51
+ null || isVisuallyHidden(element)
52
+ );
53
+ }
54
+
55
+ /** Whether text is cut: its box, or a box inside it that a reader sees, clips it. */
56
+ function isTextCut(element: HTMLElement): boolean {
57
+ return (
58
+ overflows(element) ||
59
+ [...element.querySelectorAll('*')].some(
60
+ child => !isLeftOut(child) && overflows(child),
61
+ )
62
+ );
63
+ }
64
+
65
+ /**
66
+ * The text a sighted reader sees, without hidden, visually hidden and field
67
+ * text: the label or heading itself.
68
+ */
69
+ function visibleText(root: HTMLElement): string {
70
+ let text = '';
71
+ const walk = (node: Node) => {
72
+ if (node.nodeType === Node.TEXT_NODE) {
73
+ text += node.textContent ?? '';
74
+ } else if (node instanceof Element && !isLeftOut(node)) {
75
+ node.childNodes.forEach(walk);
76
+ }
77
+ };
78
+ walk(root);
79
+ return text.replace(/\s+/g, ' ').trim();
80
+ }
81
+
82
+ /**
83
+ * Whether a caller's tooltip already describes the anchor (a Button's
84
+ * `tooltip` prop or a wrapping Tooltip). Its tooltip replaces this one, so one
85
+ * tooltip shows at one spot.
86
+ */
87
+ function hasCallerTooltip(anchor: HTMLElement): boolean {
88
+ const ids = anchor.getAttribute('aria-describedby')?.split(/\s+/) ?? [];
89
+ return ids.some(
90
+ id =>
91
+ id !== '' &&
92
+ anchor.ownerDocument.getElementById(id)?.getAttribute('role') ===
93
+ 'tooltip',
94
+ );
95
+ }
96
+
97
+ /**
98
+ * The text keyboard focus on `target` should show for the anchor: the
99
+ * measured element's text (the anchor's own without `measureRef`) when a box
100
+ * cuts it short and focus is inside the anchor; otherwise `null`. With
101
+ * `yieldsToCallerTooltip` (a Button), a caller tooltip that describes the
102
+ * anchor also gives `null`.
103
+ */
104
+ export function cutTextFor(
105
+ anchorRef: RefObject<HTMLElement | null>,
106
+ measureRef: RefObject<HTMLElement | null> | undefined,
107
+ target: Element,
108
+ yieldsToCallerTooltip: boolean,
109
+ ): string | null {
110
+ const anchor = anchorRef.current;
111
+ const measured = measureRef?.current ?? anchor;
112
+ // React delivers focus from a portal (a header's filter popover) to the
113
+ // anchor's handlers; only focus inside the anchor counts.
114
+ if (
115
+ anchor == null ||
116
+ measured == null ||
117
+ !anchor.contains(target) ||
118
+ (yieldsToCallerTooltip && hasCallerTooltip(anchor))
119
+ ) {
120
+ return null;
121
+ }
122
+ const text = visibleText(measured);
123
+ return text !== '' && isTextCut(measured) ? text : null;
124
+ }
125
+
126
+ export {UndescribedTooltip};
@@ -0,0 +1,158 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file cutTextOnKeyboardFocus.tsx
7
+ * @input An anchor that keyboard focus reaches and the element whose text a
8
+ * box may cut short
9
+ * @output Exports `useCutTextOnKeyboardFocus`, which shows that text in full
10
+ * in an undescribed tooltip while keyboard focus is inside the anchor and
11
+ * the text is cut
12
+ * @position Used by Button (a cut label) and TableHeaderCell (a cut heading).
13
+ * Its first-load part is the focus handlers. The measurement and the
14
+ * tooltip load in one module after the page's first paint (cutText.tsx).
15
+ */
16
+
17
+ import {
18
+ useCallback,
19
+ useEffect,
20
+ useRef,
21
+ useState,
22
+ type FocusEvent,
23
+ type ReactNode,
24
+ type RefObject,
25
+ } from 'react';
26
+ import {useInteractionModalityTrackingFor} from '../utils/interactionModality';
27
+ import {createModuleLoader} from '../utils/moduleLoader';
28
+ import {isElement} from '../utils/nodeType';
29
+
30
+ // A parent's commit can run this hook's effect before the browser paints, as
31
+ // a Table's commit does. A task queued in the next animation frame runs after
32
+ // that frame paints.
33
+ const cutTextModule = createModuleLoader(async () => {
34
+ await new Promise<void>(resolve => {
35
+ requestAnimationFrame(() => {
36
+ setTimeout(resolve, 0);
37
+ });
38
+ });
39
+ return import('./cutText');
40
+ });
41
+
42
+ export interface CutTextOnKeyboardFocus {
43
+ /** The tooltip to render beside the anchor; `null` while none can show. */
44
+ readonly tooltip: ReactNode;
45
+ readonly onFocus: (event: FocusEvent<HTMLElement>) => void;
46
+ readonly onBlur: (event: FocusEvent<HTMLElement>) => void;
47
+ /** A press closes it, as a press closes a tooltip. */
48
+ readonly onPointerDown: () => void;
49
+ }
50
+
51
+ /**
52
+ * Shows a component's cut text in an undescribed tooltip on keyboard focus:
53
+ * a Button's cut label, a table header cell's cut heading. When keyboard focus
54
+ * reaches the anchor or an element inside it, the loaded module measures
55
+ * `measureRef`'s text; if a box cuts it short, it shows until focus leaves the
56
+ * anchor, Escape, or a press. With `yieldsToCallerTooltip`, a caller's own
57
+ * tooltip on the anchor wins. A hover and a touch tap show nothing, and
58
+ * nothing is measured at rest. A focus that arrives before the module loads
59
+ * shows once it loads, if focus is still there; a press first drops it.
60
+ * Internal: the package does not export it.
61
+ */
62
+ export function useCutTextOnKeyboardFocus({
63
+ anchorRef,
64
+ measureRef,
65
+ isEnabled,
66
+ yieldsToCallerTooltip = false,
67
+ }: {
68
+ /** The element focus reaches and the tooltip attaches to. */
69
+ anchorRef: RefObject<HTMLElement | null>;
70
+ /** The element whose text is cut; the anchor itself when omitted. */
71
+ measureRef?: RefObject<HTMLElement | null>;
72
+ isEnabled: boolean;
73
+ /** Shows nothing while a caller's tooltip describes the anchor (Button). */
74
+ yieldsToCallerTooltip?: boolean;
75
+ }): CutTextOnKeyboardFocus {
76
+ const [cutText, setCutText] = useState<string | null>(null);
77
+ const heldFocusRef = useRef<Element | null>(null);
78
+ const readModality = useInteractionModalityTrackingFor(anchorRef, isEnabled);
79
+ // Syncs with the module loader: the module loads after the page's first
80
+ // paint, and a focus that arrived before it shows then.
81
+ useEffect(() => {
82
+ if (!isEnabled || cutTextModule.loaded() != null) {
83
+ return;
84
+ }
85
+ let isCurrent = true;
86
+ cutTextModule.load().then(
87
+ module => {
88
+ if (!isCurrent) {
89
+ return;
90
+ }
91
+ const held = heldFocusRef.current;
92
+ heldFocusRef.current = null;
93
+ if (held?.matches(':focus-visible') === true) {
94
+ setCutText(
95
+ module.cutTextFor(
96
+ anchorRef,
97
+ measureRef,
98
+ held,
99
+ yieldsToCallerTooltip,
100
+ ),
101
+ );
102
+ }
103
+ },
104
+ () => {},
105
+ );
106
+ return () => {
107
+ isCurrent = false;
108
+ };
109
+ }, [isEnabled, anchorRef, measureRef, yieldsToCallerTooltip]);
110
+ // The open tooltip takes this as `onHide`, so it keeps one identity.
111
+ const hide = useCallback(() => {
112
+ heldFocusRef.current = null;
113
+ setCutText(null);
114
+ }, []);
115
+ const onFocus = (event: FocusEvent<HTMLElement>) => {
116
+ const target = event.target;
117
+ // `:focus-visible` also matches a text field a pointer focused, so the
118
+ // modality reader decides: only keyboard focus counts.
119
+ if (
120
+ !isEnabled ||
121
+ !isElement(target) ||
122
+ !target.matches(':focus-visible') ||
123
+ readModality() !== 'keyboard'
124
+ ) {
125
+ return;
126
+ }
127
+ const loaded = cutTextModule.loaded();
128
+ if (loaded == null) {
129
+ heldFocusRef.current = target;
130
+ } else {
131
+ setCutText(
132
+ loaded.cutTextFor(anchorRef, measureRef, target, yieldsToCallerTooltip),
133
+ );
134
+ }
135
+ };
136
+ const onBlur = (event: FocusEvent<HTMLElement>) => {
137
+ const next = event.relatedTarget;
138
+ if (!(isElement(next) && anchorRef.current?.contains(next))) {
139
+ hide();
140
+ }
141
+ };
142
+ // The module is set once, before the state update that shows a text, so a
143
+ // render with a text always finds it.
144
+ const loaded = cutTextModule.loaded();
145
+ return {
146
+ tooltip:
147
+ isEnabled && cutText != null && loaded != null ? (
148
+ <loaded.UndescribedTooltip
149
+ anchorRef={anchorRef}
150
+ content={cutText}
151
+ onHide={hide}
152
+ />
153
+ ) : null,
154
+ onFocus,
155
+ onBlur,
156
+ onPointerDown: hide,
157
+ };
158
+ }
@@ -5,11 +5,15 @@
5
5
  /**
6
6
  * @file textClampContext.ts
7
7
  * @input Uses createLayerScopedContext
8
- * @output TextClampContext: true inside a Text that clamps its lines
9
- * @position Internal; Text provides it and Link reads it
8
+ * @output TextClampContext: true inside a Text that clamps its lines;
9
+ * TextMeasureOnInterestContext: true where a Text measures truncation on
10
+ * its first hover, tap or focus instead of when it mounts
11
+ * @position Internal; Text provides TextClampContext and Link reads it;
12
+ * Table's default cells provide TextMeasureOnInterestContext and Text reads
13
+ * it
10
14
  *
11
- * A layer boundary resets it to false, because content in a layer is not
12
- * inside the clamped text box.
15
+ * A layer boundary resets both to false. Content in a layer is not inside
16
+ * the clamped text or the cell.
13
17
  */
14
18
 
15
19
  import {createLayerScopedContext} from '../Layer/layerScopedContext';
@@ -19,3 +23,9 @@ export const TextClampContext = createLayerScopedContext(
19
23
  1,
20
24
  false,
21
25
  );
26
+
27
+ export const TextMeasureOnInterestContext = createLayerScopedContext(
28
+ 'TextMeasureOnInterestContext',
29
+ 1,
30
+ false,
31
+ );