@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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createActionDetails } from "../internal/action/action-details.mjs";
|
|
3
|
+
import { useLatest } from "../internal/use-latest.mjs";
|
|
4
|
+
import { callUrgentHandler } from "../internal/action/call-urgent-handler.mjs";
|
|
5
|
+
import { useCallback, useDeferredValue, useInsertionEffect, useRef, useState } from "react";
|
|
6
|
+
//#region src/combobox/use-combobox-text.ts
|
|
7
|
+
/**
|
|
8
|
+
* The text of a combobox, the library's urgent lane (design/components/combobox.md 2.2 and 4):
|
|
9
|
+
* the controlled or internal `inputValue`, its deferred `query`, and the write that calls
|
|
10
|
+
* `onInputValueChange` synchronously, outside any transition.
|
|
11
|
+
*/
|
|
12
|
+
function useComboboxText({ inputValue, defaultInputValue, onInputValueChange }) {
|
|
13
|
+
const latest = useLatest({
|
|
14
|
+
inputValue,
|
|
15
|
+
onInputValueChange
|
|
16
|
+
});
|
|
17
|
+
const [internalText, setInternalText] = useState(() => defaultInputValue ?? inputValue ?? "");
|
|
18
|
+
const text = inputValue ?? internalText;
|
|
19
|
+
const query = useDeferredValue(text);
|
|
20
|
+
const stale = text !== query;
|
|
21
|
+
const textRef = useRef(text);
|
|
22
|
+
useInsertionEffect(() => {
|
|
23
|
+
textRef.current = text;
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
text,
|
|
27
|
+
query,
|
|
28
|
+
stale,
|
|
29
|
+
textRef,
|
|
30
|
+
writeText: useCallback((next, reason, event) => {
|
|
31
|
+
const props = latest.current;
|
|
32
|
+
if (props.inputValue === void 0) setInternalText(next);
|
|
33
|
+
textRef.current = next;
|
|
34
|
+
const handler = props.onInputValueChange;
|
|
35
|
+
if (handler === void 0) return;
|
|
36
|
+
callUrgentHandler(handler, next, createActionDetails(event, { reason }));
|
|
37
|
+
}, [latest])
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useComboboxText };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=use-combobox-text.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-combobox-text.mjs","names":[],"sources":["../../src/combobox/use-combobox-text.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useDeferredValue, useInsertionEffect, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { callUrgentHandler } from \"../internal/action/call-urgent-handler.js\";\nimport type { ChangeReason, UrgentChangeHandler } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport type { ComboboxInputValueChangeDetails } from \"./combobox-root.js\";\n\nexport interface ComboboxTextOptions {\n /** The Root's props of the text. */\n readonly inputValue: string | undefined;\n readonly defaultInputValue: string | undefined;\n readonly onInputValueChange:\n | UrgentChangeHandler<string, ComboboxInputValueChangeDetails>\n | undefined;\n}\n\nexport interface ComboboxText {\n /** The text in the input (urgent): the controlled `inputValue`, else the internal text. */\n readonly text: string;\n /** `useDeferredValue(text)`: the text the mounted results are for. */\n readonly query: string;\n /** `text !== query`. */\n readonly stale: boolean;\n /** The latest text, for handlers, effects and code after an `await`. */\n readonly textRef: RefObject<string>;\n /** Writes the text and calls `onInputValueChange` (design 2.2). */\n readonly writeText: (next: string, reason: ChangeReason, event: Event | undefined) => void;\n}\n\n/**\n * The text of a combobox, the library's urgent lane (design/components/combobox.md 2.2 and 4):\n * the controlled or internal `inputValue`, its deferred `query`, and the write that calls\n * `onInputValueChange` synchronously, outside any transition.\n */\nexport function useComboboxText({\n inputValue,\n defaultInputValue,\n onInputValueChange,\n}: ComboboxTextOptions): ComboboxText {\n const latest = useLatest({ inputValue, onInputValueChange });\n\n const [internalText, setInternalText] = useState(() => defaultInputValue ?? inputValue ?? \"\");\n const text = inputValue ?? internalText;\n const query = useDeferredValue(text);\n const stale = text !== query;\n const textRef = useRef(text);\n useInsertionEffect(() => {\n textRef.current = text;\n });\n\n /**\n * Writes the text (urgent) and calls `onInputValueChange` synchronously (design 2.2), under the\n * handler rule (`callUrgentHandler`: a throw or a returned promise's rejection goes to\n * `reportError`, the write above stands).\n */\n const writeText = useCallback(\n (next: string, reason: ChangeReason, event: Event | undefined): void => {\n const props = latest.current;\n if (props.inputValue === undefined) setInternalText(next);\n textRef.current = next;\n const handler = props.onInputValueChange;\n if (handler === undefined) return;\n callUrgentHandler(handler, next, createActionDetails(event, { reason }));\n },\n [latest],\n );\n\n return { text, query, stale, textRef, writeText };\n}\n"],"mappings":";;;;;;;;;;;AAoCA,SAAgB,gBAAgB,EAC9B,YACA,mBACA,sBACoC;CACpC,MAAM,SAAS,UAAU;EAAE;EAAY;CAAmB,CAAC;CAE3D,MAAM,CAAC,cAAc,mBAAmB,eAAe,qBAAqB,cAAc,EAAE;CAC5F,MAAM,OAAO,cAAc;CAC3B,MAAM,QAAQ,iBAAiB,IAAI;CACnC,MAAM,QAAQ,SAAS;CACvB,MAAM,UAAU,OAAO,IAAI;CAC3B,yBAAyB;EACvB,QAAQ,UAAU;CACpB,CAAC;CAmBD,OAAO;EAAE;EAAM;EAAO;EAAO;EAAS,WAZpB,aACf,MAAc,QAAsB,UAAmC;GACtE,MAAM,QAAQ,OAAO;GACrB,IAAI,MAAM,eAAe,KAAA,GAAW,gBAAgB,IAAI;GACxD,QAAQ,UAAU;GAClB,MAAM,UAAU,MAAM;GACtB,IAAI,YAAY,KAAA,GAAW;GAC3B,kBAAkB,SAAS,MAAM,oBAAoB,OAAO,EAAE,OAAO,CAAC,CAAC;EACzE,GACA,CAAC,MAAM,CAGqC;CAAE;AAClD"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { sortByDocumentOrder } from "../internal/dom-order.mjs";
|
|
3
|
+
import { useRegisterCount } from "../internal/use-register-count.mjs";
|
|
2
4
|
import { useCallback, useRef, useState } from "react";
|
|
3
5
|
//#region src/combobox/use-option-registry.ts
|
|
4
6
|
const isDev = process.env.NODE_ENV !== "production";
|
|
@@ -9,9 +11,8 @@ const isDev = process.env.NODE_ENV !== "production";
|
|
|
9
11
|
function useOptionRegistry(labels) {
|
|
10
12
|
const [registry] = useState(() => /* @__PURE__ */ new Map());
|
|
11
13
|
const [optionCount, setOptionCount] = useState(0);
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const [labelCount, setLabelCount] = useState(0);
|
|
14
|
+
const { count: statusCount, register: registerStatus, countRef: statusCountRef } = useRegisterCount();
|
|
15
|
+
const { count: labelCount, register: registerLabel } = useRegisterCount();
|
|
15
16
|
const warnedDuplicate = useRef(false);
|
|
16
17
|
return {
|
|
17
18
|
registry,
|
|
@@ -33,26 +34,15 @@ function useOptionRegistry(labels) {
|
|
|
33
34
|
setOptionCount(registry.size);
|
|
34
35
|
};
|
|
35
36
|
}, [registry, labels]),
|
|
36
|
-
registerStatus
|
|
37
|
-
|
|
38
|
-
setStatusCount((count) => count + 1);
|
|
39
|
-
return () => {
|
|
40
|
-
statusCountRef.current -= 1;
|
|
41
|
-
setStatusCount((count) => count - 1);
|
|
42
|
-
};
|
|
43
|
-
}, []),
|
|
44
|
-
registerLabel: useCallback(() => {
|
|
45
|
-
setLabelCount((count) => count + 1);
|
|
46
|
-
return () => setLabelCount((count) => count - 1);
|
|
47
|
-
}, []),
|
|
37
|
+
registerStatus,
|
|
38
|
+
registerLabel,
|
|
48
39
|
orderedOptions: useCallback(() => {
|
|
49
40
|
const options = [];
|
|
50
41
|
for (const [optionValue, entry] of registry) options.push({
|
|
51
42
|
value: optionValue,
|
|
52
43
|
...entry
|
|
53
44
|
});
|
|
54
|
-
options
|
|
55
|
-
return options;
|
|
45
|
+
return sortByDocumentOrder(options, (option) => option.element);
|
|
56
46
|
}, [registry])
|
|
57
47
|
};
|
|
58
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-option-registry.mjs","names":[],"sources":["../../src/combobox/use-option-registry.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { ComboboxOptionEntry } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface OrderedOption extends ComboboxOptionEntry {\n readonly value: string;\n}\n\nexport interface OptionRegistry {\n /** The mounted Options by value. */\n readonly registry: ReadonlyMap<string, ComboboxOptionEntry>;\n readonly optionCount: number;\n readonly statusCount: number;\n /**\n * The same count for the announcement effect: the open commit's passive effects can run before\n * the re-render the Status's registration scheduled (the race `registry` avoids for options).\n */\n readonly statusCountRef: RefObject<number>;\n readonly labelCount: number;\n readonly registerOption: (value: string, entry: ComboboxOptionEntry) => () => void;\n readonly registerStatus: () => () => void;\n readonly registerLabel: () => () => void;\n /** The registered Options in document order. */\n readonly orderedOptions: () => OrderedOption[];\n}\n\n/**\n * The Options, Statuses and Labels mounted in a Combobox (design/components/combobox.md 2, 6.5).\n * An Option's label is learnt into `labels` (design 2.3) as it registers.\n */\nexport function useOptionRegistry(labels: Map<string, string>): OptionRegistry {\n const [registry] = useState(() => new Map<string, ComboboxOptionEntry>());\n const [optionCount, setOptionCount] = useState(0);\n const
|
|
1
|
+
{"version":3,"file":"use-option-registry.mjs","names":[],"sources":["../../src/combobox/use-option-registry.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { sortByDocumentOrder } from \"../internal/dom-order.js\";\nimport { useRegisterCount } from \"../internal/use-register-count.js\";\nimport type { ComboboxOptionEntry } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface OrderedOption extends ComboboxOptionEntry {\n readonly value: string;\n}\n\nexport interface OptionRegistry {\n /** The mounted Options by value. */\n readonly registry: ReadonlyMap<string, ComboboxOptionEntry>;\n readonly optionCount: number;\n readonly statusCount: number;\n /**\n * The same count for the announcement effect: the open commit's passive effects can run before\n * the re-render the Status's registration scheduled (the race `registry` avoids for options).\n */\n readonly statusCountRef: RefObject<number>;\n readonly labelCount: number;\n readonly registerOption: (value: string, entry: ComboboxOptionEntry) => () => void;\n readonly registerStatus: () => () => void;\n readonly registerLabel: () => () => void;\n /** The registered Options in document order. */\n readonly orderedOptions: () => OrderedOption[];\n}\n\n/**\n * The Options, Statuses and Labels mounted in a Combobox (design/components/combobox.md 2, 6.5).\n * An Option's label is learnt into `labels` (design 2.3) as it registers.\n */\nexport function useOptionRegistry(labels: Map<string, string>): OptionRegistry {\n const [registry] = useState(() => new Map<string, ComboboxOptionEntry>());\n const [optionCount, setOptionCount] = useState(0);\n const {\n count: statusCount,\n register: registerStatus,\n countRef: statusCountRef,\n } = useRegisterCount();\n const { count: labelCount, register: registerLabel } = useRegisterCount();\n const warnedDuplicate = useRef(false);\n\n const registerOption = useCallback(\n (optionValue: string, entry: ComboboxOptionEntry) => {\n const existing = registry.get(optionValue);\n if (\n isDev &&\n !warnedDuplicate.current &&\n existing !== undefined &&\n existing.element !== entry.element &&\n existing.element.isConnected\n ) {\n warnedDuplicate.current = true;\n console.error(\n `Combobox.Option: two options have the value ${JSON.stringify(optionValue)}. ` +\n \"Option ids are derived from the value, so they must be unique within one Combobox.\",\n );\n }\n registry.set(optionValue, entry);\n labels.set(optionValue, entry.label ?? (entry.element.textContent ?? \"\").trim());\n setOptionCount(registry.size);\n return () => {\n if (registry.get(optionValue) === entry) registry.delete(optionValue);\n setOptionCount(registry.size);\n };\n },\n [registry, labels],\n );\n\n const orderedOptions = useCallback((): OrderedOption[] => {\n const options: OrderedOption[] = [];\n for (const [optionValue, entry] of registry) options.push({ value: optionValue, ...entry });\n return sortByDocumentOrder(options, (option) => option.element);\n }, [registry]);\n\n return {\n registry,\n optionCount,\n statusCount,\n statusCountRef,\n labelCount,\n registerOption,\n registerStatus,\n registerLabel,\n orderedOptions,\n };\n}\n"],"mappings":";;;;;AAOA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;AA4BvC,SAAgB,kBAAkB,QAA6C;CAC7E,MAAM,CAAC,YAAY,+BAAe,IAAI,IAAiC,CAAC;CACxE,MAAM,CAAC,aAAa,kBAAkB,SAAS,CAAC;CAChD,MAAM,EACJ,OAAO,aACP,UAAU,gBACV,UAAU,mBACR,iBAAiB;CACrB,MAAM,EAAE,OAAO,YAAY,UAAU,kBAAkB,iBAAiB;CACxE,MAAM,kBAAkB,OAAO,KAAK;CAmCpC,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,gBAvCqB,aACpB,aAAqB,UAA+B;GACnD,MAAM,WAAW,SAAS,IAAI,WAAW;GACzC,IACE,SACA,CAAC,gBAAgB,WACjB,aAAa,KAAA,KACb,SAAS,YAAY,MAAM,WAC3B,SAAS,QAAQ,aACjB;IACA,gBAAgB,UAAU;IAC1B,QAAQ,MACN,+CAA+C,KAAK,UAAU,WAAW,EAAE,qFAE7E;GACF;GACA,SAAS,IAAI,aAAa,KAAK;GAC/B,OAAO,IAAI,aAAa,MAAM,UAAU,MAAM,QAAQ,eAAe,GAAA,CAAI,KAAK,CAAC;GAC/E,eAAe,SAAS,IAAI;GAC5B,aAAa;IACX,IAAI,SAAS,IAAI,WAAW,MAAM,OAAO,SAAS,OAAO,WAAW;IACpE,eAAe,SAAS,IAAI;GAC9B;EACF,GACA,CAAC,UAAU,MAAM,CAeJ;EACb;EACA;EACA,gBAfqB,kBAAmC;GACxD,MAAM,UAA2B,CAAC;GAClC,KAAK,MAAM,CAAC,aAAa,UAAU,UAAU,QAAQ,KAAK;IAAE,OAAO;IAAa,GAAG;GAAM,CAAC;GAC1F,OAAO,oBAAoB,UAAU,WAAW,OAAO,OAAO;EAChE,GAAG,CAAC,QAAQ,CAWG;CACf;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createActionDetails } from "../internal/action-details.mjs";
|
|
3
|
-
import { useOverlayClose } from "../internal/use-overlay-close.mjs";
|
|
2
|
+
import { createActionDetails } from "../internal/action/action-details.mjs";
|
|
3
|
+
import { useOverlayClose } from "../internal/overlay/use-overlay-close.mjs";
|
|
4
4
|
import { useDialogContext } from "./dialog-context.mjs";
|
|
5
5
|
//#region src/dialog/dialog-close.tsx
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-close.mjs","names":[],"sources":["../../src/dialog/dialog-close.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { useOverlayClose } from \"../internal/use-overlay-close.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\n/**\n * State of `Dialog.Close`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogCloseState {\n /** The `action` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Details passed to `Dialog.Close`'s `action`. */\nexport interface DialogCloseDetails extends ActionDetails {\n /** The `value` the dialog closes with (`dialog.returnValue`); `\"\"` without `value`. */\n readonly returnValue: string;\n}\n\n/**\n * Props of `Dialog.Close`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogCloseProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"value\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this part's own transition (`data-pending` on the button), then closes the\n * dialog with `value` as `returnValue`: in library mode through the Root\n * (`openChangeAction(false)` awaited, view transition if set), in JS-free mode with\n * `close(value)`. A rejection reaches the nearest Error Boundary above the Close part and\n * leaves the dialog open. If the dialog was dismissed and opened again while the action ran,\n * the close is dropped: it belonged to the earlier open. Without `action` in JS-free mode the\n * button is a native `command=\"request-close\"` invoker.\n */\n action?: Action<[details: DialogCloseDetails]>;\n /**\n * What a click does while this part's `action` is pending. `\"ignore\"`: nothing (the click is\n * cancelled, `aria-disabled=\"true\"` meanwhile). `\"run\"`: the action runs again (`data-pending`\n * until every run has settled); the dialog closes once, when the last run settles and only if\n * the latest run resolved (a rejection leaves it open, as in `\"ignore\"` mode). No effect\n * without `action`.\n *\n * @defaultValue `\"ignore\"`\n */\n whilePending?: WhilePending;\n /** Becomes `dialog.returnValue` (and `details.returnValue` of `openChangeAction(false)`). */\n value?: string;\n /**\n * Never closes. Native `disabled` on a `<button>`; owned, so a `render` element cannot\n * re-enable it. With a link or component `render` whose click this part handles (library mode,\n * or with `action`), `aria-disabled=\"true\"` instead: the element stays focusable.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogCloseState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogCloseState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogCloseState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, DialogCloseState>;\n}\n\n/**\n * A close button: `<button type=\"button\" commandfor command=\"request-close\">`. In JS-free mode\n * without `action` the browser closes the dialog (a close request: `cancel`, then `close`), with\n * `value` as the `returnValue`. In library mode the click is always cancelled and the close goes\n * through the Root (`openChangeAction(false)` awaited, then `close(value)` in the commit, inside\n * the view transition if the Popup's `transition` is set). With `action` the action runs first in\n * this part's own transition (`data-pending` and `aria-disabled` on the button; a second click\n * meanwhile is ignored unless `whilePending=\"run\"`); a rejection leaves the dialog open.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,\n * `command`, `value`, `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,\n * `data-disabled`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogClose({\n action,\n whilePending,\n value,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogCloseProps) {\n const ctx = useDialogContext(\"Dialog.Close\");\n const { popupRef, recordCloseIntent } = ctx;\n const isLibrary = ctx.mode === \"library\";\n return useOverlayClose({\n part: \"Dialog.Close\",\n noun: \"dialog\",\n isLibrary,\n popupId: ctx.ids.popup,\n command: \"request-close\",\n openGeneration: ctx.openGeneration,\n action,\n whilePending,\n details: (event) => createActionDetails(event, { returnValue: value ?? \"\" }),\n close: (event) => {\n const returnValue = value ?? \"\";\n if (isLibrary) {\n // A library-owned close (design 2.3): awaited, then `close(returnValue)` in the commit. A\n // no-op when `false` is already intended (a repeated click, or a dismissal meanwhile).\n ctx.requestClose(event, \"activate\", returnValue);\n return;\n }\n // JS-free mode with `action`: a browser-owned close; there is no Root state to go through.\n const dialog = popupRef.current;\n if (dialog === null || !dialog.open) return;\n recordCloseIntent({ reason: \"activate\", event });\n dialog.close(returnValue);\n },\n ownProps: { value },\n disabled,\n className,\n style,\n children,\n render,\n rest,\n });\n}\n\nDialogClose.displayName = \"DialogClose\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,YAAY,EAC1B,QACA,cACA,OACA,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACgB;CACnB,MAAM,MAAM,iBAAiB,cAAc;CAC3C,MAAM,EAAE,UAAU,sBAAsB;CACxC,MAAM,YAAY,IAAI,SAAS;CAC/B,OAAO,gBAAgB;EACrB,MAAM;EACN,MAAM;EACN;EACA,SAAS,IAAI,IAAI;EACjB,SAAS;EACT,gBAAgB,IAAI;EACpB;EACA;EACA,UAAU,UAAU,oBAAoB,OAAO,EAAE,aAAa,SAAS,GAAG,CAAC;EAC3E,QAAQ,UAAU;GAChB,MAAM,cAAc,SAAS;GAC7B,IAAI,WAAW;IAGb,IAAI,aAAa,OAAO,YAAY,WAAW;IAC/C;GACF;GAEA,MAAM,SAAS,SAAS;GACxB,IAAI,WAAW,QAAQ,CAAC,OAAO,MAAM;GACrC,kBAAkB;IAAE,QAAQ;IAAY;GAAM,CAAC;GAC/C,OAAO,MAAM,WAAW;EAC1B;EACA,UAAU,EAAE,MAAM;EAClB;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH;AAEA,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"dialog-close.mjs","names":[],"sources":["../../src/dialog/dialog-close.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { useOverlayClose } from \"../internal/overlay/use-overlay-close.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\n/**\n * State of `Dialog.Close`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogCloseState {\n /** The `action` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Details passed to `Dialog.Close`'s `action`. */\nexport interface DialogCloseDetails extends ActionDetails {\n /** The `value` the dialog closes with (`dialog.returnValue`); `\"\"` without `value`. */\n readonly returnValue: string;\n}\n\n/**\n * Props of `Dialog.Close`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogCloseProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"value\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this part's own transition (`data-pending` on the button), then closes the\n * dialog with `value` as `returnValue`: in library mode through the Root\n * (`openChangeAction(false)` awaited, view transition if set), in JS-free mode with\n * `close(value)`. A rejection reaches the nearest Error Boundary above the Close part and\n * leaves the dialog open. If the dialog was dismissed and opened again while the action ran,\n * the close is dropped: it belonged to the earlier open. Without `action` in JS-free mode the\n * button is a native `command=\"request-close\"` invoker.\n */\n action?: Action<[details: DialogCloseDetails]>;\n /**\n * What a click does while this part's `action` is pending. `\"ignore\"`: nothing (the click is\n * cancelled, `aria-disabled=\"true\"` meanwhile). `\"run\"`: the action runs again (`data-pending`\n * until every run has settled); the dialog closes once, when the last run settles and only if\n * the latest run resolved (a rejection leaves it open, as in `\"ignore\"` mode). No effect\n * without `action`.\n *\n * @defaultValue `\"ignore\"`\n */\n whilePending?: WhilePending;\n /** Becomes `dialog.returnValue` (and `details.returnValue` of `openChangeAction(false)`). */\n value?: string;\n /**\n * Never closes. Native `disabled` on a `<button>`; owned, so a `render` element cannot\n * re-enable it. With a link or component `render` whose click this part handles (library mode,\n * or with `action`), `aria-disabled=\"true\"` instead: the element stays focusable.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogCloseState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogCloseState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogCloseState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, DialogCloseState>;\n}\n\n/**\n * A close button: `<button type=\"button\" commandfor command=\"request-close\">`. In JS-free mode\n * without `action` the browser closes the dialog (a close request: `cancel`, then `close`), with\n * `value` as the `returnValue`. In library mode the click is always cancelled and the close goes\n * through the Root (`openChangeAction(false)` awaited, then `close(value)` in the commit, inside\n * the view transition if the Popup's `transition` is set). With `action` the action runs first in\n * this part's own transition (`data-pending` and `aria-disabled` on the button; a second click\n * meanwhile is ignored unless `whilePending=\"run\"`); a rejection leaves the dialog open.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,\n * `command`, `value`, `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,\n * `data-disabled`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogClose({\n action,\n whilePending,\n value,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogCloseProps) {\n const ctx = useDialogContext(\"Dialog.Close\");\n const { popupRef, recordCloseIntent } = ctx;\n const isLibrary = ctx.mode === \"library\";\n return useOverlayClose({\n part: \"Dialog.Close\",\n noun: \"dialog\",\n isLibrary,\n popupId: ctx.ids.popup,\n command: \"request-close\",\n openGeneration: ctx.openGeneration,\n action,\n whilePending,\n details: (event) => createActionDetails(event, { returnValue: value ?? \"\" }),\n close: (event) => {\n const returnValue = value ?? \"\";\n if (isLibrary) {\n // A library-owned close (design 2.3): awaited, then `close(returnValue)` in the commit. A\n // no-op when `false` is already intended (a repeated click, or a dismissal meanwhile).\n ctx.requestClose(event, \"activate\", returnValue);\n return;\n }\n // JS-free mode with `action`: a browser-owned close; there is no Root state to go through.\n const dialog = popupRef.current;\n if (dialog === null || !dialog.open) return;\n recordCloseIntent({ reason: \"activate\", event });\n dialog.close(returnValue);\n },\n ownProps: { value },\n disabled,\n className,\n style,\n children,\n render,\n rest,\n });\n}\n\nDialogClose.displayName = \"DialogClose\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,YAAY,EAC1B,QACA,cACA,OACA,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACgB;CACnB,MAAM,MAAM,iBAAiB,cAAc;CAC3C,MAAM,EAAE,UAAU,sBAAsB;CACxC,MAAM,YAAY,IAAI,SAAS;CAC/B,OAAO,gBAAgB;EACrB,MAAM;EACN,MAAM;EACN;EACA,SAAS,IAAI,IAAI;EACjB,SAAS;EACT,gBAAgB,IAAI;EACpB;EACA;EACA,UAAU,UAAU,oBAAoB,OAAO,EAAE,aAAa,SAAS,GAAG,CAAC;EAC3E,QAAQ,UAAU;GAChB,MAAM,cAAc,SAAS;GAC7B,IAAI,WAAW;IAGb,IAAI,aAAa,OAAO,YAAY,WAAW;IAC/C;GACF;GAEA,MAAM,SAAS,SAAS;GACxB,IAAI,WAAW,QAAQ,CAAC,OAAO,MAAM;GACrC,kBAAkB;IAAE,QAAQ;IAAY;GAAM,CAAC;GAC/C,OAAO,MAAM,WAAW;EAC1B;EACA,UAAU,EAAE,MAAM;EAClB;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH;AAEA,YAAY,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-context.mjs","names":[],"sources":["../../src/dialog/dialog-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { ChangeReason } from \"../internal/types.js\";\nimport type { OverlayRootValue } from \"../internal/use-overlay-root.js\";\n\n/**\n * The Root's machinery (`useOverlayRoot`, as Popover's) with the `<dialog>` as the popup element\n * and a close's `returnValue`. `mode` \"static\" is JS-free mode, where the browser owns open and\n * close through Invoker Commands; in \"library\" mode opening and the closes a part asks for are\n * library-owned requests, dismissals browser-owned facts reported to `onOpenChange` (design\n * section 2,
|
|
1
|
+
{"version":3,"file":"dialog-context.mjs","names":[],"sources":["../../src/dialog/dialog-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { ChangeReason } from \"../internal/types.js\";\nimport type { OverlayRootValue } from \"../internal/overlay/use-overlay-root.js\";\n\n/**\n * The Root's machinery (`useOverlayRoot`, as Popover's) with the `<dialog>` as the popup element\n * and a close's `returnValue`. `mode` \"static\" is JS-free mode, where the browser owns open and\n * close through Invoker Commands; in \"library\" mode opening and the closes a part asks for are\n * library-owned requests, dismissals browser-owned facts reported to `onOpenChange` (design\n * section 2, conventions 3.9).\n */\nexport interface DialogContextValue extends OverlayRootValue<\n HTMLDialogElement,\n [returnValue: string]\n> {\n readonly modal: boolean;\n /**\n * A library-owned close (library mode, design 2.3): a Close part, a `method=\"dialog\"` submit,\n * a Form's settle close, a foreign close command. Records `returnValue` for the apply effect's\n * `close()` and dispatches `false` (`openChangeAction(false)` awaited). A no-op when `false` is\n * already intended. `notifyClosed` (a fact: a native close) records nothing.\n */\n readonly requestClose: (\n event: Event | undefined,\n reason: ChangeReason,\n returnValue: string,\n ) => void;\n /**\n * Read and clear the `returnValue` of the pending part-initiated close, for the apply effect's\n * `close()`; `\"\"` when there is none (a controlled close).\n */\n readonly takeCloseReturnValue: () => string;\n}\n\nexport const DialogContext = createContext<DialogContextValue | null>(null);\n\nexport function useDialogContext(part: string): DialogContextValue {\n const context = use(DialogContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Dialog.Root.`);\n }\n return context;\n}\n"],"mappings":";;;AAmCA,MAAa,gBAAgB,cAAyC,IAAI;AAE1E,SAAgB,iBAAiB,MAAkC;CACjE,MAAM,UAAU,IAAI,aAAa;CACjC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,wCAAwC;CAElE,OAAO;AACT"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
2
|
+
//#region src/dialog/dialog-dismiss.ts
|
|
3
|
+
/** The nearest `<dialog>` around a node (the dialog itself counts). */
|
|
4
|
+
function closestDialog(target) {
|
|
5
|
+
return target instanceof Element ? target.closest("dialog") : null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* An open popover that takes Escape before the dialog: `auto` or `hint` (they have a close
|
|
9
|
+
* watcher). A `manual` popover, or `hint` where the engine maps it to `manual`, does not.
|
|
10
|
+
*/
|
|
11
|
+
function isOpenLightPopover(element) {
|
|
12
|
+
if (!element.hasAttribute("popover")) return false;
|
|
13
|
+
const reflected = element.popover;
|
|
14
|
+
if ((typeof reflected === "string" ? reflected : element.getAttribute("popover").toLowerCase()) === "manual") return false;
|
|
15
|
+
return isPopoverOpen(element);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether Escape belongs to a layer inside `dialog` that sits above it (design 9: "closes the
|
|
19
|
+
* innermost one only"): the target is inside an open nested `<dialog>` or popover, or an open
|
|
20
|
+
* `auto` / `hint` popover inside the dialog would take the close request (close watchers are
|
|
21
|
+
* per document, not per focus).
|
|
22
|
+
*/
|
|
23
|
+
function escapeBelongsToInnerLayer(dialog, target) {
|
|
24
|
+
for (let node = target instanceof Element ? target : null; node !== null && node !== dialog; node = node.parentElement) {
|
|
25
|
+
if (node instanceof HTMLDialogElement && node.open) return true;
|
|
26
|
+
if (isOpenLightPopover(node)) return true;
|
|
27
|
+
}
|
|
28
|
+
for (const element of dialog.querySelectorAll("[popover]")) if (isOpenLightPopover(element)) return true;
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
/** Whether a pointer event on the dialog itself lies outside its border box (the `::backdrop`). */
|
|
32
|
+
function onBackdrop(dialog, event) {
|
|
33
|
+
if (event.target !== dialog) return false;
|
|
34
|
+
const { clientX, clientY } = event;
|
|
35
|
+
const rect = dialog.getBoundingClientRect();
|
|
36
|
+
return !(rect.top <= clientY && clientY <= rect.bottom && rect.left <= clientX && clientX <= rect.right);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Installs the JS dismissals of `dialog` and returns their cleanup: Escape for a non-modal
|
|
40
|
+
* dialog, and with `lightDismiss` a click outside (on the backdrop for a modal dialog). Each
|
|
41
|
+
* calls `dialog.requestClose()`, so the close is the browser's, a fact (conventions 3.9.2).
|
|
42
|
+
* Not for a dialog where native `closedby` is in use.
|
|
43
|
+
*/
|
|
44
|
+
function listenDialogDismiss(dialog, { modal, lightDismiss }) {
|
|
45
|
+
const doc = dialog.ownerDocument;
|
|
46
|
+
const listeners = [];
|
|
47
|
+
if (!modal) listeners.push(["keydown", (event) => {
|
|
48
|
+
const keyboardEvent = event;
|
|
49
|
+
if (keyboardEvent.key !== "Escape" || keyboardEvent.defaultPrevented) return;
|
|
50
|
+
if (!dialog.open || closestDialog(keyboardEvent.target) !== dialog) return;
|
|
51
|
+
if (escapeBelongsToInnerLayer(dialog, keyboardEvent.target)) return;
|
|
52
|
+
keyboardEvent.preventDefault();
|
|
53
|
+
dialog.requestClose();
|
|
54
|
+
}]);
|
|
55
|
+
let pressedOutside = false;
|
|
56
|
+
const isOutside = (target) => {
|
|
57
|
+
return !(target instanceof Node) || !dialog.contains(target);
|
|
58
|
+
};
|
|
59
|
+
let outsideAttached = false;
|
|
60
|
+
const onOutsidePointerDown = (event) => {
|
|
61
|
+
pressedOutside = dialog.open && isOutside(event.target);
|
|
62
|
+
};
|
|
63
|
+
const onOutsideClick = (event) => {
|
|
64
|
+
const pressed = pressedOutside;
|
|
65
|
+
pressedOutside = false;
|
|
66
|
+
if (!dialog.open || !pressed || !isOutside(event.target)) return;
|
|
67
|
+
dialog.requestClose();
|
|
68
|
+
};
|
|
69
|
+
const syncOutside = () => {
|
|
70
|
+
const want = dialog.open;
|
|
71
|
+
if (want === outsideAttached) return;
|
|
72
|
+
outsideAttached = want;
|
|
73
|
+
pressedOutside = false;
|
|
74
|
+
if (want) {
|
|
75
|
+
doc.addEventListener("pointerdown", onOutsidePointerDown, true);
|
|
76
|
+
doc.addEventListener("click", onOutsideClick, true);
|
|
77
|
+
} else {
|
|
78
|
+
doc.removeEventListener("pointerdown", onOutsidePointerDown, true);
|
|
79
|
+
doc.removeEventListener("click", onOutsideClick, true);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
if (lightDismiss) {
|
|
83
|
+
if (modal) listeners.push(["pointerdown", (event) => {
|
|
84
|
+
pressedOutside = dialog.open && onBackdrop(dialog, event);
|
|
85
|
+
}], ["click", (event) => {
|
|
86
|
+
const pressed = pressedOutside;
|
|
87
|
+
pressedOutside = false;
|
|
88
|
+
if (!dialog.open || !pressed || !onBackdrop(dialog, event)) return;
|
|
89
|
+
dialog.requestClose();
|
|
90
|
+
}]);
|
|
91
|
+
else {
|
|
92
|
+
listeners.push(["toggle", syncOutside]);
|
|
93
|
+
syncOutside();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const [type, listener] of listeners) dialog.addEventListener(type, listener);
|
|
97
|
+
return () => {
|
|
98
|
+
for (const [type, listener] of listeners) dialog.removeEventListener(type, listener);
|
|
99
|
+
if (outsideAttached) {
|
|
100
|
+
doc.removeEventListener("pointerdown", onOutsidePointerDown, true);
|
|
101
|
+
doc.removeEventListener("click", onOutsideClick, true);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { listenDialogDismiss };
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=dialog-dismiss.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog-dismiss.mjs","names":[],"sources":["../../src/dialog/dialog-dismiss.ts"],"sourcesContent":["// Dialog's JS baseline for what the platform gives only behind `closedby`: Escape on a\n// non-modal dialog and light dismiss (design/components/dialog.md 2.6). No \"use client\"\n// directive: DOM listeners only (conventions 7.1).\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\n\n/** The nearest `<dialog>` around a node (the dialog itself counts). */\nfunction closestDialog(target: EventTarget | null): Element | null {\n return target instanceof Element ? target.closest(\"dialog\") : null;\n}\n\n/**\n * An open popover that takes Escape before the dialog: `auto` or `hint` (they have a close\n * watcher). A `manual` popover, or `hint` where the engine maps it to `manual`, does not.\n */\nfunction isOpenLightPopover(element: Element): boolean {\n if (!element.hasAttribute(\"popover\")) return false;\n // The IDL attribute reflects the state the engine applies; jsdom has none.\n const reflected: unknown = (element as HTMLElement).popover;\n const state =\n typeof reflected === \"string\" ? reflected : element.getAttribute(\"popover\")!.toLowerCase();\n if (state === \"manual\") return false;\n return isPopoverOpen(element);\n}\n\n/**\n * Whether Escape belongs to a layer inside `dialog` that sits above it (design 9: \"closes the\n * innermost one only\"): the target is inside an open nested `<dialog>` or popover, or an open\n * `auto` / `hint` popover inside the dialog would take the close request (close watchers are\n * per document, not per focus).\n */\nfunction escapeBelongsToInnerLayer(dialog: HTMLDialogElement, target: EventTarget | null): boolean {\n for (\n let node = target instanceof Element ? target : null;\n node !== null && node !== dialog;\n node = node.parentElement\n ) {\n if (node instanceof HTMLDialogElement && node.open) return true;\n if (isOpenLightPopover(node)) return true;\n }\n for (const element of dialog.querySelectorAll(\"[popover]\")) {\n if (isOpenLightPopover(element)) return true;\n }\n return false;\n}\n\n/** Whether a pointer event on the dialog itself lies outside its border box (the `::backdrop`). */\nfunction onBackdrop(dialog: HTMLDialogElement, event: Event): boolean {\n if (event.target !== dialog) return false;\n const { clientX, clientY } = event as MouseEvent;\n const rect = dialog.getBoundingClientRect();\n return !(\n rect.top <= clientY &&\n clientY <= rect.bottom &&\n rect.left <= clientX &&\n clientX <= rect.right\n );\n}\n\nexport interface DialogDismissOptions {\n /** The Root's `modal`. A modal dialog has the platform's close watcher Escape. */\n readonly modal: boolean;\n /** The Popup's `lightDismiss`. */\n readonly lightDismiss: boolean;\n}\n\n/**\n * Installs the JS dismissals of `dialog` and returns their cleanup: Escape for a non-modal\n * dialog, and with `lightDismiss` a click outside (on the backdrop for a modal dialog). Each\n * calls `dialog.requestClose()`, so the close is the browser's, a fact (conventions 3.9.2).\n * Not for a dialog where native `closedby` is in use.\n */\nexport function listenDialogDismiss(\n dialog: HTMLDialogElement,\n { modal, lightDismiss }: DialogDismissOptions,\n): () => void {\n const doc = dialog.ownerDocument;\n const listeners: [string, EventListener][] = [];\n\n if (!modal) {\n // Non-modal dialogs get no close watcher Escape from the platform (design 2.6).\n listeners.push([\n \"keydown\",\n (event) => {\n const keyboardEvent = event as KeyboardEvent;\n if (keyboardEvent.key !== \"Escape\" || keyboardEvent.defaultPrevented) return;\n if (!dialog.open || closestDialog(keyboardEvent.target) !== dialog) return;\n // A popover or nested dialog inside takes this Escape (its close watcher); leave the\n // event alone so that it can.\n if (escapeBelongsToInnerLayer(dialog, keyboardEvent.target)) return;\n keyboardEvent.preventDefault();\n dialog.requestClose();\n },\n ]);\n }\n\n // Light dismiss needs both the press and the click outside, like native `closedby=\"any\"`: a\n // drag that starts inside (selecting text in an input) and ends on the backdrop or outside\n // fires `click` on the common ancestor and must not close (it would lose a half-filled form).\n let pressedOutside = false;\n\n const isOutside = (target: EventTarget | null): boolean => {\n // The Trigger counts as outside, as native `closedby=\"any\"` treats it.\n return !(target instanceof Node) || !dialog.contains(target);\n };\n let outsideAttached = false;\n const onOutsidePointerDown = (event: Event) => {\n pressedOutside = dialog.open && isOutside(event.target);\n };\n const onOutsideClick = (event: Event) => {\n const pressed = pressedOutside;\n pressedOutside = false;\n if (!dialog.open || !pressed || !isOutside(event.target)) return;\n dialog.requestClose();\n };\n const syncOutside = () => {\n const want = dialog.open;\n if (want === outsideAttached) return;\n outsideAttached = want;\n pressedOutside = false;\n if (want) {\n doc.addEventListener(\"pointerdown\", onOutsidePointerDown, true);\n doc.addEventListener(\"click\", onOutsideClick, true);\n } else {\n doc.removeEventListener(\"pointerdown\", onOutsidePointerDown, true);\n doc.removeEventListener(\"click\", onOutsideClick, true);\n }\n };\n\n if (lightDismiss) {\n if (modal) {\n // A press or click on the ::backdrop targets the dialog itself, outside its border box.\n listeners.push(\n [\n \"pointerdown\",\n (event) => {\n pressedOutside = dialog.open && onBackdrop(dialog, event);\n },\n ],\n [\n \"click\",\n (event) => {\n const pressed = pressedOutside;\n pressedOutside = false;\n if (!dialog.open || !pressed || !onBackdrop(dialog, event)) return;\n dialog.requestClose();\n },\n ],\n );\n } else {\n // A document listener only while open, following the native `toggle` (the React\n // `onToggle` prop never fires on a hydrated <dialog>); reads `dialog.open`, not\n // `newState` (coalescing).\n listeners.push([\"toggle\", syncOutside]);\n syncOutside();\n }\n }\n\n for (const [type, listener] of listeners) dialog.addEventListener(type, listener);\n return () => {\n for (const [type, listener] of listeners) dialog.removeEventListener(type, listener);\n if (outsideAttached) {\n doc.removeEventListener(\"pointerdown\", onOutsidePointerDown, true);\n doc.removeEventListener(\"click\", onOutsideClick, true);\n }\n };\n}\n"],"mappings":";;;AAMA,SAAS,cAAc,QAA4C;CACjE,OAAO,kBAAkB,UAAU,OAAO,QAAQ,QAAQ,IAAI;AAChE;;;;;AAMA,SAAS,mBAAmB,SAA2B;CACrD,IAAI,CAAC,QAAQ,aAAa,SAAS,GAAG,OAAO;CAE7C,MAAM,YAAsB,QAAwB;CAGpD,KADE,OAAO,cAAc,WAAW,YAAY,QAAQ,aAAa,SAAS,CAAC,CAAE,YAAY,OAC7E,UAAU,OAAO;CAC/B,OAAO,cAAc,OAAO;AAC9B;;;;;;;AAQA,SAAS,0BAA0B,QAA2B,QAAqC;CACjG,KACE,IAAI,OAAO,kBAAkB,UAAU,SAAS,MAChD,SAAS,QAAQ,SAAS,QAC1B,OAAO,KAAK,eACZ;EACA,IAAI,gBAAgB,qBAAqB,KAAK,MAAM,OAAO;EAC3D,IAAI,mBAAmB,IAAI,GAAG,OAAO;CACvC;CACA,KAAK,MAAM,WAAW,OAAO,iBAAiB,WAAW,GACvD,IAAI,mBAAmB,OAAO,GAAG,OAAO;CAE1C,OAAO;AACT;;AAGA,SAAS,WAAW,QAA2B,OAAuB;CACpE,IAAI,MAAM,WAAW,QAAQ,OAAO;CACpC,MAAM,EAAE,SAAS,YAAY;CAC7B,MAAM,OAAO,OAAO,sBAAsB;CAC1C,OAAO,EACL,KAAK,OAAO,WACZ,WAAW,KAAK,UAChB,KAAK,QAAQ,WACb,WAAW,KAAK;AAEpB;;;;;;;AAeA,SAAgB,oBACd,QACA,EAAE,OAAO,gBACG;CACZ,MAAM,MAAM,OAAO;CACnB,MAAM,YAAuC,CAAC;CAE9C,IAAI,CAAC,OAEH,UAAU,KAAK,CACb,YACC,UAAU;EACT,MAAM,gBAAgB;EACtB,IAAI,cAAc,QAAQ,YAAY,cAAc,kBAAkB;EACtE,IAAI,CAAC,OAAO,QAAQ,cAAc,cAAc,MAAM,MAAM,QAAQ;EAGpE,IAAI,0BAA0B,QAAQ,cAAc,MAAM,GAAG;EAC7D,cAAc,eAAe;EAC7B,OAAO,aAAa;CACtB,CACF,CAAC;CAMH,IAAI,iBAAiB;CAErB,MAAM,aAAa,WAAwC;EAEzD,OAAO,EAAE,kBAAkB,SAAS,CAAC,OAAO,SAAS,MAAM;CAC7D;CACA,IAAI,kBAAkB;CACtB,MAAM,wBAAwB,UAAiB;EAC7C,iBAAiB,OAAO,QAAQ,UAAU,MAAM,MAAM;CACxD;CACA,MAAM,kBAAkB,UAAiB;EACvC,MAAM,UAAU;EAChB,iBAAiB;EACjB,IAAI,CAAC,OAAO,QAAQ,CAAC,WAAW,CAAC,UAAU,MAAM,MAAM,GAAG;EAC1D,OAAO,aAAa;CACtB;CACA,MAAM,oBAAoB;EACxB,MAAM,OAAO,OAAO;EACpB,IAAI,SAAS,iBAAiB;EAC9B,kBAAkB;EAClB,iBAAiB;EACjB,IAAI,MAAM;GACR,IAAI,iBAAiB,eAAe,sBAAsB,IAAI;GAC9D,IAAI,iBAAiB,SAAS,gBAAgB,IAAI;EACpD,OAAO;GACL,IAAI,oBAAoB,eAAe,sBAAsB,IAAI;GACjE,IAAI,oBAAoB,SAAS,gBAAgB,IAAI;EACvD;CACF;CAEA,IAAI,cAAc;EAChB,IAAI,OAEF,UAAU,KACR,CACE,gBACC,UAAU;GACT,iBAAiB,OAAO,QAAQ,WAAW,QAAQ,KAAK;EAC1D,CACF,GACA,CACE,UACC,UAAU;GACT,MAAM,UAAU;GAChB,iBAAiB;GACjB,IAAI,CAAC,OAAO,QAAQ,CAAC,WAAW,CAAC,WAAW,QAAQ,KAAK,GAAG;GAC5D,OAAO,aAAa;EACtB,CACF,CACF;OACK;GAIL,UAAU,KAAK,CAAC,UAAU,WAAW,CAAC;GACtC,YAAY;EACd;CACF;CAEA,KAAK,MAAM,CAAC,MAAM,aAAa,WAAW,OAAO,iBAAiB,MAAM,QAAQ;CAChF,aAAa;EACX,KAAK,MAAM,CAAC,MAAM,aAAa,WAAW,OAAO,oBAAoB,MAAM,QAAQ;EACnF,IAAI,iBAAiB;GACnB,IAAI,oBAAoB,eAAe,sBAAsB,IAAI;GACjE,IAAI,oBAAoB,SAAS,gBAAgB,IAAI;EACvD;CACF;AACF"}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
3
3
|
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
4
4
|
import { useRender } from "../internal/use-render.mjs";
|
|
5
|
-
import { FormContext } from "../internal/field-context.mjs";
|
|
5
|
+
import { FormContext } from "../internal/form/field-context.mjs";
|
|
6
6
|
import { useDialogContext } from "./dialog-context.mjs";
|
|
7
|
-
import { FormStatusWatcher } from "../internal/form-status-watcher.mjs";
|
|
8
|
-
import { hasAnyError } from "../internal/validity.mjs";
|
|
7
|
+
import { FormStatusWatcher } from "../internal/form/form-status-watcher.mjs";
|
|
8
|
+
import { hasAnyError } from "../internal/form/validity.mjs";
|
|
9
9
|
import { use, useCallback, useRef, useState } from "react";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
//#region src/dialog/dialog-form.tsx
|
|
@@ -110,7 +110,7 @@ DialogForm.displayName = "DialogForm";
|
|
|
110
110
|
*/
|
|
111
111
|
function DialogFormSettle({ watches, missingAction, onPendingChange, onSettled }) {
|
|
112
112
|
const form = use(FormContext);
|
|
113
|
-
useDevWarning(form !== null && missingAction, isDev && "
|
|
113
|
+
useDevWarning(form !== null && missingAction, isDev && "Dialog.Form: rendered as a `Form.Root`, it needs a function `action`; without one the form navigates instead of closing the dialog. Render a plain `<Dialog.Form>` for a `method=\"dialog\"` form.");
|
|
114
114
|
const isForm = form !== null;
|
|
115
115
|
const errors = form?.errors;
|
|
116
116
|
const settled = useCallback(() => onSettled(!isForm || !hasAnyError(errors)), [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-form.mjs","names":[],"sources":["../../src/dialog/dialog-form.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { FormContext } from \"../internal/field-context.js\";\nimport { FormStatusWatcher } from \"../internal/form-status-watcher.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport { hasAnyError } from \"../internal/validity.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Dialog.Form`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogFormState {\n /** `useFormStatus().pending` of this form, exposed for `className` / `children` functions. */\n readonly pending: boolean;\n}\n\n/**\n * Props of `Dialog.Form`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogFormProps extends Omit<\n ComponentPropsWithRef<\"form\">,\n \"method\" | \"action\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * React form action (`(formData) => unknown`, may be a Server Function). Passed to the form\n * unwrapped so React's progressive enhancement is kept; the dialog closes with the submitter's\n * `value` as `returnValue` once the action's transition settles (see `closeOnSettle`): in\n * library mode through the Root (`openChangeAction(false)` awaited, view transition if set),\n * in JS-free mode with `close(value)`. A rejection leaves the dialog open. Without `action`\n * the form renders `method=\"dialog\"`: submitting closes the dialog, natively in JS-free mode\n * and through the Root in library mode (a `preventDefault()` in your own `onSubmit` blocks\n * both; `stopPropagation()` there leaves the close to the browser, reported to `onOpenChange`\n * as a fact).\n * A string `action` (a URL) is a plain navigating form.\n */\n action?: string | ((formData: FormData) => unknown);\n /**\n * With a function `action`: close the dialog once the action's transition settles without\n * throwing and, when this form is rendered as a `Form.Root`\n * (`render={<Form.Root errors={state.errors} />}`), with no field error: a settle whose\n * `errors` has a non-empty entry (hidden stale ones included, the `autoReset` rule) keeps\n * the dialog open and the Form focuses the first errored field.\n *\n * Without a `Form.Root` the library never sees a result, so any settle that does not throw\n * counts, including a `useActionState` result that reports errors: render the form as a\n * `Form.Root` to route them, throw to keep the dialog open, or set `closeOnSettle={false}`\n * and close it yourself (a `Dialog.Close`, a submit button in a separate `method=\"dialog\"`\n * form, or a controlled `open`). A `formMethod=\"dialog\"` submitter inside this form cannot\n * close it: React prevents every submit of a form with a function `action` and runs the\n * action again.\n *\n * The dialog is not closed either when it was closed (Escape, a Close part) while the action\n * ran, also if the user re-opened it meanwhile.\n *\n * @defaultValue `true`\n */\n closeOnSettle?: boolean;\n /**\n * Only with a string `action` (a navigating form, for example `\"post\"`). Owned otherwise:\n * `\"dialog\"` without `action`, React's own with a function `action`.\n */\n method?: ComponentPropsWithRef<\"form\">[\"method\"];\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogFormState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogFormState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogFormState>;\n /** Replace the default `<form>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"form\">, DialogFormState>;\n}\n\n/**\n * A form that completes the dialog. Without `action`: `<form method=\"dialog\">`, so a submit\n * closes the dialog with the submitter's `value` as `returnValue` (natively in JS-free mode;\n * in library mode the Popup cancels the submission and closes through the Root). With a\n * function `action`: `<form action={action}>` (React overrides the method) and a status watcher\n * that closes the dialog once the action has settled, with the submitter's `value`, unless\n * `closeOnSettle` is `false`, the dialog was closed while the action ran, or the form is rendered\n * as a `Form.Root` and the result has a field error (`render={<Form.Root errors={...} />}`, the\n * recommended composition for validation).\n *\n * `DialogFormState.pending` is this form's own status; it is not emitted as `data-pending` and\n * is not folded into any control's `pending` (conventions 2.7). Submit buttons read\n * `useFormStatus()` themselves.\n *\n * Owned keys (conventions 1.2): `method` (except with a string `action`), `action`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogForm({\n action,\n closeOnSettle = true,\n method,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogFormProps) {\n const ctx = useDialogContext(\"Dialog.Form\");\n const { popupRef, recordCloseIntent, requestClose } = ctx;\n const isLibrary = ctx.mode === \"library\";\n const [pending, setPending] = useState(false);\n const submission = useRef<{ event: Event; returnValue: string } | null>(null);\n // The dialog closed after the last submit (Escape, a Close part): the settle must not close it\n // again, also when the user re-opened it meanwhile.\n const closedSinceSubmit = useRef(false);\n const watches = typeof action === \"function\";\n\n // The submitter's `value` comes from the native `submit` event (capture, before React's\n // handler runs the action).\n const libraryRef = useCallback((form: HTMLFormElement) => {\n const onSubmit = (event: Event) => {\n if (event.target !== form) return;\n const submitter = (event as SubmitEvent).submitter as\n | HTMLButtonElement\n | HTMLInputElement\n | null;\n submission.current = { event, returnValue: submitter?.value ?? \"\" };\n closedSinceSubmit.current = false;\n };\n const dialog = form.closest(\"dialog\");\n const onClose = (event: Event) => {\n if (event.target === dialog) closedSinceSubmit.current = true;\n };\n form.addEventListener(\"submit\", onSubmit, true);\n dialog?.addEventListener(\"close\", onClose);\n return () => {\n form.removeEventListener(\"submit\", onSubmit, true);\n dialog?.removeEventListener(\"close\", onClose);\n };\n }, []);\n\n // `clean`: no field error in the settle's result (always `true` without a `Form.Root`).\n const onSettled = useCallback(\n (clean: boolean) => {\n const dialog = popupRef.current;\n const submitted = submission.current;\n submission.current = null;\n if (!closeOnSettle || closedSinceSubmit.current) return;\n // A result with field errors keeps the dialog open; the Form.Root focuses the first errored\n // field (design/components/dialog.md, \"Dialog.Form and Form.Root\").\n if (!clean) return;\n if (dialog === null || !dialog.open) return;\n const returnValue = submitted?.returnValue ?? \"\";\n if (isLibrary) {\n // A library-owned close (design 2.3): `openChangeAction(false)` awaited, then\n // `close(returnValue)` in the commit, inside the view transition if set.\n requestClose(submitted?.event, \"activate\", returnValue);\n return;\n }\n recordCloseIntent({ reason: \"activate\", event: submitted?.event });\n dialog.close(returnValue);\n },\n [closeOnSettle, popupRef, isLibrary, recordCloseIntent, requestClose],\n );\n\n const state: DialogFormState = { pending };\n\n return useRender<ComponentPropsWithRef<\"form\">, DialogFormState>({\n defaultElement: \"form\",\n render,\n state,\n className,\n style,\n children: (s) => (\n <>\n {resolveStateValue(children, s)}\n <DialogFormSettle\n watches={watches}\n missingAction={action === undefined}\n onPendingChange={setPending}\n onSettled={onSettled}\n />\n </>\n ),\n props: rest,\n libraryProps: {\n method: action === undefined ? \"dialog\" : typeof action === \"string\" ? method : undefined,\n // React's own type wants `void | Promise<void>`; the library's actions return `unknown`\n // (conventions 2.2) and React ignores the result.\n action: action as ComponentPropsWithRef<\"form\">[\"action\"],\n },\n ref: libraryRef,\n });\n}\n\nDialogForm.displayName = \"DialogForm\";\n\n/**\n * Rendered among the form's children, so it reads the `FormContext` exactly when the form is a\n * `Form.Root` (either orientation of the `render` composition): the settle close then waits for\n * a result with no field error (`hasAnyError`, the `autoReset` predicate, hidden stale entries\n * included).\n */\nfunction DialogFormSettle({\n watches,\n missingAction,\n onPendingChange,\n onSettled,\n}: {\n readonly watches: boolean;\n readonly missingAction: boolean;\n readonly onPendingChange: (pending: boolean) => void;\n readonly onSettled: (clean: boolean) => void;\n}) {\n const form = use(FormContext);\n useDevWarning(\n form !== null && missingAction,\n isDev &&\n \"`Dialog.Form` rendered as a `Form.Root` needs a function `action`; without one the form \" +\n \"navigates instead of closing the dialog. Render a plain `<Dialog.Form>` for a \" +\n '`method=\"dialog\"` form.',\n );\n const isForm = form !== null;\n const errors = form?.errors;\n const settled = useCallback(\n () => onSettled(!isForm || !hasAnyError(errors)),\n [isForm, errors, onSettled],\n );\n if (!watches) return null;\n return <FormStatusWatcher onPendingChange={onPendingChange} onSettled={settled} />;\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;;;AAuFvC,SAAgB,WAAW,EACzB,QACA,gBAAgB,MAChB,QACA,WACA,OACA,UACA,QACA,GAAG,QACe;CAClB,MAAM,MAAM,iBAAiB,aAAa;CAC1C,MAAM,EAAE,UAAU,mBAAmB,iBAAiB;CACtD,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,aAAa,OAAqD,IAAI;CAG5E,MAAM,oBAAoB,OAAO,KAAK;CACtC,MAAM,UAAU,OAAO,WAAW;CAIlC,MAAM,aAAa,aAAa,SAA0B;EACxD,MAAM,YAAY,UAAiB;GACjC,IAAI,MAAM,WAAW,MAAM;GAC3B,MAAM,YAAa,MAAsB;GAIzC,WAAW,UAAU;IAAE;IAAO,aAAa,WAAW,SAAS;GAAG;GAClE,kBAAkB,UAAU;EAC9B;EACA,MAAM,SAAS,KAAK,QAAQ,QAAQ;EACpC,MAAM,WAAW,UAAiB;GAChC,IAAI,MAAM,WAAW,QAAQ,kBAAkB,UAAU;EAC3D;EACA,KAAK,iBAAiB,UAAU,UAAU,IAAI;EAC9C,QAAQ,iBAAiB,SAAS,OAAO;EACzC,aAAa;GACX,KAAK,oBAAoB,UAAU,UAAU,IAAI;GACjD,QAAQ,oBAAoB,SAAS,OAAO;EAC9C;CACF,GAAG,CAAC,CAAC;CAGL,MAAM,YAAY,aACf,UAAmB;EAClB,MAAM,SAAS,SAAS;EACxB,MAAM,YAAY,WAAW;EAC7B,WAAW,UAAU;EACrB,IAAI,CAAC,iBAAiB,kBAAkB,SAAS;EAGjD,IAAI,CAAC,OAAO;EACZ,IAAI,WAAW,QAAQ,CAAC,OAAO,MAAM;EACrC,MAAM,cAAc,WAAW,eAAe;EAC9C,IAAI,WAAW;GAGb,aAAa,WAAW,OAAO,YAAY,WAAW;GACtD;EACF;EACA,kBAAkB;GAAE,QAAQ;GAAY,OAAO,WAAW;EAAM,CAAC;EACjE,OAAO,MAAM,WAAW;CAC1B,GACA;EAAC;EAAe;EAAU;EAAW;EAAmB;CAAY,CACtE;CAIA,OAAO,UAA0D;EAC/D,gBAAgB;EAChB;EACA,OAAA,EAL+B,QAK3B;EACJ;EACA;EACA,WAAW,MACT,qBAAA,UAAA,EAAA,UAAA,CACG,kBAAkB,UAAU,CAAC,GAC9B,oBAAC,kBAAD;GACW;GACT,eAAe,WAAW,KAAA;GAC1B,iBAAiB;GACN;EACZ,CAAA,CACD,EAAA,CAAA;EAEJ,OAAO;EACP,cAAc;GACZ,QAAQ,WAAW,KAAA,IAAY,WAAW,OAAO,WAAW,WAAW,SAAS,KAAA;GAGxE;EACV;EACA,KAAK;CACP,CAAC;AACH;AAEA,WAAW,cAAc;;;;;;;AAQzB,SAAS,iBAAiB,EACxB,SACA,eACA,iBACA,aAMC;CACD,MAAM,OAAO,IAAI,WAAW;CAC5B,cACE,SAAS,QAAQ,eACjB,SACE,iMAGJ;CACA,MAAM,SAAS,SAAS;CACxB,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,kBACR,UAAU,CAAC,UAAU,CAAC,YAAY,MAAM,CAAC,GAC/C;EAAC;EAAQ;EAAQ;CAAS,CAC5B;CACA,IAAI,CAAC,SAAS,OAAO;CACrB,OAAO,oBAAC,mBAAD;EAAoC;EAAiB,WAAW;CAAU,CAAA;AACnF"}
|
|
1
|
+
{"version":3,"file":"dialog-form.mjs","names":[],"sources":["../../src/dialog/dialog-form.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { FormContext } from \"../internal/form/field-context.js\";\nimport { FormStatusWatcher } from \"../internal/form/form-status-watcher.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport { hasAnyError } from \"../internal/form/validity.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Dialog.Form`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogFormState {\n /** `useFormStatus().pending` of this form, exposed for `className` / `children` functions. */\n readonly pending: boolean;\n}\n\n/**\n * Props of `Dialog.Form`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogFormProps extends Omit<\n ComponentPropsWithRef<\"form\">,\n \"method\" | \"action\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * React form action (`(formData) => unknown`, may be a Server Function). Passed to the form\n * unwrapped so React's progressive enhancement is kept; the dialog closes with the submitter's\n * `value` as `returnValue` once the action's transition settles (see `closeOnSettle`): in\n * library mode through the Root (`openChangeAction(false)` awaited, view transition if set),\n * in JS-free mode with `close(value)`. A rejection leaves the dialog open. Without `action`\n * the form renders `method=\"dialog\"`: submitting closes the dialog, natively in JS-free mode\n * and through the Root in library mode (a `preventDefault()` in your own `onSubmit` blocks\n * both; `stopPropagation()` there leaves the close to the browser, reported to `onOpenChange`\n * as a fact).\n * A string `action` (a URL) is a plain navigating form.\n */\n action?: string | ((formData: FormData) => unknown);\n /**\n * With a function `action`: close the dialog once the action's transition settles without\n * throwing and, when this form is rendered as a `Form.Root`\n * (`render={<Form.Root errors={state.errors} />}`), with no field error: a settle whose\n * `errors` has a non-empty entry (hidden stale ones included, the `autoReset` rule) keeps\n * the dialog open and the Form focuses the first errored field.\n *\n * Without a `Form.Root` the library never sees a result, so any settle that does not throw\n * counts, including a `useActionState` result that reports errors: render the form as a\n * `Form.Root` to route them, throw to keep the dialog open, or set `closeOnSettle={false}`\n * and close it yourself (a `Dialog.Close`, a submit button in a separate `method=\"dialog\"`\n * form, or a controlled `open`). A `formMethod=\"dialog\"` submitter inside this form cannot\n * close it: React prevents every submit of a form with a function `action` and runs the\n * action again.\n *\n * The dialog is not closed either when it was closed (Escape, a Close part) while the action\n * ran, also if the user re-opened it meanwhile.\n *\n * @defaultValue `true`\n */\n closeOnSettle?: boolean;\n /**\n * Only with a string `action` (a navigating form, for example `\"post\"`). Owned otherwise:\n * `\"dialog\"` without `action`, React's own with a function `action`.\n */\n method?: ComponentPropsWithRef<\"form\">[\"method\"];\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogFormState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogFormState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogFormState>;\n /** Replace the default `<form>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"form\">, DialogFormState>;\n}\n\n/**\n * A form that completes the dialog. Without `action`: `<form method=\"dialog\">`, so a submit\n * closes the dialog with the submitter's `value` as `returnValue` (natively in JS-free mode;\n * in library mode the Popup cancels the submission and closes through the Root). With a\n * function `action`: `<form action={action}>` (React overrides the method) and a status watcher\n * that closes the dialog once the action has settled, with the submitter's `value`, unless\n * `closeOnSettle` is `false`, the dialog was closed while the action ran, or the form is rendered\n * as a `Form.Root` and the result has a field error (`render={<Form.Root errors={...} />}`, the\n * recommended composition for validation).\n *\n * `DialogFormState.pending` is this form's own status; it is not emitted as `data-pending` and\n * is not folded into any control's `pending` (conventions 2.7). Submit buttons read\n * `useFormStatus()` themselves.\n *\n * Owned keys (conventions 1.2): `method` (except with a string `action`), `action`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogForm({\n action,\n closeOnSettle = true,\n method,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogFormProps) {\n const ctx = useDialogContext(\"Dialog.Form\");\n const { popupRef, recordCloseIntent, requestClose } = ctx;\n const isLibrary = ctx.mode === \"library\";\n const [pending, setPending] = useState(false);\n const submission = useRef<{ event: Event; returnValue: string } | null>(null);\n // The dialog closed after the last submit (Escape, a Close part): the settle must not close it\n // again, also when the user re-opened it meanwhile.\n const closedSinceSubmit = useRef(false);\n const watches = typeof action === \"function\";\n\n // The submitter's `value` comes from the native `submit` event (capture, before React's\n // handler runs the action).\n const libraryRef = useCallback((form: HTMLFormElement) => {\n const onSubmit = (event: Event) => {\n if (event.target !== form) return;\n const submitter = (event as SubmitEvent).submitter as\n | HTMLButtonElement\n | HTMLInputElement\n | null;\n submission.current = { event, returnValue: submitter?.value ?? \"\" };\n closedSinceSubmit.current = false;\n };\n const dialog = form.closest(\"dialog\");\n const onClose = (event: Event) => {\n if (event.target === dialog) closedSinceSubmit.current = true;\n };\n form.addEventListener(\"submit\", onSubmit, true);\n dialog?.addEventListener(\"close\", onClose);\n return () => {\n form.removeEventListener(\"submit\", onSubmit, true);\n dialog?.removeEventListener(\"close\", onClose);\n };\n }, []);\n\n // `clean`: no field error in the settle's result (always `true` without a `Form.Root`).\n const onSettled = useCallback(\n (clean: boolean) => {\n const dialog = popupRef.current;\n const submitted = submission.current;\n submission.current = null;\n if (!closeOnSettle || closedSinceSubmit.current) return;\n // A result with field errors keeps the dialog open; the Form.Root focuses the first errored\n // field (design/components/dialog.md, \"Dialog.Form and Form.Root\").\n if (!clean) return;\n if (dialog === null || !dialog.open) return;\n const returnValue = submitted?.returnValue ?? \"\";\n if (isLibrary) {\n // A library-owned close (design 2.3): `openChangeAction(false)` awaited, then\n // `close(returnValue)` in the commit, inside the view transition if set.\n requestClose(submitted?.event, \"activate\", returnValue);\n return;\n }\n recordCloseIntent({ reason: \"activate\", event: submitted?.event });\n dialog.close(returnValue);\n },\n [closeOnSettle, popupRef, isLibrary, recordCloseIntent, requestClose],\n );\n\n const state: DialogFormState = { pending };\n\n return useRender<ComponentPropsWithRef<\"form\">, DialogFormState>({\n defaultElement: \"form\",\n render,\n state,\n className,\n style,\n children: (s) => (\n <>\n {resolveStateValue(children, s)}\n <DialogFormSettle\n watches={watches}\n missingAction={action === undefined}\n onPendingChange={setPending}\n onSettled={onSettled}\n />\n </>\n ),\n props: rest,\n libraryProps: {\n method: action === undefined ? \"dialog\" : typeof action === \"string\" ? method : undefined,\n // React's own type wants `void | Promise<void>`; the library's actions return `unknown`\n // (conventions 2.2) and React ignores the result.\n action: action as ComponentPropsWithRef<\"form\">[\"action\"],\n },\n ref: libraryRef,\n });\n}\n\nDialogForm.displayName = \"DialogForm\";\n\n/**\n * Rendered among the form's children, so it reads the `FormContext` exactly when the form is a\n * `Form.Root` (either orientation of the `render` composition): the settle close then waits for\n * a result with no field error (`hasAnyError`, the `autoReset` predicate, hidden stale entries\n * included).\n */\nfunction DialogFormSettle({\n watches,\n missingAction,\n onPendingChange,\n onSettled,\n}: {\n readonly watches: boolean;\n readonly missingAction: boolean;\n readonly onPendingChange: (pending: boolean) => void;\n readonly onSettled: (clean: boolean) => void;\n}) {\n const form = use(FormContext);\n useDevWarning(\n form !== null && missingAction,\n isDev &&\n \"Dialog.Form: rendered as a `Form.Root`, it needs a function `action`; without one the form \" +\n \"navigates instead of closing the dialog. Render a plain `<Dialog.Form>` for a \" +\n '`method=\"dialog\"` form.',\n );\n const isForm = form !== null;\n const errors = form?.errors;\n const settled = useCallback(\n () => onSettled(!isForm || !hasAnyError(errors)),\n [isForm, errors, onSettled],\n );\n if (!watches) return null;\n return <FormStatusWatcher onPendingChange={onPendingChange} onSettled={settled} />;\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;;;AAuFvC,SAAgB,WAAW,EACzB,QACA,gBAAgB,MAChB,QACA,WACA,OACA,UACA,QACA,GAAG,QACe;CAClB,MAAM,MAAM,iBAAiB,aAAa;CAC1C,MAAM,EAAE,UAAU,mBAAmB,iBAAiB;CACtD,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,aAAa,OAAqD,IAAI;CAG5E,MAAM,oBAAoB,OAAO,KAAK;CACtC,MAAM,UAAU,OAAO,WAAW;CAIlC,MAAM,aAAa,aAAa,SAA0B;EACxD,MAAM,YAAY,UAAiB;GACjC,IAAI,MAAM,WAAW,MAAM;GAC3B,MAAM,YAAa,MAAsB;GAIzC,WAAW,UAAU;IAAE;IAAO,aAAa,WAAW,SAAS;GAAG;GAClE,kBAAkB,UAAU;EAC9B;EACA,MAAM,SAAS,KAAK,QAAQ,QAAQ;EACpC,MAAM,WAAW,UAAiB;GAChC,IAAI,MAAM,WAAW,QAAQ,kBAAkB,UAAU;EAC3D;EACA,KAAK,iBAAiB,UAAU,UAAU,IAAI;EAC9C,QAAQ,iBAAiB,SAAS,OAAO;EACzC,aAAa;GACX,KAAK,oBAAoB,UAAU,UAAU,IAAI;GACjD,QAAQ,oBAAoB,SAAS,OAAO;EAC9C;CACF,GAAG,CAAC,CAAC;CAGL,MAAM,YAAY,aACf,UAAmB;EAClB,MAAM,SAAS,SAAS;EACxB,MAAM,YAAY,WAAW;EAC7B,WAAW,UAAU;EACrB,IAAI,CAAC,iBAAiB,kBAAkB,SAAS;EAGjD,IAAI,CAAC,OAAO;EACZ,IAAI,WAAW,QAAQ,CAAC,OAAO,MAAM;EACrC,MAAM,cAAc,WAAW,eAAe;EAC9C,IAAI,WAAW;GAGb,aAAa,WAAW,OAAO,YAAY,WAAW;GACtD;EACF;EACA,kBAAkB;GAAE,QAAQ;GAAY,OAAO,WAAW;EAAM,CAAC;EACjE,OAAO,MAAM,WAAW;CAC1B,GACA;EAAC;EAAe;EAAU;EAAW;EAAmB;CAAY,CACtE;CAIA,OAAO,UAA0D;EAC/D,gBAAgB;EAChB;EACA,OAAA,EAL+B,QAK3B;EACJ;EACA;EACA,WAAW,MACT,qBAAA,UAAA,EAAA,UAAA,CACG,kBAAkB,UAAU,CAAC,GAC9B,oBAAC,kBAAD;GACW;GACT,eAAe,WAAW,KAAA;GAC1B,iBAAiB;GACN;EACZ,CAAA,CACD,EAAA,CAAA;EAEJ,OAAO;EACP,cAAc;GACZ,QAAQ,WAAW,KAAA,IAAY,WAAW,OAAO,WAAW,WAAW,SAAS,KAAA;GAGxE;EACV;EACA,KAAK;CACP,CAAC;AACH;AAEA,WAAW,cAAc;;;;;;;AAQzB,SAAS,iBAAiB,EACxB,SACA,eACA,iBACA,aAMC;CACD,MAAM,OAAO,IAAI,WAAW;CAC5B,cACE,SAAS,QAAQ,eACjB,SACE,oMAGJ;CACA,MAAM,SAAS,SAAS;CACxB,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,kBACR,UAAU,CAAC,UAAU,CAAC,YAAY,MAAM,CAAC,GAC/C;EAAC;EAAQ;EAAQ;CAAS,CAC5B;CACA,IAAI,CAAC,SAAS,OAAO;CACrB,OAAO,oBAAC,mBAAD;EAAoC;EAAiB,WAAW;CAAU,CAAA;AACnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-popup.d.mts","names":[],"sources":["../../src/dialog/dialog-popup.tsx"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"dialog-popup.d.mts","names":[],"sources":["../../src/dialog/dialog-popup.tsx"],"mappings":";;;;;;;iBAuCiB;;WAEN;;WAEA;;;;;;;iBAQM,yBAAyB,KACxC;;;;;;;;;;;;;EAeA;;;;;;;;;;;EAWA,eAAe,UAAU;;;;;;;;;;EAUzB;;;;;;;;EAQA;;;;;;;;;;;;;;;;EAgBA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;wBAkCvC,cACd,aACA,cACA,cACA,uBACA,YACA,WACA,OACA,UACA,WACG,QACF,mBAAgB;yBAXH"}
|