UNPKG

@mitcsutt/kiln-dnd

Version:

Kiln drag and drop: sortable lists, boards, drop zones and grid layouts with one keyboard model and one announcer, rendered through kiln-ui

102 lines (101 loc) • 2.39 kB
//#region src/core/engine.ts var e; function t() { return e ??= import("@dnd-kit/dom"), e; } function n(e, t, n) { let { DragDropManager: r, PointerSensor: i, PointerActivationConstraints: a, Feedback: o } = e, s = new r({ sensors: [i.configure({ activationConstraints: (e) => e.pointerType === "touch" ? [new a.Delay({ value: 250, tolerance: 5 })] : [new a.Distance({ value: 5 })] })], plugins: [ e.AutoScroller, e.Cursor, e.PreventSelection, o.configure({ dropAnimation: null }) ], ...n }), c = () => { let e = s.dragOperation, { current: t, initial: n } = e.position; return { sourceId: String(e.source?.id ?? ""), targetId: e.target ? String(e.target.id) : null, pointer: { x: t.x, y: t.y }, delta: { x: t.x - n.x, y: t.y - n.y } }; }, l = [ s.monitor.addEventListener("dragstart", (e) => { t.start(String(e.operation.source?.id ?? "")); }), s.monitor.addEventListener("dragmove", (e) => { let n = c(); if (e.to) { let { initial: t } = s.dragOperation.position; n.pointer = { x: e.to.x, y: e.to.y }, n.delta = { x: e.to.x - t.x, y: e.to.y - t.y }; } t.move(n); }), s.monitor.addEventListener("dragover", () => { t.move(c()); }), s.monitor.addEventListener("dragend", (e) => { t.end(c(), e.canceled); }) ]; return { draggable(t) { let n = new e.Draggable({ id: t.id, element: t.element, handle: t.handle, disabled: t.disabled, plugins: [o.configure({ feedback: t.feedback })] }, s); return { update(e) { e.element !== void 0 && (n.element = e.element), "handle" in e && (n.handle = e.handle), e.disabled !== void 0 && (n.disabled = e.disabled); }, destroy: () => { n.destroy(); } }; }, droppable(t) { let n = t.accepts, r = new e.Droppable({ id: t.id, element: t.element, disabled: t.disabled, collisionPriority: t.priority, accept: (e) => n(String(e.id)) }, s); return { update(e) { e.element !== void 0 && (r.element = e.element), e.disabled !== void 0 && (r.disabled = e.disabled), e.accepts && (n = e.accepts); }, destroy: () => { r.destroy(); } }; }, destroy() { for (let e of l) e(); s.destroy(); } }; } //#endregion export { n as createEngine, t as loadEngine }; //# sourceMappingURL=engine.js.map