@webamoki/web-svelte 0.7.4 → 1.0.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/README.md +83 -3
- package/dist/components/form/Button.svelte +24 -23
- package/dist/components/form/Button.svelte.d.ts +2 -2
- package/dist/components/form/Errors.svelte +13 -13
- package/dist/components/form/FieldWrapper.svelte +57 -55
- package/dist/components/form/FieldWrapper.svelte.d.ts +4 -4
- package/dist/components/form/Form.svelte +18 -14
- package/dist/components/form/Form.svelte.d.ts +31 -22
- package/dist/components/form/IconInputWrapper.svelte +30 -29
- package/dist/components/form/IconInputWrapper.svelte.d.ts +7 -7
- package/dist/components/form/fields/ChoiceField.svelte +45 -43
- package/dist/components/form/fields/ChoiceField.svelte.d.ts +28 -23
- package/dist/components/form/fields/ChoiceMultiField.svelte +44 -42
- package/dist/components/form/fields/ChoiceMultiField.svelte.d.ts +28 -23
- package/dist/components/form/fields/DateField.svelte +42 -40
- package/dist/components/form/fields/DateField.svelte.d.ts +29 -22
- package/dist/components/form/fields/HexColorField.svelte +21 -19
- package/dist/components/form/fields/HexColorField.svelte.d.ts +24 -19
- package/dist/components/form/fields/MessageField.svelte +39 -60
- package/dist/components/form/fields/MessageField.svelte.d.ts +33 -24
- package/dist/components/form/fields/NumberField.svelte +38 -36
- package/dist/components/form/fields/NumberField.svelte.d.ts +32 -23
- package/dist/components/form/fields/PasswordField.svelte +45 -39
- package/dist/components/form/fields/PasswordField.svelte.d.ts +28 -21
- package/dist/components/form/fields/SelectField.svelte +84 -79
- package/dist/components/form/fields/SelectField.svelte.d.ts +39 -26
- package/dist/components/form/fields/SelectMultiField.svelte +90 -85
- package/dist/components/form/fields/SelectMultiField.svelte.d.ts +38 -25
- package/dist/components/form/fields/TextField.svelte +31 -29
- package/dist/components/form/fields/TextField.svelte.d.ts +32 -23
- package/dist/components/form/fields/TextFieldNullable.svelte +49 -47
- package/dist/components/form/fields/TextFieldNullable.svelte.d.ts +32 -23
- package/dist/components/form/fields/TimeField.svelte +66 -64
- package/dist/components/form/fields/TimeField.svelte.d.ts +33 -24
- package/dist/components/form/fields/WeekdayChoiceField.svelte +37 -35
- package/dist/components/form/fields/WeekdayChoiceField.svelte.d.ts +27 -22
- package/dist/components/form/fields/WeekdayChoiceMultiField.svelte +37 -35
- package/dist/components/form/fields/WeekdayChoiceMultiField.svelte.d.ts +27 -22
- package/dist/components/showcase/CodeBlock.svelte +41 -41
- package/dist/components/showcase/Container.svelte +7 -7
- package/dist/components/showcase/Preview.svelte +4 -4
- package/dist/components/showcase/Sidebar.svelte +4 -4
- package/dist/components/showcase/SidebarLink.svelte +3 -3
- package/dist/components/ui/choice/Choice.svelte +25 -22
- package/dist/components/ui/choice/Choice.svelte.d.ts +7 -7
- package/dist/components/ui/choice/ChoiceInternal.svelte +73 -69
- package/dist/components/ui/choice/ChoiceInternal.svelte.d.ts +9 -9
- package/dist/components/ui/choice/ChoiceMulti.svelte +59 -53
- package/dist/components/ui/choice/ChoiceMulti.svelte.d.ts +7 -7
- package/dist/components/ui/choice/WeekdayChoice.svelte +22 -21
- package/dist/components/ui/choice/WeekdayChoice.svelte.d.ts +6 -6
- package/dist/components/ui/choice/WeekdayChoiceMulti.svelte +24 -22
- package/dist/components/ui/choice/WeekdayChoiceMulti.svelte.d.ts +6 -6
- package/dist/components/ui/context-menu/ContextMenu.svelte +51 -50
- package/dist/components/ui/context-menu/ContextMenu.svelte.d.ts +1 -1
- package/dist/components/ui/context-menu/ContextMenuContent.svelte +92 -91
- package/dist/components/ui/context-menu/ContextMenuItem.svelte +26 -25
- package/dist/components/ui/context-menu/ContextMenuItem.svelte.d.ts +1 -1
- package/dist/components/ui/context-menu/ContextMenuTrigger.svelte +16 -15
- package/dist/components/ui/context-menu/context-menu-state.svelte.d.ts +3 -3
- package/dist/components/ui/context-menu/context-menu-state.svelte.js +15 -15
- package/dist/components/ui/drag-drop/Draggable.svelte +73 -72
- package/dist/components/ui/drag-drop/Draggable.svelte.d.ts +2 -2
- package/dist/components/ui/drag-drop/Dropzone.svelte +56 -54
- package/dist/components/ui/drag-drop/Dropzone.svelte.d.ts +3 -3
- package/dist/components/ui/drag-drop/drag-manager.d.ts +2 -2
- package/dist/components/ui/drag-drop/drag-manager.js +9 -9
- package/dist/components/ui/index.d.ts +2 -2
- package/dist/components/ui/index.js +5 -5
- package/dist/components/ui/search/SearchBar.svelte +18 -18
- package/dist/components/ui/search/SearchBar.svelte.d.ts +2 -2
- package/dist/highlight.js +2 -2
- package/dist/server/form-handler.d.ts +12 -12
- package/dist/server/form-handler.js +17 -17
- package/dist/server/form-processor.d.ts +1 -1
- package/dist/server/form-processor.js +0 -1
- package/dist/shadcn/components/ui/button/button.svelte +72 -71
- package/dist/shadcn/components/ui/button/button.svelte.d.ts +23 -23
- package/dist/shadcn/components/ui/button/index.d.ts +1 -1
- package/dist/shadcn/components/ui/button/index.js +2 -2
- package/dist/shadcn/components/ui/input/index.d.ts +1 -1
- package/dist/shadcn/components/ui/input/index.js +2 -2
- package/dist/shadcn/components/ui/input/input.svelte +35 -32
- package/dist/shadcn/components/ui/input/input.svelte.d.ts +2 -2
- package/dist/shadcn/components/ui/select/index.d.ts +6 -6
- package/dist/shadcn/components/ui/select/index.js +7 -7
- package/dist/shadcn/components/ui/select/select-content.svelte +35 -34
- package/dist/shadcn/components/ui/select/select-content.svelte.d.ts +1 -1
- package/dist/shadcn/components/ui/select/select-group-heading.svelte +15 -14
- package/dist/shadcn/components/ui/select/select-group.svelte +2 -2
- package/dist/shadcn/components/ui/select/select-item.svelte +31 -31
- package/dist/shadcn/components/ui/select/select-label.svelte +14 -13
- package/dist/shadcn/components/ui/select/select-label.svelte.d.ts +1 -1
- package/dist/shadcn/components/ui/select/select-scroll-down-button.svelte +13 -13
- package/dist/shadcn/components/ui/select/select-scroll-up-button.svelte +13 -13
- package/dist/shadcn/components/ui/select/select-separator.svelte +13 -12
- package/dist/shadcn/components/ui/select/select-trigger.svelte +26 -26
- package/dist/shadcn/components/ui/select/select-trigger.svelte.d.ts +2 -2
- package/dist/shadcn/components/ui/separator/separator.svelte +14 -14
- package/dist/shadcn/components/ui/textarea/textarea.svelte +22 -21
- package/dist/shadcn/components/ui/textarea/textarea.svelte.d.ts +1 -1
- package/dist/shadcn/utils.d.ts +4 -4
- package/dist/utils/datetime/index.d.ts +68 -68
- package/dist/utils/datetime/index.js +124 -124
- package/dist/utils/email/README.md +60 -60
- package/dist/utils/email/aws-signer.d.ts +1 -1
- package/dist/utils/email/aws-signer.js +39 -39
- package/dist/utils/email/ses.d.ts +8 -10
- package/dist/utils/email/ses.js +15 -23
- package/dist/utils/form/index.d.ts +11 -11
- package/dist/utils/form/index.js +23 -24
- package/dist/utils/form/virtual-form.d.ts +5 -5
- package/dist/utils/form/virtual-form.js +58 -58
- package/dist/utils/search.d.ts +1 -1
- package/dist/utils/search.js +22 -22
- package/dist/utils/types/arktype.d.ts +2 -2
- package/dist/utils/types/arktype.js +3 -3
- package/dist/utils/types/db.d.ts +2 -1
- package/dist/utils/types/db.js +7 -7
- package/package.json +69 -54
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export interface ChoiceProps<
|
|
3
|
+
V,
|
|
4
|
+
I,
|
|
5
|
+
K extends number | string | symbol
|
|
6
|
+
> extends ChoiceInternalProps<V, I, K> {
|
|
7
|
+
onChange?: (value: V) => void;
|
|
8
|
+
value?: V;
|
|
9
|
+
}
|
|
7
10
|
</script>
|
|
8
11
|
|
|
9
|
-
<script
|
|
10
|
-
|
|
12
|
+
<script generics="V, I, K extends number | string | symbol" lang="ts">
|
|
13
|
+
import ChoiceInternal, { type ChoiceInternalProps } from './ChoiceInternal.svelte';
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let {
|
|
16
|
+
getValue,
|
|
17
|
+
onChange,
|
|
18
|
+
value = $bindable(undefined),
|
|
19
|
+
...props
|
|
20
|
+
}: ChoiceProps<V, I, K> = $props();
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
function handleItemClick(item: I) {
|
|
23
|
+
value = getValue(item);
|
|
24
|
+
// Trigger event
|
|
25
|
+
onChange?.(value);
|
|
26
|
+
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
function isActive(item: I) {
|
|
29
|
+
return value === getValue(item);
|
|
30
|
+
}
|
|
28
31
|
</script>
|
|
29
32
|
|
|
30
|
-
<ChoiceInternal {
|
|
33
|
+
<ChoiceInternal {getValue} {handleItemClick} {isActive} {...props} />
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export interface ChoiceProps<V, I, K extends
|
|
2
|
-
value?: V;
|
|
1
|
+
export interface ChoiceProps<V, I, K extends number | string | symbol> extends ChoiceInternalProps<V, I, K> {
|
|
3
2
|
onChange?: (value: V) => void;
|
|
3
|
+
value?: V;
|
|
4
4
|
}
|
|
5
5
|
import { type ChoiceInternalProps } from './ChoiceInternal.svelte';
|
|
6
|
-
declare function $$render<V, I, K extends
|
|
6
|
+
declare function $$render<V, I, K extends number | string | symbol>(): {
|
|
7
7
|
props: ChoiceProps<V, I, K>;
|
|
8
8
|
exports: {};
|
|
9
9
|
bindings: "value";
|
|
10
10
|
slots: {};
|
|
11
11
|
events: {};
|
|
12
12
|
};
|
|
13
|
-
declare class __sveltets_Render<V, I, K extends
|
|
13
|
+
declare class __sveltets_Render<V, I, K extends number | string | symbol> {
|
|
14
14
|
props(): ReturnType<typeof $$render<V, I, K>>['props'];
|
|
15
15
|
events(): ReturnType<typeof $$render<V, I, K>>['events'];
|
|
16
16
|
slots(): ReturnType<typeof $$render<V, I, K>>['slots'];
|
|
@@ -18,12 +18,12 @@ declare class __sveltets_Render<V, I, K extends string | number | symbol> {
|
|
|
18
18
|
exports(): {};
|
|
19
19
|
}
|
|
20
20
|
interface $$IsomorphicComponent {
|
|
21
|
-
new <V, I, K extends
|
|
21
|
+
new <V, I, K extends number | string | symbol>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V, I, K>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V, I, K>['props']>, ReturnType<__sveltets_Render<V, I, K>['events']>, ReturnType<__sveltets_Render<V, I, K>['slots']>> & {
|
|
22
22
|
$$bindings?: ReturnType<__sveltets_Render<V, I, K>['bindings']>;
|
|
23
23
|
} & ReturnType<__sveltets_Render<V, I, K>['exports']>;
|
|
24
|
-
<V, I, K extends
|
|
24
|
+
<V, I, K extends number | string | symbol>(internal: unknown, props: ReturnType<__sveltets_Render<V, I, K>['props']> & {}): ReturnType<__sveltets_Render<V, I, K>['exports']>;
|
|
25
25
|
z_$$bindings?: ReturnType<__sveltets_Render<any, any, any>['bindings']>;
|
|
26
26
|
}
|
|
27
27
|
declare const Choice: $$IsomorphicComponent;
|
|
28
|
-
type Choice<V, I, K extends
|
|
28
|
+
type Choice<V, I, K extends number | string | symbol> = InstanceType<typeof Choice<V, I, K>>;
|
|
29
29
|
export default Choice;
|
|
@@ -1,79 +1,83 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
export interface ChoiceInternalProps<
|
|
3
|
+
V,
|
|
4
|
+
I,
|
|
5
|
+
K extends number | string | symbol
|
|
6
|
+
> extends Partial<FormAttrs> {
|
|
7
|
+
buttonContent?: Snippet<[label: string, item: I]>;
|
|
8
|
+
class?: string;
|
|
9
|
+
getKey: (item: I) => K;
|
|
10
|
+
getLabel: (item: I) => string;
|
|
11
|
+
getValue: (item: I) => V;
|
|
12
|
+
items: readonly I[];
|
|
13
|
+
vertical?: boolean;
|
|
14
|
+
}
|
|
12
15
|
</script>
|
|
13
16
|
|
|
14
|
-
<script
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import type { Snippet } from 'svelte';
|
|
17
|
+
<script generics="V, I, K extends number | string | symbol" lang="ts">
|
|
18
|
+
import type { FormAttrs } from '../../form/FieldWrapper.svelte';
|
|
19
|
+
import type { Snippet } from 'svelte';
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
handleItemClick: (item: I) => void;
|
|
21
|
-
isActive: (item: I) => boolean;
|
|
22
|
-
}
|
|
21
|
+
import { cn } from '../../../shadcn/utils.js';
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
interface Props extends ChoiceInternalProps<V, I, K> {
|
|
24
|
+
handleItemClick: (item: I) => void;
|
|
25
|
+
isActive: (item: I) => boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
'aria-invalid': ariaInvalid,
|
|
30
|
+
buttonContent,
|
|
31
|
+
class: className,
|
|
32
|
+
disabled,
|
|
33
|
+
getKey,
|
|
34
|
+
getLabel,
|
|
35
|
+
handleItemClick,
|
|
36
|
+
isActive,
|
|
37
|
+
items = [],
|
|
38
|
+
readonly,
|
|
39
|
+
vertical,
|
|
40
|
+
...control
|
|
41
|
+
}: Props = $props();
|
|
38
42
|
</script>
|
|
39
43
|
|
|
40
44
|
<div
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
{...control}
|
|
46
|
+
class={cn(
|
|
47
|
+
'w-fit rounded-lg border border-border bg-muted p-1 text-sm leading-[0.01em] font-semibold shadow-inner',
|
|
48
|
+
'grid gap-1',
|
|
49
|
+
vertical ? 'grid-flow-row auto-rows-fr' : 'auto-cols-fr grid-flow-col',
|
|
50
|
+
disabled || readonly ? 'pointer-events-none' : 'cursor-pointer',
|
|
51
|
+
disabled && 'opacity-50',
|
|
52
|
+
ariaInvalid && 'border-destructive',
|
|
53
|
+
className
|
|
54
|
+
)}
|
|
51
55
|
>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
56
|
+
{#each items as item (getKey(item))}
|
|
57
|
+
{#if buttonContent}
|
|
58
|
+
<button
|
|
59
|
+
class="cursor-pointer rounded-lg bg-transparent text-muted-foreground hover:text-foreground hover:outline-2 focus-visible:outline-ring data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm"
|
|
60
|
+
data-state={isActive(item) ? 'active' : 'inactive'}
|
|
61
|
+
onclick={() => {
|
|
62
|
+
if (disabled || readonly) return;
|
|
63
|
+
handleItemClick(item);
|
|
64
|
+
}}
|
|
65
|
+
type="button"
|
|
66
|
+
>
|
|
67
|
+
{@render buttonContent(getLabel(item), item)}
|
|
68
|
+
</button>
|
|
69
|
+
{:else}
|
|
70
|
+
<button
|
|
71
|
+
class="h-8 cursor-pointer rounded-lg bg-transparent p-2 text-muted-foreground hover:text-foreground hover:outline-2 focus-visible:outline-ring data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm"
|
|
72
|
+
data-state={isActive(item) ? 'active' : 'inactive'}
|
|
73
|
+
onclick={() => {
|
|
74
|
+
if (disabled || readonly) return;
|
|
75
|
+
handleItemClick(item);
|
|
76
|
+
}}
|
|
77
|
+
type="button"
|
|
78
|
+
>
|
|
79
|
+
{getLabel(item)}
|
|
80
|
+
</button>
|
|
81
|
+
{/if}
|
|
82
|
+
{/each}
|
|
79
83
|
</div>
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export interface ChoiceInternalProps<V, I, K extends
|
|
2
|
-
|
|
1
|
+
export interface ChoiceInternalProps<V, I, K extends number | string | symbol> extends Partial<FormAttrs> {
|
|
2
|
+
buttonContent?: Snippet<[label: string, item: I]>;
|
|
3
|
+
class?: string;
|
|
3
4
|
getKey: (item: I) => K;
|
|
4
5
|
getLabel: (item: I) => string;
|
|
5
6
|
getValue: (item: I) => V;
|
|
7
|
+
items: readonly I[];
|
|
6
8
|
vertical?: boolean;
|
|
7
|
-
buttonContent?: Snippet<[label: string, item: I]>;
|
|
8
|
-
class?: string;
|
|
9
9
|
}
|
|
10
10
|
import type { FormAttrs } from '../../form/FieldWrapper.svelte';
|
|
11
11
|
import type { Snippet } from 'svelte';
|
|
12
|
-
declare function $$render<V, I, K extends
|
|
12
|
+
declare function $$render<V, I, K extends number | string | symbol>(): {
|
|
13
13
|
props: ChoiceInternalProps<V, I, K> & {
|
|
14
14
|
handleItemClick: (item: I) => void;
|
|
15
15
|
isActive: (item: I) => boolean;
|
|
@@ -19,7 +19,7 @@ declare function $$render<V, I, K extends string | number | symbol>(): {
|
|
|
19
19
|
slots: {};
|
|
20
20
|
events: {};
|
|
21
21
|
};
|
|
22
|
-
declare class __sveltets_Render<V, I, K extends
|
|
22
|
+
declare class __sveltets_Render<V, I, K extends number | string | symbol> {
|
|
23
23
|
props(): ReturnType<typeof $$render<V, I, K>>['props'];
|
|
24
24
|
events(): ReturnType<typeof $$render<V, I, K>>['events'];
|
|
25
25
|
slots(): ReturnType<typeof $$render<V, I, K>>['slots'];
|
|
@@ -27,12 +27,12 @@ declare class __sveltets_Render<V, I, K extends string | number | symbol> {
|
|
|
27
27
|
exports(): {};
|
|
28
28
|
}
|
|
29
29
|
interface $$IsomorphicComponent {
|
|
30
|
-
new <V, I, K extends
|
|
30
|
+
new <V, I, K extends number | string | symbol>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V, I, K>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V, I, K>['props']>, ReturnType<__sveltets_Render<V, I, K>['events']>, ReturnType<__sveltets_Render<V, I, K>['slots']>> & {
|
|
31
31
|
$$bindings?: ReturnType<__sveltets_Render<V, I, K>['bindings']>;
|
|
32
32
|
} & ReturnType<__sveltets_Render<V, I, K>['exports']>;
|
|
33
|
-
<V, I, K extends
|
|
33
|
+
<V, I, K extends number | string | symbol>(internal: unknown, props: ReturnType<__sveltets_Render<V, I, K>['props']> & {}): ReturnType<__sveltets_Render<V, I, K>['exports']>;
|
|
34
34
|
z_$$bindings?: ReturnType<__sveltets_Render<any, any, any>['bindings']>;
|
|
35
35
|
}
|
|
36
36
|
declare const ChoiceInternal: $$IsomorphicComponent;
|
|
37
|
-
type ChoiceInternal<V, I, K extends
|
|
37
|
+
type ChoiceInternal<V, I, K extends number | string | symbol> = InstanceType<typeof ChoiceInternal<V, I, K>>;
|
|
38
38
|
export default ChoiceInternal;
|
|
@@ -1,58 +1,64 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export interface ChoiceMultiProps<
|
|
3
|
+
V,
|
|
4
|
+
I,
|
|
5
|
+
K extends number | string | symbol
|
|
6
|
+
> extends ChoiceInternalProps<V, I, K> {
|
|
7
|
+
onAdd?: (value: V) => void;
|
|
8
|
+
onRemove?: (value: V) => void;
|
|
9
|
+
value: V[];
|
|
10
|
+
}
|
|
8
11
|
</script>
|
|
9
12
|
|
|
10
|
-
<script
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
13
|
+
<script generics="V,I, K extends number | string | symbol" lang="ts">
|
|
14
|
+
import * as sorted from 'sorted-array-functions';
|
|
15
|
+
|
|
16
|
+
import ChoiceInternal, { type ChoiceInternalProps } from './ChoiceInternal.svelte';
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
getValue,
|
|
20
|
+
items,
|
|
21
|
+
onAdd,
|
|
22
|
+
onRemove,
|
|
23
|
+
value = $bindable([]),
|
|
24
|
+
...props
|
|
25
|
+
}: ChoiceMultiProps<V, I, K> = $props();
|
|
26
|
+
|
|
27
|
+
// Items property shouldn't be updated, ignore warning
|
|
28
|
+
// svelte-ignore state_referenced_locally
|
|
29
|
+
const valueIndex = new Map<V, number>(
|
|
30
|
+
items.map((item, index) => [getValue(item), index] as const)
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
function compareItems(a: V, b: V) {
|
|
34
|
+
const index1 = valueIndex.get(a);
|
|
35
|
+
if (index1 === undefined) return 1;
|
|
36
|
+
const index2 = valueIndex.get(b);
|
|
37
|
+
if (index2 === undefined) return -1;
|
|
38
|
+
|
|
39
|
+
return Math.sign(index1 - index2) as -1 | 0 | 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function contains(item: I) {
|
|
43
|
+
// Sorted contains function
|
|
44
|
+
return sorted.has(value, getValue(item), compareItems);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function handleItemClick(item: I) {
|
|
48
|
+
// Toggle add or remove
|
|
49
|
+
if (!contains(item)) {
|
|
50
|
+
sorted.add(value, getValue(item), compareItems);
|
|
51
|
+
// Trigger event
|
|
52
|
+
onAdd?.(getValue(item));
|
|
53
|
+
} else {
|
|
54
|
+
sorted.remove(value, getValue(item), compareItems);
|
|
55
|
+
// Trigger event
|
|
56
|
+
onRemove?.(getValue(item));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Re-assign value to trigger state update
|
|
60
|
+
value = value;
|
|
61
|
+
}
|
|
56
62
|
</script>
|
|
57
63
|
|
|
58
|
-
<ChoiceInternal {
|
|
64
|
+
<ChoiceInternal {getValue} {handleItemClick} isActive={contains} {items} {...props} />
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export interface ChoiceMultiProps<V, I, K extends
|
|
2
|
-
value: V[];
|
|
1
|
+
export interface ChoiceMultiProps<V, I, K extends number | string | symbol> extends ChoiceInternalProps<V, I, K> {
|
|
3
2
|
onAdd?: (value: V) => void;
|
|
4
3
|
onRemove?: (value: V) => void;
|
|
4
|
+
value: V[];
|
|
5
5
|
}
|
|
6
6
|
import { type ChoiceInternalProps } from './ChoiceInternal.svelte';
|
|
7
|
-
declare function $$render<V, I, K extends
|
|
7
|
+
declare function $$render<V, I, K extends number | string | symbol>(): {
|
|
8
8
|
props: ChoiceMultiProps<V, I, K>;
|
|
9
9
|
exports: {};
|
|
10
10
|
bindings: "value";
|
|
11
11
|
slots: {};
|
|
12
12
|
events: {};
|
|
13
13
|
};
|
|
14
|
-
declare class __sveltets_Render<V, I, K extends
|
|
14
|
+
declare class __sveltets_Render<V, I, K extends number | string | symbol> {
|
|
15
15
|
props(): ReturnType<typeof $$render<V, I, K>>['props'];
|
|
16
16
|
events(): ReturnType<typeof $$render<V, I, K>>['events'];
|
|
17
17
|
slots(): ReturnType<typeof $$render<V, I, K>>['slots'];
|
|
@@ -19,12 +19,12 @@ declare class __sveltets_Render<V, I, K extends string | number | symbol> {
|
|
|
19
19
|
exports(): {};
|
|
20
20
|
}
|
|
21
21
|
interface $$IsomorphicComponent {
|
|
22
|
-
new <V, I, K extends
|
|
22
|
+
new <V, I, K extends number | string | symbol>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V, I, K>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V, I, K>['props']>, ReturnType<__sveltets_Render<V, I, K>['events']>, ReturnType<__sveltets_Render<V, I, K>['slots']>> & {
|
|
23
23
|
$$bindings?: ReturnType<__sveltets_Render<V, I, K>['bindings']>;
|
|
24
24
|
} & ReturnType<__sveltets_Render<V, I, K>['exports']>;
|
|
25
|
-
<V, I, K extends
|
|
25
|
+
<V, I, K extends number | string | symbol>(internal: unknown, props: ReturnType<__sveltets_Render<V, I, K>['props']> & {}): ReturnType<__sveltets_Render<V, I, K>['exports']>;
|
|
26
26
|
z_$$bindings?: ReturnType<__sveltets_Render<any, any, any>['bindings']>;
|
|
27
27
|
}
|
|
28
28
|
declare const ChoiceMulti: $$IsomorphicComponent;
|
|
29
|
-
type ChoiceMulti<V, I, K extends
|
|
29
|
+
type ChoiceMulti<V, I, K extends number | string | symbol> = InstanceType<typeof ChoiceMulti<V, I, K>>;
|
|
30
30
|
export default ChoiceMulti;
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
export interface WeekdayChoiceProps {
|
|
3
|
+
class?: string;
|
|
4
|
+
disabled?: boolean | null;
|
|
5
|
+
letterLabels?: boolean;
|
|
6
|
+
longLabels?: boolean;
|
|
7
|
+
onChange?: (value: Day) => void;
|
|
8
|
+
readonly?: boolean | null;
|
|
9
|
+
value?: Day;
|
|
10
|
+
vertical?: boolean;
|
|
11
|
+
}
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
14
|
<script lang="ts">
|
|
15
|
-
|
|
16
|
-
import { identity } from 'ramda';
|
|
15
|
+
import type { Day } from '../../../utils/types/arktype.js';
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
import { Days, formatDayLetter, formatDayShort } from '../../../utils/datetime/index.js';
|
|
18
|
+
import { identity } from 'ramda';
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
import Choice from './Choice.svelte';
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
let { value = $bindable(undefined), ...props }: WeekdayChoiceProps = $props();
|
|
23
|
+
|
|
24
|
+
let getLabel = $derived.by(() => {
|
|
25
|
+
if (props.longLabels) return identity;
|
|
26
|
+
if (props.letterLabels) return formatDayLetter;
|
|
27
|
+
return formatDayShort;
|
|
28
|
+
});
|
|
28
29
|
</script>
|
|
29
30
|
|
|
30
|
-
<Choice
|
|
31
|
+
<Choice getKey={identity} {getLabel} getValue={identity} items={Days} bind:value {...props} />
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export interface WeekdayChoiceProps {
|
|
2
|
-
|
|
3
|
-
onChange?: (value: Day) => void;
|
|
4
|
-
vertical?: boolean;
|
|
5
|
-
longLabels?: boolean;
|
|
6
|
-
letterLabels?: boolean;
|
|
2
|
+
class?: string;
|
|
7
3
|
disabled?: boolean | null;
|
|
4
|
+
letterLabels?: boolean;
|
|
5
|
+
longLabels?: boolean;
|
|
6
|
+
onChange?: (value: Day) => void;
|
|
8
7
|
readonly?: boolean | null;
|
|
9
|
-
|
|
8
|
+
value?: Day;
|
|
9
|
+
vertical?: boolean;
|
|
10
10
|
}
|
|
11
11
|
import type { Day } from '../../../utils/types/arktype.js';
|
|
12
12
|
declare const WeekdayChoice: import("svelte").Component<WeekdayChoiceProps, {}, "value">;
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
|
|
2
|
+
import { identity } from 'ramda';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
export interface WeekdayChoiceMultiProps {
|
|
5
|
+
class?: string;
|
|
6
|
+
disabled?: boolean | null;
|
|
7
|
+
letterLabels?: boolean;
|
|
8
|
+
longLabels?: boolean;
|
|
9
|
+
onAdd?: (value: Day) => void;
|
|
10
|
+
onRemove?: (value: Day) => void;
|
|
11
|
+
readonly?: boolean | null;
|
|
12
|
+
value: Day[];
|
|
13
|
+
vertical?: boolean;
|
|
14
|
+
}
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<script lang="ts">
|
|
18
|
-
|
|
19
|
-
import { Days, formatDayLetter, formatDayShort } from '../../../utils/datetime/index.js';
|
|
20
|
-
import type { Day } from '../../../utils/types/arktype.js';
|
|
18
|
+
import type { Day } from '../../../utils/types/arktype.js';
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
import { Days, formatDayLetter, formatDayShort } from '../../../utils/datetime/index.js';
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
import ChoiceMulti from './ChoiceMulti.svelte';
|
|
23
|
+
|
|
24
|
+
let { value = $bindable([]), ...props }: WeekdayChoiceMultiProps = $props();
|
|
25
|
+
|
|
26
|
+
let getLabel = $derived.by(() => {
|
|
27
|
+
if (props.longLabels) return identity;
|
|
28
|
+
if (props.letterLabels) return formatDayLetter;
|
|
29
|
+
return formatDayShort;
|
|
30
|
+
});
|
|
29
31
|
</script>
|
|
30
32
|
|
|
31
|
-
<ChoiceMulti
|
|
33
|
+
<ChoiceMulti getKey={identity} {getLabel} getValue={identity} items={Days} bind:value {...props} />
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export interface WeekdayChoiceMultiProps {
|
|
2
|
-
|
|
2
|
+
class?: string;
|
|
3
|
+
disabled?: boolean | null;
|
|
4
|
+
letterLabels?: boolean;
|
|
5
|
+
longLabels?: boolean;
|
|
3
6
|
onAdd?: (value: Day) => void;
|
|
4
7
|
onRemove?: (value: Day) => void;
|
|
5
|
-
vertical?: boolean;
|
|
6
|
-
longLabels?: boolean;
|
|
7
|
-
letterLabels?: boolean;
|
|
8
|
-
disabled?: boolean | null;
|
|
9
8
|
readonly?: boolean | null;
|
|
10
|
-
|
|
9
|
+
value: Day[];
|
|
10
|
+
vertical?: boolean;
|
|
11
11
|
}
|
|
12
12
|
import type { Day } from '../../../utils/types/arktype.js';
|
|
13
13
|
declare const WeekdayChoiceMulti: import("svelte").Component<WeekdayChoiceMultiProps, {}, "value">;
|