@immich/ui 0.42.1 → 0.42.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.
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { commandPaletteManager, type CommandItem } from '../../services/command-palette-manager.svelte';
3
- import { onMount } from 'svelte';
3
+ import { untrack } from 'svelte';
4
4
 
5
5
  type Props = {
6
6
  commands?: CommandItem[];
@@ -9,5 +9,11 @@
9
9
 
10
10
  const { commands = [], global }: Props = $props();
11
11
 
12
- onMount(() => commandPaletteManager.addCommands(commands, { global }));
12
+ $effect(() => {
13
+ // prevent reactivity loop
14
+ const addCommands = (commands: CommandItem[], global?: boolean) =>
15
+ untrack(() => commandPaletteManager.addCommands(commands, { global }));
16
+
17
+ return addCommands(commands, global);
18
+ });
13
19
  </script>
@@ -14,7 +14,7 @@
14
14
  items,
15
15
  bottomItems,
16
16
  size = 'medium',
17
- anchor,
17
+ target,
18
18
  position = 'top-left',
19
19
  class: className,
20
20
  ...restProps
@@ -83,14 +83,14 @@
83
83
  }
84
84
  };
85
85
 
86
- const alignOffset = $derived(anchor.clientWidth / 2);
87
- const sideOffset = $derived(-anchor.clientHeight / 2);
86
+ const alignOffset = $derived(target.clientWidth / 2);
87
+ const sideOffset = $derived(-target.clientHeight / 2);
88
88
  const { side, align } = $derived(getAlignment(position));
89
89
  </script>
90
90
 
91
91
  <DropdownMenu.Root open={true} onOpenChange={() => onClose()}>
92
92
  <DropdownMenu.Portal>
93
- <DropdownMenu.Content forceMount customAnchor={anchor} {side} {align} {alignOffset} {sideOffset}>
93
+ <DropdownMenu.Content forceMount customAnchor={target} {side} {align} {alignOffset} {sideOffset}>
94
94
  {#snippet child({ wrapperProps, props, open })}
95
95
  {#if open}
96
96
  <div {...wrapperProps} class={zIndex.ContextMenu}>
@@ -2,11 +2,11 @@ import { type Shortcut } from '../actions/shortcut.js';
2
2
  import type { MaybeArray, TranslationProps } from '../types.js';
3
3
  export type CommandItem = {
4
4
  icon: string;
5
- iconClass: string;
5
+ iconClass?: string;
6
6
  type: string;
7
7
  title: string;
8
8
  description?: string;
9
- text: string;
9
+ text?: string;
10
10
  shortcuts?: MaybeArray<Shortcut>;
11
11
  shortcutOptions?: {
12
12
  ignoreInputFields?: boolean;
@@ -15,7 +15,7 @@ export type CommandItem = {
15
15
  } & ({
16
16
  href: string;
17
17
  } | {
18
- action: () => void | Promise<void>;
18
+ action: (command: CommandItem) => void;
19
19
  });
20
20
  export type CommandPaletteTranslations = TranslationProps<'search_placeholder' | 'search_no_results' | 'search_recently_used' | 'command_palette_prompt_default'>;
21
21
  export declare const asText: (...items: unknown[]) => string;
@@ -10,11 +10,11 @@ export const asText = (...items) => {
10
10
  .join('|')
11
11
  .toLowerCase();
12
12
  };
13
- const isMatch = (item, query) => {
13
+ const isMatch = ({ title, description, type, text = asText(title, description, type) }, query) => {
14
14
  if (!query) {
15
15
  return true;
16
16
  }
17
- return item.text.includes(query);
17
+ return text.includes(query);
18
18
  };
19
19
  class CommandPaletteManager {
20
20
  query = $state('');
@@ -73,14 +73,12 @@ class CommandPaletteManager {
73
73
  if ('href' in command) {
74
74
  if (!command.href.startsWith('/')) {
75
75
  window.open(command.href, '_blank');
76
+ return;
76
77
  }
77
- else {
78
- await goto(command.href);
79
- }
80
- }
81
- else {
82
- await command.action();
78
+ await goto(command.href);
79
+ return;
83
80
  }
81
+ command.action(command);
84
82
  }
85
83
  setTranslations(translations = {}) {
86
84
  this.#translations = translations;
@@ -1,6 +1,6 @@
1
1
  import type { ContextMenuBaseProps } from '../types.js';
2
2
  declare class MenuManager {
3
- show(event: MouseEvent, props: ContextMenuBaseProps): Promise<void>;
3
+ show(props: ContextMenuBaseProps): Promise<void>;
4
4
  }
5
5
  export declare const menuManager: MenuManager;
6
6
  export {};
@@ -1,10 +1,9 @@
1
1
  import ContextMenu from '../components/ContextMenu/ContextMenu.svelte';
2
2
  import { modalManager } from './modal-manager.svelte.js';
3
3
  class MenuManager {
4
- show(event, props) {
4
+ show(props) {
5
5
  return modalManager.show(ContextMenu, {
6
6
  ...props,
7
- anchor: event.currentTarget,
8
7
  });
9
8
  }
10
9
  }
package/dist/types.d.ts CHANGED
@@ -225,10 +225,10 @@ export type MenuProps = {
225
225
  } & HTMLAttributes<HTMLDivElement>;
226
226
  export type ContextMenuPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
227
227
  export type ContextMenuBaseProps = MenuProps & {
228
+ target: HTMLElement;
228
229
  position?: ContextMenuPosition;
229
230
  };
230
231
  export type ContextMenuProps = ContextMenuBaseProps & {
231
232
  onClose: () => void;
232
- anchor: HTMLElement;
233
233
  };
234
234
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immich/ui",
3
- "version": "0.42.1",
3
+ "version": "0.42.3",
4
4
  "license": "GNU Affero General Public License version 3",
5
5
  "repository": {
6
6
  "type": "git",