/*
    *
    * Wijmo Library 5.20182.500
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
"use strict";var __extends=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])};return function(t,o){function n(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}}();Object.defineProperty(exports,"__esModule",{value:!0});var wjcCore=require("wijmo/wijmo"),wjcXlsx=require("wijmo/wijmo.xlsx"),wjcGrid=require("wijmo/wijmo.grid"),wjcInput=require("wijmo/wijmo.input"),wjcGridXlsx=require("wijmo/wijmo.grid.xlsx"),wjcGridFilter=require("wijmo/wijmo.grid.filter"),wjcSelfRef=require("wijmo/wijmo.grid.sheet"),wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.grid=window.wijmo.grid||{},window.wijmo.grid.sheet=wjcSelf;var _CalcEngine=function(){function e(e){this._expressionCache={},this._idChars="$:!",this._functionTable={},this._cacheSize=0,this._tableRefStart=!1,this.unknownFunction=new wjcCore.Event,this._owner=e,this._buildSymbolTable(),this._registerAggregateFunction(),this._registerMathFunction(),this._registerLogicalFunction(),this._registerTextFunction(),this._registerDateFunction(),this._registLookUpReferenceFunction(),this._registFinacialFunction()}return e.prototype.onUnknownFunction=function(e,t){var o,n;if(t&&t.length>0){o=[];for(var i=0;i<t.length;i++)o[i]=t[i].evaluate(this._rowIndex,this._columnIndex)}if(n=new UnknownFunctionEventArgs(e,o),this.unknownFunction.raise(this,n),null!=n.value)return new _Expression(n.value);throw'The function "'+e+'" has not supported in FlexSheet yet.'},e.prototype.evaluate=function(e,t,o,n,i){var r;try{if(e&&e.length>1&&"="===e[0]){for(this._containsCellRef=!1,this._rowIndex=n,this._columnIndex=i,this._sheet=o||this._owner.selectedSheet,r=this._checkCache(e).evaluate(n,i,o);r instanceof _Expression;)r=r.evaluate(n,i,o);return t&&wjcCore.isPrimitive(r)?wjcCore.Globalize.format(r,t):r}return e||""}catch(e){return"Error: "+e}},e.prototype.addCustomFunction=function(e,t,o,n){var i=this;e=e.toLowerCase(),this._functionTable[e]=new _FunctionDefinition(function(e){var o,n=[];if(e&&e.length>0)for(var r=0;r<e.length;r++)o=e[r],n[r]=o instanceof _CellRangeExpression?o.cells:o.evaluate(i._rowIndex,i._columnIndex);return t.apply(i,n)},n,o)},e.prototype.addFunction=function(e,t,o,n){var i=this;e=e.toLowerCase(),this._functionTable[e]=new _FunctionDefinition(function(e){var o,n=[];if(e&&e.length>0)for(var r=0;r<e.length;r++)o=e[r],n[r]=o instanceof _CellRangeExpression?o.getValuseWithTwoDimensions():[[o.evaluate(i._rowIndex,i._columnIndex)]];return t.apply(i,n)},n,o)},e.prototype._clearExpressionCache=function(){this._expressionCache=null,this._expressionCache={},this._cacheSize=0},e.prototype._parse=function(e){return this._expression=e,this._expressLength=e?e.length:0,this._pointer=0,this._expressLength>0&&"="===this._expression[0]&&this._pointer++,this._parseExpression()},e.prototype._buildSymbolTable=function(){this._tokenTable||(this._tokenTable={},this._addToken("+",_TokenID.ADD,_TokenType.ADDSUB),this._addToken("-",_TokenID.SUB,_TokenType.ADDSUB),this._addToken("(",_TokenID.OPEN,_TokenType.GROUP),this._addToken(")",_TokenID.CLOSE,_TokenType.GROUP),this._addToken("*",_TokenID.MUL,_TokenType.MULDIV),this._addToken(",",_TokenID.COMMA,_TokenType.GROUP),this._addToken(".",_TokenID.PERIOD,_TokenType.GROUP),this._addToken("/",_TokenID.DIV,_TokenType.MULDIV),this._addToken("\\",_TokenID.DIVINT,_TokenType.MULDIV),this._addToken("=",_TokenID.EQ,_TokenType.COMPARE),this._addToken(">",_TokenID.GT,_TokenType.COMPARE),this._addToken("<",_TokenID.LT,_TokenType.COMPARE),this._addToken("^",_TokenID.POWER,_TokenType.POWER),this._addToken("<>",_TokenID.NE,_TokenType.COMPARE),this._addToken(">=",_TokenID.GE,_TokenType.COMPARE),this._addToken("<=",_TokenID.LE,_TokenType.COMPARE),this._addToken("&",_TokenID.CONCAT,_TokenType.CONCAT),this._addToken("[",_TokenID.OPEN,_TokenType.SQUAREBRACKETS),this._addToken("]",_TokenID.CLOSE,_TokenType.SQUAREBRACKETS))},e.prototype._registerAggregateFunction=function(){var e=this;e._functionTable.sum=new _FunctionDefinition(function(t,o){return e._getAggregateResult(wjcCore.Aggregate.Sum,t,o)}),e._functionTable.average=new _FunctionDefinition(function(t,o){return e._getAggregateResult(wjcCore.Aggregate.Avg,t,o)}),e._functionTable.max=new _FunctionDefinition(function(t,o){return e._getAggregateResult(wjcCore.Aggregate.Max,t,o)}),e._functionTable.min=new _FunctionDefinition(function(t,o){return e._getAggregateResult(wjcCore.Aggregate.Min,t,o)}),e._functionTable.var=new _FunctionDefinition(function(t,o){return e._getAggregateResult(wjcCore.Aggregate.Var,t,o)}),e._functionTable.varp=new _FunctionDefinition(function(t,o){return e._getAggregateResult(wjcCore.Aggregate.VarPop,t,o)}),e._functionTable.stdev=new _FunctionDefinition(function(t,o){return e._getAggregateResult(wjcCore.Aggregate.Std,t,o)}),e._functionTable.stdevp=new _FunctionDefinition(function(t,o){return e._getAggregateResult(wjcCore.Aggregate.StdPop,t,o)}),e._functionTable.count=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.Count,t,o)}),e._functionTable.counta=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountA,t,o)}),e._functionTable.countblank=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.ConutBlank,t,o)}),e._functionTable.countif=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountIf,t,o)},2,2),e._functionTable.countifs=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountIfs,t,o)},254,2),e._functionTable.sumif=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.SumIf,t,o)},3,2),e._functionTable.sumifs=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.SumIfs,t,o)},255,2),e._functionTable.rank=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.Rank,t,o)},3,2),e._functionTable.product=new _FunctionDefinition(function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.Product,t,o)},255,1),e._functionTable.subtotal=new _FunctionDefinition(function(t,o){return e._handleSubtotal(t,o)},255,2),e._functionTable.dcount=new _FunctionDefinition(function(t,o){return e._handleDCount(t,o)},3,3),e._functionTable.sumproduct=new _FunctionDefinition(function(t,o){return e._getSumProduct(t,o)},255,1)},e.prototype._registerMathFunction=function(){var e=this,t=["abs","acos","asin","atan","cos","exp","ln","sin","sqrt","tan"],o=["ceiling","floor"],n=["round","rounddown","roundup"];e._functionTable.pi=new _FunctionDefinition(function(){return Math.PI},0,0),e._functionTable.rand=new _FunctionDefinition(function(){return Math.random()},0,0),e._functionTable.power=new _FunctionDefinition(function(t,o){return Math.pow(_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o))},2,2),e._functionTable.atan2=new _FunctionDefinition(function(t,o){var n=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),i=_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o);if(0===n&&0===i)throw"The x number and y number can't both be zero for the atan2 function";return Math.atan2(i,n)},2,2),e._functionTable.mod=new _FunctionDefinition(function(t,o){return _Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o)%_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)},2,2),e._functionTable.trunc=new _FunctionDefinition(function(t,o){var n,i=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),r=2===t.length?_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o):0;return 0===r?i>=0?Math.floor(i):Math.ceil(i):(n=Math.pow(10,r),i>=0?Math.floor(i*n)/n:Math.ceil(i*n)/n)},2,1),o.forEach(function(t){e._functionTable[t]=new _FunctionDefinition(function(o,n){var i,r,l,s=_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n),a=2===o.length?_Expression.toNumber(o[1],e._rowIndex,e._columnIndex,n):1;if(isNaN(s))throw"Invalid Number!";if(isNaN(a))throw"Invalid Significance!";if(s>0&&a<0)throw"The significance has to be positive, if the number is positive.";if(0===s||0===a)return 0;if(i=a-Math.floor(a),r=1,0!==i)for(;i<1;)r*=10,i*=10;return l="ceiling"===t?Math.ceil(s/a):Math.floor(s/a),a*r*l/r},2,1)}),n.forEach(function(t){e._functionTable[t]=new _FunctionDefinition(function(o,n){var i,r,l,s=_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n),a=_Expression.toNumber(o[1],e._rowIndex,e._columnIndex,n);if(0===a){switch(t){case"rounddown":i=s>=0?Math.floor(s):Math.ceil(s);break;case"roundup":i=s>=0?Math.ceil(s):Math.floor(s);break;case"round":i=Math.round(s);break;default:i=Math.floor(s)}r="n0"}else if(a>0&&wjcCore.isInt(a)){switch(l=Math.pow(10,a),t){case"rounddown":i=s>=0?Math.floor(s*l)/l:Math.ceil(s*l)/l;break;case"roundup":i=s>=0?Math.ceil(s*l)/l:Math.floor(s*l)/l;break;case"round":i=Math.round(s*l)/l}r="n"+a}if(null!=i)return{value:i,format:r};throw"Invalid precision!"},2,2)}),t.forEach(function(t){e._functionTable[t]=new _FunctionDefinition(function(o,n){return"ln"===t?Math.log(_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n)):Math[t](_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n))},1,1)})},e.prototype._registerLogicalFunction=function(){var e=this;e._functionTable.and=new _FunctionDefinition(function(t,o){var n,i=!0;for(n=0;n<t.length&&(i=i&&_Expression.toBoolean(t[n],e._rowIndex,e._columnIndex,o));n++);return i},Number.MAX_VALUE,1),e._functionTable.or=new _FunctionDefinition(function(t,o){var n,i=!1;for(n=0;n<t.length&&!(i=i||_Expression.toBoolean(t[n],e._rowIndex,e._columnIndex,o));n++);return i},Number.MAX_VALUE,1),e._functionTable.not=new _FunctionDefinition(function(t,o){return!_Expression.toBoolean(t[0],e._rowIndex,e._columnIndex,o)},1,1),e._functionTable.if=new _FunctionDefinition(function(t,o){return 3===t.length?_Expression.toBoolean(t[0],e._rowIndex,e._columnIndex,o)?t[1].evaluate(e._rowIndex,e._columnIndex,o):t[2].evaluate(e._rowIndex,e._columnIndex,o):!!_Expression.toBoolean(t[0],e._rowIndex,e._columnIndex,o)&&t[1].evaluate(e._rowIndex,e._columnIndex,o)},3,2),e._functionTable.true=new _FunctionDefinition(function(){return!0},0,0),e._functionTable.false=new _FunctionDefinition(function(){return!1},0,0)},e.prototype._registerTextFunction=function(){var e=this;e._functionTable.char=new _FunctionDefinition(function(t,o){var n,i="";for(n=0;n<t.length;n++)i+=String.fromCharCode(_Expression.toNumber(t[n],e._rowIndex,e._columnIndex,o));return i},Number.MAX_VALUE,1),e._functionTable.code=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.charCodeAt(0):-1},1,1),e._functionTable.concatenate=new _FunctionDefinition(function(t,o){var n,i="";for(n=0;n<t.length;n++)i=i.concat(_Expression.toString(t[n],e._rowIndex,e._columnIndex,o));return i},Number.MAX_VALUE,1),e._functionTable.left=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o));return n&&n.length>0?n.slice(0,i):null},2,2),e._functionTable.right=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o));return n&&n.length>0?n.slice(-i):null},2,2),e._functionTable.find=new _FunctionDefinition(function(t,o){var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),r=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),l=null!=t[2]?wjcCore.asInt(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)):0;return null!=r&&null!=i&&(n=!isNaN(l)&&l>0&&l<r.length?r.indexOf(i,l):r.indexOf(i))>-1?n+1:-1},3,2),e._functionTable.search=new _FunctionDefinition(function(t,o){var n,i,r,l=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),s=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),a=null!=t[2]?wjcCore.asInt(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)):0;return null!=s&&null!=l&&(i=new RegExp(l,"i"),!isNaN(a)&&a>0&&a<s.length?(s=s.substring(a),n=a+1):n=1,(r=s.search(i))>-1)?r+n:-1},3,2),e._functionTable.len=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n?n.length:-1},1,1),e._functionTable.mid=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)),r=Math.floor(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o));return n&&n.length>0&&i>0?n.substr(i-1,r):null},3,3),e._functionTable.lower=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.toLowerCase():null},1,1),e._functionTable.upper=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.toUpperCase():null},1,1),e._functionTable.proper=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n[0].toUpperCase()+n.substring(1).toLowerCase():null},1,1),e._functionTable.trim=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.trim():null},1,1),e._functionTable.replace=new _FunctionDefinition(function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)),r=Math.floor(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)),l=_Expression.toString(t[3],e._rowIndex,e._columnIndex,o);return n&&n.length>0&&i>0?n.substring(0,i-1)+l+n.slice(i-1+r):null},4,4),e._functionTable.substitute=new _FunctionDefinition(function(t,o){var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),r=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),l=_Expression.toString(t[2],e._rowIndex,e._columnIndex,o),s=4===t.length?_Expression.toNumber(t[3],e._rowIndex,e._columnIndex,o):null,a=0;if(null!=s&&s<1||isNaN(s))throw"Invalid instance number.";return i&&i.length>0&&r&&r.length>0?(n=new RegExp(r,"g"),i.replace(n,function(e){return a++,null!=s?(s=Math.floor(s),a===s?l:e):l})):null},4,3),e._functionTable.rept=new _FunctionDefinition(function(t,o){var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),r=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)),l="";if(i&&i.length>0&&r>0)for(n=0;n<r;n++)l=l.concat(i);return l},2,2),e._functionTable.text=new _FunctionDefinition(function(t,o){var n,i=t[0].evaluate(e._rowIndex,e._columnIndex,o),r=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o);if(!wjcCore.isPrimitive(i)&&i&&(i=i.value),wjcCore.isDate(i))r=r.replace(/\[\$\-.+\]/g,"").replace(/(\\)(.)/g,"$2").replace(/H+/g,function(e){return e.toLowerCase()}).replace(/m+/g,function(e){return e.toUpperCase()}).replace(/S+/g,function(e){return e.toLowerCase()}).replace(/AM\/PM/gi,"tt").replace(/A\/P/gi,"t").replace(/\.000/g,".fff").replace(/\.00/g,".ff").replace(/\.0/g,".f").replace(/\\[\-\s,]/g,function(e){return e.substring(1)}).replace(/Y+/g,function(e){return e.toLowerCase()}).replace(/D+/g,function(e){return e.toLowerCase()}).replace(/M+:?|:?M+/gi,function(e){return e.indexOf(":")>-1?e.toLowerCase():e}).replace(/g+e/gi,function(e){return e.substring(0,e.length-1)+"yy"});else{if(!wjcCore.isNumber(i))return i;if((n=r.match(/^(\d+)(\.\d+)?\E\+(\d+)(\.\d+)?$/))&&5===n.length)return e._parseToScientificValue(i,n[1],n[2],n[3],n[4]);/M{1,4}|d{1,4}|y{1,4}/.test(r)?i=new Date(1900,0,i-1):r&&r.indexOf("#")>-1&&(r=wjcXlsx.Workbook.fromXlsxFormat(r)[0])}if(wjcCore.isDate(i))switch(r){case"d":return i.getDate();case"M":return i.getMonth()+1;case"y":r="yy";break;case"yyy":r="yyyy"}return wjcCore.Globalize.format(i,r)},2,2),e._functionTable.value=new _FunctionDefinition(function(t,o){var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);if((i=i.replace(/(\,\d{3})/g,function(e){return e.substring(1)})).length>0){if(i[0]===wjcCore.culture.Globalize.numberFormat.currency.symbol)return+(i=i.substring(1));if("%"===i[i.length-1])return+(i=i.substring(0,i.length-1))/100}return n=+i,isNaN(n)?_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o):n},1,1)},e.prototype._registerDateFunction=function(){var e=this;e._functionTable.now=new _FunctionDefinition(function(){return{value:new Date,format:"M/d/yyyy h:mm"}},0,0),e._functionTable.today=new _FunctionDefinition(function(){var e=new Date;return{value:new Date(e.getFullYear(),e.getMonth(),e.getDate()),format:"M/d/yyyy"}},0,0),e._functionTable.year=new _FunctionDefinition(function(t,o){var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return!wjcCore.isPrimitive(n)&&n?n.value:wjcCore.isDate(n)?n.getFullYear():1900},1,1),e._functionTable.month=new _FunctionDefinition(function(t,o){var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return!wjcCore.isPrimitive(n)&&n?n.value:wjcCore.isDate(n)?n.getMonth()+1:1},1,1),e._functionTable.day=new _FunctionDefinition(function(t,o){var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return!wjcCore.isPrimitive(n)&&n?n.value:wjcCore.isDate(n)?n.getDate():0},1,1),e._functionTable.hour=new _FunctionDefinition(function(t,o){var n=t[0].evaluate(e._rowIndex,e._columnIndex,o);if(wjcCore.isNumber(n)&&!isNaN(n))return Math.floor(24*(n-Math.floor(n)));if(wjcCore.isDate(n))return n.getHours();if(n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o),!wjcCore.isPrimitive(n)&&n&&(n=n.value),wjcCore.isDate(n))return n.getHours();throw"Invalid parameter."},1,1),e._functionTable.time=new _FunctionDefinition(function(t,o){var n=t[0].evaluate(e._rowIndex,e._columnIndex,o),i=t[1].evaluate(e._rowIndex,e._columnIndex,o),r=t[2].evaluate(e._rowIndex,e._columnIndex,o);if(wjcCore.isNumber(n)&&wjcCore.isNumber(i)&&wjcCore.isNumber(r))return n%=24,i%=60,r%=60,{value:new Date(0,0,0,n,i,r),format:"h:mm tt"};throw"Invalid parameters."},3,3),e._functionTable.date=new _FunctionDefinition(function(t,o){var n=t[0].evaluate(e._rowIndex,e._columnIndex,o),i=t[1].evaluate(e._rowIndex,e._columnIndex,o),r=t[2].evaluate(e._rowIndex,e._columnIndex,o);if(wjcCore.isNumber(n)&&wjcCore.isNumber(i)&&wjcCore.isNumber(r))return{value:new Date(n,i-1,r),format:"M/d/yyyy"};throw"Invalid parameters."},3,3),e._functionTable.datedif=new _FunctionDefinition(function(t,o){var n,i,r,l,s,a=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o),h=_Expression.toDate(t[1],e._rowIndex,e._columnIndex,o),c=t[2].evaluate(e._rowIndex,e._columnIndex,o);if(!wjcCore.isPrimitive(a)&&a&&(a=a.value),!wjcCore.isPrimitive(h)&&h&&(h=h.value),wjcCore.isDate(a)&&wjcCore.isDate(h)&&wjcCore.isString(c)){if(n=a.getTime(),i=h.getTime(),n>i)throw"Start date is later than end date.";switch(r=h.getDate()-a.getDate(),l=h.getMonth()-a.getMonth(),s=h.getFullYear()-a.getFullYear(),c.toUpperCase()){case"Y":return l>0?s:l<0?s-1:r>=0?s:s-1;case"M":return r>=0?12*s+l:12*s+l-1;case"D":return(i-n)/864e5;case"YM":return(l=r>=0?12*s+l:12*s+l-1)%12;case"YD":return l>0?(new Date(a.getFullYear(),h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5:l<0?(new Date(a.getFullYear()+1,h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5:r>=0?r:(new Date(a.getFullYear()+1,h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5;case"MD":return r>=0?r:r=new Date(h.getFullYear(),h.getMonth(),0).getDate()-new Date(h.getFullYear(),h.getMonth()-1,1).getDate()+1+r;default:throw"Invalid unit."}}throw"Invalid parameters."},3,3)},e.prototype._registLookUpReferenceFunction=function(){var e=this;e._functionTable.column=new _FunctionDefinition(function(t,o,n,i){var r;if(null==t)return i+1;if(r=t[0],(r=e._ensureNonFunctionExpression(r))instanceof _CellRangeExpression)return r.cells.col+1;throw"Invalid Cell Reference."},1,0),e._functionTable.columns=new _FunctionDefinition(function(t,o){var n=t[0];if((n=e._ensureNonFunctionExpression(n))instanceof _CellRangeExpression)return n.cells.columnSpan;throw"Invalid Cell Reference."},1,1),e._functionTable.row=new _FunctionDefinition(function(t,o,n,i){var r;if(null==t)return n+1;if(r=t[0],(r=e._ensureNonFunctionExpression(r))instanceof _CellRangeExpression)return r.cells.row+1;throw"Invalid Cell Reference."},1,0),e._functionTable.rows=new _FunctionDefinition(function(t,o){var n=t[0];if((n=e._ensureNonFunctionExpression(n))instanceof _CellRangeExpression)return n.cells.rowSpan;throw"Invalid Cell Reference."},1,1),e._functionTable.choose=new _FunctionDefinition(function(t,o){var n=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o);if(isNaN(n))throw"Invalid index number.";if(n<1||n>=t.length)throw"The index number is out of the list range.";return t[n].evaluate(e._rowIndex,e._columnIndex,o)},255,2),e._functionTable.index=new _FunctionDefinition(function(t,o){var n,i=t[0],r=_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o),l=null!=t[2]?_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o):0;if(isNaN(r)||r<0)throw"Invalid Row Number.";if(isNaN(l)||l<0)throw"Invalid Column Number.";if((i=e._ensureNonFunctionExpression(i))instanceof _CellRangeExpression){if(n=i.cells,r>n.rowSpan||l>n.columnSpan)throw"Index is out of the cell range.";if(r>0&&l>0)return e._owner.getCellValue(n.topRow+r-1,n.leftCol+l-1,!0,o);if(0===r&&0===l)return i;if(0===r)return new _CellRangeExpression(new wjcGrid.CellRange(n.topRow,n.leftCol+l-1,n.bottomRow,n.leftCol+l-1),i.sheetRef,e._owner);if(0===l)return new _CellRangeExpression(new wjcGrid.CellRange(n.topRow+r-1,n.leftCol,n.topRow+r-1,n.rightCol),i.sheetRef,e._owner)}throw"Invalid Cell Reference."},4,2),e._functionTable.hlookup=new _FunctionDefinition(function(t,o){return e._handleHLookup(t,o)},4,3)},e.prototype._registFinacialFunction=function(){var e=this;e._functionTable.rate=new _FunctionDefinition(function(t,o){return{value:e._calculateRate(t,o),format:"p2"}},6,3)},e.prototype._addToken=function(e,t,o){var n=new _Token(e,t,o);this._tokenTable[e]=n},e.prototype._parseExpression=function(){return this._getToken(),this._parseCompareOrConcat()},e.prototype._parseCompareOrConcat=function(){for(var e,t,o=this._parseAddSub();this._token.tokenType===_TokenType.COMPARE||this._token.tokenType===_TokenType.CONCAT;)e=this._token,this._getToken(),t=this._parseAddSub(),o=new _BinaryExpression(e,o,t);return o},e.prototype._parseAddSub=function(){for(var e,t,o=this._parseMulDiv();this._token.tokenType===_TokenType.ADDSUB;)e=this._token,this._getToken(),t=this._parseMulDiv(),o=new _BinaryExpression(e,o,t);return o},e.prototype._parseMulDiv=function(){for(var e,t,o=this._parsePower();this._token.tokenType===_TokenType.MULDIV;)e=this._token,this._getToken(),t=this._parsePower(),o=new _BinaryExpression(e,o,t);return o},e.prototype._parsePower=function(){for(var e,t,o=this._parseUnary();this._token.tokenType===_TokenType.POWER;)e=this._token,this._getToken(),t=this._parseUnary(),o=new _BinaryExpression(e,o,t);return o},e.prototype._parseUnary=function(){var e,t;return this._token.tokenID===_TokenID.ADD||this._token.tokenID===_TokenID.SUB?(e=this._token,this._getToken(),t=this._parseAtom(),new _UnaryExpression(e,t)):this._parseAtom()},e.prototype._parseAtom=function(){var e,t,o,n,i,r,l,s,a,h,c,d,u,_=null;switch(this._token.tokenType){case _TokenType.LITERAL:_=new _Expression(this._token);break;case _TokenType.IDENTIFIER:if(e=this._token.value.toString().toLowerCase(),t=this._functionTable[e]){if(o=this._getParameters(),this._token.tokenType===_TokenType.GROUP&&this._token.tokenID===_TokenID.CLOSE){if(n=o?o.length:0,-1!==t.paramMin&&n<t.paramMin)throw"Too few parameters.";if(-1!==t.paramMax&&n>t.paramMax)throw"Too many parameters.";"rand"===e&&(this._containsCellRef=!0),_=new _FunctionExpression(e,t,o);break}if("true"===e||"false"===e){_=new _FunctionExpression(e,t,o,!1);break}}if(2===(h=e.split("!")).length?(d=h[0],c=h[1]):c=h[0],r=this._getDefinedName(c,d||this._sheet.name.toLowerCase())){if(r.sheetName&&r.sheetName!==this._sheet.name&&r.sheetName.toLowerCase()!==d)throw"The defined name item works in "+r.sheetName+".  It does not work in current sheet.";a=this._pointer,s=this._expressLength,l=this._expression,this._pointer=0,_=this._checkCache(r.value),this._pointer=a,this._expressLength=s,this._expression=l;break}if(d="",null!=(u=this._owner._getTable(e))){if(""===(d=u.sheet.name))throw"The Table("+e+") is not located in any sheet.";if(this._getToken(),this._token.tokenType!==_TokenType.SQUAREBRACKETS||this._token.tokenID!==_TokenID.OPEN)throw"Invalid Table Reference.";this._tableRefStart=!0,_=this._getTableReference(u,d);break}if(i=this._getCellRange(e)){this._containsCellRef=!0,_=new _CellRangeExpression(i.cellRef.cellRange,i.sheetRef,this._owner,e.indexOf(":")>-1,i.cellRef.absRow,i.cellRef.absCol,i.cellRef.absRow2,i.cellRef.absCol2);break}o=this._getParameters(),_=this.onUnknownFunction(e,o);break;case _TokenType.GROUP:if(this._token.tokenID!==_TokenID.OPEN)throw"Expression expected.";if(this._getToken(),_=this._parseCompareOrConcat(),this._token.tokenID!==_TokenID.CLOSE)throw"Unbalanced parenthesis.";break;case _TokenType.SQUAREBRACKETS:if(this._token.tokenID!==_TokenID.OPEN)throw"Table References expected.";null!=(u=this._sheet.findTable(this._rowIndex,this._columnIndex))&&(d=u.sheet.name,this._tableRefStart=!0,_=this._getTableReference(u,d,!1))}if(null===_)throw"";return this._getToken(),_},e.prototype._getToken=function(){for(var e,t,o,n,i,r="",l="",s=new RegExp("[　-〿぀-ゟ゠-ヿ＀-ﾟ一-龯㐀-䶿]");this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;if(this._pointer>=this._expressLength)this._token=new _Token(null,_TokenID.END,_TokenType.GROUP);else{if(t=this._expression[this._pointer],n=t>="a"&&t<="z"||t>="A"&&t<="Z"||s.test(t),i=t>="0"&&t<="9"||"."==t,!n&&!i){var a=this._tokenTable[t];if(a)return this._token=a,this._pointer++,void(this._pointer<this._expressLength&&(">"===t||"<"===t)&&(a=this._tokenTable[this._expression.substring(this._pointer-1,this._pointer+1)])&&(this._token=a,this._pointer++))}if(i)this._parseDigit();else if('"'!==t){if("'"!==t||(l=this._parseSheetRef()))if("#"!==t){if(!n&&"_"!==t&&this._idChars.indexOf(t)<0&&!l)throw"Identifier expected.";for(e=1;e+this._pointer<this._expressLength;e++)if(t=this._expression[this._pointer+e],n=t>="a"&&t<="z"||t>="A"&&t<="Z"||s.test(t),i=t>="0"&&t<="9","'"!==t||":"!==o){if(o=t,!n&&!i&&"_"!==t&&this._idChars.indexOf(t)<0)break}else r=l+this._expression.substring(this._pointer,this._pointer+e),this._pointer+=e,l=this._parseSheetRef(),e=0;r+=l+this._expression.substring(this._pointer,this._pointer+e),this._pointer+=e,this._token=new _Token(r,_TokenID.ATOM,_TokenType.IDENTIFIER)}else this._parseDate()}else this._parseString()}},e.prototype._getTableToken=function(){for(var e,t,o,n="",i=!1;this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;for("@"===(t=this._expression[this._pointer])&&(n=t,this._pointer++),"["===(t=this._expression[this._pointer])&&(i=!0),e=1;e+this._pointer<this._expressLength;e++){if(t=this._expression[this._pointer+e],i&&","===t)throw"Invalid table reference.";if("]"===t)break}o=n+this._expression.substring(this._pointer+(i?1:0),this._pointer+e),this._pointer+=e+(i?1:0),this._token=new _Token(o,_TokenID.ATOM,_TokenType.IDENTIFIER)},e.prototype._parseDigit=function(){var e,t,o=-1,n=!1,i=!1,r=0;for(e=0;e+this._pointer<this._expressLength;e++)if((t=this._expression[this._pointer+e])>="0"&&t<="9")r=10*r+(+t-0),o>-1&&(o*=10);else if("."===t&&o<0)o=1;else{if("E"!==t&&"e"!==t||n){if("%"===t){i=!0,e++;break}break}n=!0,"+"!==(t=this._expression[this._pointer+e+1])&&"-"!==t||e++}n?r=+this._expression.substring(this._pointer,this._pointer+e):(o>1&&(r/=o),i&&(r/=100)),this._token=new _Token(r,_TokenID.ATOM,_TokenType.LITERAL),this._pointer+=e},e.prototype._parseString=function(){var e,t,o;for(e=1;e+this._pointer<this._expressLength;e++)if('"'===(t=this._expression[this._pointer+e])){if('"'!==(e+this._pointer<this._expressLength-1?this._expression[this._pointer+e+1]:" "))break;e++}if('"'!==t)throw"Can't find final quote.";if(o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,"!"===this._expression[this._pointer])throw"Illegal cross sheet reference.";this._token=new _Token(o.replace('""','"'),_TokenID.ATOM,_TokenType.LITERAL)},e.prototype._parseDate=function(){var e,t,o;for(e=1;e+this._pointer<this._expressLength&&"#"!==(t=this._expression[this._pointer+e]);e++);if("#"!==t)throw'Can\'t find final date delimiter ("#").';o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,this._token=new _Token(Date.parse(o),_TokenID.ATOM,_TokenType.LITERAL)},e.prototype._parseSheetRef=function(){var e,t,o;for(e=1;e+this._pointer<this._expressLength;e++)if("'"===(t=this._expression[this._pointer+e])){if("'"!==(e+this._pointer<this._expressLength-1?this._expression[this._pointer+e+1]:" "))break;e++}if("'"!==t)throw"Can't find final quote.";return o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,"!"===this._expression[this._pointer]?o.replace(/\'\'/g,"'"):""},e.prototype._getCellRange=function(e){var t,o,n,i,r;if(e&&(t=e.split(":")).length>0&&t.length<3&&(o=this._parseCell(t[0]),(i=o.cellRef?o.cellRef.cellRange:null)&&2===t.length)){if(n=this._parseCell(t[1]),r=n.cellRef.cellRange,o.sheetRef&&!n.sheetRef&&(n.sheetRef=o.sheetRef),o.sheetRef!==n.sheetRef)throw"The cell reference must be in the same sheet!";r?(i.col2=r.col,i.row2=r.row):i=null}return null==i?null:{cellRef:{cellRange:i,absRow:o.cellRef.absRow,absCol:o.cellRef.absCol,absRow2:n?n.cellRef.absRow:null,absCol2:n?n.cellRef.absCol:null},sheetRef:o.sheetRef}},e.prototype._parseCellRange=function(e){var t,o,n=-1,i=-1,r=!1,l=!1;for(t=0;t<e.length;t++)if("$"!==(o=e[t])||r){if(!(o>="a"&&o<="z"||o>="A"&&o<="Z"))break;n<0&&(n=0),n=26*n+(o.toUpperCase().charCodeAt(0)-"A".charCodeAt(0)+1)}else r=!0;for(;t<e.length;t++)if("$"!==(o=e[t])||l){if(!(o>="0"&&o<="9"))break;i<0&&(i=0),i=10*i+(+o-0)}else l=!0;return t<e.length&&(i=n=-1),-1===i||-1===n?null:{cellRange:new wjcGrid.CellRange(i-1,n-1),absRow:l,absCol:r}},e.prototype._parseCell=function(e){var t,o,n,i;if((o=e.lastIndexOf("!"))>0&&o<e.length-1)i=e.substring(0,o),n=e.substring(o+1);else{if(!(o<=0))return null;n=e}return t=this._parseCellRange(n),{cellRef:t,sheetRef:i}},e.prototype._getParameters=function(){var e,t,o=this._pointer,n=this._token;if(this._getToken(),this._token.tokenType!==_TokenType.SQUAREBRACKETS||this._token.tokenID!==_TokenID.OPEN){if(this._token.tokenID!==_TokenID.OPEN)return this._pointer=o,this._token=n,null;if(o=this._pointer,this._getToken(),this._token.tokenID===_TokenID.CLOSE)return null;for(this._pointer=o,e=new Array,t=this._parseExpression(),e.push(t);this._token.tokenID===_TokenID.COMMA;)t=this._parseExpression(),e.push(t);if(this._token.tokenID!==_TokenID.CLOSE)throw"Syntax error.";return e}},e.prototype._getTableReference=function(e,t,o){void 0===o&&(o=!0);var n,i,r=[],l=this._getTableParameter(),s=!1;if(null==l)throw"Invalid table reference.";for(r.push(l);this._tableRefStart&&(this._token.tokenID===_TokenID.COMMA||":"===this._token.value);){if(":"===this._token.value&&(s=!0),null==(l=this._getTableParameter()))throw"Invalid table reference.";s?(r[r.length-1]+=":"+l,s=!1):r.push(l)}if(this._token.tokenType!==_TokenType.SQUAREBRACKETS||this._token.tokenID!==_TokenID.CLOSE)throw"Unbalanced square brackets.";return this._tableRefStart=!1,n=this._getTableRange(e,r),this._containsCellRef=!0,i=new _CellRangeExpression(n,t.toLowerCase(),this._owner),i._tableParams=r,o&&(i._tableName=e.name),i},e.prototype._getTableParameter=function(){var e;for(this._pointer;this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;return"]"===this._expression[this._pointer]?(this._tableRefStart=!1,null):(this._getTableToken(),e=this._token.value,this._getToken(),e)},e.prototype._getTableRange=function(e,t){for(var o,n,i,r,l,s,a=0;a<t.length;a++){if(n)throw"Invalid Table Refernce.";if(o=t[a].toLowerCase(),l=null,"#"===o[0]){switch(o){case"#all":l=e.getRange();break;case"#data":l=e.getRange(TableSection.Data);break;case"#headers":l=e.getRange(TableSection.Header);break;case"#totals":l=e.getRange(TableSection.Footer);break;case"#this row":if(r=e.getRange(),!(this._rowIndex>=r.topRow&&this._rowIndex<=r.bottomRow))throw"The row is out of the table ("+e.name+") range.";l=new wjcGrid.CellRange(this._rowIndex,r.leftCol,this._rowIndex,r.rightCol);break;default:throw"Invalid Table Refernce."}if(null==l)throw"Invalid Table Refernce.";null==i?i=l:(i.row=i.topRow<l.topRow?i.topRow:l.topRow,i.row2=i.bottomRow>l.bottomRow?i.bottomRow:l.bottomRow)}else{n=!0,s=o.split(":");for(var h=0;h<s.length;h++){if(s.length>2)throw"Invalid Table Column Refernce.";if("@"===(o=s[h])[0]){if(null==(l=e.getRange(TableSection.Data,o.substring(1))))throw"Invalid Table Refernce.";if(!(this._rowIndex>=l.topRow&&this._rowIndex<=l.bottomRow))throw"The row is out of the table ("+e.name+") range.";l.row=this._rowIndex,l.row2=this._rowIndex}else if(null==(l=e.getRange(TableSection.Data,o)))throw"Invalid Table Refernce.";0===h&&(null==i?i=l:i.col=l.col),i.col2=l.col,l=null}}}return i},e.prototype._getAggregateResult=function(e,t,o){var n,i=this._getItemList(t,o);return n=wjcCore.getAggregate(e,i.items),i.isDate&&(n={value:n=new Date(n),format:i.format||"M/d/yyyy"}),n},e.prototype._getFlexSheetAggregateResult=function(e,t,o){var n,i,r,l;switch(e){case _FlexSheetAggregate.Count:return n=this._getItemList(t,o,!0,!1),this._countNumberCells(n.items);case _FlexSheetAggregate.CountA:return(n=this._getItemList(t,o,!1,!1)).items.length;case _FlexSheetAggregate.ConutBlank:return n=this._getItemList(t,o,!1,!0),this._countBlankCells(n.items);case _FlexSheetAggregate.Rank:if(r=_Expression.toNumber(t[0],this._rowIndex,this._columnIndex,o),l=t[2]?_Expression.toNumber(t[2],this._rowIndex,this._columnIndex,o):0,isNaN(r))throw"Invalid number.";if(isNaN(l))throw"Invalid order.";if(t[1]=this._ensureNonFunctionExpression(t[1]),t[1]instanceof _CellRangeExpression)return n=this._getItemList([t[1]],o),this._getRankOfCellRange(r,n.items,l);throw"Invalid Cell Reference.";case _FlexSheetAggregate.CountIf:if(t[0]=this._ensureNonFunctionExpression(t[0]),t[0]instanceof _CellRangeExpression)return n=this._getItemList([t[0]],o,!1),this._countCellsByCriterias([n.items],[t[1]],o);throw"Invalid Cell Reference.";case _FlexSheetAggregate.CountIfs:return this._handleCountIfs(t,o);case _FlexSheetAggregate.SumIf:if(t[0]=this._ensureNonFunctionExpression(t[0]),t[0]instanceof _CellRangeExpression)return n=this._getItemList([t[0]],o,!1),t[2]=this._ensureNonFunctionExpression(t[2]),null!=t[2]&&t[2]instanceof _CellRangeExpression&&(i=this._getItemList([t[2]],o)),this._sumCellsByCriterias([n.items],[t[1]],i?i.items:null,o);throw"Invalid Cell Reference.";case _FlexSheetAggregate.SumIfs:return this._handleSumIfs(t,o);case _FlexSheetAggregate.Product:return n=this._getItemList(t,o),this._getProductOfNumbers(n.items)}throw"Invalid aggregate type."},e.prototype._getItemList=function(e,t,o,n,i,r){void 0===o&&(o=!0),void 0===n&&(n=!1),void 0===i&&(i=!0);var l,s,a,h,c,d,u,_,g,w,p=new Array;for(s=0;s<e.length;s++)if(c=e[s],(c=this._ensureNonFunctionExpression(c))instanceof _CellRangeExpression){for(h=c.getValues(i,r,t),0===s&&((g=(_=c._getSheet()||t||this._sheet).getCellStyle(c.cells.topRow,c.cells.leftCol))&&(u=g.format),u||(w=_.grid.columns[c.cells.leftCol])&&(u=w.format)),a=0;a<h.length;a++)if(l=h[a],n||null!=l&&""!==l){if(wjcCore.isString(l)&&0===l.indexOf("Error: ")){p=[0];break}null==d&&(d=l instanceof Date),l=o&&!wjcCore.isBoolean(l)?+l:l,p.push(l)}}else{if(l=c instanceof _Expression?c.evaluate(this._rowIndex,this._columnIndex,t):c,wjcCore.isPrimitive(l)||(l=l.value),!n&&(null==l||""===l))continue;if(wjcCore.isString(l)&&0===l.indexOf("Error: ")){p=[0];break}null==d&&(d=l instanceof Date),l=o?+l:l,p.push(l)}return 0===p.length&&(d=!1),{isDate:d,items:p,format:u}},e.prototype._countBlankCells=function(e){for(var t,o=0,n=0;o<e.length;o++)(null==(t=e[o])||wjcCore.isString(t)&&""===t||wjcCore.isNumber(t)&&isNaN(t))&&n++;return n},e.prototype._countNumberCells=function(e){for(var t,o=0,n=0;o<e.length;o++)null!=(t=e[o])&&wjcCore.isNumber(t)&&!isNaN(t)&&n++;return n},e.prototype._getRankOfCellRange=function(e,t,o){void 0===o&&(o=0);var n,i=0,r=0;for(o?t.sort(function(e,t){return isNaN(e)||isNaN(t)?-1:e-t}):t.sort(function(e,t){return isNaN(e)||isNaN(t)?1:t-e});i<t.length;i++)if(n=t[i],!isNaN(n)&&(r++,e===n))return r;throw e+" is not in the cell range."},e.prototype._handleCountIfs=function(e,t){var o,n,i,r,l=0,s=[],a=[];if(e.length%2!=0)throw"Invalid params.";for(;l<e.length/2;l++){if(n=e[2*l],!((n=this._ensureNonFunctionExpression(n))instanceof _CellRangeExpression))throw"Invalid Cell Reference.";if(0===l){if(!n.cells)throw"Invalid Cell Reference.";i=n.cells.rowSpan,r=n.cells.columnSpan}else{if(!n.cells)throw"Invalid Cell Reference.";if(n.cells.rowSpan!==i||n.cells.columnSpan!==r)throw"The row span and column span of each cell range has to be same with each other."}o=this._getItemList([n],t,!1),s[l]=o.items,a[l]=e[2*l+1]}return this._countCellsByCriterias(s,a,t)},e.prototype._countCellsByCriterias=function(e,t,o,n){for(var i,r,l,s,a,h=0,c=0,d=0,u=e[0].length,_=[];c<t.length;c++)"*"===(a=_Expression.toString(t[c],this._rowIndex,this._columnIndex,o))?_.push(a):_.push(this._parseRightExpr(a));for(;h<u;h++){i=!1;e:for(c=0;c<e.length;c++)if(l=e[c],s=l[h],"string"==typeof(a=_[c])){if("*"!==a&&(null==s||""===s)){i=!1;break e}if(!(i="*"===a||this.evaluate(this._combineExpr(s,a),null,o,this._rowIndex,this._columnIndex)))break e}else if(!(i=i=a.reg.test(s.toString())===a.checkMathces))break e;i&&(n?null!=(r=n[h])&&wjcCore.isNumber(r)&&!isNaN(r)&&d++:d++)}return d},e.prototype._handleSumIfs=function(e,t){var o,n,i,r,l,s,a=1,h=[],c=[];if(e.length%2!=1)throw"Invalid params.";if(i=e[0],!((i=this._ensureNonFunctionExpression(i))instanceof _CellRangeExpression))throw"Invalid Sum Cell Reference.";if(!i.cells)throw"Invalid Sum Cell Reference.";for(l=i.cells.rowSpan,s=i.cells.columnSpan,n=this._getItemList([i],t);a<(e.length+1)/2;a++){if(r=e[2*a-1],!((r=this._ensureNonFunctionExpression(r))instanceof _CellRangeExpression))throw"Invalid Criteria Cell Reference.";if(!r.cells)throw"Invalid Criteria Cell Reference.";if(r.cells.rowSpan!==l||r.cells.columnSpan!==s)throw"The row span and column span of each cell range has to be same with each other.";o=this._getItemList([r],t,!1),h[a-1]=o.items,c[a-1]=e[2*a]}return this._sumCellsByCriterias(h,c,n.items,t)},e.prototype._sumCellsByCriterias=function(e,t,o,n){var i,r,l,s,a,h=0,c=0,d=0,u=e[0].length,_=[];for(null==o&&(o=e[0]);c<t.length;c++)"*"===(a=_Expression.toString(t[c],this._rowIndex,this._columnIndex,n))?_.push(a):_.push(this._parseRightExpr(a));for(;h<u;h++){r=!1,i=o[h];e:for(c=0;c<e.length;c++)if(l=e[c],s=l[h],"string"==typeof(a=_[c])){if("*"!==a&&(null==s||""===s)){r=!1;break e}if(!(r="*"===a||this.evaluate(this._combineExpr(s,a),null,n,this._rowIndex,this._columnIndex)))break e}else if(!(r=a.reg.test(s.toString())===a.checkMathces))break e;r&&wjcCore.isNumber(i)&&!isNaN(i)&&(d+=i)}return d},e.prototype._getProductOfNumbers=function(e){var t,o=0,n=1,i=!1;if(e)for(;o<e.length;o++)t=e[o],wjcCore.isNumber(t)&&!isNaN(t)&&(n*=t,i=!0);return i?n:0},e.prototype._handleSubtotal=function(e,t){var o,n,i,r,l=!0;if((o=_Expression.toNumber(e[0],this._rowIndex,this._columnIndex,t))>=1&&o<=11||o>=101&&o<=111){switch(o>=101&&o<=111&&(l=!1),o=wjcCore.asEnum(o,_SubtotalFunction),n=this._getItemList(e.slice(1),t,!0,!1,l),o){case _SubtotalFunction.Count:case _SubtotalFunction.CountWithoutHidden:return this._countNumberCells(n.items);case _SubtotalFunction.CountA:case _SubtotalFunction.CountAWithoutHidden:return n.items.length;case _SubtotalFunction.Product:case _SubtotalFunction.ProductWithoutHidden:return this._getProductOfNumbers(n.items);case _SubtotalFunction.Average:case _SubtotalFunction.AverageWithoutHidden:i=wjcCore.Aggregate.Avg;break;case _SubtotalFunction.Max:case _SubtotalFunction.MaxWithoutHidden:i=wjcCore.Aggregate.Max;break;case _SubtotalFunction.Min:case _SubtotalFunction.MinWithoutHidden:i=wjcCore.Aggregate.Min;break;case _SubtotalFunction.Std:case _SubtotalFunction.StdWithoutHidden:i=wjcCore.Aggregate.Std;break;case _SubtotalFunction.StdPop:case _SubtotalFunction.StdPopWithoutHidden:i=wjcCore.Aggregate.StdPop;break;case _SubtotalFunction.Sum:case _SubtotalFunction.SumWithoutHidden:i=wjcCore.Aggregate.Sum;break;case _SubtotalFunction.Var:case _SubtotalFunction.VarWithoutHidden:i=wjcCore.Aggregate.Var;break;case _SubtotalFunction.VarPop:case _SubtotalFunction.VarPopWithoutHidden:i=wjcCore.Aggregate.VarPop}return r=wjcCore.getAggregate(i,n.items),n.isDate&&(r=new Date(r)),r}throw"Invalid Subtotal function."},e.prototype._handleDCount=function(e,t){var o,n,i,r=e[0],l=e[2];if(r=this._ensureNonFunctionExpression(r),l=this._ensureNonFunctionExpression(l),r instanceof _CellRangeExpression&&l instanceof _CellRangeExpression&&(o=e[1].evaluate(this._rowIndex,this._columnIndex,t),n=this._getColumnIndexByField(r,o),(i=this._getItemList([r],t,!0,!1,!0,n)).items&&i.items.length>1))return this._DCountWithCriterias(i.items.slice(1),r,l);throw"Invalid Count Cell Reference."},e.prototype._DCountWithCriterias=function(e,t,o){var n,i,r,l,s,a,h,c,d,u,_,g=o.cells,w=0;if(n=this._getSheet(t.sheetRef),i=this._getSheet(o.sheetRef),g.rowSpan>1){for(r=g.topRow,l=g.bottomRow;l>g.topRow;l--){for(u=[],_=[],s=g.leftCol;s<=g.rightCol;s++)if(null!=(h=this._owner.getCellValue(l,s,!1,i))&&""!==h){if(_.push(new _Expression(h)),c=this._owner.getCellValue(r,s,!1,i),a=this._getColumnIndexByField(t,c),!(null!=(d=this._getItemList([t],n,!1,!1,!0,a)).items&&d.items.length>1))throw"Invalid Count Cell Reference.";u.push(d.items.slice(1))}w+=this._countCellsByCriterias(u,_,n,e)}return w}throw"Invalid Criteria Cell Reference."},e.prototype._getColumnIndexByField=function(e,t){var o,n,i,r,l;if(o=e.cells,-1===(l=o.topRow))throw"Invalid Count Cell Reference.";if(wjcCore.isInt(t)&&!isNaN(t)){if(t>=1&&t<=o.columnSpan)return i=o.leftCol+t-1}else for(n=this._getSheet(e.sheetRef),i=o.leftCol;i<=o.rightCol;i++)if(r=this._owner.getCellValue(l,i,!1,n),t=wjcCore.isString(t)?t.toLowerCase():t,r=wjcCore.isString(r)?r.toLowerCase():r,t===r)return i;throw"Invalid field."},e.prototype._getSumProduct=function(e,t){var o,n,i,r=0,l=this._getItemListForSumProduct(e,t);if(l.length>0){n=l[0].length,i=l.length;for(var s=0;s<n;s++){o=1;for(var a=0;a<i;a++)o*=l[a][s];r+=o}}return r},e.prototype._getItemListForSumProduct=function(e,t){var o,n,i,r,l,s,a=[new Array];for(i=0;i<e.length;i++){if(s=e[i],o=new Array,(s=this._ensureNonFunctionExpression(s))instanceof _CellRangeExpression)for(l=s.getValues(!0,null,t),r=0;r<l.length;r++)n=l[r],o.push(+n);else n=s instanceof _Expression?s.evaluate(this._rowIndex,this._columnIndex,t):s,o.push(+n);if(i>0&&o.length!==a[0].length)throw"The cell ranges of the sumProduct formula must have the same dimensions.";a[i]=o}return a},e.prototype._getSheet=function(e){var t,o=0;if(e)for(;o<this._owner.sheets.length&&(t=this._owner.sheets[o]).name!==e;o++);return t},e.prototype._parseRightExpr=function(e){var t,o,n=!1;if(e.indexOf("?")>-1||e.indexOf("*")>-1){if(null==(t=e.match(/([\?\*]*)(\w+)([\?\*]*)(\w+)([\?\*]*)/))||6!==t.length)throw"Invalid Criteria.";return o=new RegExp("^"+(t[1].length>0?this._parseRegCriteria(t[1]):"")+t[2]+(t[3].length>0?this._parseRegCriteria(t[3]):"")+t[4]+(t[5].length>0?this._parseRegCriteria(t[5]):"")+"$","i"),/^[<>=]/.test(e)?"="===e.trim()[0]&&(n=!0):n=!0,{reg:o,checkMathces:n}}if(isNaN(+e))if(/^\w/.test(e))e='="'+e+'"';else{if(!/^[<>=]{1,2}\s*-?.+$/.test(e))throw"Invalid Criteria.";e=e.replace(/([<>=]{1,2})\s*(-?.+)/,'$1"$2"')}else e="="+ +e;return e},e.prototype._combineExpr=function(e,t){return(wjcCore.isString(e)||wjcCore.isDate(e))&&(e='"'+e+'"'),(e="="+e)+t},e.prototype._parseRegCriteria=function(e){for(var t=0,o=0,n="";t<e.length;t++)"*"===e[t]?(o>0&&(n+="\\w{"+o+"}",o=0),n+="\\w*"):"?"===e[t]&&o++;return o>0&&(n+="\\w{"+o+"}"),n},e.prototype._calculateRate=function(e,t){var o,n,i,r,l,s,a,h,c,d,u=0,_=0;for(i=_Expression.toNumber(e[0],this._rowIndex,this._columnIndex,t),r=_Expression.toNumber(e[1],this._rowIndex,this._columnIndex,t),l=_Expression.toNumber(e[2],this._rowIndex,this._columnIndex,t),s=null!=e[3]?_Expression.toNumber(e[3],this._rowIndex,this._columnIndex,t):0,a=null!=e[4]?_Expression.toNumber(e[4],this._rowIndex,this._columnIndex,t):0,n=null!=e[5]?_Expression.toNumber(e[5],this._rowIndex,this._columnIndex,t):.1,Math.abs(n)<1e-7?l*(1+i*n)+r*(1+n*a)*i+s:l*(h=Math.exp(i*Math.log(1+n)))+r*(1/n+a)*(h-1)+s,c=l+r*i+s,d=l*h+r*(1/n+a)*(h-1)+s,o=n;Math.abs(c-d)>1e-7&&u<20;)n=(d*_-c*o)/(d-c),_=o,o=n,c=d,d=Math.abs(n)<1e-7?l*(1+i*n)+r*(1+n*a)*i+s:l*(h=Math.exp(i*Math.log(1+n)))+r*(1/n+a)*(h-1)+s,++u;if(Math.abs(c-d)>1e-7&&20===u)throw"It is not able to calculate the rate with current parameters.";return n},e.prototype._handleHLookup=function(e,t){var o,n,i=e[0].evaluate(this._rowIndex,this._columnIndex,t),r=e[1],l=_Expression.toNumber(e[2],this._rowIndex,this._columnIndex,t),s=null==e[3]||_Expression.toBoolean(e[3],this._rowIndex,this._columnIndex,t);if(null==i||""==i)throw"Invalid lookup value.";if(isNaN(l)||l<0)throw"Invalid row index.";if((r=this._ensureNonFunctionExpression(r))instanceof _CellRangeExpression){if(o=r.cells,l>o.rowSpan)throw"Row index is out of the cell range.";if(s?-1===(n=this._exactMatch(i,o,t,!1))&&(n=this._approximateMatch(i,o,t)):n=this._exactMatch(i,o,t),-1===n)throw"Lookup Value is not found.";return this._owner.getCellValue(o.topRow+l-1,n,!1,t)}throw"Invalid Cell Reference."},e.prototype._exactMatch=function(e,t,o,n){void 0===n&&(n=!0);var i,r,l,s,a=t.topRow;if(wjcCore.isString(e)&&(e=e.toLowerCase()),n&&wjcCore.isString(e)&&(e.indexOf("?")>-1||e.indexOf("*")>-1)){if(null==(l=e.match(/([\?\*]*)(\w+)([\?\*]*)(\w+)([\?\*]*)/))||6!==l.length)throw"Invalid lookup value.";s=new RegExp("^"+(l[1].length>0?this._parseRegCriteria(l[1]):"")+l[2]+(l[3].length>0?this._parseRegCriteria(l[3]):"")+l[4]+(l[5].length>0?this._parseRegCriteria(l[5]):"")+"$","i")}for(i=t.leftCol;i<=t.rightCol;i++)if(r=this._owner.getCellValue(a,i,!1,o),null!=s){if(s.test(r))return i}else if(wjcCore.isString(r)&&(r=r.toLowerCase()),e===r)return i;return-1},e.prototype._approximateMatch=function(e,t,o){var n,i,r=t.topRow,l=[],s=0;for(wjcCore.isString(e)&&(e=e.toLowerCase()),i=t.leftCol;i<=t.rightCol;i++)n=this._owner.getCellValue(r,i,!1,o),n=isNaN(+n)?n:+n,l.push({value:n,index:i});for(l.sort(function(e,t){return wjcCore.isString(e.value)&&(e.value=e.value.toLowerCase()),wjcCore.isString(t.value)&&(t.value=t.value.toLowerCase()),e.value>t.value?-1:e.value===t.value?t.index-e.index:1});s<l.length;s++)if(n=l[s],wjcCore.isString(n.value)&&(n.value=n.value.toLowerCase()),e>n.value)return n.index;throw"Lookup Value is not found."},e.prototype._parseToScientificValue=function(e,t,o,n,i){var r,l,s,a,h=0;if(Math.abs(e)>=1)for(l="+",r=Math.pow(10,t.length);e>r;)e/=r,h+=t.length;else for(l="-",r=Math.pow(10,t.length);e*r<r;)e*=r,h+=t.length;if(s=wjcCore.Globalize.format(e,"D"+t.length),o)for((s+=wjcCore.Globalize.format(e-Math.floor(e),t+o).substring(1)).indexOf(".")>-1?a=s.length-1-s.indexOf("."):(s+=".",a=0);a<o.length-1;)s+="0",a++;if(s+="E"+l+wjcCore.Globalize.format(h,"D"+n.length),i){s+=".";for(var c=1;c<i.length;c++)s+="0"}return s},e.prototype._checkCache=function(e,t,o,n){null!=t&&(this._sheet=this._owner.sheets[t]),null!=o&&(this._rowIndex=o),null!=n&&(this._columnIndex=n);var i=this._expressionCache[e]||this._expressionCache[this._rowIndex+"_"+this._columnIndex+":"+e];if(i)return i;if(i=this._parse(e),this._token.tokenID!==_TokenID.END||this._token.tokenType!==_TokenType.GROUP)throw"Invalid Expression: "+e;return this._cacheSize>1e4&&this._clearExpressionCache(),this._expressionCache[(this._containsCellRef?this._rowIndex+"_"+this._columnIndex+":":"")+e]=i,this._cacheSize++,i},e.prototype._ensureNonFunctionExpression=function(e,t){for(;e instanceof _FunctionExpression;)e=e.evaluate(this._rowIndex,this._columnIndex,t);return e},e.prototype._getDefinedName=function(e,t){for(var o,n,i=0;i<this._owner.definedNames.length;i++)if((o=this._owner.definedNames[i]).name.toLowerCase()===e)if(o.sheetName){if(o.sheetName.toLowerCase()===t)return o}else n=o;return n},e}();exports._CalcEngine=_CalcEngine;var _Token=function(){function e(e,t,o){this._value=e,this._tokenID=t,this._tokenType=o}return Object.defineProperty(e.prototype,"value",{get:function(){return this._value},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tokenID",{get:function(){return this._tokenID},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tokenType",{get:function(){return this._tokenType},enumerable:!0,configurable:!0}),e}();exports._Token=_Token;var _FunctionDefinition=function(){function e(e,t,o){this._paramMax=Number.MAX_VALUE,this._paramMin=Number.MIN_VALUE,this._func=e,wjcCore.isNumber(t)&&!isNaN(t)&&(this._paramMax=t),wjcCore.isNumber(o)&&!isNaN(o)&&(this._paramMin=o)}return Object.defineProperty(e.prototype,"paramMax",{get:function(){return this._paramMax},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"paramMin",{get:function(){return this._paramMin},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"func",{get:function(){return this._func},enumerable:!0,configurable:!0}),e}();exports._FunctionDefinition=_FunctionDefinition;var _TokenType;!function(e){e[e.COMPARE=0]="COMPARE",e[e.ADDSUB=1]="ADDSUB",e[e.MULDIV=2]="MULDIV",e[e.POWER=3]="POWER",e[e.CONCAT=4]="CONCAT",e[e.GROUP=5]="GROUP",e[e.LITERAL=6]="LITERAL",e[e.IDENTIFIER=7]="IDENTIFIER",e[e.SQUAREBRACKETS=8]="SQUAREBRACKETS"}(_TokenType=exports._TokenType||(exports._TokenType={}));var _TokenID;!function(e){e[e.GT=0]="GT",e[e.LT=1]="LT",e[e.GE=2]="GE",e[e.LE=3]="LE",e[e.EQ=4]="EQ",e[e.NE=5]="NE",e[e.ADD=6]="ADD",e[e.SUB=7]="SUB",e[e.MUL=8]="MUL",e[e.DIV=9]="DIV",e[e.DIVINT=10]="DIVINT",e[e.MOD=11]="MOD",e[e.POWER=12]="POWER",e[e.CONCAT=13]="CONCAT",e[e.OPEN=14]="OPEN",e[e.CLOSE=15]="CLOSE",e[e.END=16]="END",e[e.COMMA=17]="COMMA",e[e.PERIOD=18]="PERIOD",e[e.ATOM=19]="ATOM"}(_TokenID=exports._TokenID||(exports._TokenID={}));var _FlexSheetAggregate;!function(e){e[e.Count=0]="Count",e[e.CountA=1]="CountA",e[e.ConutBlank=2]="ConutBlank",e[e.CountIf=3]="CountIf",e[e.CountIfs=4]="CountIfs",e[e.Rank=5]="Rank",e[e.SumIf=6]="SumIf",e[e.SumIfs=7]="SumIfs",e[e.Product=8]="Product"}(_FlexSheetAggregate||(_FlexSheetAggregate={}));var _SubtotalFunction;!function(e){e[e.Average=1]="Average",e[e.Count=2]="Count",e[e.CountA=3]="CountA",e[e.Max=4]="Max",e[e.Min=5]="Min",e[e.Product=6]="Product",e[e.Std=7]="Std",e[e.StdPop=8]="StdPop",e[e.Sum=9]="Sum",e[e.Var=10]="Var",e[e.VarPop=11]="VarPop",e[e.AverageWithoutHidden=101]="AverageWithoutHidden",e[e.CountWithoutHidden=102]="CountWithoutHidden",e[e.CountAWithoutHidden=103]="CountAWithoutHidden",e[e.MaxWithoutHidden=104]="MaxWithoutHidden",e[e.MinWithoutHidden=105]="MinWithoutHidden",e[e.ProductWithoutHidden=106]="ProductWithoutHidden",e[e.StdWithoutHidden=107]="StdWithoutHidden",e[e.StdPopWithoutHidden=108]="StdPopWithoutHidden",e[e.SumWithoutHidden=109]="SumWithoutHidden",e[e.VarWithoutHidden=110]="VarWithoutHidden",e[e.VarPopWithoutHidden=111]="VarPopWithoutHidden"}(_SubtotalFunction||(_SubtotalFunction={}));var _Expression=function(){function e(e){this._token=e?e instanceof _Token?e:new _Token(e,_TokenID.ATOM,_TokenType.LITERAL):new _Token(null,_TokenID.ATOM,_TokenType.IDENTIFIER)}return Object.defineProperty(e.prototype,"token",{get:function(){return this._token},enumerable:!0,configurable:!0}),e.prototype.evaluate=function(e,t,o){if(this._token.tokenType!==_TokenType.LITERAL)throw"Bad expression.";return this._token.value},e.toString=function(e,t,o,n){var i=e.evaluate(t,o,n);return wjcCore.isPrimitive(i)||(i=i.value),null!=i?i.toString():""},e.toNumber=function(e,t,o,n){var i=e.evaluate(t,o,n),r=["January","February","March","April","May","June","July","August","September","October","November","December","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];if(wjcCore.isPrimitive(i)||(i=i.value),wjcCore.isNumber(i))return i;if(wjcCore.isBoolean(i))return i?1:0;if(wjcCore.isDate(i))return this._toOADate(i);if(wjcCore.isString(i)){if(i){if(isNaN(+i)){for(var l in r)if(i.indexOf(r[l])>-1)return this._toOADate(new Date(i));return+i}return+i}return 0}return wjcCore.changeType(i,wjcCore.DataType.Number,"")},e.toBoolean=function(e,t,o,n){var i=e.evaluate(t,o,n);return wjcCore.isPrimitive(i)||(i=i.value),wjcCore.isBoolean(i)?i:wjcCore.isNumber(i)?0!==i:wjcCore.changeType(i,wjcCore.DataType.Boolean,"")},e.toDate=function(e,t,o,n){var i=e.evaluate(t,o,n);return wjcCore.isPrimitive(i)||(i=i.value),wjcCore.isDate(i)?i:wjcCore.isNumber(i)?this._fromOADate(i):wjcCore.changeType(i,wjcCore.DataType.Date,"")},e._toOADate=function(e){var t=Date.UTC(1899,11,30);return(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())-t)/864e5},e._fromOADate=function(e){var t=Date.UTC(1899,11,30),o=new Date,n=e>=60?0:864e5;return new Date(864e5*e+t+6e4*o.getTimezoneOffset()+n)},e.prototype._updateCellRangeExp=function(e,t,o,n,i){return!1},e.prototype._moveCellRangeExp=function(e,t,o,n,i){return void 0===n&&(n=!1),void 0===i&&(i=!1),!1},e.prototype._updateCellRangeExpForReorderingRows=function(e){return!1},e.prototype._getStringExpression=function(){return null==this._token.value?"":wjcCore.isString(this._token.value)?'"'+this._token.value+'"':this._token.value.toString()},e}();exports._Expression=_Expression;var _UnaryExpression=function(e){function t(t,o){var n=e.call(this,t)||this;return n._expr=o,n}return __extends(t,e),t.prototype.evaluate=function(e,t,o){if(this.token.tokenID===_TokenID.SUB)return null==this._evaluatedValue&&(this._evaluatedValue=-_Expression.toNumber(this._expr,e,t,o)),this._evaluatedValue;if(this.token.tokenID===_TokenID.ADD)return null==this._evaluatedValue&&(this._evaluatedValue=+_Expression.toNumber(this._expr,e,t,o)),this._evaluatedValue;throw"Bad expression."},t.prototype._updateCellRangeExp=function(e,t,o,n,i){return this._expr._updateCellRangeExp(e,t,o,n,i)},t.prototype._moveCellRangeExp=function(e,t,o,n,i){return void 0===n&&(n=!1),void 0===i&&(i=!1),this._expr._moveCellRangeExp(e,t,o,n,i)},t.prototype._updateCellRangeExpForReorderingRows=function(e){return this._expr._updateCellRangeExpForReorderingRows(e)},t.prototype._getStringExpression=function(){return this.token.tokenID===_TokenID.SUB?"-"+this._expr._getStringExpression():this.token.tokenID===_TokenID.ADD?"+"+this._expr._getStringExpression():""},t}(_Expression);exports._UnaryExpression=_UnaryExpression;var _BinaryExpression=function(e){function t(t,o,n){var i=e.call(this,t)||this;return i._leftExpr=o,i._rightExpr=n,i}return __extends(t,e),t.prototype.evaluate=function(e,t,o){var n,i,r,l,s,a,h,c=!1;if(null!=this._evaluatedValue)return this._evaluatedValue;if(n=_Expression.toString(this._leftExpr,e,t,o),i=_Expression.toString(this._rightExpr,e,t,o),this.token.tokenType===_TokenType.CONCAT)return this._evaluatedValue=n+i,this._evaluatedValue;if(r=this._leftExpr.evaluate(e,t,o),l=this._rightExpr.evaluate(e,t,o),c=this._isDateValue(r)||this._isDateValue(l),s=_Expression.toNumber(this._leftExpr,e,t,o),a=_Expression.toNumber(this._rightExpr,e,t,o),h=s-a,this.token.tokenType===_TokenType.COMPARE)switch(this.token.tokenID){case _TokenID.GT:return h>0;case _TokenID.LT:return h<0;case _TokenID.GE:return h>=0;case _TokenID.LE:return h<=0;case _TokenID.EQ:return isNaN(h)?(this._evaluatedValue=n.toLowerCase()===i.toLowerCase(),this._evaluatedValue):(this._evaluatedValue=0===h,this._evaluatedValue);case _TokenID.NE:return isNaN(h)?(this._evaluatedValue=n.toLowerCase()!==i.toLowerCase(),this._evaluatedValue):(this._evaluatedValue=0!==h,this._evaluatedValue)}switch(this.token.tokenID){case _TokenID.ADD:this._evaluatedValue=s+a;break;case _TokenID.SUB:this._evaluatedValue=s-a;break;case _TokenID.MUL:this._evaluatedValue=s*a;break;case _TokenID.DIV:this._evaluatedValue=s/a;break;case _TokenID.DIVINT:this._evaluatedValue=Math.floor(s/a);break;case _TokenID.MOD:this._evaluatedValue=Math.floor(s%a);break;case _TokenID.POWER:0===a&&(this._evaluatedValue=1),.5===a&&(this._evaluatedValue=Math.sqrt(s)),1===a&&(this._evaluatedValue=s),2===a&&(this._evaluatedValue=s*s),3===a&&(this._evaluatedValue=s*s*s),4===a&&(this._evaluatedValue=s*s*s*s),this._evaluatedValue=Math.pow(s,a);break;default:this._evaluatedValue=NaN}if(!isNaN(this._evaluatedValue))return c&&(this._evaluatedValue={value:_Expression._fromOADate(this._evaluatedValue),format:r.format||l.format}),this._evaluatedValue;throw"Bad expression."},t.prototype._updateCellRangeExp=function(e,t,o,n,i){var r,l=!1;return r=this._leftExpr._updateCellRangeExp(e,t,o,n,i),l=l||r,r=this._rightExpr._updateCellRangeExp(e,t,o,n,i),l||r},t.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1),void 0===i&&(i=!1);var r,l=!1;return r=this._leftExpr._moveCellRangeExp(e,t,o,n,i),l=l||r,r=this._rightExpr._moveCellRangeExp(e,t,o,n,i),l||r},t.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o=!1;return t=this._leftExpr._updateCellRangeExpForReorderingRows(e),o=o||t,t=this._rightExpr._updateCellRangeExpForReorderingRows(e),o||t},t.prototype._getStringExpression=function(){var e;switch(this.token.tokenID){case _TokenID.GT:e=">";break;case _TokenID.LT:e="<";break;case _TokenID.GE:e=">=";break;case _TokenID.LE:e="<=";break;case _TokenID.EQ:e="=";break;case _TokenID.NE:e="<>";break;case _TokenID.ADD:e="+";break;case _TokenID.SUB:e="-";break;case _TokenID.MUL:e="*";break;case _TokenID.DIV:e="/";break;case _TokenID.DIVINT:e="\\";break;case _TokenID.POWER:e="^";break;default:return""}return this._leftExpr._getStringExpression()+e+this._rightExpr._getStringExpression()},t.prototype._isDateValue=function(e){return wjcCore.isPrimitive(e)?wjcCore.isDate(e):wjcCore.isDate(e.value)},t}(_Expression);exports._BinaryExpression=_BinaryExpression;var _CellRangeExpression=function(e){function t(t,o,n,i,r,l,s,a){void 0===i&&(i=!0),void 0===r&&(r=!1),void 0===l&&(l=!1),void 0===s&&(s=!1),void 0===a&&(a=!1);var h=e.call(this)||this;return h._cells=new wjcGrid.CellRange(t.topRow,t.leftCol,t.bottomRow,t.rightCol),h._sheetRef=o,h._flex=n,h._evalutingRange={},h._isCellRange=i,h._absRow=r,h._absCol=l,h._absRow2=s,h._absCol2=a,h}return __extends(t,e),t.prototype.evaluate=function(e,t,o){return null==this._evaluatedValue&&(this._evaluatedValue=this._getCellValue(this._cells,o,e,t)),this._evaluatedValue},t.prototype.getValues=function(e,t,o){void 0===e&&(e=!0);var n,i,t,r,l,s=[],a=0;if(r=null==t||isNaN(+t)?this._cells.leftCol:t,l=null==t||isNaN(+t)?this._cells.rightCol:t,!(o=this._getSheet()||o||this._flex.selectedSheet))return null;for(i=this._cells.topRow;i<=this._cells.bottomRow;i++){if(i>=o.grid.rows.length)throw"The cell reference is out of the cell range of the flexsheet.";if(e||!1!==o.grid.rows[i].isVisible)for(t=r;t<=l;t++){if(t>=o.grid.columns.length)throw"The cell reference is out of the cell range of the flexsheet.";(e||!1!==o.grid.columns[t].isVisible)&&(n=this._getCellValue(new wjcGrid.CellRange(i,t),o),wjcCore.isPrimitive(n)||(n=n.value),s[a]=n,a++)}}return s},t.prototype.getValuseWithTwoDimensions=function(e,t){void 0===e&&(e=!0);var o,n,i,r,l=[],s=0,a=0;if(!(t=this._getSheet()||t||this._flex.selectedSheet))return null;for(i=this._cells.topRow;i<=this._cells.bottomRow;i++){if(i>=t.grid.rows.length)throw"The cell reference is out of the cell range of the flexsheet.";if(e||!1!==t.grid.rows[i].isVisible){for(n=[],a=0,r=this._cells.leftCol;r<=this._cells.rightCol;r++){if(r>=t.grid.columns.length)throw"The cell reference is out of the cell range of the flexsheet.";e||!1!==t.grid.columns[r].isVisible?(o=this._getCellValue(new wjcGrid.CellRange(i,r),t),wjcCore.isPrimitive(o)||(o=o.value),n[a]=o,a++):a++}l[s]=n,s++}else s++}return l},Object.defineProperty(t.prototype,"cells",{get:function(){return this._cells},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"sheetRef",{get:function(){return this._sheetRef},enumerable:!0,configurable:!0}),t.prototype._getCellValue=function(e,t,o,n){var t,i,r,l;if(!(t=this._getSheet()||t||this._flex.selectedSheet))return null;if(e.isSingleCell?(r=e.row,l=e.col):(null!=o&&o>=e.topRow&&o<=e.bottomRow&&e.col===e.col2&&(r=o,l=e.col),null!=n&&n>=e.leftCol&&n<=e.rightCol&&e.row===e.row2&&(r=e.row,l=n)),null==r||null==l)throw"Invalid Cell Reference.";if(i=t.name+":"+r+","+l+"-"+r+","+l,this._evalutingRange[i])throw"Circular Reference";try{if(this._flex)return this._evalutingRange[i]=!0,r<t.rowCount&&l<t.columnCount?this._flex.getCellValue(r,l,!1,t):0}finally{delete this._evalutingRange[i]}},t.prototype._getSheet=function(){var e,t=0;if(!this._sheetRef)return null;for(;t<this._flex.sheets.length;t++)if((e=this._flex.sheets[t]).name.toLowerCase()===this._sheetRef)return e;throw"Invalid sheet reference"},t.prototype._updateCellRangeExp=function(e,t,o,n,i){var r=this._cells,l=!1;if(this._tableParams&&this._tableParams.length>0)return!1;if(e===this._flex.selectedSheetIndex){if(this._sheetRef&&this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase())return!1}else if(!this._sheetRef||this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase())return!1;return i?n?r.topRow>=t?(r.row+=o,r.row2+=o,l=!0):r.topRow<t&&r.bottomRow>=t&&(r.row2+=o,l=!0):r.topRow>t?(r.row-=o,r.row2-=o,l=!0):r.isSingleCell?r.row>=t-o+1&&(r.row=t-o+1,r.row2=t-o+1,l=!0):r.topRow>=t-o+1?(r.row=t-o+1,r.row2-=o,l=!0):r.topRow<t-o+1&&r.bottomRow>=t-o+1&&(r.bottomRow>t?r.row2-=o:r.row2=t-o,l=!0):n?r.leftCol>=t?(r.col+=o,r.col2+=o,l=!0):r.leftCol<t&&r.rightCol>=t&&(r.col2+=o,l=!0):r.leftCol>t?(r.col-=o,r.col2-=o,l=!0):r.isSingleCell?r.col>=t-o+1&&(r.col=t-o+1,r.col2=t-o+1,l=!0):r.leftCol>=t-o+1?(r.col=t-o+1,r.col2-=o,l=!0):r.leftCol<t-o+1&&r.rightCol>=t-o+1&&(r.rightCol>t?r.col2-=o:r.col2=t-o,l=!0),l},t.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1),void 0===i&&(i=!1);var r,l,s=this._cells,a=!1;return!(this._tableParams&&this._tableParams.length>0)&&(r=o.topRow-t.topRow,l=o.leftCol-t.leftCol,i?(0!==r&&(s.row+=i&&this._absRow?0:r,s.row2+=this._isCellRange?i&&this._absRow2?0:r:i&&this._absRow?0:r,a=!0),0!==l&&(s.col+=i&&this._absCol?0:l,s.col2+=this._isCellRange?i&&this._absCol2?0:l:i&&this._absCol?0:l,a=!0),a):(t.contains(s)?(0!==r&&(s.row+=r,s.row2+=r,a=!0),0!==l&&(s.col+=l,s.col2+=l,a=!0)):t.intersects(s)?(t.intersectsRow(s)&&0!==r&&(t.topRow<=s.topRow?r<0?(s.row+=r,a=!0):r>0&&n&&(t.topRow<s.topRow&&(s.row-=s.topRow-t.topRow),s.row2-=t.rowSpan,a=!0):t.bottomRow>=s.bottomRow?r>0?(s.row2+=r,a=!0):r<0&&n&&(t.bottomRow>s.bottomRow&&(s.row2+=t.bottomRow-s.bottomRow),s.row+=t.rowSpan,a=!0):n&&(r<0?s.row+=t.rowSpan:s.row2-=t.rowSpan,a=!0)),t.intersectsColumn(s)&&0!==l&&(t.leftCol<=s.leftCol?l<0?(s.col+=l,a=!0):l>0&&n&&(t.leftCol<s.leftCol&&(s.col-=s.leftCol-t.leftCol),s.col2-=t.columnSpan,a=!0):t.rightCol>=s.rightCol?l>0?(s.col2+=l,a=!0):l<0&&n&&(t.rightCol>s.rightCol&&(s.col2+=t.rightCol-s.rightCol),s.col+=t.columnSpan,a=!0):n&&(l<0?s.col+=t.columnSpan:s.col2-=t.columnSpan,a=!0))):n&&(s.topRow>t.bottomRow&&r>0&&(s.row-=t.rowSpan,s.row2-=t.rowSpan,a=!0),s.bottomRow<t.topRow&&r<0&&(s.row+=t.rowSpan,s.row2+=t.rowSpan,a=!0),s.leftCol>t.rightCol&&l>0&&(s.col-=t.columnSpan,s.col2-=t.columnSpan,a=!0),s.rightCol<t.leftCol&&l<0&&(s.col+=t.columnSpan,s.col2+=t.columnSpan,a=!0)),a))},t.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o=this._cells;return(t=this._cells.row+e)<0?t=0:t>=this._flex.rows.length&&(t=this._flex.rows.length-1),o.row=t,this._isCellRange&&((t=this._cells.row2+e)<0?t=0:t>=this._flex.rows.length&&(t=this._flex.rows.length-1)),o.row2=t,!0},t.prototype._getStringExpression=function(){return this._tableParams&&this._tableParams.length>0?this._getTableParamsStringExpression():(this._sheetRef?this._sheetRef+"!":"")+wjcXlsx.Workbook.xlsxAddress(this._cells.row,this._cells.col,this._absRow,this._absCol)+(this._isCellRange?":"+wjcXlsx.Workbook.xlsxAddress(this._cells.row2,this._cells.col2,this._absRow2,this._absCol2):"")},t.prototype._getTableParamsStringExpression=function(){for(var e,t=0,o="",n=this._tableParams.length,i=!1;t<n;t++)"#"===(e=this._tableParams[t])[0]?(o+="["+e+"]",t<n-1&&(o+=", ")):i?o+=": ["+e+"]":(o+="["+e+"]",i=!0);return n>1&&(o="["+o+"]"),this._tableName&&(o=this._tableName+o),o},t}(_Expression);exports._CellRangeExpression=_CellRangeExpression;var _FunctionExpression=function(e){function t(t,o,n,i){void 0===i&&(i=!0);var r=e.call(this)||this;return r._funcId=t,r._funcDefinition=o,r._params=n,r._needCacheEvaluatedVal=i,r}return __extends(t,e),t.prototype.evaluate=function(e,t,o){return this._needCacheEvaluatedVal?(null==this._evaluatedValue&&(this._evaluatedValue=this._funcDefinition.func(this._params,o,e,t)),this._evaluatedValue):this._funcDefinition.func(this._params,o,e,t)},t.prototype._updateCellRangeExp=function(e,t,o,n,i){var r,l,s=!1;if(this._params&&this._params.length>0)for(r=0;r<this._params.length;r++)l=this._params[r]._updateCellRangeExp(e,t,o,n,i),s||(s=s||l);return s},t.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1),void 0===i&&(i=!1);var r,l,s=!1;if(this._params&&this._params.length>0)for(r=0;r<this._params.length;r++)l=this._params[r]._moveCellRangeExp(e,t,o,n,i),s||(s=s||l);return s},t.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o,n=!1;if(this._params&&this._params.length>0)for(t=0;t<this._params.length;t++)o=this._params[t]._updateCellRangeExpForReorderingRows(e),n||(n=n||o);return n},t.prototype._getStringExpression=function(){return this._funcId+this._parseParamsExpToString()},t.prototype._parseParamsExpToString=function(){var e,t,o;if(this._params&&this._params.length>0){for(o="",e=0;e<this._params.length;e++)t=this._params[e],0===e&&(o+="("),o+=t._getStringExpression(),e<this._params.length-1?o+=", ":o+=")";return o}return"()"},t}(_Expression);exports._FunctionExpression=_FunctionExpression;var _UndoAction=function(){function e(e){this._owner=e,this._sheetIndex=e.selectedSheetIndex}return Object.defineProperty(e.prototype,"sheetIndex",{get:function(){return this._sheetIndex},enumerable:!0,configurable:!0}),e.prototype.undo=function(){throw"This abstract method must be overridden."},e.prototype.redo=function(){throw"This abstract method must be overridden."},e.prototype.saveNewState=function(){throw"This abstract method must be overridden."},e}();exports._UndoAction=_UndoAction;var _EditAction=function(e){function t(t,o){var n=e.call(this,t)||this;return n._isPaste=!1,n._selections=o?[o]:t.selectedSheet.selectionRanges.length>0?t.selectedSheet.selectionRanges.slice():[t.selection.clone()],n._mergeAction=new _CellMergeAction(t),n._cellStyleAction=new _CellStyleAction(t),n._saveValues(!0),n}return __extends(t,e),Object.defineProperty(t.prototype,"isPaste",{get:function(){return this._isPaste},enumerable:!0,configurable:!0}),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return!!this._saveValues(!1)&&(this._mergeAction.saveNewState(),this._cellStyleAction.saveNewState(),this._checkActionState())},t.prototype.markIsPaste=function(){this._isPaste=!0},t.prototype.updateForPasting=function(e){var t=this._selections[this._selections.length-1],o=this._owner.getCellData(e.row,e.col,!!this._owner.columns[e.col].dataMap);t||(t=this._owner.selection,this._selections=[t]),o=null==o?"":o,this._oldValues["r"+e.row+"_c"+e.col]={row:e.row,col:e.col,value:o},t.row=Math.min(t.topRow,e.topRow),t.row2=Math.max(t.bottomRow,e.bottomRow),t.col=Math.min(t.leftCol,e.leftCol),t.col2=Math.max(t.rightCol,e.rightCol)},t.prototype._storeDeletedTables=function(e){null==this._deletedTables&&(this._deletedTables=[]),this._deletedTables.push(e)},t.prototype._checkActionState=function(){var e=this,t=!1;return Object.keys(e._oldValues).forEach(function(o){var n,i;t||(n=e._oldValues[o],i=e._newValues[o],n&&i&&n.value!==i.value&&(t=!0))}),t||e._mergeAction._checkActionState()||e._cellStyleAction._checkActionState()},t.prototype._saveValues=function(e){var t,o,n,i,r,l,s={};for(t=0;t<this._selections.length;t++)for(i=(o=this._selections[t]).topRow;i<=o.bottomRow;i++)for(r=o.leftCol;r<=o.rightCol;r++){if(!(n=this._owner.columns[r]))return!1;l=null==(l=this._owner.getCellData(i,r,!!n.dataMap))?"":l,s["r"+i+"_c"+r]={row:i,col:r,value:l}}return e?this._oldValues=s:this._newValues=s,!0},t.prototype._handleUndoRedo=function(e){var t=this;t._owner._clearCalcEngine(),t._owner.selectedSheet.selectionRanges.clear(),t._owner.deferUpdate(function(){var o,n,i,r,l=e?t._oldValues:t._newValues;if(t._deletedTables&&t._deletedTables.length>0)for(o=0;o<t._deletedTables.length;o++)n=t._deletedTables[o],e?t._owner.selectedSheet.tables.push(n):t._owner.selectedSheet.tables.remove(n);for(i=0;i<t._selections.length;i++)r=t._selections[i],t._owner.selectedSheet.selectionRanges.push(r);Object.keys(l).forEach(function(e){var o=l[e];t._owner.setCellData(o.row,o.col,o.value)}),e?(t._mergeAction.undo(),t._cellStyleAction.undo()):(t._mergeAction.redo(),t._cellStyleAction.redo()),t._owner.refresh(!1)})},t}(_UndoAction);exports._EditAction=_EditAction;var _ColumnResizeAction=function(e){function t(t,o,n){var i=e.call(this,t)||this;return i._panel=o,i._colIndex=n,i._oldColWidth=o.columns[n].width,i}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newColWidth=this._panel.columns[this._colIndex].width,this._oldColWidth!==this._newColWidth},t.prototype._handleUndoRedo=function(e){var t=this._panel.columns[this._colIndex];t&&(t.width=e?this._oldColWidth:this._newColWidth)},t}(_UndoAction);exports._ColumnResizeAction=_ColumnResizeAction;var _RowResizeAction=function(e){function t(t,o,n){var i=e.call(this,t)||this;return i._panel=o,i._rowIndex=n,i._oldRowHeight=o.rows[n].height,i}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newRowHeight=this._panel.rows[this._rowIndex].height,this._oldRowHeight!==this._newRowHeight},t.prototype._handleUndoRedo=function(e){var t=this._panel.rows[this._rowIndex];t&&(t.height=e?this._oldRowHeight:this._newRowHeight)},t}(_UndoAction);exports._RowResizeAction=_RowResizeAction;var _ColumnsChangedAction=function(e){function t(t,o,n,i){var r=e.call(this,t)||this;return r._columnIndex=o,r._count=n,r._isAdding=i,r._saveValues(!0),r}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._saveValues(!1),!0},t.prototype._saveValues=function(e){var t,o,n,i,r=[],l=[];if(null==this._isAdding)for(t=0;t<this._owner.columns.length;t++)r.push(this._owner.columns[t]);else if(e&&!this._isAdding||!e&&this._isAdding)for(t=this._columnIndex;t<this._columnIndex+this._count&&t<this._owner.columns.length;t++)r.push(this._owner.columns[t]);if(this._owner.selectedSheet.tables&&this._owner.selectedSheet.tables.length>0)for(o=0;o<this._owner.selectedSheet.tables.length;o++)(n=this._owner.selectedSheet.tables[o])&&n.sheet.name===this._owner.selectedSheet.name&&l.push({name:n.name,range:n.getRange(),columns:n.getColumns()});i={columns:r,sortList:this._owner.sortManager._cloneSortList(this._owner.sortManager._committedList),styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,mergedCells:this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,tableRanges:l,selection:this._owner.selection},e?this._oldValue=i:this._newValue=i},t.prototype._handleUndoRedo=function(e){var t,o,n,i,r,l,s,a,h,c,d,u,_=this,g=e?_._oldValue:_._newValue;_._owner.selectedSheet&&(_._owner.deferUpdate(function(){var w;if(_._owner._isUndoing=!0,_._owner._clearCalcEngine(),_._owner.finishEditing(),null==_._isAdding&&(_._owner.columns.clear(),_._columnIndex=0),_._owner.selectedSheet._styledCells=null,_._owner.selectedSheet._mergedRanges.length=0,_._owner.columns.beginUpdate(),g.columns&&g.columns.length>0)for(t=0;t<g.columns.length;t++)(o=g.columns[t])&&o.isVisible&&(_._owner.columns.insert(_._columnIndex+t,o),_._owner.itemsSource&&(w=_._owner.allowAddNew&&_._owner.newRowAtTop?_._owner.rows[1]:_._owner.rows[0])&&(w._ubv||(w._ubv={}),w._ubv[o._hash]=o.header));else for(t=_._columnIndex+_._count-1;t>=_._columnIndex;t--)(o=_._owner.columns[t])&&o.isVisible&&_._owner.columns.removeAt(t);for(_._owner.columns.endUpdate(),_._owner.selectedSheet._styledCells=_._owner._cloneObject(g.styledCells),u=0;u<g.mergedCells.length;u++)_._owner.selectedSheet._mergedRanges[u]=g.mergedCells[u];for(i=0;i<g.tableRanges.length;i++)r=g.tableRanges[i],(l=_._owner._getTable(r.name))&&l._setTableRange(r.range,r.columns);if(_._affectedFormulas&&(a=e?_._affectedFormulas.oldFormulas:_._affectedFormulas.newFormulas),a&&a.length>0)for(n=0;n<a.length;n++)null!=(s=a[n]).point?s.sheet.name===_._owner.selectedSheet.name?_._owner.setCellData(s.point.x,s.point.y,s.formula):s.sheet.grid.setCellData(s.point.x,s.point.y,s.formula):s.row._ubv[s.column._hash]=s.formula;if(_._deletedTables&&_._deletedTables.length>0)for(i=0;i<_._deletedTables.length;i++)l=_._deletedTables[i],e?_._owner.selectedSheet.tables.push(l):_._owner.selectedSheet.tables.remove(l);if(_._affectedDefinedNameVals&&(h=e?_._affectedDefinedNameVals.oldDefinedNameVals:_._affectedDefinedNameVals.newDefinedNameVals),h&&h.length>0)for(n=0;n<h.length;n++)c=h[n],(d=_._owner._getDefinedNameIndexByName(c.name))>-1&&(_._owner.definedNames[d].value=c.value);_._owner.selectedSheet.grid.wj_sheetInfo.styledCells=_._owner.selectedSheet._styledCells,_._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=_._owner.selectedSheet._mergedRanges,_._owner._isUndoing=!1}),_._owner._copyColumnsToSelectedSheet(),_._owner.sortManager.sortDescriptions.sourceCollection=g.sortList.slice(),_._owner.sortManager.commitSort(!1),_._owner.selection=g.selection)},t}(_UndoAction);exports._ColumnsChangedAction=_ColumnsChangedAction;var _RowsChangedAction=function(e){function t(t,o,n,i){var r=e.call(this,t)||this;return r._rowIndex=o,r._count=n,r._isAdding=i,r._saveValues(!0),r}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._saveValues(!1),!0},t.prototype._saveValues=function(e){var t,o,n,i,r,l,s=[],a=[],h=[];if(null==this._isAdding)if(this._owner.itemsSource)for(r=this._owner.itemsSource instanceof wjcCore.CollectionView?this._owner.itemsSource.sourceCollection.slice():this._owner.itemsSource.slice(),o=0;o<this._owner.columns.length;o++)a.push(this._owner.columns[o]);else for(t=0;t<this._owner.rows.length;t++)s.push(this._owner.rows[t]);else if(e&&!this._isAdding||!e&&this._isAdding)for(t=this._rowIndex;t<this._rowIndex+this._count&&t<this._owner.rows.length;t++)s.push(this._owner.rows[t]);if(this._owner.selectedSheet.tables&&this._owner.selectedSheet.tables.length>0)for(n=0;n<this._owner.selectedSheet.tables.length;n++)(i=this._owner.selectedSheet.tables[n])&&i.sheet.name===this._owner.selectedSheet.name&&h.push({name:i.name,range:i.getRange(),setting:{showHeaderRow:i.showHeaderRow,showTotalRow:i.showTotalRow}});l={rows:s,columns:a,itemsSource:r,styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,mergedCells:this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,tableSettings:h,selection:this._owner.selection},e?this._oldValue=l:this._newValue=l},t.prototype._handleUndoRedo=function(e){var t,o,n,i,r,l,s,a,h,c,d,u,_,g,w=this,p=this,f=!!p._owner.itemsSource,m=e?p._oldValue:p._newValue;p._owner.selectedSheet&&(p._owner.deferUpdate(function(){if(p._owner._isUndoing=!0,p._owner._clearCalcEngine(),p._owner.finishEditing(),null==p._isAdding&&(p._owner.itemsSource&&p._owner.columns.clear(),p._owner.rows.clear(),p._rowIndex=0),p._owner.selectedSheet._styledCells=null,p._owner.selectedSheet._mergedRanges.length=0,null==w._isAdding&&f){for(p._owner.collectionView.beginUpdate(),p._owner.autoGenerateColumns=!1,p._owner.itemsSource instanceof wjcCore.CollectionView?(g=[0,p._owner.itemsSource.sourceCollection.length].concat(m.itemsSource),Array.prototype.splice.apply(p._owner.itemsSource.sourceCollection,g)):p._owner.itemsSource=m.itemsSource.slice(),p._owner.columns.beginUpdate(),n=0;n<m.columns.length;n++)p._owner.columns.push(m.columns[n]);p._owner.columns.endUpdate(),p._owner.collectionView.endUpdate()}else{if(f?p._owner.collectionView.beginUpdate():p._owner.rows.beginUpdate(),m.rows&&m.rows.length>0)for(t=0;t<m.rows.length;t++)o=m.rows[t],f&&o.dataItem?(p._owner.itemsSource instanceof wjcCore.CollectionView?p._owner.itemsSource.sourceCollection.splice(p._rowIndex+t-(p._owner.allowAddNew&&p._owner.newRowAtTop?2:1),0,o.dataItem):p._owner.itemsSource.splice(p._rowIndex+t-(p._owner.allowAddNew&&p._owner.newRowAtTop?2:1),0,o.dataItem),p._owner.selectedSheet._orgItemsSource&&p._owner.selectedSheet._orgItemsSource.splice(p._rowIndex+t-(p._owner.allowAddNew&&p._owner.newRowAtTop?2:1),0,o.dataItem)):p._owner.rows.insert(p._rowIndex+t,o);else for(t=p._rowIndex+p._count-1;t>=p._rowIndex;t--)(o=p._owner.rows[t])&&o.isVisible&&(f&&o.dataItem?(p._owner.itemsSource instanceof wjcCore.CollectionView?p._owner.itemsSource.sourceCollection.splice(t-(p._owner.allowAddNew&&p._owner.newRowAtTop?2:1),1):p._owner.itemsSource.splice(t-(p._owner.allowAddNew&&p._owner.newRowAtTop?2:1),1),p._owner.selectedSheet._orgItemsSource&&p._owner.selectedSheet._orgItemsSource.splice(t-(p._owner.allowAddNew&&p._owner.newRowAtTop?2:1),1)):p._owner.rows.removeAt(t));f?p._owner.collectionView.endUpdate():p._owner.rows.endUpdate()}for(p._owner.selectedSheet._styledCells=p._owner._cloneObject(m.styledCells),_=0;_<m.mergedCells.length;_++)p._owner.selectedSheet._mergedRanges[_]=m.mergedCells[_];for(r=0;r<m.tableSettings.length;r++)l=m.tableSettings[r],(s=p._owner._getTable(l.name))&&(s._showHeaderRow=l.setting.showHeaderRow,s._showTotalRow=l.setting.showTotalRow,s._setTableRange(l.range));if(p._affectedFormulas&&(h=e?p._affectedFormulas.oldFormulas:p._affectedFormulas.newFormulas),h&&h.length>0)for(i=0;i<h.length;i++)null!=(a=h[i]).point?a.sheet.name===p._owner.selectedSheet.name?p._owner.setCellData(a.point.x,a.point.y,a.formula):a.sheet.grid.setCellData(a.point.x,a.point.y,a.formula):a.row._ubv[a.column._hash]=a.formula;if(p._deletedTables&&p._deletedTables.length>0)for(r=0;r<p._deletedTables.length;r++)s=p._deletedTables[r],e?p._owner.selectedSheet.tables.push(s):p._owner.selectedSheet.tables.remove(s);if(p._affectedDefinedNameVals&&(c=e?p._affectedDefinedNameVals.oldDefinedNameVals:p._affectedDefinedNameVals.newDefinedNameVals),c&&c.length>0)for(i=0;i<c.length;i++)d=c[i],(u=p._owner._getDefinedNameIndexByName(d.name))>-1&&(p._owner.definedNames[u].value=d.value);p._owner.selectedSheet.grid.wj_sheetInfo.styledCells=p._owner.selectedSheet._styledCells,p._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=p._owner.selectedSheet._mergedRanges,p._owner.selection=m.selection,p._owner._isUndoing=!1}),p._owner._copyRowsToSelectedSheet())},t}(_UndoAction);exports._RowsChangedAction=_RowsChangedAction;var _CellStyleAction=function(e){function t(t,o){var n=e.call(this,t)||this;return n._oldStyledCells=o?t._cloneObject(o):t.selectedSheet?t._cloneObject(t.selectedSheet._styledCells):null,n}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newStyledCells=this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,!0},t.prototype._checkActionState=function(){return null!=this._oldStyledCells&&null==this._newStyledCells||null==this._oldStyledCells&&null!=this._newStyledCells||null!=this._oldStyledCells&&null!=this._newStyledCells&&this._oldStyledCells.length!==this._newStyledCells.length},t.prototype._handleUndoRedo=function(e){var t;this._owner.selectedSheet&&(t=e?this._oldStyledCells:this._newStyledCells,this._owner.selectedSheet._styledCells=this._owner._cloneObject(t),this._owner.selectedSheet.grid.wj_sheetInfo.styledCells=this._owner.selectedSheet._styledCells,this._owner.refresh(!1))},t}(_UndoAction);exports._CellStyleAction=_CellStyleAction;var _CellMergeAction=function(e){function t(t){var o=e.call(this,t)||this;return o._oldMergedCells=t.selectedSheet?t.selectedSheet._cloneMergedCells():null,o}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newMergedCells=this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,!0},t.prototype._handleUndoRedo=function(e){var t,o;if(this._owner.selectedSheet){if(t=e?this._oldMergedCells:this._newMergedCells,this._owner._clearCalcEngine(),t)for(this._owner.selectedSheet._mergedRanges.length=0,o=0;o<t.length;o++)this._owner.selectedSheet._mergedRanges[o]=t[o];this._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=this._owner.selectedSheet._mergedRanges,this._owner.refresh(!0)}},t.prototype._checkActionState=function(){var e,t,o;if(null!=this._oldMergedCells&&null==this._newMergedCells||null==this._oldMergedCells&&null!=this._newMergedCells)return!0;if(null!=this._oldMergedCells&&null!=this._newMergedCells&&this._oldMergedCells.length!==this._newMergedCells.length)return!0;if(null!=this._oldMergedCells&&null!=this._newMergedCells&&this._oldMergedCells.length===this._newMergedCells.length)for(e=0;e<this._oldMergedCells.length;e++)if(o=this._oldMergedCells[e],t=this._oldMergedCells[e],!o.equals(t))return!0;return!1},t}(_UndoAction);exports._CellMergeAction=_CellMergeAction;var _SortColumnAction=function(e){function t(t){var o=e.call(this,t)||this;return o._saveValues(!0),o}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._saveValues(!1),!0},t.prototype._saveValues=function(e){var t,o,n,i,r,l=[];for(o=0;o<this._owner.columns.length;o++)l.push(this._owner.columns[o]);if(this._owner.itemsSource)i=this._owner.collectionView._view.slice();else for(n=[],t=0;t<this._owner.rows.length;t++)n.push(this._owner.rows[t]);r={sortList:this._owner.sortManager._committedList.slice(),rows:n,columns:l,selection:this._owner.selection.clone(),items:i,formulas:this._owner._scanFormulas(),styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null},e?this._oldValue=r:this._newValue=r},t.prototype._handleUndoRedo=function(e){var t,o,n,i,r,l,s=this,a=this,h=e?a._oldValue:a._newValue,c=!!a._owner.itemsSource,d=this._owner.itemsSource instanceof wjcCore.CollectionView;a._owner.selectedSheet&&(a._owner._isUndoing=!0,a._owner.deferUpdate(function(){if(a._owner._clearCalcEngine(),a._owner.sortManager.sortDescriptions.sourceCollection=h.sortList.slice(),a._owner.sortManager._committedList=h.sortList.slice(),a._owner.selectedSheet._styledCells=a._owner._cloneObject(h.styledCells),c)a._owner.autoGenerateColumns=!1,d?a._owner.itemsSource.sourceCollection=h.items:(l=a._owner.selectedSheet._filterDefinition,a._owner.itemsSource=h.items);else for(a._owner.rows.clear(),a._owner.selectedSheet.grid.rows.clear(),t=0;t<h.rows.length;t++)n=h.rows[t],a._owner.selectedSheet.grid.rows.push(n),a._owner.rows.push(n);for(a._owner.columns.clear(),c&&!d&&(r=s._owner.rows[0]instanceof wjcGrid._NewRowTemplate?s._owner.rows[1]:s._owner.rows[0]),o=0;o<h.columns.length;o++)i=h.columns[o],a._owner.columns.push(i),r&&(r._ubv||(r._ubv={}),r._ubv[i._hash]=i.header);c&&(d||(a._owner.filter.filterDefinition=l),a._owner.selection=h.selection),a._owner._resetFormulas(h.formulas),a._owner._isUndoing=!1}))},t}(_UndoAction);exports._SortColumnAction=_SortColumnAction;var _MoveCellsAction=function(e){function t(t,o,n,i){var r=e.call(this,t)||this;return t.selectedSheet?(0===o.topRow&&o.bottomRow===t.rows.length-1?r._isDraggingColumns=!0:r._isDraggingColumns=!1,r._isCopyCells=i,r._dragRange=o,r._dropRange=n,r._saveValues(!0),r):r}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return!!this._owner.selectedSheet&&(!!this._dropRange&&(this._saveValues(!1),!0))},t.prototype._saveValues=function(e){var t,o,n,i,r,l,s,a,h,c,d,u;for(d=[],u={},t=this._dropRange.topRow;t<=this._dropRange.bottomRow;t++)for(o=this._dropRange.leftCol;o<=this._dropRange.rightCol;o++)this._isDraggingColumns&&(u[o]||(u[o]={dataType:this._owner.columns[o].dataType,align:this._owner.columns[o].align,format:this._owner.columns[o].format})),n=t*this._owner.columns.length+o,r=this._owner.selectedSheet._styledCells[n]?this._owner._cloneObject(this._owner.selectedSheet._styledCells[n]):null,i=this._owner.getCellData(t,o,!1),d.push({rowIndex:t,columnIndex:o,cellContent:i,cellStyle:r});if(e?(this._oldDroppingCells=d,this._oldDroppingColumnSetting=u):(this._newDroppingCells=d,this._newDroppingColumnSetting=u),this._isCopyCells){if(this._isDraggingColumns)if(e)for(t=this._dragRange.topRow;t<=this._dragRange.bottomRow;t++)for(o=this._dragRange.leftCol;o<=this._dragRange.rightCol;o++)(a=this._owner.selectedSheet.findTable(t,o))&&(h=a.getRange(),c=a.getColumns(),a.showHeaderRow&&t===h.topRow&&(this._draggingTableColumns||(this._draggingTableColumns=[]),this._draggingTableColumns.push({rowIndex:t,columnIndex:o,cellContent:c[o-h.leftCol].name})));else if(this._draggingTableColumns&&this._draggingTableColumns.length>0&&this._draggingTableColumns&&this._draggingTableColumns.length>0)for(l=0;l<this._draggingTableColumns.length;l++)s=this._draggingTableColumns[l],(a=this._owner.selectedSheet.findTable(s.rowIndex,s.columnIndex))&&(h=a.getRange(),c=a.getColumns(),a.showHeaderRow&&s.rowIndex===h.topRow&&(s.updatedCellContent=c[s.columnIndex-h.leftCol].name))}else if(e)for(this._draggingCells=[],this._draggingColumnSetting={},t=this._dragRange.topRow;t<=this._dragRange.bottomRow;t++)for(o=this._dragRange.leftCol;o<=this._dragRange.rightCol;o++)this._isDraggingColumns&&(this._draggingColumnSetting[o]||(this._draggingColumnSetting[o]={dataType:this._owner.columns[o].dataType,align:this._owner.columns[o].align,format:this._owner.columns[o].format})),n=t*this._owner.columns.length+o,r=this._owner.selectedSheet._styledCells[n]?this._owner._cloneObject(this._owner.selectedSheet._styledCells[n]):null,i=this._owner.getCellData(t,o,!1),this._draggingCells.push({rowIndex:t,columnIndex:o,cellContent:i,cellStyle:r});else if(this._isDraggingColumns&&this._draggingCells&&this._draggingCells.length>0)for(l=0;l<this._draggingCells.length;l++)s=this._draggingCells[l],(a=this._owner.selectedSheet.findTable(s.rowIndex,s.columnIndex))&&(h=a.getRange(),c=a.getColumns(),a.showHeaderRow&&s.rowIndex===h.topRow&&(s.updatedCellContent=c[s.columnIndex-h.leftCol].name))},t.prototype._handleUndoRedo=function(e){var t,o,n,i,r,l,s,a,h,c,d=this,u=e?d._oldDroppingCells:d._newDroppingCells,_=e?d._oldDroppingColumnSetting:d._newDroppingColumnSetting;d._owner.selectedSheet&&(d._owner._clearCalcEngine(),d._owner.deferUpdate(function(){var g,w,p;if(d._affectedFormulas&&(l=e?d._affectedFormulas.oldFormulas:d._affectedFormulas.newFormulas),l&&l.length>0)for(t=0;t<l.length;t++)(s=l[t]).sheet.name===d._owner.selectedSheet.name?d._owner.setCellData(s.point.x,s.point.y,s.formula):s.sheet.grid.setCellData(s.point.x,s.point.y,s.formula);if(d._affectedDefinedNameVals&&(a=e?d._affectedDefinedNameVals.oldDefinedNameVals:d._affectedDefinedNameVals.newDefinedNameVals),a&&a.length>0)for(t=0;t<a.length;t++)h=a[t],(c=d._owner._getDefinedNameIndexByName(h.name))>-1&&(d._owner.definedNames[c].value=h.value);for(t=0;t<u.length;t++)o=u[t],d._owner.setCellData(o.rowIndex,o.columnIndex,o.cellContent),(g=d._owner.selectedSheet.findTable(o.rowIndex,o.columnIndex))&&(w=g.getRange(),p=g.getColumns(),g.showHeaderRow&&o.rowIndex===w.topRow&&(p[o.columnIndex-w.leftCol].name=o.cellContent)),n=o.rowIndex*d._owner.columns.length+o.columnIndex,o.cellStyle?d._owner.selectedSheet._styledCells[n]=o.cellStyle:delete d._owner.selectedSheet._styledCells[n];if(d._isDraggingColumns&&_&&Object.keys(_).forEach(function(e){d._owner.columns[+e].dataType=_[+e].dataType?_[+e].dataType:wjcCore.DataType.Object,d._owner.columns[+e].align=_[+e].align,d._owner.columns[+e].format=_[+e].format}),d._isCopyCells){if(d._draggingTableColumns&&d._draggingTableColumns.length>0)for(t=0;t<d._draggingTableColumns.length;t++)o=d._draggingTableColumns[t],(g=d._owner.selectedSheet.findTable(o.rowIndex,o.columnIndex))&&(w=g.getRange(),p=g.getColumns(),g.showHeaderRow&&o.rowIndex===w.topRow&&(d._owner.setCellData(o.rowIndex,o.columnIndex,e?o.cellContent:o.updatedCellContent),p[o.columnIndex-w.leftCol].name=e?o.cellContent:o.updatedCellContent))}else{for(t=0;t<d._draggingCells.length;t++)o=d._draggingCells[t],(g=d._owner.selectedSheet.findTable(o.rowIndex,o.columnIndex))?(w=g.getRange(),p=g.getColumns(),g.showHeaderRow&&o.rowIndex===w.topRow?(d._owner.setCellData(o.rowIndex,o.columnIndex,e?o.cellContent:o.updatedCellContent),p[o.columnIndex-w.leftCol].name=e?o.cellContent:o.updatedCellContent):d._owner.setCellData(o.rowIndex,o.columnIndex,e?o.cellContent:null)):d._owner.setCellData(o.rowIndex,o.columnIndex,e?o.cellContent:null),n=o.rowIndex*d._owner.columns.length+o.columnIndex,e?o.cellStyle&&(d._owner.selectedSheet._styledCells[n]=o.cellStyle):d._owner.selectedSheet._styledCells[n]&&delete d._owner.selectedSheet._styledCells[n];if(d._isDraggingColumns&&d._draggingColumnSetting&&Object.keys(d._draggingColumnSetting).forEach(function(t){d._owner.columns[+t].dataType=e&&d._draggingColumnSetting[+t].dataType?d._draggingColumnSetting[+t].dataType:wjcCore.DataType.Object,d._owner.columns[+t].align=e?d._draggingColumnSetting[+t].align:null,d._owner.columns[+t].format=e?d._draggingColumnSetting[+t].format:null}),e){if(d._isDraggingColumns)if(d._dragRange.leftCol<d._dropRange.leftCol)for(r=d._dragRange.leftCol,i=d._dropRange.leftCol;i<=d._dropRange.rightCol;i++)d._owner._updateColumnFiler(i,r),r++;else for(r=d._dragRange.rightCol,i=d._dropRange.rightCol;i>=d._dropRange.leftCol;i--)d._owner._updateColumnFiler(i,r),r--}else if(d._isDraggingColumns)if(d._dragRange.leftCol>d._dropRange.leftCol)for(r=d._dropRange.leftCol,i=d._dragRange.leftCol;i<=d._dragRange.rightCol;i++)d._owner._updateColumnFiler(i,r),r++;else for(r=d._dropRange.rightCol,i=d._dragRange.rightCol;i>=d._dragRange.leftCol;i--)d._owner._updateColumnFiler(i,r),r--}}))},t}(_UndoAction);exports._MoveCellsAction=_MoveCellsAction;var _CutAction=function(e){function t(t){var o=e.call(this,t)||this;return o._oldValues=[],o._mergeAction=new _CellMergeAction(t),o._celltyleAction=new _CellStyleAction(t),o._cutSheet=t._copiedSheet,o._selection=t.selection,o._cutSelection=t.selectionMode===wjcGrid.SelectionMode.ListBox?t._getSelectionForListBoxMode(o._cutSheet.grid):t._copiedRanges[0],o._saveCutValues(!0),o}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){var e,t,o;this._cutSheet===this._owner.selectedSheet?this._owner:this._cutSheet.grid;for(this._saveCutValues(!1),this._newValues=[],e=this._selection.topRow;e<=this._selection.bottomRow;e++)for(t=this._selection.leftCol;t<=this._selection.rightCol;t++){if(!this._owner.columns[t])return!1;o=null==(o=this._owner.getCellData(e,t,!!this._owner.columns[t].dataMap))?"":o,this._newValues.push({row:e,col:t,value:o})}return this._mergeAction.saveNewState(),this._celltyleAction.saveNewState(),!0},t.prototype.updateForPasting=function(e){var t=this._owner.getCellData(e.row,e.col,!!this._owner.columns[e.col].dataMap);t=null==t?"":t,this._oldValues.push({row:e.row,col:e.col,value:t}),this._selection.row=Math.min(this._selection.topRow,e.topRow),this._selection.row2=Math.max(this._selection.bottomRow,e.bottomRow),this._selection.col=Math.min(this._selection.leftCol,e.leftCol),this._selection.col2=Math.max(this._selection.rightCol,e.rightCol)},t.prototype._saveCutValues=function(e){var t,o,n,i=this._cutSheet===this._owner.selectedSheet?this._owner:this._cutSheet.grid,r=[];for(t=this._cutSelection.topRow;t<=this._cutSelection.bottomRow;t++)if(null!=i.rows[t])for(o=this._cutSelection.leftCol;o<=this._cutSelection.rightCol;o++)n=null==(n=i.getCellData(t,o,!!i.columns[o].dataMap))?"":n,r.push({row:t,col:o,value:n});e?this._oldCutValues=r:this._newCutValues=r},t.prototype._handleUndoRedo=function(e){var t=this,o=e?t._oldCutValues:t._newCutValues,n=e?t._oldValues:t._newValues;t._owner._clearCalcEngine(),t._owner.selectedSheet.selectionRanges.clear(),t._owner.deferUpdate(function(){var i,r,l=t._cutSheet===t._owner.selectedSheet?t._owner:t._cutSheet.grid;for(t._owner.selectedSheet.selectionRanges.push(t._selection),i=0;i<o.length;i++)r=o[i],l.setCellData(r.row,r.col,r.value);for(i=0;i<n.length;i++)r=n[i],t._owner.setCellData(r.row,r.col,r.value);e?(t._mergeAction.undo(),t._celltyleAction.undo()):(t._mergeAction.redo(),t._celltyleAction.redo()),t._owner.refresh(!1)})},t}(_UndoAction);exports._CutAction=_CutAction;var _TableSettingAction=function(e){function t(t,o){var n=e.call(this,t)||this;return n._table=o,n._saveValues(!0),n}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._saveValues(!1),!0},t.prototype._saveValues=function(e){var t={name:this._table.name,style:this._table.style,showHeaderRow:this._table.showHeaderRow,showTotalRow:this._table.showTotalRow,showbandedRows:this._table.showBandedRows,showBandedColumns:this._table.showBandedColumns,alterFirstColumn:this._table.alterFirstColumn,alterLastColumn:this._table.alterLastColumn};e?this._oldTableSetting=t:this._newTableSetting=t},t.prototype._handleUndoRedo=function(e){var t=e?this._oldTableSetting:this._newTableSetting;this._owner.beginUpdate(),this._owner._isUndoing=!0,this._table.name=t.name,this._table.style=t.style,this._table.showHeaderRow=t.showHeaderRow,this._table.showTotalRow=t.showTotalRow,this._table.showBandedRows=t.showbandedRows,this._table.showBandedColumns=t.showBandedColumns,this._table.alterFirstColumn=t.alterFirstColumn,this._table.alterLastColumn=t.alterLastColumn,this._owner._isUndoing=!1,this._owner.endUpdate()},t}(_UndoAction);exports._TableSettingAction=_TableSettingAction;var _TableAction=function(e){function t(t,o){var n=e.call(this,t)||this;return n._addedTable=o,n}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype._handleUndoRedo=function(e){var t,o,n;if(this._addedTable.showHeaderRow)for(o=this._addedTable.getRange(),n=this._addedTable.getColumns(),t=0;t<o.columnSpan;t++)this._owner.setCellData(o.topRow,o.leftCol+t,e?this._addedTable._orgHeaderCellsContent[t]:n[t].name);e?this._owner.selectedSheet.tables.remove(this._addedTable):this._owner.selectedSheet.tables.push(this._addedTable),this._owner.refresh()},t}(_UndoAction);exports._TableAction=_TableAction;var _FilteringAction=function(e){function t(t){var o=e.call(this,t)||this;return o._oldFilterDefinition=t.filter.filterDefinition,o._oldRowsVisible=o._getRowsVisible(),o}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newFilterDefinition=this._owner.filter.filterDefinition,this._newRowsVisible=this._getRowsVisible(),!0},t.prototype._handleUndoRedo=function(e){var t=e?this._oldFilterDefinition:this._newFilterDefinition;this._owner.filter.filterDefinition!==t?(this._owner._isUndoing=!0,this._owner.selectedSheet._filterDefinition=t,this._owner.selectedSheet._applyFilterSetting(),this._owner._isUndoing=!1,this._owner.filter.apply()):this._setRowVisible(e)},t.prototype._getRowsVisible=function(){for(var e,t=[],o=0;o<this._owner.rows.length;o++)(e=this._owner.rows[o])&&t.push(e.visible);return t},t.prototype._setRowVisible=function(e){for(var t,o=e?this._oldRowsVisible:this._newRowsVisible,n=0;n<o.length;n++)(t=this._owner.rows[n])&&(t.visible=o[n])},t}(_UndoAction);exports._FilteringAction=_FilteringAction;var _ContextMenu=function(e){function t(t,o){var n=e.call(this,t)||this;return n._idx=-1,n._isDisableDelRow=!1,n._owner=o,n.applyTemplate("",n.getTemplate(),{_insRows:"insert-rows",_delRows:"delete-rows",_insCols:"insert-columns",_delCols:"delete-columns",_convertTable:"convert-table"}),n._init(),n}return __extends(t,e),Object.defineProperty(t.prototype,"visible",{get:function(){return"none"!==this.hostElement.style.display},enumerable:!0,configurable:!0}),t.prototype.show=function(e,t){if(this._owner.selectedSheet){var o=(t?t.x:e.clientX)+(e?window.pageXOffset:0),n=(t?t.y:e.clientY)+(e?window.pageYOffset:0);this.hostElement.style.position="absolute",this.hostElement.style.display="inline",this._owner._isDisableDeleteRow(this._owner.selection.topRow,this._owner.selection.bottomRow)&&(this._isDisableDelRow=!0,wjcCore.addClass(this._delRows,"wj-state-disabled")),this._showTableOperation(),this._owner.selection.isValid||wjcCore.addClass(this._convertTable,"wj-state-disabled"),n+this.hostElement.clientHeight>window.innerHeight&&(n-=this.hostElement.clientHeight),o+this.hostElement.clientWidth>window.innerWidth&&(o-=this.hostElement.clientWidth),this.hostElement.style.top=n+"px",this.hostElement.style.left=o+"px"}},t.prototype.hide=function(){this._idx=-1;var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this.hostElement.style.display="none",this._isDisableDelRow=!1,wjcCore.removeClass(this._delRows,"wj-state-disabled"),wjcCore.removeClass(this._convertTable,"wj-state-disabled")},t.prototype.moveToNext=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");for(this._removeSelectedState(e),this._idx++,1===this._idx&&this._isDisableDelRow&&this._idx++;e[this._idx]&&"none"===e[this._idx].style.display;)this._idx++;this._idx>=e.length&&(this._idx=0),wjcCore.addClass(e[this._idx],"wj-context-menu-item-selected")},t.prototype.moveToPrev=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");for(this._removeSelectedState(e),this._idx--,1===this._idx&&this._isDisableDelRow&&this._idx--;this._idx>0&&"none"===e[this._idx].style.display;)this._idx--;this._idx<0&&(this._idx=e.length-1),wjcCore.addClass(e[this._idx],"wj-context-menu-item-selected")},t.prototype.moveToFirst=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this._idx=0,wjcCore.addClass(e[this._idx],"wj-context-menu-item-selected")},t.prototype.moveToLast=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this._idx=e.length-1,e[this._idx]&&"none"===e[this._idx].style.display&&this._idx--,wjcCore.addClass(e[this._idx],"wj-context-menu-item-selected")},t.prototype.handleContextMenu=function(){if(-1===this._idx)this.moveToNext();else{switch(this.hostElement.querySelectorAll(".wj-context-menu-item")[this._idx]){case this._insCols:this._owner.insertColumns();break;case this._insRows:this._owner.insertRows();break;case this._delCols:this._owner.deleteColumns();break;case this._delRows:this._isDisableDelRow||this._owner.deleteRows();break;case this._convertTable:this._addTable()}this.hide(),this._owner.hostElement.focus()}},t.prototype._init=function(){var e=this,t=this.hostElement.querySelectorAll(".wj-context-menu-item");e.hostElement.style.zIndex="9999",document.querySelector("body").appendChild(e.hostElement),e.addEventListener(document.body,"mousemove",function(){e._removeSelectedState(t)}),e.addEventListener(e.hostElement,"contextmenu",function(e){e.preventDefault()}),e.addEventListener(e._insRows,"click",function(t){e._owner.insertRows(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._delRows,"click",function(t){e._isDisableDelRow||e._owner.deleteRows(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._insCols,"click",function(t){e._owner.insertColumns(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._delCols,"click",function(t){e._owner.deleteColumns(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._convertTable,"click",function(t){e._addTable(),e.hide(),e._owner.hostElement.focus()})},t.prototype._removeSelectedState=function(e){for(var t=0;t<e.length;t++)wjcCore.removeClass(e[t],"wj-context-menu-item-selected")},t.prototype._showTableOperation=function(){var e,t,o=this._owner.selection;for(e=o.topRow;e<=o.bottomRow;e++)for(t=o.leftCol;t<=o.rightCol;t++)if(null!=this._owner.selectedSheet.findTable(e,t))return this._convertTable.style.display="none",void(this._convertTable.parentElement.style.display="none");o.isSingleCell||this._owner._containsMergedCells(o)?(this._convertTable.style.display="none",this._convertTable.parentElement.style.display="none"):(this._convertTable.style.display="inline",this._convertTable.parentElement.style.display="inline")},t.prototype._addTable=function(){var e,t;0!==this._owner.undoStack.stackSize&&(e=this._owner.selectedSheet._addTable(this._owner.selection),t=new _TableAction(this._owner,e),this._owner.undoStack._addAction(t))},t.controlTemplate='<div class="wj-context-menu wj-control wj-flexsheet-context-menu" width="150px"><div class="wj-context-menu-item" wj-part="insert-rows">Insert Row</div><div class="wj-context-menu-item" wj-part="delete-rows">Delete Rows</div><div class="wj-context-menu-item" wj-part="insert-columns">Insert Column</div><div class="wj-context-menu-item" wj-part="delete-columns">Delete Columns</div><div><div class="wj-state-disabled" style="width:100%;height:1px;background-color:lightgray;"></div><div class="wj-context-menu-item" wj-part="convert-table">Convert To Table</div></div></div>',t}(wjcCore.Control);exports._ContextMenu=_ContextMenu;var _TabHolder=function(e){function t(t,o){var n=e.call(this,t)||this;return n._splitterMousedownHdl=n._splitterMousedownHandler.bind(n),n._owner=o,n.applyTemplate("",n.getTemplate(),{_divSheet:"left",_divSplitter:"splitter",_divRight:"right"}),n._init(),n}return __extends(t,e),Object.defineProperty(t.prototype,"sheetControl",{get:function(){return this._sheetControl},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"visible",{get:function(){return"none"!==this.hostElement.style.display},set:function(e){this.hostElement.style.display=e?"block":"none",this._divSheet.style.display=e?"block":"none"},enumerable:!0,configurable:!0}),t.prototype.getSheetBlanketSize=function(){return 20},t.prototype.adjustSize=function(){var e=this._owner.scrollSize.width-this._owner.clientSize.width,t=(this._owner.scrollSize.height,this._owner.clientSize.height,this._divSplitter.parentElement);e<=0?(t.style.minWidth="100px",this._divSplitter.style.display="none",this._divRight.style.display="none",this._divSheet.style.width="100%",this._divSplitter.removeEventListener("mousedown",this._splitterMousedownHdl,!0)):(t.style.minWidth="300px",this._divSplitter.style.display="none",this._divRight.style.display="none",this._divSheet.style.width="100%",this._divSplitter.removeEventListener("mousedown",this._splitterMousedownHdl,!0),this._divSplitter.addEventListener("mousedown",this._splitterMousedownHdl,!0)),this._sheetControl._adjustSize()},t.prototype._init=function(){var e=this;e._funSplitterMousedown=function(t){e._splitterMouseupHandler(t)},e._divSplitter.parentElement.style.height=e.getSheetBlanketSize()+"px",e._sheetControl=new _SheetTabs(e._divSheet,this._owner)},t.prototype._splitterMousedownHandler=function(e){this._startPos=e.pageX,document.addEventListener("mousemove",this._splitterMousemoveHandler.bind(this),!0),document.addEventListener("mouseup",this._funSplitterMousedown,!0),e.preventDefault()},t.prototype._splitterMousemoveHandler=function(e){null!==this._startPos&&void 0!==this._startPos&&this._adjustDis(e.pageX-this._startPos)},t.prototype._splitterMouseupHandler=function(e){document.removeEventListener("mousemove",this._splitterMousemoveHandler,!0),document.removeEventListener("mouseup",this._funSplitterMousedown,!0),this._adjustDis(e.pageX-this._startPos),this._startPos=null},t.prototype._adjustDis=function(e){var t=this._divRight.offsetWidth-e,o=this._divSheet.offsetWidth+e;t<=100?(t=100,e=this._divRight.offsetWidth-t,o=this._divSheet.offsetWidth+e):o<=100&&(e=(o=100)-this._divSheet.offsetWidth,t=this._divRight.offsetWidth-e),0!=e&&(this._divRight.style.width=t+"px",this._divSheet.style.width=o+"px",this._startPos=this._startPos+e)},t.controlTemplate='<div><div wj-part="left" style ="float:left;height:100%;overflow:hidden"></div><div wj-part="splitter" style="float:left;height:100%;width:6px;background-color:#e9eaee;padding:2px;cursor:e-resize"><div style="background-color:#8a9eb2;height:100%"></div></div><div wj-part="right" style="float:left;height:100%;background-color:#e9eaee"></div></div>',t}(wjcCore.Control);exports._TabHolder=_TabHolder;var _FlexSheetCellFactory=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.updateCell=function(t,o,n,i,r){var l,s,a,h,c,d,u,_,g,w,p,f,m,C,b,S=t.grid;switch(t.cellType===wjcGrid.CellType.Cell&&this._resetCellStyle(t.columns[n],i),e.prototype.updateCell.call(this,t,o,n,i,r),r&&!r.isSingleCell&&(o=r.row,n=r.col,r.row2,r.col2),b=S.selectedSheet,w=S._getBindingColumn(t,o,t.columns[n]),t.cellType){case wjcGrid.CellType.RowHeader:i.textContent=o+1+"";break;case wjcGrid.CellType.ColumnHeader:l=b&&b._showDefaultHeader||wjcCore.isNullOrWhiteSpace(w.header)||!wjcCore.isNullOrWhiteSpace(w.binding)&&(w.header===w.binding||w.header===wjcCore.toHeaderCase(w.binding))?FlexSheet.convertNumberToAlpha(n):w.header,i.textContent?i.innerHTML=i.innerHTML.replace(wjcCore.escapeHtml(i.textContent.trim()),l).replace(i.textContent,l):i.innerHTML+=l,i.style.textAlign="center";break;case wjcGrid.CellType.Cell:if(s=o*S.columns.length+n,u=b&&b._styledCells?b._styledCells[s]:null,r&&!r.isSingleCell&&(o=(f=this._getFirstVisibleCell(S,r)).row,n=f.col),t.rows[o]instanceof HeaderRow)t.columns[n].dataType===wjcCore.DataType.Boolean?1===i.childElementCount&&i.firstElementChild instanceof HTMLInputElement&&"checkbox"===i.firstElementChild.type&&(i.innerHTML=wjcCore.escapeHtml(S.getCellValue(o,n))):i.innerHTML||(i.innerHTML=wjcCore.escapeHtml(S.getCellValue(o,n))),wjcCore.addClass(i,"wj-header-row");else if(h=S.getCellValue(o,n,!1),c=S.getCellData(o,n,!1),d=null!=c&&"string"==typeof c&&"="===c[0],m=t.rows[o]instanceof wjcGrid.GroupRow,p=(u?u.format:null)||(m?null:w.format),S.editRange&&S.editRange.contains(o,n)?!wjcCore.isNumber(h)||w.dataMap||d||(p&&(h=this._getFormattedValue(h,p)),(g=i.querySelector("input"))&&(g.value=h)):t.columns[n].dataType===wjcCore.DataType.Boolean?(_=i.querySelector('[type="checkbox"]'))&&(_.checked=S.getCellValue(o,n),_.disabled=_.disabled||!S.canEditCell(o,n)):w.dataMap&&!m?(h=S.getCellValue(o,n,!0),(a=i.firstChild)&&3===a.nodeType&&a.nodeValue!==h&&(a.nodeValue=h)):0===i.childElementCount&&i.textContent===S.getCellData(o,n,!0)&&(""!==(h=S.getCellValue(o,n,!0))&&wjcCore.isNumber(+h)&&!isNaN(+h)&&/[hsmy\:]/i.test(p)&&(C=_Expression._fromOADate(+h),isNaN(C.getTime())||(h=wjcCore.Globalize.formatDate(C,p))),!p&&m||(h=wjcCore.isString(h)?h.replace(/^(\')(\s*[\w|=])/,"$2"):h,wjcCore.isString(h)?h&&this._isURL(h)?i.innerHTML='<a href="'+h+'" target="_blank">'+wjcCore.escapeHtml(h)+"</a>":i.innerHTML=wjcCore.escapeHtml(h):i.innerHTML=h)),u){var y,R=i.style;for(var v in u)"className"===v?u.className&&wjcCore.addClass(i,u.className):"format"!==v&&(y=u[v])&&(!wjcCore.hasClass(i,"wj-state-selected")&&!wjcCore.hasClass(i,"wj-state-multi-selected")||"color"!==v&&"backgroundColor"!==v?R[v]="whiteSpace"===v&&"normal"===y?"":y:R[v]="")}(i.style.backgroundColor||i.style.color)&&(u||(u={},b&&b._styledCells[s]),i.style.backgroundColor&&(u.backgroundColor=i.style.backgroundColor),i.style.color&&(u.color=i.style.color))}t.cellType===wjcGrid.CellType.Cell&&(o!==S._lastVisibleFrozenRow||wjcCore.hasClass(i,"wj-frozen-row")||wjcCore.addClass(i,"wj-frozen-row"),n!==S._lastVisibleFrozenColumn||wjcCore.hasClass(i,"wj-frozen-col")||wjcCore.addClass(i,"wj-frozen-col"))},t.prototype._resetCellStyle=function(e,t){["fontFamily","fontSize","fontStyle","fontWeight","textDecoration","textAlign","verticalAlign","backgroundColor","color","whiteSpace","borderLeftStyle","borderLeftColor","borderLeftWidth","borderRightStyle","borderRightColor","borderRightWidth","borderTopStyle","borderTopColor","borderTopWidth","borderBottomStyle","borderBottomColor","borderBottomWidth"].forEach(function(o){"textAlign"===o?t.style.textAlign=e.getAlignment():t.style[o]=""})},t.prototype._getFormattedValue=function(e,t){return e!==Math.round(e)&&(t=t.replace(/([a-z])(\d*)(.*)/gi,"$0112$3")),wjcCore.Globalize.formatNumber(e,t,!0)},t.prototype._getFirstVisibleCell=function(e,t){var o,n;for(o=t.topRow;o<=t.bottomRow&&!e.rows[o].isVisible;o++);for(n=t.leftCol;n<=t.rightCol&&!e.columns[n].isVisible;n++);return new wjcGrid.CellRange(o,n)},t.prototype._isURL=function(e){return new RegExp("^(https|http|ftp|rtsp|mms)://(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].[a-z]{2,6})(:[0-9]{1,4})?(/($|[a-zA-Z0-9.,?'\\+&amp;%$#=~_-]+))*").test(e)},t}(wjcGrid.CellFactory);exports._FlexSheetCellFactory=_FlexSheetCellFactory;var FlexSheetFunctions=[{name:"abs",description:"Returns the absolute value of a number."},{name:"acos",description:"Returns the arccosine of a number."},{name:"and",description:"Returns TRUE if all of its arguments are TRUE."},{name:"asin",description:"Returns the arcsine of a number."},{name:"atan",description:"Returns the arctangent of a number."},{name:"atan2",description:"Returns the arctangent from x- and y-coordinates."},{name:"average",description:"Returns the average of its arguments."},{name:"ceiling",description:"Rounds a number to the nearest integer or to the nearest multiple of significance."},{name:"char",description:"Returns the character specified by the code number."},{name:"choose",description:"Chooses a value from a list of values."},{name:"code",description:"Returns a numeric code for the first character in a text string."},{name:"column",description:"Returns the column number of a reference."},{name:"columns",description:"Returns the number of columns in a reference."},{name:"concatenate",description:"Joins several text items into one text item."},{name:"cos",description:"Returns the cosine of a number."},{name:"count",description:"Counts how many numbers are in the list of arguments."},{name:"counta",description:"Counts how many values are in the list of arguments."},{name:"countblank",description:"Counts the number of blank cells within a range."},{name:"countif",description:"Counts the number of cells within a range that meet the given criteria."},{name:"countifs",description:"Counts the number of cells within a range that meet multiple criteria."},{name:"date",description:"Returns the serial number of a particular date."},{name:"datedif",description:"Calculates the number of days, months, or years between two dates."},{name:"day",description:"Converts a serial number to a day of the month."},{name:"dcount",description:"Counts the cells that contain numbers in a database."},{name:"exp",description:"Returns e raised to the power of a given number."},{name:"false",description:"Returns the logical value FALSE."},{name:"find",description:"Finds one text value within another (case-sensitive)."},{name:"floor",description:"Rounds a number down, toward zero."},{name:"hlookup",description:"Looks in the top row of an array and returns the value of the indicated cell."},{name:"hour",description:"Converts a serial number to an hour."},{name:"if",description:"Specifies a logical test to perform."},{name:"index",description:"Uses an index to choose a value from a reference."},{name:"left",description:"Returns the leftmost characters from a text value."},{name:"len",description:"Returns the number of characters in a text string."},{name:"ln",description:"Returns the natural logarithm of a number."},{name:"lower",description:"Converts text to lowercase."},{name:"max",description:"Returns the maximum value in a list of arguments."},{name:"mid",description:"Returns a specific number of characters from a text string starting at the position you specify."},{name:"min",description:"Returns the minimum value in a list of arguments."},{name:"mod",description:"Returns the remainder from division."},{name:"month",description:"Converts a serial number to a month."},{name:"not",description:"Reverses the logic of its argument."},{name:"now",description:"Returns the serial number of the current date and time."},{name:"or",description:"Returns TRUE if any argument is TRUE."},{name:"pi",description:"Returns the value of pi."},{name:"power",description:"Returns the result of a number raised to a power."},{name:"product",description:"Multiplies its arguments."},{name:"proper",description:"Capitalizes the first letter in each word of a text value."},{name:"rand",description:"Returns a random number between 0 and 1."},{name:"rank",description:"Returns the rank of a number in a list of numbers."},{name:"rate",description:"Returns the interest rate per period of an annuity."},{name:"replace",description:"Replaces characters within text."},{name:"rept",description:"Repeats text a given number of times."},{name:"right",description:"Returns the rightmost characters from a text value."},{name:"round",description:"Rounds a number to a specified number of digits."},{name:"rounddown",description:"Rounds a number down, toward zero."},{name:"roundup",description:"Rounds a number up, away from zero."},{name:"row",description:"Returns the row number of a reference."},{name:"rows",description:"Returns the number of rows in a reference."},{name:"search",description:"Finds one text value within another (not case-sensitive)."},{name:"sin",description:"Returns the sine of the given angle."},{name:"sqrt",description:"Returns a positive square root."},{name:"stdev",description:"Estimates standard deviation based on a sample."},{name:"stdevp",description:"Calculates standard deviation based on the entire population."},{name:"substitute",description:"Substitutes new text for old text in a text string."},{name:"subtotal",description:"Returns a subtotal in a list or database."},{name:"sum",description:"Adds its arguments."},{name:"sumif",description:"Adds the cells specified by a given criteria."},{name:"sumifs",description:"Adds the cells in a range that meet multiple criteria."},{name:"sumproduct",description:"Multiplies corresponding components in the given arrays, and returns the sum of those products."},{name:"tan",description:"Returns the tangent of a number."},{name:"text",description:"Formats a number and converts it to text."},{name:"time",description:"Returns the serial number of a particular time."},{name:"today",description:"Returns the serial number of today's date."},{name:"trim",description:"Removes spaces from text."},{name:"true",description:"Returns the logical value TRUE."},{name:"trunc",description:"Truncates a number to an integer."},{name:"upper",description:"Converts text to uppercase."},{name:"value",description:"Converts a text argument to a number."},{name:"var",description:"Estimates variance based on a sample."},{name:"varp",description:"Calculates variance based on the entire population."},{name:"year",description:"Converts a serial number to a year."}],FlexSheet=function(e){function t(t,o){var n=e.call(this,t,o)||this;return n._selectedSheetIndex=-1,n._columnHeaderClicked=!1,n._addingSheet=!1,n._mouseMoveHdl=n._mouseMove.bind(n),n._clickHdl=n._click.bind(n),n._touchStartHdl=n._touchStart.bind(n),n._touchEndHdl=n._touchEnd.bind(n),n._isContextMenuKeyDown=!1,n._isClicking=!1,n._definedNames=new wjcCore.ObservableArray,n._builtInTableStylesCache=null,n._needCopyToSheet=!0,n._isSorting=!1,n.selectedSheetChanged=new wjcCore.Event,n.draggingRowColumn=new wjcCore.Event,n.droppingRowColumn=new wjcCore.Event,n.loaded=new wjcCore.Event,n.unknownFunction=new wjcCore.Event,n.sheetCleared=new wjcCore.Event,n.prepareChangingRow=new wjcCore.Event,n.prepareChangingColumn=new wjcCore.Event,n.rowChanged=new wjcCore.Event,n.columnChanged=new wjcCore.Event,n._needCopyToSheet=!1,n._colorThemes=["FFFFFF","000000","EEECE1","1F497D","4F818D","C0504D","9BBB59","8064A2","4BACC6","F79646"],n._eCt.style.backgroundColor="white",wjcCore.addClass(n.hostElement,"wj-flexsheet"),wjcCore.setCss(n.hostElement,{fontFamily:"Arial"}),n._cf=new _FlexSheetCellFactory,n._bndSortConverter=n._sheetSortConverter.bind(n),n.quickAutoSize=!1,n._init(),n.showSort=!1,n.allowSorting=!1,n.showGroups=!1,n.showMarquee=!0,n.showSelectedHeaders=wjcGrid.HeadersVisibility.All,n.allowResizing=wjcGrid.AllowResizing.Both,n.allowDragging=wjcGrid.AllowDragging.None,n._needCopyToSheet=!0,n}return __extends(t,e),t.prototype._getProductInfo=function(){return"R20I,FlexSheet"},Object.defineProperty(t.prototype,"sheets",{get:function(){return this._sheets||(this._sheets=new SheetCollection,this._sheets.selectedSheetChanged.addHandler(this._selectedSheetChange,this),this._sheets.collectionChanged.addHandler(this._sourceChange,this),this._sheets.sheetVisibleChanged.addHandler(this._sheetVisibleChange,this),this._sheets.sheetCleared.addHandler(this.onSheetCleared,this)),this._sheets},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selectedSheetIndex",{get:function(){return this._selectedSheetIndex},set:function(e){e!==this._selectedSheetIndex&&(this._showSheet(e),this._sheets.selectedIndex=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selectedSheet",{get:function(){return this._sheets[this._selectedSheetIndex]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isFunctionListOpen",{get:function(){return this._functionListHost&&"none"!==this._functionListHost.style.display},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isTabHolderVisible",{get:function(){return this._tabHolder.visible},set:function(e){e!==this._tabHolder.visible&&(e?(this._divContainer.style.height=this._divContainer.parentElement.clientHeight-this._tabHolder.getSheetBlanketSize()+"px",this._eFocus.removeAttribute("tabindex")):(this._divContainer.style.height=this._divContainer.parentElement.clientHeight+"px",this._eFocus.tabIndex=this._orgTabIndex),this._tabHolder.visible=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"undoStack",{get:function(){return this._undoStack},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"sortManager",{get:function(){return this._sortManager},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filter",{get:function(){return this._filter},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showFilterIcons",{get:function(){return!!this._filter&&this._filter.showFilterIcons},set:function(e){this._filter&&this._filter.showFilterIcons!==e&&(this._filter.showFilterIcons=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"definedNames",{get:function(){return this._definedNames},enumerable:!0,configurable:!0}),t.prototype.onSelectedSheetChanged=function(e){this.selectedSheetChanged.raise(this,e)},t.prototype.onDraggingRowColumn=function(e){this.draggingRowColumn.raise(this,e)},t.prototype.onDroppingRowColumn=function(e){this.droppingRowColumn.raise(this,new wjcCore.EventArgs)},t.prototype.onLoaded=function(e){var t=this;t._toRefresh&&(clearTimeout(t._toRefresh),t._toRefresh=null),t._toRefresh=setTimeout(function(){t._setFlexSheetToDirty(),t.invalidate()},10),t.loaded.raise(this,new wjcCore.EventArgs)},t.prototype.onUnknownFunction=function(e){this.unknownFunction.raise(this,e)},t.prototype.onSheetCleared=function(e){this.sheetCleared.raise(this,new wjcCore.EventArgs)},t.prototype.onPrepareChangingRow=function(e){this.prepareChangingRow.raise(this,e)},t.prototype.onPrepareChangingColumn=function(e){this.prepareChangingColumn.raise(this,e)},t.prototype.onRowChanged=function(e){this.rowChanged.raise(this,e)},t.prototype.onColumnChanged=function(e){this.columnChanged.raise(this,e)},t.prototype.refresh=function(t){void 0===t&&(t=!0);var o,n,i;if(this._divContainer.style.height=this._divContainer.parentElement.clientHeight-(this.isTabHolderVisible?this._tabHolder.getSheetBlanketSize():0)+"px",!this.preserveSelectedState&&this.selectedSheet&&(this.selectedSheet.selectionRanges.clear(),this.selectedSheet.selectionRanges.push(this.selection)),t&&this._clearCalcEngine(),this._lastVisibleFrozenRow=-1,this.frozenRows>0)for(var r=this.frozenRows-1;r>=0;r--)if(this.rows[r]&&this.rows[r].isVisible){this._lastVisibleFrozenRow=r;break}if(this._lastVisibleFrozenColumn=-1,this.frozenColumns>0)for(var l=this.frozenColumns-1;l>=0;l--)if(this.columns[l]&&this.columns[l].isVisible){this._lastVisibleFrozenColumn=l;break}if(this.selectedSheet){if(this.selectedSheet._freezeHiddenRowCnt>0)for(o=0;o<this.selectedSheet._freezeHiddenRowCnt;o++)(n=this.rows[o])instanceof HeaderRow||(n.visible=!1);if(this.selectedSheet._freezeHiddenColumnCnt>0)for(i=0;i<this.selectedSheet._freezeHiddenColumnCnt;i++)this.columns[i].visible=!1}e.prototype.refresh.call(this,t),this._tabHolder.adjustSize()},t.prototype.setCellData=function(e,t,o,n,i){void 0===n&&(n=!1),void 0===i&&(i=!0);var r=wjcCore.isString(o)&&o.length>1&&"="===o[0];return this._clearCalcEngine(),this.cells.setCellData(e,t,o,n&&!r,i)},t.prototype.containsFocus=function(){return this.isFunctionListOpen||e.prototype.containsFocus.call(this)},t.prototype.addUnboundSheet=function(e,t,o,n,i){var r=this._addSheet(e,t,o,n,i);return 0===r.selectionRanges.length&&r.selectionRanges.push(this.selection),r},t.prototype.addBoundSheet=function(e,t,o,n){var i=this._addSheet(e,0,0,o,n);return t&&(i.itemsSource=t,this.childItemsPath&&(i.grid.childItemsPath=this.childItemsPath)),0===i.selectionRanges.length&&i.selectionRanges.push(this.selection),i},t.prototype.applyCellsStyle=function(e,t,o){void 0===o&&(o=!1);var n,i,r,l,s,a=t||[this.selection];if(this.selectedSheet){if(!e&&this._cloneStyle)return this.selectedSheet._styledCells=this._cloneObject(this._cloneStyle),this._cloneStyle=null,void this.refresh(!1);if(a){for(t||o?o&&!this._cloneStyle&&(this._cloneStyle=this._cloneObject(this.selectedSheet._styledCells)):(this.undoStack.stackSize>0&&(s=new _CellStyleAction(this,this._cloneStyle)),this._cloneStyle=null),l=0;l<a.length;l++)for(n=(r=a[l]).topRow;n<=r.bottomRow;n++)for(i=r.leftCol;i<=r.rightCol;i++)this._applyStyleForCell(n,i,e);s&&(s.saveNewState(),this._undoStack._addAction(s))}t||this.refresh(!1)}},t.prototype.freezeAtCursor=function(){var e,t,o,n,i,r=this;if(r.selectedSheet){if(r.selection&&0===r.frozenRows&&0===r.frozenColumns){if(r._ptScrl.y<0)for(e=0;e<r.selection.topRow-1;e++)if(!((i=r.rows[e])instanceof HeaderRow)){if(!(i._pos+r._ptScrl.y<0)){r.selectedSheet._freezeHiddenRowCnt=e;break}i.visible=!1}if(r._ptScrl.x<0)for(t=0;t<r.selection.leftCol-1;t++){if(!(r.columns[t]._pos+r._ptScrl.x<0)){r.selectedSheet._freezeHiddenColumnCnt=t;break}r.columns[t].visible=!1}o=r.selection.leftCol>0?r.selection.leftCol:0,n=r.selection.topRow>0?r.selection.topRow:0}else{for(e=0;e<r.frozenRows-1;e++)r.rows[e].visible=!0;for(t=0;t<r.frozenColumns-1;t++)r.columns[t].visible=!0;r._filter.apply(),o=0,n=0,r.selectedSheet._freezeHiddenRowCnt=0,r.selectedSheet._freezeHiddenColumnCnt=0}r.frozenRows=r.selectedSheet.grid.frozenRows=n,r.frozenColumns=r.selectedSheet.grid.frozenColumns=o,setTimeout(function(){r._setFlexSheetToDirty(),r.invalidate(),r.scrollIntoView(r.selection.topRow,r.selection.leftCol)},10)}},t.prototype.showColumnFilter=function(){var e=this.selection.col>0?this.selection.col:0;this.columns.length>0&&this._filter.editColumnFilter(this.columns[e])},t.prototype.clear=function(){this.beginUpdate(),this.selection=new wjcGrid.CellRange,this.sheets.clear(),this._selectedSheetIndex=-1,this.columns.clear(),this.rows.clear(),this.columnHeaders.columns.clear(),this.rowHeaders.rows.clear(),this._undoStack.clear(),this._ptScrl=new wjcCore.Point,this._clearCalcEngine(),this._definedNames.clear(),this._builtInTableStylesCache=null,this.addUnboundSheet(),this.endUpdate()},t.prototype.getSelectionFormatState=function(){var e,t,o=this.rows.length,n=this.columns.length,i={isBold:!1,isItalic:!1,isUnderline:!1,textAlign:"left",isMergedCell:!1};if(0===o||0===n)return i;if(this.selection){if(this.selection.row>=o||this.selection.row2>=o||this.selection.col>=n||this.selection.col2>=n)return i;for(e=this.selection.topRow;e<=this.selection.bottomRow;e++)for(t=this.selection.leftCol;t<=this.selection.rightCol;t++)this._checkCellFormat(e,t,i)}return i},t.prototype.insertRows=function(e,t){var o,n,i,r,l,s,a=wjcCore.isNumber(e)&&e>=0?e:this.selection&&this.selection.topRow>-1?this.selection.topRow:0,h=wjcCore.isNumber(t)?t:1,c=this.rows[a],d=!1;if(this.selectedSheet){if(this.rows.length>0?a>=this.rows.length&&(a=this.rows.length-1):a=0,this._clearCalcEngine(),this.finishEditing(),0===a&&c&&c.constructor===HeaderRow&&(a=1),this.onPrepareChangingRow(new RowColumnChangedEventArgs(a,h,!0)),this.undoStack.stackSize>0&&(o=new _RowsChangedAction(this,a,h,!0)),this._updateCellsForUpdatingRow(this.rows.length,a,h),(!this.collectionView||0===this.collectionView.sortDescriptions.length)&&(n=this._updateAffectedFormula(a,h,!0,!0),i=this._updateAffectedNamedRanges(a,h,!0,!0)),o&&(o._affectedFormulas=n,o._affectedDefinedNameVals=i),this.collectionView){for(d=!0,l=this.itemsSource instanceof wjcCore.CollectionView,this.collectionView.beginUpdate(),r=0;r<h;r++)l?(s=this.itemsSource.newItemCreator?this.itemsSource.newItemCreator():{},this.itemsSource.sourceCollection.splice(a-(this.allowAddNew&&this.newRowAtTop?2:1),0,s)):(this.selectedSheet.grid.collectionView.beginUpdate(),s={},this.itemsSource.splice(a-(this.allowAddNew&&this.newRowAtTop?2:1),0,s),this.itemsSource!==this.selectedSheet.grid.itemsSource&&this.selectedSheet.grid.itemsSource.splice(a-(this.allowAddNew&&this.newRowAtTop?2:1),0,s)),this.selectedSheet._orgItemsSource&&this.selectedSheet._orgItemsSource.splice(a-(this.allowAddNew&&this.newRowAtTop?2:1),0,s);l||this.selectedSheet.grid.collectionView.endUpdate(),this.collectionView.endUpdate()}else{for(this.rows.beginUpdate(),r=0;r<h;r++)this.rows.insert(a,new wjcGrid.Row);this.rows.endUpdate()}this._updateTablesForUpdatingRow(a,h),this.selection&&-1!==this.selection.row&&-1!==this.selection.col||(this.selection=new wjcGrid.CellRange(0,0)),o&&(o.saveNewState(),this._undoStack._addAction(o)),this.onRowChanged(new RowColumnChangedEventArgs(a,h,!0)),d&&this.refresh()}},t.prototype.deleteRows=function(e,t){var o,n,i,r,l,s,a,h,c,d=wjcCore.isNumber(t)&&t>=0?t:this.selection&&this.selection.topRow>-1?this.selection.bottomRow-this.selection.topRow+1:1,u=wjcCore.isNumber(e)&&e>=0?e:this.selection&&this.selection.topRow>-1?this.selection.topRow:-1,_=wjcCore.isNumber(e)&&e>=0?e+d-1:this.selection&&this.selection.topRow>-1?this.selection.bottomRow:-1,g=!1;if(this.selectedSheet&&!(u>=this.rows.length)&&(_=Math.min(_,this.rows.length-1),this._clearCalcEngine(),this.finishEditing(),u>-1&&_>-1)){for(this.onPrepareChangingRow(new RowColumnChangedEventArgs(u,d,!1)),this.undoStack.stackSize>0&&(o=new _RowsChangedAction(this,u,d,!1)),this._updateCellsForUpdatingRow(this.rows.length,u,d,!0),n=this._updateAffectedFormula(_,_-u+1,!1,!0),i=this._updateAffectedNamedRanges(_,_-u+1,!1,!0),r=this._updateTablesForUpdatingRow(u,d,!0),o&&(o._affectedFormulas=n,o._affectedDefinedNameVals=i,o._deletedTables=r),c=!!this.collectionView&&this.itemsSource instanceof wjcCore.CollectionView,this.rows.beginUpdate();_>=u;_--)(!(l=this.rows[_])||l.constructor!==HeaderRow&&l.isVisible)&&(l.dataItem&&this.collectionView?(g=!0,this.collectionView.beginUpdate(),(s=this._getCvIndex(_))>-1&&(a=this.collectionView.items[s],c?this.itemsSource.sourceCollection.splice(this.itemsSource.sourceCollection.indexOf(a),1):(this.selectedSheet.grid.collectionView.beginUpdate(),this.itemsSource.splice(this.itemsSource.indexOf(a),1),this.itemsSource!==this.selectedSheet.grid.itemsSource&&this.selectedSheet.grid.itemsSource.splice(this.itemsSource.indexOf(a),1)),this.selectedSheet._orgItemsSource&&this.selectedSheet._orgItemsSource.splice(this.selectedSheet._orgItemsSource.indexOf(a),1)),c||this.selectedSheet.grid.collectionView.endUpdate(),this.collectionView.endUpdate()):this.rows.removeAt(_));this.rows.endUpdate(),h=this.rows.length,this.selectedSheet.selectionRanges.clear(),0===h?(this.select(new wjcGrid.CellRange),"move"===this.hostElement.style.cursor&&(this.hostElement.style.cursor="default")):_===h-1?this.select(new wjcGrid.CellRange(_,0,_,this.columns.length-1)):this.select(new wjcGrid.CellRange(this.selection.topRow,this.selection.col,this.selection.topRow,this.selection.col2)),o&&(o.saveNewState(),this._undoStack._addAction(o)),this.onRowChanged(new RowColumnChangedEventArgs(u,d,!1)),g&&this.refresh()}},t.prototype.insertColumns=function(e,t){var o,n,i,r,l,s,a=wjcCore.isNumber(e)&&e>=0?e:this.selection&&this.selection.leftCol>-1?this.selection.leftCol:0,h=wjcCore.isNumber(t)?t:1;if(this.selectedSheet){for(this.columns.length>0?a>=this.columns.length&&(a=this.columns.length-1):a=0,this._clearCalcEngine(),this.finishEditing(),this.onPrepareChangingColumn(new RowColumnChangedEventArgs(a,h,!0)),this.undoStack.stackSize>0&&(o=new _ColumnsChangedAction(this,a,h,!0)),this._updateCellsForUpdatingColumn(this.columns.length,a,h),l=this._updateAffectedFormula(a,h,!0,!1),s=this._updateAffectedNamedRanges(a,h,!0,!1),o&&(o._affectedFormulas=l,o._affectedDefinedNameVals=s),this.columns.beginUpdate(),i=0;i<h;i++)(n=new wjcGrid.Column).isRequired=!1,this.itemsSource&&(n.binding=this._getUniqueColumnName(),(r=this.allowAddNew&&this.newRowAtTop?this.rows[1]:this.rows[0])&&(r._ubv||(r._ubv={}),r._ubv[n._hash]=n.header)),this.columns.insert(a,n);this.columns.endUpdate(),this._sortManager._updateSortSortDescription(a,h),this._sortManager.commitSort(!1),this._updateTablesForUpdatingColumn(a,h),this.selection&&-1!==this.selection.row&&-1!==this.selection.col||(this.selection=new wjcGrid.CellRange(0,0)),o&&(o.saveNewState(),this._undoStack._addAction(o)),this.onColumnChanged(new RowColumnChangedEventArgs(a,h,!0))}},t.prototype.deleteColumns=function(e,t){var o,n,i,r,l,s=wjcCore.isNumber(t)&&t>=0?t:this.selection&&this.selection.leftCol>-1?this.selection.rightCol-this.selection.leftCol+1:1,a=wjcCore.isNumber(e)&&e>=0?e:this.selection&&this.selection.leftCol>-1?this.selection.leftCol:-1,h=wjcCore.isNumber(e)&&e>=0?e+s-1:this.selection&&this.selection.leftCol>-1?this.selection.rightCol:-1;if(this.selectedSheet&&!(a>=this.columns.length)&&(h=Math.min(h,this.columns.length-1),this._clearCalcEngine(),this.finishEditing(),a>-1&&h>-1)){for(this.onPrepareChangingColumn(new RowColumnChangedEventArgs(a,s,!1)),this.undoStack.stackSize>0&&(n=new _ColumnsChangedAction(this,a,s,!1)),this._updateCellsForUpdatingColumn(this.columns.length,a,s,!0),i=this._updateAffectedFormula(h,h-a+1,!1,!1),r=this._updateAffectedNamedRanges(h,h-a+1,!1,!1),l=this._updateTablesForUpdatingColumn(a,s,!0),n&&(n._affectedFormulas=i,n._affectedDefinedNameVals=r,n._deletedTables=l),this.columns.beginUpdate();h>=a;h--)this.columns[h].isVisible&&(this.columns.removeAt(h),this._sortManager.deleteSortLevel(h));this.columns.endUpdate(),this._sortManager._updateSortSortDescription(a,s,!1),this._sortManager.commitSort(!1),o=this.columns.length,this.selectedSheet.selectionRanges.clear(),0===o?(this.select(new wjcGrid.CellRange),"move"===this.hostElement.style.cursor&&(this.hostElement.style.cursor="default")):h===o-1?this.select(new wjcGrid.CellRange(0,h,this.rows.length-1,h)):this.select(new wjcGrid.CellRange(this.selection.row,this.selection.leftCol,this.selection.row2,this.selection.leftCol)),n&&(n.saveNewState(),this._undoStack._addAction(n)),this.onColumnChanged(new RowColumnChangedEventArgs(a,s,!1))}},t.prototype.mergeRange=function(e,t){void 0===t&&(t=!1);var o,n,i,r=e||this.selection,l=-1,s=-1;if(this.selectedSheet){if(r){if(1===r.rowSpan&&1===r.columnSpan)return;for(o=r.topRow;o<=r.bottomRow;o++)for(n=r.leftCol;n<=r.rightCol;n++)if(this.selectedSheet.findTable(o,n))return;if(e||t||(this.undoStack.stackSize>0&&(i=new _CellMergeAction(this)),this.hostElement.focus()),!this._resetMergedRange(r)){for(o=r.topRow;o<=r.bottomRow;o++)if(this.rows[o].isVisible){l=o;break}for(n=r.leftCol;n<=r.rightCol;n++)if(this.columns[n].isVisible){s=n;break}l>-1&&s>-1&&this.selectedSheet._mergedRanges.push(new wjcGrid.CellRange(l,s,r.bottomRow,r.rightCol))}i&&(i.saveNewState(),this._undoStack._addAction(i))}e||this.refresh()}},t.prototype.getMergedRange=function(t,o,n,i){void 0===i&&(i=!0);var r,l,s,a,h=this.selectedSheet?this.selectedSheet._getMergedRange(o,n):null;return t===this.cells&&h?!h.isSingleCell&&(this.frozenRows>0||this.frozenColumns>0)&&(h.topRow<this.frozenRows&&h.bottomRow>=this.frozenRows||h.leftCol<this.frozenColumns&&h.rightCol>=this.frozenColumns)?(r=h.topRow,l=h.bottomRow,s=h.leftCol,a=h.rightCol,o>=this.frozenRows&&h.topRow<this.frozenRows&&(r=this.frozenRows),o<this.frozenRows&&h.bottomRow>=this.frozenRows&&(l=this.frozenRows-1),l>=this.rows.length&&(l=this.rows.length-1),n>=this.frozenColumns&&h.leftCol<this.frozenColumns&&(s=this.frozenColumns),n<this.frozenColumns&&h.rightCol>=this.frozenColumns&&(a=this.frozenColumns-1),a>=this.columns.length&&(a=this.columns.length-1),new wjcGrid.CellRange(r,s,l,a)):h.bottomRow>=this.rows.length?new wjcGrid.CellRange(h.topRow,h.leftCol,this.rows.length-1,h.rightCol):h.rightCol>=this.columns.length?new wjcGrid.CellRange(h.topRow,h.leftCol,h.bottomRow,this.columns.length-1):h.clone():n>=0&&this.columns&&this.columns.length>n&&o>=0&&this.rows&&this.rows.length>o?e.prototype.getMergedRange.call(this,t,o,n,i):null},t.prototype.evaluate=function(e,t,o,n){void 0===n&&(n=!0);var i=this._evaluate(e,t,o);return n&&null!=i&&!wjcCore.isPrimitive(i)?i.value:i},t.prototype.getCellValue=function(e,t,o,n){void 0===o&&(o=!1);var i,r,l=n&&n!==this.selectedSheet?n.grid.columns[t]:this.columns[t],s=this._getCellStyle(e,t,n);return i=s&&s.format?s.format:"",r=n&&n!==this.selectedSheet?n.grid.getCellData(e,t,!1):this.getCellData(e,t,!1),wjcCore.isString(r)&&"="===r[0]&&(r=this._evaluate(r,o?i:"",n,e,t)),o?(i||null==r||wjcCore.isPrimitive(r)||(s?s.format=r.format:this._applyStyleForCell(e,t,{format:r.format})),r=this._formatEvaluatedResult(r,l,i)):null==r||wjcCore.isPrimitive(r)||(r=r.value),null==r?"":r},t.prototype.showFunctionList=function(e){var t,o,n=this,i=n._cumulativeOffset(e),r=n._cumulativeOffset(n._root);n._functionTarget=wjcCore.tryCast(e,HTMLInputElement),n._functionTarget&&n._functionTarget.value&&"="===n._functionTarget.value[0]?(n._functionList._cv.filter=function(e){var t,o=e.actualvalue.toLowerCase(),i=n._getCurrentFormulaIndex(n._functionTarget.value);return-1===i&&(i=0),(t=n._functionTarget.value.substr(i+1).trim().toLowerCase()).length>0&&0===o.indexOf(t)||"="===n._functionTarget.value},n._functionList.selectedIndex=0,t=i.y+e.clientHeight+2+(wjcCore.hasClass(e,"wj-grid-editor")?this._ptScrl.y:0),o=i.x+(wjcCore.hasClass(e,"wj-grid-editor")?this._ptScrl.x:0),wjcCore.setCss(n._functionListHost,{height:n._functionList._cv.items.length>5?"218px":"auto",display:n._functionList._cv.items.length>0?"block":"none",top:"",left:""}),n._functionListHost.scrollTop=0,n._functionListHost.offsetHeight+t>r.y+n._root.offsetHeight?t=t-e.clientHeight-n._functionListHost.offsetHeight-5:t+=5,n._functionListHost.offsetWidth+o>r.x+n._root.offsetWidth&&(o=r.x+n._root.offsetWidth-n._functionListHost.offsetWidth),wjcCore.setCss(n._functionListHost,{top:t,left:o})):n.hideFunctionList()},t.prototype.hideFunctionList=function(){this._functionListHost.style.display="none"},t.prototype.selectPreviousFunction=function(){this._functionList.selectedIndex>0&&this._functionList.selectedIndex--},t.prototype.selectNextFunction=function(){this._functionList.selectedIndex<this._functionList.itemsSource.length&&this._functionList.selectedIndex++},t.prototype.applyFunctionToCell=function(){var e,t=this;t._functionTarget&&(-1===(e=t._getCurrentFormulaIndex(t._functionTarget.value))?e=t._functionTarget.value.indexOf("="):e+=1,t._functionTarget.value=t._functionTarget.value.substring(0,e)+t._functionList.selectedValue+"(","="!==t._functionTarget.value[0]&&(t._functionTarget.value="="+t._functionTarget.value),t._functionTarget.focus(),t.hideFunctionList())},t.prototype.save=function(e){var t=this._saveToWorkbook();return e&&t.save(e),t},t.prototype.saveAsync=function(e,t,o){var n=this._saveToWorkbook();return n.saveAsync(e,t,o),n},t.prototype.saveToWorkbookOM=function(){return this._saveToWorkbook()._serialize()},t.prototype.load=function(e){var t,o,n=this;if(e instanceof Blob)(o=new FileReader).onload=function(){var e=o.result;e=wjcXlsx.Workbook._base64EncArr(new Uint8Array(e)),(t=new wjcXlsx.Workbook).load(e),n._loadFromWorkbook(t)},o.readAsArrayBuffer(e);else if(e instanceof wjcXlsx.Workbook)n._loadFromWorkbook(e);else{if(e instanceof ArrayBuffer)e=wjcXlsx.Workbook._base64EncArr(new Uint8Array(e));else if(!wjcCore.isString(e))throw"Invalid workbook.";(t=new wjcXlsx.Workbook).load(e),n._loadFromWorkbook(t)}},t.prototype.loadAsync=function(e,t,o){var n,i,r=this;if(e instanceof Blob)(i=new FileReader).onload=function(){var e=i.result;e=wjcXlsx.Workbook._base64EncArr(new Uint8Array(e)),(n=new wjcXlsx.Workbook).loadAsync(e,function(e){r._loadFromWorkbook(e),t&&t(e)},o)},i.readAsArrayBuffer(e);else if(e instanceof wjcXlsx.Workbook)r._loadFromWorkbook(e),t&&t(e);else{if(e instanceof ArrayBuffer)e=wjcXlsx.Workbook._base64EncArr(new Uint8Array(e));else if(!wjcCore.isString(e))throw"Invalid workbook.";(n=new wjcXlsx.Workbook).loadAsync(e,function(e){r._loadFromWorkbook(e),t&&t(e)},o)}},t.prototype.loadFromWorkbookOM=function(e){var t;e instanceof wjcXlsx.Workbook?t=e:(t=new wjcXlsx.Workbook)._deserialize(e),this._loadFromWorkbook(t)},t.prototype.undo=function(){var e=this;setTimeout(function(){e._undoStack.undo()},100)},t.prototype.redo=function(){var e=this;setTimeout(function(){e._undoStack.redo()},100)},t.prototype.select=function(t,o){void 0===o&&(o=!0);var n,i,r;if(wjcCore.isNumber(t)&&wjcCore.isNumber(o)&&(t=new wjcGrid.CellRange(t,o),o=!0),t.rowSpan!==this.rows.length&&t.columnSpan!==this.columns.length)for(i=t.topRow;i<=t.bottomRow;i++)for(r=t.leftCol;r<=t.rightCol;r++)(n=this.getMergedRange(this.cells,i,r))&&!t.equals(n)&&(t.row<=t.row2?(t.row=Math.min(t.topRow,n.topRow),t.row2=Math.max(t.bottomRow,n.bottomRow)):(t.row=Math.max(t.bottomRow,n.bottomRow),t.row2=Math.min(t.topRow,n.topRow)),t.col<=t.col2?(t.col=Math.min(t.leftCol,n.leftCol),t.col2=Math.max(t.rightCol,n.rightCol)):(t.col=Math.max(t.rightCol,n.rightCol),t.col2=Math.min(t.leftCol,n.leftCol)));this._isPasting&&this.collectionView&&(this.collectionView._pendingRefresh=!1),e.prototype.select.call(this,t,o)},t.prototype.addCustomFunction=function(e,t,o,n,i){wjcCore._deprecated("addCustomFunction","addFunction"),this._calcEngine.addCustomFunction(e,t,n,i),this._addCustomFunctionDescription(e,o)},t.prototype.addFunction=function(e,t,o,n,i){this._calcEngine.addFunction(e,t,n,i),this._addCustomFunctionDescription(e,o)},t.prototype.dispose=function(){var t=window.navigator.userAgent;this._needCopyToSheet=!1,document.removeEventListener("mousemove",this._mouseMoveHdl),document.body.removeEventListener("click",this._clickHdl),(t.match(/iPad/i)||t.match(/iPhone/i))&&(document.body.removeEventListener("touchstart",this._touchStartHdl),document.body.removeEventListener("touchend",this._touchEndHdl)),this.hideFunctionList(),e.prototype.dispose.call(this)},t.prototype.getClipString=function(t){var o,n,i,r,l,s,a="",h=!0;if(!this.selectedSheet)return e.prototype.getClipString.call(this,t);if(this._isCutting=!1,!t)if(this.selectedSheet.selectionRanges.length>1){if(this._isMultipleRowsSelected()){for(a="",0===(o=this.selectedSheet.selectionRanges.slice(0)).length&&(o=[this.selection]),o.sort(this._sortByRow),i=0;i<o.length;i++)a&&(a+="\n"),a+=this.getClipString(o[i]);return a}if(this._isMultipleColumnsSelected()){for(a="",0===(o=this.selectedSheet.selectionRanges.slice(0)).length&&(o=[this.selection]),o.sort(this._sortByColumn),n=(r=o[0]).topRow,h=!0;n<=r.bottomRow;n++)for(h||(a+="\n"),h=!1,i=0,_=!0;i<o.length;i++)l=o[i],_||(a+="\t"),_=!1,a+=this.getClipString(new wjcGrid.CellRange(n,l.col,n,l.col2));return a}wjcCore.assert(!1,"Copy or Cut operation cannot be used on multiple selections.")}else switch(t=this.selection,this.selectionMode){case wjcGrid.SelectionMode.Row:case wjcGrid.SelectionMode.RowRange:t.col=0,t.col2=this.columns.length-1;break;case wjcGrid.SelectionMode.ListBox:t.col=0,t.col2=this.columns.length-1;for(var c=0;c<this.rows.length;c++)this.rows[c].isSelected&&this.rows[c].isVisible&&(t.row=t.row2=c,a&&(a+="\n"),a+=this.getClipString(t));return a}if(!(t=wjcCore.asType(t,wjcGrid.CellRange)).isValid)return"";for(var d=t.topRow,h=!0;d<=t.bottomRow;d++)if(this.rows[d].isVisible){h||(a+="\n"),h=!1;for(var u=t.leftCol,_=!0;u<=t.rightCol;u++)this.columns[u].isVisible&&(_||(a+="\t"),_=!1,(s=(s=this.getCellValue(d,u,!0).toString()).replace(/\t/g," ")).indexOf("\n")>-1&&(s='"'+s.replace(/"/g,'""')+'"'),a+=s)}return a},t.prototype.setClipString=function(t,o){var n,i,r,l,s,a,h,c,d,u,_,g,w,p,f,m,C,b,S,y,R,v,T,x=null==o,j=!1,k=!1;if(this.selectedSheet){if(o=o?wjcCore.asType(o,wjcGrid.CellRange):this.selection,(t=wjcCore.asString(t).replace(/\r\n/g,"\n").replace(/\r/g,"\n"))&&"\n"==t[t.length-1]&&(t=t.substring(0,t.length-1)),R=t,c=this._edtHdl._parseClipString(wjcCore.asString(t)),x&&!o.isSingleCell&&c.length&&this._edtHdl._expandClipRows(c,o),k=this._containsMultiLineText(c),(!this._copiedRanges||0===this._copiedRanges.length||R.trim()!==this._getRangeString(this._copiedRanges,this._copiedSheet).trim()&&!this._containsRandFormula(this._copiedRanges,this._copiedSheet)||this._cutValue)&&!k)return R!==this._cutValue&&(this._cutValue=null,e.prototype.setClipString.call(this,t)),this._copiedRanges=null,void(this._copiedSheet=null);if(v=this._getRangeString(this._copiedRanges,this._copiedSheet,!1),(v=wjcCore.asString(v).replace(/\r\n/g,"\n").replace(/\r/g,"\n"))&&"\n"==v[v.length-1]&&(v=v.substring(0,v.length-1)),c=this._edtHdl._parseClipString(wjcCore.asString(v)),x&&!o.isSingleCell&&c.length&&this._edtHdl._expandClipRows(c,o),(l=o.topRow+c.length-1)>=this.rows.length&&(l=this.rows.length-1),(s=o.leftCol+c[0].length-1)>=this.columns.length&&(s=this.columns.length-1),n=new wjcGrid.CellRange(o.topRow,o.leftCol,l,s),!this.onPasting(new wjcGrid.CellRangeEventArgs(this.cells,n)))return this._cutValue=null,this._copiedRanges=null,this._copiedSheet=null,!1;if(this.beginUpdate(),k||!this._copiedRanges||this._copiedRanges.length>1||0===this._copiedRanges.length)for(i=o.topRow,a=(b=this._copiedRanges&&this._copiedRanges.length>1?this._copiedRanges[0]:new wjcGrid.CellRange).topRow,_=0;_<c.length&&i<this.rows.length;_++,i++)if(this.rows[i].isVisible){for(d=c[_],h=b.leftCol,p=(r=o.leftCol)-h,g=0;g<d.length&&r<this.columns.length;g++,r++)this.columns[r].isVisible?(u=d[g],this.columns[r].isReadOnly||this.rows[i].isReadOnly||(j=this._postSetClipStringProcess(u,i,r,a,h),n.row2=Math.max(n.row2,i),n.col2=Math.max(n.col2,r)),h>=0&&h++):g--;a>=0&&a++}else _--;else if(this._copiedRanges&&1===this._copiedRanges.length)for(S=0,(b=this.selectionMode===wjcGrid.SelectionMode.ListBox?this._getSelectionForListBoxMode(this._copiedSheet.grid):this._copiedRanges[0]).rowSpan>o.rowSpan?b.rowSpan:o.rowSpan,b.columnSpan>o.columnSpan?b.columnSpan:o.columnSpan,i=o.topRow,_=0;_<c.length&&i<this.rows.length;_++,i++)if(y=0,this.rows[i].isVisible){for(;this._copiedSheet.grid.rows[b.topRow+S]&&!this._copiedSheet.grid.rows[b.topRow+S].isVisible;)S++;if(S>=b.rowSpan&&(S%=b.rowSpan),!this._copiedSheet.grid.rows[b.topRow+S])break;for(w=i-b.topRow-S,d=c[_],r=o.leftCol,g=0;g<d.length&&r<this.columns.length;g++,r++)if(this.columns[r]&&this.columns[r].isVisible){if(y>=b.columnSpan&&(y%=b.columnSpan),!this._copiedSheet.grid.columns[b.leftCol+y])break;if(p=r-b.leftCol-y,!this.columns[r].isReadOnly&&!this.rows[i].isReadOnly){if(null!=this._copiedSheet.grid.columns[b.leftCol+y].dataMap,u=d[g],T=this._getCellStyle(b.topRow+S,b.leftCol+y,this._copiedSheet),u&&"string"==typeof u&&"="===u[0]&&(0!==w||0!==p))try{f=this._calcEngine._parse(u),m=new wjcGrid.CellRange(b.topRow+S,b.leftCol+y),C=new wjcGrid.CellRange(b.topRow+S+w,b.leftCol+y+p),f._moveCellRangeExp(this.selectedSheetIndex,m,C,!1,!0)&&(u="="+f._getStringExpression())}catch(e){}this._copiedSheet.grid.columns[b.leftCol+y].format&&(T?T.format||(T.format=this._copiedSheet.grid.columns[b.leftCol+y].format):T={format:this._copiedSheet.grid.columns[b.leftCol+y].format}),j=this._postSetClipStringProcess(u,i,r,b.topRow+S,b.leftCol+y,T),n.row2=Math.max(n.row2,i),n.col2=Math.max(n.col2,r)}y++}else g--;S++}else _--;this._isCutting&&(this._delCutData(c.length,c[0].length),this._isCutting=!1,this._cutValue=R,this._copiedRanges=null,this._copiedSheet=null),this.endUpdate(),this.collectionView&&j&&this.collectionView.refresh(),this.select(n),this.onPasted(new wjcGrid.CellRangeEventArgs(this.cells,n))}else e.prototype.setClipString.call(this,t,o)},t.prototype.getBuiltInTableStyle=function(e){var t;return null==this._builtInTableStylesCache&&(this._builtInTableStylesCache={}),null==(t=this._builtInTableStylesCache[e.toLowerCase()])&&(t=this._createBuiltInTableStyle(e),Object.freeze(t),this._builtInTableStylesCache[e.toLowerCase()]=t),t},t.prototype._getCvIndex=function(t){return t>-1&&this.collectionView?this.rows[t]instanceof HeaderRow?t:e.prototype._getCvIndex.call(this,t):-1},t.prototype._init=function(){var e=this,t=this,o=window.navigator.userAgent,n=function(e){document.removeEventListener("mouseup",n),t._mouseUp(e)};t.hostElement.setAttribute("tabindex","-1"),t._divContainer=t.hostElement.querySelector('[wj-part="container"]'),t._tabHolder=new _TabHolder(t.hostElement.querySelector('[wj-part="tab-holder"]'),t),t._contextMenu=new _ContextMenu(t.hostElement.querySelector('[wj-part="context-menu"]'),t),t._gpCells=new FlexSheetPanel(t,wjcGrid.CellType.Cell,t.rows,t.columns,t._eCt),t._gpCHdr=new FlexSheetPanel(t,wjcGrid.CellType.ColumnHeader,t._hdrRows,t.columns,t._eCHdrCt),t._gpRHdr=new FlexSheetPanel(t,wjcGrid.CellType.RowHeader,t.rows,t._hdrCols,t._eRHdrCt),t._gpTL=new FlexSheetPanel(t,wjcGrid.CellType.TopLeft,t._hdrRows,t._hdrCols,t._eTLCt),t._sortManager=new SortManager(t),t._filter=new FlexSheetFilter(t),t._filter.filterApplied.addHandler(function(){t.selectedSheet&&(t.selectedSheet._filterDefinition=t._filter.filterDefinition,t.selectedSheet.itemsSource&&(t.selectedSheet._storeRowSettings(),t.selectedSheet._setRowSettings()))}),t._calcEngine=new _CalcEngine(t),t._calcEngine.unknownFunction.addHandler(function(e,o){t.onUnknownFunction(o)},t),t._initFuncsList(),t._undoStack=new UndoStack(t),t.loadedRows.addHandler(function(){if(t.itemsSource&&!(t.rows[0]instanceof HeaderRow)){for(var e,o=new HeaderRow,n=0;n<t.columns.length;n++)e=t.columns[n],o._ubv||(o._ubv={}),o._ubv[e._hash]=e.header;t.rows[0]instanceof wjcGrid._NewRowTemplate&&t.newRowAtTop?t.rows.insert(1,o):t.rows.insert(0,o)}t._filter&&t._filter.apply()}),t.itemsSourceChanged.addHandler(function(){var o;for(o=0;o<t.columns.length;o++)t.columns[o].isRequired=!1;t.collectionView&&t.collectionView.currentChanged.removeHandler(e._cvCurrentChanged,e)}),t.copied.addHandler(function(e,o){var n;t.selectedSheet&&(t._copiedSheet=t.selectedSheet,t._needCopyToSheet=!0,t.selectedSheet.selectionRanges.length>1?t._isMultipleRowsSelected()?((n=t.selectedSheet.selectionRanges.slice(0)).sort(t._sortByRow),t._copiedRanges=n):t._isMultipleColumnsSelected()?((n=t.selectedSheet.selectionRanges.slice(0)).sort(t._sortByColumn),t._copiedRanges=n):wjcCore.assert(!1,"Copy operation cannot be used on multiple selections."):t._copiedRanges=[o.range])}),t.rows.collectionChanged.addHandler(function(e,o){t._clearForEmptySheet("rows"),t.itemsSource||!t.selectedSheet||!t._needCopyToSheet||t._isCopying||t._isUndoing||o.item instanceof wjcGrid._NewRowTemplate||t._copyRowsToSelectedSheet()},t),t.columns.collectionChanged.addHandler(function(e,o){t._clearForEmptySheet("columns"),t.selectedSheet&&t._needCopyToSheet&&!t._isCopying&&!t._isUndoing&&t._copyColumnsToSelectedSheet()},t),t.definedNames.collectionChanged.addHandler(function(e,o){if(o.action===wjcCore.NotifyCollectionChangedAction.Add||o.action===wjcCore.NotifyCollectionChangedAction.Change){var n=o.action===wjcCore.NotifyCollectionChangedAction.Add?"inserted":"updated";if(!(o.item instanceof DefinedName))throw t.definedNames.remove(o.item),"Invalid defined name item object was "+n+".  The DefinedName instance should be "+n+" in the definedNames array.";if(!o.item||!o.item.name||null==o.item.value)throw t.definedNames.remove(o.item),"Invalid defined name was "+n+".";if(null!=o.item.sheetName&&!t._validateSheetName(o.item.sheetName))throw t.definedNames.remove(o.item),"The sheet name ("+o.item.sheetName+") does not exist in FlexSheet.";if(t._checkExistDefinedName(o.item.name,o.item.sheetName,o.index))throw t.definedNames.remove(o.item),"The "+o.item.name+" already existed in definedNames."}}),t.addEventListener(t.hostElement,"mousedown",function(e){document.addEventListener("mouseup",n),t._isDescendant(t._divContainer,e.target)&&t._mouseDown(e)},!0),t.addEventListener(t.hostElement,"drop",function(){t._columnHeaderClicked=!1}),t.addEventListener(t.hostElement,"contextmenu",function(e){var o,n,i,r,l,s,a,h,c;!e.defaultPrevented&&t.selectedSheet&&(t.activeEditor||(t._isContextMenuKeyDown&&t.selection.row>-1&&t.selection.col>-1&&t.rows.length>0&&t.columns.length>0?(i=t.columns[t.selection.col],n=t.rows[t.selection.row],a=t._cumulativeOffset(t.hostElement),h=t._cumulativeScrollOffset(t.hostElement),r=i.pos+t._eCt.offsetLeft+a.x+i.renderSize/2+t._ptScrl.x,l=n.pos+t._eCt.offsetTop+a.y+n.renderSize/2+t._ptScrl.y,s=new wjcCore.Point(r-h.x,l-h.y),o=t.hitTest(r,l),t._isContextMenuKeyDown=!1):o=t.hitTest(e),e.preventDefault(),o&&o.cellType!==wjcGrid.CellType.None&&(o.cellType===wjcGrid.CellType.TopLeft?c=new wjcGrid.CellRange(0,0,t.rows.length-1,t.columns.length-1):o.cellType===wjcGrid.CellType.Cell&&(c=new wjcGrid.CellRange(o.row,o.col)).intersects(t.selection)&&(c=null),c&&(t.selection=c,t.selectedSheet&&(t.selectedSheet.selectionRanges.clear(),t.selectedSheet.selectionRanges.push(c))),t._contextMenu.show(e,s))))}),t.prepareCellForEdit.addHandler(t._prepareCellForEditHandler,t),t.cellEditEnded.addHandler(function(e,o){(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&setTimeout(function(){t.hideFunctionList()},200)}),t.cellEditEnding.addHandler(function(e,o){(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&t._clearCalcEngine()}),t.pasting.addHandler(function(){t._needCopyToSheet=!1,t._isPasting=!0}),t.pasted.addHandler(function(){t.selection;t._needCopyToSheet=!0,t._isPasting=!1,t._clearCalcEngine()}),t.resizingColumn.addHandler(function(){t._resizing=!0}),t.resizingRow.addHandler(function(){t._resizing=!0}),t.resizedColumn.addHandler(function(){t._resizing=!1}),t.resizedRow.addHandler(function(){t._resizing=!1}),t.selectionChanged.addHandler(function(){var e=t.selection;t._isCopying||!e.isValid||t.containsFocus()||t.hostElement.focus(),e.rightCol>=t.columns.length&&(t.selection=new wjcGrid.CellRange(e.row,Math.min(e.col,t.columns.length-1),e.row2,Math.min(t.selection.col2,t.columns.length-1))),t._enableMulSel||t._isCopying||!t.selectedSheet||t.selectedSheet.selectionRanges.clear()}),t.addEventListener(t.hostElement,"keydown",function(e){var o,n,i=!1,r=!1;if(e.ctrlKey){if(89===e.keyCode&&(t.finishEditing(),t.redo(),e.preventDefault()),90===e.keyCode&&(t.finishEditing(),t.undo(),e.preventDefault()),t.selectedSheet&&65===e.keyCode&&(t.selectedSheet.selectionRanges.clear(),t.selectedSheet.selectionRanges.push(t.selection)),67!==e.keyCode&&45!=e.keyCode||(t.activeEditor&&(t._copiedRanges=null,t._copiedSheet=null),t._cutValue=null),88===e.keyCode&&!t.activeEditor){if(e.stopPropagation(),t.selectionMode===wjcGrid.SelectionMode.ListBox)for(var l=0;l<t.rows.length;l++)if(t.rows[l].isSelected)if(i){if(r)continue;wjcCore.assert(!1,"Cut operation cannot be used on multiple selections.")}else i=!0,r=!0;else r&&(r=!1);t.selectedSheet.selectionRanges.length>0&&(1===t.selectedSheet.selectionRanges.length?(t.finishEditing(),o=new wjcGrid.CellRangeEventArgs(t.cells,t.selection),t.onCopying(o)&&(t._cutValue=null,n=t.getClipString(),t._isCutting=!0,wjcCore.Clipboard.copy(n),t.onCopied(o))):wjcCore.assert(!1,"Cut operation cannot be used on multiple selections."))}e.keyCode===wjcCore.Key.Space&&t.selection.isValid&&t.selectionMode===wjcGrid.SelectionMode.CellRange&&t.select(new wjcGrid.CellRange(0,t.selection.col,t.rows.length-1,t.selection.col))}if(e.keyCode===wjcCore.Key.Escape&&t._contextMenu.hide(),(93===e.keyCode||e.shiftKey&&121===e.keyCode)&&(t._isContextMenuKeyDown=!0),t.selectedSheet&&!t._edtHdl.activeEditor)switch(e.keyCode){case wjcCore.Key.Left:case wjcCore.Key.Right:case wjcCore.Key.Up:case wjcCore.Key.Down:case wjcCore.Key.PageUp:case wjcCore.Key.PageDown:case wjcCore.Key.Home:case wjcCore.Key.End:case wjcCore.Key.Tab:case wjcCore.Key.Enter:t.selectedSheet._addSelection(t.selection),t.scrollIntoView(t.selection.row,t.selection.col)}}),t.addEventListener(document.body,"keydown",function(e){!t._isDescendant(t.hostElement,e.target)&&t.hostElement!==e.target||t._edtHdl.activeEditor||!t.selectedSheet||e.keyCode!==wjcCore.Key.Delete&&e.keyCode!==wjcCore.Key.Back||(t._delSeletionContent(e),e.preventDefault()),t._contextMenu.visible&&(e.keyCode===wjcCore.Key.Down&&t._contextMenu.moveToNext(),e.keyCode===wjcCore.Key.Up&&t._contextMenu.moveToPrev(),e.keyCode===wjcCore.Key.Home&&t._contextMenu.moveToFirst(),e.keyCode===wjcCore.Key.End&&t._contextMenu.moveToLast(),e.keyCode===wjcCore.Key.Enter&&t._contextMenu.handleContextMenu(),e.preventDefault())},!0),document.body.addEventListener("click",t._clickHdl),document.addEventListener("mousemove",t._mouseMoveHdl),(o.match(/iPad/i)||o.match(/iPhone/i))&&(document.body.addEventListener("touchstart",t._touchStartHdl),document.body.addEventListener("touchend",t._touchEndHdl)),t.addEventListener(t.hostElement,"drop",function(){t._htDown=null})},t.prototype._initFuncsList=function(){var e=this;e._functionListHost=document.createElement("div"),wjcCore.addClass(e._functionListHost,"wj-flexsheet-formula-list"),document.querySelector("body").appendChild(e._functionListHost),e._functionListHost.style.display="none",e._functionListHost.style.position="absolute",e._functionList=new wjcInput.ListBox(e._functionListHost),e._functionList.isContentHtml=!0,e._functionList.itemsSource=e._getFunctions(),e._functionList.displayMemberPath="displayValue",e._functionList.selectedValuePath="actualvalue",e.addEventListener(e._functionListHost,"click",e.applyFunctionToCell.bind(e)),e.addEventListener(e._functionListHost,"keydown",function(t){t.keyCode===wjcCore.Key.Escape&&(e.hideFunctionList(),e.hostElement.focus(),t.preventDefault()),t.keyCode===wjcCore.Key.Enter&&(e.applyFunctionToCell(),e.hostElement.focus(),t.preventDefault(),t.stopPropagation())})},t.prototype._getFunctions=function(){for(var e,t=[],o=0;o<FlexSheetFunctions.length;o++)e=FlexSheetFunctions[o],t.push({displayValue:'<div class="wj-flexsheet-formula-name">'+e.name+'</div><div class="wj-flexsheet-formula-description">'+e.description+"</div>",actualvalue:e.name});return t},t.prototype._addCustomFunctionDescription=function(e,t){for(var o={displayValue:'<div class="wj-flexsheet-formula-name">'+e+"</div>"+(t?'<div class="wj-flexsheet-formula-description">'+t+"</div>":""),actualvalue:e},n=this._functionList.itemsSource,i=-1,r=0;r<n.length;r++)if(n[r].actualvalue===e){i=r;break}i>-1?n.splice(i,1,o):n.push(o)},t.prototype._getCurrentFormulaIndex=function(e){var t=-1;return["+","-","*","/","^","(","&"].forEach(function(o){var n=e.lastIndexOf(o);n>t&&(t=n)}),t},t.prototype._prepareCellForEditHandler=function(){var e=this,t=e._edtHdl._edt;t&&(e.addEventListener(t,"keydown",function(t){if(e.isFunctionListOpen)switch(t.keyCode){case wjcCore.Key.Up:e.selectPreviousFunction(),t.preventDefault(),t.stopPropagation();break;case wjcCore.Key.Down:e.selectNextFunction(),t.preventDefault(),t.stopPropagation();break;case wjcCore.Key.Tab:case wjcCore.Key.Enter:e.applyFunctionToCell(),t.preventDefault(),t.stopPropagation();break;case wjcCore.Key.Escape:e.hideFunctionList(),t.preventDefault(),t.stopPropagation()}}),e.addEventListener(t,"keyup",function(o){(o.keyCode>40||o.keyCode<32)&&o.keyCode!==wjcCore.Key.Tab&&o.keyCode!==wjcCore.Key.Escape&&setTimeout(function(){e.showFunctionList(t)},0)}))},t.prototype._addSheet=function(e,t,o,n,i){var r=this,l=new Sheet(r,i,e,t,o);return r.sheets.isValidSheetName(l)||l._setValidName(r.sheets.getValidSheetName(l)),l.nameChanged.addHandler(function(e,t){r._updateDefinedNameWithSheetRefUpdating(t.oldValue,t.newValue)}),"number"==typeof n?(n<0&&(n=0),n>=r.sheets.length&&(n=r.sheets.length)):n=r.sheets.length,r.sheets.insert(n,l),l},t.prototype._showSheet=function(e){!this.sheets||!this.sheets.length||e>=this.sheets.length||e<0||e===this.selectedSheetIndex||this.sheets[e]&&!this.sheets[e].visible||(this.finishEditing(),this._clearCalcEngine(),this._isCopying=!0,this.selectedSheetIndex>-1&&this.selectedSheetIndex<this.sheets.length&&this._copyTo(this.sheets[this.selectedSheetIndex]),this.sheets[e]&&(this._selectedSheetIndex=e,this._copyFrom(this.sheets[e])),this._isCopying=!1,this._filter.closeEditor())},t.prototype._selectedSheetChange=function(e,t){this._showSheet(t.newValue),this.invalidate(!0),this.onSelectedSheetChanged(t)},t.prototype._sourceChange=function(e,t){if(t.action===wjcCore.NotifyCollectionChangedAction.Add||t.action===wjcCore.NotifyCollectionChangedAction.Change)t.item._attachOwner(this),t.action===wjcCore.NotifyCollectionChangedAction.Add?(this._addingSheet=!0,t.index<=this.selectedSheetIndex&&(this._selectedSheetIndex+=1)):t.index===this.selectedSheetIndex&&this._copyFrom(t.item,!0),this.selectedSheetIndex=t.index;else if(t.action===wjcCore.NotifyCollectionChangedAction.Reset){for(var o=0;o<this.sheets.length;o++)this.sheets[o]._attachOwner(this);this.sheets.length>0?(0===this.selectedSheetIndex&&this._copyFrom(this.selectedSheet,!0),this.selectedSheetIndex=0):(this.rows.clear(),this.columns.clear(),this._selectedSheetIndex=-1)}else this.sheets.length>0?this.selectedSheetIndex>=this.sheets.length?this.selectedSheetIndex=0:this.selectedSheetIndex>t.index&&(this._selectedSheetIndex-=1):(this.rows.clear(),this.columns.clear(),this._selectedSheetIndex=-1);this.invalidate(!0)},t.prototype._sheetVisibleChange=function(e,t){t.item.visible||t.index===this.selectedSheetIndex&&(this.selectedSheetIndex===this.sheets.length-1?this.selectedSheetIndex=t.index-1:this.selectedSheetIndex=t.index+1)},t.prototype._applyStyleForCell=function(e,t,o){var n,i,r,l=this,s=l.rows[e];null==s||s instanceof HeaderRow||!s.isVisible||(r=e*l.columns.length+t,(i=l.selectedSheet._getMergedRange(e,t))&&(r=i.topRow*l.columns.length+i.leftCol),(n=l.selectedSheet._styledCells[r])?(n.className="normal"===o.className?"":o.className||n.className,n.textAlign=o.textAlign||n.textAlign,n.verticalAlign=o.verticalAlign||n.verticalAlign,n.fontFamily=o.fontFamily||n.fontFamily,n.fontSize=o.fontSize||n.fontSize,n.backgroundColor=o.backgroundColor||n.backgroundColor,n.color=o.color||n.color,n.fontStyle="none"===o.fontStyle?"":o.fontStyle||n.fontStyle,n.fontWeight="none"===o.fontWeight?"":o.fontWeight||n.fontWeight,n.textDecoration="none"===o.textDecoration?"":o.textDecoration||n.textDecoration,n.format=o.format||n.format,n.whiteSpace=o.whiteSpace||n.whiteSpace,n.borderTopColor=o.borderTopColor||n.borderTopColor,n.borderTopStyle=o.borderTopStyle||n.borderTopStyle,n.borderTopWidth=o.borderTopWidth||n.borderTopWidth,n.borderBottomColor=o.borderBottomColor||n.borderBottomColor,n.borderBottomStyle=o.borderBottomStyle||n.borderBottomStyle,n.borderBottomWidth=o.borderBottomWidth||n.borderBottomWidth,n.borderLeftColor=o.borderLeftColor||n.borderLeftColor,n.borderLeftStyle=o.borderLeftStyle||n.borderLeftStyle,n.borderLeftWidth=o.borderLeftWidth||n.borderLeftWidth,n.borderRightColor=o.borderRightColor||n.borderRightColor,n.borderRightStyle=o.borderRightStyle||n.borderRightStyle,n.borderRightWidth=o.borderRightWidth||n.borderRightWidth):l.selectedSheet._styledCells[r]={className:o.className,textAlign:o.textAlign,verticalAlign:o.verticalAlign,fontStyle:o.fontStyle,fontWeight:o.fontWeight,fontFamily:o.fontFamily,fontSize:o.fontSize,textDecoration:o.textDecoration,backgroundColor:o.backgroundColor,color:o.color,format:o.format,whiteSpace:o.whiteSpace,borderTopColor:o.borderTopColor,borderTopStyle:o.borderTopStyle,borderTopWidth:o.borderTopWidth,borderBottomColor:o.borderBottomColor,borderBottomStyle:o.borderBottomStyle,borderBottomWidth:o.borderBottomWidth,borderLeftColor:o.borderLeftColor,borderLeftStyle:o.borderLeftStyle,borderLeftWidth:o.borderLeftWidth,borderRightColor:o.borderRightColor,borderRightStyle:o.borderRightStyle,borderRightWidth:o.borderRightWidth})},t.prototype._checkCellFormat=function(e,t,o){var n,i,r=e*this.columns.length+t;this.selectedSheet&&((n=this.selectedSheet._getMergedRange(e,t))&&(o.isMergedCell=!0,r=n.topRow*this.columns.length+n.leftCol),(i=this.selectedSheet._styledCells[r])&&(o.isBold=o.isBold||"bold"===i.fontWeight,o.isItalic=o.isItalic||"italic"===i.fontStyle,o.isUnderline=o.isUnderline||"underline"===i.textDecoration),e===this.selection.row&&t===this.selection.col&&(i&&i.textAlign?o.textAlign=i.textAlign:t>-1&&(o.textAlign=this.columns[t].getAlignment()||o.textAlign)))},t.prototype._resetMergedRange=function(e){var t,o,n,i,r=!1;for(t=e.topRow;t<=e.bottomRow;t++)for(o=e.leftCol;o<=e.rightCol;o++)(i=this.selectedSheet._getMergedRange(t,o))&&(r=!0,n=this.selectedSheet._mergedRanges.indexOf(i),this.selectedSheet._mergedRanges.splice(n,1));return r},t.prototype._updateCellsForUpdatingRow=function(e,t,o,n){var i,r,l,s,a,h,c,d=e*this.columns.length;if(n)for(r=i=t*this.columns.length;r<d;r++)l=r-o*this.columns.length,(s=this.selectedSheet._styledCells[r])&&(r>=(t+o)*this.columns.length&&(this.selectedSheet._styledCells[l]=s),delete this.selectedSheet._styledCells[r]);else for(i=t*this.columns.length-1,r=d-1;r>i;r--)l=r+this.columns.length*o,(s=this.selectedSheet._styledCells[r])&&(this.selectedSheet._styledCells[l]=s,delete this.selectedSheet._styledCells[r]);if(this.selectedSheet._mergedRanges.length>0)for(h=this.selectedSheet._mergedRanges.length-1;h>=0;h--)a=this.selectedSheet._mergedRanges[h],n?(c=t+o-1)<a.topRow?(a.row-=o,a.row2-=o):c>=a.topRow&&c<=a.bottomRow?t<=a.topRow&&c>=a.bottomRow?this.selectedSheet._mergedRanges.splice(h,1):t<a.topRow?a.row<=a.row2?(a.row+=t-a.topRow,a.row2-=o):(a.row2+=t-a.topRow,a.row-=o):t===a.topRow&&o===a.rowSpan?this.selectedSheet._mergedRanges.splice(h,1):a.row<=a.row2?a.row2-=o:a.row-=o:t<=a.topRow?this.selectedSheet._mergedRanges.splice(h,1):t<=a.bottomRow&&(a.row<=a.row2?a.row2+=t-a.bottomRow-1:a.row+=t-a.bottomRow-1):t<=a.topRow?(a.row+=o,a.row2+=o):t>a.topRow&&t<=a.bottomRow&&(a.row<=a.row2?a.row2+=o:a.row+=o)},t.prototype._updateCellsForUpdatingColumn=function(e,t,o,n){var i,r,l,s,a,h,c,d=this.rows.length*e;if(n)for(i=t;i<d;i++)r=i-o*(Math.floor(i/e)+((s=i%e)>=t?1:0)),(l=this.selectedSheet._styledCells[i])&&((s<t||s>=t+o)&&(this.selectedSheet._styledCells[r]=l),delete this.selectedSheet._styledCells[i]);else for(i=d-1;i>=t;i--)r=i+Math.floor(i/e)*o+((s=i%e)>=t?1:0),(l=this.selectedSheet._styledCells[i])&&(this.selectedSheet._styledCells[r]=l,delete this.selectedSheet._styledCells[i]);if(this.selectedSheet._mergedRanges.length>0)for(h=this.selectedSheet._mergedRanges.length-1;h>=0;h--)a=this.selectedSheet._mergedRanges[h],n?(c=t+o-1)<a.leftCol?(a.col-=o,a.col2-=o):c>=a.leftCol&&c<=a.rightCol?t<=a.leftCol&&c>=a.rightCol?this.selectedSheet._mergedRanges.splice(h,1):t<a.leftCol?a.col<=a.col2?(a.col+=t-a.leftCol,a.col2-=o):(a.col2+=t-a.leftCol,a.col-=o):t===a.leftCol&&o===a.columnSpan?this.selectedSheet._mergedRanges.splice(h,1):a.col<=a.col2?a.col2-=o:a.col-=o:t<=a.leftCol?this.selectedSheet._mergedRanges.splice(h,1):t<=a.rightCol&&(a.col<=a.col2?a.col2-=a.rightCol-t+1:a.col-=a.rightCol-t+1):t<=a.leftCol?(a.col+=o,a.col2+=o):t>a.leftCol&&t<=a.rightCol&&(a.col<=a.col2?a.col2+=o:a.col+=o)},t.prototype._cloneObject=function(e){var t;if(null==e||!wjcCore.isObject(e))return e;t={};for(var o in e)e.hasOwnProperty(o)&&null!=e[o]&&(e[o].clone?t[o]=e[o].clone():t[o]=this._cloneObject(e[o]));return t},t.prototype._evaluate=function(e,t,o,n,i){return e&&e.length>1?(e="="===e[0]?e:"="+e,this._calcEngine.evaluate(e,t,o,n,i)):e},t.prototype._copyTo=function(e){var t,o,n,i=this,r=e.grid.autoGenerateColumns;if(e._storeRowSettings(),n=this.selection.clone(),e.grid.selection=new wjcGrid.CellRange,e.grid.rows.clear(),e.grid.columns.clear(),e.grid.columnHeaders.columns.clear(),e.grid.rowHeaders.rows.clear(),i.itemsSource)e.grid.autoGenerateColumns=!1,e.itemsSource=i.itemsSource,e.grid.collectionView.beginUpdate();else for(e.itemsSource=null,o=0;o<i.rows.length;o++)e.grid.rows.push(i.rows[o]);for(e._sortList=i.sortManager._committedList.slice(),e._getFilterSetting(),t=0;t<i.columns.length;t++)e.grid.columns.push(i.columns[t]);e.grid.collectionView&&(i._resetMappedColumns(e.grid),e.grid.collectionView.endUpdate()),e.grid.autoGenerateColumns=r,e.grid.frozenRows=i.frozenRows,e.grid.frozenColumns=i.frozenColumns,e.grid.allowAddNew=i.allowAddNew,null!=i.newRowAtTop&&(e.grid.newRowAtTop=i.newRowAtTop),e.grid.selection=n,e._scrollPosition=i.scrollPosition,setTimeout(function(){i._setFlexSheetToDirty(),i.refresh(!0)},10)},t.prototype._copyFrom=function(e,t){void 0===t&&(t=!0);var o,n,i,r,l,s,a=this,h=a.autoGenerateColumns;if(a._isCopying=!0,a._dragable=!1,a.itemsSource=null,a.rows.clear(),a.columns.clear(),a.columnHeaders.columns.clear(),a.rowHeaders.rows.clear(),s=e.grid.selection.clone(),a.selection=new wjcGrid.CellRange,e.selectionRanges.length>1&&a.selectionMode===wjcGrid.SelectionMode.CellRange&&(a._enableMulSel=!0),e.itemsSource)a.autoGenerateColumns=!1,a.itemsSource=e.itemsSource,a.collectionView.beginUpdate();else for(n=0;n<e.grid.rows.length;n++)a.rows.push(e.grid.rows[n]);for(a.sortManager.sortDescriptions.sourceCollection=e._sortList.slice(),a.sortManager._committedList=e._sortList.slice(),o=0;o<e.grid.columns.length;o++)(r=e.grid.columns[o]).isRequired=!1,a.columns.push(r);for(a.collectionView&&(a._resetMappedColumns(a),a.collectionView.endUpdate(),a.collectionView.collectionChanged.addHandler(function(t,o){switch(o.action){case wjcCore.NotifyCollectionChangedAction.Add:e._orgItemsSource&&e._orgItemsSource.splice(o.index,0,o.item);break;case wjcCore.NotifyCollectionChangedAction.Remove:e._orgItemsSource&&e._orgItemsSource.splice(e._orgItemsSource.indexOf(o.item),1);break;case wjcCore.NotifyCollectionChangedAction.Reset:setTimeout(function(){a.invalidate()},10)}},a)),a.rows.length&&a.columns.length&&(a.selection=s),e._applyFilterSetting(),n=0;n<a.rows.length;n++)(i=e._rowSettings[n])&&((l=a.rows[n]).height=i.height,l.allowMerging=i.allowMerging,l.visible=i.visible,l instanceof wjcGrid.GroupRow&&(l.isCollapsed=!!i.isCollapsed),l.isSelected=!!i.isSelected,l.isReadOnly=!!i.readOnly);a.autoGenerateColumns=h,a.frozenRows=e.grid.frozenRows,a.frozenColumns=e.grid.frozenColumns,a._isCopying=!1,a._addingSheet?(a._toRefresh&&(clearTimeout(a._toRefresh),a._toRefresh=null),a._toRefresh=setTimeout(function(){a._setFlexSheetToDirty(),a.invalidate()},10),a._addingSheet=!1):t&&a.refresh(),a.scrollPosition=e._scrollPosition,a._ptScrl=e._scrollPosition},t.prototype._resetMappedColumns=function(e){var t,o,n=0;if(e._mappedColumns=null,e.collectionView)for(o=e.collectionView.sortDescriptions;n<o.length;n++)(t=e.columns.getColumn(o[n].property))&&t.dataMap&&(e._mappedColumns||(e._mappedColumns={}),e._mappedColumns[t.binding]=t.dataMap)},t.prototype._loadFromWorkbook=function(e){var t,o,n,i,r=0,l=this;if(null!=e.sheets&&0!==e.sheets.length){if(l.beginUpdate(),l.clear(),l._reservedContent=e.reservedContent,t=e.sheets.length,e.colorThemes&&e.colorThemes.length>0)for(i=0;i<this._colorThemes.length;i++)this._colorThemes[i]=e.colorThemes[i];for(;r<t;r++){if(r>0&&l.addUnboundSheet(),l.selectedSheet.grid.wj_sheetInfo={},wjcGridXlsx.FlexGridXlsxConverter.load(l.selectedSheet.grid,e,{sheetIndex:r,includeColumnHeaders:!1}),l.selectedSheet.name=l.selectedSheet.grid.wj_sheetInfo.name,l.selectedSheet.visible=l.selectedSheet.grid.wj_sheetInfo.visible,l.selectedSheet._styledCells=l.selectedSheet.grid.wj_sheetInfo.styledCells,l.selectedSheet.grid.wj_sheetInfo.mergedRanges)for(n=0;n<l.selectedSheet.grid.wj_sheetInfo.mergedRanges.length;n++)l.selectedSheet._mergedRanges[n]=l.selectedSheet.grid.wj_sheetInfo.mergedRanges[n];if(l._copyFrom(l.selectedSheet,!1),null!=l.selectedSheet.grid.wj_sheetInfo.tables&&l.selectedSheet.grid.wj_sheetInfo.tables.length>0)for(i=0;i<l.selectedSheet.grid.wj_sheetInfo.tables.length;i++)this._parseFromWorkbookTable(l.selectedSheet.grid.wj_sheetInfo.tables[i],l.selectedSheet)}if(null!=e.activeWorksheet&&e.activeWorksheet>-1&&e.activeWorksheet<l.sheets.length?l.selectedSheetIndex=e.activeWorksheet:l.selectedSheetIndex=0,e.definedNames&&e.definedNames.length>0)for(i=0;i<e.definedNames.length;i++)o=e.definedNames[i],l.definedNames.push(new DefinedName(l,o.name,o.value,o.sheetName));l.endUpdate(),l.onLoaded()}},t.prototype._saveToWorkbook=function(){var e,t,o,n,i,r;if(0===this.sheets.length)throw"The flexsheet is empty.";if(n=this.sheets[0],0===this.selectedSheetIndex&&(n._storeRowSettings(),n.itemsSource instanceof wjcCore.CollectionView||this._copyRowsToSelectedSheet()),n._setRowSettings(),n.tables.length>0)for(n.grid.wj_sheetInfo.tables=[],r=0;r<n.tables.length;r++)n.grid.wj_sheetInfo.tables.push(this._parseToWorkbookTable(n.tables[r]));for((e=wjcGridXlsx.FlexGridXlsxConverter.save(n.grid,{sheetName:n.name,sheetVisible:n.visible,includeColumnHeaders:!1})).reservedContent=this._reservedContent,i=1;i<this.sheets.length;i++){if(n=this.sheets[i],this.selectedSheetIndex===i&&(n._storeRowSettings(),n.itemsSource instanceof wjcCore.CollectionView||this._copyRowsToSelectedSheet()),n._setRowSettings(),n.tables.length>0)for(n.grid.wj_sheetInfo.tables=[],r=0;r<n.tables.length;r++)n.grid.wj_sheetInfo.tables.push(this._parseToWorkbookTable(n.tables[r]));t=wjcGridXlsx.FlexGridXlsxConverter.save(n.grid,{sheetName:n.name,sheetVisible:n.visible,includeColumnHeaders:!1}),e._addWorkSheet(t.sheets[0],i)}for(e.activeWorksheet=this.selectedSheetIndex,r=0;r<this.definedNames.length;r++){var l=this.definedNames[r];(o=new wjcXlsx.DefinedName).name=l.name,o.value=l.value,o.sheetName=l.sheetName,e.definedNames.push(o)}if(this._colorThemes&&this._colorThemes.length>0)for(r=0;r<this._colorThemes.length;r++)e.colorThemes[r]=this._colorThemes[r];return e},t.prototype._mouseDown=function(e){var t,o,n,i=window.navigator.userAgent,r=this.hitTest(e);this.columns;if(this.selectedSheet&&(this.selectedSheet._scrollPosition=this.scrollPosition),this._dragable)return this._isDragging=!0,this._draggingMarker=document.createElement("div"),wjcCore.setCss(this._draggingMarker,{position:"absolute",display:"none",borderStyle:"dotted",cursor:"move"}),document.body.appendChild(this._draggingMarker),this._draggingTooltip=new wjcCore.Tooltip,this._draggingCells=this.selection,this.selectedSheet&&this.selectedSheet.selectionRanges.clear(),this.onDraggingRowColumn(new DraggingRowColumnEventArgs(this._draggingRow,e.shiftKey)),void e.preventDefault();if(r.cellType!==wjcGrid.CellType.None&&(this._isClicking=!0),this.selectionMode===wjcGrid.SelectionMode.CellRange?e.ctrlKey?this._enableMulSel||(this._enableMulSel=!0):r.cellType!==wjcGrid.CellType.None&&(this.selectedSheet&&this.selectedSheet.selectionRanges.clear(),this._enableMulSel&&this.refresh(!1),this._enableMulSel=!1):(this._enableMulSel=!1,this.selectedSheet&&this.selectedSheet.selectionRanges.clear()),this._htDown=r,0!==this.rows.length&&0!==this.columns.length&&(i.match(/iPad/i)||i.match(/iPhone/i)||this._contextMenu.hide(),this.selectionMode===wjcGrid.SelectionMode.CellRange)){if(r.cellType===wjcGrid.CellType.RowHeader&&3===e.which)return n=new wjcGrid.CellRange(r.row,0,r.row,this.columns.length-1),void(this.selection.contains(n)||(this.selection=n));if((r.cellType===wjcGrid.CellType.ColumnHeader||r.cellType===wjcGrid.CellType.None)&&!(r.col>-1&&this.columns[r.col].isSelected)&&wjcCore.hasClass(e.target,"wj-cell")&&!r.edgeRight){if(this._columnHeaderClicked=!0,o=this.itemsSource&&this.rows[0]&&!this.rows[0].isVisible?1:0,e.shiftKey)this._multiSelectColumns(r);else{if(t=new wjcGrid.CellRange(o,r.col,this.rows.length-1,r.col),3===e.which&&this.selection.contains(t))return;this.select(t)}this._eCt.children[o]&&this._eCt.children[o].children[r.col]&&this._eCt.children[o].children[r.col].focus()}}},t.prototype._mouseMove=function(e){var t,o=this.hitTest(e),n=this.selection,i=this.rows.length,r=this.columns.length,l=this.hostElement.style.cursor;return 0===this.rows.length||0===this.columns.length?(this._dragable=!1,void(o.cellType===wjcGrid.CellType.Cell&&(this.hostElement.style.cursor="default"))):this._isDragging?(this.hostElement.style.cursor="move",void this._showDraggingMarker(e)):(t=this.itemsSource?0===n.topRow||1===n.topRow:0===n.topRow,n&&o.cellType!==wjcGrid.CellType.None&&!this.itemsSource&&(this._draggingColumn=t&&n.bottomRow===i-1,this._draggingRow=0===n.leftCol&&n.rightCol===r-1,o.cellType===wjcGrid.CellType.Cell?(this._draggingColumn&&((o.col===n.leftCol-1||o.col===n.rightCol)&&o.edgeRight||o.row===i-1&&o.edgeBottom)&&(l="move"),this._draggingRow&&!this._containsGroupRows(n)&&((o.row===n.topRow-1||o.row===n.bottomRow)&&o.edgeBottom||o.col===r-1&&o.edgeRight)&&(l="move")):o.cellType===wjcGrid.CellType.ColumnHeader?o.edgeBottom&&(this._draggingColumn&&o.col>=n.leftCol&&o.col<=n.rightCol?l="move":this._draggingRow&&0===n.topRow&&(l="move")):o.cellType===wjcGrid.CellType.RowHeader&&o.edgeRight&&(this._draggingColumn&&0===n.leftCol?l="move":this._draggingRow&&o.row>=n.topRow&&o.row<=n.bottomRow&&!this._containsGroupRows(n)&&(l="move")),this._dragable="move"===l,this.hostElement.style.cursor=l),void(this._htDown&&this._htDown.panel&&(o=new wjcGrid.HitTestInfo(this._htDown.panel,e),this._multiSelectColumns(o),o.cellType===wjcGrid.CellType.Cell&&this.scrollIntoView(o.row,o.col))))},t.prototype._mouseUp=function(e){try{this._isDragging&&(this._draggingCells.equals(this._dropRange)||(this._handleDropping(e),this.onDroppingRowColumn()))}finally{this._isDragging&&(this._draggingCells=null,this._dropRange=null,document.body.removeChild(this._draggingMarker),this._draggingMarker=null,this._draggingTooltip.hide(),this._draggingTooltip=null,this._isDragging=!1,this._draggingColumn=!1,this._draggingRow=!1),this._htDown&&this._htDown.cellType!==wjcGrid.CellType.None&&this.selectedSheet&&(this._htDown.cellType===wjcGrid.CellType.TopLeft&&this.selectionMode===wjcGrid.SelectionMode.CellRange&&(this.selection=new wjcGrid.CellRange(0,0,this.rows.length-1,this.columns.length-1)),this.selection.isValid&&this.selectedSheet._addSelection(this.selection),this._enableMulSel=!1),this._isClicking=!1,this._columnHeaderClicked=!1,this._htDown=null}},t.prototype._click=function(){var e=this,t=window.navigator.userAgent;t.match(/iPad/i)||t.match(/iPhone/i)||e._contextMenu.hide(),setTimeout(function(){e.hideFunctionList()},200)},t.prototype._touchStart=function(e){var t=this;wjcCore.hasClass(e.target,"wj-context-menu-item")||t._contextMenu.hide(),t._longClickTimer=setTimeout(function(){var o;t._isDescendant(t._divContainer,e.target)&&(o=t.hitTest(e))&&o.cellType!==wjcGrid.CellType.None&&!t._resizing&&(o.cellType===wjcGrid.CellType.TopLeft&&(t.selection=new wjcGrid.CellRange(0,0,t.rows.length-1,t.columns.length-1),t.selectedSheet&&(t.selectedSheet.selectionRanges.clear(),t.selectedSheet.selectionRanges.push(t.selection))),t._contextMenu.show(null,new wjcCore.Point(e.pageX+10,e.pageY+10)))},500)},t.prototype._touchEnd=function(){clearTimeout(this._longClickTimer)},t.prototype._showDraggingMarker=function(e){var o,n,i,r,l,s,a,h,c,d=new wjcGrid.HitTestInfo(this.cells,e),u=this.selection,_=this.columns.length,g=this.rows.length,w=this._cumulativeScrollOffset(this.hostElement),p=this._root.getBoundingClientRect(),f=p.left+w.x,m=p.top+w.y;if(this.scrollIntoView(d.row,d.col),this._draggingColumn){for(n=u.rightCol-u.leftCol+1,l=0,((i=d.col)<0||i+n>_)&&(i=_-n),o=this.cells.getCellBoundingRect(0,i),s=this._root.offsetHeight-this._eCHdr.offsetHeight,r=(r=this.cells.height)>s?s:r,a=0;a<n;a++)l+=this.columns[i+a].renderSize;h=t.convertNumberToAlpha(i)+" : "+t.convertNumberToAlpha(i+n-1),this._dropRange?(this._dropRange.col=i,this._dropRange.col2=i+n-1):this._dropRange=new wjcGrid.CellRange(0,i,this.rows.length-1,i+n-1)}else if(this._draggingRow){for(n=u.bottomRow-u.topRow+1,r=0,((i=d.row)<0||i+n>g)&&(i=g-n),o=this.cells.getCellBoundingRect(i,0),s=this._root.offsetWidth-this._eRHdr.offsetWidth,a=0;a<n;a++)r+=this.rows[i+a].renderSize;l=(l=this.cells.width)>s?s:l,h=i+1+" : "+(i+n),this._dropRange?(this._dropRange.row=i,this._dropRange.row2=i+n-1):this._dropRange=new wjcGrid.CellRange(i,0,i+n-1,this.columns.length-1)}if(o){if(c={display:"inline",zIndex:"9999",opacity:.5,top:o.top-(this._draggingColumn?this._ptScrl.y:0)+w.y,left:o.left-(this._draggingRow?this._ptScrl.x:0)+w.x,height:r,width:l},o.top=o.top-(this._draggingColumn?this._ptScrl.y:0),o.left=o.left-(this._draggingRow?this._ptScrl.x:0),this.rightToLeft&&this._draggingRow&&(c.left=c.left-l+o.width+2*this._ptScrl.x,o.left=o.left+2*this._ptScrl.x),this._draggingRow){if(f+this._eRHdr.offsetWidth!==c.left||m+this._root.offsetHeight+1<c.top+c.height)return}else if(m+this._eCHdr.offsetHeight!==c.top||f+this._root.offsetWidth+1<c.left+c.width)return;wjcCore.setCss(this._draggingMarker,c),this._draggingTooltip.show(this.hostElement,h,o)}},t.prototype._handleDropping=function(e){var t,o,n,i,r,l,s,a=this;if(a.selectedSheet&&a._draggingCells&&a._dropRange&&!a._containsMergedCells(a._draggingCells)&&!a._containsMergedCells(a._dropRange)){if(a._clearCalcEngine(),a._draggingColumn&&a._draggingCells.leftCol>a._dropRange.leftCol||a._draggingRow&&a._draggingCells.topRow>a._dropRange.topRow)if(e.shiftKey){if(!a._allowExchangeCells(a._draggingRow,!0))return void console.warn("Can not complete operation: You are attempting to change a position of table row or column in a way that is not allowed.");if(a._draggingColumn){for(i=a._dropRange.leftCol,o=a._draggingCells.leftCol;o<=a._draggingCells.rightCol;o++)a.columns.moveElement(o,i),i++;a._exchangeTableColumns(!0)}else if(a._draggingRow)for(n=a._dropRange.topRow,t=a._draggingCells.topRow;t<=a._draggingCells.bottomRow;t++)a.rows.moveElement(t,n),n++;a._exchangeCellStyle(!0)}else{for(this.undoStack.stackSize>0&&(r=new _MoveCellsAction(a,a._draggingCells,a._dropRange,e.ctrlKey)),n=a._dropRange.topRow,t=a._draggingCells.topRow;t<=a._draggingCells.bottomRow;t++){for(i=a._dropRange.leftCol,o=a._draggingCells.leftCol;o<=a._draggingCells.rightCol;o++)a._moveCellContent(t,o,n,i,e.ctrlKey),a._draggingColumn&&n===a._dropRange.topRow&&(a.columns[i].dataType=a.columns[o].dataType?a.columns[o].dataType:wjcCore.DataType.Object,a.columns[i].align=a.columns[o].align,a.columns[i].format=a.columns[o].format,e.ctrlKey||(a.columns[o].dataType=wjcCore.DataType.Object,a.columns[o].align=null,a.columns[o].format=null)),i++;n++}if(a._draggingColumn&&!e.ctrlKey)for(i=a._dropRange.leftCol,o=a._draggingCells.leftCol;o<=a._draggingCells.rightCol;o++)a._updateColumnFiler(o,i),i++}else if(a._draggingColumn&&a._draggingCells.leftCol<a._dropRange.leftCol||a._draggingRow&&a._draggingCells.topRow<a._dropRange.topRow)if(e.shiftKey){if(!a._allowExchangeCells(a._draggingRow,!1))return void console.warn("Can not complete operation: You are attempting to change a position of table row or column in a way that is not allowed.");if(a._draggingColumn){for(i=a._dropRange.rightCol,o=a._draggingCells.rightCol;o>=a._draggingCells.leftCol;o--)a.columns.moveElement(o,i),i--;a._exchangeTableColumns(!1)}else if(a._draggingRow)for(n=a._dropRange.bottomRow,t=a._draggingCells.bottomRow;t>=a._draggingCells.topRow;t--)a.rows.moveElement(t,n),n--;a._exchangeCellStyle(!1)}else{for(this.undoStack.stackSize>0&&(r=new _MoveCellsAction(a,a._draggingCells,a._dropRange,e.ctrlKey)),n=a._dropRange.bottomRow,t=a._draggingCells.bottomRow;t>=a._draggingCells.topRow;t--){for(i=a._dropRange.rightCol,o=a._draggingCells.rightCol;o>=a._draggingCells.leftCol;o--)a._moveCellContent(t,o,n,i,e.ctrlKey),a._draggingColumn&&n===a._dropRange.bottomRow&&(a.columns[i].dataType=a.columns[o].dataType?a.columns[o].dataType:wjcCore.DataType.Object,a.columns[i].align=a.columns[o].align,a.columns[i].format=a.columns[o].format,e.ctrlKey||(a.columns[o].dataType=wjcCore.DataType.Object,a.columns[o].align=null,a.columns[o].format=null)),i--;n--}if(a._draggingColumn&&!e.ctrlKey)for(i=a._dropRange.rightCol,o=a._draggingCells.rightCol;o>=a._draggingCells.leftCol;o--)a._updateColumnFiler(o,i),i--}e.ctrlKey||(l=a._updateFormulaForDropping(e.shiftKey),s=a._updateNamedRangesForDropping(e.shiftKey)),r&&r.saveNewState()&&(r._affectedFormulas=l,r._affectedDefinedNameVals=s,a._undoStack._addAction(r)),a._undoStack._pendingAction&&(a._undoStack._pendingAction._affectedFormulas=l,a._undoStack._pendingAction._affectedDefinedNameVals=s),a.select(a._dropRange),a.selectedSheet._addSelection(a.selection),a.hostElement.focus()}},t.prototype._moveCellContent=function(e,t,o,n,i){var r,l,s,a,h,c,d,u,_=this.getCellData(e,t,!1),g=e*this.columns.length+t,w=o*this.columns.length+n,p=this.selectedSheet._styledCells[g],f=!0;if((l=this.selectedSheet.findTable(o,n))&&(d=l.getRange(),u=l.getColumns(),l.showHeaderRow&&o===d.topRow&&(h=u[a=n-d.leftCol].name,null==_||""===_?f=!1:u[a].name=_)),f?this.setCellData(o,n,_):f=!0,p?this.selectedSheet._styledCells[w]=this._cloneObject(p):delete this.selectedSheet._styledCells[w],i)(r=this.selectedSheet.findTable(e,t))&&(c=r.getRange(),r===l&&e===o&&r.showHeaderRow&&e===c.topRow&&(s=t-c.leftCol,r._updateColumnName(s,_)));else{if(delete this.selectedSheet._styledCells[g],r=this.selectedSheet.findTable(e,t)){if(c=r.getRange(),r===l&&e===o&&r.showHeaderRow&&e===c.topRow)return s=t-c.leftCol,void r._updateColumnName(s,h);if(r.showHeaderRow&&e===c.topRow)return}this.setCellData(e,t,null)}},t.prototype._allowExchangeCells=function(e,t){var o,n,i,r,l,s=this.selectedSheet.tables;for(o=0;o<s.length;o++)if(n=s[o],e?(i=n.getRange(TableSection.Data),this._draggingCells.rowSpan,r=new wjcGrid.CellRange(this._draggingCells.topRow,i.leftCol,this._draggingCells.bottomRow,i.rightCol),l=new wjcGrid.CellRange(this._dropRange.topRow,i.leftCol,this._dropRange.bottomRow,i.rightCol)):(i=n.getRange(),this._draggingCells.columnSpan,r=new wjcGrid.CellRange(i.topRow,this._draggingCells.leftCol,i.bottomRow,this._draggingCells.rightCol),l=new wjcGrid.CellRange(i.topRow,this._dropRange.leftCol,i.bottomRow,this._dropRange.rightCol)),i.intersects(r)&&!i.contains(r)||i.intersects(l)&&!i.contains(l)||i.contains(r)&&!i.contains(l)||!i.contains(r)&&i.contains(l))return!1;return!0},t.prototype._exchangeTableColumns=function(e){var t,o,n,i,r,l,s=this.selectedSheet.tables;for(t=0;t<s.length;t++)if(o=s[t],(n=o.getRange()).leftCol<=this._draggingCells.leftCol&&n.rightCol>=this._draggingCells.rightCol)for(i=(e?this._draggingCells.leftCol:this._draggingCells.rightCol)-n.leftCol,r=(e?this._dropRange.leftCol:this._dropRange.rightCol)-n.leftCol,l=0;l<this._draggingCells.columnSpan;l++)o._moveColumns(i,r),e?(i++,r++):(i--,r--)},t.prototype._exchangeCellStyle=function(e){var t,o,n,i,r,l=0,s=[];for(t=this._draggingCells.topRow;t<=this._draggingCells.bottomRow;t++)for(o=this._draggingCells.leftCol;o<=this._draggingCells.rightCol;o++)n=t*this.columns.length+o,this.selectedSheet._styledCells[n]?(s.push(this._cloneObject(this.selectedSheet._styledCells[n])),delete this.selectedSheet._styledCells[n]):s.push(void 0);if(e){if(this._draggingColumn)for(r=this._draggingCells.rightCol-this._draggingCells.leftCol+1,o=this._draggingCells.leftCol-1;o>=this._dropRange.leftCol;o--)for(t=0;t<this.rows.length;t++)n=t*this.columns.length+o,i=t*this.columns.length+o+r,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];else if(this._draggingRow)for(r=this._draggingCells.bottomRow-this._draggingCells.topRow+1,t=this._draggingCells.topRow-1;t>=this._dropRange.topRow;t--)for(o=0;o<this.columns.length;o++)n=t*this.columns.length+o,i=(t+r)*this.columns.length+o,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i]}else if(this._draggingColumn)for(r=this._draggingCells.rightCol-this._draggingCells.leftCol+1,o=this._draggingCells.rightCol+1;o<=this._dropRange.rightCol;o++)for(t=0;t<this.rows.length;t++)n=t*this.columns.length+o,i=t*this.columns.length+o-r,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];else if(this._draggingRow)for(r=this._draggingCells.bottomRow-this._draggingCells.topRow+1,t=this._draggingCells.bottomRow+1;t<=this._dropRange.bottomRow;t++)for(o=0;o<this.columns.length;o++)n=t*this.columns.length+o,i=(t-r)*this.columns.length+o,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];for(t=this._dropRange.topRow;t<=this._dropRange.bottomRow;t++)for(o=this._dropRange.leftCol;o<=this._dropRange.rightCol;o++)n=t*this.columns.length+o,s[l]?this.selectedSheet._styledCells[n]=s[l]:delete this.selectedSheet._styledCells[n],l++},t.prototype._containsMergedCells=function(e,t){var o,n,i,r,l;if(t=t||this.selectedSheet,l=t===this.selectedSheet?this:t.grid,!t)return!1;for(o=e.topRow;o<=e.bottomRow;o++)for(n=e.leftCol;n<=e.rightCol;n++)if(i=o*l.columns.length+n,(r=t._mergedRanges[i])&&r.isValid&&!r.isSingleCell)return!0;return!1},t.prototype._multiSelectColumns=function(e){var t;e&&this._columnHeaderClicked&&((t=new wjcGrid.CellRange(e.row,e.col)).row=this.itemsSource&&this.rows[0]&&!this.rows[0].isVisible?1:0,t.row2=this.rows.length-1,t.col2=this.selection.col2,this.select(t))},t.prototype._cumulativeOffset=function(e){var t=0,o=0;do{t+=e.offsetTop||0,o+=e.offsetLeft||0,e=e.offsetParent}while(e);return new wjcCore.Point(o,t)},t.prototype._cumulativeScrollOffset=function(e){var t=0,o=0;do{t+=e.scrollTop||0,o+=e.scrollLeft||0,e=e.offsetParent}while(e&&!(e instanceof HTMLBodyElement));return t+=document.body.scrollTop||document.documentElement.scrollTop,o+=document.body.scrollLeft||document.documentElement.scrollLeft,new wjcCore.Point(o,t)},t.prototype._checkHitWithinSelection=function(e){var t;if(null!=e&&e.cellType===wjcGrid.CellType.Cell){if((t=this.getMergedRange(this.cells,e.row,e.col))&&t.contains(this.selection))return!0;if(this.selection.row===e.row&&this.selection.col===e.col)return!0}return!1},t.prototype._clearForEmptySheet=function(e){this.selectedSheet&&0===this[e].length&&!0!==this._isCopying&&!0!==this._isUndoing&&!0!==this._isSorting&&(this.selectedSheet._mergedRanges.length=0,this.selectedSheet._styledCells=null,this.select(new wjcGrid.CellRange))},t.prototype._containsGroupRows=function(e){var t;for(t=e.topRow;t<=e.bottomRow;t++)if(this.rows[t]instanceof wjcGrid.GroupRow)return!0;return!1},t.prototype._delSeletionContent=function(e){var t,o,n,i,r,l,s,a,h,c,d=this.selectedSheet.selectionRanges.slice(),u=!1,_=new _EditAction(this),g=this.editableCollectionView,w=!1,p=this.scrollPosition;if(!this.isReadOnly)if(this.allowDelete&&this.selection.isValid&&0===this.selection.leftCol&&this.selection.rightCol===this.columns.length-1)this.deleteRows(this.selection.topRow,this.selection.rowSpan);else{for(this.beginUpdate(),this.undoStack.stackSize>0&&(_=new _EditAction(this)),null!=d&&0!==d.length||(d=[this.selection]),n=0;n<d.length;n++){if(t=d[n],o=new wjcGrid.CellRange,h=new wjcGrid.CellEditEndingEventArgs(this.cells,o,e),this.selectedSheet.tables.length>0)for(l=0;l<this.selectedSheet.tables.length;l++)s=this.selectedSheet.tables[l],t.contains(s.getRange())&&(_&&_._storeDeletedTables(s),this.selectedSheet.tables.remove(s));for(r=t.topRow;r<=t.bottomRow;r++)if((c=this.rows[r])&&!c.isReadOnly)for(i=t.leftCol;i<=t.rightCol;i++)(!(a=this._getBindingColumn(this.cells,r,this.columns[i])).isReadOnly&&!1===a.isRequired||null==a.isRequired&&a.dataType==wjcCore.DataType.String)&&this.getCellData(r,i,!0)&&(o.setRange(r,i),h.cancel=!1,this.onBeginningEdit(h)&&(g&&(w||(w=!0,g.beginUpdate()),g.editItem(c.dataItem),this._edtHdl._edItem=g.currentEditItem),this.setCellData(r,i,"",!0),u=!0,this.onCellEditEnding(h),this.onCellEditEnded(h)));w&&(g.endUpdate(),t.rowSpan>1&&g.commitEdit())}u&&_&&(_.saveNewState(),this._undoStack._addAction(_)),this.selection=t,this.scrollPosition=p,this.endUpdate()}},t.prototype._updateAffectedFormula=function(e,t,o,n){var i,r,l,s,a,h,c,d,u,_=[],g=[],w=this.selection.clone();for(this.selectedSheet._storeRowSettings(),this.beginUpdate(),i=0;i<this.sheets.length;i++)for(l=(r=this.sheets[i]).grid,s=0;s<l.rows.length;s++)for(a=0;a<l.columns.length;a++)if((d=l.getCellData(s,a,!1))&&wjcCore.isString(d)&&"="===d[0]&&(u=this._updateCellRef(d,i,e,t,o,n))){if(_.push({sheet:r,point:new wjcCore.Point(s,a),formula:d}),h=s,c=a,i===this.selectedSheetIndex&&(n?s>=e&&(o?h+=t:h-=t):a>=e&&(o?c+=t:c-=t),!o&&(n&&s<=e&&s>=e-t+1||!n&&a<=e&&a>=e-t+1)))continue;l.setCellData(s,a,u,!1),g.push({sheet:r,point:new wjcCore.Point(h,c),formula:u})}return this.selection=w,this.endUpdate(),{oldFormulas:_,newFormulas:g}},t.prototype._updateAffectedNamedRanges=function(e,t,o,n){var i,r,l,s,a=[],h=[];for(i=0;i<this.definedNames.length;i++)(l=(r=this.definedNames[i]).value)&&wjcCore.isString(l)&&(s=this._updateCellRef(l,this.selectedSheetIndex,e,t,o,n))&&(a.push({name:r.name,value:l}),r.value=s,h.push({name:r.name,value:s}));return{oldDefinedNameVals:a,newDefinedNameVals:h}},t.prototype._updateColumnFiler=function(e,t){for(var o=JSON.parse(this._filter.filterDefinition),n=0;n<o.filters.length;n++){var i=o.filters[n];if(i.columnIndex===e){i.columnIndex=t;break}}this._filter.filterDefinition=JSON.stringify(o)},t.prototype._isDescendant=function(e,t){for(var o=t.parentNode;null!=o;){if(o===e)return!0;o=o.parentNode}return!1},t.prototype._clearCalcEngine=function(){this._calcEngine._clearExpressionCache()},t.prototype._getRangeString=function(e,t,o){void 0===o&&(o=!0);var n,i,r,l,s,a="",h=!0,c=t.grid;if(wjcCore.isArray(e))if(e.length>1){if(this._isMultipleRowsSelected(e,t)){for(a="",i=0;i<e.length;i++)a&&(a+="\n"),a+=this._getRangeString(e[i],t);return a}if(!this._isMultipleColumnsSelected(e,t))return"";for(a="",n=0,h=!0;n<c.rows.length;n++){for(h||(a+="\n"),h=!1,i=0,g=!0;i<e.length;i++)(r=e[i].clone()).row=r.row2=n,g||(a+="\t"),g=!1,a+=this._getRangeString(e[i],t);return a}}else switch(s=e[0],this.selectionMode){case wjcGrid.SelectionMode.Row:case wjcGrid.SelectionMode.RowRange:s.col=0,s.col2=t.grid.columns.length-1;break;case wjcGrid.SelectionMode.ListBox:s.col=0,s.col2=t.grid.columns.length-1;for(var d=0;d<t.grid.rows.length;d++)t.grid.rows[d].isSelected&&t.grid.rows[d].isVisible&&(s.row=s.row2=d,a&&(a+="\n"),a+=this._getRangeString(s,t));return a}for(var u=(s=wjcCore.asType(wjcCore.isArray(e)?e[0]:e,wjcGrid.CellRange)).topRow;u<=s.bottomRow;u++)if(c.rows[u]&&c.rows[u].isVisible){h||(a+="\n"),h=!1;for(var _=s.leftCol,g=!0;_<=s.rightCol;_++)if(c.columns[_]&&c.columns[_].isVisible){g||(a+="\t"),g=!1;var w=this._getCellStyle(u,_,t),p=w?w.format:"",f=c.columns[_];o?(l=c.getCellData(u,_,!1),wjcCore.isString(l)&&"="===l[0]&&(l=this._evaluate(l,p,t,u,_)),l=this._formatEvaluatedResult(l,f,p)):(l=c.getCellData(u,_,!1),wjcCore.isDate(l)&&(l=wjcCore.Globalize.format(l,f.format)),f.dataMap&&(l=f.dataMap.getDisplayValue(l))),(l=(l=null==l?"":l.toString()).replace(/\t/g," ")).indexOf("\n")>-1&&(l='"'+l.replace(/"/g,'""')+'"'),a+=l}}return a},t.prototype._getSelectionForListBoxMode=function(e){for(var t,o=0;o<e.rows.length;o++)e.rows[o].isSelected&&(t?t.row2=o:t=new wjcGrid.CellRange(o,0,o,e.columns.length-1));return t},t.prototype._containsRandFormula=function(e,t){for(var o=0;o<e.length;o++)for(var n=e[o],i=n.topRow;i<=n.bottomRow&&i<t.grid.rows.length;i++)for(var r=n.leftCol;r<=n.rightCol&&r<t.grid.columns.length;r++){var l=t.grid.getCellData(i,r,!1);if(wjcCore.isString(l)&&"="===l[0]&&-1!==l.search(/rand/i))return!0}return!1},t.prototype._isMultipleRowsSelected=function(e,t){var o,n,i;e&&e.length>1?i=e:this.selectedSheet.selectionRanges.length>1&&(i=this.selectedSheet.selectionRanges),o=i[0];for(var r=1;r<i.length;r++)if((n=i[r]).leftCol!==o.leftCol||n.rightCol!==o.rightCol)return!1;return!0},t.prototype._isMultipleColumnsSelected=function(e,t){var o,n,i;e&&e.length>1?i=e:this.selectedSheet.selectionRanges.length>1&&(i=this.selectedSheet.selectionRanges),o=i[0];for(var r=0;r<i.length;r++)if((n=i[r]).topRow!==o.topRow||n.bottomRow!==o.bottomRow)return!1;return!0},t.prototype._postSetClipStringProcess=function(e,t,o,n,i,r){var l,s,a,h,c,d=!1;return n>=0&&i>=0&&this._copiedSheet&&(l=this._copiedSheet._getMergedRange(n,i))&&l.topRow===n&&l.leftCol===i&&(s=(s=t+l.rowSpan-1)<this.rows.length?s:this.rows.length-1,a=(a=o+l.columnSpan-1)<this.columns.length?a:this.columns.length-1,this.mergeRange(new wjcGrid.CellRange(t,o,s,a),!0)),h=new wjcGrid.CellRangeEventArgs(this.cells,new wjcGrid.CellRange(t,o),e),this.onPastingCell(h)&&this.cells.setCellData(t,o,h.data)&&(wjcCore.isString(h.data)&&(c=h.data.match(/\n/g))&&c.length>0&&(r?r.whiteSpace="pre":r={whiteSpace:"pre"},this.rows[t].height=this.rows.defaultSize*(c.length+1)),r&&this._applyStyleForCell(t,o,r),this.onPastedCell(h),d=!0),d},t.prototype._delCutData=function(e,t){var o,n,i,r,l=this._copiedSheet===this.selectedSheet?this:this._copiedSheet.grid;for(o=(r=this.selectionMode===wjcGrid.SelectionMode.ListBox?this._getSelectionForListBoxMode(l):this._copiedRanges[0]).topRow;o<=r.bottomRow;o++)if(null!=l.rows[o])for(n=r.leftCol;n<=r.rightCol;n++)(this._copiedSheet!==this.selectedSheet||o<this.selection.topRow||o>this.selection.topRow+e||n<this.selection.leftCol||n>this.selection.leftCol+t)&&(0==(i=l._getBindingColumn(l.cells,o,l.columns[n])).isRequired||null==i.isRequired&&i.dataType==wjcCore.DataType.String)&&l.getCellData(o,n,!0)&&l.setCellData(o,n,"",!0)},t.prototype._containsMultiLineText=function(e){for(var t=0;t<e.length;t++)for(var o=e[t],n=0;n<o.length;n++)if(o[n].indexOf("\n")>=0)return!0;return!1},t.prototype._sortByRow=function(e,t){return e.topRow>t.topRow?1:e.topRow<t.topRow?-1:0},t.prototype._sortByColumn=function(e,t){return e.leftCol>t.leftCol?1:e.leftCol<t.leftCol?-1:0},t.prototype._setFlexSheetToDirty=function(){this.columns._dirty=!0,this.rows._dirty=!0,this.rowHeaders.columns._dirty=!0,this.rowHeaders.rows._dirty=!0,this.columnHeaders.columns._dirty=!0,this.columnHeaders.rows._dirty=!0},t.convertNumberToAlpha=function(e){var t,o,n="";if(e>=0)do{t=Math.floor(e/26),o=e%26,n=String.fromCharCode(o+65)+n,e=t-1}while(t);return n},t.prototype._updateFormulaForReorderingRows=function(e,t,o){void 0===o&&(o=!1);var n,i,r=o?e-t:t-e;this.beginUpdate();for(var l=0;l<this.columns.length;l++)if((n=this.getCellData(t,l,!1))&&"string"==typeof n&&"="===n[0]&&0!==r){try{i=this._calcEngine._parse(n)}catch(e){continue}i._updateCellRangeExpForReorderingRows(r)&&this.setCellData(t,l,"="+i._getStringExpression())}this.endUpdate()},t.prototype._updateFormulaForDropping=function(e){var t,o,n,i,r,l,s,a,h,c=[],d=[];for(this.beginUpdate(),n=0;n<this.sheets.length;n++)for(o=(t=this.sheets[n]).grid,i=0;i<o.rows.length;i++)for(l=0;l<o.columns.length;l++)(a=o.getCellData(i,l,!1))&&"string"==typeof a&&"="===a[0]&&(h=this._updateCellRefForDropping(a,n,e))&&(o.setCellData(i,l,h,!1),e&&n===this.selectedSheetIndex?(r=o.rows[i],s=o.columns[l],c.push({sheet:t,row:r,column:s,formula:a}),d.push({sheet:t,row:r,column:s,formula:h})):(c.push({sheet:t,point:new wjcCore.Point(i,l),formula:a}),d.push({sheet:t,point:new wjcCore.Point(i,l),formula:h})));return this.endUpdate(),{oldFormulas:c,newFormulas:d}},t.prototype._updateNamedRangesForDropping=function(e){var t,o,n,i,r=[],l=[];for(t=0;t<this.definedNames.length;t++)(n=(o=this.definedNames[t]).value)&&wjcCore.isString(n)&&(i=this._updateCellRefForDropping(n,this.selectedSheetIndex,e))&&(r.push({name:o.name,value:n}),o.value=i,l.push({name:o.name,value:i}));return{oldDefinedNameVals:r,newDefinedNameVals:l}},t.prototype._updateCellRefForDropping=function(e,t,o){void 0===o&&(o=!1);var n;try{n=this._calcEngine._parse(e)}catch(e){return null}return n._moveCellRangeExp(t,this._draggingCells,this._dropRange,o)?"="+n._getStringExpression():null},t.prototype._updateCellStyleForReorderingRows=function(e,t,o){var n,i,r=this.columns.length;for(n=0;n<r;n++)(i=this._getCellStyle(e,n))&&(o[t*r+n]=i)},t.prototype._scanFormulas=function(){for(var e=[],t=0;t<this.rows.length;t++)for(var o=0;o<this.columns.length;o++){var n=this.getCellData(t,o,!1);n&&wjcCore.isString(n)&&"="===n[0]&&e.push({row:t,column:o,formula:n})}return e},t.prototype._resetFormulas=function(e){var t=this;e&&t.deferUpdate(function(){for(var o=0;o<e.length;o++){var n=e[o];t.setCellData(n.row,n.column,n.formula)}})},t.prototype._getCellStyle=function(e,t,o){return(o=o||this.selectedSheet)?o.getCellStyle(e,t):null},t.prototype._validateSheetName=function(e){for(var t=0;t<this.sheets.length;t++)if(this.sheets[t].name===e)return!0;return!1},t.prototype._checkExistDefinedName=function(e,t,o){void 0===o&&(o=-1);for(var n=0;n<this.definedNames.length;n++)if(this.definedNames[n].name===e&&this.definedNames[n].sheetName===t&&n!==o)return!0;return!1},t.prototype._updateDefinedNameWithSheetRefUpdating=function(e,t){for(var o,n,i,r=0;r<this.definedNames.length;r++)if((o=this.definedNames[r]).sheetName===e&&null!=o.sheetName&&(o._sheetName=t),(n=o.value.match(/(\w+)\!\$?[A-Za-z]+\$?\d+/g))&&n.length>0)for(var l=0;l<n.length;l++)(i=n[l]).substring(0,i.indexOf("!"))===e&&(o.value=o.value.replace(i,i.replace(e,t)))},t.prototype._updateFormulasWithNameUpdating=function(e,t,o){void 0===o&&(o=!1);var n,i,r,l,s,a,h,c,d,u,_=this.selection.clone(),g=!1;for(u=o?/\[/:/\w/,this.selectedSheet._storeRowSettings(),this.beginUpdate(),n=0;n<this.sheets.length;n++)for(l=this.sheets[n].grid,i=0;i<l.rows.length;i++)for(r=0;r<l.columns.length;r++)if((s=l.getCellData(i,r,!1))&&"string"==typeof s&&"="===s[0]){for(g=!1,a=s.indexOf(e),d=new RegExp(e,"g");a>-1;)h="",c="",a>0&&(h=s[a-1]),a+e.length<s.length&&(c=s[a+e.length]),!/\w/.test(h)&&(o&&u.test(c)||!o&&!u.test(c))&&(s=s.replace(d,function(o,n){return n===a?t:e}),g=!0),a=s.indexOf(e,a+e.length);g&&l.setCellData(i,r,s,!1)}this.selection=_,this.endUpdate()},t.prototype._getDefinedNameIndexByName=function(e){for(var t=0;t<this.definedNames.length;t++)if(this.definedNames[t].name===e)return t;return-1},t.prototype._updateTablesForUpdatingRow=function(e,t,o){var n,i,r,l,s;if(this.selectedSheet.tables.length>0)for(n=this.selectedSheet.tables.length-1;n>=0;n--)if(i=this.selectedSheet.tables[n],r=i.getRange(),o)if((l=e+t-1)<r.topRow)i._updateTableRange(-t,-t,0,0);else if(l>=r.topRow&&l<=r.bottomRow)if(e<r.topRow)i.showHeaderRow&&(i._showHeaderRow=!1),i._updateTableRange(e-r.topRow,-t,0,0);else{if(e===r.topRow&&t===r.rowSpan){null==s&&(s=[]),s.push(i),this.selectedSheet.tables.remove(i);continue}e===r.topRow&&i.showHeaderRow&&(i._showHeaderRow=!1),l===r.bottomRow&&i.showTotalRow&&(i._showTotalRow=!1),i._updateTableRange(0,-t,0,0)}else e<=r.topRow?(null==s&&(s=[]),s.push(i),this.selectedSheet.tables.remove(i)):e<=r.bottomRow&&(i.showTotalRow&&(i._showTotalRow=!1),i._updateTableRange(0,e-r.bottomRow-1,0,0));else e<=r.topRow?i._updateTableRange(t,t,0,0):e>r.topRow&&e<=r.bottomRow&&i._updateTableRange(0,t,0,0);return s},t.prototype._updateTablesForUpdatingColumn=function(e,t,o){var n,i,r,l,s,a,h,c;if(this.selectedSheet.tables.length>0)for(n=this.selectedSheet.tables.length-1;n>=0;n--)if(i=this.selectedSheet.tables[n],r=i.getRange(),o)if((l=e+t-1)<r.leftCol)i._updateTableRange(0,0,-t,-t);else if(l>=r.leftCol&&l<=r.rightCol){if(e<r.leftCol)s=t-r.leftCol+e,a=r.leftCol,i._updateTableRange(0,0,e-r.leftCol,-t);else{if(e===r.leftCol&&t===r.columnSpan){null==c&&(c=[]),c.push(i),this.selectedSheet.tables.remove(i);continue}s=t,a=e,i._updateTableRange(0,0,0,-s)}i._columns.splice(a-r.leftCol,s)}else e<=r.leftCol?(null==c&&(c=[]),c.push(i),this.selectedSheet.tables.remove(i)):e<=r.rightCol&&(s=r.rightCol-e+1,i._updateTableRange(0,0,0,-s),i._columns.splice(e,s));else if(e<=r.leftCol)i._updateTableRange(0,0,t,t);else if(e>r.leftCol&&e<=r.rightCol)for(i._updateTableRange(0,0,0,t),a=e-r.leftCol,h=0;h<t;h++)i._addColumn(a+h);return c},t.prototype._isDisableDeleteRow=function(e,t){var o,n,i;if(this.selectedSheet.tables.length>0)for(o=0;o<this.selectedSheet.tables.length;o++)if(n=this.selectedSheet.tables[o],i=n.getRange(),n.showHeaderRow&&i.topRow>=e&&i.topRow<=t)return!0;return!1},t.prototype._copy=function(t,o){var n,i;if("columns"==t){if(e.prototype._copy.call(this,t,o),this.itemsSource&&(n=this.rows[0])instanceof HeaderRow){n._ubv=null,n._ubv={};for(var r=0;r<this.columns.length;r++)i=this.columns[r],n._ubv[i._hash]=i.header}return!0}return!1},t.prototype._getTableSheetIndex=function(e,t){this.sheets;for(var o=0;o<e.length;o++)if(e[o].indexOf(t)>-1)return o;return-1},t.prototype._sheetSortConverter=function(t,o,n,i){return n=e.prototype._sortConverter.call(this,t,o,n,i),wjcCore.isString(n)&&n.length>0&&"="===n[0]&&(n=this.evaluate(n)),n},t.prototype._formatEvaluatedResult=function(e,t,o){return wjcCore.isPrimitive(e)?(t.dataMap&&(e=t.dataMap.getDisplayValue(e)),!wjcCore.isInt(e)||t.format||t.dataMap||o?((o||t.format)&&wjcCore.isString(e)&&(+e).toString()===e&&(e=+e),e=null!=e?wjcCore.Globalize.format(e,o||t.format):""):e=e.toString()):e&&(!wjcCore.isInt(e.value)||t.format||t.dataMap||o||e.format?(wjcCore.isString(e.value)&&(+e.value).toString()===e.value&&(e.value=+e.value),e=null!=e.value?wjcCore.Globalize.format(e.value,o||e.format||t.format):""):e=e.value.toString()),e},t.prototype._updateCellRef=function(e,t,o,n,i,r){var l;try{l=this._calcEngine._parse(e)}catch(e){return null}return l._updateCellRangeExp(t,o,n,i,r)?"="+l._getStringExpression():null},t.prototype._copyRowsToSelectedSheet=function(){var e,t=this;if(t.selectedSheet){for(t.selectedSheet.grid.rows.clear(),e=0;e<t.rows.length;e++)t.selectedSheet.grid.rows.push(t.rows[e]);setTimeout(function(){t._setFlexSheetToDirty(),t.invalidate()},10)}},t.prototype._copyColumnsToSelectedSheet=function(){var e,t=this;if(t.selectedSheet){for(t.selectedSheet.grid.columns.clear(),e=0;e<t.columns.length;e++)t.selectedSheet.grid.columns.push(t.columns[e]);setTimeout(function(){t._setFlexSheetToDirty(),t.invalidate()},10)}},t.prototype._getUniqueColumnName=function(){for(var e=1;null!=this.columns.getColumn("col"+e);)e++;return"col"+e},t.prototype._parseFromWorkbookTable=function(e,t){var o,n,i,r,l,s,a,h,c,d,u,_=t===this.selectedSheet?this:t.grid;if(n=e.range.split(":"),i=n[0],r=n[1],l=wjcXlsx.Workbook.tableAddress(i),o=new wjcGrid.CellRange(l.row,l.col),s=wjcXlsx.Workbook.tableAddress(r),o.row2=s.row,o.col2=s.col,o.bottomRow>=t.rowCount)for(u=o.bottomRow-t.rowCount+1,g=0;g<u;g++)_.rows.push(new wjcGrid.Row);if(o.rightCol>=t.columnCount)for(u=o.rightCol-t.columnCount+1,g=0;g<u;g++)_.columns.push(new wjcGrid.Column);if(e.columns&&e.columns.length>0){a=[];for(var g=0;g<e.columns.length;g++)h=e.columns[g],a[g]=new TableColumn(h.name,h.totalRowLabel,h.totalRowFunction,h.showFilterButton)}return null!=e.style&&(c=this._isBuiltInStyleName(e.style.name)?this.getBuiltInTableStyle(e.style.name):this._parseFromWorkbookTableStyle(e.style)),d=new Table(e.name,o,c,a,{showHeaderRow:e.showHeaderRow,showTotalRow:e.showTotalRow,showBandedColumns:e.showBandedColumns,showBandedRows:e.showBandedRows,alterFirstColumn:e.alterFirstColumn,alterLastColumn:e.alterLastColumn}),t.tables.push(d),d},t.prototype._parseFromWorkbookTableStyle=function(e){var t=new TableStyle(e.name);return null!=e.firstBandedColumnStyle&&(t.firstBandedColumnStyle=this._parseFromWorkbookTableStyleElement(e.firstBandedColumnStyle)),null!=e.firstBandedRowStyle&&(t.firstBandedRowStyle=this._parseFromWorkbookTableStyleElement(e.firstBandedRowStyle)),null!=e.firstColumnStyle&&(t.firstColumnStyle=this._parseFromWorkbookTableStyleElement(e.firstColumnStyle)),null!=e.firstHeaderCellStyle&&(t.firstHeaderCellStyle=this._parseFromWorkbookTableStyleElement(e.firstHeaderCellStyle)),null!=e.firstTotalCellStyle&&(t.firstTotalCellStyle=this._parseFromWorkbookTableStyleElement(e.firstTotalCellStyle)),null!=e.headerRowStyle&&(t.headerRowStyle=this._parseFromWorkbookTableStyleElement(e.headerRowStyle)),null!=e.lastColumnStyle&&(t.lastColumnStyle=this._parseFromWorkbookTableStyleElement(e.lastColumnStyle)),null!=e.lastHeaderCellStyle&&(t.lastHeaderCellStyle=this._parseFromWorkbookTableStyleElement(e.lastHeaderCellStyle)),null!=e.lastTotalCellStyle&&(t.lastTotalCellStyle=this._parseFromWorkbookTableStyleElement(e.lastTotalCellStyle)),null!=e.secondBandedColumnStyle&&(t.secondBandedColumnStyle=this._parseFromWorkbookTableStyleElement(e.secondBandedColumnStyle)),null!=e.secondBandedRowStyle&&(t.secondBandedRowStyle=this._parseFromWorkbookTableStyleElement(e.secondBandedRowStyle)),null!=e.totalRowStyle&&(t.totalRowStyle=this._parseFromWorkbookTableStyleElement(e.totalRowStyle)),null!=e.wholeTableStyle&&(t.wholeTableStyle=this._parseFromWorkbookTableStyleElement(e.wholeTableStyle)),t},t.prototype._parseFromWorkbookTableStyleElement=function(e){var t;return t={fontWeight:e.font&&e.font.bold?"bold":"none",fontStyle:e.font&&e.font.italic?"italic":"none",textDecoration:e.font&&e.font.underline?"underline":"none",fontFamily:e.font&&e.font.family?e.font.family:"",fontSize:e.font&&e.font.size?e.font.size+"px":"",color:e.font&&e.font.color?e.font.color:"",backgroundColor:e.fill&&e.fill.color?e.fill.color:""},e.borders&&(e.borders.left&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.left.style,"Left",t),t.borderLeftColor=e.borders.left.color),e.borders.right&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.right.style,"Right",t),t.borderRightColor=e.borders.right.color),e.borders.top&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.top.style,"Top",t),t.borderTopColor=e.borders.top.color),e.borders.bottom&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.bottom.style,"Bottom",t),t.borderBottomColor=e.borders.bottom.color),e.borders.vertical&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.vertical.style,"Vertical",t),t.borderVerticalColor=e.borders.vertical.color),e.borders.horizontal&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.horizontal.style,"Horizontal",t),t.borderHorizontalColor=e.borders.horizontal.color)),null!=e.size&&(t.size=e.size),t},t.prototype._parseToWorkbookTable=function(e){var t,o,n=new wjcXlsx.WorkbookTable,i=e.getRange(),r=e.getColumns();n.name=e.name,t=wjcXlsx.Workbook.xlsxAddress(i.topRow,i.leftCol),o=wjcXlsx.Workbook.xlsxAddress(i.bottomRow,i.rightCol),n.range=t+":"+o,null!=e.style&&(e.style.isBuiltIn?(n.style=new wjcXlsx.WorkbookTableStyle,n.style.name=e.style.name):n.style=this._parseToWorkbookTableStyle(e.style)),n.showBandedColumns=e.showBandedColumns,n.showBandedRows=e.showBandedRows,n.showHeaderRow=e.showHeaderRow,n.showTotalRow=e.showTotalRow,n.alterFirstColumn=e.alterFirstColumn,n.alterLastColumn=e.alterLastColumn;for(var l=0;l<r.length;l++){var s=r[l],a=new wjcXlsx.WorkbookTableColumn;a.name=s.name,a.totalRowLabel=s.totalRowLabel,a.totalRowFunction=s.totalRowFunction,a.showFilterButton=s.showFilterButton,n.columns.push(a)}return n},t.prototype._parseToWorkbookTableStyle=function(e){var t=new wjcXlsx.WorkbookTableStyle;return t.name=e.name,null!=e.firstBandedColumnStyle&&(t.firstBandedColumnStyle=this._parseToWorkbookTableStyleElement(e.firstBandedColumnStyle,!0)),null!=e.firstBandedRowStyle&&(t.firstBandedRowStyle=this._parseToWorkbookTableStyleElement(e.firstBandedRowStyle,!0)),null!=e.firstColumnStyle&&(t.firstColumnStyle=this._parseToWorkbookTableStyleElement(e.firstColumnStyle)),null!=e.firstHeaderCellStyle&&(t.firstHeaderCellStyle=this._parseToWorkbookTableStyleElement(e.firstHeaderCellStyle)),null!=e.firstTotalCellStyle&&(t.firstTotalCellStyle=this._parseToWorkbookTableStyleElement(e.firstTotalCellStyle)),null!=e.headerRowStyle&&(t.headerRowStyle=this._parseToWorkbookTableStyleElement(e.headerRowStyle)),null!=e.lastColumnStyle&&(t.lastColumnStyle=this._parseToWorkbookTableStyleElement(e.lastColumnStyle)),null!=e.lastHeaderCellStyle&&(t.lastHeaderCellStyle=this._parseToWorkbookTableStyleElement(e.lastHeaderCellStyle)),null!=e.lastTotalCellStyle&&(t.lastTotalCellStyle=this._parseToWorkbookTableStyleElement(e.lastTotalCellStyle)),null!=e.secondBandedColumnStyle&&(t.secondBandedColumnStyle=this._parseToWorkbookTableStyleElement(e.secondBandedColumnStyle,!0)),null!=e.secondBandedRowStyle&&(t.secondBandedRowStyle=this._parseToWorkbookTableStyleElement(e.secondBandedRowStyle,!0)),null!=e.totalRowStyle&&(t.totalRowStyle=this._parseToWorkbookTableStyleElement(e.totalRowStyle)),null!=e.wholeTableStyle&&(t.wholeTableStyle=this._parseToWorkbookTableStyleElement(e.wholeTableStyle)),t},t.prototype._parseToWorkbookTableStyleElement=function(e,t){void 0===t&&(t=!1);var o,n=wjcGridXlsx.FlexGridXlsxConverter._parseCellStyle(e,!0);return t?(o=new wjcXlsx.WorkbookTableBandedStyle).size=e.size:o=new wjcXlsx.WorkbookTableCommonStyle,o._deserialize(n),o},t.prototype._isBuiltInStyleName=function(e){var t;if(0===e.search(/TableStyleLight/i)){if(t=+e.substring(15),!isNaN(t)&&t>=1&&t<=21)return!0}else if(0===e.search(/TableStyleMedium/i)){if(t=+e.substring(16),!isNaN(t)&&t>=1&&t<=28)return!0}else if(0===e.search(/TableStyleDark/i)&&(t=+e.substring(14),!isNaN(t)&&t>=1&&t<=11))return!0;return!1},t.prototype._getTable=function(e){for(var t,o,n,i=0;i<this.sheets.length;i++)for(o=this.sheets[i].tables,n=0;n<o.length;n++)if((t=o[n]).name.toLowerCase()===e.toLowerCase())return t;return null},t.prototype._isTableColumnRef=function(e,t){return new RegExp("\\[(\\s*@)?"+t+"\\]","i").test(e)},t.prototype._getThemeColor=function(e,t){var o,n,i=this._colorThemes[e];return null!=t?(o=new wjcCore.Color("#"+i),n=o.getHsl(),n[2]=t<0?n[2]*(1+t):n[2]*(1-t)+(1-1*(1-t)),(o=wjcCore.Color.fromHsl(n[0],n[1],n[2])).toString()):"#"+i},t.prototype._createBuiltInTableStyle=function(e){var t;if(0===e.search(/TableStyleLight/i)){if(t=+e.substring(15),!isNaN(t)&&t>=1&&t<=21)return t<=7?this._generateTableLightStyle1(t-1,e,!0):t<=14?this._generateTableLightStyle2(t-8,e):this._generateTableLightStyle1(t-15,e,!1)}else if(0===e.search(/TableStyleMedium/i)){if(t=+e.substring(16),!isNaN(t)&&t>=1&&t<=28)return t<=7?this._generateTableMediumStyle1(t-1,e):t<=14?this._generateTableMediumStyle2(t-8,e):t<=21?this._generateTableMediumStyle3(t-15,e):this._generateTableMediumStyle4(t-22,e)}else if(0===e.search(/TableStyleDark/i)&&(t=+e.substring(14),!isNaN(t)&&t>=1&&t<=11))return t<=7?this._generateTableDarkStyle1(t-1,e):this._generateTableDarkStyle2(t-8,e);return null},t.prototype._generateTableLightStyle1=function(e,t,o){var n=new TableStyle(t,!0),i=0===e?1:e+3,r=o?"1px":"2px",l=o?"solid":"double",s=o?"1px":"3px";return n.wholeTableStyle={borderTopColor:this._getThemeColor(i),borderTopStyle:"solid",borderTopWidth:"1px",borderBottomColor:this._getThemeColor(i),borderBottomStyle:"solid",borderBottomWidth:"1px"},n.firstColumnStyle={fontWeight:"bold"},n.lastColumnStyle={fontWeight:"bold"},n.headerRowStyle={borderBottomColor:this._getThemeColor(i),borderBottomStyle:"solid",borderBottomWidth:r,fontWeight:"bold"},n.totalRowStyle={borderTopColor:this._getThemeColor(i),borderTopStyle:l,borderTopWidth:s,fontWeight:"bold"},0===e?(n.wholeTableStyle.color=this._getThemeColor(i),n.firstColumnStyle.color=this._getThemeColor(i),n.lastColumnStyle.color=this._getThemeColor(i),n.headerRowStyle.color=this._getThemeColor(i),n.totalRowStyle.color=this._getThemeColor(i),n.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.15)},n.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.15)}):(o?(n.wholeTableStyle.color=this._getThemeColor(i,-.25),n.firstColumnStyle.color=this._getThemeColor(i,-.25),n.lastColumnStyle.color=this._getThemeColor(i,-.25),n.headerRowStyle.color=this._getThemeColor(i,-.25),n.totalRowStyle.color=this._getThemeColor(i,-.25)):(n.wholeTableStyle.color=this._getThemeColor(1),n.firstColumnStyle.color=this._getThemeColor(1),n.lastColumnStyle.color=this._getThemeColor(1),n.headerRowStyle.color=this._getThemeColor(1),n.totalRowStyle.color=this._getThemeColor(1)),n.firstBandedRowStyle={backgroundColor:this._getThemeColor(i,.8)},n.firstBandedColumnStyle={backgroundColor:this._getThemeColor(i,.8)}),o||(n.wholeTableStyle.borderLeftColor=this._getThemeColor(i),n.wholeTableStyle.borderLeftStyle="solid",n.wholeTableStyle.borderLeftWidth="1px",n.wholeTableStyle.borderRightColor=this._getThemeColor(i),n.wholeTableStyle.borderRightStyle="solid",n.wholeTableStyle.borderRightWidth="1px",n.wholeTableStyle.borderHorizontalColor=this._getThemeColor(i),n.wholeTableStyle.borderHorizontalStyle="solid",n.wholeTableStyle.borderHorizontalWidth="1px",n.wholeTableStyle.borderVerticalColor=this._getThemeColor(i),n.wholeTableStyle.borderVerticalStyle="solid",n.wholeTableStyle.borderVerticalWidth="1px"),n},t.prototype._generateTableLightStyle2=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px",borderBottomColor:this._getThemeColor(n),borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightColor:this._getThemeColor(n),borderRightStyle:"solid",borderRightWidth:"1px",color:this._getThemeColor(1)},o.firstBandedRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px"},o.secondBandedRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px"},o.firstBandedColumnStyle={borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px"},o.secondBandedColumnStyle={borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px"},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o},t.prototype._generateTableMediumStyle1=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"1px",borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightStyle:"solid",borderRightWidth:"1px",borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.borderTopColor=this._getThemeColor(n),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n),o.wholeTableStyle.borderRightColor=this._getThemeColor(n),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.15)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.15)}):(o.wholeTableStyle.borderTopColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderRightColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n,.4),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.8)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.8)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o},t.prototype._generateTableMediumStyle2=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderVerticalStyle:"solid",borderVerticalWidth:"1px",borderVerticalColor:this._getThemeColor(0),borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",borderHorizontalColor:this._getThemeColor(0),color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.backgroundColor=this._getThemeColor(0,-.15),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)}):(o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.8),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.6)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.6)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.headerRowStyle={borderBottomColor:this._getThemeColor(0),borderBottomStyle:"solid",borderBottomWidth:"3px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(0),borderTopStyle:"solid",borderTopWidth:"3px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o},t.prototype._generateTableMediumStyle3=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"2px",borderTopColor:this._getThemeColor(1),borderBottomStyle:"solid",borderBottomWidth:"2px",borderBottomColor:this._getThemeColor(1),color:this._getThemeColor(1)},0===e&&(o.wholeTableStyle.borderLeftColor=this._getThemeColor(1),o.wholeTableStyle.borderLeftStyle="solid",o.wholeTableStyle.borderLeftWidth="1px",o.wholeTableStyle.borderRightColor=this._getThemeColor(1),o.wholeTableStyle.borderRightStyle="solid",o.wholeTableStyle.borderRightWidth="1px",o.wholeTableStyle.borderVerticalColor=this._getThemeColor(1),o.wholeTableStyle.borderVerticalStyle="solid",o.wholeTableStyle.borderVerticalWidth="1px",o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(1),o.wholeTableStyle.borderHorizontalStyle="solid",o.wholeTableStyle.borderHorizontalWidth="1px"),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.headerRowStyle={borderBottomColor:this._getThemeColor(1),borderBottomStyle:"solid",borderBottomWidth:"2px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(1),borderTopStyle:"double",borderTopWidth:"3px"},o},t.prototype._generateTableMediumStyle4=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"1px",borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightStyle:"solid",borderRightWidth:"1px",borderVerticalStyle:"solid",borderVerticalWidth:"1px",borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.borderTopColor=this._getThemeColor(n),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n),o.wholeTableStyle.borderRightColor=this._getThemeColor(n),o.wholeTableStyle.borderVerticalColor=this._getThemeColor(n),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n),o.wholeTableStyle.backgroundColor=this._getThemeColor(0,-.15),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)}):(o.wholeTableStyle.borderTopColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderRightColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderVerticalColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n,.4),o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.8),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.6)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.6)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"2px",fontWeight:"bold",color:this._getThemeColor(1)},o},t.prototype._generateTableDarkStyle1=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3,i=0===e?.25:-.25;return o.wholeTableStyle={color:this._getThemeColor(0)},o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,i)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,i)},o.firstColumnStyle={borderRightColor:this._getThemeColor(0),borderRightStyle:"solid",borderRightWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n,i)},o.lastColumnStyle={borderLeftColor:this._getThemeColor(0),borderLeftStyle:"solid",borderLeftWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n,i)},o.headerRowStyle={borderBottomColor:this._getThemeColor(0),borderBottomStyle:"solid",borderBottomWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(1)},o.totalRowStyle={borderTopColor:this._getThemeColor(0),borderTopStyle:"solid",borderTopWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0)},0===e?(o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.5),o.totalRowStyle.backgroundColor=this._getThemeColor(n,.15)):(o.wholeTableStyle.backgroundColor=this._getThemeColor(n),o.totalRowStyle.backgroundColor=this._getThemeColor(n,-.5)),o},t.prototype._generateTableDarkStyle2=function(e,t){var o=new TableStyle(t,!0),n=0===e?0:2*e+2,i=0===e?1:2*e+3,r=0===e?-.15:.8;return o.wholeTableStyle={backgroundColor:this._getThemeColor(n,r)},o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,r-.2)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,r-.2)},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={color:this._getThemeColor(0),backgroundColor:this._getThemeColor(i)},o.totalRowStyle={borderTopColor:this._getThemeColor(1),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o},t.controlTemplate='<div style="width:100%;height:100%"><div wj-part="container" style="width:100%">'+wjcGrid.FlexGrid.controlTemplate+'</div><div wj-part="tab-holder" class="wj-tabholder" style="width:100%; min-width:100px"></div><div wj-part="context-menu" style="display:none;z-index:100"></div></div>',t}(wjcGrid.FlexGrid);exports.FlexSheet=FlexSheet;var DraggingRowColumnEventArgs=function(e){function t(t,o){var n=e.call(this)||this;return n._isDraggingRows=t,n._isShiftKey=o,n}return __extends(t,e),Object.defineProperty(t.prototype,"isDraggingRows",{get:function(){return this._isDraggingRows},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isShiftKey",{get:function(){return this._isShiftKey},enumerable:!0,configurable:!0}),t}(wjcCore.EventArgs);exports.DraggingRowColumnEventArgs=DraggingRowColumnEventArgs;var UnknownFunctionEventArgs=function(e){function t(t,o){var n=e.call(this)||this;return n._funcName=t,n._params=o,n}return __extends(t,e),Object.defineProperty(t.prototype,"funcName",{get:function(){return this._funcName},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),t}(wjcCore.EventArgs);exports.UnknownFunctionEventArgs=UnknownFunctionEventArgs;var RowColumnChangedEventArgs=function(e){function t(t,o,n){var i=e.call(this)||this;return i._index=t,i._count=o,i._added=n,i}return __extends(t,e),Object.defineProperty(t.prototype,"index",{get:function(){return this._index},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"count",{get:function(){return this._count},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"added",{get:function(){return this._added},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAdd",{get:function(){return wjcCore._deprecated("RowColumnChangedEventArgs.isAdd","RowColumnChangedEventArgs.added"),this._added},enumerable:!0,configurable:!0}),t}(wjcCore.EventArgs);exports.RowColumnChangedEventArgs=RowColumnChangedEventArgs;var FlexSheetPanel=function(e){function t(t,o,n,i,r){return e.call(this,t,o,n,i,r)||this}return __extends(t,e),t.prototype.getSelectedState=function(t,o,n){var i,r,l,s,a,h;if(this.grid){if(h=this.grid.getMergedRange(this,t,o),i=this.grid.selectedSheet?this.grid.selectedSheet.selectionRanges:null,a=e.prototype.getSelectedState.call(this,t,o,n),r=i?i.length:0,a===wjcGrid.SelectedState.None&&r>0)for(l=0;l<i.length;l++)if((s=i[l])&&s instanceof wjcGrid.CellRange){if(this.cellType===wjcGrid.CellType.Cell){if(h){if(h.contains(s.row,s.col))return l!==r-1||this.grid._isClicking?wjcGrid.SelectedState.Selected:this.grid.showMarquee?wjcGrid.SelectedState.None:wjcGrid.SelectedState.Cursor;if(h.intersects(s))return wjcGrid.SelectedState.Selected}if(s.row===t&&s.col===o)return l!==r-1||this.grid._isClicking?wjcGrid.SelectedState.Selected:this.grid.showMarquee?wjcGrid.SelectedState.None:wjcGrid.SelectedState.Cursor;if(s.contains(t,o))return wjcGrid.SelectedState.Selected}if(this.grid.showSelectedHeaders&wjcGrid.HeadersVisibility.Row&&this.cellType===wjcGrid.CellType.RowHeader&&s.containsRow(t))return wjcGrid.SelectedState.Selected;if(this.grid.showSelectedHeaders&wjcGrid.HeadersVisibility.Column&&this.cellType===wjcGrid.CellType.ColumnHeader&&s.containsColumn(o))return wjcGrid.SelectedState.Selected}return a}},t.prototype.getCellData=function(t,o,n){var i,r,l,s,a;if(wjcCore.isString(o)&&(o=this.columns.indexOf(o))<0)throw"Invalid column name or binding.";return t>=this.rows.length||wjcCore.asNumber(o,!1,!0)>=this.columns.length?null:(i=e.prototype.getCellData.call(this,t,o,n),r=this.columns[wjcCore.asNumber(o,!1,!0)],l=this.grid?this.grid._getBindingColumn(this,t,r):r,n&&(a=e.prototype.getCellData.call(this,t,o,!1),s=this.grid?this.grid._getCellStyle(t,o):null,!wjcCore.isNumber(a)||0===a||!l||l.format||l.dataMap||s||(i=a.toString())),i)},t.prototype.setCellData=function(t,o,n,i,r){if(void 0===i&&(i=!0),void 0===r&&(r=!0),t>=this.rows.length||o>=this.columns.length)return!1;var l,s=this.getCellData(t,o,!1),a=this.grid._isPasting;return i&&n&&wjcCore.isString(n)&&"'"!==n[0]&&(this.grid.columns[o].dataType===wjcCore.DataType.String||wjcCore.isNullOrWhiteSpace(n)||isNaN(+n)?this.grid.columns[o].dataType===wjcCore.DataType.Boolean?n=wjcCore.changeType(n,wjcCore.DataType.Boolean,null):"="!==n[0]&&(l=wjcCore.Globalize.parseDate(n,""))&&(n=l):n===(+n).toString()?n=+n:i=!1),(n&&wjcCore.isString(n)&&("="===n[0]||"'"===n[0])||wjcCore.isString(s))&&(i=!1),e.prototype.setCellData.call(this,t,o,n,i&&!a,r)},t.prototype._renderCell=function(t,o,n,i,r,l){var s,a,h,c,d=o*this.grid.columns.length+n,u=this.grid.getMergedRange(this,o,n);return c=e.prototype._renderCell.call(this,t,o,n,i,r,l),this.cellType!==wjcGrid.CellType.Cell?c:u&&d>u.topRow*this.grid.columns.length+u.leftCol?c:((s=t.childNodes[l])&&(null!=this.grid.editRange&&this.grid.editRange.contains(o,n)||this.grid.selectedSheet&&(h=this.grid.selectedSheet.findTable(o,n))&&h._updateCell(o,n,s),wjcCore.hasClass(s,"wj-state-selected")||wjcCore.hasClass(s,"wj-state-multi-selected")?(s.style.backgroundColor="",s.style.color=""):this.grid.selectedSheet&&(a=this.grid.selectedSheet._styledCells[d])&&(""!==a.backgroundColor&&(s.style.backgroundColor=a.backgroundColor),""!==a.color&&(s.style.color=a.color))),c)},t}(wjcGrid.GridPanel);exports.FlexSheetPanel=FlexSheetPanel;var HeaderRow=function(e){function t(){var t=e.call(this)||this;return t.isReadOnly=!0,t}return __extends(t,e),t}(wjcGrid.Row);exports.HeaderRow=HeaderRow;var DefinedName=function(){function e(e,t,o,n){if(this._owner=e,this._name=t,this._value=o,null!=n){if(!e._validateSheetName(n))throw"The sheet name:("+n+") does not exist in FlexSheet.";this._sheetName=n}}return Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){var t;if(this._name!==e){if(this._owner._checkExistDefinedName(name,this._sheetName))throw"The "+name+" already existed in definedNames.";t=this._name,this._name=e,this._owner._updateFormulasWithNameUpdating(t,this._name)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this._value!==e&&(this._value=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"sheetName",{get:function(){return this._sheetName},enumerable:!0,configurable:!0}),e}();exports.DefinedName=DefinedName;var Sheet=function(){function e(e,t,o,n,i){this._visible=!0,this._unboundSortDesc=new wjcCore.ObservableArray,this._currentStyledCells={},this._currentMergedRanges=[],this._isEmptyGrid=!1,this._rowSettings=[],this._scrollPosition=new wjcCore.Point,this._freezeHiddenRowCnt=0,this._freezeHiddenColumnCnt=0,this._showDefaultHeader=!1,this.nameChanged=new wjcCore.Event,this.visibleChanged=new wjcCore.Event;var r=this;r._owner=e,r._name=o,r._sortList=[new ColumnSortDescription(-1,!0)],wjcCore.isNumber(n)&&!isNaN(n)&&n>=0?r._rowCount=n:r._rowCount=200,wjcCore.isNumber(i)&&!isNaN(i)&&i>=0?r._columnCount=i:r._columnCount=20,t?(r._showDefaultHeader=!0,r._grid=t):r._grid=this._createGrid(),r._grid.loadedRows.addHandler(function(){r._addHeaderRow(),r._setRowSettings()}),r._grid.itemsSourceChanged.addHandler(this._gridItemsSourceChanged,this),r._addHeaderRow(),r._unboundSortDesc.collectionChanged.addHandler(function(){var e,t,o=r._unboundSortDesc,n={};for(e=0;e<o.length;e++)if(!wjcCore.tryCast(o[e],_UnboundSortDescription))throw"sortDescriptions array must contain SortDescription objects.";if(r._owner){if(r._owner.rows.beginUpdate(),r._owner.rows.sort(r._compareRows()),!r._owner._isUndoing){for(e=0;e<r._owner.rows.length;e++)e!==(t=r._owner.rows[e])._idx&&r._owner._updateFormulaForReorderingRows(t._idx,e),r._owner._updateCellStyleForReorderingRows(t._idx,e,n);r._currentStyledCells=n}r._owner.rows.endUpdate(),r._owner.rows._dirty=!0,r._owner.rows._update(),r._owner.selectedSheet&&(r._owner._copyTo(r._owner.selectedSheet),r._owner._copyFrom(r._owner.selectedSheet))}}),r.tables.collectionChanged.addHandler(function(e,t){if(null!=t.item&&!(t.item instanceof Table))throw"The tables only allows to handle Table instance.";if(t.action===wjcCore.NotifyCollectionChangedAction.Add||t.action===wjcCore.NotifyCollectionChangedAction.Change){if(t.item){var o=void 0,n=void 0,i=t.item,l=i.getRange(),s=r===r._owner.selectedSheet?r._owner:r.grid;try{if(l.topRow>=s.rows.length||l.leftCol>=s.columns.length)throw"";if(l.leftCol+l.columnSpan>s.columns.length)throw"";if(l.topRow+l.rowSpan>s.rows.length)throw"";for(o=l.topRow;o<=l.bottomRow;o++)for(n=l.leftCol;n<=l.rightCol;n++)if(r.findTable(o,n)!==i)throw"";i._attachSheet(r)}catch(e){r.tables.removeAt(t.index)}}}else t.action===wjcCore.NotifyCollectionChangedAction.Remove&&t.item&&t.item._detachSheet()})}return Object.defineProperty(e.prototype,"grid",{get:function(){return null==this._grid.wj_sheetInfo&&(this._grid.wj_sheetInfo={}),this._grid},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){if(!wjcCore.isNullOrWhiteSpace(e)&&(this._name&&this._name.toLowerCase()!==e.toLowerCase()||!this._name)){var t=new wjcCore.PropertyChangedEventArgs("sheetName",this._name,e);this._name=e,this.grid.wj_sheetInfo.name=e,this.onNameChanged(t)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"visible",{get:function(){return this._visible},set:function(e){this._visible!==e&&(this._visible=e,this.grid.wj_sheetInfo.visible=e,this.onVisibleChanged(new wjcCore.EventArgs))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rowCount",{get:function(){return null!=this._grid?this._grid.rows.length:0},set:function(e){var t;if(!this.itemsSource&&wjcCore.isNumber(e)&&!isNaN(e)&&e>=0&&this._rowCount!==e){if(this._rowCount<e)for(t=0;t<e-this._rowCount;t++)this.grid.rows.push(new wjcGrid.Row);else this.grid.rows.splice(e,this._rowCount-e);this._rowCount=e,this._owner&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name&&this._owner._copyFrom(this,!0)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"columnCount",{get:function(){return null!=this._grid?this._grid.columns.length:0},set:function(e){var t;if(!this.itemsSource&&wjcCore.isNumber(e)&&!isNaN(e)&&e>=0&&this._columnCount!==e){if(this._columnCount<e)for(t=0;t<e-this._columnCount;t++)this._grid.columns.push(new wjcGrid.Column);else this._grid.columns.splice(e,this._columnCount-e);this._columnCount=e,this._owner&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name&&this._owner._copyFrom(this,!0)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"selectionRanges",{get:function(){var e=this;return this._selectionRanges||(this._selectionRanges=new wjcCore.ObservableArray,this._selectionRanges.collectionChanged.addHandler(function(){var t,o;e._owner&&!e._owner._isClicking&&((t=e._selectionRanges.length)>0&&(o=e._selectionRanges[t-1])&&o instanceof wjcGrid.CellRange&&(e._owner.selection=o),t>1?(e._owner._enableMulSel=!0,e._owner.refresh(!1)):e._owner.refresh(),e._owner._enableMulSel=!1)},this)),this._selectionRanges},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"itemsSource",{get:function(){return null!=this._grid?this._grid.itemsSource:null},set:function(e){var t=this;null==t._grid&&(t._createGrid(),t._grid.itemsSourceChanged.addHandler(t._gridItemsSourceChanged,t)),t._isEmptyGrid&&t._clearGrid(),t._grid.itemsSource=e,t._owner&&t._owner._isCopying||null==e||(t._orgItemsSource=t._grid.collectionView._view.slice())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"filterSetting",{get:function(){return this===this._owner.selectedSheet&&this._getFilterSetting(),this._filterSetting},set:function(e){this._filterSetting=e,this===this._owner.selectedSheet&&this._applyFilterSetting()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tables",{get:function(){return null==this._tables&&(this._tables=new wjcCore.ObservableArray),this._tables},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_styledCells",{get:function(){return this._currentStyledCells||(this._currentStyledCells={}),this._currentStyledCells},set:function(e){this._currentStyledCells=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_mergedRanges",{get:function(){return this._currentMergedRanges||(this._currentMergedRanges=[]),this._currentMergedRanges},enumerable:!0,configurable:!0}),e.prototype.onNameChanged=function(e){this.nameChanged.raise(this,e)},e.prototype.onVisibleChanged=function(e){this.visibleChanged.raise(this,e)},e.prototype.getCellStyle=function(e,t){var o,n=this._grid.rows.length,i=this._grid.columns.length;return e>=n||t>=i?null:(o=e*i+t,this._styledCells[o])},e.prototype.addTableFromArray=function(e,t,o,n,i,r,l,s){void 0===s&&(s=!0);var a,h,c,d,u,_,g,w,p,f,m,C=!1,b=this===this._owner.selectedSheet?this._owner:this.grid;if(null==o||0===o.length)throw"Invalid array to load.";if(!(null!=n&&0!==n.length||null!=(n=Object.keys(o[0]))&&0!==n.length))throw"Invalid array to load.";if(e>=this.rowCount||t>=this.columnCount)return null;var S=null==(l&&l.showHeaderRow)||l.showHeaderRow,y=!(!l||!l.showTotalRow),R=e+(S?1:0),v=R+o.length-1+(y?1:0);for(a=[],p=0;p<n.length;p++)f=n[p],h=new TableColumn(f),0===p?h._totalRowLabel="Total":p===n.length-1&&(h._totalRowFunction="Sum"),a.push(h);if(c=new wjcGrid.CellRange(e,t,v,t+n.length-1),0!==(d=this._needShiftForTable(c))){if(!s)return null;if(!this._canShiftCells(c))return null;if(u=this._needAddRowCountForAddTable(d,c),b.collectionView){for(m=b.itemsSource instanceof wjcCore.CollectionView,b.collectionView.beginUpdate(),g=0;g<u;g++)m?b.itemsSource.sourceCollection.push({}):b.itemsSource.push({});b.collectionView.endUpdate()}else for(g=0;g<u;g++)b.rows.push(new wjcGrid.Row);C=!0}if(t+n.length>=b.columns.length){if(!s)return null;if(_=t+n.length-b.columns.length+1,this.itemsSource&&_>0)return null;for(b.columns.beginUpdate(),g=0;g<_;g++)b.columns.push(new wjcGrid.Column);b.columns.endUpdate()}if(b.beginUpdate(),C&&this._moveDownCells(d,c),S)for(p=0;p<n.length;p++)f=n[p],b.setCellData(e,t+p,f);for(w=0;w<o.length;w++)for(p=0;p<n.length;p++)f=n[p],b.setCellData(R+w,t+p,o[w][f]);return b.endUpdate(),this._addTable(c,i,r,a,l)},e.prototype.findTable=function(e,t){var o,n;if(this._tables&&this._tables.length>0)for(var i=0;i<this._tables.length;i++)if(o=this._tables[i],n=o.getRange(),e>=n.topRow&&e<=n.bottomRow&&t>=n.leftCol&&t<=n.rightCol)return o;return null},e.prototype._attachOwner=function(e){this._owner!==e&&(this._owner=e)},e.prototype._setValidName=function(e){this._name=e,this.grid.wj_sheetInfo.name=e},e.prototype._storeRowSettings=function(){var e,t=0;for(this._rowSettings=[];t<this._grid.rows.length;t++)(e=this._owner.rows[t])&&(this._rowSettings[t]={height:e.height,allowMerging:e.allowMerging,isCollapsed:e instanceof wjcGrid.GroupRow?e.isCollapsed:null,visible:e.visible,isSelected:e.isSelected,readOnly:e.isReadOnly})},e.prototype._setRowSettings=function(){for(var e,t,o=0;o<this._rowSettings.length;o++)(t=this._rowSettings[o])&&(e=this._grid.rows[o])&&(e.height=t.height,e.allowMerging=t.allowMerging,e.visible=t.visible,e instanceof wjcGrid.GroupRow&&(e.isCollapsed=!!t.isCollapsed),e.isSelected=!!t.isSelected,e.isReadOnly=!!t.readOnly)},e.prototype._addTable=function(e,t,o,n,i){if(!e.isValid)return null;var r;return null!=t&&null==this._owner._getTable(t)||(t=this._getUniqueTableName()),r=new Table(t,e,o,n,i),this.tables.push(r),r},e.prototype._addSelection=function(e){var t,o;for(this.selectionRanges.beginUpdate(),o=this.selectionRanges.length-1;o>=0;o--)t=this.selectionRanges[o],e.contains(t)&&this.selectionRanges.removeAt(o);e.isValid&&this.selectionRanges.push(e),this.selectionRanges.endUpdate()},e.prototype._compareRows=function(){var e=this,t=this._unboundSortDesc;return function(o,n){for(var i=0;i<t.length;i++){var r=t[i],l=o._ubv&&r.column?o._ubv[r.column._hash]:"",s=n._ubv&&r.column?n._ubv[r.column._hash]:"";if(wjcCore.isString(l)&&"="===l[0]&&(l=e._owner.evaluate(l)),wjcCore.isString(s)&&"="===s[0]&&(s=e._owner.evaluate(s)),l!==l&&(l=null),s!==s&&(s=null),wjcCore.isString(l)&&(l=l.toLowerCase()+l),wjcCore.isString(s)&&(s=s.toLowerCase()+s),""===l||null==l)return 1;if(""===s||null==s)return-1;var a=l<s?-1:l>s?1:0;if(wjcCore.isString(l)&&wjcCore.isNumber(s)&&(a=1),wjcCore.isString(s)&&wjcCore.isNumber(l)&&(a=-1),0!==a)return r.ascending?+a:-a}return 0}},e.prototype._createGrid=function(){var e,t,o,n,i=document.createElement("div");for(this._isEmptyGrid=!0,i.style.visibility="hidden",document.body.appendChild(i),e=new wjcGrid.FlexGrid(i),document.body.removeChild(i),n=0;n<this._rowCount;n++)e.rows.push(new wjcGrid.Row);for(o=0;o<this._columnCount;o++)(t=new wjcGrid.Column).isRequired=!1,e.columns.push(t);return e.wj_sheetInfo={name:this.name,visible:this.visible,styledCells:this._styledCells,mergedRanges:this._mergedRanges},e},e.prototype._clearGrid=function(){this._grid.rows.clear(),this._grid.columns.clear(),this._grid.columnHeaders.columns.clear(),this._grid.rowHeaders.rows.clear()},e.prototype._gridItemsSourceChanged=function(){var e=this;e._owner&&!e._owner._isCopying&&e._owner.selectedSheet&&e._name===e._owner.selectedSheet.name&&(e._owner.filter.clear(),e._owner._copyFrom(e,!1),setTimeout(function(){e._owner._setFlexSheetToDirty(),e._owner.invalidate()},10))},e.prototype._addHeaderRow=function(){if(this._grid.itemsSource&&!(this._grid.rows[0]instanceof HeaderRow)){for(var e,t=new HeaderRow,o=0;o<this._grid.columns.length;o++)e=this._grid.columns[o],t._ubv||(t._ubv={}),t._ubv[e._hash]=e.header;this._grid.rows.insert(0,t)}},e.prototype._getUniqueTableName=function(){for(var e="Table1",t=2;;){if(null==this._owner._getTable(e))break;e="Table"+t,t+=1}return e},e.prototype._needShiftForTable=function(e){var t,o,n,i=0,r=0,l=this===this._owner.selectedSheet?this._owner:this.grid;for(t=e.topRow;t<=e.bottomRow;t++){if(t>=l.rows.length)return i=e.rowSpan-r;for(o=e.leftCol;o<=e.rightCol&&o<l.columns.length;o++)if(null!=(n=l.getCellData(t,o,!1))&&""!==n)return i=e.rowSpan-r;r++}return i},e.prototype._needAddRowCountForAddTable=function(e,t){var o,n,i,r,l,s=this===this._owner.selectedSheet?this._owner:this.grid;for(o=1;o<=e;o++)for(n=s.rows.length-o,i=t.leftCol;i<=t.rightCol&&i<s.columns.length;i++)if(r=s.getCellData(n,i,!1),l=this.getCellStyle(n,i),null!=r&&""!==r||null!=l)return e-o+1;return 0},e.prototype._moveDownTable=function(e){var t,o,n,i,r=e.getRange(),l=this===this._owner.selectedSheet?this._owner:this.grid;for(t=r.bottomRow;t>=r.topRow;t--)for(o=r.leftCol;o<=r.rightCol;o++)i=null!=l.columns[o].dataMap,n=l.getCellData(t,o,i),l.setCellData(t+1,o,n),l.setCellData(t,o,"");e._updateTableRange(1,1,0,0)},e.prototype._moveDownCells=function(e,t){var o,n,i,r,l,s,a,h,c,d,u=this===this._owner.selectedSheet?this._owner:this.grid;for(o=u.rows.length-1-e;o>=t.topRow;o--)for(n=t.leftCol;n<=t.rightCol&&n<u.columns.length;n++)d=null!=u.columns[n].dataMap,i=u.getCellData(o,n,d),u.setCellData(o+e,n,i),u.setCellData(o,n,""),r=this.getCellStyle(o,n),s=(o+e)*u.columns.length+n,l=o*u.columns.length+n,r&&(this._styledCells[s]=r,this._styledCells[l]=null),(a=this._mergedRanges[l])&&(a.row+=e,a.row2+=e,this._mergedRanges[s]=a,this._mergedRanges[l]=null),(h=this.findTable(o,n))&&(c=h.getRange()).topRow===o&&c.leftCol===n&&h._updateTableRange(e,e,0,0)},e.prototype._moveUpCells=function(e,t){var o,n,i,r,l,s,a,h,c,d,u=this===this._owner.selectedSheet?this._owner:this.grid;for(o=t.topRow;o<u.rows.length;o++)for(n=t.leftCol;n<=t.rightCol&&n<u.columns.length;n++)d=null!=u.columns[n].dataMap,i=u.getCellData(o,n,d),u.setCellData(o-e,n,i),u.setCellData(o,n,""),r=this.getCellStyle(o,n),s=(o-e)*u.columns.length+n,l=o*u.columns.length+n,r&&(this._styledCells[s]=r,this._styledCells[l]=null),(a=this._mergedRanges[l])&&(a.row-=e,a.row2-=e,this._mergedRanges[s]=a,this._mergedRanges[l]=null),(h=this.findTable(o,n))&&(c=h.getRange()).topRow===o&&c.leftCol===n&&h._updateTableRange(-e,-e,0,0)},e.prototype._moveDownCellsWithinTable=function(e,t,o){var n,i,r,l,s=this===this._owner.selectedSheet?this._owner:this.grid;for(n=o.bottomRow;n>o.topRow+e;n--)for(i=o.leftCol;i<=o.rightCol;i++)l=null!=s.columns[i].dataMap,r=s.getCellData(n,i,l),s.setCellData(n+t,i,r),s.setCellData(n,i,""),(n+t)*s.columns.length+i,n*s.columns.length+i},e.prototype._moveUpCellsWithinTable=function(e,t,o){var n,i,r,l,s=o.topRow+e,a=this===this._owner.selectedSheet?this._owner:this.grid;for(n=s;n<=o.bottomRow;n++)for(i=o.leftCol;i<=o.rightCol;i++)n>=s+t&&(l=null!=a.columns[i].dataMap,r=a.getCellData(n,i,l),a.setCellData(n-t,i,r)),a.setCellData(n,i,""),(n-t)*a.columns.length+i,n*a.columns.length+i},e.prototype._canShiftCells=function(e){var t,o,n,i,r,l,s=this===this._owner.selectedSheet?this._owner:this.grid;for(t=e.topRow;t<s.rows.length;t++)for(o=e.leftCol;o<=e.rightCol&&o<s.columns.length;o++){if((r=this.findTable(t,o))&&((l=r.getRange()).leftCol<e.leftCol||l.rightCol>e.rightCol))return!1;if(n=t*s.columns.length+o,(i=this._mergedRanges[n])&&(i.leftCol<e.leftCol||i.rightCol>e.rightCol))return!1}return!0},e.prototype._needMoveDownTable=function(e){var t,o,n=e.getRange(),i=e.getColumns(),r=this===this._owner.selectedSheet?this._owner:this.grid;if(0===n.topRow)return!0;for(t=0;t<i.length;t++)if(null!=(o=r.getCellData(n.topRow-1,n.leftCol+t,!1))&&""!==o)return!0;return!1},e.prototype._needAddRowCountForInsertTableRows=function(e,t){var o,n,i,r,l,s=this===this._owner.selectedSheet?this._owner:this.grid;for(o=1;o<=e;o++){if((n=s.rows.length-o)<=t.bottomRow)return e;for(i=t.leftCol;i<=t.rightCol&&i<s.columns.length;i++)if(r=s.getCellData(n,i,!1),l=this.getCellStyle(n,i),null!=r&&""!==r||null!=l)return e-o+1}return 0},e.prototype._getFilterSetting=function(){var e,t=0;for(this._filterDefinition=this._owner.filter.filterDefinition,this._filterSetting={},this._filterSetting.filterColumns=this._owner.filter.filterColumns,this._filterSetting.columnFilterSettings||(this._filterSetting.columnFilterSettings=[]);t<this._owner.filter._filters.length;t++)(e=this._owner.filter._filters[t])&&this._filterSetting.columnFilterSettings.push({column:e.column,filterType:e.filterType,dataMap:e.dataMap,valueFilterSetting:{maxValues:e.valueFilter.maxValues,uniqueValues:e.valueFilter.uniqueValues,sortValues:e.valueFilter.sortValues,dataMap:e.valueFilter.dataMap},conditionFilterSetting:{dataMap:e.conditionFilter.dataMap}})},e.prototype._applyFilterSetting=function(){var e,t,o,n,i,r,l,s,a,h,c=0;if(null==this._filterSetting)this._clearFilterSetting();else if(this._owner.filter.filterColumns=this._filterSetting.filterColumns,this._filterDefinition&&(this._owner.filter.filterDefinition=this._filterDefinition),null!=(e=this._filterSetting.columnFilterSettings)&&e.length>0)for(;c<e.length;c++)(t=e[c])&&null!=t.column&&(i=this._owner.filter.getColumnFilter(t.column))&&(r=i.valueFilter.showValues,l=i.valueFilter.filterText,s={operator:i.conditionFilter.condition1.operator,value:i.conditionFilter.condition1.value},a={operator:i.conditionFilter.condition2.operator,value:i.conditionFilter.condition2.value},h=i.conditionFilter.and,null!=t.dataMap&&(i.dataMap=t.dataMap),null!=t.filterType&&(i.filterType=t.filterType),(o=t.valueFilterSetting)&&(o.dataMap&&(i.valueFilter.dataMap=o.dataMap),null!=o.maxValues&&(i.valueFilter.maxValues=o.maxValues),null!=o.sortValues&&(i.valueFilter.sortValues=o.sortValues),o.uniqueValues&&(i.valueFilter.uniqueValues=o.uniqueValues)),(n=t.conditionFilterSetting)&&n.dataMap&&(i.conditionFilter.dataMap=n.dataMap),i.valueFilter.showValues=r,i.valueFilter.filterText=l,i.conditionFilter.condition1.operator=s.operator,i.conditionFilter.condition1.value=s.value,i.conditionFilter.condition2.operator=a.operator,i.conditionFilter.condition2.value=a.value,i.conditionFilter.and=h)},e.prototype._clearFilterSetting=function(){var e,t=0;for(this._owner.filter.filterColumns=null;t<this._owner.filter._filters.length;t++)(e=this._owner.filter._filters[t])&&(e.filterType=null,e.dataMap=null,e.valueFilter.uniqueValues=null,e.valueFilter.dataMap=null,e.valueFilter.maxValues=250,e.valueFilter.showValues=null,e.conditionFilter.dataMap=null);this._filterDefinition&&(this._owner.filter.filterDefinition=this._filterDefinition)},e.prototype._cloneMergedCells=function(){for(var e,t=0,o=[];t<this._mergedRanges.length;t++)e=this._mergedRanges[t],o.push(e.clone());return o},e.prototype._getMergedRange=function(e,t){var o,n;for(o=0;o<this._mergedRanges.length;o++)if(n=this._mergedRanges[o],e>=n.topRow&&e<=n.bottomRow&&t>=n.leftCol&&t<=n.rightCol)return n;return null},e}();exports.Sheet=Sheet;var SheetCollection=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._current=-1,t.sheetCleared=new wjcCore.Event,t.selectedSheetChanged=new wjcCore.Event,t.sheetNameChanged=new wjcCore.Event,t.sheetVisibleChanged=new wjcCore.Event,t}return __extends(t,e),t.prototype.onSheetCleared=function(){this.sheetCleared.raise(this,new wjcCore.EventArgs)},Object.defineProperty(t.prototype,"selectedIndex",{get:function(){return this._current},set:function(e){this._moveCurrentTo(+e)},enumerable:!0,configurable:!0}),t.prototype.onSelectedSheetChanged=function(e){this.selectedSheetChanged.raise(this,e)},t.prototype.insert=function(t,o){var n;(n=o.name?this.getValidSheetName(o):this._getUniqueName())!==o.name&&(o.name=n),e.prototype.insert.call(this,t,o),this._postprocessSheet(o)},t.prototype.push=function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];this.length;for(var n,i=0;i<t.length;i++)(n=t[i].name?this.getValidSheetName(t[i]):this._getUniqueName())!==t[i].name&&(t[i].name=n),e.prototype.push.call(this,t[i]),this._postprocessSheet(t[i]);return this.length},t.prototype.splice=function(t,o,n){var i;return n?((i=n.name?this.getValidSheetName(n):this._getUniqueName())!==n.name&&(n.name=i),this._postprocessSheet(n),e.prototype.splice.call(this,t,o,n)):e.prototype.splice.call(this,t,o,n)},t.prototype.removeAt=function(t){this.hide(t)&&(e.prototype.removeAt.call(this,t),t<this.selectedIndex&&(this._current-=1))},t.prototype.onSheetNameChanged=function(e){this.sheetNameChanged.raise(this,e)},t.prototype.onSheetVisibleChanged=function(e){this.sheetVisibleChanged.raise(this,e)},t.prototype.selectFirst=function(){return this._moveCurrentTo(0)},t.prototype.selectLast=function(){return this._moveCurrentTo(this.length-1)},t.prototype.selectPrevious=function(){return this._moveCurrentTo(this._current-1)},t.prototype.selectNext=function(){return this._moveCurrentTo(this._current+1)},t.prototype.hide=function(e){return!(e<0&&e>=this.length)&&(!!this[e].visible&&(this[e].visible=!1,!0))},t.prototype.show=function(e){return!(e<0&&e>=this.length)&&(this[e].visible=!0,this._moveCurrentTo(e),!0)},t.prototype.clear=function(){e.prototype.clear.call(this),this._current=-1,this.onSheetCleared()},t.prototype.isValidSheetName=function(e){var t=this._getSheetIndexFrom(e.name),o=this.indexOf(e);return-1===t||t===o},t.prototype.getValidSheetName=function(e){for(var t,o=e.name,n=1,i=this.indexOf(e);;){if(-1===(t=this._getSheetIndexFrom(o))||t===i)break;o=e.name.concat((n+1).toString()),n+=1}return o},t.prototype._moveCurrentTo=function(e){var t,o=e;if(e<0||e>=this.length)return!1;if(this._current<o||0===o)for(;o<this.length&&!this[o].visible;)o++;else if(this._current>o)for(;o>=0&&!this[o].visible;)o--;if(o===this.length)for(o=e;o>=0&&!this[o].visible;)o--;return!(o<0)&&(o!==this._current&&(t=new wjcCore.PropertyChangedEventArgs("sheetIndex",this._current,o),this._current=o,this.onSelectedSheetChanged(t)),!0)},t.prototype._getSheetIndexFrom=function(e){var t;if(!e)return-1;e=e.toLowerCase();for(var o=0;o<this.length;o++)if(t=this[o],(t.name?t.name.toLowerCase():"")===e)return o;return-1},t.prototype._postprocessSheet=function(e){var t=this;e.nameChanged.addHandler(function(){var o,n=t._getSheetIndexFrom(e.name);t.isValidSheetName(e)||e._setValidName(t.getValidSheetName(e)),o=new wjcCore.NotifyCollectionChangedEventArgs(wjcCore.NotifyCollectionChangedAction.Change,e,wjcCore.isNumber(n)?n:t.length-1),t.onSheetNameChanged(o)}),e.visibleChanged.addHandler(function(){var o=t._getSheetIndexFrom(e.name),n=new wjcCore.NotifyCollectionChangedEventArgs(wjcCore.NotifyCollectionChangedAction.Change,e,wjcCore.isNumber(o)?o:t.length-1);t.onSheetVisibleChanged(n)})},t.prototype._getUniqueName=function(){for(var e="Sheet1",t=2;;){if(-1===this._getSheetIndexFrom(e))break;e="Sheet"+t,t+=1}return e},t}(wjcCore.ObservableArray);exports.SheetCollection=SheetCollection;var _SheetTabs=function(e){function t(t,o,n){var i=e.call(this,t,n)||this;i._rtl=!1,i._sheetTabClicked=!1;var r=i;return r._owner=o,r._sheets=o.sheets,r._rtl="rtl"==getComputedStyle(r._owner.hostElement).direction,r._initControl(),r.deferUpdate(function(){n&&r.initialize(n)}),i}return __extends(t,e),t.prototype.refresh=function(e){this._tabContainer.innerHTML="",this._tabContainer.innerHTML=this._getSheetTabs(),this._rtl&&this._adjustSheetsPosition(),this._adjustSize()},t.prototype._sourceChanged=function(e,t){void 0===t&&(t=wjcCore.NotifyCollectionChangedEventArgs.reset);var o=t;switch(o.action){case wjcCore.NotifyCollectionChangedAction.Add:o.index-1<0&&0,this._tabContainer.innerHTML="",this._tabContainer.innerHTML=this._getSheetTabs(),this._rtl&&this._adjustSheetsPosition(),this._adjustSize();break;case wjcCore.NotifyCollectionChangedAction.Remove:this._tabContainer.removeChild(this._tabContainer.children[o.index]),this._tabContainer.hasChildNodes()&&this._updateTabActive(o.index,!0),this._adjustSize();break;default:this.invalidate()}},t.prototype._selectedSheetChanged=function(e,t){this._updateTabActive(t.oldValue,!1),this._updateTabActive(t.newValue,!0),this._sheetTabClicked?this._sheetTabClicked=!1:this._scrollToActiveSheet(t.newValue,t.oldValue),this._adjustSize()},t.prototype._initControl=function(){var e=this;e.applyTemplate("",e.getTemplate(),{_sheetContainer:"sheet-container",_tabContainer:"container",_sheetPage:"sheet-page",_newSheet:"new-sheet"}),e._rtl&&(e._sheetPage.style.right="0px",e._tabContainer.parentElement.style.right=e._sheetPage.clientWidth+"px",e._tabContainer.style.right="0px",e._tabContainer.style.cssFloat="right",e._newSheet.style.right=e._sheetPage.clientWidth+e._tabContainer.parentElement.clientWidth+"px"),e._adjustNavigationButtons(e._rtl),e.addEventListener(e.hostElement,"mousedown",function(){e._owner._mouseHdl._htDown=null}),e.addEventListener(e._newSheet,"click",function(t){var o=e._owner.selectedSheetIndex;e._owner.addUnboundSheet(),e._scrollToActiveSheet(e._owner.selectedSheetIndex,o)}),e._sheets.collectionChanged.addHandler(e._sourceChanged,e),e._sheets.selectedSheetChanged.addHandler(e._selectedSheetChanged,e),e._sheets.sheetNameChanged.addHandler(e._updateSheetName,e),e._sheets.sheetVisibleChanged.addHandler(e._updateTabShown,e),e._initSheetPage(),e._initSheetTab()},t.prototype._initSheetTab=function(){var e=this;e.addEventListener(e._tabContainer,"mousedown",function(t){var o,n=t.target;n instanceof HTMLLIElement&&(e._sheetTabClicked=!0,o=e._getItemIndex(e._tabContainer,n),e._scrollSheetTabContainer(n),o>-1&&(e._sheets.selectedIndex=o))})},t.prototype._initSheetPage=function(){var e=this;e.hostElement.querySelector("div.wj-sheet-page").addEventListener("click",function(t){var o="[object HTMLButtonElement]"===t.target.toString()?t.target:t.target.parentElement,n=e._getItemIndex(e._sheetPage,o);if(0!==e._sheets.length)switch(n){case 0:e._sheets.selectFirst();break;case 1:e._sheets.selectPrevious();break;case 2:e._sheets.selectNext();break;case 3:e._sheets.selectLast()}})},t.prototype._getSheetTabs=function(){var e,t="";for(e=0;e<this._sheets.length;e++)t+=this._getSheetElement(this._sheets[e],this._sheets.selectedIndex===e);return t},t.prototype._getSheetElement=function(e,t){void 0===t&&(t=!1);var o="<li";return e.visible?t&&(o+=' class="active"'):o+=' class="hidden"',o+=">"+e.name+"</li>"},t.prototype._updateTabActive=function(e,t){e<0||e>=this._tabContainer.children.length||(t?wjcCore.addClass(this._tabContainer.children[e],"active"):wjcCore.removeClass(this._tabContainer.children[e],"active"))},t.prototype._updateTabShown=function(e,t){t.index<0||t.index>=this._tabContainer.children.length||(t.item.visible?wjcCore.removeClass(this._tabContainer.children[t.index],"hidden"):wjcCore.addClass(this._tabContainer.children[t.index],"hidden"),this._adjustSize())},t.prototype._adjustSize=function(){var e,t,o=this._tabContainer.childElementCount,n=0,i=0;if("none"!==this.hostElement.style.display){for(i=this._tabContainer.parentElement.scrollLeft,this._tabContainer.parentElement.style.width="",this._tabContainer.style.width="",this._sheetPage.parentElement.style.width="",e=0;e<o;e++)n+=this._tabContainer.children[e].offsetWidth+1;t=this.hostElement.offsetWidth-this._sheetPage.offsetWidth-this._newSheet.offsetWidth-2,this._tabContainer.parentElement.style.width=(n>t?t:n)+"px",this._tabContainer.style.width=n+"px",this._sheetPage.parentElement.style.width=this._sheetPage.offsetWidth+this._newSheet.offsetWidth+this._tabContainer.parentElement.offsetWidth+3+"px",this._tabContainer.parentElement.scrollLeft=i}},t.prototype._getItemIndex=function(e,t){for(var o=0;o<e.children.length;o++)if(e.children[o]===t)return o;return-1},t.prototype._updateSheetName=function(e,t){this._tabContainer.querySelectorAll("li")[t.index].textContent=t.item.name,this._adjustSize()},t.prototype._scrollSheetTabContainer=function(e){var t,o=this._tabContainer.parentElement.scrollLeft,n=this._sheetPage.offsetWidth,i=this._newSheet.offsetWidth,r=this._tabContainer.parentElement.offsetWidth;if(this._rtl)switch(wjcGrid.FlexGrid._getRtlMode()){case"rev":(t=-this._tabContainer.offsetLeft)+e.offsetLeft+e.offsetWidth>r+o?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:t+e.offsetLeft<o&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth);break;case"neg":e.offsetLeft<o?this._tabContainer.parentElement.scrollLeft-=e.offsetWidth:e.offsetLeft+e.offsetWidth>r+o&&(this._tabContainer.parentElement.scrollLeft+=e.offsetWidth);break;default:e.offsetLeft-i+o<0?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:e.offsetLeft+e.offsetWidth-i+o>r&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth)}else e.offsetLeft+e.offsetWidth-n>r+o?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:e.offsetLeft-n<o&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth)},t.prototype._adjustSheetsPosition=function(){var e,t,o=this._tabContainer.querySelectorAll("li"),n=0;for(t=0;t<o.length;t++)(e=o[t]).style.cssFloat="right",e.style.right=n+"px",n+=o[t].clientWidth},t.prototype._scrollToActiveSheet=function(e,t){var o,n,i,r=this._tabContainer.querySelectorAll("li");if(n=this._tabContainer.clientWidth>this._tabContainer.parentElement.clientWidth?this._tabContainer.clientWidth-this._tabContainer.parentElement.clientWidth:0,r.length>0&&e<r.length&&t<r.length){if(0===e&&!this._rtl||e===r.length-1&&this._rtl){if(this._rtl)switch(wjcGrid.FlexGrid._getRtlMode()){case"rev":this._tabContainer.parentElement.scrollLeft=0;break;case"neg":this._tabContainer.parentElement.scrollLeft=-n;break;default:this._tabContainer.parentElement.scrollLeft=n}else this._tabContainer.parentElement.scrollLeft=0;return}if(0===e&&this._rtl||e===r.length-1&&!this._rtl){if(this._rtl)switch(wjcGrid.FlexGrid._getRtlMode()){case"rev":this._tabContainer.parentElement.scrollLeft=n;break;case"neg":default:this._tabContainer.parentElement.scrollLeft=0}else this._tabContainer.parentElement.scrollLeft=n;return}if(e>=t)for(i=t+1;i<=e;i++)o=r[i],this._scrollSheetTabContainer(o);else for(i=t-1;i>=e;i--)o=r[i],this._scrollSheetTabContainer(o)}},t.prototype._adjustNavigationButtons=function(e){var t,o=this.hostElement.querySelectorAll(".wj-sheet-page button");o&&4===o.length&&(e?(t=o[0].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-step-backward"),wjcCore.addClass(t,"wj-glyph-step-forward"),t=o[1].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-left"),wjcCore.addClass(t,"wj-glyph-right"),t=o[2].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-right"),wjcCore.addClass(t,"wj-glyph-left"),t=o[3].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-step-forward"),wjcCore.addClass(t,"wj-glyph-step-backward")):(t=o[0].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-step-forward"),wjcCore.addClass(t,"wj-glyph-step-backward"),t=o[1].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-right"),wjcCore.addClass(t,"wj-glyph-left"),t=o[2].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-left"),wjcCore.addClass(t,"wj-glyph-right"),t=o[3].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-step-backward"),wjcCore.addClass(t,"wj-glyph-step-forward")))},t.controlTemplate='<div wj-part="sheet-container" class="wj-sheet" style="height:100%;position:relative"><div wj-part="sheet-page" class="wj-btn-group wj-sheet-page"><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-step-backward"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-left"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-right"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-step-forward"></span></button></div><div class="wj-sheet-tab" style="height:100%;overflow:hidden"><ul wj-part="container"></ul></div><div wj-part="new-sheet" class="wj-new-sheet"><span class="wj-sheet-icon wj-glyph-file"></span></div></div>',t}(wjcCore.Control);exports._SheetTabs=_SheetTabs;var _UnboundSortDescription=function(){function e(e,t){this._column=e,this._ascending=t}return Object.defineProperty(e.prototype,"column",{get:function(){return this._column},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ascending",{get:function(){return this._ascending},enumerable:!0,configurable:!0}),e}();exports._UnboundSortDescription=_UnboundSortDescription;var SortManager=function(){function e(e){this._owner=e,this._sortDescriptions=new wjcCore.CollectionView,this._committedList=[new ColumnSortDescription(-1,!0)],this._sortDescriptions.newItemCreator=function(){return new ColumnSortDescription(-1,!0)}}return Object.defineProperty(e.prototype,"sortDescriptions",{get:function(){return this._sortDescriptions},set:function(e){this._sortDescriptions=e,this.commitSort()},enumerable:!0,configurable:!0}),e.prototype.addSortLevel=function(e,t){void 0===t&&(t=!0);var o=this._sortDescriptions.addNew();null!=e&&!isNaN(e)&&wjcCore.isInt(e)&&(o.columnIndex=e),o.ascending=t,this._sortDescriptions.commitNew()},e.prototype.deleteSortLevel=function(e){var t;(t=null!=e?this._getSortItem(e):this._sortDescriptions.currentItem)&&this._sortDescriptions.remove(t)},e.prototype.copySortLevel=function(){var e=this._sortDescriptions.currentItem;if(e){var t=this._sortDescriptions.addNew();t.columnIndex=parseInt(e.columnIndex),t.ascending=e.ascending,this._sortDescriptions.commitNew()}},e.prototype.editSortLevel=function(e,t){null!=e&&(this._sortDescriptions.currentItem.columnIndex=e),null!=t&&(this._sortDescriptions.currentItem.ascending=t)},e.prototype.moveSortLevel=function(e){var t=this._sortDescriptions.currentItem;if(t){var o=this._sortDescriptions.sourceCollection,n=o.indexOf(t),i=n+e;n>-1&&i>-1&&(o.splice(n,1),o.splice(i,0,t),this._sortDescriptions.refresh(),this._sortDescriptions.moveCurrentTo(t))}},e.prototype.checkSortItemExists=function(e){for(var t=0,o=this._sortDescriptions.itemCount;t<o;t++)if(+this._sortDescriptions.items[t].columnIndex===e)return t;return-1},e.prototype.commitSort=function(e){void 0===e&&(e=!0);var t,o,n,i,r,l,s,a,h,c,d,u,_,g=this._owner.itemsSource instanceof wjcCore.CollectionView,w={},p={};if(this._owner.selectedSheet&&0!==this._owner.columns.length){if(this._owner._needCopyToSheet=!1,l=this._owner.selectedSheet._unboundSortDesc,e&&this._owner.undoStack.stackSize>0&&(s=new _SortColumnAction(this._owner)),this._sortDescriptions.itemCount>0?this._committedList=this._cloneSortList(this._sortDescriptions.items):this._committedList=[new ColumnSortDescription(-1,!0)],this._owner.collectionView){for(this._owner._isSorting=!0,this._owner.beginUpdate(),this._owner.collectionView.canSort=!0,(a=this._owner.editableCollectionView)&&a.currentEditItem&&-1!==a.items.indexOf(a.currentEditItem)&&!this._isEmpty(a.currentEditItem)&&a.commitEdit(),this._owner.collectionView.beginUpdate(),this._owner.selectedSheet.grid.collectionView.beginUpdate(),(n=this._owner.collectionView.sortDescriptions).clear(),h=this._owner.selection.clone(),d=this._owner.collectionView._view.slice(),r=0;r<d.length;r++)null!=(_=d[r]).index&&(r!==_.index&&this._owner._updateFormulaForReorderingRows(_.index+1,r+1,!0),this._owner._updateCellStyleForReorderingRows(r+1,_.index+1,w));for(Object.keys(w).length>0&&(this._owner.selectedSheet._styledCells=w),g?this._owner.itemsSource.sourceCollection=this._owner.selectedSheet._orgItemsSource.slice():(this._owner.autoGenerateColumns=!1,this._owner.selectedSheet.grid.collectionView.canSort=!0,c=this._owner.selectedSheet._filterDefinition,this._owner.itemsSource=this._owner.selectedSheet._orgItemsSource.slice(),this._synchColumn(),(i=this._owner.selectedSheet.grid.collectionView.sortDescriptions).clear()),this._owner.collectionView.sourceCollection.map(function(e,t){e.index=t}),this._owner.selection=h,navigator.userAgent.toLowerCase().indexOf("chrome")>-1&&(this._owner.collectionView.useStableSort=!0,g||(this._owner.selectedSheet.grid.collectionView.useStableSort=!0)),r=0;r<this._sortDescriptions.itemCount;r++)(t=this._sortDescriptions.items[r]).columnIndex>-1&&(o=new wjcCore.SortDescription(this._owner.columns[t.columnIndex].binding,t.ascending),n.push(o),g||(this._owner.collectionView.sortDescriptions.push(o),i.push(o)));for(this._owner.selectedSheet.selectionRanges.clear(),this._owner.collectionView.endUpdate(),this._owner.selectedSheet.grid.collectionView.endUpdate(),h=this._owner.selection.clone(),u=this._owner.collectionView._view.slice(),g?this._owner.itemsSource.sourceCollection=u:(this._owner.itemsSource=u,this._synchColumn(),c&&(this._owner.filter.filterDefinition=c),this._owner.selectedSheet.grid.collectionView.canSort=!1),r=0;r<u.length;r++)r!==(_=u[r]).index&&this._owner._updateFormulaForReorderingRows(_.index+1,r+1),this._owner._updateCellStyleForReorderingRows(_.index+1,r+1,p);this._owner.selectedSheet._styledCells=p,this._owner.selection=h,this._owner.collectionView.canSort=!1,this._owner.endUpdate(),this._owner._isSorting=!1}else for(l.clear(),r=0;r<this._sortDescriptions.itemCount;r++)(t=this._sortDescriptions.items[r]).columnIndex>-1&&l.push(new _UnboundSortDescription(this._owner.columns[t.columnIndex],t.ascending));s&&(s.saveNewState(),this._owner.undoStack._addAction(s)),this._owner._copiedRanges=null,this._owner._needCopyToSheet=!0}},e.prototype.cancelSort=function(){this._sortDescriptions.sourceCollection=this._committedList.slice()},e.prototype.clearSort=function(){this._sortDescriptions.sourceCollection=[],this.commitSort()},e.prototype._getColumnIndex=function(e){for(var t=0,o=this._owner.columns.length;t<o;t++)if(this._owner.columns[t].binding===e)return t;return-1},e.prototype._getSortItem=function(e){var t=this.checkSortItemExists(e);if(t>-1)return this._sortDescriptions.items[t]},e.prototype._cloneSortList=function(e){for(var t=[],o=0;o<e.length;o++)t[o]=e[o].clone();return t},e.prototype._updateSortSortDescription=function(e,t,o){void 0===o&&(o=!0);var n,i;for(n=this._sortDescriptions.items.length-1;n>=0;n--)i=this._sortDescriptions.items[n],o?i.columnIndex>e&&(i.columnIndex+=t):i.columnIndex>=e+t?i.columnIndex-=t:i.columnIndex>=e&&this._sortDescriptions.remove(i)},e.prototype._synchColumn=function(){var e,t,o;for(this._owner.columns.clear(),e=this._owner.rows[0]instanceof wjcGrid._NewRowTemplate?this._owner.rows[1]:this._owner.rows[0],t=0;t<this._owner.selectedSheet.grid.columns.length;t++)(o=this._owner.selectedSheet.grid.columns[t]).isRequired=!1,this._owner.columns.push(o),e._ubv||(e._ubv={}),e._ubv[o._hash]=o.header},e.prototype._isEmpty=function(e){var t=Object.prototype.hasOwnProperty;if(null==e)return!0;if(e.length>0)return!1;if(0===e.length)return!0;for(var o in e)if(t.call(e,o))return!1;return!0},e}();exports.SortManager=SortManager;var ColumnSortDescription=function(){function e(e,t){this._columnIndex=e,this._ascending=t}return Object.defineProperty(e.prototype,"columnIndex",{get:function(){return this._columnIndex},set:function(e){this._columnIndex=+e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ascending",{get:function(){return this._ascending},set:function(e){this._ascending=e},enumerable:!0,configurable:!0}),e.prototype.clone=function(){return new e(this._columnIndex,this._ascending)},e}();exports.ColumnSortDescription=ColumnSortDescription;var UndoStack=function(){function e(e){this.MAX_STACK_SIZE=500,this._stack=[],this._pointer=-1,this._resizingTriggered=!1,this.undoStackChanged=new wjcCore.Event;var t=this;t._owner=e,t._owner.prepareCellForEdit.addHandler(t._initCellEditAction,t),t._owner.cellEditEnded.addHandler(function(e,o){t._pendingAction&&(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&t._pendingAction instanceof _EditAction&&!t._pendingAction.isPaste&&t._afterProcessCellEditAction(t)},t),t._owner.pasting.addHandler(t._initCellEditActionForPasting,t),t._owner.pastingCell.addHandler(function(e,o){t._pendingAction&&(t._pendingAction instanceof _EditAction?t._pendingAction.updateForPasting(o.range):t._pendingAction instanceof _CutAction&&t._pendingAction.updateForPasting(o.range))},t),t._owner.pasted.addHandler(function(){t._pendingAction&&(t._pendingAction instanceof _EditAction&&t._pendingAction.isPaste?t._afterProcessCellEditAction(t):t._pendingAction instanceof _CutAction&&(t._pendingAction.saveNewState(),t._addAction(t._pendingAction),t._pendingAction=null))},t),t._owner.resizingColumn.addHandler(function(e,o){0!==t.stackSize&&t._owner.selectedSheet&&(t._resizingTriggered||(t._pendingAction=new _ColumnResizeAction(t._owner,o.panel,o.col),t._resizingTriggered=!0))},t),t._owner.resizedColumn.addHandler(function(e,o){t._pendingAction instanceof _ColumnResizeAction&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null,t._resizingTriggered=!1},t),t._owner.resizingRow.addHandler(function(e,o){0!==t.stackSize&&t._owner.selectedSheet&&(t._resizingTriggered||(t._pendingAction=new _RowResizeAction(t._owner,o.panel,o.row),t._resizingTriggered=!0))},t),t._owner.resizedRow.addHandler(function(e,o){t._pendingAction instanceof _RowResizeAction&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null,t._resizingTriggered=!1},t),t._owner.draggingRowColumn.addHandler(function(e,o){0!==t.stackSize&&t._owner.selectedSheet&&o.isShiftKey&&(o.isDraggingRows?t._pendingAction=new _RowsChangedAction(t._owner):t._pendingAction=new _ColumnsChangedAction(t._owner))},t),t._owner.droppingRowColumn.addHandler(function(){t._pendingAction&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null},t)}return Object.defineProperty(e.prototype,"stackSize",{get:function(){return null==this._stackSize?this.MAX_STACK_SIZE:this._stackSize},set:function(e){wjcCore.isNumber(e)&&(e<0?this._stackSize=0:e>this.MAX_STACK_SIZE?this._stackSize=this.MAX_STACK_SIZE:this._stackSize=Math.floor(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"canUndo",{get:function(){return this._pointer>-1&&this._pointer<this._stack.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"canRedo",{get:function(){return this._pointer+1>-1&&this._pointer+1<this._stack.length},enumerable:!0,configurable:!0}),e.prototype.onUndoStackChanged=function(){this.undoStackChanged.raise(this)},e.prototype.undo=function(){var e;this.canUndo&&(e=this._stack[this._pointer],this._beforeUndoRedo(e),e.undo(),this._pointer--,this.onUndoStackChanged())},e.prototype.redo=function(){var e;this.canRedo&&(this._pointer++,e=this._stack[this._pointer],this._beforeUndoRedo(e),e.redo(),this.onUndoStackChanged())},e.prototype._addAction=function(e){this._stack.length>0&&this._stack.length>this._pointer+1&&this._stack.splice(this._pointer+1,this._stack.length-this._pointer-1),this._stack.length>=this.stackSize&&this._stack.splice(0,this._stack.length-this.stackSize+1),this._pointer=this._stack.length,this._stack.push(e),this.onUndoStackChanged()},e.prototype._pop=function(){var e;return this._pointer<0?null:(e=this._stack[this._pointer],this._pointer--,e)},e.prototype.clear=function(){this._stack.length=0},e.prototype._initCellEditAction=function(e,t){0!==this.stackSize&&this._owner.selectedSheet&&(this._pendingAction=new _EditAction(this._owner,t.range))},e.prototype._initCellEditActionForPasting=function(){0!==this.stackSize&&this._owner.selectedSheet&&(this._owner._isCutting?this._pendingAction=new _CutAction(this._owner):(this._pendingAction=new _EditAction(this._owner),this._pendingAction.markIsPaste()))},e.prototype._afterProcessCellEditAction=function(e){e._pendingAction&&(e._pendingAction instanceof _EditAction&&e._pendingAction.saveNewState()&&e._addAction(this._pendingAction),e._pendingAction=null)},e.prototype._beforeUndoRedo=function(e){this._owner.selectedSheetIndex=e.sheetIndex},e}();exports.UndoStack=UndoStack;var Table=function(){function e(e,t,o,n,i){if(this._showHeaderRow=!0,this._showTotalRow=!1,this._showBandedColumns=!1,this._showBandedRows=!0,this._alterFirstColumn=!1,this._alterLastColumn=!1,this._orgHeaderCellsContent=[],!t.isValid)throw"The range of this table is invalid.";this._name=e,this._range=t.clone(),this._style=o,null!=n&&n.length>0&&this._pushTableColumns(n),null!=i&&(null!=i.showHeaderRow&&(this._showHeaderRow=i.showHeaderRow),null!=i.showTotalRow&&(this._showTotalRow=i.showTotalRow),null!=i.showBandedColumns&&(this._showBandedColumns=i.showBandedColumns),null!=i.showBandedRows&&(this._showBandedRows=i.showBandedRows),null!=i.alterFirstColumn&&(this._alterFirstColumn=i.alterFirstColumn),null!=i.alterLastColumn&&(this._alterLastColumn=i.alterLastColumn))}return Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){var t,o;if(null==e||""===e)throw"The name of the Table should not be empty.";this._name.toLowerCase()!==e.toLowerCase()&&(o=this._name,this._name=e,this._owner&&(!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._owner._updateFormulasWithNameUpdating(o,e,!0),t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null)))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"sheet",{get:function(){return this._sheet},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"style",{get:function(){return this._style},set:function(e){var t;e.name!==this._style.name&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._style=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showHeaderRow",{get:function(){return this._showHeaderRow},set:function(e){var t,o;if(e!==this._showHeaderRow&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),o=this._showHeaderRow,this._showHeaderRow=e,this._owner))try{this._owner.beginUpdate(),this._adjustTableRangeWithHeaderRow(),t&&(t.saveNewState(),this._owner.undoStack._addAction(t))}catch(e){throw this._showHeaderRow=o,e}finally{t=null,this._owner.endUpdate()}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showTotalRow",{get:function(){return this._showTotalRow},set:function(e){var t,o;if(e!==this._showTotalRow&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),o=this._showTotalRow,this._showTotalRow=e,this._owner))try{this._owner.beginUpdate(),this._adjustTableRangeWithTotalRow(),t&&(t.saveNewState(),this._owner.undoStack._addAction(t))}catch(e){throw this._showTotalRow=o,e}finally{t=null,this._owner.endUpdate()}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showBandedColumns",{get:function(){return this._showBandedColumns},set:function(e){var t;e!==this._showBandedColumns&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._showBandedColumns=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showBandedRows",{get:function(){return this._showBandedRows},set:function(e){var t;e!==this._showBandedRows&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._showBandedRows=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alterFirstColumn",{get:function(){return this._alterFirstColumn},set:function(e){var t;e!==this._alterFirstColumn&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._alterFirstColumn=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alterLastColumn",{get:function(){return this._alterLastColumn},set:function(e){var t;e!==this._alterLastColumn&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._alterLastColumn=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),e.prototype.getRange=function(e,t){void 0===e&&(e=TableSection.All);var o;switch(e){case TableSection.Data:o=this._getDataRange();break;case TableSection.Header:o=this._getHeaderRange();break;case TableSection.Footer:o=this._getFooterRange();break;default:o=this._range.clone()}if(null!=t&&o){var n=this._getColumnIndex(t);if(null==n)return null;o.col=o.col2=o.leftCol+n}return o},e.prototype.getColumns=function(){return this._columns?this._columns.slice():[]},e.prototype.insertRows=function(e,t,o){void 0===o&&(o=!0);var n,i,r,l,s,a=this.getRange(),h=!1;if(null==t&&(t=1),!wjcCore.isInt(t)||t<1)return!1;if(0===e&&this._showHeaderRow||e===this._range.rowSpan-1&&this._showTotalRow||e<0||e>=this._range.rowSpan)return!1;if(this._owner){if(this._owner.beginUpdate(),l=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid,o){if(r=new wjcGrid.CellRange(a.bottomRow+1,a.col,a.bottomRow+1,a.col2),this._sheet._canShiftCells(r)){if(n=this._sheet._needAddRowCountForInsertTableRows(t,a),l.collectionView){for(s=l.itemsSource instanceof wjcCore.CollectionView,l.collectionView.beginUpdate(),i=0;i<n;i++)s?l.itemsSource.sourceCollection.push({}):l.itemsSource.push({});l.collectionView.endUpdate()}else for(i=0;i<n;i++)l.rows.push(new wjcGrid.Row);this._sheet._moveDownCells(t,r),h=!0}}else this._canInsertRowsWithoutShift(t)&&(h=!0);h&&(this._sheet._moveDownCellsWithinTable(e,t,a),this._updateTableRange(0,t,0,0)),this._owner.endUpdate()}else this._updateTableRange(0,t,0,0),h=!0;return h},e.prototype.deleteRows=function(e,t,o){void 0===o&&(o=!0);var n,i=!1,r=this.getRange();null==t&&(t=1),!wjcCore.isInt(t)||t<1||0===e&&this._showHeaderRow||e===this._range.rowSpan-1&&this._showTotalRow||e<0||e>=this._range.rowSpan||e+t>this._range.rowSpan-(this._showTotalRow?1:0)||(this._owner?(this._owner.beginUpdate(),o?(n=new wjcGrid.CellRange(r.bottomRow+1,r.col,r.bottomRow+1,r.col2),this._sheet._canShiftCells(n)&&(i=!0)):i=!0,i&&(this._sheet._moveUpCellsWithinTable(e,t,r),o&&this._sheet._moveUpCells(t,n),this._updateTableRange(0,-t,0,0)),this._owner.endUpdate()):this._updateTableRange(0,-t,0,0))},e.prototype._addColumn=function(e,t){var o,n=this.getRange();if(e<=0||e>this._columns.length)throw"The column index is out of range.";t=this._getUniqueColumnName(e,t),(o=new TableColumn(t))._attach(this),this._columns.splice(e,0,o),this.showHeaderRow&&this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(n.topRow,n.leftCol+e,t)},e.prototype._updateCell=function(e,t,o){var n,i=e-this._range.topRow,r=t-this._range.leftCol;null!=this._style&&(n=this._getTableCellAppliedStyles(i,r),this._applyStylesForCell(n,o))},e.prototype._updateTableRange=function(e,t,o,n){this._range.row<=this._range.row2?(this._range.row+=e,this._range.row2+=t):(this._range.row2+=e,this._range.row+=t),this._range.col<=this._range.col2?(this._range.col+=o,this._range.col2+=n):(this._range.col2+=o,this._range.col+=n)},e.prototype._setTableRange=function(e,t){var o;if(this._range=e,null!=t)for(this._columns.splice(0,this._columns.length),o=0;o<t.length;o++)this._columns.push(t[o])},e.prototype._updateColumnName=function(e,t){var o=this._columns[e];t=this._getUniqueColumnName(null,t),o.name=t,this._showHeaderRow&&this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(this._range.topRow,this._range.leftCol+e,t)},e.prototype._updateColumnTotalRowContent=function(e,t){var o,n;null==t&&(t=this._columns.indexOf(e)),t<0||(e.totalRowFunction?n=null!=(o=this._getSubtotalFunction(e.totalRowFunction.toLowerCase()))?"=subtotal("+o+",["+e.name+"])":"="===e.totalRowFunction[0]?e.totalRowFunction:"="+e.totalRowFunction:0===t?(e.totalRowLabel||(e.totalRowLabel="Total"),n=e.totalRowLabel):n=e.totalRowLabel,this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(this._range.bottomRow,this._range.leftCol+t,n,!1))},e.prototype._attachSheet=function(e){var t=this.getRange();if(!(this._sheet&&this._owner||(this._sheet=e,this._owner=e._owner,null==this._owner))){if(this._owner._containsMergedCells(this._range,e))throw"Table does not allow the merged cell within the table.";null==this._style&&(this._style=this._owner.getBuiltInTableStyle("TableStyleMedium9")),null!=this._columns&&0!==this._columns.length||this._generateColumns(this._showHeaderRow);try{this._owner.beginUpdate(),this._showHeaderRow&&1===t.rowSpan&&this._adjustTableRangeWithHeaderRow(),this._showTotalRow&&this._updateTotalRow()}finally{this._owner.endUpdate()}}},e.prototype._detachSheet=function(){this._sheet=null,this._owner=null},e.prototype._pushTableColumns=function(e){var t,o;for(this._columns=[],o=0;o<e.length;o++)(t=e[o])._attach(this),this._columns.push(t)},e.prototype._generateColumns=function(e){var t,o,n,i,r,l=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(!this._range.isValid)throw"The range of the table is invalid.";this._columns=[];for(var s=0;s<this._range.columnSpan;s++)i=this._sheet.grid.columns[this._range.leftCol+s],r=this._range.topRow*this._sheet.grid.columns.length+this._range.leftCol+s,1===this._range.rowSpan?t=this._getUniqueColumnName(s+1):(t=this._sheet.grid.getCellData(this._range.topRow,this._range.leftCol+s,!1)||"",wjcCore.isString(t)&&"="===t[0]&&(t=this._owner.evaluate(t,"",this._sheet,!1)),n=this._sheet._styledCells[r],t=this._owner._formatEvaluatedResult(t,i,n?n.format:""),t=this._getUniqueColumnName(s+1,t.toString())),e&&this._range.rowSpan>1&&(this._orgHeaderCellsContent[s]=this._sheet.grid.getCellData(this._range.topRow,this._range.leftCol+s,!1),isNaN(+t)||i.format||n&&n.format||(n?n.format="@":this._sheet._styledCells[r]={format:"@"}),l.setCellData(this._range.topRow,this._range.leftCol+s,t,!1)),(o=new TableColumn(t))._attach(this),0===s?o._totalRowLabel="Total":s===this._range.columnSpan-1&&(o._totalRowFunction="Sum"),this._columns.push(o)},e.prototype._getTableCellAppliedStyles=function(e,t){var o,n={},i=!1,r=!1,l=0;return this._showHeaderRow&&(l=1),this._showHeaderRow&&0===e?i=!0:this._showTotalRow&&e===this._range.rowSpan-1&&(r=!0),this._extendStyle(n,this._style.wholeTableStyle,e,t,i,r),i||r||(!this._showBandedColumns||null==this._style.firstBandedColumnStyle&&null==this._style.secondBandedColumnStyle||(t%((o=this._style.firstBandedColumnStyle?null==this._style.firstBandedColumnStyle.size?1:this._style.firstBandedColumnStyle.size:1)+(this._style.secondBandedColumnStyle?null==this._style.secondBandedColumnStyle.size?1:this._style.secondBandedColumnStyle.size:1))>=o?this._style.secondBandedColumnStyle&&this._extendStyle(n,this._style.secondBandedRowStyle,e,t,i,r):this._style.firstBandedColumnStyle&&this._extendStyle(n,this._style.firstBandedColumnStyle,e,t,i,r)),!this._showBandedRows||null==this._style.firstBandedRowStyle&&null==this._style.secondBandedRowStyle||((e-l)%((o=this._style.firstBandedRowStyle?null==this._style.firstBandedRowStyle.size?1:this._style.firstBandedRowStyle.size:1)+(this._style.secondBandedRowStyle?null==this._style.secondBandedRowStyle.size?1:this._style.secondBandedRowStyle.size:1))>=o?this._style.secondBandedRowStyle&&this._extendStyle(n,this._style.secondBandedRowStyle,e,t,i,r):this._style.firstBandedRowStyle&&this._extendStyle(n,this._style.firstBandedRowStyle,e,t,i,r))),this._alterLastColumn&&t===this._range.columnSpan-1&&this._style.lastColumnStyle&&this._extendStyle(n,this._style.lastColumnStyle,e,t,i,r),this._alterFirstColumn&&0===t&&this._style.firstColumnStyle&&this._extendStyle(n,this._style.firstColumnStyle,e,t,i,r),i?(this._style.headerRowStyle&&this._extendStyle(n,this._style.headerRowStyle,e,t,i,r),t===this._range.columnSpan-1&&this._style.lastHeaderCellStyle&&this._extendStyle(n,this._style.lastHeaderCellStyle,e,t,i,r),0===t&&this._style.firstHeaderCellStyle&&this._extendStyle(n,this._style.firstHeaderCellStyle,e,t,i,r)):r&&(this._style.totalRowStyle&&this._extendStyle(n,this._style.totalRowStyle,e,t,i,r),t===this._range.columnSpan-1&&this._style.lastTotalCellStyle&&this._extendStyle(n,this._style.lastTotalCellStyle,e,t,i,r),0===t&&this._style.firstTotalCellStyle&&this._extendStyle(n,this._style.firstTotalCellStyle,e,t,i,r)),n},e.prototype._applyStylesForCell=function(e,t){var o,n=t.style;for(var i in e)(o=e[i])&&(n[i]=o)},e.prototype._extendStyle=function(e,t,o,n,i,r){var l;for(var s in t)null!==(l=t[s])&&(s.indexOf("borderTop")>-1?(0===o||r)&&(e[s]=l):s.indexOf("borderBottom")>-1?(o===this._range.rowSpan-1||i)&&(e[s]=l):s.indexOf("borderLeft")>-1?0===n&&(e[s]=l):s.indexOf("borderRight")>-1?n===this._range.columnSpan-1&&(e[s]=l):s.indexOf("borderHorizontal")>-1?o<this._range.rowSpan-1&&("borderHorizontalStyle"===s?e.borderBottomStyle=l:"borderHorizontalWidth"===s?e.borderBottomWidth=l:e.borderBottomColor=l):s.indexOf("borderVertical")>-1?n<this._range.columnSpan-1&&("borderVerticalStyle"===s?e.borderRightStyle=l:"borderVerticalWidth"===s?e.borderRightWidth=l:e.borderRightColor=l):e[s]=l)},e.prototype._getSubtotalFunction=function(e){switch(e){case"average":return"101";case"countnums":return"102";case"count":return"103";case"max":return"104";case"min":return"105";case"stddev":return"107";case"sum":return"109";case"var":return"110"}return null},e.prototype._checkColumnNameExist=function(e){var t,o=this.getColumns();for(t=0;t<o.length;t++)if(o[t].name.toLowerCase()===e.toLowerCase())return!0;return!1},e.prototype._adjustTableRangeWithHeaderRow=function(){var e,t,o,n,i=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(this._showHeaderRow){if(this._sheet._needMoveDownTable(this)){if(o=this.getRange(),n=new wjcGrid.CellRange(o.bottomRow+1,o.col,o.bottomRow+1,o.col2),!this._sheet._canShiftCells(n))throw"The operation is not allowed.  The operation is attempting to shift the cells in a table or a merged cell on the current sheet.";1===this._sheet._needAddRowCountForInsertTableRows(1,o)&&(i.collectionView?(i.collectionView.beginUpdate(),i.itemsSource instanceof wjcCore.CollectionView?i.itemsSource.sourceCollection.push({}):i.itemsSource.push({}),i.collectionView.endUpdate()):i.rows.push(new wjcGrid.Row)),this._sheet._moveDownCells(1,n),this._sheet._moveDownTable(this)}for(this._range.row<=this._range.row2?this._range.row-=1:this._range.row2-=1,e=0;e<this._columns.length;e++)t=this._columns[e],this._orgHeaderCellsContent[e]=i.getCellData(this._range.topRow,this._range.leftCol+e,!1),i.setCellData(this._range.topRow,this._range.leftCol+e,t.name)}else{for(e=this._range.leftCol;e<=this._range.rightCol;e++)i.setCellData(this._range.topRow,e,"");this._range.row<=this._range.row2?this._range.row+=1:this._range.row2+=1}},e.prototype._adjustTableRangeWithTotalRow=function(){var e,t,o,n=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(t=this.getRange(),o=new wjcGrid.CellRange(t.bottomRow+1,t.col,t.bottomRow+1,t.col2),this._showTotalRow){if(this._sheet._canShiftCells(o))1===this._sheet._needAddRowCountForInsertTableRows(1,t)&&(n.collectionView?(n.collectionView.beginUpdate(),n.itemsSource instanceof wjcCore.CollectionView?n.itemsSource.sourceCollection.push({}):n.itemsSource.push({}),n.collectionView.endUpdate()):n.rows.push(new wjcGrid.Row)),this._sheet._moveDownCells(1,o),this._owner._updateAffectedFormula(this._range.bottomRow+1,1,!0,!0);else if(!this._beneathRowIsEmpty())throw"The operation is not allowed.  The operation is attempting to shift the cells in a table or a merged cell on the current sheet.";this._range.row<=this._range.row2?this._range.row2+=1:this._range.row+=1,this._updateTotalRow()}else{for(e=this._range.leftCol;e<=this._range.rightCol;e++)n.setCellData(this._range.bottomRow,e,"");this._sheet._canShiftCells(o)&&(this._sheet._moveUpCells(1,o),this._owner._updateAffectedFormula(this._range.bottomRow+1,1,!1,!0)),this._range.row<=this._range.row2?this._range.row2-=1:this._range.row-=1}},e.prototype._updateTotalRow=function(){var e;if(this.showTotalRow)for(var t=0;t<this._columns.length;t++)e=this._columns[t],this._updateColumnTotalRowContent(e,t)},e.prototype._getUniqueColumnName=function(e,t){var o,n=1;if(t||(t="Column"+e),this._checkColumnNameExist(t)){for(o=t+n;this._checkColumnNameExist(o);)o=t+ ++n;t=o}return t},e.prototype._moveColumns=function(e,t){if(this._columns){var o=this._columns[e];this._columns.splice(e,1),t<0&&(t=this._columns.length),this._columns.splice(t,0,o)}},e.prototype._canInsertRowsWithoutShift=function(e){var t,o,n,i,r,l=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(this._range.bottomRow+e>=l.rows.length)return!1;for(t=1;t<=e;t++)for(o=this._range.bottomRow+t,n=this._range.leftCol;n<=this._range.rightCol;n++)if(i=l.getCellData(o,n,!1),r=this._sheet.getCellStyle(o,n),null!=i&&""!==i||null!=r)return!1;return!0},e.prototype._beneathRowIsEmpty=function(){var e,t,o,n=this._range.bottomRow+1,i=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(n>=i.rows.length)return!1;for(e=this._range.leftCol;e<=this._range.rightCol;e++){if(null!=(t=i.getCellData(this._range.bottomRow+1,e,!1))&&""!==t)return!1;if(null!=this._sheet.getCellStyle(this._range.bottomRow+1,e))return!1;if(null!=this._sheet.findTable(n,e))return null;if(o=n*i.columns.length+e,null!=this._sheet._mergedRanges[o])return!1}return!0},e.prototype._getDataRange=function(){var e=this._range.topRow,t=this._range.bottomRow;return this._showHeaderRow&&(e+=1),this._showTotalRow&&(t-=1),new wjcGrid.CellRange(e,this._range.leftCol,t,this._range.rightCol)},e.prototype._getHeaderRange=function(){return this._showHeaderRow?new wjcGrid.CellRange(this._range.topRow,this._range.leftCol,this._range.topRow,this._range.rightCol):null},e.prototype._getFooterRange=function(){return this._showTotalRow?new wjcGrid.CellRange(this._range.bottomRow,this._range.leftCol,this._range.bottomRow,this._range.rightCol):null},e.prototype._getColumnIndex=function(e){var t,o,n;if(wjcCore.isInt(e)&&e>=0&&e<this._columns.length)t=e;else{e instanceof TableColumn?o=e.name.toLowerCase():wjcCore.isString(e)&&""!==e&&(o=e.toLowerCase()),n=this.getColumns();for(var i=0;i<n.length;i++)if(n[i].name.toLowerCase()===o){t=i;break}}return t},e}();exports.Table=Table;var TableColumn=function(){function e(e,t,o,n){void 0===n&&(n=!0),this._name=e,this._totalRowLabel=t,this._totalRowFunction=o,null!=n&&(this._showFilterButton=n)}return Object.defineProperty(e.prototype,"table",{get:function(){return this._table},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){e!==this._name&&(this._name=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"totalRowLabel",{get:function(){return this._totalRowLabel},set:function(e){e!==this._totalRowLabel&&(this._totalRowLabel=e,this._updateTableTotalInfo())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"totalRowFunction",{get:function(){return this._totalRowFunction},set:function(e){e!==this._totalRowFunction&&(this._totalRowFunction=e,this._updateTableTotalInfo())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showFilterButton",{get:function(){return this._showFilterButton},set:function(e){this._showFilterButton!==e&&(this._showFilterButton=e)},enumerable:!0,configurable:!0}),e.prototype._attach=function(e){this._table=e},e.prototype._updateTableTotalInfo=function(){this._table&&this._table.showTotalRow&&(this._table._updateColumnTotalRowContent(this),this._table._owner&&this._table._owner.refresh())},e}();exports.TableColumn=TableColumn;var TableStyle=function(){function e(e,t){void 0===t&&(t=!1),this._name=e,this._isBuiltIn=t}return Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){e!==this._name&&(this._name=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"wholeTableStyle",{get:function(){return this._wholeTableStyle},set:function(e){this._wholeTableStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstBandedColumnStyle",{get:function(){return this._firstBandedColumnStyle},set:function(e){this._firstBandedColumnStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"secondBandedColumnStyle",{get:function(){return this._secondBandedColumnStyle},set:function(e){this._secondBandedColumnStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstBandedRowStyle",{get:function(){return this._firstBandedRowStyle},set:function(e){this._firstBandedRowStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"secondBandedRowStyle",{get:function(){return this._secondBandedRowStyle},set:function(e){this._secondBandedRowStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstColumnStyle",{get:function(){return this._firstColumnStyle},set:function(e){this._firstColumnStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"lastColumnStyle",{get:function(){return this._lastColumnStyle},set:function(e){this._lastColumnStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"headerRowStyle",{get:function(){return this._headerRowStyle},set:function(e){this._headerRowStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"totalRowStyle",{get:function(){return this._totalRowStyle},set:function(e){this._totalRowStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstHeaderCellStyle",{get:function(){return this._firstHeaderCellStyle},set:function(e){this._firstHeaderCellStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"lastHeaderCellStyle",{get:function(){return this._lastHeaderCellStyle},set:function(e){this._lastHeaderCellStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstTotalCellStyle",{get:function(){return this._firstTotalCellStyle},set:function(e){this._firstTotalCellStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"lastTotalCellStyle",{get:function(){return this._lastTotalCellStyle},set:function(e){this._lastTotalCellStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isBuiltIn",{get:function(){return this._isBuiltIn},enumerable:!0,configurable:!0}),e}();exports.TableStyle=TableStyle;var TableSection;!function(e){e[e.All=0]="All",e[e.Data=1]="Data",e[e.Header=2]="Header",e[e.Footer=3]="Footer"}(TableSection=exports.TableSection||(exports.TableSection={}));var FlexSheetValueFilter=function(e){function t(t){return e.call(this,t)||this}return __extends(t,e),t.prototype.apply=function(e){var t,o=this.column.grid;return!(o instanceof FlexSheet)||(!this.showValues||!Object.keys(this.showValues).length||(o.rows[e]instanceof wjcGrid._NewRowTemplate||(t=this.dataMap||this.column.dataMap,e=t?t.getDisplayValue(o.getCellValue(e,this.column.index)):o.getCellValue(e,this.column.index,!0),void 0!=this.showValues[e])))},t}(wjcGridFilter.ValueFilter);exports.FlexSheetValueFilter=FlexSheetValueFilter;var FlexSheetValueFilterEditor=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.updateEditor=function(){var t,o,n,i,r,l,s,a,h,c=this.filter.column,d=c.grid,u=c.index,_=[],g={};if(this.filter.uniqueValues||null!=d.itemsSource&&null!=d.childItemsPath)e.prototype.updateEditor.call(this);else{for(f=0;f<d.rows.length;f++)r=this.filter.apply(f),i=this.filter.showValues,this.filter.showValues=null,l=d.filter._filter(f),this.filter.showValues=i,(!(o=d.getMergedRange(d.cells,f,u))||f===o.topRow&&u===o.leftCol)&&((t=d.rows[f])instanceof HeaderRow||t instanceof wjcGrid.GroupRow||t instanceof wjcGrid._NewRowTemplate||!(t.visible||!r&&l)||(n=d.getCellValue(f,u),s=this.filter.dataMap?this.filter.dataMap.getDisplayValue(n):d.getCellValue(f,u,!0),n=""===n?null:n,a=d.getCellData(f,u,!0),g[s]||(g[s]=!0,h=a&&"="===a[0]?f+"_"+u:"",_.push({value:n,text:s,cellRef:h}))));var w=this.filter.showValues;if(w&&0!=Object.keys(w).length){for(var p in w)for(f=0;f<_.length;f++)if(w[p]&&""!==_[f].cellRef&&_[f].cellRef===w[p].cellRef)w[_[f].text]={show:!0,cellRef:_[f].cellRef},_[f].show=!0,delete w[p];else if(_[f].text==p){_[f].show=!0;break}}else for(var f=0;f<_.length;f++)_[f].show=!0;this._lbValues.isContentHtml=c.isContentHtml,this._cmbFilter.text=this.filter.filterText,this._filterText=this._cmbFilter.text.toLowerCase(),this._view.pageSize=this.filter.maxValues,this._view.sourceCollection=_,this._view.moveCurrentToPosition(-1)}},t.prototype.updateFilter=function(){var e=null,t=this._view.items;if(this._filterText||this._cbSelectAll.indeterminate){e={};for(var o=0;o<t.length;o++){var n=t[o];n.show&&(e[n.text]={show:!0,cellRef:n.cellRef})}}this._filter.showValues=e,this._filter.filterText=this._filterText},t}(wjcGridFilter.ValueFilterEditor);exports.FlexSheetValueFilterEditor=FlexSheetValueFilterEditor;var FlexSheetConditionFilter=function(e){function t(t){return e.call(this,t)||this}return __extends(t,e),t.prototype.apply=function(e){var t,o,n,i,r=this.column,l=r.grid,s=this.condition1,a=this.condition2;if(!(l instanceof FlexSheet))return!0;if(!this.isActive)return!0;if(l.rows[e]instanceof wjcGrid._NewRowTemplate)return!0;""===(t=l.getCellValue(e,r.index))&&r.dataType!==wjcCore.DataType.String&&(t=null),o=n=t,(i=this.dataMap||r.dataMap)?o=n=t=i.getDisplayValue(t):wjcCore.isDate(t)?(wjcCore.isString(s.value)||wjcCore.isString(a.value))&&(o=n=t=l.getCellValue(e,r.index,!0)):wjcCore.isNumber(t)&&(o=n=t=wjcCore.Globalize.parseFloat(l.getCellValue(e,r.index,!0)),0!==t||r.dataType||(s.isActive&&""===s.value&&(o=t.toString()),a.isActive&&""===a.value&&(n=n.toString())));var h=s.apply(o),c=a.apply(n);return s.isActive&&a.isActive?this.and?h&&c:h||c:s.isActive?h:!a.isActive||c},t}(wjcGridFilter.ConditionFilter);exports.FlexSheetConditionFilter=FlexSheetConditionFilter;var FlexSheetColumnFilter=function(e){function t(t,o){var n=e.call(this,t,o)||this;return n._valueFilter=new FlexSheetValueFilter(o),n._conditionFilter=new FlexSheetConditionFilter(o),n}return __extends(t,e),t}(wjcGridFilter.ColumnFilter);exports.FlexSheetColumnFilter=FlexSheetColumnFilter;var FlexSheetColumnFilterEditor=function(e){function t(t,o,n){void 0===n&&(n=!0);var i,r,l=e.call(this,t,o,n)||this,s=l;return n&&(l._divSort.style.display=""),i=l.cloneElement(l._btnAsc),r=l.cloneElement(l._btnDsc),l._btnAsc.parentNode.replaceChild(i,l._btnAsc),l._btnDsc.parentNode.replaceChild(r,l._btnDsc),i.addEventListener("click",function(e){s._sortBtnClick(e,!0)}),r.addEventListener("click",function(e){s._sortBtnClick(e,!1)}),l}return __extends(t,e),t.prototype._showFilter=function(t){t==wjcGridFilter.FilterType.Value&&null==this._edtVal&&(this._edtVal=new FlexSheetValueFilterEditor(this._divEdtVal,this.filter.valueFilter)),e.prototype._showFilter.call(this,t)},t.prototype._sortBtnClick=function(e,t){var o,n,i=this.filter.column,r=i.grid.sortManager;e.preventDefault(),e.stopPropagation(),(o=r.checkSortItemExists(i.index))>-1?(r.sortDescriptions.moveCurrentToPosition(o),r.sortDescriptions.currentItem.ascending=t,n=-o):(r.addSortLevel(i.index,t),n=-(r.sortDescriptions.items.length-1)),r.moveSortLevel(n),r.commitSort(),this.updateEditor(),this.onButtonClicked()},t.prototype.cloneElement=function(e){for(var t=e.cloneNode();e.firstChild;)t.appendChild(e.lastChild);return t},t}(wjcGridFilter.ColumnFilterEditor);exports.FlexSheetColumnFilterEditor=FlexSheetColumnFilterEditor;var FlexSheetFilter=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),Object.defineProperty(t.prototype,"filterDefinition",{get:function(){for(var e={filters:[]},t=0;t<this._filters.length;t++){var o=this._filters[t];if(o&&o.column)if(o.conditionFilter.isActive){var n=o.conditionFilter;e.filters.push({columnIndex:o.column.index,type:"condition",condition1:{operator:n.condition1.operator,value:n.condition1.value},and:n.and,condition2:{operator:n.condition2.operator,value:n.condition2.value}})}else if(o.valueFilter.isActive){var i=o.valueFilter;e.filters.push({columnIndex:o.column.index,type:"value",filterText:i.filterText,showValues:i.showValues})}}return JSON.stringify(e)},set:function(e){var t=JSON.parse(wjcCore.asString(e));this.clear();for(var o=0;o<t.filters.length;o++){var n=t.filters[o],i=this.grid.columns[n.columnIndex],r=this.getColumnFilter(i,!0);if(r)switch(n.type){case"condition":var l=r.conditionFilter;l.condition1.value=i.dataType==wjcCore.DataType.Date?wjcCore.changeType(n.condition1.value,i.dataType,null):n.condition1.value,l.condition1.operator=n.condition1.operator,l.and=n.and,l.condition2.value=i.dataType==wjcCore.DataType.Date?wjcCore.changeType(n.condition2.value,i.dataType,null):n.condition2.value,l.condition2.operator=n.condition2.operator;break;case"value":var s=r.valueFilter;s.filterText=n.filterText,s.showValues=n.showValues}}this.apply()},enumerable:!0,configurable:!0}),t.prototype.apply=function(){var e=this;e.grid.deferUpdate(function(){for(var t,o,n,i=-1,r=0;r<e.grid.rows.length;r++)if(!((t=e.grid.rows[r])instanceof HeaderRow||r<=i))if(i=-1,o=e._filter(r),t instanceof wjcGrid.GroupRow){if(n=t.getCellRange(),null==t.dataItem||t.dataItem instanceof wjcCore.CollectionViewGroup)t.visible=e._checkGroupVisible(n);else if(t.visible=o,i=n.bottomRow,n.isValid)for(var l=n.topRow;l<=n.bottomRow;l++)e.grid.rows[l].visible=o}else t.visible=o;e.grid._isCopying||e.grid._isUndoing||e.grid._isSorting||e.onFilterApplied()})},t.prototype.editColumnFilter=function(e,t){var o=this,n=o.grid;o.closeEditor(),e=o._asColumn(e);var i=document.createElement("div"),r=o.getColumnFilter(e),l=new FlexSheetColumnFilterEditor(i,r,o.showSortButtons);wjcCore.addClass(i,"wj-dropdown-panel"),o._divEdt=i,o._edtCol=e;var s=new wjcGrid.CellRangeEventArgs(n.cells,new wjcGrid.CellRange(-1,e.index));if(o.onFilterChanging(s),s.cancel)return o._divEdt=null,void(o._edtCol=null);s.cancel=!0,n.undoStack.stackSize>0&&(o._undoAcion=new _FilteringAction(n)),n.rightToLeft&&(i.dir="rtl"),l.filterChanged.addHandler(function(){s.cancel=!1,o._filterChanged=!0,setTimeout(function(){s.cancel||(o.apply(),o._undoAcion&&(o._undoAcion.saveNewState(),n.undoStack._addAction(o._undoAcion),o._undoAcion=null))})}),l.buttonClicked.addHandler(function(){o.closeEditor(),n.focus(),o.onFilterChanged(s)}),l.lostFocus.addHandler(function(){setTimeout(function(){var e=wjcCore.Control.getControl(o._divEdt);e&&!e.containsFocus()&&o.closeEditor()},10)}),n._edtHdl._commitRowEdits(),n.scrollIntoView(-1,e.index,!0);var a=o.grid.columnHeaders,h=t?t.row:a.rows.length-1,c=t?t.col:e.index,d=a.getCellBoundingRect(h,c),u=document.elementFromPoint(d.left+d.width/2,d.top+d.height/2);(u=wjcCore.closest(u,".wj-cell"))?wjcCore.showPopup(i,u,!1,!1,!1):wjcCore.showPopup(i,d),o._setAriaExpanded(u,!0),o._setAriaExpanded(n.cells.getCellElement(-1,c),!0);for(var _=l.hostElement.querySelectorAll("input"),g=0;g<_.length;g++){var w=_[g];if(w.offsetHeight>0&&w.tabIndex>-1&&!w.disabled){w.focus();break}}l.containsFocus()||l.focus()},t.prototype.closeEditor=function(){this._undoAcion&&!this._filterChanged&&(this._undoAcion=null),e.prototype.closeEditor.call(this)},t.prototype.getColumnFilter=function(e,t){if(void 0===t&&(t=!0),wjcCore.isString(e)?e=this.grid.columns.getColumn(e):wjcCore.isNumber(e)&&(e=this.grid.columns[e]),!e)return null;e=wjcCore.asType(e,wjcGrid.Column);for(var o=0;o<this._filters.length;o++)if(this._filters[o].column==e)return this._filters[o];if(t){var n=new FlexSheetColumnFilter(this,e);return this._filters.push(n),n}return null},t.prototype._checkGroupVisible=function(e){for(var t,o=!0,n=e.topRow+1;n<=e.bottomRow;n++)if(t=this.grid.rows[n])if(t instanceof wjcGrid.GroupRow)o=this._checkGroupVisible(t.getCellRange());else if(o=this._filter(n))break;return o},t}(wjcGridFilter.FlexGridFilter);exports.FlexSheetFilter=FlexSheetFilter;