UNPKG

@progress/kendo-react-listbox

Version:

React ListBox enables you to display a list of items and manage the data between multiple lists. KendoReact ListBox package

9 lines (8 loc) 2.13 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=(e=[],c=[],a,t)=>{let r=[],i=[],n=[];const f={listBoxOneData:e,listBoxTwoData:c};switch(a){case"moveUp":r=[...e],r.forEach((s,o)=>{s[t]&&(r=u(o,o-1,r))}),n=[...c],n.forEach((s,o)=>{s[t]&&(n=u(o,o-1,n))}),f.listBoxOneData=r,f.listBoxTwoData=n;break;case"moveDown":r=e.reverse(),r.forEach((s,o)=>{s[t]&&(r=u(o,o-1,r))}),n=c.reverse(),n.forEach((s,o)=>{s[t]&&(n=u(o,o-1,n))}),f.listBoxOneData=[...r].reverse(),f.listBoxTwoData=[...n].reverse();break;case"transferTo":r=e.filter(s=>!s[t]),i=e.filter(s=>s[t]),n=c.concat(i),f.listBoxOneData=r,f.listBoxTwoData=n;break;case"transferFrom":n=c.filter(s=>!s[t]),i=c.filter(s=>s[t]),r=e.concat(i),f.listBoxOneData=r,f.listBoxTwoData=n;break;case"transferAllTo":f.listBoxOneData=[],f.listBoxTwoData=c.concat(e);break;case"transferAllFrom":f.listBoxOneData=c.concat(e),f.listBoxTwoData=[];break;case"remove":n=c.filter(s=>!s[t]),r=e.filter(s=>!s[t]),f.listBoxOneData=r,f.listBoxTwoData=n;break}return f},u=(e,c,a)=>{const t=a.splice(e,1)[0];return a.splice(c,0,t),a},h=(e=[],c=[],a,t,r)=>{const i=e.findIndex(I=>I[r]===a[r]),n=c.findIndex(I=>I[r]===a[r]),f=t!==null?e.findIndex(I=>I[r]===t[r]):-1,s=t!==null?c.findIndex(I=>I[r]===t[r]):-1,o=i>=0,m=n>=0,b=f>=0,S=s>=0,p=[...e],L=[...c];return o&&b?{listBoxOneData:u(i,f,e),listBoxTwoData:c}:m&&S?{listBoxOneData:e,listBoxTwoData:u(n,s,c)}:o&&(S||t===null)?(t===null?L.push(e[i]):L.splice(s+1,0,e[i]),p.splice(i,1),{listBoxOneData:p,listBoxTwoData:L}):m&&(b||t===null)?(t===null?p.push(c[n]):p.splice(f+1,0,c[n]),L.splice(n,1),{listBoxOneData:p,listBoxTwoData:L}):{listBoxOneData:e,listBoxTwoData:c}};exports.moveItem=u;exports.processListBoxData=g;exports.processListBoxDragAndDrop=h;