@kirana-ui/web 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 +1598 -143
- package/package.json +48 -3
- package/skills/kirana-ui-primitives/SKILL.md +53 -12
- package/src/accordion.d.ts +1 -1
- package/src/accordion.js +2 -1
- package/src/accordion.js.map +1 -1
- package/src/alert-dialog.d.ts +2 -2
- package/src/alert-dialog.js +9 -4
- package/src/alert-dialog.js.map +1 -1
- package/src/around.d.ts +28 -4
- package/src/around.js +46 -13
- package/src/around.js.map +1 -1
- package/src/autocomplete.d.ts +7 -4
- package/src/autocomplete.js +8 -4
- package/src/autocomplete.js.map +1 -1
- package/src/avatar.d.ts +11 -5
- package/src/avatar.js +41 -12
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +2 -1
- package/src/button.js +2 -1
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +9 -5
- package/src/calendar.js +22 -9
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +1 -1
- package/src/carousel.js +4 -2
- package/src/carousel.js.map +1 -1
- package/src/checkbox-group.d.ts +22 -0
- package/src/checkbox-group.js +36 -0
- package/src/checkbox-group.js.map +1 -0
- package/src/checkbox.d.ts +4 -2
- package/src/checkbox.js +10 -4
- package/src/checkbox.js.map +1 -1
- package/src/color-picker.d.ts +28 -0
- package/src/color-picker.js +81 -0
- package/src/color-picker.js.map +1 -0
- package/src/combobox.d.ts +27 -7
- package/src/combobox.js +79 -17
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +3 -3
- package/src/command.js +6 -5
- package/src/command.js.map +1 -1
- package/src/context-menu.d.ts +2 -1
- package/src/context-menu.js.map +1 -1
- package/src/date-field.d.ts +2 -2
- package/src/date-field.js +3 -3
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +14 -8
- package/src/date-picker.js +49 -10
- package/src/date-picker.js.map +1 -1
- package/src/dates.d.ts +11 -5
- package/src/dates.js +58 -20
- package/src/dates.js.map +1 -1
- package/src/dialog.d.ts +3 -2
- package/src/dialog.js +12 -4
- package/src/dialog.js.map +1 -1
- package/src/drawer.d.ts +2 -1
- package/src/drawer.js +7 -3
- package/src/drawer.js.map +1 -1
- package/src/editable.d.ts +21 -0
- package/src/editable.js +56 -0
- package/src/editable.js.map +1 -0
- package/src/file-upload.d.ts +23 -0
- package/src/file-upload.js +98 -0
- package/src/file-upload.js.map +1 -0
- package/src/hover-card.d.ts +2 -1
- package/src/hover-card.js.map +1 -1
- package/src/index.d.ts +29 -7
- package/src/index.js +11 -0
- package/src/menu.d.ts +4 -3
- package/src/menu.js +19 -10
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +2 -2
- package/src/menubar.js +5 -3
- package/src/menubar.js.map +1 -1
- package/src/navigation-menu.d.ts +4 -3
- package/src/navigation-menu.js +10 -6
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +5 -2
- package/src/number-field.js +23 -3
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +4 -2
- package/src/otp.js +24 -4
- package/src/otp.js.map +1 -1
- package/src/password-input.d.ts +20 -0
- package/src/password-input.js +39 -0
- package/src/password-input.js.map +1 -0
- package/src/popover.d.ts +8 -7
- package/src/popover.js +33 -5
- package/src/popover.js.map +1 -1
- package/src/radio-group.d.ts +2 -1
- package/src/radio-group.js +9 -2
- package/src/radio-group.js.map +1 -1
- package/src/rating.d.ts +18 -0
- package/src/rating.js +54 -0
- package/src/rating.js.map +1 -0
- package/src/runtime.d.ts +9 -4
- package/src/runtime.js +8 -5
- package/src/runtime.js.map +1 -1
- package/src/select.d.ts +12 -4
- package/src/select.js +33 -10
- package/src/select.js.map +1 -1
- package/src/slider.d.ts +2 -2
- package/src/slider.js +3 -2
- package/src/slider.js.map +1 -1
- package/src/steps.d.ts +17 -0
- package/src/steps.js +47 -0
- package/src/steps.js.map +1 -0
- package/src/tags-input.d.ts +35 -0
- package/src/tags-input.js +96 -0
- package/src/tags-input.js.map +1 -0
- package/src/time-field.d.ts +18 -0
- package/src/time-field.js +54 -0
- package/src/time-field.js.map +1 -0
- package/src/toast.d.ts +4 -3
- package/src/toast.js +6 -4
- package/src/toast.js.map +1 -1
- package/src/toggle-group.d.ts +1 -1
- package/src/toggle-group.js +2 -1
- package/src/toggle-group.js.map +1 -1
- package/src/toolbar.d.ts +0 -6
- package/src/toolbar.js +14 -3
- package/src/toolbar.js.map +1 -1
- package/src/tooltip.d.ts +2 -1
- package/src/tooltip.js.map +1 -1
- package/src/tour.d.ts +27 -0
- package/src/tour.js +62 -0
- package/src/tour.js.map +1 -0
- package/src/tree.d.ts +29 -0
- package/src/tree.js +99 -0
- package/src/tree.js.map +1 -0
package/src/combobox.d.ts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { Drawn, Each, ElementOf, Tag } from "./runtime.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { Placed } from "./around.js";
|
|
3
|
+
import { Combobox, ComboboxEntry, ComboboxProps } from "@kirana-ui/core/combobox";
|
|
4
|
+
type Props = Omit<ComboboxProps<string, boolean>, "value" | "defaultValue" | "values" | "defaultValues"> & {
|
|
5
|
+
/** With `multiple`, the chosen values, with commas between. */
|
|
6
|
+
value?: string | readonly string[] | null;
|
|
7
|
+
defaultValue?: string | readonly string[] | null;
|
|
4
8
|
values?: string | readonly string[];
|
|
5
9
|
defaultValues?: string | readonly string[];
|
|
6
10
|
};
|
|
7
11
|
type Parts = Record<string, (controller: Combobox<string>, element: HTMLElement) => Drawn["part"] | Drawn | undefined>;
|
|
8
12
|
/** A combobox's parts: an autocomplete has them too. */
|
|
9
13
|
export declare const PARTS: Parts;
|
|
10
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* With `multiple`: a chip for each chosen value, from a `<template kui-each="chips">`. With
|
|
16
|
+
* `items` as data: what is left of them, from a `<template kui-each="collection">`; one
|
|
17
|
+
* written in a group's copy is that group's items left.
|
|
18
|
+
*/
|
|
11
19
|
export declare const LISTS: {
|
|
12
20
|
chips: (controller: Combobox<string>) => Each<{
|
|
13
21
|
value: string;
|
|
14
22
|
}>;
|
|
23
|
+
collection: (controller: Combobox<string>, around: unknown) => Each<ComboboxEntry<string>>;
|
|
15
24
|
};
|
|
16
25
|
/**
|
|
17
26
|
* `<kui-combobox>` around an `input`, with a `trigger` and a `clear` button if it has them,
|
|
@@ -22,11 +31,22 @@ export declare const LISTS: {
|
|
|
22
31
|
* nothing matches. The `input` may be inside the `popup`, the items then in a `list` part: the
|
|
23
32
|
* popup is placed against the `trigger`, and the input has focus while it is open. With `multiple`, the input is in a `chips` part with a
|
|
24
33
|
* `<template kui-each="chips">` holding a `chip` (`{value}`) and its `chip-remove` button.
|
|
34
|
+
* With the input in the popup, the `trigger` may hold a `value` part: it says the chosen
|
|
35
|
+
* value's label, or its `kui-placeholder`. A `status` part says how the list stands to
|
|
36
|
+
* software that reads the page, as the page changes its text. With `items` given as data, the
|
|
37
|
+
* list is a `<template kui-each="collection">` holding an `item` (`kui-value="{value}"`,
|
|
38
|
+
* `{label}`; `kui-when="item"` where groups are given too) or a `group`
|
|
39
|
+
* (`kui-when="group"`, `{value}` its name) with a `<template kui-each="collection">` of its
|
|
40
|
+
* own for its items: the element filters, and draws what is left.
|
|
25
41
|
* With a name it draws the hidden input a form reads. `value`,
|
|
26
42
|
* `default-value`, `input-value`, `default-input-value`, `open`, `default-open`, `disabled`,
|
|
27
|
-
* `required`, `inline`, `auto-highlight`, `multiple
|
|
28
|
-
* commas between
|
|
29
|
-
* `
|
|
43
|
+
* `read-only`, `required`, `inline`, `auto-highlight`, `multiple` (with it, `value`
|
|
44
|
+
* and `default-value` hold the chosen values with commas between; `values` and
|
|
45
|
+
* `default-values`, the older names, are still read),
|
|
46
|
+
* `name`, `form`, `presentation` (`sheet` opens the list from the bottom edge, modal, over a
|
|
47
|
+
* `backdrop` part in the portal; `auto` on a narrow touch screen) and `sheet-below`; `items`,
|
|
48
|
+
* `filter`, `itemToStringLabel` and `itemToStringValue` as
|
|
49
|
+
* properties; it tells `value-change`,
|
|
30
50
|
* `values-change`, `input-value-change` and `open-change`.
|
|
31
51
|
*/
|
|
32
52
|
export declare const tag: Tag<Props, Combobox<string>>;
|
|
@@ -37,7 +57,7 @@ declare global {
|
|
|
37
57
|
"values-change": ["onValuesChange", "values"];
|
|
38
58
|
"input-value-change": ["onInputValueChange", "inputValue"];
|
|
39
59
|
"open-change": ["onOpenChange", "open"];
|
|
40
|
-
}
|
|
60
|
+
}> & Placed;
|
|
41
61
|
}
|
|
42
62
|
}
|
|
43
63
|
export {};
|
package/src/combobox.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fieldAround, itemOptions, list, once, positioner, valueOf } from "./around.js";
|
|
2
2
|
import { defineElement, entryAround, partAround } from "./runtime.js";
|
|
3
3
|
import { computed } from "@kirana-ui/core";
|
|
4
4
|
import { createCombobox } from "@kirana-ui/core/combobox";
|
|
@@ -10,6 +10,11 @@ const groupOf = (controller, element) => once(groups, element, (group) => contro
|
|
|
10
10
|
const PARTS = {
|
|
11
11
|
input: (controller) => controller.input,
|
|
12
12
|
trigger: (controller) => controller.trigger,
|
|
13
|
+
value: (controller, element) => ({
|
|
14
|
+
part: PLAIN,
|
|
15
|
+
text: computed(() => controller.shown.get().label ?? element.getAttribute("kui-placeholder") ?? void 0)
|
|
16
|
+
}),
|
|
17
|
+
status: (controller) => controller.status,
|
|
13
18
|
clear: (controller) => ({
|
|
14
19
|
part: controller.clear,
|
|
15
20
|
mounted: controller.clearable
|
|
@@ -26,8 +31,13 @@ const PARTS = {
|
|
|
26
31
|
separator: (controller) => controller.separator,
|
|
27
32
|
item(controller, element) {
|
|
28
33
|
const id = element.getAttribute("kui-id") ?? `kui-combobox-item-${++made}`;
|
|
34
|
+
const off = () => {
|
|
35
|
+
const entry = entryAround(element);
|
|
36
|
+
return entry?.type === "item" && entry.disabled ? { disabled: true } : {};
|
|
37
|
+
};
|
|
29
38
|
return controller.item(valueOf(element), () => ({
|
|
30
39
|
...itemOptions(element)(),
|
|
40
|
+
...off(),
|
|
31
41
|
id
|
|
32
42
|
}), groupOf(controller, element.parentElement && partAround(element.parentElement, "group")));
|
|
33
43
|
},
|
|
@@ -40,16 +50,39 @@ const PARTS = {
|
|
|
40
50
|
const value = entryAround(element)?.value;
|
|
41
51
|
return value === void 0 ? void 0 : controller.chipRemove(value);
|
|
42
52
|
},
|
|
43
|
-
"item-indicator"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
"item-indicator"(controller, element) {
|
|
54
|
+
const mark = controller.itemIndicator(valueOf(partAround(element, "item")));
|
|
55
|
+
return {
|
|
56
|
+
part: mark,
|
|
57
|
+
mounted: mark.mounted,
|
|
58
|
+
mount: mark.mount
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/** A part that draws no element of its own in a framework: here, the page's element as it is. */
|
|
63
|
+
const PLAIN = {
|
|
64
|
+
props: computed(() => ({})),
|
|
65
|
+
attach: () => () => {}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* With `multiple`: a chip for each chosen value, from a `<template kui-each="chips">`. With
|
|
69
|
+
* `items` as data: what is left of them, from a `<template kui-each="collection">`; one
|
|
70
|
+
* written in a group's copy is that group's items left.
|
|
71
|
+
*/
|
|
72
|
+
const LISTS = {
|
|
73
|
+
chips: (controller) => ({
|
|
74
|
+
entries: computed(() => controller.values.get().map((value) => ({ value }))),
|
|
75
|
+
key: (chip) => chip.value
|
|
76
|
+
}),
|
|
77
|
+
collection: (controller, around) => {
|
|
78
|
+
const group = around;
|
|
79
|
+
return {
|
|
80
|
+
entries: controller.entries(group?.type === "group" ? group : void 0),
|
|
81
|
+
key: (entry) => entry.key,
|
|
82
|
+
type: (entry) => entry.type
|
|
83
|
+
};
|
|
84
|
+
}
|
|
47
85
|
};
|
|
48
|
-
/** With `multiple`: a chip for each chosen value, from a `<template kui-each="chips">`. */
|
|
49
|
-
const LISTS = { chips: (controller) => ({
|
|
50
|
-
entries: computed(() => controller.values.get().map((value) => ({ value }))),
|
|
51
|
-
key: (chip) => chip.value
|
|
52
|
-
}) };
|
|
53
86
|
/**
|
|
54
87
|
* `<kui-combobox>` around an `input`, with a `trigger` and a `clear` button if it has them,
|
|
55
88
|
* and a `portal` with a `positioner` (`kui-side` … and `kui-anchor`, an element's id) around
|
|
@@ -59,11 +92,22 @@ const LISTS = { chips: (controller) => ({
|
|
|
59
92
|
* nothing matches. The `input` may be inside the `popup`, the items then in a `list` part: the
|
|
60
93
|
* popup is placed against the `trigger`, and the input has focus while it is open. With `multiple`, the input is in a `chips` part with a
|
|
61
94
|
* `<template kui-each="chips">` holding a `chip` (`{value}`) and its `chip-remove` button.
|
|
95
|
+
* With the input in the popup, the `trigger` may hold a `value` part: it says the chosen
|
|
96
|
+
* value's label, or its `kui-placeholder`. A `status` part says how the list stands to
|
|
97
|
+
* software that reads the page, as the page changes its text. With `items` given as data, the
|
|
98
|
+
* list is a `<template kui-each="collection">` holding an `item` (`kui-value="{value}"`,
|
|
99
|
+
* `{label}`; `kui-when="item"` where groups are given too) or a `group`
|
|
100
|
+
* (`kui-when="group"`, `{value}` its name) with a `<template kui-each="collection">` of its
|
|
101
|
+
* own for its items: the element filters, and draws what is left.
|
|
62
102
|
* With a name it draws the hidden input a form reads. `value`,
|
|
63
103
|
* `default-value`, `input-value`, `default-input-value`, `open`, `default-open`, `disabled`,
|
|
64
|
-
* `required`, `inline`, `auto-highlight`, `multiple
|
|
65
|
-
* commas between
|
|
66
|
-
* `
|
|
104
|
+
* `read-only`, `required`, `inline`, `auto-highlight`, `multiple` (with it, `value`
|
|
105
|
+
* and `default-value` hold the chosen values with commas between; `values` and
|
|
106
|
+
* `default-values`, the older names, are still read),
|
|
107
|
+
* `name`, `form`, `presentation` (`sheet` opens the list from the bottom edge, modal, over a
|
|
108
|
+
* `backdrop` part in the portal; `auto` on a narrow touch screen) and `sheet-below`; `items`,
|
|
109
|
+
* `filter`, `itemToStringLabel` and `itemToStringValue` as
|
|
110
|
+
* properties; it tells `value-change`,
|
|
67
111
|
* `values-change`, `input-value-change` and `open-change`.
|
|
68
112
|
*/
|
|
69
113
|
const tag = defineElement({
|
|
@@ -76,6 +120,7 @@ const tag = defineElement({
|
|
|
76
120
|
open: "boolean",
|
|
77
121
|
"default-open": "boolean",
|
|
78
122
|
disabled: "boolean",
|
|
123
|
+
"read-only": "boolean",
|
|
79
124
|
required: "boolean",
|
|
80
125
|
inline: "boolean",
|
|
81
126
|
"auto-highlight": "boolean",
|
|
@@ -83,15 +128,29 @@ const tag = defineElement({
|
|
|
83
128
|
values: "string",
|
|
84
129
|
"default-values": "string",
|
|
85
130
|
name: "string",
|
|
86
|
-
form: "string"
|
|
131
|
+
form: "string",
|
|
132
|
+
presentation: "string",
|
|
133
|
+
"sheet-below": "number"
|
|
87
134
|
},
|
|
88
|
-
properties: [
|
|
135
|
+
properties: [
|
|
136
|
+
"items",
|
|
137
|
+
"filter",
|
|
138
|
+
"itemToStringLabel",
|
|
139
|
+
"itemToStringValue"
|
|
140
|
+
],
|
|
89
141
|
create: (props, host) => createCombobox(computed(() => {
|
|
90
142
|
const own = props.get();
|
|
143
|
+
const many = (given) => own.multiple ? list(given) : given;
|
|
91
144
|
return {
|
|
92
145
|
...own,
|
|
146
|
+
value: many(own.value),
|
|
147
|
+
defaultValue: many(own.defaultValue),
|
|
93
148
|
values: list(own.values),
|
|
94
|
-
defaultValues: list(own.defaultValues)
|
|
149
|
+
defaultValues: list(own.defaultValues),
|
|
150
|
+
onValueChange(value, details) {
|
|
151
|
+
own.onValueChange?.(value, details);
|
|
152
|
+
if (own.multiple && Array.isArray(value)) own.onValuesChange?.(value, details);
|
|
153
|
+
}
|
|
95
154
|
};
|
|
96
155
|
}), { field: fieldAround(host) }),
|
|
97
156
|
lists: LISTS,
|
|
@@ -117,7 +176,10 @@ const tag = defineElement({
|
|
|
117
176
|
prop: "open"
|
|
118
177
|
}
|
|
119
178
|
},
|
|
120
|
-
parts:
|
|
179
|
+
parts: {
|
|
180
|
+
...PARTS,
|
|
181
|
+
backdrop: (controller) => controller.backdrop
|
|
182
|
+
}
|
|
121
183
|
});
|
|
122
184
|
export { LISTS, PARTS, tag };
|
|
123
185
|
|
package/src/combobox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combobox.js","names":[],"sources":["../../../../packages/web/src/combobox.ts"],"sourcesContent":["import { computed } from \"@kirana-ui/core\"\nimport type { Combobox, ComboboxGroup, ComboboxProps } from \"@kirana-ui/core/combobox\"\nimport { createCombobox } from \"@kirana-ui/core/combobox\"\n\nimport { fieldAround, itemOptions, list, MARK, once, positioner, valueOf } from \"./around.ts\"\nimport { defineElement, entryAround, partAround } from \"./runtime.ts\"\nimport type { Drawn, Each, ElementOf } from \"./runtime.ts\"\n\ntype Props = Omit<ComboboxProps<string>, \"values\" | \"defaultValues\"> & {\n values?: string | readonly string[]\n defaultValues?: string | readonly string[]\n}\n\nconst groups = new WeakMap<HTMLElement, ComboboxGroup>()\nlet made = 0\n\nconst groupOf = (controller: Combobox<string>, element: HTMLElement | null) =>\n once(groups, element, (group) =>\n controller.group(group.getAttribute(\"kui-id\") ?? `kui-combobox-group-${++made}`)\n )\n\ntype Parts = Record<\n string,\n (controller: Combobox<string>, element: HTMLElement) => Drawn[\"part\"] | Drawn | undefined\n>\n\n/** A combobox's parts: an autocomplete has them too. */\nexport const PARTS: Parts = {\n input: (controller) => controller.input,\n trigger: (controller) => controller.trigger,\n clear: (controller) => ({ part: controller.clear, mounted: controller.clearable }),\n positioner,\n popup: (controller) => controller.popup,\n list: (controller) => controller.list,\n empty: (controller) => ({ part: controller.emptyPart, mounted: controller.empty }),\n group: (controller, element) => groupOf(controller, element)?.root,\n // Outside a group it is plain text, and names nothing.\n \"group-label\": (controller, element) =>\n groups.get(partAround(element, \"group\")!)?.label ?? controller.groupLabel,\n separator: (controller) => controller.separator,\n item(controller, element) {\n const id = element.getAttribute(\"kui-id\") ?? `kui-combobox-item-${++made}`\n return controller.item(\n valueOf(element),\n () => ({ ...itemOptions(element)(), id }),\n groupOf(controller, element.parentElement && partAround(element.parentElement, \"group\"))\n )\n },\n chips: (controller) => controller.chips,\n chip(controller, element) {\n const value = entryAround<{ value: string }>(element)?.value\n return value === undefined ? undefined : controller.chip(value)\n },\n \"chip-remove\"(controller, element) {\n const value = entryAround<{ value: string }>(element)?.value\n return value === undefined ? undefined : controller.chipRemove(value)\n },\n \"item-indicator\": (controller, element) => ({\n part: MARK,\n mounted: controller.selected(valueOf(partAround(element, \"item\"))),\n }),\n}\n\n/** With `multiple`: a chip for each chosen value, from a `<template kui-each=\"chips\">`. */\nexport const LISTS = {\n chips: (controller: Combobox<string>): Each<{ value: string }> => ({\n entries: computed(() => controller.values.get().map((value) => ({ value }))),\n key: (chip) => chip.value,\n }),\n}\n\n/**\n * `<kui-combobox>` around an `input`, with a `trigger` and a `clear` button if it has them,\n * and a `portal` with a `positioner` (`kui-side` … and `kui-anchor`, an element's id) around\n * the `popup`, which holds an `item` for each\n * `kui-value` (`kui-disabled`, `kui-label`, `kui-id`) with an `item-indicator`, in `group`s\n * with a `group-label` and `separator`s if it has them, and an `empty` part drawn while\n * nothing matches. The `input` may be inside the `popup`, the items then in a `list` part: the\n * popup is placed against the `trigger`, and the input has focus while it is open. With `multiple`, the input is in a `chips` part with a\n * `<template kui-each=\"chips\">` holding a `chip` (`{value}`) and its `chip-remove` button.\n * With a name it draws the hidden input a form reads. `value`,\n * `default-value`, `input-value`, `default-input-value`, `open`, `default-open`, `disabled`,\n * `required`, `inline`, `auto-highlight`, `multiple`, `values` and `default-values` (with\n * commas between),\n * `name`, `form`; `items` and `filter` as properties; it tells `value-change`,\n * `values-change`, `input-value-change` and `open-change`.\n */\nexport const tag = defineElement<Props, Combobox<string>>({\n tag: \"kui-combobox\",\n props: {\n value: \"string\",\n \"default-value\": \"string\",\n \"input-value\": \"string\",\n \"default-input-value\": \"string\",\n open: \"boolean\",\n \"default-open\": \"boolean\",\n disabled: \"boolean\",\n required: \"boolean\",\n inline: \"boolean\",\n \"auto-highlight\": \"boolean\",\n multiple: \"boolean\",\n values: \"string\",\n \"default-values\": \"string\",\n name: \"string\",\n form: \"string\",\n },\n properties: [\"items\", \"filter\"],\n create: (props, host) =>\n createCombobox<string>(\n computed(() => {\n const own = props.get()\n return { ...own, values: list(own.values), defaultValues: list(own.defaultValues) }\n }),\n { field: fieldAround(host) }\n ),\n lists: LISTS,\n inner: (controller) => ({ part: controller.hidden, mounted: controller.named }),\n changes: {\n onValueChange: { event: \"value-change\", prop: \"value\" },\n onValuesChange: { event: \"values-change\", prop: \"values\" },\n onInputValueChange: { event: \"input-value-change\", prop: \"inputValue\" },\n onOpenChange: { event: \"open-change\", prop: \"open\" },\n },\n parts: PARTS,\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-combobox\": ElementOf<\n typeof tag,\n {\n \"value-change\": [\"onValueChange\", \"value\"]\n \"values-change\": [\"onValuesChange\", \"values\"]\n \"input-value-change\": [\"onInputValueChange\", \"inputValue\"]\n \"open-change\": [\"onOpenChange\", \"open\"]\n }\n >\n }\n}\n"],"mappings":";;;;;AAaA,MAAM,yBAAS,IAAI,QAAoC;AACvD,IAAI,OAAO;AAEX,MAAM,WAAW,YAA8B,YAC7C,KAAK,QAAQ,UAAU,UACrB,WAAW,MAAM,MAAM,aAAa,QAAQ,KAAK,sBAAsB,EAAE,MAAM,CACjF;;AAQF,MAAa,QAAe;CAC1B,QAAQ,eAAe,WAAW;CAClC,UAAU,eAAe,WAAW;CACpC,QAAQ,gBAAgB;EAAE,MAAM,WAAW;EAAO,SAAS,WAAW;CAAU;CAChF;CACA,QAAQ,eAAe,WAAW;CAClC,OAAO,eAAe,WAAW;CACjC,QAAQ,gBAAgB;EAAE,MAAM,WAAW;EAAW,SAAS,WAAW;CAAM;CAChF,QAAQ,YAAY,YAAY,QAAQ,YAAY,OAAO,CAAC,EAAE;CAE9D,gBAAgB,YAAY,YAC1B,OAAO,IAAI,WAAW,SAAS,OAAO,CAAE,CAAC,EAAE,SAAS,WAAW;CACjE,YAAY,eAAe,WAAW;CACtC,KAAK,YAAY,SAAS;EACxB,MAAM,KAAK,QAAQ,aAAa,QAAQ,KAAK,qBAAqB,EAAE;EACpE,OAAO,WAAW,KAChB,QAAQ,OAAO,UACR;GAAE,GAAG,YAAY,OAAO,CAAC,CAAC;GAAG;EAAG,IACvC,QAAQ,YAAY,QAAQ,iBAAiB,WAAW,QAAQ,eAAe,OAAO,CAAC,CACzF;CACF;CACA,QAAQ,eAAe,WAAW;CAClC,KAAK,YAAY,SAAS;EACxB,MAAM,QAAQ,YAA+B,OAAO,CAAC,EAAE;EACvD,OAAO,UAAU,KAAA,IAAY,KAAA,IAAY,WAAW,KAAK,KAAK;CAChE;CACA,cAAc,YAAY,SAAS;EACjC,MAAM,QAAQ,YAA+B,OAAO,CAAC,EAAE;EACvD,OAAO,UAAU,KAAA,IAAY,KAAA,IAAY,WAAW,WAAW,KAAK;CACtE;CACA,mBAAmB,YAAY,aAAa;EAC1C,MAAM;EACN,SAAS,WAAW,SAAS,QAAQ,WAAW,SAAS,MAAM,CAAC,CAAC;CACnE;AACF;;AAGA,MAAa,QAAQ,EACnB,QAAQ,gBAA2D;CACjE,SAAS,eAAe,WAAW,OAAO,IAAI,CAAC,CAAC,KAAK,WAAW,EAAE,MAAM,EAAE,CAAC;CAC3E,MAAM,SAAS,KAAK;AACtB,GACF;;;;;;;;;;;;;;;;;AAkBA,MAAa,MAAM,cAAuC;CACxD,KAAK;CACL,OAAO;EACL,OAAO;EACP,iBAAiB;EACjB,eAAe;EACf,uBAAuB;EACvB,MAAM;EACN,gBAAgB;EAChB,UAAU;EACV,UAAU;EACV,QAAQ;EACR,kBAAkB;EAClB,UAAU;EACV,QAAQ;EACR,kBAAkB;EAClB,MAAM;EACN,MAAM;CACR;CACA,YAAY,CAAC,SAAS,QAAQ;CAC9B,SAAS,OAAO,SACd,eACE,eAAe;EACb,MAAM,MAAM,MAAM,IAAI;EACtB,OAAO;GAAE,GAAG;GAAK,QAAQ,KAAK,IAAI,MAAM;GAAG,eAAe,KAAK,IAAI,aAAa;EAAE;CACpF,CAAC,GACD,EAAE,OAAO,YAAY,IAAI,EAAE,CAC7B;CACF,OAAO;CACP,QAAQ,gBAAgB;EAAE,MAAM,WAAW;EAAQ,SAAS,WAAW;CAAM;CAC7E,SAAS;EACP,eAAe;GAAE,OAAO;GAAgB,MAAM;EAAQ;EACtD,gBAAgB;GAAE,OAAO;GAAiB,MAAM;EAAS;EACzD,oBAAoB;GAAE,OAAO;GAAsB,MAAM;EAAa;EACtE,cAAc;GAAE,OAAO;GAAe,MAAM;EAAO;CACrD;CACA,OAAO;AACT,CAAC"}
|
|
1
|
+
{"version":3,"file":"combobox.js","names":[],"sources":["../../../../packages/web/src/combobox.ts"],"sourcesContent":["import { computed } from \"@kirana-ui/core\"\nimport type { ChangeDetails } from \"@kirana-ui/core\"\nimport type {\n Combobox,\n ComboboxEntry,\n ComboboxGroup,\n ComboboxProps,\n} from \"@kirana-ui/core/combobox\"\nimport { createCombobox } from \"@kirana-ui/core/combobox\"\n\nimport { fieldAround, itemOptions, list, once, positioner, valueOf } from \"./around.ts\"\nimport type { Placed } from \"./around.ts\"\nimport { defineElement, entryAround, partAround } from \"./runtime.ts\"\nimport type { Drawn, Each, ElementOf } from \"./runtime.ts\"\n\ntype Props = Omit<\n ComboboxProps<string, boolean>,\n \"value\" | \"defaultValue\" | \"values\" | \"defaultValues\"\n> & {\n /** With `multiple`, the chosen values, with commas between. */\n value?: string | readonly string[] | null\n defaultValue?: string | readonly string[] | null\n values?: string | readonly string[]\n defaultValues?: string | readonly string[]\n}\n\nconst groups = new WeakMap<HTMLElement, ComboboxGroup>()\nlet made = 0\n\nconst groupOf = (controller: Combobox<string>, element: HTMLElement | null) =>\n once(groups, element, (group) =>\n controller.group(group.getAttribute(\"kui-id\") ?? `kui-combobox-group-${++made}`)\n )\n\ntype Parts = Record<\n string,\n (controller: Combobox<string>, element: HTMLElement) => Drawn[\"part\"] | Drawn | undefined\n>\n\n/** A combobox's parts: an autocomplete has them too. */\nexport const PARTS: Parts = {\n input: (controller) => controller.input,\n trigger: (controller) => controller.trigger,\n // It says the chosen value's label, or its `kui-placeholder`, unless the page wrote there.\n value: (controller, element) => ({\n part: PLAIN,\n text: computed(\n () => controller.shown.get().label ?? element.getAttribute(\"kui-placeholder\") ?? undefined\n ),\n }),\n status: (controller) => controller.status,\n clear: (controller) => ({ part: controller.clear, mounted: controller.clearable }),\n positioner,\n popup: (controller) => controller.popup,\n list: (controller) => controller.list,\n empty: (controller) => ({ part: controller.emptyPart, mounted: controller.empty }),\n group: (controller, element) => groupOf(controller, element)?.root,\n // Outside a group it is plain text, and names nothing.\n \"group-label\": (controller, element) =>\n groups.get(partAround(element, \"group\")!)?.label ?? controller.groupLabel,\n separator: (controller) => controller.separator,\n item(controller, element) {\n const id = element.getAttribute(\"kui-id\") ?? `kui-combobox-item-${++made}`\n // Drawn from data, its entry says whether it can be chosen.\n const off = () => {\n const entry = entryAround<ComboboxEntry<string>>(element)\n return entry?.type === \"item\" && entry.disabled ? { disabled: true } : {}\n }\n return controller.item(\n valueOf(element),\n () => ({ ...itemOptions(element)(), ...off(), id }),\n groupOf(controller, element.parentElement && partAround(element.parentElement, \"group\"))\n )\n },\n chips: (controller) => controller.chips,\n chip(controller, element) {\n const value = entryAround<{ value: string }>(element)?.value\n return value === undefined ? undefined : controller.chip(value)\n },\n \"chip-remove\"(controller, element) {\n const value = entryAround<{ value: string }>(element)?.value\n return value === undefined ? undefined : controller.chipRemove(value)\n },\n \"item-indicator\"(controller, element) {\n // In the page while chosen, and through its exit.\n const mark = controller.itemIndicator(valueOf(partAround(element, \"item\")))\n return { part: mark, mounted: mark.mounted, mount: mark.mount }\n },\n}\n\n/** A part that draws no element of its own in a framework: here, the page's element as it is. */\nconst PLAIN = { props: computed(() => ({})), attach: () => () => {} }\n\n/**\n * With `multiple`: a chip for each chosen value, from a `<template kui-each=\"chips\">`. With\n * `items` as data: what is left of them, from a `<template kui-each=\"collection\">`; one\n * written in a group's copy is that group's items left.\n */\nexport const LISTS = {\n chips: (controller: Combobox<string>): Each<{ value: string }> => ({\n entries: computed(() => controller.values.get().map((value) => ({ value }))),\n key: (chip) => chip.value,\n }),\n collection: (controller: Combobox<string>, around: unknown): Each<ComboboxEntry<string>> => {\n const group = around as ComboboxEntry<string> | undefined\n return {\n entries: controller.entries(group?.type === \"group\" ? group : undefined),\n key: (entry) => entry.key,\n type: (entry) => entry.type,\n }\n },\n}\n\n/**\n * `<kui-combobox>` around an `input`, with a `trigger` and a `clear` button if it has them,\n * and a `portal` with a `positioner` (`kui-side` … and `kui-anchor`, an element's id) around\n * the `popup`, which holds an `item` for each\n * `kui-value` (`kui-disabled`, `kui-label`, `kui-id`) with an `item-indicator`, in `group`s\n * with a `group-label` and `separator`s if it has them, and an `empty` part drawn while\n * nothing matches. The `input` may be inside the `popup`, the items then in a `list` part: the\n * popup is placed against the `trigger`, and the input has focus while it is open. With `multiple`, the input is in a `chips` part with a\n * `<template kui-each=\"chips\">` holding a `chip` (`{value}`) and its `chip-remove` button.\n * With the input in the popup, the `trigger` may hold a `value` part: it says the chosen\n * value's label, or its `kui-placeholder`. A `status` part says how the list stands to\n * software that reads the page, as the page changes its text. With `items` given as data, the\n * list is a `<template kui-each=\"collection\">` holding an `item` (`kui-value=\"{value}\"`,\n * `{label}`; `kui-when=\"item\"` where groups are given too) or a `group`\n * (`kui-when=\"group\"`, `{value}` its name) with a `<template kui-each=\"collection\">` of its\n * own for its items: the element filters, and draws what is left.\n * With a name it draws the hidden input a form reads. `value`,\n * `default-value`, `input-value`, `default-input-value`, `open`, `default-open`, `disabled`,\n * `read-only`, `required`, `inline`, `auto-highlight`, `multiple` (with it, `value`\n * and `default-value` hold the chosen values with commas between; `values` and\n * `default-values`, the older names, are still read),\n * `name`, `form`, `presentation` (`sheet` opens the list from the bottom edge, modal, over a\n * `backdrop` part in the portal; `auto` on a narrow touch screen) and `sheet-below`; `items`,\n * `filter`, `itemToStringLabel` and `itemToStringValue` as\n * properties; it tells `value-change`,\n * `values-change`, `input-value-change` and `open-change`.\n */\nexport const tag = defineElement<Props, Combobox<string>>({\n tag: \"kui-combobox\",\n props: {\n value: \"string\",\n \"default-value\": \"string\",\n \"input-value\": \"string\",\n \"default-input-value\": \"string\",\n open: \"boolean\",\n \"default-open\": \"boolean\",\n disabled: \"boolean\",\n \"read-only\": \"boolean\",\n required: \"boolean\",\n inline: \"boolean\",\n \"auto-highlight\": \"boolean\",\n multiple: \"boolean\",\n values: \"string\",\n \"default-values\": \"string\",\n name: \"string\",\n form: \"string\",\n presentation: \"string\",\n \"sheet-below\": \"number\",\n },\n properties: [\"items\", \"filter\", \"itemToStringLabel\", \"itemToStringValue\"],\n create: (props, host) =>\n createCombobox<string, boolean>(\n computed(() => {\n const own = props.get()\n // With `multiple`, Base UI's `value` holding the list; the older `values` still read.\n const many = <Given>(given: Given) => (own.multiple ? list(given) : given)\n return {\n ...own,\n value: many(own.value) as string | readonly string[] | null | undefined,\n defaultValue: many(own.defaultValue) as string | readonly string[] | null | undefined,\n values: list(own.values),\n defaultValues: list(own.defaultValues),\n onValueChange(value: string | string[] | null, details: ChangeDetails) {\n own.onValueChange?.(value, details)\n // The older event too: a listener cannot be told from none.\n if (own.multiple && Array.isArray(value)) own.onValuesChange?.(value, details)\n },\n }\n }),\n { field: fieldAround(host) }\n ),\n lists: LISTS,\n inner: (controller) => ({ part: controller.hidden, mounted: controller.named }),\n changes: {\n onValueChange: { event: \"value-change\", prop: \"value\" },\n onValuesChange: { event: \"values-change\", prop: \"values\" },\n onInputValueChange: { event: \"input-value-change\", prop: \"inputValue\" },\n onOpenChange: { event: \"open-change\", prop: \"open\" },\n },\n // A combobox's list may open as a sheet, over a backdrop: an autocomplete's does not.\n parts: { ...PARTS, backdrop: (controller) => controller.backdrop },\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-combobox\": ElementOf<\n typeof tag,\n {\n \"value-change\": [\"onValueChange\", \"value\"]\n \"values-change\": [\"onValuesChange\", \"values\"]\n \"input-value-change\": [\"onInputValueChange\", \"inputValue\"]\n \"open-change\": [\"onOpenChange\", \"open\"]\n }\n > &\n Placed\n }\n}\n"],"mappings":"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"}
|
package/src/command.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ElementOf, Tag } from "./runtime.js";
|
|
2
2
|
import { Command, CommandProps } from "@kirana-ui/core/command";
|
|
3
3
|
/**
|
|
4
|
-
* `<kui-command>` around `kui-part="root"`, an `input` and a `list` of `item`s (`kui-value`,
|
|
5
|
-
* `kui-disabled`, `kui-label`, `kui-keywords` with commas between, `kui-id`), in `group`s
|
|
4
|
+
* `<kui-command>` around `kui-part="root"`, an `input` and a `list` of `item`s (`kui-value`, its
|
|
5
|
+
* `kui-label` or its text when left out, `kui-disabled`, `kui-label`, `kui-keywords` with commas between, `kui-id`), in `group`s
|
|
6
6
|
* with a `group-heading` and `separator`s (`kui-always-render`) if it has them, and an
|
|
7
7
|
* `empty` part drawn while nothing matches. What is typed filters the list; Enter or a press
|
|
8
|
-
* runs an item. `input-value`, `default-input-value`, `loop`, `disabled`; `filter` as a
|
|
8
|
+
* runs an item. `input-value`, `default-input-value`, `loop`, `auto-highlight` (on unless `="false"`), `disabled`; `filter` as a
|
|
9
9
|
* property; it tells `input-value-change` and `select`.
|
|
10
10
|
*/
|
|
11
11
|
export declare const tag: Tag<CommandProps, Command>;
|
package/src/command.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { list, once
|
|
1
|
+
import { list, once } from "./around.js";
|
|
2
2
|
import { defineElement, partAround } from "./runtime.js";
|
|
3
3
|
import { createCommand } from "@kirana-ui/core/command";
|
|
4
4
|
// src/command.ts
|
|
@@ -6,11 +6,11 @@ const groups = /* @__PURE__ */ new WeakMap();
|
|
|
6
6
|
let made = 0;
|
|
7
7
|
const groupOf = (controller, element) => once(groups, element, (group) => controller.group(group.getAttribute("kui-id") ?? `kui-command-group-${++made}`));
|
|
8
8
|
/**
|
|
9
|
-
* `<kui-command>` around `kui-part="root"`, an `input` and a `list` of `item`s (`kui-value`,
|
|
10
|
-
* `kui-disabled`, `kui-label`, `kui-keywords` with commas between, `kui-id`), in `group`s
|
|
9
|
+
* `<kui-command>` around `kui-part="root"`, an `input` and a `list` of `item`s (`kui-value`, its
|
|
10
|
+
* `kui-label` or its text when left out, `kui-disabled`, `kui-label`, `kui-keywords` with commas between, `kui-id`), in `group`s
|
|
11
11
|
* with a `group-heading` and `separator`s (`kui-always-render`) if it has them, and an
|
|
12
12
|
* `empty` part drawn while nothing matches. What is typed filters the list; Enter or a press
|
|
13
|
-
* runs an item. `input-value`, `default-input-value`, `loop`, `disabled`; `filter` as a
|
|
13
|
+
* runs an item. `input-value`, `default-input-value`, `loop`, `auto-highlight` (on unless `="false"`), `disabled`; `filter` as a
|
|
14
14
|
* property; it tells `input-value-change` and `select`.
|
|
15
15
|
*/
|
|
16
16
|
const tag = defineElement({
|
|
@@ -19,6 +19,7 @@ const tag = defineElement({
|
|
|
19
19
|
"input-value": "string",
|
|
20
20
|
"default-input-value": "string",
|
|
21
21
|
loop: "boolean",
|
|
22
|
+
"auto-highlight": "boolean",
|
|
22
23
|
disabled: "boolean"
|
|
23
24
|
},
|
|
24
25
|
properties: ["filter"],
|
|
@@ -46,7 +47,7 @@ const tag = defineElement({
|
|
|
46
47
|
"group-heading": (controller, element) => groups.get(partAround(element, "group"))?.heading ?? controller.heading,
|
|
47
48
|
item(controller, element) {
|
|
48
49
|
const id = element.getAttribute("kui-id") ?? `kui-command-item-${++made}`;
|
|
49
|
-
return controller.item(
|
|
50
|
+
return controller.item(element.getAttribute("kui-value") ?? void 0, () => ({
|
|
50
51
|
id,
|
|
51
52
|
...element.hasAttribute("kui-disabled") ? { disabled: true } : {},
|
|
52
53
|
...element.hasAttribute("kui-label") ? { label: element.getAttribute("kui-label") } : {},
|
package/src/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","names":[],"sources":["../../../../packages/web/src/command.ts"],"sourcesContent":["import { createCommand } from \"@kirana-ui/core/command\"\nimport type { Command, CommandGroup, CommandProps } from \"@kirana-ui/core/command\"\n\nimport { list, once
|
|
1
|
+
{"version":3,"file":"command.js","names":[],"sources":["../../../../packages/web/src/command.ts"],"sourcesContent":["import { createCommand } from \"@kirana-ui/core/command\"\nimport type { Command, CommandGroup, CommandProps } from \"@kirana-ui/core/command\"\n\nimport { list, once } from \"./around.ts\"\nimport { defineElement, partAround } from \"./runtime.ts\"\nimport type { ElementOf } from \"./runtime.ts\"\n\nconst groups = new WeakMap<HTMLElement, CommandGroup>()\nlet made = 0\nconst groupOf = (controller: Command, element: HTMLElement | null) =>\n once(groups, element, (group) =>\n controller.group(group.getAttribute(\"kui-id\") ?? `kui-command-group-${++made}`)\n )\n\n/**\n * `<kui-command>` around `kui-part=\"root\"`, an `input` and a `list` of `item`s (`kui-value`, its\n * `kui-label` or its text when left out, `kui-disabled`, `kui-label`, `kui-keywords` with commas between, `kui-id`), in `group`s\n * with a `group-heading` and `separator`s (`kui-always-render`) if it has them, and an\n * `empty` part drawn while nothing matches. What is typed filters the list; Enter or a press\n * runs an item. `input-value`, `default-input-value`, `loop`, `auto-highlight` (on unless `=\"false\"`), `disabled`; `filter` as a\n * property; it tells `input-value-change` and `select`.\n */\nexport const tag = defineElement<CommandProps, Command>({\n tag: \"kui-command\",\n props: {\n \"input-value\": \"string\",\n \"default-input-value\": \"string\",\n loop: \"boolean\",\n \"auto-highlight\": \"boolean\",\n disabled: \"boolean\",\n },\n properties: [\"filter\"],\n create: (props) => createCommand(props),\n changes: {\n onInputValueChange: { event: \"input-value-change\", prop: \"inputValue\" },\n onSelect: { event: \"select\", prop: \"value\", hold: false },\n },\n parts: {\n root: (controller) => controller.root,\n input: (controller) => controller.input,\n list: (controller) => controller.list,\n empty: (controller) => ({ part: controller.emptyPart, mounted: controller.empty }),\n group: (controller, element) => groupOf(controller, element)?.part,\n \"group-heading\": (controller, element) =>\n groups.get(partAround(element, \"group\")!)?.heading ?? controller.heading,\n item(controller, element) {\n const id = element.getAttribute(\"kui-id\") ?? `kui-command-item-${++made}`\n return controller.item(\n element.getAttribute(\"kui-value\") ?? undefined,\n () => ({\n id,\n ...(element.hasAttribute(\"kui-disabled\") ? { disabled: true } : {}),\n ...(element.hasAttribute(\"kui-label\")\n ? { label: element.getAttribute(\"kui-label\")! }\n : {}),\n ...(element.hasAttribute(\"kui-keywords\")\n ? { keywords: list(element.getAttribute(\"kui-keywords\"))! }\n : {}),\n }),\n groupOf(controller, element.parentElement && partAround(element.parentElement, \"group\"))\n )\n },\n separator: (controller, element) =>\n controller.separator(() => element.hasAttribute(\"kui-always-render\")),\n },\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-command\": ElementOf<\n typeof tag,\n { \"input-value-change\": [\"onInputValueChange\", \"inputValue\"]; select: [\"onSelect\", \"value\"] }\n >\n }\n}\n"],"mappings":";;;;AAOA,MAAM,yBAAS,IAAI,QAAmC;AACtD,IAAI,OAAO;AACX,MAAM,WAAW,YAAqB,YACpC,KAAK,QAAQ,UAAU,UACrB,WAAW,MAAM,MAAM,aAAa,QAAQ,KAAK,qBAAqB,EAAE,MAAM,CAChF;;;;;;;;;AAUF,MAAa,MAAM,cAAqC;CACtD,KAAK;CACL,OAAO;EACL,eAAe;EACf,uBAAuB;EACvB,MAAM;EACN,kBAAkB;EAClB,UAAU;CACZ;CACA,YAAY,CAAC,QAAQ;CACrB,SAAS,UAAU,cAAc,KAAK;CACtC,SAAS;EACP,oBAAoB;GAAE,OAAO;GAAsB,MAAM;EAAa;EACtE,UAAU;GAAE,OAAO;GAAU,MAAM;GAAS,MAAM;EAAM;CAC1D;CACA,OAAO;EACL,OAAO,eAAe,WAAW;EACjC,QAAQ,eAAe,WAAW;EAClC,OAAO,eAAe,WAAW;EACjC,QAAQ,gBAAgB;GAAE,MAAM,WAAW;GAAW,SAAS,WAAW;EAAM;EAChF,QAAQ,YAAY,YAAY,QAAQ,YAAY,OAAO,CAAC,EAAE;EAC9D,kBAAkB,YAAY,YAC5B,OAAO,IAAI,WAAW,SAAS,OAAO,CAAE,CAAC,EAAE,WAAW,WAAW;EACnE,KAAK,YAAY,SAAS;GACxB,MAAM,KAAK,QAAQ,aAAa,QAAQ,KAAK,oBAAoB,EAAE;GACnE,OAAO,WAAW,KAChB,QAAQ,aAAa,WAAW,KAAK,KAAA,UAC9B;IACL;IACA,GAAI,QAAQ,aAAa,cAAc,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACjE,GAAI,QAAQ,aAAa,WAAW,IAChC,EAAE,OAAO,QAAQ,aAAa,WAAW,EAAG,IAC5C,CAAC;IACL,GAAI,QAAQ,aAAa,cAAc,IACnC,EAAE,UAAU,KAAK,QAAQ,aAAa,cAAc,CAAC,EAAG,IACxD,CAAC;GACP,IACA,QAAQ,YAAY,QAAQ,iBAAiB,WAAW,QAAQ,eAAe,OAAO,CAAC,CACzF;EACF;EACA,YAAY,YAAY,YACtB,WAAW,gBAAgB,QAAQ,aAAa,mBAAmB,CAAC;CACxE;AACF,CAAC"}
|
package/src/context-menu.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ElementOf, Tag, Told } from "./runtime.js";
|
|
2
|
+
import { Placed } from "./around.js";
|
|
2
3
|
/**
|
|
3
4
|
* `<kui-context-menu>`: a menu for an area of the page, opened at the pointer by a secondary
|
|
4
5
|
* press, or a long one on a touch screen. Its `kui-part="trigger"` is the area; the rest are a
|
|
@@ -12,7 +13,7 @@ declare global {
|
|
|
12
13
|
}, {
|
|
13
14
|
"checked-change": Told<"checked", boolean>;
|
|
14
15
|
"value-change": Told<"value", string>;
|
|
15
|
-
}
|
|
16
|
+
}> & Placed;
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=context-menu.d.ts.map
|
package/src/context-menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-menu.js","names":["defineMenu"],"sources":["../../../../packages/web/src/context-menu.ts"],"sourcesContent":["import { defineMenu } from \"./menu.ts\"\nimport type { ElementOf, Told } from \"./runtime.ts\"\n\n/**\n * `<kui-context-menu>`: a menu for an area of the page, opened at the pointer by a secondary\n * press, or a long one on a touch screen. Its `kui-part=\"trigger\"` is the area; the rest are a\n * menu's parts.\n */\nexport const tag = defineMenu(\n \"kui-context-menu\",\n () => ({ context: true }),\n (controller) => controller.area\n)\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-context-menu\": ElementOf<\n typeof tag,\n { \"open-change\": [\"onOpenChange\", \"open\"] },\n { \"checked-change\": Told<\"checked\", boolean>; \"value-change\": Told<\"value\", string> }\n
|
|
1
|
+
{"version":3,"file":"context-menu.js","names":["defineMenu"],"sources":["../../../../packages/web/src/context-menu.ts"],"sourcesContent":["import { defineMenu } from \"./menu.ts\"\nimport type { Placed } from \"./around.ts\"\nimport type { ElementOf, Told } from \"./runtime.ts\"\n\n/**\n * `<kui-context-menu>`: a menu for an area of the page, opened at the pointer by a secondary\n * press, or a long one on a touch screen. Its `kui-part=\"trigger\"` is the area; the rest are a\n * menu's parts.\n */\nexport const tag = defineMenu(\n \"kui-context-menu\",\n () => ({ context: true }),\n (controller) => controller.area\n)\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-context-menu\": ElementOf<\n typeof tag,\n { \"open-change\": [\"onOpenChange\", \"open\"] },\n { \"checked-change\": Told<\"checked\", boolean>; \"value-change\": Told<\"value\", string> }\n > &\n Placed\n }\n}\n"],"mappings":";;;;;;;AASA,MAAa,MAAMA,KACjB,2BACO,EAAE,SAAS,KAAK,KACtB,eAAe,WAAW,IAC7B"}
|
package/src/date-field.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { DateField, DateFieldProps } from "@kirana-ui/core/date-field";
|
|
|
4
4
|
* `<kui-date-field>` around `kui-part="root"`, which holds a `<template kui-each="segments">`
|
|
5
5
|
* with the `segment` each part of the date is typed in (`{type}` and `{index}` say which),
|
|
6
6
|
* and the hidden `input` a form reads. `value`, `default-value`, `locale`, `min`, `max`,
|
|
7
|
-
* `disabled`, `read-only`, `required`, `name`, `form`; `placeholders`
|
|
8
|
-
* tells `value-change`.
|
|
7
|
+
* `disabled`, `read-only`, `required`, `name`, `form`; `placeholders` and `calendarSystem`
|
|
8
|
+
* (an instance from `@internationalized/date`) as properties; it tells `value-change`.
|
|
9
9
|
*/
|
|
10
10
|
export declare const tag: Tag<DateFieldProps, DateField>;
|
|
11
11
|
declare global {
|
package/src/date-field.js
CHANGED
|
@@ -7,8 +7,8 @@ const { parts, lists } = fieldParts((controller) => controller);
|
|
|
7
7
|
* `<kui-date-field>` around `kui-part="root"`, which holds a `<template kui-each="segments">`
|
|
8
8
|
* with the `segment` each part of the date is typed in (`{type}` and `{index}` say which),
|
|
9
9
|
* and the hidden `input` a form reads. `value`, `default-value`, `locale`, `min`, `max`,
|
|
10
|
-
* `disabled`, `read-only`, `required`, `name`, `form`; `placeholders`
|
|
11
|
-
* tells `value-change`.
|
|
10
|
+
* `disabled`, `read-only`, `required`, `name`, `form`; `placeholders` and `calendarSystem`
|
|
11
|
+
* (an instance from `@internationalized/date`) as properties; it tells `value-change`.
|
|
12
12
|
*/
|
|
13
13
|
const tag = defineElement({
|
|
14
14
|
tag: "kui-date-field",
|
|
@@ -24,7 +24,7 @@ const tag = defineElement({
|
|
|
24
24
|
name: "string",
|
|
25
25
|
form: "string"
|
|
26
26
|
},
|
|
27
|
-
properties: ["placeholders"],
|
|
27
|
+
properties: ["placeholders", "calendarSystem"],
|
|
28
28
|
create: (props) => createDateField(props),
|
|
29
29
|
changes: { onValueChange: {
|
|
30
30
|
event: "value-change",
|
package/src/date-field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/web/src/date-field.ts"],"sourcesContent":["import { createDateField } from \"@kirana-ui/core/date-field\"\nimport type { DateField, DateFieldProps } from \"@kirana-ui/core/date-field\"\n\nimport { fieldParts } from \"./dates.ts\"\nimport { defineElement } from \"./runtime.ts\"\nimport type { ElementOf } from \"./runtime.ts\"\n\nconst { parts, lists } = fieldParts<DateField>((controller) => controller)\n\n/**\n * `<kui-date-field>` around `kui-part=\"root\"`, which holds a `<template kui-each=\"segments\">`\n * with the `segment` each part of the date is typed in (`{type}` and `{index}` say which),\n * and the hidden `input` a form reads. `value`, `default-value`, `locale`, `min`, `max`,\n * `disabled`, `read-only`, `required`, `name`, `form`; `placeholders` as
|
|
1
|
+
{"version":3,"file":"date-field.js","names":[],"sources":["../../../../packages/web/src/date-field.ts"],"sourcesContent":["import { createDateField } from \"@kirana-ui/core/date-field\"\nimport type { DateField, DateFieldProps } from \"@kirana-ui/core/date-field\"\n\nimport { fieldParts } from \"./dates.ts\"\nimport { defineElement } from \"./runtime.ts\"\nimport type { ElementOf } from \"./runtime.ts\"\n\nconst { parts, lists } = fieldParts<DateField>((controller) => controller)\n\n/**\n * `<kui-date-field>` around `kui-part=\"root\"`, which holds a `<template kui-each=\"segments\">`\n * with the `segment` each part of the date is typed in (`{type}` and `{index}` say which),\n * and the hidden `input` a form reads. `value`, `default-value`, `locale`, `min`, `max`,\n * `disabled`, `read-only`, `required`, `name`, `form`; `placeholders` and `calendarSystem`\n * (an instance from `@internationalized/date`) as properties; it tells `value-change`.\n */\nexport const tag = defineElement<DateFieldProps, DateField>({\n tag: \"kui-date-field\",\n props: {\n value: \"string\",\n \"default-value\": \"string\",\n locale: \"string\",\n min: \"string\",\n max: \"string\",\n disabled: \"boolean\",\n \"read-only\": \"boolean\",\n required: \"boolean\",\n name: \"string\",\n form: \"string\",\n },\n properties: [\"placeholders\", \"calendarSystem\"],\n create: (props) => createDateField(props),\n changes: { onValueChange: { event: \"value-change\", prop: \"value\" } },\n lists,\n parts: { root: (controller) => controller.root, ...parts },\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-date-field\": ElementOf<typeof tag, { \"value-change\": [\"onValueChange\", \"value\"] }>\n }\n}\n"],"mappings":";;;;AAOA,MAAM,EAAE,OAAO,UAAU,YAAuB,eAAe,UAAU;;;;;;;;AASzE,MAAa,MAAM,cAAyC;CAC1D,KAAK;CACL,OAAO;EACL,OAAO;EACP,iBAAiB;EACjB,QAAQ;EACR,KAAK;EACL,KAAK;EACL,UAAU;EACV,aAAa;EACb,UAAU;EACV,MAAM;EACN,MAAM;CACR;CACA,YAAY,CAAC,gBAAgB,gBAAgB;CAC7C,SAAS,UAAU,gBAAgB,KAAK;CACxC,SAAS,EAAE,eAAe;EAAE,OAAO;EAAgB,MAAM;CAAQ,EAAE;CACnE;CACA,OAAO;EAAE,OAAO,eAAe,WAAW;EAAM,GAAG;CAAM;AAC3D,CAAC"}
|
package/src/date-picker.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { ElementOf, Tag } from "./runtime.js";
|
|
2
|
+
import { Placed } from "./around.js";
|
|
2
3
|
import { DatePicker, DatePickerProps } from "@kirana-ui/core/date-picker";
|
|
3
4
|
/**
|
|
4
5
|
* `<kui-date-picker>`: a date field and a calendar in a popover that are one value. A
|
|
5
|
-
* `kui-part="field"` with a date field's `segments` template and `input
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
9
|
-
*
|
|
10
|
-
* `
|
|
6
|
+
* `kui-part="field"` with a date field's `segments` template and `input` (with `mode="range"`,
|
|
7
|
+
* two: `kui-range="start"` and `kui-range="end"`); a `trigger` button; a `clear` button and
|
|
8
|
+
* `preset` buttons (`kui-value`: a day, or a range's first and last with a comma between);
|
|
9
|
+
* and a `portal` with a `positioner` around the `popup`, which holds the `calendar` with a
|
|
10
|
+
* calendar's parts and templates. `value` (a range as a preset's), `default-value`, `mode`,
|
|
11
|
+
* `open`, `default-open`,
|
|
12
|
+
* `locale`, `min`, `max`, `calendar-system`, `fixed-weeks`, `months` (each drawn in a
|
|
13
|
+
* `<template kui-each="months">`), `paged-navigation`, `month`, `default-month`, `disabled`,
|
|
14
|
+
* `read-only`, `required`, `name`, `form`; `isDateUnavailable` and `placeholders` as
|
|
15
|
+
* properties; it tells `value-change`, `open-change` and `month-change`.
|
|
11
16
|
*/
|
|
12
|
-
export declare const tag: Tag<DatePickerProps
|
|
17
|
+
export declare const tag: Tag<DatePickerProps<import("@kirana-ui/core/date-picker").DatePickerMode>, DatePicker & {
|
|
13
18
|
mounted: unknown;
|
|
14
19
|
}>;
|
|
15
20
|
declare global {
|
|
@@ -17,7 +22,8 @@ declare global {
|
|
|
17
22
|
"kui-date-picker": ElementOf<typeof tag, {
|
|
18
23
|
"value-change": ["onValueChange", "value"];
|
|
19
24
|
"open-change": ["onOpenChange", "open"];
|
|
20
|
-
|
|
25
|
+
"month-change": ["onMonthChange", "month"];
|
|
26
|
+
}> & Placed;
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
//# sourceMappingURL=date-picker.d.ts.map
|
package/src/date-picker.js
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
1
|
import { positioner } from "./around.js";
|
|
2
2
|
import { calendarParts, fieldParts } from "./dates.js";
|
|
3
3
|
import { defineElement } from "./runtime.js";
|
|
4
|
+
import { computed } from "@kirana-ui/core";
|
|
4
5
|
import { createDatePicker } from "@kirana-ui/core/date-picker";
|
|
5
6
|
// src/date-picker.ts
|
|
6
|
-
|
|
7
|
+
/** The field an element is written in: the last day's in a `kui-range="end"` field. */
|
|
8
|
+
const fieldOf = (controller, element) => element.closest("[kui-part=\"field\"]")?.getAttribute("kui-range") === "end" && controller.endField || controller.field;
|
|
9
|
+
/** A value as an attribute writes it: a day, or a range's first and last with a comma between. */
|
|
10
|
+
function valueOf(given, range) {
|
|
11
|
+
if (typeof given !== "string" || !range) return given;
|
|
12
|
+
if (given === "") return null;
|
|
13
|
+
const [start, end] = given.split(",");
|
|
14
|
+
return {
|
|
15
|
+
start: start || null,
|
|
16
|
+
end: end || null
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const field = fieldParts(fieldOf);
|
|
7
20
|
const calendar = calendarParts((controller) => controller.calendar);
|
|
8
21
|
/**
|
|
9
22
|
* `<kui-date-picker>`: a date field and a calendar in a popover that are one value. A
|
|
10
|
-
* `kui-part="field"` with a date field's `segments` template and `input
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
14
|
-
*
|
|
15
|
-
* `
|
|
23
|
+
* `kui-part="field"` with a date field's `segments` template and `input` (with `mode="range"`,
|
|
24
|
+
* two: `kui-range="start"` and `kui-range="end"`); a `trigger` button; a `clear` button and
|
|
25
|
+
* `preset` buttons (`kui-value`: a day, or a range's first and last with a comma between);
|
|
26
|
+
* and a `portal` with a `positioner` around the `popup`, which holds the `calendar` with a
|
|
27
|
+
* calendar's parts and templates. `value` (a range as a preset's), `default-value`, `mode`,
|
|
28
|
+
* `open`, `default-open`,
|
|
29
|
+
* `locale`, `min`, `max`, `calendar-system`, `fixed-weeks`, `months` (each drawn in a
|
|
30
|
+
* `<template kui-each="months">`), `paged-navigation`, `month`, `default-month`, `disabled`,
|
|
31
|
+
* `read-only`, `required`, `name`, `form`; `isDateUnavailable` and `placeholders` as
|
|
32
|
+
* properties; it tells `value-change`, `open-change` and `month-change`.
|
|
16
33
|
*/
|
|
17
34
|
const tag = defineElement({
|
|
18
35
|
tag: "kui-date-picker",
|
|
19
36
|
props: {
|
|
20
37
|
value: "string",
|
|
21
38
|
"default-value": "string",
|
|
39
|
+
mode: "string",
|
|
22
40
|
open: "boolean",
|
|
23
41
|
"default-open": "boolean",
|
|
24
42
|
locale: "string",
|
|
@@ -26,6 +44,10 @@ const tag = defineElement({
|
|
|
26
44
|
max: "string",
|
|
27
45
|
"calendar-system": "string",
|
|
28
46
|
"fixed-weeks": "boolean",
|
|
47
|
+
months: "number",
|
|
48
|
+
"paged-navigation": "boolean",
|
|
49
|
+
month: "string",
|
|
50
|
+
"default-month": "string",
|
|
29
51
|
disabled: "boolean",
|
|
30
52
|
"read-only": "boolean",
|
|
31
53
|
required: "boolean",
|
|
@@ -34,7 +56,15 @@ const tag = defineElement({
|
|
|
34
56
|
},
|
|
35
57
|
properties: ["isDateUnavailable", "placeholders"],
|
|
36
58
|
create(props) {
|
|
37
|
-
const
|
|
59
|
+
const range = props.peek().mode === "range";
|
|
60
|
+
const picker = createDatePicker(computed(() => {
|
|
61
|
+
const own = props.get();
|
|
62
|
+
return {
|
|
63
|
+
...own,
|
|
64
|
+
value: valueOf(own.value, range),
|
|
65
|
+
defaultValue: valueOf(own.defaultValue, range)
|
|
66
|
+
};
|
|
67
|
+
}));
|
|
38
68
|
return {
|
|
39
69
|
...picker,
|
|
40
70
|
mounted: picker.popover.mounted
|
|
@@ -48,6 +78,10 @@ const tag = defineElement({
|
|
|
48
78
|
onOpenChange: {
|
|
49
79
|
event: "open-change",
|
|
50
80
|
prop: "open"
|
|
81
|
+
},
|
|
82
|
+
onMonthChange: {
|
|
83
|
+
event: "month-change",
|
|
84
|
+
prop: "month"
|
|
51
85
|
}
|
|
52
86
|
},
|
|
53
87
|
lists: {
|
|
@@ -55,13 +89,18 @@ const tag = defineElement({
|
|
|
55
89
|
...calendar.lists
|
|
56
90
|
},
|
|
57
91
|
parts: {
|
|
58
|
-
field: (controller) => controller.
|
|
92
|
+
field: (controller, element) => fieldOf(controller, element).root,
|
|
59
93
|
...field.parts,
|
|
60
94
|
trigger: (controller) => controller.popover.trigger,
|
|
61
95
|
positioner: (controller, element) => positioner(controller.popover, element),
|
|
62
96
|
popup: (controller) => controller.popover.popup,
|
|
63
97
|
calendar: (controller) => controller.calendar.root,
|
|
64
|
-
...calendar.parts
|
|
98
|
+
...calendar.parts,
|
|
99
|
+
clear: (controller) => controller.clear,
|
|
100
|
+
preset(controller, element) {
|
|
101
|
+
const given = element.getAttribute("kui-value") ?? "";
|
|
102
|
+
return controller.preset(given.includes(",") ? valueOf(given, true) : given);
|
|
103
|
+
}
|
|
65
104
|
}
|
|
66
105
|
});
|
|
67
106
|
export { tag };
|
package/src/date-picker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-picker.js","names":[],"sources":["../../../../packages/web/src/date-picker.ts"],"sourcesContent":["import { createDatePicker } from \"@kirana-ui/core/date-picker\"\nimport type {
|
|
1
|
+
{"version":3,"file":"date-picker.js","names":[],"sources":["../../../../packages/web/src/date-picker.ts"],"sourcesContent":["import { computed } from \"@kirana-ui/core\"\nimport { createDatePicker } from \"@kirana-ui/core/date-picker\"\nimport type {\n DatePicker,\n DatePickerProps,\n DatePickerRange,\n DatePickerValue,\n} from \"@kirana-ui/core/date-picker\"\n\nimport { positioner } from \"./around.ts\"\nimport type { Placed } from \"./around.ts\"\nimport { calendarParts, fieldParts } from \"./dates.ts\"\nimport { defineElement } from \"./runtime.ts\"\nimport type { ElementOf } from \"./runtime.ts\"\n\n/** The field an element is written in: the last day's in a `kui-range=\"end\"` field. */\nconst fieldOf = (controller: DatePicker, element: HTMLElement) =>\n (element.closest('[kui-part=\"field\"]')?.getAttribute(\"kui-range\") === \"end\" &&\n controller.endField) ||\n controller.field\n/** A value as an attribute writes it: a day, or a range's first and last with a comma between. */\nfunction valueOf(given: unknown, range: boolean): DatePickerValue | undefined {\n if (typeof given !== \"string\" || !range) return given as DatePickerValue | undefined\n if (given === \"\") return null\n const [start, end] = given.split(\",\")\n return { start: start || null, end: end || null } satisfies DatePickerRange\n}\nconst field = fieldParts<DatePicker>(fieldOf)\nconst calendar = calendarParts<DatePicker>((controller) => controller.calendar)\n\n/**\n * `<kui-date-picker>`: a date field and a calendar in a popover that are one value. A\n * `kui-part=\"field\"` with a date field's `segments` template and `input` (with `mode=\"range\"`,\n * two: `kui-range=\"start\"` and `kui-range=\"end\"`); a `trigger` button; a `clear` button and\n * `preset` buttons (`kui-value`: a day, or a range's first and last with a comma between);\n * and a `portal` with a `positioner` around the `popup`, which holds the `calendar` with a\n * calendar's parts and templates. `value` (a range as a preset's), `default-value`, `mode`,\n * `open`, `default-open`,\n * `locale`, `min`, `max`, `calendar-system`, `fixed-weeks`, `months` (each drawn in a\n * `<template kui-each=\"months\">`), `paged-navigation`, `month`, `default-month`, `disabled`,\n * `read-only`, `required`, `name`, `form`; `isDateUnavailable` and `placeholders` as\n * properties; it tells `value-change`, `open-change` and `month-change`.\n */\nexport const tag = defineElement<DatePickerProps, DatePicker & { mounted: unknown }>({\n tag: \"kui-date-picker\",\n props: {\n value: \"string\",\n \"default-value\": \"string\",\n mode: \"string\",\n open: \"boolean\",\n \"default-open\": \"boolean\",\n locale: \"string\",\n min: \"string\",\n max: \"string\",\n \"calendar-system\": \"string\",\n \"fixed-weeks\": \"boolean\",\n months: \"number\",\n \"paged-navigation\": \"boolean\",\n month: \"string\",\n \"default-month\": \"string\",\n disabled: \"boolean\",\n \"read-only\": \"boolean\",\n required: \"boolean\",\n name: \"string\",\n form: \"string\",\n },\n properties: [\"isDateUnavailable\", \"placeholders\"],\n create(props) {\n const range = props.peek().mode === \"range\"\n const picker = createDatePicker(\n computed(() => {\n const own = props.get()\n return {\n ...own,\n value: valueOf(own.value, range),\n defaultValue: valueOf(own.defaultValue, range),\n }\n })\n )\n // What a portal waits for: the popover's.\n return { ...picker, mounted: picker.popover.mounted }\n },\n changes: {\n onValueChange: { event: \"value-change\", prop: \"value\" },\n onOpenChange: { event: \"open-change\", prop: \"open\" },\n onMonthChange: { event: \"month-change\", prop: \"month\" },\n },\n lists: { ...field.lists, ...calendar.lists },\n parts: {\n field: (controller, element) => fieldOf(controller, element).root,\n ...field.parts,\n trigger: (controller) => controller.popover.trigger,\n positioner: (controller, element) => positioner(controller.popover, element),\n popup: (controller) => controller.popover.popup,\n calendar: (controller) => controller.calendar.root,\n ...calendar.parts,\n clear: (controller) => controller.clear,\n preset(controller, element) {\n const given = element.getAttribute(\"kui-value\") ?? \"\"\n // A range is written as its first and its last day with a comma between.\n return controller.preset(\n given.includes(\",\") ? (valueOf(given, true) as DatePickerRange) : given\n )\n },\n },\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-date-picker\": ElementOf<\n typeof tag,\n {\n \"value-change\": [\"onValueChange\", \"value\"]\n \"open-change\": [\"onOpenChange\", \"open\"]\n \"month-change\": [\"onMonthChange\", \"month\"]\n }\n > &\n Placed\n }\n}\n"],"mappings":";;;;;;;AAgBA,MAAM,WAAW,YAAwB,YACtC,QAAQ,QAAQ,sBAAoB,CAAC,EAAE,aAAa,WAAW,MAAM,SACpE,WAAW,YACb,WAAW;;AAEb,SAAS,QAAQ,OAAgB,OAA6C;CAC5E,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,OAAO;CAChD,IAAI,UAAU,IAAI,OAAO;CACzB,MAAM,CAAC,OAAO,OAAO,MAAM,MAAM,GAAG;CACpC,OAAO;EAAE,OAAO,SAAS;EAAM,KAAK,OAAO;CAAK;AAClD;AACA,MAAM,QAAQ,WAAuB,OAAO;AAC5C,MAAM,WAAW,eAA2B,eAAe,WAAW,QAAQ;;;;;;;;;;;;;;AAe9E,MAAa,MAAM,cAAkE;CACnF,KAAK;CACL,OAAO;EACL,OAAO;EACP,iBAAiB;EACjB,MAAM;EACN,MAAM;EACN,gBAAgB;EAChB,QAAQ;EACR,KAAK;EACL,KAAK;EACL,mBAAmB;EACnB,eAAe;EACf,QAAQ;EACR,oBAAoB;EACpB,OAAO;EACP,iBAAiB;EACjB,UAAU;EACV,aAAa;EACb,UAAU;EACV,MAAM;EACN,MAAM;CACR;CACA,YAAY,CAAC,qBAAqB,cAAc;CAChD,OAAO,OAAO;EACZ,MAAM,QAAQ,MAAM,KAAK,CAAC,CAAC,SAAS;EACpC,MAAM,SAAS,iBACb,eAAe;GACb,MAAM,MAAM,MAAM,IAAI;GACtB,OAAO;IACL,GAAG;IACH,OAAO,QAAQ,IAAI,OAAO,KAAK;IAC/B,cAAc,QAAQ,IAAI,cAAc,KAAK;GAC/C;EACF,CAAC,CACH;EAEA,OAAO;GAAE,GAAG;GAAQ,SAAS,OAAO,QAAQ;EAAQ;CACtD;CACA,SAAS;EACP,eAAe;GAAE,OAAO;GAAgB,MAAM;EAAQ;EACtD,cAAc;GAAE,OAAO;GAAe,MAAM;EAAO;EACnD,eAAe;GAAE,OAAO;GAAgB,MAAM;EAAQ;CACxD;CACA,OAAO;EAAE,GAAG,MAAM;EAAO,GAAG,SAAS;CAAM;CAC3C,OAAO;EACL,QAAQ,YAAY,YAAY,QAAQ,YAAY,OAAO,CAAC,CAAC;EAC7D,GAAG,MAAM;EACT,UAAU,eAAe,WAAW,QAAQ;EAC5C,aAAa,YAAY,YAAY,WAAW,WAAW,SAAS,OAAO;EAC3E,QAAQ,eAAe,WAAW,QAAQ;EAC1C,WAAW,eAAe,WAAW,SAAS;EAC9C,GAAG,SAAS;EACZ,QAAQ,eAAe,WAAW;EAClC,OAAO,YAAY,SAAS;GAC1B,MAAM,QAAQ,QAAQ,aAAa,WAAW,KAAK;GAEnD,OAAO,WAAW,OAChB,MAAM,SAAS,GAAG,IAAK,QAAQ,OAAO,IAAI,IAAwB,KACpE;EACF;CACF;AACF,CAAC"}
|