gitea源码

sortable.ts 906B

123456789101112131415161718192021222324
  1. import type {SortableOptions, SortableEvent} from 'sortablejs';
  2. import type SortableType from 'sortablejs';
  3. export async function createSortable(el: Element, opts: {handle?: string} & SortableOptions = {}): Promise<SortableType> {
  4. // @ts-expect-error: wrong type derived by typescript
  5. const {Sortable} = await import(/* webpackChunkName: "sortablejs" */'sortablejs');
  6. return new Sortable(el, {
  7. animation: 150,
  8. ghostClass: 'card-ghost',
  9. onChoose: (e: SortableEvent) => {
  10. const handle = opts.handle ? e.item.querySelector(opts.handle) : e.item;
  11. handle.classList.add('tw-cursor-grabbing');
  12. opts.onChoose?.(e);
  13. },
  14. onUnchoose: (e: SortableEvent) => {
  15. const handle = opts.handle ? e.item.querySelector(opts.handle) : e.item;
  16. handle.classList.remove('tw-cursor-grabbing');
  17. opts.onUnchoose?.(e);
  18. },
  19. ...opts,
  20. } satisfies SortableOptions);
  21. }