@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20
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 +2 -2
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +3 -20
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
- package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
- package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
- package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
- package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
- package/dist/alert-dialog/index.d.mts +33 -0
- package/dist/alert-dialog/index.d.mts.map +1 -0
- package/dist/alert-dialog/index.mjs +33 -0
- package/dist/alert-dialog/index.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
- package/dist/collapsible/collapsible-context.mjs +8 -0
- package/dist/collapsible/collapsible-context.mjs.map +1 -0
- package/dist/collapsible/collapsible-panel.d.mts +53 -0
- package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
- package/dist/collapsible/collapsible-panel.mjs +41 -0
- package/dist/collapsible/collapsible-panel.mjs.map +1 -0
- package/dist/collapsible/collapsible-root.d.mts +108 -0
- package/dist/collapsible/collapsible-root.d.mts.map +1 -0
- package/dist/collapsible/collapsible-root.mjs +147 -0
- package/dist/collapsible/collapsible-root.mjs.map +1 -0
- package/dist/collapsible/collapsible-trigger.d.mts +45 -0
- package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
- package/dist/collapsible/collapsible-trigger.mjs +62 -0
- package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
- package/dist/collapsible/index.d.mts +21 -0
- package/dist/collapsible/index.d.mts.map +1 -0
- package/dist/collapsible/index.mjs +21 -0
- package/dist/collapsible/index.mjs.map +1 -0
- package/dist/combobox/chip-text.mjs +24 -0
- package/dist/combobox/chip-text.mjs.map +1 -0
- package/dist/combobox/combobox-chips.d.mts +159 -0
- package/dist/combobox/combobox-chips.d.mts.map +1 -0
- package/dist/combobox/combobox-chips.mjs +198 -0
- package/dist/combobox/combobox-chips.mjs.map +1 -0
- package/dist/combobox/combobox-clear.d.mts +5 -2
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +3 -1
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs +4 -5
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts +10 -3
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +13 -5
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +50 -4
- package/dist/combobox/combobox-keyboard.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts +1 -1
- package/dist/combobox/combobox-list.mjs +2 -1
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts +5 -2
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +4 -3
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +127 -35
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +396 -44
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/index.d.mts +8 -2
- package/dist/combobox/index.d.mts.map +1 -1
- package/dist/combobox/index.mjs +7 -1
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/combobox/use-combobox-form.mjs +2 -3
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/dialog/dialog-close.d.mts +9 -5
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +19 -8
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.d.mts +2 -0
- package/dist/dialog/dialog-context.mjs +14 -2
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-description.d.mts +2 -1
- package/dist/dialog/dialog-description.d.mts.map +1 -1
- package/dist/dialog/dialog-description.mjs +8 -4
- package/dist/dialog/dialog-description.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts +2 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +11 -6
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +2 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +23 -14
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts +2 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +15 -5
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-title.d.mts +2 -1
- package/dist/dialog/dialog-title.d.mts.map +1 -1
- package/dist/dialog/dialog-title.mjs +8 -4
- package/dist/dialog/dialog-title.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 +14 -9
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/accordion.md +2 -0
- package/dist/docs/components/alert-dialog.md +546 -0
- package/dist/docs/components/collapsible.md +408 -0
- package/dist/docs/components/combobox.md +288 -26
- package/dist/docs/components/dialog.md +7 -5
- package/dist/docs/components/field.md +180 -3
- package/dist/docs/components/hover-card.md +494 -0
- package/dist/docs/components/multi-select.md +622 -0
- package/dist/docs/components/number-field.md +1 -1
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/select.md +9 -1
- package/dist/docs/components/separator.md +182 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/components/tooltip.md +1 -1
- package/dist/docs/concepts/experimental.md +3 -3
- package/dist/docs/concepts/server-components.md +1 -1
- package/dist/docs/index.md +7 -2
- package/dist/docs/roadmap.md +8 -0
- package/dist/field/field-control.d.mts +13 -4
- package/dist/field/field-control.d.mts.map +1 -1
- package/dist/field/field-control.mjs +39 -10
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-label.d.mts +6 -2
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +12 -2
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +9 -1
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/hover-card/hover-card-context.mjs +13 -0
- package/dist/hover-card/hover-card-context.mjs.map +1 -0
- package/dist/hover-card/hover-card-popup.d.mts +102 -0
- package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
- package/dist/hover-card/hover-card-popup.mjs +80 -0
- package/dist/hover-card/hover-card-popup.mjs.map +1 -0
- package/dist/hover-card/hover-card-root.d.mts +94 -0
- package/dist/hover-card/hover-card-root.d.mts.map +1 -0
- package/dist/hover-card/hover-card-root.mjs +74 -0
- package/dist/hover-card/hover-card-root.mjs.map +1 -0
- package/dist/hover-card/hover-card-trigger.d.mts +65 -0
- package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
- package/dist/hover-card/hover-card-trigger.mjs +109 -0
- package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
- package/dist/hover-card/index.d.mts +24 -0
- package/dist/hover-card/index.d.mts.map +1 -0
- package/dist/hover-card/index.mjs +24 -0
- package/dist/hover-card/index.mjs.map +1 -0
- package/dist/hover-card/use-hover-card-interest.mjs +242 -0
- package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
- package/dist/index.d.mts +38 -9
- package/dist/index.mjs +6 -1
- package/dist/internal/action/use-multiple-selection.mjs +83 -0
- package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
- package/dist/internal/details-summary.mjs +56 -0
- package/dist/internal/details-summary.mjs.map +1 -0
- package/dist/internal/form/field-context.mjs.map +1 -1
- package/dist/internal/form/hidden-values.mjs +29 -0
- package/dist/internal/form/hidden-values.mjs.map +1 -0
- package/dist/internal/form/validity.mjs +3 -1
- package/dist/internal/form/validity.mjs.map +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-close.mjs +5 -3
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +4 -1
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-popup.mjs +20 -7
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
- package/dist/internal/typeahead.mjs +52 -0
- package/dist/internal/typeahead.mjs.map +1 -0
- package/dist/{combobox → internal}/use-active-option.mjs +8 -6
- package/dist/internal/use-active-option.mjs.map +1 -0
- package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
- package/dist/internal/use-deferred-leave.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +57 -1
- package/dist/internal/use-name-warning.mjs.map +1 -1
- package/dist/internal/use-option-registry.mjs +70 -0
- package/dist/internal/use-option-registry.mjs.map +1 -0
- package/dist/menu/use-menu-keyboard.mjs +7 -27
- package/dist/menu/use-menu-keyboard.mjs.map +1 -1
- package/dist/multi-select/index.d.mts +37 -0
- package/dist/multi-select/index.d.mts.map +1 -0
- package/dist/multi-select/index.mjs +37 -0
- package/dist/multi-select/index.mjs.map +1 -0
- package/dist/multi-select/multi-select-context.mjs +19 -0
- package/dist/multi-select/multi-select-context.mjs.map +1 -0
- package/dist/multi-select/multi-select-group.d.mts +120 -0
- package/dist/multi-select/multi-select-group.d.mts.map +1 -0
- package/dist/multi-select/multi-select-group.mjs +111 -0
- package/dist/multi-select/multi-select-group.mjs.map +1 -0
- package/dist/multi-select/multi-select-keyboard.mjs +145 -0
- package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
- package/dist/multi-select/multi-select-label.d.mts +42 -0
- package/dist/multi-select/multi-select-label.d.mts.map +1 -0
- package/dist/multi-select/multi-select-label.mjs +41 -0
- package/dist/multi-select/multi-select-label.mjs.map +1 -0
- package/dist/multi-select/multi-select-list.d.mts +47 -0
- package/dist/multi-select/multi-select-list.d.mts.map +1 -0
- package/dist/multi-select/multi-select-list.mjs +65 -0
- package/dist/multi-select/multi-select-list.mjs.map +1 -0
- package/dist/multi-select/multi-select-option.d.mts +68 -0
- package/dist/multi-select/multi-select-option.d.mts.map +1 -0
- package/dist/multi-select/multi-select-option.mjs +93 -0
- package/dist/multi-select/multi-select-option.mjs.map +1 -0
- package/dist/multi-select/multi-select-popup.d.mts +58 -0
- package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
- package/dist/multi-select/multi-select-popup.mjs +71 -0
- package/dist/multi-select/multi-select-popup.mjs.map +1 -0
- package/dist/multi-select/multi-select-root.d.mts +125 -0
- package/dist/multi-select/multi-select-root.d.mts.map +1 -0
- package/dist/multi-select/multi-select-root.mjs +257 -0
- package/dist/multi-select/multi-select-root.mjs.map +1 -0
- package/dist/multi-select/multi-select-trigger.d.mts +66 -0
- package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
- package/dist/multi-select/multi-select-trigger.mjs +169 -0
- package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
- package/dist/multi-select/multi-select-value.d.mts +57 -0
- package/dist/multi-select/multi-select-value.d.mts.map +1 -0
- package/dist/multi-select/multi-select-value.mjs +41 -0
- package/dist/multi-select/multi-select-value.mjs.map +1 -0
- package/dist/number-field/number-field-root.mjs +1 -1
- package/dist/number-field/use-step-button.d.mts.map +1 -1
- package/dist/number-field/use-step-button.mjs +11 -2
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +6 -3
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +3 -2
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.mjs +1 -1
- package/dist/select/select-root.d.mts +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +5 -1
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/separator/index.d.mts +3 -0
- package/dist/separator/index.mjs +1 -0
- package/dist/separator/separator.d.mts +58 -0
- package/dist/separator/separator.d.mts.map +1 -0
- package/dist/separator/separator.mjs +41 -0
- package/dist/separator/separator.mjs.map +1 -0
- package/dist/slider/slider-root.mjs +1 -0
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.mjs +1 -1
- package/package.json +6 -1
- package/skills/funstack-ui-knowledge/SKILL.md +14 -9
- package/dist/combobox/use-active-option.mjs.map +0 -1
- package/dist/combobox/use-deferred-leave.mjs.map +0 -1
- package/dist/combobox/use-option-registry.mjs +0 -52
- package/dist/combobox/use-option-registry.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-root.mjs","names":[],"sources":["../../src/select/select-root.tsx"],"sourcesContent":["\"use client\";\nimport { useMemo, useRef } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/action/use-controllable-action.js\";\nimport {\n fieldInputProps,\n useFieldControl,\n useFieldValueChange,\n} from \"../internal/form/use-field-control.js\";\nimport { useResetTarget } from \"../internal/form/use-form-reset.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useNativeSelectValue } from \"../internal/form/use-native-select-value.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { SelectContext } from \"./select-context.js\";\nimport type { SelectContextValue } from \"./select-context.js\";\nimport { useSelectPartRef } from \"./select-dom.js\";\n\n/** Details passed as the second argument of `valueChangeAction`. */\nexport interface SelectValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user picked an option (pointer, keyboard, typeahead, or browser autofill,\n * which the library cannot tell from a pick); `details.event` is the native `change` event.\n * `\"platform\"`: the browser changed the value without a pick the library saw: a form reset\n * (`details.event` is the `reset` event), or a pick before hydration / Firefox form-state\n * restoration reconciled at mount (`details.event` is `undefined`).\n */\n readonly reason: ChangeReason;\n}\n\n/**\n * State of `Select.Root`, `Select.Trigger`, `Select.Value`, `Select.Group`, `Select.GroupLabel`,\n * `Select.Separator`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface SelectRootState {\n /** Optimistic value. Content rendered from it must not suspend. */\n readonly value: string;\n /** An action dispatched through this Select is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Select.Root`.\n *\n * @see https://ui.funstack.work/components/select\n */\nexport interface SelectRootProps extends Omit<\n ComponentPropsWithRef<\"select\">,\n | \"value\"\n | \"defaultValue\"\n | \"onChange\"\n | \"multiple\"\n | \"size\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Controlled value. `undefined` means uncontrolled. Use `\"\"` for the placeholder option. */\n value?: string;\n /**\n * Initial value in uncontrolled mode, and the value a form reset returns to (the latest prop is\n * mirrored into the options' `defaultSelected`). When omitted, the browser's choice (an option\n * whose value is `\"\"`, else the first enabled option) is adopted at mount, without a dispatch,\n * and is what a form reset returns to. Until a pick (or a platform change) sets the value,\n * options that mount later without the adopted one (a Suspense fallback) adopt again.\n *\n * @defaultValue the browser's choice\n */\n defaultValue?: string;\n /**\n * Runs inside the Root's transition whenever the selected option changes. May be sync or async\n * (also a Server Function); rejections reach the nearest Error Boundary and roll the selection\n * back.\n *\n * In engines whose closed select changes the value on every arrow press (Firefox, Safari with\n * native appearance), every press dispatches; the latest dispatch wins. A `setState` placed\n * after your own `await` is not a Transition update; wrap it in `startTransition` (React\n * limitation). Controlled mode is the way to veto a change.\n */\n valueChangeAction?: ChangeAction<string, SelectValueChangeDetails>;\n /**\n * Native `disabled`. Never set by the library while pending.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, SelectRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, SelectRootState>;\n /**\n * The options and the Trigger. The function form receives the optimistic value; must not suspend.\n */\n children?: StateValue<ReactNode, SelectRootState>;\n /** Replace the rendered element. Must keep a `<select>`. */\n render?: RenderProp<ComponentPropsWithRef<\"select\">, SelectRootState>;\n}\n\n/**\n * The `<select>` itself: owns the value, the transition, the form-reset listener, the mount\n * reconciliation and the re-apply of late options (design/components/select.md 15.2). Renders\n * `value={optimistic}`: react-dom restores a controlled select to its props after every event,\n * and only the sync-lane optimistic value survives that restore.\n *\n * Owned keys (conventions 1.2): `value`, `disabled`, `data-pending`, `data-disabled`, `onChange`;\n * inside a `Field.Root` also `id`, `name`, `required`, `aria-invalid`, `aria-describedby`\n * (token-merged) and `data-invalid`, and `disabled` / `name` / `required` default from the Field.\n *\n * @see https://ui.funstack.work/components/select\n */\nexport function SelectRoot({\n value,\n defaultValue,\n valueChangeAction,\n disabled: disabledProp,\n className,\n style,\n children,\n render,\n ...rest\n}: SelectRootProps) {\n const { ref: libraryRef, node: selectRef } = useSelectPartRef<HTMLSelectElement>(\n \"Select.Root\",\n \"select\",\n );\n // Inside a Field.Root (design/components/field-form.md 7.2) the Field owns the id and the ARIA\n // wiring, and `name` / `required` / `disabled` default from it.\n const field = useFieldControl({\n labelable: true,\n name: rest.name,\n disabled: disabledProp,\n required: rest.required,\n id: rest.id,\n component: \"Select.Root\",\n });\n const disabled = field.disabled;\n const rootRef = useMergedRefs<HTMLSelectElement>(libraryRef, field.ref);\n\n const { optimistic, pending, dispatch, latestInFlight, adopt } = useControllableAction<\n string,\n SelectValueChangeDetails\n >({\n controlled: value,\n defaultValue,\n initialValue: \"\",\n action: valueChangeAction,\n transitionTypes: () => transitionTypes(\"select\"),\n warn: { component: \"Select.Root\", prop: \"value\" },\n });\n // Inside a Field: a value React writes with no event (a rejected action rolling back, a\n // controlled change) re-reads validity and `validate` after the commit.\n useFieldValueChange(optimistic);\n // Deliberately no warning when neither `value` nor `defaultValue` is given: the browser's\n // first-option default is adopted (design decisions 3 and 4).\n\n // Controlled: the mount-time value is the reset target (conventions 3.8 rule 6). Neither\n // `value` nor `defaultValue`: the value adopted at mount, chosen inside the hook.\n const resetTarget = useResetTarget(value, defaultValue) ?? value;\n\n // Any dispatch, a pick or a platform change, ends the adoption of the browser's default.\n const established = useRef(false);\n const dispatchChange = (next: string, details: SelectValueChangeDetails) => {\n established.current = true;\n dispatch(next, details);\n };\n\n const { optionMounted } = useNativeSelectValue({\n ref: selectRef,\n optimistic,\n latestInFlight,\n resetTarget,\n adoptDefault:\n value === undefined && defaultValue === undefined\n ? { adopt, established: () => established.current }\n : undefined,\n onPlatformChange: (next, event) =>\n dispatchChange(next, createActionDetails(event, { reason: \"platform\" })),\n });\n\n // Memoised: every member is a state value, a prop or a stable callback.\n const context = useMemo<SelectContextValue>(\n () => ({ optimistic, pending, disabled, groupDisabled: false, optionMounted }),\n [optimistic, pending, disabled, optionMounted],\n );\n const state: SelectRootState = { value: optimistic, pending, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"select\">, SelectRootState>({\n defaultElement: \"select\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...fieldInputProps(field),\n value: optimistic,\n disabled,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n onChange: (event: ChangeEvent<HTMLSelectElement>) => {\n // A natively disabled select fires no change; this covers `render` elements.\n if (disabled) return;\n const next = event.currentTarget.value;\n // No-op rule against the optimistic value (conventions 2.3, design 4.2).\n if (next === optimistic) return;\n dispatchChange(next, createActionDetails(event.nativeEvent, { reason: \"activate\" }));\n },\n },\n ref: rootRef,\n });\n\n return <SelectContext value={context}>{element}</SelectContext>;\n}\n\nSelectRoot.displayName = \"SelectRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HA,SAAgB,WAAW,EACzB,OACA,cACA,mBACA,UAAU,cACV,WACA,OACA,UACA,QACA,GAAG,QACe;CAClB,MAAM,EAAE,KAAK,YAAY,MAAM,cAAc,iBAC3C,eACA,QACF;CAGA,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,MAAM,KAAK;EACX,UAAU;EACV,UAAU,KAAK;EACf,IAAI,KAAK;EACT,WAAW;CACb,CAAC;CACD,MAAM,WAAW,MAAM;CACvB,MAAM,UAAU,cAAiC,YAAY,MAAM,GAAG;CAEtE,MAAM,EAAE,YAAY,SAAS,UAAU,gBAAgB,UAAU,sBAG/D;EACA,YAAY;EACZ;EACA,cAAc;EACd,QAAQ;EACR,uBAAuB,gBAAgB,QAAQ;EAC/C,MAAM;GAAE,WAAW;GAAe,MAAM;EAAQ;CAClD,CAAC;CAGD,oBAAoB,UAAU;CAM9B,MAAM,cAAc,eAAe,OAAO,YAAY,KAAK;CAG3D,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,kBAAkB,MAAc,YAAsC;EAC1E,YAAY,UAAU;EACtB,SAAS,MAAM,OAAO;CACxB;CAEA,MAAM,EAAE,kBAAkB,qBAAqB;EAC7C,KAAK;EACL;EACA;EACA;EACA,cACE,UAAU,KAAA,KAAa,iBAAiB,KAAA,IACpC;GAAE;GAAO,mBAAmB,YAAY;EAAQ,IAChD,KAAA;EACN,mBAAmB,MAAM,UACvB,eAAe,MAAM,oBAAoB,OAAO,EAAE,QAAQ,WAAW,CAAC,CAAC;CAC3E,CAAC;CAGD,MAAM,UAAU,eACP;EAAE;EAAY;EAAS;EAAU,eAAe;EAAO;CAAc,IAC5E;EAAC;EAAY;EAAS;EAAU;CAAa,CAC/C;CAGA,MAAM,UAAU,UAA4D;EAC1E,gBAAgB;EAChB;EACA,OAAA;GAL+B,OAAO;GAAY;GAAS;EAKvD;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG,gBAAgB,KAAK;GACxB,OAAO;GACP;GACA,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;GAClC,WAAW,UAA0C;IAEnD,IAAI,UAAU;IACd,MAAM,OAAO,MAAM,cAAc;IAEjC,IAAI,SAAS,YAAY;IACzB,eAAe,MAAM,oBAAoB,MAAM,aAAa,EAAE,QAAQ,WAAW,CAAC,CAAC;GACrF;EACF;EACA,KAAK;CACP,CAAC;CAED,OAAO,oBAAC,eAAD;EAAe,OAAO;EAAU,UAAA;CAAuB,CAAA;AAChE;AAEA,WAAW,cAAc"}
|
|
1
|
+
{"version":3,"file":"select-root.mjs","names":[],"sources":["../../src/select/select-root.tsx"],"sourcesContent":["\"use client\";\nimport { useMemo, useRef } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/action/use-controllable-action.js\";\nimport {\n fieldInputProps,\n useFieldControl,\n useFieldValueChange,\n} from \"../internal/form/use-field-control.js\";\nimport { useResetTarget } from \"../internal/form/use-form-reset.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useNativeSelectValue } from \"../internal/form/use-native-select-value.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { SelectContext } from \"./select-context.js\";\nimport type { SelectContextValue } from \"./select-context.js\";\nimport { useSelectPartRef } from \"./select-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed as the second argument of `valueChangeAction`. */\nexport interface SelectValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user picked an option (pointer, keyboard, typeahead, or browser autofill,\n * which the library cannot tell from a pick); `details.event` is the native `change` event.\n * `\"platform\"`: the browser changed the value without a pick the library saw: a form reset\n * (`details.event` is the `reset` event), or a pick before hydration / Firefox form-state\n * restoration reconciled at mount (`details.event` is `undefined`).\n */\n readonly reason: ChangeReason;\n}\n\n/**\n * State of `Select.Root`, `Select.Trigger`, `Select.Value`, `Select.Group`, `Select.GroupLabel`,\n * `Select.Separator`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface SelectRootState {\n /** Optimistic value. Content rendered from it must not suspend. */\n readonly value: string;\n /** An action dispatched through this Select is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Select.Root`.\n *\n * @see https://ui.funstack.work/components/select\n */\nexport interface SelectRootProps extends Omit<\n ComponentPropsWithRef<\"select\">,\n | \"value\"\n | \"defaultValue\"\n | \"onChange\"\n | \"multiple\"\n | \"size\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Controlled value. `undefined` means uncontrolled. Use `\"\"` for the placeholder option. */\n value?: string;\n /**\n * Initial value in uncontrolled mode, and the value a form reset returns to (the latest prop is\n * mirrored into the options' `defaultSelected`). When omitted, the browser's choice (an option\n * whose value is `\"\"`, else the first enabled option) is adopted at mount, without a dispatch,\n * and is what a form reset returns to. Until a pick (or a platform change) sets the value,\n * options that mount later without the adopted one (a Suspense fallback) adopt again.\n *\n * @defaultValue the browser's choice\n */\n defaultValue?: string;\n /**\n * Runs inside the Root's transition whenever the selected option changes. May be sync or async\n * (also a Server Function); rejections reach the nearest Error Boundary and roll the selection\n * back.\n *\n * In engines whose closed select changes the value on every arrow press (Firefox, Safari with\n * native appearance), every press dispatches; the latest dispatch wins. A `setState` placed\n * after your own `await` is not a Transition update; wrap it in `startTransition` (React\n * limitation). Controlled mode is the way to veto a change.\n */\n valueChangeAction?: ChangeAction<string, SelectValueChangeDetails>;\n /**\n * Native `disabled`. Never set by the library while pending.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, SelectRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, SelectRootState>;\n /**\n * The options and the Trigger. The function form receives the optimistic value; must not suspend.\n */\n children?: StateValue<ReactNode, SelectRootState>;\n /** Replace the rendered element. Must keep a `<select>`. */\n render?: RenderProp<ComponentPropsWithRef<\"select\">, SelectRootState>;\n}\n\n/**\n * The `<select>` itself: owns the value, the transition, the form-reset listener, the mount\n * reconciliation and the re-apply of late options (design/components/select.md 15.2). Renders\n * `value={optimistic}`: react-dom restores a controlled select to its props after every event,\n * and only the sync-lane optimistic value survives that restore.\n *\n * Owned keys (conventions 1.2): `value`, `disabled`, `data-pending`, `data-disabled`, `onChange`;\n * inside a `Field.Root` also `id`, `name`, `required`, `aria-invalid`, `aria-describedby`\n * (token-merged) and `data-invalid`, and `disabled` / `name` / `required` default from the Field.\n *\n * @see https://ui.funstack.work/components/select\n */\nexport function SelectRoot({\n value,\n defaultValue,\n valueChangeAction,\n disabled: disabledProp,\n className,\n style,\n children,\n render,\n ...restWithMultiple\n}: SelectRootProps) {\n // `multiple` is a type error and is not passed on: a list of values is MultiSelect\n // (design/components/select.md 13, multi-select.md A.3). The name stays free for the native\n // multi drop-down.\n const { multiple, ...rest } = restWithMultiple as typeof restWithMultiple & {\n multiple?: unknown;\n };\n useDevWarning(\n multiple !== undefined && multiple !== false,\n isDev &&\n \"Select.Root: `multiple` is not supported; it is ignored. Select is a native single \" +\n \"<select>. For several values use MultiSelect (`@funstack/ui/multi-select`), or \" +\n \"CheckboxGroup for a short list shown in the page.\",\n );\n const { ref: libraryRef, node: selectRef } = useSelectPartRef<HTMLSelectElement>(\n \"Select.Root\",\n \"select\",\n );\n // Inside a Field.Root (design/components/field-form.md 7.2) the Field owns the id and the ARIA\n // wiring, and `name` / `required` / `disabled` default from it.\n const field = useFieldControl({\n labelable: true,\n name: rest.name,\n disabled: disabledProp,\n required: rest.required,\n id: rest.id,\n component: \"Select.Root\",\n });\n const disabled = field.disabled;\n const rootRef = useMergedRefs<HTMLSelectElement>(libraryRef, field.ref);\n\n const { optimistic, pending, dispatch, latestInFlight, adopt } = useControllableAction<\n string,\n SelectValueChangeDetails\n >({\n controlled: value,\n defaultValue,\n initialValue: \"\",\n action: valueChangeAction,\n transitionTypes: () => transitionTypes(\"select\"),\n warn: { component: \"Select.Root\", prop: \"value\" },\n });\n // Inside a Field: a value React writes with no event (a rejected action rolling back, a\n // controlled change) re-reads validity and `validate` after the commit.\n useFieldValueChange(optimistic);\n // Deliberately no warning when neither `value` nor `defaultValue` is given: the browser's\n // first-option default is adopted (design decisions 3 and 4).\n\n // Controlled: the mount-time value is the reset target (conventions 3.8 rule 6). Neither\n // `value` nor `defaultValue`: the value adopted at mount, chosen inside the hook.\n const resetTarget = useResetTarget(value, defaultValue) ?? value;\n\n // Any dispatch, a pick or a platform change, ends the adoption of the browser's default.\n const established = useRef(false);\n const dispatchChange = (next: string, details: SelectValueChangeDetails) => {\n established.current = true;\n dispatch(next, details);\n };\n\n const { optionMounted } = useNativeSelectValue({\n ref: selectRef,\n optimistic,\n latestInFlight,\n resetTarget,\n adoptDefault:\n value === undefined && defaultValue === undefined\n ? { adopt, established: () => established.current }\n : undefined,\n onPlatformChange: (next, event) =>\n dispatchChange(next, createActionDetails(event, { reason: \"platform\" })),\n });\n\n // Memoised: every member is a state value, a prop or a stable callback.\n const context = useMemo<SelectContextValue>(\n () => ({ optimistic, pending, disabled, groupDisabled: false, optionMounted }),\n [optimistic, pending, disabled, optionMounted],\n );\n const state: SelectRootState = { value: optimistic, pending, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"select\">, SelectRootState>({\n defaultElement: \"select\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...fieldInputProps(field),\n value: optimistic,\n disabled,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n onChange: (event: ChangeEvent<HTMLSelectElement>) => {\n // A natively disabled select fires no change; this covers `render` elements.\n if (disabled) return;\n const next = event.currentTarget.value;\n // No-op rule against the optimistic value (conventions 2.3, design 4.2).\n if (next === optimistic) return;\n dispatchChange(next, createActionDetails(event.nativeEvent, { reason: \"activate\" }));\n },\n },\n ref: rootRef,\n });\n\n return <SelectContext value={context}>{element}</SelectContext>;\n}\n\nSelectRoot.displayName = \"SelectRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;AAkGvC,SAAgB,WAAW,EACzB,OACA,cACA,mBACA,UAAU,cACV,WACA,OACA,UACA,QACA,GAAG,oBACe;CAIlB,MAAM,EAAE,UAAU,GAAG,SAAS;CAG9B,cACE,aAAa,KAAA,KAAa,aAAa,OACvC,SACE,qNAGJ;CACA,MAAM,EAAE,KAAK,YAAY,MAAM,cAAc,iBAC3C,eACA,QACF;CAGA,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,MAAM,KAAK;EACX,UAAU;EACV,UAAU,KAAK;EACf,IAAI,KAAK;EACT,WAAW;CACb,CAAC;CACD,MAAM,WAAW,MAAM;CACvB,MAAM,UAAU,cAAiC,YAAY,MAAM,GAAG;CAEtE,MAAM,EAAE,YAAY,SAAS,UAAU,gBAAgB,UAAU,sBAG/D;EACA,YAAY;EACZ;EACA,cAAc;EACd,QAAQ;EACR,uBAAuB,gBAAgB,QAAQ;EAC/C,MAAM;GAAE,WAAW;GAAe,MAAM;EAAQ;CAClD,CAAC;CAGD,oBAAoB,UAAU;CAM9B,MAAM,cAAc,eAAe,OAAO,YAAY,KAAK;CAG3D,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,kBAAkB,MAAc,YAAsC;EAC1E,YAAY,UAAU;EACtB,SAAS,MAAM,OAAO;CACxB;CAEA,MAAM,EAAE,kBAAkB,qBAAqB;EAC7C,KAAK;EACL;EACA;EACA;EACA,cACE,UAAU,KAAA,KAAa,iBAAiB,KAAA,IACpC;GAAE;GAAO,mBAAmB,YAAY;EAAQ,IAChD,KAAA;EACN,mBAAmB,MAAM,UACvB,eAAe,MAAM,oBAAoB,OAAO,EAAE,QAAQ,WAAW,CAAC,CAAC;CAC3E,CAAC;CAGD,MAAM,UAAU,eACP;EAAE;EAAY;EAAS;EAAU,eAAe;EAAO;CAAc,IAC5E;EAAC;EAAY;EAAS;EAAU;CAAa,CAC/C;CAGA,MAAM,UAAU,UAA4D;EAC1E,gBAAgB;EAChB;EACA,OAAA;GAL+B,OAAO;GAAY;GAAS;EAKvD;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG,gBAAgB,KAAK;GACxB,OAAO;GACP;GACA,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;GAClC,WAAW,UAA0C;IAEnD,IAAI,UAAU;IACd,MAAM,OAAO,MAAM,cAAc;IAEjC,IAAI,SAAS,YAAY;IACzB,eAAe,MAAM,oBAAoB,MAAM,aAAa,EAAE,QAAQ,WAAW,CAAC,CAAC;GACrF;EACF;EACA,KAAK;CACP,CAAC;CAED,OAAO,oBAAC,eAAD;EAAe,OAAO;EAAU,UAAA;CAAuB,CAAA;AAChE;AAEA,WAAW,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Separator } from "./separator.mjs";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { CSSProperties, ComponentPropsWithRef } from "react";
|
|
3
|
+
//#region src/separator/separator.d.ts
|
|
4
|
+
/** The direction of the line itself. */
|
|
5
|
+
export type SeparatorOrientation = "horizontal" | "vertical";
|
|
6
|
+
/** State of `Separator`, passed to the function forms of `className`, `style` and `render`. */
|
|
7
|
+
export interface SeparatorState {
|
|
8
|
+
/** The `orientation` prop. */
|
|
9
|
+
readonly orientation: SeparatorOrientation;
|
|
10
|
+
/** The `decorative` prop. */
|
|
11
|
+
readonly decorative: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Props of `Separator`.
|
|
15
|
+
*
|
|
16
|
+
* @see https://ui.funstack.work/components/separator
|
|
17
|
+
*/
|
|
18
|
+
export interface SeparatorProps extends Omit<ComponentPropsWithRef<"hr">, "role" | "aria-orientation" | "className" | "style" | "children"> {
|
|
19
|
+
/**
|
|
20
|
+
* The direction of the line itself. A vertical separator sits between things laid out in a row.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue `"horizontal"`
|
|
23
|
+
*/
|
|
24
|
+
orientation?: SeparatorOrientation;
|
|
25
|
+
/**
|
|
26
|
+
* A visual line with no meaning: `role="none"`, no `aria-orientation`. Leave it `false` when
|
|
27
|
+
* the line marks a real break between sections of content.
|
|
28
|
+
*
|
|
29
|
+
* @defaultValue `false`
|
|
30
|
+
*/
|
|
31
|
+
decorative?: boolean;
|
|
32
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
33
|
+
className?: StateValue<string | undefined, SeparatorState>;
|
|
34
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
35
|
+
style?: StateValue<CSSProperties | undefined, SeparatorState>;
|
|
36
|
+
/**
|
|
37
|
+
* Replace the `<hr>` (element form) or take over rendering (function form). Another element
|
|
38
|
+
* must carry `role="separator"` itself unless `decorative`.
|
|
39
|
+
*/
|
|
40
|
+
render?: RenderProp<ComponentPropsWithRef<"hr">, SeparatorState>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A line between two pieces of content: an `<hr>` with `aria-orientation` and
|
|
44
|
+
* `data-orientation`, or with `decorative` a `role="none"` line with no `aria-orientation`. Not
|
|
45
|
+
* focusable. Directive-free, so a Server Component may render it.
|
|
46
|
+
*
|
|
47
|
+
* Owned keys (conventions 1.2): `aria-orientation`, `data-orientation`, and `role` while
|
|
48
|
+
* `decorative` (`"none"`, which wins over a `render` element's own). While not decorative no
|
|
49
|
+
* `role` is rendered, so a `render` element keeps the one it carries.
|
|
50
|
+
*
|
|
51
|
+
* @see https://ui.funstack.work/components/separator
|
|
52
|
+
*/
|
|
53
|
+
export declare function Separator({ orientation, decorative, className, style, render, ref, ...rest }: SeparatorProps): import("react").ReactNode;
|
|
54
|
+
export declare namespace Separator {
|
|
55
|
+
var displayName: string;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//# sourceMappingURL=separator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"separator.d.mts","names":[],"sources":["../../src/separator/separator.tsx"],"mappings":";;;;YASY;;iBAGK;;WAEN,aAAa;;WAEb;;;;;;;iBAQM,uBAAuB,KACtC;;;;;;EAQA,cAAc;;;;;;;EAOd;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;;;;EAK9C,SAAS,WAAW,6BAA6B;;;;;;;;;;;;;wBAcnC,YACd,aACA,YACA,WACA,OACA,QACA,QACG,QACF,iCAAc;yBARD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { mergeRenderRef, renderElement } from "../internal/render-element.mjs";
|
|
2
|
+
//#region src/separator/separator.tsx
|
|
3
|
+
/**
|
|
4
|
+
* A line between two pieces of content: an `<hr>` with `aria-orientation` and
|
|
5
|
+
* `data-orientation`, or with `decorative` a `role="none"` line with no `aria-orientation`. Not
|
|
6
|
+
* focusable. Directive-free, so a Server Component may render it.
|
|
7
|
+
*
|
|
8
|
+
* Owned keys (conventions 1.2): `aria-orientation`, `data-orientation`, and `role` while
|
|
9
|
+
* `decorative` (`"none"`, which wins over a `render` element's own). While not decorative no
|
|
10
|
+
* `role` is rendered, so a `render` element keeps the one it carries.
|
|
11
|
+
*
|
|
12
|
+
* @see https://ui.funstack.work/components/separator
|
|
13
|
+
*/
|
|
14
|
+
function Separator({ orientation = "horizontal", decorative = false, className, style, render, ref, ...rest }) {
|
|
15
|
+
return renderElement({
|
|
16
|
+
defaultElement: "hr",
|
|
17
|
+
render,
|
|
18
|
+
state: {
|
|
19
|
+
orientation,
|
|
20
|
+
decorative
|
|
21
|
+
},
|
|
22
|
+
className,
|
|
23
|
+
style,
|
|
24
|
+
children: void 0,
|
|
25
|
+
props: rest,
|
|
26
|
+
libraryProps: decorative ? {
|
|
27
|
+
role: "none",
|
|
28
|
+
"aria-orientation": void 0,
|
|
29
|
+
"data-orientation": orientation
|
|
30
|
+
} : {
|
|
31
|
+
"aria-orientation": orientation,
|
|
32
|
+
"data-orientation": orientation
|
|
33
|
+
},
|
|
34
|
+
ref: mergeRenderRef(ref, render)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
Separator.displayName = "Separator";
|
|
38
|
+
//#endregion
|
|
39
|
+
export { Separator };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=separator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"separator.mjs","names":[],"sources":["../../src/separator/separator.tsx"],"sourcesContent":["// No \"use client\": `Separator` reads no context and calls no hook, so a Server Component may\n// render it and it runs once, on the server (design/components/separator.md 7). It must not\n// import from any \"use client\" module (checked by src/__tests__/directives.test.ts).\nimport type { ComponentPropsWithRef, CSSProperties } from \"react\";\nimport { mergeRenderRef, renderElement } from \"../internal/render-element.js\";\nimport type { DataAttributes } from \"../internal/render-element.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\n\n/** The direction of the line itself. */\nexport type SeparatorOrientation = \"horizontal\" | \"vertical\";\n\n/** State of `Separator`, passed to the function forms of `className`, `style` and `render`. */\nexport interface SeparatorState {\n /** The `orientation` prop. */\n readonly orientation: SeparatorOrientation;\n /** The `decorative` prop. */\n readonly decorative: boolean;\n}\n\n/**\n * Props of `Separator`.\n *\n * @see https://ui.funstack.work/components/separator\n */\nexport interface SeparatorProps extends Omit<\n ComponentPropsWithRef<\"hr\">,\n \"role\" | \"aria-orientation\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * The direction of the line itself. A vertical separator sits between things laid out in a row.\n *\n * @defaultValue `\"horizontal\"`\n */\n orientation?: SeparatorOrientation;\n /**\n * A visual line with no meaning: `role=\"none\"`, no `aria-orientation`. Leave it `false` when\n * the line marks a real break between sections of content.\n *\n * @defaultValue `false`\n */\n decorative?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, SeparatorState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, SeparatorState>;\n /**\n * Replace the `<hr>` (element form) or take over rendering (function form). Another element\n * must carry `role=\"separator\"` itself unless `decorative`.\n */\n render?: RenderProp<ComponentPropsWithRef<\"hr\">, SeparatorState>;\n}\n\n/**\n * A line between two pieces of content: an `<hr>` with `aria-orientation` and\n * `data-orientation`, or with `decorative` a `role=\"none\"` line with no `aria-orientation`. Not\n * focusable. Directive-free, so a Server Component may render it.\n *\n * Owned keys (conventions 1.2): `aria-orientation`, `data-orientation`, and `role` while\n * `decorative` (`\"none\"`, which wins over a `render` element's own). While not decorative no\n * `role` is rendered, so a `render` element keeps the one it carries.\n *\n * @see https://ui.funstack.work/components/separator\n */\nexport function Separator({\n orientation = \"horizontal\",\n decorative = false,\n className,\n style,\n render,\n ref,\n ...rest\n}: SeparatorProps) {\n const state: SeparatorState = { orientation, decorative };\n const libraryProps: Partial<ComponentPropsWithRef<\"hr\">> & DataAttributes = decorative\n ? { role: \"none\", \"aria-orientation\": undefined, \"data-orientation\": orientation }\n : { \"aria-orientation\": orientation, \"data-orientation\": orientation };\n\n return renderElement<ComponentPropsWithRef<\"hr\">, SeparatorState>({\n defaultElement: \"hr\",\n render,\n state,\n className,\n style,\n children: undefined,\n props: rest,\n libraryProps,\n // Passed through to the element, never read during render.\n // oxlint-disable-next-line react/refs\n ref: mergeRenderRef(ref, render),\n });\n}\n\nSeparator.displayName = \"Separator\";\n"],"mappings":";;;;;;;;;;;;;AA+DA,SAAgB,UAAU,EACxB,cAAc,cACd,aAAa,OACb,WACA,OACA,QACA,KACA,GAAG,QACc;CAMjB,OAAO,cAA2D;EAChE,gBAAgB;EAChB;EACA,OAAA;GAR8B;GAAa;EAQvC;EACJ;EACA;EACA,UAAU,KAAA;EACV,OAAO;EACP,cAZ0E,aACxE;GAAE,MAAM;GAAQ,oBAAoB,KAAA;GAAW,oBAAoB;EAAY,IAC/E;GAAE,oBAAoB;GAAa,oBAAoB;EAAY;EAarE,KAAK,eAAe,KAAK,MAAM;CACjC,CAAC;AACH;AAEA,UAAU,cAAc"}
|
|
@@ -210,6 +210,7 @@ function SliderRootImpl(props) {
|
|
|
210
210
|
const beginGesture = useCallback((index, event, element) => {
|
|
211
211
|
const { disabled: off } = latest.current;
|
|
212
212
|
if (off || event.button !== 0 || activeGesture.current !== null) return;
|
|
213
|
+
for (const input of registry.values()) if (input.matches(":disabled")) return;
|
|
213
214
|
const track = trackRef.current;
|
|
214
215
|
if (track === null) {
|
|
215
216
|
if (isDev && !warnedNoTrack.current) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider-root.mjs","names":[],"sources":["../../src/slider/slider-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { mergeTokenLists } from \"../internal/merge-props.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n Orientation,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useFieldControl, useFieldValueChange } from \"../internal/form/use-field-control.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useNativeGroupReconciliation } from \"../internal/form/use-native-group-reconciliation.js\";\nimport { useResetTarget } from \"../internal/form/use-form-reset.js\";\nimport { useRegisterCount } from \"../internal/use-register-count.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useStepCommit } from \"../internal/action/use-step-commit.js\";\nimport {\n clampToNeighbours,\n equalValues,\n nearestThumb,\n platformDefault,\n pointerValue,\n resolveTie,\n sanitize,\n shapeOf,\n sliderGeometry,\n tiedRange,\n toArray,\n} from \"./slider-arithmetic.js\";\nimport { SliderContext } from \"./slider-context.js\";\nimport type { SliderContextValue, SliderFieldWiring } from \"./slider-context.js\";\nimport { useSliderDevWarnings } from \"./use-slider-dev-warnings.js\";\nimport { useThumbRegistry } from \"./use-thumb-registry.js\";\n\n/** One number (one thumb) or one number per thumb, in ascending order. */\nexport type SliderValue = number | readonly number[];\n\n/** The arrow-key axis and layout of a Slider. */\nexport type SliderOrientation = Orientation;\n\n/** Details passed as the second argument of `Slider.Root`'s `valueChangeAction` (each step). */\nexport interface SliderValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user moved a thumb (`details.event` is the native `input` event for a key\n * press, the `pointerdown` / `pointermove` / `pointerup` for a drag, the `keydown` for a\n * JS-normalised key).\n * `\"platform\"`: a form reset (the `reset` event) or a value found in the inputs at mount\n * (`undefined`).\n * `\"dismiss\"`: the commit action rejected and the slider reverted to the committed value\n * (uncontrolled mode; `undefined`).\n */\n readonly reason: ChangeReason;\n /** Index of the thumb that moved; `null` on a platform path or a revert, where several may change. */\n readonly thumb: number | null;\n}\n\n/** Details passed as the second argument of `Slider.Root`'s `valueCommitAction` (each gesture). */\nexport interface SliderValueCommitDetails extends ActionDetails {\n /**\n * `\"activate\"`: a gesture ended (`details.event` is the native `change` event for a key press,\n * the `pointerup` / `pointercancel` / `lostpointercapture` for a drag, the `keydown` for a\n * JS-normalised key). `\"platform\"`: a form reset (the `reset` event) or mount reconciliation\n * (`undefined`). Never `\"dismiss\"`.\n */\n readonly reason: ChangeReason;\n /** Index of the thumb the gesture moved; `null` on a platform path. */\n readonly thumb: number | null;\n}\n\n/**\n * State of `Slider.Root` and `Slider.Label`, passed to the function forms of `className`,\n * `style`, `children` and `render`.\n */\nexport interface SliderRootState<T extends SliderValue = number> {\n /**\n * The value the thumbs show: the value a gesture has reached while a pointer is captured or a\n * step or commit is in flight, else the optimistic value. Content rendered from it must not\n * suspend.\n */\n readonly value: T;\n /** `value` as an array, one entry per thumb, in thumb order. */\n readonly values: readonly number[];\n /** A step or commit dispatched through this Slider is in flight. */\n readonly pending: boolean;\n /** A pointer is captured on a thumb. */\n readonly dragging: boolean;\n /** The `orientation` prop. */\n readonly orientation: SliderOrientation;\n /** The `disabled` prop, or the enclosing Field's. */\n readonly disabled: boolean;\n /** The `min` prop. */\n readonly min: number;\n /** The `max` prop. */\n readonly max: number;\n /** The `step` prop. */\n readonly step: number;\n}\n\n/**\n * Props of `Slider.Root`. `T` is `number` (one thumb) or `readonly number[]` (one entry per\n * thumb), inferred from `value` / `defaultValue`.\n *\n * @see https://ui.funstack.work/components/slider\n */\nexport interface SliderRootProps<T extends SliderValue = number> extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"defaultValue\"\n | \"role\"\n | \"className\"\n | \"style\"\n | \"children\"\n // The value attributes are the native inputs' (design 8): never authored.\n | \"aria-valuemin\"\n | \"aria-valuemax\"\n | \"aria-valuenow\"\n | \"aria-valuetext\"\n | \"aria-orientation\"\n> {\n /** Controlled value: one number, or one per thumb in ascending order. `undefined`: uncontrolled. */\n value?: T;\n /**\n * Initial value in uncontrolled mode; also the form-reset target (latest value).\n *\n * @defaultValue the platform's midpoint, `min + (max - min) / 2`, snapped to `step`\n */\n defaultValue?: T;\n /**\n * Runs inside the Root's step transition on every step: each pointer move, each key press,\n * each platform change, and the revert after a rejected commit (`reason: \"dismiss\"`,\n * uncontrolled). Awaited; `data-pending` meanwhile (without this action a step starts no\n * transition and is never pending). Adopt the value here in a controlled\n * parent (`setValue(next)` in the sync prefix is a transition update). Not the place for a\n * save: a pending async action entangles every transition in the app, and a drag is many\n * steps. A `setState` after your own `await` needs `startTransition`.\n */\n valueChangeAction?: ChangeAction<T, SliderValueChangeDetails>;\n /**\n * Runs inside the Root's commit transition once per gesture: pointer release, each key press,\n * a form reset, a value found at mount. Awaited; the thumb keeps the gesture's value and shows\n * `data-pending` until it settles; in uncontrolled mode the value is committed when it\n * resolves and reverts to the previous value if it rejects. May be a Server Function.\n */\n valueCommitAction?: ChangeAction<T, SliderValueCommitDetails>;\n /**\n * Lower bound of the range.\n *\n * @defaultValue `0`\n */\n min?: number;\n /**\n * Upper bound of the range. A `max` that is not on the step grid from `min` is unreachable, as\n * on a native range (dev warning).\n *\n * @defaultValue `100`\n */\n max?: number;\n /**\n * Must be positive. Values snap to `min + n × step`.\n *\n * @defaultValue `1`\n */\n step?: number;\n /**\n * Minimum number of steps between two adjacent thumbs.\n *\n * @defaultValue `0` (thumbs may share a value)\n */\n minStepsBetweenThumbs?: number;\n /**\n * Layout and arrow-key axis. Vertical sliders have `min` at the bottom.\n *\n * @defaultValue `\"horizontal\"`\n */\n orientation?: SliderOrientation;\n /**\n * `aria-valuetext` for a thumb, from the value it shows. Set it when the number alone is not\n * meaningful (\"3 of 5 stars\", \"Tuesday\"). Default: none (the number is announced).\n */\n getAriaValueText?: (value: number, index: number) => string;\n /**\n * Form field name for every thumb's input (a Thumb's own `name` wins). With several thumbs,\n * read with `FormData.getAll()`.\n */\n name?: string;\n /** The `form` attribute for every thumb's input (a Thumb's own `form` wins). */\n form?: string;\n /**\n * Disables every input (native `disabled`; not submitted) and the pointer. Never set while\n * pending. Inside a `Field.Root`, the Field's `disabled` also applies.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, SliderRootState<T>>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, SliderRootState<T>>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, SliderRootState<T>>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, SliderRootState<T>>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nconst STEP_TYPES = transitionTypes(\"slider\", \"change\");\nconst COMMIT_TYPES = transitionTypes(\"slider\", \"commit\");\n\n/** The `details` fields of both actions. */\nfunction sliderDetails(reason: ChangeReason, thumb: number | null) {\n return { reason, thumb };\n}\n\nfunction replaceAt(values: readonly number[], index: number, value: number): readonly number[] {\n return values.map((v, i) => (i === index ? value : v));\n}\n\n/** Writes each registered input's `defaultValue` (the attribute a form reset restores). */\nfunction writeDefaults(\n registry: ReadonlyMap<number, HTMLInputElement>,\n target: readonly number[],\n): void {\n for (const [index, input] of registry) {\n const entry = target[index];\n if (entry !== undefined) input.defaultValue = String(entry);\n }\n}\n\n/** A pointer captured on a Thumb or the Track (design 4.1). */\ninterface ActiveGesture {\n readonly pointerId: number;\n /** Detaches the gesture's listeners. */\n readonly detach: () => void;\n}\n\n/**\n * Owns the slider's state (design/components/slider.md 2): the committed value through\n * `useControllableAction` with `valueCommitAction` (once per gesture), each step through its own\n * transition (`valueChangeAction`), and the value a gesture has reached in the urgent lane\n * (`live`), which the thumbs show while a pointer is captured or anything is in flight. Also the\n * pointer gesture, the Thumb registry, mount reconciliation and form reset, and the geometry\n * custom properties `--slider-start`, `--slider-end` and `--slider-value-<i>`.\n *\n * Owned keys (conventions 1.2): `role` (`\"group\"` with several thumbs), `aria-labelledby` (the\n * Label's id while a Label is mounted and there are several thumbs; token-merged with the\n * consumer's), `data-pending`, `data-dragging`, `data-orientation`, `data-disabled`. The custom\n * properties are merged into `style`, where the consumer's entries win.\n *\n * Inside a `Field.Root` (design 9.4) the Root calls `useFieldControl`: with one thumb, Thumb 0's\n * input is the Field's labelable control; with several, the Root registers itself as the group\n * and also owns the Field label in `aria-labelledby`, the Field's `aria-describedby` and\n * `data-invalid`. `name` / `disabled` default from the Field.\n */\nfunction SliderRootImpl<T extends SliderValue = number>(props: SliderRootProps<T>) {\n const {\n value,\n defaultValue,\n valueChangeAction,\n valueCommitAction,\n min = 0,\n max = 100,\n step: stepProp = 1,\n minStepsBetweenThumbs = 0,\n orientation = \"horizontal\",\n getAriaValueText,\n name: nameProp,\n form,\n disabled: disabledProp = false,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n const stepValid = Number.isFinite(stepProp) && stepProp > 0;\n const step = stepValid ? stepProp : 1;\n const gap = Math.max(0, minStepsBetweenThumbs) * step;\n\n const id = useId();\n const labelId = `${id}-label`;\n\n // The shape (one number or an array) is fixed at mount (design 3.1).\n const [shape] = useState<\"number\" | \"array\">(() => shapeOf(value ?? defaultValue) ?? \"number\");\n const fromArray = useCallback(\n (values: readonly number[]): T => (shape === \"number\" ? values[0] : values) as T,\n [shape],\n );\n\n // --- State (design 2) ----------------------------------------------------------------------\n\n const [gestureThumb, setGestureThumb] = useState<number | null>(null);\n const activeGesture = useRef<ActiveGesture | null>(null);\n const trackRef = useRef<HTMLElement | null>(null);\n\n // The step and commit core (design 2.4), shared with NumberField; values are arrays inside.\n const {\n shown,\n shownRef,\n optimisticShown: optimisticValues,\n pending,\n pendingSource: pendingThumb,\n step: stepTo,\n commit: commitGesture,\n openGesture,\n captureGesture,\n markGestureStart,\n takeEdit,\n } = useStepCommit<T, readonly number[], number, ReturnType<typeof sliderDetails>>({\n controlled: value,\n defaultValue,\n initialValue: platformDefault(min, max, step) as T,\n stepAction: valueChangeAction,\n commitAction: valueCommitAction,\n stepTypes: STEP_TYPES,\n commitTypes: COMMIT_TYPES,\n warn: { component: \"Slider.Root\", prop: \"value\" },\n toShown: toArray,\n fromShown: fromArray,\n equals: equalValues,\n details: sliderDetails,\n captured: gestureThumb !== null,\n });\n\n // --- Inside a Field.Root (design 9.4) ------------------------------------------------------\n\n // One thumb: its input is the Field's labelable control. Several: the Root (`role=\"group\"`)\n // registers, `Field.Label` drops `for` and names the group through `aria-labelledby`.\n const thumbCount = shown.length;\n const field = useFieldControl({\n labelable: thumbCount === 1,\n name: nameProp,\n disabled: disabledProp,\n component: \"Slider.Root\",\n });\n const fieldName = field.fieldName;\n const name = field.name;\n const disabled = field.disabled;\n const fieldId = field.id;\n const thumbId = useCallback(\n (index: number) => (index === 0 && fieldId !== undefined ? fieldId : `${id}-thumb-${index}`),\n [id, fieldId],\n );\n const rootRef = thumbCount > 1 ? field.ref : undefined;\n useDevWarning(\n field.inField && field.required,\n isDev &&\n \"Slider.Root: a range is never empty, so `required` on the enclosing Field.Root has no \" +\n \"effect on the slider.\",\n );\n // A pointer gesture and the JS-normalised keys fire no `input` / `change` the Field hears:\n // tell it at the commit, when the optimistic value changes (design 9.4.4). `\"activate\"`\n // dismisses a shown server error, a rollback does not.\n useFieldValueChange(optimisticValues.join(\"\\u0000\"), takeEdit);\n const {\n \"aria-labelledby\": fieldLabelledBy,\n \"aria-describedby\": fieldDescribedBy,\n \"aria-invalid\": fieldInvalid,\n \"data-invalid\": fieldDataInvalid,\n } = field.attributes;\n const inField = field.inField;\n const fieldRef = field.ref;\n const fieldWiring = useMemo<SliderFieldWiring | null>(() => {\n if (!inField) return null;\n const single = thumbCount === 1;\n return {\n inputRef: single ? fieldRef : undefined,\n describedBy: single ? fieldDescribedBy : undefined,\n invalid: fieldInvalid,\n dataInvalid: fieldDataInvalid,\n name: fieldName,\n };\n }, [inField, fieldRef, thumbCount, fieldDescribedBy, fieldInvalid, fieldDataInvalid, fieldName]);\n\n const latest = useLatest({\n min,\n max,\n step,\n gap,\n orientation,\n disabled,\n });\n\n // --- Thumb registry ------------------------------------------------------------------------\n\n const { registry, registerThumb, formElement } = useThumbRegistry();\n\n // --- Labels --------------------------------------------------------------------------------\n\n // The ref is for the dev warning, which can run before the re-render the registration scheduled.\n const {\n count: labelCount,\n register: registerLabel,\n countRef: labelCountRef,\n } = useRegisterCount();\n\n // --- Residual browser paths: mount reconciliation and form reset (design 9.2, 9.3) --------\n\n // Neither mode's target given: the current value (controlled after an uncontrolled mount), else\n // the platform default.\n const resetBase = useResetTarget(value, defaultValue);\n const resetTarget = (): readonly number[] =>\n toArray(resetBase ?? value ?? platformDefault(min, max, step));\n\n const readCurrent = (): readonly number[] =>\n shownRef.current.map((v, index) => {\n const input = registry.get(index);\n if (input === undefined) return v;\n const read = Number(input.value);\n return Number.isFinite(read) ? read : v;\n });\n\n const { onItemMounted } = useNativeGroupReconciliation<readonly number[]>({\n element: formElement,\n readCurrent,\n readDefault: resetTarget,\n base: () => shownRef.current,\n // Compare as the DOM would hold the values: a consumer's off-grid value is sanitised by the\n // browser (not by jsdom), and that is not a platform change.\n equals: (a, b) => {\n const reference = shownRef.current;\n return equalValues(\n sanitize(a, reference, min, max, step, gap),\n sanitize(b, reference, min, max, step, gap),\n );\n },\n onPlatformChange: (next, event) => {\n if (next.length !== shownRef.current.length) return;\n openGesture();\n stepTo(next, null, \"platform\", event);\n commitGesture(null, \"platform\", event);\n },\n onResetEvent: () => {\n // react-dom writes `defaultValue = value` after every update of a controlled input, so the\n // reset target is written here, right before the browser's reset algorithm reads it.\n writeDefaults(registry, resetTarget());\n },\n });\n\n // --- Keyboard (design 4.2) -----------------------------------------------------------------\n\n const inputStep = useCallback(\n (index: number, raw: number, event: Event) => {\n if (!Number.isFinite(raw)) return;\n const before = shownRef.current;\n if (index >= before.length) return;\n // A key press is a one-step gesture: it starts at the value shown before it.\n if (stepTo(replaceAt(before, index, raw), index, \"activate\", event)) {\n markGestureStart(before);\n }\n },\n [markGestureStart, shownRef, stepTo],\n );\n\n const inputCommit = useCallback(\n (index: number, event: Event) => {\n // A pointer gesture commits at its release.\n if (activeGesture.current !== null) return;\n commitGesture(index, \"activate\", event);\n },\n [commitGesture],\n );\n\n const inputKeyDown = useCallback(\n (index: number, event: KeyboardEvent) => {\n const {\n orientation: axis,\n disabled: off,\n min: lo,\n max: hi,\n step: inc,\n gap: g,\n } = latest.current;\n if (off) return;\n if (event.key !== \"ArrowLeft\" && event.key !== \"ArrowRight\") return;\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n // Vertical: Firefox decreases a vertical range on ArrowRight; the APG says increase.\n // Horizontal RTL: the track is mirrored (min on the right), so ArrowLeft increases;\n // Chromium and Firefox mirror a native range, WebKit does not (design 7). LTR stays native.\n let increaseKey: \"ArrowLeft\" | \"ArrowRight\";\n if (axis === \"vertical\") {\n increaseKey = \"ArrowRight\";\n } else {\n // Read at the keydown: the direction may come from any ancestor and change at any time.\n const input = event.currentTarget as Element | null;\n if (input === null || getComputedStyle(input).direction !== \"rtl\") return;\n increaseKey = \"ArrowLeft\";\n }\n event.preventDefault();\n const before = shownRef.current;\n const current = before[index];\n if (current === undefined) return;\n const delta = event.key === increaseKey ? inc : -inc;\n const next = replaceAt(\n before,\n index,\n clampToNeighbours(before, index, current + delta, lo, hi, inc, g),\n );\n if (activeGesture.current !== null) {\n stepTo(next, index, \"activate\", event);\n return;\n }\n openGesture();\n stepTo(next, index, \"activate\", event);\n commitGesture(index, \"activate\", event);\n },\n [commitGesture, latest, openGesture, shownRef, stepTo],\n );\n\n // --- Pointer (design 4.1) ------------------------------------------------------------------\n\n const warnedNoTrack = useRef(false);\n const beginGesture = useCallback(\n (index: number | null, event: PointerEvent, element: HTMLElement) => {\n const { disabled: off } = latest.current;\n if (off || event.button !== 0 || activeGesture.current !== null) return;\n const track = trackRef.current;\n if (track === null) {\n if (isDev && !warnedNoTrack.current) {\n warnedNoTrack.current = true;\n console.error(\n \"Slider.Thumb: a pointer press needs a Slider.Track to map the pointer to a value. \" +\n \"Without a Track the slider is keyboard-only.\",\n );\n }\n return;\n }\n // No text selection, no focus change through the compatibility `mousedown`.\n event.preventDefault();\n const rtl = getComputedStyle(track).direction === \"rtl\";\n\n const valueAt = (clientX: number, clientY: number): number => {\n const { min: lo, max: hi, orientation: axis } = latest.current;\n const rect = (trackRef.current ?? track).getBoundingClientRect();\n return pointerValue(rect, clientX, clientY, axis, rtl, lo, hi);\n };\n const moveTo = (thumb: number, raw: number, cause: Event): void => {\n const { min: lo, max: hi, step: inc, gap: g } = latest.current;\n const before = shownRef.current;\n if (thumb >= before.length) return;\n stepTo(\n replaceAt(before, thumb, clampToNeighbours(before, thumb, raw, lo, hi, inc, g)),\n thumb,\n \"activate\",\n cause,\n );\n };\n\n const start = valueAt(event.clientX, event.clientY);\n const startValues = shownRef.current;\n // A press on a Thumb that shares its value with a neighbour (stacked thumbs) moves the one\n // that can go toward the pointer, the Track's tie rule; when the press is exactly on the\n // value, the first move decides. Otherwise a Thumb press moves that Thumb.\n const tied = index === null ? null : tiedRange(startValues, index);\n /** The thumb the gesture moves; `null` while a press on stacked thumbs is undecided. */\n let decided: number | null =\n index === null ? nearestThumb(startValues, start) : tied ? resolveTie(tied, start) : index;\n /** The thumb shown as dragging and focused meanwhile. */\n let thumb = decided ?? index ?? 0;\n const pointerId = event.pointerId;\n try {\n element.setPointerCapture(pointerId);\n } catch {\n // An inactive pointer id (a synthetic event): the gesture still follows the element.\n }\n\n const decide = (raw: number): boolean => {\n if (decided !== null) return true;\n decided = resolveTie(tied, raw);\n if (decided === null) return false;\n if (decided !== thumb) {\n thumb = decided;\n setGestureThumb(thumb);\n registry.get(thumb)?.focus({ focusVisible: false } as FocusOptions);\n }\n return true;\n };\n const follow = (pointerEvent: PointerEvent): void => {\n const raw = valueAt(pointerEvent.clientX, pointerEvent.clientY);\n if (decide(raw)) moveTo(thumb, raw, pointerEvent);\n };\n\n const onMove = (moveEvent: PointerEvent): void => {\n if (moveEvent.pointerId !== pointerId) return;\n follow(moveEvent);\n };\n const onEnd = (endEvent: PointerEvent): void => {\n if (endEvent.pointerId !== pointerId) return;\n detach();\n // The release position is the gesture's last (an engine may coalesce the final move\n // into the `pointerup`); a cancel or a lost capture keeps the last move's value.\n if (endEvent.type === \"pointerup\") follow(endEvent);\n activeGesture.current = null;\n setGestureThumb(null);\n commitGesture(thumb, \"activate\", endEvent);\n };\n const detach = (): void => {\n element.removeEventListener(\"pointermove\", onMove);\n element.removeEventListener(\"pointerup\", onEnd);\n element.removeEventListener(\"pointercancel\", onEnd);\n element.removeEventListener(\"lostpointercapture\", onEnd);\n };\n element.addEventListener(\"pointermove\", onMove);\n element.addEventListener(\"pointerup\", onEnd);\n element.addEventListener(\"pointercancel\", onEnd);\n element.addEventListener(\"lostpointercapture\", onEnd);\n\n activeGesture.current = { pointerId, detach };\n setGestureThumb(thumb);\n // A capture alone holds `live` on screen, from what is shown (a press exactly on the\n // current value steps nothing).\n captureGesture();\n // `:focus-visible` does not match after a pointer press, as on a native range.\n registry.get(thumb)?.focus({ focusVisible: false } as FocusOptions);\n if (decided !== null) moveTo(thumb, start, event);\n },\n [captureGesture, commitGesture, latest, registry, shownRef, stepTo],\n );\n\n // An unmount mid-gesture leaves no listener behind.\n useEffect(\n () => () => {\n activeGesture.current?.detach();\n activeGesture.current = null;\n },\n [],\n );\n\n // --- Development warnings ------------------------------------------------------------------\n\n useSliderDevWarnings({\n stepProp,\n stepValid,\n min,\n max,\n step,\n value,\n defaultValue,\n shape,\n // Inside a Field, `Field.Label` names the group (design 9.4.2).\n unnamedGroup:\n shown.length > 1 &&\n !inField &&\n rest[\"aria-label\"] === undefined &&\n rest[\"aria-labelledby\"] === undefined,\n labelCountRef,\n });\n\n // --- Render --------------------------------------------------------------------------------\n\n const count = shown.length;\n const geometry = sliderGeometry(shown, min, max);\n\n const shownValue = fromArray(shown);\n const dragging = gestureThumb !== null;\n const state = useMemo<SliderRootState<T>>(\n () => ({\n value: shownValue,\n values: shown,\n pending,\n dragging,\n orientation,\n disabled,\n min,\n max,\n step,\n }),\n [shownValue, shown, pending, dragging, orientation, disabled, min, max, step],\n );\n\n // Memoised: the functions are stable, so this changes only with the state below.\n const context = useMemo<SliderContextValue>(\n () => ({\n state: state as SliderRootState<SliderValue>,\n shown,\n min,\n max,\n step,\n gap,\n orientation,\n disabled,\n pending,\n draggingThumb: gestureThumb,\n pendingThumb,\n name,\n form,\n getAriaValueText,\n labelId,\n thumbId,\n trackRef,\n inputStep,\n inputCommit,\n inputKeyDown,\n beginGesture,\n registerThumb,\n registerLabel,\n onItemMounted,\n field: fieldWiring,\n }),\n [\n state,\n shown,\n min,\n max,\n step,\n gap,\n orientation,\n disabled,\n pending,\n gestureThumb,\n pendingThumb,\n name,\n form,\n getAriaValueText,\n labelId,\n thumbId,\n inputStep,\n inputCommit,\n inputKeyDown,\n beginGesture,\n registerThumb,\n registerLabel,\n onItemMounted,\n fieldWiring,\n ],\n );\n\n // Several thumbs: the Field's label, then `Slider.Label` while one is mounted (the consumer's\n // tokens come first through the merge). Only when there is one: an owned `undefined` would\n // remove the consumer's own tokens.\n const labelledBy =\n count > 1 ? mergeTokenLists(fieldLabelledBy, labelCount > 0 ? labelId : undefined) : \"\";\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n role: count > 1 ? \"group\" : undefined,\n ...(labelledBy !== \"\" ? { \"aria-labelledby\": labelledBy } : {}),\n // The group element is described (read when focus enters it); one thumb: its input is.\n ...(count > 1 && fieldDescribedBy !== undefined\n ? { \"aria-describedby\": fieldDescribedBy }\n : {}),\n // Inside a Field only (`aria-invalid` goes on the inputs, never on the group).\n ...(inField ? { \"data-invalid\": fieldDataInvalid } : {}),\n \"data-pending\": dataAttr(pending),\n \"data-dragging\": dataAttr(dragging),\n \"data-orientation\": orientation,\n \"data-disabled\": dataAttr(disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, SliderRootState<T>>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The geometry properties lose to the consumer's own entries (design 3.1).\n style: (s) => ({ ...(geometry as CSSProperties), ...resolveStateValue(style, s) }),\n children,\n props: rest,\n libraryProps,\n ref: rootRef,\n });\n\n return <SliderContext value={context}>{element}</SliderContext>;\n}\n\nSliderRootImpl.displayName = \"SliderRoot\";\n\n/**\n * `Slider.Root`. Overloaded so that the value's shape is inferred from `value` / `defaultValue`\n * as `number` or `readonly number[]` (an array literal would otherwise infer a mutable\n * `number[]`), and every action and state function receives that shape (design 3.1).\n *\n * @see https://ui.funstack.work/components/slider\n */\nexport const SliderRoot = SliderRootImpl as {\n (props: SliderRootProps<number>): ReactNode;\n (props: SliderRootProps<readonly number[]>): ReactNode;\n (props: SliderRootProps<SliderValue>): ReactNode;\n displayName?: string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkNA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,MAAM,aAAa,gBAAgB,UAAU,QAAQ;AACrD,MAAM,eAAe,gBAAgB,UAAU,QAAQ;;AAGvD,SAAS,cAAc,QAAsB,OAAsB;CACjE,OAAO;EAAE;EAAQ;CAAM;AACzB;AAEA,SAAS,UAAU,QAA2B,OAAe,OAAkC;CAC7F,OAAO,OAAO,KAAK,GAAG,MAAO,MAAM,QAAQ,QAAQ,CAAE;AACvD;;AAGA,SAAS,cACP,UACA,QACM;CACN,KAAK,MAAM,CAAC,OAAO,UAAU,UAAU;EACrC,MAAM,QAAQ,OAAO;EACrB,IAAI,UAAU,KAAA,GAAW,MAAM,eAAe,OAAO,KAAK;CAC5D;AACF;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,eAA+C,OAA2B;CACjF,MAAM,EACJ,OACA,cACA,mBACA,mBACA,MAAM,GACN,MAAM,KACN,MAAM,WAAW,GACjB,wBAAwB,GACxB,cAAc,cACd,kBACA,MAAM,UACN,MACA,UAAU,eAAe,OACzB,WACA,OACA,UACA,QACA,GAAG,SACD;CAEJ,MAAM,YAAY,OAAO,SAAS,QAAQ,KAAK,WAAW;CAC1D,MAAM,OAAO,YAAY,WAAW;CACpC,MAAM,MAAM,KAAK,IAAI,GAAG,qBAAqB,IAAI;CAEjD,MAAM,KAAK,MAAM;CACjB,MAAM,UAAU,GAAG,GAAG;CAGtB,MAAM,CAAC,SAAS,eAAmC,QAAQ,SAAS,YAAY,KAAK,QAAQ;CAC7F,MAAM,YAAY,aACf,WAAkC,UAAU,WAAW,OAAO,KAAK,QACpE,CAAC,KAAK,CACR;CAIA,MAAM,CAAC,cAAc,mBAAmB,SAAwB,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AEA,eAAe,cAAc;;;;;;;;AAS7B,MAAa,aAAa"}
|
|
1
|
+
{"version":3,"file":"slider-root.mjs","names":[],"sources":["../../src/slider/slider-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { mergeTokenLists } from \"../internal/merge-props.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n Orientation,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useFieldControl, useFieldValueChange } from \"../internal/form/use-field-control.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useNativeGroupReconciliation } from \"../internal/form/use-native-group-reconciliation.js\";\nimport { useResetTarget } from \"../internal/form/use-form-reset.js\";\nimport { useRegisterCount } from \"../internal/use-register-count.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useStepCommit } from \"../internal/action/use-step-commit.js\";\nimport {\n clampToNeighbours,\n equalValues,\n nearestThumb,\n platformDefault,\n pointerValue,\n resolveTie,\n sanitize,\n shapeOf,\n sliderGeometry,\n tiedRange,\n toArray,\n} from \"./slider-arithmetic.js\";\nimport { SliderContext } from \"./slider-context.js\";\nimport type { SliderContextValue, SliderFieldWiring } from \"./slider-context.js\";\nimport { useSliderDevWarnings } from \"./use-slider-dev-warnings.js\";\nimport { useThumbRegistry } from \"./use-thumb-registry.js\";\n\n/** One number (one thumb) or one number per thumb, in ascending order. */\nexport type SliderValue = number | readonly number[];\n\n/** The arrow-key axis and layout of a Slider. */\nexport type SliderOrientation = Orientation;\n\n/** Details passed as the second argument of `Slider.Root`'s `valueChangeAction` (each step). */\nexport interface SliderValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user moved a thumb (`details.event` is the native `input` event for a key\n * press, the `pointerdown` / `pointermove` / `pointerup` for a drag, the `keydown` for a\n * JS-normalised key).\n * `\"platform\"`: a form reset (the `reset` event) or a value found in the inputs at mount\n * (`undefined`).\n * `\"dismiss\"`: the commit action rejected and the slider reverted to the committed value\n * (uncontrolled mode; `undefined`).\n */\n readonly reason: ChangeReason;\n /** Index of the thumb that moved; `null` on a platform path or a revert, where several may change. */\n readonly thumb: number | null;\n}\n\n/** Details passed as the second argument of `Slider.Root`'s `valueCommitAction` (each gesture). */\nexport interface SliderValueCommitDetails extends ActionDetails {\n /**\n * `\"activate\"`: a gesture ended (`details.event` is the native `change` event for a key press,\n * the `pointerup` / `pointercancel` / `lostpointercapture` for a drag, the `keydown` for a\n * JS-normalised key). `\"platform\"`: a form reset (the `reset` event) or mount reconciliation\n * (`undefined`). Never `\"dismiss\"`.\n */\n readonly reason: ChangeReason;\n /** Index of the thumb the gesture moved; `null` on a platform path. */\n readonly thumb: number | null;\n}\n\n/**\n * State of `Slider.Root` and `Slider.Label`, passed to the function forms of `className`,\n * `style`, `children` and `render`.\n */\nexport interface SliderRootState<T extends SliderValue = number> {\n /**\n * The value the thumbs show: the value a gesture has reached while a pointer is captured or a\n * step or commit is in flight, else the optimistic value. Content rendered from it must not\n * suspend.\n */\n readonly value: T;\n /** `value` as an array, one entry per thumb, in thumb order. */\n readonly values: readonly number[];\n /** A step or commit dispatched through this Slider is in flight. */\n readonly pending: boolean;\n /** A pointer is captured on a thumb. */\n readonly dragging: boolean;\n /** The `orientation` prop. */\n readonly orientation: SliderOrientation;\n /** The `disabled` prop, or the enclosing Field's. */\n readonly disabled: boolean;\n /** The `min` prop. */\n readonly min: number;\n /** The `max` prop. */\n readonly max: number;\n /** The `step` prop. */\n readonly step: number;\n}\n\n/**\n * Props of `Slider.Root`. `T` is `number` (one thumb) or `readonly number[]` (one entry per\n * thumb), inferred from `value` / `defaultValue`.\n *\n * @see https://ui.funstack.work/components/slider\n */\nexport interface SliderRootProps<T extends SliderValue = number> extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"defaultValue\"\n | \"role\"\n | \"className\"\n | \"style\"\n | \"children\"\n // The value attributes are the native inputs' (design 8): never authored.\n | \"aria-valuemin\"\n | \"aria-valuemax\"\n | \"aria-valuenow\"\n | \"aria-valuetext\"\n | \"aria-orientation\"\n> {\n /** Controlled value: one number, or one per thumb in ascending order. `undefined`: uncontrolled. */\n value?: T;\n /**\n * Initial value in uncontrolled mode; also the form-reset target (latest value).\n *\n * @defaultValue the platform's midpoint, `min + (max - min) / 2`, snapped to `step`\n */\n defaultValue?: T;\n /**\n * Runs inside the Root's step transition on every step: each pointer move, each key press,\n * each platform change, and the revert after a rejected commit (`reason: \"dismiss\"`,\n * uncontrolled). Awaited; `data-pending` meanwhile (without this action a step starts no\n * transition and is never pending). Adopt the value here in a controlled\n * parent (`setValue(next)` in the sync prefix is a transition update). Not the place for a\n * save: a pending async action entangles every transition in the app, and a drag is many\n * steps. A `setState` after your own `await` needs `startTransition`.\n */\n valueChangeAction?: ChangeAction<T, SliderValueChangeDetails>;\n /**\n * Runs inside the Root's commit transition once per gesture: pointer release, each key press,\n * a form reset, a value found at mount. Awaited; the thumb keeps the gesture's value and shows\n * `data-pending` until it settles; in uncontrolled mode the value is committed when it\n * resolves and reverts to the previous value if it rejects. May be a Server Function.\n */\n valueCommitAction?: ChangeAction<T, SliderValueCommitDetails>;\n /**\n * Lower bound of the range.\n *\n * @defaultValue `0`\n */\n min?: number;\n /**\n * Upper bound of the range. A `max` that is not on the step grid from `min` is unreachable, as\n * on a native range (dev warning).\n *\n * @defaultValue `100`\n */\n max?: number;\n /**\n * Must be positive. Values snap to `min + n × step`.\n *\n * @defaultValue `1`\n */\n step?: number;\n /**\n * Minimum number of steps between two adjacent thumbs.\n *\n * @defaultValue `0` (thumbs may share a value)\n */\n minStepsBetweenThumbs?: number;\n /**\n * Layout and arrow-key axis. Vertical sliders have `min` at the bottom.\n *\n * @defaultValue `\"horizontal\"`\n */\n orientation?: SliderOrientation;\n /**\n * `aria-valuetext` for a thumb, from the value it shows. Set it when the number alone is not\n * meaningful (\"3 of 5 stars\", \"Tuesday\"). Default: none (the number is announced).\n */\n getAriaValueText?: (value: number, index: number) => string;\n /**\n * Form field name for every thumb's input (a Thumb's own `name` wins). With several thumbs,\n * read with `FormData.getAll()`.\n */\n name?: string;\n /** The `form` attribute for every thumb's input (a Thumb's own `form` wins). */\n form?: string;\n /**\n * Disables every input (native `disabled`; not submitted) and the pointer. Never set while\n * pending. Inside a `Field.Root`, the Field's `disabled` also applies.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, SliderRootState<T>>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, SliderRootState<T>>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, SliderRootState<T>>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, SliderRootState<T>>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nconst STEP_TYPES = transitionTypes(\"slider\", \"change\");\nconst COMMIT_TYPES = transitionTypes(\"slider\", \"commit\");\n\n/** The `details` fields of both actions. */\nfunction sliderDetails(reason: ChangeReason, thumb: number | null) {\n return { reason, thumb };\n}\n\nfunction replaceAt(values: readonly number[], index: number, value: number): readonly number[] {\n return values.map((v, i) => (i === index ? value : v));\n}\n\n/** Writes each registered input's `defaultValue` (the attribute a form reset restores). */\nfunction writeDefaults(\n registry: ReadonlyMap<number, HTMLInputElement>,\n target: readonly number[],\n): void {\n for (const [index, input] of registry) {\n const entry = target[index];\n if (entry !== undefined) input.defaultValue = String(entry);\n }\n}\n\n/** A pointer captured on a Thumb or the Track (design 4.1). */\ninterface ActiveGesture {\n readonly pointerId: number;\n /** Detaches the gesture's listeners. */\n readonly detach: () => void;\n}\n\n/**\n * Owns the slider's state (design/components/slider.md 2): the committed value through\n * `useControllableAction` with `valueCommitAction` (once per gesture), each step through its own\n * transition (`valueChangeAction`), and the value a gesture has reached in the urgent lane\n * (`live`), which the thumbs show while a pointer is captured or anything is in flight. Also the\n * pointer gesture, the Thumb registry, mount reconciliation and form reset, and the geometry\n * custom properties `--slider-start`, `--slider-end` and `--slider-value-<i>`.\n *\n * Owned keys (conventions 1.2): `role` (`\"group\"` with several thumbs), `aria-labelledby` (the\n * Label's id while a Label is mounted and there are several thumbs; token-merged with the\n * consumer's), `data-pending`, `data-dragging`, `data-orientation`, `data-disabled`. The custom\n * properties are merged into `style`, where the consumer's entries win.\n *\n * Inside a `Field.Root` (design 9.4) the Root calls `useFieldControl`: with one thumb, Thumb 0's\n * input is the Field's labelable control; with several, the Root registers itself as the group\n * and also owns the Field label in `aria-labelledby`, the Field's `aria-describedby` and\n * `data-invalid`. `name` / `disabled` default from the Field.\n */\nfunction SliderRootImpl<T extends SliderValue = number>(props: SliderRootProps<T>) {\n const {\n value,\n defaultValue,\n valueChangeAction,\n valueCommitAction,\n min = 0,\n max = 100,\n step: stepProp = 1,\n minStepsBetweenThumbs = 0,\n orientation = \"horizontal\",\n getAriaValueText,\n name: nameProp,\n form,\n disabled: disabledProp = false,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n const stepValid = Number.isFinite(stepProp) && stepProp > 0;\n const step = stepValid ? stepProp : 1;\n const gap = Math.max(0, minStepsBetweenThumbs) * step;\n\n const id = useId();\n const labelId = `${id}-label`;\n\n // The shape (one number or an array) is fixed at mount (design 3.1).\n const [shape] = useState<\"number\" | \"array\">(() => shapeOf(value ?? defaultValue) ?? \"number\");\n const fromArray = useCallback(\n (values: readonly number[]): T => (shape === \"number\" ? values[0] : values) as T,\n [shape],\n );\n\n // --- State (design 2) ----------------------------------------------------------------------\n\n const [gestureThumb, setGestureThumb] = useState<number | null>(null);\n const activeGesture = useRef<ActiveGesture | null>(null);\n const trackRef = useRef<HTMLElement | null>(null);\n\n // The step and commit core (design 2.4), shared with NumberField; values are arrays inside.\n const {\n shown,\n shownRef,\n optimisticShown: optimisticValues,\n pending,\n pendingSource: pendingThumb,\n step: stepTo,\n commit: commitGesture,\n openGesture,\n captureGesture,\n markGestureStart,\n takeEdit,\n } = useStepCommit<T, readonly number[], number, ReturnType<typeof sliderDetails>>({\n controlled: value,\n defaultValue,\n initialValue: platformDefault(min, max, step) as T,\n stepAction: valueChangeAction,\n commitAction: valueCommitAction,\n stepTypes: STEP_TYPES,\n commitTypes: COMMIT_TYPES,\n warn: { component: \"Slider.Root\", prop: \"value\" },\n toShown: toArray,\n fromShown: fromArray,\n equals: equalValues,\n details: sliderDetails,\n captured: gestureThumb !== null,\n });\n\n // --- Inside a Field.Root (design 9.4) ------------------------------------------------------\n\n // One thumb: its input is the Field's labelable control. Several: the Root (`role=\"group\"`)\n // registers, `Field.Label` drops `for` and names the group through `aria-labelledby`.\n const thumbCount = shown.length;\n const field = useFieldControl({\n labelable: thumbCount === 1,\n name: nameProp,\n disabled: disabledProp,\n component: \"Slider.Root\",\n });\n const fieldName = field.fieldName;\n const name = field.name;\n const disabled = field.disabled;\n const fieldId = field.id;\n const thumbId = useCallback(\n (index: number) => (index === 0 && fieldId !== undefined ? fieldId : `${id}-thumb-${index}`),\n [id, fieldId],\n );\n const rootRef = thumbCount > 1 ? field.ref : undefined;\n useDevWarning(\n field.inField && field.required,\n isDev &&\n \"Slider.Root: a range is never empty, so `required` on the enclosing Field.Root has no \" +\n \"effect on the slider.\",\n );\n // A pointer gesture and the JS-normalised keys fire no `input` / `change` the Field hears:\n // tell it at the commit, when the optimistic value changes (design 9.4.4). `\"activate\"`\n // dismisses a shown server error, a rollback does not.\n useFieldValueChange(optimisticValues.join(\"\\u0000\"), takeEdit);\n const {\n \"aria-labelledby\": fieldLabelledBy,\n \"aria-describedby\": fieldDescribedBy,\n \"aria-invalid\": fieldInvalid,\n \"data-invalid\": fieldDataInvalid,\n } = field.attributes;\n const inField = field.inField;\n const fieldRef = field.ref;\n const fieldWiring = useMemo<SliderFieldWiring | null>(() => {\n if (!inField) return null;\n const single = thumbCount === 1;\n return {\n inputRef: single ? fieldRef : undefined,\n describedBy: single ? fieldDescribedBy : undefined,\n invalid: fieldInvalid,\n dataInvalid: fieldDataInvalid,\n name: fieldName,\n };\n }, [inField, fieldRef, thumbCount, fieldDescribedBy, fieldInvalid, fieldDataInvalid, fieldName]);\n\n const latest = useLatest({\n min,\n max,\n step,\n gap,\n orientation,\n disabled,\n });\n\n // --- Thumb registry ------------------------------------------------------------------------\n\n const { registry, registerThumb, formElement } = useThumbRegistry();\n\n // --- Labels --------------------------------------------------------------------------------\n\n // The ref is for the dev warning, which can run before the re-render the registration scheduled.\n const {\n count: labelCount,\n register: registerLabel,\n countRef: labelCountRef,\n } = useRegisterCount();\n\n // --- Residual browser paths: mount reconciliation and form reset (design 9.2, 9.3) --------\n\n // Neither mode's target given: the current value (controlled after an uncontrolled mount), else\n // the platform default.\n const resetBase = useResetTarget(value, defaultValue);\n const resetTarget = (): readonly number[] =>\n toArray(resetBase ?? value ?? platformDefault(min, max, step));\n\n const readCurrent = (): readonly number[] =>\n shownRef.current.map((v, index) => {\n const input = registry.get(index);\n if (input === undefined) return v;\n const read = Number(input.value);\n return Number.isFinite(read) ? read : v;\n });\n\n const { onItemMounted } = useNativeGroupReconciliation<readonly number[]>({\n element: formElement,\n readCurrent,\n readDefault: resetTarget,\n base: () => shownRef.current,\n // Compare as the DOM would hold the values: a consumer's off-grid value is sanitised by the\n // browser (not by jsdom), and that is not a platform change.\n equals: (a, b) => {\n const reference = shownRef.current;\n return equalValues(\n sanitize(a, reference, min, max, step, gap),\n sanitize(b, reference, min, max, step, gap),\n );\n },\n onPlatformChange: (next, event) => {\n if (next.length !== shownRef.current.length) return;\n openGesture();\n stepTo(next, null, \"platform\", event);\n commitGesture(null, \"platform\", event);\n },\n onResetEvent: () => {\n // react-dom writes `defaultValue = value` after every update of a controlled input, so the\n // reset target is written here, right before the browser's reset algorithm reads it.\n writeDefaults(registry, resetTarget());\n },\n });\n\n // --- Keyboard (design 4.2) -----------------------------------------------------------------\n\n const inputStep = useCallback(\n (index: number, raw: number, event: Event) => {\n if (!Number.isFinite(raw)) return;\n const before = shownRef.current;\n if (index >= before.length) return;\n // A key press is a one-step gesture: it starts at the value shown before it.\n if (stepTo(replaceAt(before, index, raw), index, \"activate\", event)) {\n markGestureStart(before);\n }\n },\n [markGestureStart, shownRef, stepTo],\n );\n\n const inputCommit = useCallback(\n (index: number, event: Event) => {\n // A pointer gesture commits at its release.\n if (activeGesture.current !== null) return;\n commitGesture(index, \"activate\", event);\n },\n [commitGesture],\n );\n\n const inputKeyDown = useCallback(\n (index: number, event: KeyboardEvent) => {\n const {\n orientation: axis,\n disabled: off,\n min: lo,\n max: hi,\n step: inc,\n gap: g,\n } = latest.current;\n if (off) return;\n if (event.key !== \"ArrowLeft\" && event.key !== \"ArrowRight\") return;\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n // Vertical: Firefox decreases a vertical range on ArrowRight; the APG says increase.\n // Horizontal RTL: the track is mirrored (min on the right), so ArrowLeft increases;\n // Chromium and Firefox mirror a native range, WebKit does not (design 7). LTR stays native.\n let increaseKey: \"ArrowLeft\" | \"ArrowRight\";\n if (axis === \"vertical\") {\n increaseKey = \"ArrowRight\";\n } else {\n // Read at the keydown: the direction may come from any ancestor and change at any time.\n const input = event.currentTarget as Element | null;\n if (input === null || getComputedStyle(input).direction !== \"rtl\") return;\n increaseKey = \"ArrowLeft\";\n }\n event.preventDefault();\n const before = shownRef.current;\n const current = before[index];\n if (current === undefined) return;\n const delta = event.key === increaseKey ? inc : -inc;\n const next = replaceAt(\n before,\n index,\n clampToNeighbours(before, index, current + delta, lo, hi, inc, g),\n );\n if (activeGesture.current !== null) {\n stepTo(next, index, \"activate\", event);\n return;\n }\n openGesture();\n stepTo(next, index, \"activate\", event);\n commitGesture(index, \"activate\", event);\n },\n [commitGesture, latest, openGesture, shownRef, stepTo],\n );\n\n // --- Pointer (design 4.1) ------------------------------------------------------------------\n\n const warnedNoTrack = useRef(false);\n const beginGesture = useCallback(\n (index: number | null, event: PointerEvent, element: HTMLElement) => {\n const { disabled: off } = latest.current;\n if (off || event.button !== 0 || activeGesture.current !== null) return;\n // Disabled by the platform (an ancestor `<fieldset disabled>`): the range inputs match\n // `:disabled` while the Root's state does not see it, and the Track and Thumb spans still\n // take the pointer (conventions 3.6, #180). Read at the press, like the direction.\n for (const input of registry.values()) {\n if (input.matches(\":disabled\")) return;\n }\n const track = trackRef.current;\n if (track === null) {\n if (isDev && !warnedNoTrack.current) {\n warnedNoTrack.current = true;\n console.error(\n \"Slider.Thumb: a pointer press needs a Slider.Track to map the pointer to a value. \" +\n \"Without a Track the slider is keyboard-only.\",\n );\n }\n return;\n }\n // No text selection, no focus change through the compatibility `mousedown`.\n event.preventDefault();\n const rtl = getComputedStyle(track).direction === \"rtl\";\n\n const valueAt = (clientX: number, clientY: number): number => {\n const { min: lo, max: hi, orientation: axis } = latest.current;\n const rect = (trackRef.current ?? track).getBoundingClientRect();\n return pointerValue(rect, clientX, clientY, axis, rtl, lo, hi);\n };\n const moveTo = (thumb: number, raw: number, cause: Event): void => {\n const { min: lo, max: hi, step: inc, gap: g } = latest.current;\n const before = shownRef.current;\n if (thumb >= before.length) return;\n stepTo(\n replaceAt(before, thumb, clampToNeighbours(before, thumb, raw, lo, hi, inc, g)),\n thumb,\n \"activate\",\n cause,\n );\n };\n\n const start = valueAt(event.clientX, event.clientY);\n const startValues = shownRef.current;\n // A press on a Thumb that shares its value with a neighbour (stacked thumbs) moves the one\n // that can go toward the pointer, the Track's tie rule; when the press is exactly on the\n // value, the first move decides. Otherwise a Thumb press moves that Thumb.\n const tied = index === null ? null : tiedRange(startValues, index);\n /** The thumb the gesture moves; `null` while a press on stacked thumbs is undecided. */\n let decided: number | null =\n index === null ? nearestThumb(startValues, start) : tied ? resolveTie(tied, start) : index;\n /** The thumb shown as dragging and focused meanwhile. */\n let thumb = decided ?? index ?? 0;\n const pointerId = event.pointerId;\n try {\n element.setPointerCapture(pointerId);\n } catch {\n // An inactive pointer id (a synthetic event): the gesture still follows the element.\n }\n\n const decide = (raw: number): boolean => {\n if (decided !== null) return true;\n decided = resolveTie(tied, raw);\n if (decided === null) return false;\n if (decided !== thumb) {\n thumb = decided;\n setGestureThumb(thumb);\n registry.get(thumb)?.focus({ focusVisible: false } as FocusOptions);\n }\n return true;\n };\n const follow = (pointerEvent: PointerEvent): void => {\n const raw = valueAt(pointerEvent.clientX, pointerEvent.clientY);\n if (decide(raw)) moveTo(thumb, raw, pointerEvent);\n };\n\n const onMove = (moveEvent: PointerEvent): void => {\n if (moveEvent.pointerId !== pointerId) return;\n follow(moveEvent);\n };\n const onEnd = (endEvent: PointerEvent): void => {\n if (endEvent.pointerId !== pointerId) return;\n detach();\n // The release position is the gesture's last (an engine may coalesce the final move\n // into the `pointerup`); a cancel or a lost capture keeps the last move's value.\n if (endEvent.type === \"pointerup\") follow(endEvent);\n activeGesture.current = null;\n setGestureThumb(null);\n commitGesture(thumb, \"activate\", endEvent);\n };\n const detach = (): void => {\n element.removeEventListener(\"pointermove\", onMove);\n element.removeEventListener(\"pointerup\", onEnd);\n element.removeEventListener(\"pointercancel\", onEnd);\n element.removeEventListener(\"lostpointercapture\", onEnd);\n };\n element.addEventListener(\"pointermove\", onMove);\n element.addEventListener(\"pointerup\", onEnd);\n element.addEventListener(\"pointercancel\", onEnd);\n element.addEventListener(\"lostpointercapture\", onEnd);\n\n activeGesture.current = { pointerId, detach };\n setGestureThumb(thumb);\n // A capture alone holds `live` on screen, from what is shown (a press exactly on the\n // current value steps nothing).\n captureGesture();\n // `:focus-visible` does not match after a pointer press, as on a native range.\n registry.get(thumb)?.focus({ focusVisible: false } as FocusOptions);\n if (decided !== null) moveTo(thumb, start, event);\n },\n [captureGesture, commitGesture, latest, registry, shownRef, stepTo],\n );\n\n // An unmount mid-gesture leaves no listener behind.\n useEffect(\n () => () => {\n activeGesture.current?.detach();\n activeGesture.current = null;\n },\n [],\n );\n\n // --- Development warnings ------------------------------------------------------------------\n\n useSliderDevWarnings({\n stepProp,\n stepValid,\n min,\n max,\n step,\n value,\n defaultValue,\n shape,\n // Inside a Field, `Field.Label` names the group (design 9.4.2).\n unnamedGroup:\n shown.length > 1 &&\n !inField &&\n rest[\"aria-label\"] === undefined &&\n rest[\"aria-labelledby\"] === undefined,\n labelCountRef,\n });\n\n // --- Render --------------------------------------------------------------------------------\n\n const count = shown.length;\n const geometry = sliderGeometry(shown, min, max);\n\n const shownValue = fromArray(shown);\n const dragging = gestureThumb !== null;\n const state = useMemo<SliderRootState<T>>(\n () => ({\n value: shownValue,\n values: shown,\n pending,\n dragging,\n orientation,\n disabled,\n min,\n max,\n step,\n }),\n [shownValue, shown, pending, dragging, orientation, disabled, min, max, step],\n );\n\n // Memoised: the functions are stable, so this changes only with the state below.\n const context = useMemo<SliderContextValue>(\n () => ({\n state: state as SliderRootState<SliderValue>,\n shown,\n min,\n max,\n step,\n gap,\n orientation,\n disabled,\n pending,\n draggingThumb: gestureThumb,\n pendingThumb,\n name,\n form,\n getAriaValueText,\n labelId,\n thumbId,\n trackRef,\n inputStep,\n inputCommit,\n inputKeyDown,\n beginGesture,\n registerThumb,\n registerLabel,\n onItemMounted,\n field: fieldWiring,\n }),\n [\n state,\n shown,\n min,\n max,\n step,\n gap,\n orientation,\n disabled,\n pending,\n gestureThumb,\n pendingThumb,\n name,\n form,\n getAriaValueText,\n labelId,\n thumbId,\n inputStep,\n inputCommit,\n inputKeyDown,\n beginGesture,\n registerThumb,\n registerLabel,\n onItemMounted,\n fieldWiring,\n ],\n );\n\n // Several thumbs: the Field's label, then `Slider.Label` while one is mounted (the consumer's\n // tokens come first through the merge). Only when there is one: an owned `undefined` would\n // remove the consumer's own tokens.\n const labelledBy =\n count > 1 ? mergeTokenLists(fieldLabelledBy, labelCount > 0 ? labelId : undefined) : \"\";\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n role: count > 1 ? \"group\" : undefined,\n ...(labelledBy !== \"\" ? { \"aria-labelledby\": labelledBy } : {}),\n // The group element is described (read when focus enters it); one thumb: its input is.\n ...(count > 1 && fieldDescribedBy !== undefined\n ? { \"aria-describedby\": fieldDescribedBy }\n : {}),\n // Inside a Field only (`aria-invalid` goes on the inputs, never on the group).\n ...(inField ? { \"data-invalid\": fieldDataInvalid } : {}),\n \"data-pending\": dataAttr(pending),\n \"data-dragging\": dataAttr(dragging),\n \"data-orientation\": orientation,\n \"data-disabled\": dataAttr(disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, SliderRootState<T>>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The geometry properties lose to the consumer's own entries (design 3.1).\n style: (s) => ({ ...(geometry as CSSProperties), ...resolveStateValue(style, s) }),\n children,\n props: rest,\n libraryProps,\n ref: rootRef,\n });\n\n return <SliderContext value={context}>{element}</SliderContext>;\n}\n\nSliderRootImpl.displayName = \"SliderRoot\";\n\n/**\n * `Slider.Root`. Overloaded so that the value's shape is inferred from `value` / `defaultValue`\n * as `number` or `readonly number[]` (an array literal would otherwise infer a mutable\n * `number[]`), and every action and state function receives that shape (design 3.1).\n *\n * @see https://ui.funstack.work/components/slider\n */\nexport const SliderRoot = SliderRootImpl as {\n (props: SliderRootProps<number>): ReactNode;\n (props: SliderRootProps<readonly number[]>): ReactNode;\n (props: SliderRootProps<SliderValue>): ReactNode;\n displayName?: string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkNA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,MAAM,aAAa,gBAAgB,UAAU,QAAQ;AACrD,MAAM,eAAe,gBAAgB,UAAU,QAAQ;;AAGvD,SAAS,cAAc,QAAsB,OAAsB;CACjE,OAAO;EAAE;EAAQ;CAAM;AACzB;AAEA,SAAS,UAAU,QAA2B,OAAe,OAAkC;CAC7F,OAAO,OAAO,KAAK,GAAG,MAAO,MAAM,QAAQ,QAAQ,CAAE;A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A;EACA;EACA;EACA,OAAO;CACT,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAKA,MAAM,aACJ,QAAQ,IAAI,gBAAgB,iBAAiB,aAAa,IAAI,UAAU,KAAA,CAAS,IAAI;CACvF,MAAM,eAAuE;EAC3E,MAAM,QAAQ,IAAI,UAAU,KAAA;EAC5B,GAAI,eAAe,KAAK,EAAE,mBAAmB,WAAW,IAAI,CAAC;EAE7D,GAAI,QAAQ,KAAK,qBAAqB,KAAA,IAClC,EAAE,oBAAoB,iBAAiB,IACvC,CAAC;EAEL,GAAI,UAAU,EAAE,gBAAgB,iBAAiB,IAAI,CAAC;EACtD,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,QAAQ;EAClC,oBAAoB;EACpB,iBAAiB,SAAS,QAAQ;CACpC;CAEA,MAAM,UAAU,UAA4D;EAC1E,gBAAgB;EAChB;EACA;EACA;EAEA,QAAQ,OAAO;GAAE,GAAI;GAA4B,GAAG,kBAAkB,OAAO,CAAC;EAAE;EAChF;EACA,OAAO;EACP;EACA,KAAK;CACP,CAAC;CAED,OAAO,oBAAC,eAAD;EAAe,OAAO;EAAU,UAAA;CAAuB,CAAA;AAChE;AAEA,eAAe,cAAc;;;;;;;;AAS7B,MAAa,aAAa"}
|
|
@@ -5,9 +5,9 @@ import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
|
5
5
|
import { useRender } from "../internal/use-render.mjs";
|
|
6
6
|
import { useLatest } from "../internal/use-latest.mjs";
|
|
7
7
|
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
8
|
-
import { DialogContext } from "../dialog/dialog-context.mjs";
|
|
9
8
|
import { animationBaseline } from "../internal/overlay/use-exit-animation.mjs";
|
|
10
9
|
import { callUrgentHandler } from "../internal/action/call-urgent-handler.mjs";
|
|
10
|
+
import { DialogContext } from "../dialog/dialog-context.mjs";
|
|
11
11
|
import { ToastViewportContext } from "./toast-context.mjs";
|
|
12
12
|
import { toast, toastManagerInternals } from "./toast.mjs";
|
|
13
13
|
import { DEFAULT_HOTKEY, regionLabel } from "./toast-hotkey.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funstack/ui",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.20",
|
|
4
4
|
"description": "Headless UI library for React — the first Async React-native UI library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -34,21 +34,26 @@
|
|
|
34
34
|
"exports": {
|
|
35
35
|
".": "./dist/index.mjs",
|
|
36
36
|
"./accordion": "./dist/accordion/index.mjs",
|
|
37
|
+
"./alert-dialog": "./dist/alert-dialog/index.mjs",
|
|
37
38
|
"./button": "./dist/button/index.mjs",
|
|
38
39
|
"./checkbox": "./dist/checkbox/index.mjs",
|
|
39
40
|
"./checkbox-group": "./dist/checkbox-group/index.mjs",
|
|
41
|
+
"./collapsible": "./dist/collapsible/index.mjs",
|
|
40
42
|
"./combobox": "./dist/combobox/index.mjs",
|
|
41
43
|
"./csp": "./dist/csp/index.mjs",
|
|
42
44
|
"./dialog": "./dist/dialog/index.mjs",
|
|
43
45
|
"./field": "./dist/field/index.mjs",
|
|
44
46
|
"./form": "./dist/form/index.mjs",
|
|
47
|
+
"./hover-card": "./dist/hover-card/index.mjs",
|
|
45
48
|
"./menu": "./dist/menu/index.mjs",
|
|
46
49
|
"./meter": "./dist/meter/index.mjs",
|
|
50
|
+
"./multi-select": "./dist/multi-select/index.mjs",
|
|
47
51
|
"./number-field": "./dist/number-field/index.mjs",
|
|
48
52
|
"./popover": "./dist/popover/index.mjs",
|
|
49
53
|
"./progress": "./dist/progress/index.mjs",
|
|
50
54
|
"./radio-group": "./dist/radio-group/index.mjs",
|
|
51
55
|
"./select": "./dist/select/index.mjs",
|
|
56
|
+
"./separator": "./dist/separator/index.mjs",
|
|
52
57
|
"./slider": "./dist/slider/index.mjs",
|
|
53
58
|
"./switch": "./dist/switch/index.mjs",
|
|
54
59
|
"./tabs": "./dist/tabs/index.mjs",
|
|
@@ -11,18 +11,18 @@ Requirements: `react` and `react-dom` `>=19.3.0` (peer dependencies). ESM only.
|
|
|
11
11
|
|
|
12
12
|
## Mental model
|
|
13
13
|
|
|
14
|
-
- **Action props, not event handlers.** Interactive props are named `action` or `fooAction` (`pressedChangeAction`, `valueChangeAction`, `openChangeAction`, `checkedChangeAction`). The component calls them inside its own React transition and awaits a returned promise. Change actions (`xChangeAction`) take `(next, details)`; task actions (`action` on `Button`, `Menu.Item`, `Dialog.Close`, `Popover.Close`, `Toast.Action`) take only `(details)`, so write `action={() => save()}`, not `action={(next) => ...}`. The return type is `unknown`. `details.event` is the native DOM event; `details.reason` (where present) is `"activate" | "platform" | "dismiss" | "timeout"`.
|
|
14
|
+
- **Action props, not event handlers.** Interactive props are named `action` or `fooAction` (`pressedChangeAction`, `valueChangeAction`, `openChangeAction`, `checkedChangeAction`). The component calls them inside its own React transition and awaits a returned promise. Change actions (`xChangeAction`) take `(next, details)`; task actions (`action` on `Button`, `Menu.Item`, `Dialog.Close`, `AlertDialog.Action`, `Popover.Close`, `Toast.Action`) take only `(details)`, so write `action={() => save()}`, not `action={(next) => ...}`. The return type is `unknown`. `details.event` is the native DOM event; `details.reason` (where present) is `"activate" | "platform" | "dismiss" | "timeout"`.
|
|
15
15
|
- **State triple.** A controllable state `x` comes as `x` (controlled), `defaultX` (uncontrolled initial value) and `xChangeAction`. `undefined` means uncontrolled; "nothing selected" is `null`. Do not switch between controlled and uncontrolled after mount.
|
|
16
16
|
- **Optimistic and pending are built in.** While an action is pending, triggers (the parts the user acts on) already show the new value, and the state owner (usually the `Root`) and the trigger carry `data-pending`. If the action rejects, the value rolls back and the error goes to the nearest Error Boundary. Uncontrolled state is written only after success.
|
|
17
|
-
- **Latest intent wins, for uncontrolled state.** A second click while pending is a new intent: the optimistic display follows it, and uncontrolled state commits only the most recent dispatch (set-valued state, `CheckboxGroup` and non-`exclusive` `ToggleGroup` / `Accordion`, commits every change whose action resolved, in order, and leaves out one whose action rejected; a later action's `next` still includes an earlier pending change, so persist `details.added` / `details.removed`, not the whole `next`; exception: a `CheckboxGroup` form reset, `reason: "platform"` with `details.event?.type === "reset"`, is absolute, so persist its `next` whole, its `added` / `removed` can be empty; to keep saves from overlapping at all, queue them with React's `useActionState`). The rejection of an older action that a newer one superseded does not reach the Error Boundary (as with React's own `useTransition`); the library passes it to the global `reportError`, so it fires the window `error` event and fails a test run that does not stub `reportError`. The same goes for a rejection that arrives after its component unmounted (a toast or menu closed while its action ran) or while `<Activity>` hides it. In controlled mode, your own `setState` after an `await` lands in completion order, so an older response can overwrite a newer one; guard it yourself or queue the calls with React's `useActionState`. A pure trigger (a part that runs a task: `Button`, `Dialog.Close`, `Popover.Close`, `Menu.Item`, `Toast.Action`) has no value to protect; what a click while its own action is pending does is its `whilePending` prop (`"run" | "ignore"`, type `WhilePending`). `"run"` runs the action again (runs overlap; `data-pending` until the last settles, no `aria-disabled`; an older run's rejection goes to `reportError`); `"ignore"` drops the click, cancels its default action and renders `aria-disabled="true"` while pending (not while you have it natively `disabled`: native `disabled` wins). Defaults: `Button` `"run"` (put `whilePending="ignore"` on a Save, Pay or Delete, and on a `formAction` submitter that must not submit twice: React drops an older overlapping submission's rejection); Close parts `"ignore"`; `Menu.Item` and `Toast.Action` `"ignore"`, but `"run"` with `closeOnActivate={false}` / `closeOnSettle={false}`. Parts are never natively disabled while pending.
|
|
18
|
-
- **Content regions show the committed value.** Panels and popup content follow the committed state, so content that suspends keeps the old content on screen until it is ready (with value or open props, an Accordion item, Dialog or Popover stays closed until then; without them their content is rendered ahead and must not suspend). The library never adds `<Suspense>` and has no `fallback` props; you place boundaries.
|
|
19
|
-
- **`transition` prop = `<ViewTransition>`.** Parts whose content is driven by library state accept `transition`; passing it wraps the part in `<ViewTransition default={transition}>`. Without it, no boundary is rendered. Each dispatch is tagged with `fsui-<component>` transition types (for example `fsui-tabs-next`), usable in a type map or `:active-view-transition-type()`. On a popup (`Dialog`, `Popover`, `Menu`, `Combobox`), write a CSS exit for dismissals next to `transition`: the library turns the popup's CSS transitions off for the moment of its own show or hide while a view transition runs, so an `html:active-view-transition .popup { transition: none }` rule (older docs needed one) is not needed: remove it (keeping it is harmless, but it also cuts a dismissal's fade during an unrelated view transition). Only CSS transitions are cut: write the popup's exit as a `transition`, not a `@keyframes` animation.
|
|
17
|
+
- **Latest intent wins, for uncontrolled state.** A second click while pending is a new intent: the optimistic display follows it, and uncontrolled state commits only the most recent dispatch (set-valued state, `CheckboxGroup` and non-`exclusive` `ToggleGroup` / `Accordion`, commits every change whose action resolved, in order, and leaves out one whose action rejected; a later action's `next` still includes an earlier pending change, so persist `details.added` / `details.removed`, not the whole `next`; exception: a `CheckboxGroup` form reset, `reason: "platform"` with `details.event?.type === "reset"`, is absolute, so persist its `next` whole, its `added` / `removed` can be empty; to keep saves from overlapping at all, queue them with React's `useActionState`). The rejection of an older action that a newer one superseded does not reach the Error Boundary (as with React's own `useTransition`); the library passes it to the global `reportError`, so it fires the window `error` event and fails a test run that does not stub `reportError`. The same goes for a rejection that arrives after its component unmounted (a toast or menu closed while its action ran) or while `<Activity>` hides it. In controlled mode, your own `setState` after an `await` lands in completion order, so an older response can overwrite a newer one; guard it yourself or queue the calls with React's `useActionState`. A pure trigger (a part that runs a task: `Button`, `Dialog.Close`, `AlertDialog.Cancel`, `AlertDialog.Action`, `Popover.Close`, `Menu.Item`, `Toast.Action`) has no value to protect; what a click while its own action is pending does is its `whilePending` prop (`"run" | "ignore"`, type `WhilePending`). `"run"` runs the action again (runs overlap; `data-pending` until the last settles, no `aria-disabled`; an older run's rejection goes to `reportError`); `"ignore"` drops the click, cancels its default action and renders `aria-disabled="true"` while pending (not while you have it natively `disabled`: native `disabled` wins). Defaults: `Button` `"run"` (put `whilePending="ignore"` on a Save, Pay or Delete, and on a `formAction` submitter that must not submit twice: React drops an older overlapping submission's rejection); Close parts (`Dialog.Close`, `Popover.Close`, `AlertDialog.Cancel`, `AlertDialog.Action`) `"ignore"`; `Menu.Item` and `Toast.Action` `"ignore"`, but `"run"` with `closeOnActivate={false}` / `closeOnSettle={false}`. Parts are never natively disabled while pending.
|
|
18
|
+
- **Content regions show the committed value.** Panels and popup content follow the committed state, so content that suspends keeps the old content on screen until it is ready (with value or open props, an Accordion item, Collapsible, Dialog or Popover stays closed until then; without them their content is rendered ahead and must not suspend). The library never adds `<Suspense>` and has no `fallback` props; you place boundaries.
|
|
19
|
+
- **`transition` prop = `<ViewTransition>`.** Parts whose content is driven by library state accept `transition`; passing it wraps the part in `<ViewTransition default={transition}>`. Without it, no boundary is rendered. Each dispatch is tagged with `fsui-<component>` transition types (for example `fsui-tabs-next`), usable in a type map or `:active-view-transition-type()`. On a popup (`Dialog`, `Popover`, `Menu`, `Combobox`, `MultiSelect`), write a CSS exit for dismissals next to `transition`: the library turns the popup's CSS transitions off for the moment of its own show or hide while a view transition runs, so an `html:active-view-transition .popup { transition: none }` rule (older docs needed one) is not needed: remove it (keeping it is harmless, but it also cuts a dismissal's fade during an unrelated view transition). Only CSS transitions are cut: write the popup's exit as a `transition`, not a `@keyframes` animation.
|
|
20
20
|
- **Browser-owned state.** Where the platform owns the state (popover top layer, `<details open>`, `<dialog>` dismissal, native inputs), the library observes it instead of copying it. Escape and click-outside are browser dismissals, **facts**: they are not passed to `openChangeAction` (requests only) but to `onOpenChange(false, details)`, called synchronously, not awaited, never pending, and they cannot be vetoed. A controlled overlay therefore takes both: `open={open} openChangeAction={setOpen} onOpenChange={setOpen}` (set state directly in `onOpenChange`, never in `startTransition` or after an `await`; a parent that keeps `open={true}` re-opens it).
|
|
21
21
|
- **Headless.** No provider, no theme, no stylesheet. Style with your CSS on `data-*` attributes (present as `data-x=""` when true, absent when false; enum states carry a value, `data-orientation="vertical"`). Hover, focus and active are not attributes: use `:hover`, `:focus-visible`, `:active`.
|
|
22
22
|
|
|
23
23
|
## Things agents get wrong
|
|
24
24
|
|
|
25
|
-
1. **Do not use `onClick`, `onChange`, `onValueChange`, `onPressedChange`.** They do not exist as library props. Handlers a part installs itself (for example `onClick` on `Toggle`) are removed from its props type; unused DOM handlers pass through to the element. The library's own `on*` props report **facts** (changes that had already happened when the library heard of them, such as a popup dismissed with Escape): `onOpenChange` on `Popover.Root`, `Menu.Root`, `Combobox.Root` and `
|
|
25
|
+
1. **Do not use `onClick`, `onChange`, `onValueChange`, `onPressedChange`.** They do not exist as library props. Handlers a part installs itself (for example `onClick` on `Toggle`) are removed from its props type; unused DOM handlers pass through to the element. The library's own `on*` props report **facts** (changes that had already happened when the library heard of them, such as a popup dismissed with Escape): `onOpenChange` on `Popover.Root`, `Menu.Root`, `Combobox.Root`, `MultiSelect.Root`, `Dialog.Root` and `AlertDialog.Root` (dismissals only, always `false`), `Combobox.Root`'s `onInputValueChange` (input text), and a toast's `onClose` (`toast({ onClose })`, formerly `closeAction`). Each is called synchronously, outside any transition, not awaited; it may return a promise; a rejection, or a throw, goes to `reportError`.
|
|
26
26
|
2. **Do not wrap the action in `startTransition` yourself**, and do not add `useOptimistic` or a pending flag around a component: it already does this. But a `setState` that runs **after your own `await`** inside an action is outside the transition (a React rule); wrap that one in `startTransition`.
|
|
27
27
|
3. **Return a promise only if the UI must wait for it.** A pending async action holds every other transition in the app (including router navigations). For background work, do not return the promise: `valueChangeAction={(v) => { void save(v); }}`.
|
|
28
28
|
4. **No `asChild`, no `as`.** Use `render`: `render={<MyButton />}` (the element must accept `ref` and spread its props) or `render={(props, state) => <a {...props} />}`.
|
|
@@ -44,22 +44,27 @@ Each line: import path, parts, main state props.
|
|
|
44
44
|
- `Toolbar` (`@funstack/ui/toolbar`): `Root`, `Separator`. Any focusable descendant is an item; no item part.
|
|
45
45
|
- `Tabs` (`@funstack/ui/tabs`): `Root`, `List`, `Tab`, `Panel`, `Indicator`. `value` / `valueChangeAction`; `Panel` takes `transition`, `keepMounted`.
|
|
46
46
|
- `Accordion` (`@funstack/ui/accordion`): `Root`, `Item` (`<details>`), `Trigger` (`<summary>`, first child of the Item), `Panel`. Without value props it needs no JavaScript; `exclusive` for one open item.
|
|
47
|
+
- `Collapsible` (`@funstack/ui/collapsible`): `Root` (the `<details>` itself), `Trigger` (`<summary>`, first child of the Root), `Panel`. One disclosure; use it rather than a lone `Accordion.Item`. `open` / `defaultOpen` / `openChangeAction` (no `onOpenChange`: find-in-page arrives as `reason: "platform"`); with none of them it needs no JavaScript, and `defaultOpen` alone (even `false`) selects library mode.
|
|
47
48
|
- `Tooltip` (`@funstack/ui/tooltip`): `Root`, `Trigger`, `Popup`, `Arrow`. Open state is the browser's (no open props); `delay`, `closeDelay`.
|
|
49
|
+
- `HoverCard` (`@funstack/ui/hover-card`): `Root`, `Trigger` (a link), `Popup` (render it right after the Trigger; `render={<span />}` inside running text). Opens on hover or keyboard focus after `delay` (600) as a request (`openChangeAction(true)`, content mounts in the transition and may suspend, Trigger `data-pending`); every close (lost interest after `closeDelay` 300, Escape, a press outside or on the link) is a fact for `onOpenChange(false)`. Content must be supplementary (nothing on touch); a click-to-open card is a Popover.
|
|
48
50
|
- `Popover` (`@funstack/ui/popover`): `Root`, `Trigger`, `Popup`, `Close`, `Title`, `Description`. `open` / `openChangeAction` (requests) / `onOpenChange` (dismissals); without open props it needs no JavaScript.
|
|
49
|
-
- `Dialog` (`@funstack/ui/dialog`): `Root`, `Trigger`, `Popup` (`<dialog>`), `Close`, `Form`, `Title`, `Description`. Same modes as Popover; `Dialog.Form` closes after its form action settles.
|
|
51
|
+
- `Dialog` (`@funstack/ui/dialog`): `Root`, `Trigger`, `Popup` (`<dialog>`), `Close`, `Form`, `Title`, `Description`. Same modes as Popover; `Dialog.Form` closes after its form action settles. A `Close` with `action` (Dialog or Popover) renders no native command, so it does nothing before hydration; the JS-free way to run work and close is `Dialog.Form` with a Server Function.
|
|
52
|
+
- `AlertDialog` (`@funstack/ui/alert-dialog`): a Dialog for confirmations. `Root` (no `modal`: always modal), `Trigger`, `Popup` (`<dialog role="alertdialog">`, no `lightDismiss`: a backdrop click does nothing), `Title`, `Description` (expected: dev warning without one), `Cancel` (focused on open; `initialFocus` on the Popup overrides), `Action`, `Form`. Put the confirmed work in `<AlertDialog.Action action={() => deleteProject(id)}>`: it pends on the button and closes the dialog when it resolves; a rejection keeps it open (place an Error Boundary inside the Popup to show it; a caught error resolves and closes). An Action with `action` does nothing before hydration (as every Close part with `action`); the confirm that works without JavaScript is `AlertDialog.Form action={serverFunction}` with a plain submit button. Escape always closes it (a fact for `onOpenChange`; no prop turns it off), and so does Cancel while the Action is pending (in library mode that close waits for the action to settle and shows nothing meanwhile: disable Cancel with your own `useOptimistic` flag set inside the action when the work is slow). Same transition types and data attributes as Dialog.
|
|
50
53
|
- `Menu` (`@funstack/ui/menu`): `Root`, `Trigger`, `Popup`, `Item` (`action`), `CheckboxItem`, `RadioGroup`, `RadioItem`, `Group`, `GroupLabel`, `Separator`, `SubmenuTrigger`, `ContextTrigger` (context menu). A `Root` inside a `Popup` is a submenu.
|
|
51
54
|
- `Toast` (`@funstack/ui/toast`): `toast()` (also `toast.promise`, `toast.update`, `toast.dismiss`), `createToastManager`, parts `Viewport`, `Root`, `Title`, `Description`, `Action`, `Close`.
|
|
52
|
-
- `Field` (`@funstack/ui/field`): `Root`, `Label`, `Control`, `Description`, `Error`. Native constraint validation, no validation engine.
|
|
55
|
+
- `Field` (`@funstack/ui/field`): `Root`, `Label`, `Control`, `Description`, `Error`. Native constraint validation, no validation engine. A textarea is `<Field.Control render={<textarea />} />`, grown with CSS `field-sizing: content` (no auto-size prop). `Field.Control` also works outside a `Field.Root` as the plain control (it takes `id` there; the other parts throw). There is no Input, Textarea or Fieldset part: use the native elements, and group Fields in a native `<fieldset>` / `<legend>` (`<fieldset disabled>` disables every FUNSTACK control inside, but their `data-disabled` does not see it: select `:disabled`). Never disable a fieldset because a submission is pending (focus is lost); use `form[data-pending]`.
|
|
53
56
|
- `Form` (`@funstack/ui/form`): `Root` (`action`, `errors` for server errors per field), `Submit`.
|
|
54
57
|
- `Checkbox` (`@funstack/ui/checkbox`): native checkbox; `checked` / `checkedChangeAction`, controlled-only `indeterminate`.
|
|
55
58
|
- `CheckboxGroup` (`@funstack/ui/checkbox-group`): `Root`, `Label`, `Item`, `Parent` (select-all). `value` is `string[]`.
|
|
56
59
|
- `RadioGroup` (`@funstack/ui/radio-group`): `Root`, `Label`, `Item`. Native radios; `value` / `valueChangeAction`.
|
|
57
60
|
- `Switch` (`@funstack/ui/switch`): native `<input type="checkbox" role="switch">`; `checked` / `checkedChangeAction`.
|
|
58
|
-
- `Select` (`@funstack/ui/select`): a real `<select>`. `Root`, `Trigger`, `Value`, `Option`, `Group`, `GroupLabel`, `Separator`. Styled picker via CSS `appearance: base-select`.
|
|
59
|
-
- `Combobox` (`@funstack/ui/combobox`): `Root`, `Label`, `Input`, `Trigger`, `Clear`, `Popup`, `List`, `Option`, `Group`, `GroupLabel`, `Empty`, `Status`. You render the options (no built-in filtering); `List` children get the deferred `query`; `inputValue` / `onInputValueChange` is urgent.
|
|
61
|
+
- `Select` (`@funstack/ui/select`): a real `<select>`. `Root`, `Trigger`, `Value`, `Option`, `Group`, `GroupLabel`, `Separator`. Styled picker via CSS `appearance: base-select`. Single value only: `<Select.Root multiple>` is a type error (dropped with a dev warning); use `MultiSelect`.
|
|
62
|
+
- `Combobox` (`@funstack/ui/combobox`): `Root`, `Label`, `Input`, `Trigger`, `Clear`, `Popup`, `List`, `Option`, `Group`, `GroupLabel`, `Empty`, `Status`, and with `multiple` `Chips`, `Chip`, `ChipRemove`. You render the options (no built-in filtering); `List` children get the deferred `query`; `inputValue` / `onInputValueChange` is urgent. `Root multiple`: `value` is `string[]` (pick order), `valueChangeAction(next, { added, removed })` (persist the diff); a pick toggles, clears the text and keeps the listbox open; render chips with `<Combobox.Chips>{({ value }) => value.map((v) => <Combobox.Chip key={v} value={v} />)}</Combobox.Chips>` next to the Input (not around it).
|
|
63
|
+
- `MultiSelect` (`@funstack/ui/multi-select`): a select-only combobox for several values (JS listbox on a popover; nothing opens before hydration). `Root`, `Label`, `Trigger` (`button[role=combobox]`, the Tab stop), `Value`, `Popup`, `List`, `Option`, `Group`, `GroupLabel`, `Empty`, `Status`. `value` is `string[]` (pick order), `valueChangeAction(next, { added, removed })` (persist the diff); a pick toggles and keeps the listbox open; full open-state API (`open`, `openChangeAction`, `onOpenChange`). Show the selection with `<MultiSelect.Value>{({ value }) => value.map((v) => names[v]).join(", ")}</MultiSelect.Value>` (the library knows a label only after the option was rendered once). `required` (at least one) blocks the submit with no browser bubble: put it in a `Field.Root` with `Field.Error` for the message. No chips, no search, no Clear: for those use `Combobox multiple`.
|
|
60
64
|
- `Slider` (`@funstack/ui/slider`): `Root`, `Label`, `Track`, `Indicator`, `Thumb`, `Value`. `valueChangeAction` per step, `valueCommitAction` once per gesture; `value` is a number or `number[]`.
|
|
61
65
|
- `NumberField` (`@funstack/ui/number-field`): `Root`, `Label`, `Input`, `Increment`, `Decrement`. Locale-formatted; `valueChangeAction`, `valueCommitAction`.
|
|
62
66
|
- `Progress` (`@funstack/ui/progress`) and `Meter` (`@funstack/ui/meter`): `Root`, `Track`, `Indicator`, `Label`, `Value`. Output only, no actions; the Root renders in a Server Component.
|
|
67
|
+
- `Separator` (`@funstack/ui/separator`): a single `<hr>`; `orientation` (`"horizontal"` default, `"vertical"`), `decorative` (`role="none"`, no `aria-orientation`: for a purely visual line; it is also the separator element that is valid inside a Combobox or MultiSelect listbox, where a Group boundary styled in CSS is the other option). `data-orientation` always; reset the `<hr>`'s margin and border in CSS. No `"use client"`: a Server Component may render it. Inside a Toolbar, Menu or Select use their own `Separator` part.
|
|
63
68
|
- `CSPProvider`, `STYLE_SHA256` (`@funstack/ui/csp`): for a strict `style-src` Content Security Policy.
|
|
64
69
|
|
|
65
70
|
## Full documentation
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-active-option.mjs","names":[],"sources":["../../src/combobox/use-active-option.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\nimport type { OptionRegistry } from \"./use-option-registry.js\";\n\nexport interface ActiveOptionOptions {\n readonly popover: Pick<PopoverRootValue, \"committed\" | \"intended\">;\n readonly orderedOptions: OptionRegistry[\"orderedOptions\"];\n /** The Root's `autoHighlight`. */\n readonly autoHighlight: boolean;\n /** The results shown are for an older text: never auto-highlighted. */\n readonly stale: boolean;\n}\n\nexport interface ActiveOption {\n /** The value of the option `aria-activedescendant` points at, or `null` (urgent state). */\n readonly activeValue: string | null;\n /** The same, for handlers: written together with the state. */\n readonly activeRef: RefObject<string | null>;\n readonly setActive: (next: string | null) => void;\n /** The edge to activate once the open has options (ArrowDown / ArrowUp while closed). */\n readonly pendingEdgeRef: RefObject<\"first\" | \"last\" | null>;\n /**\n * `autoHighlight` (APG automatic selection) highlights once per open and once per edit, when\n * the results for it settle. Home / End / Left / Right clear the active option without\n * re-arming it, so the caret keys really return visual focus to the input.\n */\n readonly autoArmedRef: RefObject<boolean>;\n}\n\n/**\n * The active option of a combobox (design/components/combobox.md 2 and 6.5): urgent virtual\n * focus, revalidated against the mounted options in a layout effect after every commit.\n */\nexport function useActiveOption({\n popover,\n orderedOptions,\n autoHighlight,\n stale,\n}: ActiveOptionOptions): ActiveOption {\n const [activeValue, setActiveValue] = useState<string | null>(null);\n const activeRef = useRef<string | null>(null);\n const setActive = useCallback((next: string | null) => {\n activeRef.current = next;\n setActiveValue(next);\n }, []);\n const pendingEdgeRef = useRef<\"first\" | \"last\" | null>(null);\n const autoArmedRef = useRef(true);\n\n // Revalidation (design 6.5): urgent, in a layout effect after every commit; never dispatches.\n useLayoutEffect(() => {\n const current = activeRef.current;\n if (!popover.committed) {\n // Keep the edge of an open that is on its way (the optimistic commit comes first).\n if (!popover.intended()) pendingEdgeRef.current = null;\n autoArmedRef.current = true;\n if (current !== null) setActive(null);\n return;\n }\n const enabled = orderedOptions().filter((option) => !option.disabled);\n let next = current;\n if (pendingEdgeRef.current !== null && enabled.length > 0) {\n next = (pendingEdgeRef.current === \"first\" ? enabled[0] : enabled.at(-1))!.value;\n pendingEdgeRef.current = null;\n } else if (next !== null && !enabled.some((option) => option.value === next)) {\n next = null;\n }\n if (next !== null) {\n // Something is active (keys, hover): nothing to highlight for these results.\n autoArmedRef.current = false;\n } else if (autoHighlight && autoArmedRef.current && !stale && enabled.length > 0) {\n // Only settled results: a stale list's first option is never auto-highlighted, so a fast\n // Enter commits the typed text or does nothing (design 6.5).\n next = enabled[0]!.value;\n autoArmedRef.current = false;\n }\n if (next !== current) setActive(next);\n });\n\n return { activeValue, activeRef, setActive, pendingEdgeRef, autoArmedRef };\n}\n"],"mappings":";;;;;;;AAmCA,SAAgB,gBAAgB,EAC9B,SACA,gBACA,eACA,SACoC;CACpC,MAAM,CAAC,aAAa,kBAAkB,SAAwB,IAAI;CAClE,MAAM,YAAY,OAAsB,IAAI;CAC5C,MAAM,YAAY,aAAa,SAAwB;EACrD,UAAU,UAAU;EACpB,eAAe,IAAI;CACrB,GAAG,CAAC,CAAC;CACL,MAAM,iBAAiB,OAAgC,IAAI;CAC3D,MAAM,eAAe,OAAO,IAAI;CAGhC,sBAAsB;EACpB,MAAM,UAAU,UAAU;EAC1B,IAAI,CAAC,QAAQ,WAAW;GAEtB,IAAI,CAAC,QAAQ,SAAS,GAAG,eAAe,UAAU;GAClD,aAAa,UAAU;GACvB,IAAI,YAAY,MAAM,UAAU,IAAI;GACpC;EACF;EACA,MAAM,UAAU,eAAe,CAAC,CAAC,QAAQ,WAAW,CAAC,OAAO,QAAQ;EACpE,IAAI,OAAO;EACX,IAAI,eAAe,YAAY,QAAQ,QAAQ,SAAS,GAAG;GACzD,QAAQ,eAAe,YAAY,UAAU,QAAQ,KAAK,QAAQ,GAAG,EAAE,EAAA,CAAI;GAC3E,eAAe,UAAU;EAC3B,OAAO,IAAI,SAAS,QAAQ,CAAC,QAAQ,MAAM,WAAW,OAAO,UAAU,IAAI,GACzE,OAAO;EAET,IAAI,SAAS,MAEX,aAAa,UAAU;OAClB,IAAI,iBAAiB,aAAa,WAAW,CAAC,SAAS,QAAQ,SAAS,GAAG;GAGhF,OAAO,QAAQ,EAAE,CAAE;GACnB,aAAa,UAAU;EACzB;EACA,IAAI,SAAS,SAAS,UAAU,IAAI;CACtC,CAAC;CAED,OAAO;EAAE;EAAa;EAAW;EAAW;EAAgB;CAAa;AAC3E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-deferred-leave.mjs","names":[],"sources":["../../src/combobox/use-deferred-leave.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { useLatest } from \"../internal/use-latest.js\";\n\nexport interface DeferredLeaveOptions {\n readonly inputRef: RefObject<HTMLInputElement | null>;\n readonly popupRef: RefObject<HTMLElement | null>;\n /** Focus has left the input and the popup (design 5.4). */\n readonly leave: (event: Event) => void;\n}\n\nexport interface DeferredLeave {\n readonly focusIn: (event: FocusEvent) => void;\n readonly focusOut: (event: FocusEvent) => void;\n}\n\n/**\n * The Combobox Input's focus-leave decision (design 5.4), for `Combobox.Root`. A press blurs the\n * input at `mousedown`, but its outcome is known only at the `click`, which runs in the\n * `pointerup` task: a `<label for>` (Combobox.Label, Field.Label) refocuses the input there.\n * While the input is focused (and until a leave deferred to a release has been decided), the\n * presses on its document are tracked; a leave check made while one is down waits for the last\n * release. A window blur forgets the presses (a release it swallowed would otherwise hold the\n * check back), and so does focus arriving in the input.\n *\n * Returns the Input's `focus` and `blur` handlers: `focusIn` starts the tracking, `focusOut`\n * calls `leave` at once when focus moved to an element outside the input and the popup, and\n * decides one task after the press is released (or one task later) when it moved nowhere.\n */\nexport function useDeferredLeave({\n inputRef,\n popupRef,\n leave,\n}: DeferredLeaveOptions): DeferredLeave {\n const leaveRef = useLatest(leave);\n\n const presses = useRef(new Set<number>());\n const afterPress = useRef<(() => void) | null>(null);\n const unwatchPresses = useRef<(() => void) | null>(null);\n const unwatch = (): void => {\n unwatchPresses.current?.();\n unwatchPresses.current = null;\n presses.current.clear();\n afterPress.current = null;\n };\n const watchPresses = (input: HTMLInputElement): void => {\n presses.current.clear();\n if (unwatchPresses.current !== null) return;\n const doc = input.ownerDocument;\n const win = doc.defaultView;\n const released = (): void => {\n const check = afterPress.current;\n if (check === null || presses.current.size > 0) return;\n unwatch();\n setTimeout(check, 0);\n };\n const down = (event: PointerEvent): void => {\n presses.current.add(event.pointerId);\n };\n const up = (event: PointerEvent): void => {\n presses.current.delete(event.pointerId);\n released();\n };\n const blur = (): void => {\n presses.current.clear();\n released();\n };\n doc.addEventListener(\"pointerdown\", down, true);\n doc.addEventListener(\"pointerup\", up, true);\n doc.addEventListener(\"pointercancel\", up, true);\n win?.addEventListener(\"blur\", blur);\n unwatchPresses.current = () => {\n doc.removeEventListener(\"pointerdown\", down, true);\n doc.removeEventListener(\"pointerup\", up, true);\n doc.removeEventListener(\"pointercancel\", up, true);\n win?.removeEventListener(\"blur\", blur);\n };\n };\n useEffect(() => {\n // Focused before the Root mounted (autofocus, typing before hydration): no `focus` follows.\n const input = inputRef.current;\n if (input !== null && input.ownerDocument.activeElement === input) watchPresses(input);\n return unwatch;\n // `inputRef` is the Root's own ref object: the effect runs once, at mount.\n }, [inputRef]);\n\n const focusIn = (event: FocusEvent): void => {\n watchPresses(event.currentTarget as HTMLInputElement);\n };\n\n const focusOut = (event: FocusEvent): void => {\n const input = inputRef.current;\n const popup = popupRef.current;\n const next = event.relatedTarget;\n if (next instanceof Node) {\n if (next === input || (popup !== null && popup.contains(next))) return;\n unwatch();\n leave(event);\n return;\n }\n // No related target: the window lost focus (nothing to do), or a press landed on something\n // that takes no focus (a label, the page itself: focus moved to <body>). Decide one task\n // after the press is released (its click has run then), or one task later without a press.\n if (input === null) {\n unwatch();\n return;\n }\n const doc = input.ownerDocument;\n const check = () => {\n if (!doc.hasFocus()) return;\n const active = doc.activeElement;\n if (active === input || (active !== null && popup !== null && popup.contains(active))) {\n return;\n }\n if (input.isConnected) leaveRef.current(event);\n };\n if (presses.current.size > 0) {\n afterPress.current = check;\n } else {\n unwatch();\n setTimeout(check, 0);\n }\n };\n\n return { focusIn, focusOut };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8BA,SAAgB,iBAAiB,EAC/B,UACA,UACA,SACsC;CACtC,MAAM,WAAW,UAAU,KAAK;CAEhC,MAAM,UAAU,uBAAO,IAAI,IAAY,CAAC;CACxC,MAAM,aAAa,OAA4B,IAAI;CACnD,MAAM,iBAAiB,OAA4B,IAAI;CACvD,MAAM,gBAAsB;EAC1B,eAAe,UAAU;EACzB,eAAe,UAAU;EACzB,QAAQ,QAAQ,MAAM;EACtB,WAAW,UAAU;CACvB;CACA,MAAM,gBAAgB,UAAkC;EACtD,QAAQ,QAAQ,MAAM;EACtB,IAAI,eAAe,YAAY,MAAM;EACrC,MAAM,MAAM,MAAM;EAClB,MAAM,MAAM,IAAI;EAChB,MAAM,iBAAuB;GAC3B,MAAM,QAAQ,WAAW;GACzB,IAAI,UAAU,QAAQ,QAAQ,QAAQ,OAAO,GAAG;GAChD,QAAQ;GACR,WAAW,OAAO,CAAC;EACrB;EACA,MAAM,QAAQ,UAA8B;GAC1C,QAAQ,QAAQ,IAAI,MAAM,SAAS;EACrC;EACA,MAAM,MAAM,UAA8B;GACxC,QAAQ,QAAQ,OAAO,MAAM,SAAS;GACtC,SAAS;EACX;EACA,MAAM,aAAmB;GACvB,QAAQ,QAAQ,MAAM;GACtB,SAAS;EACX;EACA,IAAI,iBAAiB,eAAe,MAAM,IAAI;EAC9C,IAAI,iBAAiB,aAAa,IAAI,IAAI;EAC1C,IAAI,iBAAiB,iBAAiB,IAAI,IAAI;EAC9C,KAAK,iBAAiB,QAAQ,IAAI;EAClC,eAAe,gBAAgB;GAC7B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