@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirana-ui/web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Kirana UI Primitives as custom elements, for a page with no framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "The Kirana authors",
|
|
@@ -59,10 +59,18 @@
|
|
|
59
59
|
"types": "./src/checkbox.d.ts",
|
|
60
60
|
"default": "./src/checkbox.js"
|
|
61
61
|
},
|
|
62
|
+
"./checkbox-group": {
|
|
63
|
+
"types": "./src/checkbox-group.d.ts",
|
|
64
|
+
"default": "./src/checkbox-group.js"
|
|
65
|
+
},
|
|
62
66
|
"./collapsible": {
|
|
63
67
|
"types": "./src/collapsible.d.ts",
|
|
64
68
|
"default": "./src/collapsible.js"
|
|
65
69
|
},
|
|
70
|
+
"./color-picker": {
|
|
71
|
+
"types": "./src/color-picker.d.ts",
|
|
72
|
+
"default": "./src/color-picker.js"
|
|
73
|
+
},
|
|
66
74
|
"./combobox": {
|
|
67
75
|
"types": "./src/combobox.d.ts",
|
|
68
76
|
"default": "./src/combobox.js"
|
|
@@ -91,6 +99,10 @@
|
|
|
91
99
|
"types": "./src/drawer.d.ts",
|
|
92
100
|
"default": "./src/drawer.js"
|
|
93
101
|
},
|
|
102
|
+
"./editable": {
|
|
103
|
+
"types": "./src/editable.d.ts",
|
|
104
|
+
"default": "./src/editable.js"
|
|
105
|
+
},
|
|
94
106
|
"./field": {
|
|
95
107
|
"types": "./src/field.d.ts",
|
|
96
108
|
"default": "./src/field.js"
|
|
@@ -99,6 +111,10 @@
|
|
|
99
111
|
"types": "./src/fieldset.d.ts",
|
|
100
112
|
"default": "./src/fieldset.js"
|
|
101
113
|
},
|
|
114
|
+
"./file-upload": {
|
|
115
|
+
"types": "./src/file-upload.d.ts",
|
|
116
|
+
"default": "./src/file-upload.js"
|
|
117
|
+
},
|
|
102
118
|
"./form": {
|
|
103
119
|
"types": "./src/form.d.ts",
|
|
104
120
|
"default": "./src/form.js"
|
|
@@ -151,6 +167,10 @@
|
|
|
151
167
|
"types": "./src/pagination.d.ts",
|
|
152
168
|
"default": "./src/pagination.js"
|
|
153
169
|
},
|
|
170
|
+
"./password-input": {
|
|
171
|
+
"types": "./src/password-input.d.ts",
|
|
172
|
+
"default": "./src/password-input.js"
|
|
173
|
+
},
|
|
154
174
|
"./popover": {
|
|
155
175
|
"types": "./src/popover.d.ts",
|
|
156
176
|
"default": "./src/popover.js"
|
|
@@ -167,6 +187,10 @@
|
|
|
167
187
|
"types": "./src/radio-group.d.ts",
|
|
168
188
|
"default": "./src/radio-group.js"
|
|
169
189
|
},
|
|
190
|
+
"./rating": {
|
|
191
|
+
"types": "./src/rating.d.ts",
|
|
192
|
+
"default": "./src/rating.js"
|
|
193
|
+
},
|
|
170
194
|
"./resizable": {
|
|
171
195
|
"types": "./src/resizable.d.ts",
|
|
172
196
|
"default": "./src/resizable.js"
|
|
@@ -187,6 +211,10 @@
|
|
|
187
211
|
"types": "./src/slider.d.ts",
|
|
188
212
|
"default": "./src/slider.js"
|
|
189
213
|
},
|
|
214
|
+
"./steps": {
|
|
215
|
+
"types": "./src/steps.d.ts",
|
|
216
|
+
"default": "./src/steps.js"
|
|
217
|
+
},
|
|
190
218
|
"./switch": {
|
|
191
219
|
"types": "./src/switch.d.ts",
|
|
192
220
|
"default": "./src/switch.js"
|
|
@@ -195,6 +223,14 @@
|
|
|
195
223
|
"types": "./src/tabs.d.ts",
|
|
196
224
|
"default": "./src/tabs.js"
|
|
197
225
|
},
|
|
226
|
+
"./tags-input": {
|
|
227
|
+
"types": "./src/tags-input.d.ts",
|
|
228
|
+
"default": "./src/tags-input.js"
|
|
229
|
+
},
|
|
230
|
+
"./time-field": {
|
|
231
|
+
"types": "./src/time-field.d.ts",
|
|
232
|
+
"default": "./src/time-field.js"
|
|
233
|
+
},
|
|
198
234
|
"./toast": {
|
|
199
235
|
"types": "./src/toast.d.ts",
|
|
200
236
|
"default": "./src/toast.js"
|
|
@@ -215,10 +251,18 @@
|
|
|
215
251
|
"types": "./src/tooltip.d.ts",
|
|
216
252
|
"default": "./src/tooltip.js"
|
|
217
253
|
},
|
|
254
|
+
"./tour": {
|
|
255
|
+
"types": "./src/tour.d.ts",
|
|
256
|
+
"default": "./src/tour.js"
|
|
257
|
+
},
|
|
258
|
+
"./tree": {
|
|
259
|
+
"types": "./src/tree.d.ts",
|
|
260
|
+
"default": "./src/tree.js"
|
|
261
|
+
},
|
|
218
262
|
"./package.json": "./package.json"
|
|
219
263
|
},
|
|
220
264
|
"dependencies": {
|
|
221
|
-
"@kirana-ui/core": "0.
|
|
265
|
+
"@kirana-ui/core": "0.4.0"
|
|
222
266
|
},
|
|
223
267
|
"homepage": "https://ui.kirana.style",
|
|
224
268
|
"repository": {
|
|
@@ -238,6 +282,7 @@
|
|
|
238
282
|
"REFERENCE.md",
|
|
239
283
|
"llms.txt",
|
|
240
284
|
"skills",
|
|
241
|
-
"LICENSE"
|
|
285
|
+
"LICENSE",
|
|
286
|
+
"CHANGELOG.md"
|
|
242
287
|
]
|
|
243
288
|
}
|
|
@@ -33,10 +33,16 @@ from one core. The package for a framework is all a project installs.
|
|
|
33
33
|
A popup that is placed against its trigger (a popover, a menu, a select, a combobox, a
|
|
34
34
|
tooltip, a hover card) is `Portal > Positioner > Popup`: the `Positioner` takes `side`
|
|
35
35
|
(also `inline-start` and `inline-end`, which turn with the reading direction, and which
|
|
36
|
-
`data-side` then says), `align`, `sideOffset
|
|
36
|
+
`data-side` then says), `align`, `sideOffset` and `alignOffset` (a number, or a function
|
|
37
|
+
of the anchor's and the positioner's sizes), `collisionPadding` (a number, or one a side),
|
|
38
|
+
`collisionBoundary`, `collisionAvoidance`, `sticky`, `arrowPadding`, `positionMethod`, and
|
|
37
39
|
`anchor` for another element than its trigger to be placed against (an element, the
|
|
38
|
-
framework's own ref to one, or a function that gives one). A
|
|
39
|
-
|
|
40
|
+
framework's own ref to one, or a function that gives one). A popup that holds an `Arrow`
|
|
41
|
+
is given `position: relative`, so the arrow is placed in it through its entrance and
|
|
42
|
+
after. A popover may have a `Backdrop` in its portal, is `modal` (`true`: the page is
|
|
43
|
+
inert and does not scroll; `"trap-focus"`: only Tab is kept inside), and its trigger's
|
|
44
|
+
`openOnHover` lets the pointer open it too. A dialog, an alert dialog and a drawer have
|
|
45
|
+
no positioner: `Portal > Backdrop` and `Popup`, placed by the design.
|
|
40
46
|
3. Style by attributes and variables, never by guessing class names:
|
|
41
47
|
- a boolean state is present or absent: `[data-open]`, never `[data-open="true"]`;
|
|
42
48
|
- an entrance starts from `[data-starting-style]`, an exit ends at
|
|
@@ -46,17 +52,19 @@ from one core. The package for a framework is all a project installs.
|
|
|
46
52
|
4. A value is controlled when given (`value` + `onValueChange`) and the component's own
|
|
47
53
|
otherwise (`defaultValue`). A callback beside a value the component holds is
|
|
48
54
|
`(value, details)`, and `details.cancel()` keeps the value as it was. A callback that
|
|
49
|
-
reports something that happened (`
|
|
50
|
-
|
|
55
|
+
reports something that happened (`onClearErrors`, `onMonthChange`) takes only that. The
|
|
56
|
+
names are Base UI's: `loopFocus`, `disablePointerDismissal`, a multiple Select's or
|
|
57
|
+
Combobox's list in `value`, One-Time Code's `validationType` and `onValueComplete`, a
|
|
58
|
+
toast's `timeout`; the older names still work and are marked deprecated.
|
|
51
59
|
5. A control with a `name` is submitted with its form and follows the form's reset. Wrap it
|
|
52
60
|
in `Field` for a label, a description and validation. `readOnly` and `keepMounted` are
|
|
53
61
|
props of the parts `llms.txt` lists them for, and of no others.
|
|
54
62
|
|
|
55
63
|
Per framework: React takes `render` for another element; Vue takes `as` / `as-child`, binds
|
|
56
64
|
with `v-model:value` and names props in kebab case; Svelte takes a `child` snippet and
|
|
57
|
-
`bind:value`; Solid takes `as` and `render`; Angular's parts are directives on your own
|
|
58
|
-
elements (`<button
|
|
59
|
-
a part that comes and goes is structural (`*
|
|
65
|
+
`bind:value`; Solid (2, with `@solidjs/web`) takes `as` and `render`; Angular's parts are directives on your own
|
|
66
|
+
elements (`<button kpDialogTrigger>`), bound with `[(value)]`, with `[kpId]` for an id, and
|
|
67
|
+
a part that comes and goes is structural (`*kpDialogPortal`, `*kpTabsPanel`: the list is in
|
|
60
68
|
`llms.txt`); custom elements name each part with `kui-part` inside `<kui-dialog>`.
|
|
61
69
|
|
|
62
70
|
Composing a part with another element: with React's `render={<a … />}` and Vue's `as-child`
|
|
@@ -72,9 +80,24 @@ the text a part writes (`Meter.Value`, `Select.Value`) stay inside it on React a
|
|
|
72
80
|
`props().children` on Solid, and are given to a Svelte `child` snippet to render
|
|
73
81
|
(`{ props, state, input }`, `{ props, state, text }`). A handler given to a part is typed
|
|
74
82
|
with `preventKiranaHandler()` (`PartEvent`, exported by each package). For an element of the
|
|
75
|
-
design system's own
|
|
76
|
-
`@kirana-ui/react/use-render`,
|
|
77
|
-
|
|
83
|
+
design system's own composed as a part is, use `useRender` and `mergeProps` from
|
|
84
|
+
`@kirana-ui/react/use-render`, `Primitive` from `@kirana-ui/vue/primitive`, or `Primitive`
|
|
85
|
+
and `mergeProps` from `@kirana-ui/solid/primitive` and `@kirana-ui/svelte/primitive` (Solid's
|
|
86
|
+
`as` and `render`, Svelte's `as` and `child`, a `state` written as `data-*`); never write
|
|
87
|
+
another merge. On Angular such an element is a directive of your own with host bindings, and
|
|
88
|
+
custom elements need nothing: the page writes its own element.
|
|
89
|
+
|
|
90
|
+
A design system on Angular hosts each primitive in a directive of its own
|
|
91
|
+
(`hostDirectives: [{ directive: KpDialog, inputs: [...], outputs: [...] }]`), exposing what
|
|
92
|
+
its callers set; gives the primitive the rest with `hostInputs(KpTooltip, { delay: () => 0 })`
|
|
93
|
+
in its constructor (each value a function read like a signal, so `computed` values follow;
|
|
94
|
+
an input the element binds wins), never a subclass of the primitive; draws a structural part
|
|
95
|
+
(`kpDialogPortal`) in a component's template around `<ng-content />` (a part given to it finds
|
|
96
|
+
its root where it is written); and names its own directives as it likes, `kui…` included:
|
|
97
|
+
the primitives are `kp…` so that no design system's selector is theirs (two directives with
|
|
98
|
+
one selector both match, silently, and a component whose selector is its host's recurses).
|
|
99
|
+
Tooltips need no provider on any
|
|
100
|
+
framework: a design system passes `delay` on its own tooltip root (`hostInputs` on Angular).
|
|
78
101
|
|
|
79
102
|
## When something is wrong
|
|
80
103
|
|
|
@@ -115,7 +138,25 @@ component's ref, kind, label, state and actions), `act({ steps: [{ ref, action,
|
|
|
115
138
|
through the component's own handlers: its callback runs with `details.source === "agent"`
|
|
116
139
|
and may cancel. Give every control an accessible name (a `<label>`, `aria-label`): it is how
|
|
117
140
|
an agent finds it. Mark a destructive control `data-agent-confirm="what it does"`, private
|
|
118
|
-
regions `data-agent-hidden`, secrets `data-agent-secret
|
|
141
|
+
regions `data-agent-hidden`, secrets `data-agent-secret` (whatever is inside is listed with its
|
|
142
|
+
name and its actions, never its value, its choices or whether it is checked). A bridge given a
|
|
143
|
+
`root` also reads what was opened from inside it (a dialog, a menu, a select's list), by the
|
|
144
|
+
`aria-controls` of what opened it. A step names its control by ref, by its label, by words of
|
|
145
|
+
the label, by the text of its row or by one of its choices; a name two controls answer to
|
|
146
|
+
fails with both. `subscribe((changed, changes) => …)` says of each change its `key`, `value`,
|
|
147
|
+
`previous`, `source` and `reason`; `record()` keeps a person's changes in `history()` beside
|
|
148
|
+
the agent's, each with its `source` and a sentence (`text`), and `undoSource("agent")` takes
|
|
149
|
+
back only the agent's. `stage({ steps })` shows a suggestion in the controls and gives
|
|
150
|
+
`revert()` and `keep()`. `act` takes a `signal`; `timeout` bounds a wait for `allow` or
|
|
151
|
+
`confirm`. A component of your own is read through `kinds` (`AgentKind`: a selector, `read`,
|
|
152
|
+
`perform`). A slider's `setValue` fails with what the slider holds when
|
|
153
|
+
its range or step does not hold the value asked for, and so does a spin button's (a Date or
|
|
154
|
+
Time Field's part, typed as a person types it). The thumbs of a range named by their group
|
|
155
|
+
are told apart by their place (`"Price, 1 of 2"`). A list of several values (a listbox, a
|
|
156
|
+
select with `multiple`, a tree) says `values` and takes a list in `setValue`; a closed
|
|
157
|
+
select's are known once its list has been read. A tree is one component: its shown nodes
|
|
158
|
+
are its `items` (with `level` below the top and `open` for a branch), and `setValue`,
|
|
159
|
+
`open` and `close` take a node's name. `allow(action)` is the policy,
|
|
119
160
|
asked for every step; `confirm(action)` is a person's answer, asked for a step on something
|
|
120
161
|
marked `data-agent-confirm`, and without it such a step fails with "Needs a person" whatever
|
|
121
162
|
`allow` says. Never write `confirm: () => true`: open a dialog and resolve with what the
|
package/src/accordion.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Accordion, AccordionProps } from "@kirana-ui/core/accordion";
|
|
|
5
5
|
* `trigger` button and a `panel` that is in the page while its item is open. An item's
|
|
6
6
|
* `kui-value` tells it from the others; an item that is given none makes its own.
|
|
7
7
|
* `value` and `default-value` (the open items, with commas between), `multiple`, `disabled`,
|
|
8
|
-
* `orientation`, `loop
|
|
8
|
+
* `orientation`, `loop-focus` (`loop` is its older name); it tells `value-change`.
|
|
9
9
|
*/
|
|
10
10
|
export declare const tag: Tag<Omit<AccordionProps<string>, "defaultValue" | "value"> & {
|
|
11
11
|
value?: string | readonly string[];
|
package/src/accordion.js
CHANGED
|
@@ -19,7 +19,7 @@ function itemOf(controller, element) {
|
|
|
19
19
|
* `trigger` button and a `panel` that is in the page while its item is open. An item's
|
|
20
20
|
* `kui-value` tells it from the others; an item that is given none makes its own.
|
|
21
21
|
* `value` and `default-value` (the open items, with commas between), `multiple`, `disabled`,
|
|
22
|
-
* `orientation`, `loop
|
|
22
|
+
* `orientation`, `loop-focus` (`loop` is its older name); it tells `value-change`.
|
|
23
23
|
*/
|
|
24
24
|
const tag = defineElement({
|
|
25
25
|
tag: "kui-accordion",
|
|
@@ -29,6 +29,7 @@ const tag = defineElement({
|
|
|
29
29
|
multiple: "boolean",
|
|
30
30
|
disabled: "boolean",
|
|
31
31
|
orientation: "string",
|
|
32
|
+
"loop-focus": "boolean",
|
|
32
33
|
loop: "boolean"
|
|
33
34
|
},
|
|
34
35
|
create: (props) => createAccordion(computed(() => {
|
package/src/accordion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion.js","names":[],"sources":["../../../../packages/web/src/accordion.ts"],"sourcesContent":["import { computed } from \"@kirana-ui/core\"\nimport { createAccordion } from \"@kirana-ui/core/accordion\"\nimport type { Accordion, AccordionItem, AccordionProps } from \"@kirana-ui/core/accordion\"\n\nimport { list, ownValue } from \"./around.ts\"\nimport { defineElement, partAround } from \"./runtime.ts\"\nimport type { ElementOf } from \"./runtime.ts\"\n\n// An item's parts share the item: made when the first of them is met.\nconst items = new WeakMap<HTMLElement, AccordionItem>()\n\nfunction itemOf(controller: Accordion<string>, element: HTMLElement): AccordionItem | undefined {\n const around = partAround(element, \"item\")\n if (!around) return undefined\n let item = items.get(around)\n if (!item) {\n item = controller.item(around.getAttribute(\"kui-value\") ?? ownValue(around), () =>\n around.hasAttribute(\"kui-disabled\") ? { disabled: true } : {}\n )\n items.set(around, item)\n }\n return item\n}\n\ntype Props = Omit<AccordionProps<string>, \"value\" | \"defaultValue\"> & {\n value?: string | readonly string[]\n defaultValue?: string | readonly string[]\n}\n\n/**\n * `<kui-accordion>` around `kui-part=\"root\"` and its `item`s, each with a `header`, a\n * `trigger` button and a `panel` that is in the page while its item is open. An item's\n * `kui-value` tells it from the others; an item that is given none makes its own.\n * `value` and `default-value` (the open items, with commas between), `multiple`, `disabled`,\n * `orientation`, `loop
|
|
1
|
+
{"version":3,"file":"accordion.js","names":[],"sources":["../../../../packages/web/src/accordion.ts"],"sourcesContent":["import { computed } from \"@kirana-ui/core\"\nimport { createAccordion } from \"@kirana-ui/core/accordion\"\nimport type { Accordion, AccordionItem, AccordionProps } from \"@kirana-ui/core/accordion\"\n\nimport { list, ownValue } from \"./around.ts\"\nimport { defineElement, partAround } from \"./runtime.ts\"\nimport type { ElementOf } from \"./runtime.ts\"\n\n// An item's parts share the item: made when the first of them is met.\nconst items = new WeakMap<HTMLElement, AccordionItem>()\n\nfunction itemOf(controller: Accordion<string>, element: HTMLElement): AccordionItem | undefined {\n const around = partAround(element, \"item\")\n if (!around) return undefined\n let item = items.get(around)\n if (!item) {\n item = controller.item(around.getAttribute(\"kui-value\") ?? ownValue(around), () =>\n around.hasAttribute(\"kui-disabled\") ? { disabled: true } : {}\n )\n items.set(around, item)\n }\n return item\n}\n\ntype Props = Omit<AccordionProps<string>, \"value\" | \"defaultValue\"> & {\n value?: string | readonly string[]\n defaultValue?: string | readonly string[]\n}\n\n/**\n * `<kui-accordion>` around `kui-part=\"root\"` and its `item`s, each with a `header`, a\n * `trigger` button and a `panel` that is in the page while its item is open. An item's\n * `kui-value` tells it from the others; an item that is given none makes its own.\n * `value` and `default-value` (the open items, with commas between), `multiple`, `disabled`,\n * `orientation`, `loop-focus` (`loop` is its older name); it tells `value-change`.\n */\nexport const tag = defineElement<Props & { id: string }, Accordion<string>>({\n tag: \"kui-accordion\",\n props: {\n value: \"string\",\n \"default-value\": \"string\",\n multiple: \"boolean\",\n disabled: \"boolean\",\n orientation: \"string\",\n \"loop-focus\": \"boolean\",\n loop: \"boolean\",\n },\n create: (props) =>\n createAccordion<string>(\n computed(() => {\n const own = props.get()\n return { ...own, value: list(own.value), defaultValue: list(own.defaultValue) }\n })\n ),\n changes: { onValueChange: { event: \"value-change\", prop: \"value\" } },\n parts: {\n root: (controller) => controller.root,\n item(controller, element) {\n const item = itemOf(controller, element)\n return item && { part: item.root, mount: () => item.mount() }\n },\n header: (controller, element) => itemOf(controller, element)?.header,\n trigger: (controller, element) => itemOf(controller, element)?.trigger,\n panel(controller, element) {\n const item = itemOf(controller, element)\n return item && { mounted: item.mounted, part: item.panel }\n },\n },\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-accordion\": ElementOf<typeof tag, { \"value-change\": [\"onValueChange\", \"value\"] }>\n }\n}\n"],"mappings":";;;;;AASA,MAAM,wBAAQ,IAAI,QAAoC;AAEtD,SAAS,OAAO,YAA+B,SAAiD;CAC9F,MAAM,SAAS,WAAW,SAAS,MAAM;CACzC,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,IAAI,OAAO,MAAM,IAAI,MAAM;CAC3B,IAAI,CAAC,MAAM;EACT,OAAO,WAAW,KAAK,OAAO,aAAa,WAAW,KAAK,SAAS,MAAM,SACxE,OAAO,aAAa,cAAc,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC,CAC9D;EACA,MAAM,IAAI,QAAQ,IAAI;CACxB;CACA,OAAO;AACT;;;;;;;;AAcA,MAAa,MAAM,cAAyD;CAC1E,KAAK;CACL,OAAO;EACL,OAAO;EACP,iBAAiB;EACjB,UAAU;EACV,UAAU;EACV,aAAa;EACb,cAAc;EACd,MAAM;CACR;CACA,SAAS,UACP,gBACE,eAAe;EACb,MAAM,MAAM,MAAM,IAAI;EACtB,OAAO;GAAE,GAAG;GAAK,OAAO,KAAK,IAAI,KAAK;GAAG,cAAc,KAAK,IAAI,YAAY;EAAE;CAChF,CAAC,CACH;CACF,SAAS,EAAE,eAAe;EAAE,OAAO;EAAgB,MAAM;CAAQ,EAAE;CACnE,OAAO;EACL,OAAO,eAAe,WAAW;EACjC,KAAK,YAAY,SAAS;GACxB,MAAM,OAAO,OAAO,YAAY,OAAO;GACvC,OAAO,QAAQ;IAAE,MAAM,KAAK;IAAM,aAAa,KAAK,MAAM;GAAE;EAC9D;EACA,SAAS,YAAY,YAAY,OAAO,YAAY,OAAO,CAAC,EAAE;EAC9D,UAAU,YAAY,YAAY,OAAO,YAAY,OAAO,CAAC,EAAE;EAC/D,MAAM,YAAY,SAAS;GACzB,MAAM,OAAO,OAAO,YAAY,OAAO;GACvC,OAAO,QAAQ;IAAE,SAAS,KAAK;IAAS,MAAM,KAAK;GAAM;EAC3D;CACF;AACF,CAAC"}
|
package/src/alert-dialog.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { As, ElementOf, Tag } from "./runtime.js";
|
|
2
2
|
import { AlertDialogProps } from "@kirana-ui/core/alert-dialog";
|
|
3
3
|
/**
|
|
4
|
-
* `<kui-alert-dialog>`: a dialog that asks, with the dialog's parts
|
|
5
|
-
* close it. `open`, `default-open`; it tells `open-change`.
|
|
4
|
+
* `<kui-alert-dialog>`: a dialog that asks, with the dialog's parts, its `viewport` too. A
|
|
5
|
+
* press outside does not close it. `open`, `default-open`; it tells `open-change`.
|
|
6
6
|
*/
|
|
7
7
|
export declare const tag: Tag<{
|
|
8
8
|
id: string;
|
package/src/alert-dialog.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { ownDisabled } from "./around.js";
|
|
1
2
|
import { defineElement } from "./runtime.js";
|
|
2
3
|
import { createAlertDialog } from "@kirana-ui/core/alert-dialog";
|
|
3
4
|
// src/alert-dialog.ts
|
|
4
5
|
/**
|
|
5
|
-
* `<kui-alert-dialog>`: a dialog that asks, with the dialog's parts
|
|
6
|
-
* close it. `open`, `default-open`; it tells `open-change`.
|
|
6
|
+
* `<kui-alert-dialog>`: a dialog that asks, with the dialog's parts, its `viewport` too. A
|
|
7
|
+
* press outside does not close it. `open`, `default-open`; it tells `open-change`.
|
|
7
8
|
*/
|
|
8
9
|
const tag = defineElement({
|
|
9
10
|
tag: "kui-alert-dialog",
|
|
@@ -17,18 +18,22 @@ const tag = defineElement({
|
|
|
17
18
|
prop: "open"
|
|
18
19
|
} },
|
|
19
20
|
parts: {
|
|
20
|
-
trigger: (controller) => controller.
|
|
21
|
+
trigger: (controller, element) => ownDisabled(element, controller.triggerPart),
|
|
21
22
|
backdrop: (controller) => ({
|
|
22
23
|
mounted: controller.mounted,
|
|
23
24
|
part: controller.backdrop
|
|
24
25
|
}),
|
|
26
|
+
viewport: (controller) => ({
|
|
27
|
+
mounted: controller.mounted,
|
|
28
|
+
part: controller.viewport
|
|
29
|
+
}),
|
|
25
30
|
popup: (controller) => ({
|
|
26
31
|
mounted: controller.mounted,
|
|
27
32
|
part: controller.popup
|
|
28
33
|
}),
|
|
29
34
|
title: (controller) => controller.title,
|
|
30
35
|
description: (controller) => controller.description,
|
|
31
|
-
close: (controller) => controller.
|
|
36
|
+
close: (controller, element) => ownDisabled(element, controller.closePart)
|
|
32
37
|
}
|
|
33
38
|
});
|
|
34
39
|
export { tag };
|
package/src/alert-dialog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alert-dialog.js","names":[],"sources":["../../../../packages/web/src/alert-dialog.ts"],"sourcesContent":["import { createAlertDialog } from \"@kirana-ui/core/alert-dialog\"\nimport type { AlertDialogProps } from \"@kirana-ui/core/alert-dialog\"\n\nimport { defineElement } from \"./runtime.ts\"\nimport type { As, ElementOf } from \"./runtime.ts\"\n\n/**\n * `<kui-alert-dialog>`: a dialog that asks, with the dialog's parts. A press outside does not
|
|
1
|
+
{"version":3,"file":"alert-dialog.js","names":[],"sources":["../../../../packages/web/src/alert-dialog.ts"],"sourcesContent":["import { createAlertDialog } from \"@kirana-ui/core/alert-dialog\"\nimport type { AlertDialogProps } from \"@kirana-ui/core/alert-dialog\"\n\nimport { ownDisabled } from \"./around.ts\"\nimport { defineElement } from \"./runtime.ts\"\nimport type { As, ElementOf } from \"./runtime.ts\"\n\n/**\n * `<kui-alert-dialog>`: a dialog that asks, with the dialog's parts, its `viewport` too. A\n * press outside does not close it. `open`, `default-open`; it tells `open-change`.\n */\nexport const tag = defineElement({\n tag: \"kui-alert-dialog\",\n props: { open: \"boolean\", \"default-open\": \"boolean\" },\n create: (props) => createAlertDialog(props),\n changes: { onOpenChange: { event: \"open-change\", prop: \"open\" } },\n parts: {\n trigger: (controller, element) => ownDisabled(element, controller.triggerPart),\n backdrop: (controller) => ({ mounted: controller.mounted, part: controller.backdrop }),\n viewport: (controller) => ({ mounted: controller.mounted, part: controller.viewport }),\n popup: (controller) => ({ mounted: controller.mounted, part: controller.popup }),\n title: (controller) => controller.title,\n description: (controller) => controller.description,\n close: (controller, element) => ownDisabled(element, controller.closePart),\n },\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-alert-dialog\": ElementOf<\n As<typeof tag, AlertDialogProps>,\n { \"open-change\": [\"onOpenChange\", \"open\"] }\n >\n }\n}\n"],"mappings":";;;;;;;;AAWA,MAAa,MAAM,cAAc;CAC/B,KAAK;CACL,OAAO;EAAE,MAAM;EAAW,gBAAgB;CAAU;CACpD,SAAS,UAAU,kBAAkB,KAAK;CAC1C,SAAS,EAAE,cAAc;EAAE,OAAO;EAAe,MAAM;CAAO,EAAE;CAChE,OAAO;EACL,UAAU,YAAY,YAAY,YAAY,SAAS,WAAW,WAAW;EAC7E,WAAW,gBAAgB;GAAE,SAAS,WAAW;GAAS,MAAM,WAAW;EAAS;EACpF,WAAW,gBAAgB;GAAE,SAAS,WAAW;GAAS,MAAM,WAAW;EAAS;EACpF,QAAQ,gBAAgB;GAAE,SAAS,WAAW;GAAS,MAAM,WAAW;EAAM;EAC9E,QAAQ,eAAe,WAAW;EAClC,cAAc,eAAe,WAAW;EACxC,QAAQ,YAAY,YAAY,YAAY,SAAS,WAAW,SAAS;CAC3E;AACF,CAAC"}
|
package/src/around.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Drawn } from "./runtime.js";
|
|
2
2
|
import { Part, PositionOptions, ReadonlySignal, Signal } from "@kirana-ui/core";
|
|
3
3
|
import { Field } from "@kirana-ui/core/field";
|
|
4
|
+
/**
|
|
5
|
+
* A button that takes a `kui-disabled` of its own (a dialog's trigger or close, a navigation
|
|
6
|
+
* menu's trigger): its part made with options read from the element, and followed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ownDisabled(element: HTMLElement, make: (options: () => {
|
|
9
|
+
disabled?: boolean | undefined;
|
|
10
|
+
}) => Part): Drawn;
|
|
4
11
|
/** The field a control is in, if it is in one. */
|
|
5
12
|
export declare const fieldAround: (host: HTMLElement) => Field | undefined;
|
|
6
13
|
/** Several values, as an attribute writes them: `default-value="a,b"`. */
|
|
@@ -19,13 +26,30 @@ export declare const valueOf: (element: HTMLElement | null) => string;
|
|
|
19
26
|
export declare function ownValue(element: HTMLElement | null): string;
|
|
20
27
|
/** What is made once for an element and shared by the parts inside it: an item, a group. */
|
|
21
28
|
export declare function once<Made extends object>(kept: WeakMap<HTMLElement, Made>, element: HTMLElement | null, make: (element: HTMLElement) => Made): Made | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* What a component with a positioner takes as a property of its custom element, for what an
|
|
31
|
+
* attribute cannot say: a function, an element, an object.
|
|
32
|
+
*/
|
|
33
|
+
export interface Placed {
|
|
34
|
+
/**
|
|
35
|
+
* Its positioner's options that no attribute can say (`sideOffset` as a function,
|
|
36
|
+
* `collisionBoundary` as an element or a rectangle, `collisionPadding` a side,
|
|
37
|
+
* `collisionAvoidance`, `anchor` as an element). A `kui-` attribute on the positioner comes
|
|
38
|
+
* before the same option here. Read when the popup comes into the page, and when one of the
|
|
39
|
+
* positioner's attributes changes.
|
|
40
|
+
*/
|
|
41
|
+
positioning?: Partial<PositionOptions> | undefined;
|
|
42
|
+
}
|
|
22
43
|
/**
|
|
23
44
|
* Where a positioner goes, as its own attributes say: `kui-side`, `kui-align`,
|
|
24
|
-
* `kui-side-offset`, `kui-align-offset`, `kui-collision-padding`,
|
|
25
|
-
*
|
|
26
|
-
*
|
|
45
|
+
* `kui-side-offset`, `kui-align-offset`, `kui-collision-padding`, `kui-sticky`,
|
|
46
|
+
* `kui-arrow-padding`, `kui-position-method`, and two that name an element by its id:
|
|
47
|
+
* `kui-anchor`, what the popup is placed against when that is not its trigger, and
|
|
48
|
+
* `kui-collision-boundary`, what it is held inside. What no attribute can say is the
|
|
49
|
+
* `positioning` property of its custom element (`host`). Written before the part is put on,
|
|
50
|
+
* so the first placement reads them.
|
|
27
51
|
*/
|
|
28
|
-
export declare function place(positioning: Signal<Partial<PositionOptions>>, element: HTMLElement,
|
|
52
|
+
export declare function place(positioning: Signal<Partial<PositionOptions>>, element: HTMLElement, host?: (HTMLElement & Placed) | null): void;
|
|
29
53
|
/**
|
|
30
54
|
* A positioner as a part: the one place a component draws one. Its attributes are read
|
|
31
55
|
* before it is put on, and again when one of them changes: a popup that is open follows.
|
package/src/around.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { controllerAround } from "./runtime.js";
|
|
2
|
-
import { computed } from "@kirana-ui/core";
|
|
1
|
+
import { controllerAround, ownerOf, partProps } from "./runtime.js";
|
|
2
|
+
import { computed, effect } from "@kirana-ui/core";
|
|
3
3
|
// src/around.ts
|
|
4
|
+
/**
|
|
5
|
+
* A button that takes a `kui-disabled` of its own (a dialog's trigger or close, a navigation
|
|
6
|
+
* menu's trigger): its part made with options read from the element, and followed.
|
|
7
|
+
*/
|
|
8
|
+
function ownDisabled(element, make) {
|
|
9
|
+
const own = partProps(element, { disabled: "boolean" }, {});
|
|
10
|
+
return {
|
|
11
|
+
part: make(() => own.props.get()),
|
|
12
|
+
mount: own.mount
|
|
13
|
+
};
|
|
14
|
+
}
|
|
4
15
|
/** The field a control is in, if it is in one. */
|
|
5
16
|
const fieldAround = (host) => controllerAround(host, "kui-field");
|
|
6
17
|
/** Several values, as an attribute writes them: `default-value="a,b"`. */
|
|
@@ -38,44 +49,66 @@ const PLACING = [
|
|
|
38
49
|
"kui-side-offset",
|
|
39
50
|
"kui-align-offset",
|
|
40
51
|
"kui-collision-padding",
|
|
52
|
+
"kui-collision-boundary",
|
|
53
|
+
"kui-sticky",
|
|
54
|
+
"kui-arrow-padding",
|
|
55
|
+
"kui-position-method",
|
|
41
56
|
"kui-anchor"
|
|
42
57
|
];
|
|
43
58
|
/**
|
|
44
59
|
* Where a positioner goes, as its own attributes say: `kui-side`, `kui-align`,
|
|
45
|
-
* `kui-side-offset`, `kui-align-offset`, `kui-collision-padding`,
|
|
46
|
-
*
|
|
47
|
-
*
|
|
60
|
+
* `kui-side-offset`, `kui-align-offset`, `kui-collision-padding`, `kui-sticky`,
|
|
61
|
+
* `kui-arrow-padding`, `kui-position-method`, and two that name an element by its id:
|
|
62
|
+
* `kui-anchor`, what the popup is placed against when that is not its trigger, and
|
|
63
|
+
* `kui-collision-boundary`, what it is held inside. What no attribute can say is the
|
|
64
|
+
* `positioning` property of its custom element (`host`). Written before the part is put on,
|
|
65
|
+
* so the first placement reads them.
|
|
48
66
|
*/
|
|
49
|
-
function place(positioning, element,
|
|
67
|
+
function place(positioning, element, host) {
|
|
50
68
|
const against = element.getAttribute("kui-anchor");
|
|
69
|
+
const within = element.getAttribute("kui-collision-boundary");
|
|
70
|
+
const sticky = element.getAttribute("kui-sticky");
|
|
51
71
|
const asked = {
|
|
52
72
|
side: element.getAttribute("kui-side") ?? void 0,
|
|
53
73
|
align: element.getAttribute("kui-align") ?? void 0,
|
|
54
74
|
sideOffset: number(element.getAttribute("kui-side-offset")),
|
|
55
75
|
alignOffset: number(element.getAttribute("kui-align-offset")),
|
|
56
76
|
collisionPadding: number(element.getAttribute("kui-collision-padding")),
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
collisionBoundary: within === null || within === "clipping-ancestors" ? void 0 : element.ownerDocument.getElementById(within) ?? void 0,
|
|
78
|
+
sticky: sticky === null ? void 0 : sticky !== "false",
|
|
79
|
+
arrowPadding: number(element.getAttribute("kui-arrow-padding")),
|
|
80
|
+
positionMethod: element.getAttribute("kui-position-method") ?? void 0,
|
|
81
|
+
anchor: against === null ? void 0 : () => element.ownerDocument.getElementById(against)
|
|
59
82
|
};
|
|
60
83
|
for (const key of Object.keys(asked)) if (asked[key] === void 0) delete asked[key];
|
|
61
|
-
positioning.set(
|
|
84
|
+
positioning.set({
|
|
85
|
+
...host?.positioning,
|
|
86
|
+
...asked
|
|
87
|
+
});
|
|
62
88
|
}
|
|
63
89
|
/**
|
|
64
90
|
* A positioner as a part: the one place a component draws one. Its attributes are read
|
|
65
91
|
* before it is put on, and again when one of them changes: a popup that is open follows.
|
|
66
92
|
*/
|
|
67
93
|
function positioner(controller, element) {
|
|
68
|
-
|
|
94
|
+
const host = ownerOf(element);
|
|
95
|
+
place(controller.positioning, element, host);
|
|
69
96
|
return {
|
|
70
97
|
mounted: controller.mounted,
|
|
71
98
|
part: controller.positioner,
|
|
72
99
|
mount() {
|
|
73
|
-
const observer = new MutationObserver(() => place(controller.positioning, element));
|
|
100
|
+
const observer = new MutationObserver(() => place(controller.positioning, element, host));
|
|
74
101
|
observer.observe(element, {
|
|
75
102
|
attributes: true,
|
|
76
103
|
attributeFilter: PLACING
|
|
77
104
|
});
|
|
78
|
-
|
|
105
|
+
const stop = effect(() => {
|
|
106
|
+
if (controller.mounted.get()) place(controller.positioning, element, host);
|
|
107
|
+
});
|
|
108
|
+
return () => {
|
|
109
|
+
stop();
|
|
110
|
+
observer.disconnect();
|
|
111
|
+
};
|
|
79
112
|
}
|
|
80
113
|
};
|
|
81
114
|
}
|
|
@@ -90,6 +123,6 @@ const itemOptions = (element, id) => () => ({
|
|
|
90
123
|
...element.hasAttribute("kui-label") ? { label: element.getAttribute("kui-label") } : {},
|
|
91
124
|
...id === void 0 ? {} : { id }
|
|
92
125
|
});
|
|
93
|
-
export { MARK, fieldAround, itemOptions, list, once, options, ownValue, place, positioner, valueOf };
|
|
126
|
+
export { MARK, fieldAround, itemOptions, list, once, options, ownDisabled, ownValue, place, positioner, valueOf };
|
|
94
127
|
|
|
95
128
|
//# sourceMappingURL=around.js.map
|
package/src/around.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"around.js","names":[],"sources":["../../../../packages/web/src/around.ts"],"sourcesContent":["import { computed } from \"@kirana-ui/core\"\nimport type { Part, PositionOptions, ReadonlySignal, Signal } from \"@kirana-ui/core\"\nimport type { Field } from \"@kirana-ui/core/field\"\n\nimport { controllerAround } from \"./runtime.ts\"\nimport type { Drawn } from \"./runtime.ts\"\n\n/** The field a control is in, if it is in one. */\nexport const fieldAround = (host: HTMLElement): Field | undefined =>\n controllerAround<Field>(host, \"kui-field\")\n\n/** Several values, as an attribute writes them: `default-value=\"a,b\"`. */\nexport const list = (given: unknown): string[] | undefined =>\n typeof given === \"string\" ? given.split(\",\").filter(Boolean) : (given as string[] | undefined)\n\n/** A part's own options: `kui-disabled`, and its text when it is not what is typed (`kui-label`). */\nexport const options = (element: HTMLElement) => () => ({\n ...(element.hasAttribute(\"kui-disabled\") ? { disabled: true } : {}),\n ...(element.hasAttribute(\"kui-label\") ? { label: element.getAttribute(\"kui-label\")! } : {}),\n})\n\n/** The value an element is the part for: `kui-value`. */\nexport const valueOf = (element: HTMLElement | null): string =>\n element?.getAttribute(\"kui-value\") ?? \"\"\n\nlet named = 0\nconst names = new WeakMap<HTMLElement, string>()\n\n/**\n * The value of an element that was given none: a name of its own, the same each time it is\n * asked for. An item with no `kui-value`, a thumb with no `kui-index`.\n */\nexport function ownValue(element: HTMLElement | null): string {\n if (!element) return \"\"\n let name = names.get(element)\n if (!name) names.set(element, (name = `kui-own-${++named}`))\n return name\n}\n\n/** What is made once for an element and shared by the parts inside it: an item, a group. */\nexport function once<Made extends object>(\n kept: WeakMap<HTMLElement, Made>,\n element: HTMLElement | null,\n make: (element: HTMLElement) => Made\n): Made | undefined {\n if (!element) return undefined\n let made = kept.get(element)\n if (!made) kept.set(element, (made = make(element)))\n return made\n}\n\nconst number = (text: string | null) => (text === null ? undefined : Number(text))\n\nconst PLACING = [\n \"kui-side\",\n \"kui-align\",\n \"kui-side-offset\",\n \"kui-align-offset\",\n \"kui-collision-padding\",\n \"kui-anchor\",\n]\n\n/**\n * Where a positioner goes, as its own attributes say: `kui-side`, `kui-align`,\n * `kui-side-offset`, `kui-align-offset`, `kui-collision-padding`,
|
|
1
|
+
{"version":3,"file":"around.js","names":[],"sources":["../../../../packages/web/src/around.ts"],"sourcesContent":["import { computed, effect } from \"@kirana-ui/core\"\nimport type { Part, PositionOptions, ReadonlySignal, Signal } from \"@kirana-ui/core\"\nimport type { Field } from \"@kirana-ui/core/field\"\n\nimport { controllerAround, ownerOf, partProps } from \"./runtime.ts\"\nimport type { Drawn } from \"./runtime.ts\"\n\n/**\n * A button that takes a `kui-disabled` of its own (a dialog's trigger or close, a navigation\n * menu's trigger): its part made with options read from the element, and followed.\n */\nexport function ownDisabled(\n element: HTMLElement,\n make: (options: () => { disabled?: boolean | undefined }) => Part\n): Drawn {\n const own = partProps<{ disabled?: boolean }>(element, { disabled: \"boolean\" }, {})\n return { part: make(() => own.props.get()), mount: own.mount }\n}\n\n/** The field a control is in, if it is in one. */\nexport const fieldAround = (host: HTMLElement): Field | undefined =>\n controllerAround<Field>(host, \"kui-field\")\n\n/** Several values, as an attribute writes them: `default-value=\"a,b\"`. */\nexport const list = (given: unknown): string[] | undefined =>\n typeof given === \"string\" ? given.split(\",\").filter(Boolean) : (given as string[] | undefined)\n\n/** A part's own options: `kui-disabled`, and its text when it is not what is typed (`kui-label`). */\nexport const options = (element: HTMLElement) => () => ({\n ...(element.hasAttribute(\"kui-disabled\") ? { disabled: true } : {}),\n ...(element.hasAttribute(\"kui-label\") ? { label: element.getAttribute(\"kui-label\")! } : {}),\n})\n\n/** The value an element is the part for: `kui-value`. */\nexport const valueOf = (element: HTMLElement | null): string =>\n element?.getAttribute(\"kui-value\") ?? \"\"\n\nlet named = 0\nconst names = new WeakMap<HTMLElement, string>()\n\n/**\n * The value of an element that was given none: a name of its own, the same each time it is\n * asked for. An item with no `kui-value`, a thumb with no `kui-index`.\n */\nexport function ownValue(element: HTMLElement | null): string {\n if (!element) return \"\"\n let name = names.get(element)\n if (!name) names.set(element, (name = `kui-own-${++named}`))\n return name\n}\n\n/** What is made once for an element and shared by the parts inside it: an item, a group. */\nexport function once<Made extends object>(\n kept: WeakMap<HTMLElement, Made>,\n element: HTMLElement | null,\n make: (element: HTMLElement) => Made\n): Made | undefined {\n if (!element) return undefined\n let made = kept.get(element)\n if (!made) kept.set(element, (made = make(element)))\n return made\n}\n\nconst number = (text: string | null) => (text === null ? undefined : Number(text))\n\nconst PLACING = [\n \"kui-side\",\n \"kui-align\",\n \"kui-side-offset\",\n \"kui-align-offset\",\n \"kui-collision-padding\",\n \"kui-collision-boundary\",\n \"kui-sticky\",\n \"kui-arrow-padding\",\n \"kui-position-method\",\n \"kui-anchor\",\n]\n\n/**\n * What a component with a positioner takes as a property of its custom element, for what an\n * attribute cannot say: a function, an element, an object.\n */\nexport interface Placed {\n /**\n * Its positioner's options that no attribute can say (`sideOffset` as a function,\n * `collisionBoundary` as an element or a rectangle, `collisionPadding` a side,\n * `collisionAvoidance`, `anchor` as an element). A `kui-` attribute on the positioner comes\n * before the same option here. Read when the popup comes into the page, and when one of the\n * positioner's attributes changes.\n */\n positioning?: Partial<PositionOptions> | undefined\n}\n\n/**\n * Where a positioner goes, as its own attributes say: `kui-side`, `kui-align`,\n * `kui-side-offset`, `kui-align-offset`, `kui-collision-padding`, `kui-sticky`,\n * `kui-arrow-padding`, `kui-position-method`, and two that name an element by its id:\n * `kui-anchor`, what the popup is placed against when that is not its trigger, and\n * `kui-collision-boundary`, what it is held inside. What no attribute can say is the\n * `positioning` property of its custom element (`host`). Written before the part is put on,\n * so the first placement reads them.\n */\nexport function place(\n positioning: Signal<Partial<PositionOptions>>,\n element: HTMLElement,\n host?: (HTMLElement & Placed) | null\n): void {\n const against = element.getAttribute(\"kui-anchor\")\n const within = element.getAttribute(\"kui-collision-boundary\")\n const sticky = element.getAttribute(\"kui-sticky\")\n const asked: Record<string, unknown> = {\n side: element.getAttribute(\"kui-side\") ?? undefined,\n align: element.getAttribute(\"kui-align\") ?? undefined,\n sideOffset: number(element.getAttribute(\"kui-side-offset\")),\n alignOffset: number(element.getAttribute(\"kui-align-offset\")),\n collisionPadding: number(element.getAttribute(\"kui-collision-padding\")),\n // Found now: a boundary is what is in the page as the popup comes into it.\n collisionBoundary:\n within === null || within === \"clipping-ancestors\"\n ? undefined\n : (element.ownerDocument.getElementById(within) ?? undefined),\n sticky: sticky === null ? undefined : sticky !== \"false\",\n arrowPadding: number(element.getAttribute(\"kui-arrow-padding\")),\n positionMethod: element.getAttribute(\"kui-position-method\") ?? undefined,\n // Looked for each time the popup is placed: the element may come into the page later.\n anchor: against === null ? undefined : () => element.ownerDocument.getElementById(against),\n }\n for (const key of Object.keys(asked)) if (asked[key] === undefined) delete asked[key]\n positioning.set({ ...host?.positioning, ...asked } as Partial<PositionOptions>)\n}\n\n/**\n * A positioner as a part: the one place a component draws one. Its attributes are read\n * before it is put on, and again when one of them changes: a popup that is open follows.\n */\nexport function positioner(\n controller: {\n positioning: Signal<Partial<PositionOptions>>\n mounted: ReadonlySignal<boolean>\n positioner: Part\n },\n element: HTMLElement\n): Drawn {\n // Found while the positioner is where the page wrote it: it is out of the page while closed.\n const host = ownerOf(element)\n place(controller.positioning, element, host)\n return {\n mounted: controller.mounted,\n part: controller.positioner,\n mount() {\n const observer = new MutationObserver(() => place(controller.positioning, element, host))\n observer.observe(element, { attributes: true, attributeFilter: PLACING })\n // Read again as the popup comes into the page: the property may have been set since.\n const stop = effect(() => {\n if (controller.mounted.get()) place(controller.positioning, element, host)\n })\n return () => {\n stop()\n observer.disconnect()\n }\n },\n }\n}\n\n/** A mark an item shows while it is chosen: nothing a screen reader says. */\nexport const MARK: Part = {\n props: computed(() => ({ \"aria-hidden\": \"true\" })),\n attach: () => () => {},\n}\n\n/** An item's options in a list that is filtered or typed through: with `kui-label`, and an id. */\nexport const itemOptions = (element: HTMLElement, id?: string) => () => ({\n ...(element.hasAttribute(\"kui-disabled\") ? { disabled: true } : {}),\n ...(element.hasAttribute(\"kui-label\") ? { label: element.getAttribute(\"kui-label\")! } : {}),\n ...(id === undefined ? {} : { id }),\n})\n"],"mappings":"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"}
|
package/src/autocomplete.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ElementOf, Tag } from "./runtime.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Placed } from "./around.js";
|
|
3
3
|
import { Combobox } from "@kirana-ui/core/combobox";
|
|
4
|
+
import { AutocompleteProps } from "@kirana-ui/core/autocomplete";
|
|
4
5
|
/**
|
|
5
6
|
* `<kui-autocomplete>`: a combobox whose text is the value, with a combobox's parts: the
|
|
6
7
|
* list only suggests. `value`, `default-value`, `open`, `default-open`, `mode`,
|
|
7
|
-
* `open-on-input-click`, `auto-highlight`, `disabled`, `required`, `name`, `form`;
|
|
8
|
-
*
|
|
8
|
+
* `open-on-input-click`, `auto-highlight`, `disabled`, `read-only`, `required`, `name`, `form`;
|
|
9
|
+
* `filter` and `items` as properties (with `items`, the suggestions are a
|
|
10
|
+
* `<template kui-each="collection">`, as a combobox's); it tells `value-change` and
|
|
11
|
+
* `open-change`.
|
|
9
12
|
*/
|
|
10
13
|
export declare const tag: Tag<AutocompleteProps, Combobox<string>>;
|
|
11
14
|
declare global {
|
|
@@ -13,7 +16,7 @@ declare global {
|
|
|
13
16
|
"kui-autocomplete": ElementOf<typeof tag, {
|
|
14
17
|
"value-change": ["onValueChange", "value"];
|
|
15
18
|
"open-change": ["onOpenChange", "open"];
|
|
16
|
-
}
|
|
19
|
+
}> & Placed;
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
22
|
//# sourceMappingURL=autocomplete.d.ts.map
|
package/src/autocomplete.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { fieldAround } from "./around.js";
|
|
2
|
-
import { PARTS } from "./combobox.js";
|
|
2
|
+
import { LISTS, PARTS } from "./combobox.js";
|
|
3
3
|
import { defineElement } from "./runtime.js";
|
|
4
4
|
import { createAutocomplete } from "@kirana-ui/core/autocomplete";
|
|
5
5
|
// src/autocomplete.ts
|
|
6
6
|
/**
|
|
7
7
|
* `<kui-autocomplete>`: a combobox whose text is the value, with a combobox's parts: the
|
|
8
8
|
* list only suggests. `value`, `default-value`, `open`, `default-open`, `mode`,
|
|
9
|
-
* `open-on-input-click`, `auto-highlight`, `disabled`, `required`, `name`, `form`;
|
|
10
|
-
*
|
|
9
|
+
* `open-on-input-click`, `auto-highlight`, `disabled`, `read-only`, `required`, `name`, `form`;
|
|
10
|
+
* `filter` and `items` as properties (with `items`, the suggestions are a
|
|
11
|
+
* `<template kui-each="collection">`, as a combobox's); it tells `value-change` and
|
|
12
|
+
* `open-change`.
|
|
11
13
|
*/
|
|
12
14
|
const tag = defineElement({
|
|
13
15
|
tag: "kui-autocomplete",
|
|
@@ -20,11 +22,12 @@ const tag = defineElement({
|
|
|
20
22
|
"open-on-input-click": "boolean",
|
|
21
23
|
"auto-highlight": "boolean",
|
|
22
24
|
disabled: "boolean",
|
|
25
|
+
"read-only": "boolean",
|
|
23
26
|
required: "boolean",
|
|
24
27
|
name: "string",
|
|
25
28
|
form: "string"
|
|
26
29
|
},
|
|
27
|
-
properties: ["filter"],
|
|
30
|
+
properties: ["filter", "items"],
|
|
28
31
|
create: (props, host) => createAutocomplete(props, { field: fieldAround(host) }),
|
|
29
32
|
changes: {
|
|
30
33
|
onValueChange: {
|
|
@@ -36,6 +39,7 @@ const tag = defineElement({
|
|
|
36
39
|
prop: "open"
|
|
37
40
|
}
|
|
38
41
|
},
|
|
42
|
+
lists: { collection: LISTS.collection },
|
|
39
43
|
parts: PARTS
|
|
40
44
|
});
|
|
41
45
|
export { tag };
|
package/src/autocomplete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.js","names":[],"sources":["../../../../packages/web/src/autocomplete.ts"],"sourcesContent":["import { createAutocomplete } from \"@kirana-ui/core/autocomplete\"\nimport type { AutocompleteProps } from \"@kirana-ui/core/autocomplete\"\nimport type { Combobox } from \"@kirana-ui/core/combobox\"\n\nimport { fieldAround } from \"./around.ts\"\nimport { PARTS } from \"./combobox.ts\"\nimport { defineElement } from \"./runtime.ts\"\nimport type { ElementOf } from \"./runtime.ts\"\n\n/**\n * `<kui-autocomplete>`: a combobox whose text is the value, with a combobox's parts: the\n * list only suggests. `value`, `default-value`, `open`, `default-open`, `mode`,\n * `open-on-input-click`, `auto-highlight`, `disabled`, `required`, `name`, `form
|
|
1
|
+
{"version":3,"file":"autocomplete.js","names":[],"sources":["../../../../packages/web/src/autocomplete.ts"],"sourcesContent":["import { createAutocomplete } from \"@kirana-ui/core/autocomplete\"\nimport type { AutocompleteProps } from \"@kirana-ui/core/autocomplete\"\nimport type { Combobox } from \"@kirana-ui/core/combobox\"\n\nimport { fieldAround } from \"./around.ts\"\nimport type { Placed } from \"./around.ts\"\nimport { LISTS, PARTS } from \"./combobox.ts\"\nimport { defineElement } from \"./runtime.ts\"\nimport type { ElementOf } from \"./runtime.ts\"\n\n/**\n * `<kui-autocomplete>`: a combobox whose text is the value, with a combobox's parts: the\n * list only suggests. `value`, `default-value`, `open`, `default-open`, `mode`,\n * `open-on-input-click`, `auto-highlight`, `disabled`, `read-only`, `required`, `name`, `form`;\n * `filter` and `items` as properties (with `items`, the suggestions are a\n * `<template kui-each=\"collection\">`, as a combobox's); it tells `value-change` and\n * `open-change`.\n */\nexport const tag = defineElement<AutocompleteProps, Combobox<string>>({\n tag: \"kui-autocomplete\",\n props: {\n value: \"string\",\n \"default-value\": \"string\",\n open: \"boolean\",\n \"default-open\": \"boolean\",\n mode: \"string\",\n \"open-on-input-click\": \"boolean\",\n \"auto-highlight\": \"boolean\",\n disabled: \"boolean\",\n \"read-only\": \"boolean\",\n required: \"boolean\",\n name: \"string\",\n form: \"string\",\n },\n properties: [\"filter\", \"items\"],\n create: (props, host) =>\n createAutocomplete(props, { field: fieldAround(host) }) as Combobox<string>,\n changes: {\n onValueChange: { event: \"value-change\", prop: \"value\" },\n onOpenChange: { event: \"open-change\", prop: \"open\" },\n },\n lists: { collection: LISTS.collection },\n parts: PARTS,\n})\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kui-autocomplete\": ElementOf<\n typeof tag,\n { \"value-change\": [\"onValueChange\", \"value\"]; \"open-change\": [\"onOpenChange\", \"open\"] }\n > &\n Placed\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAa,MAAM,cAAmD;CACpE,KAAK;CACL,OAAO;EACL,OAAO;EACP,iBAAiB;EACjB,MAAM;EACN,gBAAgB;EAChB,MAAM;EACN,uBAAuB;EACvB,kBAAkB;EAClB,UAAU;EACV,aAAa;EACb,UAAU;EACV,MAAM;EACN,MAAM;CACR;CACA,YAAY,CAAC,UAAU,OAAO;CAC9B,SAAS,OAAO,SACd,mBAAmB,OAAO,EAAE,OAAO,YAAY,IAAI,EAAE,CAAC;CACxD,SAAS;EACP,eAAe;GAAE,OAAO;GAAgB,MAAM;EAAQ;EACtD,cAAc;GAAE,OAAO;GAAe,MAAM;EAAO;CACrD;CACA,OAAO,EAAE,YAAY,MAAM,WAAW;CACtC,OAAO;AACT,CAAC"}
|