@funstack/ui 0.1.0-alpha.17 → 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 +35 -38
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +1 -1
- package/dist/button/button.d.mts +18 -11
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +32 -16
- 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 +15 -12
- 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 -161
- 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/accordion.md +1 -1
- package/dist/docs/components/button.md +13 -10
- package/dist/docs/components/dialog.md +4 -4
- package/dist/docs/components/field.md +4 -3
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/toast.md +8 -5
- package/dist/docs/concepts/browser-owned-state.md +1 -1
- 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} +20 -32
- 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} +8 -8
- 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 -63
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -0
- package/dist/internal/{use-popover-trigger.d.mts → overlay/use-popover-trigger.d.mts} +3 -3
- package/dist/internal/overlay/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/{use-popover-trigger.mjs → overlay/use-popover-trigger.mjs} +47 -26
- package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -0
- package/dist/internal/{use-resolved-placement.mjs → overlay/use-resolved-placement.mjs} +2 -2
- package/dist/internal/overlay/use-resolved-placement.mjs.map +1 -0
- package/dist/internal/render-element.mjs +47 -9
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +4 -8
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/use-mount-fixed.mjs +22 -0
- package/dist/internal/use-mount-fixed.mjs.map +1 -0
- package/dist/internal/use-register-count.mjs +4 -1
- package/dist/internal/use-register-count.mjs.map +1 -1
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/menu/menu-checkbox-item.mjs +2 -2
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +1 -1
- package/dist/menu/menu-gestures.mjs.map +1 -1
- package/dist/menu/menu-item.d.mts.map +1 -1
- package/dist/menu/menu-item.mjs +9 -10
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +1 -1
- package/dist/menu/menu-outside.mjs.map +1 -1
- package/dist/menu/menu-popup.d.mts +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +10 -6
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs +2 -2
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.mjs +2 -2
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +3 -3
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +1 -1
- package/dist/menu/menu-trigger.mjs +3 -3
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/number-field/number-field-input.mjs +1 -1
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +43 -107
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/popover/popover-close.mjs +3 -3
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-context.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +1 -1
- package/dist/popover/popover-popup.mjs +3 -3
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +2 -2
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +1 -1
- package/dist/popover/popover-trigger.mjs +1 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +3 -3
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +5 -5
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-group-label.d.mts.map +1 -1
- package/dist/select/select-group-label.mjs +3 -1
- package/dist/select/select-group-label.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-option.mjs.map +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +7 -7
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/select/select-trigger.d.mts.map +1 -1
- package/dist/select/select-trigger.mjs +3 -1
- package/dist/select/select-trigger.mjs.map +1 -1
- package/dist/select/select-value.mjs +3 -6
- package/dist/select/select-value.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +38 -104
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/use-thumb-registry.mjs.map +1 -1
- package/dist/switch/switch.mjs +1 -1
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-panel.mjs +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +4 -4
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/{internal → tabs}/use-until-found.mjs +1 -1
- package/dist/tabs/use-until-found.mjs.map +1 -0
- package/dist/toast/toast-action.d.mts +13 -3
- package/dist/toast/toast-action.d.mts.map +1 -1
- package/dist/toast/toast-action.mjs +23 -13
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts +13 -2
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +16 -6
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-root.mjs +1 -1
- package/dist/toast/toast-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +48 -143
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +1 -1
- package/dist/toast/use-modal-portal-host.mjs.map +1 -1
- package/dist/toast/use-toast-announcements.mjs +46 -0
- package/dist/toast/use-toast-announcements.mjs.map +1 -0
- package/dist/toast/use-toast-focus.mjs +75 -0
- package/dist/toast/use-toast-focus.mjs.map +1 -0
- package/dist/toast/use-toast-pauses.mjs +58 -0
- package/dist/toast/use-toast-pauses.mjs.map +1 -0
- package/dist/toggle/toggle.mjs +2 -2
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +5 -5
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-context.d.mts +1 -1
- package/dist/tooltip/tooltip-context.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +1 -1
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.d.mts.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +9 -4
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +1 -1
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/{internal → tooltip}/tooltip-warm.mjs +1 -1
- package/dist/tooltip/tooltip-warm.mjs.map +1 -0
- package/dist/tooltip/use-tooltip-interaction.mjs +2 -2
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/funstack-ui-knowledge/SKILL.md +1 -1
- package/dist/internal/action-details.mjs.map +0 -1
- package/dist/internal/anchor-position.d.mts.map +0 -1
- package/dist/internal/anchor-position.mjs.map +0 -1
- package/dist/internal/call-urgent-handler.mjs.map +0 -1
- package/dist/internal/content-focus-probe.mjs.map +0 -1
- package/dist/internal/css-transition-cut.mjs.map +0 -1
- package/dist/internal/field-context.d.mts.map +0 -1
- package/dist/internal/field-context.mjs.map +0 -1
- package/dist/internal/focus-first-invalid.mjs.map +0 -1
- package/dist/internal/focus-visible.mjs.map +0 -1
- package/dist/internal/form-status-watcher.mjs.map +0 -1
- package/dist/internal/group-member.mjs.map +0 -1
- package/dist/internal/invokers.mjs.map +0 -1
- package/dist/internal/modal-registry.mjs.map +0 -1
- package/dist/internal/overlay-popup.mjs.map +0 -1
- package/dist/internal/popover-open.mjs.map +0 -1
- package/dist/internal/report-dropped.mjs.map +0 -1
- package/dist/internal/sync-presence.mjs.map +0 -1
- package/dist/internal/tooltip-warm.mjs.map +0 -1
- package/dist/internal/trigger-ref.mjs.map +0 -1
- package/dist/internal/use-action-trigger.mjs.map +0 -1
- package/dist/internal/use-checkable-input.mjs.map +0 -1
- package/dist/internal/use-controllable-action.mjs.map +0 -1
- package/dist/internal/use-exit-animation.mjs.map +0 -1
- package/dist/internal/use-field-control.mjs.map +0 -1
- package/dist/internal/use-fieldset-group.mjs.map +0 -1
- package/dist/internal/use-form-owner-event.mjs.map +0 -1
- package/dist/internal/use-form-reset.mjs.map +0 -1
- package/dist/internal/use-interest-dismiss.mjs.map +0 -1
- package/dist/internal/use-modal-registration.mjs.map +0 -1
- package/dist/internal/use-native-checked.mjs.map +0 -1
- package/dist/internal/use-native-group-reconciliation.mjs.map +0 -1
- package/dist/internal/use-native-select-value.mjs.map +0 -1
- package/dist/internal/use-overlay-close.mjs.map +0 -1
- package/dist/internal/use-overlay-root.d.mts +0 -2
- package/dist/internal/use-overlay-root.mjs.map +0 -1
- package/dist/internal/use-popover-popup.mjs.map +0 -1
- package/dist/internal/use-popover-trigger.d.mts.map +0 -1
- package/dist/internal/use-popover-trigger.mjs.map +0 -1
- package/dist/internal/use-resolved-placement.mjs.map +0 -1
- package/dist/internal/use-until-found.mjs.map +0 -1
- package/dist/internal/validity.d.mts.map +0 -1
- package/dist/internal/validity.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs-root.mjs","names":[],"sources":["../../src/tabs/tabs-root.tsx"],"sourcesContent":["\"use client\";\nimport { useId, useMemo, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { TabsContext } from \"./tabs-context.js\";\nimport type { TabsActivationMode, TabsContextValue, TabsOrientation } from \"./tabs-context.js\";\nimport { tabId } from \"./tabs-ids.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport type { TabsActivationMode, TabsOrientation } from \"./tabs-context.js\";\n\n/** Details passed as the second argument of `valueChangeAction`. */\nexport interface TabsValueChangeDetails extends ActionDetails {\n /**\n * The shared vocabulary (conventions 2.2); Tabs dispatches two of its values.\n * `\"activate\"`: the user selected the tab (click, Enter/Space, or focus in automatic mode).\n * `\"platform\"`: the browser revealed a `keepMounted=\"until-found\"` panel through find-in-page or a\n * text fragment (`details.event` is the `beforematch` event).\n */\n readonly reason: ChangeReason;\n}\n\n/**\n * State of `Tabs.Root`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface TabsRootState {\n /** Optimistic selected value, or `null`. Content rendered from it must not suspend. */\n readonly value: string | null;\n /** An action dispatched through this Tabs is in flight. */\n readonly pending: boolean;\n /** The `orientation` prop. */\n readonly orientation: TabsOrientation;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Tabs.Root`.\n *\n * @see https://ui.funstack.work/components/tabs\n */\nexport interface TabsRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"className\" | \"style\" | \"children\" | \"defaultValue\"\n> {\n /** Controlled selected value. `null` selects nothing; `undefined` means uncontrolled. */\n value?: string | null;\n /**\n * Initial value in uncontrolled mode.\n *\n * @defaultValue `null` (no panel shown)\n */\n defaultValue?: string | null;\n /**\n * Runs inside the Root's transition whenever the user selects a tab. May be sync or async;\n * rejections reach the nearest Error Boundary and roll the selection back.\n *\n * With `activationMode=\"automatic\"` every arrow key press calls it; prefer `\"manual\"` when the\n * action awaits a server round trip. A `setState` placed after your own `await` is not a\n * Transition update; wrap it in `startTransition` (React limitation).\n */\n valueChangeAction?: ChangeAction<string, TabsValueChangeDetails>;\n /**\n * Layout and arrow-key axis.\n *\n * @defaultValue `\"horizontal\"`\n */\n orientation?: TabsOrientation;\n /**\n * `\"automatic\"`: selection follows focus. `\"manual\"`: Enter, Space or click selects.\n *\n * @defaultValue `\"automatic\"`\n */\n activationMode?: TabsActivationMode;\n /**\n * Whether arrow keys wrap from the last tab to the first.\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /**\n * Disables every Tab (focusable, never dispatches).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, TabsRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, TabsRootState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, TabsRootState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, TabsRootState>;\n}\n\n/** Looks up an element by id in the tree that contains `node` (document or shadow root). */\nfunction findById(node: Node | null, id: string): Element | null {\n const root = node?.getRootNode() ?? (typeof document === \"undefined\" ? null : document);\n if (root !== null && \"getElementById\" in root) {\n return (root as Document | ShadowRoot).getElementById(id);\n }\n return null;\n}\n\n/**\n * Owns the Tabs state (`value`), the transition, the ids and the context. Renders a `div` with\n * `data-pending` while a selection is in flight (including a suspending panel's wait).\n *\n * Owned keys (conventions 1.2): `data-pending`, `data-orientation`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/tabs\n */\nexport function TabsRoot({\n value,\n defaultValue,\n valueChangeAction,\n orientation = \"horizontal\",\n activationMode = \"automatic\",\n loop = true,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TabsRootProps) {\n const rootId = useId();\n const rootRef = useRef<HTMLElement | null>(null);\n\n const { committed, optimistic, pending, dispatch } = useControllableAction<\n string | null,\n TabsValueChangeDetails\n >({\n controlled: value,\n defaultValue,\n initialValue: null,\n // Only ever dispatched with a string: the Tabs UI cannot deselect.\n action:\n valueChangeAction === undefined\n ? undefined\n : (next, details) => valueChangeAction(next as string, details),\n transitionTypes: (next, prev) => {\n // Direction is relative to the committed tab (design 10.2), by DOM order of the two tabs.\n if (next === null || prev === null || next === prev) return transitionTypes(\"tabs\");\n const prevTab = findById(rootRef.current, tabId(rootId, prev));\n const nextTab = findById(rootRef.current, tabId(rootId, next));\n if (prevTab === null || nextTab === null) return transitionTypes(\"tabs\");\n
|
|
1
|
+
{"version":3,"file":"tabs-root.mjs","names":[],"sources":["../../src/tabs/tabs-root.tsx"],"sourcesContent":["\"use client\";\nimport { useId, useMemo, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { compareDocumentOrder } from \"../internal/dom-order.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/action/use-controllable-action.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { TabsContext } from \"./tabs-context.js\";\nimport type { TabsActivationMode, TabsContextValue, TabsOrientation } from \"./tabs-context.js\";\nimport { tabId } from \"./tabs-ids.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport type { TabsActivationMode, TabsOrientation } from \"./tabs-context.js\";\n\n/** Details passed as the second argument of `valueChangeAction`. */\nexport interface TabsValueChangeDetails extends ActionDetails {\n /**\n * The shared vocabulary (conventions 2.2); Tabs dispatches two of its values.\n * `\"activate\"`: the user selected the tab (click, Enter/Space, or focus in automatic mode).\n * `\"platform\"`: the browser revealed a `keepMounted=\"until-found\"` panel through find-in-page or a\n * text fragment (`details.event` is the `beforematch` event).\n */\n readonly reason: ChangeReason;\n}\n\n/**\n * State of `Tabs.Root`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface TabsRootState {\n /** Optimistic selected value, or `null`. Content rendered from it must not suspend. */\n readonly value: string | null;\n /** An action dispatched through this Tabs is in flight. */\n readonly pending: boolean;\n /** The `orientation` prop. */\n readonly orientation: TabsOrientation;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Tabs.Root`.\n *\n * @see https://ui.funstack.work/components/tabs\n */\nexport interface TabsRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"className\" | \"style\" | \"children\" | \"defaultValue\"\n> {\n /** Controlled selected value. `null` selects nothing; `undefined` means uncontrolled. */\n value?: string | null;\n /**\n * Initial value in uncontrolled mode.\n *\n * @defaultValue `null` (no panel shown)\n */\n defaultValue?: string | null;\n /**\n * Runs inside the Root's transition whenever the user selects a tab. May be sync or async;\n * rejections reach the nearest Error Boundary and roll the selection back.\n *\n * With `activationMode=\"automatic\"` every arrow key press calls it; prefer `\"manual\"` when the\n * action awaits a server round trip. A `setState` placed after your own `await` is not a\n * Transition update; wrap it in `startTransition` (React limitation).\n */\n valueChangeAction?: ChangeAction<string, TabsValueChangeDetails>;\n /**\n * Layout and arrow-key axis.\n *\n * @defaultValue `\"horizontal\"`\n */\n orientation?: TabsOrientation;\n /**\n * `\"automatic\"`: selection follows focus. `\"manual\"`: Enter, Space or click selects.\n *\n * @defaultValue `\"automatic\"`\n */\n activationMode?: TabsActivationMode;\n /**\n * Whether arrow keys wrap from the last tab to the first.\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /**\n * Disables every Tab (focusable, never dispatches).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, TabsRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, TabsRootState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, TabsRootState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, TabsRootState>;\n}\n\n/** Looks up an element by id in the tree that contains `node` (document or shadow root). */\nfunction findById(node: Node | null, id: string): Element | null {\n const root = node?.getRootNode() ?? (typeof document === \"undefined\" ? null : document);\n if (root !== null && \"getElementById\" in root) {\n return (root as Document | ShadowRoot).getElementById(id);\n }\n return null;\n}\n\n/**\n * Owns the Tabs state (`value`), the transition, the ids and the context. Renders a `div` with\n * `data-pending` while a selection is in flight (including a suspending panel's wait).\n *\n * Owned keys (conventions 1.2): `data-pending`, `data-orientation`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/tabs\n */\nexport function TabsRoot({\n value,\n defaultValue,\n valueChangeAction,\n orientation = \"horizontal\",\n activationMode = \"automatic\",\n loop = true,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TabsRootProps) {\n const rootId = useId();\n const rootRef = useRef<HTMLElement | null>(null);\n\n const { committed, optimistic, pending, dispatch } = useControllableAction<\n string | null,\n TabsValueChangeDetails\n >({\n controlled: value,\n defaultValue,\n initialValue: null,\n // Only ever dispatched with a string: the Tabs UI cannot deselect.\n action:\n valueChangeAction === undefined\n ? undefined\n : (next, details) => valueChangeAction(next as string, details),\n transitionTypes: (next, prev) => {\n // Direction is relative to the committed tab (design 10.2), by DOM order of the two tabs.\n if (next === null || prev === null || next === prev) return transitionTypes(\"tabs\");\n const prevTab = findById(rootRef.current, tabId(rootId, prev));\n const nextTab = findById(rootRef.current, tabId(rootId, next));\n if (prevTab === null || nextTab === null) return transitionTypes(\"tabs\");\n return transitionTypes(\"tabs\", compareDocumentOrder(prevTab, nextTab) < 0 ? \"next\" : \"prev\");\n },\n warn: { component: \"Tabs.Root\", prop: \"value\" },\n });\n // `null` is a legitimate default (no panel), but forgetting both props is the likelier cause\n // of an empty Tabs (design/components/tabs.md, resolved question 2).\n useDevWarning(\n value === undefined && defaultValue === undefined,\n isDev &&\n \"Tabs.Root: neither `value` nor `defaultValue` was passed, so no tab is selected and no \" +\n \"panel is shown. Pass `defaultValue`, or `defaultValue={null}` to start with no selection.\",\n );\n\n // Memoised: `dispatch` is stable, so this changes only with the state and the props below.\n const context = useMemo<TabsContextValue>(\n () => ({\n rootId,\n committed,\n optimistic,\n pending,\n orientation,\n activationMode,\n loop,\n disabled,\n select: (next, event, reason) => {\n // No-op rule against the optimistic value (conventions 2.3 item 7, design section 9.4).\n if (next === optimistic) return;\n dispatch(next, createActionDetails(event, { reason }));\n },\n }),\n [rootId, committed, optimistic, pending, orientation, activationMode, loop, disabled, dispatch],\n );\n\n const state: TabsRootState = { value: optimistic, pending, orientation, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, TabsRootState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n \"data-pending\": dataAttr(pending),\n \"data-orientation\": orientation,\n \"data-disabled\": dataAttr(disabled),\n },\n ref: rootRef,\n });\n\n return <TabsContext value={context}>{element}</TabsContext>;\n}\n\nTabsRoot.displayName = \"TabsRoot\";\n"],"mappings":";;;;;;;;;;;;;AAqBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AA2FvC,SAAS,SAAS,MAAmB,IAA4B;CAC/D,MAAM,OAAO,MAAM,YAAY,MAAM,OAAO,aAAa,cAAc,OAAO;CAC9E,IAAI,SAAS,QAAQ,oBAAoB,MACvC,OAAQ,KAA+B,eAAe,EAAE;CAE1D,OAAO;AACT;;;;;;;;;AAUA,SAAgB,SAAS,EACvB,OACA,cACA,mBACA,cAAc,cACd,iBAAiB,aACjB,OAAO,MACP,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACa;CAChB,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,OAA2B,IAAI;CAE/C,MAAM,EAAE,WAAW,YAAY,SAAS,aAAa,sBAGnD;EACA,YAAY;EACZ;EACA,cAAc;EAEd,QACE,sBAAsB,KAAA,IAClB,KAAA,KACC,MAAM,YAAY,kBAAkB,MAAgB,OAAO;EAClE,kBAAkB,MAAM,SAAS;GAE/B,IAAI,SAAS,QAAQ,SAAS,QAAQ,SAAS,MAAM,OAAO,gBAAgB,MAAM;GAClF,MAAM,UAAU,SAAS,QAAQ,SAAS,MAAM,QAAQ,IAAI,CAAC;GAC7D,MAAM,UAAU,SAAS,QAAQ,SAAS,MAAM,QAAQ,IAAI,CAAC;GAC7D,IAAI,YAAY,QAAQ,YAAY,MAAM,OAAO,gBAAgB,MAAM;GACvE,OAAO,gBAAgB,QAAQ,qBAAqB,SAAS,OAAO,IAAI,IAAI,SAAS,MAAM;EAC7F;EACA,MAAM;GAAE,WAAW;GAAa,MAAM;EAAQ;CAChD,CAAC;CAGD,cACE,UAAU,KAAA,KAAa,iBAAiB,KAAA,GACxC,SACE,kLAEJ;CAGA,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS,MAAM,OAAO,WAAW;GAE/B,IAAI,SAAS,YAAY;GACzB,SAAS,MAAM,oBAAoB,OAAO,EAAE,OAAO,CAAC,CAAC;EACvD;CACF,IACA;EAAC;EAAQ;EAAW;EAAY;EAAS;EAAa;EAAgB;EAAM;EAAU;CAAQ,CAChG;CAIA,MAAM,UAAU,UAAuD;EACrE,gBAAgB;EAChB;EACA,OAAA;GAL6B,OAAO;GAAY;GAAS;GAAa;EAKlE;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,gBAAgB,SAAS,OAAO;GAChC,oBAAoB;GACpB,iBAAiB,SAAS,QAAQ;EACpC;EACA,KAAK;CACP,CAAC;CAED,OAAO,oBAAC,aAAD;EAAa,OAAO;EAAU,UAAA;CAAqB,CAAA;AAC5D;AAEA,SAAS,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-until-found.mjs","names":[],"sources":["../../src/tabs/use-until-found.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\n\nexport interface UseUntilFoundOptions {\n /**\n * The element should currently be `hidden=\"until-found\"`. The part renders a boolean `hidden`\n * itself as well, so server-rendered HTML hides it (as `hidden=\"\"`) before hydration.\n *\n * Pass `false` while a change the element itself triggered (its `beforematch`) is pending:\n * the browser has already revealed it, and re-asserting would hide it again until the commit.\n * When that change is rejected the owner's optimistic state reverts, `active` becomes `true`\n * again and the next commit re-hides it.\n */\n active: boolean;\n /** Called with the `beforematch` event when find-in-page or a text fragment reveals it. */\n onMatch: (event: Event) => void;\n}\n\n/**\n * The single home of the `hidden=\"until-found\"` workaround (conventions 7.4).\n *\n * react-dom 19.3 serialises `hidden` as a boolean attribute (`hidden=\"\"` on client and server),\n * so the part renders a boolean `hidden` and this hook upgrades the attribute to `\"until-found\"`\n * through a ref in a layout effect. The upgrade is re-asserted after **every** commit while\n * `active`: when the browser reveals the element it removes the attribute itself, and if the\n * resulting action is rejected React sees no prop change (the boolean `hidden` stayed `true`\n * throughout) and would leave the element visible.\n *\n * `beforematch` has no React prop, so a native listener is attached in an effect through the\n * returned ref (conventions 2.6, 7.4). Attach the ref to the element that renders the boolean\n * `hidden`.\n */\nexport function useUntilFound<E extends HTMLElement>(\n options: UseUntilFoundOptions,\n): RefObject<E | null> {\n const { active } = options;\n const node = useRef<E | null>(null);\n const onMatch = useEffectEvent((event: Event) => {\n options.onMatch(event);\n });\n\n // No dependency array on purpose: re-assert after every commit of the owner (see above).\n useLayoutEffect(() => {\n const element = node.current;\n if (element !== null && active && element.getAttribute(\"hidden\") !== \"until-found\") {\n element.setAttribute(\"hidden\", \"until-found\");\n }\n });\n\n // Re-subscribed after every commit so a swapped element (a changed `render`) is covered.\n useEffect(() => {\n const element = node.current;\n if (element === null) return;\n const listener = (event: Event) => onMatch(event);\n element.addEventListener(\"beforematch\", listener);\n return () => element.removeEventListener(\"beforematch\", listener);\n });\n\n return node;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiCA,SAAgB,cACd,SACqB;CACrB,MAAM,EAAE,WAAW;CACnB,MAAM,OAAO,OAAiB,IAAI;CAClC,MAAM,UAAU,gBAAgB,UAAiB;EAC/C,QAAQ,QAAQ,KAAK;CACvB,CAAC;CAGD,sBAAsB;EACpB,MAAM,UAAU,KAAK;EACrB,IAAI,YAAY,QAAQ,UAAU,QAAQ,aAAa,QAAQ,MAAM,eACnE,QAAQ,aAAa,UAAU,aAAa;CAEhD,CAAC;CAGD,gBAAgB;EACd,MAAM,UAAU,KAAK;EACrB,IAAI,YAAY,MAAM;EACtB,MAAM,YAAY,UAAiB,QAAQ,KAAK;EAChD,QAAQ,iBAAiB,eAAe,QAAQ;EAChD,aAAa,QAAQ,oBAAoB,eAAe,QAAQ;CAClE,CAAC;CAED,OAAO;AACT"}
|
|
@@ -9,6 +9,8 @@ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
|
9
9
|
export interface ToastActionState {
|
|
10
10
|
/** This part's action is in flight. */
|
|
11
11
|
readonly pending: boolean;
|
|
12
|
+
/** The `disabled` prop. Not set by pending. */
|
|
13
|
+
readonly disabled: boolean;
|
|
12
14
|
/** The toast this Action belongs to. */
|
|
13
15
|
readonly toast: ToastItem;
|
|
14
16
|
}
|
|
@@ -44,6 +46,14 @@ export interface ToastActionProps extends Omit<ComponentPropsWithRef<"button">,
|
|
|
44
46
|
* @defaultValue `"ignore"`, or `"run"` with `closeOnSettle={false}`
|
|
45
47
|
*/
|
|
46
48
|
whilePending?: WhilePending;
|
|
49
|
+
/**
|
|
50
|
+
* Never runs the action. Native `disabled` on a `<button>` (owned; a `render` element cannot
|
|
51
|
+
* re-enable it) and `data-disabled`. With a link or component `render`, `aria-disabled="true"`
|
|
52
|
+
* instead and the click is cancelled (a disabled link does not navigate).
|
|
53
|
+
*
|
|
54
|
+
* @defaultValue `false`
|
|
55
|
+
*/
|
|
56
|
+
disabled?: boolean;
|
|
47
57
|
/**
|
|
48
58
|
* The button's content, or a function of the part's state.
|
|
49
59
|
*
|
|
@@ -63,12 +73,12 @@ export interface ToastActionProps extends Omit<ComponentPropsWithRef<"button">,
|
|
|
63
73
|
* disabled while pending: a second click meanwhile is ignored and the Action is `aria-disabled`,
|
|
64
74
|
* unless `whilePending` is `"run"` (the default with `closeOnSettle={false}`).
|
|
65
75
|
*
|
|
66
|
-
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `
|
|
67
|
-
* `data-pending`.
|
|
76
|
+
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `onClick`,
|
|
77
|
+
* `aria-disabled`, `data-pending`, `data-disabled`.
|
|
68
78
|
*
|
|
69
79
|
* @see https://ui.funstack.work/components/toast
|
|
70
80
|
*/
|
|
71
|
-
export declare function ToastAction({ action, closeOnSettle, whilePending, children, className, style, render, ...rest }: ToastActionProps): ReactNode;
|
|
81
|
+
export declare function ToastAction({ action, closeOnSettle, whilePending, disabled, children, className, style, render, ...rest }: ToastActionProps): ReactNode;
|
|
72
82
|
export declare namespace ToastAction {
|
|
73
83
|
var displayName: string;
|
|
74
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-action.d.mts","names":[],"sources":["../../src/toast/toast-action.tsx"],"mappings":";;;;;;;;iBAgBiB;;WAEN;;WAEA,OAAO;;;;;;;iBAQD,yBAAyB,KACxC;;;;;;;;;;EAYA,SAAS,QAAQ,SAAS;;;;;;EAM1B;;;;;;;;;;EAUA,eAAe;;;;;;
|
|
1
|
+
{"version":3,"file":"toast-action.d.mts","names":[],"sources":["../../src/toast/toast-action.tsx"],"mappings":";;;;;;;;iBAgBiB;;WAEN;;WAEA;;WAEA,OAAO;;;;;;;iBAQD,yBAAyB,KACxC;;;;;;;;;;EAYA,SAAS,QAAQ,SAAS;;;;;;EAM1B;;;;;;;;;;EAUA,eAAe;;;;;;;;EAQf;;;;;;EAMA,WAAW,WAAW,WAAW;;EAEjC,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;wBAcvC,cACd,QACA,eACA,cACA,UACA,UACA,WACA,OACA,WACG,QACF,mBAAgB;yBAVH"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createActionDetails } from "../internal/action-details.mjs";
|
|
2
|
+
import { createActionDetails } from "../internal/action/action-details.mjs";
|
|
3
3
|
import { dataAttr } from "../internal/data-attr.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { disabledButton, rendersButton } from "../internal/render-element.mjs";
|
|
5
|
+
import { usePureTrigger } from "../internal/action/use-pure-trigger.mjs";
|
|
6
6
|
import { useRender } from "../internal/use-render.mjs";
|
|
7
7
|
import { useToastRootContext } from "./toast-context.mjs";
|
|
8
8
|
import { useLayoutEffect, useState } from "react";
|
|
@@ -13,15 +13,18 @@ import { useLayoutEffect, useState } from "react";
|
|
|
13
13
|
* disabled while pending: a second click meanwhile is ignored and the Action is `aria-disabled`,
|
|
14
14
|
* unless `whilePending` is `"run"` (the default with `closeOnSettle={false}`).
|
|
15
15
|
*
|
|
16
|
-
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `
|
|
17
|
-
* `data-pending`.
|
|
16
|
+
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `onClick`,
|
|
17
|
+
* `aria-disabled`, `data-pending`, `data-disabled`.
|
|
18
18
|
*
|
|
19
19
|
* @see https://ui.funstack.work/components/toast
|
|
20
20
|
*/
|
|
21
|
-
function ToastAction({ action, closeOnSettle = true, whilePending, children, className, style, render, ...rest }) {
|
|
21
|
+
function ToastAction({ action, closeOnSettle = true, whilePending, disabled = false, children, className, style, render, ...rest }) {
|
|
22
22
|
const root = useToastRootContext("Toast.Action");
|
|
23
|
-
const
|
|
24
|
-
|
|
23
|
+
const trigger = usePureTrigger({
|
|
24
|
+
whilePending,
|
|
25
|
+
defaultWhilePending: closeOnSettle ? "ignore" : "run"
|
|
26
|
+
});
|
|
27
|
+
const { pending } = trigger;
|
|
25
28
|
const [token] = useState(() => ({}));
|
|
26
29
|
const effective = action ?? root.toast.action?.action;
|
|
27
30
|
const { setActionPending } = root;
|
|
@@ -34,23 +37,30 @@ function ToastAction({ action, closeOnSettle = true, whilePending, children, cla
|
|
|
34
37
|
setActionPending,
|
|
35
38
|
token
|
|
36
39
|
]);
|
|
40
|
+
const disabledProps = disabledButton(render, disabled).props;
|
|
37
41
|
const state = {
|
|
38
42
|
pending,
|
|
43
|
+
disabled,
|
|
39
44
|
toast: root.toast
|
|
40
45
|
};
|
|
41
46
|
const onClick = (event) => {
|
|
42
|
-
if (
|
|
47
|
+
if (disabled) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (effective === void 0) return;
|
|
43
52
|
const native = event.nativeEvent;
|
|
44
53
|
const details = createActionDetails(native, { id: root.toast.id });
|
|
45
|
-
|
|
54
|
+
trigger.runActivation(event, () => effective(details), () => {
|
|
46
55
|
if (closeOnSettle) root.close("activate", native);
|
|
47
|
-
})
|
|
56
|
+
});
|
|
48
57
|
};
|
|
49
58
|
const libraryProps = {
|
|
50
59
|
...rendersButton(render) && { type: "button" },
|
|
60
|
+
disabled: disabledProps.disabled,
|
|
51
61
|
onClick,
|
|
52
|
-
|
|
53
|
-
"data-
|
|
62
|
+
...trigger.pendingProps(disabledProps),
|
|
63
|
+
"data-disabled": dataAttr(disabled)
|
|
54
64
|
};
|
|
55
65
|
const element = useRender({
|
|
56
66
|
defaultElement: "button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-action.mjs","names":[],"sources":["../../src/toast/toast-action.tsx"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { Action, RenderProp, StateValue, WhilePending } from \"../internal/types.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"toast-action.mjs","names":[],"sources":["../../src/toast/toast-action.tsx"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { Action, RenderProp, StateValue, WhilePending } from \"../internal/types.js\";\nimport { usePureTrigger } from \"../internal/action/use-pure-trigger.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport type { ToastActionDetails, ToastItem } from \"./toast.js\";\nimport { useToastRootContext } from \"./toast-context.js\";\n\n/**\n * State of `Toast.Action`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ToastActionState {\n /** This part's action is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. Not set by pending. */\n readonly disabled: boolean;\n /** The toast this Action belongs to. */\n readonly toast: ToastItem;\n}\n\n/**\n * Props of `Toast.Action`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport interface ToastActionProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs in this part's own transition: `data-pending` on the Action and the Root, the toast's\n * timer paused. When it resolves the toast closes with `reason: \"activate\"` (unless\n * `closeOnSettle` is `false`); a rejection keeps the toast and reaches the nearest Error\n * Boundary above the Viewport. A caught error counts as success and closes the toast: rethrow\n * after `toast.update`, or use `closeOnSettle={false}`.\n *\n * @defaultValue the toast's `action.action`\n */\n action?: Action<[details: ToastActionDetails]>;\n /**\n * Close the toast when the action resolves.\n *\n * @defaultValue `true`\n */\n closeOnSettle?: boolean;\n /**\n * What a click does while this part's action is pending. `\"ignore\"`: nothing (the click is\n * cancelled, `aria-disabled=\"true\"` meanwhile): one Undo, one Retry. `\"run\"`: the action runs\n * again; the Action and the Root stay `data-pending` and the timer paused until every run has\n * settled. With `closeOnSettle` the toast then closes once, if the latest run resolved; a\n * rejected latest run keeps it, as in `\"ignore\"` mode.\n *\n * @defaultValue `\"ignore\"`, or `\"run\"` with `closeOnSettle={false}`\n */\n whilePending?: WhilePending;\n /**\n * Never runs the action. Native `disabled` on a `<button>` (owned; a `render` element cannot\n * re-enable it) and `data-disabled`. With a link or component `render`, `aria-disabled=\"true\"`\n * instead and the click is cancelled (a disabled link does not navigate).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * The button's content, or a function of the part's state.\n *\n * @defaultValue the toast's `action.label`\n */\n children?: StateValue<ReactNode, ToastActionState>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToastActionState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToastActionState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ToastActionState>;\n}\n\n/**\n * The toast's action button (Undo, Retry, View): a `button type=\"button\"` whose `action` runs as\n * a transition. Renders nothing when neither the part nor the toast has an action. Never natively\n * disabled while pending: a second click meanwhile is ignored and the Action is `aria-disabled`,\n * unless `whilePending` is `\"run\"` (the default with `closeOnSettle={false}`).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `onClick`,\n * `aria-disabled`, `data-pending`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport function ToastAction({\n action,\n closeOnSettle = true,\n whilePending,\n disabled = false,\n children,\n className,\n style,\n render,\n ...rest\n}: ToastActionProps) {\n const root = useToastRootContext(\"Toast.Action\");\n // Mixed ownership (conventions 2.5.1): ignore while the library closes the toast after the\n // action; a toast that stays makes the Action a user-owned trigger.\n const trigger = usePureTrigger({\n whilePending,\n defaultWhilePending: closeOnSettle ? \"ignore\" : \"run\",\n });\n const { pending } = trigger;\n const [token] = useState(() => ({}));\n const effective = action ?? root.toast.action?.action;\n const { setActionPending } = root;\n\n // The Root (and through it the Viewport's timer) sees this part's pending state.\n useLayoutEffect(() => {\n if (!pending) return;\n setActionPending(token, true);\n return () => setActionPending(token, false);\n }, [pending, setActionPending, token]);\n\n const disabledProps = disabledButton(render, disabled).props;\n const state: ToastActionState = { pending, disabled, toast: root.toast };\n\n const onClick = (event: MouseEvent<HTMLElement>): void => {\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n if (effective === undefined) return;\n const native = event.nativeEvent;\n const details = createActionDetails(native, { id: root.toast.id });\n // When ignoring, a second click while this Action's own run is in flight starts nothing and\n // is cancelled (the hook's guard): one Undo, one Retry.\n trigger.runActivation(\n event,\n () => effective(details),\n () => {\n // Closing is idempotent: a dismissal meanwhile already closed it.\n if (closeOnSettle) root.close(\"activate\", native);\n },\n );\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...(rendersButton(render) && { type: \"button\" as const }),\n disabled: disabledProps.disabled,\n onClick,\n // While `data-pending` exactly when ignoring (conventions 3.6), and when disabled on a link\n // or component `render`; native `disabled` wins. Owned, so an idle Action removes a render\n // element's own.\n ...trigger.pendingProps(disabledProps),\n \"data-disabled\": dataAttr(disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"button\">, ToastActionState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children: children ?? root.toast.action?.label,\n props: rest,\n libraryProps,\n });\n return effective === undefined ? null : element;\n}\n\nToastAction.displayName = \"ToastAction\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6FA,SAAgB,YAAY,EAC1B,QACA,gBAAgB,MAChB,cACA,WAAW,OACX,UACA,WACA,OACA,QACA,GAAG,QACgB;CACnB,MAAM,OAAO,oBAAoB,cAAc;CAG/C,MAAM,UAAU,eAAe;EAC7B;EACA,qBAAqB,gBAAgB,WAAW;CAClD,CAAC;CACD,MAAM,EAAE,YAAY;CACpB,MAAM,CAAC,SAAS,gBAAgB,CAAC,EAAE;CACnC,MAAM,YAAY,UAAU,KAAK,MAAM,QAAQ;CAC/C,MAAM,EAAE,qBAAqB;CAG7B,sBAAsB;EACpB,IAAI,CAAC,SAAS;EACd,iBAAiB,OAAO,IAAI;EAC5B,aAAa,iBAAiB,OAAO,KAAK;CAC5C,GAAG;EAAC;EAAS;EAAkB;CAAK,CAAC;CAErC,MAAM,gBAAgB,eAAe,QAAQ,QAAQ,CAAC,CAAC;CACvD,MAAM,QAA0B;EAAE;EAAS;EAAU,OAAO,KAAK;CAAM;CAEvE,MAAM,WAAW,UAAyC;EACxD,IAAI,UAAU;GAEZ,MAAM,eAAe;GACrB;EACF;EACA,IAAI,cAAc,KAAA,GAAW;EAC7B,MAAM,SAAS,MAAM;EACrB,MAAM,UAAU,oBAAoB,QAAQ,EAAE,IAAI,KAAK,MAAM,GAAG,CAAC;EAGjE,QAAQ,cACN,aACM,UAAU,OAAO,SACjB;GAEJ,IAAI,eAAe,KAAK,MAAM,YAAY,MAAM;EAClD,CACF;CACF;CAEA,MAAM,eAAiE;EACrE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EACvD,UAAU,cAAc;EACxB;EAIA,GAAG,QAAQ,aAAa,aAAa;EACrC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,MAAM,UAAU,UAA6D;EAC3E,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,YAAY,KAAK,MAAM,QAAQ;EACzC,OAAO;EACP;CACF,CAAC;CACD,OAAO,cAAc,KAAA,IAAY,OAAO;AAC1C;AAEA,YAAY,cAAc"}
|
|
@@ -7,6 +7,8 @@ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
|
7
7
|
* `render`.
|
|
8
8
|
*/
|
|
9
9
|
export interface ToastCloseState {
|
|
10
|
+
/** The `disabled` prop. */
|
|
11
|
+
readonly disabled: boolean;
|
|
10
12
|
/** The toast this Close belongs to. */
|
|
11
13
|
readonly toast: ToastItem;
|
|
12
14
|
}
|
|
@@ -16,6 +18,14 @@ export interface ToastCloseState {
|
|
|
16
18
|
* @see https://ui.funstack.work/components/toast
|
|
17
19
|
*/
|
|
18
20
|
export interface ToastCloseProps extends Omit<ComponentPropsWithRef<"button">, "onClick" | "className" | "style" | "children"> {
|
|
21
|
+
/**
|
|
22
|
+
* Never closes. Native `disabled` on a `<button>` (owned; a `render` element cannot re-enable
|
|
23
|
+
* it) and `data-disabled`. With a link or component `render`, `aria-disabled="true"` instead
|
|
24
|
+
* and the click is cancelled (a disabled link does not navigate).
|
|
25
|
+
*
|
|
26
|
+
* @defaultValue `false`
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean;
|
|
19
29
|
/** Content, or a function of the part's state. */
|
|
20
30
|
children?: StateValue<ReactNode, ToastCloseState>;
|
|
21
31
|
/** Class name, or a function of the part's state that returns one. */
|
|
@@ -29,11 +39,12 @@ export interface ToastCloseProps extends Omit<ComponentPropsWithRef<"button">, "
|
|
|
29
39
|
* Dismisses the toast (`reason: "dismiss"`, the same as Escape). Label it yourself (`aria-label`
|
|
30
40
|
* or text). No Invoker Command: `hide-popover` would hide the whole region.
|
|
31
41
|
*
|
|
32
|
-
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `
|
|
42
|
+
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `aria-disabled`,
|
|
43
|
+
* `onClick`, `data-disabled`.
|
|
33
44
|
*
|
|
34
45
|
* @see https://ui.funstack.work/components/toast
|
|
35
46
|
*/
|
|
36
|
-
export declare function ToastClose({ children, className, style, render, ...rest }: ToastCloseProps): ReactNode;
|
|
47
|
+
export declare function ToastClose({ disabled, children, className, style, render, ...rest }: ToastCloseProps): ReactNode;
|
|
37
48
|
export declare namespace ToastClose {
|
|
38
49
|
var displayName: string;
|
|
39
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-close.d.mts","names":[],"sources":["../../src/toast/toast-close.tsx"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"toast-close.d.mts","names":[],"sources":["../../src/toast/toast-close.tsx"],"mappings":";;;;;;;;iBAgBiB;;WAEN;;WAEA,OAAO;;;;;;;iBAQD,wBAAwB,KACvC;;;;;;;;EAUA;;EAEA,WAAW,WAAW,WAAW;;EAEjC,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,iCAAiC;;;;;;;;;;;wBAYvC,aACd,UACA,UACA,WACA,OACA,WACG,QACF,kBAAe;yBAPF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
|
+
import { disabledButton, rendersButton } from "../internal/render-element.mjs";
|
|
3
4
|
import { useRender } from "../internal/use-render.mjs";
|
|
4
5
|
import { TEXT_NAME, useNameWarning } from "../internal/use-name-warning.mjs";
|
|
5
6
|
import { useToastRootContext } from "./toast-context.mjs";
|
|
@@ -9,25 +10,34 @@ const isDev = process.env.NODE_ENV !== "production";
|
|
|
9
10
|
* Dismisses the toast (`reason: "dismiss"`, the same as Escape). Label it yourself (`aria-label`
|
|
10
11
|
* or text). No Invoker Command: `hide-popover` would hide the whole region.
|
|
11
12
|
*
|
|
12
|
-
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `
|
|
13
|
+
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `aria-disabled`,
|
|
14
|
+
* `onClick`, `data-disabled`.
|
|
13
15
|
*
|
|
14
16
|
* @see https://ui.funstack.work/components/toast
|
|
15
17
|
*/
|
|
16
|
-
function ToastClose({ children, className, style, render, ...rest }) {
|
|
18
|
+
function ToastClose({ disabled = false, children, className, style, render, ...rest }) {
|
|
17
19
|
const root = useToastRootContext("Toast.Close");
|
|
18
20
|
const devRef = useNameWarning(isDev && "Toast.Close: the button has no accessible name. Give it text or an `aria-label`.", TEXT_NAME);
|
|
19
21
|
const onClick = (event) => {
|
|
20
|
-
if (
|
|
22
|
+
if (disabled) {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
21
26
|
root.close("dismiss", event.nativeEvent);
|
|
22
27
|
};
|
|
23
28
|
const libraryProps = {
|
|
24
29
|
...rendersButton(render) && { type: "button" },
|
|
25
|
-
|
|
30
|
+
...disabledButton(render, disabled).props,
|
|
31
|
+
onClick,
|
|
32
|
+
"data-disabled": dataAttr(disabled)
|
|
26
33
|
};
|
|
27
34
|
return useRender({
|
|
28
35
|
defaultElement: "button",
|
|
29
36
|
render,
|
|
30
|
-
state: {
|
|
37
|
+
state: {
|
|
38
|
+
disabled,
|
|
39
|
+
toast: root.toast
|
|
40
|
+
},
|
|
31
41
|
className,
|
|
32
42
|
style,
|
|
33
43
|
children,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-close.mjs","names":[],"sources":["../../src/toast/toast-close.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { TEXT_NAME, useNameWarning } from \"../internal/use-name-warning.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport type { ToastItem } from \"./toast.js\";\nimport { useToastRootContext } from \"./toast-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Toast.Close`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ToastCloseState {\n /** The toast this Close belongs to. */\n readonly toast: ToastItem;\n}\n\n/**\n * Props of `Toast.Close`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport interface ToastCloseProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ToastCloseState>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToastCloseState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToastCloseState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ToastCloseState>;\n}\n\n/**\n * Dismisses the toast (`reason: \"dismiss\"`, the same as Escape). Label it yourself (`aria-label`\n * or text). No Invoker Command: `hide-popover` would hide the whole region.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `onClick`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport function ToastClose({ children
|
|
1
|
+
{"version":3,"file":"toast-close.mjs","names":[],"sources":["../../src/toast/toast-close.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { TEXT_NAME, useNameWarning } from \"../internal/use-name-warning.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport type { ToastItem } from \"./toast.js\";\nimport { useToastRootContext } from \"./toast-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Toast.Close`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ToastCloseState {\n /** The `disabled` prop. */\n readonly disabled: boolean;\n /** The toast this Close belongs to. */\n readonly toast: ToastItem;\n}\n\n/**\n * Props of `Toast.Close`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport interface ToastCloseProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Never closes. Native `disabled` on a `<button>` (owned; a `render` element cannot re-enable\n * it) and `data-disabled`. With a link or component `render`, `aria-disabled=\"true\"` instead\n * and the click is cancelled (a disabled link does not navigate).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ToastCloseState>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToastCloseState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToastCloseState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ToastCloseState>;\n}\n\n/**\n * Dismisses the toast (`reason: \"dismiss\"`, the same as Escape). Label it yourself (`aria-label`\n * or text). No Invoker Command: `hide-popover` would hide the whole region.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `aria-disabled`,\n * `onClick`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport function ToastClose({\n disabled = false,\n children,\n className,\n style,\n render,\n ...rest\n}: ToastCloseProps) {\n const root = useToastRootContext(\"Toast.Close\");\n\n const devRef = useNameWarning(\n isDev && \"Toast.Close: the button has no accessible name. Give it text or an `aria-label`.\",\n TEXT_NAME,\n );\n\n const onClick = (event: MouseEvent<HTMLElement>): void => {\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n root.close(\"dismiss\", event.nativeEvent);\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned (both keys): a render element must not re-enable a disabled Close.\n ...disabledButton(render, disabled).props,\n onClick,\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, ToastCloseState>({\n defaultElement: \"button\",\n render,\n state: { disabled, toast: root.toast },\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref: devRef,\n });\n}\n\nToastClose.displayName = \"ToastClose\";\n"],"mappings":";;;;;;;AAUA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;AAiDvC,SAAgB,WAAW,EACzB,WAAW,OACX,UACA,WACA,OACA,QACA,GAAG,QACe;CAClB,MAAM,OAAO,oBAAoB,aAAa;CAE9C,MAAM,SAAS,eACb,SAAS,oFACT,SACF;CAEA,MAAM,WAAW,UAAyC;EACxD,IAAI,UAAU;GAEZ,MAAM,eAAe;GACrB;EACF;EACA,KAAK,MAAM,WAAW,MAAM,WAAW;CACzC;CAEA,MAAM,eAAiE;EACrE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EAEvD,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;EACpC;EACA,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA4D;EACjE,gBAAgB;EAChB;EACA,OAAO;GAAE;GAAU,OAAO,KAAK;EAAM;EACrC;EACA;EACA;EACA,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,WAAW,cAAc"}
|
|
@@ -4,7 +4,7 @@ import { resolveStateValue } from "../internal/render-element.mjs";
|
|
|
4
4
|
import { useRender } from "../internal/use-render.mjs";
|
|
5
5
|
import { useLatest } from "../internal/use-latest.mjs";
|
|
6
6
|
import { ownsArrows } from "../internal/use-roving-focus.mjs";
|
|
7
|
-
import { exitAnimations } from "../internal/use-exit-animation.mjs";
|
|
7
|
+
import { exitAnimations } from "../internal/overlay/use-exit-animation.mjs";
|
|
8
8
|
import { ToastRootContext, useToastRootContext, useToastViewportContext } from "./toast-context.mjs";
|
|
9
9
|
import { Suspense, useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
10
10
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-root.mjs","names":[],"sources":["../../src/toast/toast-root.tsx"],"sourcesContent":["\"use client\";\nimport { Suspense, useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, KeyboardEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { exitAnimations } from \"../internal/use-exit-animation.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { ownsArrows } from \"../internal/use-roving-focus.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport type { ToastItem, ToastPriority } from \"./toast.js\";\nimport { ToastRootContext, useToastRootContext, useToastViewportContext } from \"./toast-context.js\";\nimport type { ToastRootContextValue } from \"./toast-context.js\";\n\n/**\n * State of `Toast.Root`, `Toast.Title`, `Toast.Description`, passed to the function forms of\n * `className`, `style`, `children` and `render`.\n */\nexport interface ToastRootState {\n /** The toast this Root renders (the Root's `toast` prop). */\n readonly toast: ToastItem;\n /** `toast.pending`: its promise is unsettled or its Action runs. */\n readonly pending: boolean;\n /** `toast.ending`: closed, kept for its exit animation. */\n readonly ending: boolean;\n /** `toast.type`, rendered as `data-type`. */\n readonly type: string | undefined;\n /** `toast.priority`, resolved (`\"normal\"` when absent). */\n readonly priority: ToastPriority;\n}\n\n/**\n * Props of `Toast.Root`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport interface ToastRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"className\" | \"style\" | \"children\" | \"onKeyDown\"\n> {\n /** The toast to render: an item of the Viewport's `state.toasts`. */\n toast: ToastItem;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ToastRootState>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToastRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToastRootState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ToastRootState>;\n /**\n * Rendered by the Root's own Suspense guard while `children` suspend, in place of the\n * invisible default. The toast's timer and announcement wait for the reveal either way.\n * Parts inside it (a visually hidden `<Toast.Title>` giving the toast a name) gate nothing.\n *\n * @defaultValue `null`\n */\n fallback?: ReactNode;\n}\n\n/**\n * The Suspense guard's fallback: renders the Root's `fallback` (nothing by default) and tells\n * the Root its content is suspended, so the timer and the announcement wait for the reveal\n * (design 3.5, 21).\n */\nfunction SuspenseGuard({ children }: { children: ReactNode }) {\n const { setSuspended } = useToastRootContext(\"Toast.Root\");\n useLayoutEffect(() => {\n setSuspended(true);\n return () => setSuspended(false);\n }, [setSuspended]);\n return children;\n}\n\n/**\n * One toast: a focusable `div[role=dialog]` (`alertdialog` for `priority: \"high\"`) named by its\n * Title and described by its Description. Escape dismisses it, ArrowDown / ArrowUp move to the\n * next / previous toast. Its children render inside a Suspense guard whose fallback is the\n * `fallback` prop (invisible by default), so a toast whose content suspends does not pull the whole Viewport into a boundary above it.\n * When the toast closes it stays with `data-ending` (and `inert`) until its exit animations end.\n *\n * Owned keys (conventions 1.2): `role`, `tabIndex`, `aria-labelledby`, `aria-describedby`,\n * `inert`, `data-type`, `data-pending`, `data-ending`, `onKeyDown`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport function ToastRoot({\n toast: item,\n children,\n className,\n style,\n render,\n fallback = null,\n ...rest\n}: ToastRootProps) {\n const viewport = useToastViewportContext(\"Toast.Root\");\n const id = item.id;\n const baseId = useId();\n const ids = useMemo(\n () => ({ title: `${baseId}title`, description: `${baseId}description` }),\n [baseId],\n );\n const elementRef = useRef<HTMLElement | null>(null);\n const titleRef = useRef<HTMLElement | null>(null);\n const descriptionRef = useRef<HTMLElement | null>(null);\n\n // Action pending, aggregated over the Action parts inside (normally one).\n const pendingTokens = useRef(new Set<object>());\n const [actionPending, setActionPendingState] = useState(false);\n // Suspended content behind the guard: a ref for effects of the same commit, state to re-run\n // the announcement once it reveals.\n const suspendedRef = useRef(false);\n const [suspended, setSuspendedState] = useState(false);\n\n const idRef = useLatest(id);\n // The Root's announcement effect has run once: later Title / Description commits are reveals.\n const announcedOnce = useRef(false);\n const revealQueued = useRef(false);\n\n const setActionPending = useCallback(\n (token: object, pending: boolean) => {\n const tokens = pendingTokens.current;\n if (pending) tokens.add(token);\n else tokens.delete(token);\n const any = tokens.size > 0;\n setActionPendingState(any);\n viewport.setActionPending(idRef.current, any);\n },\n [viewport, idRef],\n );\n\n const setSuspended = useCallback(\n (value: boolean) => {\n suspendedRef.current = value;\n setSuspendedState(value);\n viewport.setSuspended(idRef.current, value);\n },\n [viewport, idRef],\n );\n\n const close = useCallback(\n (reason: Parameters<ToastRootContextValue[\"close\"]>[0], event: Event | undefined) =>\n viewport.close([idRef.current], reason, event),\n [viewport, idRef],\n );\n\n const registerTitle = useCallback((element: HTMLElement | null) => {\n titleRef.current = element;\n }, []);\n const registerDescription = useCallback((element: HTMLElement | null) => {\n descriptionRef.current = element;\n }, []);\n\n const pending = item.pending || actionPending;\n const priority = item.priority ?? \"normal\";\n\n // Announce once the content has committed un-suspended (design 5): the Title and Description\n // text exists now. The Viewport skips text it already announced for this toast and speaks the\n // batch a microtask later.\n const announceNow = (): void => {\n if (item.ending || suspendedRef.current) return;\n const resolver = item.announce ?? viewport.announcer();\n let text: string | null;\n if (resolver !== undefined) text = resolver(item);\n else {\n text = [titleRef.current?.textContent, descriptionRef.current?.textContent]\n .map((t) => (t ?? \"\").trim())\n .filter((t) => t !== \"\")\n .join(\" \");\n }\n viewport.announce(item.id, text, priority);\n };\n const announceRef = useLatest(announceNow);\n\n // A Title or Description inside the consumer's own `<Suspense>` commits after the Root (the\n // boundary's retry does not re-run the Root's effect). Read once the whole reveal committed,\n // so a Title and a Description revealed together are announced as one text.\n const contentCommitted = useCallback(() => {\n if (!announcedOnce.current || revealQueued.current) return;\n revealQueued.current = true;\n queueMicrotask(() => {\n revealQueued.current = false;\n announceRef.current();\n });\n }, [announceRef]);\n const state = useMemo<ToastRootState>(\n () => ({ toast: item, pending, ending: item.ending, type: item.type, priority }),\n [item, pending, priority],\n );\n\n const context = useMemo<ToastRootContextValue>(\n () => ({\n toast: item,\n ids,\n state,\n registerTitle,\n registerDescription,\n contentCommitted,\n setActionPending,\n setSuspended,\n close,\n }),\n [\n item,\n ids,\n state,\n registerTitle,\n registerDescription,\n contentCommitted,\n setActionPending,\n setSuspended,\n close,\n ],\n );\n\n const rootRef = useCallback(\n (element: HTMLElement) => {\n elementRef.current = element;\n viewport.registerRoot(id, element);\n return () => {\n if (elementRef.current === element) elementRef.current = null;\n viewport.registerRoot(id, null);\n };\n },\n [viewport, id],\n );\n\n // A layout effect, so toasts announce in queue order (before the Viewport's own effect\n // announces the queued ones).\n useLayoutEffect(() => {\n announcedOnce.current = true;\n announceRef.current();\n }, [item, suspended, priority, announceRef]);\n\n // Exit (design 10.2): keep the ending toast until the animations the ending state started\n // settle, then drop it. Animations that ran before (a progress bar, paused with the region or\n // not) are not waited for: the Viewport recorded them just before marking the toast ending.\n useLayoutEffect(() => {\n if (!item.ending) return;\n const element = elementRef.current;\n const baseline = viewport.exitBaseline(item.id);\n const animations = element === null ? [] : exitAnimations(element, baseline);\n if (animations.length === 0) {\n viewport.drop(item.id);\n return;\n }\n let cancelled = false;\n void Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {\n if (!cancelled) viewport.drop(item.id);\n });\n return () => {\n cancelled = true;\n };\n }, [item.ending, item.id, viewport]);\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>): void => {\n if (event.defaultPrevented || item.ending) return;\n if (event.key === \"Escape\") {\n event.preventDefault();\n close(\"dismiss\", event.nativeEvent);\n } else if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n // A text field, select or slider inside the toast keeps its arrows (the roving rule,\n // toggle-group.md 6.3).\n if (ownsArrows(event.target as Element)) return;\n event.preventDefault();\n viewport.focusSibling(id, event.key === \"ArrowDown\" ? 1 : -1);\n }\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n role: priority === \"high\" ? \"alertdialog\" : \"dialog\",\n tabIndex: 0,\n \"aria-labelledby\": ids.title,\n \"aria-describedby\": ids.description,\n inert: item.ending || undefined,\n \"data-type\": item.type,\n \"data-pending\": dataAttr(pending),\n \"data-ending\": dataAttr(item.ending),\n onKeyDown,\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, ToastRootState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children: (s: ToastRootState) => (\n <Suspense fallback={<SuspenseGuard>{fallback}</SuspenseGuard>}>\n {resolveStateValue(children, s)}\n </Suspense>\n ),\n props: rest,\n libraryProps,\n ref: rootRef,\n });\n\n return <ToastRootContext value={context}>{element}</ToastRootContext>;\n}\n\nToastRoot.displayName = \"ToastRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;AAiEA,SAAS,cAAc,EAAE,YAAqC;CAC5D,MAAM,EAAE,iBAAiB,oBAAoB,YAAY;CACzD,sBAAsB;EACpB,aAAa,IAAI;EACjB,aAAa,aAAa,KAAK;CACjC,GAAG,CAAC,YAAY,CAAC;CACjB,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,UAAU,EACxB,OAAO,MACP,UACA,WACA,OACA,QACA,WAAW,MACX,GAAG,QACc;CACjB,MAAM,WAAW,wBAAwB,YAAY;CACrD,MAAM,KAAK,KAAK;CAChB,MAAM,SAAS,MAAM;CACrB,MAAM,MAAM,eACH;EAAE,OAAO,GAAG,OAAO;EAAQ,aAAa,GAAG,OAAO;CAAa,IACtE,CAAC,MAAM,CACT;CACA,MAAM,aAAa,OAA2B,IAAI;CAClD,MAAM,WAAW,OAA2B,IAAI;CAChD,MAAM,iBAAiB,OAA2B,IAAI;CAGtD,MAAM,gBAAgB,uBAAO,IAAI,IAAY,CAAC;CAC9C,MAAM,CAAC,eAAe,yBAAyB,SAAS,KAAK;CAG7D,MAAM,eAAe,OAAO,KAAK;CACjC,MAAM,CAAC,WAAW,qBAAqB,SAAS,KAAK;CAErD,MAAM,QAAQ,UAAU,EAAE;CAE1B,MAAM,gBAAgB,OAAO,KAAK;CAClC,MAAM,eAAe,OAAO,KAAK;CAEjC,MAAM,mBAAmB,aACtB,OAAe,YAAqB;EACnC,MAAM,SAAS,cAAc;EAC7B,IAAI,SAAS,OAAO,IAAI,KAAK;OACxB,OAAO,OAAO,KAAK;EACxB,MAAM,MAAM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GAAG;GACzC,MAAM,eAAe;GACrB,SAAS,aAAa,IAAI,MAAM,QAAQ,cAAc,IAAI,EAAE;EAC9D;CACF;CAEA,MAAM,eAA8D;EAClE,MAAM,aAAa,SAAS,gBAAgB;EAC5C,UAAU;EACV,mBAAmB,IAAI;EACvB,oBAAoB,IAAI;EACxB,OAAO,KAAK,UAAU,KAAA;EACtB,aAAa,KAAK;EAClB,gBAAgB,SAAS,OAAO;EAChC,eAAe,SAAS,KAAK,MAAM;EACnC;CACF;CAEA,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,WAAW,MACT,oBAAC,UAAD;GAAU,UAAU,oBAAC,eAAD,EAAA,UAAgB,SAAwB,CAAA;GACzD,UAAA,kBAAkB,UAAU,CAAC;EACtB,CAAA;EAEZ,OAAO;EACP;EACA,KAAK;CACP,CAAC;CAED,OAAO,oBAAC,kBAAD;EAAkB,OAAO;EAAU,UAAA;CAA0B,CAAA;AACtE;AAEA,UAAU,cAAc"}
|
|
1
|
+
{"version":3,"file":"toast-root.mjs","names":[],"sources":["../../src/toast/toast-root.tsx"],"sourcesContent":["\"use client\";\nimport { Suspense, useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, KeyboardEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { exitAnimations } from \"../internal/overlay/use-exit-animation.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { ownsArrows } from \"../internal/use-roving-focus.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport type { ToastItem, ToastPriority } from \"./toast.js\";\nimport { ToastRootContext, useToastRootContext, useToastViewportContext } from \"./toast-context.js\";\nimport type { ToastRootContextValue } from \"./toast-context.js\";\n\n/**\n * State of `Toast.Root`, `Toast.Title`, `Toast.Description`, passed to the function forms of\n * `className`, `style`, `children` and `render`.\n */\nexport interface ToastRootState {\n /** The toast this Root renders (the Root's `toast` prop). */\n readonly toast: ToastItem;\n /** `toast.pending`: its promise is unsettled or its Action runs. */\n readonly pending: boolean;\n /** `toast.ending`: closed, kept for its exit animation. */\n readonly ending: boolean;\n /** `toast.type`, rendered as `data-type`. */\n readonly type: string | undefined;\n /** `toast.priority`, resolved (`\"normal\"` when absent). */\n readonly priority: ToastPriority;\n}\n\n/**\n * Props of `Toast.Root`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport interface ToastRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"className\" | \"style\" | \"children\" | \"onKeyDown\"\n> {\n /** The toast to render: an item of the Viewport's `state.toasts`. */\n toast: ToastItem;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ToastRootState>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToastRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToastRootState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ToastRootState>;\n /**\n * Rendered by the Root's own Suspense guard while `children` suspend, in place of the\n * invisible default. The toast's timer and announcement wait for the reveal either way.\n * Parts inside it (a visually hidden `<Toast.Title>` giving the toast a name) gate nothing.\n *\n * @defaultValue `null`\n */\n fallback?: ReactNode;\n}\n\n/**\n * The Suspense guard's fallback: renders the Root's `fallback` (nothing by default) and tells\n * the Root its content is suspended, so the timer and the announcement wait for the reveal\n * (design 3.5, 21).\n */\nfunction SuspenseGuard({ children }: { children: ReactNode }) {\n const { setSuspended } = useToastRootContext(\"Toast.Root\");\n useLayoutEffect(() => {\n setSuspended(true);\n return () => setSuspended(false);\n }, [setSuspended]);\n return children;\n}\n\n/**\n * One toast: a focusable `div[role=dialog]` (`alertdialog` for `priority: \"high\"`) named by its\n * Title and described by its Description. Escape dismisses it, ArrowDown / ArrowUp move to the\n * next / previous toast. Its children render inside a Suspense guard whose fallback is the\n * `fallback` prop (invisible by default), so a toast whose content suspends does not pull the whole Viewport into a boundary above it.\n * When the toast closes it stays with `data-ending` (and `inert`) until its exit animations end.\n *\n * Owned keys (conventions 1.2): `role`, `tabIndex`, `aria-labelledby`, `aria-describedby`,\n * `inert`, `data-type`, `data-pending`, `data-ending`, `onKeyDown`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport function ToastRoot({\n toast: item,\n children,\n className,\n style,\n render,\n fallback = null,\n ...rest\n}: ToastRootProps) {\n const viewport = useToastViewportContext(\"Toast.Root\");\n const id = item.id;\n const baseId = useId();\n const ids = useMemo(\n () => ({ title: `${baseId}title`, description: `${baseId}description` }),\n [baseId],\n );\n const elementRef = useRef<HTMLElement | null>(null);\n const titleRef = useRef<HTMLElement | null>(null);\n const descriptionRef = useRef<HTMLElement | null>(null);\n\n // Action pending, aggregated over the Action parts inside (normally one).\n const pendingTokens = useRef(new Set<object>());\n const [actionPending, setActionPendingState] = useState(false);\n // Suspended content behind the guard: a ref for effects of the same commit, state to re-run\n // the announcement once it reveals.\n const suspendedRef = useRef(false);\n const [suspended, setSuspendedState] = useState(false);\n\n const idRef = useLatest(id);\n // The Root's announcement effect has run once: later Title / Description commits are reveals.\n const announcedOnce = useRef(false);\n const revealQueued = useRef(false);\n\n const setActionPending = useCallback(\n (token: object, pending: boolean) => {\n const tokens = pendingTokens.current;\n if (pending) tokens.add(token);\n else tokens.delete(token);\n const any = tokens.size > 0;\n setActionPendingState(any);\n viewport.setActionPending(idRef.current, any);\n },\n [viewport, idRef],\n );\n\n const setSuspended = useCallback(\n (value: boolean) => {\n suspendedRef.current = value;\n setSuspendedState(value);\n viewport.setSuspended(idRef.current, value);\n },\n [viewport, idRef],\n );\n\n const close = useCallback(\n (reason: Parameters<ToastRootContextValue[\"close\"]>[0], event: Event | undefined) =>\n viewport.close([idRef.current], reason, event),\n [viewport, idRef],\n );\n\n const registerTitle = useCallback((element: HTMLElement | null) => {\n titleRef.current = element;\n }, []);\n const registerDescription = useCallback((element: HTMLElement | null) => {\n descriptionRef.current = element;\n }, []);\n\n const pending = item.pending || actionPending;\n const priority = item.priority ?? \"normal\";\n\n // Announce once the content has committed un-suspended (design 5): the Title and Description\n // text exists now. The Viewport skips text it already announced for this toast and speaks the\n // batch a microtask later.\n const announceNow = (): void => {\n if (item.ending || suspendedRef.current) return;\n const resolver = item.announce ?? viewport.announcer();\n let text: string | null;\n if (resolver !== undefined) text = resolver(item);\n else {\n text = [titleRef.current?.textContent, descriptionRef.current?.textContent]\n .map((t) => (t ?? \"\").trim())\n .filter((t) => t !== \"\")\n .join(\" \");\n }\n viewport.announce(item.id, text, priority);\n };\n const announceRef = useLatest(announceNow);\n\n // A Title or Description inside the consumer's own `<Suspense>` commits after the Root (the\n // boundary's retry does not re-run the Root's effect). Read once the whole reveal committed,\n // so a Title and a Description revealed together are announced as one text.\n const contentCommitted = useCallback(() => {\n if (!announcedOnce.current || revealQueued.current) return;\n revealQueued.current = true;\n queueMicrotask(() => {\n revealQueued.current = false;\n announceRef.current();\n });\n }, [announceRef]);\n const state = useMemo<ToastRootState>(\n () => ({ toast: item, pending, ending: item.ending, type: item.type, priority }),\n [item, pending, priority],\n );\n\n const context = useMemo<ToastRootContextValue>(\n () => ({\n toast: item,\n ids,\n state,\n registerTitle,\n registerDescription,\n contentCommitted,\n setActionPending,\n setSuspended,\n close,\n }),\n [\n item,\n ids,\n state,\n registerTitle,\n registerDescription,\n contentCommitted,\n setActionPending,\n setSuspended,\n close,\n ],\n );\n\n const rootRef = useCallback(\n (element: HTMLElement) => {\n elementRef.current = element;\n viewport.registerRoot(id, element);\n return () => {\n if (elementRef.current === element) elementRef.current = null;\n viewport.registerRoot(id, null);\n };\n },\n [viewport, id],\n );\n\n // A layout effect, so toasts announce in queue order (before the Viewport's own effect\n // announces the queued ones).\n useLayoutEffect(() => {\n announcedOnce.current = true;\n announceRef.current();\n }, [item, suspended, priority, announceRef]);\n\n // Exit (design 10.2): keep the ending toast until the animations the ending state started\n // settle, then drop it. Animations that ran before (a progress bar, paused with the region or\n // not) are not waited for: the Viewport recorded them just before marking the toast ending.\n useLayoutEffect(() => {\n if (!item.ending) return;\n const element = elementRef.current;\n const baseline = viewport.exitBaseline(item.id);\n const animations = element === null ? [] : exitAnimations(element, baseline);\n if (animations.length === 0) {\n viewport.drop(item.id);\n return;\n }\n let cancelled = false;\n void Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {\n if (!cancelled) viewport.drop(item.id);\n });\n return () => {\n cancelled = true;\n };\n }, [item.ending, item.id, viewport]);\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>): void => {\n if (event.defaultPrevented || item.ending) return;\n if (event.key === \"Escape\") {\n event.preventDefault();\n close(\"dismiss\", event.nativeEvent);\n } else if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n // A text field, select or slider inside the toast keeps its arrows (the roving rule,\n // toggle-group.md 6.3).\n if (ownsArrows(event.target as Element)) return;\n event.preventDefault();\n viewport.focusSibling(id, event.key === \"ArrowDown\" ? 1 : -1);\n }\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n role: priority === \"high\" ? \"alertdialog\" : \"dialog\",\n tabIndex: 0,\n \"aria-labelledby\": ids.title,\n \"aria-describedby\": ids.description,\n inert: item.ending || undefined,\n \"data-type\": item.type,\n \"data-pending\": dataAttr(pending),\n \"data-ending\": dataAttr(item.ending),\n onKeyDown,\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, ToastRootState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children: (s: ToastRootState) => (\n <Suspense fallback={<SuspenseGuard>{fallback}</SuspenseGuard>}>\n {resolveStateValue(children, s)}\n </Suspense>\n ),\n props: rest,\n libraryProps,\n ref: rootRef,\n });\n\n return <ToastRootContext value={context}>{element}</ToastRootContext>;\n}\n\nToastRoot.displayName = \"ToastRoot\";\n"],"mappings":";;;;;;;;;;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AChC,eAAe,SAAS,KAAK,MAAM;EACnC;CACF;CAEA,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,WAAW,MACT,oBAAC,UAAD;GAAU,UAAU,oBAAC,eAAD,EAAA,UAAgB,SAAwB,CAAA;GACzD,UAAA,kBAAkB,UAAU,CAAC;EACtB,CAAA;EAEZ,OAAO;EACP;EACA,KAAK;CACP,CAAC;CAED,OAAO,oBAAC,kBAAD;EAAkB,OAAO;EAAU,UAAA;CAA0B,CAAA;AACtE;AAEA,UAAU,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-viewport.d.mts","names":[],"sources":["../../src/toast/toast-viewport.tsx"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"toast-viewport.d.mts","names":[],"sources":["../../src/toast/toast-viewport.tsx"],"mappings":";;;;;;;;iBAuCiB;;WAEN,iBAAiB;;WAEjB;;WAEA;;;;;;;iBAQM,2BAA2B,KAC1C;;;;;;EAgBA,UAAU;;;;;;EAMV;;;;;;EAMA;;;;;;;;EAQA;;;;;;;EAOA,YAAY,OAAO;;EAEnB,WAAW,WAAW,WAAW;;EAEjC,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,kCAAkC;;;;;;;;;;;;;wBAgBxC,gBACd,SACA,OACA,UACA,QACA,UACA,UACA,WACA,OACA,WACG,QACF,qCAAkB,IAAA;yBAXL"}
|