@funstack/ui 0.1.0-alpha.10 → 0.1.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordion/accordion-context.mjs.map +1 -1
- package/dist/accordion/accordion-item.d.mts +3 -4
- package/dist/accordion/accordion-item.d.mts.map +1 -1
- package/dist/accordion/accordion-item.mjs +10 -4
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-panel.d.mts +3 -4
- package/dist/accordion/accordion-panel.d.mts.map +1 -1
- package/dist/accordion/accordion-panel.mjs +2 -1
- package/dist/accordion/accordion-panel.mjs.map +1 -1
- package/dist/accordion/accordion-root.d.mts +3 -3
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +8 -19
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts +3 -4
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +5 -3
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/button/button.d.mts +4 -2
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +3 -2
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.d.mts +4 -5
- package/dist/checkbox/checkbox.d.mts.map +1 -1
- package/dist/checkbox/checkbox.mjs +16 -59
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-context.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-item.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +21 -27
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-label.mjs +1 -6
- package/dist/checkbox-group/checkbox-group-label.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-parent.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +12 -10
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +74 -101
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +5 -6
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-group.d.mts.map +1 -1
- package/dist/combobox/combobox-group.mjs +2 -1
- package/dist/combobox/combobox-group.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +14 -7
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts.map +1 -1
- package/dist/combobox/combobox-list.mjs +6 -10
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +2 -1
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs +9 -25
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +11 -10
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +37 -109
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +6 -25
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/index.d.mts +2 -2
- package/dist/combobox/index.mjs +3 -3
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/combobox/use-combobox-form.mjs +56 -0
- package/dist/combobox/use-combobox-form.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +62 -0
- package/dist/combobox/use-option-registry.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +29 -62
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +5 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +3 -4
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +37 -98
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +30 -118
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +13 -16
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/field/field-control.mjs +6 -13
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts.map +1 -1
- package/dist/field/field-description.mjs +1 -2
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts.map +1 -1
- package/dist/field/field-error.mjs +1 -2
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +3 -11
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +21 -41
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.mjs +1 -1
- package/dist/field/use-server-error-visibility.mjs +44 -0
- package/dist/field/use-server-error-visibility.mjs.map +1 -0
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +6 -7
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +1 -1
- package/dist/form/form-submit.mjs +4 -10
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/internal/anchor-position.mjs +1 -59
- package/dist/internal/anchor-position.mjs.map +1 -1
- package/dist/internal/announce.mjs.map +1 -1
- package/dist/internal/arrow-keys.mjs +21 -0
- package/dist/internal/arrow-keys.mjs.map +1 -0
- package/dist/internal/decimal.mjs +7 -1
- package/dist/internal/decimal.mjs.map +1 -1
- package/dist/internal/dom-order.mjs +17 -0
- package/dist/internal/dom-order.mjs.map +1 -0
- package/dist/internal/field-context.d.mts.map +1 -1
- package/dist/internal/field-context.mjs +11 -1
- package/dist/internal/field-context.mjs.map +1 -1
- package/dist/internal/focus-first-invalid.mjs +1 -1
- package/dist/internal/focus-first-invalid.mjs.map +1 -1
- package/dist/internal/group-member.mjs +37 -0
- package/dist/internal/group-member.mjs.map +1 -0
- package/dist/internal/overlay-popup.mjs +103 -0
- package/dist/internal/overlay-popup.mjs.map +1 -0
- package/dist/internal/popover-open.mjs +18 -0
- package/dist/internal/popover-open.mjs.map +1 -0
- package/dist/internal/render-element.d.mts +2 -0
- package/dist/internal/render-element.mjs +20 -2
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/shipped-styles.mjs +14 -0
- package/dist/internal/shipped-styles.mjs.map +1 -0
- package/dist/internal/sync-presence.mjs +5 -1
- package/dist/internal/sync-presence.mjs.map +1 -1
- package/dist/internal/toolbar-context.mjs.map +1 -1
- package/dist/internal/tooltip-warm.mjs +1 -1
- package/dist/internal/tooltip-warm.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +1 -1
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/types.d.mts +8 -6
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +5 -23
- package/dist/internal/use-action-trigger.mjs.map +1 -1
- package/dist/internal/use-checkable-input.mjs +79 -0
- package/dist/internal/use-checkable-input.mjs.map +1 -0
- package/dist/internal/use-controllable-action.mjs +16 -24
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- package/dist/internal/use-dev-warning.mjs +8 -4
- package/dist/internal/use-dev-warning.mjs.map +1 -1
- package/dist/internal/use-element-check.mjs +39 -0
- package/dist/internal/use-element-check.mjs.map +1 -0
- package/dist/internal/use-exit-animation.mjs +1 -1
- package/dist/internal/use-exit-animation.mjs.map +1 -1
- package/dist/internal/use-field-control.mjs +28 -12
- package/dist/internal/use-field-control.mjs.map +1 -1
- package/dist/internal/use-fieldset-group.mjs +46 -0
- package/dist/internal/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/use-form-reset.mjs +1 -5
- package/dist/internal/use-form-reset.mjs.map +1 -1
- package/dist/internal/use-item-order.mjs +42 -0
- package/dist/internal/use-item-order.mjs.map +1 -0
- package/dist/internal/use-latest.mjs +4 -8
- package/dist/internal/use-latest.mjs.map +1 -1
- package/dist/internal/use-merged-refs.mjs +19 -0
- package/dist/internal/use-merged-refs.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +84 -0
- package/dist/internal/use-name-warning.mjs.map +1 -0
- package/dist/internal/use-native-checked.mjs +4 -6
- package/dist/internal/use-native-checked.mjs.map +1 -1
- package/dist/internal/use-native-focusgroup.mjs +19 -0
- package/dist/internal/use-native-focusgroup.mjs.map +1 -0
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-overlay-close.mjs +63 -0
- package/dist/internal/use-overlay-close.mjs.map +1 -0
- package/dist/internal/{use-popover-root.mjs → use-overlay-root.mjs} +28 -39
- package/dist/internal/use-overlay-root.mjs.map +1 -0
- package/dist/internal/use-popover-popup.mjs +32 -78
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.d.mts +15 -0
- package/dist/internal/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/use-popover-trigger.mjs +13 -17
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/use-register-count.mjs +24 -0
- package/dist/internal/use-register-count.mjs.map +1 -0
- package/dist/internal/use-render.d.mts +2 -0
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-resolved-placement.mjs +38 -22
- package/dist/internal/use-resolved-placement.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs +5 -18
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/internal/use-superseded-rejection.mjs +47 -0
- package/dist/internal/use-superseded-rejection.mjs.map +1 -0
- package/dist/internal/validity.mjs +1 -13
- package/dist/internal/validity.mjs.map +1 -1
- package/dist/internal/value-set.mjs +41 -0
- package/dist/internal/value-set.mjs.map +1 -0
- package/dist/menu/index.d.mts +1 -1
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context-trigger.d.mts +2 -7
- package/dist/menu/menu-context-trigger.d.mts.map +1 -1
- package/dist/menu/menu-context-trigger.mjs +10 -187
- package/dist/menu/menu-context-trigger.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-dom.mjs +1 -2
- package/dist/menu/menu-dom.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +167 -0
- package/dist/menu/menu-gestures.mjs.map +1 -0
- package/dist/menu/menu-group.d.mts.map +1 -1
- package/dist/menu/menu-group.mjs +2 -1
- package/dist/menu/menu-group.mjs.map +1 -1
- package/dist/menu/menu-hover.mjs +0 -1
- package/dist/menu/menu-hover.mjs.map +1 -1
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +101 -0
- package/dist/menu/menu-outside.mjs.map +1 -0
- package/dist/menu/menu-point.mjs +85 -0
- package/dist/menu/menu-point.mjs.map +1 -0
- package/dist/menu/menu-popup.d.mts +6 -7
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +37 -248
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.d.mts +10 -0
- package/dist/menu/menu-root.d.mts.map +1 -1
- package/dist/menu/menu-root.mjs +10 -8
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +6 -6
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +4 -9
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +8 -6
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menu/use-menu-item.mjs +14 -16
- package/dist/menu/use-menu-item.mjs.map +1 -1
- package/dist/menu/use-menu-keyboard.mjs +88 -0
- package/dist/menu/use-menu-keyboard.mjs.map +1 -0
- package/dist/meter/meter-root.mjs +1 -1
- package/dist/number-field/index.d.mts +2 -1
- package/dist/number-field/index.d.mts.map +1 -1
- package/dist/number-field/index.mjs +2 -2
- package/dist/number-field/index.mjs.map +1 -1
- package/dist/number-field/number-field-arithmetic.mjs +30 -11
- package/dist/number-field/number-field-arithmetic.mjs.map +1 -1
- package/dist/number-field/number-field-context.d.mts +6 -1
- package/dist/number-field/number-field-context.d.mts.map +1 -0
- package/dist/number-field/number-field-context.mjs.map +1 -1
- package/dist/number-field/number-field-decrement.d.mts +1 -1
- package/dist/number-field/number-field-decrement.mjs +1 -1
- package/dist/number-field/number-field-decrement.mjs.map +1 -1
- package/dist/number-field/number-field-increment.d.mts +2 -22
- package/dist/number-field/number-field-increment.d.mts.map +1 -1
- package/dist/number-field/number-field-increment.mjs +2 -53
- package/dist/number-field/number-field-increment.mjs.map +1 -1
- package/dist/number-field/number-field-input.d.mts.map +1 -1
- package/dist/number-field/number-field-input.mjs +18 -22
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-label.d.mts.map +1 -1
- package/dist/number-field/number-field-label.mjs +3 -9
- package/dist/number-field/number-field-label.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts +2 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +81 -91
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/number-field/use-number-field-dev-warnings.mjs +28 -0
- package/dist/number-field/use-number-field-dev-warnings.mjs.map +1 -0
- package/dist/number-field/use-step-button.d.mts +24 -0
- package/dist/number-field/use-step-button.d.mts.map +1 -0
- package/dist/number-field/use-step-button.mjs +57 -3
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +28 -67
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-context.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +9 -6
- package/dist/popover/popover-popup.d.mts.map +1 -1
- package/dist/popover/popover-popup.mjs +13 -36
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +4 -3
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +4 -8
- package/dist/popover/popover-trigger.d.mts.map +1 -1
- package/dist/popover/popover-trigger.mjs +2 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/progress/progress-root.mjs +1 -1
- package/dist/radio-group/radio-group-context.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.d.mts +3 -4
- package/dist/radio-group/radio-group-item.d.mts.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +20 -25
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-label.mjs +1 -6
- package/dist/radio-group/radio-group-label.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +21 -40
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-dom.mjs +9 -18
- package/dist/select/select-dom.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-root.mjs +3 -2
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/slider/slider-arithmetic.mjs +74 -13
- package/dist/slider/slider-arithmetic.mjs.map +1 -1
- package/dist/slider/slider-context.mjs.map +1 -1
- package/dist/slider/slider-label.d.mts.map +1 -1
- package/dist/slider/slider-label.mjs +3 -9
- package/dist/slider/slider-label.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts +2 -2
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +36 -116
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/slider-thumb.d.mts.map +1 -1
- package/dist/slider/slider-thumb.mjs +8 -6
- package/dist/slider/slider-thumb.mjs.map +1 -1
- package/dist/slider/slider-value.d.mts.map +1 -1
- package/dist/slider/slider-value.mjs +2 -1
- package/dist/slider/slider-value.mjs.map +1 -1
- package/dist/slider/use-slider-dev-warnings.mjs +29 -0
- package/dist/slider/use-slider-dev-warnings.mjs.map +1 -0
- package/dist/slider/use-thumb-registry.mjs +51 -0
- package/dist/slider/use-thumb-registry.mjs.map +1 -0
- package/dist/switch/switch.d.mts +4 -5
- package/dist/switch/switch.d.mts.map +1 -1
- package/dist/switch/switch.mjs +15 -55
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-context.d.mts +2 -3
- package/dist/tabs/tabs-context.d.mts.map +1 -1
- package/dist/tabs/tabs-context.mjs.map +1 -1
- package/dist/tabs/tabs-list.d.mts.map +1 -1
- package/dist/tabs/tabs-list.mjs +9 -22
- package/dist/tabs/tabs-list.mjs.map +1 -1
- package/dist/tabs/tabs-panel.d.mts +3 -4
- package/dist/tabs/tabs-panel.d.mts.map +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts +4 -3
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +2 -1
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/tabs/tabs-tab.d.mts +3 -4
- package/dist/tabs/tabs-tab.d.mts.map +1 -1
- package/dist/tabs/tabs-tab.mjs.map +1 -1
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +2 -8
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-context.mjs.map +1 -1
- package/dist/toast/toast-hotkey.mjs +27 -0
- package/dist/toast/toast-hotkey.mjs.map +1 -0
- package/dist/toast/toast-queue.mjs +137 -0
- package/dist/toast/toast-queue.mjs.map +1 -0
- package/dist/toast/toast-timers.mjs +65 -0
- package/dist/toast/toast-timers.mjs.map +1 -0
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +30 -235
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/toast.mjs +1 -1
- package/dist/toast/toast.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +52 -0
- package/dist/toast/use-modal-portal-host.mjs.map +1 -0
- package/dist/toggle/toggle.d.mts +3 -4
- package/dist/toggle/toggle.d.mts.map +1 -1
- package/dist/toggle/toggle.mjs +7 -10
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-context.d.mts +2 -1
- package/dist/toggle-group/toggle-group-context.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-context.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-item.d.mts +5 -3
- package/dist/toggle-group/toggle-group-item.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-item.mjs +5 -7
- package/dist/toggle-group/toggle-group-item.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +29 -64
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/toolbar/toolbar-root.d.mts +2 -2
- package/dist/toolbar/toolbar-root.d.mts.map +1 -1
- package/dist/toolbar/toolbar-root.mjs +3 -4
- package/dist/toolbar/toolbar-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-context.d.mts +1 -1
- package/dist/tooltip/tooltip-context.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +6 -15
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +2 -2
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.d.mts +2 -1
- package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +3 -2
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/tooltip/use-tooltip-interaction.mjs +4 -3
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/accordion/accordion-context.d.mts +0 -5
- package/dist/accordion/accordion-context.d.mts.map +0 -1
- package/dist/internal/use-popover-root.mjs.map +0 -1
- /package/dist/internal/{use-popover-root.d.mts → use-overlay-root.d.mts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/internal/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/internal/types.ts"],"mappings":";;;YAGY;;;;;;;YAQA,OAAO,4CAA4C,MAAM;iBAEpD;;WAEN,OAAO;;;YAIN,aAAa,GAAG,gBAAgB,gBAAgB,iBAAiB,QAC1E,MAAM,GAAG,SAAS;;;;;;;;YAUT,oBAAoB,GAAG,gBAAgB,gBAAgB,kBACjE,MAAM,GACN,SAAS;;;;;;;;;;;;;;;YAiBC;;YAGA,WAAW,GAAG,SAAS,MAAM,OAAO,UAAU;;;;;;YAO9C,WAAW,OAAO,SAC1B,aAAa,QAAQ,YACnB,OAAO,OAAO,OAAO,UAAU"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useSupersededRejection } from "./use-superseded-rejection.mjs";
|
|
3
|
+
import { useRef, useTransition } from "react";
|
|
3
4
|
//#region src/internal/use-action-trigger.ts
|
|
4
|
-
/** Reports an error that cannot reach a boundary (conventions 2.4: never swallow). */
|
|
5
|
-
function report(error) {
|
|
6
|
-
if (typeof reportError === "function") reportError(error);
|
|
7
|
-
else console.error(error);
|
|
8
|
-
}
|
|
9
5
|
/**
|
|
10
6
|
* The transition of a pure-trigger part: an `action` with no state of its own (`Button`,
|
|
11
7
|
* `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`; conventions 3.4). A second `run`
|
|
@@ -19,19 +15,11 @@ function report(error) {
|
|
|
19
15
|
*/
|
|
20
16
|
function useActionTrigger(options = {}) {
|
|
21
17
|
const { openGeneration, ignoreWhilePending = true } = options;
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
if (supersededError !== null) throw supersededError.error;
|
|
18
|
+
const ownCapture = useSupersededRejection();
|
|
19
|
+
const captureSuperseded = options.captureSuperseded ?? ownCapture;
|
|
25
20
|
const [pending, startOwnTransition] = useTransition();
|
|
26
21
|
const latest = useRef(0);
|
|
27
|
-
const mounted = useRef(false);
|
|
28
22
|
const inFlight = useRef(0);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
mounted.current = true;
|
|
31
|
-
return () => {
|
|
32
|
-
mounted.current = false;
|
|
33
|
-
};
|
|
34
|
-
}, []);
|
|
35
23
|
const run = (work, then) => {
|
|
36
24
|
if (ignoreWhilePending && inFlight.current > 0) return false;
|
|
37
25
|
inFlight.current++;
|
|
@@ -43,13 +31,7 @@ function useActionTrigger(options = {}) {
|
|
|
43
31
|
} catch (error) {
|
|
44
32
|
inFlight.current--;
|
|
45
33
|
if (id === latest.current) throw error;
|
|
46
|
-
|
|
47
|
-
if (hasSupersededError.current) {
|
|
48
|
-
report(error);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
hasSupersededError.current = true;
|
|
52
|
-
setSupersededError({ error });
|
|
34
|
+
captureSuperseded(error);
|
|
53
35
|
return;
|
|
54
36
|
}
|
|
55
37
|
inFlight.current--;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-action-trigger.mjs","names":[],"sources":["../../src/internal/use-action-trigger.ts"],"sourcesContent":["\"use client\";\nimport {
|
|
1
|
+
{"version":3,"file":"use-action-trigger.mjs","names":[],"sources":["../../src/internal/use-action-trigger.ts"],"sourcesContent":["\"use client\";\nimport { useRef, useTransition } from \"react\";\nimport { useSupersededRejection } from \"./use-superseded-rejection.js\";\n\nexport interface ActionTriggerOptions {\n /**\n * Open generation of the overlay a `then` belongs to: `then` is skipped when a newer open of\n * the overlay started after the run began.\n */\n readonly openGeneration?: (() => number) | undefined;\n /**\n * Ignore `run` while a run is in flight (conventions 2.5): `run` returns `false` and starts\n * nothing. In flight means the hook's synchronous in-flight counter is non-zero (it also sees\n * two activations in one task, before React re-rendered); the last render's `pending` is not\n * consulted, so a click in a settled-but-held commit window runs. Default `true`: every pure\n * trigger ignores re-entry. Only the continuous controls (`Slider`, `NumberField`)\n * pass `false`, because a step is not a re-entry: every step must run.\n */\n readonly ignoreWhilePending?: boolean | undefined;\n /**\n * A component with two transition channels (Slider, NumberField) passes one\n * `useSupersededRejection()` called before both hooks, so a superseded rejection of either\n * channel is thrown before both `useTransition`s and never waits for the other channel's\n * pending action. Stable. Default: the hook's own.\n */\n readonly captureSuperseded?: ((error: unknown) => void) | undefined;\n}\n\nexport interface ActionTrigger {\n /** A run started through this hook is in flight (the part's own transition). */\n readonly pending: boolean;\n /**\n * Runs `work` inside the part's own transition and, once it resolves, `then` (still inside the\n * transition: a Close part's close, a menu item's close). A rejection skips `then` and reaches\n * the nearest Error Boundary above the part, also when a later run superseded this one. With\n * `openGeneration`, `then` is skipped when a newer open of the overlay started after the run\n * began. Returns `false` when the run was ignored (a run is in flight and `ignoreWhilePending`\n * is on, the default), so the part can\n * `preventDefault()` the activation, and `true` otherwise.\n */\n readonly run: (work: () => unknown, then?: () => void) => boolean;\n}\n\n/**\n * The transition of a pure-trigger part: an `action` with no state of its own (`Button`,\n * `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`; conventions 3.4). A second `run`\n * while one is in flight is ignored by default (conventions 2.5, design/components/button.md 16).\n *\n * With `ignoreWhilePending: false` (the continuous controls' steps) runs overlap, and the hook\n * surfaces superseded rejections as `useControllableAction` does: React keeps only the newest\n * thenable per `useTransition`, so the rejection of a run that a later run superseded would be\n * dropped. The hook catches it and throws it from render, so it reaches the same boundary as the\n * latest run's rejection does.\n */\nexport function useActionTrigger(options: ActionTriggerOptions = {}): ActionTrigger {\n const { openGeneration, ignoreWhilePending = true } = options;\n\n // Before `useTransition` on purpose (see the hook). Unused (never throws) with an external one.\n const ownCapture = useSupersededRejection();\n const captureSuperseded = options.captureSuperseded ?? ownCapture;\n\n const [pending, startOwnTransition] = useTransition();\n const latest = useRef(0);\n // Runs whose work has not settled yet. Updated synchronously, so a second activation in the\n // same task (React's `pending` is still the stale render value) is seen (conventions 2.5).\n const inFlight = useRef(0);\n\n const run = (work: () => unknown, then?: () => void): boolean => {\n // The own counter only, not the rendered `pending` (design/components/button.md 5.2): after\n // the work settled, a commit held by entanglement must not drop a new activation.\n if (ignoreWhilePending && inFlight.current > 0) return false;\n inFlight.current++;\n const id = ++latest.current;\n // The open this run belongs to (design/components/popover.md 3.4): if the\n // user dismisses and re-opens while the action runs, its close must not close the new open.\n const generation = openGeneration?.();\n startOwnTransition(async () => {\n try {\n await work();\n } catch (error) {\n inFlight.current--;\n // The latest run's rejection takes React's own route to the boundary.\n if (id === latest.current) throw error;\n captureSuperseded(error);\n return;\n }\n inFlight.current--;\n if (openGeneration !== undefined && openGeneration() !== generation) return;\n then?.();\n });\n return true;\n };\n\n return { pending, run };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsDA,SAAgB,iBAAiB,UAAgC,CAAC,GAAkB;CAClF,MAAM,EAAE,gBAAgB,qBAAqB,SAAS;CAGtD,MAAM,aAAa,uBAAuB;CAC1C,MAAM,oBAAoB,QAAQ,qBAAqB;CAEvD,MAAM,CAAC,SAAS,sBAAsB,cAAc;CACpD,MAAM,SAAS,OAAO,CAAC;CAGvB,MAAM,WAAW,OAAO,CAAC;CAEzB,MAAM,OAAO,MAAqB,SAA+B;EAG/D,IAAI,sBAAsB,SAAS,UAAU,GAAG,OAAO;EACvD,SAAS;EACT,MAAM,KAAK,EAAE,OAAO;EAGpB,MAAM,aAAa,iBAAiB;EACpC,mBAAmB,YAAY;GAC7B,IAAI;IACF,MAAM,KAAK;GACb,SAAS,OAAO;IACd,SAAS;IAET,IAAI,OAAO,OAAO,SAAS,MAAM;IACjC,kBAAkB,KAAK;IACvB;GACF;GACA,SAAS;GACT,IAAI,mBAAmB,KAAA,KAAa,eAAe,MAAM,YAAY;GACrE,OAAO;EACT,CAAC;EACD,OAAO;CACT;CAEA,OAAO;EAAE;EAAS;CAAI;AACxB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createActionDetails } from "./action-details.mjs";
|
|
3
|
+
import { dataAttr } from "./data-attr.mjs";
|
|
4
|
+
import { useControllableAction } from "./use-controllable-action.mjs";
|
|
5
|
+
import { useMergedRefs } from "./use-merged-refs.mjs";
|
|
6
|
+
import { fieldInputProps, useFieldControl, useFieldValueChange } from "./use-field-control.mjs";
|
|
7
|
+
import { guardCheckableChange, useNativeChecked } from "./use-native-checked.mjs";
|
|
8
|
+
//#region src/internal/use-checkable-input.ts
|
|
9
|
+
/**
|
|
10
|
+
* The single-checkbox machinery `Checkbox` and `Switch` share: the Field wiring, the
|
|
11
|
+
* controllable action, the native `checked` re-apply and reconciliation (`useNativeChecked`),
|
|
12
|
+
* and the input's owned layer. The components keep their props, state, `useRender` call and
|
|
13
|
+
* transition boundary.
|
|
14
|
+
*/
|
|
15
|
+
function useCheckableInput(options) {
|
|
16
|
+
const { component, checked, defaultChecked, checkedChangeAction, disabled: disabledProp, own, transitionTypes, role, indeterminate } = options;
|
|
17
|
+
const field = useFieldControl({
|
|
18
|
+
labelable: true,
|
|
19
|
+
name: own.name,
|
|
20
|
+
disabled: disabledProp,
|
|
21
|
+
required: own.required,
|
|
22
|
+
id: own.id,
|
|
23
|
+
component
|
|
24
|
+
});
|
|
25
|
+
const disabled = field.disabled;
|
|
26
|
+
const { optimistic, pending, dispatch, latestInFlight } = useControllableAction({
|
|
27
|
+
controlled: checked,
|
|
28
|
+
defaultValue: defaultChecked,
|
|
29
|
+
initialValue: false,
|
|
30
|
+
action: checkedChangeAction,
|
|
31
|
+
transitionTypes,
|
|
32
|
+
warn: {
|
|
33
|
+
component,
|
|
34
|
+
prop: "checked"
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
useFieldValueChange(optimistic);
|
|
38
|
+
const mixed = indeterminate !== void 0;
|
|
39
|
+
const shownIndeterminate = indeterminate === true && !pending;
|
|
40
|
+
const inputRef = useNativeChecked({
|
|
41
|
+
type: "checkbox",
|
|
42
|
+
component,
|
|
43
|
+
checked: optimistic,
|
|
44
|
+
defaultChecked: checked === void 0 ? defaultChecked ?? false : void 0,
|
|
45
|
+
indeterminate: mixed ? shownIndeterminate : void 0,
|
|
46
|
+
latestInFlight,
|
|
47
|
+
onPlatformChange: (next, event) => dispatch(next, createActionDetails(event, { reason: "platform" }))
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
optimistic,
|
|
51
|
+
pending,
|
|
52
|
+
disabled,
|
|
53
|
+
shownIndeterminate,
|
|
54
|
+
ref: useMergedRefs(inputRef, field.ref),
|
|
55
|
+
libraryProps: {
|
|
56
|
+
...fieldInputProps(field),
|
|
57
|
+
type: "checkbox",
|
|
58
|
+
...role !== void 0 && { role },
|
|
59
|
+
checked: optimistic,
|
|
60
|
+
defaultChecked: void 0,
|
|
61
|
+
...mixed && { indeterminate: void 0 },
|
|
62
|
+
"aria-checked": void 0,
|
|
63
|
+
disabled,
|
|
64
|
+
"data-checked": dataAttr(optimistic),
|
|
65
|
+
...mixed && { "data-indeterminate": dataAttr(shownIndeterminate) },
|
|
66
|
+
"data-pending": dataAttr(pending),
|
|
67
|
+
"data-disabled": dataAttr(disabled),
|
|
68
|
+
onChange: (event) => {
|
|
69
|
+
if (disabled) return;
|
|
70
|
+
const nativeEvent = event.nativeEvent;
|
|
71
|
+
guardCheckableChange(nativeEvent, () => dispatch(!optimistic, createActionDetails(nativeEvent, { reason: "activate" })), component);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { useCheckableInput };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=use-checkable-input.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-checkable-input.mjs","names":[],"sources":["../../src/internal/use-checkable-input.ts"],"sourcesContent":["\"use client\";\nimport type { ChangeEvent, ComponentPropsWithRef, Ref } from \"react\";\nimport { createActionDetails } from \"./action-details.js\";\nimport { dataAttr } from \"./data-attr.js\";\nimport type { DataAttributes } from \"./render-element.js\";\nimport type { ActionDetails, ChangeAction, ChangeReason } from \"./types.js\";\nimport { useControllableAction } from \"./use-controllable-action.js\";\nimport { fieldInputProps, useFieldControl, useFieldValueChange } from \"./use-field-control.js\";\nimport { useMergedRefs } from \"./use-merged-refs.js\";\nimport { guardCheckableChange, useNativeChecked } from \"./use-native-checked.js\";\n\n/** The details shape `Checkbox` and `Switch` share (each declares its own public name). */\nexport interface CheckableChangeDetails extends ActionDetails {\n readonly reason: ChangeReason;\n}\n\nexport interface UseCheckableInputOptions {\n /** Warning tag and dispatch-guard name. */\n readonly component: \"Checkbox\" | \"Switch\";\n readonly checked: boolean | undefined;\n readonly defaultChecked: boolean | undefined;\n readonly checkedChangeAction: ChangeAction<boolean, CheckableChangeDetails> | undefined;\n /** The `disabled` prop. */\n readonly disabled: boolean | undefined;\n /** The control's own `name` / `required` / `id` (the Field's \"own or the Field's\"). */\n readonly own: Pick<ComponentPropsWithRef<\"input\">, \"name\" | \"required\" | \"id\">;\n /** View Transition types of a dispatch of `next`. */\n readonly transitionTypes: (next: boolean) => readonly string[];\n /** Switch only: the owned `role`. */\n readonly role?: \"switch\" | undefined;\n /** Checkbox only: the `indeterminate` prop. `undefined` for a control with no mixed state. */\n readonly indeterminate?: boolean | undefined;\n}\n\nexport interface CheckableInput {\n readonly optimistic: boolean;\n readonly pending: boolean;\n /** Own `disabled` or the Field's. */\n readonly disabled: boolean;\n /** `indeterminate && !pending`. */\n readonly shownIndeterminate: boolean;\n readonly ref: Ref<HTMLInputElement> | undefined;\n /** The owned layer (conventions 1.2) of the input. */\n readonly libraryProps: Partial<ComponentPropsWithRef<\"input\">> & DataAttributes;\n}\n\n/**\n * The single-checkbox machinery `Checkbox` and `Switch` share: the Field wiring, the\n * controllable action, the native `checked` re-apply and reconciliation (`useNativeChecked`),\n * and the input's owned layer. The components keep their props, state, `useRender` call and\n * transition boundary.\n */\nexport function useCheckableInput(options: UseCheckableInputOptions): CheckableInput {\n const {\n component,\n checked,\n defaultChecked,\n checkedChangeAction,\n disabled: disabledProp,\n own,\n transitionTypes,\n role,\n indeterminate,\n } = options;\n // Inside a Field.Root (design/components/field-form.md 7.2) the Field owns the id and the ARIA\n // wiring, and `name` / `required` / `disabled` default from it.\n const field = useFieldControl({\n labelable: true,\n name: own.name,\n disabled: disabledProp,\n required: own.required,\n id: own.id,\n component,\n });\n const disabled = field.disabled;\n\n const { optimistic, pending, dispatch, latestInFlight } = useControllableAction<\n boolean,\n CheckableChangeDetails\n >({\n controlled: checked,\n defaultValue: defaultChecked,\n initialValue: false,\n action: checkedChangeAction,\n transitionTypes,\n warn: { component, prop: \"checked\" },\n });\n // Inside a Field: a value React writes with no event (a rejected action rolling back, a\n // controlled change) re-reads validity and `validate` after the commit.\n useFieldValueChange(optimistic);\n\n // Suspended while pending (conventions 4.1): the browser clears the property on the click, and\n // the parent may not have recomputed yet. Restored on settle if the parent still says mixed.\n const mixed = indeterminate !== undefined;\n const shownIndeterminate = indeterminate === true && !pending;\n\n const inputRef = useNativeChecked({\n type: \"checkbox\",\n component,\n checked: optimistic,\n // Uncontrolled: the latest prop is the reset target. Controlled: React's mount-time value.\n defaultChecked: checked === undefined ? (defaultChecked ?? false) : undefined,\n indeterminate: mixed ? shownIndeterminate : undefined,\n latestInFlight,\n onPlatformChange: (next, event) =>\n dispatch(next, createActionDetails(event, { reason: \"platform\" })),\n });\n\n const ref = useMergedRefs<HTMLInputElement>(inputRef, field.ref);\n\n const libraryProps = {\n ...fieldInputProps(field),\n type: \"checkbox\",\n ...(role !== undefined && { role }),\n // The DOM state is the optimistic state (conventions 3.2): react-dom restores a controlled\n // input to its props after every event, and only the sync-lane optimistic value survives.\n checked: optimistic,\n defaultChecked: undefined,\n // Not a DOM attribute; `useNativeChecked` sets the property. Owned so a `render` element's\n // own `indeterminate` prop (which react-dom would warn about) is stripped.\n ...(mixed && { indeterminate: undefined }),\n \"aria-checked\": undefined,\n // Owned so that native disabledness, `data-disabled` and the click guard always agree: a\n // `render` element cannot re-enable (`disabled={false}`) or disable the input on its own.\n disabled,\n \"data-checked\": dataAttr(optimistic),\n ...(mixed && { \"data-indeterminate\": dataAttr(shownIndeterminate) }),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n // A natively disabled input fires no click; this covers `render` elements that do not\n // honour `disabled`.\n if (disabled) return;\n const nativeEvent = event.nativeEvent;\n // `indeterminate` plays no part: the platform's rule is \"flip checked, clear mixed\".\n guardCheckableChange(\n nativeEvent,\n () => dispatch(!optimistic, createActionDetails(nativeEvent, { reason: \"activate\" })),\n component,\n );\n },\n };\n\n return { optimistic, pending, disabled, shownIndeterminate, ref, libraryProps };\n}\n"],"mappings":";;;;;;;;;;;;;;AAoDA,SAAgB,kBAAkB,SAAmD;CACnF,MAAM,EACJ,WACA,SACA,gBACA,qB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;GACF;EAG0E;CAAE;AAChF"}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useSupersededRejection } from "./use-superseded-rejection.mjs";
|
|
2
3
|
import { useLatest } from "./use-latest.mjs";
|
|
3
4
|
import { addTransitionType, startTransition, useCallback, useEffect, useMemo, useOptimistic, useRef, useState, useTransition } from "react";
|
|
4
5
|
//#region src/internal/use-controllable-action.ts
|
|
5
6
|
const isDev = process.env.NODE_ENV !== "production";
|
|
7
|
+
/**
|
|
8
|
+
* What the user intends (conventions 3.8 rule 1): the latest in-flight dispatch's `next`, else
|
|
9
|
+
* `optimistic`. An explicit null check, not `?.next ?? optimistic`, which would drop an in-flight
|
|
10
|
+
* dispatch of a nullish value (a pending reset to "nothing checked"). Handlers and effects only.
|
|
11
|
+
*/
|
|
12
|
+
function intendedValue(latestInFlight, optimistic) {
|
|
13
|
+
const inFlight = latestInFlight();
|
|
14
|
+
return inFlight === null ? optimistic : inFlight.next;
|
|
15
|
+
}
|
|
6
16
|
function capitalize(s) {
|
|
7
17
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
8
18
|
}
|
|
9
|
-
/** Reports an error that cannot reach a boundary (conventions 2.4: never swallow). */
|
|
10
|
-
function report(error) {
|
|
11
|
-
if (typeof reportError === "function") reportError(error);
|
|
12
|
-
else console.error(error);
|
|
13
|
-
}
|
|
14
19
|
/**
|
|
15
20
|
* The one place the state model of conventions section 3 is implemented: committed state,
|
|
16
21
|
* optimistic state (`useOptimistic`, reducer form), the component's own transition, the
|
|
@@ -19,9 +24,8 @@ function report(error) {
|
|
|
19
24
|
*/
|
|
20
25
|
function useControllableAction(options) {
|
|
21
26
|
const { controlled, defaultValue, initialValue, action, transitionTypes, reducer, warn } = options;
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
if (supersededError !== null) throw supersededError.error;
|
|
27
|
+
const ownCapture = useSupersededRejection();
|
|
28
|
+
const captureSuperseded = options.captureSuperseded ?? ownCapture;
|
|
25
29
|
const [internal, setInternal] = useState(defaultValue === void 0 ? initialValue : defaultValue);
|
|
26
30
|
const isControlled = controlled !== void 0;
|
|
27
31
|
const committed = isControlled ? controlled : internal;
|
|
@@ -32,14 +36,7 @@ function useControllableAction(options) {
|
|
|
32
36
|
count: 0,
|
|
33
37
|
next: void 0
|
|
34
38
|
});
|
|
35
|
-
const mounted = useRef(false);
|
|
36
39
|
useDevWarnings(isControlled, defaultValue !== void 0, warn);
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
mounted.current = true;
|
|
39
|
-
return () => {
|
|
40
|
-
mounted.current = false;
|
|
41
|
-
};
|
|
42
|
-
}, []);
|
|
43
40
|
const props = useLatest({
|
|
44
41
|
committed,
|
|
45
42
|
isControlled,
|
|
@@ -66,13 +63,7 @@ function useControllableAction(options) {
|
|
|
66
63
|
} catch (error) {
|
|
67
64
|
settle();
|
|
68
65
|
if (id === latest.current) throw error;
|
|
69
|
-
|
|
70
|
-
if (hasSupersededError.current) {
|
|
71
|
-
report(error);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
hasSupersededError.current = true;
|
|
75
|
-
setSupersededError({ error });
|
|
66
|
+
captureSuperseded(error);
|
|
76
67
|
return;
|
|
77
68
|
}
|
|
78
69
|
settle();
|
|
@@ -81,7 +72,8 @@ function useControllableAction(options) {
|
|
|
81
72
|
}, [
|
|
82
73
|
props,
|
|
83
74
|
settle,
|
|
84
|
-
setOptimistic
|
|
75
|
+
setOptimistic,
|
|
76
|
+
captureSuperseded
|
|
85
77
|
]);
|
|
86
78
|
const latestInFlight = useCallback(() => {
|
|
87
79
|
const { count, next } = inFlight.current;
|
|
@@ -132,6 +124,6 @@ function useDevWarnings(isControlled, hasDefault, warn) {
|
|
|
132
124
|
]);
|
|
133
125
|
}
|
|
134
126
|
//#endregion
|
|
135
|
-
export { useControllableAction };
|
|
127
|
+
export { intendedValue, useControllableAction };
|
|
136
128
|
|
|
137
129
|
//# sourceMappingURL=use-controllable-action.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-controllable-action.mjs","names":[],"sources":["../../src/internal/use-controllable-action.ts"],"sourcesContent":["\"use client\";\nimport {\n addTransitionType,\n startTransition,\n useCallback,\n useEffect,\n useMemo,\n useOptimistic,\n useRef,\n useState,\n useTransition,\n} from \"react\";\nimport type { ActionDetails, ChangeAction } from \"./types.js\";\nimport { useLatest } from \"./use-latest.js\";\n\nexport interface UseControllableActionOptions<T, Details extends ActionDetails> {\n /** The controlled prop (`x`). `undefined` means uncontrolled. */\n controlled: T | undefined;\n /** The `defaultX` prop as the consumer passed it; `undefined` when omitted. */\n defaultValue: T | undefined;\n /** Initial uncontrolled value when neither `x` nor `defaultX` is given. */\n initialValue: T;\n /** The `xChangeAction` prop. Awaited inside this hook's transition. */\n action: ChangeAction<T, Details> | undefined;\n /**\n * View Transition types to attach to the commit that ends a dispatch. Receives the previous\n * committed value and the details object (Tabs derives next/prev direction from them).\n */\n transitionTypes?: (next: T, prev: T, details: Details) => readonly string[];\n /**\n * Optimistic reducer (conventions 3.4). Default: replace the value with `next`. Multi-item\n * states (Accordion's open set) pass a reducer keyed by item, reading the item from `details`,\n * so stacked optimistic patches re-base onto a changed committed value.\n */\n reducer?: (prev: T, next: T, details: Details) => T;\n /** Names used in development warnings. */\n warn?: { readonly component: string; readonly prop: string };\n}\n\nexport interface ControllableAction<T, Details extends ActionDetails> {\n /** Committed value (`x ?? internal`). Content regions render this. */\n readonly committed: T;\n /** Optimistic value; trigger parts render this. */\n readonly optimistic: T;\n /** An action dispatched through this hook is in flight. */\n readonly pending: boolean;\n /** Runs the action inside the hook's transition with optimistic feedback. */\n readonly dispatch: (next: T, details: Details) => void;\n /**\n * The `next` of the most recent dispatch while any dispatch's action is still unsettled, else\n * `null`. Lets a component with a browser-owned path (Accordion's find-in-page reveal) build on\n * what the user already intends instead of on the DOM. Read it from handlers and effects only.\n */\n readonly latestInFlight: () => { readonly next: T } | null;\n /**\n * Uncontrolled mode only (a no-op when controlled): writes the committed value without calling\n * the action, without an optimistic step and without a transition. For a component that adopts\n * a default the browser chose (Select with neither `value` nor `defaultValue` takes the first\n * enabled option, design/components/select.md 5). Call it from a layout effect so the write is\n * flushed before paint.\n */\n readonly adopt: (next: T) => void;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nfunction capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\n/** Reports an error that cannot reach a boundary (conventions 2.4: never swallow). */\nfunction report(error: unknown): void {\n if (typeof reportError === \"function\") reportError(error);\n else console.error(error);\n}\n\n/**\n * The one place the state model of conventions section 3 is implemented: committed state,\n * optimistic state (`useOptimistic`, reducer form), the component's own transition, the\n * post-`await` write of uncontrolled state, the latest-dispatch guard, and the surfacing of\n * superseded rejections (conventions 2.4).\n */\nexport function useControllableAction<T, Details extends ActionDetails = ActionDetails>(\n options: UseControllableActionOptions<T, Details>,\n): ControllableAction<T, Details> {\n const { controlled, defaultValue, initialValue, action, transitionTypes, reducer, warn } =\n options;\n\n // React keeps only the newest thenable per `useTransition`, so a rejection from a dispatch that\n // was superseded by a later one would be dropped entirely (no boundary, no `reportError`). The\n // hook catches those itself, keeps the first, and throws it from render so it reaches the same\n // nearest Error Boundary as the latest dispatch's rejection does through React.\n //\n // The throw sits before `useTransition` on purpose: React retries an errored render with every\n // pending lane, and in that retry `useTransition` unwraps the still-pending action thenable and\n // suspends, which would hold the boundary commit until the newer action settles.\n const [supersededError, setSupersededError] = useState<{ readonly error: unknown } | null>(null);\n const hasSupersededError = useRef(false);\n if (supersededError !== null) throw supersededError.error;\n\n const [internal, setInternal] = useState<T>(\n defaultValue === undefined ? initialValue : defaultValue,\n );\n const isControlled = controlled !== undefined;\n const committed = isControlled ? controlled : internal;\n const [optimistic, setOptimistic] = useOptimistic(\n committed,\n (prev: T, patch: { next: T; details: Details }) =>\n reducer ? reducer(prev, patch.next, patch.details) : patch.next,\n );\n const [pending, startOwnTransition] = useTransition();\n const latest = useRef(0);\n const inFlight = useRef<{ count: number; next: T | undefined }>({ count: 0, next: undefined });\n const mounted = useRef(false);\n\n useDevWarnings(isControlled, defaultValue !== undefined, warn);\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n // The functions below keep one identity for the hook's lifetime, so the returned object changes\n // only with `committed`, `optimistic` and `pending`, and the components' memoised context values\n // are reused across renders that change none of them (#48). They read the props of the last\n // committed render through `props`; they run from handlers, actions and effects, never render.\n const props = useLatest({ committed, isControlled, action, transitionTypes });\n\n const settle = useCallback((): void => {\n inFlight.current.count -= 1;\n if (inFlight.current.count === 0) inFlight.current.next = undefined;\n }, []);\n\n const dispatch = useCallback(\n (next: T, details: Details): void => {\n // Read once, at the call, as the per-render closure did: the action, the mode and the\n // previous value belong to the UI the user acted on, even after the `await`.\n const { committed: prev, isControlled, action, transitionTypes } = props.current;\n const id = ++latest.current;\n inFlight.current.count += 1;\n inFlight.current.next = next;\n startOwnTransition(async () => {\n for (const type of transitionTypes?.(next, prev, details) ?? []) addTransitionType(type);\n setOptimistic({ next, details });\n try {\n await action?.(next, details);\n } catch (error) {\n settle();\n // The latest dispatch's rejection takes React's own route to the boundary.\n if (id === latest.current) throw error;\n // Nothing to throw to once unmounted (React drops its own thenables the same way).\n if (!mounted.current) return;\n if (hasSupersededError.current) {\n // One boundary reset per burst is enough; later errors are still reported.\n report(error);\n return;\n }\n hasSupersededError.current = true;\n // Outside the transition by now (after an await), so this is an urgent update: the\n // owner re-renders promptly and throws.\n setSupersededError({ error });\n return;\n }\n settle();\n if (!isControlled && id === latest.current) {\n startTransition(() => setInternal(next));\n }\n });\n },\n [props, settle, setOptimistic],\n );\n\n const latestInFlight = useCallback((): { readonly next: T } | null => {\n const { count, next } = inFlight.current;\n return count > 0 ? { next: next as T } : null;\n }, []);\n\n const adopt = useCallback(\n (next: T): void => {\n if (!props.current.isControlled) setInternal(next);\n },\n [props],\n );\n\n return useMemo(\n () => ({ committed, optimistic, pending, dispatch, latestInFlight, adopt }),\n [committed, optimistic, pending, dispatch, latestInFlight, adopt],\n );\n}\n\nfunction useDevWarnings(\n isControlled: boolean,\n hasDefault: boolean,\n warn: { readonly component: string; readonly prop: string } | undefined,\n): void {\n const initialMode = useRef(isControlled);\n const warnedBoth = useRef(false);\n const warnedSwitch = useRef(false);\n const component = warn?.component ?? \"A component\";\n const prop = warn?.prop ?? \"value\";\n\n useEffect(() => {\n if (!isDev) return;\n const defaultProp = `default${capitalize(prop)}`;\n\n if (isControlled && hasDefault && !warnedBoth.current) {\n warnedBoth.current = true;\n console.error(\n `${component}: both \\`${prop}\\` and \\`${defaultProp}\\` are set. ` +\n `Use \\`${prop}\\` for controlled mode or \\`${defaultProp}\\` for uncontrolled mode, not both.`,\n );\n }\n\n if (initialMode.current !== isControlled && !warnedSwitch.current) {\n warnedSwitch.current = true;\n const from = initialMode.current ? \"controlled\" : \"uncontrolled\";\n const to = isControlled ? \"controlled\" : \"uncontrolled\";\n console.error(\n `${component}: \\`${prop}\\` changed from ${from} to ${to}. Switching modes after mount ` +\n `is not supported; keep \\`${prop}\\` either always defined or always undefined.`,\n );\n }\n }, [component, prop, isControlled, hasDefault]);\n}\n"],"mappings":";;;;AAgEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,SAAS,WAAW,GAAmB;CACrC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,MAAM,CAAC;AAC9C;;AAGA,SAAS,OAAO,OAAsB;CACpC,IAAI,OAAO,gBAAgB,YAAY,YAAY,KAAK;MACnD,QAAQ,MAAM,KAAK;AAC1B;;;;;;;AAQA,SAAgB,sBACd,SACgC;CAChC,MAAM,EAAE,YAAY,cAAc,cAAc,QAAQ,iBAAiB,SAAS,SAChF;CAUF,MAAM,CAAC,iBAAiB,sBAAsB,SAA6C,IAAI;CAC/F,MAAM,qBAAqB,OAAO,KAAK;CACvC,IAAI,oBAAoB,MAAM,MAAM,gBAAgB;CAEpD,MAA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GAAG;EAAC;EAAW;EAAM;EAAc;CAAU,CAAC;AAChD"}
|
|
1
|
+
{"version":3,"file":"use-controllable-action.mjs","names":[],"sources":["../../src/internal/use-controllable-action.ts"],"sourcesContent":["\"use client\";\nimport {\n addTransitionType,\n startTransition,\n useCallback,\n useEffect,\n useMemo,\n useOptimistic,\n useRef,\n useState,\n useTransition,\n} from \"react\";\nimport type { ActionDetails, ChangeAction } from \"./types.js\";\nimport { useLatest } from \"./use-latest.js\";\nimport { useSupersededRejection } from \"./use-superseded-rejection.js\";\n\nexport interface UseControllableActionOptions<T, Details extends ActionDetails> {\n /** The controlled prop (`x`). `undefined` means uncontrolled. */\n controlled: T | undefined;\n /** The `defaultX` prop as the consumer passed it; `undefined` when omitted. */\n defaultValue: T | undefined;\n /** Initial uncontrolled value when neither `x` nor `defaultX` is given. */\n initialValue: T;\n /** The `xChangeAction` prop. Awaited inside this hook's transition. */\n action: ChangeAction<T, Details> | undefined;\n /**\n * View Transition types to attach to the commit that ends a dispatch. Receives the previous\n * committed value and the details object (Tabs derives next/prev direction from them).\n */\n transitionTypes?: (next: T, prev: T, details: Details) => readonly string[];\n /**\n * Optimistic reducer (conventions 3.4). Default: replace the value with `next`. Multi-item\n * states (Accordion's open set) pass a reducer keyed by item, reading the item from `details`,\n * so stacked optimistic patches re-base onto a changed committed value.\n */\n reducer?: (prev: T, next: T, details: Details) => T;\n /** Names used in development warnings. */\n warn?: { readonly component: string; readonly prop: string };\n /**\n * A component with two transition channels (Slider, NumberField) passes one\n * `useSupersededRejection()` called before both hooks, so a superseded rejection of either\n * channel is thrown before both `useTransition`s and never waits for the other channel's\n * pending action. Stable. Default: the hook's own.\n */\n readonly captureSuperseded?: ((error: unknown) => void) | undefined;\n}\n\nexport interface ControllableAction<T, Details extends ActionDetails> {\n /** Committed value (`x ?? internal`). Content regions render this. */\n readonly committed: T;\n /** Optimistic value; trigger parts render this. */\n readonly optimistic: T;\n /** An action dispatched through this hook is in flight. */\n readonly pending: boolean;\n /** Runs the action inside the hook's transition with optimistic feedback. */\n readonly dispatch: (next: T, details: Details) => void;\n /**\n * The `next` of the most recent dispatch while any dispatch's action is still unsettled, else\n * `null`. Lets a component with a browser-owned path (Accordion's find-in-page reveal) build on\n * what the user already intends instead of on the DOM. Read it from handlers and effects only.\n */\n readonly latestInFlight: () => { readonly next: T } | null;\n /**\n * Uncontrolled mode only (a no-op when controlled): writes the committed value without calling\n * the action, without an optimistic step and without a transition. For a component that adopts\n * a default the browser chose (Select with neither `value` nor `defaultValue` takes the first\n * enabled option, design/components/select.md 5). Call it from a layout effect so the write is\n * flushed before paint.\n */\n readonly adopt: (next: T) => void;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * What the user intends (conventions 3.8 rule 1): the latest in-flight dispatch's `next`, else\n * `optimistic`. An explicit null check, not `?.next ?? optimistic`, which would drop an in-flight\n * dispatch of a nullish value (a pending reset to \"nothing checked\"). Handlers and effects only.\n */\nexport function intendedValue<T>(\n latestInFlight: () => { readonly next: T } | null,\n optimistic: T,\n): T {\n const inFlight = latestInFlight();\n return inFlight === null ? optimistic : inFlight.next;\n}\n\nfunction capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\n/**\n * The one place the state model of conventions section 3 is implemented: committed state,\n * optimistic state (`useOptimistic`, reducer form), the component's own transition, the\n * post-`await` write of uncontrolled state, the latest-dispatch guard, and the surfacing of\n * superseded rejections (conventions 2.4).\n */\nexport function useControllableAction<T, Details extends ActionDetails = ActionDetails>(\n options: UseControllableActionOptions<T, Details>,\n): ControllableAction<T, Details> {\n const { controlled, defaultValue, initialValue, action, transitionTypes, reducer, warn } =\n options;\n\n // Before `useTransition` on purpose (see the hook). Unused (never throws) with an external one.\n const ownCapture = useSupersededRejection();\n const captureSuperseded = options.captureSuperseded ?? ownCapture;\n\n const [internal, setInternal] = useState<T>(\n defaultValue === undefined ? initialValue : defaultValue,\n );\n const isControlled = controlled !== undefined;\n const committed = isControlled ? controlled : internal;\n const [optimistic, setOptimistic] = useOptimistic(\n committed,\n (prev: T, patch: { next: T; details: Details }) =>\n reducer ? reducer(prev, patch.next, patch.details) : patch.next,\n );\n const [pending, startOwnTransition] = useTransition();\n const latest = useRef(0);\n const inFlight = useRef<{ count: number; next: T | undefined }>({ count: 0, next: undefined });\n\n useDevWarnings(isControlled, defaultValue !== undefined, warn);\n\n // The functions below keep one identity for the hook's lifetime, so the returned object changes\n // only with `committed`, `optimistic` and `pending`, and the components' memoised context values\n // are reused across renders that change none of them. They read the props of the last\n // committed render through `props`; they run from handlers, actions and effects, never render.\n const props = useLatest({ committed, isControlled, action, transitionTypes });\n\n const settle = useCallback((): void => {\n inFlight.current.count -= 1;\n if (inFlight.current.count === 0) inFlight.current.next = undefined;\n }, []);\n\n const dispatch = useCallback(\n (next: T, details: Details): void => {\n // Read once, at the call, as the per-render closure did: the action, the mode and the\n // previous value belong to the UI the user acted on, even after the `await`.\n const { committed: prev, isControlled, action, transitionTypes } = props.current;\n const id = ++latest.current;\n inFlight.current.count += 1;\n inFlight.current.next = next;\n startOwnTransition(async () => {\n for (const type of transitionTypes?.(next, prev, details) ?? []) addTransitionType(type);\n setOptimistic({ next, details });\n try {\n await action?.(next, details);\n } catch (error) {\n settle();\n // The latest dispatch's rejection takes React's own route to the boundary.\n if (id === latest.current) throw error;\n captureSuperseded(error);\n return;\n }\n settle();\n if (!isControlled && id === latest.current) {\n startTransition(() => setInternal(next));\n }\n });\n },\n [props, settle, setOptimistic, captureSuperseded],\n );\n\n const latestInFlight = useCallback((): { readonly next: T } | null => {\n const { count, next } = inFlight.current;\n return count > 0 ? { next: next as T } : null;\n }, []);\n\n const adopt = useCallback(\n (next: T): void => {\n if (!props.current.isControlled) setInternal(next);\n },\n [props],\n );\n\n return useMemo(\n () => ({ committed, optimistic, pending, dispatch, latestInFlight, adopt }),\n [committed, optimistic, pending, dispatch, latestInFlight, adopt],\n );\n}\n\nfunction useDevWarnings(\n isControlled: boolean,\n hasDefault: boolean,\n warn: { readonly component: string; readonly prop: string } | undefined,\n): void {\n const initialMode = useRef(isControlled);\n const warnedBoth = useRef(false);\n const warnedSwitch = useRef(false);\n const component = warn?.component ?? \"A component\";\n const prop = warn?.prop ?? \"value\";\n\n useEffect(() => {\n if (!isDev) return;\n const defaultProp = `default${capitalize(prop)}`;\n\n if (isControlled && hasDefault && !warnedBoth.current) {\n warnedBoth.current = true;\n console.error(\n `${component}: both \\`${prop}\\` and \\`${defaultProp}\\` are set. ` +\n `Use \\`${prop}\\` for controlled mode or \\`${defaultProp}\\` for uncontrolled mode, not both.`,\n );\n }\n\n if (initialMode.current !== isControlled && !warnedSwitch.current) {\n warnedSwitch.current = true;\n const from = initialMode.current ? \"controlled\" : \"uncontrolled\";\n const to = isControlled ? \"controlled\" : \"uncontrolled\";\n console.error(\n `${component}: \\`${prop}\\` changed from ${from} to ${to}. Switching modes after mount ` +\n `is not supported; keep \\`${prop}\\` either always defined or always undefined.`,\n );\n }\n }, [component, prop, isControlled, hasDefault]);\n}\n"],"mappings":";;;;;AAwEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;AAOvC,SAAgB,cACd,gBACA,YACG;CACH,MAAM,WAAW,eAAe;CAChC,OAAO,aAAa,OAAO,aAAa,SAAS;AACnD;AAEA,SAAS,WAAW,GAAmB;CACrC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,MAAM,CAAC;AAC9C;;;;;;;AAQA,SAAgB,sBACd,SACgC;CAChC,MAAM,EAAE,YAAY,cAAc,cAAc,QAAQ,iBAAiB,SAAS,SAChF;CAGF,MAAM,aAAa,uBAAuB;CAC1C,MAAM,oBAAoB,QAAQ,qBAAqB;CAEvD,MAAM,CAAC,UAAU,eAAe,SAC9B,iBAAiB,KAAA,IAAY,eAAe,YAC9C;CACA,MAAM,eAAe,eAAe,KAAA;CACpC,MAAM,YAAY,eAAe,aAAa;CAC9C,MAAM,CAAC,YAAY,iBAAiB,cAClC,YACC,MAAS,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I,CAAC,MAAM,QAAQ,cAAc,YAAY,IAAI;CACnD,GACA,CAAC,KAAK,CACR;CAEA,OAAO,eACE;EAAE;EAAW;EAAY;EAAS;EAAU;EAAgB;CAAM,IACzE;EAAC;EAAW;EAAY;EAAS;EAAU;EAAgB;CAAK,CAClE;AACF;AAEA,SAAS,eACP,cACA,YACA,MACM;CACN,MAAM,cAAc,OAAO,YAAY;CACvC,MAAM,aAAa,OAAO,KAAK;CAC/B,MAAM,eAAe,OAAO,KAAK;CACjC,MAAM,YAAY,MAAM,aAAa;CACrC,MAAM,OAAO,MAAM,QAAQ;CAE3B,gBAAgB;EACd,IAAI,CAAC,OAAO;EACZ,MAAM,cAAc,UAAU,WAAW,IAAI;EAE7C,IAAI,gBAAgB,cAAc,CAAC,WAAW,SAAS;GACrD,WAAW,UAAU;GACrB,QAAQ,MACN,GAAG,UAAU,WAAW,KAAK,WAAW,YAAY,oBACzC,KAAK,8BAA8B,YAAY,oCAC5D;EACF;EAEA,IAAI,YAAY,YAAY,gBAAgB,CAAC,aAAa,SAAS;GACjE,aAAa,UAAU;GACvB,MAAM,OAAO,YAAY,UAAU,eAAe;GAElD,QAAQ,MACN,GAAG,UAAU,MAAM,KAAK,kBAAkB,KAAK,MAFtC,eAAe,eAAe,eAEiB,yDAC1B,KAAK,8CACrC;EACF;CACF,GAAG;EAAC;EAAW;EAAM;EAAc;CAAU,CAAC;AAChD"}
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
-
//#region src/internal/use-dev-warning.ts
|
|
4
|
-
const isDev = process.env.NODE_ENV !== "production";
|
|
5
3
|
/**
|
|
6
4
|
* Logs `message` through `console.error` once per component instance, the first time
|
|
7
5
|
* `condition` is true. Runs in an effect (never during render) so the warning cannot fire for a
|
|
8
6
|
* render that is discarded.
|
|
7
|
+
*
|
|
8
|
+
* Pass the message as `isDev && "..."` with the calling module's own `isDev` constant: the text
|
|
9
|
+
* then folds away in a production build (`src/__tests__/production-bundle.test.ts` checks it).
|
|
10
|
+
* In production the hook is a no-op.
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
const useDevWarning = process.env.NODE_ENV !== "production" ? useDevWarningDev : noop;
|
|
13
|
+
function useDevWarningDev(condition, message) {
|
|
11
14
|
const warned = useRef(false);
|
|
12
15
|
useEffect(() => {
|
|
13
|
-
if (!
|
|
16
|
+
if (!condition || message === false || warned.current) return;
|
|
14
17
|
warned.current = true;
|
|
15
18
|
console.error(message);
|
|
16
19
|
}, [condition, message]);
|
|
17
20
|
}
|
|
21
|
+
function noop() {}
|
|
18
22
|
//#endregion
|
|
19
23
|
export { useDevWarning };
|
|
20
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-dev-warning.mjs","names":[],"sources":["../../src/internal/use-dev-warning.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Logs `message` through `console.error` once per component instance, the first time\n * `condition` is true. Runs in an effect (never during render) so the warning cannot fire for a\n * render that is discarded.\n */\nexport
|
|
1
|
+
{"version":3,"file":"use-dev-warning.mjs","names":[],"sources":["../../src/internal/use-dev-warning.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Logs `message` through `console.error` once per component instance, the first time\n * `condition` is true. Runs in an effect (never during render) so the warning cannot fire for a\n * render that is discarded.\n *\n * Pass the message as `isDev && \"...\"` with the calling module's own `isDev` constant: the text\n * then folds away in a production build (`src/__tests__/production-bundle.test.ts` checks it).\n * In production the hook is a no-op.\n */\nexport const useDevWarning: (condition: boolean, message: string | false) => void = isDev\n ? useDevWarningDev\n : noop;\n\nfunction useDevWarningDev(condition: boolean, message: string | false): void {\n const warned = useRef(false);\n useEffect(() => {\n if (!condition || message === false || warned.current) return;\n warned.current = true;\n console.error(message);\n }, [condition, message]);\n}\n\nfunction noop(): void {}\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,gBAXC,QAAQ,IAAI,aAAa,eAYnC,mBACA;AAEJ,SAAS,iBAAiB,WAAoB,SAA+B;CAC3E,MAAM,SAAS,OAAO,KAAK;CAC3B,gBAAgB;EACd,IAAI,CAAC,aAAa,YAAY,SAAS,OAAO,SAAS;EACvD,OAAO,UAAU;EACjB,QAAQ,MAAM,OAAO;CACvB,GAAG,CAAC,WAAW,OAAO,CAAC;AACzB;AAEA,SAAS,OAAa,CAAC"}
|
|
@@ -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,SAA0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
|
|
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,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