@svar-ui/react-grid
Version:
Fast, feature-rich React DataGrid with virtual scrolling, cell editing, sorting, filtering, and accessibility support.
2 lines (1 loc) • 38.6 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("react"),X=require("@svar-ui/react-core"),st=require("@svar-ui/grid-locales"),Ct=require("@svar-ui/lib-state"),K=require("@svar-ui/grid-store"),A=require("@svar-ui/lib-react"),oe=require("@svar-ui/lib-dom"),We=require("@svar-ui/react-menu"),vt=require("@svar-ui/lib-svelte"),Q=o.createContext(null);function St(n,e){const t=new ResizeObserver(l=>{requestAnimationFrame(()=>e(l[0].contentRect))});return t.observe(n.parentNode),{destroy(){t.disconnect()}}}const et=5,Rt=700;function jt(n){return oe.id(n.getAttribute("data-id"))}function Le(n){const e=n.getBoundingClientRect(),t=document.body,l=e.top+t.scrollTop-t.clientTop||0,a=e.left+t.scrollLeft-t.clientLeft||0;return{y:Math.round(l),x:Math.round(a),width:n.offsetWidth,height:n.offsetHeight}}function qe(n,e){const t=Le(e);return{x:n.clientX-t.x,y:n.clientY-t.y}}function Mt(n,e){const t=e.current;let l=null,a,p,d=!1,w=!1;const u=document.createElement("DIV");u.className="wx-drag-zone",u.setAttribute("tabindex",-1);function g(){clearTimeout(a),a=null}function c(v){const P=oe.locate(v);P&&(l={container:u,sourceNode:v.target,from:jt(P),pos:qe(v,n)},p=l.pos,f(v))}function f(v){if(!l)return;const P=l.pos=qe(v,n);if(!d){if(!w&&!v?.target?.getAttribute("draggable-data")&&Math.abs(p.x-P.x)<et&&Math.abs(p.y-P.y)<et)return;if(N(v)===!1)return H()}if(w){const G=window.scrollX||document.documentElement.scrollLeft||document.body.scrollLeft,q=window.scrollY||document.documentElement.scrollTop||document.body.scrollTop;l.targetNode=document.elementFromPoint(v.pageX-G,v.pageY-q)}else l.targetNode=v.target;t.move&&t.move(v,l),u.style.left=-(l.offset?l.offset.x:0)+"px",u.style.top=l.pos.y+(l.offset?l.offset.y:0)+"px"}function m(v){u.parentNode&&u.parentNode.removeChild(u),u.innerHTML="",d&&t.end&&t.end(v,l),l=p=null,H()}function j(v){t.getReorder&&!t.getReorder()||v.button===0&&(M(v),window.addEventListener("mousemove",S),window.addEventListener("mouseup",i),c(v))}function S(v){f(v)}function i(v){m(v)}function y(v){if(t.getReorder&&!t.getReorder())return;a=setTimeout(()=>{w=!0,c(v.touches[0])},Rt),M(v);function P(){a&&g(),v.target.removeEventListener("touchmove",x),v.target.removeEventListener("touchend",P),m(v)}v.target.addEventListener("touchmove",x),v.target.addEventListener("touchend",P),n.addEventListener("contextmenu",C)}function x(v){d?(v.preventDefault(),f(v.touches[0])):a&&g()}function C(v){if(d||a)return v.preventDefault(),!1}function b(v){v.preventDefault()}function M(v){if(!t.getDraggableInfo)return;const{hasDraggable:P}=t.getDraggableInfo();(!P||v.target.getAttribute("draggable-data"))&&(document.body.style.userSelect="none",document.body.style.webkitUserSelect="none")}function N(v){if(d=!0,t.start){if(t.start(v,l)===!1)return!1;n.appendChild(u),document.body.style.cursor="move"}}function H(v){d=w=!1,document.body.style.cursor="",document.body.style.userSelect="",document.body.style.webkitUserSelect="",window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",i),v&&(n.removeEventListener("mousedown",j),n.removeEventListener("touchstart",y),n.removeEventListener("dragstart",b))}return n.addEventListener("mousedown",j),n.addEventListener("touchstart",y),n.addEventListener("dragstart",b),{destroy(){H(!0)}}}const Nt=.004;function Et(){return{dirX:0,dirY:0,scrollSpeedFactor:1}}function kt(n,e,t,l){const{node:a,left:p,top:d,bottom:w,sense:u,xScroll:g,yScroll:c}=l,f=qe(n,a);t.scrollState||(t.scrollState=Et());let m=0,j=0;f.x<p+u?m=-1:f.x>e.width-u&&(m=1),f.y<d+Math.round(u/2)?j=-1:f.y>e.height-w-Math.round(u/2)&&(j=1),(t.scrollState.dirX!==m||t.scrollState.dirY!==j)&&(rt(t),t.scrollState.dirX=m,t.scrollState.dirY=j),(g&&t.scrollState.dirX!==0||c&&t.scrollState.dirY!==0)&&Dt(t,l,{x:t.scrollState.dirX,y:t.scrollState.dirY})}function Dt(n,e,t){n.autoScrollTimer||(n.autoScrollTimer=setTimeout(()=>{n.activeAutoScroll=setInterval(Lt,15,n,e,t)},250))}function rt(n){n.scrollSpeedFactor=1,n.autoScrollTimer&&(n.autoScrollTimer=clearTimeout(n.autoScrollTimer),n.activeAutoScroll=clearInterval(n.activeAutoScroll))}function Lt(n,e,t){const{x:l,y:a}=t;n.scrollSpeedFactor+=Nt,l!==0&&Ht(n,e,l),a!==0&&Tt(n,e,a)}function Tt(n,e,t){const l=e.node.scrollTop;lt(l+Math.round(e.sense/3)*n.scrollSpeedFactor*t,"scrollTop",e)}function Ht(n,e,t){const l=e.node.scrollLeft;lt(l+Math.round(e.sense/3)*n.scrollSpeedFactor*t,"scrollLeft",e)}function lt(n,e,t){t.node[e]=n}function $t(n){return{tab:!0,"shift+tab":!0,arrowup:!0,arrowdown:!0,arrowright:!0,arrowleft:!0,enter:!0,escape:!0,f2:!0,home:!0,end:!0,"ctrl+home":!0,"ctrl+end":!0,"ctrl+z":n.undo,"ctrl+y":n.undo}}function Te(n,e,t,l,a,p){const d={};return n&&(d.width=`${n}px`,d.minWidth=`${n}px`),e&&(d.flexGrow=e),p&&(d.height=`${p}px`),t&&(d.position="sticky",t.left&&(d.left=`${l}px`),t.right&&(d.right=`${a}px`)),d}function it(n,e,t){let l="";if(n.fixed)for(const a in n.fixed)l+=n.fixed[a]===-1?"wx-shadow ":"wx-fixed ";return l+=e.rowspan>1?"wx-rowspan ":"",l+=e.colspan>1?"wx-colspan ":"",l+=e.vertical?"wx-vertical ":"",l+=t?t(n)+" ":"",l}function At(n){const{row:e,column:t,cellStyle:l=null,columnStyle:a=null,children:p,reorder:d}=n,[w,u]=A.useWritableProp(n.focusable),g=o.useContext(Q),c=A.useStore(g,"focusCell"),f=o.useMemo(()=>Te(t.width,t.flexgrow,t.fixed,t.left,t.right),[t.width,t.flexgrow,t.fixed,t.left,t.right]);function m(b,M){let N="wx-cell";return N+=t.fixed?" "+(t.fixed===-1?"wx-shadow":"wx-fixed"):"",N+=b?" "+b(t):"",N+=M?" "+M(e,t):"",N+=t.treetoggle?" wx-tree-cell":"",N}const j=o.useMemo(()=>m(a,l),[a,l,t,e]),S=o.useMemo(()=>typeof t.draggable=="function"?t.draggable(e,t)!==!1:t.draggable,[t,e]),i=o.useRef(null);o.useEffect(()=>{const b=c?.row===e.id&&c?.column===t.id;i.current&&w&&b&&i.current.focus()},[c,w,e.id,t.id]);const y=o.useCallback(()=>{w&&!c&&g.exec("focus-cell",{row:e.id,column:t.id,eventSource:"focus"})},[g,w,c,e.id,t.id]);o.useEffect(()=>()=>{w&&c&&(g.exec("focus-cell",{eventSource:"destroy"}),u(!1))},[g,u]);const x=o.useMemo(()=>{const b=t.fixed&&t.fixed.left===-1||t.fixed.right===-1,M=t.fixed&&t.fixed.right;return[j,b?"wx-shadow":"",M?"wx-fixed-right":""].filter(Boolean).join(" ")},[j,t]),C=t.cell;return r.jsxs("div",{className:"wx-TSCaXsGV "+x,ref:i,onFocus:y,style:f,"data-row-id":e.id,"data-col-id":t.id,tabIndex:w?"0":"-1",role:"gridcell","aria-colindex":t._colindex,"aria-readonly":t.editor?void 0:!0,children:[d&&t.draggable?S?r.jsx("i",{"draggable-data":"true",className:"wx-TSCaXsGV wx-draggable wxi-drag"}):r.jsx("i",{className:"wx-TSCaXsGV wx-draggable-stub"}):null,t.treetoggle?r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{marginLeft:`${e.$level*28}px`}}),e.$count?r.jsx("i",{"data-action":"toggle-row",className:`wx-TSCaXsGV wx-table-tree-toggle wxi-menu-${e.open!==!1?"down":"right"}`}):null]}):null,C?r.jsx(C,{api:g,row:e,column:t,onAction:({action:b,data:M})=>g.exec(b,M)}):p?p():K.getRenderValue(e,t)]})}function tt(n,e){let t,l;function a(w){t=w.clientX,n.style.opacity=1,document.body.style.cursor="ew-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",p),window.addEventListener("mouseup",d),e&&e.down&&e.down(n)}function p(w){l=w.clientX-t,e&&e.move&&e.move(l)}function d(){n.style.opacity="",document.body.style.cursor="",document.body.style.userSelect="",e&&e.up&&e.up(l),window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",d)}return n.addEventListener("mousedown",a),{destroy(){n.removeEventListener("mousedown",a)}}}function It({filter:n,column:e,action:t,filterValue:l}){function a({value:p}){t({value:p,key:e.id})}return r.jsx(X.Text,{...n.config??{},value:l,onChange:a})}function Vt({filter:n,column:e,action:t,filterValue:l}){const a=o.useContext(Q),p=A.useStore(a,"flatData"),d=o.useMemo(()=>n?.config?.options||e?.options||u(),[n,e,p]),w=o.useMemo(()=>n?.config?.template,[n]);function u(){const f=[];return p.forEach(m=>{const j=K.getValue(m,e);f.includes(j)||f.push(j)}),f.map(m=>({id:m,label:m}))}function g({value:f}){t({value:f,key:e.id})}function c(f){f.key!=="Tab"&&f.preventDefault()}return r.jsx("div",{style:{width:"100%"},onKeyDown:c,children:r.jsx(X.RichSelect,{placeholder:"",clear:!0,...n?.config??{},options:d,value:l,onChange:g,children:f=>w?w(f):f.label})})}const Pt={text:It,richselect:Vt};function zt({filter:n,column:e}){const t=o.useContext(Q),l=A.useStore(t,"filterValues");function a(d){t.exec("filter-rows",d)}const p=o.useMemo(()=>Pt[n.type],[n.type]);return r.jsx(p,{filter:n,column:e,action:a,filterValue:l[e.id]})}function Ot(n){const{cell:e,column:t,row:l,lastRow:a,sortRow:p,columnStyle:d,bodyHeight:w,hasSplit:u}=n,g=o.useContext(Q),c=A.useStore(g,"sortMarks"),f=o.useMemo(()=>c?c[t.id]:void 0,[c,t.id]),m=o.useRef(),j=o.useCallback(k=>{m.current=e.flexgrow?k.parentNode.clientWidth:e.width},[e.flexgrow,e.width]),S=o.useCallback((k,U)=>{g.exec("resize-column",{id:e.id,width:Math.max(1,(m.current||0)+k),inProgress:U})},[g,e.id]),i=o.useCallback(k=>S(k,!0),[S]),y=o.useCallback(k=>S(k,!1),[S]),x=o.useCallback(k=>{!t.sort||e.filter||g.exec("sort-rows",{key:e.id,add:k.ctrlKey})},[g,e.id,e.filter,t.sort]),C=o.useCallback(k=>{k&&k.stopPropagation(),g.exec("collapse-column",{id:e.id,row:l})},[g,e.id,l]),b=o.useCallback(k=>{k.key==="Enter"&&C()},[C]),M=o.useCallback(k=>{k.key==="Enter"&&!e.filter&&x(k)},[x,e.filter]),N=o.useMemo(()=>e.collapsed&&t.collapsed,[e.collapsed,t.collapsed]),H=o.useMemo(()=>N&&!u&&e.collapsible!=="header",[N,u,e.collapsible]),v=o.useMemo(()=>H?{top:-w/2,position:"absolute"}:{},[H,w]),P=o.useMemo(()=>Te(e.width,e.flexgrow,t.fixed,t.left,e.right??t.right,e.height+(N&&H?w:0)),[e.width,e.flexgrow,t.fixed,t.left,e.right,t.right,e.height,N,H,w]),G=o.useMemo(()=>it(t,e,d),[t,e,d]),q=o.useCallback(()=>Object.fromEntries(Object.entries(e).filter(([k])=>k!=="cell")),[e]),T=`wx-cell ${G} ${e.css||""} wx-collapsed`,Y=["wx-cell",G,e.css||"",e.filter?"wx-filter":"",t.fixed&&t.fixed.right?"wx-fixed-right":""].filter(Boolean).join(" "),I=o.useRef(null);return o.useEffect(()=>{const k=I.current;if(!k)return;const U=tt(k,{down:j,move:i,up:y});return()=>{typeof U=="function"&&U()}},[j,i,y,tt]),N?r.jsx("div",{className:"wx-RsQD74qC "+T,style:P,role:"button","aria-label":`Expand column ${e.text||""}`,"aria-expanded":!e.collapsed,tabIndex:0,onKeyDown:b,onClick:C,"data-header-id":t.id,children:r.jsx("div",{className:"wx-RsQD74qC wx-text",style:v,children:e.text||""})}):r.jsxs("div",{className:"wx-RsQD74qC "+Y,style:P,onClick:x,"data-header-id":t.id,tabIndex:!e._hidden&&t.sort&&!e.filter?0:void 0,role:"columnheader","aria-colindex":e._colindex,"aria-colspan":e.colspan>1?e.colspan:void 0,"aria-rowspan":e.rowspan>1?e.rowspan:void 0,"aria-sort":!f?.order||e.filter?"none":f?.order==="asc"?"ascending":"descending",onKeyDown:M,children:[e.collapsible?r.jsx("div",{className:"wx-RsQD74qC wx-collapse",role:"button","aria-label":e.collapsed?"Expand column":"Collapse column","aria-expanded":!e.collapsed,tabIndex:0,onKeyDown:b,onClick:C,children:r.jsx("i",{className:`wx-RsQD74qC wxi-angle-${e.collapsed?"down":"right"}`})}):null,e.cell?(()=>{const k=e.cell;return r.jsx(k,{api:g,cell:q(),column:t,row:l,onAction:({action:U,data:ye})=>g.exec(U,ye)})})():e.filter?r.jsx(zt,{filter:e.filter,column:t}):r.jsx("div",{className:"wx-RsQD74qC wx-text",children:e.text||""}),t.resize&&a&&!e._hidden?r.jsx("div",{className:"wx-RsQD74qC wx-grip",role:"presentation","aria-label":"Resize column",ref:I,onClick:k=>k.stopPropagation(),children:r.jsx("div",{})}):null,p?r.jsx("div",{className:"wx-RsQD74qC wx-sort",children:f?r.jsxs(r.Fragment,{children:[typeof f.index<"u"?r.jsx("div",{className:"wx-RsQD74qC wx-order",children:f.index+1}):null,r.jsx("i",{className:`wx-RsQD74qC wxi-arrow-${f.order==="asc"?"up":"down"}`})]}):null}):null]})}function Kt({cell:n,column:e,row:t,columnStyle:l}){const a=o.useContext(Q),p=o.useMemo(()=>Te(n?.width,n?.flexgrow,e?.fixed,e?.left,n?.right??e?.right,n?.height),[n?.width,n?.flexgrow,e?.fixed,e?.left,n?.right,e?.right,n?.height]),d=o.useMemo(()=>it(e,n,l),[e,n,l]),w=o.useCallback(()=>Object.fromEntries(Object.entries(n||{}).filter(([g])=>g!=="cell")),[n]),u=`wx-6Sdi3Dfd wx-cell ${d||""} ${n?.css||""}`+(e?.fixed&&e?.fixed.right?" wx-fixed-right":"");return r.jsx("div",{className:u,style:p,children:!e?.collapsed&&!n?.collapsed?n?.cell?o.createElement(n.cell,{api:a,cell:w(),column:e,row:t,onAction:({action:g,data:c})=>a.exec(g,c)}):r.jsx("div",{className:"wx-6Sdi3Dfd wx-text",children:n?.text||""}):null})}function nt({deltaLeft:n,contentWidth:e,columns:t,type:l="header",columnStyle:a,bodyHeight:p}){const d=o.useContext(Q),w=A.useStore(d,"_sizes"),u=A.useStore(d,"split"),g=o.useMemo(()=>w?.[`${l}RowHeights`],[w,l]),c=o.useMemo(()=>{let i=[];if(t&&t.length){const y=t[0][l].length;for(let x=0;x<y;x++){let C=0;i.push([]),t.forEach((b,M)=>{const N={...b[l][x]};if(C||i[x].push(N),N.colspan>1){if(C=N.colspan-1,!K.isCommunity()&&b.right){let H=b.right;for(let v=1;v<N.colspan;v++)H-=t[M+v].width;N.right=H}}else C&&C--})}}return i},[t,l]),f=o.useMemo(()=>u?.left||u?.right,[u]);function m(i){return t.find(y=>y.id===i)}function j(i,y){let x=y;return i.rowspan&&(x+=i.rowspan-1),x===c.length-1}function S(i,y,x){if(!x.sort)return!1;for(let C=c.length-1;C>=0;C--){const b=x.header[C];if(!b.filter&&!b._hidden)return y===C}return j(i,y)}return r.jsx("div",{className:`wx-sAsPVaUK wx-${l}`,style:{paddingLeft:`${n}px`,width:`${e}px`},role:"rowgroup",children:c.map((i,y)=>r.jsx("div",{className:l==="header"?"wx-sAsPVaUK wx-h-row":"wx-sAsPVaUK wx-f-row",style:{height:`${g?.[y]}px`,display:"flex"},role:"row",children:i.map(x=>{const C=m(x.id);return l==="header"?r.jsx(Ot,{cell:x,columnStyle:a,column:C,row:y,lastRow:j(x,y),bodyHeight:p,sortRow:S(x,y,C),hasSplit:f},x.id):r.jsx(Kt,{cell:x,columnStyle:a,column:m(x.id),row:y},x.id)})},y))})}function Ft({overlay:n}){const e=o.useContext(Q);function t(a){return typeof a=="function"}const l=n;return r.jsx("div",{className:"wx-1ty666CQ wx-overlay",children:t(n)?r.jsx(l,{onAction:({action:a,data:p})=>e.exec(a,p)}):n})}function Wt(n){const{actions:e,editor:t}=n,[l,a]=o.useState(t?.value||""),p=o.useRef(null);o.useEffect(()=>{p.current&&p.current.focus()},[]);function d(){p.current&&(a(p.current.value),e.updateValue(p.current.value))}function w({key:u}){u==="Enter"&&e.save()}return r.jsx("input",{className:"wx-e7Ao5ejY wx-text",onInput:d,onKeyDown:w,ref:p,type:"text",value:l})}function qt({actions:n,editor:e,onAction:t}){const[l,a]=o.useState(e?.value),[p,d]=o.useState(e?.renderedValue),[w,u]=o.useState(e?.options||[]),g=o.useMemo(()=>e?.config?.template,[e]),c=o.useMemo(()=>e?.config?.cell,[e]),f=o.useMemo(()=>(w||[]).findIndex(C=>C.id===l),[w,l]),m=o.useRef(null),j=o.useRef(null),S=o.useCallback(C=>{m.current=C.navigate,j.current=C.keydown,m.current(f)},[f,m]),i=o.useCallback(C=>{const b=C?.target?.value??"";d(b);const M=b?(e?.options||[]).filter(N=>(N.label||"").toLowerCase().includes(b.toLowerCase())):e?.options||[];u(M),M.length?m.current(-1/0):m.current(null)},[e]),y=o.useRef(null);o.useEffect(()=>{y.current&&y.current.focus()},[]),o.useEffect(()=>{a(e?.value),d(e?.renderedValue),u(e?.options||[])},[e]);const x=o.useCallback(({id:C})=>{n.updateValue(C),n.save()},[n]);return r.jsxs(r.Fragment,{children:[r.jsx("input",{className:"wx-0UYfSd1x wx-input",ref:y,value:p??"",onChange:i,onKeyDown:C=>j.current?j.current(C,f):void 0}),r.jsx(X.SuggestDropdown,{items:w,onReady:S,onSelect:x,children:({option:C})=>{if(g)return g(C);if(c){const b=c;return r.jsx(b,{data:C,onAction:t})}else return C.label}})]})}function Yt({actions:n,editor:e,onAction:t}){const[l]=o.useState(()=>e.value||new Date),[a]=o.useState(()=>e.config?.template),[p]=o.useState(()=>e.config?.cell);function d({value:u}){n.updateValue(u),n.save()}const w=o.useRef(null);return o.useEffect(()=>{w.current&&w.current.focus(),typeof window<"u"&&window.getSelection&&window.getSelection().removeAllRanges()},[]),r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"wx-lNWNYUb6 wx-value",ref:w,tabIndex:0,onClick:()=>n.cancel(),onKeyDown:u=>u.preventDefault(),children:a?a(l):p?(()=>{const u=p;return r.jsx(u,{data:e.value,onAction:t})})():r.jsx("span",{className:"wx-lNWNYUb6 wx-text",children:e.renderedValue})}),r.jsx(X.Dropdown,{width:"auto",children:r.jsx(X.Calendar,{value:l,onChange:d,buttons:e.config?.buttons})})]})}function _t(n){const{actions:e,editor:t}=n,l=n.onAction??n.onaction,a=t.config||{},[p]=o.useState(t.options.find(i=>i.id===t.value)),[d]=o.useState(t.value),[w]=o.useState(t.options),u=o.useMemo(()=>w.findIndex(i=>i.id===d),[w,d]);function g({id:i}){e.updateValue(i),e.save()}let c;const[f,m]=o.useState();function j(i){c=i.navigate,m(()=>i.keydown),c(u)}const S=o.useRef(null);return o.useEffect(()=>{S.current&&S.current.focus(),typeof window<"u"&&window.getSelection&&window.getSelection().removeAllRanges()},[]),r.jsxs(r.Fragment,{children:[r.jsx("div",{ref:S,className:"wx-ywGRk611 wx-value",tabIndex:0,onClick:()=>e.cancel(),onKeyDown:i=>{f(i,u),i.preventDefault()},children:a.template?a.template(p):a.cell?(()=>{const i=a.cell;return r.jsx(i,{data:p,onAction:l})})():r.jsx("span",{className:"wx-ywGRk611 wx-text",children:t.renderedValue})}),r.jsx(X.SuggestDropdown,{items:w,onReady:j,onSelect:g,children:({option:i})=>a.template?a.template(i):a.cell?(()=>{const y=a.cell;return r.jsx(y,{data:i,onAction:l})})():i.label})]})}const Xt={text:Wt,combo:qt,datepicker:Yt,richselect:_t};function Gt({column:n,row:e}){const t=o.useContext(Q),l=A.useStore(t,"editor"),a=o.useCallback((S,i)=>{t.exec("close-editor",{ignore:S}),i&&t.exec("focus-cell",{...i,eventSource:"click"})},[t]),p=o.useCallback(S=>{const i=S?null:{row:l?.id,column:l?.column};a(!1,i)},[l,a]),d=o.useCallback(()=>{a(!0,{row:l?.id,column:l?.column})},[l,a]),w=o.useCallback(S=>{t.exec("editor",{value:S})},[t]),u=o.useCallback(S=>{S.key==="Enter"&&l&&d()},[l,d]),g=o.useMemo(()=>Te(n.width,n.flexgrow,n.fixed,n.left,n.right),[n.width,n.flexgrow,n.fixed,n.left,n.right]),c=o.useMemo(()=>{let S=n.editor;typeof S=="function"&&(S=S(e,n));let i=typeof S=="string"?S:S.type;return Xt[i]},[n,e]),f=o.useRef(null);o.useEffect(()=>{if(!f.current)return;const S=oe.clickOutside(f.current,()=>p(!0));return()=>{typeof S=="function"&&S()}},[p]),o.useEffect(()=>{f.current&&typeof g=="string"&&f.current.setAttribute("style",g)},[g]);const m=typeof e.$parent<"u"?"gridcell":"cell",j=typeof e.$parent<"u"?!n.editor:void 0;return r.jsx("div",{className:"wx-8l724t2g wx-cell wx-editor",ref:f,style:typeof g=="object"&&g!==null?g:void 0,role:m,"aria-readonly":j,tabIndex:-1,onClick:S=>S.stopPropagation(),onDoubleClick:S=>S.stopPropagation(),onKeyDown:u,children:c?r.jsx(c,{editor:l,actions:{save:p,cancel:d,updateValue:w},onAction:({action:S,data:i})=>t.exec(S,i)}):null})}function ot(n){const{columns:e,type:t,columnStyle:l}=n,a=o.useContext(Q),{filterValues:p,_columns:d,_sizes:w}=a.getState();function u(g){return l?" "+l(g):""}return r.jsx(r.Fragment,{children:e.map((g,c)=>r.jsx("tr",{children:g.map(f=>{const m=d.find(i=>i.id==f.id),j=`wx-print-cell-${t}${u(m)}${f.filter?" wx-print-cell-filter":""}${f.vertical?" wx-vertical":""}`,S=f.cell;return r.jsx("th",{style:A.styleObject(K.getPrintCellStyle(f,w.columnWidth)),className:"wx-Gy81xq2u "+j,rowSpan:f.rowspan,colSpan:f.colspan,children:S?r.jsx(S,{api:a,cell:Object.fromEntries(Object.entries(f).filter(([i])=>i!=="cell")),column:m,row:c}):f.filter?r.jsx("div",{className:"wx-Gy81xq2u wx-print-filter",children:K.getPrintFilterValue(p,d,f)}):r.jsx("div",{className:"wx-Gy81xq2u wx-text",children:f.text??""})},f.id)})},c))})}function Bt(n){const{columns:e,rowStyle:t,columnStyle:l,cellStyle:a,header:p,footer:d,reorder:w}=n,u=o.useContext(Q),{flatData:g,_sizes:c}=u.getState(),f=p&&K.getHeaderFooterPrintColumns(e,"header",c.headerRowHeights),m=d&&K.getHeaderFooterPrintColumns(e,"footer",c.footerRowHeights);function j(i,y){let x="";return x+=l?" "+l(y):"",x+=a?" "+a(i,y):"",x}function S(i,y){return typeof y.draggable=="function"?y.draggable(i,y)!==!1:y.draggable}return r.jsxs("table",{className:`wx-8NTMLH0z wx-print-grid ${e.some(i=>i.flexgrow)?"wx-flex-columns":""}`,children:[p?r.jsx("thead",{children:r.jsx(ot,{columns:f,type:"header",columnStyle:l})}):null,r.jsx("tbody",{children:g.map((i,y)=>r.jsx("tr",{className:"wx-8NTMLH0z wx-row"+(t?" "+t(i):""),children:e.map(x=>x.collapsed?null:r.jsxs("td",{className:`wx-8NTMLH0z wx-print-cell wx-cell ${j(i,x)}`,style:A.styleObject(K.getPrintCellStyle(x,c.columnWidth)),children:[w&&x.draggable?r.jsx("span",{className:"wx-8NTMLH0z wx-print-draggable",children:S(i,x)?r.jsx("i",{className:"wx-8NTMLH0z wxi-drag"}):null}):null,x.treetoggle?r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{marginLeft:i.$level*28+"px"}}),i.$count?r.jsx("i",{className:`wx-8NTMLH0z wx-print-grid-tree-toggle wxi-menu-${i.open!==!1?"down":"right"}`}):null]}):null,x.cell?(()=>{const C=x.cell;return r.jsx(C,{api:u,row:i,column:x})})():r.jsx("span",{children:K.getRenderValue(i,x)})]},x.id))},y))}),d?r.jsx("tfoot",{children:r.jsx(ot,{columns:m,type:"footer",columnStyle:l})}):null]})}function Ut(n){const{config:e,...t}=n,l=o.useContext(Q),{_skin:a,_columns:p}=l.getState(),d=o.useMemo(()=>K.getPrintColumns(p,e),[]),w=o.useRef(null);return o.useEffect(()=>{const u=document.body;u.classList.add("wx-print");const g=w.current;if(!g)return;const c=g.cloneNode(!0);u.appendChild(c);const f=`@media print { @page { size: ${e.paper} ${e.mode}; }`,m=document.createElement("style");m.setAttribute("type","text/css"),m.setAttribute("media","print"),document.getElementsByTagName("head")[0].appendChild(m),m.appendChild(document.createTextNode(f)),window.print(),m.remove(),u.classList.remove("wx-print"),c.remove()},[]),r.jsx("div",{className:`wx-4zwCKA7C wx-${a}-theme wx-print-container`,ref:w,children:d.map((u,g)=>r.jsx("div",{className:"wx-4zwCKA7C wx-print-grid-wrapper",children:r.jsx(Bt,{columns:u,...t})},g))})}function Qt(n){const{header:e,footer:t,overlay:l,multiselect:a,reorder:p,onreorder:d,rowStyle:w,columnStyle:u,cellStyle:g,autoRowHeight:c,resize:f,clientWidth:m,clientHeight:j,responsiveLevel:S}=n,i=o.useContext(Q),y=A.useStore(i,"dynamic"),x=A.useStore(i,"_columns"),C=A.useStore(i,"flatData"),b=A.useStore(i,"split"),M=A.useStore(i,"_sizes"),[N,H]=A.useStoreWithCounter(i,"selectedRows"),v=A.useStore(i,"select"),P=A.useStore(i,"editor"),G=A.useStore(i,"tree"),q=A.useStore(i,"focusCell"),T=A.useStore(i,"_print"),Y=A.useStore(i,"undo"),[I,k]=o.useState(0);o.useEffect(()=>{k(pt())},[]);const[U,ye]=o.useState(0),[de,He]=o.useState(0),ee=o.useMemo(()=>(x||[]).some(s=>!s.hidden&&s.flexgrow),[x]),B=o.useMemo(()=>M?.rowHeight||0,[M]),O=o.useRef(null),[$e,ge]=o.useState(null),[se,Re]=o.useState(null),te=o.useMemo(()=>{let s=[],h=0;return b&&b.left&&(s=(x||[]).slice(0,b.left).filter(R=>!R.hidden).map(R=>({...R})),s.forEach(R=>{R.fixed={left:1},R.left=h,h+=R.width}),s.length&&(s[s.length-1].fixed={left:-1})),{columns:s,width:h}},[b,x]),ne=o.useMemo(()=>{let s=[],h=0;if(b&&b.right){s=(x||[]).slice(b.right*-1).filter(R=>!R.hidden).map(R=>({...R}));for(let R=s.length-1;R>=0;R--){const L=s[R];L.fixed={right:1},L.right=h,h+=L.width}s.length&&(s[0].fixed={right:-1})}return{columns:s,width:h}},[b,x]),F=o.useMemo(()=>{const s=(x||[]).slice(b?.left||0,(x||[]).length-(b?.right??0)).filter(h=>!h.hidden);return s.forEach(h=>{h.fixed=0}),s},[x,b]),D=o.useMemo(()=>(x||[]).reduce((s,h)=>(h.hidden||(s+=h.width),s),0),[x]),fe=1;function _(s,h,R){let L=h,V=s;if(F.length){let $=F.length;for(let E=s;E>=0;E--)F[E][R].forEach(J=>{J.colspan>1&&E>s-J.colspan&&E<$&&($=E)});if($!==F.length&&$<s){for(let E=$;E<s;E++)L-=F[E].width;V=$}}return{index:V,delta:L}}const z=o.useMemo(()=>{let s,h,R;const L=U,V=U+(m||0);let $=0,E=0,W=0,J=0;F.forEach((ae,be)=>{L>W&&($=be,J=W),W=W+ae.width,V>W&&(E=be+fe)});const ce={header:0,footer:0};for(let ae=E;ae>=$;ae--)["header","footer"].forEach(be=>{F[ae]&&F[ae][be].forEach(yt=>{const Fe=yt.colspan;if(Fe&&Fe>1){const Je=Fe-(E-ae+1);Je>0&&(ce[be]=Math.max(ce[be],Je))}})});const ve=_($,J,"header"),me=_($,J,"footer"),Ke=ve.delta,Se=ve.index,ke=me.delta,De=me.index;return ee&&D>(m||0)?s=h=R=[...te.columns,...F,...ne.columns]:(s=[...te.columns,...F.slice($,E+1),...ne.columns],h=[...te.columns,...F.slice(Se,E+ce.header+1),...ne.columns],R=[...te.columns,...F.slice(De,E+ce.footer+1),...ne.columns]),{data:s||[],header:h||[],footer:R||[],d:J,df:ke,dh:Ke}},[F,te,ne,U,m,ee,D]),re=o.useMemo(()=>e&&M?.headerHeight||0,[e,M]),xe=o.useMemo(()=>t&&M?.footerHeight||0,[t,M]),ue=o.useMemo(()=>m&&j?D>=m:!1,[m,j,D]),je=o.useMemo(()=>(j||0)-re-xe-(ue?I:0),[j,re,xe,ue,I]),Ye=o.useMemo(()=>Math.ceil((je||0)/(B||1))+1,[je,B]),Ae=o.useRef([]),[_e,ct]=o.useState(0),[Xe,at]=o.useState(void 0),Z=o.useMemo(()=>{let s=0,h=0;if(c){let V=de;for(;V>0;)V-=Ae.current[s]||B,s++;h=de-V;for(let $=Math.max(0,s-2-1);$<s;$++)h-=Ae.current[s-$]||B;s=Math.max(0,s-2)}else s=Math.floor(de/(B||1)),s=Math.max(0,s-2),h=s*(B||0);const R=y?y.rowCount:(C||[]).length,L=Math.min(R,s+(Ye||0)+2);return{d:h,start:s,end:L}},[c,de,B,y,C,Ye]),Ie=o.useMemo(()=>{const s=y?y.rowCount:(C||[]).length,h=s*(B||0);return c?_e+Z.d+(s-(Xe||0))*(B||0):h},[y,C,B,c,_e,Z.d,Xe]),le=o.useMemo(()=>m&&j?Ie+re+xe>=j-(D>=(m||0)?I:0):!1,[m,j,Ie,re,xe,D,I]),he=o.useMemo(()=>ee&&D<=(m||0)?(m||0)-0-(le?I:0):D,[ee,D,m,le,I,ue]),Ve=o.useMemo(()=>ee&&D<=(m||0)?m||0:he<(m||0)?D+(le?I:0):-1,[ee,D,m,he,le,I]),Pe=o.useRef({});o.useEffect(()=>{if(y&&(Pe.current.start!==Z.start||Pe.current.end!==Z.end)){const{start:s,end:h}=Z;Pe.current={start:s,end:h},i&&i.exec&&i.exec("request-data",{row:{start:s,end:h}})}},[y,Z,i]);const ie=o.useMemo(()=>y?C||[]:(C||[]).slice(Z.start,Z.end),[y,C,Z]),Ce=o.useMemo(()=>(N||[]).filter(s=>(ie||[]).some(h=>h.id===s)),[H,ie]),ze=o.useMemo(()=>Z.start,[Z.start]),ut=o.useCallback(s=>{He(s.target.scrollTop),ye(s.target.scrollLeft)},[]),dt=o.useCallback(s=>{s.shiftKey&&s.preventDefault(),O.current&&O.current.focus&&O.current.focus()},[]),Ge=o.useCallback(()=>!!(x||[]).find(s=>!!s.draggable),[x]),Oe=o.useRef(null),pe=o.useRef(null),ft=o.useRef({dblclick:(s,h)=>{const R={id:s,column:oe.locateAttr(h,"data-col-id")};i.exec("open-editor",R)},click:(s,h)=>{if(Oe.current)return;const R=oe.locateAttr(h,"data-col-id"),L=i.getState().focusCell;if((!L||L.row!==s||L.column!==R)&&i.exec("focus-cell",{row:s,column:R,eventSource:"click"}),v===!1)return;const V=a&&h.ctrlKey,$=a&&h.shiftKey,E=i.getState().selectedRows;(E.length!==1||E[0]!==s)&&v&&i.exec("select-row",{id:s,toggle:V,range:$})},"toggle-row":s=>{const h=i.getRow(s);i.exec(h.open!==!1?"close-row":"open-row",{id:s})},"ignore-click":()=>!1}),Me=o.useMemo(()=>({top:re,bottom:xe,left:te.width,xScroll:ue,yScroll:le,sense:c&&se?se.offsetHeight:Math.max(M?.rowHeight||0,40),node:O.current&&O.current.firstElementChild}),[re,xe,te.width,ue,le,c,se,M]);function xt(s,h){const{container:R,sourceNode:L,from:V}=h;if(Ge()&&!L.getAttribute("draggable-data"))return!1;ge(V),i.getRow(V).open&&i.exec("close-row",{id:V,nested:!0});const E=oe.locate(L,"data-id"),W=E.cloneNode(!0);W.classList.remove("wx-selected"),W.querySelectorAll("[tabindex]").forEach(me=>me.setAttribute("tabindex","-1")),R.appendChild(W),Re(W);const J=U-z.d,ce=le?I:0;R.style.width=Math.min((m||0)-ce,ee&&D<=(m||0)?he:he-ce)+J+"px";const ve=Le(E);h.offset={x:J,y:-Math.round(ve.height/2)},pe.current||(pe.current=s.clientY)}function ht(s,h){const{from:R}=h,L=h.pos,V=Le(O.current);L.x=V.x;const $=Me.top;if(L.y<$)L.y=$;else{const E=V.height-(ue&&I>0?I:Math.round(Me.sense/2))-Me.bottom;L.y>E&&(L.y=E)}if(O.current.contains(h.targetNode)){const E=oe.locate(h.targetNode,"data-id"),W=oe.id(E?.getAttribute("data-id"));if(W&&W!==R){h.to=W;const J=c?se?.offsetHeight:M?.rowHeight;if(de===0||L.y>$+J-1){const ce=E.getBoundingClientRect(),me=Le(se).y,Ke=ce.y,Se=me>Ke?-1:1,ke=Se===1?"after":"before",De=Math.abs(i.getRowIndex(R)-i.getRowIndex(W)),ae=De!==1?ke==="before"?"after":"before":ke;if(De===1&&(Se===-1&&s.clientY>pe.current||Se===1&&s.clientY<pe.current))return;pe.current=s.clientY,i.exec("move-item",{id:R,target:W,mode:ae,inProgress:!0})}}d&&d({event:s,context:h})}kt(s,V,h,Me)}function gt(s,h){const{from:R,to:L}=h;i.exec("move-item",{id:R,target:L,inProgress:!1}),Oe.current=setTimeout(()=>{Oe.current=0},1),ge(null),Re(null),pe.current=null,rt(h)}function pt(){const s=document.createElement("div");s.style.cssText="position:absolute;left:-1000px;width:100px;padding:0px;margin:0px;min-height:100px;overflow-y:scroll;",document.body.appendChild(s);const h=s.offsetWidth-s.clientWidth;return document.body.removeChild(s),h}const wt=o.useMemo(()=>Ve>0?{width:`${Ve}px`}:void 0,[Ve]),Be=o.useRef(null);function mt(){Promise.resolve().then(()=>{let s=0,h=ze;const R=Be.current;R&&(Array.from(R.children).forEach((L,V)=>{Ae.current[ze+V]=L.offsetHeight,s+=L.offsetHeight,h++}),ct(s),at(h))})}o.useEffect(()=>{ie&&c&&mt()},[ie,c,ze]);let[we,Ne]=o.useState();o.useEffect(()=>{if(q&&(!v||!Ce.length||Ce.includes(q.row)))Ne({...q});else if(ie.length&&z.data.length){if(!we||Ce.length&&!Ce.includes(we.row)||ie.findIndex(s=>s.id==we.row)===-1||z.data.findIndex(s=>s.id==we.column&&!s.collapsed)===-1){const s=Ce[0]||ie[0].id,h=z.data.findIndex(R=>!R.collapsed);Ne(h!==-1?{row:s,column:z.data[h].id}:null)}}else Ne(null)},[q]);const Ue=o.useRef(null);o.useEffect(()=>{const s=O.current;if(!s)return;const h=St(s,f);return()=>{typeof h=="function"&&h()}},[f]);const Qe=o.useRef({});Object.assign(Qe.current,{start:xt,move:ht,end:gt,getReorder:()=>p,getDraggableInfo:()=>({hasDraggable:Ge()})}),o.useEffect(()=>{const s=O.current;return s?Mt(s,Qe).destroy:void 0},[p,O.current]),o.useEffect(()=>{const s=O.current;return s?K.hotkeys(s,{keys:$t({undo:Y}),exec:R=>i.exec("hotkey",R)}).destroy:void 0},[i,Y]);const Ee=o.useRef({scroll:i.getReactiveState().scroll});Ee.current.getWidth=()=>(m||0)-(le?I:0),Ee.current.getHeight=()=>je,Ee.current.getScrollMargin=()=>te.width+ne.width,o.useEffect(()=>{K.scrollTo(Ue.current,Ee.current)},[]);const Ze=o.useRef(null);o.useEffect(()=>{const s=Ze.current;if(!s)return;const h=[];return h.push(oe.clickOutside(s,()=>i.exec("focus-cell",{eventSource:"click"})).destroy),h.push(A.delegateClick(s,ft.current)),()=>h.forEach(R=>R())},[]);const bt=`wx-grid ${S?`wx-responsive-${S}`:""}`;return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"wx-4VuBwK2D "+bt,style:{"--header-height":`${re}px`,"--footer-height":`${xe}px`,"--split-left-width":`${te.width}px`,"--split-right-width":`${ne.width}px`},children:r.jsx("div",{ref:O,className:"wx-4VuBwK2D wx-table-box",style:wt,role:G?"treegrid":"grid","aria-colcount":z.data.length,"aria-rowcount":ie.length,"aria-multiselectable":G&&a?!0:void 0,tabIndex:-1,children:r.jsxs("div",{ref:Ue,className:"wx-4VuBwK2D wx-scroll",style:{overflowX:ue?"scroll":"hidden",overflowY:le?"scroll":"hidden"},onScroll:ut,children:[e?r.jsx("div",{className:"wx-4VuBwK2D wx-header-wrapper",children:r.jsx(nt,{contentWidth:he,deltaLeft:z.dh,columns:z.header,columnStyle:u,bodyHeight:je-+t})}):null,r.jsxs("div",{ref:Ze,className:"wx-4VuBwK2D wx-body",style:{width:`${he}px`,height:`${Ie}px`},onMouseDown:s=>dt(s),children:[l?r.jsx(Ft,{overlay:l}):null,r.jsx("div",{ref:Be,className:"wx-4VuBwK2D wx-data",style:{paddingTop:`${Z.d}px`,paddingLeft:`${z.d}px`},children:ie.map((s,h)=>{const R=N.indexOf(s.id)!==-1,L=$e===s.id,V="wx-row"+(c?" wx-autoheight":"")+(w?" "+w(s):"")+(R?" wx-selected":"")+(L?" wx-inactive":""),$=c?{minHeight:`${B}px`}:{height:`${B}px`};return r.jsx("div",{className:"wx-4VuBwK2D "+V,"data-id":s.id,"data-context-id":s.id,style:$,role:"row","aria-rowindex":h,"aria-expanded":s.open,"aria-level":G?s.$level+1:void 0,"aria-selected":G?R:void 0,tabIndex:-1,children:z.data.map(E=>E.collapsed?r.jsx("div",{className:"wx-4VuBwK2D wx-cell wx-collapsed"},E.id):P?.id===s.id&&P.column==E.id?r.jsx(Gt,{row:s,column:E},E.id):r.jsx(At,{row:s,column:E,columnStyle:u,cellStyle:g,reorder:p,focusable:we?.row===s.id&&we?.column==E.id},E.id))},s.id)})})]}),t&&(C||[]).length?r.jsx(nt,{type:"footer",contentWidth:he,deltaLeft:z.df,columns:z.footer,columnStyle:u}):null]})})}),T?r.jsx(Ut,{config:T,rowStyle:w,columnStyle:u,cellStyle:g,header:e,footer:t,reorder:p}):null]})}const Zt=n=>n.split("-").map(e=>e?e.charAt(0).toUpperCase()+e.slice(1):"").join(""),Jt=o.forwardRef(function({data:e=[],columns:t=[],rowStyle:l=null,columnStyle:a=null,cellStyle:p=null,selectedRows:d,select:w=!0,multiselect:u=!1,header:g=!0,footer:c=!1,dynamic:f=null,overlay:m=null,reorder:j=!1,onReorder:S=null,autoRowHeight:i=!1,sizes:y,split:x,tree:C=!1,autoConfig:b=!1,init:M=null,responsive:N=null,sortMarks:H,undo:v=!1,...P},G){const q=o.useRef();q.current=P;const T=o.useMemo(()=>new K.DataStore(A.writable),[]),Y=o.useMemo(()=>T.in,[T]),I=o.useRef(null);I.current===null&&(I.current=new Ct.EventBusRouter((D,fe)=>{const _="on"+Zt(D);q.current&&q.current[_]&&q.current[_](fe)}),Y.setNext(I.current));const k=o.useMemo(()=>({getState:T.getState.bind(T),getReactiveState:T.getReactive.bind(T),getStores:()=>({data:T}),exec:Y.exec,setNext:D=>(I.current=I.current.setNext(D),I.current),intercept:Y.intercept.bind(Y),on:Y.on.bind(Y),detach:Y.detach.bind(Y),getRow:T.getRow.bind(T),getRowIndex:T.getRowIndex.bind(T),getColumn:T.getColumn.bind(T)}),[T,Y]),[U,ye]=o.useState(0),[de,He]=o.useState(0),[ee,B]=o.useState(null),[O,$e]=o.useState(null),ge=o.useMemo(()=>{if(b&&!t.length&&e.length){const D=e[0],fe=[];for(let _ in D)if(_!=="id"&&_[0]!=="$"){let z={id:_,header:_[0].toUpperCase()+_.slice(1)};typeof b=="object"&&(z={...z,...b}),fe.push(z)}return fe}return(O&&O.columns)??t},[b,t,e,O]),se=o.useMemo(()=>(O&&O.sizes)??y,[O,y]),Re=o.useCallback(D=>{if(ye(D.width),He(D.height),N){const _=Object.keys(N).map(Number).sort((z,re)=>z-re).find(z=>D.width<=z)??null;_!==ee&&($e(N[_]),B(_))}},[N,ee]),te=o.useMemo(()=>{let D=!C;return K.isCommunity()||(D=!0),D?j:!1},[C,j]),ne=o.useContext(X.context.theme),F=o.useRef(0);return o.useEffect(()=>{if(!F.current)M&&M(k);else{const D=T.getState();T.init({data:e,columns:ge,split:x||D.split,sizes:se||D.sizes,selectedRows:d||D.selectedRows,dynamic:f,tree:C,sortMarks:H||D.sortMarks,undo:v,_skin:ne,_select:w})}F.current++},[T,e,ge,x,se,d,f,C,H,v,ne,w,M,k]),F.current===0&&T.init({data:e,columns:ge,split:x||{left:0},sizes:se||{},selectedRows:d||[],dynamic:f,tree:C,sortMarks:H||{},undo:v,_skin:ne,select:w}),o.useImperativeHandle(G,()=>({...k}),[k]),r.jsx(Q.Provider,{value:k,children:r.jsx(X.Locale,{words:st.en,optional:!0,children:r.jsx(Qt,{header:g,footer:c,overlay:m,rowStyle:l,columnStyle:a,cellStyle:p,reorder:te,onReorder:S,multiselect:u,autoRowHeight:i,clientWidth:U,clientHeight:de,responsiveLevel:ee,resize:Re})})})});function en({item:n}){return r.jsxs("div",{tabIndex:-1,role:"menuitem","aria-label":n.hidden?`Show ${n.text} column`:`Hide ${n.text} column`,children:[r.jsx("div",{className:"wx-v13lZxja wx-icon"+(n.hidden?" wx-hidden":""),children:r.jsx("i",{className:"wx-v13lZxja wxi-eye"})}),r.jsx("span",{children:n.text})]})}function tn({columns:n=null,api:e,children:t}){o.useEffect(()=>{We.registerMenuItem("table-header",en)},[]);function l(u){for(let g=u.header.length-1;g>=0;g--){const c=u.header[g].text;if(c)return c}return u.id}function a(u){const g=u.action;g&&e.exec("hide-column",{id:g.id,mode:!g.hidden})}function p(u){return u}const d=A.useStoreLater(e,"_columns"),w=o.useMemo(()=>{if(e){const u=Array.isArray(d)?d:[];return(n?u.filter(c=>n[c.id]):u).map(c=>{const f=l(c);return{id:c.id,text:f,type:"table-header",hidden:c.hidden}})}else return[]},[e,n,d]);return r.jsx(We.ContextMenu,{dataKey:"headerId",options:w,onClick:a,at:"point",resolver:p,children:typeof t=="function"?t():t})}function nn(n){const{content:e=null,api:t,children:l}=n,a=o.useRef(null),p=o.useRef(null),[d,w]=o.useState(),[u,g]=o.useState(),[c,f]=o.useState();function m(b){for(;b;){if(b.getAttribute){const M=b.getAttribute("data-row-id"),N=b.getAttribute("data-col-id");if(M&&t&&N){const H=t.getColumn(N);return{id:M,col:H,target:b}}}b=b.parentNode}return{id:null,col:null,target:null}}o.useEffect(()=>{const b=p.current;if(b&&d&&c){let M=b.getBoundingClientRect(),N=c.left,H=c.top;M.right>=d.right&&(N=d.width-M.width-5),M.bottom>=d.bottom&&(H=c.top-(M.bottom-d.bottom+2)),(N!==c.left||H!==c.top)&&f({...c,left:N,top:H})}},[d,c]);const j=o.useRef(),S=300,i=b=>{clearTimeout(j.current),j.current=setTimeout(()=>{b()},S)};function y(b){const{id:M,target:N,col:H}=m(b.target);if(f(null),!M){clearTimeout(j.current);return}const v=b.clientX;i(()=>{let P="";if(M){const k=x(M);g(k),P=C(H)}const G=N.getBoundingClientRect(),q=a.current;if(!q)return;const T=q.getBoundingClientRect();w(T);const Y=G.top+G.height-T.top,I=v-T.left;f({top:Y,left:I,col:H,text:P})})}function x(b){return t.getRow(b)}function C(b){return typeof b.tooltip=="function"?b.tooltip(u):K.getRenderValue(u,b)||""}return r.jsxs("div",{className:"wx-RYccULtD wx-area",ref:a,onMouseMove:y,children:[c&&c.col.tooltip!==!1&&(e||c.text)?r.jsx("div",{className:"wx-RYccULtD tooltip",role:"alert",tabIndex:0,ref:p,style:{top:c.top+"px",left:c.left+"px"},children:e?r.jsx(e,{data:u}):c.text}):null,l]})}function on({api:n,options:e=K.defaultMenuOptions,at:t="point",resolver:l,dataKey:a,filter:p,css:d,children:w,handler:u,onClick:g}){const c=o.useContext(X.context.i18n),f=o.useMemo(()=>c?c.getGroup("grid"):oe.locale(st.en).getGroup("grid"),[c]),m=y=>y.map(x=>(x.text=f(x.text),x));function j(y){return y&&n.exec("select-row",{id:y}),y}const S=y=>{const x=y.action;if(x){const C=n.getState().selectedRows[0];switch(x.id){case"add:before":n.exec("add-row",{row:{},before:C});break;case"add:after":n.exec("add-row",{row:{},after:C});break;case"copy":n.exec("add-row",{row:{...n.getRow(C),id:null},after:C});break;case"delete":n.exec("delete-row",{id:C});break;default:g(y)}}},i=l!==void 0?l:j;return r.jsx(We.ContextMenu,{css:`wx-KKGLK8TH wx-table-menu ${d}`,at:t,dataKey:a,handler:u,options:m(e),resolver:i,filter:p,onClick:S,children:w})}function sn({fonts:n=!0,children:e}){return e?r.jsx(X.Material,{fonts:n,children:e}):r.jsx(X.Material,{fonts:n})}function rn({fonts:n=!0,children:e}){return e?r.jsx(X.Willow,{fonts:n,children:e}):r.jsx(X.Willow,{fonts:n})}function ln({fonts:n=!0,children:e}){return e?r.jsx(X.WillowDark,{fonts:n,children:e}):r.jsx(X.WillowDark,{fonts:n})}oe.setEnv(vt.env);Object.defineProperty(exports,"defaultMenuOptions",{enumerable:!0,get:()=>K.defaultMenuOptions});Object.defineProperty(exports,"getEditorConfig",{enumerable:!0,get:()=>K.getEditorConfig});exports.ContextMenu=on;exports.Grid=Jt;exports.HeaderMenu=tn;exports.Material=sn;exports.Tooltip=nn;exports.Willow=rn;exports.WillowDark=ln;