@kirana-ui/react 0.1.0 → 0.2.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 (172) hide show
  1. package/llms.txt +3216 -0
  2. package/package.json +124 -2
  3. package/skills/kirana-ui-primitives/SKILL.md +142 -0
  4. package/src/accordion.d.ts +26 -15
  5. package/src/accordion.js +12 -11
  6. package/src/accordion.js.map +1 -1
  7. package/src/agent.d.ts +1 -0
  8. package/src/agent.js +1 -0
  9. package/src/alert-dialog.d.ts +3 -2
  10. package/src/autocomplete.d.ts +3 -0
  11. package/src/autocomplete.js +1 -0
  12. package/src/autosize.d.ts +12 -0
  13. package/src/autosize.js +12 -0
  14. package/src/autosize.js.map +1 -0
  15. package/src/avatar.d.ts +12 -8
  16. package/src/avatar.js +19 -10
  17. package/src/avatar.js.map +1 -1
  18. package/src/button.d.ts +4 -2
  19. package/src/button.js +3 -3
  20. package/src/button.js.map +1 -1
  21. package/src/calendar.d.ts +65 -0
  22. package/src/calendar.js +89 -0
  23. package/src/calendar.js.map +1 -0
  24. package/src/carousel.d.ts +36 -0
  25. package/src/carousel.js +52 -0
  26. package/src/carousel.js.map +1 -0
  27. package/src/checkbox.d.ts +10 -7
  28. package/src/checkbox.js +19 -12
  29. package/src/checkbox.js.map +1 -1
  30. package/src/collapsible.d.ts +12 -8
  31. package/src/collapsible.js +8 -7
  32. package/src/collapsible.js.map +1 -1
  33. package/src/combobox.d.ts +119 -0
  34. package/src/combobox.js +177 -0
  35. package/src/combobox.js.map +1 -0
  36. package/src/command.d.ts +53 -0
  37. package/src/command.js +95 -0
  38. package/src/command.js.map +1 -0
  39. package/src/context-menu.d.ts +3 -0
  40. package/src/context-menu.js +1 -0
  41. package/src/date-field.d.ts +37 -0
  42. package/src/date-field.js +64 -0
  43. package/src/date-field.js.map +1 -0
  44. package/src/date-picker.d.ts +44 -0
  45. package/src/date-picker.js +62 -0
  46. package/src/date-picker.js.map +1 -0
  47. package/src/dialog.d.ts +54 -27
  48. package/src/dialog.js +23 -6
  49. package/src/dialog.js.map +1 -1
  50. package/src/direction.d.ts +1 -0
  51. package/src/direction.js +1 -1
  52. package/src/direction.js.map +1 -1
  53. package/src/drawer.d.ts +3 -0
  54. package/src/drawer.js +1 -0
  55. package/src/element.d.ts +12 -0
  56. package/src/element.js +20 -0
  57. package/src/element.js.map +1 -0
  58. package/src/field.d.ts +24 -16
  59. package/src/field.js +11 -9
  60. package/src/field.js.map +1 -1
  61. package/src/fieldset.d.ts +10 -5
  62. package/src/fieldset.js +4 -5
  63. package/src/fieldset.js.map +1 -1
  64. package/src/form.d.ts +5 -2
  65. package/src/form.js +6 -6
  66. package/src/form.js.map +1 -1
  67. package/src/hover-card.d.ts +16 -10
  68. package/src/hover-card.js +1 -1
  69. package/src/hover-card.js.map +1 -1
  70. package/src/hover-popup.d.ts +26 -12
  71. package/src/hover-popup.js +12 -12
  72. package/src/hover-popup.js.map +1 -1
  73. package/src/index.d.ts +37 -3
  74. package/src/index.js +26 -2
  75. package/src/input.d.ts +12 -0
  76. package/src/input.js +21 -0
  77. package/src/input.js.map +1 -0
  78. package/src/label.d.ts +8 -0
  79. package/src/label.js +14 -0
  80. package/src/label.js.map +1 -0
  81. package/src/listbox.d.ts +36 -0
  82. package/src/listbox.js +88 -0
  83. package/src/listbox.js.map +1 -0
  84. package/src/menu.d.ts +107 -0
  85. package/src/menu.js +206 -0
  86. package/src/menu.js.map +1 -0
  87. package/src/menubar-context.d.ts +4 -0
  88. package/src/menubar-context.js +7 -0
  89. package/src/menubar-context.js.map +1 -0
  90. package/src/menubar.d.ts +11 -0
  91. package/src/menubar.js +25 -0
  92. package/src/menubar.js.map +1 -0
  93. package/src/message-scroller.d.ts +24 -0
  94. package/src/message-scroller.js +35 -0
  95. package/src/message-scroller.js.map +1 -0
  96. package/src/meter.d.ts +18 -9
  97. package/src/meter.js +1 -1
  98. package/src/meter.js.map +1 -1
  99. package/src/navigation-menu.d.ts +58 -0
  100. package/src/navigation-menu.js +106 -0
  101. package/src/navigation-menu.js.map +1 -0
  102. package/src/number-field.d.ts +28 -0
  103. package/src/number-field.js +58 -0
  104. package/src/number-field.js.map +1 -0
  105. package/src/otp.d.ts +35 -0
  106. package/src/otp.js +64 -0
  107. package/src/otp.js.map +1 -0
  108. package/src/pagination.d.ts +37 -0
  109. package/src/pagination.js +50 -0
  110. package/src/pagination.js.map +1 -0
  111. package/src/popover.d.ts +32 -22
  112. package/src/popover.js +10 -14
  113. package/src/popover.js.map +1 -1
  114. package/src/progress.d.ts +18 -9
  115. package/src/progress.js +1 -1
  116. package/src/progress.js.map +1 -1
  117. package/src/qr-code.d.ts +21 -0
  118. package/src/qr-code.js +32 -0
  119. package/src/qr-code.js.map +1 -0
  120. package/src/radio-group.d.ts +17 -11
  121. package/src/radio-group.js +20 -22
  122. package/src/radio-group.js.map +1 -1
  123. package/src/resizable.d.ts +24 -0
  124. package/src/resizable.js +51 -0
  125. package/src/resizable.js.map +1 -0
  126. package/src/runtime.d.ts +114 -13
  127. package/src/runtime.js +205 -24
  128. package/src/runtime.js.map +1 -1
  129. package/src/scroll-area.d.ts +36 -0
  130. package/src/scroll-area.js +64 -0
  131. package/src/scroll-area.js.map +1 -0
  132. package/src/select.d.ts +79 -31
  133. package/src/select.js +86 -23
  134. package/src/select.js.map +1 -1
  135. package/src/separator.d.ts +4 -2
  136. package/src/separator.js +3 -3
  137. package/src/separator.js.map +1 -1
  138. package/src/slider.d.ts +35 -20
  139. package/src/slider.js +20 -19
  140. package/src/slider.js.map +1 -1
  141. package/src/switch.d.ts +10 -6
  142. package/src/switch.js +12 -9
  143. package/src/switch.js.map +1 -1
  144. package/src/tabs.d.ts +22 -14
  145. package/src/tabs.js +7 -8
  146. package/src/tabs.js.map +1 -1
  147. package/src/testing.d.ts +1 -0
  148. package/src/testing.js +1 -0
  149. package/src/toast.d.ts +68 -0
  150. package/src/toast.js +107 -0
  151. package/src/toast.js.map +1 -0
  152. package/src/toggle-group.d.ts +10 -0
  153. package/src/toggle-group.js +32 -0
  154. package/src/toggle-group.js.map +1 -0
  155. package/src/toggle.d.ts +5 -2
  156. package/src/toggle.js +15 -5
  157. package/src/toggle.js.map +1 -1
  158. package/src/toolbar-context.d.ts +7 -0
  159. package/src/toolbar-context.js +9 -0
  160. package/src/toolbar-context.js.map +1 -0
  161. package/src/toolbar.d.ts +35 -0
  162. package/src/toolbar.js +63 -0
  163. package/src/toolbar.js.map +1 -0
  164. package/src/tooltip.d.ts +16 -10
  165. package/src/tooltip.js +1 -1
  166. package/src/tooltip.js.map +1 -1
  167. package/src/use-render.d.ts +38 -0
  168. package/src/use-render.js +50 -0
  169. package/src/use-render.js.map +1 -0
  170. package/src/value-bar.d.ts +19 -11
  171. package/src/value-bar.js +8 -5
  172. package/src/value-bar.js.map +1 -1
package/src/runtime.js CHANGED
@@ -1,8 +1,10 @@
1
- import { mergeProps, sameProps, signal } from "@kirana-ui/core";
2
- import { cloneElement, createElement, isValidElement, useCallback, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
1
+ import { REF_IS_A_PROP, give, refOf } from "./element.js";
2
+ import { composeProps, computed, defined, mergeProps, sameProps, signal, stateOf } from "@kirana-ui/core";
3
+ import { cloneElement, createContext, createElement, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
4
  import { createPortal } from "react-dom";
4
5
  import { jsx } from "react/jsx-runtime";
5
6
  // src/runtime.tsx
7
+ /** A layout effect in the browser, an effect (which never runs) on a server. */
6
8
  const useIsomorphicLayoutEffect = typeof document === "undefined" ? useEffect : useLayoutEffect;
7
9
  /** A core signal's value, re-rendering when it changes. */
8
10
  function useSignal(source) {
@@ -37,9 +39,39 @@ function useController(create, props) {
37
39
  for (const key in next) if (typeof next[key] !== "function") stable[key] = next[key];
38
40
  state.source.set(stable);
39
41
  });
40
- useEffect(() => state.controller.mount(), [state.controller]);
42
+ useMount(state.controller);
41
43
  return state.controller;
42
44
  }
45
+ /**
46
+ * Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an
47
+ * effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:
48
+ * a mount is not undone for that. The cleanup waits a moment, and a mount that comes back in
49
+ * the meantime keeps what is running.
50
+ */
51
+ function useMount(mounted) {
52
+ const [state] = useState(() => ({
53
+ of: mounted,
54
+ unmount: void 0,
55
+ leaving: false
56
+ }));
57
+ useEffect(() => {
58
+ if (state.of !== mounted) {
59
+ state.unmount?.();
60
+ state.unmount = void 0;
61
+ state.of = mounted;
62
+ }
63
+ state.leaving = false;
64
+ state.unmount ??= mounted.mount();
65
+ return () => {
66
+ state.leaving = true;
67
+ queueMicrotask(() => {
68
+ if (!state.leaving) return;
69
+ state.unmount?.();
70
+ state.unmount = void 0;
71
+ });
72
+ };
73
+ }, [state, mounted]);
74
+ }
43
75
  /** A part's own options as a core signal that follows each render, after it commits. */
44
76
  function useOptions(options) {
45
77
  const [source] = useState(() => signal(options, sameProps));
@@ -60,7 +92,14 @@ const RENAMED = {
60
92
  tabindex: "tabIndex",
61
93
  for: "htmlFor",
62
94
  readonly: "readOnly",
63
- novalidate: "noValidate"
95
+ novalidate: "noValidate",
96
+ autocomplete: "autoComplete",
97
+ inputmode: "inputMode",
98
+ maxlength: "maxLength",
99
+ contenteditable: "contentEditable",
100
+ spellcheck: "spellCheck",
101
+ autocapitalize: "autoCapitalize",
102
+ enterkeyhint: "enterKeyHint"
64
103
  };
65
104
  /** A style as React takes it: `inset-inline-start` is `insetInlineStart`, `--x` stays as it is. */
66
105
  function reactStyle(style) {
@@ -75,46 +114,188 @@ function toReact(props) {
75
114
  const out = {};
76
115
  for (const key in props) {
77
116
  const value = props[key];
78
- if (BOOLEAN.has(key)) out[RENAMED[key] ?? key] = value === "" || value === true;
79
- else if (key === "style" && value) out.style = reactStyle(value);
117
+ if (BOOLEAN.has(key)) {
118
+ const name = RENAMED[key] ?? key;
119
+ if (value !== void 0 || !(name in out)) {
120
+ const present = value === "" || value === true;
121
+ out[name] = key === "inert" && !REF_IS_A_PROP ? present ? "" : void 0 : present;
122
+ }
123
+ } else if (key === "style" && value) out.style = reactStyle(value);
80
124
  else if (value !== void 0) out[RENAMED[key] ?? key] = value;
81
125
  }
82
126
  return out;
83
127
  }
84
128
  /**
85
- * Renders a part: its element (or the caller's `render`), with the caller's props merged under
86
- * the part's, and the part's DOM work attached to the element.
129
+ * Renders a part: its element (or the caller's `render`), and the part's DOM work attached to
130
+ * the element. Three layers of props, lowest first: what was handed to the part, the `render`
131
+ * element's own, the part's. A higher layer wins an attribute; classes join; styles are merged
132
+ * property by property; every handler of an event runs, lowest first, and
133
+ * `event.preventKiranaHandler()` in a caller's stops the part's. The `render` element's own
134
+ * children are drawn when it has any, and both its ref and the part's `ref` get the element.
135
+ * `hold` is for a part that keeps something of its own in its element (a hidden input): it is
136
+ * given the content and returns what the element holds, whoever drew the element.
87
137
  */
88
- function usePart(part, tag, { render, ref, ...caller }, state) {
138
+ function usePart(part, tag, props, state, hold) {
139
+ const { render: asRender, ref: asRef, ...caller } = props;
140
+ const render = asRender;
141
+ const ref = asRef;
89
142
  const own = useSignal(part.props);
90
- const detach = useRef(void 0);
143
+ const asked = isValidElement(render) ? render : void 0;
144
+ const theirs = asked ? refOf(asked) : void 0;
145
+ const held = useRef(void 0);
91
146
  const attach = useCallback((element) => {
92
- detach.current?.();
93
- detach.current = element ? part.attach(element) : void 0;
94
- if (typeof ref === "function") ref(element);
95
- else if (ref) ref.current = element;
96
- }, [part, ref]);
97
- const props = {
98
- ...toReact(mergeProps(caller, own)),
147
+ const now = held.current;
148
+ if (!element) {
149
+ if (now) {
150
+ now.leaving = true;
151
+ queueMicrotask(() => {
152
+ if (!now.leaving) return;
153
+ now.detach();
154
+ if (held.current === now) held.current = void 0;
155
+ });
156
+ }
157
+ } else if (now && now.element === element && now.part === part) now.leaving = false;
158
+ else {
159
+ if (now) {
160
+ now.leaving = false;
161
+ now.detach();
162
+ }
163
+ held.current = {
164
+ element,
165
+ part,
166
+ detach: part.attach(element),
167
+ leaving: false
168
+ };
169
+ }
170
+ give(ref, element);
171
+ give(theirs, element);
172
+ }, [
173
+ part,
174
+ ref,
175
+ theirs
176
+ ]);
177
+ let under = caller;
178
+ if (asked) {
179
+ const { ref: _ref, ...element } = REF_IS_A_PROP ? asked.props : { ...asked.props };
180
+ under = composeProps(caller, element);
181
+ }
182
+ const drawn = {
183
+ ...toReact(mergeProps(under, own)),
99
184
  ref: attach
100
185
  };
101
- if (typeof render === "function") return render(props, state);
102
- if (isValidElement(render)) return cloneElement(render, {
103
- ...toReact(mergeProps(render.props, props)),
104
- ref: attach
186
+ if (hold) drawn.children = hold(drawn.children);
187
+ if (asked) return cloneElement(asked, drawn);
188
+ if (typeof render === "function") return render(drawn, state ?? stateOf(own));
189
+ return createElement(tag, drawn);
190
+ }
191
+ const forwarded = /* @__PURE__ */ new WeakMap();
192
+ /**
193
+ * A component that is handed its caller's `ref` on every React the package takes, under the
194
+ * name DevTools shows it by. React 19 gives a component its `ref` among its props, which is
195
+ * where a part reads it; before, only a `forwardRef` component was given one, so there the
196
+ * component is drawn by one that puts the ref back among the props. Its type is its own
197
+ * either way, so one that is generic stays generic. One that already has a name keeps it.
198
+ */
199
+ function component(name, draw) {
200
+ const named = draw;
201
+ if (REF_IS_A_PROP) {
202
+ named.displayName ??= name;
203
+ return draw;
204
+ }
205
+ let made = forwarded.get(draw);
206
+ if (!made) {
207
+ const drawing = draw;
208
+ const forwards = forwardRef((props, ref) => drawing(ref === null ? props : {
209
+ ...props,
210
+ ref
211
+ }));
212
+ forwards.displayName = name;
213
+ forwarded.set(draw, made = forwards);
214
+ }
215
+ return made;
216
+ }
217
+ /**
218
+ * A component's parts, each one a `component` named `Name.Part`. A part that is another
219
+ * component's (a date picker's trigger is a popover's) is the same component there and here.
220
+ */
221
+ function parts(name, all) {
222
+ const made = {};
223
+ for (const key in all) {
224
+ const part = all[key];
225
+ made[key] = typeof part === "function" ? component(`${name}.${key}`, part) : part;
226
+ }
227
+ return made;
228
+ }
229
+ /**
230
+ * A part's element as a component of its own, for a part that is not always in the page: the
231
+ * part decides, and draws this when it is. It takes the part's props, with the part it is the
232
+ * element `of`, its tag, and what the element holds of the part's own (`hold`, as `usePart`'s).
233
+ */
234
+ const PartElement = /* @__PURE__ */ component("PartElement", function PartElement({ of, tag, hold, ...props }) {
235
+ return usePart(of, tag, props, void 0, hold);
236
+ });
237
+ const readers = /* @__PURE__ */ new WeakMap();
238
+ function anchorOf(anchor) {
239
+ if (!anchor || typeof anchor === "function") return anchor;
240
+ if (!("current" in anchor) || "getBoundingClientRect" in anchor) return anchor;
241
+ let read = readers.get(anchor);
242
+ if (!read) readers.set(anchor, read = () => anchor.current);
243
+ return read;
244
+ }
245
+ /**
246
+ * A positioner's own props, written where its placement reads them: the one place they are
247
+ * named. Gives back what is left, for the part's element.
248
+ */
249
+ function usePositioning(positioning, { side, align, sideOffset, alignOffset, collisionPadding, anchor, ...rest }) {
250
+ positioning.set(defined({
251
+ side,
252
+ align,
253
+ sideOffset,
254
+ alignOffset,
255
+ collisionPadding,
256
+ anchor: anchorOf(anchor)
257
+ }));
258
+ return rest;
259
+ }
260
+ /**
261
+ * A text input whose text is the core's own (a combobox's, a number field's): its `value` is
262
+ * given to React as the input's default. To React a `value` with no `onChange` is an input
263
+ * that cannot be typed in; the core writes the text itself, as it changes.
264
+ */
265
+ function useOwnText(part) {
266
+ return useMemo(() => ({
267
+ props: computed(() => {
268
+ const { value, ...rest } = part.props.get();
269
+ return {
270
+ ...rest,
271
+ defaultValue: value
272
+ };
273
+ }),
274
+ attach: (element) => part.attach(element)
275
+ }), [part]);
276
+ }
277
+ const PortalContainer = createContext(void 0);
278
+ /**
279
+ * Says where every popup inside it is drawn, the popups those open included: an element of
280
+ * the page (a shadow root's host, a full-screen element, a frame) in place of `<body>`.
281
+ */
282
+ function PortalProvider({ container, children }) {
283
+ return /* @__PURE__ */ jsx(PortalContainer.Provider, {
284
+ value: container,
285
+ children
105
286
  });
106
- return createElement(tag, props);
107
287
  }
108
288
  /** Its children in a container at the end of the page, once the page has hydrated. */
109
289
  function Portal({ children }) {
290
+ const container = useContext(PortalContainer);
110
291
  const [ready, setReady] = useState(false);
111
292
  useIsomorphicLayoutEffect(() => setReady(true), []);
112
293
  if (!ready) return null;
113
294
  return createPortal(/* @__PURE__ */ jsx("div", {
114
295
  "data-kirana-portal": "",
115
296
  children
116
- }), document.body);
297
+ }), container ?? document.body);
117
298
  }
118
- export { Portal, useController, useOptions, usePart, useSignal };
299
+ export { PartElement, Portal, PortalProvider, component, parts, useController, useIsomorphicLayoutEffect, useMount, useOptions, useOwnText, usePart, usePositioning, useSignal };
119
300
 
120
301
  //# sourceMappingURL=runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/react/src/runtime.tsx"],"sourcesContent":["import { mergeProps, sameProps, signal } from \"@kirana-ui/core\"\nimport type { Part, PartProps, ReadonlySignal, Signal } from \"@kirana-ui/core\"\nimport {\n cloneElement,\n createElement,\n isValidElement,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\"\nimport type { ReactElement, ReactNode, Ref } from \"react\"\nimport { createPortal } from \"react-dom\"\n\nconst useIsomorphicLayoutEffect = 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 useEffect(() => state.controller.mount(), [state.controller])\n return state.controller\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}\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 // Always a boolean, never left out: an input whose `checked` comes and goes is, to React,\n // one that changes from controlled to not.\n if (BOOLEAN.has(key)) out[RENAMED[key] ?? key] = value === \"\" || value === true\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\nexport type RenderProp<State = undefined> =\n | ReactElement<Record<string, unknown>>\n | ((props: Record<string, unknown>, state: State) => ReactElement)\n\nexport interface PartComponentProps<State = undefined> {\n /** Renders the part as another element or component. The part's attributes still win. */\n render?: RenderProp<State> | undefined\n children?: ReactNode\n ref?: Ref<HTMLElement> | undefined\n [attribute: string]: unknown\n}\n\n/**\n * Renders a part: its element (or the caller's `render`), with the caller's props merged under\n * the part's, and the part's DOM work attached to the element.\n */\nexport function usePart<State = undefined>(\n part: Part,\n tag: string,\n { render, ref, ...caller }: PartComponentProps<State>,\n state?: State\n): ReactElement {\n const own = useSignal(part.props)\n const detach = useRef<(() => void) | undefined>(undefined)\n const attach = useCallback(\n (element: HTMLElement | null) => {\n detach.current?.()\n detach.current = element ? part.attach(element) : undefined\n if (typeof ref === \"function\") ref(element)\n else if (ref) (ref as { current: HTMLElement | null }).current = element\n },\n [part, ref]\n )\n const props = { ...toReact(mergeProps(caller, own)), ref: attach }\n if (typeof render === \"function\") return render(props, state as State)\n if (isValidElement(render)) {\n return cloneElement(render, { ...toReact(mergeProps(render.props, props)), ref: attach })\n }\n return createElement(tag, props)\n}\n\n/** Its children in a container at the end of the page, once the page has hydrated. */\nexport function Portal({ children }: { children?: ReactNode }): ReactElement | null {\n const [ready, setReady] = useState(false)\n useIsomorphicLayoutEffect(() => setReady(true), [])\n if (!ready) return null\n return createPortal(<div data-kirana-portal=\"\">{children}</div>, document.body)\n}\n"],"mappings":";;;;;AAiBA,MAAM,4BAA4B,OAAO,aAAa,cAAc,YAAY;;AAGhF,SAAgB,UAAa,QAA8B;CACzD,MAAM,YAAY,aAAa,aAAyB,OAAO,UAAU,QAAQ,GAAG,CAAC,MAAM,CAAC;CAC5F,MAAM,OAAO,kBAAkB,OAAO,KAAK,GAAG,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AAD;EAAK,sBAAmB;EAAI;CAAc,CAAA,GAAG,SAAS,IAAI;AAChF"}
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;CA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AW,2BAA2B,QAAQ,OAAO;CACxE,IAAI,OAAO,QAAQ,IAAI,MAAM;CAC7B,IAAI,CAAC,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"}
@@ -0,0 +1,36 @@
1
+ import { PartComponentProps } from "./runtime.js";
2
+ import { Orientation, StateOf } from "@kirana-ui/core";
3
+ import { ReactElement } from "react";
4
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
5
+ type Parts = Vocabulary["scrollArea"];
6
+ export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>>;
7
+ /**
8
+ * The area. Its scrollbars and its corner are placed against it by the library, in each
9
+ * part's `style`: a design gives a scrollbar its thickness and draws it.
10
+ */
11
+ declare function Root(props: RootProps): ReactElement;
12
+ export type ViewportProps = PartComponentProps<"div", StateOf<Parts["viewport"]>>;
13
+ declare const Viewport: (props: ViewportProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
14
+ export type ContentProps = PartComponentProps<"div", StateOf<Parts["content"]>>;
15
+ declare const Content: (props: ContentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
16
+ export type ScrollbarProps = PartComponentProps<"div", StateOf<Parts["scrollbar"]>, {
17
+ /** Which way it scrolls. Default: `vertical`. */
18
+ orientation?: Orientation;
19
+ /** In the page even while there is nothing to scroll its way. */
20
+ keepMounted?: boolean;
21
+ }>;
22
+ declare function Scrollbar({ orientation, keepMounted, ...props }: ScrollbarProps): ReactElement | null;
23
+ export type ThumbProps = PartComponentProps<"div", StateOf<Parts["thumb"]>>;
24
+ declare function Thumb(props: ThumbProps): ReactElement;
25
+ export type CornerProps = PartComponentProps<"div", StateOf<Parts["corner"]>>;
26
+ declare function Corner(props: CornerProps): ReactElement | null;
27
+ export declare const ScrollArea: {
28
+ readonly Root: typeof Root;
29
+ readonly Viewport: typeof Viewport;
30
+ readonly Content: typeof Content;
31
+ readonly Scrollbar: typeof Scrollbar;
32
+ readonly Thumb: typeof Thumb;
33
+ readonly Corner: typeof Corner;
34
+ };
35
+ export {};
36
+ //# sourceMappingURL=scroll-area.d.ts.map
@@ -0,0 +1,64 @@
1
+ import { DirectionContext } from "./direction-context.js";
2
+ import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
3
+ import { within } from "@kirana-ui/core";
4
+ import { createContext, useContext } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { createScrollArea } from "@kirana-ui/core/scroll-area";
7
+ // src/scroll-area.tsx
8
+ const Context = createContext(null);
9
+ const ScrollbarContext = createContext(null);
10
+ function useScrollArea(part) {
11
+ const controller = useContext(Context);
12
+ if (!controller) throw new Error(`<ScrollArea.${part}> must be inside <ScrollArea.Root>`);
13
+ return controller;
14
+ }
15
+ /**
16
+ * The area. Its scrollbars and its corner are placed against it by the library, in each
17
+ * part's `style`: a design gives a scrollbar its thickness and draws it.
18
+ */
19
+ function Root(props) {
20
+ const direction = useContext(DirectionContext) ?? void 0;
21
+ const controller = useController(within(createScrollArea, { direction }), {});
22
+ return /* @__PURE__ */ jsx(Context.Provider, {
23
+ value: controller,
24
+ children: usePart(controller.root, "div", props)
25
+ });
26
+ }
27
+ const Viewport = (props) => usePart(useScrollArea("Viewport").viewport, "div", props);
28
+ const Content = (props) => usePart(useScrollArea("Content").content, "div", props);
29
+ function Scrollbar({ orientation = "vertical", keepMounted, ...props }) {
30
+ const bar = useScrollArea("Scrollbar").scrollbar(orientation);
31
+ if (!useSignal(bar.shown) && !keepMounted) return null;
32
+ return /* @__PURE__ */ jsx(ScrollbarContext.Provider, {
33
+ value: bar,
34
+ children: /* @__PURE__ */ jsx(PartElement, {
35
+ of: bar.part,
36
+ tag: "div",
37
+ ...props
38
+ })
39
+ });
40
+ }
41
+ function Thumb(props) {
42
+ const bar = useContext(ScrollbarContext);
43
+ if (!bar) throw new Error("<ScrollArea.Thumb> must be inside <ScrollArea.Scrollbar>");
44
+ return usePart(bar.thumb, "div", props);
45
+ }
46
+ function Corner(props) {
47
+ const { corner } = useScrollArea("Corner");
48
+ return useSignal(corner.shown) ? /* @__PURE__ */ jsx(PartElement, {
49
+ of: corner.part,
50
+ tag: "div",
51
+ ...props
52
+ }) : null;
53
+ }
54
+ const ScrollArea = /* @__PURE__ */ parts("ScrollArea", {
55
+ Root,
56
+ Viewport,
57
+ Content,
58
+ Scrollbar,
59
+ Thumb,
60
+ Corner
61
+ });
62
+ export { ScrollArea };
63
+
64
+ //# sourceMappingURL=scroll-area.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-area.js","names":[],"sources":["../../../../packages/react/src/scroll-area.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { Orientation, StateOf } from \"@kirana-ui/core\"\nimport { createScrollArea } from \"@kirana-ui/core/scroll-area\"\nimport type { ScrollArea as Controller, ScrollAreaScrollbar } from \"@kirana-ui/core/scroll-area\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { PartElement, parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"scrollArea\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ScrollbarContext = createContext<ScrollAreaScrollbar | null>(null)\n\nfunction useScrollArea(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<ScrollArea.${part}> must be inside <ScrollArea.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\"div\", StateOf<Parts[\"root\"]>>\n\n/**\n * The area. Its scrollbars and its corner are placed against it by the library, in each\n * part's `style`: a design gives a scrollbar its thickness and draws it.\n */\nfunction Root(props: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController(within(createScrollArea, { direction }), {})\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", props)}</Context.Provider>\n )\n}\n\nexport type ViewportProps = PartComponentProps<\"div\", StateOf<Parts[\"viewport\"]>>\n\nconst Viewport = (props: ViewportProps) => usePart(useScrollArea(\"Viewport\").viewport, \"div\", props)\nexport type ContentProps = PartComponentProps<\"div\", StateOf<Parts[\"content\"]>>\n\nconst Content = (props: ContentProps) => usePart(useScrollArea(\"Content\").content, \"div\", props)\n\nexport type ScrollbarProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"scrollbar\"]>,\n {\n /** Which way it scrolls. Default: `vertical`. */\n orientation?: Orientation\n /** In the page even while there is nothing to scroll its way. */\n keepMounted?: boolean\n }\n>\n\nfunction Scrollbar({\n orientation = \"vertical\",\n keepMounted,\n ...props\n}: ScrollbarProps): ReactElement | null {\n const bar = useScrollArea(\"Scrollbar\").scrollbar(orientation)\n const shown = useSignal(bar.shown)\n if (!shown && !keepMounted) return null\n return (\n <ScrollbarContext.Provider value={bar}>\n <PartElement of={bar.part} tag=\"div\" {...props} />\n </ScrollbarContext.Provider>\n )\n}\n\nexport type ThumbProps = PartComponentProps<\"div\", StateOf<Parts[\"thumb\"]>>\n\nfunction Thumb(props: ThumbProps): ReactElement {\n const bar = useContext(ScrollbarContext)\n if (!bar) throw new Error(\"<ScrollArea.Thumb> must be inside <ScrollArea.Scrollbar>\")\n return usePart(bar.thumb, \"div\", props)\n}\n\nexport type CornerProps = PartComponentProps<\"div\", StateOf<Parts[\"corner\"]>>\n\nfunction Corner(props: CornerProps): ReactElement | null {\n const { corner } = useScrollArea(\"Corner\")\n const shown = useSignal(corner.shown)\n return shown ? <PartElement of={corner.part} tag=\"div\" {...props} /> : null\n}\n\nexport const ScrollArea = /* @__PURE__ */ parts(\"ScrollArea\", {\n Root,\n Viewport,\n Content,\n Scrollbar,\n Thumb,\n Corner,\n})\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,mBAAmB,cAA0C,IAAI;AAEvE,SAAS,cAAc,MAA0B;CAC/C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,eAAe,KAAK,mCAAmC;CACxF,OAAO;AACT;;;;;AAQA,SAAS,KAAK,OAAgC;CAC5C,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cAAc,OAAO,kBAAkB,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;CAC5E,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,KAAK;CAAoB,CAAA;AAEnG;AAIA,MAAM,YAAY,UAAyB,QAAQ,cAAc,UAAU,CAAC,CAAC,UAAU,OAAO,KAAK;AAGnG,MAAM,WAAW,UAAwB,QAAQ,cAAc,SAAS,CAAC,CAAC,SAAS,OAAO,KAAK;AAa/F,SAAS,UAAU,EACjB,cAAc,YACd,aACA,GAAG,SACmC;CACtC,MAAM,MAAM,cAAc,WAAW,CAAC,CAAC,UAAU,WAAW;CAE5D,IAAI,CADU,UAAU,IAAI,KACnB,KAAK,CAAC,aAAa,OAAO;CACnC,OACE,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO;EAChC,UAAA,oBAAC,aAAD;GAAa,IAAI,IAAI;GAAM,KAAI;GAAM,GAAI;EAAQ,CAAA;CACxB,CAAA;AAE/B;AAIA,SAAS,MAAM,OAAiC;CAC9C,MAAM,MAAM,WAAW,gBAAgB;CACvC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,0DAA0D;CACpF,OAAO,QAAQ,IAAI,OAAO,OAAO,KAAK;AACxC;AAIA,SAAS,OAAO,OAAyC;CACvD,MAAM,EAAE,WAAW,cAAc,QAAQ;CAEzC,OADc,UAAU,OAAO,KACpB,IAAI,oBAAC,aAAD;EAAa,IAAI,OAAO;EAAM,KAAI;EAAM,GAAI;CAAQ,CAAA,IAAI;AACzE;AAEA,MAAa,aAA6B,sBAAM,cAAc;CAC5D;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
package/src/select.d.ts CHANGED
@@ -1,46 +1,94 @@
1
- import { PartComponentProps } from "./runtime.js";
2
- import { PositionOptions } from "@kirana-ui/core";
1
+ import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
2
+ import { StateOf } from "@kirana-ui/core";
3
3
  import { ReactElement, ReactNode } from "react";
4
4
  import { SelectProps } from "@kirana-ui/core/select";
5
- export type RootProps<Value> = Omit<SelectProps<Value>, "id"> & {
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
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"> & {
6
9
  id?: string;
7
10
  children?: ReactNode;
8
11
  };
9
- declare function Root<Value>({ children, ...props }: RootProps<Value>): ReactElement;
10
- declare const Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
11
- export interface ValueProps extends PartComponentProps {
12
+ declare function Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement;
13
+ export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
14
+ declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
15
+ export type ValueProps<Chosen = unknown> = PartComponentProps<"span", StateOf<Parts["value"]>, {
12
16
  /** Shown while nothing is chosen. */
13
17
  placeholder?: ReactNode;
14
- }
15
- declare function Value({ placeholder, children, ...props }: ValueProps): ReactElement;
16
- declare function Portal({ children }: {
17
- children?: ReactNode;
18
- }): ReactElement | null;
19
- export type PositionerProps = PartComponentProps & Partial<PositionOptions>;
20
- declare function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }: PositionerProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
21
- declare const Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
22
- export interface ItemProps extends PartComponentProps {
18
+ /**
19
+ * What to show in place of the label. A function is given the value and its label (`null`
20
+ * and `undefined` while nothing is chosen); with `multiple`, the values and their labels, in
21
+ * the items' order. Its first parameter's type says which: `(values: string[], labels) => …`.
22
+ */
23
+ children?: ReactNode | ((value: Chosen, label: Chosen extends readonly unknown[] ? readonly string[] : string | undefined) => ReactNode);
24
+ }>;
25
+ declare function Value<Chosen = unknown>({ placeholder, children, ...props }: ValueProps<Chosen>): ReactElement;
26
+ declare function Portal({ children }: PortalProps): ReactElement | null;
27
+ export type PositionerProps = PartComponentProps<"div", StateOf<Parts["positioner"]>, PositionerOptions & {
28
+ /**
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.
31
+ */
32
+ alignItemWithTrigger?: boolean;
33
+ }>;
34
+ declare function Positioner({ alignItemWithTrigger, ...props }: PositionerProps): ReactElement;
35
+ export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
36
+ declare const Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
37
+ export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, {
38
+ id?: string;
39
+ }>;
40
+ /** Items that belong together, named by their `<Select.GroupLabel>`. */
41
+ declare function Group({ id, ...props }: GroupProps): ReactElement;
42
+ export type GroupLabelProps = PartComponentProps<"div", StateOf<Parts["groupLabel"]>>;
43
+ /** A group's name. Outside a group it is plain text, and names nothing. */
44
+ declare function GroupLabel(props: GroupLabelProps): ReactElement;
45
+ export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>>;
46
+ /** A line between groups. */
47
+ declare const Separator: (props: SeparatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
48
+ export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
49
+ /** The items' own box inside the popup, when the popup also holds scroll arrows. */
50
+ declare const List: (props: ListProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
51
+ export type ScrollUpArrowProps = PartComponentProps<"div", StateOf<Parts["scrollUpArrow"]>>;
52
+ export type ScrollDownArrowProps = PartComponentProps<"div", StateOf<Parts["scrollDownArrow"]>>;
53
+ /** In the page while there is more of the list above: it scrolls it while the pointer moves over it. */
54
+ declare function ScrollUpArrow(props: ScrollUpArrowProps): ReactElement | null;
55
+ /** In the page while there is more of the list below. */
56
+ declare function ScrollDownArrow(props: ScrollDownArrowProps): ReactElement | null;
57
+ export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
58
+ /** What the select's value is while this item is chosen. */
23
59
  value: unknown;
60
+ /** Disables this item: it cannot be chosen, and the arrows pass over it. */
24
61
  disabled?: boolean;
25
62
  /** What typeahead matches and the trigger shows; the item's text when left out. */
26
63
  label?: string;
27
- }
28
- declare function Item({ value, disabled, label, ...props }: ItemProps): ReactElement;
29
- declare function ItemText(props: PartComponentProps): ReactElement;
30
- export interface ItemIndicatorProps extends PartComponentProps {
64
+ /** Its place among all the rows, in a virtualized list. */
65
+ index?: number;
66
+ }>;
67
+ declare function Item({ value, disabled, label, index, ...props }: ItemProps): ReactElement;
68
+ export type ItemTextProps = PartComponentProps<"span", StateOf<Parts["itemText"]>>;
69
+ declare function ItemText(props: ItemTextProps): ReactElement;
70
+ export type ItemIndicatorProps = PartComponentProps<"span", StateOf<Parts["itemIndicator"]>, {
71
+ /** Keeps the mark in the page while its item is not chosen. */
31
72
  keepMounted?: boolean;
32
- }
33
- declare function ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }: ItemIndicatorProps): import("react").JSX.Element | null;
73
+ }>;
74
+ /** In the page while its item is the chosen one. */
75
+ declare function ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null;
34
76
  export declare const Select: {
35
- Root: typeof Root;
36
- Trigger: typeof Trigger;
37
- Value: typeof Value;
38
- Portal: typeof Portal;
39
- Positioner: typeof Positioner;
40
- Popup: typeof Popup;
41
- Item: typeof Item;
42
- ItemText: typeof ItemText;
43
- ItemIndicator: typeof ItemIndicator;
77
+ readonly Root: typeof Root;
78
+ readonly Trigger: typeof Trigger;
79
+ readonly Value: typeof Value;
80
+ readonly Portal: typeof Portal;
81
+ readonly Positioner: typeof Positioner;
82
+ readonly Popup: typeof Popup;
83
+ readonly List: typeof List;
84
+ readonly ScrollUpArrow: typeof ScrollUpArrow;
85
+ readonly ScrollDownArrow: typeof ScrollDownArrow;
86
+ readonly Group: typeof Group;
87
+ readonly GroupLabel: typeof GroupLabel;
88
+ readonly Separator: typeof Separator;
89
+ readonly Item: typeof Item;
90
+ readonly ItemText: typeof ItemText;
91
+ readonly ItemIndicator: typeof ItemIndicator;
44
92
  };
45
- export {};
93
+ export type { PortalProps };
46
94
  //# sourceMappingURL=select.d.ts.map