mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
refactor(web): svelte actions (#9701)
This commit is contained in:
parent
8bfa6769a5
commit
832d728940
32 changed files with 43 additions and 41 deletions
|
|
@ -1,32 +0,0 @@
|
|||
import type { Action } from 'svelte/action';
|
||||
import { shortcuts } from './shortcut';
|
||||
|
||||
export const listNavigation: Action<HTMLElement, HTMLElement> = (node, container: HTMLElement) => {
|
||||
const moveFocus = (direction: 'up' | 'down') => {
|
||||
const children = Array.from(container?.children);
|
||||
if (children.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentIndex = document.activeElement === null ? -1 : children.indexOf(document.activeElement);
|
||||
const directionFactor = (direction === 'up' ? -1 : 1) + (direction === 'up' && currentIndex === -1 ? 1 : 0);
|
||||
const newIndex = (currentIndex + directionFactor + children.length) % children.length;
|
||||
|
||||
const element = children.at(newIndex);
|
||||
if (element instanceof HTMLElement) {
|
||||
element.focus();
|
||||
}
|
||||
};
|
||||
|
||||
const { destroy } = shortcuts(node, [
|
||||
{ shortcut: { key: 'ArrowUp' }, onShortcut: () => moveFocus('up'), ignoreInputFields: false },
|
||||
{ shortcut: { key: 'ArrowDown' }, onShortcut: () => moveFocus('down'), ignoreInputFields: false },
|
||||
]);
|
||||
|
||||
return {
|
||||
update(newContainer) {
|
||||
container = newContainer;
|
||||
},
|
||||
destroy,
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue