@funstack/ui 0.1.0-alpha.11 → 0.1.0-alpha.13
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-context.mjs.map +1 -1
- package/dist/accordion/accordion-item.d.mts +3 -4
- package/dist/accordion/accordion-item.d.mts.map +1 -1
- package/dist/accordion/accordion-item.mjs +10 -4
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-panel.d.mts +3 -4
- package/dist/accordion/accordion-panel.d.mts.map +1 -1
- package/dist/accordion/accordion-panel.mjs +2 -1
- package/dist/accordion/accordion-panel.mjs.map +1 -1
- package/dist/accordion/accordion-root.d.mts +3 -3
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +8 -19
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts +3 -4
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +5 -3
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/button/button.d.mts +4 -2
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +3 -2
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.d.mts +4 -5
- package/dist/checkbox/checkbox.d.mts.map +1 -1
- package/dist/checkbox/checkbox.mjs +16 -59
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-context.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-item.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +21 -27
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-label.mjs +1 -6
- package/dist/checkbox-group/checkbox-group-label.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-parent.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +12 -10
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +74 -101
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +5 -6
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-group.d.mts.map +1 -1
- package/dist/combobox/combobox-group.mjs +2 -1
- package/dist/combobox/combobox-group.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts +6 -5
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +29 -14
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts.map +1 -1
- package/dist/combobox/combobox-list.mjs +6 -10
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +2 -1
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs +9 -25
- 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 +101 -106
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts +9 -6
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +36 -43
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/index.mjs +1 -1
- package/dist/combobox/use-combobox-form.mjs +56 -0
- package/dist/combobox/use-combobox-form.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +62 -0
- package/dist/combobox/use-option-registry.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +29 -62
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +5 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +5 -5
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +39 -103
- 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 +30 -118
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts +2 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +27 -23
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/field/field-control.mjs +6 -13
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts.map +1 -1
- package/dist/field/field-description.mjs +1 -2
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts.map +1 -1
- package/dist/field/field-error.mjs +1 -2
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +3 -11
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +22 -42
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.mjs +1 -1
- package/dist/field/use-server-error-visibility.mjs +44 -0
- package/dist/field/use-server-error-visibility.mjs.map +1 -0
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +6 -7
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +1 -1
- package/dist/form/form-submit.mjs +4 -10
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/internal/anchor-position.mjs +1 -59
- package/dist/internal/anchor-position.mjs.map +1 -1
- package/dist/internal/announce.mjs +4 -42
- package/dist/internal/announce.mjs.map +1 -1
- package/dist/internal/arrow-keys.mjs +21 -0
- package/dist/internal/arrow-keys.mjs.map +1 -0
- package/dist/internal/decimal.mjs +7 -1
- package/dist/internal/decimal.mjs.map +1 -1
- package/dist/internal/dom-order.mjs +17 -0
- package/dist/internal/dom-order.mjs.map +1 -0
- package/dist/internal/field-context.d.mts.map +1 -1
- package/dist/internal/field-context.mjs +11 -1
- package/dist/internal/field-context.mjs.map +1 -1
- package/dist/internal/focus-first-invalid.mjs +16 -7
- package/dist/internal/focus-first-invalid.mjs.map +1 -1
- package/dist/internal/group-member.mjs +37 -0
- package/dist/internal/group-member.mjs.map +1 -0
- package/dist/internal/overlay-popup.mjs +103 -0
- package/dist/internal/overlay-popup.mjs.map +1 -0
- package/dist/internal/pointer-capture.mjs +20 -0
- package/dist/internal/pointer-capture.mjs.map +1 -0
- package/dist/internal/popover-open.mjs +18 -0
- package/dist/internal/popover-open.mjs.map +1 -0
- package/dist/internal/render-element.d.mts +2 -0
- package/dist/internal/render-element.mjs +20 -2
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/shipped-styles.mjs +14 -0
- package/dist/internal/shipped-styles.mjs.map +1 -0
- package/dist/internal/sync-presence.mjs +5 -1
- package/dist/internal/sync-presence.mjs.map +1 -1
- package/dist/internal/toolbar-context.mjs.map +1 -1
- package/dist/internal/tooltip-warm.mjs +1 -1
- package/dist/internal/tooltip-warm.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +1 -1
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/trigger-ref.mjs +26 -0
- package/dist/internal/trigger-ref.mjs.map +1 -0
- package/dist/internal/types.d.mts +2 -0
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +5 -23
- package/dist/internal/use-action-trigger.mjs.map +1 -1
- package/dist/internal/use-checkable-input.mjs +79 -0
- package/dist/internal/use-checkable-input.mjs.map +1 -0
- package/dist/internal/use-controllable-action.mjs +16 -24
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- package/dist/internal/use-dev-warning.mjs +8 -4
- package/dist/internal/use-dev-warning.mjs.map +1 -1
- package/dist/internal/use-element-check.mjs +39 -0
- package/dist/internal/use-element-check.mjs.map +1 -0
- package/dist/internal/use-exit-animation.mjs +1 -1
- package/dist/internal/use-exit-animation.mjs.map +1 -1
- package/dist/internal/use-field-control.mjs +28 -12
- package/dist/internal/use-field-control.mjs.map +1 -1
- package/dist/internal/use-fieldset-group.mjs +46 -0
- package/dist/internal/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/use-form-reset.mjs +1 -5
- package/dist/internal/use-form-reset.mjs.map +1 -1
- package/dist/internal/use-item-order.mjs +42 -0
- package/dist/internal/use-item-order.mjs.map +1 -0
- package/dist/internal/use-latest.mjs +4 -8
- package/dist/internal/use-latest.mjs.map +1 -1
- package/dist/internal/use-merged-refs.mjs +19 -0
- package/dist/internal/use-merged-refs.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +84 -0
- package/dist/internal/use-name-warning.mjs.map +1 -0
- package/dist/internal/use-native-checked.mjs +4 -6
- package/dist/internal/use-native-checked.mjs.map +1 -1
- package/dist/internal/use-native-focusgroup.mjs +19 -0
- package/dist/internal/use-native-focusgroup.mjs.map +1 -0
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-overlay-close.mjs +63 -0
- package/dist/internal/use-overlay-close.mjs.map +1 -0
- package/dist/internal/{use-popover-root.mjs → use-overlay-root.mjs} +32 -39
- package/dist/internal/use-overlay-root.mjs.map +1 -0
- package/dist/internal/use-popover-popup.mjs +38 -80
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.d.mts +15 -0
- package/dist/internal/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/use-popover-trigger.mjs +28 -24
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/use-register-count.mjs +24 -0
- package/dist/internal/use-register-count.mjs.map +1 -0
- package/dist/internal/use-render.d.mts +2 -0
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-resolved-placement.mjs +38 -22
- package/dist/internal/use-resolved-placement.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs +5 -18
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/internal/use-superseded-rejection.mjs +47 -0
- package/dist/internal/use-superseded-rejection.mjs.map +1 -0
- package/dist/internal/validity.mjs +1 -13
- package/dist/internal/validity.mjs.map +1 -1
- package/dist/internal/value-set.mjs +41 -0
- package/dist/internal/value-set.mjs.map +1 -0
- package/dist/menu/index.d.mts +1 -1
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context-trigger.d.mts +2 -7
- package/dist/menu/menu-context-trigger.d.mts.map +1 -1
- package/dist/menu/menu-context-trigger.mjs +11 -187
- package/dist/menu/menu-context-trigger.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-dom.mjs +2 -17
- package/dist/menu/menu-dom.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +166 -0
- package/dist/menu/menu-gestures.mjs.map +1 -0
- package/dist/menu/menu-group.d.mts.map +1 -1
- package/dist/menu/menu-group.mjs +2 -1
- package/dist/menu/menu-group.mjs.map +1 -1
- package/dist/menu/menu-hover.mjs +0 -1
- package/dist/menu/menu-hover.mjs.map +1 -1
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +101 -0
- package/dist/menu/menu-outside.mjs.map +1 -0
- package/dist/menu/menu-point.mjs +85 -0
- package/dist/menu/menu-point.mjs.map +1 -0
- package/dist/menu/menu-popup.d.mts +6 -7
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +38 -248
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-radio-item.d.mts +2 -0
- package/dist/menu/menu-radio-item.d.mts.map +1 -1
- package/dist/menu/menu-radio-item.mjs +1 -0
- package/dist/menu/menu-radio-item.mjs.map +1 -1
- package/dist/menu/menu-root.d.mts +10 -0
- package/dist/menu/menu-root.d.mts.map +1 -1
- package/dist/menu/menu-root.mjs +10 -8
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +12 -9
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +10 -11
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +14 -7
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menu/use-menu-item.mjs +14 -16
- package/dist/menu/use-menu-item.mjs.map +1 -1
- package/dist/menu/use-menu-keyboard.mjs +88 -0
- package/dist/menu/use-menu-keyboard.mjs.map +1 -0
- package/dist/meter/meter-root.mjs +1 -1
- package/dist/number-field/index.d.mts +2 -1
- package/dist/number-field/index.d.mts.map +1 -1
- package/dist/number-field/index.mjs +2 -2
- package/dist/number-field/index.mjs.map +1 -1
- package/dist/number-field/number-field-arithmetic.mjs +30 -11
- package/dist/number-field/number-field-arithmetic.mjs.map +1 -1
- package/dist/number-field/number-field-context.d.mts +6 -1
- package/dist/number-field/number-field-context.d.mts.map +1 -0
- package/dist/number-field/number-field-context.mjs.map +1 -1
- package/dist/number-field/number-field-decrement.d.mts +1 -1
- package/dist/number-field/number-field-decrement.mjs +1 -1
- package/dist/number-field/number-field-decrement.mjs.map +1 -1
- package/dist/number-field/number-field-increment.d.mts +2 -22
- package/dist/number-field/number-field-increment.d.mts.map +1 -1
- package/dist/number-field/number-field-increment.mjs +2 -53
- package/dist/number-field/number-field-increment.mjs.map +1 -1
- package/dist/number-field/number-field-input.d.mts.map +1 -1
- package/dist/number-field/number-field-input.mjs +18 -22
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-label.d.mts.map +1 -1
- package/dist/number-field/number-field-label.mjs +3 -9
- package/dist/number-field/number-field-label.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts +3 -2
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +81 -91
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/number-field/use-number-field-dev-warnings.mjs +28 -0
- package/dist/number-field/use-number-field-dev-warnings.mjs.map +1 -0
- package/dist/number-field/use-step-button.d.mts +24 -0
- package/dist/number-field/use-step-button.d.mts.map +1 -0
- package/dist/number-field/use-step-button.mjs +57 -3
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +28 -67
- 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 +9 -6
- package/dist/popover/popover-popup.d.mts.map +1 -1
- package/dist/popover/popover-popup.mjs +13 -36
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +4 -3
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +10 -10
- package/dist/popover/popover-trigger.d.mts.map +1 -1
- package/dist/popover/popover-trigger.mjs +4 -2
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/progress/progress-root.mjs +1 -1
- package/dist/radio-group/radio-group-context.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.d.mts +3 -4
- package/dist/radio-group/radio-group-item.d.mts.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +20 -25
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-label.mjs +1 -6
- package/dist/radio-group/radio-group-label.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +21 -40
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-dom.mjs +9 -18
- package/dist/select/select-dom.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-root.mjs +3 -2
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/slider/slider-arithmetic.mjs +74 -13
- package/dist/slider/slider-arithmetic.mjs.map +1 -1
- package/dist/slider/slider-context.mjs.map +1 -1
- package/dist/slider/slider-label.d.mts.map +1 -1
- package/dist/slider/slider-label.mjs +3 -9
- package/dist/slider/slider-label.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts +2 -2
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +36 -116
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/slider-thumb.d.mts.map +1 -1
- package/dist/slider/slider-thumb.mjs +8 -6
- package/dist/slider/slider-thumb.mjs.map +1 -1
- package/dist/slider/slider-value.d.mts.map +1 -1
- package/dist/slider/slider-value.mjs +2 -1
- package/dist/slider/slider-value.mjs.map +1 -1
- package/dist/slider/use-slider-dev-warnings.mjs +29 -0
- package/dist/slider/use-slider-dev-warnings.mjs.map +1 -0
- package/dist/slider/use-thumb-registry.mjs +51 -0
- package/dist/slider/use-thumb-registry.mjs.map +1 -0
- package/dist/switch/switch.d.mts +4 -5
- package/dist/switch/switch.d.mts.map +1 -1
- package/dist/switch/switch.mjs +15 -55
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-context.d.mts +2 -3
- package/dist/tabs/tabs-context.d.mts.map +1 -1
- package/dist/tabs/tabs-context.mjs.map +1 -1
- package/dist/tabs/tabs-list.d.mts.map +1 -1
- package/dist/tabs/tabs-list.mjs +9 -22
- package/dist/tabs/tabs-list.mjs.map +1 -1
- package/dist/tabs/tabs-panel.d.mts +3 -4
- package/dist/tabs/tabs-panel.d.mts.map +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts +4 -3
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +2 -1
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/tabs/tabs-tab.d.mts +3 -4
- package/dist/tabs/tabs-tab.d.mts.map +1 -1
- package/dist/tabs/tabs-tab.mjs.map +1 -1
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +2 -8
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-context.mjs.map +1 -1
- package/dist/toast/toast-hotkey.mjs +27 -0
- package/dist/toast/toast-hotkey.mjs.map +1 -0
- package/dist/toast/toast-queue.mjs +137 -0
- package/dist/toast/toast-queue.mjs.map +1 -0
- package/dist/toast/toast-root.d.mts.map +1 -1
- package/dist/toast/toast-root.mjs +2 -0
- package/dist/toast/toast-root.mjs.map +1 -1
- package/dist/toast/toast-timers.mjs +65 -0
- package/dist/toast/toast-timers.mjs.map +1 -0
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +30 -235
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/toast.mjs +1 -1
- package/dist/toast/toast.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +52 -0
- package/dist/toast/use-modal-portal-host.mjs.map +1 -0
- package/dist/toggle/toggle.d.mts +3 -4
- package/dist/toggle/toggle.d.mts.map +1 -1
- package/dist/toggle/toggle.mjs +7 -10
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-context.d.mts +2 -1
- package/dist/toggle-group/toggle-group-context.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-context.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-item.d.mts +7 -3
- package/dist/toggle-group/toggle-group-item.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-item.mjs +6 -7
- package/dist/toggle-group/toggle-group-item.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +29 -64
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/toolbar/toolbar-root.d.mts +2 -2
- package/dist/toolbar/toolbar-root.d.mts.map +1 -1
- package/dist/toolbar/toolbar-root.mjs +3 -4
- package/dist/toolbar/toolbar-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.d.mts.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +6 -15
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +2 -2
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.d.mts +2 -1
- package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +3 -2
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/tooltip/use-tooltip-interaction.mjs +4 -3
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/accordion/accordion-context.d.mts +0 -5
- package/dist/accordion/accordion-context.d.mts.map +0 -1
- package/dist/internal/use-popover-root.mjs.map +0 -1
- /package/dist/internal/{use-popover-root.d.mts → use-overlay-root.d.mts} +0 -0
package/dist/toast/toast.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast.mjs","names":[],"sources":["../../src/toast/toast.ts"],"sourcesContent":["// No \"use client\" directive: the manager uses no React and no DOM API beyond `queueMicrotask`,\n// so a Server Component may import `toast` (for its type, or to pass nothing) without a client\n// reference (design/components/toast.md 13). The parts are client modules.\nimport type { ReactNode } from \"react\";\nimport type { Action, ActionDetails, ChangeReason } from \"../internal/types.js\";\n\n/** Announcement priority and role of a toast. */\nexport type ToastPriority = \"normal\" | \"high\";\n\n/** The `action` of a toast: what `Toast.Action` renders and runs by default. */\nexport interface ToastActionOptions {\n /** The Action button's content. */\n readonly label: ReactNode;\n /**\n * Runs in the Action part's own transition (`data-pending` on the Action and the Root, the\n * timer paused). The toast closes with `reason: \"activate\"` when it resolves; a rejection\n * keeps the toast and reaches the nearest Error Boundary above the Viewport. A caught error\n * resolves the action and therefore closes the toast: rethrow after `toast.update` to keep it.\n */\n readonly action: Action<[details: ToastActionDetails]>;\n}\n\nexport interface ToastOptions {\n /** Explicit id: an existing one updates that toast. Default: generated. */\n readonly id?: string | undefined;\n readonly title?: ReactNode;\n readonly description?: ReactNode;\n /** Free-form, rendered as `data-type` on the Root (`\"success\"`, `\"error\"`, ...). */\n readonly type?: string | undefined;\n /**\n * Announcement priority and role: `\"high\"` announces with `ariaNotify` priority `\"high\"` and\n * renders the Root as an `alertdialog`. Default `\"normal\"`.\n */\n readonly priority?: ToastPriority | undefined;\n /**\n * Milliseconds before the toast closes with `reason: \"timeout\"`; `null` never. Default: the\n * Viewport's `duration`, or `null` (persistent) when the toast has an `action`. A timed action\n * toast must keep its action reachable elsewhere too (WCAG 2.2.1).\n */\n readonly duration?: number | null | undefined;\n readonly action?: ToastActionOptions | undefined;\n /**\n * Called once when the toast leaves, with the reason: `\"activate\"` (the Action part settled),\n * `\"dismiss\"` (Close, Escape, `toast.dismiss()`, a promise toast with no message for its\n * outcome) or `\"timeout\"`. Runs in the Viewport's transition; a rejection reaches the boundary\n * above the Viewport. Not called when the Viewport unmounts.\n */\n readonly closeAction?: Action<[details: ToastCloseDetails]> | undefined;\n /**\n * The text `document.ariaNotify()` speaks for this toast; `null` announces nothing. Default:\n * the Viewport's `announce`, else the text of the toast's Title and Description.\n */\n readonly announce?: ((toast: ToastItem) => string | null) | undefined;\n /** Anything the Viewport's children want to render. */\n readonly data?: unknown;\n}\n\n/** A toast in the queue, as the Viewport's `children(state)` receives it. */\nexport interface ToastItem extends ToastOptions {\n readonly id: string;\n /**\n * The promise given to `toast.promise` is unsettled, or an action dispatched through this\n * toast's Action part is in flight.\n */\n readonly pending: boolean;\n /** Closed; kept mounted (and `inert`) for its exit animation. */\n readonly ending: boolean;\n}\n\n/** Details passed to a toast's Action. */\nexport interface ToastActionDetails extends ActionDetails {\n /** The toast's id, so an inline action can `toast.update` or `toast.dismiss` its own toast. */\n readonly id: string;\n}\n\n/** Details passed to a toast's `closeAction`. */\nexport interface ToastCloseDetails extends ActionDetails {\n readonly id: string;\n /** `\"activate\"`, `\"dismiss\"` or `\"timeout\"`. */\n readonly reason: ChangeReason;\n}\n\nexport interface ToastPromiseOptions<T> {\n /** Shown at once, with `data-pending`; no timer until the promise settles. */\n readonly pending: ToastOptions;\n /**\n * Replaces the toast when the promise fulfils; omitted: the toast is dismissed. A function that\n * throws dismisses the toast, and the returned promise rejects with what it threw.\n */\n readonly success?: ToastOptions | ((value: T) => ToastOptions) | undefined;\n /**\n * Replaces the toast when the promise rejects; the returned promise then resolves with\n * `undefined` (the toast is the handler). Omitted: the toast is dismissed and the returned\n * promise rejects with the same reason. A function that throws dismisses the toast, and the\n * returned promise rejects with what it threw.\n */\n readonly error?: ToastOptions | ((reason: unknown) => ToastOptions) | undefined;\n readonly id?: string | undefined;\n}\n\n/** The queue's input: `toast(options)` and its methods. */\nexport interface ToastManager {\n /** Adds a toast (or updates the one with `options.id`) and returns its id. */\n (options: ToastOptions): string;\n readonly add: (options: ToastOptions) => string;\n /**\n * Shows `options.pending` at once and swaps to `success` / `error` when `promise` settles.\n * Returns a promise that settles with `promise`, except that a rejection resolves with\n * `undefined` when `error` was given.\n */\n readonly promise: <T>(\n promise: PromiseLike<T>,\n options: ToastPromiseOptions<T>,\n ) => Promise<T | undefined>;\n /** Changes a toast in place (same position, same element). Unknown or closed ids are ignored. */\n readonly update: (id: string, options: Partial<ToastOptions>) => void;\n /** Closes one toast, or every toast when `id` is omitted, with `reason: \"dismiss\"`. */\n readonly dismiss: (id?: string) => void;\n}\n\n// --- Internal: the command channel between a manager and its Viewport --------------------------\n\n/** A queue mutation, applied by the subscribed Viewport (or buffered until one subscribes). */\nexport type ToastCommand =\n | {\n readonly kind: \"add\";\n readonly id: string;\n readonly options: ToastOptions;\n /** Added by `toast.promise`: pending until the promise settles. */\n readonly pending: boolean;\n }\n | {\n readonly kind: \"update\";\n readonly id: string;\n readonly options: Partial<ToastOptions>;\n /** A promise settle: the options replace the toast's (keeping its id), pending ends. */\n readonly settle: boolean;\n }\n | { readonly kind: \"dismiss\"; readonly id: string | undefined };\n\n/** What a Viewport hands its manager. */\nexport interface ToastListener {\n /**\n * Takes over the toasts a previous Viewport left behind (called on subscribe, before the\n * buffer is applied).\n */\n readonly restore: (toasts: readonly RetainedToast[]) => void;\n /** Applies a batch of commands, in dispatch order. */\n readonly apply: (commands: readonly ToastCommand[]) => void;\n /** The toasts to keep when this Viewport unsubscribes. */\n readonly retain: () => readonly RetainedToast[];\n}\n\n/** A retained queue entry: what a Viewport leaves behind when it unmounts (design 14 item 11). */\nexport interface RetainedToast {\n readonly options: ToastOptions & { readonly id: string };\n readonly pending: boolean;\n /**\n * The text last announced for it (`null`: silenced), so the next Viewport does not announce\n * it again; `undefined` when nothing was announced yet.\n */\n readonly announced?: string | null | undefined;\n}\n\nexport interface ToastManagerInternals {\n /**\n * Sets the listener, hands it the retained toasts and drains the buffer into it. Returns the\n * unsubscribe function, or `null` (changing nothing) when a different listener is subscribed:\n * the second-Viewport case.\n */\n readonly subscribe: (listener: ToastListener) => (() => void) | null;\n /** Whether a listener other than `listener` is subscribed (read during render). */\n readonly isTaken: (listener: ToastListener) => boolean;\n}\n\nconst internals = new WeakMap<ToastManager, ToastManagerInternals>();\n\n/** The command channel of `manager` (library-internal). */\nexport function toastManagerInternals(manager: ToastManager): ToastManagerInternals {\n const value = internals.get(manager);\n if (value === undefined) {\n throw new TypeError(\"Toast.Viewport: `manager` must come from `createToastManager()`.\");\n }\n return value;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nlet warnedServer = false;\n\n/**\n * Generated ids are unique across managers, so a Viewport whose `manager` prop changes never\n * mistakes a late close from the old queue (an Undo settling) for one of the new queue's toasts.\n */\nlet nextId = 0;\n\n/** On the server every method is a no-op, never buffered (design 13, product-owner amendment). */\nfunction onServer(): boolean {\n if (typeof document !== \"undefined\") return false;\n if (isDev && !warnedServer) {\n warnedServer = true;\n console.error(\n \"toast(): called on the server. Toasts are client-only; the call does nothing. Return data \" +\n \"from the Server Function and call `toast()` on the client.\",\n );\n }\n return true;\n}\n\n/** Resets the once-per-process server warning (tests only). */\nexport function resetToastServerWarning(): void {\n warnedServer = false;\n}\n\nfunction resolveOptions<V>(\n options: ToastOptions | ((value: V) => ToastOptions),\n value: V,\n): ToastOptions {\n return typeof options === \"function\" ? options(value) : options;\n}\n\n/**\n * Creates an isolated queue: `<Toast.Viewport manager={m}>` renders it. For a second React root,\n * a micro-frontend, or a test that wants a clean queue. `toast` is the default manager.\n */\nexport function createToastManager(): ToastManager {\n let listener: ToastListener | null = null;\n let retained: readonly RetainedToast[] = [];\n /** Commands issued before any Viewport subscribed (client only). */\n let buffer: ToastCommand[] = [];\n /** Commands of the current tick, flushed together from one microtask. */\n let batch: ToastCommand[] = [];\n let scheduled = false;\n\n const flush = (): void => {\n scheduled = false;\n const commands = batch;\n batch = [];\n if (commands.length === 0) return;\n if (listener !== null) listener.apply(commands);\n else buffer.push(...commands);\n };\n\n // A microtask, not a synchronous dispatch: a call made inside a `startTransition` scope (an\n // action's sync prefix) is no longer inside it when the microtask runs, so the queue update is\n // urgent and shows at once even while the action is pending (design 3.4).\n const dispatch = (command: ToastCommand): void => {\n batch.push(command);\n if (scheduled) return;\n scheduled = true;\n queueMicrotask(flush);\n };\n\n const generateId = (): string => `fsui-toast-${++nextId}`;\n\n const add = (options: ToastOptions): string => {\n const id = options.id ?? generateId();\n if (onServer()) return id;\n dispatch({ kind: \"add\", id, options, pending: false });\n return id;\n };\n\n const update = (id: string, options: Partial<ToastOptions>): void => {\n if (onServer()) return;\n dispatch({ kind: \"update\", id, options, settle: false });\n };\n\n const dismiss = (id?: string): void => {\n if (onServer()) return;\n dispatch({ kind: \"dismiss\", id });\n };\n\n const promise = <T>(\n input: PromiseLike<T>,\n options: ToastPromiseOptions<T>,\n ): Promise<T | undefined> => {\n const { success, error } = options;\n if (onServer()) {\n return Promise.resolve(input).then(\n (value) => value,\n (reason: unknown) => {\n if (error !== undefined) return undefined;\n throw reason;\n },\n );\n }\n const id = options.id ?? options.pending.id ?? generateId();\n dispatch({ kind: \"add\", id, options: options.pending, pending: true });\n // The returned promise is built from the same `then`, so it settles in the same tick as the\n // toast's update and an awaiting action prop is pending exactly as long as the toast.\n // A `success` / `error` function that throws dismisses the toast (it must not stay pending\n // forever) and the returned promise rejects with what it threw: the operation's outcome is\n // known, but its message is not, and the `error` message would misreport a fulfilment.\n const settle = <V>(options: ToastOptions | ((value: V) => ToastOptions), value: V): void => {\n let resolved: ToastOptions;\n try {\n resolved = resolveOptions(options, value);\n } catch (thrown) {\n dismiss(id);\n throw thrown;\n }\n dispatch({ kind: \"update\", id, options: resolved, settle: true });\n };\n return Promise.resolve(input).then(\n (value) => {\n if (success === undefined) dismiss(id);\n else settle(success, value);\n return value;\n },\n (reason: unknown) => {\n if (error === undefined) {\n dismiss(id);\n throw reason;\n }\n settle(error, reason);\n return undefined;\n },\n );\n };\n\n const manager = Object.assign((options: ToastOptions) => add(options), {\n add,\n promise,\n update,\n dismiss,\n }) as ToastManager;\n\n internals.set(manager, {\n subscribe: (next) => {\n if (listener !== null && listener !== next) return null;\n listener = next;\n const handedOver = retained;\n retained = [];\n if (handedOver.length > 0) next.restore(handedOver);\n // Commands issued before this Viewport subscribed, in order.\n const pending = buffer;\n buffer = [];\n if (pending.length > 0) next.apply(pending);\n return () => {\n if (listener !== next) return;\n // The queue survives the Viewport (a route-level Viewport remounting on navigation does\n // not lose an Undo); timers and `closeAction`s do not.\n retained = next.retain();\n listener = null;\n };\n },\n isTaken: (candidate) => listener !== null && listener !== candidate,\n });\n\n return manager;\n}\n\n/**\n * The default toast manager: `toast({ title: \"Saved\" })` from anywhere on the client (action\n * bodies, stores, effects). `<Toast.Viewport>` without `manager` renders it. On the server every\n * call is a no-op.\n */\nexport const toast: ToastManager = createToastManager();\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"toast.mjs","names":[],"sources":["../../src/toast/toast.ts"],"sourcesContent":["// No \"use client\" directive: the manager uses no React and no DOM API beyond `queueMicrotask`,\n// so a Server Component may import `toast` (for its type, or to pass nothing) without a client\n// reference (design/components/toast.md 13). The parts are client modules.\nimport type { ReactNode } from \"react\";\nimport type { Action, ActionDetails, ChangeReason } from \"../internal/types.js\";\n\n/** Announcement priority and role of a toast. */\nexport type ToastPriority = \"normal\" | \"high\";\n\n/** The `action` of a toast: what `Toast.Action` renders and runs by default. */\nexport interface ToastActionOptions {\n /** The Action button's content. */\n readonly label: ReactNode;\n /**\n * Runs in the Action part's own transition (`data-pending` on the Action and the Root, the\n * timer paused). The toast closes with `reason: \"activate\"` when it resolves; a rejection\n * keeps the toast and reaches the nearest Error Boundary above the Viewport. A caught error\n * resolves the action and therefore closes the toast: rethrow after `toast.update` to keep it.\n */\n readonly action: Action<[details: ToastActionDetails]>;\n}\n\nexport interface ToastOptions {\n /** Explicit id: an existing one updates that toast. Default: generated. */\n readonly id?: string | undefined;\n readonly title?: ReactNode;\n readonly description?: ReactNode;\n /** Free-form, rendered as `data-type` on the Root (`\"success\"`, `\"error\"`, ...). */\n readonly type?: string | undefined;\n /**\n * Announcement priority and role: `\"high\"` announces with `ariaNotify` priority `\"high\"` and\n * renders the Root as an `alertdialog`. Default `\"normal\"`.\n */\n readonly priority?: ToastPriority | undefined;\n /**\n * Milliseconds before the toast closes with `reason: \"timeout\"`; `null` never. Default: the\n * Viewport's `duration`, or `null` (persistent) when the toast has an `action`. A timed action\n * toast must keep its action reachable elsewhere too (WCAG 2.2.1).\n */\n readonly duration?: number | null | undefined;\n readonly action?: ToastActionOptions | undefined;\n /**\n * Called once when the toast leaves, with the reason: `\"activate\"` (the Action part settled),\n * `\"dismiss\"` (Close, Escape, `toast.dismiss()`, a promise toast with no message for its\n * outcome) or `\"timeout\"`. Runs in the Viewport's transition; a rejection reaches the boundary\n * above the Viewport. Not called when the Viewport unmounts.\n */\n readonly closeAction?: Action<[details: ToastCloseDetails]> | undefined;\n /**\n * The text `document.ariaNotify()` speaks for this toast; `null` announces nothing. Default:\n * the Viewport's `announce`, else the text of the toast's Title and Description.\n */\n readonly announce?: ((toast: ToastItem) => string | null) | undefined;\n /** Anything the Viewport's children want to render. */\n readonly data?: unknown;\n}\n\n/** A toast in the queue, as the Viewport's `children(state)` receives it. */\nexport interface ToastItem extends ToastOptions {\n readonly id: string;\n /**\n * The promise given to `toast.promise` is unsettled, or an action dispatched through this\n * toast's Action part is in flight.\n */\n readonly pending: boolean;\n /** Closed; kept mounted (and `inert`) for its exit animation. */\n readonly ending: boolean;\n}\n\n/** Details passed to a toast's Action. */\nexport interface ToastActionDetails extends ActionDetails {\n /** The toast's id, so an inline action can `toast.update` or `toast.dismiss` its own toast. */\n readonly id: string;\n}\n\n/** Details passed to a toast's `closeAction`. */\nexport interface ToastCloseDetails extends ActionDetails {\n readonly id: string;\n /** `\"activate\"`, `\"dismiss\"` or `\"timeout\"`. */\n readonly reason: ChangeReason;\n}\n\nexport interface ToastPromiseOptions<T> {\n /** Shown at once, with `data-pending`; no timer until the promise settles. */\n readonly pending: ToastOptions;\n /**\n * Replaces the toast when the promise fulfils; omitted: the toast is dismissed. A function that\n * throws dismisses the toast, and the returned promise rejects with what it threw.\n */\n readonly success?: ToastOptions | ((value: T) => ToastOptions) | undefined;\n /**\n * Replaces the toast when the promise rejects; the returned promise then resolves with\n * `undefined` (the toast is the handler). Omitted: the toast is dismissed and the returned\n * promise rejects with the same reason. A function that throws dismisses the toast, and the\n * returned promise rejects with what it threw.\n */\n readonly error?: ToastOptions | ((reason: unknown) => ToastOptions) | undefined;\n readonly id?: string | undefined;\n}\n\n/** The queue's input: `toast(options)` and its methods. */\nexport interface ToastManager {\n /** Adds a toast (or updates the one with `options.id`) and returns its id. */\n (options: ToastOptions): string;\n readonly add: (options: ToastOptions) => string;\n /**\n * Shows `options.pending` at once and swaps to `success` / `error` when `promise` settles.\n * Returns a promise that settles with `promise`, except that a rejection resolves with\n * `undefined` when `error` was given.\n */\n readonly promise: <T>(\n promise: PromiseLike<T>,\n options: ToastPromiseOptions<T>,\n ) => Promise<T | undefined>;\n /** Changes a toast in place (same position, same element). Unknown or closed ids are ignored. */\n readonly update: (id: string, options: Partial<ToastOptions>) => void;\n /** Closes one toast, or every toast when `id` is omitted, with `reason: \"dismiss\"`. */\n readonly dismiss: (id?: string) => void;\n}\n\n// --- Internal: the command channel between a manager and its Viewport --------------------------\n\n/** A queue mutation, applied by the subscribed Viewport (or buffered until one subscribes). */\nexport type ToastCommand =\n | {\n readonly kind: \"add\";\n readonly id: string;\n readonly options: ToastOptions;\n /** Added by `toast.promise`: pending until the promise settles. */\n readonly pending: boolean;\n }\n | {\n readonly kind: \"update\";\n readonly id: string;\n readonly options: Partial<ToastOptions>;\n /** A promise settle: the options replace the toast's (keeping its id), pending ends. */\n readonly settle: boolean;\n }\n | { readonly kind: \"dismiss\"; readonly id: string | undefined };\n\n/** What a Viewport hands its manager. */\nexport interface ToastListener {\n /**\n * Takes over the toasts a previous Viewport left behind (called on subscribe, before the\n * buffer is applied).\n */\n readonly restore: (toasts: readonly RetainedToast[]) => void;\n /** Applies a batch of commands, in dispatch order. */\n readonly apply: (commands: readonly ToastCommand[]) => void;\n /** The toasts to keep when this Viewport unsubscribes. */\n readonly retain: () => readonly RetainedToast[];\n}\n\n/** A retained queue entry: what a Viewport leaves behind when it unmounts (design 14 item 11). */\nexport interface RetainedToast {\n readonly options: ToastOptions & { readonly id: string };\n readonly pending: boolean;\n /**\n * The text last announced for it (`null`: silenced), so the next Viewport does not announce\n * it again; `undefined` when nothing was announced yet.\n */\n readonly announced?: string | null | undefined;\n}\n\nexport interface ToastManagerInternals {\n /**\n * Sets the listener, hands it the retained toasts and drains the buffer into it. Returns the\n * unsubscribe function, or `null` (changing nothing) when a different listener is subscribed:\n * the second-Viewport case.\n */\n readonly subscribe: (listener: ToastListener) => (() => void) | null;\n /** Whether a listener other than `listener` is subscribed (read during render). */\n readonly isTaken: (listener: ToastListener) => boolean;\n}\n\nconst internals = new WeakMap<ToastManager, ToastManagerInternals>();\n\n/** The command channel of `manager` (library-internal). */\nexport function toastManagerInternals(manager: ToastManager): ToastManagerInternals {\n const value = internals.get(manager);\n if (value === undefined) {\n throw new TypeError(\"Toast.Viewport: `manager` must come from `createToastManager()`.\");\n }\n return value;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nlet warnedServer = false;\n\n/**\n * Generated ids are unique across managers, so a Viewport whose `manager` prop changes never\n * mistakes a late close from the old queue (an Undo settling) for one of the new queue's toasts.\n */\nlet nextId = 0;\n\n/** On the server every method is a no-op, never buffered (design 13). */\nfunction onServer(): boolean {\n if (typeof document !== \"undefined\") return false;\n if (isDev && !warnedServer) {\n warnedServer = true;\n console.error(\n \"toast(): called on the server. Toasts are client-only; the call does nothing. Return data \" +\n \"from the Server Function and call `toast()` on the client.\",\n );\n }\n return true;\n}\n\n/** Resets the once-per-process server warning (tests only). */\nexport function resetToastServerWarning(): void {\n warnedServer = false;\n}\n\nfunction resolveOptions<V>(\n options: ToastOptions | ((value: V) => ToastOptions),\n value: V,\n): ToastOptions {\n return typeof options === \"function\" ? options(value) : options;\n}\n\n/**\n * Creates an isolated queue: `<Toast.Viewport manager={m}>` renders it. For a second React root,\n * a micro-frontend, or a test that wants a clean queue. `toast` is the default manager.\n */\nexport function createToastManager(): ToastManager {\n let listener: ToastListener | null = null;\n let retained: readonly RetainedToast[] = [];\n /** Commands issued before any Viewport subscribed (client only). */\n let buffer: ToastCommand[] = [];\n /** Commands of the current tick, flushed together from one microtask. */\n let batch: ToastCommand[] = [];\n let scheduled = false;\n\n const flush = (): void => {\n scheduled = false;\n const commands = batch;\n batch = [];\n if (commands.length === 0) return;\n if (listener !== null) listener.apply(commands);\n else buffer.push(...commands);\n };\n\n // A microtask, not a synchronous dispatch: a call made inside a `startTransition` scope (an\n // action's sync prefix) is no longer inside it when the microtask runs, so the queue update is\n // urgent and shows at once even while the action is pending (design 3.4).\n const dispatch = (command: ToastCommand): void => {\n batch.push(command);\n if (scheduled) return;\n scheduled = true;\n queueMicrotask(flush);\n };\n\n const generateId = (): string => `fsui-toast-${++nextId}`;\n\n const add = (options: ToastOptions): string => {\n const id = options.id ?? generateId();\n if (onServer()) return id;\n dispatch({ kind: \"add\", id, options, pending: false });\n return id;\n };\n\n const update = (id: string, options: Partial<ToastOptions>): void => {\n if (onServer()) return;\n dispatch({ kind: \"update\", id, options, settle: false });\n };\n\n const dismiss = (id?: string): void => {\n if (onServer()) return;\n dispatch({ kind: \"dismiss\", id });\n };\n\n const promise = <T>(\n input: PromiseLike<T>,\n options: ToastPromiseOptions<T>,\n ): Promise<T | undefined> => {\n const { success, error } = options;\n if (onServer()) {\n return Promise.resolve(input).then(\n (value) => value,\n (reason: unknown) => {\n if (error !== undefined) return undefined;\n throw reason;\n },\n );\n }\n const id = options.id ?? options.pending.id ?? generateId();\n dispatch({ kind: \"add\", id, options: options.pending, pending: true });\n // The returned promise is built from the same `then`, so it settles in the same tick as the\n // toast's update and an awaiting action prop is pending exactly as long as the toast.\n // A `success` / `error` function that throws dismisses the toast (it must not stay pending\n // forever) and the returned promise rejects with what it threw: the operation's outcome is\n // known, but its message is not, and the `error` message would misreport a fulfilment.\n const settle = <V>(options: ToastOptions | ((value: V) => ToastOptions), value: V): void => {\n let resolved: ToastOptions;\n try {\n resolved = resolveOptions(options, value);\n } catch (thrown) {\n dismiss(id);\n throw thrown;\n }\n dispatch({ kind: \"update\", id, options: resolved, settle: true });\n };\n return Promise.resolve(input).then(\n (value) => {\n if (success === undefined) dismiss(id);\n else settle(success, value);\n return value;\n },\n (reason: unknown) => {\n if (error === undefined) {\n dismiss(id);\n throw reason;\n }\n settle(error, reason);\n return undefined;\n },\n );\n };\n\n const manager = Object.assign((options: ToastOptions) => add(options), {\n add,\n promise,\n update,\n dismiss,\n }) as ToastManager;\n\n internals.set(manager, {\n subscribe: (next) => {\n if (listener !== null && listener !== next) return null;\n listener = next;\n const handedOver = retained;\n retained = [];\n if (handedOver.length > 0) next.restore(handedOver);\n // Commands issued before this Viewport subscribed, in order.\n const pending = buffer;\n buffer = [];\n if (pending.length > 0) next.apply(pending);\n return () => {\n if (listener !== next) return;\n // The queue survives the Viewport (a route-level Viewport remounting on navigation does\n // not lose an Undo); timers and `closeAction`s do not.\n retained = next.retain();\n listener = null;\n };\n },\n isTaken: (candidate) => listener !== null && listener !== candidate,\n });\n\n return manager;\n}\n\n/**\n * The default toast manager: `toast({ title: \"Saved\" })` from anywhere on the client (action\n * bodies, stores, effects). `<Toast.Viewport>` without `manager` renders it. On the server every\n * call is a no-op.\n */\nexport const toast: ToastManager = createToastManager();\n"],"mappings":"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"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { getServerTopmostModal, getTopmostModal, subscribeModals } from "../internal/modal-registry.mjs";
|
|
3
|
+
import { useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
//#region src/toast/use-modal-portal-host.ts
|
|
5
|
+
/** No store: `useSyncExternalStore` only tells the hydration render from a client render. */
|
|
6
|
+
const subscribeNothing = () => () => {};
|
|
7
|
+
const onClient = () => true;
|
|
8
|
+
const onServerOrHydrating = () => false;
|
|
9
|
+
/**
|
|
10
|
+
* The element the region is portalled into for its whole client life. The library moves this
|
|
11
|
+
* element (between its inline anchor and the topmost modal dialog); React never sees the move, so
|
|
12
|
+
* the toasts keep their state (an Undo in flight stays pending). `display: contents`: no box.
|
|
13
|
+
*/
|
|
14
|
+
function createHost() {
|
|
15
|
+
if (typeof document === "undefined") return null;
|
|
16
|
+
const host = document.createElement("div");
|
|
17
|
+
host.style.display = "contents";
|
|
18
|
+
return host;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The Viewport's portal host (design/components/toast.md 4.3): in the topmost open modal
|
|
22
|
+
* `Dialog` (a region outside it would be inert), else at its inline anchor. Its layout effect
|
|
23
|
+
* moves the host and must run before the Viewport's region effect: a move hides the popover
|
|
24
|
+
* (removal steps), which that effect shows again in the same commit. `onMove` runs after a move.
|
|
25
|
+
*/
|
|
26
|
+
function useModalPortalHost(onMove) {
|
|
27
|
+
const container = useSyncExternalStore(subscribeModals, getTopmostModal, getServerTopmostModal);
|
|
28
|
+
const portalled = useSyncExternalStore(subscribeNothing, onClient, onServerOrHydrating);
|
|
29
|
+
const [host] = useState(createHost);
|
|
30
|
+
const anchorRef = useRef(null);
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
if (host === null) return;
|
|
33
|
+
return () => host.remove();
|
|
34
|
+
}, [host]);
|
|
35
|
+
useLayoutEffect(() => {
|
|
36
|
+
if (host === null || !portalled) return;
|
|
37
|
+
const target = container ?? anchorRef.current;
|
|
38
|
+
if (target === null || host.parentNode === target) return;
|
|
39
|
+
const moved = host.parentNode !== null;
|
|
40
|
+
target.append(host);
|
|
41
|
+
if (moved) onMove();
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
portalled,
|
|
45
|
+
host,
|
|
46
|
+
anchorRef
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { useModalPortalHost };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=use-modal-portal-host.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-modal-portal-host.mjs","names":[],"sources":["../../src/toast/use-modal-portal-host.ts"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { RefObject } from \"react\";\nimport {\n getServerTopmostModal,\n getTopmostModal,\n subscribeModals,\n} from \"../internal/modal-registry.js\";\n\n/** No store: `useSyncExternalStore` only tells the hydration render from a client render. */\nconst subscribeNothing = (): (() => void) => () => {};\nconst onClient = (): boolean => true;\nconst onServerOrHydrating = (): boolean => false;\n\n/**\n * The element the region is portalled into for its whole client life. The library moves this\n * element (between its inline anchor and the topmost modal dialog); React never sees the move, so\n * the toasts keep their state (an Undo in flight stays pending). `display: contents`: no box.\n */\nfunction createHost(): HTMLElement | null {\n if (typeof document === \"undefined\") return null;\n const host = document.createElement(\"div\");\n host.style.display = \"contents\";\n return host;\n}\n\nexport interface ModalPortalHost {\n /** `false` for the hydration render (and on the server): render the region inline. */\n readonly portalled: boolean;\n /** Portal into it when `portalled`; `null` without a document. */\n readonly host: HTMLElement | null;\n /** For the inline anchor element the host sits in while no modal is open. */\n readonly anchorRef: RefObject<HTMLDivElement | null>;\n}\n\n/**\n * The Viewport's portal host (design/components/toast.md 4.3): in the topmost open modal\n * `Dialog` (a region outside it would be inert), else at its inline anchor. Its layout effect\n * moves the host and must run before the Viewport's region effect: a move hides the popover\n * (removal steps), which that effect shows again in the same commit. `onMove` runs after a move.\n */\nexport function useModalPortalHost(onMove: () => void): ModalPortalHost {\n const container = useSyncExternalStore(subscribeModals, getTopmostModal, getServerTopmostModal);\n // The hydration render matches the server's inline region; every later render portals into\n // `host`, whose place the library changes without React noticing.\n const portalled = useSyncExternalStore(subscribeNothing, onClient, onServerOrHydrating);\n const [host] = useState(createHost);\n const anchorRef = useRef<HTMLDivElement | null>(null);\n\n useLayoutEffect(() => {\n if (host === null) return;\n return () => host.remove();\n }, [host]);\n\n useLayoutEffect(() => {\n if (host === null || !portalled) return;\n const target = container ?? anchorRef.current;\n if (target === null || host.parentNode === target) return;\n const moved = host.parentNode !== null;\n target.append(host);\n if (moved) onMove();\n });\n\n return { portalled, host, anchorRef };\n}\n"],"mappings":";;;;;AAUA,MAAM,+BAA6C,CAAC;AACpD,MAAM,iBAA0B;AAChC,MAAM,4BAAqC;;;;;;AAO3C,SAAS,aAAiC;CACxC,IAAI,OAAO,aAAa,aAAa,OAAO;CAC5C,MAAM,OAAO,SAAS,cAAc,KAAK;CACzC,KAAK,MAAM,UAAU;CACrB,OAAO;AACT;;;;;;;AAiBA,SAAgB,mBAAmB,QAAqC;CACtE,MAAM,YAAY,qBAAqB,iBAAiB,iBAAiB,qBAAqB;CAG9F,MAAM,YAAY,qBAAqB,kBAAkB,UAAU,mBAAmB;CACtF,MAAM,CAAC,QAAQ,SAAS,UAAU;CAClC,MAAM,YAAY,OAA8B,IAAI;CAEpD,sBAAsB;EACpB,IAAI,SAAS,MAAM;EACnB,aAAa,KAAK,OAAO;CAC3B,GAAG,CAAC,IAAI,CAAC;CAET,sBAAsB;EACpB,IAAI,SAAS,QAAQ,CAAC,WAAW;EACjC,MAAM,SAAS,aAAa,UAAU;EACtC,IAAI,WAAW,QAAQ,KAAK,eAAe,QAAQ;EACnD,MAAM,QAAQ,KAAK,eAAe;EAClC,OAAO,OAAO,IAAI;EAClB,IAAI,OAAO,OAAO;CACpB,CAAC;CAED,OAAO;EAAE;EAAW;EAAM;CAAU;AACtC"}
|
package/dist/toggle/toggle.d.mts
CHANGED
|
@@ -34,10 +34,9 @@ export interface ToggleProps extends Omit<ComponentPropsWithRef<"button">, "onCl
|
|
|
34
34
|
* commit that ends an action (and rollbacks), not the optimistic flip itself; animate the flip
|
|
35
35
|
* with a CSS `transition` on `[data-pressed]`.
|
|
36
36
|
*
|
|
37
|
-
* Static:
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* page cross-fades for about 250 ms and the next transition commit waits for it (issue #35).
|
|
37
|
+
* Static: setting or unsetting it remounts the element. Any value, `"none"` included, makes a
|
|
38
|
+
* mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms
|
|
39
|
+
* page cross-fade that the next transition waits for).
|
|
41
40
|
*/
|
|
42
41
|
transition?: ViewTransitionClass;
|
|
43
42
|
className?: StateValue<string | undefined, ToggleState>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.d.mts","names":[],"sources":["../../src/toggle/toggle.tsx"],"mappings":";;;iBAgBiB;;WAEN;;WAEA;;WAEA;;;iBAIM,mCAAmC;iBAKnC,oBAAoB,KACnC;;EAIA;;EAEA;;;;;;;;EAQA,sBAAsB,sBAAsB;;;;;EAK5C
|
|
1
|
+
{"version":3,"file":"toggle.d.mts","names":[],"sources":["../../src/toggle/toggle.tsx"],"mappings":";;;iBAgBiB;;WAEN;;WAEA;;WAEA;;;iBAIM,mCAAmC;iBAKnC,oBAAoB,KACnC;;EAIA;;EAEA;;;;;;;;EAQA,sBAAsB,sBAAsB;;;;;EAK5C;;;;;;;;;;EAUA,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;wBAQvC,SACd,SACA,gBACA,qBACA,UACA,YACA,WACA,OACA,UACA,WACG,QACF,cAAW;yBAXE"}
|
package/dist/toggle/toggle.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createActionDetails } from "../internal/action-details.mjs";
|
|
3
3
|
import { dataAttr } from "../internal/data-attr.mjs";
|
|
4
4
|
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
5
|
-
import {
|
|
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
8
|
import { useControllableAction } from "../internal/use-controllable-action.mjs";
|
|
@@ -24,16 +24,14 @@ function Toggle({ pressed, defaultPressed, pressedChangeAction, disabled = false
|
|
|
24
24
|
prop: "pressed"
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
-
const state = {
|
|
28
|
-
pressed: optimistic,
|
|
29
|
-
pending,
|
|
30
|
-
disabled
|
|
31
|
-
};
|
|
32
|
-
const focusable = !isHostButton(render);
|
|
33
27
|
const element = useRender({
|
|
34
28
|
defaultElement: "button",
|
|
35
29
|
render,
|
|
36
|
-
state
|
|
30
|
+
state: {
|
|
31
|
+
pressed: optimistic,
|
|
32
|
+
pending,
|
|
33
|
+
disabled
|
|
34
|
+
},
|
|
37
35
|
className,
|
|
38
36
|
style,
|
|
39
37
|
children,
|
|
@@ -42,8 +40,7 @@ function Toggle({ pressed, defaultPressed, pressedChangeAction, disabled = false
|
|
|
42
40
|
type: "button"
|
|
43
41
|
} : rest,
|
|
44
42
|
libraryProps: {
|
|
45
|
-
|
|
46
|
-
...focusable && { "aria-disabled": disabled ? true : void 0 },
|
|
43
|
+
...disabledButton(render, disabled).props,
|
|
47
44
|
"aria-pressed": optimistic,
|
|
48
45
|
"data-pressed": dataAttr(optimistic),
|
|
49
46
|
"data-pending": dataAttr(pending),
|
|
@@ -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 {
|
|
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\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\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 /** Initial pressed state in uncontrolled mode. Default `false`. */\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). Default `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 className?: StateValue<string | undefined, ToggleState>;\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 */\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":";;;;;;;;;;;;;;AA2EA,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,4 +1,5 @@
|
|
|
1
|
+
import { Orientation } from "../internal/types.mjs";
|
|
1
2
|
//#region src/toggle-group/toggle-group-context.d.ts
|
|
2
|
-
export type ToggleGroupOrientation =
|
|
3
|
+
export type ToggleGroupOrientation = Orientation;
|
|
3
4
|
//#endregion
|
|
4
5
|
//# sourceMappingURL=toggle-group-context.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group-context.d.mts","names":[],"sources":["../../src/toggle-group/toggle-group-context.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"toggle-group-context.d.mts","names":[],"sources":["../../src/toggle-group/toggle-group-context.ts"],"mappings":";;YAIY,yBAAyB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group-context.mjs","names":[],"sources":["../../src/toggle-group/toggle-group-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\
|
|
1
|
+
{"version":3,"file":"toggle-group-context.mjs","names":[],"sources":["../../src/toggle-group/toggle-group-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { Orientation } from \"../internal/types.js\";\n\nexport type ToggleGroupOrientation = Orientation;\n\nexport interface ToggleGroupContextValue {\n /** Optimistic pressed values: Items render `aria-pressed` from it. */\n readonly optimistic: ReadonlySet<string>;\n /** Committed pressed values; for per-Item pending only (design 5.3). */\n readonly committed: ReadonlySet<string>;\n readonly pending: boolean;\n /** `Root disabled`. */\n readonly disabled: boolean;\n /** The effective orientation: the Toolbar's inside one. */\n readonly orientation: ToggleGroupOrientation;\n /**\n * The value whose Item renders `focusgroupstart` (standalone group with\n * `experimental_focusgroup`): the first pressed enabled Item in document order, else `null`.\n */\n readonly focusgroupStartValue: string | null;\n /** An Item was activated (stable). Computes the patch of design 5.2 against the optimistic set. */\n readonly toggle: (value: string, event: Event) => void;\n /** Registers an Item's element and value; returns the cleanup (stable; used as a callback ref). */\n readonly registerItem: (element: HTMLElement, value: string) => () => void;\n}\n\nexport const ToggleGroupContext = createContext<ToggleGroupContextValue | null>(null);\n\nexport function useToggleGroupContext(part: string): ToggleGroupContextValue {\n const context = use(ToggleGroupContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a ToggleGroup.Root.`);\n }\n return context;\n}\n"],"mappings":";;;AA2BA,MAAa,qBAAqB,cAA8C,IAAI;AAEpF,SAAgB,sBAAsB,MAAuC;CAC3E,MAAM,UAAU,IAAI,kBAAkB;CACtC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,6CAA6C;CAEvE,OAAO;AACT"}
|
|
@@ -3,6 +3,8 @@ import { ToggleGroupOrientation } from "./toggle-group-context.mjs";
|
|
|
3
3
|
import { CSSProperties, ComponentPropsWithRef, ReactNode, ViewTransitionClass } from "react";
|
|
4
4
|
//#region src/toggle-group/toggle-group-item.d.ts
|
|
5
5
|
export interface ToggleGroupItemState {
|
|
6
|
+
/** The Item's `value` prop. */
|
|
7
|
+
readonly value: string;
|
|
6
8
|
/** Optimistic pressed state. */
|
|
7
9
|
readonly pressed: boolean;
|
|
8
10
|
/** The group's action is in flight and this Item's optimistic state differs from its committed one. */
|
|
@@ -23,8 +25,10 @@ export interface ToggleGroupItemProps extends Omit<ComponentPropsWithRef<"button
|
|
|
23
25
|
/**
|
|
24
26
|
* Forwarded as `default` to the Item's `<ViewTransition>`. As on Toggle: animates the commit
|
|
25
27
|
* that ends the group's action (and rollbacks), not the optimistic flip, which is a CSS
|
|
26
|
-
* `transition` on `[data-pressed]`.
|
|
27
|
-
*
|
|
28
|
+
* `transition` on `[data-pressed]`.
|
|
29
|
+
* Static: setting or unsetting it remounts the element. Any value, `"none"` included, makes a
|
|
30
|
+
* mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms
|
|
31
|
+
* page cross-fade that the next transition waits for).
|
|
28
32
|
*/
|
|
29
33
|
transition?: ViewTransitionClass;
|
|
30
34
|
className?: StateValue<string | undefined, ToggleGroupItemState>;
|
|
@@ -39,7 +43,7 @@ export interface ToggleGroupItemProps extends Omit<ComponentPropsWithRef<"button
|
|
|
39
43
|
* pressed state is the Root's (design/components/toggle-group.md 16.3). Its `tabindex` is written
|
|
40
44
|
* by the roving engine (the group's, or the enclosing Toolbar's).
|
|
41
45
|
*
|
|
42
|
-
* Owned keys (conventions 1.2): `
|
|
46
|
+
* Owned keys (conventions 1.2): `aria-pressed`, `disabled`,
|
|
43
47
|
* `aria-disabled` (link or component `render`), `data-pressed`, `data-pending`, `data-disabled`, `data-orientation`, `onClick`, and
|
|
44
48
|
* `focusgroupstart` while the Root renders `focusgroup`.
|
|
45
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group-item.d.mts","names":[],"sources":["../../src/toggle-group/toggle-group-item.tsx"],"mappings":";;;;iBAgBiB;;WAEN;;WAEA;;WAEA;WACA,aAAa;;iBAGP,6BAA6B,KAC5C;;EAIA;;;;;;EAMA
|
|
1
|
+
{"version":3,"file":"toggle-group-item.d.mts","names":[],"sources":["../../src/toggle-group/toggle-group-item.tsx"],"mappings":";;;;iBAgBiB;;WAEN;;WAEA;;WAEA;;WAEA;WACA,aAAa;;iBAGP,6BAA6B,KAC5C;;EAIA;;;;;;EAMA;;;;;;;;;EASA,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;wBAYvC,kBACd,OACA,UAAU,cACV,YACA,WACA,OACA,UACA,WACG,QACF,uBAAoB;yBATP"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
3
|
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { disabledButton, rendersButton } from "../internal/render-element.mjs";
|
|
5
5
|
import { useRender } from "../internal/use-render.mjs";
|
|
6
6
|
import { useToggleGroupContext } from "./toggle-group-context.mjs";
|
|
7
7
|
import { useCallback } from "react";
|
|
@@ -11,7 +11,7 @@ import { useCallback } from "react";
|
|
|
11
11
|
* pressed state is the Root's (design/components/toggle-group.md 16.3). Its `tabindex` is written
|
|
12
12
|
* by the roving engine (the group's, or the enclosing Toolbar's).
|
|
13
13
|
*
|
|
14
|
-
* Owned keys (conventions 1.2): `
|
|
14
|
+
* Owned keys (conventions 1.2): `aria-pressed`, `disabled`,
|
|
15
15
|
* `aria-disabled` (link or component `render`), `data-pressed`, `data-pending`, `data-disabled`, `data-orientation`, `onClick`, and
|
|
16
16
|
* `focusgroupstart` while the Root renders `focusgroup`.
|
|
17
17
|
*/
|
|
@@ -20,10 +20,10 @@ function ToggleGroupItem({ value, disabled: disabledProp = false, transition, cl
|
|
|
20
20
|
const pressed = ctx.optimistic.has(value);
|
|
21
21
|
const pending = ctx.pending && pressed !== ctx.committed.has(value);
|
|
22
22
|
const disabled = ctx.disabled || disabledProp;
|
|
23
|
-
const {
|
|
24
|
-
const registerRef = useCallback((el) =>
|
|
25
|
-
const focusable = !isHostButton(render);
|
|
23
|
+
const { registerItem } = ctx;
|
|
24
|
+
const registerRef = useCallback((el) => registerItem(el, value), [registerItem, value]);
|
|
26
25
|
const state = {
|
|
26
|
+
value,
|
|
27
27
|
pressed,
|
|
28
28
|
pending,
|
|
29
29
|
disabled,
|
|
@@ -41,8 +41,7 @@ function ToggleGroupItem({ value, disabled: disabledProp = false, transition, cl
|
|
|
41
41
|
type: "button"
|
|
42
42
|
} : rest,
|
|
43
43
|
libraryProps: {
|
|
44
|
-
|
|
45
|
-
...focusable && { "aria-disabled": disabled ? true : void 0 },
|
|
44
|
+
...disabledButton(render, disabled).props,
|
|
46
45
|
"aria-pressed": pressed,
|
|
47
46
|
"data-pressed": dataAttr(pressed),
|
|
48
47
|
"data-pending": dataAttr(pending),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group-item.mjs","names":[],"sources":["../../src/toggle-group/toggle-group-item.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"toggle-group-item.mjs","names":[],"sources":["../../src/toggle-group/toggle-group-item.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport { useToggleGroupContext } from \"./toggle-group-context.js\";\nimport type { ToggleGroupOrientation } from \"./toggle-group-context.js\";\n\nexport interface ToggleGroupItemState {\n /** The Item's `value` prop. */\n readonly value: string;\n /** Optimistic pressed state. */\n readonly pressed: boolean;\n /** The group's action is in flight and this Item's optimistic state differs from its committed one. */\n readonly pending: boolean;\n /** Own `disabled` or the Root's. */\n readonly disabled: boolean;\n readonly orientation: ToggleGroupOrientation;\n}\n\nexport interface ToggleGroupItemProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"type\" | \"value\" | \"tabIndex\" | \"aria-pressed\" | \"className\" | \"style\" | \"children\"\n> {\n /** The value this Item presses. Unique within the group. */\n value: string;\n /**\n * Never dispatches. Native `disabled` on a `<button>` (skipped by the arrow keys); with a link\n * or component `render`, `aria-disabled=\"true\"` instead: the element stays focusable and the\n * arrow keys reach it (the APG Toolbar behaviour).\n */\n disabled?: boolean;\n /**\n * Forwarded as `default` to the Item's `<ViewTransition>`. As on Toggle: animates the commit\n * that ends the group's action (and rollbacks), not the optimistic flip, which is a CSS\n * `transition` on `[data-pressed]`.\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 className?: StateValue<string | undefined, ToggleGroupItemState>;\n style?: StateValue<CSSProperties | undefined, ToggleGroupItemState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, ToggleGroupItemState>;\n /** Must be, or render, a `<button>` (a toggle is a button). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ToggleGroupItemState>;\n}\n\n/**\n * One toggle of a ToggleGroup: the `Toggle` element (`<button type=\"button\" aria-pressed>`) whose\n * pressed state is the Root's (design/components/toggle-group.md 16.3). Its `tabindex` is written\n * by the roving engine (the group's, or the enclosing Toolbar's).\n *\n * Owned keys (conventions 1.2): `aria-pressed`, `disabled`,\n * `aria-disabled` (link or component `render`), `data-pressed`, `data-pending`, `data-disabled`, `data-orientation`, `onClick`, and\n * `focusgroupstart` while the Root renders `focusgroup`.\n */\nexport function ToggleGroupItem({\n value,\n disabled: disabledProp = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: ToggleGroupItemProps) {\n const ctx = useToggleGroupContext(\"ToggleGroup.Item\");\n const pressed = ctx.optimistic.has(value);\n const pending = ctx.pending && pressed !== ctx.committed.has(value);\n const disabled = ctx.disabled || disabledProp;\n const { registerItem } = ctx;\n const registerRef = useCallback(\n (el: HTMLElement) => registerItem(el, value),\n [registerItem, value],\n );\n\n const state: ToggleGroupItemState = {\n value,\n pressed,\n pending,\n disabled,\n orientation: ctx.orientation,\n };\n\n const element = useRender<ComponentPropsWithRef<\"button\">, ToggleGroupItemState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n // Pass-through layer, as Toggle: a `render` element's own `type` wins.\n props: rendersButton(render) ? { ...rest, type: \"button\" } : rest,\n libraryProps: {\n ...disabledButton(render, disabled).props,\n \"aria-pressed\": pressed,\n \"data-pressed\": dataAttr(pressed),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n \"data-orientation\": ctx.orientation,\n ...(ctx.focusgroupStartValue !== null && {\n focusgroupstart: ctx.focusgroupStartValue === value ? \"\" : undefined,\n }),\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n // Native buttons do not fire `click` when disabled; the guard covers `render` elements\n // (a link must not navigate either).\n if (disabled) {\n event.preventDefault();\n return;\n }\n ctx.toggle(value, event.nativeEvent);\n },\n },\n ref: registerRef,\n });\n\n return useTransitionBoundary(\"ToggleGroup.Item\", transition, element);\n}\n\nToggleGroupItem.displayName = \"ToggleGroupItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,SAAgB,gBAAgB,EAC9B,OACA,UAAU,eAAe,OACzB,YACA,WACA,OACA,UACA,QACA,GAAG,QACoB;CACvB,MAAM,MAAM,sBAAsB,kBAAkB;CACpD,MAAM,UAAU,IAAI,WAAW,IAAI,KAAK;CACxC,MAAM,UAAU,IAAI,WAAW,YAAY,IAAI,UAAU,IAAI,KAAK;CAClE,MAAM,WAAW,IAAI,YAAY;CACjC,MAAM,EAAE,iBAAiB;CACzB,MAAM,cAAc,aACjB,OAAoB,aAAa,IAAI,KAAK,GAC3C,CAAC,cAAc,KAAK,CACtB;CAEA,MAAM,QAA8B;EAClC;EACA;EACA;EACA;EACA,aAAa,IAAI;CACnB;CAEA,MAAM,UAAU,UAAiE;EAC/E,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EAEA,OAAO,cAAc,MAAM,IAAI;GAAE,GAAG;GAAM,MAAM;EAAS,IAAI;EAC7D,cAAc;GACZ,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;GACpC,gBAAgB;GAChB,gBAAgB,SAAS,OAAO;GAChC,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;GAClC,oBAAoB,IAAI;GACxB,GAAI,IAAI,yBAAyB,QAAQ,EACvC,iBAAiB,IAAI,yBAAyB,QAAQ,KAAK,KAAA,EAC7D;GACA,UAAU,UAAyC;IAGjD,IAAI,UAAU;KACZ,MAAM,eAAe;KACrB;IACF;IACA,IAAI,OAAO,OAAO,MAAM,WAAW;GACrC;EACF;EACA,KAAK;CACP,CAAC;CAED,OAAO,sBAAsB,oBAAoB,YAAY,OAAO;AACtE;AAEA,gBAAgB,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":";;;;;iBA2BiB,sCAAsC;;WAE5C;;WAEA;;iBAGM;;;;;;WAMN;;WAEA;WACA;;WAEA,aAAa;;UAGd,iCAAiC,KACzC;;EAYA,cAAc;;EAEd;;EAEA;;;;;;;EAOA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;iBAGnC,iCAAiC;EAChD;;EAEA;;EAEA;;;;;;;;;EASA,oBAAoB,uBAAuB;;EAE3C;;iBAGe,kCAAkC;;EAEjD;;EAEA;;EAEA;;;;;;EAMA;;EAEA,oBAAoB,4BAA4B;;;YAItC,uBAAuB,2BAA2B;;;;;;;;;;wBAkC9C,gBAAgB,OAAO,uCAAoB,IAAA;yBAA3C"}
|
|
@@ -8,44 +8,19 @@ import { transitionTypes } from "../internal/transition-types.mjs";
|
|
|
8
8
|
import { useLatest } from "../internal/use-latest.mjs";
|
|
9
9
|
import { useControllableAction } from "../internal/use-controllable-action.mjs";
|
|
10
10
|
import { ToggleGroupContext } from "./toggle-group-context.mjs";
|
|
11
|
+
import { compareDocumentOrder } from "../internal/dom-order.mjs";
|
|
12
|
+
import { EMPTY_SET, applyPatch, arraysEqual, sortByOrder, toSet } from "../internal/value-set.mjs";
|
|
13
|
+
import { useItemOrder } from "../internal/use-item-order.mjs";
|
|
14
|
+
import { useNativeFocusgroup } from "../internal/use-native-focusgroup.mjs";
|
|
11
15
|
import { useRovingFocus } from "../internal/use-roving-focus.mjs";
|
|
12
|
-
import { useCallback,
|
|
16
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
13
17
|
import { jsx } from "react/jsx-runtime";
|
|
14
18
|
//#region src/toggle-group/toggle-group-root.tsx
|
|
15
19
|
const isDev = process.env.NODE_ENV !== "production";
|
|
16
|
-
const EMPTY = /* @__PURE__ */ new Set();
|
|
17
|
-
function toSet(value) {
|
|
18
|
-
if (value === null) return EMPTY;
|
|
19
|
-
return typeof value === "string" ? /* @__PURE__ */ new Set([value]) : new Set(value);
|
|
20
|
-
}
|
|
21
|
-
/** The optimistic reducer (design 5.2): apply a patch, so stacked dispatches re-base. */
|
|
22
|
-
function reduce(set, patch) {
|
|
23
|
-
const next = new Set(set);
|
|
24
|
-
for (const v of patch.removed) next.delete(v);
|
|
25
|
-
for (const v of patch.added) next.add(v);
|
|
26
|
-
return next;
|
|
27
|
-
}
|
|
28
|
-
/** `values` sorted by `order`; values not in `order` keep their iteration order, last. */
|
|
29
|
-
function sortByOrder(values, order) {
|
|
30
|
-
const wanted = new Set(values);
|
|
31
|
-
const sorted = [];
|
|
32
|
-
for (const v of order) if (wanted.delete(v)) sorted.push(v);
|
|
33
|
-
for (const v of wanted) sorted.push(v);
|
|
34
|
-
return sorted;
|
|
35
|
-
}
|
|
36
|
-
function arraysEqual(a, b) {
|
|
37
|
-
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
38
|
-
}
|
|
39
|
-
function byDocumentOrder(a, b) {
|
|
40
|
-
if (a === b) return 0;
|
|
41
|
-
return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
42
|
-
}
|
|
43
20
|
/** Standalone entry (design 6.2): the first pressed item, else the first item (radio-like). */
|
|
44
21
|
function pressedFirst(items) {
|
|
45
22
|
return items.find((el) => el.getAttribute("aria-pressed") === "true") ?? items[0];
|
|
46
23
|
}
|
|
47
|
-
/** Engine capabilities never change while the page lives. */
|
|
48
|
-
const subscribeNever = () => () => {};
|
|
49
24
|
const NO_LAYOUT = {
|
|
50
25
|
order: [],
|
|
51
26
|
disabled: []
|
|
@@ -63,39 +38,39 @@ function ToggleGroupRoot(props) {
|
|
|
63
38
|
const { exclusive = false, value, defaultValue, valueChangeAction, deselectable = true, orientation: orientationProp, loop: loopProp, disabled = false, experimental_focusgroup: focusgroupProp, className, style, children, render, ...rest } = props;
|
|
64
39
|
const toolbar = useToolbarContext();
|
|
65
40
|
const inToolbar = toolbar !== null;
|
|
66
|
-
useDevWarning(inToolbar && orientationProp !== void 0, "ToggleGroup.Root: `orientation` is ignored inside a Toolbar.Root; the group follows the Toolbar's orientation.");
|
|
67
|
-
useDevWarning(inToolbar && loopProp !== void 0, "ToggleGroup.Root: `loop` is ignored inside a Toolbar.Root; the Toolbar's `loop` applies.");
|
|
68
|
-
useDevWarning(inToolbar && focusgroupProp === true, "ToggleGroup.Root: `experimental_focusgroup` is ignored inside a Toolbar.Root. A nested focusgroup would split the Toolbar's single Tab stop; set the flag on the Toolbar.Root.");
|
|
41
|
+
useDevWarning(inToolbar && orientationProp !== void 0, isDev && "ToggleGroup.Root: `orientation` is ignored inside a Toolbar.Root; the group follows the Toolbar's orientation.");
|
|
42
|
+
useDevWarning(inToolbar && loopProp !== void 0, isDev && "ToggleGroup.Root: `loop` is ignored inside a Toolbar.Root; the Toolbar's `loop` applies.");
|
|
43
|
+
useDevWarning(inToolbar && focusgroupProp === true, isDev && "ToggleGroup.Root: `experimental_focusgroup` is ignored inside a Toolbar.Root. A nested focusgroup would split the Toolbar's single Tab stop; set the flag on the Toolbar.Root.");
|
|
69
44
|
const orientation = toolbar?.orientation ?? orientationProp ?? "horizontal";
|
|
70
45
|
const loop = loopProp ?? true;
|
|
71
46
|
const flag = !inToolbar && focusgroupProp === true;
|
|
72
47
|
const [mountExclusive] = useState(exclusive);
|
|
73
|
-
useDevWarning(mountExclusive !== exclusive, "ToggleGroup.Root: `exclusive` changed after mount. Switching between exclusive and multiple mode is not supported; the group keeps the mode it mounted with.");
|
|
48
|
+
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.");
|
|
74
49
|
const controlledKey = value === void 0 ? void 0 : JSON.stringify(value);
|
|
75
50
|
const controlledSet = useMemo(() => controlledKey === void 0 ? void 0 : toSet(JSON.parse(controlledKey)), [controlledKey]);
|
|
76
51
|
const defaultKey = defaultValue === void 0 ? void 0 : JSON.stringify(defaultValue);
|
|
77
52
|
const defaultSet = useMemo(() => defaultKey === void 0 ? void 0 : toSet(JSON.parse(defaultKey)), [defaultKey]);
|
|
78
53
|
const registry = useRef(/* @__PURE__ */ new Map());
|
|
79
|
-
const
|
|
54
|
+
const registerItem = useCallback((element, itemValue) => {
|
|
80
55
|
registry.current.set(element, itemValue);
|
|
81
56
|
return () => {
|
|
82
57
|
registry.current.delete(element);
|
|
83
58
|
};
|
|
84
59
|
}, []);
|
|
85
|
-
const sortedItems = () => [...registry.current].sort(([a], [b]) =>
|
|
60
|
+
const sortedItems = () => [...registry.current].sort(([a], [b]) => compareDocumentOrder(a, b));
|
|
86
61
|
/** Sorts by the Items' current document order. Reads the DOM: handlers and effects only. */
|
|
87
62
|
const sortByDocument = (values) => sortByOrder(values, sortedItems().map(([, v]) => v));
|
|
88
63
|
const { optimistic, committed, pending, dispatch } = useControllableAction({
|
|
89
64
|
controlled: controlledSet,
|
|
90
65
|
defaultValue: defaultSet,
|
|
91
|
-
initialValue:
|
|
66
|
+
initialValue: EMPTY_SET,
|
|
92
67
|
action: valueChangeAction && ((next, details) => valueChangeAction(mountExclusive ? [...next][0] ?? null : sortByDocument(next), details)),
|
|
93
68
|
transitionTypes: (_next, _prev, details) => [
|
|
94
69
|
...transitionTypes("toggle-group"),
|
|
95
70
|
...details.added.length > 0 ? ["fsui-toggle-group-press"] : [],
|
|
96
71
|
...details.removed.length > 0 ? ["fsui-toggle-group-release"] : []
|
|
97
72
|
],
|
|
98
|
-
reducer: (prev, _next, details) =>
|
|
73
|
+
reducer: (prev, _next, details) => applyPatch(prev, details),
|
|
99
74
|
warn: {
|
|
100
75
|
component: "ToggleGroup.Root",
|
|
101
76
|
prop: "value"
|
|
@@ -119,32 +94,22 @@ function ToggleGroupRoot(props) {
|
|
|
119
94
|
added: [itemValue],
|
|
120
95
|
removed: exclusive ? [...optimistic] : []
|
|
121
96
|
};
|
|
122
|
-
dispatch(
|
|
97
|
+
dispatch(applyPatch(optimistic, patch), createActionDetails(event, patch));
|
|
123
98
|
}, [dispatch, latest]);
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
if (!isDev || warnedDuplicate.current) return;
|
|
138
|
-
const duplicate = order.find((v, i) => order.indexOf(v) !== i);
|
|
139
|
-
if (duplicate !== void 0) {
|
|
140
|
-
warnedDuplicate.current = true;
|
|
141
|
-
console.error(`ToggleGroup.Item: two Items share the value "${duplicate}" in one ToggleGroup.Root. Item values must be unique; both follow the same pressed state.`);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
useLayoutEffect(() => {
|
|
145
|
-
syncLayout();
|
|
99
|
+
const { layout, renderedValue } = useItemOrder({
|
|
100
|
+
optimistic,
|
|
101
|
+
initial: NO_LAYOUT,
|
|
102
|
+
read: () => {
|
|
103
|
+
const items = sortedItems();
|
|
104
|
+
return {
|
|
105
|
+
order: items.map(([, v]) => v),
|
|
106
|
+
disabled: items.filter(([el]) => el.matches(":disabled")).map(([, v]) => v)
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
changed: (prev, next) => flag && (!arraysEqual(next.order, prev.order) || !arraysEqual(next.disabled, prev.disabled)),
|
|
110
|
+
duplicateMessage: isDev && ((duplicate) => `ToggleGroup.Item: two Items share the value "${duplicate}" in one ToggleGroup.Root. Item values must be unique; both follow the same pressed state.`)
|
|
146
111
|
});
|
|
147
|
-
const native =
|
|
112
|
+
const native = useNativeFocusgroup(flag);
|
|
148
113
|
const focusgroupStartValue = flag && !disabled ? renderedValue.find((v) => (layout.order.length === 0 || layout.order.includes(v)) && !layout.disabled.includes(v)) ?? null : null;
|
|
149
114
|
const rootRef = useRef(null);
|
|
150
115
|
const roving = useRovingFocus(rootRef, {
|
|
@@ -163,7 +128,7 @@ function ToggleGroupRoot(props) {
|
|
|
163
128
|
orientation,
|
|
164
129
|
focusgroupStartValue,
|
|
165
130
|
toggle,
|
|
166
|
-
|
|
131
|
+
registerItem
|
|
167
132
|
}), [
|
|
168
133
|
optimistic,
|
|
169
134
|
committed,
|
|
@@ -172,7 +137,7 @@ function ToggleGroupRoot(props) {
|
|
|
172
137
|
orientation,
|
|
173
138
|
focusgroupStartValue,
|
|
174
139
|
toggle,
|
|
175
|
-
|
|
140
|
+
registerItem
|
|
176
141
|
]);
|
|
177
142
|
const state = {
|
|
178
143
|
value: renderedValue,
|