@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
1 lines • 14.8 kB
JavaScript
module.exports=function(r){var n={};function i(e){if(n[e])return n[e].exports;var t=n[e]={exports:{},id:e,loaded:!1};return r[e].call(t.exports,t,t.exports,i),t.loaded=!0,t.exports}return i.m=r,i.c=n,i.p="",i(0)}({0:function(e,t,r){e.exports=r(1723)},3:function(e,t){e.exports=function(){throw Error("define cannot be used indirect")}},20:function(e,t){e.exports=require("../kendo.core")},958:function(e,t){e.exports=require("../util/text-metrics")},1718:function(e,t){e.exports=require("../util/main")},1723:function(e,t,r){var n;r(3),r=[r(20),r(958),r(1718)],void 0===(t="function"==typeof(n=function(){var d=window.kendo,u=d.jQuery,p=d.spreadsheet.UnionRef,c=d.spreadsheet.CellRef,h=d.spreadsheet.RangeRef,i=["color","fontFamily","underline","italic","bold","textAlign","indent","verticalAlign","background","format","link","editor","borderTop","borderRight","borderBottom","borderLeft","comment","html"],r=d.Class.extend({init:function(e,t){this._sheet=t;this._ref=e},clone:function(){return new r(this._ref.clone(),this._sheet)},skipHiddenCells:function(){var s=[];var f=this,e=f._sheet;var u=e.isHiddenRow.bind(e);var l=e.isHiddenColumn.bind(e);f._ref.forEach(function(e){e=f._normalize(e.toRangeRef());var t=e.topLeft,r=e.bottomRight;var n=_(t.row,r.row,u);var i=_(t.col,r.col,l);for(var o=0;o<n.length;++o)for(var a=0;a<i.length;++a)s.push(new h(new c(n[o].begin,i[a].begin),new c(n[o].end,i[a].end)))});return e.range(s.length>1?new p(s):s[0])},_normalize:function(e){return this._sheet._grid.normalize(e)},_set:function(i,o,e){var t=this;var a=t._sheet;t._ref.forEach(function(e){var t=e;var r=i==="value"||i==="formula"||i==="link";if(r&&e.topLeft){var n=new c(e.topLeft.row,e.topLeft.col);a.forEachMergedCell(function(e){if(e.intersects(n))t=n})}a._set(t.toRangeRef(),i,o)});if(!e)a.triggerChange({recalc:i=="formula"||i=="value"||i=="validation",value:o,range:t,ref:t._ref,isValue:i=="value"});return t},_get:function(e){return this._sheet._get(this._ref.toRangeRef(),e)},_property:function(e,t){if(t===undefined)return this._get(e);else return this._set(e,t)},value:function(e){if(e!==undefined)this._set("formula",null,true);return this._property("value",e)},html:function(e){return this._property("html",e)},resize:function(e){var t=this._resizedRef(e);return new r(t,this._sheet)},_resizedRef:function(t){return this._ref.map(function(e){return e.toRangeRef().resize(t)})},input:function(r,n){n=u.extend({arrayFormula:false},n);var i=this._get("format"),o;if(r!==undefined){var e=this._ref.toRangeRef().topLeft;o=d.spreadsheet.calc.parse(this._sheet.name(),e.row,e.col,r,i);this._sheet.batch(function(){var e=null;if(o.type=="exp")e=d.spreadsheet.calc.compile(o);else if(i!="@"){var t=i&&d.spreadsheet.formatting.type(o.value,i);if(o.type=="date"&&t!="date")this.format(o.format||l(d.culture().calendar.patterns.d));else if(o.type=="percent"&&t!="percent")this.format(o.value*100==(o.value*100|0)?"0%":"0.00%");else if(o.format)if(!i||o.currency||t=="number"&&o.type=="number"&&o.format.length>i.length)this.format(o.format)}else if(o.type!="string")o.value=r;this.formula(e,n.arrayFormula);if(!e)this.value(o.value)}.bind(this),{recalc:true,value:r,ref:this._ref,editorChange:this._sheet.isInEditMode(),isValue:true});return this}else{r=this._get("value");var t=this._get("formula");var a=i&&!t&&d.spreadsheet.formatting.type(r,i);if(t)r="="+t;else e:{if(i&&a=="date"){var s=d.spreadsheet.formatting.text(r,i);o=d.spreadsheet.calc.parse(null,null,null,s,i);var f=d.spreadsheet.formatting.text(o.value,i);if(s==f){r=s;break e}}if(a==="date")r=d.toString(d.spreadsheet.numberToDate(r),d.culture().calendar.patterns.d);else if(a==="percent")r=d.spreadsheet.calc.runtime.limitPrecision(r*100)+"%";else if(typeof r=="string"&&(/^[=']/.test(r)||/^(?:true|false)$/i.test(r)||v(r)))r="'"+r;else if(this._sheet._useCultureDecimals()&&typeof r=="number"&&r!=Math.floor(r))r=String(r).replace(".",d.culture().numberFormat["."])}return r}},enable:function(e){if(e===undefined)return!d.util.withExit(function(n){this._sheet.forEach(this._ref,function(e,t,r){if(r.enable===false)n(true)})},this);return this._property("enable",e)},formula:function(e,t){var r=this;if(e===undefined){var n=r._get("formula");return n?""+n:null}if(t){var i=this._ref.toRangeRef();e=r._sheet.range(i.topLeft)._set("formula",e)._get("formula");if(e)e.setArrayFormulaRange(i)}else r._set("formula",e);return r},intersectingArrayFormula:function(){var n=this._ref.clone().simplify().setSheet(this._sheet.name());return d.util.withExit(function(r){this._sheet._forFormulas(function(e){var t=e.arrayFormulaRange;if(t&&(t=n.intersect(t))!==d.spreadsheet.NULLREF)r({formula:e,intersection:t})})},this)},canEditArrayFormula:function(){var e=this.intersectingArrayFormula();if(e)return e.formula.arrayFormulaRange.eq(e.intersection);return true},validation:function(e){if(e===undefined){var t=this._get("validation");return t?t.toJSON():null}return this._property("validation",e)},_getValidationState:function(){var e=this._ref.toRangeRef();var t=e.topLeft.row;var r=e.topLeft.col;var n=e.bottomRight.row;var i=e.bottomRight.col;var o,a;for(o=r;o<=i;o++)for(a=t;a<=n;a++){var s=this._sheet._validation(a,o);if(s&&s.type==="reject"&&s.value===false)return s}return false},merge:function(){this._ref=this._sheet._merge(this._ref);return this},unmerge:function(){var t=this._sheet._mergedCells;this._ref.forEach(function(e){e.toRangeRef().intersecting(t).forEach(function(e){t.splice(t.indexOf(e),1)})});this._sheet.triggerChange({});return this},select:function(){this._sheet.select(this._ref);return this},values:function(e){if(this._ref instanceof p)throw new Error("Unsupported for multiple ranges.");if(this._ref===d.spreadsheet.NULLREF)if(e!==undefined)throw new Error("Unsupported for NULLREF.");else return[];var t=this._ref.toRangeRef();var r=t.topLeft.row;var n=t.topLeft.col;var i=t.bottomRight.row;var o=t.bottomRight.col;var a,s;if(e===undefined){e=new Array(t.height());for(var f=0;f<e.length;f++)e[f]=new Array(t.width());for(a=n;a<=o;a++)for(s=r;s<=i;s++)e[s-r][a-n]=this._sheet._value(s,a);return e}else{this._sheet._set(t,"formula",null);for(a=n;a<=o;a++)for(s=r;s<=i;s++){var u=e[s-r];if(u){var l=u[a-n];if(l!==undefined)this._sheet._value(s,a,l)}}this._sheet.triggerChange({recalc:true,ref:t});return this}},_properties:function(i,e){if(this._ref instanceof p)throw new Error("Unsupported for multiple ranges.");if(this._ref===d.spreadsheet.NULLREF)if(i!==undefined)throw new Error("Unsupported for NULLREF.");else return[];var r=this._ref.toRangeRef();var o=r.topLeft.row;var a=r.topLeft.col;var l=r.bottomRight.row;var h=r.bottomRight.col;var n,s;var f=this._sheet;if(i===undefined){i=new Array(r.height());f.forEach(r,function(e,t,r){e-=o;t-=a;var n=i[e]||(i[e]=[]);n[t]=r});return i}else{var u;r=r.clone();var c=function(e){var t=u[e];r.topLeft.row=r.bottomRight.row=s;r.topLeft.col=r.bottomRight.col=n;if(e=="value")f._set(r,"formula",null);f._set(r,e,t)};for(n=a;n<=h;n++){if(!e&&f.isHiddenColumn(n))continue;for(s=o;s<=l;s++){if(!e&&f.isHiddenRow(s))continue;if(e&&f.isFilteredRow(s))continue;var t=i[s-o];if(t){u=t[n-a];if(u)Object.keys(u).forEach(c)}}}f.triggerChange({recalc:true,ref:this._ref});return this}},clear:function(t){t=t||{};var e=t.clearAll||!Object.keys(t).length;var r=this._sheet;var n={recalc:e||t.contentsOnly,ref:this._ref};r.batch(function(){if(n.recalc)this.formula(null);if(e)this.validation(null);if(e||t.formatOnly){i.forEach(function(e){if(!(t.keepBorders&&/^border/i.test(e)))this[e](null)}.bind(this));this.fontSize(null);this.wrap(null);this.unmerge()}}.bind(this),n);return this},clearContent:function(){return this.clear({contentsOnly:true})},clearFormat:function(){return this.clear({formatOnly:true})},isSortable:function(){return!this.cantSort()},cantSort:function(){if(this._ref instanceof p)return{code:"cantSortMultipleSelection",message:"Unsupported for multiple ranges."};if(this._ref===d.spreadsheet.NULLREF)return{code:"cantSortNullRef",message:"Unsupported for NULLREF."};var i=this._sheet._getMergedCells(this._ref.toRangeRef());var o=i.primary;var a=i.secondary;var s=null,f=null;var u={};try{this._sheet.forEach(this,function(e,t){var r=new c(e,t).print();var n=o[r];if(n){if(s===null){s=n.width();f=n.height()}else if(!(s==n.width()&&f==n.height()))throw u}else if(!a[r]&&i.hasMerged)throw u})}catch(e){if(e!==u)throw e;return{code:"cantSortMixedCells",message:"Unsupported for range containing cells of different shapes."}}return false},sort:function(e){var t=this.cantSort();if(t)throw new Error(t.message);if(e===undefined)e={column:0};e=e instanceof Array?e:[e];this._sheet._sortBy(this._ref.toRangeRef(),e.map(function(e,t){if(typeof e==="number")e={column:e};return{index:e.column===undefined?t:e.column,ascending:e.ascending===undefined?true:e.ascending}}));return this},isFilterable:function(){return!(this._ref instanceof p)},filter:function(e){if(this._ref instanceof p)throw new Error("Unsupported for multiple ranges.");if(e===false)this.clearFilters();else{e=e===true?[]:e instanceof Array?e:[e];this._sheet._filterBy(this._ref.toRangeRef(),e.map(function(e,t){return{index:e.column===undefined?e.index===undefined?t:e.index:e.column,filter:e.filter}}))}return this},clearFilter:function(e){this._sheet.clearFilter(e)},clearFilters:function(){var e=this._sheet.filter();var t=[];if(e){for(var r=0;r<e.columns.length;r++)t.push(e.columns[r].index);this._sheet.batch(function(){this.clearFilter(t);this._filter=null},{layout:true,filter:true})}},hasFilter:function(){var e=this._sheet.filter();return!!e},leftColumn:function(){return new r(this._ref.leftColumn(),this._sheet)},rightColumn:function(){return new r(this._ref.rightColumn(),this._sheet)},topRow:function(){return new r(this._ref.topRow(),this._sheet)},bottomRow:function(){return new r(this._ref.bottomRow(),this._sheet)},column:function(e){return new r(this._ref.toColumn(e),this._sheet)},row:function(e){return new r(this._ref.toRow(e),this._sheet)},forEachRow:function(t){this._ref.forEachRow(function(e){t(new r(e,this._sheet))}.bind(this))},forEachColumn:function(t){this._ref.forEachColumn(function(e){t(new r(e,this._sheet))}.bind(this))},sheet:function(){return this._sheet},topLeft:function(){return this._ref.toRangeRef().topLeft},intersectingMerged:function(){var e=this._sheet;var t=[];e._mergedCells.forEach(function(e){if(e.intersects(this._ref))t.push(e.toString())}.bind(this));return t},getState:function(e){var a=this._ref.first();var t={ref:a,data:[],origRef:this._ref,rows:this._sheet._rows.getState()};var s;if(!e){s=d.spreadsheet.ALL_PROPERTIES;t.mergedCells=this.intersectingMerged()}else if(e==="input")s=["value","formula"];else if(e==="border")s=["borderLeft","borderTop","borderRight","borderBottom"];else s=[e];var f=t.data;this.forEachCell(function(e,t,r){var n={};var i=e-a.row;var o=t-a.col;if(!f[i])f[i]=[];f[i][o]=n;s.forEach(function(e){var t=typeof r[e]=="undefined"?null:r[e];if(t instanceof d.spreadsheet.calc.runtime.Formula||t instanceof d.spreadsheet.validation.Validation)t=t.deepClone();n[e]=t})});return t},setState:function(f,u){var l=this._sheet;var h=this._ref.first();var t=f.ref.row-h.row;var r=f.ref.col-h.col;var c=u&&!u.isExternal();var d=u&&!c;l.batch(function(){if(f.mergedCells)this.unmerge();if(!u)this._sheet._rows.setState(f.rows);var a=h.row;var s=this.hasFilter();f.data.forEach(function(e,i){if(s&&c&&l.isHiddenRow(f.ref.row+i))return;var o=h.col;e.forEach(function(t,e){if(s&&c&&l.isHiddenColumn(f.ref.col+e))return;var r=u?l.range(a,o):l.range(h.row+i,h.col+e);if(r.enable()){for(var n in t)if(n!="value")if(!(u&&n=="enable"))r._set(n,t[n]);if(!t.formula)if(d)try{if(t.value==null)r._set("value",null);else r.input(t.value)}catch(e){r._set("value",t.value)}else r._set("value",t.value)}o++});a++});if(f.mergedCells)f.mergedCells.forEach(function(e){e=l._ref(e).relative(t,r,3);l.range(e).merge()},this)}.bind(this),{recalc:true,ref:this._ref})},_adjustRowHeight:function(){var e=this;var u=e._sheet;var t=u._getMergedCells(e._ref.toRangeRef());var l=t.primary;var h=t.secondary;u.batch(function(){e.forEachRow(function(e){var t=e._ref.topLeft.row;var f=u.rowHeight(t);if(!f)return;e.forEachCell(function(e,t,r){var n=new c(e,t).print();if(h[n])return;var i=l[n];var o;if(i)o=u._columns.sum(i.topLeft.col,i.bottomRight.col);else o=u.columnWidth(t);var a=r.value;if(r.format&&a!=null)a=d.spreadsheet.formatting.format(a,r.format);var s=d.spreadsheet.util.getTextHeight(a,o,r.fontFamily,r.fontSize,r.wrap);f=Math.max(f,s)});u.rowHeight(t,f)})},{layout:true})},forEachCell:function(t){this._ref.forEach(function(e){this._sheet.forEach(e.toRangeRef(),t.bind(this))}.bind(this))},hasValue:function(){var a=this._sheet._defaultCellStyle;return d.util.withExit(function(o){this.forEachCell(function(e,t,r){for(var n in r){var i=r[n];if(i!==undefined&&i!==null&&i!==a[n])o(true)}})},this)},wrap:function(e){if(e===undefined)return!!this._property("wrap");this._property("wrap",e);if(e!==null)this._adjustRowHeight();return this},fontSize:function(e){if(e===undefined)return this._property("fontSize");this._property("fontSize",e);if(e!==null)this._adjustRowHeight();return this},draw:function(e,t){this._sheet.draw(this,e,t)},insideBorders:function(e){return this.insideVerticalBorders(e).insideHorizontalBorders(e)},insideVerticalBorders:function(t){this._ref.forEach(function(e){if(e instanceof h&&e.width()>1){e=e.clone();e.topLeft.col++;this._sheet.range(e)._set("vBorders",t)}},this);return this},insideHorizontalBorders:function(t){this._ref.forEach(function(e){if(e instanceof h&&e.height()>1){e=e.clone();e.topLeft.row++;this._sheet.range(e)._set("hBorders",t)}},this);return this}});function _(e,t,r){while(e<=t&&r(e))e++;if(e>t)return[];for(var n=e+1;n<=t;++n)if(r(n))return[{begin:e,end:n-1}].concat(_(n+1,t,r));return[{begin:e,end:t}]}function l(e){return e.replace(/M/g,"m").replace(/'/g,'"').replace(/tt/,"am/pm")}function v(e){return!/^=/.test(e)&&/number|percent/.test(d.spreadsheet.calc.parse(null,0,0,e).type)}u.each(i,function(e,t){r.prototype[t]=function(e){return this._property(t,e)}});var a=u('<div style="position: absolute !important; top: -4000px !important; height: auto !important;'+"padding: 1px 3px !important; box-sizing: border-box; margin: 0 !important; border: 1px solid black !important;"+"line-height: normal !important; visibility: hidden !important;"+'white-space: pre-wrap;"></div>')[0];function e(e,t,r,n,i){var o={baselineMarkerSize:0,width:i===true?t+"px":"auto","font-size":(n||12)+"px","font-family":r||"Arial","white-space":i===true?"pre-wrap":"pre","overflow-wrap":i===true?"break-word":"normal","word-wrap":i===true?"break-word":"normal"};return d.util.measureText(e,o,{box:a,normalizeText:false}).height}d.spreadsheet.util={getTextHeight:e},d.spreadsheet.Range=r})?n.apply(t,r):n)||(e.exports=t)}});