@funstack/ui 0.1.0-alpha.10 → 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 +11 -10
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +37 -109
- 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.d.mts +2 -2
- package/dist/combobox/index.mjs +3 -3
- package/dist/combobox/index.mjs.map +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 +4 -4
- 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 +8 -6
- 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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useElementCheck } from "./use-element-check.mjs";
|
|
3
|
+
import { useMergedRefs } from "./use-merged-refs.mjs";
|
|
4
|
+
import { useFieldControl } from "./use-field-control.mjs";
|
|
5
|
+
import { useCallback, useId, useRef } from "react";
|
|
6
|
+
//#region src/internal/use-fieldset-group.ts
|
|
7
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
8
|
+
/**
|
|
9
|
+
* The `<fieldset>` wiring of a native-input group Root (`RadioGroup.Root`,
|
|
10
|
+
* `CheckboxGroup.Root`). Inside a `Field.Root` (design/components/field-form.md 7.2) the fieldset
|
|
11
|
+
* is the Field's group control: `aria-labelledby` → `Field.Label`, the ARIA wiring, and `name` /
|
|
12
|
+
* `required` / `disabled` defaulting from the Field.
|
|
13
|
+
*/
|
|
14
|
+
function useFieldsetGroup(options) {
|
|
15
|
+
const { component } = options;
|
|
16
|
+
const field = useFieldControl({
|
|
17
|
+
labelable: false,
|
|
18
|
+
name: options.name,
|
|
19
|
+
disabled: options.disabled,
|
|
20
|
+
required: options.required,
|
|
21
|
+
component
|
|
22
|
+
});
|
|
23
|
+
const fallbackName = useId();
|
|
24
|
+
const fieldsetRef = useRef(null);
|
|
25
|
+
const checkElement = useElementCheck(isDev && ((el) => el.tagName !== "FIELDSET" ? `${component}: expected to render a <fieldset> element but got <${el.tagName.toLowerCase()}>. The platform semantics (legend naming, disabled inheritance, form reset) need a real <fieldset>.` : null));
|
|
26
|
+
const libraryRef = useCallback((el) => {
|
|
27
|
+
fieldsetRef.current = el;
|
|
28
|
+
checkElement?.(el);
|
|
29
|
+
return () => {
|
|
30
|
+
fieldsetRef.current = null;
|
|
31
|
+
};
|
|
32
|
+
}, [checkElement]);
|
|
33
|
+
const rootRef = useMergedRefs(libraryRef, field.ref);
|
|
34
|
+
return {
|
|
35
|
+
field,
|
|
36
|
+
name: field.name ?? fallbackName,
|
|
37
|
+
required: field.required,
|
|
38
|
+
disabled: field.disabled,
|
|
39
|
+
fieldsetRef,
|
|
40
|
+
rootRef
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { useFieldsetGroup };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=use-fieldset-group.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-fieldset-group.mjs","names":[],"sources":["../../src/internal/use-fieldset-group.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useId, useRef } from \"react\";\nimport type { Ref, RefObject } from \"react\";\nimport type { FieldControlBinding } from \"./use-field-control.js\";\nimport { useFieldControl } from \"./use-field-control.js\";\nimport { useElementCheck } from \"./use-element-check.js\";\nimport { useMergedRefs } from \"./use-merged-refs.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface UseFieldsetGroupOptions {\n /** Dev warning tag (`\"RadioGroup.Root\"`). */\n readonly component: string;\n /** The Root's own `name` / `disabled` / `required` props. */\n readonly name: string | undefined;\n readonly disabled: boolean | undefined;\n readonly required: boolean | undefined;\n}\n\nexport interface FieldsetGroup {\n readonly field: FieldControlBinding;\n /** Own `name`, else the Field's, else a `useId()` value. */\n readonly name: string;\n /** Own `required` or the Field's. */\n readonly required: boolean;\n /** Own `disabled` or the Field's. */\n readonly disabled: boolean;\n /** The rendered `<fieldset>`. */\n readonly fieldsetRef: RefObject<HTMLFieldSetElement | null>;\n /** The Root's library ref: fills `fieldsetRef`, checks the element, registers with the Field. */\n readonly rootRef: Ref<HTMLFieldSetElement> | undefined;\n}\n\n/**\n * The `<fieldset>` wiring of a native-input group Root (`RadioGroup.Root`,\n * `CheckboxGroup.Root`). Inside a `Field.Root` (design/components/field-form.md 7.2) the fieldset\n * is the Field's group control: `aria-labelledby` → `Field.Label`, the ARIA wiring, and `name` /\n * `required` / `disabled` defaulting from the Field.\n */\nexport function useFieldsetGroup(options: UseFieldsetGroupOptions): FieldsetGroup {\n const { component } = options;\n const field = useFieldControl({\n labelable: false,\n name: options.name,\n disabled: options.disabled,\n required: options.required,\n component,\n });\n const fallbackName = useId();\n const fieldsetRef = useRef<HTMLFieldSetElement | null>(null);\n\n const checkElement = useElementCheck<HTMLFieldSetElement>(\n isDev &&\n ((el) =>\n el.tagName !== \"FIELDSET\"\n ? `${component}: expected to render a <fieldset> element but got ` +\n `<${el.tagName.toLowerCase()}>. The platform semantics (legend naming, disabled ` +\n `inheritance, form reset) need a real <fieldset>.`\n : null),\n );\n const libraryRef = useCallback(\n (el: HTMLFieldSetElement) => {\n fieldsetRef.current = el;\n checkElement?.(el);\n return () => {\n fieldsetRef.current = null;\n };\n },\n [checkElement],\n );\n const rootRef = useMergedRefs<HTMLFieldSetElement>(libraryRef, field.ref);\n\n return {\n field,\n name: field.name ?? fallbackName,\n required: field.required,\n disabled: field.disabled,\n fieldsetRef,\n rootRef,\n };\n}\n"],"mappings":";;;;;;AAQA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;AA+BvC,SAAgB,iBAAiB,SAAiD;CAChF,MAAM,EAAE,cAAc;CACtB,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,MAAM,QAAQ;EACd,UAAU,QAAQ;EAClB,UAAU,QAAQ;EAClB;CACF,CAAC;CACD,MAAM,eAAe,MAAM;CAC3B,MAAM,cAAc,OAAmC,IAAI;CAE3D,MAAM,eAAe,gBACnB,WACI,OACA,GAAG,YAAY,aACX,GAAG,UAAU,qDACT,GAAG,QAAQ,YAAY,EAAE,uGAE7B,KACV;CACA,MAAM,aAAa,aAChB,OAA4B;EAC3B,YAAY,UAAU;EACtB,eAAe,EAAE;EACjB,aAAa;GACX,YAAY,UAAU;EACxB;CACF,GACA,CAAC,YAAY,CACf;CACA,MAAM,UAAU,cAAmC,YAAY,MAAM,GAAG;CAExE,OAAO;EACL;EACA,MAAM,MAAM,QAAQ;EACpB,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB;EACA;CACF;AACF"}
|
|
@@ -5,11 +5,7 @@ import { useFormOwnerEvent } from "./use-form-owner-event.mjs";
|
|
|
5
5
|
/**
|
|
6
6
|
* Stable `reset` subscription on the form owner of `ref.current` (conventions 3.8).
|
|
7
7
|
*
|
|
8
|
-
* -
|
|
9
|
-
* but the listener is moved only when the owner changed. It is never removed and re-added on an
|
|
10
|
-
* ordinary re-render: React's automatic reset after a successful `<form action>` runs in the
|
|
11
|
-
* commit's mutation phase, between an effect's cleanup and its next run, so a subscription that
|
|
12
|
-
* followed every commit would miss it (rule 4). Built on `useFormOwnerEvent`.
|
|
8
|
+
* - Built on `useFormOwnerEvent`, with its owner-following rules (rule 4).
|
|
13
9
|
* - The `reset` event fires before the reset algorithm, so `onReset` is called in a microtask,
|
|
14
10
|
* when the inputs hold their reset values (rule 5), and only if no listener cancelled the reset
|
|
15
11
|
* (rule 7).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-form-reset.mjs","names":[],"sources":["../../src/internal/use-form-reset.ts"],"sourcesContent":["\"use client\";\nimport type { RefObject } from \"react\";\nimport { useFormOwnerEvent } from \"./use-form-owner-event.js\";\nimport type { FormAssociatedElement } from \"./use-form-owner-event.js\";\nimport { useLatest } from \"./use-latest.js\";\n\
|
|
1
|
+
{"version":3,"file":"use-form-reset.mjs","names":[],"sources":["../../src/internal/use-form-reset.ts"],"sourcesContent":["\"use client\";\nimport type { RefObject } from \"react\";\nimport { useFormOwnerEvent } from \"./use-form-owner-event.js\";\nimport type { FormAssociatedElement } from \"./use-form-owner-event.js\";\nimport { useLatest } from \"./use-latest.js\";\n\n/**\n * Stable `reset` subscription on the form owner of `ref.current` (conventions 3.8).\n *\n * - Built on `useFormOwnerEvent`, with its owner-following rules (rule 4).\n * - The `reset` event fires before the reset algorithm, so `onReset` is called in a microtask,\n * when the inputs hold their reset values (rule 5), and only if no listener cancelled the reset\n * (rule 7).\n * - `onReset` always sees the latest committed render's values.\n */\nexport function useFormReset(\n ref: RefObject<FormAssociatedElement | null>,\n onReset: (event: Event) => void,\n /**\n * Called synchronously from the `reset` event, before the reset algorithm runs: the last\n * moment to write a reset target the browser will restore (Combobox re-applies its mirrored\n * `defaultValue`, which react-dom's attribute syncing overwrites after every keystroke).\n */\n onResetEvent?: (event: Event) => void,\n): void {\n // Read in the microtask, after the commit that may have run the reset (React's own reset runs\n // in a commit's mutation phase): the latest committed `onReset`.\n const latestOnReset = useLatest(onReset);\n useFormOwnerEvent(ref, \"reset\", (event) => {\n onResetEvent?.(event);\n queueMicrotask(() => {\n if (event.defaultPrevented) return;\n latestOnReset.current(event);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAgB,aACd,KACA,SAMA,cACM;CAGN,MAAM,gBAAgB,UAAU,OAAO;CACvC,kBAAkB,KAAK,UAAU,UAAU;EACzC,eAAe,KAAK;EACpB,qBAAqB;GACnB,IAAI,MAAM,kBAAkB;GAC5B,cAAc,QAAQ,KAAK;EAC7B,CAAC;CACH,CAAC;AACH"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { arraysEqual, firstDuplicate, sortByOrder } from "./value-set.mjs";
|
|
3
|
+
import { useEffectEvent, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
//#region src/internal/use-item-order.ts
|
|
5
|
+
/**
|
|
6
|
+
* The Items' document order, kept in state for the Root state's `value` (CheckboxGroup,
|
|
7
|
+
* ToggleGroup). Render cannot read the DOM, so the order is refreshed after a commit of the Root,
|
|
8
|
+
* only when what renders from it would change (a value given out of document order, Items
|
|
9
|
+
* reordered or added). The first render, and the server, use the value's own order.
|
|
10
|
+
*
|
|
11
|
+
* A deps-less layout effect runs only when the Root itself committed: Items moved by a child that
|
|
12
|
+
* re-renders alone are picked up at the Root's next render. The comparison ends the chain: the
|
|
13
|
+
* re-render it causes renders exactly the value just compared against.
|
|
14
|
+
*/
|
|
15
|
+
function useItemOrder(options) {
|
|
16
|
+
const { optimistic, initial } = options;
|
|
17
|
+
const [layout, setLayout] = useState(initial);
|
|
18
|
+
const renderedValue = sortByOrder(optimistic, layout.order);
|
|
19
|
+
const warnedDuplicate = useRef(false);
|
|
20
|
+
const sync = useEffectEvent(() => {
|
|
21
|
+
const next = options.read();
|
|
22
|
+
if (!arraysEqual(sortByOrder(optimistic, next.order), renderedValue) || options.changed?.(layout, next) === true) setLayout(next);
|
|
23
|
+
const { duplicateMessage } = options;
|
|
24
|
+
if (duplicateMessage === false || warnedDuplicate.current) return;
|
|
25
|
+
const duplicate = firstDuplicate(next.order);
|
|
26
|
+
if (duplicate !== void 0) {
|
|
27
|
+
warnedDuplicate.current = true;
|
|
28
|
+
console.error(duplicateMessage(duplicate));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
sync();
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
layout,
|
|
36
|
+
renderedValue
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { useItemOrder };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=use-item-order.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-item-order.mjs","names":[],"sources":["../../src/internal/use-item-order.ts"],"sourcesContent":["\"use client\";\nimport { useEffectEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport { arraysEqual, firstDuplicate, sortByOrder } from \"./value-set.js\";\nimport type { ValueSet } from \"./value-set.js\";\n\n/** What a multi-value group reads from its Items' DOM: at least their values in document order. */\nexport interface ItemLayout {\n readonly order: readonly string[];\n}\n\nexport interface UseItemOrderOptions<L extends ItemLayout> {\n /** The optimistic set the state's `value` is built from. */\n readonly optimistic: ValueSet;\n /** Before the first read (the server render and the first client render). */\n readonly initial: L;\n /** Reads the Items' layout from the DOM (layout phase). */\n readonly read: () => L;\n /** Something else that renders from the layout changed (default: nothing else does). */\n readonly changed?: ((prev: L, next: L) => boolean) | undefined;\n /**\n * Dev only, once: two Items share a value. Pass `isDev && ((value) => ...)` with the calling\n * module's own `isDev`, so the text folds away in production.\n */\n readonly duplicateMessage: false | ((value: string) => string);\n}\n\nexport interface ItemOrder<L extends ItemLayout> {\n /** The layout as of the Root's last commit. */\n readonly layout: L;\n /** `optimistic` in the Items' document order (values with no Item last): the state's `value`. */\n readonly renderedValue: string[];\n}\n\n/**\n * The Items' document order, kept in state for the Root state's `value` (CheckboxGroup,\n * ToggleGroup). Render cannot read the DOM, so the order is refreshed after a commit of the Root,\n * only when what renders from it would change (a value given out of document order, Items\n * reordered or added). The first render, and the server, use the value's own order.\n *\n * A deps-less layout effect runs only when the Root itself committed: Items moved by a child that\n * re-renders alone are picked up at the Root's next render. The comparison ends the chain: the\n * re-render it causes renders exactly the value just compared against.\n */\nexport function useItemOrder<L extends ItemLayout>(options: UseItemOrderOptions<L>): ItemOrder<L> {\n const { optimistic, initial } = options;\n const [layout, setLayout] = useState<L>(initial);\n const renderedValue = sortByOrder(optimistic, layout.order);\n const warnedDuplicate = useRef(false);\n const sync = useEffectEvent(() => {\n const next = options.read();\n const valueChanged = !arraysEqual(sortByOrder(optimistic, next.order), renderedValue);\n if (valueChanged || options.changed?.(layout, next) === true) setLayout(next);\n\n const { duplicateMessage } = options;\n if (duplicateMessage === false || warnedDuplicate.current) return;\n const duplicate = firstDuplicate(next.order);\n if (duplicate !== undefined) {\n warnedDuplicate.current = true;\n console.error(duplicateMessage(duplicate));\n }\n });\n useLayoutEffect(() => {\n // oxlint-disable-next-line react/set-state-in-effect -- a DOM read render cannot do\n sync();\n });\n return { layout, renderedValue };\n}\n"],"mappings":";;;;;;;;;;;;;;AA2CA,SAAgB,aAAmC,SAA+C;CAChG,MAAM,EAAE,YAAY,YAAY;CAChC,MAAM,CAAC,QAAQ,aAAa,SAAY,OAAO;CAC/C,MAAM,gBAAgB,YAAY,YAAY,OAAO,KAAK;CAC1D,MAAM,kBAAkB,OAAO,KAAK;CACpC,MAAM,OAAO,qBAAqB;EAChC,MAAM,OAAO,QAAQ,KAAK;EAE1B,IAAI,CADkB,YAAY,YAAY,YAAY,KAAK,KAAK,GAAG,aAAa,KAChE,QAAQ,UAAU,QAAQ,IAAI,MAAM,MAAM,UAAU,IAAI;EAE5E,MAAM,EAAE,qBAAqB;EAC7B,IAAI,qBAAqB,SAAS,gBAAgB,SAAS;EAC3D,MAAM,YAAY,eAAe,KAAK,KAAK;EAC3C,IAAI,cAAc,KAAA,GAAW;GAC3B,gBAAgB,UAAU;GAC1B,QAAQ,MAAM,iBAAiB,SAAS,CAAC;EAC3C;CACF,CAAC;CACD,sBAAsB;EAEpB,KAAK;CACP,CAAC;CACD,OAAO;EAAE;EAAQ;CAAc;AACjC"}
|
|
@@ -10,14 +10,10 @@ import { useInsertionEffect, useRef } from "react";
|
|
|
10
10
|
* that changed the value already sees it. A render that never commits (a discarded concurrent or
|
|
11
11
|
* StrictMode render) never writes it. Never read it during render.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* fires synchronously during the mutation phase (Chromium fires `blur` / `focusout` when a
|
|
18
|
-
* focused node is removed). This is the same value a per-render closure would have given (the
|
|
19
|
-
* handler attached then was the previous commit's too), so it is not a regression; just do not
|
|
20
|
-
* rely on the new value before the layout phase.
|
|
13
|
+
* Insertion effects run children first, so earlier in that commit (a descendant's insertion
|
|
14
|
+
* effect, a DOM event fired during the mutation phase such as Chromium's `blur` on removal) it
|
|
15
|
+
* still holds the previous commit's value, as a per-render closure would. Rely on the new value
|
|
16
|
+
* from the layout phase on.
|
|
21
17
|
*/
|
|
22
18
|
function useLatest(value) {
|
|
23
19
|
const ref = useRef(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-latest.mjs","names":[],"sources":["../../src/internal/use-latest.ts"],"sourcesContent":["\"use client\";\nimport { useInsertionEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\n\n/**\n * A ref holding the value of the last **committed** render, for stable callbacks (handlers,\n * actions, effects) that must read the current props without changing identity on every render.\n *\n * Written in an insertion effect: it runs in the mutation phase, before every layout effect of\n * the same commit (a child's included), so a callback called from a layout effect of the commit\n * that changed the value already sees it. A render that never commits (a discarded concurrent or\n * StrictMode render) never writes it. Never read it during render.\n *\n *
|
|
1
|
+
{"version":3,"file":"use-latest.mjs","names":[],"sources":["../../src/internal/use-latest.ts"],"sourcesContent":["\"use client\";\nimport { useInsertionEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\n\n/**\n * A ref holding the value of the last **committed** render, for stable callbacks (handlers,\n * actions, effects) that must read the current props without changing identity on every render.\n *\n * Written in an insertion effect: it runs in the mutation phase, before every layout effect of\n * the same commit (a child's included), so a callback called from a layout effect of the commit\n * that changed the value already sees it. A render that never commits (a discarded concurrent or\n * StrictMode render) never writes it. Never read it during render.\n *\n * Insertion effects run children first, so earlier in that commit (a descendant's insertion\n * effect, a DOM event fired during the mutation phase such as Chromium's `blur` on removal) it\n * still holds the previous commit's value, as a per-render closure would. Rely on the new value\n * from the layout phase on.\n */\nexport function useLatest<T>(value: T): RefObject<T> {\n const ref = useRef(value);\n useInsertionEffect(() => {\n ref.current = value;\n });\n return ref;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,SAAgB,UAAa,OAAwB;CACnD,MAAM,MAAM,OAAO,KAAK;CACxB,yBAAyB;EACvB,IAAI,UAAU;CAChB,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { mergeRefs } from "./merge-props.mjs";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
//#region src/internal/use-merged-refs.ts
|
|
5
|
+
/**
|
|
6
|
+
* `mergeRefs` with a stable identity while every ref keeps its own. `undefined` entries are
|
|
7
|
+
* dropped: a single remaining ref passes through unwrapped, none gives `undefined`. Call it with
|
|
8
|
+
* the same number of arguments on every render.
|
|
9
|
+
*/
|
|
10
|
+
function useMergedRefs(...refs) {
|
|
11
|
+
return useMemo(() => {
|
|
12
|
+
const defined = refs.filter((ref) => ref !== void 0);
|
|
13
|
+
return defined.length <= 1 ? defined[0] : mergeRefs(...defined);
|
|
14
|
+
}, refs);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { useMergedRefs };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=use-merged-refs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-merged-refs.mjs","names":[],"sources":["../../src/internal/use-merged-refs.ts"],"sourcesContent":["\"use client\";\nimport { useMemo } from \"react\";\nimport type { Ref } from \"react\";\nimport { mergeRefs } from \"./merge-props.js\";\n\n/**\n * `mergeRefs` with a stable identity while every ref keeps its own. `undefined` entries are\n * dropped: a single remaining ref passes through unwrapped, none gives `undefined`. Call it with\n * the same number of arguments on every render.\n */\nexport function useMergedRefs<T>(...refs: readonly (Ref<T> | undefined)[]): Ref<T> | undefined {\n return useMemo(\n () => {\n const defined = refs.filter((ref) => ref !== undefined);\n return defined.length <= 1 ? defined[0] : mergeRefs(...defined);\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- the refs themselves are the deps\n refs,\n );\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,cAAiB,GAAG,MAA2D;CAC7F,OAAO,cACC;EACJ,MAAM,UAAU,KAAK,QAAQ,QAAQ,QAAQ,KAAA,CAAS;EACtD,OAAO,QAAQ,UAAU,IAAI,QAAQ,KAAK,UAAU,GAAG,OAAO;CAChE,GAEA,IACF;AACF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
+
//#region src/internal/use-name-warning.ts
|
|
4
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
5
|
+
/** A button is also named by its text or `title`. */
|
|
6
|
+
const BUTTON_NAME = {
|
|
7
|
+
text: true,
|
|
8
|
+
title: true
|
|
9
|
+
};
|
|
10
|
+
/** Text content names it too (`title` does not). */
|
|
11
|
+
const TEXT_NAME = { text: true };
|
|
12
|
+
/** Whether `element` has an accessible name by `rules` (development checks only). */
|
|
13
|
+
function hasName(element, rules) {
|
|
14
|
+
if (element.hasAttribute("aria-label")) return true;
|
|
15
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
16
|
+
if (labelledBy !== null) {
|
|
17
|
+
if (!rules.resolveIds) return true;
|
|
18
|
+
const doc = element.ownerDocument;
|
|
19
|
+
if (labelledBy.split(/\s+/).some((id) => id !== "" && doc.getElementById(id) !== null)) return true;
|
|
20
|
+
}
|
|
21
|
+
if (rules.text && (element.textContent ?? "").trim() !== "") return true;
|
|
22
|
+
return rules.title === true && element.hasAttribute("title");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Development check that a part the consumer must name (an icon-only button, a listbox) has an
|
|
26
|
+
* accessible name: a microtask after the element attaches (the text may come from children
|
|
27
|
+
* rendered in the same commit, and a Label's registration re-render is flushed by then), once
|
|
28
|
+
* per instance. The result is a callback ref, or a function to call from the part's own ref.
|
|
29
|
+
*
|
|
30
|
+
* Pass `message` as `isDev && "..."` with the calling module's own `isDev` constant, so the text
|
|
31
|
+
* folds away in a production build; there the hook is a no-op that returns `undefined`.
|
|
32
|
+
*/
|
|
33
|
+
const useNameWarning = isDev ? useNameWarningDev : noop;
|
|
34
|
+
function noop() {}
|
|
35
|
+
function useNameWarningDev(message, rules = {}) {
|
|
36
|
+
const warned = useRef(false);
|
|
37
|
+
const { resolveIds, text, title } = rules;
|
|
38
|
+
const check = useCallback((element) => {
|
|
39
|
+
if (warned.current) return () => {};
|
|
40
|
+
queueMicrotask(() => {
|
|
41
|
+
if (warned.current || !element.isConnected) return;
|
|
42
|
+
if (hasName(element, {
|
|
43
|
+
resolveIds,
|
|
44
|
+
text,
|
|
45
|
+
title
|
|
46
|
+
})) return;
|
|
47
|
+
warned.current = true;
|
|
48
|
+
console.error(message);
|
|
49
|
+
});
|
|
50
|
+
return () => {};
|
|
51
|
+
}, [
|
|
52
|
+
message,
|
|
53
|
+
resolveIds,
|
|
54
|
+
text,
|
|
55
|
+
title
|
|
56
|
+
]);
|
|
57
|
+
return message === false ? void 0 : check;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Development check that a popup has an accessible name once it is (or can be) shown: in an
|
|
61
|
+
* effect while `shown`, once per instance. `applies` limits it to the elements that need a name
|
|
62
|
+
* (a role). Pass `message` as `isDev && "..."`, as for `useNameWarning`; a no-op in production.
|
|
63
|
+
*/
|
|
64
|
+
const useShownNameWarning = isDev ? useShownNameWarningDev : noop;
|
|
65
|
+
function useShownNameWarningDev(element, shown, message, applies) {
|
|
66
|
+
const warned = useRef(false);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (message === false || !shown || warned.current) return;
|
|
69
|
+
const target = element !== null && "current" in element ? element.current : element;
|
|
70
|
+
if (target === null || hasName(target, { resolveIds: true })) return;
|
|
71
|
+
if (applies !== void 0 && !applies(target)) return;
|
|
72
|
+
warned.current = true;
|
|
73
|
+
console.error(message);
|
|
74
|
+
}, [
|
|
75
|
+
element,
|
|
76
|
+
shown,
|
|
77
|
+
message,
|
|
78
|
+
applies
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { BUTTON_NAME, TEXT_NAME, useNameWarning, useShownNameWarning };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=use-name-warning.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-name-warning.mjs","names":[],"sources":["../../src/internal/use-name-warning.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { ElementCheck } from \"./use-element-check.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** What counts as a name besides `aria-label` and `aria-labelledby`. */\nexport interface NameRules {\n /** `aria-labelledby` counts only when one of its ids is in the document (a mounted Title). */\n readonly resolveIds?: boolean;\n /** Text content counts (a button with a visible label). */\n readonly text?: boolean;\n /** `title` counts. */\n readonly title?: boolean;\n}\n\n/** A button is also named by its text or `title`. */\nexport const BUTTON_NAME: NameRules = { text: true, title: true };\n\n/** Text content names it too (`title` does not). */\nexport const TEXT_NAME: NameRules = { text: true };\n\n/** Whether `element` has an accessible name by `rules` (development checks only). */\nfunction hasName(element: Element, rules: NameRules): boolean {\n if (element.hasAttribute(\"aria-label\")) return true;\n const labelledBy = element.getAttribute(\"aria-labelledby\");\n if (labelledBy !== null) {\n if (!rules.resolveIds) return true;\n const doc = element.ownerDocument;\n if (labelledBy.split(/\\s+/).some((id) => id !== \"\" && doc.getElementById(id) !== null)) {\n return true;\n }\n }\n if (rules.text && (element.textContent ?? \"\").trim() !== \"\") return true;\n return rules.title === true && element.hasAttribute(\"title\");\n}\n\n/**\n * Development check that a part the consumer must name (an icon-only button, a listbox) has an\n * accessible name: a microtask after the element attaches (the text may come from children\n * rendered in the same commit, and a Label's registration re-render is flushed by then), once\n * per instance. The result is a callback ref, or a function to call from the part's own ref.\n *\n * Pass `message` as `isDev && \"...\"` with the calling module's own `isDev` constant, so the text\n * folds away in a production build; there the hook is a no-op that returns `undefined`.\n */\nexport const useNameWarning: (\n message: string | false,\n rules?: NameRules,\n) => ElementCheck<HTMLElement> | undefined = isDev ? useNameWarningDev : noop;\n\nfunction noop(): undefined {\n return undefined;\n}\n\nfunction useNameWarningDev(\n message: string | false,\n rules: NameRules = {},\n): ElementCheck<HTMLElement> | undefined {\n const warned = useRef(false);\n const { resolveIds, text, title } = rules;\n const check = useCallback(\n (element: HTMLElement) => {\n if (warned.current) return () => {};\n queueMicrotask(() => {\n if (warned.current || !element.isConnected) return;\n if (hasName(element, { resolveIds, text, title })) return;\n warned.current = true;\n console.error(message);\n });\n return () => {};\n },\n [message, resolveIds, text, title],\n );\n return message === false ? undefined : check;\n}\n\n/**\n * Development check that a popup has an accessible name once it is (or can be) shown: in an\n * effect while `shown`, once per instance. `applies` limits it to the elements that need a name\n * (a role). Pass `message` as `isDev && \"...\"`, as for `useNameWarning`; a no-op in production.\n */\nexport const useShownNameWarning: (\n element: RefObject<Element | null> | Element | null,\n shown: boolean,\n message: string | false,\n applies?: (element: Element) => boolean,\n) => void = isDev ? useShownNameWarningDev : noop;\n\nfunction useShownNameWarningDev(\n element: RefObject<Element | null> | Element | null,\n shown: boolean,\n message: string | false,\n applies?: (element: Element) => boolean,\n): void {\n const warned = useRef(false);\n useEffect(() => {\n if (message === false || !shown || warned.current) return;\n const target = element !== null && \"current\" in element ? element.current : element;\n if (target === null || hasName(target, { resolveIds: true })) return;\n if (applies !== undefined && !applies(target)) return;\n warned.current = true;\n console.error(message);\n }, [element, shown, message, applies]);\n}\n"],"mappings":";;;AAKA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAavC,MAAa,cAAyB;CAAE,MAAM;CAAM,OAAO;AAAK;;AAGhE,MAAa,YAAuB,EAAE,MAAM,KAAK;;AAGjD,SAAS,QAAQ,SAAkB,OAA2B;CAC5D,IAAI,QAAQ,aAAa,YAAY,GAAG,OAAO;CAC/C,MAAM,aAAa,QAAQ,aAAa,iBAAiB;CACzD,IAAI,eAAe,MAAM;EACvB,IAAI,CAAC,MAAM,YAAY,OAAO;EAC9B,MAAM,MAAM,QAAQ;EACpB,IAAI,WAAW,MAAM,KAAK,CAAC,CAAC,MAAM,OAAO,OAAO,MAAM,IAAI,eAAe,EAAE,MAAM,IAAI,GACnF,OAAO;CAEX;CACA,IAAI,MAAM,SAAS,QAAQ,eAAe,GAAA,CAAI,KAAK,MAAM,IAAI,OAAO;CACpE,OAAO,MAAM,UAAU,QAAQ,QAAQ,aAAa,OAAO;AAC7D;;;;;;;;;;AAWA,MAAa,iBAGgC,QAAQ,oBAAoB;AAEzE,SAAS,OAAkB,CAE3B;AAEA,SAAS,kBACP,SACA,QAAmB,CAAC,GACmB;CACvC,MAAM,SAAS,OAAO,KAAK;CAC3B,MAAM,EAAE,YAAY,MAAM,UAAU;CACpC,MAAM,QAAQ,aACX,YAAyB;EACxB,IAAI,OAAO,SAAS,aAAa,CAAC;EAClC,qBAAqB;GACnB,IAAI,OAAO,WAAW,CAAC,QAAQ,aAAa;GAC5C,IAAI,QAAQ,SAAS;IAAE;IAAY;IAAM;GAAM,CAAC,GAAG;GACnD,OAAO,UAAU;GACjB,QAAQ,MAAM,OAAO;EACvB,CAAC;EACD,aAAa,CAAC;CAChB,GACA;EAAC;EAAS;EAAY;EAAM;CAAK,CACnC;CACA,OAAO,YAAY,QAAQ,KAAA,IAAY;AACzC;;;;;;AAOA,MAAa,sBAKD,QAAQ,yBAAyB;AAE7C,SAAS,uBACP,SACA,OACA,SACA,SACM;CACN,MAAM,SAAS,OAAO,KAAK;CAC3B,gBAAgB;EACd,IAAI,YAAY,SAAS,CAAC,SAAS,OAAO,SAAS;EACnD,MAAM,SAAS,YAAY,QAAQ,aAAa,UAAU,QAAQ,UAAU;EAC5E,IAAI,WAAW,QAAQ,QAAQ,QAAQ,EAAE,YAAY,KAAK,CAAC,GAAG;EAC9D,IAAI,YAAY,KAAA,KAAa,CAAC,QAAQ,MAAM,GAAG;EAC/C,OAAO,UAAU;EACjB,QAAQ,MAAM,OAAO;CACvB,GAAG;EAAC;EAAS;EAAO;EAAS;CAAO,CAAC;AACvC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useElementCheck } from "./use-element-check.mjs";
|
|
2
3
|
import { useFormReset } from "./use-form-reset.mjs";
|
|
3
4
|
import { useCallback, useEffectEvent, useLayoutEffect, useRef } from "react";
|
|
4
5
|
//#region src/internal/use-native-checked.ts
|
|
@@ -23,17 +24,14 @@ const isDev = process.env.NODE_ENV !== "production";
|
|
|
23
24
|
function useNativeChecked(options) {
|
|
24
25
|
const { type, component, checked, defaultChecked, indeterminate, group = false } = options;
|
|
25
26
|
const node = useRef(null);
|
|
26
|
-
const
|
|
27
|
+
const checkElement = useElementCheck(isDev && ((el) => isInputOfType(el, type) ? null : `${component}: expected to render an \`<input type="${type}">\` but got ${describeElement(el)}; the platform semantics (form participation, labels, keyboard, reset) need a real input. A \`render\` element must keep the input.`));
|
|
27
28
|
const ref = useCallback((el) => {
|
|
28
29
|
node.current = el;
|
|
29
|
-
|
|
30
|
-
warnedElement.current = true;
|
|
31
|
-
console.error(`${component}: expected to render an \`<input type="${type}">\` but got ${describeElement(el)}; the platform semantics (form participation, labels, keyboard, reset) need a real input. A \`render\` element must keep the input.`);
|
|
32
|
-
}
|
|
30
|
+
checkElement?.(el);
|
|
33
31
|
return () => {
|
|
34
32
|
node.current = null;
|
|
35
33
|
};
|
|
36
|
-
}, [
|
|
34
|
+
}, [checkElement]);
|
|
37
35
|
/** What the user intends: the latest in-flight dispatch, else the optimistic value (rule 1). */
|
|
38
36
|
const readBase = useEffectEvent(() => options.latestInFlight?.()?.next ?? checked);
|
|
39
37
|
const report = useEffectEvent((next, event) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-native-checked.mjs","names":[],"sources":["../../src/internal/use-native-checked.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefCallback } from \"react\";\nimport { useFormReset } from \"./use-form-reset.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface UseNativeCheckedOptions {\n /** Dev-only: the expected `input.type`. */\n readonly type: \"checkbox\" | \"radio\";\n /** Dev-only: the part's name in warnings (`\"Switch\"`, `\"RadioGroup.Item\"`). */\n readonly component: string;\n /** What the DOM must show after every commit: the optimistic value. */\n readonly checked: boolean;\n /**\n * The form-reset target. Uncontrolled parts pass the latest `defaultChecked` prop (`?? false`),\n * mirrored into `el.defaultChecked` after every commit. Controlled parts pass `undefined`:\n * React's mount-time value stays (conventions 3.8 rule 6).\n */\n readonly defaultChecked: boolean | undefined;\n /** Checkbox only: `el.indeterminate` after every commit (the part passes `indeterminate && !pending`). */\n readonly indeterminate?: boolean | undefined;\n /**\n * `true` inside a group (`RadioGroup.Item`): the hook does the element check and the re-apply\n * only; mount reconciliation and form reset are reported once per group by the Root through\n * `useNativeGroupReconciliation`. Default `false`: the hook reports both paths itself.\n */\n readonly group?: boolean | undefined;\n /**\n * Group members only: the Root's `onItemMounted` from `useNativeGroupReconciliation`. Called\n * from this member's mount layout effect so that a member mounting after the Root (a Suspense\n * boundary that hydrates later) still gets the group reconciled. Receives the member's element\n * (`null` if the ref is not attached). Ignored without `group`.\n */\n readonly onItemMounted?: ((element: HTMLInputElement | null) => void) | undefined;\n /** From `useControllableAction`: the value the DOM is compared against on the residual paths. */\n readonly latestInFlight?: (() => { readonly next: boolean } | null) | undefined;\n /**\n * Single controls only. The browser changed the value on a residual path and it differs from\n * what the user intends. `event` is the `reset` event, or `undefined` for mount reconciliation.\n * The part dispatches with `reason: \"platform\"`.\n */\n readonly onPlatformChange?: ((next: boolean, event: Event | undefined) => void) | undefined;\n}\n\n/**\n * Per-element machinery for a controlled native `<input type=\"checkbox\" | \"radio\">`\n * (conventions 3.8): returns the ref to attach to the input (merged by `useRender`).\n *\n * 1. Ref callback: stores the node; in development warns once when it is not an `<input>` of\n * the expected `type`.\n * 2. Mount reconciliation (single controls): a click before hydration or Firefox's form-state\n * restoration left the DOM different from what the user intends; reported once with\n * `event: undefined`.\n * 3. Re-apply after every commit: `checked` (optimistic, or the latest in-flight value),\n * `indeterminate` and `defaultChecked`, none of which React manages for a controlled input\n * except `checked`.\n * 4. Form reset (single controls): in a microtask after the reset, compares `el.defaultChecked`\n * with what the user intends and reports a difference with the `reset` event.\n *\n * The hook knows nothing about transitions or `reason`; the part wires `onPlatformChange`.\n */\nexport function useNativeChecked(options: UseNativeCheckedOptions): RefCallback<HTMLInputElement> {\n const { type, component, checked, defaultChecked, indeterminate, group = false } = options;\n const node = useRef<HTMLInputElement | null>(null);\n const warnedElement = useRef(false);\n\n const ref = useCallback(\n (el: HTMLInputElement) => {\n node.current = el;\n if (isDev && !warnedElement.current && !isInputOfType(el, type)) {\n warnedElement.current = true;\n console.error(\n `${component}: expected to render an \\`<input type=\"${type}\">\\` but got ` +\n `${describeElement(el)}; the platform semantics (form participation, labels, ` +\n `keyboard, reset) need a real input. A \\`render\\` element must keep the input.`,\n );\n }\n return () => {\n node.current = null;\n };\n },\n [type, component],\n );\n\n /** What the user intends: the latest in-flight dispatch, else the optimistic value (rule 1). */\n const readBase = useEffectEvent(() => options.latestInFlight?.()?.next ?? checked);\n const report = useEffectEvent((next: boolean, event: Event | undefined) => {\n options.onPlatformChange?.(next, event);\n });\n\n // 2. Mount reconciliation. Declared before the re-apply effect so that the hydrated DOM value is\n // read before anything overwrites it (rule 3). StrictMode's second run finds the first run's\n // dispatch in flight and does nothing.\n const reconcileMount = useEffectEvent(() => {\n if (group) return;\n const el = node.current;\n if (el === null) return;\n if (el.checked !== readBase()) report(el.checked, undefined);\n });\n useLayoutEffect(() => {\n reconcileMount();\n }, []);\n\n // 2b. Group members tell the Root they mounted; the Root reconciles the group again if its own\n // mount reconciliation already ran (a member mounting later), which covers the `checked`\n // write this member skips in its mount commit (below).\n const notifyMounted = useEffectEvent(() => {\n if (group) options.onItemMounted?.(node.current);\n });\n useLayoutEffect(() => {\n notifyMounted();\n }, []);\n\n // 3. Re-apply after every commit (rule 8). `checked` is skipped in the mount commit (including\n // StrictMode's re-run of it, which closes over the same render): React has just written it\n // from the prop, or kept the hydrated DOM value for the residual path to read. That matters\n // for groups, whose Root reconciles in its own layout effect, after its Items' effects.\n const renderToken = {};\n const mountToken = useRef<object | null>(null);\n useLayoutEffect(() => {\n if (mountToken.current === null) mountToken.current = renderToken;\n const el = node.current;\n if (el === null) return;\n // The order defaultChecked -> checked -> indeterminate is load-bearing for the first two.\n // React's automatic reset after a <form action> runs in the mutation phase, after react-dom\n // wrote `checked` and before this effect, and clears the dirty-checkedness flag; writing\n // `defaultChecked` (a new default from the same transition) then moves `checked` too, and the\n // `checked` write that follows restores the intended value. The other way round, the `checked`\n // write is skipped (it still matches) and the DOM ends up on the new default.\n // `indeterminate` is independent of both writes and goes last. Tested in\n // use-native-checked.test.tsx (\"re-apply order\").\n if (defaultChecked !== undefined && el.defaultChecked !== defaultChecked) {\n el.defaultChecked = defaultChecked;\n }\n if (mountToken.current !== renderToken) {\n const want = readBase();\n if (el.checked !== want) el.checked = want;\n }\n if (indeterminate !== undefined && el.indeterminate !== indeterminate) {\n el.indeterminate = indeterminate;\n }\n });\n\n // 4. Form reset (rules 4 to 7). `el.defaultChecked` is the value the browser reset to; by the\n // time the microtask runs after React's own reset, the re-apply effect may already have put\n // the optimistic value back into `checked`. (`useFormReset` already calls this through an\n // Effect Event, so it reads the latest render's options directly.)\n useFormReset(node, (event) => {\n if (group) return;\n const el = node.current;\n if (el === null) return;\n const next = el.defaultChecked;\n const base = options.latestInFlight?.()?.next ?? checked;\n if (next !== base) options.onPlatformChange?.(next, event);\n else if (el.checked !== base) el.checked = base;\n });\n\n return ref;\n}\n\nfunction isInputOfType(el: Element, type: string): boolean {\n return el.tagName === \"INPUT\" && (el as HTMLInputElement).type === type;\n}\n\nfunction describeElement(el: Element): string {\n const tag = el.tagName.toLowerCase();\n return tag === \"input\" ? `\\`<input type=\"${(el as HTMLInputElement).type}\">\\`` : `\\`<${tag}>\\``;\n}\n\nconst warnedPreventDefault = new WeakSet<EventTarget>();\n\n/**\n * Shared `onChange` guard for checkable inputs (conventions 3.8 rule 9, 2.3 item 3):\n *\n * - A click that is already cancelled (`preventDefault()` in a pass-through `onClick`, which runs\n * before the library's `onChange`) is not a change: the browser reverts the DOM after dispatch\n * and React restores unchanged props. Nothing is dispatched.\n * - Otherwise `dispatch()` runs (the action's sync prefix included); if the event is cancelled\n * now, the action's sync prefix called `preventDefault()`, which desyncs the input while the\n * action is pending. Development warns once per input element.\n */\nexport function guardCheckableChange(\n event: Event,\n dispatch: () => void,\n component: string = \"A checkable input\",\n): void {\n if (event.defaultPrevented) return;\n dispatch();\n if (!isDev || !event.defaultPrevented) return;\n const target = event.target;\n if (target !== null) {\n if (warnedPreventDefault.has(target)) return;\n warnedPreventDefault.add(target);\n }\n console.error(\n `${component}: \\`preventDefault()\\` on the change event is not supported; it desyncs the ` +\n `input while the action is pending. Use controlled mode to veto a change.`,\n );\n}\n"],"mappings":";;;;AAKA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;;AAyDvC,SAAgB,iBAAiB,SAAiE;CAChG,MAAM,EAAE,MAAM,WAAW,SAAS,gBAAgB,eAAe,QAAQ,UAAU;CACnF,MAAM,OAAO,OAAgC,IAAI;CACjD,MAAM,gBAAgB,OAAO,KAAK;CAElC,MAAM,MAAM,aACT,OAAyB;EACxB,KAAK,UAAU;EACf,IAAI,SAAS,CAAC,cAAc,WAAW,CAAC,cAAc,IAAI,IAAI,GAAG;GAC/D,cAAc,UAAU;GACxB,QAAQ,MACN,GAAG,UAAU,yCAAyC,KAAK,eACtD,gBAAgB,EAAE,EAAE,oIAE3B;EACF;EACA,aAAa;GACX,KAAK,UAAU;EACjB;CACF,GACA,CAAC,MAAM,SAAS,CAClB;;CAGA,MAAM,WAAW,qBAAqB,QAAQ,iBAAiB,CAAC,EAAE,QAAQ,OAAO;CACjF,MAAM,SAAS,gBAAgB,MAAe,UAA6B;EACzE,QAAQ,mBAAmB,MAAM,KAAK;CACxC,CAAC;CAKD,MAAM,iBAAiB,qBAAqB;EAC1C,IAAI,OAAO;EACX,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EACjB,IAAI,GAAG,YAAY,SAAS,GAAG,OAAO,GAAG,SAAS,KAAA,CAAS;CAC7D,CAAC;CACD,sBAAsB;EACpB,eAAe;CACjB,GAAG,CAAC,CAAC;CAKL,MAAM,gBAAgB,qBAAqB;EACzC,IAAI,OAAO,QAAQ,gBAAgB,KAAK,OAAO;CACjD,CAAC;CACD,sBAAsB;EACpB,cAAc;CAChB,GAAG,CAAC,CAAC;CAML,MAAM,cAAc,CAAC;CACrB,MAAM,aAAa,OAAsB,IAAI;CAC7C,sBAAsB;EACpB,IAAI,WAAW,YAAY,MAAM,WAAW,UAAU;EACtD,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EASjB,IAAI,mBAAmB,KAAA,KAAa,GAAG,mBAAmB,gBACxD,GAAG,iBAAiB;EAEtB,IAAI,WAAW,YAAY,aAAa;GACtC,MAAM,OAAO,SAAS;GACtB,IAAI,GAAG,YAAY,MAAM,GAAG,UAAU;EACxC;EACA,IAAI,kBAAkB,KAAA,KAAa,GAAG,kBAAkB,eACtD,GAAG,gBAAgB;CAEvB,CAAC;CAMD,aAAa,OAAO,UAAU;EAC5B,IAAI,OAAO;EACX,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EACjB,MAAM,OAAO,GAAG;EAChB,MAAM,OAAO,QAAQ,iBAAiB,CAAC,EAAE,QAAQ;EACjD,IAAI,SAAS,MAAM,QAAQ,mBAAmB,MAAM,KAAK;OACpD,IAAI,GAAG,YAAY,MAAM,GAAG,UAAU;CAC7C,CAAC;CAED,OAAO;AACT;AAEA,SAAS,cAAc,IAAa,MAAuB;CACzD,OAAO,GAAG,YAAY,WAAY,GAAwB,SAAS;AACrE;AAEA,SAAS,gBAAgB,IAAqB;CAC5C,MAAM,MAAM,GAAG,QAAQ,YAAY;CACnC,OAAO,QAAQ,UAAU,kBAAmB,GAAwB,KAAK,QAAQ,MAAM,IAAI;AAC7F;AAEA,MAAM,uCAAuB,IAAI,QAAqB;;;;;;;;;;;AAYtD,SAAgB,qBACd,OACA,UACA,YAAoB,qBACd;CACN,IAAI,MAAM,kBAAkB;CAC5B,SAAS;CACT,IAAI,CAAC,SAAS,CAAC,MAAM,kBAAkB;CACvC,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,MAAM;EACnB,IAAI,qBAAqB,IAAI,MAAM,GAAG;EACtC,qBAAqB,IAAI,MAAM;CACjC;CACA,QAAQ,MACN,GAAG,UAAU,qJAEf;AACF"}
|
|
1
|
+
{"version":3,"file":"use-native-checked.mjs","names":[],"sources":["../../src/internal/use-native-checked.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefCallback } from \"react\";\nimport { useElementCheck } from \"./use-element-check.js\";\nimport { useFormReset } from \"./use-form-reset.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface UseNativeCheckedOptions {\n /** Dev-only: the expected `input.type`. */\n readonly type: \"checkbox\" | \"radio\";\n /** Dev-only: the part's name in warnings (`\"Switch\"`, `\"RadioGroup.Item\"`). */\n readonly component: string;\n /** What the DOM must show after every commit: the optimistic value. */\n readonly checked: boolean;\n /**\n * The form-reset target. Uncontrolled parts pass the latest `defaultChecked` prop (`?? false`),\n * mirrored into `el.defaultChecked` after every commit. Controlled parts pass `undefined`:\n * React's mount-time value stays (conventions 3.8 rule 6).\n */\n readonly defaultChecked: boolean | undefined;\n /** Checkbox only: `el.indeterminate` after every commit (the part passes `indeterminate && !pending`). */\n readonly indeterminate?: boolean | undefined;\n /**\n * `true` inside a group (`RadioGroup.Item`, `CheckboxGroup.Item` and `.Parent`): the hook does\n * the element check and the re-apply only; mount reconciliation and form reset are reported\n * once per group by the Root through `useNativeGroupReconciliation`. Default `false`: the hook\n * reports both paths itself.\n */\n readonly group?: boolean | undefined;\n /**\n * Group members only: the Root's `onItemMounted` from `useNativeGroupReconciliation`. Called\n * from this member's mount layout effect so that a member mounting after the Root (a Suspense\n * boundary that hydrates later) still gets the group reconciled. Receives the member's element\n * (`null` if the ref is not attached). Ignored without `group`.\n */\n readonly onItemMounted?: ((element: HTMLInputElement | null) => void) | undefined;\n /** From `useControllableAction`: the value the DOM is compared against on the residual paths. */\n readonly latestInFlight?: (() => { readonly next: boolean } | null) | undefined;\n /**\n * Single controls only. The browser changed the value on a residual path and it differs from\n * what the user intends. `event` is the `reset` event, or `undefined` for mount reconciliation.\n * The part dispatches with `reason: \"platform\"`.\n */\n readonly onPlatformChange?: ((next: boolean, event: Event | undefined) => void) | undefined;\n}\n\n/**\n * Per-element machinery for a controlled native `<input type=\"checkbox\" | \"radio\">`\n * (conventions 3.8): returns the ref to attach to the input (merged by `useRender`).\n *\n * 1. Ref callback: stores the node; in development warns once when it is not an `<input>` of\n * the expected `type`.\n * 2. Mount reconciliation (single controls): a click before hydration or Firefox's form-state\n * restoration left the DOM different from what the user intends; reported once with\n * `event: undefined`.\n * 3. Re-apply after every commit: `checked` (optimistic, or the latest in-flight value),\n * `indeterminate` and `defaultChecked`, none of which React manages for a controlled input\n * except `checked`.\n * 4. Form reset (single controls): in a microtask after the reset, compares `el.defaultChecked`\n * with what the user intends and reports a difference with the `reset` event.\n *\n * The hook knows nothing about transitions or `reason`; the part wires `onPlatformChange`.\n */\nexport function useNativeChecked(options: UseNativeCheckedOptions): RefCallback<HTMLInputElement> {\n const { type, component, checked, defaultChecked, indeterminate, group = false } = options;\n const node = useRef<HTMLInputElement | null>(null);\n const checkElement = useElementCheck<HTMLInputElement>(\n isDev &&\n ((el) =>\n isInputOfType(el, type)\n ? null\n : `${component}: expected to render an \\`<input type=\"${type}\">\\` but got ` +\n `${describeElement(el)}; the platform semantics (form participation, labels, ` +\n `keyboard, reset) need a real input. A \\`render\\` element must keep the input.`),\n );\n\n const ref = useCallback(\n (el: HTMLInputElement) => {\n node.current = el;\n checkElement?.(el);\n return () => {\n node.current = null;\n };\n },\n [checkElement],\n );\n\n /** What the user intends: the latest in-flight dispatch, else the optimistic value (rule 1). */\n const readBase = useEffectEvent(() => options.latestInFlight?.()?.next ?? checked);\n const report = useEffectEvent((next: boolean, event: Event | undefined) => {\n options.onPlatformChange?.(next, event);\n });\n\n // 2. Mount reconciliation. Declared before the re-apply effect so that the hydrated DOM value is\n // read before anything overwrites it (rule 3). StrictMode's second run finds the first run's\n // dispatch in flight and does nothing.\n const reconcileMount = useEffectEvent(() => {\n if (group) return;\n const el = node.current;\n if (el === null) return;\n if (el.checked !== readBase()) report(el.checked, undefined);\n });\n useLayoutEffect(() => {\n reconcileMount();\n }, []);\n\n // 2b. Group members tell the Root they mounted; the Root reconciles the group again if its own\n // mount reconciliation already ran (a member mounting later), which covers the `checked`\n // write this member skips in its mount commit (below).\n const notifyMounted = useEffectEvent(() => {\n if (group) options.onItemMounted?.(node.current);\n });\n useLayoutEffect(() => {\n notifyMounted();\n }, []);\n\n // 3. Re-apply after every commit (rule 8). `checked` is skipped in the mount commit (including\n // StrictMode's re-run of it, which closes over the same render): React has just written it\n // from the prop, or kept the hydrated DOM value for the residual path to read. That matters\n // for groups, whose Root reconciles in its own layout effect, after its Items' effects.\n const renderToken = {};\n const mountToken = useRef<object | null>(null);\n useLayoutEffect(() => {\n if (mountToken.current === null) mountToken.current = renderToken;\n const el = node.current;\n if (el === null) return;\n // defaultChecked before checked (conventions 3.8): after React's automatic `<form action>`\n // reset clears the dirty flag, writing `defaultChecked` moves `checked` too, and the `checked`\n // write that follows restores the intended value. `indeterminate` is independent and goes\n // last. Pinned by use-native-checked.test.tsx (\"re-apply order\").\n if (defaultChecked !== undefined && el.defaultChecked !== defaultChecked) {\n el.defaultChecked = defaultChecked;\n }\n if (mountToken.current !== renderToken) {\n const want = readBase();\n if (el.checked !== want) el.checked = want;\n }\n if (indeterminate !== undefined && el.indeterminate !== indeterminate) {\n el.indeterminate = indeterminate;\n }\n });\n\n // 4. Form reset (rules 4 to 7). `el.defaultChecked` is the value the browser reset to; by the\n // time the microtask runs after React's own reset, the re-apply effect may already have put\n // the optimistic value back into `checked`. (`useFormReset` already calls this through an\n // Effect Event, so it reads the latest render's options directly.)\n useFormReset(node, (event) => {\n if (group) return;\n const el = node.current;\n if (el === null) return;\n const next = el.defaultChecked;\n const base = options.latestInFlight?.()?.next ?? checked;\n if (next !== base) options.onPlatformChange?.(next, event);\n else if (el.checked !== base) el.checked = base;\n });\n\n return ref;\n}\n\nfunction isInputOfType(el: Element, type: string): boolean {\n return el.tagName === \"INPUT\" && (el as HTMLInputElement).type === type;\n}\n\nfunction describeElement(el: Element): string {\n const tag = el.tagName.toLowerCase();\n return tag === \"input\" ? `\\`<input type=\"${(el as HTMLInputElement).type}\">\\`` : `\\`<${tag}>\\``;\n}\n\nconst warnedPreventDefault = new WeakSet<EventTarget>();\n\n/**\n * Shared `onChange` guard for checkable inputs (conventions 3.8 rule 9, 2.3 item 3):\n *\n * - A click that is already cancelled (`preventDefault()` in a pass-through `onClick`, which runs\n * before the library's `onChange`) is not a change: the browser reverts the DOM after dispatch\n * and React restores unchanged props. Nothing is dispatched.\n * - Otherwise `dispatch()` runs (the action's sync prefix included); if the event is cancelled\n * now, the action's sync prefix called `preventDefault()`, which desyncs the input while the\n * action is pending. Development warns once per input element.\n */\nexport function guardCheckableChange(\n event: Event,\n dispatch: () => void,\n component: string = \"A checkable input\",\n): void {\n if (event.defaultPrevented) return;\n dispatch();\n if (!isDev || !event.defaultPrevented) return;\n const target = event.target;\n if (target !== null) {\n if (warnedPreventDefault.has(target)) return;\n warnedPreventDefault.add(target);\n }\n console.error(\n `${component}: \\`preventDefault()\\` on the change event is not supported; it desyncs the ` +\n `input while the action is pending. Use controlled mode to veto a change.`,\n );\n}\n"],"mappings":";;;;;AAMA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;;AA0DvC,SAAgB,iBAAiB,SAAiE;CAChG,MAAM,EAAE,MAAM,WAAW,SAAS,gBAAgB,eAAe,QAAQ,UAAU;CACnF,MAAM,OAAO,OAAgC,IAAI;CACjD,MAAM,eAAe,gBACnB,WACI,OACA,cAAc,IAAI,IAAI,IAClB,OACA,GAAG,UAAU,yCAAyC,KAAK,eACxD,gBAAgB,EAAE,EAAE,qIAEjC;CAEA,MAAM,MAAM,aACT,OAAyB;EACxB,KAAK,UAAU;EACf,eAAe,EAAE;EACjB,aAAa;GACX,KAAK,UAAU;EACjB;CACF,GACA,CAAC,YAAY,CACf;;CAGA,MAAM,WAAW,qBAAqB,QAAQ,iBAAiB,CAAC,EAAE,QAAQ,OAAO;CACjF,MAAM,SAAS,gBAAgB,MAAe,UAA6B;EACzE,QAAQ,mBAAmB,MAAM,KAAK;CACxC,CAAC;CAKD,MAAM,iBAAiB,qBAAqB;EAC1C,IAAI,OAAO;EACX,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EACjB,IAAI,GAAG,YAAY,SAAS,GAAG,OAAO,GAAG,SAAS,KAAA,CAAS;CAC7D,CAAC;CACD,sBAAsB;EACpB,eAAe;CACjB,GAAG,CAAC,CAAC;CAKL,MAAM,gBAAgB,qBAAqB;EACzC,IAAI,OAAO,QAAQ,gBAAgB,KAAK,OAAO;CACjD,CAAC;CACD,sBAAsB;EACpB,cAAc;CAChB,GAAG,CAAC,CAAC;CAML,MAAM,cAAc,CAAC;CACrB,MAAM,aAAa,OAAsB,IAAI;CAC7C,sBAAsB;EACpB,IAAI,WAAW,YAAY,MAAM,WAAW,UAAU;EACtD,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EAKjB,IAAI,mBAAmB,KAAA,KAAa,GAAG,mBAAmB,gBACxD,GAAG,iBAAiB;EAEtB,IAAI,WAAW,YAAY,aAAa;GACtC,MAAM,OAAO,SAAS;GACtB,IAAI,GAAG,YAAY,MAAM,GAAG,UAAU;EACxC;EACA,IAAI,kBAAkB,KAAA,KAAa,GAAG,kBAAkB,eACtD,GAAG,gBAAgB;CAEvB,CAAC;CAMD,aAAa,OAAO,UAAU;EAC5B,IAAI,OAAO;EACX,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,MAAM;EACjB,MAAM,OAAO,GAAG;EAChB,MAAM,OAAO,QAAQ,iBAAiB,CAAC,EAAE,QAAQ;EACjD,IAAI,SAAS,MAAM,QAAQ,mBAAmB,MAAM,KAAK;OACpD,IAAI,GAAG,YAAY,MAAM,GAAG,UAAU;CAC7C,CAAC;CAED,OAAO;AACT;AAEA,SAAS,cAAc,IAAa,MAAuB;CACzD,OAAO,GAAG,YAAY,WAAY,GAAwB,SAAS;AACrE;AAEA,SAAS,gBAAgB,IAAqB;CAC5C,MAAM,MAAM,GAAG,QAAQ,YAAY;CACnC,OAAO,QAAQ,UAAU,kBAAmB,GAAwB,KAAK,QAAQ,MAAM,IAAI;AAC7F;AAEA,MAAM,uCAAuB,IAAI,QAAqB;;;;;;;;;;;AAYtD,SAAgB,qBACd,OACA,UACA,YAAoB,qBACd;CACN,IAAI,MAAM,kBAAkB;CAC5B,SAAS;CACT,IAAI,CAAC,SAAS,CAAC,MAAM,kBAAkB;CACvC,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,MAAM;EACnB,IAAI,qBAAqB,IAAI,MAAM,GAAG;EACtC,qBAAqB,IAAI,MAAM;CACjC;CACA,QAAQ,MACN,GAAG,UAAU,qJAEf;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
//#region src/internal/use-native-focusgroup.ts
|
|
4
|
+
/** Engine capabilities never change while the page lives. */
|
|
5
|
+
const subscribeNever = () => () => {};
|
|
6
|
+
/**
|
|
7
|
+
* Whether the native `focusgroup` path is on: the `experimental_focusgroup` flag is set and the
|
|
8
|
+
* engine implements it. Detected only with the flag, and never during SSR or hydration
|
|
9
|
+
* (conventions 8): the server snapshot is `false`, so hydration markup matches the server and
|
|
10
|
+
* React re-renders with the client answer afterwards. The IDL attribute is camel-cased
|
|
11
|
+
* `focusGroup` (`"focusgroup" in HTMLElement.prototype` is always false).
|
|
12
|
+
*/
|
|
13
|
+
function useNativeFocusgroup(flag) {
|
|
14
|
+
return useSyncExternalStore(subscribeNever, () => flag && "focusGroup" in HTMLElement.prototype, () => false);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { useNativeFocusgroup };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=use-native-focusgroup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-native-focusgroup.mjs","names":[],"sources":["../../src/internal/use-native-focusgroup.ts"],"sourcesContent":["\"use client\";\nimport { useSyncExternalStore } from \"react\";\n\n/** Engine capabilities never change while the page lives. */\nconst subscribeNever = () => () => {};\n\n/**\n * Whether the native `focusgroup` path is on: the `experimental_focusgroup` flag is set and the\n * engine implements it. Detected only with the flag, and never during SSR or hydration\n * (conventions 8): the server snapshot is `false`, so hydration markup matches the server and\n * React re-renders with the client answer afterwards. The IDL attribute is camel-cased\n * `focusGroup` (`\"focusgroup\" in HTMLElement.prototype` is always false).\n */\nexport function useNativeFocusgroup(flag: boolean): boolean {\n return useSyncExternalStore(\n subscribeNever,\n () => flag && \"focusGroup\" in HTMLElement.prototype,\n () => false,\n );\n}\n"],"mappings":";;;;AAIA,MAAM,6BAA6B,CAAC;;;;;;;;AASpC,SAAgB,oBAAoB,MAAwB;CAC1D,OAAO,qBACL,sBACM,QAAQ,gBAAgB,YAAY,iBACpC,KACR;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-native-group-reconciliation.mjs","names":[],"sources":["../../src/internal/use-native-group-reconciliation.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { useFormReset } from \"./use-form-reset.js\";\nimport type { FormAssociatedElement } from \"./use-form-
|
|
1
|
+
{"version":3,"file":"use-native-group-reconciliation.mjs","names":[],"sources":["../../src/internal/use-native-group-reconciliation.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { useFormReset } from \"./use-form-reset.js\";\nimport type { FormAssociatedElement } from \"./use-form-owner-event.js\";\nimport { useLatest } from \"./use-latest.js\";\n\nexport interface UseNativeGroupReconciliationOptions<T> {\n /**\n * The group's form-associated element: `RadioGroup.Root`'s / `CheckboxGroup.Root`'s\n * `<fieldset>`, `Select.Root`'s `<select>` (whose options are the members), or any member\n * input when the Root renders no form-associated element (`Slider.Root` subscribes through its\n * first Thumb's `<input type=\"range\">`).\n */\n readonly element: RefObject<FormAssociatedElement | null>;\n /** The group's value as the DOM shows it now (`checked` of the members). */\n readonly readCurrent: () => T;\n /** The value the browser resets the group to (`defaultChecked` of the members, rule 5). */\n readonly readDefault: () => T;\n /**\n * What the user intends (rule 1): the latest in-flight dispatch's `next`, else the optimistic\n * value. `intendedValue` (use-controllable-action.ts) keeps an in-flight dispatch of a nullish\n * value (a pending reset to \"nothing checked\"), which `?.next ?? optimistic` would drop.\n */\n readonly base: () => T;\n /**\n * The browser changed the group's value on a residual path and it differs from `base()`.\n * `event` is the `reset` event, or `undefined` for mount reconciliation (the Root's mount, or a\n * member mounting later). The Root dispatches once for the whole group with\n * `reason: \"platform\"`.\n */\n readonly onPlatformChange: (next: T, event: Event | undefined) => void;\n /**\n * Equality between a read value and `base()`. Default `Object.is`, right for a primitive value\n * (RadioGroup's `string | null`); a group with a collection value (CheckboxGroup's\n * `ReadonlySet<string>`) passes structural equality, since every read builds a new object.\n */\n readonly equals?: ((a: T, b: T) => boolean) | undefined;\n /**\n * Passed through to `useFormReset`: called synchronously from the `reset` event, before the\n * reset algorithm runs. A group of controlled **value** inputs (Slider) writes each input's\n * `defaultValue` to the reset target here, because react-dom keeps that attribute equal to the\n * current value after every update (conventions 3.8 rule 6).\n */\n readonly onResetEvent?: ((event: Event) => void) | undefined;\n}\n\nexport interface UseNativeGroupReconciliationResult {\n /**\n * Stable. Pass it to every member, which hands it to\n * `useNativeChecked({ group: true, onItemMounted })`; the hook calls it from the member's mount\n * layout effect. A member that mounts after the Root's own mount reconciliation (inside a\n * Suspense boundary that hydrates later, selective hydration, or a member added on the client)\n * makes the adapter reconcile the group again: `readCurrent()` vs `base()`, in a microtask, once\n * for all members mounted in the same commit. Members mounting in the Root's own commit are\n * covered by the Root's mount reconciliation (their effects run before the Root's) and are\n * ignored. The member's element argument is not used here; the Root may use it (dev warnings).\n */\n readonly onItemMounted: (element?: Element | null) => void;\n}\n\n/**\n * Group adapter of the native-input machinery (conventions 3.8): one dispatch per group for the\n * residual browser paths, from the Root rather than once per member.\n *\n * - Mount reconciliation, once, in a layout effect: `readCurrent()` vs `base()`. The members'\n * `useNativeChecked({ group: true })` leaves `checked` alone in their mount commit, so this\n * effect, which runs after the members' (children first), still reads the hydrated DOM.\n * - Late members: a member mounting in a later commit (a Suspense boundary that hydrates after the\n * Root, where a click before hydration changed the DOM) reports through `onItemMounted`, and the\n * group is reconciled again the same way (see `UseNativeGroupReconciliationResult`).\n * - Form reset through `useFormReset` on the container: in a microtask after the reset,\n * `readDefault()` vs `base()`.\n *\n * Values are compared with `equals` (default `Object.is`).\n */\nexport function useNativeGroupReconciliation<T>(\n options: UseNativeGroupReconciliationOptions<T>,\n): UseNativeGroupReconciliationResult {\n const { element } = options;\n\n // The latest committed options, for the late reconciliation, which runs in a microtask outside\n // any effect (so it cannot go through an Effect Event).\n const latest = useLatest(options);\n\n /** The Root's own mount reconciliation has run (reset by its cleanup, StrictMode included). */\n const rootReconciled = useRef(false);\n /** A late reconciliation is queued; members mounting in the same commit share it. */\n const lateQueued = useRef(false);\n\n const reconcileMount = useEffectEvent(() => {\n if (element.current === null) return;\n reconcile(options, options.readCurrent());\n });\n useLayoutEffect(() => {\n reconcileMount();\n rootReconciled.current = true;\n return () => {\n rootReconciled.current = false;\n };\n }, []);\n\n const onItemMounted = useCallback(() => {\n if (!rootReconciled.current || lateQueued.current) return;\n lateQueued.current = true;\n queueMicrotask(() => {\n lateQueued.current = false;\n if (!rootReconciled.current) return;\n const current = latest.current;\n if (current.element.current === null) return;\n reconcile(current, current.readCurrent());\n });\n }, [latest]);\n\n useFormReset(\n element,\n (event) => {\n if (element.current === null) return;\n reconcile(options, options.readDefault(), event);\n },\n (event) => {\n if (element.current === null) return;\n options.onResetEvent?.(event);\n },\n );\n\n return { onItemMounted };\n}\n\nfunction reconcile<T>(options: UseNativeGroupReconciliationOptions<T>, next: T, event?: Event) {\n const equals = options.equals ?? Object.is;\n if (!equals(next, options.base())) options.onPlatformChange(next, event);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4EA,SAAgB,6BACd,SACoC;CACpC,MAAM,EAAE,YAAY;CAIpB,MAAM,SAAS,UAAU,OAAO;;CAGhC,MAAM,iBAAiB,OAAO,KAAK;;CAEnC,MAAM,aAAa,OAAO,KAAK;CAE/B,MAAM,iBAAiB,qBAAqB;EAC1C,IAAI,QAAQ,YAAY,MAAM;EAC9B,UAAU,SAAS,QAAQ,YAAY,CAAC;CAC1C,CAAC;CACD,sBAAsB;EACpB,eAAe;EACf,eAAe,UAAU;EACzB,aAAa;GACX,eAAe,UAAU;EAC3B;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,kBAAkB;EACtC,IAAI,CAAC,eAAe,WAAW,WAAW,SAAS;EACnD,WAAW,UAAU;EACrB,qBAAqB;GACnB,WAAW,UAAU;GACrB,IAAI,CAAC,eAAe,SAAS;GAC7B,MAAM,UAAU,OAAO;GACvB,IAAI,QAAQ,QAAQ,YAAY,MAAM;GACtC,UAAU,SAAS,QAAQ,YAAY,CAAC;EAC1C,CAAC;CACH,GAAG,CAAC,MAAM,CAAC;CAEX,aACE,UACC,UAAU;EACT,IAAI,QAAQ,YAAY,MAAM;EAC9B,UAAU,SAAS,QAAQ,YAAY,GAAG,KAAK;CACjD,IACC,UAAU;EACT,IAAI,QAAQ,YAAY,MAAM;EAC9B,QAAQ,eAAe,KAAK;CAC9B,CACF;CAEA,OAAO,EAAE,cAAc;AACzB;AAEA,SAAS,UAAa,SAAiD,MAAS,OAAe;CAE7F,IAAI,EADW,QAAQ,UAAU,OAAO,GAAA,CAC5B,MAAM,QAAQ,KAAK,CAAC,GAAG,QAAQ,iBAAiB,MAAM,KAAK;AACzE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dataAttr } from "./data-attr.mjs";
|
|
3
|
+
import { useActionTrigger } from "./use-action-trigger.mjs";
|
|
4
|
+
import { disabledButton, rendersButton } from "./render-element.mjs";
|
|
5
|
+
import { useRender } from "./use-render.mjs";
|
|
6
|
+
import { useElementCheck } from "./use-element-check.mjs";
|
|
7
|
+
//#region src/internal/use-overlay-close.ts
|
|
8
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
9
|
+
/**
|
|
10
|
+
* The Close part of a popover-like or dialog overlay (design/components/popover.md 3.4,
|
|
11
|
+
* dialog.md 3.4): `<button type="button" commandfor command>`. In JS-free mode without `action`
|
|
12
|
+
* the browser runs the command. Otherwise the click is cancelled, refused while disabled, and
|
|
13
|
+
* `close` runs, after the `action` when there is one, inside this part's own transition; a
|
|
14
|
+
* second click meanwhile starts nothing, and a close whose open was superseded by a newer one
|
|
15
|
+
* (dismissed and re-opened meanwhile) is dropped (the open-generation guard).
|
|
16
|
+
*/
|
|
17
|
+
function useOverlayClose(options) {
|
|
18
|
+
const { part, noun, isLibrary, popupId, command, action, disabled, render } = options;
|
|
19
|
+
const { pending, run } = useActionTrigger({ openGeneration: options.openGeneration });
|
|
20
|
+
const installClick = isLibrary || action !== void 0;
|
|
21
|
+
const disabledProps = disabledButton(render, disabled, { handlesClick: installClick });
|
|
22
|
+
const ref = useElementCheck(isDev && ((element) => !installClick && element.tagName !== "BUTTON" ? `${part}: rendered a <${element.tagName.toLowerCase()}> in JS-free mode without \`action\`. Only a <button> runs \`command="${command}"\`; this element will not close the ${noun}.` : null), [installClick]);
|
|
23
|
+
const onClick = (event) => {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
if (disabled) return;
|
|
26
|
+
const native = event.nativeEvent;
|
|
27
|
+
if (action === void 0) {
|
|
28
|
+
options.close(native);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const details = options.details(native);
|
|
32
|
+
run(() => action(details), () => options.close(native));
|
|
33
|
+
};
|
|
34
|
+
const libraryProps = {
|
|
35
|
+
...rendersButton(render) && { type: "button" },
|
|
36
|
+
disabled: disabledProps.props.disabled,
|
|
37
|
+
commandfor: disabledProps.invoker ? popupId : void 0,
|
|
38
|
+
command: disabledProps.invoker ? command : void 0,
|
|
39
|
+
...options.ownProps,
|
|
40
|
+
...installClick && { onClick },
|
|
41
|
+
"aria-disabled": pending || !disabledProps.invoker ? true : void 0,
|
|
42
|
+
"data-pending": dataAttr(pending),
|
|
43
|
+
"data-disabled": dataAttr(disabled)
|
|
44
|
+
};
|
|
45
|
+
return useRender({
|
|
46
|
+
defaultElement: "button",
|
|
47
|
+
render,
|
|
48
|
+
state: {
|
|
49
|
+
pending,
|
|
50
|
+
disabled
|
|
51
|
+
},
|
|
52
|
+
className: options.className,
|
|
53
|
+
style: options.style,
|
|
54
|
+
children: options.children,
|
|
55
|
+
props: options.rest,
|
|
56
|
+
libraryProps,
|
|
57
|
+
ref
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { useOverlayClose };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=use-overlay-close.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-overlay-close.mjs","names":[],"sources":["../../src/internal/use-overlay-close.ts"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"./data-attr.js\";\nimport type { Action, ActionDetails, RenderProp, StateValue } from \"./types.js\";\nimport { useActionTrigger } from \"./use-action-trigger.js\";\nimport { useElementCheck } from \"./use-element-check.js\";\nimport { disabledButton, rendersButton, useRender } from \"./use-render.js\";\nimport type { DataAttributes } from \"./use-render.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The state of Popover.Close and Dialog.Close. */\nexport interface OverlayCloseState {\n /** The `action` is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface OverlayCloseOptions<Details extends ActionDetails> {\n /** Public name of the part (`\"Popover.Close\"`). */\n readonly part: string;\n /** What the part closes, for the development warning (`\"popover\"`). */\n readonly noun: string;\n readonly isLibrary: boolean;\n /** The popup's id (`commandfor`) and the native command. */\n readonly popupId: string;\n readonly command: \"hide-popover\" | \"request-close\";\n readonly openGeneration: () => number;\n readonly action: Action<[details: Details]> | undefined;\n /** The `action`'s details, built at the click. */\n readonly details: (event: Event) => Details;\n /** The close after the action (or at once without one): through the Root, or natively. */\n readonly close: (event: Event) => void;\n /** Owned keys after `command` (Dialog.Close's `value`). */\n readonly ownProps?: ComponentPropsWithRef<\"button\">;\n readonly disabled: boolean;\n readonly className: StateValue<string | undefined, OverlayCloseState> | undefined;\n readonly style: StateValue<CSSProperties | undefined, OverlayCloseState> | undefined;\n readonly children: StateValue<ReactNode, OverlayCloseState> | undefined;\n readonly render: RenderProp<ComponentPropsWithRef<\"button\">, OverlayCloseState> | undefined;\n readonly rest: Omit<ComponentPropsWithRef<\"button\">, \"className\" | \"style\" | \"children\">;\n}\n\n/**\n * The Close part of a popover-like or dialog overlay (design/components/popover.md 3.4,\n * dialog.md 3.4): `<button type=\"button\" commandfor command>`. In JS-free mode without `action`\n * the browser runs the command. Otherwise the click is cancelled, refused while disabled, and\n * `close` runs, after the `action` when there is one, inside this part's own transition; a\n * second click meanwhile starts nothing, and a close whose open was superseded by a newer one\n * (dismissed and re-opened meanwhile) is dropped (the open-generation guard).\n */\nexport function useOverlayClose<Details extends ActionDetails>(\n options: OverlayCloseOptions<Details>,\n): ReactNode {\n const { part, noun, isLibrary, popupId, command, action, disabled, render } = options;\n const { pending, run } = useActionTrigger({ openGeneration: options.openGeneration });\n const installClick = isLibrary || action !== undefined;\n // JS-free mode without `action` is the browser's command, which only native `disabled` stops.\n const disabledProps = disabledButton(render, disabled, { handlesClick: installClick });\n\n const ref = useElementCheck(\n isDev &&\n ((element) =>\n !installClick && element.tagName !== \"BUTTON\"\n ? `${part}: rendered a <${element.tagName.toLowerCase()}> in JS-free mode without ` +\n `\\`action\\`. Only a <button> runs \\`command=\"${command}\"\\`; this element will not ` +\n `close the ${noun}.`\n : null),\n [installClick],\n );\n\n const onClick = (event: MouseEvent<HTMLElement>) => {\n // Cancelling the click cancels the command.\n event.preventDefault();\n if (disabled) return;\n const native = event.nativeEvent;\n if (action === undefined) {\n options.close(native);\n return;\n }\n const details = options.details(native);\n run(\n () => action(details),\n () => options.close(native),\n );\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Close.\n disabled: disabledProps.props.disabled,\n commandfor: disabledProps.invoker ? popupId : undefined,\n command: disabledProps.invoker ? command : undefined,\n ...options.ownProps,\n ...(installClick && { onClick }),\n // Exactly while `data-pending`: a Close that will not act is unavailable to AT. Owned,\n // so an idle Close removes a render element's own `aria-disabled`.\n \"aria-disabled\": pending || !disabledProps.invoker ? true : undefined,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, OverlayCloseState>({\n defaultElement: \"button\",\n render,\n state: { pending, disabled },\n className: options.className,\n style: options.style,\n children: options.children,\n props: options.rest,\n libraryProps,\n ref,\n });\n}\n"],"mappings":";;;;;;;AASA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;AA0CvC,SAAgB,gBACd,SACW;CACX,MAAM,EAAE,MAAM,MAAM,WAAW,SAAS,SAAS,QAAQ,UAAU,WAAW;CAC9E,MAAM,EAAE,SAAS,QAAQ,iBAAiB,EAAE,gBAAgB,QAAQ,eAAe,CAAC;CACpF,MAAM,eAAe,aAAa,WAAW,KAAA;CAE7C,MAAM,gBAAgB,eAAe,QAAQ,UAAU,EAAE,cAAc,aAAa,CAAC;CAErF,MAAM,MAAM,gBACV,WACI,YACA,CAAC,gBAAgB,QAAQ,YAAY,WACjC,GAAG,KAAK,gBAAgB,QAAQ,QAAQ,YAAY,EAAE,wEACP,QAAQ,uCAC1C,KAAK,KAClB,OACR,CAAC,YAAY,CACf;CAEA,MAAM,WAAW,UAAmC;EAElD,MAAM,eAAe;EACrB,IAAI,UAAU;EACd,MAAM,SAAS,MAAM;EACrB,IAAI,WAAW,KAAA,GAAW;GACxB,QAAQ,MAAM,MAAM;GACpB;EACF;EACA,MAAM,UAAU,QAAQ,QAAQ,MAAM;EACtC,UACQ,OAAO,OAAO,SACd,QAAQ,MAAM,MAAM,CAC5B;CACF;CAEA,MAAM,eAAiE;EACrE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EAEvD,UAAU,cAAc,MAAM;EAC9B,YAAY,cAAc,UAAU,UAAU,KAAA;EAC9C,SAAS,cAAc,UAAU,UAAU,KAAA;EAC3C,GAAG,QAAQ;EACX,GAAI,gBAAgB,EAAE,QAAQ;EAG9B,iBAAiB,WAAW,CAAC,cAAc,UAAU,OAAO,KAAA;EAC5D,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA,OAAO;GAAE;GAAS;EAAS;EAC3B,WAAW,QAAQ;EACnB,OAAO,QAAQ;EACf,UAAU,QAAQ;EAClB,OAAO,QAAQ;EACf;EACA;CACF,CAAC;AACH"}
|