@kirana-ui/react 0.2.0 → 0.4.0

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.
Files changed (148) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/llms.txt +1800 -187
  3. package/package.json +48 -3
  4. package/skills/kirana-ui-primitives/SKILL.md +53 -12
  5. package/src/accordion.d.ts +2 -2
  6. package/src/accordion.js +3 -2
  7. package/src/accordion.js.map +1 -1
  8. package/src/alert-dialog.d.ts +2 -2
  9. package/src/autocomplete.d.ts +2 -2
  10. package/src/autosize.d.ts +1 -1
  11. package/src/avatar.d.ts +28 -7
  12. package/src/avatar.js +22 -9
  13. package/src/avatar.js.map +1 -1
  14. package/src/button.d.ts +5 -2
  15. package/src/button.js +4 -1
  16. package/src/button.js.map +1 -1
  17. package/src/calendar.d.ts +23 -8
  18. package/src/calendar.js +50 -13
  19. package/src/calendar.js.map +1 -1
  20. package/src/carousel.d.ts +6 -3
  21. package/src/carousel.js +1 -1
  22. package/src/carousel.js.map +1 -1
  23. package/src/checkbox-group-context.d.ts +4 -0
  24. package/src/checkbox-group-context.js +7 -0
  25. package/src/checkbox-group-context.js.map +1 -0
  26. package/src/checkbox-group.d.ts +15 -0
  27. package/src/checkbox-group.js +30 -0
  28. package/src/checkbox-group.js.map +1 -0
  29. package/src/checkbox.d.ts +7 -2
  30. package/src/checkbox.js +9 -3
  31. package/src/checkbox.js.map +1 -1
  32. package/src/collapsible.d.ts +1 -1
  33. package/src/color-picker.d.ts +61 -0
  34. package/src/color-picker.js +119 -0
  35. package/src/color-picker.js.map +1 -0
  36. package/src/combobox.d.ts +54 -5
  37. package/src/combobox.js +49 -8
  38. package/src/combobox.js.map +1 -1
  39. package/src/command.d.ts +4 -4
  40. package/src/command.js +2 -1
  41. package/src/command.js.map +1 -1
  42. package/src/date-field.d.ts +2 -2
  43. package/src/date-field.js +3 -2
  44. package/src/date-field.js.map +1 -1
  45. package/src/date-picker.d.ts +33 -11
  46. package/src/date-picker.js +22 -5
  47. package/src/date-picker.js.map +1 -1
  48. package/src/dialog.d.ts +11 -6
  49. package/src/dialog.js +27 -8
  50. package/src/dialog.js.map +1 -1
  51. package/src/direction.d.ts +1 -1
  52. package/src/direction.js +1 -1
  53. package/src/editable.d.ts +32 -0
  54. package/src/editable.js +63 -0
  55. package/src/editable.js.map +1 -0
  56. package/src/field.d.ts +1 -1
  57. package/src/fieldset.d.ts +1 -1
  58. package/src/file-upload.d.ts +54 -0
  59. package/src/file-upload.js +96 -0
  60. package/src/file-upload.js.map +1 -0
  61. package/src/form.d.ts +1 -1
  62. package/src/hover-popup.d.ts +1 -1
  63. package/src/hover-popup.js +1 -1
  64. package/src/index.d.ts +28 -7
  65. package/src/index.js +12 -1
  66. package/src/input.d.ts +1 -1
  67. package/src/input.js +1 -1
  68. package/src/label.d.ts +1 -1
  69. package/src/listbox.d.ts +1 -1
  70. package/src/listbox.js +1 -1
  71. package/src/menu.d.ts +5 -5
  72. package/src/menu.js +14 -9
  73. package/src/menu.js.map +1 -1
  74. package/src/menubar.d.ts +2 -2
  75. package/src/menubar.js +4 -2
  76. package/src/menubar.js.map +1 -1
  77. package/src/message-scroller.d.ts +1 -1
  78. package/src/navigation-menu.d.ts +5 -5
  79. package/src/navigation-menu.js +14 -4
  80. package/src/navigation-menu.js.map +1 -1
  81. package/src/number-field.d.ts +11 -2
  82. package/src/number-field.js +20 -3
  83. package/src/number-field.js.map +1 -1
  84. package/src/otp.d.ts +3 -2
  85. package/src/otp.js +10 -2
  86. package/src/otp.js.map +1 -1
  87. package/src/pagination.d.ts +1 -1
  88. package/src/password-input.d.ts +23 -0
  89. package/src/password-input.js +40 -0
  90. package/src/password-input.js.map +1 -0
  91. package/src/popover.d.ts +12 -4
  92. package/src/popover.js +14 -1
  93. package/src/popover.js.map +1 -1
  94. package/src/qr-code.d.ts +1 -1
  95. package/src/radio-group.d.ts +4 -2
  96. package/src/radio-group.js +6 -3
  97. package/src/radio-group.js.map +1 -1
  98. package/src/rating.d.ts +28 -0
  99. package/src/rating.js +59 -0
  100. package/src/rating.js.map +1 -0
  101. package/src/resizable.d.ts +1 -1
  102. package/src/resizable.js +1 -1
  103. package/src/runtime.d.ts +18 -8
  104. package/src/runtime.js +24 -5
  105. package/src/runtime.js.map +1 -1
  106. package/src/scroll-area.d.ts +1 -1
  107. package/src/scroll-area.js +1 -1
  108. package/src/select.d.ts +17 -6
  109. package/src/select.js +6 -3
  110. package/src/select.js.map +1 -1
  111. package/src/separator.d.ts +1 -1
  112. package/src/slider.d.ts +2 -2
  113. package/src/slider.js +3 -2
  114. package/src/slider.js.map +1 -1
  115. package/src/steps.d.ts +51 -0
  116. package/src/steps.js +69 -0
  117. package/src/steps.js.map +1 -0
  118. package/src/switch.d.ts +2 -1
  119. package/src/switch.js +1 -1
  120. package/src/switch.js.map +1 -1
  121. package/src/tabs.d.ts +2 -2
  122. package/src/tabs.js +4 -3
  123. package/src/tabs.js.map +1 -1
  124. package/src/tags-input.d.ts +47 -0
  125. package/src/tags-input.js +92 -0
  126. package/src/tags-input.js.map +1 -0
  127. package/src/time-field.d.ts +32 -0
  128. package/src/time-field.js +67 -0
  129. package/src/time-field.js.map +1 -0
  130. package/src/toast.d.ts +1 -1
  131. package/src/toggle-group.d.ts +2 -2
  132. package/src/toggle-group.js +4 -3
  133. package/src/toggle-group.js.map +1 -1
  134. package/src/toggle.d.ts +1 -1
  135. package/src/toggle.js +1 -1
  136. package/src/toolbar.d.ts +14 -6
  137. package/src/toolbar.js +19 -9
  138. package/src/toolbar.js.map +1 -1
  139. package/src/tour.d.ts +61 -0
  140. package/src/tour.js +68 -0
  141. package/src/tour.js.map +1 -0
  142. package/src/tree.d.ts +45 -0
  143. package/src/tree.js +93 -0
  144. package/src/tree.js.map +1 -0
  145. package/src/use-render.d.ts +1 -1
  146. package/src/use-render.js +1 -1
  147. package/src/use-render.js.map +1 -1
  148. package/src/value-bar.d.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/react/src/runtime.tsx"],"sourcesContent":["import {\n composeProps,\n computed,\n defined,\n mergeProps,\n sameProps,\n signal,\n stateOf,\n} from \"@kirana-ui/core\"\nimport type {\n Anchor,\n Part,\n PartEvent,\n PartProps,\n PartState,\n PositionOptions,\n ReadonlySignal,\n Signal,\n} from \"@kirana-ui/core\"\nimport {\n cloneElement,\n createContext,\n createElement,\n forwardRef,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\"\nimport type {\n ClassAttributes,\n ComponentPropsWithoutRef,\n HTMLAttributes,\n JSX,\n ReactElement,\n ReactNode,\n Ref,\n RefCallback,\n RefObject,\n SyntheticEvent,\n} from \"react\"\nimport { createPortal } from \"react-dom\"\n\nimport { REF_IS_A_PROP, give, refOf } from \"./element.ts\"\n\n/** A layout effect in the browser, an effect (which never runs) on a server. */\nexport const useIsomorphicLayoutEffect =\n typeof document === \"undefined\" ? useEffect : useLayoutEffect\n\n/** A core signal's value, re-rendering when it changes. */\nexport function useSignal<T>(source: ReadonlySignal<T>): T {\n const subscribe = useCallback((listener: () => void) => source.subscribe(listener), [source])\n const read = useCallback(() => source.peek(), [source])\n return useSyncExternalStore(subscribe, read, read)\n}\n\n/**\n * A component's controller, made once, following the props of each render. The props reach the\n * core after the render commits (a layout effect), never during it: another part that reads the\n * controller is another component, and React forbids updating it mid-render.\n */\nexport function useController<P extends object, C extends { mount(): () => void }>(\n create: (props: ReadonlySignal<P>) => C,\n props: Omit<P, \"id\"> & { id?: string | undefined }\n): C {\n const generated = useId()\n const next = { ...props, id: props.id ?? generated } as P\n const latest = useRef(next)\n latest.current = next\n const [state] = useState(() => {\n // The callbacks the core holds always call the latest render's.\n const stable = {} as Record<string, unknown>\n for (const key in next) {\n stable[key] =\n typeof next[key] === \"function\"\n ? (...args: unknown[]) =>\n (latest.current[key] as ((...args: unknown[]) => unknown) | undefined)?.(...args)\n : next[key]\n }\n const source: Signal<P> = signal(stable as P, sameProps as (a: P, b: P) => boolean)\n return { source, controller: create(source) }\n })\n useIsomorphicLayoutEffect(() => {\n const stable = { ...state.source.peek() } as Record<string, unknown>\n for (const key in next) {\n if (typeof next[key] !== \"function\") stable[key] = next[key]\n }\n state.source.set(stable as P)\n })\n useMount(state.controller)\n return state.controller\n}\n\n/**\n * Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an\n * effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:\n * a mount is not undone for that. The cleanup waits a moment, and a mount that comes back in\n * the meantime keeps what is running.\n */\nexport function useMount(mounted: { mount(): () => void }): void {\n const [state] = useState(() => ({\n of: mounted,\n unmount: undefined as (() => void) | undefined,\n leaving: false,\n }))\n useEffect(() => {\n if (state.of !== mounted) {\n state.unmount?.()\n state.unmount = undefined\n state.of = mounted\n }\n state.leaving = false\n state.unmount ??= mounted.mount()\n return () => {\n state.leaving = true\n queueMicrotask(() => {\n if (!state.leaving) return\n state.unmount?.()\n state.unmount = undefined\n })\n }\n }, [state, mounted])\n}\n\n/** A part's own options as a core signal that follows each render, after it commits. */\nexport function useOptions<T extends Record<string, unknown>>(options: T): ReadonlySignal<T> {\n const [source] = useState(() => signal(options, sameProps as (a: T, b: T) => boolean))\n useIsomorphicLayoutEffect(() => source.set(options))\n return source\n}\n\n// HTML's boolean attributes, which React takes as booleans: a part's `\"\"` means \"present\".\nconst BOOLEAN = new Set([\n \"hidden\",\n \"disabled\",\n \"inert\",\n \"required\",\n \"readonly\",\n \"multiple\",\n \"checked\",\n \"novalidate\",\n])\nconst RENAMED: Record<string, string> = {\n tabindex: \"tabIndex\",\n for: \"htmlFor\",\n readonly: \"readOnly\",\n novalidate: \"noValidate\",\n autocomplete: \"autoComplete\",\n inputmode: \"inputMode\",\n maxlength: \"maxLength\",\n contenteditable: \"contentEditable\",\n spellcheck: \"spellCheck\",\n autocapitalize: \"autoCapitalize\",\n enterkeyhint: \"enterKeyHint\",\n}\n\n/** A style as React takes it: `inset-inline-start` is `insetInlineStart`, `--x` stays as it is. */\nfunction reactStyle(style: Record<string, string>): Record<string, string> {\n const out: Record<string, string> = {}\n for (const name in style) {\n const key = name.startsWith(\"--\")\n ? name\n : name.replace(/-([a-z])/g, (_match, letter: string) => letter.toUpperCase())\n out[key] = style[name]!\n }\n return out\n}\n\nfunction toReact(props: PartProps): Record<string, unknown> {\n const out: Record<string, unknown> = {}\n for (const key in props) {\n const value = props[key]\n if (BOOLEAN.has(key)) {\n const name = RENAMED[key] ?? key\n // Always a boolean, never left out: an input whose `checked` comes and goes is, to React,\n // one that changes from controlled to not. But a part with nothing to say leaves what a\n // caller wrote under React's own name (`readOnly`).\n if (value !== undefined || !(name in out)) {\n const present = value === \"\" || value === true\n // React 19 knows `inert` as a boolean, and takes `\"\"` for false with a warning. Before,\n // it is an attribute React does not know: `true` is dropped with a warning, and `\"\"`\n // is written.\n out[name] = key === \"inert\" && !REF_IS_A_PROP ? (present ? \"\" : undefined) : present\n }\n } else if (key === \"style\" && value) out.style = reactStyle(value as Record<string, string>)\n else if (value !== undefined) out[RENAMED[key] ?? key] = value\n }\n return out\n}\n\n/** The elements a part is drawn as, by their tag: `\"button\"`, `\"div\"`, `\"svg\"`. */\nexport type PartTag = keyof JSX.IntrinsicElements\n\n/** The element a tag draws: an `HTMLButtonElement` for `\"button\"`. */\nexport type ElementOf<Tag extends PartTag> =\n JSX.IntrinsicElements[Tag] extends ClassAttributes<infer Drawn> ? Drawn : Element\n\nexport type { PartEvent }\n\n// A handler takes the event with its `preventKiranaHandler()`; anything else is as it was.\ntype Hearing<Prop> = Prop extends (event: infer Heard) => infer Answer\n ? Heard extends SyntheticEvent\n ? (event: PartEvent<Heard>) => Answer\n : Prop\n : Prop\n\n/**\n * The props a `render` function is handed, to spread on what it draws: the part's attributes,\n * its handlers and its ref, with the caller's under them. An attribute of one kind of element\n * (`href`, `type`) is among them unnamed, as `unknown`.\n */\nexport type RenderedProps = HTMLAttributes<HTMLElement> & {\n ref?: RefCallback<HTMLElement> | undefined\n} & Record<string, unknown>\n\n/**\n * What `render` takes: an element, drawn with the part's props merged over its own, or a\n * function given the part's props and its state.\n */\nexport type RenderProp<State = PartState> =\n | ReactElement<Record<string, unknown>>\n | ((props: RenderedProps, state: State) => ReactElement)\n\n/**\n * A part's props: its element's own (`Tag`'s attributes and handlers, a `ref` to that\n * element), `render`, and the part's own props (`Own`) in place of the element's of the same\n * name. `State` is what a `render` function is told of the part.\n */\nexport type PartComponentProps<Tag extends PartTag = \"div\", State = PartState, Own = unknown> = {\n [Name in keyof ComponentPropsWithoutRef<Tag> as Name extends keyof Own ? never : Name]: Hearing<\n ComponentPropsWithoutRef<Tag>[Name]\n >\n} & Own & {\n /**\n * Renders the part as another element or component. An element's own props lie over the\n * props handed to the part, and the part's own (its role, its state, its handlers) over\n * both; a function is given the part's props and its state (`open`, `side` …, read from\n * its `data-*` attributes).\n */\n render?: RenderProp<State> | undefined\n ref?: Ref<ElementOf<Tag>> | undefined\n }\n\n// A part's props as `usePart` reads them, whatever element they are typed for.\ninterface Handed {\n render?: RenderProp<never> | undefined\n ref?: Ref<never> | undefined\n [attribute: string]: unknown\n}\n\n/** A part's DOM work on the element it is on. */\ninterface Attached {\n element: HTMLElement\n part: Part\n detach(): void\n leaving: boolean\n}\n\n/**\n * Renders a part: its element (or the caller's `render`), and the part's DOM work attached to\n * the element. Three layers of props, lowest first: what was handed to the part, the `render`\n * element's own, the part's. A higher layer wins an attribute; classes join; styles are merged\n * property by property; every handler of an event runs, lowest first, and\n * `event.preventKiranaHandler()` in a caller's stops the part's. The `render` element's own\n * children are drawn when it has any, and both its ref and the part's `ref` get the element.\n * `hold` is for a part that keeps something of its own in its element (a hidden input): it is\n * given the content and returns what the element holds, whoever drew the element.\n */\nexport function usePart<Tag extends PartTag, State = PartState>(\n part: Part,\n tag: Tag,\n props: PartComponentProps<Tag, State>,\n state?: State,\n hold?: (content: ReactNode) => ReactNode\n): ReactElement {\n const { render: asRender, ref: asRef, ...caller } = props as Handed\n const render = asRender as RenderProp<State> | undefined\n const ref = asRef as Ref<HTMLElement> | undefined\n const own = useSignal(part.props)\n const asked = isValidElement(render) ? render : undefined\n const theirs = asked ? refOf(asked) : undefined\n const held = useRef<Attached | undefined>(undefined)\n const attach = useCallback(\n (element: HTMLElement | null) => {\n const now = held.current\n if (!element) {\n // React takes a ref away and hands it straight back when the caller's `ref` is a new\n // function, and in StrictMode when the element is first drawn. The part's DOM work is\n // not undone for that (a popup would close its layer and give focus back): it is\n // undone a moment later, if the element has not come back.\n if (now) {\n now.leaving = true\n queueMicrotask(() => {\n if (!now.leaving) return\n now.detach()\n if (held.current === now) held.current = undefined\n })\n }\n } else if (now && now.element === element && now.part === part) {\n now.leaving = false\n } else {\n if (now) {\n now.leaving = false\n now.detach()\n }\n held.current = { element, part, detach: part.attach(element), leaving: false }\n }\n give(ref, element)\n give(theirs, element)\n },\n [part, ref, theirs]\n )\n let under: PartProps = caller\n if (asked) {\n // React 19 keeps an element's ref among its props: it is given the element above. Before,\n // the props have none, and reading it there warns.\n const { ref: _ref, ...element } = REF_IS_A_PROP ? asked.props : { ...asked.props }\n under = composeProps(caller, element)\n }\n const drawn: Record<string, unknown> = { ...toReact(mergeProps(under, own)), ref: attach }\n if (hold) drawn.children = hold(drawn.children as ReactNode)\n if (asked) return cloneElement(asked, drawn)\n if (typeof render === \"function\") return render(drawn, state ?? (stateOf(own) as State))\n return createElement(tag, drawn)\n}\n\nconst forwarded = new WeakMap<object, unknown>()\n\n/**\n * A component that is handed its caller's `ref` on every React the package takes, under the\n * name DevTools shows it by. React 19 gives a component its `ref` among its props, which is\n * where a part reads it; before, only a `forwardRef` component was given one, so there the\n * component is drawn by one that puts the ref back among the props. Its type is its own\n * either way, so one that is generic stays generic. One that already has a name keeps it.\n */\nexport function component<Drawn extends (props: never) => ReactNode>(\n name: string,\n draw: Drawn\n): Drawn {\n const named = draw as Drawn & { displayName?: string }\n if (REF_IS_A_PROP) {\n named.displayName ??= name\n return draw\n }\n let made = forwarded.get(draw)\n if (!made) {\n const drawing = draw as unknown as (props: object) => ReactElement | null\n const forwards = forwardRef<unknown, object>((props, ref) =>\n drawing(ref === null ? props : { ...props, ref })\n )\n forwards.displayName = name\n forwarded.set(draw, (made = forwards))\n }\n return made as Drawn\n}\n\n/**\n * A component's parts, each one a `component` named `Name.Part`. A part that is another\n * component's (a date picker's trigger is a popover's) is the same component there and here.\n */\nexport function parts<const Parts extends Record<string, unknown>>(\n name: string,\n all: Parts\n): Parts {\n const made: Record<string, unknown> = {}\n for (const key in all) {\n const part: unknown = all[key]\n made[key] =\n typeof part === \"function\"\n ? component(`${name}.${key}`, part as (props: never) => ReactNode)\n : part\n }\n return made as Parts\n}\n\n/**\n * A part's element as a component of its own, for a part that is not always in the page: the\n * part decides, and draws this when it is. It takes the part's props, with the part it is the\n * element `of`, its tag, and what the element holds of the part's own (`hold`, as `usePart`'s).\n */\nexport const PartElement = /* @__PURE__ */ component(\n \"PartElement\",\n function PartElement<Tag extends PartTag, State = PartState>({\n of,\n tag,\n hold,\n ...props\n }: PartComponentProps<Tag, State> & {\n of: Part\n tag: Tag\n hold?: ((content: ReactNode) => ReactNode) | undefined\n }): ReactElement {\n return usePart(of, tag, props as unknown as PartComponentProps<Tag, State>, undefined, hold)\n }\n)\n\n/** A positioner's own props: where its popup goes, and what it is placed against. */\nexport type PositionerOptions = Partial<Omit<PositionOptions, \"anchor\">> & {\n /**\n * What the popup is placed against, when that is not its trigger: an element, a ref to one,\n * a place in the viewport (an object with `getBoundingClientRect`), or a function that gives\n * one. It may change while the popup is open: the popup follows.\n */\n anchor?: Anchor | RefObject<Element | null> | (() => Anchor | null | undefined) | null | undefined\n}\n\n/** A positioner's props: where its popup goes and what it is placed against, and its element's. */\nexport type PositionerProps<State = PartState> = PartComponentProps<\"div\", State, PositionerOptions>\n\n// A ref's reader, the same function for the same ref: a render that changes nothing asks for\n// no new placement.\nconst readers = new WeakMap<object, () => Element | null>()\n\nfunction anchorOf(anchor: PositionerOptions[\"anchor\"]): PositionOptions[\"anchor\"] {\n if (!anchor || typeof anchor === \"function\") return anchor\n if (!(\"current\" in anchor) || \"getBoundingClientRect\" in anchor) return anchor as Anchor\n let read = readers.get(anchor)\n if (!read) readers.set(anchor, (read = () => anchor.current))\n return read\n}\n\n/**\n * A positioner's own props, written where its placement reads them: the one place they are\n * named. Gives back what is left, for the part's element.\n */\nexport function usePositioning<Props extends PositionerOptions>(\n positioning: Signal<Partial<PositionOptions>>,\n { side, align, sideOffset, alignOffset, collisionPadding, anchor, ...rest }: Props\n): Omit<Props, keyof PositionerOptions> {\n // Written while rendering, so the first placement (made when the element attaches, before\n // this component's effects) reads them. Nothing re-renders for it: the core compares.\n positioning.set(\n defined({ side, align, sideOffset, alignOffset, collisionPadding, anchor: anchorOf(anchor) })\n )\n return rest\n}\n\n/**\n * A text input whose text is the core's own (a combobox's, a number field's): its `value` is\n * given to React as the input's default. To React a `value` with no `onChange` is an input\n * that cannot be typed in; the core writes the text itself, as it changes.\n */\nexport function useOwnText(part: Part): Part {\n return useMemo(\n () => ({\n props: computed(() => {\n const { value, ...rest } = part.props.get()\n return { ...rest, defaultValue: value }\n }),\n attach: (element) => part.attach(element),\n }),\n [part]\n )\n}\n\nconst PortalContainer = createContext<HTMLElement | null | undefined>(undefined)\n\n/** What `PortalProvider` takes. */\nexport interface PortalProviderProps {\n /** Where the popups inside are drawn; the end of `<body>` while it is not given. */\n container?: HTMLElement | null | undefined\n children?: ReactNode\n}\n\n/**\n * Says where every popup inside it is drawn, the popups those open included: an element of\n * the page (a shadow root's host, a full-screen element, a frame) in place of `<body>`.\n */\nexport function PortalProvider({ container, children }: PortalProviderProps): ReactElement {\n return <PortalContainer.Provider value={container}>{children}</PortalContainer.Provider>\n}\n\n/** Draws no element of its own: its children at the end of `<body>`, or where a `PortalProvider` says. */\nexport interface PortalProps {\n children?: ReactNode\n}\n\n/** Its children in a container at the end of the page, once the page has hydrated. */\nexport function Portal({ children }: PortalProps): ReactElement | null {\n const container = useContext(PortalContainer)\n const [ready, setReady] = useState(false)\n useIsomorphicLayoutEffect(() => setReady(true), [])\n if (!ready) return null\n return createPortal(<div data-kirana-portal=\"\">{children}</div>, container ?? document.body)\n}\n"],"mappings":";;;;;;;AAoDA,MAAa,4BACX,OAAO,aAAa,cAAc,YAAY;;AAGhD,SAAgB,UAAa,QAA8B;CACzD,MAAM,YAAY,aAAa,aAAyB,OAAO,UAAU,QAAQ,GAAG,CAAC,MAAM,CAAC;CAC5F,MAAM,OAAO,kBAAkB,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC;CACtD,OAAO,qBAAqB,WAAW,MAAM,IAAI;AACnD;;;;;;AAOA,SAAgB,cACd,QACA,OACG;CACH,MAAM,YAAY,MAAM;CACxB,MAAM,OAAO;EAAE,GAAG;EAAO,IAAI,MAAM,MAAM;CAAU;CACnD,MAAM,SAAS,OAAO,IAAI;CAC1B,OAAO,UAAU;CACjB,MAAM,CAAC,SAAS,eAAe;EAE7B,MAAM,SAAS,CAAC;EAChB,KAAK,MAAM,OAAO,MAChB,OAAO,OACL,OAAO,KAAK,SAAS,cAChB,GAAG,SACD,OAAO,QAAQ,IAAI,GAAqD,GAAG,IAAI,IAClF,KAAK;EAEb,MAAM,SAAoB,OAAO,QAAa,SAAoC;EAClF,OAAO;GAAE;GAAQ,YAAY,OAAO,MAAM;EAAE;CAC9C,CAAC;CACD,gCAAgC;EAC9B,MAAM,SAAS,EAAE,GAAG,MAAM,OAAO,KAAK,EAAE;EACxC,KAAK,MAAM,OAAO,MAChB,IAAI,OAAO,KAAK,SAAS,YAAY,OAAO,OAAO,KAAK;EAE1D,MAAM,OAAO,IAAI,MAAW;CAC9B,CAAC;CACD,SAAS,MAAM,UAAU;CACzB,OAAO,MAAM;AACf;;;;;;;AAQA,SAAgB,SAAS,SAAwC;CAC/D,MAAM,CAAC,SAAS,gBAAgB;EAC9B,IAAI;EACJ,SAAS,KAAA;EACT,SAAS;CACX,EA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,MAAM,QAAQ,IAAI,QAAS,aAAa,OAAO,OAAQ;CAC5D,OAAO;AACT;;;;;AAMA,SAAgB,eACd,aACA,EAAE,MAAM,OAAO,YAAY,aAAa,kBAAkB,QAAQ,GAAG,QAC/B;CAGtC,YAAY,IACV,QAAQ;EAAE;EAAM;EAAO;EAAY;EAAa;EAAkB,QAAQ,SAAS,MAAM;CAAE,CAAC,CAC9F;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,WAAW,MAAkB;CAC3C,OAAO,eACE;EACL,OAAO,eAAe;GACpB,MAAM,EAAE,OAAO,GAAG,SAAS,KAAK,MAAM,IAAI;GAC1C,OAAO;IAAE,GAAG;IAAM,cAAc;GAAM;EACxC,CAAC;EACD,SAAS,YAAY,KAAK,OAAO,OAAO;CAC1C,IACA,CAAC,IAAI,CACP;AACF;AAEA,MAAM,kBAAkB,cAA8C,KAAA,CAAS;;;;;AAa/E,SAAgB,eAAe,EAAE,WAAW,YAA+C;CACzF,OAAO,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAAY;CAAmC,CAAA;AACzF;;AAQA,SAAgB,OAAO,EAAE,YAA8C;CACrE,MAAM,YAAY,WAAW,eAAe;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CACxC,gCAAgC,SAAS,IAAI,GAAG,CAAC,CAAC;CAClD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,oBAAC,OAAD;EAAK,sBAAmB;EAAI;CAAc,CAAA,GAAG,aAAa,SAAS,IAAI;AAC7F"}
1
+ {"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/react/src/runtime.tsx"],"sourcesContent":["import {\n composeProps,\n computed,\n defined,\n forElement,\n mergeProps,\n sameProps,\n signal,\n stateOf,\n untype,\n} from \"@kirana-ui/core\"\nimport type {\n Anchor,\n Direction,\n Part,\n PartEvent,\n PartProps,\n PartState,\n PositionOptions,\n ReadonlySignal,\n Signal,\n} from \"@kirana-ui/core\"\nimport {\n cloneElement,\n createContext,\n createElement,\n forwardRef,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\"\nimport type {\n ClassAttributes,\n ComponentPropsWithoutRef,\n HTMLAttributes,\n JSX,\n ReactElement,\n ReactNode,\n Ref,\n RefCallback,\n RefObject,\n SyntheticEvent,\n} from \"react\"\nimport { createPortal } from \"react-dom\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\n\nimport { REF_IS_A_PROP, give, refOf } from \"./element.ts\"\n\n/** A layout effect in the browser, an effect (which never runs) on a server. */\nexport const useIsomorphicLayoutEffect =\n typeof document === \"undefined\" ? useEffect : useLayoutEffect\n\n/** A core signal's value, re-rendering when it changes. */\nexport function useSignal<T>(source: ReadonlySignal<T>): T {\n const subscribe = useCallback((listener: () => void) => source.subscribe(listener), [source])\n const read = useCallback(() => source.peek(), [source])\n return useSyncExternalStore(subscribe, read, read)\n}\n\n/**\n * A component's controller, made once, following the props of each render. The props reach the\n * core after the render commits (a layout effect), never during it: another part that reads the\n * controller is another component, and React forbids updating it mid-render.\n */\nexport function useController<P extends object, C extends { mount(): () => void }>(\n create: (props: ReadonlySignal<P>) => C,\n // The maker says what the props are: read from the props too, a maker written in place\n // (`within(createX, around)`) had them come out as `object`.\n props: NoInfer<Omit<P, \"id\"> & { id?: string | undefined }>\n): C {\n const generated = useId()\n const next = { ...props, id: props.id ?? generated } as P\n const latest = useRef(next)\n latest.current = next\n const [state] = useState(() => {\n // The callbacks the core holds always call the latest render's.\n const stable = {} as Record<string, unknown>\n for (const key in next) {\n stable[key] =\n typeof next[key] === \"function\"\n ? (...args: unknown[]) =>\n (latest.current[key] as ((...args: unknown[]) => unknown) | undefined)?.(...args)\n : next[key]\n }\n const source: Signal<P> = signal(stable as P, sameProps as (a: P, b: P) => boolean)\n return { source, controller: create(source) }\n })\n useIsomorphicLayoutEffect(() => {\n const stable = { ...state.source.peek() } as Record<string, unknown>\n for (const key in next) {\n if (typeof next[key] !== \"function\") stable[key] = next[key]\n }\n state.source.set(stable as P)\n })\n useMount(state.controller)\n return state.controller\n}\n\n/**\n * Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an\n * effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:\n * a mount is not undone for that. The cleanup waits a moment, and a mount that comes back in\n * the meantime keeps what is running.\n */\nexport function useMount(mounted: { mount(): () => void }): void {\n const [state] = useState(() => ({\n of: mounted,\n unmount: undefined as (() => void) | undefined,\n leaving: false,\n }))\n useEffect(() => {\n if (state.of !== mounted) {\n state.unmount?.()\n state.unmount = undefined\n state.of = mounted\n }\n state.leaving = false\n state.unmount ??= mounted.mount()\n return () => {\n state.leaving = true\n queueMicrotask(() => {\n if (!state.leaving) return\n state.unmount?.()\n state.unmount = undefined\n })\n }\n }, [state, mounted])\n}\n\n/** A part's own options as a core signal that follows each render, after it commits. */\nexport function useOptions<T extends Record<string, unknown>>(options: T): ReadonlySignal<T> {\n const [source] = useState(() => signal(options, sameProps as (a: T, b: T) => boolean))\n useIsomorphicLayoutEffect(() => source.set(options))\n return source\n}\n\n// HTML's boolean attributes, which React takes as booleans: a part's `\"\"` means \"present\".\nconst BOOLEAN = new Set([\n \"hidden\",\n \"disabled\",\n \"inert\",\n \"required\",\n \"readonly\",\n \"multiple\",\n \"checked\",\n \"novalidate\",\n])\nconst RENAMED: Record<string, string> = {\n tabindex: \"tabIndex\",\n for: \"htmlFor\",\n readonly: \"readOnly\",\n novalidate: \"noValidate\",\n autocomplete: \"autoComplete\",\n inputmode: \"inputMode\",\n maxlength: \"maxLength\",\n contenteditable: \"contentEditable\",\n spellcheck: \"spellCheck\",\n autocapitalize: \"autoCapitalize\",\n enterkeyhint: \"enterKeyHint\",\n}\n\n/** A style as React takes it: `inset-inline-start` is `insetInlineStart`, `--x` stays as it is. */\nfunction reactStyle(style: Record<string, string>): Record<string, string> {\n const out: Record<string, string> = {}\n for (const name in style) {\n const key = name.startsWith(\"--\")\n ? name\n : name.replace(/-([a-z])/g, (_match, letter: string) => letter.toUpperCase())\n out[key] = style[name]!\n }\n return out\n}\n\nfunction toReact(props: PartProps, own: PartProps): Record<string, unknown> {\n const out: Record<string, unknown> = {}\n // A boolean the part has a key for is always given: the merge leaves out one that no layer\n // has a value for, and `checked` would then come and go.\n for (const key in own) {\n if (BOOLEAN.has(key) && !(key in props) && (key !== \"inert\" || REF_IS_A_PROP))\n out[RENAMED[key] ?? key] = false\n }\n for (const key in props) {\n const value = props[key]\n if (BOOLEAN.has(key)) {\n const name = RENAMED[key] ?? key\n // Always a boolean, never left out: an input whose `checked` comes and goes is, to React,\n // one that changes from controlled to not. But a part with nothing to say leaves what a\n // caller wrote under React's own name (`readOnly`).\n if (value !== undefined || !(name in out)) {\n const present = value === \"\" || value === true\n // React 19 knows `inert` as a boolean, and takes `\"\"` for false with a warning. Before,\n // it is an attribute React does not know: `true` is dropped with a warning, and `\"\"`\n // is written.\n out[name] = key === \"inert\" && !REF_IS_A_PROP ? (present ? \"\" : undefined) : present\n }\n } else if (key === \"style\" && value) out.style = reactStyle(value as Record<string, string>)\n else if (value !== undefined) out[RENAMED[key] ?? key] = value\n }\n return out\n}\n\n/** The elements a part is drawn as, by their tag: `\"button\"`, `\"div\"`, `\"svg\"`. */\nexport type PartTag = keyof JSX.IntrinsicElements\n\n/** The element a tag draws: an `HTMLButtonElement` for `\"button\"`. */\nexport type ElementOf<Tag extends PartTag> =\n JSX.IntrinsicElements[Tag] extends ClassAttributes<infer Drawn> ? Drawn : Element\n\nexport type { PartEvent }\n\n// A handler takes the event with its `preventKiranaHandler()`; anything else is as it was.\ntype Hearing<Prop> = Prop extends (event: infer Heard) => infer Answer\n ? Heard extends SyntheticEvent\n ? (event: PartEvent<Heard>) => Answer\n : Prop\n : Prop\n\n/**\n * The props a `render` function is handed, to spread on what it draws: the part's attributes,\n * its handlers and its ref, with the caller's under them. An attribute of one kind of element\n * (`href`, `type`) is among them unnamed, as `unknown`.\n */\nexport type RenderedProps = HTMLAttributes<HTMLElement> & {\n ref?: RefCallback<HTMLElement> | undefined\n} & Record<string, unknown>\n\n/**\n * What `render` takes: an element, drawn with the part's props merged over its own, or a\n * function given the part's props and its state. Unnamed, a state is any entries a `data-*`\n * attribute is written from: a part's own entry names its exactly.\n */\nexport type RenderProp<State = Record<string, string | boolean | null | undefined>> =\n | ReactElement<Record<string, unknown>>\n | ((props: RenderedProps, state: State) => ReactElement)\n\n/**\n * A part's props: its element's own (`Tag`'s attributes and handlers, a `ref` to that\n * element), `render`, and the part's own props (`Own`) in place of the element's of the same\n * name. `State` is what a `render` function is told of the part. A plain element of one's own\n * drawn through `useRender` names its state here (`PartComponentProps<\"span\", { variant:\n * string | null }>`); unnamed, it is any entries of `string | boolean | null | undefined`.\n */\nexport type PartComponentProps<\n Tag extends PartTag = \"div\",\n State = Record<string, string | boolean | null | undefined>,\n Own = unknown,\n> = {\n [Name in keyof ComponentPropsWithoutRef<Tag> as Name extends keyof Own ? never : Name]: Hearing<\n ComponentPropsWithoutRef<Tag>[Name]\n >\n} & Own & {\n /**\n * Renders the part as another element or component. An element's own props lie over the\n * props handed to the part, and the part's own (its role, its state, its handlers) over\n * both; a function is given the part's props and its state (`open`, `side` …, read from\n * its `data-*` attributes).\n */\n render?: RenderProp<State> | undefined\n ref?: Ref<ElementOf<Tag>> | undefined\n }\n\n// A part's props as `usePart` reads them, whatever element they are typed for.\ninterface Handed {\n render?: RenderProp<never> | undefined\n ref?: Ref<never> | undefined\n [attribute: string]: unknown\n}\n\n/** A part's DOM work on the element it is on. */\ninterface Attached {\n element: HTMLElement\n part: Part\n detach(): void\n leaving: boolean\n}\n\n/**\n * Renders a part: its element (or the caller's `render`), and the part's DOM work attached to\n * the element. Three layers of props, lowest first: what was handed to the part, the `render`\n * element's own, the part's. A higher layer wins an attribute; classes join; styles are merged\n * property by property; every handler of an event runs, lowest first, and\n * `event.preventKiranaHandler()` in a caller's stops the part's. The `render` element's own\n * children are drawn when it has any, and both its ref and the part's `ref` get the element.\n * `hold` is for a part that keeps something of its own in its element (a hidden input): it is\n * given the content and returns what the element holds, whoever drew the element.\n */\nexport function usePart<Tag extends PartTag, State = PartState>(\n part: Part,\n tag: Tag,\n props: PartComponentProps<Tag, State>,\n state?: State,\n hold?: (content: ReactNode) => ReactNode\n): ReactElement {\n const { render: asRender, ref: asRef, ...caller } = props as Handed\n const render = asRender as RenderProp<State> | undefined\n const ref = asRef as Ref<HTMLElement> | undefined\n const own = useSignal(part.props)\n const asked = isValidElement(render) ? render : undefined\n const theirs = asked ? refOf(asked) : undefined\n const held = useRef<Attached | undefined>(undefined)\n const attach = useCallback(\n (element: HTMLElement | null) => {\n const now = held.current\n if (!element) {\n // React takes a ref away and hands it straight back when the caller's `ref` is a new\n // function, and in StrictMode when the element is first drawn. The part's DOM work is\n // not undone for that (a popup would close its layer and give focus back): it is\n // undone a moment later, if the element has not come back.\n if (now) {\n now.leaving = true\n queueMicrotask(() => {\n if (!now.leaving) return\n now.detach()\n if (held.current === now) held.current = undefined\n })\n }\n } else if (now && now.element === element && now.part === part) {\n now.leaving = false\n } else {\n if (now) {\n now.leaving = false\n now.detach()\n }\n untype(element)\n held.current = { element, part, detach: part.attach(element), leaving: false }\n }\n give(ref, element)\n give(theirs, element)\n },\n [part, ref, theirs]\n )\n let under: PartProps = caller\n if (asked) {\n // React 19 keeps an element's ref among its props: it is given the element above. Before,\n // the props have none, and reading it there warns.\n const { ref: _ref, ...element } = REF_IS_A_PROP ? asked.props : { ...asked.props }\n under = composeProps(caller, element)\n }\n // The element's tag, where it is known before it is drawn: a function, or a component given\n // as `render`, draws one of its own choosing.\n const drawnAs = asked\n ? typeof asked.type === \"string\"\n ? asked.type\n : undefined\n : typeof render === \"function\"\n ? undefined\n : tag\n const placed = forElement(own, under, drawnAs)\n const drawn: Record<string, unknown> = {\n ...toReact(mergeProps(under, placed), placed),\n ref: attach,\n }\n if (hold) drawn.children = hold(drawn.children as ReactNode)\n if (asked) return cloneElement(asked, drawn)\n if (typeof render === \"function\") return render(drawn, state ?? (stateOf(own) as State))\n return createElement(tag, drawn)\n}\n\nconst forwarded = new WeakMap<object, unknown>()\n\n/**\n * A component that is handed its caller's `ref` on every React the package takes, under the\n * name DevTools shows it by. React 19 gives a component its `ref` among its props, which is\n * where a part reads it; before, only a `forwardRef` component was given one, so there the\n * component is drawn by one that puts the ref back among the props. Its type is its own\n * either way, so one that is generic stays generic. One that already has a name keeps it.\n */\nexport function component<Drawn extends (props: never) => ReactNode>(\n name: string,\n draw: Drawn\n): Drawn {\n const named = draw as Drawn & { displayName?: string }\n if (REF_IS_A_PROP) {\n named.displayName ??= name\n return draw\n }\n let made = forwarded.get(draw)\n if (!made) {\n const drawing = draw as unknown as (props: object) => ReactElement | null\n const forwards = forwardRef<unknown, object>((props, ref) =>\n drawing(ref === null ? props : { ...props, ref })\n )\n forwards.displayName = name\n forwarded.set(draw, (made = forwards))\n }\n return made as Drawn\n}\n\n/**\n * A component's parts, each one a `component` named `Name.Part`. A part that is another\n * component's (a date picker's trigger is a popover's) is the same component there and here.\n */\nexport function parts<const Parts extends Record<string, unknown>>(\n name: string,\n all: Parts\n): Parts {\n const made: Record<string, unknown> = {}\n for (const key in all) {\n const part: unknown = all[key]\n made[key] =\n typeof part === \"function\"\n ? component(`${name}.${key}`, part as (props: never) => ReactNode)\n : part\n }\n return made as Parts\n}\n\n/**\n * A part's element as a component of its own, for a part that is not always in the page: the\n * part decides, and draws this when it is. It takes the part's props, with the part it is the\n * element `of`, its tag, and what the element holds of the part's own (`hold`, as `usePart`'s).\n */\nexport const PartElement = /* @__PURE__ */ component(\n \"PartElement\",\n function PartElement<Tag extends PartTag, State = PartState>({\n of,\n tag,\n hold,\n ...props\n }: PartComponentProps<Tag, State> & {\n of: Part\n tag: Tag\n hold?: ((content: ReactNode) => ReactNode) | undefined\n }): ReactElement {\n return usePart(of, tag, props as unknown as PartComponentProps<Tag, State>, undefined, hold)\n }\n)\n\n/** A positioner's own props: where its popup goes, and what it is placed against. */\nexport type PositionerOptions = Partial<Omit<PositionOptions, \"anchor\">> & {\n /**\n * What the popup is placed against, when that is not its trigger: an element, a ref to one,\n * a place in the viewport (an object with `getBoundingClientRect`), or a function that gives\n * one. It may change while the popup is open: the popup follows.\n */\n anchor?: Anchor | RefObject<Element | null> | (() => Anchor | null | undefined) | null | undefined\n}\n\n/** A positioner's props: where its popup goes and what it is placed against, and its element's. */\nexport type PositionerProps<State = PartState> = PartComponentProps<\"div\", State, PositionerOptions>\n\n// A ref's reader, the same function for the same ref: a render that changes nothing asks for\n// no new placement.\nconst readers = new WeakMap<object, () => Element | null>()\n\nfunction anchorOf(anchor: PositionerOptions[\"anchor\"]): PositionOptions[\"anchor\"] {\n if (!anchor || typeof anchor === \"function\") return anchor\n if (!(\"current\" in anchor) || \"getBoundingClientRect\" in anchor) return anchor as Anchor\n let read = readers.get(anchor)\n if (!read) readers.set(anchor, (read = () => anchor.current))\n return read\n}\n\n/**\n * A positioner's own props, written where its placement reads them: the one place they are\n * named. Gives back what is left, for the part's element.\n */\nexport function usePositioning<Props extends PositionerOptions>(\n positioning: Signal<Partial<PositionOptions>>,\n {\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n collisionBoundary,\n collisionAvoidance,\n sticky,\n arrowPadding,\n positionMethod,\n anchor,\n ...rest\n }: Props\n): Omit<Props, keyof PositionerOptions> {\n // Written while rendering, so the first placement (made when the element attaches, before\n // this component's effects) reads them. Nothing re-renders for it: the core compares.\n positioning.set(\n defined({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n collisionBoundary,\n collisionAvoidance,\n sticky,\n arrowPadding,\n positionMethod,\n anchor: anchorOf(anchor),\n })\n )\n return rest\n}\n\n/**\n * A text input whose text is the core's own (a combobox's, a number field's): its `value` is\n * given to React as the input's default. To React a `value` with no `onChange` is an input\n * that cannot be typed in; the core writes the text itself, as it changes.\n */\nexport function useOwnText(part: Part): Part {\n return useMemo(\n () => ({\n props: computed(() => {\n const { value, ...rest } = part.props.get()\n return { ...rest, defaultValue: value }\n }),\n attach: (element) => part.attach(element),\n }),\n [part]\n )\n}\n\nconst PortalContainer = createContext<HTMLElement | null | undefined>(undefined)\n\n/** What `PortalProvider` takes. */\nexport interface PortalProviderProps {\n /** Where the popups inside are drawn; the end of `<body>` while it is not given. */\n container?: HTMLElement | null | undefined\n children?: ReactNode\n}\n\n/**\n * Says where every popup inside it is drawn, the popups those open included: an element of\n * the page (a shadow root's host, a full-screen element, a frame) in place of `<body>`.\n */\nexport function PortalProvider({ container, children }: PortalProviderProps): ReactElement {\n return <PortalContainer.Provider value={container}>{children}</PortalContainer.Provider>\n}\n\n/** Draws no element of its own: its children at the end of `<body>`, or where a `PortalProvider` says. */\nexport interface PortalProps {\n children?: ReactNode\n}\n\n/** Its children in a container at the end of the page, once the page has hydrated. */\nexport function Portal({ children }: PortalProps): ReactElement | null {\n const container = useContext(PortalContainer)\n const [ready, setReady] = useState(false)\n useIsomorphicLayoutEffect(() => setReady(true), [])\n if (!ready) return null\n return createPortal(<div data-kirana-portal=\"\">{children}</div>, container ?? document.body)\n}\n\n/**\n * The reading direction a `DirectionProvider` around this component states, as the signal a\n * controller takes (`within(createX, { direction })`); `undefined` outside one, where the\n * controller reads the direction its element is laid out in. For a component of your own: the\n * library's parts read the same.\n */\nexport function useDirectionAround(): ReadonlySignal<Direction> | undefined {\n return useContext(DirectionContext) ?? undefined\n}\n"],"mappings":";;;;;;;;AAyDA,MAAa,4BACX,OAAO,aAAa,cAAc,YAAY;;AAGhD,SAAgB,UAAa,QAA8B;CACzD,MAAM,YAAY,aAAa,aAAyB,OAAO,UAAU,QAAQ,GAAG,CAAC,MAAM,CAAC;CAC5F,MAAM,OAAO,kBAAkB,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC;CACtD,OAAO,qBAAqB,WAAW,MAAM,IAAI;AACnD;;;;;;AAOA,SAAgB,cACd,QAGA,OACG;CACH,MAAM,YAAY,MAAM;CACxB,MAAM,OAAO;EAAE,GAAG;E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EACA;EACA;EACA;EACA;EACA;EACA,QAAQ,SAAS,MAAM;CACzB,CAAC,CACH;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,WAAW,MAAkB;CAC3C,OAAO,eACE;EACL,OAAO,eAAe;GACpB,MAAM,EAAE,OAAO,GAAG,SAAS,KAAK,MAAM,IAAI;GAC1C,OAAO;IAAE,GAAG;IAAM,cAAc;GAAM;EACxC,CAAC;EACD,SAAS,YAAY,KAAK,OAAO,OAAO;CAC1C,IACA,CAAC,IAAI,CACP;AACF;AAEA,MAAM,kBAAkB,cAA8C,KAAA,CAAS;;;;;AAa/E,SAAgB,eAAe,EAAE,WAAW,YAA+C;CACzF,OAAO,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAAY;CAAmC,CAAA;AACzF;;AAQA,SAAgB,OAAO,EAAE,YAA8C;CACrE,MAAM,YAAY,WAAW,eAAe;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CACxC,gCAAgC,SAAS,IAAI,GAAG,CAAC,CAAC;CAClD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,oBAAC,OAAD;EAAK,sBAAmB;EAAI;CAAc,CAAA,GAAG,aAAa,SAAS,IAAI;AAC7F;;;;;;;AAQA,SAAgB,qBAA4D;CAC1E,OAAO,WAAW,gBAAgB,KAAK,KAAA;AACzC"}
@@ -1,6 +1,6 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
- import { Orientation, StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement } from "react";
3
+ import { Orientation, StateOf } from "@kirana-ui/core";
4
4
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
5
5
  type Parts = Vocabulary["scrollArea"];
6
6
  export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>>;
@@ -1,7 +1,7 @@
1
1
  import { DirectionContext } from "./direction-context.js";
2
2
  import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
3
- import { within } from "@kirana-ui/core";
4
3
  import { createContext, useContext } from "react";
4
+ import { within } from "@kirana-ui/core";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { createScrollArea } from "@kirana-ui/core/scroll-area";
7
7
  // src/scroll-area.tsx
package/src/select.d.ts CHANGED
@@ -1,15 +1,20 @@
1
1
  import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
2
- import { StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement, ReactNode } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
4
  import { SelectProps } from "@kirana-ui/core/select";
5
5
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
6
  type Parts = Vocabulary["select"];
7
- /** `Value` is what tells an item from the others: the type of `value`, and of `values`' entries. */
8
- export type RootProps<Value = unknown> = Omit<SelectProps<Value>, "id"> & {
7
+ /**
8
+ * `Value` is what tells an item from the others. `Multiple` is inferred from `multiple`: with
9
+ * `multiple`, `value`, `defaultValue` and `onValueChange` hold a list of them.
10
+ */
11
+ export type RootProps<Value = unknown, Multiple extends boolean | undefined = false> = Omit<SelectProps<Value, Multiple>, "id" | "multiple"> & {
12
+ /** Several values: `value`, `defaultValue` and `onValueChange` then hold a list. Read once. */
13
+ multiple?: Multiple | undefined;
9
14
  id?: string;
10
15
  children?: ReactNode;
11
16
  };
12
- declare function Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement;
17
+ declare function Root<Value = unknown, Multiple extends boolean | undefined = false>({ children, ...props }: RootProps<Value, Multiple>): ReactElement;
13
18
  export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
14
19
  declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
15
20
  export type ValueProps<Chosen = unknown> = PartComponentProps<"span", StateOf<Parts["value"]>, {
@@ -26,14 +31,19 @@ declare function Value<Chosen = unknown>({ placeholder, children, ...props }: Va
26
31
  declare function Portal({ children }: PortalProps): ReactElement | null;
27
32
  export type PositionerProps = PartComponentProps<"div", StateOf<Parts["positioner"]>, PositionerOptions & {
28
33
  /**
29
- * The list opens over its trigger, the chosen item's text on the trigger's own, where
30
- * there is room and unless a finger opened it.
34
+ * The list opens over its trigger, the chosen item's text on the trigger's own, where there is
35
+ * room and unless a finger opened it. While it lies there the page's scroll is held (its
36
+ * scrollbar's room kept), and a scroll of a box around the trigger closes the list
37
+ * (`"ancestor-scroll"`), as a change of the window's size does (`"window-resize"`).
31
38
  */
32
39
  alignItemWithTrigger?: boolean;
33
40
  }>;
34
41
  declare function Positioner({ alignItemWithTrigger, ...props }: PositionerProps): ReactElement;
35
42
  export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
43
+ export type BackdropProps = PartComponentProps<"div", StateOf<Parts["backdrop"]>>;
36
44
  declare const Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
45
+ /** What lies over the page behind the list: a sheet's (`presentation`) is modal. */
46
+ declare const Backdrop: (props: BackdropProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
37
47
  export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, {
38
48
  id?: string;
39
49
  }>;
@@ -78,6 +88,7 @@ export declare const Select: {
78
88
  readonly Trigger: typeof Trigger;
79
89
  readonly Value: typeof Value;
80
90
  readonly Portal: typeof Portal;
91
+ readonly Backdrop: typeof Backdrop;
81
92
  readonly Positioner: typeof Positioner;
82
93
  readonly Popup: typeof Popup;
83
94
  readonly List: typeof List;
package/src/select.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FieldContext } from "./field-context.js";
2
2
  import { PartElement, Portal as Portal$1, parts, useController, useMount, useOptions, usePart, usePositioning, useSignal } from "./runtime.js";
3
- import { defined, within } from "@kirana-ui/core";
4
3
  import { createContext, useContext, useId, useMemo } from "react";
4
+ import { defined, within } from "@kirana-ui/core";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
6
  import { createSelect } from "@kirana-ui/core/select";
7
7
  // src/select.tsx
@@ -45,6 +45,8 @@ function Positioner({ alignItemWithTrigger, ...props }) {
45
45
  return usePart(controller.positioner, "div", usePositioning(controller.positioning, props));
46
46
  }
47
47
  const Popup = (props) => usePart(useSelect("Popup").popup, "div", props);
48
+ /** What lies over the page behind the list: a sheet's (`presentation`) is modal. */
49
+ const Backdrop = (props) => usePart(useSelect("Backdrop").backdrop, "div", props);
48
50
  const GroupContext = createContext(null);
49
51
  /** Items that belong together, named by their `<Select.GroupLabel>`. */
50
52
  function Group({ id, ...props }) {
@@ -124,9 +126,9 @@ function ItemText(props) {
124
126
  function ItemIndicator({ keepMounted, ...props }) {
125
127
  const controller = useSelect("ItemIndicator");
126
128
  const value = useContext(ItemContext);
127
- const selected = useSignal(controller.selected(value));
128
129
  const part = useMemo(() => controller.itemIndicator(value), [controller, value]);
129
- return selected || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
130
+ useMount(part);
131
+ return useSignal(part.mounted) || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
130
132
  of: part,
131
133
  tag: "span",
132
134
  ...props
@@ -137,6 +139,7 @@ const Select = /* @__PURE__ */ parts("Select", {
137
139
  Trigger,
138
140
  Value,
139
141
  Portal,
142
+ Backdrop,
140
143
  Positioner,
141
144
  Popup,
142
145
  List,
package/src/select.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"select.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/select.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSelect } from \"@kirana-ui/core/select\"\nimport type { Select as Controller, SelectGroup, SelectProps } from \"@kirana-ui/core/select\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n usePart,\n usePositioning,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"select\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useSelect(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Select.${part}> must be inside <Select.Root>`)\n return controller\n}\n\n/** `Value` is what tells an item from the others: the type of `value`, and of `values`' entries. */\nexport type RootProps<Value = unknown> = Omit<SelectProps<Value>, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller: Controller = useController(within(createSelect<Value>, { field }), props)\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nconst HiddenInput = () => usePart(useSelect(\"Root\").input, \"input\", {})\n\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\n\nconst Trigger = (props: TriggerProps) => usePart(useSelect(\"Trigger\").trigger, \"button\", props)\n\nexport type ValueProps<Chosen = unknown> = PartComponentProps<\n \"span\",\n StateOf<Parts[\"value\"]>,\n {\n /** Shown while nothing is chosen. */\n placeholder?: ReactNode\n /**\n * What to show in place of the label. A function is given the value and its label (`null`\n * and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in\n * the items' order. Its first parameter's type says which: `(values: string[], labels) => …`.\n */\n children?:\n | ReactNode\n | ((\n value: Chosen,\n label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined\n ) => ReactNode)\n }\n>\n\nfunction Value<Chosen = unknown>({\n placeholder,\n children,\n ...props\n}: ValueProps<Chosen>): ReactElement {\n const controller = useSelect(\"Value\")\n const shown = useSignal(controller.shown)\n let drawn: ReactNode\n if (typeof children === \"function\") {\n const draw = children as (value: unknown, label: unknown) => ReactNode\n drawn = controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label)\n } else drawn = children ?? shown.label ?? placeholder\n return usePart(controller.valuePart, \"span\", { ...props, children: drawn })\n}\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useSelect(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions & {\n /**\n * The list opens over its trigger, the chosen item's text on the trigger's own, where\n * there is room and unless a finger opened it.\n */\n alignItemWithTrigger?: boolean\n }\n>\n\nfunction Positioner({ alignItemWithTrigger, ...props }: PositionerProps): ReactElement {\n const controller = useSelect(\"Positioner\")\n controller.alignItemWithTrigger.set(Boolean(alignItemWithTrigger))\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\n\nconst Popup = (props: PopupProps) => usePart(useSelect(\"Popup\").popup, \"div\", props)\nconst GroupContext = createContext<SelectGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `<Select.GroupLabel>`. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useSelect(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupLabelProps = PartComponentProps<\"div\", StateOf<Parts[\"groupLabel\"]>>\n\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: GroupLabelProps): ReactElement {\n const lone = useSelect(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\n/** A line between groups. */\nconst Separator = (props: SeparatorProps) => usePart(useSelect(\"Separator\").separator, \"div\", props)\n\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\n/** The items' own box inside the popup, when the popup also holds scroll arrows. */\nconst List = (props: ListProps) => usePart(useSelect(\"List\").list, \"div\", props)\n\nexport type ScrollUpArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"scrollUpArrow\"]>>\nexport type ScrollDownArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"scrollDownArrow\"]>>\n\n/** The arrow at one end of the list, and whether it is in the page: while there is more that way. */\nfunction useScrollArrow(name: string, direction: \"up\" | \"down\") {\n const controller = useSelect(name)\n const arrow = useMemo(() => controller.scrollArrow(direction), [controller, direction])\n useMount(arrow)\n return { part: arrow.part, mounted: useSignal(arrow.mounted) }\n}\n\n/** In the page while there is more of the list above: it scrolls it while the pointer moves over it. */\nfunction ScrollUpArrow(props: ScrollUpArrowProps): ReactElement | null {\n const { part, mounted } = useScrollArrow(\"ScrollUpArrow\", \"up\")\n return mounted ? <PartElement of={part} tag=\"div\" {...props} /> : null\n}\n\n/** In the page while there is more of the list below. */\nfunction ScrollDownArrow(props: ScrollDownArrowProps): ReactElement | null {\n const { part, mounted } = useScrollArrow(\"ScrollDownArrow\", \"down\")\n return mounted ? <PartElement of={part} tag=\"div\" {...props} /> : null\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the select's value is while this item is chosen. */\n value: unknown\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What typeahead matches and the trigger shows; the item's text when left out. */\n label?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, index, ...props }: ItemProps): ReactElement {\n const controller = useSelect(\"Item\")\n const options = useOptions({ disabled, label, index })\n const part = useMemo(\n () => controller.item(value, () => defined(options.get())),\n [controller, value, options]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemTextProps = PartComponentProps<\"span\", StateOf<Parts[\"itemText\"]>>\n\nfunction ItemText(props: ItemTextProps): ReactElement {\n const controller = useSelect(\"ItemText\")\n const value = useContext(ItemContext)\n const part = useMemo(() => controller.itemText(value), [controller, value])\n return usePart(part, \"span\", props)\n}\n\nexport type ItemIndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"itemIndicator\"]>,\n {\n /** Keeps the mark in the page while its item is not chosen. */\n keepMounted?: boolean\n }\n>\n\n/** In the page while its item is the chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useSelect(\"ItemIndicator\")\n const value = useContext(ItemContext)\n const selected = useSignal(controller.selected(value))\n const part = useMemo(() => controller.itemIndicator(value), [controller, value])\n return selected || keepMounted ? <PartElement of={part} tag=\"span\" {...props} /> : null\n}\n\nexport const Select = /* @__PURE__ */ parts(\"Select\", {\n Root,\n Trigger,\n Value,\n Portal,\n Positioner,\n Popup,\n List,\n ScrollUpArrow,\n ScrollDownArrow,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemText,\n ItemIndicator,\n})\n"],"mappings":";;;;;;;AA0BA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAQA,SAAS,KAAsB,EAAE,UAAU,GAAG,SAAyC;CACrF,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAyB,cAAc,OAAO,cAAqB,EAAE,MAAM,CAAC,GAAG,KAAK;CAC1F,MAAM,QAAQ,UAAU,WAAW,KAAK;CACxC,OACE,qBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAzB,UAAA,CACG,UACA,QAAQ,oBAAC,aAAD,CAAc,CAAA,IAA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AAQ,MAAM,OAAO,KAAK;CAAwB,CAAA;AAChG;AAIA,SAAS,SAAS,OAAoC;CACpD,MAAM,aAAa,UAAU,UAAU;CACvC,MAAM,QAAQ,WAAW,WAAW;CACpC,MAAM,OAAO,cAAc,WAAW,SAAS,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAC1E,OAAO,QAAQ,MAAM,QAAQ,KAAK;AACpC;;AAYA,SAAS,cAAc,EAAE,aAAa,GAAG,SAAkD;CACzF,MAAM,aAAa,UAAU,eAAe;CAC5C,MAAM,QAAQ,WAAW,WAAW;CACpC,MAAM,WAAW,UAAU,WAAW,SAAS,KAAK,CAAC;CACrD,MAAM,OAAO,cAAc,WAAW,cAAc,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAC/E,OAAO,YAAY,cAAc,oBAAC,aAAD;EAAa,IAAI;EAAM,KAAI;EAAO,GAAI;CAAQ,CAAA,IAAI;AACrF;AAEA,MAAa,SAAyB,sBAAM,UAAU;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
1
+ {"version":3,"file":"select.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/select.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSelect } from \"@kirana-ui/core/select\"\nimport type { Select as Controller, SelectGroup, SelectProps } from \"@kirana-ui/core/select\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n usePart,\n usePositioning,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"select\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useSelect(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Select.${part}> must be inside <Select.Root>`)\n return controller\n}\n\n/**\n * `Value` is what tells an item from the others. `Multiple` is inferred from `multiple`: with\n * `multiple`, `value`, `defaultValue` and `onValueChange` hold a list of them.\n */\nexport type RootProps<Value = unknown, Multiple extends boolean | undefined = false> = Omit<\n SelectProps<Value, Multiple>,\n \"id\" | \"multiple\"\n> & {\n /** Several values: `value`, `defaultValue` and `onValueChange` then hold a list. Read once. */\n multiple?: Multiple | undefined\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value = unknown, Multiple extends boolean | undefined = false>({\n children,\n ...props\n}: RootProps<Value, Multiple>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller: Controller = useController(\n within(createSelect<Value, Multiple>, { field }),\n props\n )\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nconst HiddenInput = () => usePart(useSelect(\"Root\").input, \"input\", {})\n\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\n\nconst Trigger = (props: TriggerProps) => usePart(useSelect(\"Trigger\").trigger, \"button\", props)\n\nexport type ValueProps<Chosen = unknown> = PartComponentProps<\n \"span\",\n StateOf<Parts[\"value\"]>,\n {\n /** Shown while nothing is chosen. */\n placeholder?: ReactNode\n /**\n * What to show in place of the label. A function is given the value and its label (`null`\n * and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in\n * the items' order. Its first parameter's type says which: `(values: string[], labels) => …`.\n */\n children?:\n | ReactNode\n | ((\n value: Chosen,\n label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined\n ) => ReactNode)\n }\n>\n\nfunction Value<Chosen = unknown>({\n placeholder,\n children,\n ...props\n}: ValueProps<Chosen>): ReactElement {\n const controller = useSelect(\"Value\")\n const shown = useSignal(controller.shown)\n let drawn: ReactNode\n if (typeof children === \"function\") {\n const draw = children as (value: unknown, label: unknown) => ReactNode\n drawn = controller.multiple ? draw(shown.values, shown.labels) : draw(shown.value, shown.label)\n } else drawn = children ?? shown.label ?? placeholder\n return usePart(controller.valuePart, \"span\", { ...props, children: drawn })\n}\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useSelect(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions & {\n /**\n * The list opens over its trigger, the chosen item's text on the trigger's own, where there is\n * room and unless a finger opened it. While it lies there the page's scroll is held (its\n * scrollbar's room kept), and a scroll of a box around the trigger closes the list\n * (`\"ancestor-scroll\"`), as a change of the window's size does (`\"window-resize\"`).\n */\n alignItemWithTrigger?: boolean\n }\n>\n\nfunction Positioner({ alignItemWithTrigger, ...props }: PositionerProps): ReactElement {\n const controller = useSelect(\"Positioner\")\n controller.alignItemWithTrigger.set(Boolean(alignItemWithTrigger))\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type BackdropProps = PartComponentProps<\"div\", StateOf<Parts[\"backdrop\"]>>\n\nconst Popup = (props: PopupProps) => usePart(useSelect(\"Popup\").popup, \"div\", props)\n/** What lies over the page behind the list: a sheet's (`presentation`) is modal. */\nconst Backdrop = (props: BackdropProps) => usePart(useSelect(\"Backdrop\").backdrop, \"div\", props)\nconst GroupContext = createContext<SelectGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `<Select.GroupLabel>`. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useSelect(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupLabelProps = PartComponentProps<\"div\", StateOf<Parts[\"groupLabel\"]>>\n\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: GroupLabelProps): ReactElement {\n const lone = useSelect(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\n/** A line between groups. */\nconst Separator = (props: SeparatorProps) => usePart(useSelect(\"Separator\").separator, \"div\", props)\n\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\n/** The items' own box inside the popup, when the popup also holds scroll arrows. */\nconst List = (props: ListProps) => usePart(useSelect(\"List\").list, \"div\", props)\n\nexport type ScrollUpArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"scrollUpArrow\"]>>\nexport type ScrollDownArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"scrollDownArrow\"]>>\n\n/** The arrow at one end of the list, and whether it is in the page: while there is more that way. */\nfunction useScrollArrow(name: string, direction: \"up\" | \"down\") {\n const controller = useSelect(name)\n const arrow = useMemo(() => controller.scrollArrow(direction), [controller, direction])\n useMount(arrow)\n return { part: arrow.part, mounted: useSignal(arrow.mounted) }\n}\n\n/** In the page while there is more of the list above: it scrolls it while the pointer moves over it. */\nfunction ScrollUpArrow(props: ScrollUpArrowProps): ReactElement | null {\n const { part, mounted } = useScrollArrow(\"ScrollUpArrow\", \"up\")\n return mounted ? <PartElement of={part} tag=\"div\" {...props} /> : null\n}\n\n/** In the page while there is more of the list below. */\nfunction ScrollDownArrow(props: ScrollDownArrowProps): ReactElement | null {\n const { part, mounted } = useScrollArrow(\"ScrollDownArrow\", \"down\")\n return mounted ? <PartElement of={part} tag=\"div\" {...props} /> : null\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the select's value is while this item is chosen. */\n value: unknown\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What typeahead matches and the trigger shows; the item's text when left out. */\n label?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, index, ...props }: ItemProps): ReactElement {\n const controller = useSelect(\"Item\")\n const options = useOptions({ disabled, label, index })\n const part = useMemo(\n () => controller.item(value, () => defined(options.get())),\n [controller, value, options]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemTextProps = PartComponentProps<\"span\", StateOf<Parts[\"itemText\"]>>\n\nfunction ItemText(props: ItemTextProps): ReactElement {\n const controller = useSelect(\"ItemText\")\n const value = useContext(ItemContext)\n const part = useMemo(() => controller.itemText(value), [controller, value])\n return usePart(part, \"span\", props)\n}\n\nexport type ItemIndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"itemIndicator\"]>,\n {\n /** Keeps the mark in the page while its item is not chosen. */\n keepMounted?: boolean\n }\n>\n\n/** In the page while its item is the chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useSelect(\"ItemIndicator\")\n const value = useContext(ItemContext)\n const part = useMemo(() => controller.itemIndicator(value), [controller, value])\n // In the page while chosen, and through its exit.\n useMount(part)\n const mounted = useSignal(part.mounted)\n return mounted || keepMounted ? <PartElement of={part} tag=\"span\" {...props} /> : null\n}\n\nexport const Select = /* @__PURE__ */ parts(\"Select\", {\n Root,\n Trigger,\n Value,\n Portal,\n Backdrop,\n Positioner,\n Popup,\n List,\n ScrollUpArrow,\n ScrollDownArrow,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemText,\n ItemIndicator,\n})\n"],"mappings":";;;;;;;AA0BA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,UAAU,MAA0B;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StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
4
  import { SeparatorProps as SeparatorProps$1 } from "@kirana-ui/core/separator";
5
5
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
6
  export type SeparatorProps = PartComponentProps<"div", StateOf<Vocabulary["separator"]["root"]>, SeparatorProps$1>;
package/src/slider.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
- import { StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement, ReactNode } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
4
  import { SliderProps, SliderValue } from "@kirana-ui/core/slider";
5
5
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
6
  type Parts = Vocabulary["slider"];
@@ -11,7 +11,7 @@ type Parts = Vocabulary["slider"];
11
11
  export type RootProps<Value extends SliderValue = SliderValue> = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<SliderProps<Value>, "id"> & {
12
12
  id?: string;
13
13
  }>;
14
- declare function Root<Value extends SliderValue = number>({ value, defaultValue, onValueChange, onValueCommitted, min, max, step, largeStep, minStepsBetweenValues, thumbAlignment, orientation, disabled, name, form, format, locale, getAriaValueText, id, ...rest }: RootProps<Value>): ReactElement;
14
+ declare function Root<Value extends SliderValue = number>({ value, defaultValue, onValueChange, onValueCommitted, min, max, step, largeStep, minStepsBetweenValues, thumbAlignment, orientation, disabled, readOnly, name, form, format, locale, getAriaValueText, id, ...rest }: RootProps<Value>): ReactElement;
15
15
  export type ControlProps = PartComponentProps<"div", StateOf<Parts["control"]>>;
16
16
  export type TrackProps = PartComponentProps<"div", StateOf<Parts["track"]>>;
17
17
  export type IndicatorProps = PartComponentProps<"div", StateOf<Parts["indicator"]>>;
package/src/slider.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { DirectionContext } from "./direction-context.js";
2
2
  import { FieldContext } from "./field-context.js";
3
3
  import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
4
- import { within } from "@kirana-ui/core";
5
4
  import { createContext, useContext, useId } from "react";
5
+ import { within } from "@kirana-ui/core";
6
6
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
7
  import { createSlider } from "@kirana-ui/core/slider";
8
8
  // src/slider.tsx
@@ -12,7 +12,7 @@ function useSlider(part) {
12
12
  if (!controller) throw new Error(`<Slider.${part}> must be inside <Slider.Root>`);
13
13
  return controller;
14
14
  }
15
- function Root({ value, defaultValue, onValueChange, onValueCommitted, min, max, step, largeStep, minStepsBetweenValues, thumbAlignment, orientation, disabled, name, form, format, locale, getAriaValueText, id, ...rest }) {
15
+ function Root({ value, defaultValue, onValueChange, onValueCommitted, min, max, step, largeStep, minStepsBetweenValues, thumbAlignment, orientation, disabled, readOnly, name, form, format, locale, getAriaValueText, id, ...rest }) {
16
16
  const field = useContext(FieldContext) ?? void 0;
17
17
  const direction = useContext(DirectionContext) ?? void 0;
18
18
  const create = within(createSlider, {
@@ -32,6 +32,7 @@ function Root({ value, defaultValue, onValueChange, onValueCommitted, min, max,
32
32
  thumbAlignment,
33
33
  orientation,
34
34
  disabled,
35
+ readOnly,
35
36
  name,
36
37
  form,
37
38
  format,
package/src/slider.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"slider.js","names":[],"sources":["../../../../packages/react/src/slider.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSlider } from \"@kirana-ui/core/slider\"\nimport type { Slider as Controller, SliderProps, SliderValue } from \"@kirana-ui/core/slider\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"slider\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useSlider(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Slider.${part}> must be inside <Slider.Root>`)\n return controller\n}\n\n/**\n * `Value` is what the slider is given, `value` or `defaultValue`: a number for one thumb, a\n * list for a range. What `onValueChange` and `onValueCommitted` are told is the same kind.\n */\nexport type RootProps<Value extends SliderValue = SliderValue> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<SliderProps<Value>, \"id\"> & { id?: string }\n>\n\n// Given neither `value` nor `defaultValue`, a slider has one thumb: its value is a number.\nfunction Root<Value extends SliderValue = number>({\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n min,\n max,\n step,\n largeStep,\n minStepsBetweenValues,\n thumbAlignment,\n orientation,\n disabled,\n name,\n form,\n format,\n locale,\n getAriaValueText,\n id,\n ...rest\n}: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createSlider<Value>, { field, direction })\n const controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n min,\n max,\n step,\n largeStep,\n minStepsBetweenValues,\n thumbAlignment,\n orientation,\n disabled,\n name,\n form,\n format,\n locale,\n getAriaValueText,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </Context.Provider>\n )\n}\n\nexport type ControlProps = PartComponentProps<\"div\", StateOf<Parts[\"control\"]>>\nexport type TrackProps = PartComponentProps<\"div\", StateOf<Parts[\"track\"]>>\nexport type IndicatorProps = PartComponentProps<\"div\", StateOf<Parts[\"indicator\"]>>\n\nconst Control = (props: ControlProps) => usePart(useSlider(\"Control\").control, \"div\", props)\nconst Track = (props: TrackProps) => usePart(useSlider(\"Track\").track, \"div\", props)\nconst Indicator = (props: IndicatorProps) => usePart(useSlider(\"Indicator\").indicator, \"div\", props)\n\nexport type ThumbProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"thumb\"]>,\n {\n /**\n * Which value of a range the thumb is, from 0. A thumb that is given none takes its place\n * among the slider's thumbs, in the order they are written.\n */\n index?: number\n }\n>\n\nfunction Thumb({ index, ...rest }: ThumbProps): ReactElement {\n const controller = useSlider(\"Thumb\")\n // The same on every render of this thumb, a second one in StrictMode included.\n const generated = useId()\n const at = index ?? generated\n // Its native input is the element's last child, whatever element the caller asked for.\n return usePart(controller.thumb(at), \"div\", rest, undefined, (content) => (\n <>\n {content}\n <PartElement of={controller.thumbInput(at)} tag=\"input\" />\n </>\n ))\n}\n\nexport type ValueProps = PartComponentProps<\n \"output\",\n StateOf<Parts[\"value\"]>,\n {\n /** Draws something else than the written value: it is given the text, and each thumb's value. */\n children?: (text: string, values: readonly number[]) => ReactNode\n }\n>\n\n/** The written value, or what `children` makes of it and of the values. */\nfunction Value({ children, ...props }: ValueProps): ReactElement {\n const controller = useSlider(\"Value\")\n const text = useSignal(controller.text)\n const values = useSignal(controller.values)\n return usePart(controller.value, \"output\", {\n ...props,\n children: children ? children(text, values) : text,\n })\n}\n\nexport const Slider = /* @__PURE__ */ parts(\"Slider\", {\n Root,\n Value,\n Control,\n Track,\n Indicator,\n Thumb,\n})\n"],"mappings":";;;;;;;;AAeA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAaA,SAAS,KAAyC,EAChD,OACA,cACA,eACA,kBACA,KACA,KACA,MACA,WACA,uBACA,gBACA,aACA,UACA,MACA,MACA,QACA,QACA,kBACA,IACA,GAAG,QAC8B;CACjC,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,cAAqB;EAAE;EAAO;CAAU,CAAC;CAC/D,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAM,GAAI;EAAO,CAAA;CACvC,CAAA;AAEtB;AAMA,MAAM,WAAW,UAAwB,QAAQ,UAAU,SAAS,CAAC,CAAC,SAAS,OAAO,KAAK;AAC3F,MAAM,SAAS,UAAsB,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,OAAO,KAAK;AACnF,MAAM,aAAa,UAA0B,QAAQ,UAAU,WAAW,CAAC,CAAC,WAAW,OAAO,KAAK;AAcnG,SAAS,MAAM,EAAE,OAAO,GAAG,QAAkC;CAC3D,MAAM,aAAa,UAAU,OAAO;CAEpC,MAAM,YAAY,MAAM;CACxB,MAAM,KAAK,SAAS;CAEpB,OAAO,QAAQ,WAAW,MAAM,EAAE,GAAG,OAAO,MAAM,KAAA,IAAY,YAC5D,qBAAA,YAAA,EAAA,UAAA,CACG,SACD,oBAAC,aAAD;EAAa,IAAI,WAAW,WAAW,EAAE;EAAG,KAAI;CAAS,CAAA,CACzD,EAAA,CAAA,CACH;AACH;;AAYA,SAAS,MAAM,EAAE,UAAU,GAAG,SAAmC;CAC/D,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,OAAO,UAAU,WAAW,IAAI;CACtC,MAAM,SAAS,UAAU,WAAW,MAAM;CAC1C,OAAO,QAAQ,WAAW,OAAO,UAAU;EACzC,GAAG;EACH,UAAU,WAAW,SAAS,MAAM,MAAM,IAAI;CAChD,CAAC;AACH;AAEA,MAAa,SAAyB,sBAAM,UAAU;CACpD;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
1
+ {"version":3,"file":"slider.js","names":[],"sources":["../../../../packages/react/src/slider.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSlider } from \"@kirana-ui/core/slider\"\nimport type { Slider as Controller, SliderProps, SliderValue } from \"@kirana-ui/core/slider\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"slider\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useSlider(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Slider.${part}> must be inside <Slider.Root>`)\n return controller\n}\n\n/**\n * `Value` is what the slider is given, `value` or `defaultValue`: a number for one thumb, a\n * list for a range. What `onValueChange` and `onValueCommitted` are told is the same kind.\n */\nexport type RootProps<Value extends SliderValue = SliderValue> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<SliderProps<Value>, \"id\"> & { id?: string }\n>\n\n// Given neither `value` nor `defaultValue`, a slider has one thumb: its value is a number.\nfunction Root<Value extends SliderValue = number>({\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n min,\n max,\n step,\n largeStep,\n minStepsBetweenValues,\n thumbAlignment,\n orientation,\n disabled,\n readOnly,\n name,\n form,\n format,\n locale,\n getAriaValueText,\n id,\n ...rest\n}: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createSlider<Value>, { field, direction })\n const controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n onValueCommitted,\n min,\n max,\n step,\n largeStep,\n minStepsBetweenValues,\n thumbAlignment,\n orientation,\n disabled,\n readOnly,\n name,\n form,\n format,\n locale,\n getAriaValueText,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </Context.Provider>\n )\n}\n\nexport type ControlProps = PartComponentProps<\"div\", StateOf<Parts[\"control\"]>>\nexport type TrackProps = PartComponentProps<\"div\", StateOf<Parts[\"track\"]>>\nexport type IndicatorProps = PartComponentProps<\"div\", StateOf<Parts[\"indicator\"]>>\n\nconst Control = (props: ControlProps) => usePart(useSlider(\"Control\").control, \"div\", props)\nconst Track = (props: TrackProps) => usePart(useSlider(\"Track\").track, \"div\", props)\nconst Indicator = (props: IndicatorProps) => usePart(useSlider(\"Indicator\").indicator, \"div\", props)\n\nexport type ThumbProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"thumb\"]>,\n {\n /**\n * Which value of a range the thumb is, from 0. A thumb that is given none takes its place\n * among the slider's thumbs, in the order they are written.\n */\n index?: number\n }\n>\n\nfunction Thumb({ index, ...rest }: ThumbProps): ReactElement {\n const controller = useSlider(\"Thumb\")\n // The same on every render of this thumb, a second one in StrictMode included.\n const generated = useId()\n const at = index ?? generated\n // Its native input is the element's last child, whatever element the caller asked for.\n return usePart(controller.thumb(at), \"div\", rest, undefined, (content) => (\n <>\n {content}\n <PartElement of={controller.thumbInput(at)} tag=\"input\" />\n </>\n ))\n}\n\nexport type ValueProps = PartComponentProps<\n \"output\",\n StateOf<Parts[\"value\"]>,\n {\n /** Draws something else than the written value: it is given the text, and each thumb's value. */\n children?: (text: string, values: readonly number[]) => ReactNode\n }\n>\n\n/** The written value, or what `children` makes of it and of the values. */\nfunction Value({ children, ...props }: ValueProps): ReactElement {\n const controller = useSlider(\"Value\")\n const text = useSignal(controller.text)\n const values = useSignal(controller.values)\n return usePart(controller.value, \"output\", {\n ...props,\n children: children ? children(text, values) : text,\n })\n}\n\nexport const Slider = /* @__PURE__ */ parts(\"Slider\", {\n Root,\n Value,\n Control,\n Track,\n Indicator,\n Thumb,\n})\n"],"mappings":";;;;;;;;AAeA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,UAAU,M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AYA,SAAS,MAAM,EAAE,UAAU,GAAG,SAAmC;CAC/D,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,OAAO,UAAU,WAAW,IAAI;CACtC,MAAM,SAAS,UAAU,WAAW,MAAM;CAC1C,OAAO,QAAQ,WAAW,OAAO,UAAU;EACzC,GAAG;EACH,UAAU,WAAW,SAAS,MAAM,MAAM,IAAI;CAChD,CAAC;AACH;AAEA,MAAa,SAAyB,sBAAM,UAAU;CACpD;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
package/src/steps.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { PartComponentProps } from "./runtime.js";
2
+ import { ReactElement } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
+ import { StepsProps } from "@kirana-ui/core/steps";
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
+ type Parts = Vocabulary["steps"];
7
+ export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<StepsProps, "id"> & {
8
+ id?: string;
9
+ }>;
10
+ declare function Root({ step, defaultStep, onStepChange, count, linear, orientation, id, ...rest }: RootProps): ReactElement;
11
+ export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
12
+ declare const List: (props: ListProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
13
+ export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
14
+ /**
15
+ * Which step it is, from 0. Left out, its place among the items in the page, once it is
16
+ * there: give it on a page a server draws, which cannot count them.
17
+ */
18
+ index?: number;
19
+ }>;
20
+ declare function Item({ index, ...props }: ItemProps): ReactElement;
21
+ export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
22
+ declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
23
+ export type IndicatorProps = PartComponentProps<"span", StateOf<Parts["indicator"]>>;
24
+ declare const Indicator: (props: IndicatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
25
+ export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>>;
26
+ declare const Separator: (props: SeparatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
27
+ export type ContentProps = PartComponentProps<"div", StateOf<Parts["content"]>, {
28
+ /** The step it is shown for, from 0. */
29
+ index: number;
30
+ }>;
31
+ declare function Content({ index, ...props }: ContentProps): ReactElement;
32
+ export type CompletedProps = PartComponentProps<"div", StateOf<Parts["completed"]>>;
33
+ declare const Completed: (props: CompletedProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
34
+ export type PreviousProps = PartComponentProps<"button", StateOf<Parts["previous"]>>;
35
+ declare const Previous: (props: PreviousProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
36
+ export type NextProps = PartComponentProps<"button", StateOf<Parts["next"]>>;
37
+ declare const Next: (props: NextProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
38
+ export declare const Steps: {
39
+ readonly Root: typeof Root;
40
+ readonly List: typeof List;
41
+ readonly Item: typeof Item;
42
+ readonly Trigger: typeof Trigger;
43
+ readonly Indicator: typeof Indicator;
44
+ readonly Separator: typeof Separator;
45
+ readonly Content: typeof Content;
46
+ readonly Completed: typeof Completed;
47
+ readonly Previous: typeof Previous;
48
+ readonly Next: typeof Next;
49
+ };
50
+ export {};
51
+ //# sourceMappingURL=steps.d.ts.map
package/src/steps.js ADDED
@@ -0,0 +1,69 @@
1
+ import { DirectionContext } from "./direction-context.js";
2
+ import { parts, useController, usePart } from "./runtime.js";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ import { within } from "@kirana-ui/core";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { createSteps } from "@kirana-ui/core/steps";
7
+ // src/steps.tsx
8
+ const Context = createContext(null);
9
+ const ItemContext = createContext(null);
10
+ function useSteps(part) {
11
+ const controller = useContext(Context);
12
+ if (!controller) throw new Error(`<Steps.${part}> must be inside <Steps.Root>`);
13
+ return controller;
14
+ }
15
+ function useIndex(part) {
16
+ const index = useContext(ItemContext);
17
+ if (index === null) throw new Error(`<Steps.${part}> must be inside <Steps.Item>`);
18
+ return index;
19
+ }
20
+ function Root({ step, defaultStep, onStepChange, count, linear, orientation, id, ...rest }) {
21
+ const direction = useContext(DirectionContext) ?? void 0;
22
+ const create = within(createSteps, { direction });
23
+ const controller = useController(create, {
24
+ step,
25
+ defaultStep,
26
+ onStepChange,
27
+ count,
28
+ linear,
29
+ orientation,
30
+ id
31
+ });
32
+ return /* @__PURE__ */ jsx(Context.Provider, {
33
+ value: controller,
34
+ children: usePart(controller.root, "div", rest)
35
+ });
36
+ }
37
+ const List = (props) => usePart(useSteps("List").list, "div", props);
38
+ function Item({ index, ...props }) {
39
+ const controller = useSteps("Item");
40
+ const item = useMemo(() => controller.item(index), [controller, index]);
41
+ return /* @__PURE__ */ jsx(ItemContext.Provider, {
42
+ value: item.index,
43
+ children: usePart(item, "div", props)
44
+ });
45
+ }
46
+ const Trigger = (props) => usePart(useSteps("Trigger").trigger(useIndex("Trigger")), "button", props);
47
+ const Indicator = (props) => usePart(useSteps("Indicator").indicator(useIndex("Indicator")), "span", props);
48
+ const Separator = (props) => usePart(useSteps("Separator").separator(useIndex("Separator")), "div", props);
49
+ function Content({ index, ...props }) {
50
+ return usePart(useSteps("Content").content(index), "div", props);
51
+ }
52
+ const Completed = (props) => usePart(useSteps("Completed").completed, "div", props);
53
+ const Previous = (props) => usePart(useSteps("Previous").previous, "button", props);
54
+ const Next = (props) => usePart(useSteps("Next").next, "button", props);
55
+ const Steps = /* @__PURE__ */ parts("Steps", {
56
+ Root,
57
+ List,
58
+ Item,
59
+ Trigger,
60
+ Indicator,
61
+ Separator,
62
+ Content,
63
+ Completed,
64
+ Previous,
65
+ Next
66
+ });
67
+ export { Steps };
68
+
69
+ //# sourceMappingURL=steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steps.js","names":[],"sources":["../../../../packages/react/src/steps.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf, ReadonlySignal } from \"@kirana-ui/core\"\nimport { createSteps } from \"@kirana-ui/core/steps\"\nimport type { Steps as Controller, StepsProps } from \"@kirana-ui/core/steps\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"steps\"]\n\nconst Context = createContext<Controller | null>(null)\n// The step an item is, for the parts inside it: given, or counted from the page.\nconst ItemContext = createContext<ReadonlySignal<number> | null>(null)\n\nfunction useSteps(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Steps.${part}> must be inside <Steps.Root>`)\n return controller\n}\n\nfunction useIndex(part: string): ReadonlySignal<number> {\n const index = useContext(ItemContext)\n if (index === null) throw new Error(`<Steps.${part}> must be inside <Steps.Item>`)\n return index\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<StepsProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n step,\n defaultStep,\n onStepChange,\n count,\n linear,\n orientation,\n id,\n ...rest\n}: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createSteps, { direction })\n const controller: Controller = useController(create, {\n step,\n defaultStep,\n onStepChange,\n count,\n linear,\n orientation,\n id,\n })\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst List = (props: ListProps) => usePart(useSteps(\"List\").list, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /**\n * Which step it is, from 0. Left out, its place among the items in the page, once it is\n * there: give it on a page a server draws, which cannot count them.\n */\n index?: number\n }\n>\n\nfunction Item({ index, ...props }: ItemProps): ReactElement {\n const controller = useSteps(\"Item\")\n const item = useMemo(() => controller.item(index), [controller, index])\n return (\n <ItemContext.Provider value={item.index}>{usePart(item, \"div\", props)}</ItemContext.Provider>\n )\n}\n\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\n\nconst Trigger = (props: TriggerProps) =>\n usePart(useSteps(\"Trigger\").trigger(useIndex(\"Trigger\")), \"button\", props)\n\nexport type IndicatorProps = PartComponentProps<\"span\", StateOf<Parts[\"indicator\"]>>\n\nconst Indicator = (props: IndicatorProps) =>\n usePart(useSteps(\"Indicator\").indicator(useIndex(\"Indicator\")), \"span\", props)\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\nconst Separator = (props: SeparatorProps) =>\n usePart(useSteps(\"Separator\").separator(useIndex(\"Separator\")), \"div\", props)\n\nexport type ContentProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"content\"]>,\n {\n /** The step it is shown for, from 0. */\n index: number\n }\n>\n\nfunction Content({ index, ...props }: ContentProps): ReactElement {\n return usePart(useSteps(\"Content\").content(index), \"div\", props)\n}\n\nexport type CompletedProps = PartComponentProps<\"div\", StateOf<Parts[\"completed\"]>>\n\nconst Completed = (props: CompletedProps) => usePart(useSteps(\"Completed\").completed, \"div\", props)\n\nexport type PreviousProps = PartComponentProps<\"button\", StateOf<Parts[\"previous\"]>>\n\nconst Previous = (props: PreviousProps) => usePart(useSteps(\"Previous\").previous, \"button\", props)\n\nexport type NextProps = PartComponentProps<\"button\", StateOf<Parts[\"next\"]>>\n\nconst Next = (props: NextProps) => usePart(useSteps(\"Next\").next, \"button\", props)\n\nexport const Steps = /* @__PURE__ */ parts(\"Steps\", {\n Root,\n List,\n Item,\n Trigger,\n Indicator,\n Separator,\n Content,\n Completed,\n Previous,\n Next,\n})\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAErD,MAAM,cAAc,cAA6C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CAAC,GAAG,OAAO,KAAK;AAW9E,SAAS,QAAQ,EAAE,OAAO,GAAG,SAAqC;CAChE,OAAO,QAAQ,SAAS,SAAS,CAAC,CAAC,QAAQ,KAAK,GAAG,OAAO,KAAK;AACjE;AAIA,MAAM,aAAa,UAA0B,QAAQ,SAAS,WAAW,CAAC,CAAC,WAAW,OAAO,KAAK;AAIlG,MAAM,YAAY,UAAyB,QAAQ,SAAS,UAAU,CAAC,CAAC,UAAU,UAAU,KAAK;AAIjG,MAAM,QAAQ,UAAqB,QAAQ,SAAS,MAAM,CAAC,CAAC,MAAM,UAAU,KAAK;AAEjF,MAAa,QAAwB,sBAAM,SAAS;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
package/src/switch.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
- import { StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
4
  import { SwitchProps } from "@kirana-ui/core/switch";
5
5
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
6
  type Parts = Vocabulary["switch"];
7
7
  export type RootProps = PartComponentProps<"span", StateOf<Parts["root"]>, Omit<SwitchProps, "id"> & {
8
+ /** The id of the switch's hidden native checkbox, not of the switch: a `<label for>` names it. Inside a `Field`, that input takes the field's id instead. */
8
9
  id?: string;
9
10
  }>;
10
11
  declare function Root({ checked, defaultChecked, onCheckedChange, disabled, readOnly, required, name, form, value, id, ...rest }: RootProps): ReactElement;
package/src/switch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FieldContext } from "./field-context.js";
2
2
  import { PartElement, parts, useController, usePart } from "./runtime.js";
3
- import { within } from "@kirana-ui/core";
4
3
  import { createContext, useContext } from "react";
4
+ import { within } from "@kirana-ui/core";
5
5
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
6
  import { createSwitch } from "@kirana-ui/core/switch";
7
7
  // src/switch.tsx
package/src/switch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"switch.js","names":[],"sources":["../../../../packages/react/src/switch.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSwitch } from \"@kirana-ui/core/switch\"\nimport type { Switch as Controller, SwitchProps } from \"@kirana-ui/core/switch\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"switch\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useSwitch(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Switch.${part}> must be inside <Switch.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"root\"]>,\n Omit<SwitchProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n checked,\n defaultChecked,\n onCheckedChange,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const create = within(createSwitch, { field })\n const controller = useController(create, {\n checked,\n defaultChecked,\n onCheckedChange,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"span\" hold={withInput} {...rest} />\n </Context.Provider>\n )\n}\n\n// Its native input is the element's last child, whatever element the caller asked for.\nconst withInput = (content: ReactNode) => (\n <>\n {content}\n <Input />\n </>\n)\n\nconst Input = () => usePart(useSwitch(\"Root\").input, \"input\", {})\n\nexport type ThumbProps = PartComponentProps<\"span\", StateOf<Parts[\"thumb\"]>>\n\nconst Thumb = (props: ThumbProps) => usePart(useSwitch(\"Thumb\").thumb, \"span\", props)\n\nexport const Switch = /* @__PURE__ */ parts(\"Switch\", { Root, Thumb })\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,SACA,gBACA,iBACA,UACA,UACA,UACA,MACA,MACA,OACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,SAAS,OAAO,cAAc,EAAE,MAAM,CAAC;CAC7C,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAO,MAAM;GAAW,GAAI;EAAO,CAAA;CACzD,CAAA;AAEtB;AAGA,MAAM,aAAa,YACjB,qBAAA,YAAA,EAAA,UAAA,CACG,SACD,oBAAC,OAAD,CAAQ,CAAA,CACR,EAAA,CAAA;AAGJ,MAAM,cAAc,QAAQ,UAAU,MAAM,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC;AAIhE,MAAM,SAAS,UAAsB,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,QAAQ,KAAK;AAEpF,MAAa,SAAyB,sBAAM,UAAU;CAAE;CAAM;AAAM,CAAC"}
1
+ {"version":3,"file":"switch.js","names":[],"sources":["../../../../packages/react/src/switch.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createSwitch } from \"@kirana-ui/core/switch\"\nimport type { Switch as Controller, SwitchProps } from \"@kirana-ui/core/switch\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport { PartElement, parts, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"switch\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useSwitch(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Switch.${part}> must be inside <Switch.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"root\"]>,\n Omit<SwitchProps, \"id\"> & {\n /** The id of the switch's hidden native checkbox, not of the switch: a `<label for>` names it. Inside a `Field`, that input takes the field's id instead. */\n id?: string\n }\n>\n\nfunction Root({\n checked,\n defaultChecked,\n onCheckedChange,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n ...rest\n}: RootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const create = within(createSwitch, { field })\n const controller = useController(create, {\n checked,\n defaultChecked,\n onCheckedChange,\n disabled,\n readOnly,\n required,\n name,\n form,\n value,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"span\" hold={withInput} {...rest} />\n </Context.Provider>\n )\n}\n\n// Its native input is the element's last child, whatever element the caller asked for.\nconst withInput = (content: ReactNode) => (\n <>\n {content}\n <Input />\n </>\n)\n\nconst Input = () => usePart(useSwitch(\"Root\").input, \"input\", {})\n\nexport type ThumbProps = PartComponentProps<\"span\", StateOf<Parts[\"thumb\"]>>\n\nconst Thumb = (props: ThumbProps) => usePart(useSwitch(\"Thumb\").thumb, \"span\", props)\n\nexport const Switch = /* @__PURE__ */ parts(\"Switch\", { Root, Thumb })\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,UAAU,MAA0B;CAC3C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,WAAW,KAAK,+BAA+B;CAChF,OAAO;AACT;AAWA,SAAS,KAAK,EACZ,SACA,gBACA,iBACA,UACA,UACA,UACA,MACA,MACA,OACA,IACA,GAAG,QACuB;CAC1B,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,SAAS,OAAO,cAAc,EAAE,MAAM,CAAC;CAC7C,MAAM,aAAa,cAAc,QAAQ;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAO,MAAM;GAAW,GAAI;EAAO,CAAA;CACzD,CAAA;AAEtB;AAGA,MAAM,aAAa,YACjB,qBAAA,YAAA,EAAA,UAAA,CACG,SACD,oBAAC,OAAD,CAAQ,CAAA,CACR,EAAA,CAAA;AAGJ,MAAM,cAAc,QAAQ,UAAU,MAAM,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC;AAIhE,MAAM,SAAS,UAAsB,QAAQ,UAAU,OAAO,CAAC,CAAC,OAAO,QAAQ,KAAK;AAEpF,MAAa,SAAyB,sBAAM,UAAU;CAAE;CAAM;AAAM,CAAC"}
package/src/tabs.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
- import { StateOf } from "@kirana-ui/core";
3
2
  import { ReactElement } from "react";
3
+ import { StateOf } from "@kirana-ui/core";
4
4
  import { TabsListOptions, TabsProps } from "@kirana-ui/core/tabs";
5
5
  import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
6
  type Parts = Vocabulary["tabs"];
@@ -10,7 +10,7 @@ export type RootProps<Value = unknown> = PartComponentProps<"div", StateOf<Parts
10
10
  }>;
11
11
  declare function Root<Value = unknown>({ value, defaultValue, onValueChange, orientation, id, ...rest }: RootProps<Value>): ReactElement;
12
12
  export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>, TabsListOptions>;
13
- declare function List({ activateOnFocus, loop, ...props }: ListProps): ReactElement;
13
+ declare function List({ activateOnFocus, loop, loopFocus, ...props }: ListProps): ReactElement;
14
14
  export type TabProps = PartComponentProps<"button", StateOf<Parts["tab"]>, {
15
15
  /** What the tabs' value is while this tab is the active one. */
16
16
  value: unknown;