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.

15 lines 169 kB
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(":root{--e-virt-table-color-white: #fff;--e-virt-table-color-black: #000000;--e-virt-table-color-primary: rgb(82, 146, 247);--e-virt-table-text-color-primary: #333;--e-virt-table-text-color-regular: #666;--e-virt-table-text-color-secondary: #999;--e-virt-table-box-shadow: 0 2px 12px 0 #0000001a;--e-virt-table-editor-bg-color: #fff;--e-virt-table-border-color: #e1e6eb}.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(--e-virt-table-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(--e-virt-table-editor-bg-color);border:2px solid var(--e-virt-table-color-primary);box-sizing:border-box;box-shadow:var(--e-virt-table-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(--e-virt-table-color-white);overflow-y:auto;resize:none}.e-virt-table-context-menu{position:absolute;font-size:14px;color:var(--e-virt-table-text-color-regular);background-color:var(--e-virt-table-color-white);border-radius:4px;border:1px solid #e4e7ed;box-shadow:var(--e-virt-table-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(--e-virt-table-text-color-regular)}.e-virt-table-context-menu-item:hover{color:var(--e-virt-table-color-primary);background-color:#f5f7fa}")),document.head.appendChild(e)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})(); (function(D,F){typeof exports=="object"&&typeof module<"u"?module.exports=F():typeof define=="function"&&define.amd?define(F):(D=typeof globalThis<"u"?globalThis:D||self,D.EVirtTable=F())})(this,function(){"use strict";var ts=Object.defineProperty;var es=(D,F,z)=>F in D?ts(D,F,{enumerable:!0,configurable:!0,writable:!0,value:z}):D[F]=z;var l=(D,F,z)=>es(D,typeof F!="symbol"?F+"":F,z);function D(){return D=Object.assign?Object.assign.bind():function(a){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(a[i]=e[i])}return a},D.apply(this,arguments)}function F(a,t){a.prototype=Object.create(t.prototype),a.prototype.constructor=a,st(a,t)}function z(a){return z=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},z(a)}function st(a,t){return st=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,s){return i.__proto__=s,i},st(a,t)}function Ce(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ft(a,t,e){return Ce()?ft=Reflect.construct.bind():ft=function(s,r,o){var n=[null];n.push.apply(n,r);var h=Function.bind.apply(s,n),c=new h;return o&&st(c,o.prototype),c},ft.apply(null,arguments)}function be(a){return Function.toString.call(a).indexOf("[native code]")!==-1}function mt(a){var t=typeof Map=="function"?new Map:void 0;return mt=function(i){if(i===null||!be(i))return i;if(typeof i!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(i))return t.get(i);t.set(i,s)}function s(){return ft(i,arguments,z(this).constructor)}return s.prototype=Object.create(i.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),st(s,i)},mt(a)}var ve=/%[sdj%]/g,Xt=function(){};typeof process<"u"&&process.env&&process.env.NODE_ENV!=="production"&&typeof window<"u"&&typeof document<"u"&&(Xt=function(t,e){typeof console<"u"&&console.warn&&typeof ASYNC_VALIDATOR_NO_WARNING>"u"&&e.every(function(i){return typeof i=="string"})&&console.warn(t,e)});function Ct(a){if(!a||!a.length)return null;var t={};return a.forEach(function(e){var i=e.field;t[i]=t[i]||[],t[i].push(e)}),t}function k(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),i=1;i<t;i++)e[i-1]=arguments[i];var s=0,r=e.length;if(typeof a=="function")return a.apply(null,e);if(typeof a=="string"){var o=a.replace(ve,function(n){if(n==="%%")return"%";if(s>=r)return n;switch(n){case"%s":return String(e[s++]);case"%d":return Number(e[s++]);case"%j":try{return JSON.stringify(e[s++])}catch{return"[Circular]"}break;default:return n}});return o}return a}function Re(a){return a==="string"||a==="url"||a==="hex"||a==="email"||a==="date"||a==="pattern"}function H(a,t){return!!(a==null||t==="array"&&Array.isArray(a)&&!a.length||Re(t)&&typeof a=="string"&&!a)}function Ie(a,t,e){var i=[],s=0,r=a.length;function o(n){i.push.apply(i,n||[]),s++,s===r&&e(i)}a.forEach(function(n){t(n,o)})}function Nt(a,t,e){var i=0,s=a.length;function r(o){if(o&&o.length){e(o);return}var n=i;i=i+1,n<s?t(a[n],r):e([])}r([])}function _e(a){var t=[];return Object.keys(a).forEach(function(e){t.push.apply(t,a[e]||[])}),t}var Kt=function(a){F(t,a);function t(e,i){var s;return s=a.call(this,"Async Validation Error")||this,s.errors=e,s.fields=i,s}return t}(mt(Error));function Oe(a,t,e,i,s){if(t.first){var r=new Promise(function(u,x){var p=function(y){return i(y),y.length?x(new Kt(y,Ct(y))):u(s)},g=_e(a);Nt(g,e,p)});return r.catch(function(u){return u}),r}var o=t.firstFields===!0?Object.keys(a):t.firstFields||[],n=Object.keys(a),h=n.length,c=0,d=[],f=new Promise(function(u,x){var p=function(w){if(d.push.apply(d,w),c++,c===h)return i(d),d.length?x(new Kt(d,Ct(d))):u(s)};n.length||(i(d),u(s)),n.forEach(function(g){var w=a[g];o.indexOf(g)!==-1?Nt(w,e,p):Ie(w,e,p)})});return f.catch(function(u){return u}),f}function Ae(a){return!!(a&&a.message!==void 0)}function Le(a,t){for(var e=a,i=0;i<t.length;i++){if(e==null)return e;e=e[t[i]]}return e}function Bt(a,t){return function(e){var i;return a.fullFields?i=Le(t,a.fullFields):i=t[e.field||a.fullField],Ae(e)?(e.field=e.field||a.fullField,e.fieldValue=i,e):{message:typeof e=="function"?e():e,fieldValue:i,field:e.field||a.fullField}}}function Yt(a,t){if(t){for(var e in t)if(t.hasOwnProperty(e)){var i=t[e];typeof i=="object"&&typeof a[e]=="object"?a[e]=D({},a[e],i):a[e]=i}}return a}var Vt=function(t,e,i,s,r,o){t.required&&(!i.hasOwnProperty(t.field)||H(e,o||t.type))&&s.push(k(r.messages.required,t.fullField))},Se=function(t,e,i,s,r){(/^\s+$/.test(e)||e==="")&&s.push(k(r.messages.whitespace,t.fullField))},xt,Te=function(){if(xt)return xt;var a="[a-fA-F\\d:]",t=function(C){return C&&C.includeBoundaries?"(?:(?<=\\s|^)(?="+a+")|(?<="+a+")(?=\\s|$))":""},e="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",i="[a-fA-F\\d]{1,4}",s=(` (?: (?:`+i+":){7}(?:"+i+`|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8 (?:`+i+":){6}(?:"+e+"|:"+i+`|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4 (?:`+i+":){5}(?::"+e+"|(?::"+i+`){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4 (?:`+i+":){4}(?:(?::"+i+"){0,1}:"+e+"|(?::"+i+`){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4 (?:`+i+":){3}(?:(?::"+i+"){0,2}:"+e+"|(?::"+i+`){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4 (?:`+i+":){2}(?:(?::"+i+"){0,3}:"+e+"|(?::"+i+`){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4 (?:`+i+":){1}(?:(?::"+i+"){0,4}:"+e+"|(?::"+i+`){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4 (?::(?:(?::`+i+"){0,5}:"+e+"|(?::"+i+`){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4 )(?:%[0-9a-zA-Z]{1,})? // %eth0 %1 `).replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),r=new RegExp("(?:^"+e+"$)|(?:^"+s+"$)"),o=new RegExp("^"+e+"$"),n=new RegExp("^"+s+"$"),h=function(C){return C&&C.exact?r:new RegExp("(?:"+t(C)+e+t(C)+")|(?:"+t(C)+s+t(C)+")","g")};h.v4=function(E){return E&&E.exact?o:new RegExp(""+t(E)+e+t(E),"g")},h.v6=function(E){return E&&E.exact?n:new RegExp(""+t(E)+s+t(E),"g")};var c="(?:(?:[a-z]+:)?//)",d="(?:\\S+(?::\\S*)?@)?",f=h.v4().source,u=h.v6().source,x="(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)",p="(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*",g="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))",w="(?::\\d{2,5})?",y='(?:[/?#][^\\s"]*)?',m="(?:"+c+"|www\\.)"+d+"(?:localhost|"+f+"|"+u+"|"+x+p+g+")"+w+y;return xt=new RegExp("(?:^"+m+"$)","i"),xt},Wt={email:/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,hex:/^#?([a-f0-9]{6}|[a-f0-9]{3})$/i},rt={integer:function(t){return rt.number(t)&&parseInt(t,10)===t},float:function(t){return rt.number(t)&&!rt.integer(t)},array:function(t){return Array.isArray(t)},regexp:function(t){if(t instanceof RegExp)return!0;try{return!!new RegExp(t)}catch{return!1}},date:function(t){return typeof t.getTime=="function"&&typeof t.getMonth=="function"&&typeof t.getYear=="function"&&!isNaN(t.getTime())},number:function(t){return isNaN(t)?!1:typeof t=="number"},object:function(t){return typeof t=="object"&&!rt.array(t)},method:function(t){return typeof t=="function"},email:function(t){return typeof t=="string"&&t.length<=320&&!!t.match(Wt.email)},url:function(t){return typeof t=="string"&&t.length<=2048&&!!t.match(Te())},hex:function(t){return typeof t=="string"&&!!t.match(Wt.hex)}},Me=function(t,e,i,s,r){if(t.required&&e===void 0){Vt(t,e,i,s,r);return}var o=["integer","float","array","regexp","object","method","email","number","date","url","hex"],n=t.type;o.indexOf(n)>-1?rt[n](e)||s.push(k(r.messages.types[n],t.fullField,t.type)):n&&typeof e!==t.type&&s.push(k(r.messages.types[n],t.fullField,t.type))},He=function(t,e,i,s,r){var o=typeof t.len=="number",n=typeof t.min=="number",h=typeof t.max=="number",c=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,d=e,f=null,u=typeof e=="number",x=typeof e=="string",p=Array.isArray(e);if(u?f="number":x?f="string":p&&(f="array"),!f)return!1;p&&(d=e.length),x&&(d=e.replace(c,"_").length),o?d!==t.len&&s.push(k(r.messages[f].len,t.fullField,t.len)):n&&!h&&d<t.min?s.push(k(r.messages[f].min,t.fullField,t.min)):h&&!n&&d>t.max?s.push(k(r.messages[f].max,t.fullField,t.max)):n&&h&&(d<t.min||d>t.max)&&s.push(k(r.messages[f].range,t.fullField,t.min,t.max))},Z="enum",De=function(t,e,i,s,r){t[Z]=Array.isArray(t[Z])?t[Z]:[],t[Z].indexOf(e)===-1&&s.push(k(r.messages[Z],t.fullField,t[Z].join(", ")))},Fe=function(t,e,i,s,r){if(t.pattern){if(t.pattern instanceof RegExp)t.pattern.lastIndex=0,t.pattern.test(e)||s.push(k(r.messages.pattern.mismatch,t.fullField,e,t.pattern));else if(typeof t.pattern=="string"){var o=new RegExp(t.pattern);o.test(e)||s.push(k(r.messages.pattern.mismatch,t.fullField,e,t.pattern))}}},_={required:Vt,whitespace:Se,type:Me,range:He,enum:De,pattern:Fe},ke=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e,"string")&&!t.required)return i();_.required(t,e,s,o,r,"string"),H(e,"string")||(_.type(t,e,s,o,r),_.range(t,e,s,o,r),_.pattern(t,e,s,o,r),t.whitespace===!0&&_.whitespace(t,e,s,o,r))}i(o)},Xe=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e)&&!t.required)return i();_.required(t,e,s,o,r),e!==void 0&&_.type(t,e,s,o,r)}i(o)},Ne=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(e===""&&(e=void 0),H(e)&&!t.required)return i();_.required(t,e,s,o,r),e!==void 0&&(_.type(t,e,s,o,r),_.range(t,e,s,o,r))}i(o)},Ke=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e)&&!t.required)return i();_.required(t,e,s,o,r),e!==void 0&&_.type(t,e,s,o,r)}i(o)},Be=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e)&&!t.required)return i();_.required(t,e,s,o,r),H(e)||_.type(t,e,s,o,r)}i(o)},Ye=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e)&&!t.required)return i();_.required(t,e,s,o,r),e!==void 0&&(_.type(t,e,s,o,r),_.range(t,e,s,o,r))}i(o)},Ve=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e)&&!t.required)return i();_.required(t,e,s,o,r),e!==void 0&&(_.type(t,e,s,o,r),_.range(t,e,s,o,r))}i(o)},We=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(e==null&&!t.required)return i();_.required(t,e,s,o,r,"array"),e!=null&&(_.type(t,e,s,o,r),_.range(t,e,s,o,r))}i(o)},Pe=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e)&&!t.required)return i();_.required(t,e,s,o,r),e!==void 0&&_.type(t,e,s,o,r)}i(o)},ze="enum",$e=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e)&&!t.required)return i();_.required(t,e,s,o,r),e!==void 0&&_[ze](t,e,s,o,r)}i(o)},qe=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e,"string")&&!t.required)return i();_.required(t,e,s,o,r),H(e,"string")||_.pattern(t,e,s,o,r)}i(o)},Ge=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e,"date")&&!t.required)return i();if(_.required(t,e,s,o,r),!H(e,"date")){var h;e instanceof Date?h=e:h=new Date(e),_.type(t,h,s,o,r),h&&_.range(t,h.getTime(),s,o,r)}}i(o)},je=function(t,e,i,s,r){var o=[],n=Array.isArray(e)?"array":typeof e;_.required(t,e,s,o,r,n),i(o)},bt=function(t,e,i,s,r){var o=t.type,n=[],h=t.required||!t.required&&s.hasOwnProperty(t.field);if(h){if(H(e,o)&&!t.required)return i();_.required(t,e,s,n,r,o),H(e,o)||_.type(t,e,s,n,r)}i(n)},Ue=function(t,e,i,s,r){var o=[],n=t.required||!t.required&&s.hasOwnProperty(t.field);if(n){if(H(e)&&!t.required)return i();_.required(t,e,s,o,r)}i(o)},ot={string:ke,method:Xe,number:Ne,boolean:Ke,regexp:Be,integer:Ye,float:Ve,array:We,object:Pe,enum:$e,pattern:qe,date:Ge,url:bt,hex:bt,email:bt,required:je,any:Ue};function vt(){return{default:"Validation error on field %s",required:"%s is required",enum:"%s must be one of %s",whitespace:"%s cannot be empty",date:{format:"%s date %s is invalid for format %s",parse:"%s date could not be parsed, %s is invalid ",invalid:"%s date %s is invalid"},types:{string:"%s is not a %s",method:"%s is not a %s (function)",array:"%s is not an %s",object:"%s is not an %s",number:"%s is not a %s",date:"%s is not a %s",boolean:"%s is not a %s",integer:"%s is not an %s",float:"%s is not a %s",regexp:"%s is not a valid %s",email:"%s is not a valid %s",url:"%s is not a valid %s",hex:"%s is not a valid %s"},string:{len:"%s must be exactly %s characters",min:"%s must be at least %s characters",max:"%s cannot be longer than %s characters",range:"%s must be between %s and %s characters"},number:{len:"%s must equal %s",min:"%s cannot be less than %s",max:"%s cannot be greater than %s",range:"%s must be between %s and %s"},array:{len:"%s must be exactly %s in length",min:"%s cannot be less than %s in length",max:"%s cannot be greater than %s in length",range:"%s must be between %s and %s in length"},pattern:{mismatch:"%s value %s does not match pattern %s"},clone:function(){var t=JSON.parse(JSON.stringify(this));return t.clone=this.clone,t}}}var Rt=vt(),nt=function(){function a(e){this.rules=null,this._messages=Rt,this.define(e)}var t=a.prototype;return t.define=function(i){var s=this;if(!i)throw new Error("Cannot configure a schema with no rules");if(typeof i!="object"||Array.isArray(i))throw new Error("Rules must be an object");this.rules={},Object.keys(i).forEach(function(r){var o=i[r];s.rules[r]=Array.isArray(o)?o:[o]})},t.messages=function(i){return i&&(this._messages=Yt(vt(),i)),this._messages},t.validate=function(i,s,r){var o=this;s===void 0&&(s={}),r===void 0&&(r=function(){});var n=i,h=s,c=r;if(typeof h=="function"&&(c=h,h={}),!this.rules||Object.keys(this.rules).length===0)return c&&c(null,n),Promise.resolve(n);function d(g){var w=[],y={};function m(C){if(Array.isArray(C)){var b;w=(b=w).concat.apply(b,C)}else w.push(C)}for(var E=0;E<g.length;E++)m(g[E]);w.length?(y=Ct(w),c(w,y)):c(null,n)}if(h.messages){var f=this.messages();f===Rt&&(f=vt()),Yt(f,h.messages),h.messages=f}else h.messages=this.messages();var u={},x=h.keys||Object.keys(this.rules);x.forEach(function(g){var w=o.rules[g],y=n[g];w.forEach(function(m){var E=m;typeof E.transform=="function"&&(n===i&&(n=D({},n)),y=n[g]=E.transform(y)),typeof E=="function"?E={validator:E}:E=D({},E),E.validator=o.getValidationMethod(E),E.validator&&(E.field=g,E.fullField=E.fullField||g,E.type=o.getType(E),u[g]=u[g]||[],u[g].push({rule:E,value:y,source:n,field:g}))})});var p={};return Oe(u,h,function(g,w){var y=g.rule,m=(y.type==="object"||y.type==="array")&&(typeof y.fields=="object"||typeof y.defaultField=="object");m=m&&(y.required||!y.required&&g.value),y.field=g.field;function E(R,A){return D({},A,{fullField:y.fullField+"."+R,fullFields:y.fullFields?[].concat(y.fullFields,[R]):[R]})}function C(R){R===void 0&&(R=[]);var A=Array.isArray(R)?R:[R];!h.suppressWarning&&A.length&&a.warning("async-validator:",A),A.length&&y.message!==void 0&&(A=[].concat(y.message));var L=A.map(Bt(y,n));if(h.first&&L.length)return p[y.field]=1,w(L);if(!m)w(L);else{if(y.required&&!g.value)return y.message!==void 0?L=[].concat(y.message).map(Bt(y,n)):h.error&&(L=[h.error(y,k(h.messages.required,y.field))]),w(L);var I={};y.defaultField&&Object.keys(g.value).map(function(O){I[O]=y.defaultField}),I=D({},I,g.rule.fields);var v={};Object.keys(I).forEach(function(O){var M=I[O],T=Array.isArray(M)?M:[M];v[O]=T.map(E.bind(null,O))});var S=new a(v);S.messages(h.messages),g.rule.options&&(g.rule.options.messages=h.messages,g.rule.options.error=h.error),S.validate(g.value,g.rule.options||h,function(O){var M=[];L&&L.length&&M.push.apply(M,L),O&&O.length&&M.push.apply(M,O),w(M.length?M:null)})}}var b;if(y.asyncValidator)b=y.asyncValidator(y,g.value,C,g.source,h);else if(y.validator){try{b=y.validator(y,g.value,C,g.source,h)}catch(R){console.error==null||console.error(R),h.suppressValidatorError||setTimeout(function(){throw R},0),C(R.message)}b===!0?C():b===!1?C(typeof y.message=="function"?y.message(y.fullField||y.field):y.message||(y.fullField||y.field)+" fails"):b instanceof Array?C(b):b instanceof Error&&C(b.message)}b&&b.then&&b.then(function(){return C()},function(R){return C(R)})},function(g){d(g)},n)},t.getType=function(i){if(i.type===void 0&&i.pattern instanceof RegExp&&(i.type="pattern"),typeof i.validator!="function"&&i.type&&!ot.hasOwnProperty(i.type))throw new Error(k("Unknown rule type %s",i.type));return i.type||"string"},t.getValidationMethod=function(i){if(typeof i.validator=="function")return i.validator;var s=Object.keys(i),r=s.indexOf("message");return r!==-1&&s.splice(r,1),s.length===1&&s[0]==="required"?ot.required:ot[this.getType(i)]||void 0},a}();nt.register=function(t,e){if(typeof e!="function")throw new Error("Cannot register a validator by type, validator is not a function");ot[t]=e},nt.warning=Xt,nt.messages=Rt,nt.validators=ot;function Pt(){return"xxxxxxxxxxxxxxxxxx".replace(/[x]/g,function(a){const t=Math.random()*16|0;return(a==="x"?t:t&3|8).toString(16)})}function zt(a,t){let e=0,i;return function(...s){const r=new Date().getTime(),o=r-e;!e||o>=t?(a.apply(this,s),e=r):i||(i=setTimeout(()=>{a.apply(this,s),e=new Date().getTime(),i=void 0},t-o))}}function $t(a=[]){return a.length?a.map(t=>$t(t.children)+1).sort((t,e)=>e-t)[0]:0}function Ze(a=[]){let t=[],e=[],i=[];return a.forEach(s=>{s.fixed==="left"?t.push(s):s.fixed==="right"?i.push(s):e.push(s)}),[...t.sort((s,r)=>(s.sort??0)-(r.sort??0)),...e.sort((s,r)=>(s.sort??0)-(r.sort??0)),...i.sort((s,r)=>(s.sort??0)-(r.sort??0))]}function qt(a=[],t=1,e=0){return a.map(i=>{if(i.children){let s=0,r=i.fixed;i.children.forEach(n=>{n.fixed=r});const o=qt(i.children,t-1,e+1);return o&&o.forEach(n=>{s+=n.colspan??0}),{...i,width:i.width,level:e,rowspan:1,colspan:s,children:o}}return{...i,level:e,rowspan:t,colspan:1}})}function It(a=[]){let t=[];return a.forEach(e=>{e.children?t=t.concat(It(e.children)):t.push(e)}),t}const Gt=/^(\r\n|\n\r|\r|\n)/,Je=/^[^\t\r\n]+/,jt=/^\t/;function Qe(a){let t=[[""]];if(a.length===0)return t;let e=0,i=0,s;for(;a.length>0&&s!==a.length;)if(s=a.length,a.match(jt))a=a.replace(jt,""),e+=1,t[i][e]="";else if(a.match(Gt))a=a.replace(Gt,""),e=0,i+=1,t[i]=[""];else{let r="";if(a.startsWith('"')){let o=0,n=!0;for(;n;){const h=a.slice(0,1);h==='"'&&(o+=1),r+=h,a=a.slice(1),(a.length===0||a.match(/^[\t\r\n]/)&&o%2===0)&&(n=!1)}r=r.replace(/^"/,"").replace(/"$/,"").replace(/["]*/g,h=>new Array(Math.floor(h.length/2)).fill('"').join(""))}else{const o=a.match(Je);r=o?o[0]:"",a=a.slice(r.length)}t[i][e]=r}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 ti(a){let t,e,i,s,r="",o;for(t=0,e=a.length;t<e;t+=1){for(s=a[t].length,i=0;i<s;i+=1)i>0&&(r+=" "),o=a[t][i],typeof o=="string"?o.indexOf(` `)>-1?r+=`"${o.replace(/"/g,'""')}"`:r+=o:o==null?r+="":r+=o;t!==e-1&&(r+=` `)}return r}function Ut(a,t,e=[]){let i=0;const s=[];return a.forEach((r,o)=>{if(o===0)s.push(1);else{const n=e.reduce((c,d)=>`${c}${r[d]??""}`,"")||r[t],h=e.reduce((c,d)=>`${c}${a[o-1][d]??""}`,"")||a[o-1][t];n===h?(s[i]+=1,s.push(0)):(s.push(1),i=o)}}),s}function Zt(a,t){let e="",i="";const s={};return t.forEach((r,o)=>{o===0?(e=r.key,i=r.key,s[r.key]=1):a[r.key]===a[e]?(s[r.key]=0,s[i]+=1):(s[r.key]=1,e=r.key,i=r.key)}),s}function ei(a,t,e=[]){const{visibleRows:i,rowIndex:s,headIndex:r}=a,o=Ut(i,t,e);return o[s-r]===0?{rowspan:0,colspan:0,relationRowKeys:e,mergeRow:!0}:{rowspan:o[s-r],colspan:1,relationRowKeys:e,mergeRow:!0}}function ii(a,t=[]){const{column:e,row:i,visibleLeafColumns:s}=a,r=s.filter(o=>t.includes(o.key));if(t.includes(e.key)){const o=Zt(i,r);return o[e.key]===0?{rowspan:0,colspan:0,relationColKeys:t,mergeCol:!0}:{rowspan:1,colspan:o[e.key],relationColKeys:t,mergeCol:!0}}}class Jt{constructor(t,e,i,s,r,o,n){l(this,"ctx");l(this,"x",0);l(this,"y",0);l(this,"width",0);l(this,"height",0);l(this,"fixed");l(this,"cellType");this.ctx=t,this.x=e,this.y=i,this.width=s,this.height=r,this.fixed=n,this.cellType=o}isHorizontalVisible(){if(this.fixed)return!0;const{stageWidth:t,fixedLeftWidth:e,scrollX:i,fixedRightWidth:s}=this.ctx,r=t;return!(this.x+this.width-e-i<=0||this.x-i>=r-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+1}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 _t extends Jt{constructor(e,i,s,r,o,n,h,c,d,f="body"){super(e,r,o,n,h,f,c.fixed);l(this,"formatter");l(this,"formatterFooter");l(this,"hoverIconName","");l(this,"operation",!1);l(this,"align");l(this,"verticalAlign");l(this,"fixed");l(this,"type");l(this,"editorType");l(this,"editorProps");l(this,"cellType");l(this,"level");l(this,"colspan",1);l(this,"rowspan",1);l(this,"mergeRow",!1);l(this,"mergeCol",!1);l(this,"relationRowKeys",[]);l(this,"relationColKeys",[]);l(this,"key");l(this,"column");l(this,"rowIndex");l(this,"colIndex");l(this,"rowKey");l(this,"row");l(this,"value");l(this,"render");l(this,"renderFooter");l(this,"style",{});l(this,"rules",[]);l(this,"message","");l(this,"text","");l(this,"displayText","");l(this,"visibleWidth",0);l(this,"visibleHeight",0);l(this,"isHasChanged",!1);l(this,"drawX",0);l(this,"drawY",0);l(this,"drawCellBgColor","");l(this,"drawCellSkyBgColor","");l(this,"drawTextColor","");l(this,"drawTextX",0);l(this,"drawTextY",0);l(this,"drawImageX",0);l(this,"drawImageY",0);l(this,"drawImageWidth",0);l(this,"drawImageHeight",0);l(this,"drawImageName","");l(this,"drawImageSource");l(this,"ellipsis",!1);l(this,"rowExpand",!1);l(this,"rowHasChildren",!1);l(this,"overflowTooltipShow",!0);l(this,"overflowTooltipMaxWidth",500);l(this,"overflowTooltipPlacement","top");this.visibleWidth=this.width,this.visibleHeight=this.height,this.colIndex=s,this.rowIndex=i,this.key=c.key,this.type=c.type||"",this.editorType=c.editorType||"text",this.editorProps=c.editorProps||{},this.cellType=f,this.align=c.align||"center",this.verticalAlign=c.verticalAlign||"middle",this.fixed=c.fixed,this.level=c.level||0,this.operation=c.operation||!1,this.column=c,this.rules=c.rules||[],this.row=d,this.rowKey=this.cellType==="body"?this.ctx.database.getRowKeyForRowIndex(i):`${this.cellType}_${this.rowIndex}`,this.value=this.getValue(),this.render=c.render,this.overflowTooltipShow=c.overflowTooltipShow!==!1,this.overflowTooltipMaxWidth=c.overflowTooltipMaxWidth||500,this.overflowTooltipPlacement=c.overflowTooltipPlacement||"top",this.renderFooter=c.renderFooter,this.hoverIconName=c.hoverIconName,this.formatter=c.formatter,this.formatterFooter=c.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:r=1,relationRowKeys:o,relationColKeys:n,mergeRow:h=!1,mergeCol:c=!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(o)&&o.length>0?this.relationRowKeys=o:this.relationRowKeys=[this.key],Array.isArray(n)&&n.length>0?this.relationColKeys=n:this.relationColKeys=[this.key],this.mergeCol=c,this.mergeRow=h,this.colspan=s,this.rowspan=r,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:r,props:o={}}=s;this.editorType=r,this.editorProps=o}}}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 r,o=0,n="";if(this.type==="tree"&&s==="body"){const h=this.ctx.database.getRowForRowKey(i),{expand:c=!1,hasChildren:d=!1,expandLoading:f=!1,level:u=0}=h||{};if(this.rowExpand=c,this.rowHasChildren=d,f){const g=this.ctx.icons.get("loading");n="loading",r=g,o=u*8}else if(d){const g=this.ctx.icons.get("expand"),w=this.ctx.icons.get("shrink");r=c?w:g,n=c?"shrink":"expand",o=u*8}else o=u*8;let x=20,p=20;if(r){let g=this.drawX+o+e,w=this.drawY+(this.visibleHeight-p)/2;this.ctx.paint.drawImage(r,g,w,x,p),this.drawImageX=g,this.drawImageY=w,this.drawImageWidth=x,this.drawImageHeight=p,this.drawImageName=n,this.drawImageSource=r}this.align="left",this.drawTextX=o+this.drawX+x-.5}}updateContainer(){const{BODY_BG_COLOR:e,EDIT_BG_COLOR:i,BODY_CELL_STYLE_METHOD:s,FOOTER_CELL_STYLE_METHOD:r,READONLY_TEXT_COLOR:o,FOOTER_BG_COLOR:n,HIGHLIGHT_SELECTED_ROW:h,HIGHLIGHT_SELECTED_ROW_COLOR:c,HIGHLIGHT_HOVER_ROW:d,HIGHLIGHT_HOVER_ROW_COLOR:f}=this.ctx.config;if(this.cellType==="footer"){let y=n,m=o;if(typeof r=="function"){const E=r,{backgroundColor:C,color:b}=E({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()})||{};C&&(y=C),b&&(m=b)}this.drawCellSkyBgColor="transparent",this.drawCellBgColor=y,this.drawTextColor=m;return}let u="transparent";const x=this.ctx.focusCell,p=this.ctx.hoverCell;d&&(p==null?void 0:p.rowKey)===this.rowKey&&(u=f),h&&(x==null?void 0:x.rowKey)===this.rowKey&&(u=c),this.drawCellSkyBgColor=u;let g=e,w=o;if(["index","index-selection","selection"].includes(this.type)){this.drawCellBgColor=e,this.drawTextColor=o;return}if(this.ctx.database.getReadonly(this.rowKey,this.key)||(g=i,w=o),typeof s=="function"){const y=s,{backgroundColor:m,color:E}=y({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,isHasChanged:this.isHasChanged,value:this.getValue()})||{};m&&(g=m),E&&(w=E)}this.drawCellBgColor=g,this.drawTextColor=w}updateSelection(){const{visibleWidth:e,visibleHeight:i,rowspan:s,colspan:r,cellType:o,type:n,rowIndex:h,rowKey:c}=this;if(!(s===0||r===0)&&o!=="footer"&&["index-selection","selection"].includes(n)){const d=this.ctx.database.getRowSelection(c),f=this.ctx.database.getRowSelectable(c),{CHECKBOX_SIZE:u=0}=this.ctx.config,x=this.drawX+(e-u)/2,p=this.drawY+(i-u)/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&&n=="index-selection"?(this.ctx.hoverCell&&this.ctx.hoverCell.rowIndex===h||["checkbox-disabled","checkbox-check"].includes(w))&&(this.drawImageX=x,this.drawImageY=p,this.drawImageWidth=u,this.drawImageHeight=u,this.drawImageName=w,this.drawImageSource=g):g&&n==="selection"&&(this.drawImageX=x,this.drawImageY=p,this.drawImageWidth=u,this.drawImageHeight=u,this.drawImageName=w,this.drawImageSource=g)}}updateHoverIcon(){const{BODY_CELL_HOVER_ICON_METHOD:e,CELL_HOVER_ICON_SIZE:i,CELL_PADDING:s}=this.ctx.config;if(typeof e=="function"){const h=e({row:this.row,rowIndex:this.rowIndex,colIndex:this.colIndex,column:this.column,value:this.getValue()});h!==void 0&&(this.hoverIconName=h)}const r=this.drawX+this.width-i-s,o=this.drawY+(this.height-i)/2;if(this.hoverIconName&&this.ctx.hoverCell&&this.ctx.hoverCell.rowIndex===this.rowIndex){const n=this.ctx.icons.get(this.hoverIconName);this.drawImageX=r,this.drawImageY=o,this.drawImageWidth=i,this.drawImageHeight=i,this.drawImageName=this.hoverIconName,this.drawImageSource=n}}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"}}draw(){const{paint:e,config:{BORDER_COLOR:i}}=this.ctx,{drawX:s,drawY:r}=this;e.drawRect(s,r,this.visibleWidth,this.visibleHeight,{borderColor:i,fillColor:this.drawCellBgColor}),e.drawRect(s,r,this.width,this.height,{borderColor:"transparent",borderWidth:1,fillColor:this.drawCellSkyBgColor}),this.drawText(),this.drawImage(),this.drawSelector(),this.drawAutofillPiont(),this.drawErrorTip()}getWidthByColIndexColSpan(e,i){if(i===0)return 0;let s=0;for(let r=e;r<e+i;r++){const o=this.ctx.header.leafCellHeaders[r];s+=o.width}return s}drawText(){const{CELL_PADDING:e,BODY_FONT:i}=this.ctx.config,{ellipsis:s}=this.ctx.paint.handleEllipsis(this.text,this.width,e,i);return this.ellipsis=s,this.ctx.paint.drawText(this.displayText,this.drawTextX,this.drawTextY,this.visibleWidth,this.visibleHeight,{font:i,padding:e,align:this.align,verticalAlign:this.verticalAlign,color:this.drawTextColor})}drawImage(){this.drawImageSource&&this.ctx.paint.drawImage(this.drawImageSource,this.drawImageX,this.drawImageY,this.drawImageWidth,this.drawImageHeight)}drawAutofillPiont(){if(this.cellType==="footer")return;const{SELECT_BORDER_COLOR:e,ENABLE_AUTOFILL:i,ENABLE_SELECTOR:s,AUTOFILL_POINT_BORDER_COLOR:r}=this.ctx.config;if(!s||!i)return;const{xArr:o,yArr:n}=this.ctx.selector,h=o[1],c=n[1],{colIndex:d,rowIndex:f,drawX:u,drawY:x}=this;d===h&&f===c&&this.ctx.paint.drawRect(u+this.width-6,x+this.height-6,6,6,{borderColor:r,fillColor:e})}drawSelector(){if(this.cellType==="footer")return;const{ENABLE_SELECTOR:e}=this.ctx.config;if(!e)return;const{xArr:i,yArr:s,xArrCopy:r,yArrCopy:o}=this.ctx.selector;this.drawBorder({xArr:r,yArr:o,borderColor:this.ctx.config.SELECT_BORDER_COLOR||"rgb(82,146,247)",fillColor:this.ctx.config.SELECT_AREA_COLOR||"rgba(82,146,247,0.1)",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:this.ctx.config.SELECT_AREA_COLOR||"rgba(82,146,247,0.1)",borderWidth:1,lineDash:[4,4]}),this.drawBorder({xArr:i,yArr:s,borderColor:this.ctx.config.SELECT_BORDER_COLOR||"rgb(82,146,247)",fillColor:this.ctx.config.SELECT_AREA_COLOR||"rgba(82,146,247,0.1)",borderWidth:1})}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,r=this.drawX,o=this.drawY,n=[r+s-e-.5,o,r+s-.5,o,r+s-.5,o+e];this.ctx.paint.drawLine(n,{borderColor:i,fillColor:i,borderWidth:1,lineCap:"round",lineJoin:"round"})}drawBorder(e){const{drawX:i,drawY:s,width:r,rowIndex:o,colIndex:n}=this;let h=i+.5,c=s+.5,d=this.height;o===0&&(c=this.y+1,d=d-1),n===this.ctx.maxColIndex&&(h=h-1);const{xArr:f,yArr:u,lineDash:x=[],borderWidth:p=1,borderColor:g,fillColor:w}=e,y=f[0],m=f[1],E=u[0],C=u[1];n>=y&&n<=m&&o===E&&this.ctx.paint.drawLine([h,c,h+r-2,c],{borderColor:g,fillColor:w,borderWidth:p,lineCap:"round",lineJoin:"round",lineDash:x}),n>=y&&n<=m&&o===C&&this.ctx.paint.drawLine([h,c+d-1.5,h+r,c+d-1.5],{borderColor:g,fillColor:w,borderWidth:p,lineCap:"round",lineJoin:"round",lineDash:x}),n===y&&o>=E&&o<=C&&this.ctx.paint.drawLine([h,c,h,c+d-1],{borderColor:g,fillColor:w,borderWidth:p,lineCap:"round",lineJoin:"round",lineDash:x}),n===m&&o>=E&&o<=C&&this.ctx.paint.drawLine([h+r-1.5,c,h+r-1.5,c+d-1.5],{borderColor:g,fillColor:w,borderWidth:p,lineCap:"round",lineJoin:"round",lineDash:x})}}class si{constructor(t,e){l(this,"loading",!1);l(this,"ctx");l(this,"data");l(this,"columns");l(this,"footerData",[]);l(this,"rowKeyMap",new Map);l(this,"colIndexKeyMap",new Map);l(this,"headerMap",new Map);l(this,"rowIndexRowKeyMap",new Map);l(this,"checkboxKeyMap",new Map);l(this,"originalDataMap",new Map);l(this,"changedDataMap",new Map);l(this,"validationErrorMap",new Map);l(this,"itemRowKeyMap",new WeakMap);l(this,"bufferData",[]);l(this,"sumHeight",0);l(this,"filterMethod");l(this,"positions",[]);this.ctx=t;const{data:i=[],columns:s=[],footerData:r=[]}=e;this.data=i,this.footerData=r,this.columns=s,this.setLoading(!0),this.init()}init(){this.clearBufferData(),this.rowKeyMap.clear(),this.checkboxKeyMap.clear(),this.colIndexKeyMap.clear(),this.rowIndexRowKeyMap.clear(),this.originalDataMap.clear(),this.changedDataMap.clear(),this.validationErrorMap.clear(),this.itemRowKeyMap=new WeakMap,this.initData(this.data)}clearBufferData(){this.bufferData=[]}initData(t,e=0){t.forEach((i,s)=>{let r=i._hasChildren||!1;Array.isArray(i.children)&&i.children.length&&(r=!0,this.initData(i.children,e+1));const{ROW_KEY:o="",DEFAULT_EXPAND_ALL:n,CELL_HEIGHT:h,SELECTABLE_METHOD:c,CHECKBOX_KEY:d}=this.ctx.config,f=i[o],u=f!=null?`${f}`:Pt();this.itemRowKeyMap.set(i,u);const x=i._height||h,p=i._readonly;let g=!0;if(typeof c=="function"&&(g=c),d){const w=i[d];if(this.checkboxKeyMap.has(w)){const y=this.checkboxKeyMap.get(w)||[];y.push(u),this.checkboxKeyMap.set(w,y)}else this.checkboxKeyMap.set(w,[u])}this.rowKeyMap.set(u,{readonly:p,index:s,rowIndex:s,level:e,height:x,check:!1,selectable:g,expand:n,expandLazy:!1,hasChildren:r,expandLoading:!1,item:i})})}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 r={...i};r.children&&Array.isArray(r.children)&&(r.children=this.filterColumns(r.children)),e.push(r)}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=r=>{r.forEach(o=>{t.push(o);const n=this.itemRowKeyMap.get(o),{expand:h,hasChildren:c,height:d}=this.rowKeyMap.get(n),f=this.sumHeight;this.sumHeight+=d,this.rowIndexRowKeyMap.set(e,n),this.positions.push({top:f,height:d,bottom:this.sumHeight}),e+=1,h&&c&&i(o.children)})};this.rowIndexRowKeyMap.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.clearBufferData(),this.ctx.emit("draw")}setExpandRowKeys(t,e=!0){t.forEach(i=>{const s=this.rowKeyMap.get(i);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.rowKeyMap.forEach(e=>{e.expand=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,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.rowKeyMap.get(t).index}getItemValueForRowIndexAndColIndex(t,e){if(!(this.rowIndexRowKeyMap.has(t)&&this.colIndexKeyMap.get(e)))return null;const s=this.rowIndexRowKeyMap.get(t),r=this.colIndexKeyMap.get(e);return s===void 0||r===void 0?null:{rowKey:s,key:r,value:this.getItemValue(s,r)}}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){let i=[];const s=new Set;let r=t;const{BEFORE_VALUE_CHANGE_METHOD:o}=this.ctx.config;if(typeof o=="function"){const d=o,f=t.map(x=>({rowKey:x.rowKey,key:x.key,value:x.value,oldValue:this.getItemValue(x.rowKey,x.key),row:this.ctx.database.getRowDataItemForRowKey(x.rowKey)}));r=await d(f)}r.forEach(d=>{const{value:f,rowKey:u,key:x}=d,p=this.getItemValue(u,x);this.setItemValue(u,x,f),s.add(u),i.push({rowKey:u,key:x,oldValue:p,newValue:f})});let n=[];const h=i.map(d=>{const f=this.ctx.database.getRowDataItemForRowKey(d.rowKey);return{rowKey:d.rowKey,key:d.key,value:d.newValue,row:f}});s.forEach(d=>{n.push(this.ctx.database.getRowDataItemForRowKey(d))});const c=h.map(({rowKey:d,key:f})=>this.getValidator(d,f));Promise.all(c).then(()=>{this.validationErrorMap.size===0&&this.changedDataMap.size>0&&this.ctx.emit("validateChangedData",this.getChangedData())}),this.ctx.emit("change",h,n),e&&this.ctx.history.pushState({changeList:i,scrollX:this.ctx.scrollX,scrollY:this.ctx.scrollY,type:"multiple"}),this.ctx.emit("draw")}async setItemValue(t,e,i,s=!1,r=!1,o=!1){if(!this.rowKeyMap.has(t))return{};const{item:n}=this.rowKeyMap.get(t);let h=n[e];if(this.ctx.database.getReadonly(t,e))return{oldValue:h,newValue:h};n[e]!==null&&typeof n[e]=="object"&&(h=JSON.parse(JSON.stringify(n[e])));const c=`${t}​_${e}`;this.originalDataMap.has(c)||this.originalDataMap.set(c,h);const d=this.originalDataMap.get(c);let f=i;if(o){const{BEFORE_VALUE_CHANGE_METHOD:u}=this.ctx.config;if(typeof u=="function"){const w=await u([{rowKey:t,key:e,value:i,oldValue:n[e],row:this.ctx.database.getRowDataItemForRowKey(t)}]);w&&w.length&&(f=w[0].value)}this.changedDataMap.set(c,f),n[e]=f;const x=this.ctx.database.getRowDataItemForRowKey(t),p={rowKey:t,key:e,value:f,row:x};this.getValidator(t,e).then(()=>{this.validationErrorMap.size===0&&this.changedDataMap.size>0&&this.ctx.emit("validateChangedData",this.getChangedData())}),this.ctx.emit("change",[p],[x]),this.ctx.emit("editChange",{rowKey:t,key:e,oldValue:h,value:f,originalValue:d,row:x})}else this.changedDataMap.set(c,f),n[e]=f;return this.ctx.hasEvent("iterationChange")&&this.ctx.emit("iterationChange",{rowKey:t,key:e,oldValue:h,value:f,originalValue:this.originalDataMap.get(c),row:this.ctx.database.getRowDataItemForRowKey(t)}),s&&this.ctx.history.pushState({type:"single",scrollX:this.ctx.scrollX,scrollY:this.ctx.scrollY,changeList:[{rowKey:t,key:e,oldValue:h,newValue:f}]}),r&&this.ctx.emit("draw"),{oldValue:h,newValue:f}}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),r=s[i];this.checkboxKeyMap.has(r)&&(this.checkboxKeyMap.get(r)||[]).forEach(n=>{const h=this.rowKeyMap.get(n);h.check=e})}}toggleRowSelection(t){const e=this.rowKeyMap.get(t);e.check=!e.check,this.setRowSelectionByCheckboxKey(t,e.check),this.ctx.emit("toggleRowSelection",e);const i=this.getSelectionRows();this.ctx.emit("selectionChange",i),this.ctx.emit("draw")}setRowSelection(t,e){const i=this.rowKeyMap.get(t);i.check=e,this.setRowSelectionByCheckboxKey(t,i.check);const s=this.getSelectionRows();this.ctx.emit("setRowSelection",s),this.ctx.emit("draw")}getSelectionRows(){let t=[];return this.rowKeyMap.forEach(e=>{e.check&&t.push(e.item)}),t}getRowSelection(t){const{check:e}=this.rowKeyMap.get(t);return e}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=>{const i=e.selectable;typeof i=="function"?i({row:e.item,rowIndex:e.rowIndex})&&(e.check=!0):i&&(e.check=!0)});const t=this.getSelectionRows();this.ctx.emit("toggleAllSelection",t),this.ctx.emit("selectionChange",t),this.ctx.emit("draw")}clearSelection(){this.rowKeyMap.forEach(e=>{const i=e.selectable;typeof i=="function"?i({row:e.item,rowIndex:e.rowIndex})&&(e.check=!1):i&&(e.check=!1)});const t=this.getSelectionRows();this.ctx.emit("clearSelection"),this.ctx.emit("selectionChange",t),this.ctx.emit("draw")}getCheckedState(){let t=0,e=0;this.rowKeyMap.forEach(o=>{o.check&&(t+=1);const n=o.selectable;typeof n=="function"?n({row:o.item,rowIndex:o.rowIndex})&&(e+=1):n&&(e+=1)});const i=e&&e>t&&t>0;return{check:e&&e===t,indeterminate:i,selectable:e!==0}}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}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),r=i.split("​_")[0],o=i.split("​_")[1];s!==e&&t.push({rowKey:r,colKey:o,originalValue:s,row:this.ctx.database.getRowDataItemForRowKey(r),value:e})}),t}getChangedRows(){const t=new Set;this.changedDataMap.forEach((i,s)=>{const r=this.originalDataMap.get(s),o=s.split("​_")[0];r!==i&&t.add(o)});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),r=this.changedDataMap.get(i);return s!==r}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),r=this.headerMap.get(e),o=s==null?void 0:s.readonly,n=r==null?void 0:r.readonly,{BODY_CELL_READONLY_METHOD:h}=this.ctx.config;if(typeof h=="function"&&r){const d=h({row:s.item,rowIndex:s.rowIndex,colIndex:r.colIndex,column:r.column,value:this.getItemValue(t,e)});if(d!==void 0)return d}return n||o}clearValidate(){this.validationErrorMap.clear()}hasValidationError(){return this.validationErrorMap.size!==0}getValidator(t,e){return new Promise(i=>{const s=this.rowKeyMap.get(t),r=this.headerMap.get(e),{BODY_CELL_RULES_METHOD:o}=this.ctx.config;if(r===void 0)return i([]);const n=r.column;let h=n.rules;if(typeof o=="function"){const d=o({row:s.item,rowIndex:s.rowIndex,colIndex:r.colIndex,column:n,value:this.getItemValue(t,e)});d&&(h=d)}if(h){let c={},d={};if(d[e]=this.getItemValue(t,e),Array.isArray(h)){const u=h.map(x=>({...x,row:s.item,column:n,rowIndex:s.rowIndex,colIndex:r.colIndex}));c[e]=u}else c[e]={...h,row:s.item,column:n,rowIndex:s.rowIndex,colIndex:r.colIndex};new nt(c).validate(d).then(()=>{this.clearValidationError(t,e),i([])}).catch(({errors:u})=>{const x=u.map(p=>({...p,column:n,key:e,row:s.item,rowKey:t}));this.setValidationError(t,e,x),i(x)})}else i([])})}getHeightByRowIndexRowSpan(t,e){let i=0;for(let s=0;s<e;s++){const r=this.positions[t+s];r&&(i+=r.height)}return i}getSpanInfo(t){const{rowIndex:e,key:i,rowKey:s,row:r,value:o,colIndex:n,relationRowKeys:h,relationColKeys:c,rowspan:d,height:f,width:u,colspan:x,mergeRow:p,mergeCol:g}=t;if(d===1&&x===1)return{xArr:[n,n],yArr:[e,e],rowspan:d,colspan:x,height:f,width:u,offsetTop:0,offsetLeft:0,dataList:[{rowKey:s,key:i,row:r,value:o}]};let w=e,y=e,m=n,E=n,C=[],b=0,R=0,A=0,L=0;if(d!==1&&p){L=u;const I=h.reduce