@immich/ui 0.49.2 → 0.49.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,16 +2,25 @@
2
2
  import Toast from './Toast.svelte';
3
3
  import { zIndex } from '../../constants.js';
4
4
  import { isCustomToast } from '../../services/toast-manager.svelte.js';
5
- import type { ToastId, ToastItem } from '../../types.js';
5
+ import type { ToastPanelProps } from '../../types.js';
6
+ import { cleanClass } from '../../utilities/internal.js';
7
+ import { twMerge } from 'tailwind-merge';
6
8
 
7
- type Props = {
8
- items: Array<ToastItem & ToastId>;
9
- };
9
+ const { items, class: className, ...props }: ToastPanelProps = $props();
10
10
 
11
- const { items }: Props = $props();
11
+ const isEmpty = $derived(items.length === 0);
12
12
  </script>
13
13
 
14
- <div class="absolute top-0 right-0 flex flex-col items-end justify-end gap-2 p-4 {zIndex.ToastPanel}">
14
+ <div
15
+ class={twMerge(
16
+ cleanClass(
17
+ isEmpty ? 'hidden' : 'absolute top-0 right-0 flex flex-col items-end justify-end gap-2 p-4',
18
+ zIndex.ToastPanel,
19
+ className,
20
+ ),
21
+ )}
22
+ {...props}
23
+ >
15
24
  {#each items as item (item.id)}
16
25
  {#if isCustomToast(item)}
17
26
  <item.component {...item.props} />
@@ -1,7 +1,4 @@
1
- import type { ToastId, ToastItem } from '../../types.js';
2
- type Props = {
3
- items: Array<ToastItem & ToastId>;
4
- };
5
- declare const ToastPanel: import("svelte").Component<Props, {}, "">;
1
+ import type { ToastPanelProps } from '../../types.js';
2
+ declare const ToastPanel: import("svelte").Component<ToastPanelProps, {}, "">;
6
3
  type ToastPanel = ReturnType<typeof ToastPanel>;
7
4
  export default ToastPanel;
@@ -1,16 +1,17 @@
1
- import type { ToastCustom, ToastItem, ToastOptions, ToastShow } from '../types.js';
1
+ import type { ToastCustom, ToastItem, ToastOptions, ToastPanelProps, ToastShow } from '../types.js';
2
2
  export declare const isCustomToast: (item: ToastItem) => item is ToastCustom;
3
3
  declare class ToastManager {
4
4
  #private;
5
5
  show(item: ToastShow, options?: ToastOptions): void;
6
6
  custom(item: ToastCustom, options?: ToastOptions): void;
7
+ setOptions(options: Omit<ToastPanelProps, 'items'>): void;
7
8
  open(item: ToastItem, options?: ToastOptions): void;
9
+ mount(): Promise<void>;
8
10
  unmount(): Promise<void>;
9
11
  success(item?: string | ToastShow, options?: ToastOptions): void;
10
12
  info(item?: string | ToastShow, options?: ToastOptions): void;
11
13
  warning(item?: string | ToastShow, options?: ToastOptions): void;
12
14
  danger(item?: string | ToastShow, options?: ToastOptions): void;
13
- mount(): Promise<void>;
14
15
  private remove;
15
16
  }
16
17
  export declare const toastManager: ToastManager;
@@ -13,6 +13,9 @@ class ToastManager {
13
13
  custom(item, options) {
14
14
  return this.open(item, options);
15
15
  }
16
+ setOptions(options) {
17
+ Object.assign(this.#props, options);
18
+ }
16
19
  open(item, options) {
17
20
  const { timeout = 3000, closable = true, id = generateId() } = options || {};
18
21
  const toast = item;
@@ -32,6 +35,14 @@ class ToastManager {
32
35
  setTimeout(() => this.remove(toast), timeout);
33
36
  }
34
37
  }
38
+ async mount() {
39
+ if (!this.#ref) {
40
+ this.#ref = await mount(ToastPanel, {
41
+ target: document.body,
42
+ props: this.#props,
43
+ });
44
+ }
45
+ }
35
46
  async unmount() {
36
47
  if (this.#ref) {
37
48
  await unmount(this.#ref);
@@ -49,14 +60,6 @@ class ToastManager {
49
60
  danger(item, options) {
50
61
  this.show({ title: t('toast_danger_title'), color: 'danger', ...expand(item) }, options);
51
62
  }
52
- async mount() {
53
- if (!this.#ref) {
54
- this.#ref = await mount(ToastPanel, {
55
- target: document.body,
56
- props: this.#props,
57
- });
58
- }
59
- }
60
63
  remove(target) {
61
64
  this.#props.items = this.#props.items.filter((item) => item.id !== target.id);
62
65
  }
package/dist/types.d.ts CHANGED
@@ -181,6 +181,9 @@ export type ToastContainerProps = ToastCommonProps & {
181
181
  shape?: Shape;
182
182
  size?: ContainerSize;
183
183
  } & Omit<HTMLAttributes<HTMLElement>, 'title' | 'color' | 'size'>;
184
+ export type ToastPanelProps = {
185
+ items: Array<ToastItem & ToastId>;
186
+ } & HTMLAttributes<HTMLDivElement>;
184
187
  export type ToastProps = ToastContentProps & ToastContainerProps;
185
188
  type Closable = {
186
189
  onClose: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immich/ui",
3
- "version": "0.49.2",
3
+ "version": "0.49.3",
4
4
  "license": "GNU Affero General Public License version 3",
5
5
  "repository": {
6
6
  "type": "git",