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

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 +1918 -3142
  6. package/dist/index.js.map +1 -1
  7. package/dist/style.css +2 -0
  8. package/package.json +63 -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 -12
  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 -43
  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 -198
  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 b=require("react/jsx-runtime"),d=require("react"),Tn=require("react-dom");function On(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 Ve=On(d),Rn=(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,a)=>i+(a.frozen?0:a.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,a)=>i-a.size,e)}return t.map(({size:n})=>n)},Dn=(e,r)=>{const t=e.map(({basis:s,minWidth:n,maxWidth:o,grow:i,shrink:a})=>[s,n,o,i,a].join(",")).join("|");return d.useMemo(()=>{if(r===void 0)return{fullWidth:!1,columnWidths:void 0,columnRights:void 0,totalWidth:void 0};const s=Rn(r,e);let n=0;const o=s.map((i,a)=>(n+=i,a===s.length-1?1/0:n));return{fullWidth:Math.abs(r-n)<.1,columnWidths:s,columnRights:o,totalWidth:n}},[r,t])};var _e=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Le(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Xe,St;function mt(){if(St)return Xe;St=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return Xe=e,Xe}var Ye,It;function Nn(){if(It)return Ye;It=1;var e=typeof _e=="object"&&_e&&_e.Object===Object&&_e;return Ye=e,Ye}var Ze,Ct;function Qt(){if(Ct)return Ze;Ct=1;var e=Nn(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return Ze=t,Ze}var Je,Tt;function jn(){if(Tt)return Je;Tt=1;var e=Qt(),r=function(){return e.Date.now()};return Je=r,Je}var Qe,Ot;function Mn(){if(Ot)return Qe;Ot=1;var e=/\s/;function r(t){for(var s=t.length;s--&&e.test(t.charAt(s)););return s}return Qe=r,Qe}var He,Rt;function An(){if(Rt)return He;Rt=1;var e=Mn(),r=/^\s+/;function t(s){return s&&s.slice(0,e(s)+1).replace(r,"")}return He=t,He}var et,Dt;function Ht(){if(Dt)return et;Dt=1;var e=Qt(),r=e.Symbol;return et=r,et}var tt,Nt;function _n(){if(Nt)return tt;Nt=1;var e=Ht(),r=Object.prototype,t=r.hasOwnProperty,s=r.toString,n=e?e.toStringTag:void 0;function o(i){var a=t.call(i,n),h=i[n];try{i[n]=void 0;var f=!0}catch{}var g=s.call(i);return f&&(a?i[n]=h:delete i[n]),g}return tt=o,tt}var nt,jt;function kn(){if(jt)return nt;jt=1;var e=Object.prototype,r=e.toString;function t(s){return r.call(s)}return nt=t,nt}var rt,Mt;function zn(){if(Mt)return rt;Mt=1;var e=Ht(),r=_n(),t=kn(),s="[object Null]",n="[object Undefined]",o=e?e.toStringTag:void 0;function i(a){return a==null?a===void 0?n:s:o&&o in Object(a)?r(a):t(a)}return rt=i,rt}var st,At;function Fn(){if(At)return st;At=1;function e(r){return r!=null&&typeof r=="object"}return st=e,st}var ot,_t;function Vn(){if(_t)return ot;_t=1;var e=zn(),r=Fn(),t="[object Symbol]";function s(n){return typeof n=="symbol"||r(n)&&e(n)==t}return ot=s,ot}var it,kt;function Pn(){if(kt)return it;kt=1;var e=An(),r=mt(),t=Vn(),s=NaN,n=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,i=/^0o[0-7]+$/i,a=parseInt;function h(f){if(typeof f=="number")return f;if(t(f))return s;if(r(f)){var g=typeof f.valueOf=="function"?f.valueOf():f;f=r(g)?g+"":g}if(typeof f!="string")return f===0?f:+f;f=e(f);var C=o.test(f);return C||i.test(f)?a(f.slice(2),C?2:8):n.test(f)?s:+f}return it=h,it}var lt,zt;function en(){if(zt)return lt;zt=1;var e=mt(),r=jn(),t=Pn(),s="Expected a function",n=Math.max,o=Math.min;function i(a,h,f){var g,C,p,D,E,N,z=0,W=!1,R=!1,O=!0;if(typeof a!="function")throw new TypeError(s);h=t(h)||0,e(f)&&(W=!!f.leading,R="maxWait"in f,p=R?n(t(f.maxWait)||0,h):p,O="trailing"in f?!!f.trailing:O);function j(L){var y=g,A=C;return g=C=void 0,z=L,D=a.apply(A,y),D}function q(L){return z=L,E=setTimeout(ee,h),W?j(L):D}function F(L){var y=L-N,A=L-z,le=h-y;return R?o(le,p-A):le}function oe(L){var y=L-N,A=L-z;return N===void 0||y>=h||y<0||R&&A>=p}function ee(){var L=r();if(oe(L))return P(L);E=setTimeout(ee,F(L))}function P(L){return E=void 0,O&&g?j(L):(g=C=void 0,D)}function Z(){E!==void 0&&clearTimeout(E),z=0,g=N=C=E=void 0}function Ce(){return E===void 0?D:P(r())}function te(){var L=r(),y=oe(L);if(g=arguments,C=this,N=L,y){if(E===void 0)return q(N);if(R)return clearTimeout(E),E=setTimeout(ee,h),j(N)}return E===void 0&&(E=setTimeout(ee,h)),D}return te.cancel=Z,te.flush=Ce,te}return lt=i,lt}var Ln=en();const Wn=Le(Ln);var at,Ft;function qn(){if(Ft)return at;Ft=1;var e=en(),r=mt(),t="Expected a function";function s(n,o,i){var a=!0,h=!0;if(typeof n!="function")throw new TypeError(t);return r(i)&&(a="leading"in i?!!i.leading:a,h="trailing"in i?!!i.trailing:h),e(n,o,{leading:a,maxWait:o,trailing:h})}return at=s,at}var Bn=qn();const Kn=Le(Bn),Un=(e,r,t,s)=>{switch(r){case"debounce":return Wn(e,t,s);case"throttle":return Kn(e,t,s);default:return e}};function $n({skipOnMount:e=!1,refreshMode:r,refreshRate:t=1e3,refreshOptions:s,handleWidth:n=!0,handleHeight:o=!0,targetRef:i,observerOptions:a,onResize:h}={}){const f=d.useRef(e),[g,C]=d.useState({width:void 0,height:void 0}),[p,D]=d.useState(i?.current||null);i&&setTimeout(()=>{i.current!==p&&D(i.current)},0);const E=d.useMemo(()=>new Proxy(R=>{R!==p&&D(R)},{get(R,O){return O==="current"?p:R[O]},set(R,O,j){return O==="current"?D(j):R[O]=j,!0}}),[p]),N=d.useCallback((R,O)=>!(R.width===O.width&&R.height===O.height||R.width===O.width&&!o||R.height===O.height&&!n),[n,o]),z=d.useCallback(R=>{if(!(!n&&!o)){if(f.current){f.current=!1;return}R.forEach(O=>{const{width:j,height:q}=O?.contentRect||{};C(F=>N(F,{width:j,height:q})?{width:j,height:q}:F)})}},[n,o,f,N]),W=d.useCallback(Un(z,r,t,s),[z,r,t,s]);return d.useEffect(()=>{let R;return p?(R=new window.ResizeObserver(W),R.observe(p,a)):(g.width||g.height)&&C({width:void 0,height:void 0}),()=>{var O,j,q;(O=R?.disconnect)===null||O===void 0||O.call(R),(q=(j=W).cancel)===null||q===void 0||q.call(j)}},[W,p]),d.useEffect(()=>{h?.(g.width,g.height)},[g]),Object.assign({ref:E},g)}const Gn=()=>b.jsx(b.Fragment,{}),Xn=()=>!1,Vt=({rowData:e})=>e,Yn=()=>null,Zn=({rowIndex:e})=>b.jsx(b.Fragment,{children:e+1}),ct=()=>!0,Jn=e=>e,Qn=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}},Hn=(e,r,t)=>d.useMemo(()=>{const s=[r===!1?{basis:0,grow:0,shrink:0,minWidth:0,component:()=>b.jsx(b.Fragment,{}),headerClassName:"dsg-hidden-cell",cellClassName:"dsg-hidden-cell",isCellEmpty:ct}:{...r,basis:r?.basis??40,grow:r?.grow??0,shrink:r?.shrink??0,minWidth:r?.minWidth??0,title:r?.title??b.jsx("div",{className:"dsg-corner-indicator"}),component:r?.component??Zn,isCellEmpty:ct},...e];return t&&s.push({...t,basis:t?.basis??40,grow:t?.grow??0,shrink:t?.shrink??0,minWidth:t.minWidth??0,isCellEmpty:ct}),s.map(n=>{const o=n.width!==void 0?Qn(n.width):{basis:void 0,grow:void 0,shrink:void 0};return{...n,basis:n.basis??o.basis??0,grow:n.grow??o.grow??1,shrink:n.shrink??o.shrink??1,minWidth:n.minWidth??100,component:n.component??Gn,disableKeys:n.disableKeys??!1,disabled:n.disabled??!1,keepFocus:n.keepFocus??!1,deleteValue:n.deleteValue??Vt,copyValue:n.copyValue??Yn,pasteValue:n.pasteValue??Vt,prePasteValues:n.prePasteValues??Jn,isCellEmpty:n.isCellEmpty??Xn}})},[r,t,e]);function Pe(e,r,t,s){var n,o=!1,i=0;function a(){n&&clearTimeout(n)}function h(){a(),o=!0}typeof r!="boolean"&&(s=t,t=r,r=void 0);function f(){for(var g=arguments.length,C=new Array(g),p=0;p<g;p++)C[p]=arguments[p];var D=this,E=Date.now()-i;if(o)return;function N(){i=Date.now(),t.apply(D,C)}function z(){n=void 0}s&&!n&&N(),a(),s===void 0&&E>e?N():r!==!0&&(n=setTimeout(s?z:N,s===void 0?e-E:e))}return f.cancel=h,f}function er(e,r,t){return t===void 0?Pe(e,r,!1):Pe(e,t,r!==!1)}var ut,Pt;function tr(){return Pt||(Pt=1,ut=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}),ut}var nr=tr();const tn=Le(nr),Fe=e=>{const[r,t]=d.useState(e),s=d.useCallback(n=>{t(o=>{const i=typeof n=="function"?n(o):n;return tn(i,o)?o:i})},[t]);return[r,s]},rr=(e,r,t)=>{const[s,n]=Fe({top:!0,right:!0,bottom:!0,left:!0});return d.useEffect(()=>{const o=Pe(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},fe=(e,r)=>{d.useEffect(()=>(document.addEventListener(e,r),()=>{document.removeEventListener(e,r)}),[r,e])},Lt=(e,r=200)=>{const t=d.useRef(null),s=d.useMemo(()=>Pe(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])},nn=(e={})=>(({addRows:r})=>{const[t,s]=d.useState(1),[n,o]=d.useState(String(t));return b.jsxs("div",{className:"dsg-add-row",children:[b.jsx("button",{type:"button",className:"dsg-add-row-btn",onClick:()=>r(t),children:e.button??"Add"})," ",b.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"]})}),rn=nn();rn.displayName="AddRows";const sr=(e,r)=>{const[t,s]=d.useState(e),n=d.useRef();d.useEffect(()=>()=>n.current?.cancel(),[]);const o=d.useMemo(()=>n.current=er(r,i=>{s(i)}),[r]);return[t,o]},pt=e=>e.type==="CUT"?b.jsx(b.Fragment,{children:"Cut"}):e.type==="COPY"?b.jsx(b.Fragment,{children:"Copy"}):e.type==="PASTE"?b.jsx(b.Fragment,{children:"Paste"}):e.type==="DELETE_ROW"?b.jsx(b.Fragment,{children:"Delete row"}):e.type==="DELETE_ROWS"?b.jsxs(b.Fragment,{children:["Delete rows ",b.jsx("b",{children:e.fromRow})," to ",b.jsx("b",{children:e.toRow})]}):e.type==="INSERT_ROW_BELLOW"?b.jsx(b.Fragment,{children:"Insert row below"}):e.type==="DUPLICATE_ROW"?b.jsx(b.Fragment,{children:"Duplicate row"}):e.type==="DUPLICATE_ROWS"?b.jsxs(b.Fragment,{children:["Duplicate rows ",b.jsx("b",{children:e.fromRow})," to ",b.jsx("b",{children:e.toRow})]}):e.type,sn=(e=pt)=>(({clientX:r,clientY:t,items:s,close:n})=>{const o=d.useRef(null),i=d.useCallback(a=>{o.current?.contains(a.target)||n()},[n]);return fe("mousedown",i),b.jsx("div",{className:"dsg-context-menu",style:{left:r+"px",top:t+"px"},ref:o,children:s.map(a=>b.jsx("div",{onClick:a.action,className:"dsg-context-menu-item",children:e(a)},a.type))})}),on=sn(pt);on.displayName="ContextMenu";const or=typeof DOMParser<"u"?new DOMParser:{parseFromString:()=>null},ir=e=>or.parseFromString(e,"text/html"),ft=e=>{const r=ir(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 a=0;a<t.rows[o].cells.length;a++)i.push(t.rows[o].cells[a].textContent??"")}return n}const s=r.getElementsByTagName("span")[0];return s?[[s.textContent??""]]:[[""]]},ke=e=>{const r=e.replace(/\r|\n$/g,""),t=[[]];let s=0,n=0,o=!1,i=0;const a=()=>{let h=r.slice(n,s);h[0]==='"'&&h[h.length-1]==='"'&&(o=!0),o&&h[h.length-1]==='"'&&h.includes(`
3
- `)&&(h=h.slice(1,h.length-1).replace(/""/g,'"'),o=!1),o&&h[h.length-1]!=='"'?h.split(`
4
- `).forEach((f,g,{length:C})=>{t[i].push(f),g<C-1&&(t.push([]),i++)}):t[i].push(h)};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]===" "&&(a(),n=s+1,o=!1),r[s]===`
5
- `&&!o&&(a(),t.push([]),n=s+1,i++),s++;return a(),t},lr=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;"),ar=e=>e.match(/^[^\x00-\x20\x7F-\x9F]$/)!==null,ht=(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},Ie=(e,r)=>e?{col:e.col,row:e.row,colId:r[e.col+1]?.id}:null,cr=(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:ht(e.min,r,t,s),max:ht(e.max,r,t,s)};if(!n.min||!n.max)throw new Error("min and max must be defined");return n},Wt=(e,r)=>e?{min:Ie(e.min,r),max:Ie(e.max,r)}:null,qt=()=>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 Se(e,r,t){let s=t.initialDeps??[],n,o=!0;function i(){var a,h,f;let g;t.key&&((a=t.debug)!=null&&a.call(t))&&(g=Date.now());const C=e();if(!(C.length!==s.length||C.some((E,N)=>s[N]!==E)))return n;s=C;let D;if(t.key&&((h=t.debug)!=null&&h.call(t))&&(D=Date.now()),n=r(...C),t.key&&((f=t.debug)!=null&&f.call(t))){const E=Math.round((Date.now()-g)*100)/100,N=Math.round((Date.now()-D)*100)/100,z=N/16,W=(R,O)=>{for(R=String(R);R.length<O;)R=" "+R;return R};console.info(`%c⏱ ${W(N,5)} /${W(E,5)} ms`,`
6
- font-size: .6rem;
7
- font-weight: bold;
8
- color: hsl(${Math.max(0,Math.min(120-120*z,120))}deg 100% 31%);`,t?.key)}return t?.onChange&&!(o&&t.skipInitialOnChange)&&t.onChange(n),o=!1,n}return i.updateDeps=a=>{s=a},i}function Bt(e,r){if(e===void 0)throw new Error("Unexpected undefined");return e}const ur=(e,r)=>Math.abs(e-r)<1.01,fr=(e,r,t)=>{let s;return function(...n){e.clearTimeout(s),s=e.setTimeout(()=>r.apply(this,n),t)}},Kt=e=>{const{offsetWidth:r,offsetHeight:t}=e;return{width:r,height:t}},dr=e=>e,ln=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},hr=(e,r)=>{const t=e.scrollElement;if(!t)return;const s=e.targetWindow;if(!s)return;const n=i=>{const{width:a,height:h}=i;r({width:Math.round(a),height:Math.round(h)})};if(n(Kt(t)),!s.ResizeObserver)return()=>{};const o=new s.ResizeObserver(i=>{const a=()=>{const h=i[0];if(h?.borderBoxSize){const f=h.borderBoxSize[0];if(f){n({width:f.inlineSize,height:f.blockSize});return}}n(Kt(t))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return o.observe(t,{box:"border-box"}),()=>{o.unobserve(t)}},Ut={passive:!0},$t=typeof window>"u"?!0:"onscrollend"in window,mr=(e,r)=>{const t=e.scrollElement;if(!t)return;const s=e.targetWindow;if(!s)return;let n=0;const o=e.options.useScrollendEvent&&$t?()=>{}:fr(s,()=>{r(n,!1)},e.options.isScrollingResetDelay),i=g=>()=>{const{horizontal:C,isRtl:p}=e.options;n=C?t.scrollLeft*(p&&-1||1):t.scrollTop,o(),r(n,g)},a=i(!0),h=i(!1);t.addEventListener("scroll",a,Ut);const f=e.options.useScrollendEvent&&$t;return f&&t.addEventListener("scrollend",h,Ut),()=>{t.removeEventListener("scroll",a),f&&t.removeEventListener("scrollend",h)}},pr=(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"]},gr=(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 wr{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:dr,rangeExtractor:ln,onChange:()=>{},measureElement:pr,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=Se(()=>(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 a=t[i];if(n.has(a.lane))continue;const h=o.get(a.lane);if(h==null||a.end>h.end?o.set(a.lane,a):a.end<h.end&&n.set(a.lane,!0),n.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((i,a)=>i.end===a.end?i.index-a.index:i.end-a.end)[0]:void 0},this.getMeasurementOptions=Se(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(t,s,n,o,i,a)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMeasuredCacheIndexes=[],{count:t,paddingStart:s,scrollMargin:n,getItemKey:o,enabled:i,lanes:a}),{key:!1}),this.getMeasurements=Se(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:t,paddingStart:s,scrollMargin:n,getItemKey:o,enabled:i,lanes:a},h)=>{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 f=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,f),C=new Array(a).fill(void 0);for(let p=0;p<f;p++){const D=g[p];D&&(C[D.lane]=p)}for(let p=f;p<t;p++){const D=o(p),E=this.laneAssignments.get(p);let N,z;if(E!==void 0&&this.options.lanes>1){N=E;const j=C[N],q=j!==void 0?g[j]:void 0;z=q?q.end+this.options.gap:s+n}else{const j=this.options.lanes===1?g[p-1]:this.getFurthestMeasurement(g,p);z=j?j.end+this.options.gap:s+n,N=j?j.lane:p%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(p,N)}const W=h.get(D),R=typeof W=="number"?W:this.options.estimateSize(p),O=z+R;g[p]={index:p,start:z,size:R,end:O,key:D,lane:N},C[N]=p}return this.measurementsCache=g,g},{key:process.env.NODE_ENV!=="production"&&"getMeasurements",debug:()=>this.options.debug}),this.calculateRange=Se(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,s,n,o)=>this.range=t.length>0&&s>0?xr({measurements:t,outerSize:s,scrollOffset:n,lanes:o}):null,{key:process.env.NODE_ENV!=="production"&&"calculateRange",debug:()=>this.options.debug}),this.getVirtualIndexes=Se(()=>{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,a=this.elementsCache.get(i);a!==t&&(a&&this.observer.unobserve(a),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=Se(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,s)=>{const n=[];for(let o=0,i=t.length;o<i;o++){const a=t[o],h=s[a];n.push(h)}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 Bt(s[an(0,s.length-1,n=>Bt(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 a=this.getMaxScrollOffset();return Math.max(Math.min(a,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 a=s==="end"?n.end+this.options.scrollPaddingEnd:n.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,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,a=f=>{if(!this.targetWindow)return;const g=this.getOffsetForIndex(t,f);if(!g){console.warn("Failed to get offset for index:",t);return}const[C,p]=g;this._scrollToOffset(C,{adjustments:void 0,behavior:n}),this.targetWindow.requestAnimationFrame(()=>{const D=()=>{if(this.currentScrollToIndex!==t)return;const E=this.getScrollOffset(),N=this.getOffsetForIndex(t,p);if(!N){console.warn("Failed to get offset for index:",t);return}ur(N[0],E)||h(p)};this.isDynamicMode()?this.targetWindow.requestAnimationFrame(D):D()})},h=f=>{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(()=>a(f))):console.warn(`Failed to scroll to index ${t} after ${i} attempts.`))};a(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(a=>a===null);){const a=s[i];o[a.lane]===null&&(o[a.lane]=a.end),i--}n=Math.max(...o.filter(a=>a!==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 an=(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 xr({measurements:e,outerSize:r,scrollOffset:t,lanes:s}){const n=e.length-1,o=h=>e[h].start;if(e.length<=s)return{startIndex:0,endIndex:n};let i=an(0,n,o,t),a=i;if(s===1)for(;a<n&&e[a].end<t+r;)a++;else if(s>1){const h=Array(s).fill(0);for(;a<n&&h.some(g=>g<t+r);){const g=e[a];h[g.lane]=g.end,a++}const f=Array(s).fill(t+r);for(;i>=0&&f.some(g=>g>=t);){const g=e[i];f[g.lane]=g.start,i--}i=Math.max(0,i-i%s),a=Math.min(n,a+(s-1-a%s))}return{startIndex:i,endIndex:a}}const Gt=typeof document<"u"?Ve.useLayoutEffect:Ve.useEffect;function br({useFlushSync:e=!0,...r}){const t=Ve.useReducer(()=>({}),{})[1],s={...r,onChange:(o,i)=>{var a;e&&i?Tn.flushSync(t):t(),(a=r.onChange)==null||a.call(r,o,i)}},[n]=Ve.useState(()=>new wr(s));return n.setOptions(s),Gt(()=>n._didMount(),[]),Gt(()=>n._willUpdate()),n}function Xt(e){return br({observeElementRect:hr,observeElementOffset:mr,scrollToFn:gr,...e})}var dt={exports:{}};var Yt;function yr(){return Yt||(Yt=1,(function(e){(function(){var r={}.hasOwnProperty;function t(){for(var o="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(o=n(o,s(a)))}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 a in o)r.call(o,a)&&o[a]&&(i=n(i,a));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})()})(dt)),dt.exports}var vr=yr();const X=Le(vr),Zt=({children:e,gutter:r,stickyRight:t,active:s,disabled:n,className:o,width:i,left:a})=>b.jsx("div",{className:X("dsg-cell",r&&"dsg-cell-gutter",n&&"dsg-cell-disabled",r&&s&&"dsg-cell-gutter-active",t&&"dsg-cell-sticky-right",o),style:{width:i,left:t?void 0:a},children:e}),ze=(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]),Er=({data:e,columns:r,outerRef:t,innerRef:s,columnWidths:n,hasStickyRightColumn:o,displayHeight:i,headerRowHeight:a,rowHeight:h,rowKey:f,fullWidth:g,selection:C,activeCell:p,rowClassName:D,cellClassName:E,children:N,editing:z,getContextMenuItems:W,setRowData:R,deleteRows:O,duplicateRows:j,insertRowAfter:q,stopEditing:F,onScroll:oe})=>{const ee=Xt({count:e.length,getScrollElement:()=>t.current,paddingStart:a,estimateSize:T=>h(T).height,getItemKey:T=>{if(f&&T>0){const K=e[T-1];if(typeof f=="function")return f({rowData:K,rowIndex:T});if(typeof f=="string"&&K instanceof Object&&f in K){const B=K[f];if(typeof B=="string"||typeof B=="number")return B}}return T},overscan:5}),P=Xt({count:r.length,getScrollElement:()=>t.current,estimateSize:T=>n?.[T]??100,horizontal:!0,getItemKey:T=>r[T].id??T,overscan:1,rangeExtractor:T=>{const K=ln(T);return K[0]!==0&&K.unshift(0),o&&K[K.length-1]!==r.length-1&&K.push(r.length-1),K}});d.useEffect(()=>{P.measure()},[P,n]);const Z=ze(R,1),Ce=ze(O,0),te=ze(j,0),L=ze(q,0),y=C?.min.col??p?.col,A=C?.max.col??p?.col,le=C?.min.row??p?.row,J=C?.max.row??p?.row;return b.jsx("div",{ref:t,className:"dsg-container",onScroll:oe,style:{height:i},children:b.jsxs("div",{ref:s,style:{width:g?"100%":P.getTotalSize(),height:ee.getTotalSize()},children:[a>0&&b.jsx("div",{className:X("dsg-row","dsg-row-header"),style:{width:g?"100%":P.getTotalSize(),height:a},children:P.getVirtualItems().map(T=>b.jsx(Zt,{gutter:T.index===0,stickyRight:o&&T.index===r.length-1,width:T.size,left:T.start,className:X("dsg-cell-header",y!==void 0&&A!==void 0&&y<=T.index-1&&A>=T.index-1&&"dsg-cell-header-active",r[T.index].headerClassName),children:b.jsx("div",{className:"dsg-cell-header-container",children:r[T.index].title})},T.key))}),ee.getVirtualItems().map(T=>{const K=T.index>=(le??1/0)&&T.index<=(J??-1/0);return b.jsx("div",{className:X("dsg-row",typeof D=="string"?D:null,typeof D=="function"?D({rowData:e[T.index],rowIndex:T.index}):null),style:{height:T.size,top:T.start,width:g?"100%":P.getTotalSize()},children:P.getVirtualItems().map(B=>{const Te=r[B.index].cellClassName,ie=r[B.index].disabled,We=r[B.index].component,Oe=ie===!0||typeof ie=="function"&&ie({rowData:e[T.index],rowIndex:T.index}),Re=p?.row===T.index&&p.col===B.index-1;return b.jsx(Zt,{gutter:B.index===0,stickyRight:o&&B.index===r.length-1,active:B.index===0&&K,disabled:Oe,className:X(typeof Te=="function"?Te({rowData:e[T.index],rowIndex:T.index,columnId:r[B.index].id}):Te,typeof E=="function"?E({rowData:e[T.index],rowIndex:T.index,columnId:r[B.index].id}):E),width:B.size,left:B.start,children:b.jsx(We,{rowData:e[T.index],getContextMenuItems:W,disabled:Oe,active:Re,columnIndex:B.index-1,rowIndex:T.index,focus:Re&&z,deleteRow:Ce(T.index),duplicateRow:te(T.index),stopEditing:F,insertRowBelow:L(T.index),setRowData:Z(T.index),columnData:r[B.index].columnData})},B.key)})},T.key)}),N]})})},Jt=(e,r,t,s)=>[[s,e],[r,e],[r,t],[s,t],[s,e]],Sr=(e,r,t,s)=>`polygon(evenodd, ${[...Jt(0,"100%","100%",0),...Jt(e,r,t,s)].map(o=>o.map(i=>typeof i=="number"&&i!==0?i+"px":i).join(" ")).join(",")})`,cn=d.memo(({columnWidths:e,columnRights:r,headerRowHeight:t,selection:s,rowHeight:n,activeCell:o,hasStickyRightColumn:i,dataLength:a,viewWidth:h,viewHeight:f,contentWidth:g,edges:C,isCellDisabled:p,editing:D,expandSelection:E})=>{const N=o?p(o):!1,z=d.useMemo(()=>{if(!s)return N;for(let P=s.min.col;P<=s.max.col;++P)for(let Z=s.min.row;Z<=s.max.row;++Z)if(!p({col:P,row:Z}))return!1;return!0},[N,p,s]);if(!e||!r)return null;const W=P=>P<a-1?1:0,R=P=>P<e.length-(i?3:2)?1:0,O=o&&{width:e[o.col+1]+R(o.col),height:n(o.row).height+W(o.row),left:r[o.col],top:n(o.row).top+t},j=s&&{width:e.slice(s.min.col+1,s.max.col+2).reduce((P,Z)=>P+Z)+R(s.max.col),height:n(s.max.row).top+n(s.max.row).height-n(s.min.row).top+W(s.max.row),left:r[s.min.col],top:n(s.min.row).top+t},q=s?.min||o,F=s?.max||o,oe=F&&E!==null&&{left:r[F.col]+e[F.col+1],top:n(F.row).top+n(F.row).height+t,transform:`translate(-${F.col<e.length-(i?3:2)?50:100}%, -${F.row<a-1?50:100}%)`},ee=q&&F&&E!==null&&{width:e.slice(q.col+1,F.col+2).reduce((P,Z)=>P+Z)+R(F.col),height:n(F.row+E).top+n(F.row+E).height-n(F.row+1).top+W(F.row+E)-1,left:r[q.col],top:n(F.row).top+n(F.row).height+t+1};return b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"dsg-scrollable-view-container",style:{height:n(a-1).top+n(a-1).height+t,width:g||"100%"},children:b.jsx("div",{className:X({"dsg-scrollable-view":!0,"dsg-scrollable-view-t":!C.top,"dsg-scrollable-view-r":!C.right,"dsg-scrollable-view-b":!C.bottom,"dsg-scrollable-view-l":!C.left}),style:{top:t,left:e[0],height:f?f-t:0,width:g&&h?h-e[0]-(i?e[e.length-1]:0):`calc(100% - ${e[0]+(i?e[e.length-1]:0)}px)`}})}),(j||O)&&b.jsx("div",{className:"dsg-selection-col-marker-container",style:{left:j?.left??O?.left,width:j?.width??O?.width,height:n(a-1).top+n(a-1).height+t},children:b.jsx("div",{className:X("dsg-selection-col-marker",z&&"dsg-selection-col-marker-disabled"),style:{top:t}})}),(j||O)&&b.jsx("div",{className:"dsg-selection-row-marker-container",style:{top:j?.top??O?.top,height:j?.height??O?.height,width:g||"100%"},children:b.jsx("div",{className:X("dsg-selection-row-marker",z&&"dsg-selection-row-marker-disabled"),style:{left:e[0]}})}),O&&o&&b.jsx("div",{className:X("dsg-active-cell",{"dsg-active-cell-focus":D,"dsg-active-cell-disabled":N}),style:O}),j&&O&&b.jsx("div",{className:X("dsg-selection-rect",z&&"dsg-selection-rect-disabled"),style:{...j,clipPath:Sr(O.top-j.top,O.left-j.left,O.top+O.height-j.top,O.left+O.width-j.left)}}),ee&&b.jsx("div",{className:X("dsg-expand-rows-rect"),style:ee}),oe&&b.jsx("div",{className:X("dsg-expand-rows-indicator",z&&"dsg-expand-rows-indicator-disabled"),style:oe})]})});cn.displayName="SelectionRect";const Ir=({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,a=t.current.length-1;for(;i<=a;){const h=Math.floor((i+a)/2);if(t.current[h].top<o)i=h+1;else if(t.current[h].top>o)a=h-1;else return h}if(a===t.current.length-1&&e.length>t.current.length&&(!t.current.length||o>=t.current[a].top+t.current[a].height)){let h=a===-1?0:t.current[a].top+t.current[a].height;do{a++;const f=r({rowIndex:a,rowData:e[a]});t.current.push({height:f,top:h}),h+=f}while(h<=o&&a<t.current.length-1)}return a};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 a=t.current.length;a<=o;a++){const h=r({rowIndex:a,rowData:e[a]});t.current.push({height:h,top:i}),i+=h}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])},Cr=[],Tr=[],Or=()=>({}),je=()=>null,Rr=({rowData:e})=>({...e}),gt=d.memo(d.forwardRef(({value:e=Cr,className:r,style:t,height:s=400,onChange:n=je,columns:o=Tr,rowHeight:i=40,headerRowHeight:a=typeof i=="number"?i:40,gutterColumn:h,stickyRightColumn:f,rowKey:g,addRowsComponent:C=rn,createRow:p=Or,autoAddRow:D=!1,lockRows:E=!1,disableExpandSelection:N=!1,disableSmartDelete:z=!1,duplicateRow:W=Rr,contextMenuComponent:R=on,disableContextMenu:O=!1,onFocus:j=je,onBlur:q=je,onActiveCellChange:F=je,onSelectionChange:oe=je,rowClassName:ee,cellClassName:P,onScroll:Z},Ce)=>{const te=d.useRef(null),L=O||E,y=Hn(o,h,f),A=!!f,le=d.useRef(null),J=d.useRef(null),T=d.useRef(null),K=d.useRef(null),[B,Te]=sr(1,100),{getRowSize:ie,totalSize:We,getRowIndex:Oe}=Ir({value:e,rowHeight:i}),Re=Math.min(s,a+We(s)+B),{width:pe,height:he}=$n({targetRef:J,refreshMode:"throttle",refreshRate:100});Te(he?Re-he:0);const mn=rr(J,pe,he),{fullWidth:wt,totalWidth:pn,columnWidths:ne,columnRights:se}=Dn(y,pe),[ge,re]=d.useState(null),[we,gn]=d.useState([]),[V,U]=d.useState(!1),[xe,xt]=d.useState(0),[be,bt]=d.useState(null),[u,k]=Fe(null),[G,_]=Fe(null),x=d.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]),[ae,ye]=Fe({columns:!1,rows:!1,active:!1}),wn=N||V||ae.active||u?.row===e?.length-1||x?.max.row===e?.length-1||u&&y.slice((x?.min.col??u.col)+1,(x?.max.col??u.col)+2).every(l=>l.disabled===!0)?null:xe,yt=Lt(le),vt=Lt(J);d.useEffect(()=>{u!==null&&(document.activeElement.blur(),window.getSelection()?.removeAllRanges())},[u!==null]);const me=d.useCallback((l,c=!1,w=!1)=>{const m=yt(c),S=w&&vt(c);if(m&&se&&ne){let v=l.clientX-m.left,M=l.clientY-m.top;return S&&(l.clientY-S.top<=a&&(M=0),l.clientX-S.left<=ne[0]&&(v=0),A&&S.right-l.clientX<=ne[ne.length-1]&&(v=se[se.length-2]+1)),{col:se.findIndex(I=>v<I)-1,row:Oe(M-a)}}return null},[se,ne,e.length,yt,vt,a,A,Oe]),Q=d.useRef(e);Q.current=e;const H=d.useCallback(l=>{const c=y[l.col+1].disabled;return!!(typeof c=="function"?c({rowData:Q.current[l.row],rowIndex:l.row}):c)},[y]),ce=d.useCallback((l,c=1)=>{E||(_(null),U(!1),n([...Q.current.slice(0,l+1),...new Array(c).fill(0).map(p),...Q.current.slice(l+1)],[{type:"CREATE",fromRowIndex:l+1,toRowIndex:l+1+c}]),k(w=>({col:w?.col||0,row:l+c,doNotScrollX:!0})))},[p,E,n,k,_]),ve=d.useCallback((l,c=l)=>{E||(n([...Q.current.slice(0,c+1),...Q.current.slice(l,c+1).map((w,m)=>W({rowData:w,rowIndex:m+l})),...Q.current.slice(c+1)],[{type:"CREATE",fromRowIndex:c+1,toRowIndex:c+2+c-l}]),k({col:0,row:c+1,doNotScrollX:!0}),_({col:y.length-(A?3:2),row:2*c-l+1,doNotScrollX:!0}),U(!1))},[y.length,W,E,n,k,_,A]),ue=d.useCallback(l=>{if(!(!he||!pe)){if(!l.doNotScrollY){const c=ie(l.row).top,w=ie(l.row).top+ie(l.row).height+a-he+1,m=J.current.scrollTop;m>c?J.current.scrollTop=c:m<w&&(J.current.scrollTop=w)}if(se&&ne&&J.current&&!l.doNotScrollX){const c=se[l.col]-se[0],w=se[l.col]+ne[l.col+1]+(A?ne[ne.length-1]:0)-pe+1,m=J.current.scrollLeft;m>c?J.current.scrollLeft=c:m<w&&(J.current.scrollLeft=w)}}},[he,pe,a,se,ne,ie,A]);d.useEffect(()=>{G&&ue(G)},[G,ue]),d.useEffect(()=>{u&&ue(u)},[u,ue]);const xn=d.useCallback((l,c)=>{n([...Q.current?.slice(0,l),c,...Q.current?.slice(l+1)],[{type:"UPDATE",fromRowIndex:l,toRowIndex:l+1}])},[n]),Ee=d.useCallback((l,c=l)=>{E||(U(!1),k(w=>{const m=Math.min(Q.current.length-2-c+l,l);return m<0?null:w&&{col:w.col,row:m}}),_(null),n([...Q.current.slice(0,l),...Q.current.slice(c+1)],[{type:"DELETE",fromRowIndex:l,toRowIndex:c+1}]))},[E,n,k,_]),Ae=d.useCallback((l=!0)=>{const c=l&&!z;if(!u)return;const w=x?.min||u,m=x?.max||u;if(e.slice(w.row,m.row+1).every((v,M)=>y.every(I=>I.isCellEmpty({rowData:v,rowIndex:M+w.row})))){c&&Ee(w.row,m.row);return}const S=[...e];for(let v=w.row;v<=m.row;++v)for(let M=w.col;M<=m.col;++M)if(!H({col:M,row:v})){const{deleteValue:I=({rowData:$})=>$}=y[M+1];S[v]=I({rowData:S[v],rowIndex:v})}if(c&&tn(S,e)){k({col:0,row:w.row,doNotScrollX:!0}),_({col:y.length-(A?3:2),row:m.row,doNotScrollX:!0});return}n(S,[{type:"UPDATE",fromRowIndex:w.row,toRowIndex:m.row+1}])},[u,y,e,Ee,H,n,x?.max,x?.min,k,_,A]),qe=d.useCallback(({nextRow:l=!0}={})=>{u?.row===Q.current.length-1?l&&D?ce(u.row):U(!1):(U(!1),l&&k(c=>c&&{col:c.col,row:c.row+1}))},[u?.row,D,ce,k]),De=d.useCallback(async l=>{if(!V&&u){const c=[],w=x?.min||u,m=x?.max||u;for(let I=w.row;I<=m.row;++I){c.push([]);for(let $=w.col;$<=m.col;++$){const{copyValue:Y=()=>null}=y[$+1];c[I-w.row].push(Y({rowData:e[I],rowIndex:I}))}}const S=c.map(I=>I.join(" ")).join(`
9
- `),v=`<table>${c.map(I=>`<tr>${I.map($=>`<td>${lr(String($??"")).replace(/\n/g,"<br/>")}</td>`).join("")}</tr>`).join("")}</table>`;if(l!==void 0){l.clipboardData?.setData("text/plain",S),l.clipboardData?.setData("text/html",v),l.preventDefault();return}let M=!1;if(navigator.clipboard.write!==void 0){const I=new Blob([S],{type:"text/plain"}),$=new Blob([v],{type:"text/html"}),Y=[new ClipboardItem({"text/plain":I,"text/html":$})];await navigator.clipboard.write(Y).then(()=>{M=!0})}else navigator.clipboard.writeText!==void 0?await navigator.clipboard.writeText(S).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,y,e,V,x]);fe("copy",De);const Be=d.useCallback(l=>{!V&&u&&(De(l),Ae(!1))},[u,Ae,V,De]);fe("cut",Be);const Ne=d.useCallback(async l=>{if(!V&&u){const c=x?.min||u,w=x?.max||u,m=await Promise.all(l[0].map((S,v)=>{const M=y[c.col+v+1]?.prePasteValues,I=l.map($=>$[v]);return M?.(I)??I}));if(l=l.map((S,v)=>m.map(M=>M[v])),l.length===1){const S=[...e];for(let v=0;v<l[0].length;v++){const M=y[c.col+v+1]?.pasteValue;if(M)for(let I=c.row;I<=w.row;I++)H({col:v+c.col,row:I})||(S[I]=await M({rowData:S[I],value:l[0][v],rowIndex:I}))}n(S,[{type:"UPDATE",fromRowIndex:c.row,toRowIndex:w.row+1}]),k({col:c.col,row:c.row}),_({col:Math.min(c.col+l[0].length-1,y.length-(A?3:2)),row:w.row})}else{let S=[...e];const v=c.row+l.length-e.length;v>0&&(E?l.splice(l.length-v,v):S=[...S,...new Array(v).fill(0).map(()=>p())]);for(let I=0;I<l[0].length&&c.col+I<y.length-(A?2:1);I++){const $=y[c.col+I+1]?.pasteValue;if($)for(let Y=0;Y<l.length;Y++)H({col:c.col+I,row:c.row+Y})||(S[c.row+Y]=await $({rowData:S[c.row+Y],value:l[Y][I],rowIndex:c.row+Y}))}const M=[{type:"UPDATE",fromRowIndex:c.row,toRowIndex:c.row+l.length-(!E&&v>0?v:0)}];v>0&&!E&&M.push({type:"CREATE",fromRowIndex:c.row+l.length-v,toRowIndex:c.row+l.length}),n(S,M),k({col:c.col,row:c.row}),_({col:Math.min(c.col+l[0].length-1,y.length-(A?3:2)),row:c.row+l.length-1})}}},[u,y,p,e,V,A,H,E,n,x?.max,x?.min,k,_]),bn=d.useCallback(l=>{if(u&&!V){let c=[[""]];l.clipboardData?.types.includes("text/html")?c=ft(l.clipboardData?.getData("text/html")):l.clipboardData?.types.includes("text/plain")?c=ke(l.clipboardData?.getData("text/plain")):l.clipboardData?.types.includes("text")&&(c=ke(l.clipboardData?.getData("text"))),Ne(c),l.preventDefault()}},[u,Ne,V]);fe("paste",bn);const yn=d.useCallback(l=>{if(ge&&we.length)return;const c=l.button===2||l.button===0&&l.ctrlKey,w=le.current?.contains(l.target)||!1,m=w?me(l,!0,!0):null;if(!w&&V&&u&&y[u.col+1].keepFocus)return;if(l.target instanceof HTMLElement&&l.target.className.includes("dsg-expand-rows-indicator")){bt(Math.max(u?.row??0,x?.max.row??0));return}const S=m&&u&&u.col===m.col&&u.row===m.row&&!H(u);if(S&&V)return;const v=m?.col===y.length-2&&A,M=c&&x&&m&&m.row>=x.min.row&&m.row<=x.max.row&&m.col>=x.min.col&&m.col<=x.max.col,I=c&&x&&m&&m.row===-1&&m.col>=x.min.col&&m.col<=x.max.col,$=c&&x&&m&&m.row>=x.min.row&&m.row<=x.max.row&&m.col===-1,Y=v&&x&&m&&m.row>=x.min.row&&m.row<=x.max.row;if(c&&!L&&re({x:l.clientX,y:l.clientY,cursorIndex:m}),(!(l.shiftKey&&u)||c)&&e.length>0&&k(m&&{col:(M||I)&&u?u.col:Math.max(0,v?0:m.col),row:(M||$||Y)&&u?u.row:Math.max(0,m.row),doNotScrollX:!!(M&&u||v||m.col===-1),doNotScrollY:!!(M&&u||m.row===-1)}),S&&!c&&(te.current=u),U(!!(S&&!c)),ye(m&&!c?{columns:m.col!==-1&&!v||!!(l.shiftKey&&u),rows:m.row!==-1||!!(l.shiftKey&&u),active:!0}:{columns:!1,rows:!1,active:!1}),l.shiftKey&&u&&!c)_(m&&{col:Math.max(0,m.col-(v?1:0)),row:Math.max(0,m.row)});else if(!M){if(m&&(m?.col===-1||m?.row===-1||v)){let Ke=m.col,Ue=m.row,$e=!1,Ge=!1;(m.col===-1||v)&&(Ke=y.length-(A?3:2),$e=!0),m.row===-1&&(Ue=e.length-1,Ge=!0),I&&G&&(Ke=G.col,Ge=!0),($||Y)&&G&&(Ue=G.row,$e=!0),_({col:Ke,row:Ue,doNotScrollX:$e,doNotScrollY:Ge})}else _(null);w&&l.preventDefault()}},[ge,we.length,me,V,u,y,H,x,A,L,ye,k,_,G,e.length]);fe("mousedown",yn);const vn=d.useCallback(()=>{if(be!==null){if(xe>0&&u){let l=[];const c=x?.min||u,w=x?.max||u;for(let m=c.row;m<=w.row;++m){l.push([]);for(let S=c.col;S<=w.col;++S){const{copyValue:v=()=>null}=y[S+1];l[m-c.row].push(String(v({rowData:e[m],rowIndex:m})??""))}}Promise.all(l[0].map((m,S)=>{const v=y[c.col+S+1]?.prePasteValues,M=l.map(I=>I[S]);return v?.(M)??M})).then(m=>{l=l.map((v,M)=>m.map(I=>I[M]));const S=[...e];for(let v=0;v<l[0].length;v++){const M=y[c.col+v+1]?.pasteValue;if(M)for(let I=w.row+1;I<=w.row+xe;I++)H({col:v+c.col,row:I})||(S[I]=M({rowData:S[I],value:l[(I-w.row-1)%l.length][v],rowIndex:I}))}n(S,[{type:"UPDATE",fromRowIndex:w.row+1,toRowIndex:w.row+1+xe}])}),xt(0),k({col:Math.min(u?.col??1/0,x?.min.col??1/0),row:Math.min(u?.row??1/0,x?.min.row??1/0),doNotScrollX:!0,doNotScrollY:!0}),_({col:Math.max(u?.col??0,x?.max.col??0),row:Math.max(u?.row??0,x?.max.row??0)+xe})}bt(null)}ye({columns:!1,rows:!1,active:!1})},[be,ye,xe,u,x?.min,x?.max,e,n,k,_,y,H]);fe("mouseup",vn);const En=d.useCallback(l=>{if(be!==null){const c=me(l);c&&(xt(Math.max(0,c.row-be)),ue({col:c.col,row:Math.max(c.row,be)}))}if(ae.active){const c=me(l),w=y.length-(A?3:2);_(c&&{col:ae.columns?Math.max(0,Math.min(w,c.col)):w,row:ae.rows?Math.max(0,c.row):e.length-1,doNotScrollX:!ae.columns,doNotScrollY:!ae.rows}),U(!1)}},[ue,ae.active,ae.columns,ae.rows,me,y.length,A,_,e.length,be]);fe("mousemove",En);const Sn=d.useCallback(l=>{if(u&&!l.isComposing){if(l.key==="Tab"&&!l.shiftKey&&u.col===y.length-(A?3:2)&&!y[u.col+1].disableKeys)if(u.row===e.length-1){if(K.current){l.preventDefault(),k(null),_(null),U(!1);const c=qt(),w=c.indexOf(K.current);c[(w+1)%c.length].focus();return}}else{k(c=>({col:0,row:(c?.row??0)+1})),_(null),U(!1),l.preventDefault();return}if(l.key==="Tab"&&l.shiftKey&&u.col===0&&!y[u.col+1].disableKeys)if(u.row===0){if(T.current){l.preventDefault(),k(null),_(null),U(!1);const c=qt(),w=c.indexOf(T.current);c[(w-1+c.length)%c.length].focus();return}}else{k(c=>({col:y.length-(A?3:2),row:(c?.row??1)-1})),_(null),U(!1),l.preventDefault();return}if(l.key?.startsWith("Arrow")||l.key==="Tab"){if(V&&y[u.col+1].disableKeys||V&&["ArrowLeft","ArrowRight"].includes(l.key))return;const c=([w,m],S)=>S&&{col:Math.max(0,Math.min(y.length-(A?3:2),S.col+w)),row:Math.max(0,Math.min(e.length-1,S.row+m))};if(l.key==="Tab"&&l.shiftKey)k(w=>c([-1,0],w)),_(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]*=y.length,w[1]*=e.length),l.shiftKey?_(m=>c(w,m||u)):(k(m=>c(w,m)),_(null))}U(!1),l.preventDefault()}else l.key==="Escape"?(!V&&!G&&k(null),_(null),U(!1)):(l.key==="Enter"||l.key==="F2")&&!l.ctrlKey&&!l.metaKey&&!l.altKey&&!l.shiftKey?(_(null),V?y[u.col+1].disableKeys||(qe(),l.preventDefault()):H(u)||(te.current=u,U(!0),ue(u),l.preventDefault())):l.key==="Enter"&&!l.ctrlKey&&!l.metaKey&&!l.altKey&&l.shiftKey?ce(x?.max.row||u.row):l.key==="d"&&(l.ctrlKey||l.metaKey)&&!l.altKey&&!l.shiftKey?(ve(x?.min.row||u.row,x?.max.row),l.preventDefault()):(ar(l.key)||l.code.match(/Key[A-Z]$/))&&!l.ctrlKey&&!l.metaKey&&!l.altKey?!V&&!H(u)&&(te.current=u,_(null),U(!0),ue(u)):["Backspace","Delete"].includes(l.key)?V||(Ae(),l.preventDefault()):l.key==="a"&&(l.ctrlKey||l.metaKey)&&(V||(k({col:0,row:0,doNotScrollY:!0,doNotScrollX:!0}),_({col:y.length-(A?3:2),row:e.length-1,doNotScrollY:!0,doNotScrollX:!0}),l.preventDefault()))}},[u,y,e.length,Ae,ve,V,ce,H,ue,x?.max.row,x?.min.row,G,k,_,qe,A]);fe("keydown",Sn);const In=d.useCallback(l=>{const c=le.current?.contains(l.target)||!1,w=c?me(l,!0,!0):null,m=w&&u&&u.col===w.col&&u.row===w.row&&V;c&&!m&&l.preventDefault()},[me,u,V]);fe("contextmenu",In),d.useEffect(()=>{const l=[];u?.row!==void 0&&l.push({type:"COPY",action:()=>{De(),re(null)}},{type:"CUT",action:()=>{Be(),re(null)}},{type:"PASTE",action:async()=>{if(navigator.clipboard.read!==void 0)(await navigator.clipboard.read()).forEach(async w=>{let m=[[""]];if(w.types.includes("text/html")){const S=await w.getType("text/html");m=ft(await S.text())}else if(w.types.includes("text/plain")){const S=await w.getType("text/plain");m=ke(await S.text())}else if(w.types.includes("text")){const S=await w.getType("text");m=ft(await S.text())}Ne(m)});else if(navigator.clipboard.readText!==void 0){const c=await navigator.clipboard.readText();Ne(ke(c))}else alert("This action is unavailable in your browser, but you can still use Ctrl+V for paste");re(null)}}),x?.max.row!==void 0?l.push({type:"INSERT_ROW_BELLOW",action:()=>{re(null),ce(x.max.row)}}):u?.row!==void 0&&l.push({type:"INSERT_ROW_BELLOW",action:()=>{re(null),ce(u.row)}}),x?.min.row!==void 0&&x.min.row!==x.max.row?l.push({type:"DUPLICATE_ROWS",fromRow:x.min.row+1,toRow:x.max.row+1,action:()=>{re(null),ve(x.min.row,x.max.row)}}):u?.row!==void 0&&l.push({type:"DUPLICATE_ROW",action:()=>{re(null),ve(u.row)}}),x?.min.row!==void 0&&x.min.row!==x.max.row?l.push({type:"DELETE_ROWS",fromRow:x.min.row+1,toRow:x.max.row+1,action:()=>{re(null),Ee(x.min.row,x.max.row)}}):u?.row!==void 0&&l.push({type:"DELETE_ROW",action:()=>{re(null),Ee(u.row)}}),gn(l),l.length||re(null)},[x,u,Ee,ve,ce,Be,De,Ne]);const Et=d.useRef(we);Et.current=we;const Cn=d.useCallback(()=>Et.current,[]);d.useImperativeHandle(Ce,()=>({activeCell:Ie(u,y),selection:Wt(x??(u?{min:u,max:u}:null),y),setSelection:l=>{const c=cr(l,y.length-(A?2:1),e.length,y);k(c?.min||null),U(!1),ye({columns:!1,active:!1,rows:!1}),_(c?.max||null)},setActiveCell:l=>{const c=ht(l,y.length-(A?2:1),e.length,y);k(c),U(!1),ye({columns:!1,active:!1,rows:!1}),_(null)}}));const de=d.useRef({onFocus:j,onBlur:q,onActiveCellChange:F,onSelectionChange:oe});return de.current.onFocus=j,de.current.onBlur=q,de.current.onActiveCellChange=F,de.current.onSelectionChange=oe,d.useEffect(()=>{te.current&&(V?de.current.onFocus({cell:Ie(te.current,y)}):de.current.onBlur({cell:Ie(te.current,y)}))},[V,y]),d.useEffect(()=>{de.current.onActiveCellChange({cell:Ie(u,y)})},[u?.col,u?.row,y]),d.useEffect(()=>{de.current.onSelectionChange({selection:Wt(x??(u?{min:u,max:u}:null),y)})},[x?.min.col??u?.col,x?.min.row??u?.row,x?.max.col??u?.col,x?.max.row??u?.row,u?.col,u?.row,y]),b.jsxs("div",{className:r,style:t,children:[b.jsx("div",{ref:T,tabIndex:o.length&&e.length?0:void 0,onFocus:l=>{l.target.blur(),k({col:0,row:0})}}),b.jsx(Er,{columns:y,outerRef:J,columnWidths:ne,hasStickyRightColumn:A,displayHeight:Re,data:e,fullWidth:wt,headerRowHeight:a,activeCell:u,innerRef:le,rowHeight:ie,rowKey:g,selection:x,rowClassName:ee,editing:V,getContextMenuItems:Cn,setRowData:xn,deleteRows:Ee,insertRowAfter:ce,duplicateRows:ve,stopEditing:qe,cellClassName:P,onScroll:Z,children:b.jsx(cn,{columnRights:se,columnWidths:ne,activeCell:u,selection:x,headerRowHeight:a,rowHeight:ie,hasStickyRightColumn:A,dataLength:e.length,viewHeight:he,viewWidth:pe,contentWidth:wt?void 0:pn,edges:mn,editing:V,isCellDisabled:H,expandSelection:wn})}),b.jsx("div",{ref:K,tabIndex:o.length&&e.length?0:void 0,onFocus:l=>{l.target.blur(),k({col:y.length-(A?3:2),row:e.length-1})}}),!E&&C&&b.jsx(C,{addRows:l=>ce(e.length-1,l)}),ge&&we.length>0&&b.jsx(R,{clientX:ge.x,clientY:ge.y,cursorIndex:ge.cursorIndex,items:we,close:()=>re(null)})]})}));gt.displayName="DataSheetGrid";const Dr=d.forwardRef(({columns:e,gutterColumn:r,stickyRightColumn:t,addRowsComponent:s,createRow:n,duplicateRow:o,style:i,rowKey:a,onFocus:h,onBlur:f,onActiveCellChange:g,onSelectionChange:C,rowClassName:p,rowHeight:D,...E},N)=>{const[z]=d.useState({columns:e,gutterColumn:r,stickyRightColumn:t,addRowsComponent:s,createRow:n,duplicateRow:o,style:i,rowKey:a,onFocus:h,onBlur:f,onActiveCellChange:g,onSelectionChange:C,rowClassName:p,rowHeight:D});return b.jsx(gt,{...z,...E,rowHeight:typeof D=="number"?D:z.rowHeight,ref:N})}),Nr=()=>{const e=d.useRef(!0),r=e.current;return e.current=!1,r},un=d.memo(({active:e,focus:r,rowData:t,setRowData:s,columnData:{placeholder:n,alignRight:o,formatInputOnFocus:i,formatBlurredInput:a,parseUserInput:h,continuousUpdates:f}})=>{const g=d.useRef(null),C=Nr(),p=d.useRef({rowData:t,formatInputOnFocus:i,formatBlurredInput:a,setRowData:s,parseUserInput:h,continuousUpdates:f,firstRender:C,focusedAt:0,changedAt:0,escPressed:!1});return p.current={rowData:t,formatInputOnFocus:i,formatBlurredInput:a,setRowData:s,parseUserInput:h,continuousUpdates:f,firstRender:C,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]),b.jsx("input",{defaultValue:a(t),className:X("dsg-input",o&&"dsg-input-align-right"),placeholder:e?n:void 0,tabIndex:-1,ref:g,style:{pointerEvents:r?"auto":"none"},onChange:D=>{p.current.changedAt=Date.now(),f&&s(h(D.target.value))},onKeyDown:D=>{D.key==="Escape"&&(p.current.escPressed=!0)}})});un.displayName="TextComponent";const jr=Me();function Me({placeholder:e,alignRight:r=!1,continuousUpdates:t=!0,deletedValue:s=null,parseUserInput:n=f=>f.trim()||null,formatBlurredInput:o=f=>String(f??""),formatInputOnFocus:i=f=>String(f??""),formatForCopy:a=f=>String(f??""),parsePastedValue:h=f=>f.replace(/[\n\r]+/g," ").trim()||null}={}){return{component:un,columnData:{placeholder:e,alignRight:r,continuousUpdates:t,formatInputOnFocus:i,formatBlurredInput:o,parseUserInput:n},deleteValue:()=>s,copyValue:({rowData:f})=>a(f),pasteValue:({value:f})=>h(f),isCellEmpty:({rowData:f})=>f==null}}const Mr=["","false","no","off","disabled","0","n","f","unchecked","undefined","null","wrong","negative"],fn=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]),b.jsx("input",{className:"dsg-checkbox",tabIndex:-1,type:"checkbox",ref:i,disabled:o,checked:!!r,onMouseDown:()=>!s&&t(!r),onChange:()=>null})});fn.displayName="CheckboxComponent";const Ar={component:fn,deleteValue:()=>!1,copyValue:({rowData:e})=>e?"YES":"NO",pasteValue:({value:e})=>!Mr.includes(e.toLowerCase()),isCellEmpty:({rowData:e})=>!e},_r=Me({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}}),kr=Me({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)}}),zr=1e12,Fr=1e10,Vr=Me({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*zr)/Fr):"",parseUserInput:e=>{const r=parseFloat(e);return isNaN(r)?null:r/100},parsePastedValue:e=>{const r=parseFloat(e);return isNaN(r)?null:r}}),dn=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]),b.jsx("input",{className:X("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)}})});dn.displayName="DateComponent";const Pr={component:dn,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},hn=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]),b.jsx("input",{className:X("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))}})});hn.displayName="IsoDateComponent";const Lr={component:hn,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},Wr=({columnData:{key:e,original:r},rowData:t,setRowData:s,...n})=>{const o=d.useRef(t);o.current=t;const i=d.useCallback(h=>{s({...o.current,[e]:h})},[e,s]);if(!r.component)return b.jsx(b.Fragment,{});const a=r.component;return b.jsx(a,{columnData:r.columnData,setRowData:i,rowData:t[e],...n})},qr=(e,r)=>({id:e,...r,columnData:{key:e,original:r},component:Wr,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}),Br=gt,Kr=Dr;exports.DataSheetGrid=Kr;exports.DynamicDataSheetGrid=Br;exports.checkboxColumn=Ar;exports.createAddRowsComponent=nn;exports.createContextMenuComponent=sn;exports.createTextColumn=Me;exports.dateColumn=Pr;exports.floatColumn=_r;exports.intColumn=kr;exports.isoDateColumn=Lr;exports.keyColumn=qr;exports.percentColumn=Vr;exports.renderContextMenuItem=pt;exports.textColumn=jr;
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,C=({rowIndex:e})=>(0,u.jsx)(u.Fragment,{children:e+1}),w=()=>!0,T=e=>e,E=e=>{if(typeof e==`number`)return{basis:0,grow:e,shrink:1};if(e.match(/^ *\d+(\.\d*)? *$/))return{basis:0,grow:parseFloat(e.trim()),shrink:1};if(e.match(/^ *\d+(\.\d*)? *px *$/))return{basis:parseFloat(e.trim()),grow:1,shrink:1};if(e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? *$/)){let[t,n]=e.trim().split(` `);return{basis:0,grow:parseFloat(t),shrink:parseFloat(n)}}if(e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? *px *$/)){let[t,n]=e.trim().split(` `);return{basis:parseFloat(n),grow:parseFloat(t),shrink:1}}if(e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? \d+(\.\d*)? *px *$/)){let[t,n,r]=e.trim().split(` `);return{basis:parseFloat(r),grow:parseFloat(t),shrink:parseFloat(n)}}return{basis:0,grow:1,shrink:1}},ee=(e,t,n,r=!1)=>(0,c.useMemo)(()=>{let i=[t===!1?{basis:0,grow:0,shrink:0,minWidth:0,component:()=>(0,u.jsx)(u.Fragment,{}),headerClassName:`dsg-hidden-cell`,cellClassName:`dsg-hidden-cell`,isCellEmpty:w}:{...t,basis:t?.basis??40,grow:t?.grow??0,shrink:t?.shrink??0,minWidth:t?.minWidth??0,title:t?.title??(0,u.jsx)(`div`,{className:`dsg-corner-indicator`}),component:t?.component??C,isCellEmpty:w},...e];return n&&i.push({...n,basis:n?.basis??40,grow:n?.grow??0,shrink:n?.shrink??0,minWidth:n.minWidth??0,isCellEmpty:w}),i.map((e,t)=>{let n=e.width===void 0?{basis:void 0,grow:void 0,shrink:void 0}:E(e.width),i=e.stickyLeft===void 0?t===1&&r:e.stickyLeft;return{...e,basis:e.basis??n.basis??0,grow:e.grow??n.grow??1,shrink:e.shrink??n.shrink??1,minWidth:e.minWidth??100,component:e.component??y,disableKeys:e.disableKeys??!1,disabled:e.disabled??!1,keepFocus:e.keepFocus??!1,deleteValue:e.deleteValue??x,copyValue:e.copyValue??S,pasteValue:e.pasteValue??x,prePasteValues:e.prePasteValues??T,isCellEmpty:e.isCellEmpty??b,stickyLeft:i}})},[t,n,e,r]),D=e=>{let[t,n]=(0,c.useState)(e);return[t,(0,c.useCallback)(e=>{n(t=>{let n=typeof e==`function`?e(t):e;return(0,f.default)(n,t)?t:n})},[n])]},te=(e,t,n)=>{let[r,i]=D({top:!0,right:!0,bottom:!0,left:!0});return(0,c.useEffect)(()=>{let r=(0,d.throttle)(100,()=>{i({top:e.current?.scrollTop===0,right:(e.current?.scrollLeft??0)>=(e.current?.scrollWidth??0)-(t??0)-1,bottom:(e.current?.scrollTop??0)>=(e.current?.scrollHeight??0)-(n??0)-1,left:e.current?.scrollLeft===0})}),a=e.current;return a?.addEventListener(`scroll`,r),setTimeout(r,100),()=>{a?.removeEventListener(`scroll`,r),r.cancel()}},[n,t,e,i]),r},O=(e,t)=>{(0,c.useEffect)(()=>{let n=(...e)=>{t(...e)};return document.addEventListener(e,n),()=>{document.removeEventListener(e,n)}},[t,e])},k=(e,t=200)=>{let n=(0,c.useRef)(null),r=(0,c.useMemo)(()=>(0,d.throttle)(t,!0,()=>{setTimeout(()=>n.current=e.current?.getBoundingClientRect()||null,0)}),[e,t]);return(0,c.useCallback)((t=!1)=>(t?n.current=e.current?.getBoundingClientRect()||null:r(),n.current),[e,r])},A=(e={})=>({addRows:t})=>{let[n,r]=(0,c.useState)(1),[i,a]=(0,c.useState)(String(n));return(0,u.jsxs)(`div`,{className:`dsg-add-row`,children:[(0,u.jsx)(`button`,{type:`button`,className:`dsg-add-row-btn`,onClick:()=>t(n),children:e.button??`Add`}),` `,(0,u.jsx)(`input`,{className:`dsg-add-row-input`,value:i,onBlur:()=>a(String(n)),type:`number`,min:1,onChange:e=>{a(e.target.value),r(Math.max(1,Math.round(parseInt(e.target.value)||0)))},onKeyDown:e=>{e.key===`Enter`&&t(n)}}),` `,e.unit??`rows`]})},ne=A();ne.displayName=`AddRows`;var re=(e,t)=>{let[n,r]=(0,c.useState)(e),i=(0,c.useRef)(void 0);return(0,c.useEffect)(()=>()=>i.current?.cancel(),[]),[n,(0,c.useMemo)(()=>i.current=(0,d.debounce)(t,e=>{r(e)}),[t])]},j=e=>e.type===`CUT`?(0,u.jsx)(u.Fragment,{children:`Cut`}):e.type===`COPY`?(0,u.jsx)(u.Fragment,{children:`Copy`}):e.type===`PASTE`?(0,u.jsx)(u.Fragment,{children:`Paste`}):e.type===`DELETE_ROW`?(0,u.jsx)(u.Fragment,{children:`Delete row`}):e.type===`DELETE_ROWS`?(0,u.jsxs)(u.Fragment,{children:[`Delete rows `,(0,u.jsx)(`b`,{children:e.fromRow}),` to `,(0,u.jsx)(`b`,{children:e.toRow})]}):e.type===`INSERT_ROW_BELLOW`?(0,u.jsx)(u.Fragment,{children:`Insert row below`}):e.type===`DUPLICATE_ROW`?(0,u.jsx)(u.Fragment,{children:`Duplicate row`}):e.type===`DUPLICATE_ROWS`?(0,u.jsxs)(u.Fragment,{children:[`Duplicate rows `,(0,u.jsx)(`b`,{children:e.fromRow}),` to `,(0,u.jsx)(`b`,{children:e.toRow})]}):e.type,M=(e=j)=>({clientX:t,clientY:n,items:r,close:i})=>{let a=(0,c.useRef)(null);return O(`mousedown`,(0,c.useCallback)(e=>{a.current?.contains(e.target)||i()},[i])),(0,u.jsx)(`div`,{className:`dsg-context-menu`,style:{left:t+`px`,top:n+`px`},ref:a,children:r.map(t=>(0,u.jsx)(`div`,{onClick:t.action,className:`dsg-context-menu-item`,children:e(t)},t.type))})},N=M(j);N.displayName=`ContextMenu`;var ie=typeof DOMParser<`u`?new DOMParser:{parseFromString:()=>null},ae=e=>ie.parseFromString(p.default.sanitize(e,{FORBID_TAGS:[`style`]}),`text/html`),oe=e=>{let t=ae(e.replace(/<br\/?>/g,`
2
+ `)),n=t.getElementsByTagName(`table`)[0];if(n){let e=[];for(let t=0;t<n.rows.length;t++){let r=[];e.push(r);for(let e=0;e<n.rows[t].cells.length;e++)r.push(n.rows[t].cells[e].textContent??``)}return e}let r=t.getElementsByTagName(`span`)[0];return r?[[r.textContent??``]]:[[``]]},se=e=>{let t=e.replace(/\r|\n$/g,``),n=[[]],r=0,i=0,a=!1,o=0,s=()=>{let e=t.slice(i,r);e[0]===`"`&&e[e.length-1]===`"`&&(a=!0),a&&e[e.length-1]===`"`&&e.includes(`
3
+ `)&&(e=e.slice(1,e.length-1).replace(/""/g,`"`),a=!1),a&&e[e.length-1]!==`"`?e.split(`
4
+ `).forEach((e,t,{length:r})=>{n[o].push(e),t<r-1&&(n.push([]),o++)}):n[o].push(e)};for(;r<t.length;)a&&t[r]===`"`&&![void 0,` `,`"`].includes(t[r+1])&&(a=!1),a&&t[r]===`"`&&t[r+1]===`"`&&r++,r===i&&t[r]===`"`&&(a=!0),t[r]===` `&&(s(),i=r+1,a=!1),t[r]===`
5
+ `&&!a&&(s(),n.push([]),i=r+1,o++),r++;return s(),n},ce=e=>/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,le=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`),ue=e=>e.match(/^[^\x00-\x20\x7F-\x9F]$/)!==null,de=(e,t,n,r)=>{if(e===null||!t||!n)return null;if(typeof e!=`object`)throw Error(`Value must be an object or null`);let i=r.findIndex(t=>t.id===e.col),a={col:Math.max(0,Math.min(t-1,i===-1?Number(e.col):i-1)),row:Math.max(0,Math.min(n-1,Number(e.row)))};if(isNaN(a.col)||isNaN(a.row))throw Error(`col or cell are not valid positive numbers`);return a},fe=(e,t)=>e?{col:e.col,row:e.row,colId:t[e.col+1]?.id}:null,pe=(e,t,n,r)=>{if(e===null||!t||!n)return null;if(typeof e!=`object`)throw Error(`Value must be an object or null`);let i={min:de(e.min,t,n,r),max:de(e.max,t,n,r)};if(!i.min||!i.max)throw Error(`min and max must be defined`);return i},me=(e,t)=>e?{min:fe(e.min,t),max:fe(e.max,t)}:null,he=()=>Array.from(document.querySelectorAll(`*`)).filter(e=>e instanceof HTMLElement&&typeof e.tabIndex==`number`&&e.tabIndex>=0&&!e.disabled&&(!(e instanceof HTMLAnchorElement)||!!e.href||e.getAttribute(`tabIndex`)!==null)&&getComputedStyle(e).visibility!==`collapse`),ge=({children:e,gutter:t,stickyRight:n,stickyLeft:r,active:i,disabled:a,className:o,width:s,left:c})=>(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-cell`,t&&`dsg-cell-gutter`,a&&`dsg-cell-disabled`,t&&i&&`dsg-cell-gutter-active`,n&&`dsg-cell-sticky-right`,r&&`dsg-cell-sticky-left`,o),style:{width:s,left:n?void 0:c},children:e}),_e=(e,t)=>(0,c.useMemo)(()=>{let n=new Map;return r=>(n.has(r)||n.set(r,(...n)=>{e(r,...n.slice(0,t))}),n.get(r))},[t,e]),ve=({data:e,columns:t,outerRef:n,innerRef:r,columnWidths:i,hasStickyRightColumn:a,pinFirstColumn:o,displayHeight:s,headerRowHeight:l,rowHeight:d,rowKey:f,fullWidth:p,selection:g,activeCell:_,rowClassName:v,cellClassName:y,children:b,editing:x,getContextMenuItems:S,setRowData:C,deleteRows:w,duplicateRows:T,insertRowAfter:E,stopEditing:ee,onScroll:D})=>{let te=(0,m.useVirtualizer)({count:e.length,getScrollElement:()=>n.current,paddingStart:l,estimateSize:e=>d(e).height,getItemKey:t=>{if(f&&t>0){let n=e[t-1];if(typeof f==`function`)return f({rowData:n,rowIndex:t});if(typeof f==`string`&&n instanceof Object&&f in n){let e=n[f];if(typeof e==`string`||typeof e==`number`)return e}}return t},overscan:5}),O=(0,m.useVirtualizer)({count:t.length,getScrollElement:()=>n.current,estimateSize:e=>i?.[e]??100,horizontal:!0,getItemKey:e=>t[e].id??e,overscan:1,rangeExtractor:e=>{let n=(0,m.defaultRangeExtractor)(e);if(n[0]!==0&&n.unshift(0),(o||t[1]?.stickyLeft)&&t.length>1&&!n.includes(1)){let e=n.findIndex(e=>e>1);e===-1?n.push(1):n.splice(e,0,1)}return a&&n[n.length-1]!==t.length-1&&n.push(t.length-1),n}});(0,c.useEffect)(()=>{O.measure()},[O,i]);let k=_e(C,1),A=_e(w,0),ne=_e(T,0),re=_e(E,0),j=e=>{if(!t[e].stickyLeft)return 0;if(!i?.length){let t=O.getOffsetForIndex(e);return typeof t==`number`?t:0}let n=0;for(let t=0;t<e;t++)n+=i[t];return n},M=g?.min.col??_?.col,N=g?.max.col??_?.col,ie=g?.min.row??_?.row,ae=g?.max.row??_?.row;return(0,u.jsx)(`div`,{ref:n,className:`dsg-container`,onScroll:D,style:{height:s},children:(0,u.jsxs)(`div`,{ref:r,style:{width:p?`100%`:O.getTotalSize(),height:te.getTotalSize()},children:[l>0&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,`dsg-row-header`),style:{width:p?`100%`:O.getTotalSize(),height:l},children:O.getVirtualItems().map(e=>{let n=!!t[e.index].stickyLeft;return(0,u.jsx)(ge,{gutter:e.index===0,stickyRight:a&&e.index===t.length-1,stickyLeft:n,width:e.size,left:n?j(e.index):e.start,className:(0,h.default)(`dsg-cell-header`,M!==void 0&&N!==void 0&&M<=e.index-1&&N>=e.index-1&&`dsg-cell-header-active`,t[e.index].headerClassName),children:(0,u.jsx)(`div`,{className:`dsg-cell-header-container`,children:t[e.index].title})},e.key)})}),te.getVirtualItems().map(n=>{let r=n.index>=(ie??1/0)&&n.index<=(ae??-1/0);return(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-row`,typeof v==`string`?v:null,typeof v==`function`?v({rowData:e[n.index],rowIndex:n.index}):null),style:{height:n.size,top:n.start,width:p?`100%`:O.getTotalSize()},children:O.getVirtualItems().map(i=>{let o=t[i.index].cellClassName,s=t[i.index].disabled,c=t[i.index].component,l=s===!0||typeof s==`function`&&s({rowData:e[n.index],rowIndex:n.index}),d=_?.row===n.index&&_.col===i.index-1,f=!!t[i.index].stickyLeft;return(0,u.jsx)(ge,{gutter:i.index===0,stickyRight:a&&i.index===t.length-1,stickyLeft:f,active:i.index===0&&r,disabled:l,className:(0,h.default)(typeof o==`function`?o({rowData:e[n.index],rowIndex:n.index,columnId:t[i.index].id}):o,typeof y==`function`?y({rowData:e[n.index],rowIndex:n.index,columnId:t[i.index].id}):y),width:i.size,left:f?j(i.index):i.start,children:(0,u.jsx)(c,{rowData:e[n.index],getContextMenuItems:S,disabled:l,active:d,columnIndex:i.index-1,rowIndex:n.index,focus:d&&x,deleteRow:A(n.index),duplicateRow:ne(n.index),stopEditing:ee,insertRowBelow:re(n.index),setRowData:k(n.index),columnData:t[i.index].columnData})},i.key)})},n.key)}),b]})})},P=(e,t,n,r)=>[[r,e],[t,e],[t,n],[r,n],[r,e]],ye=(e,t,n,r)=>`polygon(evenodd, ${[...P(0,`100%`,`100%`,0),...P(e,t,n,r)].map(e=>e.map(e=>typeof e==`number`&&e!==0?e+`px`:e).join(` `)).join(`,`)})`,be=c.default.memo(({columnWidths:e,columnRights:t,headerRowHeight:n,selection:r,rowHeight:i,activeCell:a,hasStickyRightColumn:o,dataLength:s,viewWidth:l,viewHeight:d,contentWidth:f,edges:p,isCellDisabled:m,editing:g,expandSelection:_,stickyLeftColumns:v,getStickyLeftOffset:y})=>{let b=a?m(a):!1,x=(0,c.useMemo)(()=>{if(!r)return b;for(let e=r.min.col;e<=r.max.col;++e)for(let t=r.min.row;t<=r.max.row;++t)if(!m({col:e,row:t}))return!1;return!0},[b,m,r]);if(!e||!t)return null;let S=e=>+(e<s-1),C=t=>+(t<e.length-(o?3:2)),w=a&&{width:e[a.col+1]+C(a.col),height:i(a.row).height+S(a.row),left:t[a.col],top:i(a.row).top+n},T=r&&{width:e.slice(r.min.col+1,r.max.col+2).reduce((e,t)=>e+t)+C(r.max.col),height:i(r.max.row).top+i(r.max.row).height-i(r.min.row).top+S(r.max.row),left:t[r.min.col],top:i(r.min.row).top+n},E=a&&v&&y&&v[a.col],ee=E&&y?y(a.col+1):0,D=r&&v&&y&&(()=>{for(let e=r.min.col;e<=r.max.col;e++)if(!v[e])return!1;return!0})(),te=D&&r&&y?y(r.min.col+1):0,O=r?.min||a,k=r?.max||a,A=k&&v&&y&&v[k.col],ne=A&&k&&y?y(k.col+1)+e[k.col+1]:0,re=r&&v?.[r.min.col]||a&&v?.[a.col],j=re&&y?y((r?.min.col??a?.col??0)+1):0,M=k&&_!==null&&{left:t[k.col]+e[k.col+1],top:i(k.row).top+i(k.row).height+n,transform:`translate(-${k.col<e.length-(o?3:2)?50:100}%, -${k.row<s-1?50:100}%)`},N=O&&k&&_!==null&&{width:e.slice(O.col+1,k.col+2).reduce((e,t)=>e+t)+C(k.col),height:i(k.row+_).top+i(k.row+_).height-i(k.row+1).top+S(k.row+_)-1,left:t[O.col],top:i(k.row).top+i(k.row).height+n+1};return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{className:`dsg-scrollable-view-container`,style:{height:i(s-1).top+i(s-1).height+n,width:f||`100%`},children:(0,u.jsx)(`div`,{className:(0,h.default)({"dsg-scrollable-view":!0,"dsg-scrollable-view-t":!p.top,"dsg-scrollable-view-r":!p.right,"dsg-scrollable-view-b":!p.bottom,"dsg-scrollable-view-l":!p.left}),style:{top:n,left:e[0],height:d?d-n:0,width:f&&l?l-e[0]-(o?e[e.length-1]:0):`calc(100% - ${e[0]+(o?e[e.length-1]:0)}px)`}})}),(T||w)&&!re&&(0,u.jsx)(`div`,{className:`dsg-selection-col-marker-container`,style:{left:T?.left??w?.left,width:T?.width??w?.width,height:i(s-1).top+i(s-1).height+n},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker`,x&&`dsg-selection-col-marker-disabled`),style:{top:n}})}),(T||w)&&re&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker-container`,`dsg-selection-col-marker-container-sticky`),style:{position:`sticky`,left:j,top:`auto`,width:T?.width??w?.width,height:i(s-1).top+i(s-1).height+n},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-col-marker`,x&&`dsg-selection-col-marker-disabled`),style:{top:n}})}),(T||w)&&(0,u.jsx)(`div`,{className:`dsg-selection-row-marker-container`,style:{top:T?.top??w?.top,height:T?.height??w?.height,width:f||`100%`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-row-marker`,x&&`dsg-selection-row-marker-disabled`),style:{left:e[0]}})}),w&&a&&!E&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-active-cell`,{"dsg-active-cell-focus":g,"dsg-active-cell-disabled":b}),style:w}),w&&a&&E&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:w.top,left:0,right:0,height:w.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-active-cell`,{"dsg-active-cell-focus":g,"dsg-active-cell-disabled":b,"dsg-active-cell-sticky":!0}),style:{position:`sticky`,left:ee,width:w.width,height:`100%`}})}),T&&w&&!D&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-rect`,x&&`dsg-selection-rect-disabled`),style:{...T,clipPath:ye(w.top-T.top,w.left-T.left,w.top+w.height-T.top,w.left+w.width-T.left)}}),T&&w&&D&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:T.top,left:0,right:0,height:T.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-selection-rect`,x&&`dsg-selection-rect-disabled`,`dsg-selection-rect-sticky`),style:{position:`sticky`,left:te,width:T.width,height:`100%`,background:`var(--dsg-selection-background-color)`,clipPath:ye(w.top-T.top,ee-te,w.top+w.height-T.top,ee+w.width-te)}})}),N&&!D&&(0,u.jsx)(`div`,{className:`dsg-expand-rows-rect`,style:N}),N&&D&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:N.top,left:0,right:0,height:N.height,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-rect`,`dsg-expand-rows-rect-sticky`),style:{position:`sticky`,left:te,width:N.width,height:`100%`}})}),M&&!A&&(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-indicator`,x&&`dsg-expand-rows-indicator-disabled`),style:M}),M&&A&&(0,u.jsx)(`div`,{style:{position:`absolute`,top:M.top,left:0,right:0,height:0,pointerEvents:`none`},children:(0,u.jsx)(`div`,{className:(0,h.default)(`dsg-expand-rows-indicator`,x&&`dsg-expand-rows-indicator-disabled`,`dsg-expand-rows-indicator-sticky`),style:{position:`sticky`,left:ne,transform:M.transform,pointerEvents:`auto`}})})]})});be.displayName=`SelectionRect`;var xe=({value:e,rowHeight:t})=>{let n=(0,c.useRef)([]),[,r]=(0,c.useState)(0);return(0,c.useMemo)(()=>{let i=r=>{if(typeof t==`number`)return Math.min(e.length-1,Math.max(-1,Math.floor(r/t)));let i=0,a=n.current.length-1;for(;i<=a;){let e=Math.floor((i+a)/2);if(n.current[e].top<r)i=e+1;else if(n.current[e].top>r)a=e-1;else return e}if(a===n.current.length-1&&e.length>n.current.length&&(!n.current.length||r>=n.current[a].top+n.current[a].height)){let i=a===-1?0:n.current[a].top+n.current[a].height;do{a++;let r=t({rowIndex:a,rowData:e[a]});n.current.push({height:r,top:i}),i+=r}while(i<=r&&a<n.current.length-1)}return a};return{resetAfter:e=>{n.current=n.current.slice(0,e),r(e=>e+1)},getRowSize:r=>{if(typeof t==`number`)return{height:t,top:t*r};if(r>=e.length)return{height:0,top:0};if(r<n.current.length)return n.current[r];let i=n.current[n.current.length-1].top+n.current[n.current.length-1].height;for(let a=n.current.length;a<=r;a++){let r=t({rowIndex:a,rowData:e[a]});n.current.push({height:r,top:i}),i+=r}return n.current[r]},getRowIndex:i,totalSize:r=>{if(typeof t==`number`)return e.length*t;let a=i(r);return n.current[a].top+n.current[a].height}}},[t,e])},Se=[],Ce=[],we=()=>({}),Te=()=>null,Ee=({rowData:e})=>({...e}),F=c.default.memo(c.default.forwardRef(({value:e=Se,className:t,style:n,height:r=400,onChange:i=Te,columns:a=Ce,rowHeight:o=40,headerRowHeight:s=typeof o==`number`?o:40,gutterColumn:d,stickyRightColumn:p,rowKey:m,addRowsComponent:h=ne,createRow:g=we,autoAddRow:_=!1,lockRows:y=!1,disableExpandSelection:b=!1,disableSmartDelete:x=!1,duplicateRow:S=Ee,contextMenuComponent:C=N,disableContextMenu:w=!1,onFocus:T=Te,onBlur:E=Te,onActiveCellChange:A=Te,onSelectionChange:j=Te,rowClassName:M,cellClassName:ie,onScroll:ae,pinFirstColumn:ge=!1},_e)=>{let P=(0,c.useRef)(null),ye=w||y,F=ee(a,d,p,ge),I=!!p,De=ge||!!F[1]?.stickyLeft,Oe=(0,c.useRef)(null),L=(0,c.useRef)(null),ke=(0,c.useRef)(null),Ae=(0,c.useRef)(null),[je,Me]=re(1,100),{getRowSize:Ne,totalSize:Pe,getRowIndex:Fe}=xe({value:e,rowHeight:o}),Ie=Math.min(r,s+Pe(r)+je),{width:Le,height:R}=(0,l.useResizeDetector)({targetRef:L,refreshMode:`throttle`,refreshRate:100});Me(R?Ie-R:0);let Re=te(L,Le,R),{fullWidth:ze,totalWidth:Be,columnWidths:z,columnRights:B}=v(F,Le),Ve=(0,c.useMemo)(()=>F.slice(1).map(e=>!!e.stickyLeft),[F]),He=(0,c.useCallback)(e=>{if(!F[e]?.stickyLeft)return 0;if(!z?.length){let t=0;for(let n=0;n<e;n++)(F[n].stickyLeft||n===0)&&(t+=F[n].basis||F[n].minWidth||100);return t}let t=0;for(let n=0;n<e;n++)(F[n].stickyLeft||n===0)&&(t+=z[n]);return t},[F,z]),[Ue,V]=(0,c.useState)(null),[We,Ge]=(0,c.useState)([]),[H,U]=(0,c.useState)(!1),[Ke,qe]=(0,c.useState)(0),[Je,Ye]=(0,c.useState)(null),[W,G]=D(null),[K,q]=D(null),J=(0,c.useMemo)(()=>W&&K&&{min:{col:Math.min(W.col,K.col),row:Math.min(W.row,K.row)},max:{col:Math.max(W.col,K.col),row:Math.max(W.row,K.row)}},[W,K]),[Y,Xe]=D({columns:!1,rows:!1,active:!1}),Ze=b||H||Y.active||W?.row===e?.length-1||J?.max.row===e?.length-1||W&&F.slice((J?.min.col??W.col)+1,(J?.max.col??W.col)+2).every(e=>e.disabled===!0)?null:Ke,Qe=k(Oe),$e=k(L);(0,c.useEffect)(()=>{W!==null&&(document.activeElement.blur(),window.getSelection()?.removeAllRanges())},[W!==null]);let et=(0,c.useCallback)((e,t=!1,n=!1)=>{let r=Qe(t),i=n&&$e(t);if(r&&B&&z){let t=e.clientX-r.left,n=e.clientY-r.top;return i&&(e.clientY-i.top<=s&&(n=0),e.clientX-i.left<=z[0]&&(t=0),De&&e.clientX-i.left<=z[0]+z[1]&&(t=B[0]+1),I&&i.right-e.clientX<=z[z.length-1]&&(t=B[B.length-2]+1)),{col:B.findIndex(e=>t<e)-1,row:Fe(n-s)}}return null},[B,z,e.length,Qe,$e,s,I,De,Fe]),X=(0,c.useRef)(e);X.current=e;let Z=(0,c.useCallback)(e=>{let t=F[e.col+1].disabled;return!!(typeof t==`function`?t({rowData:X.current[e.row],rowIndex:e.row}):t)},[F]),Q=(0,c.useCallback)((e,t=1)=>{y||(q(null),U(!1),i([...X.current.slice(0,e+1),...Array(t).fill(0).map(g),...X.current.slice(e+1)],[{type:`CREATE`,fromRowIndex:e+1,toRowIndex:e+1+t}]),G(n=>({col:n?.col||0,row:e+t,doNotScrollX:!0})))},[g,y,i,G,q]),tt=(0,c.useCallback)((e,t=e)=>{y||(i([...X.current.slice(0,t+1),...X.current.slice(e,t+1).map((t,n)=>S({rowData:t,rowIndex:n+e})),...X.current.slice(t+1)],[{type:`CREATE`,fromRowIndex:t+1,toRowIndex:t+2+t-e}]),G({col:0,row:t+1,doNotScrollX:!0}),q({col:F.length-(I?3:2),row:2*t-e+1,doNotScrollX:!0}),U(!1))},[F.length,S,y,i,G,q,I]),$=(0,c.useCallback)(e=>{if(!(!R||!Le)){if(!e.doNotScrollY){let t=Ne(e.row).top,n=Ne(e.row).top+Ne(e.row).height+s-R+1,r=L.current.scrollTop;r>t?L.current.scrollTop=t:r<n&&(L.current.scrollTop=n)}if(B&&z&&L.current&&!e.doNotScrollX){let t=B[e.col]-B[0],n=B[e.col]+z[e.col+1]+(I?z[z.length-1]:0)-Le+1,r=L.current.scrollLeft;r>t?L.current.scrollLeft=t:r<n&&(L.current.scrollLeft=n)}}},[R,Le,s,B,z,Ne,I]);(0,c.useEffect)(()=>{K&&$(K)},[K,$]),(0,c.useEffect)(()=>{W&&$(W)},[W,$]);let nt=(0,c.useCallback)((e,t)=>{i([...X.current?.slice(0,e),t,...X.current?.slice(e+1)],[{type:`UPDATE`,fromRowIndex:e,toRowIndex:e+1}])},[i]),rt=(0,c.useCallback)((e,t=e)=>{y||(U(!1),G(n=>{let r=Math.min(X.current.length-2-t+e,e);return r<0?null:n&&{col:n.col,row:r}}),q(null),i([...X.current.slice(0,e),...X.current.slice(t+1)],[{type:`DELETE`,fromRowIndex:e,toRowIndex:t+1}]))},[y,i,G,q]),it=(0,c.useCallback)((t=!0)=>{let n=t&&!x;if(!W)return;let r=J?.min||W,a=J?.max||W;if(e.slice(r.row,a.row+1).every((e,t)=>F.every(n=>n.isCellEmpty({rowData:e,rowIndex:t+r.row})))){n&&rt(r.row,a.row);return}let o=[...e];for(let e=r.row;e<=a.row;++e)for(let t=r.col;t<=a.col;++t)if(!Z({col:t,row:e})){let{deleteValue:n=({rowData:e})=>e}=F[t+1];o[e]=n({rowData:o[e],rowIndex:e})}if(n&&(0,f.default)(o,e)){G({col:0,row:r.row,doNotScrollX:!0}),q({col:F.length-(I?3:2),row:a.row,doNotScrollX:!0});return}i(o,[{type:`UPDATE`,fromRowIndex:r.row,toRowIndex:a.row+1}])},[W,F,e,rt,Z,i,J?.max,J?.min,G,q,I]),at=(0,c.useCallback)(({nextRow:e=!0}={})=>{W?.row===X.current.length-1?e&&_?Q(W.row):U(!1):(U(!1),e&&G(e=>e&&{col:e.col,row:e.row+1}))},[W?.row,_,Q,G]),ot=(0,c.useCallback)(async t=>{if(!H&&W){let n=[],r=J?.min||W,i=J?.max||W;for(let t=r.row;t<=i.row;++t){n.push([]);for(let a=r.col;a<=i.col;++a){let{copyValue:i=()=>null}=F[a+1];n[t-r.row].push(i({rowData:e[t],rowIndex:t}))}}let a=n.map(e=>e.map(e=>ce(String(e??``))).join(` `)).join(`
6
+ `),o=`<table>${n.map(e=>`<tr>${e.map(e=>`<td>${le(String(e??``)).replace(/\n/g,`<br/>`)}</td>`).join(``)}</tr>`).join(``)}</table>`;if(t!==void 0){t.clipboardData?.setData(`text/plain`,a),t.clipboardData?.setData(`text/html`,o),t.preventDefault();return}let s=!1;if(navigator.clipboard.write!==void 0){let e=new Blob([a],{type:`text/plain`}),t=new Blob([o],{type:`text/html`}),n=[new ClipboardItem({"text/plain":e,"text/html":t})];await navigator.clipboard.write(n).then(()=>{s=!0})}else navigator.clipboard.writeText===void 0?document.execCommand!==void 0&&document.execCommand(`copy`)&&(s=!0):await navigator.clipboard.writeText(a).then(()=>{s=!0});s||alert(`This action is unavailable in your browser, but you can still use Ctrl+C for copy or Ctrl+X for cut`)}},[W,F,e,H,J]);O(`copy`,ot);let st=(0,c.useCallback)(e=>{!H&&W&&(ot(e),it(!1))},[W,it,H,ot]);O(`cut`,st);let ct=(0,c.useCallback)(async t=>{if(!H&&W){let n=J?.min||W,r=J?.max||W,a=await Promise.all(t[0].map((e,r)=>{let i=F[n.col+r+1]?.prePasteValues,a=t.map(e=>e[r]);return i?.(a)??a}));if(t=t.map((e,t)=>a.map(e=>e[t])),t.length===1){let a=[...e];for(let e=0;e<t[0].length;e++){let i=F[n.col+e+1]?.pasteValue;if(i)for(let o=n.row;o<=r.row;o++)Z({col:e+n.col,row:o})||(a[o]=await i({rowData:a[o],value:t[0][e],rowIndex:o}))}i(a,[{type:`UPDATE`,fromRowIndex:n.row,toRowIndex:r.row+1}]),G({col:n.col,row:n.row}),q({col:Math.min(n.col+t[0].length-1,F.length-(I?3:2)),row:r.row})}else{let r=[...e],a=n.row+t.length-e.length;a>0&&(y?t.splice(t.length-a,a):r=[...r,...Array(a).fill(0).map(()=>g())]);for(let e=0;e<t[0].length&&n.col+e<F.length-(I?2:1);e++){let i=F[n.col+e+1]?.pasteValue;if(i)for(let a=0;a<t.length;a++)Z({col:n.col+e,row:n.row+a})||(r[n.row+a]=await i({rowData:r[n.row+a],value:t[a][e],rowIndex:n.row+a}))}let o=[{type:`UPDATE`,fromRowIndex:n.row,toRowIndex:n.row+t.length-(!y&&a>0?a:0)}];a>0&&!y&&o.push({type:`CREATE`,fromRowIndex:n.row+t.length-a,toRowIndex:n.row+t.length}),i(r,o),G({col:n.col,row:n.row}),q({col:Math.min(n.col+t[0].length-1,F.length-(I?3:2)),row:n.row+t.length-1})}}},[W,F,g,e,H,I,Z,y,i,J?.max,J?.min,G,q]);O(`paste`,(0,c.useCallback)(e=>{if(W&&!H){let t=[[``]];e.clipboardData?.types.includes(`text/html`)?t=oe(e.clipboardData?.getData(`text/html`)):e.clipboardData?.types.includes(`text/plain`)?t=se(e.clipboardData?.getData(`text/plain`)):e.clipboardData?.types.includes(`text`)&&(t=se(e.clipboardData?.getData(`text`))),ct(t),e.preventDefault()}},[W,ct,H])),O(`mousedown`,(0,c.useCallback)(t=>{if(Ue&&We.length)return;let n=t.button===2||t.button===0&&t.ctrlKey,r=Oe.current?.contains(t.target)||!1,i=r?et(t,!0,!0):null;if(!r&&H&&W&&F[W.col+1].keepFocus)return;if(t.target instanceof HTMLElement&&t.target.className.includes(`dsg-expand-rows-indicator`)){Ye(Math.max(W?.row??0,J?.max.row??0));return}let a=i&&W&&W.col===i.col&&W.row===i.row&&!Z(W),o=H&&t.target instanceof HTMLElement&&t.target.classList.contains(`dsg-input`);if((a||o)&&H)return;let s=i?.col===F.length-2&&I,c=n&&J&&i&&i.row>=J.min.row&&i.row<=J.max.row&&i.col>=J.min.col&&i.col<=J.max.col,l=n&&J&&i?.row===-1&&i.col>=J.min.col&&i.col<=J.max.col,u=n&&J&&i&&i.row>=J.min.row&&i.row<=J.max.row&&i.col===-1,d=s&&J&&i&&i.row>=J.min.row&&i.row<=J.max.row;if(n&&!ye&&V({x:t.clientX,y:t.clientY,cursorIndex:i}),(!(t.shiftKey&&W)||n)&&e.length>0&&G(i&&{col:(c||l)&&W?W.col:Math.max(0,s?0:i.col),row:(c||u||d)&&W?W.row:Math.max(0,i.row),doNotScrollX:!!(c&&W||s||i.col===-1),doNotScrollY:!!(c&&W||i.row===-1)}),a&&!n&&(P.current=W),U(!!(a&&!n)),Xe(i&&!n?{columns:i.col!==-1&&!s||!!(t.shiftKey&&W),rows:i.row!==-1||!!(t.shiftKey&&W),active:!0}:{columns:!1,rows:!1,active:!1}),t.shiftKey&&W&&!n)q(i&&{col:Math.max(0,i.col-+!!s),row:Math.max(0,i.row)});else if(!c){if(i&&(i?.col===-1||i?.row===-1||s)){let t=i.col,n=i.row,r=!1,a=!1;(i.col===-1||s)&&(t=F.length-(I?3:2),r=!0),i.row===-1&&(n=e.length-1,a=!0),l&&K&&(t=K.col,a=!0),(u||d)&&K&&(n=K.row,r=!0),q({col:t,row:n,doNotScrollX:r,doNotScrollY:a})}else q(null);r&&t.preventDefault()}},[Ue,We.length,et,H,W,F,Z,J,I,ye,Xe,G,q,K,e.length])),O(`mouseup`,(0,c.useCallback)(()=>{if(Je!==null){if(Ke>0&&W){let t=[],n=J?.min||W,r=J?.max||W;for(let i=n.row;i<=r.row;++i){t.push([]);for(let a=n.col;a<=r.col;++a){let{copyValue:r=()=>null}=F[a+1];t[i-n.row].push(String(r({rowData:e[i],rowIndex:i})??``))}}Promise.all(t[0].map((e,r)=>{let i=F[n.col+r+1]?.prePasteValues,a=t.map(e=>e[r]);return i?.(a)??a})).then(a=>{t=t.map((e,t)=>a.map(e=>e[t]));let o=[...e];for(let e=0;e<t[0].length;e++){let i=F[n.col+e+1]?.pasteValue;if(i)for(let a=r.row+1;a<=r.row+Ke;a++)Z({col:e+n.col,row:a})||(o[a]=i({rowData:o[a],value:t[(a-r.row-1)%t.length][e],rowIndex:a}))}i(o,[{type:`UPDATE`,fromRowIndex:r.row+1,toRowIndex:r.row+1+Ke}])}),qe(0),G({col:Math.min(W?.col??1/0,J?.min.col??1/0),row:Math.min(W?.row??1/0,J?.min.row??1/0),doNotScrollX:!0,doNotScrollY:!0}),q({col:Math.max(W?.col??0,J?.max.col??0),row:Math.max(W?.row??0,J?.max.row??0)+Ke})}Ye(null)}Xe({columns:!1,rows:!1,active:!1})},[Je,Xe,Ke,W,J?.min,J?.max,e,i,G,q,F,Z])),O(`mousemove`,(0,c.useCallback)(t=>{if(Je!==null){let e=et(t);e&&(qe(Math.max(0,e.row-Je)),$({col:e.col,row:Math.max(e.row,Je)}))}if(Y.active){let n=et(t),r=F.length-(I?3:2);q(n&&{col:Y.columns?Math.max(0,Math.min(r,n.col)):r,row:Y.rows?Math.max(0,n.row):e.length-1,doNotScrollX:!Y.columns,doNotScrollY:!Y.rows}),U(!1)}},[$,Y.active,Y.columns,Y.rows,et,F.length,I,q,e.length,Je])),O(`keydown`,(0,c.useCallback)(t=>{if(W&&!t.isComposing){if(t.key===`Tab`&&!t.shiftKey&&W.col===F.length-(I?3:2)&&!F[W.col+1].disableKeys)if(W.row===e.length-1){if(Ae.current){t.preventDefault(),G(null),q(null),U(!1);let e=he();e[(e.indexOf(Ae.current)+1)%e.length].focus();return}}else{G(e=>({col:0,row:(e?.row??0)+1})),q(null),U(!1),t.preventDefault();return}if(t.key===`Tab`&&t.shiftKey&&W.col===0&&!F[W.col+1].disableKeys)if(W.row===0){if(ke.current){t.preventDefault(),G(null),q(null),U(!1);let e=he();e[(e.indexOf(ke.current)-1+e.length)%e.length].focus();return}}else{G(e=>({col:F.length-(I?3:2),row:(e?.row??1)-1})),q(null),U(!1),t.preventDefault();return}if(t.key?.startsWith(`Arrow`)||t.key===`Tab`){if(H&&F[W.col+1].disableKeys||H&&[`ArrowLeft`,`ArrowRight`].includes(t.key))return;let n=([t,n],r)=>r&&{col:Math.max(0,Math.min(F.length-(I?3:2),r.col+t)),row:Math.max(0,Math.min(e.length-1,r.row+n))};if(t.key===`Tab`&&t.shiftKey)G(e=>n([-1,0],e)),q(null);else{let r={ArrowDown:[0,1],ArrowUp:[0,-1],ArrowLeft:[-1,0],ArrowRight:[1,0],Tab:[1,0]}[t.key];(t.ctrlKey||t.metaKey)&&(r[0]*=F.length,r[1]*=e.length),t.shiftKey?q(e=>n(r,e||W)):(G(e=>n(r,e)),q(null))}U(!1),t.preventDefault()}else t.key===`Escape`?(!H&&!K&&G(null),q(null),U(!1)):(t.key===`Enter`||t.key===`F2`)&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&!t.shiftKey?(q(null),H?F[W.col+1].disableKeys||(at(),t.preventDefault()):Z(W)||(P.current=W,U(!0),$(W),t.preventDefault())):t.key===`Enter`&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&t.shiftKey&&!H?Q(J?.max.row||W.row):t.key===`d`&&(t.ctrlKey||t.metaKey)&&!t.altKey&&!t.shiftKey?(tt(J?.min.row||W.row,J?.max.row),t.preventDefault()):(ue(t.key)||t.code.match(/Key[A-Z]$/))&&!t.ctrlKey&&!t.metaKey&&!t.altKey?!H&&!Z(W)&&(P.current=W,q(null),U(!0),$(W)):[`Backspace`,`Delete`].includes(t.key)?H||(it(),t.preventDefault()):t.key===`a`&&(t.ctrlKey||t.metaKey)&&(H||(G({col:0,row:0,doNotScrollY:!0,doNotScrollX:!0}),q({col:F.length-(I?3:2),row:e.length-1,doNotScrollY:!0,doNotScrollX:!0}),t.preventDefault()))}},[W,F,e.length,it,tt,H,Q,Z,$,J?.max.row,J?.min.row,K,G,q,at,I])),O(`contextmenu`,(0,c.useCallback)(e=>{let t=Oe.current?.contains(e.target)||!1,n=t?et(e,!0,!0):null,r=n&&W&&W.col===n.col&&W.row===n.row&&H;t&&!r&&e.preventDefault()},[et,W,H])),(0,c.useEffect)(()=>{let e=[];W?.row!==void 0&&e.push({type:`COPY`,action:()=>{ot(),V(null)}},{type:`CUT`,action:()=>{st(),V(null)}},{type:`PASTE`,action:()=>{(async()=>{if(navigator.clipboard.read!==void 0){let e=await navigator.clipboard.read();for(let t of e){let e=[[``]];t.types.includes(`text/html`)?e=oe(await(await t.getType(`text/html`)).text()):t.types.includes(`text/plain`)?e=se(await(await t.getType(`text/plain`)).text()):t.types.includes(`text`)&&(e=oe(await(await t.getType(`text`)).text())),await ct(e)}}else navigator.clipboard.readText===void 0?alert(`This action is unavailable in your browser, but you can still use Ctrl+V for paste`):await ct(se(await navigator.clipboard.readText()));V(null)})()}}),J?.max.row===void 0?W?.row!==void 0&&e.push({type:`INSERT_ROW_BELLOW`,action:()=>{V(null),Q(W.row)}}):e.push({type:`INSERT_ROW_BELLOW`,action:()=>{V(null),Q(J.max.row)}}),J?.min.row!==void 0&&J.min.row!==J.max.row?e.push({type:`DUPLICATE_ROWS`,fromRow:J.min.row+1,toRow:J.max.row+1,action:()=>{V(null),tt(J.min.row,J.max.row)}}):W?.row!==void 0&&e.push({type:`DUPLICATE_ROW`,action:()=>{V(null),tt(W.row)}}),J?.min.row!==void 0&&J.min.row!==J.max.row?e.push({type:`DELETE_ROWS`,fromRow:J.min.row+1,toRow:J.max.row+1,action:()=>{V(null),rt(J.min.row,J.max.row)}}):W?.row!==void 0&&e.push({type:`DELETE_ROW`,action:()=>{V(null),rt(W.row)}}),Ge(e),e.length||V(null)},[J,W,rt,tt,Q,st,ot,ct]);let lt=(0,c.useRef)(We);lt.current=We;let ut=(0,c.useCallback)(()=>lt.current,[]);(0,c.useImperativeHandle)(_e,()=>({activeCell:fe(W,F),selection:me(J??(W?{min:W,max:W}:null),F),setSelection:t=>{let n=pe(t,F.length-(I?2:1),e.length,F);G(n?.min||null),U(!1),Xe({columns:!1,active:!1,rows:!1}),q(n?.max||null)},setActiveCell:t=>{G(de(t,F.length-(I?2:1),e.length,F)),U(!1),Xe({columns:!1,active:!1,rows:!1}),q(null)}}));let dt=(0,c.useRef)({onFocus:T,onBlur:E,onActiveCellChange:A,onSelectionChange:j});return dt.current.onFocus=T,dt.current.onBlur=E,dt.current.onActiveCellChange=A,dt.current.onSelectionChange=j,(0,c.useEffect)(()=>{P.current&&(H?dt.current.onFocus({cell:fe(P.current,F)}):dt.current.onBlur({cell:fe(P.current,F)}))},[H,F]),(0,c.useEffect)(()=>{dt.current.onActiveCellChange({cell:fe(W,F)})},[W?.col,W?.row,F]),(0,c.useEffect)(()=>{dt.current.onSelectionChange({selection:me(J??(W?{min:W,max:W}:null),F)})},[J?.min.col??W?.col,J?.min.row??W?.row,J?.max.col??W?.col,J?.max.row??W?.row,W?.col,W?.row,F]),(0,u.jsxs)(`div`,{className:t,style:n,children:[(0,u.jsx)(`div`,{ref:ke,tabIndex:a.length&&e.length?0:void 0,onFocus:e=>{e.target.blur(),G({col:0,row:0})}}),(0,u.jsx)(ve,{columns:F,outerRef:L,columnWidths:z,hasStickyRightColumn:I,pinFirstColumn:ge,displayHeight:Ie,data:e,fullWidth:ze,headerRowHeight:s,activeCell:W,innerRef:Oe,rowHeight:Ne,rowKey:m,selection:J,rowClassName:M,editing:H,getContextMenuItems:ut,setRowData:nt,deleteRows:rt,insertRowAfter:Q,duplicateRows:tt,stopEditing:at,cellClassName:ie,onScroll:ae,children:(0,u.jsx)(be,{columnRights:B,columnWidths:z,activeCell:W,selection:J,headerRowHeight:s,rowHeight:Ne,hasStickyRightColumn:I,dataLength:e.length,viewHeight:R,viewWidth:Le,contentWidth:ze?void 0:Be,edges:Re,editing:H,isCellDisabled:Z,expandSelection:Ze,stickyLeftColumns:Ve,getStickyLeftOffset:He})}),(0,u.jsx)(`div`,{ref:Ae,tabIndex:a.length&&e.length?0:void 0,onFocus:t=>{t.target.blur(),G({col:F.length-(I?3:2),row:e.length-1})}}),!y&&h&&(0,u.jsx)(h,{addRows:t=>Q(e.length-1,t)}),Ue&&We.length>0&&(0,u.jsx)(C,{clientX:Ue.x,clientY:Ue.y,cursorIndex:Ue.cursorIndex,items:We,close:()=>V(null)})]})}));F.displayName=`DataSheetGrid`;var I=c.default.forwardRef(({columns:e,gutterColumn:t,stickyRightColumn:n,addRowsComponent:r,createRow:i,duplicateRow:a,style:o,rowKey:s,onFocus:l,onBlur:d,onActiveCellChange:f,onSelectionChange:p,rowClassName:m,rowHeight:h,...g},_)=>{let[v]=(0,c.useState)({columns:e,gutterColumn:t,stickyRightColumn:n,addRowsComponent:r,createRow:i,duplicateRow:a,style:o,rowKey:s,onFocus:l,onBlur:d,onActiveCellChange:f,onSelectionChange:p,rowClassName:m,rowHeight:h});return(0,u.jsx)(F,{...v,...g,rowHeight:typeof h==`number`?h:v.rowHeight,ref:_})}),De=()=>{let e=(0,c.useRef)(!0),t=e.current;return e.current=!1,t},Oe=`.dsg-cell-sticky-left, .dsg-cell-gutter`,L=`.dsg-cell-sticky-right`,ke=1;function Ae(e,t){let{top:n,left:r}=e.getBoundingClientRect(),i={top:n,left:r,right:r+e.clientWidth,bottom:n+e.clientHeight},a=e.querySelector(`.dsg-row-header`);return a?(i.top=Math.max(i.top,a.getBoundingClientRect().bottom),t?.matches(Oe)||Array.from(a.querySelectorAll(Oe)).forEach(e=>{i.left=Math.max(i.left,e.getBoundingClientRect().right)}),t?.matches(L)||Array.from(a.querySelectorAll(L)).forEach(e=>{i.right=Math.min(i.right,e.getBoundingClientRect().left)}),i):i}function je(e,t){return e.top>=t.top-ke&&e.top<=t.bottom+ke&&e.left>=t.left-ke&&e.left<=t.right+ke}var Me=(e,t)=>e!==null&&e.top===t.top&&e.left===t.left&&e.width===t.width&&e.height===t.height&&e.maxWidth===t.maxWidth&&e.maxHeight===t.maxHeight&&e.anchorVisible===t.anchorVisible,Ne=480,Pe=300,Fe=(e,t,n,r,i)=>Math.max(0,Math.min(Math.max(e,n),r-t-i)),Ie=c.default.memo(({active:e,focus:t,rowData:n,setRowData:r,columnData:{placeholder:i,alignRight:a,formatInputOnFocus:o,formatBlurredInput:s,parseUserInput:l,continuousUpdates:d}})=>{let f=(0,c.useRef)(null),p=De(),[m,_]=(0,c.useState)(null),[v,y]=(0,c.useState)(null);(0,c.useLayoutEffect)(()=>{if(!e||!m){y(null);return}let t=getComputedStyle(document.documentElement),n=parseFloat(t.getPropertyValue(`--dsg-cell-expanded-max-width`))||Ne,r=parseFloat(t.getPropertyValue(`--dsg-cell-expanded-max-height`))||Pe,i=m.closest(`.dsg-container`),a=m.closest(`.dsg-cell`),o,s=()=>{let e=m.getBoundingClientRect(),t=Fe(e.width,e.left,n,window.innerWidth,8),c=Fe(e.height,e.top,r,window.innerHeight,8),l={top:e.top,left:e.left,width:e.width,height:e.height,maxWidth:t,maxHeight:c,anchorVisible:!i||je(e,Ae(i,a))};y(e=>Me(e,l)?e:l),o=requestAnimationFrame(s)};return s(),()=>cancelAnimationFrame(o)},[e,m]);let b=(0,c.useRef)({rowData:n,formatInputOnFocus:o,formatBlurredInput:s,setRowData:r,parseUserInput:l,continuousUpdates:d,firstRender:p,focusedAt:0,changedAt:0,escPressed:!1,currentValue:s(n)});b.current={rowData:n,formatInputOnFocus:o,formatBlurredInput:s,setRowData:r,parseUserInput:l,continuousUpdates:d,firstRender:p,focusedAt:b.current.focusedAt,changedAt:b.current.changedAt,escPressed:b.current.escPressed,currentValue:b.current.currentValue},(0,c.useLayoutEffect)(()=>{if(t){if(f.current){let e=b.current.formatInputOnFocus(b.current.rowData);f.current.value=e,b.current.currentValue=e,f.current.focus(),f.current.select()}b.current.escPressed=!1,b.current.focusedAt=Date.now()}else !b.current.escPressed&&!b.current.continuousUpdates&&!b.current.firstRender&&b.current.changedAt>=b.current.focusedAt&&b.current.setRowData(b.current.parseUserInput(b.current.currentValue)),f.current?.blur()},[t]),(0,c.useEffect)(()=>{if(!t&&f.current){let e=b.current.formatBlurredInput(n);f.current.value=e,b.current.currentValue=e}},[t,n]);let x=v?.anchorVisible??!0,S=e&&(x||t),C=S&&!x,w=t&&!C,T=!!(t&&v),E=(0,u.jsx)(`textarea`,{rows:1,defaultValue:s(n),className:(0,h.default)(`dsg-input`,a&&`dsg-input-align-right`,T&&`dsg-input-floating`),placeholder:e?i:void 0,tabIndex:-1,ref:f,style:v?{pointerEvents:w?`auto`:`none`,minWidth:T?Math.min(v.width,v.maxWidth):v.width,...T?{maxWidth:v.maxWidth,maxHeight:v.maxHeight}:{width:v.width}}:{pointerEvents:w?`auto`:`none`},onChange:e=>{b.current.changedAt=Date.now(),b.current.currentValue=e.target.value,d&&r(l(e.target.value))},onKeyDown:e=>{e.key===`Escape`&&(b.current.escPressed=!0),e.key===`Enter`&&!e.shiftKey&&e.preventDefault()}}),ee=v&&(0,u.jsx)(`div`,{className:(0,h.default)(t&&`dsg-input-floating-wrapper`),style:{position:`fixed`,top:v.top,left:v.left,minHeight:v.height,zIndex:1e3,display:`flex`,alignItems:`center`,pointerEvents:`none`,opacity:C?0:void 0},children:E});return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{ref:_,className:`dsg-input-anchor`}),m&&(0,g.createPortal)(S?ee:E,S?document.body:m)]})});Ie.displayName=`TextComponent`;var Le=R();function R({placeholder:e,alignRight:t=!1,continuousUpdates:n=!0,deletedValue:r=null,parseUserInput:i=e=>e.trim()||null,formatBlurredInput:a=e=>String(e??``),formatInputOnFocus:o=e=>String(e??``),formatForCopy:s=e=>String(e??``),parsePastedValue:c=e=>e.trim()||null}={}){return{component:Ie,columnData:{placeholder:e,alignRight:t,continuousUpdates:n,formatInputOnFocus:o,formatBlurredInput:a,parseUserInput:i},deleteValue:()=>r,copyValue:({rowData:e})=>s(e),pasteValue:({value:e})=>c(e),isCellEmpty:({rowData:e})=>e==null}}var Re=[``,`false`,`no`,`off`,`disabled`,`0`,`n`,`f`,`unchecked`,`undefined`,`null`,`wrong`,`negative`],ze=c.default.memo(({focus:e,rowData:t,setRowData:n,active:r,stopEditing:i,disabled:a})=>{let o=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e&&(n(!t),i({nextRow:!1}))},[e,i]),(0,u.jsx)(`input`,{className:`dsg-checkbox`,tabIndex:-1,type:`checkbox`,ref:o,disabled:a,checked:!!t,onMouseDown:()=>!r&&n(!t),onChange:()=>null})});ze.displayName=`CheckboxComponent`;var Be={component:ze,deleteValue:()=>!1,copyValue:({rowData:e})=>e?`YES`:`NO`,pasteValue:({value:e})=>!Re.includes(e.toLowerCase()),isCellEmpty:({rowData:e})=>!e},z=R({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat().format(e):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:t},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:t}}),B=R({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat().format(e):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:Math.round(t)},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:Math.round(t)}}),Ve=0xe8d4a51000,He=1e10,Ue=R({alignRight:!0,formatBlurredInput:e=>typeof e==`number`?new Intl.NumberFormat(void 0,{style:`percent`}).format(e):``,formatInputOnFocus:e=>typeof e==`number`&&!isNaN(e)?String(Math.round(e*Ve)/He):``,parseUserInput:e=>{let t=parseFloat(e);return isNaN(t)?null:t/100},parsePastedValue:e=>{let t=parseFloat(e);return isNaN(t)?null:t}}),V=c.default.memo(({focus:e,active:t,rowData:n,setRowData:r})=>{let i=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e?i.current?.select():i.current?.blur()},[e]),(0,u.jsx)(`input`,{className:(0,h.default)(`dsg-input`,!t&&`dsg-hide-date-picker`),type:`date`,tabIndex:-1,max:`9999-12-31`,ref:i,style:{pointerEvents:e?`auto`:`none`,opacity:n||t?void 0:0},value:n?.toISOString().substr(0,10)??``,onChange:e=>{let t=new Date(e.target.value);r(isNaN(t.getTime())?null:t)}})});V.displayName=`DateComponent`;var We={component:V,deleteValue:()=>null,copyValue:({rowData:e})=>e?e.toISOString().substr(0,10):null,pasteValue:({value:e})=>{let t=new Date(e.replace(/\.\s?|\//g,`-`));return isNaN(t.getTime())?null:t},minWidth:170,isCellEmpty:({rowData:e})=>!e},Ge=c.default.memo(({focus:e,active:t,rowData:n,setRowData:r})=>{let i=(0,c.useRef)(null);return(0,c.useLayoutEffect)(()=>{e?i.current?.select():i.current?.blur()},[e]),(0,u.jsx)(`input`,{className:(0,h.default)(`dsg-input`,!t&&`dsg-hide-date-picker`),type:`date`,tabIndex:-1,max:`9999-12-31`,ref:i,style:{pointerEvents:e?`auto`:`none`,opacity:n||t?void 0:0},value:n??``,onChange:e=>{let t=new Date(e.target.value);r(isNaN(t.getTime())?null:t.toISOString().substr(0,10))}})});Ge.displayName=`IsoDateComponent`;var H={component:Ge,deleteValue:()=>null,copyValue:({rowData:e})=>e,pasteValue:({value:e})=>{let t=new Date(e.replace(/\.\s?|\//g,`-`));return isNaN(t.getTime())?null:t.toISOString().substr(0,10)},minWidth:170,isCellEmpty:({rowData:e})=>!e},U=({columnData:{key:e,original:t},rowData:n,setRowData:r,...i})=>{let a=(0,c.useRef)(n);a.current=n;let o=(0,c.useCallback)(t=>{r({...a.current,[e]:t})},[e,r]);if(!t.component)return(0,u.jsx)(u.Fragment,{});let s=t.component;return(0,u.jsx)(s,{columnData:t.columnData,setRowData:o,rowData:n[e],...i})},Ke=(e,t)=>({id:e,...t,columnData:{key:e,original:t},component:U,copyValue:({rowData:n,rowIndex:r})=>t.copyValue?.({rowData:n[e],rowIndex:r})??null,deleteValue:({rowData:n,rowIndex:r})=>({...n,[e]:t.deleteValue?.({rowData:n[e],rowIndex:r})??null}),pasteValue:({rowData:n,value:r,rowIndex:i})=>({...n,[e]:t.pasteValue?.({rowData:n[e],value:r,rowIndex:i})??null}),disabled:typeof t.disabled==`function`?({rowData:n,rowIndex:r})=>typeof t.disabled==`function`?t.disabled({rowData:n[e],rowIndex:r}):t.disabled??!1:t.disabled,cellClassName:typeof t.cellClassName==`function`?({rowData:n,rowIndex:r,columnId:i})=>typeof t.cellClassName==`function`?t.cellClassName({rowData:n[e],rowIndex:r,columnId:i}):t.cellClassName??void 0:t.cellClassName,isCellEmpty:({rowData:n,rowIndex:r})=>t.isCellEmpty?.({rowData:n[e],rowIndex:r})??!1}),qe=F,Je=I;exports.DataSheetGrid=Je,exports.DynamicDataSheetGrid=qe,exports.checkboxColumn=Be,exports.createAddRowsComponent=A,exports.createContextMenuComponent=M,exports.createTextColumn=R,exports.dateColumn=We,exports.floatColumn=z,exports.intColumn=B,exports.isoDateColumn=H,exports.keyColumn=Ke,exports.percentColumn=Ue,exports.renderContextMenuItem=j,exports.textColumn=Le;
7
+ //# sourceMappingURL=index.cjs.map