@immich/ui 0.49.1 → 0.49.2
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/CommandPalette/CommandPaletteContext.svelte +6 -7
- package/dist/components/CommandPalette/CommandPaletteContext.svelte.d.ts +2 -3
- package/dist/components/CommandPalette/CommandPaletteItem.svelte +2 -2
- package/dist/components/CommandPalette/CommandPaletteItem.svelte.d.ts +2 -2
- package/dist/services/command-palette-manager.svelte.d.ts +14 -31
- package/dist/services/command-palette-manager.svelte.js +11 -27
- package/dist/site/constants.d.ts +2 -2
- package/dist/site/constants.js +3 -2
- package/dist/types.d.ts +11 -0
- package/package.json +1 -1
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { commandPaletteManager
|
|
2
|
+
import { commandPaletteManager } from '../../services/command-palette-manager.svelte';
|
|
3
|
+
import type { ActionItem } from '../../types.js';
|
|
3
4
|
import { untrack } from 'svelte';
|
|
4
5
|
|
|
5
6
|
type Props = {
|
|
6
|
-
commands?:
|
|
7
|
-
global?: boolean;
|
|
7
|
+
commands?: ActionItem[];
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
const { commands = []
|
|
10
|
+
const { commands = [] }: Props = $props();
|
|
11
11
|
|
|
12
12
|
$effect(() => {
|
|
13
13
|
// prevent reactivity loop
|
|
14
|
-
const addCommands = (commands:
|
|
15
|
-
untrack(() => commandPaletteManager.addCommands(commands, { global }));
|
|
14
|
+
const addCommands = (commands: ActionItem[]) => untrack(() => commandPaletteManager.addCommands(commands));
|
|
16
15
|
|
|
17
|
-
return addCommands(commands
|
|
16
|
+
return addCommands(commands);
|
|
18
17
|
});
|
|
19
18
|
</script>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ActionItem } from '../../types.js';
|
|
2
2
|
type Props = {
|
|
3
|
-
commands?:
|
|
4
|
-
global?: boolean;
|
|
3
|
+
commands?: ActionItem[];
|
|
5
4
|
};
|
|
6
5
|
declare const CommandPaletteContext: import("svelte").Component<Props, {}, "">;
|
|
7
6
|
type CommandPaletteContext = ReturnType<typeof CommandPaletteContext>;
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
import IconButton from '../IconButton/IconButton.svelte';
|
|
7
7
|
import Kbd from '../Kbd/Kbd.svelte';
|
|
8
8
|
import Text from '../Text/Text.svelte';
|
|
9
|
-
import type {
|
|
9
|
+
import type { ActionItem } from '../../types.js';
|
|
10
10
|
import { cleanClass } from '../../utilities/internal.js';
|
|
11
11
|
import { mdiClose } from '@mdi/js';
|
|
12
12
|
|
|
13
13
|
type Props = {
|
|
14
|
-
item:
|
|
14
|
+
item: ActionItem;
|
|
15
15
|
selected: boolean;
|
|
16
16
|
onSelect: () => void;
|
|
17
17
|
onRemove?: () => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ActionItem } from '../../types.js';
|
|
2
2
|
type Props = {
|
|
3
|
-
item:
|
|
3
|
+
item: ActionItem;
|
|
4
4
|
selected: boolean;
|
|
5
5
|
onSelect: () => void;
|
|
6
6
|
onRemove?: () => void;
|
|
@@ -1,36 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { IfLike, MaybeArray, TranslationProps } from '../types.js';
|
|
3
|
-
export type CommandItem = {
|
|
4
|
-
icon: string;
|
|
5
|
-
iconClass?: string;
|
|
6
|
-
type: string;
|
|
7
|
-
title: string;
|
|
8
|
-
description?: string;
|
|
9
|
-
text?: string;
|
|
10
|
-
shortcuts?: MaybeArray<Shortcut>;
|
|
11
|
-
shortcutOptions?: {
|
|
12
|
-
ignoreInputFields?: boolean;
|
|
13
|
-
preventDefault?: boolean;
|
|
14
|
-
};
|
|
15
|
-
id?: string;
|
|
16
|
-
} & IfLike & ({
|
|
17
|
-
href: string;
|
|
18
|
-
} | {
|
|
19
|
-
action: (command: CommandItemResponse) => void;
|
|
20
|
-
});
|
|
21
|
-
export type CommandItemResponse = CommandItem & {
|
|
22
|
-
id: string;
|
|
23
|
-
isGlobal: boolean;
|
|
24
|
-
};
|
|
1
|
+
import type { ActionItem, MaybeArray, TranslationProps } from '../types.js';
|
|
25
2
|
export type CommandPaletteTranslations = TranslationProps<'search_placeholder' | 'search_no_results' | 'search_recently_used' | 'command_palette_prompt_default' | 'command_palette_to_select' | 'command_palette_to_close' | 'command_palette_to_navigate' | 'command_palette_to_show_all' | 'global'>;
|
|
26
3
|
export declare const asText: (...items: unknown[]) => string;
|
|
27
4
|
declare class CommandPaletteManager {
|
|
28
5
|
#private;
|
|
29
6
|
selectedIndex: number;
|
|
30
|
-
items:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
items: (ActionItem & {
|
|
8
|
+
id: string;
|
|
9
|
+
})[];
|
|
10
|
+
filteredItems: (ActionItem & {
|
|
11
|
+
id: string;
|
|
12
|
+
})[];
|
|
13
|
+
recentItems: (ActionItem & {
|
|
14
|
+
id: string;
|
|
15
|
+
})[];
|
|
16
|
+
results: (ActionItem & {
|
|
17
|
+
id: string;
|
|
18
|
+
})[];
|
|
34
19
|
get isEnabled(): boolean;
|
|
35
20
|
enable(): void;
|
|
36
21
|
get query(): string;
|
|
@@ -47,9 +32,7 @@ declare class CommandPaletteManager {
|
|
|
47
32
|
up(): void;
|
|
48
33
|
down(): void;
|
|
49
34
|
reset(): void;
|
|
50
|
-
addCommands(itemOrItems: MaybeArray<
|
|
51
|
-
global: boolean;
|
|
52
|
-
}): () => void;
|
|
35
|
+
addCommands(itemOrItems: MaybeArray<ActionItem>): () => void;
|
|
53
36
|
removeCommands(itemOrItems: MaybeArray<{
|
|
54
37
|
id: string;
|
|
55
38
|
}>): void;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { goto } from '$app/navigation';
|
|
2
1
|
import { matchesShortcut, shortcuts, shouldIgnoreEvent } from '../actions/shortcut.js';
|
|
3
2
|
import CommandPaletteModal from '../internal/CommandPaletteModal.svelte';
|
|
4
3
|
import { generateId, isEnabled } from '../utilities/internal.js';
|
|
@@ -10,11 +9,11 @@ export const asText = (...items) => {
|
|
|
10
9
|
.join('|')
|
|
11
10
|
.toLowerCase();
|
|
12
11
|
};
|
|
13
|
-
const isMatch = ({ title, description, type,
|
|
12
|
+
const isMatch = ({ title, description, type, searchText = asText(title, description, type) }, query) => {
|
|
14
13
|
if (!query) {
|
|
15
14
|
return true;
|
|
16
15
|
}
|
|
17
|
-
return
|
|
16
|
+
return searchText.includes(query);
|
|
18
17
|
};
|
|
19
18
|
class CommandPaletteManager {
|
|
20
19
|
#query = $state('');
|
|
@@ -84,18 +83,7 @@ class CommandPaletteManager {
|
|
|
84
83
|
if (preventDefault) {
|
|
85
84
|
event.preventDefault();
|
|
86
85
|
}
|
|
87
|
-
await
|
|
88
|
-
}
|
|
89
|
-
async #executeCommand(command) {
|
|
90
|
-
if ('href' in command) {
|
|
91
|
-
if (!command.href.startsWith('/')) {
|
|
92
|
-
window.open(command.href, '_blank');
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
await goto(command.href);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
command.action(command);
|
|
86
|
+
await command.onAction(command);
|
|
99
87
|
}
|
|
100
88
|
setTranslations(translations = {}) {
|
|
101
89
|
this.#translations = translations;
|
|
@@ -143,8 +131,7 @@ class CommandPaletteManager {
|
|
|
143
131
|
if (!selected) {
|
|
144
132
|
return;
|
|
145
133
|
}
|
|
146
|
-
|
|
147
|
-
if (globalItem) {
|
|
134
|
+
if (selected.isGlobal) {
|
|
148
135
|
this.#globalLayer.recentItems = this.#globalLayer.recentItems.filter(({ id }) => id !== selected.id);
|
|
149
136
|
this.#globalLayer.recentItems.unshift(selected);
|
|
150
137
|
}
|
|
@@ -152,7 +139,7 @@ class CommandPaletteManager {
|
|
|
152
139
|
this.#layers.at(-1).recentItems = this.#layers.at(-1).recentItems.filter(({ id }) => id !== selected.id);
|
|
153
140
|
this.#layers.at(-1)?.recentItems.unshift(selected);
|
|
154
141
|
}
|
|
155
|
-
await
|
|
142
|
+
await selected.onAction(selected);
|
|
156
143
|
await this.close();
|
|
157
144
|
}
|
|
158
145
|
remove(index) {
|
|
@@ -178,19 +165,16 @@ class CommandPaletteManager {
|
|
|
178
165
|
this.#globalLayer = { items: [], recentItems: [] };
|
|
179
166
|
this.#query = '';
|
|
180
167
|
}
|
|
181
|
-
addCommands(itemOrItems
|
|
168
|
+
addCommands(itemOrItems) {
|
|
182
169
|
const items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
|
|
183
170
|
const itemsWithId = items.map((item) => ({
|
|
184
171
|
...item,
|
|
185
|
-
id:
|
|
186
|
-
isGlobal: options.global,
|
|
172
|
+
id: generateId(),
|
|
187
173
|
}));
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.#layers.at(-1).items.push(...itemsWithId);
|
|
193
|
-
}
|
|
174
|
+
const globalItems = itemsWithId.filter(({ isGlobal }) => isGlobal);
|
|
175
|
+
const localItems = itemsWithId.filter(({ isGlobal }) => !isGlobal);
|
|
176
|
+
this.#globalLayer.items.push(...globalItems);
|
|
177
|
+
this.#layers.at(-1).items.push(...localItems);
|
|
194
178
|
return () => this.removeCommands(itemsWithId);
|
|
195
179
|
}
|
|
196
180
|
#removeCommands(layer, ids) {
|
package/dist/site/constants.d.ts
CHANGED
package/dist/site/constants.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { goto } from '$app/navigation';
|
|
1
2
|
import { asText } from '../services/command-palette-manager.svelte.js';
|
|
2
3
|
import { mdiOpenInNew } from '@mdi/js';
|
|
3
4
|
export const Constants = {
|
|
@@ -132,6 +133,6 @@ export const siteCommands = [
|
|
|
132
133
|
iconClass: 'text-indigo-700 dark:text-indigo-200',
|
|
133
134
|
title: site.title,
|
|
134
135
|
description: site.description,
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
onAction: () => goto(site.href),
|
|
137
|
+
searchText: asText('Site', 'Link', site.title, site.description, site.href),
|
|
137
138
|
}));
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Translations } from './services/translation.svelte.js';
|
|
|
2
2
|
import type { DateTime } from 'luxon';
|
|
3
3
|
import type { Component, Snippet } from 'svelte';
|
|
4
4
|
import type { HTMLAnchorAttributes, HTMLAttributes, HTMLButtonAttributes, HTMLInputAttributes, HTMLLabelAttributes, HTMLTextareaAttributes } from 'svelte/elements';
|
|
5
|
+
import type { Shortcut } from './actions/shortcut.js';
|
|
5
6
|
export type Color = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info';
|
|
6
7
|
export type TextColor = Color | 'muted';
|
|
7
8
|
export type TextVariant = 'italic';
|
|
@@ -242,10 +243,20 @@ export type IfLike = {
|
|
|
242
243
|
export type ActionItemHandler<T = never> = (item: ActionItem<T>) => void | Promise<void>;
|
|
243
244
|
export type ActionItem<T = never> = Omit<{
|
|
244
245
|
title: string;
|
|
246
|
+
description?: string;
|
|
247
|
+
type?: string;
|
|
248
|
+
searchText?: string;
|
|
245
249
|
icon: IconLike;
|
|
250
|
+
iconClass?: string;
|
|
246
251
|
color?: Color;
|
|
247
252
|
onAction: ActionItemHandler<T>;
|
|
248
253
|
data: T;
|
|
254
|
+
shortcuts?: MaybeArray<Shortcut>;
|
|
255
|
+
shortcutOptions?: {
|
|
256
|
+
ignoreInputFields?: boolean;
|
|
257
|
+
preventDefault?: boolean;
|
|
258
|
+
};
|
|
259
|
+
isGlobal?: boolean;
|
|
249
260
|
} & IfLike, [
|
|
250
261
|
T
|
|
251
262
|
] extends [never] ? 'data' : ''>;
|