@sage-bionetworks/react-datasheet-grid 4.11.5-sage.8 → 4.11.5-sage.9

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.
Files changed (69) hide show
  1. package/README.md +29 -19
  2. package/dist/index.cjs +7 -10
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +323 -28
  5. package/dist/index.js +1899 -3363
  6. package/dist/index.js.map +1 -1
  7. package/dist/style.css +2 -1
  8. package/package.json +59 -58
  9. package/dist/columns/checkboxColumn.d.ts +0 -3
  10. package/dist/columns/checkboxColumn.d.ts.map +0 -1
  11. package/dist/columns/dateColumn.d.ts +0 -3
  12. package/dist/columns/dateColumn.d.ts.map +0 -1
  13. package/dist/columns/floatColumn.d.ts +0 -9
  14. package/dist/columns/floatColumn.d.ts.map +0 -1
  15. package/dist/columns/intColumn.d.ts +0 -9
  16. package/dist/columns/intColumn.d.ts.map +0 -1
  17. package/dist/columns/isoDateColumn.d.ts +0 -3
  18. package/dist/columns/isoDateColumn.d.ts.map +0 -1
  19. package/dist/columns/keyColumn.d.ts +0 -8
  20. package/dist/columns/keyColumn.d.ts.map +0 -1
  21. package/dist/columns/percentColumn.d.ts +0 -9
  22. package/dist/columns/percentColumn.d.ts.map +0 -1
  23. package/dist/columns/textColumn.d.ts +0 -24
  24. package/dist/columns/textColumn.d.ts.map +0 -1
  25. package/dist/components/AddRows.d.ts +0 -8
  26. package/dist/components/AddRows.d.ts.map +0 -1
  27. package/dist/components/Cell.d.ts +0 -13
  28. package/dist/components/Cell.d.ts.map +0 -1
  29. package/dist/components/ContextMenu.d.ts +0 -7
  30. package/dist/components/ContextMenu.d.ts.map +0 -1
  31. package/dist/components/DataSheetGrid.d.ts +0 -6
  32. package/dist/components/DataSheetGrid.d.ts.map +0 -1
  33. package/dist/components/Grid.d.ts +0 -44
  34. package/dist/components/Grid.d.ts.map +0 -1
  35. package/dist/components/SelectionRect.d.ts +0 -4
  36. package/dist/components/SelectionRect.d.ts.map +0 -1
  37. package/dist/components/StaticDataSheetGrid.d.ts +0 -6
  38. package/dist/components/StaticDataSheetGrid.d.ts.map +0 -1
  39. package/dist/hooks/useColumnWidths.d.ts +0 -14
  40. package/dist/hooks/useColumnWidths.d.ts.map +0 -1
  41. package/dist/hooks/useColumns.d.ts +0 -8
  42. package/dist/hooks/useColumns.d.ts.map +0 -1
  43. package/dist/hooks/useDebounceState.d.ts +0 -2
  44. package/dist/hooks/useDebounceState.d.ts.map +0 -1
  45. package/dist/hooks/useDeepEqualState.d.ts +0 -3
  46. package/dist/hooks/useDeepEqualState.d.ts.map +0 -1
  47. package/dist/hooks/useDocumentEventListener.d.ts +0 -2
  48. package/dist/hooks/useDocumentEventListener.d.ts.map +0 -1
  49. package/dist/hooks/useEdges.d.ts +0 -8
  50. package/dist/hooks/useEdges.d.ts.map +0 -1
  51. package/dist/hooks/useFirstRender.d.ts +0 -2
  52. package/dist/hooks/useFirstRender.d.ts.map +0 -1
  53. package/dist/hooks/useGetBoundingClientRect.d.ts +0 -3
  54. package/dist/hooks/useGetBoundingClientRect.d.ts.map +0 -1
  55. package/dist/hooks/useMemoizedIndexCallback.d.ts +0 -2
  56. package/dist/hooks/useMemoizedIndexCallback.d.ts.map +0 -1
  57. package/dist/hooks/useRowHeights.d.ts +0 -13
  58. package/dist/hooks/useRowHeights.d.ts.map +0 -1
  59. package/dist/index.d.ts.map +0 -1
  60. package/dist/types.d.ts +0 -202
  61. package/dist/types.d.ts.map +0 -1
  62. package/dist/utils/copyPasting.d.ts +0 -5
  63. package/dist/utils/copyPasting.d.ts.map +0 -1
  64. package/dist/utils/domParser.d.ts +0 -2
  65. package/dist/utils/domParser.d.ts.map +0 -1
  66. package/dist/utils/tab.d.ts +0 -2
  67. package/dist/utils/tab.d.ts.map +0 -1
  68. package/dist/utils/typeCheck.d.ts +0 -6
  69. package/dist/utils/typeCheck.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,19 +1,22 @@
1
- # react-datasheet-grid
1
+ # @sage-bionetworks/react-datasheet-grid
2
2
 
3
- ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/nick-keller/react-datasheet-grid/tests.yml?branch=master)
4
- [![Coveralls](https://img.shields.io/coveralls/github/nick-keller/react-datasheet-grid)](https://coveralls.io/github/nick-keller/react-datasheet-grid)
5
- [![npm](https://img.shields.io/npm/dm/react-datasheet-grid)](https://www.npmjs.com/package/react-datasheet-grid)
6
- [![GitHub last commit](https://img.shields.io/github/last-commit/nick-keller/react-datasheet-grid)](https://github.com/nick-keller/react-datasheet-grid)
7
- ![npm bundle size](https://img.shields.io/bundlephobia/min/react-datasheet-grid)
8
- [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
3
+ A Sage Bionetworks fork of [nick-keller/react-datasheet-grid](https://github.com/nick-keller/react-datasheet-grid),
4
+ published to npm as `@sage-bionetworks/react-datasheet-grid` and consumed by
5
+ `synapse-react-client`.
9
6
 
10
- View [demo and documentation](https://react-datasheet-grid.netlify.app/)
7
+ The fork previously lived in its own repository at
8
+ [Sage-Bionetworks/react-datasheet-grid](https://github.com/sage-bionetworks/react-datasheet-grid);
9
+ its sources were migrated here from commit `96e0c33`, which remains the archive
10
+ for the pre-migration history.
11
+
12
+ View the upstream [demo and documentation](https://react-datasheet-grid.netlify.app/)
11
13
 
12
14
  An Airtable-like / Excel-like component to create beautiful spreadsheets.
13
15
 
14
16
  ![Preview](./images/preview.png)
15
17
 
16
18
  Feature rich:
19
+
17
20
  - Dead simple to set up and to use
18
21
  - Supports copy / pasting to and from Excel, Google-sheet...
19
22
  - Keyboard navigation and shortcuts fully-supported
@@ -29,7 +32,7 @@ Feature rich:
29
32
  ## Install
30
33
 
31
34
  ```bash
32
- npm i react-datasheet-grid
35
+ npm i @sage-bionetworks/react-datasheet-grid
33
36
  ```
34
37
 
35
38
  ## Usage
@@ -40,13 +43,13 @@ import {
40
43
  checkboxColumn,
41
44
  textColumn,
42
45
  keyColumn,
43
- } from 'react-datasheet-grid'
46
+ } from '@sage-bionetworks/react-datasheet-grid'
44
47
 
45
48
  // Import the style only once in your app!
46
- import 'react-datasheet-grid/dist/style.css'
49
+ import '@sage-bionetworks/react-datasheet-grid/dist/style.css'
47
50
 
48
51
  const Example = () => {
49
- const [ data, setData ] = useState([
52
+ const [data, setData] = useState([
50
53
  { active: true, firstName: 'Elon', lastName: 'Musk' },
51
54
  { active: false, firstName: 'Jeff', lastName: 'Bezos' },
52
55
  ])
@@ -66,12 +69,19 @@ const Example = () => {
66
69
  },
67
70
  ]
68
71
 
69
- return (
70
- <DataSheetGrid
71
- value={data}
72
- onChange={setData}
73
- columns={columns}
74
- />
75
- )
72
+ return <DataSheetGrid value={data} onChange={setData} columns={columns} />
76
73
  }
77
74
  ```
75
+
76
+ ## Development
77
+
78
+ ```bash
79
+ pnpm nx run @sage-bionetworks/react-datasheet-grid:test # vitest (src/ and tests/)
80
+ pnpm nx run @sage-bionetworks/react-datasheet-grid:example:dev # demo app at example/
81
+ pnpm nx run @sage-bionetworks/react-datasheet-grid:e2e # playwright specs in e2e/
82
+ ```
83
+
84
+ `example/` is a small demo app that imports the grid from `../src`, and the
85
+ Playwright specs in `e2e/` drive it. Both exist to cover behavior that needs a
86
+ real browser — layout, scrolling, and cell expansion — which JSDOM cannot
87
+ measure.
package/dist/index.cjs CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),d=require("react"),Mn=require("react-dom");function kn(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,s.get?s:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const Pe=kn(d),An=(e,r)=>{const t=r.map(({basis:n,minWidth:o,maxWidth:i})=>({basis:n,minWidth:o,maxWidth:i,size:n,violation:0,frozen:!1,factor:0}));let s=t.reduce((n,o)=>n-o.size,e);s>0?r.forEach(({grow:n},o)=>{t[o].factor=n}):s<0&&r.forEach(({shrink:n},o)=>{t[o].factor=n});for(const n of t)n.factor===0&&(n.frozen=!0);for(;t.some(({frozen:n})=>!n);){const n=t.reduce((i,c)=>i+(c.frozen?0:c.factor),0);let o=0;for(const i of t)i.frozen||(i.size+=s*i.factor/n,i.size<i.minWidth?i.violation=i.minWidth-i.size:i.maxWidth!==void 0&&i.size>i.maxWidth?i.violation=i.maxWidth-i.size:i.violation=0,i.size+=i.violation,o+=i.violation);if(o>0)for(const i of t)i.violation>0&&(i.frozen=!0);else if(o<0)for(const i of t)i.violation<0&&(i.frozen=!0);else break;s=t.reduce((i,c)=>i-c.size,e)}return t.map(({size:n})=>n)},_n=(e,r)=>{const t=e.map(({basis:s,minWidth:n,maxWidth:o,grow:i,shrink:c})=>[s,n,o,i,c].join(",")).join("|");return d.useMemo(()=>{if(r===void 0)return{fullWidth:!1,columnWidths:void 0,columnRights:void 0,totalWidth:void 0};const s=An(r,e);let n=0;const o=s.map((i,c)=>(n+=i,c===s.length-1?1/0:n));return{fullWidth:Math.abs(r-n)<.1,columnWidths:s,columnRights:o,totalWidth:n}},[r,t])};var ze=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function We(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ze,Tt;function gt(){if(Tt)return Ze;Tt=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return Ze=e,Ze}var Je,Rt;function zn(){if(Rt)return Je;Rt=1;var e=typeof ze=="object"&&ze&&ze.Object===Object&&ze;return Je=e,Je}var Qe,Dt;function nn(){if(Dt)return Qe;Dt=1;var e=zn(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return Qe=t,Qe}var He,Ot;function Fn(){if(Ot)return He;Ot=1;var e=nn(),r=function(){return e.Date.now()};return He=r,He}var et,jt;function Vn(){if(jt)return et;jt=1;var e=/\s/;function r(t){for(var s=t.length;s--&&e.test(t.charAt(s)););return s}return et=r,et}var tt,Nt;function Ln(){if(Nt)return tt;Nt=1;var e=Vn(),r=/^\s+/;function t(s){return s&&s.slice(0,e(s)+1).replace(r,"")}return tt=t,tt}var nt,Mt;function rn(){if(Mt)return nt;Mt=1;var e=nn(),r=e.Symbol;return nt=r,nt}var rt,kt;function Pn(){if(kt)return rt;kt=1;var e=rn(),r=Object.prototype,t=r.hasOwnProperty,s=r.toString,n=e?e.toStringTag:void 0;function o(i){var c=t.call(i,n),f=i[n];try{i[n]=void 0;var m=!0}catch{}var g=s.call(i);return m&&(c?i[n]=f:delete i[n]),g}return rt=o,rt}var st,At;function qn(){if(At)return st;At=1;var e=Object.prototype,r=e.toString;function t(s){return r.call(s)}return st=t,st}var ot,_t;function Wn(){if(_t)return ot;_t=1;var e=rn(),r=Pn(),t=qn(),s="[object Null]",n="[object Undefined]",o=e?e.toStringTag:void 0;function i(c){return c==null?c===void 0?n:s:o&&o in Object(c)?r(c):t(c)}return ot=i,ot}var it,zt;function Bn(){if(zt)return it;zt=1;function e(r){return r!=null&&typeof r=="object"}return it=e,it}var lt,Ft;function Kn(){if(Ft)return lt;Ft=1;var e=Wn(),r=Bn(),t="[object Symbol]";function s(n){return typeof n=="symbol"||r(n)&&e(n)==t}return lt=s,lt}var ct,Vt;function Un(){if(Vt)return ct;Vt=1;var e=Ln(),r=gt(),t=Kn(),s=NaN,n=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,i=/^0o[0-7]+$/i,c=parseInt;function f(m){if(typeof m=="number")return m;if(t(m))return s;if(r(m)){var g=typeof m.valueOf=="function"?m.valueOf():m;m=r(g)?g+"":g}if(typeof m!="string")return m===0?m:+m;m=e(m);var O=o.test(m);return O||i.test(m)?c(m.slice(2),O?2:8):n.test(m)?s:+m}return ct=f,ct}var at,Lt;function sn(){if(Lt)return at;Lt=1;var e=gt(),r=Fn(),t=Un(),s="Expected a function",n=Math.max,o=Math.min;function i(c,f,m){var g,O,p,j,S,T,k=0,K=!1,R=!1,F=!0;if(typeof c!="function")throw new TypeError(s);f=t(f)||0,e(m)&&(K=!!m.leading,R="maxWait"in m,p=R?n(t(m.maxWait)||0,f):p,F="trailing"in m?!!m.trailing:F);function q(L){var A=g,b=O;return g=O=void 0,k=L,j=c.apply(b,A),j}function U(L){return k=L,S=setTimeout(W,f),K?q(L):j}function ee(L){var A=L-T,b=L-k,_=f-A;return R?o(_,p-b):_}function z(L){var A=L-T,b=L-k;return T===void 0||A>=f||A<0||R&&b>=p}function W(){var L=r();if(z(L))return ce(L);S=setTimeout(W,ee(L))}function ce(L){return S=void 0,F&&g?q(L):(g=O=void 0,j)}function J(){S!==void 0&&clearTimeout(S),k=0,g=T=O=S=void 0}function te(){return S===void 0?j:ce(r())}function se(){var L=r(),A=z(L);if(g=arguments,O=this,T=L,A){if(S===void 0)return U(T);if(R)return clearTimeout(S),S=setTimeout(W,f),q(T)}return S===void 0&&(S=setTimeout(W,f)),j}return se.cancel=J,se.flush=te,se}return at=i,at}var $n=sn();const Gn=We($n);var ut,Pt;function Xn(){if(Pt)return ut;Pt=1;var e=sn(),r=gt(),t="Expected a function";function s(n,o,i){var c=!0,f=!0;if(typeof n!="function")throw new TypeError(t);return r(i)&&(c="leading"in i?!!i.leading:c,f="trailing"in i?!!i.trailing:f),e(n,o,{leading:c,maxWait:o,trailing:f})}return ut=s,ut}var Yn=Xn();const Zn=We(Yn),Jn=(e,r,t,s)=>{switch(r){case"debounce":return Gn(e,t,s);case"throttle":return Zn(e,t,s);default:return e}};function Qn({skipOnMount:e=!1,refreshMode:r,refreshRate:t=1e3,refreshOptions:s,handleWidth:n=!0,handleHeight:o=!0,targetRef:i,observerOptions:c,onResize:f}={}){const m=d.useRef(e),[g,O]=d.useState({width:void 0,height:void 0}),[p,j]=d.useState(i?.current||null);i&&setTimeout(()=>{i.current!==p&&j(i.current)},0);const S=d.useMemo(()=>new Proxy(R=>{R!==p&&j(R)},{get(R,F){return F==="current"?p:R[F]},set(R,F,q){return F==="current"?j(q):R[F]=q,!0}}),[p]),T=d.useCallback((R,F)=>!(R.width===F.width&&R.height===F.height||R.width===F.width&&!o||R.height===F.height&&!n),[n,o]),k=d.useCallback(R=>{if(!(!n&&!o)){if(m.current){m.current=!1;return}R.forEach(F=>{const{width:q,height:U}=F?.contentRect||{};O(ee=>T(ee,{width:q,height:U})?{width:q,height:U}:ee)})}},[n,o,m,T]),K=d.useCallback(Jn(k,r,t,s),[k,r,t,s]);return d.useEffect(()=>{let R;return p?(R=new window.ResizeObserver(K),R.observe(p,c)):(g.width||g.height)&&O({width:void 0,height:void 0}),()=>{var F,q,U;(F=R?.disconnect)===null||F===void 0||F.call(R),(U=(q=K).cancel)===null||U===void 0||U.call(q)}},[K,p]),d.useEffect(()=>{f?.(g.width,g.height)},[g]),Object.assign({ref:S},g)}const Hn=()=>x.jsx(x.Fragment,{}),er=()=>!1,qt=({rowData:e})=>e,tr=()=>null,nr=({rowIndex:e})=>x.jsx(x.Fragment,{children:e+1}),ft=()=>!0,rr=e=>e,sr=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*)? *$/)){const[r,t]=e.trim().split(" ");return{basis:0,grow:parseFloat(r),shrink:parseFloat(t)}}if(e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? *px *$/)){const[r,t]=e.trim().split(" ");return{basis:parseFloat(t),grow:parseFloat(r),shrink:1}}if(e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? \d+(\.\d*)? *px *$/)){const[r,t,s]=e.trim().split(" ");return{basis:parseFloat(s),grow:parseFloat(r),shrink:parseFloat(t)}}return{basis:0,grow:1,shrink:1}},or=(e,r,t,s=!1)=>d.useMemo(()=>{const n=[r===!1?{basis:0,grow:0,shrink:0,minWidth:0,component:()=>x.jsx(x.Fragment,{}),headerClassName:"dsg-hidden-cell",cellClassName:"dsg-hidden-cell",isCellEmpty:ft}:{...r,basis:r?.basis??40,grow:r?.grow??0,shrink:r?.shrink??0,minWidth:r?.minWidth??0,title:r?.title??x.jsx("div",{className:"dsg-corner-indicator"}),component:r?.component??nr,isCellEmpty:ft},...e];return t&&n.push({...t,basis:t?.basis??40,grow:t?.grow??0,shrink:t?.shrink??0,minWidth:t.minWidth??0,isCellEmpty:ft}),n.map((o,i)=>{const c=o.width!==void 0?sr(o.width):{basis:void 0,grow:void 0,shrink:void 0},f=o.stickyLeft!==void 0?o.stickyLeft:i===1&&s;return{...o,basis:o.basis??c.basis??0,grow:o.grow??c.grow??1,shrink:o.shrink??c.shrink??1,minWidth:o.minWidth??100,component:o.component??Hn,disableKeys:o.disableKeys??!1,disabled:o.disabled??!1,keepFocus:o.keepFocus??!1,deleteValue:o.deleteValue??qt,copyValue:o.copyValue??tr,pasteValue:o.pasteValue??qt,prePasteValues:o.prePasteValues??rr,isCellEmpty:o.isCellEmpty??er,stickyLeft:f}})},[r,t,e,s]);function qe(e,r,t,s){var n,o=!1,i=0;function c(){n&&clearTimeout(n)}function f(){c(),o=!0}typeof r!="boolean"&&(s=t,t=r,r=void 0);function m(){for(var g=arguments.length,O=new Array(g),p=0;p<g;p++)O[p]=arguments[p];var j=this,S=Date.now()-i;if(o)return;function T(){i=Date.now(),t.apply(j,O)}function k(){n=void 0}s&&!n&&T(),c(),s===void 0&&S>e?T():r!==!0&&(n=setTimeout(s?k:T,s===void 0?e-S:e))}return m.cancel=f,m}function ir(e,r,t){return t===void 0?qe(e,r,!1):qe(e,t,r!==!1)}var dt,Wt;function lr(){return Wt||(Wt=1,dt=function e(r,t){if(r===t)return!0;if(r&&t&&typeof r=="object"&&typeof t=="object"){if(r.constructor!==t.constructor)return!1;var s,n,o;if(Array.isArray(r)){if(s=r.length,s!=t.length)return!1;for(n=s;n--!==0;)if(!e(r[n],t[n]))return!1;return!0}if(r.constructor===RegExp)return r.source===t.source&&r.flags===t.flags;if(r.valueOf!==Object.prototype.valueOf)return r.valueOf()===t.valueOf();if(r.toString!==Object.prototype.toString)return r.toString()===t.toString();if(o=Object.keys(r),s=o.length,s!==Object.keys(t).length)return!1;for(n=s;n--!==0;)if(!Object.prototype.hasOwnProperty.call(t,o[n]))return!1;for(n=s;n--!==0;){var i=o[n];if(!e(r[i],t[i]))return!1}return!0}return r!==r&&t!==t}),dt}var cr=lr();const on=We(cr),Le=e=>{const[r,t]=d.useState(e),s=d.useCallback(n=>{t(o=>{const i=typeof n=="function"?n(o):n;return on(i,o)?o:i})},[t]);return[r,s]},ar=(e,r,t)=>{const[s,n]=Le({top:!0,right:!0,bottom:!0,left:!0});return d.useEffect(()=>{const o=qe(100,()=>{n({top:e.current?.scrollTop===0,right:(e.current?.scrollLeft??0)>=(e.current?.scrollWidth??0)-(r??0)-1,bottom:(e.current?.scrollTop??0)>=(e.current?.scrollHeight??0)-(t??0)-1,left:e.current?.scrollLeft===0})}),i=e.current;return i?.addEventListener("scroll",o),setTimeout(o,100),()=>{i?.removeEventListener("scroll",o),o.cancel()}},[t,r,e,n]),s},me=(e,r)=>{d.useEffect(()=>(document.addEventListener(e,r),()=>{document.removeEventListener(e,r)}),[r,e])},Bt=(e,r=200)=>{const t=d.useRef(null),s=d.useMemo(()=>qe(r,!0,()=>{setTimeout(()=>t.current=e.current?.getBoundingClientRect()||null,0)}),[e,r]);return d.useCallback((n=!1)=>(n?t.current=e.current?.getBoundingClientRect()||null:s(),t.current),[e,s])},ln=(e={})=>(({addRows:r})=>{const[t,s]=d.useState(1),[n,o]=d.useState(String(t));return x.jsxs("div",{className:"dsg-add-row",children:[x.jsx("button",{type:"button",className:"dsg-add-row-btn",onClick:()=>r(t),children:e.button??"Add"})," ",x.jsx("input",{className:"dsg-add-row-input",value:n,onBlur:()=>o(String(t)),type:"number",min:1,onChange:i=>{o(i.target.value),s(Math.max(1,Math.round(parseInt(i.target.value)||0)))},onKeyDown:i=>{i.key==="Enter"&&r(t)}})," ",e.unit??"rows"]})}),cn=ln();cn.displayName="AddRows";const ur=(e,r)=>{const[t,s]=d.useState(e),n=d.useRef();d.useEffect(()=>()=>n.current?.cancel(),[]);const o=d.useMemo(()=>n.current=ir(r,i=>{s(i)}),[r]);return[t,o]},wt=e=>e.type==="CUT"?x.jsx(x.Fragment,{children:"Cut"}):e.type==="COPY"?x.jsx(x.Fragment,{children:"Copy"}):e.type==="PASTE"?x.jsx(x.Fragment,{children:"Paste"}):e.type==="DELETE_ROW"?x.jsx(x.Fragment,{children:"Delete row"}):e.type==="DELETE_ROWS"?x.jsxs(x.Fragment,{children:["Delete rows ",x.jsx("b",{children:e.fromRow})," to ",x.jsx("b",{children:e.toRow})]}):e.type==="INSERT_ROW_BELLOW"?x.jsx(x.Fragment,{children:"Insert row below"}):e.type==="DUPLICATE_ROW"?x.jsx(x.Fragment,{children:"Duplicate row"}):e.type==="DUPLICATE_ROWS"?x.jsxs(x.Fragment,{children:["Duplicate rows ",x.jsx("b",{children:e.fromRow})," to ",x.jsx("b",{children:e.toRow})]}):e.type,an=(e=wt)=>(({clientX:r,clientY:t,items:s,close:n})=>{const o=d.useRef(null),i=d.useCallback(c=>{o.current?.contains(c.target)||n()},[n]);return me("mousedown",i),x.jsx("div",{className:"dsg-context-menu",style:{left:r+"px",top:t+"px"},ref:o,children:s.map(c=>x.jsx("div",{onClick:c.action,className:"dsg-context-menu-item",children:e(c)},c.type))})}),un=an(wt);un.displayName="ContextMenu";const fr=typeof DOMParser<"u"?new DOMParser:{parseFromString:()=>null},dr=e=>fr.parseFromString(e,"text/html"),ht=e=>{const r=dr(e.replace(/<br\/?>/g,`
2
- `)),t=r.getElementsByTagName("table")[0];if(t){const n=[];for(let o=0;o<t.rows.length;o++){const i=[];n.push(i);for(let c=0;c<t.rows[o].cells.length;c++)i.push(t.rows[o].cells[c].textContent??"")}return n}const s=r.getElementsByTagName("span")[0];return s?[[s.textContent??""]]:[[""]]},Fe=e=>{const r=e.replace(/\r|\n$/g,""),t=[[]];let s=0,n=0,o=!1,i=0;const c=()=>{let f=r.slice(n,s);f[0]==='"'&&f[f.length-1]==='"'&&(o=!0),o&&f[f.length-1]==='"'&&f.includes(`
3
- `)&&(f=f.slice(1,f.length-1).replace(/""/g,'"'),o=!1),o&&f[f.length-1]!=='"'?f.split(`
4
- `).forEach((m,g,{length:O})=>{t[i].push(m),g<O-1&&(t.push([]),i++)}):t[i].push(f)};for(;s<r.length;)o&&r[s]==='"'&&![void 0," ",'"'].includes(r[s+1])&&(o=!1),o&&r[s]==='"'&&r[s+1]==='"'&&s++,s===n&&r[s]==='"'&&(o=!0),r[s]===" "&&(c(),n=s+1,o=!1),r[s]===`
5
- `&&!o&&(c(),t.push([]),n=s+1,i++),s++;return c(),t},hr=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;"),mr=e=>e.match(/^[^\x00-\x20\x7F-\x9F]$/)!==null,pt=(e,r,t,s)=>{if(e===null||!r||!t)return null;if(typeof e!="object")throw new Error("Value must be an object or null");const n=s.findIndex(i=>i.id===e.col),o={col:Math.max(0,Math.min(r-1,n===-1?Number(e.col):n-1)),row:Math.max(0,Math.min(t-1,Number(e.row)))};if(isNaN(o.col)||isNaN(o.row))throw new Error("col or cell are not valid positive numbers");return o},De=(e,r)=>e?{col:e.col,row:e.row,colId:r[e.col+1]?.id}:null,pr=(e,r,t,s)=>{if(e===null||!r||!t)return null;if(typeof e!="object")throw new Error("Value must be an object or null");const n={min:pt(e.min,r,t,s),max:pt(e.max,r,t,s)};if(!n.min||!n.max)throw new Error("min and max must be defined");return n},Kt=(e,r)=>e?{min:De(e.min,r),max:De(e.max,r)}:null,Ut=()=>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");function Re(e,r,t){let s=t.initialDeps??[],n,o=!0;function i(){var c,f,m;let g;t.key&&((c=t.debug)!=null&&c.call(t))&&(g=Date.now());const O=e();if(!(O.length!==s.length||O.some((S,T)=>s[T]!==S)))return n;s=O;let j;if(t.key&&((f=t.debug)!=null&&f.call(t))&&(j=Date.now()),n=r(...O),t.key&&((m=t.debug)!=null&&m.call(t))){const S=Math.round((Date.now()-g)*100)/100,T=Math.round((Date.now()-j)*100)/100,k=T/16,K=(R,F)=>{for(R=String(R);R.length<F;)R=" "+R;return R};console.info(`%c⏱ ${K(T,5)} /${K(S,5)} ms`,`
6
- font-size: .6rem;
7
- font-weight: bold;
8
- color: hsl(${Math.max(0,Math.min(120-120*k,120))}deg 100% 31%);`,t?.key)}return t?.onChange&&!(o&&t.skipInitialOnChange)&&t.onChange(n),o=!1,n}return i.updateDeps=c=>{s=c},i}function $t(e,r){if(e===void 0)throw new Error("Unexpected undefined");return e}const gr=(e,r)=>Math.abs(e-r)<1.01,wr=(e,r,t)=>{let s;return function(...n){e.clearTimeout(s),s=e.setTimeout(()=>r.apply(this,n),t)}},Gt=e=>{const{offsetWidth:r,offsetHeight:t}=e;return{width:r,height:t}},xr=e=>e,fn=e=>{const r=Math.max(e.startIndex-e.overscan,0),t=Math.min(e.endIndex+e.overscan,e.count-1),s=[];for(let n=r;n<=t;n++)s.push(n);return s},br=(e,r)=>{const t=e.scrollElement;if(!t)return;const s=e.targetWindow;if(!s)return;const n=i=>{const{width:c,height:f}=i;r({width:Math.round(c),height:Math.round(f)})};if(n(Gt(t)),!s.ResizeObserver)return()=>{};const o=new s.ResizeObserver(i=>{const c=()=>{const f=i[0];if(f?.borderBoxSize){const m=f.borderBoxSize[0];if(m){n({width:m.inlineSize,height:m.blockSize});return}}n(Gt(t))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return o.observe(t,{box:"border-box"}),()=>{o.unobserve(t)}},Xt={passive:!0},Yt=typeof window>"u"?!0:"onscrollend"in window,yr=(e,r)=>{const t=e.scrollElement;if(!t)return;const s=e.targetWindow;if(!s)return;let n=0;const o=e.options.useScrollendEvent&&Yt?()=>{}:wr(s,()=>{r(n,!1)},e.options.isScrollingResetDelay),i=g=>()=>{const{horizontal:O,isRtl:p}=e.options;n=O?t.scrollLeft*(p&&-1||1):t.scrollTop,o(),r(n,g)},c=i(!0),f=i(!1);t.addEventListener("scroll",c,Xt);const m=e.options.useScrollendEvent&&Yt;return m&&t.addEventListener("scrollend",f,Xt),()=>{t.removeEventListener("scroll",c),m&&t.removeEventListener("scrollend",f)}},vr=(e,r,t)=>{if(r?.borderBoxSize){const s=r.borderBoxSize[0];if(s)return Math.round(s[t.options.horizontal?"inlineSize":"blockSize"])}return e[t.options.horizontal?"offsetWidth":"offsetHeight"]},Er=(e,{adjustments:r=0,behavior:t},s)=>{var n,o;const i=e+r;(o=(n=s.scrollElement)==null?void 0:n.scrollTo)==null||o.call(n,{[s.options.horizontal?"left":"top"]:i,behavior:t})};class Sr{constructor(r){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.currentScrollToIndex=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let t=null;const s=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(n=>{n.forEach(o=>{const i=()=>{this._measureElement(o.target,o)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var n;(n=s())==null||n.disconnect(),t=null},observe:n=>{var o;return(o=s())==null?void 0:o.observe(n,{box:"border-box"})},unobserve:n=>{var o;return(o=s())==null?void 0:o.unobserve(n)}}})(),this.range=null,this.setOptions=t=>{Object.entries(t).forEach(([s,n])=>{typeof n>"u"&&delete t[s]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:xr,rangeExtractor:fn,onChange:()=>{},measureElement:vr,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...t}},this.notify=t=>{var s,n;(n=(s=this.options).onChange)==null||n.call(s,this,t)},this.maybeNotify=Re(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:process.env.NODE_ENV!=="production"&&"maybeNotify",debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(n=>{this.observer.observe(n)}),this.unsubs.push(this.options.observeElementRect(this,n=>{this.scrollRect=n,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(n,o)=>{this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<n?"forward":"backward":null,this.scrollOffset=n,this.isScrolling=o,this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(t,s)=>{const n=new Map,o=new Map;for(let i=s-1;i>=0;i--){const c=t[i];if(n.has(c.lane))continue;const f=o.get(c.lane);if(f==null||c.end>f.end?o.set(c.lane,c):c.end<f.end&&n.set(c.lane,!0),n.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((i,c)=>i.end===c.end?i.index-c.index:i.end-c.end)[0]:void 0},this.getMeasurementOptions=Re(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(t,s,n,o,i,c)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMeasuredCacheIndexes=[],{count:t,paddingStart:s,scrollMargin:n,getItemKey:o,enabled:i,lanes:c}),{key:!1}),this.getMeasurements=Re(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:t,paddingStart:s,scrollMargin:n,getItemKey:o,enabled:i,lanes:c},f)=>{if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const p of this.laneAssignments.keys())p>=t&&this.laneAssignments.delete(p);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(p=>{this.itemSizeCache.set(p.key,p.size)}));const m=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1);const g=this.measurementsCache.slice(0,m),O=new Array(c).fill(void 0);for(let p=0;p<m;p++){const j=g[p];j&&(O[j.lane]=p)}for(let p=m;p<t;p++){const j=o(p),S=this.laneAssignments.get(p);let T,k;if(S!==void 0&&this.options.lanes>1){T=S;const q=O[T],U=q!==void 0?g[q]:void 0;k=U?U.end+this.options.gap:s+n}else{const q=this.options.lanes===1?g[p-1]:this.getFurthestMeasurement(g,p);k=q?q.end+this.options.gap:s+n,T=q?q.lane:p%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(p,T)}const K=f.get(j),R=typeof K=="number"?K:this.options.estimateSize(p),F=k+R;g[p]={index:p,start:k,size:R,end:F,key:j,lane:T},O[T]=p}return this.measurementsCache=g,g},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=Re(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,s,n,o)=>this.range=t.length>0&&s>0?Ir({measurements:t,outerSize:s,scrollOffset:n,lanes:o}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=Re(()=>{let t=null,s=null;const n=this.calculateRange();return n&&(t=n.startIndex,s=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,s]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,s]},(t,s,n,o,i)=>o===null||i===null?[]:t({startIndex:o,endIndex:i,overscan:s,count:n}),{key:process.env.NODE_ENV!=="production"&&"getVirtualIndexes",debug:()=>this.options.debug}),this.indexFromElement=t=>{const s=this.options.indexAttribute,n=t.getAttribute(s);return n?parseInt(n,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this._measureElement=(t,s)=>{const n=this.indexFromElement(t),o=this.measurementsCache[n];if(!o)return;const i=o.key,c=this.elementsCache.get(i);c!==t&&(c&&this.observer.unobserve(c),this.observer.observe(t),this.elementsCache.set(i,t)),t.isConnected&&this.resizeItem(n,this.options.measureElement(t,s,this))},this.resizeItem=(t,s)=>{const n=this.measurementsCache[t];if(!n)return;const o=this.itemSizeCache.get(n.key)??n.size,i=s-o;i!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(n,i,this):n.start<this.getScrollOffset()+this.scrollAdjustments)&&(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("correction",i),this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=i,behavior:void 0})),this.pendingMeasuredCacheIndexes.push(n.index),this.itemSizeCache=new Map(this.itemSizeCache.set(n.key,s)),this.notify(!1))},this.measureElement=t=>{if(!t){this.elementsCache.forEach((s,n)=>{s.isConnected||(this.observer.unobserve(s),this.elementsCache.delete(n))});return}this._measureElement(t,void 0)},this.getVirtualItems=Re(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,s)=>{const n=[];for(let o=0,i=t.length;o<i;o++){const c=t[o],f=s[c];n.push(f)}return n},{key:process.env.NODE_ENV!=="production"&&"getVirtualItems",debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const s=this.getMeasurements();if(s.length!==0)return $t(s[dn(0,s.length-1,n=>$t(s[n]).start,t)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(t,s,n=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();s==="auto"&&(s=t>=i+o?"end":"start"),s==="center"?t+=(n-o)/2:s==="end"&&(t-=o);const c=this.getMaxScrollOffset();return Math.max(Math.min(c,t),0)},this.getOffsetForIndex=(t,s="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const n=this.measurementsCache[t];if(!n)return;const o=this.getSize(),i=this.getScrollOffset();if(s==="auto")if(n.end>=i+o-this.options.scrollPaddingEnd)s="end";else if(n.start<=i+this.options.scrollPaddingStart)s="start";else return[i,s];if(s==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),s];const c=s==="end"?n.end+this.options.scrollPaddingEnd:n.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(c,s,n.size),s]},this.isDynamicMode=()=>this.elementsCache.size>0,this.scrollToOffset=(t,{align:s="start",behavior:n}={})=>{n==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(t,s),{adjustments:void 0,behavior:n})},this.scrollToIndex=(t,{align:s="auto",behavior:n}={})=>{n==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),t=Math.max(0,Math.min(t,this.options.count-1)),this.currentScrollToIndex=t;let o=0;const i=10,c=m=>{if(!this.targetWindow)return;const g=this.getOffsetForIndex(t,m);if(!g){console.warn("Failed to get offset for index:",t);return}const[O,p]=g;this._scrollToOffset(O,{adjustments:void 0,behavior:n}),this.targetWindow.requestAnimationFrame(()=>{const j=()=>{if(this.currentScrollToIndex!==t)return;const S=this.getScrollOffset(),T=this.getOffsetForIndex(t,p);if(!T){console.warn("Failed to get offset for index:",t);return}gr(T[0],S)||f(p)};this.isDynamicMode()?this.targetWindow.requestAnimationFrame(j):j()})},f=m=>{this.targetWindow&&this.currentScrollToIndex===t&&(o++,o<i?(process.env.NODE_ENV!=="production"&&this.options.debug&&console.info("Schedule retry",o,i),this.targetWindow.requestAnimationFrame(()=>c(m))):console.warn(`Failed to scroll to index ${t} after ${i} attempts.`))};c(s)},this.scrollBy=(t,{behavior:s}={})=>{s==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+t,{adjustments:void 0,behavior:s})},this.getTotalSize=()=>{var t;const s=this.getMeasurements();let n;if(s.length===0)n=this.options.paddingStart;else if(this.options.lanes===1)n=((t=s[s.length-1])==null?void 0:t.end)??0;else{const o=Array(this.options.lanes).fill(null);let i=s.length-1;for(;i>=0&&o.some(c=>c===null);){const c=s[i];o[c.lane]===null&&(o[c.lane]=c.end),i--}n=Math.max(...o.filter(c=>c!==null))}return Math.max(n-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(t,{adjustments:s,behavior:n})=>{this.options.scrollToFn(t,{behavior:n,adjustments:s},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(r)}}const dn=(e,r,t,s)=>{for(;e<=r;){const n=(e+r)/2|0,o=t(n);if(o<s)e=n+1;else if(o>s)r=n-1;else return n}return e>0?e-1:0};function Ir({measurements:e,outerSize:r,scrollOffset:t,lanes:s}){const n=e.length-1,o=f=>e[f].start;if(e.length<=s)return{startIndex:0,endIndex:n};let i=dn(0,n,o,t),c=i;if(s===1)for(;c<n&&e[c].end<t+r;)c++;else if(s>1){const f=Array(s).fill(0);for(;c<n&&f.some(g=>g<t+r);){const g=e[c];f[g.lane]=g.end,c++}const m=Array(s).fill(t+r);for(;i>=0&&m.some(g=>g>=t);){const g=e[i];m[g.lane]=g.start,i--}i=Math.max(0,i-i%s),c=Math.min(n,c+(s-1-c%s))}return{startIndex:i,endIndex:c}}const Zt=typeof document<"u"?Pe.useLayoutEffect:Pe.useEffect;function Cr({useFlushSync:e=!0,...r}){const t=Pe.useReducer(()=>({}),{})[1],s={...r,onChange:(o,i)=>{var c;e&&i?Mn.flushSync(t):t(),(c=r.onChange)==null||c.call(r,o,i)}},[n]=Pe.useState(()=>new Sr(s));return n.setOptions(s),Zt(()=>n._didMount(),[]),Zt(()=>n._willUpdate()),n}function Jt(e){return Cr({observeElementRect:br,observeElementOffset:yr,scrollToFn:Er,...e})}var mt={exports:{}};var Qt;function Tr(){return Qt||(Qt=1,(function(e){(function(){var r={}.hasOwnProperty;function t(){for(var o="",i=0;i<arguments.length;i++){var c=arguments[i];c&&(o=n(o,s(c)))}return o}function s(o){if(typeof o=="string"||typeof o=="number")return o;if(typeof o!="object")return"";if(Array.isArray(o))return t.apply(null,o);if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]"))return o.toString();var i="";for(var c in o)r.call(o,c)&&o[c]&&(i=n(i,c));return i}function n(o,i){return i?o?o+" "+i:o+i:o}e.exports?(t.default=t,e.exports=t):window.classNames=t})()})(mt)),mt.exports}var Rr=Tr();const $=We(Rr),Ht=({children:e,gutter:r,stickyRight:t,stickyLeft:s,active:n,disabled:o,className:i,width:c,left:f})=>x.jsx("div",{className:$("dsg-cell",r&&"dsg-cell-gutter",o&&"dsg-cell-disabled",r&&n&&"dsg-cell-gutter-active",t&&"dsg-cell-sticky-right",s&&"dsg-cell-sticky-left",i),style:{width:c,left:t?void 0:f},children:e}),Ve=(e,r)=>d.useMemo(()=>{const t=new Map;return s=>(t.has(s)||t.set(s,(...n)=>{e(s,...n.slice(0,r))}),t.get(s))},[r,e]),Dr=({data:e,columns:r,outerRef:t,innerRef:s,columnWidths:n,hasStickyRightColumn:o,pinFirstColumn:i,displayHeight:c,headerRowHeight:f,rowHeight:m,rowKey:g,fullWidth:O,selection:p,activeCell:j,rowClassName:S,cellClassName:T,children:k,editing:K,getContextMenuItems:R,setRowData:F,deleteRows:q,duplicateRows:U,insertRowAfter:ee,stopEditing:z,onScroll:W})=>{const ce=Jt({count:e.length,getScrollElement:()=>t.current,paddingStart:f,estimateSize:v=>m(v).height,getItemKey:v=>{if(g&&v>0){const D=e[v-1];if(typeof g=="function")return g({rowData:D,rowIndex:v});if(typeof g=="string"&&D instanceof Object&&g in D){const N=D[g];if(typeof N=="string"||typeof N=="number")return N}}return v},overscan:5}),J=Jt({count:r.length,getScrollElement:()=>t.current,estimateSize:v=>n?.[v]??100,horizontal:!0,getItemKey:v=>r[v].id??v,overscan:1,rangeExtractor:v=>{const D=fn(v);if(D[0]!==0&&D.unshift(0),(i||r[1]?.stickyLeft)&&r.length>1&&!D.includes(1)){const ge=D.findIndex(oe=>oe>1);ge===-1?D.push(1):D.splice(ge,0,1)}return o&&D[D.length-1]!==r.length-1&&D.push(r.length-1),D}});d.useEffect(()=>{J.measure()},[J,n]);const te=Ve(F,1),se=Ve(q,0),L=Ve(U,0),A=Ve(ee,0),b=v=>{if(!r[v].stickyLeft)return 0;if(!n||!n.length){const N=J.getOffsetForIndex(v);return typeof N=="number"?N:0}let D=0;for(let N=0;N<v;N++)D+=n[N];return D},_=p?.min.col??j?.col,ae=p?.max.col??j?.col,pe=p?.min.row??j?.row,G=p?.max.row??j?.row;return x.jsx("div",{ref:t,className:"dsg-container",onScroll:W,style:{height:c},children:x.jsxs("div",{ref:s,style:{width:O?"100%":J.getTotalSize(),height:ce.getTotalSize()},children:[f>0&&x.jsx("div",{className:$("dsg-row","dsg-row-header"),style:{width:O?"100%":J.getTotalSize(),height:f},children:J.getVirtualItems().map(v=>{const D=!!r[v.index].stickyLeft;return x.jsx(Ht,{gutter:v.index===0,stickyRight:o&&v.index===r.length-1,stickyLeft:D,width:v.size,left:D?b(v.index):v.start,className:$("dsg-cell-header",_!==void 0&&ae!==void 0&&_<=v.index-1&&ae>=v.index-1&&"dsg-cell-header-active",r[v.index].headerClassName),children:x.jsx("div",{className:"dsg-cell-header-container",children:r[v.index].title})},v.key)})}),ce.getVirtualItems().map(v=>{const D=v.index>=(pe??1/0)&&v.index<=(G??-1/0);return x.jsx("div",{className:$("dsg-row",typeof S=="string"?S:null,typeof S=="function"?S({rowData:e[v.index],rowIndex:v.index}):null),style:{height:v.size,top:v.start,width:O?"100%":J.getTotalSize()},children:J.getVirtualItems().map(N=>{const ge=r[N.index].cellClassName,oe=r[N.index].disabled,Be=r[N.index].component,Oe=oe===!0||typeof oe=="function"&&oe({rowData:e[v.index],rowIndex:v.index}),je=j?.row===v.index&&j.col===N.index-1,ue=!!r[N.index].stickyLeft;return x.jsx(Ht,{gutter:N.index===0,stickyRight:o&&N.index===r.length-1,stickyLeft:ue,active:N.index===0&&D,disabled:Oe,className:$(typeof ge=="function"?ge({rowData:e[v.index],rowIndex:v.index,columnId:r[N.index].id}):ge,typeof T=="function"?T({rowData:e[v.index],rowIndex:v.index,columnId:r[N.index].id}):T),width:N.size,left:ue?b(N.index):N.start,children:x.jsx(Be,{rowData:e[v.index],getContextMenuItems:R,disabled:Oe,active:je,columnIndex:N.index-1,rowIndex:v.index,focus:je&&K,deleteRow:se(v.index),duplicateRow:L(v.index),stopEditing:z,insertRowBelow:A(v.index),setRowData:te(v.index),columnData:r[N.index].columnData})},N.key)})},v.key)}),k]})})},en=(e,r,t,s)=>[[s,e],[r,e],[r,t],[s,t],[s,e]],tn=(e,r,t,s)=>`polygon(evenodd, ${[...en(0,"100%","100%",0),...en(e,r,t,s)].map(o=>o.map(i=>typeof i=="number"&&i!==0?i+"px":i).join(" ")).join(",")})`,hn=d.memo(({columnWidths:e,columnRights:r,headerRowHeight:t,selection:s,rowHeight:n,activeCell:o,hasStickyRightColumn:i,dataLength:c,viewWidth:f,viewHeight:m,contentWidth:g,edges:O,isCellDisabled:p,editing:j,expandSelection:S,stickyLeftColumns:T,getStickyLeftOffset:k})=>{const K=o?p(o):!1,R=d.useMemo(()=>{if(!s)return K;for(let D=s.min.col;D<=s.max.col;++D)for(let N=s.min.row;N<=s.max.row;++N)if(!p({col:D,row:N}))return!1;return!0},[K,p,s]),[F,q]=d.useState(null);if(d.useEffect(()=>{if(!j){q(null);return}const D=document.activeElement;if(!(D instanceof HTMLElement)||!D.classList.contains("dsg-input")){q(null);return}const N=new ResizeObserver(()=>{q(D.getBoundingClientRect().width)});return N.observe(D),()=>N.disconnect()},[j]),!e||!r)return null;const U=D=>D<c-1?1:0,ee=D=>D<e.length-(i?3:2)?1:0,z=o&&{width:(F!==null?F:e[o.col+1])+ee(o.col),height:n(o.row).height+U(o.row),left:r[o.col],top:n(o.row).top+t},W=s&&{width:e.slice(s.min.col+1,s.max.col+2).reduce((D,N)=>D+N)+ee(s.max.col),height:n(s.max.row).top+n(s.max.row).height-n(s.min.row).top+U(s.max.row),left:r[s.min.col],top:n(s.min.row).top+t},ce=o&&T&&k&&T[o.col],J=ce&&k?k(o.col+1):0,te=s&&T&&k&&(()=>{for(let D=s.min.col;D<=s.max.col;D++)if(!T[D])return!1;return!0})(),se=te&&s&&k?k(s.min.col+1):0,L=s?.min||o,A=s?.max||o,b=A&&T&&k&&T[A.col],_=b&&A&&k?k(A.col+1)+e[A.col+1]:0,ae=s&&T&&T[s.min.col]||o&&T&&T[o.col],pe=ae&&k?k((s?.min.col??o?.col??0)+1):0,G=A&&S!==null&&{left:r[A.col]+e[A.col+1],top:n(A.row).top+n(A.row).height+t,transform:`translate(-${A.col<e.length-(i?3:2)?50:100}%, -${A.row<c-1?50:100}%)`},v=L&&A&&S!==null&&{width:e.slice(L.col+1,A.col+2).reduce((D,N)=>D+N)+ee(A.col),height:n(A.row+S).top+n(A.row+S).height-n(A.row+1).top+U(A.row+S)-1,left:r[L.col],top:n(A.row).top+n(A.row).height+t+1};return x.jsxs(x.Fragment,{children:[x.jsx("div",{className:"dsg-scrollable-view-container",style:{height:n(c-1).top+n(c-1).height+t,width:g||"100%"},children:x.jsx("div",{className:$({"dsg-scrollable-view":!0,"dsg-scrollable-view-t":!O.top,"dsg-scrollable-view-r":!O.right,"dsg-scrollable-view-b":!O.bottom,"dsg-scrollable-view-l":!O.left}),style:{top:t,left:e[0],height:m?m-t:0,width:g&&f?f-e[0]-(i?e[e.length-1]:0):`calc(100% - ${e[0]+(i?e[e.length-1]:0)}px)`}})}),(W||z)&&!ae&&x.jsx("div",{className:"dsg-selection-col-marker-container",style:{left:W?.left??z?.left,width:W?.width??z?.width,height:n(c-1).top+n(c-1).height+t},children:x.jsx("div",{className:$("dsg-selection-col-marker",R&&"dsg-selection-col-marker-disabled"),style:{top:t}})}),(W||z)&&ae&&x.jsx("div",{className:$("dsg-selection-col-marker-container","dsg-selection-col-marker-container-sticky"),style:{position:"sticky",left:pe,top:"auto",width:W?.width??z?.width,height:n(c-1).top+n(c-1).height+t},children:x.jsx("div",{className:$("dsg-selection-col-marker",R&&"dsg-selection-col-marker-disabled"),style:{top:t}})}),(W||z)&&x.jsx("div",{className:"dsg-selection-row-marker-container",style:{top:W?.top??z?.top,height:W?.height??z?.height,width:g||"100%"},children:x.jsx("div",{className:$("dsg-selection-row-marker",R&&"dsg-selection-row-marker-disabled"),style:{left:e[0]}})}),z&&o&&!ce&&x.jsx("div",{className:$("dsg-active-cell",{"dsg-active-cell-focus":j,"dsg-active-cell-disabled":K}),style:z}),z&&o&&ce&&x.jsx("div",{style:{position:"absolute",top:z.top,left:0,right:0,height:z.height,pointerEvents:"none"},children:x.jsx("div",{className:$("dsg-active-cell",{"dsg-active-cell-focus":j,"dsg-active-cell-disabled":K,"dsg-active-cell-sticky":!0}),style:{position:"sticky",left:J,width:z.width,height:"100%"}})}),W&&z&&!te&&x.jsx("div",{className:$("dsg-selection-rect",R&&"dsg-selection-rect-disabled"),style:{...W,clipPath:tn(z.top-W.top,z.left-W.left,z.top+z.height-W.top,z.left+z.width-W.left)}}),W&&z&&te&&x.jsx("div",{style:{position:"absolute",top:W.top,left:0,right:0,height:W.height,pointerEvents:"none"},children:x.jsx("div",{className:$("dsg-selection-rect",R&&"dsg-selection-rect-disabled","dsg-selection-rect-sticky"),style:{position:"sticky",left:se,width:W.width,height:"100%",background:"var(--dsg-selection-background-color)",clipPath:tn(z.top-W.top,J-se,z.top+z.height-W.top,J+z.width-se)}})}),v&&!te&&x.jsx("div",{className:"dsg-expand-rows-rect",style:v}),v&&te&&x.jsx("div",{style:{position:"absolute",top:v.top,left:0,right:0,height:v.height,pointerEvents:"none"},children:x.jsx("div",{className:$("dsg-expand-rows-rect","dsg-expand-rows-rect-sticky"),style:{position:"sticky",left:se,width:v.width,height:"100%"}})}),G&&!b&&x.jsx("div",{className:$("dsg-expand-rows-indicator",R&&"dsg-expand-rows-indicator-disabled"),style:G}),G&&b&&x.jsx("div",{style:{position:"absolute",top:G.top,left:0,right:0,height:0,pointerEvents:"none"},children:x.jsx("div",{className:$("dsg-expand-rows-indicator",R&&"dsg-expand-rows-indicator-disabled","dsg-expand-rows-indicator-sticky"),style:{position:"sticky",left:_,transform:G.transform,pointerEvents:"auto"}})})]})});hn.displayName="SelectionRect";const Or=({value:e,rowHeight:r})=>{const t=d.useRef([]),[,s]=d.useState(0);return d.useMemo(()=>{const n=o=>{if(typeof r=="number")return Math.min(e.length-1,Math.max(-1,Math.floor(o/r)));let i=0,c=t.current.length-1;for(;i<=c;){const f=Math.floor((i+c)/2);if(t.current[f].top<o)i=f+1;else if(t.current[f].top>o)c=f-1;else return f}if(c===t.current.length-1&&e.length>t.current.length&&(!t.current.length||o>=t.current[c].top+t.current[c].height)){let f=c===-1?0:t.current[c].top+t.current[c].height;do{c++;const m=r({rowIndex:c,rowData:e[c]});t.current.push({height:m,top:f}),f+=m}while(f<=o&&c<t.current.length-1)}return c};return{resetAfter:o=>{t.current=t.current.slice(0,o),s(i=>i+1)},getRowSize:o=>{if(typeof r=="number")return{height:r,top:r*o};if(o>=e.length)return{height:0,top:0};if(o<t.current.length)return t.current[o];let i=t.current[t.current.length-1].top+t.current[t.current.length-1].height;for(let c=t.current.length;c<=o;c++){const f=r({rowIndex:c,rowData:e[c]});t.current.push({height:f,top:i}),i+=f}return t.current[o]},getRowIndex:n,totalSize:o=>{if(typeof r=="number")return e.length*r;const i=n(o);return t.current[i].top+t.current[i].height}}},[r,e])},jr=[],Nr=[],Mr=()=>({}),ke=()=>null,kr=({rowData:e})=>({...e}),xt=d.memo(d.forwardRef(({value:e=jr,className:r,style:t,height:s=400,onChange:n=ke,columns:o=Nr,rowHeight:i=40,headerRowHeight:c=typeof i=="number"?i:40,gutterColumn:f,stickyRightColumn:m,rowKey:g,addRowsComponent:O=cn,createRow:p=Mr,autoAddRow:j=!1,lockRows:S=!1,disableExpandSelection:T=!1,disableSmartDelete:k=!1,duplicateRow:K=kr,contextMenuComponent:R=un,disableContextMenu:F=!1,onFocus:q=ke,onBlur:U=ke,onActiveCellChange:ee=ke,onSelectionChange:z=ke,rowClassName:W,cellClassName:ce,onScroll:J,pinFirstColumn:te=!1},se)=>{const L=d.useRef(null),A=F||S,b=or(o,f,m,te),_=!!m,ae=te||!!b[1]?.stickyLeft,pe=d.useRef(null),G=d.useRef(null),v=d.useRef(null),D=d.useRef(null),[N,ge]=ur(1,100),{getRowSize:oe,totalSize:Be,getRowIndex:Oe}=Or({value:e,rowHeight:i}),je=Math.min(s,c+Be(s)+N),{width:ue,height:xe}=Qn({targetRef:G,refreshMode:"throttle",refreshRate:100});ge(xe?je-xe:0);const xn=ar(G,ue,xe),{fullWidth:bt,totalWidth:bn,columnWidths:X,columnRights:ie}=_n(b,ue),yn=d.useMemo(()=>b.slice(1).map(l=>!!l.stickyLeft),[b]),vn=d.useCallback(l=>{if(!b[l]?.stickyLeft)return 0;if(!X||!X.length){let w=0;for(let h=0;h<l;h++)(b[h].stickyLeft||h===0)&&(w+=b[h].basis||b[h].minWidth||100);return w}let a=0;for(let w=0;w<l;w++)(b[w].stickyLeft||w===0)&&(a+=X[w]);return a},[b,X]),[ye,le]=d.useState(null),[ve,En]=d.useState([]),[B,Y]=d.useState(!1),[Ee,yt]=d.useState(0),[Se,vt]=d.useState(null),[u,P]=Le(null),[Q,V]=Le(null),y=d.useMemo(()=>u&&Q&&{min:{col:Math.min(u.col,Q.col),row:Math.min(u.row,Q.row)},max:{col:Math.max(u.col,Q.col),row:Math.max(u.row,Q.row)}},[u,Q]),[fe,Ie]=Le({columns:!1,rows:!1,active:!1}),Sn=T||B||fe.active||u?.row===e?.length-1||y?.max.row===e?.length-1||u&&b.slice((y?.min.col??u.col)+1,(y?.max.col??u.col)+2).every(l=>l.disabled===!0)?null:Ee,Et=Bt(pe),St=Bt(G);d.useEffect(()=>{u!==null&&(document.activeElement.blur(),window.getSelection()?.removeAllRanges())},[u!==null]);const be=d.useCallback((l,a=!1,w=!1)=>{const h=Et(a),I=w&&St(a);if(h&&ie&&X){let C=l.clientX-h.left,M=l.clientY-h.top;return I&&(l.clientY-I.top<=c&&(M=0),l.clientX-I.left<=X[0]&&(C=0),ae&&l.clientX-I.left<=X[0]+X[1]&&(C=ie[0]+1),_&&I.right-l.clientX<=X[X.length-1]&&(C=ie[ie.length-2]+1)),{col:ie.findIndex(E=>C<E)-1,row:Oe(M-c)}}return null},[ie,X,e.length,Et,St,c,_,ae,Oe]),ne=d.useRef(e);ne.current=e;const re=d.useCallback(l=>{const a=b[l.col+1].disabled;return!!(typeof a=="function"?a({rowData:ne.current[l.row],rowIndex:l.row}):a)},[b]),de=d.useCallback((l,a=1)=>{S||(V(null),Y(!1),n([...ne.current.slice(0,l+1),...new Array(a).fill(0).map(p),...ne.current.slice(l+1)],[{type:"CREATE",fromRowIndex:l+1,toRowIndex:l+1+a}]),P(w=>({col:w?.col||0,row:l+a,doNotScrollX:!0})))},[p,S,n,P,V]),Ce=d.useCallback((l,a=l)=>{S||(n([...ne.current.slice(0,a+1),...ne.current.slice(l,a+1).map((w,h)=>K({rowData:w,rowIndex:h+l})),...ne.current.slice(a+1)],[{type:"CREATE",fromRowIndex:a+1,toRowIndex:a+2+a-l}]),P({col:0,row:a+1,doNotScrollX:!0}),V({col:b.length-(_?3:2),row:2*a-l+1,doNotScrollX:!0}),Y(!1))},[b.length,K,S,n,P,V,_]),he=d.useCallback(l=>{if(!(!xe||!ue)){if(!l.doNotScrollY){const a=oe(l.row).top,w=oe(l.row).top+oe(l.row).height+c-xe+1,h=G.current.scrollTop;h>a?G.current.scrollTop=a:h<w&&(G.current.scrollTop=w)}if(ie&&X&&G.current&&!l.doNotScrollX){const a=ie[l.col]-ie[0],w=ie[l.col]+X[l.col+1]+(_?X[X.length-1]:0)-ue+1,h=G.current.scrollLeft;h>a?G.current.scrollLeft=a:h<w&&(G.current.scrollLeft=w)}}},[xe,ue,c,ie,X,oe,_]);d.useEffect(()=>{Q&&he(Q)},[Q,he]),d.useEffect(()=>{u&&he(u)},[u,he]);const In=d.useCallback((l,a)=>{n([...ne.current?.slice(0,l),a,...ne.current?.slice(l+1)],[{type:"UPDATE",fromRowIndex:l,toRowIndex:l+1}])},[n]),Te=d.useCallback((l,a=l)=>{S||(Y(!1),P(w=>{const h=Math.min(ne.current.length-2-a+l,l);return h<0?null:w&&{col:w.col,row:h}}),V(null),n([...ne.current.slice(0,l),...ne.current.slice(a+1)],[{type:"DELETE",fromRowIndex:l,toRowIndex:a+1}]))},[S,n,P,V]),_e=d.useCallback((l=!0)=>{const a=l&&!k;if(!u)return;const w=y?.min||u,h=y?.max||u;if(e.slice(w.row,h.row+1).every((C,M)=>b.every(E=>E.isCellEmpty({rowData:C,rowIndex:M+w.row})))){a&&Te(w.row,h.row);return}const I=[...e];for(let C=w.row;C<=h.row;++C)for(let M=w.col;M<=h.col;++M)if(!re({col:M,row:C})){const{deleteValue:E=({rowData:Z})=>Z}=b[M+1];I[C]=E({rowData:I[C],rowIndex:C})}if(a&&on(I,e)){P({col:0,row:w.row,doNotScrollX:!0}),V({col:b.length-(_?3:2),row:h.row,doNotScrollX:!0});return}n(I,[{type:"UPDATE",fromRowIndex:w.row,toRowIndex:h.row+1}])},[u,b,e,Te,re,n,y?.max,y?.min,P,V,_]),Ke=d.useCallback(({nextRow:l=!0}={})=>{u?.row===ne.current.length-1?l&&j?de(u.row):Y(!1):(Y(!1),l&&P(a=>a&&{col:a.col,row:a.row+1}))},[u?.row,j,de,P]),Ne=d.useCallback(async l=>{if(!B&&u){const a=[],w=y?.min||u,h=y?.max||u;for(let E=w.row;E<=h.row;++E){a.push([]);for(let Z=w.col;Z<=h.col;++Z){const{copyValue:H=()=>null}=b[Z+1];a[E-w.row].push(H({rowData:e[E],rowIndex:E}))}}const I=a.map(E=>E.join(" ")).join(`
9
- `),C=`<table>${a.map(E=>`<tr>${E.map(Z=>`<td>${hr(String(Z??"")).replace(/\n/g,"<br/>")}</td>`).join("")}</tr>`).join("")}</table>`;if(l!==void 0){l.clipboardData?.setData("text/plain",I),l.clipboardData?.setData("text/html",C),l.preventDefault();return}let M=!1;if(navigator.clipboard.write!==void 0){const E=new Blob([I],{type:"text/plain"}),Z=new Blob([C],{type:"text/html"}),H=[new ClipboardItem({"text/plain":E,"text/html":Z})];await navigator.clipboard.write(H).then(()=>{M=!0})}else navigator.clipboard.writeText!==void 0?await navigator.clipboard.writeText(I).then(()=>{M=!0}):document.execCommand!==void 0&&document.execCommand("copy")&&(M=!0);M||alert("This action is unavailable in your browser, but you can still use Ctrl+C for copy or Ctrl+X for cut")}},[u,b,e,B,y]);me("copy",Ne);const Ue=d.useCallback(l=>{!B&&u&&(Ne(l),_e(!1))},[u,_e,B,Ne]);me("cut",Ue);const Me=d.useCallback(async l=>{if(!B&&u){const a=y?.min||u,w=y?.max||u,h=await Promise.all(l[0].map((I,C)=>{const M=b[a.col+C+1]?.prePasteValues,E=l.map(Z=>Z[C]);return M?.(E)??E}));if(l=l.map((I,C)=>h.map(M=>M[C])),l.length===1){const I=[...e];for(let C=0;C<l[0].length;C++){const M=b[a.col+C+1]?.pasteValue;if(M)for(let E=a.row;E<=w.row;E++)re({col:C+a.col,row:E})||(I[E]=await M({rowData:I[E],value:l[0][C],rowIndex:E}))}n(I,[{type:"UPDATE",fromRowIndex:a.row,toRowIndex:w.row+1}]),P({col:a.col,row:a.row}),V({col:Math.min(a.col+l[0].length-1,b.length-(_?3:2)),row:w.row})}else{let I=[...e];const C=a.row+l.length-e.length;C>0&&(S?l.splice(l.length-C,C):I=[...I,...new Array(C).fill(0).map(()=>p())]);for(let E=0;E<l[0].length&&a.col+E<b.length-(_?2:1);E++){const Z=b[a.col+E+1]?.pasteValue;if(Z)for(let H=0;H<l.length;H++)re({col:a.col+E,row:a.row+H})||(I[a.row+H]=await Z({rowData:I[a.row+H],value:l[H][E],rowIndex:a.row+H}))}const M=[{type:"UPDATE",fromRowIndex:a.row,toRowIndex:a.row+l.length-(!S&&C>0?C:0)}];C>0&&!S&&M.push({type:"CREATE",fromRowIndex:a.row+l.length-C,toRowIndex:a.row+l.length}),n(I,M),P({col:a.col,row:a.row}),V({col:Math.min(a.col+l[0].length-1,b.length-(_?3:2)),row:a.row+l.length-1})}}},[u,b,p,e,B,_,re,S,n,y?.max,y?.min,P,V]),Cn=d.useCallback(l=>{if(u&&!B){let a=[[""]];l.clipboardData?.types.includes("text/html")?a=ht(l.clipboardData?.getData("text/html")):l.clipboardData?.types.includes("text/plain")?a=Fe(l.clipboardData?.getData("text/plain")):l.clipboardData?.types.includes("text")&&(a=Fe(l.clipboardData?.getData("text"))),Me(a),l.preventDefault()}},[u,Me,B]);me("paste",Cn);const Tn=d.useCallback(l=>{if(ye&&ve.length)return;const a=l.button===2||l.button===0&&l.ctrlKey,w=pe.current?.contains(l.target)||!1,h=w?be(l,!0,!0):null;if(!w&&B&&u&&b[u.col+1].keepFocus)return;if(l.target instanceof HTMLElement&&l.target.className.includes("dsg-expand-rows-indicator")){vt(Math.max(u?.row??0,y?.max.row??0));return}const I=h&&u&&u.col===h.col&&u.row===h.row&&!re(u),C=B&&l.target instanceof HTMLElement&&l.target.classList.contains("dsg-input");if((I||C)&&B)return;const M=h?.col===b.length-2&&_,E=a&&y&&h&&h.row>=y.min.row&&h.row<=y.max.row&&h.col>=y.min.col&&h.col<=y.max.col,Z=a&&y&&h&&h.row===-1&&h.col>=y.min.col&&h.col<=y.max.col,H=a&&y&&h&&h.row>=y.min.row&&h.row<=y.max.row&&h.col===-1,Ct=M&&y&&h&&h.row>=y.min.row&&h.row<=y.max.row;if(a&&!A&&le({x:l.clientX,y:l.clientY,cursorIndex:h}),(!(l.shiftKey&&u)||a)&&e.length>0&&P(h&&{col:(E||Z)&&u?u.col:Math.max(0,M?0:h.col),row:(E||H||Ct)&&u?u.row:Math.max(0,h.row),doNotScrollX:!!(E&&u||M||h.col===-1),doNotScrollY:!!(E&&u||h.row===-1)}),I&&!a&&(L.current=u),Y(!!(I&&!a)),Ie(h&&!a?{columns:h.col!==-1&&!M||!!(l.shiftKey&&u),rows:h.row!==-1||!!(l.shiftKey&&u),active:!0}:{columns:!1,rows:!1,active:!1}),l.shiftKey&&u&&!a)V(h&&{col:Math.max(0,h.col-(M?1:0)),row:Math.max(0,h.row)});else if(!E){if(h&&(h?.col===-1||h?.row===-1||M)){let $e=h.col,Ge=h.row,Xe=!1,Ye=!1;(h.col===-1||M)&&($e=b.length-(_?3:2),Xe=!0),h.row===-1&&(Ge=e.length-1,Ye=!0),Z&&Q&&($e=Q.col,Ye=!0),(H||Ct)&&Q&&(Ge=Q.row,Xe=!0),V({col:$e,row:Ge,doNotScrollX:Xe,doNotScrollY:Ye})}else V(null);w&&l.preventDefault()}},[ye,ve.length,be,B,u,b,re,y,_,A,Ie,P,V,Q,e.length]);me("mousedown",Tn);const Rn=d.useCallback(()=>{if(Se!==null){if(Ee>0&&u){let l=[];const a=y?.min||u,w=y?.max||u;for(let h=a.row;h<=w.row;++h){l.push([]);for(let I=a.col;I<=w.col;++I){const{copyValue:C=()=>null}=b[I+1];l[h-a.row].push(String(C({rowData:e[h],rowIndex:h})??""))}}Promise.all(l[0].map((h,I)=>{const C=b[a.col+I+1]?.prePasteValues,M=l.map(E=>E[I]);return C?.(M)??M})).then(h=>{l=l.map((C,M)=>h.map(E=>E[M]));const I=[...e];for(let C=0;C<l[0].length;C++){const M=b[a.col+C+1]?.pasteValue;if(M)for(let E=w.row+1;E<=w.row+Ee;E++)re({col:C+a.col,row:E})||(I[E]=M({rowData:I[E],value:l[(E-w.row-1)%l.length][C],rowIndex:E}))}n(I,[{type:"UPDATE",fromRowIndex:w.row+1,toRowIndex:w.row+1+Ee}])}),yt(0),P({col:Math.min(u?.col??1/0,y?.min.col??1/0),row:Math.min(u?.row??1/0,y?.min.row??1/0),doNotScrollX:!0,doNotScrollY:!0}),V({col:Math.max(u?.col??0,y?.max.col??0),row:Math.max(u?.row??0,y?.max.row??0)+Ee})}vt(null)}Ie({columns:!1,rows:!1,active:!1})},[Se,Ie,Ee,u,y?.min,y?.max,e,n,P,V,b,re]);me("mouseup",Rn);const Dn=d.useCallback(l=>{if(Se!==null){const a=be(l);a&&(yt(Math.max(0,a.row-Se)),he({col:a.col,row:Math.max(a.row,Se)}))}if(fe.active){const a=be(l),w=b.length-(_?3:2);V(a&&{col:fe.columns?Math.max(0,Math.min(w,a.col)):w,row:fe.rows?Math.max(0,a.row):e.length-1,doNotScrollX:!fe.columns,doNotScrollY:!fe.rows}),Y(!1)}},[he,fe.active,fe.columns,fe.rows,be,b.length,_,V,e.length,Se]);me("mousemove",Dn);const On=d.useCallback(l=>{if(u&&!l.isComposing){if(l.key==="Tab"&&!l.shiftKey&&u.col===b.length-(_?3:2)&&!b[u.col+1].disableKeys)if(u.row===e.length-1){if(D.current){l.preventDefault(),P(null),V(null),Y(!1);const a=Ut(),w=a.indexOf(D.current);a[(w+1)%a.length].focus();return}}else{P(a=>({col:0,row:(a?.row??0)+1})),V(null),Y(!1),l.preventDefault();return}if(l.key==="Tab"&&l.shiftKey&&u.col===0&&!b[u.col+1].disableKeys)if(u.row===0){if(v.current){l.preventDefault(),P(null),V(null),Y(!1);const a=Ut(),w=a.indexOf(v.current);a[(w-1+a.length)%a.length].focus();return}}else{P(a=>({col:b.length-(_?3:2),row:(a?.row??1)-1})),V(null),Y(!1),l.preventDefault();return}if(l.key?.startsWith("Arrow")||l.key==="Tab"){if(B&&b[u.col+1].disableKeys||B&&["ArrowLeft","ArrowRight"].includes(l.key))return;const a=([w,h],I)=>I&&{col:Math.max(0,Math.min(b.length-(_?3:2),I.col+w)),row:Math.max(0,Math.min(e.length-1,I.row+h))};if(l.key==="Tab"&&l.shiftKey)P(w=>a([-1,0],w)),V(null);else{const w={ArrowDown:[0,1],ArrowUp:[0,-1],ArrowLeft:[-1,0],ArrowRight:[1,0],Tab:[1,0]}[l.key];(l.ctrlKey||l.metaKey)&&(w[0]*=b.length,w[1]*=e.length),l.shiftKey?V(h=>a(w,h||u)):(P(h=>a(w,h)),V(null))}Y(!1),l.preventDefault()}else l.key==="Escape"?(!B&&!Q&&P(null),V(null),Y(!1)):(l.key==="Enter"||l.key==="F2")&&!l.ctrlKey&&!l.metaKey&&!l.altKey&&!l.shiftKey?(V(null),B?b[u.col+1].disableKeys||(Ke(),l.preventDefault()):re(u)||(L.current=u,Y(!0),he(u),l.preventDefault())):l.key==="Enter"&&!l.ctrlKey&&!l.metaKey&&!l.altKey&&l.shiftKey?de(y?.max.row||u.row):l.key==="d"&&(l.ctrlKey||l.metaKey)&&!l.altKey&&!l.shiftKey?(Ce(y?.min.row||u.row,y?.max.row),l.preventDefault()):(mr(l.key)||l.code.match(/Key[A-Z]$/))&&!l.ctrlKey&&!l.metaKey&&!l.altKey?!B&&!re(u)&&(L.current=u,V(null),Y(!0),he(u)):["Backspace","Delete"].includes(l.key)?B||(_e(),l.preventDefault()):l.key==="a"&&(l.ctrlKey||l.metaKey)&&(B||(P({col:0,row:0,doNotScrollY:!0,doNotScrollX:!0}),V({col:b.length-(_?3:2),row:e.length-1,doNotScrollY:!0,doNotScrollX:!0}),l.preventDefault()))}},[u,b,e.length,_e,Ce,B,de,re,he,y?.max.row,y?.min.row,Q,P,V,Ke,_]);me("keydown",On);const jn=d.useCallback(l=>{const a=pe.current?.contains(l.target)||!1,w=a?be(l,!0,!0):null,h=w&&u&&u.col===w.col&&u.row===w.row&&B;a&&!h&&l.preventDefault()},[be,u,B]);me("contextmenu",jn),d.useEffect(()=>{const l=[];u?.row!==void 0&&l.push({type:"COPY",action:()=>{Ne(),le(null)}},{type:"CUT",action:()=>{Ue(),le(null)}},{type:"PASTE",action:async()=>{if(navigator.clipboard.read!==void 0)(await navigator.clipboard.read()).forEach(async w=>{let h=[[""]];if(w.types.includes("text/html")){const I=await w.getType("text/html");h=ht(await I.text())}else if(w.types.includes("text/plain")){const I=await w.getType("text/plain");h=Fe(await I.text())}else if(w.types.includes("text")){const I=await w.getType("text");h=ht(await I.text())}Me(h)});else if(navigator.clipboard.readText!==void 0){const a=await navigator.clipboard.readText();Me(Fe(a))}else alert("This action is unavailable in your browser, but you can still use Ctrl+V for paste");le(null)}}),y?.max.row!==void 0?l.push({type:"INSERT_ROW_BELLOW",action:()=>{le(null),de(y.max.row)}}):u?.row!==void 0&&l.push({type:"INSERT_ROW_BELLOW",action:()=>{le(null),de(u.row)}}),y?.min.row!==void 0&&y.min.row!==y.max.row?l.push({type:"DUPLICATE_ROWS",fromRow:y.min.row+1,toRow:y.max.row+1,action:()=>{le(null),Ce(y.min.row,y.max.row)}}):u?.row!==void 0&&l.push({type:"DUPLICATE_ROW",action:()=>{le(null),Ce(u.row)}}),y?.min.row!==void 0&&y.min.row!==y.max.row?l.push({type:"DELETE_ROWS",fromRow:y.min.row+1,toRow:y.max.row+1,action:()=>{le(null),Te(y.min.row,y.max.row)}}):u?.row!==void 0&&l.push({type:"DELETE_ROW",action:()=>{le(null),Te(u.row)}}),En(l),l.length||le(null)},[y,u,Te,Ce,de,Ue,Ne,Me]);const It=d.useRef(ve);It.current=ve;const Nn=d.useCallback(()=>It.current,[]);d.useImperativeHandle(se,()=>({activeCell:De(u,b),selection:Kt(y??(u?{min:u,max:u}:null),b),setSelection:l=>{const a=pr(l,b.length-(_?2:1),e.length,b);P(a?.min||null),Y(!1),Ie({columns:!1,active:!1,rows:!1}),V(a?.max||null)},setActiveCell:l=>{const a=pt(l,b.length-(_?2:1),e.length,b);P(a),Y(!1),Ie({columns:!1,active:!1,rows:!1}),V(null)}}));const we=d.useRef({onFocus:q,onBlur:U,onActiveCellChange:ee,onSelectionChange:z});return we.current.onFocus=q,we.current.onBlur=U,we.current.onActiveCellChange=ee,we.current.onSelectionChange=z,d.useEffect(()=>{L.current&&(B?we.current.onFocus({cell:De(L.current,b)}):we.current.onBlur({cell:De(L.current,b)}))},[B,b]),d.useEffect(()=>{we.current.onActiveCellChange({cell:De(u,b)})},[u?.col,u?.row,b]),d.useEffect(()=>{we.current.onSelectionChange({selection:Kt(y??(u?{min:u,max:u}:null),b)})},[y?.min.col??u?.col,y?.min.row??u?.row,y?.max.col??u?.col,y?.max.row??u?.row,u?.col,u?.row,b]),x.jsxs("div",{className:r,style:t,children:[x.jsx("div",{ref:v,tabIndex:o.length&&e.length?0:void 0,onFocus:l=>{l.target.blur(),P({col:0,row:0})}}),x.jsx(Dr,{columns:b,outerRef:G,columnWidths:X,hasStickyRightColumn:_,pinFirstColumn:te,displayHeight:je,data:e,fullWidth:bt,headerRowHeight:c,activeCell:u,innerRef:pe,rowHeight:oe,rowKey:g,selection:y,rowClassName:W,editing:B,getContextMenuItems:Nn,setRowData:In,deleteRows:Te,insertRowAfter:de,duplicateRows:Ce,stopEditing:Ke,cellClassName:ce,onScroll:J,children:x.jsx(hn,{columnRights:ie,columnWidths:X,activeCell:u,selection:y,headerRowHeight:c,rowHeight:oe,hasStickyRightColumn:_,dataLength:e.length,viewHeight:xe,viewWidth:ue,contentWidth:bt?void 0:bn,edges:xn,editing:B,isCellDisabled:re,expandSelection:Sn,stickyLeftColumns:yn,getStickyLeftOffset:vn})}),x.jsx("div",{ref:D,tabIndex:o.length&&e.length?0:void 0,onFocus:l=>{l.target.blur(),P({col:b.length-(_?3:2),row:e.length-1})}}),!S&&O&&x.jsx(O,{addRows:l=>de(e.length-1,l)}),ye&&ve.length>0&&x.jsx(R,{clientX:ye.x,clientY:ye.y,cursorIndex:ye.cursorIndex,items:ve,close:()=>le(null)})]})}));xt.displayName="DataSheetGrid";const Ar=d.forwardRef(({columns:e,gutterColumn:r,stickyRightColumn:t,addRowsComponent:s,createRow:n,duplicateRow:o,style:i,rowKey:c,onFocus:f,onBlur:m,onActiveCellChange:g,onSelectionChange:O,rowClassName:p,rowHeight:j,...S},T)=>{const[k]=d.useState({columns:e,gutterColumn:r,stickyRightColumn:t,addRowsComponent:s,createRow:n,duplicateRow:o,style:i,rowKey:c,onFocus:f,onBlur:m,onActiveCellChange:g,onSelectionChange:O,rowClassName:p,rowHeight:j});return x.jsx(xt,{...k,...S,rowHeight:typeof j=="number"?j:k.rowHeight,ref:T})}),_r=()=>{const e=d.useRef(!0),r=e.current;return e.current=!1,r},mn=d.memo(({active:e,focus:r,rowData:t,setRowData:s,columnData:{placeholder:n,alignRight:o,formatInputOnFocus:i,formatBlurredInput:c,parseUserInput:f,continuousUpdates:m}})=>{const g=d.useRef(null),O=_r(),p=d.useRef({rowData:t,formatInputOnFocus:i,formatBlurredInput:c,setRowData:s,parseUserInput:f,continuousUpdates:m,firstRender:O,focusedAt:0,changedAt:0,escPressed:!1});return p.current={rowData:t,formatInputOnFocus:i,formatBlurredInput:c,setRowData:s,parseUserInput:f,continuousUpdates:m,firstRender:O,focusedAt:p.current.focusedAt,changedAt:p.current.changedAt,escPressed:p.current.escPressed},d.useLayoutEffect(()=>{r?(g.current&&(g.current.value=p.current.formatInputOnFocus(p.current.rowData),g.current.focus(),g.current.select()),p.current.escPressed=!1,p.current.focusedAt=Date.now()):g.current&&(!p.current.escPressed&&!p.current.continuousUpdates&&!p.current.firstRender&&p.current.changedAt>=p.current.focusedAt&&p.current.setRowData(p.current.parseUserInput(g.current.value)),g.current.blur())},[r]),d.useEffect(()=>{!r&&g.current&&(g.current.value=p.current.formatBlurredInput(t))},[r,t]),x.jsx("input",{defaultValue:c(t),className:$("dsg-input",o&&"dsg-input-align-right"),placeholder:e?n:void 0,tabIndex:-1,ref:g,style:{pointerEvents:r?"auto":"none"},onChange:j=>{p.current.changedAt=Date.now(),m&&s(f(j.target.value))},onKeyDown:j=>{j.key==="Escape"&&(p.current.escPressed=!0)}})});mn.displayName="TextComponent";const zr=Ae();function Ae({placeholder:e,alignRight:r=!1,continuousUpdates:t=!0,deletedValue:s=null,parseUserInput:n=m=>m.trim()||null,formatBlurredInput:o=m=>String(m??""),formatInputOnFocus:i=m=>String(m??""),formatForCopy:c=m=>String(m??""),parsePastedValue:f=m=>m.replace(/[\n\r]+/g," ").trim()||null}={}){return{component:mn,columnData:{placeholder:e,alignRight:r,continuousUpdates:t,formatInputOnFocus:i,formatBlurredInput:o,parseUserInput:n},deleteValue:()=>s,copyValue:({rowData:m})=>c(m),pasteValue:({value:m})=>f(m),isCellEmpty:({rowData:m})=>m==null}}const Fr=["","false","no","off","disabled","0","n","f","unchecked","undefined","null","wrong","negative"],pn=d.memo(({focus:e,rowData:r,setRowData:t,active:s,stopEditing:n,disabled:o})=>{const i=d.useRef(null);return d.useLayoutEffect(()=>{e&&(t(!r),n({nextRow:!1}))},[e,n]),x.jsx("input",{className:"dsg-checkbox",tabIndex:-1,type:"checkbox",ref:i,disabled:o,checked:!!r,onMouseDown:()=>!s&&t(!r),onChange:()=>null})});pn.displayName="CheckboxComponent";const Vr={component:pn,deleteValue:()=>!1,copyValue:({rowData:e})=>e?"YES":"NO",pasteValue:({value:e})=>!Fr.includes(e.toLowerCase()),isCellEmpty:({rowData:e})=>!e},Lr=Ae({alignRight:!0,formatBlurredInput:e=>typeof e=="number"?new Intl.NumberFormat().format(e):"",parseUserInput:e=>{const r=parseFloat(e);return isNaN(r)?null:r},parsePastedValue:e=>{const r=parseFloat(e);return isNaN(r)?null:r}}),Pr=Ae({alignRight:!0,formatBlurredInput:e=>typeof e=="number"?new Intl.NumberFormat().format(e):"",parseUserInput:e=>{const r=parseFloat(e);return isNaN(r)?null:Math.round(r)},parsePastedValue:e=>{const r=parseFloat(e);return isNaN(r)?null:Math.round(r)}}),qr=1e12,Wr=1e10,Br=Ae({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*qr)/Wr):"",parseUserInput:e=>{const r=parseFloat(e);return isNaN(r)?null:r/100},parsePastedValue:e=>{const r=parseFloat(e);return isNaN(r)?null:r}}),gn=d.memo(({focus:e,active:r,rowData:t,setRowData:s})=>{const n=d.useRef(null);return d.useLayoutEffect(()=>{e?n.current?.select():n.current?.blur()},[e]),x.jsx("input",{className:$("dsg-input",!r&&"dsg-hide-date-picker"),type:"date",tabIndex:-1,max:"9999-12-31",ref:n,style:{pointerEvents:e?"auto":"none",opacity:t||r?void 0:0},value:t?.toISOString().substr(0,10)??"",onChange:o=>{const i=new Date(o.target.value);s(isNaN(i.getTime())?null:i)}})});gn.displayName="DateComponent";const Kr={component:gn,deleteValue:()=>null,copyValue:({rowData:e})=>e?e.toISOString().substr(0,10):null,pasteValue:({value:e})=>{const r=new Date(e.replace(/\.\s?|\//g,"-"));return isNaN(r.getTime())?null:r},minWidth:170,isCellEmpty:({rowData:e})=>!e},wn=d.memo(({focus:e,active:r,rowData:t,setRowData:s})=>{const n=d.useRef(null);return d.useLayoutEffect(()=>{e?n.current?.select():n.current?.blur()},[e]),x.jsx("input",{className:$("dsg-input",!r&&"dsg-hide-date-picker"),type:"date",tabIndex:-1,max:"9999-12-31",ref:n,style:{pointerEvents:e?"auto":"none",opacity:t||r?void 0:0},value:t??"",onChange:o=>{const i=new Date(o.target.value);s(isNaN(i.getTime())?null:i.toISOString().substr(0,10))}})});wn.displayName="IsoDateComponent";const Ur={component:wn,deleteValue:()=>null,copyValue:({rowData:e})=>e,pasteValue:({value:e})=>{const r=new Date(e.replace(/\.\s?|\//g,"-"));return isNaN(r.getTime())?null:r.toISOString().substr(0,10)},minWidth:170,isCellEmpty:({rowData:e})=>!e},$r=({columnData:{key:e,original:r},rowData:t,setRowData:s,...n})=>{const o=d.useRef(t);o.current=t;const i=d.useCallback(f=>{s({...o.current,[e]:f})},[e,s]);if(!r.component)return x.jsx(x.Fragment,{});const c=r.component;return x.jsx(c,{columnData:r.columnData,setRowData:i,rowData:t[e],...n})},Gr=(e,r)=>({id:e,...r,columnData:{key:e,original:r},component:$r,copyValue:({rowData:t,rowIndex:s})=>r.copyValue?.({rowData:t[e],rowIndex:s})??null,deleteValue:({rowData:t,rowIndex:s})=>({...t,[e]:r.deleteValue?.({rowData:t[e],rowIndex:s})??null}),pasteValue:({rowData:t,value:s,rowIndex:n})=>({...t,[e]:r.pasteValue?.({rowData:t[e],value:s,rowIndex:n})??null}),disabled:typeof r.disabled=="function"?({rowData:t,rowIndex:s})=>typeof r.disabled=="function"?r.disabled({rowData:t[e],rowIndex:s}):r.disabled??!1:r.disabled,cellClassName:typeof r.cellClassName=="function"?({rowData:t,rowIndex:s,columnId:n})=>typeof r.cellClassName=="function"?r.cellClassName({rowData:t[e],rowIndex:s,columnId:n}):r.cellClassName??void 0:r.cellClassName,isCellEmpty:({rowData:t,rowIndex:s})=>r.isCellEmpty?.({rowData:t[e],rowIndex:s})??!1}),Xr=xt,Yr=Ar;exports.DataSheetGrid=Yr;exports.DynamicDataSheetGrid=Xr;exports.checkboxColumn=Vr;exports.createAddRowsComponent=ln;exports.createContextMenuComponent=an;exports.createTextColumn=Ae;exports.dateColumn=Kr;exports.floatColumn=Lr;exports.intColumn=Pr;exports.isoDateColumn=Ur;exports.keyColumn=Gr;exports.percentColumn=Br;exports.renderContextMenuItem=wt;exports.textColumn=zr;
10
- //# sourceMappingURL=index.cjs.map
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,ee=({rowIndex:e})=>(0,u.jsx)(u.Fragment,{children:e+1}),C=()=>!0,w=e=>e,te=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}},ne=(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:C}:{...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??ee,isCellEmpty:C},...e];return n&&i.push({...n,basis:n?.basis??40,grow:n?.grow??0,shrink:n?.shrink??0,minWidth:n.minWidth??0,isCellEmpty:C}),i.map((e,t)=>{let n=e.width===void 0?{basis:void 0,grow:void 0,shrink:void 0}:te(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??w,isCellEmpty:e.isCellEmpty??b,stickyLeft:i}})},[t,n,e,r]),T=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])]},E=(e,t,n)=>{let[r,i]=T({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},D=(e,t)=>{(0,c.useEffect)(()=>{let n=(...e)=>{t(...e)};return document.addEventListener(e,n),()=>{document.removeEventListener(e,n)}},[t,e])},O=(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])},k=(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`]})},re=k();re.displayName=`AddRows`;var ie=(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])]},A=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=A)=>({clientX:t,clientY:n,items:r,close:i})=>{let a=(0,c.useRef)(null);return D(`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(A);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.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??``]]:[[``]]},ce=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(`
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.replace(/"/g,`""`)}"`:e,ue=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`),de=e=>e.match(/^[^\x00-\x20\x7F-\x9F]$/)!==null,fe=(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},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 Error(`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,rowKey:f,fullWidth:p,selection:g,activeCell:_,rowClassName:v,cellClassName:y,children:b,editing:x,getContextMenuItems:S,setRowData:ee,deleteRows:C,duplicateRows:w,insertRowAfter:te,stopEditing:ne,onScroll:T})=>{let E=(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}),D=(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)(()=>{D.measure()},[D,i]);let O=ve(ee,1),k=ve(C,0),re=ve(w,0),ie=ve(te,0),A=e=>{if(!t[e].stickyLeft)return 0;if(!i||!i.length){let t=D.getOffsetForIndex(e);return typeof t==`number`?t:0}let n=0;for(let t=0;t<e;t++)n+=i[t];return n},j=g?.min.col??_?.col,M=g?.max.col??_?.col,ae=g?.min.row??_?.row,oe=g?.max.row??_?.row;return(0,u.jsx)(`div`,{ref:n,className:`dsg-container`,onScroll:T,style:{height:s},children:(0,u.jsxs)(`div`,{ref:r,style:{width:p?`100%`:D.getTotalSize(),height:E.getTotalSize()},children:[l>0&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,`dsg-row-header`),style:{width:p?`100%`:D.getTotalSize(),height:l},children:D.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?A(e.index):e.start,className:(0,h.default)(`dsg-cell-header`,j!==void 0&&M!==void 0&&j<=e.index-1&&M>=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)})}),E.getVirtualItems().map(n=>{let r=n.index>=(ae??1/0)&&n.index<=(oe??-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%`:D.getTotalSize()},children:D.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)(_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 y==`function`?y({rowData:e[n.index],rowIndex:n.index,columnId:t[i.index].id}):y),width:i.size,left:f?A(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:k(n.index),duplicateRow:re(n.index),stopEditing:ne,insertRowBelow:ie(n.index),setRowData:O(n.index),columnData:t[i.index].columnData})},i.key)})},n.key)}),b]})})},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),ee=t=>+(t<e.length-(o?3:2)),C=a&&{width:e[a.col+1]+ee(a.col),height:i(a.row).height+S(a.row),left:t[a.col],top:i(a.row).top+n},w=r&&{width:e.slice(r.min.col+1,r.max.col+2).reduce((e,t)=>e+t)+ee(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},te=a&&v&&y&&v[a.col],ne=te&&y?y(a.col+1):0,T=r&&v&&y&&(()=>{for(let e=r.min.col;e<=r.max.col;e++)if(!v[e])return!1;return!0})(),E=T&&r&&y?y(r.min.col+1):0,D=r?.min||a,O=r?.max||a,k=O&&v&&y&&v[O.col],re=k&&O&&y?y(O.col+1)+e[O.col+1]:0,ie=r&&v&&v[r.min.col]||a&&v&&v[a.col],A=ie&&y?y((r?.min.col??a?.col??0)+1):0,j=O&&_!==null&&{left:t[O.col]+e[O.col+1],top:i(O.row).top+i(O.row).height+n,transform:`translate(-${O.col<e.length-(o?3:2)?50:100}%, -${O.row<s-1?50:100}%)`},M=D&&O&&_!==null&&{width:e.slice(D.col+1,O.col+2).reduce((e,t)=>e+t)+ee(O.col),height:i(O.row+_).top+i(O.row+_).height-i(O.row+1).top+S(O.row+_)-1,left:t[D.col],top:i(O.row).top+i(O.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)`}})}),(w||C)&&!ie&&(0,u.jsx)(`div`,{className:`dsg-selection-col-marker-container`,style:{left:w?.left??C?.left,width:w?.width??C?.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}})}),(w||C)&&ie&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker-container`,`dsg-selection-col-marker-container-sticky`),style:{position:`sticky`,left:A,top:`auto`,width:w?.width??C?.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}})}),(w||C)&&(0,u.jsx)(`div`,{className:`dsg-selection-row-marker-container`,style:{top:w?.top??C?.top,height:w?.height??C?.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]}})}),C&&a&&!te&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-active-cell`,{"dsg-active-cell-focus":g,"dsg-active-cell-disabled":b}),style:C}),C&&a&&te&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:C.top,left:0,right:0,height:C.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:ne,width:C.width,height:`100%`}})}),w&&C&&!T&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-rect`,x&&`dsg-selection-rect-disabled`),style:{...w,clipPath:be(C.top-w.top,C.left-w.left,C.top+C.height-w.top,C.left+C.width-w.left)}}),w&&C&&T&&(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-selection-rect`,x&&`dsg-selection-rect-disabled`,`dsg-selection-rect-sticky`),style:{position:`sticky`,left:E,width:w.width,height:`100%`,background:`var(--dsg-selection-background-color)`,clipPath:be(C.top-w.top,ne-E,C.top+C.height-w.top,ne+C.width-E)}})}),M&&!T&&(0,u.jsx)(`div`,{className:`dsg-expand-rows-rect`,style:M}),M&&T&&(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:E,width:M.width,height:`100%`}})}),j&&!k&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-indicator`,x&&`dsg-expand-rows-indicator-disabled`),style:j}),j&&k&&(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:re,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[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])},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=re,createRow:g=Te,autoAddRow:_=!1,lockRows:y=!1,disableExpandSelection:b=!1,disableSmartDelete:x=!1,duplicateRow:S=De,contextMenuComponent:ee=M,disableContextMenu:C=!1,onFocus:w=Ee,onBlur:te=Ee,onActiveCellChange:k=Ee,onSelectionChange:A=Ee,rowClassName:j,cellClassName:ae,onScroll:oe,pinFirstColumn:_e=!1},ve)=>{let N=(0,c.useRef)(null),be=C||y,P=ne(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]=ie(1,100),{getRowSize:Pe,totalSize:Fe,getRowIndex:Ie}=Se({value:e,rowHeight:o}),Le=Math.min(r,s+Fe(r)+Me),{width:Re,height:L}=(0,l.useResizeDetector)({targetRef:I,refreshMode:`throttle`,refreshRate:100});Ne(L?Le-L:0);let ze=E(I,Re,L),{fullWidth:Be,totalWidth:Ve,columnWidths:R,columnRights:z}=v(P,Re),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||!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]=T(null),[G,K]=T(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]=T({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=O(ke),et=O(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[R.length-1]&&(t=z[z.length-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(!(!L||!Re)){if(!e.doNotScrollY){let t=Pe(e.row).top,n=Pe(e.row).top+Pe(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[R.length-1]:0)-Re+1,r=I.current.scrollLeft;r>t?I.current.scrollLeft=t:r<n&&(I.current.scrollLeft=n)}}},[L,Re,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})}if(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});return}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??``)).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`)}},[U,P,e,V,q]);D(`copy`,st);let ct=(0,c.useCallback)(e=>{!V&&U&&(st(e),at(!1))},[U,at,V,st]);D(`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 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]);D(`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])),D(`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&&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])),D(`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 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])),D(`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])),D(`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)||t.code.match(/Key[A-Z]$/))&&!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])),D(`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 navigator.clipboard.readText===void 0?alert(`This action is unavailable in your browser, but you can still use Ctrl+V for paste`):await lt(ce(await navigator.clipboard.readText()));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=>{W(fe(t,P.length-(F?2:1),e.length,P)),H(!1),Ze({columns:!1,active:!1,rows:!1}),K(null)}}));let $=(0,c.useRef)({onFocus:w,onBlur:te,onActiveCellChange:k,onSelectionChange:A});return $.current.onFocus=w,$.current.onBlur=te,$.current.onActiveCellChange=k,$.current.onSelectionChange=A,(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: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:L,viewWidth:Re,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)(ee,{clientX:We.x,clientY:We.y,cursorIndex:We.cursorIndex,items:Ge,close:()=>B(null)})]})}));P.displayName=`DataSheetGrid`;var F=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)(P,{...v,...g,rowHeight:typeof h==`number`?h:v.rowHeight,ref:_})}),Oe=()=>{let e=(0,c.useRef)(!0),t=e.current;return e.current=!1,t},ke=480,I=300,Ae=(e,t,n,r,i)=>Math.max(0,Math.min(Math.max(e,n),r-t-i)),je=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=Oe(),[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`))||ke,r=parseFloat(t.getPropertyValue(`--dsg-cell-expanded-max-height`))||I,i,a=()=>{let e=m.getBoundingClientRect(),t=Ae(e.width,e.left,n,window.innerWidth,8),o=Ae(e.height,e.top,r,window.innerHeight,8);y(n=>n&&n.top===e.top&&n.left===e.left&&n.width===e.width&&n.height===e.height&&n.maxWidth===t&&n.maxHeight===o?n:{top:e.top,left:e.left,width:e.width,height:e.height,maxWidth:t,maxHeight:o}),i=requestAnimationFrame(a)};return a(),()=>cancelAnimationFrame(i)},[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=!!(t&&v),S=(0,u.jsx)(`textarea`,{rows:1,defaultValue:s(n),className:(0,h.default)(`dsg-input`,a&&`dsg-input-align-right`,x&&`dsg-input-floating`),placeholder:e?i:void 0,tabIndex:-1,ref:f,style:v?{pointerEvents:t?`auto`:`none`,minWidth:x?Math.min(v.width,v.maxWidth):v.width,...x?{maxWidth:v.maxWidth,maxHeight:v.maxHeight}:{width:v.width}}:{pointerEvents:t?`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`},children:S});return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{ref:_,className:`dsg-input-anchor`}),m&&(0,g.createPortal)(e?ee:S,e?document.body:m)]})});je.displayName=`TextComponent`;var Me=Ne();function Ne({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:je,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 Pe=[``,`false`,`no`,`off`,`disabled`,`0`,`n`,`f`,`unchecked`,`undefined`,`null`,`wrong`,`negative`],Fe=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})});Fe.displayName=`CheckboxComponent`;var Ie={component:Fe,deleteValue:()=>!1,copyValue:({rowData:e})=>e?`YES`:`NO`,pasteValue:({value:e})=>!Pe.includes(e.toLowerCase()),isCellEmpty:({rowData:e})=>!e},Le=Ne({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}}),Re=Ne({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)}}),L=0xe8d4a51000,ze=1e10,Be=Ne({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*L)/ze):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:t/100},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:t}}),Ve=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)}})});Ve.displayName=`DateComponent`;var R={component:Ve,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},z=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))}})});z.displayName=`IsoDateComponent`;var He={component:z,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},Ue=({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})},We=(e,t)=>({id:e,...t,columnData:{key:e,original:t},component:Ue,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}),B=P,Ge=F;exports.DataSheetGrid=Ge,exports.DynamicDataSheetGrid=B,exports.checkboxColumn=Ie,exports.createAddRowsComponent=k,exports.createContextMenuComponent=j,exports.createTextColumn=Ne,exports.dateColumn=R,exports.floatColumn=Le,exports.intColumn=Re,exports.isoDateColumn=He,exports.keyColumn=We,exports.percentColumn=Be,exports.renderContextMenuItem=A,exports.textColumn=Me;
7
+ //# sourceMappingURL=index.cjs.map