@kirana-ui/react 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +140 -0
- package/llms.txt +1800 -187
- package/package.json +48 -3
- package/skills/kirana-ui-primitives/SKILL.md +53 -12
- package/src/accordion.d.ts +2 -2
- package/src/accordion.js +3 -2
- package/src/accordion.js.map +1 -1
- package/src/alert-dialog.d.ts +2 -2
- package/src/autocomplete.d.ts +2 -2
- package/src/autosize.d.ts +1 -1
- package/src/avatar.d.ts +28 -7
- package/src/avatar.js +22 -9
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +5 -2
- package/src/button.js +4 -1
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +23 -8
- package/src/calendar.js +50 -13
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +6 -3
- package/src/carousel.js +1 -1
- package/src/carousel.js.map +1 -1
- package/src/checkbox-group-context.d.ts +4 -0
- package/src/checkbox-group-context.js +7 -0
- package/src/checkbox-group-context.js.map +1 -0
- package/src/checkbox-group.d.ts +15 -0
- package/src/checkbox-group.js +30 -0
- package/src/checkbox-group.js.map +1 -0
- package/src/checkbox.d.ts +7 -2
- package/src/checkbox.js +9 -3
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +1 -1
- package/src/color-picker.d.ts +61 -0
- package/src/color-picker.js +119 -0
- package/src/color-picker.js.map +1 -0
- package/src/combobox.d.ts +54 -5
- package/src/combobox.js +49 -8
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +4 -4
- package/src/command.js +2 -1
- package/src/command.js.map +1 -1
- package/src/date-field.d.ts +2 -2
- package/src/date-field.js +3 -2
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +33 -11
- package/src/date-picker.js +22 -5
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +11 -6
- package/src/dialog.js +27 -8
- package/src/dialog.js.map +1 -1
- package/src/direction.d.ts +1 -1
- package/src/direction.js +1 -1
- package/src/editable.d.ts +32 -0
- package/src/editable.js +63 -0
- package/src/editable.js.map +1 -0
- package/src/field.d.ts +1 -1
- package/src/fieldset.d.ts +1 -1
- package/src/file-upload.d.ts +54 -0
- package/src/file-upload.js +96 -0
- package/src/file-upload.js.map +1 -0
- package/src/form.d.ts +1 -1
- package/src/hover-popup.d.ts +1 -1
- package/src/hover-popup.js +1 -1
- package/src/index.d.ts +28 -7
- package/src/index.js +12 -1
- package/src/input.d.ts +1 -1
- package/src/input.js +1 -1
- package/src/label.d.ts +1 -1
- package/src/listbox.d.ts +1 -1
- package/src/listbox.js +1 -1
- package/src/menu.d.ts +5 -5
- package/src/menu.js +14 -9
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +2 -2
- package/src/menubar.js +4 -2
- package/src/menubar.js.map +1 -1
- package/src/message-scroller.d.ts +1 -1
- package/src/navigation-menu.d.ts +5 -5
- package/src/navigation-menu.js +14 -4
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +11 -2
- package/src/number-field.js +20 -3
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +3 -2
- package/src/otp.js +10 -2
- package/src/otp.js.map +1 -1
- package/src/pagination.d.ts +1 -1
- package/src/password-input.d.ts +23 -0
- package/src/password-input.js +40 -0
- package/src/password-input.js.map +1 -0
- package/src/popover.d.ts +12 -4
- package/src/popover.js +14 -1
- package/src/popover.js.map +1 -1
- package/src/qr-code.d.ts +1 -1
- package/src/radio-group.d.ts +4 -2
- package/src/radio-group.js +6 -3
- package/src/radio-group.js.map +1 -1
- package/src/rating.d.ts +28 -0
- package/src/rating.js +59 -0
- package/src/rating.js.map +1 -0
- package/src/resizable.d.ts +1 -1
- package/src/resizable.js +1 -1
- package/src/runtime.d.ts +18 -8
- package/src/runtime.js +24 -5
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +1 -1
- package/src/scroll-area.js +1 -1
- package/src/select.d.ts +17 -6
- package/src/select.js +6 -3
- package/src/select.js.map +1 -1
- package/src/separator.d.ts +1 -1
- package/src/slider.d.ts +2 -2
- package/src/slider.js +3 -2
- package/src/slider.js.map +1 -1
- package/src/steps.d.ts +51 -0
- package/src/steps.js +69 -0
- package/src/steps.js.map +1 -0
- package/src/switch.d.ts +2 -1
- package/src/switch.js +1 -1
- package/src/switch.js.map +1 -1
- package/src/tabs.d.ts +2 -2
- package/src/tabs.js +4 -3
- package/src/tabs.js.map +1 -1
- package/src/tags-input.d.ts +47 -0
- package/src/tags-input.js +92 -0
- package/src/tags-input.js.map +1 -0
- package/src/time-field.d.ts +32 -0
- package/src/time-field.js +67 -0
- package/src/time-field.js.map +1 -0
- package/src/toast.d.ts +1 -1
- package/src/toggle-group.d.ts +2 -2
- package/src/toggle-group.js +4 -3
- package/src/toggle-group.js.map +1 -1
- package/src/toggle.d.ts +1 -1
- package/src/toggle.js +1 -1
- package/src/toolbar.d.ts +14 -6
- package/src/toolbar.js +19 -9
- package/src/toolbar.js.map +1 -1
- package/src/tour.d.ts +61 -0
- package/src/tour.js +68 -0
- package/src/tour.js.map +1 -0
- package/src/tree.d.ts +45 -0
- package/src/tree.js +93 -0
- package/src/tree.js.map +1 -0
- package/src/use-render.d.ts +1 -1
- package/src/use-render.js +1 -1
- package/src/use-render.js.map +1 -1
- package/src/value-bar.d.ts +1 -1
package/src/tour.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { Portal as Portal$1, parts, useController, usePart, usePositioning, useSignal } from "./runtime.js";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { createTour } from "@kirana-ui/core/tour";
|
|
7
|
+
// src/tour.tsx
|
|
8
|
+
const Context = createContext(null);
|
|
9
|
+
function useTour(part) {
|
|
10
|
+
const controller = useContext(Context);
|
|
11
|
+
if (!controller) throw new Error(`<Tour.${part}> must be inside <Tour.Root>`);
|
|
12
|
+
return controller;
|
|
13
|
+
}
|
|
14
|
+
function Root({ children, ...props }) {
|
|
15
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
16
|
+
const controller = useController(within(createTour, { direction }), props);
|
|
17
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
18
|
+
value: controller,
|
|
19
|
+
children
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function Portal({ children }) {
|
|
23
|
+
return useSignal(useTour("Portal").mounted) ? /* @__PURE__ */ jsx(Portal$1, { children }) : null;
|
|
24
|
+
}
|
|
25
|
+
const Spotlight = (props) => usePart(useTour("Spotlight").spotlight, "div", props);
|
|
26
|
+
function Positioner(props) {
|
|
27
|
+
const controller = useTour("Positioner");
|
|
28
|
+
return usePart(controller.positioner, "div", usePositioning(controller.positioning, props));
|
|
29
|
+
}
|
|
30
|
+
/** The step: its children, or what a function of the step shown draws. */
|
|
31
|
+
function Popup({ children, ...props }) {
|
|
32
|
+
const controller = useTour("Popup");
|
|
33
|
+
const step = useSignal(controller.shown);
|
|
34
|
+
const index = useSignal(controller.index);
|
|
35
|
+
const current = useSignal(controller.current);
|
|
36
|
+
const total = useSignal(controller.total);
|
|
37
|
+
return usePart(controller.popup, "div", {
|
|
38
|
+
...props,
|
|
39
|
+
children: typeof children === "function" ? children({
|
|
40
|
+
step,
|
|
41
|
+
index,
|
|
42
|
+
current,
|
|
43
|
+
total
|
|
44
|
+
}) : children
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const Arrow = (props) => usePart(useTour("Arrow").arrow, "div", props);
|
|
48
|
+
const Title = (props) => usePart(useTour("Title").title, "h2", props);
|
|
49
|
+
const Description = (props) => usePart(useTour("Description").description, "p", props);
|
|
50
|
+
const Previous = (props) => usePart(useTour("Previous").previous, "button", props);
|
|
51
|
+
const Next = (props) => usePart(useTour("Next").next, "button", props);
|
|
52
|
+
const Close = (props) => usePart(useTour("Close").close, "button", props);
|
|
53
|
+
const Tour = /* @__PURE__ */ parts("Tour", {
|
|
54
|
+
Root,
|
|
55
|
+
Portal,
|
|
56
|
+
Spotlight,
|
|
57
|
+
Positioner,
|
|
58
|
+
Popup,
|
|
59
|
+
Arrow,
|
|
60
|
+
Title,
|
|
61
|
+
Description,
|
|
62
|
+
Previous,
|
|
63
|
+
Next,
|
|
64
|
+
Close
|
|
65
|
+
});
|
|
66
|
+
export { Tour };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=tour.js.map
|
package/src/tour.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tour.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/tour.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createTour } from \"@kirana-ui/core/tour\"\nimport type { Tour as Controller, TourProps, TourStep } from \"@kirana-ui/core/tour\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport {\n Portal as BodyPortal,\n parts,\n useController,\n usePart,\n usePositioning,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"tour\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useTour(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Tour.${part}> must be inside <Tour.Root>`)\n return controller\n}\n\n/** `Step` is what each step is: a `TourStep` with whatever the page draws it from. */\nexport type RootProps<Step extends TourStep = TourStep> = Omit<TourProps<Step>, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Step extends TourStep = TourStep>({\n children,\n ...props\n}: RootProps<Step>): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController(within(createTour<Step>, { direction }), props)\n return <Context.Provider value={controller as Controller}>{children}</Context.Provider>\n}\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useTour(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type SpotlightProps = PartComponentProps<\"div\", StateOf<Parts[\"spotlight\"]>>\n\nconst Spotlight = (props: SpotlightProps) => usePart(useTour(\"Spotlight\").spotlight, \"div\", props)\n\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions\n>\n\nfunction Positioner(props: PositionerProps): ReactElement {\n const controller = useTour(\"Positioner\")\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\n/** What the popup's `children` is told of the step it shows, to draw it. */\nexport interface TourShownStep<Step extends TourStep = TourStep> {\n /** The step shown, as the page gave it; `undefined` while none is. */\n step: Step | undefined\n /** Its index, from 0. */\n index: number\n /** Its place, from 1: the \"2\" of \"2 of 5\". */\n current: number\n /** How many steps there are: the \"5\" of \"2 of 5\". */\n total: number\n}\n\nexport type PopupProps<Step extends TourStep = TourStep> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"popup\"]>,\n {\n /** What the popup holds, or a function given the step shown that draws it. */\n children?: ReactNode | ((shown: TourShownStep<Step>) => ReactNode)\n }\n>\n\n/** The step: its children, or what a function of the step shown draws. */\nfunction Popup<Step extends TourStep = TourStep>({\n children,\n ...props\n}: PopupProps<Step>): ReactElement {\n const controller = useTour(\"Popup\")\n const step = useSignal(controller.shown) as Step | undefined\n const index = useSignal(controller.index)\n const current = useSignal(controller.current)\n const total = useSignal(controller.total)\n return usePart(controller.popup, \"div\", {\n ...props,\n children: typeof children === \"function\" ? children({ step, index, current, total }) : children,\n })\n}\n\nexport type ArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"arrow\"]>>\nexport type TitleProps = PartComponentProps<\"h2\", StateOf<Parts[\"title\"]>>\nexport type DescriptionProps = PartComponentProps<\"p\", StateOf<Parts[\"description\"]>>\nexport type PreviousProps = PartComponentProps<\"button\", StateOf<Parts[\"previous\"]>>\nexport type NextProps = PartComponentProps<\"button\", StateOf<Parts[\"next\"]>>\nexport type CloseProps = PartComponentProps<\"button\", StateOf<Parts[\"close\"]>>\n\nconst Arrow = (props: ArrowProps) => usePart(useTour(\"Arrow\").arrow, \"div\", props)\nconst Title = (props: TitleProps) => usePart(useTour(\"Title\").title, \"h2\", props)\nconst Description = (props: DescriptionProps) =>\n usePart(useTour(\"Description\").description, \"p\", props)\nconst Previous = (props: PreviousProps) => usePart(useTour(\"Previous\").previous, \"button\", props)\nconst Next = (props: NextProps) => usePart(useTour(\"Next\").next, \"button\", props)\nconst Close = (props: CloseProps) => usePart(useTour(\"Close\").close, \"button\", props)\n\nexport const Tour = /* @__PURE__ */ parts(\"Tour\", {\n Root,\n Portal,\n Spotlight,\n Positioner,\n Popup,\n Arrow,\n Title,\n Description,\n Previous,\n Next,\n Close,\n})\n"],"mappings":";;;;;;;AAuBA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,QAAQ,MAA0B;CACzC,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,SAAS,KAAK,6BAA6B;CAC5E,OAAO;AACT;AAQA,SAAS,KAAuC,EAC9C,UACA,GAAG,SAC6B;CAChC,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cAAc,OAAO,YAAkB,EAAE,UAAU,CAAC,GAAG,KAAK;CAC/E,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAA2B;CAA2B,CAAA;AACxF;AAEA,SAAS,OAAO,EAAE,YAA8C;CAE9D,OADgB,UAAU,QAAQ,QAAQ,CAAC,CAAC,OAC/B,IAAI,oBAACA,UAAD,EAAa,SAAqB,CAAA,IAAI;AACzD;AAIA,MAAM,aAAa,UAA0B,QAAQ,QAAQ,WAAW,CAAC,CAAC,WAAW,OAAO,KAAK;AAQjG,SAAS,WAAW,OAAsC;CACxD,MAAM,aAAa,QAAQ,YAAY;CACvC,OAAO,QAAQ,WAAW,YAAY,OAAO,eAAe,WAAW,aAAa,KAAK,CAAC;AAC5F;;AAwBA,SAAS,MAAwC,EAC/C,UACA,GAAG,SAC8B;CACjC,MAAM,aAAa,QAAQ,OAAO;CAClC,MAAM,OAAO,UAAU,WAAW,KAAK;CACvC,MAAM,QAAQ,UAAU,WAAW,KAAK;CACxC,MAAM,UAAU,UAAU,WAAW,OAAO;CAC5C,MAAM,QAAQ,UAAU,WAAW,KAAK;CACxC,OAAO,QAAQ,WAAW,OAAO,OAAO;EACtC,GAAG;EACH,UAAU,OAAO,aAAa,aAAa,SAAS;GAAE;GAAM;GAAO;GAAS;EAAM,CAAC,IAAI;CACzF,CAAC;AACH;AASA,MAAM,SAAS,UAAsB,QAAQ,QAAQ,OAAO,CAAC,CAAC,OAAO,OAAO,KAAK;AACjF,MAAM,SAAS,UAAsB,QAAQ,QAAQ,OAAO,CAAC,CAAC,OAAO,MAAM,KAAK;AAChF,MAAM,eAAe,UACnB,QAAQ,QAAQ,aAAa,CAAC,CAAC,aAAa,KAAK,KAAK;AACxD,MAAM,YAAY,UAAyB,QAAQ,QAAQ,UAAU,CAAC,CAAC,UAAU,UAAU,KAAK;AAChG,MAAM,QAAQ,UAAqB,QAAQ,QAAQ,MAAM,CAAC,CAAC,MAAM,UAAU,KAAK;AAChF,MAAM,SAAS,UAAsB,QAAQ,QAAQ,OAAO,CAAC,CAAC,OAAO,UAAU,KAAK;AAEpF,MAAa,OAAuB,sBAAM,QAAQ;CAChD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/tree.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
|
+
import { TreeProps } from "@kirana-ui/core/tree";
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["tree"];
|
|
7
|
+
/** `Value` is what tells a node from the others: the type of the values' entries. */
|
|
8
|
+
export type RootProps<Value = unknown> = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<TreeProps<Value>, "id"> & {
|
|
9
|
+
id?: string;
|
|
10
|
+
}>;
|
|
11
|
+
declare function Root<Value = unknown>({ expandedValue, defaultExpandedValue, onExpandedChange, selectionMode, selectedValue, defaultSelectedValue, onSelectedChange, expandOnClick, id, ...rest }: RootProps<Value>): ReactElement;
|
|
12
|
+
export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
|
|
13
|
+
/** What tells this node from the others in the tree: what the values hold. */
|
|
14
|
+
value: unknown;
|
|
15
|
+
/** A branch: it has children, drawn in its `Tree.Group`, and opens and closes. */
|
|
16
|
+
branch?: boolean;
|
|
17
|
+
/** Disables this node: it cannot be chosen, opened or closed, and the keys pass over it. */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** A branch whose children are being loaded. */
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
/** What typing matches, when it is not the node's text. */
|
|
22
|
+
label?: string;
|
|
23
|
+
}>;
|
|
24
|
+
declare function Item({ value, branch, disabled, loading, label, ...rest }: ItemProps): ReactElement;
|
|
25
|
+
export type ItemRowProps = PartComponentProps<"div", StateOf<Parts["itemRow"]>>;
|
|
26
|
+
export type ItemIndicatorProps = PartComponentProps<"span", StateOf<Parts["itemIndicator"]>>;
|
|
27
|
+
export type ItemTextProps = PartComponentProps<"span", StateOf<Parts["itemText"]>>;
|
|
28
|
+
declare const ItemRow: (props: ItemRowProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
29
|
+
declare const ItemIndicator: (props: ItemIndicatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
30
|
+
declare const ItemText: (props: ItemTextProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
31
|
+
export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, {
|
|
32
|
+
/** Keeps the closed group in the page, `hidden`. */
|
|
33
|
+
keepMounted?: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
declare function Group({ keepMounted, ...props }: GroupProps): ReactElement | null;
|
|
36
|
+
export declare const Tree: {
|
|
37
|
+
readonly Root: typeof Root;
|
|
38
|
+
readonly Item: typeof Item;
|
|
39
|
+
readonly ItemRow: typeof ItemRow;
|
|
40
|
+
readonly ItemIndicator: typeof ItemIndicator;
|
|
41
|
+
readonly ItemText: typeof ItemText;
|
|
42
|
+
readonly Group: typeof Group;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=tree.d.ts.map
|
package/src/tree.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { PartElement, parts, useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
|
|
3
|
+
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
import { defined, within } from "@kirana-ui/core";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { createTree } from "@kirana-ui/core/tree";
|
|
7
|
+
// src/tree.tsx
|
|
8
|
+
const Context = createContext(null);
|
|
9
|
+
const ItemContext = createContext(null);
|
|
10
|
+
const LevelContext = createContext(0);
|
|
11
|
+
function useTree(part) {
|
|
12
|
+
const controller = useContext(Context);
|
|
13
|
+
if (!controller) throw new Error(`<Tree.${part}> must be inside <Tree.Root>`);
|
|
14
|
+
return controller;
|
|
15
|
+
}
|
|
16
|
+
function useItem(part) {
|
|
17
|
+
const item = useContext(ItemContext);
|
|
18
|
+
if (!item) throw new Error(`<Tree.${part}> must be inside <Tree.Item>`);
|
|
19
|
+
return item;
|
|
20
|
+
}
|
|
21
|
+
function Root({ expandedValue, defaultExpandedValue, onExpandedChange, selectionMode, selectedValue, defaultSelectedValue, onSelectedChange, expandOnClick, id, ...rest }) {
|
|
22
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
23
|
+
const create = within(createTree, { direction });
|
|
24
|
+
const controller = useController(create, {
|
|
25
|
+
expandedValue,
|
|
26
|
+
defaultExpandedValue,
|
|
27
|
+
onExpandedChange,
|
|
28
|
+
selectionMode,
|
|
29
|
+
selectedValue,
|
|
30
|
+
defaultSelectedValue,
|
|
31
|
+
onSelectedChange,
|
|
32
|
+
expandOnClick,
|
|
33
|
+
id
|
|
34
|
+
});
|
|
35
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
36
|
+
value: controller,
|
|
37
|
+
children: /* @__PURE__ */ jsx(LevelContext.Provider, {
|
|
38
|
+
value: 0,
|
|
39
|
+
children: usePart(controller.root, "div", rest)
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function Item({ value, branch, disabled, loading, label, ...rest }) {
|
|
44
|
+
const controller = useTree("Item");
|
|
45
|
+
const level = useContext(LevelContext) + 1;
|
|
46
|
+
const options = useOptions({
|
|
47
|
+
branch,
|
|
48
|
+
disabled,
|
|
49
|
+
loading,
|
|
50
|
+
label,
|
|
51
|
+
level
|
|
52
|
+
});
|
|
53
|
+
const item = useMemo(() => controller.item(value, () => defined(options.get())), [
|
|
54
|
+
controller,
|
|
55
|
+
value,
|
|
56
|
+
options
|
|
57
|
+
]);
|
|
58
|
+
useMount(item);
|
|
59
|
+
return /* @__PURE__ */ jsx(ItemContext.Provider, {
|
|
60
|
+
value: item,
|
|
61
|
+
children: /* @__PURE__ */ jsx(LevelContext.Provider, {
|
|
62
|
+
value: level,
|
|
63
|
+
children: /* @__PURE__ */ jsx(PartElement, {
|
|
64
|
+
of: item.root,
|
|
65
|
+
tag: "div",
|
|
66
|
+
...rest
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const ItemRow = (props) => usePart(useItem("ItemRow").row, "div", props);
|
|
72
|
+
const ItemIndicator = (props) => usePart(useItem("ItemIndicator").indicator, "span", props);
|
|
73
|
+
const ItemText = (props) => usePart(useItem("ItemText").text, "span", props);
|
|
74
|
+
function Group({ keepMounted, ...props }) {
|
|
75
|
+
const item = useItem("Group");
|
|
76
|
+
if (!useSignal(item.mounted) && !keepMounted) return null;
|
|
77
|
+
return /* @__PURE__ */ jsx(PartElement, {
|
|
78
|
+
of: item.group,
|
|
79
|
+
tag: "div",
|
|
80
|
+
...props
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const Tree = /* @__PURE__ */ parts("Tree", {
|
|
84
|
+
Root,
|
|
85
|
+
Item,
|
|
86
|
+
ItemRow,
|
|
87
|
+
ItemIndicator,
|
|
88
|
+
ItemText,
|
|
89
|
+
Group
|
|
90
|
+
});
|
|
91
|
+
export { Tree };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=tree.js.map
|
package/src/tree.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","names":[],"sources":["../../../../packages/react/src/tree.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createTree } from \"@kirana-ui/core/tree\"\nimport type { Tree as Controller, TreeItem, TreeProps } from \"@kirana-ui/core/tree\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport {\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"tree\"]\n\nconst Context = createContext<Controller | null>(null)\n// The node a part is inside, for its row, mark, text and group.\nconst ItemContext = createContext<TreeItem | null>(null)\n// How deep the nodes inside are: 0 at the root, so a node at the top is at level 1. Known from\n// how the parts are nested, so a server writes `aria-level` too.\nconst LevelContext = createContext(0)\n\nfunction useTree(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Tree.${part}> must be inside <Tree.Root>`)\n return controller\n}\n\nfunction useItem(part: string): TreeItem {\n const item = useContext(ItemContext)\n if (!item) throw new Error(`<Tree.${part}> must be inside <Tree.Item>`)\n return item\n}\n\n/** `Value` is what tells a node from the others: the type of the values' entries. */\nexport type RootProps<Value = unknown> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<TreeProps<Value>, \"id\"> & { id?: string }\n>\n\nfunction Root<Value = unknown>({\n expandedValue,\n defaultExpandedValue,\n onExpandedChange,\n selectionMode,\n selectedValue,\n defaultSelectedValue,\n onSelectedChange,\n expandOnClick,\n id,\n ...rest\n}: RootProps<Value>): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createTree<Value>, { direction })\n const controller: Controller = useController(create, {\n expandedValue,\n defaultExpandedValue,\n onExpandedChange,\n selectionMode,\n selectedValue,\n defaultSelectedValue,\n onSelectedChange,\n expandOnClick,\n id,\n })\n return (\n <Context.Provider value={controller as Controller<unknown>}>\n <LevelContext.Provider value={0}>\n {usePart(controller.root, \"div\", rest)}\n </LevelContext.Provider>\n </Context.Provider>\n )\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What tells this node from the others in the tree: what the values hold. */\n value: unknown\n /** A branch: it has children, drawn in its `Tree.Group`, and opens and closes. */\n branch?: boolean\n /** Disables this node: it cannot be chosen, opened or closed, and the keys pass over it. */\n disabled?: boolean\n /** A branch whose children are being loaded. */\n loading?: boolean\n /** What typing matches, when it is not the node's text. */\n label?: string\n }\n>\n\nfunction Item({ value, branch, disabled, loading, label, ...rest }: ItemProps): ReactElement {\n const controller = useTree(\"Item\")\n const level = useContext(LevelContext) + 1\n const options = useOptions({ branch, disabled, loading, label, level })\n const item = useMemo(\n () => controller.item(value, () => defined(options.get())),\n [controller, value, options]\n )\n useMount(item)\n return (\n <ItemContext.Provider value={item}>\n <LevelContext.Provider value={level}>\n <PartElement of={item.root} tag=\"div\" {...rest} />\n </LevelContext.Provider>\n </ItemContext.Provider>\n )\n}\n\nexport type ItemRowProps = PartComponentProps<\"div\", StateOf<Parts[\"itemRow\"]>>\nexport type ItemIndicatorProps = PartComponentProps<\"span\", StateOf<Parts[\"itemIndicator\"]>>\nexport type ItemTextProps = PartComponentProps<\"span\", StateOf<Parts[\"itemText\"]>>\n\nconst ItemRow = (props: ItemRowProps) => usePart(useItem(\"ItemRow\").row, \"div\", props)\nconst ItemIndicator = (props: ItemIndicatorProps) =>\n usePart(useItem(\"ItemIndicator\").indicator, \"span\", props)\nconst ItemText = (props: ItemTextProps) => usePart(useItem(\"ItemText\").text, \"span\", props)\n\nexport type GroupProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"group\"]>,\n {\n /** Keeps the closed group in the page, `hidden`. */\n keepMounted?: boolean\n }\n>\n\nfunction Group({ keepMounted, ...props }: GroupProps): ReactElement | null {\n const item = useItem(\"Group\")\n const mounted = useSignal(item.mounted)\n if (!mounted && !keepMounted) return null\n return <PartElement of={item.group} tag=\"div\" {...props} />\n}\n\nexport const Tree = /* @__PURE__ */ parts(\"Tree\", {\n Root,\n Item,\n ItemRow,\n ItemIndicator,\n ItemText,\n Group,\n})\n"],"mappings":";;;;;;;AAsBA,MAAM,UAAU,cAAiC,IAAI;AAErD,MAAM,cAAc,cAA+B,IAAI;AAGvD,MAAM,eAAe,cAAc,CAAC;AAEpC,SAAS,QAAQ,MAA0B;CACzC,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,SAAS,KAAK,6BAA6B;CAC5E,OAAO;AACT;AAEA,SAAS,QAAQ,MAAwB;CACvC,MAAM,OAAO,WAAW,WAAW;CACnC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,SAAS,KAAK,6BAA6B;CACtE,OAAO;AACT;AASA,SAAS,KAAsB,EAC7B,eACA,sBACA,kBACA,eACA,eACA,sBACA,kBACA,eACA,IACA,GAAG,QAC8B;CACjC,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,YAAmB,EAAE,UAAU,CAAC;CACtD,MAAM,aAAyB,cAAc,QAAQ;EACnD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAa,UAAd;GAAuB,OAAO;GAC3B,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;EAChB,CAAA;CACP,CAAA;AAEtB;AAmBA,SAAS,KAAK,EAAE,OAAO,QAAQ,UAAU,SAAS,OAAO,GAAG,QAAiC;CAC3F,MAAM,aAAa,QAAQ,MAAM;CACjC,MAAM,QAAQ,WAAW,YAAY,IAAI;CACzC,MAAM,UAAU,WAAW;EAAE;EAAQ;EAAU;EAAS;EAAO;CAAM,CAAC;CACtE,MAAM,OAAO,cACL,WAAW,KAAK,aAAa,QAAQ,QAAQ,IAAI,CAAC,CAAC,GACzD;EAAC;EAAY;EAAO;CAAO,CAC7B;CACA,SAAS,IAAI;CACb,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAO;EAC3B,UAAA,oBAAC,aAAa,UAAd;GAAuB,OAAO;GAC5B,UAAA,oBAAC,aAAD;IAAa,IAAI,KAAK;IAAM,KAAI;IAAM,GAAI;GAAO,CAAA;EAC5B,CAAA;CACH,CAAA;AAE1B;AAMA,MAAM,WAAW,UAAwB,QAAQ,QAAQ,SAAS,CAAC,CAAC,KAAK,OAAO,KAAK;AACrF,MAAM,iBAAiB,UACrB,QAAQ,QAAQ,eAAe,CAAC,CAAC,WAAW,QAAQ,KAAK;AAC3D,MAAM,YAAY,UAAyB,QAAQ,QAAQ,UAAU,CAAC,CAAC,MAAM,QAAQ,KAAK;AAW1F,SAAS,MAAM,EAAE,aAAa,GAAG,SAA0C;CACzE,MAAM,OAAO,QAAQ,OAAO;CAE5B,IAAI,CADY,UAAU,KAAK,OACpB,KAAK,CAAC,aAAa,OAAO;CACrC,OAAO,oBAAC,aAAD;EAAa,IAAI,KAAK;EAAO,KAAI;EAAM,GAAI;CAAQ,CAAA;AAC5D;AAEA,MAAa,OAAuB,sBAAM,QAAQ;CAChD;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/use-render.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface UseRenderOptions<State extends Record<string, unknown>> {
|
|
|
6
6
|
* What its caller asked the element to be drawn as: an element, whose own props lie over
|
|
7
7
|
* `props`, or a function given the props and the state.
|
|
8
8
|
*/
|
|
9
|
-
render?: RenderProp<State
|
|
9
|
+
render?: RenderProp<NoInfer<State>> | undefined;
|
|
10
10
|
/** The element drawn when there is no `render`: a `div` unless said. */
|
|
11
11
|
defaultTagName?: string | undefined;
|
|
12
12
|
/** The element's props: the component's own and its caller's, already merged (`mergeProps`). */
|
package/src/use-render.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { REF_IS_A_PROP, give, refOf } from "./element.js";
|
|
2
|
-
import { composeProps, mergeProps as mergeProps$1, stateAttributes } from "@kirana-ui/core";
|
|
3
2
|
import { cloneElement, createElement, isValidElement, useCallback } from "react";
|
|
3
|
+
import { composeProps, mergeProps as mergeProps$1, stateAttributes } from "@kirana-ui/core";
|
|
4
4
|
// src/use-render.tsx
|
|
5
5
|
/**
|
|
6
6
|
* Gives a plain element of one's own (a badge, a breadcrumb's link) the `render` prop a part
|
package/src/use-render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-render.js","names":["layer"],"sources":["../../../../packages/react/src/use-render.tsx"],"sourcesContent":["import { composeProps, mergeProps as layer, stateAttributes } from \"@kirana-ui/core\"\nimport { cloneElement, createElement, isValidElement, useCallback } from \"react\"\nimport type { ReactElement, Ref } from \"react\"\n\nimport { REF_IS_A_PROP, give, refOf } from \"./element.ts\"\nimport type { RenderProp } from \"./runtime.tsx\"\n\nexport type { RenderProp } from \"./runtime.tsx\"\n\n/** What `useRender` takes. */\nexport interface UseRenderOptions<State extends Record<string, unknown>> {\n /**\n * What its caller asked the element to be drawn as: an element, whose own props lie over\n * `props`, or a function given the props and the state.\n */\n render?: RenderProp<State
|
|
1
|
+
{"version":3,"file":"use-render.js","names":["layer"],"sources":["../../../../packages/react/src/use-render.tsx"],"sourcesContent":["import { composeProps, mergeProps as layer, stateAttributes } from \"@kirana-ui/core\"\nimport { cloneElement, createElement, isValidElement, useCallback } from \"react\"\nimport type { ReactElement, Ref } from \"react\"\n\nimport { REF_IS_A_PROP, give, refOf } from \"./element.ts\"\nimport type { RenderProp } from \"./runtime.tsx\"\n\nexport type { RenderProp } from \"./runtime.tsx\"\n\n/** What `useRender` takes. */\nexport interface UseRenderOptions<State extends Record<string, unknown>> {\n /**\n * What its caller asked the element to be drawn as: an element, whose own props lie over\n * `props`, or a function given the props and the state.\n */\n render?: RenderProp<NoInfer<State>> | undefined\n /** The element drawn when there is no `render`: a `div` unless said. */\n defaultTagName?: string | undefined\n /** The element's props: the component's own and its caller's, already merged (`mergeProps`). */\n props?: Record<string, unknown> | undefined\n /**\n * The component's state. A function `render` is given it, and it is written on the element\n * as `data-*` attributes, under `props`: `true` is present and empty, `false`, `null` and\n * `undefined` are absent, anything else is its text, and `isActive` is `data-is-active`.\n */\n state?: State | undefined\n /** A ref of the component's own, given the element beside `props.ref` and the `render` element's. */\n ref?: Ref<HTMLElement> | undefined\n}\n\n/**\n * Gives a plain element of one's own (a badge, a breadcrumb's link) the `render` prop a part\n * takes, by a part's rule: `props` lie under the `render` element's own props, classes join,\n * styles are merged property by property, both handlers of an event run (`props`' first), the\n * `render` element's own children are drawn when it has any, and every ref gets the element.\n */\nexport function useRender<State extends Record<string, unknown> = Record<string, never>>({\n render,\n defaultTagName = \"div\",\n props,\n state,\n ref,\n}: UseRenderOptions<State>): ReactElement {\n const asked = isValidElement(render) ? render : undefined\n const theirs = asked ? refOf(asked) : undefined\n const { ref: given, ...own } = (props ?? {}) as { ref?: Ref<HTMLElement> }\n const attach = useCallback(\n (element: HTMLElement | null) => {\n give(ref, element)\n give(given, element)\n give(theirs, element)\n },\n [ref, given, theirs]\n )\n let merged: Record<string, unknown> = state ? composeProps(stateAttributes(state), own) : own\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 merged = composeProps(merged, element)\n }\n // Only where there is a ref to give: a component that takes none would be handed one.\n const drawn = ref || given ? { ...merged, ref: attach } : merged\n if (asked) return cloneElement(asked, drawn)\n if (typeof render === \"function\") return render(drawn, state as State)\n return createElement(defaultTagName, drawn)\n}\n\n/**\n * Several sets of props as one, for a component's own props and its caller's: a later set\n * wins an attribute it gives (one it leaves `undefined` stays), classes join, styles are\n * merged property by property, and the handlers of an event run in order, until one calls\n * `event.preventKiranaHandler()`, which stops those after it.\n */\nexport function mergeProps(\n ...props: readonly (Record<string, unknown> | undefined)[]\n): Record<string, unknown> {\n let merged: Record<string, unknown> = {}\n for (const each of props) if (each) merged = layer(merged, each)\n return merged\n}\n"],"mappings":";;;;;;;;;;AAoCA,SAAgB,UAAyE,EACvF,QACA,iBAAiB,OACjB,OACA,OACA,OACwC;CACxC,MAAM,QAAQ,eAAe,MAAM,IAAI,SAAS,KAAA;CAChD,MAAM,SAAS,QAAQ,MAAM,KAAK,IAAI,KAAA;CACtC,MAAM,EAAE,KAAK,OAAO,GAAG,QAAS,SAAS,CAAC;CAC1C,MAAM,SAAS,aACZ,YAAgC;EAC/B,KAAK,KAAK,OAAO;EACjB,KAAK,OAAO,OAAO;EACnB,KAAK,QAAQ,OAAO;CACtB,GACA;EAAC;EAAK;EAAO;CAAM,CACrB;CACA,IAAI,SAAkC,QAAQ,aAAa,gBAAgB,KAAK,GAAG,GAAG,IAAI;CAC1F,IAAI,OAAO;EAGT,MAAM,EAAE,KAAK,MAAM,GAAG,YAAY,gBAAgB,MAAM,QAAQ,EAAE,GAAG,MAAM,MAAM;EACjF,SAAS,aAAa,QAAQ,OAAO;CACvC;CAEA,MAAM,QAAQ,OAAO,QAAQ;EAAE,GAAG;EAAQ,KAAK;CAAO,IAAI;CAC1D,IAAI,OAAO,OAAO,aAAa,OAAO,KAAK;CAC3C,IAAI,OAAO,WAAW,YAAY,OAAO,OAAO,OAAO,KAAc;CACrE,OAAO,cAAc,gBAAgB,KAAK;AAC5C;;;;;;;AAQA,SAAgB,WACd,GAAG,OACsB;CACzB,IAAI,SAAkC,CAAC;CACvC,KAAK,MAAM,QAAQ,OAAO,IAAI,MAAM,SAASA,aAAM,QAAQ,IAAI;CAC/D,OAAO;AACT"}
|
package/src/value-bar.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReadonlySignal } from "@kirana-ui/core";
|
|
2
1
|
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { ReadonlySignal } from "@kirana-ui/core";
|
|
3
3
|
import { ValueBar, ValueBarProps } from "@kirana-ui/core/progress";
|
|
4
4
|
/** What a value bar's written value takes of its own: what to write in its place. */
|
|
5
5
|
export interface ValueOptions {
|