@cube-dev/ui-kit 0.141.0 → 0.142.1
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/CHANGELOG.md +103 -0
- package/dist/_internal/hooks/use-chained-callback.js +1 -1
- package/dist/_internal/hooks/use-debounced-value.js +1 -1
- package/dist/_internal/hooks/use-deprecation-warning.js +1 -1
- package/dist/_internal/hooks/use-event.js +1 -1
- package/dist/_internal/hooks/use-is-first-render.js +1 -1
- package/dist/_internal/hooks/use-sync-ref.js +1 -1
- package/dist/_internal/hooks/use-timer/timer.js +1 -1
- package/dist/_internal/hooks/use-timer/use-timer.js +1 -1
- package/dist/_internal/hooks/use-warn.js +1 -1
- package/dist/components/Block.js +1 -1
- package/dist/components/CollectionItem.js +1 -1
- package/dist/components/GlobalStyles.js +1 -1
- package/dist/components/GridProvider.js +1 -1
- package/dist/components/HiddenInput.js +1 -1
- package/dist/components/Root.js +1 -1
- package/dist/components/actions/Action/Action.js +1 -1
- package/dist/components/actions/Banner/Banner.js +1 -1
- package/dist/components/actions/Button/Button.js +17 -3
- package/dist/components/actions/Button/Button.js.map +1 -1
- package/dist/components/actions/ButtonGroup/ButtonGroup.js +1 -1
- package/dist/components/actions/ButtonSplit/ButtonSplit.js +1 -1
- package/dist/components/actions/ButtonSplit/context.js +1 -1
- package/dist/components/actions/CommandMenu/CommandMenu.js +3 -4
- package/dist/components/actions/CommandMenu/CommandMenu.js.map +1 -1
- package/dist/components/actions/CommandMenu/styled.js +1 -1
- package/dist/components/actions/ItemAction/ItemAction.js +1 -1
- package/dist/components/actions/ItemActionContext.js +1 -1
- package/dist/components/actions/ItemButton/ItemButton.js +18 -2
- package/dist/components/actions/ItemButton/ItemButton.js.map +1 -1
- package/dist/components/actions/Link/Link.js +1 -1
- package/dist/components/actions/Menu/Menu.js +3 -4
- package/dist/components/actions/Menu/Menu.js.map +1 -1
- package/dist/components/actions/Menu/MenuItem.js +1 -1
- package/dist/components/actions/Menu/MenuSection.js +1 -1
- package/dist/components/actions/Menu/MenuTrigger.js +8 -5
- package/dist/components/actions/Menu/MenuTrigger.js.map +1 -1
- package/dist/components/actions/Menu/SubMenuTrigger.js +10 -7
- package/dist/components/actions/Menu/SubMenuTrigger.js.map +1 -1
- package/dist/components/actions/Menu/SubmenuTriggerContext.js +1 -1
- package/dist/components/actions/Menu/context.js +1 -1
- package/dist/components/actions/Menu/styled.js +1 -1
- package/dist/components/actions/index.js +1 -1
- package/dist/components/actions/use-action.js +1 -1
- package/dist/components/actions/use-anchored-menu.js +4 -3
- package/dist/components/actions/use-anchored-menu.js.map +1 -1
- package/dist/components/actions/use-context-menu.js +4 -3
- package/dist/components/actions/use-context-menu.js.map +1 -1
- package/dist/components/content/ActiveZone/ActiveZone.js +1 -1
- package/dist/components/content/Alert/Alert.js +1 -1
- package/dist/components/content/Alert/use-alert.js +1 -1
- package/dist/components/content/Avatar/Avatar.js +1 -1
- package/dist/components/content/Badge/Badge.js +1 -1
- package/dist/components/content/Card/Card.js +1 -1
- package/dist/components/content/Content.js +1 -1
- package/dist/components/content/CopyPasteBlock/CopyPasteBlock.js +1 -1
- package/dist/components/content/CopySnippet/CopySnippet.js +1 -1
- package/dist/components/content/Disclosure/Disclosure.js +1 -1
- package/dist/components/content/Divider.js +1 -1
- package/dist/components/content/Footer.js +1 -1
- package/dist/components/content/Header.js +1 -1
- package/dist/components/content/HotKeys/HotKeys.js +1 -1
- package/dist/components/content/InlineInput/InlineInput.js +1 -1
- package/dist/components/content/Item/Item.js +1 -1
- package/dist/components/content/ItemBadge/ItemBadge.js +1 -1
- package/dist/components/content/ItemCard/ItemCard.js +1 -1
- package/dist/components/content/Layout/GridLayout.js +1 -1
- package/dist/components/content/Layout/Layout.js +1 -1
- package/dist/components/content/Layout/LayoutBlock.js +1 -1
- package/dist/components/content/Layout/LayoutCenter.js +1 -1
- package/dist/components/content/Layout/LayoutContainer.js +1 -1
- package/dist/components/content/Layout/LayoutContent.js +1 -1
- package/dist/components/content/Layout/LayoutContext.js +1 -1
- package/dist/components/content/Layout/LayoutFlex.js +1 -1
- package/dist/components/content/Layout/LayoutFooter.js +1 -1
- package/dist/components/content/Layout/LayoutGrid.js +1 -1
- package/dist/components/content/Layout/LayoutHeader.js +1 -1
- package/dist/components/content/Layout/LayoutPane.js +1 -1
- package/dist/components/content/Layout/LayoutPanel.js +1 -1
- package/dist/components/content/Layout/LayoutPanelHeader.js +1 -1
- package/dist/components/content/Layout/LayoutToolbar.js +1 -1
- package/dist/components/content/Layout/hooks/useTinyScrollbar.js +1 -1
- package/dist/components/content/Layout/index.js +1 -1
- package/dist/components/content/Layout/utils.js +1 -1
- package/dist/components/content/Paragraph.js +1 -1
- package/dist/components/content/Placeholder/Placeholder.js +1 -1
- package/dist/components/content/PrismCode/PrismCode.js +1 -1
- package/dist/components/content/PrismCode/prismSetup.js +1 -1
- package/dist/components/content/PrismDiffCode/PrismDiffCode.js +1 -1
- package/dist/components/content/Result/Result.js +1 -1
- package/dist/components/content/Skeleton/Skeleton.js +1 -1
- package/dist/components/content/Tag/Tag.js +1 -1
- package/dist/components/content/Text.js +1 -1
- package/dist/components/content/TextItem/TextItem.js +1 -1
- package/dist/components/content/Title.js +1 -1
- package/dist/components/content/Tree/Tree.js +1 -1
- package/dist/components/content/Tree/TreeNode.js +1 -1
- package/dist/components/content/Tree/styled.js +1 -1
- package/dist/components/content/Tree/tree-index.js +1 -1
- package/dist/components/content/Tree/use-checkbox-tree.js +1 -1
- package/dist/components/content/Tree/use-load-data.js +1 -1
- package/dist/components/content/highlightText.js +1 -1
- package/dist/components/content/use-auto-tooltip.js +1 -1
- package/dist/components/fields/Checkbox/Checkbox.js +1 -1
- package/dist/components/fields/Checkbox/CheckboxGroup.js +3 -3
- package/dist/components/fields/Checkbox/CheckboxGroup.js.map +1 -1
- package/dist/components/fields/Checkbox/context.js +1 -1
- package/dist/components/fields/ComboBox/ComboBox.js +11 -7
- package/dist/components/fields/ComboBox/ComboBox.js.map +1 -1
- package/dist/components/fields/DatePicker/DateInput.js +1 -1
- package/dist/components/fields/DatePicker/DateInputBase.js +1 -1
- package/dist/components/fields/DatePicker/DatePicker.js +1 -1
- package/dist/components/fields/DatePicker/DatePickerButton.js +1 -1
- package/dist/components/fields/DatePicker/DatePickerElement.js +1 -1
- package/dist/components/fields/DatePicker/DatePickerInput.js +1 -1
- package/dist/components/fields/DatePicker/DatePickerSegment.js +1 -1
- package/dist/components/fields/DatePicker/DateRangePicker.js +1 -1
- package/dist/components/fields/DatePicker/DateRangeSeparatedPicker.js +1 -1
- package/dist/components/fields/DatePicker/TimeInput.js +1 -1
- package/dist/components/fields/DatePicker/intl.js +1 -1
- package/dist/components/fields/DatePicker/parseDate.js +1 -1
- package/dist/components/fields/DatePicker/props.js +1 -1
- package/dist/components/fields/DatePicker/utils.js +1 -1
- package/dist/components/fields/FileInput/FileInput.js +1 -1
- package/dist/components/fields/FilterListBox/FilterListBox.js +1 -1
- package/dist/components/fields/FilterPicker/FilterPicker.js +1 -21
- package/dist/components/fields/FilterPicker/FilterPicker.js.map +1 -1
- package/dist/components/fields/Input/Input.js +1 -1
- package/dist/components/fields/ListBox/DraggableListBox.js +1 -1
- package/dist/components/fields/ListBox/ListBox.js +2 -1
- package/dist/components/fields/ListBox/ListBox.js.map +1 -1
- package/dist/components/fields/NumberInput/NumberInput.js +1 -1
- package/dist/components/fields/NumberInput/StepButton.js +1 -1
- package/dist/components/fields/PasswordInput/PasswordInput.js +1 -1
- package/dist/components/fields/Picker/Picker.js +1 -21
- package/dist/components/fields/Picker/Picker.js.map +1 -1
- package/dist/components/fields/RadioGroup/Radio.js +1 -1
- package/dist/components/fields/RadioGroup/RadioGroup.js +3 -3
- package/dist/components/fields/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/components/fields/RadioGroup/context.js +1 -1
- package/dist/components/fields/SearchInput/SearchInput.js +1 -1
- package/dist/components/fields/Select/Select.js +10 -7
- package/dist/components/fields/Select/Select.js.map +1 -1
- package/dist/components/fields/Slider/Gradation.js +1 -1
- package/dist/components/fields/Slider/HueSlider.js +1 -1
- package/dist/components/fields/Slider/RangeSlider.js +1 -1
- package/dist/components/fields/Slider/Slider.js +1 -1
- package/dist/components/fields/Slider/SliderBase.js +1 -1
- package/dist/components/fields/Slider/SliderThumb.js +1 -1
- package/dist/components/fields/Slider/SliderTrack.js +1 -1
- package/dist/components/fields/Slider/elements.js +1 -1
- package/dist/components/fields/Slider/index.js +1 -1
- package/dist/components/fields/Switch/Switch.js +1 -1
- package/dist/components/fields/TextArea/TextArea.js +1 -1
- package/dist/components/fields/TextInput/TextInput.js +1 -1
- package/dist/components/fields/TextInput/TextInputBase.js +1 -1
- package/dist/components/fields/TextInputMapper/TextInputMapper.js +1 -1
- package/dist/components/form/FieldWrapper/FieldWrapper.js +1 -1
- package/dist/components/form/FieldWrapper/extract-field-wrapper-props.js +1 -1
- package/dist/components/form/Form/Field.js +1 -1
- package/dist/components/form/Form/Form.d.ts +1 -2
- package/dist/components/form/Form/Form.js +3 -3
- package/dist/components/form/Form/Form.js.map +1 -1
- package/dist/components/form/Form/ResetButton/ResetButton.js +1 -1
- package/dist/components/form/Form/SubmitButton/SubmitButton.js +1 -1
- package/dist/components/form/Form/SubmitError.js +1 -1
- package/dist/components/form/Form/index.d.ts +1 -1
- package/dist/components/form/Form/index.js +1 -1
- package/dist/components/form/Form/use-field/use-field-props.js +1 -1
- package/dist/components/form/Form/use-field/use-field.js +1 -1
- package/dist/components/form/Form/use-form.js +1 -1
- package/dist/components/form/Form/validation.js +1 -1
- package/dist/components/form/Label.js +3 -3
- package/dist/components/form/Label.js.map +1 -1
- package/dist/components/form/wrapper.js +1 -1
- package/dist/components/helpers/DisplayTransition/DisplayTransition.js +1 -1
- package/dist/components/helpers/IconSwitch/IconSwitch.js +1 -1
- package/dist/components/layout/Flex.js +1 -1
- package/dist/components/layout/Flow.js +1 -1
- package/dist/components/layout/Grid.js +1 -1
- package/dist/components/layout/Panel.js +1 -1
- package/dist/components/layout/Prefix.js +1 -1
- package/dist/components/layout/ResizablePanel.js +1 -1
- package/dist/components/layout/Space.js +1 -1
- package/dist/components/layout/Suffix.js +1 -1
- package/dist/components/navigation/Tabs/DraggableTabList.js +1 -1
- package/dist/components/navigation/Tabs/TabButton.js +1 -1
- package/dist/components/navigation/Tabs/TabDropIndicator.js +1 -1
- package/dist/components/navigation/Tabs/TabPanel.js +1 -1
- package/dist/components/navigation/Tabs/TabPicker.js +1 -1
- package/dist/components/navigation/Tabs/Tabs.js +1 -1
- package/dist/components/navigation/Tabs/TabsAction.js +1 -1
- package/dist/components/navigation/Tabs/TabsContext.js +1 -1
- package/dist/components/navigation/Tabs/popover-placement.js +1 -1
- package/dist/components/navigation/Tabs/styled.js +1 -1
- package/dist/components/navigation/Tabs/types.js +1 -1
- package/dist/components/navigation/Tabs/use-tab-editing.js +1 -1
- package/dist/components/navigation/Tabs/use-tab-indicator.js +1 -1
- package/dist/components/organisms/FileTabs/FileTabs.js +1 -1
- package/dist/components/organisms/StatsCard/StatsCard.js +1 -1
- package/dist/components/other/Calendar/Calendar.js +1 -1
- package/dist/components/other/Calendar/CalendarCell.js +1 -1
- package/dist/components/other/Calendar/CalendarGrid.js +1 -1
- package/dist/components/other/Calendar/RangeCalendar.js +1 -1
- package/dist/components/other/CloudLogo/CloudLogo.js +1 -1
- package/dist/components/overlays/AlertDialog/AlertDialog.js +1 -1
- package/dist/components/overlays/AlertDialog/AlertDialogApiProvider.js +1 -1
- package/dist/components/overlays/AlertDialog/AlertDialogZone.js +1 -1
- package/dist/components/overlays/Dialog/Dialog.d.ts +1 -2
- package/dist/components/overlays/Dialog/Dialog.js +3 -3
- package/dist/components/overlays/Dialog/Dialog.js.map +1 -1
- package/dist/components/overlays/Dialog/DialogContainer.js +1 -1
- package/dist/components/overlays/Dialog/DialogForm.js +1 -1
- package/dist/components/overlays/Dialog/DialogTrigger.js +54 -8
- package/dist/components/overlays/Dialog/DialogTrigger.js.map +1 -1
- package/dist/components/overlays/Dialog/context.js +1 -1
- package/dist/components/overlays/Dialog/use-dialog-container.js +1 -1
- package/dist/components/overlays/Modal/Modal.js +3 -3
- package/dist/components/overlays/Modal/Modal.js.map +1 -1
- package/dist/components/overlays/Modal/OpenTransitionContext.js +1 -1
- package/dist/components/overlays/Modal/Overlay.js +1 -1
- package/dist/components/overlays/Modal/Popover.js +1 -1
- package/dist/components/overlays/Modal/Tray.js +3 -3
- package/dist/components/overlays/Modal/Tray.js.map +1 -1
- package/dist/components/overlays/Modal/Underlay.js +1 -1
- package/dist/components/overlays/Notifications/Notification.js +1 -1
- package/dist/components/overlays/Notifications/NotificationAction.js +1 -1
- package/dist/components/overlays/Notifications/NotificationCard.js +1 -1
- package/dist/components/overlays/Notifications/NotificationContext.js +1 -1
- package/dist/components/overlays/Notifications/NotificationItem.js +1 -1
- package/dist/components/overlays/Notifications/OverlayContainer.js +1 -1
- package/dist/components/overlays/Notifications/OverlayProvider.js +1 -1
- package/dist/components/overlays/Notifications/PersistentNotificationsList.js +1 -1
- package/dist/components/overlays/Notifications/dismissed-storage.js +1 -1
- package/dist/components/overlays/Notifications/format-relative-time.js +1 -1
- package/dist/components/overlays/Notifications/index.js +1 -1
- package/dist/components/overlays/Notifications/use-notification-state.js +1 -1
- package/dist/components/overlays/Notifications/use-notifications.js +1 -1
- package/dist/components/overlays/Notifications/use-overlay-timers.js +1 -1
- package/dist/components/overlays/Notifications/use-persistent-notifications.js +1 -1
- package/dist/components/overlays/Notifications/use-persistent-state.js +1 -1
- package/dist/components/overlays/Notifications/use-toast-state.js +1 -1
- package/dist/components/overlays/Toast/ToastItem.js +1 -1
- package/dist/components/overlays/Toast/index.js +1 -1
- package/dist/components/overlays/Toast/useProgressToast.js +1 -1
- package/dist/components/overlays/Toast/useToast.js +1 -1
- package/dist/components/overlays/Tooltip/Tooltip.js +1 -1
- package/dist/components/overlays/Tooltip/TooltipProvider.js +1 -1
- package/dist/components/overlays/Tooltip/TooltipTrigger.js +1 -1
- package/dist/components/overlays/Tooltip/context.js +1 -1
- package/dist/components/portal/Portal.js +1 -1
- package/dist/components/portal/PortalProvider.js +1 -1
- package/dist/components/portal/usePortal.js +1 -1
- package/dist/components/shared/DraggableCollection.js +1 -1
- package/dist/components/shared/InvalidIcon.js +1 -1
- package/dist/components/shared/ValidIcon.js +1 -1
- package/dist/components/status/LoadingAnimation/LoadingAnimation.js +1 -1
- package/dist/components/status/Spin/Cube.js +1 -1
- package/dist/components/status/Spin/InternalSpinner.js +1 -1
- package/dist/components/status/Spin/Spin.js +1 -1
- package/dist/components/status/Spin/SpinsContainer.js +1 -1
- package/dist/data/item-themes.js +1 -1
- package/dist/data/themes.js +1 -1
- package/dist/icons/AdjustmentsHorizontalIcon.js +1 -1
- package/dist/icons/AdjustmentsIcon.js +1 -1
- package/dist/icons/AiIcon.js +1 -1
- package/dist/icons/AreaChartIcon.js +1 -1
- package/dist/icons/BackwardIcon.js +1 -1
- package/dist/icons/BarChartIcon.js +1 -1
- package/dist/icons/BellFilledIcon.js +1 -1
- package/dist/icons/BellIcon.js +1 -1
- package/dist/icons/BooleanIcon.js +1 -1
- package/dist/icons/CalendarEditIcon.js +1 -1
- package/dist/icons/CalendarIcon.js +1 -1
- package/dist/icons/CaretDownIcon.js +1 -1
- package/dist/icons/CaretUpIcon.js +1 -1
- package/dist/icons/ChartAreaStackedIcon.js +1 -1
- package/dist/icons/ChartAreaStackedPercentageIcon.js +1 -1
- package/dist/icons/ChartBarGroupedHorizontalIcon.js +1 -1
- package/dist/icons/ChartBarGroupedIcon.js +1 -1
- package/dist/icons/ChartBarHorizontalIcon.js +1 -1
- package/dist/icons/ChartBarLineIcon.js +1 -1
- package/dist/icons/ChartBarStackedHorizontalIcon.js +1 -1
- package/dist/icons/ChartBarStackedIcon.js +1 -1
- package/dist/icons/ChartBarStackedPercentageHorizontalIcon.js +1 -1
- package/dist/icons/ChartBarStackedPercentageIcon.js +1 -1
- package/dist/icons/ChartBoxPlot2Icon.js +1 -1
- package/dist/icons/ChartBoxPlotIcon.js +1 -1
- package/dist/icons/ChartBubbleIcon.js +1 -1
- package/dist/icons/ChartDonut2Icon.js +1 -1
- package/dist/icons/ChartFunnelIcon.js +1 -1
- package/dist/icons/ChartHeatmapIcon.js +1 -1
- package/dist/icons/ChartKPIIcon.js +1 -1
- package/dist/icons/ChartPie2Icon.js +1 -1
- package/dist/icons/ChartScatterIcon.js +1 -1
- package/dist/icons/CheckCircleFilledIcon.js +1 -1
- package/dist/icons/CheckCircleIcon.js +1 -1
- package/dist/icons/CheckIcon.js +1 -1
- package/dist/icons/CircleFilledIcon.js +1 -1
- package/dist/icons/ClearIcon.js +1 -1
- package/dist/icons/CloseCircleFilledIcon.js +1 -1
- package/dist/icons/CloseCircleIcon.js +1 -1
- package/dist/icons/CloseIcon.js +1 -1
- package/dist/icons/CodeIcon.js +1 -1
- package/dist/icons/ColumnTotalIcon.js +1 -1
- package/dist/icons/CopyIcon.js +1 -1
- package/dist/icons/CountIcon.js +1 -1
- package/dist/icons/CubeIcon.js +1 -1
- package/dist/icons/CubePauseIcon.js +1 -1
- package/dist/icons/CubePlayIcon.js +1 -1
- package/dist/icons/CurrencyDollarIcon.js +1 -1
- package/dist/icons/DangerIcon.js +1 -1
- package/dist/icons/DashboardIcon.js +1 -1
- package/dist/icons/DatabaseIcon.js +1 -1
- package/dist/icons/DecimalDecreaseIcon.js +1 -1
- package/dist/icons/DecimalIncreaseIcon.js +1 -1
- package/dist/icons/DirectionIcon.js +1 -1
- package/dist/icons/DonutIcon.js +1 -1
- package/dist/icons/DownIcon.js +1 -1
- package/dist/icons/EditIcon.js +1 -1
- package/dist/icons/ExclamationCircleFilledIcon.js +1 -1
- package/dist/icons/ExclamationCircleIcon.js +1 -1
- package/dist/icons/ExclamationIcon.js +1 -1
- package/dist/icons/EyeIcon.js +1 -1
- package/dist/icons/EyeInvisibleIcon.js +1 -1
- package/dist/icons/FilterIcon.js +1 -1
- package/dist/icons/FolderFilledIcon.js +1 -1
- package/dist/icons/FolderIcon.js +1 -1
- package/dist/icons/FolderOpenFilledIcon.js +1 -1
- package/dist/icons/FolderOpenIcon.js +1 -1
- package/dist/icons/ForwardIcon.js +1 -1
- package/dist/icons/GripVerticalIcon.js +1 -1
- package/dist/icons/HierarchyIcon.js +1 -1
- package/dist/icons/HierarchyOpenIcon.js +1 -1
- package/dist/icons/Icon.js +1 -1
- package/dist/icons/InfoCircleIcon.js +1 -1
- package/dist/icons/InfoIcon.js +1 -1
- package/dist/icons/KeyIcon.js +1 -1
- package/dist/icons/LeftIcon.js +1 -1
- package/dist/icons/LineChartIcon.js +1 -1
- package/dist/icons/LoadingIcon.js +1 -1
- package/dist/icons/LockFilledIcon.js +1 -1
- package/dist/icons/LockIcon.js +1 -1
- package/dist/icons/MoreIcon.js +1 -1
- package/dist/icons/NotAllowedIcon.js +1 -1
- package/dist/icons/Number123Icon.js +1 -1
- package/dist/icons/NumberIcon.js +1 -1
- package/dist/icons/PauseCircleFilledIcon.js +1 -1
- package/dist/icons/PauseCircleIcon.js +1 -1
- package/dist/icons/PauseIcon.js +1 -1
- package/dist/icons/PercentageIcon.js +1 -1
- package/dist/icons/PieChartIcon.js +1 -1
- package/dist/icons/PlayCircleIcon.js +1 -1
- package/dist/icons/PlayIcon.js +1 -1
- package/dist/icons/PlusIcon.js +1 -1
- package/dist/icons/ProgressBarIcon.js +1 -1
- package/dist/icons/ReloadIcon.js +1 -1
- package/dist/icons/ReportIcon.js +1 -1
- package/dist/icons/ReturnIcon.js +1 -1
- package/dist/icons/RightIcon.js +1 -1
- package/dist/icons/RowTotalsIcon.js +1 -1
- package/dist/icons/SchemeIcon.js +1 -1
- package/dist/icons/SearchIcon.js +1 -1
- package/dist/icons/SemanticQueryIcon.js +1 -1
- package/dist/icons/SettingsIcon.js +1 -1
- package/dist/icons/ShieldFilledIcon.js +1 -1
- package/dist/icons/ShieldIcon.js +1 -1
- package/dist/icons/SlashIcon.js +1 -1
- package/dist/icons/SparklesIcon.js +1 -1
- package/dist/icons/SqlIcon.js +1 -1
- package/dist/icons/StatsIcon.js +1 -1
- package/dist/icons/StopIcon.js +1 -1
- package/dist/icons/StringIcon.js +1 -1
- package/dist/icons/SubtotalsIcon.js +1 -1
- package/dist/icons/SwitchIcon.js +1 -1
- package/dist/icons/TableIcon.js +1 -1
- package/dist/icons/ThumbsDownIcon.js +1 -1
- package/dist/icons/ThumbsUpIcon.js +1 -1
- package/dist/icons/ThunderboltCrossedIcon.js +1 -1
- package/dist/icons/ThunderboltFilledIcon.js +1 -1
- package/dist/icons/ThunderboltIcon.js +1 -1
- package/dist/icons/TimeIcon.js +1 -1
- package/dist/icons/TrashIcon.js +1 -1
- package/dist/icons/UnlockIcon.js +1 -1
- package/dist/icons/UpIcon.js +1 -1
- package/dist/icons/UserGroupIcon.js +1 -1
- package/dist/icons/UserIcon.js +1 -1
- package/dist/icons/UserLockIcon.js +1 -1
- package/dist/icons/ViewIcon.js +1 -1
- package/dist/icons/WarningFilledIcon.js +1 -1
- package/dist/icons/WarningIcon.js +1 -1
- package/dist/icons/wrap-icon.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/provider.js +1 -1
- package/dist/providers/TrackingProvider.js +1 -1
- package/dist/providers/navigationAdapter.default.js +1 -1
- package/dist/tokens/base.js +1 -1
- package/dist/tokens/colors.js +1 -1
- package/dist/tokens/index.js +1 -1
- package/dist/tokens/layout.js +1 -1
- package/dist/tokens/palette.js +1 -1
- package/dist/tokens/shadows.js +1 -1
- package/dist/tokens/sizes.js +1 -1
- package/dist/tokens/spacing.js +1 -1
- package/dist/tokens/typography.js +1 -1
- package/dist/utils/ResizeSensor.js +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/modules.js +1 -1
- package/dist/utils/promise.js +1 -1
- package/dist/utils/raf.js +1 -1
- package/dist/utils/random.js +1 -1
- package/dist/utils/range.js +1 -1
- package/dist/utils/react/RenderCache.js +1 -1
- package/dist/utils/react/Slots.js +1 -1
- package/dist/utils/react/chain.js +1 -1
- package/dist/utils/react/forwardRefWithGenerics.js +1 -1
- package/dist/utils/react/index.d.ts +1 -0
- package/dist/utils/react/index.js +2 -1
- package/dist/utils/react/interactions.js +1 -1
- package/dist/utils/react/isTextOnly.js +1 -1
- package/dist/utils/react/mapProps.js +1 -1
- package/dist/utils/react/mergeProps.js +1 -1
- package/dist/utils/react/nullableValue.js +1 -1
- package/dist/utils/react/resolveIcon.js +1 -1
- package/dist/utils/react/sharedStore.js +1 -1
- package/dist/utils/react/useCombinedRefs.js +1 -1
- package/dist/utils/react/useControlledFocusVisible.js +1 -1
- package/dist/utils/react/useEventBus.js +26 -17
- package/dist/utils/react/useEventBus.js.map +1 -1
- package/dist/utils/react/useId.js +1 -1
- package/dist/utils/react/useIsDarwin.js +1 -1
- package/dist/utils/react/useKeySymbols.js +1 -1
- package/dist/utils/react/useLayoutEffect.js +1 -1
- package/dist/utils/react/useLocalStorage.js +1 -1
- package/dist/utils/react/useMergeStyles.js +1 -1
- package/dist/utils/react/usePopoverSync.d.ts +116 -0
- package/dist/utils/react/usePopoverSync.js +131 -11
- package/dist/utils/react/usePopoverSync.js.map +1 -1
- package/dist/utils/react/useQaProps.js +1 -1
- package/dist/utils/react/useViewportSize.js +1 -1
- package/dist/utils/react/wrapNodeIfPlain.js +1 -1
- package/dist/utils/selection.js +1 -1
- package/dist/utils/styles.js +1 -1
- package/dist/utils/tree.js +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/version.js +2 -2
- package/docs/components/actions/Button.md +102 -24
- package/docs/components/actions/ItemButton.md +71 -34
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandMenu.js","names":["mergeProps","MenuTrigger"],"sources":["../../../../src/components/actions/CommandMenu/CommandMenu.tsx"],"sourcesContent":["import { useSyncRef } from '@react-aria/utils';\nimport { useDOMRef } from '@react-spectrum/utils';\nimport { DOMRef, FocusStrategy } from '@react-types/shared';\nimport {\n BaseProps,\n CONTAINER_STYLES,\n ContainerStyleProps,\n filterBaseProps,\n Styles,\n} from '@tenphi/tasty';\nimport React, {\n Key,\n ReactElement,\n ReactNode,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useFilter, useMenu } from 'react-aria';\n// Import Item and Section from Menu for CommandMenu compound component\nimport { Item, Section, useTreeState } from 'react-stately';\n\nimport { LoadingIcon } from '../../../icons';\nimport { mergeProps } from '../../../utils/react';\nimport { extractStyles } from '../../../utils/styles';\nimport { TooltipProvider } from '../../overlays/Tooltip/TooltipProvider';\nimport { useMenuContext } from '../Menu';\nimport { CubeMenuProps } from '../Menu/Menu';\nimport { MenuItem } from '../Menu/MenuItem';\nimport { MenuSection } from '../Menu/MenuSection';\nimport { MenuTrigger } from '../Menu/MenuTrigger';\nimport {\n StyledDivider,\n StyledFooter,\n StyledHeader,\n StyledMenu,\n} from '../Menu/styled';\n\nimport {\n StyledCommandMenu,\n StyledEmptyState,\n StyledLoadingWrapper,\n StyledSearchInput,\n} from './styled';\n\nexport interface CommandMenuItem {\n // Standard item props\n id: string;\n textValue: string;\n\n // Enhanced search features\n keywords?: string[];\n forceMount?: boolean;\n\n // Standard Menu item props inherited\n [key: string]: any;\n}\n\nexport interface CubeCommandMenuProps<T>\n extends BaseProps,\n ContainerStyleProps,\n Omit<\n CubeMenuProps<T>,\n 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange'\n > {\n // Search-specific props\n searchPlaceholder?: string;\n searchValue?: string;\n onSearchChange?: (value: string) => void;\n filter?: (textValue: string, inputValue: string) => boolean;\n emptyLabel?: ReactNode;\n searchInputStyles?: Styles;\n headerStyles?: Styles;\n footerStyles?: Styles;\n\n // Advanced search features\n isLoading?: boolean;\n shouldFilter?: boolean;\n\n // Focus management - override the autoFocus from CubeMenuProps to allow boolean | FocusStrategy\n autoFocus?: boolean | FocusStrategy;\n\n // Size prop\n size?: 'medium' | 'large' | (string & {});\n\n /** Currently selected keys (controlled) */\n selectedKeys?: string[];\n /** Initially selected keys (uncontrolled) */\n defaultSelectedKeys?: string[];\n /** Handler for selection changes */\n onSelectionChange?: (keys: string[]) => void;\n}\n\nfunction CommandMenu<T extends object>(\n props: CubeCommandMenuProps<T>,\n ref: DOMRef<HTMLDivElement>,\n) {\n const {\n searchPlaceholder = 'Search commands...',\n searchValue: controlledSearchValue,\n onSearchChange,\n filter: customFilter,\n emptyLabel = 'No commands found',\n searchInputStyles,\n headerStyles,\n footerStyles,\n isLoading = false,\n shouldFilter = true,\n autoFocus = true,\n size = 'medium',\n qa,\n styles,\n selectedKeys,\n defaultSelectedKeys,\n onSelectionChange,\n header,\n footer,\n ...restMenuProps\n } = props;\n\n const domRef = useDOMRef(ref);\n const searchInputRef = useRef<HTMLInputElement>(null);\n const contextProps = useMenuContext();\n\n // Convert string[] to Set<Key> for React Aria compatibility\n const ariaSelectedKeys = selectedKeys ? new Set(selectedKeys) : undefined;\n const ariaDefaultSelectedKeys = defaultSelectedKeys\n ? new Set(defaultSelectedKeys)\n : undefined;\n\n const handleSelectionChange = onSelectionChange\n ? (keys: 'all' | Set<Key>) => {\n if (keys === 'all') {\n // Handle 'all' selection case - collect all available keys\n const allKeys = Array.from(treeState.collection.getKeys()).map(\n (key: any) => String(key),\n );\n onSelectionChange(allKeys);\n } else if (keys instanceof Set) {\n onSelectionChange(Array.from(keys).map((key) => String(key)));\n } else {\n onSelectionChange([]);\n }\n }\n : undefined;\n\n const completeProps = mergeProps(contextProps, restMenuProps, {\n selectedKeys: ariaSelectedKeys,\n defaultSelectedKeys: ariaDefaultSelectedKeys,\n onSelectionChange: handleSelectionChange,\n });\n\n // Search state management\n const [internalSearchValue, setInternalSearchValue] = useState('');\n const searchValue = controlledSearchValue ?? internalSearchValue;\n\n const handleSearchChange = useCallback(\n (value: string) => {\n if (controlledSearchValue === undefined) {\n setInternalSearchValue(value);\n }\n onSearchChange?.(value);\n },\n [controlledSearchValue, onSearchChange],\n );\n\n // Filter setup\n const { contains } = useFilter({ sensitivity: 'base' });\n const textFilterFn = useMemo(\n () => customFilter || contains,\n [customFilter, contains],\n );\n\n // Enhanced filter function that supports keywords and forceMount\n const enhancedFilter = useCallback(\n (textValue: string, inputValue: string, item?: any) => {\n // Always show force-mounted items\n if (item?.forceMount) {\n return true;\n }\n\n // If shouldFilter is false, show all items\n if (!shouldFilter) {\n return true;\n }\n\n // Split input value into individual words and filter out empty strings\n const searchWords = inputValue\n .trim()\n .toLowerCase()\n .split(/\\s+/)\n .filter((word) => word.length > 0);\n\n // If no search words, show all items\n if (searchWords.length === 0) {\n return true;\n }\n\n // Collect all searchable text for this item\n const searchableTexts: string[] = [];\n\n // Add main text value\n searchableTexts.push(textValue.toLowerCase());\n\n // Add keywords if available\n if (item?.keywords && Array.isArray(item.keywords)) {\n searchableTexts.push(\n ...item.keywords.map((keyword: string) => keyword.toLowerCase()),\n );\n }\n\n // Check if ALL search words match at least one of the searchable texts\n return searchWords.every((searchWord) =>\n searchableTexts.some((text) => text.includes(searchWord)),\n );\n },\n [shouldFilter],\n );\n\n // Collection filter for React Stately\n const collectionFilter = useCallback(\n (nodes: Iterable<any>): Iterable<any> => {\n const term = searchValue.trim();\n\n // If no search term, return all nodes\n if (!term) {\n return nodes;\n }\n\n // Split search term into words for multi-word filtering\n const searchWords = term\n .toLowerCase()\n .split(/\\s+/)\n .filter((word) => word.length > 0);\n\n // If no valid search words, return all nodes\n if (searchWords.length === 0) {\n return nodes;\n }\n\n // Recursive helper to filter sections and items\n const filterNodes = (iter: Iterable<any>): any[] => {\n const result: any[] = [];\n\n for (const node of iter) {\n if (node.type === 'section') {\n const filteredChildren = filterNodes(node.childNodes);\n\n if (filteredChildren.length) {\n result.push({\n ...node,\n childNodes: filteredChildren,\n });\n }\n } else {\n const text = node.textValue ?? String(node.rendered ?? '');\n\n if (enhancedFilter(text, term, node.props)) {\n result.push(node);\n }\n }\n }\n\n return result;\n };\n\n return filterNodes(nodes);\n },\n [searchValue, enhancedFilter],\n );\n\n // Create tree state with filter for both keyboard navigation and rendering\n const treeStateProps = {\n ...completeProps,\n filter: collectionFilter,\n shouldUseVirtualFocus: true, // Always use virtual focus for CommandMenu\n };\n\n const treeState = useTreeState(treeStateProps);\n\n const collectionItems = [...treeState.collection];\n const hasSections = collectionItems.some((item) => item.type === 'section');\n\n // Track focused key for aria-activedescendant\n const [focusedKey, setFocusedKey] = React.useState<React.Key | null>(null);\n const focusedKeyRef = useRef<React.Key | null>(null);\n\n // Apply filtering to collection items for rendering and empty state checks\n const filteredCollectionItems = useMemo(() => {\n const term = searchValue.trim();\n if (!term) {\n return collectionItems;\n }\n\n // Split search term into words for multi-word filtering\n const searchWords = term\n .toLowerCase()\n .split(/\\s+/)\n .filter((word) => word.length > 0);\n\n // If no valid search words, return all items\n if (searchWords.length === 0) {\n return collectionItems;\n }\n\n const filterNodes = (items: any[]): any[] => {\n const result: any[] = [];\n\n [...items].forEach((item) => {\n if (item.type === 'section') {\n const filteredChildren = filterNodes(item.childNodes);\n if (filteredChildren.length) {\n result.push({\n ...item,\n childNodes: filteredChildren,\n });\n }\n } else {\n const text = item.textValue ?? String(item.rendered ?? '');\n if (enhancedFilter(text, term, item.props)) {\n result.push(item);\n }\n }\n });\n\n return result;\n };\n\n return filterNodes(collectionItems);\n }, [collectionItems, searchValue, enhancedFilter]);\n\n const hasFilteredItems = filteredCollectionItems.length > 0;\n const viewHasSections = filteredCollectionItems.some(\n (item) => item.type === 'section',\n );\n\n // Helper function to find the first selectable item from filtered results\n const findFirstSelectableItem = useCallback(() => {\n const { selectionManager } = treeState;\n\n const visit = (items: any[]): Key | null => {\n for (const node of items) {\n if (node?.type === 'section') {\n const childResult = visit(Array.from(node.childNodes ?? []));\n if (childResult != null) return childResult;\n } else if (\n node?.type === 'item' &&\n !selectionManager.isDisabled(node.key)\n ) {\n return node.key;\n }\n }\n return null;\n };\n\n return visit(filteredCollectionItems);\n }, [filteredCollectionItems, treeState.selectionManager]);\n\n // Create a ref for the menu container\n const menuRef = useRef<HTMLUListElement>(null);\n\n // Use menu hook for accessibility\n const { menuProps } = useMenu(\n {\n ...completeProps,\n 'aria-label': 'Command palette menu',\n filter: collectionFilter,\n shouldUseVirtualFocus: true,\n },\n treeState,\n menuRef,\n );\n\n // Manual rendering of menu items (similar to Menu component)\n const renderedItems = useMemo(() => {\n const items: React.ReactNode[] = [];\n let isFirstSection = true;\n\n filteredCollectionItems.forEach((item) => {\n if (item.type === 'section') {\n if (!isFirstSection) {\n items.push(\n <StyledDivider\n key={`divider-${String(item.key)}`}\n role=\"separator\"\n aria-orientation=\"horizontal\"\n />,\n );\n }\n\n items.push(\n <MenuSection\n key={item.key}\n item={item}\n state={treeState}\n styles={completeProps.sectionStyles}\n itemStyles={completeProps.itemStyles}\n headingStyles={completeProps.sectionHeadingStyles}\n size={size}\n />,\n );\n\n isFirstSection = false;\n return;\n }\n\n let menuItem = (\n <MenuItem\n key={item.key}\n item={item}\n state={treeState}\n styles={completeProps.itemStyles}\n size={size}\n onAction={item.onAction}\n />\n );\n\n // Apply tooltip wrapper if tooltip property is provided\n if (item.props.tooltip) {\n const tooltipProps =\n typeof item.props.tooltip === 'string'\n ? { title: item.props.tooltip }\n : item.props.tooltip;\n\n menuItem = (\n <TooltipProvider\n key={item.key}\n activeWrap\n placement=\"right\"\n {...tooltipProps}\n >\n {menuItem}\n </TooltipProvider>\n );\n }\n\n // Apply custom wrapper if provided\n if (item.props.wrapper) {\n menuItem = item.props.wrapper(menuItem);\n }\n\n // Ensure every child has a stable key, even if the wrapper component didn't set one.\n items.push(React.cloneElement(menuItem, { key: item.key }));\n });\n\n return items;\n }, [\n filteredCollectionItems,\n treeState,\n completeProps.sectionStyles,\n completeProps.itemStyles,\n\n completeProps.sectionHeadingStyles,\n ]);\n\n // Auto-focus search input\n React.useEffect(() => {\n if (autoFocus && searchInputRef.current) {\n // Use a small timeout to ensure the element is visible and focusable\n // This is especially important when the CommandMenu is opened in a popover\n const timeoutId = setTimeout(() => {\n if (searchInputRef.current) {\n searchInputRef.current.focus();\n }\n }, 0);\n\n return () => clearTimeout(timeoutId);\n }\n }, [autoFocus]);\n\n // Also focus when the component becomes visible (for trigger/popover usage)\n React.useEffect(() => {\n // Check if autoFocus is enabled and we're in a trigger context\n if (autoFocus && contextProps.autoFocus && searchInputRef.current) {\n // Use a small timeout to ensure the popover is fully rendered\n const timeoutId = setTimeout(() => {\n if (searchInputRef.current) {\n searchInputRef.current.focus();\n }\n }, 50); // Slightly longer timeout for popover context\n\n return () => clearTimeout(timeoutId);\n }\n }, [autoFocus, contextProps.autoFocus]);\n\n // Track the previous search value to only run auto-focus when search actually changes\n const prevSearchValueRef = useRef<string>('');\n\n // Auto-focus first item when search value changes (but not on initial render)\n React.useEffect(() => {\n const currentSearchValue = searchValue.trim();\n const prevSearchValue = prevSearchValueRef.current;\n\n // Only auto-focus when search value actually changes\n if (currentSearchValue !== prevSearchValue && currentSearchValue !== '') {\n const firstSelectableKey = findFirstSelectableItem();\n\n if (firstSelectableKey && hasFilteredItems) {\n // Focus the first item in the selection manager\n treeState.selectionManager.setFocusedKey(firstSelectableKey);\n setFocusedKey(firstSelectableKey);\n focusedKeyRef.current = firstSelectableKey;\n } else {\n // Clear focus if no items are available\n treeState.selectionManager.setFocusedKey(null);\n setFocusedKey(null);\n focusedKeyRef.current = null;\n }\n }\n\n // Update the previous search value\n prevSearchValueRef.current = currentSearchValue;\n }, [searchValue, findFirstSelectableItem, hasFilteredItems]);\n\n // Extract styles\n const extractedStyles = useMemo(\n () => extractStyles(props, CONTAINER_STYLES),\n [props],\n );\n\n // Determine if we should show empty state based on actual filtered collection\n const hasSearchTerm = searchValue.trim().length > 0;\n const showEmptyState = hasSearchTerm && !hasFilteredItems && !isLoading;\n\n // Sync refs\n useSyncRef(contextProps, menuRef);\n\n const mods = useMemo(() => {\n // Determine mods based on menu context\n let popoverMod = completeProps.mods?.popover;\n let trayMod = completeProps.mods?.tray;\n\n return {\n sections: viewHasSections,\n footer: !!footer,\n header: !!header,\n popover: popoverMod,\n tray: trayMod,\n };\n }, [viewHasSections, footer, header, completeProps.mods]);\n\n return (\n <StyledCommandMenu\n {...(filterBaseProps(props) as Record<string, unknown>)}\n ref={domRef}\n qa={qa || 'CommandMenu'}\n data-size={size}\n mods={mods}\n styles={mergeProps(extractedStyles, styles)}\n >\n {/* Header */}\n {header && (\n <StyledHeader\n role=\"presentation\"\n data-size={size}\n styles={{ border: 'none', ...headerStyles }}\n >\n {header}\n </StyledHeader>\n )}\n\n {/* Search Input */}\n <StyledSearchInput\n ref={searchInputRef}\n type=\"search\"\n placeholder={searchPlaceholder}\n value={searchValue}\n styles={searchInputStyles}\n data-size={size}\n aria-controls={`${qa || 'CommandMenu'}-menu`}\n role=\"combobox\"\n aria-expanded=\"true\"\n aria-haspopup=\"listbox\"\n aria-activedescendant={\n focusedKey != null\n ? `${qa || 'CommandMenu'}-menu-option-${focusedKey}`\n : undefined\n }\n onChange={(e) => handleSearchChange(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n e.preventDefault();\n\n const isArrowDown = e.key === 'ArrowDown';\n const { selectionManager } = treeState;\n // Use the ref to get the current focused key synchronously\n const currentKey =\n focusedKeyRef.current || selectionManager.focusedKey;\n\n // Helper function to get all visible item keys accounting for sections\n const getVisibleItemKeys = (): Key[] => {\n const keys: Key[] = [];\n\n const visit = (items: any[]) => {\n for (const node of items) {\n if (node?.type === 'section') {\n visit(Array.from(node.childNodes ?? []));\n } else if (node?.type === 'item') {\n keys.push(node.key);\n }\n }\n };\n\n visit(filteredCollectionItems);\n return keys;\n };\n\n // Helper function to find next selectable key in a direction\n const findNextSelectableKey = (\n currentIndex: number,\n direction: 'forward' | 'backward',\n visibleKeys: Key[],\n ) => {\n const increment = direction === 'forward' ? 1 : -1;\n\n for (\n let i = currentIndex + increment;\n i >= 0 && i < visibleKeys.length;\n i += increment\n ) {\n const key = visibleKeys[i];\n if (!selectionManager.isDisabled(key)) {\n return key;\n }\n }\n\n return null;\n };\n\n // Helper function to find first or last selectable key\n const findFirstLastSelectableKey = (\n direction: 'forward' | 'backward',\n visibleKeys: Key[],\n ) => {\n const keysToCheck =\n direction === 'forward'\n ? visibleKeys\n : [...visibleKeys].reverse();\n\n for (const key of keysToCheck) {\n if (!selectionManager.isDisabled(key)) {\n return key;\n }\n }\n\n return null;\n };\n\n const visibleKeys = getVisibleItemKeys();\n\n if (visibleKeys.length === 0) {\n return; // No visible items to navigate\n }\n\n let nextKey;\n const direction = isArrowDown ? 'forward' : 'backward';\n\n if (currentKey == null) {\n // No current focus, start from the first/last item\n nextKey = findFirstLastSelectableKey(direction, visibleKeys);\n } else {\n // Find current position in visible keys\n const currentIndex = visibleKeys.indexOf(currentKey);\n\n if (currentIndex === -1) {\n // Current key not in visible items, start from beginning/end\n nextKey = findFirstLastSelectableKey(direction, visibleKeys);\n } else {\n // Find next selectable item from current position\n nextKey = findNextSelectableKey(\n currentIndex,\n direction,\n visibleKeys,\n );\n\n // If no next key found, wrap to first/last selectable item\n if (nextKey == null) {\n nextKey = findFirstLastSelectableKey(direction, visibleKeys);\n }\n }\n }\n\n if (nextKey != null) {\n selectionManager.setFocusedKey(nextKey);\n setFocusedKey(nextKey);\n focusedKeyRef.current = nextKey; // Update ref immediately\n }\n } else if (\n e.key === 'Enter' ||\n (e.key === ' ' && !searchValue.trim())\n ) {\n const currentFocusedKey =\n focusedKey || treeState.selectionManager.focusedKey;\n if (currentFocusedKey != null) {\n e.preventDefault();\n\n // Trigger action for the focused item (like Menu does)\n // First check if there's a selection mode, if so, handle selection\n if (treeState.selectionManager.selectionMode !== 'none') {\n treeState.selectionManager.select(currentFocusedKey, e);\n } else {\n // Default behavior: trigger action\n const node = treeState.collection.getItem(currentFocusedKey);\n if (node) {\n // Call the tree state's action handler\n const onAction = (completeProps as any).onAction;\n if (onAction) {\n onAction(currentFocusedKey);\n }\n // Also call the item's individual onAction if it exists\n if (node.props?.onAction) {\n node.props.onAction(currentFocusedKey);\n }\n }\n }\n\n // Close the menu if we're in a trigger context and closeOnSelect is enabled (default behavior)\n const { onClose, closeOnSelect } = contextProps;\n if (onClose && closeOnSelect !== false) {\n onClose();\n }\n }\n } else if (e.key === 'Escape') {\n if (searchValue) {\n e.preventDefault();\n handleSearchChange('');\n }\n }\n }}\n />\n\n {/* Loading State */}\n {isLoading && (\n <StyledLoadingWrapper>\n <LoadingIcon\n role=\"progressbar\"\n aria-label=\"Loading commands\"\n aria-hidden={false}\n />\n </StyledLoadingWrapper>\n )}\n\n {/* Menu Content - always render unless loading */}\n {!isLoading && !showEmptyState && (\n <StyledMenu\n {...menuProps}\n ref={menuRef}\n id={`${qa || 'CommandMenu'}-menu`}\n aria-label=\"Command menu\"\n qa=\"Menu\"\n data-size={size}\n mods={mods}\n styles={{\n border: 'none',\n boxShadow: 'none',\n radius: 0,\n padding: '0.5x',\n }}\n >\n {renderedItems}\n </StyledMenu>\n )}\n\n {/* Empty State - show when search term exists but no results */}\n {!isLoading && showEmptyState && (\n <StyledEmptyState>{emptyLabel}</StyledEmptyState>\n )}\n\n {/* Footer */}\n {footer && (\n <StyledFooter\n role=\"presentation\"\n data-size={size}\n styles={footerStyles}\n >\n {footer}\n </StyledFooter>\n )}\n </StyledCommandMenu>\n );\n}\n\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\nconst _CommandMenu = React.forwardRef(CommandMenu) as <T>(\n props: CubeCommandMenuProps<T> & React.RefAttributes<HTMLDivElement>,\n) => ReactElement;\n\n// Attach Trigger alias from MenuTrigger for consistent API\n// Also attach Item and Section for compound component pattern\nconst __CommandMenu = Object.assign(_CommandMenu, {\n Trigger: MenuTrigger,\n Item,\n Section,\n displayName: 'CommandMenu',\n});\n\nexport { __CommandMenu as CommandMenu };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA8FA,SAAS,YACP,OACA,KACA;CACA,MAAM,EACJ,oBAAoB,sBACpB,aAAa,uBACb,gBACA,QAAQ,cACR,aAAa,qBACb,mBACA,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,EAAE,QAAQ,WACT,EAAE,QAAQ,OAAO,CAAC,YAAY,MAAM,EACrC;MACA,MAAM,oBACJ,cAAc,UAAU,iBAAiB;AAC3C,UAAI,qBAAqB,MAAM;AAC7B,SAAE,gBAAgB;AAIlB,WAAI,UAAU,iBAAiB,kBAAkB,OAC/C,WAAU,iBAAiB,OAAO,mBAAmB,EAAE;YAClD;QAEL,MAAM,OAAO,UAAU,WAAW,QAAQ,kBAAkB;AAC5D,YAAI,MAAM;SAER,MAAM,WAAY,cAAsB;AACxC,aAAI,SACF,UAAS,kBAAkB;AAG7B,aAAI,KAAK,OAAO,SACd,MAAK,MAAM,SAAS,kBAAkB;;;OAM5C,MAAM,EAAE,SAAS,kBAAkB;AACnC,WAAI,WAAW,kBAAkB,MAC/B,UAAS;;gBAGJ,EAAE,QAAQ,UACnB;UAAI,aAAa;AACf,SAAE,gBAAgB;AAClB,0BAAmB,GAAG;;;;KAI5B;GAGD,aACC,oBAAC,kCACC,oBAAC;IACC,MAAK;IACL,cAAW;IACX,eAAa;KACb,GACmB;GAIxB,CAAC,aAAa,CAAC,kBACd,oBAAC;IACC,GAAI;IACJ,KAAK;IACL,IAAI,GAAG,MAAM,cAAc;IAC3B,cAAW;IACX,IAAG;IACH,aAAW;IACL;IACN,QAAQ;KACN,QAAQ;KACR,WAAW;KACX,QAAQ;KACR,SAAS;KACV;cAEA;KACU;GAId,CAAC,aAAa,kBACb,oBAAC,8BAAkB,aAA8B;GAIlD,UACC,oBAAC;IACC,MAAK;IACL,aAAW;IACX,QAAQ;cAEP;KACY;;GAEC;;AAKxB,MAAM,eAAe,MAAM,WAAW,YAAY;AAMlD,MAAM,gBAAgB,OAAO,OAAO,cAAc;CAChD,SAASC;CACT;CACA;CACA,aAAa;CACd,CAAC"}
|
|
1
|
+
{"version":3,"file":"CommandMenu.js","names":["mergeProps","MenuTrigger"],"sources":["../../../../src/components/actions/CommandMenu/CommandMenu.tsx"],"sourcesContent":["import { useObjectRef, useSyncRef } from '@react-aria/utils';\nimport { FocusStrategy } from '@react-types/shared';\nimport {\n BaseProps,\n CONTAINER_STYLES,\n ContainerStyleProps,\n filterBaseProps,\n Styles,\n} from '@tenphi/tasty';\nimport React, {\n Key,\n ReactElement,\n ReactNode,\n Ref,\n useCallback,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useFilter, useMenu } from 'react-aria';\n// Import Item and Section from Menu for CommandMenu compound component\nimport { Item, Section, useTreeState } from 'react-stately';\n\nimport { LoadingIcon } from '../../../icons';\nimport { mergeProps } from '../../../utils/react';\nimport { extractStyles } from '../../../utils/styles';\nimport { TooltipProvider } from '../../overlays/Tooltip/TooltipProvider';\nimport { useMenuContext } from '../Menu';\nimport { CubeMenuProps } from '../Menu/Menu';\nimport { MenuItem } from '../Menu/MenuItem';\nimport { MenuSection } from '../Menu/MenuSection';\nimport { MenuTrigger } from '../Menu/MenuTrigger';\nimport {\n StyledDivider,\n StyledFooter,\n StyledHeader,\n StyledMenu,\n} from '../Menu/styled';\n\nimport {\n StyledCommandMenu,\n StyledEmptyState,\n StyledLoadingWrapper,\n StyledSearchInput,\n} from './styled';\n\nexport interface CommandMenuItem {\n // Standard item props\n id: string;\n textValue: string;\n\n // Enhanced search features\n keywords?: string[];\n forceMount?: boolean;\n\n // Standard Menu item props inherited\n [key: string]: any;\n}\n\nexport interface CubeCommandMenuProps<T>\n extends BaseProps,\n ContainerStyleProps,\n Omit<\n CubeMenuProps<T>,\n 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange'\n > {\n // Search-specific props\n searchPlaceholder?: string;\n searchValue?: string;\n onSearchChange?: (value: string) => void;\n filter?: (textValue: string, inputValue: string) => boolean;\n emptyLabel?: ReactNode;\n searchInputStyles?: Styles;\n headerStyles?: Styles;\n footerStyles?: Styles;\n\n // Advanced search features\n isLoading?: boolean;\n shouldFilter?: boolean;\n\n // Focus management - override the autoFocus from CubeMenuProps to allow boolean | FocusStrategy\n autoFocus?: boolean | FocusStrategy;\n\n // Size prop\n size?: 'medium' | 'large' | (string & {});\n\n /** Currently selected keys (controlled) */\n selectedKeys?: string[];\n /** Initially selected keys (uncontrolled) */\n defaultSelectedKeys?: string[];\n /** Handler for selection changes */\n onSelectionChange?: (keys: string[]) => void;\n}\n\nfunction CommandMenu<T extends object>(\n props: CubeCommandMenuProps<T>,\n ref: Ref<HTMLDivElement>,\n) {\n const {\n searchPlaceholder = 'Search commands...',\n searchValue: controlledSearchValue,\n onSearchChange,\n filter: customFilter,\n emptyLabel = 'No commands found',\n searchInputStyles,\n headerStyles,\n footerStyles,\n isLoading = false,\n shouldFilter = true,\n autoFocus = true,\n size = 'medium',\n qa,\n styles,\n selectedKeys,\n defaultSelectedKeys,\n onSelectionChange,\n header,\n footer,\n ...restMenuProps\n } = props;\n\n const domRef = useObjectRef(ref);\n const searchInputRef = useRef<HTMLInputElement>(null);\n const contextProps = useMenuContext();\n\n // Convert string[] to Set<Key> for React Aria compatibility\n const ariaSelectedKeys = selectedKeys ? new Set(selectedKeys) : undefined;\n const ariaDefaultSelectedKeys = defaultSelectedKeys\n ? new Set(defaultSelectedKeys)\n : undefined;\n\n const handleSelectionChange = onSelectionChange\n ? (keys: 'all' | Set<Key>) => {\n if (keys === 'all') {\n // Handle 'all' selection case - collect all available keys\n const allKeys = Array.from(treeState.collection.getKeys()).map(\n (key: any) => String(key),\n );\n onSelectionChange(allKeys);\n } else if (keys instanceof Set) {\n onSelectionChange(Array.from(keys).map((key) => String(key)));\n } else {\n onSelectionChange([]);\n }\n }\n : undefined;\n\n const completeProps = mergeProps(contextProps, restMenuProps, {\n selectedKeys: ariaSelectedKeys,\n defaultSelectedKeys: ariaDefaultSelectedKeys,\n onSelectionChange: handleSelectionChange,\n });\n\n // Search state management\n const [internalSearchValue, setInternalSearchValue] = useState('');\n const searchValue = controlledSearchValue ?? internalSearchValue;\n\n const handleSearchChange = useCallback(\n (value: string) => {\n if (controlledSearchValue === undefined) {\n setInternalSearchValue(value);\n }\n onSearchChange?.(value);\n },\n [controlledSearchValue, onSearchChange],\n );\n\n // Filter setup\n const { contains } = useFilter({ sensitivity: 'base' });\n const textFilterFn = useMemo(\n () => customFilter || contains,\n [customFilter, contains],\n );\n\n // Enhanced filter function that supports keywords and forceMount\n const enhancedFilter = useCallback(\n (textValue: string, inputValue: string, item?: any) => {\n // Always show force-mounted items\n if (item?.forceMount) {\n return true;\n }\n\n // If shouldFilter is false, show all items\n if (!shouldFilter) {\n return true;\n }\n\n // Split input value into individual words and filter out empty strings\n const searchWords = inputValue\n .trim()\n .toLowerCase()\n .split(/\\s+/)\n .filter((word) => word.length > 0);\n\n // If no search words, show all items\n if (searchWords.length === 0) {\n return true;\n }\n\n // Collect all searchable text for this item\n const searchableTexts: string[] = [];\n\n // Add main text value\n searchableTexts.push(textValue.toLowerCase());\n\n // Add keywords if available\n if (item?.keywords && Array.isArray(item.keywords)) {\n searchableTexts.push(\n ...item.keywords.map((keyword: string) => keyword.toLowerCase()),\n );\n }\n\n // Check if ALL search words match at least one of the searchable texts\n return searchWords.every((searchWord) =>\n searchableTexts.some((text) => text.includes(searchWord)),\n );\n },\n [shouldFilter],\n );\n\n // Collection filter for React Stately\n const collectionFilter = useCallback(\n (nodes: Iterable<any>): Iterable<any> => {\n const term = searchValue.trim();\n\n // If no search term, return all nodes\n if (!term) {\n return nodes;\n }\n\n // Split search term into words for multi-word filtering\n const searchWords = term\n .toLowerCase()\n .split(/\\s+/)\n .filter((word) => word.length > 0);\n\n // If no valid search words, return all nodes\n if (searchWords.length === 0) {\n return nodes;\n }\n\n // Recursive helper to filter sections and items\n const filterNodes = (iter: Iterable<any>): any[] => {\n const result: any[] = [];\n\n for (const node of iter) {\n if (node.type === 'section') {\n const filteredChildren = filterNodes(node.childNodes);\n\n if (filteredChildren.length) {\n result.push({\n ...node,\n childNodes: filteredChildren,\n });\n }\n } else {\n const text = node.textValue ?? String(node.rendered ?? '');\n\n if (enhancedFilter(text, term, node.props)) {\n result.push(node);\n }\n }\n }\n\n return result;\n };\n\n return filterNodes(nodes);\n },\n [searchValue, enhancedFilter],\n );\n\n // Create tree state with filter for both keyboard navigation and rendering\n const treeStateProps = {\n ...completeProps,\n filter: collectionFilter,\n shouldUseVirtualFocus: true, // Always use virtual focus for CommandMenu\n };\n\n const treeState = useTreeState(treeStateProps);\n\n const collectionItems = [...treeState.collection];\n const hasSections = collectionItems.some((item) => item.type === 'section');\n\n // Track focused key for aria-activedescendant\n const [focusedKey, setFocusedKey] = React.useState<React.Key | null>(null);\n const focusedKeyRef = useRef<React.Key | null>(null);\n\n // Apply filtering to collection items for rendering and empty state checks\n const filteredCollectionItems = useMemo(() => {\n const term = searchValue.trim();\n if (!term) {\n return collectionItems;\n }\n\n // Split search term into words for multi-word filtering\n const searchWords = term\n .toLowerCase()\n .split(/\\s+/)\n .filter((word) => word.length > 0);\n\n // If no valid search words, return all items\n if (searchWords.length === 0) {\n return collectionItems;\n }\n\n const filterNodes = (items: any[]): any[] => {\n const result: any[] = [];\n\n [...items].forEach((item) => {\n if (item.type === 'section') {\n const filteredChildren = filterNodes(item.childNodes);\n if (filteredChildren.length) {\n result.push({\n ...item,\n childNodes: filteredChildren,\n });\n }\n } else {\n const text = item.textValue ?? String(item.rendered ?? '');\n if (enhancedFilter(text, term, item.props)) {\n result.push(item);\n }\n }\n });\n\n return result;\n };\n\n return filterNodes(collectionItems);\n }, [collectionItems, searchValue, enhancedFilter]);\n\n const hasFilteredItems = filteredCollectionItems.length > 0;\n const viewHasSections = filteredCollectionItems.some(\n (item) => item.type === 'section',\n );\n\n // Helper function to find the first selectable item from filtered results\n const findFirstSelectableItem = useCallback(() => {\n const { selectionManager } = treeState;\n\n const visit = (items: any[]): Key | null => {\n for (const node of items) {\n if (node?.type === 'section') {\n const childResult = visit(Array.from(node.childNodes ?? []));\n if (childResult != null) return childResult;\n } else if (\n node?.type === 'item' &&\n !selectionManager.isDisabled(node.key)\n ) {\n return node.key;\n }\n }\n return null;\n };\n\n return visit(filteredCollectionItems);\n }, [filteredCollectionItems, treeState.selectionManager]);\n\n // Create a ref for the menu container\n const menuRef = useRef<HTMLUListElement>(null);\n\n // Use menu hook for accessibility\n const { menuProps } = useMenu(\n {\n ...completeProps,\n 'aria-label': 'Command palette menu',\n filter: collectionFilter,\n shouldUseVirtualFocus: true,\n },\n treeState,\n menuRef,\n );\n\n // Manual rendering of menu items (similar to Menu component)\n const renderedItems = useMemo(() => {\n const items: React.ReactNode[] = [];\n let isFirstSection = true;\n\n filteredCollectionItems.forEach((item) => {\n if (item.type === 'section') {\n if (!isFirstSection) {\n items.push(\n <StyledDivider\n key={`divider-${String(item.key)}`}\n role=\"separator\"\n aria-orientation=\"horizontal\"\n />,\n );\n }\n\n items.push(\n <MenuSection\n key={item.key}\n item={item}\n state={treeState}\n styles={completeProps.sectionStyles}\n itemStyles={completeProps.itemStyles}\n headingStyles={completeProps.sectionHeadingStyles}\n size={size}\n />,\n );\n\n isFirstSection = false;\n return;\n }\n\n let menuItem = (\n <MenuItem\n key={item.key}\n item={item}\n state={treeState}\n styles={completeProps.itemStyles}\n size={size}\n onAction={item.onAction}\n />\n );\n\n // Apply tooltip wrapper if tooltip property is provided\n if (item.props.tooltip) {\n const tooltipProps =\n typeof item.props.tooltip === 'string'\n ? { title: item.props.tooltip }\n : item.props.tooltip;\n\n menuItem = (\n <TooltipProvider\n key={item.key}\n activeWrap\n placement=\"right\"\n {...tooltipProps}\n >\n {menuItem}\n </TooltipProvider>\n );\n }\n\n // Apply custom wrapper if provided\n if (item.props.wrapper) {\n menuItem = item.props.wrapper(menuItem);\n }\n\n // Ensure every child has a stable key, even if the wrapper component didn't set one.\n items.push(React.cloneElement(menuItem, { key: item.key }));\n });\n\n return items;\n }, [\n filteredCollectionItems,\n treeState,\n completeProps.sectionStyles,\n completeProps.itemStyles,\n\n completeProps.sectionHeadingStyles,\n ]);\n\n // Auto-focus search input\n React.useEffect(() => {\n if (autoFocus && searchInputRef.current) {\n // Use a small timeout to ensure the element is visible and focusable\n // This is especially important when the CommandMenu is opened in a popover\n const timeoutId = setTimeout(() => {\n if (searchInputRef.current) {\n searchInputRef.current.focus();\n }\n }, 0);\n\n return () => clearTimeout(timeoutId);\n }\n }, [autoFocus]);\n\n // Also focus when the component becomes visible (for trigger/popover usage)\n React.useEffect(() => {\n // Check if autoFocus is enabled and we're in a trigger context\n if (autoFocus && contextProps.autoFocus && searchInputRef.current) {\n // Use a small timeout to ensure the popover is fully rendered\n const timeoutId = setTimeout(() => {\n if (searchInputRef.current) {\n searchInputRef.current.focus();\n }\n }, 50); // Slightly longer timeout for popover context\n\n return () => clearTimeout(timeoutId);\n }\n }, [autoFocus, contextProps.autoFocus]);\n\n // Track the previous search value to only run auto-focus when search actually changes\n const prevSearchValueRef = useRef<string>('');\n\n // Auto-focus first item when search value changes (but not on initial render)\n React.useEffect(() => {\n const currentSearchValue = searchValue.trim();\n const prevSearchValue = prevSearchValueRef.current;\n\n // Only auto-focus when search value actually changes\n if (currentSearchValue !== prevSearchValue && currentSearchValue !== '') {\n const firstSelectableKey = findFirstSelectableItem();\n\n if (firstSelectableKey && hasFilteredItems) {\n // Focus the first item in the selection manager\n treeState.selectionManager.setFocusedKey(firstSelectableKey);\n setFocusedKey(firstSelectableKey);\n focusedKeyRef.current = firstSelectableKey;\n } else {\n // Clear focus if no items are available\n treeState.selectionManager.setFocusedKey(null);\n setFocusedKey(null);\n focusedKeyRef.current = null;\n }\n }\n\n // Update the previous search value\n prevSearchValueRef.current = currentSearchValue;\n }, [searchValue, findFirstSelectableItem, hasFilteredItems]);\n\n // Extract styles\n const extractedStyles = useMemo(\n () => extractStyles(props, CONTAINER_STYLES),\n [props],\n );\n\n // Determine if we should show empty state based on actual filtered collection\n const hasSearchTerm = searchValue.trim().length > 0;\n const showEmptyState = hasSearchTerm && !hasFilteredItems && !isLoading;\n\n // Sync refs\n useSyncRef(contextProps, menuRef);\n\n const mods = useMemo(() => {\n // Determine mods based on menu context\n let popoverMod = completeProps.mods?.popover;\n let trayMod = completeProps.mods?.tray;\n\n return {\n sections: viewHasSections,\n footer: !!footer,\n header: !!header,\n popover: popoverMod,\n tray: trayMod,\n };\n }, [viewHasSections, footer, header, completeProps.mods]);\n\n return (\n <StyledCommandMenu\n {...(filterBaseProps(props) as Record<string, unknown>)}\n ref={domRef}\n qa={qa || 'CommandMenu'}\n data-size={size}\n mods={mods}\n styles={mergeProps(extractedStyles, styles)}\n >\n {/* Header */}\n {header && (\n <StyledHeader\n role=\"presentation\"\n data-size={size}\n styles={{ border: 'none', ...headerStyles }}\n >\n {header}\n </StyledHeader>\n )}\n\n {/* Search Input */}\n <StyledSearchInput\n ref={searchInputRef}\n type=\"search\"\n placeholder={searchPlaceholder}\n value={searchValue}\n styles={searchInputStyles}\n data-size={size}\n aria-controls={`${qa || 'CommandMenu'}-menu`}\n role=\"combobox\"\n aria-expanded=\"true\"\n aria-haspopup=\"listbox\"\n aria-activedescendant={\n focusedKey != null\n ? `${qa || 'CommandMenu'}-menu-option-${focusedKey}`\n : undefined\n }\n onChange={(e) => handleSearchChange(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n e.preventDefault();\n\n const isArrowDown = e.key === 'ArrowDown';\n const { selectionManager } = treeState;\n // Use the ref to get the current focused key synchronously\n const currentKey =\n focusedKeyRef.current || selectionManager.focusedKey;\n\n // Helper function to get all visible item keys accounting for sections\n const getVisibleItemKeys = (): Key[] => {\n const keys: Key[] = [];\n\n const visit = (items: any[]) => {\n for (const node of items) {\n if (node?.type === 'section') {\n visit(Array.from(node.childNodes ?? []));\n } else if (node?.type === 'item') {\n keys.push(node.key);\n }\n }\n };\n\n visit(filteredCollectionItems);\n return keys;\n };\n\n // Helper function to find next selectable key in a direction\n const findNextSelectableKey = (\n currentIndex: number,\n direction: 'forward' | 'backward',\n visibleKeys: Key[],\n ) => {\n const increment = direction === 'forward' ? 1 : -1;\n\n for (\n let i = currentIndex + increment;\n i >= 0 && i < visibleKeys.length;\n i += increment\n ) {\n const key = visibleKeys[i];\n if (!selectionManager.isDisabled(key)) {\n return key;\n }\n }\n\n return null;\n };\n\n // Helper function to find first or last selectable key\n const findFirstLastSelectableKey = (\n direction: 'forward' | 'backward',\n visibleKeys: Key[],\n ) => {\n const keysToCheck =\n direction === 'forward'\n ? visibleKeys\n : [...visibleKeys].reverse();\n\n for (const key of keysToCheck) {\n if (!selectionManager.isDisabled(key)) {\n return key;\n }\n }\n\n return null;\n };\n\n const visibleKeys = getVisibleItemKeys();\n\n if (visibleKeys.length === 0) {\n return; // No visible items to navigate\n }\n\n let nextKey;\n const direction = isArrowDown ? 'forward' : 'backward';\n\n if (currentKey == null) {\n // No current focus, start from the first/last item\n nextKey = findFirstLastSelectableKey(direction, visibleKeys);\n } else {\n // Find current position in visible keys\n const currentIndex = visibleKeys.indexOf(currentKey);\n\n if (currentIndex === -1) {\n // Current key not in visible items, start from beginning/end\n nextKey = findFirstLastSelectableKey(direction, visibleKeys);\n } else {\n // Find next selectable item from current position\n nextKey = findNextSelectableKey(\n currentIndex,\n direction,\n visibleKeys,\n );\n\n // If no next key found, wrap to first/last selectable item\n if (nextKey == null) {\n nextKey = findFirstLastSelectableKey(direction, visibleKeys);\n }\n }\n }\n\n if (nextKey != null) {\n selectionManager.setFocusedKey(nextKey);\n setFocusedKey(nextKey);\n focusedKeyRef.current = nextKey; // Update ref immediately\n }\n } else if (\n e.key === 'Enter' ||\n (e.key === ' ' && !searchValue.trim())\n ) {\n const currentFocusedKey =\n focusedKey || treeState.selectionManager.focusedKey;\n if (currentFocusedKey != null) {\n e.preventDefault();\n\n // Trigger action for the focused item (like Menu does)\n // First check if there's a selection mode, if so, handle selection\n if (treeState.selectionManager.selectionMode !== 'none') {\n treeState.selectionManager.select(currentFocusedKey, e);\n } else {\n // Default behavior: trigger action\n const node = treeState.collection.getItem(currentFocusedKey);\n if (node) {\n // Call the tree state's action handler\n const onAction = (completeProps as any).onAction;\n if (onAction) {\n onAction(currentFocusedKey);\n }\n // Also call the item's individual onAction if it exists\n if (node.props?.onAction) {\n node.props.onAction(currentFocusedKey);\n }\n }\n }\n\n // Close the menu if we're in a trigger context and closeOnSelect is enabled (default behavior)\n const { onClose, closeOnSelect } = contextProps;\n if (onClose && closeOnSelect !== false) {\n onClose();\n }\n }\n } else if (e.key === 'Escape') {\n if (searchValue) {\n e.preventDefault();\n handleSearchChange('');\n }\n }\n }}\n />\n\n {/* Loading State */}\n {isLoading && (\n <StyledLoadingWrapper>\n <LoadingIcon\n role=\"progressbar\"\n aria-label=\"Loading commands\"\n aria-hidden={false}\n />\n </StyledLoadingWrapper>\n )}\n\n {/* Menu Content - always render unless loading */}\n {!isLoading && !showEmptyState && (\n <StyledMenu\n {...menuProps}\n ref={menuRef}\n id={`${qa || 'CommandMenu'}-menu`}\n aria-label=\"Command menu\"\n qa=\"Menu\"\n data-size={size}\n mods={mods}\n styles={{\n border: 'none',\n boxShadow: 'none',\n radius: 0,\n padding: '0.5x',\n }}\n >\n {renderedItems}\n </StyledMenu>\n )}\n\n {/* Empty State - show when search term exists but no results */}\n {!isLoading && showEmptyState && (\n <StyledEmptyState>{emptyLabel}</StyledEmptyState>\n )}\n\n {/* Footer */}\n {footer && (\n <StyledFooter\n role=\"presentation\"\n data-size={size}\n styles={footerStyles}\n >\n {footer}\n </StyledFooter>\n )}\n </StyledCommandMenu>\n );\n}\n\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\nconst _CommandMenu = React.forwardRef(CommandMenu) as <T>(\n props: CubeCommandMenuProps<T> & React.RefAttributes<HTMLDivElement>,\n) => ReactElement;\n\n// Attach Trigger alias from MenuTrigger for consistent API\n// Also attach Item and Section for compound component pattern\nconst __CommandMenu = Object.assign(_CommandMenu, {\n Trigger: MenuTrigger,\n Item,\n Section,\n displayName: 'CommandMenu',\n});\n\nexport { __CommandMenu as CommandMenu };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8FA,SAAS,YACP,OACA,KACA;CACA,MAAM,EACJ,oBAAoB,sBACpB,aAAa,uBACb,gBACA,QAA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1 | Cube Dev Team */
|
|
2
2
|
import { mergeProps } from "../../../utils/react/mergeProps.js";
|
|
3
3
|
import { TooltipProvider } from "../../overlays/Tooltip/TooltipProvider.js";
|
|
4
4
|
import { DANGER_CLEAR_STYLES, DANGER_OUTLINE_STYLES, DANGER_PRIMARY_STYLES, DEFAULT_CLEAR_STYLES, DEFAULT_OUTLINE_STYLES, DEFAULT_PRIMARY_STYLES, ITEM_ACTION_BASE_STYLES, NOTE_CLEAR_STYLES, NOTE_OUTLINE_STYLES, NOTE_PRIMARY_STYLES, SPECIAL_CLEAR_STYLES, SPECIAL_OUTLINE_STYLES, SPECIAL_PRIMARY_STYLES, SUCCESS_CLEAR_STYLES, SUCCESS_OUTLINE_STYLES, SUCCESS_PRIMARY_STYLES, WARNING_CLEAR_STYLES, WARNING_OUTLINE_STYLES, WARNING_PRIMARY_STYLES } from "../../../data/item-themes.js";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.142.1 | Cube Dev Team */
|
|
2
2
|
import { mergeProps as mergeProps$1 } from "../../../utils/react/mergeProps.js";
|
|
3
|
+
import { mergeRefs } from "../../../utils/react/useCombinedRefs.js";
|
|
4
|
+
import { useDismissParentPopover } from "../../../utils/react/usePopoverSync.js";
|
|
5
|
+
import { useEvent } from "../../../_internal/hooks/use-event.js";
|
|
3
6
|
import { DisplayTransition } from "../../helpers/DisplayTransition/DisplayTransition.js";
|
|
4
7
|
import { ItemActionProvider } from "../ItemActionContext.js";
|
|
5
8
|
import { useAction } from "../use-action.js";
|
|
@@ -97,13 +100,24 @@ const ItemButton = forwardRef(function ItemButton(allProps, ref) {
|
|
|
97
100
|
return () => observer.disconnect();
|
|
98
101
|
}, [areActionsVisible, autoHideActions]);
|
|
99
102
|
const shouldShowActions = isHovered || isFocusWithin || hasPressed || !autoHideActions;
|
|
103
|
+
const dismissParentPopover = useDismissParentPopover();
|
|
104
|
+
const buttonElementRef = useRef(null);
|
|
105
|
+
const wrappedOnPress = useEvent((e) => {
|
|
106
|
+
onPress?.(e);
|
|
107
|
+
const el = buttonElementRef.current;
|
|
108
|
+
if (!el) return;
|
|
109
|
+
if (el.hasAttribute("data-popover-trigger")) return;
|
|
110
|
+
if (el.closest("[data-popover-keep]")) return;
|
|
111
|
+
dismissParentPopover(el);
|
|
112
|
+
});
|
|
100
113
|
const { actionProps } = useAction({
|
|
101
114
|
...allProps,
|
|
102
115
|
htmlType,
|
|
103
116
|
to,
|
|
104
117
|
as,
|
|
105
118
|
mods,
|
|
106
|
-
isDisabled: finalIsDisabled
|
|
119
|
+
isDisabled: finalIsDisabled,
|
|
120
|
+
onPress: wrappedOnPress
|
|
107
121
|
}, ref);
|
|
108
122
|
const finalMods = useMemo(() => {
|
|
109
123
|
return shouldShowActions ? {
|
|
@@ -111,11 +125,13 @@ const ItemButton = forwardRef(function ItemButton(allProps, ref) {
|
|
|
111
125
|
"actions-shown": true
|
|
112
126
|
} : mods;
|
|
113
127
|
}, [mods, shouldShowActions]);
|
|
128
|
+
const combinedRef = useMemo(() => mergeRefs(actionProps.ref, buttonElementRef), [actionProps.ref]);
|
|
114
129
|
const button = /* @__PURE__ */ jsx(StyledItem, {
|
|
115
130
|
insideWrapper: !!actions,
|
|
116
131
|
showActions: shouldShowActions,
|
|
117
132
|
actions: actions ? true : void 0,
|
|
118
133
|
...mergeProps$1(rest, actionProps),
|
|
134
|
+
ref: combinedRef,
|
|
119
135
|
"data-popover-dismiss": "",
|
|
120
136
|
htmlType: actionProps.type,
|
|
121
137
|
type,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemButton.js","names":["Item","mergeProps"],"sources":["../../../../src/components/actions/ItemButton/ItemButton.tsx"],"sourcesContent":["import { FocusableRef } from '@react-types/shared';\nimport { Styles, tasty } from '@tenphi/tasty';\nimport {\n CSSProperties,\n forwardRef,\n ReactNode,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useFocusWithin, useHover } from 'react-aria';\n\nimport { mergeProps } from '../../../utils/react';\nimport { CubeItemProps, Item } from '../../content/Item';\nimport { ItemBadge } from '../../content/ItemBadge';\nimport { DisplayTransition } from '../../helpers';\nimport { CubeItemActionProps, ItemAction } from '../ItemAction';\nimport { ItemActionProvider } from '../ItemActionContext';\nimport { CubeUseActionProps, useAction } from '../use-action';\n\nexport interface CubeItemButtonProps\n extends Omit<CubeItemProps, 'size'>,\n Omit<CubeUseActionProps, 'as'> {\n actions?: ReactNode;\n size?: Omit<CubeItemProps['size'], 'inline'>;\n wrapperStyles?: Styles;\n}\n\nconst StyledItem = tasty(Item, {\n as: 'button',\n type: 'item',\n theme: 'default',\n styles: {\n recipe: 'reset button',\n placeContent: 'center stretch',\n },\n});\n\nconst ActionsWrapper = tasty({\n styles: {\n display: 'grid',\n position: 'relative',\n placeContent: 'stretch',\n placeItems: 'stretch',\n\n $size: {\n '': '$size-md',\n 'size=xsmall': '$size-xs',\n 'size=small': '$size-sm',\n 'size=medium': '$size-md',\n 'size=large': '$size-lg',\n 'size=xlarge': '$size-xl',\n },\n\n Actions: {\n $: '>',\n position: 'absolute',\n inset: {\n '': '1bw 1bw auto auto',\n 'type=card': '(1bw + .5x) (1bw + .5x) auto auto',\n },\n display: 'flex',\n gap: '1bw',\n placeItems: 'center',\n placeContent: 'center end',\n pointerEvents: {\n '': 'auto',\n '!actions-shown': 'none',\n },\n padding: '0 $side-padding',\n height: 'min ($size - 2bw)',\n opacity: {\n '': 1,\n '!actions-shown': 0,\n },\n translate: {\n '': '0 0',\n '!actions-shown': '.5x 0',\n },\n transition: 'theme, translate',\n\n // Size for the action buttons\n '$action-size': 'min(max((2x + 2bw), ($size - 1x - 2bw)), (3x - 2bw))',\n // Side padding for the button\n '$side-padding': '(($size - $action-size - 2bw) / 2)',\n },\n },\n});\n\nconst ItemButton = forwardRef(function ItemButton(\n allProps: CubeItemButtonProps,\n ref: FocusableRef<HTMLElement>,\n) {\n const {\n mods,\n to,\n htmlType,\n as,\n type = 'item',\n theme = 'default',\n onPress,\n // Extract react-aria press callbacks to prevent them from leaking to DOM via rest.\n // These are handled by useButton inside useAction.\n onPressStart: _onPressStart,\n onPressEnd: _onPressEnd,\n onPressChange: _onPressChange,\n onPressUp: _onPressUp,\n actions,\n size = 'medium',\n wrapperStyles,\n autoHideActions = false,\n disableActionsFocus = false,\n isDisabled,\n isLoading = false,\n ...rest\n } = allProps as CubeItemButtonProps & {\n as?: 'a' | 'button' | 'div' | 'span';\n };\n\n // Loading state makes the component disabled (same logic as Item)\n const finalIsDisabled =\n isDisabled === true || (isLoading && isDisabled !== false);\n\n const actionsRef = useRef<HTMLDivElement>(null);\n const [actionsWidth, setActionsWidth] = useState(0);\n const [areActionsVisible, setAreActionsVisible] = useState(false);\n const [areActionsShown, setAreActionsShown] = useState(false);\n\n useLayoutEffect(() => {\n if (actions && actionsRef.current) {\n const width = Math.round(actionsRef.current.offsetWidth);\n if (width !== actionsWidth) {\n setActionsWidth(width);\n }\n }\n }, [actions, areActionsVisible]);\n\n const [isFocusWithin, setIsFocusWithin] = useState(false);\n const [hasPressed, setHasPressed] = useState(false);\n const { hoverProps, isHovered } = useHover({});\n const { focusWithinProps } = useFocusWithin({\n onFocusWithinChange: setIsFocusWithin,\n });\n\n // Watch for data-pressed attribute on any descendant element\n useLayoutEffect(() => {\n const actionsEl = actionsRef.current;\n\n if (!actionsEl || !autoHideActions) return;\n\n const checkPressed = () => {\n setHasPressed(actionsEl.querySelector('[data-pressed]') !== null);\n };\n\n const observer = new MutationObserver(checkPressed);\n\n observer.observe(actionsEl, {\n attributes: true,\n attributeFilter: ['data-pressed'],\n subtree: true,\n });\n\n checkPressed();\n\n return () => observer.disconnect();\n }, [areActionsVisible, autoHideActions]);\n\n const shouldShowActions =\n isHovered || isFocusWithin || hasPressed || !autoHideActions;\n\n const { actionProps } = useAction(\n {\n ...(allProps as any),\n htmlType,\n to,\n as,\n mods,\n isDisabled: finalIsDisabled,\n },\n ref,\n );\n\n const finalMods = useMemo(() => {\n return shouldShowActions ? { ...mods, 'actions-shown': true } : mods;\n }, [mods, shouldShowActions]);\n\n const button = (\n <StyledItem\n insideWrapper={!!actions}\n showActions={shouldShowActions}\n actions={actions ? true : undefined}\n {...(mergeProps(rest, actionProps) as any)}\n data-popover-dismiss=\"\"\n htmlType={actionProps.type}\n type={type}\n theme={theme}\n size={size}\n isLoading={isLoading}\n isDisabled={isDisabled}\n />\n );\n\n if (actions) {\n return (\n <ActionsWrapper\n {...hoverProps}\n data-size={size}\n data-type={type}\n data-theme={theme}\n mods={finalMods}\n styles={wrapperStyles}\n style={\n {\n '--actions-width':\n areActionsVisible || !autoHideActions\n ? `${actionsWidth}px`\n : '0px',\n ...(typeof size === 'number' && { '--size': `${size}px` }),\n } as CSSProperties\n }\n >\n {button}\n <ItemActionProvider\n type={type}\n theme={theme}\n disableActionsFocus={disableActionsFocus}\n isDisabled={finalIsDisabled}\n >\n {autoHideActions ? (\n <DisplayTransition\n exposeUnmounted\n isShown={shouldShowActions}\n onPhaseChange={(phase) => {\n setAreActionsVisible(phase !== 'unmounted');\n }}\n onToggle={(isShown) => {\n setAreActionsShown(isShown);\n }}\n >\n {({ ref: transitionRef }) => {\n return (\n <div\n {...focusWithinProps}\n ref={(node: any) => {\n actionsRef.current = node;\n transitionRef(node);\n }}\n data-element=\"Actions\"\n >\n {actions}\n </div>\n );\n }}\n </DisplayTransition>\n ) : (\n <div ref={actionsRef} data-element=\"Actions\">\n {actions}\n </div>\n )}\n </ItemActionProvider>\n </ActionsWrapper>\n );\n }\n\n return button;\n});\n\nconst _ItemButton = Object.assign(ItemButton, {\n Action: ItemAction,\n Badge: ItemBadge,\n});\n\nexport { _ItemButton as ItemButton };\nexport type {\n CubeItemButtonProps as ItemButtonProps,\n CubeItemActionProps as ItemActionProps,\n};\n"],"mappings":";;;;;;;;;;;;;;AA6BA,MAAM,aAAa,MAAMA,OAAM;CAC7B,IAAI;CACJ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ACA,SAAS;IACT,gBAAgB,UAAU;AACxB,0BAAqB,UAAU,YAAY;;IAE7C,WAAW,YAAY;AACrB,wBAAmB,QAAQ;;eAG3B,EAAE,KAAK,oBAAoB;AAC3B,YACE,oBAAC;MACC,GAAI;MACJ,MAAM,SAAc;AAClB,kBAAW,UAAU;AACrB,qBAAc,KAAK;;MAErB,gBAAa;gBAEZ;OACG;;KAGQ,GAEpB,oBAAC;IAAI,KAAK;IAAY,gBAAa;cAChC;KACG;IAEW;GACN;AAIrB,QAAO;EACP;AAEF,MAAM,cAAc,OAAO,OAAO,YAAY;CAC5C,QAAQ;CACR,OAAO;CACR,CAAC"}
|
|
1
|
+
{"version":3,"file":"ItemButton.js","names":["Item","mergeProps"],"sources":["../../../../src/components/actions/ItemButton/ItemButton.tsx"],"sourcesContent":["import { FocusableRef, PressEvent } from '@react-types/shared';\nimport { Styles, tasty } from '@tenphi/tasty';\nimport {\n CSSProperties,\n forwardRef,\n ReactNode,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useFocusWithin, useHover } from 'react-aria';\n\nimport { useEvent } from '../../../_internal';\nimport {\n mergeProps,\n mergeRefs,\n useDismissParentPopover,\n} from '../../../utils/react';\nimport { CubeItemProps, Item } from '../../content/Item';\nimport { ItemBadge } from '../../content/ItemBadge';\nimport { DisplayTransition } from '../../helpers';\nimport { CubeItemActionProps, ItemAction } from '../ItemAction';\nimport { ItemActionProvider } from '../ItemActionContext';\nimport { CubeUseActionProps, useAction } from '../use-action';\n\nexport interface CubeItemButtonProps\n extends Omit<CubeItemProps, 'size'>,\n Omit<CubeUseActionProps, 'as'> {\n actions?: ReactNode;\n size?: Omit<CubeItemProps['size'], 'inline'>;\n wrapperStyles?: Styles;\n}\n\nconst StyledItem = tasty(Item, {\n as: 'button',\n type: 'item',\n theme: 'default',\n styles: {\n recipe: 'reset button',\n placeContent: 'center stretch',\n },\n});\n\nconst ActionsWrapper = tasty({\n styles: {\n display: 'grid',\n position: 'relative',\n placeContent: 'stretch',\n placeItems: 'stretch',\n\n $size: {\n '': '$size-md',\n 'size=xsmall': '$size-xs',\n 'size=small': '$size-sm',\n 'size=medium': '$size-md',\n 'size=large': '$size-lg',\n 'size=xlarge': '$size-xl',\n },\n\n Actions: {\n $: '>',\n position: 'absolute',\n inset: {\n '': '1bw 1bw auto auto',\n 'type=card': '(1bw + .5x) (1bw + .5x) auto auto',\n },\n display: 'flex',\n gap: '1bw',\n placeItems: 'center',\n placeContent: 'center end',\n pointerEvents: {\n '': 'auto',\n '!actions-shown': 'none',\n },\n padding: '0 $side-padding',\n height: 'min ($size - 2bw)',\n opacity: {\n '': 1,\n '!actions-shown': 0,\n },\n translate: {\n '': '0 0',\n '!actions-shown': '.5x 0',\n },\n transition: 'theme, translate',\n\n // Size for the action buttons\n '$action-size': 'min(max((2x + 2bw), ($size - 1x - 2bw)), (3x - 2bw))',\n // Side padding for the button\n '$side-padding': '(($size - $action-size - 2bw) / 2)',\n },\n },\n});\n\nconst ItemButton = forwardRef(function ItemButton(\n allProps: CubeItemButtonProps,\n ref: FocusableRef<HTMLElement>,\n) {\n const {\n mods,\n to,\n htmlType,\n as,\n type = 'item',\n theme = 'default',\n onPress,\n // Extract react-aria press callbacks to prevent them from leaking to DOM via rest.\n // These are handled by useButton inside useAction.\n onPressStart: _onPressStart,\n onPressEnd: _onPressEnd,\n onPressChange: _onPressChange,\n onPressUp: _onPressUp,\n actions,\n size = 'medium',\n wrapperStyles,\n autoHideActions = false,\n disableActionsFocus = false,\n isDisabled,\n isLoading = false,\n ...rest\n } = allProps as CubeItemButtonProps & {\n as?: 'a' | 'button' | 'div' | 'span';\n };\n\n // Loading state makes the component disabled (same logic as Item)\n const finalIsDisabled =\n isDisabled === true || (isLoading && isDisabled !== false);\n\n const actionsRef = useRef<HTMLDivElement>(null);\n const [actionsWidth, setActionsWidth] = useState(0);\n const [areActionsVisible, setAreActionsVisible] = useState(false);\n const [areActionsShown, setAreActionsShown] = useState(false);\n\n useLayoutEffect(() => {\n if (actions && actionsRef.current) {\n const width = Math.round(actionsRef.current.offsetWidth);\n if (width !== actionsWidth) {\n setActionsWidth(width);\n }\n }\n }, [actions, areActionsVisible]);\n\n const [isFocusWithin, setIsFocusWithin] = useState(false);\n const [hasPressed, setHasPressed] = useState(false);\n const { hoverProps, isHovered } = useHover({});\n const { focusWithinProps } = useFocusWithin({\n onFocusWithinChange: setIsFocusWithin,\n });\n\n // Watch for data-pressed attribute on any descendant element\n useLayoutEffect(() => {\n const actionsEl = actionsRef.current;\n\n if (!actionsEl || !autoHideActions) return;\n\n const checkPressed = () => {\n setHasPressed(actionsEl.querySelector('[data-pressed]') !== null);\n };\n\n const observer = new MutationObserver(checkPressed);\n\n observer.observe(actionsEl, {\n attributes: true,\n attributeFilter: ['data-pressed'],\n subtree: true,\n });\n\n checkPressed();\n\n return () => observer.disconnect();\n }, [areActionsVisible, autoHideActions]);\n\n const shouldShowActions =\n isHovered || isFocusWithin || hasPressed || !autoHideActions;\n\n // Default: pressing an ItemButton inside an open popover closes that\n // popover. Opt-outs: `data-popover-trigger` on self (applied by\n // FilterPicker / Picker / Select / MenuTrigger for their own triggers) and\n // `data-popover-keep` on self or any ancestor. Modals don't subscribe.\n const dismissParentPopover = useDismissParentPopover();\n const buttonElementRef = useRef<HTMLElement | null>(null);\n\n const wrappedOnPress = useEvent((e: PressEvent) => {\n onPress?.(e);\n const el = buttonElementRef.current;\n if (!el) return;\n if (el.hasAttribute('data-popover-trigger')) return;\n if (el.closest('[data-popover-keep]')) return;\n dismissParentPopover(el);\n });\n\n const { actionProps } = useAction(\n {\n ...(allProps as any),\n htmlType,\n to,\n as,\n mods,\n isDisabled: finalIsDisabled,\n onPress: wrappedOnPress,\n },\n ref,\n );\n\n const finalMods = useMemo(() => {\n return shouldShowActions ? { ...mods, 'actions-shown': true } : mods;\n }, [mods, shouldShowActions]);\n\n // Merge the useAction-supplied ref with our internal ref so the dismiss\n // wrapper can read the rendered DOM node at press time.\n const combinedRef = useMemo(\n () => mergeRefs(actionProps.ref as any, buttonElementRef),\n [actionProps.ref],\n );\n\n const button = (\n <StyledItem\n insideWrapper={!!actions}\n showActions={shouldShowActions}\n actions={actions ? true : undefined}\n {...(mergeProps(rest, actionProps) as any)}\n ref={combinedRef}\n data-popover-dismiss=\"\"\n htmlType={actionProps.type}\n type={type}\n theme={theme}\n size={size}\n isLoading={isLoading}\n isDisabled={isDisabled}\n />\n );\n\n if (actions) {\n return (\n <ActionsWrapper\n {...hoverProps}\n data-size={size}\n data-type={type}\n data-theme={theme}\n mods={finalMods}\n styles={wrapperStyles}\n style={\n {\n '--actions-width':\n areActionsVisible || !autoHideActions\n ? `${actionsWidth}px`\n : '0px',\n ...(typeof size === 'number' && { '--size': `${size}px` }),\n } as CSSProperties\n }\n >\n {button}\n <ItemActionProvider\n type={type}\n theme={theme}\n disableActionsFocus={disableActionsFocus}\n isDisabled={finalIsDisabled}\n >\n {autoHideActions ? (\n <DisplayTransition\n exposeUnmounted\n isShown={shouldShowActions}\n onPhaseChange={(phase) => {\n setAreActionsVisible(phase !== 'unmounted');\n }}\n onToggle={(isShown) => {\n setAreActionsShown(isShown);\n }}\n >\n {({ ref: transitionRef }) => {\n return (\n <div\n {...focusWithinProps}\n ref={(node: any) => {\n actionsRef.current = node;\n transitionRef(node);\n }}\n data-element=\"Actions\"\n >\n {actions}\n </div>\n );\n }}\n </DisplayTransition>\n ) : (\n <div ref={actionsRef} data-element=\"Actions\">\n {actions}\n </div>\n )}\n </ItemActionProvider>\n </ActionsWrapper>\n );\n }\n\n return button;\n});\n\nconst _ItemButton = Object.assign(ItemButton, {\n Action: ItemAction,\n Badge: ItemBadge,\n});\n\nexport { _ItemButton as ItemButton };\nexport type {\n CubeItemButtonProps as ItemButtonProps,\n CubeItemActionProps as ItemActionProps,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,MAAM,aAAa,MAAMA,OAAM;CAC7B,IAAI;CACJ,MAAM;CACN,OAAO;CACP,QAAQ;EACN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,UAAU,YAAY;EAChB;EACC;EACD;EACK;EACC;GACZ;AAGJ,KAAI,QACF,QACE,qBAAC;EACC,GAAI;EACJ,aAAW;EACX,aAAW;EACX,cAAY;EACZ,MAAM;EACN,QAAQ;EACR,OACE;GACE,mBACE,qBAAqB,CAAC,kBAClB,GAAG,aAAa,MAChB;GACN,GAAI,OAAO,SAAS,YAAY,EAAE,UAAU,GAAG,KAAK,KAAK;GAC1D;aAGF,QACD,oBAAC;GACO;GACC;GACc;GACrB,YAAY;aAEX,kBACC,oBAAC;IACC;IACA,SAAS;IACT,gBAAgB,UAAU;AACxB,0BAAqB,UAAU,YAAY;;IAE7C,WAAW,YAAY;AACrB,wBAAmB,QAAQ;;eAG3B,EAAE,KAAK,oBAAoB;AAC3B,YACE,oBAAC;MACC,GAAI;MACJ,MAAM,SAAc;AAClB,kBAAW,UAAU;AACrB,qBAAc,KAAK;;MAErB,gBAAa;gBAEZ;OACG;;KAGQ,GAEpB,oBAAC;IAAI,KAAK;IAAY,gBAAa;cAChC;KACG;IAEW;GACN;AAIrB,QAAO;EACP;AAEF,MAAM,cAAc,OAAO,OAAO,YAAY;CAC5C,QAAQ;CACR,OAAO;CACR,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.142.1 | Cube Dev Team */
|
|
2
2
|
import { extractStyles } from "../../../utils/styles.js";
|
|
3
3
|
import { mergeProps as mergeProps$1 } from "../../../utils/react/mergeProps.js";
|
|
4
4
|
import { _CollectionItem } from "../../CollectionItem.js";
|
|
@@ -12,14 +12,13 @@ import { CONTAINER_STYLES, filterBaseProps } from "@tenphi/tasty";
|
|
|
12
12
|
import React, { useMemo } from "react";
|
|
13
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { useMenu } from "react-aria";
|
|
15
|
-
import { useDOMRef } from "@react-spectrum/utils";
|
|
16
15
|
import { Section, useTreeState } from "react-stately";
|
|
17
|
-
import { useSyncRef } from "@react-aria/utils";
|
|
16
|
+
import { useObjectRef, useSyncRef } from "@react-aria/utils";
|
|
18
17
|
|
|
19
18
|
//#region src/components/actions/Menu/Menu.tsx
|
|
20
19
|
function Menu(props, ref) {
|
|
21
20
|
const { header, footer, menuStyles, headerStyles, footerStyles, itemStyles, sectionStyles, sectionHeadingStyles, size = "medium", focusOnHover = false, qa, selectedKeys, defaultSelectedKeys, onSelectionChange, ...rest } = props;
|
|
22
|
-
const domRef =
|
|
21
|
+
const domRef = useObjectRef(ref);
|
|
23
22
|
const contextProps = useMenuContext();
|
|
24
23
|
const completeProps = mergeProps$1(contextProps, rest, {
|
|
25
24
|
focusOnHover,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.js","names":["mergeProps","Section","BaseSection","CollectionItem","MenuTrigger"],"sources":["../../../../src/components/actions/Menu/Menu.tsx"],"sourcesContent":["import { useSyncRef } from '@react-aria/utils';\nimport { useDOMRef } from '@react-spectrum/utils';\nimport { DOMRef, FocusStrategy, ItemProps } from '@react-types/shared';\nimport {\n BasePropsWithoutChildren,\n CONTAINER_STYLES,\n ContainerStyleProps,\n filterBaseProps,\n Styles,\n} from '@tenphi/tasty';\nimport React, { ReactElement, ReactNode, useMemo } from 'react';\nimport { AriaMenuProps, useMenu } from 'react-aria';\nimport { Section as BaseSection, useTreeState } from 'react-stately';\n\nimport { mergeProps } from '../../../utils/react';\nimport { extractStyles } from '../../../utils/styles';\nimport { CollectionItem } from '../../CollectionItem';\n\nimport { useMenuContext } from './context';\nimport { MenuItem } from './MenuItem';\nimport { MenuSection } from './MenuSection';\nimport { MenuTrigger } from './MenuTrigger';\nimport {\n StyledDivider,\n StyledFooter,\n StyledHeader,\n StyledMenu,\n StyledMenuWrapper,\n} from './styled';\nimport { SubMenuTrigger } from './SubMenuTrigger';\n\nexport interface CubeMenuProps<T>\n extends BasePropsWithoutChildren,\n ContainerStyleProps,\n Omit<\n AriaMenuProps<T>,\n 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange'\n > {\n // @deprecated\n header?: ReactNode;\n footer?: ReactNode;\n menuStyles?: Styles;\n headerStyles?: Styles;\n footerStyles?: Styles;\n styles?: Styles;\n itemStyles?: Styles;\n sectionStyles?: Styles;\n sectionHeadingStyles?: Styles;\n /**\n * Whether keyboard navigation should wrap around when reaching the start/end of the collection.\n * This directly maps to the `shouldFocusWrap` option supported by React-Aria's `useMenu` hook.\n */\n shouldFocusWrap?: boolean;\n\n /**\n * Whether the menu should automatically receive focus when it mounts.\n * This directly maps to the `autoFocus` option supported by React-Aria's `useMenu` hook.\n */\n autoFocus?: boolean | FocusStrategy;\n shouldUseVirtualFocus?: boolean;\n\n /** Size of the menu items */\n size?: 'medium' | 'large' | (string & {});\n\n /** Currently selected keys (controlled) */\n selectedKeys?: string[];\n /** Initially selected keys (uncontrolled) */\n defaultSelectedKeys?: string[];\n /** Handler for selection changes */\n onSelectionChange?: (keys: string[]) => void;\n}\n\nfunction Menu<T extends object>(\n props: CubeMenuProps<T>,\n ref: DOMRef<HTMLUListElement>,\n) {\n const {\n header,\n footer,\n menuStyles,\n headerStyles,\n footerStyles,\n itemStyles,\n sectionStyles,\n sectionHeadingStyles,\n size = 'medium',\n focusOnHover = false,\n qa,\n selectedKeys,\n defaultSelectedKeys,\n onSelectionChange,\n ...rest\n } = props;\n const domRef = useDOMRef(ref);\n const contextProps = useMenuContext();\n\n // Convert string[] to Set<Key> for React Aria compatibility\n const ariaSelectedKeys = selectedKeys ? new Set(selectedKeys) : undefined;\n const ariaDefaultSelectedKeys = defaultSelectedKeys\n ? new Set(defaultSelectedKeys)\n : undefined;\n\n const handleSelectionChange = onSelectionChange\n ? (keys: any) => {\n if (keys === 'all') {\n // Handle 'all' selection case - collect all available keys\n const allKeys = Array.from(state.collection.getKeys()).map(\n (key: any) => String(key),\n );\n onSelectionChange(allKeys);\n } else if (keys instanceof Set) {\n onSelectionChange(Array.from(keys).map((key) => String(key)));\n } else {\n onSelectionChange([]);\n }\n }\n : undefined;\n\n const completeProps = mergeProps(contextProps, rest, {\n focusOnHover,\n selectedKeys: ariaSelectedKeys,\n defaultSelectedKeys: ariaDefaultSelectedKeys,\n onSelectionChange: handleSelectionChange,\n });\n\n // Props used for collection building.\n const treeProps = completeProps as typeof completeProps;\n\n const state = useTreeState(treeProps as typeof completeProps);\n const collectionItems = [...state.collection];\n const hasSections = collectionItems.some((item) => item.type === 'section');\n\n const { menuProps } = useMenu(completeProps, state, domRef);\n const styles = useMemo(\n () => extractStyles(completeProps, CONTAINER_STYLES),\n [completeProps],\n );\n\n const wrapperMods = useMemo(() => {\n return {\n popover: completeProps.mods?.popover,\n footer: !!footer,\n header: !!header,\n };\n }, [completeProps.mods?.popover, footer, header]);\n\n const menuMods = useMemo(() => {\n return {\n sections: hasSections,\n };\n }, [hasSections]);\n\n // Sync the ref stored in the context object with the DOM ref returned by useDOMRef.\n // The helper from @react-aria/utils expects the context object as the first argument\n // to keep it up-to-date, and a ref object as the second.\n useSyncRef(contextProps, domRef);\n\n const renderedItems = useMemo(() => {\n const items: React.ReactNode[] = [];\n let isFirstSection = true;\n\n collectionItems.forEach((item) => {\n if (item.type === 'section') {\n if (!isFirstSection) {\n items.push(\n <StyledDivider\n key={`divider-${String(item.key)}`}\n role=\"separator\"\n aria-orientation=\"horizontal\"\n />,\n );\n }\n\n items.push(\n <MenuSection\n key={item.key}\n item={item}\n state={state}\n styles={sectionStyles}\n itemStyles={itemStyles}\n headingStyles={sectionHeadingStyles}\n size={size}\n />,\n );\n\n isFirstSection = false;\n return;\n }\n\n let menuItem = (\n <MenuItem\n key={item.key}\n item={item}\n state={state}\n styles={itemStyles}\n size={size}\n onAction={item.onAction}\n />\n );\n\n // Apply tooltip wrapper if tooltip property is provided\n // if (item.props.tooltip) {\n // const tooltipProps =\n // typeof item.props.tooltip === 'string'\n // ? { title: item.props.tooltip }\n // : item.props.tooltip;\n\n // menuItem = (\n // <TooltipProvider key={item.key} placement=\"right\" {...tooltipProps}>\n // {menuItem}\n // </TooltipProvider>\n // );\n // }\n\n // Apply custom wrapper if provided\n if (item.props?.wrapper) {\n menuItem = item.props.wrapper(menuItem);\n } else if ((item as any).wrapper) {\n // Handle wrapper from collection nodes (e.g., SubMenuTrigger)\n menuItem = (item as any).wrapper(menuItem);\n }\n\n // Ensure every child has a stable key, even if the wrapper component didn't set one.\n items.push(React.cloneElement(menuItem, { key: item.key }));\n });\n\n return items;\n }, [collectionItems, state, sectionStyles, itemStyles, sectionHeadingStyles]);\n\n return (\n <StyledMenuWrapper\n qa={qa}\n styles={styles}\n mods={wrapperMods}\n {...(filterBaseProps(completeProps) as Record<string, unknown>)}\n >\n {header ? (\n <StyledHeader data-size={size} styles={headerStyles}>\n {header}\n </StyledHeader>\n ) : (\n <div role=\"presentation\" />\n )}\n <StyledMenu\n {...mergeProps(\n {\n styles: menuStyles,\n 'data-size': size,\n mods: menuMods,\n },\n menuProps,\n )}\n ref={domRef}\n role={menuProps.role ?? 'menu'}\n >\n {renderedItems}\n </StyledMenu>\n {footer ? (\n <StyledFooter data-size={size} styles={footerStyles}>\n {footer}\n </StyledFooter>\n ) : (\n <div role=\"presentation\" />\n )}\n </StyledMenuWrapper>\n );\n}\n\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\nconst _Menu = React.forwardRef(Menu) as <T>(\n props: CubeMenuProps<T> & React.RefAttributes<HTMLUListElement>,\n) => ReactElement;\n\ntype SectionComponent = typeof BaseSection;\n\nconst Section = Object.assign(BaseSection, {\n displayName: 'Section',\n}) as SectionComponent;\n\ntype __MenuComponent = typeof _Menu & {\n Item: typeof CollectionItem;\n Section: typeof Section;\n SubMenuTrigger: typeof SubMenuTrigger;\n Trigger: typeof MenuTrigger;\n};\n\nconst __Menu = Object.assign(_Menu as __MenuComponent, {\n Item: CollectionItem,\n Section,\n SubMenuTrigger,\n Trigger: MenuTr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,SAASC;CACT,aAAa;CACd,CAAC;AAEF,OAAO,cAAc"}
|
|
1
|
+
{"version":3,"file":"Menu.js","names":["mergeProps","Section","BaseSection","CollectionItem","MenuTrigger"],"sources":["../../../../src/components/actions/Menu/Menu.tsx"],"sourcesContent":["import { useObjectRef, useSyncRef } from '@react-aria/utils';\nimport { FocusStrategy, ItemProps } from '@react-types/shared';\nimport {\n BasePropsWithoutChildren,\n CONTAINER_STYLES,\n ContainerStyleProps,\n filterBaseProps,\n Styles,\n} from '@tenphi/tasty';\nimport React, { ReactElement, ReactNode, Ref, useMemo } from 'react';\nimport { AriaMenuProps, useMenu } from 'react-aria';\nimport { Section as BaseSection, useTreeState } from 'react-stately';\n\nimport { mergeProps } from '../../../utils/react';\nimport { extractStyles } from '../../../utils/styles';\nimport { CollectionItem } from '../../CollectionItem';\n\nimport { useMenuContext } from './context';\nimport { MenuItem } from './MenuItem';\nimport { MenuSection } from './MenuSection';\nimport { MenuTrigger } from './MenuTrigger';\nimport {\n StyledDivider,\n StyledFooter,\n StyledHeader,\n StyledMenu,\n StyledMenuWrapper,\n} from './styled';\nimport { SubMenuTrigger } from './SubMenuTrigger';\n\nexport interface CubeMenuProps<T>\n extends BasePropsWithoutChildren,\n ContainerStyleProps,\n Omit<\n AriaMenuProps<T>,\n 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange'\n > {\n // @deprecated\n header?: ReactNode;\n footer?: ReactNode;\n menuStyles?: Styles;\n headerStyles?: Styles;\n footerStyles?: Styles;\n styles?: Styles;\n itemStyles?: Styles;\n sectionStyles?: Styles;\n sectionHeadingStyles?: Styles;\n /**\n * Whether keyboard navigation should wrap around when reaching the start/end of the collection.\n * This directly maps to the `shouldFocusWrap` option supported by React-Aria's `useMenu` hook.\n */\n shouldFocusWrap?: boolean;\n\n /**\n * Whether the menu should automatically receive focus when it mounts.\n * This directly maps to the `autoFocus` option supported by React-Aria's `useMenu` hook.\n */\n autoFocus?: boolean | FocusStrategy;\n shouldUseVirtualFocus?: boolean;\n\n /** Size of the menu items */\n size?: 'medium' | 'large' | (string & {});\n\n /** Currently selected keys (controlled) */\n selectedKeys?: string[];\n /** Initially selected keys (uncontrolled) */\n defaultSelectedKeys?: string[];\n /** Handler for selection changes */\n onSelectionChange?: (keys: string[]) => void;\n}\n\nfunction Menu<T extends object>(\n props: CubeMenuProps<T>,\n ref: Ref<HTMLUListElement>,\n) {\n const {\n header,\n footer,\n menuStyles,\n headerStyles,\n footerStyles,\n itemStyles,\n sectionStyles,\n sectionHeadingStyles,\n size = 'medium',\n focusOnHover = false,\n qa,\n selectedKeys,\n defaultSelectedKeys,\n onSelectionChange,\n ...rest\n } = props;\n const domRef = useObjectRef(ref);\n const contextProps = useMenuContext();\n\n // Convert string[] to Set<Key> for React Aria compatibility\n const ariaSelectedKeys = selectedKeys ? new Set(selectedKeys) : undefined;\n const ariaDefaultSelectedKeys = defaultSelectedKeys\n ? new Set(defaultSelectedKeys)\n : undefined;\n\n const handleSelectionChange = onSelectionChange\n ? (keys: any) => {\n if (keys === 'all') {\n // Handle 'all' selection case - collect all available keys\n const allKeys = Array.from(state.collection.getKeys()).map(\n (key: any) => String(key),\n );\n onSelectionChange(allKeys);\n } else if (keys instanceof Set) {\n onSelectionChange(Array.from(keys).map((key) => String(key)));\n } else {\n onSelectionChange([]);\n }\n }\n : undefined;\n\n const completeProps = mergeProps(contextProps, rest, {\n focusOnHover,\n selectedKeys: ariaSelectedKeys,\n defaultSelectedKeys: ariaDefaultSelectedKeys,\n onSelectionChange: handleSelectionChange,\n });\n\n // Props used for collection building.\n const treeProps = completeProps as typeof completeProps;\n\n const state = useTreeState(treeProps as typeof completeProps);\n const collectionItems = [...state.collection];\n const hasSections = collectionItems.some((item) => item.type === 'section');\n\n const { menuProps } = useMenu(completeProps, state, domRef);\n const styles = useMemo(\n () => extractStyles(completeProps, CONTAINER_STYLES),\n [completeProps],\n );\n\n const wrapperMods = useMemo(() => {\n return {\n popover: completeProps.mods?.popover,\n footer: !!footer,\n header: !!header,\n };\n }, [completeProps.mods?.popover, footer, header]);\n\n const menuMods = useMemo(() => {\n return {\n sections: hasSections,\n };\n }, [hasSections]);\n\n // Sync the ref stored in the context object with the menu's DOM ref.\n // `useSyncRef` from @react-aria/utils expects the context object as the\n // first argument to keep it up-to-date, and a ref object as the second.\n useSyncRef(contextProps, domRef);\n\n const renderedItems = useMemo(() => {\n const items: React.ReactNode[] = [];\n let isFirstSection = true;\n\n collectionItems.forEach((item) => {\n if (item.type === 'section') {\n if (!isFirstSection) {\n items.push(\n <StyledDivider\n key={`divider-${String(item.key)}`}\n role=\"separator\"\n aria-orientation=\"horizontal\"\n />,\n );\n }\n\n items.push(\n <MenuSection\n key={item.key}\n item={item}\n state={state}\n styles={sectionStyles}\n itemStyles={itemStyles}\n headingStyles={sectionHeadingStyles}\n size={size}\n />,\n );\n\n isFirstSection = false;\n return;\n }\n\n let menuItem = (\n <MenuItem\n key={item.key}\n item={item}\n state={state}\n styles={itemStyles}\n size={size}\n onAction={item.onAction}\n />\n );\n\n // Apply tooltip wrapper if tooltip property is provided\n // if (item.props.tooltip) {\n // const tooltipProps =\n // typeof item.props.tooltip === 'string'\n // ? { title: item.props.tooltip }\n // : item.props.tooltip;\n\n // menuItem = (\n // <TooltipProvider key={item.key} placement=\"right\" {...tooltipProps}>\n // {menuItem}\n // </TooltipProvider>\n // );\n // }\n\n // Apply custom wrapper if provided\n if (item.props?.wrapper) {\n menuItem = item.props.wrapper(menuItem);\n } else if ((item as any).wrapper) {\n // Handle wrapper from collection nodes (e.g., SubMenuTrigger)\n menuItem = (item as any).wrapper(menuItem);\n }\n\n // Ensure every child has a stable key, even if the wrapper component didn't set one.\n items.push(React.cloneElement(menuItem, { key: item.key }));\n });\n\n return items;\n }, [collectionItems, state, sectionStyles, itemStyles, sectionHeadingStyles]);\n\n return (\n <StyledMenuWrapper\n qa={qa}\n styles={styles}\n mods={wrapperMods}\n {...(filterBaseProps(completeProps) as Record<string, unknown>)}\n >\n {header ? (\n <StyledHeader data-size={size} styles={headerStyles}>\n {header}\n </StyledHeader>\n ) : (\n <div role=\"presentation\" />\n )}\n <StyledMenu\n {...mergeProps(\n {\n styles: menuStyles,\n 'data-size': size,\n mods: menuMods,\n },\n menuProps,\n )}\n ref={domRef}\n role={menuProps.role ?? 'menu'}\n >\n {renderedItems}\n </StyledMenu>\n {footer ? (\n <StyledFooter data-size={size} styles={footerStyles}>\n {footer}\n </StyledFooter>\n ) : (\n <div role=\"presentation\" />\n )}\n </StyledMenuWrapper>\n );\n}\n\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\nconst _Menu = React.forwardRef(Menu) as <T>(\n props: CubeMenuProps<T> & React.RefAttributes<HTMLUListElement>,\n) => ReactElement;\n\ntype SectionComponent = typeof BaseSection;\n\nconst Section = Object.assign(BaseSection, {\n displayName: 'Section',\n}) as SectionComponent;\n\ntype __MenuComponent = typeof _Menu & {\n Item: typeof CollectionItem;\n Section: typeof Section;\n SubMenuTrigger: typeof SubMenuTrigger;\n Trigger: typeof MenuTrigger;\n};\n\nconst __Menu = Object.assign(_Menu as __MenuComponent, {\n Item: CollectionItem,\n Section,\n SubMenuTrigger,\n Trigger: MenuTrigger,\n displayName: 'Menu',\n});\n\n__Menu.displayName = 'Menu';\n\nexport { __Menu as Menu };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuEA,SAAS,KACP,OACA,KACA;CACA,MAAM,EACJ,QACA,QACA,YACA,cACA,cACA,YACA,eACA,sBACA,OAAO,UACP,eAAe,OACf,IACA,cACA,qBACA,mBACA,GAAG,SACD;CACJ,MAAM,SAAS,aAAa,IAAI;CAChC,MAAM,eAAe,gBAAgB;CAwBrC,MAAM,gBAAgBA,aAAW,cAAc,MAAM;EACnD;EACA,cAvBuB,eAAe,IAAI,IAAI,aAAa,GAAG;EAwB9D,qBAvB8B,sBAC5B,IAAI,IAAI,oBAAoB,GAC5B;EAsBF,mBApB4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AI,KAAK,OAAO,QACd,YAAW,KAAK,MAAM,QAAQ,SAAS;YAC7B,KAAa,QAEvB,YAAY,KAAa,QAAQ,SAAS;AAI5C,SAAM,KAAK,MAAM,aAAa,UAAU,EAAE,KAAK,KAAK,KAAK,CAAC,CAAC;IAC3D;AAEF,SAAO;IACN;EAAC;EAAiB;EAAO;EAAe;EAAY;EAAqB,CAAC;AAE7E,QACE,qBAAC;EACK;EACI;EACR,MAAM;EACN,GAAK,gBAAgB,cAAc;;GAElC,SACC,oBAAC;IAAa,aAAW;IAAM,QAAQ;cACpC;KACY,GAEf,oBAAC,SAAI,MAAK,iBAAiB;GAE7B,oBAAC;IACC,GAAIA,aACF;KACE,QAAQ;KACR,aAAa;KACb,MAAM;KACP,EACD,UACD;IACD,KAAK;IACL,MAAM,UAAU,QAAQ;cAEvB;KACU;GACZ,SACC,oBAAC;IAAa,aAAW;IAAM,QAAQ;cACpC;KACY,GAEf,oBAAC,SAAI,MAAK,iBAAiB;;GAEX;;AAMxB,MAAM,QAAQ,MAAM,WAAW,KAAK;AAMpC,MAAMC,YAAU,OAAO,OAAOC,SAAa,EACzC,aAAa,WACd,CAAC;AASF,MAAM,SAAS,OAAO,OAAO,OAA0B;CACrD,MAAMC;CACN;CACA;CACA,SAASC;CACT,aAAa;CACd,CAAC;AAEF,OAAO,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.142.1 | Cube Dev Team */
|
|
2
2
|
import { mergeProps as mergeProps$1 } from "../../../utils/react/mergeProps.js";
|
|
3
3
|
import { filterCollectionItemProps } from "../../CollectionItem.js";
|
|
4
4
|
import { _Item } from "../../content/Item/Item.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.142.1 | Cube Dev Team */
|
|
2
2
|
import { TooltipProvider } from "../../overlays/Tooltip/TooltipProvider.js";
|
|
3
3
|
import { MenuItem } from "./MenuItem.js";
|
|
4
4
|
import { StyledMenu, StyledSection, StyledSectionHeading } from "./styled.js";
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.142.1 | Cube Dev Team */
|
|
2
2
|
import { SlotProvider } from "../../../utils/react/Slots.js";
|
|
3
|
+
import { usePopoverSync } from "../../../utils/react/usePopoverSync.js";
|
|
3
4
|
import { useEvent } from "../../../_internal/hooks/use-event.js";
|
|
4
5
|
import { MenuContext } from "./context.js";
|
|
5
6
|
import { generateRandomId } from "../../../utils/random.js";
|
|
6
|
-
import { usePopoverSync } from "../../../utils/react/usePopoverSync.js";
|
|
7
7
|
import { _Tray } from "../../overlays/Modal/Tray.js";
|
|
8
8
|
import { _Popover } from "../../overlays/Modal/Popover.js";
|
|
9
9
|
import { Fragment, forwardRef, useEffect, useMemo, useRef } from "react";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { DismissButton, FocusScope, useMenuTrigger, useOverlayPosition } from "react-aria";
|
|
12
|
-
import {
|
|
12
|
+
import { useIsMobileDevice } from "@react-spectrum/utils";
|
|
13
13
|
import { useMenuTriggerState } from "react-stately";
|
|
14
|
+
import { useObjectRef } from "@react-aria/utils";
|
|
14
15
|
import { PressResponder } from "@react-aria/interactions";
|
|
15
16
|
|
|
16
17
|
//#region src/components/actions/Menu/MenuTrigger.tsx
|
|
17
18
|
function MenuTrigger(props, ref) {
|
|
18
19
|
const menuPopoverRef = useRef(null);
|
|
19
20
|
const triggerRef = useRef(null);
|
|
20
|
-
const domRef =
|
|
21
|
+
const domRef = useObjectRef(ref);
|
|
21
22
|
const menuTriggerRef = props.targetRef || domRef || triggerRef;
|
|
22
23
|
const menuRef = useRef(null);
|
|
23
24
|
const wasOpenRef = useRef(false);
|
|
@@ -30,7 +31,9 @@ function MenuTrigger(props, ref) {
|
|
|
30
31
|
menuId,
|
|
31
32
|
isOpen: state.isOpen,
|
|
32
33
|
onClose: () => state.close(),
|
|
33
|
-
enabled: !isDummy
|
|
34
|
+
enabled: !isDummy,
|
|
35
|
+
triggerRef: menuTriggerRef,
|
|
36
|
+
containerRef: menuPopoverRef
|
|
34
37
|
});
|
|
35
38
|
useEffect(() => {
|
|
36
39
|
if (!state.isOpen && wasOpenRef.current && !isDummy) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuTrigger.js","names":["Tray","Popover"],"sources":["../../../../src/components/actions/Menu/MenuTrigger.tsx"],"sourcesContent":["import { PressResponder } from '@react-aria/interactions';\nimport { useDOMRef, useIsMobileDevice } from '@react-spectrum/utils';\nimport { DOMRef } from '@react-types/shared';\nimport {\n forwardRef,\n Fragment,\n ReactElement,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport {\n AriaMenuTriggerProps,\n DismissButton,\n FocusScope,\n Placement,\n PositionProps,\n useMenuTrigger,\n useOverlayPosition,\n} from 'react-aria';\nimport { MenuTriggerState, useMenuTriggerState } from 'react-stately';\n\nimport { useEvent } from '../../../_internal';\nimport { generateRandomId } from '../../../utils/random';\nimport { SlotProvider } from '../../../utils/react';\nimport { usePopoverSync } from '../../../utils/react/usePopoverSync';\nimport { Popover, Tray } from '../../overlays/Modal';\n\nimport { MenuContext, MenuContextValue } from './context';\n\nexport type { AriaMenuTriggerProps };\n\nexport type CubeMenuTriggerProps = AriaMenuTriggerProps &\n PositionProps & {\n isDisabled?: boolean;\n children: [\n ReactElement | ((state: MenuTriggerState) => ReactElement),\n ReactElement,\n ];\n\n closeOnSelect?: boolean;\n isDummy?: boolean;\n /**\n * Overlay variant to use on mobile screens. Defaults to `'popover'`, which\n * keeps the desktop overlay even on small viewports. Pass `'tray'` to opt\n * into the bottom-sheet `Tray` overlay on mobile (the previous implicit\n * default). Mirrors the `mobileType` API on `DialogTrigger`.\n */\n mobileType?: 'popover' | 'tray';\n };\n\nfunction MenuTrigger(props: CubeMenuTriggerProps, ref: DOMRef<HTMLElement>) {\n const menuPopoverRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLElement>(null);\n const domRef = useDOMRef(ref);\n const menuTriggerRef = props.targetRef || domRef || triggerRef;\n const menuRef = useRef<HTMLUListElement>(null);\n const wasOpenRef = useRef(false);\n const {\n children,\n shouldFlip = true,\n closeOnSelect,\n trigger = 'press',\n isDisabled,\n isDummy,\n mobileType = 'popover',\n } = props;\n\n // Generate a unique ID for this menu instance\n const menuId = useMemo(() => generateRandomId(), []);\n\n if (!Array.isArray(children) || children.length > 2) {\n throw new Error('MenuTrigger must have exactly 2 children');\n }\n\n let [menuTrigger, menu] = children;\n const state: MenuTriggerState = useMenuTriggerState(props);\n\n usePopoverSync({\n menuId,\n isOpen: state.isOpen,\n onClose: () => state.close(),\n enabled: !isDummy,\n });\n\n // Restore focus manually when the menu closes\n useEffect(() => {\n if (!state.isOpen && wasOpenRef.current && !isDummy) {\n wasOpenRef.current = false;\n // Use setTimeout to ensure focus restoration happens after any animations\n setTimeout(() => {\n menuTriggerRef.current?.focus();\n }, 0);\n } else if (state.isOpen) {\n wasOpenRef.current = true;\n }\n }, [state.isOpen, menuTriggerRef, isDummy]);\n\n if (typeof menuTrigger === 'function') {\n menuTrigger = (menuTrigger as CubeMenuTriggerProps['children'][0])(state);\n }\n\n const { menuTriggerProps, menuProps } = useMenuTrigger(\n { isDisabled },\n state,\n menuTriggerRef,\n );\n\n let initialPlacement: Placement = props.placement ?? 'bottom start';\n\n // Tray rendering is now opt-in via `mobileType=\"tray\"` (matches DialogTrigger).\n // Without that opt-in, MenuTrigger always renders a Popover so that environments\n // like jsdom (where `window.screen.width === 0` makes useIsMobileDevice() true)\n // don't accidentally swap in the tray overlay.\n const isMobileDevice = useIsMobileDevice();\n const isTray = mobileType === 'tray' && isMobileDevice;\n const { overlayProps: positionProps, placement } = useOverlayPosition({\n targetRef: menuTriggerRef,\n overlayRef: menuPopoverRef,\n scrollRef: menuRef,\n placement: initialPlacement,\n shouldFlip: shouldFlip,\n isOpen: state.isOpen && !isTray,\n onClose: state.close,\n containerPadding: props.containerPadding,\n offset: props.offset ?? 8,\n crossOffset: props.crossOffset ?? 0,\n });\n\n const menuContext = {\n ...menuProps,\n ref: menuRef,\n onClose: state.close,\n closeOnSelect,\n autoFocus: (state.focusStrategy as any) ?? 'first',\n style: isTray\n ? {\n width: '100%',\n maxHeight: 'inherit',\n }\n : undefined,\n mods: {\n popover: !isTray,\n tray: isTray,\n },\n isClosing: !state.isOpen,\n } as MenuContextValue;\n\n // Wrap in a FocusScope so the menu popover registers as a child of any\n // outer contained FocusScope (e.g. a parent Dialog/Popover). Without this,\n // when the menu opens inside an outer contained FocusScope, the outer\n // scope rejects focus moving into the menu items (which live in a portal\n // and would otherwise belong to no scope) and yanks focus back to the\n // menu trigger.\n const contents = (\n <FocusScope restoreFocus>\n <DismissButton onDismiss={state.close} />\n {menu}\n <DismissButton onDismiss={state.close} />\n </FocusScope>\n );\n\n // Shared between the Popover and Tray branches so both react-aria\n // `useOverlay` calls see the same predicate. Without this, the Tray branch\n // falls back to unconditional dismiss-on-outside-interaction, which\n // `useOverlay` translates into stopPropagation/preventDefault in the\n // capture phase — that swallows clicks on sibling triggers (see Menu\n // rapid-open test).\n //\n // `useEvent` gives us a single stable callback reference for the lifetime\n // of the component while always reading the latest closure values. This\n // matters because `useMenuTriggerState` returns a fresh `state` object on\n // every render, so a vanilla `useCallback([..., state])` would produce a\n // new function every render and defeat any stability guarantees consumers\n // rely on.\n const shouldCloseOnInteractOutside = useEvent((el: Element) => {\n // While `Popover` is animating out, `useInteractOutside`'s capture-phase\n // listener is still attached (jsdom 29+ uses pointerdown/click capture).\n // The animation lasts ~350ms; without this guard, clicks on a sibling\n // trigger during the exit window get stopPropagation()'d and the\n // sibling's `onClick` never runs — breaking rapid-open and \"open menu\n // again with new props\" flows. Reading `state.isOpen` directly is safe\n // because `useEvent` always sees the latest closure.\n if (!state.isOpen) return false;\n\n const menuTriggerEl = el.closest('[data-popover-trigger]');\n if (!menuTriggerEl) {\n // Plain interactive controls (Button, ItemButton) opt in via\n // `data-popover-dismiss`. We schedule the close via setTimeout(0) so\n // it lands AFTER the click event finishes — the button's onPress\n // fires first, then the popover closes. Without this, useOverlay\n // would stopPropagation() the click and the user would need a second\n // click to actually press the button.\n if (el.closest('[data-popover-dismiss]')) {\n setTimeout(() => state.close(), 0);\n return false;\n }\n return true;\n }\n if (\n isDummy &&\n (menuTriggerEl === menuTriggerRef.current ||\n menuTriggerRef.current?.contains(el))\n ) {\n return true;\n }\n if (menuTriggerEl === menuTriggerRef.current) return true;\n return false;\n });\n\n let overlay;\n if (isTray) {\n overlay = (\n <Tray\n isOpen={state.isOpen}\n shouldCloseOnInteractOutside={shouldCloseOnInteractOutside}\n onClose={state.close}\n >\n {contents}\n </Tray>\n );\n } else {\n overlay = (\n <Popover\n ref={menuPopoverRef}\n hideArrow\n isNonModal\n isOpen={state.isOpen}\n style={positionProps.style}\n placement={placement}\n shouldCloseOnInteractOutside={shouldCloseOnInteractOutside}\n onClose={state.close}\n >\n {contents}\n </Popover>\n );\n }\n\n return (\n <Fragment>\n <SlotProvider\n slots={{ actionButton: { holdAffordance: trigger === 'longPress' } }}\n >\n {!isDummy ? (\n <PressResponder\n {...menuTriggerProps}\n ref={menuTriggerRef}\n data-popover-trigger\n isPressed={state.isOpen}\n >\n {menuTrigger}\n </PressResponder>\n ) : null}\n </SlotProvider>\n <MenuContext.Provider value={menuContext}>{overlay}</MenuContext.Provider>\n </Fragment>\n );\n}\n\n/**\n * The MenuTrigger serves as a wrapper around a Menu and its associated trigger,\n * linking the Menu's open state with the trigger's press state.\n */\nlet _MenuTrigger = forwardRef(MenuTrigger);\n\n_MenuTrigger.displayName = 'MenuTrigger';\n\nexport { _MenuTrigger as MenuTrigger };\n"],"mappings":";;;;;;;;;;;;;;;;AAmDA,SAAS,YAAY,OAA6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names":["Tray","Popover"],"sources":["../../../../src/components/actions/Menu/MenuTrigger.tsx"],"sourcesContent":["import { PressResponder } from '@react-aria/interactions';\nimport { useObjectRef } from '@react-aria/utils';\nimport { useIsMobileDevice } from '@react-spectrum/utils';\nimport {\n forwardRef,\n Fragment,\n ReactElement,\n Ref,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport {\n AriaMenuTriggerProps,\n DismissButton,\n FocusScope,\n Placement,\n PositionProps,\n useMenuTrigger,\n useOverlayPosition,\n} from 'react-aria';\nimport { MenuTriggerState, useMenuTriggerState } from 'react-stately';\n\nimport { useEvent } from '../../../_internal';\nimport { generateRandomId } from '../../../utils/random';\nimport { SlotProvider } from '../../../utils/react';\nimport { usePopoverSync } from '../../../utils/react/usePopoverSync';\nimport { Popover, Tray } from '../../overlays/Modal';\n\nimport { MenuContext, MenuContextValue } from './context';\n\nexport type { AriaMenuTriggerProps };\n\nexport type CubeMenuTriggerProps = AriaMenuTriggerProps &\n PositionProps & {\n isDisabled?: boolean;\n children: [\n ReactElement | ((state: MenuTriggerState) => ReactElement),\n ReactElement,\n ];\n\n closeOnSelect?: boolean;\n isDummy?: boolean;\n /**\n * Overlay variant to use on mobile screens. Defaults to `'popover'`, which\n * keeps the desktop overlay even on small viewports. Pass `'tray'` to opt\n * into the bottom-sheet `Tray` overlay on mobile (the previous implicit\n * default). Mirrors the `mobileType` API on `DialogTrigger`.\n */\n mobileType?: 'popover' | 'tray';\n };\n\nfunction MenuTrigger(props: CubeMenuTriggerProps, ref: Ref<HTMLElement>) {\n const menuPopoverRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLElement>(null);\n const domRef = useObjectRef(ref);\n const menuTriggerRef = props.targetRef || domRef || triggerRef;\n const menuRef = useRef<HTMLUListElement>(null);\n const wasOpenRef = useRef(false);\n const {\n children,\n shouldFlip = true,\n closeOnSelect,\n trigger = 'press',\n isDisabled,\n isDummy,\n mobileType = 'popover',\n } = props;\n\n // Generate a unique ID for this menu instance\n const menuId = useMemo(() => generateRandomId(), []);\n\n if (!Array.isArray(children) || children.length > 2) {\n throw new Error('MenuTrigger must have exactly 2 children');\n }\n\n let [menuTrigger, menu] = children;\n const state: MenuTriggerState = useMenuTriggerState(props);\n\n usePopoverSync({\n menuId,\n isOpen: state.isOpen,\n onClose: () => state.close(),\n enabled: !isDummy,\n triggerRef: menuTriggerRef,\n containerRef: menuPopoverRef,\n });\n\n // Restore focus manually when the menu closes\n useEffect(() => {\n if (!state.isOpen && wasOpenRef.current && !isDummy) {\n wasOpenRef.current = false;\n // Use setTimeout to ensure focus restoration happens after any animations\n setTimeout(() => {\n menuTriggerRef.current?.focus();\n }, 0);\n } else if (state.isOpen) {\n wasOpenRef.current = true;\n }\n }, [state.isOpen, menuTriggerRef, isDummy]);\n\n if (typeof menuTrigger === 'function') {\n menuTrigger = (menuTrigger as CubeMenuTriggerProps['children'][0])(state);\n }\n\n const { menuTriggerProps, menuProps } = useMenuTrigger(\n { isDisabled },\n state,\n menuTriggerRef,\n );\n\n let initialPlacement: Placement = props.placement ?? 'bottom start';\n\n // Tray rendering is now opt-in via `mobileType=\"tray\"` (matches DialogTrigger).\n // Without that opt-in, MenuTrigger always renders a Popover so that environments\n // like jsdom (where `window.screen.width === 0` makes useIsMobileDevice() true)\n // don't accidentally swap in the tray overlay.\n const isMobileDevice = useIsMobileDevice();\n const isTray = mobileType === 'tray' && isMobileDevice;\n const { overlayProps: positionProps, placement } = useOverlayPosition({\n targetRef: menuTriggerRef,\n overlayRef: menuPopoverRef,\n scrollRef: menuRef,\n placement: initialPlacement,\n shouldFlip: shouldFlip,\n isOpen: state.isOpen && !isTray,\n onClose: state.close,\n containerPadding: props.containerPadding,\n offset: props.offset ?? 8,\n crossOffset: props.crossOffset ?? 0,\n });\n\n const menuContext = {\n ...menuProps,\n ref: menuRef,\n onClose: state.close,\n closeOnSelect,\n autoFocus: (state.focusStrategy as any) ?? 'first',\n style: isTray\n ? {\n width: '100%',\n maxHeight: 'inherit',\n }\n : undefined,\n mods: {\n popover: !isTray,\n tray: isTray,\n },\n isClosing: !state.isOpen,\n } as MenuContextValue;\n\n // Wrap in a FocusScope so the menu popover registers as a child of any\n // outer contained FocusScope (e.g. a parent Dialog/Popover). Without this,\n // when the menu opens inside an outer contained FocusScope, the outer\n // scope rejects focus moving into the menu items (which live in a portal\n // and would otherwise belong to no scope) and yanks focus back to the\n // menu trigger.\n const contents = (\n <FocusScope restoreFocus>\n <DismissButton onDismiss={state.close} />\n {menu}\n <DismissButton onDismiss={state.close} />\n </FocusScope>\n );\n\n // Shared between the Popover and Tray branches so both react-aria\n // `useOverlay` calls see the same predicate. Without this, the Tray branch\n // falls back to unconditional dismiss-on-outside-interaction, which\n // `useOverlay` translates into stopPropagation/preventDefault in the\n // capture phase — that swallows clicks on sibling triggers (see Menu\n // rapid-open test).\n //\n // `useEvent` gives us a single stable callback reference for the lifetime\n // of the component while always reading the latest closure values. This\n // matters because `useMenuTriggerState` returns a fresh `state` object on\n // every render, so a vanilla `useCallback([..., state])` would produce a\n // new function every render and defeat any stability guarantees consumers\n // rely on.\n const shouldCloseOnInteractOutside = useEvent((el: Element) => {\n // While `Popover` is animating out, `useInteractOutside`'s capture-phase\n // listener is still attached (jsdom 29+ uses pointerdown/click capture).\n // The animation lasts ~350ms; without this guard, clicks on a sibling\n // trigger during the exit window get stopPropagation()'d and the\n // sibling's `onClick` never runs — breaking rapid-open and \"open menu\n // again with new props\" flows. Reading `state.isOpen` directly is safe\n // because `useEvent` always sees the latest closure.\n if (!state.isOpen) return false;\n\n const menuTriggerEl = el.closest('[data-popover-trigger]');\n if (!menuTriggerEl) {\n // Plain interactive controls (Button, ItemButton) opt in via\n // `data-popover-dismiss`. We schedule the close via setTimeout(0) so\n // it lands AFTER the click event finishes — the button's onPress\n // fires first, then the popover closes. Without this, useOverlay\n // would stopPropagation() the click and the user would need a second\n // click to actually press the button.\n if (el.closest('[data-popover-dismiss]')) {\n setTimeout(() => state.close(), 0);\n return false;\n }\n return true;\n }\n if (\n isDummy &&\n (menuTriggerEl === menuTriggerRef.current ||\n menuTriggerRef.current?.contains(el))\n ) {\n return true;\n }\n if (menuTriggerEl === menuTriggerRef.current) return true;\n return false;\n });\n\n let overlay;\n if (isTray) {\n overlay = (\n <Tray\n isOpen={state.isOpen}\n shouldCloseOnInteractOutside={shouldCloseOnInteractOutside}\n onClose={state.close}\n >\n {contents}\n </Tray>\n );\n } else {\n overlay = (\n <Popover\n ref={menuPopoverRef}\n hideArrow\n isNonModal\n isOpen={state.isOpen}\n style={positionProps.style}\n placement={placement}\n shouldCloseOnInteractOutside={shouldCloseOnInteractOutside}\n onClose={state.close}\n >\n {contents}\n </Popover>\n );\n }\n\n return (\n <Fragment>\n <SlotProvider\n slots={{ actionButton: { holdAffordance: trigger === 'longPress' } }}\n >\n {!isDummy ? (\n <PressResponder\n {...menuTriggerProps}\n ref={menuTriggerRef}\n data-popover-trigger\n isPressed={state.isOpen}\n >\n {menuTrigger}\n </PressResponder>\n ) : null}\n </SlotProvider>\n <MenuContext.Provider value={menuContext}>{overlay}</MenuContext.Provider>\n </Fragment>\n );\n}\n\n/**\n * The MenuTrigger serves as a wrapper around a Menu and its associated trigger,\n * linking the Menu's open state with the trigger's press state.\n */\nlet _MenuTrigger = forwardRef(MenuTrigger);\n\n_MenuTrigger.displayName = 'MenuTrigger';\n\nexport { _MenuTrigger as MenuTrigger };\n"],"mappings":";;;;;;;;;;;;;;;;;AAoDA,SAAS,YAAY,OAA6B,KAAuB;CACvE,MAAM,iBAAiB,OAAuB,KAAK;CACnD,MAAM,aAAa,OAAoB,KAAK;CAC5C,MAAM,SAAS,aAAa,IAAI;CAChC,MAAM,iBAAiB,MAAM,aAAa,UAAU;CACpD,MAAM,UAAU,OAAyB,KAAK;CAC9C,MAAM,aAAa,OAAO,MAAM;CAChC,MAAM,EACJ,UACA,aAAa,MACb,eACA,UAAU,SACV,YACA,SACA,aAAa,cACX;CAGJ,MAAM,SAAS,cAAc,kBAAkB,EAAE,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BAAc,WAAW,MAAM,QAAS;;GAC9B;CAgBf,MAAM,+BAA+B,UAAU,OAAgB;AAQ7D,MAAI,CAAC,MAAM,OAAQ,QAAO;EAE1B,MAAM,gBAAgB,GAAG,QAAQ,yBAAyB;AAC1D,MAAI,CAAC,eAAe;AAOlB,OAAI,GAAG,QAAQ,yBAAyB,EAAE;AACxC,qBAAiB,MAAM,OAAO,EAAE,EAAE;AAClC,WAAO;;AAET,UAAO;;AAET,MACE,YACC,kBAAkB,eAAe,WAChC,eAAe,SAAS,SAAS,GAAG,EAEtC,QAAO;AAET,MAAI,kBAAkB,eAAe,QAAS,QAAO;AACrD,SAAO;GACP;CAEF,IAAI;AACJ,KAAI,OACF,WACE,oBAACA;EACC,QAAQ,MAAM;EACgB;EAC9B,SAAS,MAAM;YAEd;GACI;KAGT,WACE,oBAACC;EACC,KAAK;EACL;EACA;EACA,QAAQ,MAAM;EACd,OAAO,cAAc;EACV;EACmB;EAC9B,SAAS,MAAM;YAEd;GACO;AAId,QACE,qBAAC,uBACC,oBAAC;EACC,OAAO,EAAE,cAAc,EAAE,gBAAgB,YAAY,aAAa,EAAE;YAEnE,CAAC,UACA,oBAAC;GACC,GAAI;GACJ,KAAK;GACL;GACA,WAAW,MAAM;aAEhB;IACc,GACf;GACS,EACf,oBAAC,YAAY;EAAS,OAAO;YAAc;GAA+B,IACjE;;;;;;AAQf,IAAI,eAAe,WAAW,YAAY;AAE1C,aAAa,cAAc"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.142.1 | Cube Dev Team */
|
|
2
|
+
import { usePopoverSync } from "../../../utils/react/usePopoverSync.js";
|
|
2
3
|
import { useEvent } from "../../../_internal/hooks/use-event.js";
|
|
3
4
|
import { MenuContext, useMenuContext } from "./context.js";
|
|
4
5
|
import { SubmenuTriggerContext } from "./SubmenuTriggerContext.js";
|
|
5
6
|
import { generateRandomId } from "../../../utils/random.js";
|
|
6
|
-
import { usePopoverSync } from "../../../utils/react/usePopoverSync.js";
|
|
7
7
|
import { _Popover } from "../../overlays/Modal/Popover.js";
|
|
8
8
|
import React, { useEffect, useMemo, useRef } from "react";
|
|
9
9
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -23,14 +23,17 @@ function InternalSubMenuTrigger(props) {
|
|
|
23
23
|
const { children, placement = DEFAULT_PLACEMENT, offset = DEFAULT_OFFSET, crossOffset = DEFAULT_CROSS_OFFSET, shouldFlip = true, isDisabled, autoFocus = "first", onAction, targetKey, ...overlayProps } = props;
|
|
24
24
|
const [menuTrigger, menu] = React.Children.toArray(children);
|
|
25
25
|
const state = useMenuTriggerState(props);
|
|
26
|
-
|
|
27
|
-
menuId: useMemo(() => generateRandomId(), []),
|
|
28
|
-
isOpen: state.isOpen,
|
|
29
|
-
onClose: () => state.close()
|
|
30
|
-
});
|
|
26
|
+
const submenuId = useMemo(() => generateRandomId(), []);
|
|
31
27
|
const domTriggerRef = useRef(null);
|
|
32
28
|
const popoverRef = useRef(null);
|
|
33
29
|
const menuRef = useRef(null);
|
|
30
|
+
usePopoverSync({
|
|
31
|
+
menuId: submenuId,
|
|
32
|
+
isOpen: state.isOpen,
|
|
33
|
+
onClose: () => state.close(),
|
|
34
|
+
triggerRef: domTriggerRef,
|
|
35
|
+
containerRef: popoverRef
|
|
36
|
+
});
|
|
34
37
|
const { menuTriggerProps: rawTriggerProps, menuProps } = useMenuTrigger({
|
|
35
38
|
type: "submenu",
|
|
36
39
|
isDisabled
|