@funstack/ui 0.1.0-alpha.18 → 0.1.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordion/accordion-item.mjs +1 -1
- package/dist/accordion/accordion-panel.mjs +1 -1
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +30 -35
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +1 -1
- package/dist/button/button.d.mts +11 -6
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +25 -14
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.mjs +1 -1
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +3 -3
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +3 -3
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +5 -5
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.mjs +2 -2
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +81 -0
- package/dist/combobox/combobox-keyboard.mjs.map +1 -0
- package/dist/combobox/combobox-popup.mjs +3 -3
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +44 -129
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +2 -9
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/use-active-option.mjs +49 -0
- package/dist/combobox/use-active-option.mjs.map +1 -0
- package/dist/combobox/use-combobox-form.mjs +3 -5
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/combobox/use-combobox-text.mjs +43 -0
- package/dist/combobox/use-combobox-text.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +7 -17
- package/dist/combobox/use-option-registry.mjs.map +1 -1
- package/dist/dialog/dialog-close.mjs +2 -2
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-dismiss.mjs +108 -0
- package/dist/dialog/dialog-dismiss.mjs.map +1 -0
- package/dist/dialog/dialog-form.mjs +4 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +73 -169
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +4 -3
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +11 -8
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/button.md +3 -3
- package/dist/docs/components/dialog.md +3 -3
- package/dist/docs/components/field.md +4 -3
- package/dist/docs/components/popover.md +3 -3
- package/dist/docs/components/toast.md +8 -5
- package/dist/docs/roadmap.md +9 -1
- package/dist/field/field-control.d.mts +1 -1
- package/dist/field/field-control.mjs +2 -2
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts +1 -1
- package/dist/field/field-description.mjs +1 -1
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts +1 -1
- package/dist/field/field-error.mjs +1 -1
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts +1 -1
- package/dist/field/field-label.mjs +1 -1
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.d.mts +2 -2
- package/dist/field/field-root.d.mts.map +1 -1
- package/dist/field/field-root.mjs +4 -4
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.d.mts +2 -2
- package/dist/form/form-root.d.mts +1 -1
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +14 -4
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +7 -3
- package/dist/form/form-submit.d.mts.map +1 -1
- package/dist/form/form-submit.mjs +11 -7
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/form/index.d.mts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/internal/{action-details.mjs → action/action-details.mjs} +1 -1
- package/dist/internal/action/action-details.mjs.map +1 -0
- package/dist/internal/{call-urgent-handler.mjs → action/call-urgent-handler.mjs} +5 -10
- package/dist/internal/action/call-urgent-handler.mjs.map +1 -0
- package/dist/internal/{report-dropped.mjs → action/report-dropped.mjs} +3 -21
- package/dist/internal/action/report-dropped.mjs.map +1 -0
- package/dist/internal/{use-action-trigger.mjs → action/use-action-trigger.mjs} +3 -2
- package/dist/internal/action/use-action-trigger.mjs.map +1 -0
- package/dist/internal/action/use-connected.mjs +24 -0
- package/dist/internal/action/use-connected.mjs.map +1 -0
- package/dist/internal/{use-controllable-action.mjs → action/use-controllable-action.mjs} +13 -28
- package/dist/internal/action/use-controllable-action.mjs.map +1 -0
- package/dist/internal/action/use-pure-trigger.mjs +34 -0
- package/dist/internal/action/use-pure-trigger.mjs.map +1 -0
- package/dist/internal/action/use-step-commit.mjs +147 -0
- package/dist/internal/action/use-step-commit.mjs.map +1 -0
- package/dist/internal/{field-context.d.mts → form/field-context.d.mts} +1 -1
- package/dist/internal/form/field-context.d.mts.map +1 -0
- package/dist/internal/{field-context.mjs → form/field-context.mjs} +2 -2
- package/dist/internal/form/field-context.mjs.map +1 -0
- package/dist/internal/{focus-first-invalid.mjs → form/focus-first-invalid.mjs} +3 -3
- package/dist/internal/form/focus-first-invalid.mjs.map +1 -0
- package/dist/internal/{form-status-watcher.mjs → form/form-status-watcher.mjs} +1 -1
- package/dist/internal/form/form-status-watcher.mjs.map +1 -0
- package/dist/internal/{group-member.mjs → form/group-member.mjs} +2 -2
- package/dist/internal/form/group-member.mjs.map +1 -0
- package/dist/internal/{sync-presence.mjs → form/sync-presence.mjs} +1 -1
- package/dist/internal/form/sync-presence.mjs.map +1 -0
- package/dist/internal/{use-checkable-input.mjs → form/use-checkable-input.mjs} +5 -5
- package/dist/internal/form/use-checkable-input.mjs.map +1 -0
- package/dist/internal/{use-field-control.mjs → form/use-field-control.mjs} +3 -3
- package/dist/internal/form/use-field-control.mjs.map +1 -0
- package/dist/internal/{use-fieldset-group.mjs → form/use-fieldset-group.mjs} +3 -3
- package/dist/internal/form/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/{use-form-owner-event.mjs → form/use-form-owner-event.mjs} +1 -1
- package/dist/internal/form/use-form-owner-event.mjs.map +1 -0
- package/dist/internal/{use-form-reset.mjs → form/use-form-reset.mjs} +15 -3
- package/dist/internal/form/use-form-reset.mjs.map +1 -0
- package/dist/internal/{use-native-checked.mjs → form/use-native-checked.mjs} +5 -4
- package/dist/internal/form/use-native-checked.mjs.map +1 -0
- package/dist/internal/{use-native-group-reconciliation.mjs → form/use-native-group-reconciliation.mjs} +2 -2
- package/dist/internal/form/use-native-group-reconciliation.mjs.map +1 -0
- package/dist/internal/{use-native-select-value.mjs → form/use-native-select-value.mjs} +2 -2
- package/dist/internal/form/use-native-select-value.mjs.map +1 -0
- package/dist/internal/{validity.d.mts → form/validity.d.mts} +1 -1
- package/dist/internal/form/validity.d.mts.map +1 -0
- package/dist/internal/{validity.mjs → form/validity.mjs} +1 -1
- package/dist/internal/form/validity.mjs.map +1 -0
- package/dist/internal/{anchor-position.d.mts → overlay/anchor-position.d.mts} +1 -1
- package/dist/internal/overlay/anchor-position.d.mts.map +1 -0
- package/dist/internal/{anchor-position.mjs → overlay/anchor-position.mjs} +1 -1
- package/dist/internal/overlay/anchor-position.mjs.map +1 -0
- package/dist/internal/{content-focus-probe.mjs → overlay/content-focus-probe.mjs} +1 -1
- package/dist/internal/overlay/content-focus-probe.mjs.map +1 -0
- package/dist/internal/{css-transition-cut.mjs → overlay/css-transition-cut.mjs} +1 -1
- package/dist/internal/overlay/css-transition-cut.mjs.map +1 -0
- package/dist/internal/{focus-visible.mjs → overlay/focus-visible.mjs} +1 -1
- package/dist/internal/overlay/focus-visible.mjs.map +1 -0
- package/dist/internal/{invokers.mjs → overlay/invokers.mjs} +1 -1
- package/dist/internal/overlay/invokers.mjs.map +1 -0
- package/dist/internal/{modal-registry.mjs → overlay/modal-registry.mjs} +1 -1
- package/dist/internal/overlay/modal-registry.mjs.map +1 -0
- package/dist/internal/{overlay-popup.mjs → overlay/overlay-popup.mjs} +3 -3
- package/dist/internal/overlay/overlay-popup.mjs.map +1 -0
- package/dist/internal/overlay/overlay-show.mjs +73 -0
- package/dist/internal/overlay/overlay-show.mjs.map +1 -0
- package/dist/internal/{popover-open.mjs → overlay/popover-open.mjs} +1 -1
- package/dist/internal/overlay/popover-open.mjs.map +1 -0
- package/dist/internal/{trigger-ref.mjs → overlay/trigger-ref.mjs} +1 -1
- package/dist/internal/overlay/trigger-ref.mjs.map +1 -0
- package/dist/internal/overlay/use-apply-open-state.mjs +44 -0
- package/dist/internal/overlay/use-apply-open-state.mjs.map +1 -0
- package/dist/internal/{use-exit-animation.mjs → overlay/use-exit-animation.mjs} +2 -2
- package/dist/internal/overlay/use-exit-animation.mjs.map +1 -0
- package/dist/internal/{use-interest-dismiss.mjs → overlay/use-interest-dismiss.mjs} +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -0
- package/dist/internal/{use-modal-registration.mjs → overlay/use-modal-registration.mjs} +1 -1
- package/dist/internal/overlay/use-modal-registration.mjs.map +1 -0
- package/dist/internal/{use-overlay-close.mjs → overlay/use-overlay-close.mjs} +14 -13
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -0
- package/dist/internal/overlay/use-overlay-root.d.mts +2 -0
- package/dist/internal/{use-overlay-root.mjs → overlay/use-overlay-root.mjs} +44 -28
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -0
- package/dist/internal/{use-popover-popup.mjs → overlay/use-popover-popup.mjs} +74 -66
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -0
- package/dist/internal/{use-popover-trigger.d.mts → overlay/use-popover-trigger.d.mts} +3 -3
- package/dist/internal/overlay/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/{use-popover-trigger.mjs → overlay/use-popover-trigger.mjs} +47 -26
- package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -0
- package/dist/internal/{use-resolved-placement.mjs → overlay/use-resolved-placement.mjs} +2 -2
- package/dist/internal/overlay/use-resolved-placement.mjs.map +1 -0
- package/dist/internal/render-element.mjs +47 -9
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +4 -8
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/use-mount-fixed.mjs +22 -0
- package/dist/internal/use-mount-fixed.mjs.map +1 -0
- package/dist/internal/use-register-count.mjs +4 -1
- package/dist/internal/use-register-count.mjs.map +1 -1
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/menu/menu-checkbox-item.mjs +2 -2
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +1 -1
- package/dist/menu/menu-gestures.mjs.map +1 -1
- package/dist/menu/menu-item.d.mts.map +1 -1
- package/dist/menu/menu-item.mjs +9 -10
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +1 -1
- package/dist/menu/menu-outside.mjs.map +1 -1
- package/dist/menu/menu-popup.d.mts +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +10 -6
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs +2 -2
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.mjs +2 -2
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +3 -3
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +1 -1
- package/dist/menu/menu-trigger.mjs +3 -3
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/number-field/number-field-input.mjs +1 -1
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +43 -107
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/popover/popover-close.mjs +3 -3
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-context.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +1 -1
- package/dist/popover/popover-popup.mjs +3 -3
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +2 -2
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +1 -1
- package/dist/popover/popover-trigger.mjs +1 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +3 -3
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +5 -5
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-group-label.d.mts.map +1 -1
- package/dist/select/select-group-label.mjs +3 -1
- package/dist/select/select-group-label.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-option.mjs.map +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +7 -7
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/select/select-trigger.d.mts.map +1 -1
- package/dist/select/select-trigger.mjs +3 -1
- package/dist/select/select-trigger.mjs.map +1 -1
- package/dist/select/select-value.mjs +3 -6
- package/dist/select/select-value.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +38 -104
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/use-thumb-registry.mjs.map +1 -1
- package/dist/switch/switch.mjs +1 -1
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-panel.mjs +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +4 -4
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/{internal → tabs}/use-until-found.mjs +1 -1
- package/dist/tabs/use-until-found.mjs.map +1 -0
- package/dist/toast/toast-action.d.mts +13 -3
- package/dist/toast/toast-action.d.mts.map +1 -1
- package/dist/toast/toast-action.mjs +23 -13
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts +13 -2
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +16 -6
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-root.mjs +1 -1
- package/dist/toast/toast-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +48 -143
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +1 -1
- package/dist/toast/use-modal-portal-host.mjs.map +1 -1
- package/dist/toast/use-toast-announcements.mjs +46 -0
- package/dist/toast/use-toast-announcements.mjs.map +1 -0
- package/dist/toast/use-toast-focus.mjs +75 -0
- package/dist/toast/use-toast-focus.mjs.map +1 -0
- package/dist/toast/use-toast-pauses.mjs +58 -0
- package/dist/toast/use-toast-pauses.mjs.map +1 -0
- package/dist/toggle/toggle.mjs +2 -2
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +5 -5
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-context.d.mts +1 -1
- package/dist/tooltip/tooltip-context.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +1 -1
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.d.mts.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +9 -4
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +1 -1
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/{internal → tooltip}/tooltip-warm.mjs +1 -1
- package/dist/tooltip/tooltip-warm.mjs.map +1 -0
- package/dist/tooltip/use-tooltip-interaction.mjs +2 -2
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/funstack-ui-knowledge/SKILL.md +1 -1
- package/dist/internal/action-details.mjs.map +0 -1
- package/dist/internal/anchor-position.d.mts.map +0 -1
- package/dist/internal/anchor-position.mjs.map +0 -1
- package/dist/internal/call-urgent-handler.mjs.map +0 -1
- package/dist/internal/content-focus-probe.mjs.map +0 -1
- package/dist/internal/css-transition-cut.mjs.map +0 -1
- package/dist/internal/field-context.d.mts.map +0 -1
- package/dist/internal/field-context.mjs.map +0 -1
- package/dist/internal/focus-first-invalid.mjs.map +0 -1
- package/dist/internal/focus-visible.mjs.map +0 -1
- package/dist/internal/form-status-watcher.mjs.map +0 -1
- package/dist/internal/group-member.mjs.map +0 -1
- package/dist/internal/invokers.mjs.map +0 -1
- package/dist/internal/modal-registry.mjs.map +0 -1
- package/dist/internal/overlay-popup.mjs.map +0 -1
- package/dist/internal/popover-open.mjs.map +0 -1
- package/dist/internal/report-dropped.mjs.map +0 -1
- package/dist/internal/sync-presence.mjs.map +0 -1
- package/dist/internal/tooltip-warm.mjs.map +0 -1
- package/dist/internal/trigger-ref.mjs.map +0 -1
- package/dist/internal/use-action-trigger.mjs.map +0 -1
- package/dist/internal/use-checkable-input.mjs.map +0 -1
- package/dist/internal/use-controllable-action.mjs.map +0 -1
- package/dist/internal/use-exit-animation.mjs.map +0 -1
- package/dist/internal/use-field-control.mjs.map +0 -1
- package/dist/internal/use-fieldset-group.mjs.map +0 -1
- package/dist/internal/use-form-owner-event.mjs.map +0 -1
- package/dist/internal/use-form-reset.mjs.map +0 -1
- package/dist/internal/use-interest-dismiss.mjs.map +0 -1
- package/dist/internal/use-modal-registration.mjs.map +0 -1
- package/dist/internal/use-native-checked.mjs.map +0 -1
- package/dist/internal/use-native-group-reconciliation.mjs.map +0 -1
- package/dist/internal/use-native-select-value.mjs.map +0 -1
- package/dist/internal/use-overlay-close.mjs.map +0 -1
- package/dist/internal/use-overlay-root.d.mts +0 -2
- package/dist/internal/use-overlay-root.mjs.map +0 -1
- package/dist/internal/use-popover-popup.mjs.map +0 -1
- package/dist/internal/use-popover-trigger.d.mts.map +0 -1
- package/dist/internal/use-popover-trigger.mjs.map +0 -1
- package/dist/internal/use-resolved-placement.mjs.map +0 -1
- package/dist/internal/use-until-found.mjs.map +0 -1
- package/dist/internal/validity.d.mts.map +0 -1
- package/dist/internal/validity.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tooltip-interaction.mjs","names":[],"sources":["../../src/tooltip/use-tooltip-interaction.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useEffectEvent } from \"react\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { syncPresence } from \"../internal/sync-presence.js\";\nimport { createDelayedPair } from \"../internal/use-delayed-pair.js\";\n\nexport interface TooltipInteractionOptions {\n readonly delay: number;\n readonly closeDelay: number;\n readonly disabled: boolean;\n /** The Trigger renders `interestfor` (flag on and not disabled). Re-runs the detection. */\n readonly interestForRequested: boolean;\n}\n\n/**\n * The cross-engine JS path of design section 2.2: hover / keyboard focus with delays,\n * `showPopover({ source })`, Escape and pointerdown-anywhere. Listeners go through\n * `addEventListener` (conventions 7.4) so they can be feature-detected away: where the trigger\n * renders `interestfor` and the element implements `interestForElement`, the browser owns the\n * whole interaction and nothing is attached.\n *\n * Open state is browser-owned (conventions 3.5): every decision reads\n * `popup.matches(\":popover-open\")`, never a copy. The document listeners are attached right after\n * `showPopover()` (the `toggle` event is queued as a task, so waiting for it would leave a window\n * in which an Escape or pointerdown does nothing) and detached when `toggle` reports a close,\n * including closes the library did not perform (native light dismiss of `popover=\"hint\"`).\n *\n * Skip-delay (design 6): while another tooltip is showing anywhere in the document\n * (`[role=\"tooltip\"]:popover-open`, FUNSTACK's or not), a hover or keyboard focus hides it and\n * opens this one at once. Stateless: the DOM is read at the start of each hover or focus.\n *\n * Warm opens (design, \"Amendment: warm opens\"): on **both** paths one `beforetoggle` listener on\n * the popup writes `data-instant` by presence: on an open, iff another tooltip is showing at that\n * moment (the skip-delay condition); on a close, never. `beforetoggle` is synchronous and precedes\n * the top-layer insertion, so the open's first style recalc already sees the attribute and\n * `.tip[data-instant] { transition: none }` creates no transition (a later write would start and\n * cancel one). A DOM write, never React state (conventions 7.4). This hook's only listener on the\n * native path (the popup also has `useResolvedPlacement`'s `toggle`); it handles and cancels\n * nothing.\n */\nexport function useTooltipInteraction(\n trigger: HTMLElement | null,\n popup: HTMLElement | null,\n options: TooltipInteractionOptions,\n): void {\n const getDelays = useEffectEvent(() => ({\n delay: options.delay,\n closeDelay: options.closeDelay,\n }));\n const { disabled, interestForRequested } = options;\n\n useEffect(() => {\n if (popup === null) return;\n // Attached before the `disabled` and native-path branches and removed last, so every open and\n // close (the library's below, the browser's, a consumer's through the ref) passes through it.\n const onBeforeToggle = (event: Event) => {\n const opening = (event as ToggleEvent).newState === \"open\";\n syncPresence(\n popup,\n \"data-instant\",\n opening && otherOpenTooltip(popup.ownerDocument, popup) !== null,\n );\n };\n popup.addEventListener(\"beforetoggle\", onBeforeToggle);\n // The effect event is called (from the timers this effect sets up), never passed itself.\n const detach = attachInteraction(trigger, popup, disabled, interestForRequested, () =>\n getDelays(),\n );\n return () => {\n detach?.();\n popup.removeEventListener(\"beforetoggle\", onBeforeToggle);\n };\n }, [trigger, popup, disabled, interestForRequested]);\n}\n\n/**\n * The rest of the effect: the JS path's interaction listeners, or nothing (disabled, no trigger,\n * the native path). Returns their cleanup, which hides an open popup first.\n */\nfunction attachInteraction(\n trigger: HTMLElement | null,\n popup: HTMLElement,\n disabled: boolean,\n interestForRequested: boolean,\n getDelays: () => { delay: number; closeDelay: number },\n): (() => void) | undefined {\n // Disabling while open hides the popup on both paths (design section 13, Disabled row). On the\n // JS path the previous run's cleanup already did; on the native path nothing else would, and\n // removing `interestfor` does not close an open popover.\n if (disabled) {\n if (isOpen(popup)) popup.hidePopover();\n return;\n }\n if (trigger === null) return;\n // Native path (conventions 8): only when the flag put `interestfor` on the element, and per\n // element, so a `render`ed `<span>` (no `interestForElement`) keeps the JS path. No\n // interaction listener is attached here (only the caller's `beforetoggle`), Escape included:\n // the browser's interest handling and the `hint` close watcher decide, so in Chromium an Escape\n // that closes the tooltip may also close an enclosing modal `<dialog>` (the library cannot\n // `preventDefault()` a keydown it never sees).\n if (\n interestForRequested &&\n trigger.hasAttribute(\"interestfor\") &&\n \"interestForElement\" in trigger\n ) {\n return;\n }\n\n const doc = trigger.ownerDocument;\n // One pending open or close at a time (the timer helper shared with Menu's hover intent).\n const timers = createDelayedPair();\n const clear = timers.cancel;\n const show = () => {\n if (isOpen(popup) || !popup.isConnected || !trigger.isConnected) return;\n popup.showPopover({ source: trigger });\n listenDocument(true);\n };\n const hide = () => {\n // A removed popover is already hidden (`isOpen` is false), so this never throws.\n if (!isOpen(popup)) return;\n popup.hidePopover();\n listenDocument(false);\n };\n const showLater = () => {\n timers.open(getDelays().delay, show);\n };\n const hideLater = () => {\n timers.close(getDelays().closeDelay, hide);\n };\n const hideNow = () => {\n clear();\n hide();\n };\n // Another tooltip is showing: open now and hide it, else wait `delay` (design 6). Show first,\n // so this popup's `beforetoggle` still sees the other one open (`data-instant`): the DOM of\n // the native path, where `hint` stacking hides it inside `showPopover` after `beforetoggle`.\n // With `hint` here too that already happened and the guard skips the call. The other Root\n // sees its `toggle` and detaches; its pending close timer finds it closed.\n const showSoon = () => {\n const other = isOpen(popup) ? null : otherOpenTooltip(doc, popup);\n if (other === null) {\n showLater();\n return;\n }\n clear();\n show();\n if (isOpen(other)) other.hidePopover();\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n clear();\n // Escape while closed passes through untouched.\n if (!isOpen(popup)) return;\n hide();\n // This Escape was the tooltip's: an enclosing modal `<dialog>` or `popover=\"auto\"` menu\n // stays open (the close request sees a canceled keydown). A second Escape reaches them.\n event.preventDefault();\n };\n function listenDocument(listen: boolean) {\n if (listen) {\n doc.addEventListener(\"keydown\", onKeyDown);\n doc.addEventListener(\"pointerdown\", hideNow, true);\n } else {\n doc.removeEventListener(\"keydown\", onKeyDown);\n doc.removeEventListener(\"pointerdown\", hideNow, true);\n }\n }\n // Follows opens and closes the library did not perform; reads the DOM, not `newState`, so a\n // toggle task that is stale by the time it runs cannot detach the listeners of an open popup.\n const onToggle = () => {\n listenDocument(isOpen(popup));\n };\n const onTriggerEnter = (event: PointerEvent) => {\n // No hover on touch; the ARIA relation still works for screen-reader focus (design 5.3).\n if (event.pointerType !== \"touch\") showSoon();\n };\n const onTriggerFocus = () => {\n // Pointer focus (a click) does not open; keyboard focus does (design 5.2).\n if (trigger.matches(\":focus-visible\")) showSoon();\n };\n // The document listeners exist only while the popup is open, so before that the trigger\n // itself cancels a pending open: a click or Escape before `delay` elapses must not open the\n // tooltip afterwards. Once open, the document listeners do the hiding.\n const onTriggerKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") clear();\n };\n\n trigger.addEventListener(\"pointerenter\", onTriggerEnter);\n trigger.addEventListener(\"pointerleave\", hideLater);\n trigger.addEventListener(\"pointerdown\", clear);\n trigger.addEventListener(\"keydown\", onTriggerKeyDown);\n trigger.addEventListener(\"focus\", onTriggerFocus);\n trigger.addEventListener(\"blur\", hideLater);\n popup.addEventListener(\"pointerenter\", clear);\n popup.addEventListener(\"pointerleave\", hideLater);\n popup.addEventListener(\"toggle\", onToggle);\n\n return () => {\n hideNow();\n listenDocument(false);\n trigger.removeEventListener(\"pointerenter\", onTriggerEnter);\n trigger.removeEventListener(\"pointerleave\", hideLater);\n trigger.removeEventListener(\"pointerdown\", clear);\n trigger.removeEventListener(\"keydown\", onTriggerKeyDown);\n trigger.removeEventListener(\"focus\", onTriggerFocus);\n trigger.removeEventListener(\"blur\", hideLater);\n popup.removeEventListener(\"pointerenter\", clear);\n popup.removeEventListener(\"pointerleave\", hideLater);\n popup.removeEventListener(\"toggle\", onToggle);\n };\n}\n\n/**\n * A tooltip popover other than `popup` that is showing in the document, or `null` (the warm\n * condition of design 6, the same one the native path's `:root:has()` rule reads). Walks the\n * tooltip popovers and asks each for `:popover-open` rather than one `querySelector`, which the\n * jsdom shim could not answer.\n */\nfunction otherOpenTooltip(doc: Document, popup: HTMLElement): HTMLElement | null {\n for (const element of doc.querySelectorAll<HTMLElement>('[role=\"tooltip\"][popover]')) {\n if (element !== popup && isOpen(element)) return element;\n }\n return null;\n}\n\n/** The popover's top-layer state, read from the DOM. A removed popover is never open. */\nfunction isOpen(popup: HTMLElement): boolean {\n return popup.isConnected && isPopoverOpen(popup);\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"use-tooltip-interaction.mjs","names":[],"sources":["../../src/tooltip/use-tooltip-interaction.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useEffectEvent } from \"react\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport { syncPresence } from \"../internal/form/sync-presence.js\";\nimport { createDelayedPair } from \"../internal/use-delayed-pair.js\";\n\nexport interface TooltipInteractionOptions {\n readonly delay: number;\n readonly closeDelay: number;\n readonly disabled: boolean;\n /** The Trigger renders `interestfor` (flag on and not disabled). Re-runs the detection. */\n readonly interestForRequested: boolean;\n}\n\n/**\n * The cross-engine JS path of design section 2.2: hover / keyboard focus with delays,\n * `showPopover({ source })`, Escape and pointerdown-anywhere. Listeners go through\n * `addEventListener` (conventions 7.4) so they can be feature-detected away: where the trigger\n * renders `interestfor` and the element implements `interestForElement`, the browser owns the\n * whole interaction and nothing is attached.\n *\n * Open state is browser-owned (conventions 3.5): every decision reads\n * `popup.matches(\":popover-open\")`, never a copy. The document listeners are attached right after\n * `showPopover()` (the `toggle` event is queued as a task, so waiting for it would leave a window\n * in which an Escape or pointerdown does nothing) and detached when `toggle` reports a close,\n * including closes the library did not perform (native light dismiss of `popover=\"hint\"`).\n *\n * Skip-delay (design 6): while another tooltip is showing anywhere in the document\n * (`[role=\"tooltip\"]:popover-open`, FUNSTACK's or not), a hover or keyboard focus hides it and\n * opens this one at once. Stateless: the DOM is read at the start of each hover or focus.\n *\n * Warm opens (design, \"Amendment: warm opens\"): on **both** paths one `beforetoggle` listener on\n * the popup writes `data-instant` by presence: on an open, iff another tooltip is showing at that\n * moment (the skip-delay condition); on a close, never. `beforetoggle` is synchronous and precedes\n * the top-layer insertion, so the open's first style recalc already sees the attribute and\n * `.tip[data-instant] { transition: none }` creates no transition (a later write would start and\n * cancel one). A DOM write, never React state (conventions 7.4). This hook's only listener on the\n * native path (the popup also has `useResolvedPlacement`'s `toggle`); it handles and cancels\n * nothing.\n */\nexport function useTooltipInteraction(\n trigger: HTMLElement | null,\n popup: HTMLElement | null,\n options: TooltipInteractionOptions,\n): void {\n const getDelays = useEffectEvent(() => ({\n delay: options.delay,\n closeDelay: options.closeDelay,\n }));\n const { disabled, interestForRequested } = options;\n\n useEffect(() => {\n if (popup === null) return;\n // Attached before the `disabled` and native-path branches and removed last, so every open and\n // close (the library's below, the browser's, a consumer's through the ref) passes through it.\n const onBeforeToggle = (event: Event) => {\n const opening = (event as ToggleEvent).newState === \"open\";\n syncPresence(\n popup,\n \"data-instant\",\n opening && otherOpenTooltip(popup.ownerDocument, popup) !== null,\n );\n };\n popup.addEventListener(\"beforetoggle\", onBeforeToggle);\n // The effect event is called (from the timers this effect sets up), never passed itself.\n const detach = attachInteraction(trigger, popup, disabled, interestForRequested, () =>\n getDelays(),\n );\n return () => {\n detach?.();\n popup.removeEventListener(\"beforetoggle\", onBeforeToggle);\n };\n }, [trigger, popup, disabled, interestForRequested]);\n}\n\n/**\n * The rest of the effect: the JS path's interaction listeners, or nothing (disabled, no trigger,\n * the native path). Returns their cleanup, which hides an open popup first.\n */\nfunction attachInteraction(\n trigger: HTMLElement | null,\n popup: HTMLElement,\n disabled: boolean,\n interestForRequested: boolean,\n getDelays: () => { delay: number; closeDelay: number },\n): (() => void) | undefined {\n // Disabling while open hides the popup on both paths (design section 13, Disabled row). On the\n // JS path the previous run's cleanup already did; on the native path nothing else would, and\n // removing `interestfor` does not close an open popover.\n if (disabled) {\n if (isOpen(popup)) popup.hidePopover();\n return;\n }\n if (trigger === null) return;\n // Native path (conventions 8): only when the flag put `interestfor` on the element, and per\n // element, so a `render`ed `<span>` (no `interestForElement`) keeps the JS path. No\n // interaction listener is attached here (only the caller's `beforetoggle`), Escape included:\n // the browser's interest handling and the `hint` close watcher decide, so in Chromium an Escape\n // that closes the tooltip may also close an enclosing modal `<dialog>` (the library cannot\n // `preventDefault()` a keydown it never sees).\n if (\n interestForRequested &&\n trigger.hasAttribute(\"interestfor\") &&\n \"interestForElement\" in trigger\n ) {\n return;\n }\n\n const doc = trigger.ownerDocument;\n // One pending open or close at a time (the timer helper shared with Menu's hover intent).\n const timers = createDelayedPair();\n const clear = timers.cancel;\n const show = () => {\n if (isOpen(popup) || !popup.isConnected || !trigger.isConnected) return;\n popup.showPopover({ source: trigger });\n listenDocument(true);\n };\n const hide = () => {\n // A removed popover is already hidden (`isOpen` is false), so this never throws.\n if (!isOpen(popup)) return;\n popup.hidePopover();\n listenDocument(false);\n };\n const showLater = () => {\n timers.open(getDelays().delay, show);\n };\n const hideLater = () => {\n timers.close(getDelays().closeDelay, hide);\n };\n const hideNow = () => {\n clear();\n hide();\n };\n // Another tooltip is showing: open now and hide it, else wait `delay` (design 6). Show first,\n // so this popup's `beforetoggle` still sees the other one open (`data-instant`): the DOM of\n // the native path, where `hint` stacking hides it inside `showPopover` after `beforetoggle`.\n // With `hint` here too that already happened and the guard skips the call. The other Root\n // sees its `toggle` and detaches; its pending close timer finds it closed.\n const showSoon = () => {\n const other = isOpen(popup) ? null : otherOpenTooltip(doc, popup);\n if (other === null) {\n showLater();\n return;\n }\n clear();\n show();\n if (isOpen(other)) other.hidePopover();\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n clear();\n // Escape while closed passes through untouched.\n if (!isOpen(popup)) return;\n hide();\n // This Escape was the tooltip's: an enclosing modal `<dialog>` or `popover=\"auto\"` menu\n // stays open (the close request sees a canceled keydown). A second Escape reaches them.\n event.preventDefault();\n };\n function listenDocument(listen: boolean) {\n if (listen) {\n doc.addEventListener(\"keydown\", onKeyDown);\n doc.addEventListener(\"pointerdown\", hideNow, true);\n } else {\n doc.removeEventListener(\"keydown\", onKeyDown);\n doc.removeEventListener(\"pointerdown\", hideNow, true);\n }\n }\n // Follows opens and closes the library did not perform; reads the DOM, not `newState`, so a\n // toggle task that is stale by the time it runs cannot detach the listeners of an open popup.\n const onToggle = () => {\n listenDocument(isOpen(popup));\n };\n const onTriggerEnter = (event: PointerEvent) => {\n // No hover on touch; the ARIA relation still works for screen-reader focus (design 5.3).\n if (event.pointerType !== \"touch\") showSoon();\n };\n const onTriggerFocus = () => {\n // Pointer focus (a click) does not open; keyboard focus does (design 5.2).\n if (trigger.matches(\":focus-visible\")) showSoon();\n };\n // The document listeners exist only while the popup is open, so before that the trigger\n // itself cancels a pending open: a click or Escape before `delay` elapses must not open the\n // tooltip afterwards. Once open, the document listeners do the hiding.\n const onTriggerKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") clear();\n };\n\n trigger.addEventListener(\"pointerenter\", onTriggerEnter);\n trigger.addEventListener(\"pointerleave\", hideLater);\n trigger.addEventListener(\"pointerdown\", clear);\n trigger.addEventListener(\"keydown\", onTriggerKeyDown);\n trigger.addEventListener(\"focus\", onTriggerFocus);\n trigger.addEventListener(\"blur\", hideLater);\n popup.addEventListener(\"pointerenter\", clear);\n popup.addEventListener(\"pointerleave\", hideLater);\n popup.addEventListener(\"toggle\", onToggle);\n\n return () => {\n hideNow();\n listenDocument(false);\n trigger.removeEventListener(\"pointerenter\", onTriggerEnter);\n trigger.removeEventListener(\"pointerleave\", hideLater);\n trigger.removeEventListener(\"pointerdown\", clear);\n trigger.removeEventListener(\"keydown\", onTriggerKeyDown);\n trigger.removeEventListener(\"focus\", onTriggerFocus);\n trigger.removeEventListener(\"blur\", hideLater);\n popup.removeEventListener(\"pointerenter\", clear);\n popup.removeEventListener(\"pointerleave\", hideLater);\n popup.removeEventListener(\"toggle\", onToggle);\n };\n}\n\n/**\n * A tooltip popover other than `popup` that is showing in the document, or `null` (the warm\n * condition of design 6, the same one the native path's `:root:has()` rule reads). Walks the\n * tooltip popovers and asks each for `:popover-open` rather than one `querySelector`, which the\n * jsdom shim could not answer.\n */\nfunction otherOpenTooltip(doc: Document, popup: HTMLElement): HTMLElement | null {\n for (const element of doc.querySelectorAll<HTMLElement>('[role=\"tooltip\"][popover]')) {\n if (element !== popup && isOpen(element)) return element;\n }\n return null;\n}\n\n/** The popover's top-layer state, read from the DOM. A removed popover is never open. */\nfunction isOpen(popup: HTMLElement): boolean {\n return popup.isConnected && isPopoverOpen(popup);\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ Requirements: `react` and `react-dom` `>=19.3.0` (peer dependencies). ESM only.
|
|
|
14
14
|
- **Action props, not event handlers.** Interactive props are named `action` or `fooAction` (`pressedChangeAction`, `valueChangeAction`, `openChangeAction`, `checkedChangeAction`). The component calls them inside its own React transition and awaits a returned promise. Change actions (`xChangeAction`) take `(next, details)`; task actions (`action` on `Button`, `Menu.Item`, `Dialog.Close`, `Popover.Close`, `Toast.Action`) take only `(details)`, so write `action={() => save()}`, not `action={(next) => ...}`. The return type is `unknown`. `details.event` is the native DOM event; `details.reason` (where present) is `"activate" | "platform" | "dismiss" | "timeout"`.
|
|
15
15
|
- **State triple.** A controllable state `x` comes as `x` (controlled), `defaultX` (uncontrolled initial value) and `xChangeAction`. `undefined` means uncontrolled; "nothing selected" is `null`. Do not switch between controlled and uncontrolled after mount.
|
|
16
16
|
- **Optimistic and pending are built in.** While an action is pending, triggers (the parts the user acts on) already show the new value, and the state owner (usually the `Root`) and the trigger carry `data-pending`. If the action rejects, the value rolls back and the error goes to the nearest Error Boundary. Uncontrolled state is written only after success.
|
|
17
|
-
- **Latest intent wins, for uncontrolled state.** A second click while pending is a new intent: the optimistic display follows it, and uncontrolled state commits only the most recent dispatch (set-valued state, `CheckboxGroup` and non-`exclusive` `ToggleGroup` / `Accordion`, commits every change whose action resolved, in order, and leaves out one whose action rejected; a later action's `next` still includes an earlier pending change, so persist `details.added` / `details.removed`, not the whole `next`; exception: a `CheckboxGroup` form reset, `reason: "platform"` with `details.event?.type === "reset"`, is absolute, so persist its `next` whole, its `added` / `removed` can be empty; to keep saves from overlapping at all, queue them with React's `useActionState`). The rejection of an older action that a newer one superseded does not reach the Error Boundary (as with React's own `useTransition`); the library passes it to the global `reportError`, so it fires the window `error` event and fails a test run that does not stub `reportError`. The same goes for a rejection that arrives after its component unmounted (a toast or menu closed while its action ran) or while `<Activity>` hides it. In controlled mode, your own `setState` after an `await` lands in completion order, so an older response can overwrite a newer one; guard it yourself or queue the calls with React's `useActionState`. A pure trigger (a part that runs a task: `Button`, `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`) has no value to protect; what a click while its own action is pending does is its `whilePending` prop (`"run" | "ignore"`, type `WhilePending`). `"run"` runs the action again (runs overlap; `data-pending` until the last settles, no `aria-disabled`; an older run's rejection goes to `reportError`); `"ignore"` drops the click, cancels its default action and renders `aria-disabled="true"` while pending. Defaults: `Button` `"run"` (put `whilePending="ignore"` on a Save, Pay or Delete, and on a `formAction` submitter that must not submit twice: React drops an older overlapping submission's rejection); Close parts `"ignore"`; `Menu.Item` and `Toast.Action` `"ignore"`, but `"run"` with `closeOnActivate={false}` / `closeOnSettle={false}`. Parts are never natively disabled while pending.
|
|
17
|
+
- **Latest intent wins, for uncontrolled state.** A second click while pending is a new intent: the optimistic display follows it, and uncontrolled state commits only the most recent dispatch (set-valued state, `CheckboxGroup` and non-`exclusive` `ToggleGroup` / `Accordion`, commits every change whose action resolved, in order, and leaves out one whose action rejected; a later action's `next` still includes an earlier pending change, so persist `details.added` / `details.removed`, not the whole `next`; exception: a `CheckboxGroup` form reset, `reason: "platform"` with `details.event?.type === "reset"`, is absolute, so persist its `next` whole, its `added` / `removed` can be empty; to keep saves from overlapping at all, queue them with React's `useActionState`). The rejection of an older action that a newer one superseded does not reach the Error Boundary (as with React's own `useTransition`); the library passes it to the global `reportError`, so it fires the window `error` event and fails a test run that does not stub `reportError`. The same goes for a rejection that arrives after its component unmounted (a toast or menu closed while its action ran) or while `<Activity>` hides it. In controlled mode, your own `setState` after an `await` lands in completion order, so an older response can overwrite a newer one; guard it yourself or queue the calls with React's `useActionState`. A pure trigger (a part that runs a task: `Button`, `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`) has no value to protect; what a click while its own action is pending does is its `whilePending` prop (`"run" | "ignore"`, type `WhilePending`). `"run"` runs the action again (runs overlap; `data-pending` until the last settles, no `aria-disabled`; an older run's rejection goes to `reportError`); `"ignore"` drops the click, cancels its default action and renders `aria-disabled="true"` while pending (not while you have it natively `disabled`: native `disabled` wins). Defaults: `Button` `"run"` (put `whilePending="ignore"` on a Save, Pay or Delete, and on a `formAction` submitter that must not submit twice: React drops an older overlapping submission's rejection); Close parts `"ignore"`; `Menu.Item` and `Toast.Action` `"ignore"`, but `"run"` with `closeOnActivate={false}` / `closeOnSettle={false}`. Parts are never natively disabled while pending.
|
|
18
18
|
- **Content regions show the committed value.** Panels and popup content follow the committed state, so content that suspends keeps the old content on screen until it is ready (with value or open props, an Accordion item, Dialog or Popover stays closed until then; without them their content is rendered ahead and must not suspend). The library never adds `<Suspense>` and has no `fallback` props; you place boundaries.
|
|
19
19
|
- **`transition` prop = `<ViewTransition>`.** Parts whose content is driven by library state accept `transition`; passing it wraps the part in `<ViewTransition default={transition}>`. Without it, no boundary is rendered. Each dispatch is tagged with `fsui-<component>` transition types (for example `fsui-tabs-next`), usable in a type map or `:active-view-transition-type()`. On a popup (`Dialog`, `Popover`, `Menu`, `Combobox`), write a CSS exit for dismissals next to `transition`: the library turns the popup's CSS transitions off for the moment of its own show or hide while a view transition runs, so an `html:active-view-transition .popup { transition: none }` rule (older docs needed one) is not needed: remove it (keeping it is harmless, but it also cuts a dismissal's fade during an unrelated view transition). Only CSS transitions are cut: write the popup's exit as a `transition`, not a `@keyframes` animation.
|
|
20
20
|
- **Browser-owned state.** Where the platform owns the state (popover top layer, `<details open>`, `<dialog>` dismissal, native inputs), the library observes it instead of copying it. Escape and click-outside are browser dismissals, **facts**: they are not passed to `openChangeAction` (requests only) but to `onOpenChange(false, details)`, called synchronously, not awaited, never pending, and they cannot be vetoed. A controlled overlay therefore takes both: `open={open} openChangeAction={setOpen} onOpenChange={setOpen}` (set state directly in `onOpenChange`, never in `startTransition` or after an `await`; a parent that keeps `open={true}` re-opens it).
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"action-details.mjs","names":[],"sources":["../../src/internal/action-details.ts"],"sourcesContent":["import type { ActionDetails } from \"./types.js\";\n\nfunction isDev(): boolean {\n return process.env.NODE_ENV !== \"production\";\n}\n\nfunction rejectEventWrite(): never {\n throw new TypeError(\n \"`details.event` is a read-only virtual property; it cannot be assigned or defined. \" +\n \"Keep the DOM event out of `details` so that it stays serialisable.\",\n );\n}\n\n/**\n * Builds the `details` argument of an action (conventions 2.2).\n *\n * `fields` is a plain, extensible object of serialisable component-specific fields. `event` is a\n * virtual, non-own property served by a Proxy: `details.event` and `\"event\" in details` work,\n * while `Object.keys`, spread, `JSON.stringify` and React's Server Function serialiser see only\n * the real fields. That is what lets a Server Function be passed directly as an action.\n *\n * Writing `event` (`details.event = x`, `Object.defineProperty(details, \"event\", ...)`) is\n * rejected so that an own, enumerable `event` can never appear: in development it throws a\n * `TypeError`; in production an assignment is ignored and a `defineProperty` is declined (which\n * makes `Object.defineProperty` throw and `Reflect.defineProperty` return `false`).\n *\n * No `\"use client\"` directive: this file uses no client-only API, so it is importable from\n * anywhere (conventions 7.1).\n */\nexport function createActionDetails<T extends object>(\n event: Event | undefined,\n fields: T,\n): T & ActionDetails {\n return new Proxy(fields, {\n get: (target, key, receiver) => (key === \"event\" ? event : Reflect.get(target, key, receiver)),\n has: (target, key) => key === \"event\" || Reflect.has(target, key),\n set: (target, key, value, receiver) => {\n if (key === \"event\") {\n if (isDev()) rejectEventWrite();\n return true;\n }\n return Reflect.set(target, key, value, receiver);\n },\n defineProperty: (target, key, descriptor) => {\n if (key === \"event\") {\n if (isDev()) rejectEventWrite();\n return false;\n }\n return Reflect.defineProperty(target, key, descriptor);\n },\n }) as T & ActionDetails;\n}\n"],"mappings":";AAEA,SAAS,QAAiB;CACxB,OAAO,QAAQ,IAAI,aAAa;AAClC;AAEA,SAAS,mBAA0B;CACjC,MAAM,IAAI,UACR,uJAEF;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,oBACd,OACA,QACmB;CACnB,OAAO,IAAI,MAAM,QAAQ;EACvB,MAAM,QAAQ,KAAK,aAAc,QAAQ,UAAU,QAAQ,QAAQ,IAAI,QAAQ,KAAK,QAAQ;EAC5F,MAAM,QAAQ,QAAQ,QAAQ,WAAW,QAAQ,IAAI,QAAQ,GAAG;EAChE,MAAM,QAAQ,KAAK,OAAO,aAAa;GACrC,IAAI,QAAQ,SAAS;IACnB,IAAI,MAAM,GAAG,iBAAiB;IAC9B,OAAO;GACT;GACA,OAAO,QAAQ,IAAI,QAAQ,KAAK,OAAO,QAAQ;EACjD;EACA,iBAAiB,QAAQ,KAAK,eAAe;GAC3C,IAAI,QAAQ,SAAS;IACnB,IAAI,MAAM,GAAG,iBAAiB;IAC9B,OAAO;GACT;GACA,OAAO,QAAQ,eAAe,QAAQ,KAAK,UAAU;EACvD;CACF,CAAC;AACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anchor-position.d.mts","names":[],"sources":["../../src/internal/anchor-position.ts"],"mappings":";;YAcY;;;;;YAKA,aAAa;;;;;YAKb"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anchor-position.mjs","names":[],"sources":["../../src/internal/anchor-position.ts"],"sourcesContent":["// Placement of a popover against its implicit anchor (the invoker set by `popovertarget`, `commandfor`,\n// `interestfor` or `showPopover({ source })`): inline `position-area` from a side and an\n// alignment, plus `position-try-fallbacks` that flip it when it does not fit; and the parser that\n// reads back which option the browser applied. Shared by Tooltip, Popover and Menu\n// (design/conventions.md 13; design/components/tooltip.md 7.1, popover.md 8).\n//\n// Keyword policy (conventions 13.1): physical keywords and the `self-*` group only. A plain\n// logical keyword (`block-end`, `span-inline-end`) on a top-layer popup resolves against the\n// root's writing mode, so it would ignore a `dir=\"rtl\"` container; `self-x-*` resolves against the\n// popup's own (inherited) direction. Keyword groups are never mixed in one value.\n//\n// No \"use client\" directive: pure functions, importable from anywhere (conventions 7.1).\n\n/** A physical side of the anchor. */\nexport type PhysicalSide = \"top\" | \"bottom\" | \"left\" | \"right\";\n/**\n * Side of the anchor the popup is placed on: physical, or inline-logical (`inline-start` /\n * `inline-end` follow the popup's own `direction` through the `self-x-*` keywords).\n */\nexport type AnchorSide = PhysicalSide | \"inline-start\" | \"inline-end\";\n/**\n * Alignment along that side: inline-relative on a `top` / `bottom` side (`start`: the popup's\n * inline-start edge meets the anchor's), the top / bottom edges on the others.\n */\nexport type AnchorAlign = \"start\" | \"center\" | \"end\";\n/** A computed `direction`. */\nexport type Direction = \"ltr\" | \"rtl\";\n\n/** Flip to the opposite side, then the other axis, then both, when the popup does not fit. */\nexport const POSITION_TRY_FALLBACKS = \"flip-block, flip-inline, flip-block flip-inline\";\n\nconst SIDE_KEYWORD: Record<AnchorSide, string> = {\n top: \"top\",\n bottom: \"bottom\",\n left: \"left\",\n right: \"right\",\n \"inline-start\": \"self-x-start\",\n \"inline-end\": \"self-x-end\",\n};\n\n/**\n * The `position-area` for a side and an alignment (the matrix of conventions 13.1):\n * `bottom` + `center` is `bottom`, `bottom` + `start` is `bottom span-self-x-end`, `right` +\n * `start` is `right span-bottom`, `inline-end` + `start` is `self-x-end span-bottom`.\n */\nexport function positionArea(side: AnchorSide, align: AnchorAlign): string {\n const keyword = SIDE_KEYWORD[side];\n if (align === \"center\") return keyword;\n const horizontal = side === \"top\" || side === \"bottom\";\n const span = horizontal\n ? align === \"start\"\n ? \"span-self-x-end\"\n : \"span-self-x-start\"\n : align === \"start\"\n ? \"span-bottom\"\n : \"span-top\";\n return `${keyword} ${span}`;\n}\n\n// --- Reading back the applied option (conventions 13.2) --------------------------------------\n\n/** Where the browser placed a popup: a physical side and the alignment along it. */\nexport interface ResolvedPlacement {\n readonly side: PhysicalSide;\n readonly align: AnchorAlign;\n}\n\ntype Axis = \"x\" | \"y\";\n\ninterface Token {\n /** `side`: the cell is on that side; `span`: spans toward a direction; `neutral`: neither. */\n readonly kind: \"side\" | \"span\" | \"neutral\";\n /** The physical direction of a `side` or `span` token. */\n readonly physical: PhysicalSide | null;\n}\n\nconst AXIS_OF: Record<PhysicalSide, Axis> = { top: \"y\", bottom: \"y\", left: \"x\", right: \"x\" };\n\n/**\n * Parses a computed `position-area` (conventions 13.2) into the physical side the popup sits on\n * and its alignment. Total: anything it cannot map returns `null` (`none`, an empty value, a\n * vertical `writing-mode`, a corner cell, the cell over the anchor, an unknown keyword), and the\n * part keeps the requested values. The engines serialise in grammar order, in any keyword group:\n * `span-left top`, `span-all bottom` (Firefox's form of a flipped `bottom`), `self-end\n * span-self-end`, `span-self-x-end bottom`, `self-x-start span-top`.\n *\n * `selfDirection` is the popup's computed `direction` (it resolves `self-*` tokens);\n * `rootDirection` the root's (plain `x-*` / `inline-*` tokens, which a consumer `style` override\n * may use), passed as a function so it is read only when such a token appears.\n */\nexport function parsePositionArea(\n value: string | null | undefined,\n selfDirection: Direction,\n rootDirection: Direction | (() => Direction),\n writingMode: string = \"horizontal-tb\",\n): ResolvedPlacement | null {\n if (writingMode !== \"horizontal-tb\" || typeof value !== \"string\") return null;\n const words = value.trim().split(/\\s+/);\n if (words.length > 2 || words[0] === \"\" || words[0] === \"none\") return null;\n let root: Direction | undefined;\n const rootDir = (): Direction =>\n (root ??= typeof rootDirection === \"function\" ? rootDirection() : rootDirection);\n\n const tokens: Token[] = [];\n for (let index = 0; index < words.length; index++) {\n const token = classify(words[index]!, index, words.length, selfDirection, rootDir);\n if (token === null) return null;\n tokens.push(token);\n }\n\n const sides = tokens.filter((t) => t.kind === \"side\");\n // No side (the cell over the anchor) or two (a corner): not a placement of the table.\n if (sides.length !== 1) return null;\n const side = sides[0]!.physical!;\n const span = tokens.find((t) => t.kind === \"span\");\n if (span === undefined) return { side, align: \"center\" };\n const toward = span.physical!;\n if (AXIS_OF[toward] === AXIS_OF[side]) return null;\n if (AXIS_OF[side] === \"y\") {\n // Inline-relative: spanning toward the popup's inline-end puts the inline-start edges\n // together.\n const inlineEnd: PhysicalSide = selfDirection === \"rtl\" ? \"left\" : \"right\";\n return { side, align: toward === inlineEnd ? \"start\" : \"end\" };\n }\n return { side, align: toward === \"bottom\" ? \"start\" : \"end\" };\n}\n\nfunction classify(\n word: string,\n index: number,\n count: number,\n selfDirection: Direction,\n rootDirection: () => Direction,\n): Token | null {\n if (word === \"center\" || word === \"span-all\") return { kind: \"neutral\", physical: null };\n const span = word.startsWith(\"span-\");\n const physical = physicalOf(\n span ? word.slice(5) : word,\n index,\n count,\n selfDirection,\n rootDirection,\n );\n return physical === null ? null : { kind: span ? \"span\" : \"side\", physical };\n}\n\n/**\n * The physical direction a keyword names, in `horizontal-tb`. Bare `start` / `end` /\n * `self-start` / `self-end` are positional: the block axis first, the inline axis second; alone\n * they name both axes (a corner, or a span over both), which the table does not describe.\n */\nfunction physicalOf(\n name: string,\n index: number,\n count: number,\n selfDirection: Direction,\n rootDirection: () => Direction,\n): PhysicalSide | null {\n switch (name) {\n case \"top\":\n case \"bottom\":\n case \"left\":\n case \"right\":\n return name;\n // The block axis is top / bottom in horizontal-tb, whatever the direction.\n case \"y-start\":\n case \"self-y-start\":\n case \"y-self-start\":\n case \"block-start\":\n case \"self-block-start\":\n return \"top\";\n case \"y-end\":\n case \"self-y-end\":\n case \"y-self-end\":\n case \"block-end\":\n case \"self-block-end\":\n return \"bottom\";\n // The inline axis against the popup's own direction.\n case \"self-x-start\":\n case \"x-self-start\":\n case \"self-inline-start\":\n return inlineEdge(\"start\", selfDirection);\n case \"self-x-end\":\n case \"x-self-end\":\n case \"self-inline-end\":\n return inlineEdge(\"end\", selfDirection);\n // The inline axis against the containing block's (the root's, for a top-layer popup).\n case \"x-start\":\n case \"inline-start\":\n return inlineEdge(\"start\", rootDirection());\n case \"x-end\":\n case \"inline-end\":\n return inlineEdge(\"end\", rootDirection());\n case \"start\":\n case \"end\":\n case \"self-start\":\n case \"self-end\": {\n if (count !== 2) return null;\n const edge = name.endsWith(\"start\") ? \"start\" : \"end\";\n if (index === 0) return edge === \"start\" ? \"top\" : \"bottom\";\n return inlineEdge(edge, name.startsWith(\"self-\") ? selfDirection : rootDirection());\n }\n default:\n return null;\n }\n}\n\nfunction inlineEdge(edge: \"start\" | \"end\", direction: Direction): PhysicalSide {\n return (edge === \"start\") === (direction === \"ltr\") ? \"left\" : \"right\";\n}\n"],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"call-urgent-handler.mjs","names":[],"sources":["../../src/internal/call-urgent-handler.ts"],"sourcesContent":["/** Whether `value` is a thenable (a promise, or anything with a callable `then`). */\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n (typeof value === \"object\" || typeof value === \"function\") &&\n value !== null &&\n typeof (value as { then?: unknown }).then === \"function\"\n );\n}\n\n/**\n * Calls an `on*` handler under the rule every handler the library defines follows (conventions\n * 2.1, #148): synchronously, in the caller's event, not awaited and with no pending state. A\n * synchronous throw is caught and passed to `reportError`, so the library's own bookkeeping after\n * the call still runs; a returned thenable gets a rejection handler that passes the reason to\n * `reportError`. Nothing reaches an Error Boundary, and a returned promise is never a warning.\n * Used by `onOpenChange` (the overlay Roots), a toast's `onClose` and Combobox's\n * `onInputValueChange`. A missing handler is a no-op.\n *\n * Directive-free: no client-only API (it does not import `report-dropped.ts`, a client module,\n * and repeats its two-line `reportError` fallback instead).\n */\nexport function callUrgentHandler<Args extends readonly unknown[]>(\n handler: ((...args: Args) => unknown) | undefined,\n ...args: Args\n): void {\n if (handler === undefined) return;\n let result: unknown;\n try {\n result = handler(...args);\n } catch (error) {\n report(error);\n return;\n }\n if (isThenable(result)) result.then(undefined, report);\n}\n\n/** `reportError`, or `console.error` where it does not exist (jsdom), as `reportDropped`. */\nfunction report(error: unknown): void {\n if (typeof reportError === \"function\") reportError(error);\n else console.error(error);\n}\n"],"mappings":";;AACA,SAAS,WAAW,OAA+C;CACjE,QACG,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,UAAU,QACV,OAAQ,MAA6B,SAAS;AAElD;;;;;;;;;;;;;AAcA,SAAgB,kBACd,SACA,GAAG,MACG;CACN,IAAI,YAAY,KAAA,GAAW;CAC3B,IAAI;CACJ,IAAI;EACF,SAAS,QAAQ,GAAG,IAAI;CAC1B,SAAS,OAAO;EACd,OAAO,KAAK;EACZ;CACF;CACA,IAAI,WAAW,MAAM,GAAG,OAAO,KAAK,KAAA,GAAW,MAAM;AACvD;;AAGA,SAAS,OAAO,OAAsB;CACpC,IAAI,OAAO,gBAAgB,YAAY,YAAY,KAAK;MACnD,QAAQ,MAAM,KAAK;AAC1B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"content-focus-probe.mjs","names":[],"sources":["../../src/internal/content-focus-probe.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\nimport type { ReactNode, RefObject } from \"react\";\n\n/**\n * Records, from its layout-effect cleanup, whether focus is inside the popup when the content\n * goes away: React runs a deleted component's layout cleanups before it detaches the host nodes,\n * so `document.activeElement` still names the focused element there.\n */\nfunction ContentFocusProbe({\n onDetach,\n children,\n}: {\n onDetach: () => void;\n children?: ReactNode;\n}): ReactNode {\n useLayoutEffect(() => onDetach, [onDetach]);\n return children;\n}\n\nexport interface ContentFocusProbeHook {\n /**\n * Wraps the library-mode content of a top-layer popup: call it only while the content is\n * shown (`visible ? wrapContent(x) : null`), or inside the `<Activity>` for `keepMounted`.\n */\n readonly wrapContent: (children: ReactNode) => ReactNode;\n /**\n * Whether the wrapped content unmounted (or was hidden by `<Activity>`) while it held focus\n * since the last `forget()`. The owner reads it after its close\n * (design/components/popover.md 6.2 rule 2, design/components/dialog.md 6.2 rule 2).\n * Handlers and effects only.\n */\n readonly hadFocus: () => boolean;\n /**\n * Clear the record: on every open, after the owner used it, and whenever the content went\n * away while the popup stays open (not a close).\n */\n readonly forget: () => void;\n}\n\n/**\n * The content probe shared by the popover-like Popups (Popover, Menu) and Dialog.Popup: a\n * library-driven close with `transition` unmounts the content, the focused Close part included,\n * in the close commit, before the layout effect that hides the popup runs, so focus falls to\n * `<body>` and the platform may restore nothing. The probe tells the owner that this happened.\n */\nexport function useContentFocusProbe(\n popupRef: RefObject<HTMLElement | null>,\n): ContentFocusProbeHook {\n const lostFocus = useRef(false);\n\n const record = useCallback(() => {\n const element = popupRef.current;\n if (element === null) return;\n const active = element.ownerDocument.activeElement;\n if (active !== null && active !== element && element.contains(active)) {\n lostFocus.current = true;\n }\n }, [popupRef]);\n\n const wrapContent = useCallback(\n (children: ReactNode): ReactNode => (\n <ContentFocusProbe onDetach={record}>{children}</ContentFocusProbe>\n ),\n [record],\n );\n const hadFocus = useCallback(() => lostFocus.current, []);\n const forget = useCallback(() => {\n lostFocus.current = false;\n }, []);\n\n return { wrapContent, hadFocus, forget };\n}\n"],"mappings":";;;;;;;;;AASA,SAAS,kBAAkB,EACzB,UACA,YAIY;CACZ,sBAAsB,UAAU,CAAC,QAAQ,CAAC;CAC1C,OAAO;AACT;;;;;;;AA4BA,SAAgB,qBACd,UACuB;CACvB,MAAM,YAAY,OAAO,KAAK;CAE9B,MAAM,SAAS,kBAAkB;EAC/B,MAAM,UAAU,SAAS;EACzB,IAAI,YAAY,MAAM;EACtB,MAAM,SAAS,QAAQ,cAAc;EACrC,IAAI,WAAW,QAAQ,WAAW,WAAW,QAAQ,SAAS,MAAM,GAClE,UAAU,UAAU;CAExB,GAAG,CAAC,QAAQ,CAAC;CAab,OAAO;EAAE,aAXW,aACjB,aACC,oBAAC,mBAAD;GAAmB,UAAU;GAAS;EAA4B,CAAA,GAEpE,CAAC,MAAM,CAOU;EAAG,UALL,kBAAkB,UAAU,SAAS,CAAC,CAK1B;EAAG,QAJjB,kBAAkB;GAC/B,UAAU,UAAU;EACtB,GAAG,CAAC,CAEiC;CAAE;AACzC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"css-transition-cut.mjs","names":[],"sources":["../../src/internal/css-transition-cut.ts"],"sourcesContent":["// No directive: a DOM helper (conventions 7.1).\n\n/** What `transition: none` sets, each restored on its own. */\nconst LONGHANDS = [\n \"transition-property\",\n \"transition-duration\",\n \"transition-timing-function\",\n \"transition-delay\",\n \"transition-behavior\",\n] as const;\n\n/** Elements inside a cut right now: a nested call (Menu's `reshow`) runs inside the outer one. */\nconst cutting = new WeakSet<HTMLElement>();\n\n/** Whether a document view transition is running (`html:active-view-transition`). */\nfunction viewTransitionActive(element: HTMLElement): boolean {\n try {\n return element.ownerDocument.documentElement.matches(\":active-view-transition\");\n } catch {\n // An engine (or jsdom) that does not know the pseudo-class has no view transition to avoid.\n return false;\n }\n}\n\n/**\n * Runs the library's own show or hide of a popup (`showPopover()`, `hidePopover()`,\n * `showModal()`, `show()`, `close()`) with the popup's CSS transitions cut, when the Popup has a\n * `transition` prop and a view transition is running (conventions 5.1, issue #147). The view\n * transition animates that show or hide; a CSS `transition` on the popup would run next to it\n * (the open's `@starting-style` enter under the view transition's enter; in Chromium the close's\n * `display` / `overlay` fade keeps the hidden box in the new snapshot, a double image).\n *\n * One synchronous step: an inline `transition: none !important`, the call, a forced style\n * recalculation (without it Chromium sees the restored value and the fade runs), and the inline\n * `transition` longhands restored as they were, so nothing is left for React's `style` diffing.\n * Everything goes through CSSOM, never the `style` attribute: a CSP without `'unsafe-inline'`\n * for styles blocks an attribute write (React's `style` prop is CSSOM too). Only CSS\n * transitions are cut, not a `@keyframes` animation. Dismissals (Escape, light dismiss) never\n * come here: their CSS exit plays.\n */\nexport function withCssTransitionCut<T>(\n element: HTMLElement,\n hasTransition: boolean,\n run: () => T,\n): T {\n if (!hasTransition || cutting.has(element) || !viewTransitionActive(element)) return run();\n const { style } = element;\n const hadAttribute = element.hasAttribute(\"style\");\n // The shorthand, and the longhands for a consumer who set only some of them (the shorthand\n // then reads as \"\").\n const shorthand = style.getPropertyValue(\"transition\");\n const shorthandPriority = style.getPropertyPriority(\"transition\");\n const longhands = LONGHANDS.map(\n (name) => [name, style.getPropertyValue(name), style.getPropertyPriority(name)] as const,\n );\n cutting.add(element);\n style.setProperty(\"transition\", \"none\", \"important\");\n try {\n return run();\n } finally {\n // The show or hide's style change is processed while the cut is in place.\n void getComputedStyle(element).opacity;\n // Only while the cut is still ours: a listener inside the call that wrote its own\n // `transition` keeps it.\n const ours = (name: string) =>\n style.getPropertyValue(name) === \"none\" && style.getPropertyPriority(name) === \"important\";\n if (ours(\"transition-property\") || ours(\"transition\")) {\n style.removeProperty(\"transition\");\n if (shorthand !== \"\") {\n style.setProperty(\"transition\", shorthand, shorthandPriority);\n } else {\n for (const [name, value, priority] of longhands) {\n if (value !== \"\") style.setProperty(name, value, priority);\n }\n }\n }\n // `removeAttribute` parses nothing, so CSP does not block it.\n if (!hadAttribute && style.length === 0) element.removeAttribute(\"style\");\n cutting.delete(element);\n }\n}\n"],"mappings":";;AAGA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,0BAAU,IAAI,QAAqB;;AAGzC,SAAS,qBAAqB,SAA+B;CAC3D,IAAI;EACF,OAAO,QAAQ,cAAc,gBAAgB,QAAQ,yBAAyB;CAChF,QAAQ;EAEN,OAAO;CACT;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,qBACd,SACA,eACA,KACG;CACH,IAAI,CAAC,iBAAiB,QAAQ,IAAI,OAAO,KAAK,CAAC,qBAAqB,OAAO,GAAG,OAAO,IAAI;CACzF,MAAM,EAAE,UAAU;CAClB,MAAM,eAAe,QAAQ,aAAa,OAAO;CAGjD,MAAM,YAAY,MAAM,iBAAiB,YAAY;CACrD,MAAM,oBAAoB,MAAM,oBAAoB,YAAY;CAChE,MAAM,YAAY,UAAU,KACzB,SAAS;EAAC;EAAM,MAAM,iBAAiB,IAAI;EAAG,MAAM,oBAAoB,IAAI;CAAC,CAChF;CACA,QAAQ,IAAI,OAAO;CACnB,MAAM,YAAY,cAAc,QAAQ,WAAW;CACnD,IAAI;EACF,OAAO,IAAI;CACb,UAAU;EAER,iBAAsB,OAAO,CAAC,CAAC;EAG/B,MAAM,QAAQ,SACZ,MAAM,iBAAiB,IAAI,MAAM,UAAU,MAAM,oBAAoB,IAAI,MAAM;EACjF,IAAI,KAAK,qBAAqB,KAAK,KAAK,YAAY,GAAG;GACrD,MAAM,eAAe,YAAY;GACjC,IAAI,cAAc,IAChB,MAAM,YAAY,cAAc,WAAW,iBAAiB;QAE5D,KAAK,MAAM,CAAC,MAAM,OAAO,aAAa,WACpC,IAAI,UAAU,IAAI,MAAM,YAAY,MAAM,OAAO,QAAQ;EAG/D;EAEA,IAAI,CAAC,gBAAgB,MAAM,WAAW,GAAG,QAAQ,gBAAgB,OAAO;EACxE,QAAQ,OAAO,OAAO;CACxB;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-context.d.mts","names":[],"sources":["../../src/internal/field-context.ts"],"mappings":";;;iBAMiB;;WAEN;;WAEA;;WAEA,UAAU;;WAEV;;WAEA;;WAEA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-context.mjs","names":[],"sources":["../../src/internal/field-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport { dataAttr } from \"./data-attr.js\";\nimport type { FieldValidity, FormErrors, ValidatableElement } from \"./validity.js\";\n\n/** The state every Field part receives (design/components/field-form.md 4.1). */\nexport interface FieldState {\n /** An error is shown: the control matches `:user-invalid`, or a server error for this field is shown. */\n readonly invalid: boolean;\n /** The messages shown: `[validationMessage]` for a native constraint, the strings `validate` returned for a custom one, the server's strings for a server error; `[]` while valid. */\n readonly messages: readonly string[];\n /** A snapshot of the control's `ValidityState` (all valid on the server and before the first read). */\n readonly validity: FieldValidity;\n /** `Field.Root disabled` or the control's own `disabled`. */\n readonly disabled: boolean;\n /** `Field.Root required` or the control's own `required`. */\n readonly required: boolean;\n /** The enclosing form's submission is in flight (`useFormStatus().pending`); `false` outside a form. */\n readonly pending: boolean;\n}\n\nexport interface FieldIds {\n readonly control: string;\n readonly label: string;\n readonly description: string;\n readonly error: string;\n}\n\n/** What a control reports to its Field (design 7.1). */\nexport interface FieldControlRegistration {\n /** The element the Field labels, describes and listens to (the input, or a group's fieldset). */\n readonly element: HTMLElement;\n /** `<label for>` can target it. Groups report `false`. */\n readonly labelable: boolean;\n /** The control's own `required` / `disabled` props (for the Field's `data-*` state). */\n readonly required: boolean;\n readonly disabled: boolean;\n /**\n * Where `validity`, `validationMessage` and the custom-validity slot are read and written when\n * that is not the registered element (NumberField: the hidden `input[type=number]` after the\n * visible text input). `:user-invalid`, the listeners and the focus target stay on `element`;\n * after writing the slot the Field mirrors this element's `validationMessage` into `element`\n * (design/components/field-form.md, `validityElement`). Resolved on every read.\n */\n readonly validityElement?: (() => ValidatableElement | null) | undefined;\n}\n\nexport interface FieldContextValue {\n readonly ids: FieldIds;\n /** `Field.Root name`. */\n readonly name: string | undefined;\n /** `Field.Root disabled` / `required` (the props, not the merged state). */\n readonly disabled: boolean;\n readonly required: boolean;\n readonly state: FieldState;\n /** The registered control is labelable (default `true`, also before any registration). */\n readonly labelable: boolean;\n /** Registers the Field's control; returns the unregister function. The first one wins. */\n readonly registerControl: (registration: FieldControlRegistration) => () => void;\n /** A `Field.Error` is mounted (the Field may cancel the platform bubble). */\n readonly registerError: () => () => void;\n /**\n * The control's value changed in the DOM without an `input` / `change` event the Field could\n * hear (a Combobox selection, a CheckboxGroup's derived `required`, a rolled-back optimistic\n * value): re-reads the slot and the mirror after the commit that wrote it, and refreshes the\n * other Fields of the `Form.Root` (cross-field rules). `edit`: the user made the change, so a\n * shown server error is dismissed as by an `input` event. Call from a layout effect.\n */\n readonly notifyChange: (edit: boolean) => void;\n}\n\nexport const FieldContext = createContext<FieldContextValue | null>(null);\n\nexport function useFieldContext(part: string): FieldContextValue {\n const ctx = use(FieldContext);\n if (ctx === null) throw new Error(`${part} must be rendered inside a Field.Root.`);\n return ctx;\n}\n\n/** What a Field registers with its Form (design 3.5). */\nexport interface FormFieldRegistration {\n /** The control, or a group's first enabled (or checked) member. */\n readonly getFocusTarget: () => HTMLElement | null;\n /** The Field shows a server error at the latest commit. */\n readonly showsServerError: () => boolean;\n /** The server messages shown, for an announcement when focus does not move. */\n readonly serverMessages: () => readonly string[];\n /** Re-runs `validate` and re-reads validity (another Field's control changed). */\n readonly refresh: () => void;\n}\n\nexport interface FormContextValue {\n readonly errors: FormErrors | undefined;\n readonly registerField: (registration: FormFieldRegistration) => () => void;\n /**\n * The `FormData` of the submission in flight when the Form ran it itself (the intercepted path),\n * else `null`: the stale-value suppression of design 3.2 item 2 is computed against it.\n */\n readonly submittedData: () => FormData | null;\n /** Refreshes every registered Field except `source` (a change no DOM event carried). */\n readonly refreshFields: (source: FormFieldRegistration | null) => void;\n}\n\nexport const FormContext = createContext<FormContextValue | null>(null);\n\n/** The four state attributes every Field part renders (design 6.1). */\nexport function fieldDataAttributes(state: FieldState) {\n return {\n \"data-invalid\": dataAttr(state.invalid),\n \"data-disabled\": dataAttr(state.disabled),\n \"data-required\": dataAttr(state.required),\n \"data-pending\": dataAttr(state.pending),\n };\n}\n"],"mappings":";;;;AAuEA,MAAa,eAAe,cAAwC,IAAI;AAExE,SAAgB,gBAAgB,MAAiC;CAC/D,MAAM,MAAM,IAAI,YAAY;CAC5B,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,GAAG,KAAK,uCAAuC;CACjF,OAAO;AACT;AA0BA,MAAa,cAAc,cAAuC,IAAI;;AAGtE,SAAgB,oBAAoB,OAAmB;CACrD,OAAO;EACL,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,MAAM,QAAQ;EACxC,iBAAiB,SAAS,MAAM,QAAQ;EACxC,gBAAgB,SAAS,MAAM,OAAO;CACxC;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"focus-first-invalid.mjs","names":[],"sources":["../../src/internal/focus-first-invalid.ts"],"sourcesContent":["// Directive-free: the module-level first-invalid collector (design/components/field-form.md 2.5).\nimport { announce } from \"./announce.js\";\nimport { sortByDocumentOrder } from \"./dom-order.js\";\n\ninterface Batch {\n /** The elements whose `invalid` event was collected (a group's members, not its target). */\n readonly sources: Set<Element>;\n readonly targets: HTMLElement[];\n /** The message each target's Field shows, for the announcement when focus does not move. */\n readonly messages: Map<HTMLElement, string>;\n /** `document.activeElement` when the first target arrived. */\n readonly activeBefore: Element | null;\n /** The batch moved focus (later microtasks then re-focus, never announce). */\n moved: boolean;\n /** The target already announced. */\n announced: HTMLElement | null;\n}\n\n/** The submission attempt in progress: every target added during the current task. */\nlet batch: Batch | null = null;\n\n/**\n * Adds a control whose `invalid` event (fired on `source`) a Field cancelled during a submission\n * attempt, and focuses the first collected control in document order in a microtask, so the\n * result does not depend on the browser's dispatch order or on how many forms are on the page.\n *\n * The batch lives until the end of the task (a `setTimeout`), not just one microtask: when the\n * browser dispatches the `invalid` events itself (a click on a submit button), it runs a\n * microtask checkpoint after each listener, so the microtask of the first event runs before the\n * second event fires. Every add therefore queues a focus of the batch's first target; later ones\n * re-focus the same element, which is a no-op.\n *\n * A second `invalid` for the same `source` (the element the event fired on) starts a new batch:\n * one validation fires it once per element, so it belongs to the next attempt, even when that\n * attempt comes before the timer (two attempts in one task, or a test that does not yield to\n * timers between them). Joining the old batch would compare focus with the old attempt's.\n *\n * Skips the focus when focus moved during the attempt to an element that is not one of the\n * collected targets: a plain `<input required>` with no Field kept the platform's behaviour\n * (bubble and focus), and the library does not fight it.\n */\nexport function collectInvalid(target: HTMLElement | null, message: string, source: Element): void {\n if (target === null) return;\n if (batch !== null && batch.sources.has(source)) batch = null;\n if (batch === null) {\n const created: Batch = {\n sources: new Set(),\n targets: [],\n messages: new Map(),\n activeBefore: target.ownerDocument.activeElement,\n moved: false,\n announced: null,\n };\n batch = created;\n setTimeout(() => {\n if (batch === created) batch = null;\n }, 0);\n }\n const current = batch;\n current.sources.add(source);\n if (!current.targets.includes(target)) current.targets.push(target);\n current.messages.set(target, message);\n queueMicrotask(() => focusFirst(current));\n}\n\n/**\n * Tests only: forget the submission attempt in progress. Its timer is a task away, and the next\n * test can start before it runs (no task in between); its attempt would then join this one and\n * compare focus with an element of the previous test.\n */\nexport function resetInvalidBatch(): void {\n batch = null;\n}\n\nfunction focusFirst(current: Batch): void {\n const { targets, activeBefore } = current;\n const connected = targets.filter((t) => t.isConnected);\n if (connected.length === 0) return;\n const active = connected[0]!.ownerDocument.activeElement;\n if (active !== activeBefore && active !== null && !connected.includes(active as HTMLElement)) {\n return;\n }\n const first = sortByDocumentOrder(connected, (t) => t)[0]!;\n if (active !== first) {\n current.moved = true;\n first.focus();\n } else if (!current.moved && current.announced !== first) {\n // Focus was already on the first invalid control (an implicit submission with Enter): the\n // cancelled bubble was the only announcement, so speak the message instead.\n current.announced = first;\n announce(first, current.messages.get(first) ?? \"\");\n }\n}\n"],"mappings":";;;;AAmBA,IAAI,QAAsB;;;;;;;;;;;;;;;;;;;;;AAsB1B,SAAgB,eAAe,QAA4B,SAAiB,QAAuB;CACjG,IAAI,WAAW,MAAM;CACrB,IAAI,UAAU,QAAQ,MAAM,QAAQ,IAAI,MAAM,GAAG,QAAQ;CACzD,IAAI,UAAU,MAAM;EAClB,MAAM,UAAiB;GACrB,yBAAS,IAAI,IAAI;GACjB,SAAS,CAAC;GACV,0BAAU,IAAI,IAAI;GAClB,cAAc,OAAO,cAAc;GACnC,OAAO;GACP,WAAW;EACb;EACA,QAAQ;EACR,iBAAiB;GACf,IAAI,UAAU,SAAS,QAAQ;EACjC,GAAG,CAAC;CACN;CACA,MAAM,UAAU;CAChB,QAAQ,QAAQ,IAAI,MAAM;CAC1B,IAAI,CAAC,QAAQ,QAAQ,SAAS,MAAM,GAAG,QAAQ,QAAQ,KAAK,MAAM;CAClE,QAAQ,SAAS,IAAI,QAAQ,OAAO;CACpC,qBAAqB,WAAW,OAAO,CAAC;AAC1C;AAWA,SAAS,WAAW,SAAsB;CACxC,MAAM,EAAE,SAAS,iBAAiB;CAClC,MAAM,YAAY,QAAQ,QAAQ,MAAM,EAAE,WAAW;CACrD,IAAI,UAAU,WAAW,GAAG;CAC5B,MAAM,SAAS,UAAU,EAAE,CAAE,cAAc;CAC3C,IAAI,WAAW,gBAAgB,WAAW,QAAQ,CAAC,UAAU,SAAS,MAAqB,GACzF;CAEF,MAAM,QAAQ,oBAAoB,YAAY,MAAM,CAAC,CAAC,CAAC;CACvD,IAAI,WAAW,OAAO;EACpB,QAAQ,QAAQ;EAChB,MAAM,MAAM;CACd,OAAO,IAAI,CAAC,QAAQ,SAAS,QAAQ,cAAc,OAAO;EAGxD,QAAQ,YAAY;EACpB,SAAS,OAAO,QAAQ,SAAS,IAAI,KAAK,KAAK,EAAE;CACnD;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"focus-visible.mjs","names":[],"sources":["../../src/internal/focus-visible.ts"],"sourcesContent":["// Directive-free: the `focus({ focusVisible })` probe behind a pointer open's quiet initial focus\n// (design/components/popover.md 6.1, menu.md 6.1).\n\n/**\n * An initial focus target opened by a pointer: where the engine reads `focus({ focusVisible })`,\n * the library focuses it with `focusVisible: false` right after `showPopover()` instead of\n * writing `autofocus` (WebKit shows the ring for an `autofocus` target after a click).\n * Elsewhere it is an ordinary target.\n */\nexport interface QuietFocusTarget {\n readonly element: HTMLElement;\n readonly focusVisible: false;\n}\n\nlet focusVisibleOption: boolean | undefined;\n\n/**\n * The engine reads the `focusVisible` member of `focus()`'s options (Chromium 145, Firefox 104,\n * Safari 18.4). Detected once through a getter: the bindings convert the dictionary before the\n * method runs, so a detached element is enough and nothing is focused.\n */\nexport function supportsFocusVisibleOption(doc: Document): boolean {\n if (focusVisibleOption === undefined) {\n let read = false;\n try {\n doc.createElement(\"div\").focus({\n get focusVisible() {\n read = true;\n return false;\n },\n } as FocusOptions);\n } catch {\n read = false;\n }\n focusVisibleOption = read;\n }\n return focusVisibleOption;\n}\n\n/** Tests only: forget the detection, so the next pointer open detects the option again. */\nexport function resetFocusVisibleOption(): void {\n focusVisibleOption = undefined;\n}\n"],"mappings":";AAcA,IAAI;;;;;;AAOJ,SAAgB,2BAA2B,KAAwB;CACjE,IAAI,uBAAuB,KAAA,GAAW;EACpC,IAAI,OAAO;EACX,IAAI;GACF,IAAI,cAAc,KAAK,CAAC,CAAC,MAAM,EAC7B,IAAI,eAAe;IACjB,OAAO;IACP,OAAO;GACT,EACF,CAAiB;EACnB,QAAQ;GACN,OAAO;EACT;EACA,qBAAqB;CACvB;CACA,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"form-status-watcher.mjs","names":[],"sources":["../../src/internal/form-status-watcher.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { useFormStatus } from \"react-dom\";\n\nexport interface FormStatusWatcherProps {\n readonly onPendingChange: (pending: boolean) => void;\n readonly onSettled: () => void;\n}\n\n/**\n * Observes React's form channel (Dialog design 8.1, Field/Form design 3.2): rendered inside a\n * `<form>`, `useFormStatus().pending` covers the action's whole transition, including the\n * Suspense wait of what it re-renders. On `true → false` the submission settled without throwing\n * (a rejection unmounts the form through the nearest Error Boundary, so the edge is never seen).\n * Used by `Dialog.Form` and `Form.Root`.\n */\nexport function FormStatusWatcher({ onPendingChange, onSettled }: FormStatusWatcherProps) {\n const { pending } = useFormStatus();\n const previous = useRef(false);\n useEffect(() => {\n const was = previous.current;\n previous.current = pending;\n if (was === pending) return;\n onPendingChange(pending);\n if (was && !pending) onSettled();\n }, [pending, onPendingChange, onSettled]);\n return null;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAgB,kBAAkB,EAAE,iBAAiB,aAAqC;CACxF,MAAM,EAAE,YAAY,cAAc;CAClC,MAAM,WAAW,OAAO,KAAK;CAC7B,gBAAgB;EACd,MAAM,MAAM,SAAS;EACrB,SAAS,UAAU;EACnB,IAAI,QAAQ,SAAS;EACrB,gBAAgB,OAAO;EACvB,IAAI,OAAO,CAAC,SAAS,UAAU;CACjC,GAAG;EAAC;EAAS;EAAiB;CAAS,CAAC;CACxC,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"group-member.mjs","names":[],"sources":["../../src/internal/group-member.ts"],"sourcesContent":["\"use client\";\nimport type { ChangeEvent, ComponentPropsWithRef } from \"react\";\nimport { dataAttr } from \"./data-attr.js\";\nimport type { DataAttributes } from \"./render-element.js\";\nimport { guardCheckableChange } from \"./use-native-checked.js\";\n\nexport interface GroupMemberPropsOptions {\n readonly type: \"radio\" | \"checkbox\";\n /** Dispatch-guard name (`\"RadioGroup.Item\"`). */\n readonly component: string;\n /** The group's shared `name` and `form`. */\n readonly name: string;\n readonly form: string | undefined;\n readonly value: string;\n readonly required: boolean;\n /** Optimistic. */\n readonly checked: boolean;\n readonly pending: boolean;\n /** Own `disabled` prop or the Root's: `data-disabled` and the click guard. */\n readonly effectiveDisabled: boolean;\n /** The member's own `disabled` prop only: the Root's reaches it through `<fieldset disabled>`. */\n readonly ownDisabled: boolean;\n /** CheckboxGroup inside a Field: the group's `aria-invalid` (the fieldset cannot carry it). */\n readonly invalid?: \"true\" | \"false\" | undefined;\n /** The user checked (radio) or toggled (checkbox) the input. */\n readonly activate: (event: Event) => void;\n}\n\n/**\n * The owned layer (conventions 1.2) of a group Item's `<input>`: `type`, the group's `name` /\n * `form`, `value`, `checked` (the optimistic state), `defaultChecked` (never rendered), a\n * checkbox's `aria-checked` (removed), `disabled`, `required`, the state `data-*` attributes,\n * and the guarded `onChange`.\n */\nexport function groupMemberProps(\n options: GroupMemberPropsOptions,\n): Partial<ComponentPropsWithRef<\"input\">> & DataAttributes {\n const { type, component, checked, pending, effectiveDisabled, invalid, activate } = options;\n return {\n type,\n name: options.name,\n value: options.value,\n checked,\n defaultChecked: undefined,\n ...(type === \"checkbox\" && { \"aria-checked\": undefined }),\n // Owned (Switch precedent) so that native disabledness, `data-disabled` and the click guard\n // agree. Only the Item's own prop: `Root disabled` reaches the input through the fieldset.\n disabled: options.ownDisabled,\n form: options.form,\n required: options.required,\n \"data-checked\": dataAttr(checked),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(effectiveDisabled),\n ...(invalid !== undefined && { \"aria-invalid\": invalid }),\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 (effectiveDisabled) return;\n const nativeEvent = event.nativeEvent;\n guardCheckableChange(nativeEvent, () => activate(nativeEvent), component);\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAkCA,SAAgB,iBACd,SAC0D;CAC1D,MAAM,EAAE,MAAM,WAAW,SAAS,SAAS,mBAAmB,SAAS,aAAa;CACpF,OAAO;EACL;EACA,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf;EACA,gBAAgB,KAAA;EAChB,GAAI,SAAS,cAAc,EAAE,gBAAgB,KAAA,EAAU;EAGvD,UAAU,QAAQ;EAClB,MAAM,QAAQ;EACd,UAAU,QAAQ;EAClB,gBAAgB,SAAS,OAAO;EAChC,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,iBAAiB;EAC3C,GAAI,YAAY,KAAA,KAAa,EAAE,gBAAgB,QAAQ;EACvD,WAAW,UAAyC;GAGlD,IAAI,mBAAmB;GACvB,MAAM,cAAc,MAAM;GAC1B,qBAAqB,mBAAmB,SAAS,WAAW,GAAG,SAAS;EAC1E;CACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invokers.mjs","names":[],"sources":["../../src/internal/invokers.ts"],"sourcesContent":["// No directive: DOM reads and listeners only (conventions 7.1). The platform's invoker\n// relationship between a button and a popover, as the overlays read it.\n\n/** An invoker button's IDL; absent where the engine lacks the Popover API or Invoker Commands. */\ninterface InvokerButton {\n readonly popoverTargetElement?: Element | null;\n readonly commandForElement?: Element | null;\n readonly command?: string;\n}\n\n/**\n * The `source` of a `ToggleEvent` (Chromium 140, Firefox 145, Safari 26.5), a `CommandEvent` or\n * an `InterestEvent`: the invoker that caused it, `null` without one. Not in TypeScript's DOM lib\n * for all three.\n */\nexport function eventSource(event: Event): Element | null {\n return (event as Event & { readonly source?: Element | null }).source ?? null;\n}\n\n/**\n * Whether the `ToggleEvent.source` of a close is a `popovertarget` invoker of `popup`. A\n * `commandfor` or `interestfor` invoker sets `source` too (Chromium's lost-interest hide, a\n * dismissal), and so names no `popovertarget` here.\n */\nexport function closedByPopoverTarget(event: ToggleEvent, popup: HTMLElement): boolean {\n const source = eventSource(event);\n return (\n (source instanceof HTMLButtonElement || source instanceof HTMLInputElement) &&\n source.popoverTargetElement === popup\n );\n}\n\n/** The `<input>` types HTML counts as buttons: the ones `popovertarget` applies to. */\nconst INPUT_BUTTON_TYPES = new Set([\"submit\", \"image\", \"reset\", \"button\"]);\n\n/**\n * Whether a press on `target` is a press on a foreign invoker of `popup`: its closest button (a\n * `<button>`, or an `<input>` of a button type) is outside the popup and names it through\n * `popovertarget`, or (a `<button>`) through `commandfor` with a popover command\n * (`toggle-popover`, `show-popover`, `hide-popover`). HTML's invoker relationship, the one light\n * dismiss exempts (conventions 3.5): a disabled button and a submit button with a form owner\n * invoke nothing. Read through the IDL, so an engine without it has no such invoker.\n */\nexport function isPopoverInvoker(target: EventTarget | null, popup: Element): boolean {\n if (!(target instanceof Element)) return false;\n const button = target.closest<HTMLButtonElement | HTMLInputElement>(\"button, input\");\n if (button === null || popup.contains(button)) return false;\n const isInput = button.tagName === \"INPUT\";\n if (isInput && !INPUT_BUTTON_TYPES.has(button.type)) return false;\n if (button.disabled) return false;\n if (button.form !== null && (button.type === \"submit\" || button.type === \"image\")) return false;\n const invoker = button as InvokerButton;\n if (invoker.popoverTargetElement === popup) return true;\n return !isInput && invoker.commandForElement === popup && /-popover$/.test(invoker.command ?? \"\");\n}\n\n/**\n * While a popup that closes on focus leaving is shown: a primary-button `mousedown` on a foreign\n * invoker of it moves no focus (conventions 3.5). Chromium and Firefox focus a button on\n * press, which would close the popup at the `focusout` before the click's own toggle (as\n * `\"dismiss\"`, and the toggle then re-showed it). Returns the cleanup.\n */\nexport function listenInvokerPresses(popup: HTMLElement): () => void {\n const doc = popup.ownerDocument;\n const onMouseDown = (event: MouseEvent) => {\n if (event.button === 0 && isPopoverInvoker(event.target, popup)) event.preventDefault();\n };\n doc.addEventListener(\"mousedown\", onMouseDown, true);\n return () => doc.removeEventListener(\"mousedown\", onMouseDown, true);\n}\n"],"mappings":";;;;;;AAeA,SAAgB,YAAY,OAA8B;CACxD,OAAQ,MAAuD,UAAU;AAC3E;;;;;;AAOA,SAAgB,sBAAsB,OAAoB,OAA6B;CACrF,MAAM,SAAS,YAAY,KAAK;CAChC,QACG,kBAAkB,qBAAqB,kBAAkB,qBAC1D,OAAO,yBAAyB;AAEpC;;AAGA,MAAM,qCAAqB,IAAI,IAAI;CAAC;CAAU;CAAS;CAAS;AAAQ,CAAC;;;;;;;;;AAUzE,SAAgB,iBAAiB,QAA4B,OAAyB;CACpF,IAAI,EAAE,kBAAkB,UAAU,OAAO;CACzC,MAAM,SAAS,OAAO,QAA8C,eAAe;CACnF,IAAI,WAAW,QAAQ,MAAM,SAAS,MAAM,GAAG,OAAO;CACtD,MAAM,UAAU,OAAO,YAAY;CACnC,IAAI,WAAW,CAAC,mBAAmB,IAAI,OAAO,IAAI,GAAG,OAAO;CAC5D,IAAI,OAAO,UAAU,OAAO;CAC5B,IAAI,OAAO,SAAS,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,OAAO;CAC1F,MAAM,UAAU;CAChB,IAAI,QAAQ,yBAAyB,OAAO,OAAO;CACnD,OAAO,CAAC,WAAW,QAAQ,sBAAsB,SAAS,YAAY,KAAK,QAAQ,WAAW,EAAE;AAClG;;;;;;;AAQA,SAAgB,qBAAqB,OAAgC;CACnE,MAAM,MAAM,MAAM;CAClB,MAAM,eAAe,UAAsB;EACzC,IAAI,MAAM,WAAW,KAAK,iBAAiB,MAAM,QAAQ,KAAK,GAAG,MAAM,eAAe;CACxF;CACA,IAAI,iBAAiB,aAAa,aAAa,IAAI;CACnD,aAAa,IAAI,oBAAoB,aAAa,aAAa,IAAI;AACrE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"modal-registry.mjs","names":[],"sources":["../../src/internal/modal-registry.ts"],"sourcesContent":["// No \"use client\" directive: a plain module-level store, no React and no DOM calls\n// (design/components/toast.md 4.3, conventions 3.5 \"module-level registry\").\n//\n// The stack of open modal `<dialog>` elements the library's Dialog opened. A top-layer element\n// outside the topmost modal dialog is inert and absent from the accessibility tree, so Toast's\n// Viewport portals its region into the topmost one. Writers (`use-modal-registration.ts`) run\n// in layout effects and platform event listeners, never during render; readers subscribe through\n// `useSyncExternalStore` with a server snapshot of `null`. Never the source of truth for a\n// component's own state.\n\nconst stack: Element[] = [];\nconst listeners = new Set<() => void>();\n\nfunction notify(): void {\n for (const listener of [...listeners]) listener();\n}\n\n/** Records `dialog` as the topmost open modal dialog (moves it to the top if already present). */\nexport function pushModal(dialog: Element): void {\n const index = stack.indexOf(dialog);\n if (index !== -1 && index === stack.length - 1) return;\n if (index !== -1) stack.splice(index, 1);\n stack.push(dialog);\n notify();\n}\n\n/** Forgets `dialog` (closed or unmounted). */\nexport function removeModal(dialog: Element): void {\n const index = stack.indexOf(dialog);\n if (index === -1) return;\n stack.splice(index, 1);\n notify();\n}\n\nexport function subscribeModals(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/** The topmost open modal dialog the library opened, or `null`. */\nexport function getTopmostModal(): Element | null {\n return stack.at(-1) ?? null;\n}\n\n/** The server snapshot: nothing is open on the server. */\nexport function getServerTopmostModal(): Element | null {\n return null;\n}\n"],"mappings":";AAUA,MAAM,QAAmB,CAAC;AAC1B,MAAM,4BAAY,IAAI,IAAgB;AAEtC,SAAS,SAAe;CACtB,KAAK,MAAM,YAAY,CAAC,GAAG,SAAS,GAAG,SAAS;AAClD;;AAGA,SAAgB,UAAU,QAAuB;CAC/C,MAAM,QAAQ,MAAM,QAAQ,MAAM;CAClC,IAAI,UAAU,MAAM,UAAU,MAAM,SAAS,GAAG;CAChD,IAAI,UAAU,IAAI,MAAM,OAAO,OAAO,CAAC;CACvC,MAAM,KAAK,MAAM;CACjB,OAAO;AACT;;AAGA,SAAgB,YAAY,QAAuB;CACjD,MAAM,QAAQ,MAAM,QAAQ,MAAM;CAClC,IAAI,UAAU,IAAI;CAClB,MAAM,OAAO,OAAO,CAAC;CACrB,OAAO;AACT;AAEA,SAAgB,gBAAgB,UAAkC;CAChE,UAAU,IAAI,QAAQ;CACtB,aAAa;EACX,UAAU,OAAO,QAAQ;CAC3B;AACF;;AAGA,SAAgB,kBAAkC;CAChD,OAAO,MAAM,GAAG,EAAE,KAAK;AACzB;;AAGA,SAAgB,wBAAwC;CACtD,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-popup.mjs","names":[],"sources":["../../src/internal/overlay-popup.tsx"],"sourcesContent":["\"use client\";\n// The pieces Dialog.Popup shares with usePopoverPopup (Popover, Menu, Combobox). The two stay\n// separate: Dialog has showModal / show, `close` / `cancel` / `submit` and light dismiss.\nimport { Activity, useRef, useState } from \"react\";\nimport type { ReactNode, RefObject, ViewTransitionClass } from \"react\";\nimport { ToolbarContext } from \"./toolbar-context.js\";\nimport { useDevWarning } from \"./use-dev-warning.js\";\nimport { useExitAnimation } from \"./use-exit-animation.js\";\nimport type { ExitAnimation } from \"./use-exit-animation.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface OverlayContentOptions {\n readonly isLibrary: boolean;\n readonly keepMounted: boolean | undefined;\n /** Committed open, or held while the exit animates (design/components/popover.md 4.4). */\n readonly visible: boolean;\n readonly wrapContent: (children: ReactNode) => ReactNode;\n}\n\n/**\n * The children of a popup (Popover, Dialog, Menu, Combobox). JS-free mode: always rendered.\n * Library mode: rendered while `visible`, or with `keepMounted` inside an `<Activity>` whose mode\n * changes with committed state, inside the Root's transition (conventions 5.5). The content is\n * not part of an enclosing Toolbar's sequence (the engine excludes `[popover]` and `dialog`), so\n * parts inside it see no Toolbar. `children` is called only when rendered.\n */\nexport function renderOverlayContent(\n { isLibrary, keepMounted, visible, wrapContent }: OverlayContentOptions,\n children: () => ReactNode,\n): ReactNode {\n let node: ReactNode;\n if (!isLibrary) {\n node = children();\n } else if (keepMounted === true) {\n node = <Activity mode={visible ? \"visible\" : \"hidden\"}>{wrapContent(children())}</Activity>;\n } else {\n node = visible ? wrapContent(children()) : null;\n }\n return <ToolbarContext value={null}>{node}</ToolbarContext>;\n}\n\nexport interface CloseHold extends ExitAnimation {\n /**\n * The close's native event (`toggle` / `close`) arrived: hold the content until the exit\n * animations settle, or release a hold now when nothing animates (Firefox, or no CSS exit: the\n * popup is already `display: none`, the commit is invisible). Call before reporting the fact,\n * so its commit keeps the children. Nothing for the library's own close (`echo`) with\n * `transition`: the close commit's view transition carried the content out.\n */\n readonly afterClose: (popup: Element, echo: boolean) => void;\n /**\n * The apply effect's release rule: a hold the close commit set (or a fact's commit) that no\n * exit animation is going to release, the popup being hidden and its close event handled.\n */\n readonly releaseIfIdle: (committed: boolean, awaitingClose: boolean, shown: boolean) => void;\n}\n\n/**\n * `held` for a popup (design/components/popover.md 4.4): the children stay mounted while the\n * close animates. A library-driven close commits `false` first and hides in the layout effect,\n * so without `transition` the children are held through the close commit (\"previous value in\n * state\"). With `transition` the close commit unmounts them inside the view transition, whose old\n * snapshot carries the content out.\n */\nexport function useCloseHold(\n committed: boolean,\n isLibrary: boolean,\n transition: ViewTransitionClass | undefined,\n): CloseHold {\n const exit = useExitAnimation();\n const [prevCommitted, setPrevCommitted] = useState(committed);\n if (prevCommitted !== committed) {\n setPrevCommitted(committed);\n if (isLibrary && prevCommitted && transition === undefined) exit.holdDuringRender();\n }\n return {\n ...exit,\n afterClose: (popup, echo) => {\n if (echo && transition !== undefined) return;\n const animations = exit.exitAnimations(popup);\n if (animations.length > 0) exit.holdUntil(animations);\n else exit.release();\n },\n releaseIfIdle: (isCommitted, awaitingClose, shown) => {\n if (exit.held && !isCommitted && !exit.waiting() && !awaitingClose && !shown) {\n exit.release();\n }\n },\n };\n}\n\n/** The lower-cased `command` of a `command` event. */\nexport function commandOf(event: Event): string {\n return String((event as Event & { command?: string }).command ?? \"\").toLowerCase();\n}\n\n/** Resolves `initialFocus` against the popup (a ref, or a selector inside the popup). */\nexport function resolveInitialFocus(\n popup: HTMLElement,\n initialFocus: RefObject<HTMLElement | null> | string,\n): HTMLElement | null {\n if (typeof initialFocus === \"string\") return popup.querySelector<HTMLElement>(initialFocus);\n return initialFocus.current;\n}\n\nexport type InitialFocusTarget = (\n popup: HTMLElement,\n initialFocus: RefObject<HTMLElement | null> | string | undefined,\n) => HTMLElement | null;\n\n/**\n * `initialFocus` resolved right before a library open (design 6.1): the target, or `null` (the\n * platform picks) without one, or when it resolves to nothing or outside the popup; those two\n * warn once per instance in development. `noun` names the popup in the warning.\n */\nexport function useInitialFocusTarget(part: string, noun: string): InitialFocusTarget {\n const warned = useRef(false);\n return (popup, initialFocus) => {\n if (initialFocus === undefined) return null;\n const target = resolveInitialFocus(popup, initialFocus);\n if (target !== null && popup.contains(target)) return target;\n if (isDev && !warned.current) {\n warned.current = true;\n console.error(\n target === null\n ? `${part}: \\`initialFocus\\` resolved to no element; the platform picks the focus target.`\n : `${part}: \\`initialFocus\\` is outside the ${noun}; the platform picks the focus target.`,\n );\n }\n return null;\n };\n}\n\n/**\n * Design 6.2 rule 2, after a close that began with focus inside (or whose commit unmounted the\n * focused content): when focus is now on `<body>` or still inside the hidden popup, focus the\n * Trigger (connected, and `canFocus` when given), else blur what holds focus.\n */\nexport function returnFocusToTrigger(\n popup: HTMLElement,\n trigger: HTMLElement | null,\n canFocus?: (trigger: HTMLElement) => boolean,\n): void {\n const doc = popup.ownerDocument;\n const active = doc.activeElement;\n if (active !== null && active !== doc.body && !popup.contains(active)) return;\n if (trigger !== null && trigger.isConnected && (canFocus === undefined || canFocus(trigger))) {\n trigger.focus();\n } else if (active instanceof HTMLElement && active !== doc.body) {\n active.blur();\n }\n}\n\n/** The development warnings for a Popup's library-only props in JS-free mode. */\nexport function useJsFreePropWarnings(\n part: string,\n noun: string,\n isLibrary: boolean,\n transition: ViewTransitionClass | undefined,\n keepMounted: boolean | undefined,\n): void {\n useDevWarning(\n !isLibrary && transition !== undefined,\n isDev &&\n `${part}: \\`transition\\` has no effect in JS-free mode; the browser opens and closes the ` +\n `${noun} outside any React transition. Animate it with CSS (\\`@starting-style\\`).`,\n );\n useDevWarning(\n !isLibrary && keepMounted === false,\n isDev &&\n `${part}: \\`keepMounted={false}\\` cannot be honoured in JS-free mode; the content is ` +\n \"always mounted so that the server HTML is complete.\",\n );\n}\n"],"mappings":";;;;;;;AAUA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;AAiBvC,SAAgB,qBACd,EAAE,WAAW,aAAa,SAAS,eACnC,UACW;CACX,IAAI;CACJ,IAAI,CAAC,WACH,OAAO,SAAS;MACX,IAAI,gBAAgB,MACzB,OAAO,oBAAC,UAAD;EAAU,MAAM,UAAU,YAAY;EAAW,UAAA,YAAY,SAAS,CAAC;CAAY,CAAA;MAE1F,OAAO,UAAU,YAAY,SAAS,CAAC,IAAI;CAE7C,OAAO,oBAAC,gBAAD;EAAgB,OAAO;EAAO,UAAA;CAAqB,CAAA;AAC5D;;;;;;;;AAyBA,SAAgB,aACd,WACA,WACA,YACW;CACX,MAAM,OAAO,iBAAiB;CAC9B,MAAM,CAAC,eAAe,oBAAoB,SAAS,SAAS;CAC5D,IAAI,kBAAkB,WAAW;EAC/B,iBAAiB,SAAS;EAC1B,IAAI,aAAa,iBAAiB,eAAe,KAAA,GAAW,KAAK,iBAAiB;CACpF;CACA,OAAO;EACL,GAAG;EACH,aAAa,OAAO,SAAS;GAC3B,IAAI,QAAQ,eAAe,KAAA,GAAW;GACtC,MAAM,aAAa,KAAK,eAAe,KAAK;GAC5C,IAAI,WAAW,SAAS,GAAG,KAAK,UAAU,UAAU;QAC/C,KAAK,QAAQ;EACpB;EACA,gBAAgB,aAAa,eAAe,UAAU;GACpD,IAAI,KAAK,QAAQ,CAAC,eAAe,CAAC,KAAK,QAAQ,KAAK,CAAC,iBAAiB,CAAC,OACrE,KAAK,QAAQ;EAEjB;CACF;AACF;;AAGA,SAAgB,UAAU,OAAsB;CAC9C,OAAO,OAAQ,MAAuC,WAAW,EAAE,CAAC,CAAC,YAAY;AACnF;;AAGA,SAAgB,oBACd,OACA,cACoB;CACpB,IAAI,OAAO,iBAAiB,UAAU,OAAO,MAAM,cAA2B,YAAY;CAC1F,OAAO,aAAa;AACtB;;;;;;AAYA,SAAgB,sBAAsB,MAAc,MAAkC;CACpF,MAAM,SAAS,OAAO,KAAK;CAC3B,QAAQ,OAAO,iBAAiB;EAC9B,IAAI,iBAAiB,KAAA,GAAW,OAAO;EACvC,MAAM,SAAS,oBAAoB,OAAO,YAAY;EACtD,IAAI,WAAW,QAAQ,MAAM,SAAS,MAAM,GAAG,OAAO;EACtD,IAAI,SAAS,CAAC,OAAO,SAAS;GAC5B,OAAO,UAAU;GACjB,QAAQ,MACN,WAAW,OACP,GAAG,KAAK,mFACR,GAAG,KAAK,oCAAoC,KAAK,uCACvD;EACF;EACA,OAAO;CACT;AACF;;;;;;AAOA,SAAgB,qBACd,OACA,SACA,UACM;CACN,MAAM,MAAM,MAAM;CAClB,MAAM,SAAS,IAAI;CACnB,IAAI,WAAW,QAAQ,WAAW,IAAI,QAAQ,CAAC,MAAM,SAAS,MAAM,GAAG;CACvE,IAAI,YAAY,QAAQ,QAAQ,gBAAgB,aAAa,KAAA,KAAa,SAAS,OAAO,IACxF,QAAQ,MAAM;MACT,IAAI,kBAAkB,eAAe,WAAW,IAAI,MACzD,OAAO,KAAK;AAEhB;;AAGA,SAAgB,sBACd,MACA,MACA,WACA,YACA,aACM;CACN,cACE,CAAC,aAAa,eAAe,KAAA,GAC7B,SACE,GAAG,KAAK,mFACH,KAAK,0EACd;CACA,cACE,CAAC,aAAa,gBAAgB,OAC9B,SACE,GAAG,KAAK,iIAEZ;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"popover-open.mjs","names":[],"sources":["../../src/internal/popover-open.ts"],"sourcesContent":["// No directive: a pure DOM read (conventions 7.1).\n\n/**\n * Whether `element` is a showing popover (`:popover-open`). `false` for `null` and where the\n * selector is unsupported (it throws there, for example on a `render` element in an engine\n * without the Popover API).\n */\nexport function isPopoverOpen(element: Element | null): boolean {\n if (element === null) return false;\n try {\n return element.matches(\":popover-open\");\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,cAAc,SAAkC;CAC9D,IAAI,YAAY,MAAM,OAAO;CAC7B,IAAI;EACF,OAAO,QAAQ,QAAQ,eAAe;CACxC,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"report-dropped.mjs","names":[],"sources":["../../src/internal/report-dropped.ts"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\n\n/**\n * Reports an action rejection that React would drop (conventions 2.4), for `useControllableAction`\n * and `useActionTrigger`. React routes a transition's rejection only by unwrapping the newest\n * thenable of a `useTransition` in a render of the component that owns it, so two rejections reach\n * no Error Boundary:\n *\n * - a **superseded** run's (a later run of the same hook replaced its thenable), and\n * - the **latest** run's once the owner is **gone**: unmounted, or hidden (a consumer's\n * `<Activity>`, the library's `keepMounted` overlays in `overlay-popup.tsx`, Toast's Suspense\n * guard, any Suspense boundary showing its fallback): no render reads it (#152). Hidden counts\n * as gone: the rejection is reported once and does not reach the boundary on re-show, where\n * React would deliver it (a deliberate deviation, conventions resolved question 43).\n *\n * The library passes them to the global `reportError` instead, as React's standalone\n * `startTransition` does with every rejection: a window `error` event, seen by monitoring tools\n * and by test runners, while the UI stays up. `console.error` where there is no `reportError`.\n */\nexport function reportDropped(error: unknown): void {\n if (typeof reportError === \"function\") reportError(error);\n else console.error(error);\n}\n\n/**\n * Whether the calling component's effects are connected: `true` from its mount layout effect until\n * that effect is cleaned up, which happens on unmount, when an `<Activity>` hides it (`keepMounted`\n * included) and when a Suspense boundary above it re-suspends and shows its fallback. Read from\n * action continuations only, to decide between rethrowing a latest rejection (React routes it to\n * the boundary) and `reportDropped`.\n */\nexport function useConnected(): RefObject<boolean> {\n const connected = useRef(false);\n useLayoutEffect(() => {\n connected.current = true;\n return () => {\n connected.current = false;\n };\n }, []);\n return connected;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,cAAc,OAAsB;CAClD,IAAI,OAAO,gBAAgB,YAAY,YAAY,KAAK;MACnD,QAAQ,MAAM,KAAK;AAC1B;;;;;;;;AASA,SAAgB,eAAmC;CACjD,MAAM,YAAY,OAAO,KAAK;CAC9B,sBAAsB;EACpB,UAAU,UAAU;EACpB,aAAa;GACX,UAAU,UAAU;EACtB;CACF,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-presence.mjs","names":[],"sources":["../../src/internal/sync-presence.ts"],"sourcesContent":["/**\n * Makes a boolean attribute's presence match `present`. For group members that may hydrate after\n * their Root (`RadioGroup.Item`, `CheckboxGroup.Item` / `Parent`): hydration keeps server\n * attributes that differ from the client render (React only warns), and a member hydrating late\n * can render a different state than the server did.\n *\n * No `\"use client\"` directive: no client-only API (conventions 7.1).\n */\nexport function syncPresence(el: Element, name: string, present: boolean): void {\n if (el.hasAttribute(name) !== present) {\n if (present) el.setAttribute(name, \"\");\n else el.removeAttribute(name);\n }\n}\n\n/** `syncPresence` for each entry of `attributes`, in order. */\nexport function syncPresences(el: Element, attributes: Readonly<Record<string, boolean>>): void {\n for (const [name, present] of Object.entries(attributes)) syncPresence(el, name, present);\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,aAAa,IAAa,MAAc,SAAwB;CAC9E,IAAI,GAAG,aAAa,IAAI,MAAM,SAAS;EACrC,IAAI,SAAS,GAAG,aAAa,MAAM,EAAE;OAChC,GAAG,gBAAgB,IAAI;CAC9B;AACF;;AAGA,SAAgB,cAAc,IAAa,YAAqD;CAC9F,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,UAAU,GAAG,aAAa,IAAI,MAAM,OAAO;AAC1F"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-warm.mjs","names":[],"sources":["../../src/internal/tooltip-warm.ts"],"sourcesContent":["// Tooltip's skip-delay rule on the native `interestfor` path (design/components/tooltip.md 6,\n// conventions 12): while any tooltip is showing, the inline `interest-delay-start` of a flagged\n// Trigger computes to 0. No \"use client\" directive: constants only (conventions 7.1).\n\n/** Registered, non-inherited: `1` on the marked triggers while a tooltip is showing, else `0`. */\nconst TOOLTIP_WARM_PROPERTY = \"--fsui-tooltip-warm\";\n/** The marker a flagged Trigger renders; the shipped rule matches nothing else. */\nexport const TOOLTIP_TRIGGER_MARKER = \"data-fsui-tooltip-trigger\";\n/** The dedupe key of the shipped rule (`<style href precedence>`). */\nexport const TOOLTIP_WARM_HREF = \"@funstack/ui/tooltip-warm\";\n\n/**\n * The library's second shipped stylesheet: interaction timing, nothing visual (conventions 12's\n * selector exception: it matches only the library's marker and sets only a `--fsui-` registered\n * property the Trigger's inline style consumes). Its SHA-256 is `STYLE_SHA256` in\n * `@funstack/ui/csp` (a jsdom row recomputes it). When the stylesheet is missing (blocked by a\n * CSP, or never rendered) the property is unregistered and unset: `warmDelay`'s `var()` carries\n * its own `0` fallback, so the Trigger keeps its own `delay` (without it the declaration would be\n * invalid at computed-value time and the browser's `normal` delay would apply).\n */\nexport const TOOLTIP_WARM_RULES =\n \"/* @funstack/ui: tooltip skip-delay. Functional only: while a tooltip is showing, the next \" +\n \"one opens without its delay. */\\n\" +\n `@property ${TOOLTIP_WARM_PROPERTY} { syntax: \"<number>\"; inherits: false; initial-value: 0; }\\n` +\n `:root:has([role=\"tooltip\"]:popover-open) [${TOOLTIP_TRIGGER_MARKER}] { ${TOOLTIP_WARM_PROPERTY}: 1; }\\n`;\n\n/**\n * The inline `interest-delay-start` of a flagged Trigger: `delay` when cold, `0` when warm, and\n * `delay` when the stylesheet is missing (the explicit `0` fallback).\n */\nexport function warmDelay(delay: number): string {\n return `calc(${delay}ms * (1 - var(${TOOLTIP_WARM_PROPERTY}, 0)))`;\n}\n"],"mappings":";;AAKA,MAAM,wBAAwB;;AAE9B,MAAa,yBAAyB;;AAEtC,MAAa,oBAAoB;;;;;;;;;;AAWjC,MAAa,qBACX;YAEa,sBAAsB,yGACU,uBAAuB,MAAM,sBAAsB;;;;;AAMlG,SAAgB,UAAU,OAAuB;CAC/C,OAAO,QAAQ,MAAM,gBAAgB,sBAAsB;AAC7D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-ref.mjs","names":[],"sources":["../../src/internal/trigger-ref.ts"],"sourcesContent":["import type { RefObject } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The Roots that already warned about a second Trigger, keyed by their `triggerRef`. */\nconst warned = new WeakSet<RefObject<HTMLElement | null>>();\n\n/**\n * Registers `element` as the Root's one Trigger (`triggerRef`, last mounted wins) and returns\n * the ref cleanup. In development, a second Trigger mounting while another is registered\n * warns once per Root (popover.md 14.2): only the registered one is the popup's `source` (anchor,\n * focus return) and, in JS-free mode, the one whose `data-open` is kept current.\n */\nexport function registerTrigger(\n triggerRef: RefObject<HTMLElement | null>,\n element: HTMLElement,\n part: string,\n): () => void {\n // A Trigger's own cleanup clears the ref first (a remount, StrictMode, a ref change), so a\n // registered element here is another, still mounted Trigger.\n if (isDev && triggerRef.current !== null) {\n if (!warned.has(triggerRef)) {\n warned.add(triggerRef);\n console.error(\n `${part}: a second ${part} mounted in the same Root. A Root supports one ${part}: ` +\n \"the popup only follows the last one mounted (its anchor, focus return and, \" +\n `without an action, data-open). Render one ${part} per Root.`,\n );\n }\n }\n triggerRef.current = element;\n return () => {\n if (triggerRef.current === element) triggerRef.current = null;\n };\n}\n"],"mappings":";AAEA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,yBAAS,IAAI,QAAuC;;;;;;;AAQ1D,SAAgB,gBACd,YACA,SACA,MACY;CAGZ,IAAI,SAAS,WAAW,YAAY,MAC9B;MAAA,CAAC,OAAO,IAAI,UAAU,GAAG;GAC3B,OAAO,IAAI,UAAU;GACrB,QAAQ,MACN,GAAG,KAAK,aAAa,KAAK,iDAAiD,KAAK,yHAEjC,KAAK,WACtD;EACF;;CAEF,WAAW,UAAU;CACrB,aAAa;EACX,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;CAC3D;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
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 { reportDropped, useConnected } from \"./report-dropped.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.1): `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 `false`: runs\n * overlap, as with React's own `useTransition`. A pure trigger passes\n * `(whilePending ?? <its default>) === \"ignore\"`, read per render (#146).\n */\n readonly ignoreWhilePending?: boolean | 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). With overlapping runs, `then` runs\n * once, when the last run in flight settles, and only if the latest run resolved: it is the\n * latest run's `then` (#146 review F1). A rejection skips `then` and reaches\n * the nearest Error Boundary above the part; a run that a later run superseded, or any run\n * once the part unmounted or was hidden by `<Activity>`, passes its rejection to `reportError`\n * instead (conventions 2.4). 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), 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), and the steps\n * of the continuous controls (`Slider`, `NumberField`). A second `run` while one is in flight is\n * ignored only with `ignoreWhilePending` (a part whose `whilePending` is `\"ignore\"`, conventions\n * 2.5.1).\n *\n * Without it (`whilePending=\"run\"`, the steps) runs overlap, and the hook handles superseded\n * rejections as `useControllableAction` does: React keeps only the newest\n * thenable per `useTransition`, so the rejection of a run that a later run superseded reaches no\n * boundary. The hook passes it to `reportError` (`reportDropped`); the latest run's rejection\n * is rethrown inside the transition and reaches the boundary. In both modes, a latest rejection\n * that arrives after the part unmounted or was hidden by `<Activity>` is reported too (#152):\n * React would route it only through a render of the part.\n */\nexport function useActionTrigger(options: ActionTriggerOptions = {}): ActionTrigger {\n const { openGeneration, ignoreWhilePending = false } = options;\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 const connected = useConnected();\n // The latest run's continuation once it resolved, waiting for the other runs in flight to\n // settle. Cleared by every new run: only the latest run's outcome decides (#146 review F1).\n const resolvedThen = useRef<(() => void) | null>(null);\n\n // A run settled. When it was the last in flight, the latest run's continuation runs if that\n // run resolved; a rejected latest run (or a newer run since) left nothing to run.\n const settled = () => {\n inFlight.current--;\n if (inFlight.current > 0) return;\n const continuation = resolvedThen.current;\n resolvedThen.current = null;\n continuation?.();\n };\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 resolvedThen.current = null;\n startOwnTransition(async () => {\n try {\n await work();\n } catch (error) {\n // The latest run's rejection takes React's own route to the boundary while the part is\n // there to render it; otherwise React would drop it, as it drops a superseded one (2.4).\n const rethrow = id === latest.current && connected.current;\n if (!rethrow) reportDropped(error);\n settled();\n if (rethrow) throw error;\n return;\n }\n if (id === latest.current && then !== undefined) {\n resolvedThen.current = () => {\n if (openGeneration !== undefined && openGeneration() !== generation) return;\n then();\n };\n }\n settled();\n });\n return true;\n };\n\n return { pending, run };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuDA,SAAgB,iBAAiB,UAAgC,CAAC,GAAkB;CAClF,MAAM,EAAE,gBAAgB,qBAAqB,UAAU;CAEvD,MAAM,CAAC,SAAS,sBAAsB,cAAc;CACpD,MAAM,SAAS,OAAO,CAAC;CAGvB,MAAM,WAAW,OAAO,CAAC;CACzB,MAAM,YAAY,aAAa;CAG/B,MAAM,eAAe,OAA4B,IAAI;CAIrD,MAAM,gBAAgB;EACpB,SAAS;EACT,IAAI,SAAS,UAAU,GAAG;EAC1B,MAAM,eAAe,aAAa;EAClC,aAAa,UAAU;EACvB,eAAe;CACjB;CAEA,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,aAAa,UAAU;EACvB,mBAAmB,YAAY;GAC7B,IAAI;IACF,MAAM,KAAK;GACb,SAAS,OAAO;IAGd,MAAM,UAAU,OAAO,OAAO,WAAW,UAAU;IACnD,IAAI,CAAC,SAAS,cAAc,KAAK;IACjC,QAAQ;IACR,IAAI,SAAS,MAAM;IACnB;GACF;GACA,IAAI,OAAO,OAAO,WAAW,SAAS,KAAA,GACpC,aAAa,gBAAgB;IAC3B,IAAI,mBAAmB,KAAA,KAAa,eAAe,MAAM,YAAY;IACrE,KAAK;GACP;GAEF,QAAQ;EACV,CAAC;EACD,OAAO;CACT;CAEA,OAAO;EAAE;EAAS;CAAI;AACxB"}
|
|
@@ -1 +0,0 @@
|
|
|
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,qBACA,UAAU,cACV,KACA,iBACA,MACA,kBACE;CAGJ,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,MAAM,IAAI;EACV,UAAU;EACV,UAAU,IAAI;EACd,IAAI,IAAI;EACR;CACF,CAAC;CACD,MAAM,WAAW,MAAM;CAEvB,MAAM,EAAE,YAAY,SAAS,UAAU,mBAAmB,sBAGxD;EACA,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ;EACR;EACA,MAAM;GAAE;GAAW,MAAM;EAAU;CACrC,CAAC;CAGD,oBAAoB,UAAU;CAI9B,MAAM,QAAQ,kBAAkB,KAAA;CAChC,MAAM,qBAAqB,kBAAkB,QAAQ,CAAC;CAEtD,MAAM,WAAW,iBAAiB;EAChC,MAAM;EACN;EACA,SAAS;EAET,gBAAgB,YAAY,KAAA,IAAa,kBAAkB,QAAS,KAAA;EACpE,eAAe,QAAQ,qBAAqB,KAAA;EAC5C;EACA,mBAAmB,MAAM,UACvB,SAAS,MAAM,oBAAoB,OAAO,EAAE,QAAQ,WAAW,CAAC,CAAC;CACrE,CAAC;CAqCD,OAAO;EAAE;EAAY;EAAS;EAAU;EAAoB,KAnChD,cAAgC,UAAU,MAAM,GAmCE;EAAG,cAAA;GAhC/D,GAAG,gBAAgB,KAAK;GACxB,MAAM;GACN,GAAI,SAAS,KAAA,KAAa,EAAE,KAAK;GAGjC,SAAS;GACT,gBAAgB,KAAA;GAGhB,GAAI,SAAS,EAAE,eAAe,KAAA,EAAU;GACxC,gBAAgB,KAAA;GAGhB;GACA,gBAAgB,SAAS,UAAU;GACnC,GAAI,SAAS,EAAE,sBAAsB,SAAS,kBAAkB,EAAE;GAClE,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;GAClC,WAAW,UAAyC;IAGlD,IAAI,UAAU;IACd,MAAM,cAAc,MAAM;IAE1B,qBACE,mBACM,SAAS,CAAC,YAAY,oBAAoB,aAAa,EAAE,QAAQ,WAAW,CAAC,CAAC,GACpF,SACF;GACF;EAG0E;CAAE;AAChF"}
|
|
@@ -1 +0,0 @@
|
|
|
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 { reportDropped, useConnected } from \"./report-dropped.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 * With a reducer, uncontrolled state is also committed through it: once every overlapping\n * dispatch has settled, the dispatches that resolved are folded onto the committed value in\n * dispatch order, and a rejected one leaves no trace (#150). Without one, the latest dispatch's\n * `next` is committed when it resolves (the latest-dispatch guard). A dispatch made with\n * `{ whole: true }` bypasses the reducer: its `next` replaces the value in both places.\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 /**\n * Runs the action inside the hook's transition with optimistic feedback. `options.whole`\n * (internal, never part of a public details type): `next` replaces the value instead of going\n * through `reducer`, in the optimistic step and in the uncontrolled replay of the burst. For a\n * dispatch whose `next` is absolute rather than a per-item step (CheckboxGroup's form reset,\n * Accordion's mount reconciliation). Without a `reducer` every dispatch is already whole.\n */\n readonly dispatch: (next: T, details: Details, options?: DispatchOptions) => 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 * A fact (#148, design/components/overlay-open-change.md 2.5): `next` is already true in the DOM\n * (the browser hid a popup the library did not hide). Supersedes every dispatch in flight (none\n * of them commits uncontrolled state; a later rejection is reported, not thrown), makes `next`\n * the in-flight intent, drops the optimistic patches of those dispatches, and in uncontrolled\n * mode writes the committed value. Never calls the action. Every write is urgent: call it from\n * the platform event's listener, outside any transition, so the change commits in that event's\n * own (discrete) commit. Advances `epoch`.\n */\n readonly adoptFact: (next: T) => void;\n /**\n * How many facts were adopted (`adoptFact`). It changes in the fact's commit even when nothing\n * else does (a controlled parent that keeps its value), so a memoised context that includes it\n * re-renders its consumers, and their effects can re-apply the value to the DOM.\n */\n readonly epoch: number;\n}\n\n/** Per-dispatch options of `ControllableAction.dispatch`. Internal. */\nexport interface DispatchOptions {\n /** Adopt `next` whole instead of applying `reducer` (see `dispatch`). Default `false`. */\n readonly whole?: boolean | undefined;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** One uncontrolled reducer-mode dispatch of a burst; `resolved` once its action resolved. */\ninterface BurstEntry<T, Details> {\n readonly next: T;\n readonly details: Details;\n readonly reducer: (prev: T, next: T, details: Details) => T;\n /** `next` is adopted whole (`DispatchOptions.whole`), not reduced. */\n readonly whole: boolean;\n resolved: boolean;\n}\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 reporting of the\n * rejections React would drop: superseded ones, and the latest one once the owner left\n * (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 const [internal, setInternal] = useState<T>(\n defaultValue === undefined ? initialValue : defaultValue,\n );\n const isControlled = controlled !== undefined;\n const committed = isControlled ? controlled : internal;\n // The fact epoch (`adoptFact`): urgent state. A patch carries the epoch of its dispatch and the\n // reducer of the render ignores it once the render's epoch is newer: React re-applies pending\n // optimistic updates on every render with that render's reducer, so one urgent `setEpoch` drops\n // every patch of a superseded dispatch in the fact's own commit (probed, issue-148 memo). The\n // passthrough stays the plain committed value: an object passthrough (`{ value, epoch }`, the\n // design's sketch) defeats React's bailout of a render whose state did not change, which an\n // inline ref re-run on every render turns into an update loop.\n const [epoch, setEpoch] = useState(0);\n const epochRef = useRef(0);\n const [optimistic, setOptimistic] = useOptimistic(\n committed,\n (prev: T, patch: { next: T; details: Details; epoch: number; whole: boolean }) =>\n patch.epoch < epoch\n ? prev\n : reducer && !patch.whole\n ? reducer(prev, patch.next, patch.details)\n : 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 /** The uncontrolled reducer-mode dispatches of the current burst (overlapping), in order. */\n const burst = useRef<BurstEntry<T, Details>[]>([]);\n const connected = useConnected();\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, reducer });\n\n /**\n * Marks a dispatch settled. When it was the last one in flight, the uncontrolled reducer-mode\n * dispatches of the burst that resolved are committed, in dispatch order (see `reducer`).\n */\n const settle = useCallback((): void => {\n inFlight.current.count -= 1;\n if (inFlight.current.count > 0) return;\n inFlight.current.next = undefined;\n const resolved = burst.current.filter((entry) => entry.resolved);\n burst.current = [];\n if (resolved.length === 0) return;\n startTransition(() =>\n setInternal((prev) =>\n resolved.reduce(\n (value, entry) =>\n entry.whole ? entry.next : entry.reducer(value, entry.next, entry.details),\n prev,\n ),\n ),\n );\n }, []);\n\n const dispatch = useCallback(\n (next: T, details: Details, options?: DispatchOptions): void => {\n const whole = options?.whole ?? false;\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, reducer } = props.current;\n const id = ++latest.current;\n const dispatchEpoch = epochRef.current;\n inFlight.current.count += 1;\n inFlight.current.next = next;\n // Uncontrolled with a reducer: committed from the burst once every dispatch settled.\n const entry: BurstEntry<T, Details> | null =\n !isControlled && reducer ? { next, details, reducer, whole, resolved: false } : null;\n if (entry) burst.current.push(entry);\n startOwnTransition(async () => {\n for (const type of transitionTypes?.(next, prev, details) ?? []) addTransitionType(type);\n setOptimistic({ next, details, epoch: dispatchEpoch, whole });\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 while the\n // owner is there to render it. React drops a superseded one (it keeps only the newest\n // thenable) and one whose owner unmounted or is hidden: reported instead (2.4, #152).\n if (id === latest.current && connected.current) throw error;\n reportDropped(error);\n return;\n }\n if (entry) entry.resolved = true;\n settle();\n if (!isControlled && !entry && id === latest.current) {\n startTransition(() => setInternal(next));\n }\n });\n },\n [props, settle, setOptimistic, connected],\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 const adoptFact = useCallback(\n (next: T): void => {\n // Supersede: no dispatch in flight is the latest any more, so none commits and a later\n // rejection is reported (2.4). Their settles still count down `inFlight`.\n latest.current += 1;\n if (inFlight.current.count > 0) inFlight.current.next = next;\n burst.current = [];\n epochRef.current += 1;\n setEpoch(epochRef.current);\n if (!props.current.isControlled) setInternal(next);\n },\n [props],\n );\n\n return useMemo(\n () => ({ committed, optimistic, pending, dispatch, latestInFlight, adopt, adoptFact, epoch }),\n [committed, optimistic, pending, dispatch, latestInFlight, adopt, adoptFact, epoch],\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":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
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 * (a fact, an urgent commit) runs none (design 4.4, overlay-open-change.md 2.8).\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 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-form-owner-event.mjs","names":[],"sources":["../../src/internal/use-form-owner-event.ts"],"sourcesContent":["\"use client\";\nimport { useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\n\n/** A form-associated element whose form owner the hook follows. */\nexport type FormAssociatedElement =\n | HTMLInputElement\n | HTMLFieldSetElement\n | HTMLSelectElement\n | HTMLTextAreaElement;\n\ninterface Subscription {\n readonly form: HTMLFormElement;\n readonly listener: (event: Event) => void;\n}\n\n/**\n * Stable subscription to `type` on the form owner of `ref.current` (conventions 3.8 rule 4,\n * generalised for Field, design/components/field-form.md 14).\n *\n * - The owner (`element.form`, which honours the `form` attribute) is re-read after every commit,\n * but the listener is moved only when the owner changed. It is never removed and re-added on an\n * ordinary re-render: React's automatic reset after a successful `<form action>` runs in the\n * commit's mutation phase, between an effect's cleanup and its next run, so a subscription that\n * followed every commit would miss it.\n * - `handler` always sees the latest committed render's values (`useEffectEvent`).\n * - `ref.current` may be any element: one without a `form` property has no owner.\n */\nexport function useFormOwnerEvent(\n ref: RefObject<Element | null>,\n type: string,\n handler: (event: Event, form: HTMLFormElement) => void,\n): void {\n const handle = useEffectEvent((event: Event, form: HTMLFormElement) => {\n handler(event, form);\n });\n const subscription = useRef<Subscription | null>(null);\n\n // No deps on purpose: follows the form owner after every commit (a changed `form` attribute, the\n // element moved to another form), but re-subscribes only when the owner actually changed.\n useLayoutEffect(() => {\n const element = ref.current as Partial<FormAssociatedElement> | null;\n const form = element?.form ?? null;\n const current = subscription.current;\n if (current !== null && current.form === form) return;\n if (current !== null) current.form.removeEventListener(type, current.listener);\n subscription.current = null;\n if (form === null) return;\n const listener = (event: Event) => handle(event, form);\n form.addEventListener(type, listener);\n subscription.current = { form, listener };\n });\n\n // The only place the subscription is torn down: unmount (and StrictMode's simulated unmount,\n // after which the effect above subscribes again).\n useLayoutEffect(\n () => () => {\n const current = subscription.current;\n if (current !== null) current.form.removeEventListener(type, current.listener);\n subscription.current = null;\n },\n [type],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,SAAgB,kBACd,KACA,MACA,SACM;CACN,MAAM,SAAS,gBAAgB,OAAc,SAA0B;EACrE,QAAQ,OAAO,IAAI;CACrB,CAAC;CACD,MAAM,eAAe,OAA4B,IAAI;CAIrD,sBAAsB;EAEpB,MAAM,OADU,IAAI,SACE,QAAQ;EAC9B,MAAM,UAAU,aAAa;EAC7B,IAAI,YAAY,QAAQ,QAAQ,SAAS,MAAM;EAC/C,IAAI,YAAY,MAAM,QAAQ,KAAK,oBAAoB,MAAM,QAAQ,QAAQ;EAC7E,aAAa,UAAU;EACvB,IAAI,SAAS,MAAM;EACnB,MAAM,YAAY,UAAiB,OAAO,OAAO,IAAI;EACrD,KAAK,iBAAiB,MAAM,QAAQ;EACpC,aAAa,UAAU;GAAE;GAAM;EAAS;CAC1C,CAAC;CAID,4BACc;EACV,MAAM,UAAU,aAAa;EAC7B,IAAI,YAAY,MAAM,QAAQ,KAAK,oBAAoB,MAAM,QAAQ,QAAQ;EAC7E,aAAa,UAAU;CACzB,GACA,CAAC,IAAI,CACP;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-interest-dismiss.mjs","names":[],"sources":["../../src/internal/use-interest-dismiss.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef } from \"react\";\nimport { eventSource } from \"./invokers.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport type { PopoverRootValue } from \"./use-overlay-root.js\";\n\nexport interface InterestDismiss {\n /** `interest` at the popup: remembers the button that has interest in it. */\n onInterest(event: Event): void;\n /** `loseinterest` at the popup: the lost-interest hide (see `useInterestDismiss`). */\n onLoseInterest(event: Event): void;\n /** The opening `beforetoggle` the Root routes: whether it is the interest invoker's open. */\n noteOpen(event: ToggleEvent): void;\n /** The popup's `toggle` reported it hidden: the interest open is over. */\n noteClosed(): void;\n /** Whether the hide whose `toggle` arrived was the lost-interest hide; clears it. */\n takeLostInterest(): boolean;\n /** The popup element detached: cancels a pending hide and forgets everything. Stable. */\n reset(): void;\n}\n\n/**\n * Lost interest of an `interestfor` button naming the popup (library mode; Chromium; popover.md\n * lost-interest amendment), for `usePopoverPopup`. The platform hides only a popover its own\n * interest show opened (`invokedVia == kInterest`), and the library cancels that show and\n * re-shows with `showPopover({ source })`, so the platform never hides: the library does, as a\n * dismissal. Chromium also fires `loseinterest` from inside every hide of the popup while the\n * button has interest (Escape, script, the library's own close), before the state flips, and a\n * `hidePopover()` called from there re-enters the hide and loses its `toggle`: the hide waits one\n * task and runs only if the popup is still shown and still meant to be open, and returns no focus\n * to the Trigger. A pending interest open is cancelled instead.\n */\nexport function useInterestDismiss(ctx: PopoverRootValue): InterestDismiss {\n const isLibrary = ctx.mode === \"library\";\n const { popupRef } = ctx;\n // The button that has interest in the popup (`InterestEvent.source`), whether the current open\n // was that button's interest open, the task that hides the popup on its lost interest, and\n // whether the hide in flight is that one.\n const interestInvoker = useRef<Element | null>(null);\n const interestOpen = useRef(false);\n const interestHideTask = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const interestHide = useRef(false);\n\n const onInterest = (event: Event): void => {\n const element = popupRef.current;\n if (!isLibrary || element === null || event.target !== element) return;\n interestInvoker.current = eventSource(event);\n };\n\n const onLoseInterest = (event: Event): void => {\n const element = popupRef.current;\n if (!isLibrary || element === null || event.target !== element) return;\n const source = eventSource(event);\n if (source === null || source !== interestInvoker.current) return;\n interestInvoker.current = null;\n if (!interestOpen.current) return;\n if (isPopoverOpen(element)) {\n clearTimeout(interestHideTask.current);\n interestHideTask.current = setTimeout(() => {\n interestHideTask.current = undefined;\n if (!isPopoverOpen(element) || !ctx.intended()) return;\n // Interest regained meanwhile (the pointer came back): the popup stays.\n if (interestInvoker.current !== null) return;\n // Recorded right before the hide, so its one-task clear cannot run first.\n ctx.recordCloseIntent({ reason: \"dismiss\", event });\n interestHide.current = true;\n element.hidePopover();\n }, 0);\n } else if (ctx.intended()) {\n interestOpen.current = false;\n ctx.requestClose(event, \"dismiss\");\n }\n };\n\n const noteOpen = (event: ToggleEvent): void => {\n // Chromium dispatches `interest` and then the interest show in one step, so a show whose\n // `source` is the remembered interest invoker is that button's interest open.\n const source = eventSource(event);\n interestOpen.current = source !== null && source === interestInvoker.current;\n };\n\n const noteClosed = (): void => {\n interestOpen.current = false;\n };\n\n const takeLostInterest = (): boolean => {\n const lostInterest = interestHide.current;\n interestHide.current = false;\n return lostInterest;\n };\n\n const reset = useCallback((): void => {\n clearTimeout(interestHideTask.current);\n interestHideTask.current = undefined;\n interestHide.current = false;\n interestInvoker.current = null;\n interestOpen.current = false;\n }, []);\n\n return { onInterest, onLoseInterest, noteOpen, noteClosed, takeLostInterest, reset };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAAgB,mBAAmB,KAAwC;CACzE,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,aAAa;CAIrB,MAAM,kBAAkB,OAAuB,IAAI;CACnD,MAAM,eAAe,OAAO,KAAK;CACjC,MAAM,mBAAmB,OAAkD,KAAA,CAAS;CACpF,MAAM,eAAe,OAAO,KAAK;CAEjC,MAAM,cAAc,UAAuB;EACzC,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,aAAa,YAAY,QAAQ,MAAM,WAAW,SAAS;EAChE,gBAAgB,UAAU,YAAY,KAAK;CAC7C;CAEA,MAAM,kBAAkB,UAAuB;EAC7C,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,aAAa,YAAY,QAAQ,MAAM,WAAW,SAAS;EAChE,MAAM,SAAS,YAAY,KAAK;EAChC,IAAI,WAAW,QAAQ,WAAW,gBAAgB,SAAS;EAC3D,gBAAgB,UAAU;EAC1B,IAAI,CAAC,aAAa,SAAS;EAC3B,IAAI,cAAc,OAAO,GAAG;GAC1B,aAAa,iBAAiB,OAAO;GACrC,iBAAiB,UAAU,iBAAiB;IAC1C,iBAAiB,UAAU,KAAA;IAC3B,IAAI,CAAC,cAAc,OAAO,KAAK,CAAC,IAAI,SAAS,GAAG;IAEhD,IAAI,gBAAgB,YAAY,MAAM;IAEtC,IAAI,kBAAkB;KAAE,QAAQ;KAAW;IAAM,CAAC;IAClD,aAAa,UAAU;IACvB,QAAQ,YAAY;GACtB,GAAG,CAAC;EACN,OAAO,IAAI,IAAI,SAAS,GAAG;GACzB,aAAa,UAAU;GACvB,IAAI,aAAa,OAAO,SAAS;EACnC;CACF;CAEA,MAAM,YAAY,UAA6B;EAG7C,MAAM,SAAS,YAAY,KAAK;EAChC,aAAa,UAAU,WAAW,QAAQ,WAAW,gBAAgB;CACvE;CAEA,MAAM,mBAAyB;EAC7B,aAAa,UAAU;CACzB;CAEA,MAAM,yBAAkC;EACtC,MAAM,eAAe,aAAa;EAClC,aAAa,UAAU;EACvB,OAAO;CACT;CAUA,OAAO;EAAE;EAAY;EAAgB;EAAU;EAAY;EAAkB,OAR/D,kBAAwB;GACpC,aAAa,iBAAiB,OAAO;GACrC,iBAAiB,UAAU,KAAA;GAC3B,aAAa,UAAU;GACvB,gBAAgB,UAAU;GAC1B,aAAa,UAAU;EACzB,GAAG,CAAC,CAE6E;CAAE;AACrF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-modal-registration.mjs","names":[],"sources":["../../src/internal/use-modal-registration.ts"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect } from \"react\";\nimport { pushModal, removeModal } from \"./modal-registry.js\";\n\nfunction isModal(dialog: HTMLDialogElement): boolean {\n if (!dialog.isConnected || !dialog.open) return false;\n try {\n return dialog.matches(\":modal\");\n } catch {\n return false;\n }\n}\n\n/**\n * Keeps the modal registry (`modal-registry.ts`) in step with a `<dialog>`: registered while it\n * is open as a modal (`showModal()`), removed when it closes or unmounts. Reads the DOM truth\n * (`:modal`) instead of the component's state, so every way of opening counts.\n *\n * `beforetoggle` fires synchronously inside `showModal()` / `close()`, before the state changes,\n * so that check runs a microtask later; `toggle` and `close` re-check.\n */\nexport function useModalRegistration(dialog: HTMLDialogElement | null): void {\n useLayoutEffect(() => {\n if (dialog === null) return;\n let active = true;\n const sync = (): void => {\n if (!active) return;\n if (isModal(dialog)) pushModal(dialog);\n else removeModal(dialog);\n };\n const syncSoon = (): void => queueMicrotask(sync);\n dialog.addEventListener(\"beforetoggle\", syncSoon);\n dialog.addEventListener(\"toggle\", sync);\n dialog.addEventListener(\"close\", sync);\n sync();\n return () => {\n active = false;\n dialog.removeEventListener(\"beforetoggle\", syncSoon);\n dialog.removeEventListener(\"toggle\", sync);\n dialog.removeEventListener(\"close\", sync);\n removeModal(dialog);\n };\n }, [dialog]);\n}\n"],"mappings":";;;;AAIA,SAAS,QAAQ,QAAoC;CACnD,IAAI,CAAC,OAAO,eAAe,CAAC,OAAO,MAAM,OAAO;CAChD,IAAI;EACF,OAAO,OAAO,QAAQ,QAAQ;CAChC,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;AAUA,SAAgB,qBAAqB,QAAwC;CAC3E,sBAAsB;EACpB,IAAI,WAAW,MAAM;EACrB,IAAI,SAAS;EACb,MAAM,aAAmB;GACvB,IAAI,CAAC,QAAQ;GACb,IAAI,QAAQ,MAAM,GAAG,UAAU,MAAM;QAChC,YAAY,MAAM;EACzB;EACA,MAAM,iBAAuB,eAAe,IAAI;EAChD,OAAO,iBAAiB,gBAAgB,QAAQ;EAChD,OAAO,iBAAiB,UAAU,IAAI;EACtC,OAAO,iBAAiB,SAAS,IAAI;EACrC,KAAK;EACL,aAAa;GACX,SAAS;GACT,OAAO,oBAAoB,gBAAgB,QAAQ;GACnD,OAAO,oBAAoB,UAAU,IAAI;GACzC,OAAO,oBAAoB,SAAS,IAAI;GACxC,YAAY,MAAM;EACpB;CACF,GAAG,CAAC,MAAM,CAAC;AACb"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|