@funstack/ui 0.1.0-alpha.11 → 0.1.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordion/accordion-context.mjs.map +1 -1
- package/dist/accordion/accordion-item.d.mts +3 -4
- package/dist/accordion/accordion-item.d.mts.map +1 -1
- package/dist/accordion/accordion-item.mjs +10 -4
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-panel.d.mts +3 -4
- package/dist/accordion/accordion-panel.d.mts.map +1 -1
- package/dist/accordion/accordion-panel.mjs +2 -1
- package/dist/accordion/accordion-panel.mjs.map +1 -1
- package/dist/accordion/accordion-root.d.mts +3 -3
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +8 -19
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts +3 -4
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +5 -3
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/button/button.d.mts +4 -2
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +3 -2
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.d.mts +4 -5
- package/dist/checkbox/checkbox.d.mts.map +1 -1
- package/dist/checkbox/checkbox.mjs +16 -59
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-context.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-item.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +21 -27
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-label.mjs +1 -6
- package/dist/checkbox-group/checkbox-group-label.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-parent.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +12 -10
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +74 -101
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +5 -6
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-group.d.mts.map +1 -1
- package/dist/combobox/combobox-group.mjs +2 -1
- package/dist/combobox/combobox-group.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +14 -7
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts.map +1 -1
- package/dist/combobox/combobox-list.mjs +6 -10
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +2 -1
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs +9 -25
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +30 -102
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +6 -25
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/index.mjs +1 -1
- package/dist/combobox/use-combobox-form.mjs +56 -0
- package/dist/combobox/use-combobox-form.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +62 -0
- package/dist/combobox/use-option-registry.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +29 -62
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +5 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +3 -4
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +37 -98
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +30 -118
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +13 -16
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/field/field-control.mjs +6 -13
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts.map +1 -1
- package/dist/field/field-description.mjs +1 -2
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts.map +1 -1
- package/dist/field/field-error.mjs +1 -2
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +3 -11
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +21 -41
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.mjs +1 -1
- package/dist/field/use-server-error-visibility.mjs +44 -0
- package/dist/field/use-server-error-visibility.mjs.map +1 -0
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +6 -7
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +1 -1
- package/dist/form/form-submit.mjs +4 -10
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/internal/anchor-position.mjs +1 -59
- package/dist/internal/anchor-position.mjs.map +1 -1
- package/dist/internal/announce.mjs.map +1 -1
- package/dist/internal/arrow-keys.mjs +21 -0
- package/dist/internal/arrow-keys.mjs.map +1 -0
- package/dist/internal/decimal.mjs +7 -1
- package/dist/internal/decimal.mjs.map +1 -1
- package/dist/internal/dom-order.mjs +17 -0
- package/dist/internal/dom-order.mjs.map +1 -0
- package/dist/internal/field-context.d.mts.map +1 -1
- package/dist/internal/field-context.mjs +11 -1
- package/dist/internal/field-context.mjs.map +1 -1
- package/dist/internal/focus-first-invalid.mjs +1 -1
- package/dist/internal/focus-first-invalid.mjs.map +1 -1
- package/dist/internal/group-member.mjs +37 -0
- package/dist/internal/group-member.mjs.map +1 -0
- package/dist/internal/overlay-popup.mjs +103 -0
- package/dist/internal/overlay-popup.mjs.map +1 -0
- package/dist/internal/popover-open.mjs +18 -0
- package/dist/internal/popover-open.mjs.map +1 -0
- package/dist/internal/render-element.d.mts +2 -0
- package/dist/internal/render-element.mjs +20 -2
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/shipped-styles.mjs +14 -0
- package/dist/internal/shipped-styles.mjs.map +1 -0
- package/dist/internal/sync-presence.mjs +5 -1
- package/dist/internal/sync-presence.mjs.map +1 -1
- package/dist/internal/toolbar-context.mjs.map +1 -1
- package/dist/internal/tooltip-warm.mjs +1 -1
- package/dist/internal/tooltip-warm.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +1 -1
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/types.d.mts +2 -0
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +5 -23
- package/dist/internal/use-action-trigger.mjs.map +1 -1
- package/dist/internal/use-checkable-input.mjs +79 -0
- package/dist/internal/use-checkable-input.mjs.map +1 -0
- package/dist/internal/use-controllable-action.mjs +16 -24
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- package/dist/internal/use-dev-warning.mjs +8 -4
- package/dist/internal/use-dev-warning.mjs.map +1 -1
- package/dist/internal/use-element-check.mjs +39 -0
- package/dist/internal/use-element-check.mjs.map +1 -0
- package/dist/internal/use-exit-animation.mjs +1 -1
- package/dist/internal/use-exit-animation.mjs.map +1 -1
- package/dist/internal/use-field-control.mjs +28 -12
- package/dist/internal/use-field-control.mjs.map +1 -1
- package/dist/internal/use-fieldset-group.mjs +46 -0
- package/dist/internal/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/use-form-reset.mjs +1 -5
- package/dist/internal/use-form-reset.mjs.map +1 -1
- package/dist/internal/use-item-order.mjs +42 -0
- package/dist/internal/use-item-order.mjs.map +1 -0
- package/dist/internal/use-latest.mjs +4 -8
- package/dist/internal/use-latest.mjs.map +1 -1
- package/dist/internal/use-merged-refs.mjs +19 -0
- package/dist/internal/use-merged-refs.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +84 -0
- package/dist/internal/use-name-warning.mjs.map +1 -0
- package/dist/internal/use-native-checked.mjs +4 -6
- package/dist/internal/use-native-checked.mjs.map +1 -1
- package/dist/internal/use-native-focusgroup.mjs +19 -0
- package/dist/internal/use-native-focusgroup.mjs.map +1 -0
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-overlay-close.mjs +63 -0
- package/dist/internal/use-overlay-close.mjs.map +1 -0
- package/dist/internal/{use-popover-root.mjs → use-overlay-root.mjs} +28 -39
- package/dist/internal/use-overlay-root.mjs.map +1 -0
- package/dist/internal/use-popover-popup.mjs +32 -78
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.d.mts +15 -0
- package/dist/internal/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/use-popover-trigger.mjs +13 -17
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/use-register-count.mjs +24 -0
- package/dist/internal/use-register-count.mjs.map +1 -0
- package/dist/internal/use-render.d.mts +2 -0
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-resolved-placement.mjs +38 -22
- package/dist/internal/use-resolved-placement.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs +5 -18
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/internal/use-superseded-rejection.mjs +47 -0
- package/dist/internal/use-superseded-rejection.mjs.map +1 -0
- package/dist/internal/validity.mjs +1 -13
- package/dist/internal/validity.mjs.map +1 -1
- package/dist/internal/value-set.mjs +41 -0
- package/dist/internal/value-set.mjs.map +1 -0
- package/dist/menu/index.d.mts +1 -1
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context-trigger.d.mts +2 -7
- package/dist/menu/menu-context-trigger.d.mts.map +1 -1
- package/dist/menu/menu-context-trigger.mjs +10 -187
- package/dist/menu/menu-context-trigger.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-dom.mjs +1 -2
- package/dist/menu/menu-dom.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +167 -0
- package/dist/menu/menu-gestures.mjs.map +1 -0
- package/dist/menu/menu-group.d.mts.map +1 -1
- package/dist/menu/menu-group.mjs +2 -1
- package/dist/menu/menu-group.mjs.map +1 -1
- package/dist/menu/menu-hover.mjs +0 -1
- package/dist/menu/menu-hover.mjs.map +1 -1
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +101 -0
- package/dist/menu/menu-outside.mjs.map +1 -0
- package/dist/menu/menu-point.mjs +85 -0
- package/dist/menu/menu-point.mjs.map +1 -0
- package/dist/menu/menu-popup.d.mts +6 -7
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +37 -248
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.d.mts +10 -0
- package/dist/menu/menu-root.d.mts.map +1 -1
- package/dist/menu/menu-root.mjs +10 -8
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +6 -6
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +4 -9
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +8 -6
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menu/use-menu-item.mjs +14 -16
- package/dist/menu/use-menu-item.mjs.map +1 -1
- package/dist/menu/use-menu-keyboard.mjs +88 -0
- package/dist/menu/use-menu-keyboard.mjs.map +1 -0
- package/dist/meter/meter-root.mjs +1 -1
- package/dist/number-field/index.d.mts +2 -1
- package/dist/number-field/index.d.mts.map +1 -1
- package/dist/number-field/index.mjs +2 -2
- package/dist/number-field/index.mjs.map +1 -1
- package/dist/number-field/number-field-arithmetic.mjs +30 -11
- package/dist/number-field/number-field-arithmetic.mjs.map +1 -1
- package/dist/number-field/number-field-context.d.mts +6 -1
- package/dist/number-field/number-field-context.d.mts.map +1 -0
- package/dist/number-field/number-field-context.mjs.map +1 -1
- package/dist/number-field/number-field-decrement.d.mts +1 -1
- package/dist/number-field/number-field-decrement.mjs +1 -1
- package/dist/number-field/number-field-decrement.mjs.map +1 -1
- package/dist/number-field/number-field-increment.d.mts +2 -22
- package/dist/number-field/number-field-increment.d.mts.map +1 -1
- package/dist/number-field/number-field-increment.mjs +2 -53
- package/dist/number-field/number-field-increment.mjs.map +1 -1
- package/dist/number-field/number-field-input.d.mts.map +1 -1
- package/dist/number-field/number-field-input.mjs +18 -22
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-label.d.mts.map +1 -1
- package/dist/number-field/number-field-label.mjs +3 -9
- package/dist/number-field/number-field-label.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts +2 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +81 -91
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/number-field/use-number-field-dev-warnings.mjs +28 -0
- package/dist/number-field/use-number-field-dev-warnings.mjs.map +1 -0
- package/dist/number-field/use-step-button.d.mts +24 -0
- package/dist/number-field/use-step-button.d.mts.map +1 -0
- package/dist/number-field/use-step-button.mjs +57 -3
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +28 -67
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-context.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +9 -6
- package/dist/popover/popover-popup.d.mts.map +1 -1
- package/dist/popover/popover-popup.mjs +13 -36
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +4 -3
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +4 -8
- package/dist/popover/popover-trigger.d.mts.map +1 -1
- package/dist/popover/popover-trigger.mjs +2 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/progress/progress-root.mjs +1 -1
- package/dist/radio-group/radio-group-context.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.d.mts +3 -4
- package/dist/radio-group/radio-group-item.d.mts.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +20 -25
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-label.mjs +1 -6
- package/dist/radio-group/radio-group-label.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +21 -40
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-dom.mjs +9 -18
- package/dist/select/select-dom.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-root.mjs +3 -2
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/slider/slider-arithmetic.mjs +74 -13
- package/dist/slider/slider-arithmetic.mjs.map +1 -1
- package/dist/slider/slider-context.mjs.map +1 -1
- package/dist/slider/slider-label.d.mts.map +1 -1
- package/dist/slider/slider-label.mjs +3 -9
- package/dist/slider/slider-label.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts +2 -2
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +36 -116
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/slider-thumb.d.mts.map +1 -1
- package/dist/slider/slider-thumb.mjs +8 -6
- package/dist/slider/slider-thumb.mjs.map +1 -1
- package/dist/slider/slider-value.d.mts.map +1 -1
- package/dist/slider/slider-value.mjs +2 -1
- package/dist/slider/slider-value.mjs.map +1 -1
- package/dist/slider/use-slider-dev-warnings.mjs +29 -0
- package/dist/slider/use-slider-dev-warnings.mjs.map +1 -0
- package/dist/slider/use-thumb-registry.mjs +51 -0
- package/dist/slider/use-thumb-registry.mjs.map +1 -0
- package/dist/switch/switch.d.mts +4 -5
- package/dist/switch/switch.d.mts.map +1 -1
- package/dist/switch/switch.mjs +15 -55
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-context.d.mts +2 -3
- package/dist/tabs/tabs-context.d.mts.map +1 -1
- package/dist/tabs/tabs-context.mjs.map +1 -1
- package/dist/tabs/tabs-list.d.mts.map +1 -1
- package/dist/tabs/tabs-list.mjs +9 -22
- package/dist/tabs/tabs-list.mjs.map +1 -1
- package/dist/tabs/tabs-panel.d.mts +3 -4
- package/dist/tabs/tabs-panel.d.mts.map +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts +4 -3
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +2 -1
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/tabs/tabs-tab.d.mts +3 -4
- package/dist/tabs/tabs-tab.d.mts.map +1 -1
- package/dist/tabs/tabs-tab.mjs.map +1 -1
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +2 -8
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-context.mjs.map +1 -1
- package/dist/toast/toast-hotkey.mjs +27 -0
- package/dist/toast/toast-hotkey.mjs.map +1 -0
- package/dist/toast/toast-queue.mjs +137 -0
- package/dist/toast/toast-queue.mjs.map +1 -0
- package/dist/toast/toast-timers.mjs +65 -0
- package/dist/toast/toast-timers.mjs.map +1 -0
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +30 -235
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/toast.mjs +1 -1
- package/dist/toast/toast.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +52 -0
- package/dist/toast/use-modal-portal-host.mjs.map +1 -0
- package/dist/toggle/toggle.d.mts +3 -4
- package/dist/toggle/toggle.d.mts.map +1 -1
- package/dist/toggle/toggle.mjs +7 -10
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-context.d.mts +2 -1
- package/dist/toggle-group/toggle-group-context.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-context.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-item.d.mts +5 -3
- package/dist/toggle-group/toggle-group-item.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-item.mjs +5 -7
- package/dist/toggle-group/toggle-group-item.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +29 -64
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/toolbar/toolbar-root.d.mts +2 -2
- package/dist/toolbar/toolbar-root.d.mts.map +1 -1
- package/dist/toolbar/toolbar-root.mjs +3 -4
- package/dist/toolbar/toolbar-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-context.d.mts +1 -1
- package/dist/tooltip/tooltip-context.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +6 -15
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +2 -2
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.d.mts +2 -1
- package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +3 -2
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/tooltip/use-tooltip-interaction.mjs +4 -3
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/accordion/accordion-context.d.mts +0 -5
- package/dist/accordion/accordion-context.d.mts.map +0 -1
- package/dist/internal/use-popover-root.mjs.map +0 -1
- /package/dist/internal/{use-popover-root.d.mts → use-overlay-root.d.mts} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLatest } from "./use-latest.mjs";
|
|
3
|
+
import { useCallback, useRef } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* A development check of the element a part mounted (a `render` element of the wrong kind, an
|
|
6
|
+
* element in the wrong place): `message(element)` returns the warning, or `null` when the element
|
|
7
|
+
* is fine. The first warning of an instance is logged with `console.error`; later ones are not.
|
|
8
|
+
*
|
|
9
|
+
* The result is a callback ref (merge it with the part's own) or a function to call from the
|
|
10
|
+
* part's own ref (`check?.(element)`). Ref callbacks run in the layout phase, when the element's
|
|
11
|
+
* siblings are in place. As a ref, `deps` re-run the check when they change (the callback is
|
|
12
|
+
* re-created, as a `useCallback` ref would be).
|
|
13
|
+
*
|
|
14
|
+
* Pass `message` as `isDev && ((element) => ...)` with the calling module's own `isDev`
|
|
15
|
+
* constant, so its texts fold away in a production build; there the hook is a no-op that
|
|
16
|
+
* returns `undefined`.
|
|
17
|
+
*/
|
|
18
|
+
const useElementCheck = process.env.NODE_ENV !== "production" ? useElementCheckDev : noop;
|
|
19
|
+
function noop() {}
|
|
20
|
+
function useElementCheckDev(message, deps = []) {
|
|
21
|
+
const warned = useRef(false);
|
|
22
|
+
const latest = useLatest(message);
|
|
23
|
+
const check = useCallback((element) => {
|
|
24
|
+
const current = latest.current;
|
|
25
|
+
if (!warned.current && current !== false) {
|
|
26
|
+
const text = current(element);
|
|
27
|
+
if (text !== null) {
|
|
28
|
+
warned.current = true;
|
|
29
|
+
console.error(text);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return () => {};
|
|
33
|
+
}, [latest, ...deps]);
|
|
34
|
+
return message === false ? void 0 : check;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { useElementCheck };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=use-element-check.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-element-check.mjs","names":[],"sources":["../../src/internal/use-element-check.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef } from \"react\";\nimport type { DependencyList } from \"react\";\nimport { useLatest } from \"./use-latest.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Runs the check on `element`; returns a no-op cleanup, so it is also a callback ref. */\nexport type ElementCheck<E extends Element> = (element: E) => () => void;\n\n/**\n * A development check of the element a part mounted (a `render` element of the wrong kind, an\n * element in the wrong place): `message(element)` returns the warning, or `null` when the element\n * is fine. The first warning of an instance is logged with `console.error`; later ones are not.\n *\n * The result is a callback ref (merge it with the part's own) or a function to call from the\n * part's own ref (`check?.(element)`). Ref callbacks run in the layout phase, when the element's\n * siblings are in place. As a ref, `deps` re-run the check when they change (the callback is\n * re-created, as a `useCallback` ref would be).\n *\n * Pass `message` as `isDev && ((element) => ...)` with the calling module's own `isDev`\n * constant, so its texts fold away in a production build; there the hook is a no-op that\n * returns `undefined`.\n */\nexport const useElementCheck: <E extends Element = HTMLElement>(\n message: false | ((element: E) => string | null),\n deps?: DependencyList,\n) => ElementCheck<E> | undefined = isDev ? useElementCheckDev : noop;\n\nfunction noop(): undefined {\n return undefined;\n}\n\nfunction useElementCheckDev<E extends Element = HTMLElement>(\n message: false | ((element: E) => string | null),\n deps: DependencyList = [],\n): ElementCheck<E> | undefined {\n const warned = useRef(false);\n const latest = useLatest(message);\n const check = useCallback(\n (element: E) => {\n const current = latest.current;\n if (!warned.current && current !== false) {\n const text = current(element);\n if (text !== null) {\n warned.current = true;\n console.error(text);\n }\n }\n // A cleanup, so a merged ref is never called back with `null`.\n return () => {};\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- `deps` decide when to re-check\n [latest, ...deps],\n );\n return message === false ? undefined : check;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,MAAa,kBAnBC,QAAQ,IAAI,aAAa,eAsBI,qBAAqB;AAEhE,SAAS,OAAkB,CAE3B;AAEA,SAAS,mBACP,SACA,OAAuB,CAAC,GACK;CAC7B,MAAM,SAAS,OAAO,KAAK;CAC3B,MAAM,SAAS,UAAU,OAAO;CAChC,MAAM,QAAQ,aACX,YAAe;EACd,MAAM,UAAU,OAAO;EACvB,IAAI,CAAC,OAAO,WAAW,YAAY,OAAO;GACxC,MAAM,OAAO,QAAQ,OAAO;GAC5B,IAAI,SAAS,MAAM;IACjB,OAAO,UAAU;IACjB,QAAQ,MAAM,IAAI;GACpB;EACF;EAEA,aAAa,CAAC;CAChB,GAEA,CAAC,QAAQ,GAAG,IAAI,CAClB;CACA,OAAO,YAAY,QAAQ,KAAA,IAAY;AACzC"}
|
|
@@ -10,7 +10,7 @@ function ends(animation) {
|
|
|
10
10
|
* The animations running in an element's subtree right before it closes (the synchronous
|
|
11
11
|
* `beforetoggle` of the hide, Toast's `data-ending` write): the baseline that `exitAnimations`
|
|
12
12
|
* excludes, so a finite animation already running inside (a progress bar) does not hold the exit
|
|
13
|
-
* (Toast 10.2
|
|
13
|
+
* (Toast 10.2). Empty where `getAnimations` is absent (jsdom).
|
|
14
14
|
*/
|
|
15
15
|
function animationBaseline(element) {
|
|
16
16
|
if (!element.isConnected || typeof element.getAnimations !== "function") return /* @__PURE__ */ new Set();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-exit-animation.mjs","names":[],"sources":["../../src/internal/use-exit-animation.ts"],"sourcesContent":["\"use client\";\nimport { useRef, useState } from \"react\";\n\n/** An animation that ends: infinite ones (a spinner) would hold the content forever. */\nfunction ends(animation: Animation): boolean {\n const end = animation.effect?.getComputedTiming().endTime;\n return typeof end === \"number\" && Number.isFinite(end);\n}\n\n/**\n * The animations running in an element's subtree right before it closes (the synchronous\n * `beforetoggle` of the hide, Toast's `data-ending` write): the baseline that `exitAnimations`\n * excludes, so a finite animation already running inside (a progress bar) does not hold the exit\n * (Toast 10.2
|
|
1
|
+
{"version":3,"file":"use-exit-animation.mjs","names":[],"sources":["../../src/internal/use-exit-animation.ts"],"sourcesContent":["\"use client\";\nimport { useRef, useState } from \"react\";\n\n/** An animation that ends: infinite ones (a spinner) would hold the content forever. */\nfunction ends(animation: Animation): boolean {\n const end = animation.effect?.getComputedTiming().endTime;\n return typeof end === \"number\" && Number.isFinite(end);\n}\n\n/**\n * The animations running in an element's subtree right before it closes (the synchronous\n * `beforetoggle` of the hide, Toast's `data-ending` write): the baseline that `exitAnimations`\n * excludes, so a finite animation already running inside (a progress bar) does not hold the exit\n * (Toast 10.2). Empty where `getAnimations` is absent (jsdom).\n */\nexport function animationBaseline(element: Element): ReadonlySet<Animation> {\n if (!element.isConnected || typeof element.getAnimations !== \"function\") return new Set();\n return new Set(element.getAnimations({ subtree: true }));\n}\n\n/**\n * The running exit animations of a top-layer element that has just been hidden, read after a\n * style flush so that `transition-behavior: allow-discrete` exits exist, minus the `baseline`\n * of animations that were already running before the close. Empty where the engine does not\n * animate the exit (Firefox) or there is no CSS exit.\n */\nexport function exitAnimations(element: Element, baseline?: ReadonlySet<Animation>): Animation[] {\n if (!element.isConnected || typeof element.getAnimations !== \"function\") return [];\n void getComputedStyle(element).opacity;\n return element\n .getAnimations({ subtree: true })\n .filter((animation) => ends(animation) && !(baseline?.has(animation) ?? false));\n}\n\nexport interface ExitAnimation {\n /** Keep the content mounted (design/components/popover.md 4.4). */\n readonly held: boolean;\n /** Set `held` now (urgent, library-internal) and clear it when `animations` settle. */\n readonly holdUntil: (animations: readonly Animation[]) => void;\n /** Clear `held` now (a normal update, never a transition), cancelling any wait in progress. */\n readonly release: () => void;\n /** Set `held` during render (the \"previous value in state\" pattern). */\n readonly holdDuringRender: () => void;\n /** Whether a `holdUntil` wait is still running. Handlers and effects only. */\n readonly waiting: () => boolean;\n /**\n * Record the animations already running in `element`'s subtree. Call from the synchronous\n * `beforetoggle` of a close, before the hide starts the exit.\n */\n readonly recordBaseline: (element: Element) => void;\n /** `exitAnimations(element)` minus the recorded baseline, which it consumes. */\n readonly exitAnimations: (element: Element) => Animation[];\n}\n\n/**\n * The deferred unmount of a top-layer popup's content while its hide animates. `held` is cleared\n * with a normal (urgent) update, never in a transition: the popup is already hidden, nothing\n * visible changes, and only transition commits start a document view transition, so a dismissal\n * runs one (its notification commit) instead of two (design 4.4).\n */\nexport function useExitAnimation(): ExitAnimation {\n const [held, setHeld] = useState(false);\n // The generation of the wait in progress, or null; a newer wait supersedes an older one.\n const wait = useRef<number | null>(null);\n const generation = useRef(0);\n // The animations running right before the latest close, consumed by `exitAnimations`.\n const baseline = useRef<ReadonlySet<Animation> | null>(null);\n\n const holdUntil = (animations: readonly Animation[]): void => {\n const current = ++generation.current;\n wait.current = current;\n setHeld(true);\n void Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {\n if (generation.current !== current) return;\n wait.current = null;\n setHeld(false);\n });\n };\n\n const release = (): void => {\n generation.current++;\n wait.current = null;\n setHeld(false);\n };\n\n return {\n held,\n holdUntil,\n release,\n holdDuringRender: () => setHeld(true),\n waiting: () => wait.current !== null,\n recordBaseline: (element) => {\n baseline.current = animationBaseline(element);\n },\n exitAnimations: (element) => {\n const recorded = baseline.current ?? undefined;\n baseline.current = null;\n return exitAnimations(element, recorded);\n },\n };\n}\n"],"mappings":";;;;AAIA,SAAS,KAAK,WAA+B;CAC3C,MAAM,MAAM,UAAU,QAAQ,kBAAkB,CAAC,CAAC;CAClD,OAAO,OAAO,QAAQ,YAAY,OAAO,SAAS,GAAG;AACvD;;;;;;;AAQA,SAAgB,kBAAkB,SAA0C;CAC1E,IAAI,CAAC,QAAQ,eAAe,OAAO,QAAQ,kBAAkB,YAAY,uBAAO,IAAI,IAAI;CACxF,OAAO,IAAI,IAAI,QAAQ,cAAc,EAAE,SAAS,KAAK,CAAC,CAAC;AACzD;;;;;;;AAQA,SAAgB,eAAe,SAAkB,UAAgD;CAC/F,IAAI,CAAC,QAAQ,eAAe,OAAO,QAAQ,kBAAkB,YAAY,OAAO,CAAC;CACjF,iBAAsB,OAAO,CAAC,CAAC;CAC/B,OAAO,QACJ,cAAc,EAAE,SAAS,KAAK,CAAC,CAAC,CAChC,QAAQ,cAAc,KAAK,SAAS,KAAK,EAAE,UAAU,IAAI,SAAS,KAAK,MAAM;AAClF;;;;;;;AA4BA,SAAgB,mBAAkC;CAChD,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CAEtC,MAAM,OAAO,OAAsB,IAAI;CACvC,MAAM,aAAa,OAAO,CAAC;CAE3B,MAAM,WAAW,OAAsC,IAAI;CAE3D,MAAM,aAAa,eAA2C;EAC5D,MAAM,UAAU,EAAE,WAAW;EAC7B,KAAK,UAAU;EACf,QAAQ,IAAI;EACZ,QAAa,WAAW,WAAW,KAAK,cAAc,UAAU,QAAQ,CAAC,CAAC,CAAC,WAAW;GACpF,IAAI,WAAW,YAAY,SAAS;GACpC,KAAK,UAAU;GACf,QAAQ,KAAK;EACf,CAAC;CACH;CAEA,MAAM,gBAAsB;EAC1B,WAAW;EACX,KAAK,UAAU;EACf,QAAQ,KAAK;CACf;CAEA,OAAO;EACL;EACA;EACA;EACA,wBAAwB,QAAQ,IAAI;EACpC,eAAe,KAAK,YAAY;EAChC,iBAAiB,YAAY;GAC3B,SAAS,UAAU,kBAAkB,OAAO;EAC9C;EACA,iBAAiB,YAAY;GAC3B,MAAM,WAAW,SAAS,WAAW,KAAA;GACrC,SAAS,UAAU;GACnB,OAAO,eAAe,SAAS,QAAQ;EACzC;CACF;AACF"}
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { dataAttr } from "./data-attr.mjs";
|
|
3
3
|
import { useDevWarning } from "./use-dev-warning.mjs";
|
|
4
|
-
import { mergeRefs } from "./merge-props.mjs";
|
|
5
4
|
import { FieldContext } from "./field-context.mjs";
|
|
6
|
-
import { use, useCallback, useLayoutEffect,
|
|
5
|
+
import { use, useCallback, useLayoutEffect, useRef } from "react";
|
|
7
6
|
//#region src/internal/use-field-control.ts
|
|
7
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
8
|
+
/**
|
|
9
|
+
* "Own or the Field's" (design/components/field-form.md 7.1): `name` falls back to the Field's,
|
|
10
|
+
* `disabled` and `required` are either's. Outside a Field (`field === null`) the own props.
|
|
11
|
+
*/
|
|
12
|
+
function resolveFieldDefaults(field, own) {
|
|
13
|
+
if (field === null) return {
|
|
14
|
+
name: own.name,
|
|
15
|
+
disabled: own.disabled,
|
|
16
|
+
required: own.required
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
name: own.name ?? field.name,
|
|
20
|
+
disabled: own.disabled || field.disabled,
|
|
21
|
+
required: own.required || field.required
|
|
22
|
+
};
|
|
23
|
+
}
|
|
8
24
|
/**
|
|
9
25
|
* The owned props of a labelable native control (`<input>`, `<select>`) inside a Field: the
|
|
10
26
|
* ARIA wiring plus `name` and `required` ("own or the Field's"). Empty outside a Field, so the
|
|
@@ -18,10 +34,6 @@ function fieldInputProps(field) {
|
|
|
18
34
|
required: field.required
|
|
19
35
|
};
|
|
20
36
|
}
|
|
21
|
-
/** `mergeRefs` with a stable identity while both refs keep theirs. */
|
|
22
|
-
function useMergedRef(a, b) {
|
|
23
|
-
return useMemo(() => b === void 0 ? a : a === void 0 ? b : mergeRefs(a, b), [a, b]);
|
|
24
|
-
}
|
|
25
37
|
/**
|
|
26
38
|
* The contract between a Field and its control (design/components/field-form.md 7.1), called by
|
|
27
39
|
* `Field.Control` and by the owner part of every FUNSTACK form control. Outside a `Field.Root` it
|
|
@@ -51,13 +63,14 @@ function useFieldControl(options) {
|
|
|
51
63
|
disabled,
|
|
52
64
|
validityElement
|
|
53
65
|
]);
|
|
54
|
-
useDevWarning(field !== null && id !== void 0, `${component}: the \`id\` prop is ignored inside a Field.Root; the Field owns the control's id so that Field.Label can point at it.`);
|
|
55
|
-
useDevWarning(field !== null && name !== void 0 && field.name !== void 0 && name !== field.name, `${component}: its \`name\` ("${name}") differs from the Field.Root's ("${field?.name}"). The Field reads server errors and \`validate\`'s value by the Field's name.`);
|
|
66
|
+
useDevWarning(field !== null && id !== void 0, isDev && `${component}: the \`id\` prop is ignored inside a Field.Root; the Field owns the control's id so that Field.Label can point at it.`);
|
|
67
|
+
useDevWarning(field !== null && name !== void 0 && field.name !== void 0 && name !== field.name, isDev && `${component}: its \`name\` ("${name}") differs from the Field.Root's ("${field?.name}"). The Field reads server errors and \`validate\`'s value by the Field's name.`);
|
|
56
68
|
if (field === null) return {
|
|
57
69
|
inField: false,
|
|
58
70
|
ref: void 0,
|
|
59
71
|
id,
|
|
60
72
|
name,
|
|
73
|
+
fieldName: void 0,
|
|
61
74
|
disabled,
|
|
62
75
|
required,
|
|
63
76
|
attributes: {},
|
|
@@ -75,9 +88,12 @@ function useFieldControl(options) {
|
|
|
75
88
|
inField: true,
|
|
76
89
|
ref,
|
|
77
90
|
id: labelable ? ids.control : void 0,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
...resolveFieldDefaults(field, {
|
|
92
|
+
name,
|
|
93
|
+
disabled,
|
|
94
|
+
required
|
|
95
|
+
}),
|
|
96
|
+
fieldName: field.name,
|
|
81
97
|
attributes,
|
|
82
98
|
state
|
|
83
99
|
};
|
|
@@ -104,6 +120,6 @@ function useFieldValueChange(value, takeEdit) {
|
|
|
104
120
|
});
|
|
105
121
|
}
|
|
106
122
|
//#endregion
|
|
107
|
-
export { fieldInputProps, useFieldControl, useFieldValueChange
|
|
123
|
+
export { fieldInputProps, resolveFieldDefaults, useFieldControl, useFieldValueChange };
|
|
108
124
|
|
|
109
125
|
//# sourceMappingURL=use-field-control.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-field-control.mjs","names":[],"sources":["../../src/internal/use-field-control.ts"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect,
|
|
1
|
+
{"version":3,"file":"use-field-control.mjs","names":[],"sources":["../../src/internal/use-field-control.ts"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useRef } from \"react\";\nimport type { RefCallback } from \"react\";\nimport { dataAttr } from \"./data-attr.js\";\nimport { FieldContext } from \"./field-context.js\";\nimport type { FieldContextValue, FieldState } from \"./field-context.js\";\nimport { useDevWarning } from \"./use-dev-warning.js\";\nimport type { ValidatableElement } from \"./validity.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface UseFieldControlOptions {\n /** `<label for>` can target the element (input, select, textarea). Groups pass `false`. */\n readonly labelable: boolean;\n /** The control's own props, so \"own or the Field's\" can be computed. */\n readonly name?: string | undefined;\n readonly disabled?: boolean | undefined;\n readonly required?: boolean | undefined;\n /** The consumer's own `id` prop: ignored inside a Field (the Field owns it), with a warning. */\n readonly id?: string | undefined;\n /** Dev warning tag. */\n readonly component: string;\n /**\n * The element whose validity is real when it is not the registered one (NumberField's hidden\n * number input; field-form.md `validityElement`). Keep its identity stable.\n */\n readonly validityElement?: (() => ValidatableElement | null) | undefined;\n}\n\n/** The ARIA and state attributes a part spreads into its owned layer. */\nexport interface FieldControlAttributes {\n /** Labelable controls only: the id `Field.Label`'s `for` points at. */\n id?: string;\n \"aria-labelledby\"?: string;\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: \"true\" | \"false\";\n \"data-invalid\"?: \"\" | undefined;\n}\n\nexport interface FieldControlBinding {\n /** The control is inside a `Field.Root`. */\n readonly inField: boolean;\n /** Merge into the part's library ref: registers the element with the Field. `undefined` outside a Field. */\n readonly ref: RefCallback<HTMLElement> | undefined;\n /** The control id the Field's Label points at (labelable controls inside a Field), else the consumer's. */\n readonly id: string | undefined;\n /** Own `name` ?? the Field's. */\n readonly name: string | undefined;\n /** The Field's own `name` (`undefined` outside a Field or when it has none). */\n readonly fieldName: string | undefined;\n /** Own `disabled` || the Field's. */\n readonly disabled: boolean;\n /** Own `required` || the Field's. */\n readonly required: boolean;\n /**\n * Owned attributes: `id` (labelable controls), `aria-invalid`, `data-invalid`,\n * `aria-labelledby` (groups) and `aria-describedby` (both token-merged by the owned layer, the\n * consumer's tokens first). Empty outside a Field, so nothing is owned there.\n */\n readonly attributes: FieldControlAttributes;\n /** The Field's state, `undefined` outside a Field. */\n readonly state: FieldState | undefined;\n}\n\n/**\n * \"Own or the Field's\" (design/components/field-form.md 7.1): `name` falls back to the Field's,\n * `disabled` and `required` are either's. Outside a Field (`field === null`) the own props.\n */\nexport function resolveFieldDefaults(\n field: Pick<FieldContextValue, \"name\" | \"disabled\" | \"required\"> | null,\n own: {\n readonly name: string | undefined;\n readonly disabled: boolean;\n readonly required: boolean;\n },\n): { name: string | undefined; disabled: boolean; required: boolean } {\n if (field === null) return { name: own.name, disabled: own.disabled, required: own.required };\n return {\n name: own.name ?? field.name,\n disabled: own.disabled || field.disabled,\n required: own.required || field.required,\n };\n}\n\n/**\n * The owned props of a labelable native control (`<input>`, `<select>`) inside a Field: the\n * ARIA wiring plus `name` and `required` (\"own or the Field's\"). Empty outside a Field, so the\n * consumer's own `id` / `name` / `required` keep passing through untouched there.\n */\nexport function fieldInputProps(field: FieldControlBinding): FieldControlAttributes & {\n name?: string | undefined;\n required?: boolean;\n} {\n if (!field.inField) return {};\n return { ...field.attributes, name: field.name, required: field.required };\n}\n\n/**\n * The contract between a Field and its control (design/components/field-form.md 7.1), called by\n * `Field.Control` and by the owner part of every FUNSTACK form control. Outside a `Field.Root` it\n * returns the control's own props and nothing to merge.\n *\n * Inside a Field: registers the element from the returned ref (the Field attaches its listeners\n * and reads validity there; a group's `<fieldset>` makes `Field.Label` drop `for`), resolves \"own\n * or the Field's\" for `name` / `disabled` / `required`, and returns the owned ARIA wiring.\n */\nexport function useFieldControl(options: UseFieldControlOptions): FieldControlBinding {\n const {\n labelable,\n name,\n disabled = false,\n required = false,\n id,\n component,\n validityElement,\n } = options;\n const field = use(FieldContext);\n const registerControl = field?.registerControl;\n\n const ref = useCallback(\n (element: HTMLElement) => {\n if (registerControl === undefined) return () => {};\n return registerControl({ element, labelable, required, disabled, validityElement });\n },\n [registerControl, labelable, required, disabled, validityElement],\n );\n\n useDevWarning(\n field !== null && id !== undefined,\n isDev &&\n `${component}: the \\`id\\` prop is ignored inside a Field.Root; the Field owns the control's ` +\n \"id so that Field.Label can point at it.\",\n );\n useDevWarning(\n field !== null && name !== undefined && field.name !== undefined && name !== field.name,\n isDev &&\n `${component}: its \\`name\\` (\"${name}\") differs from the Field.Root's (\"${field?.name}\"). ` +\n \"The Field reads server errors and `validate`'s value by the Field's name.\",\n );\n\n if (field === null) {\n return {\n inField: false,\n ref: undefined,\n id,\n name,\n fieldName: undefined,\n disabled,\n required,\n attributes: {},\n state: undefined,\n };\n }\n\n const { ids, state } = field;\n const attributes: FieldControlAttributes = {\n \"aria-describedby\": state.invalid ? `${ids.description} ${ids.error}` : ids.description,\n \"aria-invalid\": state.invalid ? \"true\" : \"false\",\n \"data-invalid\": dataAttr(state.invalid),\n };\n if (labelable) attributes.id = ids.control;\n else attributes[\"aria-labelledby\"] = ids.label;\n\n return {\n inField: true,\n ref,\n id: labelable ? ids.control : undefined,\n ...resolveFieldDefaults(field, { name, disabled, required }),\n fieldName: field.name,\n attributes,\n state,\n };\n}\n\n/**\n * Tells the enclosing Field (if any) that the control's value changed, after the commit that\n * wrote it to the DOM (design/components/field-form.md 2.1: `validate` and the mirror follow the\n * value). Needed where the DOM changes without an `input` / `change` event the Field hears: a\n * Combobox selection (React writes the hidden input), a CheckboxGroup's derived `required`, a\n * Parent checking Items, a rejected action rolling the value back. Nothing at mount.\n *\n * `takeEdit` is read when the value changed: `true` when the user made this change (a shown\n * server error is dismissed, like an `input` event would). Native controls whose own events\n * already dismiss pass nothing.\n */\nexport function useFieldValueChange(value: unknown, takeEdit?: () => boolean): void {\n const notifyChange = use(FieldContext)?.notifyChange;\n const previous = useRef(value);\n // No deps: compares with the last committed value after every commit of the caller.\n useLayoutEffect(() => {\n if (Object.is(previous.current, value)) return;\n previous.current = value;\n const edit = takeEdit?.() ?? false;\n notifyChange?.(edit);\n });\n}\n"],"mappings":";;;;;;AASA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;AA2DvC,SAAgB,qBACd,OACA,KAKoE;CACpE,IAAI,UAAU,MAAM,OAAO;EAAE,MAAM,IAAI;EAAM,UAAU,IAAI;EAAU,UAAU,IAAI;CAAS;CAC5F,OAAO;EACL,MAAM,IAAI,QAAQ,MAAM;EACxB,UAAU,IAAI,YAAY,MAAM;EAChC,UAAU,IAAI,YAAY,MAAM;CAClC;AACF;;;;;;AAOA,SAAgB,gBAAgB,OAG9B;CACA,IAAI,CAAC,MAAM,SAAS,OAAO,CAAC;CAC5B,OAAO;EAAE,GAAG,MAAM;EAAY,MAAM,MAAM;EAAM,UAAU,MAAM;CAAS;AAC3E;;;;;;;;;;AAWA,SAAgB,gBAAgB,SAAsD;CACpF,MAAM,EACJ,WACA,MACA,WAAW,OACX,WAAW,OACX,IACA,WACA,oBACE;CACJ,MAAM,QAAQ,IAAI,YAAY;CAC9B,MAAM,kBAAkB,OAAO;CAE/B,MAAM,MAAM,aACT,YAAyB;EACxB,IAAI,oBAAoB,KAAA,GAAW,aAAa,CAAC;EACjD,OAAO,gBAAgB;GAAE;GAAS;GAAW;GAAU;GAAU;EAAgB,CAAC;CACpF,GACA;EAAC;EAAiB;EAAW;EAAU;EAAU;CAAe,CAClE;CAEA,cACE,UAAU,QAAQ,OAAO,KAAA,GACzB,SACE,GAAG,UAAU,uHAEjB;CACA,cACE,UAAU,QAAQ,SAAS,KAAA,KAAa,MAAM,SAAS,KAAA,KAAa,SAAS,MAAM,MACnF,SACE,GAAG,UAAU,mBAAmB,KAAK,qCAAqC,OAAO,KAAK,gFAE1F;CAEA,IAAI,UAAU,MACZ,OAAO;EACL,SAAS;EACT,KAAK,KAAA;EACL;EACA;EACA,WAAW,KAAA;EACX;EACA;EACA,YAAY,CAAC;EACb,OAAO,KAAA;CACT;CAGF,MAAM,EAAE,KAAK,UAAU;CACvB,MAAM,aAAqC;EACzC,oBAAoB,MAAM,UAAU,GAAG,IAAI,YAAY,GAAG,IAAI,UAAU,IAAI;EAC5E,gBAAgB,MAAM,UAAU,SAAS;EACzC,gBAAgB,SAAS,MAAM,OAAO;CACxC;CACA,IAAI,WAAW,WAAW,KAAK,IAAI;MAC9B,WAAW,qBAAqB,IAAI;CAEzC,OAAO;EACL,SAAS;EACT;EACA,IAAI,YAAY,IAAI,UAAU,KAAA;EAC9B,GAAG,qBAAqB,OAAO;GAAE;GAAM;GAAU;EAAS,CAAC;EAC3D,WAAW,MAAM;EACjB;EACA;CACF;AACF;;;;;;;;;;;;AAaA,SAAgB,oBAAoB,OAAgB,UAAgC;CAClF,MAAM,eAAe,IAAI,YAAY,CAAC,EAAE;CACxC,MAAM,WAAW,OAAO,KAAK;CAE7B,sBAAsB;EACpB,IAAI,OAAO,GAAG,SAAS,SAAS,KAAK,GAAG;EACxC,SAAS,UAAU;EACnB,MAAM,OAAO,WAAW,KAAK;EAC7B,eAAe,IAAI;CACrB,CAAC;AACH"}
|
|
@@ -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"}
|