/
uzer_007
/
Rixea
Обзор
Документация
Войти
/
uzer_007
/
Rixea
Код
Запросы
0
Задачи
Вики
Пакеты
5
Релизы
2
CI/CD
Аналитика
Безопасность
master
web_src/js/modules/sortable.ts
28 строк
1 KB
uzer_007
feat: первая версия Rixea
02 авг 2026, 22:16
02 авг 2026, 22:16
d4f7504
Код
Авторство
О чём код?
import type {SortableOptions, SortableEvent} from 'sortablejs'; import type SortableType from 'sortablejs'; export function restoreSortableItem(container: Element, item: Element, oldIndex: number): void { const siblings = Array.from(container.children).filter((child) => child !== item); container.insertBefore(item, siblings[oldIndex] ?? null); } export async function createSortable(el: HTMLElement, opts: {handle?: string} & SortableOptions = {}): Promise<SortableType> { // type reassigned because typescript derives the wrong type from this import const {Sortable} = (await import('sortablejs') as unknown as {Sortable: typeof SortableType}); return new Sortable(el, { animation: 150, ghostClass: 'card-ghost', onChoose: (e: SortableEvent) => { const handle = opts.handle ? e.item.querySelector(opts.handle)! : e.item; handle.classList.add('tw-cursor-grabbing'); opts.onChoose?.(e); }, onUnchoose: (e: SortableEvent) => { const handle = opts.handle ? e.item.querySelector(opts.handle)! : e.item; handle.classList.remove('tw-cursor-grabbing'); opts.onUnchoose?.(e); }, ...opts, } satisfies SortableOptions); }