@immich/ui 0.58.2 → 0.58.3

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.
@@ -2,11 +2,15 @@
2
2
  import InternalSelect from '../../internal/Select.svelte';
3
3
  import type { MultiSelectProps, SelectItem } from '../../types.js';
4
4
 
5
- let { onChange, values = $bindable([]), ...restProps }: MultiSelectProps<T> = $props();
5
+ let { onChange, onItemChange, values = $bindable([]), ...restProps }: MultiSelectProps<T> = $props();
6
6
 
7
- const handleChange = (items: SelectItem<T>[]) => {
8
- onChange?.(items);
7
+ const handleChange = (values: T[]) => {
8
+ onChange?.(values);
9
+ };
10
+
11
+ const handleItemChange = (items: SelectItem<T>[]) => {
12
+ onItemChange?.(items);
9
13
  };
10
14
  </script>
11
15
 
12
- <InternalSelect multiple bind:values onChange={handleChange} {...restProps} />
16
+ <InternalSelect multiple bind:values onItemChange={handleItemChange} onChange={handleChange} {...restProps} />
@@ -2,14 +2,18 @@
2
2
  import InternalSelect from '../../internal/Select.svelte';
3
3
  import type { SelectItem, SelectProps } from '../../types.js';
4
4
 
5
- let { onChange, value = $bindable(), ...restProps }: SelectProps<T> = $props();
5
+ let { onChange, onItemChange, value = $bindable(), ...restProps }: SelectProps<T> = $props();
6
6
 
7
7
  let values = $derived(value ? [value] : []);
8
8
 
9
- const handleChange = (items: SelectItem<T>[]) => {
10
- value = items[0];
9
+ const handleChange = (values: T[]) => {
10
+ value = values[0];
11
11
  onChange?.(value);
12
12
  };
13
+
14
+ const handleItemChange = (items: SelectItem<T>[]) => {
15
+ onItemChange?.(items[0]);
16
+ };
13
17
  </script>
14
18
 
15
- <InternalSelect bind:values onChange={handleChange} {...restProps} />
19
+ <InternalSelect bind:values onChange={handleChange} onItemChange={handleItemChange} {...restProps} />
@@ -12,9 +12,10 @@
12
12
 
13
13
  type Props = {
14
14
  multiple?: boolean;
15
- values: SelectItem<T>[];
15
+ values: T[];
16
16
  asLabel?: (items: SelectItem<T>[]) => string;
17
- onChange?: (values: SelectItem<T>[]) => void;
17
+ onChange?: (values: T[]) => void;
18
+ onItemChange?: (items: SelectItem<T>[]) => void;
18
19
  } & SelectCommonProps<T>;
19
20
 
20
21
  let {
@@ -24,6 +25,7 @@
24
25
  multiple = false,
25
26
  values = $bindable([]),
26
27
  onChange,
28
+ onItemChange,
27
29
  asLabel = (options: SelectItem<T>[]) => options.map(({ label }) => label).join(', '),
28
30
  placeholder,
29
31
  class: className,
@@ -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(data));
48
49
 
49
- const selectedLabel = $derived(asLabel(values));
50
+ const findOption = (value: string) => options.find((option) => option.value === value);
51
+ const valuesToOptions = (values: T[]) =>
52
+ values.map(findOption).filter((item): item is SelectItem<T> => Boolean(item));
53
+
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,15 @@
68
73
  }
69
74
  });
70
75
 
71
- const findOption = (value: string) => options.find((option) => option.value === value);
72
-
73
- const onValueChange = (items: string[] | string) => {
74
- values = (Array.isArray(items) ? items : [items]).map(findOption).filter((item) => item !== undefined);
76
+ const onValueChange = (newValues: string[] | string) => {
77
+ values = (Array.isArray(newValues) ? newValues : [newValues]) as T[];
78
+ const items = values.map((value) => findOption(value)).filter((item): item is SelectItem<T> => item !== undefined);
75
79
 
76
80
  onChange?.(values);
81
+ onItemChange?.(items);
77
82
  };
78
83
 
79
- let internalValue = $derived(multiple ? values.map(({ value }) => value) : (values[0]?.value ?? ''));
84
+ let internalValue = $derived(multiple ? values : (values[0] ?? ''));
80
85
  </script>
81
86
 
82
87
  <div class={cleanClass('flex flex-col gap-1', className)} bind:this={ref}>
@@ -3,9 +3,10 @@ import { Select } from 'bits-ui';
3
3
  declare function $$render<T extends string>(): {
4
4
  props: {
5
5
  multiple?: boolean;
6
- values: SelectItem<T>[];
6
+ values: T[];
7
7
  asLabel?: (items: SelectItem<T>[]) => string;
8
- onChange?: (values: SelectItem<T>[]) => void;
8
+ onChange?: (values: T[]) => void;
9
+ onItemChange?: (items: SelectItem<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
@@ -165,12 +165,14 @@ export type SelectCommonProps<T extends string> = {
165
165
  class?: string;
166
166
  };
167
167
  export type SelectProps<T extends string> = SelectCommonProps<T> & {
168
- value?: SelectItem<T>;
169
- onChange?: (value: SelectItem<T>) => void;
168
+ value?: T;
169
+ onChange?: (value: T) => void;
170
+ onItemChange?: (item: SelectItem<T>) => void;
170
171
  };
171
172
  export type MultiSelectProps<T extends string> = SelectCommonProps<T> & {
172
- values?: SelectItem<T>[];
173
- onChange?: (values: SelectItem<T>[]) => void;
173
+ values?: T[];
174
+ onChange?: (values: T[]) => void;
175
+ onItemChange?: (items: SelectItem<T>[]) => void;
174
176
  };
175
177
  export type ToastId = {
176
178
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immich/ui",
3
- "version": "0.58.2",
3
+ "version": "0.58.3",
4
4
  "license": "GNU Affero General Public License version 3",
5
5
  "repository": {
6
6
  "type": "git",