@kirana-ui/vue 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/llms.txt +303 -82
- package/package.json +6 -2
- package/skills/kirana-ui-primitives/SKILL.md +29 -8
- package/src/alert-dialog.d.ts +2 -2
- package/src/autocomplete.d.ts +2 -2
- package/src/avatar.d.ts +31 -4
- package/src/avatar.js +39 -15
- package/src/avatar.js.map +1 -1
- package/src/calendar.d.ts +17 -11
- package/src/calendar.js +76 -11
- package/src/calendar.js.map +1 -1
- package/src/checkbox-group-context.d.ts +5 -0
- package/src/checkbox-group-context.js +6 -0
- package/src/checkbox-group-context.js.map +1 -0
- package/src/checkbox-group.d.ts +12 -0
- package/src/checkbox-group.js +44 -0
- package/src/checkbox-group.js.map +1 -0
- package/src/checkbox.d.ts +1 -0
- package/src/checkbox.js +9 -2
- package/src/checkbox.js.map +1 -1
- package/src/combobox.d.ts +23 -1
- package/src/combobox.js +51 -3
- package/src/combobox.js.map +1 -1
- package/src/command.js +2 -0
- package/src/command.js.map +1 -1
- package/src/date-picker.d.ts +8 -5
- package/src/date-picker.js +12 -1
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +19 -0
- package/src/dialog.js +4 -1
- package/src/dialog.js.map +1 -1
- package/src/drawer.d.ts +2 -2
- package/src/index.d.ts +6 -3
- package/src/index.js +2 -1
- package/src/number-field.d.ts +33 -1
- package/src/number-field.js +98 -68
- package/src/number-field.js.map +1 -1
- package/src/otp.js +2 -0
- package/src/otp.js.map +1 -1
- package/src/popover.d.ts +26 -3
- package/src/popover.js +36 -4
- package/src/popover.js.map +1 -1
- package/src/radio-group.js +6 -2
- package/src/radio-group.js.map +1 -1
- package/src/select.d.ts +1 -0
- package/src/select.js +2 -0
- package/src/select.js.map +1 -1
- package/src/slider.d.ts +5 -0
- package/src/slider.js +1 -0
- package/src/slider.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirana-ui/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Kirana UI Primitives for Vue",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "The Kirana authors",
|
|
@@ -47,6 +47,10 @@
|
|
|
47
47
|
"types": "./src/checkbox.d.ts",
|
|
48
48
|
"default": "./src/checkbox.js"
|
|
49
49
|
},
|
|
50
|
+
"./checkbox-group": {
|
|
51
|
+
"types": "./src/checkbox-group.d.ts",
|
|
52
|
+
"default": "./src/checkbox-group.js"
|
|
53
|
+
},
|
|
50
54
|
"./collapsible": {
|
|
51
55
|
"types": "./src/collapsible.d.ts",
|
|
52
56
|
"default": "./src/collapsible.js"
|
|
@@ -226,7 +230,7 @@
|
|
|
226
230
|
"./package.json": "./package.json"
|
|
227
231
|
},
|
|
228
232
|
"dependencies": {
|
|
229
|
-
"@kirana-ui/core": "0.
|
|
233
|
+
"@kirana-ui/core": "0.3.0"
|
|
230
234
|
},
|
|
231
235
|
"peerDependencies": {
|
|
232
236
|
"vue": "^3.5.0"
|
|
@@ -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
|
|
@@ -55,8 +61,8 @@ from one core. The package for a framework is all a project installs.
|
|
|
55
61
|
Per framework: React takes `render` for another element; Vue takes `as` / `as-child`, binds
|
|
56
62
|
with `v-model:value` and names props in kebab case; Svelte takes a `child` snippet and
|
|
57
63
|
`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 (`*
|
|
64
|
+
elements (`<button kpDialogTrigger>`), bound with `[(value)]`, with `[kpId]` for an id, and
|
|
65
|
+
a part that comes and goes is structural (`*kpDialogPortal`, `*kpTabsPanel`: the list is in
|
|
60
66
|
`llms.txt`); custom elements name each part with `kui-part` inside `<kui-dialog>`.
|
|
61
67
|
|
|
62
68
|
Composing a part with another element: with React's `render={<a … />}` and Vue's `as-child`
|
|
@@ -72,9 +78,24 @@ the text a part writes (`Meter.Value`, `Select.Value`) stay inside it on React a
|
|
|
72
78
|
`props().children` on Solid, and are given to a Svelte `child` snippet to render
|
|
73
79
|
(`{ props, state, input }`, `{ props, state, text }`). A handler given to a part is typed
|
|
74
80
|
with `preventKiranaHandler()` (`PartEvent`, exported by each package). For an element of the
|
|
75
|
-
design system's own
|
|
76
|
-
`@kirana-ui/react/use-render`,
|
|
77
|
-
|
|
81
|
+
design system's own composed as a part is, use `useRender` and `mergeProps` from
|
|
82
|
+
`@kirana-ui/react/use-render`, `Primitive` from `@kirana-ui/vue/primitive`, or `Primitive`
|
|
83
|
+
and `mergeProps` from `@kirana-ui/solid/primitive` and `@kirana-ui/svelte/primitive` (Solid's
|
|
84
|
+
`as` and `render`, Svelte's `as` and `child`, a `state` written as `data-*`); never write
|
|
85
|
+
another merge. On Angular such an element is a directive of your own with host bindings, and
|
|
86
|
+
custom elements need nothing: the page writes its own element.
|
|
87
|
+
|
|
88
|
+
A design system on Angular hosts each primitive in a directive of its own
|
|
89
|
+
(`hostDirectives: [{ directive: KpDialog, inputs: [...], outputs: [...] }]`), exposing what
|
|
90
|
+
its callers set; gives the primitive the rest with `hostInputs(KpTooltip, { delay: () => 0 })`
|
|
91
|
+
in its constructor (each value a function read like a signal, so `computed` values follow;
|
|
92
|
+
an input the element binds wins), never a subclass of the primitive; draws a structural part
|
|
93
|
+
(`kpDialogPortal`) in a component's template around `<ng-content />` (a part given to it finds
|
|
94
|
+
its root where it is written); and names its own directives as it likes, `kui…` included:
|
|
95
|
+
the primitives are `kp…` so that no design system's selector is theirs (two directives with
|
|
96
|
+
one selector both match, silently, and a component whose selector is its host's recurses).
|
|
97
|
+
Tooltips need no provider on any
|
|
98
|
+
framework: a design system passes `delay` on its own tooltip root (`hostInputs` on Angular).
|
|
78
99
|
|
|
79
100
|
## When something is wrong
|
|
80
101
|
|
package/src/alert-dialog.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PortalProps } from "./runtime.js";
|
|
2
|
-
import { AlertDialog, AlertRootProps, BackdropProps, CloseProps, DescriptionProps, Dialog, Drawer, DrawerRootEmits, DrawerRootProps, PopupProps, RootEmits, TitleProps, TriggerProps } from "./dialog.js";
|
|
3
|
-
export { AlertDialog, type AlertRootProps, type BackdropProps, type CloseProps, type DescriptionProps, type Dialog, type Drawer, type DrawerRootEmits, type DrawerRootProps, type PopupProps, type PortalProps, type RootEmits, type AlertRootProps as RootProps, type TitleProps, type TriggerProps };
|
|
2
|
+
import { AlertDialog, AlertRootProps, BackdropProps, CloseProps, DescriptionProps, Dialog, Drawer, DrawerRootEmits, DrawerRootProps, PopupProps, RootEmits, TitleProps, TriggerProps, ViewportProps } from "./dialog.js";
|
|
3
|
+
export { AlertDialog, type AlertRootProps, type BackdropProps, type CloseProps, type DescriptionProps, type Dialog, type Drawer, type DrawerRootEmits, type DrawerRootProps, type PopupProps, type PortalProps, type RootEmits, type AlertRootProps as RootProps, type TitleProps, type TriggerProps, type ViewportProps };
|
package/src/autocomplete.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PortalProps } from "./runtime.js";
|
|
2
2
|
import { PositionerProps } from "./popover.js";
|
|
3
|
-
import { Autocomplete, AutocompleteRootEmits, AutocompleteRootProps, ChipProps, ChipRemoveProps, ChipsProps, ClearProps, Combobox, EmptyProps, GroupLabelProps, GroupProps, InputProps, ItemIndicatorProps, ItemProps, ListProps, PopupProps, SeparatorProps, TriggerProps } from "./combobox.js";
|
|
4
|
-
export { Autocomplete, type AutocompleteRootEmits, type AutocompleteRootProps, type ChipProps, type ChipRemoveProps, type ChipsProps, type ClearProps, type Combobox, type EmptyProps, type GroupLabelProps, type GroupProps, type InputProps, type ItemIndicatorProps, type ItemProps, type ListProps, type PopupProps, type PortalProps, type PositionerProps, type AutocompleteRootEmits as RootEmits, type AutocompleteRootProps as RootProps, type SeparatorProps, type TriggerProps };
|
|
3
|
+
import { Autocomplete, AutocompleteRootEmits, AutocompleteRootProps, ChipProps, ChipRemoveProps, ChipsProps, ClearProps, CollectionProps, Combobox, EmptyProps, GroupLabelProps, GroupProps, InputProps, ItemIndicatorProps, ItemProps, ListProps, PopupProps, SeparatorProps, StatusProps, TriggerProps, ValueProps } from "./combobox.js";
|
|
4
|
+
export { Autocomplete, type AutocompleteRootEmits, type AutocompleteRootProps, type ChipProps, type ChipRemoveProps, type ChipsProps, type ClearProps, type CollectionProps, type Combobox, type EmptyProps, type GroupLabelProps, type GroupProps, type InputProps, type ItemIndicatorProps, type ItemProps, type ListProps, type PopupProps, type PortalProps, type PositionerProps, type AutocompleteRootEmits as RootEmits, type AutocompleteRootProps as RootProps, type SeparatorProps, type StatusProps, type TriggerProps, type ValueProps };
|
package/src/avatar.d.ts
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
import { PartComponent, PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ImageStatus } from "@kirana-ui/core/avatar";
|
|
2
3
|
export type RootProps = PartComponentProps;
|
|
3
4
|
export interface ImageProps extends PartComponentProps {
|
|
4
5
|
/** The picture's address: the part is in the page once it has loaded. */
|
|
5
6
|
src?: string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Keeps the element in the page while the picture loads, as Base UI's: it loads the
|
|
9
|
+
* picture itself (`loading="lazy"` works), and until it has loaded it is `aria-hidden`,
|
|
10
|
+
* with `data-loading` or `data-error` for the design to hide or fade it by. Default:
|
|
11
|
+
* `false`, the element is drawn once the picture has loaded.
|
|
12
|
+
*/
|
|
13
|
+
keepMounted?: boolean | undefined;
|
|
14
|
+
}
|
|
15
|
+
export type ImageEmits = {
|
|
16
|
+
/**
|
|
17
|
+
* `@loading-status-change`: each time the picture's loading status changes, `loading` once it
|
|
18
|
+
* has an address, then `loaded` or `error`; `idle` again when its address is taken away. The
|
|
19
|
+
* root says the same in `data-image-loading-status`.
|
|
20
|
+
*/
|
|
21
|
+
loadingStatusChange: (status: ImageStatus) => void;
|
|
22
|
+
};
|
|
23
|
+
export interface FallbackProps extends PartComponentProps {
|
|
24
|
+
/**
|
|
25
|
+
* How long to wait before showing, in milliseconds, so a picture that loads sooner never
|
|
26
|
+
* lets the fallback be seen. Read once. Default: `0`, at once.
|
|
27
|
+
*/
|
|
28
|
+
delay?: number | undefined;
|
|
6
29
|
}
|
|
7
|
-
export type FallbackProps = PartComponentProps;
|
|
8
30
|
export declare const Avatar: {
|
|
9
|
-
Root: PartComponent<"span",
|
|
10
|
-
|
|
11
|
-
|
|
31
|
+
Root: PartComponent<"span", {
|
|
32
|
+
readonly imageLoadingStatus?: "error" | "idle" | "loaded" | "loading" | undefined;
|
|
33
|
+
}, PartComponentProps>;
|
|
34
|
+
Image: PartComponent<"img", {
|
|
35
|
+
readonly loading?: true | undefined;
|
|
36
|
+
readonly error?: true | undefined;
|
|
37
|
+
}, ImageProps, ImageEmits>;
|
|
38
|
+
Fallback: PartComponent<"span", Record<never, never>, FallbackProps>;
|
|
12
39
|
};
|
|
13
40
|
//# sourceMappingURL=avatar.d.ts.map
|
package/src/avatar.js
CHANGED
|
@@ -1,37 +1,61 @@
|
|
|
1
1
|
import { context, controller, fromSignal, partComponent } from "./runtime.js";
|
|
2
|
-
import { defineComponent, h, watchEffect } from "vue";
|
|
2
|
+
import { defineComponent, h, onBeforeUnmount, onMounted, watchEffect } from "vue";
|
|
3
3
|
import { createAvatar } from "@kirana-ui/core/avatar";
|
|
4
4
|
// src/avatar.ts
|
|
5
5
|
const scope = context("Avatar");
|
|
6
6
|
const RootElement = partComponent("AvatarRootElement", "span", () => scope.use().root);
|
|
7
7
|
const ImageElement = partComponent("AvatarImageElement", "img", () => scope.use().image);
|
|
8
|
+
const KeptImageElement = partComponent("AvatarKeptImageElement", "img", () => scope.use().keptImage);
|
|
8
9
|
const FallbackElement = partComponent("AvatarFallbackElement", "span", () => scope.use().fallback);
|
|
10
|
+
const Root = defineComponent({
|
|
11
|
+
name: "AvatarRoot",
|
|
12
|
+
inheritAttrs: false,
|
|
13
|
+
setup(_props, { attrs, slots }) {
|
|
14
|
+
scope.provide(controller(createAvatar, () => ({})));
|
|
15
|
+
return () => h(RootElement, attrs, slots);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
/** Runs something with a `mount()` for the component's life in the page. */
|
|
19
|
+
function whileMounted(made) {
|
|
20
|
+
let stop;
|
|
21
|
+
onMounted(() => {
|
|
22
|
+
stop = made.mount();
|
|
23
|
+
});
|
|
24
|
+
onBeforeUnmount(() => stop?.());
|
|
25
|
+
}
|
|
9
26
|
const Avatar = {
|
|
10
|
-
Root
|
|
11
|
-
name: "AvatarRoot",
|
|
12
|
-
inheritAttrs: false,
|
|
13
|
-
setup(_props, { attrs, slots }) {
|
|
14
|
-
scope.provide(controller(createAvatar, () => ({})));
|
|
15
|
-
return () => h(RootElement, attrs, slots);
|
|
16
|
-
}
|
|
17
|
-
}),
|
|
27
|
+
Root,
|
|
18
28
|
Image: defineComponent({
|
|
19
29
|
name: "AvatarImage",
|
|
20
30
|
inheritAttrs: false,
|
|
21
|
-
props: {
|
|
22
|
-
|
|
31
|
+
props: {
|
|
32
|
+
src: String,
|
|
33
|
+
keepMounted: Boolean
|
|
34
|
+
},
|
|
35
|
+
emits: ["loadingStatusChange"],
|
|
36
|
+
setup(props, { attrs, emit }) {
|
|
23
37
|
const made = scope.use();
|
|
24
38
|
watchEffect(() => made.source.set(props.src), { flush: "sync" });
|
|
39
|
+
whileMounted(made.statusReport(() => (status) => emit("loadingStatusChange", status)));
|
|
25
40
|
const status = fromSignal(made.status);
|
|
26
|
-
return () =>
|
|
41
|
+
return () => props.keepMounted ? h(KeptImageElement, {
|
|
42
|
+
...attrs,
|
|
43
|
+
src: props.src
|
|
44
|
+
}) : status.value === "loaded" ? h(ImageElement, attrs) : null;
|
|
27
45
|
}
|
|
28
46
|
}),
|
|
29
47
|
Fallback: defineComponent({
|
|
30
48
|
name: "AvatarFallback",
|
|
31
49
|
inheritAttrs: false,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
props: { delay: {
|
|
51
|
+
type: Number,
|
|
52
|
+
default: void 0
|
|
53
|
+
} },
|
|
54
|
+
setup(props, { attrs, slots }) {
|
|
55
|
+
const presence = scope.use().fallbackPresence({ delay: props.delay });
|
|
56
|
+
whileMounted(presence);
|
|
57
|
+
const shown = fromSignal(presence.shown);
|
|
58
|
+
return () => shown.value ? h(FallbackElement, attrs, slots) : null;
|
|
35
59
|
}
|
|
36
60
|
})
|
|
37
61
|
};
|
package/src/avatar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar.js","names":[],"sources":["../../../../packages/vue/src/avatar.ts"],"sourcesContent":["import { createAvatar } from \"@kirana-ui/core/avatar\"\nimport type { Avatar as Controller } from \"@kirana-ui/core/avatar\"\nimport { defineComponent, h, watchEffect } from \"vue\"\n\nimport { context, controller, fromSignal, partComponent } from \"./runtime.ts\"\nimport type { PartComponent, PartComponentProps, StatesOf } from \"./runtime.ts\"\n\ntype State = StatesOf<\"avatar\">\n\nconst scope = context<Controller>(\"Avatar\")\nconst RootElement = partComponent(\"AvatarRootElement\", \"span\", () => scope.use().root)\nconst ImageElement = partComponent(\"AvatarImageElement\", \"img\", () => scope.use().image)\nconst FallbackElement = partComponent(\"AvatarFallbackElement\", \"span\", () => scope.use().fallback)\n\nexport type RootProps = PartComponentProps\n\nconst Root = defineComponent({\n name: \"AvatarRoot\",\n inheritAttrs: false,\n setup(_props, { attrs, slots }) {\n scope.provide(controller(createAvatar, () => ({})))\n return () => h(RootElement, attrs, slots)\n },\n}) as unknown as PartComponent<\"span\", State[\"root\"], RootProps>\n\nexport interface ImageProps extends PartComponentProps {\n /** The picture's address: the part is in the page once it has loaded. */\n src?: string | undefined\n}\n\n/** The picture: in the page once `src` has loaded
|
|
1
|
+
{"version":3,"file":"avatar.js","names":[],"sources":["../../../../packages/vue/src/avatar.ts"],"sourcesContent":["import { createAvatar } from \"@kirana-ui/core/avatar\"\nimport type { Avatar as Controller, ImageStatus } from \"@kirana-ui/core/avatar\"\nimport { defineComponent, h, onBeforeUnmount, onMounted, watchEffect } from \"vue\"\nimport type { PropType } from \"vue\"\n\nimport { context, controller, fromSignal, partComponent } from \"./runtime.ts\"\nimport type { PartComponent, PartComponentProps, StatesOf } from \"./runtime.ts\"\n\ntype State = StatesOf<\"avatar\">\n\nconst scope = context<Controller>(\"Avatar\")\nconst RootElement = partComponent(\"AvatarRootElement\", \"span\", () => scope.use().root)\nconst ImageElement = partComponent(\"AvatarImageElement\", \"img\", () => scope.use().image)\nconst KeptImageElement = partComponent(\"AvatarKeptImageElement\", \"img\", () => scope.use().keptImage)\nconst FallbackElement = partComponent(\"AvatarFallbackElement\", \"span\", () => scope.use().fallback)\n\nexport type RootProps = PartComponentProps\n\nconst Root = defineComponent({\n name: \"AvatarRoot\",\n inheritAttrs: false,\n setup(_props, { attrs, slots }) {\n scope.provide(controller(createAvatar, () => ({})))\n return () => h(RootElement, attrs, slots)\n },\n}) as unknown as PartComponent<\"span\", State[\"root\"], RootProps>\n\nexport interface ImageProps extends PartComponentProps {\n /** The picture's address: the part is in the page once it has loaded. */\n src?: string | undefined\n /**\n * Keeps the element in the page while the picture loads, as Base UI's: it loads the\n * picture itself (`loading=\"lazy\"` works), and until it has loaded it is `aria-hidden`,\n * with `data-loading` or `data-error` for the design to hide or fade it by. Default:\n * `false`, the element is drawn once the picture has loaded.\n */\n keepMounted?: boolean | undefined\n}\n\nexport type ImageEmits = {\n /**\n * `@loading-status-change`: each time the picture's loading status changes, `loading` once it\n * has an address, then `loaded` or `error`; `idle` again when its address is taken away. The\n * root says the same in `data-image-loading-status`.\n */\n loadingStatusChange: (status: ImageStatus) => void\n}\n\n/** Runs something with a `mount()` for the component's life in the page. */\nfunction whileMounted(made: { mount(): () => void }) {\n let stop: (() => void) | undefined\n onMounted(() => {\n stop = made.mount()\n })\n onBeforeUnmount(() => stop?.())\n}\n\n/**\n * The picture: in the page once `src` has loaded, or all along with `keep-mounted`.\n * `@loading-status-change` hears its loading.\n */\nconst Image = defineComponent({\n name: \"AvatarImage\",\n inheritAttrs: false,\n props: { src: String, keepMounted: Boolean },\n emits: [\"loadingStatusChange\"],\n setup(props, { attrs, emit }) {\n const made = scope.use()\n watchEffect(() => made.source.set(props.src), { flush: \"sync\" })\n whileMounted(made.statusReport(() => (status) => emit(\"loadingStatusChange\", status)))\n const status = fromSignal(made.status)\n return () =>\n props.keepMounted\n ? h(KeptImageElement, { ...attrs, src: props.src })\n : status.value === \"loaded\"\n ? h(ImageElement, attrs)\n : null\n },\n}) as unknown as PartComponent<\"img\", State[\"image\"], ImageProps, ImageEmits>\n\nexport interface FallbackProps extends PartComponentProps {\n /**\n * How long to wait before showing, in milliseconds, so a picture that loads sooner never\n * lets the fallback be seen. Read once. Default: `0`, at once.\n */\n delay?: number | undefined\n}\n\n/** What shows until the picture has loaded, or when it cannot; after `delay`, when given one. */\nconst Fallback = defineComponent({\n name: \"AvatarFallback\",\n inheritAttrs: false,\n props: { delay: { type: Number as PropType<number>, default: undefined as unknown } },\n setup(props, { attrs, slots }) {\n const presence = scope.use().fallbackPresence({ delay: props.delay as number | undefined })\n whileMounted(presence)\n const shown = fromSignal(presence.shown)\n return () => (shown.value ? h(FallbackElement, attrs, slots) : null)\n },\n}) as unknown as PartComponent<\"span\", State[\"fallback\"], FallbackProps>\n\nexport const Avatar = { Root, Image, Fallback }\n"],"mappings":";;;;AAUA,MAAM,QAAQ,QAAoB,QAAQ;AAC1C,MAAM,cAAc,cAAc,qBAAqB,cAAc,MAAM,IAAI,CAAC,CAAC,IAAI;AACrF,MAAM,eAAe,cAAc,sBAAsB,aAAa,MAAM,IAAI,CAAC,CAAC,KAAK;AACvF,MAAM,mBAAmB,cAAc,0BAA0B,aAAa,MAAM,IAAI,CAAC,CAAC,SAAS;AACnG,MAAM,kBAAkB,cAAc,yBAAyB,cAAc,MAAM,IAAI,CAAC,CAAC,QAAQ;AAIjG,MAAM,OAAO,gBAAgB;CAC3B,MAAM;CACN,cAAc;CACd,MAAM,QAAQ,EAAE,OAAO,SAAS;EAC9B,MAAM,QAAQ,WAAW,qBAAqB,CAAC,EAAE,CAAC;EAClD,aAAa,EAAE,aAAa,OAAO,KAAK;CAC1C;AACF,CAAC;;AAwBD,SAAS,aAAa,MAA+B;CACnD,IAAI;CACJ,gBAAgB;EACd,OAAO,KAAK,MAAM;CACpB,CAAC;CACD,sBAAsB,OAAO,CAAC;AAChC;AA8CA,MAAa,SAAS;CAAE;CAAM,OAxChB,gBAAgB;EAC5B,MAAM;EACN,cAAc;EACd,OAAO;GAAE,KAAK;GAAQ,aAAa;EAAQ;EAC3C,OAAO,CAAC,qBAAqB;EAC7B,MAAM,OAAO,EAAE,OAAO,QAAQ;GAC5B,MAAM,OAAO,MAAM,IAAI;GACvB,kBAAkB,KAAK,OAAO,IAAI,MAAM,GAAG,GAAG,EAAE,OAAO,OAAO,CAAC;GAC/D,aAAa,KAAK,oBAAoB,WAAW,KAAK,uBAAuB,MAAM,CAAC,CAAC;GACrF,MAAM,SAAS,WAAW,KAAK,MAAM;GACrC,aACE,MAAM,cACF,EAAE,kBAAkB;IAAE,GAAG;IAAO,KAAK,MAAM;GAAI,CAAC,IAChD,OAAO,UAAU,WACf,EAAE,cAAc,KAAK,IACrB;EACV;CACF,CAuB8B;CAAO,UAZpB,gBAAgB;EAC/B,MAAM;EACN,cAAc;EACd,OAAO,EAAE,OAAO;GAAE,MAAM;GAA4B,SAAS,KAAA;EAAqB,EAAE;EACpF,MAAM,OAAO,EAAE,OAAO,SAAS;GAC7B,MAAM,WAAW,MAAM,IAAI,CAAC,CAAC,iBAAiB,EAAE,OAAO,MAAM,MAA4B,CAAC;GAC1F,aAAa,QAAQ;GACrB,MAAM,QAAQ,WAAW,SAAS,KAAK;GACvC,aAAc,MAAM,QAAQ,EAAE,iBAAiB,OAAO,KAAK,IAAI;EACjE;CACF,CAEqC;AAAS"}
|
package/src/calendar.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Changes, PartComponent, PartComponentProps, PlainComponent } from "./runtime.js";
|
|
2
|
-
import {
|
|
1
|
+
import { Changes, PartComponent, PartComponentProps, PartGiven, PartInstance, PlainComponent, StatesOf } from "./runtime.js";
|
|
2
|
+
import { PublicProps } from "vue";
|
|
3
|
+
import { Calendar as Calendar$1, CalendarDay, CalendarMode, CalendarMonth, CalendarProps, CalendarValueOf, CalendarWeekday } from "@kirana-ui/core/calendar";
|
|
4
|
+
type State = StatesOf<"calendar">;
|
|
3
5
|
/**
|
|
4
6
|
* The calendar its parts are inside. Exported for a component that is made of one (a date picker
|
|
5
7
|
* provides its own to the calendar's parts).
|
|
@@ -8,15 +10,14 @@ declare const scope: {
|
|
|
8
10
|
provide(controller: Calendar$1): Calendar$1;
|
|
9
11
|
use(): Calendar$1;
|
|
10
12
|
};
|
|
11
|
-
|
|
13
|
+
/** `value` and its events are typed by `mode`: a day, a range, or a list of days. */
|
|
14
|
+
export type RootProps<Mode extends CalendarMode = "single"> = Omit<CalendarProps<Mode>, "id" | "onValueChange" | "onMonthChange"> & {
|
|
12
15
|
id?: string | undefined;
|
|
13
16
|
} & PartComponentProps;
|
|
14
|
-
export type RootEmits = Changes<"value",
|
|
15
|
-
/** The month shown has changed: its first day. */
|
|
16
|
-
monthChange: (month: string) => void;
|
|
17
|
-
};
|
|
17
|
+
export type RootEmits<Mode extends CalendarMode = "single"> = Changes<"value", CalendarValueOf<Mode>> & Changes<"month", string>;
|
|
18
18
|
export type HeadingProps = PartComponentProps;
|
|
19
19
|
export type WeekdaysProps = Record<never, never>;
|
|
20
|
+
export type MonthsProps = Record<never, never>;
|
|
20
21
|
export type WeeksProps = Record<never, never>;
|
|
21
22
|
export interface HeadCellProps extends PartComponentProps {
|
|
22
23
|
/** The day of the week it names, as `Calendar.Weekdays` gives it. */
|
|
@@ -30,11 +31,11 @@ export type DayProps = CellProps;
|
|
|
30
31
|
export type PreviousProps = PartComponentProps;
|
|
31
32
|
export type NextProps = PartComponentProps;
|
|
32
33
|
export type GridProps = PartComponentProps;
|
|
34
|
+
export type InputProps = PartComponentProps;
|
|
33
35
|
export declare const Calendar: {
|
|
34
|
-
Root:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, RootProps, RootEmits>;
|
|
36
|
+
Root: new <Mode extends CalendarMode = "single", As extends string = "div">(props: PartGiven<As, RootProps<Mode>, RootEmits<Mode>> & PublicProps) => PartInstance<As, RootProps<Mode>, RootEmits<Mode>, {
|
|
37
|
+
state: State["root"];
|
|
38
|
+
}>;
|
|
38
39
|
Heading: PartComponent<"div", Record<never, never>, PartComponentProps>;
|
|
39
40
|
Previous: PartComponent<"button", {
|
|
40
41
|
readonly disabled?: true | undefined;
|
|
@@ -42,6 +43,9 @@ export declare const Calendar: {
|
|
|
42
43
|
Next: PartComponent<"button", {
|
|
43
44
|
readonly disabled?: true | undefined;
|
|
44
45
|
}, PartComponentProps, {}, unknown>;
|
|
46
|
+
Months: PlainComponent<MonthsProps, {}, {
|
|
47
|
+
month: CalendarMonth;
|
|
48
|
+
}>;
|
|
45
49
|
Grid: PartComponent<"table", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
46
50
|
Weekdays: PlainComponent<WeekdaysProps, {}, {
|
|
47
51
|
weekday: CalendarWeekday;
|
|
@@ -68,6 +72,8 @@ export declare const Calendar: {
|
|
|
68
72
|
readonly rangeStart?: true | undefined;
|
|
69
73
|
readonly rangeEnd?: true | undefined;
|
|
70
74
|
}, CellProps>;
|
|
75
|
+
/** The hidden input the value is submitted by, when the root has a `name`. */
|
|
76
|
+
Input: PartComponent<"input", Record<never, never>, PartComponentProps, {}, unknown>;
|
|
71
77
|
};
|
|
72
78
|
export { scope as calendarScope };
|
|
73
79
|
//# sourceMappingURL=calendar.d.ts.map
|
package/src/calendar.js
CHANGED
|
@@ -2,7 +2,7 @@ import { useDirectionAround } from "./direction-context.js";
|
|
|
2
2
|
import { written } from "./element.js";
|
|
3
3
|
import { context, controller, fromSignal, optional, partComponent } from "./runtime.js";
|
|
4
4
|
import { within } from "@kirana-ui/core";
|
|
5
|
-
import { Fragment, defineComponent, h, useId } from "vue";
|
|
5
|
+
import { Fragment, defineComponent, h, inject, provide, useId } from "vue";
|
|
6
6
|
import { createCalendar } from "@kirana-ui/core/calendar";
|
|
7
7
|
// src/calendar.ts
|
|
8
8
|
/**
|
|
@@ -11,14 +11,35 @@ import { createCalendar } from "@kirana-ui/core/calendar";
|
|
|
11
11
|
*/
|
|
12
12
|
const scope = context("Calendar");
|
|
13
13
|
const RootElement = partComponent("CalendarRootElement", "div", () => scope.use().root);
|
|
14
|
-
/**
|
|
14
|
+
/** The place of the month its parts are drawn in, inside `Calendar.Months`. */
|
|
15
|
+
const MONTH = Symbol("CalendarMonth");
|
|
16
|
+
/** The month a part is drawn in: the one `Calendar.Months` gave, or the first. */
|
|
17
|
+
const useMonth = () => scope.use().monthAt(inject(MONTH, 0));
|
|
18
|
+
/**
|
|
19
|
+
* `v-model:value`, `@value-change="(value, details) => …"`; `v-model:month` (the first day of
|
|
20
|
+
* the month shown), `@month-change="(month, details) => …"`.
|
|
21
|
+
*/
|
|
15
22
|
const Root = defineComponent({
|
|
16
23
|
name: "CalendarRoot",
|
|
17
24
|
inheritAttrs: false,
|
|
18
25
|
props: {
|
|
19
|
-
value: optional([
|
|
20
|
-
|
|
26
|
+
value: optional([
|
|
27
|
+
String,
|
|
28
|
+
Object,
|
|
29
|
+
Array
|
|
30
|
+
]),
|
|
31
|
+
defaultValue: [
|
|
32
|
+
String,
|
|
33
|
+
Object,
|
|
34
|
+
Array
|
|
35
|
+
],
|
|
21
36
|
mode: String,
|
|
37
|
+
minDays: Number,
|
|
38
|
+
maxDays: Number,
|
|
39
|
+
months: Number,
|
|
40
|
+
pagedNavigation: Boolean,
|
|
41
|
+
month: optional(String),
|
|
42
|
+
defaultMonth: String,
|
|
22
43
|
defaultFocusedValue: String,
|
|
23
44
|
locale: String,
|
|
24
45
|
calendarSystem: Object,
|
|
@@ -28,11 +49,14 @@ const Root = defineComponent({
|
|
|
28
49
|
disabled: Boolean,
|
|
29
50
|
readOnly: Boolean,
|
|
30
51
|
fixedWeeks: Boolean,
|
|
52
|
+
name: String,
|
|
53
|
+
form: String,
|
|
31
54
|
id: String
|
|
32
55
|
},
|
|
33
56
|
emits: [
|
|
34
57
|
"update:value",
|
|
35
58
|
"valueChange",
|
|
59
|
+
"update:month",
|
|
36
60
|
"monthChange"
|
|
37
61
|
],
|
|
38
62
|
setup(props, { attrs, slots, emit }) {
|
|
@@ -43,6 +67,12 @@ const Root = defineComponent({
|
|
|
43
67
|
value: props.value,
|
|
44
68
|
defaultValue: props.defaultValue,
|
|
45
69
|
mode: props.mode,
|
|
70
|
+
minDays: props.minDays,
|
|
71
|
+
maxDays: props.maxDays,
|
|
72
|
+
months: props.months,
|
|
73
|
+
pagedNavigation: props.pagedNavigation,
|
|
74
|
+
month: props.month,
|
|
75
|
+
defaultMonth: props.defaultMonth,
|
|
46
76
|
defaultFocusedValue: props.defaultFocusedValue,
|
|
47
77
|
locale: props.locale,
|
|
48
78
|
calendarSystem: props.calendarSystem,
|
|
@@ -52,11 +82,16 @@ const Root = defineComponent({
|
|
|
52
82
|
disabled: props.disabled,
|
|
53
83
|
readOnly: props.readOnly,
|
|
54
84
|
fixedWeeks: props.fixedWeeks,
|
|
85
|
+
name: props.name,
|
|
86
|
+
form: props.form,
|
|
55
87
|
onValueChange(value, details) {
|
|
56
88
|
emit("valueChange", value, details);
|
|
57
89
|
if (!details.canceled) emit("update:value", value);
|
|
58
90
|
},
|
|
59
|
-
onMonthChange
|
|
91
|
+
onMonthChange(month, details) {
|
|
92
|
+
emit("monthChange", month, details);
|
|
93
|
+
if (!details.canceled) emit("update:month", month);
|
|
94
|
+
}
|
|
60
95
|
})));
|
|
61
96
|
return () => h(RootElement, attrs, slots);
|
|
62
97
|
}
|
|
@@ -66,8 +101,9 @@ const Heading = defineComponent({
|
|
|
66
101
|
name: "CalendarHeading",
|
|
67
102
|
inheritAttrs: false,
|
|
68
103
|
setup(_, { attrs, slots }) {
|
|
69
|
-
const
|
|
70
|
-
const
|
|
104
|
+
const month = useMonth();
|
|
105
|
+
const title = fromSignal(month.title);
|
|
106
|
+
const HeadingElement = partComponent("CalendarHeadingElement", "div", () => month.heading, written(() => title.value));
|
|
71
107
|
return () => h(HeadingElement, attrs, slots.default ?? (() => title.value));
|
|
72
108
|
}
|
|
73
109
|
});
|
|
@@ -79,11 +115,37 @@ const Weekdays = defineComponent({
|
|
|
79
115
|
return () => weekdays.value.map((weekday) => h(Fragment, { key: weekday.index }, slots.default?.({ weekday })));
|
|
80
116
|
}
|
|
81
117
|
});
|
|
118
|
+
/** Holds the parts of one month: they are that month's. */
|
|
119
|
+
const MonthScope = defineComponent({
|
|
120
|
+
name: "CalendarMonthScope",
|
|
121
|
+
props: { index: {
|
|
122
|
+
type: Number,
|
|
123
|
+
required: true
|
|
124
|
+
} },
|
|
125
|
+
setup(props, { slots }) {
|
|
126
|
+
provide(MONTH, props.index);
|
|
127
|
+
return () => slots.default?.();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* Its slot once for each month shown (`months` on the root), side by side: `v-slot="{ month }"`.
|
|
132
|
+
* The parts inside each are that month's. Left out for one month.
|
|
133
|
+
*/
|
|
134
|
+
const Months = defineComponent({
|
|
135
|
+
name: "CalendarMonths",
|
|
136
|
+
setup(_, { slots }) {
|
|
137
|
+
const months = fromSignal(scope.use().months);
|
|
138
|
+
return () => months.value.map((month) => h(MonthScope, {
|
|
139
|
+
key: month.index,
|
|
140
|
+
index: month.index
|
|
141
|
+
}, () => slots.default?.({ month })));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
82
144
|
/** Its slot once for each week of the month shown: `v-slot="{ week }"`. */
|
|
83
145
|
const Weeks = defineComponent({
|
|
84
146
|
name: "CalendarWeeks",
|
|
85
147
|
setup(_, { slots }) {
|
|
86
|
-
const weeks = fromSignal(
|
|
148
|
+
const weeks = fromSignal(useMonth().weeks);
|
|
87
149
|
return () => weeks.value.map((week) => h(Fragment, { key: week[0].date }, slots.default?.({ week })));
|
|
88
150
|
}
|
|
89
151
|
});
|
|
@@ -108,7 +170,7 @@ const dated = (name, tag, member) => defineComponent({
|
|
|
108
170
|
required: true
|
|
109
171
|
} },
|
|
110
172
|
setup(props, { attrs, slots }) {
|
|
111
|
-
const part = scope.use()[member](props.date);
|
|
173
|
+
const part = scope.use()[member](props.date, inject(MONTH, void 0));
|
|
112
174
|
const Element = partComponent(`${name}Element`, tag, () => part);
|
|
113
175
|
return () => h(Element, attrs, slots);
|
|
114
176
|
}
|
|
@@ -118,12 +180,15 @@ const Calendar = {
|
|
|
118
180
|
Heading,
|
|
119
181
|
Previous: partComponent("CalendarPrevious", "button", () => scope.use().previous),
|
|
120
182
|
Next: partComponent("CalendarNext", "button", () => scope.use().next),
|
|
121
|
-
|
|
183
|
+
Months,
|
|
184
|
+
Grid: partComponent("CalendarGrid", "table", () => useMonth().grid),
|
|
122
185
|
Weekdays,
|
|
123
186
|
HeadCell,
|
|
124
187
|
Weeks,
|
|
125
188
|
Cell: dated("CalendarCell", "td", "cell"),
|
|
126
|
-
Day: dated("CalendarDay", "button", "day")
|
|
189
|
+
Day: dated("CalendarDay", "button", "day"),
|
|
190
|
+
/** The hidden input the value is submitted by, when the root has a `name`. */
|
|
191
|
+
Input: partComponent("CalendarInput", "input", () => scope.use().input)
|
|
127
192
|
};
|
|
128
193
|
export { Calendar, scope as calendarScope };
|
|
129
194
|
|
package/src/calendar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.js","names":[],"sources":["../../../../packages/vue/src/calendar.ts"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { ChangeDetails } from \"@kirana-ui/core\"\nimport { createCalendar } from \"@kirana-ui/core/calendar\"\nimport type {\n Calendar as Controller,\n CalendarDay,\n CalendarProps,\n CalendarValue,\n CalendarWeekday,\n} from \"@kirana-ui/core/calendar\"\nimport { Fragment, defineComponent, h, useId } from \"vue\"\nimport type { PropType } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { written } from \"./element.ts\"\nimport { context, controller, fromSignal, optional, partComponent } from \"./runtime.ts\"\nimport type {\n Changes,\n PartComponent,\n PartComponentProps,\n PlainComponent,\n StatesOf,\n} from \"./runtime.ts\"\n\ntype State = StatesOf<\"calendar\">\n\n/**\n * The calendar its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the calendar's parts).\n */\nconst scope = context<Controller>(\"Calendar\")\n/** For a component made of this one's parts: a date picker. */\nexport { scope as calendarScope }\n\nconst RootElement = partComponent(\"CalendarRootElement\", \"div\", () => scope.use().root)\n\nexport type RootProps = Omit<CalendarProps, \"id\" | \"onValueChange\" | \"onMonthChange\"> & {\n id?: string | undefined\n} & PartComponentProps\n\nexport type RootEmits = Changes<\"value\", CalendarValue> & {\n /** The month shown has changed: its first day. */\n monthChange: (month: string) => void\n}\n\n/** `v-model:value`, `@value-change=\"(value, details) => …\"`, `@month-change=\"(month) => …\"`. */\nconst Root = defineComponent({\n name: \"CalendarRoot\",\n inheritAttrs: false,\n props: {\n value: optional([String, Object] as PropType<CalendarValue>),\n defaultValue: [String, Object] as PropType<CalendarValue>,\n mode: String as PropType<\"single\" | \"range\">,\n defaultFocusedValue: String,\n locale: String,\n calendarSystem: Object as PropType<CalendarProps[\"calendarSystem\"]>,\n min: String,\n max: String,\n isDateUnavailable: Function as PropType<(date: string) => boolean>,\n disabled: Boolean,\n readOnly: Boolean,\n fixedWeeks: Boolean,\n id: String,\n },\n emits: [\"update:value\", \"valueChange\", \"monthChange\"],\n setup(props, { attrs, slots, emit }) {\n const generated = useId()\n const direction = useDirectionAround()\n scope.provide(\n controller(within(createCalendar, { direction }), () => ({\n id: props.id ?? generated,\n value: props.value,\n defaultValue: props.defaultValue,\n mode: props.mode,\n defaultFocusedValue: props.defaultFocusedValue,\n locale: props.locale,\n calendarSystem: props.calendarSystem,\n min: props.min,\n max: props.max,\n isDateUnavailable: props.isDateUnavailable,\n disabled: props.disabled,\n readOnly: props.readOnly,\n fixedWeeks: props.fixedWeeks,\n onValueChange(value: CalendarValue, details: ChangeDetails) {\n emit(\"valueChange\", value, details)\n if (!details.canceled) emit(\"update:value\", value)\n },\n onMonthChange: (month: string) => emit(\"monthChange\", month),\n }))\n )\n return () => h(RootElement, attrs, slots)\n },\n}) as unknown as PartComponent<\"div\", State[\"root\"], RootProps, RootEmits>\n\nexport type HeadingProps = PartComponentProps\n\n/** Names the month shown, unless it is given something else to say. */\nconst Heading = defineComponent({\n name: \"CalendarHeading\",\n inheritAttrs: false,\n setup(_, { attrs, slots }) {\n const title = fromSignal(scope.use().title)\n // With `as-child` the caller's element holds the text, unless it writes its own.\n const HeadingElement = partComponent(\n \"CalendarHeadingElement\",\n \"div\",\n () => scope.use().heading,\n written(() => title.value)\n )\n return () => h(HeadingElement, attrs, slots.default ?? (() => title.value))\n },\n}) as unknown as PartComponent<\"div\", State[\"heading\"], HeadingProps>\n\nexport type WeekdaysProps = Record<never, never>\n\n/** Its slot once for each day of the week, in the locale's order: `v-slot=\"{ weekday }\"`. */\nconst Weekdays = defineComponent({\n name: \"CalendarWeekdays\",\n setup(_, { slots }) {\n const weekdays = fromSignal(scope.use().weekdays)\n return () =>\n weekdays.value.map((weekday) =>\n h(Fragment, { key: weekday.index }, slots.default?.({ weekday }))\n )\n },\n}) as unknown as PlainComponent<WeekdaysProps, {}, { weekday: CalendarWeekday }>\n\nexport type WeeksProps = Record<never, never>\n\n/** Its slot once for each week of the month shown: `v-slot=\"{ week }\"`. */\nconst Weeks = defineComponent({\n name: \"CalendarWeeks\",\n setup(_, { slots }) {\n const weeks = fromSignal(scope.use().weeks)\n return () =>\n weeks.value.map((week) => h(Fragment, { key: week[0]!.date }, slots.default?.({ week })))\n },\n}) as unknown as PlainComponent<WeeksProps, {}, { week: readonly CalendarDay[] }>\n\nexport interface HeadCellProps extends PartComponentProps {\n /** The day of the week it names, as `Calendar.Weekdays` gives it. */\n weekday: CalendarWeekday\n}\n\nconst HeadCell = defineComponent({\n name: \"CalendarHeadCell\",\n inheritAttrs: false,\n props: { weekday: { type: Object as PropType<CalendarWeekday>, required: true } },\n setup(props, { attrs, slots }) {\n const part = scope.use().headCell(props.weekday)\n const Element = partComponent(\"CalendarHeadCellElement\", \"th\", () => part)\n return () => h(Element, attrs, slots)\n },\n}) as unknown as PartComponent<\"th\", State[\"headCell\"], HeadCellProps>\n\nexport interface CellProps extends PartComponentProps {\n /** The day it is for, as a week of `Calendar.Weeks` gives it. */\n date: string\n}\nexport type DayProps = CellProps\nexport type PreviousProps = PartComponentProps\nexport type NextProps = PartComponentProps\nexport type GridProps = PartComponentProps\n\nconst dated = <Tag extends string, Member extends \"cell\" | \"day\">(\n name: string,\n tag: Tag,\n member: Member\n) =>\n defineComponent({\n name,\n inheritAttrs: false,\n props: { date: { type: String, required: true } },\n setup(props, { attrs, slots }) {\n const part = scope.use()[member](props.date)\n const Element = partComponent<string>(`${name}Element`, tag, () => part)\n return () => h(Element, attrs, slots)\n },\n }) as unknown as PartComponent<Tag, State[Member], CellProps>\n\nexport const Calendar = {\n Root,\n Heading,\n Previous: partComponent<\"button\", State[\"previous\"]>(\n \"CalendarPrevious\",\n \"button\",\n () => scope.use().previous\n ),\n Next: partComponent<\"button\", State[\"next\"]>(\"CalendarNext\", \"button\", () => scope.use().next),\n Grid: partComponent<\"table\", State[\"grid\"]>(\"CalendarGrid\", \"table\", () => scope.use().grid),\n Weekdays,\n HeadCell,\n Weeks,\n Cell: dated(\"CalendarCell\", \"td\", \"cell\"),\n Day: dated(\"CalendarDay\", \"button\", \"day\"),\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"calendar.js","names":[],"sources":["../../../../packages/vue/src/calendar.ts"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { ChangeDetails } from \"@kirana-ui/core\"\nimport { createCalendar } from \"@kirana-ui/core/calendar\"\nimport type {\n Calendar as Controller,\n CalendarDay,\n CalendarMode,\n CalendarMonth,\n CalendarProps,\n CalendarValue,\n CalendarValueOf,\n CalendarWeekday,\n} from \"@kirana-ui/core/calendar\"\nimport { Fragment, defineComponent, h, inject, provide, useId } from \"vue\"\nimport type { InjectionKey, PropType, PublicProps } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { written } from \"./element.ts\"\nimport { context, controller, fromSignal, optional, partComponent } from \"./runtime.ts\"\nimport type {\n Changes,\n PartComponent,\n PartComponentProps,\n PartGiven,\n PartInstance,\n PlainComponent,\n StatesOf,\n} from \"./runtime.ts\"\n\ntype State = StatesOf<\"calendar\">\n\n/**\n * The calendar its parts are inside. Exported for a component that is made of one (a date picker\n * provides its own to the calendar's parts).\n */\nconst scope = context<Controller>(\"Calendar\")\n/** For a component made of this one's parts: a date picker. */\nexport { scope as calendarScope }\n\nconst RootElement = partComponent(\"CalendarRootElement\", \"div\", () => scope.use().root)\n\n/** The place of the month its parts are drawn in, inside `Calendar.Months`. */\nconst MONTH: InjectionKey<number> = Symbol(\"CalendarMonth\")\n/** The month a part is drawn in: the one `Calendar.Months` gave, or the first. */\nconst useMonth = () => scope.use().monthAt(inject(MONTH, 0))\n\n/** `value` and its events are typed by `mode`: a day, a range, or a list of days. */\nexport type RootProps<Mode extends CalendarMode = \"single\"> = Omit<\n CalendarProps<Mode>,\n \"id\" | \"onValueChange\" | \"onMonthChange\"\n> & {\n id?: string | undefined\n} & PartComponentProps\n\nexport type RootEmits<Mode extends CalendarMode = \"single\"> = Changes<\n \"value\",\n CalendarValueOf<Mode>\n> &\n Changes<\"month\", string>\n\n/**\n * `v-model:value`, `@value-change=\"(value, details) => …\"`; `v-model:month` (the first day of\n * the month shown), `@month-change=\"(month, details) => …\"`.\n */\nconst Root = defineComponent({\n name: \"CalendarRoot\",\n inheritAttrs: false,\n props: {\n value: optional([String, Object, Array] as PropType<CalendarValue>),\n defaultValue: [String, Object, Array] as PropType<CalendarValue>,\n mode: String as PropType<CalendarMode>,\n minDays: Number,\n maxDays: Number,\n months: Number,\n pagedNavigation: Boolean,\n month: optional(String),\n defaultMonth: String,\n defaultFocusedValue: String,\n locale: String,\n calendarSystem: Object as PropType<CalendarProps[\"calendarSystem\"]>,\n min: String,\n max: String,\n isDateUnavailable: Function as PropType<(date: string) => boolean>,\n disabled: Boolean,\n readOnly: Boolean,\n fixedWeeks: Boolean,\n name: String,\n form: String,\n id: String,\n },\n emits: [\"update:value\", \"valueChange\", \"update:month\", \"monthChange\"],\n setup(props, { attrs, slots, emit }) {\n const generated = useId()\n const direction = useDirectionAround()\n scope.provide(\n controller(within(createCalendar, { direction }), () => ({\n id: props.id ?? generated,\n value: props.value,\n defaultValue: props.defaultValue,\n mode: props.mode,\n minDays: props.minDays,\n maxDays: props.maxDays,\n months: props.months,\n pagedNavigation: props.pagedNavigation,\n month: props.month,\n defaultMonth: props.defaultMonth,\n defaultFocusedValue: props.defaultFocusedValue,\n locale: props.locale,\n calendarSystem: props.calendarSystem,\n min: props.min,\n max: props.max,\n isDateUnavailable: props.isDateUnavailable,\n disabled: props.disabled,\n readOnly: props.readOnly,\n fixedWeeks: props.fixedWeeks,\n name: props.name,\n form: props.form,\n onValueChange(value: CalendarValue, details: ChangeDetails) {\n emit(\"valueChange\", value, details)\n if (!details.canceled) emit(\"update:value\", value)\n },\n onMonthChange(month: string, details: ChangeDetails) {\n emit(\"monthChange\", month, details)\n if (!details.canceled) emit(\"update:month\", month)\n },\n }))\n )\n return () => h(RootElement, attrs, slots)\n },\n}) as unknown as new <Mode extends CalendarMode = \"single\", As extends string = \"div\">(\n props: PartGiven<As, RootProps<Mode>, RootEmits<Mode>> & PublicProps\n) => PartInstance<As, RootProps<Mode>, RootEmits<Mode>, { state: State[\"root\"] }>\n\nexport type HeadingProps = PartComponentProps\n\n/** Names the month shown, unless it is given something else to say. */\nconst Heading = defineComponent({\n name: \"CalendarHeading\",\n inheritAttrs: false,\n setup(_, { attrs, slots }) {\n const month = useMonth()\n const title = fromSignal(month.title)\n // With `as-child` the caller's element holds the text, unless it writes its own.\n const HeadingElement = partComponent(\n \"CalendarHeadingElement\",\n \"div\",\n () => month.heading,\n written(() => title.value)\n )\n return () => h(HeadingElement, attrs, slots.default ?? (() => title.value))\n },\n}) as unknown as PartComponent<\"div\", State[\"heading\"], HeadingProps>\n\nexport type WeekdaysProps = Record<never, never>\n\n/** Its slot once for each day of the week, in the locale's order: `v-slot=\"{ weekday }\"`. */\nconst Weekdays = defineComponent({\n name: \"CalendarWeekdays\",\n setup(_, { slots }) {\n const weekdays = fromSignal(scope.use().weekdays)\n return () =>\n weekdays.value.map((weekday) =>\n h(Fragment, { key: weekday.index }, slots.default?.({ weekday }))\n )\n },\n}) as unknown as PlainComponent<WeekdaysProps, {}, { weekday: CalendarWeekday }>\n\nexport type MonthsProps = Record<never, never>\n\n/** Holds the parts of one month: they are that month's. */\nconst MonthScope = defineComponent({\n name: \"CalendarMonthScope\",\n props: { index: { type: Number, required: true } },\n setup(props, { slots }) {\n // Keyed by its place: a scope is one month's for as long as it is drawn.\n provide(MONTH, props.index)\n return () => slots.default?.()\n },\n})\n\n/**\n * Its slot once for each month shown (`months` on the root), side by side: `v-slot=\"{ month }\"`.\n * The parts inside each are that month's. Left out for one month.\n */\nconst Months = defineComponent({\n name: \"CalendarMonths\",\n setup(_, { slots }) {\n const months = fromSignal(scope.use().months)\n return () =>\n months.value.map((month) =>\n h(MonthScope, { key: month.index, index: month.index }, () => slots.default?.({ month }))\n )\n },\n}) as unknown as PlainComponent<MonthsProps, {}, { month: CalendarMonth }>\n\nexport type WeeksProps = Record<never, never>\n\n/** Its slot once for each week of the month shown: `v-slot=\"{ week }\"`. */\nconst Weeks = defineComponent({\n name: \"CalendarWeeks\",\n setup(_, { slots }) {\n const weeks = fromSignal(useMonth().weeks)\n return () =>\n weeks.value.map((week) => h(Fragment, { key: week[0]!.date }, slots.default?.({ week })))\n },\n}) as unknown as PlainComponent<WeeksProps, {}, { week: readonly CalendarDay[] }>\n\nexport interface HeadCellProps extends PartComponentProps {\n /** The day of the week it names, as `Calendar.Weekdays` gives it. */\n weekday: CalendarWeekday\n}\n\nconst HeadCell = defineComponent({\n name: \"CalendarHeadCell\",\n inheritAttrs: false,\n props: { weekday: { type: Object as PropType<CalendarWeekday>, required: true } },\n setup(props, { attrs, slots }) {\n const part = scope.use().headCell(props.weekday)\n const Element = partComponent(\"CalendarHeadCellElement\", \"th\", () => part)\n return () => h(Element, attrs, slots)\n },\n}) as unknown as PartComponent<\"th\", State[\"headCell\"], HeadCellProps>\n\nexport interface CellProps extends PartComponentProps {\n /** The day it is for, as a week of `Calendar.Weeks` gives it. */\n date: string\n}\nexport type DayProps = CellProps\nexport type PreviousProps = PartComponentProps\nexport type NextProps = PartComponentProps\nexport type GridProps = PartComponentProps\nexport type InputProps = PartComponentProps\n\nconst dated = <Tag extends string, Member extends \"cell\" | \"day\">(\n name: string,\n tag: Tag,\n member: Member\n) =>\n defineComponent({\n name,\n inheritAttrs: false,\n props: { date: { type: String, required: true } },\n setup(props, { attrs, slots }) {\n const part = scope.use()[member](props.date, inject(MONTH, undefined))\n const Element = partComponent<string>(`${name}Element`, tag, () => part)\n return () => h(Element, attrs, slots)\n },\n }) as unknown as PartComponent<Tag, State[Member], CellProps>\n\nexport const Calendar = {\n Root,\n Heading,\n Previous: partComponent<\"button\", State[\"previous\"]>(\n \"CalendarPrevious\",\n \"button\",\n () => scope.use().previous\n ),\n Next: partComponent<\"button\", State[\"next\"]>(\"CalendarNext\", \"button\", () => scope.use().next),\n Months,\n Grid: partComponent<\"table\", State[\"grid\"]>(\"CalendarGrid\", \"table\", () => useMonth().grid),\n Weekdays,\n HeadCell,\n Weeks,\n Cell: dated(\"CalendarCell\", \"td\", \"cell\"),\n Day: dated(\"CalendarDay\", \"button\", \"day\"),\n /** The hidden input the value is submitted by, when the root has a `name`. */\n Input: partComponent<\"input\", State[\"input\"]>(\"CalendarInput\", \"input\", () => scope.use().input),\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InjectionKey } from "vue";
|
|
2
|
+
import { CheckboxGroup } from "@kirana-ui/core/checkbox-group";
|
|
3
|
+
/** The group a checkbox is one of the boxes of, if it is in one. */
|
|
4
|
+
export declare const CHECKBOX_GROUP: InjectionKey<CheckboxGroup | null>;
|
|
5
|
+
//# sourceMappingURL=checkbox-group-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox-group-context.js","names":[],"sources":["../../../../packages/vue/src/checkbox-group-context.ts"],"sourcesContent":["import type { CheckboxGroup } from \"@kirana-ui/core/checkbox-group\"\nimport type { InjectionKey } from \"vue\"\n\n/** The group a checkbox is one of the boxes of, if it is in one. */\nexport const CHECKBOX_GROUP: InjectionKey<CheckboxGroup | null> = Symbol(\"CheckboxGroup\")\n"],"mappings":";;AAIA,MAAa,iBAAqD,OAAO,eAAe"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Changes, PartComponent, PartComponentProps, StatesOf } from "./runtime.js";
|
|
2
|
+
import { CheckboxGroupProps as CheckboxGroupProps$1 } from "@kirana-ui/core/checkbox-group";
|
|
3
|
+
export type CheckboxGroupProps = Omit<CheckboxGroupProps$1, "id" | "onValueChange"> & {
|
|
4
|
+
id?: string | undefined;
|
|
5
|
+
} & PartComponentProps;
|
|
6
|
+
export type CheckboxGroupEmits = Changes<"value", string[]>;
|
|
7
|
+
/**
|
|
8
|
+
* `v-model:value` (a list). Each `Checkbox.Root` with a `value` inside it is checked while the
|
|
9
|
+
* list has its value; with `all-values`, a `Checkbox.Root` marked `parent` stands for them all.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CheckboxGroup: PartComponent<"div", StatesOf<"checkboxGroup">["root"], CheckboxGroupProps, CheckboxGroupEmits>;
|
|
12
|
+
//# sourceMappingURL=checkbox-group.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CHECKBOX_GROUP } from "./checkbox-group-context.js";
|
|
2
|
+
import { useFieldAround } from "./field-context.js";
|
|
3
|
+
import { controller, optional, partComponent } from "./runtime.js";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { defineComponent, h, provide, useId } from "vue";
|
|
6
|
+
import { createCheckboxGroup } from "@kirana-ui/core/checkbox-group";
|
|
7
|
+
// src/checkbox-group.ts
|
|
8
|
+
/**
|
|
9
|
+
* `v-model:value` (a list). Each `Checkbox.Root` with a `value` inside it is checked while the
|
|
10
|
+
* list has its value; with `all-values`, a `Checkbox.Root` marked `parent` stands for them all.
|
|
11
|
+
*/
|
|
12
|
+
const CheckboxGroup = defineComponent({
|
|
13
|
+
name: "CheckboxGroup",
|
|
14
|
+
inheritAttrs: false,
|
|
15
|
+
props: {
|
|
16
|
+
value: optional(Array),
|
|
17
|
+
defaultValue: Array,
|
|
18
|
+
allValues: Array,
|
|
19
|
+
disabled: Boolean,
|
|
20
|
+
id: String
|
|
21
|
+
},
|
|
22
|
+
emits: ["update:value", "valueChange"],
|
|
23
|
+
setup(props, { attrs, slots, emit }) {
|
|
24
|
+
const generated = useId();
|
|
25
|
+
const field = useFieldAround();
|
|
26
|
+
const made = controller(within(createCheckboxGroup, { field }), () => ({
|
|
27
|
+
id: props.id ?? generated,
|
|
28
|
+
value: props.value,
|
|
29
|
+
defaultValue: props.defaultValue,
|
|
30
|
+
allValues: props.allValues,
|
|
31
|
+
disabled: props.disabled,
|
|
32
|
+
onValueChange(value, details) {
|
|
33
|
+
emit("valueChange", value, details);
|
|
34
|
+
if (!details.canceled) emit("update:value", value);
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
provide(CHECKBOX_GROUP, made);
|
|
38
|
+
const Element = partComponent("CheckboxGroupElement", "div", () => made.root);
|
|
39
|
+
return () => h(Element, attrs, slots);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
export { CheckboxGroup };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=checkbox-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox-group.js","names":[],"sources":["../../../../packages/vue/src/checkbox-group.ts"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { ChangeDetails } from \"@kirana-ui/core\"\nimport { createCheckboxGroup } from \"@kirana-ui/core/checkbox-group\"\nimport type { CheckboxGroupProps as CoreProps } from \"@kirana-ui/core/checkbox-group\"\nimport { defineComponent, h, provide, useId } from \"vue\"\nimport type { PropType } from \"vue\"\n\nimport { CHECKBOX_GROUP } from \"./checkbox-group-context.ts\"\nimport { useFieldAround } from \"./field-context.ts\"\nimport { controller, optional, partComponent } from \"./runtime.ts\"\nimport type { Changes, PartComponent, PartComponentProps, StatesOf } from \"./runtime.ts\"\n\nexport type CheckboxGroupProps = Omit<CoreProps, \"id\" | \"onValueChange\"> & {\n id?: string | undefined\n} & PartComponentProps\n\nexport type CheckboxGroupEmits = Changes<\"value\", string[]>\n\n/**\n * `v-model:value` (a list). Each `Checkbox.Root` with a `value` inside it is checked while the\n * list has its value; with `all-values`, a `Checkbox.Root` marked `parent` stands for them all.\n */\nexport const CheckboxGroup = defineComponent({\n name: \"CheckboxGroup\",\n inheritAttrs: false,\n props: {\n value: optional(Array as PropType<readonly string[]>),\n defaultValue: Array as PropType<readonly string[]>,\n allValues: Array as PropType<readonly string[]>,\n disabled: Boolean,\n id: String,\n },\n emits: [\"update:value\", \"valueChange\"],\n setup(props, { attrs, slots, emit }) {\n const generated = useId()\n const field = useFieldAround()\n const made = controller(within(createCheckboxGroup, { field }), () => ({\n id: props.id ?? generated,\n value: props.value,\n defaultValue: props.defaultValue,\n allValues: props.allValues,\n disabled: props.disabled,\n onValueChange(value: string[], details: ChangeDetails) {\n emit(\"valueChange\", value, details)\n if (!details.canceled) emit(\"update:value\", value)\n },\n }))\n provide(CHECKBOX_GROUP, made)\n const Element = partComponent(\"CheckboxGroupElement\", \"div\", () => made.root)\n return () => h(Element, attrs, slots)\n },\n}) as unknown as PartComponent<\n \"div\",\n StatesOf<\"checkboxGroup\">[\"root\"],\n CheckboxGroupProps,\n CheckboxGroupEmits\n>\n"],"mappings":";;;;;;;;;;;AAsBA,MAAa,gBAAgB,gBAAgB;CAC3C,MAAM;CACN,cAAc;CACd,OAAO;EACL,OAAO,SAAS,KAAoC;EACpD,cAAc;EACd,WAAW;EACX,UAAU;EACV,IAAI;CACN;CACA,OAAO,CAAC,gBAAgB,aAAa;CACrC,MAAM,OAAO,EAAE,OAAO,OAAO,QAAQ;EACnC,MAAM,YAAY,MAAM;EACxB,MAAM,QAAQ,eAAe;EAC7B,MAAM,OAAO,WAAW,OAAO,qBAAqB,EAAE,MAAM,CAAC,UAAU;GACrE,IAAI,MAAM,MAAM;GAChB,OAAO,MAAM;GACb,cAAc,MAAM;GACpB,WAAW,MAAM;GACjB,UAAU,MAAM;GAChB,cAAc,OAAiB,SAAwB;IACrD,KAAK,eAAe,OAAO,OAAO;IAClC,IAAI,CAAC,QAAQ,UAAU,KAAK,gBAAgB,KAAK;GACnD;EACF,EAAE;EACF,QAAQ,gBAAgB,IAAI;EAC5B,MAAM,UAAU,cAAc,wBAAwB,aAAa,KAAK,IAAI;EAC5E,aAAa,EAAE,SAAS,OAAO,KAAK;CACtC;AACF,CAAC"}
|