UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

1 lines 11.6 kB
module.exports=function(t){function e(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return t[n].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}({0:function(t,e,i){i(1514),t.exports=i(1514)},3:function(t,e){t.exports=function(){throw Error("define cannot be used indirect")}},19:function(t,e){t.exports=require("../kendo.core")},1514:function(t,e,i){var n,s,o;!function(r,define){s=[i(19)],n=r,o="function"==typeof n?n.apply(e,s):n,!(void 0!==o&&(t.exports=o))}(function(){!function(t,e){function i(t){return"("==t||"["==t||"{"==t}function n(t){return")"==t||"]"==t||"}"==t}function s(t,e){return"("==e?")"==t:"["==e?"]"==t:"{"==e&&"}"==t}function o(t,e){return t.begin<=e.begin&&t.end>=e.end}function r(e){return t.spreadsheet.calc.runtime.FUNCS[e.toLowerCase()]}function l(t,e){return!(!t||!e)&&("ref"==t.type&&"ref"==e.type?t.ref.eq(e.ref):t.value===e.value)}var u,h,a,c,f,p,d,g,m;t.support.browser.msie&&t.support.browser.version<9||(u=t.jQuery,h=t.ui.Widget,a=".kendoFormulaInput",c=t.keys,f={wrapper:"k-spreadsheet-formula-input",listWrapper:"k-spreadsheet-formula-list"},p=["font-family","font-size","font-stretch","font-style","font-weight","letter-spacing","text-transform","line-height"],d={27:"esc",37:"left",39:"right",35:"end",36:"home",32:"spacebar"},g=/(^_|[^a-z0-9]$)/i,m=h.extend({init:function(t,e){h.call(this,t,e),t=this.element,t.addClass(m.classNames.wrapper).attr("contenteditable",!0).attr("spellcheck",!1).css("white-space","pre"),this.options.autoScale&&t.on("input",this.scale.bind(this)),this._highlightedRefs=[],this._staticTokens=[],this._formulaSource(),this._formulaList(),this._popup(),this._tooltip(),t.on("keydown",this._keydown.bind(this)).on("keyup",this._keyup.bind(this)).on("blur",this._blur.bind(this)).on("input click",this._input.bind(this)).on("focus",this._focus.bind(this)).on("paste",this._paste.bind(this))},options:{name:"FormulaInput",autoScale:!1,filterOperator:"startswith",scalePadding:30,minLength:1},events:["keyup","focus"],enable:function(t){return void 0===t?"true"===this.element.attr("contenteditable"):(t?this.element.attr("contenteditable",t):this.element.removeAttr("contenteditable"),void this.element.toggleClass("k-state-disabled",!t))},getPos:function(){function t(t,e){try{!function s(i){if(i===t)throw e;if(1==i.nodeType)for(var n=i.firstChild;n;n=n.nextSibling)s(n);else 3==i.nodeType&&(e+=i.nodeValue.length)}(n)}catch(i){return i}}var i,n=this.element[0],s=e.getSelection(),o=t(s.focusNode,s.focusOffset),r=t(s.anchorNode,s.anchorOffset);if(null!=o&&null!=r)return o>r&&(i=o,o=r,r=i),{begin:o,end:r,collapsed:o==r}},setPos:function(t,i){function n(t,e){return t.startOffset!=e.startOffset||t.endOffset!=e.endOffset||t.startContainer!=e.endContainer||t.endContainer!=e.endContainer}function s(t,e){try{!function n(t){var i,s;if(3==t.nodeType){if(i=t.nodeValue.length,i>=e)throw t;e-=i}else if(1==t.nodeType)for(s=t.firstChild;s;s=s.nextSibling)n(s)}(t)}catch(i){return{node:i,pos:e}}}var o,r,l,u=this.element[0];t=s(u,t),i=null!=i?s(u,i):t,t&&i&&(o=document.createRange(),o.setStart(t.node,t.pos),o.setEnd(i.node,i.pos),r=e.getSelection(),l=r.getRangeAt(0),n(o,l)&&(r.removeAllRanges(),r.addRange(o)))},end:function(){this.setPos(this.length())},home:function(){this.setPos(0)},select:function(){this.setPos(0,this.length())},length:function(){return this.value().length},_formulaSource:function(){var e,i,n=[];for(i in t.spreadsheet.calc.runtime.FUNCS)g.test(i)||(e=i.toUpperCase(),n.push({value:e,text:e}));this.formulaSource=new t.data.DataSource({data:n})},_formulaList:function(){this.list=new t.ui.StaticList(u("<ul />").addClass(m.classNames.listWrapper).insertAfter(this.element),{autoBind:!1,selectable:!0,change:this._formulaListChange.bind(this),dataSource:this.formulaSource,dataValueField:"value",template:"#:data.value#"}),this.list.element.on("mousedown",function(t){t.preventDefault()})},_formulaListChange:function(){var t,e,i,n=this._tokenContext();n&&!this._mute&&(t=n.token,e=this.list.value()[0],i={replace:!0,token:t,end:t.end},n.nextToken&&"("==n.nextToken.value||(e+="("),this._replaceAt(i,e),this.popup.close())},_popup:function(){this.popup=new t.ui.Popup(this.list.element,{anchor:this.element})},_blur:function(){this.popup.close(),clearTimeout(this._focusId),this.trigger("blur")},_isFormula:function(){return/^=/.test(this.value())},_keydown:function(t){var e=t.keyCode;d[e]?(this.popup.close(),this._navigated=!0):this._move(e)&&(this._navigated=!0,t.preventDefault()),this._keyDownTimeout=setTimeout(this._syntaxHighlight.bind(this))},_keyup:function(){var t,e=this.popup;this._isFormula()&&!this._navigated&&(t=((this._tokenContext()||{}).token||{}).value,this.filter(t),t&&this.formulaSource.view().length?(e[e.visible()?"position":"open"](),this.list.focusFirst()):e.close()),this._navigated=!1,this._syntaxHighlight(),this.trigger("keyup")},_input:function(){this._syntaxHighlight()},_focus:function(){setTimeout(this._sync.bind(this)),this._focusTimeout=setTimeout(this._syntaxHighlight.bind(this)),this.trigger("focus")},_paste:function(i){var n,s,o;i.preventDefault(),n=this.getPos(),s=t.support.browser.msie?e.clipboardData.getData("Text"):i.originalEvent.clipboardData.getData("text/plain"),o=this.value(),o=o.substr(0,n.begin)+s+o.substr(n.end),this.value(o),this.setPos(n.begin+s.length),this.scale()},_move:function(t){var e=this.list,i=this.popup;if(i.visible()){if(t===c.DOWN)return e.focusNext(),e.focus()||e.focusFirst(),!0;if(t===c.UP)return e.focusPrev(),e.focus()||e.focusLast(),!0;if(t===c.ENTER)return e.select(e.focus()),i.close(),!0;if(t===c.TAB)return e.select(e.focus()),i.close(),!0;if(t===c.PAGEUP)return e.focusFirst(),!0;if(t===c.PAGEDOWN)return e.focusLast(),!0}return t===c.ENTER||t===c.TAB},_tokenContext:function(){var e,i,n,s=this.getPos(),r=this.value();if(!r||!s||!s.collapsed)return null;for(e=t.spreadsheet.calc.tokenize(r,this.row(),this.col()),n=0;n<e.length;++n)if(i=e[n],o(i,s)&&/^(?:str|sym|func)$/.test(i.type))return{token:i,nextToken:e[n+1]};return null},_sync:function(){this._editorToSync&&this.isActive()&&this._editorToSync.value(this.value())},_textContainer:function(){var e=t.getComputedStyles(this.element[0],p);e.position="absolute",e.visibility="hidden",e.whiteSpace="pre",e.top=-3333,e.left=-3333,this._span=u("<span style='white-space: pre'/>").css(e).insertAfter(this.element)},_tooltip:function(){this._cellTooltip=u('<div class="k-widget k-tooltip" style="position:absolute; display:none">A1</div>').insertAfter(this.element)},tooltip:function(t){this._cellTooltip.text(t)},toggleTooltip:function(t){this._cellTooltip.toggle(t)},isActive:function(){return this.element[0]===t._activeElement()},filter:function(t){!t||t.length<this.options.minLength||(this._mute=!0,this.list.select(-1),this._mute=!1,this.formulaSource.filter({field:this.list.options.dataValueField,operator:this.options.filterOperator,value:t}))},hide:function(){this.enable(!1),this.element.hide(),this._cellTooltip.hide()},show:function(){this.enable(!0),this.element.show()},row:function(){if(this.activeCell)return this.activeCell.row},col:function(){if(this.activeCell)return this.activeCell.col},position:function(t){t&&(this.show(),this.element.css({top:t.top+1+"px",left:t.left+1+"px"}),this._cellTooltip.css({top:t.top-this._cellTooltip.height()-10+"px",left:t.left}))},resize:function(t){t&&this.element.css({width:t.width-1,height:t.height-1})},canInsertRef:function(t){var e,i=this._canInsertRef(t),n=i&&i.token;if(n)for(e=0;e<this._staticTokens.length;e++)if(l(n,this._staticTokens[e]))return null;return i},_canInsertRef:function(e){function n(t){return t.begin>u.begin}function s(t){if(t){if(/^(?:num|str|bool|sym|ref)$/.test(t.type))return{replace:!0,token:t,end:t.end};if(/^(?:op|punc|startexp)$/.test(t.type))return t.end==u.end?r(t,h[c+1]):r(h[c-1],t)}}function r(t,e){if(null==t)return null;if(null==e)return/^(?:op|startexp)$/.test(t.type)||i(t.value)?{token:t,end:u.end}:null;if(l){if("op"==t.type&&/^(?:punc|op)$/.test(e.type))return{token:t,end:u.end}}else{if("startexp"==t.type)return{token:t,end:u.end};if(/^(?:op|punc)$/.test(t.type)&&/^[,;({]$/.test(t.value))return{token:t,end:u.end};if(/^(?:ref|sym)/.test(t.type))return{token:t,replace:!0,end:t.end};if(/^(?:ref|sym)/.test(e.type))return{token:e,replace:!0,end:e.end}}return!1}var l,u,h,a,c;if(this.popup.visible())return null;if(l=e,u=this.getPos(),u&&this._isFormula()){if(0===u.begin)return null;for(h=t.spreadsheet.calc.tokenize(this.value(),this.row(),this.col()),c=0;c<h.length;++c){if(a=h[c],o(a,u))return s(a);if(n(a))return r(h[c-1],a)}return r(a,null)}return null},refAtPoint:function(t){var e,i=this._canInsertRef();i&&(e=t.selection()._ref.simplify().clone().relative(0,0,3),t!==this.activeSheet&&(e=e.setSheet(t.name(),!0)),this._replaceAt(i,e.print(0,0)))},_replaceAt:function(t,e){var i,n=this.value(),s=t.token,o=n.substr(t.end);n=n.substr(0,t.replace?s.begin:t.end)+e,i=n.length,n+=o,this._value(n),this.setPos(i),this.scale(),this._syntaxHighlight()},syncWith:function(e){var i,n=this,s="input"+a,o=n._sync.bind(n);t.support.browser.msie&&(s="keydown"+a,i=function(){setTimeout(o)}),n._editorToSync=e,n.element.off(s).on(s,i||o)},scale:function(){var t,e,i=this.element;this._span||this._textContainer(),this._span.html(i.html()),t=this._span.width()+this.options.scalePadding,e=this._span.height(),t>i.width()&&i.width(t),e>i.height()&&i.height(e),this._sync()},_value:function(t){this.element.text(t)},value:function(t){if(void 0===t){var e=this.element[0].innerText;return e.replace(/\n$/,"")}this._value(t),this._syntaxHighlight()},highlightedRefs:function(){return this._highlightedRefs.slice()},_syntaxHighlight:function(){var e,l=this.getPos(),u=this.value(),h=t.spreadsheet.Pane.classNames.series,a=[],c=0,f=[],p=[];if(!l||l.collapsed){if(!/^=/.test(u))return(this._staticTokens.length||this._highlightedRefs.length)&&(this._staticTokens=[],this._highlightedRefs=[],this.element.text(u)),void(this.popup&&this.popup.close());p=t.spreadsheet.calc.tokenize(u,this.row(),this.col()),p.forEach(function(t){if(t.active=!1,t.cls=["k-syntax-"+t.type],"ref"==t.type&&(t.colorClass=h[c++%h.length],t.cls.push(t.colorClass),a.push(t)),l&&"punc"==t.type)if(i(t.value))f.unshift(t);else if(n(t.value)){var u=f.shift();u?s(t.value,u.value)?(o(t,l)||o(u,l))&&(t.cls.push("k-syntax-paren-match"),u.cls.push("k-syntax-paren-match")):(t.cls.push("k-syntax-error"),u.cls.push("k-syntax-error")):t.cls.push("k-syntax-error")}l&&o(t,l)&&(t.cls.push("k-syntax-at-point"),t.active=!0,e=t),"func"!=t.type||r(t.value)||l&&o(t,l)||t.cls.push("k-syntax-error")}),p.reverse().forEach(function(e){var i=e.begin,n=e.end,s=t.htmlEncode(u.substring(i,n));u=u.substr(0,i)+"<span class='"+e.cls.join(" ")+"'>"+s+"</span>"+u.substr(n)}),this.element.html(u),l&&this.setPos(l.begin,l.end),e&&/^(?:startexp|op|punc)$/.test(e.type)&&this._setStaticTokens(p),this._highlightedRefs=a}},_setStaticTokens:function(t){var e,i;for(this._staticTokens=[],e=0;e<t.length;e++)i=t[e],/^(?:num|str|bool|sym|ref)$/.test(i.type)&&this._staticTokens.push(i)},destroy:function(){this._editorToSync=null,this.element.off(a),clearTimeout(this._focusTimeout),clearTimeout(this._keyDownTimeout),this._cellTooltip=null,this._span=null,this.popup.destroy(),this.popup=null,h.fn.destroy.call(this)},insertNewline:function(){var t=this.value(),e=this.getPos(),i=e.end==t.length;t=t.substr(0,e.begin)+(i?"\n\n":"\n"+t.substr(e.end)),this.value(t),this.setPos(e.begin+1)}}),t.spreadsheet.FormulaInput=m,u.extend(!0,m,{classNames:f}))}(kendo,window)},i(3))}});