@kirana-ui/vue 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 +1779 -182
- package/package.json +48 -3
- package/skills/kirana-ui-primitives/SKILL.md +53 -12
- package/src/accordion.d.ts +4 -0
- package/src/accordion.js +6 -0
- package/src/accordion.js.map +1 -1
- package/src/alert-dialog.d.ts +2 -2
- package/src/autocomplete.d.ts +2 -2
- package/src/avatar.d.ts +31 -4
- package/src/avatar.js +40 -16
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +4 -1
- package/src/button.js +4 -1
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +22 -13
- package/src/calendar.js +83 -12
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +5 -2
- package/src/carousel.js +1 -4
- package/src/carousel.js.map +1 -1
- package/src/checkbox-group-context.d.ts +5 -0
- package/src/checkbox-group-context.js +6 -0
- package/src/checkbox-group-context.js.map +1 -0
- package/src/checkbox-group.d.ts +12 -0
- package/src/checkbox-group.js +44 -0
- package/src/checkbox-group.js.map +1 -0
- package/src/checkbox.d.ts +17 -0
- package/src/checkbox.js +9 -2
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +2 -0
- package/src/color-picker.d.ts +118 -0
- package/src/color-picker.js +174 -0
- package/src/color-picker.js.map +1 -0
- package/src/combobox.d.ts +105 -5
- package/src/combobox.js +83 -12
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +2 -2
- package/src/command.js +3 -1
- package/src/command.js.map +1 -1
- package/src/date-field.d.ts +1 -1
- package/src/date-field.js +2 -0
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +39 -13
- package/src/date-picker.js +104 -51
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +41 -8
- package/src/dialog.js +44 -8
- package/src/dialog.js.map +1 -1
- package/src/drawer.d.ts +2 -2
- package/src/editable.d.ts +87 -0
- package/src/editable.js +83 -0
- package/src/editable.js.map +1 -0
- package/src/element.js +5 -5
- package/src/element.js.map +1 -1
- package/src/file-upload.d.ts +76 -0
- package/src/file-upload.js +139 -0
- package/src/file-upload.js.map +1 -0
- package/src/hover-card.d.ts +3 -0
- package/src/index.d.ts +28 -7
- package/src/index.js +12 -1
- package/src/menu.d.ts +10 -0
- package/src/menu.js +17 -6
- package/src/menu.js.map +1 -1
- package/src/menubar.js +10 -1
- package/src/menubar.js.map +1 -1
- package/src/navigation-menu.d.ts +14 -3
- package/src/navigation-menu.js +20 -2
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +33 -1
- package/src/number-field.js +98 -68
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +25 -3
- package/src/otp.js +22 -3
- package/src/otp.js.map +1 -1
- package/src/password-input.d.ts +37 -0
- package/src/password-input.js +44 -0
- package/src/password-input.js.map +1 -0
- package/src/popover.d.ts +32 -4
- package/src/popover.js +37 -5
- package/src/popover.js.map +1 -1
- package/src/radio-group.d.ts +12 -0
- package/src/radio-group.js +6 -2
- package/src/radio-group.js.map +1 -1
- package/src/rating.d.ts +34 -0
- package/src/rating.js +81 -0
- package/src/rating.js.map +1 -0
- package/src/runtime.d.ts +2 -1
- package/src/runtime.js +5 -2
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +24 -1
- package/src/select.d.ts +39 -5
- package/src/select.js +30 -9
- package/src/select.js.map +1 -1
- package/src/slider.d.ts +35 -0
- package/src/slider.js +1 -0
- package/src/slider.js.map +1 -1
- package/src/steps.d.ts +74 -0
- package/src/steps.js +84 -0
- package/src/steps.js.map +1 -0
- package/src/switch.d.ts +12 -0
- package/src/tabs.d.ts +2 -0
- package/src/tabs.js +5 -0
- package/src/tabs.js.map +1 -1
- package/src/tags-input.d.ts +69 -0
- package/src/tags-input.js +145 -0
- package/src/tags-input.js.map +1 -0
- package/src/time-field.d.ts +41 -0
- package/src/time-field.js +85 -0
- package/src/time-field.js.map +1 -0
- package/src/toast.d.ts +12 -4
- package/src/toggle-group.js +6 -0
- package/src/toggle-group.js.map +1 -1
- package/src/toolbar-context.d.ts +1 -1
- package/src/toolbar.d.ts +4 -1
- package/src/toolbar.js +17 -2
- package/src/toolbar.js.map +1 -1
- package/src/tooltip.d.ts +5 -0
- package/src/tour.d.ts +75 -0
- package/src/tour.js +95 -0
- package/src/tour.js.map +1 -0
- package/src/tree.d.ts +69 -0
- package/src/tree.js +118 -0
- package/src/tree.js.map +1 -0
package/src/toolbar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","names":[],"sources":["../../../../packages/vue/src/toolbar.ts"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { Orientation } from \"@kirana-ui/core\"\nimport { createToolbar } from \"@kirana-ui/core/toolbar\"\nimport type {\n Toolbar as Controller,\n ToolbarItemOptions,\n ToolbarProps,\n} from \"@kirana-ui/core/toolbar\"\nimport { defineComponent, h, inject, provide } from \"vue\"\nimport type { PropType } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { controller, optional, partComponent, toSignal } from \"./runtime.ts\"\nimport type { PartComponent, PartComponentProps, StatesOf } from \"./runtime.ts\"\nimport { TOGGLE_GROUP, TOOLBAR } from \"./toolbar-context.ts\"\n\ntype State = StatesOf<\"toolbar\">\n\nfunction useToolbar(): Controller {\n const made = inject(TOOLBAR, null)\n if (!made) throw new Error(\"A Toolbar part must be inside <Toolbar.Root>\")\n return made\n}\n\nexport interface RootProps extends ToolbarProps, PartComponentProps {}\n\nconst Root = defineComponent({\n name: \"ToolbarRoot\",\n inheritAttrs: false,\n props: {\n orientation: String as PropType<Orientation>,\n loop: optional(Boolean),\n disabled: Boolean,\n },\n setup(props, { attrs, slots }) {\n const direction = useDirectionAround()\n const made = controller(within(createToolbar, { direction }), () => ({\n orientation: props.orientation,\n loop: props.loop,\n disabled: props.disabled,\n }))\n provide(TOOLBAR, made)\n // A toggle group around the toolbar is not the group of the toolbar's toggles.\n provide(TOGGLE_GROUP, null)\n const Element = partComponent(\"ToolbarRootElement\", \"div\", () => made.root)\n return () => h(Element, attrs, slots)\n },\n}) as unknown as PartComponent<\"div\", State[\"root\"], RootProps>\n\nexport interface ButtonProps extends ToolbarItemOptions, PartComponentProps {}\nexport type InputProps = ButtonProps\nexport type GroupProps = ButtonProps\nexport type LinkProps = PartComponentProps\nexport type SeparatorProps = PartComponentProps\n\nconst item = <Item extends \"button\" | \"input\" | \"group\", Tag extends string>(\n name: Item,\n label: string,\n tag: Tag\n) =>\n defineComponent({\n name: `Toolbar${label}`,\n inheritAttrs: false,\n props: {
|
|
1
|
+
{"version":3,"file":"toolbar.js","names":[],"sources":["../../../../packages/vue/src/toolbar.ts"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { Orientation } from \"@kirana-ui/core\"\nimport { createToolbar } from \"@kirana-ui/core/toolbar\"\nimport type {\n Toolbar as Controller,\n ToolbarItemOptions,\n ToolbarProps,\n} from \"@kirana-ui/core/toolbar\"\nimport { defineComponent, h, inject, provide } from \"vue\"\nimport type { PropType } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { controller, optional, partComponent, toSignal } from \"./runtime.ts\"\nimport type { PartComponent, PartComponentProps, StatesOf } from \"./runtime.ts\"\nimport { TOGGLE_GROUP, TOOLBAR } from \"./toolbar-context.ts\"\n\ntype State = StatesOf<\"toolbar\">\n\nfunction useToolbar(): Controller {\n const made = inject(TOOLBAR, null)\n if (!made) throw new Error(\"A Toolbar part must be inside <Toolbar.Root>\")\n return made\n}\n\nexport interface RootProps extends ToolbarProps, PartComponentProps {}\n\nconst Root = defineComponent({\n name: \"ToolbarRoot\",\n inheritAttrs: false,\n props: {\n orientation: String as PropType<Orientation>,\n loopFocus: optional(Boolean),\n /**\n * Whether the arrows wrap from the last item to the first.\n * @deprecated Base UI's name is `loopFocus`, which wins when both are given.\n */\n loop: optional(Boolean),\n disabled: Boolean,\n },\n setup(props, { attrs, slots }) {\n const direction = useDirectionAround()\n const made = controller(within(createToolbar, { direction }), () => ({\n orientation: props.orientation,\n loop: props.loop,\n loopFocus: props.loopFocus,\n disabled: props.disabled,\n }))\n provide(TOOLBAR, made)\n // A toggle group around the toolbar is not the group of the toolbar's toggles.\n provide(TOGGLE_GROUP, null)\n const Element = partComponent(\"ToolbarRootElement\", \"div\", () => made.root)\n return () => h(Element, attrs, slots)\n },\n}) as unknown as PartComponent<\"div\", State[\"root\"], RootProps>\n\n/** `focusable-when-disabled` keeps it focusable while disabled, as Base UI's. Default `true`. */\nexport interface ButtonProps extends ToolbarItemOptions, PartComponentProps {}\nexport type InputProps = ButtonProps\nexport type GroupProps = Omit<ButtonProps, \"focusableWhenDisabled\">\nexport type LinkProps = PartComponentProps\nexport type SeparatorProps = PartComponentProps\n\nconst item = <Item extends \"button\" | \"input\" | \"group\", Tag extends string>(\n name: Item,\n label: string,\n tag: Tag\n) =>\n defineComponent({\n name: `Toolbar${label}`,\n inheritAttrs: false,\n props: {\n disabled: optional(Boolean),\n // Absent is `undefined`, which the core reads as Base UI's default, `true`.\n focusableWhenDisabled: { type: Boolean, default: undefined as unknown },\n },\n setup(props, { attrs, slots }) {\n const options = toSignal(() => ({\n disabled: props.disabled,\n focusableWhenDisabled: props.focusableWhenDisabled as boolean | undefined,\n }))\n const part = useToolbar()[name](() => defined(options.get()))\n const Element = partComponent<string>(`Toolbar${label}Element`, tag, () => part)\n return () => h(Element, attrs, slots)\n },\n }) as unknown as PartComponent<Tag, State[Item], ButtonProps>\n\nexport const Toolbar = {\n Root,\n Button: item(\"button\", \"Button\", \"button\"),\n Link: partComponent<\"a\", State[\"link\"]>(\"ToolbarLink\", \"a\", () => useToolbar().link()),\n Input: item(\"input\", \"Input\", \"input\"),\n Group: item(\"group\", \"Group\", \"div\"),\n Separator: partComponent<\"div\", State[\"separator\"]>(\n \"ToolbarSeparator\",\n \"div\",\n () => useToolbar().separator\n ),\n}\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CAAC;CACrF,OAAO,KAAK,SAAS,SAAS,OAAO;CACrC,OAAO,KAAK,SAAS,SAAS,KAAK;CACnC,WAAW,cACT,oBACA,aACM,WAAW,CAAC,CAAC,SACrB;AACF"}
|
package/src/tooltip.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const Tooltip: {
|
|
|
5
5
|
Root: PlainComponent<RootProps, RootEmits>;
|
|
6
6
|
Trigger: PartComponent<"button", {
|
|
7
7
|
readonly popupOpen?: true | undefined;
|
|
8
|
+
readonly triggerDisabled?: true | undefined;
|
|
8
9
|
}, TriggerProps>;
|
|
9
10
|
Portal: PlainComponent<PortalProps, {}, {}>;
|
|
10
11
|
Positioner: PartComponent<"div", {
|
|
@@ -12,6 +13,7 @@ export declare const Tooltip: {
|
|
|
12
13
|
readonly closed?: true | undefined;
|
|
13
14
|
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "right" | "top" | undefined;
|
|
14
15
|
readonly align?: "center" | "end" | "start" | undefined;
|
|
16
|
+
readonly anchorHidden?: true | undefined;
|
|
15
17
|
}, PositionerProps>;
|
|
16
18
|
Popup: PartComponent<"div", {
|
|
17
19
|
readonly open?: true | undefined;
|
|
@@ -23,8 +25,11 @@ export declare const Tooltip: {
|
|
|
23
25
|
readonly instant?: "delay" | "dismiss" | "focus" | undefined;
|
|
24
26
|
}, PartComponentProps, {}, unknown>;
|
|
25
27
|
Arrow: PartComponent<"div", {
|
|
28
|
+
readonly open?: true | undefined;
|
|
29
|
+
readonly closed?: true | undefined;
|
|
26
30
|
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "right" | "top" | undefined;
|
|
27
31
|
readonly align?: "center" | "end" | "start" | undefined;
|
|
32
|
+
readonly instant?: "delay" | "dismiss" | "focus" | undefined;
|
|
28
33
|
readonly uncentered?: true | undefined;
|
|
29
34
|
}, PartComponentProps, {}, unknown>;
|
|
30
35
|
};
|
package/src/tour.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Changes, Listeners, PartComponent, PartComponentProps, PlainComponent, PlainInstance, PortalProps } from "./runtime.js";
|
|
2
|
+
import { PositionerProps } from "./popover.js";
|
|
3
|
+
import { PublicProps } from "vue";
|
|
4
|
+
import { TourProps, TourStep } from "@kirana-ui/core/tour";
|
|
5
|
+
/** `Step` is what each step is: a `TourStep` with whatever the page draws it from. */
|
|
6
|
+
export type RootProps<Step extends TourStep = TourStep> = Omit<TourProps<Step>, "id" | "onOpenChange" | "onStepChange"> & {
|
|
7
|
+
id?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
export type RootEmits = Changes<"open", boolean> & Changes<"step", number>;
|
|
10
|
+
/** What the popup's slot is told of the step it shows, beside its state, to draw it. */
|
|
11
|
+
export interface TourShownStep<Step extends TourStep = TourStep> {
|
|
12
|
+
/** The step shown, as the page gave it; `undefined` while none is. */
|
|
13
|
+
step: Step | undefined;
|
|
14
|
+
/** Its index, from 0. */
|
|
15
|
+
index: number;
|
|
16
|
+
/** Its place, from 1: the "2" of "2 of 5". */
|
|
17
|
+
current: number;
|
|
18
|
+
/** How many steps there are: the "5" of "2 of 5". */
|
|
19
|
+
total: number;
|
|
20
|
+
}
|
|
21
|
+
export type SpotlightProps = PartComponentProps;
|
|
22
|
+
export type PopupProps = PartComponentProps;
|
|
23
|
+
export type ArrowProps = PartComponentProps;
|
|
24
|
+
export type TitleProps = PartComponentProps;
|
|
25
|
+
export type DescriptionProps = PartComponentProps;
|
|
26
|
+
export type PreviousProps = PartComponentProps;
|
|
27
|
+
export type NextProps = PartComponentProps;
|
|
28
|
+
export type CloseProps = PartComponentProps;
|
|
29
|
+
export declare const Tour: {
|
|
30
|
+
Root: new <Step extends TourStep = TourStep>(props: RootProps<Step> & Listeners<RootEmits> & PublicProps) => PlainInstance<RootProps<Step>, RootEmits, {}>;
|
|
31
|
+
Portal: PlainComponent<PortalProps, {}, {}>;
|
|
32
|
+
Spotlight: PartComponent<"div", {
|
|
33
|
+
readonly open?: true | undefined;
|
|
34
|
+
readonly closed?: true | undefined;
|
|
35
|
+
readonly startingStyle?: true | undefined;
|
|
36
|
+
readonly endingStyle?: true | undefined;
|
|
37
|
+
readonly centered?: true | undefined;
|
|
38
|
+
}, PartComponentProps, {}, unknown>;
|
|
39
|
+
Positioner: PartComponent<"div", {
|
|
40
|
+
readonly open?: true | undefined;
|
|
41
|
+
readonly closed?: true | undefined;
|
|
42
|
+
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "right" | "top" | undefined;
|
|
43
|
+
readonly align?: "center" | "end" | "start" | undefined;
|
|
44
|
+
readonly centered?: true | undefined;
|
|
45
|
+
readonly anchorHidden?: true | undefined;
|
|
46
|
+
}, PositionerProps>;
|
|
47
|
+
Popup: PartComponent<"div", {
|
|
48
|
+
readonly open?: true | undefined;
|
|
49
|
+
readonly closed?: true | undefined;
|
|
50
|
+
readonly startingStyle?: true | undefined;
|
|
51
|
+
readonly endingStyle?: true | undefined;
|
|
52
|
+
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "right" | "top" | undefined;
|
|
53
|
+
readonly align?: "center" | "end" | "start" | undefined;
|
|
54
|
+
readonly centered?: true | undefined;
|
|
55
|
+
}, PartComponentProps, {}, TourShownStep<TourStep>>;
|
|
56
|
+
Arrow: PartComponent<"div", {
|
|
57
|
+
readonly open?: true | undefined;
|
|
58
|
+
readonly closed?: true | undefined;
|
|
59
|
+
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "right" | "top" | undefined;
|
|
60
|
+
readonly align?: "center" | "end" | "start" | undefined;
|
|
61
|
+
readonly centered?: true | undefined;
|
|
62
|
+
readonly uncentered?: true | undefined;
|
|
63
|
+
}, PartComponentProps, {}, unknown>;
|
|
64
|
+
Title: PartComponent<"h2", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
65
|
+
Description: PartComponent<"p", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
66
|
+
Previous: PartComponent<"button", {
|
|
67
|
+
readonly disabled?: true | undefined;
|
|
68
|
+
}, PartComponentProps, {}, unknown>;
|
|
69
|
+
Next: PartComponent<"button", {
|
|
70
|
+
readonly last?: true | undefined;
|
|
71
|
+
}, PartComponentProps, {}, unknown>;
|
|
72
|
+
Close: PartComponent<"button", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
73
|
+
};
|
|
74
|
+
export type { PortalProps, PositionerProps };
|
|
75
|
+
//# sourceMappingURL=tour.d.ts.map
|
package/src/tour.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useDirectionAround } from "./direction-context.js";
|
|
2
|
+
import { positionerComponent } from "./popover.js";
|
|
3
|
+
import { context, controller, fromSignal, optional, partComponent, portalComponent } from "./runtime.js";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { defineComponent, h, useId } from "vue";
|
|
6
|
+
import { createTour } from "@kirana-ui/core/tour";
|
|
7
|
+
// src/tour.ts
|
|
8
|
+
const scope = context("Tour");
|
|
9
|
+
/** `v-model:open` and `v-model:step`, or each with its `@…-change="(value, details) => …"`. */
|
|
10
|
+
const Root = defineComponent({
|
|
11
|
+
name: "TourRoot",
|
|
12
|
+
props: {
|
|
13
|
+
steps: {
|
|
14
|
+
type: Array,
|
|
15
|
+
required: true
|
|
16
|
+
},
|
|
17
|
+
open: optional(Boolean),
|
|
18
|
+
defaultOpen: Boolean,
|
|
19
|
+
step: optional(Number),
|
|
20
|
+
defaultStep: Number,
|
|
21
|
+
waitForTarget: Number,
|
|
22
|
+
spotlightPadding: Number,
|
|
23
|
+
closeOnOutsidePress: Boolean,
|
|
24
|
+
interactive: Boolean,
|
|
25
|
+
keyboardNavigation: optional(Boolean),
|
|
26
|
+
id: String
|
|
27
|
+
},
|
|
28
|
+
emits: [
|
|
29
|
+
"update:open",
|
|
30
|
+
"openChange",
|
|
31
|
+
"update:step",
|
|
32
|
+
"stepChange"
|
|
33
|
+
],
|
|
34
|
+
setup(props, { slots, emit }) {
|
|
35
|
+
const generated = useId();
|
|
36
|
+
scope.provide(controller(within(createTour, { direction: useDirectionAround() }), () => ({
|
|
37
|
+
id: props.id ?? generated,
|
|
38
|
+
steps: props.steps,
|
|
39
|
+
open: props.open,
|
|
40
|
+
defaultOpen: props.defaultOpen,
|
|
41
|
+
step: props.step,
|
|
42
|
+
defaultStep: props.defaultStep,
|
|
43
|
+
waitForTarget: props.waitForTarget,
|
|
44
|
+
spotlightPadding: props.spotlightPadding,
|
|
45
|
+
closeOnOutsidePress: props.closeOnOutsidePress,
|
|
46
|
+
interactive: props.interactive,
|
|
47
|
+
keyboardNavigation: props.keyboardNavigation,
|
|
48
|
+
onOpenChange(open, details) {
|
|
49
|
+
emit("openChange", open, details);
|
|
50
|
+
if (!details.canceled) emit("update:open", open);
|
|
51
|
+
},
|
|
52
|
+
onStepChange(step, details) {
|
|
53
|
+
emit("stepChange", step, details);
|
|
54
|
+
if (!details.canceled) emit("update:step", step);
|
|
55
|
+
}
|
|
56
|
+
})));
|
|
57
|
+
return () => slots.default?.();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const PopupElement = partComponent("TourPopupElement", "div", () => scope.use().popup);
|
|
61
|
+
/** The step, drawn by its slot (`v-slot="{ step, index, current, total }"`). */
|
|
62
|
+
const Popup = defineComponent({
|
|
63
|
+
name: "TourPopup",
|
|
64
|
+
inheritAttrs: false,
|
|
65
|
+
setup(_props, { attrs, slots }) {
|
|
66
|
+
const made = scope.use();
|
|
67
|
+
const step = fromSignal(made.shown);
|
|
68
|
+
const index = fromSignal(made.index);
|
|
69
|
+
const current = fromSignal(made.current);
|
|
70
|
+
const total = fromSignal(made.total);
|
|
71
|
+
return () => h(PopupElement, attrs, { default: (given) => slots.default?.({
|
|
72
|
+
...given,
|
|
73
|
+
step: step.value,
|
|
74
|
+
index: index.value,
|
|
75
|
+
current: current.value,
|
|
76
|
+
total: total.value
|
|
77
|
+
}) });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const Tour = {
|
|
81
|
+
Root,
|
|
82
|
+
Portal: portalComponent("TourPortal", () => scope.use().mounted),
|
|
83
|
+
Spotlight: partComponent("TourSpotlight", "div", () => scope.use().spotlight),
|
|
84
|
+
Positioner: positionerComponent("TourPositioner", () => scope.use(), partComponent("TourPositionerElement", "div", () => scope.use().positioner)),
|
|
85
|
+
Popup,
|
|
86
|
+
Arrow: partComponent("TourArrow", "div", () => scope.use().arrow),
|
|
87
|
+
Title: partComponent("TourTitle", "h2", () => scope.use().title),
|
|
88
|
+
Description: partComponent("TourDescription", "p", () => scope.use().description),
|
|
89
|
+
Previous: partComponent("TourPrevious", "button", () => scope.use().previous),
|
|
90
|
+
Next: partComponent("TourNext", "button", () => scope.use().next),
|
|
91
|
+
Close: partComponent("TourClose", "button", () => scope.use().close)
|
|
92
|
+
};
|
|
93
|
+
export { Tour };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=tour.js.map
|
package/src/tour.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tour.js","names":[],"sources":["../../../../packages/vue/src/tour.ts"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { ChangeDetails } from \"@kirana-ui/core\"\nimport { createTour } from \"@kirana-ui/core/tour\"\nimport type { Tour as Controller, TourProps, TourStep } from \"@kirana-ui/core/tour\"\nimport { defineComponent, h, useId } from \"vue\"\nimport type { PropType, PublicProps } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { positionerComponent } from \"./popover.ts\"\nimport {\n context,\n controller,\n fromSignal,\n optional,\n partComponent,\n portalComponent,\n} from \"./runtime.ts\"\nimport type {\n Changes,\n Listeners,\n PartComponent,\n PartComponentProps,\n PlainInstance,\n StatesOf,\n} from \"./runtime.ts\"\n\nexport type { PortalProps, PositionerProps } from \"./popover.ts\"\n\ntype State = StatesOf<\"tour\">\n\nconst scope = context<Controller>(\"Tour\")\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<\n TourProps<Step>,\n \"id\" | \"onOpenChange\" | \"onStepChange\"\n> & { id?: string | undefined }\n\nexport type RootEmits = Changes<\"open\", boolean> & Changes<\"step\", number>\n\n/** `v-model:open` and `v-model:step`, or each with its `@…-change=\"(value, details) => …\"`. */\nconst Root = defineComponent({\n name: \"TourRoot\",\n props: {\n steps: { type: Array as PropType<readonly TourStep[]>, required: true },\n open: optional(Boolean),\n defaultOpen: Boolean,\n step: optional(Number),\n defaultStep: Number,\n waitForTarget: Number,\n spotlightPadding: Number,\n closeOnOutsidePress: Boolean,\n interactive: Boolean,\n keyboardNavigation: optional(Boolean),\n id: String,\n },\n emits: [\"update:open\", \"openChange\", \"update:step\", \"stepChange\"],\n setup(props, { slots, emit }) {\n const generated = useId()\n scope.provide(\n controller(within(createTour, { direction: useDirectionAround() }), () => ({\n id: props.id ?? generated,\n steps: props.steps,\n open: props.open,\n defaultOpen: props.defaultOpen,\n step: props.step,\n defaultStep: props.defaultStep,\n waitForTarget: props.waitForTarget,\n spotlightPadding: props.spotlightPadding,\n closeOnOutsidePress: props.closeOnOutsidePress,\n interactive: props.interactive,\n keyboardNavigation: props.keyboardNavigation,\n onOpenChange(open: boolean, details: ChangeDetails) {\n emit(\"openChange\", open, details)\n if (!details.canceled) emit(\"update:open\", open)\n },\n onStepChange(step: number, details: ChangeDetails) {\n emit(\"stepChange\", step, details)\n if (!details.canceled) emit(\"update:step\", step)\n },\n }))\n )\n return () => slots.default?.()\n },\n}) as unknown as new <Step extends TourStep = TourStep>(\n props: RootProps<Step> & Listeners<RootEmits> & PublicProps\n) => PlainInstance<RootProps<Step>, RootEmits, {}>\n\n/** What the popup's slot is told of the step it shows, beside its state, 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\nconst PopupElement = partComponent(\"TourPopupElement\", \"div\", () => scope.use().popup)\n\n/** The step, drawn by its slot (`v-slot=\"{ step, index, current, total }\"`). */\nconst Popup = defineComponent({\n name: \"TourPopup\",\n inheritAttrs: false,\n setup(_props, { attrs, slots }) {\n const made = scope.use()\n const step = fromSignal(made.shown)\n const index = fromSignal(made.index)\n const current = fromSignal(made.current)\n const total = fromSignal(made.total)\n return () =>\n h(PopupElement, attrs, {\n default: (given: object) =>\n slots.default?.({\n ...given,\n step: step.value,\n index: index.value,\n current: current.value,\n total: total.value,\n }),\n })\n },\n}) as unknown as PartComponent<\"div\", State[\"popup\"], PartComponentProps, {}, TourShownStep>\n\nexport type SpotlightProps = PartComponentProps\nexport type PopupProps = PartComponentProps\nexport type ArrowProps = PartComponentProps\nexport type TitleProps = PartComponentProps\nexport type DescriptionProps = PartComponentProps\nexport type PreviousProps = PartComponentProps\nexport type NextProps = PartComponentProps\nexport type CloseProps = PartComponentProps\nexport const Tour = {\n Root,\n Portal: portalComponent(\"TourPortal\", () => scope.use().mounted),\n Spotlight: partComponent<\"div\", State[\"spotlight\"]>(\n \"TourSpotlight\",\n \"div\",\n () => scope.use().spotlight\n ),\n Positioner: positionerComponent<State[\"positioner\"]>(\n \"TourPositioner\",\n () => scope.use(),\n partComponent(\"TourPositionerElement\", \"div\", () => scope.use().positioner)\n ),\n Popup,\n Arrow: partComponent<\"div\", State[\"arrow\"]>(\"TourArrow\", \"div\", () => scope.use().arrow),\n Title: partComponent<\"h2\", State[\"title\"]>(\"TourTitle\", \"h2\", () => scope.use().title),\n Description: partComponent<\"p\", State[\"description\"]>(\n \"TourDescription\",\n \"p\",\n () => scope.use().description\n ),\n Previous: partComponent<\"button\", State[\"previous\"]>(\n \"TourPrevious\",\n \"button\",\n () => scope.use().previous\n ),\n Next: partComponent<\"button\", State[\"next\"]>(\"TourNext\", \"button\", () => scope.use().next),\n Close: partComponent<\"button\", State[\"close\"]>(\"TourClose\", \"button\", () => scope.use().close),\n}\n"],"mapp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AAK;EACnC,MAAM,UAAU,WAAW,KAAK,OAAO;EACvC,MAAM,QAAQ,WAAW,KAAK,KAAK;EACnC,aACE,EAAE,cAAc,OAAO,EACrB,UAAU,UACR,MAAM,UAAU;GACd,GAAG;GACH,MAAM,KAAK;GACX,OAAO,MAAM;GACb,SAAS,QAAQ;GACjB,OAAO,MAAM;EACf,CAAC,EACL,CAAC;CACL;AACF,CAAC;AAUD,MAAa,OAAO;CAClB;CACA,QAAQ,gBAAgB,oBAAoB,MAAM,IAAI,CAAC,CAAC,OAAO;CAC/D,WAAW,cACT,iBACA,aACM,MAAM,IAAI,CAAC,CAAC,SACpB;CACA,YAAY,oBACV,wBACM,MAAM,IAAI,GAChB,cAAc,yBAAyB,aAAa,MAAM,IAAI,CAAC,CAAC,UAAU,CAC5E;CACA;CACA,OAAO,cAAqC,aAAa,aAAa,MAAM,IAAI,CAAC,CAAC,KAAK;CACvF,OAAO,cAAoC,aAAa,YAAY,MAAM,IAAI,CAAC,CAAC,KAAK;CACrF,aAAa,cACX,mBACA,WACM,MAAM,IAAI,CAAC,CAAC,WACpB;CACA,UAAU,cACR,gBACA,gBACM,MAAM,IAAI,CAAC,CAAC,QACpB;CACA,MAAM,cAAuC,YAAY,gBAAgB,MAAM,IAAI,CAAC,CAAC,IAAI;CACzF,OAAO,cAAwC,aAAa,gBAAgB,MAAM,IAAI,CAAC,CAAC,KAAK;AAC/F"}
|
package/src/tree.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { PartComponent, PartComponentProps, PartGiven, PartInstance, StatesOf } from "./runtime.js";
|
|
2
|
+
import { ChangeDetails } from "@kirana-ui/core";
|
|
3
|
+
import { PublicProps } from "vue";
|
|
4
|
+
import { TreeProps } from "@kirana-ui/core/tree";
|
|
5
|
+
type State = StatesOf<"tree">;
|
|
6
|
+
/** `Value` is what tells a node from the others: the type of the values' entries. */
|
|
7
|
+
export type RootProps<Value = unknown> = Omit<TreeProps<Value>, "id" | "onExpandedChange" | "onSelectedChange"> & {
|
|
8
|
+
id?: string | undefined;
|
|
9
|
+
} & PartComponentProps;
|
|
10
|
+
export type RootEmits<Value = unknown> = {
|
|
11
|
+
"update:expandedValue": (value: Value[]) => void;
|
|
12
|
+
expandedChange: (value: Value[], details: ChangeDetails) => void;
|
|
13
|
+
"update:selectedValue": (value: Value[]) => void;
|
|
14
|
+
selectedChange: (value: Value[], details: ChangeDetails) => void;
|
|
15
|
+
};
|
|
16
|
+
export interface ItemProps extends PartComponentProps {
|
|
17
|
+
/** What tells this node from the others in the tree: what the values hold. */
|
|
18
|
+
value: unknown;
|
|
19
|
+
/** A branch: it has children, drawn in its `Tree.Group`, and opens and closes. */
|
|
20
|
+
branch?: boolean | undefined;
|
|
21
|
+
/** Disables this node: it cannot be chosen, opened or closed, and the keys pass over it. */
|
|
22
|
+
disabled?: boolean | undefined;
|
|
23
|
+
/** A branch whose children are being loaded. */
|
|
24
|
+
loading?: boolean | undefined;
|
|
25
|
+
/** What typing matches, when it is not the node's text. */
|
|
26
|
+
label?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface GroupProps extends PartComponentProps {
|
|
29
|
+
/** Keeps the closed group in the page, `hidden`. */
|
|
30
|
+
keepMounted?: boolean | undefined;
|
|
31
|
+
}
|
|
32
|
+
export type ItemRowProps = PartComponentProps;
|
|
33
|
+
export type ItemIndicatorProps = PartComponentProps;
|
|
34
|
+
export type ItemTextProps = PartComponentProps;
|
|
35
|
+
export declare const Tree: {
|
|
36
|
+
Root: new <Value = unknown, As extends string = "div">(props: PartGiven<As, RootProps<Value>, RootEmits<Value>> & PublicProps) => PartInstance<As, RootProps<Value>, RootEmits<Value>, {
|
|
37
|
+
state: State["root"];
|
|
38
|
+
}>;
|
|
39
|
+
Item: PartComponent<"div", {
|
|
40
|
+
readonly selected?: true | undefined;
|
|
41
|
+
readonly highlighted?: true | undefined;
|
|
42
|
+
readonly disabled?: true | undefined;
|
|
43
|
+
readonly open?: true | undefined;
|
|
44
|
+
readonly closed?: true | undefined;
|
|
45
|
+
readonly loading?: true | undefined;
|
|
46
|
+
}, ItemProps>;
|
|
47
|
+
ItemRow: PartComponent<"div", {
|
|
48
|
+
readonly selected?: true | undefined;
|
|
49
|
+
readonly highlighted?: true | undefined;
|
|
50
|
+
readonly disabled?: true | undefined;
|
|
51
|
+
readonly open?: true | undefined;
|
|
52
|
+
readonly closed?: true | undefined;
|
|
53
|
+
readonly loading?: true | undefined;
|
|
54
|
+
}, PartComponentProps, {}, unknown>;
|
|
55
|
+
ItemIndicator: PartComponent<"span", {
|
|
56
|
+
readonly open?: true | undefined;
|
|
57
|
+
readonly closed?: true | undefined;
|
|
58
|
+
readonly loading?: true | undefined;
|
|
59
|
+
}, PartComponentProps, {}, unknown>;
|
|
60
|
+
ItemText: PartComponent<"span", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
61
|
+
Group: PartComponent<"div", {
|
|
62
|
+
readonly open?: true | undefined;
|
|
63
|
+
readonly closed?: true | undefined;
|
|
64
|
+
readonly startingStyle?: true | undefined;
|
|
65
|
+
readonly endingStyle?: true | undefined;
|
|
66
|
+
}, GroupProps>;
|
|
67
|
+
};
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=tree.d.ts.map
|
package/src/tree.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useDirectionAround } from "./direction-context.js";
|
|
2
|
+
import { context, controller, fromSignal, optional, partComponent, toSignal } from "./runtime.js";
|
|
3
|
+
import { defined, within } from "@kirana-ui/core";
|
|
4
|
+
import { defineComponent, h, inject, onBeforeUnmount, onMounted, provide, useId } from "vue";
|
|
5
|
+
import { createTree } from "@kirana-ui/core/tree";
|
|
6
|
+
// src/tree.ts
|
|
7
|
+
const scope = context("Tree");
|
|
8
|
+
const ITEM = Symbol("TreeItem");
|
|
9
|
+
const LEVEL = Symbol("TreeLevel");
|
|
10
|
+
const ANY = null;
|
|
11
|
+
function useItem() {
|
|
12
|
+
const item = inject(ITEM, void 0);
|
|
13
|
+
if (!item) throw new Error("A Tree part must be inside <Tree.Item>");
|
|
14
|
+
return item;
|
|
15
|
+
}
|
|
16
|
+
const RootElement = partComponent("TreeRootElement", "div", () => scope.use().root);
|
|
17
|
+
/**
|
|
18
|
+
* `v-model:expanded-value` and `v-model:selected-value`, or each with its
|
|
19
|
+
* `@expanded-change` / `@selected-change="(value, details) => …"`.
|
|
20
|
+
*/
|
|
21
|
+
const Root = defineComponent({
|
|
22
|
+
name: "TreeRoot",
|
|
23
|
+
inheritAttrs: false,
|
|
24
|
+
props: {
|
|
25
|
+
expandedValue: optional(Array),
|
|
26
|
+
defaultExpandedValue: Array,
|
|
27
|
+
selectionMode: String,
|
|
28
|
+
selectedValue: optional(Array),
|
|
29
|
+
defaultSelectedValue: Array,
|
|
30
|
+
expandOnClick: optional(Boolean),
|
|
31
|
+
id: String
|
|
32
|
+
},
|
|
33
|
+
emits: [
|
|
34
|
+
"update:expandedValue",
|
|
35
|
+
"expandedChange",
|
|
36
|
+
"update:selectedValue",
|
|
37
|
+
"selectedChange"
|
|
38
|
+
],
|
|
39
|
+
setup(props, { attrs, slots, emit }) {
|
|
40
|
+
const generated = useId();
|
|
41
|
+
scope.provide(controller(within(createTree, { direction: useDirectionAround() }), () => ({
|
|
42
|
+
id: props.id ?? generated,
|
|
43
|
+
expandedValue: props.expandedValue,
|
|
44
|
+
defaultExpandedValue: props.defaultExpandedValue,
|
|
45
|
+
selectionMode: props.selectionMode,
|
|
46
|
+
selectedValue: props.selectedValue,
|
|
47
|
+
defaultSelectedValue: props.defaultSelectedValue,
|
|
48
|
+
expandOnClick: props.expandOnClick,
|
|
49
|
+
onExpandedChange(value, details) {
|
|
50
|
+
emit("expandedChange", value, details);
|
|
51
|
+
if (!details.canceled) emit("update:expandedValue", value);
|
|
52
|
+
},
|
|
53
|
+
onSelectedChange(value, details) {
|
|
54
|
+
emit("selectedChange", value, details);
|
|
55
|
+
if (!details.canceled) emit("update:selectedValue", value);
|
|
56
|
+
}
|
|
57
|
+
})));
|
|
58
|
+
provide(LEVEL, 0);
|
|
59
|
+
return () => h(RootElement, attrs, slots);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
/** `value` tells this node from the others; `branch` for one with children in a `Tree.Group`. */
|
|
63
|
+
const Item = defineComponent({
|
|
64
|
+
name: "TreeItem",
|
|
65
|
+
inheritAttrs: false,
|
|
66
|
+
props: {
|
|
67
|
+
value: {
|
|
68
|
+
type: ANY,
|
|
69
|
+
default: void 0
|
|
70
|
+
},
|
|
71
|
+
branch: Boolean,
|
|
72
|
+
disabled: Boolean,
|
|
73
|
+
loading: Boolean,
|
|
74
|
+
label: String
|
|
75
|
+
},
|
|
76
|
+
setup(props, { attrs, slots }) {
|
|
77
|
+
const level = inject(LEVEL, 0) + 1;
|
|
78
|
+
const options = toSignal(() => ({
|
|
79
|
+
branch: props.branch,
|
|
80
|
+
disabled: props.disabled,
|
|
81
|
+
loading: props.loading,
|
|
82
|
+
label: props.label,
|
|
83
|
+
level
|
|
84
|
+
}));
|
|
85
|
+
const item = scope.use().item(props.value, () => defined(options.get()));
|
|
86
|
+
provide(ITEM, item);
|
|
87
|
+
provide(LEVEL, level);
|
|
88
|
+
let stop;
|
|
89
|
+
onMounted(() => {
|
|
90
|
+
stop = item.mount();
|
|
91
|
+
});
|
|
92
|
+
onBeforeUnmount(() => stop?.());
|
|
93
|
+
const Element = partComponent("TreeItemElement", "div", () => item.root);
|
|
94
|
+
return () => h(Element, attrs, slots);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const GroupElement = partComponent("TreeGroupElement", "div", () => useItem().group);
|
|
98
|
+
/** A branch's children; `keep-mounted` keeps the closed group in the page, `hidden`. */
|
|
99
|
+
const Group = defineComponent({
|
|
100
|
+
name: "TreeGroup",
|
|
101
|
+
inheritAttrs: false,
|
|
102
|
+
props: { keepMounted: Boolean },
|
|
103
|
+
setup(props, { attrs, slots }) {
|
|
104
|
+
const mounted = fromSignal(useItem().mounted);
|
|
105
|
+
return () => mounted.value || props.keepMounted ? h(GroupElement, attrs, slots) : null;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const Tree = {
|
|
109
|
+
Root,
|
|
110
|
+
Item,
|
|
111
|
+
ItemRow: partComponent("TreeItemRow", "div", () => useItem().row),
|
|
112
|
+
ItemIndicator: partComponent("TreeItemIndicator", "span", () => useItem().indicator),
|
|
113
|
+
ItemText: partComponent("TreeItemText", "span", () => useItem().text),
|
|
114
|
+
Group
|
|
115
|
+
};
|
|
116
|
+
export { Tree };
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=tree.js.map
|
package/src/tree.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","names":[],"sources":["../../../../packages/vue/src/tree.ts"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { ChangeDetails } from \"@kirana-ui/core\"\nimport { createTree } from \"@kirana-ui/core/tree\"\nimport type { Tree as Controller, TreeItem, TreeProps } from \"@kirana-ui/core/tree\"\nimport { defineComponent, h, inject, onBeforeUnmount, onMounted, provide, useId } from \"vue\"\nimport type { InjectionKey, PropType, PublicProps } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { context, controller, fromSignal, optional, partComponent, toSignal } from \"./runtime.ts\"\nimport type {\n PartComponent,\n PartComponentProps,\n PartGiven,\n PartInstance,\n StatesOf,\n} from \"./runtime.ts\"\n\ntype State = StatesOf<\"tree\">\n\nconst scope = context<Controller>(\"Tree\")\n// The node a part is inside, for its row, mark, text and group.\nconst ITEM: InjectionKey<TreeItem> = Symbol(\"TreeItem\")\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 LEVEL: InjectionKey<number> = Symbol(\"TreeLevel\")\nconst ANY = null as unknown as PropType<unknown>\n\nfunction useItem(): TreeItem {\n const item = inject(ITEM, undefined)\n if (!item) throw new Error(\"A Tree part must be inside <Tree.Item>\")\n return item\n}\n\nconst RootElement = partComponent(\"TreeRootElement\", \"div\", () => scope.use().root)\n\n/** `Value` is what tells a node from the others: the type of the values' entries. */\nexport type RootProps<Value = unknown> = Omit<\n TreeProps<Value>,\n \"id\" | \"onExpandedChange\" | \"onSelectedChange\"\n> & { id?: string | undefined } & PartComponentProps\n\nexport type RootEmits<Value = unknown> = {\n \"update:expandedValue\": (value: Value[]) => void\n expandedChange: (value: Value[], details: ChangeDetails) => void\n \"update:selectedValue\": (value: Value[]) => void\n selectedChange: (value: Value[], details: ChangeDetails) => void\n}\n\n/**\n * `v-model:expanded-value` and `v-model:selected-value`, or each with its\n * `@expanded-change` / `@selected-change=\"(value, details) => …\"`.\n */\nconst Root = defineComponent({\n name: \"TreeRoot\",\n inheritAttrs: false,\n props: {\n expandedValue: optional(Array as PropType<readonly unknown[]>),\n defaultExpandedValue: Array as PropType<readonly unknown[]>,\n selectionMode: String as PropType<TreeProps[\"selectionMode\"]>,\n selectedValue: optional(Array as PropType<readonly unknown[]>),\n defaultSelectedValue: Array as PropType<readonly unknown[]>,\n expandOnClick: optional(Boolean),\n id: String,\n },\n emits: [\"update:expandedValue\", \"expandedChange\", \"update:selectedValue\", \"selectedChange\"],\n setup(props, { attrs, slots, emit }) {\n const generated = useId()\n scope.provide(\n controller(within(createTree, { direction: useDirectionAround() }), () => ({\n id: props.id ?? generated,\n expandedValue: props.expandedValue,\n defaultExpandedValue: props.defaultExpandedValue,\n selectionMode: props.selectionMode,\n selectedValue: props.selectedValue,\n defaultSelectedValue: props.defaultSelectedValue,\n expandOnClick: props.expandOnClick,\n onExpandedChange(value: unknown[], details: ChangeDetails) {\n emit(\"expandedChange\", value, details)\n if (!details.canceled) emit(\"update:expandedValue\", value)\n },\n onSelectedChange(value: unknown[], details: ChangeDetails) {\n emit(\"selectedChange\", value, details)\n if (!details.canceled) emit(\"update:selectedValue\", value)\n },\n }))\n )\n provide(LEVEL, 0)\n return () => h(RootElement, attrs, slots)\n },\n}) as unknown as new <Value = unknown, As extends string = \"div\">(\n props: PartGiven<As, RootProps<Value>, RootEmits<Value>> & PublicProps\n) => PartInstance<As, RootProps<Value>, RootEmits<Value>, { state: State[\"root\"] }>\n\nexport interface ItemProps extends PartComponentProps {\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 | undefined\n /** Disables this node: it cannot be chosen, opened or closed, and the keys pass over it. */\n disabled?: boolean | undefined\n /** A branch whose children are being loaded. */\n loading?: boolean | undefined\n /** What typing matches, when it is not the node's text. */\n label?: string | undefined\n}\n\n/** `value` tells this node from the others; `branch` for one with children in a `Tree.Group`. */\nconst Item = defineComponent({\n name: \"TreeItem\",\n inheritAttrs: false,\n props: {\n value: { type: ANY, default: undefined as unknown },\n branch: Boolean,\n disabled: Boolean,\n loading: Boolean,\n label: String,\n },\n setup(props, { attrs, slots }) {\n const level = inject(LEVEL, 0) + 1\n const options = toSignal(() => ({\n branch: props.branch,\n disabled: props.disabled,\n loading: props.loading,\n label: props.label,\n level,\n }))\n // A node is its value for as long as it is in the page.\n const item = scope.use().item(props.value, () => defined(options.get()))\n provide(ITEM, item)\n provide(LEVEL, level)\n let stop: (() => void) | undefined\n onMounted(() => {\n stop = item.mount()\n })\n onBeforeUnmount(() => stop?.())\n const Element = partComponent(\"TreeItemElement\", \"div\", () => item.root)\n return () => h(Element, attrs, slots)\n },\n}) as unknown as PartComponent<\"div\", State[\"item\"], ItemProps>\n\nconst GroupElement = partComponent(\"TreeGroupElement\", \"div\", () => useItem().group)\n\nexport interface GroupProps extends PartComponentProps {\n /** Keeps the closed group in the page, `hidden`. */\n keepMounted?: boolean | undefined\n}\n\n/** A branch's children; `keep-mounted` keeps the closed group in the page, `hidden`. */\nconst Group = defineComponent({\n name: \"TreeGroup\",\n inheritAttrs: false,\n props: { keepMounted: Boolean },\n setup(props, { attrs, slots }) {\n const mounted = fromSignal(useItem().mounted)\n return () => (mounted.value || props.keepMounted ? h(GroupElement, attrs, slots) : null)\n },\n}) as unknown as PartComponent<\"div\", State[\"group\"], GroupProps>\n\nexport type ItemRowProps = PartComponentProps\nexport type ItemIndicatorProps = PartComponentProps\nexport type ItemTextProps = PartComponentProps\nexport const Tree = {\n Root,\n Item,\n ItemRow: partComponent<\"div\", State[\"itemRow\"]>(\"TreeItemRow\", \"div\", () => useItem().row),\n ItemIndicator: partComponent<\"span\", State[\"itemIndicator\"]>(\n \"TreeItemIndicator\",\n \"span\",\n () => useItem().indicator\n ),\n ItemText: partComponent<\"span\", State[\"itemText\"]>(\"TreeItemText\", \"span\", () => useItem().text),\n Group,\n}\n"],"mappings":";;;;;;AAmBA,MAAM,QAAQ,QAAoB,MAAM;AAExC,MAAM,OAA+B,OAAO,UAAU;AAGtD,MAAM,QAA8B,OAAO,WAAW;AACtD,MAAM,MAAM;AAEZ,SAAS,UAAoB;CAC3B,MAAM,OAAO,OAAO,MAAM,KAAA,CAAS;CACnC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,wCAAwC;CACnE,OAAO;AACT;AAEA,MAAM,cAAc,cAAc,mBAAmB,aAAa,MAAM,IAAI,CAAC,CAAC,IAAI;;;;;AAmBlF,MAAM,OAAO,gBAAgB;CAC3B,MAAM;CACN,cAAc;CACd,OAAO;EACL,eAAe,SAAS,KAAqC;EAC7D,sBAAsB;EACtB,eAAe;EACf,eAAe,SAAS,KAAqC;EAC7D,sBAAsB;EACtB,eAAe,SAAS,OAAO;EAC/B,IAAI;CACN;CACA,OAAO;EAAC;EAAwB;EAAkB;EAAwB;CAAgB;CAC1F,MAAM,OAAO,EAAE,OAAO,OAAO,QAAQ;EACnC,MAAM,YAAY,MAAM;EACxB,MAAM,QACJ,WAAW,OAAO,YAAY,EAAE,WAAW,mBAAmB,EAAE,CAAC,UAAU;GACzE,IAAI,MAAM,MAAM;GAChB,eAAe,MAAM;GACrB,sBAAsB,MAAM;GAC5B,eAAe,MAAM;GACrB,eAAe,MAAM;GACrB,sBAA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