@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
73 lines (72 loc) • 2.25 kB
JavaScript
import { collides as e, getFirstCollision as t } from "./collision.js";
import { sortLayoutItemsByColRow as n, sortLayoutItemsByRowCol as r } from "./sort.js";
import { bottom as i, cloneLayout as a, cloneLayoutItem as o, getStatics as s } from "./layout.js";
//#region src/grid/engine/compactors.ts
function c(t, n, r, i, a) {
let o = i === "x" ? "w" : "h";
n[i] += 1;
let l = t.findIndex((e) => e.i === n.i), u = a ?? s(t).length > 0;
for (let a = l + 1; a < t.length; a++) {
let s = t[a];
if (s !== void 0 && !s.static) {
if (!u && s.y > n.y + n.h) break;
e(n, s) && c(t, s, r + n[o], i, u);
}
}
n[i] = r;
}
function l(e, n, r, i) {
for (n.x = Math.max(n.x, 0), n.y = Math.max(n.y, 0), n.y = Math.min(i, n.y); n.y > 0 && !t(e, n);) n.y--;
let a;
for (; (a = t(e, n)) !== void 0;) c(r, n, a.y + a.h, "y");
return n.y = Math.max(n.y, 0), n;
}
function u(e, n, r, i) {
for (n.x = Math.max(n.x, 0), n.y = Math.max(n.y, 0); n.x > 0 && !t(e, n);) n.x--;
let a;
for (; (a = t(e, n)) !== void 0;) if (c(i, n, a.x + a.w, "x"), n.x + n.w > r) for (n.x = r - n.w, n.y++; n.x > 0 && !t(e, n);) n.x--;
return n.x = Math.max(n.x, 0), n;
}
var d = {
type: "vertical",
allowOverlap: !1,
compact(e) {
let t = s(e), n = i(t), a = r(e), c = Array(e.length);
for (let r = 0; r < a.length; r++) {
let i = a[r];
if (i === void 0) continue;
let s = o(i);
s.static || (s = l(t, s, a, n), n = Math.max(n, s.y + s.h), t.push(s));
let u = e.indexOf(i);
c[u] = s, s.moved = !1;
}
return c;
}
}, f = {
type: "horizontal",
allowOverlap: !1,
compact(e, t) {
let r = s(e), i = n(e), a = Array(e.length);
for (let n = 0; n < i.length; n++) {
let s = i[n];
if (s === void 0) continue;
let c = o(s);
c.static || (c = u(r, c, t, i), r.push(c));
let l = e.indexOf(s);
a[l] = c, c.moved = !1;
}
return a;
}
}, p = {
type: null,
allowOverlap: !1,
compact(e) {
return a(e);
}
};
function m(e) {
return e === "vertical" ? d : e === "horizontal" ? f : p;
}
//#endregion
export { u as compactItemHorizontal, l as compactItemVertical, m as getCompactor, f as horizontalCompactor, p as noCompactor, c as resolveCompactionCollision, d as verticalCompactor };
//# sourceMappingURL=compactors.js.map