@funstack/ui 0.1.0-alpha.17 → 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 +35 -38
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +1 -1
- package/dist/button/button.d.mts +18 -11
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +32 -16
- 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 +15 -12
- 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 -161
- 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/accordion.md +1 -1
- package/dist/docs/components/button.md +13 -10
- package/dist/docs/components/dialog.md +4 -4
- package/dist/docs/components/field.md +4 -3
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/toast.md +8 -5
- package/dist/docs/concepts/browser-owned-state.md +1 -1
- 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} +20 -32
- 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} +8 -8
- 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 -63
- 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":"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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oBAAoB;CACxB,IAAI,QAAQ;CACZ,MAAM,aAAa;EACjB,IAAI,mBAAmB;GACrB,oBAAoB;GACpB,QAAQ,KAAM,sBAAsB,IAAI;EAC1C,OAAO,WAAW;CACpB;CACA,IAAI,UAAU,QAAQ,KAAM,sBAAsB,IAAI;CACtD,MAAM,YAAY,UAAiB;EACjC,IAAI,UAAU;GACZ,oBAAoB;GACpB;EACF;EACA,MAAM,UAAU,UAAU;EAC1B,IAAI,QAAQ,SAAS,SAAS;EAC9B,MAAM,SAAS,MAAM;EAGrB,IAAI,kBAAkB,QAAQ,OAAO,aAAa,KAAK,eACjD;OAAA,OAAO,MAAM,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
|
+
{"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,aAAa,UAAU,aAAa,YAAY,aAAa,WAAW;GAE1E,MAAM,OAAO,WACT,QAAQ,eAAe,QAAQ,eAC/B,QAAQ,cAAc,QAAQ;GAClC,MAAM,SAAS,WAAW,QAAQ,YAAY,QAAQ;GACtD,MAAM,MAAM,CAAC,YAAY,UAAU,cAAc,QAAQ,CAAC,OAAO;GACjE,IAAI,OAAO,MAAM,QAAQ,IAAI,SAAS,MAAM,OAAO,KAAM,SAAS,MAAM,KAAM,OAAO;EACvF;EACA,UAAU,QAAQ;CACpB;CACA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,cACd,OACA,MACA,WACY;CACZ,MAAM,MAAM,MAAM;CAClB,MAAM,UAAU,WAA+B,kBAAkB,QAAQ,MAAM,SAAS,MAAM;CAC9F,MAAM,cAAc;EAClB,IAAI,cAAc,KAAK,GAAG,MAAM,YAAY;CAC9C;CAEA,MAAM,iBAAiB,UAAiB;EACtC,IAAI,OAAO,MAAM,MAAM,KAAK,YAAY,OAAO,IAAI,GAAG;EACtD,MAAM;CACR;CACA,MAAM,iBAAiB,UAAiB;EAC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";
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { listenInvokerPresses } from \"../internal/invokers.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { capturePointer } from \"../internal/pointer-capture.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/shipped-styles.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useNativeFocusgroup } from \"../internal/use-native-focusgroup.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { useAnchoredPlacement } from \"../internal/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { claimPress, MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuListContextValue } from \"./menu-context.js\";\nimport { edgeItem } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport { listenOutside } from \"./menu-outside.js\";\nimport { MENU_POINT_HREF, MENU_POINT_RULES, pointStyle } from \"./menu-point.js\";\nimport { useMenuKeyboard } from \"./use-menu-keyboard.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */\nexport type MenuSide = AnchorSide;\n/**\n * Alignment of the Popup along its side: inline-relative on a top / bottom side, the top / bottom\n * edges on the others.\n */\nexport type MenuAlign = AnchorAlign;\n\n/**\n * State of `Menu.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`, and while the menu\n * is placed at a point (`context`).\n */\n readonly side: MenuSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n /**\n * The current open came from a `Menu.ContextTrigger`: the popup is placed at the pointer, with\n * `--menu-point-x` / `--menu-point-y` set inline (`data-context`).\n */\n readonly context: boolean;\n}\n\n/**\n * Props of `Menu.Popup`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onContextMenu\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. A submenu's `\"inline-end\"` is the right of the item in LTR,\n * its left in RTL; its fallback is `flip-inline` only. `\"left\"` / `\"right\"` stay physical.\n * `null` emits no inline positioning (and no `data-side` / `data-align`): the stylesheet owns\n * placement. Ignored for an open from a\n * `Menu.ContextTrigger`, which is placed at the pointer; there `null` also opts out of the\n * inline point placement and the library's `@position-try` rules, leaving only\n * `--menu-point-x` / `--menu-point-y`.\n *\n * @defaultValue `\"bottom\"` for a top-level menu, `\"inline-end\"` for a submenu\n */\n side?: MenuSide | null;\n /**\n * Alignment along the side: inline-relative on a top / bottom side (mirrored under\n * `direction: rtl`), the top edges on the others. Ignored when `side` is `null`.\n *\n * @defaultValue `\"start\"` (both levels)\n */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines.\n *\n * @defaultValue `false`\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n * While a view transition runs, the popup's CSS transitions are turned off for the moment of the\n * library's own show or hide (an inline `transition: none !important`, restored right after),\n * so that show or hide runs no CSS transition (a `@keyframes` animation is not cut).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab);\n * a press on a button of the consumer's that names it (`popovertarget`, `commandfor`) moves no\n * focus, so that button's click closes the menu as `\"activate\"`.\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While\n * shown, those are where the browser placed it (conventions 13.2), otherwise the requested\n * values.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this\n * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`\n * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`.\n * Such an open is placed at the pointer: `--menu-point-x` / `--menu-point-y` inline and, unless\n * `side` is `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's\n * `@position-try` fallbacks, whose rules it renders as a hoisted `<style>`. A top-level menu\n * closes at once on a right- or middle-click outside it.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const csp = use(CSPContext);\n // The listeners installed at the open read the placement of the latest commit (4.8).\n const latestPlacement = useLatest(menu.placement);\n // A submenu opens on the inline-end side of its item: the side ArrowRight (ArrowLeft in RTL)\n // points to.\n const sideOption = sideProp === undefined ? (submenu ? \"inline-end\" : \"bottom\") : sideProp;\n // A ContextTrigger's open is placed at the point; nothing is anchored (context-menu.md 3.3).\n const point = menu.placement.kind === \"point\" ? menu.placement : null;\n const requestedSide = point !== null ? null : sideOption;\n // Resolved while shown (conventions 13.2); idle for a point open, which has no side.\n const placement = useAnchoredPlacement({\n side: requestedSide,\n align,\n fallbacks: submenu ? \"flip-inline\" : undefined,\n });\n const { side, align: resolvedAlign, ref: placementRef } = placement;\n\n const nativeFocusgroup = useNativeFocusgroup(experimental_focusgroup);\n const { onKeyDown, typingAhead } = useMenuKeyboard(menu, nativeFocusgroup);\n\n const { setElement, visible, renderContent, reshow } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so.\n resolveInitialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n // A point open nests through the region that opened it (context-menu.md 3.1).\n source: () => (point !== null ? point.source : popover.triggerRef.current),\n // The outside right- / middle-click listeners and the foreign invoker press guard of a\n // top-level menu.\n whileShown: submenu\n ? undefined\n : (element) => {\n const stopListening = listenOutside(element, menu, () => latestPlacement.current);\n const stopPresses = listenInvokerPresses(element);\n return () => {\n stopListening();\n stopPresses();\n };\n },\n });\n\n // A move (context-menu.md 4.3): the popup is shown and the placement changed since it was\n // shown (a new point, or a right-click in the region while a Trigger open is shown). Re-show\n // it so the respelled fallbacks place it afresh, the source is the region and the first item\n // is focused again; then capture the still-pressed pointer again, against the Firefox / WebKit\n // `pointerup` light dismiss. Runs after the hook's apply effect (declared after it).\n // Once the popup is not visible (hidden, exit animation over) and no open is intended or in\n // flight, a point placement goes back to anchored for the next open that is not a\n // ContextTrigger's: after a point open that was shown and closed, and after one that was\n // rejected or refused.\n const shownKey = useRef<number | \"anchor\" | null>(null);\n useLayoutEffect(() => {\n const element = popover.popupRef.current;\n if (element === null) return;\n const key = point !== null ? point.generation : \"anchor\";\n if (isPopoverOpen(element)) {\n if (shownKey.current !== null && shownKey.current !== key && reshow()) {\n capturePointer(element, point?.pointerId);\n }\n shownKey.current = key;\n } else {\n shownKey.current = null;\n if (!visible && point !== null && !popover.pending && !popover.intended()) {\n menu.resetPlacement(point.generation);\n }\n }\n });\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName === \"DIALOG\"\n ? \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\"\n : null),\n );\n const pressRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n // A press inside a menu is never a long-press of a Menu.ContextTrigger around it.\n // Native, so it runs before React's root listener dispatches to the region.\n const onPointerDown = (event: Event) => claimPress(event);\n element.addEventListener(\"pointerdown\", onPointerDown);\n return () => element.removeEventListener(\"pointerdown\", onPointerDown);\n },\n [checkElement],\n );\n const ref = useMergedRefs(setElement, pressRef, placementRef);\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = {\n open: popover.committed,\n side,\n align: resolvedAlign,\n submenu,\n context: point !== null,\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (isPopoverOpen(popup)) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n // No native menu over the custom one. The popup is a sibling of any ContextTrigger, so this\n // event never reaches a region as a move; an outer region sees it prevented and stays quiet.\n onContextMenu: (event: MouseEvent<HTMLElement>) => {\n event.preventDefault();\n },\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...placement.dataAttributes,\n \"data-context\": point !== null ? \"\" : undefined,\n };\n\n // The shipped `@position-try` rules (conventions 12): hoisted into <head> and deduplicated by\n // React, rendered only by a point open that does not opt out with `side={null}`, with the\n // `<CSPProvider>` nonce for a nonce-based `style-src`.\n const pointRules =\n point !== null && sideOption !== null ? (\n <style href={MENU_POINT_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {MENU_POINT_RULES}\n </style>\n ) : null;\n\n const content = (s: MenuPopupState): ReactNode => (\n <MenuListContext value={listContext}>\n {pointRules}\n {renderContent(() => resolveStateValue(children, s))}\n </MenuListContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins.\n style:\n point !== null\n ? (s) => ({ ...pointStyle(point, sideOption === null), ...resolveStateValue(style, s) })\n : placement.style(style),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAoHvC,MAAM,qBACJ;;;;;;;;;;;;;;;;;;;;;;;;;AA0BF,SAAgB,UAAU,EACxB,MAAM,UACN,QAAQ,SACR,aACA,0BAA0B,OAC1B,YACA,WACA,OACA,UACA,QACA,GAAG,QACc;CACjB,MAAM,OAAO,eAAe,YAAY;CACxC,MAAM,EAAE,SAAS,SAAS,SAAS;CACnC,MAAM,MAAM,IAAI,UAAU;CAE1B,MAAM,kBAAkB,UAAU,KAAK,SAAS;CAGhD,MAAM,aAAa,aAAa,KAAA,IAAa,UAAU,eAAe,WAAY;CAElF,MAAM,QAAQ,KAAK,UAAU,SAAS,UAAU,KAAK,YAAY;CAGjE,MAAM,YAAY,qBAAqB;EACrC,MAHoB,UAAU,OAAO,OAAO;EAI5C;EACA,WAAW,UAAU,gBAAgB,KAAA;CACvC,CAAC;CACD,MAA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K;EACpE,UAAA;CACI,CAAA,IACL;CAEN,MAAM,WAAW,MACf,qBAAC,iBAAD;EAAiB,OAAO;EAAxB,UAAA,CACG,YACA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC,CACpC;;CAGnB,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,OACE,UAAU,QACL,OAAO;GAAE,GAAG,WAAW,OAAO,eAAe,IAAI;GAAG,GAAG,kBAAkB,OAAO,CAAC;EAAE,KACpF,UAAU,MAAM,KAAK;EAC3B,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,cAAc,YAAY,OAAO;AAChE;AAEA,UAAU,cAAc"}
|
|
1
|
+
{"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/overlay/anchor-position.js\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { listenInvokerPresses } from \"../internal/overlay/invokers.js\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport { capturePointer } from \"../internal/pointer-capture.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/shipped-styles.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useNativeFocusgroup } from \"../internal/use-native-focusgroup.js\";\nimport { usePopoverPopup } from \"../internal/overlay/use-popover-popup.js\";\nimport { useAnchoredPlacement } from \"../internal/overlay/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { claimPress, MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuListContextValue } from \"./menu-context.js\";\nimport { edgeItem } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport { listenOutside } from \"./menu-outside.js\";\nimport { MENU_POINT_HREF, MENU_POINT_RULES, pointStyle } from \"./menu-point.js\";\nimport { useMenuKeyboard } from \"./use-menu-keyboard.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */\nexport type MenuSide = AnchorSide;\n/**\n * Alignment of the Popup along its side: inline-relative on a top / bottom side, the top / bottom\n * edges on the others.\n */\nexport type MenuAlign = AnchorAlign;\n\n/**\n * State of `Menu.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`, and while the menu\n * is placed at a point (`context`).\n */\n readonly side: MenuSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n /**\n * The current open came from a `Menu.ContextTrigger`: the popup is placed at the pointer, with\n * `--menu-point-x` / `--menu-point-y` set inline (`data-context`).\n */\n readonly context: boolean;\n}\n\n/**\n * Props of `Menu.Popup`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onContextMenu\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. A submenu's `\"inline-end\"` is the right of the item in LTR,\n * its left in RTL; its fallback is `flip-inline` only. `\"left\"` / `\"right\"` stay physical.\n * `null` emits no inline positioning (and no `data-side` / `data-align`): the stylesheet owns\n * placement. Ignored for an open from a\n * `Menu.ContextTrigger`, which is placed at the pointer; there `null` also opts out of the\n * inline point placement and the library's `@position-try` rules, leaving only\n * `--menu-point-x` / `--menu-point-y`.\n *\n * @defaultValue `\"bottom\"` for a top-level menu, `\"inline-end\"` for a submenu\n */\n side?: MenuSide | null;\n /**\n * Alignment along the side: inline-relative on a top / bottom side (mirrored under\n * `direction: rtl`), the top edges on the others. Ignored when `side` is `null`.\n *\n * @defaultValue `\"start\"` (both levels)\n */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines.\n *\n * @defaultValue `false`\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n * While a view transition runs, the popup's CSS transitions are turned off for the moment of the\n * library's own show or hide (an inline `transition: none !important`, restored right after),\n * so that show or hide runs no CSS transition (a `@keyframes` animation is not cut).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/**\n * What a press may focus inside a popup: items, the popup itself, the consumer's controls.\n * Differs from the roving and Tooltip selectors on purpose: it asks \"does a press focus\n * something\", so any `input` counts (a hidden one is never pressed).\n */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab);\n * a press on a button of the consumer's that names it (`popovertarget`, `commandfor`) moves no\n * focus, so that button's click closes the menu as `\"activate\"`.\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While\n * shown, those are where the browser placed it (conventions 13.2), otherwise the requested\n * values.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this\n * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`\n * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`.\n * Such an open is placed at the pointer: `--menu-point-x` / `--menu-point-y` inline and, unless\n * `side` is `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's\n * `@position-try` fallbacks, whose rules it renders as a hoisted `<style>`. A top-level menu\n * closes at once on a right- or middle-click outside it.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const csp = use(CSPContext);\n // The listeners installed at the open read the placement of the latest commit (4.8).\n const latestPlacement = useLatest(menu.placement);\n // A submenu opens on the inline-end side of its item: the side ArrowRight (ArrowLeft in RTL)\n // points to.\n const sideOption = sideProp === undefined ? (submenu ? \"inline-end\" : \"bottom\") : sideProp;\n // A ContextTrigger's open is placed at the point; nothing is anchored (context-menu.md 3.3).\n const point = menu.placement.kind === \"point\" ? menu.placement : null;\n const requestedSide = point !== null ? null : sideOption;\n // Resolved while shown (conventions 13.2); idle for a point open, which has no side.\n const placement = useAnchoredPlacement({\n side: requestedSide,\n align,\n fallbacks: submenu ? \"flip-inline\" : undefined,\n });\n const { side, align: resolvedAlign, ref: placementRef } = placement;\n\n const nativeFocusgroup = useNativeFocusgroup(experimental_focusgroup);\n const { onKeyDown, typingAhead } = useMenuKeyboard(menu, nativeFocusgroup);\n\n const { setElement, visible, renderContent, reshow } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so.\n initialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n // A point open nests through the region that opened it (context-menu.md 3.1).\n source: () => (point !== null ? point.source : popover.triggerRef.current),\n // The outside right- / middle-click listeners and the foreign invoker press guard of a\n // top-level menu.\n whileShown: submenu\n ? undefined\n : (element) => {\n const stopListening = listenOutside(element, menu, () => latestPlacement.current);\n const stopPresses = listenInvokerPresses(element);\n return () => {\n stopListening();\n stopPresses();\n };\n },\n });\n\n // A move (context-menu.md 4.3): the popup is shown and the placement changed since it was\n // shown (a new point, or a right-click in the region while a Trigger open is shown). Re-show\n // it so the respelled fallbacks place it afresh, the source is the region and the first item\n // is focused again; then capture the still-pressed pointer again, against the Firefox / WebKit\n // `pointerup` light dismiss. Runs after the hook's apply effect (declared after it).\n // Once the popup is not visible (hidden, exit animation over) and no open is intended or in\n // flight, a point placement goes back to anchored for the next open that is not a\n // ContextTrigger's: after a point open that was shown and closed, and after one that was\n // rejected or refused.\n const shownKey = useRef<number | \"anchor\" | null>(null);\n useLayoutEffect(() => {\n const element = popover.popupRef.current;\n if (element === null) return;\n const key = point !== null ? point.generation : \"anchor\";\n if (isPopoverOpen(element)) {\n if (shownKey.current !== null && shownKey.current !== key && reshow()) {\n capturePointer(element, point?.pointerId);\n }\n shownKey.current = key;\n } else {\n shownKey.current = null;\n if (!visible && point !== null && !popover.pending && !popover.intended()) {\n menu.resetPlacement(point.generation);\n }\n }\n });\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName === \"DIALOG\"\n ? \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\"\n : null),\n );\n const pressRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n // A press inside a menu is never a long-press of a Menu.ContextTrigger around it.\n // Native, so it runs before React's root listener dispatches to the region.\n const onPointerDown = (event: Event) => claimPress(event);\n element.addEventListener(\"pointerdown\", onPointerDown);\n return () => element.removeEventListener(\"pointerdown\", onPointerDown);\n },\n [checkElement],\n );\n const ref = useMergedRefs(setElement, pressRef, placementRef);\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = {\n open: popover.committed,\n side,\n align: resolvedAlign,\n submenu,\n context: point !== null,\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (isPopoverOpen(popup)) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n // No native menu over the custom one. The popup is a sibling of any ContextTrigger, so this\n // event never reaches a region as a move; an outer region sees it prevented and stays quiet.\n onContextMenu: (event: MouseEvent<HTMLElement>) => {\n event.preventDefault();\n },\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...placement.dataAttributes,\n \"data-context\": point !== null ? \"\" : undefined,\n };\n\n // The shipped `@position-try` rules (conventions 12): hoisted into <head> and deduplicated by\n // React, rendered only by a point open that does not opt out with `side={null}`, with the\n // `<CSPProvider>` nonce for a nonce-based `style-src`.\n const pointRules =\n point !== null && sideOption !== null ? (\n <style href={MENU_POINT_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {MENU_POINT_RULES}\n </style>\n ) : null;\n\n const content = (s: MenuPopupState): ReactNode => (\n <MenuListContext value={listContext}>\n {pointRules}\n {renderContent(() => resolveStateValue(children, s))}\n </MenuListContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins.\n style:\n point !== null\n ? (s) => ({ ...pointStyle(point, sideOption === null), ...resolveStateValue(style, s) })\n : placement.style(style),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;AAwHvC,MAAM,qBACJ;;;;;;;;;;;;;;;;;;;;;;;;;AA0BF,SAAgB,UAAU,EACxB,MAAM,UACN,QAAQ,SACR,aACA,0BAA0B,OAC1B,YACA,WACA,OACA,UACA,QACA,GAAG,QACc;CACjB,MAAM,OAAO,eAAe,YAAY;CACxC,MAAM,EAAE,SAAS,SAAS,SAAS;CACnC,MAAM,MAAM,IAAI,UAAU;CAE1B,MAAM,kBAAkB,UAAU,KAAK,SAAS;CAGhD,MAAM,aAAa,aAAa,KAAA,IAAa,UAAU,eAAe,WAAY;CAElF,MAAM,QAAQ,KAAK,UAAU,SAAS,UAAU,KAAK,YAAY;CAGjE,MAAM,YAAY,qBAAqB;EACrC,MAHoB,UAAU,OAAO,OAAO;EAI5C;EACA,WAAW,UAAU,gBAAgB,KAAA;CACvC,CAAC;CACD,MAAM,EAAE,MAAM,OAAO,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,IACL;CAEN,MAAM,WAAW,MACf,qBAAC,iBAAD;EAAiB,OAAO;EAAxB,UAAA,CACG,YACA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC,CACpC;;CAGnB,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,OACE,UAAU,QACL,OAAO;GAAE,GAAG,WAAW,OAAO,eAAe,IAAI;GAAG,GAAG,kBAAkB,OAAO,CAAC;EAAE,KACpF,UAAU,MAAM,KAAK;EAC3B,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,cAAc,YAAY,OAAO;AAChE;AAEA,UAAU,cAAc"}
|
|
@@ -1,9 +1,9 @@
|
|
|
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 { useRender } from "../internal/use-render.mjs";
|
|
5
5
|
import { transitionTypes } from "../internal/transition-types.mjs";
|
|
6
|
-
import { useControllableAction } from "../internal/use-controllable-action.mjs";
|
|
6
|
+
import { useControllableAction } from "../internal/action/use-controllable-action.mjs";
|
|
7
7
|
import { MenuGroupContext, MenuRadioGroupContext } from "./menu-context.mjs";
|
|
8
8
|
import { useId, useMemo, useRef } from "react";
|
|
9
9
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-radio-group.mjs","names":[],"sources":["../../src/menu/menu-radio-group.tsx"],"sourcesContent":["\"use client\";\nimport { useId, useMemo, 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 { useRender } from \"../internal/use-render.js\";\nimport { MenuGroupContext, MenuRadioGroupContext } from \"./menu-context.js\";\nimport type { MenuRadioGroupContextValue } from \"./menu-context.js\";\n\n/**\n * State of `Menu.RadioGroup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuRadioGroupState {\n /** Optimistic value; `null` when no item is selected. */\n readonly value: string | null;\n /** `valueChangeAction` is in flight. */\n readonly pending: boolean;\n}\n\n/**\n * Props of `Menu.RadioGroup`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuRadioGroupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"defaultValue\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled value; `null` selects nothing, `undefined` means uncontrolled. */\n value?: string | null;\n /**\n * Initial value when uncontrolled.\n *\n * @defaultValue `null`\n */\n defaultValue?: string | null;\n /**\n * Receives the chosen item's `value`, awaited inside the group's transition; the items'\n * `aria-checked` follow at once and roll back on rejection. Re-activating the selected item\n * dispatches nothing. May be a Server Function.\n */\n valueChangeAction?: ChangeAction<string>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuRadioGroupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuRadioGroupState>;\n /** The RadioItems and a GroupLabel. May be a function of the part's state. */\n children?: StateValue<ReactNode, MenuRadioGroupState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuRadioGroupState>;\n}\n\n/**\n * The state owner of a set of `Menu.RadioItem`s: `<div role=\"group\" aria-labelledby>` (named by\n * a `Menu.GroupLabel` inside it). Emits `data-pending` while `valueChangeAction` runs.\n *\n * Owned keys (conventions 1.2): `role`, `aria-labelledby` (token-merged), `data-pending`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuRadioGroup({\n value,\n defaultValue,\n valueChangeAction,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuRadioGroupProps) {\n const labelId = `${useId()}-label`;\n // The work to run after a dispatch's action resolved (an item's `closeOnActivate`), keyed by\n // the dispatch's details object.\n const after = useRef(new WeakMap<object, () => void>());\n\n const { optimistic, pending, dispatch } = useControllableAction<string | null>({\n controlled: value,\n defaultValue,\n initialValue: null,\n action: async (next, details) => {\n if (next !== null) await valueChangeAction?.(next, details);\n after.current.get(details)?.();\n },\n transitionTypes: () => transitionTypes(\"menu\", \"select\"),\n warn: { component: \"Menu.RadioGroup\", prop: \"value\" },\n });\n\n // Memoised: `dispatch` is stable.\n const context = useMemo<MenuRadioGroupContextValue>(\n () => ({\n value: optimistic,\n pending,\n select: (next, event, then) => {\n const details = createActionDetails(event, {});\n if (then !== undefined) after.current.set(details, then);\n dispatch(next, details);\n },\n }),\n [optimistic, pending, dispatch],\n );\n const groupContext = useMemo(() => ({ labelId }), [labelId]);\n\n const state: MenuRadioGroupState = { value: optimistic, pending };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuRadioGroupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n role: \"group\",\n \"aria-labelledby\": labelId,\n \"data-pending\": dataAttr(pending),\n },\n });\n\n return (\n <MenuGroupContext value={groupContext}>\n <MenuRadioGroupContext value={context}>{element}</MenuRadioGroupContext>\n </MenuGroupContext>\n );\n}\n\nMenuRadioGroup.displayName = \"MenuRadioGroup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgEA,SAAgB,eAAe,EAC7B,OACA,cACA,mBACA,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,UAAU,GAAG,MAAM,EAAE;CAG3B,MAAM,QAAQ,uBAAO,IAAI,QAA4B,CAAC;CAEtD,MAAM,EAAE,YAAY,SAAS,aAAa,sBAAqC;EAC7E,YAAY;EACZ;EACA,cAAc;EACd,QAAQ,OAAO,MAAM,YAAY;GAC/B,IAAI,SAAS,MAAM,MAAM,oBAAoB,MAAM,OAAO;GAC1D,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG;EAC/B;EACA,uBAAuB,gBAAgB,QAAQ,QAAQ;EACvD,MAAM;GAAE,WAAW;GAAmB,MAAM;EAAQ;CACtD,CAAC;CAGD,MAAM,UAAU,eACP;EACL,OAAO;EACP;EACA,SAAS,MAAM,OAAO,SAAS;GAC7B,MAAM,UAAU,oBAAoB,OAAO,CAAC,CAAC;GAC7C,IAAI,SAAS,KAAA,GAAW,MAAM,QAAQ,IAAI,SAAS,IAAI;GACvD,SAAS,MAAM,OAAO;EACxB;CACF,IACA;EAAC;EAAY;EAAS;CAAQ,CAChC;CACA,MAAM,eAAe,eAAe,EAAE,QAAQ,IAAI,CAAC,OAAO,CAAC;CAI3D,MAAM,UAAU,UAA6D;EAC3E,gBAAgB;EAChB;EACA,OAAA;GALmC,OAAO;GAAY;EAKlD;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,MAAM;GACN,mBAAmB;GACnB,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;CAED,OACE,oBAAC,kBAAD;EAAkB,OAAO;EACvB,UAAA,oBAAC,uBAAD;GAAuB,OAAO;GAAU,UAAA;EAA+B,CAAA;CACvD,CAAA;AAEtB;AAEA,eAAe,cAAc"}
|
|
1
|
+
{"version":3,"file":"menu-radio-group.mjs","names":[],"sources":["../../src/menu/menu-radio-group.tsx"],"sourcesContent":["\"use client\";\nimport { useId, useMemo, 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 { useRender } from \"../internal/use-render.js\";\nimport { MenuGroupContext, MenuRadioGroupContext } from \"./menu-context.js\";\nimport type { MenuRadioGroupContextValue } from \"./menu-context.js\";\n\n/**\n * State of `Menu.RadioGroup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuRadioGroupState {\n /** Optimistic value; `null` when no item is selected. */\n readonly value: string | null;\n /** `valueChangeAction` is in flight. */\n readonly pending: boolean;\n}\n\n/**\n * Props of `Menu.RadioGroup`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuRadioGroupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"defaultValue\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled value; `null` selects nothing, `undefined` means uncontrolled. */\n value?: string | null;\n /**\n * Initial value when uncontrolled.\n *\n * @defaultValue `null`\n */\n defaultValue?: string | null;\n /**\n * Receives the chosen item's `value`, awaited inside the group's transition; the items'\n * `aria-checked` follow at once and roll back on rejection. Re-activating the selected item\n * dispatches nothing. May be a Server Function.\n */\n valueChangeAction?: ChangeAction<string>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuRadioGroupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuRadioGroupState>;\n /** The RadioItems and a GroupLabel. May be a function of the part's state. */\n children?: StateValue<ReactNode, MenuRadioGroupState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuRadioGroupState>;\n}\n\n/**\n * The state owner of a set of `Menu.RadioItem`s: `<div role=\"group\" aria-labelledby>` (named by\n * a `Menu.GroupLabel` inside it). Emits `data-pending` while `valueChangeAction` runs.\n *\n * Owned keys (conventions 1.2): `role`, `aria-labelledby` (token-merged), `data-pending`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuRadioGroup({\n value,\n defaultValue,\n valueChangeAction,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuRadioGroupProps) {\n const labelId = `${useId()}-label`;\n // The work to run after a dispatch's action resolved (an item's `closeOnActivate`), keyed by\n // the dispatch's details object.\n const after = useRef(new WeakMap<object, () => void>());\n\n const { optimistic, pending, dispatch } = useControllableAction<string | null>({\n controlled: value,\n defaultValue,\n initialValue: null,\n action: async (next, details) => {\n if (next !== null) await valueChangeAction?.(next, details);\n after.current.get(details)?.();\n },\n transitionTypes: () => transitionTypes(\"menu\", \"select\"),\n warn: { component: \"Menu.RadioGroup\", prop: \"value\" },\n });\n\n // Memoised: `dispatch` is stable.\n const context = useMemo<MenuRadioGroupContextValue>(\n () => ({\n value: optimistic,\n pending,\n select: (next, event, then) => {\n const details = createActionDetails(event, {});\n if (then !== undefined) after.current.set(details, then);\n dispatch(next, details);\n },\n }),\n [optimistic, pending, dispatch],\n );\n const groupContext = useMemo(() => ({ labelId }), [labelId]);\n\n const state: MenuRadioGroupState = { value: optimistic, pending };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuRadioGroupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n role: \"group\",\n \"aria-labelledby\": labelId,\n \"data-pending\": dataAttr(pending),\n },\n });\n\n return (\n <MenuGroupContext value={groupContext}>\n <MenuRadioGroupContext value={context}>{element}</MenuRadioGroupContext>\n </MenuGroupContext>\n );\n}\n\nMenuRadioGroup.displayName = \"MenuRadioGroup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgEA,SAAgB,eAAe,EAC7B,OACA,cACA,mBACA,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,UAAU,GAAG,MAAM,EAAE;CAG3B,MAAM,QAAQ,uBAAO,IAAI,QAA4B,CAAC;CAEtD,MAAM,EAAE,YAAY,SAAS,aAAa,sBAAqC;EAC7E,YAAY;EACZ;EACA,cAAc;EACd,QAAQ,OAAO,MAAM,YAAY;GAC/B,IAAI,SAAS,MAAM,MAAM,oBAAoB,MAAM,OAAO;GAC1D,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG;EAC/B;EACA,uBAAuB,gBAAgB,QAAQ,QAAQ;EACvD,MAAM;GAAE,WAAW;GAAmB,MAAM;EAAQ;CACtD,CAAC;CAGD,MAAM,UAAU,eACP;EACL,OAAO;EACP;EACA,SAAS,MAAM,OAAO,SAAS;GAC7B,MAAM,UAAU,oBAAoB,OAAO,CAAC,CAAC;GAC7C,IAAI,SAAS,KAAA,GAAW,MAAM,QAAQ,IAAI,SAAS,IAAI;GACvD,SAAS,MAAM,OAAO;EACxB;CACF,IACA;EAAC;EAAY;EAAS;CAAQ,CAChC;CACA,MAAM,eAAe,eAAe,EAAE,QAAQ,IAAI,CAAC,OAAO,CAAC;CAI3D,MAAM,UAAU,UAA6D;EAC3E,gBAAgB;EAChB;EACA,OAAA;GALmC,OAAO;GAAY;EAKlD;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,MAAM;GACN,mBAAmB;GACnB,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;CAED,OACE,oBAAC,kBAAD;EAAkB,OAAO;EACvB,UAAA,oBAAC,uBAAD;GAAuB,OAAO;GAAU,UAAA;EAA+B,CAAA;CACvD,CAAA;AAEtB;AAEA,eAAe,cAAc"}
|
package/dist/menu/menu-root.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
3
3
|
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
4
4
|
import { useDelayedPair } from "../internal/use-delayed-pair.mjs";
|
|
5
|
-
import { popoverDetails,
|
|
5
|
+
import { popoverDetails, usePopoverRoot } from "../internal/overlay/use-overlay-root.mjs";
|
|
6
6
|
import { ANCHOR_PLACEMENT, MenuContext, MenuListContext, MenuRegionContext } from "./menu-context.mjs";
|
|
7
7
|
import { isRtl } from "./menu-dom.mjs";
|
|
8
8
|
import { use, useCallback, useMemo, useRef, useState } from "react";
|
|
@@ -39,7 +39,7 @@ function MenuRoot({ open, defaultOpen, openChangeAction, onOpenChange, loop = tr
|
|
|
39
39
|
const [placement, setPlacement] = useState(ANCHOR_PLACEMENT);
|
|
40
40
|
const placementGeneration = useRef(0);
|
|
41
41
|
const pointDispatch = useRef(false);
|
|
42
|
-
const popover =
|
|
42
|
+
const popover = usePopoverRoot({
|
|
43
43
|
component: "menu",
|
|
44
44
|
part: "Menu.Root",
|
|
45
45
|
mode: "library",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-root.mjs","names":[],"sources":["../../src/menu/menu-root.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { useDelayedPair } from \"../internal/use-delayed-pair.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { popoverDetails, useOverlayRoot } from \"../internal/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport {\n ANCHOR_PLACEMENT,\n MenuContext,\n MenuListContext,\n MenuRegionContext,\n} from \"./menu-context.js\";\nimport type {\n MenuContextValue,\n MenuOpenAtOptions,\n MenuOpenFocus,\n MenuPlacement,\n} from \"./menu-context.js\";\nimport { isRtl } from \"./menu-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed as the second argument of `Menu.Root`'s `openChangeAction` and `onOpenChange`. */\nexport interface MenuOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,\n * arrow keys), an item's activation (the close after its action), ArrowLeft in a submenu, or a\n * foreign invoker.\n * `\"dismiss\"`: Escape, a click outside, Tab or focus leaving the menu, the pointer leaving a\n * hover-opened submenu, the parent menu closing (a submenu when the whole stack closes), script.\n * `\"platform\"`: the menu was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\n/** State of `Menu.Root`, passed to the function forms of `children`. */\nexport interface MenuRootState {\n /** Optimistic open state. Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An open or close of this Root is in flight (its `openChangeAction`). */\n readonly pending: boolean;\n /** This Root is a submenu (rendered inside a `Menu.Popup`). */\n readonly submenu: boolean;\n /**\n * The current open (optimistic) came from a `Menu.ContextTrigger`: the menu is placed at the\n * pointer rather than against the Trigger.\n */\n readonly context: boolean;\n}\n\n/**\n * Props of `Menu.Root`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuRootProps {\n /**\n * Controlled open state. `undefined` means uncontrolled. A controlled Root needs\n * `onOpenChange` too: the browser closes the menu without asking (development warns).\n */\n open?: boolean;\n /** Initial open state when uncontrolled. Opens after hydration. */\n defaultOpen?: boolean;\n /**\n * Requests only. Awaited for `true` (the menu opens when it resolves and the items have\n * rendered) and for the closes the user asks a part for (Trigger toggle, an item's activation,\n * ArrowLeft in a submenu, the pointer leaving a hover-opened submenu). Never called for a\n * dismissal: that goes to `onOpenChange`. May be a Server Function. A `setState` placed after\n * your own `await` needs `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;\n /**\n * Facts only: the menu was closed without the library closing it on request (Escape, a click\n * outside, Tab or focus leaving the menu, a right-click outside, a scroll under a context\n * menu, the parent menu closing a submenu, a foreign invoker, script). Always `false`. Called\n * synchronously in the platform's `toggle` event, outside any Transition, and not awaited:\n * nothing is pending and no view transition runs.\n *\n * Controlled: set your state **directly** here (`onOpenChange={setOpen}`), not in\n * `startTransition` and not after an `await`; a parent that keeps `open={true}` gets the menu\n * re-opened at once. May return a promise; a rejection or a throw goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, MenuOpenChangeDetails>;\n /**\n * Arrow keys wrap from the last item to the first and back.\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /**\n * Submenu only: milliseconds from hovering the SubmenuTrigger to the open.\n *\n * @defaultValue `100`\n */\n delay?: number;\n /**\n * Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the\n * close.\n *\n * @defaultValue `150`\n */\n closeDelay?: number;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, MenuRootState>;\n}\n\nconst DEFAULT_FOCUS: MenuOpenFocus = { cause: \"first\", pointer: false };\n\n/**\n * Owns the ids, the open state and the context of one menu level. Renders no DOM. A `Menu.Root`\n * rendered inside a `Menu.Popup` is a **submenu**: its Trigger is a `Menu.SubmenuTrigger` (an\n * item of the parent menu) and its Popup opens beside that item.\n *\n * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a\n * part asks for are requests, transitions through `openChangeAction` (pending Trigger, items\n * render from committed state, `showPopover()` / `hidePopover()` once the change has committed);\n * dismissals are the browser's facts, reported to `onOpenChange`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuRoot({\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n loop = true,\n delay,\n closeDelay,\n children,\n}: MenuRootProps) {\n const parent = use(MenuContext);\n const list = use(MenuListContext);\n // A Root inside a Popup's content is a submenu (design 1); the enclosing menu is the Popup's.\n const parentMenu = list !== null ? list.menu : null;\n const submenu = parentMenu !== null;\n\n useDevWarning(\n !submenu && (delay !== undefined || closeDelay !== undefined),\n isDev &&\n \"Menu.Root: `delay` and `closeDelay` only apply to a submenu (a Menu.Root inside a \" +\n \"Menu.Popup); a top-level menu does not open on hover.\",\n );\n const inRegion = use(MenuRegionContext);\n useDevWarning(\n parent !== null && !submenu && !inRegion,\n isDev &&\n \"Menu.Root: rendered inside another Menu.Root but outside its Menu.Popup. A submenu's Root \" +\n \"goes inside the parent's Menu.Popup.\",\n );\n\n const timers = useDelayedPair();\n // The cause recorded by the part about to dispatch an open, and the cause of the open being\n // shown (design 14, \"Open cause\").\n const nextCause = useRef<MenuOpenFocus | null>(null);\n const openCause = useRef<MenuOpenFocus | null>(null);\n\n // Placement of the current open (context-menu.md 3.1). Written urgently, not in a transition:\n // while closed it renders nothing visible, and a move of an open menu (4.3) answers the\n // right-click at once, where a transition would be entangled with any pending async action\n // (an item's, the open's) and the menu would stay at the old point until it settled.\n const [placement, setPlacement] = useState<MenuPlacement>(ANCHOR_PLACEMENT);\n const placementGeneration = useRef(0);\n // Set by `openAt` around its `requestOpen`: the dispatch is a point open.\n const pointDispatch = useRef(false);\n\n const popover = useOverlayRoot<MenuOpenChangeDetails>({\n component: \"menu\",\n part: \"Menu.Root\",\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: popoverDetails,\n onDispatch: (next) => {\n // Any dispatch cancels hover intent (design walkthrough 9).\n timers.cancel();\n if (next) openCause.current = nextCause.current ?? DEFAULT_FOCUS;\n nextCause.current = null;\n // Every other open (Trigger, foreign invoker, mount reconciliation) is anchored.\n if (next && !pointDispatch.current) setPlacement(ANCHOR_PLACEMENT);\n },\n });\n\n const { intended, requestOpen, popupRef } = popover;\n const openAt = useCallback(\n (point: { readonly x: number; readonly y: number }, options: MenuOpenAtOptions) => {\n const generation = ++placementGeneration.current;\n // The popup's direction picks the edge at the point (context-menu.md 4.6, conventions\n // 13.4): the popup element exists while closed and `direction` is inherited, so it\n // computes without a box. Stored, so the Popup's style stays a function of state.\n const popup = popupRef.current;\n setPlacement({\n kind: \"point\",\n x: point.x,\n y: point.y,\n generation,\n source: options.source,\n pointerId: options.pointerId,\n direction: popup !== null && isRtl(popup) ? \"rtl\" : \"ltr\",\n // A touch or pen open is placed above the finger (4.7); re-evaluated on every move.\n offset: options.offset,\n });\n const focus: MenuOpenFocus = { cause: \"first\", pointer: options.pointer };\n if (intended()) {\n // A move, or a right-click while the open is still pending: no dispatch. The re-show\n // (or the open being shown) focuses the first item by this event's modality.\n openCause.current = focus;\n return;\n }\n nextCause.current = focus;\n pointDispatch.current = true;\n try {\n requestOpen(options.event, \"activate\");\n } finally {\n pointDispatch.current = false;\n }\n },\n [intended, requestOpen, popupRef],\n );\n const resetPlacement = useCallback((generation: number) => {\n setPlacement((current) =>\n current.kind === \"point\" && current.generation === generation ? ANCHOR_PLACEMENT : current,\n );\n }, []);\n\n const setOpenCause = useCallback((cause: MenuOpenFocus[\"cause\"], pointer = false) => {\n nextCause.current = { cause, pointer };\n }, []);\n const takeOpenCause = useCallback(() => {\n const cause = openCause.current ?? DEFAULT_FOCUS;\n openCause.current = null;\n return cause;\n }, []);\n\n const resolvedDelay = delay ?? 100;\n const resolvedCloseDelay = closeDelay ?? 150;\n // `popover` is memoised by `useOverlayRoot` and the other members are stable, so this\n // changes only with the open state, pending and the props listed below.\n const value = useMemo<MenuContextValue>(() => {\n const self: MenuContextValue = {\n popover,\n submenu,\n // The top-level menu: this one, or the parent's root (design 2.2).\n get root() {\n return parentMenu?.root ?? self;\n },\n parent: parentMenu,\n loop,\n delay: resolvedDelay,\n closeDelay: resolvedCloseDelay,\n triggerId: `${popover.ids.popup}-trigger`,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n };\n return self;\n }, [\n popover,\n submenu,\n parentMenu,\n loop,\n resolvedDelay,\n resolvedCloseDelay,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n ]);\n\n const state: MenuRootState = {\n open: popover.optimistic,\n pending: popover.pending,\n submenu,\n context: popover.optimistic && placement.kind === \"point\",\n };\n\n return <MenuContext value={value}>{resolveStateValue(children, state)}</MenuContext>;\n}\n\nMenuRoot.displayName = \"MenuRoot\";\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAuFvC,MAAM,gBAA+B;CAAE,OAAO;CAAS,SAAS;AAAM;;;;;;;;;;;;;AActE,SAAgB,SAAS,EACvB,MACA,aACA,kBACA,cACA,OAAO,MACP,OACA,YACA,YACgB;CAChB,MAAM,SAAS,IAAI,WAAW;CAC9B,MAAM,OAAO,IAAI,eAAe;CAEhC,MAAM,aAAa,SAAS,OAAO,KAAK,OAAO;CAC/C,MAAM,UAAU,eAAe;CAE/B,cACE,CAAC,YAAY,UAAU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,SAAS,WAAW,QAAQ,eAAe,aAAa,mBAAmB,OACrF;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,eAAe,aAAa,OAA+B,UAAU,UAAU;EACnF,UAAU,UAAU;GAAE;GAAO;EAAQ;CACvC,GAAG,CAAC,CAAC;CACL,MAAM,gBAAgB,kBAAkB;EACtC,MAAM,QAAQ,UAAU,WAAW;EACnC,UAAU,UAAU;EACpB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,SAAS;CAC/B,MAAM,qBAAqB,cAAc;CAGzC,MAAM,QAAQ,cAAgC;EAC5C,MAAM,OAAyB;GAC7B;GACA;GAEA,IAAI,OAAO;IACT,OAAO,YAAY,QAAQ;GAC7B;GACA,QAAQ;GACR;GACA,OAAO;GACP,YAAY;GACZ,WAAW,GAAG,QAAQ,IAAI,MAAM;GAChC;GACA;GACA;GACA;GACA;GACA;EACF;EACA,OAAO;CACT,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;EACA,SAAS,QAAQ,cAAc,UAAU,SAAS;CACpD;CAEA,OAAO,oBAAC,aAAD;EAAoB;EAAQ,UAAA,kBAAkB,UAAU,KAAK;CAAe,CAAA;AACrF;AAEA,SAAS,cAAc"}
|
|
1
|
+
{"version":3,"file":"menu-root.mjs","names":[],"sources":["../../src/menu/menu-root.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { useDelayedPair } from \"../internal/use-delayed-pair.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { popoverDetails, usePopoverRoot } from \"../internal/overlay/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport {\n ANCHOR_PLACEMENT,\n MenuContext,\n MenuListContext,\n MenuRegionContext,\n} from \"./menu-context.js\";\nimport type {\n MenuContextValue,\n MenuOpenAtOptions,\n MenuOpenFocus,\n MenuPlacement,\n} from \"./menu-context.js\";\nimport { isRtl } from \"./menu-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed as the second argument of `Menu.Root`'s `openChangeAction` and `onOpenChange`. */\nexport interface MenuOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,\n * arrow keys), an item's activation (the close after its action), ArrowLeft in a submenu, or a\n * foreign invoker.\n * `\"dismiss\"`: Escape, a click outside, Tab or focus leaving the menu, the pointer leaving a\n * hover-opened submenu, the parent menu closing (a submenu when the whole stack closes), script.\n * `\"platform\"`: the menu was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\n/** State of `Menu.Root`, passed to the function forms of `children`. */\nexport interface MenuRootState {\n /** Optimistic open state. Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An open or close of this Root is in flight (its `openChangeAction`). */\n readonly pending: boolean;\n /** This Root is a submenu (rendered inside a `Menu.Popup`). */\n readonly submenu: boolean;\n /**\n * The current open (optimistic) came from a `Menu.ContextTrigger`: the menu is placed at the\n * pointer rather than against the Trigger.\n */\n readonly context: boolean;\n}\n\n/**\n * Props of `Menu.Root`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuRootProps {\n /**\n * Controlled open state. `undefined` means uncontrolled. A controlled Root needs\n * `onOpenChange` too: the browser closes the menu without asking (development warns).\n */\n open?: boolean;\n /** Initial open state when uncontrolled. Opens after hydration. */\n defaultOpen?: boolean;\n /**\n * Requests only. Awaited for `true` (the menu opens when it resolves and the items have\n * rendered) and for the closes the user asks a part for (Trigger toggle, an item's activation,\n * ArrowLeft in a submenu, the pointer leaving a hover-opened submenu). Never called for a\n * dismissal: that goes to `onOpenChange`. May be a Server Function. A `setState` placed after\n * your own `await` needs `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;\n /**\n * Facts only: the menu was closed without the library closing it on request (Escape, a click\n * outside, Tab or focus leaving the menu, a right-click outside, a scroll under a context\n * menu, the parent menu closing a submenu, a foreign invoker, script). Always `false`. Called\n * synchronously in the platform's `toggle` event, outside any Transition, and not awaited:\n * nothing is pending and no view transition runs.\n *\n * Controlled: set your state **directly** here (`onOpenChange={setOpen}`), not in\n * `startTransition` and not after an `await`; a parent that keeps `open={true}` gets the menu\n * re-opened at once. May return a promise; a rejection or a throw goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, MenuOpenChangeDetails>;\n /**\n * Arrow keys wrap from the last item to the first and back.\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /**\n * Submenu only: milliseconds from hovering the SubmenuTrigger to the open.\n *\n * @defaultValue `100`\n */\n delay?: number;\n /**\n * Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the\n * close.\n *\n * @defaultValue `150`\n */\n closeDelay?: number;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, MenuRootState>;\n}\n\nconst DEFAULT_FOCUS: MenuOpenFocus = { cause: \"first\", pointer: false };\n\n/**\n * Owns the ids, the open state and the context of one menu level. Renders no DOM. A `Menu.Root`\n * rendered inside a `Menu.Popup` is a **submenu**: its Trigger is a `Menu.SubmenuTrigger` (an\n * item of the parent menu) and its Popup opens beside that item.\n *\n * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a\n * part asks for are requests, transitions through `openChangeAction` (pending Trigger, items\n * render from committed state, `showPopover()` / `hidePopover()` once the change has committed);\n * dismissals are the browser's facts, reported to `onOpenChange`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuRoot({\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n loop = true,\n delay,\n closeDelay,\n children,\n}: MenuRootProps) {\n const parent = use(MenuContext);\n const list = use(MenuListContext);\n // A Root inside a Popup's content is a submenu (design 1); the enclosing menu is the Popup's.\n const parentMenu = list !== null ? list.menu : null;\n const submenu = parentMenu !== null;\n\n useDevWarning(\n !submenu && (delay !== undefined || closeDelay !== undefined),\n isDev &&\n \"Menu.Root: `delay` and `closeDelay` only apply to a submenu (a Menu.Root inside a \" +\n \"Menu.Popup); a top-level menu does not open on hover.\",\n );\n const inRegion = use(MenuRegionContext);\n useDevWarning(\n parent !== null && !submenu && !inRegion,\n isDev &&\n \"Menu.Root: rendered inside another Menu.Root but outside its Menu.Popup. A submenu's Root \" +\n \"goes inside the parent's Menu.Popup.\",\n );\n\n const timers = useDelayedPair();\n // The cause recorded by the part about to dispatch an open, and the cause of the open being\n // shown (design 14, \"Open cause\").\n const nextCause = useRef<MenuOpenFocus | null>(null);\n const openCause = useRef<MenuOpenFocus | null>(null);\n\n // Placement of the current open (context-menu.md 3.1). Written urgently, not in a transition:\n // while closed it renders nothing visible, and a move of an open menu (4.3) answers the\n // right-click at once, where a transition would be entangled with any pending async action\n // (an item's, the open's) and the menu would stay at the old point until it settled.\n const [placement, setPlacement] = useState<MenuPlacement>(ANCHOR_PLACEMENT);\n const placementGeneration = useRef(0);\n // Set by `openAt` around its `requestOpen`: the dispatch is a point open.\n const pointDispatch = useRef(false);\n\n const popover = usePopoverRoot<MenuOpenChangeDetails>({\n component: \"menu\",\n part: \"Menu.Root\",\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: popoverDetails,\n onDispatch: (next) => {\n // Any dispatch cancels hover intent (design walkthrough 9).\n timers.cancel();\n if (next) openCause.current = nextCause.current ?? DEFAULT_FOCUS;\n nextCause.current = null;\n // Every other open (Trigger, foreign invoker, mount reconciliation) is anchored.\n if (next && !pointDispatch.current) setPlacement(ANCHOR_PLACEMENT);\n },\n });\n\n const { intended, requestOpen, popupRef } = popover;\n const openAt = useCallback(\n (point: { readonly x: number; readonly y: number }, options: MenuOpenAtOptions) => {\n const generation = ++placementGeneration.current;\n // The popup's direction picks the edge at the point (context-menu.md 4.6, conventions\n // 13.4): the popup element exists while closed and `direction` is inherited, so it\n // computes without a box. Stored, so the Popup's style stays a function of state.\n const popup = popupRef.current;\n setPlacement({\n kind: \"point\",\n x: point.x,\n y: point.y,\n generation,\n source: options.source,\n pointerId: options.pointerId,\n direction: popup !== null && isRtl(popup) ? \"rtl\" : \"ltr\",\n // A touch or pen open is placed above the finger (4.7); re-evaluated on every move.\n offset: options.offset,\n });\n const focus: MenuOpenFocus = { cause: \"first\", pointer: options.pointer };\n if (intended()) {\n // A move, or a right-click while the open is still pending: no dispatch. The re-show\n // (or the open being shown) focuses the first item by this event's modality.\n openCause.current = focus;\n return;\n }\n nextCause.current = focus;\n pointDispatch.current = true;\n try {\n requestOpen(options.event, \"activate\");\n } finally {\n pointDispatch.current = false;\n }\n },\n [intended, requestOpen, popupRef],\n );\n const resetPlacement = useCallback((generation: number) => {\n setPlacement((current) =>\n current.kind === \"point\" && current.generation === generation ? ANCHOR_PLACEMENT : current,\n );\n }, []);\n\n const setOpenCause = useCallback((cause: MenuOpenFocus[\"cause\"], pointer = false) => {\n nextCause.current = { cause, pointer };\n }, []);\n const takeOpenCause = useCallback(() => {\n const cause = openCause.current ?? DEFAULT_FOCUS;\n openCause.current = null;\n return cause;\n }, []);\n\n const resolvedDelay = delay ?? 100;\n const resolvedCloseDelay = closeDelay ?? 150;\n // `popover` is memoised by `usePopoverRoot` and the other members are stable, so this\n // changes only with the open state, pending and the props listed below.\n const value = useMemo<MenuContextValue>(() => {\n const self: MenuContextValue = {\n popover,\n submenu,\n // The top-level menu: this one, or the parent's root (design 2.2).\n get root() {\n return parentMenu?.root ?? self;\n },\n parent: parentMenu,\n loop,\n delay: resolvedDelay,\n closeDelay: resolvedCloseDelay,\n triggerId: `${popover.ids.popup}-trigger`,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n };\n return self;\n }, [\n popover,\n submenu,\n parentMenu,\n loop,\n resolvedDelay,\n resolvedCloseDelay,\n setOpenCause,\n takeOpenCause,\n timers,\n placement,\n openAt,\n resetPlacement,\n ]);\n\n const state: MenuRootState = {\n open: popover.optimistic,\n pending: popover.pending,\n submenu,\n context: popover.optimistic && placement.kind === \"point\",\n };\n\n return <MenuContext value={value}>{resolveStateValue(children, state)}</MenuContext>;\n}\n\nMenuRoot.displayName = \"MenuRoot\";\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAuFvC,MAAM,gBAA+B;CAAE,OAAO;CAAS,SAAS;AAAM;;;;;;;;;;;;;AActE,SAAgB,SAAS,EACvB,MACA,aACA,kBACA,cACA,OAAO,MACP,OACA,YACA,YACgB;CAChB,MAAM,SAAS,IAAI,WAAW;CAC9B,MAAM,OAAO,IAAI,eAAe;CAEhC,MAAM,aAAa,SAAS,OAAO,KAAK,OAAO;CAC/C,MAAM,UAAU,eAAe;CAE/B,cACE,CAAC,YAAY,UAAU,KAAA,KAAa,eAAe,KAAA,IACnD,SACE,yIAEJ;CACA,MAAM,WAAW,IAAI,iBAAiB;CACtC,cACE,WAAW,QAAQ,CAAC,WAAW,CAAC,UAChC,SACE,gIAEJ;CAEA,MAAM,SAAS,eAAe;CAG9B,MAAM,YAAY,OAA6B,IAAI;CACnD,MAAM,YAAY,OAA6B,IAAI;CAMnD,MAAM,CAAC,WAAW,gBAAgB,SAAwB,gBAAgB;CAC1E,MAAM,sBAAsB,OAAO,CAAC;CAEpC,MAAM,gBAAgB,OAAO,KAAK;CAElC,MAAM,UAAU,eAAsC;EACpD,WAAW;EACX,MAAM;EACN,MAAM;EACN;EACA;EACA;EACA;EACA,SAAS;EACT,aAAa,SAAS;GAEpB,OAAO,OAAO;GACd,IAAI,MAAM,UAAU,UAAU,UAAU,WAAW;GACnD,UAAU,UAAU;GAEpB,IAAI,QAAQ,CAAC,cAAc,SAAS,aAAa,gBAAgB;EAC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G;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;EACA,SAAS,QAAQ,cAAc,UAAU,SAAS;CACpD;CAEA,OAAO,oBAAC,aAAD;EAAoB;EAAQ,UAAA,kBAAkB,UAAU,KAAK;CAAe,CAAA;AACrF;AAEA,SAAS,cAAc"}
|
|
@@ -3,7 +3,7 @@ import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
|
3
3
|
import { useRender } from "../internal/use-render.mjs";
|
|
4
4
|
import { useLatest } from "../internal/use-latest.mjs";
|
|
5
5
|
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
6
|
-
import { usePopoverTrigger } from "../internal/use-popover-trigger.mjs";
|
|
6
|
+
import { usePopoverTrigger } from "../internal/overlay/use-popover-trigger.mjs";
|
|
7
7
|
import { registerSubmenuHover, useMenuContext } from "./menu-context.mjs";
|
|
8
8
|
import { hasModifier, isRtl } from "./menu-dom.mjs";
|
|
9
9
|
import { useMenuItem } from "./use-menu-item.mjs";
|
|
@@ -71,7 +71,7 @@ function MenuSubmenuTrigger({ disabled = false, label, className, style, childre
|
|
|
71
71
|
part: "Menu.SubmenuTrigger",
|
|
72
72
|
disabled,
|
|
73
73
|
render,
|
|
74
|
-
|
|
74
|
+
submenuItem: true,
|
|
75
75
|
handlers: {
|
|
76
76
|
onKeyDown: (event) => {
|
|
77
77
|
item.libraryProps.onKeyDown(event);
|
|
@@ -85,7 +85,7 @@ function MenuSubmenuTrigger({ disabled = false, label, className, style, childre
|
|
|
85
85
|
if (event.pointerType !== "touch") hoverLeave(event.nativeEvent);
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
|
|
88
|
+
onActivate: (event) => open(event.nativeEvent)
|
|
89
89
|
});
|
|
90
90
|
const ref = useMergedRefs(triggerRef, hoverRef);
|
|
91
91
|
return useRender({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-submenu-trigger.mjs","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { registerSubmenuHover, useMenuContext } from \"./menu-context.js\";\nimport { hasModifier, isRtl } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { openMenuWithFocus } from \"./menu-trigger.js\";\nimport type { MenuTriggerState } from \"./menu-trigger.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Menu.SubmenuTrigger`: the same shape as `MenuTriggerState` (`open` is the submenu's).\n */\nexport type MenuSubmenuTriggerState = MenuTriggerState;\n\n/**\n * Props of `Menu.SubmenuTrigger`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuSubmenuTriggerProps extends Omit<\n MenuItemProps,\n | \"action\"\n | \"closeOnActivate\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"commandfor\"\n | \"command\"\n | \"popoverTarget\"\n | \"popoverTargetAction\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"render\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuSubmenuTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuSubmenuTriggerState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>;\n}\n\n/**\n * The item that opens a submenu: an item of the parent menu (`role=\"menuitem\"`, roving\n * `tabindex`, typeahead) and the Trigger of the submenu's Root (`popovertarget`,\n * `aria-haspopup=\"menu\"`; no `aria-expanded`: the browser exposes the submenu's state on its\n * invoker). ArrowRight (ArrowLeft in RTL), Enter, Space or a click open the submenu with its first\n * item focused; hovering it opens the submenu after the Root's `delay` and leaves focus where it\n * is.\n *\n * Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `popoverTarget`, `aria-haspopup`,\n * `aria-expanded`, `data-open`, `data-pending`; `commandfor`, `command` and `popoverTargetAction`,\n * never written) and the item's (`role`, `tabIndex`, `disabled` (absent), `aria-disabled`,\n * `data-disabled`, `data-typeahead`, `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`,\n * `onPointerLeave`).\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuSubmenuTrigger({\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuSubmenuTriggerProps) {\n const menu = useMenuContext(\"Menu.SubmenuTrigger\");\n useDevWarning(\n !menu.submenu,\n isDev &&\n \"Menu.SubmenuTrigger: rendered in a top-level Menu.Root. Use Menu.Trigger, or put this Root \" +\n \"inside the parent's Menu.Popup.\",\n );\n\n const open = (event: Event) => openMenuWithFocus(menu, event, \"first\");\n\n // The item half: role, roving tabindex, aria-disabled, Enter / Space, pointer focus. Its\n // activation is the click, which the trigger half handles (`activate` below), so the item's own\n // `onClick` is not used.\n const item = useMenuItem({\n part: \"Menu.SubmenuTrigger\",\n role: \"menuitem\",\n disabled,\n label,\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.defaultPrevented || hasModifier(event) || disabled) return;\n const parentPopup = event.currentTarget.closest('[role=\"menu\"]');\n const forward = parentPopup !== null && isRtl(parentPopup) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== forward) return;\n event.preventDefault();\n open(event.nativeEvent);\n };\n\n // Hover intent (design/components/menu.md 7), shared by the pointer handlers and a\n // press-drag-release gesture of a context menu, whose captured pointer never enters this element\n // (context-menu.md 2.6).\n const hoverEnter = (native: Event) => {\n if (disabled) return;\n menu.timers.open(menu.delay, () => {\n menu.setOpenCause(\"none\");\n menu.popover.requestOpen(native, \"activate\");\n });\n };\n const hoverLeave = (native: Event) => {\n // Leaving before the open delay cancels it; leaving an open submenu's trigger starts the\n // close delay (cancelled by entering the submenu).\n if (menu.popover.intended()) scheduleHoverClose(menu, native);\n else menu.timers.cancel();\n };\n const submenuPopupRef = menu.popover.popupRef;\n const latestHover = useLatest({ enter: hoverEnter, leave: hoverLeave });\n const hoverRef = useCallback(\n (element: HTMLElement) =>\n registerSubmenuHover(element, {\n enter: (event) => latestHover.current.enter(event),\n leave: (event) => latestHover.current.leave(event),\n popup: () => submenuPopupRef.current,\n }),\n [latestHover, submenuPopupRef],\n );\n\n const {\n state,\n libraryProps,\n ref: triggerRef,\n } = usePopoverTrigger(menu.popover, {\n part: \"Menu.SubmenuTrigger\",\n disabled,\n render,\n
|
|
1
|
+
{"version":3,"file":"menu-submenu-trigger.mjs","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { usePopoverTrigger } from \"../internal/overlay/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { registerSubmenuHover, useMenuContext } from \"./menu-context.js\";\nimport { hasModifier, isRtl } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { openMenuWithFocus } from \"./menu-trigger.js\";\nimport type { MenuTriggerState } from \"./menu-trigger.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Menu.SubmenuTrigger`: the same shape as `MenuTriggerState` (`open` is the submenu's).\n */\nexport type MenuSubmenuTriggerState = MenuTriggerState;\n\n/**\n * Props of `Menu.SubmenuTrigger`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuSubmenuTriggerProps extends Omit<\n MenuItemProps,\n | \"action\"\n | \"closeOnActivate\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"commandfor\"\n | \"command\"\n | \"popoverTarget\"\n | \"popoverTargetAction\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"render\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuSubmenuTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuSubmenuTriggerState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>;\n}\n\n/**\n * The item that opens a submenu: an item of the parent menu (`role=\"menuitem\"`, roving\n * `tabindex`, typeahead) and the Trigger of the submenu's Root (`popovertarget`,\n * `aria-haspopup=\"menu\"`; no `aria-expanded`: the browser exposes the submenu's state on its\n * invoker). ArrowRight (ArrowLeft in RTL), Enter, Space or a click open the submenu with its first\n * item focused; hovering it opens the submenu after the Root's `delay` and leaves focus where it\n * is.\n *\n * Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `popoverTarget`, `aria-haspopup`,\n * `aria-expanded`, `data-open`, `data-pending`; `commandfor`, `command` and `popoverTargetAction`,\n * never written) and the item's (`role`, `tabIndex`, `disabled` (absent), `aria-disabled`,\n * `data-disabled`, `data-typeahead`, `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`,\n * `onPointerLeave`).\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuSubmenuTrigger({\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuSubmenuTriggerProps) {\n const menu = useMenuContext(\"Menu.SubmenuTrigger\");\n useDevWarning(\n !menu.submenu,\n isDev &&\n \"Menu.SubmenuTrigger: rendered in a top-level Menu.Root. Use Menu.Trigger, or put this Root \" +\n \"inside the parent's Menu.Popup.\",\n );\n\n const open = (event: Event) => openMenuWithFocus(menu, event, \"first\");\n\n // The item half: role, roving tabindex, aria-disabled, Enter / Space, pointer focus. Its\n // activation is the click, which the trigger half handles (`activate` below), so the item's own\n // `onClick` is not used.\n const item = useMenuItem({\n part: \"Menu.SubmenuTrigger\",\n role: \"menuitem\",\n disabled,\n label,\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.defaultPrevented || hasModifier(event) || disabled) return;\n const parentPopup = event.currentTarget.closest('[role=\"menu\"]');\n const forward = parentPopup !== null && isRtl(parentPopup) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== forward) return;\n event.preventDefault();\n open(event.nativeEvent);\n };\n\n // Hover intent (design/components/menu.md 7), shared by the pointer handlers and a\n // press-drag-release gesture of a context menu, whose captured pointer never enters this element\n // (context-menu.md 2.6).\n const hoverEnter = (native: Event) => {\n if (disabled) return;\n menu.timers.open(menu.delay, () => {\n menu.setOpenCause(\"none\");\n menu.popover.requestOpen(native, \"activate\");\n });\n };\n const hoverLeave = (native: Event) => {\n // Leaving before the open delay cancels it; leaving an open submenu's trigger starts the\n // close delay (cancelled by entering the submenu).\n if (menu.popover.intended()) scheduleHoverClose(menu, native);\n else menu.timers.cancel();\n };\n const submenuPopupRef = menu.popover.popupRef;\n const latestHover = useLatest({ enter: hoverEnter, leave: hoverLeave });\n const hoverRef = useCallback(\n (element: HTMLElement) =>\n registerSubmenuHover(element, {\n enter: (event) => latestHover.current.enter(event),\n leave: (event) => latestHover.current.leave(event),\n popup: () => submenuPopupRef.current,\n }),\n [latestHover, submenuPopupRef],\n );\n\n const {\n state,\n libraryProps,\n ref: triggerRef,\n } = usePopoverTrigger(menu.popover, {\n part: \"Menu.SubmenuTrigger\",\n disabled,\n render,\n submenuItem: true,\n // Item first (Enter / Space activation, pointer focus), then the submenu keys.\n handlers: {\n onKeyDown: (event) => {\n item.libraryProps.onKeyDown(event);\n onKeyDown(event);\n },\n onPointerMove: item.libraryProps.onPointerMove,\n onPointerEnter: (event: PointerEvent<HTMLButtonElement>) => {\n if (event.pointerType !== \"touch\") hoverEnter(event.nativeEvent);\n },\n onPointerLeave: (event: PointerEvent<HTMLButtonElement>) => {\n if (event.pointerType !== \"touch\") hoverLeave(event.nativeEvent);\n },\n },\n // A click opens (or moves focus into the open submenu); it never closes.\n onActivate: (event) => open(event.nativeEvent),\n });\n const ref = useMergedRefs(triggerRef, hoverRef);\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...libraryProps,\n role: item.libraryProps.role,\n tabIndex: item.libraryProps.tabIndex,\n \"data-typeahead\": item.libraryProps[\"data-typeahead\"],\n id: menu.triggerId,\n \"aria-haspopup\": \"menu\",\n },\n ref,\n });\n}\n\nMenuSubmenuTrigger.displayName = \"MenuSubmenuTrigger\";\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;AAuDvC,SAAgB,mBAAmB,EACjC,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,OAAO,eAA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AM,gBAAgB,SAAS,WAAW,MAAM,WAAW;GACjE;GACA,iBAAiB,UAA2C;IAC1D,IAAI,MAAM,gBAAgB,SAAS,WAAW,MAAM,WAAW;GACjE;EACF;EAEA,aAAa,UAAU,KAAK,MAAM,WAAW;CAC/C,CAAC;CACD,MAAM,MAAM,cAAc,YAAY,QAAQ;CAE9C,OAAO,UAAoE;EACzE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG;GACH,MAAM,KAAK,aAAa;GACxB,UAAU,KAAK,aAAa;GAC5B,kBAAkB,KAAK,aAAa;GACpC,IAAI,KAAK;GACT,iBAAiB;EACnB;EACA;CACF,CAAC;AACH;AAEA,mBAAmB,cAAc"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
-
import { PopoverTriggerHookState } from "../internal/use-popover-trigger.mjs";
|
|
2
|
+
import { PopoverTriggerHookState } from "../internal/overlay/use-popover-trigger.mjs";
|
|
3
3
|
import "./menu-context.mjs";
|
|
4
4
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
5
5
|
//#region src/menu/menu-trigger.d.ts
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { useToolbarContext } from "../internal/toolbar-context.mjs";
|
|
3
3
|
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
4
4
|
import { useRender } from "../internal/use-render.mjs";
|
|
5
|
-
import { isPopoverOpen } from "../internal/popover-open.mjs";
|
|
6
|
-
import { usePopoverTrigger } from "../internal/use-popover-trigger.mjs";
|
|
5
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
6
|
+
import { toggleFromTrigger, usePopoverTrigger } from "../internal/overlay/use-popover-trigger.mjs";
|
|
7
7
|
import { useMenuContext } from "./menu-context.mjs";
|
|
8
8
|
import { edgeItem, focusItem, hasModifier, isRtl } from "./menu-dom.mjs";
|
|
9
9
|
//#region src/menu/menu-trigger.tsx
|
|
@@ -72,7 +72,7 @@ function MenuTrigger({ disabled = false, className, style, children, render, ...
|
|
|
72
72
|
if (event.button === 0 && menu.popover.intended()) event.preventDefault();
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
|
|
75
|
+
onActivate: (event) => toggleFromTrigger(menu.popover, event.nativeEvent, () => menu.setOpenCause("first", isPointerClick(event.nativeEvent)))
|
|
76
76
|
});
|
|
77
77
|
return useRender({
|
|
78
78
|
defaultElement: "button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-trigger.mjs","names":[],"sources":["../../src/menu/menu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n MouseEvent as ReactMouseEvent,\n ReactNode,\n} from \"react\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { useToolbarContext } from \"../internal/toolbar-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport type { PopoverTriggerHookState } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport type { MenuContextValue } from \"./menu-context.js\";\nimport { edgeItem, focusItem, hasModifier, isRtl } from \"./menu-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Menu.Trigger`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport type MenuTriggerState = PopoverTriggerHookState;\n\n/**\n * Props of `Menu.Trigger`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"onClick\"\n | \"onKeyDown\"\n | \"onMouseDown\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"commandfor\"\n | \"command\"\n | \"popoverTarget\"\n | \"popoverTargetAction\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * The menu cannot be opened from this button. Native `disabled` on a `<button>`; with a link or\n * component `render`, `aria-disabled=\"true\"` instead (the element stays focusable).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuTriggerState>;\n /**\n * Should render a `<button>` (the `popovertarget` path before hydration). Another element works\n * through the click handler, but a press on it while the menu is open is a light dismiss rather\n * than the awaited close.\n */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuTriggerState>;\n}\n\n/**\n * Opens with the first (`\"first\"`) or last (`\"last\"`) item focused, or focuses that item when the\n * menu is already open (a pre-hydration open, design walkthrough 10). Shared with SubmenuTrigger.\n */\nexport function openMenuWithFocus(\n menu: MenuContextValue,\n event: Event,\n which: \"first\" | \"last\",\n): void {\n const { popover } = menu;\n if (popover.intended()) {\n const popup = popover.popupRef.current;\n if (popup !== null && isPopoverOpen(popup)) {\n const item = edgeItem(popup, which);\n if (item !== null) focusItem(item);\n }\n return;\n }\n menu.setOpenCause(which, isPointerClick(event));\n popover.requestOpen(event, \"activate\");\n}\n\n/** A click from a pointing device (`detail` counts clicks; keyboard and `click()` give 0). */\nfunction isPointerClick(event: Event): boolean {\n return event.type === \"click\" && (event as MouseEvent).detail > 0;\n}\n\n/**\n * The menu button: `<button type=\"button\" popovertarget aria-haspopup=\"menu\">`, with no\n * `aria-expanded` (the browser exposes the menu's state on its invoker; a link or other non-button\n * element, or a disabled component `render`, renders it from the shown menu). A click (Enter,\n * Space) toggles the menu through the Root's transition; ArrowDown / ArrowUp open it with the\n * first / last item focused (inside a vertical `Toolbar.Root`: the inline-end arrow, with the\n * first item focused).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `id`, `disabled`, `aria-disabled`\n * (link or component `render`), `popoverTarget`, `aria-haspopup`, `aria-expanded`, `onClick`,\n * `onKeyDown`, `onMouseDown`, `data-open`, `data-pending`, `data-disabled`; `commandfor`,\n * `command` and `popoverTargetAction` (never written; omitted from the props type).\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuTrigger({\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuTriggerProps) {\n const menu = useMenuContext(\"Menu.Trigger\");\n useDevWarning(\n menu.submenu,\n isDev &&\n \"Menu.Trigger: rendered in a submenu. Use Menu.SubmenuTrigger, which is also an item of the \" +\n \"parent menu.\",\n );\n\n // Inside a vertical Toolbar, ArrowDown / ArrowUp are the Toolbar's: the trigger opens on the\n // inline-end arrow instead, as a submenu trigger does (design/components/toggle-group.md 7.4).\n const toolbar = useToolbarContext();\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (disabled || hasModifier(event)) return;\n let which: \"first\" | \"last\";\n if (toolbar?.orientation === \"vertical\") {\n const openKey = isRtl(event.currentTarget) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== openKey) return;\n which = \"first\";\n } else {\n if (event.key !== \"ArrowDown\" && event.key !== \"ArrowUp\") return;\n which = event.key === \"ArrowDown\" ? \"first\" : \"last\";\n }\n // No page scroll, and an enclosing Toolbar sees `defaultPrevented`; Enter and Space stay the\n // native click.\n event.preventDefault();\n openMenuWithFocus(menu, event.nativeEvent, which);\n };\n\n const { state, libraryProps, ref } = usePopoverTrigger(menu.popover, {\n part: \"Menu.Trigger\",\n disabled,\n render,\n handlers: {\n onKeyDown,\n onMouseDown: (event: ReactMouseEvent<HTMLButtonElement>) => {\n // A press on the Trigger of an open menu must not move focus out of the popup: the Popup's\n // focusout would hide the menu before the click's library-owned close (design 2.2).\n if (event.button === 0 && menu.popover.intended()) event.preventDefault();\n },\n },\n
|
|
1
|
+
{"version":3,"file":"menu-trigger.mjs","names":[],"sources":["../../src/menu/menu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n MouseEvent as ReactMouseEvent,\n ReactNode,\n} from \"react\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport { useToolbarContext } from \"../internal/toolbar-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { toggleFromTrigger, usePopoverTrigger } from \"../internal/overlay/use-popover-trigger.js\";\nimport type { PopoverTriggerHookState } from \"../internal/overlay/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport type { MenuContextValue } from \"./menu-context.js\";\nimport { edgeItem, focusItem, hasModifier, isRtl } from \"./menu-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Menu.Trigger`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport type MenuTriggerState = PopoverTriggerHookState;\n\n/**\n * Props of `Menu.Trigger`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"onClick\"\n | \"onKeyDown\"\n | \"onMouseDown\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"commandfor\"\n | \"command\"\n | \"popoverTarget\"\n | \"popoverTargetAction\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * The menu cannot be opened from this button. Native `disabled` on a `<button>`; with a link or\n * component `render`, `aria-disabled=\"true\"` instead (the element stays focusable).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuTriggerState>;\n /**\n * Should render a `<button>` (the `popovertarget` path before hydration). Another element works\n * through the click handler, but a press on it while the menu is open is a light dismiss rather\n * than the awaited close.\n */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuTriggerState>;\n}\n\n/**\n * Opens with the first (`\"first\"`) or last (`\"last\"`) item focused, or focuses that item when the\n * menu is already open (a pre-hydration open, design walkthrough 10). Shared with SubmenuTrigger.\n */\nexport function openMenuWithFocus(\n menu: MenuContextValue,\n event: Event,\n which: \"first\" | \"last\",\n): void {\n const { popover } = menu;\n if (popover.intended()) {\n const popup = popover.popupRef.current;\n if (popup !== null && isPopoverOpen(popup)) {\n const item = edgeItem(popup, which);\n if (item !== null) focusItem(item);\n }\n return;\n }\n menu.setOpenCause(which, isPointerClick(event));\n popover.requestOpen(event, \"activate\");\n}\n\n/** A click from a pointing device (`detail` counts clicks; keyboard and `click()` give 0). */\nfunction isPointerClick(event: Event): boolean {\n return event.type === \"click\" && (event as MouseEvent).detail > 0;\n}\n\n/**\n * The menu button: `<button type=\"button\" popovertarget aria-haspopup=\"menu\">`, with no\n * `aria-expanded` (the browser exposes the menu's state on its invoker; a link or other non-button\n * element, or a disabled component `render`, renders it from the shown menu). A click (Enter,\n * Space) toggles the menu through the Root's transition; ArrowDown / ArrowUp open it with the\n * first / last item focused (inside a vertical `Toolbar.Root`: the inline-end arrow, with the\n * first item focused).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `id`, `disabled`, `aria-disabled`\n * (link or component `render`), `popoverTarget`, `aria-haspopup`, `aria-expanded`, `onClick`,\n * `onKeyDown`, `onMouseDown`, `data-open`, `data-pending`, `data-disabled`; `commandfor`,\n * `command` and `popoverTargetAction` (never written; omitted from the props type).\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuTrigger({\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuTriggerProps) {\n const menu = useMenuContext(\"Menu.Trigger\");\n useDevWarning(\n menu.submenu,\n isDev &&\n \"Menu.Trigger: rendered in a submenu. Use Menu.SubmenuTrigger, which is also an item of the \" +\n \"parent menu.\",\n );\n\n // Inside a vertical Toolbar, ArrowDown / ArrowUp are the Toolbar's: the trigger opens on the\n // inline-end arrow instead, as a submenu trigger does (design/components/toggle-group.md 7.4).\n const toolbar = useToolbarContext();\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (disabled || hasModifier(event)) return;\n let which: \"first\" | \"last\";\n if (toolbar?.orientation === \"vertical\") {\n const openKey = isRtl(event.currentTarget) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== openKey) return;\n which = \"first\";\n } else {\n if (event.key !== \"ArrowDown\" && event.key !== \"ArrowUp\") return;\n which = event.key === \"ArrowDown\" ? \"first\" : \"last\";\n }\n // No page scroll, and an enclosing Toolbar sees `defaultPrevented`; Enter and Space stay the\n // native click.\n event.preventDefault();\n openMenuWithFocus(menu, event.nativeEvent, which);\n };\n\n const { state, libraryProps, ref } = usePopoverTrigger(menu.popover, {\n part: \"Menu.Trigger\",\n disabled,\n render,\n handlers: {\n onKeyDown,\n onMouseDown: (event: ReactMouseEvent<HTMLButtonElement>) => {\n // A press on the Trigger of an open menu must not move focus out of the popup: the Popup's\n // focusout would hide the menu before the click's library-owned close (design 2.2).\n if (event.button === 0 && menu.popover.intended()) event.preventDefault();\n },\n },\n // The default toggle, with the open cause recorded right before an open.\n onActivate: (event) =>\n toggleFromTrigger(menu.popover, event.nativeEvent, () =>\n menu.setOpenCause(\"first\", isPointerClick(event.nativeEvent)),\n ),\n });\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...libraryProps,\n id: menu.triggerId,\n \"aria-haspopup\": \"menu\",\n },\n ref,\n });\n}\n\nMenuTrigger.displayName = \"MenuTrigger\";\n"],"mappings":";;;;;;;;;AAmBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;AAqDvC,SAAgB,kBACd,MAC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;CACJ,CAAC;CAED,OAAO,UAA6D;EAClE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG;GACH,IAAI,KAAK;GACT,iBAAiB;EACnB;EACA;CACF,CAAC;AACH;AAEA,YAAY,cAAc"}
|
|
@@ -4,7 +4,7 @@ import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
|
4
4
|
import { useRender } from "../internal/use-render.mjs";
|
|
5
5
|
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
6
6
|
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
7
|
-
import { useFieldControl } from "../internal/use-field-control.mjs";
|
|
7
|
+
import { useFieldControl } from "../internal/form/use-field-control.mjs";
|
|
8
8
|
import { useNumberFieldContext } from "./number-field-context.mjs";
|
|
9
9
|
import { isValidElement, useCallback, useEffectEvent, useLayoutEffect, useRef } from "react";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-field-input.mjs","names":[],"sources":["../../src/number-field/number-field-input.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type {\n ChangeEvent,\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n Ref,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useFieldControl } from \"../internal/use-field-control.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport type { NumberFieldState } from \"./number-field-root.js\";\nimport { useNumberFieldContext } from \"./number-field-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Props of `NumberField.Input`.\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport interface NumberFieldInputProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"value\"\n | \"defaultValue\"\n | \"type\"\n | \"onChange\"\n | \"onKeyDown\"\n | \"onBlur\"\n | \"disabled\"\n | \"readOnly\"\n | \"required\"\n | \"name\"\n | \"form\"\n | \"min\"\n | \"max\"\n | \"step\"\n | \"pattern\"\n | \"aria-invalid\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The hidden native `<input type=\"number\">` rendered after the visible input. */\n hiddenInputRef?: Ref<HTMLInputElement>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NumberFieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NumberFieldState>;\n /** Must render an `<input>` of type `text`, `search` or `tel`; the hidden input is rendered after it regardless. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, NumberFieldState>;\n}\n\n/** Visually hidden, unfocusable, out of the accessibility tree: the form's control (6.1). */\nconst HIDDEN_STYLE: CSSProperties = {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n margin: \"-1px\",\n padding: 0,\n border: 0,\n opacity: 0,\n overflow: \"hidden\",\n clipPath: \"inset(50%)\",\n pointerEvents: \"none\",\n};\n\nconst TEXT_TYPES = [\"text\", \"search\", \"tel\"];\n\n/**\n * The visible text field (`input[type=text]`, the user's surface) **followed by** the visually\n * hidden native `input[type=number]` that carries `name`, `form`, `min`, `max`, `step`,\n * `required` and the canonical value (design/components/number-field.md 6). `ref` goes to the\n * visible input, `hiddenInputRef` to the hidden one.\n *\n * Owned keys on the visible input: `id`, `type`, `value`, `disabled`, `readOnly`, `onChange`,\n * `onKeyDown`, `onBlur`, `aria-invalid` and `aria-describedby` (Field, token-merged),\n * `data-pending`, `data-disabled`, `data-invalid`. Defaults the consumer's own prop replaces:\n * `inputMode`, `autoComplete=\"off\"`, `autoCorrect=\"off\"`, `spellCheck={false}`.\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport function NumberFieldInput({\n hiddenInputRef,\n className,\n style,\n render,\n ...rest\n}: NumberFieldInputProps) {\n const ctx = useNumberFieldContext(\"NumberField.Input\");\n const { state, visibleRef, hiddenRef, syncHidden, onItemMounted } = ctx;\n\n // --- The Field contract (design 7.1): the visible input registers, the hidden one validates.\n const validityElement = useCallback(() => hiddenRef.current, [hiddenRef]);\n const field = useFieldControl({\n labelable: true,\n name: ctx.name,\n disabled: state.disabled,\n required: state.required,\n component: \"NumberField.Input\",\n validityElement,\n });\n\n const restName = (rest as { name?: unknown }).name;\n useDevWarning(\n restName !== undefined,\n isDev &&\n \"NumberField.Input: `name` belongs on NumberField.Root (it goes to the hidden number input); \" +\n \"on the visible input it would post the formatted text.\",\n );\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n const type = element.tagName === \"INPUT\" ? (element as HTMLInputElement).type : \"\";\n return !TEXT_TYPES.includes(type)\n ? `NumberField.Input: rendered <${element.tagName.toLowerCase()}` +\n `${type === \"\" ? \"\" : ` type=\"${type}\"`}>. Render an <input> of type \"text\", ` +\n '\"search\" or \"tel\": a number input would re-introduce the native parser.'\n : null;\n }),\n );\n const libraryRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n visibleRef.current = element as HTMLInputElement;\n return () => {\n if (visibleRef.current === element) visibleRef.current = null;\n };\n },\n [checkElement, visibleRef],\n );\n const mergedRef = useMergedRefs<HTMLElement>(libraryRef, field.ref);\n\n const hiddenMergedRef = useMergedRefs<HTMLInputElement | null>(hiddenRef, hiddenInputRef);\n\n // After every commit: the hidden input holds the shown value (a rollback, a controlled change,\n // a reset) and the visible input mirrors its validity (a changed `min` / `max` / `required`).\n useLayoutEffect(() => {\n syncHidden(state.value);\n });\n\n // The hidden input is never the one the browser reports on (6.3); the visible input is\n // invalid in the same cases and gets the report (or the Field handles it).\n useLayoutEffect(() => {\n const hidden = hiddenRef.current;\n if (hidden === null) return;\n const onInvalid = (event: Event) => event.preventDefault();\n hidden.addEventListener(\"invalid\", onInvalid);\n return () => hidden.removeEventListener(\"invalid\", onInvalid);\n }, [hiddenRef]);\n\n // React's `onWheel` is passive: a native, non-passive listener can stop the page scroll (4.4).\n const onWheel = useEffectEvent((event: WheelEvent) => {\n ctx.wheel(event);\n });\n const { stepOnWheel } = ctx;\n useLayoutEffect(() => {\n const visible = visibleRef.current;\n if (!stepOnWheel || visible === null) return;\n visible.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => visible.removeEventListener(\"wheel\", onWheel);\n }, [stepOnWheel, visibleRef]);\n\n // A late mount (inside a Suspense boundary that hydrates after the Root) reconciles again.\n const mounted = useRef(false);\n useLayoutEffect(() => {\n if (mounted.current) return;\n mounted.current = true;\n onItemMounted();\n }, [onItemMounted]);\n\n const renderType =\n isValidElement<{ type?: unknown }>(render) && typeof render.props.type === \"string\"\n ? render.props.type\n : undefined;\n const type = renderType !== undefined && TEXT_TYPES.includes(renderType) ? renderType : \"text\";\n useDevWarning(\n renderType !== undefined && !TEXT_TYPES.includes(renderType),\n isDev &&\n `NumberField.Input: \\`render\\` has type=\"${renderType ?? \"\"}\"; the visible input is ` +\n 'rendered as type \"text\". A number input would re-introduce the native parser the ' +\n \"NumberField exists to avoid.\",\n );\n\n const dataInvalid =\n ctx.fieldInvalid === undefined ? {} : { \"data-invalid\": dataAttr(ctx.fieldInvalid) };\n const libraryProps: ComponentPropsWithRef<\"input\"> & DataAttributes = {\n ...field.attributes,\n id: ctx.inputId,\n type,\n value: state.text,\n disabled: state.disabled,\n readOnly: state.readOnly,\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n ctx.typed(event.currentTarget.value);\n },\n onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => {\n ctx.keyDown(event.nativeEvent);\n },\n onBlur: (event: FocusEvent<HTMLInputElement>) => {\n ctx.commitDraft(event.nativeEvent);\n },\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(state.disabled),\n ...dataInvalid,\n };\n\n const visible = useRender<ComponentPropsWithRef<\"input\">, NumberFieldState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n props: {\n inputMode: ctx.allowsFractions ? \"decimal\" : \"numeric\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n spellCheck: false,\n ...rest,\n },\n libraryProps,\n ref: mergedRef,\n });\n\n const { min, max, step } = ctx.bounds;\n return (\n <>\n {visible}\n <input\n ref={hiddenMergedRef}\n type=\"number\"\n name={field.name}\n form={ctx.form}\n min={min}\n max={max}\n step={step}\n required={field.required}\n disabled={field.disabled}\n readOnly={state.readOnly}\n defaultValue={ctx.resetTargetText}\n autoComplete=\"off\"\n aria-hidden=\"true\"\n tabIndex={-1}\n style={HIDDEN_STYLE}\n />\n </>\n );\n}\n\nNumberFieldInput.displayName = \"NumberFieldInput\";\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAwCvC,MAAM,eAA8B;CAClC,UAAU;CACV,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,SAAS;CACT,UAAU;CACV,UAAU;CACV,eAAe;AACjB;AAEA,MAAM,aAAa;CAAC;CAAQ;CAAU;AAAK;;;;;;;;;;;;;;AAe3C,SAAgB,iBAAiB,EAC/B,gBACA,WACA,OACA,QACA,GAAG,QACqB;CACxB,MAAM,MAAM,sBAAsB,mBAAmB;CACrD,MAAM,EAAE,OAAO,YAAY,WAAW,YAAY,kBAAkB;CAGpE,MAAM,kBAAkB,kBAAkB,UAAU,SAAS,CAAC,SAAS,CAAC;CACxE,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,MAAM,IAAI;EACV,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB,WAAW;EACX;CACF,CAAC;CAED,MAAM,WAAY,KAA4B;CAC9C,cACE,aAAa,KAAA,GACb,SACE,oJAEJ;CAEA,MAAM,eAAe,gBACnB,WAC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AAO,eAAe,KAAA,KAAa,WAAW,SAAS,UAAU,IAAI,aAAa;CACxF,cACE,eAAe,KAAA,KAAa,CAAC,WAAW,SAAS,UAAU,GAC3D,SACE,2CAA2C,cAAc,GAAG,sIAGhE;CAEA,MAAM,cACJ,IAAI,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,SAAS,IAAI,YAAY,EAAE;CACrF,MAAM,eAAgE;EACpE,GAAG,MAAM;EACT,IAAI,IAAI;EACR;EACA,OAAO,MAAM;EACb,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB,WAAW,UAAyC;GAClD,IAAI,MAAM,MAAM,cAAc,KAAK;EACrC;EACA,YAAY,UAA2C;GACrD,IAAI,QAAQ,MAAM,WAAW;EAC/B;EACA,SAAS,UAAwC;GAC/C,IAAI,YAAY,MAAM,WAAW;EACnC;EACA,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,MAAM,QAAQ;EACxC,GAAG;CACL;CAEA,MAAM,UAAU,UAA4D;EAC1E,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,KAAA;EACV,OAAO;GACL,WAAW,IAAI,kBAAkB,YAAY;GAC7C,cAAc;GACd,aAAa;GACb,YAAY;GACZ,GAAG;EACL;EACA;EACA,KAAK;CACP,CAAC;CAED,MAAM,EAAE,KAAK,KAAK,SAAS,IAAI;CAC/B,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,SACD,oBAAC,SAAD;EACE,KAAK;EACL,MAAK;EACL,MAAM,MAAM;EACZ,MAAM,IAAI;EACL;EACA;EACC;EACN,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB,cAAc,IAAI;EAClB,cAAa;EACb,eAAY;EACZ,UAAU;EACV,OAAO;CACR,CAAA,CACD,EAAA,CAAA;AAEN;AAEA,iBAAiB,cAAc"}
|
|
1
|
+
{"version":3,"file":"number-field-input.mjs","names":[],"sources":["../../src/number-field/number-field-input.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type {\n ChangeEvent,\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n Ref,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useFieldControl } from \"../internal/form/use-field-control.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport type { NumberFieldState } from \"./number-field-root.js\";\nimport { useNumberFieldContext } from \"./number-field-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Props of `NumberField.Input`.\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport interface NumberFieldInputProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"value\"\n | \"defaultValue\"\n | \"type\"\n | \"onChange\"\n | \"onKeyDown\"\n | \"onBlur\"\n | \"disabled\"\n | \"readOnly\"\n | \"required\"\n | \"name\"\n | \"form\"\n | \"min\"\n | \"max\"\n | \"step\"\n | \"pattern\"\n | \"aria-invalid\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The hidden native `<input type=\"number\">` rendered after the visible input. */\n hiddenInputRef?: Ref<HTMLInputElement>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NumberFieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NumberFieldState>;\n /** Must render an `<input>` of type `text`, `search` or `tel`; the hidden input is rendered after it regardless. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, NumberFieldState>;\n}\n\n/** Visually hidden, unfocusable, out of the accessibility tree: the form's control (6.1). */\nconst HIDDEN_STYLE: CSSProperties = {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n margin: \"-1px\",\n padding: 0,\n border: 0,\n opacity: 0,\n overflow: \"hidden\",\n clipPath: \"inset(50%)\",\n pointerEvents: \"none\",\n};\n\nconst TEXT_TYPES = [\"text\", \"search\", \"tel\"];\n\n/**\n * The visible text field (`input[type=text]`, the user's surface) **followed by** the visually\n * hidden native `input[type=number]` that carries `name`, `form`, `min`, `max`, `step`,\n * `required` and the canonical value (design/components/number-field.md 6). `ref` goes to the\n * visible input, `hiddenInputRef` to the hidden one.\n *\n * Owned keys on the visible input: `id`, `type`, `value`, `disabled`, `readOnly`, `onChange`,\n * `onKeyDown`, `onBlur`, `aria-invalid` and `aria-describedby` (Field, token-merged),\n * `data-pending`, `data-disabled`, `data-invalid`. Defaults the consumer's own prop replaces:\n * `inputMode`, `autoComplete=\"off\"`, `autoCorrect=\"off\"`, `spellCheck={false}`.\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport function NumberFieldInput({\n hiddenInputRef,\n className,\n style,\n render,\n ...rest\n}: NumberFieldInputProps) {\n const ctx = useNumberFieldContext(\"NumberField.Input\");\n const { state, visibleRef, hiddenRef, syncHidden, onItemMounted } = ctx;\n\n // --- The Field contract (design 7.1): the visible input registers, the hidden one validates.\n const validityElement = useCallback(() => hiddenRef.current, [hiddenRef]);\n const field = useFieldControl({\n labelable: true,\n name: ctx.name,\n disabled: state.disabled,\n required: state.required,\n component: \"NumberField.Input\",\n validityElement,\n });\n\n const restName = (rest as { name?: unknown }).name;\n useDevWarning(\n restName !== undefined,\n isDev &&\n \"NumberField.Input: `name` belongs on NumberField.Root (it goes to the hidden number input); \" +\n \"on the visible input it would post the formatted text.\",\n );\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n const type = element.tagName === \"INPUT\" ? (element as HTMLInputElement).type : \"\";\n return !TEXT_TYPES.includes(type)\n ? `NumberField.Input: rendered <${element.tagName.toLowerCase()}` +\n `${type === \"\" ? \"\" : ` type=\"${type}\"`}>. Render an <input> of type \"text\", ` +\n '\"search\" or \"tel\": a number input would re-introduce the native parser.'\n : null;\n }),\n );\n const libraryRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n visibleRef.current = element as HTMLInputElement;\n return () => {\n if (visibleRef.current === element) visibleRef.current = null;\n };\n },\n [checkElement, visibleRef],\n );\n const mergedRef = useMergedRefs<HTMLElement>(libraryRef, field.ref);\n\n const hiddenMergedRef = useMergedRefs<HTMLInputElement | null>(hiddenRef, hiddenInputRef);\n\n // After every commit: the hidden input holds the shown value (a rollback, a controlled change,\n // a reset) and the visible input mirrors its validity (a changed `min` / `max` / `required`).\n useLayoutEffect(() => {\n syncHidden(state.value);\n });\n\n // The hidden input is never the one the browser reports on (6.3); the visible input is\n // invalid in the same cases and gets the report (or the Field handles it).\n useLayoutEffect(() => {\n const hidden = hiddenRef.current;\n if (hidden === null) return;\n const onInvalid = (event: Event) => event.preventDefault();\n hidden.addEventListener(\"invalid\", onInvalid);\n return () => hidden.removeEventListener(\"invalid\", onInvalid);\n }, [hiddenRef]);\n\n // React's `onWheel` is passive: a native, non-passive listener can stop the page scroll (4.4).\n const onWheel = useEffectEvent((event: WheelEvent) => {\n ctx.wheel(event);\n });\n const { stepOnWheel } = ctx;\n useLayoutEffect(() => {\n const visible = visibleRef.current;\n if (!stepOnWheel || visible === null) return;\n visible.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => visible.removeEventListener(\"wheel\", onWheel);\n }, [stepOnWheel, visibleRef]);\n\n // A late mount (inside a Suspense boundary that hydrates after the Root) reconciles again.\n const mounted = useRef(false);\n useLayoutEffect(() => {\n if (mounted.current) return;\n mounted.current = true;\n onItemMounted();\n }, [onItemMounted]);\n\n const renderType =\n isValidElement<{ type?: unknown }>(render) && typeof render.props.type === \"string\"\n ? render.props.type\n : undefined;\n const type = renderType !== undefined && TEXT_TYPES.includes(renderType) ? renderType : \"text\";\n useDevWarning(\n renderType !== undefined && !TEXT_TYPES.includes(renderType),\n isDev &&\n `NumberField.Input: \\`render\\` has type=\"${renderType ?? \"\"}\"; the visible input is ` +\n 'rendered as type \"text\". A number input would re-introduce the native parser the ' +\n \"NumberField exists to avoid.\",\n );\n\n const dataInvalid =\n ctx.fieldInvalid === undefined ? {} : { \"data-invalid\": dataAttr(ctx.fieldInvalid) };\n const libraryProps: ComponentPropsWithRef<\"input\"> & DataAttributes = {\n ...field.attributes,\n id: ctx.inputId,\n type,\n value: state.text,\n disabled: state.disabled,\n readOnly: state.readOnly,\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n ctx.typed(event.currentTarget.value);\n },\n onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => {\n ctx.keyDown(event.nativeEvent);\n },\n onBlur: (event: FocusEvent<HTMLInputElement>) => {\n ctx.commitDraft(event.nativeEvent);\n },\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(state.disabled),\n ...dataInvalid,\n };\n\n const visible = useRender<ComponentPropsWithRef<\"input\">, NumberFieldState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n props: {\n inputMode: ctx.allowsFractions ? \"decimal\" : \"numeric\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n spellCheck: false,\n ...rest,\n },\n libraryProps,\n ref: mergedRef,\n });\n\n const { min, max, step } = ctx.bounds;\n return (\n <>\n {visible}\n <input\n ref={hiddenMergedRef}\n type=\"number\"\n name={field.name}\n form={ctx.form}\n min={min}\n max={max}\n step={step}\n required={field.required}\n disabled={field.disabled}\n readOnly={state.readOnly}\n defaultValue={ctx.resetTargetText}\n autoComplete=\"off\"\n aria-hidden=\"true\"\n tabIndex={-1}\n style={HIDDEN_STYLE}\n />\n </>\n );\n}\n\nNumberFieldInput.displayName = \"NumberFieldInput\";\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAwCvC,MAAM,eAA8B;CAClC,UAAU;CACV,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,S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IAAI,kBAAkB,YAAY;GAC7C,cAAc;GACd,aAAa;GACb,YAAY;GACZ,GAAG;EACL;EACA;EACA,KAAK;CACP,CAAC;CAED,MAAM,EAAE,KAAK,KAAK,SAAS,IAAI;CAC/B,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,SACD,oBAAC,SAAD;EACE,KAAK;EACL,MAAK;EACL,MAAM,MAAM;EACZ,MAAM,IAAI;EACL;EACA;EACC;EACN,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB,cAAc,IAAI;EAClB,cAAa;EACb,eAAY;EACZ,UAAU;EACV,OAAO;CACR,CAAA,CACD,EAAA,CAAA;AAEN;AAEA,iBAAiB,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-field-root.d.mts","names":[],"sources":["../../src/number-field/number-field-root.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"number-field-root.d.mts","names":[],"sources":["../../src/number-field/number-field-root.tsx"],"mappings":";;;;;iBAqCiB,sCAAsC;;;;;;;;;WAS5C,QAAQ;;WAER,QAAQ;;;iBAIF;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,6BAA6B,KAC5C;;EAIA;;;;;;EAMA;;;;;;;EAOA,oBAAoB,4BAA4B;;;;;;;EAOhD,oBAAoB,4BAA4B;;EAEhD;;EAEA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA,SAAS,KAAK;;;;;;;EAOd;;;;;;EAMA;;;;;;EAMA;;EAEA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;;EAOA,YAAY,sBAAsB,OAAO;;EAEzC,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;wBAoEpC,gBAAgB,OAAO,uCAAoB,IAAA;yBAA3C"}
|