@kirana-ui/vue 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 +1619 -241
- package/package.json +14 -2
- package/skills/kirana-ui-primitives/SKILL.md +142 -0
- package/src/accordion.d.ts +42 -75
- package/src/accordion.js +4 -2
- 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 +4 -2
- package/src/autosize.d.ts +9 -9
- package/src/autosize.js.map +1 -1
- package/src/avatar.d.ts +10 -13
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +4 -21
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +65 -99
- package/src/calendar.js +6 -1
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +36 -58
- package/src/carousel.js.map +1 -1
- package/src/checkbox.d.ts +28 -50
- package/src/checkbox.js +2 -2
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +26 -36
- package/src/collapsible.js.map +1 -1
- package/src/combobox.d.ts +139 -290
- package/src/combobox.js +11 -1
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +43 -86
- package/src/command.js.map +1 -1
- package/src/context-menu.d.ts +4 -2
- package/src/date-field.d.ts +31 -61
- package/src/date-field.js +7 -3
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +83 -139
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +74 -145
- package/src/dialog.js +3 -1
- package/src/dialog.js.map +1 -1
- package/src/direction.d.ts +5 -8
- package/src/direction.js.map +1 -1
- package/src/drawer.d.ts +3 -2
- package/src/element.d.ts +23 -0
- package/src/element.js +90 -0
- package/src/element.js.map +1 -0
- package/src/field.d.ts +63 -45
- package/src/field.js +3 -2
- package/src/field.js.map +1 -1
- package/src/fieldset.d.ts +12 -13
- package/src/fieldset.js.map +1 -1
- package/src/form.d.ts +5 -15
- package/src/form.js.map +1 -1
- package/src/hover-card.d.ts +29 -43
- package/src/hover-card.js.map +1 -1
- package/src/hover-popup.d.ts +27 -46
- package/src/hover-popup.js +4 -1
- package/src/hover-popup.js.map +1 -1
- package/src/index.d.ts +13 -3
- package/src/input.d.ts +12 -14
- package/src/input.js.map +1 -1
- package/src/label.d.ts +3 -3
- package/src/label.js.map +1 -1
- package/src/listbox.d.ts +34 -89
- package/src/listbox.js.map +1 -1
- package/src/menu.d.ts +170 -533
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +6 -24
- package/src/menubar.js.map +1 -1
- package/src/message-scroller.d.ts +23 -17
- package/src/message-scroller.js.map +1 -1
- package/src/meter.d.ts +10 -31
- package/src/meter.js.map +1 -1
- package/src/navigation-menu.d.ts +77 -88
- package/src/navigation-menu.js +13 -12
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +72 -68
- package/src/number-field.js +2 -2
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +33 -54
- package/src/otp.js +2 -2
- package/src/otp.js.map +1 -1
- package/src/pagination.d.ts +31 -58
- package/src/pagination.js.map +1 -1
- package/src/popover.d.ts +60 -36
- package/src/popover.js +33 -5
- package/src/popover.js.map +1 -1
- package/src/primitive.d.ts +21 -0
- package/src/primitive.js +27 -0
- package/src/primitive.js.map +1 -0
- package/src/progress.d.ts +28 -31
- package/src/progress.js.map +1 -1
- package/src/qr-code.d.ts +12 -21
- package/src/qr-code.js.map +1 -1
- package/src/radio-group.d.ts +37 -75
- package/src/radio-group.js +2 -2
- package/src/radio-group.js.map +1 -1
- package/src/resizable.d.ts +26 -45
- package/src/resizable.js.map +1 -1
- package/src/runtime.d.ts +93 -21
- package/src/runtime.js +24 -25
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +33 -28
- package/src/scroll-area.js.map +1 -1
- package/src/select.d.ts +87 -147
- package/src/select.js +31 -6
- package/src/select.js.map +1 -1
- package/src/separator.d.ts +4 -9
- package/src/separator.js.map +1 -1
- package/src/slider.d.ts +61 -80
- package/src/slider.js +10 -10
- package/src/slider.js.map +1 -1
- package/src/switch.d.ts +21 -39
- package/src/switch.js +2 -2
- package/src/switch.js.map +1 -1
- package/src/tabs.d.ts +44 -98
- 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 +58 -45
- package/src/toast.js +46 -17
- package/src/toast.js.map +1 -1
- package/src/toggle-group.d.ts +8 -39
- package/src/toggle-group.js.map +1 -1
- package/src/toggle.d.ts +5 -34
- package/src/toggle.js.map +1 -1
- package/src/toolbar.d.ts +31 -69
- package/src/toolbar.js.map +1 -1
- package/src/tooltip.d.ts +29 -43
- package/src/tooltip.js.map +1 -1
- package/src/value-bar.d.ts +26 -35
- package/src/value-bar.js +10 -3
- package/src/value-bar.js.map +1 -1
package/src/runtime.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { draw, written } from "./element.js";
|
|
2
|
+
import { sameProps, signal, stateOf } from "@kirana-ui/core";
|
|
3
|
+
import { Teleport, defineComponent, h, inject, onBeforeUnmount, onMounted, onScopeDispose, provide, queuePostFlushCb, shallowRef, watchEffect } from "vue";
|
|
3
4
|
// src/runtime.ts
|
|
4
5
|
/** A core signal as a Vue ref, read-only: tracked by whatever reads `.value`. */
|
|
5
6
|
function fromSignal(source) {
|
|
@@ -52,19 +53,28 @@ function toVue(props) {
|
|
|
52
53
|
}
|
|
53
54
|
return out;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
/**
|
|
57
|
+
* A component's instance as its element: its root, or with several roots the first element
|
|
58
|
+
* after the fragment's own mark.
|
|
59
|
+
*/
|
|
60
|
+
function elementOf(instance) {
|
|
61
|
+
let found = instance?.$el ?? null;
|
|
62
|
+
while (found && found.nodeType !== 1) found = found.nextSibling;
|
|
63
|
+
return found;
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
66
|
* A part as a component: its element (`as`, the part's own tag by default), or with `as-child`
|
|
64
|
-
* the caller's own element in its slot, which takes the part's props
|
|
65
|
-
*
|
|
67
|
+
* the caller's own element in its slot, which takes the part's props, and the part's DOM work
|
|
68
|
+
* attached to the element. Three layers of props, lowest first: the attributes on the part,
|
|
69
|
+
* the slotted element's own, the part's. A higher layer wins an attribute; classes join;
|
|
70
|
+
* styles are merged; every listener of an event runs, lowest first, and
|
|
71
|
+
* `event.preventKiranaHandler()` in a caller's stops the part's. The default slot is given the
|
|
72
|
+
* part's state (`{ state }`: `open`, `side` …, read from its `data-*` attributes), typed by
|
|
73
|
+
* `State`. `hold` is for a part that keeps something of its own in its element (a hidden
|
|
74
|
+
* input, the text it writes: `written`): it is given the content and returns what the element
|
|
75
|
+
* holds, whoever drew the element.
|
|
66
76
|
*/
|
|
67
|
-
function partComponent(name, tag, resolve) {
|
|
77
|
+
function partComponent(name, tag, resolve, hold) {
|
|
68
78
|
return defineComponent({
|
|
69
79
|
name,
|
|
70
80
|
inheritAttrs: false,
|
|
@@ -88,23 +98,12 @@ function partComponent(name, tag, resolve) {
|
|
|
88
98
|
detach = wanted ? part.attach(wanted) : void 0;
|
|
89
99
|
};
|
|
90
100
|
const attach = (target) => {
|
|
91
|
-
|
|
92
|
-
while (found instanceof Node && !(found instanceof HTMLElement)) found = found.nextSibling;
|
|
101
|
+
const found = target instanceof HTMLElement ? target : elementOf(target);
|
|
93
102
|
wanted = found instanceof HTMLElement ? found : null;
|
|
94
103
|
if (wanted) queuePostFlushCb(sync);
|
|
95
104
|
else sync();
|
|
96
105
|
};
|
|
97
|
-
return () => {
|
|
98
|
-
const merged = {
|
|
99
|
-
...mergeProps(attrs, toVue(own.value)),
|
|
100
|
-
ref: attach
|
|
101
|
-
};
|
|
102
|
-
if (props.asChild) {
|
|
103
|
-
const child = firstElement(slots.default?.());
|
|
104
|
-
return child ? cloneVNode(child, merged, true) : null;
|
|
105
|
-
}
|
|
106
|
-
return h(props.as, merged, slots.default?.());
|
|
107
|
-
};
|
|
106
|
+
return () => draw(props.as, props.asChild, attrs, slots.default?.({ state: stateOf(own.value) }), toVue(own.value), attach, hold);
|
|
108
107
|
}
|
|
109
108
|
});
|
|
110
109
|
}
|
|
@@ -144,6 +143,6 @@ const optional = (type) => ({
|
|
|
144
143
|
type,
|
|
145
144
|
default: void 0
|
|
146
145
|
});
|
|
147
|
-
export { PortalProvider, context, controller, fromSignal, optional, partComponent, portalComponent, toSignal };
|
|
146
|
+
export { PortalProvider, context, controller, elementOf, fromSignal, optional, partComponent, portalComponent, toSignal, written };
|
|
148
147
|
|
|
149
148
|
//# sourceMappingURL=runtime.js.map
|
package/src/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/vue/src/runtime.ts"],"sourcesContent":["import { mergeProps, sameProps, signal } from \"@kirana-ui/core\"\nimport type { Part, PartProps, ReadonlySignal } from \"@kirana-ui/core\"\nimport {\n Comment,\n Fragment,\n Teleport,\n cloneVNode,\n defineComponent,\n h,\n inject,\n onBeforeUnmount,\n onMounted,\n onScopeDispose,\n provide,\n queuePostFlushCb,\n shallowRef,\n watchEffect,\n} from \"vue\"\nimport type { Component, InjectionKey, PropType, ShallowRef, VNode } from \"vue\"\n\n/** A core signal as a Vue ref, read-only: tracked by whatever reads `.value`. */\nexport function fromSignal<T>(source: ReadonlySignal<T>): Readonly<ShallowRef<T>> {\n const ref = shallowRef(source.peek())\n // On a server nothing changes after the first read, and no scope is disposed to unsubscribe.\n if (typeof window !== \"undefined\") {\n onScopeDispose(\n source.subscribe(() => {\n ref.value = source.peek()\n })\n )\n }\n return ref\n}\n\n/** A core signal that follows Vue state: the core hears a changed prop as it changes. */\nexport function toSignal<T extends Record<string, unknown>>(read: () => T): ReadonlySignal<T> {\n const source = signal(read(), sameProps as (a: T, b: T) => boolean)\n watchEffect(() => source.set(read()), { flush: \"sync\" })\n return source\n}\n\n/** A component's controller, made once, following its props. */\nexport function controller<P extends Record<string, unknown>, C extends { mount(): () => void }>(\n create: (props: ReadonlySignal<P>) => C,\n read: () => P\n): C {\n const made = create(toSignal(read))\n let stop: (() => void) | undefined\n onMounted(() => {\n stop = made.mount()\n })\n onBeforeUnmount(() => stop?.())\n return made\n}\n\n/** A controller its parts find: `provide` in the root, `use` in a part. */\nexport function context<C>(name: string): { provide(controller: C): C; use(): C } {\n const key: InjectionKey<C> = Symbol(name)\n return {\n provide(made) {\n provide(key, made)\n return made\n },\n use() {\n const made = inject(key, undefined)\n if (!made) throw new Error(`A ${name} part must be inside <${name}.Root>`)\n return made\n },\n }\n}\n\nfunction toVue(props: PartProps): PartProps {\n const out: PartProps = {}\n for (const key in props) {\n const value = props[key]\n if (typeof value === \"function\") {\n // Vue names an event from the listener's key, so `onKeyDown` would listen for `key-down`:\n // it is `onKeydown`. Focus and blur are the bubbling ones, as in the core.\n const name = key.slice(2).toLowerCase()\n const event = name === \"focus\" ? \"focusin\" : name === \"blur\" ? \"focusout\" : name\n out[`on${event[0]!.toUpperCase()}${event.slice(1)}`] = value\n } else {\n out[key] = value\n }\n }\n return out\n}\n\nfunction firstElement(nodes: VNode[] | undefined): VNode | undefined {\n for (const node of nodes ?? []) {\n if (node.type === Comment) continue\n if (node.type === Fragment) return firstElement(node.children as VNode[])\n return node\n }\n return undefined\n}\n\n/**\n * A part as a component: its element (`as`, the part's own tag by default), or with `as-child`\n * the caller's own element in its slot, which takes the part's props. Either way the caller's\n * attributes are merged under the part's, and the part's DOM work is attached to the element.\n */\nexport function partComponent(name: string, tag: string, resolve: () => Part): Component {\n return defineComponent({\n name,\n inheritAttrs: false,\n props: { as: { type: String, default: tag }, asChild: Boolean },\n setup(props, { attrs, slots }) {\n const part = resolve()\n const own = fromSignal(part.props)\n let element: HTMLElement | null = null\n let detach: (() => void) | undefined\n\n // Vue calls a function ref as soon as the element exists, before the tree it is in reaches\n // the page: the part's DOM work (focus, measures, the starting style) waits for the flush\n // that follows the render, when it is there. An element that leaves detaches at once.\n let wanted: HTMLElement | null = null\n const sync = () => {\n if (wanted === element) return\n detach?.()\n element = wanted\n detach = wanted ? part.attach(wanted) : undefined\n }\n const attach = (target: unknown) => {\n // On a component (`as-child` over one), the ref is its instance: its root element, or\n // with several roots the first element after the fragment's own mark.\n let found: unknown =\n target instanceof HTMLElement ? target : (target as { $el?: unknown } | null)?.$el\n while (found instanceof Node && !(found instanceof HTMLElement)) found = found.nextSibling\n wanted = found instanceof HTMLElement ? found : null\n if (wanted) queuePostFlushCb(sync)\n else sync()\n }\n\n return () => {\n const merged = { ...mergeProps(attrs, toVue(own.value)), ref: attach }\n if (props.asChild) {\n const child = firstElement(slots.default?.())\n return child ? cloneVNode(child, merged, true) : null\n }\n return h(props.as, merged, slots.default?.())\n }\n },\n })\n}\n\nconst PORTAL_CONTAINER: InjectionKey<() => HTMLElement | null | undefined> =\n Symbol(\"PortalContainer\")\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) in place of `<body>`.\n */\nexport const PortalProvider = defineComponent({\n name: \"PortalProvider\",\n props: {\n container: { type: null as unknown as PropType<HTMLElement | null>, default: undefined },\n },\n setup(props, { slots }) {\n provide(PORTAL_CONTAINER, () => props.container)\n return () => slots.default?.()\n },\n})\n\n/** Its slot in a container at the end of the page, while `mounted`. */\nexport function portalComponent(name: string, mounted: () => ReadonlySignal<boolean>): Component {\n return defineComponent({\n name,\n setup(_props, { slots }) {\n const shown = fromSignal(mounted())\n const container = inject(PORTAL_CONTAINER, undefined)\n // Only in a browser, once the page is in it: a server draws no portal, so hydration must\n // find none either. One that opens later is drawn at once.\n const ready = shallowRef(false)\n onMounted(() => {\n ready.value = true\n })\n return () =>\n shown.value && ready.value\n ? h(\n Teleport,\n { to: container?.() ?? \"body\" },\n h(\"div\", { \"data-kirana-portal\": \"\" }, slots.default?.())\n )\n : null\n },\n })\n}\n\n/** A prop that is \"not given\" when absent, where Vue would make a boolean `false`. */\nexport const optional = <T>(type: T) => ({ type, default: undefined })\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/vue/src/runtime.ts"],"sourcesContent":["import { sameProps, signal, stateOf } from \"@kirana-ui/core\"\nimport type {\n ChangeDetails,\n Part,\n PartDefinition,\n PartEvent,\n PartProps,\n PartState,\n ReadonlySignal,\n StateOf,\n} from \"@kirana-ui/core\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport {\n Teleport,\n defineComponent,\n h,\n inject,\n onBeforeUnmount,\n onMounted,\n onScopeDispose,\n provide,\n queuePostFlushCb,\n shallowRef,\n watchEffect,\n} from \"vue\"\nimport type {\n DefineSetupFnComponent,\n HTMLAttributes,\n InjectionKey,\n IntrinsicElementAttributes,\n ObjectEmitsOptions,\n PropType,\n PublicProps,\n ShallowRef,\n SlotsType,\n VNode,\n} from \"vue\"\n\nimport { draw } from \"./element.ts\"\nimport type { Hold } from \"./element.ts\"\n\nexport { written } from \"./element.ts\"\nexport type { Hold } from \"./element.ts\"\n\n/** A core signal as a Vue ref, read-only: tracked by whatever reads `.value`. */\nexport function fromSignal<T>(source: ReadonlySignal<T>): Readonly<ShallowRef<T>> {\n const ref = shallowRef(source.peek())\n // On a server nothing changes after the first read, and no scope is disposed to unsubscribe.\n if (typeof window !== \"undefined\") {\n onScopeDispose(\n source.subscribe(() => {\n ref.value = source.peek()\n })\n )\n }\n return ref\n}\n\n/** A core signal that follows Vue state: the core hears a changed prop as it changes. */\nexport function toSignal<T extends Record<string, unknown>>(read: () => T): ReadonlySignal<T> {\n const source = signal(read(), sameProps as (a: T, b: T) => boolean)\n watchEffect(() => source.set(read()), { flush: \"sync\" })\n return source\n}\n\n/** A component's controller, made once, following its props. */\nexport function controller<P extends Record<string, unknown>, C extends { mount(): () => void }>(\n create: (props: ReadonlySignal<P>) => C,\n read: () => P\n): C {\n const made = create(toSignal(read))\n let stop: (() => void) | undefined\n onMounted(() => {\n stop = made.mount()\n })\n onBeforeUnmount(() => stop?.())\n return made\n}\n\n/** A controller its parts find: `provide` in the root, `use` in a part. */\nexport function context<C>(name: string): { provide(controller: C): C; use(): C } {\n const key: InjectionKey<C> = Symbol(name)\n return {\n provide(made) {\n provide(key, made)\n return made\n },\n use() {\n const made = inject(key, undefined)\n if (!made) throw new Error(`A ${name} part must be inside <${name}.Root>`)\n return made\n },\n }\n}\n\nfunction toVue(props: PartProps): PartProps {\n const out: PartProps = {}\n for (const key in props) {\n const value = props[key]\n if (typeof value === \"function\") {\n // Vue names an event from the listener's key, so `onKeyDown` would listen for `key-down`:\n // it is `onKeydown`. Focus and blur are the bubbling ones, as in the core.\n const name = key.slice(2).toLowerCase()\n const event = name === \"focus\" ? \"focusin\" : name === \"blur\" ? \"focusout\" : name\n out[`on${event[0]!.toUpperCase()}${event.slice(1)}`] = value\n } else {\n out[key] = value\n }\n }\n return out\n}\n\n/**\n * The state of each part of a component, by their names in the vocabulary: what a part's\n * `data-*` attributes say, and what its default slot is given as `state`.\n */\nexport type StatesOf<Name extends keyof Vocabulary> = {\n [Each in keyof Vocabulary[Name]]: Vocabulary[Name][Each] extends infer Definition extends\n PartDefinition\n ? StateOf<Definition>\n : never\n}\n\n/** What every part takes besides its own props and its element's attributes. */\nexport interface PartComponentProps {\n /** Another tag for the part's element (`as=\"a\"`): its attributes are then that tag's. */\n as?: string | undefined\n /** Draws the element in the part's slot in place of the part's own: it takes the part's props. */\n asChild?: boolean | undefined\n}\n\nexport type { PartEvent }\n\n// A listener 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 Event\n ? (event: PartEvent<Heard>) => Answer\n : Prop\n : Prop\n\ntype Heard<Attributes> = { [Name in keyof Attributes]: Hearing<Attributes[Name]> }\n\n/**\n * What the element of a tag takes, listeners included (`onClick` is `@click`, its event a\n * `MouseEvent` with `preventKiranaHandler()`, which keeps the part's own listener out of it):\n * Vue's own attributes for the tag, a plain element's for a tag Vue does not know, and any\n * `data-*` attribute.\n */\nexport type ElementAttributes<Tag extends string> = Heard<\n Tag extends keyof IntrinsicElementAttributes ? IntrinsicElementAttributes[Tag] : HTMLAttributes\n> & { [name: `data${string}`]: unknown }\n\n/** A component's events as the listeners among its props: `openChange` is `onOpenChange`. */\nexport type Listeners<Emits> = {\n [Name in keyof Emits & string as `on${Capitalize<Name>}`]?: Emits[Name]\n}\n\n/**\n * The two events of a value its caller may hold: `update:open`, which `v-model:open` hears,\n * and `openChange`, which also carries the details and may cancel the change.\n */\nexport type Changes<Name extends string, Value, Details = ChangeDetails> = {\n [Event in `update:${Name}`]: (value: Value) => void\n} & { [Event in `${Name}Change`]: (value: Value, details: Details) => void }\n\n/**\n * What a caller may hand a part drawn as `Tag`: the part's own props, a listener for each of\n * its events, and what the element takes. A prop or an event of the part's that an attribute\n * of the element shares a name with (`value`, `disabled`, `onSelect`) is the part's.\n */\nexport type PartGiven<Tag extends string, Props, Emits = {}> = Props & {\n as?: Tag | undefined\n} & Listeners<Emits> &\n Omit<ElementAttributes<Tag>, keyof Props | keyof Listeners<Emits>>\n\n/** A component's default slot, given `Slot`. */\nexport type DefaultSlot<Slot> = SlotsType<{ default?: (props: Slot) => VNode[] }>\n\n/** A part's instance, as Vue's own tools read a component: its props, its events, its slot. */\nexport type PartInstance<\n Tag extends string,\n Props,\n Emits extends ObjectEmitsOptions,\n Slot,\n> = InstanceType<\n // Its listeners are the ones `PartGiven` names, each once.\n DefineSetupFnComponent<\n PartGiven<Tag, Props, Emits>,\n Emits,\n DefaultSlot<Slot>,\n PartGiven<Tag, Props, Emits>\n >\n>\n\n/**\n * A part as its callers see it. `Tag` is the element it draws, and `as` another: the part\n * takes the attributes and listeners of whichever it is. `State` is what its default slot is\n * given as `state` (`StateOf` its entry in the vocabulary), with `Given` beside it when the\n * part hands its slot more. `Props` are the part's own, `Emits` its events with their payloads.\n *\n * A part whose value has a type of its caller's (a root with `value`) writes the same\n * signature out with that type as a parameter: `new <Value, As extends string = \"div\">(props:\n * PartGiven<As, RootProps<Value>, RootEmits<Value>> & PublicProps) => PartInstance<…>`.\n */\nexport type PartComponent<\n Tag extends string,\n State = PartState,\n Props = PartComponentProps,\n Emits extends ObjectEmitsOptions = {},\n Given = unknown,\n> = new <As extends string = Tag>(\n props: PartGiven<As, Props, Emits> & PublicProps\n) => PartInstance<As, Props, Emits, { state: State } & Given>\n\n/**\n * A component that draws no element of its own (a root that only provides, a portal, a list\n * that draws its slot once for each entry): its props, its events, what its slot is given.\n */\nexport type PlainComponent<\n Props = {},\n Emits extends ObjectEmitsOptions = {},\n Slot = {},\n> = DefineSetupFnComponent<\n Props & Listeners<Emits>,\n Emits,\n DefaultSlot<Slot>,\n Props & Listeners<Emits>\n>\n\n/** The instance of a `PlainComponent`, for one whose value has a type of its caller's. */\nexport type PlainInstance<Props, Emits extends ObjectEmitsOptions, Slot> = InstanceType<\n PlainComponent<Props, Emits, Slot>\n>\n\n/**\n * A component's instance as its element: its root, or with several roots the first element\n * after the fragment's own mark.\n */\nexport function elementOf(instance: unknown): Element | null {\n let found = (instance as { $el?: Node | null } | null)?.$el ?? null\n while (found && found.nodeType !== 1) found = found.nextSibling\n return found as Element | null\n}\n\n/**\n * A part as a component: its element (`as`, the part's own tag by default), or with `as-child`\n * the caller's own element in its slot, which takes the part's props, and the part's DOM work\n * attached to the element. Three layers of props, lowest first: the attributes on the part,\n * the slotted element's own, the part's. A higher layer wins an attribute; classes join;\n * styles are merged; every listener of an event runs, lowest first, and\n * `event.preventKiranaHandler()` in a caller's stops the part's. The default slot is given the\n * part's state (`{ state }`: `open`, `side` …, read from its `data-*` attributes), typed by\n * `State`. `hold` is for a part that keeps something of its own in its element (a hidden\n * input, the text it writes: `written`): it is given the content and returns what the element\n * holds, whoever drew the element.\n */\nexport function partComponent<Tag extends string, State = PartState>(\n name: string,\n tag: Tag,\n resolve: () => Part,\n hold?: Hold\n): PartComponent<Tag, State> {\n return defineComponent({\n name,\n inheritAttrs: false,\n props: { as: { type: String, default: tag as string }, asChild: Boolean },\n setup(props, { attrs, slots }) {\n const part = resolve()\n const own = fromSignal(part.props)\n let element: HTMLElement | null = null\n let detach: (() => void) | undefined\n\n // Vue calls a function ref as soon as the element exists, before the tree it is in reaches\n // the page: the part's DOM work (focus, measures, the starting style) waits for the flush\n // that follows the render, when it is there. An element that leaves detaches at once.\n let wanted: HTMLElement | null = null\n const sync = () => {\n if (wanted === element) return\n detach?.()\n element = wanted\n detach = wanted ? part.attach(wanted) : undefined\n }\n const attach = (target: unknown) => {\n // On a component (`as-child` over one), the ref is its instance.\n const found = target instanceof HTMLElement ? target : elementOf(target)\n wanted = found instanceof HTMLElement ? found : null\n if (wanted) queuePostFlushCb(sync)\n else sync()\n }\n\n return () =>\n draw(\n props.as,\n props.asChild,\n attrs,\n slots.default?.({ state: stateOf(own.value) }),\n toVue(own.value),\n attach,\n hold\n )\n },\n }) as unknown as PartComponent<Tag, State>\n}\n\nconst PORTAL_CONTAINER: InjectionKey<() => HTMLElement | null | undefined> =\n Symbol(\"PortalContainer\")\n\n/** What `PortalProvider` takes. */\nexport interface PortalProviderProps {\n /** Where the popups are drawn; `<body>` when left out, or while there is none. */\n container?: HTMLElement | null | undefined\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) in place of `<body>`.\n */\nexport const PortalProvider = defineComponent({\n name: \"PortalProvider\",\n props: {\n container: { type: null as unknown as PropType<HTMLElement | null>, default: undefined },\n },\n setup(props, { slots }) {\n provide(PORTAL_CONTAINER, () => props.container)\n return () => slots.default?.()\n },\n}) as unknown as PlainComponent<PortalProviderProps>\n\n/** A portal takes nothing: where it is drawn is its `PortalProvider`'s to say. */\nexport type PortalProps = Record<never, never>\n\n/** Its slot in a container at the end of the page, while `mounted`. */\nexport function portalComponent(\n name: string,\n mounted: () => ReadonlySignal<boolean>\n): PlainComponent<PortalProps> {\n return defineComponent({\n name,\n setup(_props, { slots }) {\n const shown = fromSignal(mounted())\n const container = inject(PORTAL_CONTAINER, undefined)\n // Only in a browser, once the page is in it: a server draws no portal, so hydration must\n // find none either. One that opens later is drawn at once.\n const ready = shallowRef(false)\n onMounted(() => {\n ready.value = true\n })\n return () =>\n shown.value && ready.value\n ? h(\n Teleport,\n { to: container?.() ?? \"body\" },\n h(\"div\", { \"data-kirana-portal\": \"\" }, slots.default?.())\n )\n : null\n },\n }) as unknown as PlainComponent<PortalProps>\n}\n\n/** A prop that is \"not given\" when absent, where Vue would make a boolean `false`. */\nexport const optional = <T>(type: T) => ({ type, default: undefined })\n"],"mappings":"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"}
|
package/src/scroll-area.d.ts
CHANGED
|
@@ -1,32 +1,37 @@
|
|
|
1
|
+
import { PartComponent, PartComponentProps } from "./runtime.js";
|
|
1
2
|
import { Orientation } from "@kirana-ui/core";
|
|
2
|
-
|
|
3
|
+
export type RootProps = PartComponentProps;
|
|
4
|
+
export interface ScrollbarProps extends PartComponentProps {
|
|
5
|
+
/** Which way it scrolls; `vertical` when left out. */
|
|
6
|
+
orientation?: Orientation | undefined;
|
|
7
|
+
/** Keeps the bar in the page while there is nothing to scroll that way. */
|
|
8
|
+
keepMounted?: boolean | undefined;
|
|
9
|
+
}
|
|
10
|
+
export type ThumbProps = PartComponentProps;
|
|
11
|
+
export type CornerProps = PartComponentProps;
|
|
12
|
+
export type ViewportProps = PartComponentProps;
|
|
13
|
+
export type ContentProps = PartComponentProps;
|
|
3
14
|
export declare const ScrollArea: {
|
|
4
|
-
Root:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
keepMounted: boolean;
|
|
26
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
27
|
-
Thumb: import("vue").Component;
|
|
28
|
-
Corner: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
29
|
-
[key: string]: any;
|
|
30
|
-
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
15
|
+
Root: PartComponent<"div", {
|
|
16
|
+
readonly hasOverflowX?: true | undefined;
|
|
17
|
+
readonly hasOverflowY?: true | undefined;
|
|
18
|
+
readonly scrolling?: true | undefined;
|
|
19
|
+
readonly hovering?: true | undefined;
|
|
20
|
+
}, PartComponentProps>;
|
|
21
|
+
Viewport: PartComponent<"div", {
|
|
22
|
+
readonly hasOverflowX?: true | undefined;
|
|
23
|
+
readonly hasOverflowY?: true | undefined;
|
|
24
|
+
readonly scrolling?: true | undefined;
|
|
25
|
+
}, PartComponentProps, {}, unknown>;
|
|
26
|
+
Content: PartComponent<"div", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
27
|
+
Scrollbar: PartComponent<"div", {
|
|
28
|
+
readonly orientation?: "horizontal" | "vertical" | undefined;
|
|
29
|
+
readonly hovering?: true | undefined;
|
|
30
|
+
readonly scrolling?: true | undefined;
|
|
31
|
+
}, ScrollbarProps>;
|
|
32
|
+
Thumb: PartComponent<"div", {
|
|
33
|
+
readonly orientation?: "horizontal" | "vertical" | undefined;
|
|
34
|
+
}, PartComponentProps, {}, unknown>;
|
|
35
|
+
Corner: PartComponent<"div", Record<never, never>, PartComponentProps>;
|
|
31
36
|
};
|
|
32
37
|
//# sourceMappingURL=scroll-area.d.ts.map
|
package/src/scroll-area.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-area.js","names":[],"sources":["../../../../packages/vue/src/scroll-area.ts"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { Orientation } 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 { defineComponent, h, inject, provide } from \"vue\"\nimport type { InjectionKey, PropType } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { context, controller, fromSignal, partComponent } from \"./runtime.ts\"\n\nconst scope = context<Controller>(\"ScrollArea\")\nconst SCROLLBAR: InjectionKey<ScrollAreaScrollbar> = Symbol(\"ScrollAreaScrollbar\")\n\nconst Root = defineComponent({\n name: \"ScrollAreaRoot\",\n inheritAttrs: false,\n setup(_props, { attrs, slots }) {\n const direction = useDirectionAround()\n const made = scope.provide(controller(within(createScrollArea, { direction }), () => ({})))\n const Element = partComponent(\"ScrollAreaRootElement\", \"div\", () => made.root)\n return () => h(Element, attrs, slots)\n },\n})\n\n/** `orientation` is which way it scrolls (`vertical` by default). */\nconst Scrollbar = defineComponent({\n name: \"ScrollAreaScrollbar\",\n inheritAttrs: false,\n props: {\n orientation: { type: String as PropType<Orientation>, default: \"vertical\" },\n keepMounted: Boolean,\n },\n setup(props, { attrs, slots }) {\n const bar = scope.use().scrollbar(props.orientation)\n provide(SCROLLBAR, bar)\n const shown = fromSignal(bar.shown)\n const Element = partComponent(\"ScrollAreaScrollbarElement\", \"div\", () => bar.part)\n return () => (shown.value || props.keepMounted ? h(Element, attrs, slots) : null)\n },\n})\n\nconst Thumb = partComponent(\"ScrollAreaThumb\", \"div\", () => {\n const bar = inject(SCROLLBAR, undefined)\n if (!bar) throw new Error(\"A ScrollArea.Thumb must be inside <ScrollArea.Scrollbar>\")\n return bar.thumb\n})\n\nconst Corner = defineComponent({\n name: \"ScrollAreaCorner\",\n inheritAttrs: false,\n setup(_props, { attrs, slots }) {\n const { corner } = scope.use()\n const shown = fromSignal(corner.shown)\n const Element = partComponent(\"ScrollAreaCornerElement\", \"div\", () => corner.part)\n return () => (shown.value ? h(Element, attrs, slots) : null)\n },\n})\n\nexport const ScrollArea = {\n Root,\n Viewport: partComponent(\"ScrollAreaViewport\"
|
|
1
|
+
{"version":3,"file":"scroll-area.js","names":[],"sources":["../../../../packages/vue/src/scroll-area.ts"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { Orientation } 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 { defineComponent, h, inject, provide } from \"vue\"\nimport type { InjectionKey, PropType } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { context, controller, fromSignal, partComponent } from \"./runtime.ts\"\nimport type { PartComponent, PartComponentProps, StatesOf } from \"./runtime.ts\"\n\ntype State = StatesOf<\"scrollArea\">\n\nconst scope = context<Controller>(\"ScrollArea\")\nconst SCROLLBAR: InjectionKey<ScrollAreaScrollbar> = Symbol(\"ScrollAreaScrollbar\")\n\nexport type RootProps = PartComponentProps\n\nconst Root = defineComponent({\n name: \"ScrollAreaRoot\",\n inheritAttrs: false,\n setup(_props, { attrs, slots }) {\n const direction = useDirectionAround()\n const made = scope.provide(controller(within(createScrollArea, { direction }), () => ({})))\n const Element = partComponent(\"ScrollAreaRootElement\", \"div\", () => made.root)\n return () => h(Element, attrs, slots)\n },\n}) as unknown as PartComponent<\"div\", State[\"root\"], RootProps>\n\nexport interface ScrollbarProps extends PartComponentProps {\n /** Which way it scrolls; `vertical` when left out. */\n orientation?: Orientation | undefined\n /** Keeps the bar in the page while there is nothing to scroll that way. */\n keepMounted?: boolean | undefined\n}\n\n/** `orientation` is which way it scrolls (`vertical` by default). */\nconst Scrollbar = defineComponent({\n name: \"ScrollAreaScrollbar\",\n inheritAttrs: false,\n props: {\n orientation: { type: String as PropType<Orientation>, default: \"vertical\" },\n keepMounted: Boolean,\n },\n setup(props, { attrs, slots }) {\n const bar = scope.use().scrollbar(props.orientation)\n provide(SCROLLBAR, bar)\n const shown = fromSignal(bar.shown)\n const Element = partComponent(\"ScrollAreaScrollbarElement\", \"div\", () => bar.part)\n return () => (shown.value || props.keepMounted ? h(Element, attrs, slots) : null)\n },\n}) as unknown as PartComponent<\"div\", State[\"scrollbar\"], ScrollbarProps>\n\nexport type ThumbProps = PartComponentProps\nconst Thumb = partComponent<\"div\", State[\"thumb\"]>(\"ScrollAreaThumb\", \"div\", () => {\n const bar = inject(SCROLLBAR, undefined)\n if (!bar) throw new Error(\"A ScrollArea.Thumb must be inside <ScrollArea.Scrollbar>\")\n return bar.thumb\n})\n\nexport type CornerProps = PartComponentProps\n\nconst Corner = defineComponent({\n name: \"ScrollAreaCorner\",\n inheritAttrs: false,\n setup(_props, { attrs, slots }) {\n const { corner } = scope.use()\n const shown = fromSignal(corner.shown)\n const Element = partComponent(\"ScrollAreaCornerElement\", \"div\", () => corner.part)\n return () => (shown.value ? h(Element, attrs, slots) : null)\n },\n}) as unknown as PartComponent<\"div\", State[\"corner\"], CornerProps>\n\nexport type ViewportProps = PartComponentProps\nexport type ContentProps = PartComponentProps\nexport const ScrollArea = {\n Root,\n Viewport: partComponent<\"div\", State[\"viewport\"]>(\n \"ScrollAreaViewport\",\n \"div\",\n () => scope.use().viewport\n ),\n Content: partComponent<\"div\", State[\"content\"]>(\n \"ScrollAreaContent\",\n \"div\",\n () => scope.use().content\n ),\n Scrollbar,\n Thumb,\n Corner,\n}\n"],"mappings":";;;;;;AAaA,MAAM,QAAQ,QAAoB,YAAY;AAC9C,MAAM,YAA+C,OAAO,qBAAqB;AAIjF,MAAM,OAAO,gBAAgB;CAC3B,MAAM;CACN,cAAc;CACd,MAAM,QAAQ,EAAE,OAAO,SAAS;EAC9B,MAAM,YAAY,mBAAmB;EACrC,MAAM,OAAO,MAAM,QAAQ,WAAW,OAAO,kBAAkB,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;EAC1F,MAAM,UAAU,cAAc,yBAAyB,aAAa,KAAK,IAAI;EAC7E,aAAa,EAAE,SAAS,OAAO,KAAK;CACtC;AACF,CAAC;;AAUD,MAAM,YAAY,gBAAgB;CAChC,MAAM;CACN,cAAc;CACd,OAAO;EACL,aAAa;GAAE,MAAM;GAAiC,SAAS;EAAW;EAC1E,aAAa;CACf;CACA,MAAM,OAAO,EAAE,OAAO,SAAS;EAC7B,MAAM,MAAM,MAAM,IAAI,CAAC,CAAC,UAAU,MAAM,WAAW;EACnD,QAAQ,WAAW,GAAG;EACtB,MAAM,QAAQ,WAAW,IAAI,KAAK;EAClC,MAAM,UAAU,cAAc,8BAA8B,aAAa,IAAI,IAAI;EACjF,aAAc,MAAM,SAAS,MAAM,cAAc,EAAE,SAAS,OAAO,KAAK,IAAI;CAC9E;AACF,CAAC;AAGD,MAAM,QAAQ,cAAqC,mBAAmB,aAAa;CACjF,MAAM,MAAM,OAAO,WAAW,KAAA,CAAS;CACvC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,0DAA0D;CACpF,OAAO,IAAI;AACb,CAAC;AAID,MAAM,SAAS,gBAAgB;CAC7B,MAAM;CACN,cAAc;CACd,MAAM,QAAQ,EAAE,OAAO,SAAS;EAC9B,MAAM,EAAE,WAAW,MAAM,IAAI;EAC7B,MAAM,QAAQ,WAAW,OAAO,KAAK;EACrC,MAAM,UAAU,cAAc,2BAA2B,aAAa,OAAO,IAAI;EACjF,aAAc,MAAM,QAAQ,EAAE,SAAS,OAAO,KAAK,IAAI;CACzD;AACF,CAAC;AAID,MAAa,aAAa;CACxB;CACA,UAAU,cACR,sBACA,aACM,MAAM,IAAI,CAAC,CAAC,QACpB;CACA,SAAS,cACP,qBACA,aACM,MAAM,IAAI,CAAC,CAAC,OACpB;CACA;CACA;CACA;AACF"}
|
package/src/select.d.ts
CHANGED
|
@@ -1,154 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Changes, Listeners, PartComponent, PartComponentProps, PartGiven, PartInstance, PlainComponent, PlainInstance, PortalProps, StatesOf } from "./runtime.js";
|
|
2
|
+
import { PositionerProps as PositionerProps$1 } from "./popover.js";
|
|
3
|
+
import { PublicProps } from "vue";
|
|
4
|
+
import { SelectItemOptions, SelectProps, SelectShown } from "@kirana-ui/core/select";
|
|
5
|
+
type State = StatesOf<"select">;
|
|
6
|
+
export type RootProps<Value = unknown> = Omit<SelectProps<Value>, "id" | "onValueChange" | "onValuesChange" | "onOpenChange"> & {
|
|
7
|
+
id?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
/** The value is `null` when the select is put back to none chosen. */
|
|
10
|
+
export type RootEmits<Value = unknown> = Changes<"value", Value | null> & Changes<"values", Value[]> & Changes<"open", boolean>;
|
|
11
|
+
export interface ValueProps extends PartComponentProps {
|
|
12
|
+
/** What it shows while nothing is chosen. */
|
|
13
|
+
placeholder?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
export interface ItemProps extends SelectItemOptions, PartComponentProps {
|
|
16
|
+
/** What the select's value is while this item is the chosen one. */
|
|
17
|
+
value: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface ItemIndicatorProps extends PartComponentProps {
|
|
20
|
+
/** Keeps the mark in the page while its item is not chosen. */
|
|
21
|
+
keepMounted?: boolean | undefined;
|
|
22
|
+
}
|
|
23
|
+
export interface PositionerProps extends PositionerProps$1 {
|
|
24
|
+
/** Opens the list over its trigger, the chosen item's text on the trigger's own. */
|
|
25
|
+
alignItemWithTrigger?: boolean | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface GroupProps extends PartComponentProps {
|
|
28
|
+
id?: string | undefined;
|
|
29
|
+
}
|
|
30
|
+
export type TriggerProps = PartComponentProps;
|
|
31
|
+
export type PopupProps = PartComponentProps;
|
|
32
|
+
export type ListProps = PartComponentProps;
|
|
33
|
+
export type ScrollUpArrowProps = PartComponentProps;
|
|
34
|
+
export type ScrollDownArrowProps = PartComponentProps;
|
|
35
|
+
export type GroupLabelProps = PartComponentProps;
|
|
36
|
+
export type SeparatorProps = PartComponentProps;
|
|
37
|
+
export type ItemTextProps = PartComponentProps;
|
|
3
38
|
export declare const Select: {
|
|
4
|
-
Root:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}>, () => (import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
29
|
-
[key: string]: any;
|
|
30
|
-
}>[] | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
31
|
-
[key: string]: any;
|
|
32
|
-
}> | null | undefined)[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("openChange" | "update:open" | "update:value" | "valueChange")[], "openChange" | "update:open" | "update:value" | "valueChange", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
33
|
-
value: {
|
|
34
|
-
type: PropType<unknown>;
|
|
35
|
-
default: unknown;
|
|
36
|
-
};
|
|
37
|
-
defaultValue: {
|
|
38
|
-
type: PropType<unknown>;
|
|
39
|
-
default: unknown;
|
|
40
|
-
};
|
|
41
|
-
open: {
|
|
42
|
-
type: BooleanConstructor;
|
|
43
|
-
default: undefined;
|
|
44
|
-
};
|
|
45
|
-
defaultOpen: BooleanConstructor;
|
|
46
|
-
disabled: BooleanConstructor;
|
|
47
|
-
required: BooleanConstructor;
|
|
48
|
-
name: StringConstructor;
|
|
49
|
-
form: StringConstructor;
|
|
50
|
-
items: PropType<readonly {
|
|
51
|
-
value: unknown;
|
|
52
|
-
label: string;
|
|
53
|
-
}[]>;
|
|
54
|
-
virtualized: PropType<SelectProps["virtualized"]>;
|
|
55
|
-
id: StringConstructor;
|
|
56
|
-
}>> & Readonly<{
|
|
57
|
-
onOpenChange?: ((...args: any[]) => any) | undefined;
|
|
58
|
-
"onUpdate:open"?: ((...args: any[]) => any) | undefined;
|
|
59
|
-
"onUpdate:value"?: ((...args: any[]) => any) | undefined;
|
|
60
|
-
onValueChange?: ((...args: any[]) => any) | undefined;
|
|
61
|
-
}>, {
|
|
62
|
-
value: unknown;
|
|
63
|
-
defaultValue: unknown;
|
|
64
|
-
open: boolean;
|
|
65
|
-
defaultOpen: boolean;
|
|
66
|
-
disabled: boolean;
|
|
67
|
-
required: boolean;
|
|
68
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
69
|
-
Trigger: import("vue").Component;
|
|
70
|
-
Value: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
71
|
-
placeholder: {
|
|
72
|
-
type: StringConstructor;
|
|
73
|
-
default: string;
|
|
74
|
-
};
|
|
75
|
-
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
76
|
-
[key: string]: any;
|
|
77
|
-
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
78
|
-
placeholder: {
|
|
79
|
-
type: StringConstructor;
|
|
80
|
-
default: string;
|
|
81
|
-
};
|
|
82
|
-
}>> & Readonly<{}>, {
|
|
83
|
-
placeholder: string;
|
|
84
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
85
|
-
Portal: import("vue").Component;
|
|
86
|
-
Positioner: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
87
|
-
alignItemWithTrigger: BooleanConstructor;
|
|
88
|
-
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
89
|
-
[key: string]: any;
|
|
90
|
-
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
91
|
-
alignItemWithTrigger: BooleanConstructor;
|
|
92
|
-
}>> & Readonly<{}>, {
|
|
93
|
-
alignItemWithTrigger: boolean;
|
|
94
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
95
|
-
Popup: import("vue").Component;
|
|
39
|
+
Root: new <Value = unknown>(props: RootProps<Value> & Listeners<RootEmits<Value>> & PublicProps) => PlainInstance<RootProps<Value>, RootEmits<Value>, {}>;
|
|
40
|
+
Trigger: PartComponent<"button", {
|
|
41
|
+
readonly popupOpen?: true | undefined;
|
|
42
|
+
readonly placeholder?: true | undefined;
|
|
43
|
+
readonly disabled?: true | undefined;
|
|
44
|
+
}, PartComponentProps, {}, unknown>;
|
|
45
|
+
Value: new <As extends string = "span">(props: PartGiven<As, ValueProps> & PublicProps) => PartInstance<As, ValueProps, {}, {
|
|
46
|
+
state: State["value"];
|
|
47
|
+
} & SelectShown>;
|
|
48
|
+
Portal: PlainComponent<PortalProps, {}, {}>;
|
|
49
|
+
Positioner: PartComponent<"div", {
|
|
50
|
+
readonly open?: true | undefined;
|
|
51
|
+
readonly closed?: true | undefined;
|
|
52
|
+
readonly align?: "center" | "end" | "start" | undefined;
|
|
53
|
+
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "none" | "right" | "top" | undefined;
|
|
54
|
+
}, PositionerProps>;
|
|
55
|
+
Popup: PartComponent<"div", {
|
|
56
|
+
readonly open?: true | undefined;
|
|
57
|
+
readonly closed?: true | undefined;
|
|
58
|
+
readonly startingStyle?: true | undefined;
|
|
59
|
+
readonly endingStyle?: true | undefined;
|
|
60
|
+
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "right" | "top" | undefined;
|
|
61
|
+
readonly align?: "center" | "end" | "start" | undefined;
|
|
62
|
+
}, PartComponentProps, {}, unknown>;
|
|
96
63
|
/** The items' own box inside the popup, when the popup also holds scroll arrows. */
|
|
97
|
-
List:
|
|
64
|
+
List: PartComponent<"div", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
98
65
|
/** In the page while there is more of the list above: it scrolls it under a moving pointer. */
|
|
99
|
-
ScrollUpArrow:
|
|
100
|
-
|
|
101
|
-
|
|
66
|
+
ScrollUpArrow: PartComponent<"div", {
|
|
67
|
+
readonly direction?: "down" | "up" | undefined;
|
|
68
|
+
readonly visible?: true | undefined;
|
|
69
|
+
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "none" | "right" | "top" | undefined;
|
|
70
|
+
readonly startingStyle?: true | undefined;
|
|
71
|
+
readonly endingStyle?: true | undefined;
|
|
72
|
+
}>;
|
|
102
73
|
/** In the page while there is more of the list below. */
|
|
103
|
-
ScrollDownArrow:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
113
|
-
GroupLabel: import("vue").Component;
|
|
74
|
+
ScrollDownArrow: PartComponent<"div", {
|
|
75
|
+
readonly direction?: "down" | "up" | undefined;
|
|
76
|
+
readonly visible?: true | undefined;
|
|
77
|
+
readonly side?: "bottom" | "inline-end" | "inline-start" | "left" | "none" | "right" | "top" | undefined;
|
|
78
|
+
readonly startingStyle?: true | undefined;
|
|
79
|
+
readonly endingStyle?: true | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
Group: PartComponent<"div", Record<never, never>, GroupProps>;
|
|
82
|
+
GroupLabel: PartComponent<"div", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
114
83
|
/** A line between groups. */
|
|
115
|
-
Separator:
|
|
116
|
-
Item:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
default: undefined;
|
|
124
|
-
};
|
|
125
|
-
label: StringConstructor;
|
|
126
|
-
index: NumberConstructor;
|
|
127
|
-
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
128
|
-
[key: string]: any;
|
|
129
|
-
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
130
|
-
value: {
|
|
131
|
-
type: PropType<unknown>;
|
|
132
|
-
required: true;
|
|
133
|
-
};
|
|
134
|
-
disabled: {
|
|
135
|
-
type: BooleanConstructor;
|
|
136
|
-
default: undefined;
|
|
137
|
-
};
|
|
138
|
-
label: StringConstructor;
|
|
139
|
-
index: NumberConstructor;
|
|
140
|
-
}>> & Readonly<{}>, {
|
|
141
|
-
disabled: boolean;
|
|
142
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
143
|
-
ItemText: import("vue").Component;
|
|
144
|
-
ItemIndicator: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
145
|
-
keepMounted: BooleanConstructor;
|
|
146
|
-
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
147
|
-
[key: string]: any;
|
|
148
|
-
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
149
|
-
keepMounted: BooleanConstructor;
|
|
150
|
-
}>> & Readonly<{}>, {
|
|
151
|
-
keepMounted: boolean;
|
|
152
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
84
|
+
Separator: PartComponent<"div", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
85
|
+
Item: PartComponent<"div", {
|
|
86
|
+
readonly selected?: true | undefined;
|
|
87
|
+
readonly highlighted?: true | undefined;
|
|
88
|
+
readonly disabled?: true | undefined;
|
|
89
|
+
}, ItemProps>;
|
|
90
|
+
ItemText: PartComponent<"span", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
91
|
+
ItemIndicator: PartComponent<"span", Record<never, never>, ItemIndicatorProps>;
|
|
153
92
|
};
|
|
93
|
+
export type { PortalProps };
|
|
154
94
|
//# sourceMappingURL=select.d.ts.map
|
package/src/select.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { positionerComponent } from "./popover.js";
|
|
2
2
|
import { useFieldAround } from "./field-context.js";
|
|
3
|
+
import { written } from "./element.js";
|
|
3
4
|
import { context, controller, fromSignal, optional, partComponent, portalComponent, toSignal } from "./runtime.js";
|
|
4
5
|
import { defined, within } from "@kirana-ui/core";
|
|
5
6
|
import { defineComponent, h, inject, onBeforeUnmount, onMounted, provide, useId, watchEffect } from "vue";
|
|
@@ -8,7 +9,10 @@ import { createSelect } from "@kirana-ui/core/select";
|
|
|
8
9
|
const scope = context("Select");
|
|
9
10
|
const ITEM = Symbol("SelectItem");
|
|
10
11
|
const HiddenInput = partComponent("SelectHiddenInput", "input", () => scope.use().input);
|
|
11
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* `v-model:value`, `v-model:open`; `@value-change` and `@open-change` carry the details. With
|
|
14
|
+
* `multiple`: `v-model:values` and `@values-change`.
|
|
15
|
+
*/
|
|
12
16
|
const Root = defineComponent({
|
|
13
17
|
name: "SelectRoot",
|
|
14
18
|
props: {
|
|
@@ -26,13 +30,18 @@ const Root = defineComponent({
|
|
|
26
30
|
required: Boolean,
|
|
27
31
|
name: String,
|
|
28
32
|
form: String,
|
|
29
|
-
items: Array,
|
|
33
|
+
items: [Array, Object],
|
|
34
|
+
multiple: Boolean,
|
|
35
|
+
values: optional(Array),
|
|
36
|
+
defaultValues: Array,
|
|
30
37
|
virtualized: Object,
|
|
31
38
|
id: String
|
|
32
39
|
},
|
|
33
40
|
emits: [
|
|
34
41
|
"update:value",
|
|
35
42
|
"valueChange",
|
|
43
|
+
"update:values",
|
|
44
|
+
"valuesChange",
|
|
36
45
|
"update:open",
|
|
37
46
|
"openChange"
|
|
38
47
|
],
|
|
@@ -50,11 +59,18 @@ const Root = defineComponent({
|
|
|
50
59
|
name: props.name,
|
|
51
60
|
form: props.form,
|
|
52
61
|
items: props.items,
|
|
62
|
+
multiple: props.multiple,
|
|
63
|
+
values: props.values,
|
|
64
|
+
defaultValues: props.defaultValues,
|
|
53
65
|
virtualized: props.virtualized,
|
|
54
66
|
onValueChange(value, details) {
|
|
55
67
|
emit("valueChange", value, details);
|
|
56
68
|
if (!details.canceled) emit("update:value", value);
|
|
57
69
|
},
|
|
70
|
+
onValuesChange(values, details) {
|
|
71
|
+
emit("valuesChange", values, details);
|
|
72
|
+
if (!details.canceled) emit("update:values", values);
|
|
73
|
+
},
|
|
58
74
|
onOpenChange(open, details) {
|
|
59
75
|
emit("openChange", open, details);
|
|
60
76
|
if (!details.canceled) emit("update:open", open);
|
|
@@ -64,8 +80,12 @@ const Root = defineComponent({
|
|
|
64
80
|
return () => [slots.default?.(), named.value ? h(HiddenInput) : null];
|
|
65
81
|
}
|
|
66
82
|
});
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Shows the chosen value's label, or `placeholder` while nothing is chosen; with `multiple`,
|
|
85
|
+
* the chosen labels with commas between. Or what its slot makes of them
|
|
86
|
+
* (`v-slot="{ value, label }"`, with `multiple` `v-slot="{ values, labels }"`, in the items'
|
|
87
|
+
* order), which is given the part's `state` too.
|
|
88
|
+
*/
|
|
69
89
|
const Value = defineComponent({
|
|
70
90
|
name: "SelectValue",
|
|
71
91
|
inheritAttrs: false,
|
|
@@ -74,8 +94,13 @@ const Value = defineComponent({
|
|
|
74
94
|
default: ""
|
|
75
95
|
} },
|
|
76
96
|
setup(props, { attrs, slots }) {
|
|
77
|
-
const
|
|
78
|
-
|
|
97
|
+
const shown = fromSignal(scope.use().shown);
|
|
98
|
+
const label = () => shown.value.label ?? props.placeholder;
|
|
99
|
+
const ValueElement = partComponent("SelectValueElement", "span", () => scope.use().valuePart, written(label));
|
|
100
|
+
return () => h(ValueElement, attrs, { default: (given) => slots.default ? slots.default({
|
|
101
|
+
...given,
|
|
102
|
+
...shown.value
|
|
103
|
+
}) : label() });
|
|
79
104
|
}
|
|
80
105
|
});
|
|
81
106
|
/** `label` is what typeahead matches and the trigger shows; the item's text when left out. */
|