react-base-data-table 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -43,7 +43,7 @@ Valid keys: `+JSON.stringify(Object.keys(g),null," "));var O=le(L,V,I,N,z+"."+V
|
|
|
43
43
|
${e.isInExpandedSelection?"bg-blue-100/50":""}
|
|
44
44
|
${e.isSelected?"outline-2 outline-radius outline-blue-500! bg-transparent ":"outline-none"}
|
|
45
45
|
${e.isInLinkedGroup||!b&&((te=e.header.editOptions)!=null&&te.greyedOutIfNotEditable)?"bg-gray-200/50! ":""}
|
|
46
|
-
`,onKeyDown:u,onMouseDown:l,onMouseEnter:R,onContextMenu:e.onContextMenu?_=>{e.onContextMenu(e.rowIndex,e.columnIndex,e.item,_)}:void 0,children:[e.comments&&e.comments.length>0&&y.jsx("div",{onClick:()=>i(d?void 0:{rowIndex:e.rowIndex,columnIndex:e.columnIndex}),className:"absolute top-0 right-0 ",style:{width:0,height:0,borderTop:"10px solid var(--comment-color)",borderLeft:"10px solid transparent"}}),x(),d&&y.jsx("div",{className:"absolute z-2000 w-[220px] mr-[-220px] bg-white border-2 border-[var(--comment-color)] rounded shadow-lg p-2 px-3 top-0 right-0",children:y.jsx(cl,{comment:((ce=e.comments)==null?void 0:ce[0])||{text:"",propertyId:e.header.id,value:e.item[e.header.id],date:new Date},columnId:e.header.id,isNewComment:((ue=e.comments)==null?void 0:ue.length)===0,saveComment:_=>{var T;(T=e.onSaveComment)==null||T.call(e,_,e.item)},deleteComment:_=>w(_),setIsEditing:E,isEditing:S||((P=e.comments)==null?void 0:P.length)===0})})]},`item-${e.columnIndex}-${e.rowIndex}`)}function dl(e,t){c.useEffect(()=>{function r(n){e.current&&n.target&&!e.current.contains(n.target)&&t()}return document.addEventListener("mousedown",r),()=>{document.removeEventListener("mousedown",r)}},[e,t])}function hl(e){var m;const[t,r]=c.useState(""),[n,a]=c.useState(!1),i=c.useRef(null),o=c.useRef(null),[s,l]=c.useState([]);c.useEffect(()=>{var b;l(((b=e.currentFilter)==null?void 0:b.itemsToHide)??[])},[(m=e.currentFilter)==null?void 0:m.itemsToHide,e.show]),c.useEffect(()=>{var b,x;if(e.show&&o.current){const S=o.current.getBoundingClientRect(),E=(x=(b=e.tableRef)==null?void 0:b.current)==null?void 0:x.getBoundingClientRect(),R=(E==null?void 0:E.width)??0,w=S.width+S.x>R;a(w)}else a(!1)},[e.show]),dl(i,()=>{e.show&&e.onShowOrHide(!1)});const u=()=>t?[...e.items].filter(b=>b==null?void 0:b.toString().toLocaleLowerCase().includes(t==null?void 0:t.toString().toLocaleLowerCase())):[...e.items],f=b=>{b.preventDefault(),t&&e.onSetFilter(e.headerId,[t])},d=()=>{l([...e.items])},p=()=>{l([])},v=b=>{const x=s.findIndex(E=>E===b);let S=[...s];x===-1?S=[...S,b]:S.splice(x,1),l(S)},h=()=>{const x=u().filter(E=>!s.includes(E)),S=[...e.items].filter(E=>!x.includes(E));e.onSetFilter(e.headerId,S.map(E=>E))};return y.jsxs("div",{ref:i,className:"relative",children:[y.jsx("button",{onClick:()=>e.onShowOrHide(!e.show),className:`border-solid border hover:!border-primary cursor-pointer border-gray-300 rounded focus:outline-hidden! ${e.currentFilter?"bg-purple-800":"bg-white"} `,children:y.jsx(Ie,{path:qs,color:e.currentFilter?"white":"grey",size:.6})}),e.show?y.jsxs("div",{ref:o,className:`absolute mt-1 bg-white shadow-xs p-3 w-60 z- rounded-md font-normal border border-border-color-light ${n?"right-0":""}`,children:[y.jsx("div",{className:"font-semibold mb-1",children:"Filter by value:"}),y.jsxs("form",{onSubmit:f,children:[y.jsx("input",{type:"text",value:t,onChange:b=>r(b==null?void 0:b.target.value),placeholder:"Search...",className:"input input-bordered input-xs w-full max-w-xs"}),y.jsx("input",{type:"submit",value:""})]}),y.jsxs("div",{className:"flex text-xs mt-1 font-semibold text-primary",children:[y.jsx("button",{onClick:p,onFocus:()=>{},className:"mr-4 cursor-pointer hover:border-none! border-none! focus:outline-hidden! bg-transparent btn-sm",children:"Select All"}),y.jsx("button",{onClick:d,onFocus:()=>{},className:"cursor-pointer hover:border-none! border-none! focus:outline-hidden! bg-transparent btn-sm",children:"Clear"})]}),y.jsx("div",{className:"overflow-auto max-h-44 mt-2",style:{scrollbarWidth:"thin"},children:u().map((b,x)=>y.jsxs("div",{className:"flex mt-2",children:[y.jsx("input",{type:"checkbox",onClick:()=>v(b),readOnly:!0,checked:!s.includes(b),className:"checkbox checkbox-primary checkbox-xs mr-2"}),y.jsx("p",{className:"text-xs",children:(b==null?void 0:b.toString())||y.jsx("span",{className:"italic",children:"(Blanks)"})})]},`filter-item-${b}-${x}`))}),y.jsxs("div",{className:"flex float-end mt-2",children:[y.jsx(Re,{onClick:()=>{h(),e.onShowOrHide(!1)},text:"OK",iconColor:"#6161bb",small:!0}),y.jsx(Re,{className:"ml-1",onClick:()=>e.onShowOrHide(!1),text:"Cancel",iconColor:"#6161bb",small:!0})]})]}):""]})}var io=(e=>(e.STRING="string",e.NUMBER="number",e))(io||{});function pl(e){const[t,r]=c.useState(""),n=(d,p)=>{if(!d){r("");return}r(p)},a=d=>{if(e.activeFilters)return e.activeFilters.find(p=>p.headerId===d)};function i(d,p,v=0){const h=u(d,p,v),m=d.filter(b=>b.children&&b.children.length>0).map(b=>b.children).flat();return m.length>0?[h,...i(m,p,v+1)]:[h]}const o=d=>e.filterItemsCache[d]??[];function s(d){return d.reduce((p,v)=>v.children&&v.children.length>0?Math.max(p,1+s(v.children)):Math.max(p,1),0)}function l(d){return d.children&&d.children.length>0?d.children.reduce((p,v)=>p+l(v),0):1}function u(d,p,v=0){return d.length===0?null:y.jsx("tr",{className:"z-100",children:d.map((h,m)=>{var E,R;const b=l(h),S=h.children&&h.children.length>0?1:p-v;return y.jsx("th",{colSpan:b,rowSpan:S,className:`${e.noBorder?"":"border-solid border border-gray-300! bg-slate-100"}`,children:y.jsxs("div",{style:{width:h.width?`${h.width}px`:"auto"},className:"flex justify-between",children:[y.jsxs("div",{className:"flex",children:[h.customHeader?h.customHeader(h):y.jsx("button",{onClick:()=>{var w;return(w=e.onSortByColumn)==null?void 0:w.call(e,h)},className:`font-semibold bg-transparent text-left text-slate-600 text-xs border-none outline-hidden! whitespace-pre ${h.sortable?"cursor-pointer hover:underline":"cursor-default"}`,children:h.text}),e.currentSortId===h.id&&y.jsxs(y.Fragment,{children:[y.jsx(Ie,{path:e.ascendingOrder?Ds:Fs,color:"grey",size:.6}),y.jsx("button",{onClick:e.onResetSort,className:`border-solid border bg-slate-300 hover:bg-slate-400! hover:border-transparent cursor-pointer rounded-lg h-min focus:outline-hidden!
|
|
46
|
+
`,onKeyDown:u,onMouseDown:l,onMouseEnter:R,onContextMenu:e.onContextMenu?_=>{e.onContextMenu(e.rowIndex,e.columnIndex,e.item,_)}:void 0,children:[e.comments&&e.comments.length>0&&y.jsx("div",{onClick:()=>i(d?void 0:{rowIndex:e.rowIndex,columnIndex:e.columnIndex}),className:"absolute top-0 right-0 ",style:{width:0,height:0,borderTop:"10px solid var(--comment-color)",borderLeft:"10px solid transparent"}}),x(),d&&y.jsx("div",{className:"absolute z-2000 w-[220px] mr-[-220px] bg-white border-2 border-[var(--comment-color)] rounded shadow-lg p-2 px-3 top-0 right-0",children:y.jsx(cl,{comment:((ce=e.comments)==null?void 0:ce[0])||{text:"",propertyId:e.header.id,value:e.item[e.header.id],date:new Date},columnId:e.header.id,isNewComment:((ue=e.comments)==null?void 0:ue.length)===0,saveComment:_=>{var T;(T=e.onSaveComment)==null||T.call(e,_,e.item)},deleteComment:_=>w(_),setIsEditing:E,isEditing:S||((P=e.comments)==null?void 0:P.length)===0})})]},`item-${e.columnIndex}-${e.rowIndex}`)}function dl(e,t){c.useEffect(()=>{function r(n){e.current&&n.target&&!e.current.contains(n.target)&&t()}return document.addEventListener("mousedown",r),()=>{document.removeEventListener("mousedown",r)}},[e,t])}function hl(e){var m;const[t,r]=c.useState(""),[n,a]=c.useState(!1),i=c.useRef(null),o=c.useRef(null),[s,l]=c.useState([]);c.useEffect(()=>{var b;l(((b=e.currentFilter)==null?void 0:b.itemsToHide)??[])},[(m=e.currentFilter)==null?void 0:m.itemsToHide,e.show]),c.useEffect(()=>{var b,x;if(e.show&&o.current){const S=o.current.getBoundingClientRect(),E=(x=(b=e.tableRef)==null?void 0:b.current)==null?void 0:x.getBoundingClientRect(),R=(E==null?void 0:E.width)??0,w=S.width+S.x>R;a(w)}else a(!1)},[e.show]),dl(i,()=>{e.show&&e.onShowOrHide(!1)});const u=()=>t?[...e.items].filter(b=>b==null?void 0:b.toString().toLocaleLowerCase().includes(t==null?void 0:t.toString().toLocaleLowerCase())):[...e.items],f=b=>{b.preventDefault(),t&&e.onSetFilter(e.headerId,[t])},d=()=>{l([...e.items])},p=()=>{l([])},v=b=>{const x=s.findIndex(E=>E===b);let S=[...s];x===-1?S=[...S,b]:S.splice(x,1),l(S)},h=()=>{const x=u().filter(E=>!s.includes(E)),S=[...e.items].filter(E=>!x.includes(E));e.onSetFilter(e.headerId,S.map(E=>E))};return y.jsxs("div",{ref:i,className:"relative",children:[y.jsx("button",{onClick:()=>e.onShowOrHide(!e.show),className:`border-solid border hover:!border-primary cursor-pointer border-gray-300 rounded focus:outline-hidden! ${e.currentFilter?"bg-purple-800":"bg-white"} `,children:y.jsx(Ie,{path:qs,color:e.currentFilter?"white":"grey",size:.6})}),e.show?y.jsxs("div",{ref:o,className:`absolute mt-1 bg-white shadow-xs p-3 w-60 z-200 rounded-md font-normal border border-border-color-light ${n?"right-0":""}`,children:[y.jsx("div",{className:"font-semibold mb-1",children:"Filter by value:"}),y.jsxs("form",{onSubmit:f,children:[y.jsx("input",{type:"text",value:t,onChange:b=>r(b==null?void 0:b.target.value),placeholder:"Search...",className:"input input-bordered input-xs w-full max-w-xs"}),y.jsx("input",{type:"submit",value:""})]}),y.jsxs("div",{className:"flex text-xs mt-1 font-semibold text-primary",children:[y.jsx("button",{onClick:p,onFocus:()=>{},className:"mr-4 cursor-pointer hover:border-none! border-none! focus:outline-hidden! bg-transparent btn-sm",children:"Select All"}),y.jsx("button",{onClick:d,onFocus:()=>{},className:"cursor-pointer hover:border-none! border-none! focus:outline-hidden! bg-transparent btn-sm",children:"Clear"})]}),y.jsx("div",{className:"overflow-auto max-h-44 mt-2",style:{scrollbarWidth:"thin"},children:u().map((b,x)=>y.jsxs("div",{className:"flex mt-2",children:[y.jsx("input",{type:"checkbox",onClick:()=>v(b),readOnly:!0,checked:!s.includes(b),className:"checkbox checkbox-primary checkbox-xs mr-2"}),y.jsx("p",{className:"text-xs",children:(b==null?void 0:b.toString())||y.jsx("span",{className:"italic",children:"(Blanks)"})})]},`filter-item-${b}-${x}`))}),y.jsxs("div",{className:"flex float-end mt-2",children:[y.jsx(Re,{onClick:()=>{h(),e.onShowOrHide(!1)},text:"OK",iconColor:"#6161bb",small:!0}),y.jsx(Re,{className:"ml-1",onClick:()=>e.onShowOrHide(!1),text:"Cancel",iconColor:"#6161bb",small:!0})]})]}):""]})}var io=(e=>(e.STRING="string",e.NUMBER="number",e))(io||{});function pl(e){const[t,r]=c.useState(""),n=(d,p)=>{if(!d){r("");return}r(p)},a=d=>{if(e.activeFilters)return e.activeFilters.find(p=>p.headerId===d)};function i(d,p,v=0){const h=u(d,p,v),m=d.filter(b=>b.children&&b.children.length>0).map(b=>b.children).flat();return m.length>0?[h,...i(m,p,v+1)]:[h]}const o=d=>e.filterItemsCache[d]??[];function s(d){return d.reduce((p,v)=>v.children&&v.children.length>0?Math.max(p,1+s(v.children)):Math.max(p,1),0)}function l(d){return d.children&&d.children.length>0?d.children.reduce((p,v)=>p+l(v),0):1}function u(d,p,v=0){return d.length===0?null:y.jsx("tr",{className:"z-100",children:d.map((h,m)=>{var E,R;const b=l(h),S=h.children&&h.children.length>0?1:p-v;return y.jsx("th",{colSpan:b,rowSpan:S,className:`${e.noBorder?"":"border-solid border border-gray-300! bg-slate-100"}`,children:y.jsxs("div",{style:{width:h.width?`${h.width}px`:"auto"},className:"flex justify-between",children:[y.jsxs("div",{className:"flex",children:[h.customHeader?h.customHeader(h):y.jsx("button",{onClick:()=>{var w;return(w=e.onSortByColumn)==null?void 0:w.call(e,h)},className:`font-semibold bg-transparent text-left text-slate-600 text-xs border-none outline-hidden! whitespace-pre ${h.sortable?"cursor-pointer hover:underline":"cursor-default"}`,children:h.text}),e.currentSortId===h.id&&y.jsxs(y.Fragment,{children:[y.jsx(Ie,{path:e.ascendingOrder?Ds:Fs,color:"grey",size:.6}),y.jsx("button",{onClick:e.onResetSort,className:`border-solid border bg-slate-300 hover:bg-slate-400! hover:border-transparent cursor-pointer rounded-lg h-min focus:outline-hidden!
|
|
47
47
|
`,children:y.jsx(Ie,{path:Gs,color:"grey",size:.6})})]})]}),h.hasFilter?y.jsx("div",{className:"ml-2",children:y.jsx(hl,{show:t===h.id,tableRef:e.tableRef,currentFilter:a(h.id),filterName:h.text,headerId:h.id,filterType:io.STRING,items:o(h.id),itemsToHide:((R=(E=e.activeFilters)==null?void 0:E.find(w=>w.headerId===h.id))==null?void 0:R.itemsToHide)??[],onShowOrHide:w=>n(w,h.id),onSetFilter:e.onSetFilter??(()=>{})})}):y.jsx(y.Fragment,{})]})},h.id+`-${m}`)})},`header-row-${v}`)}const f=s(e.headers);return y.jsx("thead",{children:i(e.headers,f)})}const gl=e=>e.every(t=>typeof t=="number"),vl=(e,t)=>e<t?-1:e>t?1:0,bl=(e,t)=>e>t?-1:e<t?1:0,oo=" ",ml=(e,t)=>e.length===0?[]:t.length===0?[...e]:[...e].filter(r=>{for(const n of t){let a=r[n.headerId],i=!1;if(gl(n.itemsToHide)?(a=typeof a=="string"?a.split(oo).join(""):a,i=n.itemsToHide.includes(Number(a))):n.itemsToHide.includes(a)&&(i=!0),i)return!1}return!0}),yl=(e,t,r,n)=>{let a=[...e];if(!n)return a;const i=t.find(s=>s.id===n);if(i!=null&&i.customSort)return a.sort((s,l)=>i.customSort(s,l,r==="asc")),a;let o=!0;return a.forEach(s=>{var d;const l=(d=s[n])==null?void 0:d.toString();if(!l)return;const u=Dr(l),f=["NaN"];isNaN(u)&&!f.includes(l)&&(o=!1)}),o?(a.sort((s,l)=>{const u=Dr(s[n]),f=Dr(l[n]),d=typeof u=="number"&&!isNaN(u),p=typeof f=="number"&&!isNaN(f);return d&&!p?-1:!d&&p?1:r==="desc"?f-u:u-f}),a):(r==="desc"?a.sort((s,l)=>vl(l[n],s[n])):a.sort((s,l)=>bl(l[n],s[n])),a)},Dr=e=>typeof e=="number"?e:typeof e=="string"?Number(e.split(oo).join("")):e;function xl(e,t,r=[],n){const[a,i]=c.useState(r),o=()=>{i([])},s=(v,h)=>{const m=[...a],b=m.findIndex(x=>x.headerId===v);b!==-1?h.length>0?m[b]={headerId:v,itemsToHide:h}:m.splice(b,1):h.length>0&&m.push({headerId:v,itemsToHide:h}),i(m)},l=n||e,u=c.useMemo(()=>ml(l,a),[l,a]);function f(v){return v.flatMap(h=>h.children&&h.children.length>0?f(h.children):[h])}const d=c.useMemo(()=>f(t),[t]),p=c.useMemo(()=>{const v={};return d.forEach(h=>{let m=u.map(x=>x[h.id]);const b=a.find(x=>x.headerId===h.id);b&&(m=m.concat(b.itemsToHide)),v[h.id]=[...new Set(m)].filter(x=>typeof x=="string"||typeof x=="number")}),v},[u,a,d]);return{activeFilters:a,setActiveFilters:i,clearActiveFilters:o,setActiveTableFilter:s,filteredItems:u,filterItemsCache:p}}function wl(e,t,r,n){const[a,i]=c.useState(r),[o,s]=c.useState(!0);c.useEffect(()=>{i(r)},[r]);const l=()=>{i(void 0),s(!0)},u=d=>{if(!(d!=null&&d.sortable))return;let p;a===d.id?p=!o:p=!0,i(d.id),s(p),n&&n(d.id)},f=c.useMemo(()=>yl(e,t,o?"asc":"desc",a),[e,t,o,a]);return{currentSortId:a,setCurrentSortId:i,ascendingOrder:o,setAscendingOrder:s,onResetSort:l,onSortByColumn:u,sortedItems:f}}function Cl(e,t,r=[],n,a){const{currentSortId:i,setCurrentSortId:o,ascendingOrder:s,setAscendingOrder:l,onResetSort:u,onSortByColumn:f,sortedItems:d}=wl(e,t,n,a),{activeFilters:p,setActiveFilters:v,clearActiveFilters:h,setActiveTableFilter:m,filteredItems:b,filterItemsCache:x}=xl(e,t,r,d),S=c.useMemo(()=>b,[b]);return{activeFilters:p,setActiveFilters:v,clearActiveFilters:h,setActiveTableFilter:m,filterItemsCache:x,currentSortId:i,setCurrentSortId:o,ascendingOrder:s,setAscendingOrder:l,onResetSort:u,onSortByColumn:f,processedItems:S}}function Sl(e,t,r){const[n,a]=c.useState([]),i=c.useCallback(d=>{a(p=>p.includes(d)?p.filter(m=>m!==d):[...p,d])},[]),o=c.useMemo(()=>{if(!t)return{"":e.map((m,b)=>({rowIndex:b,item:m}))};const d=e.reduce((h,m)=>{const b=m[t];return h[b]||(h[b]=[]),h[b].push({rowIndex:0,item:m}),h},{});let p=0;const v={};return Object.keys(d).forEach(h=>{v[h]=d[h].map(({item:m})=>({rowIndex:p++,item:m}))}),v},[e,t]),s=c.useMemo(()=>{const d=Object.entries(o);if(!r||r.length===0)return d;const p=new Set(r.map(E=>E.master)),v=new Set(r.flatMap(E=>E.linked)),h=new Map(r.map(E=>[E.master,E.linked])),m=new Set,b=[],x=new Map(d.map(E=>[E[0],E]));for(const[E,R]of d)if(!m.has(E))if(p.has(E)){b.push([E,R]),m.add(E);const w=h.get(E)||[];for(const B of w){const J=x.get(B);J&&!m.has(B)&&(b.push(J),m.add(B))}}else{if(v.has(E))continue;b.push([E,R]),m.add(E)}let S=0;return b.map(([E,R])=>{const w=R.map(({item:B})=>({rowIndex:S++,item:B}));return[E,w]})},[o,r]),l=c.useMemo(()=>d=>{var p;return(p=r==null?void 0:r.find(v=>v.linked.includes(d)))==null?void 0:p.master},[r]),u=c.useMemo(()=>{const d=[];return s.forEach(([p,v])=>{var m;const h=(n==null?void 0:n.includes(p))??!1;d.push({isGroup:!0,groupName:p,isCollapsed:h,masterGroupName:l(p),linkedGroupNames:(m=r==null?void 0:r.find(b=>b.master===p))==null?void 0:m.linked}),h||v.forEach(({rowIndex:b,item:x})=>{d.push({isGroup:!1,rowIndex:b,groupName:p,isCollapsed:h,item:x})})}),d},[s,n]),f=c.useMemo(()=>d=>!!(r!=null&&r.some(p=>p.linked.includes(d))),[r]);return{groupedItems:o,groupedItemsEntries:s,collapsedGroups:n,flatGroupedItemsToDisplay:u,onCollapseGroup:i,setCollapsedGroup:a,isGroupLinked:f,getMasterGroupNameLinked:l}}const El=(e,t,r,n,a)=>{e.stopPropagation();let i=t,o=[...r];if(e.key==="Tab"){let s=(t==null?void 0:t.rowIndex)??0,l=(t==null?void 0:t.columnIndex)??0;if(r.length>1){const u=Math.min(...r.map(v=>v.rowIndex)),f=Math.max(...r.map(v=>v.rowIndex)),d=Math.min(...r.map(v=>v.columnIndex)),p=Math.max(...r.map(v=>v.columnIndex));e.shiftKey?(l--,l<d&&(l=p,s--,s<u&&(s=f))):(l++,l>p&&(l=d,s++,s>f&&(s=u)))}else l=((t==null?void 0:t.columnIndex)??0)+(e.shiftKey?-1:1),l>=n?(l=0,s++):l<0&&(l=n-1,s--),s>=a&&(s=0),s<0&&(s=a-1),o=[];i={rowIndex:s,columnIndex:l}}if(e.shiftKey&&["ArrowDown","ArrowUp","ArrowLeft","ArrowRight"].includes(e.key)&&(o=$l(t,r,e.key)),!e.shiftKey&&["ArrowDown","ArrowUp","ArrowLeft","ArrowRight"].includes(e.key)){let s=(t==null?void 0:t.rowIndex)??0,l=(t==null?void 0:t.columnIndex)??0;switch(e.key){case"ArrowDown":s=Math.min(a-1,s+1);break;case"ArrowUp":s=Math.max(0,s-1);break;case"ArrowRight":l=Math.min(n-1,l+1);break;case"ArrowLeft":l=Math.max(0,l-1);break}i={rowIndex:s,columnIndex:l},o=[]}return{newSelectedCell:i,newExpandedSelection:o}};function $l(e,t,r){if(!e)return t;let n,a,i,o;if(t.length===0)return[{...e}];n=Math.min(...t.map(h=>h.rowIndex)),a=Math.max(...t.map(h=>h.rowIndex)),i=Math.min(...t.map(h=>h.columnIndex)),o=Math.max(...t.map(h=>h.columnIndex));let s=0,l=0;switch(e.rowIndex===n?s=a:s=n,e.columnIndex===i?l=o:l=i,r){case"ArrowUp":s=s-1;break;case"ArrowDown":s=s+1;break;case"ArrowLeft":l=l-1;break;case"ArrowRight":l=l+1;break;default:return t}const u=Math.min(e.rowIndex,s),f=Math.max(e.rowIndex,s),d=Math.min(e.columnIndex,l),p=Math.max(e.columnIndex,l),v=[];for(let h=u;h<=f;h++)for(let m=d;m<=p;m++)v.push({rowIndex:h,columnIndex:m});return v}function _l({headers:e,items:t,groupedItemsEntries:r,onChange:n,onBulkChange:a,onRowDoubleClick:i}){const[o,s]=c.useState(),[l,u]=c.useState([]),f=c.useCallback(P=>{if(P)if(r){const _=r.flatMap(([T,H])=>H.filter(X=>X.rowIndex===P.rowIndex))[0];if(_)return _.item}else return t[P.rowIndex]},[r,t]),d=c.useCallback((P,_,T,H)=>{const X=t.findIndex(q=>q===_);let Z;if(H){const q=_[T.fromArray];q[H.index]={...q[H.index],[T.id]:P},Z={..._,[T.fromArray]:q}}else Z={..._,[T.id]:P};return{itemUpdated:Z,originalIndex:X}},[t]),p=c.useCallback((P,_,T,H)=>{var q;const{itemUpdated:X,originalIndex:Z}=d(P,_,T,H.fromArrayData);if(n){const re=(q=H.fromArrayData)==null?void 0:q.index;(re===void 0?_[T.id]!==P:_[T.fromArray][re]!==P)&&n(X,Z,re)}},[n,d]),v=c.useCallback((P,_,T)=>{T.preventDefault(),l.some(X=>X.rowIndex===P&&X.columnIndex===_)||(s({rowIndex:P,columnIndex:_}),u([]))},[l]),h=c.useCallback((P,_,T,H)=>{var Z;let X=[...l];if(o&&!l.some(q=>q.rowIndex===o.rowIndex&&q.columnIndex===o.columnIndex)&&(X=[...l,o]),(l==null?void 0:l.length)>1){const q=X.map(re=>{const ne=f(re);return ne?(console.log("Edit value",P),{itemUpdated:{...ne,[T.id]:P},originalIndex:t.findIndex(g=>g===ne)}):null}).filter(Boolean);a&&q.length>0&&a(q,T.id)}else{const{itemUpdated:q,originalIndex:re}=d(P,_,T);if(n){const ne=(Z=H.fromArrayData)==null?void 0:Z.index;(ne===void 0?_[T.id]!==P:_[T.fromArray][ne]!==P)&&n(q,re,ne)}}},[l,o,f,t,a,n,d]),m=c.useCallback(P=>{var _,T;((o==null?void 0:o.rowIndex)!==P.rowIndex||(o==null?void 0:o.columnIndex)!==P.columnIndex||((_=o==null?void 0:o.fromArrayData)==null?void 0:_.index)!==((T=P.fromArrayData)==null?void 0:T.index))&&(s(P),u([]))},[o]),b=c.useCallback(P=>{const{newSelectedCell:_,newExpandedSelection:T}=El(P,o,l,e.length,t.length);s(_),u(T)},[o,l,e.length,t.length]),x=c.useCallback(P=>{i&&i(P)},[i]),S=c.useRef(!1),[E,R]=c.useState(!1),[w,B]=c.useState(),J=c.useCallback((P,_,T)=>{S.current=!0,B({rowIndex:_,columnIndex:T})},[]),te=c.useCallback((P,_,T)=>{if(P.stopPropagation(),!E||!w)return;const H=Math.min(w.rowIndex,_),X=Math.max(w.rowIndex,_),Z=Math.min(w.columnIndex,T),q=Math.max(w.columnIndex,T),re=[];for(let ne=H;ne<=X;ne++)for(let g=Z;g<=q;g++)re.push({rowIndex:ne,columnIndex:g});u(re)},[E,w]),ce=c.useCallback(P=>{P.preventDefault(),S.current&&!E&&R(!0),E&&w!==o&&s(w)},[E,w,o]),ue=c.useCallback(()=>{S.current=!1,R(!1)},[]);return c.useEffect(()=>(window.addEventListener("mouseup",ue),()=>{window.removeEventListener("mouseup",ue)}),[ue]),{selectedCell:o,expandedSelection:l,isDragging:E,setSelectedCell:s,setExpandedSelection:u,onCellBlur:p,onCellEnter:h,onCellClick:m,handleCellKeyDown:b,handleRowDoubleClick:x,onCellMouseDown:J,onCellMouseEnter:te,onMouseMove:ce,onRightClick:v,getItemFromCellCoordinates:f}}function Je(e,t,r){let n=r.initialDeps??[],a;function i(){var o,s,l,u;let f;r.key&&((o=r.debug)!=null&&o.call(r))&&(f=Date.now());const d=e();if(!(d.length!==n.length||d.some((h,m)=>n[m]!==h)))return a;n=d;let v;if(r.key&&((s=r.debug)!=null&&s.call(r))&&(v=Date.now()),a=t(...d),r.key&&((l=r.debug)!=null&&l.call(r))){const h=Math.round((Date.now()-f)*100)/100,m=Math.round((Date.now()-v)*100)/100,b=m/16,x=(S,E)=>{for(S=String(S);S.length<E;)S=" "+S;return S};console.info(`%c⏱ ${x(m,5)} /${x(h,5)} ms`,`
|
|
48
48
|
font-size: .6rem;
|
|
49
49
|
font-weight: bold;
|