UNPKG

@scalar/api-client

Version:

the open source API testing client

43 lines (42 loc) 1.47 kB
import { useLayout as v } from "../../hooks/useLayout.js"; function I(f, { collections: n, collectionMutators: a, tags: o, tagMutators: p, workspaceMutators: x }) { const { layout: D } = v(), y = (i, d) => { i.type === "collection" ? a.edit(i.uid, "children", d) : i.type === "tag" && p.edit(i.uid, "children", d); }; return { handleDragEnd: (i, d) => { if (!i || !d) return; const { id: l, parentId: r } = i, { id: u, parentId: s, offset: c } = d; if (r ? n[r] ? a.edit( r, "children", n[r].children.filter((e) => e !== l) ) : o[r] && p.edit( r, "children", o[r].children.filter((e) => e !== l) ) : x.edit( f.value?.uid, "collections", f.value?.collections.filter((e) => e !== l) ?? [] ), c === 2) { const e = n[u] || o[u]; e && y(e, [...e.children ?? [], l]); } else if (s) { const e = n[s] || o[s]; if (!e) return; const t = [...e.children ?? []], h = t.findIndex((U) => u === U) ?? 0; t.splice(h + c, 0, l), y(e, t); } else { const e = [...f.value?.collections ?? []], t = e.findIndex((h) => u === h) ?? 0; e.splice(t + c, 0, l), x.edit(f.value?.uid, "collections", e); } }, isDroppable: (i, d) => !(D === "modal" || !n[i.id] && d.offset !== 2 || n[i.id] && n[d.id]?.info?.title === "Drafts") }; } export { I as dragHandlerFactory };