@cube-dev/ui-kit 0.135.0 → 0.136.0
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 +27 -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 +2 -2
- package/dist/components/Root.js.map +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 +2 -1
- 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 +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 +2 -1
- 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 +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.d.ts +7 -0
- package/dist/components/actions/Menu/MenuTrigger.js +32 -33
- package/dist/components/actions/Menu/MenuTrigger.js.map +1 -1
- package/dist/components/actions/Menu/SubMenuTrigger.js +7 -20
- 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 +6 -19
- package/dist/components/actions/use-anchored-menu.js.map +1 -1
- package/dist/components/actions/use-context-menu.js +17 -21
- 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/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.d.ts +7 -7
- 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 +1 -1
- package/dist/components/fields/Checkbox/context.js +1 -1
- package/dist/components/fields/ComboBox/ComboBox.js +14 -20
- 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 +14 -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 +8 -16
- 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 +14 -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 +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 +14 -21
- 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.js +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.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 +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/EditableTitle.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/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.js +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 +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 +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 +4 -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.js +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/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/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.js +1 -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 +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.js +69 -0
- package/dist/utils/react/usePopoverSync.js.map +1 -0
- 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/package.json +2 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { SlotProvider } from "../../../utils/react/Slots.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useEvent } from "../../../_internal/hooks/use-event.js";
|
|
4
4
|
import { MenuContext } from "./context.js";
|
|
5
5
|
import { generateRandomId } from "../../../utils/random.js";
|
|
6
|
+
import { usePopoverSync } from "../../../utils/react/usePopoverSync.js";
|
|
6
7
|
import { _Tray } from "../../overlays/Modal/Tray.js";
|
|
7
8
|
import { _Popover } from "../../overlays/Modal/Popover.js";
|
|
8
9
|
import { Fragment, forwardRef, useEffect, useMemo, useRef } from "react";
|
|
@@ -20,29 +21,17 @@ function MenuTrigger(props, ref) {
|
|
|
20
21
|
const menuTriggerRef = props.targetRef || domRef || triggerRef;
|
|
21
22
|
const menuRef = useRef(null);
|
|
22
23
|
const wasOpenRef = useRef(false);
|
|
23
|
-
const { children, shouldFlip = true, closeOnSelect, trigger = "press", isDisabled, isDummy } = props;
|
|
24
|
+
const { children, shouldFlip = true, closeOnSelect, trigger = "press", isDisabled, isDummy, mobileType = "popover" } = props;
|
|
24
25
|
const menuId = useMemo(() => generateRandomId(), []);
|
|
25
|
-
const { emit, on } = useEventBus();
|
|
26
26
|
if (!Array.isArray(children) || children.length > 2) throw new Error("MenuTrigger must have exactly 2 children");
|
|
27
27
|
let [menuTrigger, menu] = children;
|
|
28
28
|
const state = useMenuTriggerState(props);
|
|
29
|
-
|
|
30
|
-
return on("popover:open", (data) => {
|
|
31
|
-
if (data.menuId !== menuId && state.isOpen && !isDummy) state.close();
|
|
32
|
-
});
|
|
33
|
-
}, [
|
|
34
|
-
on,
|
|
35
|
-
menuId,
|
|
36
|
-
state
|
|
37
|
-
]);
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (state.isOpen && !isDummy) emit("popover:open", { menuId });
|
|
40
|
-
}, [
|
|
41
|
-
state.isOpen,
|
|
42
|
-
emit,
|
|
29
|
+
usePopoverSync({
|
|
43
30
|
menuId,
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
isOpen: state.isOpen,
|
|
32
|
+
onClose: () => state.close(),
|
|
33
|
+
enabled: !isDummy
|
|
34
|
+
});
|
|
46
35
|
useEffect(() => {
|
|
47
36
|
if (!state.isOpen && wasOpenRef.current && !isDummy) {
|
|
48
37
|
wasOpenRef.current = false;
|
|
@@ -58,14 +47,15 @@ function MenuTrigger(props, ref) {
|
|
|
58
47
|
if (typeof menuTrigger === "function") menuTrigger = menuTrigger(state);
|
|
59
48
|
const { menuTriggerProps, menuProps } = useMenuTrigger({ isDisabled }, state, menuTriggerRef);
|
|
60
49
|
let initialPlacement = props.placement ?? "bottom start";
|
|
61
|
-
const
|
|
50
|
+
const isMobileDevice = useIsMobileDevice();
|
|
51
|
+
const isTray = mobileType === "tray" && isMobileDevice;
|
|
62
52
|
const { overlayProps: positionProps, placement } = useOverlayPosition({
|
|
63
53
|
targetRef: menuTriggerRef,
|
|
64
54
|
overlayRef: menuPopoverRef,
|
|
65
55
|
scrollRef: menuRef,
|
|
66
56
|
placement: initialPlacement,
|
|
67
57
|
shouldFlip,
|
|
68
|
-
isOpen: state.isOpen && !
|
|
58
|
+
isOpen: state.isOpen && !isTray,
|
|
69
59
|
onClose: state.close,
|
|
70
60
|
containerPadding: props.containerPadding,
|
|
71
61
|
offset: props.offset ?? 8,
|
|
@@ -77,13 +67,13 @@ function MenuTrigger(props, ref) {
|
|
|
77
67
|
onClose: state.close,
|
|
78
68
|
closeOnSelect,
|
|
79
69
|
autoFocus: state.focusStrategy ?? "first",
|
|
80
|
-
style:
|
|
70
|
+
style: isTray ? {
|
|
81
71
|
width: "100%",
|
|
82
72
|
maxHeight: "inherit"
|
|
83
73
|
} : void 0,
|
|
84
74
|
mods: {
|
|
85
|
-
popover: !
|
|
86
|
-
tray:
|
|
75
|
+
popover: !isTray,
|
|
76
|
+
tray: isTray
|
|
87
77
|
},
|
|
88
78
|
isClosing: !state.isOpen
|
|
89
79
|
};
|
|
@@ -92,9 +82,24 @@ function MenuTrigger(props, ref) {
|
|
|
92
82
|
menu,
|
|
93
83
|
/* @__PURE__ */ jsx(DismissButton, { onDismiss: state.close })
|
|
94
84
|
] });
|
|
85
|
+
const shouldCloseOnInteractOutside = useEvent((el) => {
|
|
86
|
+
if (!state.isOpen) return false;
|
|
87
|
+
const menuTriggerEl = el.closest("[data-popover-trigger]");
|
|
88
|
+
if (!menuTriggerEl) {
|
|
89
|
+
if (el.closest("[data-popover-dismiss]")) {
|
|
90
|
+
setTimeout(() => state.close(), 0);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if (isDummy && (menuTriggerEl === menuTriggerRef.current || menuTriggerRef.current?.contains(el))) return true;
|
|
96
|
+
if (menuTriggerEl === menuTriggerRef.current) return true;
|
|
97
|
+
return false;
|
|
98
|
+
});
|
|
95
99
|
let overlay;
|
|
96
|
-
if (
|
|
100
|
+
if (isTray) overlay = /* @__PURE__ */ jsx(_Tray, {
|
|
97
101
|
isOpen: state.isOpen,
|
|
102
|
+
shouldCloseOnInteractOutside,
|
|
98
103
|
onClose: state.close,
|
|
99
104
|
children: contents
|
|
100
105
|
});
|
|
@@ -105,13 +110,7 @@ function MenuTrigger(props, ref) {
|
|
|
105
110
|
isOpen: state.isOpen,
|
|
106
111
|
style: positionProps.style,
|
|
107
112
|
placement,
|
|
108
|
-
shouldCloseOnInteractOutside
|
|
109
|
-
const menuTriggerEl = el.closest("[data-popover-trigger]");
|
|
110
|
-
if (!menuTriggerEl) return true;
|
|
111
|
-
if (isDummy && (menuTriggerEl === menuTriggerRef.current || menuTriggerRef.current?.contains(el))) return true;
|
|
112
|
-
if (menuTriggerEl === menuTriggerRef.current) return true;
|
|
113
|
-
return false;
|
|
114
|
-
},
|
|
113
|
+
shouldCloseOnInteractOutside,
|
|
115
114
|
onClose: state.close,
|
|
116
115
|
children: contents
|
|
117
116
|
});
|
|
@@ -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 Placement,\n PositionProps,\n useMenuTrigger,\n useOverlayPosition,\n} from 'react-aria';\nimport { MenuTriggerState, useMenuTriggerState } from 'react-stately';\n\nimport { generateRandomId } from '../../../utils/random';\nimport { SlotProvider } from '../../../utils/react';\nimport { useEventBus } from '../../../utils/react/useEventBus';\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\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 } = props;\n\n // Generate a unique ID for this menu instance\n const menuId = useMemo(() => generateRandomId(), []);\n\n // Get event bus for menu synchronization\n const { emit, on } = useEventBus();\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 // Listen for other menus opening and close this one if needed\n useEffect(() => {\n const unsubscribe = on('popover:open', (data: { menuId: string }) => {\n // If another menu is opening and this menu is open, close this one\n if (data.menuId !== menuId && state.isOpen && !isDummy) {\n state.close();\n }\n });\n\n return unsubscribe;\n }, [on, menuId, state]);\n\n // Emit event when this menu opens\n useEffect(() => {\n if (state.isOpen && !isDummy) {\n emit('popover:open', { menuId });\n }\n }, [state.isOpen, emit, menuId, isDummy]);\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 const isMobile = useIsMobileDevice();\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 && !isMobile,\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: isMobile\n ? {\n width: '100%',\n maxHeight: 'inherit',\n }\n : undefined,\n mods: {\n popover: !isMobile,\n tray: isMobile,\n },\n isClosing: !state.isOpen,\n } as MenuContextValue;\n\n const contents = (\n <>\n <DismissButton onDismiss={state.close} />\n {menu}\n <DismissButton onDismiss={state.close} />\n </>\n );\n\n // On small screen devices, the menu is rendered in a tray, otherwise a popover.\n let overlay;\n if (isMobile) {\n overlay = (\n <Tray isOpen={state.isOpen} onClose={state.close}>\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={(el) => {\n const menuTriggerEl = el.closest('[data-popover-trigger]');\n // If no menu trigger was clicked, allow closing\n if (!menuTriggerEl) return true;\n // For dummy triggers (like useAnchoredMenu), check if the clicked element\n // is the target element or its descendant\n if (\n isDummy &&\n (menuTriggerEl === menuTriggerRef.current ||\n menuTriggerRef.current?.contains(el))\n ) {\n return true;\n }\n // If the same trigger that opened this menu was clicked, allow closing\n if (menuTriggerEl === menuTriggerRef.current) return true;\n // Otherwise, don't close (let event mechanism handle it)\n return false;\n }}\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":";;;;;;;;;;;;;;;AA0CA,SAAS,YAAY,OAA6B,KAA0B;CAC1E,MAAM,iBAAiB,OAAuB,KAAK;CACnD,MAAM,aAAa,OAAoB,KAAK;CAC5C,MAAM,SAAS,UAAU,IAAI;CAC7B,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,YACE;CAGJ,MAAM,SAAS,cAAc,kBAAkB,EAAE,EAAE,CAAC;CAGpD,MAAM,EAAE,MAAM,OAAO,aAAa;AAElC,KAAI,CAAC,MAAM,QAAQ,SAAS,IAAI,SAAS,SAAS,EAChD,OAAM,IAAI,MAAM,2CAA2C;CAG7D,IAAI,CAAC,aAAa,QAAQ;CAC1B,MAAM,QAA0B,oBAAoB,MAAM;AAG1D,iBAAgB;AAQd,SAPoB,GAAG,iBAAiB,SAA6B;AAEnE,OAAI,KAAK,WAAW,UAAU,MAAM,UAAU,CAAC,QAC7C,OAAM,OAAO;IAEf;IAGD;EAAC;EAAI;EAAQ;EAAM,CAAC;AAGvB,iBAAgB;AACd,MAAI,MAAM,UAAU,CAAC,QACnB,MAAK,gBAAgB,EAAE,QAAQ,CAAC;IAEjC;EAAC,MAAM;EAAQ;EAAM;EAAQ;EAAQ,CAAC;AAGzC,iBAAgB;AACd,MAAI,CAAC,MAAM,UAAU,WAAW,WAAW,CAAC,SAAS;AACnD,cAAW,UAAU;AAErB,oBAAi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AAM;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
|
+
{"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 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 const contents = (\n <>\n <DismissButton onDismiss={state.close} />\n {menu}\n <DismissButton onDismiss={state.close} />\n </>\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":";;;;;;;;;;;;;;;;AAkDA,SAAS,YAAY,OAA6B,KAA0B;CAC1E,MAAM,iBAAiB,OAAuB,KAAK;CACnD,MAAM,aAAa,OAAoB,KAAK;CAC5C,MAAM,SAAS,UAAU,IAAI;CAC7B,MAAM,iBAAiB,MAAM,aAAa,UAAU;CACpD,MAAM,UAAU,OAAyB,KAAK;CAC9C,MAAM,aAAa,OAAO,MAAM;CAChC,MAAM,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;EACE,oBAAC,iBAAc,WAAW,MAAM,QAAS;EACxC;EACD,oBAAC,iBAAc,WAAW,MAAM,QAAS;KACxC;CAgBL,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,8 +1,8 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
2
|
-
import { useEventBus } from "../../../utils/react/useEventBus.js";
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
3
2
|
import { MenuContext, useMenuContext } from "./context.js";
|
|
4
3
|
import { SubmenuTriggerContext } from "./SubmenuTriggerContext.js";
|
|
5
4
|
import { generateRandomId } from "../../../utils/random.js";
|
|
5
|
+
import { usePopoverSync } from "../../../utils/react/usePopoverSync.js";
|
|
6
6
|
import { _Popover } from "../../overlays/Modal/Popover.js";
|
|
7
7
|
import React, { useEffect, useMemo, useRef } from "react";
|
|
8
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -22,8 +22,11 @@ function InternalSubMenuTrigger(props) {
|
|
|
22
22
|
const { children, placement = DEFAULT_PLACEMENT, offset = DEFAULT_OFFSET, crossOffset = DEFAULT_CROSS_OFFSET, shouldFlip = true, isDisabled, autoFocus = "first", onAction, targetKey, ...overlayProps } = props;
|
|
23
23
|
const [menuTrigger, menu] = React.Children.toArray(children);
|
|
24
24
|
const state = useMenuTriggerState(props);
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
usePopoverSync({
|
|
26
|
+
menuId: useMemo(() => generateRandomId(), []),
|
|
27
|
+
isOpen: state.isOpen,
|
|
28
|
+
onClose: () => state.close()
|
|
29
|
+
});
|
|
27
30
|
const domTriggerRef = useRef(null);
|
|
28
31
|
const popoverRef = useRef(null);
|
|
29
32
|
const menuRef = useRef(null);
|
|
@@ -69,22 +72,6 @@ function InternalSubMenuTrigger(props) {
|
|
|
69
72
|
parentContext.isClosing
|
|
70
73
|
]);
|
|
71
74
|
useSyncRef(parentContext, domTriggerRef);
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
return on("popover:open", (data) => {
|
|
74
|
-
if (data.menuId !== submenuId && state.isOpen) state.close();
|
|
75
|
-
});
|
|
76
|
-
}, [
|
|
77
|
-
on,
|
|
78
|
-
submenuId,
|
|
79
|
-
state
|
|
80
|
-
]);
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
if (state.isOpen) emit("popover:open", { menuId: submenuId });
|
|
83
|
-
}, [
|
|
84
|
-
state.isOpen,
|
|
85
|
-
emit,
|
|
86
|
-
submenuId
|
|
87
|
-
]);
|
|
88
75
|
useEffect(() => {
|
|
89
76
|
return () => {
|
|
90
77
|
if (hoverOpenTimerRef.current) clearTimeout(hoverOpenTimerRef.current);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubMenuTrigger.js","names":["Popover"],"sources":["../../../../src/components/actions/Menu/SubMenuTrigger.tsx"],"sourcesContent":["import { useSyncRef } from '@react-aria/utils';\nimport React, {\n Key,\n ReactElement,\n ReactNode,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport {\n AriaMenuTriggerProps,\n DismissButton,\n Placement,\n useMenuTrigger,\n useOverlayPosition,\n} from 'react-aria';\nimport { useMenuTriggerState } from 'react-stately';\n\nimport { generateRandomId } from '../../../utils/random';\nimport { useEventBus } from '../../../utils/react/useEventBus';\nimport { Popover } from '../../overlays/Modal';\n\nimport { MenuContext, MenuContextValue, useMenuContext } from './context';\nimport { SubmenuTriggerContext } from './SubmenuTriggerContext';\n\n// Default placement & offset for sub-menus (matches Spectrum / Aria)\nconst DEFAULT_PLACEMENT: Placement = 'right top';\nconst DEFAULT_OFFSET = 4;\nconst DEFAULT_CROSS_OFFSET = -5;\n\nexport interface CubeSubMenuTriggerProps extends AriaMenuTriggerProps {\n /** The preferred placement of the sub-menu relative to the trigger */\n placement?: Placement;\n\n /** Distance in pixels between the trigger and sub-menu */\n offset?: number;\n\n /** Distance in pixels along the cross axis from the default alignment */\n crossOffset?: number;\n\n /** Whether the sub-menu should flip to the opposite side when it would overflow */\n shouldFlip?: boolean;\n\n /** Minimum padding in pixels between the sub-menu and viewport edges */\n containerPadding?: number;\n\n /**\n * Sub-menu trigger and the sub-menu itself. Must be exactly two React nodes.\n *\n * 1) Trigger – **must render `<li role=\"menuitem\">`** (usually `Menu.Item`).\n * 2) Sub-menu – a `<Menu>` element.\n */\n children: [ReactNode, ReactElement];\n\n /** Whether the trigger is disabled and cannot be activated */\n isDisabled?: boolean;\n\n /**\n * Callback fired when an action is selected from the sub-menu.\n * Bubbles the `onAction` event from the sub-menu to parent components.\n */\n onAction?: (key: Key) => void;\n\n /**\n * Controls focus behavior when the sub-menu opens.\n * - `true` or `'first'`: Focus the first item\n * - `'last'`: Focus the last item\n * - `false`: Don't auto-focus any item\n * @default 'first'\n */\n autoFocus?: boolean | 'first' | 'last';\n}\n\ninterface InternalSubMenuTriggerProps extends CubeSubMenuTriggerProps {\n targetKey?: Key;\n}\n\n/**\n * Internal SubMenuTrigger that receives the already-rendered trigger element\n * from the collection system and wraps it with submenu behavior.\n */\nfunction InternalSubMenuTrigger(props: InternalSubMenuTriggerProps) {\n const {\n children,\n placement = DEFAULT_PLACEMENT,\n offset = DEFAULT_OFFSET,\n crossOffset = DEFAULT_CROSS_OFFSET,\n shouldFlip = true,\n isDisabled,\n autoFocus = 'first',\n onAction,\n targetKey,\n ...overlayProps\n } = props;\n\n // Children: [menuTrigger (already rendered MenuItem), menu (Menu component)]\n const [menuTrigger, menu] = React.Children.toArray(children) as [\n ReactElement,\n ReactElement,\n ];\n\n const state = useMenuTriggerState(props as AriaMenuTriggerProps);\n\n // Generate a unique ID for this submenu instance\n const submenuId = useMemo(() => generateRandomId(), []);\n\n // Get event bus for submenu synchronization\n const { emit, on } = useEventBus();\n\n // Refs – trigger (MenuItem <li>) and overlay (<div> from Popover)\n const domTriggerRef = useRef<HTMLElement>(null);\n const popoverRef = useRef<HTMLDivElement>(null);\n const menuRef = useRef<HTMLUListElement>(null);\n\n // Strip keyboard/press handlers that we will implement ourselves\n const { menuTriggerProps: rawTriggerProps, menuProps } = useMenuTrigger(\n { type: 'submenu', isDisabled },\n state,\n domTriggerRef,\n );\n\n // Get parent context to check if parent menu is closing\n const parentContext = useMenuContext();\n\n // Remove default onKeyDown/onPress handlers from trigger props – we implement custom ones\n const {\n onKeyDown: _mtOnKeyDown,\n onPress: _mtOnPress,\n onPressStart: _mtOnPressStart,\n onKeyUp: _mtOnKeyUp,\n ...menuTriggerProps\n } = rawTriggerProps;\n\n const { overlayProps: positionProps } = useOverlayPosition({\n targetRef: domTriggerRef,\n overlayRef: popoverRef,\n scrollRef: menuRef,\n placement,\n offset: offset as number,\n crossOffset: crossOffset as number,\n shouldFlip,\n isOpen: state.isOpen,\n onClose: state.close,\n });\n\n /**\n * Build a MenuContext for the nested menu so it behaves just like a regular\n * popover-based Menu (selection handling, focus management, etc.).\n */\n const nestedMenuContext = useMemo(() => {\n const ctx: MenuContextValue = {\n ...menuProps,\n ref: menuRef,\n // Pass the parent's onClose to close the entire menu hierarchy\n onClose: () => {\n // Close this submenu state immediately\n state.close();\n\n // Then close the parent menu\n if (parentContext.onClose) {\n parentContext.onClose();\n }\n },\n closeOnSelect: true,\n autoFocus,\n mods: {\n popover: true,\n },\n // Propagate closing state from parent\n isClosing: parentContext.isClosing || !state.isOpen,\n };\n\n return ctx;\n }, [\n menuProps,\n autoFocus,\n state,\n parentContext.onClose,\n parentContext.isClosing,\n ]);\n\n // Sync the parent selection manager focus with DOM ref (for virtual focus scenarios)\n useSyncRef(parentContext, domTriggerRef);\n\n // Listen for other menus opening and close this submenu if needed\n useEffect(() => {\n const unsubscribe = on('popover:open', (data: { menuId: string }) => {\n // If another menu is opening and this submenu is open, close this one\n if (data.menuId !== submenuId && state.isOpen) {\n state.close();\n }\n });\n\n return unsubscribe;\n }, [on, submenuId, state]);\n\n // Emit event when this submenu opens\n useEffect(() => {\n if (state.isOpen) {\n emit('popover:open', { menuId: submenuId });\n }\n }, [state.isOpen, emit, submenuId]);\n\n // Cleanup hover timers and reset refs on unmount\n useEffect(() => {\n return () => {\n if (hoverOpenTimerRef.current) {\n clearTimeout(hoverOpenTimerRef.current);\n }\n if (hoverCloseTimerRef.current) {\n clearTimeout(hoverCloseTimerRef.current);\n }\n isHoveringRef.current = false;\n isHoveringSubmenuRef.current = false;\n };\n }, []);\n\n // ----- Render -----\n\n // Handle keyboard navigation\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (isDisabled) return;\n\n // Arrow right opens submenu\n if (e.key === 'ArrowRight') {\n e.preventDefault();\n e.stopPropagation();\n state.open();\n }\n // Enter or Space opens submenu (suppress subsequent onAction)\n else if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n e.stopPropagation();\n // Stop immediate propagation to prevent React Aria's handlers from running\n e.nativeEvent.stopImmediatePropagation();\n state.open();\n suppressNextActionRef.current = true; // Remember it was keyboard\n }\n // Arrow left closes submenu if open\n else if (e.key === 'ArrowLeft' && state.isOpen) {\n e.preventDefault();\n e.stopPropagation();\n state.close();\n }\n };\n\n // Use refs to store timer IDs\n const hoverOpenTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const hoverCloseTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n // Track if mouse is over trigger or submenu\n const isHoveringRef = useRef(false);\n const isHoveringSubmenuRef = useRef(false);\n\n // Track whether the next onAction comes from a keyboard press\n const suppressNextActionRef = useRef(false);\n\n const checkShouldClose = () => {\n // Only close if mouse is not over trigger OR submenu\n if (!isHoveringRef.current && !isHoveringSubmenuRef.current) {\n hoverCloseTimerRef.current = setTimeout(() => {\n // Double check before closing\n if (!isHoveringRef.current && !isHoveringSubmenuRef.current) {\n state.close();\n }\n }, 300);\n }\n };\n\n // Handle mouse interactions on trigger\n const handleMouseEnter = () => {\n if (isDisabled) return;\n\n isHoveringRef.current = true;\n\n // Clear any pending close timer\n if (hoverCloseTimerRef.current) {\n clearTimeout(hoverCloseTimerRef.current);\n hoverCloseTimerRef.current = null;\n }\n\n // Use a small delay to prevent accidental opens\n if (!state.isOpen) {\n hoverOpenTimerRef.current = setTimeout(() => {\n if (isHoveringRef.current) {\n state.open();\n }\n }, 200);\n }\n };\n\n const handleMouseLeave = () => {\n isHoveringRef.current = false;\n\n // Clear open timer if it exists\n if (hoverOpenTimerRef.current) {\n clearTimeout(hoverOpenTimerRef.current);\n hoverOpenTimerRef.current = null;\n }\n\n // Check if we should close\n checkShouldClose();\n };\n\n // Handle mouse events on the submenu popover\n const handlePopoverMouseEnter = () => {\n isHoveringSubmenuRef.current = true;\n\n // Clear any pending close timer when entering submenu\n if (hoverCloseTimerRef.current) {\n clearTimeout(hoverCloseTimerRef.current);\n hoverCloseTimerRef.current = null;\n }\n };\n\n const handlePopoverMouseLeave = () => {\n isHoveringSubmenuRef.current = false;\n\n // Check if we should close\n checkShouldClose();\n };\n\n // Merge event handlers\n const mergeHandler = (handler1: any, handler2: any) => {\n return (...args: any[]) => {\n handler1?.(...args);\n handler2?.(...args);\n };\n };\n\n // Provide context to the trigger element (already rendered MenuItem)\n const triggerContextValue = useMemo(\n () => ({\n triggerRef: domTriggerRef,\n triggerProps: menuTriggerProps,\n isOpen: state.isOpen,\n isDisabled,\n onMouseEnter: handleMouseEnter,\n onMouseLeave: handleMouseLeave,\n onKeyDown: handleKeyDown,\n onAction: isDisabled\n ? undefined\n : () => {\n // Ignore the synthetic press generated by the same Enter/Space\n if (suppressNextActionRef.current) {\n suppressNextActionRef.current = false;\n return;\n }\n // This is a mouse click, open the submenu\n state.open();\n },\n }),\n [\n state,\n isDisabled,\n handleMouseEnter,\n handleMouseLeave,\n handleKeyDown,\n menuTriggerProps,\n ],\n );\n\n return (\n <>\n <SubmenuTriggerContext.Provider value={triggerContextValue}>\n {menuTrigger}\n </SubmenuTriggerContext.Provider>\n {state.isOpen && (\n <Popover\n ref={popoverRef}\n hideArrow\n isNonModal\n isOpen={!parentContext.isClosing}\n style={positionProps.style}\n placement={placement as Placement}\n onClose={state.close}\n // Spread any additional overlay props\n {...overlayProps}\n >\n {/* Wrap content in a div to capture mouse events */}\n <div\n style={{ display: 'contents' }}\n onMouseEnter={handlePopoverMouseEnter}\n onMouseLeave={handlePopoverMouseLeave}\n >\n {/* Dismiss buttons for screen reader / keyboard support */}\n <DismissButton onDismiss={state.close} />\n {/* Provide updated menu context so nested menu behaves correctly */}\n <MenuContext.Provider value={nestedMenuContext}>\n {/* Clone nested menu to inject required props */}\n {React.cloneElement(menu, {\n ...(menu.props as any),\n autoFocus,\n onAction: (key: Key) => {\n // Call original menu onAction first\n (menu.props as any).onAction?.(key);\n onAction?.(key);\n // Don't close here - MenuItem will handle it via context.onClose\n },\n onKeyDown: (e: React.KeyboardEvent) => {\n // Handle keyboard navigation for closing submenu\n if (e.key === 'ArrowLeft' || e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n state.close();\n // Return focus to trigger\n domTriggerRef.current?.focus();\n }\n // Call original handler if exists\n (menu.props as any).onKeyDown?.(e);\n },\n ref: menuRef,\n })}\n </MenuContext.Provider>\n <DismissButton onDismiss={state.close} />\n </div>\n </Popover>\n )}\n </>\n );\n}\n\n/**\n * Public SubMenuTrigger component that users interact with.\n * It just provides the getCollectionNode for the collection system.\n */\nexport function SubMenuTrigger(props: CubeSubMenuTriggerProps) {\n // This component is never actually rendered directly.\n // The collection system uses getCollectionNode to build the menu.\n return null;\n}\n\n// Allow React Stately collection builder to treat SubMenuTrigger as an Item\n(SubMenuTrigger as any).getCollectionNode = function* (\n props: CubeSubMenuTriggerProps,\n) {\n const [trigger, menu] = React.Children.toArray(\n props.children,\n ) as ReactElement[];\n\n // Yield a collection node that tells the Menu to wrap this item with InternalSubMenuTrigger\n yield {\n element: trigger,\n wrapper: (element: ReactElement) => (\n <InternalSubMenuTrigger\n key={element.key || undefined}\n targetKey={element.key || undefined}\n {...props}\n >\n {element}\n {menu}\n </InternalSubMenuTrigger>\n ),\n };\n};\n\nSubMenuTrigger.displayName = 'SubMenuTrigger';\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAM,oBAA+B;AACrC,MAAM,iBAAiB;AACvB,MAAM,uBAAuB;;;;;AAqD7B,SAAS,uBAAuB,OAAoC;CAClE,MAAM,EACJ,UACA,YAAY,mBACZ,SAAS,gBACT,cAAc,sBACd,aAAa,MACb,YACA,YAAY,SACZ,UACA,WACA,GAAG,iBACD;CAGJ,MAAM,CAAC,aAAa,QAAQ,MAAM,SAAS,QAAQ,SAAS;CAK5D,MAAM,QAAQ,oBAAoB,MAA8B;CAGhE,MAAM,YAAY,cAAc,kBAAkB,EAAE,EAAE,CAAC;CAGvD,MAAM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,QAAQ,OAAO;GAC1B,GAAI;cAEH,SACA;KALI,QAAQ,OAAO,OAMG;EAE5B;;AAGH,eAAe,cAAc"}
|
|
1
|
+
{"version":3,"file":"SubMenuTrigger.js","names":["Popover"],"sources":["../../../../src/components/actions/Menu/SubMenuTrigger.tsx"],"sourcesContent":["import { useSyncRef } from '@react-aria/utils';\nimport React, {\n Key,\n ReactElement,\n ReactNode,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport {\n AriaMenuTriggerProps,\n DismissButton,\n Placement,\n useMenuTrigger,\n useOverlayPosition,\n} from 'react-aria';\nimport { useMenuTriggerState } from 'react-stately';\n\nimport { generateRandomId } from '../../../utils/random';\nimport { usePopoverSync } from '../../../utils/react/usePopoverSync';\nimport { Popover } from '../../overlays/Modal';\n\nimport { MenuContext, MenuContextValue, useMenuContext } from './context';\nimport { SubmenuTriggerContext } from './SubmenuTriggerContext';\n\n// Default placement & offset for sub-menus (matches Spectrum / Aria)\nconst DEFAULT_PLACEMENT: Placement = 'right top';\nconst DEFAULT_OFFSET = 4;\nconst DEFAULT_CROSS_OFFSET = -5;\n\nexport interface CubeSubMenuTriggerProps extends AriaMenuTriggerProps {\n /** The preferred placement of the sub-menu relative to the trigger */\n placement?: Placement;\n\n /** Distance in pixels between the trigger and sub-menu */\n offset?: number;\n\n /** Distance in pixels along the cross axis from the default alignment */\n crossOffset?: number;\n\n /** Whether the sub-menu should flip to the opposite side when it would overflow */\n shouldFlip?: boolean;\n\n /** Minimum padding in pixels between the sub-menu and viewport edges */\n containerPadding?: number;\n\n /**\n * Sub-menu trigger and the sub-menu itself. Must be exactly two React nodes.\n *\n * 1) Trigger – **must render `<li role=\"menuitem\">`** (usually `Menu.Item`).\n * 2) Sub-menu – a `<Menu>` element.\n */\n children: [ReactNode, ReactElement];\n\n /** Whether the trigger is disabled and cannot be activated */\n isDisabled?: boolean;\n\n /**\n * Callback fired when an action is selected from the sub-menu.\n * Bubbles the `onAction` event from the sub-menu to parent components.\n */\n onAction?: (key: Key) => void;\n\n /**\n * Controls focus behavior when the sub-menu opens.\n * - `true` or `'first'`: Focus the first item\n * - `'last'`: Focus the last item\n * - `false`: Don't auto-focus any item\n * @default 'first'\n */\n autoFocus?: boolean | 'first' | 'last';\n}\n\ninterface InternalSubMenuTriggerProps extends CubeSubMenuTriggerProps {\n targetKey?: Key;\n}\n\n/**\n * Internal SubMenuTrigger that receives the already-rendered trigger element\n * from the collection system and wraps it with submenu behavior.\n */\nfunction InternalSubMenuTrigger(props: InternalSubMenuTriggerProps) {\n const {\n children,\n placement = DEFAULT_PLACEMENT,\n offset = DEFAULT_OFFSET,\n crossOffset = DEFAULT_CROSS_OFFSET,\n shouldFlip = true,\n isDisabled,\n autoFocus = 'first',\n onAction,\n targetKey,\n ...overlayProps\n } = props;\n\n // Children: [menuTrigger (already rendered MenuItem), menu (Menu component)]\n const [menuTrigger, menu] = React.Children.toArray(children) as [\n ReactElement,\n ReactElement,\n ];\n\n const state = useMenuTriggerState(props as AriaMenuTriggerProps);\n\n // Generate a unique ID for this submenu instance\n const submenuId = useMemo(() => generateRandomId(), []);\n\n usePopoverSync({\n menuId: submenuId,\n isOpen: state.isOpen,\n onClose: () => state.close(),\n });\n\n // Refs – trigger (MenuItem <li>) and overlay (<div> from Popover)\n const domTriggerRef = useRef<HTMLElement>(null);\n const popoverRef = useRef<HTMLDivElement>(null);\n const menuRef = useRef<HTMLUListElement>(null);\n\n // Strip keyboard/press handlers that we will implement ourselves\n const { menuTriggerProps: rawTriggerProps, menuProps } = useMenuTrigger(\n { type: 'submenu', isDisabled },\n state,\n domTriggerRef,\n );\n\n // Get parent context to check if parent menu is closing\n const parentContext = useMenuContext();\n\n // Remove default onKeyDown/onPress handlers from trigger props – we implement custom ones\n const {\n onKeyDown: _mtOnKeyDown,\n onPress: _mtOnPress,\n onPressStart: _mtOnPressStart,\n onKeyUp: _mtOnKeyUp,\n ...menuTriggerProps\n } = rawTriggerProps;\n\n const { overlayProps: positionProps } = useOverlayPosition({\n targetRef: domTriggerRef,\n overlayRef: popoverRef,\n scrollRef: menuRef,\n placement,\n offset: offset as number,\n crossOffset: crossOffset as number,\n shouldFlip,\n isOpen: state.isOpen,\n onClose: state.close,\n });\n\n /**\n * Build a MenuContext for the nested menu so it behaves just like a regular\n * popover-based Menu (selection handling, focus management, etc.).\n */\n const nestedMenuContext = useMemo(() => {\n const ctx: MenuContextValue = {\n ...menuProps,\n ref: menuRef,\n // Pass the parent's onClose to close the entire menu hierarchy\n onClose: () => {\n // Close this submenu state immediately\n state.close();\n\n // Then close the parent menu\n if (parentContext.onClose) {\n parentContext.onClose();\n }\n },\n closeOnSelect: true,\n autoFocus,\n mods: {\n popover: true,\n },\n // Propagate closing state from parent\n isClosing: parentContext.isClosing || !state.isOpen,\n };\n\n return ctx;\n }, [\n menuProps,\n autoFocus,\n state,\n parentContext.onClose,\n parentContext.isClosing,\n ]);\n\n // Sync the parent selection manager focus with DOM ref (for virtual focus scenarios)\n useSyncRef(parentContext, domTriggerRef);\n\n // Cleanup hover timers and reset refs on unmount\n useEffect(() => {\n return () => {\n if (hoverOpenTimerRef.current) {\n clearTimeout(hoverOpenTimerRef.current);\n }\n if (hoverCloseTimerRef.current) {\n clearTimeout(hoverCloseTimerRef.current);\n }\n isHoveringRef.current = false;\n isHoveringSubmenuRef.current = false;\n };\n }, []);\n\n // ----- Render -----\n\n // Handle keyboard navigation\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (isDisabled) return;\n\n // Arrow right opens submenu\n if (e.key === 'ArrowRight') {\n e.preventDefault();\n e.stopPropagation();\n state.open();\n }\n // Enter or Space opens submenu (suppress subsequent onAction)\n else if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n e.stopPropagation();\n // Stop immediate propagation to prevent React Aria's handlers from running\n e.nativeEvent.stopImmediatePropagation();\n state.open();\n suppressNextActionRef.current = true; // Remember it was keyboard\n }\n // Arrow left closes submenu if open\n else if (e.key === 'ArrowLeft' && state.isOpen) {\n e.preventDefault();\n e.stopPropagation();\n state.close();\n }\n };\n\n // Use refs to store timer IDs\n const hoverOpenTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const hoverCloseTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n // Track if mouse is over trigger or submenu\n const isHoveringRef = useRef(false);\n const isHoveringSubmenuRef = useRef(false);\n\n // Track whether the next onAction comes from a keyboard press\n const suppressNextActionRef = useRef(false);\n\n const checkShouldClose = () => {\n // Only close if mouse is not over trigger OR submenu\n if (!isHoveringRef.current && !isHoveringSubmenuRef.current) {\n hoverCloseTimerRef.current = setTimeout(() => {\n // Double check before closing\n if (!isHoveringRef.current && !isHoveringSubmenuRef.current) {\n state.close();\n }\n }, 300);\n }\n };\n\n // Handle mouse interactions on trigger\n const handleMouseEnter = () => {\n if (isDisabled) return;\n\n isHoveringRef.current = true;\n\n // Clear any pending close timer\n if (hoverCloseTimerRef.current) {\n clearTimeout(hoverCloseTimerRef.current);\n hoverCloseTimerRef.current = null;\n }\n\n // Use a small delay to prevent accidental opens\n if (!state.isOpen) {\n hoverOpenTimerRef.current = setTimeout(() => {\n if (isHoveringRef.current) {\n state.open();\n }\n }, 200);\n }\n };\n\n const handleMouseLeave = () => {\n isHoveringRef.current = false;\n\n // Clear open timer if it exists\n if (hoverOpenTimerRef.current) {\n clearTimeout(hoverOpenTimerRef.current);\n hoverOpenTimerRef.current = null;\n }\n\n // Check if we should close\n checkShouldClose();\n };\n\n // Handle mouse events on the submenu popover\n const handlePopoverMouseEnter = () => {\n isHoveringSubmenuRef.current = true;\n\n // Clear any pending close timer when entering submenu\n if (hoverCloseTimerRef.current) {\n clearTimeout(hoverCloseTimerRef.current);\n hoverCloseTimerRef.current = null;\n }\n };\n\n const handlePopoverMouseLeave = () => {\n isHoveringSubmenuRef.current = false;\n\n // Check if we should close\n checkShouldClose();\n };\n\n // Merge event handlers\n const mergeHandler = (handler1: any, handler2: any) => {\n return (...args: any[]) => {\n handler1?.(...args);\n handler2?.(...args);\n };\n };\n\n // Provide context to the trigger element (already rendered MenuItem)\n const triggerContextValue = useMemo(\n () => ({\n triggerRef: domTriggerRef,\n triggerProps: menuTriggerProps,\n isOpen: state.isOpen,\n isDisabled,\n onMouseEnter: handleMouseEnter,\n onMouseLeave: handleMouseLeave,\n onKeyDown: handleKeyDown,\n onAction: isDisabled\n ? undefined\n : () => {\n // Ignore the synthetic press generated by the same Enter/Space\n if (suppressNextActionRef.current) {\n suppressNextActionRef.current = false;\n return;\n }\n // This is a mouse click, open the submenu\n state.open();\n },\n }),\n [\n state,\n isDisabled,\n handleMouseEnter,\n handleMouseLeave,\n handleKeyDown,\n menuTriggerProps,\n ],\n );\n\n return (\n <>\n <SubmenuTriggerContext.Provider value={triggerContextValue}>\n {menuTrigger}\n </SubmenuTriggerContext.Provider>\n {state.isOpen && (\n <Popover\n ref={popoverRef}\n hideArrow\n isNonModal\n isOpen={!parentContext.isClosing}\n style={positionProps.style}\n placement={placement as Placement}\n onClose={state.close}\n // Spread any additional overlay props\n {...overlayProps}\n >\n {/* Wrap content in a div to capture mouse events */}\n <div\n style={{ display: 'contents' }}\n onMouseEnter={handlePopoverMouseEnter}\n onMouseLeave={handlePopoverMouseLeave}\n >\n {/* Dismiss buttons for screen reader / keyboard support */}\n <DismissButton onDismiss={state.close} />\n {/* Provide updated menu context so nested menu behaves correctly */}\n <MenuContext.Provider value={nestedMenuContext}>\n {/* Clone nested menu to inject required props */}\n {React.cloneElement(menu, {\n ...(menu.props as any),\n autoFocus,\n onAction: (key: Key) => {\n // Call original menu onAction first\n (menu.props as any).onAction?.(key);\n onAction?.(key);\n // Don't close here - MenuItem will handle it via context.onClose\n },\n onKeyDown: (e: React.KeyboardEvent) => {\n // Handle keyboard navigation for closing submenu\n if (e.key === 'ArrowLeft' || e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n state.close();\n // Return focus to trigger\n domTriggerRef.current?.focus();\n }\n // Call original handler if exists\n (menu.props as any).onKeyDown?.(e);\n },\n ref: menuRef,\n })}\n </MenuContext.Provider>\n <DismissButton onDismiss={state.close} />\n </div>\n </Popover>\n )}\n </>\n );\n}\n\n/**\n * Public SubMenuTrigger component that users interact with.\n * It just provides the getCollectionNode for the collection system.\n */\nexport function SubMenuTrigger(props: CubeSubMenuTriggerProps) {\n // This component is never actually rendered directly.\n // The collection system uses getCollectionNode to build the menu.\n return null;\n}\n\n// Allow React Stately collection builder to treat SubMenuTrigger as an Item\n(SubMenuTrigger as any).getCollectionNode = function* (\n props: CubeSubMenuTriggerProps,\n) {\n const [trigger, menu] = React.Children.toArray(\n props.children,\n ) as ReactElement[];\n\n // Yield a collection node that tells the Menu to wrap this item with InternalSubMenuTrigger\n yield {\n element: trigger,\n wrapper: (element: ReactElement) => (\n <InternalSubMenuTrigger\n key={element.key || undefined}\n targetKey={element.key || undefined}\n {...props}\n >\n {element}\n {menu}\n </InternalSubMenuTrigger>\n ),\n };\n};\n\nSubMenuTrigger.displayName = 'SubMenuTrigger';\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAM,oBAA+B;AACrC,MAAM,iBAAiB;AACvB,MAAM,uBAAuB;;;;;AAqD7B,SAAS,uBAAuB,OAAoC;CAClE,MAAM,EACJ,UACA,YAAY,mBACZ,SAAS,gBACT,cAAc,sBACd,aAAa,MACb,YACA,YAAY,SACZ,UACA,WACA,GAAG,iBACD;CAGJ,MAAM,CAAC,aAAa,QAAQ,MAAM,SAAS,QAAQ,SAAS;CAK5D,MAAM,QAAQ,oBAAoB,MAA8B;AAKhE,gBAAe;EACb,QAHgB,cAAc,kBAAkB,EAAE,EAAE,CAAC;EAIrD,QAAQ,MAAM;EACd,eAAe,MAAM,OAAO;EAC7B,CAAC;CAGF,MAAM,gBAAgB,OAAoB,KAAK;CAC/C,MAAM,aAAa,OAAuB,KAAK;CAC/C,MAAM,UAAU,OAAyB,KAAK;CAG9C,MAAM,EAAE,kBAAkB,iBAAiB,cAAc,eACvD;EAAE,MAAM;EAAW;EAAY,EAC/B,OAC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,GAAI;YAGJ,qBAAC;GACC,OAAO,EAAE,SAAS,YAAY;GAC9B,cAAc;GACd,cAAc;;IAGd,oBAAC,iBAAc,WAAW,MAAM,QAAS;IAEzC,oBAAC,YAAY;KAAS,OAAO;eAE1B,MAAM,aAAa,MAAM;MACxB,GAAI,KAAK;MACT;MACA,WAAW,QAAa;AAEtB,OAAC,KAAK,MAAc,WAAW,IAAI;AACnC,kBAAW,IAAI;;MAGjB,YAAY,MAA2B;AAErC,WAAI,EAAE,QAAQ,eAAe,EAAE,QAAQ,UAAU;AAC/C,UAAE,gBAAgB;AAClB,UAAE,iBAAiB;AACnB,cAAM,OAAO;AAEb,sBAAc,SAAS,OAAO;;AAGhC,OAAC,KAAK,MAAc,YAAY,EAAE;;MAEpC,KAAK;MACN,CAAC;MACmB;IACvB,oBAAC,iBAAc,WAAW,MAAM,QAAS;;IACrC;GACE,IAEX;;;;;;AAQP,SAAgB,eAAe,OAAgC;AAG7D,QAAO;;AAIT,AAAC,eAAuB,oBAAoB,WAC1C,OACA;CACA,MAAM,CAAC,SAAS,QAAQ,MAAM,SAAS,QACrC,MAAM,SACP;AAGD,OAAM;EACJ,SAAS;EACT,UAAU,YACR,qBAAC;GAEC,WAAW,QAAQ,OAAO;GAC1B,GAAI;cAEH,SACA;KALI,QAAQ,OAAO,OAMG;EAE5B;;AAGH,eAAe,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { DEFAULT_NEUTRAL_STYLES } from "../../../data/item-themes.js";
|
|
3
3
|
import { Space } from "../../layout/Space.js";
|
|
4
4
|
import { DEFAULT_BUTTON_STYLES } from "../Button/Button.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { ItemActionProvider, useItemActionContext } from "./ItemActionContext.js";
|
|
3
3
|
import { openLink, parseTo, performClickHandler, useAction } from "./use-action.js";
|
|
4
4
|
import { ItemAction } from "./ItemAction/ItemAction.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { mergeProps as mergeProps$1 } from "../../utils/react/mergeProps.js";
|
|
3
3
|
import { useEvent } from "../../_internal/hooks/use-event.js";
|
|
4
4
|
import { useFocus as useFocus$1 } from "../../utils/react/interactions.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { mergeProps as mergeProps$1 } from "../../utils/react/mergeProps.js";
|
|
3
|
-
import { useEventBus } from "../../utils/react/useEventBus.js";
|
|
4
3
|
import { useEvent } from "../../_internal/hooks/use-event.js";
|
|
5
4
|
import { generateRandomId } from "../../utils/random.js";
|
|
5
|
+
import { usePopoverSync } from "../../utils/react/usePopoverSync.js";
|
|
6
6
|
import { _MenuTrigger } from "./Menu/MenuTrigger.js";
|
|
7
7
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -33,24 +33,11 @@ function useAnchoredMenu(Component, defaultTriggerProps, defaultMenuProps) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
}, []);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
return on("popover:open", (data) => {
|
|
40
|
-
if (data.menuId !== menuId && isOpen) setIsOpen(false);
|
|
41
|
-
});
|
|
42
|
-
}, [
|
|
43
|
-
on,
|
|
44
|
-
menuId,
|
|
45
|
-
isOpen
|
|
46
|
-
]);
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (isOpen) emit("popover:open", { menuId });
|
|
49
|
-
}, [
|
|
36
|
+
usePopoverSync({
|
|
37
|
+
menuId: useMemo(() => generateRandomId(), []),
|
|
50
38
|
isOpen,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
]);
|
|
39
|
+
onClose: () => setIsOpen(false)
|
|
40
|
+
});
|
|
54
41
|
function setupCheck() {
|
|
55
42
|
if (!setupRef.current) throw new Error("useAnchoredMenu: MenuTrigger must be rendered. Use `rendered` property to include it in your component tree.");
|
|
56
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-anchored-menu.js","names":["MenuTrigger","mergeProps"],"sources":["../../../src/components/actions/use-anchored-menu.tsx"],"sourcesContent":["import { Pressable } from '@react-aria/interactions';\nimport {\n ComponentProps,\n ComponentType,\n ReactElement,\n RefObject,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { VisuallyHidden } from 'react-aria';\n\nimport { useEvent } from '../../_internal';\nimport { generateRandomId } from '../../utils/random';\nimport { mergeProps } from '../../utils/react';\nimport {
|
|
1
|
+
{"version":3,"file":"use-anchored-menu.js","names":["MenuTrigger","mergeProps"],"sources":["../../../src/components/actions/use-anchored-menu.tsx"],"sourcesContent":["import { Pressable } from '@react-aria/interactions';\nimport {\n ComponentProps,\n ComponentType,\n ReactElement,\n RefObject,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { VisuallyHidden } from 'react-aria';\n\nimport { useEvent } from '../../_internal';\nimport { generateRandomId } from '../../utils/random';\nimport { mergeProps } from '../../utils/react';\nimport { usePopoverSync } from '../../utils/react/usePopoverSync';\n\nimport { MenuTrigger } from './Menu';\n\nexport interface UseAnchoredMenuReturn<P, T> {\n /** Ref to attach to the anchor element for positioning the menu. */\n anchorRef: RefObject<HTMLElement | null>;\n\n /**\n * Programmatically opens the menu with the provided props.\n * @param props - Props to pass to the menu component\n * @param triggerProps - Additional props for MenuTrigger (merged with defaultTriggerProps)\n */\n open(props?: P, triggerProps?: T): void;\n\n /**\n * Updates the props of the currently open menu.\n * Props are merged if defaults are provided.\n */\n update(props: P, triggerProps?: T): void;\n\n /** Closes the menu programmatically. */\n close(): void;\n\n /** Current open/closed state of the menu. */\n isOpen: boolean;\n\n /**\n * JSX element that must be rendered in your component tree.\n * Contains the MenuTrigger and positioning logic.\n */\n get rendered(): ReactElement | null;\n}\n\n/**\n * Generic hook to manage an anchored menu component.\n *\n * @param Component - A React component that represents the menu content (Menu or CommandMenu).\n * @param defaultTriggerProps - Default props to pass to the MenuTrigger.\n * @param defaultMenuProps - Default props to pass to the Menu component.\n * @returns An object with `anchorRef` to position the menu, `open` function to open the menu with provided props, `close` function to close the menu, and `rendered` JSX element to include in your component tree.\n */\nexport function useAnchoredMenu<P, T = ComponentProps<typeof MenuTrigger>>(\n Component: ComponentType<P>,\n defaultTriggerProps?: Omit<\n ComponentProps<typeof MenuTrigger>,\n 'children' | 'isOpen' | 'onOpenChange' | 'targetRef'\n >,\n defaultMenuProps?: P,\n): UseAnchoredMenuReturn<P, T> {\n const [isOpen, setIsOpen] = useState(false);\n const [componentProps, setComponentProps] = useState<P | null>(null);\n const [triggerProps, setTriggerProps] = useState<T | null>(null);\n const anchorRef = useRef<HTMLElement>(null);\n const setupRef = useRef(false);\n\n useEffect(() => {\n const el = anchorRef.current;\n if (el) {\n el.dataset.popoverTrigger = '';\n return () => {\n delete el.dataset.popoverTrigger;\n };\n }\n }, []);\n\n // Generate a unique ID for this menu instance\n const menuId = useMemo(() => generateRandomId(), []);\n\n usePopoverSync({\n menuId,\n isOpen,\n onClose: () => setIsOpen(false),\n });\n\n function setupCheck() {\n if (!setupRef.current) {\n throw new Error(\n 'useAnchoredMenu: MenuTrigger must be rendered. Use `rendered` property to include it in your component tree.',\n );\n }\n }\n\n // 'open' accepts props required by the Component and opens the menu\n const open = useEvent((props: P = {} as P, triggerProps?: T) => {\n setupCheck();\n\n // Merge defaultMenuProps with provided props\n const finalProps = defaultMenuProps\n ? { ...defaultMenuProps, ...props }\n : props;\n\n setComponentProps(finalProps);\n setTriggerProps(triggerProps ?? null);\n setIsOpen(true);\n });\n\n const update = useEvent((props: P, triggerProps?: T) => {\n setupCheck();\n\n // Merge defaultMenuProps with provided props\n const finalProps = defaultMenuProps\n ? { ...defaultMenuProps, ...props }\n : props;\n\n setComponentProps(finalProps);\n setTriggerProps(triggerProps ?? null);\n });\n\n const close = useEvent(() => {\n setIsOpen(false);\n });\n\n // Render the menu only when componentProps is set\n const renderedMenu = useMemo(() => {\n if (!componentProps) return null;\n\n return (\n <MenuTrigger\n isDummy\n isOpen={isOpen}\n targetRef={anchorRef}\n placement=\"bottom start\"\n onOpenChange={setIsOpen}\n {...mergeProps(defaultTriggerProps, triggerProps || undefined)}\n >\n <VisuallyHidden>\n <Pressable>\n <button aria-label=\"context-menu\" />\n </Pressable>\n </VisuallyHidden>\n <Component {...componentProps} />\n </MenuTrigger>\n );\n }, [componentProps, triggerProps, isOpen, defaultTriggerProps]);\n\n return {\n anchorRef,\n open,\n update,\n close,\n isOpen,\n get rendered() {\n setupRef.current = true;\n\n return renderedMenu;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,gBACd,WACA,qBAIA,kBAC6B;CAC7B,MAAM,CAAC,QAAQ,aAAa,SAAS,MAAM;CAC3C,MAAM,CAAC,gBAAgB,qBAAqB,SAAmB,KAAK;CACpE,MAAM,CAAC,cAAc,mBAAmB,SAAmB,KAAK;CAChE,MAAM,YAAY,OAAoB,KAAK;CAC3C,MAAM,WAAW,OAAO,MAAM;AAE9B,iBAAgB;EACd,MAAM,KAAK,UAAU;AACrB,MAAI,IAAI;AACN,MAAG,QAAQ,iBAAiB;AAC5B,gBAAa;AACX,WAAO,GAAG,QAAQ;;;IAGrB,EAAE,CAAC;AAKN,gBAAe;EACb,QAHa,cAAc,kBAAkB,EAAE,EAAE,CAAC;EAIlD;EACA,eAAe,UAAU,MAAM;EAChC,CAAC;CAEF,SAAS,aAAa;AACpB,MAAI,CAAC,SAAS,QACZ,OAAM,IAAI,MACR,+GACD;;CAKL,MAAM,OAAO,UAAU,QAAW,EAAE,EAAO,iBAAqB;AAC9D,cAAY;AAOZ,oBAJmB,mBACf;GAAE,GAAG;GAAkB,GAAG;GAAO,GACjC,MAEyB;AAC7B,kBAAgB,gBAAgB,KAAK;AACrC,YAAU,KAAK;GACf;CAEF,MAAM,SAAS,UAAU,OAAU,iBAAqB;AACtD,cAAY;AAOZ,oBAJmB,mBACf;GAAE,GAAG;GAAkB,GAAG;GAAO,GACjC,MAEyB;AAC7B,kBAAgB,gBAAgB,KAAK;GACrC;CAEF,MAAM,QAAQ,eAAe;AAC3B,YAAU,MAAM;GAChB;CAGF,MAAM,eAAe,cAAc;AACjC,MAAI,CAAC,eAAgB,QAAO;AAE5B,SACE,qBAACA;GACC;GACQ;GACR,WAAW;GACX,WAAU;GACV,cAAc;GACd,GAAIC,aAAW,qBAAqB,gBAAgB,OAAU;cAE9D,oBAAC,4BACC,oBAAC,uBACC,oBAAC,YAAO,cAAW,iBAAiB,GAC1B,GACG,EACjB,oBAAC,aAAU,GAAI,iBAAkB;IACrB;IAEf;EAAC;EAAgB;EAAc;EAAQ;EAAoB,CAAC;AAE/D,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,IAAI,WAAW;AACb,YAAS,UAAU;AAEnB,UAAO;;EAEV"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { mergeProps as mergeProps$1 } from "../../utils/react/mergeProps.js";
|
|
3
|
-
import { useEventBus } from "../../utils/react/useEventBus.js";
|
|
4
3
|
import { useEvent } from "../../_internal/hooks/use-event.js";
|
|
5
4
|
import { generateRandomId } from "../../utils/random.js";
|
|
5
|
+
import { usePopoverSync } from "../../utils/react/usePopoverSync.js";
|
|
6
6
|
import { _MenuTrigger } from "./Menu/MenuTrigger.js";
|
|
7
7
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
8
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -26,27 +26,23 @@ function useContextMenu(Component, defaultTriggerProps, defaultMenuProps) {
|
|
|
26
26
|
const targetRef = useRef(null);
|
|
27
27
|
const invisibleAnchorRef = useRef(null);
|
|
28
28
|
const setupRef = useRef(false);
|
|
29
|
-
const menuId = useMemo(() => generateRandomId(), []);
|
|
30
|
-
const { emit, on } = useEventBus();
|
|
31
29
|
useEffect(() => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
]);
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (isOpen) emit("popover:open", { menuId });
|
|
45
|
-
}, [
|
|
30
|
+
const el = targetRef.current;
|
|
31
|
+
if (el) {
|
|
32
|
+
el.dataset.popoverTrigger = "";
|
|
33
|
+
return () => {
|
|
34
|
+
delete el.dataset.popoverTrigger;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
38
|
+
usePopoverSync({
|
|
39
|
+
menuId: useMemo(() => generateRandomId(), []),
|
|
46
40
|
isOpen,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
onClose: () => {
|
|
42
|
+
setIsOpen(false);
|
|
43
|
+
setAnchorPosition(null);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
50
46
|
function setupCheck() {
|
|
51
47
|
if (!setupRef.current) throw new Error("useContextMenu: MenuTrigger must be rendered. Use `rendered` property to include it in your component tree.");
|
|
52
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-context-menu.js","names":["MenuTrigger","mergeProps"],"sources":["../../../src/components/actions/use-context-menu.tsx"],"sourcesContent":["import { Pressable } from '@react-aria/interactions';\nimport {\n ComponentProps,\n ComponentType,\n MouseEvent,\n PointerEvent,\n ReactElement,\n RefObject,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { VisuallyHidden } from 'react-aria';\n\nimport { useEvent } from '../../_internal';\nimport { generateRandomId } from '../../utils/random';\nimport { mergeProps } from '../../utils/react';\nimport { useEventBus } from '../../utils/react/useEventBus';\n\nimport { MenuTrigger } from './Menu';\n\ntype NativeMouseEvent = globalThis.MouseEvent;\ntype NativePointerEvent = globalThis.PointerEvent;\n\nexport interface UseContextMenuReturn<\n E extends HTMLElement = HTMLElement,\n P extends object = {},\n T = ComponentProps<typeof MenuTrigger>,\n> {\n /** Container element that receives context menu events. Attach this ref to your target element. */\n targetRef: RefObject<E | null>;\n\n /**\n * Programmatically opens the menu at the specified coordinates or element center.\n * Runtime props are merged with defaultMenuProps (runtime props take precedence).\n *\n * @param props - Props to pass to the menu component (optional, defaults to defaultMenuProps)\n * @param triggerProps - Additional props for MenuTrigger (merged with defaultTriggerProps)\n * @param event - The pointer/mouse event containing coordinates for positioning (optional, centers on element if not provided)\n */\n open(\n props?: P,\n triggerProps?: T,\n event?: NativeMouseEvent | NativePointerEvent | MouseEvent | PointerEvent,\n ): void;\n\n /**\n * Updates the props of the currently open menu without repositioning.\n * Props are merged with defaultMenuProps.\n */\n update(props: P, triggerProps?: T): void;\n\n /** Closes the menu programmatically. */\n close(): void;\n\n /** Current open/closed state of the menu. */\n isOpen: boolean;\n\n /**\n * JSX element that must be rendered in your component tree.\n * Contains the MenuTrigger and positioning logic.\n * IMPORTANT: Must be placed directly inside the target container (the element with targetRef).\n */\n get rendered(): ReactElement | null;\n}\n\n/**\n * Generic hook to manage a context menu component that opens at pointer coordinates.\n *\n * @param Component - A React component that represents the menu content (Menu or CommandMenu).\n * @param defaultTriggerProps - Default props to pass to the MenuTrigger.\n * @param defaultMenuProps - Default props to pass to the Menu component.\n * @returns An object with `targetRef` to attach to the container element, `open` function to open the menu at event coordinates, `close` function to close the menu, and `rendered` JSX element to include in your component tree.\n */\nexport function useContextMenu<\n E extends HTMLElement = HTMLElement,\n P extends object = {},\n T = ComponentProps<typeof MenuTrigger>,\n>(\n Component: ComponentType<P>,\n defaultTriggerProps?: Omit<\n ComponentProps<typeof MenuTrigger>,\n 'children' | 'isOpen' | 'onOpenChange' | 'targetRef'\n >,\n defaultMenuProps?: P,\n): UseContextMenuReturn<E, P, T> {\n const [isOpen, setIsOpen] = useState(false);\n const [componentProps, setComponentProps] = useState<P | null>(null);\n const [triggerProps, setTriggerProps] = useState<T | null>(null);\n const [anchorPosition, setAnchorPosition] = useState<{\n x: number;\n y: number;\n } | null>(null);\n const targetRef = useRef<E>(null);\n const invisibleAnchorRef = useRef<HTMLSpanElement>(null);\n const setupRef = useRef(false);\n\n // Generate a unique ID for this menu instance\n const menuId = useMemo(() => generateRandomId(), []);\n\n // Get event bus for menu synchronization\n const { emit, on } = useEventBus();\n\n // Listen for other menus opening and close this one if needed\n useEffect(() => {\n const unsubscribe = on('popover:open', (data: { menuId: string }) => {\n // If another menu is opening and this menu is open, close this one\n if (data.menuId !== menuId && isOpen) {\n setIsOpen(false);\n setAnchorPosition(null);\n }\n });\n\n return unsubscribe;\n }, [on, menuId, isOpen]);\n\n // Emit event when this menu opens\n useEffect(() => {\n if (isOpen) {\n emit('popover:open', { menuId });\n }\n }, [isOpen, emit, menuId]);\n\n function setupCheck() {\n if (!setupRef.current) {\n throw new Error(\n 'useContextMenu: MenuTrigger must be rendered. Use `rendered` property to include it in your component tree.',\n );\n }\n }\n\n // Helper function to calculate position relative to targetRef, taking the\n // element's scroll offset into account. Without the scroll offset the menu\n // would be rendered at the wrong place inside scrollable containers.\n const calculatePosition = (\n event?: NativeMouseEvent | NativePointerEvent | MouseEvent | PointerEvent,\n ) => {\n const container = targetRef.current;\n\n // If no event is provided, position at the center of the element\n if (!event) {\n if (!container) {\n return { x: 0, y: 0 };\n }\n\n const containerRect = container.getBoundingClientRect();\n const scrollLeft = container.scrollLeft;\n const scrollTop = container.scrollTop;\n\n const computed = window.getComputedStyle(container);\n const borderLeft = parseFloat(computed.borderLeftWidth) || 0;\n const borderTop = parseFloat(computed.borderTopWidth) || 0;\n\n // Position at the center of the element's content area\n const x = container.clientWidth / 2 + scrollLeft;\n const y = container.clientHeight / 2 + scrollTop;\n\n // Clamp to the full scroll size\n const clampedX = Math.max(0, Math.min(x, container.scrollWidth));\n const clampedY = Math.max(0, Math.min(y, container.scrollHeight));\n\n return { x: clampedX, y: clampedY };\n }\n\n // If the target reference is missing, fall back to viewport coordinates.\n if (!container) {\n const { clientX = 0, clientY = 0 } = event;\n\n return { x: clientX, y: clientY };\n }\n\n const containerRect = container.getBoundingClientRect();\n\n // Get coordinates from the event (viewport-relative)\n const { clientX, clientY } = event;\n\n // Take the element's scroll offset into account so that the coordinates are\n // relative to the **content** box, not the visible viewport of the\n // element.\n const scrollLeft = container.scrollLeft;\n const scrollTop = container.scrollTop;\n\n const computed = window.getComputedStyle(container);\n const borderLeft = parseFloat(computed.borderLeftWidth) || 0;\n const borderTop = parseFloat(computed.borderTopWidth) || 0;\n\n const x = clientX - containerRect.left - borderLeft + scrollLeft;\n const y = clientY - containerRect.top - borderTop + scrollTop;\n\n // Clamp to the full scroll size so that the invisible anchor always stays\n // inside the element regardless of the scroll position.\n const clampedX = Math.max(0, Math.min(x, container.scrollWidth));\n const clampedY = Math.max(0, Math.min(y, container.scrollHeight));\n\n return { x: clampedX, y: clampedY };\n };\n\n // 'open' accepts props, trigger props, and optional event for positioning, then opens the menu\n const open = useEvent(\n (\n props: P = {} as P,\n triggerProps?: T,\n event?: NativeMouseEvent | NativePointerEvent | MouseEvent | PointerEvent,\n ) => {\n setupCheck();\n\n // Ensure the target element can serve as a positioning context for the\n // invisible target element. If the consumer hasn't explicitly set\n // `position: relative | absolute | fixed | sticky` we switch it to\n // `relative` so that absolutely-positioned children are laid out correctly.\n if (targetRef.current) {\n const computedStyle = window.getComputedStyle(targetRef.current);\n\n if (computedStyle.position === 'static') {\n targetRef.current.style.position = 'relative';\n }\n }\n\n // Prevent default context menu if it's a context menu event\n if (\n event &&\n 'preventDefault' in event &&\n typeof event.preventDefault === 'function'\n ) {\n event.preventDefault();\n }\n\n const { x, y } = calculatePosition(event);\n setAnchorPosition({ x, y });\n\n // Merge defaultMenuProps with provided props\n const finalProps = defaultMenuProps\n ? { ...defaultMenuProps, ...props }\n : props;\n\n setComponentProps(finalProps);\n setTriggerProps(triggerProps ?? null);\n setIsOpen(true);\n },\n );\n\n const update = useEvent((props: P, triggerProps?: T) => {\n setupCheck();\n\n // Merge defaultMenuProps with provided props\n const finalProps = defaultMenuProps\n ? { ...defaultMenuProps, ...props }\n : props;\n\n setComponentProps(finalProps as P);\n setTriggerProps(triggerProps ?? null);\n });\n\n const close = useEvent(() => {\n setIsOpen(false);\n setAnchorPosition(null);\n });\n\n // Context menu event handler\n const onContextMenu = useEvent(\n (event: MouseEvent | PointerEvent | MouseEvent | PointerEvent) => {\n event.preventDefault();\n if (isOpen) {\n const pos = calculatePosition(event);\n setAnchorPosition(pos);\n } else {\n open(defaultMenuProps, undefined, event);\n }\n },\n );\n\n // Bind the onContextMenu event to targetRef\n useEffect(() => {\n const element = targetRef.current;\n if (!element) return;\n\n element.addEventListener('contextmenu', onContextMenu as any);\n\n return () => {\n element.removeEventListener('contextmenu', onContextMenu as any);\n };\n }, [onContextMenu]);\n\n // Render the menu only when componentProps is set\n const renderedMenu = useMemo(() => {\n if (!componentProps || !anchorPosition) return null;\n\n return (\n <>\n {/* Invisible anchor element positioned at click coordinates */}\n <span\n ref={invisibleAnchorRef}\n style={{\n position: 'absolute',\n left: `${anchorPosition.x}px`,\n top: `${anchorPosition.y}px`,\n width: '0px',\n height: '0px',\n lineHeight: '0',\n pointerEvents: 'none',\n visibility: 'hidden',\n }}\n />\n <MenuTrigger\n isDummy\n isOpen={isOpen}\n targetRef={invisibleAnchorRef}\n offset={0}\n crossOffset={0}\n placement={\n (triggerProps as ComponentProps<typeof MenuTrigger>)?.placement ||\n defaultTriggerProps?.placement ||\n 'bottom start'\n }\n onOpenChange={setIsOpen}\n {...mergeProps(defaultTriggerProps, triggerProps || undefined)}\n >\n <VisuallyHidden>\n <Pressable>\n <button aria-label=\"Open context menu\" />\n </Pressable>\n </VisuallyHidden>\n <Component {...componentProps} />\n </MenuTrigger>\n </>\n );\n }, [\n componentProps,\n triggerProps,\n isOpen,\n defaultTriggerProps,\n anchorPosition,\n ]);\n\n return {\n targetRef,\n open,\n update,\n close,\n isOpen,\n get rendered() {\n setupRef.current = true;\n\n return renderedMenu;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2EA,SAAgB,eAKd,WACA,qBAIA,kBAC+B;CAC/B,MAAM,CAAC,QAAQ,aAAa,SAAS,MAAM;CAC3C,MAAM,CAAC,gBAAgB,qBAAqB,SAAmB,KAAK;CACpE,MAAM,CAAC,cAAc,mBAAmB,SAAmB,KAAK;CAChE,MAAM,CAAC,gBAAgB,qBAAqB,SAGlC,KAAK;CACf,MAAM,YAAY,OAAU,KAAK;CACjC,MAAM,qBAAqB,OAAwB,KAAK;CACxD,MAAM,WAAW,OAAO,MAAM;CAG9B,MAAM,SAAS,cAAc,kBAAkB,EAAE,EAAE,CAAC;CAGpD,MAAM,EAAE,MAAM,OAAO,aAAa;AAGlC,iBAAgB;AASd,SARoB,GAAG,iBAAiB,SAA6B;AAEnE,OAAI,KAAK,WAAW,UAAU,QAAQ;AACpC,cAAU,MAAM;AAChB,sBAAkB,KAAK;;IAEzB;IAGD;EAAC;EAAI;EAAQ;EAAO,CAAC;AAGxB,iBAAgB;AACd,MAAI,OACF,MAAK,gBAAgB,EAAE,QAAQ,CAAC;IAEjC;EAAC;EAAQ;EAAM;EAAO,CAAC;CAE1B,SAAS,aAAa;AACpB,MAAI,CAAC,SAAS,QACZ,OAAM,IAAI,MACR,8GACD;;CAOL,MAAM,qBACJ,UACG;EAC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B,OAAU;cAE9D,oBAAC,4BACC,oBAAC,uBACC,oBAAC,YAAO,cAAW,sBAAsB,GAC/B,GACG,EACjB,oBAAC,aAAU,GAAI,iBAAkB;IACrB,IACb;IAEJ;EACD;EACA;EACA;EACA;EACA;EACD,CAAC;AAEF,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,IAAI,WAAW;AACb,YAAS,UAAU;AAEnB,UAAO;;EAEV"}
|
|
1
|
+
{"version":3,"file":"use-context-menu.js","names":["MenuTrigger","mergeProps"],"sources":["../../../src/components/actions/use-context-menu.tsx"],"sourcesContent":["import { Pressable } from '@react-aria/interactions';\nimport {\n ComponentProps,\n ComponentType,\n MouseEvent,\n PointerEvent,\n ReactElement,\n RefObject,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { VisuallyHidden } from 'react-aria';\n\nimport { useEvent } from '../../_internal';\nimport { generateRandomId } from '../../utils/random';\nimport { mergeProps } from '../../utils/react';\nimport { usePopoverSync } from '../../utils/react/usePopoverSync';\n\nimport { MenuTrigger } from './Menu';\n\ntype NativeMouseEvent = globalThis.MouseEvent;\ntype NativePointerEvent = globalThis.PointerEvent;\n\nexport interface UseContextMenuReturn<\n E extends HTMLElement = HTMLElement,\n P extends object = {},\n T = ComponentProps<typeof MenuTrigger>,\n> {\n /** Container element that receives context menu events. Attach this ref to your target element. */\n targetRef: RefObject<E | null>;\n\n /**\n * Programmatically opens the menu at the specified coordinates or element center.\n * Runtime props are merged with defaultMenuProps (runtime props take precedence).\n *\n * @param props - Props to pass to the menu component (optional, defaults to defaultMenuProps)\n * @param triggerProps - Additional props for MenuTrigger (merged with defaultTriggerProps)\n * @param event - The pointer/mouse event containing coordinates for positioning (optional, centers on element if not provided)\n */\n open(\n props?: P,\n triggerProps?: T,\n event?: NativeMouseEvent | NativePointerEvent | MouseEvent | PointerEvent,\n ): void;\n\n /**\n * Updates the props of the currently open menu without repositioning.\n * Props are merged with defaultMenuProps.\n */\n update(props: P, triggerProps?: T): void;\n\n /** Closes the menu programmatically. */\n close(): void;\n\n /** Current open/closed state of the menu. */\n isOpen: boolean;\n\n /**\n * JSX element that must be rendered in your component tree.\n * Contains the MenuTrigger and positioning logic.\n * IMPORTANT: Must be placed directly inside the target container (the element with targetRef).\n */\n get rendered(): ReactElement | null;\n}\n\n/**\n * Generic hook to manage a context menu component that opens at pointer coordinates.\n *\n * @param Component - A React component that represents the menu content (Menu or CommandMenu).\n * @param defaultTriggerProps - Default props to pass to the MenuTrigger.\n * @param defaultMenuProps - Default props to pass to the Menu component.\n * @returns An object with `targetRef` to attach to the container element, `open` function to open the menu at event coordinates, `close` function to close the menu, and `rendered` JSX element to include in your component tree.\n */\nexport function useContextMenu<\n E extends HTMLElement = HTMLElement,\n P extends object = {},\n T = ComponentProps<typeof MenuTrigger>,\n>(\n Component: ComponentType<P>,\n defaultTriggerProps?: Omit<\n ComponentProps<typeof MenuTrigger>,\n 'children' | 'isOpen' | 'onOpenChange' | 'targetRef'\n >,\n defaultMenuProps?: P,\n): UseContextMenuReturn<E, P, T> {\n const [isOpen, setIsOpen] = useState(false);\n const [componentProps, setComponentProps] = useState<P | null>(null);\n const [triggerProps, setTriggerProps] = useState<T | null>(null);\n const [anchorPosition, setAnchorPosition] = useState<{\n x: number;\n y: number;\n } | null>(null);\n const targetRef = useRef<E>(null);\n const invisibleAnchorRef = useRef<HTMLSpanElement>(null);\n const setupRef = useRef(false);\n\n // Mark the container as a popover trigger so that other open menus' close-on-\n // outside predicates treat clicks inside it (including programmatic\n // open buttons rendered alongside a context-menu target) as a legitimate\n // trigger interaction instead of a generic outside click. This mirrors the\n // pattern in `useAnchoredMenu`.\n useEffect(() => {\n const el = targetRef.current;\n if (el) {\n el.dataset.popoverTrigger = '';\n return () => {\n delete el.dataset.popoverTrigger;\n };\n }\n }, []);\n\n // Generate a unique ID for this menu instance\n const menuId = useMemo(() => generateRandomId(), []);\n\n usePopoverSync({\n menuId,\n isOpen,\n onClose: () => {\n setIsOpen(false);\n setAnchorPosition(null);\n },\n });\n\n function setupCheck() {\n if (!setupRef.current) {\n throw new Error(\n 'useContextMenu: MenuTrigger must be rendered. Use `rendered` property to include it in your component tree.',\n );\n }\n }\n\n // Helper function to calculate position relative to targetRef, taking the\n // element's scroll offset into account. Without the scroll offset the menu\n // would be rendered at the wrong place inside scrollable containers.\n const calculatePosition = (\n event?: NativeMouseEvent | NativePointerEvent | MouseEvent | PointerEvent,\n ) => {\n const container = targetRef.current;\n\n // If no event is provided, position at the center of the element\n if (!event) {\n if (!container) {\n return { x: 0, y: 0 };\n }\n\n const containerRect = container.getBoundingClientRect();\n const scrollLeft = container.scrollLeft;\n const scrollTop = container.scrollTop;\n\n const computed = window.getComputedStyle(container);\n const borderLeft = parseFloat(computed.borderLeftWidth) || 0;\n const borderTop = parseFloat(computed.borderTopWidth) || 0;\n\n // Position at the center of the element's content area\n const x = container.clientWidth / 2 + scrollLeft;\n const y = container.clientHeight / 2 + scrollTop;\n\n // Clamp to the full scroll size\n const clampedX = Math.max(0, Math.min(x, container.scrollWidth));\n const clampedY = Math.max(0, Math.min(y, container.scrollHeight));\n\n return { x: clampedX, y: clampedY };\n }\n\n // If the target reference is missing, fall back to viewport coordinates.\n if (!container) {\n const { clientX = 0, clientY = 0 } = event;\n\n return { x: clientX, y: clientY };\n }\n\n const containerRect = container.getBoundingClientRect();\n\n // Get coordinates from the event (viewport-relative)\n const { clientX, clientY } = event;\n\n // Take the element's scroll offset into account so that the coordinates are\n // relative to the **content** box, not the visible viewport of the\n // element.\n const scrollLeft = container.scrollLeft;\n const scrollTop = container.scrollTop;\n\n const computed = window.getComputedStyle(container);\n const borderLeft = parseFloat(computed.borderLeftWidth) || 0;\n const borderTop = parseFloat(computed.borderTopWidth) || 0;\n\n const x = clientX - containerRect.left - borderLeft + scrollLeft;\n const y = clientY - containerRect.top - borderTop + scrollTop;\n\n // Clamp to the full scroll size so that the invisible anchor always stays\n // inside the element regardless of the scroll position.\n const clampedX = Math.max(0, Math.min(x, container.scrollWidth));\n const clampedY = Math.max(0, Math.min(y, container.scrollHeight));\n\n return { x: clampedX, y: clampedY };\n };\n\n // 'open' accepts props, trigger props, and optional event for positioning, then opens the menu\n const open = useEvent(\n (\n props: P = {} as P,\n triggerProps?: T,\n event?: NativeMouseEvent | NativePointerEvent | MouseEvent | PointerEvent,\n ) => {\n setupCheck();\n\n // Ensure the target element can serve as a positioning context for the\n // invisible target element. If the consumer hasn't explicitly set\n // `position: relative | absolute | fixed | sticky` we switch it to\n // `relative` so that absolutely-positioned children are laid out correctly.\n if (targetRef.current) {\n const computedStyle = window.getComputedStyle(targetRef.current);\n\n if (computedStyle.position === 'static') {\n targetRef.current.style.position = 'relative';\n }\n }\n\n // Prevent default context menu if it's a context menu event\n if (\n event &&\n 'preventDefault' in event &&\n typeof event.preventDefault === 'function'\n ) {\n event.preventDefault();\n }\n\n const { x, y } = calculatePosition(event);\n setAnchorPosition({ x, y });\n\n // Merge defaultMenuProps with provided props\n const finalProps = defaultMenuProps\n ? { ...defaultMenuProps, ...props }\n : props;\n\n setComponentProps(finalProps);\n setTriggerProps(triggerProps ?? null);\n setIsOpen(true);\n },\n );\n\n const update = useEvent((props: P, triggerProps?: T) => {\n setupCheck();\n\n // Merge defaultMenuProps with provided props\n const finalProps = defaultMenuProps\n ? { ...defaultMenuProps, ...props }\n : props;\n\n setComponentProps(finalProps as P);\n setTriggerProps(triggerProps ?? null);\n });\n\n const close = useEvent(() => {\n setIsOpen(false);\n setAnchorPosition(null);\n });\n\n // Context menu event handler\n const onContextMenu = useEvent(\n (event: MouseEvent | PointerEvent | MouseEvent | PointerEvent) => {\n event.preventDefault();\n if (isOpen) {\n const pos = calculatePosition(event);\n setAnchorPosition(pos);\n } else {\n open(defaultMenuProps, undefined, event);\n }\n },\n );\n\n // Bind the onContextMenu event to targetRef\n useEffect(() => {\n const element = targetRef.current;\n if (!element) return;\n\n element.addEventListener('contextmenu', onContextMenu as any);\n\n return () => {\n element.removeEventListener('contextmenu', onContextMenu as any);\n };\n }, [onContextMenu]);\n\n // Render the menu only when componentProps is set\n const renderedMenu = useMemo(() => {\n if (!componentProps || !anchorPosition) return null;\n\n return (\n <>\n {/* Invisible anchor element positioned at click coordinates */}\n <span\n ref={invisibleAnchorRef}\n style={{\n position: 'absolute',\n left: `${anchorPosition.x}px`,\n top: `${anchorPosition.y}px`,\n width: '0px',\n height: '0px',\n lineHeight: '0',\n pointerEvents: 'none',\n visibility: 'hidden',\n }}\n />\n <MenuTrigger\n isDummy\n isOpen={isOpen}\n targetRef={invisibleAnchorRef}\n offset={0}\n crossOffset={0}\n placement={\n (triggerProps as ComponentProps<typeof MenuTrigger>)?.placement ||\n defaultTriggerProps?.placement ||\n 'bottom start'\n }\n onOpenChange={setIsOpen}\n {...mergeProps(defaultTriggerProps, triggerProps || undefined)}\n >\n <VisuallyHidden>\n <Pressable>\n <button aria-label=\"Open context menu\" />\n </Pressable>\n </VisuallyHidden>\n <Component {...componentProps} />\n </MenuTrigger>\n </>\n );\n }, [\n componentProps,\n triggerProps,\n isOpen,\n defaultTriggerProps,\n anchorPosition,\n ]);\n\n return {\n targetRef,\n open,\n update,\n close,\n isOpen,\n get rendered() {\n setupRef.current = true;\n\n return renderedMenu;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2EA,SAAgB,eAKd,WACA,qBAIA,kBAC+B;CAC/B,MAAM,CAAC,QAAQ,aAAa,SAAS,MAAM;CAC3C,MAAM,CAAC,gBAAgB,qBAAqB,SAAmB,KAAK;CACpE,MAAM,CAAC,cAAc,mBAAmB,SAAmB,KAAK;CAChE,MAAM,CAAC,gBAAgB,qBAAqB,SAGlC,KAAK;CACf,MAAM,YAAY,OAAU,KAAK;CACjC,MAAM,qBAAqB,OAAwB,KAAK;CACxD,MAAM,WAAW,OAAO,MAAM;AAO9B,iBAAgB;EACd,MAAM,KAAK,UAAU;AACrB,MAAI,IAAI;AACN,MAAG,QAAQ,iBAAiB;AAC5B,gBAAa;AACX,WAAO,GAAG,QAAQ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eAAe,EAAE;IAC1B,KAAK,GAAG,eAAe,EAAE;IACzB,OAAO;IACP,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,YAAY;IACb;IACD,EACF,qBAACA;GACC;GACQ;GACR,WAAW;GACX,QAAQ;GACR,aAAa;GACb,WACG,cAAqD,aACtD,qBAAqB,aACrB;GAEF,cAAc;GACd,GAAIC,aAAW,qBAAqB,gBAAgB,OAAU;cAE9D,oBAAC,4BACC,oBAAC,uBACC,oBAAC,YAAO,cAAW,sBAAsB,GAC/B,GACG,EACjB,oBAAC,aAAU,GAAI,iBAAkB;IACrB,IACb;IAEJ;EACD;EACA;EACA;EACA;EACA;EACD,CAAC;AAEF,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,IAAI,WAAW;AACb,YAAS,UAAU;AAEnB,UAAO;;EAEV"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | 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 { useFocus as useFocus$1 } from "../../../utils/react/interactions.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { extractStyles } from "../../../utils/styles.js";
|
|
3
3
|
import { useDeprecationWarning } from "../../../_internal/hooks/use-deprecation-warning.js";
|
|
4
4
|
import { CONTAINER_STYLES, TEXT_STYLES, filterBaseProps } from "@tenphi/tasty";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { extractStyles } from "../../../utils/styles.js";
|
|
3
3
|
import { CONTAINER_STYLES, Element, filterBaseProps } from "@tenphi/tasty";
|
|
4
4
|
import { forwardRef } from "react";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { extractStyles } from "../../../utils/styles.js";
|
|
3
3
|
import { CONTAINER_STYLES, filterBaseProps, tasty } from "@tenphi/tasty";
|
|
4
4
|
import { forwardRef } from "react";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { extractStyles } from "../../utils/styles.js";
|
|
3
3
|
import { useSlotProps } from "../../utils/react/Slots.js";
|
|
4
4
|
import { CONTAINER_STYLES, TEXT_STYLES, filterBaseProps, tasty } from "@tenphi/tasty";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.136.0 | Cube Dev Team */
|
|
2
2
|
import { extractStyles } from "../../../utils/styles.js";
|
|
3
3
|
import { useTimer } from "../../../_internal/hooks/use-timer/use-timer.js";
|
|
4
4
|
import { CopyIcon } from "../../../icons/CopyIcon.js";
|