@funstack/ui 0.1.0-alpha.11 → 0.1.0-alpha.12
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/accordion/accordion-context.mjs.map +1 -1
- package/dist/accordion/accordion-item.d.mts +3 -4
- package/dist/accordion/accordion-item.d.mts.map +1 -1
- package/dist/accordion/accordion-item.mjs +10 -4
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-panel.d.mts +3 -4
- package/dist/accordion/accordion-panel.d.mts.map +1 -1
- package/dist/accordion/accordion-panel.mjs +2 -1
- package/dist/accordion/accordion-panel.mjs.map +1 -1
- package/dist/accordion/accordion-root.d.mts +3 -3
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +8 -19
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts +3 -4
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +5 -3
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/button/button.d.mts +4 -2
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +3 -2
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.d.mts +4 -5
- package/dist/checkbox/checkbox.d.mts.map +1 -1
- package/dist/checkbox/checkbox.mjs +16 -59
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-context.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-item.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +21 -27
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-label.mjs +1 -6
- package/dist/checkbox-group/checkbox-group-label.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-parent.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +12 -10
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +74 -101
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +5 -6
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-group.d.mts.map +1 -1
- package/dist/combobox/combobox-group.mjs +2 -1
- package/dist/combobox/combobox-group.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +14 -7
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts.map +1 -1
- package/dist/combobox/combobox-list.mjs +6 -10
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +2 -1
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs +9 -25
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +30 -102
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +6 -25
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/index.mjs +1 -1
- package/dist/combobox/use-combobox-form.mjs +56 -0
- package/dist/combobox/use-combobox-form.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +62 -0
- package/dist/combobox/use-option-registry.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +29 -62
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +5 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +3 -4
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +37 -98
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +30 -118
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +13 -16
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/field/field-control.mjs +6 -13
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts.map +1 -1
- package/dist/field/field-description.mjs +1 -2
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts.map +1 -1
- package/dist/field/field-error.mjs +1 -2
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +3 -11
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +21 -41
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.mjs +1 -1
- package/dist/field/use-server-error-visibility.mjs +44 -0
- package/dist/field/use-server-error-visibility.mjs.map +1 -0
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +6 -7
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +1 -1
- package/dist/form/form-submit.mjs +4 -10
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/internal/anchor-position.mjs +1 -59
- package/dist/internal/anchor-position.mjs.map +1 -1
- package/dist/internal/announce.mjs.map +1 -1
- package/dist/internal/arrow-keys.mjs +21 -0
- package/dist/internal/arrow-keys.mjs.map +1 -0
- package/dist/internal/decimal.mjs +7 -1
- package/dist/internal/decimal.mjs.map +1 -1
- package/dist/internal/dom-order.mjs +17 -0
- package/dist/internal/dom-order.mjs.map +1 -0
- package/dist/internal/field-context.d.mts.map +1 -1
- package/dist/internal/field-context.mjs +11 -1
- package/dist/internal/field-context.mjs.map +1 -1
- package/dist/internal/focus-first-invalid.mjs +1 -1
- package/dist/internal/focus-first-invalid.mjs.map +1 -1
- package/dist/internal/group-member.mjs +37 -0
- package/dist/internal/group-member.mjs.map +1 -0
- package/dist/internal/overlay-popup.mjs +103 -0
- package/dist/internal/overlay-popup.mjs.map +1 -0
- package/dist/internal/popover-open.mjs +18 -0
- package/dist/internal/popover-open.mjs.map +1 -0
- package/dist/internal/render-element.d.mts +2 -0
- package/dist/internal/render-element.mjs +20 -2
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/shipped-styles.mjs +14 -0
- package/dist/internal/shipped-styles.mjs.map +1 -0
- package/dist/internal/sync-presence.mjs +5 -1
- package/dist/internal/sync-presence.mjs.map +1 -1
- package/dist/internal/toolbar-context.mjs.map +1 -1
- package/dist/internal/tooltip-warm.mjs +1 -1
- package/dist/internal/tooltip-warm.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +1 -1
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/types.d.mts +2 -0
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +5 -23
- package/dist/internal/use-action-trigger.mjs.map +1 -1
- package/dist/internal/use-checkable-input.mjs +79 -0
- package/dist/internal/use-checkable-input.mjs.map +1 -0
- package/dist/internal/use-controllable-action.mjs +16 -24
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- package/dist/internal/use-dev-warning.mjs +8 -4
- package/dist/internal/use-dev-warning.mjs.map +1 -1
- package/dist/internal/use-element-check.mjs +39 -0
- package/dist/internal/use-element-check.mjs.map +1 -0
- package/dist/internal/use-exit-animation.mjs +1 -1
- package/dist/internal/use-exit-animation.mjs.map +1 -1
- package/dist/internal/use-field-control.mjs +28 -12
- package/dist/internal/use-field-control.mjs.map +1 -1
- package/dist/internal/use-fieldset-group.mjs +46 -0
- package/dist/internal/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/use-form-reset.mjs +1 -5
- package/dist/internal/use-form-reset.mjs.map +1 -1
- package/dist/internal/use-item-order.mjs +42 -0
- package/dist/internal/use-item-order.mjs.map +1 -0
- package/dist/internal/use-latest.mjs +4 -8
- package/dist/internal/use-latest.mjs.map +1 -1
- package/dist/internal/use-merged-refs.mjs +19 -0
- package/dist/internal/use-merged-refs.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +84 -0
- package/dist/internal/use-name-warning.mjs.map +1 -0
- package/dist/internal/use-native-checked.mjs +4 -6
- package/dist/internal/use-native-checked.mjs.map +1 -1
- package/dist/internal/use-native-focusgroup.mjs +19 -0
- package/dist/internal/use-native-focusgroup.mjs.map +1 -0
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-overlay-close.mjs +63 -0
- package/dist/internal/use-overlay-close.mjs.map +1 -0
- package/dist/internal/{use-popover-root.mjs → use-overlay-root.mjs} +28 -39
- package/dist/internal/use-overlay-root.mjs.map +1 -0
- package/dist/internal/use-popover-popup.mjs +32 -78
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.d.mts +15 -0
- package/dist/internal/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/use-popover-trigger.mjs +13 -17
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/use-register-count.mjs +24 -0
- package/dist/internal/use-register-count.mjs.map +1 -0
- package/dist/internal/use-render.d.mts +2 -0
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-resolved-placement.mjs +38 -22
- package/dist/internal/use-resolved-placement.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs +5 -18
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/internal/use-superseded-rejection.mjs +47 -0
- package/dist/internal/use-superseded-rejection.mjs.map +1 -0
- package/dist/internal/validity.mjs +1 -13
- package/dist/internal/validity.mjs.map +1 -1
- package/dist/internal/value-set.mjs +41 -0
- package/dist/internal/value-set.mjs.map +1 -0
- package/dist/menu/index.d.mts +1 -1
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context-trigger.d.mts +2 -7
- package/dist/menu/menu-context-trigger.d.mts.map +1 -1
- package/dist/menu/menu-context-trigger.mjs +10 -187
- package/dist/menu/menu-context-trigger.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-dom.mjs +1 -2
- package/dist/menu/menu-dom.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +167 -0
- package/dist/menu/menu-gestures.mjs.map +1 -0
- package/dist/menu/menu-group.d.mts.map +1 -1
- package/dist/menu/menu-group.mjs +2 -1
- package/dist/menu/menu-group.mjs.map +1 -1
- package/dist/menu/menu-hover.mjs +0 -1
- package/dist/menu/menu-hover.mjs.map +1 -1
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +101 -0
- package/dist/menu/menu-outside.mjs.map +1 -0
- package/dist/menu/menu-point.mjs +85 -0
- package/dist/menu/menu-point.mjs.map +1 -0
- package/dist/menu/menu-popup.d.mts +6 -7
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +37 -248
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.d.mts +10 -0
- package/dist/menu/menu-root.d.mts.map +1 -1
- package/dist/menu/menu-root.mjs +10 -8
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +6 -6
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +4 -9
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +8 -6
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menu/use-menu-item.mjs +14 -16
- package/dist/menu/use-menu-item.mjs.map +1 -1
- package/dist/menu/use-menu-keyboard.mjs +88 -0
- package/dist/menu/use-menu-keyboard.mjs.map +1 -0
- package/dist/meter/meter-root.mjs +1 -1
- package/dist/number-field/index.d.mts +2 -1
- package/dist/number-field/index.d.mts.map +1 -1
- package/dist/number-field/index.mjs +2 -2
- package/dist/number-field/index.mjs.map +1 -1
- package/dist/number-field/number-field-arithmetic.mjs +30 -11
- package/dist/number-field/number-field-arithmetic.mjs.map +1 -1
- package/dist/number-field/number-field-context.d.mts +6 -1
- package/dist/number-field/number-field-context.d.mts.map +1 -0
- package/dist/number-field/number-field-context.mjs.map +1 -1
- package/dist/number-field/number-field-decrement.d.mts +1 -1
- package/dist/number-field/number-field-decrement.mjs +1 -1
- package/dist/number-field/number-field-decrement.mjs.map +1 -1
- package/dist/number-field/number-field-increment.d.mts +2 -22
- package/dist/number-field/number-field-increment.d.mts.map +1 -1
- package/dist/number-field/number-field-increment.mjs +2 -53
- package/dist/number-field/number-field-increment.mjs.map +1 -1
- package/dist/number-field/number-field-input.d.mts.map +1 -1
- package/dist/number-field/number-field-input.mjs +18 -22
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-label.d.mts.map +1 -1
- package/dist/number-field/number-field-label.mjs +3 -9
- package/dist/number-field/number-field-label.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts +2 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +81 -91
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/number-field/use-number-field-dev-warnings.mjs +28 -0
- package/dist/number-field/use-number-field-dev-warnings.mjs.map +1 -0
- package/dist/number-field/use-step-button.d.mts +24 -0
- package/dist/number-field/use-step-button.d.mts.map +1 -0
- package/dist/number-field/use-step-button.mjs +57 -3
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +28 -67
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-context.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +9 -6
- package/dist/popover/popover-popup.d.mts.map +1 -1
- package/dist/popover/popover-popup.mjs +13 -36
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +4 -3
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +4 -8
- package/dist/popover/popover-trigger.d.mts.map +1 -1
- package/dist/popover/popover-trigger.mjs +2 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/progress/progress-root.mjs +1 -1
- package/dist/radio-group/radio-group-context.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.d.mts +3 -4
- package/dist/radio-group/radio-group-item.d.mts.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +20 -25
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-label.mjs +1 -6
- package/dist/radio-group/radio-group-label.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +21 -40
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-dom.mjs +9 -18
- package/dist/select/select-dom.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-root.mjs +3 -2
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/slider/slider-arithmetic.mjs +74 -13
- package/dist/slider/slider-arithmetic.mjs.map +1 -1
- package/dist/slider/slider-context.mjs.map +1 -1
- package/dist/slider/slider-label.d.mts.map +1 -1
- package/dist/slider/slider-label.mjs +3 -9
- package/dist/slider/slider-label.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts +2 -2
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +36 -116
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/slider-thumb.d.mts.map +1 -1
- package/dist/slider/slider-thumb.mjs +8 -6
- package/dist/slider/slider-thumb.mjs.map +1 -1
- package/dist/slider/slider-value.d.mts.map +1 -1
- package/dist/slider/slider-value.mjs +2 -1
- package/dist/slider/slider-value.mjs.map +1 -1
- package/dist/slider/use-slider-dev-warnings.mjs +29 -0
- package/dist/slider/use-slider-dev-warnings.mjs.map +1 -0
- package/dist/slider/use-thumb-registry.mjs +51 -0
- package/dist/slider/use-thumb-registry.mjs.map +1 -0
- package/dist/switch/switch.d.mts +4 -5
- package/dist/switch/switch.d.mts.map +1 -1
- package/dist/switch/switch.mjs +15 -55
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-context.d.mts +2 -3
- package/dist/tabs/tabs-context.d.mts.map +1 -1
- package/dist/tabs/tabs-context.mjs.map +1 -1
- package/dist/tabs/tabs-list.d.mts.map +1 -1
- package/dist/tabs/tabs-list.mjs +9 -22
- package/dist/tabs/tabs-list.mjs.map +1 -1
- package/dist/tabs/tabs-panel.d.mts +3 -4
- package/dist/tabs/tabs-panel.d.mts.map +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts +4 -3
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +2 -1
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/tabs/tabs-tab.d.mts +3 -4
- package/dist/tabs/tabs-tab.d.mts.map +1 -1
- package/dist/tabs/tabs-tab.mjs.map +1 -1
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +2 -8
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-context.mjs.map +1 -1
- package/dist/toast/toast-hotkey.mjs +27 -0
- package/dist/toast/toast-hotkey.mjs.map +1 -0
- package/dist/toast/toast-queue.mjs +137 -0
- package/dist/toast/toast-queue.mjs.map +1 -0
- package/dist/toast/toast-timers.mjs +65 -0
- package/dist/toast/toast-timers.mjs.map +1 -0
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +30 -235
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/toast.mjs +1 -1
- package/dist/toast/toast.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +52 -0
- package/dist/toast/use-modal-portal-host.mjs.map +1 -0
- package/dist/toggle/toggle.d.mts +3 -4
- package/dist/toggle/toggle.d.mts.map +1 -1
- package/dist/toggle/toggle.mjs +7 -10
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-context.d.mts +2 -1
- package/dist/toggle-group/toggle-group-context.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-context.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-item.d.mts +5 -3
- package/dist/toggle-group/toggle-group-item.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-item.mjs +5 -7
- package/dist/toggle-group/toggle-group-item.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +29 -64
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/toolbar/toolbar-root.d.mts +2 -2
- package/dist/toolbar/toolbar-root.d.mts.map +1 -1
- package/dist/toolbar/toolbar-root.mjs +3 -4
- package/dist/toolbar/toolbar-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-context.d.mts +1 -1
- package/dist/tooltip/tooltip-context.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +6 -15
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +2 -2
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.d.mts +2 -1
- package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +3 -2
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/tooltip/use-tooltip-interaction.mjs +4 -3
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/accordion/accordion-context.d.mts +0 -5
- package/dist/accordion/accordion-context.d.mts.map +0 -1
- package/dist/internal/use-popover-root.mjs.map +0 -1
- /package/dist/internal/{use-popover-root.d.mts → use-overlay-root.d.mts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-context-trigger.mjs","names":[],"sources":["../../src/menu/menu-context-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport {\n claimPress,\n isPressClaimed,\n markHandled,\n MenuRegionContext,\n submenuHover,\n useMenuContext,\n} from \"./menu-context.js\";\nimport { capturePointer, isDisabledItem, isEditableTarget, ITEM_SELECTOR } from \"./menu-dom.js\";\n\nexport interface MenuContextTriggerState {\n /** Optimistic open state (the Root's). */\n readonly open: boolean;\n /** The Root's transition is pending (an open or a close in flight). */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface MenuContextTriggerProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"onContextMenu\"\n | \"onPointerDown\"\n | \"onPointerMove\"\n | \"onPointerUp\"\n | \"onPointerCancel\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The region does nothing; a `contextmenu` bubbles on to an outer region. `data-disabled`. */\n disabled?: boolean;\n /**\n * What a `contextmenu` (or long-press) on an editable target inside the region opens: the\n * browser's own menu (`\"native\"`, default: copy and paste keep working) or this menu.\n * Editable: a text-taking `<input>`, a `<textarea>`, an element with `isContentEditable`.\n */\n editableTargets?: \"native\" | \"menu\";\n /** Milliseconds a touch or pen pointer must stay down (within 10 px) to open. Default 500. */\n longPressDelay?: number;\n className?: StateValue<string | undefined, MenuContextTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuContextTriggerState>;\n children?: StateValue<ReactNode, MenuContextTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuContextTriggerState>;\n}\n\n/** Movement that cancels a long-press (Base UI's slop); also a touch drag's activation slop. */\nconst LONG_PRESS_SLOP = 10;\n/**\n * Movement a mouse or pen press-drag-release needs before a release activates or dismisses\n * (Chromium's `kMaximumLengthMovedToActivate`, macOS's \"moved\"; context-menu.md 2.6).\n */\nconst DRAG_SLOP = 4;\n/** A release outside the menu dismisses it only this long after the open (GTK, Base UI). */\nconst DRAG_DISMISS_DELAY = 500;\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\ninterface LongPress {\n readonly pointerId: number;\n readonly pointerType: string;\n readonly x: number;\n readonly y: number;\n readonly timer: ReturnType<typeof setTimeout>;\n}\n\ninterface DragOptions {\n readonly pointerId: number;\n /** The open point: the slop is measured from it. */\n readonly x: number;\n readonly y: number;\n readonly slop: number;\n /**\n * Activates `item` for a release: through `item.click()`, with the click swallow of a long-press\n * out of the way and armed again for the click an engine may synthesise from this release.\n */\n readonly activate: (item: HTMLElement) => void;\n}\n\nconst isTouchLike = (pointerType: string) => pointerType === \"touch\" || pointerType === \"pen\";\n\n/**\n * Press-drag-release (context-menu.md 2.6): while the popup holds the capture of `pointerId`\n * (taken at the open), every `pointermove` and the `pointerup` target the popup and items never\n * see boundary events, so the gesture hit-tests with `elementFromPoint`. A move focuses the item\n * under the pointer quietly (a SubmenuTrigger also starts its hover intent); a release more than\n * the slop away from the open point activates an enabled, non-submenu item through its\n * `click()` (Menu's one activation path), or dismisses the menu when it lands outside every popup\n * of the tree at least 500 ms after the open; any other release leaves the menu open. Ends at the\n * release, `pointercancel`, `lostpointercapture` and the menu closing. Returns the cleanup.\n *\n * The 500 ms count from when the popup is shown, not from the press: with an async\n * `openChangeAction` or suspending items the menu appears only when they settle (review M2). A\n * gesture that starts on a popup already showing (a move) counts from its start.\n */\nfunction startDrag(popup: HTMLElement, options: DragOptions): () => void {\n const doc = popup.ownerDocument;\n // `performance.now()` at the first open `toggle`; null until the popup has been shown.\n let shownAt: number | null = popup.matches(\":popover-open\") ? performance.now() : null;\n // The SubmenuTrigger the pointer is over, whose hover intent is running.\n let submenuTrigger: HTMLElement | null = null;\n\n const ours = (event: Event) => (event as globalThis.PointerEvent).pointerId === options.pointerId;\n const hitTest = (event: globalThis.PointerEvent): Element | null =>\n typeof doc.elementFromPoint === \"function\"\n ? doc.elementFromPoint(event.clientX, event.clientY)\n : null;\n /** The item under the pointer, inside this menu's tree (submenus are DOM descendants). */\n const itemAt = (target: Element | null): HTMLElement | null => {\n const item = target?.closest<HTMLElement>(ITEM_SELECTOR) ?? null;\n return item !== null && popup.contains(item) ? item : null;\n };\n /** The pointer is over the submenu `trigger` opens (its popup is the `commandfor` target). */\n const inSubmenuOf = (trigger: HTMLElement, target: Element | null) => {\n const id = trigger.getAttribute(\"commandfor\");\n const submenu = id === null ? null : doc.getElementById(id);\n return submenu !== null && target !== null && submenu.contains(target);\n };\n const hoverSubmenu = (next: HTMLElement | null, event: Event) => {\n if (next === submenuTrigger) return;\n if (submenuTrigger !== null) submenuHover(submenuTrigger)?.leave(event);\n submenuTrigger = next;\n if (next !== null) submenuHover(next)?.enter(event);\n };\n\n const onMove = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n const target = hitTest(event);\n const item = itemAt(target);\n // Menu 6.2's pointer focus, without the ring: keyboard and pointer agree on the current item.\n if (item !== null && doc.activeElement !== item) {\n item.focus({ focusVisible: false } as FocusOptions);\n }\n if (item !== null && submenuHover(item) !== undefined) hoverSubmenu(item, event);\n else if (submenuTrigger !== null && !inSubmenuOf(submenuTrigger, target)) {\n hoverSubmenu(null, event);\n }\n };\n const onUp = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n end();\n const moved = Math.hypot(event.clientX - options.x, event.clientY - options.y) > options.slop;\n // Time alone never activates or dismisses: a stationary release keeps the menu open.\n if (!moved) return;\n const target = hitTest(event);\n if (target !== null && popup.contains(target)) {\n const item = itemAt(target);\n // A disabled item, a SubmenuTrigger (native menus activate nothing there), a separator or\n // padding: the menu stays open.\n if (item === null || isDisabledItem(item) || item.hasAttribute(\"aria-haspopup\")) return;\n options.activate(item);\n return;\n }\n if (\n shownAt !== null &&\n performance.now() - shownAt >= DRAG_DISMISS_DELAY &&\n popup.matches(\":popover-open\")\n ) {\n popup.hidePopover();\n }\n };\n const onEnd = (event: Event) => {\n if (ours(event)) end();\n };\n const onToggle = () => {\n if (!popup.matches(\":popover-open\")) end();\n else shownAt ??= performance.now();\n };\n const end = () => {\n popup.removeEventListener(\"pointermove\", onMove);\n popup.removeEventListener(\"pointerup\", onUp);\n popup.removeEventListener(\"pointercancel\", onEnd);\n popup.removeEventListener(\"lostpointercapture\", onEnd);\n popup.removeEventListener(\"toggle\", onToggle);\n submenuTrigger = null;\n };\n popup.addEventListener(\"pointermove\", onMove);\n popup.addEventListener(\"pointerup\", onUp);\n popup.addEventListener(\"pointercancel\", onEnd);\n popup.addEventListener(\"lostpointercapture\", onEnd);\n popup.addEventListener(\"toggle\", onToggle);\n return end;\n}\n\n/** How long the touch guard waits for the `touchend` that follows the finger's `pointerup`. */\nconst TOUCH_END_WAIT = 250;\n\n/**\n * While the finger that opened a touch menu is still down, the browser must not take its drag\n * as a pan (it would end the stream with `pointercancel`): a non-passive document `touchmove`\n * listener prevents it (context-menu.md 2.2). The lift's `touchend`, which follows that\n * pointer's `pointerup`, is prevented as well, so the engine synthesises no click from it: a click\n * where the finger was (beside the offset menu) would light-dismiss the menu in Chromium, and one\n * over an item would activate it a second time. Ends at that `touchend` / `touchcancel`, at the\n * pointer's `pointercancel`, and shortly after its `pointerup` if no touch event follows (a\n * synthetic pointer). Returns the cleanup.\n *\n * Only the gesture finger's lift ends it (review L4): another finger lifting while it is still\n * down must not hand its next slide to panning. Pointer events expose no `Touch.identifier`, so\n * the lift is recognised by order: the engines dispatch a lift's `pointerup` and `touchend` from\n * the same input, the `pointerup` first. A `touchend` before that pointer's `pointerup` is another\n * finger's; it is still prevented (no click may light-dismiss the menu mid-gesture).\n */\nfunction guardTouch(doc: Document, pointerId: number): () => void {\n let fallback: ReturnType<typeof setTimeout> | undefined;\n // The gesture's pointer has lifted: the next `touchend` is its own.\n let lifted = false;\n const onTouchMove = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n };\n const onTouchEnd = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n if (lifted) end();\n };\n const onPointerUp = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n lifted = true;\n fallback ??= setTimeout(end, TOUCH_END_WAIT);\n };\n const onPointerCancel = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId === pointerId) end();\n };\n const end = () => {\n if (fallback !== undefined) clearTimeout(fallback);\n doc.removeEventListener(\"touchmove\", onTouchMove);\n doc.removeEventListener(\"touchend\", onTouchEnd);\n doc.removeEventListener(\"touchcancel\", end, true);\n doc.removeEventListener(\"pointerup\", onPointerUp, true);\n doc.removeEventListener(\"pointercancel\", onPointerCancel, true);\n };\n doc.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n doc.addEventListener(\"touchend\", onTouchEnd, { passive: false });\n doc.addEventListener(\"touchcancel\", end, true);\n doc.addEventListener(\"pointerup\", onPointerUp, true);\n doc.addEventListener(\"pointercancel\", onPointerCancel, true);\n return end;\n}\n\n/**\n * A region whose `contextmenu` (right-click, Ctrl+click, Shift+F10 / the ContextMenu key at a\n * focused descendant) or touch / pen long-press opens the Root's `Menu.Popup` at the pointer\n * (design/components/context-menu.md). A plain element (default `div`) with no role and no ARIA:\n * the region keeps its own semantics (`render={<tr />}`), and keyboard users reach it through\n * focusable content inside it. A second right-click inside the region while the menu is open moves\n * the menu there. Render the `Menu.Popup` as a sibling of the region where the markup allows; in\n * a table row (`render={<tr />}`), inside one of its cells: events from inside the popup are\n * never the region's.\n *\n * Owned keys (conventions 1.2): `onContextMenu`, `onPointerDown`, `onPointerMove`,\n * `onPointerUp`, `onPointerCancel`, `data-open`, `data-pending`, `data-disabled`, and the style\n * key `WebkitTouchCallout` (`\"none\"`; the consumer's `style` wins).\n */\nexport function MenuContextTrigger({\n disabled = false,\n editableTargets = \"native\",\n longPressDelay = 500,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuContextTriggerProps) {\n const menu = useMenuContext(\"Menu.ContextTrigger\");\n const { popover } = menu;\n useDevWarning(\n menu.submenu,\n \"Menu.ContextTrigger: rendered in a submenu. A Menu.Root inside a Menu.Popup is a submenu; a \" +\n \"context menu region belongs to a top-level Menu.Root.\",\n );\n useDevWarning(\n longPressDelay < 0,\n \"Menu.ContextTrigger: `longPressDelay` is negative; it is a number of milliseconds.\",\n );\n\n // Modality bookkeeping (design 2.1): a sequence number, not a clock, so two events in the same\n // millisecond still order.\n const sequence = useRef(0);\n const lastPointerDown = useRef(-1);\n const lastKeyDown = useRef(-1);\n const longPress = useRef<LongPress | null>(null);\n // Disarms the one-shot click swallow armed by a long-press open or a drag activation.\n const disarmSwallow = useRef<(() => void) | null>(null);\n // Ends the running press-drag-release gesture and its touch guard (2.6).\n const endDrag = useRef<(() => void) | null>(null);\n const warnedNoPopup = useRef(false);\n\n const cancelLongPress = useCallback(() => {\n if (longPress.current !== null) clearTimeout(longPress.current.timer);\n longPress.current = null;\n }, []);\n\n const stopDrag = useCallback(() => {\n endDrag.current?.();\n endDrag.current = null;\n }, []);\n\n useEffect(\n () => () => {\n cancelLongPress();\n stopDrag();\n disarmSwallow.current?.();\n },\n [cancelLongPress, stopDrag],\n );\n // A region disabled mid-gesture opens nothing.\n useEffect(() => {\n if (disabled) cancelLongPress();\n }, [disabled, cancelLongPress]);\n\n // A close ends any armed click swallow (review H1) and the drag gesture.\n const open = popover.optimistic;\n useEffect(() => {\n if (open) return;\n disarmSwallow.current?.();\n stopDrag();\n }, [open, stopDrag]);\n\n // The modality bookkeeping observes `keydown` and `pointerdown` without owning them (the region\n // is full of the consumer's interactive content), in the capture phase, so a descendant's\n // `stopPropagation()` (a slider, a drag handle) does not hide them (review L2).\n const modalityRef = useCallback((element: HTMLElement) => {\n const onKeyDown = () => {\n lastKeyDown.current = ++sequence.current;\n };\n const onPointerDown = () => {\n lastPointerDown.current = ++sequence.current;\n };\n element.addEventListener(\"keydown\", onKeyDown, true);\n element.addEventListener(\"pointerdown\", onPointerDown, true);\n return () => {\n element.removeEventListener(\"keydown\", onKeyDown, true);\n element.removeEventListener(\"pointerdown\", onPointerDown, true);\n };\n }, []);\n\n /** The popup element to capture on and open, or `null` (no Popup mounted: nothing opens). */\n const popupElement = (): HTMLElement | null => {\n const popup = popover.popupRef.current;\n if (popup === null && isDev && !warnedNoPopup.current) {\n warnedNoPopup.current = true;\n console.error(\n \"Menu.ContextTrigger: a context menu was requested but the Menu.Root has no mounted \" +\n \"Menu.Popup; the browser's own menu shows instead.\",\n );\n }\n return popup;\n };\n\n /**\n * One-shot swallow of the `click` an engine may synthesise when the long-press ends (2.2),\n * scoped to that release (review H1): the click comes in the same task as the `pointerup` of\n * `pointerId`, so the swallow ends one task after that `pointerup` (or `pointercancel`), and at\n * once on any `keydown`, the next `pointerdown`, or the menu closing. iOS synthesises no click\n * after a long-press; a swallow left armed would eat the next keyboard activation\n * (`element.click()`).\n */\n const armClickSwallow = (doc: Document, pointerId: number, releasing = false) => {\n disarmSwallow.current?.();\n let released: ReturnType<typeof setTimeout> | undefined;\n const onClick = (event: Event) => {\n event.preventDefault();\n event.stopPropagation();\n disarm();\n };\n const onRelease = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n if (released === undefined) released = setTimeout(disarm, 0);\n };\n const disarm = () => {\n if (released !== undefined) clearTimeout(released);\n doc.removeEventListener(\"click\", onClick, true);\n doc.removeEventListener(\"pointerdown\", disarm, true);\n doc.removeEventListener(\"keydown\", disarm, true);\n doc.removeEventListener(\"pointerup\", onRelease, true);\n doc.removeEventListener(\"pointercancel\", onRelease, true);\n if (disarmSwallow.current === disarm) disarmSwallow.current = null;\n };\n doc.addEventListener(\"click\", onClick, true);\n doc.addEventListener(\"pointerdown\", disarm, true);\n doc.addEventListener(\"keydown\", disarm, true);\n doc.addEventListener(\"pointerup\", onRelease, true);\n doc.addEventListener(\"pointercancel\", onRelease, true);\n disarmSwallow.current = disarm;\n // Armed from inside the release itself (a drag activation): the click comes in this task.\n if (releasing) released = setTimeout(disarm, 0);\n };\n\n /**\n * Starts the press-drag-release gesture of 2.6 on the pointer the popup captured at this open\n * or move (a new one replaces the running one), with the touch guard for a finger.\n */\n const beginDrag = (\n popup: HTMLElement,\n pointerId: number,\n point: { readonly x: number; readonly y: number },\n pointerType: string,\n slop: number,\n ) => {\n stopDrag();\n const doc = popup.ownerDocument;\n const end = startDrag(popup, {\n pointerId,\n x: point.x,\n y: point.y,\n slop,\n activate: (item) => {\n disarmSwallow.current?.();\n item.click();\n armClickSwallow(doc, pointerId, true);\n },\n });\n const unguard = pointerType === \"touch\" ? guardTouch(doc, pointerId) : null;\n endDrag.current = () => {\n end();\n unguard?.();\n };\n };\n\n /**\n * The event comes from this Root's own popup, rendered inside the region (a table row, where a\n * `<div>` cannot be a sibling of the `<tr>`): never a move or a long-press of the region.\n */\n const fromOwnPopup = (target: EventTarget | null): boolean => {\n const popup = popover.popupRef.current;\n return popup !== null && target instanceof Node && popup.contains(target);\n };\n\n const onContextMenu = (event: MouseEvent<HTMLElement>) => {\n const native = event.nativeEvent;\n // An inner region or a consumer handler was first (the Popup's own handler prevents a\n // right-click inside the menu); a disabled region lets the event bubble on to an outer\n // region (design 2.4).\n if (native.defaultPrevented || disabled || fromOwnPopup(native.target)) return;\n // Copy and paste keep the browser's menu (2.3).\n if (editableTargets === \"native\" && isEditableTarget(native.target)) return;\n const popup = popupElement();\n if (popup === null) return;\n native.preventDefault();\n markHandled(native, menu);\n // Android and pen: the platform's own `contextmenu` arrived during our timer; it opens.\n const timed = longPress.current;\n cancelLongPress();\n const keyboard = native.button === -1 || lastKeyDown.current > lastPointerDown.current;\n const pointerEvent = native as globalThis.PointerEvent;\n const pointerType =\n timed?.pointerType ??\n (typeof pointerEvent.pointerType === \"string\" ? pointerEvent.pointerType : \"mouse\");\n // The pointer still down: the one this event reports, or (Android, whose touch `contextmenu`\n // has `buttons === 0`) the finger the long-press was timing.\n const pointerId =\n native.buttons !== 0 && typeof pointerEvent.pointerId === \"number\"\n ? pointerEvent.pointerId\n : (timed?.pointerId ?? undefined);\n const point = { x: native.clientX, y: native.clientY };\n // whatwg/html#10905: in Firefox and WebKit the pending `pointerup` would light-dismiss a\n // menu opened between `pointerdown` and `pointerup`. Capture now, on the still-hidden popup:\n // the open commit lands at an unpredictable time relative to the `pointerup`. With the\n // capture, the press-drag-release gesture runs (2.6); Windows (`contextmenu` after the\n // release) and the keyboard take neither.\n if (pointerId !== undefined && capturePointer(popup, pointerId)) {\n const slop = timed !== null || pointerType === \"touch\" ? LONG_PRESS_SLOP : DRAG_SLOP;\n beginDrag(popup, pointerId, point, pointerType, slop);\n }\n menu.openAt(point, {\n source: event.currentTarget,\n event: native,\n pointer: !keyboard,\n pointerId,\n // A touch or pen open is placed above the point (4.7).\n offset: !keyboard && isTouchLike(pointerType),\n });\n };\n\n // The long-press only; the modality bookkeeping is `modalityRef`'s.\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const native = event.nativeEvent;\n if (longPress.current !== null) {\n // A second finger: not a long-press.\n cancelLongPress();\n return;\n }\n if (disabled || (native.pointerType !== \"touch\" && native.pointerType !== \"pen\")) return;\n // A press inside any Menu.Popup (this Root's, or another menu inside the region) is claimed by\n // that popup; a press an inner region already times is claimed by it.\n if (fromOwnPopup(native.target)) return;\n if (!native.isPrimary || isPressClaimed(native)) return;\n if (editableTargets === \"native\" && isEditableTarget(native.target)) return;\n // The innermost enabled region times the press; outer regions leave it (as `contextmenu`'s\n // `defaultPrevented` rule, design 2.4).\n claimPress(native);\n const source = event.currentTarget;\n const { pointerId, pointerType, clientX, clientY } = native;\n const timer = setTimeout(\n () => {\n longPress.current = null;\n const popup = popupElement();\n if (popup === null) return;\n const point = { x: clientX, y: clientY };\n // The finger is still down: its `pointerup` would light-dismiss in WebKit. The capture\n // also lets it slide onto an item and lift to activate it (2.6).\n if (capturePointer(popup, pointerId)) {\n beginDrag(popup, pointerId, point, pointerType, LONG_PRESS_SLOP);\n }\n armClickSwallow(source.ownerDocument, pointerId);\n menu.openAt(point, { source, event: native, pointer: true, pointerId, offset: true });\n },\n Math.max(0, longPressDelay),\n );\n longPress.current = { pointerId, pointerType, x: clientX, y: clientY, timer };\n };\n\n const onPointerMove = (event: PointerEvent<HTMLElement>) => {\n const press = longPress.current;\n if (press === null || event.pointerId !== press.pointerId) return;\n if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > LONG_PRESS_SLOP) {\n cancelLongPress();\n }\n };\n\n // `pointercancel`: the browser took the gesture for panning (the region stays scrollable).\n const onPointerEnd = (event: PointerEvent<HTMLElement>) => {\n const press = longPress.current;\n if (press !== null && event.pointerId === press.pointerId) cancelLongPress();\n };\n\n const state: MenuContextTriggerState = {\n open: popover.optimistic,\n pending: popover.pending,\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n onContextMenu,\n onPointerDown,\n onPointerMove,\n onPointerUp: onPointerEnd,\n onPointerCancel: onPointerEnd,\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, MenuContextTriggerState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // iOS link and image previews appear at about the long-press time (2.2).\n style: (s) => ({ WebkitTouchCallout: \"none\", ...resolveStateValue(style, s) }),\n // A Menu.Root inside is a nested region's menu (no \"outside its Popup\" warning).\n children: (s) => (\n <MenuRegionContext value={true}>{resolveStateValue(children, s)}</MenuRegionContext>\n ),\n props: rest,\n libraryProps,\n ref: modalityRef,\n });\n}\n\nMenuContextTrigger.displayName = \"MenuContextTrigger\";\n"],"mappings":";;;;;;;;;;;AA4DA,MAAM,kBAAkB;;;;;AAKxB,MAAM,YAAY;;AAElB,MAAM,qBAAqB;AAE3B,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAuBvC,MAAM,eAAe,gBAAwB,gBAAgB,WAAW,gBAAgB;;;;;;;;;;;;;;;AAgBxF,SAAS,UAAU,OAAoB,SAAkC;CACvE,MAAM,MAAM,MAAM;CAElB,IAAI,UAAyB,MAAM,QAAQ,eAAe,IAAI,YAAY,IAAI,IAAI;CAElF,IAAI,iBAAqC;CAEzC,MAAM,QAAQ,UAAkB,MAAkC,cAAc,QAAQ;CACxF,MAAM,WAAW,UACf,OAAO,IAAI,qBAAqB,aAC5B,IAAI,iBAAiB,MAAM,SAAS,MAAM,OAAO,IACjD;;CAEN,MAAM,UAAU,WAA+C;EAC7D,MAAM,OAAO,QAAQ,QAAA,4EAAkC,KAAK;EAC5D,OAAO,SAAS,QAAQ,MAAM,SAAS,IAAI,IAAI,OAAO;CACxD;;CAEA,MAAM,eAAe,SAAsB,WAA2B;EACpE,MAAM,KAAK,QAAQ,aAAa,YAAY;EAC5C,MAAM,UAAU,OAAO,OAAO,OAA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I,iBACjE,gBAAgB;CAEpB;CAGA,MAAM,gBAAgB,UAAqC;EACzD,MAAM,QAAQ,UAAU;EACxB,IAAI,UAAU,QAAQ,MAAM,cAAc,MAAM,WAAW,gBAAgB;CAC7E;CAEA,MAAM,QAAiC;EACrC,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;CACF;CAEA,MAAM,eAA8D;EAClE;EACA;EACA;EACA,aAAa;EACb,iBAAiB;EACjB,aAAa,SAAS,MAAM,IAAI;EAChC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAAiE;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,QAAQ,OAAO;GAAE,oBAAoB;GAAQ,GAAG,kBAAkB,OAAO,CAAC;EAAE;EAE5E,WAAW,MACT,oBAAC,mBAAD;GAAmB,OAAO;GAAO,UAAA,kBAAkB,UAAU,CAAC;EAAqB,CAAA;EAErF,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,mBAAmB,cAAc"}
|
|
1
|
+
{"version":3,"file":"menu-context-trigger.mjs","names":[],"sources":["../../src/menu/menu-context-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport {\n claimPress,\n isPressClaimed,\n markHandled,\n MenuRegionContext,\n useMenuContext,\n} from \"./menu-context.js\";\nimport { capturePointer, isEditableTarget } from \"./menu-dom.js\";\nimport {\n armClickSwallow,\n DRAG_SLOP,\n guardTouch,\n isTouchLike,\n LONG_PRESS_SLOP,\n startDrag,\n} from \"./menu-gestures.js\";\nimport type { MenuTriggerState } from \"./menu-trigger.js\";\n\nexport type MenuContextTriggerState = MenuTriggerState;\n\nexport interface MenuContextTriggerProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"onContextMenu\"\n | \"onPointerDown\"\n | \"onPointerMove\"\n | \"onPointerUp\"\n | \"onPointerCancel\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The region does nothing; a `contextmenu` bubbles on to an outer region. `data-disabled`. */\n disabled?: boolean;\n /**\n * What a `contextmenu` (or long-press) on an editable target inside the region opens: the\n * browser's own menu (`\"native\"`, default: copy and paste keep working) or this menu.\n * Editable: a text-taking `<input>`, a `<textarea>`, an element with `isContentEditable`.\n */\n editableTargets?: \"native\" | \"menu\";\n /** Milliseconds a touch or pen pointer must stay down (within 10 px) to open. Default 500. */\n longPressDelay?: number;\n className?: StateValue<string | undefined, MenuContextTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuContextTriggerState>;\n children?: StateValue<ReactNode, MenuContextTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuContextTriggerState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\ninterface LongPress {\n readonly pointerId: number;\n readonly pointerType: string;\n readonly x: number;\n readonly y: number;\n readonly timer: ReturnType<typeof setTimeout>;\n}\n\n/**\n * A region whose `contextmenu` (right-click, Ctrl+click, Shift+F10 / the ContextMenu key at a\n * focused descendant) or touch / pen long-press opens the Root's `Menu.Popup` at the pointer\n * (design/components/context-menu.md). A plain element (default `div`) with no role and no ARIA:\n * the region keeps its own semantics (`render={<tr />}`), and keyboard users reach it through\n * focusable content inside it. A second right-click inside the region while the menu is open moves\n * the menu there. Render the `Menu.Popup` as a sibling of the region where the markup allows; in\n * a table row (`render={<tr />}`), inside one of its cells: events from inside the popup are\n * never the region's.\n *\n * Owned keys (conventions 1.2): `onContextMenu`, `onPointerDown`, `onPointerMove`,\n * `onPointerUp`, `onPointerCancel`, `data-open`, `data-pending`, `data-disabled`, and the style\n * key `WebkitTouchCallout` (`\"none\"`; the consumer's `style` wins).\n */\nexport function MenuContextTrigger({\n disabled = false,\n editableTargets = \"native\",\n longPressDelay = 500,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuContextTriggerProps) {\n const menu = useMenuContext(\"Menu.ContextTrigger\");\n const { popover } = menu;\n useDevWarning(\n menu.submenu,\n isDev &&\n \"Menu.ContextTrigger: rendered in a submenu. A Menu.Root inside a Menu.Popup is a submenu; a \" +\n \"context menu region belongs to a top-level Menu.Root.\",\n );\n useDevWarning(\n longPressDelay < 0,\n isDev && \"Menu.ContextTrigger: `longPressDelay` is negative; it is a number of milliseconds.\",\n );\n\n // Modality bookkeeping (design 2.1): a sequence number, not a clock, so two events in the same\n // millisecond still order.\n const sequence = useRef(0);\n const lastPointerDown = useRef(-1);\n const lastKeyDown = useRef(-1);\n const longPress = useRef<LongPress | null>(null);\n // Disarms the one-shot click swallow armed by a long-press open or a drag activation.\n const disarmSwallow = useRef<(() => void) | null>(null);\n // Ends the running press-drag-release gesture and its touch guard (2.6).\n const endDrag = useRef<(() => void) | null>(null);\n const warnedNoPopup = useRef(false);\n\n const cancelLongPress = useCallback(() => {\n if (longPress.current !== null) clearTimeout(longPress.current.timer);\n longPress.current = null;\n }, []);\n\n const stopDrag = useCallback(() => {\n endDrag.current?.();\n endDrag.current = null;\n }, []);\n\n useEffect(\n () => () => {\n cancelLongPress();\n stopDrag();\n disarmSwallow.current?.();\n },\n [cancelLongPress, stopDrag],\n );\n // A region disabled mid-gesture opens nothing.\n useEffect(() => {\n if (disabled) cancelLongPress();\n }, [disabled, cancelLongPress]);\n\n // A close ends any armed click swallow and the drag gesture.\n const open = popover.optimistic;\n useEffect(() => {\n if (open) return;\n disarmSwallow.current?.();\n stopDrag();\n }, [open, stopDrag]);\n\n // The modality bookkeeping observes `keydown` and `pointerdown` without owning them (the region\n // is full of the consumer's interactive content), in the capture phase, so a descendant's\n // `stopPropagation()` (a slider, a drag handle) does not hide them.\n const modalityRef = useCallback((element: HTMLElement) => {\n const onKeyDown = () => {\n lastKeyDown.current = ++sequence.current;\n };\n const onPointerDown = () => {\n lastPointerDown.current = ++sequence.current;\n };\n element.addEventListener(\"keydown\", onKeyDown, true);\n element.addEventListener(\"pointerdown\", onPointerDown, true);\n return () => {\n element.removeEventListener(\"keydown\", onKeyDown, true);\n element.removeEventListener(\"pointerdown\", onPointerDown, true);\n };\n }, []);\n\n /** The popup element to capture on and open, or `null` (no Popup mounted: nothing opens). */\n const popupElement = (): HTMLElement | null => {\n const popup = popover.popupRef.current;\n if (popup === null && isDev && !warnedNoPopup.current) {\n warnedNoPopup.current = true;\n console.error(\n \"Menu.ContextTrigger: a context menu was requested but the Menu.Root has no mounted \" +\n \"Menu.Popup; the browser's own menu shows instead.\",\n );\n }\n return popup;\n };\n\n /**\n * Starts the press-drag-release gesture of 2.6 on the pointer the popup captured at this open\n * or move (a new one replaces the running one), with the touch guard for a finger.\n */\n const beginDrag = (\n popup: HTMLElement,\n pointerId: number,\n point: { readonly x: number; readonly y: number },\n pointerType: string,\n slop: number,\n ) => {\n stopDrag();\n const doc = popup.ownerDocument;\n const end = startDrag(popup, {\n pointerId,\n x: point.x,\n y: point.y,\n slop,\n activate: (item) => {\n disarmSwallow.current?.();\n item.click();\n armClickSwallow(disarmSwallow, doc, pointerId, true);\n },\n });\n const unguard = pointerType === \"touch\" ? guardTouch(doc, pointerId) : null;\n endDrag.current = () => {\n end();\n unguard?.();\n };\n };\n\n /**\n * The event comes from this Root's own popup, rendered inside the region (a table row, where a\n * `<div>` cannot be a sibling of the `<tr>`): never a move or a long-press of the region.\n */\n const fromOwnPopup = (target: EventTarget | null): boolean => {\n const popup = popover.popupRef.current;\n return popup !== null && target instanceof Node && popup.contains(target);\n };\n\n const onContextMenu = (event: MouseEvent<HTMLElement>) => {\n const native = event.nativeEvent;\n // An inner region or a consumer handler was first (the Popup's own handler prevents a\n // right-click inside the menu); a disabled region lets the event bubble on to an outer\n // region (design 2.4).\n if (native.defaultPrevented || disabled || fromOwnPopup(native.target)) return;\n // Copy and paste keep the browser's menu (2.3).\n if (editableTargets === \"native\" && isEditableTarget(native.target)) return;\n const popup = popupElement();\n if (popup === null) return;\n native.preventDefault();\n markHandled(native, menu);\n // Android and pen: the platform's own `contextmenu` arrived during our timer; it opens.\n const timed = longPress.current;\n cancelLongPress();\n const keyboard = native.button === -1 || lastKeyDown.current > lastPointerDown.current;\n const pointerEvent = native as globalThis.PointerEvent;\n const pointerType =\n timed?.pointerType ??\n (typeof pointerEvent.pointerType === \"string\" ? pointerEvent.pointerType : \"mouse\");\n // The pointer still down: the one this event reports, or (Android, whose touch `contextmenu`\n // has `buttons === 0`) the finger the long-press was timing.\n const pointerId =\n native.buttons !== 0 && typeof pointerEvent.pointerId === \"number\"\n ? pointerEvent.pointerId\n : (timed?.pointerId ?? undefined);\n const point = { x: native.clientX, y: native.clientY };\n // whatwg/html#10905: in Firefox and WebKit the pending `pointerup` would light-dismiss a\n // menu opened between `pointerdown` and `pointerup`. Capture now, on the still-hidden popup:\n // the open commit lands at an unpredictable time relative to the `pointerup`. With the\n // capture, the press-drag-release gesture runs (2.6); Windows (`contextmenu` after the\n // release) and the keyboard take neither.\n if (pointerId !== undefined && capturePointer(popup, pointerId)) {\n const slop = timed !== null || pointerType === \"touch\" ? LONG_PRESS_SLOP : DRAG_SLOP;\n beginDrag(popup, pointerId, point, pointerType, slop);\n }\n menu.openAt(point, {\n source: event.currentTarget,\n event: native,\n pointer: !keyboard,\n pointerId,\n // A touch or pen open is placed above the point (4.7).\n offset: !keyboard && isTouchLike(pointerType),\n });\n };\n\n // The long-press only; the modality bookkeeping is `modalityRef`'s.\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const native = event.nativeEvent;\n if (longPress.current !== null) {\n // A second finger: not a long-press.\n cancelLongPress();\n return;\n }\n if (disabled || (native.pointerType !== \"touch\" && native.pointerType !== \"pen\")) return;\n // A press inside any Menu.Popup (this Root's, or another menu inside the region) is claimed by\n // that popup; a press an inner region already times is claimed by it.\n if (fromOwnPopup(native.target)) return;\n if (!native.isPrimary || isPressClaimed(native)) return;\n if (editableTargets === \"native\" && isEditableTarget(native.target)) return;\n // The innermost enabled region times the press; outer regions leave it (as `contextmenu`'s\n // `defaultPrevented` rule, design 2.4).\n claimPress(native);\n const source = event.currentTarget;\n const { pointerId, pointerType, clientX, clientY } = native;\n const timer = setTimeout(\n () => {\n longPress.current = null;\n const popup = popupElement();\n if (popup === null) return;\n const point = { x: clientX, y: clientY };\n // The finger is still down: its `pointerup` would light-dismiss in WebKit. The capture\n // also lets it slide onto an item and lift to activate it (2.6).\n if (capturePointer(popup, pointerId)) {\n beginDrag(popup, pointerId, point, pointerType, LONG_PRESS_SLOP);\n }\n armClickSwallow(disarmSwallow, source.ownerDocument, pointerId);\n menu.openAt(point, { source, event: native, pointer: true, pointerId, offset: true });\n },\n Math.max(0, longPressDelay),\n );\n longPress.current = { pointerId, pointerType, x: clientX, y: clientY, timer };\n };\n\n const onPointerMove = (event: PointerEvent<HTMLElement>) => {\n const press = longPress.current;\n if (press === null || event.pointerId !== press.pointerId) return;\n if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > LONG_PRESS_SLOP) {\n cancelLongPress();\n }\n };\n\n // `pointercancel`: the browser took the gesture for panning (the region stays scrollable).\n const onPointerEnd = (event: PointerEvent<HTMLElement>) => {\n const press = longPress.current;\n if (press !== null && event.pointerId === press.pointerId) cancelLongPress();\n };\n\n const state: MenuContextTriggerState = {\n open: popover.optimistic,\n pending: popover.pending,\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n onContextMenu,\n onPointerDown,\n onPointerMove,\n onPointerUp: onPointerEnd,\n onPointerCancel: onPointerEnd,\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, MenuContextTriggerState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // iOS link and image previews appear at about the long-press time (2.2).\n style: (s) => ({ WebkitTouchCallout: \"none\", ...resolveStateValue(style, s) }),\n // A Menu.Root inside is a nested region's menu (no \"outside its Popup\" warning).\n children: (s) => (\n <MenuRegionContext value={true}>{resolveStateValue(children, s)}</MenuRegionContext>\n ),\n props: rest,\n libraryProps,\n ref: modalityRef,\n });\n}\n\nMenuContextTrigger.displayName = \"MenuContextTrigger\";\n"],"mappings":";;;;;;;;;;;AA6DA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;AAwBvC,SAAgB,mBAAmB,EACjC,WAAW,OACX,kBAAkB,UAClB,iBAAiB,KACjB,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,OAAO,eAAe,qBAAqB;CACjD,MAAM,EAAE,YAAY;CACpB,cACE,KAAK,SACL,SACE,mJAEJ;CACA,cACE,iBAAiB,GACjB,SAAS,oFACX;CAIA,MAAM,WAAW,OAAO,CAAC;CACzB,MAAM,kBAAkB,OAAO,EAAE;CACjC,MAAM,cAAc,OAAO,EAAE;CAC7B,MAAM,YAAY,OAAyB,IAAI;CAE/C,MAAM,gBAAgB,OAA4B,IAAI;CAEtD,MAAM,UAAU,OAA4B,IAAI;CAChD,MAAM,gBAAgB,OAAO,KAAK;CAElC,MAAM,kBAAkB,kBAAkB;EACxC,IAAI,UAAU,YAAY,MAAM,aAAa,UAAU,QAAQ,KAAK;EACpE,UAAU,UAAU;CACtB,GAAG,CAAC,CAAC;CAEL,MAAM,WAAW,kBAAkB;EACjC,QAAQ,UAAU;EAClB,QAAQ,UAAU;CACpB,GAAG,CAAC,CAAC;CAEL,sBACc;EACV,gBAAgB;EAChB,SAAS;EACT,cAAc,UAAU;CAC1B,GACA,CAAC,iBAAiB,QAAQ,CAC5B;CAEA,gBAAgB;EACd,IAAI,UAAU,gBAAgB;CAChC,GAAG,CAAC,UAAU,eAAe,CAAC;CAG9B,MAAM,OAAO,QAAQ;CACrB,gBAAgB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+
import "../internal/use-overlay-root.mjs";
|
|
@@ -17,7 +17,7 @@ const handledEvents = /* @__PURE__ */ new WeakMap();
|
|
|
17
17
|
/**
|
|
18
18
|
* `pointerdown` events that are not a long-press of an enclosing region: claimed by the innermost
|
|
19
19
|
* region that started its timer for them (nested regions), and by every `Menu.Popup` for the
|
|
20
|
-
* presses inside it (a menu inside a region
|
|
20
|
+
* presses inside it (a menu inside a region). As `contextmenu`'s `defaultPrevented`
|
|
21
21
|
* rule (context-menu.md 2.4).
|
|
22
22
|
*/
|
|
23
23
|
const claimedPresses = /* @__PURE__ */ new WeakSet();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-context.mjs","names":[],"sources":["../../src/menu/menu-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { DelayedPair } from \"../internal/use-delayed-pair.js\";\nimport type { PopoverRootValue } from \"../internal/use-popover-root.js\";\n\n/**\n * Where focus goes when the menu opens (design/components/menu.md 6.1): the first enabled item,\n * the last one (ArrowUp on the Trigger), or nowhere (a hover-opened submenu keeps focus on its\n * SubmenuTrigger).\n */\nexport type MenuOpenCause = \"first\" | \"last\" | \"none\";\n\n/** How the open being shown should place focus (design 6.1; review H1). */\nexport interface MenuOpenFocus {\n readonly cause: MenuOpenCause;\n /**\n * The open came from a pointer click (`detail > 0`): the item is focused without the focus\n * ring where the engine supports `focus({ focusVisible: false })`.\n */\n readonly pointer: boolean;\n}\n\n/**\n * How the current open is placed (design/components/context-menu.md 3.1): against the Trigger\n * (`anchor`: a Menu.Trigger, a foreign invoker, a controlled or platform open), or at a point\n * (`point`: a Menu.ContextTrigger). `generation` grows with every point open or move, so a second\n * right-click at a new point is a state change while the menu is open (4.3).\n */\nexport type MenuPlacement =\n | { readonly kind: \"anchor\" }\n | {\n readonly kind: \"point\";\n readonly x: number;\n readonly y: number;\n readonly generation: number;\n /** The region that opened: the `source` of `showPopover({ source })` (nesting). */\n readonly source: HTMLElement;\n /** The pointer held down at the open, re-captured after a move's re-show (2.1). */\n readonly pointerId: number | undefined;\n /**\n * The popup's computed `direction` at this open or move (#88, 4.6): which edge of the menu\n * sits at the point. Read once by `openAt`, never during render.\n */\n readonly direction: \"ltr\" | \"rtl\";\n /**\n * A touch or pen open (#88, 4.7): the menu is placed above the point with\n * `--menu-point-gap`, so it does not open under the finger.\n */\n readonly offset: boolean;\n };\n\nexport const ANCHOR_PLACEMENT: MenuPlacement = { kind: \"anchor\" };\n\n/** What a ContextTrigger passes to `openAt`. */\nexport interface MenuOpenAtOptions {\n readonly source: HTMLElement;\n /** The `contextmenu` event, or the long-press `pointerdown` (`details.event`). */\n readonly event: Event;\n /** A pointer opened (quiet focus); `false` for the keyboard (focus ring). */\n readonly pointer: boolean;\n readonly pointerId: number | undefined;\n /** A touch or pen open: placed above the point (4.7). */\n readonly offset: boolean;\n}\n\n/** One menu level: what its Root provides to its Trigger, Popup and items. */\nexport interface MenuContextValue {\n /** The shared popover machinery (`usePopoverRoot`). */\n readonly popover: PopoverRootValue;\n /** This Root is nested in a `Menu.Popup`. */\n readonly submenu: boolean;\n /** The top-level menu: item activation closes the whole stack through it (design 2.2). */\n readonly root: MenuContextValue;\n /** The enclosing menu of a submenu; `null` at the top level. */\n readonly parent: MenuContextValue | null;\n readonly loop: boolean;\n readonly delay: number;\n readonly closeDelay: number;\n /** The Trigger's id (`aria-labelledby` of the Popup). */\n readonly triggerId: string;\n /** Record the focus target of the next open (and whether a pointer asked for it). */\n readonly setOpenCause: (cause: MenuOpenCause, pointer?: boolean) => void;\n /** Read and clear the focus target of the open being shown (default `\"first\"`, keyboard). */\n readonly takeOpenCause: () => MenuOpenFocus;\n /** Submenu hover-intent timers, shared by the SubmenuTrigger and the Popup. */\n readonly timers: DelayedPair;\n /** Placement of the current (or last) open (context-menu.md 3.1). */\n readonly placement: MenuPlacement;\n /**\n * A ContextTrigger opens the menu at `point`, or moves it there when it is already open (no\n * dispatch, 4.3).\n */\n readonly openAt: (\n point: { readonly x: number; readonly y: number },\n options: MenuOpenAtOptions,\n ) => void;\n /**\n * Back to the anchored placement once a point open has been shown and hidden (the popup is no\n * longer visible): the next open that is not a ContextTrigger's (controlled, platform, foreign\n * invoker) places against the Trigger. Ignored when a newer point was recorded meanwhile.\n */\n readonly resetPlacement: (generation: number) => void;\n}\n\nexport const MenuContext = createContext<MenuContextValue | null>(null);\n\n/**\n * `true` inside a `Menu.ContextTrigger`: a `Menu.Root` there is a nested context region's own\n * top-level menu (context-menu.md 2.4), not a misplaced submenu.\n */\nexport const MenuRegionContext = createContext(false);\n\n/**\n * `contextmenu` events a ContextTrigger handled (opened or moved its menu), with the top-level\n * menu they belong to: that menu's document listener leaves its menu open for them\n * (context-menu.md 5 and 14).\n */\nconst handledEvents = new WeakMap<Event, object>();\n\n/**\n * `pointerdown` events that are not a long-press of an enclosing region: claimed by the innermost\n * region that started its timer for them (nested regions), and by every `Menu.Popup` for the\n * presses inside it (a menu inside a region, review M1). As `contextmenu`'s `defaultPrevented`\n * rule (context-menu.md 2.4).\n */\nconst claimedPresses = new WeakSet<Event>();\n\nexport function claimPress(event: Event): void {\n claimedPresses.add(event);\n}\n\nexport function isPressClaimed(event: Event): boolean {\n return claimedPresses.has(event);\n}\n\n/**\n * What a hit on a `Menu.SubmenuTrigger` during a press-drag-release gesture does (context-menu.md\n * 2.6): the hover intent a real `pointerenter` / `pointerleave` would start. Registered by the\n * SubmenuTrigger on its element; the gesture runs under pointer capture, so the element never\n * receives boundary events itself.\n */\nexport interface SubmenuHover {\n readonly enter: (event: Event) => void;\n readonly leave: (event: Event) => void;\n}\n\nconst submenuHovers = new WeakMap<Element, SubmenuHover>();\n\nexport function registerSubmenuHover(element: Element, hover: SubmenuHover): () => void {\n submenuHovers.set(element, hover);\n return () => {\n if (submenuHovers.get(element) === hover) submenuHovers.delete(element);\n };\n}\n\nexport function submenuHover(element: Element): SubmenuHover | undefined {\n return submenuHovers.get(element);\n}\n\n/** The top-level menu's identity: its popup ref object, stable for the Root's lifetime. */\nconst menuKey = (menu: MenuContextValue): object => menu.root.popover.popupRef;\n\nexport function markHandled(event: Event, menu: MenuContextValue): void {\n handledEvents.set(event, menuKey(menu));\n}\n\nexport function isHandledBy(event: Event, menu: MenuContextValue): boolean {\n return handledEvents.get(event) === menuKey(menu);\n}\n\n/**\n * The close an activated item runs once its action settled: the whole stack, through the\n * top-level Root (design 2.2). Recorded at activation: if the menu was dismissed and opened again\n * meanwhile, the close belongs to the previous opening and does nothing (as `useActionTrigger`).\n */\nexport function closeStackLater(menu: MenuContextValue, event: Event): () => void {\n const { popover } = menu.root;\n const generation = popover.openGeneration();\n return () => {\n if (popover.openGeneration() === generation) popover.requestClose(event, \"activate\");\n };\n}\n\nexport function useMenuContext(part: string): MenuContextValue {\n const context = use(MenuContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Menu.Root.`);\n }\n return context;\n}\n\n/** What a `Menu.Popup` tells the items rendered in it. */\nexport interface MenuListContextValue {\n /** The menu this popup belongs to. */\n readonly menu: MenuContextValue;\n /**\n * `experimental_focusgroup` is on and the engine implements it: items render no `tabindex`\n * (Chromium leaves `tabindex=\"-1\"` elements out of a focusgroup) and the JS arrow keys step\n * aside.\n */\n readonly nativeFocusgroup: boolean;\n /** A typeahead buffer is active: Space is a character, not an activation (design 5.1). */\n readonly typingAhead: () => boolean;\n}\n\nexport const MenuListContext = createContext<MenuListContextValue | null>(null);\n\n/** `Menu.Group` / `Menu.RadioGroup`: the id their `Menu.GroupLabel` renders. */\nexport interface MenuGroupContextValue {\n readonly labelId: string;\n}\n\nexport const MenuGroupContext = createContext<MenuGroupContextValue | null>(null);\n\n/** `Menu.RadioGroup`'s state for its `Menu.RadioItem`s. */\nexport interface MenuRadioGroupContextValue {\n /** Optimistic value. */\n readonly value: string | null;\n readonly pending: boolean;\n /**\n * Dispatch `value` through the group's transition; `then` runs once the change action\n * resolved (an item's `closeOnActivate`).\n */\n readonly select: (value: string, event: Event, then: (() => void) | undefined) => void;\n}\n\nexport const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AAchF,MAAa,wBAAwB,cAAiD,IAAI"}
|
|
1
|
+
{"version":3,"file":"menu-context.mjs","names":[],"sources":["../../src/menu/menu-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { DelayedPair } from \"../internal/use-delayed-pair.js\";\nimport type { PopoverRootValue } from \"../internal/use-overlay-root.js\";\n\n/**\n * Where focus goes when the menu opens (design/components/menu.md 6.1): the first enabled item,\n * the last one (ArrowUp on the Trigger), or nowhere (a hover-opened submenu keeps focus on its\n * SubmenuTrigger).\n */\nexport type MenuOpenCause = \"first\" | \"last\" | \"none\";\n\n/** How the open being shown should place focus (design 6.1). */\nexport interface MenuOpenFocus {\n readonly cause: MenuOpenCause;\n /**\n * The open came from a pointer click (`detail > 0`): the item is focused without the focus\n * ring where the engine supports `focus({ focusVisible: false })`.\n */\n readonly pointer: boolean;\n}\n\n/**\n * How the current open is placed (design/components/context-menu.md 3.1): against the Trigger\n * (`anchor`: a Menu.Trigger, a foreign invoker, a controlled or platform open), or at a point\n * (`point`: a Menu.ContextTrigger). `generation` grows with every point open or move, so a second\n * right-click at a new point is a state change while the menu is open (4.3).\n */\nexport type MenuPlacement =\n | { readonly kind: \"anchor\" }\n | {\n readonly kind: \"point\";\n readonly x: number;\n readonly y: number;\n readonly generation: number;\n /** The region that opened: the `source` of `showPopover({ source })` (nesting). */\n readonly source: HTMLElement;\n /** The pointer held down at the open, re-captured after a move's re-show (2.1). */\n readonly pointerId: number | undefined;\n /**\n * The popup's computed `direction` at this open or move (4.6): which edge of the menu\n * sits at the point. Read once by `openAt`, never during render.\n */\n readonly direction: \"ltr\" | \"rtl\";\n /**\n * A touch or pen open (4.7): the menu is placed above the point with\n * `--menu-point-gap`, so it does not open under the finger.\n */\n readonly offset: boolean;\n };\n\nexport const ANCHOR_PLACEMENT: MenuPlacement = { kind: \"anchor\" };\n\n/** What a ContextTrigger passes to `openAt`. */\nexport interface MenuOpenAtOptions {\n readonly source: HTMLElement;\n /** The `contextmenu` event, or the long-press `pointerdown` (`details.event`). */\n readonly event: Event;\n /** A pointer opened (quiet focus); `false` for the keyboard (focus ring). */\n readonly pointer: boolean;\n readonly pointerId: number | undefined;\n /** A touch or pen open: placed above the point (4.7). */\n readonly offset: boolean;\n}\n\n/** One menu level: what its Root provides to its Trigger, Popup and items. */\nexport interface MenuContextValue {\n /** The shared popover machinery (`useOverlayRoot`). */\n readonly popover: PopoverRootValue;\n /** This Root is nested in a `Menu.Popup`. */\n readonly submenu: boolean;\n /** The top-level menu: item activation closes the whole stack through it (design 2.2). */\n readonly root: MenuContextValue;\n /** The enclosing menu of a submenu; `null` at the top level. */\n readonly parent: MenuContextValue | null;\n readonly loop: boolean;\n readonly delay: number;\n readonly closeDelay: number;\n /** The Trigger's id (`aria-labelledby` of the Popup). */\n readonly triggerId: string;\n /** Record the focus target of the next open (and whether a pointer asked for it). */\n readonly setOpenCause: (cause: MenuOpenCause, pointer?: boolean) => void;\n /** Read and clear the focus target of the open being shown (default `\"first\"`, keyboard). */\n readonly takeOpenCause: () => MenuOpenFocus;\n /** Submenu hover-intent timers, shared by the SubmenuTrigger and the Popup. */\n readonly timers: DelayedPair;\n /** Placement of the current (or last) open (context-menu.md 3.1). */\n readonly placement: MenuPlacement;\n /**\n * A ContextTrigger opens the menu at `point`, or moves it there when it is already open (no\n * dispatch, 4.3).\n */\n readonly openAt: (\n point: { readonly x: number; readonly y: number },\n options: MenuOpenAtOptions,\n ) => void;\n /**\n * Back to the anchored placement once a point open has been shown and hidden (the popup is no\n * longer visible): the next open that is not a ContextTrigger's (controlled, platform, foreign\n * invoker) places against the Trigger. Ignored when a newer point was recorded meanwhile.\n */\n readonly resetPlacement: (generation: number) => void;\n}\n\nexport const MenuContext = createContext<MenuContextValue | null>(null);\n\n/**\n * `true` inside a `Menu.ContextTrigger`: a `Menu.Root` there is a nested context region's own\n * top-level menu (context-menu.md 2.4), not a misplaced submenu.\n */\nexport const MenuRegionContext = createContext(false);\n\n/**\n * `contextmenu` events a ContextTrigger handled (opened or moved its menu), with the top-level\n * menu they belong to: that menu's document listener leaves its menu open for them\n * (context-menu.md 5 and 14).\n */\nconst handledEvents = new WeakMap<Event, object>();\n\n/**\n * `pointerdown` events that are not a long-press of an enclosing region: claimed by the innermost\n * region that started its timer for them (nested regions), and by every `Menu.Popup` for the\n * presses inside it (a menu inside a region). As `contextmenu`'s `defaultPrevented`\n * rule (context-menu.md 2.4).\n */\nconst claimedPresses = new WeakSet<Event>();\n\nexport function claimPress(event: Event): void {\n claimedPresses.add(event);\n}\n\nexport function isPressClaimed(event: Event): boolean {\n return claimedPresses.has(event);\n}\n\n/**\n * What a hit on a `Menu.SubmenuTrigger` during a press-drag-release gesture does (context-menu.md\n * 2.6): the hover intent a real `pointerenter` / `pointerleave` would start. Registered by the\n * SubmenuTrigger on its element; the gesture runs under pointer capture, so the element never\n * receives boundary events itself.\n */\nexport interface SubmenuHover {\n readonly enter: (event: Event) => void;\n readonly leave: (event: Event) => void;\n}\n\nconst submenuHovers = new WeakMap<Element, SubmenuHover>();\n\nexport function registerSubmenuHover(element: Element, hover: SubmenuHover): () => void {\n submenuHovers.set(element, hover);\n return () => {\n if (submenuHovers.get(element) === hover) submenuHovers.delete(element);\n };\n}\n\nexport function submenuHover(element: Element): SubmenuHover | undefined {\n return submenuHovers.get(element);\n}\n\n/** The top-level menu's identity: its popup ref object, stable for the Root's lifetime. */\nconst menuKey = (menu: MenuContextValue): object => menu.root.popover.popupRef;\n\nexport function markHandled(event: Event, menu: MenuContextValue): void {\n handledEvents.set(event, menuKey(menu));\n}\n\nexport function isHandledBy(event: Event, menu: MenuContextValue): boolean {\n return handledEvents.get(event) === menuKey(menu);\n}\n\n/**\n * The close an activated item runs once its action settled: the whole stack, through the\n * top-level Root (design 2.2). Recorded at activation: if the menu was dismissed and opened again\n * meanwhile, the close belongs to the previous opening and does nothing (as `useActionTrigger`).\n */\nexport function closeStackLater(menu: MenuContextValue, event: Event): () => void {\n const { popover } = menu.root;\n const generation = popover.openGeneration();\n return () => {\n if (popover.openGeneration() === generation) popover.requestClose(event, \"activate\");\n };\n}\n\nexport function useMenuContext(part: string): MenuContextValue {\n const context = use(MenuContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Menu.Root.`);\n }\n return context;\n}\n\n/** What a `Menu.Popup` tells the items rendered in it. */\nexport interface MenuListContextValue {\n /** The menu this popup belongs to. */\n readonly menu: MenuContextValue;\n /**\n * `experimental_focusgroup` is on and the engine implements it: items render no `tabindex`\n * (Chromium leaves `tabindex=\"-1\"` elements out of a focusgroup) and the JS arrow keys step\n * aside.\n */\n readonly nativeFocusgroup: boolean;\n /** A typeahead buffer is active: Space is a character, not an activation (design 5.1). */\n readonly typingAhead: () => boolean;\n}\n\nexport const MenuListContext = createContext<MenuListContextValue | null>(null);\n\n/** `Menu.Group` / `Menu.RadioGroup`: the id their `Menu.GroupLabel` renders. */\nexport interface MenuGroupContextValue {\n readonly labelId: string;\n}\n\nexport const MenuGroupContext = createContext<MenuGroupContextValue | null>(null);\n\n/** `Menu.RadioGroup`'s state for its `Menu.RadioItem`s. */\nexport interface MenuRadioGroupContextValue {\n /** Optimistic value. */\n readonly value: string | null;\n readonly pending: boolean;\n /**\n * Dispatch `value` through the group's transition; `then` runs once the change action\n * resolved (an item's `closeOnActivate`).\n */\n readonly select: (value: string, event: Event, then: (() => void) | undefined) => void;\n}\n\nexport const MenuRadioGroupContext = createContext<MenuRadioGroupContextValue | null>(null);\n"],"mappings":";;;AAmDA,MAAa,mBAAkC,EAAE,MAAM,SAAS;AAqDhE,MAAa,cAAc,cAAuC,IAAI;;;;;AAMtE,MAAa,oBAAoB,cAAc,KAAK;;;;;;AAOpD,MAAM,gCAAgB,IAAI,QAAuB;;;;;;;AAQjD,MAAM,iCAAiB,IAAI,QAAe;AAE1C,SAAgB,WAAW,OAAoB;CAC7C,eAAe,IAAI,KAAK;AAC1B;AAEA,SAAgB,eAAe,OAAuB;CACpD,OAAO,eAAe,IAAI,KAAK;AACjC;AAaA,MAAM,gCAAgB,IAAI,QAA+B;AAEzD,SAAgB,qBAAqB,SAAkB,OAAiC;CACtF,cAAc,IAAI,SAAS,KAAK;CAChC,aAAa;EACX,IAAI,cAAc,IAAI,OAAO,MAAM,OAAO,cAAc,OAAO,OAAO;CACxE;AACF;AAEA,SAAgB,aAAa,SAA4C;CACvE,OAAO,cAAc,IAAI,OAAO;AAClC;;AAGA,MAAM,WAAW,SAAmC,KAAK,KAAK,QAAQ;AAEtE,SAAgB,YAAY,OAAc,MAA8B;CACtE,cAAc,IAAI,OAAO,QAAQ,IAAI,CAAC;AACxC;AAEA,SAAgB,YAAY,OAAc,MAAiC;CACzE,OAAO,cAAc,IAAI,KAAK,MAAM,QAAQ,IAAI;AAClD;;;;;;AAOA,SAAgB,gBAAgB,MAAwB,OAA0B;CAChF,MAAM,EAAE,YAAY,KAAK;CACzB,MAAM,aAAa,QAAQ,eAAe;CAC1C,aAAa;EACX,IAAI,QAAQ,eAAe,MAAM,YAAY,QAAQ,aAAa,OAAO,UAAU;CACrF;AACF;AAEA,SAAgB,eAAe,MAAgC;CAC7D,MAAM,UAAU,IAAI,WAAW;CAC/B,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,sCAAsC;CAEhE,OAAO;AACT;AAgBA,MAAa,kBAAkB,cAA2C,IAAI;AAO9E,MAAa,mBAAmB,cAA4C,IAAI;AAchF,MAAa,wBAAwB,cAAiD,IAAI"}
|
package/dist/menu/menu-dom.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
//#region src/menu/menu-dom.ts
|
|
3
2
|
const ITEM_SELECTOR = "[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]";
|
|
4
3
|
/** The items of `popup` in DOM order, without the items of its submenus. Disabled included. */
|
|
@@ -10,7 +9,7 @@ function isMenuItem(element, popup) {
|
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
12
11
|
* Disabled by its `disabled` prop. Keys on `data-disabled`, not `aria-disabled`: an item is also
|
|
13
|
-
* `aria-disabled` while its own action is pending
|
|
12
|
+
* `aria-disabled` while its own action is pending. A pending item is an ordinary item for
|
|
14
13
|
* navigation; only the open focus (`edgeItem`) skips items with the `disabled` prop. Arrow keys,
|
|
15
14
|
* Home / End and typeahead skip nothing.
|
|
16
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-dom.mjs","names":[],"sources":["../../src/menu/menu-dom.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"menu-dom.mjs","names":[],"sources":["../../src/menu/menu-dom.ts"],"sourcesContent":["// DOM helpers shared by the Menu parts. Items are read from the DOM when they are needed (a key\n// press, an open), never registered (design/components/menu.md 13 and 14). No \"use client\"\n// directive: pure DOM reads (conventions 7.1).\n\nexport const ITEM_SELECTOR = '[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]';\n\n/** The items of `popup` in DOM order, without the items of its submenus. Disabled included. */\nexport function menuItems(popup: Element): HTMLElement[] {\n return Array.from(popup.querySelectorAll<HTMLElement>(ITEM_SELECTOR)).filter(\n (item) => item.closest('[role=\"menu\"]') === popup,\n );\n}\n\nexport function isMenuItem(element: Element, popup: Element): boolean {\n return element.matches(ITEM_SELECTOR) && element.closest('[role=\"menu\"]') === popup;\n}\n\n/**\n * Disabled by its `disabled` prop. Keys on `data-disabled`, not `aria-disabled`: an item is also\n * `aria-disabled` while its own action is pending. A pending item is an ordinary item for\n * navigation; only the open focus (`edgeItem`) skips items with the `disabled` prop. Arrow keys,\n * Home / End and typeahead skip nothing.\n */\nexport function isDisabledItem(item: Element): boolean {\n return item.hasAttribute(\"data-disabled\");\n}\n\n/** The first (or last) enabled item; the first (or last) item if all are disabled. */\nexport function edgeItem(popup: Element, which: \"first\" | \"last\"): HTMLElement | null {\n const items = menuItems(popup);\n const ordered = which === \"first\" ? items : [...items].reverse();\n return ordered.find((item) => !isDisabledItem(item)) ?? ordered[0] ?? null;\n}\n\n/** Keyboard focus: the ring shows even where the engine's heuristic would not (as Tabs). */\nexport function focusItem(item: HTMLElement): void {\n item.focus({ focusVisible: true } as FocusOptions);\n}\n\n/** The text typeahead matches: the item's `label` prop, else its text content. */\nexport function typeaheadText(item: Element): string {\n return (item.getAttribute(\"data-typeahead\") ?? item.textContent ?? \"\").trim().toLowerCase();\n}\n\nexport function isRtl(element: Element): boolean {\n return getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * `setPointerCapture`, which throws `NotFoundError` for a pointer the engine no longer tracks\n * (context-menu.md 2.1). A silent no-op when no button is down. `true` when the capture was\n * taken (the press-drag-release gesture runs only then, 2.6).\n */\nexport function capturePointer(element: Element | null, pointerId: number | undefined): boolean {\n if (element === null || pointerId === undefined) return false;\n try {\n element.setPointerCapture(pointerId);\n return true;\n } catch {\n // Not an active pointer (a synthetic event, a released button): nothing to capture.\n return false;\n }\n}\n\n/** `<input>` types that take no text: their `contextmenu` is not an editing one. */\nconst NON_TEXT_INPUTS = new Set([\n \"button\",\n \"submit\",\n \"reset\",\n \"checkbox\",\n \"radio\",\n \"range\",\n \"color\",\n \"file\",\n \"image\",\n \"hidden\",\n]);\n\n/**\n * An editable target keeps the browser's own context menu by default (context-menu.md 2.3): a\n * text-taking `<input>`, a `<textarea>`, or editable content.\n */\nexport function isEditableTarget(target: EventTarget | null): boolean {\n if (target === null || (target as Node).nodeType !== 1) return false;\n const element = target as HTMLElement;\n if (element.closest(\"textarea\") !== null) return true;\n const input = element.closest(\"input\");\n if (input !== null && !NON_TEXT_INPUTS.has(input.type)) return true;\n // `isContentEditable` where implemented (every engine; not jsdom).\n if (typeof element.isContentEditable === \"boolean\") return element.isContentEditable;\n return element.closest('[contenteditable]:not([contenteditable=\"false\"])') !== null;\n}\n\nexport function hasModifier(event: { altKey: boolean; ctrlKey: boolean; metaKey: boolean }) {\n return event.altKey || event.ctrlKey || event.metaKey;\n}\n"],"mappings":";AAIA,MAAa,gBAAgB;;A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AM,OAAO;CACjD,MAAM,QAAQ,QAAQ,QAAQ,OAAO;CACrC,IAAI,UAAU,QAAQ,CAAC,gBAAgB,IAAI,MAAM,IAAI,GAAG,OAAO;CAE/D,IAAI,OAAO,QAAQ,sBAAsB,WAAW,OAAO,QAAQ;CACnE,OAAO,QAAQ,QAAQ,oDAAkD,MAAM;AACjF;AAEA,SAAgB,YAAY,OAAgE;CAC1F,OAAO,MAAM,UAAU,MAAM,WAAW,MAAM;AAChD"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { isPopoverOpen } from "../internal/popover-open.mjs";
|
|
2
|
+
import { submenuHover } from "./menu-context.mjs";
|
|
3
|
+
import { isDisabledItem } from "./menu-dom.mjs";
|
|
4
|
+
//#region src/menu/menu-gestures.ts
|
|
5
|
+
/** A release outside the menu dismisses it only this long after the open (GTK, Base UI). */
|
|
6
|
+
const DRAG_DISMISS_DELAY = 500;
|
|
7
|
+
const isTouchLike = (pointerType) => pointerType === "touch" || pointerType === "pen";
|
|
8
|
+
/**
|
|
9
|
+
* Press-drag-release (context-menu.md 2.6). The popup holds the capture of `pointerId`, so its
|
|
10
|
+
* items see no boundary events and the gesture hit-tests with `elementFromPoint`. A move focuses
|
|
11
|
+
* the item under the pointer without the ring (a SubmenuTrigger starts its hover intent); a
|
|
12
|
+
* release beyond the slop activates an enabled, non-submenu item through `click()`, or dismisses
|
|
13
|
+
* when outside every popup of the tree at least 500 ms after the popup was shown (not after the
|
|
14
|
+
* press: an async open appears late). Ends at the release, `pointercancel`,
|
|
15
|
+
* `lostpointercapture` or the close. Returns the cleanup.
|
|
16
|
+
*/
|
|
17
|
+
function startDrag(popup, options) {
|
|
18
|
+
const doc = popup.ownerDocument;
|
|
19
|
+
let shownAt = isPopoverOpen(popup) ? performance.now() : null;
|
|
20
|
+
let submenuTrigger = null;
|
|
21
|
+
const ours = (event) => event.pointerId === options.pointerId;
|
|
22
|
+
const hitTest = (event) => typeof doc.elementFromPoint === "function" ? doc.elementFromPoint(event.clientX, event.clientY) : null;
|
|
23
|
+
/** The item under the pointer, inside this menu's tree (submenus are DOM descendants). */
|
|
24
|
+
const itemAt = (target) => {
|
|
25
|
+
const item = target?.closest("[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]") ?? null;
|
|
26
|
+
return item !== null && popup.contains(item) ? item : null;
|
|
27
|
+
};
|
|
28
|
+
/** The pointer is over the submenu `trigger` opens (its popup is the `commandfor` target). */
|
|
29
|
+
const inSubmenuOf = (trigger, target) => {
|
|
30
|
+
const id = trigger.getAttribute("commandfor");
|
|
31
|
+
const submenu = id === null ? null : doc.getElementById(id);
|
|
32
|
+
return submenu !== null && target !== null && submenu.contains(target);
|
|
33
|
+
};
|
|
34
|
+
const hoverSubmenu = (next, event) => {
|
|
35
|
+
if (next === submenuTrigger) return;
|
|
36
|
+
if (submenuTrigger !== null) submenuHover(submenuTrigger)?.leave(event);
|
|
37
|
+
submenuTrigger = next;
|
|
38
|
+
if (next !== null) submenuHover(next)?.enter(event);
|
|
39
|
+
};
|
|
40
|
+
const onMove = (event) => {
|
|
41
|
+
if (!ours(event)) return;
|
|
42
|
+
const target = hitTest(event);
|
|
43
|
+
const item = itemAt(target);
|
|
44
|
+
if (item !== null && doc.activeElement !== item) item.focus({ focusVisible: false });
|
|
45
|
+
if (item !== null && submenuHover(item) !== void 0) hoverSubmenu(item, event);
|
|
46
|
+
else if (submenuTrigger !== null && !inSubmenuOf(submenuTrigger, target)) hoverSubmenu(null, event);
|
|
47
|
+
};
|
|
48
|
+
const onUp = (event) => {
|
|
49
|
+
if (!ours(event)) return;
|
|
50
|
+
end();
|
|
51
|
+
if (!(Math.hypot(event.clientX - options.x, event.clientY - options.y) > options.slop)) return;
|
|
52
|
+
const target = hitTest(event);
|
|
53
|
+
if (target !== null && popup.contains(target)) {
|
|
54
|
+
const item = itemAt(target);
|
|
55
|
+
if (item === null || isDisabledItem(item) || item.hasAttribute("aria-haspopup")) return;
|
|
56
|
+
options.activate(item);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (shownAt !== null && performance.now() - shownAt >= DRAG_DISMISS_DELAY && isPopoverOpen(popup)) popup.hidePopover();
|
|
60
|
+
};
|
|
61
|
+
const onEnd = (event) => {
|
|
62
|
+
if (ours(event)) end();
|
|
63
|
+
};
|
|
64
|
+
const onToggle = () => {
|
|
65
|
+
if (!isPopoverOpen(popup)) end();
|
|
66
|
+
else shownAt ??= performance.now();
|
|
67
|
+
};
|
|
68
|
+
const end = () => {
|
|
69
|
+
popup.removeEventListener("pointermove", onMove);
|
|
70
|
+
popup.removeEventListener("pointerup", onUp);
|
|
71
|
+
popup.removeEventListener("pointercancel", onEnd);
|
|
72
|
+
popup.removeEventListener("lostpointercapture", onEnd);
|
|
73
|
+
popup.removeEventListener("toggle", onToggle);
|
|
74
|
+
submenuTrigger = null;
|
|
75
|
+
};
|
|
76
|
+
popup.addEventListener("pointermove", onMove);
|
|
77
|
+
popup.addEventListener("pointerup", onUp);
|
|
78
|
+
popup.addEventListener("pointercancel", onEnd);
|
|
79
|
+
popup.addEventListener("lostpointercapture", onEnd);
|
|
80
|
+
popup.addEventListener("toggle", onToggle);
|
|
81
|
+
return end;
|
|
82
|
+
}
|
|
83
|
+
/** How long the touch guard waits for the `touchend` that follows the finger's `pointerup`. */
|
|
84
|
+
const TOUCH_END_WAIT = 250;
|
|
85
|
+
/**
|
|
86
|
+
* The touch guard while the finger that opened a menu is down (context-menu.md 2.2): a
|
|
87
|
+
* non-passive `touchmove` listener keeps its drag from becoming a pan (`pointercancel`), and the
|
|
88
|
+
* lift's `touchend` is prevented so no click is synthesised (it would light-dismiss the menu or
|
|
89
|
+
* activate an item twice). Only that finger's lift ends it, recognised by order (its
|
|
90
|
+
* `pointerup` comes first; pointer events carry no `Touch.identifier`); other fingers'
|
|
91
|
+
* `touchend`s are prevented too. Also ends at `touchcancel`, the pointer's `pointercancel`, and
|
|
92
|
+
* shortly after its `pointerup` when no touch event follows. Returns the cleanup.
|
|
93
|
+
*/
|
|
94
|
+
function guardTouch(doc, pointerId) {
|
|
95
|
+
let fallback;
|
|
96
|
+
let lifted = false;
|
|
97
|
+
const onTouchMove = (event) => {
|
|
98
|
+
if (event.cancelable) event.preventDefault();
|
|
99
|
+
};
|
|
100
|
+
const onTouchEnd = (event) => {
|
|
101
|
+
if (event.cancelable) event.preventDefault();
|
|
102
|
+
if (lifted) end();
|
|
103
|
+
};
|
|
104
|
+
const onPointerUp = (event) => {
|
|
105
|
+
if (event.pointerId !== pointerId) return;
|
|
106
|
+
lifted = true;
|
|
107
|
+
fallback ??= setTimeout(end, TOUCH_END_WAIT);
|
|
108
|
+
};
|
|
109
|
+
const onPointerCancel = (event) => {
|
|
110
|
+
if (event.pointerId === pointerId) end();
|
|
111
|
+
};
|
|
112
|
+
const end = () => {
|
|
113
|
+
if (fallback !== void 0) clearTimeout(fallback);
|
|
114
|
+
doc.removeEventListener("touchmove", onTouchMove);
|
|
115
|
+
doc.removeEventListener("touchend", onTouchEnd);
|
|
116
|
+
doc.removeEventListener("touchcancel", end, true);
|
|
117
|
+
doc.removeEventListener("pointerup", onPointerUp, true);
|
|
118
|
+
doc.removeEventListener("pointercancel", onPointerCancel, true);
|
|
119
|
+
};
|
|
120
|
+
doc.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
121
|
+
doc.addEventListener("touchend", onTouchEnd, { passive: false });
|
|
122
|
+
doc.addEventListener("touchcancel", end, true);
|
|
123
|
+
doc.addEventListener("pointerup", onPointerUp, true);
|
|
124
|
+
doc.addEventListener("pointercancel", onPointerCancel, true);
|
|
125
|
+
return end;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* One-shot swallow of the `click` an engine may synthesise when the long-press ends (2.2),
|
|
129
|
+
* scoped to that release: the click comes in the same task as the `pointerup` of
|
|
130
|
+
* `pointerId`, so the swallow ends one task after that `pointerup` (or `pointercancel`), and at
|
|
131
|
+
* once on any `keydown`, the next `pointerdown`, or the menu closing. iOS synthesises no click
|
|
132
|
+
* after a long-press; a swallow left armed would eat the next keyboard activation
|
|
133
|
+
* (`element.click()`). `slot` holds the disarm of the armed swallow (one per region).
|
|
134
|
+
*/
|
|
135
|
+
function armClickSwallow(slot, doc, pointerId, releasing = false) {
|
|
136
|
+
slot.current?.();
|
|
137
|
+
let released;
|
|
138
|
+
const onClick = (event) => {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
event.stopPropagation();
|
|
141
|
+
disarm();
|
|
142
|
+
};
|
|
143
|
+
const onRelease = (event) => {
|
|
144
|
+
if (event.pointerId !== pointerId) return;
|
|
145
|
+
if (released === void 0) released = setTimeout(disarm, 0);
|
|
146
|
+
};
|
|
147
|
+
const disarm = () => {
|
|
148
|
+
if (released !== void 0) clearTimeout(released);
|
|
149
|
+
doc.removeEventListener("click", onClick, true);
|
|
150
|
+
doc.removeEventListener("pointerdown", disarm, true);
|
|
151
|
+
doc.removeEventListener("keydown", disarm, true);
|
|
152
|
+
doc.removeEventListener("pointerup", onRelease, true);
|
|
153
|
+
doc.removeEventListener("pointercancel", onRelease, true);
|
|
154
|
+
if (slot.current === disarm) slot.current = null;
|
|
155
|
+
};
|
|
156
|
+
doc.addEventListener("click", onClick, true);
|
|
157
|
+
doc.addEventListener("pointerdown", disarm, true);
|
|
158
|
+
doc.addEventListener("keydown", disarm, true);
|
|
159
|
+
doc.addEventListener("pointerup", onRelease, true);
|
|
160
|
+
doc.addEventListener("pointercancel", onRelease, true);
|
|
161
|
+
slot.current = disarm;
|
|
162
|
+
if (releasing) released = setTimeout(disarm, 0);
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
export { armClickSwallow, guardTouch, isTouchLike, startDrag };
|
|
166
|
+
|
|
167
|
+
//# sourceMappingURL=menu-gestures.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-gestures.mjs","names":[],"sources":["../../src/menu/menu-gestures.ts"],"sourcesContent":["// The pointer gestures of Menu.ContextTrigger (design/components/context-menu.md 2.2, 2.6). No\n// \"use client\" directive: DOM listeners only (conventions 7.1).\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { submenuHover } from \"./menu-context.js\";\nimport { isDisabledItem, ITEM_SELECTOR } from \"./menu-dom.js\";\n\n/** Movement that cancels a long-press (Base UI's slop); also a touch drag's activation slop. */\nexport const LONG_PRESS_SLOP = 10;\n/**\n * Movement a mouse or pen press-drag-release needs before a release activates or dismisses\n * (Chromium's `kMaximumLengthMovedToActivate`, macOS's \"moved\"; context-menu.md 2.6).\n */\nexport const DRAG_SLOP = 4;\n/** A release outside the menu dismisses it only this long after the open (GTK, Base UI). */\nconst DRAG_DISMISS_DELAY = 500;\n\ninterface DragOptions {\n readonly pointerId: number;\n /** The open point: the slop is measured from it. */\n readonly x: number;\n readonly y: number;\n readonly slop: number;\n /**\n * Activates `item` for a release: through `item.click()`, with the click swallow of a long-press\n * out of the way and armed again for the click an engine may synthesise from this release.\n */\n readonly activate: (item: HTMLElement) => void;\n}\n\nexport const isTouchLike = (pointerType: string) =>\n pointerType === \"touch\" || pointerType === \"pen\";\n\n/**\n * Press-drag-release (context-menu.md 2.6). The popup holds the capture of `pointerId`, so its\n * items see no boundary events and the gesture hit-tests with `elementFromPoint`. A move focuses\n * the item under the pointer without the ring (a SubmenuTrigger starts its hover intent); a\n * release beyond the slop activates an enabled, non-submenu item through `click()`, or dismisses\n * when outside every popup of the tree at least 500 ms after the popup was shown (not after the\n * press: an async open appears late). Ends at the release, `pointercancel`,\n * `lostpointercapture` or the close. Returns the cleanup.\n */\nexport function startDrag(popup: HTMLElement, options: DragOptions): () => void {\n const doc = popup.ownerDocument;\n // `performance.now()` at the first open `toggle`; null until the popup has been shown.\n let shownAt: number | null = isPopoverOpen(popup) ? performance.now() : null;\n // The SubmenuTrigger the pointer is over, whose hover intent is running.\n let submenuTrigger: HTMLElement | null = null;\n\n const ours = (event: Event) => (event as globalThis.PointerEvent).pointerId === options.pointerId;\n const hitTest = (event: globalThis.PointerEvent): Element | null =>\n typeof doc.elementFromPoint === \"function\"\n ? doc.elementFromPoint(event.clientX, event.clientY)\n : null;\n /** The item under the pointer, inside this menu's tree (submenus are DOM descendants). */\n const itemAt = (target: Element | null): HTMLElement | null => {\n const item = target?.closest<HTMLElement>(ITEM_SELECTOR) ?? null;\n return item !== null && popup.contains(item) ? item : null;\n };\n /** The pointer is over the submenu `trigger` opens (its popup is the `commandfor` target). */\n const inSubmenuOf = (trigger: HTMLElement, target: Element | null) => {\n const id = trigger.getAttribute(\"commandfor\");\n const submenu = id === null ? null : doc.getElementById(id);\n return submenu !== null && target !== null && submenu.contains(target);\n };\n const hoverSubmenu = (next: HTMLElement | null, event: Event) => {\n if (next === submenuTrigger) return;\n if (submenuTrigger !== null) submenuHover(submenuTrigger)?.leave(event);\n submenuTrigger = next;\n if (next !== null) submenuHover(next)?.enter(event);\n };\n\n const onMove = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n const target = hitTest(event);\n const item = itemAt(target);\n // Menu 6.2's pointer focus, without the ring: keyboard and pointer agree on the current item.\n if (item !== null && doc.activeElement !== item) {\n item.focus({ focusVisible: false } as FocusOptions);\n }\n if (item !== null && submenuHover(item) !== undefined) hoverSubmenu(item, event);\n else if (submenuTrigger !== null && !inSubmenuOf(submenuTrigger, target)) {\n hoverSubmenu(null, event);\n }\n };\n const onUp = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n end();\n const moved = Math.hypot(event.clientX - options.x, event.clientY - options.y) > options.slop;\n // Time alone never activates or dismisses: a stationary release keeps the menu open.\n if (!moved) return;\n const target = hitTest(event);\n if (target !== null && popup.contains(target)) {\n const item = itemAt(target);\n // A disabled item, a SubmenuTrigger (native menus activate nothing there), a separator or\n // padding: the menu stays open.\n if (item === null || isDisabledItem(item) || item.hasAttribute(\"aria-haspopup\")) return;\n options.activate(item);\n return;\n }\n if (\n shownAt !== null &&\n performance.now() - shownAt >= DRAG_DISMISS_DELAY &&\n isPopoverOpen(popup)\n ) {\n popup.hidePopover();\n }\n };\n const onEnd = (event: Event) => {\n if (ours(event)) end();\n };\n const onToggle = () => {\n if (!isPopoverOpen(popup)) end();\n else shownAt ??= performance.now();\n };\n const end = () => {\n popup.removeEventListener(\"pointermove\", onMove);\n popup.removeEventListener(\"pointerup\", onUp);\n popup.removeEventListener(\"pointercancel\", onEnd);\n popup.removeEventListener(\"lostpointercapture\", onEnd);\n popup.removeEventListener(\"toggle\", onToggle);\n submenuTrigger = null;\n };\n popup.addEventListener(\"pointermove\", onMove);\n popup.addEventListener(\"pointerup\", onUp);\n popup.addEventListener(\"pointercancel\", onEnd);\n popup.addEventListener(\"lostpointercapture\", onEnd);\n popup.addEventListener(\"toggle\", onToggle);\n return end;\n}\n\n/** How long the touch guard waits for the `touchend` that follows the finger's `pointerup`. */\nconst TOUCH_END_WAIT = 250;\n\n/**\n * The touch guard while the finger that opened a menu is down (context-menu.md 2.2): a\n * non-passive `touchmove` listener keeps its drag from becoming a pan (`pointercancel`), and the\n * lift's `touchend` is prevented so no click is synthesised (it would light-dismiss the menu or\n * activate an item twice). Only that finger's lift ends it, recognised by order (its\n * `pointerup` comes first; pointer events carry no `Touch.identifier`); other fingers'\n * `touchend`s are prevented too. Also ends at `touchcancel`, the pointer's `pointercancel`, and\n * shortly after its `pointerup` when no touch event follows. Returns the cleanup.\n */\nexport function guardTouch(doc: Document, pointerId: number): () => void {\n let fallback: ReturnType<typeof setTimeout> | undefined;\n // The gesture's pointer has lifted: the next `touchend` is its own.\n let lifted = false;\n const onTouchMove = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n };\n const onTouchEnd = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n if (lifted) end();\n };\n const onPointerUp = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n lifted = true;\n fallback ??= setTimeout(end, TOUCH_END_WAIT);\n };\n const onPointerCancel = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId === pointerId) end();\n };\n const end = () => {\n if (fallback !== undefined) clearTimeout(fallback);\n doc.removeEventListener(\"touchmove\", onTouchMove);\n doc.removeEventListener(\"touchend\", onTouchEnd);\n doc.removeEventListener(\"touchcancel\", end, true);\n doc.removeEventListener(\"pointerup\", onPointerUp, true);\n doc.removeEventListener(\"pointercancel\", onPointerCancel, true);\n };\n doc.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n doc.addEventListener(\"touchend\", onTouchEnd, { passive: false });\n doc.addEventListener(\"touchcancel\", end, true);\n doc.addEventListener(\"pointerup\", onPointerUp, true);\n doc.addEventListener(\"pointercancel\", onPointerCancel, true);\n return end;\n}\n\n/**\n * One-shot swallow of the `click` an engine may synthesise when the long-press ends (2.2),\n * scoped to that release: the click comes in the same task as the `pointerup` of\n * `pointerId`, so the swallow ends one task after that `pointerup` (or `pointercancel`), and at\n * once on any `keydown`, the next `pointerdown`, or the menu closing. iOS synthesises no click\n * after a long-press; a swallow left armed would eat the next keyboard activation\n * (`element.click()`). `slot` holds the disarm of the armed swallow (one per region).\n */\nexport function armClickSwallow(\n slot: { current: (() => void) | null },\n doc: Document,\n pointerId: number,\n releasing = false,\n): void {\n slot.current?.();\n let released: ReturnType<typeof setTimeout> | undefined;\n const onClick = (event: Event) => {\n event.preventDefault();\n event.stopPropagation();\n disarm();\n };\n const onRelease = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n if (released === undefined) released = setTimeout(disarm, 0);\n };\n const disarm = () => {\n if (released !== undefined) clearTimeout(released);\n doc.removeEventListener(\"click\", onClick, true);\n doc.removeEventListener(\"pointerdown\", disarm, true);\n doc.removeEventListener(\"keydown\", disarm, true);\n doc.removeEventListener(\"pointerup\", onRelease, true);\n doc.removeEventListener(\"pointercancel\", onRelease, true);\n if (slot.current === disarm) slot.current = null;\n };\n doc.addEventListener(\"click\", onClick, true);\n doc.addEventListener(\"pointerdown\", disarm, true);\n doc.addEventListener(\"keydown\", disarm, true);\n doc.addEventListener(\"pointerup\", onRelease, true);\n doc.addEventListener(\"pointercancel\", onRelease, true);\n slot.current = disarm;\n // Armed from inside the release itself (a drag activation): the click comes in this task.\n if (releasing) released = setTimeout(disarm, 0);\n}\n"],"mappings":";;;;;AAcA,MAAM,qBAAqB;AAe3B,MAAa,eAAe,gBAC1B,gBAAgB,WAAW,gBAAgB;;;;;;;;;;AAW7C,SAAgB,UAAU,OAAoB,SAAkC;CAC9E,MAAM,MAAM,MAAM;CAElB,IAAI,UAAyB,cAAc,KAAK,IAAI,YAAY,IAAI,IAAI;CAExE,IAAI,iBAAqC;CAEzC,MAAM,QAAQ,UAAkB,MAAkC,cAAc,QAAQ;CACxF,MAAM,WAAW,UACf,OAAO,IAAI,qBAAqB,aAC5B,IAAI,iBAAiB,MAAM,SAAS,MAAM,OAAO,IACjD;;CAEN,MAAM,UAAU,WAA+C;EAC7D,MAAM,OAAO,QAAQ,QAAA,4EAAkC,KAAK;EAC5D,OAAO,SAAS,QAAQ,MAAM,SAAS,IAAI,IAAI,OAAO;CACxD;;CAEA,MAAM,eAAe,SAAsB,WAA2B;EACpE,MAAM,KAAK,QAAQ,aAAa,YAAY;EAC5C,MAAM,UAAU,OAAO,OAAO,OAAO,IAAI,eAAe,EAAE;EAC1D,OAAO,YAAY,QAAQ,WAAW,QAAQ,QAAQ,SAAS,MAAM;CACvE;CACA,MAAM,gBAAgB,MAA0B,UAAiB;EAC/D,IAAI,SAAS,gBAAgB;EAC7B,IAAI,mBAAmB,MAAM,aAAa,cAAc,CAAC,EAAE,MAAM,KAAK;EACtE,iBAAiB;EACjB,IAAI,SAAS,MAAM,aAAa,IAAI,CAAC,EAAE,MAAM,KAAK;CACpD;CAEA,MAAM,UAAU,UAAmC;EACjD,IAAI,CAAC,KAAK,KAAK,GAAG;EAClB,MAAM,SAAS,QAAQ,KAAK;EAC5B,MAAM,OAAO,OAAO,MAAM;EAE1B,IAAI,SAAS,QAAQ,IAAI,kBAAkB,MACzC,KAAK,MAAM,EAAE,cAAc,MAAM,CAAiB;EAE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aAAa,QAAQ;EACjD,IAAI,oBAAoB,SAAS,SAAS,IAAI;EAC9C,IAAI,oBAAoB,eAAe,QAAQ,IAAI;EACnD,IAAI,oBAAoB,WAAW,QAAQ,IAAI;EAC/C,IAAI,oBAAoB,aAAa,WAAW,IAAI;EACpD,IAAI,oBAAoB,iBAAiB,WAAW,IAAI;EACxD,IAAI,KAAK,YAAY,QAAQ,KAAK,UAAU;CAC9C;CACA,IAAI,iBAAiB,SAAS,SAAS,IAAI;CAC3C,IAAI,iBAAiB,eAAe,QAAQ,IAAI;CAChD,IAAI,iBAAiB,WAAW,QAAQ,IAAI;CAC5C,IAAI,iBAAiB,aAAa,WAAW,IAAI;CACjD,IAAI,iBAAiB,iBAAiB,WAAW,IAAI;CACrD,KAAK,UAAU;CAEf,IAAI,WAAW,WAAW,WAAW,QAAQ,CAAC;AAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-group.d.mts","names":[],"sources":["../../src/menu/menu-group.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"menu-group.d.mts","names":[],"sources":["../../src/menu/menu-group.tsx"],"mappings":";;;;YAWY,iBAAiB;YACjB,sBAAsB;YACtB,qBAAqB;iBAIhB,uBAAuB,KACtC;EAGA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;;;;;wBAOpC,YAAY,WAAW,OAAO,UAAU,WAAW,QAAQ,iCAAc,IAAA;yBAAzE;;;iBAkBC,4BAA4B,KAC3C;EAGA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;;;;;wBAOpC,iBACd,WACA,OACA,UACA,WACG,QACF,sBAAmB;yBANN;;;iBA0BC,2BAA2B,KAC1C;EAGA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,6BAA6B;;;wBAInC,gBAAgB,WAAW,OAAO,WAAW,QAAQ,qBAAkB;yBAAvE"}
|
package/dist/menu/menu-group.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { MenuGroupContext } from "./menu-context.mjs";
|
|
|
5
5
|
import { use, useId, useMemo } from "react";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/menu/menu-group.tsx
|
|
8
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
8
9
|
const EMPTY = {};
|
|
9
10
|
/**
|
|
10
11
|
* A labelled set of items: `<div role="group" aria-labelledby>` named by the `Menu.GroupLabel`
|
|
@@ -38,7 +39,7 @@ MenuGroup.displayName = "MenuGroup";
|
|
|
38
39
|
*/
|
|
39
40
|
function MenuGroupLabel({ className, style, children, render, ...rest }) {
|
|
40
41
|
const group = use(MenuGroupContext);
|
|
41
|
-
useDevWarning(group === null, "Menu.GroupLabel: rendered outside a Menu.Group or Menu.RadioGroup; it names nothing.");
|
|
42
|
+
useDevWarning(group === null, isDev && "Menu.GroupLabel: rendered outside a Menu.Group or Menu.RadioGroup; it names nothing.");
|
|
42
43
|
return useRender({
|
|
43
44
|
defaultElement: "div",
|
|
44
45
|
render,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-group.mjs","names":[],"sources":["../../src/menu/menu-group.tsx"],"sourcesContent":["\"use client\";\nimport { use, useId, useMemo } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { MenuGroupContext } from \"./menu-context.js\";\n\n/** `Menu.Group`, `Menu.GroupLabel` and `Menu.Separator` have no state. */\nexport type MenuGroupState = Record<string, never>;\nexport type MenuGroupLabelState = Record<string, never>;\nexport type MenuSeparatorState = Record<string, never>;\n\nconst EMPTY: Record<string, never> = {};\n\nexport interface MenuGroupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, MenuGroupState>;\n style?: StateValue<CSSProperties | undefined, MenuGroupState>;\n children?: StateValue<ReactNode, MenuGroupState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuGroupState>;\n}\n\n/**\n * A labelled set of items: `<div role=\"group\" aria-labelledby>` named by the `Menu.GroupLabel`\n * inside it. Owned keys: `role`, `aria-labelledby` (token-merged).\n */\nexport function MenuGroup({ className, style, children, render, ...rest }: MenuGroupProps) {\n const labelId = `${useId()}-label`;\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuGroupState>({\n defaultElement: \"div\",\n render,\n state: EMPTY,\n className,\n style,\n children,\n props: rest,\n libraryProps: { role: \"group\", \"aria-labelledby\": labelId },\n });\n const context = useMemo(() => ({ labelId }), [labelId]);\n return <MenuGroupContext value={context}>{element}</MenuGroupContext>;\n}\n\nMenuGroup.displayName = \"MenuGroup\";\n\nexport interface MenuGroupLabelProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, MenuGroupLabelState>;\n style?: StateValue<CSSProperties | undefined, MenuGroupLabelState>;\n children?: StateValue<ReactNode, MenuGroupLabelState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuGroupLabelState>;\n}\n\n/**\n * The name of the enclosing `Menu.Group` or `Menu.RadioGroup`: a `<div>` with the id the group's\n * `aria-labelledby` references. Owned key: `id`.\n */\nexport function MenuGroupLabel({\n className,\n style,\n children,\n render,\n ...rest\n}: MenuGroupLabelProps) {\n const group = use(MenuGroupContext);\n useDevWarning(\n group === null,\n \"Menu.GroupLabel: rendered outside a Menu.Group or Menu.RadioGroup; it names nothing.\",\n );\n return useRender<ComponentPropsWithRef<\"div\">, MenuGroupLabelState>({\n defaultElement: \"div\",\n render,\n state: EMPTY,\n className,\n style,\n children,\n props: rest,\n libraryProps: group === null ? {} : { id: group.labelId },\n });\n}\n\nMenuGroupLabel.displayName = \"MenuGroupLabel\";\n\nexport interface MenuSeparatorProps extends Omit<\n ComponentPropsWithRef<\"hr\">,\n \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, MenuSeparatorState>;\n style?: StateValue<CSSProperties | undefined, MenuSeparatorState>;\n /** Another element must carry `role=\"separator\"` itself. */\n render?: RenderProp<ComponentPropsWithRef<\"hr\">, MenuSeparatorState>;\n}\n\n/** A divider between items: `<hr>` (implicit `role=\"separator\"`). Owns no keys. */\nexport function MenuSeparator({ className, style, render, ...rest }: MenuSeparatorProps) {\n return useRender<ComponentPropsWithRef<\"hr\">, MenuSeparatorState>({\n defaultElement: \"hr\",\n render,\n state: EMPTY,\n className,\n style,\n children: undefined,\n props: rest,\n });\n}\n\nMenuSeparator.displayName = \"MenuSeparator\";\n"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"menu-group.mjs","names":[],"sources":["../../src/menu/menu-group.tsx"],"sourcesContent":["\"use client\";\nimport { use, useId, useMemo } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { MenuGroupContext } from \"./menu-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `Menu.Group`, `Menu.GroupLabel` and `Menu.Separator` have no state. */\nexport type MenuGroupState = Record<string, never>;\nexport type MenuGroupLabelState = Record<string, never>;\nexport type MenuSeparatorState = Record<string, never>;\n\nconst EMPTY: Record<string, never> = {};\n\nexport interface MenuGroupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, MenuGroupState>;\n style?: StateValue<CSSProperties | undefined, MenuGroupState>;\n children?: StateValue<ReactNode, MenuGroupState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuGroupState>;\n}\n\n/**\n * A labelled set of items: `<div role=\"group\" aria-labelledby>` named by the `Menu.GroupLabel`\n * inside it. Owned keys: `role`, `aria-labelledby` (token-merged).\n */\nexport function MenuGroup({ className, style, children, render, ...rest }: MenuGroupProps) {\n const labelId = `${useId()}-label`;\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuGroupState>({\n defaultElement: \"div\",\n render,\n state: EMPTY,\n className,\n style,\n children,\n props: rest,\n libraryProps: { role: \"group\", \"aria-labelledby\": labelId },\n });\n const context = useMemo(() => ({ labelId }), [labelId]);\n return <MenuGroupContext value={context}>{element}</MenuGroupContext>;\n}\n\nMenuGroup.displayName = \"MenuGroup\";\n\nexport interface MenuGroupLabelProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, MenuGroupLabelState>;\n style?: StateValue<CSSProperties | undefined, MenuGroupLabelState>;\n children?: StateValue<ReactNode, MenuGroupLabelState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuGroupLabelState>;\n}\n\n/**\n * The name of the enclosing `Menu.Group` or `Menu.RadioGroup`: a `<div>` with the id the group's\n * `aria-labelledby` references. Owned key: `id`.\n */\nexport function MenuGroupLabel({\n className,\n style,\n children,\n render,\n ...rest\n}: MenuGroupLabelProps) {\n const group = use(MenuGroupContext);\n useDevWarning(\n group === null,\n isDev && \"Menu.GroupLabel: rendered outside a Menu.Group or Menu.RadioGroup; it names nothing.\",\n );\n return useRender<ComponentPropsWithRef<\"div\">, MenuGroupLabelState>({\n defaultElement: \"div\",\n render,\n state: EMPTY,\n className,\n style,\n children,\n props: rest,\n libraryProps: group === null ? {} : { id: group.labelId },\n });\n}\n\nMenuGroupLabel.displayName = \"MenuGroupLabel\";\n\nexport interface MenuSeparatorProps extends Omit<\n ComponentPropsWithRef<\"hr\">,\n \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, MenuSeparatorState>;\n style?: StateValue<CSSProperties | undefined, MenuSeparatorState>;\n /** Another element must carry `role=\"separator\"` itself. */\n render?: RenderProp<ComponentPropsWithRef<\"hr\">, MenuSeparatorState>;\n}\n\n/** A divider between items: `<hr>` (implicit `role=\"separator\"`). Owns no keys. */\nexport function MenuSeparator({ className, style, render, ...rest }: MenuSeparatorProps) {\n return useRender<ComponentPropsWithRef<\"hr\">, MenuSeparatorState>({\n defaultElement: \"hr\",\n render,\n state: EMPTY,\n className,\n style,\n children: undefined,\n props: rest,\n });\n}\n\nMenuSeparator.displayName = \"MenuSeparator\";\n"],"mappings":";;;;;;;AAQA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAOvC,MAAM,QAA+B,CAAC;;;;;AAgBtC,SAAgB,UAAU,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QAAwB;CACzF,MAAM,UAAU,GAAG,MAAM,EAAE;CAC3B,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP,cAAc;GAAE,MAAM;GAAS,mBAAmB;EAAQ;CAC5D,CAAC;CACD,MAAM,UAAU,eAAe,EAAE,QAAQ,IAAI,CAAC,OAAO,CAAC;CACtD,OAAO,oBAAC,kBAAD;EAAkB,OAAO;EAAU,UAAA;CAA0B,CAAA;AACtE;AAEA,UAAU,cAAc;;;;;AAgBxB,SAAgB,eAAe,EAC7B,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,QAAQ,IAAI,gBAAgB;CAClC,cACE,UAAU,MACV,SAAS,sFACX;CACA,OAAO,UAA6D;EAClE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP,cAAc,UAAU,OAAO,CAAC,IAAI,EAAE,IAAI,MAAM,QAAQ;CAC1D,CAAC;AACH;AAEA,eAAe,cAAc;;AAa7B,SAAgB,cAAc,EAAE,WAAW,OAAO,QAAQ,GAAG,QAA4B;CACvF,OAAO,UAA2D;EAChE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA,UAAU,KAAA;EACV,OAAO;CACT,CAAC;AACH;AAEA,cAAc,cAAc"}
|
package/dist/menu/menu-hover.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-hover.mjs","names":[],"sources":["../../src/menu/menu-hover.ts"],"sourcesContent":["\"use client\"
|
|
1
|
+
{"version":3,"file":"menu-hover.mjs","names":[],"sources":["../../src/menu/menu-hover.ts"],"sourcesContent":["// Hover intent of submenus. No \"use client\" directive: no hooks (conventions 7.1).\nimport type { MenuContextValue } from \"./menu-context.js\";\n\nfunction hovered(element: Element | null): boolean {\n if (element === null) return false;\n try {\n return element.matches(\":hover\");\n } catch {\n return false;\n }\n}\n\n/**\n * Starts the submenu's `closeDelay` (design/components/menu.md 7): on expiry the submenu closes\n * with `\"dismiss\"` unless the pointer is back over its SubmenuTrigger or Popup, or keyboard focus\n * is inside it (a user who arrowed in and nudged the mouse keeps the submenu).\n */\nexport function scheduleHoverClose(menu: MenuContextValue, event: Event): void {\n const { popover, timers, closeDelay } = menu;\n timers.close(closeDelay, () => {\n const popup = popover.popupRef.current;\n if (hovered(popover.triggerRef.current) || hovered(popup)) return;\n const active = popup?.ownerDocument.activeElement ?? null;\n if (popup !== null && active !== null && popup.contains(active)) return;\n popover.requestClose(event, \"dismiss\");\n });\n}\n"],"mappings":";AAGA,SAAS,QAAQ,SAAkC;CACjD,IAAI,YAAY,MAAM,OAAO;CAC7B,IAAI;EACF,OAAO,QAAQ,QAAQ,QAAQ;CACjC,QAAQ;EACN,OAAO;CACT;AACF;;;;;;AAOA,SAAgB,mBAAmB,MAAwB,OAAoB;CAC7E,MAAM,EAAE,SAAS,QAAQ,eAAe;CACxC,OAAO,MAAM,kBAAkB;EAC7B,MAAM,QAAQ,QAAQ,SAAS;EAC/B,IAAI,QAAQ,QAAQ,WAAW,OAAO,KAAK,QAAQ,KAAK,GAAG;EAC3D,MAAM,SAAS,OAAO,cAAc,iBAAiB;EACrD,IAAI,UAAU,QAAQ,WAAW,QAAQ,MAAM,SAAS,MAAM,GAAG;EACjE,QAAQ,aAAa,OAAO,SAAS;CACvC,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-item.mjs","names":[],"sources":["../../src/menu/menu-item.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { Action, ActionDetails, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\n/** Details passed to `Menu.Item`'s `action`. */\nexport interface MenuItemDetails extends ActionDetails {}\n\nexport interface MenuItemState {\n /** This item's `action` is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface MenuItemProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"onKeyDown\" | \"onPointerMove\" | \"disabled\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this item's own transition (`data-pending` on the item); the menu stays open\n * until it settles, then the whole menu closes (`closeOnActivate`). May be a Server Function\n * (`details.event` is virtual). A rejection leaves the menu open and reaches the nearest Error\n * Boundary above the item. Without `action`, activation only closes.\n */\n action?: Action<[details: MenuItemDetails]>;\n /** Close the whole menu once `action` settles. Default `true`. */\n closeOnActivate?: boolean;\n /**\n * Renders `aria-disabled` and `data-disabled`: the item stays focusable and never activates.\n * It is an ordinary item for navigation; only the open focus skips items with `disabled`.\n */\n disabled?: boolean;\n /** Text typeahead matches when the item's text content is not representative (an icon). */\n label?: string;\n className?: StateValue<string | undefined, MenuItemState>;\n style?: StateValue<CSSProperties | undefined, MenuItemState>;\n children?: StateValue<ReactNode, MenuItemState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuItemState>;\n}\n\n/**\n * A menu command: `<button type=\"button\" role=\"menuitem\" tabindex=\"-1\">`. Click, Enter or Space\n * runs `action` in the item's own transition (`data-pending` and `aria-disabled` on the item; a\n * second activation meanwhile is ignored); once it resolves the whole menu stack closes\n * through the top-level Root (`openChangeAction(false, { reason: \"activate\" })` awaited, view\n * transition if set). Hovering the item focuses it.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>`), `role`, `tabIndex`, `disabled`\n * (always absent), `aria-disabled`, `onClick`, `onKeyDown`, `onPointerMove`, `data-pending`,\n * `data-disabled`, `data-typeahead`.\n */\nexport function MenuItem({\n action,\n closeOnActivate = true,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuItemProps) {\n const menu = useMenuContext(\"Menu.Item\");\n // The close belongs to the top-level menu, so its open generation guards it.\n const { pending, run } = useActionTrigger({ openGeneration: menu.root.popover.openGeneration });\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.Item\",\n role: \"menuitem\",\n disabled,\n label,\n activate: (event) => {\n const details: MenuItemDetails = createActionDetails(event, {});\n // A second activation while this item's own run is in flight starts nothing and is\n // cancelled (the hook's guard
|
|
1
|
+
{"version":3,"file":"menu-item.mjs","names":[],"sources":["../../src/menu/menu-item.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { Action, ActionDetails, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\n/** Details passed to `Menu.Item`'s `action`. */\nexport interface MenuItemDetails extends ActionDetails {}\n\nexport interface MenuItemState {\n /** This item's `action` is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface MenuItemProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"onKeyDown\" | \"onPointerMove\" | \"disabled\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this item's own transition (`data-pending` on the item); the menu stays open\n * until it settles, then the whole menu closes (`closeOnActivate`). May be a Server Function\n * (`details.event` is virtual). A rejection leaves the menu open and reaches the nearest Error\n * Boundary above the item. Without `action`, activation only closes.\n */\n action?: Action<[details: MenuItemDetails]>;\n /** Close the whole menu once `action` settles. Default `true`. */\n closeOnActivate?: boolean;\n /**\n * Renders `aria-disabled` and `data-disabled`: the item stays focusable and never activates.\n * It is an ordinary item for navigation; only the open focus skips items with `disabled`.\n */\n disabled?: boolean;\n /** Text typeahead matches when the item's text content is not representative (an icon). */\n label?: string;\n className?: StateValue<string | undefined, MenuItemState>;\n style?: StateValue<CSSProperties | undefined, MenuItemState>;\n children?: StateValue<ReactNode, MenuItemState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuItemState>;\n}\n\n/**\n * A menu command: `<button type=\"button\" role=\"menuitem\" tabindex=\"-1\">`. Click, Enter or Space\n * runs `action` in the item's own transition (`data-pending` and `aria-disabled` on the item; a\n * second activation meanwhile is ignored); once it resolves the whole menu stack closes\n * through the top-level Root (`openChangeAction(false, { reason: \"activate\" })` awaited, view\n * transition if set). Hovering the item focuses it.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>`), `role`, `tabIndex`, `disabled`\n * (always absent), `aria-disabled`, `onClick`, `onKeyDown`, `onPointerMove`, `data-pending`,\n * `data-disabled`, `data-typeahead`.\n */\nexport function MenuItem({\n action,\n closeOnActivate = true,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuItemProps) {\n const menu = useMenuContext(\"Menu.Item\");\n // The close belongs to the top-level menu, so its open generation guards it.\n const { pending, run } = useActionTrigger({ openGeneration: menu.root.popover.openGeneration });\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.Item\",\n role: \"menuitem\",\n disabled,\n label,\n activate: (event) => {\n const details: MenuItemDetails = createActionDetails(event, {});\n // A second activation while this item's own run is in flight starts nothing and is\n // cancelled (the hook's guard): a link does not navigate, a composed command does not\n // run. Enter / Space reach here through the element's click, their keydown is cancelled.\n const started = run(\n () => action?.(details),\n closeOnActivate ? () => menu.root.popover.requestClose(event, \"activate\") : undefined,\n );\n if (!started) event.preventDefault();\n },\n });\n\n const state: MenuItemState = { pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuItemState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...(rendersButton(render) && { type: \"button\" as const }),\n ...libraryProps,\n // Also while pending: an item that will not act is unavailable to AT. Navigation keys\n // on `data-disabled` (the `disabled` prop), so a pending item is still an enabled item.\n \"aria-disabled\": disabled || pending ? true : undefined,\n \"data-pending\": dataAttr(pending),\n },\n });\n}\n\nMenuItem.displayName = \"MenuItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,SAAS,EACvB,QACA,kBAAkB,MAClB,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACa;CAChB,MAAM,OAAO,eAAe,WAAW;CAEvC,MAAM,EAAE,SAAS,QAAQ,iBAAiB,EAAE,gBAAgB,KAAK,KAAK,QAAQ,eAAe,CAAC;CAE9F,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAA2B,oBAAoB,OAAO,CAAC,CAAC;GAQ9D,IAAI,CAJY,UACR,SAAS,OAAO,GACtB,wBAAwB,KAAK,KAAK,QAAQ,aAAa,OAAO,UAAU,IAAI,KAAA,CAEnE,GAAG,MAAM,eAAe;EACrC;CACF,CAAC;CAID,OAAO,UAA0D;EAC/D,gBAAgB;EAChB;EACA,OAAA;GAL6B;GAAS;EAKlC;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GAGH,iBAAiB,YAAY,UAAU,OAAO,KAAA;GAC9C,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;AACH;AAEA,SAAS,cAAc"}
|