@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
|
@@ -3,53 +3,21 @@ import { dataAttr } from "../internal/data-attr.mjs";
|
|
|
3
3
|
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
4
4
|
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
5
5
|
import { useRender } from "../internal/use-render.mjs";
|
|
6
|
+
import { useLatest } from "../internal/use-latest.mjs";
|
|
6
7
|
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
7
|
-
import { isPopoverOpen } from "../internal/popover-open.mjs";
|
|
8
8
|
import { useDialogContext } from "./dialog-context.mjs";
|
|
9
|
-
import { useContentFocusProbe } from "../internal/content-focus-probe.mjs";
|
|
10
|
-
import { withCssTransitionCut } from "../internal/css-transition-cut.mjs";
|
|
11
|
-
import { commandOf, renderOverlayContent, resolveInitialFocus, returnFocusToTrigger, useCloseHold, useInitialFocusTarget, useJsFreePropWarnings } from "../internal/overlay-popup.mjs";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
9
|
+
import { useContentFocusProbe } from "../internal/overlay/content-focus-probe.mjs";
|
|
10
|
+
import { withCssTransitionCut } from "../internal/overlay/css-transition-cut.mjs";
|
|
11
|
+
import { commandOf, renderOverlayContent, resolveInitialFocus, returnFocusToTrigger, useCloseHold, useInitialFocusTarget, useJsFreePropWarnings } from "../internal/overlay/overlay-popup.mjs";
|
|
12
|
+
import { createPopupFlags, showWithFocus } from "../internal/overlay/overlay-show.mjs";
|
|
13
|
+
import { useApplyOpenState } from "../internal/overlay/use-apply-open-state.mjs";
|
|
14
|
+
import { eventSource } from "../internal/overlay/invokers.mjs";
|
|
15
|
+
import { useModalRegistration } from "../internal/overlay/use-modal-registration.mjs";
|
|
14
16
|
import { useShownNameWarning } from "../internal/use-name-warning.mjs";
|
|
17
|
+
import { listenDialogDismiss } from "./dialog-dismiss.mjs";
|
|
15
18
|
import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from "react";
|
|
16
19
|
//#region src/dialog/dialog-popup.tsx
|
|
17
20
|
const isDev = process.env.NODE_ENV !== "production";
|
|
18
|
-
/** The nearest `<dialog>` around a node (the dialog itself counts). */
|
|
19
|
-
function closestDialog(target) {
|
|
20
|
-
return target instanceof Element ? target.closest("dialog") : null;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* An open popover that takes Escape before the dialog: `auto` or `hint` (they have a close
|
|
24
|
-
* watcher). A `manual` popover, or `hint` where the engine maps it to `manual`, does not.
|
|
25
|
-
*/
|
|
26
|
-
function isOpenLightPopover(element) {
|
|
27
|
-
if (!element.hasAttribute("popover")) return false;
|
|
28
|
-
const reflected = element.popover;
|
|
29
|
-
if ((typeof reflected === "string" ? reflected : element.getAttribute("popover").toLowerCase()) === "manual") return false;
|
|
30
|
-
return isPopoverOpen(element);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Whether Escape belongs to a layer inside `dialog` that sits above it (design 9: "closes the
|
|
34
|
-
* innermost one only"): the target is inside an open nested `<dialog>` or popover, or an open
|
|
35
|
-
* `auto` / `hint` popover inside the dialog would take the close request (close watchers are
|
|
36
|
-
* per document, not per focus).
|
|
37
|
-
*/
|
|
38
|
-
function escapeBelongsToInnerLayer(dialog, target) {
|
|
39
|
-
for (let node = target instanceof Element ? target : null; node !== null && node !== dialog; node = node.parentElement) {
|
|
40
|
-
if (node instanceof HTMLDialogElement && node.open) return true;
|
|
41
|
-
if (isOpenLightPopover(node)) return true;
|
|
42
|
-
}
|
|
43
|
-
for (const element of dialog.querySelectorAll("[popover]")) if (isOpenLightPopover(element)) return true;
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
/** Whether a pointer event on the dialog itself lies outside its border box (the `::backdrop`). */
|
|
47
|
-
function onBackdrop(dialog, event) {
|
|
48
|
-
if (event.target !== dialog) return false;
|
|
49
|
-
const { clientX, clientY } = event;
|
|
50
|
-
const rect = dialog.getBoundingClientRect();
|
|
51
|
-
return !(rect.top <= clientY && clientY <= rect.bottom && rect.left <= clientX && clientX <= rect.right);
|
|
52
|
-
}
|
|
53
21
|
/** The submitter's or invoker's `value` (`""` without one, or where the engine gives no source). */
|
|
54
22
|
function valueOf(element) {
|
|
55
23
|
if (element instanceof HTMLButtonElement || element instanceof HTMLInputElement) return element.value;
|
|
@@ -81,9 +49,7 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
|
|
|
81
49
|
const isLibrary = ctx.mode === "library";
|
|
82
50
|
const { modal, ids, popupRef, triggerRef } = ctx;
|
|
83
51
|
const [dialog, setDialog] = useState(null);
|
|
84
|
-
const
|
|
85
|
-
const libraryClose = useRef(false);
|
|
86
|
-
const refusedFact = useRef(false);
|
|
52
|
+
const [flags] = useState(createPopupFlags);
|
|
87
53
|
const initialFocusTarget = useInitialFocusTarget("Dialog.Popup", "dialog");
|
|
88
54
|
const exit = useCloseHold(ctx.committed, isLibrary, transition);
|
|
89
55
|
const contentProbe = useContentFocusProbe(popupRef);
|
|
@@ -91,32 +57,16 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
|
|
|
91
57
|
useModalRegistration(dialog);
|
|
92
58
|
useJsFreePropWarnings("Dialog.Popup", "dialog", isLibrary, transition, keepMounted);
|
|
93
59
|
const checkElement = useElementCheck(isDev && ((element) => element.tagName !== "DIALOG" ? `Dialog.Popup: expected to render a <dialog> element but got <${element.tagName.toLowerCase()}>. Top layer, backdrop, focus and Escape all come from a real <dialog>.` : null));
|
|
94
|
-
const libraryRef = useCallback((element) => {
|
|
95
|
-
checkElement?.(element);
|
|
96
|
-
popupRef.current = element;
|
|
97
|
-
setDialog(element);
|
|
98
|
-
return () => {
|
|
99
|
-
if (popupRef.current === element) popupRef.current = null;
|
|
100
|
-
setDialog(null);
|
|
101
|
-
};
|
|
102
|
-
}, [checkElement, popupRef]);
|
|
103
60
|
const openDialog = (element) => {
|
|
104
|
-
const refused =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const added = target !== null && !target.hasAttribute("autofocus");
|
|
110
|
-
if (added) target.setAttribute("autofocus", "");
|
|
111
|
-
try {
|
|
112
|
-
withCssTransitionCut(element, transition !== void 0, () => {
|
|
61
|
+
const refused = flags.takeRefusedFact() && !modal;
|
|
62
|
+
showWithFocus(element, {
|
|
63
|
+
refused,
|
|
64
|
+
autofocus: refused ? null : initialFocusTarget(element, initialFocus),
|
|
65
|
+
show: () => withCssTransitionCut(element, transition !== void 0, () => {
|
|
113
66
|
if (modal) element.showModal();
|
|
114
67
|
else element.show();
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
if (added) target.removeAttribute("autofocus");
|
|
118
|
-
if (inerted) element.removeAttribute("inert");
|
|
119
|
-
}
|
|
68
|
+
})
|
|
69
|
+
});
|
|
120
70
|
};
|
|
121
71
|
const reconcileOnMount = useEffectEvent(() => {
|
|
122
72
|
const element = popupRef.current;
|
|
@@ -126,27 +76,20 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
|
|
|
126
76
|
useLayoutEffect(() => {
|
|
127
77
|
if (isLibrary) reconcileOnMount();
|
|
128
78
|
}, [isLibrary]);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
withCssTransitionCut(element, transition !== void 0, () => element.close(returnValue));
|
|
142
|
-
if (contentProbe.hadFocus()) {
|
|
143
|
-
contentProbe.forget();
|
|
144
|
-
returnFocusToTrigger(element, triggerRef.current);
|
|
145
|
-
}
|
|
79
|
+
useApplyOpenState(ctx, {
|
|
80
|
+
flags,
|
|
81
|
+
exit,
|
|
82
|
+
probe: contentProbe,
|
|
83
|
+
isShown: (element) => element.open,
|
|
84
|
+
show: openDialog,
|
|
85
|
+
hide: (element) => {
|
|
86
|
+
const returnValue = ctx.takeCloseReturnValue();
|
|
87
|
+
withCssTransitionCut(element, transition !== void 0, () => element.close(returnValue));
|
|
88
|
+
if (contentProbe.hadFocus()) {
|
|
89
|
+
contentProbe.forget();
|
|
90
|
+
returnFocusToTrigger(element, triggerRef.current);
|
|
146
91
|
}
|
|
147
92
|
}
|
|
148
|
-
if (ctx.committed && element.open) contentProbe.forget();
|
|
149
|
-
exit.releaseIfIdle(ctx.committed, awaitingClose.current, element.open);
|
|
150
93
|
});
|
|
151
94
|
useEffect(() => {
|
|
152
95
|
if (isLibrary || initialFocus === void 0 || dialog === null) return;
|
|
@@ -197,28 +140,58 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
|
|
|
197
140
|
event.preventDefault();
|
|
198
141
|
ctx.requestClose(event, "activate", valueOf(submitter));
|
|
199
142
|
});
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
if (element === null || event.target !== element) return;
|
|
203
|
-
awaitingClose.current = false;
|
|
143
|
+
const handleClose = (element, event) => {
|
|
144
|
+
flags.endClose();
|
|
204
145
|
const active = element.ownerDocument.activeElement;
|
|
205
146
|
if (active !== null && element.contains(active)) returnFocusToTrigger(element, triggerRef.current);
|
|
206
147
|
const intent = ctx.takeCloseIntent();
|
|
207
|
-
const echo =
|
|
208
|
-
libraryClose.current = false;
|
|
148
|
+
const echo = flags.takeLibraryClose();
|
|
209
149
|
if (!isLibrary) return;
|
|
210
150
|
exit.afterClose(element, echo);
|
|
211
151
|
if (echo) return;
|
|
212
|
-
|
|
152
|
+
flags.markFact();
|
|
213
153
|
ctx.takeCloseReturnValue();
|
|
214
154
|
ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? "dismiss", element.returnValue);
|
|
155
|
+
};
|
|
156
|
+
const latestHandleClose = useLatest(handleClose);
|
|
157
|
+
const onClose = useEffectEvent((event) => {
|
|
158
|
+
const element = popupRef.current;
|
|
159
|
+
if (element === null || event.target !== element) return;
|
|
160
|
+
handleClose(element, event);
|
|
215
161
|
});
|
|
162
|
+
const mounted = useRef(false);
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
mounted.current = true;
|
|
165
|
+
return () => {
|
|
166
|
+
mounted.current = false;
|
|
167
|
+
};
|
|
168
|
+
}, [mounted]);
|
|
169
|
+
const libraryRef = useCallback((element) => {
|
|
170
|
+
checkElement?.(element);
|
|
171
|
+
popupRef.current = element;
|
|
172
|
+
flags.attach(element, (lost) => {
|
|
173
|
+
if (mounted.current) latestHandleClose.current(lost, void 0);
|
|
174
|
+
});
|
|
175
|
+
setDialog(element);
|
|
176
|
+
return () => {
|
|
177
|
+
if (popupRef.current === element) popupRef.current = null;
|
|
178
|
+
setDialog(null);
|
|
179
|
+
};
|
|
180
|
+
}, [
|
|
181
|
+
checkElement,
|
|
182
|
+
popupRef,
|
|
183
|
+
flags,
|
|
184
|
+
latestHandleClose,
|
|
185
|
+
mounted
|
|
186
|
+
]);
|
|
216
187
|
const onBeforeToggle = useEffectEvent((event) => {
|
|
217
188
|
const element = popupRef.current;
|
|
218
189
|
if (element === null || event.target !== element) return;
|
|
219
190
|
const newState = event.newState;
|
|
220
|
-
|
|
221
|
-
|
|
191
|
+
if (newState === "closed") {
|
|
192
|
+
flags.beginClose();
|
|
193
|
+
exit.recordBaseline(element);
|
|
194
|
+
}
|
|
222
195
|
if (newState === "open") {
|
|
223
196
|
ctx.nextOpenGeneration();
|
|
224
197
|
contentProbe.forget();
|
|
@@ -226,7 +199,6 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
|
|
|
226
199
|
});
|
|
227
200
|
useEffect(() => {
|
|
228
201
|
if (dialog === null) return;
|
|
229
|
-
const doc = dialog.ownerDocument;
|
|
230
202
|
const root = dialog.getRootNode();
|
|
231
203
|
const nativeClosedBy = experimental_closedBy && "closedBy" in dialog;
|
|
232
204
|
const listeners = [
|
|
@@ -255,82 +227,14 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
|
|
|
255
227
|
false
|
|
256
228
|
]
|
|
257
229
|
];
|
|
258
|
-
if (!modal && !nativeClosedBy) listeners.push([
|
|
259
|
-
dialog,
|
|
260
|
-
"keydown",
|
|
261
|
-
(event) => {
|
|
262
|
-
const keyboardEvent = event;
|
|
263
|
-
if (keyboardEvent.key !== "Escape" || keyboardEvent.defaultPrevented) return;
|
|
264
|
-
if (!dialog.open || closestDialog(keyboardEvent.target) !== dialog) return;
|
|
265
|
-
if (escapeBelongsToInnerLayer(dialog, keyboardEvent.target)) return;
|
|
266
|
-
keyboardEvent.preventDefault();
|
|
267
|
-
dialog.requestClose();
|
|
268
|
-
},
|
|
269
|
-
false
|
|
270
|
-
]);
|
|
271
|
-
let pressedOutside = false;
|
|
272
|
-
const isOutside = (target) => {
|
|
273
|
-
return !(target instanceof Node) || !dialog.contains(target);
|
|
274
|
-
};
|
|
275
|
-
let outsideAttached = false;
|
|
276
|
-
const onOutsidePointerDown = (event) => {
|
|
277
|
-
pressedOutside = dialog.open && isOutside(event.target);
|
|
278
|
-
};
|
|
279
|
-
const onOutsideClick = (event) => {
|
|
280
|
-
const pressed = pressedOutside;
|
|
281
|
-
pressedOutside = false;
|
|
282
|
-
if (!dialog.open || !pressed || !isOutside(event.target)) return;
|
|
283
|
-
dialog.requestClose();
|
|
284
|
-
};
|
|
285
|
-
const syncOutside = () => {
|
|
286
|
-
const want = dialog.open;
|
|
287
|
-
if (want === outsideAttached) return;
|
|
288
|
-
outsideAttached = want;
|
|
289
|
-
pressedOutside = false;
|
|
290
|
-
if (want) {
|
|
291
|
-
doc.addEventListener("pointerdown", onOutsidePointerDown, true);
|
|
292
|
-
doc.addEventListener("click", onOutsideClick, true);
|
|
293
|
-
} else {
|
|
294
|
-
doc.removeEventListener("pointerdown", onOutsidePointerDown, true);
|
|
295
|
-
doc.removeEventListener("click", onOutsideClick, true);
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
if (lightDismiss && !nativeClosedBy) {
|
|
299
|
-
if (modal) listeners.push([
|
|
300
|
-
dialog,
|
|
301
|
-
"pointerdown",
|
|
302
|
-
(event) => {
|
|
303
|
-
pressedOutside = dialog.open && onBackdrop(dialog, event);
|
|
304
|
-
},
|
|
305
|
-
false
|
|
306
|
-
], [
|
|
307
|
-
dialog,
|
|
308
|
-
"click",
|
|
309
|
-
(event) => {
|
|
310
|
-
const pressed = pressedOutside;
|
|
311
|
-
pressedOutside = false;
|
|
312
|
-
if (!dialog.open || !pressed || !onBackdrop(dialog, event)) return;
|
|
313
|
-
dialog.requestClose();
|
|
314
|
-
},
|
|
315
|
-
false
|
|
316
|
-
]);
|
|
317
|
-
else {
|
|
318
|
-
listeners.push([
|
|
319
|
-
dialog,
|
|
320
|
-
"toggle",
|
|
321
|
-
syncOutside,
|
|
322
|
-
false
|
|
323
|
-
]);
|
|
324
|
-
syncOutside();
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
230
|
for (const [target, type, listener, capture] of listeners) target.addEventListener(type, listener, capture);
|
|
231
|
+
const stopDismiss = nativeClosedBy ? null : listenDialogDismiss(dialog, {
|
|
232
|
+
modal,
|
|
233
|
+
lightDismiss
|
|
234
|
+
});
|
|
328
235
|
return () => {
|
|
329
236
|
for (const [target, type, listener, capture] of listeners) target.removeEventListener(type, listener, capture);
|
|
330
|
-
|
|
331
|
-
doc.removeEventListener("pointerdown", onOutsidePointerDown, true);
|
|
332
|
-
doc.removeEventListener("click", onOutsideClick, true);
|
|
333
|
-
}
|
|
237
|
+
stopDismiss?.();
|
|
334
238
|
};
|
|
335
239
|
}, [
|
|
336
240
|
dialog,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-popup.mjs","names":[],"sources":["../../src/dialog/dialog-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n ReactNode,\n RefObject,\n ViewTransitionClass,\n} from \"react\";\nimport { useContentFocusProbe } from \"../internal/content-focus-probe.js\";\nimport { withCssTransitionCut } from \"../internal/css-transition-cut.js\";\nimport {\n commandOf,\n renderOverlayContent,\n resolveInitialFocus,\n returnFocusToTrigger,\n useCloseHold,\n useInitialFocusTarget,\n useJsFreePropWarnings,\n} from \"../internal/overlay-popup.js\";\nimport { eventSource } from \"../internal/invokers.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useModalRegistration } from \"../internal/use-modal-registration.js\";\nimport { useShownNameWarning } from \"../internal/use-name-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\n/**\n * State of `Dialog.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogPopupState {\n /** Committed open state (library mode); `false` in JS-free mode. Read `:open` for the DOM truth. */\n readonly open: boolean;\n /** The Root's `modal`. */\n readonly modal: boolean;\n}\n\n/**\n * Props of `Dialog.Popup`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogPopupProps extends Omit<\n ComponentPropsWithRef<\"dialog\">,\n \"id\" | \"open\" | \"closedby\" | \"onToggle\" | \"onBeforeToggle\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Library mode: what happens to the children while the dialog is closed.\n * - `false` (default): not rendered. Mounting them is part of the opening transition, so\n * content that suspends holds the open until it is ready. Unmount waits for the dialog's\n * exit animations.\n * - `true`: rendered inside `<Activity mode=\"hidden\">`: DOM and state preserved, effects\n * stopped, pre-rendered at low priority. Not in the server HTML.\n *\n * Ignored in JS-free mode (always mounted).\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Element to focus when the dialog opens: a ref, or a selector resolved inside the dialog.\n * The library writes `autofocus` on it right before `showModal()` / `show()` and the platform\n * focuses it. Use `tabIndex={-1}` on a heading or wrapper for long or destructive dialogs (APG).\n *\n * In JS-free mode the browser opens the dialog itself, so the attribute is written after\n * hydration and kept while mounted; before hydration only `autoFocus` in the markup works.\n *\n * @defaultValue the platform's choice (first focusable descendant; the dialog itself if none)\n */\n initialFocus?: RefObject<HTMLElement | null> | string;\n /**\n * Close on a click outside the dialog (on the backdrop for modal dialogs).\n * Baseline: JS `pointerdown` + `click` listeners, which close only when both the press and the\n * click land outside (a drag that starts inside, such as selecting text, never closes); with\n * `experimental_closedBy`, native `closedby=\"any\"`, which behaves the same. A click on the\n * Trigger of an open non-modal dialog counts as outside, as it does natively.\n *\n * @defaultValue `false`\n */\n lightDismiss?: boolean;\n /**\n * Experimental (Chrome 134+, Firefox 141+; Safari 27.0 ignores it). Renders `closedby`\n * (`\"any\"` when `lightDismiss`, else `\"closerequest\"`) and skips the JS dismiss listeners where\n * `HTMLDialogElement.prototype.closedBy` exists. Elsewhere the JS baseline stays active.\n *\n * @defaultValue `false`\n */\n experimental_closedBy?: boolean;\n /**\n * Library mode only. Forwarded to the `<ViewTransition default>` around the dialog. Animates\n * the opening commit, content changes while open, and every library-driven close (a Close\n * part, a Form submit or settled action, a foreign close command, a controlled\n * `open={false}`), in all engines; dismissals (Escape, a click outside: `onOpenChange`) are the\n * browser's and animate with CSS only, never with a view transition. Ignored (dev warning) in\n * JS-free mode. While a view transition runs, the dialog's CSS transitions are turned off for\n * the moment of the library's own show or close (an inline `transition: none !important`,\n * restored right after), so that show or close runs no CSS transition (a `@keyframes`\n * animation is not cut).\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogPopupState>;\n /** Must render a `<dialog>`. */\n render?: RenderProp<ComponentPropsWithRef<\"dialog\">, DialogPopupState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\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\n/** The submitter's or invoker's `value` (`\"\"` without one, or where the engine gives no source). */\nfunction valueOf(element: unknown): string {\n if (element instanceof HTMLButtonElement || element instanceof HTMLInputElement) {\n return element.value;\n }\n return \"\";\n}\n\n/**\n * The dialog itself: a `<dialog>` with the id the Trigger's `commandfor` names, wired to Title\n * and Description through `aria-labelledby` / `aria-describedby`. Never renders `open`: modal\n * opening and closing go through `showModal()` / `close()` only. Style it with `:open` and\n * `:modal`; it emits `data-modal` but no `data-open`.\n *\n * In library mode the children render from committed state, so content that suspends keeps the\n * dialog closed (and the Trigger pending) until it is ready; `showModal()` runs in the layout\n * effect of the commit that mounted them. A close a part asks for (Close, a `method=\"dialog\"`\n * submit, a Form's settle close, a foreign close command) is cancelled and goes through the\n * Root: `openChangeAction(false)` is awaited and `close(returnValue)` runs in the layout effect\n * of the commit that ends it, inside the view transition if `transition` is set. A dismissal\n * (Escape, a click outside, script) is the browser's, a fact: the native `close` event makes\n * committed state `false` urgently and calls `onOpenChange(false, { reason: \"dismiss\",\n * returnValue })`; no view transition runs for it.\n *\n * Owned keys (conventions 1.2): `id`, `open`, `closedby`, `aria-labelledby` and\n * `aria-describedby` (token-merged), `data-modal`, `suppressHydrationWarning`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogPopup({\n keepMounted,\n initialFocus,\n lightDismiss = false,\n experimental_closedBy = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogPopupProps) {\n const ctx = useDialogContext(\"Dialog.Popup\");\n const isLibrary = ctx.mode === \"library\";\n const { modal, ids, popupRef, triggerRef } = ctx;\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n // Set by the synchronous `beforetoggle` of a close, cleared by the `close` event a task later:\n // the dialog is closed but its fact is not reported yet, so the apply effect must not re-open\n // it from a commit that lands in between.\n const awaitingClose = useRef(false);\n // Set right before the library's own `close()` (the apply effect), consumed by the `close`\n // event it causes: the echo is recognised by its source, not by what is intended. Every other\n // close is a fact (overlay-open-change.md 6.3), reported the moment it happens, also while a\n // part's close is in flight: nothing is stored for later.\n const libraryClose = useRef(false);\n // Set when a fact closed the dialog, cleared once a commit has `committed` false (the fact was\n // adopted): a show while it is set is the re-open of a dismissal a controlled parent refused\n // (overlay-open-change.md 2.4).\n const refusedFact = useRef(false);\n const initialFocusTarget = useInitialFocusTarget(\"Dialog.Popup\", \"dialog\");\n\n // `held`: children stay mounted while the close animates (design 4.4).\n const exit = useCloseHold(ctx.committed, isLibrary, transition);\n\n // Whether the content unmounted while holding focus since the dialog was last shown: a close\n // with `transition` removes the focused Close part before `close()` runs (design 6.2 rule 2).\n const contentProbe = useContentFocusProbe(popupRef);\n const { wrapContent } = contentProbe;\n\n // Toast's Viewport moves its region into the topmost open modal (design/components/toast.md 4.3).\n useModalRegistration(dialog);\n\n useJsFreePropWarnings(\"Dialog.Popup\", \"dialog\", isLibrary, transition, keepMounted);\n\n const checkElement = useElementCheck<HTMLDialogElement>(\n isDev &&\n ((element) =>\n element.tagName !== \"DIALOG\"\n ? `Dialog.Popup: expected to render a <dialog> element but got <${element.tagName.toLowerCase()}>. ` +\n \"Top layer, backdrop, focus and Escape all come from a real <dialog>.\"\n : null),\n );\n const libraryRef = useCallback(\n (element: HTMLDialogElement) => {\n checkElement?.(element);\n popupRef.current = element;\n setDialog(element);\n return () => {\n if (popupRef.current === element) popupRef.current = null;\n setDialog(null);\n };\n },\n [checkElement, popupRef],\n );\n\n // --- Opening -----------------------------------------------------------------------------\n\n const openDialog = (element: HTMLDialogElement): void => {\n // A refused re-open of a non-modal dialog never moves focus (#156): no initial focus target,\n // and the dialog is `inert` for the duration of `show()`, so the dialog focusing steps focus\n // nothing (a consumer's own `inert` is left alone). A modal dialog must hold focus: its\n // re-open is a normal open.\n const refused = refusedFact.current && !modal;\n refusedFact.current = false;\n const inerted = refused && !element.hasAttribute(\"inert\");\n if (inerted) element.setAttribute(\"inert\", \"\");\n const target = refused ? null : initialFocusTarget(element, initialFocus);\n // The platform's dialog focusing steps honour `autofocus`; React drops `autoFocus` on\n // client-rendered content (react/react#23301). Never `.focus()` (design 6.1).\n const added = target !== null && !target.hasAttribute(\"autofocus\");\n if (added) target.setAttribute(\"autofocus\", \"\");\n try {\n // A view transition animates the open: the CSS enter does not run next to it (conventions\n // 5.1).\n withCssTransitionCut(element, transition !== undefined, () => {\n if (modal) element.showModal();\n else element.show();\n });\n } finally {\n if (added) target.removeAttribute(\"autofocus\");\n if (inerted) element.removeAttribute(\"inert\");\n }\n };\n\n // Mount reconciliation (design 2.4): a click before hydration opened the dialog natively.\n // Runs before the apply effect; the dispatch makes the apply effect wait for it.\n const reconcileOnMount = useEffectEvent(() => {\n const element = popupRef.current;\n if (element === null || !element.open) return;\n ctx.requestOpen(undefined, \"platform\");\n });\n useLayoutEffect(() => {\n if (isLibrary) reconcileOnMount();\n }, [isLibrary]);\n\n // The apply effect (design 2.5), as usePopoverPopup's: once nothing is in flight, the DOM\n // follows committed state. Opens on the user's dispatch, `defaultOpen`, a controlled parent,\n // the re-open of a dismissal a controlled parent refused (overlay-open-change.md 2.4: in the\n // fact's own commit, which `epoch` makes re-render the Popup, or once the requests it\n // superseded settled); closes after a part-initiated close settled, a controlled close, or a\n // refused pre-hydration open. Also returns focus after a close whose commit unmounted the\n // focused content, and releases a `held` no exit animation is going to release (4.4). It runs\n // only for commits that re-render the Popup (the Root's context is memoised): do not rely on an\n // unrelated render to re-apply state.\n useLayoutEffect(() => {\n if (!isLibrary) return;\n const element = popupRef.current;\n if (element === null || !element.isConnected) return;\n // The fact was adopted (or anything else closed the dialog in state): a later show is a new\n // open, with initial focus.\n if (!ctx.committed) refusedFact.current = false;\n if (!ctx.pending && ctx.latestInFlight() === null) {\n if (ctx.committed && !element.open) {\n // Closed, but its `close` event has not arrived yet: wait for it.\n if (!awaitingClose.current) openDialog(element);\n } else if (!ctx.committed && element.open) {\n // The library's own close: the `close` listener recognises it by `libraryClose` and\n // dispatches nothing. `close()`, not `requestClose()`: the veto point was\n // `openChangeAction`, not `cancel`. The part's `returnValue` (design 2.3), `\"\"` for a\n // controlled close.\n ctx.recordCloseIntent(undefined);\n libraryClose.current = true;\n const returnValue = ctx.takeCloseReturnValue();\n withCssTransitionCut(element, transition !== undefined, () => element.close(returnValue));\n // The close commit may have unmounted the focused content before `close()`: a\n // non-modal dialog restores focus only from inside, so do it now (a modal one always\n // restores it on `close()`).\n if (contentProbe.hadFocus()) {\n contentProbe.forget();\n returnFocusToTrigger(element, triggerRef.current);\n }\n }\n }\n // Content that unmounted while the dialog stays open (not a close): forget it.\n if (ctx.committed && element.open) contentProbe.forget();\n // A hold the close commit set (or a fact's commit) that no exit animation is going to\n // release: the dialog is closed and its `close` event has been handled.\n exit.releaseIfIdle(ctx.committed, awaitingClose.current, element.open);\n });\n\n // JS-free mode: there is no \"right before showModal()\" (the browser runs the command), so the\n // `autofocus` attribute stays on the target while it is mounted.\n useEffect(() => {\n if (isLibrary || initialFocus === undefined || dialog === null) return;\n const target = resolveInitialFocus(dialog, initialFocus);\n if (target === null || !dialog.contains(target) || target.hasAttribute(\"autofocus\")) return;\n target.setAttribute(\"autofocus\", \"\");\n return () => target.removeAttribute(\"autofocus\");\n }, [isLibrary, initialFocus, dialog]);\n\n // --- Native listeners (conventions 7.4) ---------------------------------------------------\n\n const onCommand = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element || event.defaultPrevented) return;\n const command = commandOf(event);\n if (command === \"show-modal\") {\n // A foreign invoker (design 2.2): opening goes through the library in library mode.\n if (!isLibrary) return;\n event.preventDefault();\n ctx.requestOpen(event, \"activate\");\n } else if (command === \"request-close\" || command === \"close\") {\n if (isLibrary) {\n // A foreign close invoker (design 2.3) goes through the library like a foreign\n // `show-modal`: same markup as Dialog.Close, same behaviour. `source` is the invoker\n // (`\"\"` where an engine gives none).\n event.preventDefault();\n ctx.requestClose(event, \"activate\", valueOf(eventSource(event)));\n } else if (element.open) {\n // The `command` event fires whatever the dialog's state (HTML): a close at a closed\n // dialog leaves no intent for a later close.\n ctx.recordCloseIntent({ reason: \"activate\", event });\n }\n }\n });\n\n // On the dialog's root node (the document, or a shadow root: `submit` is not composed), bubble\n // phase: after React's root listener, so a consumer's `onSubmit` has run (design 8.1).\n const onSubmit = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n const form = event.target;\n if (element === null || !(form instanceof HTMLFormElement)) return;\n if (form.closest(\"dialog\") !== element) return;\n const submitter = (event as SubmitEvent).submitter;\n const formMethod = submitter?.getAttribute(\"formmethod\");\n const method = formMethod != null ? formMethod.toLowerCase() : form.method;\n if (method !== \"dialog\") return;\n if (!isLibrary) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n return;\n }\n // The consumer blocked the submission: the form did not submit, the dialog stays open.\n if (event.defaultPrevented) return;\n // The consumer opted out with `stopPropagation()`: the browser closes the dialog, reported\n // as a fact. Checked explicitly because React's root can be this same node (FUNSTACK\n // Static hydrates the document), where `stopPropagation()` does not stop this listener.\n if (event.cancelBubble) return;\n // Cancel the native close; the library closes once `openChangeAction(false)` settled.\n event.preventDefault();\n ctx.requestClose(event, \"activate\", valueOf(submitter));\n });\n\n const onClose = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n awaitingClose.current = false;\n\n // Focus return is the platform's; it leaves focus inside the hidden dialog only when the\n // opener is gone (design 6.2).\n const active = element.ownerDocument.activeElement;\n if (active !== null && element.contains(active)) {\n returnFocusToTrigger(element, triggerRef.current);\n }\n\n const intent = ctx.takeCloseIntent();\n const echo = libraryClose.current;\n libraryClose.current = false;\n if (!isLibrary) return;\n\n // The library's own `close()` is no fact.\n exit.afterClose(element, echo);\n\n if (echo) return;\n refusedFact.current = true;\n // Closed by the browser: a returnValue a pending part close recorded will never be used.\n ctx.takeCloseReturnValue();\n // A fact, also while a part's close is in flight: it supersedes that request (committed\n // `false` now) and `onOpenChange(false)` is called (overlay-open-change.md 2.5, 6.3).\n ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? \"dismiss\", element.returnValue);\n });\n\n const onBeforeToggle = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n const newState = (event as ToggleEvent).newState;\n awaitingClose.current = newState === \"closed\";\n // What already runs inside is not the exit.\n if (newState === \"closed\") exit.recordBaseline(element);\n // Every native open counts as a new opening (design 3.4, as Popover 14.1): foreign,\n // pre-hydration and JS-free opens too, so a Close action from an earlier opening skips its\n // close. Counted here, synchronously inside `showModal()` / `show()`, not at the queued\n // `toggle`: an action settling between the open and that task would otherwise still see the\n // old generation and close the new open.\n if (newState === \"open\") {\n ctx.nextOpenGeneration();\n contentProbe.forget();\n }\n });\n\n useEffect(() => {\n if (dialog === null) return;\n const doc = dialog.ownerDocument;\n // The document, or the shadow root the dialog lives in (`submit` does not cross it).\n const root = dialog.getRootNode();\n // Feature detection only with the flag on, inside an effect (conventions 8).\n const nativeClosedBy = experimental_closedBy && \"closedBy\" in dialog;\n\n const listeners: [EventTarget, string, EventListener, boolean][] = [\n [dialog, \"command\", onCommand, false],\n // Bubble phase on the root node: after React's root listener (the consumer's `onSubmit`).\n [root, \"submit\", onSubmit, false],\n [dialog, \"close\", onClose, false],\n [dialog, \"beforetoggle\", onBeforeToggle, false],\n ];\n\n if (!modal && !nativeClosedBy) {\n // Non-modal dialogs get no close watcher Escape from the platform (design 2.6).\n listeners.push([\n dialog,\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 false,\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 && !nativeClosedBy) {\n if (modal) {\n // A press or click on the ::backdrop targets the dialog itself, outside its border box.\n listeners.push(\n [\n dialog,\n \"pointerdown\",\n (event) => {\n pressedOutside = dialog.open && onBackdrop(dialog, event);\n },\n false,\n ],\n [\n dialog,\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 false,\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([dialog, \"toggle\", syncOutside, false]);\n syncOutside();\n }\n }\n\n for (const [target, type, listener, capture] of listeners) {\n target.addEventListener(type, listener, capture);\n }\n return () => {\n for (const [target, type, listener, capture] of listeners) {\n target.removeEventListener(type, listener, capture);\n }\n if (outsideAttached) {\n doc.removeEventListener(\"pointerdown\", onOutsidePointerDown, true);\n doc.removeEventListener(\"click\", onOutsideClick, true);\n }\n };\n }, [dialog, modal, lightDismiss, experimental_closedBy]);\n\n // Development check (design 9): the dialog has an accessible name when it is (or can be)\n // shown.\n useShownNameWarning(\n dialog,\n !isLibrary || ctx.committed,\n isDev &&\n \"Dialog.Popup: the dialog has no accessible name. Render a Dialog.Title, or give the \" +\n \"Popup an `aria-label`.\",\n );\n\n const state: DialogPopupState = { open: ctx.committed, modal };\n const visible = ctx.committed || exit.held;\n\n const content = (s: DialogPopupState): ReactNode =>\n renderOverlayContent({ isLibrary, keepMounted, visible, wrapContent }, () =>\n resolveStateValue(children, s),\n );\n\n const libraryProps: ComponentPropsWithRef<\"dialog\"> & DataAttributes = {\n id: ids.popup,\n // Never rendered: removing `open` by hand hides a modal dialog without `close` and leaves\n // `:modal` true (research). Owned so a `render` element cannot add it.\n open: undefined,\n closedby: experimental_closedBy ? (lightDismiss ? \"any\" : \"closerequest\") : undefined,\n \"aria-labelledby\": ids.title,\n \"aria-describedby\": ids.description,\n \"data-modal\": dataAttr(modal),\n // A pre-hydration open leaves an `open` attribute the server did not render (design 2.4).\n suppressHydrationWarning: true,\n };\n\n const element = useRender<ComponentPropsWithRef<\"dialog\">, DialogPopupState>({\n defaultElement: \"dialog\",\n render,\n state,\n className,\n style,\n children: content,\n props: rest,\n libraryProps,\n ref: libraryRef,\n });\n\n return useTransitionBoundary(\"Dialog.Popup\", isLibrary ? transition : undefined, element);\n}\n\nDialogPopup.displayName = \"DialogPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;AAwHA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,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,KAA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QACK;IAIL,UAAU,KAAK;KAAC;KAAQ;KAAU;KAAa;IAAK,CAAC;IACrD,YAAY;GACd;EACF;EAEA,KAAK,MAAM,CAAC,QAAQ,MAAM,UAAU,YAAY,WAC9C,OAAO,iBAAiB,MAAM,UAAU,OAAO;EAEjD,aAAa;GACX,KAAK,MAAM,CAAC,QAAQ,MAAM,UAAU,YAAY,WAC9C,OAAO,oBAAoB,MAAM,UAAU,OAAO;GAEpD,IAAI,iBAAiB;IACnB,IAAI,oBAAoB,eAAe,sBAAsB,IAAI;IACjE,IAAI,oBAAoB,SAAS,gBAAgB,IAAI;GACvD;EACF;CACF,GAAG;EAAC;EAAQ;EAAO;EAAc;CAAqB,CAAC;CAIvD,oBACE,QACA,CAAC,aAAa,IAAI,WAClB,SACE,4GAEJ;CAEA,MAAM,QAA0B;EAAE,MAAM,IAAI;EAAW;CAAM;CAC7D,MAAM,UAAU,IAAI,aAAa,KAAK;CAEtC,MAAM,WAAW,MACf,qBAAqB;EAAE;EAAW;EAAa;EAAS;CAAY,SAClE,kBAAkB,UAAU,CAAC,CAC/B;CAEF,MAAM,eAAiE;EACrE,IAAI,IAAI;EAGR,MAAM,KAAA;EACN,UAAU,wBAAyB,eAAe,QAAQ,iBAAkB,KAAA;EAC5E,mBAAmB,IAAI;EACvB,oBAAoB,IAAI;EACxB,cAAc,SAAS,KAAK;EAE5B,0BAA0B;CAC5B;CAEA,MAAM,UAAU,UAA6D;EAC3E,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU;EACV,OAAO;EACP;EACA,KAAK;CACP,CAAC;CAED,OAAO,sBAAsB,gBAAgB,YAAY,aAAa,KAAA,GAAW,OAAO;AAC1F;AAEA,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"dialog-popup.mjs","names":[],"sources":["../../src/dialog/dialog-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n ReactNode,\n RefObject,\n ViewTransitionClass,\n} from \"react\";\nimport { useContentFocusProbe } from \"../internal/overlay/content-focus-probe.js\";\nimport { withCssTransitionCut } from \"../internal/overlay/css-transition-cut.js\";\nimport {\n commandOf,\n renderOverlayContent,\n resolveInitialFocus,\n returnFocusToTrigger,\n useCloseHold,\n useInitialFocusTarget,\n useJsFreePropWarnings,\n} from \"../internal/overlay/overlay-popup.js\";\nimport { createPopupFlags, showWithFocus } from \"../internal/overlay/overlay-show.js\";\nimport { useApplyOpenState } from \"../internal/overlay/use-apply-open-state.js\";\nimport { eventSource } from \"../internal/overlay/invokers.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useModalRegistration } from \"../internal/overlay/use-modal-registration.js\";\nimport { useShownNameWarning } from \"../internal/use-name-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\nimport { listenDialogDismiss } from \"./dialog-dismiss.js\";\n\n/**\n * State of `Dialog.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogPopupState {\n /** Committed open state (library mode); `false` in JS-free mode. Read `:open` for the DOM truth. */\n readonly open: boolean;\n /** The Root's `modal`. */\n readonly modal: boolean;\n}\n\n/**\n * Props of `Dialog.Popup`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogPopupProps extends Omit<\n ComponentPropsWithRef<\"dialog\">,\n \"id\" | \"open\" | \"closedby\" | \"onToggle\" | \"onBeforeToggle\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Library mode: what happens to the children while the dialog is closed.\n * - `false` (default): not rendered. Mounting them is part of the opening transition, so\n * content that suspends holds the open until it is ready. Unmount waits for the dialog's\n * exit animations.\n * - `true`: rendered inside `<Activity mode=\"hidden\">`: DOM and state preserved, effects\n * stopped, pre-rendered at low priority. Not in the server HTML.\n *\n * Ignored in JS-free mode (always mounted).\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Element to focus when the dialog opens: a ref, or a selector resolved inside the dialog.\n * The library writes `autofocus` on it right before `showModal()` / `show()` and the platform\n * focuses it. Use `tabIndex={-1}` on a heading or wrapper for long or destructive dialogs (APG).\n *\n * In JS-free mode the browser opens the dialog itself, so the attribute is written after\n * hydration and kept while mounted; before hydration only `autoFocus` in the markup works.\n *\n * @defaultValue the platform's choice (first focusable descendant; the dialog itself if none)\n */\n initialFocus?: RefObject<HTMLElement | null> | string;\n /**\n * Close on a click outside the dialog (on the backdrop for modal dialogs).\n * Baseline: JS `pointerdown` + `click` listeners, which close only when both the press and the\n * click land outside (a drag that starts inside, such as selecting text, never closes); with\n * `experimental_closedBy`, native `closedby=\"any\"`, which behaves the same. A click on the\n * Trigger of an open non-modal dialog counts as outside, as it does natively.\n *\n * @defaultValue `false`\n */\n lightDismiss?: boolean;\n /**\n * Experimental (Chrome 134+, Firefox 141+; Safari 27.0 ignores it). Renders `closedby`\n * (`\"any\"` when `lightDismiss`, else `\"closerequest\"`) and skips the JS dismiss listeners where\n * `HTMLDialogElement.prototype.closedBy` exists. Elsewhere the JS baseline stays active.\n *\n * @defaultValue `false`\n */\n experimental_closedBy?: boolean;\n /**\n * Library mode only. Forwarded to the `<ViewTransition default>` around the dialog. Animates\n * the opening commit, content changes while open, and every library-driven close (a Close\n * part, a Form submit or settled action, a foreign close command, a controlled\n * `open={false}`), in all engines; dismissals (Escape, a click outside: `onOpenChange`) are the\n * browser's and animate with CSS only, never with a view transition. Ignored (dev warning) in\n * JS-free mode. While a view transition runs, the dialog's CSS transitions are turned off for\n * the moment of the library's own show or close (an inline `transition: none !important`,\n * restored right after), so that show or close runs no CSS transition (a `@keyframes`\n * animation is not cut).\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogPopupState>;\n /** Must render a `<dialog>`. */\n render?: RenderProp<ComponentPropsWithRef<\"dialog\">, DialogPopupState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The submitter's or invoker's `value` (`\"\"` without one, or where the engine gives no source). */\nfunction valueOf(element: unknown): string {\n if (element instanceof HTMLButtonElement || element instanceof HTMLInputElement) {\n return element.value;\n }\n return \"\";\n}\n\n/**\n * The dialog itself: a `<dialog>` with the id the Trigger's `commandfor` names, wired to Title\n * and Description through `aria-labelledby` / `aria-describedby`. Never renders `open`: modal\n * opening and closing go through `showModal()` / `close()` only. Style it with `:open` and\n * `:modal`; it emits `data-modal` but no `data-open`.\n *\n * In library mode the children render from committed state, so content that suspends keeps the\n * dialog closed (and the Trigger pending) until it is ready; `showModal()` runs in the layout\n * effect of the commit that mounted them. A close a part asks for (Close, a `method=\"dialog\"`\n * submit, a Form's settle close, a foreign close command) is cancelled and goes through the\n * Root: `openChangeAction(false)` is awaited and `close(returnValue)` runs in the layout effect\n * of the commit that ends it, inside the view transition if `transition` is set. A dismissal\n * (Escape, a click outside, script) is the browser's, a fact: the native `close` event makes\n * committed state `false` urgently and calls `onOpenChange(false, { reason: \"dismiss\",\n * returnValue })`; no view transition runs for it.\n *\n * Owned keys (conventions 1.2): `id`, `open`, `closedby`, `aria-labelledby` and\n * `aria-describedby` (token-merged), `data-modal`, `suppressHydrationWarning`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogPopup({\n keepMounted,\n initialFocus,\n lightDismiss = false,\n experimental_closedBy = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogPopupProps) {\n const ctx = useDialogContext(\"Dialog.Popup\");\n const isLibrary = ctx.mode === \"library\";\n const { modal, ids, popupRef, triggerRef } = ctx;\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n // `awaitingClose` (the `close` event of a close has not arrived), the library echo\n // `libraryClose` (every other close is a fact, dialog.md 2.7, reported the moment it happens,\n // also while a part's close is in flight) and `refusedFact` (conventions 3.9.4), as\n // usePopoverPopup's.\n const [flags] = useState(createPopupFlags);\n const initialFocusTarget = useInitialFocusTarget(\"Dialog.Popup\", \"dialog\");\n\n // `held`: children stay mounted while the close animates (design 4.4).\n const exit = useCloseHold(ctx.committed, isLibrary, transition);\n\n // Whether the content unmounted while holding focus since the dialog was last shown: a close\n // with `transition` removes the focused Close part before `close()` runs (design 6.2 rule 2).\n const contentProbe = useContentFocusProbe(popupRef);\n const { wrapContent } = contentProbe;\n\n // Toast's Viewport moves its region into the topmost open modal (design/components/toast.md 4.3).\n useModalRegistration(dialog);\n\n useJsFreePropWarnings(\"Dialog.Popup\", \"dialog\", isLibrary, transition, keepMounted);\n\n const checkElement = useElementCheck<HTMLDialogElement>(\n isDev &&\n ((element) =>\n element.tagName !== \"DIALOG\"\n ? `Dialog.Popup: expected to render a <dialog> element but got <${element.tagName.toLowerCase()}>. ` +\n \"Top layer, backdrop, focus and Escape all come from a real <dialog>.\"\n : null),\n );\n // --- Opening -----------------------------------------------------------------------------\n\n const openDialog = (element: HTMLDialogElement): void => {\n // A refused re-open of a non-modal dialog never moves focus (#156): no initial focus target,\n // and the dialog is `inert` for the duration of `show()`, so the dialog focusing steps focus\n // nothing (a consumer's own `inert` is left alone). A modal dialog must hold focus: its\n // re-open is a normal open. Two steps on purpose: the flag is taken (and cleared) on every\n // show, a modal one included; `!modal && take()` would leave it set for a modal dialog.\n const wasRefused = flags.takeRefusedFact();\n const refused = wasRefused && !modal;\n // Otherwise the platform's dialog focusing steps honour `autofocus` (design 6.1).\n showWithFocus(element, {\n refused,\n autofocus: refused ? null : initialFocusTarget(element, initialFocus),\n // A view transition animates the open: the CSS enter does not run next to it (conventions\n // 5.1).\n show: () =>\n withCssTransitionCut(element, transition !== undefined, () => {\n if (modal) element.showModal();\n else element.show();\n }),\n });\n };\n\n // Mount reconciliation (design 2.4): a click before hydration opened the dialog natively.\n // Runs before the apply effect; the dispatch makes the apply effect wait for it.\n const reconcileOnMount = useEffectEvent(() => {\n const element = popupRef.current;\n if (element === null || !element.open) return;\n ctx.requestOpen(undefined, \"platform\");\n });\n useLayoutEffect(() => {\n if (isLibrary) reconcileOnMount();\n }, [isLibrary]);\n\n // The apply effect (design 2.5), shared with usePopoverPopup. Keep this call right after mount\n // reconciliation (as there): layout effects run in call order, and at mount the\n // reconciliation's dispatch must come first, so that the first apply sees it in flight and\n // waits. Opens on the user's dispatch, `defaultOpen`, a controlled parent, the re-open of a\n // dismissal a controlled parent refused; closes after a part-initiated close settled, a\n // controlled close, or a refused pre-hydration open.\n useApplyOpenState(ctx, {\n flags,\n exit,\n probe: contentProbe,\n isShown: (element) => element.open,\n show: openDialog,\n hide: (element) => {\n // `close()`, not `requestClose()`: the veto point was `openChangeAction`, not `cancel`. The\n // part's `returnValue` (design 2.3), `\"\"` for a controlled close.\n const returnValue = ctx.takeCloseReturnValue();\n withCssTransitionCut(element, transition !== undefined, () => element.close(returnValue));\n // The close commit may have unmounted the focused content before `close()`: a non-modal\n // dialog restores focus only from inside, so do it now (a modal one always restores it on\n // `close()`).\n if (contentProbe.hadFocus()) {\n contentProbe.forget();\n returnFocusToTrigger(element, triggerRef.current);\n }\n },\n });\n\n // JS-free mode: there is no \"right before showModal()\" (the browser runs the command), so the\n // `autofocus` attribute stays on the target while it is mounted.\n useEffect(() => {\n if (isLibrary || initialFocus === undefined || dialog === null) return;\n const target = resolveInitialFocus(dialog, initialFocus);\n if (target === null || !dialog.contains(target) || target.hasAttribute(\"autofocus\")) return;\n target.setAttribute(\"autofocus\", \"\");\n return () => target.removeAttribute(\"autofocus\");\n }, [isLibrary, initialFocus, dialog]);\n\n // --- Native listeners (conventions 7.4) ---------------------------------------------------\n\n const onCommand = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element || event.defaultPrevented) return;\n const command = commandOf(event);\n if (command === \"show-modal\") {\n // A foreign invoker (design 2.2): opening goes through the library in library mode.\n if (!isLibrary) return;\n event.preventDefault();\n ctx.requestOpen(event, \"activate\");\n } else if (command === \"request-close\" || command === \"close\") {\n if (isLibrary) {\n // A foreign close invoker (design 2.3) goes through the library like a foreign\n // `show-modal`: same markup as Dialog.Close, same behaviour. `source` is the invoker\n // (`\"\"` where an engine gives none).\n event.preventDefault();\n ctx.requestClose(event, \"activate\", valueOf(eventSource(event)));\n } else if (element.open) {\n // The `command` event fires whatever the dialog's state (HTML): a close at a closed\n // dialog leaves no intent for a later close.\n ctx.recordCloseIntent({ reason: \"activate\", event });\n }\n }\n });\n\n // On the dialog's root node (the document, or a shadow root: `submit` is not composed), bubble\n // phase: after React's root listener, so a consumer's `onSubmit` has run (design 8.1).\n const onSubmit = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n const form = event.target;\n if (element === null || !(form instanceof HTMLFormElement)) return;\n if (form.closest(\"dialog\") !== element) return;\n const submitter = (event as SubmitEvent).submitter;\n const formMethod = submitter?.getAttribute(\"formmethod\");\n const method = formMethod != null ? formMethod.toLowerCase() : form.method;\n if (method !== \"dialog\") return;\n if (!isLibrary) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n return;\n }\n // The consumer blocked the submission: the form did not submit, the dialog stays open.\n if (event.defaultPrevented) return;\n // The consumer opted out with `stopPropagation()`: the browser closes the dialog, reported\n // as a fact. Checked explicitly because React's root can be this same node (FUNSTACK\n // Static hydrates the document), where `stopPropagation()` does not stop this listener.\n if (event.cancelBubble) return;\n // Cancel the native close; the library closes once `openChangeAction(false)` settled.\n event.preventDefault();\n ctx.requestClose(event, \"activate\", valueOf(submitter));\n });\n\n // The `close` listener's work, also replayed for an element that remounted before its `close`\n // event (#159; `event` is `undefined` there: no event fired).\n const handleClose = (element: HTMLDialogElement, event: Event | undefined): void => {\n flags.endClose();\n\n // Focus return is the platform's; it leaves focus inside the hidden dialog only when the\n // opener is gone (design 6.2).\n const active = element.ownerDocument.activeElement;\n if (active !== null && element.contains(active)) {\n returnFocusToTrigger(element, triggerRef.current);\n }\n\n const intent = ctx.takeCloseIntent();\n const echo = flags.takeLibraryClose();\n if (!isLibrary) return;\n\n // The library's own `close()` is no fact.\n exit.afterClose(element, echo);\n\n if (echo) return;\n flags.markFact();\n // Closed by the browser: a returnValue a pending part close recorded will never be used.\n ctx.takeCloseReturnValue();\n // A fact, also while a part's close is in flight: it supersedes that request (committed\n // `false` now) and `onOpenChange(false)` is called (conventions 3.9.5, dialog.md 2.7).\n ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? \"dismiss\", element.returnValue);\n };\n const latestHandleClose = useLatest(handleClose);\n\n const onClose = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n handleClose(element, event);\n });\n\n // Whether the Popup is mounted, for the #159 replay. A passive effect: a Suspense hide detaches\n // the element's ref (and runs layout cleanups) but keeps passive effects, so a hidden Popup\n // still counts as mounted.\n const mounted = useRef(false);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, [mounted]);\n\n const libraryRef = useCallback(\n (element: HTMLDialogElement) => {\n checkElement?.(element);\n popupRef.current = element;\n // A new element (a remount mid-close): the old one's `close` event never comes (#159). A\n // lost fact is replayed a timer task later, unless the Popup unmounted meanwhile; also while\n // a Suspense boundary hides it (the fact happened before the hide). Here, not in the\n // listener effect's cleanup: that passive cleanup runs after the remount's layout effects,\n // and no apply follows it.\n flags.attach(element, (lost) => {\n if (mounted.current) latestHandleClose.current(lost as HTMLDialogElement, undefined);\n });\n setDialog(element);\n return () => {\n if (popupRef.current === element) popupRef.current = null;\n setDialog(null);\n };\n },\n [checkElement, popupRef, flags, latestHandleClose, mounted],\n );\n\n const onBeforeToggle = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n const newState = (event as ToggleEvent).newState;\n // An open does not end a close (as Popover's): the close's `close` event still comes, HTML\n // queues it whatever follows, and nothing reads the flag while the dialog is shown (#159).\n if (newState === \"closed\") {\n flags.beginClose();\n // What already runs inside is not the exit.\n exit.recordBaseline(element);\n }\n // Every native open counts as a new opening (design 3.4, as Popover 14.1): foreign,\n // pre-hydration and JS-free opens too, so a Close action from an earlier opening skips its\n // close. Counted here, synchronously inside `showModal()` / `show()`, not at the queued\n // `toggle`: an action settling between the open and that task would otherwise still see the\n // old generation and close the new open.\n if (newState === \"open\") {\n ctx.nextOpenGeneration();\n contentProbe.forget();\n }\n });\n\n useEffect(() => {\n if (dialog === null) return;\n // The document, or the shadow root the dialog lives in (`submit` does not cross it).\n const root = dialog.getRootNode();\n // Feature detection only with the flag on, inside an effect (conventions 8).\n const nativeClosedBy = experimental_closedBy && \"closedBy\" in dialog;\n\n const listeners: [EventTarget, string, EventListener, boolean][] = [\n [dialog, \"command\", onCommand, false],\n // Bubble phase on the root node: after React's root listener (the consumer's `onSubmit`).\n [root, \"submit\", onSubmit, false],\n [dialog, \"close\", onClose, false],\n [dialog, \"beforetoggle\", onBeforeToggle, false],\n ];\n\n for (const [target, type, listener, capture] of listeners) {\n target.addEventListener(type, listener, capture);\n }\n // Escape on a non-modal dialog and light dismiss, where native `closedby` does not do them.\n const stopDismiss = nativeClosedBy\n ? null\n : listenDialogDismiss(dialog, { modal, lightDismiss });\n return () => {\n for (const [target, type, listener, capture] of listeners) {\n target.removeEventListener(type, listener, capture);\n }\n stopDismiss?.();\n };\n }, [dialog, modal, lightDismiss, experimental_closedBy]);\n\n // Development check (design 9): the dialog has an accessible name when it is (or can be)\n // shown.\n useShownNameWarning(\n dialog,\n !isLibrary || ctx.committed,\n isDev &&\n \"Dialog.Popup: the dialog has no accessible name. Render a Dialog.Title, or give the \" +\n \"Popup an `aria-label`.\",\n );\n\n const state: DialogPopupState = { open: ctx.committed, modal };\n const visible = ctx.committed || exit.held;\n\n const content = (s: DialogPopupState): ReactNode =>\n renderOverlayContent({ isLibrary, keepMounted, visible, wrapContent }, () =>\n resolveStateValue(children, s),\n );\n\n const libraryProps: ComponentPropsWithRef<\"dialog\"> & DataAttributes = {\n id: ids.popup,\n // Never rendered: removing `open` by hand hides a modal dialog without `close` and leaves\n // `:modal` true (research). Owned so a `render` element cannot add it.\n open: undefined,\n closedby: experimental_closedBy ? (lightDismiss ? \"any\" : \"closerequest\") : undefined,\n \"aria-labelledby\": ids.title,\n \"aria-describedby\": ids.description,\n \"data-modal\": dataAttr(modal),\n // A pre-hydration open leaves an `open` attribute the server did not render (design 2.4).\n suppressHydrationWarning: true,\n };\n\n const element = useRender<ComponentPropsWithRef<\"dialog\">, DialogPopupState>({\n defaultElement: \"dialog\",\n render,\n state,\n className,\n style,\n children: content,\n props: rest,\n libraryProps,\n ref: libraryRef,\n });\n\n return useTransitionBoundary(\"Dialog.Popup\", isLibrary ? transition : undefined, element);\n}\n\nDialogPopup.displayName = \"DialogPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2HA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,SAAS,QAAQ,SAA0B;CACzC,IAAI,mBAAmB,qBAAqB,mBAAmB,kBAC7D,OAAO,QAAQ;CAEjB,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,YAAY,EAC1B,aACA,cACA,eAAe,OACf,wBAAwB,OACxB,YACA,WACA,OACA,UACA,QACA,GAAG,QACgB;CACnB,MAAM,MAAM,iBAAiB,cAAc;CAC3C,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,OAAO,KAAK,UAAU,eAAe;CAC7C,MAAM,CAAC,QAAQ,aAAa,SAAmC,IAAI;CAKnE,MAAM,CAAC,SAAS,SAAS,gB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C1F;AAEA,YAAY,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-root.d.mts","names":[],"sources":["../../src/dialog/dialog-root.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"dialog-root.d.mts","names":[],"sources":["../../src/dialog/dialog-root.tsx"],"mappings":";;;;iBAkBiB,gCAAgC;;;;;;;;WAQtC,QAAQ;;;;;;WAMR;;;iBAIM;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM;;;;;;EAMf;;;;;EAKA;;;;;;;;;;;;;EAaA,mBAAmB,sBAAsB;;;;;;;;;;;;;;;EAezC,eAAe,6BAA6B;;;;;;EAM5C;;EAEA,WAAW,WAAW,WAAW;;;;;;;;;;;;;;;;;wBA0BnB,aACd,MACA,aACA,kBACA,cACA,OACA,YACC,kCAAe,IAAA;yBAPF"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createActionDetails } from "../internal/action-details.mjs";
|
|
2
|
+
import { createActionDetails } from "../internal/action/action-details.mjs";
|
|
3
3
|
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
4
|
+
import { intendedValue } from "../internal/action/use-controllable-action.mjs";
|
|
4
5
|
import { DialogContext } from "./dialog-context.mjs";
|
|
5
|
-
import { useOverlayRoot } from "../internal/use-overlay-root.mjs";
|
|
6
|
+
import { useOverlayRoot } from "../internal/overlay/use-overlay-root.mjs";
|
|
6
7
|
import { useCallback, useInsertionEffect, useMemo, useRef } from "react";
|
|
7
8
|
import { jsx } from "react/jsx-runtime";
|
|
8
9
|
//#region src/dialog/dialog-root.tsx
|
|
@@ -40,7 +41,7 @@ function DialogRoot({ open, defaultOpen, openChangeAction, onOpenChange, modal =
|
|
|
40
41
|
const { mode, intended, latestInFlight, optimistic, requestClose: closeRoot } = root;
|
|
41
42
|
const closeReturnValue = useRef(void 0);
|
|
42
43
|
useInsertionEffect(() => {
|
|
43
|
-
if (latestInFlight
|
|
44
|
+
if (intendedValue(latestInFlight, optimistic)) closeReturnValue.current = void 0;
|
|
44
45
|
});
|
|
45
46
|
const takeCloseReturnValue = useCallback(() => {
|
|
46
47
|
const value = closeReturnValue.current;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-root.mjs","names":[],"sources":["../../src/dialog/dialog-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useInsertionEffect, useMemo, useRef } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { useOverlayRoot } from \"../internal/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { DialogContext } from \"./dialog-context.js\";\nimport type { DialogContextValue } from \"./dialog-context.js\";\n\n/** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */\nexport interface DialogOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: Trigger (open), Close or Form submit (close).\n * `\"dismiss\"`: the user closed the dialog without a part: Escape, Android back, an assistive-\n * technology dismiss gesture, or a click outside (`lightDismiss` / `closedby=\"any\"`).\n * `\"platform\"`: the dialog was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n /**\n * On close: `dialog.returnValue`: the `value` of the Close button or the form submitter that\n * closed it; for a fact (`onOpenChange`), what the browser left (`\"\"` for Escape or a click\n * outside, the argument of a script `close(value)`). On open: `undefined`.\n */\n readonly returnValue: string | undefined;\n}\n\n/** State of `Dialog.Root`, passed to the function forms of `children`. */\nexport interface DialogRootState {\n /** Optimistic open state (`false` in JS-free mode). Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An `openChangeAction` dispatched through this Dialog is in flight (library mode only). */\n readonly pending: boolean;\n /** The `modal` prop. */\n readonly modal: boolean;\n}\n\n/**\n * Props of `Dialog.Root`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogRootProps {\n /**\n * Controlled open state. `undefined` means uncontrolled (and, with `defaultOpen`,\n * `openChangeAction` and `onOpenChange` also absent, JS-free mode). A controlled Root needs\n * `onOpenChange` too: the browser closes the dialog without asking (development warns).\n */\n open?: boolean;\n /**\n * Initial open state in uncontrolled library mode. The dialog opens after hydration, never in\n * the server HTML.\n */\n defaultOpen?: boolean;\n /**\n * Requests only. Awaited for `true` (the dialog opens when it resolves and the content has\n * rendered) and for a `false` the user asked a part for (`Dialog.Close`, a `Dialog.Form`\n * submit or settled action, a foreign close command: the dialog closes with\n * `details.returnValue` when it resolves, with a view transition if the Popup's `transition` is\n * set; a controlled parent that keeps `open` vetoes it). Never called for a dismissal: that goes\n * to `onOpenChange`. May be a Server Function. Rejections reach the nearest Error Boundary\n * above Root.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, DialogOpenChangeDetails>;\n /**\n * Facts only: the dialog was closed without the library closing it (Escape, Android back, an\n * assistive-technology dismiss, a click outside with `lightDismiss`, script `close()` /\n * `requestClose()`). Always `false`, with `returnValue` as the browser left it. Called\n * synchronously in the platform's `close` event, outside any Transition, and not awaited:\n * nothing is pending and no view transition runs; the dialog is already closed and its\n * committed state is already `false` (uncontrolled). A dismissal while a part's close is in\n * flight is reported at once and supersedes that close.\n *\n * Controlled: set your state **directly** here (`onOpenChange={setOpen}`), not in\n * `startTransition` and not after an `await`; a parent that keeps `open={true}` gets the\n * dialog re-opened at once. May return a promise (a Server Function); a rejection or a throw\n * goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, DialogOpenChangeDetails>;\n /**\n * `showModal()` (top layer, backdrop, inert page, Escape) or `show()`.\n *\n * @defaultValue `true`\n */\n modal?: boolean;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, DialogRootState>;\n}\n\nconst dialogDetails = (\n event: Event | undefined,\n reason: ChangeReason,\n returnValue?: string,\n): DialogOpenChangeDetails => createActionDetails(event, { reason, returnValue });\n\nconst isDialogOpen = (dialog: HTMLDialogElement): boolean => dialog.open;\n\n/**\n * Owns the ids, the mode, the open state and the context. Renders no DOM, so it has no `ref`,\n * `className` or `style`; `pending` is exposed through `children(state)` and the Trigger.\n *\n * Without `open`, `defaultOpen`, `openChangeAction` and `onOpenChange` the Dialog runs in\n * **JS-free mode**: the Trigger is a native `command=\"show-modal\"` invoker and the browser owns\n * everything. With any of them it runs in **library mode**: opening is a request, a transition\n * (the Trigger shows `data-pending`, content renders from committed state, `showModal()` runs\n * when it has committed), and so is a close a part asks for (Close, Form, a foreign close\n * command: `openChangeAction(false)` is awaited, `close(returnValue)` runs when it has\n * committed). Dismissals (Escape, a click outside) are the browser's facts, reported to\n * `onOpenChange`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogRoot({\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n modal = true,\n children,\n}: DialogRootProps) {\n // The popover machinery (design/components/popover.md 14.1) with the `<dialog>`'s `open` and\n // `returnValue` in the details: an open's `returnValue` is an own `undefined`.\n const root = useOverlayRoot<DialogOpenChangeDetails, HTMLDialogElement, [returnValue: string]>({\n component: \"dialog\",\n part: \"Dialog.Root\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: dialogDetails,\n isShown: isDialogOpen,\n });\n const { mode, intended, latestInFlight, optimistic, requestClose: closeRoot } = root;\n\n // The `returnValue` of a pending part-initiated close (design 2.3), handed to the apply\n // effect's `close()`. Stale once `true` is intended again (a vetoed close snapped back, or a\n // re-open), so the commit that shows it clears it.\n const closeReturnValue = useRef<string | undefined>(undefined);\n useInsertionEffect(() => {\n if (latestInFlight
|
|
1
|
+
{"version":3,"file":"dialog-root.mjs","names":[],"sources":["../../src/dialog/dialog-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useInsertionEffect, useMemo, useRef } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { intendedValue } from \"../internal/action/use-controllable-action.js\";\nimport { useOverlayRoot } from \"../internal/overlay/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { DialogContext } from \"./dialog-context.js\";\nimport type { DialogContextValue } from \"./dialog-context.js\";\n\n/** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */\nexport interface DialogOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: Trigger (open), Close or Form submit (close).\n * `\"dismiss\"`: the user closed the dialog without a part: Escape, Android back, an assistive-\n * technology dismiss gesture, or a click outside (`lightDismiss` / `closedby=\"any\"`).\n * `\"platform\"`: the dialog was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n /**\n * On close: `dialog.returnValue`: the `value` of the Close button or the form submitter that\n * closed it; for a fact (`onOpenChange`), what the browser left (`\"\"` for Escape or a click\n * outside, the argument of a script `close(value)`). On open: `undefined`.\n */\n readonly returnValue: string | undefined;\n}\n\n/** State of `Dialog.Root`, passed to the function forms of `children`. */\nexport interface DialogRootState {\n /** Optimistic open state (`false` in JS-free mode). Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An `openChangeAction` dispatched through this Dialog is in flight (library mode only). */\n readonly pending: boolean;\n /** The `modal` prop. */\n readonly modal: boolean;\n}\n\n/**\n * Props of `Dialog.Root`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogRootProps {\n /**\n * Controlled open state. `undefined` means uncontrolled (and, with `defaultOpen`,\n * `openChangeAction` and `onOpenChange` also absent, JS-free mode). A controlled Root needs\n * `onOpenChange` too: the browser closes the dialog without asking (development warns).\n */\n open?: boolean;\n /**\n * Initial open state in uncontrolled library mode. The dialog opens after hydration, never in\n * the server HTML.\n */\n defaultOpen?: boolean;\n /**\n * Requests only. Awaited for `true` (the dialog opens when it resolves and the content has\n * rendered) and for a `false` the user asked a part for (`Dialog.Close`, a `Dialog.Form`\n * submit or settled action, a foreign close command: the dialog closes with\n * `details.returnValue` when it resolves, with a view transition if the Popup's `transition` is\n * set; a controlled parent that keeps `open` vetoes it). Never called for a dismissal: that goes\n * to `onOpenChange`. May be a Server Function. Rejections reach the nearest Error Boundary\n * above Root.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, DialogOpenChangeDetails>;\n /**\n * Facts only: the dialog was closed without the library closing it (Escape, Android back, an\n * assistive-technology dismiss, a click outside with `lightDismiss`, script `close()` /\n * `requestClose()`). Always `false`, with `returnValue` as the browser left it. Called\n * synchronously in the platform's `close` event, outside any Transition, and not awaited:\n * nothing is pending and no view transition runs; the dialog is already closed and its\n * committed state is already `false` (uncontrolled). A dismissal while a part's close is in\n * flight is reported at once and supersedes that close.\n *\n * Controlled: set your state **directly** here (`onOpenChange={setOpen}`), not in\n * `startTransition` and not after an `await`; a parent that keeps `open={true}` gets the\n * dialog re-opened at once. May return a promise (a Server Function); a rejection or a throw\n * goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, DialogOpenChangeDetails>;\n /**\n * `showModal()` (top layer, backdrop, inert page, Escape) or `show()`.\n *\n * @defaultValue `true`\n */\n modal?: boolean;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, DialogRootState>;\n}\n\nconst dialogDetails = (\n event: Event | undefined,\n reason: ChangeReason,\n returnValue?: string,\n): DialogOpenChangeDetails => createActionDetails(event, { reason, returnValue });\n\nconst isDialogOpen = (dialog: HTMLDialogElement): boolean => dialog.open;\n\n/**\n * Owns the ids, the mode, the open state and the context. Renders no DOM, so it has no `ref`,\n * `className` or `style`; `pending` is exposed through `children(state)` and the Trigger.\n *\n * Without `open`, `defaultOpen`, `openChangeAction` and `onOpenChange` the Dialog runs in\n * **JS-free mode**: the Trigger is a native `command=\"show-modal\"` invoker and the browser owns\n * everything. With any of them it runs in **library mode**: opening is a request, a transition\n * (the Trigger shows `data-pending`, content renders from committed state, `showModal()` runs\n * when it has committed), and so is a close a part asks for (Close, Form, a foreign close\n * command: `openChangeAction(false)` is awaited, `close(returnValue)` runs when it has\n * committed). Dismissals (Escape, a click outside) are the browser's facts, reported to\n * `onOpenChange`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogRoot({\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n modal = true,\n children,\n}: DialogRootProps) {\n // The popover machinery (design/components/popover.md 14.1) with the `<dialog>`'s `open` and\n // `returnValue` in the details: an open's `returnValue` is an own `undefined`.\n const root = useOverlayRoot<DialogOpenChangeDetails, HTMLDialogElement, [returnValue: string]>({\n component: \"dialog\",\n part: \"Dialog.Root\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: dialogDetails,\n isShown: isDialogOpen,\n });\n const { mode, intended, latestInFlight, optimistic, requestClose: closeRoot } = root;\n\n // The `returnValue` of a pending part-initiated close (design 2.3), handed to the apply\n // effect's `close()`. Stale once `true` is intended again (a vetoed close snapped back, or a\n // re-open), so the commit that shows it clears it.\n const closeReturnValue = useRef<string | undefined>(undefined);\n useInsertionEffect(() => {\n if (intendedValue(latestInFlight, optimistic)) closeReturnValue.current = undefined;\n });\n const takeCloseReturnValue = useCallback((): string => {\n const value = closeReturnValue.current;\n closeReturnValue.current = undefined;\n return value ?? \"\";\n }, []);\n\n // A library-owned close (design 2.3): `openChangeAction(false)` is awaited and the Popup's\n // apply effect calls `close(returnValue)` in the commit that ends it. A fact's `notifyClosed`\n // records no `returnValue`.\n const requestClose = useCallback(\n (event: Event | undefined, reason: ChangeReason, returnValue: string): void => {\n if (mode !== \"library\" || !intended()) return;\n closeReturnValue.current = returnValue;\n closeRoot(event, reason, returnValue);\n },\n [mode, intended, closeRoot],\n );\n\n // Memoised: `root` changes only with the open state and pending, so the value changes only\n // with those and `modal`, and the parts do not re-render for an unrelated render of the Root.\n const context = useMemo<DialogContextValue>(\n () => ({ ...root, modal, requestClose, takeCloseReturnValue }),\n [root, modal, requestClose, takeCloseReturnValue],\n );\n\n const state: DialogRootState = { open: optimistic, pending: root.pending, modal };\n\n return <DialogContext value={context}>{resolveStateValue(children, state)}</DialogContext>;\n}\n\nDialogRoot.displayName = \"DialogRoot\";\n"],"mappings":";;;;;;;;;AAoGA,MAAM,iBACJ,OACA,QACA,gBAC4B,oBAAoB,OAAO;CAAE;CAAQ;AAAY,CAAC;AAEhF,MAAM,gBAAgB,WAAuC,OAAO;;;;;;;;;;;;;;;;AAiBpE,SAAgB,WAAW,EACzB,MACA,aACA,kBACA,cACA,QAAQ,MACR,YACkB;CAGlB,MAAM,OAAO,eAAkF;EAC7F,WAAW;EACX,MAAM;EACN;EACA;EACA;EACA;EACA,SAAS;EACT,SAAS;CACX,CAAC;CACD,MAAM,EAAE,MAAM,UAAU,gBAAgB,YAAY,cAAc,cAAc;CAKhF,MAAM,mBAAmB,OAA2B,KAAA,CAAS;CAC7D,yBAAyB;EACvB,IAAI,cAAc,gBAAgB,UAAU,GAAG,iBAAiB,UAAU,KAAA;CAC5E,CAAC;CACD,MAAM,uBAAuB,kBAA0B;EACrD,MAAM,QAAQ,iBAAiB;EAC/B,iBAAiB,UAAU,KAAA;EAC3B,OAAO,SAAS;CAClB,GAAG,CAAC,CAAC;CAKL,MAAM,eAAe,aAClB,OAA0B,QAAsB,gBAA8B;EAC7E,IAAI,SAAS,aAAa,CAAC,SAAS,GAAG;EACvC,iBAAiB,UAAU;EAC3B,UAAU,OAAO,QAAQ,WAAW;CACtC,GACA;EAAC;EAAM;EAAU;CAAS,CAC5B;CAIA,MAAM,UAAU,eACP;EAAE,GAAG;EAAM;EAAO;EAAc;CAAqB,IAC5D;EAAC;EAAM;EAAO;EAAc;CAAoB,CAClD;CAEA,MAAM,QAAyB;EAAE,MAAM;EAAY,SAAS,KAAK;EAAS;CAAM;CAEhF,OAAO,oBAAC,eAAD;EAAe,OAAO;EAAU,UAAA,kBAAkB,UAAU,KAAK;CAAiB,CAAA;AAC3F;AAEA,WAAW,cAAc"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
|
-
import { disabledButton, rendersButton } from "../internal/render-element.mjs";
|
|
3
|
+
import { cancelClick, disabledButton, rendersButton } from "../internal/render-element.mjs";
|
|
4
4
|
import { useRender } from "../internal/use-render.mjs";
|
|
5
5
|
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
6
6
|
import { useDialogContext } from "./dialog-context.mjs";
|
|
7
|
-
import { registerTrigger } from "../internal/trigger-ref.mjs";
|
|
8
|
-
import { useCallback,
|
|
7
|
+
import { registerTrigger } from "../internal/overlay/trigger-ref.mjs";
|
|
8
|
+
import { useCallback, useRef } from "react";
|
|
9
9
|
//#region src/dialog/dialog-trigger.tsx
|
|
10
10
|
const isDev = process.env.NODE_ENV !== "production";
|
|
11
11
|
/**
|
|
@@ -32,14 +32,16 @@ function DialogTrigger({ disabled = false, className, style, children, render, .
|
|
|
32
32
|
disabled
|
|
33
33
|
};
|
|
34
34
|
const checkElement = useElementCheck(isDev && ((element) => !isLibrary && modal && element.tagName !== "BUTTON" ? `Dialog.Trigger: rendered a <${element.tagName.toLowerCase()}> in JS-free mode. Only a <button> runs \`command="show-modal"\`; this trigger will not open the dialog. Render a <button>, or put the Dialog in library mode (\`defaultOpen={false}\`).` : null));
|
|
35
|
+
const checkPopup = useElementCheck(isDev && (() => document.getElementById(ids.popup) === null ? "Dialog.Trigger: no Dialog.Popup is rendered for this Dialog.Root; the trigger opens nothing." : null));
|
|
35
36
|
const libraryRef = useCallback((element) => {
|
|
36
37
|
checkElement?.(element);
|
|
38
|
+
checkPopup?.(element);
|
|
37
39
|
return registerTrigger(triggerRef, element, "Dialog.Trigger");
|
|
38
|
-
}, [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
}, [
|
|
41
|
+
checkElement,
|
|
42
|
+
checkPopup,
|
|
43
|
+
triggerRef
|
|
44
|
+
]);
|
|
43
45
|
const installClick = isLibrary || !modal;
|
|
44
46
|
const disabledProps = disabledButton(render, disabled, { handlesClick: installClick });
|
|
45
47
|
const invoker = modal && disabledProps.invoker && rendersButton(render);
|
|
@@ -70,6 +72,7 @@ function DialogTrigger({ disabled = false, className, style, children, render, .
|
|
|
70
72
|
commandfor: invoker ? ids.popup : void 0,
|
|
71
73
|
command: invoker ? "show-modal" : void 0,
|
|
72
74
|
...installClick && { onClick },
|
|
75
|
+
...!installClick && !disabledProps.invoker && { onClick: cancelClick },
|
|
73
76
|
...installPress && { onPointerDown },
|
|
74
77
|
"data-open": dataAttr(state.open),
|
|
75
78
|
"data-pending": dataAttr(state.pending),
|