@immich/ui 0.58.2 → 0.58.4
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/dist/components/MultiSelect/MultiSelect.svelte +9 -5
- package/dist/components/Select/Select.svelte +10 -6
- package/dist/internal/Select.svelte +23 -16
- package/dist/internal/Select.svelte.d.ts +5 -4
- package/dist/services/toast-manager.svelte.d.ts +1 -0
- package/dist/services/toast-manager.svelte.js +3 -0
- package/dist/types.d.ts +8 -6
- package/package.json +1 -1
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends string">
|
|
2
2
|
import InternalSelect from '../../internal/Select.svelte';
|
|
3
|
-
import type { MultiSelectProps,
|
|
3
|
+
import type { MultiSelectProps, SelectOption } from '../../types.js';
|
|
4
4
|
|
|
5
|
-
let { onChange, values = $bindable([]), ...restProps }: MultiSelectProps<T> = $props();
|
|
5
|
+
let { onChange, onSelect, values = $bindable([]), ...restProps }: MultiSelectProps<T> = $props();
|
|
6
6
|
|
|
7
|
-
const handleChange = (
|
|
8
|
-
onChange?.(
|
|
7
|
+
const handleChange = (values: T[]) => {
|
|
8
|
+
onChange?.(values);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const handleSelect = (items: SelectOption<T>[]) => {
|
|
12
|
+
onSelect?.(items);
|
|
9
13
|
};
|
|
10
14
|
</script>
|
|
11
15
|
|
|
12
|
-
<InternalSelect multiple bind:values onChange={handleChange} {...restProps} />
|
|
16
|
+
<InternalSelect multiple bind:values onSelect={handleSelect} onChange={handleChange} {...restProps} />
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends string">
|
|
2
2
|
import InternalSelect from '../../internal/Select.svelte';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SelectOption, SelectProps } from '../../types.js';
|
|
4
4
|
|
|
5
|
-
let { onChange, value = $bindable(), ...restProps }: SelectProps<T> = $props();
|
|
5
|
+
let { onChange, onSelect, value = $bindable(), ...restProps }: SelectProps<T> = $props();
|
|
6
6
|
|
|
7
|
-
let values = $derived(value ? [
|
|
7
|
+
let values = $derived(value === null || value === undefined ? [] : [value]);
|
|
8
8
|
|
|
9
|
-
const handleChange = (
|
|
10
|
-
value =
|
|
9
|
+
const handleChange = (values: T[]) => {
|
|
10
|
+
value = values[0];
|
|
11
11
|
onChange?.(value);
|
|
12
12
|
};
|
|
13
|
+
|
|
14
|
+
const handleSelect = (items: SelectOption<T>[]) => {
|
|
15
|
+
onSelect?.(items[0]);
|
|
16
|
+
};
|
|
13
17
|
</script>
|
|
14
18
|
|
|
15
|
-
<InternalSelect bind:values onChange={handleChange} {...restProps} />
|
|
19
|
+
<InternalSelect bind:values onChange={handleChange} onSelect={handleSelect} {...restProps} />
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import IconButton from '../components/IconButton/IconButton.svelte';
|
|
5
5
|
import Input from '../components/Input/Input.svelte';
|
|
6
6
|
import { zIndex } from '../constants.js';
|
|
7
|
-
import type { SelectCommonProps,
|
|
7
|
+
import type { SelectCommonProps, SelectOption } from '../types.js';
|
|
8
8
|
import { cleanClass } from '../utilities/internal.js';
|
|
9
9
|
import { mdiArrowDown, mdiArrowUp, mdiCheck, mdiChevronDown } from '@mdi/js';
|
|
10
10
|
import { Select } from 'bits-ui';
|
|
@@ -12,27 +12,29 @@
|
|
|
12
12
|
|
|
13
13
|
type Props = {
|
|
14
14
|
multiple?: boolean;
|
|
15
|
-
values:
|
|
16
|
-
asLabel?: (items:
|
|
17
|
-
onChange?: (values:
|
|
15
|
+
values: T[];
|
|
16
|
+
asLabel?: (items: SelectOption<T>[]) => string;
|
|
17
|
+
onChange?: (values: T[]) => void;
|
|
18
|
+
onSelect?: (items: SelectOption<T>[]) => void;
|
|
18
19
|
} & SelectCommonProps<T>;
|
|
19
20
|
|
|
20
21
|
let {
|
|
21
|
-
|
|
22
|
+
options: optionsOrItems,
|
|
22
23
|
shape,
|
|
23
24
|
size: initialSize,
|
|
24
25
|
multiple = false,
|
|
25
26
|
values = $bindable([]),
|
|
26
27
|
onChange,
|
|
27
|
-
|
|
28
|
+
onSelect: onItemChange,
|
|
29
|
+
asLabel = (options: SelectOption<T>[]) => options.map(({ label }) => label).join(', '),
|
|
28
30
|
placeholder,
|
|
29
31
|
class: className,
|
|
30
32
|
}: Props = $props();
|
|
31
33
|
|
|
32
|
-
const asOptions = (items: string[] |
|
|
34
|
+
const asOptions = (items: string[] | SelectOption<T>[]) => {
|
|
33
35
|
return items.map((item) => {
|
|
34
36
|
if (typeof item === 'string') {
|
|
35
|
-
return { value: item, label: item } as
|
|
37
|
+
return { value: item, label: item } as SelectOption<T>;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
const label = item.label ?? item.value;
|
|
@@ -40,13 +42,16 @@
|
|
|
40
42
|
});
|
|
41
43
|
};
|
|
42
44
|
|
|
43
|
-
const options = $derived(asOptions(data));
|
|
44
|
-
|
|
45
45
|
const context = getFieldContext();
|
|
46
46
|
const { invalid, disabled, ...labelProps } = $derived(context());
|
|
47
47
|
const size = $derived(initialSize ?? labelProps.size ?? 'small');
|
|
48
|
+
const options = $derived(asOptions(optionsOrItems));
|
|
49
|
+
|
|
50
|
+
const findOption = (value: string) => options.find((option) => option.value === value);
|
|
51
|
+
const valuesToOptions = (values: T[]) =>
|
|
52
|
+
values.map(findOption).filter((item): item is SelectOption<T> => Boolean(item));
|
|
48
53
|
|
|
49
|
-
const selectedLabel = $derived(asLabel(values));
|
|
54
|
+
const selectedLabel = $derived(asLabel(valuesToOptions(values)));
|
|
50
55
|
|
|
51
56
|
const triggerStyles = tv({
|
|
52
57
|
base: 'w-full gap-1 rounded-lg py-0 text-start focus-visible:outline-none',
|
|
@@ -68,15 +73,17 @@
|
|
|
68
73
|
}
|
|
69
74
|
});
|
|
70
75
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
const onValueChange = (newValues: string[] | string) => {
|
|
77
|
+
values = (Array.isArray(newValues) ? newValues : [newValues]) as T[];
|
|
78
|
+
const items = values
|
|
79
|
+
.map((value) => findOption(value))
|
|
80
|
+
.filter((item): item is SelectOption<T> => item !== undefined);
|
|
75
81
|
|
|
76
82
|
onChange?.(values);
|
|
83
|
+
onItemChange?.(items);
|
|
77
84
|
};
|
|
78
85
|
|
|
79
|
-
let internalValue = $derived(multiple ? values
|
|
86
|
+
let internalValue = $derived(multiple ? values : (values[0] ?? ''));
|
|
80
87
|
</script>
|
|
81
88
|
|
|
82
89
|
<div class={cleanClass('flex flex-col gap-1', className)} bind:this={ref}>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { SelectCommonProps,
|
|
1
|
+
import type { SelectCommonProps, SelectOption } from '../types.js';
|
|
2
2
|
import { Select } from 'bits-ui';
|
|
3
3
|
declare function $$render<T extends string>(): {
|
|
4
4
|
props: {
|
|
5
5
|
multiple?: boolean;
|
|
6
|
-
values:
|
|
7
|
-
asLabel?: (items:
|
|
8
|
-
onChange?: (values:
|
|
6
|
+
values: T[];
|
|
7
|
+
asLabel?: (items: SelectOption<T>[]) => string;
|
|
8
|
+
onChange?: (values: T[]) => void;
|
|
9
|
+
onSelect?: (items: SelectOption<T>[]) => void;
|
|
9
10
|
} & SelectCommonProps<T>;
|
|
10
11
|
exports: {};
|
|
11
12
|
bindings: "values";
|
|
@@ -8,6 +8,7 @@ declare class ToastManager {
|
|
|
8
8
|
open(item: ToastItem, options?: ToastOptions): void;
|
|
9
9
|
mount(): Promise<void>;
|
|
10
10
|
unmount(): Promise<void>;
|
|
11
|
+
primary(item?: string | ToastShow, options?: ToastOptions): void;
|
|
11
12
|
success(item?: string | ToastShow, options?: ToastOptions): void;
|
|
12
13
|
info(item?: string | ToastShow, options?: ToastOptions): void;
|
|
13
14
|
warning(item?: string | ToastShow, options?: ToastOptions): void;
|
|
@@ -48,6 +48,9 @@ class ToastManager {
|
|
|
48
48
|
await unmount(this.#ref);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
primary(item, options) {
|
|
52
|
+
this.show({ title: t('toast_success_title'), color: 'primary', ...expand(item) }, options);
|
|
53
|
+
}
|
|
51
54
|
success(item, options) {
|
|
52
55
|
this.show({ title: t('toast_success_title'), color: 'success', ...expand(item) }, options);
|
|
53
56
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -152,25 +152,27 @@ export type TextareaProps = {
|
|
|
152
152
|
shape?: Shape;
|
|
153
153
|
grow?: boolean;
|
|
154
154
|
} & HTMLTextareaAttributes;
|
|
155
|
-
export type
|
|
155
|
+
export type SelectOption<T extends string = string> = {
|
|
156
156
|
label?: string;
|
|
157
157
|
value: T;
|
|
158
158
|
disabled?: boolean;
|
|
159
159
|
};
|
|
160
160
|
export type SelectCommonProps<T extends string> = {
|
|
161
|
-
|
|
161
|
+
options: string[] | SelectOption<T>[];
|
|
162
162
|
size?: Size;
|
|
163
163
|
shape?: Shape;
|
|
164
164
|
placeholder?: string;
|
|
165
165
|
class?: string;
|
|
166
166
|
};
|
|
167
167
|
export type SelectProps<T extends string> = SelectCommonProps<T> & {
|
|
168
|
-
value?:
|
|
169
|
-
onChange?: (value:
|
|
168
|
+
value?: T;
|
|
169
|
+
onChange?: (value: T) => void;
|
|
170
|
+
onSelect?: (options: SelectOption<T>) => void;
|
|
170
171
|
};
|
|
171
172
|
export type MultiSelectProps<T extends string> = SelectCommonProps<T> & {
|
|
172
|
-
values?:
|
|
173
|
-
onChange?: (values:
|
|
173
|
+
values?: T[];
|
|
174
|
+
onChange?: (values: T[]) => void;
|
|
175
|
+
onSelect?: (options: SelectOption<T>[]) => void;
|
|
174
176
|
};
|
|
175
177
|
export type ToastId = {
|
|
176
178
|
id: string;
|