@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
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { compareDocumentOrder } from "../internal/dom-order.mjs";
|
|
3
|
+
import { matchesHotkey } from "./toast-hotkey.mjs";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
//#region src/toast/use-toast-focus.ts
|
|
6
|
+
/** Focus in and out of `Toast.Viewport`'s toasts (design/components/toast.md 7). */
|
|
7
|
+
function useToastFocus({ entriesRef, roots, regionRef }) {
|
|
8
|
+
const returnTargetRef = useRef(null);
|
|
9
|
+
const sortedRoots = (exclude) => {
|
|
10
|
+
const open = new Set(entriesRef.current.filter((e) => !e.ending).map((e) => e.options.id));
|
|
11
|
+
const list = [];
|
|
12
|
+
for (const [id, element] of roots.current) {
|
|
13
|
+
if (!open.has(id) || exclude?.has(id) || !element.isConnected) continue;
|
|
14
|
+
list.push({
|
|
15
|
+
id,
|
|
16
|
+
element
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return list.sort((a, b) => compareDocumentOrder(a.element, b.element));
|
|
20
|
+
};
|
|
21
|
+
const moveFocusOut = (closing) => {
|
|
22
|
+
const doc = regionRef.current?.ownerDocument ?? document;
|
|
23
|
+
const active = doc.activeElement;
|
|
24
|
+
if (!(active instanceof HTMLElement)) return;
|
|
25
|
+
const all = sortedRoots();
|
|
26
|
+
const index = all.findIndex(({ element }) => element.contains(active));
|
|
27
|
+
if (index === -1 || !closing.has(all[index].id)) return;
|
|
28
|
+
const after = all.slice(index + 1).find(({ id }) => !closing.has(id));
|
|
29
|
+
const before = all.slice(0, index).reverse().find(({ id }) => !closing.has(id));
|
|
30
|
+
const target = after ?? before;
|
|
31
|
+
if (target !== void 0) {
|
|
32
|
+
target.element.focus();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const stored = returnTargetRef.current;
|
|
36
|
+
if (stored !== null && stored.isConnected && !regionRef.current?.contains(stored)) {
|
|
37
|
+
stored.focus();
|
|
38
|
+
if (doc.activeElement === stored) return;
|
|
39
|
+
}
|
|
40
|
+
active.blur();
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
returnTargetRef,
|
|
44
|
+
sortedRoots,
|
|
45
|
+
moveFocusOut
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The hotkey that focuses the newest toast (design/components/toast.md 7), remembering where
|
|
50
|
+
* focus was as the return target.
|
|
51
|
+
*/
|
|
52
|
+
function useToastHotkey({ hotkey, rejected, regionRef, focus }) {
|
|
53
|
+
const { sortedRoots, returnTargetRef } = focus;
|
|
54
|
+
const hotkeyKey = hotkey === null ? null : hotkey.join("\0");
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (hotkeyKey === null || rejected) return;
|
|
57
|
+
const keys = hotkeyKey.split("\0");
|
|
58
|
+
const doc = regionRef.current?.ownerDocument ?? document;
|
|
59
|
+
const onKeyDown = (event) => {
|
|
60
|
+
if (event.defaultPrevented || !matchesHotkey(keys, event)) return;
|
|
61
|
+
const newest = sortedRoots().at(-1);
|
|
62
|
+
if (newest === void 0) return;
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
const active = doc.activeElement;
|
|
65
|
+
if (active instanceof HTMLElement && !regionRef.current?.contains(active)) returnTargetRef.current = active;
|
|
66
|
+
newest.element.focus();
|
|
67
|
+
};
|
|
68
|
+
doc.addEventListener("keydown", onKeyDown);
|
|
69
|
+
return () => doc.removeEventListener("keydown", onKeyDown);
|
|
70
|
+
}, [hotkeyKey, rejected]);
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { useToastFocus, useToastHotkey };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=use-toast-focus.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-toast-focus.mjs","names":[],"sources":["../../src/toast/use-toast-focus.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { compareDocumentOrder } from \"../internal/dom-order.js\";\nimport { matchesHotkey } from \"./toast-hotkey.js\";\nimport type { Entry } from \"./toast-queue.js\";\n\nexport interface ToastFocusOptions {\n /** The Viewport's latest queue. */\n readonly entriesRef: RefObject<readonly Entry[]>;\n /** The mounted Roots by toast id. */\n readonly roots: RefObject<Map<string, HTMLElement>>;\n readonly regionRef: RefObject<HTMLElement | null>;\n}\n\nexport interface ToastFocus {\n /** Where focus goes back to once the last toast holding it leaves (design 7). */\n readonly returnTargetRef: RefObject<HTMLElement | null>;\n /** Open toasts' Root elements in document order. Reads refs only. */\n readonly sortedRoots: (exclude?: ReadonlySet<string>) => { id: string; element: HTMLElement }[];\n /**\n * Before toasts close: if focus is inside one of them, move it to the next toast, else the\n * previous one, else where it was before the region was entered, else the body (design 7).\n */\n readonly moveFocusOut: (closing: ReadonlySet<string>) => void;\n}\n\n/** Focus in and out of `Toast.Viewport`'s toasts (design/components/toast.md 7). */\nexport function useToastFocus({ entriesRef, roots, regionRef }: ToastFocusOptions): ToastFocus {\n const returnTargetRef = useRef<HTMLElement | null>(null);\n\n const sortedRoots = (exclude?: ReadonlySet<string>): { id: string; element: HTMLElement }[] => {\n const open = new Set(entriesRef.current.filter((e) => !e.ending).map((e) => e.options.id));\n const list: { id: string; element: HTMLElement }[] = [];\n for (const [id, element] of roots.current) {\n if (!open.has(id) || exclude?.has(id) || !element.isConnected) continue;\n list.push({ id, element });\n }\n return list.sort((a, b) => compareDocumentOrder(a.element, b.element));\n };\n\n const moveFocusOut = (closing: ReadonlySet<string>): void => {\n const doc = regionRef.current?.ownerDocument ?? document;\n const active = doc.activeElement;\n if (!(active instanceof HTMLElement)) return;\n const all = sortedRoots();\n const index = all.findIndex(({ element }) => element.contains(active));\n if (index === -1 || !closing.has(all[index]!.id)) return;\n const after = all.slice(index + 1).find(({ id }) => !closing.has(id));\n const before = all\n .slice(0, index)\n .reverse()\n .find(({ id }) => !closing.has(id));\n const target = after ?? before;\n if (target !== undefined) {\n target.element.focus();\n return;\n }\n const stored = returnTargetRef.current;\n if (stored !== null && stored.isConnected && !regionRef.current?.contains(stored)) {\n stored.focus();\n if (doc.activeElement === stored) return;\n }\n active.blur();\n };\n\n return { returnTargetRef, sortedRoots, moveFocusOut };\n}\n\nexport interface ToastHotkeyOptions {\n /** The Viewport's `hotkey`; `null` installs no listener. */\n readonly hotkey: readonly string[] | null;\n /** This Viewport renders nothing (another one renders the manager). */\n readonly rejected: boolean;\n readonly regionRef: RefObject<HTMLElement | null>;\n readonly focus: ToastFocus;\n}\n\n/**\n * The hotkey that focuses the newest toast (design/components/toast.md 7), remembering where\n * focus was as the return target.\n */\nexport function useToastHotkey({ hotkey, rejected, regionRef, focus }: ToastHotkeyOptions): void {\n const { sortedRoots, returnTargetRef } = focus;\n const hotkeyKey = hotkey === null ? null : hotkey.join(\"\\u0000\");\n useEffect(() => {\n if (hotkeyKey === null || rejected) return;\n const keys = hotkeyKey.split(\"\\u0000\");\n const doc = regionRef.current?.ownerDocument ?? document;\n const onKeyDown = (event: KeyboardEvent): void => {\n if (event.defaultPrevented || !matchesHotkey(keys, event)) return;\n const all = sortedRoots();\n const newest = all.at(-1);\n if (newest === undefined) return;\n event.preventDefault();\n const active = doc.activeElement;\n if (active instanceof HTMLElement && !regionRef.current?.contains(active)) {\n returnTargetRef.current = active;\n }\n newest.element.focus();\n };\n doc.addEventListener(\"keydown\", onKeyDown);\n return () => doc.removeEventListener(\"keydown\", onKeyDown);\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- `sortedRoots` reads refs only\n }, [hotkeyKey, rejected]);\n}\n"],"mappings":";;;;;;AA4BA,SAAgB,cAAc,EAAE,YAAY,OAAO,aAA4C;CAC7F,MAAM,kBAAkB,OAA2B,IAAI;CAEvD,MAAM,eAAe,YAA0E;EAC7F,MAAM,OAAO,IAAI,IAAI,WAAW,QAAQ,QAAQ,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,KAAK,MAAM,EAAE,QAAQ,EAAE,CAAC;EACzF,MAAM,OAA+C,CAAC;EACtD,KAAK,MAAM,CAAC,IAAI,YAAY,MAAM,SAAS;GACzC,IAAI,CAAC,KAAK,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,CAAC,QAAQ,aAAa;GAC/D,KAAK,KAAK;IAAE;IAAI;GAAQ,CAAC;EAC3B;EACA,OAAO,KAAK,MAAM,GAAG,MAAM,qBAAqB,EAAE,SAAS,EAAE,OAAO,CAAC;CACvE;CAEA,MAAM,gBAAgB,YAAuC;EAC3D,MAAM,MAAM,UAAU,SAAS,iBAAiB;EAChD,MAAM,SAAS,IAAI;EACnB,IAAI,EAAE,kBAAkB,cAAc;EACtC,MAAM,MAAM,YAAY;EACxB,MAAM,QAAQ,IAAI,WAAW,EAAE,cAAc,QAAQ,SAAS,MAAM,CAAC;EACrE,IAAI,UAAU,MAAM,CAAC,QAAQ,IAAI,IAAI,MAAM,CAAE,EAAE,GAAG;EAClD,MAAM,QAAQ,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC;EACpE,MAAM,SAAS,IACZ,MAAM,GAAG,KAAK,CAAC,CACf,QAAQ,CAAC,CACT,MAAM,EAAE,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC;EACpC,MAAM,SAAS,SAAS;EACxB,IAAI,WAAW,KAAA,GAAW;GACxB,OAAO,QAAQ,MAAM;GACrB;EACF;EACA,MAAM,SAAS,gBAAgB;EAC/B,IAAI,WAAW,QAAQ,OAAO,eAAe,CAAC,UAAU,SAAS,SAAS,MAAM,GAAG;GACjF,OAAO,MAAM;GACb,IAAI,IAAI,kBAAkB,QAAQ;EACpC;EACA,OAAO,KAAK;CACd;CAEA,OAAO;EAAE;EAAiB;EAAa;CAAa;AACtD;;;;;AAeA,SAAgB,eAAe,EAAE,QAAQ,UAAU,WAAW,SAAmC;CAC/F,MAAM,EAAE,aAAa,oBAAoB;CACzC,MAAM,YAAY,WAAW,OAAO,OAAO,OAAO,KAAK,IAAQ;CAC/D,gBAAgB;EACd,IAAI,cAAc,QAAQ,UAAU;EACpC,MAAM,OAAO,UAAU,MAAM,IAAQ;EACrC,MAAM,MAAM,UAAU,SAAS,iBAAiB;EAChD,MAAM,aAAa,UAA+B;GAChD,IAAI,MAAM,oBAAoB,CAAC,cAAc,MAAM,KAAK,GAAG;GAE3D,MAAM,SADM,YACK,CAAC,CAAC,GAAG,EAAE;GACxB,IAAI,WAAW,KAAA,GAAW;GAC1B,MAAM,eAAe;GACrB,MAAM,SAAS,IAAI;GACnB,IAAI,kBAAkB,eAAe,CAAC,UAAU,SAAS,SAAS,MAAM,GACtE,gBAAgB,UAAU;GAE5B,OAAO,QAAQ,MAAM;EACvB;EACA,IAAI,iBAAiB,WAAW,SAAS;EACzC,aAAa,IAAI,oBAAoB,WAAW,SAAS;CAE3D,GAAG,CAAC,WAAW,QAAQ,CAAC;AAC1B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLatest } from "../internal/use-latest.mjs";
|
|
3
|
+
import { useCallback, useRef, useState } from "react";
|
|
4
|
+
//#region src/toast/use-toast-pauses.ts
|
|
5
|
+
function anyPause(sources) {
|
|
6
|
+
return sources.hover || sources.focus || sources.hidden || sources.blurred;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The pause sources of `Toast.Viewport` (design/components/toast.md 6): the pointer over the
|
|
10
|
+
* region, focus inside it, a hidden document, a blurred window. `syncTimers` re-syncs the timers
|
|
11
|
+
* after a change.
|
|
12
|
+
*/
|
|
13
|
+
function useToastPauses(syncTimers) {
|
|
14
|
+
const sources = useRef({
|
|
15
|
+
hover: false,
|
|
16
|
+
focus: false,
|
|
17
|
+
hidden: false,
|
|
18
|
+
blurred: false
|
|
19
|
+
});
|
|
20
|
+
const [paused, setPaused] = useState(false);
|
|
21
|
+
const setPause = (source, value) => {
|
|
22
|
+
if (sources.current[source] === value) return;
|
|
23
|
+
sources.current[source] = value;
|
|
24
|
+
syncTimers();
|
|
25
|
+
setPaused(anyPause(sources.current));
|
|
26
|
+
};
|
|
27
|
+
const setPauseRef = useLatest(setPause);
|
|
28
|
+
return {
|
|
29
|
+
paused,
|
|
30
|
+
holding: (source) => sources.current[source],
|
|
31
|
+
anyHeld: () => anyPause(sources.current),
|
|
32
|
+
setPause,
|
|
33
|
+
watch: useCallback((doc) => {
|
|
34
|
+
const view = doc.defaultView ?? window;
|
|
35
|
+
sources.current.hidden = doc.visibilityState === "hidden";
|
|
36
|
+
const onVisibility = () => setPauseRef.current("hidden", doc.visibilityState === "hidden");
|
|
37
|
+
const onWindowBlur = (event) => {
|
|
38
|
+
if (!(event.target instanceof Node)) setPauseRef.current("blurred", true);
|
|
39
|
+
};
|
|
40
|
+
const onWindowFocus = (event) => {
|
|
41
|
+
if (!(event.target instanceof Node)) setPauseRef.current("blurred", false);
|
|
42
|
+
};
|
|
43
|
+
doc.addEventListener("visibilitychange", onVisibility);
|
|
44
|
+
view.addEventListener("blur", onWindowBlur);
|
|
45
|
+
view.addEventListener("focus", onWindowFocus);
|
|
46
|
+
setPaused(anyPause(sources.current));
|
|
47
|
+
return () => {
|
|
48
|
+
doc.removeEventListener("visibilitychange", onVisibility);
|
|
49
|
+
view.removeEventListener("blur", onWindowBlur);
|
|
50
|
+
view.removeEventListener("focus", onWindowFocus);
|
|
51
|
+
};
|
|
52
|
+
}, [setPauseRef])
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { useToastPauses };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=use-toast-pauses.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-toast-pauses.mjs","names":[],"sources":["../../src/toast/use-toast-pauses.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef, useState } from \"react\";\nimport { useLatest } from \"../internal/use-latest.js\";\n\n/** The viewport-wide pause sources (design/components/toast.md 6). */\nexport interface PauseSources {\n hover: boolean;\n focus: boolean;\n hidden: boolean;\n blurred: boolean;\n}\n\nfunction anyPause(sources: PauseSources): boolean {\n return sources.hover || sources.focus || sources.hidden || sources.blurred;\n}\n\nexport interface ToastPauses {\n /** A pause holds, as of the last write (state, for `data-paused` and the Viewport's state). */\n readonly paused: boolean;\n /** Whether `source` holds now. Handlers and effects only. */\n readonly holding: (source: keyof PauseSources) => boolean;\n /** Whether any source holds now (the timers are halted). Handlers and effects only. */\n readonly anyHeld: () => boolean;\n /**\n * Sets a source. A change re-syncs the timers synchronously, in the event, before any timer\n * callback can run (design 14 item 9), then publishes `paused`.\n */\n readonly setPause: (source: keyof PauseSources, value: boolean) => void;\n /**\n * Reads the document's visibility, listens to it and to the window's own focus and blur, and\n * publishes `paused`. Returns the cleanup. For the Viewport's mount effect; stable.\n */\n readonly watch: (doc: Document) => () => void;\n}\n\n/**\n * The pause sources of `Toast.Viewport` (design/components/toast.md 6): the pointer over the\n * region, focus inside it, a hidden document, a blurred window. `syncTimers` re-syncs the timers\n * after a change.\n */\nexport function useToastPauses(syncTimers: () => void): ToastPauses {\n const sources = useRef<PauseSources>({\n hover: false,\n focus: false,\n hidden: false,\n blurred: false,\n });\n const [paused, setPaused] = useState(false);\n\n const setPause = (source: keyof PauseSources, value: boolean): void => {\n if (sources.current[source] === value) return;\n sources.current[source] = value;\n // Applied synchronously in the event, before any timer callback can run (design 14 item 9).\n syncTimers();\n setPaused(anyPause(sources.current));\n };\n const setPauseRef = useLatest(setPause);\n\n // Stable, so the Viewport's mount effect does not re-run for it.\n const watch = useCallback(\n (doc: Document): (() => void) => {\n const view = doc.defaultView ?? window;\n sources.current.hidden = doc.visibilityState === \"hidden\";\n const onVisibility = (): void =>\n setPauseRef.current(\"hidden\", doc.visibilityState === \"hidden\");\n // The window's own focus and blur; an element's (which do not bubble) never reach here.\n const onWindowBlur = (event: Event): void => {\n if (!(event.target instanceof Node)) setPauseRef.current(\"blurred\", true);\n };\n const onWindowFocus = (event: Event): void => {\n if (!(event.target instanceof Node)) setPauseRef.current(\"blurred\", false);\n };\n doc.addEventListener(\"visibilitychange\", onVisibility);\n view.addEventListener(\"blur\", onWindowBlur);\n view.addEventListener(\"focus\", onWindowFocus);\n setPaused(anyPause(sources.current));\n return () => {\n doc.removeEventListener(\"visibilitychange\", onVisibility);\n view.removeEventListener(\"blur\", onWindowBlur);\n view.removeEventListener(\"focus\", onWindowFocus);\n };\n },\n [setPauseRef],\n );\n\n return {\n paused,\n holding: (source) => sources.current[source],\n anyHeld: () => anyPause(sources.current),\n setPause,\n watch,\n };\n}\n"],"mappings":";;;;AAYA,SAAS,SAAS,SAAgC;CAChD,OAAO,QAAQ,SAAS,QAAQ,SAAS,QAAQ,UAAU,QAAQ;AACrE;;;;;;AA0BA,SAAgB,eAAe,YAAqC;CAClE,MAAM,UAAU,OAAqB;EACnC,OAAO;EACP,OAAO;EACP,QAAQ;EACR,SAAS;CACX,CAAC;CACD,MAAM,CAAC,QAAQ,aAAa,SAAS,KAAK;CAE1C,MAAM,YAAY,QAA4B,UAAyB;EACrE,IAAI,QAAQ,QAAQ,YAAY,OAAO;EACvC,QAAQ,QAAQ,UAAU;EAE1B,WAAW;EACX,UAAU,SAAS,QAAQ,OAAO,CAAC;CACrC;CACA,MAAM,cAAc,UAAU,QAAQ;CA6BtC,OAAO;EACL;EACA,UAAU,WAAW,QAAQ,QAAQ;EACrC,eAAe,SAAS,QAAQ,OAAO;EACvC;EACA,OA/BY,aACX,QAAgC;GAC/B,MAAM,OAAO,IAAI,eAAe;GAChC,QAAQ,QAAQ,SAAS,IAAI,oBAAoB;GACjD,MAAM,qBACJ,YAAY,QAAQ,UAAU,IAAI,oBAAoB,QAAQ;GAEhE,MAAM,gBAAgB,UAAuB;IAC3C,IAAI,EAAE,MAAM,kBAAkB,OAAO,YAAY,QAAQ,WAAW,IAAI;GAC1E;GACA,MAAM,iBAAiB,UAAuB;IAC5C,IAAI,EAAE,MAAM,kBAAkB,OAAO,YAAY,QAAQ,WAAW,KAAK;GAC3E;GACA,IAAI,iBAAiB,oBAAoB,YAAY;GACrD,KAAK,iBAAiB,QAAQ,YAAY;GAC1C,KAAK,iBAAiB,SAAS,aAAa;GAC5C,UAAU,SAAS,QAAQ,OAAO,CAAC;GACnC,aAAa;IACX,IAAI,oBAAoB,oBAAoB,YAAY;IACxD,KAAK,oBAAoB,QAAQ,YAAY;IAC7C,KAAK,oBAAoB,SAAS,aAAa;GACjD;EACF,GACA,CAAC,WAAW,CAQR;CACN;AACF"}
|
package/dist/toggle/toggle.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
4
|
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
5
5
|
import { disabledButton, rendersButton } from "../internal/render-element.mjs";
|
|
6
6
|
import { useRender } from "../internal/use-render.mjs";
|
|
7
7
|
import { transitionTypes } from "../internal/transition-types.mjs";
|
|
8
|
-
import { useControllableAction } from "../internal/use-controllable-action.mjs";
|
|
8
|
+
import { useControllableAction } from "../internal/action/use-controllable-action.mjs";
|
|
9
9
|
//#region src/toggle/toggle.tsx
|
|
10
10
|
/**
|
|
11
11
|
* A two-state button (WAI-ARIA "Button" pattern, toggle variant). Renders
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.mjs","names":[],"sources":["../../src/toggle/toggle.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ActionDetails, ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\n\n/**\n * State of `Toggle`, passed to the function forms of `className`, `style`, `children` and `render`.\n */\nexport interface ToggleState {\n /** Optimistic pressed state: what the user sees, including an in-flight change. */\n readonly pressed: boolean;\n /** An action dispatched by this Toggle is in flight (including the resulting render). */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Details passed as the second argument of `pressedChangeAction`. */\nexport interface TogglePressedChangeDetails extends ActionDetails {\n // v0 adds nothing beyond `event`; the interface exists so fields can be added without a\n // breaking change (e.g. a `reason` if a ToggleGroup ever dispatches on an item's behalf).\n}\n\n/**\n * Props of `Toggle`.\n *\n * @see https://ui.funstack.work/components/toggle\n */\nexport interface ToggleProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"type\" | \"aria-pressed\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled pressed state. `undefined` means uncontrolled. */\n pressed?: boolean;\n /**\n * Initial pressed state in uncontrolled mode.\n *\n * @defaultValue `false`\n */\n defaultPressed?: boolean;\n /**\n * Called with the next pressed state on every user-initiated change. Runs inside the Toggle's\n * transition; may be sync or async. Rejections reach the nearest Error Boundary.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n pressedChangeAction?: ChangeAction<boolean, TogglePressedChangeDetails>;\n /**\n * Never dispatches. Native `disabled` on a `<button>`; with a link or component `render`,\n * `aria-disabled=\"true\"` instead (the element stays focusable).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Forwarded as `default` to the Toggle's `<ViewTransition>`. Default: no boundary. Animates the\n * commit that ends an action (and rollbacks), not the optimistic flip itself; animate the flip\n * with a CSS `transition` on `[data-pressed]`.\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, ToggleState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToggleState>;\n /** Rendered from optimistic state inside the button; must not suspend. */\n children?: StateValue<ReactNode, ToggleState>;\n /** Replace the rendered element (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ToggleState>;\n}\n\n/**\n * A two-state button (WAI-ARIA \"Button\" pattern, toggle variant). Renders\n * `<button type=\"button\" aria-pressed>`; the pressed state flips optimistically and the element\n * carries `data-pending` while `pressedChangeAction` is in flight.\n *\n * @see https://ui.funstack.work/components/toggle\n */\nexport function Toggle({\n pressed,\n defaultPressed,\n pressedChangeAction,\n disabled = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: ToggleProps) {\n const { optimistic, pending, dispatch } = useControllableAction<\n boolean,\n TogglePressedChangeDetails\n >({\n controlled: pressed,\n defaultValue: defaultPressed,\n initialValue: false,\n action: pressedChangeAction,\n transitionTypes: (next) => transitionTypes(\"toggle\", next ? \"press\" : \"release\"),\n warn: { component: \"Toggle\", prop: \"pressed\" },\n });\n\n const state: ToggleState = { pressed: optimistic, pending, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"button\">, ToggleState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n // Pass-through layer: a `render` element's own props win over these (its `type` included).\n // `type=\"button\"` only on a real button; an `<a>` or a component element does not get it.\n props: rendersButton(render) ? { ...rest, type: \"button\" } : rest,\n // Library-controlled layer: wins over a `render` element's props.\n libraryProps: {\n // Owned so that native disabledness, `data-disabled` and the click guard always agree: a\n // `render` element cannot re-enable (`disabled={false}`) or disable the button on its own.\n ...disabledButton(render, disabled).props,\n \"aria-pressed\": optimistic,\n \"data-pressed\": dataAttr(optimistic),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n // Native buttons do not fire `click` when disabled; the guard covers `render` elements\n // that do not honour `disabled` (a link must not navigate either).\n if (disabled) {\n event.preventDefault();\n return;\n }\n dispatch(!optimistic, createActionDetails(event.nativeEvent, {}));\n },\n },\n });\n\n return useTransitionBoundary(\"Toggle\", transition, element);\n}\n\nToggle.displayName = \"Toggle\";\n"],"mappings":";;;;;;;;;;;;;;;;AA6FA,SAAgB,OAAO,EACrB,SACA,gBACA,qBACA,WAAW,OACX,YACA,WACA,OACA,UACA,QACA,GAAG,QACW;CACd,MAAM,EAAE,YAAY,SAAS,aAAa,sBAGxC;EACA,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ;EACR,kBAAkB,SAAS,gBAAgB,UAAU,OAAO,UAAU,SAAS;EAC/E,MAAM;GAAE,WAAW;GAAU,MAAM;EAAU;CAC/C,CAAC;CAID,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA,OAAA;GAL2B,SAAS;GAAY;GAAS;EAKrD;EACJ;EACA;EACA;EAGA,OAAO,cAAc,MAAM,IAAI;GAAE,GAAG;GAAM,MAAM;EAAS,IAAI;EAE7D,cAAc;GAGZ,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;GACpC,gBAAgB;GAChB,gBAAgB,SAAS,UAAU;GACnC,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;GAClC,UAAU,UAAyC;IAGjD,IAAI,UAAU;KACZ,MAAM,eAAe;KACrB;IACF;IACA,SAAS,CAAC,YAAY,oBAAoB,MAAM,aAAa,CAAC,CAAC,CAAC;GAClE;EACF;CACF,CAAC;CAED,OAAO,sBAAsB,UAAU,YAAY,OAAO;AAC5D;AAEA,OAAO,cAAc"}
|
|
1
|
+
{"version":3,"file":"toggle.mjs","names":[],"sources":["../../src/toggle/toggle.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ActionDetails, ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/action/use-controllable-action.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\n\n/**\n * State of `Toggle`, passed to the function forms of `className`, `style`, `children` and `render`.\n */\nexport interface ToggleState {\n /** Optimistic pressed state: what the user sees, including an in-flight change. */\n readonly pressed: boolean;\n /** An action dispatched by this Toggle is in flight (including the resulting render). */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Details passed as the second argument of `pressedChangeAction`. */\nexport interface TogglePressedChangeDetails extends ActionDetails {\n // v0 adds nothing beyond `event`; the interface exists so fields can be added without a\n // breaking change (e.g. a `reason` if a ToggleGroup ever dispatches on an item's behalf).\n}\n\n/**\n * Props of `Toggle`.\n *\n * @see https://ui.funstack.work/components/toggle\n */\nexport interface ToggleProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"type\" | \"aria-pressed\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled pressed state. `undefined` means uncontrolled. */\n pressed?: boolean;\n /**\n * Initial pressed state in uncontrolled mode.\n *\n * @defaultValue `false`\n */\n defaultPressed?: boolean;\n /**\n * Called with the next pressed state on every user-initiated change. Runs inside the Toggle's\n * transition; may be sync or async. Rejections reach the nearest Error Boundary.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n pressedChangeAction?: ChangeAction<boolean, TogglePressedChangeDetails>;\n /**\n * Never dispatches. Native `disabled` on a `<button>`; with a link or component `render`,\n * `aria-disabled=\"true\"` instead (the element stays focusable).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Forwarded as `default` to the Toggle's `<ViewTransition>`. Default: no boundary. Animates the\n * commit that ends an action (and rollbacks), not the optimistic flip itself; animate the flip\n * with a CSS `transition` on `[data-pressed]`.\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, ToggleState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToggleState>;\n /** Rendered from optimistic state inside the button; must not suspend. */\n children?: StateValue<ReactNode, ToggleState>;\n /** Replace the rendered element (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ToggleState>;\n}\n\n/**\n * A two-state button (WAI-ARIA \"Button\" pattern, toggle variant). Renders\n * `<button type=\"button\" aria-pressed>`; the pressed state flips optimistically and the element\n * carries `data-pending` while `pressedChangeAction` is in flight.\n *\n * @see https://ui.funstack.work/components/toggle\n */\nexport function Toggle({\n pressed,\n defaultPressed,\n pressedChangeAction,\n disabled = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: ToggleProps) {\n const { optimistic, pending, dispatch } = useControllableAction<\n boolean,\n TogglePressedChangeDetails\n >({\n controlled: pressed,\n defaultValue: defaultPressed,\n initialValue: false,\n action: pressedChangeAction,\n transitionTypes: (next) => transitionTypes(\"toggle\", next ? \"press\" : \"release\"),\n warn: { component: \"Toggle\", prop: \"pressed\" },\n });\n\n const state: ToggleState = { pressed: optimistic, pending, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"button\">, ToggleState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n // Pass-through layer: a `render` element's own props win over these (its `type` included).\n // `type=\"button\"` only on a real button; an `<a>` or a component element does not get it.\n props: rendersButton(render) ? { ...rest, type: \"button\" } : rest,\n // Library-controlled layer: wins over a `render` element's props.\n libraryProps: {\n // Owned so that native disabledness, `data-disabled` and the click guard always agree: a\n // `render` element cannot re-enable (`disabled={false}`) or disable the button on its own.\n ...disabledButton(render, disabled).props,\n \"aria-pressed\": optimistic,\n \"data-pressed\": dataAttr(optimistic),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n // Native buttons do not fire `click` when disabled; the guard covers `render` elements\n // that do not honour `disabled` (a link must not navigate either).\n if (disabled) {\n event.preventDefault();\n return;\n }\n dispatch(!optimistic, createActionDetails(event.nativeEvent, {}));\n },\n },\n });\n\n return useTransitionBoundary(\"Toggle\", transition, element);\n}\n\nToggle.displayName = \"Toggle\";\n"],"mappings":";;;;;;;;;;;;;;;;AA6FA,SAAgB,OAAO,EACrB,SACA,gBACA,qBACA,WAAW,OACX,YACA,WACA,OACA,UACA,QACA,GAAG,QACW;CACd,MAAM,EAAE,YAAY,SAAS,aAAa,sBAGxC;EACA,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ;EACR,kBAAkB,SAAS,gBAAgB,UAAU,OAAO,UAAU,SAAS;EAC/E,MAAM;GAAE,WAAW;GAAU,MAAM;EAAU;CAC/C,CAAC;CAID,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA,OAAA;GAL2B,SAAS;GAAY;GAAS;EAKrD;EACJ;EACA;EACA;EAGA,OAAO,cAAc,MAAM,IAAI;GAAE,GAAG;GAAM,MAAM;EAAS,IAAI;EAE7D,cAAc;GAGZ,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;GACpC,gBAAgB;GAChB,gBAAgB,SAAS,UAAU;GACnC,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;GAClC,UAAU,UAAyC;IAGjD,IAAI,UAAU;KACZ,MAAM,eAAe;KACrB;IACF;IACA,SAAS,CAAC,YAAY,oBAAoB,MAAM,aAAa,CAAC,CAAC,CAAC;GAClE;EACF;CACF,CAAC;CAED,OAAO,sBAAsB,UAAU,YAAY,OAAO;AAC5D;AAEA,OAAO,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group-root.d.mts","names":[],"sources":["../../src/toggle-group/toggle-group-root.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"toggle-group-root.d.mts","names":[],"sources":["../../src/toggle-group/toggle-group-root.tsx"],"mappings":";;;;;iBA6BiB,sCAAsC;;WAE5C;;WAEA;;;;;;iBAOM;;;;;;WAMN;;WAEA;;WAEA;;WAEA,aAAa;;UAGd,iCAAiC,KACzC;;;;;;EAgBA,cAAc;;;;;;EAMd;;;;;;EAMA;;;;;;;;EAQA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;iBASnC,iCAAiC;;;;;;EAMhD;;;;;EAKA;;;;;;EAMA;;;;;;;;;EASA,oBAAoB,uBAAuB;;;;;EAK3C;;;;;;;;iBASe,kCAAkC;;EAEjD;;EAEA;;;;;;EAMA;;;;;;;;EAQA;;EAEA,oBAAoB,4BAA4B;;;;;;;YAQtC,uBAAuB,2BAA2B;;;;;;;;;;;;wBAoC9C,gBAAgB,OAAO,uCAAoB,IAAA;yBAA3C"}
|
|
@@ -1,20 +1,21 @@
|
|
|
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
4
|
import { useToolbarContext } from "../internal/toolbar-context.mjs";
|
|
5
5
|
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
6
6
|
import { useRender } from "../internal/use-render.mjs";
|
|
7
7
|
import { transitionTypes } from "../internal/transition-types.mjs";
|
|
8
8
|
import { useLatest } from "../internal/use-latest.mjs";
|
|
9
|
-
import { useControllableAction } from "../internal/use-controllable-action.mjs";
|
|
9
|
+
import { useControllableAction } from "../internal/action/use-controllable-action.mjs";
|
|
10
10
|
import { ToggleGroupContext } from "./toggle-group-context.mjs";
|
|
11
11
|
import { compareDocumentOrder } from "../internal/dom-order.mjs";
|
|
12
|
+
import { useMountFixed } from "../internal/use-mount-fixed.mjs";
|
|
12
13
|
import { EMPTY_SET, applyPatch, arraysEqual, sortByOrder } from "../internal/value-set.mjs";
|
|
13
14
|
import { useItemOrder } from "../internal/use-item-order.mjs";
|
|
14
15
|
import { useNativeFocusgroup } from "../internal/use-native-focusgroup.mjs";
|
|
15
16
|
import { useRovingFocus } from "../internal/use-roving-focus.mjs";
|
|
16
17
|
import { useValueSet } from "../internal/use-value-set.mjs";
|
|
17
|
-
import { useCallback, useMemo, useRef
|
|
18
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
18
19
|
import { jsx } from "react/jsx-runtime";
|
|
19
20
|
//#region src/toggle-group/toggle-group-root.tsx
|
|
20
21
|
const isDev = process.env.NODE_ENV !== "production";
|
|
@@ -47,8 +48,7 @@ function ToggleGroupRoot(props) {
|
|
|
47
48
|
const orientation = toolbar?.orientation ?? orientationProp ?? "horizontal";
|
|
48
49
|
const loop = loopProp ?? true;
|
|
49
50
|
const flag = !inToolbar && focusgroupProp === true;
|
|
50
|
-
const
|
|
51
|
-
useDevWarning(mountExclusive !== exclusive, isDev && "ToggleGroup.Root: `exclusive` changed after mount. Switching between exclusive and multiple mode is not supported; the group keeps the mode it mounted with.");
|
|
51
|
+
const mountExclusive = useMountFixed(exclusive, isDev && "ToggleGroup.Root: `exclusive` changed after mount. Switching between exclusive and multiple mode is not supported; the group keeps the mode it mounted with.");
|
|
52
52
|
const controlledSet = useValueSet(value);
|
|
53
53
|
const defaultSet = useValueSet(defaultValue);
|
|
54
54
|
const registry = useRef(/* @__PURE__ */ new Map());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group-root.mjs","names":[],"sources":["../../src/toggle-group/toggle-group-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { compareDocumentOrder } from \"../internal/dom-order.js\";\nimport { useToolbarContext } from \"../internal/toolbar-context.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ActionDetails, ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useItemOrder } from \"../internal/use-item-order.js\";\nimport type { ItemLayout } from \"../internal/use-item-order.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useNativeFocusgroup } from \"../internal/use-native-focusgroup.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useRovingFocus } from \"../internal/use-roving-focus.js\";\nimport { useValueSet } from \"../internal/use-value-set.js\";\nimport { applyPatch, EMPTY_SET, arraysEqual, sortByOrder } from \"../internal/value-set.js\";\nimport type { SetPatch, ValueSet } from \"../internal/value-set.js\";\nimport { ToggleGroupContext } from \"./toggle-group-context.js\";\nimport type { ToggleGroupContextValue, ToggleGroupOrientation } from \"./toggle-group-context.js\";\n\nexport type { ToggleGroupOrientation } from \"./toggle-group-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed as the second argument of `valueChangeAction`, in both modes. */\nexport interface ToggleGroupValueChangeDetails extends ActionDetails {\n /** Values this dispatch pressed (document order of their Items). Exclusive mode: `[next]` or `[]`. */\n readonly added: readonly string[];\n /** Values this dispatch released. Exclusive mode: `[previous]` or `[]`. */\n readonly removed: readonly string[];\n}\n\n/**\n * State of `ToggleGroup.Root`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ToggleGroupRootState {\n /**\n * Optimistic pressed values in document order of the Items (exclusive mode: `[value]` or `[]`,\n * so one state shape serves both modes). The server render and the first client render use the\n * value's own order. Content rendered from it must not suspend.\n */\n readonly value: readonly string[];\n /** An action dispatched through this group is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n /** The effective orientation: the Toolbar's when inside one. */\n readonly orientation: ToggleGroupOrientation;\n}\n\ninterface ToggleGroupRootBaseProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"role\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onPointerDown\"\n | \"defaultValue\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Axis of the arrow keys and `data-orientation`. Ignored inside a Toolbar (dev warning).\n *\n * @defaultValue `\"horizontal\"`\n */\n orientation?: ToggleGroupOrientation;\n /**\n * Whether arrows wrap from the last Item to the first. Ignored inside a Toolbar (dev warning).\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /**\n * Disables every Item (native `disabled`).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Render `focusgroup=\"toolbar …\"` and, where the browser implements it, let the browser move\n * focus between the Items. Chromium 150+ only; elsewhere the JS path stays active. Ignored\n * inside a Toolbar (a nested focusgroup would split the Toolbar's sequence; dev warning).\n *\n * @defaultValue `false`\n */\n experimental_focusgroup?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToggleGroupRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToggleGroupRootState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ToggleGroupRootState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ToggleGroupRootState>;\n}\n\n/**\n * Props of `ToggleGroup.Root` in multiple mode (the default): any number of Items pressed, `value`\n * is a `string[]`.\n *\n * @see https://ui.funstack.work/components/toggle-group\n */\nexport interface ToggleGroupMultipleProps extends ToggleGroupRootBaseProps {\n /**\n * `true` switches to exclusive mode (at most one Item pressed; see `ToggleGroupExclusiveProps`).\n *\n * @defaultValue `false`\n */\n exclusive?: false;\n /**\n * Controlled pressed values. `[]` presses nothing; `undefined` means uncontrolled. Order is not\n * significant; duplicates ignored.\n */\n value?: string[];\n /**\n * Initial pressed values in uncontrolled mode.\n *\n * @defaultValue `[]`\n */\n defaultValue?: string[];\n /**\n * Runs inside the Root's transition whenever the set of pressed Items changes. Sync or async (a\n * Server Function may be passed directly); rejections reach the nearest Error Boundary and roll\n * the change back. `next` is the whole set as a fresh array in document order;\n * `details.added` / `details.removed` say what changed. A `setState` after your own `await` is\n * not a Transition update; wrap it in `startTransition`. Prefer a functional update keyed by\n * `added` / `removed` when controlled.\n */\n valueChangeAction?: ChangeAction<string[], ToggleGroupValueChangeDetails>;\n /**\n * Exclusive mode only: a type error here (TypeScript's union excess-property check would let it\n * through otherwise).\n */\n deselectable?: never;\n}\n\n/**\n * Props of `ToggleGroup.Root` in exclusive mode (`exclusive`): at most one Item pressed, `value` is\n * `string | null`.\n *\n * @see https://ui.funstack.work/components/toggle-group\n */\nexport interface ToggleGroupExclusiveProps extends ToggleGroupRootBaseProps {\n /** At most one Item is pressed; `value` is `string | null`. */\n exclusive: true;\n /** Controlled pressed value. `null` presses nothing; `undefined` means uncontrolled. */\n value?: string | null;\n /**\n * Initial pressed value in uncontrolled mode.\n *\n * @defaultValue `null`\n */\n defaultValue?: string | null;\n /**\n * Whether pressing the pressed Item releases it (`next === null`). With `false` that press is a\n * no-op and dispatches nothing; `value` stays `string | null` because the group may start with\n * nothing pressed, but the action is then never called with `null`.\n *\n * @defaultValue `true`\n */\n deselectable?: boolean;\n /** See {@link ToggleGroupMultipleProps.valueChangeAction}; `next` is the pressed value or `null`. */\n valueChangeAction?: ChangeAction<string | null, ToggleGroupValueChangeDetails>;\n}\n\n/**\n * Props of `ToggleGroup.Root`, discriminated on `exclusive`.\n *\n * @see https://ui.funstack.work/components/toggle-group\n */\nexport type ToggleGroupRootProps = ToggleGroupMultipleProps | ToggleGroupExclusiveProps;\n\ntype GroupValue = string[] | string | null;\n\n/** Both variants as one shape, for the implementation. */\ninterface InternalProps extends ToggleGroupRootBaseProps {\n exclusive?: boolean;\n value?: GroupValue;\n defaultValue?: GroupValue;\n deselectable?: boolean;\n valueChangeAction?: ChangeAction<GroupValue, ToggleGroupValueChangeDetails>;\n}\n\n/** Standalone entry (design 6.2): the first pressed item, else the first item (radio-like). */\nfunction pressedFirst(items: readonly HTMLElement[]): HTMLElement | undefined {\n return items.find((el) => el.getAttribute(\"aria-pressed\") === \"true\") ?? items[0];\n}\n\n/** The Items' document order and their disabled values, as of the Root's last commit. */\ninterface ToggleGroupLayout extends ItemLayout {\n readonly disabled: readonly string[];\n}\n\nconst NO_LAYOUT: ToggleGroupLayout = { order: [], disabled: [] };\n\n/**\n * `<div role=\"group\">` that owns the pressed set, the transition and, when standalone, the roving\n * focus over its Items (design/components/toggle-group.md 16.2). Inside a `Toolbar.Root` it runs\n * no engine of its own: its Items are members of the Toolbar's sequence.\n *\n * Owned keys (conventions 1.2): `role`, `data-orientation`, `data-pending`, `data-disabled`;\n * standalone also `onKeyDown`, `onFocus`, `onBlur`, `onPointerDown` and, with the flag,\n * `focusgroup`.\n *\n * @see https://ui.funstack.work/components/toggle-group\n */\nexport function ToggleGroupRoot(props: ToggleGroupRootProps) {\n const {\n exclusive = false,\n value,\n defaultValue,\n valueChangeAction,\n deselectable = true,\n orientation: orientationProp,\n loop: loopProp,\n disabled = false,\n experimental_focusgroup: focusgroupProp,\n className,\n style,\n children,\n render,\n ...rest\n } = props as InternalProps;\n\n const toolbar = useToolbarContext();\n const inToolbar = toolbar !== null;\n useDevWarning(\n inToolbar && orientationProp !== undefined,\n isDev &&\n \"ToggleGroup.Root: `orientation` is ignored inside a Toolbar.Root; the group follows the \" +\n \"Toolbar's orientation.\",\n );\n useDevWarning(\n inToolbar && loopProp !== undefined,\n isDev &&\n \"ToggleGroup.Root: `loop` is ignored inside a Toolbar.Root; the Toolbar's `loop` applies.\",\n );\n useDevWarning(\n inToolbar && focusgroupProp === true,\n isDev &&\n \"ToggleGroup.Root: `experimental_focusgroup` is ignored inside a Toolbar.Root. A nested \" +\n \"focusgroup would split the Toolbar's single Tab stop; set the flag on the Toolbar.Root.\",\n );\n const orientation: ToggleGroupOrientation =\n toolbar?.orientation ?? orientationProp ?? \"horizontal\";\n const loop = loopProp ?? true;\n const flag = !inToolbar && focusgroupProp === true;\n\n // The mode is fixed at mount (design 3.1).\n const [mountExclusive] = useState(exclusive);\n useDevWarning(\n mountExclusive !== exclusive,\n isDev &&\n \"ToggleGroup.Root: `exclusive` changed after mount. Switching between exclusive and \" +\n \"multiple mode is not supported; the group keeps the mode it mounted with.\",\n );\n\n const controlledSet = useValueSet(value);\n const defaultSet = useValueSet(defaultValue);\n\n // Item registration (design 16.2): element → value, written from the Items' callback refs.\n const registry = useRef(new Map<HTMLElement, string>());\n const registerItem = useCallback((element: HTMLElement, itemValue: string) => {\n registry.current.set(element, itemValue);\n return () => {\n registry.current.delete(element);\n };\n }, []);\n const sortedItems = (): [HTMLElement, string][] =>\n [...registry.current].sort(([a], [b]) => compareDocumentOrder(a, b));\n /** Sorts by the Items' current document order. Reads the DOM: handlers and effects only. */\n const sortByDocument = (values: Iterable<string>): string[] =>\n sortByOrder(\n values,\n sortedItems().map(([, v]) => v),\n );\n\n const { optimistic, committed, pending, dispatch } = useControllableAction<\n ValueSet,\n ToggleGroupValueChangeDetails\n >({\n controlled: controlledSet,\n defaultValue: defaultSet,\n initialValue: EMPTY_SET,\n action:\n valueChangeAction &&\n ((next, details) =>\n valueChangeAction(mountExclusive ? ([...next][0] ?? null) : sortByDocument(next), details)),\n transitionTypes: (_next, _prev, details) => [\n ...transitionTypes(\"toggle-group\"),\n ...(details.added.length > 0 ? [\"fsui-toggle-group-press\"] : []),\n ...(details.removed.length > 0 ? [\"fsui-toggle-group-release\"] : []),\n ],\n // Multiple: a patch, re-based on the committed set; it is also how the uncontrolled commit is\n // folded over the resolved dispatches (#150). Exclusive is single-valued: no reducer, so the\n // optimistic value is `next` and the latest dispatch commits it, like Tabs.\n reducer: mountExclusive ? undefined : (prev, _next, details) => applyPatch(prev, details),\n warn: { component: \"ToggleGroup.Root\", prop: \"value\" },\n });\n\n // Read by the stable `toggle`: a handler only runs against the committed UI.\n const latest = useLatest({ optimistic, exclusive: mountExclusive, deselectable });\n const toggle = useCallback(\n (itemValue: string, event: Event) => {\n const { optimistic, exclusive, deselectable } = latest.current;\n let patch: SetPatch;\n if (optimistic.has(itemValue)) {\n // Exclusive and not deselectable: pressing the pressed Item is a no-op (design 5.2).\n if (exclusive && !deselectable) return;\n patch = { added: [], removed: [itemValue] };\n } else {\n patch = { added: [itemValue], removed: exclusive ? [...optimistic] : [] };\n }\n dispatch(applyPatch(optimistic, patch), createActionDetails(event, patch));\n },\n [dispatch, latest],\n );\n\n // `state.value` is in document order; `focusgroupstart` also renders from which values have a\n // disabled Item.\n const { layout, renderedValue } = useItemOrder<ToggleGroupLayout>({\n optimistic,\n initial: NO_LAYOUT,\n read: () => {\n const items = sortedItems();\n return {\n order: items.map(([, v]) => v),\n disabled: items.filter(([el]) => el.matches(\":disabled\")).map(([, v]) => v),\n };\n },\n changed: (prev, next) =>\n flag && (!arraysEqual(next.order, prev.order) || !arraysEqual(next.disabled, prev.disabled)),\n duplicateMessage:\n isDev &&\n ((duplicate) =>\n `ToggleGroup.Item: two Items share the value \"${duplicate}\" in one ToggleGroup.Root. ` +\n \"Item values must be unique; both follow the same pressed state.\"),\n });\n\n const native = useNativeFocusgroup(flag);\n\n const focusgroupStartValue =\n flag && !disabled\n ? (renderedValue.find(\n (v) =>\n (layout.order.length === 0 || layout.order.includes(v)) && !layout.disabled.includes(v),\n ) ?? null)\n : null;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const roving = useRovingFocus(rootRef, {\n enabled: !inToolbar,\n orientation,\n loop,\n native,\n entry: pressedFirst,\n memory: false,\n });\n\n const context = useMemo<ToggleGroupContextValue>(\n () => ({\n optimistic,\n committed,\n pending,\n disabled,\n orientation,\n focusgroupStartValue,\n toggle,\n registerItem,\n }),\n [\n optimistic,\n committed,\n pending,\n disabled,\n orientation,\n focusgroupStartValue,\n toggle,\n registerItem,\n ],\n );\n\n const state: ToggleGroupRootState = { value: renderedValue, pending, disabled, orientation };\n\n const focusgroup = flag\n ? `toolbar ${orientation === \"vertical\" ? \"block\" : \"inline\"} ${loop ? \"wrap\" : \"nowrap\"} nomemory`\n : undefined;\n\n const element = useRender<ComponentPropsWithRef<\"div\">, ToggleGroupRootState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n role: \"group\",\n \"data-orientation\": orientation,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n // Inside a Toolbar the group has no engine: the keys are not owned there.\n ...(!inToolbar && roving),\n ...(focusgroup !== undefined && { focusgroup }),\n },\n ref: rootRef,\n });\n\n return <ToggleGroupContext value={context}>{element}</ToggleGroupContext>;\n}\n\nToggleGroupRoot.displayName = \"ToggleGroupRoot\";\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"toggle-group-root.mjs","names":[],"sources":["../../src/toggle-group/toggle-group-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, 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 { useToolbarContext } from \"../internal/toolbar-context.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ActionDetails, ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/action/use-controllable-action.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useMountFixed } from \"../internal/use-mount-fixed.js\";\nimport { useItemOrder } from \"../internal/use-item-order.js\";\nimport type { ItemLayout } from \"../internal/use-item-order.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useNativeFocusgroup } from \"../internal/use-native-focusgroup.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useRovingFocus } from \"../internal/use-roving-focus.js\";\nimport { useValueSet } from \"../internal/use-value-set.js\";\nimport { applyPatch, EMPTY_SET, arraysEqual, sortByOrder } from \"../internal/value-set.js\";\nimport type { SetPatch, ValueSet } from \"../internal/value-set.js\";\nimport { ToggleGroupContext } from \"./toggle-group-context.js\";\nimport type { ToggleGroupContextValue, ToggleGroupOrientation } from \"./toggle-group-context.js\";\n\nexport type { ToggleGroupOrientation } from \"./toggle-group-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed as the second argument of `valueChangeAction`, in both modes. */\nexport interface ToggleGroupValueChangeDetails extends ActionDetails {\n /** Values this dispatch pressed (document order of their Items). Exclusive mode: `[next]` or `[]`. */\n readonly added: readonly string[];\n /** Values this dispatch released. Exclusive mode: `[previous]` or `[]`. */\n readonly removed: readonly string[];\n}\n\n/**\n * State of `ToggleGroup.Root`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ToggleGroupRootState {\n /**\n * Optimistic pressed values in document order of the Items (exclusive mode: `[value]` or `[]`,\n * so one state shape serves both modes). The server render and the first client render use the\n * value's own order. Content rendered from it must not suspend.\n */\n readonly value: readonly string[];\n /** An action dispatched through this group is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n /** The effective orientation: the Toolbar's when inside one. */\n readonly orientation: ToggleGroupOrientation;\n}\n\ninterface ToggleGroupRootBaseProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"role\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onPointerDown\"\n | \"defaultValue\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Axis of the arrow keys and `data-orientation`. Ignored inside a Toolbar (dev warning).\n *\n * @defaultValue `\"horizontal\"`\n */\n orientation?: ToggleGroupOrientation;\n /**\n * Whether arrows wrap from the last Item to the first. Ignored inside a Toolbar (dev warning).\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /**\n * Disables every Item (native `disabled`).\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Render `focusgroup=\"toolbar …\"` and, where the browser implements it, let the browser move\n * focus between the Items. Chromium 150+ only; elsewhere the JS path stays active. Ignored\n * inside a Toolbar (a nested focusgroup would split the Toolbar's sequence; dev warning).\n *\n * @defaultValue `false`\n */\n experimental_focusgroup?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToggleGroupRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToggleGroupRootState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ToggleGroupRootState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ToggleGroupRootState>;\n}\n\n/**\n * Props of `ToggleGroup.Root` in multiple mode (the default): any number of Items pressed, `value`\n * is a `string[]`.\n *\n * @see https://ui.funstack.work/components/toggle-group\n */\nexport interface ToggleGroupMultipleProps extends ToggleGroupRootBaseProps {\n /**\n * `true` switches to exclusive mode (at most one Item pressed; see `ToggleGroupExclusiveProps`).\n *\n * @defaultValue `false`\n */\n exclusive?: false;\n /**\n * Controlled pressed values. `[]` presses nothing; `undefined` means uncontrolled. Order is not\n * significant; duplicates ignored.\n */\n value?: string[];\n /**\n * Initial pressed values in uncontrolled mode.\n *\n * @defaultValue `[]`\n */\n defaultValue?: string[];\n /**\n * Runs inside the Root's transition whenever the set of pressed Items changes. Sync or async (a\n * Server Function may be passed directly); rejections reach the nearest Error Boundary and roll\n * the change back. `next` is the whole set as a fresh array in document order;\n * `details.added` / `details.removed` say what changed. A `setState` after your own `await` is\n * not a Transition update; wrap it in `startTransition`. Prefer a functional update keyed by\n * `added` / `removed` when controlled.\n */\n valueChangeAction?: ChangeAction<string[], ToggleGroupValueChangeDetails>;\n /**\n * Exclusive mode only: a type error here (TypeScript's union excess-property check would let it\n * through otherwise).\n */\n deselectable?: never;\n}\n\n/**\n * Props of `ToggleGroup.Root` in exclusive mode (`exclusive`): at most one Item pressed, `value` is\n * `string | null`.\n *\n * @see https://ui.funstack.work/components/toggle-group\n */\nexport interface ToggleGroupExclusiveProps extends ToggleGroupRootBaseProps {\n /** At most one Item is pressed; `value` is `string | null`. */\n exclusive: true;\n /** Controlled pressed value. `null` presses nothing; `undefined` means uncontrolled. */\n value?: string | null;\n /**\n * Initial pressed value in uncontrolled mode.\n *\n * @defaultValue `null`\n */\n defaultValue?: string | null;\n /**\n * Whether pressing the pressed Item releases it (`next === null`). With `false` that press is a\n * no-op and dispatches nothing; `value` stays `string | null` because the group may start with\n * nothing pressed, but the action is then never called with `null`.\n *\n * @defaultValue `true`\n */\n deselectable?: boolean;\n /** See {@link ToggleGroupMultipleProps.valueChangeAction}; `next` is the pressed value or `null`. */\n valueChangeAction?: ChangeAction<string | null, ToggleGroupValueChangeDetails>;\n}\n\n/**\n * Props of `ToggleGroup.Root`, discriminated on `exclusive`.\n *\n * @see https://ui.funstack.work/components/toggle-group\n */\nexport type ToggleGroupRootProps = ToggleGroupMultipleProps | ToggleGroupExclusiveProps;\n\ntype GroupValue = string[] | string | null;\n\n/** Both variants as one shape, for the implementation. */\ninterface InternalProps extends ToggleGroupRootBaseProps {\n exclusive?: boolean;\n value?: GroupValue;\n defaultValue?: GroupValue;\n deselectable?: boolean;\n valueChangeAction?: ChangeAction<GroupValue, ToggleGroupValueChangeDetails>;\n}\n\n/** Standalone entry (design 6.2): the first pressed item, else the first item (radio-like). */\nfunction pressedFirst(items: readonly HTMLElement[]): HTMLElement | undefined {\n return items.find((el) => el.getAttribute(\"aria-pressed\") === \"true\") ?? items[0];\n}\n\n/** The Items' document order and their disabled values, as of the Root's last commit. */\ninterface ToggleGroupLayout extends ItemLayout {\n readonly disabled: readonly string[];\n}\n\nconst NO_LAYOUT: ToggleGroupLayout = { order: [], disabled: [] };\n\n/**\n * `<div role=\"group\">` that owns the pressed set, the transition and, when standalone, the roving\n * focus over its Items (design/components/toggle-group.md 16.2). Inside a `Toolbar.Root` it runs\n * no engine of its own: its Items are members of the Toolbar's sequence.\n *\n * Owned keys (conventions 1.2): `role`, `data-orientation`, `data-pending`, `data-disabled`;\n * standalone also `onKeyDown`, `onFocus`, `onBlur`, `onPointerDown` and, with the flag,\n * `focusgroup`.\n *\n * @see https://ui.funstack.work/components/toggle-group\n */\nexport function ToggleGroupRoot(props: ToggleGroupRootProps) {\n const {\n exclusive = false,\n value,\n defaultValue,\n valueChangeAction,\n deselectable = true,\n orientation: orientationProp,\n loop: loopProp,\n disabled = false,\n experimental_focusgroup: focusgroupProp,\n className,\n style,\n children,\n render,\n ...rest\n } = props as InternalProps;\n\n const toolbar = useToolbarContext();\n const inToolbar = toolbar !== null;\n useDevWarning(\n inToolbar && orientationProp !== undefined,\n isDev &&\n \"ToggleGroup.Root: `orientation` is ignored inside a Toolbar.Root; the group follows the \" +\n \"Toolbar's orientation.\",\n );\n useDevWarning(\n inToolbar && loopProp !== undefined,\n isDev &&\n \"ToggleGroup.Root: `loop` is ignored inside a Toolbar.Root; the Toolbar's `loop` applies.\",\n );\n useDevWarning(\n inToolbar && focusgroupProp === true,\n isDev &&\n \"ToggleGroup.Root: `experimental_focusgroup` is ignored inside a Toolbar.Root. A nested \" +\n \"focusgroup would split the Toolbar's single Tab stop; set the flag on the Toolbar.Root.\",\n );\n const orientation: ToggleGroupOrientation =\n toolbar?.orientation ?? orientationProp ?? \"horizontal\";\n const loop = loopProp ?? true;\n const flag = !inToolbar && focusgroupProp === true;\n\n // The mode is fixed at mount (design 3.1).\n const mountExclusive = useMountFixed(\n exclusive,\n isDev &&\n \"ToggleGroup.Root: `exclusive` changed after mount. Switching between exclusive and \" +\n \"multiple mode is not supported; the group keeps the mode it mounted with.\",\n );\n\n const controlledSet = useValueSet(value);\n const defaultSet = useValueSet(defaultValue);\n\n // Item registration (design 16.2): element → value, written from the Items' callback refs.\n const registry = useRef(new Map<HTMLElement, string>());\n const registerItem = useCallback((element: HTMLElement, itemValue: string) => {\n registry.current.set(element, itemValue);\n return () => {\n registry.current.delete(element);\n };\n }, []);\n const sortedItems = (): [HTMLElement, string][] =>\n [...registry.current].sort(([a], [b]) => compareDocumentOrder(a, b));\n /** Sorts by the Items' current document order. Reads the DOM: handlers and effects only. */\n const sortByDocument = (values: Iterable<string>): string[] =>\n sortByOrder(\n values,\n sortedItems().map(([, v]) => v),\n );\n\n const { optimistic, committed, pending, dispatch } = useControllableAction<\n ValueSet,\n ToggleGroupValueChangeDetails\n >({\n controlled: controlledSet,\n defaultValue: defaultSet,\n initialValue: EMPTY_SET,\n action:\n valueChangeAction &&\n ((next, details) =>\n valueChangeAction(mountExclusive ? ([...next][0] ?? null) : sortByDocument(next), details)),\n transitionTypes: (_next, _prev, details) => [\n ...transitionTypes(\"toggle-group\"),\n ...(details.added.length > 0 ? [\"fsui-toggle-group-press\"] : []),\n ...(details.removed.length > 0 ? [\"fsui-toggle-group-release\"] : []),\n ],\n // Multiple: a patch, re-based on the committed set; it is also how the uncontrolled commit is\n // folded over the resolved dispatches (#150). Exclusive is single-valued: no reducer, so the\n // optimistic value is `next` and the latest dispatch commits it, like Tabs.\n reducer: mountExclusive ? undefined : (prev, _next, details) => applyPatch(prev, details),\n warn: { component: \"ToggleGroup.Root\", prop: \"value\" },\n });\n\n // Read by the stable `toggle`: a handler only runs against the committed UI.\n const latest = useLatest({ optimistic, exclusive: mountExclusive, deselectable });\n const toggle = useCallback(\n (itemValue: string, event: Event) => {\n const { optimistic, exclusive, deselectable } = latest.current;\n let patch: SetPatch;\n if (optimistic.has(itemValue)) {\n // Exclusive and not deselectable: pressing the pressed Item is a no-op (design 5.2).\n if (exclusive && !deselectable) return;\n patch = { added: [], removed: [itemValue] };\n } else {\n patch = { added: [itemValue], removed: exclusive ? [...optimistic] : [] };\n }\n dispatch(applyPatch(optimistic, patch), createActionDetails(event, patch));\n },\n [dispatch, latest],\n );\n\n // `state.value` is in document order; `focusgroupstart` also renders from which values have a\n // disabled Item.\n const { layout, renderedValue } = useItemOrder<ToggleGroupLayout>({\n optimistic,\n initial: NO_LAYOUT,\n read: () => {\n const items = sortedItems();\n return {\n order: items.map(([, v]) => v),\n disabled: items.filter(([el]) => el.matches(\":disabled\")).map(([, v]) => v),\n };\n },\n changed: (prev, next) =>\n flag && (!arraysEqual(next.order, prev.order) || !arraysEqual(next.disabled, prev.disabled)),\n duplicateMessage:\n isDev &&\n ((duplicate) =>\n `ToggleGroup.Item: two Items share the value \"${duplicate}\" in one ToggleGroup.Root. ` +\n \"Item values must be unique; both follow the same pressed state.\"),\n });\n\n const native = useNativeFocusgroup(flag);\n\n const focusgroupStartValue =\n flag && !disabled\n ? (renderedValue.find(\n (v) =>\n (layout.order.length === 0 || layout.order.includes(v)) && !layout.disabled.includes(v),\n ) ?? null)\n : null;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const roving = useRovingFocus(rootRef, {\n enabled: !inToolbar,\n orientation,\n loop,\n native,\n entry: pressedFirst,\n memory: false,\n });\n\n const context = useMemo<ToggleGroupContextValue>(\n () => ({\n optimistic,\n committed,\n pending,\n disabled,\n orientation,\n focusgroupStartValue,\n toggle,\n registerItem,\n }),\n [\n optimistic,\n committed,\n pending,\n disabled,\n orientation,\n focusgroupStartValue,\n toggle,\n registerItem,\n ],\n );\n\n const state: ToggleGroupRootState = { value: renderedValue, pending, disabled, orientation };\n\n const focusgroup = flag\n ? `toolbar ${orientation === \"vertical\" ? \"block\" : \"inline\"} ${loop ? \"wrap\" : \"nowrap\"} nomemory`\n : undefined;\n\n const element = useRender<ComponentPropsWithRef<\"div\">, ToggleGroupRootState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n role: \"group\",\n \"data-orientation\": orientation,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n // Inside a Toolbar the group has no engine: the keys are not owned there.\n ...(!inToolbar && roving),\n ...(focusgroup !== undefined && { focusgroup }),\n },\n ref: rootRef,\n });\n\n return <ToggleGroupContext value={context}>{element}</ToggleGroupContext>;\n}\n\nToggleGroupRoot.displayName = \"ToggleGroupRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAqKvC,SAAS,aAAa,OAAwD;CAC5E,OAAO,MAAM,MAAM,OAAO,GAAG,aAAa,cAAc,MAAM,MAAM,KAAK,MAAM;AACjF;AAOA,MAAM,YAA+B;CAAE,OAAO,CAAC;CAAG,UAAU,CAAC;AAAE;;;;;;;;;;;;AAa/D,SAAgB,gBAAgB,OAA6B;CAC3D,MAAM,EACJ,YAAY,OACZ,OACA,cACA,mBACA,eAAe,MACf,aAAa,iBACb,MAAM,UACN,WAAW,OACX,yBAAyB,gBACzB,WACA,OACA,UACA,QACA,GAAG,SACD;CAEJ,MAAM,UAAU,kBAAkB;CAClC,MAAM,YAAY,YAAY;CAC9B,cACE,aAAa,oBAAoB,KAAA,GACjC,SACE,gHAEJ;CACA,cACE,aAAa,aAAa,KAAA,GAC1B,SACE,0FACJ;CACA,cACE,aAAa,mBAAmB,MAChC,SACE,gLAEJ;CACA,MAAM,cACJ,SAAS,eAAe,mBAAmB;CAC7C,MAAM,OAAO,YAAY;CACzB,MAAM,OAAO,CAAC,aAAa,mBAAmB;CAG9C,MAAM,iBAAiB,cACrB,WACA,SACE,8JAEJ;CAEA,MAAM,gBAAgB,YAAY,KAAK;CACvC,MAAM,aAAa,YAAY,YAAY;CAG3C,MAAM,WAAW,uBAAO,IAAI,IAAyB,CAAC;CACtD,MAAM,eAAe,aAAa,SAAsB,cAAsB;EAC5E,SAAS,QAAQ,IAAI,SAAS,SAAS;EACvC,aAAa;GACX,SAAS,QAAQ,OAAO,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CACL,MAAM,oBACJ,CAAC,GAAG,SAAS,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,qBAAqB,GAAG,CAAC,CAAC;;CAErE,MAAM,kBAAkB,WACtB,YACE,QACA,YAAY,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,CAChC;CAEF,MAAM,EAAE,YAAY,WAAW,SAAS,aAAa,sBAGnD;EACA,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QACE,uBACE,MAAM,YACN,kBAAkB,iBAAkB,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,OAAQ,eAAe,IAAI,GAAG,OAAO;EAC7F,kBAAkB,OAAO,OAAO,YAAY;GAC1C,GAAG,gBAAgB,cAAc;GACjC,GAAI,QAAQ,MAAM,SAAS,IAAI,CAAC,yBAAyB,IAAI,CAAC;GAC9D,GAAI,QAAQ,QAAQ,SAAS,IAAI,CAAC,2BAA2B,IAAI,CAAC;EACpE;EAIA,SAAS,iBAAiB,KAAA,KAAa,MAAM,OAAO,YAAY,WAAW,MAAM,OAAO;EACxF,MAAM;GAAE,WAAW;GAAoB,MAAM;EAAQ;CACvD,CAAC;CAGD,MAAM,SAAS,UAAU;EAAE;EAAY,WAAW;EAAgB;CAAa,CAAC;CAChF,MAAM,SAAS,aACZ,WAAmB,UAAiB;EACnC,MAAM,EAAE,YAAY,WAAW,iBAAiB,OAAO;EACvD,IAAI;EACJ,IAAI,WAAW,IAAI,SAAS,GAAG;GAE7B,IAAI,aAAa,CAAC,cAAc;GAChC,QAAQ;IAAE,OAAO,CAAC;IAAG,SAAS,CAAC,SAAS;GAAE;EAC5C,OACE,QAAQ;GAAE,OAAO,CAAC,SAAS;GAAG,SAAS,YAAY,CAAC,GAAG,UAAU,IAAI,CAAC;EAAE;EAE1E,SAAS,WAAW,YAAY,KAAK,GAAG,oBAAoB,OAAO,KAAK,CAAC;CAC3E,GACA,CAAC,UAAU,MAAM,CACnB;CAIA,MAAM,EAAE,QAAQ,kBAAkB,aAAgC;EAChE;EACA,SAAS;EACT,YAAY;GACV,MAAM,QAAQ,YAAY;GAC1B,OAAO;IACL,OAAO,MAAM,KAAK,GAAG,OAAO,CAAC;IAC7B,UAAU,MAAM,QAAQ,CAAC,QAAQ,GAAG,QAAQ,WAAW,CAAC,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC;GAC5E;EACF;EACA,UAAU,MAAM,SACd,SAAS,CAAC,YAAY,KAAK,OAAO,KAAK,KAAK,KAAK,CAAC,YAAY,KAAK,UAAU,KAAK,QAAQ;EAC5F,kBACE,WACE,cACA,gDAAgD,UAAU;CAEhE,CAAC;CAED,MAAM,SAAS,oBAAoB,IAAI;CAEvC,MAAM,uBACJ,QAAQ,CAAC,WACJ,cAAc,MACZ,OACE,OAAO,MAAM,WAAW,KAAK,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,SAAS,SAAS,CAAC,CAC1F,KAAK,OACL;CAEN,MAAM,UAAU,OAA2B,IAAI;CAC/C,MAAM,SAAS,eAAe,SAAS;EACrC,SAAS,CAAC;EACV;EACA;EACA;EACA,OAAO;EACP,QAAQ;CACV,CAAC;CAED,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,QAA8B;EAAE,OAAO;EAAe;EAAS;EAAU;CAAY;CAE3F,MAAM,aAAa,OACf,WAAW,gBAAgB,aAAa,UAAU,SAAS,GAAG,OAAO,SAAS,SAAS,aACvF,KAAA;CAEJ,MAAM,UAAU,UAA8D;EAC5E,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,MAAM;GACN,oBAAoB;GACpB,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;GAElC,GAAI,CAAC,aAAa;GAClB,GAAI,eAAe,KAAA,KAAa,EAAE,WAAW;EAC/C;EACA,KAAK;CACP,CAAC;CAED,OAAO,oBAAC,oBAAD;EAAoB,OAAO;EAAU,UAAA;CAA4B,CAAA;AAC1E;AAEA,gBAAgB,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnchorAlign, AnchorSide } from "../internal/anchor-position.mjs";
|
|
1
|
+
import { AnchorAlign, AnchorSide } from "../internal/overlay/anchor-position.mjs";
|
|
2
2
|
//#region src/tooltip/tooltip-context.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). While
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-context.mjs","names":[],"sources":["../../src/tooltip/tooltip-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\n\n/**\n * `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). While\n * shown, the state carries the resolved physical side.\n */\nexport type TooltipSide = AnchorSide;\n/**\n * Alignment of the Popup along its side: inline-relative on a top / bottom side, the top / bottom\n * edges on the others.\n */\nexport type TooltipAlign = AnchorAlign;\n\n/** Which accessibility relation the tooltip provides for its trigger (design section 5.1). */\nexport type TooltipProvides = \"description\" | \"name\";\n\nexport interface TooltipContextValue {\n /** Id of the Popup; the Trigger references it through `aria-describedby` / `aria-labelledby`. */\n readonly popupId: string;\n readonly disabled: boolean;\n /** Written onto the Trigger as `interest-delay-start` / `-end` on the native path. */\n readonly delay: number;\n readonly closeDelay: number;\n readonly provides: TooltipProvides;\n /** Trigger and Popup register their elements through callback refs (design 12.2). */\n readonly setTriggerElement: (element: HTMLElement | null) => void;\n readonly setPopupElement: (element: HTMLElement | null) => void;\n /**\n * The Trigger reports whether it renders `interestfor`, so the Root's interaction effect re-runs\n * (and re-detects the native path) when `experimental_interestFor` changes after mount.\n */\n readonly setInterestForRequested: (requested: boolean) => void;\n}\n\nexport const TooltipContext = createContext<TooltipContextValue | null>(null);\n\n/** What `Tooltip.Popup` tells its `Tooltip.Arrow`: the placement it renders (design 12.2). */\nexport interface TooltipPopupContextValue {\n /** The resolved side while shown, else the requested one; `null` with `side={null}`. */\n readonly side: TooltipSide | null;\n readonly align: TooltipAlign;\n}\n\nexport const TooltipPopupContext = createContext<TooltipPopupContextValue | null>(null);\n\nexport function useTooltipContext(part: string): TooltipContextValue {\n const context = use(TooltipContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Tooltip.Root.`);\n }\n return context;\n}\n"],"mappings":";;;AAoCA,MAAa,iBAAiB,cAA0C,IAAI;AAS5E,MAAa,sBAAsB,cAA+C,IAAI;AAEtF,SAAgB,kBAAkB,MAAmC;CACnE,MAAM,UAAU,IAAI,cAAc;CAClC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,yCAAyC;CAEnE,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"tooltip-context.mjs","names":[],"sources":["../../src/tooltip/tooltip-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/overlay/anchor-position.js\";\n\n/**\n * `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). While\n * shown, the state carries the resolved physical side.\n */\nexport type TooltipSide = AnchorSide;\n/**\n * Alignment of the Popup along its side: inline-relative on a top / bottom side, the top / bottom\n * edges on the others.\n */\nexport type TooltipAlign = AnchorAlign;\n\n/** Which accessibility relation the tooltip provides for its trigger (design section 5.1). */\nexport type TooltipProvides = \"description\" | \"name\";\n\nexport interface TooltipContextValue {\n /** Id of the Popup; the Trigger references it through `aria-describedby` / `aria-labelledby`. */\n readonly popupId: string;\n readonly disabled: boolean;\n /** Written onto the Trigger as `interest-delay-start` / `-end` on the native path. */\n readonly delay: number;\n readonly closeDelay: number;\n readonly provides: TooltipProvides;\n /** Trigger and Popup register their elements through callback refs (design 12.2). */\n readonly setTriggerElement: (element: HTMLElement | null) => void;\n readonly setPopupElement: (element: HTMLElement | null) => void;\n /**\n * The Trigger reports whether it renders `interestfor`, so the Root's interaction effect re-runs\n * (and re-detects the native path) when `experimental_interestFor` changes after mount.\n */\n readonly setInterestForRequested: (requested: boolean) => void;\n}\n\nexport const TooltipContext = createContext<TooltipContextValue | null>(null);\n\n/** What `Tooltip.Popup` tells its `Tooltip.Arrow`: the placement it renders (design 12.2). */\nexport interface TooltipPopupContextValue {\n /** The resolved side while shown, else the requested one; `null` with `side={null}`. */\n readonly side: TooltipSide | null;\n readonly align: TooltipAlign;\n}\n\nexport const TooltipPopupContext = createContext<TooltipPopupContextValue | null>(null);\n\nexport function useTooltipContext(part: string): TooltipContextValue {\n const context = use(TooltipContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Tooltip.Root.`);\n }\n return context;\n}\n"],"mappings":";;;AAoCA,MAAa,iBAAiB,cAA0C,IAAI;AAS5E,MAAa,sBAAsB,cAA+C,IAAI;AAEtF,SAAgB,kBAAkB,MAAmC;CACnE,MAAM,UAAU,IAAI,cAAc;CAClC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,yCAAyC;CAEnE,OAAO;AACT"}
|
|
@@ -3,7 +3,7 @@ import { dataAttr } from "../internal/data-attr.mjs";
|
|
|
3
3
|
import { useRender } from "../internal/use-render.mjs";
|
|
4
4
|
import { TooltipPopupContext, useTooltipContext } from "./tooltip-context.mjs";
|
|
5
5
|
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
6
|
-
import { useAnchoredPlacement } from "../internal/use-resolved-placement.mjs";
|
|
6
|
+
import { useAnchoredPlacement } from "../internal/overlay/use-resolved-placement.mjs";
|
|
7
7
|
import { useMemo } from "react";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
//#region src/tooltip/tooltip-popup.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-popup.mjs","names":[],"sources":["../../src/tooltip/tooltip-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useMemo } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useAnchoredPlacement } from \"../internal/use-resolved-placement.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { TooltipPopupContext, useTooltipContext } from \"./tooltip-context.js\";\nimport type { TooltipAlign, TooltipPopupContextValue, TooltipSide } from \"./tooltip-context.js\";\n\nexport type { TooltipAlign, TooltipSide } from \"./tooltip-context.js\";\n\n/**\n * State of `Tooltip.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface TooltipPopupState {\n /** The Root's `disabled`. */\n readonly disabled: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (`\"top\"` / `\"bottom\"` /\n * `\"left\"` / `\"right\"`, after any fallback flip). Otherwise the `side` prop. `null` with\n * `side={null}`.\n */\n readonly side: TooltipSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: TooltipAlign;\n}\n\n/**\n * Props of `Tooltip.Popup`.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport interface TooltipPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"popover\" | \"role\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Placement relative to the trigger through inline `position-area`, with\n * `position-try-fallbacks` flipping it when it does not fit. `\"inline-start\"` /\n * `\"inline-end\"` follow the popup's direction. `null` emits no inline positioning (and no\n * `data-side` / `data-align`), so a stylesheet owns placement.\n *\n * @defaultValue `\"top\"`\n */\n side?: TooltipSide | null;\n /**\n * Alignment along the side. On a top / bottom side `start` / `end` are\n * inline-relative (mirrored under `direction: rtl`); on the other sides they are the top /\n * bottom edges. Ignored when `side` is `null`.\n *\n * @defaultValue `\"center\"`\n */\n align?: TooltipAlign;\n /**\n * Experimental (Chrome 151+, Firefox 153+; Safari 27.0 treats it as `\"manual\"`). Renders\n * `popover=\"hint\"` instead of `popover=\"manual\"`: native light dismiss, and the tooltip can\n * open over an `auto` popover (a menu) without closing it. The JS Escape / pointerdown handling\n * stays in place for engines that do not know `hint`.\n *\n * @defaultValue `false`\n */\n experimental_hint?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, TooltipPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, TooltipPopupState>;\n /**\n * Rendered at mount (hidden by the popover's `display: none`), not at open time. Tooltip\n * content should be static; if it must suspend, put the `<Suspense>` boundary inside the Popup.\n */\n children?: StateValue<ReactNode, TooltipPopupState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, TooltipPopupState>;\n}\n\n/**\n * The tooltip content: a `div` with `popover` and `role=\"tooltip\"`, shown in the top layer and\n * anchored to the trigger implicitly (`interestfor` or `showPopover({ source })`). Open state is\n * browser-owned: style it with `:popover-open` and animate it with `@starting-style` in CSS.\n *\n * `data-side` / `data-align` are where the browser placed the popup while it is shown (the\n * `position-try-fallbacks` option it applied, read from the computed `position-area`;\n * conventions 13.2) and the requested values otherwise; `Tooltip.Arrow` echoes them.\n *\n * `data-instant` is present while the tooltip is shown by an open that began while another\n * `[role=\"tooltip\"]:popover-open` existed (a warm open, skip-delay), so\n * `[data-instant] { transition: none }` skips its entry animation. Not rendered by this part: the\n * Root's effect writes it on the element from the popup's `beforetoggle` (on both paths), before\n * the open's first style recalc, and removes it at the close's. No `state` counterpart.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `data-disabled`, and `data-side` /\n * `data-align` unless `side` is `null`.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport function TooltipPopup({\n side: sideProp = \"top\",\n align: alignProp = \"center\",\n experimental_hint = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TooltipPopupProps) {\n const ctx = useTooltipContext(\"Tooltip.Popup\");\n const placement = useAnchoredPlacement({ side: sideProp, align: alignProp });\n const { side, align } = placement;\n const state: TooltipPopupState = { disabled: ctx.disabled, side, align };\n const arrow = useMemo<TooltipPopupContextValue>(() => ({ side, align }), [side, align]);\n const ref = useMergedRefs(ctx.setPopupElement, placement.ref);\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: ctx.popupId,\n popover: experimental_hint ? \"hint\" : \"manual\",\n role: \"tooltip\",\n \"data-disabled\": dataAttr(ctx.disabled),\n // Not owned with `side={null}`: the stylesheet (or a render element) may set them.\n ...placement.dataAttributes,\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, TooltipPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The consumer's style wins over the inline placement (design 3).\n style: placement.style(style),\n children,\n props: rest,\n libraryProps,\n ref,\n });\n\n return <TooltipPopupContext value={arrow}>{element}</TooltipPopupContext>;\n}\n\nTooltipPopup.displayName = \"TooltipPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,SAAgB,aAAa,EAC3B,MAAM,WAAW,OACjB,OAAO,YAAY,UACnB,oBAAoB,OACpB,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,YAAY,qBAAqB;EAAE,MAAM;EAAU,OAAO;CAAU,CAAC;CAC3E,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,QAA2B;EAAE,UAAU,IAAI;EAAU;EAAM;CAAM;CACvE,MAAM,QAAQ,eAAyC;EAAE;EAAM;CAAM,IAAI,CAAC,MAAM,KAAK,CAAC;CACtF,MAAM,MAAM,cAAc,IAAI,iBAAiB,UAAU,GAAG;CAE5D,MAAM,eAA8D;EAClE,IAAI,IAAI;EACR,SAAS,oBAAoB,SAAS;EACtC,MAAM;EACN,iBAAiB,SAAS,IAAI,QAAQ;EAEtC,GAAG,UAAU;CACf;CAEA,MAAM,UAAU,UAA2D;EACzE,gBAAgB;EAChB;EACA;EACA;EAEA,OAAO,UAAU,MAAM,KAAK;EAC5B;EACA,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,oBAAC,qBAAD;EAAqB,OAAO;EAAQ,UAAA;CAA6B,CAAA;AAC1E;AAEA,aAAa,cAAc"}
|
|
1
|
+
{"version":3,"file":"tooltip-popup.mjs","names":[],"sources":["../../src/tooltip/tooltip-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useMemo } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useAnchoredPlacement } from \"../internal/overlay/use-resolved-placement.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { TooltipPopupContext, useTooltipContext } from \"./tooltip-context.js\";\nimport type { TooltipAlign, TooltipPopupContextValue, TooltipSide } from \"./tooltip-context.js\";\n\nexport type { TooltipAlign, TooltipSide } from \"./tooltip-context.js\";\n\n/**\n * State of `Tooltip.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface TooltipPopupState {\n /** The Root's `disabled`. */\n readonly disabled: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (`\"top\"` / `\"bottom\"` /\n * `\"left\"` / `\"right\"`, after any fallback flip). Otherwise the `side` prop. `null` with\n * `side={null}`.\n */\n readonly side: TooltipSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: TooltipAlign;\n}\n\n/**\n * Props of `Tooltip.Popup`.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport interface TooltipPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"popover\" | \"role\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Placement relative to the trigger through inline `position-area`, with\n * `position-try-fallbacks` flipping it when it does not fit. `\"inline-start\"` /\n * `\"inline-end\"` follow the popup's direction. `null` emits no inline positioning (and no\n * `data-side` / `data-align`), so a stylesheet owns placement.\n *\n * @defaultValue `\"top\"`\n */\n side?: TooltipSide | null;\n /**\n * Alignment along the side. On a top / bottom side `start` / `end` are\n * inline-relative (mirrored under `direction: rtl`); on the other sides they are the top /\n * bottom edges. Ignored when `side` is `null`.\n *\n * @defaultValue `\"center\"`\n */\n align?: TooltipAlign;\n /**\n * Experimental (Chrome 151+, Firefox 153+; Safari 27.0 treats it as `\"manual\"`). Renders\n * `popover=\"hint\"` instead of `popover=\"manual\"`: native light dismiss, and the tooltip can\n * open over an `auto` popover (a menu) without closing it. The JS Escape / pointerdown handling\n * stays in place for engines that do not know `hint`.\n *\n * @defaultValue `false`\n */\n experimental_hint?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, TooltipPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, TooltipPopupState>;\n /**\n * Rendered at mount (hidden by the popover's `display: none`), not at open time. Tooltip\n * content should be static; if it must suspend, put the `<Suspense>` boundary inside the Popup.\n */\n children?: StateValue<ReactNode, TooltipPopupState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, TooltipPopupState>;\n}\n\n/**\n * The tooltip content: a `div` with `popover` and `role=\"tooltip\"`, shown in the top layer and\n * anchored to the trigger implicitly (`interestfor` or `showPopover({ source })`). Open state is\n * browser-owned: style it with `:popover-open` and animate it with `@starting-style` in CSS.\n *\n * `data-side` / `data-align` are where the browser placed the popup while it is shown (the\n * `position-try-fallbacks` option it applied, read from the computed `position-area`;\n * conventions 13.2) and the requested values otherwise; `Tooltip.Arrow` echoes them.\n *\n * `data-instant` is present while the tooltip is shown by an open that began while another\n * `[role=\"tooltip\"]:popover-open` existed (a warm open, skip-delay), so\n * `[data-instant] { transition: none }` skips its entry animation. Not rendered by this part: the\n * Root's effect writes it on the element from the popup's `beforetoggle` (on both paths), before\n * the open's first style recalc, and removes it at the close's. No `state` counterpart.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `data-disabled`, and `data-side` /\n * `data-align` unless `side` is `null`.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport function TooltipPopup({\n side: sideProp = \"top\",\n align: alignProp = \"center\",\n experimental_hint = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TooltipPopupProps) {\n const ctx = useTooltipContext(\"Tooltip.Popup\");\n const placement = useAnchoredPlacement({ side: sideProp, align: alignProp });\n const { side, align } = placement;\n const state: TooltipPopupState = { disabled: ctx.disabled, side, align };\n const arrow = useMemo<TooltipPopupContextValue>(() => ({ side, align }), [side, align]);\n const ref = useMergedRefs(ctx.setPopupElement, placement.ref);\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: ctx.popupId,\n popover: experimental_hint ? \"hint\" : \"manual\",\n role: \"tooltip\",\n \"data-disabled\": dataAttr(ctx.disabled),\n // Not owned with `side={null}`: the stylesheet (or a render element) may set them.\n ...placement.dataAttributes,\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, TooltipPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The consumer's style wins over the inline placement (design 3).\n style: placement.style(style),\n children,\n props: rest,\n libraryProps,\n ref,\n });\n\n return <TooltipPopupContext value={arrow}>{element}</TooltipPopupContext>;\n}\n\nTooltipPopup.displayName = \"TooltipPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,SAAgB,aAAa,EAC3B,MAAM,WAAW,OACjB,OAAO,YAAY,UACnB,oBAAoB,OACpB,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,YAAY,qBAAqB;EAAE,MAAM;EAAU,OAAO;CAAU,CAAC;CAC3E,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,QAA2B;EAAE,UAAU,IAAI;EAAU;EAAM;CAAM;CACvE,MAAM,QAAQ,eAAyC;EAAE;EAAM;CAAM,IAAI,CAAC,MAAM,KAAK,CAAC;CACtF,MAAM,MAAM,cAAc,IAAI,iBAAiB,UAAU,GAAG;CAE5D,MAAM,eAA8D;EAClE,IAAI,IAAI;EACR,SAAS,oBAAoB,SAAS;EACtC,MAAM;EACN,iBAAiB,SAAS,IAAI,QAAQ;EAEtC,GAAG,UAAU;CACf;CAEA,MAAM,UAAU,UAA2D;EACzE,gBAAgB;EAChB;EACA;EACA;EAEA,OAAO,UAAU,MAAM,KAAK;EAC5B;EACA,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,oBAAC,qBAAD;EAAqB,OAAO;EAAQ,UAAA;CAA6B,CAAA;AAC1E;AAEA,aAAa,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-root.d.mts","names":[],"sources":["../../src/tooltip/tooltip-root.tsx"],"mappings":";;;;;iBAYiB;;WAEN;;;;;;;iBAQM;;;;;;;EAOf;;;;;;EAMA;;;;;;EAMA;;;;;;;;EAQA,WAAW;;EAEX,WAAW,WAAW,WAAW;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"tooltip-root.d.mts","names":[],"sources":["../../src/tooltip/tooltip-root.tsx"],"mappings":";;;;;iBAYiB;;WAEN;;;;;;;iBAQM;;;;;;;EAOf;;;;;;EAMA;;;;;;EAMA;;;;;;;;EAQA,WAAW;;EAEX,WAAW,WAAW,WAAW;;;;;;;;;;;;;wBAoBnB,cACd,OACA,YACA,UACA,UACA,YACC,mCAAgB,IAAA;yBANH"}
|
|
@@ -68,7 +68,12 @@ function isKeyboardReachable(trigger) {
|
|
|
68
68
|
if (trigger.tabIndex >= 0) return true;
|
|
69
69
|
return trigger.hasAttribute("tabindex") && trigger.parentElement?.closest(COMPOSITE) != null;
|
|
70
70
|
}
|
|
71
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Development-only checks that need the mounted elements (design 12.5). Each fires once per Root.
|
|
73
|
+
* Not `useDevWarning` (its condition is computed in render, which must not read these elements'
|
|
74
|
+
* attributes) nor `useElementCheck` (one warning per hook, and these run when `provides` or
|
|
75
|
+
* either element changes, from the Root): an effect with its own flags.
|
|
76
|
+
*/
|
|
72
77
|
function useTooltipDevWarnings(trigger, popup, provides) {
|
|
73
78
|
const warned = useRef({
|
|
74
79
|
label: false,
|
|
@@ -81,16 +86,16 @@ function useTooltipDevWarnings(trigger, popup, provides) {
|
|
|
81
86
|
if (trigger !== null) {
|
|
82
87
|
if (provides === "name" && trigger.hasAttribute("aria-label") && !w.label) {
|
|
83
88
|
w.label = true;
|
|
84
|
-
console.error("
|
|
89
|
+
console.error("Tooltip.Trigger: provides=\"name\" together with aria-label on the trigger announces the name twice. Remove aria-label.");
|
|
85
90
|
}
|
|
86
91
|
if (!isKeyboardReachable(trigger) && !w.focusable) {
|
|
87
92
|
w.focusable = true;
|
|
88
|
-
console.error("
|
|
93
|
+
console.error("Tooltip.Trigger: the trigger is not focusable; keyboard users cannot open the tooltip. Render a <button> or a link, or set tabIndex={0}.");
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
if (popup !== null && popup.querySelector(FOCUSABLE) !== null && !w.interactive) {
|
|
92
97
|
w.interactive = true;
|
|
93
|
-
console.error("
|
|
98
|
+
console.error("Tooltip.Popup: tooltips must not contain interactive content. Use a non-modal dialog or a popover instead.");
|
|
94
99
|
}
|
|
95
100
|
}, [
|
|
96
101
|
trigger,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-root.mjs","names":[],"sources":["../../src/tooltip/tooltip-root.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { StateValue } from \"../internal/types.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { TooltipContext } from \"./tooltip-context.js\";\nimport type { TooltipContextValue, TooltipProvides } from \"./tooltip-context.js\";\nimport { useTooltipInteraction } from \"./use-tooltip-interaction.js\";\n\nexport type { TooltipProvides } from \"./tooltip-context.js\";\n\n/** State of `Tooltip.Root`, passed to the function forms of `children`. */\nexport interface TooltipRootState {\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Tooltip.Root`.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport interface TooltipRootProps {\n /**\n * Milliseconds from hover or keyboard focus to open. Default 250 (Chromium's\n * `interest-delay-start`). The same delay applies to hover and focus.\n *\n * @defaultValue `250`\n */\n delay?: number;\n /**\n * Milliseconds from de-hover or blur to close.\n *\n * @defaultValue `150` (Chromium's `interest-delay-end`)\n */\n closeDelay?: number;\n /**\n * When true the tooltip never opens. The ARIA relation stays in place.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Which accessibility relation the tooltip provides for the trigger.\n * `\"description\"` (default): `aria-describedby`, for triggers that have their own name.\n * `\"name\"`: `aria-labelledby`, for icon-only triggers; do not also set `aria-label`.\n *\n * @defaultValue `\"description\"`\n */\n provides?: TooltipProvides;\n /** The Trigger and the Popup. May be a function of the part's state. */\n children?: StateValue<ReactNode, TooltipRootState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nconst FOCUSABLE =\n \"a[href],area[href],button,input,select,textarea,iframe,[tabindex],[contenteditable]\";\n\n/**\n * Owns the popup id, the options and the one interaction effect. Renders no DOM, so it has no\n * `ref`, `className` or `style`. The open state is browser-owned (the popover's top-layer state):\n * there is no `open` prop, no action, and no `data-open`; style with `:popover-open`.\n *\n * Render `Tooltip.Popup` immediately after `Tooltip.Trigger` in DOM order: the HTML spec\n * recommends that reading order for popovers, and some screen readers attach an adjacent tooltip\n * to the wrong control otherwise. This is documented, not enforced.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport function TooltipRoot({\n delay = 250,\n closeDelay = 150,\n disabled = false,\n provides = \"description\",\n children,\n}: TooltipRootProps) {\n const popupId = useId();\n const [trigger, setTriggerElement] = useState<HTMLElement | null>(null);\n const [popup, setPopupElement] = useState<HTMLElement | null>(null);\n const [interestForRequested, setInterestForRequested] = useState(false);\n\n useTooltipInteraction(trigger, popup, { delay, closeDelay, disabled, interestForRequested });\n useTooltipDevWarnings(trigger, popup, provides);\n\n const context = useMemo<TooltipContextValue>(\n () => ({\n popupId,\n disabled,\n delay,\n closeDelay,\n provides,\n setTriggerElement,\n setPopupElement,\n setInterestForRequested,\n }),\n [popupId, disabled, delay, closeDelay, provides],\n );\n\n const state: TooltipRootState = { disabled };\n return <TooltipContext value={context}>{resolveStateValue(children, state)}</TooltipContext>;\n}\n\nTooltipRoot.displayName = \"TooltipRoot\";\n\n/**\n * The containers that move focus among their items with the arrow keys (roving tabindex, or a\n * native `focusgroup`): Menu, Tabs, Toolbar, a radio group, and the other APG composites, plus\n * `role=\"group\"`, which a standalone `ToggleGroup.Root` renders while its roving engine writes\n * the Items' `tabindex` (design/components/toggle-group.md 18).\n */\nconst COMPOSITE =\n '[role=\"menu\"],[role=\"menubar\"],[role=\"tablist\"],[role=\"toolbar\"],[role=\"group\"],[role=\"radiogroup\"],[role=\"listbox\"],[role=\"grid\"],[role=\"treegrid\"],[role=\"tree\"],[focusgroup]';\n\n/**\n * Whether keyboard users can focus the trigger: it is in the tab order, or it is a\n * roving-tabindex item (`tabindex=\"-1\"` set explicitly, so script can focus it) inside a\n * composite widget that moves focus to it.\n */\nfunction isKeyboardReachable(trigger: HTMLElement): boolean {\n if (trigger.tabIndex >= 0) return true;\n return trigger.hasAttribute(\"tabindex\") && trigger.parentElement?.closest(COMPOSITE) != null;\n}\n\n
|
|
1
|
+
{"version":3,"file":"tooltip-root.mjs","names":[],"sources":["../../src/tooltip/tooltip-root.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { StateValue } from \"../internal/types.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { TooltipContext } from \"./tooltip-context.js\";\nimport type { TooltipContextValue, TooltipProvides } from \"./tooltip-context.js\";\nimport { useTooltipInteraction } from \"./use-tooltip-interaction.js\";\n\nexport type { TooltipProvides } from \"./tooltip-context.js\";\n\n/** State of `Tooltip.Root`, passed to the function forms of `children`. */\nexport interface TooltipRootState {\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Tooltip.Root`.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport interface TooltipRootProps {\n /**\n * Milliseconds from hover or keyboard focus to open. Default 250 (Chromium's\n * `interest-delay-start`). The same delay applies to hover and focus.\n *\n * @defaultValue `250`\n */\n delay?: number;\n /**\n * Milliseconds from de-hover or blur to close.\n *\n * @defaultValue `150` (Chromium's `interest-delay-end`)\n */\n closeDelay?: number;\n /**\n * When true the tooltip never opens. The ARIA relation stays in place.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Which accessibility relation the tooltip provides for the trigger.\n * `\"description\"` (default): `aria-describedby`, for triggers that have their own name.\n * `\"name\"`: `aria-labelledby`, for icon-only triggers; do not also set `aria-label`.\n *\n * @defaultValue `\"description\"`\n */\n provides?: TooltipProvides;\n /** The Trigger and the Popup. May be a function of the part's state. */\n children?: StateValue<ReactNode, TooltipRootState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n// Only drives the interactive-content dev warning, so it is broader than roving's and Menu's.\nconst FOCUSABLE =\n \"a[href],area[href],button,input,select,textarea,iframe,[tabindex],[contenteditable]\";\n\n/**\n * Owns the popup id, the options and the one interaction effect. Renders no DOM, so it has no\n * `ref`, `className` or `style`. The open state is browser-owned (the popover's top-layer state):\n * there is no `open` prop, no action, and no `data-open`; style with `:popover-open`.\n *\n * Render `Tooltip.Popup` immediately after `Tooltip.Trigger` in DOM order: the HTML spec\n * recommends that reading order for popovers, and some screen readers attach an adjacent tooltip\n * to the wrong control otherwise. This is documented, not enforced.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport function TooltipRoot({\n delay = 250,\n closeDelay = 150,\n disabled = false,\n provides = \"description\",\n children,\n}: TooltipRootProps) {\n const popupId = useId();\n const [trigger, setTriggerElement] = useState<HTMLElement | null>(null);\n const [popup, setPopupElement] = useState<HTMLElement | null>(null);\n const [interestForRequested, setInterestForRequested] = useState(false);\n\n useTooltipInteraction(trigger, popup, { delay, closeDelay, disabled, interestForRequested });\n useTooltipDevWarnings(trigger, popup, provides);\n\n const context = useMemo<TooltipContextValue>(\n () => ({\n popupId,\n disabled,\n delay,\n closeDelay,\n provides,\n setTriggerElement,\n setPopupElement,\n setInterestForRequested,\n }),\n [popupId, disabled, delay, closeDelay, provides],\n );\n\n const state: TooltipRootState = { disabled };\n return <TooltipContext value={context}>{resolveStateValue(children, state)}</TooltipContext>;\n}\n\nTooltipRoot.displayName = \"TooltipRoot\";\n\n/**\n * The containers that move focus among their items with the arrow keys (roving tabindex, or a\n * native `focusgroup`): Menu, Tabs, Toolbar, a radio group, and the other APG composites, plus\n * `role=\"group\"`, which a standalone `ToggleGroup.Root` renders while its roving engine writes\n * the Items' `tabindex` (design/components/toggle-group.md 18).\n */\nconst COMPOSITE =\n '[role=\"menu\"],[role=\"menubar\"],[role=\"tablist\"],[role=\"toolbar\"],[role=\"group\"],[role=\"radiogroup\"],[role=\"listbox\"],[role=\"grid\"],[role=\"treegrid\"],[role=\"tree\"],[focusgroup]';\n\n/**\n * Whether keyboard users can focus the trigger: it is in the tab order, or it is a\n * roving-tabindex item (`tabindex=\"-1\"` set explicitly, so script can focus it) inside a\n * composite widget that moves focus to it.\n */\nfunction isKeyboardReachable(trigger: HTMLElement): boolean {\n if (trigger.tabIndex >= 0) return true;\n return trigger.hasAttribute(\"tabindex\") && trigger.parentElement?.closest(COMPOSITE) != null;\n}\n\n/**\n * Development-only checks that need the mounted elements (design 12.5). Each fires once per Root.\n * Not `useDevWarning` (its condition is computed in render, which must not read these elements'\n * attributes) nor `useElementCheck` (one warning per hook, and these run when `provides` or\n * either element changes, from the Root): an effect with its own flags.\n */\nfunction useTooltipDevWarnings(\n trigger: HTMLElement | null,\n popup: HTMLElement | null,\n provides: TooltipProvides,\n): void {\n const warned = useRef({ label: false, focusable: false, interactive: false });\n useEffect(() => {\n if (!isDev) return;\n const w = warned.current;\n if (trigger !== null) {\n if (provides === \"name\" && trigger.hasAttribute(\"aria-label\") && !w.label) {\n w.label = true;\n console.error(\n 'Tooltip.Trigger: provides=\"name\" together with aria-label on the trigger announces the name twice. Remove aria-label.',\n );\n }\n if (!isKeyboardReachable(trigger) && !w.focusable) {\n w.focusable = true;\n console.error(\n \"Tooltip.Trigger: the trigger is not focusable; keyboard users cannot open the tooltip. Render a <button> or a link, or set tabIndex={0}.\",\n );\n }\n }\n if (popup !== null && popup.querySelector(FOCUSABLE) !== null && !w.interactive) {\n w.interactive = true;\n console.error(\n \"Tooltip.Popup: tooltips must not contain interactive content. Use a non-modal dialog or a popover instead.\",\n );\n }\n }, [trigger, popup, provides]);\n}\n"],"mappings":";;;;;;;AAsDA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAGvC,MAAM,YACJ;;;;;;;;;;;;AAaF,SAAgB,YAAY,EAC1B,QAAQ,KACR,aAAa,KACb,WAAW,OACX,WAAW,eACX,YACmB;CACnB,MAAM,UAAU,MAAM;CACtB,MAAM,CAAC,SAAS,qBAAqB,SAA6B,IAAI;CACtE,MAAM,CAAC,OAAO,mBAAmB,SAA6B,IAAI;CAClE,MAAM,CAAC,sBAAsB,2BAA2B,SAAS,KAAK;CAEtE,sBAAsB,SAAS,OAAO;EAAE;EAAO;EAAY;EAAU;CAAqB,CAAC;CAC3F,sBAAsB,SAAS,OAAO,QAAQ;CAE9C,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EAAC;EAAS;EAAU;EAAO;EAAY;CAAQ,CACjD;CAGA,OAAO,oBAAC,gBAAD;EAAgB,OAAO;EAAU,UAAA,kBAAkB,UAAU,EADlC,SACsC,CAAC;CAAkB,CAAA;AAC7F;AAEA,YAAY,cAAc;;;;;;;AAQ1B,MAAM,YACJ;;;;;;AAOF,SAAS,oBAAoB,SAA+B;CAC1D,IAAI,QAAQ,YAAY,GAAG,OAAO;CAClC,OAAO,QAAQ,aAAa,UAAU,KAAK,QAAQ,eAAe,QAAQ,SAAS,KAAK;AAC1F;;;;;;;AAQA,SAAS,sBACP,SACA,OACA,UACM;CACN,MAAM,SAAS,OAAO;EAAE,OAAO;EAAO,WAAW;EAAO,aAAa;CAAM,CAAC;CAC5E,gBAAgB;EACd,IAAI,CAAC,OAAO;EACZ,MAAM,IAAI,OAAO;EACjB,IAAI,YAAY,MAAM;GACpB,IAAI,aAAa,UAAU,QAAQ,aAAa,YAAY,KAAK,CAAC,EAAE,OAAO;IACzE,EAAE,QAAQ;IACV,QAAQ,MACN,yHACF;GACF;GACA,IAAI,CAAC,oBAAoB,OAAO,KAAK,CAAC,EAAE,WAAW;IACjD,EAAE,YAAY;IACd,QAAQ,MACN,0IACF;GACF;EACF;EACA,IAAI,UAAU,QAAQ,MAAM,cAAc,SAAS,MAAM,QAAQ,CAAC,EAAE,aAAa;GAC/E,EAAE,cAAc;GAChB,QAAQ,MACN,4GACF;EACF;CACF,GAAG;EAAC;EAAS;EAAO;CAAQ,CAAC;AAC/B"}
|
|
@@ -5,7 +5,7 @@ import { useRender } from "../internal/use-render.mjs";
|
|
|
5
5
|
import { useTooltipContext } from "./tooltip-context.mjs";
|
|
6
6
|
import { CSPContext } from "../internal/csp-context.mjs";
|
|
7
7
|
import { FSUI_PRECEDENCE } from "../internal/shipped-styles.mjs";
|
|
8
|
-
import { TOOLTIP_WARM_HREF, TOOLTIP_WARM_RULES, warmDelay } from "
|
|
8
|
+
import { TOOLTIP_WARM_HREF, TOOLTIP_WARM_RULES, warmDelay } from "./tooltip-warm.mjs";
|
|
9
9
|
import { use, useLayoutEffect } from "react";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
//#region src/tooltip/tooltip-trigger.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-trigger.mjs","names":[],"sources":["../../src/tooltip/tooltip-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { use, useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/shipped-styles.js\";\nimport {\n TOOLTIP_TRIGGER_MARKER,\n TOOLTIP_WARM_HREF,\n TOOLTIP_WARM_RULES,\n warmDelay,\n} from \"
|
|
1
|
+
{"version":3,"file":"tooltip-trigger.mjs","names":[],"sources":["../../src/tooltip/tooltip-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { use, useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/shipped-styles.js\";\nimport {\n TOOLTIP_TRIGGER_MARKER,\n TOOLTIP_WARM_HREF,\n TOOLTIP_WARM_RULES,\n warmDelay,\n} from \"./tooltip-warm.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { rendersButton, resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useTooltipContext } from \"./tooltip-context.js\";\n\n/**\n * State of `Tooltip.Trigger`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface TooltipTriggerState {\n /** The Root's `disabled`. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Tooltip.Trigger`.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport interface TooltipTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"className\" | \"style\" | \"children\"\n> {\n /**\n * Experimental (Chromium 142+). Renders `interestfor` and `interest-delay-start/end` so the\n * browser owns hover, focus, Escape and long-press; the library's JS trigger path is skipped\n * where the rendered element implements `interestForElement`. No effect in other engines (the\n * attribute is ignored and the JS path runs). Pair with `Tooltip.Popup experimental_hint`.\n * Skip-delay on this path comes from a shipped rule: the Trigger renders the\n * `data-fsui-tooltip-trigger` marker, an `interest-delay-start` of\n * `calc(<delay>ms * (1 - var(--fsui-tooltip-warm, 0)))` and a hoisted\n * `<style href=\"@funstack/ui/tooltip-warm\">` (nonce from `<CSPProvider>`), rendered beside the\n * element so a `render` element with its own children keeps it. When that stylesheet is\n * missing (a CSP blocks it), the tooltip opens after its `delay` and only skip-delay is lost.\n *\n * @defaultValue `false`\n */\n experimental_interestFor?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, TooltipTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, TooltipTriggerState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, TooltipTriggerState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, TooltipTriggerState>;\n}\n\n/**\n * The element the user hovers or focuses: a `<button type=\"button\">` by default. `render` may\n * substitute a link or a custom button; the element must be focusable (a dev warning fires when\n * it is not). A natively `disabled` button never opens a tooltip; use `aria-disabled` instead.\n *\n * The library attaches its hover / focus listeners with `addEventListener` from `Tooltip.Root`,\n * so every `on*` prop passes through untouched.\n *\n * Owned keys (conventions 1.2): `aria-describedby` (with `provides=\"description\"`) or\n * `aria-labelledby` (with `provides=\"name\"`), both token-merged with the consumer's ids;\n * `data-disabled`; and `interestfor` and `data-fsui-tooltip-trigger` when\n * `experimental_interestFor` is on. `type=\"button\"` is a default the consumer may override (the\n * part installs no click handler), unlike the overlay Triggers, which own it.\n *\n * @see https://ui.funstack.work/components/tooltip\n */\nexport function TooltipTrigger({\n experimental_interestFor = false,\n className,\n style,\n children,\n render,\n ...rest\n}: TooltipTriggerProps) {\n const ctx = useTooltipContext(\"Tooltip.Trigger\");\n const { disabled, popupId, provides, setInterestForRequested } = ctx;\n const native = experimental_interestFor && !disabled;\n const csp = use(CSPContext);\n\n useLayoutEffect(() => {\n setInterestForRequested(native);\n }, [native, setInterestForRequested]);\n\n const state: TooltipTriggerState = { disabled };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // Only the relation in use is owned; the other one passes through untouched.\n ...(provides === \"name\" ? { \"aria-labelledby\": popupId } : { \"aria-describedby\": popupId }),\n \"data-disabled\": dataAttr(disabled),\n // Owned while the flag is on: a disabled tooltip removes the attribute, so the browser\n // cannot open it either. Unflagged, the key is omitted (conventions 1.2).\n ...(experimental_interestFor && {\n interestfor: native ? popupId : undefined,\n // What the shipped skip-delay rule matches (design 6); nothing else carries it.\n [TOOLTIP_TRIGGER_MARKER]: native ? \"\" : undefined,\n }),\n };\n\n // Skip-delay on the native path (design 6, conventions 12): the browser reads the delay from\n // the computed style when the hover starts, and only a rule can see that another tooltip is\n // showing. Hoisted into <head> by React (during SSR too) and deduplicated; nothing lands in\n // place. Rendered beside the element, not in its children: a `render` element with its own\n // children (`render={<a href>Text</a>}`) wins over `children` and would drop it.\n const warmRules = native ? (\n <style href={TOOLTIP_WARM_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {TOOLTIP_WARM_RULES}\n </style>\n ) : null;\n\n const element = useRender<ComponentPropsWithRef<\"button\">, TooltipTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n // The native delays sit under the consumer's style: the consumer wins. The open delay is 0\n // while another tooltip is showing (`--fsui-tooltip-warm`, design 6).\n style: native\n ? (s) => ({\n interestDelayStart: warmDelay(ctx.delay),\n interestDelayEnd: `${ctx.closeDelay}ms`,\n ...resolveStateValue(style, s),\n })\n : style,\n children,\n // `type=\"button\"` only on a real button (the consumer may override it); a link or a\n // component element does not get it.\n props: rendersButton(render) ? { type: \"button\", ...rest } : rest,\n libraryProps,\n ref: ctx.setTriggerElement,\n });\n return (\n <>\n {warmRules}\n {element}\n </>\n );\n}\n\nTooltipTrigger.displayName = \"TooltipTrigger\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,SAAgB,eAAe,EAC7B,2BAA2B,OAC3B,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,MAAM,kBAAkB,iBAAiB;CAC/C,MAAM,EAAE,UAAU,SAAS,UAAU,4BAA4B;CACjE,MAAM,SAAS,4BAA4B,CAAC;CAC5C,MAAM,MAAM,IAAI,UAAU;CAE1B,sBAAsB;EACpB,wBAAwB,MAAM;CAChC,GAAG,CAAC,QAAQ,uBAAuB,CAAC;CAEpC,MAAM,QAA6B,EAAE,SAAS;CAE9C,MAAM,eAAiE;EAErE,GAAI,aAAa,SAAS,EAAE,mBAAmB,QAAQ,IAAI,EAAE,oBAAoB,QAAQ;EACzF,iBAAiB,SAAS,QAAQ;EAGlC,GAAI,4BAA4B;GAC9B,aAAa,SAAS,UAAU,KAAA;IAEN,8BAAA,SAAS,KAAK,KAAA;EAC1C;CACF;CAOA,MAAM,YAAY,SAChB,oBAAC,SAAD;EAAO,MAAM;EAAmB,YAAY;EAAiB,OAAO,KAAK;EACtE,UAAA;CACI,CAAA,IACL;CAEJ,MAAM,UAAU,UAAgE;EAC9E,gBAAgB;EAChB;EACA;EACA;EAGA,OAAO,UACF,OAAO;GACN,oBAAoB,UAAU,IAAI,KAAK;GACvC,kBAAkB,GAAG,IAAI,WAAW;GACpC,GAAG,kBAAkB,OAAO,CAAC;EAC/B,KACA;EACJ;EAGA,OAAO,cAAc,MAAM,IAAI;GAAE,MAAM;GAAU,GAAG;EAAK,IAAI;EAC7D;EACA,KAAK,IAAI;CACX,CAAC;CACD,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,WACA,OACD,EAAA,CAAA;AAEN;AAEA,eAAe,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/tooltip/tooltip-warm.ts
|
|
2
2
|
/** Registered, non-inherited: `1` on the marked triggers while a tooltip is showing, else `0`. */
|
|
3
3
|
const TOOLTIP_WARM_PROPERTY = "--fsui-tooltip-warm";
|
|
4
4
|
/** The marker a flagged Trigger renders; the shipped rule matches nothing else. */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip-warm.mjs","names":[],"sources":["../../src/tooltip/tooltip-warm.ts"],"sourcesContent":["// Tooltip's skip-delay rule on the native `interestfor` path (design/components/tooltip.md 6,\n// conventions 12): while any tooltip is showing, the inline `interest-delay-start` of a flagged\n// Trigger computes to 0. No \"use client\" directive: constants only (conventions 7.1).\n\n/** Registered, non-inherited: `1` on the marked triggers while a tooltip is showing, else `0`. */\nconst TOOLTIP_WARM_PROPERTY = \"--fsui-tooltip-warm\";\n/** The marker a flagged Trigger renders; the shipped rule matches nothing else. */\nexport const TOOLTIP_TRIGGER_MARKER = \"data-fsui-tooltip-trigger\";\n/** The dedupe key of the shipped rule (`<style href precedence>`). */\nexport const TOOLTIP_WARM_HREF = \"@funstack/ui/tooltip-warm\";\n\n/**\n * The library's second shipped stylesheet: interaction timing, nothing visual (conventions 12's\n * selector exception: it matches only the library's marker and sets only a `--fsui-` registered\n * property the Trigger's inline style consumes). Its SHA-256 is `STYLE_SHA256` in\n * `@funstack/ui/csp` (a jsdom row recomputes it). When the stylesheet is missing (blocked by a\n * CSP, or never rendered) the property is unregistered and unset: `warmDelay`'s `var()` carries\n * its own `0` fallback, so the Trigger keeps its own `delay` (without it the declaration would be\n * invalid at computed-value time and the browser's `normal` delay would apply).\n */\nexport const TOOLTIP_WARM_RULES =\n \"/* @funstack/ui: tooltip skip-delay. Functional only: while a tooltip is showing, the next \" +\n \"one opens without its delay. */\\n\" +\n `@property ${TOOLTIP_WARM_PROPERTY} { syntax: \"<number>\"; inherits: false; initial-value: 0; }\\n` +\n `:root:has([role=\"tooltip\"]:popover-open) [${TOOLTIP_TRIGGER_MARKER}] { ${TOOLTIP_WARM_PROPERTY}: 1; }\\n`;\n\n/**\n * The inline `interest-delay-start` of a flagged Trigger: `delay` when cold, `0` when warm, and\n * `delay` when the stylesheet is missing (the explicit `0` fallback).\n */\nexport function warmDelay(delay: number): string {\n return `calc(${delay}ms * (1 - var(${TOOLTIP_WARM_PROPERTY}, 0)))`;\n}\n"],"mappings":";;AAKA,MAAM,wBAAwB;;AAE9B,MAAa,yBAAyB;;AAEtC,MAAa,oBAAoB;;;;;;;;;;AAWjC,MAAa,qBACX;YAEa,sBAAsB,yGACU,uBAAuB,MAAM,sBAAsB;;;;;AAMlG,SAAgB,UAAU,OAAuB;CAC/C,OAAO,QAAQ,MAAM,gBAAgB,sBAAsB;AAC7D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { isPopoverOpen } from "../internal/popover-open.mjs";
|
|
3
|
-
import { syncPresence } from "../internal/sync-presence.mjs";
|
|
2
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
3
|
+
import { syncPresence } from "../internal/form/sync-presence.mjs";
|
|
4
4
|
import { createDelayedPair } from "../internal/use-delayed-pair.mjs";
|
|
5
5
|
import { useEffect, useEffectEvent } from "react";
|
|
6
6
|
//#region src/tooltip/use-tooltip-interaction.ts
|