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 • 170 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.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-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-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}.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}")),document.head.appendChild(o)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
(function(H,A){typeof exports=="object"&&typeof module<"u"?module.exports=A():typeof define=="function"&&define.amd?define(A):(H=typeof globalThis<"u"?globalThis:H||self,H.EVirtTable=A())})(this,function(){"use strict";var ii=Object.defineProperty;var si=(H,A,$)=>A in H?ii(H,A,{enumerable:!0,configurable:!0,writable:!0,value:$}):H[A]=$;var n=(H,A,$)=>si(H,typeof A!="symbol"?A+"":A,$);class H{constructor(t){n(this,"rules");this.rules=t}validate(t){const e=[],{column:i,row:s,key:o,rowKey:r,colIndex:l,rowIndex:a,value:h,field:d,fieldValue:f}=t;Array.isArray(this.rules)||(this.rules=[this.rules]);for(const x of this.rules){if(!x.required&&(h==null||h===""))return e;if(x.validator){const u={field:d,fieldValue:f,value:h,column:i,colIndex:l,rowIndex:a,row:s,key:o,rowKey:r,...x};x.validator(u,h,p=>{p&&e.push({...u,message:p})})}x.pattern&&!x.pattern.test(h)&&e.push({value:h,column:i,row:s,key:o,rowKey:r,colIndex:l,rowIndex:a,field:d,fieldValue:f,message:x.message||`${o} is pattern validation error`}),x.required&&(h==null||h==="")&&e.push({value:h,column:i,row:s,key:o,rowKey:r,colIndex:l,rowIndex:a,field:d,fieldValue:f,message:x.message||`${o} is required`})}return e}}function A(){return"xxxxxxxxxxxxxxxxxx".replace(/[x]/g,function(c){const t=Math.random()*16|0;return(c==="x"?t:t&3|8).toString(16)})}function $(c,t){let e=0,i;return function(...s){const o=new Date().getTime(),r=o-e;!e||r>=t?(c.apply(this,s),e=o):i||(i=setTimeout(()=>{c.apply(this,s),e=new Date().getTime(),i=void 0},t-r))}}function bt(c=[]){return c.length?c.map(t=>bt(t.children)+1).sort((t,e)=>e-t)[0]:0}function Jt(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 Rt(c=[],t=1,e=0){return c.map(i=>{if(i.children){let s=0,o=i.fixed;i.children.forEach(l=>{l.fixed=o});const r=Rt(i.children,t-1,e+1);return r&&r.forEach(l=>{s+=l.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 It=/^(\r\n|\n\r|\r|\n)/,Qt=/^[^\t\r\n]+/,vt=/^\t/;function te(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(vt))c=c.replace(vt,""),e+=1,t[i][e]="";else if(c.match(It))c=c.replace(It,""),e=0,i+=1,t[i]=[""];else{let o="";if(c.startsWith('"')){let r=0,l=!0;for(;l;){const a=c.slice(0,1);a==='"'&&(r+=1),o+=a,c=c.slice(1),(c.length===0||c.match(/^[\t\r\n]/)&&r%2===0)&&(l=!1)}o=o.replace(/^"/,"").replace(/"$/,"").replace(/["]*/g,a=>new Array(Math.floor(a.length/2)).fill('"').join(""))}else{const r=c.match(Qt);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 ee(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 _t(c,t,e=[]){let i=0;const s=[];return c.forEach((o,r)=>{if(r===0)s.push(1);else{const l=e.reduce((h,d)=>`${h}${o[d]??""}`,"")||o[t],a=e.reduce((h,d)=>`${h}${c[r-1][d]??""}`,"")||c[r-1][t];l===a?(s[i]+=1,s.push(0)):(s.push(1),i=r)}}),s}function Ot(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 ie(c,t,e=[]){const{visibleRows:i,rowIndex:s,headIndex:o}=c,r=_t(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 se(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=Ot(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 oe(c,t=document.documentElement){const e=c.startsWith("--")?c:`--${c}`;return getComputedStyle(t).getPropertyValue(e).trim()}class St{constructor(t,e,i,s,o,r,l){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=l,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 St{constructor(e,i,s,o,r,l,a,h,d,f="body"){super(e,o,r,l,a,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,"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,"drawTextX",0);n(this,"drawTextY",0);n(this,"drawImageX",0);n(this,"drawImageY",0);n(this,"drawImageWidth",0);n(this,"drawImageHeight",0);n(this,"drawImageName","");n(this,"drawImageSource");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");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||"center",this.verticalAlign=h.verticalAlign||"middle",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.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.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.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:l,mergeRow:a=!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(l)&&l.length>0?this.relationColKeys=l:this.relationColKeys=[this.key],this.mergeCol=h,this.mergeRow=a,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.style=this.getOverlayerViewsStyle()}updateTree(){const{CELL_PADDING:e=0}=this.ctx.config,{rowKey:i,cellType:s}=this;let o,r=0,l="";if(this.type==="tree"&&s==="body"){const a=this.ctx.database.getRowForRowKey(i),{expand:h=!1,hasChildren:d=!1,expandLoading:f=!1,level:x=0}=a||{};if(this.rowExpand=h,this.rowHasChildren=d,f){const g=this.ctx.icons.get("loading");l="loading",o=g,r=x*8}else if(d){const g=this.ctx.icons.get("expand"),w=this.ctx.icons.get("shrink");o=h?w:g,l=h?"shrink":"expand",r=x*8}else r=x*8;let u=20,p=20;if(o){let g=this.drawX+r+e,w=this.drawY+(this.visibleHeight-p)/2;this.ctx.paint.drawImage(o,g,w,u,p),this.drawImageX=g,this.drawImageY=w,this.drawImageWidth=u,this.drawImageHeight=p,this.drawImageName=l,this.drawImageSource=o}this.align="left",this.drawTextX=r+this.drawX+u-.5}}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:l,FOOTER_TEXT_COLOR:a,FOOTER_BG_COLOR:h,HIGHLIGHT_SELECTED_ROW:d,HIGHLIGHT_SELECTED_ROW_COLOR:f,HIGHLIGHT_HOVER_ROW:x,HIGHLIGHT_HOVER_ROW_COLOR:u,STRIPE:p,STRIPE_COLOR:g}=this.ctx.config;if(this.cellType==="footer"){let _=h,S=a;if(typeof o=="function"){const I=o,{backgroundColor:b,color:O}=I({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()})||{};b&&(_=b),O&&(S=O)}this.drawCellSkyBgColor="transparent",this.drawCellBgColor=_,this.drawTextColor=S;return}let w="transparent";const E=this.ctx.hoverCell,y=this.ctx.currentCell;let m=this.rowIndex,R=this.rowIndex;if(this.rowspan!==1&&(x||d)){const _=this.getSpanInfo(),{yArr:S}=_;m=S[0],R=S[1]}x&&E&&(E.rowKey===this.rowKey&&(w=u),E.rowIndex>=m&&E.rowIndex<=R&&(w=u)),d&&y&&(y.rowKey===this.rowKey&&(w=f),y.rowIndex>=m&&y.rowIndex<=R&&(w=f)),this.drawCellSkyBgColor=w;let C=e,v=l;if(this.ctx.database.getReadonly(this.rowKey,this.key)||(C=i,v=r),p&&(this.rowIndex%2?C=g:C=e),typeof s=="function"){const _=s,{backgroundColor:S,color:I}=_({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,isHasChanged:this.isHasChanged,value:this.getValue()})||{};S&&(C=S),I&&(v=I)}this.drawCellBgColor=C,this.drawTextColor=v}updateSelection(){const{visibleWidth:e,visibleHeight:i,rowspan:s,colspan:o,cellType:r,type:l,rowIndex:a,rowKey:h}=this;if(!(s===0||o===0)&&r!=="footer"&&["index-selection","selection"].includes(l)){const d=this.ctx.database.getRowSelection(h),f=this.ctx.database.getRowSelectable(h),{CHECKBOX_SIZE:x=0}=this.ctx.config,u=this.drawX+(e-x)/2,p=this.drawY+(i-x)/2;let g=this.ctx.icons.get("checkbox-uncheck"),w="checkbox-uncheck";d&&f?(g=this.ctx.icons.get("checkbox-check"),w="checkbox-check"):d&&f?(g=this.ctx.icons.get("checkbox-check-disabled"),w="checkbox-check-disabled"):!d&&f?(g=this.ctx.icons.get("checkbox-uncheck"),w="checkbox-uncheck"):(g=this.ctx.icons.get("checkbox-disabled"),w="checkbox-disabled"),g&&l=="index-selection"?(this.ctx.hoverCell&&this.ctx.hoverCell.rowIndex===a||["checkbox-disabled","checkbox-check"].includes(w))&&(this.drawImageX=u,this.drawImageY=p,this.drawImageWidth=x,this.drawImageHeight=x,this.drawImageName=w,this.drawImageSource=g):g&&l==="selection"&&(this.drawImageX=u,this.drawImageY=p,this.drawImageWidth=x,this.drawImageHeight=x,this.drawImageName=w,this.drawImageSource=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:l}=this.ctx;if(this.hoverIconName&&!this.ctx.editing&&l){let a=0,h=0;if(l.rowKey===this.rowKey&&(a=this.drawX+this.width-s-o,h=this.drawY+(this.height-s)/2),this.rowspan!==1&&r){const f=this.getSpanInfo(),{yArr:x}=f,u=x[0],p=x[1];if(l.rowIndex>=u&&l.rowIndex<=p){const{width:g,height:w,offsetTop:E,offsetLeft:y}=f;a=this.drawX-y+g-s-o,h=this.drawY-E+(w-s)/2}}const d=this.ctx.icons.get(this.hoverIconName);this.drawImageX=a,this.drawImageY=h,this.drawImageWidth=s,this.drawImageHeight=s,this.drawImageName=this.hoverIconName,this.drawImageSource=d}}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.drawImageName))||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`),{position:"absolute",overflow:"hidden",left:e,top:i,width:`${this.visibleWidth}px`,height:`${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:l}=this.ctx.selector,a=r[1],h=l[1],{colIndex:d,rowIndex:f,drawX:x,drawY:u}=this;if(d===a&&f===h){const g=d===this.ctx.maxColIndex||f===this.ctx.maxRowIndex||d===this.ctx.lastCenterColIndex?6:4;this.ctx.paint.drawRect(x+this.width-g,u+this.height-g,6,6,{borderColor:o,fillColor:e})}}draw(){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}=this.ctx.config;let o=this.visibleWidth;if(this.type==="tree"){const f=this.drawTextX-this.drawX;o=this.visibleWidth-f}const{ellipsis:r}=this.ctx.paint.handleEllipsis(this.displayText,o,e,i);this.ellipsis=r;const{placeholder:l}=this.column;let a=this.displayText,h=this.drawTextColor;return!this.ctx.database.getReadonly(this.rowKey,this.key)&&l&&["",null,void 0].includes(this.text)&&this.cellType==="body"&&!(this.rowspan===0||this.colspan===0)&&(a=l,h=s),this.ctx.paint.drawText(a,this.drawTextX,this.drawTextY,o,this.visibleHeight,{font:i,padding:e,align:this.align,verticalAlign:this.verticalAlign,color:h})}drawImage(){if(this.drawImageSource){if(this.hoverIconName){const{CELL_HOVER_ICON_BG_COLOR:e,CELL_HOVER_ICON_BORDER_COLOR:i}=this.ctx.config;this.ctx.paint.drawRect(this.drawImageX-2,this.drawImageY-2,this.drawImageWidth+4,this.drawImageHeight+4,{borderColor:i,radius:4,borderWidth:1,fillColor:e})}this.ctx.paint.drawImage(this.drawImageSource,this.drawImageX,this.drawImageY,this.drawImageWidth,this.drawImageHeight)}}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[l,a]=i,[h,d]=s;!(l===a&&h===d)&&this.colIndex>=l&&this.colIndex<=a&&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,l=[o+s-e-.5,r,o+s-.5,r,o+s-.5,r+e];this.ctx.paint.drawLine(l,{borderColor:i,fillColor:i,borderWidth:1,lineCap:"round",lineJoin:"round"})}drawBorder(e){const{drawX:i,drawY:s,rowIndex:o,colIndex:r,height:l,width:a}=this;let h=i,d=s;const{xArr:f,yArr:x,lineDash:u=[],borderWidth:p=1,borderColor:g,fillColor:w}=e,E=f[0],y=f[1],m=x[0],R=x[1];if(r>=E&&r<=y&&o===m){const C=r===y?1:0,v=r===E?1:0;this.ctx.paint.drawLine([h+v,d+1,h+a-C,d+1],{borderColor:g,fillColor:w,borderWidth:p,lineCap:"round",lineJoin:"round",lineDash:u})}if(r===y&&o>=m&&o<=R){const C=o===m?1:0,v=o===R?1:0;this.ctx.paint.drawLine([h+a-1,d+C,h+a-1,d+l-v],{borderColor:g,fillColor:w,borderWidth:p,lineCap:"round",lineJoin:"round",lineDash:u})}if(r>=E&&r<=y&&o===R){const C=r===y?1:0,v=r===E?1:0;this.ctx.paint.drawLine([h+v,d+l-1,h+a-C,d+l-1],{borderColor:g,fillColor:w,borderWidth:p,lineCap:"round",lineJoin:"round",lineDash:u})}if(r===E&&o>=m&&o<=R){const C=o===R?1:0,v=o===m?1:0;this.ctx.paint.drawLine([h+1,d+v,h+1,d+l-C],{borderColor:g,fillColor:w,borderWidth:p,lineCap:"round",lineJoin:"round",lineDash:u})}}}class re{constructor(t,e){n(this,"loading",!1);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,"bufferCheckState",{buffer:!1,check:!1,indeterminate:!1,selectable:!0});n(this,"sumHeight",0);n(this,"filterMethod");n(this,"positions",[]);this.ctx=t;const{data:i=[],columns:s=[],footerData:o=[]}=e;this.data=i,this.footerData=o,this.columns=s,this.setLoading(!0),this.init()}init(t=!0){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=[]){t.forEach((s,o)=>{var E;const{ROW_KEY:r="",DEFAULT_EXPAND_ALL:l,CELL_HEIGHT:a,SELECTABLE_METHOD:h,CHECKBOX_KEY:d}=this.ctx.config,f=s[r],x=f!=null?`${f}`:A();this.itemRowKeyMap.set(s,x);const u=s._height||a,p=s._readonly;let g=!0;if(typeof h=="function"&&(g=h),d){const y=s[d];if(this.checkboxKeyMap.has(y)){const m=this.checkboxKeyMap.get(y)||[];m.push(x),this.checkboxKeyMap.set(y,m)}else this.checkboxKeyMap.set(y,[x])}this.selectionMap.set(x,{key:d?s[d]:x,row:s,check:((E=this.selectionMap.get(x))==null?void 0:E.check)||!1});const w=l||this.expandMap.get(x)||s._expand||!1;this.expandMap.set(x,w),this.rowKeyMap.set(x,{readonly:p,index:o,rowIndex:o,level:e,height:u,check:!1,selectable:g,expand:w,expandLazy:!1,hasChildren:s._hasChildren||(Array.isArray(s.children)?s.children.length>0:!1),expandLoading:!1,item:s,parentRowKeys:i}),Array.isArray(s.children)&&s.children.length&&this.initData(s.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()}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.columns.length&&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 l=this.itemRowKeyMap.get(r),{expand:a,hasChildren:h,height:d}=this.rowKeyMap.get(l),f=this.sumHeight;this.sumHeight+=d,this.rowIndexRowKeyMap.set(e,l),this.rowKeyRowIndexMap.set(l,e),this.positions.push({top:f,height:d,bottom:this.sumHeight}),e+=1,a&&h&&i(r.children)})};this.rowIndexRowKeyMap.clear(),this.rowKeyRowIndexMap.clear();let s=this.data;return typeof this.filterMethod=="function"&&(s=this.filterMethod(s)),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}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 l=new Set;let a=[],h=t.map(u=>{const{rowKey:p,key:g}=u;let w=u.value,E=w;const y=this.getRowDataItemForRowKey(p),m=this.getItemValue(p,g),R=this.getVirtualBodyCellByKey(p,g);return(R==null?void 0:R.type)==="number"&&(["",void 0,null].includes(w)?E=null:/^-?\d+(\.\d+)?$/.test(`${w}`)?E=Number(w):(E=m,a.push({...u,value:E,oldValue:m,row:y}))),{...u,value:E,oldValue:m,row:y}});if(h=h.filter(u=>!a.some(p=>u.rowKey===p.rowKey&&u.key===p.key)),a.length){const u={code:"ERR_BATCH_SET_NUMBER_VALUE",message:"Assignment failed, not a numeric type",data:a};this.ctx.emit("error",u)}if(!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(u=>{const{value:p,rowKey:g,key:w}=u,E=this.getItemValue(g,w);l.add(g),this.setItemValue(g,w,p,!1,!1,!1,r),o.push({rowKey:g,key:w,oldValue:E,newValue:p})});let f=[];l.forEach(u=>{f.push(this.ctx.database.getRowDataItemForRowKey(u))});const x=h.map(({rowKey:u,key:p})=>this.getValidator(u,p));Promise.all(x).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,l=!0){if(!this.rowKeyMap.has(t))return{};const{item:a}=this.rowKeyMap.get(t);let h=a[e],d=i;if(l&&this.ctx.database.getReadonly(t,e))return{oldValue:h,newValue:h};a[e]!==null&&typeof a[e]=="object"&&(h=JSON.parse(JSON.stringify(a[e])));const f=`${t}_${e}`;this.originalDataMap.has(f)||this.originalDataMap.set(f,h);const x=this.originalDataMap.get(f),u=this.getRowDataItemForRowKey(t);if(r){const p=this.getVirtualBodyCellByKey(t,e);if((p==null?void 0:p.type)==="number")if(["",void 0,null].includes(i))d=null;else if(/^-?\d+(\.\d+)?$/.test(`${i}`))d=Number(i);else{d=h;const w={code:"ERR_SET_NUMBER_VALUE",message:"Assignment failed, not a numeric type",data:[{rowKey:t,key:e,value:d,oldValue:h,row:u}]};this.ctx.emit("error",w)}if(d===h)return{oldValue:h,newValue:h};let g=[{rowKey:t,key:e,value:d,oldValue:h,row:u}];this.batchSetItemValue(g,s,!1),this.ctx.emit("editChange",{rowKey:t,key:e,oldValue:h,value:d,originalValue:x,row:u})}else this.changedDataMap.set(f,d),a[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:u}),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(l=>{const a=this.selectionMap.get(l);a&&(a.check=e)})}}toggleRowSelection(t){const e=this.rowKeyMap.get(t),i=this.selectionMap.get(t);if(!i)return;i.check=!i.check,this.setRowSelectionByCheckboxKey(t,i.check),this.ctx.emit("toggleRowSelection",e);const s=this.getSelectionRows();this.ctx.emit("selectionChange",s),this.bufferCheckState.buffer=!1,this.ctx.emit("draw")}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),i&&(this.bufferCheckState.buffer=!1,this.ctx.emit("draw")))}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}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.rowKeyMap.forEach((e,i)=>{let s=e.selectable;typeof s=="function"&&(s=s({row:e.item,rowIndex:e.rowIndex})),s&&this.setRowSelection(i,!0,!1)});const t=this.getSelectionRows();this.ctx.emit("toggleAllSelection",t),this.ctx.emit("selectionChange",t),this.bufferCheckState.buffer=!1,this.ctx.emit("draw")}clearSelection(t=!1){t?this.rowKeyMap.forEach((i,s)=>{this.setRowSelection(s,!1,!1)}):(this.selectionMap.clear(),this.rowKeyMap.forEach((i,s)=>{this.selectionMap.set(s,{check:!1,row:i.item,key:s})}));const e=this.getSelectionRows();this.ctx.emit("clearSelection"),this.ctx.emit("selectionChange",e),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,l=Array.from(this.selectionMap.values()).some(x=>x.check);this.rowKeyMap.forEach((x,u)=>{var g;(g=this.selectionMap.get(u))!=null&&g.check&&(s+=1);let p=x.selectable;typeof p=="function"&&(p=p({row:x.item,rowIndex:x.rowIndex})),p&&(o+=1)});const a=r>i&&s===0&&l,h=o&&o>s&&s>0||a,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.getRowDataItemForRowKey(o),value:e})}),t}getChangedRows(){const t=new Set;this.changedDataMap.forEach((i,s)=>{const o=this.originalDataMap.get(s),r=s.split("_")[0];o!==i&&t.add(r)});let e=[];return t.forEach(i=>{e.push(this.ctx.database.getRowDataItemForRowKey(i))}),e}isHasChangedData(t,e){const i=`${t}_${e}`;if(!this.changedDataMap.has(i))return!1;const s=this.originalDataMap.get(i),o=this.changedDataMap.get(i);return s!==o}getPositionForRowIndex(t){return t<this.positions.length?this.positions[t]:{height:0,top:0,bottom:0}}setHeader(t,e){return t?(this.headerMap.set(t,e),!0):!1}getReadonly(t,e){const{DISABLED:i}=this.ctx.config;if(i)return!0;const s=this.rowKeyMap.get(t),o=this.headerMap.get(e);if(!s||!o)return!0;const r=s.readonly,l=o.readonly,{BODY_CELL_READONLY_METHOD:a}=this.ctx.config;if(typeof a=="function"&&o){const d=a({row:s.item,rowIndex:s.rowIndex,colIndex:o.colIndex,column:o.column,value:this.getItemValue(t,e)});if(d!==void 0)return d}return l||r}clearValidate(){this.validationErrorMap.clear()}hasValidationError(){return this.validationErrorMap.size!==0}getValidator(t,e){return new Promise(i=>{const s=this.rowKeyMap.get(t),o=this.headerMap.get(e),{BODY_CELL_RULES_METHOD:r}=this.ctx.config;if(o===void 0)return i([]);const l=o.column;let a=l.rules;if(typeof r=="function"){const d=r({row:s.item,rowIndex:s.rowIndex,colIndex:o.colIndex,column:l,value:this.getItemValue(t,e)});d&&(a=d)}if(a){const h={row:s.item,rowIndex:s.rowIndex,colIndex:o.colIndex,column:l,key:e,rowKey:t,value:this.getItemValue(t,e),field:e,fieldValue:this.getItemValue(t,e)},f=new H(a).validate(h);this.setValidationError(t,e,f),i(f)}else this.clearValidationError(t,e),i([])})}getHeightByRowIndexRowSpan(t,e){let i=0;for(let s=0;s<e;s++){const o=this.positions[t+s];o&&(i+=o.height)}return i}getSpanInfo(t){const{rowIndex:e,key:i,rowKey:s,row:o,value:r,colIndex:l,relationRowKeys:a,relationColKeys:h,rowspan:d,height:f,width:x,colspan:u,mergeRow:p,mergeCol:g}=t;if(d===1&&u===1)return{xArr:[l,l],yArr:[e,e],rowspan:d,colspan:u,height:f,width:x,offsetTop:0,offsetLeft:0,dataList:[{rowKey:s,key:i,row:o,value:r}]};let w=e,E=e,y=l,m=l,R=[],C=0,v=0,_=0,S=0;if(d!==1&&p){S=x;const I=a.reduce((b,O)=>{const L=this.getItemValue(s,O)??"";return`${b}${L}`},"");for(let b=e-1;b>=0;b--){const O=this.rowIndexRowKeyMap.get(b)||"",L=a.reduce((X,T)=>{const K=this.getItemValue(O,T)??"";return`${X}${K}`},"");if(I===L)w=b;else break}for(let b=e;b<=this.ctx.maxRowIndex;b++){const O=this.rowIndexRowKeyMap.get(b)||"",L=a.reduce((X,T)=>{const K=this.getItemValue(O,T)??"";return`${X}${K}`},"");if(I===L)E=b;else break}for(let b=w;b<e;b++){const{height:O}=this.positions[b];C+=O}for(let b=w;b<=E;b++){const{height:O}=this.positions[b];_+=O;const L=this.rowIndexRowKeyMap.get(b)||"",{item:X}=this.rowKeyMap.get(L),T=this.getItemValue(L,i);R.push({rowKey:L,key:i,value:T,row:X})}}if(u!==1&&g){_=f;for(let I=l-1;I>=0;I--){const b=this.getColumnByColIndex(I);if(!b)break;const O=this.getItemValue(s,i),L=this.getItemValue(s,b.key);if(O===L&&h.includes(b.key))y=I;else break}for(let I=l;I<=this.ctx.maxColIndex;I++){const b=this.getColumnByColIndex(I);if(!b)break;const O=this.getItemValue(s,i),L=this.getItemValue(s,b.key);if(O===L&&h.includes(b.key))m=I;else break}for(let I=y;I<l;I++){const b=this.getColumnByColIndex(I);if(!b)break;v+=b.width||100}for(let I=y;I<=m;I++){const b=this.getColumnByColIndex(I);if(!b)break;S+=b.width||100,R.push({rowKey:s,key:b.key,value:this.getItemValue(s,b.key),row:o})}}return{xArr:[y,m],yArr:[w,E],rowspan:d,colspan:u,height:_,width:S,offsetTop:C,offsetLeft:v,dataList:R}}setLoading(t){this.loading=t,this.ctx.emit("loadingChange",t)}getLoading(){return this.loading}setValidationErrorByRowIndex(t,e,i){const s=this.rowIndexRowKeyMap.get(t),o=`${s}_${e}`,r=this.getRowForRowIndex(t),l=this.getColumnByKey(e);if(!s||!l||!r)return;const a=this.getItemValue(s,e),h=[{key:e,rowKey:s,rowIndex:t,colIndex:l.colIndex,column:l.column,row:r,value:a,message:i,field:e,fieldValue:a}];this.validationErrorMap.set(o,h)}setValidationError(t,e,i){const s=`${t}_${e}`;this.validationErrorMap.set(s,i)}clearValidationError(t,e){const i=`${t}_${e}`;this.validationErrorMap.has(i)&&this.validationErrorMap.delete(i)}getValidationError(t,e){const i=`${t}_${e}`;return this.validationErrorMap.get(i)||[]}getVirtualBodyCell(t,e){const i=this.getColumnByColIndex(e),s=this.getRowForRowIndex(t);return!i||!s?void 0:new dt(this.ctx,t,e,0,0,0,0,i,s.item,"body")}getVirtualBodyCellByKey(t,e){const i=this.getRowIndexForRowKey(t),s=this.getColIndexForKey(e);if(!(i===void 0||s===void 0))return this.getVirtualBodyCell(i,s)}hasMergeCell(t,e){let i=!1;for(let s=e[0];s<=e[1];s++)for(let o=t[0];o<=t[1];o++){const r=this.getVirtualBodyCell(s,o);if(r&&(r.rowspan!==1||r.colspan!==1)){i=!0;break}}return i}}class ne{constructor(t){n(this,"ctx");n(this,"history",[]);n(this,"historyIndex",-1);this.ctx=t,this.init()}init(){this.ctx.on("keydown",t=>{if(!this.ctx.editing){if(t.ctrlKey&&!t.shiftKey&&t.code==="KeyZ"||t.metaKey&&!t.shiftKey&&t.code==="KeyZ"){t.preventDefault(),this.ctx.clearSelector(),this.ctx.clearAutofill(),this.backState();return}if(t.ctrlKey&&t.code==="KeyY"||t.ctrlKey&&t.shiftKey&&t.code==="KeyZ"||t.metaKey&&t.shiftKey&&t.code==="KeyZ"){t.preventDefault(),this.ctx.clearSelector(),this.ctx.clearAutofill(),this.forwardState();return}}})}pushState(t){const{HISTORY_NUM:e=0,ENABLE_HISTORY:i}=this.ctx.config;i&&(this.history.push(t),this.history.length>e&&this.history.splice(0,1),this.historyIndex=this.history.length-1)}backState(){if(this.historyIndex>=0){const{changeList:t,scrollX:e,scrollY:i}=this.history[this.historyIndex],s=t.map(o=>({rowKey:o.rowKey,key:o.key,value:o.oldValue,row:{}}));this.ctx.setScroll(e,i),this.ctx.database.batchSetItemValue(s,!1,!1,"back"),this.historyIndex-=1}}forwardState(){if(this.historyIndex<this.history.length-1){this.historyIndex+=1;const{changeList:t}=this.history[this.historyIndex],e=t.map(i=>({rowKey:i.rowKey,key:i.key,value:i.newValue,row:{}}));this.ctx.database.batchSetItemValue(e,!1,!1,"forward")}}clear(){this.history=[],this.historyIndex=-1}}class le{constructor(t){n(this,"eventTasks",new Map);n(this,"ctx");this.ctx=t,this.init()}init(){this.bind(window,"resize",this.handleResize.bind(this)),this.bind(window,"mouseup",this.handleMouseUp.bind(this)),this.bind(window,"mousemove",this.handleMousemove.bind(this)),this.bind(window,"blur",this.handleOutsideMousedown.bind(this)),this.bind(window,"mousedown",this.handleOutsideMousedown.bind(this)),this.bind(this.ctx.stageElement,"click",this.handleClick.bind(this)),this.bind(window,"keydown",this.handleKeydown.bind(this)),this.bind(this.ctx.stageElement,"wheel",this.handleWheel.bind(this),{passive:!1}),this.bind(this.ctx.stageElement,"touchstart",this.handleTouchstart.bind(this),{passive:!1}),this.bind(this.ctx.stageElement,"touchend",this.handleTouchend.bind(this)),this.bind(this.ctx.stageElement,"touchmove",this.handleTouchmove.bind(this),{passive:!1}),this.bind(this.ctx.stageElement,"contextmenu",this.handleContextMenu.bind(this)),this.bind(this.ctx.stageElement,"mousedown",this.handleMouseDown.bind(this)),this.bind(this.ctx.stageElement,"dblclick",this.handleDblclick.bind(this)),this.bind(this.ctx.stageElement,"mouseover",this.handleMouseover.bind(this)),this.bind(this.ctx.stageElement,"mouseout",this.handleMouseout.bind(this)),document.addEventListener("selectionchange",this.selectionchange.bind(this))}selectionchange(){this.ctx.domSelectionStr="";const t=window.getSelection();t&&t.toString()&&(this.ctx.domSelectionStr=t.toString())}clearDomSelection(){const t=window.getSelection();t&&!t.isCollapsed&&t.removeAllRanges()}destroy(){this.eventTasks.forEach((t,e)=>{this.unbind(window,e,t)}),document.removeEventListener("selectionchange",this.selectionchange.bind(this)),this.eventTasks.clear()}handleResize(t){this.ctx.emit("resetHeader",t),this.ctx.emit("resize",t)}handleMouseDown(t){this.clearDomSelection(),t.button===0&&(this.ctx.mousedown=!0),this.ctx.containerElement.focus({preventScroll:!0}),this.ctx.emit("mousedown",t)}handleMousemove(t){this.ctx.emit("mousemove",t)}handleMouseUp(t){t.button===0&&(this.ctx.mousedown=!1),this.ctx.emit("mouseup",t)}handleClick(t){this.ctx.emit("click",t)}handleKeydown(t){const{ENABLE_KEYBOARD:e}=this.ctx.config;e&&this.ctx.isTarget(t)&&this.ctx.emit("keydown",t)}handleWheel(t){this.ctx.emit("wheel",t)}handleTouchstart(t){this.ctx.emit("touchstart",t)}handleTouchend(t){this.ctx.emit("touchend",t)}handleTouchmove(t){this.ctx.emit("touchmove",t)}handleContextMenu(t){t.preventDefault(),this.ctx.emit("contextMenu",t)}handleMouseover(t){this.ctx.isMouseoverTargetContainer=!0,this.ctx.emit("mouseover",t)}handleMouseout(t){this.ctx.isMouseoverTargetContainer=!1,this.ctx.emit("mouseout",t)}handleDblclick(t){this.ctx.emit("dblclick",t)}handleOutsideMousedown(t){this.ctx.selector.enable&&(t.target instanceof Window||t.target instanceof Node&&!this.ctx.containerElement.contains(t.target))&&this.ctx.emit("outsideMousedown",t)}bind(t,e,i,s){t.addEventListener(e,i,s),this.eventTasks.set(e,i)}unbind(t,e,i){t.removeEventListener(e,i),this.eventTasks.delete(e)}}class ae{constructor(){n(this,"events",new Map)}has(t){return this.events.has(t)}on(t,e){const i=this.events.get(t)||[];i.push(e),this.events.set(t,i)}once(t,e){const i=(...s)=>{e(...s),this.off(t,i)};return this.on(t,i),this}off(t,e){const i=this.events.get(t);if(i){const s=i.indexOf(e);s>=0&&(i.splice(s,1),i.length===0?this.events.delete(t):this.events.set(t,i))}}emit(t,...e){const i=this.events.get(t);i&&i.forEach(s=>{s(...e)})}destroy(){this.events.clear()}}class he{constructor(t){n(this,"ctx");const e=t.getContext("2d");if(!e)throw new Error("canvas context not found");this.ctx=e}scale(t){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.scale(t,t)}save(){this.ctx.save()}restore(){this.ctx.restore()}translate(t,e){this.ctx.translate(t,e)}setCursor(t="default"){this.ctx.canvas.style.cursor=t}clear(t=0,e=0,i,s){this.ctx.clearRect(t,e,i||this.ctx.canvas.width,s||this.ctx.canvas.height)}drawShadow(t,e,i,s,o){const{fillColor:r,side:l,shadowWidth:a,colorStart:h,colorEnd:d}=o;this.ctx.save(),r&&(this.ctx.fillStyle=r,this.ctx.fillRect(t,e,i,s));let f;switch(l){case"left":f=this.ctx.createLinearGradient(t-a,e,t,e),f.addColorStop(0,h),f.addColorStop(1,d),this.ctx.fillStyle=f,this.ctx.fillRect(t-a,e,a,s);break;case"right":f=this.ctx.createLinearGradient(t+i,e,t+i+a,e),f.addColorStop(0,h),f.addColorStop(1,d),this.ctx.fillStyle=f,this.ctx.fillRect(t+i,e,a,s);break;case"top":f=this.ctx.createLinearGradient(t,e-a,t,e),f.addColorStop(0,h),f.addColorStop(1,d),this.ctx.fillStyle=f,this.ctx.fillRect(t,e-a,i,a);break;case"bottom":f=this.ctx.createLinearGradient(t,e+s,t,e+s+a),f.addColorStop(0,h),f.addColorStop(1,d),this.ctx.fillStyle=f,this.ctx.fillRect(t,e+s,i,a);break;default:console.error("Invalid side specified for shadow");break}}drawLine(t,e){if(t.length<4||t.length%2!==0)throw new Error("A valid array of points is required to draw a line");this.ctx.save();const{borderColor:i="black",borderWidth:s=1}=e;this.ctx.beginPath(),this.ctx.moveTo(t[0]-.5,t[1]-.5);for(let o=2;o<t.length;o+=2)this.ctx.lineTo(t[o]-.5,t[o+1]-.5);this.ctx.strokeStyle=i,this.ctx.lineWidth=s,e.lineDash&&(this.ctx.lineDashOffset=4,this.ctx.setLineDash(e.lineDash)),e.fillColor&&(this.ctx.fillStyle=e.fillColor,this.ctx.fill()),e.borderColor&&(this.ctx.strokeStyle=e.borderColor),this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore()}drawImage(t,e,i,s,o){this.ctx.save(),this.ctx.drawImage(t,e,i,s,o),this.ctx.restore()}drawRect(t,e,i,s,{borderWidth:o=1,borderColor:r,fillColor:l,radius:a=0}={}){if(this.ctx.save(),this.ctx.beginPath(),l!==void 0&&(this.ctx.fillStyle=l),r!==void 0&&(this.ctx.lineWidth=o,this.ctx.strokeStyle=r),a===0)this.ctx.rect(t-.5,e-.5,i,s);else{const[h,d,f,x]=typeof a=="number"?[a,a,a,a]:a;this.ctx.moveTo(t+h,e),this.ctx.arcTo(t+i,e,t+i,e+d,d),this.ctx.arcTo(t+i,e+s,t+i-f,e+s,f),this.ctx.arcTo(t,e+s,t,e+s-x,x),this.ctx.arcTo(t,e,t+h,e,h)}l!==void 0&&this.ctx.fill(),r!==void 0&&this.ctx.stroke(),this.ctx.restore()}drawText(t="",e,i,s,o,r={}){this.ctx.save();const{font:l="12px Arial",align:a="center",color:h="#495060",padding:d=0,verticalAlign:f="middle"}=r;this.ctx.font=l,this.ctx.fillStyle=h,this.ctx.textBaseline=f,this.ctx.textAlign=a;let x=0;f==="top"?x=i+d:f==="bottom"?x=i+o-d:x=i+(o+1)/2;let u=0;a==="left"?u=e+d:a==="right"?u=e+s-d:u=e+s/2;const{_text:p,ellipsis:g}=this.handleEllipsis(t,s,d,l);return this.ctx.fillText(p,u,x),this.ctx.restore(),g}handleEllipsis(t,e,i=0,s="12px Arial"){let o=!1,r=t;if(this.ctx.font=s,t==null||t==="")return{_text:"",ellipsis:o};const l=this.ctx.measureText("...").width,a=this.ctx.measureText(t).width;if(a&&a+l>=e-i*2){o=!0;let h=0;for(let d=0;d<t.length;d++)if(h+=this.ctx.measureText(t[d]).width,h>=e-i*2-l){r=t.slice(0,d)+"...";break}}return{_text:r,ellipsis:o}}}class Lt{constructor(t){n(this,"_config",{});n(this,"CSS_PREFIX","e-virt-table");n(this,"ICONS",[]);n(this,"ROW_KEY","");n(this,"DISABLED",!1);n(this,"HEADER_FONT","12px normal Arial");n(this,"BODY_FONT","12px normal Arial");n(this,"BORDER",!0);n(this,"STRIPE",!1);n(this,"STRIPE_COLOR","#fafafa");n(this,"BORDER_COLOR","#e1e6eb");n(this,"WIDTH",0);n(this,"RESIZE_MIN_WIDTH",40);n(this,"HEIGHT",0);n(this,"PLACEHOLDER_COLOR","#CDD0DC");n(this,"EMPTY_BODY_HEIGHT",120);n(this,"EMPTY_CUSTOM_STYLE",{});n(this,"EMPTY_TEXT","暂无数