@sage-bionetworks/react-datasheet-grid 4.11.5-sage.12 → 4.11.5-sage.14
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 +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +409 -389
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
2
2
|
`)),n=t.getElementsByTagName(`table`)[0];if(n){let e=[];for(let t of Array.from(n.rows)){let n=[];e.push(n);for(let e of Array.from(t.cells))n.push(e.textContent??``)}return e}let r=t.getElementsByTagName(`span`)[0];return r?[[r.textContent??``]]:[[``]]},ce=e=>{let t=e.replaceAll(/\r|\n$/g,``),n=[[]],r=0,i=0,a=!1,o=0,s=()=>{let e=t.slice(i,r);e.startsWith(`"`)&&e.at(-1)===`"`&&(a=!0),a&&e.at(-1)===`"`&&e.includes(`
|
|
3
3
|
`)&&(e=e.slice(1,-1).replaceAll(`""`,`"`),a=!1),a&&e.at(-1)!==`"`?e.split(`
|
|
4
4
|
`).forEach((e,t,{length:r})=>{n[o].push(e),t<r-1&&(n.push([]),o++)}):n[o].push(e)};for(;r<t.length;)a&&t[r]===`"`&&![void 0,` `,`"`].includes(t[r+1])&&(a=!1),a&&t[r]===`"`&&t[r+1]===`"`&&r++,r===i&&t[r]===`"`&&(a=!0),t[r]===` `&&(s(),i=r+1,a=!1),t[r]===`
|
|
5
|
-
`&&!a&&(s(),n.push([]),i=r+1,o++),r++;return s(),n},le=e=>/[\t\n\r"]/.test(e)?`"${e.replaceAll(`"`,`""`)}"`:e,ue=e=>e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`).replaceAll(`'`,`'`),de=e=>/^[^\x00-\x20\x7F-\x9F]$/.exec(e)!==null,fe=(e,t,n,r)=>{if(e===null||!t||!n)return null;if(typeof e!=`object`)throw TypeError(`Value must be an object or null`);let i=r.findIndex(t=>t.id===e.col),a={col:Math.max(0,Math.min(t-1,i===-1?Number(e.col):i-1)),row:Math.max(0,Math.min(n-1,Number(e.row)))};if(isNaN(a.col)||isNaN(a.row))throw TypeError(`col or cell are not valid positive numbers`);return a},pe=(e,t)=>e?{col:e.col,row:e.row,colId:t[e.col+1]?.id}:null,me=(e,t,n,r)=>{if(e===null||!t||!n)return null;if(typeof e!=`object`)throw TypeError(`Value must be an object or null`);let i={min:fe(e.min,t,n,r),max:fe(e.max,t,n,r)};if(!i.min||!i.max)throw Error(`min and max must be defined`);return i},he=(e,t)=>e?{min:pe(e.min,t),max:pe(e.max,t)}:null,ge=()=>Array.from(document.querySelectorAll(`*`)).filter(e=>e instanceof HTMLElement&&typeof e.tabIndex==`number`&&e.tabIndex>=0&&!e.disabled&&(!(e instanceof HTMLAnchorElement)||!!e.href||e.getAttribute(`tabIndex`)!==null)&&getComputedStyle(e).visibility!==`collapse`),_e=({children:e,gutter:t,stickyRight:n,stickyLeft:r,active:i,disabled:a,className:o,width:s,left:c})=>(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-cell`,t&&`dsg-cell-gutter`,a&&`dsg-cell-disabled`,t&&i&&`dsg-cell-gutter-active`,n&&`dsg-cell-sticky-right`,r&&`dsg-cell-sticky-left`,o),style:{width:s,left:n?void 0:c},children:e}),ve=(e,t)=>(0,c.useMemo)(()=>{let n=new Map;return r=>(n.has(r)||n.set(r,(...n)=>{e(r,...n.slice(0,t))}),n.get(r))},[t,e]),ye=({data:e,columns:t,outerRef:n,innerRef:r,columnWidths:i,hasStickyRightColumn:a,pinFirstColumn:o,displayHeight:s,headerRowHeight:l,rowHeight:d,getRowSize:f,rowKey:p,fullWidth:g,selection:_,activeCell:v,rowClassName:y,cellClassName:b,children:x,editing:S,getContextMenuItems:C,setRowData:w,deleteRows:T,duplicateRows:E,insertRowAfter:ee,stopEditing:D,onScroll:te})=>{let O=(0,c.useCallback)(t=>{if(p&&t>0){let n=e[t-1];if(typeof p==`function`)return p({rowData:n,rowIndex:t});if(typeof p==`string`&&n instanceof Object&&p in n){let e=n[p];if(typeof e==`string`||typeof e==`number`)return e}}return t},[e,p]),k=(0,m.useVirtualizer)({count:e.length,getScrollElement:()=>n.current,paddingStart:l,estimateSize:e=>f(e).height,getItemKey:O,overscan:5}),A=(0,m.useVirtualizer)({count:t.length,getScrollElement:()=>n.current,estimateSize:e=>i?.[e]??100,horizontal:!0,getItemKey:e=>t[e].id??e,overscan:1,rangeExtractor:e=>{let n=(0,m.defaultRangeExtractor)(e);if(n[0]!==0&&n.unshift(0),(o||t[1]?.stickyLeft)&&t.length>1&&!n.includes(1)){let e=n.findIndex(e=>e>1);e===-1?n.push(1):n.splice(e,0,1)}return a&&n.at(-1)!==t.length-1&&n.push(t.length-1),n}});(0,c.useEffect)(()=>{A.measure()},[A,i]),(0,c.useEffect)(()=>{k.measure()},[k,d]);let ne=ve(w,1),re=ve(T,0),ie=ve(E,0),j=ve(ee,0),M=e=>{if(!t[e].stickyLeft)return 0;if(!i?.length){let t=A.getOffsetForIndex(e);return typeof t==`number`?t:0}let n=0;for(let t=0;t<e;t++)n+=i[t];return n},ae=_?.min.col??v?.col,oe=_?.max.col??v?.col,se=_?.min.row??v?.row,ce=_?.max.row??v?.row;return(0,u.jsx)(`div`,{ref:n,className:`dsg-container`,onScroll:te,style:{height:s},children:(0,u.jsxs)(`div`,{ref:r,style:{width:g?`100%`:A.getTotalSize(),height:k.getTotalSize()},children:[l>0&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,`dsg-row-header`),style:{width:g?`100%`:A.getTotalSize(),height:l},children:A.getVirtualItems().map(e=>{let n=!!t[e.index].stickyLeft;return(0,u.jsx)(_e,{gutter:e.index===0,stickyRight:a&&e.index===t.length-1,stickyLeft:n,width:e.size,left:n?M(e.index):e.start,className:(0,h.default)(`dsg-cell-header`,ae!==void 0&&oe!==void 0&&ae<=e.index-1&&oe>=e.index-1&&`dsg-cell-header-active`,t[e.index].headerClassName),children:(0,u.jsx)(`div`,{className:`dsg-cell-header-container`,children:t[e.index].title})},e.key)})}),k.getVirtualItems().map(n=>{let r=n.index>=(se??1/0)&&n.index<=(ce??-1/0);return(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,typeof y==`string`?y:null,typeof y==`function`?y({rowData:e[n.index],rowIndex:n.index}):null),style:{height:n.size,top:n.start,width:g?`100%`:A.getTotalSize()},children:A.getVirtualItems().map(i=>{let o=t[i.index].cellClassName,s=t[i.index].disabled,c=t[i.index].component,l=s===!0||typeof s==`function`&&s({rowData:e[n.index],rowIndex:n.index}),d=v?.row===n.index&&v.col===i.index-1,f=!!t[i.index].stickyLeft;return(0,u.jsx)(_e,{gutter:i.index===0,stickyRight:a&&i.index===t.length-1,stickyLeft:f,active:i.index===0&&r,disabled:l,className:(0,h.default)(typeof o==`function`?o({rowData:e[n.index],rowIndex:n.index,columnId:t[i.index].id}):o,typeof b==`function`?b({rowData:e[n.index],rowIndex:n.index,columnId:t[i.index].id}):b),width:i.size,left:f?M(i.index):i.start,children:(0,u.jsx)(c,{rowData:e[n.index],getContextMenuItems:C,disabled:l,active:d,columnIndex:i.index-1,rowIndex:n.index,focus:d&&S,deleteRow:re(n.index),duplicateRow:ie(n.index),stopEditing:D,insertRowBelow:j(n.index),setRowData:ne(n.index),columnData:t[i.index].columnData})},i.key)})},n.key)}),x]})})},N=(e,t,n,r)=>[[r,e],[t,e],[t,n],[r,n],[r,e]],be=(e,t,n,r)=>`polygon(evenodd, ${[...N(0,`100%`,`100%`,0),...N(e,t,n,r)].map(e=>e.map(e=>typeof e==`number`&&e!==0?e+`px`:e).join(` `)).join(`,`)})`,xe=c.default.memo(({columnWidths:e,columnRights:t,headerRowHeight:n,selection:r,rowHeight:i,activeCell:a,hasStickyRightColumn:o,dataLength:s,viewWidth:l,viewHeight:d,contentWidth:f,edges:p,isCellDisabled:m,editing:g,expandSelection:_,stickyLeftColumns:v,getStickyLeftOffset:y})=>{let b=a?m(a):!1,x=(0,c.useMemo)(()=>{if(!r)return b;for(let e=r.min.col;e<=r.max.col;++e)for(let t=r.min.row;t<=r.max.row;++t)if(!m({col:e,row:t}))return!1;return!0},[b,m,r]);if(!e||!t)return null;let S=e=>+(e<s-1),C=t=>+(t<e.length-(o?3:2)),w=a&&{width:e[a.col+1]+C(a.col),height:i(a.row).height+S(a.row),left:t[a.col],top:i(a.row).top+n},T=r&&{width:e.slice(r.min.col+1,r.max.col+2).reduce((e,t)=>e+t)+C(r.max.col),height:i(r.max.row).top+i(r.max.row).height-i(r.min.row).top+S(r.max.row),left:t[r.min.col],top:i(r.min.row).top+n},E=a&&v&&y&&v[a.col],ee=E&&y?y(a.col+1):0,D=r&&v&&y&&(()=>{for(let e=r.min.col;e<=r.max.col;e++)if(!v[e])return!1;return!0})(),te=D&&r&&y?y(r.min.col+1):0,O=r?.min||a,k=r?.max||a,A=k&&v&&y&&v[k.col],ne=A&&k&&y?y(k.col+1)+e[k.col+1]:0,re=r&&v?.[r.min.col]||a&&v?.[a.col],ie=re&&y?y((r?.min.col??a?.col??0)+1):0,j=k&&_!==null&&{left:t[k.col]+e[k.col+1],top:i(k.row).top+i(k.row).height+n,transform:`translate(-${k.col<e.length-(o?3:2)?50:100}%, -${k.row<s-1?50:100}%)`},M=O&&k&&_!==null&&{width:e.slice(O.col+1,k.col+2).reduce((e,t)=>e+t)+C(k.col),height:i(k.row+_).top+i(k.row+_).height-i(k.row+1).top+S(k.row+_)-1,left:t[O.col],top:i(k.row).top+i(k.row).height+n+1},ae=o?e.at(-1):0;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{className:`dsg-scrollable-view-container`,style:{height:i(s-1).top+i(s-1).height+n,width:f||`100%`},children:(0,u.jsx)(`div`,{className:(0,h.default)({"dsg-scrollable-view":!0,"dsg-scrollable-view-t":!p.top,"dsg-scrollable-view-r":!p.right,"dsg-scrollable-view-b":!p.bottom,"dsg-scrollable-view-l":!p.left}),style:{top:n,left:e[0],height:d?d-n:0,width:f&&l?l-e[0]-ae:`calc(100% - ${e[0]+ae}px)`}})}),(T||w)&&!re&&(0,u.jsx)(`div`,{className:`dsg-selection-col-marker-container`,style:{left:T?.left??w?.left,width:T?.width??w?.width,height:i(s-1).top+i(s-1).height+n},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker`,x&&`dsg-selection-col-marker-disabled`),style:{top:n}})}),(T||w)&&re&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker-container`,`dsg-selection-col-marker-container-sticky`),style:{position:`sticky`,left:ie,top:`auto`,width:T?.width??w?.width,height:i(s-1).top+i(s-1).height+n},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker`,x&&`dsg-selection-col-marker-disabled`),style:{top:n}})}),(T||w)&&(0,u.jsx)(`div`,{className:`dsg-selection-row-marker-container`,style:{top:T?.top??w?.top,height:T?.height??w?.height,width:f||`100%`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-row-marker`,x&&`dsg-selection-row-marker-disabled`),style:{left:e[0]}})}),w&&a&&!E&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-active-cell`,{"dsg-active-cell-focus":g,"dsg-active-cell-disabled":b}),style:w}),w&&a&&E&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:w.top,left:0,right:0,height:w.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-active-cell`,{"dsg-active-cell-focus":g,"dsg-active-cell-disabled":b,"dsg-active-cell-sticky":!0}),style:{position:`sticky`,left:ee,width:w.width,height:`100%`}})}),T&&w&&!D&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-rect`,x&&`dsg-selection-rect-disabled`),style:{...T,clipPath:be(w.top-T.top,w.left-T.left,w.top+w.height-T.top,w.left+w.width-T.left)}}),T&&w&&D&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:T.top,left:0,right:0,height:T.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-rect`,x&&`dsg-selection-rect-disabled`,`dsg-selection-rect-sticky`),style:{position:`sticky`,left:te,width:T.width,height:`100%`,background:`var(--dsg-selection-background-color)`,clipPath:be(w.top-T.top,ee-te,w.top+w.height-T.top,ee+w.width-te)}})}),M&&!D&&(0,u.jsx)(`div`,{className:`dsg-expand-rows-rect`,style:M}),M&&D&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:M.top,left:0,right:0,height:M.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-rect`,`dsg-expand-rows-rect-sticky`),style:{position:`sticky`,left:te,width:M.width,height:`100%`}})}),j&&!A&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-indicator`,x&&`dsg-expand-rows-indicator-disabled`),style:j}),j&&A&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:j.top,left:0,right:0,height:0,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-indicator`,x&&`dsg-expand-rows-indicator-disabled`,`dsg-expand-rows-indicator-sticky`),style:{position:`sticky`,left:ne,transform:j.transform,pointerEvents:`auto`}})})]})});xe.displayName=`SelectionRect`;var Se=({value:e,rowHeight:t})=>{let n=(0,c.useRef)([]),[,r]=(0,c.useState)(0);return(0,c.useMemo)(()=>{let i=r=>{if(typeof t==`number`)return Math.min(e.length-1,Math.max(-1,Math.floor(r/t)));let i=0,a=n.current.length-1;for(;i<=a;){let e=Math.floor((i+a)/2);if(n.current[e].top<r)i=e+1;else if(n.current[e].top>r)a=e-1;else return e}if(a===n.current.length-1&&e.length>n.current.length&&(!n.current.length||r>=n.current[a].top+n.current[a].height)){let i=a===-1?0:n.current[a].top+n.current[a].height;do{a++;let r=t({rowIndex:a,rowData:e[a]});n.current.push({height:r,top:i}),i+=r}while(i<=r&&a<n.current.length-1)}return a};return{resetAfter:e=>{n.current=n.current.slice(0,e),r(e=>e+1)},getRowSize:r=>{if(typeof t==`number`)return{height:t,top:t*r};if(r>=e.length)return{height:0,top:0};if(r<n.current.length)return n.current[r];let i=n.current.at(-1),a=i?i.top+i.height:0;for(let i=n.current.length;i<=r;i++){let r=t({rowIndex:i,rowData:e[i]});n.current.push({height:r,top:a}),a+=r}return n.current[r]},getRowIndex:i,totalSize:r=>{if(typeof t==`number`)return e.length*t;let a=i(r);return n.current[a].top+n.current[a].height}}},[t,e])},Ce=[],we=[],Te=()=>({}),Ee=()=>null,De=({rowData:e})=>({...e}),P=c.default.memo(c.default.forwardRef(({value:e=Ce,className:t,style:n,height:r=400,onChange:i=Ee,columns:a=we,rowHeight:o=40,headerRowHeight:s=typeof o==`number`?o:40,gutterColumn:d,stickyRightColumn:p,rowKey:m,addRowsComponent:h=ne,createRow:g=Te,autoAddRow:_=!1,lockRows:y=!1,disableExpandSelection:b=!1,disableSmartDelete:x=!1,duplicateRow:S=De,contextMenuComponent:C=M,disableContextMenu:w=!1,onFocus:T=Ee,onBlur:E=Ee,onActiveCellChange:A=Ee,onSelectionChange:ie=Ee,rowClassName:j,cellClassName:ae,onScroll:oe,pinFirstColumn:_e=!1},ve)=>{let N=(0,c.useRef)(null),be=w||y,P=ee(a,d,p,_e),F=!!p,Oe=_e||!!P[1]?.stickyLeft,ke=(0,c.useRef)(null),I=(0,c.useRef)(null),Ae=(0,c.useRef)(null),je=(0,c.useRef)(null),[Me,Ne]=re(1,100),{getRowSize:Pe,totalSize:Fe,getRowIndex:Ie}=Se({value:e,rowHeight:o}),Le=Math.min(r,s+Fe(r)+Me),{width:L,height:Re}=(0,l.useResizeDetector)({targetRef:I,refreshMode:`throttle`,refreshRate:100});Ne(Re?Le-Re:0);let ze=te(I,L,Re),{fullWidth:Be,totalWidth:Ve,columnWidths:R,columnRights:z}=v(P,L),He=(0,c.useMemo)(()=>P.slice(1).map(e=>!!e.stickyLeft),[P]),Ue=(0,c.useCallback)(e=>{if(!P[e]?.stickyLeft)return 0;if(!R?.length){let t=0;for(let n=0;n<e;n++)(P[n].stickyLeft||n===0)&&(t+=P[n].basis||P[n].minWidth||100);return t}let t=0;for(let n=0;n<e;n++)(P[n].stickyLeft||n===0)&&(t+=R[n]);return t},[P,R]),[We,B]=(0,c.useState)(null),[Ge,Ke]=(0,c.useState)([]),[V,H]=(0,c.useState)(!1),[qe,Je]=(0,c.useState)(0),[Ye,Xe]=(0,c.useState)(null),[U,W]=D(null),[G,K]=D(null),q=(0,c.useMemo)(()=>U&&G&&{min:{col:Math.min(U.col,G.col),row:Math.min(U.row,G.row)},max:{col:Math.max(U.col,G.col),row:Math.max(U.row,G.row)}},[U,G]),[J,Ze]=D({columns:!1,rows:!1,active:!1}),Qe=b||V||J.active||U?.row===e?.length-1||q?.max.row===e?.length-1||U&&P.slice((q?.min.col??U.col)+1,(q?.max.col??U.col)+2).every(e=>e.disabled===!0)?null:qe,$e=k(ke),et=k(I);(0,c.useEffect)(()=>{U!==null&&(document.activeElement.blur(),window.getSelection()?.removeAllRanges())},[U!==null]);let tt=(0,c.useCallback)((e,t=!1,n=!1)=>{let r=$e(t),i=n&&et(t);if(r&&z&&R){let t=e.clientX-r.left,n=e.clientY-r.top;return i&&(e.clientY-i.top<=s&&(n=0),e.clientX-i.left<=R[0]&&(t=0),Oe&&e.clientX-i.left<=R[0]+R[1]&&(t=z[0]+1),F&&i.right-e.clientX<=R.at(-1)&&(t=z.at(-2)+1)),{col:z.findIndex(e=>t<e)-1,row:Ie(n-s)}}return null},[z,R,e.length,$e,et,s,F,Oe,Ie]),Y=(0,c.useRef)(e);Y.current=e;let X=(0,c.useCallback)(e=>{let t=P[e.col+1].disabled;return!!(typeof t==`function`?t({rowData:Y.current[e.row],rowIndex:e.row}):t)},[P]),Z=(0,c.useCallback)((e,t=1)=>{y||(K(null),H(!1),i([...Y.current.slice(0,e+1),...Array(t).fill(0).map(g),...Y.current.slice(e+1)],[{type:`CREATE`,fromRowIndex:e+1,toRowIndex:e+1+t}]),W(n=>({col:n?.col||0,row:e+t,doNotScrollX:!0})))},[g,y,i,W,K]),nt=(0,c.useCallback)((e,t=e)=>{y||(i([...Y.current.slice(0,t+1),...Y.current.slice(e,t+1).map((t,n)=>S({rowData:t,rowIndex:n+e})),...Y.current.slice(t+1)],[{type:`CREATE`,fromRowIndex:t+1,toRowIndex:t+2+t-e}]),W({col:0,row:t+1,doNotScrollX:!0}),K({col:P.length-(F?3:2),row:2*t-e+1,doNotScrollX:!0}),H(!1))},[P.length,S,y,i,W,K,F]),Q=(0,c.useCallback)(e=>{if(Re&&L){if(!e.doNotScrollY){let t=Pe(e.row).top,n=Pe(e.row).top+Pe(e.row).height+s-Re+1,r=I.current.scrollTop;r>t?I.current.scrollTop=t:r<n&&(I.current.scrollTop=n)}if(z&&R&&I.current&&!e.doNotScrollX){let t=z[e.col]-z[0],n=z[e.col]+R[e.col+1]+(F?R.at(-1):0)-L+1,r=I.current.scrollLeft;r>t?I.current.scrollLeft=t:r<n&&(I.current.scrollLeft=n)}}},[Re,L,s,z,R,Pe,F]);(0,c.useEffect)(()=>{G&&Q(G)},[G,Q]),(0,c.useEffect)(()=>{U&&Q(U)},[U,Q]);let rt=(0,c.useCallback)((e,t)=>{i([...Y.current.slice(0,e),t,...Y.current.slice(e+1)],[{type:`UPDATE`,fromRowIndex:e,toRowIndex:e+1}])},[i]),it=(0,c.useCallback)((e,t=e)=>{y||(H(!1),W(n=>{let r=Math.min(Y.current.length-2-t+e,e);return r<0?null:n&&{col:n.col,row:r}}),K(null),i([...Y.current.slice(0,e),...Y.current.slice(t+1)],[{type:`DELETE`,fromRowIndex:e,toRowIndex:t+1}]))},[y,i,W,K]),at=(0,c.useCallback)((t=!0)=>{let n=t&&!x;if(!U)return;let r=q?.min||U,a=q?.max||U;if(e.slice(r.row,a.row+1).every((e,t)=>P.every(n=>n.isCellEmpty({rowData:e,rowIndex:t+r.row})))){n&&it(r.row,a.row);return}let o=[...e];for(let e=r.row;e<=a.row;++e)for(let t=r.col;t<=a.col;++t)if(!X({col:t,row:e})){let{deleteValue:n=({rowData:e})=>e}=P[t+1];o[e]=n({rowData:o[e],rowIndex:e})}n&&(0,f.default)(o,e)?(W({col:0,row:r.row,doNotScrollX:!0}),K({col:P.length-(F?3:2),row:a.row,doNotScrollX:!0})):i(o,[{type:`UPDATE`,fromRowIndex:r.row,toRowIndex:a.row+1}])},[U,P,e,it,X,i,q?.max,q?.min,W,K,F]),ot=(0,c.useCallback)(({nextRow:e=!0}={})=>{U?.row===Y.current.length-1?e&&_?Z(U.row):H(!1):(H(!1),e&&W(e=>e&&{col:e.col,row:e.row+1}))},[U?.row,_,Z,W]),st=(0,c.useCallback)(async t=>{if(!V&&U){let n=[],r=q?.min||U,i=q?.max||U;for(let t=r.row;t<=i.row;++t){n.push([]);for(let a=r.col;a<=i.col;++a){let{copyValue:i=()=>null}=P[a+1];n[t-r.row].push(i({rowData:e[t],rowIndex:t}))}}let a=n.map(e=>e.map(e=>le(String(e??``))).join(` `)).join(`
|
|
5
|
+
`&&!a&&(s(),n.push([]),i=r+1,o++),r++;return s(),n},le=e=>/[\t\n\r"]/.test(e)?`"${e.replaceAll(`"`,`""`)}"`:e,ue=e=>e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`).replaceAll(`'`,`'`),de=e=>/^[^\x00-\x20\x7F-\x9F]$/.exec(e)!==null,fe=(e,t,n,r)=>{if(e===null||!t||!n)return null;if(typeof e!=`object`)throw TypeError(`Value must be an object or null`);let i=r.findIndex(t=>t.id===e.col),a={col:Math.max(0,Math.min(t-1,i===-1?Number(e.col):i-1)),row:Math.max(0,Math.min(n-1,Number(e.row)))};if(isNaN(a.col)||isNaN(a.row))throw TypeError(`col or cell are not valid positive numbers`);return a},pe=(e,t)=>e?{col:e.col,row:e.row,colId:t[e.col+1]?.id}:null,me=(e,t,n,r)=>{if(e===null||!t||!n)return null;if(typeof e!=`object`)throw TypeError(`Value must be an object or null`);let i={min:fe(e.min,t,n,r),max:fe(e.max,t,n,r)};if(!i.min||!i.max)throw Error(`min and max must be defined`);return i},he=(e,t)=>e?{min:pe(e.min,t),max:pe(e.max,t)}:null,ge=()=>Array.from(document.querySelectorAll(`*`)).filter(e=>e instanceof HTMLElement&&typeof e.tabIndex==`number`&&e.tabIndex>=0&&!e.disabled&&(!(e instanceof HTMLAnchorElement)||!!e.href||e.getAttribute(`tabIndex`)!==null)&&getComputedStyle(e).visibility!==`collapse`),_e=(e,t)=>e.key?.toLowerCase()===t,ve=e=>(e.ctrlKey||e.metaKey)&&!e.shiftKey&&!e.altKey&&_e(e,`z`),ye=e=>!e.altKey&&(e.ctrlKey&&!e.shiftKey&&_e(e,`y`)||(e.ctrlKey||e.metaKey)&&e.shiftKey&&_e(e,`z`)),be=({children:e,gutter:t,stickyRight:n,stickyLeft:r,active:i,disabled:a,className:o,width:s,left:c})=>(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-cell`,t&&`dsg-cell-gutter`,a&&`dsg-cell-disabled`,t&&i&&`dsg-cell-gutter-active`,n&&`dsg-cell-sticky-right`,r&&`dsg-cell-sticky-left`,o),style:{width:s,left:n?void 0:c},children:e}),xe=(e,t)=>(0,c.useMemo)(()=>{let n=new Map;return r=>(n.has(r)||n.set(r,(...n)=>{e(r,...n.slice(0,t))}),n.get(r))},[t,e]),Se=({data:e,columns:t,outerRef:n,innerRef:r,columnWidths:i,hasStickyRightColumn:a,pinFirstColumn:o,displayHeight:s,headerRowHeight:l,rowHeight:d,getRowSize:f,rowKey:p,fullWidth:g,selection:_,activeCell:v,rowClassName:y,cellClassName:b,children:x,editing:S,getContextMenuItems:C,setRowData:w,deleteRows:T,duplicateRows:E,insertRowAfter:ee,stopEditing:D,onScroll:te})=>{let O=(0,c.useCallback)(t=>{if(p&&t>0){let n=e[t-1];if(typeof p==`function`)return p({rowData:n,rowIndex:t});if(typeof p==`string`&&n instanceof Object&&p in n){let e=n[p];if(typeof e==`string`||typeof e==`number`)return e}}return t},[e,p]),k=(0,m.useVirtualizer)({count:e.length,getScrollElement:()=>n.current,paddingStart:l,estimateSize:e=>f(e).height,getItemKey:O,overscan:5}),A=(0,m.useVirtualizer)({count:t.length,getScrollElement:()=>n.current,estimateSize:e=>i?.[e]??100,horizontal:!0,getItemKey:e=>t[e].id??e,overscan:1,rangeExtractor:e=>{let n=(0,m.defaultRangeExtractor)(e);if(n[0]!==0&&n.unshift(0),(o||t[1]?.stickyLeft)&&t.length>1&&!n.includes(1)){let e=n.findIndex(e=>e>1);e===-1?n.push(1):n.splice(e,0,1)}return a&&n.at(-1)!==t.length-1&&n.push(t.length-1),n}});(0,c.useEffect)(()=>{A.measure()},[A,i]),(0,c.useEffect)(()=>{k.measure()},[k,d]);let ne=xe(w,1),re=xe(T,0),ie=xe(E,0),j=xe(ee,0),M=e=>{if(!t[e].stickyLeft)return 0;if(!i?.length){let t=A.getOffsetForIndex(e);return typeof t==`number`?t:0}let n=0;for(let t=0;t<e;t++)n+=i[t];return n},ae=_?.min.col??v?.col,oe=_?.max.col??v?.col,se=_?.min.row??v?.row,ce=_?.max.row??v?.row;return(0,u.jsx)(`div`,{ref:n,className:`dsg-container`,onScroll:te,style:{height:s},children:(0,u.jsxs)(`div`,{ref:r,style:{width:g?`100%`:A.getTotalSize(),height:k.getTotalSize()},children:[l>0&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,`dsg-row-header`),style:{width:g?`100%`:A.getTotalSize(),height:l},children:A.getVirtualItems().map(e=>{let n=!!t[e.index].stickyLeft;return(0,u.jsx)(be,{gutter:e.index===0,stickyRight:a&&e.index===t.length-1,stickyLeft:n,width:e.size,left:n?M(e.index):e.start,className:(0,h.default)(`dsg-cell-header`,ae!==void 0&&oe!==void 0&&ae<=e.index-1&&oe>=e.index-1&&`dsg-cell-header-active`,t[e.index].headerClassName),children:(0,u.jsx)(`div`,{className:`dsg-cell-header-container`,children:t[e.index].title})},e.key)})}),k.getVirtualItems().map(n=>{let r=n.index>=(se??1/0)&&n.index<=(ce??-1/0);return(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,typeof y==`string`?y:null,typeof y==`function`?y({rowData:e[n.index],rowIndex:n.index}):null),style:{height:n.size,top:n.start,width:g?`100%`:A.getTotalSize()},children:A.getVirtualItems().map(i=>{let o=t[i.index].cellClassName,s=t[i.index].disabled,c=t[i.index].component,l=s===!0||typeof s==`function`&&s({rowData:e[n.index],rowIndex:n.index}),d=v?.row===n.index&&v.col===i.index-1,f=!!t[i.index].stickyLeft;return(0,u.jsx)(be,{gutter:i.index===0,stickyRight:a&&i.index===t.length-1,stickyLeft:f,active:i.index===0&&r,disabled:l,className:(0,h.default)(typeof o==`function`?o({rowData:e[n.index],rowIndex:n.index,columnId:t[i.index].id}):o,typeof b==`function`?b({rowData:e[n.index],rowIndex:n.index,columnId:t[i.index].id}):b),width:i.size,left:f?M(i.index):i.start,children:(0,u.jsx)(c,{rowData:e[n.index],getContextMenuItems:C,disabled:l,active:d,columnIndex:i.index-1,rowIndex:n.index,focus:d&&S,deleteRow:re(n.index),duplicateRow:ie(n.index),stopEditing:D,insertRowBelow:j(n.index),setRowData:ne(n.index),columnData:t[i.index].columnData})},i.key)})},n.key)}),x]})})},Ce=(e,t,n,r)=>[[r,e],[t,e],[t,n],[r,n],[r,e]],N=(e,t,n,r)=>`polygon(evenodd, ${[...Ce(0,`100%`,`100%`,0),...Ce(e,t,n,r)].map(e=>e.map(e=>typeof e==`number`&&e!==0?e+`px`:e).join(` `)).join(`,`)})`,we=c.default.memo(({columnWidths:e,columnRights:t,headerRowHeight:n,selection:r,rowHeight:i,activeCell:a,hasStickyRightColumn:o,dataLength:s,viewWidth:l,viewHeight:d,contentWidth:f,edges:p,isCellDisabled:m,editing:g,expandSelection:_,stickyLeftColumns:v,getStickyLeftOffset:y})=>{let b=a?m(a):!1,x=(0,c.useMemo)(()=>{if(!r)return b;for(let e=r.min.col;e<=r.max.col;++e)for(let t=r.min.row;t<=r.max.row;++t)if(!m({col:e,row:t}))return!1;return!0},[b,m,r]);if(!e||!t)return null;let S=e=>+(e<s-1),C=t=>+(t<e.length-(o?3:2)),w=a&&{width:e[a.col+1]+C(a.col),height:i(a.row).height+S(a.row),left:t[a.col],top:i(a.row).top+n},T=r&&{width:e.slice(r.min.col+1,r.max.col+2).reduce((e,t)=>e+t)+C(r.max.col),height:i(r.max.row).top+i(r.max.row).height-i(r.min.row).top+S(r.max.row),left:t[r.min.col],top:i(r.min.row).top+n},E=a&&v&&y&&v[a.col],ee=E&&y?y(a.col+1):0,D=r&&v&&y&&(()=>{for(let e=r.min.col;e<=r.max.col;e++)if(!v[e])return!1;return!0})(),te=D&&r&&y?y(r.min.col+1):0,O=r?.min||a,k=r?.max||a,A=k&&v&&y&&v[k.col],ne=A&&k&&y?y(k.col+1)+e[k.col+1]:0,re=r&&v?.[r.min.col]||a&&v?.[a.col],ie=re&&y?y((r?.min.col??a?.col??0)+1):0,j=k&&_!==null&&{left:t[k.col]+e[k.col+1],top:i(k.row).top+i(k.row).height+n,transform:`translate(-${k.col<e.length-(o?3:2)?50:100}%, -${k.row<s-1?50:100}%)`},M=O&&k&&_!==null&&{width:e.slice(O.col+1,k.col+2).reduce((e,t)=>e+t)+C(k.col),height:i(k.row+_).top+i(k.row+_).height-i(k.row+1).top+S(k.row+_)-1,left:t[O.col],top:i(k.row).top+i(k.row).height+n+1},ae=o?e.at(-1):0;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{className:`dsg-scrollable-view-container`,style:{height:i(s-1).top+i(s-1).height+n,width:f||`100%`},children:(0,u.jsx)(`div`,{className:(0,h.default)({"dsg-scrollable-view":!0,"dsg-scrollable-view-t":!p.top,"dsg-scrollable-view-r":!p.right,"dsg-scrollable-view-b":!p.bottom,"dsg-scrollable-view-l":!p.left}),style:{top:n,left:e[0],height:d?d-n:0,width:f&&l?l-e[0]-ae:`calc(100% - ${e[0]+ae}px)`}})}),(T||w)&&!re&&(0,u.jsx)(`div`,{className:`dsg-selection-col-marker-container`,style:{left:T?.left??w?.left,width:T?.width??w?.width,height:i(s-1).top+i(s-1).height+n},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker`,x&&`dsg-selection-col-marker-disabled`),style:{top:n}})}),(T||w)&&re&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker-container`,`dsg-selection-col-marker-container-sticky`),style:{position:`sticky`,left:ie,top:`auto`,width:T?.width??w?.width,height:i(s-1).top+i(s-1).height+n},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker`,x&&`dsg-selection-col-marker-disabled`),style:{top:n}})}),(T||w)&&(0,u.jsx)(`div`,{className:`dsg-selection-row-marker-container`,style:{top:T?.top??w?.top,height:T?.height??w?.height,width:f||`100%`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-row-marker`,x&&`dsg-selection-row-marker-disabled`),style:{left:e[0]}})}),w&&a&&!E&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-active-cell`,{"dsg-active-cell-focus":g,"dsg-active-cell-disabled":b}),style:w}),w&&a&&E&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:w.top,left:0,right:0,height:w.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-active-cell`,{"dsg-active-cell-focus":g,"dsg-active-cell-disabled":b,"dsg-active-cell-sticky":!0}),style:{position:`sticky`,left:ee,width:w.width,height:`100%`}})}),T&&w&&!D&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-rect`,x&&`dsg-selection-rect-disabled`),style:{...T,clipPath:N(w.top-T.top,w.left-T.left,w.top+w.height-T.top,w.left+w.width-T.left)}}),T&&w&&D&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:T.top,left:0,right:0,height:T.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-rect`,x&&`dsg-selection-rect-disabled`,`dsg-selection-rect-sticky`),style:{position:`sticky`,left:te,width:T.width,height:`100%`,background:`var(--dsg-selection-background-color)`,clipPath:N(w.top-T.top,ee-te,w.top+w.height-T.top,ee+w.width-te)}})}),M&&!D&&(0,u.jsx)(`div`,{className:`dsg-expand-rows-rect`,style:M}),M&&D&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:M.top,left:0,right:0,height:M.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-rect`,`dsg-expand-rows-rect-sticky`),style:{position:`sticky`,left:te,width:M.width,height:`100%`}})}),j&&!A&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-indicator`,x&&`dsg-expand-rows-indicator-disabled`),style:j}),j&&A&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:j.top,left:0,right:0,height:0,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-indicator`,x&&`dsg-expand-rows-indicator-disabled`,`dsg-expand-rows-indicator-sticky`),style:{position:`sticky`,left:ne,transform:j.transform,pointerEvents:`auto`}})})]})});we.displayName=`SelectionRect`;var Te=({value:e,rowHeight:t})=>{let n=(0,c.useRef)([]),[,r]=(0,c.useState)(0);return(0,c.useMemo)(()=>{let i=r=>{if(typeof t==`number`)return Math.min(e.length-1,Math.max(-1,Math.floor(r/t)));let i=0,a=n.current.length-1;for(;i<=a;){let e=Math.floor((i+a)/2);if(n.current[e].top<r)i=e+1;else if(n.current[e].top>r)a=e-1;else return e}if(a===n.current.length-1&&e.length>n.current.length&&(!n.current.length||r>=n.current[a].top+n.current[a].height)){let i=a===-1?0:n.current[a].top+n.current[a].height;do{a++;let r=t({rowIndex:a,rowData:e[a]});n.current.push({height:r,top:i}),i+=r}while(i<=r&&a<n.current.length-1)}return a};return{resetAfter:e=>{n.current=n.current.slice(0,e),r(e=>e+1)},getRowSize:r=>{if(typeof t==`number`)return{height:t,top:t*r};if(r>=e.length)return{height:0,top:0};if(r<n.current.length)return n.current[r];let i=n.current.at(-1),a=i?i.top+i.height:0;for(let i=n.current.length;i<=r;i++){let r=t({rowIndex:i,rowData:e[i]});n.current.push({height:r,top:a}),a+=r}return n.current[r]},getRowIndex:i,totalSize:r=>{if(typeof t==`number`)return e.length*t;let a=i(r);return n.current[a].top+n.current[a].height}}},[t,e])},Ee=[],De=[],Oe=()=>({}),ke=()=>null,Ae=({rowData:e})=>({...e}),je=c.default.memo(c.default.forwardRef(({value:e=Ee,className:t,style:n,height:r=400,onChange:i=ke,columns:a=De,rowHeight:o=40,headerRowHeight:s=typeof o==`number`?o:40,gutterColumn:d,stickyRightColumn:p,rowKey:m,addRowsComponent:h=ne,createRow:g=Oe,autoAddRow:_=!1,lockRows:y=!1,disableExpandSelection:b=!1,disableSmartDelete:x=!1,duplicateRow:S=Ae,contextMenuComponent:C=M,disableContextMenu:w=!1,onFocus:T=ke,onBlur:E=ke,onActiveCellChange:A=ke,onSelectionChange:ie=ke,rowClassName:j,cellClassName:ae,onScroll:oe,pinFirstColumn:_e=!1,onUndo:be,onRedo:xe},Ce)=>{let N=(0,c.useRef)(null),je=w||y,P=ee(a,d,p,_e),F=!!p,Me=_e||!!P[1]?.stickyLeft,Ne=(0,c.useRef)(null),I=(0,c.useRef)(null),Pe=(0,c.useRef)(null),Fe=(0,c.useRef)(null),[Ie,Le]=re(1,100),{getRowSize:Re,totalSize:ze,getRowIndex:Be}=Te({value:e,rowHeight:o}),Ve=Math.min(r,s+ze(r)+Ie),{width:He,height:L}=(0,l.useResizeDetector)({targetRef:I,refreshMode:`throttle`,refreshRate:100});Le(L?Ve-L:0);let Ue=te(I,He,L),{fullWidth:We,totalWidth:Ge,columnWidths:R,columnRights:z}=v(P,He),Ke=(0,c.useMemo)(()=>P.slice(1).map(e=>!!e.stickyLeft),[P]),qe=(0,c.useCallback)(e=>{if(!P[e]?.stickyLeft)return 0;if(!R?.length){let t=0;for(let n=0;n<e;n++)(P[n].stickyLeft||n===0)&&(t+=P[n].basis||P[n].minWidth||100);return t}let t=0;for(let n=0;n<e;n++)(P[n].stickyLeft||n===0)&&(t+=R[n]);return t},[P,R]),[Je,B]=(0,c.useState)(null),[Ye,Xe]=(0,c.useState)([]),[V,H]=(0,c.useState)(!1),[Ze,Qe]=(0,c.useState)(0),[$e,et]=(0,c.useState)(null),[U,W]=D(null),[G,K]=D(null),q=(0,c.useMemo)(()=>U&&G&&{min:{col:Math.min(U.col,G.col),row:Math.min(U.row,G.row)},max:{col:Math.max(U.col,G.col),row:Math.max(U.row,G.row)}},[U,G]),[J,tt]=D({columns:!1,rows:!1,active:!1}),nt=b||V||J.active||U?.row===e?.length-1||q?.max.row===e?.length-1||U&&P.slice((q?.min.col??U.col)+1,(q?.max.col??U.col)+2).every(e=>e.disabled===!0)?null:Ze,rt=k(Ne),it=k(I);(0,c.useEffect)(()=>{U!==null&&(document.activeElement.blur(),window.getSelection()?.removeAllRanges())},[U!==null]);let at=(0,c.useCallback)((e,t=!1,n=!1)=>{let r=rt(t),i=n&&it(t);if(r&&z&&R){let t=e.clientX-r.left,n=e.clientY-r.top;return i&&(e.clientY-i.top<=s&&(n=0),e.clientX-i.left<=R[0]&&(t=0),Me&&e.clientX-i.left<=R[0]+R[1]&&(t=z[0]+1),F&&i.right-e.clientX<=R.at(-1)&&(t=z.at(-2)+1)),{col:z.findIndex(e=>t<e)-1,row:Be(n-s)}}return null},[z,R,e.length,rt,it,s,F,Me,Be]),Y=(0,c.useRef)(e);Y.current=e;let X=(0,c.useCallback)(e=>{let t=P[e.col+1].disabled;return!!(typeof t==`function`?t({rowData:Y.current[e.row],rowIndex:e.row}):t)},[P]),Z=(0,c.useCallback)((e,t=1)=>{y||(K(null),H(!1),i([...Y.current.slice(0,e+1),...Array(t).fill(0).map(g),...Y.current.slice(e+1)],[{type:`CREATE`,fromRowIndex:e+1,toRowIndex:e+1+t}]),W(n=>({col:n?.col||0,row:e+t,doNotScrollX:!0})))},[g,y,i,W,K]),ot=(0,c.useCallback)((e,t=e)=>{y||(i([...Y.current.slice(0,t+1),...Y.current.slice(e,t+1).map((t,n)=>S({rowData:t,rowIndex:n+e})),...Y.current.slice(t+1)],[{type:`CREATE`,fromRowIndex:t+1,toRowIndex:t+2+t-e}]),W({col:0,row:t+1,doNotScrollX:!0}),K({col:P.length-(F?3:2),row:2*t-e+1,doNotScrollX:!0}),H(!1))},[P.length,S,y,i,W,K,F]),Q=(0,c.useCallback)(e=>{if(L&&He){if(!e.doNotScrollY){let t=Re(e.row).top,n=Re(e.row).top+Re(e.row).height+s-L+1,r=I.current.scrollTop;r>t?I.current.scrollTop=t:r<n&&(I.current.scrollTop=n)}if(z&&R&&I.current&&!e.doNotScrollX){let t=z[e.col]-z[0],n=z[e.col]+R[e.col+1]+(F?R.at(-1):0)-He+1,r=I.current.scrollLeft;r>t?I.current.scrollLeft=t:r<n&&(I.current.scrollLeft=n)}}},[L,He,s,z,R,Re,F]);(0,c.useEffect)(()=>{G&&Q(G)},[G,Q]),(0,c.useEffect)(()=>{U&&Q(U)},[U,Q]);let st=(0,c.useCallback)((e,t)=>{i([...Y.current.slice(0,e),t,...Y.current.slice(e+1)],[{type:`UPDATE`,fromRowIndex:e,toRowIndex:e+1}])},[i]),ct=(0,c.useCallback)((e,t=e)=>{y||(H(!1),W(n=>{let r=Math.min(Y.current.length-2-t+e,e);return r<0?null:n&&{col:n.col,row:r}}),K(null),i([...Y.current.slice(0,e),...Y.current.slice(t+1)],[{type:`DELETE`,fromRowIndex:e,toRowIndex:t+1}]))},[y,i,W,K]),lt=(0,c.useCallback)((t=!0)=>{let n=t&&!x;if(!U)return;let r=q?.min||U,a=q?.max||U;if(e.slice(r.row,a.row+1).every((e,t)=>P.every(n=>n.isCellEmpty({rowData:e,rowIndex:t+r.row})))){n&&ct(r.row,a.row);return}let o=[...e];for(let e=r.row;e<=a.row;++e)for(let t=r.col;t<=a.col;++t)if(!X({col:t,row:e})){let{deleteValue:n=({rowData:e})=>e}=P[t+1];o[e]=n({rowData:o[e],rowIndex:e})}n&&(0,f.default)(o,e)?(W({col:0,row:r.row,doNotScrollX:!0}),K({col:P.length-(F?3:2),row:a.row,doNotScrollX:!0})):i(o,[{type:`UPDATE`,fromRowIndex:r.row,toRowIndex:a.row+1}])},[U,P,e,ct,X,i,q?.max,q?.min,W,K,F]),ut=(0,c.useCallback)(({nextRow:e=!0}={})=>{U?.row===Y.current.length-1?e&&_?Z(U.row):H(!1):(H(!1),e&&W(e=>e&&{col:e.col,row:e.row+1}))},[U?.row,_,Z,W]),dt=(0,c.useCallback)(async t=>{if(!V&&U){let n=[],r=q?.min||U,i=q?.max||U;for(let t=r.row;t<=i.row;++t){n.push([]);for(let a=r.col;a<=i.col;++a){let{copyValue:i=()=>null}=P[a+1];n[t-r.row].push(i({rowData:e[t],rowIndex:t}))}}let a=n.map(e=>e.map(e=>le(String(e??``))).join(` `)).join(`
|
|
6
6
|
`),o=`<table>${n.map(e=>`<tr>${e.map(e=>`<td>${ue(String(e??``)).replaceAll(`
|
|
7
|
-
`,`<br/>`)}</td>`).join(``)}</tr>`).join(``)}</table>`;if(t!==void 0){t.clipboardData?.setData(`text/plain`,a),t.clipboardData?.setData(`text/html`,o),t.preventDefault();return}let s=!1;if(navigator.clipboard.write!==void 0){let e=new Blob([a],{type:`text/plain`}),t=new Blob([o],{type:`text/html`}),n=[new ClipboardItem({"text/plain":e,"text/html":t})];await navigator.clipboard.write(n).then(()=>{s=!0})}else navigator.clipboard.writeText===void 0?document.execCommand!==void 0&&document.execCommand(`copy`)&&(s=!0):await navigator.clipboard.writeText(a).then(()=>{s=!0});s||alert(`This action is unavailable in your browser, but you can still use Ctrl+C for copy or Ctrl+X for cut`)}},[U,P,e,V,q]);O(`copy`,st);let ct=(0,c.useCallback)(e=>{!V&&U&&(st(e),at(!1))},[U,at,V,st]);O(`cut`,ct);let lt=(0,c.useCallback)(async t=>{if(!V&&U){let n=q?.min||U,r=q?.max||U,a=await Promise.all(t[0].map((e,r)=>{let i=P[n.col+r+1]?.prePasteValues,a=t.map(e=>e[r]);return Promise.resolve(i?.(a)??a)}));if(t=t.map((e,t)=>a.map(e=>e[t])),t.length===1){let a=[...e];for(let e=0;e<t[0].length;e++){let i=P[n.col+e+1]?.pasteValue;if(i)for(let o=n.row;o<=r.row;o++)X({col:e+n.col,row:o})||(a[o]=await i({rowData:a[o],value:t[0][e],rowIndex:o}))}i(a,[{type:`UPDATE`,fromRowIndex:n.row,toRowIndex:r.row+1}]),W({col:n.col,row:n.row}),K({col:Math.min(n.col+t[0].length-1,P.length-(F?3:2)),row:r.row})}else{let r=[...e],a=n.row+t.length-e.length;a>0&&(y?t.splice(t.length-a,a):r=[...r,...Array(a).fill(0).map(()=>g())]);for(let e=0;e<t[0].length&&n.col+e<P.length-(F?2:1);e++){let i=P[n.col+e+1]?.pasteValue;if(i)for(let a=0;a<t.length;a++)X({col:n.col+e,row:n.row+a})||(r[n.row+a]=await i({rowData:r[n.row+a],value:t[a][e],rowIndex:n.row+a}))}let o=[{type:`UPDATE`,fromRowIndex:n.row,toRowIndex:n.row+t.length-(!y&&a>0?a:0)}];a>0&&!y&&o.push({type:`CREATE`,fromRowIndex:n.row+t.length-a,toRowIndex:n.row+t.length}),i(r,o),W({col:n.col,row:n.row}),K({col:Math.min(n.col+t[0].length-1,P.length-(F?3:2)),row:n.row+t.length-1})}}},[U,P,g,e,V,F,X,y,i,q?.max,q?.min,W,K]);O(`paste`,(0,c.useCallback)(e=>{if(U&&!V){let t=[[``]];e.clipboardData?.types.includes(`text/html`)?t=se(e.clipboardData?.getData(`text/html`)):e.clipboardData?.types.includes(`text/plain`)?t=ce(e.clipboardData?.getData(`text/plain`)):e.clipboardData?.types.includes(`text`)&&(t=ce(e.clipboardData?.getData(`text`))),lt(t),e.preventDefault()}},[U,lt,V])),O(`mousedown`,(0,c.useCallback)(t=>{if(We&&Ge.length)return;let n=t.button===2||t.button===0&&t.ctrlKey,r=ke.current?.contains(t.target)||!1,i=r?tt(t,!0,!0):null;if(!r&&V&&U&&P[U.col+1].keepFocus)return;if(t.target instanceof HTMLElement&&t.target.className.includes(`dsg-expand-rows-indicator`)){Xe(Math.max(U?.row??0,q?.max.row??0));return}let a=i&&U&&U.col===i.col&&U.row===i.row&&!X(U),o=V&&t.target instanceof HTMLElement&&t.target.classList.contains(`dsg-input`);if((a||o)&&V)return;let s=i?.col===P.length-2&&F,c=n&&q&&i&&i.row>=q.min.row&&i.row<=q.max.row&&i.col>=q.min.col&&i.col<=q.max.col,l=n&&q&&i?.row===-1&&i.col>=q.min.col&&i.col<=q.max.col,u=n&&q&&i&&i.row>=q.min.row&&i.row<=q.max.row&&i.col===-1,d=s&&q&&i&&i.row>=q.min.row&&i.row<=q.max.row;if(n&&!be&&B({x:t.clientX,y:t.clientY,cursorIndex:i}),(!(t.shiftKey&&U)||n)&&e.length>0&&W(i&&{col:(c||l)&&U?U.col:Math.max(0,s?0:i.col),row:(c||u||d)&&U?U.row:Math.max(0,i.row),doNotScrollX:!!(c&&U||s||i.col===-1),doNotScrollY:!!(c&&U||i.row===-1)}),a&&!n&&(N.current=U),H(!(!a||n)),Ze(i&&!n?{columns:i.col!==-1&&!s||!!(t.shiftKey&&U),rows:i.row!==-1||!!(t.shiftKey&&U),active:!0}:{columns:!1,rows:!1,active:!1}),t.shiftKey&&U&&!n)K(i&&{col:Math.max(0,i.col-+!!s),row:Math.max(0,i.row)});else if(!c){if(i&&(i?.col===-1||i?.row===-1||s)){let t=i.col,n=i.row,r=!1,a=!1;(i.col===-1||s)&&(t=P.length-(F?3:2),r=!0),i.row===-1&&(n=e.length-1,a=!0),l&&G&&(t=G.col,a=!0),(u||d)&&G&&(n=G.row,r=!0),K({col:t,row:n,doNotScrollX:r,doNotScrollY:a})}else K(null);r&&t.preventDefault()}},[We,Ge.length,tt,V,U,P,X,q,F,be,Ze,W,K,G,e.length])),O(`mouseup`,(0,c.useCallback)(()=>{if(Ye!==null){if(qe>0&&U){let t=[],n=q?.min||U,r=q?.max||U;for(let i=n.row;i<=r.row;++i){t.push([]);for(let a=n.col;a<=r.col;++a){let{copyValue:r=()=>null}=P[a+1];t[i-n.row].push(String(r({rowData:e[i],rowIndex:i})??``))}}Promise.all(t[0].map((e,r)=>{let i=P[n.col+r+1]?.prePasteValues,a=t.map(e=>e[r]);return Promise.resolve(i?.(a)??a)})).then(a=>{t=t.map((e,t)=>a.map(e=>e[t]));let o=[...e];for(let e=0;e<t[0].length;e++){let i=P[n.col+e+1]?.pasteValue;if(i)for(let a=r.row+1;a<=r.row+qe;a++)X({col:e+n.col,row:a})||(o[a]=i({rowData:o[a],value:t[(a-r.row-1)%t.length][e],rowIndex:a}))}i(o,[{type:`UPDATE`,fromRowIndex:r.row+1,toRowIndex:r.row+1+qe}])}),Je(0),W({col:Math.min(U?.col??1/0,q?.min.col??1/0),row:Math.min(U?.row??1/0,q?.min.row??1/0),doNotScrollX:!0,doNotScrollY:!0}),K({col:Math.max(U?.col??0,q?.max.col??0),row:Math.max(U?.row??0,q?.max.row??0)+qe})}Xe(null)}Ze({columns:!1,rows:!1,active:!1})},[Ye,Ze,qe,U,q?.min,q?.max,e,i,W,K,P,X])),O(`mousemove`,(0,c.useCallback)(t=>{if(Ye!==null){let e=tt(t);e&&(Je(Math.max(0,e.row-Ye)),Q({col:e.col,row:Math.max(e.row,Ye)}))}if(J.active){let n=tt(t),r=P.length-(F?3:2);K(n&&{col:J.columns?Math.max(0,Math.min(r,n.col)):r,row:J.rows?Math.max(0,n.row):e.length-1,doNotScrollX:!J.columns,doNotScrollY:!J.rows}),H(!1)}},[Q,J.active,J.columns,J.rows,tt,P.length,F,K,e.length,Ye])),O(`keydown`,(0,c.useCallback)(t=>{if(U&&!t.isComposing){if(t.key===`Tab`&&!t.shiftKey&&U.col===P.length-(F?3:2)&&!P[U.col+1].disableKeys){if(U.row===e.length-1){if(je.current){t.preventDefault(),W(null),K(null),H(!1);let e=ge();e[(e.indexOf(je.current)+1)%e.length].focus();return}}else{W(e=>({col:0,row:(e?.row??0)+1})),K(null),H(!1),t.preventDefault();return}}if(t.key===`Tab`&&t.shiftKey&&U.col===0&&!P[U.col+1].disableKeys){if(U.row===0){if(Ae.current){t.preventDefault(),W(null),K(null),H(!1);let e=ge();e[(e.indexOf(Ae.current)-1+e.length)%e.length].focus();return}}else{W(e=>({col:P.length-(F?3:2),row:(e?.row??1)-1})),K(null),H(!1),t.preventDefault();return}}if(t.key?.startsWith(`Arrow`)||t.key===`Tab`){if(V&&P[U.col+1].disableKeys||V&&[`ArrowLeft`,`ArrowRight`].includes(t.key))return;let n=([t,n],r)=>r&&{col:Math.max(0,Math.min(P.length-(F?3:2),r.col+t)),row:Math.max(0,Math.min(e.length-1,r.row+n))};if(t.key===`Tab`&&t.shiftKey)W(e=>n([-1,0],e)),K(null);else{let r={ArrowDown:[0,1],ArrowUp:[0,-1],ArrowLeft:[-1,0],ArrowRight:[1,0],Tab:[1,0]}[t.key];(t.ctrlKey||t.metaKey)&&(r[0]*=P.length,r[1]*=e.length),t.shiftKey?K(e=>n(r,e||U)):(W(e=>n(r,e)),K(null))}H(!1),t.preventDefault()}else t.key===`Escape`?(!V&&!G&&W(null),K(null),H(!1)):(t.key===`Enter`||t.key===`F2`)&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&!t.shiftKey?(K(null),V?P[U.col+1].disableKeys||(ot(),t.preventDefault()):X(U)||(N.current=U,H(!0),Q(U),t.preventDefault())):t.key===`Enter`&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&t.shiftKey&&!V?Z(q?.max.row||U.row):t.key===`d`&&(t.ctrlKey||t.metaKey)&&!t.altKey&&!t.shiftKey?(nt(q?.min.row||U.row,q?.max.row),t.preventDefault()):(de(t.key)||/Key[A-Z]$/.exec(t.code))&&!t.ctrlKey&&!t.metaKey&&!t.altKey?!V&&!X(U)&&(N.current=U,K(null),H(!0),Q(U)):[`Backspace`,`Delete`].includes(t.key)?V||(at(),t.preventDefault()):t.key===`a`&&(t.ctrlKey||t.metaKey)&&(V||(W({col:0,row:0,doNotScrollY:!0,doNotScrollX:!0}),K({col:P.length-(F?3:2),row:e.length-1,doNotScrollY:!0,doNotScrollX:!0}),t.preventDefault()))}},[U,P,e.length,at,nt,V,Z,X,Q,q?.max.row,q?.min.row,G,W,K,ot,F])),O(`contextmenu`,(0,c.useCallback)(e=>{let t=ke.current?.contains(e.target)||!1,n=t?tt(e,!0,!0):null,r=n&&U&&U.col===n.col&&U.row===n.row&&V;t&&!r&&e.preventDefault()},[tt,U,V])),(0,c.useEffect)(()=>{let e=[];U?.row!==void 0&&e.push({type:`COPY`,action:()=>{st(),B(null)}},{type:`CUT`,action:()=>{ct(),B(null)}},{type:`PASTE`,action:()=>{(async()=>{if(navigator.clipboard.read!==void 0){let e=await navigator.clipboard.read();for(let t of e){let e=[[``]];t.types.includes(`text/html`)?e=se(await(await t.getType(`text/html`)).text()):t.types.includes(`text/plain`)?e=ce(await(await t.getType(`text/plain`)).text()):t.types.includes(`text`)&&(e=se(await(await t.getType(`text`)).text())),await lt(e)}}else if(navigator.clipboard.readText!==void 0){let e=await navigator.clipboard.readText();await lt(ce(e))}else alert(`This action is unavailable in your browser, but you can still use Ctrl+V for paste`);B(null)})()}}),q?.max.row===void 0?U?.row!==void 0&&e.push({type:`INSERT_ROW_BELLOW`,action:()=>{B(null),Z(U.row)}}):e.push({type:`INSERT_ROW_BELLOW`,action:()=>{B(null),Z(q.max.row)}}),q?.min.row!==void 0&&q.min.row!==q.max.row?e.push({type:`DUPLICATE_ROWS`,fromRow:q.min.row+1,toRow:q.max.row+1,action:()=>{B(null),nt(q.min.row,q.max.row)}}):U?.row!==void 0&&e.push({type:`DUPLICATE_ROW`,action:()=>{B(null),nt(U.row)}}),q?.min.row!==void 0&&q.min.row!==q.max.row?e.push({type:`DELETE_ROWS`,fromRow:q.min.row+1,toRow:q.max.row+1,action:()=>{B(null),it(q.min.row,q.max.row)}}):U?.row!==void 0&&e.push({type:`DELETE_ROW`,action:()=>{B(null),it(U.row)}}),Ke(e),e.length||B(null)},[q,U,it,nt,Z,ct,st,lt]);let ut=(0,c.useRef)(Ge);ut.current=Ge;let dt=(0,c.useCallback)(()=>ut.current,[]);(0,c.useImperativeHandle)(ve,()=>({activeCell:pe(U,P),selection:he(q??(U?{min:U,max:U}:null),P),setSelection:t=>{let n=me(t,P.length-(F?2:1),e.length,P);W(n?.min||null),H(!1),Ze({columns:!1,active:!1,rows:!1}),K(n?.max||null)},setActiveCell:t=>{let n=fe(t,P.length-(F?2:1),e.length,P);W(n),H(!1),Ze({columns:!1,active:!1,rows:!1}),K(null)}}));let $=(0,c.useRef)({onFocus:T,onBlur:E,onActiveCellChange:A,onSelectionChange:ie});return $.current.onFocus=T,$.current.onBlur=E,$.current.onActiveCellChange=A,$.current.onSelectionChange=ie,(0,c.useEffect)(()=>{N.current&&(V?$.current.onFocus({cell:pe(N.current,P)}):$.current.onBlur({cell:pe(N.current,P)}))},[V,P]),(0,c.useEffect)(()=>{$.current.onActiveCellChange({cell:pe(U,P)})},[U?.col,U?.row,P]),(0,c.useEffect)(()=>{$.current.onSelectionChange({selection:he(q??(U?{min:U,max:U}:null),P)})},[q?.min.col??U?.col,q?.min.row??U?.row,q?.max.col??U?.col,q?.max.row??U?.row,U?.col,U?.row,P]),(0,u.jsxs)(`div`,{className:t,style:n,children:[(0,u.jsx)(`div`,{ref:Ae,tabIndex:a.length&&e.length?0:void 0,onFocus:e=>{e.target.blur(),W({col:0,row:0})}}),(0,u.jsx)(ye,{columns:P,outerRef:I,columnWidths:R,hasStickyRightColumn:F,pinFirstColumn:_e,displayHeight:Le,data:e,fullWidth:Be,headerRowHeight:s,activeCell:U,innerRef:ke,rowHeight:o,getRowSize:Pe,rowKey:m,selection:q,rowClassName:j,editing:V,getContextMenuItems:dt,setRowData:rt,deleteRows:it,insertRowAfter:Z,duplicateRows:nt,stopEditing:ot,cellClassName:ae,onScroll:oe,children:(0,u.jsx)(xe,{columnRights:z,columnWidths:R,activeCell:U,selection:q,headerRowHeight:s,rowHeight:Pe,hasStickyRightColumn:F,dataLength:e.length,viewHeight:Re,viewWidth:L,contentWidth:Be?void 0:Ve,edges:ze,editing:V,isCellDisabled:X,expandSelection:Qe,stickyLeftColumns:He,getStickyLeftOffset:Ue})}),(0,u.jsx)(`div`,{ref:je,tabIndex:a.length&&e.length?0:void 0,onFocus:t=>{t.target.blur(),W({col:P.length-(F?3:2),row:e.length-1})}}),!y&&h&&(0,u.jsx)(h,{addRows:t=>Z(e.length-1,t)}),We&&Ge.length>0&&(0,u.jsx)(C,{clientX:We.x,clientY:We.y,cursorIndex:We.cursorIndex,items:Ge,close:()=>B(null)})]})}));P.displayName=`DataSheetGrid`;function F(e){let[t]=(0,c.useState)(e);return t}var Oe=c.default.forwardRef(({columns:e,gutterColumn:t,stickyRightColumn:n,addRowsComponent:r,createRow:i,duplicateRow:a,style:o,rowKey:s,onFocus:c,onBlur:l,onActiveCellChange:d,onSelectionChange:f,rowClassName:p,rowHeight:m,...h},g)=>{let _=F(()=>({columns:e,gutterColumn:t,stickyRightColumn:n,addRowsComponent:r,createRow:i,duplicateRow:a,style:o,rowKey:s,onFocus:c,onBlur:l,onActiveCellChange:d,onSelectionChange:f,rowClassName:p,rowHeight:m}));return(0,u.jsx)(P,{..._,...h,rowHeight:typeof m==`number`?m:_.rowHeight,ref:g})}),ke=()=>{let e=(0,c.useRef)(!0),t=e.current;return e.current=!1,t},I=`.dsg-cell-sticky-left, .dsg-cell-gutter`,Ae=`.dsg-cell-sticky-right`,je=1;function Me(e,t){let{top:n,left:r}=e.getBoundingClientRect(),i={top:n,left:r,right:r+e.clientWidth,bottom:n+e.clientHeight},a=e.querySelector(`.dsg-row-header`);return a&&(i.top=Math.max(i.top,a.getBoundingClientRect().bottom),t?.matches(I)||Array.from(a.querySelectorAll(I)).forEach(e=>{i.left=Math.max(i.left,e.getBoundingClientRect().right)}),t?.matches(Ae)||Array.from(a.querySelectorAll(Ae)).forEach(e=>{i.right=Math.min(i.right,e.getBoundingClientRect().left)})),i}function Ne(e,t){return e.top>=t.top-je&&e.top<=t.bottom+je&&e.left>=t.left-je&&e.left<=t.right+je}var Pe=(e,t)=>e!==null&&e.top===t.top&&e.left===t.left&&e.width===t.width&&e.height===t.height&&e.maxWidth===t.maxWidth&&e.maxHeight===t.maxHeight&&e.anchorVisible===t.anchorVisible,Fe=480,Ie=300,Le=(e,t,n,r,i)=>Math.max(0,Math.min(Math.max(e,n),r-t-i)),L=c.default.memo(({active:e,focus:t,rowData:n,setRowData:r,columnData:{placeholder:i,alignRight:a,formatInputOnFocus:o,formatBlurredInput:s,parseUserInput:l,continuousUpdates:d}})=>{let f=(0,c.useRef)(null),p=ke(),[m,_]=(0,c.useState)(null),[v,y]=(0,c.useState)(null);(0,c.useLayoutEffect)(()=>{if(!e||!m){y(null);return}let t=getComputedStyle(document.documentElement),n=parseFloat(t.getPropertyValue(`--dsg-cell-expanded-max-width`))||Fe,r=parseFloat(t.getPropertyValue(`--dsg-cell-expanded-max-height`))||Ie,i=m.closest(`.dsg-container`),a=m.closest(`.dsg-cell`),o,s=()=>{let e=m.getBoundingClientRect(),t=Le(e.width,e.left,n,window.innerWidth,8),c=Le(e.height,e.top,r,window.innerHeight,8),l={top:e.top,left:e.left,width:e.width,height:e.height,maxWidth:t,maxHeight:c,anchorVisible:!i||Ne(e,Me(i,a))};y(e=>Pe(e,l)?e:l),o=requestAnimationFrame(s)};return s(),()=>cancelAnimationFrame(o)},[e,m]);let b=(0,c.useRef)({rowData:n,formatInputOnFocus:o,formatBlurredInput:s,setRowData:r,parseUserInput:l,continuousUpdates:d,firstRender:p,focusedAt:0,changedAt:0,escPressed:!1,currentValue:s(n)});b.current={rowData:n,formatInputOnFocus:o,formatBlurredInput:s,setRowData:r,parseUserInput:l,continuousUpdates:d,firstRender:p,focusedAt:b.current.focusedAt,changedAt:b.current.changedAt,escPressed:b.current.escPressed,currentValue:b.current.currentValue},(0,c.useLayoutEffect)(()=>{if(t){if(f.current){let e=b.current.formatInputOnFocus(b.current.rowData);f.current.value=e,b.current.currentValue=e,f.current.focus(),f.current.select()}b.current.escPressed=!1,b.current.focusedAt=Date.now()}else!b.current.escPressed&&!b.current.continuousUpdates&&!b.current.firstRender&&b.current.changedAt>=b.current.focusedAt&&b.current.setRowData(b.current.parseUserInput(b.current.currentValue)),f.current?.blur()},[t]),(0,c.useEffect)(()=>{if(!t&&f.current){let e=b.current.formatBlurredInput(n);f.current.value=e,b.current.currentValue=e}},[t,n]);let x=v?.anchorVisible??!0,S=e&&(x||t),C=S&&!x,w=t&&!C,T=!!(t&&v),E=(0,u.jsx)(`textarea`,{rows:1,defaultValue:s(n),className:(0,h.default)(`dsg-input`,a&&`dsg-input-align-right`,T&&`dsg-input-floating`),placeholder:e?i:void 0,tabIndex:-1,ref:f,style:v?{pointerEvents:w?`auto`:`none`,minWidth:T?Math.min(v.width,v.maxWidth):v.width,...T?{maxWidth:v.maxWidth,maxHeight:v.maxHeight}:{width:v.width}}:{pointerEvents:w?`auto`:`none`},onChange:e=>{b.current.changedAt=Date.now(),b.current.currentValue=e.target.value,d&&r(l(e.target.value))},onKeyDown:e=>{e.key===`Escape`&&(b.current.escPressed=!0),e.key===`Enter`&&!e.shiftKey&&e.preventDefault()}}),ee=v&&(0,u.jsx)(`div`,{className:(0,h.default)(t&&`dsg-input-floating-wrapper`),style:{position:`fixed`,top:v.top,left:v.left,minHeight:v.height,zIndex:1e3,display:`flex`,alignItems:`center`,pointerEvents:`none`,opacity:C?0:void 0},children:E});return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{ref:_,className:`dsg-input-anchor`}),m&&(0,g.createPortal)(S?ee:E,S?document.body:m)]})});L.displayName=`TextComponent`;var Re=ze();function ze({placeholder:e,alignRight:t=!1,continuousUpdates:n=!0,deletedValue:r=null,parseUserInput:i=e=>e.trim()||null,formatBlurredInput:a=e=>String(e??``),formatInputOnFocus:o=e=>String(e??``),formatForCopy:s=e=>String(e??``),parsePastedValue:c=e=>e.trim()||null}={}){return{component:L,columnData:{placeholder:e,alignRight:t,continuousUpdates:n,formatInputOnFocus:o,formatBlurredInput:a,parseUserInput:i},deleteValue:()=>r,copyValue:({rowData:e})=>s(e),pasteValue:({value:e})=>c(e),isCellEmpty:({rowData:e})=>e==null}}var Be=new Set([``,`false`,`no`,`off`,`disabled`,`0`,`n`,`f`,`unchecked`,`undefined`,`null`,`wrong`,`negative`]),Ve=c.default.memo(({focus:e,rowData:t,setRowData:n,active:r,stopEditing:i,disabled:a})=>{let o=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e&&(n(!t),i({nextRow:!1}))},[e,i]),(0,u.jsx)(`input`,{className:`dsg-checkbox`,tabIndex:-1,type:`checkbox`,ref:o,disabled:a,checked:!!t,onMouseDown:()=>!r&&n(!t),onChange:()=>null})});Ve.displayName=`CheckboxComponent`;var R={component:Ve,deleteValue:()=>!1,copyValue:({rowData:e})=>e?`YES`:`NO`,pasteValue:({value:e})=>!Be.has(e.toLowerCase()),isCellEmpty:({rowData:e})=>!e},z=ze({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat().format(e):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:t},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:t}}),He=ze({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat().format(e):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:Math.round(t)},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:Math.round(t)}}),Ue=0xe8d4a51000,We=1e10,B=ze({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat(void 0,{style:`percent`}).format(e):``,formatInputOnFocus:e=>typeof e==`number`&&!isNaN(e)?String(Math.round(e*Ue)/We):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:t/100},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:t}}),Ge=c.default.memo(({focus:e,active:t,rowData:n,setRowData:r})=>{let i=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e?i.current?.select():i.current?.blur()},[e]),(0,u.jsx)(`input`,{className:(0,h.default)(`dsg-input`,!t&&`dsg-hide-date-picker`),type:`date`,tabIndex:-1,max:`9999-12-31`,ref:i,style:{pointerEvents:e?`auto`:`none`,opacity:n||t?void 0:0},value:n?.toISOString().substr(0,10)??``,onChange:e=>{let t=new Date(e.target.value);r(isNaN(t.getTime())?null:t)}})});Ge.displayName=`DateComponent`;var Ke={component:Ge,deleteValue:()=>null,copyValue:({rowData:e})=>e?e.toISOString().substr(0,10):null,pasteValue:({value:e})=>{let t=new Date(e.replaceAll(/\.\s?|\//g,`-`));return isNaN(t.getTime())?null:t},minWidth:170,isCellEmpty:({rowData:e})=>!e},V=c.default.memo(({focus:e,active:t,rowData:n,setRowData:r})=>{let i=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e?i.current?.select():i.current?.blur()},[e]),(0,u.jsx)(`input`,{className:(0,h.default)(`dsg-input`,!t&&`dsg-hide-date-picker`),type:`date`,tabIndex:-1,max:`9999-12-31`,ref:i,style:{pointerEvents:e?`auto`:`none`,opacity:n||t?void 0:0},value:n??``,onChange:e=>{let t=new Date(e.target.value);r(isNaN(t.getTime())?null:t.toISOString().substr(0,10))}})});V.displayName=`IsoDateComponent`;var H={component:V,deleteValue:()=>null,copyValue:({rowData:e})=>e,pasteValue:({value:e})=>{let t=new Date(e.replaceAll(/\.\s?|\//g,`-`));return isNaN(t.getTime())?null:t.toISOString().substr(0,10)},minWidth:170,isCellEmpty:({rowData:e})=>!e},qe=({columnData:{key:e,original:t},rowData:n,setRowData:r,...i})=>{let a=(0,c.useRef)(n);a.current=n;let o=(0,c.useCallback)(t=>{r({...a.current,[e]:t})},[e,r]);if(!t.component)return(0,u.jsx)(u.Fragment,{});let s=t.component;return(0,u.jsx)(s,{columnData:t.columnData,setRowData:o,rowData:n[e],...i})},Je=(e,t)=>({id:e,...t,columnData:{key:e,original:t},component:qe,copyValue:({rowData:n,rowIndex:r})=>t.copyValue?.({rowData:n[e],rowIndex:r})??null,deleteValue:({rowData:n,rowIndex:r})=>({...n,[e]:t.deleteValue?.({rowData:n[e],rowIndex:r})??null}),pasteValue:({rowData:n,value:r,rowIndex:i})=>({...n,[e]:t.pasteValue?.({rowData:n[e],value:r,rowIndex:i})??null}),disabled:typeof t.disabled==`function`?({rowData:n,rowIndex:r})=>typeof t.disabled==`function`?t.disabled({rowData:n[e],rowIndex:r}):t.disabled??!1:t.disabled,cellClassName:typeof t.cellClassName==`function`?({rowData:n,rowIndex:r,columnId:i})=>typeof t.cellClassName==`function`?t.cellClassName({rowData:n[e],rowIndex:r,columnId:i}):t.cellClassName??void 0:t.cellClassName,isCellEmpty:({rowData:n,rowIndex:r})=>t.isCellEmpty?.({rowData:n[e],rowIndex:r})??!1}),Ye=P,Xe=Oe;exports.DataSheetGrid=Xe,exports.DynamicDataSheetGrid=Ye,exports.checkboxColumn=R,exports.createAddRowsComponent=A,exports.createContextMenuComponent=j,exports.createTextColumn=ze,exports.dateColumn=Ke,exports.floatColumn=z,exports.intColumn=He,exports.isoDateColumn=H,exports.keyColumn=Je,exports.percentColumn=B,exports.renderContextMenuItem=ie,exports.textColumn=Re;
|
|
7
|
+
`,`<br/>`)}</td>`).join(``)}</tr>`).join(``)}</table>`;if(t!==void 0){t.clipboardData?.setData(`text/plain`,a),t.clipboardData?.setData(`text/html`,o),t.preventDefault();return}let s=!1;if(navigator.clipboard.write!==void 0){let e=new Blob([a],{type:`text/plain`}),t=new Blob([o],{type:`text/html`}),n=[new ClipboardItem({"text/plain":e,"text/html":t})];await navigator.clipboard.write(n).then(()=>{s=!0})}else navigator.clipboard.writeText===void 0?document.execCommand!==void 0&&document.execCommand(`copy`)&&(s=!0):await navigator.clipboard.writeText(a).then(()=>{s=!0});s||alert(`This action is unavailable in your browser, but you can still use Ctrl+C for copy or Ctrl+X for cut`)}},[U,P,e,V,q]);O(`copy`,dt);let ft=(0,c.useCallback)(e=>{!V&&U&&(dt(e),lt(!1))},[U,lt,V,dt]);O(`cut`,ft);let pt=(0,c.useCallback)(async t=>{if(!V&&U){let n=q?.min||U,r=q?.max||U,a=await Promise.all(t[0].map((e,r)=>{let i=P[n.col+r+1]?.prePasteValues,a=t.map(e=>e[r]);return Promise.resolve(i?.(a)??a)}));if(t=t.map((e,t)=>a.map(e=>e[t])),t.length===1){let a=[...e];for(let e=0;e<t[0].length;e++){let i=P[n.col+e+1]?.pasteValue;if(i)for(let o=n.row;o<=r.row;o++)X({col:e+n.col,row:o})||(a[o]=await i({rowData:a[o],value:t[0][e],rowIndex:o}))}i(a,[{type:`UPDATE`,fromRowIndex:n.row,toRowIndex:r.row+1}]),W({col:n.col,row:n.row}),K({col:Math.min(n.col+t[0].length-1,P.length-(F?3:2)),row:r.row})}else{let r=[...e],a=n.row+t.length-e.length;a>0&&(y?t.splice(t.length-a,a):r=[...r,...Array(a).fill(0).map(()=>g())]);for(let e=0;e<t[0].length&&n.col+e<P.length-(F?2:1);e++){let i=P[n.col+e+1]?.pasteValue;if(i)for(let a=0;a<t.length;a++)X({col:n.col+e,row:n.row+a})||(r[n.row+a]=await i({rowData:r[n.row+a],value:t[a][e],rowIndex:n.row+a}))}let o=[{type:`UPDATE`,fromRowIndex:n.row,toRowIndex:n.row+t.length-(!y&&a>0?a:0)}];a>0&&!y&&o.push({type:`CREATE`,fromRowIndex:n.row+t.length-a,toRowIndex:n.row+t.length}),i(r,o),W({col:n.col,row:n.row}),K({col:Math.min(n.col+t[0].length-1,P.length-(F?3:2)),row:n.row+t.length-1})}}},[U,P,g,e,V,F,X,y,i,q?.max,q?.min,W,K]);O(`paste`,(0,c.useCallback)(e=>{if(U&&!V){let t=[[``]];e.clipboardData?.types.includes(`text/html`)?t=se(e.clipboardData?.getData(`text/html`)):e.clipboardData?.types.includes(`text/plain`)?t=ce(e.clipboardData?.getData(`text/plain`)):e.clipboardData?.types.includes(`text`)&&(t=ce(e.clipboardData?.getData(`text`))),pt(t),e.preventDefault()}},[U,pt,V])),O(`mousedown`,(0,c.useCallback)(t=>{if(Je&&Ye.length)return;let n=t.button===2||t.button===0&&t.ctrlKey,r=Ne.current?.contains(t.target)||!1,i=r?at(t,!0,!0):null;if(!r&&V&&U&&P[U.col+1].keepFocus)return;if(t.target instanceof HTMLElement&&t.target.className.includes(`dsg-expand-rows-indicator`)){et(Math.max(U?.row??0,q?.max.row??0));return}let a=i&&U&&U.col===i.col&&U.row===i.row&&!X(U),o=V&&t.target instanceof HTMLElement&&t.target.classList.contains(`dsg-input`);if((a||o)&&V)return;let s=i?.col===P.length-2&&F,c=n&&q&&i&&i.row>=q.min.row&&i.row<=q.max.row&&i.col>=q.min.col&&i.col<=q.max.col,l=n&&q&&i?.row===-1&&i.col>=q.min.col&&i.col<=q.max.col,u=n&&q&&i&&i.row>=q.min.row&&i.row<=q.max.row&&i.col===-1,d=s&&q&&i&&i.row>=q.min.row&&i.row<=q.max.row;if(n&&!je&&B({x:t.clientX,y:t.clientY,cursorIndex:i}),(!(t.shiftKey&&U)||n)&&e.length>0&&W(i&&{col:(c||l)&&U?U.col:Math.max(0,s?0:i.col),row:(c||u||d)&&U?U.row:Math.max(0,i.row),doNotScrollX:!!(c&&U||s||i.col===-1),doNotScrollY:!!(c&&U||i.row===-1)}),a&&!n&&(N.current=U),H(!(!a||n)),tt(i&&!n?{columns:i.col!==-1&&!s||!!(t.shiftKey&&U),rows:i.row!==-1||!!(t.shiftKey&&U),active:!0}:{columns:!1,rows:!1,active:!1}),t.shiftKey&&U&&!n)K(i&&{col:Math.max(0,i.col-+!!s),row:Math.max(0,i.row)});else if(!c){if(i&&(i?.col===-1||i?.row===-1||s)){let t=i.col,n=i.row,r=!1,a=!1;(i.col===-1||s)&&(t=P.length-(F?3:2),r=!0),i.row===-1&&(n=e.length-1,a=!0),l&&G&&(t=G.col,a=!0),(u||d)&&G&&(n=G.row,r=!0),K({col:t,row:n,doNotScrollX:r,doNotScrollY:a})}else K(null);r&&t.preventDefault()}},[Je,Ye.length,at,V,U,P,X,q,F,je,tt,W,K,G,e.length])),O(`mouseup`,(0,c.useCallback)(()=>{if($e!==null){if(Ze>0&&U){let t=[],n=q?.min||U,r=q?.max||U;for(let i=n.row;i<=r.row;++i){t.push([]);for(let a=n.col;a<=r.col;++a){let{copyValue:r=()=>null}=P[a+1];t[i-n.row].push(String(r({rowData:e[i],rowIndex:i})??``))}}Promise.all(t[0].map((e,r)=>{let i=P[n.col+r+1]?.prePasteValues,a=t.map(e=>e[r]);return Promise.resolve(i?.(a)??a)})).then(a=>{t=t.map((e,t)=>a.map(e=>e[t]));let o=[...e];for(let e=0;e<t[0].length;e++){let i=P[n.col+e+1]?.pasteValue;if(i)for(let a=r.row+1;a<=r.row+Ze;a++)X({col:e+n.col,row:a})||(o[a]=i({rowData:o[a],value:t[(a-r.row-1)%t.length][e],rowIndex:a}))}i(o,[{type:`UPDATE`,fromRowIndex:r.row+1,toRowIndex:r.row+1+Ze}])}),Qe(0),W({col:Math.min(U?.col??1/0,q?.min.col??1/0),row:Math.min(U?.row??1/0,q?.min.row??1/0),doNotScrollX:!0,doNotScrollY:!0}),K({col:Math.max(U?.col??0,q?.max.col??0),row:Math.max(U?.row??0,q?.max.row??0)+Ze})}et(null)}tt({columns:!1,rows:!1,active:!1})},[$e,tt,Ze,U,q?.min,q?.max,e,i,W,K,P,X])),O(`mousemove`,(0,c.useCallback)(t=>{if($e!==null){let e=at(t);e&&(Qe(Math.max(0,e.row-$e)),Q({col:e.col,row:Math.max(e.row,$e)}))}if(J.active){let n=at(t),r=P.length-(F?3:2);K(n&&{col:J.columns?Math.max(0,Math.min(r,n.col)):r,row:J.rows?Math.max(0,n.row):e.length-1,doNotScrollX:!J.columns,doNotScrollY:!J.rows}),H(!1)}},[Q,J.active,J.columns,J.rows,at,P.length,F,K,e.length,$e])),O(`keydown`,(0,c.useCallback)(t=>{if(U&&!t.isComposing){if(t.key===`Tab`&&!t.shiftKey&&U.col===P.length-(F?3:2)&&!P[U.col+1].disableKeys){if(U.row===e.length-1){if(Fe.current){t.preventDefault(),W(null),K(null),H(!1);let e=ge();e[(e.indexOf(Fe.current)+1)%e.length].focus();return}}else{W(e=>({col:0,row:(e?.row??0)+1})),K(null),H(!1),t.preventDefault();return}}if(t.key===`Tab`&&t.shiftKey&&U.col===0&&!P[U.col+1].disableKeys){if(U.row===0){if(Pe.current){t.preventDefault(),W(null),K(null),H(!1);let e=ge();e[(e.indexOf(Pe.current)-1+e.length)%e.length].focus();return}}else{W(e=>({col:P.length-(F?3:2),row:(e?.row??1)-1})),K(null),H(!1),t.preventDefault();return}}if(t.key?.startsWith(`Arrow`)||t.key===`Tab`){if(V&&P[U.col+1].disableKeys||V&&[`ArrowLeft`,`ArrowRight`].includes(t.key))return;let n=([t,n],r)=>r&&{col:Math.max(0,Math.min(P.length-(F?3:2),r.col+t)),row:Math.max(0,Math.min(e.length-1,r.row+n))};if(t.key===`Tab`&&t.shiftKey)W(e=>n([-1,0],e)),K(null);else{let r={ArrowDown:[0,1],ArrowUp:[0,-1],ArrowLeft:[-1,0],ArrowRight:[1,0],Tab:[1,0]}[t.key];(t.ctrlKey||t.metaKey)&&(r[0]*=P.length,r[1]*=e.length),t.shiftKey?K(e=>n(r,e||U)):(W(e=>n(r,e)),K(null))}H(!1),t.preventDefault()}else if(t.key===`Escape`)!V&&!G&&W(null),K(null),H(!1);else if((t.key===`Enter`||t.key===`F2`)&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&!t.shiftKey)K(null),V?P[U.col+1].disableKeys||(ut(),t.preventDefault()):X(U)||(N.current=U,H(!0),Q(U),t.preventDefault());else if(t.key===`Enter`&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&t.shiftKey&&!V)Z(q?.max.row||U.row);else if(t.key===`d`&&(t.ctrlKey||t.metaKey)&&!t.altKey&&!t.shiftKey)ot(q?.min.row||U.row,q?.max.row),t.preventDefault();else if(ve(t)||ye(t)){let e=ve(t)?be:xe;!V&&e&&(e(),t.preventDefault())}else(de(t.key)||/Key[A-Z]$/.exec(t.code))&&!t.ctrlKey&&!t.metaKey&&!t.altKey?!V&&!X(U)&&(N.current=U,K(null),H(!0),Q(U)):[`Backspace`,`Delete`].includes(t.key)?V||(lt(),t.preventDefault()):t.key===`a`&&(t.ctrlKey||t.metaKey)&&(V||(W({col:0,row:0,doNotScrollY:!0,doNotScrollX:!0}),K({col:P.length-(F?3:2),row:e.length-1,doNotScrollY:!0,doNotScrollX:!0}),t.preventDefault()))}},[U,P,e.length,lt,ot,V,Z,X,Q,q?.max.row,q?.min.row,G,W,K,ut,F,be,xe]));let mt=(0,c.useRef)(null);O(`focusin`,(0,c.useCallback)(e=>{U&&e!==mt.current&&(W(null),K(null),H(!1))},[U,W,K])),O(`contextmenu`,(0,c.useCallback)(e=>{let t=Ne.current?.contains(e.target)||!1,n=t?at(e,!0,!0):null,r=n&&U&&U.col===n.col&&U.row===n.row&&V;t&&!r&&e.preventDefault()},[at,U,V])),(0,c.useEffect)(()=>{let e=[];U?.row!==void 0&&e.push({type:`COPY`,action:()=>{dt(),B(null)}},{type:`CUT`,action:()=>{ft(),B(null)}},{type:`PASTE`,action:()=>{(async()=>{if(navigator.clipboard.read!==void 0){let e=await navigator.clipboard.read();for(let t of e){let e=[[``]];t.types.includes(`text/html`)?e=se(await(await t.getType(`text/html`)).text()):t.types.includes(`text/plain`)?e=ce(await(await t.getType(`text/plain`)).text()):t.types.includes(`text`)&&(e=se(await(await t.getType(`text`)).text())),await pt(e)}}else if(navigator.clipboard.readText!==void 0){let e=await navigator.clipboard.readText();await pt(ce(e))}else alert(`This action is unavailable in your browser, but you can still use Ctrl+V for paste`);B(null)})()}}),q?.max.row===void 0?U?.row!==void 0&&e.push({type:`INSERT_ROW_BELLOW`,action:()=>{B(null),Z(U.row)}}):e.push({type:`INSERT_ROW_BELLOW`,action:()=>{B(null),Z(q.max.row)}}),q?.min.row!==void 0&&q.min.row!==q.max.row?e.push({type:`DUPLICATE_ROWS`,fromRow:q.min.row+1,toRow:q.max.row+1,action:()=>{B(null),ot(q.min.row,q.max.row)}}):U?.row!==void 0&&e.push({type:`DUPLICATE_ROW`,action:()=>{B(null),ot(U.row)}}),q?.min.row!==void 0&&q.min.row!==q.max.row?e.push({type:`DELETE_ROWS`,fromRow:q.min.row+1,toRow:q.max.row+1,action:()=>{B(null),ct(q.min.row,q.max.row)}}):U?.row!==void 0&&e.push({type:`DELETE_ROW`,action:()=>{B(null),ct(U.row)}}),Xe(e),e.length||B(null)},[q,U,ct,ot,Z,ft,dt,pt]);let ht=(0,c.useRef)(Ye);ht.current=Ye;let gt=(0,c.useCallback)(()=>ht.current,[]);(0,c.useImperativeHandle)(Ce,()=>({activeCell:pe(U,P),selection:he(q??(U?{min:U,max:U}:null),P),setSelection:t=>{let n=me(t,P.length-(F?2:1),e.length,P);W(n?.min||null),H(!1),tt({columns:!1,active:!1,rows:!1}),K(n?.max||null)},setActiveCell:t=>{let n=fe(t,P.length-(F?2:1),e.length,P);W(n),H(!1),tt({columns:!1,active:!1,rows:!1}),K(null)}}));let $=(0,c.useRef)({onFocus:T,onBlur:E,onActiveCellChange:A,onSelectionChange:ie});return $.current.onFocus=T,$.current.onBlur=E,$.current.onActiveCellChange=A,$.current.onSelectionChange=ie,(0,c.useEffect)(()=>{N.current&&(V?$.current.onFocus({cell:pe(N.current,P)}):$.current.onBlur({cell:pe(N.current,P)}))},[V,P]),(0,c.useEffect)(()=>{$.current.onActiveCellChange({cell:pe(U,P)})},[U?.col,U?.row,P]),(0,c.useEffect)(()=>{$.current.onSelectionChange({selection:he(q??(U?{min:U,max:U}:null),P)})},[q?.min.col??U?.col,q?.min.row??U?.row,q?.max.col??U?.col,q?.max.row??U?.row,U?.col,U?.row,P]),(0,u.jsxs)(`div`,{className:t,style:n,onFocus:e=>{mt.current=e.nativeEvent},children:[(0,u.jsx)(`div`,{ref:Pe,tabIndex:a.length&&e.length?0:void 0,onFocus:e=>{e.target.blur(),W({col:0,row:0})}}),(0,u.jsx)(Se,{columns:P,outerRef:I,columnWidths:R,hasStickyRightColumn:F,pinFirstColumn:_e,displayHeight:Ve,data:e,fullWidth:We,headerRowHeight:s,activeCell:U,innerRef:Ne,rowHeight:o,getRowSize:Re,rowKey:m,selection:q,rowClassName:j,editing:V,getContextMenuItems:gt,setRowData:st,deleteRows:ct,insertRowAfter:Z,duplicateRows:ot,stopEditing:ut,cellClassName:ae,onScroll:oe,children:(0,u.jsx)(we,{columnRights:z,columnWidths:R,activeCell:U,selection:q,headerRowHeight:s,rowHeight:Re,hasStickyRightColumn:F,dataLength:e.length,viewHeight:L,viewWidth:He,contentWidth:We?void 0:Ge,edges:Ue,editing:V,isCellDisabled:X,expandSelection:nt,stickyLeftColumns:Ke,getStickyLeftOffset:qe})}),(0,u.jsx)(`div`,{ref:Fe,tabIndex:a.length&&e.length?0:void 0,onFocus:t=>{t.target.blur(),W({col:P.length-(F?3:2),row:e.length-1})}}),!y&&h&&(0,u.jsx)(h,{addRows:t=>Z(e.length-1,t)}),Je&&Ye.length>0&&(0,u.jsx)(C,{clientX:Je.x,clientY:Je.y,cursorIndex:Je.cursorIndex,items:Ye,close:()=>B(null)})]})}));je.displayName=`DataSheetGrid`;function P(e){let[t]=(0,c.useState)(e);return t}var F=c.default.forwardRef(({columns:e,gutterColumn:t,stickyRightColumn:n,addRowsComponent:r,createRow:i,duplicateRow:a,style:o,rowKey:s,onFocus:c,onBlur:l,onActiveCellChange:d,onSelectionChange:f,rowClassName:p,rowHeight:m,...h},g)=>{let _=P(()=>({columns:e,gutterColumn:t,stickyRightColumn:n,addRowsComponent:r,createRow:i,duplicateRow:a,style:o,rowKey:s,onFocus:c,onBlur:l,onActiveCellChange:d,onSelectionChange:f,rowClassName:p,rowHeight:m}));return(0,u.jsx)(je,{..._,...h,rowHeight:typeof m==`number`?m:_.rowHeight,ref:g})}),Me=()=>{let e=(0,c.useRef)(!0),t=e.current;return e.current=!1,t},Ne=`.dsg-cell-sticky-left, .dsg-cell-gutter`,I=`.dsg-cell-sticky-right`,Pe=1;function Fe(e,t){let{top:n,left:r}=e.getBoundingClientRect(),i={top:n,left:r,right:r+e.clientWidth,bottom:n+e.clientHeight},a=e.querySelector(`.dsg-row-header`);return a&&(i.top=Math.max(i.top,a.getBoundingClientRect().bottom),t?.matches(Ne)||Array.from(a.querySelectorAll(Ne)).forEach(e=>{i.left=Math.max(i.left,e.getBoundingClientRect().right)}),t?.matches(I)||Array.from(a.querySelectorAll(I)).forEach(e=>{i.right=Math.min(i.right,e.getBoundingClientRect().left)})),i}function Ie(e,t){return e.top>=t.top-Pe&&e.top<=t.bottom+Pe&&e.left>=t.left-Pe&&e.left<=t.right+Pe}var Le=(e,t)=>e!==null&&e.top===t.top&&e.left===t.left&&e.width===t.width&&e.height===t.height&&e.maxWidth===t.maxWidth&&e.maxHeight===t.maxHeight&&e.anchorVisible===t.anchorVisible,Re=480,ze=300,Be=(e,t,n,r,i)=>Math.max(0,Math.min(Math.max(e,n),r-t-i)),Ve=c.default.memo(({active:e,focus:t,rowData:n,setRowData:r,columnData:{placeholder:i,alignRight:a,formatInputOnFocus:o,formatBlurredInput:s,parseUserInput:l,continuousUpdates:d}})=>{let f=(0,c.useRef)(null),p=Me(),[m,_]=(0,c.useState)(null),[v,y]=(0,c.useState)(null);(0,c.useLayoutEffect)(()=>{if(!e||!m){y(null);return}let t=getComputedStyle(document.documentElement),n=parseFloat(t.getPropertyValue(`--dsg-cell-expanded-max-width`))||Re,r=parseFloat(t.getPropertyValue(`--dsg-cell-expanded-max-height`))||ze,i=m.closest(`.dsg-container`),a=m.closest(`.dsg-cell`),o,s=()=>{let e=m.getBoundingClientRect(),t=Be(e.width,e.left,n,window.innerWidth,8),c=Be(e.height,e.top,r,window.innerHeight,8),l={top:e.top,left:e.left,width:e.width,height:e.height,maxWidth:t,maxHeight:c,anchorVisible:!i||Ie(e,Fe(i,a))};y(e=>Le(e,l)?e:l),o=requestAnimationFrame(s)};return s(),()=>cancelAnimationFrame(o)},[e,m]);let b=(0,c.useRef)({rowData:n,formatInputOnFocus:o,formatBlurredInput:s,setRowData:r,parseUserInput:l,continuousUpdates:d,firstRender:p,focusedAt:0,changedAt:0,escPressed:!1,currentValue:s(n)});b.current={rowData:n,formatInputOnFocus:o,formatBlurredInput:s,setRowData:r,parseUserInput:l,continuousUpdates:d,firstRender:p,focusedAt:b.current.focusedAt,changedAt:b.current.changedAt,escPressed:b.current.escPressed,currentValue:b.current.currentValue},(0,c.useLayoutEffect)(()=>{if(t){if(f.current){let e=b.current.formatInputOnFocus(b.current.rowData);f.current.value=e,b.current.currentValue=e,f.current.focus(),f.current.select()}b.current.escPressed=!1,b.current.focusedAt=Date.now()}else!b.current.escPressed&&!b.current.continuousUpdates&&!b.current.firstRender&&b.current.changedAt>=b.current.focusedAt&&b.current.setRowData(b.current.parseUserInput(b.current.currentValue)),f.current?.blur()},[t]),(0,c.useEffect)(()=>{if(!t&&f.current){let e=b.current.formatBlurredInput(n);f.current.value=e,b.current.currentValue=e}},[t,n]);let x=v?.anchorVisible??!0,S=e&&(x||t),C=S&&!x,w=t&&!C,T=!!(t&&v),E=(0,u.jsx)(`textarea`,{rows:1,defaultValue:s(n),className:(0,h.default)(`dsg-input`,a&&`dsg-input-align-right`,T&&`dsg-input-floating`),placeholder:e?i:void 0,tabIndex:-1,ref:f,style:v?{pointerEvents:w?`auto`:`none`,minWidth:T?Math.min(v.width,v.maxWidth):v.width,...T?{maxWidth:v.maxWidth,maxHeight:v.maxHeight}:{width:v.width}}:{pointerEvents:w?`auto`:`none`},onChange:e=>{b.current.changedAt=Date.now(),b.current.currentValue=e.target.value,d&&r(l(e.target.value))},onKeyDown:e=>{e.key===`Escape`&&(b.current.escPressed=!0),e.key===`Enter`&&!e.shiftKey&&e.preventDefault()}}),ee=v&&(0,u.jsx)(`div`,{className:(0,h.default)(t&&`dsg-input-floating-wrapper`),style:{position:`fixed`,top:v.top,left:v.left,minHeight:v.height,zIndex:1e3,display:`flex`,alignItems:`center`,pointerEvents:`none`,opacity:C?0:void 0},children:E});return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{ref:_,className:`dsg-input-anchor`}),m&&(0,g.createPortal)(S?ee:E,S?document.body:m)]})});Ve.displayName=`TextComponent`;var He=L();function L({placeholder:e,alignRight:t=!1,continuousUpdates:n=!0,deletedValue:r=null,parseUserInput:i=e=>e.trim()||null,formatBlurredInput:a=e=>String(e??``),formatInputOnFocus:o=e=>String(e??``),formatForCopy:s=e=>String(e??``),parsePastedValue:c=e=>e.trim()||null}={}){return{component:Ve,columnData:{placeholder:e,alignRight:t,continuousUpdates:n,formatInputOnFocus:o,formatBlurredInput:a,parseUserInput:i},deleteValue:()=>r,copyValue:({rowData:e})=>s(e),pasteValue:({value:e})=>c(e),isCellEmpty:({rowData:e})=>e==null}}var Ue=new Set([``,`false`,`no`,`off`,`disabled`,`0`,`n`,`f`,`unchecked`,`undefined`,`null`,`wrong`,`negative`]),We=c.default.memo(({focus:e,rowData:t,setRowData:n,active:r,stopEditing:i,disabled:a})=>{let o=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e&&(n(!t),i({nextRow:!1}))},[e,i]),(0,u.jsx)(`input`,{className:`dsg-checkbox`,tabIndex:-1,type:`checkbox`,ref:o,disabled:a,checked:!!t,onMouseDown:()=>!r&&n(!t),onChange:()=>null})});We.displayName=`CheckboxComponent`;var Ge={component:We,deleteValue:()=>!1,copyValue:({rowData:e})=>e?`YES`:`NO`,pasteValue:({value:e})=>!Ue.has(e.toLowerCase()),isCellEmpty:({rowData:e})=>!e},R=L({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat().format(e):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:t},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:t}}),z=L({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat().format(e):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:Math.round(t)},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:Math.round(t)}}),Ke=0xe8d4a51000,qe=1e10,Je=L({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat(void 0,{style:`percent`}).format(e):``,formatInputOnFocus:e=>typeof e==`number`&&!isNaN(e)?String(Math.round(e*Ke)/qe):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:t/100},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:t}}),B=c.default.memo(({focus:e,active:t,rowData:n,setRowData:r})=>{let i=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e?i.current?.select():i.current?.blur()},[e]),(0,u.jsx)(`input`,{className:(0,h.default)(`dsg-input`,!t&&`dsg-hide-date-picker`),type:`date`,tabIndex:-1,max:`9999-12-31`,ref:i,style:{pointerEvents:e?`auto`:`none`,opacity:n||t?void 0:0},value:n?.toISOString().substr(0,10)??``,onChange:e=>{let t=new Date(e.target.value);r(isNaN(t.getTime())?null:t)}})});B.displayName=`DateComponent`;var Ye={component:B,deleteValue:()=>null,copyValue:({rowData:e})=>e?e.toISOString().substr(0,10):null,pasteValue:({value:e})=>{let t=new Date(e.replaceAll(/\.\s?|\//g,`-`));return isNaN(t.getTime())?null:t},minWidth:170,isCellEmpty:({rowData:e})=>!e},Xe=c.default.memo(({focus:e,active:t,rowData:n,setRowData:r})=>{let i=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e?i.current?.select():i.current?.blur()},[e]),(0,u.jsx)(`input`,{className:(0,h.default)(`dsg-input`,!t&&`dsg-hide-date-picker`),type:`date`,tabIndex:-1,max:`9999-12-31`,ref:i,style:{pointerEvents:e?`auto`:`none`,opacity:n||t?void 0:0},value:n??``,onChange:e=>{let t=new Date(e.target.value);r(isNaN(t.getTime())?null:t.toISOString().substr(0,10))}})});Xe.displayName=`IsoDateComponent`;var V={component:Xe,deleteValue:()=>null,copyValue:({rowData:e})=>e,pasteValue:({value:e})=>{let t=new Date(e.replaceAll(/\.\s?|\//g,`-`));return isNaN(t.getTime())?null:t.toISOString().substr(0,10)},minWidth:170,isCellEmpty:({rowData:e})=>!e},H=({columnData:{key:e,original:t},rowData:n,setRowData:r,...i})=>{let a=(0,c.useRef)(n);a.current=n;let o=(0,c.useCallback)(t=>{r({...a.current,[e]:t})},[e,r]);if(!t.component)return(0,u.jsx)(u.Fragment,{});let s=t.component;return(0,u.jsx)(s,{columnData:t.columnData,setRowData:o,rowData:n[e],...i})},Ze=(e,t)=>({id:e,...t,columnData:{key:e,original:t},component:H,copyValue:({rowData:n,rowIndex:r})=>t.copyValue?.({rowData:n[e],rowIndex:r})??null,deleteValue:({rowData:n,rowIndex:r})=>({...n,[e]:t.deleteValue?.({rowData:n[e],rowIndex:r})??null}),pasteValue:({rowData:n,value:r,rowIndex:i})=>({...n,[e]:t.pasteValue?.({rowData:n[e],value:r,rowIndex:i})??null}),disabled:typeof t.disabled==`function`?({rowData:n,rowIndex:r})=>typeof t.disabled==`function`?t.disabled({rowData:n[e],rowIndex:r}):t.disabled??!1:t.disabled,cellClassName:typeof t.cellClassName==`function`?({rowData:n,rowIndex:r,columnId:i})=>typeof t.cellClassName==`function`?t.cellClassName({rowData:n[e],rowIndex:r,columnId:i}):t.cellClassName??void 0:t.cellClassName,isCellEmpty:({rowData:n,rowIndex:r})=>t.isCellEmpty?.({rowData:n[e],rowIndex:r})??!1}),Qe=je,$e=F;exports.DataSheetGrid=$e,exports.DynamicDataSheetGrid=Qe,exports.checkboxColumn=Ge,exports.createAddRowsComponent=A,exports.createContextMenuComponent=j,exports.createTextColumn=L,exports.dateColumn=Ye,exports.floatColumn=R,exports.intColumn=z,exports.isoDateColumn=V,exports.keyColumn=Ze,exports.percentColumn=Je,exports.renderContextMenuItem=ie,exports.textColumn=He;
|
|
8
8
|
//# sourceMappingURL=index.cjs.map
|