@sage-bionetworks/react-datasheet-grid 4.11.5-sage.10 → 4.11.5-sage.12

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 CHANGED
@@ -1,7 +1,8 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("react-resize-detector"),u=require("react/jsx-runtime"),d=require("throttle-debounce"),f=require("fast-deep-equal");f=s(f,1);let p=require("dompurify");p=s(p,1);let m=require("@tanstack/react-virtual"),h=require("classnames");h=s(h,1);let g=require("react-dom");var _=(e,t)=>{let n=t.map(({basis:e,minWidth:t,maxWidth:n})=>({basis:e,minWidth:t,maxWidth:n,size:e,violation:0,frozen:!1,factor:0})),r=n.reduce((e,t)=>e-t.size,e);r>0?t.forEach(({grow:e},t)=>{n[t].factor=e}):r<0&&t.forEach(({shrink:e},t)=>{n[t].factor=e});for(let e of n)e.factor===0&&(e.frozen=!0);for(;n.some(({frozen:e})=>!e);){let t=n.reduce((e,t)=>e+(t.frozen?0:t.factor),0),i=0;for(let e of n)e.frozen||(e.size+=r*e.factor/t,e.size<e.minWidth?e.violation=e.minWidth-e.size:e.maxWidth!==void 0&&e.size>e.maxWidth?e.violation=e.maxWidth-e.size:e.violation=0,e.size+=e.violation,i+=e.violation);if(i>0)for(let e of n)e.violation>0&&(e.frozen=!0);else if(i<0)for(let e of n)e.violation<0&&(e.frozen=!0);else break;r=n.reduce((e,t)=>e-t.size,e)}return n.map(({size:e})=>e)},v=(e,t)=>(0,c.useMemo)(()=>{if(t===void 0)return{fullWidth:!1,columnWidths:void 0,columnRights:void 0,totalWidth:void 0};let n=_(t,e),r=0,i=n.map((e,t)=>(r+=e,t===n.length-1?1/0:r));return{fullWidth:Math.abs(t-r)<.1,columnWidths:n,columnRights:i,totalWidth:r}},[t,e.map(({basis:e,minWidth:t,maxWidth:n,grow:r,shrink:i})=>[e,t,n,r,i].join(`,`)).join(`|`)]),y=()=>(0,u.jsx)(u.Fragment,{}),b=()=>!1,x=({rowData:e})=>e,S=()=>null,C=({rowIndex:e})=>(0,u.jsx)(u.Fragment,{children:e+1}),w=()=>!0,T=e=>e,E=e=>{if(typeof e==`number`)return{basis:0,grow:e,shrink:1};if(e.match(/^ *\d+(\.\d*)? *$/))return{basis:0,grow:parseFloat(e.trim()),shrink:1};if(e.match(/^ *\d+(\.\d*)? *px *$/))return{basis:parseFloat(e.trim()),grow:1,shrink:1};if(e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? *$/)){let[t,n]=e.trim().split(` `);return{basis:0,grow:parseFloat(t),shrink:parseFloat(n)}}if(e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? *px *$/)){let[t,n]=e.trim().split(` `);return{basis:parseFloat(n),grow:parseFloat(t),shrink:1}}if(e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? \d+(\.\d*)? *px *$/)){let[t,n,r]=e.trim().split(` `);return{basis:parseFloat(r),grow:parseFloat(t),shrink:parseFloat(n)}}return{basis:0,grow:1,shrink:1}},ee=(e,t,n,r=!1)=>(0,c.useMemo)(()=>{let i=[t===!1?{basis:0,grow:0,shrink:0,minWidth:0,component:()=>(0,u.jsx)(u.Fragment,{}),headerClassName:`dsg-hidden-cell`,cellClassName:`dsg-hidden-cell`,isCellEmpty:w}:{...t,basis:t?.basis??40,grow:t?.grow??0,shrink:t?.shrink??0,minWidth:t?.minWidth??0,title:t?.title??(0,u.jsx)(`div`,{className:`dsg-corner-indicator`}),component:t?.component??C,isCellEmpty:w},...e];return n&&i.push({...n,basis:n?.basis??40,grow:n?.grow??0,shrink:n?.shrink??0,minWidth:n.minWidth??0,isCellEmpty:w}),i.map((e,t)=>{let n=e.width===void 0?{basis:void 0,grow:void 0,shrink:void 0}:E(e.width),i=e.stickyLeft===void 0?t===1&&r:e.stickyLeft;return{...e,basis:e.basis??n.basis??0,grow:e.grow??n.grow??1,shrink:e.shrink??n.shrink??1,minWidth:e.minWidth??100,component:e.component??y,disableKeys:e.disableKeys??!1,disabled:e.disabled??!1,keepFocus:e.keepFocus??!1,deleteValue:e.deleteValue??x,copyValue:e.copyValue??S,pasteValue:e.pasteValue??x,prePasteValues:e.prePasteValues??T,isCellEmpty:e.isCellEmpty??b,stickyLeft:i}})},[t,n,e,r]),D=e=>{let[t,n]=(0,c.useState)(e);return[t,(0,c.useCallback)(e=>{n(t=>{let n=typeof e==`function`?e(t):e;return(0,f.default)(n,t)?t:n})},[n])]},te=(e,t,n)=>{let[r,i]=D({top:!0,right:!0,bottom:!0,left:!0});return(0,c.useEffect)(()=>{let r=(0,d.throttle)(100,()=>{i({top:e.current?.scrollTop===0,right:(e.current?.scrollLeft??0)>=(e.current?.scrollWidth??0)-(t??0)-1,bottom:(e.current?.scrollTop??0)>=(e.current?.scrollHeight??0)-(n??0)-1,left:e.current?.scrollLeft===0})}),a=e.current;return a?.addEventListener(`scroll`,r),setTimeout(r,100),()=>{a?.removeEventListener(`scroll`,r),r.cancel()}},[n,t,e,i]),r},O=(e,t)=>{(0,c.useEffect)(()=>{let n=(...e)=>{t(...e)};return document.addEventListener(e,n),()=>{document.removeEventListener(e,n)}},[t,e])},k=(e,t=200)=>{let n=(0,c.useRef)(null),r=(0,c.useMemo)(()=>(0,d.throttle)(t,!0,()=>{setTimeout(()=>n.current=e.current?.getBoundingClientRect()||null,0)}),[e,t]);return(0,c.useCallback)((t=!1)=>(t?n.current=e.current?.getBoundingClientRect()||null:r(),n.current),[e,r])},A=(e={})=>({addRows:t})=>{let[n,r]=(0,c.useState)(1),[i,a]=(0,c.useState)(String(n));return(0,u.jsxs)(`div`,{className:`dsg-add-row`,children:[(0,u.jsx)(`button`,{type:`button`,className:`dsg-add-row-btn`,onClick:()=>t(n),children:e.button??`Add`}),` `,(0,u.jsx)(`input`,{className:`dsg-add-row-input`,value:i,onBlur:()=>a(String(n)),type:`number`,min:1,onChange:e=>{a(e.target.value),r(Math.max(1,Math.round(parseInt(e.target.value)||0)))},onKeyDown:e=>{e.key===`Enter`&&t(n)}}),` `,e.unit??`rows`]})},ne=A();ne.displayName=`AddRows`;var re=(e,t)=>{let[n,r]=(0,c.useState)(e),i=(0,c.useRef)(void 0);return(0,c.useEffect)(()=>()=>i.current?.cancel(),[]),[n,(0,c.useMemo)(()=>i.current=(0,d.debounce)(t,e=>{r(e)}),[t])]},j=e=>e.type===`CUT`?(0,u.jsx)(u.Fragment,{children:`Cut`}):e.type===`COPY`?(0,u.jsx)(u.Fragment,{children:`Copy`}):e.type===`PASTE`?(0,u.jsx)(u.Fragment,{children:`Paste`}):e.type===`DELETE_ROW`?(0,u.jsx)(u.Fragment,{children:`Delete row`}):e.type===`DELETE_ROWS`?(0,u.jsxs)(u.Fragment,{children:[`Delete rows `,(0,u.jsx)(`b`,{children:e.fromRow}),` to `,(0,u.jsx)(`b`,{children:e.toRow})]}):e.type===`INSERT_ROW_BELLOW`?(0,u.jsx)(u.Fragment,{children:`Insert row below`}):e.type===`DUPLICATE_ROW`?(0,u.jsx)(u.Fragment,{children:`Duplicate row`}):e.type===`DUPLICATE_ROWS`?(0,u.jsxs)(u.Fragment,{children:[`Duplicate rows `,(0,u.jsx)(`b`,{children:e.fromRow}),` to `,(0,u.jsx)(`b`,{children:e.toRow})]}):e.type,M=(e=j)=>({clientX:t,clientY:n,items:r,close:i})=>{let a=(0,c.useRef)(null);return O(`mousedown`,(0,c.useCallback)(e=>{a.current?.contains(e.target)||i()},[i])),(0,u.jsx)(`div`,{className:`dsg-context-menu`,style:{left:t+`px`,top:n+`px`},ref:a,children:r.map(t=>(0,u.jsx)(`div`,{onClick:t.action,className:`dsg-context-menu-item`,children:e(t)},t.type))})},N=M(j);N.displayName=`ContextMenu`;var ie=typeof DOMParser<`u`?new DOMParser:{parseFromString:()=>null},ae=e=>ie.parseFromString(p.default.sanitize(e,{FORBID_TAGS:[`style`]}),`text/html`),oe=e=>{let t=ae(e.replace(/<br\/?>/g,`
2
- `)),n=t.getElementsByTagName(`table`)[0];if(n){let e=[];for(let t=0;t<n.rows.length;t++){let r=[];e.push(r);for(let e=0;e<n.rows[t].cells.length;e++)r.push(n.rows[t].cells[e].textContent??``)}return e}let r=t.getElementsByTagName(`span`)[0];return r?[[r.textContent??``]]:[[``]]},se=e=>{let t=e.replace(/\r|\n$/g,``),n=[[]],r=0,i=0,a=!1,o=0,s=()=>{let e=t.slice(i,r);e[0]===`"`&&e[e.length-1]===`"`&&(a=!0),a&&e[e.length-1]===`"`&&e.includes(`
3
- `)&&(e=e.slice(1,e.length-1).replace(/""/g,`"`),a=!1),a&&e[e.length-1]!==`"`?e.split(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react");c=s(c,1);let l=require("react-resize-detector"),u=require("react/jsx-runtime"),d=require("throttle-debounce"),f=require("fast-deep-equal");f=s(f,1);let p=require("dompurify");p=s(p,1);let m=require("@tanstack/react-virtual"),h=require("classnames");h=s(h,1);let g=require("react-dom");var _=(e,t)=>{let n=t.map(({basis:e,minWidth:t,maxWidth:n})=>({basis:e,minWidth:t,maxWidth:n,size:e,violation:0,frozen:!1,factor:0})),r=n.reduce((e,t)=>e-t.size,e);r>0?t.forEach(({grow:e},t)=>{n[t].factor=e}):r<0&&t.forEach(({shrink:e},t)=>{n[t].factor=e});for(let e of n)e.factor===0&&(e.frozen=!0);for(;n.some(({frozen:e})=>!e);){let t=n.reduce((e,t)=>e+(t.frozen?0:t.factor),0),i=0;for(let e of n)e.frozen||(e.size+=r*e.factor/t,e.violation=e.size<e.minWidth?e.minWidth-e.size:e.maxWidth!==void 0&&e.size>e.maxWidth?e.maxWidth-e.size:0,e.size+=e.violation,i+=e.violation);if(i>0)for(let e of n)e.violation>0&&(e.frozen=!0);else if(i<0)for(let e of n)e.violation<0&&(e.frozen=!0);else break;r=n.reduce((e,t)=>e-t.size,e)}return n.map(({size:e})=>e)},v=(e,t)=>{let n=e.map(({basis:e,minWidth:t,maxWidth:n,grow:r,shrink:i})=>[e,t,n,r,i].join(`,`)).join(`|`);return(0,c.useMemo)(()=>{if(t===void 0)return{fullWidth:!1,columnWidths:void 0,columnRights:void 0,totalWidth:void 0};let n=_(t,e),r=0,i=n.map((e,t)=>(r+=e,t===n.length-1?1/0:r));return{fullWidth:Math.abs(t-r)<.1,columnWidths:n,columnRights:i,totalWidth:r}},[t,n])},y=()=>(0,u.jsx)(u.Fragment,{}),b=()=>!1,x=({rowData:e})=>e,S=()=>null,C=({rowIndex:e})=>(0,u.jsx)(u.Fragment,{children:e+1}),w=()=>!0,T=e=>e,E=e=>{if(typeof e==`number`)return{basis:0,grow:e,shrink:1};if(/^ *\d+(\.\d*)? *$/.exec(e))return{basis:0,grow:Number.parseFloat(e.trim()),shrink:1};if(/^ *\d+(\.\d*)? *px *$/.exec(e))return{basis:Number.parseFloat(e.trim()),grow:1,shrink:1};if(/^ *\d+(\.\d*)? \d+(\.\d*)? *$/.exec(e)){let[t,n]=e.trim().split(` `);return{basis:0,grow:Number.parseFloat(t),shrink:Number.parseFloat(n)}}if(/^ *\d+(\.\d*)? \d+(\.\d*)? *px *$/.exec(e)){let[t,n]=e.trim().split(` `);return{basis:Number.parseFloat(n),grow:Number.parseFloat(t),shrink:1}}if(/^ *\d+(\.\d*)? \d+(\.\d*)? \d+(\.\d*)? *px *$/.exec(e)){let[t,n,r]=e.trim().split(` `);return{basis:Number.parseFloat(r),grow:Number.parseFloat(t),shrink:Number.parseFloat(n)}}return{basis:0,grow:1,shrink:1}},ee=(e,t,n,r=!1)=>(0,c.useMemo)(()=>{let i=[t===!1?{basis:0,grow:0,shrink:0,minWidth:0,component:()=>(0,u.jsx)(u.Fragment,{}),headerClassName:`dsg-hidden-cell`,cellClassName:`dsg-hidden-cell`,isCellEmpty:w}:{...t,basis:t?.basis??40,grow:t?.grow??0,shrink:t?.shrink??0,minWidth:t?.minWidth??0,title:t?.title??(0,u.jsx)(`div`,{className:`dsg-corner-indicator`}),component:t?.component??C,isCellEmpty:w},...e];return n&&i.push({...n,basis:n?.basis??40,grow:n?.grow??0,shrink:n?.shrink??0,minWidth:n.minWidth??0,isCellEmpty:w}),i.map((e,t)=>{let n=e.width===void 0?{basis:void 0,grow:void 0,shrink:void 0}:E(e.width),i=e.stickyLeft===void 0?t===1&&r:e.stickyLeft;return{...e,basis:e.basis??n.basis??0,grow:e.grow??n.grow??1,shrink:e.shrink??n.shrink??1,minWidth:e.minWidth??100,component:e.component??y,disableKeys:e.disableKeys??!1,disabled:e.disabled??!1,keepFocus:e.keepFocus??!1,deleteValue:e.deleteValue??x,copyValue:e.copyValue??S,pasteValue:e.pasteValue??x,prePasteValues:e.prePasteValues??T,isCellEmpty:e.isCellEmpty??b,stickyLeft:i}})},[t,n,e,r]),D=e=>{let[t,n]=(0,c.useState)(e);return[t,(0,c.useCallback)(e=>{n(t=>{let n=typeof e==`function`?e(t):e;return(0,f.default)(n,t)?t:n})},[n])]},te=(e,t,n)=>{let[r,i]=D({top:!0,right:!0,bottom:!0,left:!0});return(0,c.useEffect)(()=>{let r=(0,d.throttle)(100,()=>{i({top:e.current?.scrollTop===0,right:(e.current?.scrollLeft??0)>=(e.current?.scrollWidth??0)-(t??0)-1,bottom:(e.current?.scrollTop??0)>=(e.current?.scrollHeight??0)-(n??0)-1,left:e.current?.scrollLeft===0})}),a=e.current;return a?.addEventListener(`scroll`,r),setTimeout(r,100),()=>{a?.removeEventListener(`scroll`,r),r.cancel()}},[n,t,e,i]),r},O=(e,t)=>{(0,c.useEffect)(()=>{let n=(...e)=>{t(...e)};return document.addEventListener(e,n),()=>{document.removeEventListener(e,n)}},[t,e])},k=(e,t=200)=>{let n=(0,c.useRef)(null),r=(0,c.useMemo)(()=>(0,d.throttle)(t,!0,()=>{setTimeout(()=>n.current=e.current?.getBoundingClientRect()||null,0)}),[e,t]);return(0,c.useCallback)((t=!1)=>(t?n.current=e.current?.getBoundingClientRect()||null:r(),n.current),[e,r])},A=(e={})=>({addRows:t})=>{let[n,r]=(0,c.useState)(1),[i,a]=(0,c.useState)(String(n));return(0,u.jsxs)(`div`,{className:`dsg-add-row`,children:[(0,u.jsx)(`button`,{type:`button`,className:`dsg-add-row-btn`,onClick:()=>t(n),children:e.button??`Add`}),` `,(0,u.jsx)(`input`,{className:`dsg-add-row-input`,value:i,onBlur:()=>a(String(n)),type:`number`,min:1,onChange:e=>{a(e.target.value),r(Math.max(1,Math.round(parseInt(e.target.value)||0)))},onKeyDown:e=>{e.key===`Enter`&&t(n)}}),` `,e.unit??`rows`]})},ne=A();ne.displayName=`AddRows`;var re=(e,t)=>{let[n,r]=(0,c.useState)(e),i=(0,c.useRef)(void 0);return(0,c.useEffect)(()=>()=>i.current?.cancel(),[]),[n,(0,c.useMemo)(()=>i.current=(0,d.debounce)(t,e=>{r(e)}),[t])]},ie=e=>e.type===`CUT`?(0,u.jsx)(u.Fragment,{children:`Cut`}):e.type===`COPY`?(0,u.jsx)(u.Fragment,{children:`Copy`}):e.type===`PASTE`?(0,u.jsx)(u.Fragment,{children:`Paste`}):e.type===`DELETE_ROW`?(0,u.jsx)(u.Fragment,{children:`Delete row`}):e.type===`DELETE_ROWS`?(0,u.jsxs)(u.Fragment,{children:[`Delete rows `,(0,u.jsx)(`b`,{children:e.fromRow}),` to `,(0,u.jsx)(`b`,{children:e.toRow})]}):e.type===`INSERT_ROW_BELLOW`?(0,u.jsx)(u.Fragment,{children:`Insert row below`}):e.type===`DUPLICATE_ROW`?(0,u.jsx)(u.Fragment,{children:`Duplicate row`}):e.type===`DUPLICATE_ROWS`?(0,u.jsxs)(u.Fragment,{children:[`Duplicate rows `,(0,u.jsx)(`b`,{children:e.fromRow}),` to `,(0,u.jsx)(`b`,{children:e.toRow})]}):e.type,j=(e=ie)=>({clientX:t,clientY:n,items:r,close:i})=>{let a=(0,c.useRef)(null);return O(`mousedown`,(0,c.useCallback)(e=>{a.current?.contains(e.target)||i()},[i])),(0,u.jsx)(`div`,{className:`dsg-context-menu`,style:{left:t+`px`,top:n+`px`},ref:a,children:r.map(t=>(0,u.jsx)(`div`,{onClick:t.action,className:`dsg-context-menu-item`,children:e(t)},t.type))})},M=j(ie);M.displayName=`ContextMenu`;var ae=typeof DOMParser<`u`?new DOMParser:{parseFromString:()=>null},oe=e=>ae.parseFromString(p.default.sanitize(e,{FORBID_TAGS:[`style`]}),`text/html`),se=e=>{let t=oe(e.replaceAll(/<br\/?>/g,`
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
+ `)&&(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},ce=e=>/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,le=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`),ue=e=>e.match(/^[^\x00-\x20\x7F-\x9F]$/)!==null,de=(e,t,n,r)=>{if(e===null||!t||!n)return null;if(typeof e!=`object`)throw Error(`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 Error(`col or cell are not valid positive numbers`);return a},fe=(e,t)=>e?{col:e.col,row:e.row,colId:t[e.col+1]?.id}:null,pe=(e,t,n,r)=>{if(e===null||!t||!n)return null;if(typeof e!=`object`)throw Error(`Value must be an object or null`);let i={min:de(e.min,t,n,r),max:de(e.max,t,n,r)};if(!i.min||!i.max)throw Error(`min and max must be defined`);return i},me=(e,t)=>e?{min:fe(e.min,t),max:fe(e.max,t)}:null,he=()=>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`),ge=({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}),_e=(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]),ve=({data:e,columns:t,outerRef:n,innerRef:r,columnWidths:i,hasStickyRightColumn:a,pinFirstColumn:o,displayHeight:s,headerRowHeight:l,rowHeight:d,rowKey:f,fullWidth:p,selection:g,activeCell:_,rowClassName:v,cellClassName:y,children:b,editing:x,getContextMenuItems:S,setRowData:C,deleteRows:w,duplicateRows:T,insertRowAfter:E,stopEditing:ee,onScroll:D})=>{let te=(0,m.useVirtualizer)({count:e.length,getScrollElement:()=>n.current,paddingStart:l,estimateSize:e=>d(e).height,getItemKey:t=>{if(f&&t>0){let n=e[t-1];if(typeof f==`function`)return f({rowData:n,rowIndex:t});if(typeof f==`string`&&n instanceof Object&&f in n){let e=n[f];if(typeof e==`string`||typeof e==`number`)return e}}return t},overscan:5}),O=(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[n.length-1]!==t.length-1&&n.push(t.length-1),n}});(0,c.useEffect)(()=>{O.measure()},[O,i]);let k=_e(C,1),A=_e(w,0),ne=_e(T,0),re=_e(E,0),j=e=>{if(!t[e].stickyLeft)return 0;if(!i?.length){let t=O.getOffsetForIndex(e);return typeof t==`number`?t:0}let n=0;for(let t=0;t<e;t++)n+=i[t];return n},M=g?.min.col??_?.col,N=g?.max.col??_?.col,ie=g?.min.row??_?.row,ae=g?.max.row??_?.row;return(0,u.jsx)(`div`,{ref:n,className:`dsg-container`,onScroll:D,style:{height:s},children:(0,u.jsxs)(`div`,{ref:r,style:{width:p?`100%`:O.getTotalSize(),height:te.getTotalSize()},children:[l>0&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,`dsg-row-header`),style:{width:p?`100%`:O.getTotalSize(),height:l},children:O.getVirtualItems().map(e=>{let n=!!t[e.index].stickyLeft;return(0,u.jsx)(ge,{gutter:e.index===0,stickyRight:a&&e.index===t.length-1,stickyLeft:n,width:e.size,left:n?j(e.index):e.start,className:(0,h.default)(`dsg-cell-header`,M!==void 0&&N!==void 0&&M<=e.index-1&&N>=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)})}),te.getVirtualItems().map(n=>{let r=n.index>=(ie??1/0)&&n.index<=(ae??-1/0);return(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,typeof v==`string`?v:null,typeof v==`function`?v({rowData:e[n.index],rowIndex:n.index}):null),style:{height:n.size,top:n.start,width:p?`100%`:O.getTotalSize()},children:O.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=_?.row===n.index&&_.col===i.index-1,f=!!t[i.index].stickyLeft;return(0,u.jsx)(ge,{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 y==`function`?y({rowData:e[n.index],rowIndex:n.index,columnId:t[i.index].id}):y),width:i.size,left:f?j(i.index):i.start,children:(0,u.jsx)(c,{rowData:e[n.index],getContextMenuItems:S,disabled:l,active:d,columnIndex:i.index-1,rowIndex:n.index,focus:d&&x,deleteRow:A(n.index),duplicateRow:ne(n.index),stopEditing:ee,insertRowBelow:re(n.index),setRowData:k(n.index),columnData:t[i.index].columnData})},i.key)})},n.key)}),b]})})},P=(e,t,n,r)=>[[r,e],[t,e],[t,n],[r,n],[r,e]],ye=(e,t,n,r)=>`polygon(evenodd, ${[...P(0,`100%`,`100%`,0),...P(e,t,n,r)].map(e=>e.map(e=>typeof e==`number`&&e!==0?e+`px`:e).join(` `)).join(`,`)})`,be=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],j=re&&y?y((r?.min.col??a?.col??0)+1):0,M=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}%)`},N=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};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]-(o?e[e.length-1]:0):`calc(100% - ${e[0]+(o?e[e.length-1]:0)}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:j,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:ye(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:ye(w.top-T.top,ee-te,w.top+w.height-T.top,ee+w.width-te)}})}),N&&!D&&(0,u.jsx)(`div`,{className:`dsg-expand-rows-rect`,style:N}),N&&D&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:N.top,left:0,right:0,height:N.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:N.width,height:`100%`}})}),M&&!A&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-indicator`,x&&`dsg-expand-rows-indicator-disabled`),style:M}),M&&A&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:M.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:M.transform,pointerEvents:`auto`}})})]})});be.displayName=`SelectionRect`;var xe=({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[n.current.length-1].top+n.current[n.current.length-1].height;for(let a=n.current.length;a<=r;a++){let r=t({rowIndex:a,rowData:e[a]});n.current.push({height:r,top:i}),i+=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])},Se=[],Ce=[],we=()=>({}),Te=()=>null,Ee=({rowData:e})=>({...e}),F=c.default.memo(c.default.forwardRef(({value:e=Se,className:t,style:n,height:r=400,onChange:i=Te,columns:a=Ce,rowHeight:o=40,headerRowHeight:s=typeof o==`number`?o:40,gutterColumn:d,stickyRightColumn:p,rowKey:m,addRowsComponent:h=ne,createRow:g=we,autoAddRow:_=!1,lockRows:y=!1,disableExpandSelection:b=!1,disableSmartDelete:x=!1,duplicateRow:S=Ee,contextMenuComponent:C=N,disableContextMenu:w=!1,onFocus:T=Te,onBlur:E=Te,onActiveCellChange:A=Te,onSelectionChange:j=Te,rowClassName:M,cellClassName:ie,onScroll:ae,pinFirstColumn:ge=!1},_e)=>{let P=(0,c.useRef)(null),ye=w||y,F=ee(a,d,p,ge),I=!!p,De=ge||!!F[1]?.stickyLeft,Oe=(0,c.useRef)(null),L=(0,c.useRef)(null),ke=(0,c.useRef)(null),Ae=(0,c.useRef)(null),[je,Me]=re(1,100),{getRowSize:Ne,totalSize:Pe,getRowIndex:Fe}=xe({value:e,rowHeight:o}),Ie=Math.min(r,s+Pe(r)+je),{width:Le,height:R}=(0,l.useResizeDetector)({targetRef:L,refreshMode:`throttle`,refreshRate:100});Me(R?Ie-R:0);let Re=te(L,Le,R),{fullWidth:ze,totalWidth:Be,columnWidths:z,columnRights:B}=v(F,Le),Ve=(0,c.useMemo)(()=>F.slice(1).map(e=>!!e.stickyLeft),[F]),He=(0,c.useCallback)(e=>{if(!F[e]?.stickyLeft)return 0;if(!z?.length){let t=0;for(let n=0;n<e;n++)(F[n].stickyLeft||n===0)&&(t+=F[n].basis||F[n].minWidth||100);return t}let t=0;for(let n=0;n<e;n++)(F[n].stickyLeft||n===0)&&(t+=z[n]);return t},[F,z]),[Ue,V]=(0,c.useState)(null),[We,Ge]=(0,c.useState)([]),[H,U]=(0,c.useState)(!1),[Ke,qe]=(0,c.useState)(0),[Je,Ye]=(0,c.useState)(null),[W,G]=D(null),[K,q]=D(null),J=(0,c.useMemo)(()=>W&&K&&{min:{col:Math.min(W.col,K.col),row:Math.min(W.row,K.row)},max:{col:Math.max(W.col,K.col),row:Math.max(W.row,K.row)}},[W,K]),[Y,Xe]=D({columns:!1,rows:!1,active:!1}),Ze=b||H||Y.active||W?.row===e?.length-1||J?.max.row===e?.length-1||W&&F.slice((J?.min.col??W.col)+1,(J?.max.col??W.col)+2).every(e=>e.disabled===!0)?null:Ke,Qe=k(Oe),$e=k(L);(0,c.useEffect)(()=>{W!==null&&(document.activeElement.blur(),window.getSelection()?.removeAllRanges())},[W!==null]);let et=(0,c.useCallback)((e,t=!1,n=!1)=>{let r=Qe(t),i=n&&$e(t);if(r&&B&&z){let t=e.clientX-r.left,n=e.clientY-r.top;return i&&(e.clientY-i.top<=s&&(n=0),e.clientX-i.left<=z[0]&&(t=0),De&&e.clientX-i.left<=z[0]+z[1]&&(t=B[0]+1),I&&i.right-e.clientX<=z[z.length-1]&&(t=B[B.length-2]+1)),{col:B.findIndex(e=>t<e)-1,row:Fe(n-s)}}return null},[B,z,e.length,Qe,$e,s,I,De,Fe]),X=(0,c.useRef)(e);X.current=e;let Z=(0,c.useCallback)(e=>{let t=F[e.col+1].disabled;return!!(typeof t==`function`?t({rowData:X.current[e.row],rowIndex:e.row}):t)},[F]),Q=(0,c.useCallback)((e,t=1)=>{y||(q(null),U(!1),i([...X.current.slice(0,e+1),...Array(t).fill(0).map(g),...X.current.slice(e+1)],[{type:`CREATE`,fromRowIndex:e+1,toRowIndex:e+1+t}]),G(n=>({col:n?.col||0,row:e+t,doNotScrollX:!0})))},[g,y,i,G,q]),tt=(0,c.useCallback)((e,t=e)=>{y||(i([...X.current.slice(0,t+1),...X.current.slice(e,t+1).map((t,n)=>S({rowData:t,rowIndex:n+e})),...X.current.slice(t+1)],[{type:`CREATE`,fromRowIndex:t+1,toRowIndex:t+2+t-e}]),G({col:0,row:t+1,doNotScrollX:!0}),q({col:F.length-(I?3:2),row:2*t-e+1,doNotScrollX:!0}),U(!1))},[F.length,S,y,i,G,q,I]),$=(0,c.useCallback)(e=>{if(!(!R||!Le)){if(!e.doNotScrollY){let t=Ne(e.row).top,n=Ne(e.row).top+Ne(e.row).height+s-R+1,r=L.current.scrollTop;r>t?L.current.scrollTop=t:r<n&&(L.current.scrollTop=n)}if(B&&z&&L.current&&!e.doNotScrollX){let t=B[e.col]-B[0],n=B[e.col]+z[e.col+1]+(I?z[z.length-1]:0)-Le+1,r=L.current.scrollLeft;r>t?L.current.scrollLeft=t:r<n&&(L.current.scrollLeft=n)}}},[R,Le,s,B,z,Ne,I]);(0,c.useEffect)(()=>{K&&$(K)},[K,$]),(0,c.useEffect)(()=>{W&&$(W)},[W,$]);let nt=(0,c.useCallback)((e,t)=>{i([...X.current?.slice(0,e),t,...X.current?.slice(e+1)],[{type:`UPDATE`,fromRowIndex:e,toRowIndex:e+1}])},[i]),rt=(0,c.useCallback)((e,t=e)=>{y||(U(!1),G(n=>{let r=Math.min(X.current.length-2-t+e,e);return r<0?null:n&&{col:n.col,row:r}}),q(null),i([...X.current.slice(0,e),...X.current.slice(t+1)],[{type:`DELETE`,fromRowIndex:e,toRowIndex:t+1}]))},[y,i,G,q]),it=(0,c.useCallback)((t=!0)=>{let n=t&&!x;if(!W)return;let r=J?.min||W,a=J?.max||W;if(e.slice(r.row,a.row+1).every((e,t)=>F.every(n=>n.isCellEmpty({rowData:e,rowIndex:t+r.row})))){n&&rt(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(!Z({col:t,row:e})){let{deleteValue:n=({rowData:e})=>e}=F[t+1];o[e]=n({rowData:o[e],rowIndex:e})}if(n&&(0,f.default)(o,e)){G({col:0,row:r.row,doNotScrollX:!0}),q({col:F.length-(I?3:2),row:a.row,doNotScrollX:!0});return}i(o,[{type:`UPDATE`,fromRowIndex:r.row,toRowIndex:a.row+1}])},[W,F,e,rt,Z,i,J?.max,J?.min,G,q,I]),at=(0,c.useCallback)(({nextRow:e=!0}={})=>{W?.row===X.current.length-1?e&&_?Q(W.row):U(!1):(U(!1),e&&G(e=>e&&{col:e.col,row:e.row+1}))},[W?.row,_,Q,G]),ot=(0,c.useCallback)(async t=>{if(!H&&W){let n=[],r=J?.min||W,i=J?.max||W;for(let t=r.row;t<=i.row;++t){n.push([]);for(let a=r.col;a<=i.col;++a){let{copyValue:i=()=>null}=F[a+1];n[t-r.row].push(i({rowData:e[t],rowIndex:t}))}}let a=n.map(e=>e.map(e=>ce(String(e??``))).join(` `)).join(`
6
- `),o=`<table>${n.map(e=>`<tr>${e.map(e=>`<td>${le(String(e??``)).replace(/\n/g,`<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`)}},[W,F,e,H,J]);O(`copy`,ot);let st=(0,c.useCallback)(e=>{!H&&W&&(ot(e),it(!1))},[W,it,H,ot]);O(`cut`,st);let ct=(0,c.useCallback)(async t=>{if(!H&&W){let n=J?.min||W,r=J?.max||W,a=await Promise.all(t[0].map((e,r)=>{let i=F[n.col+r+1]?.prePasteValues,a=t.map(e=>e[r]);return 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=F[n.col+e+1]?.pasteValue;if(i)for(let o=n.row;o<=r.row;o++)Z({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}]),G({col:n.col,row:n.row}),q({col:Math.min(n.col+t[0].length-1,F.length-(I?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<F.length-(I?2:1);e++){let i=F[n.col+e+1]?.pasteValue;if(i)for(let a=0;a<t.length;a++)Z({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),G({col:n.col,row:n.row}),q({col:Math.min(n.col+t[0].length-1,F.length-(I?3:2)),row:n.row+t.length-1})}}},[W,F,g,e,H,I,Z,y,i,J?.max,J?.min,G,q]);O(`paste`,(0,c.useCallback)(e=>{if(W&&!H){let t=[[``]];e.clipboardData?.types.includes(`text/html`)?t=oe(e.clipboardData?.getData(`text/html`)):e.clipboardData?.types.includes(`text/plain`)?t=se(e.clipboardData?.getData(`text/plain`)):e.clipboardData?.types.includes(`text`)&&(t=se(e.clipboardData?.getData(`text`))),ct(t),e.preventDefault()}},[W,ct,H])),O(`mousedown`,(0,c.useCallback)(t=>{if(Ue&&We.length)return;let n=t.button===2||t.button===0&&t.ctrlKey,r=Oe.current?.contains(t.target)||!1,i=r?et(t,!0,!0):null;if(!r&&H&&W&&F[W.col+1].keepFocus)return;if(t.target instanceof HTMLElement&&t.target.className.includes(`dsg-expand-rows-indicator`)){Ye(Math.max(W?.row??0,J?.max.row??0));return}let a=i&&W&&W.col===i.col&&W.row===i.row&&!Z(W),o=H&&t.target instanceof HTMLElement&&t.target.classList.contains(`dsg-input`);if((a||o)&&H)return;let s=i?.col===F.length-2&&I,c=n&&J&&i&&i.row>=J.min.row&&i.row<=J.max.row&&i.col>=J.min.col&&i.col<=J.max.col,l=n&&J&&i?.row===-1&&i.col>=J.min.col&&i.col<=J.max.col,u=n&&J&&i&&i.row>=J.min.row&&i.row<=J.max.row&&i.col===-1,d=s&&J&&i&&i.row>=J.min.row&&i.row<=J.max.row;if(n&&!ye&&V({x:t.clientX,y:t.clientY,cursorIndex:i}),(!(t.shiftKey&&W)||n)&&e.length>0&&G(i&&{col:(c||l)&&W?W.col:Math.max(0,s?0:i.col),row:(c||u||d)&&W?W.row:Math.max(0,i.row),doNotScrollX:!!(c&&W||s||i.col===-1),doNotScrollY:!!(c&&W||i.row===-1)}),a&&!n&&(P.current=W),U(!!(a&&!n)),Xe(i&&!n?{columns:i.col!==-1&&!s||!!(t.shiftKey&&W),rows:i.row!==-1||!!(t.shiftKey&&W),active:!0}:{columns:!1,rows:!1,active:!1}),t.shiftKey&&W&&!n)q(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=F.length-(I?3:2),r=!0),i.row===-1&&(n=e.length-1,a=!0),l&&K&&(t=K.col,a=!0),(u||d)&&K&&(n=K.row,r=!0),q({col:t,row:n,doNotScrollX:r,doNotScrollY:a})}else q(null);r&&t.preventDefault()}},[Ue,We.length,et,H,W,F,Z,J,I,ye,Xe,G,q,K,e.length])),O(`mouseup`,(0,c.useCallback)(()=>{if(Je!==null){if(Ke>0&&W){let t=[],n=J?.min||W,r=J?.max||W;for(let i=n.row;i<=r.row;++i){t.push([]);for(let a=n.col;a<=r.col;++a){let{copyValue:r=()=>null}=F[a+1];t[i-n.row].push(String(r({rowData:e[i],rowIndex:i})??``))}}Promise.all(t[0].map((e,r)=>{let i=F[n.col+r+1]?.prePasteValues,a=t.map(e=>e[r]);return 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=F[n.col+e+1]?.pasteValue;if(i)for(let a=r.row+1;a<=r.row+Ke;a++)Z({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+Ke}])}),qe(0),G({col:Math.min(W?.col??1/0,J?.min.col??1/0),row:Math.min(W?.row??1/0,J?.min.row??1/0),doNotScrollX:!0,doNotScrollY:!0}),q({col:Math.max(W?.col??0,J?.max.col??0),row:Math.max(W?.row??0,J?.max.row??0)+Ke})}Ye(null)}Xe({columns:!1,rows:!1,active:!1})},[Je,Xe,Ke,W,J?.min,J?.max,e,i,G,q,F,Z])),O(`mousemove`,(0,c.useCallback)(t=>{if(Je!==null){let e=et(t);e&&(qe(Math.max(0,e.row-Je)),$({col:e.col,row:Math.max(e.row,Je)}))}if(Y.active){let n=et(t),r=F.length-(I?3:2);q(n&&{col:Y.columns?Math.max(0,Math.min(r,n.col)):r,row:Y.rows?Math.max(0,n.row):e.length-1,doNotScrollX:!Y.columns,doNotScrollY:!Y.rows}),U(!1)}},[$,Y.active,Y.columns,Y.rows,et,F.length,I,q,e.length,Je])),O(`keydown`,(0,c.useCallback)(t=>{if(W&&!t.isComposing){if(t.key===`Tab`&&!t.shiftKey&&W.col===F.length-(I?3:2)&&!F[W.col+1].disableKeys)if(W.row===e.length-1){if(Ae.current){t.preventDefault(),G(null),q(null),U(!1);let e=he();e[(e.indexOf(Ae.current)+1)%e.length].focus();return}}else{G(e=>({col:0,row:(e?.row??0)+1})),q(null),U(!1),t.preventDefault();return}if(t.key===`Tab`&&t.shiftKey&&W.col===0&&!F[W.col+1].disableKeys)if(W.row===0){if(ke.current){t.preventDefault(),G(null),q(null),U(!1);let e=he();e[(e.indexOf(ke.current)-1+e.length)%e.length].focus();return}}else{G(e=>({col:F.length-(I?3:2),row:(e?.row??1)-1})),q(null),U(!1),t.preventDefault();return}if(t.key?.startsWith(`Arrow`)||t.key===`Tab`){if(H&&F[W.col+1].disableKeys||H&&[`ArrowLeft`,`ArrowRight`].includes(t.key))return;let n=([t,n],r)=>r&&{col:Math.max(0,Math.min(F.length-(I?3:2),r.col+t)),row:Math.max(0,Math.min(e.length-1,r.row+n))};if(t.key===`Tab`&&t.shiftKey)G(e=>n([-1,0],e)),q(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]*=F.length,r[1]*=e.length),t.shiftKey?q(e=>n(r,e||W)):(G(e=>n(r,e)),q(null))}U(!1),t.preventDefault()}else t.key===`Escape`?(!H&&!K&&G(null),q(null),U(!1)):(t.key===`Enter`||t.key===`F2`)&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&!t.shiftKey?(q(null),H?F[W.col+1].disableKeys||(at(),t.preventDefault()):Z(W)||(P.current=W,U(!0),$(W),t.preventDefault())):t.key===`Enter`&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&t.shiftKey&&!H?Q(J?.max.row||W.row):t.key===`d`&&(t.ctrlKey||t.metaKey)&&!t.altKey&&!t.shiftKey?(tt(J?.min.row||W.row,J?.max.row),t.preventDefault()):(ue(t.key)||t.code.match(/Key[A-Z]$/))&&!t.ctrlKey&&!t.metaKey&&!t.altKey?!H&&!Z(W)&&(P.current=W,q(null),U(!0),$(W)):[`Backspace`,`Delete`].includes(t.key)?H||(it(),t.preventDefault()):t.key===`a`&&(t.ctrlKey||t.metaKey)&&(H||(G({col:0,row:0,doNotScrollY:!0,doNotScrollX:!0}),q({col:F.length-(I?3:2),row:e.length-1,doNotScrollY:!0,doNotScrollX:!0}),t.preventDefault()))}},[W,F,e.length,it,tt,H,Q,Z,$,J?.max.row,J?.min.row,K,G,q,at,I])),O(`contextmenu`,(0,c.useCallback)(e=>{let t=Oe.current?.contains(e.target)||!1,n=t?et(e,!0,!0):null,r=n&&W&&W.col===n.col&&W.row===n.row&&H;t&&!r&&e.preventDefault()},[et,W,H])),(0,c.useEffect)(()=>{let e=[];W?.row!==void 0&&e.push({type:`COPY`,action:()=>{ot(),V(null)}},{type:`CUT`,action:()=>{st(),V(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=oe(await(await t.getType(`text/html`)).text()):t.types.includes(`text/plain`)?e=se(await(await t.getType(`text/plain`)).text()):t.types.includes(`text`)&&(e=oe(await(await t.getType(`text`)).text())),await ct(e)}}else navigator.clipboard.readText===void 0?alert(`This action is unavailable in your browser, but you can still use Ctrl+V for paste`):await ct(se(await navigator.clipboard.readText()));V(null)})()}}),J?.max.row===void 0?W?.row!==void 0&&e.push({type:`INSERT_ROW_BELLOW`,action:()=>{V(null),Q(W.row)}}):e.push({type:`INSERT_ROW_BELLOW`,action:()=>{V(null),Q(J.max.row)}}),J?.min.row!==void 0&&J.min.row!==J.max.row?e.push({type:`DUPLICATE_ROWS`,fromRow:J.min.row+1,toRow:J.max.row+1,action:()=>{V(null),tt(J.min.row,J.max.row)}}):W?.row!==void 0&&e.push({type:`DUPLICATE_ROW`,action:()=>{V(null),tt(W.row)}}),J?.min.row!==void 0&&J.min.row!==J.max.row?e.push({type:`DELETE_ROWS`,fromRow:J.min.row+1,toRow:J.max.row+1,action:()=>{V(null),rt(J.min.row,J.max.row)}}):W?.row!==void 0&&e.push({type:`DELETE_ROW`,action:()=>{V(null),rt(W.row)}}),Ge(e),e.length||V(null)},[J,W,rt,tt,Q,st,ot,ct]);let lt=(0,c.useRef)(We);lt.current=We;let ut=(0,c.useCallback)(()=>lt.current,[]);(0,c.useImperativeHandle)(_e,()=>({activeCell:fe(W,F),selection:me(J??(W?{min:W,max:W}:null),F),setSelection:t=>{let n=pe(t,F.length-(I?2:1),e.length,F);G(n?.min||null),U(!1),Xe({columns:!1,active:!1,rows:!1}),q(n?.max||null)},setActiveCell:t=>{G(de(t,F.length-(I?2:1),e.length,F)),U(!1),Xe({columns:!1,active:!1,rows:!1}),q(null)}}));let dt=(0,c.useRef)({onFocus:T,onBlur:E,onActiveCellChange:A,onSelectionChange:j});return dt.current.onFocus=T,dt.current.onBlur=E,dt.current.onActiveCellChange=A,dt.current.onSelectionChange=j,(0,c.useEffect)(()=>{P.current&&(H?dt.current.onFocus({cell:fe(P.current,F)}):dt.current.onBlur({cell:fe(P.current,F)}))},[H,F]),(0,c.useEffect)(()=>{dt.current.onActiveCellChange({cell:fe(W,F)})},[W?.col,W?.row,F]),(0,c.useEffect)(()=>{dt.current.onSelectionChange({selection:me(J??(W?{min:W,max:W}:null),F)})},[J?.min.col??W?.col,J?.min.row??W?.row,J?.max.col??W?.col,J?.max.row??W?.row,W?.col,W?.row,F]),(0,u.jsxs)(`div`,{className:t,style:n,children:[(0,u.jsx)(`div`,{ref:ke,tabIndex:a.length&&e.length?0:void 0,onFocus:e=>{e.target.blur(),G({col:0,row:0})}}),(0,u.jsx)(ve,{columns:F,outerRef:L,columnWidths:z,hasStickyRightColumn:I,pinFirstColumn:ge,displayHeight:Ie,data:e,fullWidth:ze,headerRowHeight:s,activeCell:W,innerRef:Oe,rowHeight:Ne,rowKey:m,selection:J,rowClassName:M,editing:H,getContextMenuItems:ut,setRowData:nt,deleteRows:rt,insertRowAfter:Q,duplicateRows:tt,stopEditing:at,cellClassName:ie,onScroll:ae,children:(0,u.jsx)(be,{columnRights:B,columnWidths:z,activeCell:W,selection:J,headerRowHeight:s,rowHeight:Ne,hasStickyRightColumn:I,dataLength:e.length,viewHeight:R,viewWidth:Le,contentWidth:ze?void 0:Be,edges:Re,editing:H,isCellDisabled:Z,expandSelection:Ze,stickyLeftColumns:Ve,getStickyLeftOffset:He})}),(0,u.jsx)(`div`,{ref:Ae,tabIndex:a.length&&e.length?0:void 0,onFocus:t=>{t.target.blur(),G({col:F.length-(I?3:2),row:e.length-1})}}),!y&&h&&(0,u.jsx)(h,{addRows:t=>Q(e.length-1,t)}),Ue&&We.length>0&&(0,u.jsx)(C,{clientX:Ue.x,clientY:Ue.y,cursorIndex:Ue.cursorIndex,items:We,close:()=>V(null)})]})}));F.displayName=`DataSheetGrid`;var I=c.default.forwardRef(({columns:e,gutterColumn:t,stickyRightColumn:n,addRowsComponent:r,createRow:i,duplicateRow:a,style:o,rowKey:s,onFocus:l,onBlur:d,onActiveCellChange:f,onSelectionChange:p,rowClassName:m,rowHeight:h,...g},_)=>{let[v]=(0,c.useState)({columns:e,gutterColumn:t,stickyRightColumn:n,addRowsComponent:r,createRow:i,duplicateRow:a,style:o,rowKey:s,onFocus:l,onBlur:d,onActiveCellChange:f,onSelectionChange:p,rowClassName:m,rowHeight:h});return(0,u.jsx)(F,{...v,...g,rowHeight:typeof h==`number`?h:v.rowHeight,ref:_})}),De=()=>{let e=(0,c.useRef)(!0),t=e.current;return e.current=!1,t},Oe=`.dsg-cell-sticky-left, .dsg-cell-gutter`,L=`.dsg-cell-sticky-right`,ke=1;function Ae(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(Oe)||Array.from(a.querySelectorAll(Oe)).forEach(e=>{i.left=Math.max(i.left,e.getBoundingClientRect().right)}),t?.matches(L)||Array.from(a.querySelectorAll(L)).forEach(e=>{i.right=Math.min(i.right,e.getBoundingClientRect().left)}),i):i}function je(e,t){return e.top>=t.top-ke&&e.top<=t.bottom+ke&&e.left>=t.left-ke&&e.left<=t.right+ke}var Me=(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,Ne=480,Pe=300,Fe=(e,t,n,r,i)=>Math.max(0,Math.min(Math.max(e,n),r-t-i)),Ie=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=De(),[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`))||Ne,r=parseFloat(t.getPropertyValue(`--dsg-cell-expanded-max-height`))||Pe,i=m.closest(`.dsg-container`),a=m.closest(`.dsg-cell`),o,s=()=>{let e=m.getBoundingClientRect(),t=Fe(e.width,e.left,n,window.innerWidth,8),c=Fe(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||je(e,Ae(i,a))};y(e=>Me(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)]})});Ie.displayName=`TextComponent`;var Le=R();function R({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:Ie,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 Re=[``,`false`,`no`,`off`,`disabled`,`0`,`n`,`f`,`unchecked`,`undefined`,`null`,`wrong`,`negative`],ze=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})});ze.displayName=`CheckboxComponent`;var Be={component:ze,deleteValue:()=>!1,copyValue:({rowData:e})=>e?`YES`:`NO`,pasteValue:({value:e})=>!Re.includes(e.toLowerCase()),isCellEmpty:({rowData:e})=>!e},z=R({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}}),B=R({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)}}),Ve=0xe8d4a51000,He=1e10,Ue=R({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*Ve)/He):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:t/100},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:t}}),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?.toISOString().substr(0,10)??``,onChange:e=>{let t=new Date(e.target.value);r(isNaN(t.getTime())?null:t)}})});V.displayName=`DateComponent`;var We={component:V,deleteValue:()=>null,copyValue:({rowData:e})=>e?e.toISOString().substr(0,10):null,pasteValue:({value:e})=>{let t=new Date(e.replace(/\.\s?|\//g,`-`));return isNaN(t.getTime())?null:t},minWidth:170,isCellEmpty:({rowData:e})=>!e},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??``,onChange:e=>{let t=new Date(e.target.value);r(isNaN(t.getTime())?null:t.toISOString().substr(0,10))}})});Ge.displayName=`IsoDateComponent`;var H={component:Ge,deleteValue:()=>null,copyValue:({rowData:e})=>e,pasteValue:({value:e})=>{let t=new Date(e.replace(/\.\s?|\//g,`-`));return isNaN(t.getTime())?null:t.toISOString().substr(0,10)},minWidth:170,isCellEmpty:({rowData:e})=>!e},U=({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})},Ke=(e,t)=>({id:e,...t,columnData:{key:e,original:t},component:U,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=F,Je=I;exports.DataSheetGrid=Je,exports.DynamicDataSheetGrid=qe,exports.checkboxColumn=Be,exports.createAddRowsComponent=A,exports.createContextMenuComponent=M,exports.createTextColumn=R,exports.dateColumn=We,exports.floatColumn=z,exports.intColumn=B,exports.isoDateColumn=H,exports.keyColumn=Ke,exports.percentColumn=Ue,exports.renderContextMenuItem=j,exports.textColumn=Le;
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(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`).replaceAll(`'`,`&#039;`),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(`
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
8
  //# sourceMappingURL=index.cjs.map