@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.
- package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
- package/dist/AlertDialog/AlertDialog.js +7 -0
- package/dist/AppShell/AppShell.d.ts.map +1 -1
- package/dist/AppShell/AppShell.js +5 -3
- package/dist/AppShell/observeMainOverflow.d.ts +5 -0
- package/dist/AppShell/observeMainOverflow.d.ts.map +1 -1
- package/dist/AppShell/observeMainOverflow.js +39 -9
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +8 -0
- package/dist/BottomSheet/useSheetGestures.d.ts +8 -0
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +16 -1
- package/dist/Button/Button.d.ts.map +1 -1
- package/dist/Button/Button.js +3 -16
- package/dist/Card/Card.d.ts.map +1 -1
- package/dist/Card/Card.js +5 -1
- package/dist/Citation/Citation.d.ts.map +1 -1
- package/dist/Citation/Citation.js +2 -2
- package/dist/ClickableCard/ClickableCard.d.ts.map +1 -1
- package/dist/ClickableCard/ClickableCard.js +7 -2
- package/dist/DateInput/DateInput.d.ts +0 -3
- package/dist/DateInput/DateInput.d.ts.map +1 -1
- package/dist/DateInput/DateInput.js +3 -5
- package/dist/DateInput/NativeDateField.d.ts.map +1 -1
- package/dist/DateInput/NativeDateField.js +3 -5
- package/dist/DateInput/TouchDateField.d.ts.map +1 -1
- package/dist/DateInput/TouchDateField.js +2 -4
- package/dist/DateInput/useTypedDate.d.ts.map +1 -1
- package/dist/DateInput/useTypedDate.js +9 -6
- package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
- package/dist/DateRangeInput/DateRangeInput.js +13 -9
- package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
- package/dist/DateTimeInput/DateTimeInput.js +3 -15
- package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
- package/dist/DateTimeInput/TouchDateTimeField.js +2 -14
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +7 -1
- package/dist/Drawer/Drawer.d.ts.map +1 -1
- package/dist/Drawer/Drawer.js +7 -0
- package/dist/Field/Field.d.ts.map +1 -1
- package/dist/Field/Field.js +2 -1
- package/dist/Field/FieldLabel.d.ts.map +1 -1
- package/dist/Field/FieldLabel.js +9 -2
- package/dist/Field/InputClearButton.d.ts.map +1 -1
- package/dist/Field/InputClearButton.js +23 -0
- package/dist/Field/inputStyles.stylex.d.ts +22 -6
- package/dist/Field/inputStyles.stylex.d.ts.map +1 -1
- package/dist/Field/inputStyles.stylex.js +32 -0
- package/dist/FieldStatus/FieldStatus.d.ts.map +1 -1
- package/dist/FieldStatus/FieldStatus.js +7 -2
- package/dist/FileInput/FileInput.d.ts.map +1 -1
- package/dist/FileInput/FileInput.js +4 -4
- package/dist/InputGroup/InputGroup.d.ts.map +1 -1
- package/dist/InputGroup/InputGroup.js +6 -16
- package/dist/InputGroup/InputGroupText.d.ts.map +1 -1
- package/dist/InputGroup/InputGroupText.js +2 -8
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +8 -2
- package/dist/Kbd/Kbd.d.ts +3 -2
- package/dist/Kbd/Kbd.d.ts.map +1 -1
- package/dist/Kbd/Kbd.js +3 -2
- package/dist/Layer/gestureCounter.d.ts +5 -0
- package/dist/Layer/gestureCounter.d.ts.map +1 -1
- package/dist/Layer/gestureCounter.js +40 -4
- package/dist/Layer/inputHold.d.ts +13 -0
- package/dist/Layer/inputHold.d.ts.map +1 -1
- package/dist/Layer/inputHold.js +203 -14
- package/dist/Layer/layerHost.d.ts +3 -2
- package/dist/Layer/layerHost.d.ts.map +1 -1
- package/dist/Layer/layerHost.js +3 -2
- package/dist/Layer/outsidePanClaim.d.ts +17 -0
- package/dist/Layer/outsidePanClaim.d.ts.map +1 -1
- package/dist/Layer/outsidePanClaim.js +36 -8
- package/dist/Layer/outsidePress.d.ts +7 -1
- package/dist/Layer/outsidePress.d.ts.map +1 -1
- package/dist/Layer/outsidePress.js +9 -2
- package/dist/Layer/useLayer.d.ts +21 -5
- package/dist/Layer/useLayer.d.ts.map +1 -1
- package/dist/Layer/useLayer.js +63 -40
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +7 -0
- package/dist/MetadataList/MetadataList.d.ts +1 -1
- package/dist/MetadataList/MetadataList.d.ts.map +1 -1
- package/dist/MetadataList/MetadataList.js +8 -0
- package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
- package/dist/MultiSelector/MultiSelector.js +37 -17
- package/dist/NavIcon/NavIcon.d.ts +2 -2
- package/dist/NavIcon/NavIcon.d.ts.map +1 -1
- package/dist/NavIcon/NavIcon.js +2 -2
- package/dist/NavMenu/NavHeadingMenuItem.d.ts.map +1 -1
- package/dist/NavMenu/NavHeadingMenuItem.js +4 -3
- package/dist/NumberInput/NumberInput.d.ts +13 -5
- package/dist/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/NumberInput/NumberInput.js +6 -17
- package/dist/NumberInput/numberParser.d.ts +9 -2
- package/dist/NumberInput/numberParser.d.ts.map +1 -1
- package/dist/NumberInput/numberParser.js +15 -2
- package/dist/Overlay/OverlayScrim.d.ts.map +1 -1
- package/dist/Overlay/OverlayScrim.js +13 -4
- package/dist/Overlay/useOverlay.d.ts +1 -1
- package/dist/Pagination/Pagination.d.ts +3 -2
- package/dist/Pagination/Pagination.d.ts.map +1 -1
- package/dist/Pagination/Pagination.js +9 -2
- package/dist/Popover/usePopover.d.ts +37 -6
- package/dist/Popover/usePopover.d.ts.map +1 -1
- package/dist/Popover/usePopover.js +103 -20
- package/dist/PowerSearch/PowerSearch.d.ts +4 -1
- package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearch.js +3 -4
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +1 -2
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchBottomSheet.js +173 -185
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts +0 -12
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchValueEditor.js +1 -51
- package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
- package/dist/PowerSearch/formatFilterValue.js +6 -8
- package/dist/PowerSearch/formatTokenValue.d.ts +5 -10
- package/dist/PowerSearch/formatTokenValue.d.ts.map +1 -1
- package/dist/PowerSearch/formatTokenValue.js +21 -38
- package/dist/PowerSearch/relativeDateOptions.d.ts +30 -0
- package/dist/PowerSearch/relativeDateOptions.d.ts.map +1 -0
- package/dist/PowerSearch/relativeDateOptions.js +74 -0
- package/dist/ProgressBar/ProgressBar.d.ts +1 -1
- package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
- package/dist/ProgressBar/ProgressBar.js +20 -14
- package/dist/Resizable/createResizable.d.ts.map +1 -1
- package/dist/Resizable/createResizable.js +38 -4
- package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControlItem.js +5 -3
- package/dist/SelectableCard/SelectableCard.d.ts.map +1 -1
- package/dist/SelectableCard/SelectableCard.js +6 -2
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +2 -1
- package/dist/SideNav/SideNavItem.d.ts.map +1 -1
- package/dist/SideNav/SideNavItem.js +1 -1
- package/dist/Slider/Slider.d.ts.map +1 -1
- package/dist/Slider/Slider.js +53 -8
- package/dist/Stepper/Step.d.ts.map +1 -1
- package/dist/Stepper/Step.js +2 -2
- package/dist/TabList/Tab.d.ts.map +1 -1
- package/dist/TabList/Tab.js +2 -0
- package/dist/TabList/TabMenu.d.ts.map +1 -1
- package/dist/TabList/TabMenu.js +2 -0
- package/dist/Table/BaseTable.d.ts.map +1 -1
- package/dist/Table/BaseTable.js +30 -8
- package/dist/Table/Table.d.ts +9 -4
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +9 -4
- package/dist/Table/TableHeaderCell.d.ts.map +1 -1
- package/dist/Table/TableHeaderCell.js +3 -7
- package/dist/Table/plugins/rowIndex/useTableRowIndex.d.ts.map +1 -1
- package/dist/Table/plugins/rowIndex/useTableRowIndex.js +4 -1
- package/dist/Table/plugins/rowStatus/useTableRowStatus.d.ts.map +1 -1
- package/dist/Table/plugins/rowStatus/useTableRowStatus.js +2 -0
- package/dist/Table/plugins/sortable/useTableSortable.d.ts.map +1 -1
- package/dist/Table/plugins/sortable/useTableSortable.js +18 -1
- package/dist/Table/plugins/stickyColumns/useTableStickyColumns.d.ts.map +1 -1
- package/dist/Table/plugins/stickyColumns/useTableStickyColumns.js +34 -24
- package/dist/Table/tableColumnAdmission.d.ts +7 -0
- package/dist/Table/tableColumnAdmission.d.ts.map +1 -1
- package/dist/Table/tableColumnAdmission.js +15 -0
- package/dist/Table/types.d.ts +5 -5
- package/dist/Text/Text.d.ts.map +1 -1
- package/dist/Text/Text.js +13 -8
- package/dist/Text/TruncationTooltip.d.ts +7 -39
- package/dist/Text/TruncationTooltip.d.ts.map +1 -1
- package/dist/Text/TruncationTooltip.js +47 -128
- package/dist/Text/cutText.d.ts +22 -0
- package/dist/Text/cutText.d.ts.map +1 -0
- package/dist/Text/cutText.js +92 -0
- package/dist/Text/cutTextOnKeyboardFocus.d.ts +41 -0
- package/dist/Text/cutTextOnKeyboardFocus.d.ts.map +1 -0
- package/dist/Text/cutTextOnKeyboardFocus.js +112 -0
- package/dist/Text/textClampContext.d.ts +1 -0
- package/dist/Text/textClampContext.d.ts.map +1 -1
- package/dist/Text/textClampContext.js +10 -5
- package/dist/Text/useTruncation.d.ts +23 -1
- package/dist/Text/useTruncation.d.ts.map +1 -1
- package/dist/Text/useTruncation.js +74 -28
- package/dist/TextInput/TextInput.d.ts +6 -6
- package/dist/Thumbnail/Thumbnail.js +4 -1
- package/dist/TimeInput/TimeInput.d.ts +0 -3
- package/dist/TimeInput/TimeInput.d.ts.map +1 -1
- package/dist/TimeInput/TimeInput.js +3 -5
- package/dist/TimeInput/TouchTimeField.d.ts.map +1 -1
- package/dist/TimeInput/TouchTimeField.js +3 -5
- package/dist/Timestamp/Timestamp.d.ts.map +1 -1
- package/dist/Timestamp/Timestamp.js +22 -16
- package/dist/Timestamp/TimestampHoverCard.d.ts +6 -3
- package/dist/Timestamp/TimestampHoverCard.d.ts.map +1 -1
- package/dist/Timestamp/TimestampHoverCard.js +30 -19
- package/dist/Timestamp/formatInstant.d.ts.map +1 -1
- package/dist/Timestamp/formatInstant.js +3 -3
- package/dist/Timestamp/tooltipEntries.d.ts.map +1 -1
- package/dist/Timestamp/tooltipEntries.js +4 -2
- package/dist/Toast/Toast.d.ts.map +1 -1
- package/dist/Toast/Toast.js +62 -31
- package/dist/Toast/ToastViewport.d.ts.map +1 -1
- package/dist/Toast/ToastViewport.js +35 -13
- package/dist/Toast/useToast.d.ts.map +1 -1
- package/dist/Toast/useToast.js +35 -14
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +3 -3
- package/dist/astryx.css +38 -8
- package/dist/hooks/useAnnounceRenderedText.d.ts +10 -3
- package/dist/hooks/useAnnounceRenderedText.d.ts.map +1 -1
- package/dist/hooks/useAnnounceRenderedText.js +11 -3
- package/dist/hooks/useFocusTrap.d.ts +12 -0
- package/dist/hooks/useFocusTrap.d.ts.map +1 -1
- package/dist/hooks/useFocusTrap.js +13 -6
- package/dist/hooks/useHotkeys.d.ts +9 -1
- package/dist/hooks/useHotkeys.d.ts.map +1 -1
- package/dist/hooks/useHotkeys.js +52 -2
- package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
- package/dist/hooks/useInputStatusIcon.js +2 -1
- package/dist/hooks/useKeyboardHint.d.ts.map +1 -1
- package/dist/hooks/useKeyboardHint.js +4 -3
- package/dist/i18n/generated-english/DateRangeInput/DateRangeInput.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/DateRangeInput/DateRangeInput.generated.js +2 -0
- package/dist/i18n/generated-english/MultiSelector/MultiSelector.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/MultiSelector/MultiSelector.generated.js +1 -0
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +0 -6
- package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.d.ts +8 -0
- package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/PowerSearch/relativeDateOptions.generated.js +17 -0
- package/dist/i18n/generated-english/Slider/Slider.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/Slider/Slider.generated.js +1 -0
- package/dist/i18n/generated-english/Thumbnail/Thumbnail.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/Thumbnail/Thumbnail.generated.js +1 -0
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +5 -0
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +5 -0
- package/dist/i18n/getLocaleDirection.d.ts +0 -16
- package/dist/i18n/getLocaleDirection.d.ts.map +1 -1
- package/dist/i18n/getLocaleDirection.js +16 -6
- package/dist/i18n/listFormat.d.ts +34 -0
- package/dist/i18n/listFormat.d.ts.map +1 -0
- package/dist/i18n/listFormat.js +45 -0
- package/dist/i18n/useListFormatter.d.ts +7 -3
- package/dist/i18n/useListFormatter.d.ts.map +1 -1
- package/dist/i18n/useListFormatter.js +16 -13
- package/dist/internal/module-loader.d.ts +15 -0
- package/dist/internal/module-loader.d.ts.map +1 -0
- package/dist/internal/module-loader.js +15 -0
- package/dist/motion/animatedLayout.d.ts +6 -0
- package/dist/motion/animatedLayout.d.ts.map +1 -1
- package/dist/motion/animatedLayout.js +201 -27
- package/dist/palette/color.d.ts +16 -0
- package/dist/palette/color.d.ts.map +1 -1
- package/dist/palette/color.js +37 -1
- package/dist/palette/derive-look.d.ts +235 -0
- package/dist/palette/derive-look.d.ts.map +1 -0
- package/dist/palette/derive-look.js +879 -0
- package/dist/palette/editor-look.d.ts +41 -0
- package/dist/palette/editor-look.d.ts.map +1 -0
- package/dist/palette/editor-look.js +401 -0
- package/dist/palette/mapping.d.ts +99 -6
- package/dist/palette/mapping.d.ts.map +1 -1
- package/dist/palette/mapping.js +68 -11
- package/dist/theme/tokens.d.ts +1 -1
- package/dist/theme/tokens.d.ts.map +1 -1
- package/dist/theme/tokens.js +1 -1
- package/dist/utils/characters.d.ts.map +1 -1
- package/dist/utils/characters.js +7 -0
- package/dist/utils/devWarning.d.ts +18 -0
- package/dist/utils/devWarning.d.ts.map +1 -1
- package/dist/utils/devWarning.js +30 -0
- package/dist/utils/focusReturn.d.ts +2 -0
- package/dist/utils/focusReturn.d.ts.map +1 -1
- package/dist/utils/focusReturn.js +3 -8
- package/dist/utils/hitArea.d.ts +4 -1
- package/dist/utils/hitArea.d.ts.map +1 -1
- package/dist/utils/hitArea.js +72 -9
- package/dist/utils/mergeProps.d.ts.map +1 -1
- package/dist/utils/mergeProps.js +53 -38
- package/dist/utils/scrollView.d.ts +2 -2
- package/dist/utils/scrollView.d.ts.map +1 -1
- package/dist/utils/scrollView.js +3 -3
- package/dist/utils/textDirection.d.ts +29 -5
- package/dist/utils/textDirection.d.ts.map +1 -1
- package/dist/utils/textDirection.js +56 -4
- package/dist/utils/touchHitArea.d.ts.map +1 -1
- package/dist/utils/touchHitArea.js +4 -2
- package/dist/virtualization/useInlineListWindow.d.ts.map +1 -1
- package/dist/virtualization/useInlineListWindow.js +63 -4
- package/locales/en.json +26 -6
- package/locales/pseudo.json +15 -0
- package/package.json +10 -5
- package/src/AlertDialog/AlertDialog.tsx +15 -0
- package/src/AlertDialog/useImperativeAlertDialog.doc.mjs +7 -4
- package/src/AppShell/AppShell.tsx +6 -3
- package/src/AppShell/observeMainOverflow.ts +39 -9
- package/src/Badge/Badge.doc.mjs +3 -3
- package/src/BottomSheet/BottomSheet.tsx +15 -0
- package/src/BottomSheet/useSheetGestures.ts +26 -1
- package/src/Button/Button.tsx +3 -23
- package/src/Card/Card.doc.mjs +3 -3
- package/src/Card/Card.tsx +11 -6
- package/src/Chat/ChatSendButton.doc.mjs +6 -6
- package/src/Chat/ChatToolCalls.doc.mjs +1 -1
- package/src/CheckboxInput/CheckboxInput.doc.mjs +3 -3
- package/src/Citation/Citation.tsx +8 -2
- package/src/ClickableCard/ClickableCard.tsx +9 -2
- package/src/ComplexSelector/ComplexSelector.doc.mjs +3 -3
- package/src/ContextMenu/ContextMenuItem.doc.mjs +3 -3
- package/src/DateInput/DateInput.tsx +2 -4
- package/src/DateInput/NativeDateField.tsx +5 -4
- package/src/DateInput/TouchDateField.tsx +2 -3
- package/src/DateInput/useTypedDate.ts +13 -6
- package/src/DateRangeInput/DateRangeInput.tsx +14 -10
- package/src/DateTimeInput/DateTimeInput.tsx +2 -12
- package/src/DateTimeInput/TouchDateTimeField.tsx +2 -11
- package/src/Dialog/Dialog.tsx +15 -1
- package/src/Dialog/useImperativeDialog.doc.mjs +7 -4
- package/src/Drawer/Drawer.tsx +15 -0
- package/src/DropdownMenu/DropdownMenu.doc.mjs +1 -1
- package/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs +3 -3
- package/src/DropdownMenu/DropdownMenuItem.doc.mjs +3 -3
- package/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs +3 -3
- package/src/DropdownMenu/DropdownMenuSubMenu.doc.mjs +2 -2
- package/src/Field/Field.doc.mjs +1 -1
- package/src/Field/Field.tsx +2 -1
- package/src/Field/FieldLabel.doc.mjs +3 -3
- package/src/Field/FieldLabel.tsx +11 -3
- package/src/Field/InputClearButton.tsx +27 -0
- package/src/Field/inputStyles.stylex.ts +53 -6
- package/src/FieldStatus/FieldStatus.tsx +7 -2
- package/src/FileInput/FileInput.tsx +12 -2
- package/src/Icon/Icon.doc.mjs +17 -14
- package/src/Icon/useIcon.doc.mjs +6 -6
- package/src/IconButton/IconButton.doc.mjs +2 -2
- package/src/InfoTip/InfoTip.doc.mjs +1 -1
- package/src/InputGroup/InputGroup.tsx +5 -12
- package/src/InputGroup/InputGroupText.tsx +2 -3
- package/src/Item/Item.tsx +10 -1
- package/src/Kbd/Kbd.doc.mjs +5 -5
- package/src/Kbd/Kbd.tsx +3 -2
- package/src/Layer/gestureCounter.ts +39 -3
- package/src/Layer/inputHold.ts +241 -18
- package/src/Layer/layerHost.ts +3 -2
- package/src/Layer/outsidePanClaim.ts +50 -8
- package/src/Layer/outsidePress.ts +18 -4
- package/src/Layer/useLayer.tsx +128 -76
- package/src/Lightbox/Lightbox.tsx +15 -0
- package/src/MetadataList/MetadataList.tsx +8 -0
- package/src/MoreMenu/MoreMenu.doc.mjs +1 -1
- package/src/MultiSelector/MultiSelector.doc.mjs +2 -2
- package/src/MultiSelector/MultiSelector.tsx +45 -15
- package/src/NavIcon/NavIcon.doc.mjs +19 -10
- package/src/NavIcon/NavIcon.tsx +3 -2
- package/src/NavMenu/NavHeadingMenuItem.tsx +9 -3
- package/src/NumberInput/NumberInput.doc.mjs +12 -12
- package/src/NumberInput/NumberInput.tsx +12 -15
- package/src/NumberInput/numberParser.ts +15 -2
- package/src/Overlay/Overlay.doc.mjs +13 -1
- package/src/Overlay/OverlayScrim.tsx +45 -15
- package/src/Overlay/useOverlay.doc.mjs +7 -7
- package/src/Overlay/useOverlay.tsx +1 -1
- package/src/Pagination/Pagination.doc.mjs +9 -6
- package/src/Pagination/Pagination.tsx +15 -3
- package/src/Popover/usePopover.doc.mjs +14 -4
- package/src/Popover/usePopover.tsx +180 -23
- package/src/PowerSearch/PowerSearch.doc.mjs +165 -15
- package/src/PowerSearch/PowerSearch.tsx +6 -8
- package/src/PowerSearch/PowerSearchBottomSheet.tsx +182 -223
- package/src/PowerSearch/PowerSearchValueEditor.tsx +1 -51
- package/src/PowerSearch/formatFilterValue.ts +8 -9
- package/src/PowerSearch/formatTokenValue.ts +24 -42
- package/src/PowerSearch/relativeDateOptions.ts +84 -0
- package/src/ProgressBar/ProgressBar.doc.mjs +24 -5
- package/src/ProgressBar/ProgressBar.tsx +28 -18
- package/src/Resizable/createResizable.ts +46 -5
- package/src/SegmentedControl/SegmentedControlItem.tsx +4 -3
- package/src/SelectableCard/SelectableCard.tsx +8 -2
- package/src/Selector/Selector.doc.mjs +3 -3
- package/src/Selector/Selector.tsx +3 -1
- package/src/Selector/SelectorOption.doc.mjs +3 -3
- package/src/SideNav/SideNavItem.doc.mjs +6 -6
- package/src/SideNav/SideNavItem.tsx +3 -0
- package/src/Slider/Slider.tsx +48 -6
- package/src/Stepper/Step.tsx +7 -1
- package/src/Switch/Switch.doc.mjs +3 -3
- package/src/TabList/Tab.tsx +4 -0
- package/src/TabList/TabMenu.tsx +4 -0
- package/src/Table/BaseTable.tsx +35 -7
- package/src/Table/Table.doc.mjs +56 -6
- package/src/Table/Table.tsx +9 -4
- package/src/Table/TableHeaderCell.tsx +2 -8
- package/src/Table/plugins/rowIndex/useTableRowIndex.tsx +10 -1
- package/src/Table/plugins/rowStatus/useTableRowStatus.tsx +5 -0
- package/src/Table/plugins/sortable/useTableSortable.tsx +41 -2
- package/src/Table/plugins/stickyColumns/useTableStickyColumns.tsx +49 -20
- package/src/Table/tableColumnAdmission.ts +23 -0
- package/src/Table/types.ts +5 -5
- package/src/Table/useTableRowsVirtualization.doc.mjs +2 -2
- package/src/Text/Text.tsx +21 -7
- package/src/Text/TruncationTooltip.tsx +51 -184
- package/src/Text/cutText.tsx +126 -0
- package/src/Text/cutTextOnKeyboardFocus.tsx +158 -0
- package/src/Text/textClampContext.ts +14 -4
- package/src/Text/useTruncation.ts +85 -27
- package/src/TextArea/TextArea.doc.mjs +4 -4
- package/src/TextInput/TextInput.doc.mjs +3 -3
- package/src/Thumbnail/Thumbnail.tsx +1 -1
- package/src/TimeInput/TimeInput.tsx +3 -9
- package/src/TimeInput/TouchTimeField.tsx +6 -4
- package/src/Timestamp/Timestamp.tsx +29 -21
- package/src/Timestamp/TimestampHoverCard.tsx +44 -31
- package/src/Timestamp/formatInstant.ts +7 -3
- package/src/Timestamp/tooltipEntries.ts +4 -2
- package/src/Toast/Toast.doc.mjs +24 -37
- package/src/Toast/Toast.tsx +77 -29
- package/src/Toast/ToastViewport.tsx +33 -13
- package/src/Toast/useToast.tsx +42 -15
- package/src/Tokenizer/Tokenizer.doc.mjs +2 -2
- package/src/Tooltip/useTooltip.tsx +2 -1
- package/src/TopNav/TopNavMegaMenu.doc.mjs +13 -0
- package/src/TopNav/TopNavMenu.doc.mjs +2 -0
- package/src/Typeahead/Typeahead.doc.mjs +2 -2
- package/src/hooks/useAnnounceRenderedText.ts +15 -2
- package/src/hooks/useFocusTrap.ts +27 -4
- package/src/hooks/useHotkeys.doc.mjs +54 -11
- package/src/hooks/useHotkeys.ts +72 -3
- package/src/hooks/useInputStatusIcon.tsx +2 -1
- package/src/hooks/useKeyboardHint.tsx +3 -2
- package/src/i18n/generated-english/DateRangeInput/DateRangeInput.generated.ts +2 -0
- package/src/i18n/generated-english/MultiSelector/MultiSelector.generated.ts +1 -0
- package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +0 -6
- package/src/i18n/generated-english/PowerSearch/relativeDateOptions.generated.ts +18 -0
- package/src/i18n/generated-english/Slider/Slider.generated.ts +1 -0
- package/src/i18n/generated-english/Thumbnail/Thumbnail.generated.ts +1 -0
- package/src/i18n/generated-locales/en.generated.ts +5 -0
- package/src/i18n/generated-locales/pseudo.generated.ts +5 -0
- package/src/i18n/getLocaleDirection.ts +57 -7
- package/src/i18n/listFormat.ts +55 -0
- package/src/i18n/useListFormatter.ts +22 -13
- package/src/internal/module-loader.ts +15 -0
- package/src/motion/animatedLayout.ts +215 -28
- package/src/palette/color.ts +41 -1
- package/src/palette/derive-look.ts +1186 -0
- package/src/palette/editor-look.ts +480 -0
- package/src/palette/mapping.ts +129 -15
- package/src/theme/SyntaxTheme.doc.mjs +1 -1
- package/src/theme/tokens.ts +2 -1
- package/src/theme/useThemeName.doc.mjs +1 -1
- package/src/utils/characters.ts +11 -0
- package/src/utils/devWarning.ts +35 -0
- package/src/utils/focusReturn.ts +3 -11
- package/src/utils/hitArea.ts +87 -18
- package/src/utils/mergeProps.ts +57 -34
- package/src/utils/scrollView.ts +3 -2
- package/src/utils/textDirection.ts +65 -5
- package/src/utils/touchHitArea.ts +3 -2
- 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
|
|
10
|
-
*
|
|
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
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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 (!
|
|
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
|
-
[
|
|
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 (!
|
|
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
|
-
[
|
|
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
|
-
*
|
|
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
|
|
12
|
-
*
|
|
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
|
+
);
|