@kirana-ui/react 0.1.1 → 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.
- package/llms.txt +1601 -223
- package/package.json +14 -2
- package/skills/kirana-ui-primitives/SKILL.md +142 -0
- package/src/accordion.d.ts +26 -15
- package/src/accordion.js +11 -10
- package/src/accordion.js.map +1 -1
- package/src/agent.d.ts +1 -0
- package/src/agent.js +1 -0
- package/src/alert-dialog.d.ts +3 -2
- package/src/autocomplete.d.ts +3 -2
- package/src/autosize.d.ts +5 -2
- package/src/autosize.js +2 -2
- package/src/autosize.js.map +1 -1
- package/src/avatar.d.ts +12 -8
- package/src/avatar.js +18 -9
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +4 -2
- package/src/button.js +3 -3
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +49 -28
- package/src/calendar.js +7 -3
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +25 -15
- package/src/carousel.js +3 -3
- package/src/carousel.js.map +1 -1
- package/src/checkbox.d.ts +10 -7
- package/src/checkbox.js +18 -12
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +12 -8
- package/src/collapsible.js +8 -7
- package/src/collapsible.js.map +1 -1
- package/src/combobox.d.ts +88 -60
- package/src/combobox.js +44 -31
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +30 -21
- package/src/command.js +14 -7
- package/src/command.js.map +1 -1
- package/src/context-menu.d.ts +3 -2
- package/src/date-field.d.ts +25 -13
- package/src/date-field.js +7 -3
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +31 -40
- package/src/date-picker.js +3 -3
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +45 -35
- package/src/dialog.js +12 -8
- package/src/dialog.js.map +1 -1
- package/src/direction.d.ts +1 -0
- package/src/direction.js.map +1 -1
- package/src/drawer.d.ts +3 -2
- package/src/element.d.ts +12 -0
- package/src/element.js +20 -0
- package/src/element.js.map +1 -0
- package/src/field.d.ts +24 -16
- package/src/field.js +9 -7
- package/src/field.js.map +1 -1
- package/src/fieldset.d.ts +10 -5
- package/src/fieldset.js +4 -5
- package/src/fieldset.js.map +1 -1
- package/src/form.d.ts +5 -2
- package/src/form.js +6 -6
- package/src/form.js.map +1 -1
- package/src/hover-card.d.ts +16 -10
- package/src/hover-card.js +1 -1
- package/src/hover-card.js.map +1 -1
- package/src/hover-popup.d.ts +24 -14
- package/src/hover-popup.js +5 -13
- package/src/hover-popup.js.map +1 -1
- package/src/index.d.ts +13 -3
- package/src/input.d.ts +4 -2
- package/src/input.js +3 -3
- package/src/input.js.map +1 -1
- package/src/label.d.ts +4 -1
- package/src/label.js +3 -3
- package/src/label.js.map +1 -1
- package/src/listbox.d.ts +23 -15
- package/src/listbox.js +4 -5
- package/src/listbox.js.map +1 -1
- package/src/menu.d.ts +83 -65
- package/src/menu.js +10 -18
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +5 -3
- package/src/menubar.js +3 -3
- package/src/menubar.js.map +1 -1
- package/src/message-scroller.d.ts +15 -9
- package/src/message-scroller.js +3 -3
- package/src/message-scroller.js.map +1 -1
- package/src/meter.d.ts +18 -9
- package/src/meter.js +1 -1
- package/src/meter.js.map +1 -1
- package/src/navigation-menu.d.ts +50 -40
- package/src/navigation-menu.js +15 -24
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +19 -12
- package/src/number-field.js +6 -10
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +24 -15
- package/src/otp.js +7 -13
- package/src/otp.js.map +1 -1
- package/src/pagination.d.ts +26 -16
- package/src/pagination.js +3 -3
- package/src/pagination.js.map +1 -1
- package/src/popover.d.ts +30 -21
- package/src/popover.js +9 -13
- package/src/popover.js.map +1 -1
- package/src/progress.d.ts +18 -9
- package/src/progress.js +1 -1
- package/src/progress.js.map +1 -1
- package/src/qr-code.d.ts +12 -7
- package/src/qr-code.js +3 -3
- package/src/qr-code.js.map +1 -1
- package/src/radio-group.d.ts +17 -11
- package/src/radio-group.js +16 -19
- package/src/radio-group.js.map +1 -1
- package/src/resizable.d.ts +13 -8
- package/src/resizable.js +3 -3
- package/src/resizable.js.map +1 -1
- package/src/runtime.d.ts +89 -15
- package/src/runtime.js +112 -19
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +26 -15
- package/src/scroll-area.js +9 -6
- package/src/scroll-area.js.map +1 -1
- package/src/select.d.ts +65 -45
- package/src/select.js +40 -35
- package/src/select.js.map +1 -1
- package/src/separator.d.ts +4 -2
- package/src/separator.js +3 -3
- package/src/separator.js.map +1 -1
- package/src/slider.d.ts +35 -20
- package/src/slider.js +17 -18
- package/src/slider.js.map +1 -1
- package/src/switch.d.ts +10 -6
- package/src/switch.js +11 -9
- package/src/switch.js.map +1 -1
- package/src/tabs.d.ts +22 -14
- package/src/tabs.js +5 -6
- package/src/tabs.js.map +1 -1
- package/src/testing.d.ts +1 -0
- package/src/testing.js +1 -0
- package/src/toast.d.ts +59 -23
- package/src/toast.js +59 -13
- package/src/toast.js.map +1 -1
- package/src/toggle-group.d.ts +5 -2
- package/src/toggle-group.js +3 -3
- package/src/toggle-group.js.map +1 -1
- package/src/toggle.d.ts +4 -2
- package/src/toggle.js +3 -3
- package/src/toggle.js.map +1 -1
- package/src/toolbar.d.ts +26 -11
- package/src/toolbar.js +23 -13
- package/src/toolbar.js.map +1 -1
- package/src/tooltip.d.ts +16 -10
- package/src/tooltip.js +1 -1
- package/src/tooltip.js.map +1 -1
- package/src/use-render.d.ts +38 -0
- package/src/use-render.js +50 -0
- package/src/use-render.js.map +1 -0
- package/src/value-bar.d.ts +19 -11
- package/src/value-bar.js +8 -5
- package/src/value-bar.js.map +1 -1
package/src/runtime.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
|
@@ -113,18 +114,34 @@ function toReact(props) {
|
|
|
113
114
|
const out = {};
|
|
114
115
|
for (const key in props) {
|
|
115
116
|
const value = props[key];
|
|
116
|
-
if (BOOLEAN.has(key))
|
|
117
|
-
|
|
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);
|
|
118
124
|
else if (value !== void 0) out[RENAMED[key] ?? key] = value;
|
|
119
125
|
}
|
|
120
126
|
return out;
|
|
121
127
|
}
|
|
122
128
|
/**
|
|
123
|
-
* Renders a part: its element (or the caller's `render`),
|
|
124
|
-
* the
|
|
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.
|
|
125
137
|
*/
|
|
126
|
-
function usePart(part, tag,
|
|
138
|
+
function usePart(part, tag, props, state, hold) {
|
|
139
|
+
const { render: asRender, ref: asRef, ...caller } = props;
|
|
140
|
+
const render = asRender;
|
|
141
|
+
const ref = asRef;
|
|
127
142
|
const own = useSignal(part.props);
|
|
143
|
+
const asked = isValidElement(render) ? render : void 0;
|
|
144
|
+
const theirs = asked ? refOf(asked) : void 0;
|
|
128
145
|
const held = useRef(void 0);
|
|
129
146
|
const attach = useCallback((element) => {
|
|
130
147
|
const now = held.current;
|
|
@@ -150,19 +167,95 @@ function usePart(part, tag, { render, ref, ...caller }, state) {
|
|
|
150
167
|
leaving: false
|
|
151
168
|
};
|
|
152
169
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}, [
|
|
156
|
-
|
|
157
|
-
|
|
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)),
|
|
158
184
|
ref: attach
|
|
159
185
|
};
|
|
160
|
-
if (
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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;
|
|
166
259
|
}
|
|
167
260
|
/**
|
|
168
261
|
* A text input whose text is the core's own (a combobox's, a number field's): its `value` is
|
|
@@ -203,6 +296,6 @@ function Portal({ children }) {
|
|
|
203
296
|
children
|
|
204
297
|
}), container ?? document.body);
|
|
205
298
|
}
|
|
206
|
-
export { Portal, PortalProvider, useController, useIsomorphicLayoutEffect, useMount, useOptions, useOwnText, usePart, useSignal };
|
|
299
|
+
export { PartElement, Portal, PortalProvider, component, parts, useController, useIsomorphicLayoutEffect, useMount, useOptions, useOwnText, usePart, usePositioning, useSignal };
|
|
207
300
|
|
|
208
301
|
//# sourceMappingURL=runtime.js.map
|
package/src/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/react/src/runtime.tsx"],"sourcesContent":["import { computed, mergeProps, sameProps, signal } from \"@kirana-ui/core\"\nimport type { Part, PartProps, ReadonlySignal, Signal } from \"@kirana-ui/core\"\nimport {\n cloneElement,\n createContext,\n createElement,\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 { ReactElement, ReactNode, Ref } from \"react\"\nimport { createPortal } from \"react-dom\"\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 // 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/** 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`), 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 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 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/**\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\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/** 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 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":";;;;;;AAqBA,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,Q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K;CAAO;CACjE,IAAI,OAAO,WAAW,YAAY,OAAO,OAAO,OAAO,KAAc;CACrE,IAAI,eAAe,MAAM,GACvB,OAAO,aAAa,QAAQ;EAAE,GAAG,QAAQ,WAAW,OAAO,OAAO,KAAK,CAAC;EAAG,KAAK;CAAO,CAAC;CAE1F,OAAO,cAAc,KAAK,KAAK;AACjC;;;;;;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;;;;;AAY/E,SAAgB,eAAe,EAAE,WAAW,YAA+C;CACzF,OAAO,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAAY;CAAmC,CAAA;AACzF;;AAGA,SAAgB,OAAO,EAAE,YAA2D;CAClF,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 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,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3C,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"}
|
package/src/scroll-area.d.ts
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import { Orientation } from "@kirana-ui/core";
|
|
2
|
+
import { Orientation, StateOf } from "@kirana-ui/core";
|
|
3
3
|
import { ReactElement } from "react";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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"]>, {
|
|
8
17
|
/** Which way it scrolls. Default: `vertical`. */
|
|
9
18
|
orientation?: Orientation;
|
|
10
19
|
/** In the page even while there is nothing to scroll its way. */
|
|
11
20
|
keepMounted?: boolean;
|
|
12
|
-
}
|
|
13
|
-
declare function Scrollbar({ orientation, keepMounted, ...props }: ScrollbarProps):
|
|
14
|
-
|
|
15
|
-
declare function
|
|
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;
|
|
16
27
|
export declare const ScrollArea: {
|
|
17
|
-
Root: typeof Root;
|
|
18
|
-
Viewport: typeof Viewport;
|
|
19
|
-
Content: typeof Content;
|
|
20
|
-
Scrollbar: typeof Scrollbar;
|
|
21
|
-
Thumb: typeof Thumb;
|
|
22
|
-
Corner: typeof Corner;
|
|
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;
|
|
23
34
|
};
|
|
24
35
|
export {};
|
|
25
36
|
//# sourceMappingURL=scroll-area.d.ts.map
|
package/src/scroll-area.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
|
-
import { useController, usePart, useSignal } from "./runtime.js";
|
|
2
|
+
import { PartElement, parts, useController, usePart, useSignal } from "./runtime.js";
|
|
3
3
|
import { within } from "@kirana-ui/core";
|
|
4
4
|
import { createContext, useContext } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -12,6 +12,10 @@ function useScrollArea(part) {
|
|
|
12
12
|
if (!controller) throw new Error(`<ScrollArea.${part}> must be inside <ScrollArea.Root>`);
|
|
13
13
|
return controller;
|
|
14
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
|
+
*/
|
|
15
19
|
function Root(props) {
|
|
16
20
|
const direction = useContext(DirectionContext) ?? void 0;
|
|
17
21
|
const controller = useController(within(createScrollArea, { direction }), {});
|
|
@@ -20,7 +24,6 @@ function Root(props) {
|
|
|
20
24
|
children: usePart(controller.root, "div", props)
|
|
21
25
|
});
|
|
22
26
|
}
|
|
23
|
-
const PartElement = ({ part, tag, ...props }) => usePart(part, tag, props);
|
|
24
27
|
const Viewport = (props) => usePart(useScrollArea("Viewport").viewport, "div", props);
|
|
25
28
|
const Content = (props) => usePart(useScrollArea("Content").content, "div", props);
|
|
26
29
|
function Scrollbar({ orientation = "vertical", keepMounted, ...props }) {
|
|
@@ -29,7 +32,7 @@ function Scrollbar({ orientation = "vertical", keepMounted, ...props }) {
|
|
|
29
32
|
return /* @__PURE__ */ jsx(ScrollbarContext.Provider, {
|
|
30
33
|
value: bar,
|
|
31
34
|
children: /* @__PURE__ */ jsx(PartElement, {
|
|
32
|
-
|
|
35
|
+
of: bar.part,
|
|
33
36
|
tag: "div",
|
|
34
37
|
...props
|
|
35
38
|
})
|
|
@@ -43,19 +46,19 @@ function Thumb(props) {
|
|
|
43
46
|
function Corner(props) {
|
|
44
47
|
const { corner } = useScrollArea("Corner");
|
|
45
48
|
return useSignal(corner.shown) ? /* @__PURE__ */ jsx(PartElement, {
|
|
46
|
-
|
|
49
|
+
of: corner.part,
|
|
47
50
|
tag: "div",
|
|
48
51
|
...props
|
|
49
52
|
}) : null;
|
|
50
53
|
}
|
|
51
|
-
const ScrollArea = {
|
|
54
|
+
const ScrollArea = /* @__PURE__ */ parts("ScrollArea", {
|
|
52
55
|
Root,
|
|
53
56
|
Viewport,
|
|
54
57
|
Content,
|
|
55
58
|
Scrollbar,
|
|
56
59
|
Thumb,
|
|
57
60
|
Corner
|
|
58
|
-
};
|
|
61
|
+
});
|
|
59
62
|
export { ScrollArea };
|
|
60
63
|
|
|
61
64
|
//# sourceMappingURL=scroll-area.js.map
|
package/src/scroll-area.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-area.js","names":[],"sources":["../../../../packages/react/src/scroll-area.tsx"],"sourcesContent":["import
|
|
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,74 +1,94 @@
|
|
|
1
|
-
import { PartComponentProps } from "./runtime.js";
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 & {
|
|
20
28
|
/**
|
|
21
29
|
* The list opens over its trigger, the chosen item's text on the trigger's own, where
|
|
22
30
|
* there is room and unless a finger opened it.
|
|
23
31
|
*/
|
|
24
32
|
alignItemWithTrigger?: boolean;
|
|
25
|
-
}
|
|
26
|
-
declare function Positioner({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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"]>, {
|
|
30
38
|
id?: string;
|
|
31
|
-
}
|
|
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"]>>;
|
|
32
43
|
/** A group's name. Outside a group it is plain text, and names nothing. */
|
|
33
|
-
declare function GroupLabel(props:
|
|
44
|
+
declare function GroupLabel(props: GroupLabelProps): ReactElement;
|
|
45
|
+
export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>>;
|
|
34
46
|
/** A line between groups. */
|
|
35
|
-
declare const Separator: (props:
|
|
47
|
+
declare const Separator: (props: SeparatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
48
|
+
export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
|
|
36
49
|
/** The items' own box inside the popup, when the popup also holds scroll arrows. */
|
|
37
|
-
declare const List: (props:
|
|
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"]>>;
|
|
38
53
|
/** In the page while there is more of the list above: it scrolls it while the pointer moves over it. */
|
|
39
|
-
declare function ScrollUpArrow(props:
|
|
54
|
+
declare function ScrollUpArrow(props: ScrollUpArrowProps): ReactElement | null;
|
|
40
55
|
/** In the page while there is more of the list below. */
|
|
41
|
-
declare function ScrollDownArrow(props:
|
|
42
|
-
export
|
|
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. */
|
|
43
59
|
value: unknown;
|
|
60
|
+
/** Disables this item: it cannot be chosen, and the arrows pass over it. */
|
|
44
61
|
disabled?: boolean;
|
|
45
62
|
/** What typeahead matches and the trigger shows; the item's text when left out. */
|
|
46
63
|
label?: string;
|
|
47
64
|
/** Its place among all the rows, in a virtualized list. */
|
|
48
65
|
index?: number;
|
|
49
|
-
}
|
|
66
|
+
}>;
|
|
50
67
|
declare function Item({ value, disabled, label, index, ...props }: ItemProps): ReactElement;
|
|
51
|
-
|
|
52
|
-
|
|
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. */
|
|
53
72
|
keepMounted?: boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
73
|
+
}>;
|
|
74
|
+
/** In the page while its item is the chosen one. */
|
|
75
|
+
declare function ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null;
|
|
56
76
|
export declare const Select: {
|
|
57
|
-
Root: typeof Root;
|
|
58
|
-
Trigger: typeof Trigger;
|
|
59
|
-
Value: typeof Value;
|
|
60
|
-
Portal: typeof Portal;
|
|
61
|
-
Positioner: typeof Positioner;
|
|
62
|
-
Popup: typeof Popup;
|
|
63
|
-
List: typeof List;
|
|
64
|
-
ScrollUpArrow: typeof ScrollUpArrow;
|
|
65
|
-
ScrollDownArrow: typeof ScrollDownArrow;
|
|
66
|
-
Group: typeof Group;
|
|
67
|
-
GroupLabel: typeof GroupLabel;
|
|
68
|
-
Separator: typeof Separator;
|
|
69
|
-
Item: typeof Item;
|
|
70
|
-
ItemText: typeof ItemText;
|
|
71
|
-
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;
|
|
72
92
|
};
|
|
73
|
-
export {};
|
|
93
|
+
export type { PortalProps };
|
|
74
94
|
//# sourceMappingURL=select.d.ts.map
|