@svelte-atoms/core 1.0.0-alpha.44 → 1.0.0-alpha.46
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/README.md +13 -0
- package/dist/components/accordion/item/accordion-item-body.svelte +5 -8
- package/dist/components/accordion/item/accordion-item-header.svelte +0 -13
- package/dist/components/accordion/item/accordion-item-indicator.svelte +0 -12
- package/dist/components/accordion/item/accordion-item-root.svelte +0 -12
- package/dist/components/alert/alert-actions.svelte +0 -12
- package/dist/components/alert/alert-close-button.svelte +0 -12
- package/dist/components/alert/alert-content.svelte +0 -12
- package/dist/components/alert/alert-description.svelte +0 -12
- package/dist/components/alert/alert-icon.svelte +0 -12
- package/dist/components/alert/alert-root.svelte +1 -13
- package/dist/components/alert/alert-title.svelte +0 -12
- package/dist/components/atom/html-atom.svelte +31 -17
- package/dist/components/atom/types.d.ts +9 -0
- package/dist/components/atom/utils/base.d.ts +6 -0
- package/dist/components/atom/utils/base.js +8 -0
- package/dist/components/atom/utils/cache.d.ts +17 -0
- package/dist/components/atom/utils/cache.js +134 -0
- package/dist/components/atom/utils/classes.d.ts +14 -0
- package/dist/components/atom/utils/classes.js +42 -0
- package/dist/components/atom/utils/constants.d.ts +9 -0
- package/dist/components/atom/utils/constants.js +9 -0
- package/dist/components/atom/utils/index.d.ts +6 -0
- package/dist/components/atom/utils/index.js +5 -0
- package/dist/components/atom/utils/preset.d.ts +22 -0
- package/dist/components/atom/utils/preset.js +94 -0
- package/dist/components/atom/utils/props.d.ts +13 -0
- package/dist/components/atom/utils/props.js +60 -0
- package/dist/components/atom/utils/variants.d.ts +31 -0
- package/dist/components/atom/utils/variants.js +270 -0
- package/dist/components/card/card-body.svelte +0 -12
- package/dist/components/card/card-description.svelte +0 -12
- package/dist/components/card/card-footer.svelte +0 -12
- package/dist/components/card/card-header.svelte +0 -12
- package/dist/components/card/card-media.svelte +0 -12
- package/dist/components/card/card-root.svelte +0 -12
- package/dist/components/card/card-subtitle.svelte +0 -12
- package/dist/components/card/card-title.svelte +0 -12
- package/dist/components/collapsible/collapsible-body.svelte +5 -12
- package/dist/components/collapsible/collapsible-header.svelte +0 -12
- package/dist/components/collapsible/collapsible-indicator.svelte +0 -12
- package/dist/components/collapsible/collapsible-root.svelte +0 -12
- package/dist/components/combobox/combobox-control.svelte +0 -12
- package/dist/components/combobox/combobox-item.svelte +0 -12
- package/dist/components/combobox/combobox-item.svelte.d.ts +0 -6
- package/dist/components/combobox/index.d.ts +1 -1
- package/dist/components/container/container.svelte +0 -12
- package/dist/components/datagrid/column/datagrid-column-sort-icon.svelte +3 -12
- package/dist/components/datagrid/column/datagrid-column-sort-icon.svelte.d.ts +0 -6
- package/dist/components/datagrid/datagrid-body.svelte +17 -1
- package/dist/components/dialog/dialog-body.svelte +0 -12
- package/dist/components/dialog/dialog-close-button.svelte +0 -12
- package/dist/components/dialog/dialog-close.svelte +0 -12
- package/dist/components/dialog/dialog-content.svelte +4 -12
- package/dist/components/dialog/dialog-description.svelte +0 -12
- package/dist/components/dialog/dialog-footer.svelte +0 -12
- package/dist/components/dialog/dialog-header.svelte +0 -12
- package/dist/components/dialog/dialog-title.svelte +0 -12
- package/dist/components/dialog/index.d.ts +3 -0
- package/dist/components/dialog/index.js +3 -0
- package/dist/components/drawer/drawer-backdrop.svelte +0 -12
- package/dist/components/drawer/drawer-body.svelte +0 -12
- package/dist/components/drawer/drawer-content.svelte +5 -12
- package/dist/components/drawer/drawer-description.svelte +0 -12
- package/dist/components/drawer/drawer-footer.svelte +0 -12
- package/dist/components/drawer/drawer-header.svelte +0 -12
- package/dist/components/drawer/drawer-root.svelte +5 -4
- package/dist/components/drawer/drawer-title.svelte +0 -12
- package/dist/components/dropdown/dropdown-placeholder.svelte +0 -6
- package/dist/components/dropdown/dropdown-placeholder.svelte.d.ts +0 -6
- package/dist/components/dropdown/dropdown-query.svelte +0 -12
- package/dist/components/dropdown-menu/bond.svelte.d.ts +0 -4
- package/dist/components/dropdown-menu/dropdown-menu-content.svelte +0 -12
- package/dist/components/dropdown-menu/dropdown-menu-content.svelte.d.ts +0 -6
- package/dist/components/dropdown-menu/index.d.ts +1 -1
- package/dist/components/form/field/bond.svelte.d.ts +29 -17
- package/dist/components/form/field/bond.svelte.js +73 -49
- package/dist/components/form/field/field-control.svelte +21 -18
- package/dist/components/form/field/field-label.svelte +2 -2
- package/dist/components/form/field/field-root.svelte +2 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/input/input-file-control.svelte +0 -12
- package/dist/components/input/input-icon.svelte +3 -3
- package/dist/components/input/input-number-control.svelte +28 -35
- package/dist/components/input/input-text-control.svelte +8 -3
- package/dist/components/input/input-url-control.svelte +2 -2
- package/dist/components/input/types.d.ts +4 -4
- package/dist/components/kbd/index.d.ts +3 -0
- package/dist/components/kbd/index.js +3 -0
- package/dist/components/kbd/kbd.svelte +19 -0
- package/dist/components/kbd/kbd.svelte.d.ts +4 -0
- package/dist/components/kbd/shortcut.svelte +38 -0
- package/dist/components/kbd/shortcut.svelte.d.ts +4 -0
- package/dist/components/kbd/types.d.ts +20 -0
- package/dist/components/kbd/types.js +1 -0
- package/dist/components/layer/layer-inner.svelte +0 -12
- package/dist/components/layer/layer-root.svelte +0 -12
- package/dist/components/menu/menu-content.svelte +0 -12
- package/dist/components/menu/menu-content.svelte.d.ts +0 -6
- package/dist/components/popover/bond.svelte.d.ts +29 -1
- package/dist/components/popover/bond.svelte.js +55 -2
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/popover/popover-arrow.svelte +4 -2
- package/dist/components/popover/popover-content.svelte +17 -90
- package/dist/components/popover/popover-overlay.svelte +98 -0
- package/dist/components/popover/popover-overlay.svelte.d.ts +4 -0
- package/dist/components/popover/popover-trigger.svelte +9 -0
- package/dist/components/popover/strategies/floating.svelte +10 -10
- package/dist/components/popover/types.d.ts +7 -2
- package/dist/components/portal/portal-inner.svelte +0 -12
- package/dist/components/portal/portal-root.svelte +0 -12
- package/dist/components/portal/types.d.ts +1 -1
- package/dist/components/progress/index.d.ts +3 -0
- package/dist/components/progress/index.js +3 -0
- package/dist/components/progress/progress-circular.svelte +99 -0
- package/dist/components/progress/progress-circular.svelte.d.ts +6 -0
- package/dist/components/progress/progress-linear.svelte +66 -0
- package/dist/components/progress/progress-linear.svelte.d.ts +6 -0
- package/dist/components/progress/types.d.ts +18 -0
- package/dist/components/progress/types.js +1 -0
- package/dist/components/scrollable/scrollable-container.svelte +0 -12
- package/dist/components/scrollable/scrollable-content.svelte +0 -12
- package/dist/components/scrollable/scrollable-root.svelte +0 -12
- package/dist/components/scrollable/scrollable-thumb.svelte +1 -12
- package/dist/components/scrollable/scrollable-track.svelte +0 -12
- package/dist/components/select/bond.svelte.d.ts +0 -4
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/select/select-placeholder.svelte +0 -6
- package/dist/components/select/select-placeholder.svelte.d.ts +0 -6
- package/dist/components/sidebar/sidebar-content.svelte +5 -12
- package/dist/components/stack/bond.svelte.js +6 -0
- package/dist/components/stack/stack-item.svelte +4 -0
- package/dist/components/switch/switch.svelte +2 -0
- package/dist/components/tabs/tab/tab-header.svelte +4 -4
- package/dist/components/tabs/tabs-body.svelte +0 -2
- package/dist/components/tabs/tabs-root.svelte +11 -3
- package/dist/components/toast/atoms.d.ts +1 -1
- package/dist/components/toast/atoms.js +1 -1
- package/dist/components/toast/attachments.svelte.d.ts +10 -2
- package/dist/components/toast/attachments.svelte.js +9 -1
- package/dist/components/toast/bond.svelte.d.ts +73 -0
- package/dist/components/toast/bond.svelte.js +132 -0
- package/dist/components/toast/index.d.ts +1 -1
- package/dist/components/toast/index.js +1 -1
- package/dist/components/toast/toast-close.svelte +47 -0
- package/dist/components/toast/toast-close.svelte.d.ts +26 -0
- package/dist/components/toast/toast-description.svelte +16 -24
- package/dist/components/toast/toast-description.svelte.d.ts +15 -19
- package/dist/components/toast/toast-root.svelte +36 -26
- package/dist/components/toast/toast-root.svelte.d.ts +16 -15
- package/dist/components/toast/toast-title.svelte +17 -22
- package/dist/components/toast/toast-title.svelte.d.ts +13 -13
- package/dist/components/toast/toaster.svelte.d.ts +38 -0
- package/dist/components/toast/toaster.svelte.js +107 -0
- package/dist/components/toast/types.d.ts +13 -21
- package/dist/components/tree/tree-body.svelte +5 -12
- package/dist/components/tree/tree-header.svelte +0 -12
- package/dist/components/tree/tree-indicator.svelte +0 -12
- package/dist/components/tree/tree-root.svelte +0 -12
- package/dist/context/preset.svelte.d.ts +53 -37
- package/dist/context/preset.svelte.js +29 -3
- package/package.json +1 -1
- package/dist/components/atom/utils.d.ts +0 -44
- package/dist/components/atom/utils.js +0 -275
- package/dist/components/popover/popover-engine.svelte +0 -118
- package/dist/components/popover/popover-engine.svelte.d.ts +0 -3
- package/dist/components/toast/bond.d.ts +0 -35
- package/dist/components/toast/bond.js +0 -59
- package/dist/components/toast/manager.svelte.d.ts +0 -38
- package/dist/components/toast/manager.svelte.js +0 -82
- package/dist/components/toast/toast-root-managed.svelte +0 -64
- package/dist/components/toast/toast-root-managed.svelte.d.ts +0 -7
- package/dist/components/toast/toast-toaster.svelte +0 -42
- package/dist/components/toast/toast-toaster.svelte.d.ts +0 -4
- /package/dist/components/popover/{motion.d.ts → motion.svelte.d.ts} +0 -0
- /package/dist/components/popover/{motion.js → motion.svelte.js} +0 -0
|
@@ -11,12 +11,6 @@
|
|
|
11
11
|
let {
|
|
12
12
|
class: klass = '',
|
|
13
13
|
children = undefined,
|
|
14
|
-
onmount = undefined,
|
|
15
|
-
ondestroy = undefined,
|
|
16
|
-
animate = undefined,
|
|
17
|
-
enter = undefined,
|
|
18
|
-
exit = undefined,
|
|
19
|
-
initial = undefined,
|
|
20
14
|
...restProps
|
|
21
15
|
}: SlideoverHeaderProps<E, B> & HTMLAttributes<Element> = $props();
|
|
22
16
|
|
|
@@ -30,12 +24,6 @@
|
|
|
30
24
|
{bond}
|
|
31
25
|
preset="drawer.header"
|
|
32
26
|
class={['border-border', '$preset', klass]}
|
|
33
|
-
onmount={onmount?.bind(bond.state)}
|
|
34
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
35
|
-
enter={enter?.bind(bond.state)}
|
|
36
|
-
exit={exit?.bind(bond.state)}
|
|
37
|
-
initial={initial?.bind(bond.state)}
|
|
38
|
-
animate={animate?.bind(bond.state)}
|
|
39
27
|
{...headerProps}
|
|
40
28
|
{...restProps}
|
|
41
29
|
>
|
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
portal = undefined,
|
|
21
21
|
"z-index": zindex = 1,
|
|
22
22
|
onclose = undefined,
|
|
23
|
-
initial = animateDrawerRoot({ duration: 0 }),
|
|
24
|
-
animate = animateDrawerRoot({}),
|
|
25
23
|
factory = _factory,
|
|
24
|
+
fallback = {
|
|
25
|
+
animate: animateDrawerRoot({}),
|
|
26
|
+
initial: animateDrawerRoot({ duration: 0 }),
|
|
27
|
+
},
|
|
26
28
|
...restProps
|
|
27
29
|
}: SlideoverRootProps<E, B> & HTMLAttributes<Element> = $props();
|
|
28
30
|
|
|
@@ -86,8 +88,7 @@
|
|
|
86
88
|
]}
|
|
87
89
|
style="z-index: {layer.get()};"
|
|
88
90
|
closeby="none"
|
|
89
|
-
|
|
90
|
-
animate={animate?.bind(bond.state)}
|
|
91
|
+
{fallback}
|
|
91
92
|
{...rootProps}
|
|
92
93
|
>
|
|
93
94
|
<ActivePortal portal={portal ?? 'root.l0'}>
|
|
@@ -12,12 +12,6 @@
|
|
|
12
12
|
class: klass = '',
|
|
13
13
|
as = 'h3' as E,
|
|
14
14
|
children,
|
|
15
|
-
onmount = undefined,
|
|
16
|
-
ondestroy = undefined,
|
|
17
|
-
animate = undefined,
|
|
18
|
-
enter = undefined,
|
|
19
|
-
exit = undefined,
|
|
20
|
-
initial = undefined,
|
|
21
15
|
...restProps
|
|
22
16
|
}: SlideoverTitleProps<E, B> & HTMLAttributes<Element> = $props();
|
|
23
17
|
|
|
@@ -32,12 +26,6 @@
|
|
|
32
26
|
{bond}
|
|
33
27
|
preset="drawer.title"
|
|
34
28
|
class={['border-border', '$preset', klass]}
|
|
35
|
-
onmount={onmount?.bind(bond.state)}
|
|
36
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
37
|
-
enter={enter?.bind(bond.state)}
|
|
38
|
-
exit={exit?.bind(bond.state)}
|
|
39
|
-
initial={initial?.bind(bond.state)}
|
|
40
|
-
animate={animate?.bind(bond.state)}
|
|
41
29
|
{...titleProps}
|
|
42
30
|
>
|
|
43
31
|
{@render children?.({ drawer: bond })}
|
|
@@ -3,12 +3,6 @@ declare function $$render<T extends keyof HTMLElementTagNameMap = 'div', B exten
|
|
|
3
3
|
props: {
|
|
4
4
|
class?: string;
|
|
5
5
|
children?: any;
|
|
6
|
-
onmount?: any;
|
|
7
|
-
ondestroy?: any;
|
|
8
|
-
animate?: any;
|
|
9
|
-
enter?: any;
|
|
10
|
-
exit?: any;
|
|
11
|
-
initial?: any;
|
|
12
6
|
} & Record<string, any>;
|
|
13
7
|
exports: {};
|
|
14
8
|
bindings: "";
|
|
@@ -13,12 +13,6 @@
|
|
|
13
13
|
value = $bindable(),
|
|
14
14
|
class: klass = '',
|
|
15
15
|
children = undefined,
|
|
16
|
-
onmount = undefined,
|
|
17
|
-
ondestroy = undefined,
|
|
18
|
-
animate = undefined,
|
|
19
|
-
enter = undefined,
|
|
20
|
-
exit = undefined,
|
|
21
|
-
initial = undefined,
|
|
22
16
|
...restProps
|
|
23
17
|
}: DropdownQueryProps = $props();
|
|
24
18
|
</script>
|
|
@@ -33,11 +27,5 @@
|
|
|
33
27
|
{bond}
|
|
34
28
|
preset="dropdown.query"
|
|
35
29
|
class={['inline-flex h-auto w-auto flex-1 py-1', '$preset', klass]}
|
|
36
|
-
onmount={onmount?.bind(bond.state)}
|
|
37
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
38
|
-
enter={enter?.bind(bond.state)}
|
|
39
|
-
exit={exit?.bind(bond.state)}
|
|
40
|
-
initial={initial?.bind(bond.state)}
|
|
41
|
-
animate={animate?.bind(bond.state)}
|
|
42
30
|
{...restProps}
|
|
43
31
|
/>
|
|
@@ -10,10 +10,6 @@ export declare class DropdownMenuContentAtom extends PopoverContentAtom {
|
|
|
10
10
|
role: "menu";
|
|
11
11
|
'aria-activedescendant': string | undefined;
|
|
12
12
|
'aria-orientation': "vertical";
|
|
13
|
-
'aria-modal': boolean;
|
|
14
|
-
'aria-labelledby': string;
|
|
15
|
-
inert: boolean | undefined;
|
|
16
|
-
tabindex: number;
|
|
17
13
|
'data-active': boolean;
|
|
18
14
|
};
|
|
19
15
|
get handlers(): {
|
|
@@ -12,12 +12,6 @@
|
|
|
12
12
|
base = Root as B,
|
|
13
13
|
preset = 'dropdown-menu.content',
|
|
14
14
|
children = undefined,
|
|
15
|
-
onmount = undefined,
|
|
16
|
-
ondestroy = undefined,
|
|
17
|
-
animate = undefined,
|
|
18
|
-
enter = undefined,
|
|
19
|
-
exit = undefined,
|
|
20
|
-
initial = undefined,
|
|
21
15
|
...restProps
|
|
22
16
|
} = $props();
|
|
23
17
|
</script>
|
|
@@ -28,12 +22,6 @@
|
|
|
28
22
|
{bond}
|
|
29
23
|
{preset}
|
|
30
24
|
class={['border-border overflow-hidden p-0', '$preset', klass]}
|
|
31
|
-
onmount={onmount?.bind(bond.state)}
|
|
32
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
33
|
-
enter={enter?.bind(bond.state)}
|
|
34
|
-
exit={exit?.bind(bond.state)}
|
|
35
|
-
initial={initial?.bind(bond.state)}
|
|
36
|
-
animate={animate?.bind(bond.state)}
|
|
37
25
|
{...restProps}
|
|
38
26
|
>
|
|
39
27
|
{@render children?.()}
|
|
@@ -6,12 +6,6 @@ declare function $$render<T extends keyof HTMLElementTagNameMap = 'div', B exten
|
|
|
6
6
|
base?: B;
|
|
7
7
|
preset?: string;
|
|
8
8
|
children?: any;
|
|
9
|
-
onmount?: any;
|
|
10
|
-
ondestroy?: any;
|
|
11
|
-
animate?: any;
|
|
12
|
-
enter?: any;
|
|
13
|
-
exit?: any;
|
|
14
|
-
initial?: any;
|
|
15
9
|
} & Record<string, any>;
|
|
16
10
|
exports: {};
|
|
17
11
|
bindings: "";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * as DropdownMenu from './atoms';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export { PopoverBond, type PopoverDomElements, type PopoverParams, PopoverState, type PopoverStateProps, type TriggerParams } from '../popover';
|
|
4
|
-
export type { AnimatePopoverContentParams as AnimateDropdownMenuContentParams, animatePopoverContent as animateDropdownMenuContent } from '../popover/motion';
|
|
4
|
+
export type { AnimatePopoverContentParams as AnimateDropdownMenuContentParams, animatePopoverContent as animateDropdownMenuContent } from '../popover/motion.svelte';
|
|
5
5
|
export * from './item';
|
|
6
6
|
export { dropdownMenu } from './attachments.svelte';
|
|
7
7
|
export { DropdownMenuBond, DropdownMenuBondState, DropdownMenuContentAtom, DropdownMenuTriggerAtom, DropdownMenuItemAtom, type DropdownMenuBondProps, type DropdownMenuBondElements } from './bond.svelte';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bond, BondState, type BondStateProps } from '../../../shared/bond.svelte';
|
|
1
|
+
import { Bond, BondAtom, BondState, type BondStateProps } from '../../../shared/bond.svelte';
|
|
2
2
|
export interface ValidationError {
|
|
3
3
|
path: (string | number)[];
|
|
4
4
|
message: string;
|
|
@@ -13,12 +13,13 @@ export interface ValidationAdapter<Schema, Value> {
|
|
|
13
13
|
validate(schema: Schema, value: Value): ValidationResult<Value>;
|
|
14
14
|
validateAsync?(schema: Schema, value: Value): Promise<ValidationResult<Value>>;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
parse: (value: unknown) =>
|
|
18
|
-
parseAsync?: (value: unknown) => Promise<
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
type ZodLikeSchema = {
|
|
17
|
+
parse: (value: unknown) => unknown;
|
|
18
|
+
parseAsync?: (value: unknown) => Promise<unknown>;
|
|
19
|
+
};
|
|
20
|
+
export declare class ZodValidationAdapter<T extends ZodLikeSchema> implements ValidationAdapter<T, unknown> {
|
|
21
|
+
validate(schema: T, value: unknown): ValidationResult;
|
|
22
|
+
validateAsync(schema: T, value: unknown): Promise<ValidationResult>;
|
|
22
23
|
}
|
|
23
24
|
export type FieldStateProps<Extension extends Record<string, unknown> = Record<string, unknown>, Schema = unknown, Value = unknown> = BondStateProps & {
|
|
24
25
|
disabled: boolean;
|
|
@@ -31,7 +32,7 @@ export type FieldStateProps<Extension extends Record<string, unknown> = Record<s
|
|
|
31
32
|
checked?: boolean;
|
|
32
33
|
schema?: Schema;
|
|
33
34
|
validator?: ValidationAdapter<Schema, Value>;
|
|
34
|
-
onvalidation?: (
|
|
35
|
+
onvalidation?: (result: ValidationResult<Value>) => void;
|
|
35
36
|
extend: Extension;
|
|
36
37
|
};
|
|
37
38
|
export type FieldDomElements = {
|
|
@@ -39,31 +40,41 @@ export type FieldDomElements = {
|
|
|
39
40
|
label: HTMLElement;
|
|
40
41
|
control: HTMLElement;
|
|
41
42
|
};
|
|
42
|
-
export declare class
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
root(): {
|
|
46
|
-
[x: symbol]: (node: HTMLElement) => void;
|
|
43
|
+
export declare class FieldRootAtom extends BondAtom<FieldBond, HTMLElement> {
|
|
44
|
+
constructor(bond: FieldBond);
|
|
45
|
+
get attrs(): {
|
|
47
46
|
id: string;
|
|
48
47
|
role: string;
|
|
49
48
|
'aria-labelledby': string;
|
|
50
49
|
'aria-describedby': string | undefined;
|
|
51
50
|
'aria-invalid': string;
|
|
52
51
|
};
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
}
|
|
53
|
+
export declare class FieldLabelAtom extends BondAtom<FieldBond, HTMLElement> {
|
|
54
|
+
constructor(bond: FieldBond);
|
|
55
|
+
get attrs(): {
|
|
55
56
|
id: string;
|
|
56
57
|
for: string;
|
|
57
58
|
};
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
}
|
|
60
|
+
export declare class FieldControlAtom extends BondAtom<FieldBond, HTMLElement> {
|
|
61
|
+
constructor(bond: FieldBond);
|
|
62
|
+
get attrs(): {
|
|
60
63
|
id: string;
|
|
61
64
|
'aria-labelledby': string;
|
|
62
65
|
'aria-describedby': string | undefined;
|
|
63
66
|
'aria-invalid': string;
|
|
64
67
|
'aria-disabled': string;
|
|
65
68
|
'aria-readonly': string;
|
|
69
|
+
'aria-errormessage': string | undefined;
|
|
66
70
|
};
|
|
71
|
+
}
|
|
72
|
+
export declare class FieldBond extends Bond<FieldStateProps, FieldBondState, FieldDomElements> {
|
|
73
|
+
static CONTEXT_KEY: string;
|
|
74
|
+
constructor(state: FieldBondState);
|
|
75
|
+
root(): FieldRootAtom;
|
|
76
|
+
label(): FieldLabelAtom;
|
|
77
|
+
control(): FieldControlAtom;
|
|
67
78
|
share(): this;
|
|
68
79
|
static get(): FieldBond | undefined;
|
|
69
80
|
static set(bond: FieldBond): FieldBond;
|
|
@@ -86,3 +97,4 @@ export declare class FieldBondState<Props extends FieldStateProps = FieldStatePr
|
|
|
86
97
|
value: unknown;
|
|
87
98
|
};
|
|
88
99
|
}
|
|
100
|
+
export {};
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { Bond, BondAtom, BondState } from '../../../shared/bond.svelte';
|
|
3
|
+
function isZodLikeError(error) {
|
|
4
|
+
return (typeof error === 'object' &&
|
|
5
|
+
error !== null &&
|
|
6
|
+
'issues' in error &&
|
|
7
|
+
Array.isArray(error.issues));
|
|
8
|
+
}
|
|
9
|
+
function toValidationError(issue) {
|
|
10
|
+
return {
|
|
11
|
+
path: issue.path || [],
|
|
12
|
+
message: issue.message || 'Validation error',
|
|
13
|
+
...(issue.code ? { code: issue.code } : {})
|
|
14
|
+
};
|
|
15
|
+
}
|
|
4
16
|
export class ZodValidationAdapter {
|
|
5
17
|
validate(schema, value) {
|
|
6
18
|
try {
|
|
@@ -8,14 +20,10 @@ export class ZodValidationAdapter {
|
|
|
8
20
|
return { success: true, data, errors: [] };
|
|
9
21
|
}
|
|
10
22
|
catch (error) {
|
|
11
|
-
if (
|
|
23
|
+
if (isZodLikeError(error)) {
|
|
12
24
|
return {
|
|
13
25
|
success: false,
|
|
14
|
-
errors: error.issues.map(
|
|
15
|
-
path: issue.path || [],
|
|
16
|
-
message: issue.message || 'Validation error',
|
|
17
|
-
code: issue.code
|
|
18
|
-
}))
|
|
26
|
+
errors: error.issues.map(toValidationError)
|
|
19
27
|
};
|
|
20
28
|
}
|
|
21
29
|
throw error;
|
|
@@ -30,59 +38,74 @@ export class ZodValidationAdapter {
|
|
|
30
38
|
return { success: true, data, errors: [] };
|
|
31
39
|
}
|
|
32
40
|
catch (error) {
|
|
33
|
-
if (
|
|
41
|
+
if (isZodLikeError(error)) {
|
|
34
42
|
return {
|
|
35
43
|
success: false,
|
|
36
|
-
errors: error.issues.map(
|
|
37
|
-
path: issue.path || [],
|
|
38
|
-
message: issue.message || 'Validation error',
|
|
39
|
-
code: issue.code
|
|
40
|
-
}))
|
|
44
|
+
errors: error.issues.map(toValidationError)
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
47
|
throw error;
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
|
-
export class
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
super(state);
|
|
51
|
+
export class FieldRootAtom extends BondAtom {
|
|
52
|
+
constructor(bond) {
|
|
53
|
+
super(bond, 'root');
|
|
51
54
|
}
|
|
52
|
-
|
|
55
|
+
get attrs() {
|
|
53
56
|
return {
|
|
54
|
-
|
|
57
|
+
...super.attrs,
|
|
58
|
+
id: `root-${this.bond.id}`,
|
|
55
59
|
role: 'group',
|
|
56
|
-
'aria-labelledby': `label-${this.id}`,
|
|
57
|
-
'aria-describedby': this.state.errors.length > 0 ? `error-${this.id}` : undefined,
|
|
58
|
-
'aria-invalid':
|
|
59
|
-
[createAttachmentKey()]: (node) => {
|
|
60
|
-
this.elements.root = node;
|
|
61
|
-
}
|
|
60
|
+
'aria-labelledby': `label-${this.bond.id}`,
|
|
61
|
+
'aria-describedby': this.bond.state.errors.length > 0 ? `error-${this.bond.id}` : undefined,
|
|
62
|
+
'aria-invalid': `${this.bond.state.errors.length > 0}`
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
}
|
|
66
|
+
export class FieldLabelAtom extends BondAtom {
|
|
67
|
+
constructor(bond) {
|
|
68
|
+
super(bond, 'label');
|
|
69
|
+
}
|
|
70
|
+
get attrs() {
|
|
65
71
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.elements.label = node;
|
|
70
|
-
}
|
|
72
|
+
...super.attrs,
|
|
73
|
+
id: `label-${this.bond.id}`,
|
|
74
|
+
for: `control-${this.bond.id}`
|
|
71
75
|
};
|
|
72
76
|
}
|
|
73
|
-
|
|
77
|
+
}
|
|
78
|
+
export class FieldControlAtom extends BondAtom {
|
|
79
|
+
constructor(bond) {
|
|
80
|
+
super(bond, 'control');
|
|
81
|
+
}
|
|
82
|
+
get attrs() {
|
|
74
83
|
return {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'aria-
|
|
78
|
-
'aria-
|
|
79
|
-
'aria-
|
|
80
|
-
'aria-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
+
...super.attrs,
|
|
85
|
+
id: `control-${this.bond.id}`,
|
|
86
|
+
'aria-labelledby': `label-${this.bond.id}`,
|
|
87
|
+
'aria-describedby': this.bond.state.errors.length > 0 ? `error-${this.bond.id}` : undefined,
|
|
88
|
+
'aria-invalid': `${this.bond.state.errors.length > 0}`,
|
|
89
|
+
'aria-disabled': `${this.bond.state.props.disabled}`,
|
|
90
|
+
'aria-readonly': `${this.bond.state.props.readonly}`,
|
|
91
|
+
'aria-errormessage': this.bond.state.errors.length > 0 ? `error-${this.bond.id}` : undefined
|
|
84
92
|
};
|
|
85
93
|
}
|
|
94
|
+
}
|
|
95
|
+
export class FieldBond extends Bond {
|
|
96
|
+
static CONTEXT_KEY = '@atoms/context/form/field';
|
|
97
|
+
constructor(state) {
|
|
98
|
+
super(state, 'field');
|
|
99
|
+
}
|
|
100
|
+
root() {
|
|
101
|
+
return this.atom('root', () => new FieldRootAtom(this));
|
|
102
|
+
}
|
|
103
|
+
label() {
|
|
104
|
+
return this.atom('label', () => new FieldLabelAtom(this));
|
|
105
|
+
}
|
|
106
|
+
control() {
|
|
107
|
+
return this.atom('control', () => new FieldControlAtom(this));
|
|
108
|
+
}
|
|
86
109
|
share() {
|
|
87
110
|
return FieldBond.set(this);
|
|
88
111
|
}
|
|
@@ -94,7 +117,6 @@ export class FieldBond extends Bond {
|
|
|
94
117
|
}
|
|
95
118
|
}
|
|
96
119
|
export class FieldBondState extends BondState {
|
|
97
|
-
#data = $state(undefined);
|
|
98
120
|
#errors = $state([]);
|
|
99
121
|
#isValidating = $state(false);
|
|
100
122
|
constructor(props) {
|
|
@@ -125,20 +147,22 @@ export class FieldBondState extends BondState {
|
|
|
125
147
|
const { schema, validator, value, onvalidation } = this.props;
|
|
126
148
|
if (!schema || !validator) {
|
|
127
149
|
this.#errors = [];
|
|
128
|
-
|
|
129
|
-
|
|
150
|
+
const result = { success: true, data: value, errors: [] };
|
|
151
|
+
onvalidation?.(result);
|
|
152
|
+
return result;
|
|
130
153
|
}
|
|
131
154
|
const result = validator.validate(schema, value);
|
|
132
155
|
this.#errors = result.errors;
|
|
133
|
-
onvalidation?.(
|
|
156
|
+
onvalidation?.(result);
|
|
134
157
|
return result;
|
|
135
158
|
}
|
|
136
159
|
async validateASync() {
|
|
137
160
|
const { schema, validator, value, onvalidation } = this.props;
|
|
138
161
|
if (!schema || !validator) {
|
|
139
162
|
this.#errors = [];
|
|
140
|
-
|
|
141
|
-
|
|
163
|
+
const result = { success: true, data: value, errors: [] };
|
|
164
|
+
onvalidation?.(result);
|
|
165
|
+
return result;
|
|
142
166
|
}
|
|
143
167
|
this.#isValidating = true;
|
|
144
168
|
try {
|
|
@@ -146,7 +170,7 @@ export class FieldBondState extends BondState {
|
|
|
146
170
|
? await validator.validateAsync(schema, value)
|
|
147
171
|
: validator.validate(schema, value);
|
|
148
172
|
this.#errors = result.errors;
|
|
149
|
-
onvalidation?.(
|
|
173
|
+
onvalidation?.(result);
|
|
150
174
|
return result;
|
|
151
175
|
}
|
|
152
176
|
finally {
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { FieldBond } from './bond.svelte';
|
|
4
4
|
import type { FieldControlProps } from '../types';
|
|
5
5
|
|
|
6
|
+
type InputDetail = { value?: unknown; files?: File[]; date?: Date | null; number?: number; checked?: boolean }
|
|
7
|
+
|
|
6
8
|
const bond = FieldBond.get();
|
|
7
9
|
const name = $derived(bond?.state?.props?.name);
|
|
8
10
|
|
|
@@ -17,41 +19,42 @@
|
|
|
17
19
|
oninput = undefined,
|
|
18
20
|
...restProps
|
|
19
21
|
}: FieldControlProps<E, B> = $props();
|
|
22
|
+
|
|
20
23
|
const controlProps = $derived.by(() => {
|
|
21
|
-
const raw = /** @type {Record<string, unknown>} */ (bond?.control?.() ?? {});
|
|
22
24
|
return {
|
|
23
|
-
...
|
|
25
|
+
...(bond?.control().spread ?? {}),
|
|
24
26
|
...restProps
|
|
25
27
|
};
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
function handleInput(
|
|
29
|
-
ev:
|
|
30
|
-
|
|
31
|
-
files?: File[];
|
|
32
|
-
date?: Date | null;
|
|
33
|
-
number?: number;
|
|
34
|
-
checked?: boolean;
|
|
35
|
-
}>
|
|
31
|
+
ev: InputEvent,
|
|
32
|
+
inputDetail: InputDetail
|
|
36
33
|
) {
|
|
37
|
-
oninput?.(ev,
|
|
34
|
+
oninput?.(ev, inputDetail);
|
|
38
35
|
|
|
39
36
|
if (ev.defaultPrevented) {
|
|
40
37
|
return;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
const detail =
|
|
40
|
+
const detail = inputDetail ?? {};
|
|
41
|
+
|
|
42
|
+
value = detail?.value;
|
|
43
|
+
files = detail?.files ?? [];
|
|
44
|
+
date = detail?.date ?? null;
|
|
45
|
+
if (detail?.number !== undefined) {
|
|
46
|
+
number = detail.number;
|
|
47
|
+
}
|
|
48
|
+
checked = detail?.checked ?? false;
|
|
44
49
|
|
|
45
50
|
if (!bond) {
|
|
46
51
|
return;
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
bond.state.props.value = value
|
|
50
|
-
bond.state.props.files = files
|
|
51
|
-
bond.state.props.date = date
|
|
52
|
-
|
|
53
|
-
bond.state.props.number = number = detail.number;
|
|
54
|
-
}
|
|
54
|
+
bond.state.props.value = value
|
|
55
|
+
bond.state.props.files = files
|
|
56
|
+
bond.state.props.date = date
|
|
57
|
+
bond.state.props.number = number
|
|
55
58
|
bond.state.props.checked = checked = detail?.checked ?? false;
|
|
56
59
|
}
|
|
57
60
|
</script>
|
|
@@ -62,7 +65,7 @@
|
|
|
62
65
|
{name}
|
|
63
66
|
preset="field.control"
|
|
64
67
|
class={['flex items-center', '$preset', klass]}
|
|
65
|
-
oninput={(ev:
|
|
68
|
+
oninput={(ev: InputEvent, detail: InputDetail) => handleInput(ev, detail)}
|
|
66
69
|
{...controlProps}
|
|
67
70
|
>
|
|
68
71
|
{@render children?.({ field: bond })}
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
}: FieldLabelProps<E, B> = $props();
|
|
13
13
|
|
|
14
14
|
const labelProps = $derived({
|
|
15
|
-
...bond?.label(),
|
|
15
|
+
...(bond?.label().spread ?? {}),
|
|
16
16
|
...restProps
|
|
17
17
|
});
|
|
18
18
|
</script>
|
|
19
19
|
|
|
20
|
-
<HtmlAtom preset="field.label" class={['flex
|
|
20
|
+
<HtmlAtom preset="field.label" class={['flex', '$preset', klass]} {...labelProps}>
|
|
21
21
|
{@render children?.({ field: bond })}
|
|
22
22
|
</HtmlAtom>
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
const rootProps = $derived(
|
|
47
47
|
({
|
|
48
|
-
...bond
|
|
48
|
+
...bond.root().spread,
|
|
49
49
|
...restProps
|
|
50
50
|
}) as Record<string, unknown>
|
|
51
51
|
);
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
export function getBond() {
|
|
62
62
|
return bond;
|
|
63
63
|
}
|
|
64
|
+
|
|
64
65
|
</script>
|
|
65
66
|
|
|
66
67
|
<HtmlAtom preset="field" class={['flex flex-col', '$preset', klass]} {...rootProps}>
|
package/dist/components/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
3
2
|
import { HtmlAtom } from '../atom';
|
|
4
3
|
import { InputBond } from './bond.svelte';
|
|
5
4
|
import type { InputFileControlProps } from './types';
|
|
@@ -23,17 +22,6 @@
|
|
|
23
22
|
|
|
24
23
|
const hasFiles = $derived(files.length > 0);
|
|
25
24
|
|
|
26
|
-
const fileLabel = $derived(() => {
|
|
27
|
-
if (!hasFiles) return null;
|
|
28
|
-
if (files.length === 1) {
|
|
29
|
-
const f = files[0];
|
|
30
|
-
const ext = f.name.split('.').pop()?.toUpperCase() ?? '';
|
|
31
|
-
const size = formatSize(f.size);
|
|
32
|
-
return { name: f.name, ext, size };
|
|
33
|
-
}
|
|
34
|
-
return { name: `${files.length} files selected`, ext: '', size: formatSize(files.reduce((a, f) => a + f.size, 0)) };
|
|
35
|
-
});
|
|
36
|
-
|
|
37
25
|
function formatSize(bytes: number): string {
|
|
38
26
|
if (bytes < 1024) return `${bytes} B`;
|
|
39
27
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { Icon, type IconProps } from '../icon';
|
|
3
3
|
|
|
4
|
-
let { class: klass = '', children = undefined, ...restProps }: IconProps = $props();
|
|
4
|
+
let { class: klass = '', preset = "input.icon", children = undefined, ...restProps }: IconProps = $props();
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<Icon
|
|
8
|
-
preset
|
|
8
|
+
{preset}
|
|
9
9
|
class={[
|
|
10
10
|
'border-border flex aspect-square h-full items-center justify-center bg-transparent text-sm leading-0',
|
|
11
11
|
'$preset',
|
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
]}
|
|
14
14
|
{...restProps}
|
|
15
15
|
>
|
|
16
|
-
{@render children?.()}
|
|
16
|
+
{@render children?.({})}
|
|
17
17
|
</Icon>
|