@progress/kendo-vue-listbox
Version:
72 lines (71 loc) • 2.71 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
const h = (t = [], f = [], o, s) => {
let r = [], I = [], n = [], c = {
listBoxOneData: t,
listBoxTwoData: f
};
switch (o) {
case "moveUp":
r = [...t], r.forEach((e, i) => {
e[s] && (r = u(i, i - 1, r));
}), n = [...f], n.forEach((e, i) => {
e[s] && (n = u(i, i - 1, n));
}), c.listBoxOneData = r, c.listBoxTwoData = n;
break;
case "moveDown":
r = t.reverse(), r.forEach((e, i) => {
e[s] && (r = u(i, i - 1, r));
}), n = f.reverse(), n.forEach((e, i) => {
e[s] && (n = u(i, i - 1, n));
}), c.listBoxOneData = [...r].reverse(), c.listBoxTwoData = [...n].reverse();
break;
case "transferTo":
r = t.filter((e) => !e[s]), I = t.filter((e) => e[s]), n = f.concat(I), c.listBoxOneData = r, c.listBoxTwoData = n;
break;
case "transferFrom":
n = f.filter((e) => !e[s]), I = f.filter((e) => e[s]), r = t.concat(I), c.listBoxOneData = r, c.listBoxTwoData = n;
break;
case "transferAllTo":
c.listBoxOneData = [], c.listBoxTwoData = f.concat(t);
break;
case "transferAllFrom":
c.listBoxOneData = f.concat(t), c.listBoxTwoData = [];
break;
case "remove":
n = f.filter((e) => !e[s]), r = t.filter((e) => !e[s]), c.listBoxOneData = r, c.listBoxTwoData = n;
break;
}
return c;
}, u = (t, f, o) => {
let s = o.splice(t, 1)[0];
return o.splice(f, 0, s), o;
}, k = (t = [], f = [], o, s, r) => {
let I = t.findIndex((a) => a[r] === o[r]), n = f.findIndex((a) => a[r] === o[r]), c = s !== null ? t.findIndex((a) => a[r] === s[r]) : -1, e = s !== null ? f.findIndex((a) => a[r] === s[r]) : -1, i = I >= 0, l = n >= 0, m = c >= 0, b = e >= 0, p = [...t], L = [...f];
return i && m ? {
listBoxOneData: u(I, c, t),
listBoxTwoData: f
} : l && b ? {
listBoxOneData: t,
listBoxTwoData: u(n, e, f)
} : i && (b || s === null) ? (s === null ? L.push(t[I]) : L.splice(e + 1, 0, t[I]), p.splice(I, 1), {
listBoxOneData: p,
listBoxTwoData: L
}) : l && (m || s === null) ? (s === null ? p.push(f[n]) : p.splice(c + 1, 0, f[n]), L.splice(n, 1), {
listBoxOneData: p,
listBoxTwoData: L
}) : {
listBoxOneData: t,
listBoxTwoData: f
};
};
export {
u as moveItem,
h as processListBoxData,
k as processListBoxDragAndDrop
};