@funstack/ui 0.1.0-alpha.18 → 0.1.0-alpha.19
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-item.mjs +1 -1
- package/dist/accordion/accordion-panel.mjs +1 -1
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +30 -35
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +1 -1
- package/dist/button/button.d.mts +11 -6
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +25 -14
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.mjs +1 -1
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +3 -3
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +3 -3
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +5 -5
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.mjs +2 -2
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +81 -0
- package/dist/combobox/combobox-keyboard.mjs.map +1 -0
- package/dist/combobox/combobox-popup.mjs +3 -3
- 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 +44 -129
- 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 +2 -9
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/use-active-option.mjs +49 -0
- package/dist/combobox/use-active-option.mjs.map +1 -0
- package/dist/combobox/use-combobox-form.mjs +3 -5
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/combobox/use-combobox-text.mjs +43 -0
- package/dist/combobox/use-combobox-text.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +7 -17
- package/dist/combobox/use-option-registry.mjs.map +1 -1
- package/dist/dialog/dialog-close.mjs +2 -2
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-dismiss.mjs +108 -0
- package/dist/dialog/dialog-dismiss.mjs.map +1 -0
- package/dist/dialog/dialog-form.mjs +4 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +73 -169
- 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 +4 -3
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +11 -8
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/button.md +3 -3
- package/dist/docs/components/dialog.md +3 -3
- package/dist/docs/components/field.md +4 -3
- package/dist/docs/components/popover.md +3 -3
- package/dist/docs/components/toast.md +8 -5
- package/dist/docs/roadmap.md +9 -1
- package/dist/field/field-control.d.mts +1 -1
- package/dist/field/field-control.mjs +2 -2
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts +1 -1
- package/dist/field/field-description.mjs +1 -1
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts +1 -1
- package/dist/field/field-error.mjs +1 -1
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts +1 -1
- package/dist/field/field-label.mjs +1 -1
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.d.mts +2 -2
- package/dist/field/field-root.d.mts.map +1 -1
- package/dist/field/field-root.mjs +4 -4
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.d.mts +2 -2
- package/dist/form/form-root.d.mts +1 -1
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +14 -4
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +7 -3
- package/dist/form/form-submit.d.mts.map +1 -1
- package/dist/form/form-submit.mjs +11 -7
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/form/index.d.mts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/internal/{action-details.mjs → action/action-details.mjs} +1 -1
- package/dist/internal/action/action-details.mjs.map +1 -0
- package/dist/internal/{call-urgent-handler.mjs → action/call-urgent-handler.mjs} +5 -10
- package/dist/internal/action/call-urgent-handler.mjs.map +1 -0
- package/dist/internal/{report-dropped.mjs → action/report-dropped.mjs} +3 -21
- package/dist/internal/action/report-dropped.mjs.map +1 -0
- package/dist/internal/{use-action-trigger.mjs → action/use-action-trigger.mjs} +3 -2
- package/dist/internal/action/use-action-trigger.mjs.map +1 -0
- package/dist/internal/action/use-connected.mjs +24 -0
- package/dist/internal/action/use-connected.mjs.map +1 -0
- package/dist/internal/{use-controllable-action.mjs → action/use-controllable-action.mjs} +13 -28
- package/dist/internal/action/use-controllable-action.mjs.map +1 -0
- package/dist/internal/action/use-pure-trigger.mjs +34 -0
- package/dist/internal/action/use-pure-trigger.mjs.map +1 -0
- package/dist/internal/action/use-step-commit.mjs +147 -0
- package/dist/internal/action/use-step-commit.mjs.map +1 -0
- package/dist/internal/{field-context.d.mts → form/field-context.d.mts} +1 -1
- package/dist/internal/form/field-context.d.mts.map +1 -0
- package/dist/internal/{field-context.mjs → form/field-context.mjs} +2 -2
- package/dist/internal/form/field-context.mjs.map +1 -0
- package/dist/internal/{focus-first-invalid.mjs → form/focus-first-invalid.mjs} +3 -3
- package/dist/internal/form/focus-first-invalid.mjs.map +1 -0
- package/dist/internal/{form-status-watcher.mjs → form/form-status-watcher.mjs} +1 -1
- package/dist/internal/form/form-status-watcher.mjs.map +1 -0
- package/dist/internal/{group-member.mjs → form/group-member.mjs} +2 -2
- package/dist/internal/form/group-member.mjs.map +1 -0
- package/dist/internal/{sync-presence.mjs → form/sync-presence.mjs} +1 -1
- package/dist/internal/form/sync-presence.mjs.map +1 -0
- package/dist/internal/{use-checkable-input.mjs → form/use-checkable-input.mjs} +5 -5
- package/dist/internal/form/use-checkable-input.mjs.map +1 -0
- package/dist/internal/{use-field-control.mjs → form/use-field-control.mjs} +3 -3
- package/dist/internal/form/use-field-control.mjs.map +1 -0
- package/dist/internal/{use-fieldset-group.mjs → form/use-fieldset-group.mjs} +3 -3
- package/dist/internal/form/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/{use-form-owner-event.mjs → form/use-form-owner-event.mjs} +1 -1
- package/dist/internal/form/use-form-owner-event.mjs.map +1 -0
- package/dist/internal/{use-form-reset.mjs → form/use-form-reset.mjs} +15 -3
- package/dist/internal/form/use-form-reset.mjs.map +1 -0
- package/dist/internal/{use-native-checked.mjs → form/use-native-checked.mjs} +5 -4
- package/dist/internal/form/use-native-checked.mjs.map +1 -0
- package/dist/internal/{use-native-group-reconciliation.mjs → form/use-native-group-reconciliation.mjs} +2 -2
- package/dist/internal/form/use-native-group-reconciliation.mjs.map +1 -0
- package/dist/internal/{use-native-select-value.mjs → form/use-native-select-value.mjs} +2 -2
- package/dist/internal/form/use-native-select-value.mjs.map +1 -0
- package/dist/internal/{validity.d.mts → form/validity.d.mts} +1 -1
- package/dist/internal/form/validity.d.mts.map +1 -0
- package/dist/internal/{validity.mjs → form/validity.mjs} +1 -1
- package/dist/internal/form/validity.mjs.map +1 -0
- package/dist/internal/{anchor-position.d.mts → overlay/anchor-position.d.mts} +1 -1
- package/dist/internal/overlay/anchor-position.d.mts.map +1 -0
- package/dist/internal/{anchor-position.mjs → overlay/anchor-position.mjs} +1 -1
- package/dist/internal/overlay/anchor-position.mjs.map +1 -0
- package/dist/internal/{content-focus-probe.mjs → overlay/content-focus-probe.mjs} +1 -1
- package/dist/internal/overlay/content-focus-probe.mjs.map +1 -0
- package/dist/internal/{css-transition-cut.mjs → overlay/css-transition-cut.mjs} +1 -1
- package/dist/internal/overlay/css-transition-cut.mjs.map +1 -0
- package/dist/internal/{focus-visible.mjs → overlay/focus-visible.mjs} +1 -1
- package/dist/internal/overlay/focus-visible.mjs.map +1 -0
- package/dist/internal/{invokers.mjs → overlay/invokers.mjs} +1 -1
- package/dist/internal/overlay/invokers.mjs.map +1 -0
- package/dist/internal/{modal-registry.mjs → overlay/modal-registry.mjs} +1 -1
- package/dist/internal/overlay/modal-registry.mjs.map +1 -0
- package/dist/internal/{overlay-popup.mjs → overlay/overlay-popup.mjs} +3 -3
- package/dist/internal/overlay/overlay-popup.mjs.map +1 -0
- package/dist/internal/overlay/overlay-show.mjs +73 -0
- package/dist/internal/overlay/overlay-show.mjs.map +1 -0
- package/dist/internal/{popover-open.mjs → overlay/popover-open.mjs} +1 -1
- package/dist/internal/overlay/popover-open.mjs.map +1 -0
- package/dist/internal/{trigger-ref.mjs → overlay/trigger-ref.mjs} +1 -1
- package/dist/internal/overlay/trigger-ref.mjs.map +1 -0
- package/dist/internal/overlay/use-apply-open-state.mjs +44 -0
- package/dist/internal/overlay/use-apply-open-state.mjs.map +1 -0
- package/dist/internal/{use-exit-animation.mjs → overlay/use-exit-animation.mjs} +2 -2
- package/dist/internal/overlay/use-exit-animation.mjs.map +1 -0
- package/dist/internal/{use-interest-dismiss.mjs → overlay/use-interest-dismiss.mjs} +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -0
- package/dist/internal/{use-modal-registration.mjs → overlay/use-modal-registration.mjs} +1 -1
- package/dist/internal/overlay/use-modal-registration.mjs.map +1 -0
- package/dist/internal/{use-overlay-close.mjs → overlay/use-overlay-close.mjs} +14 -13
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -0
- package/dist/internal/overlay/use-overlay-root.d.mts +2 -0
- package/dist/internal/{use-overlay-root.mjs → overlay/use-overlay-root.mjs} +44 -28
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -0
- package/dist/internal/{use-popover-popup.mjs → overlay/use-popover-popup.mjs} +74 -66
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -0
- package/dist/internal/{use-popover-trigger.d.mts → overlay/use-popover-trigger.d.mts} +3 -3
- package/dist/internal/overlay/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/{use-popover-trigger.mjs → overlay/use-popover-trigger.mjs} +47 -26
- package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -0
- package/dist/internal/{use-resolved-placement.mjs → overlay/use-resolved-placement.mjs} +2 -2
- package/dist/internal/overlay/use-resolved-placement.mjs.map +1 -0
- package/dist/internal/render-element.mjs +47 -9
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +4 -8
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/use-mount-fixed.mjs +22 -0
- package/dist/internal/use-mount-fixed.mjs.map +1 -0
- package/dist/internal/use-register-count.mjs +4 -1
- package/dist/internal/use-register-count.mjs.map +1 -1
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/menu/menu-checkbox-item.mjs +2 -2
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +1 -1
- package/dist/menu/menu-gestures.mjs.map +1 -1
- package/dist/menu/menu-item.d.mts.map +1 -1
- package/dist/menu/menu-item.mjs +9 -10
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +1 -1
- package/dist/menu/menu-outside.mjs.map +1 -1
- package/dist/menu/menu-popup.d.mts +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +10 -6
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs +2 -2
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.mjs +2 -2
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +3 -3
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +1 -1
- package/dist/menu/menu-trigger.mjs +3 -3
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/number-field/number-field-input.mjs +1 -1
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +43 -107
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/popover/popover-close.mjs +3 -3
- 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 +1 -1
- package/dist/popover/popover-popup.mjs +3 -3
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +2 -2
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +1 -1
- package/dist/popover/popover-trigger.mjs +1 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +3 -3
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +5 -5
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-group-label.d.mts.map +1 -1
- package/dist/select/select-group-label.mjs +3 -1
- package/dist/select/select-group-label.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-option.mjs.map +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +7 -7
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/select/select-trigger.d.mts.map +1 -1
- package/dist/select/select-trigger.mjs +3 -1
- package/dist/select/select-trigger.mjs.map +1 -1
- package/dist/select/select-value.mjs +3 -6
- package/dist/select/select-value.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +38 -104
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/use-thumb-registry.mjs.map +1 -1
- package/dist/switch/switch.mjs +1 -1
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-panel.mjs +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +4 -4
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/{internal → tabs}/use-until-found.mjs +1 -1
- package/dist/tabs/use-until-found.mjs.map +1 -0
- package/dist/toast/toast-action.d.mts +13 -3
- package/dist/toast/toast-action.d.mts.map +1 -1
- package/dist/toast/toast-action.mjs +23 -13
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts +13 -2
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +16 -6
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-root.mjs +1 -1
- package/dist/toast/toast-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +48 -143
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +1 -1
- package/dist/toast/use-modal-portal-host.mjs.map +1 -1
- package/dist/toast/use-toast-announcements.mjs +46 -0
- package/dist/toast/use-toast-announcements.mjs.map +1 -0
- package/dist/toast/use-toast-focus.mjs +75 -0
- package/dist/toast/use-toast-focus.mjs.map +1 -0
- package/dist/toast/use-toast-pauses.mjs +58 -0
- package/dist/toast/use-toast-pauses.mjs.map +1 -0
- package/dist/toggle/toggle.mjs +2 -2
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +5 -5
- package/dist/toggle-group/toggle-group-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.mjs +1 -1
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.d.mts.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +9 -4
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +1 -1
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/{internal → tooltip}/tooltip-warm.mjs +1 -1
- package/dist/tooltip/tooltip-warm.mjs.map +1 -0
- package/dist/tooltip/use-tooltip-interaction.mjs +2 -2
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/funstack-ui-knowledge/SKILL.md +1 -1
- package/dist/internal/action-details.mjs.map +0 -1
- package/dist/internal/anchor-position.d.mts.map +0 -1
- package/dist/internal/anchor-position.mjs.map +0 -1
- package/dist/internal/call-urgent-handler.mjs.map +0 -1
- package/dist/internal/content-focus-probe.mjs.map +0 -1
- package/dist/internal/css-transition-cut.mjs.map +0 -1
- package/dist/internal/field-context.d.mts.map +0 -1
- package/dist/internal/field-context.mjs.map +0 -1
- package/dist/internal/focus-first-invalid.mjs.map +0 -1
- package/dist/internal/focus-visible.mjs.map +0 -1
- package/dist/internal/form-status-watcher.mjs.map +0 -1
- package/dist/internal/group-member.mjs.map +0 -1
- package/dist/internal/invokers.mjs.map +0 -1
- package/dist/internal/modal-registry.mjs.map +0 -1
- package/dist/internal/overlay-popup.mjs.map +0 -1
- package/dist/internal/popover-open.mjs.map +0 -1
- package/dist/internal/report-dropped.mjs.map +0 -1
- package/dist/internal/sync-presence.mjs.map +0 -1
- package/dist/internal/tooltip-warm.mjs.map +0 -1
- package/dist/internal/trigger-ref.mjs.map +0 -1
- package/dist/internal/use-action-trigger.mjs.map +0 -1
- package/dist/internal/use-checkable-input.mjs.map +0 -1
- package/dist/internal/use-controllable-action.mjs.map +0 -1
- package/dist/internal/use-exit-animation.mjs.map +0 -1
- package/dist/internal/use-field-control.mjs.map +0 -1
- package/dist/internal/use-fieldset-group.mjs.map +0 -1
- package/dist/internal/use-form-owner-event.mjs.map +0 -1
- package/dist/internal/use-form-reset.mjs.map +0 -1
- package/dist/internal/use-interest-dismiss.mjs.map +0 -1
- package/dist/internal/use-modal-registration.mjs.map +0 -1
- package/dist/internal/use-native-checked.mjs.map +0 -1
- package/dist/internal/use-native-group-reconciliation.mjs.map +0 -1
- package/dist/internal/use-native-select-value.mjs.map +0 -1
- package/dist/internal/use-overlay-close.mjs.map +0 -1
- package/dist/internal/use-overlay-root.d.mts +0 -2
- package/dist/internal/use-overlay-root.mjs.map +0 -1
- package/dist/internal/use-popover-popup.mjs.map +0 -1
- package/dist/internal/use-popover-trigger.d.mts.map +0 -1
- package/dist/internal/use-popover-trigger.mjs.map +0 -1
- package/dist/internal/use-resolved-placement.mjs.map +0 -1
- package/dist/internal/use-until-found.mjs.map +0 -1
- package/dist/internal/validity.d.mts.map +0 -1
- package/dist/internal/validity.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-roving-focus.mjs","names":[],"sources":["../../src/internal/use-roving-focus.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useInsertionEffect, useLayoutEffect, useState } from \"react\";\nimport type { FocusEvent, KeyboardEvent, PointerEvent, RefObject } from \"react\";\nimport { focusWithRing, resolveArrowKey } from \"./arrow-keys.js\";\nimport type { Orientation } from \"./types.js\";\n\n// The roving-focus engine shared by `Toolbar.Root` and a standalone `ToggleGroup.Root`\n// (design/components/toggle-group.md section 6, conventions 3.2 and 7.4). Items are the focusable\n// descendants of the container, found in the DOM; which one is the Tab stop is urgent library\n// state kept outside React and written to the items as `tabindex` through the DOM.\n\nexport type RovingOrientation = Orientation;\n\nexport interface RovingFocusOptions {\n /** `false`: the engine writes nothing and handles nothing (a ToggleGroup inside a Toolbar). Default `true`. */\n readonly enabled?: boolean;\n readonly orientation: RovingOrientation;\n readonly loop: boolean;\n /** The native `focusgroup` path is active: write no `tabindex`, handle no navigation key. */\n readonly native: boolean;\n /** Which item is the Tab stop when there is no usable memory. */\n readonly entry: (items: readonly HTMLElement[]) => HTMLElement | undefined;\n /**\n * `true`: the last focused item stays the Tab stop after focus leaves (Toolbar). `false`: while\n * focus is inside, the focused item is the stop (so Tab and Shift+Tab leave the container);\n * once it leaves, the stop is re-derived from `entry` (ToggleGroup: the pressed Item).\n */\n readonly memory: boolean;\n}\n\nexport interface RovingFocusHandlers {\n readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n readonly onFocus: (event: FocusEvent<HTMLElement>) => void;\n readonly onBlur: (event: FocusEvent<HTMLElement>) => void;\n readonly onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n}\n\nconst FOCUSABLE = [\n \"button\",\n \"a[href]\",\n 'input:not([type=\"hidden\"])',\n \"select\",\n \"textarea\",\n \"summary\",\n '[contenteditable]:not([contenteditable=\"false\"])',\n \"[tabindex]\",\n].join(\",\");\n\nfunction isVisible(el: HTMLElement): boolean {\n // jsdom has no `checkVisibility`; `hidden` is the part of it a test can observe there.\n if (typeof el.checkVisibility === \"function\") return el.checkVisibility();\n return el.closest(\"[hidden]\") === null;\n}\n\n/**\n * Whether `el` or an ancestor below `root` takes it out of `root`'s sequence: a nested toolbar\n * (its own sequence), a popover or a dialog rendered inside the container (a `Menu.Popup`'s items\n * are the menu's).\n */\nfunction isNestedOut(el: HTMLElement, root: HTMLElement): boolean {\n for (let node: Element | null = el; node !== null && node !== root; node = node.parentElement) {\n if (\n node.getAttribute(\"role\") === \"toolbar\" ||\n node.hasAttribute(\"popover\") ||\n node.tagName === \"DIALOG\"\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isRadio(el: Element): el is HTMLInputElement {\n return el instanceof HTMLInputElement && el.type === \"radio\";\n}\n\n/** The items of a container, with native radio groups collapsed into units (design 17.2). */\nexport interface RovingItems {\n /** The toolbar's own destinations in DOM order; a radio unit appears as its representative. */\n readonly items: HTMLElement[];\n /**\n * Every native radio among the candidates → the radios of its unit (same `name` under the\n * container, DOM order). A radio without a `name` is a unit of one.\n */\n readonly units: Map<HTMLElement, readonly HTMLInputElement[]>;\n}\n\n/** The unit's representative: its checked radio, else its first (design 17.2 item 2). */\nfunction representative(unit: readonly HTMLInputElement[]): HTMLInputElement {\n return unit.find((radio) => radio.checked) ?? unit[0]!;\n}\n\n/**\n * The items of `root` (design 6.2 and 17.2): its focusable descendants minus `:disabled`,\n * `inert`, invisible, nested-toolbar / popover / dialog content, and elements whose own\n * `tabindex=\"-1\"` was not written by this engine (`managed`). `aria-disabled` elements are items.\n * Native radios that share a `name` form one unit, represented in `items` by its checked radio\n * (else its first), at the position of the unit's first radio.\n */\nexport function collectItems(\n root: HTMLElement,\n managed: { has(el: Element): boolean },\n): RovingItems {\n const candidates: HTMLElement[] = [];\n const byName = new Map<string, HTMLInputElement[]>();\n const units = new Map<HTMLElement, readonly HTMLInputElement[]>();\n for (const el of root.querySelectorAll<HTMLElement>(FOCUSABLE)) {\n if (el.matches(\":disabled\")) continue;\n if (el.closest(\"[inert]\") !== null) continue;\n if (el.getAttribute(\"tabindex\") === \"-1\" && !managed.has(el)) continue;\n if (isNestedOut(el, root)) continue;\n if (!isVisible(el)) continue;\n if (isRadio(el)) {\n // Same form owner assumed: a `form=` attribute that splits a `name` is not handled (v1).\n const unit = el.name === \"\" ? undefined : byName.get(el.name);\n if (unit !== undefined) {\n unit.push(el);\n units.set(el, unit);\n continue;\n }\n const created = [el];\n if (el.name !== \"\") byName.set(el.name, created);\n units.set(el, created);\n }\n candidates.push(el);\n }\n // `candidates` holds each unit's first radio in its place; swap in the representative.\n const items = candidates.map((el) => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n });\n return { items, units };\n}\n\n/** {@link collectItems}'s `items`: the container's destinations in DOM order. */\nexport function itemsOf(root: HTMLElement, managed: { has(el: Element): boolean }): HTMLElement[] {\n return collectItems(root, managed).items;\n}\n\nconst BUTTON_LIKE_INPUTS = new Set([\n \"button\",\n \"submit\",\n \"reset\",\n \"checkbox\",\n \"image\",\n \"color\",\n \"file\",\n]);\nconst ARROW_OWNING_ROLES = new Set([\"textbox\", \"combobox\", \"spinbutton\", \"slider\"]);\n\n/**\n * An item that owns the arrow keys (design 6.3 and 17.2): text-like `input`s, `textarea`,\n * `select`, `[contenteditable]`, `role` `textbox` / `combobox` / `spinbutton` / `slider`, and a\n * native `input[type=radio]` (its group's own arrows check as they move). A custom\n * `[role=\"radio\"]` is an ordinary item, as it is under native `focusgroup`.\n */\nexport function ownsArrows(el: Element): boolean {\n const role = el.getAttribute(\"role\");\n if (role !== null && ARROW_OWNING_ROLES.has(role)) return true;\n if (el instanceof HTMLInputElement) return !BUTTON_LIKE_INPUTS.has(el.type);\n if (el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) return true;\n const editable = el.getAttribute(\"contenteditable\");\n if (editable !== null && editable !== \"false\") return true;\n return el instanceof HTMLElement && el.isContentEditable === true;\n}\n\ninterface Engine {\n /** The options of the last committed render (written from an insertion effect). */\n readonly setOptions: (options: RovingFocusOptions) => void;\n /**\n * Re-derives the Tab stop of `root` and writes `tabindex`. `focused`: the element focus is on,\n * if any.\n */\n readonly apply: (root: HTMLElement | null, focused: Element | null) => void;\n readonly handlers: RovingFocusHandlers;\n}\n\nfunction createEngine(): Engine {\n let current: HTMLElement | null = null;\n let latestOptions: RovingFocusOptions | null = null;\n /**\n * Elements this engine wrote `tabindex` on, with the attribute value they had before the first\n * write (`null`: none). Restored when the engine lets go of an element (native path, element\n * left the container): React does not re-write a `tabIndex` prop it believes it rendered, so a\n * `[tabindex=\"0\"]` widget would otherwise become unreachable.\n */\n const managed = new Map<HTMLElement, string | null>();\n\n const restore = (el: HTMLElement) => {\n const original = managed.get(el);\n managed.delete(el);\n if (!el.isConnected || original === undefined) return;\n if (original === null) el.removeAttribute(\"tabindex\");\n else el.setAttribute(\"tabindex\", original);\n };\n\n const active = (options: RovingFocusOptions | null): options is RovingFocusOptions =>\n options !== null && options.enabled !== false;\n\n /** Native path: give back every `tabindex` this engine wrote (a hydration render may have). */\n const release = () => {\n for (const el of [...managed.keys()]) restore(el);\n current = null;\n };\n\n const apply = (root: HTMLElement | null, focused: Element | null) => {\n const options = latestOptions;\n if (root === null || !active(options)) return;\n if (options.native) {\n release();\n return;\n }\n const { items, units } = collectItems(root, managed);\n /** Every element the engine writes: the items and the other radios of their units. */\n const all = new Set<HTMLElement>(items);\n for (const radio of units.keys()) all.add(radio);\n /** The item standing for `el`: its unit's representative for a radio, else itself. */\n const itemOf = (el: HTMLElement): HTMLElement => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n };\n if (!options.memory) {\n current =\n focused instanceof HTMLElement && all.has(focused)\n ? focused\n : (options.entry(items) ?? null);\n } else if (current === null || !all.has(current) || !items.includes(itemOf(current))) {\n current = options.entry(items) ?? null;\n }\n // `current` may be any radio of its unit (focus landed on an unchecked one): `0` on it, `-1`\n // on the unit's other radios and on every other element (design 17.2 item 5).\n for (const el of all) {\n if (!managed.has(el)) managed.set(el, el.getAttribute(\"tabindex\"));\n const want = el === current ? \"0\" : \"-1\";\n if (el.getAttribute(\"tabindex\") !== want) el.setAttribute(\"tabindex\", want);\n }\n // Elements written before that are no longer items: a stale `0` must not stay a Tab stop\n // (it would be one again when re-enabled); one that left the container gets its own back.\n for (const el of [...managed.keys()]) {\n if (all.has(el)) continue;\n if (!root.contains(el)) {\n restore(el);\n } else if (el.getAttribute(\"tabindex\") !== \"-1\") {\n el.setAttribute(\"tabindex\", \"-1\");\n }\n }\n };\n\n const onFocus = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n if (!items.includes(target) && !units.has(target)) return;\n current = target;\n apply(event.currentTarget, target);\n };\n\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native || options.memory) return;\n // Focus moving to another item is handled by its focus event.\n const next = event.relatedTarget;\n if (next instanceof Node && event.currentTarget.contains(next)) return;\n apply(event.currentTarget, null);\n };\n\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof Node)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n // Safari does not focus a button on click; the pointer still makes it the stop.\n const item = [...items, ...units.keys()].find((el) => el.contains(target));\n if (item === undefined) return;\n current = item;\n apply(\n event.currentTarget,\n options.memory ? item : event.currentTarget.ownerDocument.activeElement,\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const options = latestOptions;\n // The browser moves focus itself where `focusgroup` is implemented.\n if (!active(options) || options.native) return;\n const root = event.currentTarget;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(root, managed);\n const unit = units.get(target);\n // A radio stands in `items` through its unit's representative.\n const index = items.indexOf(unit === undefined ? target : representative(unit));\n if (index < 0) return;\n\n if (ownsArrows(target)) {\n // The item keeps its arrows, Home and End; Tab / Shift+Tab move to the next / previous item\n // while one exists, as Chromium's `focusgroup=\"toolbar\"` does (design 6.3, 17.2 item 4).\n if (event.key !== \"Tab\") return;\n // From an unchecked radio whose sibling is checked: that sibling first (only the checked\n // radio of a group is sequentially focusable natively).\n const checked = unit?.find((radio) => radio.checked);\n if (checked !== undefined && checked !== target) {\n event.preventDefault();\n focusWithRing(checked);\n return;\n }\n const next = items[index + (event.shiftKey ? -1 : 1)];\n if (next === undefined) return;\n event.preventDefault();\n focusWithRing(next);\n return;\n }\n\n const rtl = options.orientation === \"horizontal\" && getComputedStyle(root).direction === \"rtl\";\n const move = resolveArrowKey(event.key, options.orientation, rtl);\n if (move === null) return;\n event.preventDefault();\n const last = items.length - 1;\n let nextIndex: number;\n switch (move) {\n case \"first\":\n nextIndex = 0;\n break;\n case \"last\":\n nextIndex = last;\n break;\n case \"next\":\n nextIndex = index >= last ? (options.loop ? 0 : last) : index + 1;\n break;\n case \"prev\":\n nextIndex = index <= 0 ? (options.loop ? last : 0) : index - 1;\n break;\n }\n const next = items[nextIndex];\n if (next !== undefined && next !== target) focusWithRing(next);\n };\n\n return {\n setOptions: (options) => {\n latestOptions = options;\n },\n apply,\n handlers: { onFocus, onBlur, onPointerDown, onKeyDown },\n };\n}\n\n/**\n * Roving focus over the focusable descendants of `ref`'s element (design 6.2). Writes `tabindex`\n * (`0` on the Tab stop, `-1` on the other items) from a layout effect after every commit of the\n * calling component, from a `MutationObserver` on the subtree and from focus / pointer events;\n * the items render none. Returns the container's handlers for its library props.\n */\nexport function useRovingFocus(\n ref: RefObject<HTMLElement | null>,\n options: RovingFocusOptions,\n): RovingFocusHandlers {\n const [engine] = useState(createEngine);\n // Before every layout effect of the same commit (as `useLatest`): handlers and the observer\n // read the options of the last committed render.\n useInsertionEffect(() => {\n engine.setOptions(options);\n });\n const enabled = options.enabled !== false;\n\n // After every commit of the container (a deps-less layout effect).\n useLayoutEffect(() => {\n const root = ref.current;\n engine.apply(root, root?.ownerDocument.activeElement ?? null);\n });\n\n // Children that change without the container re-rendering.\n useEffect(() => {\n const root = ref.current;\n if (!enabled || root === null) return;\n const observer = new MutationObserver(() => {\n engine.apply(root, root.ownerDocument.activeElement);\n });\n observer.observe(root, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"disabled\", \"hidden\", \"inert\", \"aria-disabled\"],\n });\n return () => {\n observer.disconnect();\n };\n }, [engine, enabled, ref]);\n\n return engine.handlers;\n}\n"],"mappings":";;;;AAqCA,MAAM,YAAY;CAChB;CACA;CAC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AAO,MAAM,MAAM,MAAM,cAAc,iBAAiB,IAAI;CAC9D,CAAC;CAGD,gBAAgB;EACd,MAAM,OAAO,IAAI;EACjB,IAAI,CAAC,WAAW,SAAS,MAAM;EAC/B,MAAM,WAAW,IAAI,uBAAuB;GAC1C,OAAO,MAAM,MAAM,KAAK,cAAc,aAAa;EACrD,CAAC;EACD,SAAS,QAAQ,MAAM;GACrB,WAAW;GACX,SAAS;GACT,YAAY;GACZ,iBAAiB;IAAC;IAAY;IAAU;IAAS;GAAe;EAClE,CAAC;EACD,aAAa;GACX,SAAS,WAAW;EACtB;CACF,GAAG;EAAC;EAAQ;EAAS;CAAG,CAAC;CAEzB,OAAO,OAAO;AAChB"}
|
|
1
|
+
{"version":3,"file":"use-roving-focus.mjs","names":[],"sources":["../../src/internal/use-roving-focus.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useInsertionEffect, useLayoutEffect, useState } from \"react\";\nimport type { FocusEvent, KeyboardEvent, PointerEvent, RefObject } from \"react\";\nimport { focusWithRing, resolveArrowKey } from \"./arrow-keys.js\";\nimport type { Orientation } from \"./types.js\";\n\n// The roving-focus engine shared by `Toolbar.Root` and a standalone `ToggleGroup.Root`\n// (design/components/toggle-group.md section 6, conventions 3.2 and 7.4). Items are the focusable\n// descendants of the container, found in the DOM; which one is the Tab stop is urgent library\n// state kept outside React and written to the items as `tabindex` through the DOM.\n\nexport type RovingOrientation = Orientation;\n\nexport interface RovingFocusOptions {\n /** `false`: the engine writes nothing and handles nothing (a ToggleGroup inside a Toolbar). Default `true`. */\n readonly enabled?: boolean;\n readonly orientation: RovingOrientation;\n readonly loop: boolean;\n /** The native `focusgroup` path is active: write no `tabindex`, handle no navigation key. */\n readonly native: boolean;\n /** Which item is the Tab stop when there is no usable memory. */\n readonly entry: (items: readonly HTMLElement[]) => HTMLElement | undefined;\n /**\n * `true`: the last focused item stays the Tab stop after focus leaves (Toolbar). `false`: while\n * focus is inside, the focused item is the stop (so Tab and Shift+Tab leave the container);\n * once it leaves, the stop is re-derived from `entry` (ToggleGroup: the pressed Item).\n */\n readonly memory: boolean;\n}\n\nexport interface RovingFocusHandlers {\n readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n readonly onFocus: (event: FocusEvent<HTMLElement>) => void;\n readonly onBlur: (event: FocusEvent<HTMLElement>) => void;\n readonly onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n}\n\n// What may hold the roving tab stop; narrower than Menu's and Tooltip's selectors on purpose.\nconst FOCUSABLE = [\n \"button\",\n \"a[href]\",\n 'input:not([type=\"hidden\"])',\n \"select\",\n \"textarea\",\n \"summary\",\n '[contenteditable]:not([contenteditable=\"false\"])',\n \"[tabindex]\",\n].join(\",\");\n\nfunction isVisible(el: HTMLElement): boolean {\n // jsdom has no `checkVisibility`; `hidden` is the part of it a test can observe there.\n if (typeof el.checkVisibility === \"function\") return el.checkVisibility();\n return el.closest(\"[hidden]\") === null;\n}\n\n/**\n * Whether `el` or an ancestor below `root` takes it out of `root`'s sequence: a nested toolbar\n * (its own sequence), a popover or a dialog rendered inside the container (a `Menu.Popup`'s items\n * are the menu's).\n */\nfunction isNestedOut(el: HTMLElement, root: HTMLElement): boolean {\n for (let node: Element | null = el; node !== null && node !== root; node = node.parentElement) {\n if (\n node.getAttribute(\"role\") === \"toolbar\" ||\n node.hasAttribute(\"popover\") ||\n node.tagName === \"DIALOG\"\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isRadio(el: Element): el is HTMLInputElement {\n return el instanceof HTMLInputElement && el.type === \"radio\";\n}\n\n/** The items of a container, with native radio groups collapsed into units (design 17.2). */\nexport interface RovingItems {\n /** The toolbar's own destinations in DOM order; a radio unit appears as its representative. */\n readonly items: HTMLElement[];\n /**\n * Every native radio among the candidates → the radios of its unit (same `name` under the\n * container, DOM order). A radio without a `name` is a unit of one.\n */\n readonly units: Map<HTMLElement, readonly HTMLInputElement[]>;\n}\n\n/** The unit's representative: its checked radio, else its first (design 17.2 item 2). */\nfunction representative(unit: readonly HTMLInputElement[]): HTMLInputElement {\n return unit.find((radio) => radio.checked) ?? unit[0]!;\n}\n\n/**\n * The items of `root` (design 6.2 and 17.2): its focusable descendants minus `:disabled`,\n * `inert`, invisible, nested-toolbar / popover / dialog content, and elements whose own\n * `tabindex=\"-1\"` was not written by this engine (`managed`). `aria-disabled` elements are items.\n * Native radios that share a `name` form one unit, represented in `items` by its checked radio\n * (else its first), at the position of the unit's first radio.\n */\nexport function collectItems(\n root: HTMLElement,\n managed: { has(el: Element): boolean },\n): RovingItems {\n const candidates: HTMLElement[] = [];\n const byName = new Map<string, HTMLInputElement[]>();\n const units = new Map<HTMLElement, readonly HTMLInputElement[]>();\n for (const el of root.querySelectorAll<HTMLElement>(FOCUSABLE)) {\n if (el.matches(\":disabled\")) continue;\n if (el.closest(\"[inert]\") !== null) continue;\n if (el.getAttribute(\"tabindex\") === \"-1\" && !managed.has(el)) continue;\n if (isNestedOut(el, root)) continue;\n if (!isVisible(el)) continue;\n if (isRadio(el)) {\n // Same form owner assumed: a `form=` attribute that splits a `name` is not handled (v1).\n const unit = el.name === \"\" ? undefined : byName.get(el.name);\n if (unit !== undefined) {\n unit.push(el);\n units.set(el, unit);\n continue;\n }\n const created = [el];\n if (el.name !== \"\") byName.set(el.name, created);\n units.set(el, created);\n }\n candidates.push(el);\n }\n // `candidates` holds each unit's first radio in its place; swap in the representative.\n const items = candidates.map((el) => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n });\n return { items, units };\n}\n\n/** {@link collectItems}'s `items`: the container's destinations in DOM order. */\nexport function itemsOf(root: HTMLElement, managed: { has(el: Element): boolean }): HTMLElement[] {\n return collectItems(root, managed).items;\n}\n\nconst BUTTON_LIKE_INPUTS = new Set([\n \"button\",\n \"submit\",\n \"reset\",\n \"checkbox\",\n \"image\",\n \"color\",\n \"file\",\n]);\nconst ARROW_OWNING_ROLES = new Set([\"textbox\", \"combobox\", \"spinbutton\", \"slider\"]);\n\n/**\n * An item that owns the arrow keys (design 6.3 and 17.2): text-like `input`s, `textarea`,\n * `select`, `[contenteditable]`, `role` `textbox` / `combobox` / `spinbutton` / `slider`, and a\n * native `input[type=radio]` (its group's own arrows check as they move). A custom\n * `[role=\"radio\"]` is an ordinary item, as it is under native `focusgroup`.\n */\nexport function ownsArrows(el: Element): boolean {\n const role = el.getAttribute(\"role\");\n if (role !== null && ARROW_OWNING_ROLES.has(role)) return true;\n if (el instanceof HTMLInputElement) return !BUTTON_LIKE_INPUTS.has(el.type);\n if (el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) return true;\n const editable = el.getAttribute(\"contenteditable\");\n if (editable !== null && editable !== \"false\") return true;\n return el instanceof HTMLElement && el.isContentEditable === true;\n}\n\ninterface Engine {\n /** The options of the last committed render (written from an insertion effect). */\n readonly setOptions: (options: RovingFocusOptions) => void;\n /**\n * Re-derives the Tab stop of `root` and writes `tabindex`. `focused`: the element focus is on,\n * if any.\n */\n readonly apply: (root: HTMLElement | null, focused: Element | null) => void;\n readonly handlers: RovingFocusHandlers;\n}\n\nfunction createEngine(): Engine {\n let current: HTMLElement | null = null;\n let latestOptions: RovingFocusOptions | null = null;\n /**\n * Elements this engine wrote `tabindex` on, with the attribute value they had before the first\n * write (`null`: none). Restored when the engine lets go of an element (native path, element\n * left the container): React does not re-write a `tabIndex` prop it believes it rendered, so a\n * `[tabindex=\"0\"]` widget would otherwise become unreachable.\n */\n const managed = new Map<HTMLElement, string | null>();\n\n const restore = (el: HTMLElement) => {\n const original = managed.get(el);\n managed.delete(el);\n if (!el.isConnected || original === undefined) return;\n if (original === null) el.removeAttribute(\"tabindex\");\n else el.setAttribute(\"tabindex\", original);\n };\n\n const active = (options: RovingFocusOptions | null): options is RovingFocusOptions =>\n options !== null && options.enabled !== false;\n\n /** Native path: give back every `tabindex` this engine wrote (a hydration render may have). */\n const release = () => {\n for (const el of [...managed.keys()]) restore(el);\n current = null;\n };\n\n const apply = (root: HTMLElement | null, focused: Element | null) => {\n const options = latestOptions;\n if (root === null || !active(options)) return;\n if (options.native) {\n release();\n return;\n }\n const { items, units } = collectItems(root, managed);\n /** Every element the engine writes: the items and the other radios of their units. */\n const all = new Set<HTMLElement>(items);\n for (const radio of units.keys()) all.add(radio);\n /** The item standing for `el`: its unit's representative for a radio, else itself. */\n const itemOf = (el: HTMLElement): HTMLElement => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n };\n if (!options.memory) {\n current =\n focused instanceof HTMLElement && all.has(focused)\n ? focused\n : (options.entry(items) ?? null);\n } else if (current === null || !all.has(current) || !items.includes(itemOf(current))) {\n current = options.entry(items) ?? null;\n }\n // `current` may be any radio of its unit (focus landed on an unchecked one): `0` on it, `-1`\n // on the unit's other radios and on every other element (design 17.2 item 5).\n for (const el of all) {\n if (!managed.has(el)) managed.set(el, el.getAttribute(\"tabindex\"));\n const want = el === current ? \"0\" : \"-1\";\n if (el.getAttribute(\"tabindex\") !== want) el.setAttribute(\"tabindex\", want);\n }\n // Elements written before that are no longer items: a stale `0` must not stay a Tab stop\n // (it would be one again when re-enabled); one that left the container gets its own back.\n for (const el of [...managed.keys()]) {\n if (all.has(el)) continue;\n if (!root.contains(el)) {\n restore(el);\n } else if (el.getAttribute(\"tabindex\") !== \"-1\") {\n el.setAttribute(\"tabindex\", \"-1\");\n }\n }\n };\n\n const onFocus = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n if (!items.includes(target) && !units.has(target)) return;\n current = target;\n apply(event.currentTarget, target);\n };\n\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native || options.memory) return;\n // Focus moving to another item is handled by its focus event.\n const next = event.relatedTarget;\n if (next instanceof Node && event.currentTarget.contains(next)) return;\n apply(event.currentTarget, null);\n };\n\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof Node)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n // Safari does not focus a button on click; the pointer still makes it the stop.\n const item = [...items, ...units.keys()].find((el) => el.contains(target));\n if (item === undefined) return;\n current = item;\n apply(\n event.currentTarget,\n options.memory ? item : event.currentTarget.ownerDocument.activeElement,\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const options = latestOptions;\n // The browser moves focus itself where `focusgroup` is implemented.\n if (!active(options) || options.native) return;\n const root = event.currentTarget;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(root, managed);\n const unit = units.get(target);\n // A radio stands in `items` through its unit's representative.\n const index = items.indexOf(unit === undefined ? target : representative(unit));\n if (index < 0) return;\n\n if (ownsArrows(target)) {\n // The item keeps its arrows, Home and End; Tab / Shift+Tab move to the next / previous item\n // while one exists, as Chromium's `focusgroup=\"toolbar\"` does (design 6.3, 17.2 item 4).\n if (event.key !== \"Tab\") return;\n // From an unchecked radio whose sibling is checked: that sibling first (only the checked\n // radio of a group is sequentially focusable natively).\n const checked = unit?.find((radio) => radio.checked);\n if (checked !== undefined && checked !== target) {\n event.preventDefault();\n focusWithRing(checked);\n return;\n }\n const next = items[index + (event.shiftKey ? -1 : 1)];\n if (next === undefined) return;\n event.preventDefault();\n focusWithRing(next);\n return;\n }\n\n const rtl = options.orientation === \"horizontal\" && getComputedStyle(root).direction === \"rtl\";\n const move = resolveArrowKey(event.key, options.orientation, rtl);\n if (move === null) return;\n event.preventDefault();\n const last = items.length - 1;\n let nextIndex: number;\n switch (move) {\n case \"first\":\n nextIndex = 0;\n break;\n case \"last\":\n nextIndex = last;\n break;\n case \"next\":\n nextIndex = index >= last ? (options.loop ? 0 : last) : index + 1;\n break;\n case \"prev\":\n nextIndex = index <= 0 ? (options.loop ? last : 0) : index - 1;\n break;\n }\n const next = items[nextIndex];\n if (next !== undefined && next !== target) focusWithRing(next);\n };\n\n return {\n setOptions: (options) => {\n latestOptions = options;\n },\n apply,\n handlers: { onFocus, onBlur, onPointerDown, onKeyDown },\n };\n}\n\n/**\n * Roving focus over the focusable descendants of `ref`'s element (design 6.2). Writes `tabindex`\n * (`0` on the Tab stop, `-1` on the other items) from a layout effect after every commit of the\n * calling component, from a `MutationObserver` on the subtree and from focus / pointer events;\n * the items render none. Returns the container's handlers for its library props.\n */\nexport function useRovingFocus(\n ref: RefObject<HTMLElement | null>,\n options: RovingFocusOptions,\n): RovingFocusHandlers {\n const [engine] = useState(createEngine);\n // Before every layout effect of the same commit (as `useLatest`): handlers and the observer\n // read the options of the last committed render.\n useInsertionEffect(() => {\n engine.setOptions(options);\n });\n const enabled = options.enabled !== false;\n\n // After every commit of the container (a deps-less layout effect).\n useLayoutEffect(() => {\n const root = ref.current;\n engine.apply(root, root?.ownerDocument.activeElement ?? null);\n });\n\n // Children that change without the container re-rendering.\n useEffect(() => {\n const root = ref.current;\n if (!enabled || root === null) return;\n const observer = new MutationObserver(() => {\n engine.apply(root, root.ownerDocument.activeElement);\n });\n observer.observe(root, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"disabled\", \"hidden\", \"inert\", \"aria-disabled\"],\n });\n return () => {\n observer.disconnect();\n };\n }, [engine, enabled, ref]);\n\n return engine.handlers;\n}\n"],"mappings":";;;;AAsCA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,SAAS,UAAU,IAA0B;CAE3C,IAAI,OAAO,GAAG,oBAAoB,YAAY,OAAO,GAAG,gBAAgB;CACxE,OAAO,GAAG,QAAQ,UAAU,MAAM;AACpC;;;;;;AAOA,SAAS,YAAY,IAAiB,MAA4B;CAChE,KAAK,IAAI,OAAuB,IAAI,SAAS,QAAQ,SAAS,MAAM,OAAO,KAAK,eAC9E,IACE,KAAK,aAAa,MAAM,MAAM,aAC9B,K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D,aAAa;GACX,SAAS,WAAW;EACtB;CACF,GAAG;EAAC;EAAQ;EAAS;CAAG,CAAC;CAEzB,OAAO,OAAO;AAChB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createActionDetails } from "../internal/action-details.mjs";
|
|
2
|
+
import { createActionDetails } from "../internal/action/action-details.mjs";
|
|
3
3
|
import { dataAttr } from "../internal/data-attr.mjs";
|
|
4
4
|
import { rendersButton } from "../internal/render-element.mjs";
|
|
5
5
|
import { useRender } from "../internal/use-render.mjs";
|
|
6
6
|
import { transitionTypes } from "../internal/transition-types.mjs";
|
|
7
|
-
import { useControllableAction } from "../internal/use-controllable-action.mjs";
|
|
7
|
+
import { useControllableAction } from "../internal/action/use-controllable-action.mjs";
|
|
8
8
|
import { closeStackLater, useMenuContext } from "./menu-context.mjs";
|
|
9
9
|
import { useMenuItem } from "./use-menu-item.mjs";
|
|
10
10
|
import { useRef } from "react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-checkbox-item.mjs","names":[],"sources":["../../src/menu/menu-checkbox-item.tsx"],"sourcesContent":["\"use client\";\nimport { useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { closeStackLater, useMenuContext } from \"./menu-context.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\n/**\n * State of `Menu.CheckboxItem`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface MenuCheckboxItemState {\n /** Optimistic checked state (`aria-checked`). */\n readonly checked: boolean;\n /** `checkedChangeAction` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Menu.CheckboxItem`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuCheckboxItemProps extends Omit<\n MenuItemProps,\n \"action\" | \"closeOnActivate\" | \"whilePending\" | \"className\" | \"style\" | \"children\" | \"render\"\n> {\n /** Controlled checked state. `undefined` means uncontrolled. */\n checked?: boolean;\n /**\n * Initial checked state when uncontrolled.\n *\n * @defaultValue `false`\n */\n defaultChecked?: boolean;\n /**\n * Awaited inside the item's transition; `aria-checked` flips at once and rolls back on\n * rejection (which reaches the nearest Error Boundary above the item). May be a Server\n * Function.\n */\n checkedChangeAction?: ChangeAction<boolean>;\n /**\n * Close the whole menu once the change settles. When `false` the menu stays open.\n *\n * @defaultValue `false`\n */\n closeOnActivate?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuCheckboxItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuCheckboxItemState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuCheckboxItemState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>;\n}\n\n/**\n * A checkable menu item: `<button type=\"button\" role=\"menuitemcheckbox\" aria-checked>`. Click,\n * Enter or Space toggles it through its own transition with optimistic `aria-checked` /\n * `data-checked` and `data-pending`; the menu stays open unless `closeOnActivate`.\n *\n * Owned keys (conventions 1.2): those of `Menu.Item`, plus `aria-checked` and `data-checked`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuCheckboxItem({\n checked,\n defaultChecked,\n checkedChangeAction,\n closeOnActivate = false,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuCheckboxItemProps) {\n const menu = useMenuContext(\"Menu.CheckboxItem\");\n // The close to run after a dispatch's action resolved, keyed by the dispatch's details.\n const after = useRef(new WeakMap<object, () => void>());\n const { optimistic, pending, dispatch } = useControllableAction<boolean>({\n controlled: checked,\n defaultValue: defaultChecked,\n initialValue: false,\n action: async (next, details) => {\n await checkedChangeAction?.(next, details);\n after.current.get(details)?.();\n },\n transitionTypes: (next) => transitionTypes(\"menu\", next ? \"check\" : \"uncheck\"),\n warn: { component: \"Menu.CheckboxItem\", prop: \"checked\" },\n });\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.CheckboxItem\",\n role: \"menuitemcheckbox\",\n disabled,\n label,\n activate: (event) => {\n const details = createActionDetails(event, {});\n if (closeOnActivate) after.current.set(details, closeStackLater(menu, event));\n dispatch(!optimistic, details);\n },\n });\n\n const state: MenuCheckboxItemState = { checked: optimistic, pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>({\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 \"aria-checked\": optimistic,\n \"data-checked\": dataAttr(optimistic),\n \"data-pending\": dataAttr(pending),\n },\n });\n}\n\nMenuCheckboxItem.displayName = \"MenuCheckboxItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,iBAAiB,EAC/B,SACA,gBACA,qBACA,kBAAkB,OAClB,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,OAAO,eAAe,mBAAmB;CAE/C,MAAM,QAAQ,uBAAO,IAAI,QAA4B,CAAC;CACtD,MAAM,EAAE,YAAY,SAAS,aAAa,sBAA+B;EACvE,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ,OAAO,MAAM,YAAY;GAC/B,MAAM,sBAAsB,MAAM,OAAO;GACzC,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG;EAC/B;EACA,kBAAkB,SAAS,gBAAgB,QAAQ,OAAO,UAAU,SAAS;EAC7E,MAAM;GAAE,WAAW;GAAqB,MAAM;EAAU;CAC1D,CAAC;CAED,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAAU,oBAAoB,OAAO,CAAC,CAAC;GAC7C,IAAI,iBAAiB,MAAM,QAAQ,IAAI,SAAS,gBAAgB,MAAM,KAAK,CAAC;GAC5E,SAAS,CAAC,YAAY,OAAO;EAC/B;CACF,CAAC;CAID,OAAO,UAAkE;EACvE,gBAAgB;EAChB;EACA,OAAA;GALqC,SAAS;GAAY;GAAS;EAK/D;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GACH,gBAAgB;GAChB,gBAAgB,SAAS,UAAU;GACnC,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;AACH;AAEA,iBAAiB,cAAc"}
|
|
1
|
+
{"version":3,"file":"menu-checkbox-item.mjs","names":[],"sources":["../../src/menu/menu-checkbox-item.tsx"],"sourcesContent":["\"use client\";\nimport { useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/action/use-controllable-action.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { closeStackLater, useMenuContext } from \"./menu-context.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\n/**\n * State of `Menu.CheckboxItem`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface MenuCheckboxItemState {\n /** Optimistic checked state (`aria-checked`). */\n readonly checked: boolean;\n /** `checkedChangeAction` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Menu.CheckboxItem`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuCheckboxItemProps extends Omit<\n MenuItemProps,\n \"action\" | \"closeOnActivate\" | \"whilePending\" | \"className\" | \"style\" | \"children\" | \"render\"\n> {\n /** Controlled checked state. `undefined` means uncontrolled. */\n checked?: boolean;\n /**\n * Initial checked state when uncontrolled.\n *\n * @defaultValue `false`\n */\n defaultChecked?: boolean;\n /**\n * Awaited inside the item's transition; `aria-checked` flips at once and rolls back on\n * rejection (which reaches the nearest Error Boundary above the item). May be a Server\n * Function.\n */\n checkedChangeAction?: ChangeAction<boolean>;\n /**\n * Close the whole menu once the change settles. When `false` the menu stays open.\n *\n * @defaultValue `false`\n */\n closeOnActivate?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuCheckboxItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuCheckboxItemState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuCheckboxItemState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>;\n}\n\n/**\n * A checkable menu item: `<button type=\"button\" role=\"menuitemcheckbox\" aria-checked>`. Click,\n * Enter or Space toggles it through its own transition with optimistic `aria-checked` /\n * `data-checked` and `data-pending`; the menu stays open unless `closeOnActivate`.\n *\n * Owned keys (conventions 1.2): those of `Menu.Item`, plus `aria-checked` and `data-checked`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuCheckboxItem({\n checked,\n defaultChecked,\n checkedChangeAction,\n closeOnActivate = false,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuCheckboxItemProps) {\n const menu = useMenuContext(\"Menu.CheckboxItem\");\n // The close to run after a dispatch's action resolved, keyed by the dispatch's details.\n const after = useRef(new WeakMap<object, () => void>());\n const { optimistic, pending, dispatch } = useControllableAction<boolean>({\n controlled: checked,\n defaultValue: defaultChecked,\n initialValue: false,\n action: async (next, details) => {\n await checkedChangeAction?.(next, details);\n after.current.get(details)?.();\n },\n transitionTypes: (next) => transitionTypes(\"menu\", next ? \"check\" : \"uncheck\"),\n warn: { component: \"Menu.CheckboxItem\", prop: \"checked\" },\n });\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.CheckboxItem\",\n role: \"menuitemcheckbox\",\n disabled,\n label,\n activate: (event) => {\n const details = createActionDetails(event, {});\n if (closeOnActivate) after.current.set(details, closeStackLater(menu, event));\n dispatch(!optimistic, details);\n },\n });\n\n const state: MenuCheckboxItemState = { checked: optimistic, pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>({\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 \"aria-checked\": optimistic,\n \"data-checked\": dataAttr(optimistic),\n \"data-pending\": dataAttr(pending),\n },\n });\n}\n\nMenuCheckboxItem.displayName = \"MenuCheckboxItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,iBAAiB,EAC/B,SACA,gBACA,qBACA,kBAAkB,OAClB,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,OAAO,eAAe,mBAAmB;CAE/C,MAAM,QAAQ,uBAAO,IAAI,QAA4B,CAAC;CACtD,MAAM,EAAE,YAAY,SAAS,aAAa,sBAA+B;EACvE,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ,OAAO,MAAM,YAAY;GAC/B,MAAM,sBAAsB,MAAM,OAAO;GACzC,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG;EAC/B;EACA,kBAAkB,SAAS,gBAAgB,QAAQ,OAAO,UAAU,SAAS;EAC7E,MAAM;GAAE,WAAW;GAAqB,MAAM;EAAU;CAC1D,CAAC;CAED,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAAU,oBAAoB,OAAO,CAAC,CAAC;GAC7C,IAAI,iBAAiB,MAAM,QAAQ,IAAI,SAAS,gBAAgB,MAAM,KAAK,CAAC;GAC5E,SAAS,CAAC,YAAY,OAAO;EAC/B;CACF,CAAC;CAID,OAAO,UAAkE;EACvE,gBAAgB;EAChB;EACA,OAAA;GALqC,SAAS;GAAY;GAAS;EAK/D;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GACH,gBAAgB;GAChB,gBAAgB,SAAS,UAAU;GACnC,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;AACH;AAEA,iBAAiB,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import "../internal/use-overlay-root.mjs";
|
|
1
|
+
import "../internal/overlay/use-overlay-root.mjs";
|
|
@@ -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-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 * The submenu's popup, for the gesture's \"still over the submenu\" test (not `popovertarget`: a\n * non-button SubmenuTrigger has none).\n */\n readonly popup: () => HTMLElement | null;\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;AAkBA,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"}
|
|
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/overlay/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 (`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). 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 * The submenu's popup, for the gesture's \"still over the submenu\" test (not `popovertarget`: a\n * non-button SubmenuTrigger has none).\n */\n readonly popup: () => HTMLElement | null;\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;AAkBA,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPopoverOpen } from "../internal/popover-open.mjs";
|
|
1
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
2
2
|
import { submenuHover } from "./menu-context.mjs";
|
|
3
3
|
import { isDisabledItem } from "./menu-dom.mjs";
|
|
4
4
|
//#region src/menu/menu-gestures.ts
|
|
@@ -1 +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, registered with its hover). */\n const inSubmenuOf = (trigger: HTMLElement, target: Element | null) => {\n const submenu = submenuHover(trigger)?.popup() ?? null;\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,UAAU,aAAa,OAAO,CAAC,EAAE,MAAM,KAAK;EAClD,OAAO,YAAY,QAAQ,WAAW,QAAQ,QAAQ,SAAS,MAAM;CACvE;CACA,MAAM,gBAA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,aAAa,IAAI;CACnD,IAAI,iBAAiB,iBAAiB,iBAAiB,IAAI;CAC3D,OAAO;AACT;;;;;;;;;AAUA,SAAgB,gBACd,MACA,KACA,WACA,YAAY,OACN;CACN,KAAK,UAAU;CACf,IAAI;CACJ,MAAM,WAAW,UAAiB;EAChC,MAAM,eAAe;EACrB,MAAM,gBAAgB;EACtB,OAAO;CACT;CACA,MAAM,aAAa,UAAiB;EAClC,IAAK,MAAkC,cAAc,WAAW;EAChE,IAAI,aAAa,KAAA,GAAW,WAAW,WAAW,QAAQ,CAAC;CAC7D;CACA,MAAM,eAAe;EACnB,IAAI,aAAa,KAAA,GAAW,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
|
+
{"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/overlay/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, registered with its hover). */\n const inSubmenuOf = (trigger: HTMLElement, target: Element | null) => {\n const submenu = submenuHover(trigger)?.popup() ?? null;\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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U;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-item.d.mts","names":[],"sources":["../../src/menu/menu-item.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"menu-item.d.mts","names":[],"sources":["../../src/menu/menu-item.tsx"],"mappings":";;;;iBAgBiB,wBAAwB;;;;;iBAMxB;;WAEN;;WAEA;;;;;;;iBAQM,sBAAsB,KACrC;;;;;;;EASA,SAAS,QAAQ,SAAS;;;;;;EAM1B;;;;;;;;;;EAUA,eAAe;;;;;;;EAOf;;EAEA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;wBAiBvC,WACd,QACA,iBACA,cACA,UACA,OACA,WACA,OACA,UACA,WACG,QACF,gBAAa;yBAXA"}
|
package/dist/menu/menu-item.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createActionDetails } from "../internal/action-details.mjs";
|
|
3
|
-
import { dataAttr } from "../internal/data-attr.mjs";
|
|
4
|
-
import { useActionTrigger } from "../internal/use-action-trigger.mjs";
|
|
2
|
+
import { createActionDetails } from "../internal/action/action-details.mjs";
|
|
5
3
|
import { rendersButton } from "../internal/render-element.mjs";
|
|
4
|
+
import { usePureTrigger } from "../internal/action/use-pure-trigger.mjs";
|
|
6
5
|
import { useRender } from "../internal/use-render.mjs";
|
|
7
6
|
import { useMenuContext } from "./menu-context.mjs";
|
|
8
7
|
import { useMenuItem } from "./use-menu-item.mjs";
|
|
@@ -23,11 +22,12 @@ import { useMenuItem } from "./use-menu-item.mjs";
|
|
|
23
22
|
*/
|
|
24
23
|
function MenuItem({ action, closeOnActivate = true, whilePending, disabled = false, label, className, style, children, render, ...rest }) {
|
|
25
24
|
const menu = useMenuContext("Menu.Item");
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const trigger = usePureTrigger({
|
|
26
|
+
whilePending,
|
|
27
|
+
defaultWhilePending: closeOnActivate ? "ignore" : "run",
|
|
28
|
+
openGeneration: menu.root.popover.openGeneration
|
|
30
29
|
});
|
|
30
|
+
const { pending } = trigger;
|
|
31
31
|
const { libraryProps } = useMenuItem({
|
|
32
32
|
part: "Menu.Item",
|
|
33
33
|
role: "menuitem",
|
|
@@ -35,7 +35,7 @@ function MenuItem({ action, closeOnActivate = true, whilePending, disabled = fal
|
|
|
35
35
|
label,
|
|
36
36
|
activate: (event) => {
|
|
37
37
|
const details = createActionDetails(event, {});
|
|
38
|
-
|
|
38
|
+
trigger.runActivation(event, () => action?.(details), closeOnActivate ? () => menu.root.popover.requestClose(event, "activate") : void 0);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
return useRender({
|
|
@@ -52,8 +52,7 @@ function MenuItem({ action, closeOnActivate = true, whilePending, disabled = fal
|
|
|
52
52
|
libraryProps: {
|
|
53
53
|
...rendersButton(render) && { type: "button" },
|
|
54
54
|
...libraryProps,
|
|
55
|
-
|
|
56
|
-
"data-pending": dataAttr(pending)
|
|
55
|
+
...trigger.pendingProps(libraryProps)
|
|
57
56
|
}
|
|
58
57
|
});
|
|
59
58
|
}
|
|
@@ -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
|
|
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/action-details.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { usePureTrigger } from \"../internal/action/use-pure-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\n/**\n * State of `Menu.Item`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuItemState {\n /** This item's `action` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Menu.Item`.\n *\n * @see https://ui.funstack.work/components/menu\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 /**\n * Close the whole menu once `action` settles.\n *\n * @defaultValue `true`\n */\n closeOnActivate?: boolean;\n /**\n * What a click, Enter or Space does while this item's `action` is pending. `\"ignore\"`:\n * nothing (the event is cancelled, `aria-disabled=\"true\"` meanwhile). `\"run\"`: the action runs\n * again (`data-pending` until every run has settled); a closing item closes the menu once,\n * when the last run settles and only if the latest run resolved (a rejection keeps the menu\n * open, as in `\"ignore\"` mode). No effect without `action`.\n *\n * @defaultValue `\"ignore\"`, or `\"run\"` with `closeOnActivate={false}`\n */\n whilePending?: WhilePending;\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 * @defaultValue `false`\n */\n disabled?: boolean;\n /** Text typeahead matches when the item's text content is not representative (an icon). */\n label?: string;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuItemState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuItemState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\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` on the item; a second activation\n * meanwhile is ignored and the item `aria-disabled`, unless `whilePending` is `\"run\"`, the\n * default of a `closeOnActivate={false}` item); 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 *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuItem({\n action,\n closeOnActivate = true,\n whilePending,\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 // Mixed ownership (conventions 2.5.1): an item the library closes the menu after ignores by\n // default; a keep-open item is a user-owned trigger and runs every activation.\n const trigger = usePureTrigger({\n whilePending,\n defaultWhilePending: closeOnActivate ? \"ignore\" : \"run\",\n openGeneration: menu.root.popover.openGeneration,\n });\n const { pending } = trigger;\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 // When ignoring, a second activation while this item's own run is in flight starts\n // nothing and is cancelled (the hook's guard): a link does not navigate, a composed\n // command does not run. Enter / Space reach here through the element's click, their keydown is cancelled.\n trigger.runActivation(\n event,\n () => action?.(details),\n closeOnActivate ? () => menu.root.popover.requestClose(event, \"activate\") : undefined,\n );\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 when ignoring: an item that will not act is unavailable to AT. The\n // item is never natively disabled (`useMenuItem`'s focusable branch). Navigation keys on\n // `data-disabled` (the `disabled` prop), so a pending item is still an enabled item.\n // `libraryProps` stands in for a `disabledButton` result: its `disabled` (always\n // `undefined`) and `aria-disabled` (the `disabled` prop) are the item's disabled branch.\n ...trigger.pendingProps(libraryProps),\n },\n });\n}\n\nMenuItem.displayName = \"MenuItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,SAAS,EACvB,QACA,kBAAkB,MAClB,cACA,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACa;CAChB,MAAM,OAAO,eAAe,WAAW;CAIvC,MAAM,UAAU,eAAe;EAC7B;EACA,qBAAqB,kBAAkB,WAAW;EAClD,gBAAgB,KAAK,KAAK,QAAQ;CACpC,CAAC;CACD,MAAM,EAAE,YAAY;CAEpB,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAA2B,oBAAoB,OAAO,CAAC,CAAC;GAI9D,QAAQ,cACN,aACM,SAAS,OAAO,GACtB,wBAAwB,KAAK,KAAK,QAAQ,aAAa,OAAO,UAAU,IAAI,KAAA,CAC9E;EACF;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;GAMH,GAAG,QAAQ,aAAa,YAAY;EACtC;CACF,CAAC;AACH;AAEA,SAAS,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-outside.mjs","names":[],"sources":["../../src/menu/menu-outside.ts"],"sourcesContent":["// The outside right- and middle-click, scroll and wheel handling of an open top-level menu\n// (design/components/context-menu.md 5). No \"use client\" directive: DOM listeners only\n// (conventions 7.1).\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { isHandledBy } from \"./menu-context.js\";\nimport type { MenuContextValue, MenuPlacement } from \"./menu-context.js\";\n\n/**\n * The element under a wheel event that can scroll the way the wheel turns, up to `popup`: then\n * the wheel is the menu's own and the page under it is not involved.\n */\nfunction scrollsWithin(popup: HTMLElement, target: EventTarget | null, event: WheelEvent) {\n const vertical = Math.abs(event.deltaY) >= Math.abs(event.deltaX);\n const delta = vertical ? event.deltaY : event.deltaX;\n if (delta === 0) return true;\n let element = target instanceof Element ? target : null;\n while (element !== null && popup.contains(element)) {\n const computed = element.ownerDocument.defaultView?.getComputedStyle(element);\n const overflow = computed?.[vertical ? \"overflowY\" : \"overflowX\"] ?? \"\";\n if (overflow === \"auto\" || overflow === \"scroll\" || overflow === \"overlay\") {\n // Scroll offsets run 0..room (down, or right in LTR) or -room..0 (right to left).\n const room = vertical\n ? element.scrollHeight - element.clientHeight\n : element.scrollWidth - element.clientWidth;\n const offset = vertical ? element.scrollTop : element.scrollLeft;\n const min = !vertical && computed?.direction === \"rtl\" ? -room : 0;\n if (room > 0 && (delta > 0 ? offset < min + room - 0.5 : offset > min + 0.5)) return true;\n }\n element = element.parentElement;\n }\n return false;\n}\n\n/**\n * The outside right- and middle-click close of a top-level menu (context-menu.md 5): a\n * `contextmenu` outside the menu tree that this menu's ContextTrigger did not handle, or a\n * middle-button `pointerdown` outside it, hides the root popup at once (a fact: `\"dismiss\"` to\n * `onOpenChange` from the `toggle`). Chromium's click-based light dismiss ignores those buttons.\n *\n * While the menu is placed at a point (4.8; read at each event: a right-click may\n * re-place a Trigger-opened menu), a `scroll` of the document or of an element that contains the\n * region closes it the same way; scrolls elsewhere and inside the menu are ignored. Scrolling\n * already in flight at the open (a smooth scroll, trackpad momentum) does not count: scroll\n * events are ignored until the first animation frame without one. And a `wheel`\n * over any menu never scrolls the page: it is prevented unless something in the menu under the\n * pointer can scroll that way, or it is a zoom (`ctrlKey`: Ctrl+wheel, trackpad pinch). Returns\n * the cleanup.\n */\nexport function listenOutside(\n popup: HTMLElement,\n menu: MenuContextValue,\n placement: () => MenuPlacement,\n): () => void {\n const doc = popup.ownerDocument;\n const inside = (target: EventTarget | null) => target instanceof Node && popup.contains(target);\n const close = () => {\n if (isPopoverOpen(popup)) popup.hidePopover();\n };\n // Bubble phase: the region's handler ran first and marked a move.\n const onContextMenu = (event: Event) => {\n if (inside(event.target) || isHandledBy(event, menu)) return;\n close();\n };\n const onPointerDown = (event: Event) => {\n if ((event as globalThis.PointerEvent).button !== 1 || inside(event.target)) return;\n close();\n };\n // Scroll events run in a frame's rendering steps, before its animation frame callbacks: the\n // first callback that saw none since the last one ends the in-flight scroll window.\n const view = doc.defaultView;\n let settling = typeof view?.requestAnimationFrame === \"function\";\n let scrolledThisFrame = false;\n let frame = 0;\n const tick = () => {\n if (scrolledThisFrame) {\n scrolledThisFrame = false;\n frame = view!.requestAnimationFrame(tick);\n } else settling = false;\n };\n if (settling) frame = view!.requestAnimationFrame(tick);\n const onScroll = (event: Event) => {\n if (settling) {\n scrolledThisFrame = true;\n return;\n }\n const current = placement();\n if (current.kind !== \"point\") return;\n const target = event.target;\n // The point is meaningless once the content under it moved: the document, or a scroller\n // around the region (React Aria's rule). A scroller elsewhere or inside the menu is not.\n if (target instanceof Node && target.nodeType !== Node.DOCUMENT_NODE) {\n if (inside(target) || !target.contains(current.source)) return;\n }\n close();\n };\n // Native menus never scroll the page from inside the menu; a non-overflowing popup would chain\n // the wheel to the page (Firefox ignores `overscroll-behavior` there).\n const onWheel = (event: WheelEvent) => {\n // A zoom, not a scroll: Ctrl+wheel and a trackpad pinch (`wheel` with `ctrlKey`) stay the\n // user's.\n if (event.ctrlKey) return;\n if (!scrollsWithin(popup, event.target, event)) event.preventDefault();\n };\n doc.addEventListener(\"contextmenu\", onContextMenu);\n doc.addEventListener(\"pointerdown\", onPointerDown, true);\n doc.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n popup.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => {\n if (settling) view!.cancelAnimationFrame(frame);\n doc.removeEventListener(\"contextmenu\", onContextMenu);\n doc.removeEventListener(\"pointerdown\", onPointerDown, true);\n doc.removeEventListener(\"scroll\", onScroll, { capture: true });\n popup.removeEventListener(\"wheel\", onWheel);\n };\n}\n"],"mappings":";;;;;;;AAWA,SAAS,cAAc,OAAoB,QAA4B,OAAmB;CACxF,MAAM,WAAW,KAAK,IAAI,MAAM,MAAM,KAAK,KAAK,IAAI,MAAM,MAAM;CAChE,MAAM,QAAQ,WAAW,MAAM,SAAS,MAAM;CAC9C,IAAI,UAAU,GAAG,OAAO;CACxB,IAAI,UAAU,kBAAkB,UAAU,SAAS;CACnD,OAAO,YAAY,QAAQ,MAAM,SAAS,OAAO,GAAG;EAClD,MAAM,WAAW,QAAQ,cAAc,aAAa,iBAAiB,OAAO;EAC5E,MAAM,WAAW,WAAW,WAAW,cAAc,gBAAgB;EACrE,IAAI,aAAa,UAAU,aAAa,YAAY,aAAa,WAAW;GAE1E,MAAM,OAAO,WACT,QAAQ,eAAe,QAAQ,eAC/B,QAAQ,cAAc,QAAQ;GAClC,MAAM,SAAS,WAAW,QAAQ,YAAY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AO,MAAM,QAAQ,KAAK,GAAG,MAAM,eAAe;CACvE;CACA,IAAI,iBAAiB,eAAe,aAAa;CACjD,IAAI,iBAAiB,eAAe,eAAe,IAAI;CACvD,IAAI,iBAAiB,UAAU,UAAU;EAAE,SAAS;EAAM,SAAS;CAAK,CAAC;CACzE,MAAM,iBAAiB,SAAS,SAAS,EAAE,SAAS,MAAM,CAAC;CAC3D,aAAa;EACX,IAAI,UAAU,KAAM,qBAAqB,KAAK;EAC9C,IAAI,oBAAoB,eAAe,aAAa;EACpD,IAAI,oBAAoB,eAAe,eAAe,IAAI;EAC1D,IAAI,oBAAoB,UAAU,UAAU,EAAE,SAAS,KAAK,CAAC;EAC7D,MAAM,oBAAoB,SAAS,OAAO;CAC5C;AACF"}
|
|
1
|
+
{"version":3,"file":"menu-outside.mjs","names":[],"sources":["../../src/menu/menu-outside.ts"],"sourcesContent":["// The outside right- and middle-click, scroll and wheel handling of an open top-level menu\n// (design/components/context-menu.md 5). No \"use client\" directive: DOM listeners only\n// (conventions 7.1).\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport { isHandledBy } from \"./menu-context.js\";\nimport type { MenuContextValue, MenuPlacement } from \"./menu-context.js\";\n\n/**\n * The element under a wheel event that can scroll the way the wheel turns, up to `popup`: then\n * the wheel is the menu's own and the page under it is not involved.\n */\nfunction scrollsWithin(popup: HTMLElement, target: EventTarget | null, event: WheelEvent) {\n const vertical = Math.abs(event.deltaY) >= Math.abs(event.deltaX);\n const delta = vertical ? event.deltaY : event.deltaX;\n if (delta === 0) return true;\n let element = target instanceof Element ? target : null;\n while (element !== null && popup.contains(element)) {\n const computed = element.ownerDocument.defaultView?.getComputedStyle(element);\n const overflow = computed?.[vertical ? \"overflowY\" : \"overflowX\"] ?? \"\";\n if (overflow === \"auto\" || overflow === \"scroll\" || overflow === \"overlay\") {\n // Scroll offsets run 0..room (down, or right in LTR) or -room..0 (right to left).\n const room = vertical\n ? element.scrollHeight - element.clientHeight\n : element.scrollWidth - element.clientWidth;\n const offset = vertical ? element.scrollTop : element.scrollLeft;\n const min = !vertical && computed?.direction === \"rtl\" ? -room : 0;\n if (room > 0 && (delta > 0 ? offset < min + room - 0.5 : offset > min + 0.5)) return true;\n }\n element = element.parentElement;\n }\n return false;\n}\n\n/**\n * The outside right- and middle-click close of a top-level menu (context-menu.md 5): a\n * `contextmenu` outside the menu tree that this menu's ContextTrigger did not handle, or a\n * middle-button `pointerdown` outside it, hides the root popup at once (a fact: `\"dismiss\"` to\n * `onOpenChange` from the `toggle`). Chromium's click-based light dismiss ignores those buttons.\n *\n * While the menu is placed at a point (4.8; read at each event: a right-click may\n * re-place a Trigger-opened menu), a `scroll` of the document or of an element that contains the\n * region closes it the same way; scrolls elsewhere and inside the menu are ignored. Scrolling\n * already in flight at the open (a smooth scroll, trackpad momentum) does not count: scroll\n * events are ignored until the first animation frame without one. And a `wheel`\n * over any menu never scrolls the page: it is prevented unless something in the menu under the\n * pointer can scroll that way, or it is a zoom (`ctrlKey`: Ctrl+wheel, trackpad pinch). Returns\n * the cleanup.\n */\nexport function listenOutside(\n popup: HTMLElement,\n menu: MenuContextValue,\n placement: () => MenuPlacement,\n): () => void {\n const doc = popup.ownerDocument;\n const inside = (target: EventTarget | null) => target instanceof Node && popup.contains(target);\n const close = () => {\n if (isPopoverOpen(popup)) popup.hidePopover();\n };\n // Bubble phase: the region's handler ran first and marked a move.\n const onContextMenu = (event: Event) => {\n if (inside(event.target) || isHandledBy(event, menu)) return;\n close();\n };\n const onPointerDown = (event: Event) => {\n if ((event as globalThis.PointerEvent).button !== 1 || inside(event.target)) return;\n close();\n };\n // Scroll events run in a frame's rendering steps, before its animation frame callbacks: the\n // first callback that saw none since the last one ends the in-flight scroll window.\n const view = doc.defaultView;\n let settling = typeof view?.requestAnimationFrame === \"function\";\n let scrolledThisFrame = false;\n let frame = 0;\n const tick = () => {\n if (scrolledThisFrame) {\n scrolledThisFrame = false;\n frame = view!.requestAnimationFrame(tick);\n } else settling = false;\n };\n if (settling) frame = view!.requestAnimationFrame(tick);\n const onScroll = (event: Event) => {\n if (settling) {\n scrolledThisFrame = true;\n return;\n }\n const current = placement();\n if (current.kind !== \"point\") return;\n const target = event.target;\n // The point is meaningless once the content under it moved: the document, or a scroller\n // around the region (React Aria's rule). A scroller elsewhere or inside the menu is not.\n if (target instanceof Node && target.nodeType !== Node.DOCUMENT_NODE) {\n if (inside(target) || !target.contains(current.source)) return;\n }\n close();\n };\n // Native menus never scroll the page from inside the menu; a non-overflowing popup would chain\n // the wheel to the page (Firefox ignores `overscroll-behavior` there).\n const onWheel = (event: WheelEvent) => {\n // A zoom, not a scroll: Ctrl+wheel and a trackpad pinch (`wheel` with `ctrlKey`) stay the\n // user's.\n if (event.ctrlKey) return;\n if (!scrollsWithin(popup, event.target, event)) event.preventDefault();\n };\n doc.addEventListener(\"contextmenu\", onContextMenu);\n doc.addEventListener(\"pointerdown\", onPointerDown, true);\n doc.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n popup.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => {\n if (settling) view!.cancelAnimationFrame(frame);\n doc.removeEventListener(\"contextmenu\", onContextMenu);\n doc.removeEventListener(\"pointerdown\", onPointerDown, true);\n doc.removeEventListener(\"scroll\", onScroll, { capture: true });\n popup.removeEventListener(\"wheel\", onWheel);\n };\n}\n"],"mappings":";;;;;;;AAWA,SAAS,cAAc,OAAoB,QAA4B,OAAmB;CACxF,MAAM,WAAW,KAAK,IAAI,MAAM,MAAM,KAAK,KAAK,IAAI,MAAM,MAAM;CAChE,MAAM,QAAQ,WAAW,MAAM,SAAS,MAAM;CAC9C,IAAI,UAAU,GAAG,OAAO;CACxB,IAAI,UAAU,kBAAkB,UAAU,SAAS;CACnD,OAAO,YAAY,QAAQ,MAAM,SAAS,OAAO,GAAG;EAClD,MAAM,WAAW,QAAQ,cAAc,aAAa,iBAAiB,OAAO;EAC5E,MAAM,WAAW,WAAW,WAAW,cAAc,gBAAgB;EACrE,IAAI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,KAAK,CAAC,OAAO,SAAS,QAAQ,MAAM,GAAG;EAAA;EAE1D,MAAM;CACR;CAGA,MAAM,WAAW,UAAsB;EAGrC,IAAI,MAAM,SAAS;EACnB,IAAI,CAAC,cAAc,OAAO,MAAM,QAAQ,KAAK,GAAG,MAAM,eAAe;CACvE;CACA,IAAI,iBAAiB,eAAe,aAAa;CACjD,IAAI,iBAAiB,eAAe,eAAe,IAAI;CACvD,IAAI,iBAAiB,UAAU,UAAU;EAAE,SAAS;EAAM,SAAS;CAAK,CAAC;CACzE,MAAM,iBAAiB,SAAS,SAAS,EAAE,SAAS,MAAM,CAAC;CAC3D,aAAa;EACX,IAAI,UAAU,KAAM,qBAAqB,KAAK;EAC9C,IAAI,oBAAoB,eAAe,aAAa;EACpD,IAAI,oBAAoB,eAAe,eAAe,IAAI;EAC1D,IAAI,oBAAoB,UAAU,UAAU,EAAE,SAAS,KAAK,CAAC;EAC7D,MAAM,oBAAoB,SAAS,OAAO;CAC5C;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
-
import { AnchorAlign, AnchorSide } from "../internal/anchor-position.mjs";
|
|
2
|
+
import { AnchorAlign, AnchorSide } from "../internal/overlay/anchor-position.mjs";
|
|
3
3
|
import { CSSProperties, ComponentPropsWithRef, ReactNode, ViewTransitionClass } from "react";
|
|
4
4
|
//#region src/menu/menu-popup.d.ts
|
|
5
5
|
/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-popup.d.mts","names":[],"sources":["../../src/menu/menu-popup.tsx"],"mappings":";;;;;YAsCY,WAAW;;;;;YAKX,YAAY;;;;;iBAMP;;WAEN;;;;;;WAMA,MAAM;;WAEN,OAAO;;WAEP;;;;;WAKA;;;;;;;iBAQM,uBAAuB,KACtC;;;;;;;;;;;;;EA8BA,OAAO;;;;;;;EAOP,QAAQ;;;;;;;;EAQR;;;;;;;;;EASA;;;;;;;;;;EAUA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"menu-popup.d.mts","names":[],"sources":["../../src/menu/menu-popup.tsx"],"mappings":";;;;;YAsCY,WAAW;;;;;YAKX,YAAY;;;;;iBAMP;;WAEN;;;;;;WAMA,MAAM;;WAEN,OAAO;;WAEP;;;;;WAKA;;;;;;;iBAQM,uBAAuB,KACtC;;;;;;;;;;;;;EA8BA,OAAO;;;;;;;EAOP,QAAQ;;;;;;;;EAQR;;;;;;;;;EASA;;;;;;;;;;EAUA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;wBAmCpC,YACd,MAAM,UACN,OACA,aACA,yBACA,YACA,WACA,OACA,UACA,WACG,QACF,iBAAc;yBAXD"}
|
package/dist/menu/menu-popup.mjs
CHANGED
|
@@ -6,12 +6,12 @@ import { useLatest } from "../internal/use-latest.mjs";
|
|
|
6
6
|
import { useNativeFocusgroup } from "../internal/use-native-focusgroup.mjs";
|
|
7
7
|
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
8
8
|
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
9
|
-
import { isPopoverOpen } from "../internal/popover-open.mjs";
|
|
10
|
-
import { useAnchoredPlacement } from "../internal/use-resolved-placement.mjs";
|
|
9
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
10
|
+
import { useAnchoredPlacement } from "../internal/overlay/use-resolved-placement.mjs";
|
|
11
11
|
import { CSPContext } from "../internal/csp-context.mjs";
|
|
12
12
|
import { FSUI_PRECEDENCE } from "../internal/shipped-styles.mjs";
|
|
13
|
-
import { listenInvokerPresses } from "../internal/invokers.mjs";
|
|
14
|
-
import { usePopoverPopup } from "../internal/use-popover-popup.mjs";
|
|
13
|
+
import { listenInvokerPresses } from "../internal/overlay/invokers.mjs";
|
|
14
|
+
import { usePopoverPopup } from "../internal/overlay/use-popover-popup.mjs";
|
|
15
15
|
import { MenuListContext, claimPress, useMenuContext } from "./menu-context.mjs";
|
|
16
16
|
import { edgeItem } from "./menu-dom.mjs";
|
|
17
17
|
import { capturePointer } from "../internal/pointer-capture.mjs";
|
|
@@ -23,7 +23,11 @@ import { use, useCallback, useLayoutEffect, useMemo, useRef } from "react";
|
|
|
23
23
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
24
24
|
//#region src/menu/menu-popup.tsx
|
|
25
25
|
const isDev = process.env.NODE_ENV !== "production";
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* What a press may focus inside a popup: items, the popup itself, the consumer's controls.
|
|
28
|
+
* Differs from the roving and Tooltip selectors on purpose: it asks "does a press focus
|
|
29
|
+
* something", so any `input` counts (a hidden one is never pressed).
|
|
30
|
+
*/
|
|
27
31
|
const FOCUSABLE_SELECTOR = "a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])";
|
|
28
32
|
/**
|
|
29
33
|
* The menu itself: `<div popover="auto" role="menu" aria-labelledby={trigger} tabindex="-1">`,
|
|
@@ -66,7 +70,7 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
|
|
|
66
70
|
const { onKeyDown, typingAhead } = useMenuKeyboard(menu, nativeFocusgroup);
|
|
67
71
|
const { setElement, visible, renderContent, reshow } = usePopoverPopup(popover, {
|
|
68
72
|
part: "Menu.Popup",
|
|
69
|
-
|
|
73
|
+
initialFocus: (popup) => {
|
|
70
74
|
const { cause, pointer } = menu.takeOpenCause();
|
|
71
75
|
if (cause === "none") return null;
|
|
72
76
|
const element = edgeItem(popup, cause) ?? popup;
|