@funstack/ui 0.1.0-alpha.11 → 0.1.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordion/accordion-context.mjs.map +1 -1
- package/dist/accordion/accordion-item.d.mts +3 -4
- package/dist/accordion/accordion-item.d.mts.map +1 -1
- package/dist/accordion/accordion-item.mjs +10 -4
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-panel.d.mts +3 -4
- package/dist/accordion/accordion-panel.d.mts.map +1 -1
- package/dist/accordion/accordion-panel.mjs +2 -1
- package/dist/accordion/accordion-panel.mjs.map +1 -1
- package/dist/accordion/accordion-root.d.mts +3 -3
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +8 -19
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts +3 -4
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +5 -3
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/button/button.d.mts +4 -2
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +3 -2
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.d.mts +4 -5
- package/dist/checkbox/checkbox.d.mts.map +1 -1
- package/dist/checkbox/checkbox.mjs +16 -59
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-context.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-item.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +21 -27
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-label.mjs +1 -6
- package/dist/checkbox-group/checkbox-group-label.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-parent.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +12 -10
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +74 -101
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +5 -6
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-group.d.mts.map +1 -1
- package/dist/combobox/combobox-group.mjs +2 -1
- package/dist/combobox/combobox-group.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +14 -7
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts.map +1 -1
- package/dist/combobox/combobox-list.mjs +6 -10
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +2 -1
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs +9 -25
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +30 -102
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +6 -25
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/index.mjs +1 -1
- package/dist/combobox/use-combobox-form.mjs +56 -0
- package/dist/combobox/use-combobox-form.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +62 -0
- package/dist/combobox/use-option-registry.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +29 -62
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +5 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +3 -4
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +37 -98
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +30 -118
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +13 -16
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/field/field-control.mjs +6 -13
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts.map +1 -1
- package/dist/field/field-description.mjs +1 -2
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts.map +1 -1
- package/dist/field/field-error.mjs +1 -2
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +3 -11
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +21 -41
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.mjs +1 -1
- package/dist/field/use-server-error-visibility.mjs +44 -0
- package/dist/field/use-server-error-visibility.mjs.map +1 -0
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +6 -7
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +1 -1
- package/dist/form/form-submit.mjs +4 -10
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/internal/anchor-position.mjs +1 -59
- package/dist/internal/anchor-position.mjs.map +1 -1
- package/dist/internal/announce.mjs.map +1 -1
- package/dist/internal/arrow-keys.mjs +21 -0
- package/dist/internal/arrow-keys.mjs.map +1 -0
- package/dist/internal/decimal.mjs +7 -1
- package/dist/internal/decimal.mjs.map +1 -1
- package/dist/internal/dom-order.mjs +17 -0
- package/dist/internal/dom-order.mjs.map +1 -0
- package/dist/internal/field-context.d.mts.map +1 -1
- package/dist/internal/field-context.mjs +11 -1
- package/dist/internal/field-context.mjs.map +1 -1
- package/dist/internal/focus-first-invalid.mjs +1 -1
- package/dist/internal/focus-first-invalid.mjs.map +1 -1
- package/dist/internal/group-member.mjs +37 -0
- package/dist/internal/group-member.mjs.map +1 -0
- package/dist/internal/overlay-popup.mjs +103 -0
- package/dist/internal/overlay-popup.mjs.map +1 -0
- package/dist/internal/popover-open.mjs +18 -0
- package/dist/internal/popover-open.mjs.map +1 -0
- package/dist/internal/render-element.d.mts +2 -0
- package/dist/internal/render-element.mjs +20 -2
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/shipped-styles.mjs +14 -0
- package/dist/internal/shipped-styles.mjs.map +1 -0
- package/dist/internal/sync-presence.mjs +5 -1
- package/dist/internal/sync-presence.mjs.map +1 -1
- package/dist/internal/toolbar-context.mjs.map +1 -1
- package/dist/internal/tooltip-warm.mjs +1 -1
- package/dist/internal/tooltip-warm.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +1 -1
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/types.d.mts +2 -0
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +5 -23
- package/dist/internal/use-action-trigger.mjs.map +1 -1
- package/dist/internal/use-checkable-input.mjs +79 -0
- package/dist/internal/use-checkable-input.mjs.map +1 -0
- package/dist/internal/use-controllable-action.mjs +16 -24
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- package/dist/internal/use-dev-warning.mjs +8 -4
- package/dist/internal/use-dev-warning.mjs.map +1 -1
- package/dist/internal/use-element-check.mjs +39 -0
- package/dist/internal/use-element-check.mjs.map +1 -0
- package/dist/internal/use-exit-animation.mjs +1 -1
- package/dist/internal/use-exit-animation.mjs.map +1 -1
- package/dist/internal/use-field-control.mjs +28 -12
- package/dist/internal/use-field-control.mjs.map +1 -1
- package/dist/internal/use-fieldset-group.mjs +46 -0
- package/dist/internal/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/use-form-reset.mjs +1 -5
- package/dist/internal/use-form-reset.mjs.map +1 -1
- package/dist/internal/use-item-order.mjs +42 -0
- package/dist/internal/use-item-order.mjs.map +1 -0
- package/dist/internal/use-latest.mjs +4 -8
- package/dist/internal/use-latest.mjs.map +1 -1
- package/dist/internal/use-merged-refs.mjs +19 -0
- package/dist/internal/use-merged-refs.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +84 -0
- package/dist/internal/use-name-warning.mjs.map +1 -0
- package/dist/internal/use-native-checked.mjs +4 -6
- package/dist/internal/use-native-checked.mjs.map +1 -1
- package/dist/internal/use-native-focusgroup.mjs +19 -0
- package/dist/internal/use-native-focusgroup.mjs.map +1 -0
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-overlay-close.mjs +63 -0
- package/dist/internal/use-overlay-close.mjs.map +1 -0
- package/dist/internal/{use-popover-root.mjs → use-overlay-root.mjs} +28 -39
- package/dist/internal/use-overlay-root.mjs.map +1 -0
- package/dist/internal/use-popover-popup.mjs +32 -78
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.d.mts +15 -0
- package/dist/internal/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/use-popover-trigger.mjs +13 -17
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/use-register-count.mjs +24 -0
- package/dist/internal/use-register-count.mjs.map +1 -0
- package/dist/internal/use-render.d.mts +2 -0
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-resolved-placement.mjs +38 -22
- package/dist/internal/use-resolved-placement.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs +5 -18
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/internal/use-superseded-rejection.mjs +47 -0
- package/dist/internal/use-superseded-rejection.mjs.map +1 -0
- package/dist/internal/validity.mjs +1 -13
- package/dist/internal/validity.mjs.map +1 -1
- package/dist/internal/value-set.mjs +41 -0
- package/dist/internal/value-set.mjs.map +1 -0
- package/dist/menu/index.d.mts +1 -1
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context-trigger.d.mts +2 -7
- package/dist/menu/menu-context-trigger.d.mts.map +1 -1
- package/dist/menu/menu-context-trigger.mjs +10 -187
- package/dist/menu/menu-context-trigger.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-dom.mjs +1 -2
- package/dist/menu/menu-dom.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +167 -0
- package/dist/menu/menu-gestures.mjs.map +1 -0
- package/dist/menu/menu-group.d.mts.map +1 -1
- package/dist/menu/menu-group.mjs +2 -1
- package/dist/menu/menu-group.mjs.map +1 -1
- package/dist/menu/menu-hover.mjs +0 -1
- package/dist/menu/menu-hover.mjs.map +1 -1
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +101 -0
- package/dist/menu/menu-outside.mjs.map +1 -0
- package/dist/menu/menu-point.mjs +85 -0
- package/dist/menu/menu-point.mjs.map +1 -0
- package/dist/menu/menu-popup.d.mts +6 -7
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +37 -248
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.d.mts +10 -0
- package/dist/menu/menu-root.d.mts.map +1 -1
- package/dist/menu/menu-root.mjs +10 -8
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +6 -6
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +4 -9
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +8 -6
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menu/use-menu-item.mjs +14 -16
- package/dist/menu/use-menu-item.mjs.map +1 -1
- package/dist/menu/use-menu-keyboard.mjs +88 -0
- package/dist/menu/use-menu-keyboard.mjs.map +1 -0
- package/dist/meter/meter-root.mjs +1 -1
- package/dist/number-field/index.d.mts +2 -1
- package/dist/number-field/index.d.mts.map +1 -1
- package/dist/number-field/index.mjs +2 -2
- package/dist/number-field/index.mjs.map +1 -1
- package/dist/number-field/number-field-arithmetic.mjs +30 -11
- package/dist/number-field/number-field-arithmetic.mjs.map +1 -1
- package/dist/number-field/number-field-context.d.mts +6 -1
- package/dist/number-field/number-field-context.d.mts.map +1 -0
- package/dist/number-field/number-field-context.mjs.map +1 -1
- package/dist/number-field/number-field-decrement.d.mts +1 -1
- package/dist/number-field/number-field-decrement.mjs +1 -1
- package/dist/number-field/number-field-decrement.mjs.map +1 -1
- package/dist/number-field/number-field-increment.d.mts +2 -22
- package/dist/number-field/number-field-increment.d.mts.map +1 -1
- package/dist/number-field/number-field-increment.mjs +2 -53
- package/dist/number-field/number-field-increment.mjs.map +1 -1
- package/dist/number-field/number-field-input.d.mts.map +1 -1
- package/dist/number-field/number-field-input.mjs +18 -22
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-label.d.mts.map +1 -1
- package/dist/number-field/number-field-label.mjs +3 -9
- package/dist/number-field/number-field-label.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts +2 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +81 -91
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/number-field/use-number-field-dev-warnings.mjs +28 -0
- package/dist/number-field/use-number-field-dev-warnings.mjs.map +1 -0
- package/dist/number-field/use-step-button.d.mts +24 -0
- package/dist/number-field/use-step-button.d.mts.map +1 -0
- package/dist/number-field/use-step-button.mjs +57 -3
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +28 -67
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-context.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +9 -6
- package/dist/popover/popover-popup.d.mts.map +1 -1
- package/dist/popover/popover-popup.mjs +13 -36
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +4 -3
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +4 -8
- package/dist/popover/popover-trigger.d.mts.map +1 -1
- package/dist/popover/popover-trigger.mjs +2 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/progress/progress-root.mjs +1 -1
- package/dist/radio-group/radio-group-context.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.d.mts +3 -4
- package/dist/radio-group/radio-group-item.d.mts.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +20 -25
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-label.mjs +1 -6
- package/dist/radio-group/radio-group-label.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +21 -40
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-dom.mjs +9 -18
- package/dist/select/select-dom.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-root.mjs +3 -2
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/slider/slider-arithmetic.mjs +74 -13
- package/dist/slider/slider-arithmetic.mjs.map +1 -1
- package/dist/slider/slider-context.mjs.map +1 -1
- package/dist/slider/slider-label.d.mts.map +1 -1
- package/dist/slider/slider-label.mjs +3 -9
- package/dist/slider/slider-label.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts +2 -2
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +36 -116
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/slider-thumb.d.mts.map +1 -1
- package/dist/slider/slider-thumb.mjs +8 -6
- package/dist/slider/slider-thumb.mjs.map +1 -1
- package/dist/slider/slider-value.d.mts.map +1 -1
- package/dist/slider/slider-value.mjs +2 -1
- package/dist/slider/slider-value.mjs.map +1 -1
- package/dist/slider/use-slider-dev-warnings.mjs +29 -0
- package/dist/slider/use-slider-dev-warnings.mjs.map +1 -0
- package/dist/slider/use-thumb-registry.mjs +51 -0
- package/dist/slider/use-thumb-registry.mjs.map +1 -0
- package/dist/switch/switch.d.mts +4 -5
- package/dist/switch/switch.d.mts.map +1 -1
- package/dist/switch/switch.mjs +15 -55
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-context.d.mts +2 -3
- package/dist/tabs/tabs-context.d.mts.map +1 -1
- package/dist/tabs/tabs-context.mjs.map +1 -1
- package/dist/tabs/tabs-list.d.mts.map +1 -1
- package/dist/tabs/tabs-list.mjs +9 -22
- package/dist/tabs/tabs-list.mjs.map +1 -1
- package/dist/tabs/tabs-panel.d.mts +3 -4
- package/dist/tabs/tabs-panel.d.mts.map +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts +4 -3
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +2 -1
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/tabs/tabs-tab.d.mts +3 -4
- package/dist/tabs/tabs-tab.d.mts.map +1 -1
- package/dist/tabs/tabs-tab.mjs.map +1 -1
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +2 -8
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-context.mjs.map +1 -1
- package/dist/toast/toast-hotkey.mjs +27 -0
- package/dist/toast/toast-hotkey.mjs.map +1 -0
- package/dist/toast/toast-queue.mjs +137 -0
- package/dist/toast/toast-queue.mjs.map +1 -0
- package/dist/toast/toast-timers.mjs +65 -0
- package/dist/toast/toast-timers.mjs.map +1 -0
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +30 -235
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/toast.mjs +1 -1
- package/dist/toast/toast.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +52 -0
- package/dist/toast/use-modal-portal-host.mjs.map +1 -0
- package/dist/toggle/toggle.d.mts +3 -4
- package/dist/toggle/toggle.d.mts.map +1 -1
- package/dist/toggle/toggle.mjs +7 -10
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-context.d.mts +2 -1
- package/dist/toggle-group/toggle-group-context.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-context.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-item.d.mts +5 -3
- package/dist/toggle-group/toggle-group-item.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-item.mjs +5 -7
- package/dist/toggle-group/toggle-group-item.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +29 -64
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/toolbar/toolbar-root.d.mts +2 -2
- package/dist/toolbar/toolbar-root.d.mts.map +1 -1
- package/dist/toolbar/toolbar-root.mjs +3 -4
- package/dist/toolbar/toolbar-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-context.d.mts +1 -1
- package/dist/tooltip/tooltip-context.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +6 -15
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +2 -2
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.d.mts +2 -1
- package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +3 -2
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/tooltip/use-tooltip-interaction.mjs +4 -3
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/accordion/accordion-context.d.mts +0 -5
- package/dist/accordion/accordion-context.d.mts.map +0 -1
- package/dist/internal/use-popover-root.mjs.map +0 -1
- /package/dist/internal/{use-popover-root.d.mts → use-overlay-root.d.mts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-roving-focus.mjs","names":[],"sources":["../../src/internal/use-roving-focus.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useInsertionEffect, useLayoutEffect, useState } from \"react\";\nimport type { FocusEvent, KeyboardEvent, PointerEvent, RefObject } from \"react\";\n\n// The roving-focus engine shared by `Toolbar.Root` and a standalone `ToggleGroup.Root`\n// (design/components/toggle-group.md section 6, conventions 3.2 and 7.4). Items are the focusable\n// descendants of the container, found in the DOM; which one is the Tab stop is urgent library\n// state kept outside React and written to the items as `tabindex` through the DOM.\n\nexport type RovingOrientation = \"horizontal\" | \"vertical\";\n\nexport interface RovingFocusOptions {\n /** `false`: the engine writes nothing and handles nothing (a ToggleGroup inside a Toolbar). Default `true`. */\n readonly enabled?: boolean;\n readonly orientation: RovingOrientation;\n readonly loop: boolean;\n /** The native `focusgroup` path is active: write no `tabindex`, handle no navigation key. */\n readonly native: boolean;\n /** Which item is the Tab stop when there is no usable memory. */\n readonly entry: (items: readonly HTMLElement[]) => HTMLElement | undefined;\n /**\n * `true`: the last focused item stays the Tab stop after focus leaves (Toolbar). `false`: while\n * focus is inside, the focused item is the stop (so Tab and Shift+Tab leave the container);\n * once it leaves, the stop is re-derived from `entry` (ToggleGroup: the pressed Item).\n */\n readonly memory: boolean;\n}\n\nexport interface RovingFocusHandlers {\n readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n readonly onFocus: (event: FocusEvent<HTMLElement>) => void;\n readonly onBlur: (event: FocusEvent<HTMLElement>) => void;\n readonly onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n}\n\nconst FOCUSABLE = [\n \"button\",\n \"a[href]\",\n 'input:not([type=\"hidden\"])',\n \"select\",\n \"textarea\",\n \"summary\",\n '[contenteditable]:not([contenteditable=\"false\"])',\n \"[tabindex]\",\n].join(\",\");\n\nfunction isVisible(el: HTMLElement): boolean {\n // jsdom has no `checkVisibility`; `hidden` is the part of it a test can observe there.\n if (typeof el.checkVisibility === \"function\") return el.checkVisibility();\n return el.closest(\"[hidden]\") === null;\n}\n\n/**\n * Whether `el` or an ancestor below `root` takes it out of `root`'s sequence: a nested toolbar\n * (its own sequence), a popover or a dialog rendered inside the container (a `Menu.Popup`'s items\n * are the menu's).\n */\nfunction isNestedOut(el: HTMLElement, root: HTMLElement): boolean {\n for (let node: Element | null = el; node !== null && node !== root; node = node.parentElement) {\n if (\n node.getAttribute(\"role\") === \"toolbar\" ||\n node.hasAttribute(\"popover\") ||\n node.tagName === \"DIALOG\"\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isRadio(el: Element): el is HTMLInputElement {\n return el instanceof HTMLInputElement && el.type === \"radio\";\n}\n\n/** The items of a container, with native radio groups collapsed into units (design 17.2). */\nexport interface RovingItems {\n /** The toolbar's own destinations in DOM order; a radio unit appears as its representative. */\n readonly items: HTMLElement[];\n /**\n * Every native radio among the candidates → the radios of its unit (same `name` under the\n * container, DOM order). A radio without a `name` is a unit of one.\n */\n readonly units: Map<HTMLElement, readonly HTMLInputElement[]>;\n}\n\n/** The unit's representative: its checked radio, else its first (design 17.2 item 2). */\nfunction representative(unit: readonly HTMLInputElement[]): HTMLInputElement {\n return unit.find((radio) => radio.checked) ?? unit[0]!;\n}\n\n/**\n * The items of `root` (design 6.2 and 17.2): its focusable descendants minus `:disabled`,\n * `inert`, invisible, nested-toolbar / popover / dialog content, and elements whose own\n * `tabindex=\"-1\"` was not written by this engine (`managed`). `aria-disabled` elements are items.\n * Native radios that share a `name` form one unit, represented in `items` by its checked radio\n * (else its first), at the position of the unit's first radio.\n */\nexport function collectItems(\n root: HTMLElement,\n managed: { has(el: Element): boolean },\n): RovingItems {\n const candidates: HTMLElement[] = [];\n const byName = new Map<string, HTMLInputElement[]>();\n const units = new Map<HTMLElement, readonly HTMLInputElement[]>();\n for (const el of root.querySelectorAll<HTMLElement>(FOCUSABLE)) {\n if (el.matches(\":disabled\")) continue;\n if (el.closest(\"[inert]\") !== null) continue;\n if (el.getAttribute(\"tabindex\") === \"-1\" && !managed.has(el)) continue;\n if (isNestedOut(el, root)) continue;\n if (!isVisible(el)) continue;\n if (isRadio(el)) {\n // Same form owner assumed: a `form=` attribute that splits a `name` is not handled (v1).\n const unit = el.name === \"\" ? undefined : byName.get(el.name);\n if (unit !== undefined) {\n unit.push(el);\n units.set(el, unit);\n continue;\n }\n const created = [el];\n if (el.name !== \"\") byName.set(el.name, created);\n units.set(el, created);\n }\n candidates.push(el);\n }\n // `candidates` holds each unit's first radio in its place; swap in the representative.\n const items = candidates.map((el) => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n });\n return { items, units };\n}\n\n/** {@link collectItems}'s `items`: the container's destinations in DOM order. */\nexport function itemsOf(root: HTMLElement, managed: { has(el: Element): boolean }): HTMLElement[] {\n return collectItems(root, managed).items;\n}\n\nconst BUTTON_LIKE_INPUTS = new Set([\n \"button\",\n \"submit\",\n \"reset\",\n \"checkbox\",\n \"image\",\n \"color\",\n \"file\",\n]);\nconst ARROW_OWNING_ROLES = new Set([\"textbox\", \"combobox\", \"spinbutton\", \"slider\"]);\n\n/**\n * An item that owns the arrow keys (design 6.3 and 17.2): text-like `input`s, `textarea`,\n * `select`, `[contenteditable]`, `role` `textbox` / `combobox` / `spinbutton` / `slider`, and a\n * native `input[type=radio]` (its group's own arrows check as they move). A custom\n * `[role=\"radio\"]` is an ordinary item, as it is under native `focusgroup`.\n */\nexport function ownsArrows(el: Element): boolean {\n const role = el.getAttribute(\"role\");\n if (role !== null && ARROW_OWNING_ROLES.has(role)) return true;\n if (el instanceof HTMLInputElement) return !BUTTON_LIKE_INPUTS.has(el.type);\n if (el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) return true;\n const editable = el.getAttribute(\"contenteditable\");\n if (editable !== null && editable !== \"false\") return true;\n return el instanceof HTMLElement && el.isContentEditable === true;\n}\n\ntype Move = \"next\" | \"prev\" | \"first\" | \"last\";\n\nfunction resolveKey(key: string, orientation: RovingOrientation, rtl: boolean): Move | null {\n switch (key) {\n case \"Home\":\n return \"first\";\n case \"End\":\n return \"last\";\n case \"ArrowRight\":\n return orientation === \"horizontal\" ? (rtl ? \"prev\" : \"next\") : null;\n case \"ArrowLeft\":\n return orientation === \"horizontal\" ? (rtl ? \"next\" : \"prev\") : null;\n case \"ArrowDown\":\n return orientation === \"vertical\" ? \"next\" : null;\n case \"ArrowUp\":\n return orientation === \"vertical\" ? \"prev\" : null;\n default:\n return null;\n }\n}\n\nfunction focusItem(item: HTMLElement): void {\n // Keyboard focus: the ring shows even where the engine's heuristic would not (as Tabs).\n item.focus({ focusVisible: true } as FocusOptions);\n}\n\ninterface Engine {\n /** The options of the last committed render (written from an insertion effect). */\n readonly setOptions: (options: RovingFocusOptions) => void;\n /**\n * Re-derives the Tab stop of `root` and writes `tabindex`. `focused`: the element focus is on,\n * if any.\n */\n readonly apply: (root: HTMLElement | null, focused: Element | null) => void;\n readonly handlers: RovingFocusHandlers;\n}\n\nfunction createEngine(): Engine {\n let current: HTMLElement | null = null;\n let latestOptions: RovingFocusOptions | null = null;\n /**\n * Elements this engine wrote `tabindex` on, with the attribute value they had before the first\n * write (`null`: none). Restored when the engine lets go of an element (native path, element\n * left the container): React does not re-write a `tabIndex` prop it believes it rendered, so a\n * `[tabindex=\"0\"]` widget would otherwise become unreachable.\n */\n const managed = new Map<HTMLElement, string | null>();\n\n const restore = (el: HTMLElement) => {\n const original = managed.get(el);\n managed.delete(el);\n if (!el.isConnected || original === undefined) return;\n if (original === null) el.removeAttribute(\"tabindex\");\n else el.setAttribute(\"tabindex\", original);\n };\n\n const active = (options: RovingFocusOptions | null): options is RovingFocusOptions =>\n options !== null && options.enabled !== false;\n\n /** Native path: give back every `tabindex` this engine wrote (a hydration render may have). */\n const release = () => {\n for (const el of [...managed.keys()]) restore(el);\n current = null;\n };\n\n const apply = (root: HTMLElement | null, focused: Element | null) => {\n const options = latestOptions;\n if (root === null || !active(options)) return;\n if (options.native) {\n release();\n return;\n }\n const { items, units } = collectItems(root, managed);\n /** Every element the engine writes: the items and the other radios of their units. */\n const all = new Set<HTMLElement>(items);\n for (const radio of units.keys()) all.add(radio);\n /** The item standing for `el`: its unit's representative for a radio, else itself. */\n const itemOf = (el: HTMLElement): HTMLElement => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n };\n if (!options.memory) {\n current =\n focused instanceof HTMLElement && all.has(focused)\n ? focused\n : (options.entry(items) ?? null);\n } else if (current === null || !all.has(current) || !items.includes(itemOf(current))) {\n current = options.entry(items) ?? null;\n }\n // `current` may be any radio of its unit (focus landed on an unchecked one): `0` on it, `-1`\n // on the unit's other radios and on every other element (design 17.2 item 5).\n for (const el of all) {\n if (!managed.has(el)) managed.set(el, el.getAttribute(\"tabindex\"));\n const want = el === current ? \"0\" : \"-1\";\n if (el.getAttribute(\"tabindex\") !== want) el.setAttribute(\"tabindex\", want);\n }\n // Elements written before that are no longer items: a stale `0` must not stay a Tab stop\n // (it would be one again when re-enabled); one that left the container gets its own back.\n for (const el of [...managed.keys()]) {\n if (all.has(el)) continue;\n if (!root.contains(el)) {\n restore(el);\n } else if (el.getAttribute(\"tabindex\") !== \"-1\") {\n el.setAttribute(\"tabindex\", \"-1\");\n }\n }\n };\n\n const onFocus = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n if (!items.includes(target) && !units.has(target)) return;\n current = target;\n apply(event.currentTarget, target);\n };\n\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native || options.memory) return;\n // Focus moving to another item is handled by its focus event.\n const next = event.relatedTarget;\n if (next instanceof Node && event.currentTarget.contains(next)) return;\n apply(event.currentTarget, null);\n };\n\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof Node)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n // Safari does not focus a button on click; the pointer still makes it the stop.\n const item = [...items, ...units.keys()].find((el) => el.contains(target));\n if (item === undefined) return;\n current = item;\n apply(\n event.currentTarget,\n options.memory ? item : event.currentTarget.ownerDocument.activeElement,\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const options = latestOptions;\n // The browser moves focus itself where `focusgroup` is implemented.\n if (!active(options) || options.native) return;\n const root = event.currentTarget;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(root, managed);\n const unit = units.get(target);\n // A radio stands in `items` through its unit's representative.\n const index = items.indexOf(unit === undefined ? target : representative(unit));\n if (index < 0) return;\n\n if (ownsArrows(target)) {\n // The item keeps its arrows, Home and End; Tab / Shift+Tab move to the next / previous item\n // while one exists, as Chromium's `focusgroup=\"toolbar\"` does (design 6.3, 17.2 item 4).\n if (event.key !== \"Tab\") return;\n // From an unchecked radio whose sibling is checked: that sibling first (only the checked\n // radio of a group is sequentially focusable natively).\n const checked = unit?.find((radio) => radio.checked);\n if (checked !== undefined && checked !== target) {\n event.preventDefault();\n focusItem(checked);\n return;\n }\n const next = items[index + (event.shiftKey ? -1 : 1)];\n if (next === undefined) return;\n event.preventDefault();\n focusItem(next);\n return;\n }\n\n const rtl = options.orientation === \"horizontal\" && getComputedStyle(root).direction === \"rtl\";\n const move = resolveKey(event.key, options.orientation, rtl);\n if (move === null) return;\n event.preventDefault();\n const last = items.length - 1;\n let nextIndex: number;\n switch (move) {\n case \"first\":\n nextIndex = 0;\n break;\n case \"last\":\n nextIndex = last;\n break;\n case \"next\":\n nextIndex = index >= last ? (options.loop ? 0 : last) : index + 1;\n break;\n case \"prev\":\n nextIndex = index <= 0 ? (options.loop ? last : 0) : index - 1;\n break;\n }\n const next = items[nextIndex];\n if (next !== undefined && next !== target) focusItem(next);\n };\n\n return {\n setOptions: (options) => {\n latestOptions = options;\n },\n apply,\n handlers: { onFocus, onBlur, onPointerDown, onKeyDown },\n };\n}\n\n/**\n * Roving focus over the focusable descendants of `ref`'s element (design 6.2). Writes `tabindex`\n * (`0` on the Tab stop, `-1` on the other items) from a layout effect after every commit of the\n * calling component, from a `MutationObserver` on the subtree and from focus / pointer events;\n * the items render none. Returns the container's handlers for its library props.\n */\nexport function useRovingFocus(\n ref: RefObject<HTMLElement | null>,\n options: RovingFocusOptions,\n): RovingFocusHandlers {\n const [engine] = useState(createEngine);\n // Before every layout effect of the same commit (as `useLatest`): handlers and the observer\n // read the options of the last committed render.\n useInsertionEffect(() => {\n engine.setOptions(options);\n });\n const enabled = options.enabled !== false;\n\n // After every commit of the container (a deps-less layout effect).\n useLayoutEffect(() => {\n const root = ref.current;\n engine.apply(root, root?.ownerDocument.activeElement ?? null);\n });\n\n // Children that change without the container re-rendering.\n useEffect(() => {\n const root = ref.current;\n if (!enabled || root === null) return;\n const observer = new MutationObserver(() => {\n engine.apply(root, root.ownerDocument.activeElement);\n });\n observer.observe(root, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"disabled\", \"hidden\", \"inert\", \"aria-disabled\"],\n });\n return () => {\n observer.disconnect();\n };\n }, [engine, enabled, ref]);\n\n return engine.handlers;\n}\n"],"mappings":";;;AAmCA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,SAAS,UAAU,IAA0B;CAE3C,IAAI,OAAO,GAAG,oBAAoB,YAAY,OAAO,GAAG,gBAAgB;CACxE,OAAO,GAAG,QAAQ,UAAU,MAAM;AACpC;;;;;;AAOA,SAAS,YAAY,IAAiB,MAA4B;CAChE,KAAK,IAAI,OAAuB,IAAI,SAAS,QAAQ,SAAS,MAAM,OAAO,KAAK,eAC9E,IACE,KAAK,aAAa,MAAM,MAAM,aAC9B,KAAK,aAAa,SAAS,KAC3B,KAAK,YAAY,UAEjB,OAAO;CAGX,OAAO;AACT;AAEA,SAAS,QAAQ,IAAqC;CACpD,OAAO,cAAc,oBAAoB,GAAG,SAAS;AACvD;;AAcA,SAAS,eAAe,MAAqD;CAC3E,OAAO,KAAK,MAAM,UAAU,MAAM,OAAO,KAAK,KAAK;AACrD;;;;;;;;AASA,SAAgB,aACd,MACA,SACa;CACb,MAAM,aAA4B,CAAC;CACnC,MAAM,yBAAS,IAAI,IAAgC;CACnD,MAAM,wBAAQ,IAAI,IAA8C;CAChE,KAAK,MAAM,MAAM,KAAK,iBAA8B,SAAS,GAAG;EAC9D,IAAI,GAAG,QAAQ,WAAW,GAAG;EAC7B,IAAI,GAAG,QAAQ,SAAS,MAAM,MAAM;EACpC,IAAI,GAAG,aAAa,UAAU,MAAM,QAAQ,CAAC,QAAQ,IAAI,EAAE,GAAG;EAC9D,IAAI,YAAY,IAAI,IAAI,GAAG;EAC3B,IAAI,CAAC,UAAU,EAAE,GAAG;EACpB,IAAI,QAAQ,EAAE,GAAG;GAEf,MAAM,OAAO,GAAG,SAAS,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,MAAR;GACE,KAAK;IACH,YAAY;IACZ;GACF,KAAK;IACH,YAAY;IACZ;GACF,KAAK;IACH,YAAY,SAAS,OAAQ,QAAQ,OAAO,IAAI,OAAQ,QAAQ;IAChE;GACF,KAAK,QACH,YAAY,SAAS,IAAK,QAAQ,OAAO,OAAO,IAAK,QAAQ;EAEjE;EACA,MAAM,OAAO,MAAM;EACnB,IAAI,SAAS,KAAA,KAAa,SAAS,QAAQ,UAAU,IAAI;CAC3D;CAEA,OAAO;EACL,aAAa,YAAY;GACvB,gBAAgB;EAClB;EACA;EACA,UAAU;GAAE;GAAS;GAAQ;GAAe;EAAU;CACxD;AACF;;;;;;;AAQA,SAAgB,eACd,KACA,SACqB;CACrB,MAAM,CAAC,UAAU,SAAS,YAAY;CAGtC,yBAAyB;EACvB,OAAO,WAAW,OAAO;CAC3B,CAAC;CACD,MAAM,UAAU,QAAQ,YAAY;CAGpC,sBAAsB;EACpB,MAAM,OAAO,IAAI;EACjB,OAAO,MAAM,MAAM,MAAM,cAAc,iBAAiB,IAAI;CAC9D,CAAC;CAGD,gBAAgB;EACd,MAAM,OAAO,IAAI;EACjB,IAAI,CAAC,WAAW,SAAS,MAAM;EAC/B,MAAM,WAAW,IAAI,uBAAuB;GAC1C,OAAO,MAAM,MAAM,KAAK,cAAc,aAAa;EACrD,CAAC;EACD,SAAS,QAAQ,MAAM;GACrB,WAAW;GACX,SAAS;GACT,YAAY;GACZ,iBAAiB;IAAC;IAAY;IAAU;IAAS;GAAe;EAClE,CAAC;EACD,aAAa;GACX,SAAS,WAAW;EACtB;CACF,GAAG;EAAC;EAAQ;EAAS;CAAG,CAAC;CAEzB,OAAO,OAAO;AAChB"}
|
|
1
|
+
{"version":3,"file":"use-roving-focus.mjs","names":[],"sources":["../../src/internal/use-roving-focus.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useInsertionEffect, useLayoutEffect, useState } from \"react\";\nimport type { FocusEvent, KeyboardEvent, PointerEvent, RefObject } from \"react\";\nimport { focusWithRing, resolveArrowKey } from \"./arrow-keys.js\";\nimport type { Orientation } from \"./types.js\";\n\n// The roving-focus engine shared by `Toolbar.Root` and a standalone `ToggleGroup.Root`\n// (design/components/toggle-group.md section 6, conventions 3.2 and 7.4). Items are the focusable\n// descendants of the container, found in the DOM; which one is the Tab stop is urgent library\n// state kept outside React and written to the items as `tabindex` through the DOM.\n\nexport type RovingOrientation = Orientation;\n\nexport interface RovingFocusOptions {\n /** `false`: the engine writes nothing and handles nothing (a ToggleGroup inside a Toolbar). Default `true`. */\n readonly enabled?: boolean;\n readonly orientation: RovingOrientation;\n readonly loop: boolean;\n /** The native `focusgroup` path is active: write no `tabindex`, handle no navigation key. */\n readonly native: boolean;\n /** Which item is the Tab stop when there is no usable memory. */\n readonly entry: (items: readonly HTMLElement[]) => HTMLElement | undefined;\n /**\n * `true`: the last focused item stays the Tab stop after focus leaves (Toolbar). `false`: while\n * focus is inside, the focused item is the stop (so Tab and Shift+Tab leave the container);\n * once it leaves, the stop is re-derived from `entry` (ToggleGroup: the pressed Item).\n */\n readonly memory: boolean;\n}\n\nexport interface RovingFocusHandlers {\n readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n readonly onFocus: (event: FocusEvent<HTMLElement>) => void;\n readonly onBlur: (event: FocusEvent<HTMLElement>) => void;\n readonly onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n}\n\nconst FOCUSABLE = [\n \"button\",\n \"a[href]\",\n 'input:not([type=\"hidden\"])',\n \"select\",\n \"textarea\",\n \"summary\",\n '[contenteditable]:not([contenteditable=\"false\"])',\n \"[tabindex]\",\n].join(\",\");\n\nfunction isVisible(el: HTMLElement): boolean {\n // jsdom has no `checkVisibility`; `hidden` is the part of it a test can observe there.\n if (typeof el.checkVisibility === \"function\") return el.checkVisibility();\n return el.closest(\"[hidden]\") === null;\n}\n\n/**\n * Whether `el` or an ancestor below `root` takes it out of `root`'s sequence: a nested toolbar\n * (its own sequence), a popover or a dialog rendered inside the container (a `Menu.Popup`'s items\n * are the menu's).\n */\nfunction isNestedOut(el: HTMLElement, root: HTMLElement): boolean {\n for (let node: Element | null = el; node !== null && node !== root; node = node.parentElement) {\n if (\n node.getAttribute(\"role\") === \"toolbar\" ||\n node.hasAttribute(\"popover\") ||\n node.tagName === \"DIALOG\"\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isRadio(el: Element): el is HTMLInputElement {\n return el instanceof HTMLInputElement && el.type === \"radio\";\n}\n\n/** The items of a container, with native radio groups collapsed into units (design 17.2). */\nexport interface RovingItems {\n /** The toolbar's own destinations in DOM order; a radio unit appears as its representative. */\n readonly items: HTMLElement[];\n /**\n * Every native radio among the candidates → the radios of its unit (same `name` under the\n * container, DOM order). A radio without a `name` is a unit of one.\n */\n readonly units: Map<HTMLElement, readonly HTMLInputElement[]>;\n}\n\n/** The unit's representative: its checked radio, else its first (design 17.2 item 2). */\nfunction representative(unit: readonly HTMLInputElement[]): HTMLInputElement {\n return unit.find((radio) => radio.checked) ?? unit[0]!;\n}\n\n/**\n * The items of `root` (design 6.2 and 17.2): its focusable descendants minus `:disabled`,\n * `inert`, invisible, nested-toolbar / popover / dialog content, and elements whose own\n * `tabindex=\"-1\"` was not written by this engine (`managed`). `aria-disabled` elements are items.\n * Native radios that share a `name` form one unit, represented in `items` by its checked radio\n * (else its first), at the position of the unit's first radio.\n */\nexport function collectItems(\n root: HTMLElement,\n managed: { has(el: Element): boolean },\n): RovingItems {\n const candidates: HTMLElement[] = [];\n const byName = new Map<string, HTMLInputElement[]>();\n const units = new Map<HTMLElement, readonly HTMLInputElement[]>();\n for (const el of root.querySelectorAll<HTMLElement>(FOCUSABLE)) {\n if (el.matches(\":disabled\")) continue;\n if (el.closest(\"[inert]\") !== null) continue;\n if (el.getAttribute(\"tabindex\") === \"-1\" && !managed.has(el)) continue;\n if (isNestedOut(el, root)) continue;\n if (!isVisible(el)) continue;\n if (isRadio(el)) {\n // Same form owner assumed: a `form=` attribute that splits a `name` is not handled (v1).\n const unit = el.name === \"\" ? undefined : byName.get(el.name);\n if (unit !== undefined) {\n unit.push(el);\n units.set(el, unit);\n continue;\n }\n const created = [el];\n if (el.name !== \"\") byName.set(el.name, created);\n units.set(el, created);\n }\n candidates.push(el);\n }\n // `candidates` holds each unit's first radio in its place; swap in the representative.\n const items = candidates.map((el) => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n });\n return { items, units };\n}\n\n/** {@link collectItems}'s `items`: the container's destinations in DOM order. */\nexport function itemsOf(root: HTMLElement, managed: { has(el: Element): boolean }): HTMLElement[] {\n return collectItems(root, managed).items;\n}\n\nconst BUTTON_LIKE_INPUTS = new Set([\n \"button\",\n \"submit\",\n \"reset\",\n \"checkbox\",\n \"image\",\n \"color\",\n \"file\",\n]);\nconst ARROW_OWNING_ROLES = new Set([\"textbox\", \"combobox\", \"spinbutton\", \"slider\"]);\n\n/**\n * An item that owns the arrow keys (design 6.3 and 17.2): text-like `input`s, `textarea`,\n * `select`, `[contenteditable]`, `role` `textbox` / `combobox` / `spinbutton` / `slider`, and a\n * native `input[type=radio]` (its group's own arrows check as they move). A custom\n * `[role=\"radio\"]` is an ordinary item, as it is under native `focusgroup`.\n */\nexport function ownsArrows(el: Element): boolean {\n const role = el.getAttribute(\"role\");\n if (role !== null && ARROW_OWNING_ROLES.has(role)) return true;\n if (el instanceof HTMLInputElement) return !BUTTON_LIKE_INPUTS.has(el.type);\n if (el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) return true;\n const editable = el.getAttribute(\"contenteditable\");\n if (editable !== null && editable !== \"false\") return true;\n return el instanceof HTMLElement && el.isContentEditable === true;\n}\n\ninterface Engine {\n /** The options of the last committed render (written from an insertion effect). */\n readonly setOptions: (options: RovingFocusOptions) => void;\n /**\n * Re-derives the Tab stop of `root` and writes `tabindex`. `focused`: the element focus is on,\n * if any.\n */\n readonly apply: (root: HTMLElement | null, focused: Element | null) => void;\n readonly handlers: RovingFocusHandlers;\n}\n\nfunction createEngine(): Engine {\n let current: HTMLElement | null = null;\n let latestOptions: RovingFocusOptions | null = null;\n /**\n * Elements this engine wrote `tabindex` on, with the attribute value they had before the first\n * write (`null`: none). Restored when the engine lets go of an element (native path, element\n * left the container): React does not re-write a `tabIndex` prop it believes it rendered, so a\n * `[tabindex=\"0\"]` widget would otherwise become unreachable.\n */\n const managed = new Map<HTMLElement, string | null>();\n\n const restore = (el: HTMLElement) => {\n const original = managed.get(el);\n managed.delete(el);\n if (!el.isConnected || original === undefined) return;\n if (original === null) el.removeAttribute(\"tabindex\");\n else el.setAttribute(\"tabindex\", original);\n };\n\n const active = (options: RovingFocusOptions | null): options is RovingFocusOptions =>\n options !== null && options.enabled !== false;\n\n /** Native path: give back every `tabindex` this engine wrote (a hydration render may have). */\n const release = () => {\n for (const el of [...managed.keys()]) restore(el);\n current = null;\n };\n\n const apply = (root: HTMLElement | null, focused: Element | null) => {\n const options = latestOptions;\n if (root === null || !active(options)) return;\n if (options.native) {\n release();\n return;\n }\n const { items, units } = collectItems(root, managed);\n /** Every element the engine writes: the items and the other radios of their units. */\n const all = new Set<HTMLElement>(items);\n for (const radio of units.keys()) all.add(radio);\n /** The item standing for `el`: its unit's representative for a radio, else itself. */\n const itemOf = (el: HTMLElement): HTMLElement => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n };\n if (!options.memory) {\n current =\n focused instanceof HTMLElement && all.has(focused)\n ? focused\n : (options.entry(items) ?? null);\n } else if (current === null || !all.has(current) || !items.includes(itemOf(current))) {\n current = options.entry(items) ?? null;\n }\n // `current` may be any radio of its unit (focus landed on an unchecked one): `0` on it, `-1`\n // on the unit's other radios and on every other element (design 17.2 item 5).\n for (const el of all) {\n if (!managed.has(el)) managed.set(el, el.getAttribute(\"tabindex\"));\n const want = el === current ? \"0\" : \"-1\";\n if (el.getAttribute(\"tabindex\") !== want) el.setAttribute(\"tabindex\", want);\n }\n // Elements written before that are no longer items: a stale `0` must not stay a Tab stop\n // (it would be one again when re-enabled); one that left the container gets its own back.\n for (const el of [...managed.keys()]) {\n if (all.has(el)) continue;\n if (!root.contains(el)) {\n restore(el);\n } else if (el.getAttribute(\"tabindex\") !== \"-1\") {\n el.setAttribute(\"tabindex\", \"-1\");\n }\n }\n };\n\n const onFocus = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n if (!items.includes(target) && !units.has(target)) return;\n current = target;\n apply(event.currentTarget, target);\n };\n\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native || options.memory) return;\n // Focus moving to another item is handled by its focus event.\n const next = event.relatedTarget;\n if (next instanceof Node && event.currentTarget.contains(next)) return;\n apply(event.currentTarget, null);\n };\n\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof Node)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n // Safari does not focus a button on click; the pointer still makes it the stop.\n const item = [...items, ...units.keys()].find((el) => el.contains(target));\n if (item === undefined) return;\n current = item;\n apply(\n event.currentTarget,\n options.memory ? item : event.currentTarget.ownerDocument.activeElement,\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const options = latestOptions;\n // The browser moves focus itself where `focusgroup` is implemented.\n if (!active(options) || options.native) return;\n const root = event.currentTarget;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(root, managed);\n const unit = units.get(target);\n // A radio stands in `items` through its unit's representative.\n const index = items.indexOf(unit === undefined ? target : representative(unit));\n if (index < 0) return;\n\n if (ownsArrows(target)) {\n // The item keeps its arrows, Home and End; Tab / Shift+Tab move to the next / previous item\n // while one exists, as Chromium's `focusgroup=\"toolbar\"` does (design 6.3, 17.2 item 4).\n if (event.key !== \"Tab\") return;\n // From an unchecked radio whose sibling is checked: that sibling first (only the checked\n // radio of a group is sequentially focusable natively).\n const checked = unit?.find((radio) => radio.checked);\n if (checked !== undefined && checked !== target) {\n event.preventDefault();\n focusWithRing(checked);\n return;\n }\n const next = items[index + (event.shiftKey ? -1 : 1)];\n if (next === undefined) return;\n event.preventDefault();\n focusWithRing(next);\n return;\n }\n\n const rtl = options.orientation === \"horizontal\" && getComputedStyle(root).direction === \"rtl\";\n const move = resolveArrowKey(event.key, options.orientation, rtl);\n if (move === null) return;\n event.preventDefault();\n const last = items.length - 1;\n let nextIndex: number;\n switch (move) {\n case \"first\":\n nextIndex = 0;\n break;\n case \"last\":\n nextIndex = last;\n break;\n case \"next\":\n nextIndex = index >= last ? (options.loop ? 0 : last) : index + 1;\n break;\n case \"prev\":\n nextIndex = index <= 0 ? (options.loop ? last : 0) : index - 1;\n break;\n }\n const next = items[nextIndex];\n if (next !== undefined && next !== target) focusWithRing(next);\n };\n\n return {\n setOptions: (options) => {\n latestOptions = options;\n },\n apply,\n handlers: { onFocus, onBlur, onPointerDown, onKeyDown },\n };\n}\n\n/**\n * Roving focus over the focusable descendants of `ref`'s element (design 6.2). Writes `tabindex`\n * (`0` on the Tab stop, `-1` on the other items) from a layout effect after every commit of the\n * calling component, from a `MutationObserver` on the subtree and from focus / pointer events;\n * the items render none. Returns the container's handlers for its library props.\n */\nexport function useRovingFocus(\n ref: RefObject<HTMLElement | null>,\n options: RovingFocusOptions,\n): RovingFocusHandlers {\n const [engine] = useState(createEngine);\n // Before every layout effect of the same commit (as `useLatest`): handlers and the observer\n // read the options of the last committed render.\n useInsertionEffect(() => {\n engine.setOptions(options);\n });\n const enabled = options.enabled !== false;\n\n // After every commit of the container (a deps-less layout effect).\n useLayoutEffect(() => {\n const root = ref.current;\n engine.apply(root, root?.ownerDocument.activeElement ?? null);\n });\n\n // Children that change without the container re-rendering.\n useEffect(() => {\n const root = ref.current;\n if (!enabled || root === null) return;\n const observer = new MutationObserver(() => {\n engine.apply(root, root.ownerDocument.activeElement);\n });\n observer.observe(root, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"disabled\", \"hidden\", \"inert\", \"aria-disabled\"],\n });\n return () => {\n observer.disconnect();\n };\n }, [engine, enabled, ref]);\n\n return engine.handlers;\n}\n"],"mappings":";;;;AAqCA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,SAAS,UAAU,IAA0B;CAE3C,IAAI,OAAO,GAAG,oBAAoB,YAAY,OAAO,GAAG,gBAAgB;CACxE,OAAO,GAAG,QAAQ,UAAU,MAAM;AACpC;;;;;;AAOA,SAAS,YAAY,IAAiB,MAA4B;CAChE,KAAK,IAAI,OAAuB,IAAI,SAAS,QAAQ,SAAS,MAAM,OAAO,KAAK,eAC9E,IACE,KAAK,aAAa,MAAM,MAAM,aAC9B,KAAK,aAAa,SAAS,KAC3B,KAAK,YAAY,UAEjB,OAAO;CAGX,OAAO;AACT;AAEA,SAAS,QAAQ,IAAqC;CACpD,OAAO,cAAc,oBAAoB,GAAG,SAAS;AACvD;;AAcA,SAAS,eAAe,MAAqD;CAC3E,OAAO,KAAK,MAAM,UAAU,MAAM,OAAO,KAAK,KAAK;AACrD;;;;;;;;AASA,SAAgB,aACd,MACA,SACa;CACb,MAAM,aAA4B,CAAC;CACnC,MAAM,yBAAS,IAAI,IAAgC;CACnD,MAAM,wBAAQ,IAAI,IAA8C;CAChE,KAAK,MAAM,MAAM,KAAK,iBAA8B,SAAS,GAAG;EAC9D,IAAI,GAAG,QAAQ,WAAW,GAAG;EAC7B,IAAI,GAAG,QAAQ,SAAS,MAAM,MAAM;EACpC,IAAI,GAAG,aAAa,UAAU,MAAM,QAAQ,CAAC,QAAQ,IAAI,EAAE,GAAG;EAC9D,IAAI,YAAY,IAAI,IAAI,GAAG;EAC3B,IAAI,CAAC,UAAU,EAAE,GAAG;EACpB,IAAI,QAAQ,EAAE,GAAG;GAEf,MA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AAe;EAAU;CACxD;AACF;;;;;;;AAQA,SAAgB,eACd,KACA,SACqB;CACrB,MAAM,CAAC,UAAU,SAAS,YAAY;CAGtC,yBAAyB;EACvB,OAAO,WAAW,OAAO;CAC3B,CAAC;CACD,MAAM,UAAU,QAAQ,YAAY;CAGpC,sBAAsB;EACpB,MAAM,OAAO,IAAI;EACjB,OAAO,MAAM,MAAM,MAAM,cAAc,iBAAiB,IAAI;CAC9D,CAAC;CAGD,gBAAgB;EACd,MAAM,OAAO,IAAI;EACjB,IAAI,CAAC,WAAW,SAAS,MAAM;EAC/B,MAAM,WAAW,IAAI,uBAAuB;GAC1C,OAAO,MAAM,MAAM,KAAK,cAAc,aAAa;EACrD,CAAC;EACD,SAAS,QAAQ,MAAM;GACrB,WAAW;GACX,SAAS;GACT,YAAY;GACZ,iBAAiB;IAAC;IAAY;IAAU;IAAS;GAAe;EAClE,CAAC;EACD,aAAa;GACX,SAAS,WAAW;EACtB;CACF,GAAG;EAAC;EAAQ;EAAS;CAAG,CAAC;CAEzB,OAAO,OAAO;AAChB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
//#region src/internal/use-superseded-rejection.ts
|
|
4
|
+
/** Reports an error that cannot reach a boundary (conventions 2.4: never swallow). */
|
|
5
|
+
function report(error) {
|
|
6
|
+
if (typeof reportError === "function") reportError(error);
|
|
7
|
+
else console.error(error);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Surfaces the rejections of superseded transitions (conventions 2.4) for `useControllableAction`
|
|
11
|
+
* and `useActionTrigger`. React keeps only the newest thenable per `useTransition`, so a rejection
|
|
12
|
+
* from a run that a later run superseded would be dropped entirely (no boundary, no
|
|
13
|
+
* `reportError`). The caller rethrows the latest run's rejection itself (React's own route to the
|
|
14
|
+
* boundary) and hands any other to the returned `capture`: the first is thrown from render, so it
|
|
15
|
+
* reaches the same nearest Error Boundary; later ones of the burst are reported. Nothing is thrown
|
|
16
|
+
* once unmounted (React drops its own thenables the same way).
|
|
17
|
+
*
|
|
18
|
+
* Call it **before `useTransition`**: React retries an errored render with every pending lane,
|
|
19
|
+
* and in that retry `useTransition` unwraps the still-pending action thenable and suspends, which
|
|
20
|
+
* would hold the boundary commit until the newer action settles.
|
|
21
|
+
*/
|
|
22
|
+
function useSupersededRejection() {
|
|
23
|
+
const [superseded, setSuperseded] = useState(null);
|
|
24
|
+
const captured = useRef(false);
|
|
25
|
+
const mounted = useRef(false);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
mounted.current = true;
|
|
28
|
+
return () => {
|
|
29
|
+
mounted.current = false;
|
|
30
|
+
};
|
|
31
|
+
}, []);
|
|
32
|
+
const capture = useCallback((error) => {
|
|
33
|
+
if (!mounted.current) return;
|
|
34
|
+
if (captured.current) {
|
|
35
|
+
report(error);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
captured.current = true;
|
|
39
|
+
setSuperseded({ error });
|
|
40
|
+
}, []);
|
|
41
|
+
if (superseded !== null) throw superseded.error;
|
|
42
|
+
return capture;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { useSupersededRejection };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=use-superseded-rejection.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-superseded-rejection.mjs","names":[],"sources":["../../src/internal/use-superseded-rejection.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\n/** Reports an error that cannot reach a boundary (conventions 2.4: never swallow). */\nfunction report(error: unknown): void {\n if (typeof reportError === \"function\") reportError(error);\n else console.error(error);\n}\n\n/**\n * Surfaces the rejections of superseded transitions (conventions 2.4) for `useControllableAction`\n * and `useActionTrigger`. React keeps only the newest thenable per `useTransition`, so a rejection\n * from a run that a later run superseded would be dropped entirely (no boundary, no\n * `reportError`). The caller rethrows the latest run's rejection itself (React's own route to the\n * boundary) and hands any other to the returned `capture`: the first is thrown from render, so it\n * reaches the same nearest Error Boundary; later ones of the burst are reported. Nothing is thrown\n * once unmounted (React drops its own thenables the same way).\n *\n * Call it **before `useTransition`**: React retries an errored render with every pending lane,\n * and in that retry `useTransition` unwraps the still-pending action thenable and suspends, which\n * would hold the boundary commit until the newer action settles.\n */\nexport function useSupersededRejection(): (error: unknown) => void {\n const [superseded, setSuperseded] = useState<{ readonly error: unknown } | null>(null);\n const captured = useRef(false);\n const mounted = useRef(false);\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n const capture = useCallback((error: unknown): void => {\n if (!mounted.current) return;\n if (captured.current) {\n // One boundary reset per burst is enough; later errors are still reported.\n report(error);\n return;\n }\n captured.current = true;\n // Called after an await, outside the transition: an urgent update, so the owner re-renders\n // promptly and throws.\n setSuperseded({ error });\n }, []);\n\n if (superseded !== null) throw superseded.error;\n return capture;\n}\n"],"mappings":";;;;AAIA,SAAS,OAAO,OAAsB;CACpC,IAAI,OAAO,gBAAgB,YAAY,YAAY,KAAK;MACnD,QAAQ,MAAM,KAAK;AAC1B;;;;;;;;;;;;;;AAeA,SAAgB,yBAAmD;CACjE,MAAM,CAAC,YAAY,iBAAiB,SAA6C,IAAI;CACrF,MAAM,WAAW,OAAO,KAAK;CAC7B,MAAM,UAAU,OAAO,KAAK;CAE5B,gBAAgB;EACd,QAAQ,UAAU;EAClB,aAAa;GACX,QAAQ,UAAU;EACpB;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,UAAU,aAAa,UAAyB;EACpD,IAAI,CAAC,QAAQ,SAAS;EACtB,IAAI,SAAS,SAAS;GAEpB,OAAO,KAAK;GACZ;EACF;EACA,SAAS,UAAU;EAGnB,cAAc,EAAE,MAAM,CAAC;CACzB,GAAG,CAAC,CAAC;CAEL,IAAI,eAAe,MAAM,MAAM,WAAW;CAC1C,OAAO;AACT"}
|
|
@@ -33,9 +33,6 @@ function snapshotValidity(validity) {
|
|
|
33
33
|
function validityEquals(a, b) {
|
|
34
34
|
return VALIDITY_KEYS.every((key) => a[key] === b[key]);
|
|
35
35
|
}
|
|
36
|
-
function arraysEqual(a, b) {
|
|
37
|
-
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
38
|
-
}
|
|
39
36
|
const NONE = Object.freeze([]);
|
|
40
37
|
/** `""`, `[]`, `null` and `undefined` mean no error; empty strings inside an array are dropped. */
|
|
41
38
|
function normaliseErrorValue(value) {
|
|
@@ -93,16 +90,7 @@ function focusTargetOf(el) {
|
|
|
93
90
|
const members = (el instanceof HTMLFieldSetElement ? [...el.elements] : [...el.querySelectorAll("input, select, textarea, button")]).filter((m) => m instanceof HTMLElement && !m.disabled && m.type !== "hidden");
|
|
94
91
|
return members.find((m) => m instanceof HTMLInputElement && m.type === "radio" && m.checked) ?? members.find((m) => isValidatable(m) && m.name !== "") ?? members.find(isValidatable) ?? members[0] ?? null;
|
|
95
92
|
}
|
|
96
|
-
/** Sorts elements into document order. */
|
|
97
|
-
function sortByDocumentOrder(items, elementOf) {
|
|
98
|
-
return [...items].sort((a, b) => {
|
|
99
|
-
const position = elementOf(a).compareDocumentPosition(elementOf(b));
|
|
100
|
-
if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
|
101
|
-
if (position & Node.DOCUMENT_POSITION_PRECEDING) return 1;
|
|
102
|
-
return 0;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
93
|
//#endregion
|
|
106
|
-
export { VALID,
|
|
94
|
+
export { VALID, focusTargetOf, hasAnyError, normaliseErrorValue, snapshotValidity, supportsUserInvalid, validityElementOf, validityEquals };
|
|
107
95
|
|
|
108
96
|
//# sourceMappingURL=validity.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validity.mjs","names":[],"sources":["../../src/internal/validity.ts"],"sourcesContent":["// Directive-free helpers for Field and Form (design/components/field-form.md 2, 14): the validity\n// snapshot, error-value normalisation, the `:user-invalid` read and the element resolution.\n\n/** A field error: a message, several messages, or nothing (`\"\"`, `[]`, `null`, `undefined`). */\nexport type FieldErrorValue = string | readonly string[] | null | undefined;\n\n/** Field errors keyed by field `name` (usually `state.errors` from `useActionState`). */\nexport type FormErrors = Readonly<Record<string, FieldErrorValue>>;\n\n/**\n * A plain, serialisable snapshot of the control's `ValidityState` (all `false` and\n * `valid: true` on the server and before the first read).\n */\nexport interface FieldValidity {\n readonly valueMissing: boolean;\n readonly typeMismatch: boolean;\n readonly patternMismatch: boolean;\n readonly tooLong: boolean;\n readonly tooShort: boolean;\n readonly rangeUnderflow: boolean;\n readonly rangeOverflow: boolean;\n readonly stepMismatch: boolean;\n readonly badInput: boolean;\n readonly customError: boolean;\n readonly valid: boolean;\n}\n\nconst VALIDITY_KEYS = [\n \"valueMissing\",\n \"typeMismatch\",\n \"patternMismatch\",\n \"tooLong\",\n \"tooShort\",\n \"rangeUnderflow\",\n \"rangeOverflow\",\n \"stepMismatch\",\n \"badInput\",\n \"customError\",\n \"valid\",\n] as const satisfies readonly (keyof FieldValidity)[];\n\nexport const VALID: FieldValidity = Object.freeze({\n valueMissing: false,\n typeMismatch: false,\n patternMismatch: false,\n tooLong: false,\n tooShort: false,\n rangeUnderflow: false,\n rangeOverflow: false,\n stepMismatch: false,\n badInput: false,\n customError: false,\n valid: true,\n});\n\nexport function snapshotValidity(validity: ValidityState): FieldValidity {\n const result = {} as Record<keyof FieldValidity, boolean>;\n for (const key of VALIDITY_KEYS) result[key] = validity[key];\n return result;\n}\n\nexport function validityEquals(a: FieldValidity, b: FieldValidity): boolean {\n return VALIDITY_KEYS.every((key) => a[key] === b[key]);\n}\n\
|
|
1
|
+
{"version":3,"file":"validity.mjs","names":[],"sources":["../../src/internal/validity.ts"],"sourcesContent":["// Directive-free helpers for Field and Form (design/components/field-form.md 2, 14): the validity\n// snapshot, error-value normalisation, the `:user-invalid` read and the element resolution.\n\n/** A field error: a message, several messages, or nothing (`\"\"`, `[]`, `null`, `undefined`). */\nexport type FieldErrorValue = string | readonly string[] | null | undefined;\n\n/** Field errors keyed by field `name` (usually `state.errors` from `useActionState`). */\nexport type FormErrors = Readonly<Record<string, FieldErrorValue>>;\n\n/**\n * A plain, serialisable snapshot of the control's `ValidityState` (all `false` and\n * `valid: true` on the server and before the first read).\n */\nexport interface FieldValidity {\n readonly valueMissing: boolean;\n readonly typeMismatch: boolean;\n readonly patternMismatch: boolean;\n readonly tooLong: boolean;\n readonly tooShort: boolean;\n readonly rangeUnderflow: boolean;\n readonly rangeOverflow: boolean;\n readonly stepMismatch: boolean;\n readonly badInput: boolean;\n readonly customError: boolean;\n readonly valid: boolean;\n}\n\nconst VALIDITY_KEYS = [\n \"valueMissing\",\n \"typeMismatch\",\n \"patternMismatch\",\n \"tooLong\",\n \"tooShort\",\n \"rangeUnderflow\",\n \"rangeOverflow\",\n \"stepMismatch\",\n \"badInput\",\n \"customError\",\n \"valid\",\n] as const satisfies readonly (keyof FieldValidity)[];\n\nexport const VALID: FieldValidity = Object.freeze({\n valueMissing: false,\n typeMismatch: false,\n patternMismatch: false,\n tooLong: false,\n tooShort: false,\n rangeUnderflow: false,\n rangeOverflow: false,\n stepMismatch: false,\n badInput: false,\n customError: false,\n valid: true,\n});\n\nexport function snapshotValidity(validity: ValidityState): FieldValidity {\n const result = {} as Record<keyof FieldValidity, boolean>;\n for (const key of VALIDITY_KEYS) result[key] = validity[key];\n return result;\n}\n\nexport function validityEquals(a: FieldValidity, b: FieldValidity): boolean {\n return VALIDITY_KEYS.every((key) => a[key] === b[key]);\n}\n\nconst NONE: readonly string[] = Object.freeze([]);\n\n/** `\"\"`, `[]`, `null` and `undefined` mean no error; empty strings inside an array are dropped. */\nexport function normaliseErrorValue(value: FieldErrorValue): readonly string[] {\n if (value === null || value === undefined || value === \"\") return NONE;\n if (typeof value === \"string\") return [value];\n const list = value.filter((v) => typeof v === \"string\" && v !== \"\");\n return list.length === 0 ? NONE : list;\n}\n\n/** Some entry of `errors` is a non-empty error. */\nexport function hasAnyError(errors: FormErrors | undefined): boolean {\n if (errors === undefined) return false;\n return Object.values(errors).some((v) => normaliseErrorValue(v).length > 0);\n}\n\nlet userInvalidSupport: boolean | undefined;\n\n/**\n * Whether the environment implements `:user-invalid` (every engine the library supports does).\n * Decided once per module, so the read is not on a hot path.\n *\n * Detected with `CSS.supports(\"selector(:user-invalid)\")` rather than by `matches()` throwing:\n * jsdom 30's selector engine knows the name and silently answers `false` (it does not throw), and\n * its `CSS.supports` reports `false`, so the fallback engages there and nowhere else\n * (memo/developer/field-form.md).\n */\nexport function supportsUserInvalid(): boolean {\n if (userInvalidSupport === undefined) {\n try {\n userInvalidSupport =\n typeof CSS !== \"undefined\" &&\n typeof CSS.supports === \"function\" &&\n CSS.supports(\"selector(:user-invalid)\");\n } catch {\n userInvalidSupport = false;\n }\n }\n return userInvalidSupport;\n}\n\n/** An element that takes part in constraint validation. */\nexport type ValidatableElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n\nfunction isValidatable(el: Element): el is ValidatableElement {\n return (\n el instanceof HTMLInputElement ||\n el instanceof HTMLSelectElement ||\n el instanceof HTMLTextAreaElement\n );\n}\n\n/**\n * Where `validity`, `validationMessage`, `:user-invalid` and `setCustomValidity` are read and\n * written (design 7.1): the element itself when it is a form control, else the first named\n * `willValidate` member of a `<fieldset>` (a group's first enabled item, not a CheckboxGroup\n * Parent, which has no name), else the first `input` / `select` / `textarea` inside.\n */\nexport function validityElementOf(el: Element | null): ValidatableElement | null {\n if (el === null) return null;\n if (isValidatable(el)) return el;\n const members =\n el instanceof HTMLFieldSetElement\n ? [...el.elements]\n : [...el.querySelectorAll(\"input, select, textarea\")];\n const controls = members.filter(isValidatable);\n return (\n controls.find((c) => c.willValidate && c.name !== \"\") ??\n controls.find((c) => c.willValidate) ??\n controls[0] ??\n null\n );\n}\n\n/**\n * What the Field focuses (design 2.5): the control itself, or for a group the checked radio if\n * any, else the first enabled named member (a group's first item, not a CheckboxGroup Parent,\n * which has no name), else the first enabled member.\n */\nexport function focusTargetOf(el: Element | null): HTMLElement | null {\n if (el === null) return null;\n if (isValidatable(el)) return el;\n const members = (\n el instanceof HTMLFieldSetElement\n ? [...el.elements]\n : [...el.querySelectorAll(\"input, select, textarea, button\")]\n ).filter(\n (m): m is HTMLElement =>\n m instanceof HTMLElement &&\n !(m as HTMLInputElement).disabled &&\n (m as HTMLInputElement).type !== \"hidden\",\n );\n const checkedRadio = members.find(\n (m) => m instanceof HTMLInputElement && m.type === \"radio\" && m.checked,\n );\n return (\n checkedRadio ??\n members.find((m) => isValidatable(m) && m.name !== \"\") ??\n members.find(isValidatable) ??\n members[0] ??\n null\n );\n}\n"],"mappings":";AA2BA,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,QAAuB,OAAO,OAAO;CAChD,cAAc;CACd,cAAc;CACd,iBAAiB;CACjB,SAAS;CACT,UAAU;CACV,gBAAgB;CAChB,eAAe;CACf,cAAc;CACd,UAAU;CACV,aAAa;CACb,OAAO;AACT,CAAC;AAED,SAAgB,iBAAiB,UAAwC;CACvE,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,OAAO,eAAe,OAAO,OAAO,SAAS;CACxD,OAAO;AACT;AAEA,SAAgB,eAAe,GAAkB,GAA2B;CAC1E,OAAO,cAAc,OAAO,QAAQ,EAAE,SAAS,EAAE,IAAI;AACvD;AAEA,MAAM,OAA0B,OAAO,OAAO,CAAC,CAAC;;AAGhD,SAAgB,oBAAoB,OAA2C;CAC7E,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,IAAI,OAAO;CAClE,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;CAC5C,MAAM,OAAO,MAAM,QAAQ,MAAM,OAAO,MAAM,YAAY,MAAM,EAAE;CAClE,OAAO,KAAK,WAAW,IAAI,OAAO;AACpC;;AAGA,SAAgB,YAAY,QAAyC;CACnE,IAAI,WAAW,KAAA,GA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41 @@
|
|
|
1
|
+
//#region src/internal/value-set.ts
|
|
2
|
+
const EMPTY_SET = /* @__PURE__ */ new Set();
|
|
3
|
+
/** A value prop as a set: `null` is empty, a string is one value, an array is its values. */
|
|
4
|
+
function toSet(value) {
|
|
5
|
+
if (value === null) return EMPTY_SET;
|
|
6
|
+
return typeof value === "string" ? /* @__PURE__ */ new Set([value]) : new Set(value);
|
|
7
|
+
}
|
|
8
|
+
function setsEqual(a, b) {
|
|
9
|
+
if (a.size !== b.size) return false;
|
|
10
|
+
for (const v of a) if (!b.has(v)) return false;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
/** The optimistic reducer of a patch-based group: apply a patch, so stacked dispatches re-base. */
|
|
14
|
+
function applyPatch(set, patch) {
|
|
15
|
+
const next = new Set(set);
|
|
16
|
+
for (const v of patch.removed) next.delete(v);
|
|
17
|
+
for (const v of patch.added) next.add(v);
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `values` sorted by `order` (the Items' values in document order); values not in `order` keep
|
|
22
|
+
* their iteration order, after the others.
|
|
23
|
+
*/
|
|
24
|
+
function sortByOrder(values, order) {
|
|
25
|
+
const wanted = new Set(values);
|
|
26
|
+
const sorted = [];
|
|
27
|
+
for (const v of order) if (wanted.delete(v)) sorted.push(v);
|
|
28
|
+
for (const v of wanted) sorted.push(v);
|
|
29
|
+
return sorted;
|
|
30
|
+
}
|
|
31
|
+
function arraysEqual(a, b) {
|
|
32
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
33
|
+
}
|
|
34
|
+
/** The first value that occurs twice in `values`, or `undefined`. */
|
|
35
|
+
function firstDuplicate(values) {
|
|
36
|
+
return values.find((v, i) => values.indexOf(v) !== i);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { EMPTY_SET, applyPatch, arraysEqual, firstDuplicate, setsEqual, sortByOrder, toSet };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=value-set.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-set.mjs","names":[],"sources":["../../src/internal/value-set.ts"],"sourcesContent":["// Set and order helpers of the set-valued components (CheckboxGroup, ToggleGroup, Accordion) and\n// Field. No directive: pure functions (conventions 7.1).\n\nexport type ValueSet = ReadonlySet<string>;\n\nexport const EMPTY_SET: ValueSet = new Set();\n\n/** A value prop as a set: `null` is empty, a string is one value, an array is its values. */\nexport function toSet(value: string | readonly string[] | null): ValueSet {\n if (value === null) return EMPTY_SET;\n return typeof value === \"string\" ? new Set([value]) : new Set(value);\n}\n\nexport function setsEqual(a: ValueSet, b: ValueSet): boolean {\n if (a.size !== b.size) return false;\n for (const v of a) if (!b.has(v)) return false;\n return true;\n}\n\n/** A change to a set of values (conventions 2.2: the `added` / `removed` diff). */\nexport interface SetPatch {\n readonly added: readonly string[];\n readonly removed: readonly string[];\n}\n\n/** The optimistic reducer of a patch-based group: apply a patch, so stacked dispatches re-base. */\nexport function applyPatch(set: ValueSet, patch: SetPatch): ValueSet {\n const next = new Set(set);\n for (const v of patch.removed) next.delete(v);\n for (const v of patch.added) next.add(v);\n return next;\n}\n\n/**\n * `values` sorted by `order` (the Items' values in document order); values not in `order` keep\n * their iteration order, after the others.\n */\nexport function sortByOrder(values: Iterable<string>, order: readonly string[]): string[] {\n const wanted = new Set(values);\n const sorted: string[] = [];\n for (const v of order) if (wanted.delete(v)) sorted.push(v);\n for (const v of wanted) sorted.push(v);\n return sorted;\n}\n\nexport function arraysEqual(a: readonly string[], b: readonly string[]): boolean {\n return a.length === b.length && a.every((v, i) => v === b[i]);\n}\n\n/** The first value that occurs twice in `values`, or `undefined`. */\nexport function firstDuplicate(values: readonly string[]): string | undefined {\n return values.find((v, i) => values.indexOf(v) !== i);\n}\n"],"mappings":";AAKA,MAAa,4BAAsB,IAAI,IAAI;;AAG3C,SAAgB,MAAM,OAAoD;CACxE,IAAI,UAAU,MAAM,OAAO;CAC3B,OAAO,OAAO,UAAU,2BAAW,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,KAAK;AACrE;AAEA,SAAgB,UAAU,GAAa,GAAsB;CAC3D,IAAI,EAAE,SAAS,EAAE,MAAM,OAAO;CAC9B,KAAK,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,OAAO;CACzC,OAAO;AACT;;AASA,SAAgB,WAAW,KAAe,OAA2B;CACnE,MAAM,OAAO,IAAI,IAAI,GAAG;CACxB,KAAK,MAAM,KAAK,MAAM,SAAS,KAAK,OAAO,CAAC;CAC5C,KAAK,MAAM,KAAK,MAAM,OAAO,KAAK,IAAI,CAAC;CACvC,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,QAA0B,OAAoC;CACxF,MAAM,SAAS,IAAI,IAAI,MAAM;CAC7B,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,KAAK,OAAO,IAAI,OAAO,OAAO,CAAC,GAAG,OAAO,KAAK,CAAC;CAC1D,KAAK,MAAM,KAAK,QAAQ,OAAO,KAAK,CAAC;CACrC,OAAO;AACT;AAEA,SAAgB,YAAY,GAAsB,GAA+B;CAC/E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,MAAM,EAAE,EAAE;AAC9D;;AAGA,SAAgB,eAAe,QAA+C;CAC5E,OAAO,OAAO,MAAM,GAAG,MAAM,OAAO,QAAQ,CAAC,MAAM,CAAC;AACtD"}
|
package/dist/menu/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "../internal/platform-attributes.mjs";
|
|
2
2
|
import { MenuItem, MenuItemDetails, MenuItemProps, MenuItemState } from "./menu-item.mjs";
|
|
3
3
|
import { MenuCheckboxItem, MenuCheckboxItemProps, MenuCheckboxItemState } from "./menu-checkbox-item.mjs";
|
|
4
|
+
import { MenuTrigger, MenuTriggerProps, MenuTriggerState } from "./menu-trigger.mjs";
|
|
4
5
|
import { MenuContextTrigger, MenuContextTriggerProps, MenuContextTriggerState } from "./menu-context-trigger.mjs";
|
|
5
6
|
import { MenuGroup, MenuGroupLabel, MenuGroupLabelProps, MenuGroupLabelState, MenuGroupProps, MenuGroupState, MenuSeparator, MenuSeparatorProps, MenuSeparatorState } from "./menu-group.mjs";
|
|
6
7
|
import { MenuAlign, MenuPopup, MenuPopupProps, MenuPopupState, MenuSide } from "./menu-popup.mjs";
|
|
7
8
|
import { MenuRadioGroup, MenuRadioGroupProps, MenuRadioGroupState } from "./menu-radio-group.mjs";
|
|
8
9
|
import { MenuRadioItem, MenuRadioItemProps, MenuRadioItemState } from "./menu-radio-item.mjs";
|
|
9
10
|
import { MenuOpenChangeDetails, MenuRoot, MenuRootProps, MenuRootState } from "./menu-root.mjs";
|
|
10
|
-
import { MenuTrigger, MenuTriggerProps, MenuTriggerState } from "./menu-trigger.mjs";
|
|
11
11
|
import { MenuSubmenuTrigger, MenuSubmenuTriggerProps, MenuSubmenuTriggerState } from "./menu-submenu-trigger.mjs";
|
|
12
12
|
//#region src/menu/index.d.ts
|
|
13
13
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-checkbox-item.mjs","names":[],"sources":["../../src/menu/menu-checkbox-item.tsx"],"sourcesContent":["\"use client\";\nimport { useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"menu-checkbox-item.mjs","names":[],"sources":["../../src/menu/menu-checkbox-item.tsx"],"sourcesContent":["\"use client\";\nimport { useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { closeStackLater, useMenuContext } from \"./menu-context.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nexport interface MenuCheckboxItemState {\n /** Optimistic checked state (`aria-checked`). */\n readonly checked: boolean;\n /** `checkedChangeAction` is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface MenuCheckboxItemProps extends Omit<\n MenuItemProps,\n \"action\" | \"closeOnActivate\" | \"className\" | \"style\" | \"children\" | \"render\"\n> {\n /** Controlled checked state. `undefined` means uncontrolled. */\n checked?: boolean;\n /** Initial checked state when uncontrolled. Default `false`. */\n defaultChecked?: boolean;\n /**\n * Awaited inside the item's transition; `aria-checked` flips at once and rolls back on\n * rejection (which reaches the nearest Error Boundary above the item). May be a Server\n * Function.\n */\n checkedChangeAction?: ChangeAction<boolean>;\n /** Close the whole menu once the change settles. Default `false`: the menu stays open. */\n closeOnActivate?: boolean;\n className?: StateValue<string | undefined, MenuCheckboxItemState>;\n style?: StateValue<CSSProperties | undefined, MenuCheckboxItemState>;\n children?: StateValue<ReactNode, MenuCheckboxItemState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>;\n}\n\n/**\n * A checkable menu item: `<button type=\"button\" role=\"menuitemcheckbox\" aria-checked>`. Click,\n * Enter or Space toggles it through its own transition with optimistic `aria-checked` /\n * `data-checked` and `data-pending`; the menu stays open unless `closeOnActivate`.\n *\n * Owned keys (conventions 1.2): those of `Menu.Item`, plus `aria-checked` and `data-checked`.\n */\nexport function MenuCheckboxItem({\n checked,\n defaultChecked,\n checkedChangeAction,\n closeOnActivate = false,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuCheckboxItemProps) {\n const menu = useMenuContext(\"Menu.CheckboxItem\");\n // The close to run after a dispatch's action resolved, keyed by the dispatch's details.\n const after = useRef(new WeakMap<object, () => void>());\n const { optimistic, pending, dispatch } = useControllableAction<boolean>({\n controlled: checked,\n defaultValue: defaultChecked,\n initialValue: false,\n action: async (next, details) => {\n await checkedChangeAction?.(next, details);\n after.current.get(details)?.();\n },\n transitionTypes: (next) => transitionTypes(\"menu\", next ? \"check\" : \"uncheck\"),\n warn: { component: \"Menu.CheckboxItem\", prop: \"checked\" },\n });\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.CheckboxItem\",\n role: \"menuitemcheckbox\",\n disabled,\n label,\n activate: (event) => {\n const details = createActionDetails(event, {});\n if (closeOnActivate) after.current.set(details, closeStackLater(menu, event));\n dispatch(!optimistic, details);\n },\n });\n\n const state: MenuCheckboxItemState = { checked: optimistic, pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...(rendersButton(render) && { type: \"button\" as const }),\n ...libraryProps,\n \"aria-checked\": optimistic,\n \"data-checked\": dataAttr(optimistic),\n \"data-pending\": dataAttr(pending),\n },\n });\n}\n\nMenuCheckboxItem.displayName = \"MenuCheckboxItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkDA,SAAgB,iBAAiB,EAC/B,SACA,gBACA,qBACA,kBAAkB,OAClB,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,OAAO,eAAe,mBAAmB;CAE/C,MAAM,QAAQ,uBAAO,IAAI,QAA4B,CAAC;CACtD,MAAM,EAAE,YAAY,SAAS,aAAa,sBAA+B;EACvE,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ,OAAO,MAAM,YAAY;GAC/B,MAAM,sBAAsB,MAAM,OAAO;GACzC,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG;EAC/B;EACA,kBAAkB,SAAS,gBAAgB,QAAQ,OAAO,UAAU,SAAS;EAC7E,MAAM;GAAE,WAAW;GAAqB,MAAM;EAAU;CAC1D,CAAC;CAED,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAAU,oBAAoB,OAAO,CAAC,CAAC;GAC7C,IAAI,iBAAiB,MAAM,QAAQ,IAAI,SAAS,gBAAgB,MAAM,KAAK,CAAC;GAC5E,SAAS,CAAC,YAAY,OAAO;EAC/B;CACF,CAAC;CAID,OAAO,UAAkE;EACvE,gBAAgB;EAChB;EACA,OAAA;GALqC,SAAS;GAAY;GAAS;EAK/D;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GACH,gBAAgB;GAChB,gBAAgB,SAAS,UAAU;GACnC,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;AACH;AAEA,iBAAiB,cAAc"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { MenuTriggerState } from "./menu-trigger.mjs";
|
|
2
3
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
4
|
//#region src/menu/menu-context-trigger.d.ts
|
|
4
|
-
export
|
|
5
|
-
/** Optimistic open state (the Root's). */
|
|
6
|
-
readonly open: boolean;
|
|
7
|
-
/** The Root's transition is pending (an open or a close in flight). */
|
|
8
|
-
readonly pending: boolean;
|
|
9
|
-
readonly disabled: boolean;
|
|
10
|
-
}
|
|
5
|
+
export type MenuContextTriggerState = MenuTriggerState;
|
|
11
6
|
export interface MenuContextTriggerProps extends Omit<ComponentPropsWithRef<"div">, "onContextMenu" | "onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerCancel" | "className" | "style" | "children"> {
|
|
12
7
|
/** The region does nothing; a `contextmenu` bubbles on to an outer region. `data-disabled`. */
|
|
13
8
|
disabled?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-context-trigger.d.mts","names":[],"sources":["../../src/menu/menu-context-trigger.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"menu-context-trigger.d.mts","names":[],"sources":["../../src/menu/menu-context-trigger.tsx"],"mappings":";;;;YAgCY,0BAA0B;iBAErB,gCAAgC,KAC/C;;EAWA;;;;;;EAMA;;EAEA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;wBA2BpC,qBACd,UACA,iBACA,gBACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBATV"}
|
|
@@ -3,153 +3,13 @@ import { dataAttr } from "../internal/data-attr.mjs";
|
|
|
3
3
|
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
4
4
|
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
5
5
|
import { useRender } from "../internal/use-render.mjs";
|
|
6
|
-
import { MenuRegionContext, claimPress, isPressClaimed, markHandled,
|
|
7
|
-
import { capturePointer,
|
|
6
|
+
import { MenuRegionContext, claimPress, isPressClaimed, markHandled, useMenuContext } from "./menu-context.mjs";
|
|
7
|
+
import { capturePointer, isEditableTarget } from "./menu-dom.mjs";
|
|
8
|
+
import { armClickSwallow, guardTouch, isTouchLike, startDrag } from "./menu-gestures.mjs";
|
|
8
9
|
import { useCallback, useEffect, useRef } from "react";
|
|
9
10
|
import { jsx } from "react/jsx-runtime";
|
|
10
11
|
//#region src/menu/menu-context-trigger.tsx
|
|
11
|
-
/** Movement that cancels a long-press (Base UI's slop); also a touch drag's activation slop. */
|
|
12
|
-
const LONG_PRESS_SLOP = 10;
|
|
13
|
-
/**
|
|
14
|
-
* Movement a mouse or pen press-drag-release needs before a release activates or dismisses
|
|
15
|
-
* (Chromium's `kMaximumLengthMovedToActivate`, macOS's "moved"; context-menu.md 2.6).
|
|
16
|
-
*/
|
|
17
|
-
const DRAG_SLOP = 4;
|
|
18
|
-
/** A release outside the menu dismisses it only this long after the open (GTK, Base UI). */
|
|
19
|
-
const DRAG_DISMISS_DELAY = 500;
|
|
20
12
|
const isDev = process.env.NODE_ENV !== "production";
|
|
21
|
-
const isTouchLike = (pointerType) => pointerType === "touch" || pointerType === "pen";
|
|
22
|
-
/**
|
|
23
|
-
* Press-drag-release (context-menu.md 2.6): while the popup holds the capture of `pointerId`
|
|
24
|
-
* (taken at the open), every `pointermove` and the `pointerup` target the popup and items never
|
|
25
|
-
* see boundary events, so the gesture hit-tests with `elementFromPoint`. A move focuses the item
|
|
26
|
-
* under the pointer quietly (a SubmenuTrigger also starts its hover intent); a release more than
|
|
27
|
-
* the slop away from the open point activates an enabled, non-submenu item through its
|
|
28
|
-
* `click()` (Menu's one activation path), or dismisses the menu when it lands outside every popup
|
|
29
|
-
* of the tree at least 500 ms after the open; any other release leaves the menu open. Ends at the
|
|
30
|
-
* release, `pointercancel`, `lostpointercapture` and the menu closing. Returns the cleanup.
|
|
31
|
-
*
|
|
32
|
-
* The 500 ms count from when the popup is shown, not from the press: with an async
|
|
33
|
-
* `openChangeAction` or suspending items the menu appears only when they settle (review M2). A
|
|
34
|
-
* gesture that starts on a popup already showing (a move) counts from its start.
|
|
35
|
-
*/
|
|
36
|
-
function startDrag(popup, options) {
|
|
37
|
-
const doc = popup.ownerDocument;
|
|
38
|
-
let shownAt = popup.matches(":popover-open") ? performance.now() : null;
|
|
39
|
-
let submenuTrigger = null;
|
|
40
|
-
const ours = (event) => event.pointerId === options.pointerId;
|
|
41
|
-
const hitTest = (event) => typeof doc.elementFromPoint === "function" ? doc.elementFromPoint(event.clientX, event.clientY) : null;
|
|
42
|
-
/** The item under the pointer, inside this menu's tree (submenus are DOM descendants). */
|
|
43
|
-
const itemAt = (target) => {
|
|
44
|
-
const item = target?.closest("[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]") ?? null;
|
|
45
|
-
return item !== null && popup.contains(item) ? item : null;
|
|
46
|
-
};
|
|
47
|
-
/** The pointer is over the submenu `trigger` opens (its popup is the `commandfor` target). */
|
|
48
|
-
const inSubmenuOf = (trigger, target) => {
|
|
49
|
-
const id = trigger.getAttribute("commandfor");
|
|
50
|
-
const submenu = id === null ? null : doc.getElementById(id);
|
|
51
|
-
return submenu !== null && target !== null && submenu.contains(target);
|
|
52
|
-
};
|
|
53
|
-
const hoverSubmenu = (next, event) => {
|
|
54
|
-
if (next === submenuTrigger) return;
|
|
55
|
-
if (submenuTrigger !== null) submenuHover(submenuTrigger)?.leave(event);
|
|
56
|
-
submenuTrigger = next;
|
|
57
|
-
if (next !== null) submenuHover(next)?.enter(event);
|
|
58
|
-
};
|
|
59
|
-
const onMove = (event) => {
|
|
60
|
-
if (!ours(event)) return;
|
|
61
|
-
const target = hitTest(event);
|
|
62
|
-
const item = itemAt(target);
|
|
63
|
-
if (item !== null && doc.activeElement !== item) item.focus({ focusVisible: false });
|
|
64
|
-
if (item !== null && submenuHover(item) !== void 0) hoverSubmenu(item, event);
|
|
65
|
-
else if (submenuTrigger !== null && !inSubmenuOf(submenuTrigger, target)) hoverSubmenu(null, event);
|
|
66
|
-
};
|
|
67
|
-
const onUp = (event) => {
|
|
68
|
-
if (!ours(event)) return;
|
|
69
|
-
end();
|
|
70
|
-
if (!(Math.hypot(event.clientX - options.x, event.clientY - options.y) > options.slop)) return;
|
|
71
|
-
const target = hitTest(event);
|
|
72
|
-
if (target !== null && popup.contains(target)) {
|
|
73
|
-
const item = itemAt(target);
|
|
74
|
-
if (item === null || isDisabledItem(item) || item.hasAttribute("aria-haspopup")) return;
|
|
75
|
-
options.activate(item);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (shownAt !== null && performance.now() - shownAt >= DRAG_DISMISS_DELAY && popup.matches(":popover-open")) popup.hidePopover();
|
|
79
|
-
};
|
|
80
|
-
const onEnd = (event) => {
|
|
81
|
-
if (ours(event)) end();
|
|
82
|
-
};
|
|
83
|
-
const onToggle = () => {
|
|
84
|
-
if (!popup.matches(":popover-open")) end();
|
|
85
|
-
else shownAt ??= performance.now();
|
|
86
|
-
};
|
|
87
|
-
const end = () => {
|
|
88
|
-
popup.removeEventListener("pointermove", onMove);
|
|
89
|
-
popup.removeEventListener("pointerup", onUp);
|
|
90
|
-
popup.removeEventListener("pointercancel", onEnd);
|
|
91
|
-
popup.removeEventListener("lostpointercapture", onEnd);
|
|
92
|
-
popup.removeEventListener("toggle", onToggle);
|
|
93
|
-
submenuTrigger = null;
|
|
94
|
-
};
|
|
95
|
-
popup.addEventListener("pointermove", onMove);
|
|
96
|
-
popup.addEventListener("pointerup", onUp);
|
|
97
|
-
popup.addEventListener("pointercancel", onEnd);
|
|
98
|
-
popup.addEventListener("lostpointercapture", onEnd);
|
|
99
|
-
popup.addEventListener("toggle", onToggle);
|
|
100
|
-
return end;
|
|
101
|
-
}
|
|
102
|
-
/** How long the touch guard waits for the `touchend` that follows the finger's `pointerup`. */
|
|
103
|
-
const TOUCH_END_WAIT = 250;
|
|
104
|
-
/**
|
|
105
|
-
* While the finger that opened a touch menu is still down, the browser must not take its drag
|
|
106
|
-
* as a pan (it would end the stream with `pointercancel`): a non-passive document `touchmove`
|
|
107
|
-
* listener prevents it (context-menu.md 2.2). The lift's `touchend`, which follows that
|
|
108
|
-
* pointer's `pointerup`, is prevented as well, so the engine synthesises no click from it: a click
|
|
109
|
-
* where the finger was (beside the offset menu) would light-dismiss the menu in Chromium, and one
|
|
110
|
-
* over an item would activate it a second time. Ends at that `touchend` / `touchcancel`, at the
|
|
111
|
-
* pointer's `pointercancel`, and shortly after its `pointerup` if no touch event follows (a
|
|
112
|
-
* synthetic pointer). Returns the cleanup.
|
|
113
|
-
*
|
|
114
|
-
* Only the gesture finger's lift ends it (review L4): another finger lifting while it is still
|
|
115
|
-
* down must not hand its next slide to panning. Pointer events expose no `Touch.identifier`, so
|
|
116
|
-
* the lift is recognised by order: the engines dispatch a lift's `pointerup` and `touchend` from
|
|
117
|
-
* the same input, the `pointerup` first. A `touchend` before that pointer's `pointerup` is another
|
|
118
|
-
* finger's; it is still prevented (no click may light-dismiss the menu mid-gesture).
|
|
119
|
-
*/
|
|
120
|
-
function guardTouch(doc, pointerId) {
|
|
121
|
-
let fallback;
|
|
122
|
-
let lifted = false;
|
|
123
|
-
const onTouchMove = (event) => {
|
|
124
|
-
if (event.cancelable) event.preventDefault();
|
|
125
|
-
};
|
|
126
|
-
const onTouchEnd = (event) => {
|
|
127
|
-
if (event.cancelable) event.preventDefault();
|
|
128
|
-
if (lifted) end();
|
|
129
|
-
};
|
|
130
|
-
const onPointerUp = (event) => {
|
|
131
|
-
if (event.pointerId !== pointerId) return;
|
|
132
|
-
lifted = true;
|
|
133
|
-
fallback ??= setTimeout(end, TOUCH_END_WAIT);
|
|
134
|
-
};
|
|
135
|
-
const onPointerCancel = (event) => {
|
|
136
|
-
if (event.pointerId === pointerId) end();
|
|
137
|
-
};
|
|
138
|
-
const end = () => {
|
|
139
|
-
if (fallback !== void 0) clearTimeout(fallback);
|
|
140
|
-
doc.removeEventListener("touchmove", onTouchMove);
|
|
141
|
-
doc.removeEventListener("touchend", onTouchEnd);
|
|
142
|
-
doc.removeEventListener("touchcancel", end, true);
|
|
143
|
-
doc.removeEventListener("pointerup", onPointerUp, true);
|
|
144
|
-
doc.removeEventListener("pointercancel", onPointerCancel, true);
|
|
145
|
-
};
|
|
146
|
-
doc.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
147
|
-
doc.addEventListener("touchend", onTouchEnd, { passive: false });
|
|
148
|
-
doc.addEventListener("touchcancel", end, true);
|
|
149
|
-
doc.addEventListener("pointerup", onPointerUp, true);
|
|
150
|
-
doc.addEventListener("pointercancel", onPointerCancel, true);
|
|
151
|
-
return end;
|
|
152
|
-
}
|
|
153
13
|
/**
|
|
154
14
|
* A region whose `contextmenu` (right-click, Ctrl+click, Shift+F10 / the ContextMenu key at a
|
|
155
15
|
* focused descendant) or touch / pen long-press opens the Root's `Menu.Popup` at the pointer
|
|
@@ -167,8 +27,8 @@ function guardTouch(doc, pointerId) {
|
|
|
167
27
|
function MenuContextTrigger({ disabled = false, editableTargets = "native", longPressDelay = 500, className, style, children, render, ...rest }) {
|
|
168
28
|
const menu = useMenuContext("Menu.ContextTrigger");
|
|
169
29
|
const { popover } = menu;
|
|
170
|
-
useDevWarning(menu.submenu, "Menu.ContextTrigger: rendered in a submenu. A Menu.Root inside a Menu.Popup is a submenu; a context menu region belongs to a top-level Menu.Root.");
|
|
171
|
-
useDevWarning(longPressDelay < 0, "Menu.ContextTrigger: `longPressDelay` is negative; it is a number of milliseconds.");
|
|
30
|
+
useDevWarning(menu.submenu, isDev && "Menu.ContextTrigger: rendered in a submenu. A Menu.Root inside a Menu.Popup is a submenu; a context menu region belongs to a top-level Menu.Root.");
|
|
31
|
+
useDevWarning(longPressDelay < 0, isDev && "Menu.ContextTrigger: `longPressDelay` is negative; it is a number of milliseconds.");
|
|
172
32
|
const sequence = useRef(0);
|
|
173
33
|
const lastPointerDown = useRef(-1);
|
|
174
34
|
const lastKeyDown = useRef(-1);
|
|
@@ -222,43 +82,6 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
|
|
|
222
82
|
return popup;
|
|
223
83
|
};
|
|
224
84
|
/**
|
|
225
|
-
* One-shot swallow of the `click` an engine may synthesise when the long-press ends (2.2),
|
|
226
|
-
* scoped to that release (review H1): the click comes in the same task as the `pointerup` of
|
|
227
|
-
* `pointerId`, so the swallow ends one task after that `pointerup` (or `pointercancel`), and at
|
|
228
|
-
* once on any `keydown`, the next `pointerdown`, or the menu closing. iOS synthesises no click
|
|
229
|
-
* after a long-press; a swallow left armed would eat the next keyboard activation
|
|
230
|
-
* (`element.click()`).
|
|
231
|
-
*/
|
|
232
|
-
const armClickSwallow = (doc, pointerId, releasing = false) => {
|
|
233
|
-
disarmSwallow.current?.();
|
|
234
|
-
let released;
|
|
235
|
-
const onClick = (event) => {
|
|
236
|
-
event.preventDefault();
|
|
237
|
-
event.stopPropagation();
|
|
238
|
-
disarm();
|
|
239
|
-
};
|
|
240
|
-
const onRelease = (event) => {
|
|
241
|
-
if (event.pointerId !== pointerId) return;
|
|
242
|
-
if (released === void 0) released = setTimeout(disarm, 0);
|
|
243
|
-
};
|
|
244
|
-
const disarm = () => {
|
|
245
|
-
if (released !== void 0) clearTimeout(released);
|
|
246
|
-
doc.removeEventListener("click", onClick, true);
|
|
247
|
-
doc.removeEventListener("pointerdown", disarm, true);
|
|
248
|
-
doc.removeEventListener("keydown", disarm, true);
|
|
249
|
-
doc.removeEventListener("pointerup", onRelease, true);
|
|
250
|
-
doc.removeEventListener("pointercancel", onRelease, true);
|
|
251
|
-
if (disarmSwallow.current === disarm) disarmSwallow.current = null;
|
|
252
|
-
};
|
|
253
|
-
doc.addEventListener("click", onClick, true);
|
|
254
|
-
doc.addEventListener("pointerdown", disarm, true);
|
|
255
|
-
doc.addEventListener("keydown", disarm, true);
|
|
256
|
-
doc.addEventListener("pointerup", onRelease, true);
|
|
257
|
-
doc.addEventListener("pointercancel", onRelease, true);
|
|
258
|
-
disarmSwallow.current = disarm;
|
|
259
|
-
if (releasing) released = setTimeout(disarm, 0);
|
|
260
|
-
};
|
|
261
|
-
/**
|
|
262
85
|
* Starts the press-drag-release gesture of 2.6 on the pointer the popup captured at this open
|
|
263
86
|
* or move (a new one replaces the running one), with the touch guard for a finger.
|
|
264
87
|
*/
|
|
@@ -273,7 +96,7 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
|
|
|
273
96
|
activate: (item) => {
|
|
274
97
|
disarmSwallow.current?.();
|
|
275
98
|
item.click();
|
|
276
|
-
armClickSwallow(doc, pointerId, true);
|
|
99
|
+
armClickSwallow(disarmSwallow, doc, pointerId, true);
|
|
277
100
|
}
|
|
278
101
|
});
|
|
279
102
|
const unguard = pointerType === "touch" ? guardTouch(doc, pointerId) : null;
|
|
@@ -308,7 +131,7 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
|
|
|
308
131
|
x: native.clientX,
|
|
309
132
|
y: native.clientY
|
|
310
133
|
};
|
|
311
|
-
if (pointerId !== void 0 && capturePointer(popup, pointerId)) beginDrag(popup, pointerId, point, pointerType, timed !== null || pointerType === "touch" ?
|
|
134
|
+
if (pointerId !== void 0 && capturePointer(popup, pointerId)) beginDrag(popup, pointerId, point, pointerType, timed !== null || pointerType === "touch" ? 10 : 4);
|
|
312
135
|
menu.openAt(point, {
|
|
313
136
|
source: event.currentTarget,
|
|
314
137
|
event: native,
|
|
@@ -338,8 +161,8 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
|
|
|
338
161
|
x: clientX,
|
|
339
162
|
y: clientY
|
|
340
163
|
};
|
|
341
|
-
if (capturePointer(popup, pointerId)) beginDrag(popup, pointerId, point, pointerType,
|
|
342
|
-
armClickSwallow(source.ownerDocument, pointerId);
|
|
164
|
+
if (capturePointer(popup, pointerId)) beginDrag(popup, pointerId, point, pointerType, 10);
|
|
165
|
+
armClickSwallow(disarmSwallow, source.ownerDocument, pointerId);
|
|
343
166
|
menu.openAt(point, {
|
|
344
167
|
source,
|
|
345
168
|
event: native,
|
|
@@ -359,7 +182,7 @@ function MenuContextTrigger({ disabled = false, editableTargets = "native", long
|
|
|
359
182
|
const onPointerMove = (event) => {
|
|
360
183
|
const press = longPress.current;
|
|
361
184
|
if (press === null || event.pointerId !== press.pointerId) return;
|
|
362
|
-
if (Math.hypot(event.clientX - press.x, event.clientY - press.y) >
|
|
185
|
+
if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > 10) cancelLongPress();
|
|
363
186
|
};
|
|
364
187
|
const onPointerEnd = (event) => {
|
|
365
188
|
const press = longPress.current;
|