UNPKG

e-virt-table

Version:

A powerful data table based on canvas. You can use it as data grid、Microsoft Excel or Google sheets. It supports virtual scroll、cell edit etc.

4 lines 195 kB
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(":root{--evt-header-font: 12px normal Arial;--evt-body-font: 12px normal Arial;--evt-color-white: #fff;--evt-color-black: #000000;--evt-color-primary: rgb(82, 146, 247);--evt-text-color-primary: #333;--evt-text-color-regular: #666;--evt-text-color-secondary: #999;--evt-box-shadow: 0 2px 12px 0 #0000001a;--evt-editor-bg-color: #fff;--evt-editor-text-color: #333;--evt-border-color: #e1e6eb;--evt-stripe-color: #fafafa;--evt-placeholder-color: #cdd0dc;--evt-header-bg-color: #f8faff;--evt-body-bg-color: #fff;--evt-header-text-color: #1d2129;--evt-body-text-color: #4e5969;--evt-footer-text-color: #4e5969;--evt-loading-icon-color: #4e5969;--evt-expand-icon-color: #4e5969;--evt-shrink-icon-color: #4e5969;--evt-error-tip-icon-color: red;--evt-required-color: #F56C6C;--evt-cell-hover-icon-bg-color: #fff;--evt-cell-hover-icon-border-color: #dde0ea;--evt-scroller-color: #dee0e3;--evt-scroller-track-color: #fff;--evt-scroller-focus-color: #bbbec4;--evt-select-border-color: var(--evt-color-primary);--evt-select-area-color: rgba(82, 146, 247, .1);--evt-select-row-col-bg-color: transparent;--evt-autofill-point-border-color: #fff;--evt-edit-bg-color: #fcf6ed;--evt-checkbox-color: var(--evt-color-primary);--evt-checkbox-uncheck-color: #dde0ea;--evt-checkbox-disabled-color: #f1f2f4;--evt-checkbox-check-disabled-color: #dde0ea;--evt-icon-edit-color: #4e5969;--evt-icon-select-color: #4e5969;--evt-readonly-color: #fff;--evt-readonly-text-color: var(--evt-body-text-color);--evt-error-tip-color: #ed3f14;--evt-footer-bg-color: #fafafa;--evt-highlight-hover-row-color: rgba(186, 203, 231, .1);--evt-highlight-selected-row-color: rgba(82, 146, 247, .1);--evt-tooltip-bg-color: #303133;--evt-tooltip-text-color: #fff;--evt-resize-row-line-color: #e1e6eb;--evt-resize-column-line-color: #e1e6eb;--evt-tree-line-color: #e1e6eb;--evt-sort-icon-color: rgb(82, 146, 247)}.dark{--evt-border-color: #363637;--evt-header-bg-color: #141414;--evt-body-bg-color: #141414;--evt-header-text-color: #a3a6ad;--evt-scroller-color: #414243;--evt-scroller-track-color: #141414;--evt-scroller-focus-color: #a3a6ad;--evt-edit-bg-color: #141414;--evt-readonly-text-color: #cfd3dc;--evt-footer-bg-color: #262727;--evt-autofill-point-border-color: #fff;--evt-editor-bg-color: #434343;--evt-editor-text-color: #cfd3dc}.e-virt-table-container{position:relative;outline:none}.e-virt-table-stage{position:relative;overflow:hidden;outline:none;box-sizing:border-box;z-index:10;border-radius:8px;border:1px solid var(--evt-border-color)}.e-virt-table-canvas{position:absolute;left:0;top:0;box-sizing:border-box;border:none;outline:none;z-index:10}.e-virt-table-editor{position:absolute;top:-10000px;left:-10000px;text-align:left;height:auto;line-height:0;z-index:100;overflow:hidden;background-color:var(--evt-editor-bg-color);border:2px solid var(--evt-color-primary);box-sizing:border-box;box-shadow:var(--evt-box-shadow);display:flex;align-items:center}.e-virt-table-overlayer{position:absolute;left:0;top:0;overflow:hidden;z-index:100;pointer-events:none}.e-virt-table-editor-textarea{width:100%;box-sizing:border-box;outline:none;font-weight:400;padding:8px;font-size:12px;color:inherit;white-space:pre-wrap;word-wrap:break-word;word-break:break-all;line-height:1.5;margin:0;border:none;vertical-align:middle;background:var(--evt-editor-bg-color);color:var(--evt-editor-text-color);overflow-y:auto;resize:none}.e-virt-table-context-menu{position:absolute;font-size:14px;color:var(--evt-text-color-regular);background-color:var(--evt-color-white);border-radius:4px;border:1px solid #e4e7ed;box-shadow:var(--evt-box-shadow);width:fit-content;padding:6px 0;z-index:9999;left:-99999px;top:-99999px}.e-virt-table-context-menu-item{cursor:pointer;padding:8px 24px;color:var(--evt-text-color-regular)}.e-virt-table-context-menu-item:hover{color:var(--evt-color-primary);background-color:#f5f7fa}.e-virt-table-loading{display:none;position:absolute;left:0;top:0;right:0;bottom:0;width:100%;height:100%;z-index:2000;background-color:#fff6;display:flex;align-items:center;justify-content:center}.e-virt-table-loading-spinner{opacity:1;display:flex;flex-direction:column;align-items:center;justify-content:center}.e-virt-table-loading-spinner svg{color:var(--evt-text-color-regular);animation:rotate 1s linear infinite}@keyframes rotate{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.e-virt-table-loading-text{margin:0;font-size:12px;color:var(--evt-text-color-regular)}")),document.head.appendChild(e)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})(); (function(X,D){typeof exports=="object"&&typeof module<"u"?module.exports=D():typeof define=="function"&&define.amd?define(D):(X=typeof globalThis<"u"?globalThis:X||self,X.EVirtTable=D())})(this,function(){"use strict";var Ii=Object.defineProperty;var Si=(X,D,F)=>D in X?Ii(X,D,{enumerable:!0,configurable:!0,writable:!0,value:F}):X[D]=F;var n=(X,D,F)=>Si(X,typeof D!="symbol"?D+"":D,F);class X{constructor(t){n(this,"rules");this.rules=t}validate(t){const e=[],{column:i,row:s,key:o,rowKey:r,colIndex:a,rowIndex:l,value:h,field:d,fieldValue:f}=t;Array.isArray(this.rules)||(this.rules=[this.rules]);for(const u of this.rules){if(u.validator){const x={field:d,fieldValue:f,value:h,column:i,colIndex:a,rowIndex:l,row:s,key:o,rowKey:r,...u};u.validator(x,h,w=>{w&&e.push({...x,message:w})})}if(!u.required&&(h==null||h===""))return e;u.pattern&&!u.pattern.test(h)&&e.push({value:h,column:i,row:s,key:o,rowKey:r,colIndex:a,rowIndex:l,field:d,fieldValue:f,message:u.message||`${o} is pattern validation error`}),u.required&&(h==null||h==="")&&e.push({value:h,column:i,row:s,key:o,rowKey:r,colIndex:a,rowIndex:l,field:d,fieldValue:f,message:u.message||`${o} is required`})}return e}}function D(){return"xxxxxxxxxxxxxxxxxx".replace(/[x]/g,function(c){const t=Math.random()*16|0;return(c==="x"?t:t&3|8).toString(16)})}function F(c,t){let e=0,i;return function(...s){const o=new Date().getTime(),r=o-e,a=typeof t=="function"?t():t;!e||r>=a?(c.apply(this,s),e=o):i||(i=setTimeout(()=>{c.apply(this,s),e=new Date().getTime(),i=void 0},a-r))}}function Rt(c=[]){return c.length?c.map(t=>Rt(t.children)+1).sort((t,e)=>e-t)[0]:0}function oe(c=[]){let t=[],e=[],i=[];return c.forEach(s=>{s.fixed==="left"?t.push(s):s.fixed==="right"?i.push(s):e.push(s)}),[...t.sort((s,o)=>(s.sort??0)-(o.sort??0)),...e.sort((s,o)=>(s.sort??0)-(o.sort??0)),...i.sort((s,o)=>(s.sort??0)-(o.sort??0))]}function It(c=[],t=1,e=0){return c.map(i=>{if(i.children){let s=0,o=i.fixed;i.children.forEach(a=>{a.fixed=o});const r=It(i.children,t-1,e+1);return r&&r.forEach(a=>{s+=a.colspan??0}),{...i,width:i.width,level:e,rowspan:1,colspan:s,children:r}}return{...i,level:e,rowspan:t,colspan:1}})}function ot(c=[]){let t=[];return c.forEach(e=>{e.children?t=t.concat(ot(e.children)):t.push(e)}),t}const St=/^(\r\n|\n\r|\r|\n)/,re=/^[^\t\r\n]+/,_t=/^\t/;function ne(c){let t=[[""]];if(c.length===0)return t;let e=0,i=0,s;for(;c.length>0&&s!==c.length;)if(s=c.length,c.match(_t))c=c.replace(_t,""),e+=1,t[i][e]="";else if(c.match(St))c=c.replace(St,""),e=0,i+=1,t[i]=[""];else{let o="";if(c.startsWith('"')){let r=0,a=!0;for(;a;){const l=c.slice(0,1);l==='"'&&(r+=1),o+=l,c=c.slice(1),(c.length===0||c.match(/^[\t\r\n]/)&&r%2===0)&&(a=!1)}o=o.replace(/^"/,"").replace(/"$/,"").replace(/["]*/g,l=>new Array(Math.floor(l.length/2)).fill('"').join(""))}else{const r=c.match(re);o=r?r[0]:"",c=c.slice(o.length)}t[i][e]=o}return Array.isArray(t)&&t.length>1&&t[t.length-1].length===1&&t[t.length-1][0]===""&&(t=t.slice(0,t.length-1)),t}function ae(c){let t,e,i,s,o="",r;for(t=0,e=c.length;t<e;t+=1){for(s=c[t].length,i=0;i<s;i+=1)i>0&&(o+=" "),r=c[t][i],typeof r=="string"?r.indexOf(` `)>-1?o+=`"${r.replace(/"/g,'""')}"`:o+=r:r==null?o+="":o+=r;t!==e-1&&(o+=` `)}return o}function vt(c,t,e=[]){let i=0;const s=[];return c.forEach((o,r)=>{if(r===0)s.push(1);else{const a=e.reduce((h,d)=>`${h}${o[d]??""}`,"")||o[t],l=e.reduce((h,d)=>`${h}${c[r-1][d]??""}`,"")||c[r-1][t];a===l?(s[i]+=1,s.push(0)):(s.push(1),i=r)}}),s}function Tt(c,t){let e="",i="";const s={};return t.forEach((o,r)=>{r===0?(e=o.key,i=o.key,s[o.key]=1):c[o.key]===c[e]?(s[o.key]=0,s[i]+=1):(s[o.key]=1,e=o.key,i=o.key)}),s}function le(c,t,e=[]){const{visibleRows:i,rowIndex:s,headIndex:o}=c,r=vt(i,t,e);return r[s-o]===0?{rowspan:0,colspan:0,relationRowKeys:e,mergeRow:!0}:{rowspan:r[s-o],colspan:1,relationRowKeys:e,mergeRow:!0}}function he(c,t=[]){const{column:e,row:i,visibleLeafColumns:s}=c,o=s.filter(r=>t.includes(r.key));if(t.includes(e.key)){const r=Tt(i,o);return r[e.key]===0?{rowspan:0,colspan:0,relationColKeys:t,mergeCol:!0}:{rowspan:1,colspan:r[e.key],relationColKeys:t,mergeCol:!0}}}function ce(c,t=document.documentElement){const e=c.startsWith("--")?c:`--${c}`;return getComputedStyle(t).getPropertyValue(e).trim()}function Ot(c){if(!c)return new Date(0);if(typeof c=="number")return new Date(c);const t=String(c).trim(),e=new Date(t);if(!isNaN(e.getTime()))return e;const i=[/^(\d{4})-(\d{1,2})-(\d{1,2})$/,/^(\d{4})\/(\d{1,2})\/(\d{1,2})$/,/^(\d{4})\.(\d{1,2})\.(\d{1,2})$/,/^(\d{1,2})-(\d{1,2})-(\d{4})$/,/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/,/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/,/^(\d{1,2})-(\d{1,2})-(\d{4})$/,/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/,/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/,/^(\d{4})(\d{2})(\d{2})$/,/^(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?$/,/^(\d{4})\/(\d{1,2})\/(\d{1,2})\s+(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?$/];for(const s of i){const o=t.match(s);if(o){const r=o.slice(1).map(Number);if(s.source.includes("YYYY-MM-DD")||s.source.includes("YYYY/MM/DD")||s.source.includes("YYYY.MM.DD")){const[a,l,h,d=0,f=0,u=0]=r;return new Date(a,l-1,h,d,f,u)}else if(s.source.includes("DD-MM-YYYY")||s.source.includes("DD/MM/YYYY")||s.source.includes("DD.MM.YYYY")){const[a,l,h,d=0,f=0,u=0]=r;return new Date(h,l-1,a,d,f,u)}else if(s.source.includes("MM-DD-YYYY")||s.source.includes("MM/DD/YYYY")||s.source.includes("MM.DD.YYYY")){const[a,l,h,d=0,f=0,u=0]=r;return new Date(h,a-1,l,d,f,u)}else if(s.source.includes("YYYYMMDD")){const[a,l,h]=r;return new Date(a,l-1,h)}}}return new Date(NaN)}function de(c,t){const e=Ot(c),i=Ot(t);return isNaN(e.getTime())&&isNaN(i.getTime())?0:isNaN(e.getTime())?-1:isNaN(i.getTime())?1:e.getTime()-i.getTime()}class Lt{constructor(t,e,i,s,o,r,a){n(this,"ctx");n(this,"x",0);n(this,"y",0);n(this,"width",0);n(this,"height",0);n(this,"fixed");n(this,"cellType");this.ctx=t,this.x=e,this.y=i,this.width=s,this.height=o,this.fixed=a,this.cellType=r}isHorizontalVisible(){if(this.fixed)return!0;const{stageWidth:t,fixedLeftWidth:e,scrollX:i,fixedRightWidth:s}=this.ctx,o=t;return!(this.x+this.width-e-i<=0||this.x-i>=o-s)}isVerticalVisible(){const{stageHeight:t,scrollY:e}=this.ctx,i=t;return!(this.y+this.height-e<=0||this.y-e>=i)}getDrawX(){if(this.fixed==="left")return this.x;if(this.fixed==="right"){const{stageWidth:t,config:{SCROLLER_TRACK_SIZE:e}}=this.ctx;return t-(this.ctx.header.width-this.x)-e}return this.x-this.ctx.scrollX}getDrawY(){return this.cellType==="header"?this.y:this.cellType==="footer"&&this.ctx.config.FOOTER_FIXED?this.y:this.y-this.ctx.scrollY}getLeftFixedX(){return this.x-this.ctx.scrollX}getRightFixedX(){}}class dt extends Lt{constructor(e,i,s,o,r,a,l,h,d,f="body"){super(e,o,r,a,l,f,h.fixed);n(this,"formatter");n(this,"formatterFooter");n(this,"hoverIconName","");n(this,"operation",!1);n(this,"align");n(this,"verticalAlign");n(this,"fixed");n(this,"type");n(this,"editorType");n(this,"editorProps");n(this,"cellType");n(this,"level");n(this,"colspan",1);n(this,"rowspan",1);n(this,"mergeRow",!1);n(this,"mergeCol",!1);n(this,"relationRowKeys",[]);n(this,"relationColKeys",[]);n(this,"key");n(this,"column");n(this,"rowIndex");n(this,"colIndex");n(this,"rowKey");n(this,"row");n(this,"value");n(this,"render");n(this,"renderFooter");n(this,"style",{});n(this,"domDataset",{});n(this,"rules",[]);n(this,"message","");n(this,"text","");n(this,"displayText","");n(this,"visibleWidth",0);n(this,"visibleHeight",0);n(this,"isHasChanged",!1);n(this,"drawX",0);n(this,"drawY",0);n(this,"drawCellBgColor","");n(this,"drawCellSkyBgColor","");n(this,"drawTextColor","");n(this,"drawTextFont","");n(this,"drawTextX",0);n(this,"drawTextY",0);n(this,"drawTextWidth",0);n(this,"drawTextHeight",0);n(this,"drawTreeImageX",0);n(this,"drawTreeImageY",0);n(this,"drawTreeImageWidth",0);n(this,"drawTreeImageHeight",0);n(this,"drawTreeImageName","");n(this,"drawTreeImageSource");n(this,"drawSelectionImageX",0);n(this,"drawSelectionImageY",0);n(this,"drawSelectionImageWidth",0);n(this,"drawSelectionImageHeight",0);n(this,"drawSelectionImageName","");n(this,"drawSelectionImageSource");n(this,"drawHoverImageX",0);n(this,"drawHoverImageY",0);n(this,"drawHoverImageWidth",0);n(this,"drawHoverImageHeight",0);n(this,"drawHoverImageName","");n(this,"drawHoverImageSource");n(this,"autoRowHeight",!1);n(this,"calculatedHeight",0);n(this,"ellipsis",!1);n(this,"rowExpand",!1);n(this,"rowHasChildren",!1);n(this,"overflowTooltipShow",!0);n(this,"selectorCellValueType","value");n(this,"overflowTooltipMaxWidth",500);n(this,"overflowTooltipPlacement","top");n(this,"maxLineClamp","auto");this.visibleWidth=this.width,this.visibleHeight=this.height,this.colIndex=s,this.rowIndex=i,this.key=h.key,this.type=h.type||"",this.editorType=h.editorType||"text",this.selectorCellValueType=h.selectorCellValueType||this.ctx.config.SELECTOR_CELL_VALUE_TYPE||"value",this.editorProps=h.editorProps||{},this.cellType=f,this.align=h.align||this.ctx.config.COLUMNS_ALIGN,this.verticalAlign=h.verticalAlign||this.ctx.config.COLUMNS_VERTICAL_ALIGN,this.fixed=h.fixed,this.level=h.level||0,this.operation=h.operation||!1,this.column=h,this.rules=h.rules||[],this.row=d,this.rowKey=this.cellType==="body"?this.ctx.database.getRowKeyForRowIndex(i):`${this.cellType}_${this.rowIndex}`,this.value=this.getValue(),this.render=h.render,this.overflowTooltipShow=h.overflowTooltipShow!==!1,this.autoRowHeight=h.autoRowHeight!==void 0?h.autoRowHeight:this.ctx.config.AUTO_ROW_HEIGHT,this.overflowTooltipMaxWidth=h.overflowTooltipMaxWidth||500,this.overflowTooltipPlacement=h.overflowTooltipPlacement||"top",this.renderFooter=h.renderFooter,this.hoverIconName=h.hoverIconName,this.formatter=h.formatter,this.formatterFooter=h.formatterFooter,this.maxLineClamp=h.maxLineClamp||"auto",this.update()}setWidthHeight(e,i){this.width=e,this.height=i}getValidationMessage(){const e=this.ctx.database.getValidationError(this.rowKey,this.key);if(Array.isArray(e)&&e.length){const[i]=e;this.message=i.message||""}return this.message}update(){this.drawX=this.getDrawX(),this.drawY=this.getDrawY(),this.drawTextX=this.drawX,this.drawTextY=this.drawY,this.isHasChanged=this.ctx.database.isHasChangedData(this.rowKey,this.key),this.updateSpan(),this.drawTextWidth=this.visibleWidth,this.drawTextHeight=this.visibleHeight,this.updateStyle(),this.updateType(),this.updateHoverIcon(),this.updateSelection(),this.updateTree(),this.updateEditor(),this.updateRender(),this.getValidationMessage(),this.updateContainer(),this.text=this.getText(),this.displayText=this.getDisplayText()}updateSpan(){if(this.cellType==="footer")return;const{SPAN_METHOD:e}=this.ctx.config;if(typeof e=="function"){const i=e,{colspan:s=1,rowspan:o=1,relationRowKeys:r,relationColKeys:a,mergeRow:l=!1,mergeCol:h=!1}=i({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue(),headIndex:this.ctx.body.headIndex,headPosition:this.ctx.database.getPositionForRowIndex(this.ctx.body.headIndex),visibleRows:this.ctx.body.visibleRows,visibleLeafColumns:this.ctx.header.visibleLeafColumns,rows:this.ctx.body.data})||{};Array.isArray(r)&&r.length>0?this.relationRowKeys=r:this.relationRowKeys=[this.key],Array.isArray(a)&&a.length>0?this.relationColKeys=a:this.relationColKeys=[this.key],this.mergeCol=h,this.mergeRow=l,this.colspan=s,this.rowspan=o,this.visibleWidth=this.getWidthByColIndexColSpan(this.colIndex,this.colspan),this.visibleHeight=this.ctx.database.getHeightByRowIndexRowSpan(this.rowIndex,this.rowspan)}}updateSpanInfo(){if(this.mergeRow||this.mergeCol){const e=this.getSpanInfo();this.height=e.height,this.width=e.width,this.drawX=this.getDrawX(),this.drawY=this.getDrawY(),this.drawY-=e.offsetTop,this.drawX-=e.offsetLeft}}updateType(){const{BODY_CELL_TYPE_METHOD:e}=this.ctx.config;if(typeof e=="function"){const s=e({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()});s!==void 0&&(this.type=s)}}updateEditor(){const{BODY_CELL_EDITOR_METHOD:e}=this.ctx.config;if(typeof e=="function"){const s=e({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()});if(s!==void 0){const{type:o,props:r={}}=s;this.editorType=o,this.editorProps=r}}}updateRender(){const{BODY_CELL_RENDER_METHOD:e}=this.ctx.config;if(typeof e=="function"){const s=e({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()});s!==void 0&&(this.render=s)}}validate(){this.ctx.database.getValidator(this.rowKey,this.key).then(()=>{this.ctx.database.setValidationError(this.rowKey,this.key,[]),this.message=""}).catch(e=>{if(Array.isArray(e)&&e.length){const[i]=e;this.message=i.message,this.ctx.database.setValidationError(this.rowKey,this.key,e)}}).finally(()=>{this.ctx.emit("draw")})}updateStyle(){this.autoRowHeight&&(this.domDataset={"data-auto-height":!0,"data-row-index":this.rowIndex,"data-col-index":this.colIndex}),this.style=this.getOverlayerViewsStyle()}updateTree(){const{CELL_PADDING:e=0}=this.ctx.config,{rowKey:i,cellType:s}=this;let o,r=0,a="";if(!(["tree","selection-tree","tree-selection"].includes(this.type)&&s==="body"))return;const l=this.ctx.database.getRowForRowKey(i),{expand:h=!1,hasChildren:d=!1,expandLoading:f=!1,level:u=0}=l||{};this.rowExpand=h,this.rowHasChildren=d;const{TREE_INDENT:x=16,CHECKBOX_SIZE:w,TREE_ICON_SIZE:m}=this.ctx.config;if(r=u*x,f){const I=this.ctx.icons.get("loading");a="loading",o=I}else if(d){const I=this.ctx.icons.get("expand"),_=this.ctx.icons.get("shrink");o=h?_:I,a=h?"shrink":"expand"}let g=m,E=m,y=this.drawX;(this.align==="center"||this.align==="right")&&(y=this.drawX+(this.visibleWidth-g-2*e)/2,this.align="left");let p=y+r+e,b=this.drawY+(this.visibleHeight-E)/2,C=r+this.drawX+g-.5;this.type==="selection-tree"?(p=r+this.drawSelectionImageX+this.drawSelectionImageWidth,C=p+g-e/2):this.type==="tree-selection"?C=p+w+g-e/2:C=p+g-e/2,this.drawTextX=C,this.drawTextWidth=this.drawX+this.visibleWidth-C,!(p+g+e>this.drawX+this.visibleWidth)&&(b+E+e>this.drawY+this.visibleHeight||(this.drawTreeImageX=p,this.drawTreeImageY=b,this.drawTreeImageWidth=g,this.drawTreeImageHeight=E,o?(this.drawTreeImageName=a,this.drawTreeImageSource=o):(this.drawTreeImageName="",this.drawTreeImageSource=void 0)))}drawTreeLine(){const{TREE_LINE:e,TREE_INDENT:i=16,TREE_ICON_SIZE:s=16,TREE_LINE_COLOR:o="#e1e6eb"}=this.ctx.config;if(!e||this.cellType!=="body"||!["tree","selection-tree","tree-selection"].includes(this.type)||this.rowspan===0||this.colspan===0)return;const r=this.ctx.database.getRowForRowKey(this.rowKey)||{},a=r.level??0,l=this.drawTreeImageX+this.drawTreeImageWidth/2,h=this.drawTreeImageY+this.drawTreeImageHeight/2;let d=this.drawTreeImageX-a*i;const f=Array.isArray(r.parentRowKeys)?r.parentRowKeys:[];if(a>0){for(let g=0;g<a-1;g+=1){const E=f[g+1];if(!!(E?this.ctx.database.getRowForRowKey(E)||{}:{}).isLastChild)continue;const b=Math.round(this.drawTreeImageX-(a-g)*i+s/2);this.ctx.paint.drawLine([b,this.drawY,b,this.drawY+this.visibleHeight],{borderColor:o,borderWidth:1,lineDash:[4,4],lineDashOffset:0})}const u=Math.round(this.drawTreeImageX-i+s/2),w=!!r.isLastChild?h:this.drawY+this.visibleHeight;this.ctx.paint.drawLine([u,this.drawY,u,w],{borderColor:o,borderWidth:1,lineDash:[4,4],lineDashOffset:0});const m=Math.round(d+(a-1)*i+s/2);this.ctx.paint.drawLine([m,h,l,h],{borderColor:o,borderWidth:1,lineDash:[4,4],lineDashOffset:0})}if(r.hasChildren&&r.expand){const u=this.drawTreeImageY+this.drawTreeImageHeight,x=this.drawY+this.visibleHeight;this.ctx.paint.drawLine([l,u,l,x],{borderColor:o,borderWidth:1,lineDash:[4,4],lineDashOffset:0})}}updateContainer(){const{BODY_BG_COLOR:e,EDIT_BG_COLOR:i,BODY_CELL_STYLE_METHOD:s,FOOTER_CELL_STYLE_METHOD:o,READONLY_TEXT_COLOR:r,BODY_TEXT_COLOR:a,FOOTER_TEXT_COLOR:l,FOOTER_BG_COLOR:h,HIGHLIGHT_SELECTED_ROW:d,HIGHLIGHT_SELECTED_ROW_COLOR:f,HIGHLIGHT_HOVER_ROW:u,HIGHLIGHT_HOVER_ROW_COLOR:x,STRIPE:w,STRIPE_COLOR:m}=this.ctx.config;if(this.cellType==="footer"){let _=h,T=l;if(typeof o=="function"){const S=o,{backgroundColor:R,color:v,font:O}=S({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()})||{};R&&(_=R),v&&(T=v),O&&(this.drawTextFont=O)}this.drawCellSkyBgColor="transparent",this.drawCellBgColor=_,this.drawTextColor=T;return}let g="transparent";const E=this.ctx.hoverCell,y=this.ctx.currentCell;let p=this.rowIndex,b=this.rowIndex;if(this.rowspan!==1&&(u||d)){const _=this.getSpanInfo(),{yArr:T}=_;p=T[0],b=T[1]}u&&E&&(E.rowKey===this.rowKey&&(g=x),E.rowIndex>=p&&E.rowIndex<=b&&(g=x)),d&&y&&(y.rowKey===this.rowKey&&(g=f),y.rowIndex>=p&&y.rowIndex<=b&&(g=f)),this.drawCellSkyBgColor=g;let C=e,I=a;if(this.ctx.database.getReadonly(this.rowKey,this.key)||(C=i,I=r),w&&(this.rowIndex%2?C=m:C=e),typeof s=="function"){const _=s,{backgroundColor:T,color:S,font:R}=_({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,isHasChanged:this.isHasChanged,value:this.getValue()})||{};T&&(C=T),S&&(I=S),R&&(this.drawTextFont=R)}this.drawCellBgColor=C,this.drawTextColor=I}updateSelection(){const{visibleWidth:e,visibleHeight:i,rowspan:s,colspan:o,cellType:r,type:a,rowIndex:l,rowKey:h}=this;if(s===0||o===0||r==="footer"||!["index-selection","selection","selection-tree","tree-selection"].includes(a))return;const d=this.ctx.database.getRowSelectable(h),{CHECKBOX_SIZE:f=0,CELL_PADDING:u}=this.ctx.config;let x=this.drawX+u;(this.align==="center"||this.align==="right")&&(x=this.drawX+(e-f)/2);let w=x,m=this.drawY+(i-f)/2;if(a!=="selection-tree"){if(a==="tree-selection"){const{TREE_INDENT:y=16,TREE_ICON_SIZE:p}=this.ctx.config,b=this.ctx.database.getRowForRowKey(h),{level:C=0}=b||{},I=C*y;w=x+p+I}}let g=this.ctx.icons.get("checkbox-uncheck"),E="checkbox-uncheck";if(a==="selection-tree"||a==="tree-selection"){const y=this.ctx.database.getTreeSelectionState(h);y.indeterminate&&d?(g=this.ctx.icons.get("checkbox-indeterminate"),E="checkbox-indeterminate"):y.checked&&d?(g=this.ctx.icons.get("checkbox-check"),E="checkbox-check"):!y.checked&&d?(g=this.ctx.icons.get("checkbox-uncheck"),E="checkbox-uncheck"):(g=this.ctx.icons.get("checkbox-disabled"),E="checkbox-disabled")}else{const y=this.ctx.database.getRowSelection(h);y&&d?(g=this.ctx.icons.get("checkbox-check"),E="checkbox-check"):y&&!d?(g=this.ctx.icons.get("checkbox-check-disabled"),E="checkbox-check-disabled"):!y&&d?(g=this.ctx.icons.get("checkbox-uncheck"),E="checkbox-uncheck"):(g=this.ctx.icons.get("checkbox-disabled"),E="checkbox-disabled")}w+f+u>this.drawX+this.visibleWidth||m+f+u>this.drawY+this.visibleHeight||(a==="index-selection"?(this.ctx.hoverCell&&this.ctx.hoverCell.rowIndex===l||["checkbox-disabled","checkbox-check"].includes(E))&&(this.drawSelectionImageX=w,this.drawSelectionImageY=m,this.drawSelectionImageWidth=f,this.drawSelectionImageHeight=f,this.drawSelectionImageName=E,this.drawSelectionImageSource=g):(this.drawSelectionImageX=w,this.drawSelectionImageY=m,this.drawSelectionImageWidth=f,this.drawSelectionImageHeight=f,this.drawSelectionImageName=E,this.drawSelectionImageSource=g))}updateHoverIcon(){if(this.ctx.database.getReadonly(this.rowKey,this.key))return;const{BODY_CELL_HOVER_ICON_METHOD:i,CELL_HOVER_ICON_SIZE:s,CELL_PADDING:o,ENABLE_MERGE_CELL_LINK:r}=this.ctx.config;if(typeof i=="function"){const h=i({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()});h!==void 0&&(this.hoverIconName=h)}const{hoverCell:a}=this.ctx;if(this.hoverIconName&&!this.ctx.editing&&a){let l=0,h=0;if(a.rowKey===this.rowKey&&(l=this.drawX+this.width-s-o,h=this.drawY+(this.height-s)/2),this.rowspan!==1&&r){const f=this.getSpanInfo(),{yArr:u}=f,x=u[0],w=u[1];if(a.rowIndex>=x&&a.rowIndex<=w){const{width:m,height:g,offsetTop:E,offsetLeft:y}=f;l=this.drawX-y+m-s-o,h=this.drawY-E+(g-s)/2}}const d=this.ctx.icons.get(this.hoverIconName);this.drawHoverImageX=l,this.drawHoverImageY=h,this.drawHoverImageWidth=s,this.drawHoverImageHeight=s,this.drawHoverImageName=this.hoverIconName,this.drawHoverImageSource=d}}getAutoHeight(){if(this.cellType!=="body"||!this.autoRowHeight||this.rowspan===0)return 0;if(this.render){const a=this.ctx.database.getOverlayerAutoHeight(this.rowIndex,this.colIndex);return this.rowspan>1?a<this.visibleHeight?0:Math.round(a-(this.visibleHeight-this.height)):Math.round(a)}if(!(this.displayText&&typeof this.displayText=="string"))return 0;const{BODY_FONT:e,CELL_PADDING:i,CELL_LINE_HEIGHT:s}=this.ctx.config,o=`${this.displayText}_${this.drawTextWidth}_${this.drawTextFont}`,r=this.ctx.paint.calculateTextHeight(this.displayText,this.drawTextWidth,{font:this.drawTextFont||e,padding:i,align:this.align,verticalAlign:this.verticalAlign,color:this.drawTextColor,autoRowHeight:this.autoRowHeight,lineHeight:s,maxLineClamp:this.maxLineClamp,cacheTextKey:o});return this.rowspan>1?r<this.visibleHeight?0:Math.round(r-(this.visibleHeight-this.height)):Math.round(r)}getSpanInfo(){return this.ctx.database.getSpanInfo(this)}getDisplayText(){return this.cellType==="footer"?this.renderFooter||this.text===null||this.text===void 0?"":this.text:this.rowspan===0||this.colspan===0||this.render||this.type==="index-selection"&&(this.ctx.hoverCell&&this.ctx.hoverCell.rowIndex===this.rowIndex||["checkbox-disabled","checkbox-check"].includes(this.drawSelectionImageName))||this.text===null||this.text===void 0?"":`${this.text}`}getText(){if(this.cellType==="footer")return typeof this.formatterFooter=="function"?this.formatterFooter({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.row[this.key]}):this.row[this.key];if(typeof this.formatter=="function")return this.formatter({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()});const{BODY_CELL_FORMATTER_METHOD:e}=this.ctx.config;return typeof e=="function"?e({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()}):["index-selection","index"].includes(this.type)?`${this.rowIndex+1}`:(this.value=this.ctx.database.getItemValue(this.rowKey,this.key),this.value)}getValue(){return this.ctx.database.getItemValue(this.rowKey,this.key)}setValue(e){this.ctx.setItemValueByEditor(this.rowKey,this.key,e)}getOverlayerViewsStyle(){let e=`${this.drawX-this.ctx.fixedLeftWidth}px`,i=`${this.drawY-this.ctx.body.y}px`;return this.fixed==="left"?e=`${this.drawX}px`:this.fixed==="right"&&(e=`${this.drawX-(this.ctx.stageWidth-this.ctx.fixedRightWidth)}px`),this.cellType==="footer"&&this.ctx.config.FOOTER_FIXED&&(i=`${this.drawY-this.ctx.footer.y}px`),this.autoRowHeight&&this.ctx.database.getOverlayerAutoHeight(this.rowIndex,this.colIndex)===0&&(e="-99999px",i="-99999px"),{position:"absolute",overflow:"hidden",left:e,top:i,width:`${this.visibleWidth}px`,height:this.autoRowHeight?"auto":`${this.visibleHeight}px`,pointerEvents:"initial",userSelect:"none"}}drawContainer(){const{paint:e,config:{BORDER_COLOR:i,BORDER:s}}=this.ctx,{drawX:o,drawY:r}=this;e.drawRect(o,r,this.visibleWidth,this.visibleHeight,{borderColor:s?i:"transparent",fillColor:this.drawCellBgColor}),e.drawRect(o,r,this.width,this.height,{borderColor:"transparent",fillColor:this.drawCellSkyBgColor}),s||this.ctx.paint.drawLine([o,r+this.visibleHeight,o+this.visibleWidth,r+this.visibleHeight],{borderColor:i,fillColor:i,borderWidth:1,lineCap:"round",lineJoin:"round"})}drawAutofillPiont(){if(this.cellType==="footer")return;const{SELECT_BORDER_COLOR:e,ENABLE_AUTOFILL:i,ENABLE_SELECTOR:s,AUTOFILL_POINT_BORDER_COLOR:o}=this.ctx.config;if(!s||!i||this.ctx.editing)return;const{xArr:r,yArr:a}=this.ctx.selector,l=r[1],h=a[1],{colIndex:d,rowIndex:f,drawX:u,drawY:x}=this;if(d===l&&f===h){const m=d===this.ctx.maxColIndex||f===this.ctx.maxRowIndex||d===this.ctx.lastCenterColIndex?6:4;this.ctx.paint.drawRect(u+this.width-m,x+this.height-m,6,6,{borderColor:o,fillColor:e})}}draw(){this.drawTreeLine(),this.drawText(),this.drawImage(),this.drawSelector(),this.drawAutofillPiont(),this.drawErrorTip()}getWidthByColIndexColSpan(e,i){if(i===0)return 0;let s=0;for(let o=e;o<e+i;o++){const r=this.ctx.header.leafCellHeaders[o];s+=r.width}return s}drawText(){const{CELL_PADDING:e,BODY_FONT:i,PLACEHOLDER_COLOR:s,CELL_LINE_HEIGHT:o}=this.ctx.config,{placeholder:r}=this.column;let a=this.displayText,l=this.drawTextColor;if(!this.ctx.database.getReadonly(this.rowKey,this.key)&&r&&["",null,void 0].includes(this.text)&&this.cellType==="body"&&!(this.rowspan===0||this.colspan===0)&&(a=r,l=s),["",null,void 0].includes(a))return!1;typeof a!="string"&&(a=`${a}`);const d=`${a}_${this.drawTextWidth}_${this.drawTextFont}`;return this.ellipsis=this.ctx.paint.drawText(a,this.drawTextX,this.drawTextY,this.drawTextWidth,this.drawTextHeight,{font:this.drawTextFont||i,padding:e,align:this.align,verticalAlign:this.verticalAlign,color:l,autoRowHeight:this.autoRowHeight,lineHeight:o,maxLineClamp:this.maxLineClamp,cacheTextKey:d}),this.ellipsis}drawImage(){if(this.drawSelectionImageSource&&this.ctx.paint.drawImage(this.drawSelectionImageSource,this.drawSelectionImageX,this.drawSelectionImageY,this.drawSelectionImageWidth,this.drawSelectionImageHeight),this.drawTreeImageSource&&this.ctx.paint.drawImage(this.drawTreeImageSource,this.drawTreeImageX,this.drawTreeImageY,this.drawTreeImageWidth,this.drawTreeImageHeight),this.drawHoverImageSource){const{CELL_HOVER_ICON_BG_COLOR:e,CELL_HOVER_ICON_BORDER_COLOR:i}=this.ctx.config;this.ctx.paint.drawRect(this.drawHoverImageX-2,this.drawHoverImageY-2,this.drawHoverImageWidth+4,this.drawHoverImageHeight+4,{borderColor:i,radius:4,borderWidth:1,fillColor:e}),this.ctx.paint.drawImage(this.drawHoverImageSource,this.drawHoverImageX,this.drawHoverImageY,this.drawHoverImageWidth,this.drawHoverImageHeight)}}drawSelector(){if(this.cellType==="footer")return;const{ENABLE_SELECTOR:e}=this.ctx.config;if(!e)return;const{xArr:i,yArr:s,xArrCopy:o,yArrCopy:r}=this.ctx.selector;this.drawBorder({xArr:o,yArr:r,borderColor:this.ctx.config.SELECT_BORDER_COLOR||"rgb(82,146,247)",fillColor:"transparent",borderWidth:1,lineDash:[4,4]}),this.drawBorder({xArr:this.ctx.autofill.xArr,yArr:this.ctx.autofill.yArr,borderColor:this.ctx.config.SELECT_BORDER_COLOR||"rgb(82,146,247)",fillColor:"transparent",borderWidth:1,lineDash:[4,4]}),this.drawBorder({xArr:i,yArr:s,borderColor:this.ctx.config.SELECT_BORDER_COLOR||"rgb(82,146,247)",fillColor:"transparent",borderWidth:1});const[a,l]=i,[h,d]=s;!(a===l&&h===d)&&this.colIndex>=a&&this.colIndex<=l&&this.rowIndex>=h&&this.rowIndex<=d&&this.ctx.paint.drawRect(this.drawX,this.drawY,this.width,this.height,{borderColor:"transparent",fillColor:this.ctx.config.SELECT_AREA_COLOR||"rgba(82,146,247,0.1)"}),this.operation&&this.rowIndex>=h&&this.rowIndex<=d&&this.ctx.paint.drawRect(this.drawX,this.drawY,this.visibleWidth,this.visibleHeight,{borderColor:"transparent",fillColor:this.ctx.config.SELECT_ROW_COL_BG_COLOR||"transparent"})}drawErrorTip(){if(this.cellType==="footer"||!this.message||this.rowspan===0||this.colspan===0)return;const{ERROR_TIP_ICON_SIZE:e,ERROR_TIP_COLOR:i}=this.ctx.config,{width:s}=this,o=this.drawX,r=this.drawY,a=[o+s-e-.5,r,o+s-.5,r,o+s-.5,r+e];this.ctx.paint.drawLine(a,{borderColor:i,fillColor:i,borderWidth:1,lineCap:"round",lineJoin:"round"})}drawBorder(e){const{drawX:i,drawY:s,rowIndex:o,colIndex:r,height:a,width:l}=this;let h=i,d=s;const{xArr:f,yArr:u,lineDash:x=[],borderWidth:w=1,borderColor:m,fillColor:g}=e,E=f[0],y=f[1],p=u[0],b=u[1];if(r>=E&&r<=y&&o===p){const C=r===y?1:0,I=r===E?1:0;this.ctx.paint.drawLine([h+I,d+1,h+l-C,d+1],{borderColor:m,fillColor:g,borderWidth:w,lineCap:"round",lineJoin:"round",lineDash:x})}if(r===y&&o>=p&&o<=b){const C=o===p?1:0,I=o===b?1:0;this.ctx.paint.drawLine([h+l-1,d+C,h+l-1,d+a-I],{borderColor:m,fillColor:g,borderWidth:w,lineCap:"round",lineJoin:"round",lineDash:x})}if(r>=E&&r<=y&&o===b){const C=r===y?1:0,I=r===E?1:0;this.ctx.paint.drawLine([h+I,d+a-1,h+l-C,d+a-1],{borderColor:m,fillColor:g,borderWidth:w,lineCap:"round",lineJoin:"round",lineDash:x})}if(r===E&&o>=p&&o<=b){const C=o===b?1:0,I=o===p?1:0;this.ctx.paint.drawLine([h+1,d+I,h+1,d+a-C],{borderColor:m,fillColor:g,borderWidth:w,lineCap:"round",lineJoin:"round",lineDash:x})}}}class fe{constructor(t,e){n(this,"ctx");n(this,"data");n(this,"columns");n(this,"footerData",[]);n(this,"rowKeyMap",new Map);n(this,"colIndexKeyMap",new Map);n(this,"headerMap",new Map);n(this,"rowIndexRowKeyMap",new Map);n(this,"rowKeyRowIndexMap",new Map);n(this,"checkboxKeyMap",new Map);n(this,"selectionMap",new Map);n(this,"expandMap",new Map);n(this,"originalDataMap",new Map);n(this,"changedDataMap",new Map);n(this,"validationErrorMap",new Map);n(this,"itemRowKeyMap",new WeakMap);n(this,"bufferData",[]);n(this,"overlayerAutoHeightMap",new Map);n(this,"bufferCheckState",{buffer:!1,check:!1,indeterminate:!1,selectable:!0});n(this,"sumHeight",0);n(this,"filterMethod");n(this,"positions",[]);n(this,"sortState",new Map);this.ctx=t;const{data:i=[],columns:s=[],footerData:o=[]}=e;this.data=i,this.footerData=o,this.columns=s,this.init()}init(t=!0){this.ctx.paint.clearTextCache(),this.clearBufferData(),this.rowKeyMap.clear(),this.checkboxKeyMap.clear(),this.colIndexKeyMap.clear(),this.rowIndexRowKeyMap.clear(),this.rowKeyRowIndexMap.clear();const e=this.getColumns(),i=ot(e);if(this.ctx.hasSelection=i.some(s=>s.type==="selection"),this.ctx.hasTree=i.some(s=>s.type==="tree"),t){this.originalDataMap.clear(),this.changedDataMap.clear(),this.validationErrorMap.clear();const{ROW_KEY:s}=this.ctx.config;s?(this.ctx.hasSelection||this.selectionMap.clear(),this.ctx.hasTree||this.expandMap.clear()):(this.selectionMap.clear(),this.expandMap.clear())}this.itemRowKeyMap=new WeakMap,this.initData(this.data),this.getData(),this.bufferCheckState.buffer=!1}clearBufferData(){this.bufferData=[]}initData(t,e=0,i=[]){const s=t.length;t.forEach((o,r)=>{var y;const{ROW_KEY:a="",DEFAULT_EXPAND_ALL:l,CELL_HEIGHT:h,SELECTABLE_METHOD:d,CHECKBOX_KEY:f}=this.ctx.config,u=o[a],x=u!=null?`${u}`:D();this.itemRowKeyMap.set(o,x);const w=o._height||h,m=o._readonly;let g=!0;if(typeof d=="function"&&(g=d),f){const p=o[f];if(this.checkboxKeyMap.has(p)){const b=this.checkboxKeyMap.get(p)||[];b.push(x),this.checkboxKeyMap.set(p,b)}else this.checkboxKeyMap.set(p,[x])}this.selectionMap.set(x,{key:f?o[f]:x,row:o,check:((y=this.selectionMap.get(x))==null?void 0:y.check)||!1});const E=l||this.expandMap.get(x)||o._expand||!1;this.expandMap.set(x,E),this.rowKeyMap.set(x,{readonly:m,index:r,rowIndex:r,level:e,height:w,calculatedHeight:-1,check:!1,selectable:g,expand:E,expandLazy:!1,hasChildren:o._hasChildren||(Array.isArray(o.children)?o.children.length>0:!1),expandLoading:!1,item:o,parentRowKeys:i,parentRowKey:i[i.length-1]||"",isLastChild:r===s-1}),Array.isArray(o.children)&&o.children.length&&this.initData(o.children,e+1,[...i,x])})}setRowHeight(t,e){const i=this.rowIndexRowKeyMap.get(t);if(i===void 0)return;const s=this.rowKeyMap.get(i);s.height=e,s.item._height=e,this.clearBufferData()}setBatchRowHeight(t){t.forEach(({rowIndex:e,height:i})=>{const s=this.rowIndexRowKeyMap.get(e);if(s){const o=this.rowKeyMap.get(s);o.height=i,o.item._height=i}}),this.clearBufferData()}setBatchCalculatedRowHeight(t){t.every(({height:i,rowIndex:s})=>this.getPositionForRowIndex(s).calculatedHeight===i)||(t.forEach(({rowIndex:i,height:s})=>{const o=this.rowIndexRowKeyMap.get(i);if(o){const r=this.rowKeyMap.get(o);r.calculatedHeight=s}}),this.clearBufferData(),this.getData(),this.ctx.emit("draw"))}getAllRowsData(){let t=[];const e=i=>{i.forEach(s=>{t.push(s),Array.isArray(s.children)&&e(s.children)})};return e(this.data),t}filterColumns(t){return t.reduce((e,i)=>{if(!(typeof i.hide=="function"?i.hide():i.hide)){const o={...i};o.children&&Array.isArray(o.children)&&(o.children=this.filterColumns(o.children)),e.push(o)}return e},[])}getColumns(){return this.filterColumns(this.columns)}setColumns(t){this.columns=t,this.clearBufferData()}setData(t){this.data=t,this.init()}getData(){if(this.bufferData.length>0)return{data:this.bufferData,sumHeight:this.sumHeight,positions:this.positions};let t=[],e=0;this.sumHeight=0,this.positions=[];const i=o=>{o.forEach(r=>{t.push(r);const a=this.itemRowKeyMap.get(r),{expand:l,hasChildren:h,height:d,calculatedHeight:f}=this.rowKeyMap.get(a),u=this.sumHeight,x=Math.max(f,d);this.sumHeight+=x,this.rowIndexRowKeyMap.set(e,a),this.rowKeyRowIndexMap.set(a,e),this.positions.push({top:u,height:x,bottom:this.sumHeight,calculatedHeight:f}),e+=1,l&&h&&i(r.children)})};this.rowIndexRowKeyMap.clear(),this.rowKeyRowIndexMap.clear();let s=this.data;if(typeof this.filterMethod=="function"&&(s=this.filterMethod(s)),this.sortState.size){const o=Array.from(this.sortState.entries()).sort((r,a)=>r[1].timestamp-a[1].timestamp);s=this.sortDataRecursive(s,o)}return i(s),this.bufferData=t,{data:t,sumHeight:this.sumHeight,positions:this.positions}}setFooterData(t){this.footerData=t}getFooterData(){return this.footerData}setFilterMethod(t){this.filterMethod=t}clearFilterMethod(){this.filterMethod=void 0}getSortState(t){return this.sortState.get(t)||{direction:"none",timestamp:0}}setSortState(t,e){const i=Date.now();this.ctx.config.SORT_STRICTLY&&this.sortState.clear(),e==="none"?this.sortState.delete(t):this.sortState.set(t,{direction:e,timestamp:i}),this.ctx.emit("sortChange",this.sortState),this.clearBufferData(),this.ctx.emit("draw")}clearSort(){this.sortState.clear(),this.ctx.emit("sortChange",this.sortState),this.clearBufferData(),this.ctx.emit("draw")}sortDataRecursive(t,e){let i=[...t];for(const[s,{direction:o}]of e){if(o==="none")continue;const r=this.getColumnByKey(s);!r||!r.column.sortBy||(i=this.applySingleColumnSort(i,s,o,r.column.sortBy))}return i.map(s=>(s.children&&Array.isArray(s.children)&&(s.children=this.sortDataRecursive(s.children,e)),s))}applySingleColumnSort(t,e,i,s){return t.sort((o,r)=>{const a=o[e],l=r[e];let h=0;if(typeof s=="function")h=s(o,r);else if(s==="number"){const d=Number(a)||0,f=Number(l)||0;h=d-f}else if(s==="string"){const d=String(a||""),f=String(l||"");h=d.localeCompare(f)}else s==="date"&&(h=de(a,l));return i==="asc"?h:-h})}expandItem(t,e=!1){const i=this.rowKeyMap.get(t);i.expand=e,this.expandMap.set(t,e),this.clearBufferData(),this.ctx.emit("draw")}setExpandRowKeys(t,e=!0){this.expandMap.clear(),t.forEach(i=>{const s=this.rowKeyMap.get(i);this.expandMap.set(i,e),s.expand=e}),this.clearBufferData(),this.ctx.emit("draw")}getExpandRowKeys(){let t=[];return this.rowKeyMap.forEach((e,i)=>{e.expand&&t.push(i)}),t}expandAll(t){this.expandMap.clear(),this.rowKeyMap.forEach(e=>{e.expand=t,this.expandMap.set(e.key,t)}),this.clearBufferData(),this.ctx.emit("draw")}expandLoading(t,e=!1){const i=this.rowKeyMap.get(t);i.expandLoading=e,this.clearBufferData(),this.ctx.emit("draw")}setExpandChildren(t,e){const i=this.rowKeyMap.get(t);i.expand=!0,this.expandMap.set(t,!0),i.expandLazy=!0,i.item.children=e,this.initData(i.item.children,i.level+1),this.clearBufferData()}getIsExpandLoading(t){return this.rowKeyMap.get(t).expandLoading}getIsExpandLazy(t){return this.rowKeyMap.get(t).expandLazy}getIsExpand(t){return this.rowKeyMap.get(t).expand}getRowForRowKey(t){return this.rowKeyMap.get(t)}getRowForRowIndex(t){const e=this.getRowKeyForRowIndex(t);return this.rowKeyMap.get(e)}getRowKeyForRowIndex(t){return this.rowIndexRowKeyMap.get(t)||""}getRowKeyByItem(t){return this.itemRowKeyMap.get(t)}getRowIndexForRowKey(t){return this.rowKeyRowIndexMap.get(t)}getItemValueForRowIndexAndColIndex(t,e){if(!(this.rowIndexRowKeyMap.has(t)&&this.colIndexKeyMap.get(e)))return null;const s=this.rowIndexRowKeyMap.get(t),o=this.colIndexKeyMap.get(e);return s===void 0||o===void 0?null:{rowKey:s,key:o,value:this.getItemValue(s,o)}}getItemValue(t,e){const i=this.rowKeyMap.get(t);return i&&i.item?i.item[e]===void 0?null:i.item[e]:null}async batchSetItemValue(t,e=!1,i=!0,s="none"){let o=[],r=i;const a=new Set;let l=[],h=t.map(x=>{const{rowKey:w,key:m}=x;let g=x.value,E=g;const y=this.getRowDataItemForRowKey(w),p=this.getItemValue(w,m),b=this.getVirtualBodyCellByKey(w,m);return(b==null?void 0:b.type)==="number"&&(["",void 0,null].includes(g)?E=null:/^-?\d+(\.\d+)?$/.test(`${g}`)?E=Number(g):(E=p,l.push({...x,value:E,oldValue:p,row:y}))),{...x,value:E,oldValue:p,row:y}});if(h=h.filter(x=>!l.some(w=>x.rowKey===w.rowKey&&x.key===w.key)),l.length){const x={code:"ERR_BATCH_SET_NUMBER_VALUE",message:"Assignment failed, not a numeric type",data:l};this.ctx.emit("error",x)}if(h=h.filter(x=>x.oldValue!==x.value),!h.length)return;const{BEFORE_VALUE_CHANGE_METHOD:d}=this.ctx.config;s==="none"&&typeof d=="function"&&(h=await d(h),r=!1),h.forEach(x=>{const{value:w,rowKey:m,key:g}=x,E=this.getItemValue(m,g);a.add(m),this.setItemValue(m,g,w,!1,!1,!1,r),o.push({rowKey:m,key:g,oldValue:E,newValue:w})});let f=[];a.forEach(x=>{f.push(this.ctx.database.getRowDataItemForRowKey(x))});const u=h.map(({rowKey:x,key:w})=>this.getValidator(x,w));Promise.all(u).then(()=>{this.validationErrorMap.size===0&&this.changedDataMap.size>0&&this.ctx.emit("validateChangedData",this.getChangedData())}),this.ctx.emit("change",h,f),e&&this.ctx.history.pushState({changeList:o,scrollX:this.ctx.scrollX,scrollY:this.ctx.scrollY,type:"multiple"}),this.ctx.emit("draw")}async setItemValue(t,e,i,s=!1,o=!1,r=!1,a=!0){if(!this.rowKeyMap.has(t))return{};const{item:l}=this.rowKeyMap.get(t);let h=l[e],d=i;if(a&&this.ctx.database.getReadonly(t,e))return{oldValue:h,newValue:h};l[e]!==null&&typeof l[e]=="object"&&(h=JSON.parse(JSON.stringify(l[e])));const f=`${t}​_${e}`;this.originalDataMap.has(f)||this.originalDataMap.set(f,h);const u=this.originalDataMap.get(f),x=this.getRowDataItemForRowKey(t);if(r){const w=this.getVirtualBodyCellByKey(t,e);if((w==null?void 0:w.type)==="number")if(["",void 0,null].includes(i))d=null;else if(/^-?\d+(\.\d+)?$/.test(`${i}`))d=Number(i);else{d=h;const g={code:"ERR_SET_NUMBER_VALUE",message:"Assignment failed, not a numeric type",data:[{rowKey:t,key:e,value:d,oldValue:h,row:x}]};this.ctx.emit("error",g)}if(d===h)return{oldValue:h,newValue:h};let m=[{rowKey:t,key:e,value:d,oldValue:h,row:x}];this.batchSetItemValue(m,s,!1),this.ctx.emit("editChange",{rowKey:t,key:e,oldValue:h,value:d,originalValue:u,row:x})}else this.changedDataMap.set(f,d),l[e]=d;return this.ctx.hasEvent("iterationChange")&&this.ctx.emit("iterationChange",{rowKey:t,key:e,oldValue:h,value:d,originalValue:this.originalDataMap.get(f),row:x}),o&&this.ctx.emit("draw"),{oldValue:h,newValue:d}}getRowDataItemForRowKey(t){if(!this.rowKeyMap.has(t))return{};const{item:e}=this.rowKeyMap.get(t);return e}setRowSelectionByCheckboxKey(t,e){const{CHECKBOX_KEY:i}=this.ctx.config;if(i){if(!this.rowKeyMap.has(t))return!1;const{item:s}=this.rowKeyMap.get(t),o=s[i];this.checkboxKeyMap.has(o)&&(this.checkboxKeyMap.get(o)||[]).forEach(a=>{const l=this.selectionMap.get(a);l&&(l.check=e)})}}toggleRowSelection(t,e){const i=this.rowKeyMap.get(t),s=this.selectionMap.get(t);if(!s)return;e==="selection-tree"||e==="tree-selection"?this.toggleTreeSelection(t):(s.check=!s.check,this.setRowSelectionByCheckboxKey(t,s.check)),this.ctx.emit("toggleRowSelection",i);const o=this.getSelectionRows();this.ctx.emit("selectionChange",o),this.bufferCheckState.buffer=!1,this.ctx.emit("draw")}toggleTreeSelection(t){const e=this.getTreeSelectionState(t),i=this.ctx.config.TREE_SELECT_MODE;if(i==="auto")e.checked&&!e.indeterminate?(this.clearTreeSelectionRecursive(t),this.setRowSelection(t,!1,!1)):(this.selectTreeSelectionRecursive(t),this.setRowSelection(t,!0,!1));else if(i==="cautious")e.checked&&!e.indeterminate?(this.clearTreeSelectionRecursive(t),this.setRowSelection(t,!1,!1)):(this.selectTreeSelectionRecursive(t),this.setRowSelection(t,!0,!1));else if(i==="strictly"){const s=this.selectionMap.get(t);s&&(s.check=!s.check,this.setRowSelectionByCheckboxKey(t,s.check))}this.ctx.emit("selectionChange",this.getSelectionRows()),this.ctx.emit("draw")}selectTreeSelectionRecursive(t){this.getTreeChildren(t).forEach(i=>{this.setRowSelectionByParent(i,!0),this.selectTreeSelectionRecursive(i)})}clearTreeSelectionRecursive(t){this.getTreeChildren(t).forEach(i=>{this.setRowSelectionByParent(i,!1),this.clearTreeSelectionRecursive(i)})}updateParentTreeSelection(t){const e=this.getTreeParent(t);if(!e)return;const s=this.getTreeChildren(e).map(h=>this.selectionMap.get(h)),o=s.filter(h=>h==null?void 0:h.check).length,r=s.length;let a=!1;r>0&&(o===0?a=!1:o===r||this.ctx.config.TREE_SELECT_MODE==="auto"?a=!0:this.ctx.config.TREE_SELECT_MODE==="cautious"&&(a=!1));const l=this.selectionMap.get(e);l&&l.check!==a&&(l.check=a,this.setRowSelectionByCheckboxKey(e,a),this.updateParentTreeSelection(e))}setRowSelection(t,e,i=!0){const s=this.selectionMap.get(t);s&&(s.check=e,this.setRowSelectionByCheckboxKey(t,s.check),this.ctx.emit("setRowSelection",e,s.row),(this.ctx.config.TREE_SELECT_MODE==="auto"||this.ctx.config.TREE_SELECT_MODE==="cautious")&&this.updateParentTreeSelection(t),i&&(this.bufferCheckState.buffer=!1,this.ctx.emit("draw")))}setRowSelectionByParent(t,e){const i=this.selectionMap.get(t);i&&(i.check=e,this.setRowSelectionByCheckboxKey(t,i.check))}getSelectionRows(){let t=[];return this.selectionMap.forEach(e=>{e.check&&t.push(e.row)}),t}getRowSelection(t){const e=this.selectionMap.get(t);return e?e.check:!1}getTreeSelectionState(t){if(!this.getRowForRowKey(t))return{checked:!1,indeterminate:!1};const i=this.selectionMap.get(t),s=(i==null?void 0:i.check)||!1;if(this.getTreeChildren(t).length===0)return{checked:s,indeterminate:!1};let r=!1,a=s;if(this.ctx.config.TREE_SELECT_MODE==="auto"){const h=g=>{const E=this.getTreeChildren(g);let y=[];for(const p of E)y.push(p),y.push(...h(p));return y},f=h(t).map(g=>this.selectionMap.get(g)),u=f.filter(g=>g==null?void 0:g.check).length,x=f.length,w=u>0;r=w&&!(u===x),a=s||w,s&&x>0&&u===0&&(a=!1,r=!1)}else if(this.ctx.config.TREE_SELECT_MODE==="cautious"){const h=g=>{const E=this.getTreeChildren(g);let y=[];for(const p of E)y.push(p),y.push(...h(p));return y},f=h(t).map(g=>this.selectionMap.get(g)),u=f.filter(g=>g==null?void 0:g.check).length,x=f.length,w=u>0,m=u===x;r=w&&!m,a=s||m,s&&x>0&&u===0&&(a=!1,r=!1)}else this.ctx.config.TREE_SELECT_MODE==="strictly"&&(r=!1,a=s);return{checked:a,indeterminate:r}}getTreeChildren(t){const e=this.getRowForRowKey(t);if(!e||!e.item||!e.item.children)return[];const i=[],s=o=>{for(const r of o){const a=this.getRowKeyByItem(r);a&&i.push(a),r.children&&r.children.length>0&&s(r.children)}};return s(e.item.children),i}getTreeParent(t){const e=(i,s)=>{for(const o of i){const r=this.getRowKeyByItem(o);if(o.children)for(const a of o.children){if(this.getRowKeyByItem(a)===s)return r;const h=e(o.children,s);if(h)return h}}return null};return e(this.data,t)}getRowSelectable(t){const{selectable:e,item:i,rowIndex:s}=this.rowKeyMap.get(t);return typeof e=="function"?e({row:i,rowIndex:s}):e}toggleAllSelection(){this.ctx.config.TREE_SELECT_MODE==="auto"||this.ctx.config.TREE_SELECT_MODE==="cautious"?this.rowKeyMap.forEach((i,s)=>{let o=i.selectable;if(typeof o=="function"&&(o=o({row:i.item,rowIndex:i.rowIndex})),o){const r=this.selectionMap.get(s);r&&(r.check=!0,this.setRowSelectionByCheckboxKey(s,!0))}}):this.rowKeyMap.forEach((i,s)=>{let o=i.selectable;typeof o=="function"&&(o=o({row:i.item,rowIndex:i.rowIndex})),o&&this.setRowSelection(s,!0,!1)});const e=this.getSelectionRows();this.ctx.emit("toggleAllSelection",e),this.ctx.emit("selectionChange",e),this.bufferCheckState.buffer=!1,this.ctx.emit("draw")}clearSelection(t=!1){const e=this.ctx.config.TREE_SELECT_MODE==="auto"||this.ctx.config.TREE_SELECT_MODE==="cautious";t?e?this.rowKeyMap.forEach((s,o)=>{const r=this.selectionMap.get(o);r&&(r.check=!1,this.setRowSelectionByCheckboxKey(o,!1))}):this.rowKeyMap.forEach((s,o)=>{this.setRowSelection(o,!1,!1)}):(this.selectionMap.clear(),this.rowKeyMap.forEach((s,o)=>{this.selectionMap.set(o,{check:!1,row:s.item,key:o})}));const i=this.getSelectionRows();this.ctx.emit("clearSelection"),this.ctx.emit("selectionChange",i),this.bufferCheckState.buffer=!1,this.ctx.emit("draw")}getCheckedState(){const{buffer:t,...e}=this.bufferCheckState;if(t)return e;const i=this.rowKeyMap.size;let s=0,o=0;const r=this.selectionMap.size,a=Array.from(this.selectionMap.values()).some(u=>u.check);this.rowKeyMap.forEach((u,x)=>{var m;(m=this.selectionMap.get(x))!=null&&m.check&&(s+=1);let w=u.selectable;typeof w=="function"&&(w=w({row:u.item,rowIndex:u.rowIndex})),w&&(o+=1)});const l=r>i&&s===0&&a,h=o&&o>s&&s>0||l,d=o!==0,f=!!o&&o===s;return this.bufferCheckState={buffer:!0,check:f,indeterminate:h,selectable:d},{check:f,indeterminate:h,selectable:d}}updateColIndexKeyMap(t=[]){this.colIndexKeyMap.clear(),t.forEach(e=>{this.colIndexKeyMap.set(e.colIndex,e.key)})}getColumnByColIndex(t){var i;const e=this.colIndexKeyMap.get(t);if(e&&this.headerMap.has(e))return(i=this.headerMap.get(e))==null?void 0:i.column}getColumnByKey(t){const e=this.headerMap.get(t);if(e)return e}getColIndexForKey(t){var e;if(t&&this.headerMap.has(t))return(e=this.headerMap.get(t))==null?void 0:e.colIndex}getColHeaderByIndex(t){const e=this.colIndexKeyMap.get(t);if(e&&this.headerMap.has(e))return this.headerMap.get(e)}getChangedData(){let t=[];return this.changedDataMap.forEach((e,i)=>{const s=this.originalDataMap.get(i),o=i.split("​_")[0],r=i.split("​_")[1];s!==e&&t.push({rowKey:o,colKey:r,originalValue:s,row:this.ctx.database.getRowDataI