text: define(["exports","../../../@polymer/polymer/polymer-element.js","../../../@polymer/polymer/lib/utils/flattened-nodes-observer.js","./vaadin-grid-templatizer.js"],function(_exports,_polymerElement,_flattenedNodesObserver,_vaadinGridTemplatizer){"use strict";Object.defineProperty(_exports,"__esModule",{value:!0});_exports.GridColumnElement=_exports.ColumnBaseMixin=void 0;var ColumnBaseMixin=function(superClass){return function(_superClass){babelHelpers.inherits(ColumnBaseMixin,_superClass);babelHelpers.createClass(ColumnBaseMixin,[{key:"connectedCallback",value:function connectedCallback(){var _this2=this;babelHelpers.get(babelHelpers.getPrototypeOf(ColumnBaseMixin.prototype),"connectedCallback",this).call(this);this._bodyTemplate&&(this._bodyTemplate.templatizer._grid=this._grid);this._headerTemplate&&(this._headerTemplate.templatizer._grid=this._grid);this._footerTemplate&&(this._footerTemplate.templatizer._grid=this._grid);this._templateObserver.flush();if(!this._bodyTemplate){this._templateObserver.callback()}requestAnimationFrame(function(){_this2._allCells.forEach(function(cell){if(!cell._content.parentNode){_this2._grid&&_this2._grid.appendChild(cell._content)}})})}},{key:"disconnectedCallback",value:function disconnectedCallback(){var _this3=this;babelHelpers.get(babelHelpers.getPrototypeOf(ColumnBaseMixin.prototype),"disconnectedCallback",this).call(this);requestAnimationFrame(function(){if(!_this3._findHostGrid()){_this3._allCells.forEach(function(cell){if(cell._content.parentNode){cell._content.parentNode.removeChild(cell._content)}})}});this._gridValue=void 0}},{key:"_findHostGrid",value:function _findHostGrid(){var el=this;while(el&&!/^vaadin.*grid$/.test(el.localName)){el=el.assignedSlot?el.assignedSlot.parentNode:el.parentNode}return el||void 0}},{key:"_grid",get:function get(){if(!this._gridValue){this._gridValue=this._findHostGrid()}return this._gridValue}},{key:"_allCells",get:function get(){return[].concat(this._cells||[]).concat(this._emptyCells||[]).concat(this._headerCell).concat(this._footerCell).filter(function(cell){return cell})}}],[{key:"properties",get:function get(){return{resizable:{type:Boolean,value:function value(){if("vaadin-grid-column-group"===this.localName){return}var parent=this.parentNode;if(parent&&"vaadin-grid-column-group"===parent.localName){return parent.resizable||!1}else{return!1}}},_headerTemplate:{type:Object},_footerTemplate:{type:Object},frozen:{type:Boolean,value:!1},hidden:{type:Boolean},header:{type:String},textAlign:{type:String},_lastFrozen:{type:Boolean,value:!1},_order:Number,_reorderStatus:Boolean,_emptyCells:Array,_headerCell:Object,_footerCell:Object,_grid:Object,headerRenderer:Function,footerRenderer:Function}}},{key:"observers",get:function get(){return["_widthChanged(width, _headerCell, _footerCell, _cells.*)","_frozenChanged(frozen, _headerCell, _footerCell, _cells.*)","_flexGrowChanged(flexGrow, _headerCell, _footerCell, _cells.*)","_pathOrHeaderChanged(path, header, _headerCell, _footerCell, _cells.*, renderer, headerRenderer, _bodyTemplate, _headerTemplate)","_textAlignChanged(textAlign, _cells.*, _headerCell, _footerCell)","_orderChanged(_order, _headerCell, _footerCell, _cells.*)","_lastFrozenChanged(_lastFrozen)","_setBodyTemplateOrRenderer(_bodyTemplate, renderer, _cells, _cells.*)","_setHeaderTemplateOrRenderer(_headerTemplate, headerRenderer, _headerCell)","_setFooterTemplateOrRenderer(_footerTemplate, footerRenderer, _footerCell)","_resizableChanged(resizable, _headerCell)","_reorderStatusChanged(_reorderStatus, _headerCell, _footerCell, _cells.*)","_hiddenChanged(hidden, _headerCell, _footerCell, _cells.*)"]}}]);function ColumnBaseMixin(){var _this;babelHelpers.classCallCheck(this,ColumnBaseMixin);_this=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(ColumnBaseMixin).call(this));_this._templateObserver=new _flattenedNodesObserver.FlattenedNodesObserver(babelHelpers.assertThisInitialized(babelHelpers.assertThisInitialized(_this)),function(){_this._headerTemplate=_this._prepareHeaderTemplate();_this._footerTemplate=_this._prepareFooterTemplate();_this._bodyTemplate=_this._prepareBodyTemplate()});return _this}babelHelpers.createClass(ColumnBaseMixin,[{key:"_prepareHeaderTemplate",value:function _prepareHeaderTemplate(){return this._prepareTemplatizer(this._findTemplate(!0)||null,{})}},{key:"_prepareFooterTemplate",value:function _prepareFooterTemplate(){return this._prepareTemplatizer(this._findTemplate(!1,!0)||null,{})}},{key:"_prepareBodyTemplate",value:function _prepareBodyTemplate(){return this._prepareTemplatizer(this._findTemplate()||null)}},{key:"_prepareTemplatizer",value:function _prepareTemplatizer(template,instanceProps){if(template&&!template.templatizer){var templatizer=new _vaadinGridTemplatizer.Templatizer;templatizer._grid=this._grid;templatizer.dataHost=this.dataHost;templatizer._instanceProps=instanceProps||templatizer._instanceProps;templatizer.template=template;template.templatizer=templatizer}return template}},{key:"_renderHeaderAndFooter",value:function _renderHeaderAndFooter(){if(this.headerRenderer){this.__runRenderer(this.headerRenderer,this._headerCell)}if(this.footerRenderer){this.__runRenderer(this.footerRenderer,this._footerCell)}}},{key:"__runRenderer",value:function __runRenderer(renderer,cell,rowData){var args=[cell._content,this];if(rowData&&rowData.item){args.push(rowData)}renderer.apply(this,args)}},{key:"__setColumnTemplateOrRenderer",value:function __setColumnTemplateOrRenderer(template,renderer,cells){var _this4=this;if(template&&renderer){throw new Error("You should only use either a renderer or a template")}cells.forEach(function(cell){var model=_this4._grid.__getRowModel(cell.parentElement);if(renderer){cell._renderer=renderer;if(model.item||renderer===_this4.headerRenderer||renderer===_this4.footerRenderer){_this4.__runRenderer(renderer,cell,model)}}else if(cell._template!==template){cell._template=template;cell._content.innerHTML="";template.templatizer._grid=template.templatizer._grid||_this4._grid;var inst=template.templatizer.createInstance();cell._content.appendChild(inst.root);cell._instance=inst;if(model.item){cell._instance.setProperties(model)}}})}},{key:"_setBodyTemplateOrRenderer",value:function _setBodyTemplateOrRenderer(template,renderer,cells){if((template||renderer)&&cells){this.__setColumnTemplateOrRenderer(template,renderer,cells)}}},{key:"_setHeaderTemplateOrRenderer",value:function _setHeaderTemplateOrRenderer(headerTemplate,headerRenderer,headerCell){if((headerTemplate||headerRenderer)&&headerCell){this.__setColumnTemplateOrRenderer(headerTemplate,headerRenderer,[headerCell]);headerCell.parentElement.hidden=!1}}},{key:"_setFooterTemplateOrRenderer",value:function _setFooterTemplateOrRenderer(footerTemplate,footerRenderer,footerCell){if((footerTemplate||footerRenderer)&&footerCell){this.__setColumnTemplateOrRenderer(footerTemplate,footerRenderer,[footerCell]);footerCell.parentElement.hidden=!1}}},{key:"_selectFirstTemplate",value:function _selectFirstTemplate(){var header=0<arguments.length&&arguments[0]!==void 0?arguments[0]:!1,footer=1<arguments.length&&arguments[1]!==void 0?arguments[1]:!1;return _flattenedNodesObserver.FlattenedNodesObserver.getFlattenedNodes(this).filter(function(node){return"template"===node.localName&&node.classList.contains("header")===header&&node.classList.contains("footer")===footer})[0]}},{key:"_findTemplate",value:function _findTemplate(header,footer){var template=this._selectFirstTemplate(header,footer);if(template){if(this.dataHost){template._rootDataHost=this.dataHost._rootDataHost||this.dataHost}}return template}},{key:"_flexGrowChanged",value:function _flexGrowChanged(flexGrow){if(this.parentElement&&this.parentElement._columnPropChanged){this.parentElement._columnPropChanged("flexGrow")}this._allCells.forEach(function(cell){return cell.style.flexGrow=flexGrow})}},{key:"_orderChanged",value:function _orderChanged(order){this._allCells.forEach(function(cell){return cell.style.order=order})}},{key:"_widthChanged",value:function _widthChanged(width){if(this.parentElement&&this.parentElement._columnPropChanged){this.parentElement._columnPropChanged("width")}this._allCells.forEach(function(cell){return cell.style.width=width})}},{key:"_frozenChanged",value:function _frozenChanged(frozen){var _this5=this;if(this.parentElement&&this.parentElement._columnPropChanged){this.parentElement._columnPropChanged("frozen",frozen)}this._allCells.forEach(function(cell){return _this5._toggleAttribute("frozen",frozen,cell)});this._grid&&this._grid._frozenCellsChanged&&this._grid._frozenCellsChanged()}},{key:"_lastFrozenChanged",value:function _lastFrozenChanged(lastFrozen){var _this6=this;this._allCells.forEach(function(cell){return _this6._toggleAttribute("last-frozen",lastFrozen,cell)});if(this.parentElement&&this.parentElement._columnPropChanged){this.parentElement._lastFrozen=lastFrozen}}},{key:"_pathOrHeaderChanged",value:function _pathOrHeaderChanged(path,header,headerCell,footerCell,cells,renderer,headerRenderer,bodyTemplate,headerTemplate){var _this7=this,hasHeaderText=header!==void 0&&null!==header;if(!headerRenderer&&!headerTemplate&&hasHeaderText&&headerCell){this.__setTextContent(headerCell._content,header);headerCell.parentElement.hidden=!1}if(path&&cells.value){if(!renderer&&!bodyTemplate){this.__setColumnTemplateOrRenderer(void 0,function pathRenderer(root,owner,_ref){var item=_ref.item;return _this7.__setTextContent(root,_this7.get(path,item))},cells.value)}if(!headerRenderer&&!headerTemplate&&!hasHeaderText&&headerCell){this.__setTextContent(headerCell._content,this._generateHeader(path));headerCell.parentElement.hidden=!1}}}},{key:"__setTextContent",value:function __setTextContent(node,textContent){node.textContent!==textContent&&(node.textContent=textContent)}},{key:"_generateHeader",value:function _generateHeader(path){return path.substr(path.lastIndexOf(".")+1).replace(/([A-Z])/g,"-$1").toLowerCase().replace(/-/g," ").replace(/^./,function(match){return match.toUpperCase()})}},{key:"_toggleAttribute",value:function _toggleAttribute(name,bool,node){if(node.hasAttribute(name)===!bool){if(bool){node.setAttribute(name,"")}else{node.removeAttribute(name)}}}},{key:"_reorderStatusChanged",value:function _reorderStatusChanged(reorderStatus){this._allCells.forEach(function(cell){return cell.setAttribute("reorder-status",reorderStatus)})}},{key:"_resizableChanged",value:function _resizableChanged(resizable,headerCell){if(resizable===void 0||headerCell===void 0){return}if(headerCell){[headerCell].concat(this._emptyCells).forEach(function(cell){if(cell){var existingHandle=cell.querySelector("[part~=\"resize-handle\"]");if(existingHandle){cell.removeChild(existingHandle)}if(resizable){var handle=document.createElement("div");handle.setAttribute("part","resize-handle");cell.appendChild(handle)}}})}}},{key:"_textAlignChanged",value:function _textAlignChanged(textAlign){if(textAlign===void 0){return}if(-1===["start","end","center"].indexOf(textAlign)){console.warn("textAlign can only be set as \"start\", \"end\" or \"center\"");return}var textAlignFallback;if("ltr"===getComputedStyle(this._grid).direction){if("start"===textAlign){textAlignFallback="left"}else if("end"===textAlign){textAlignFallback="right"}}else{if("start"===textAlign){textAlignFallback="right"}else if("end"===textAlign){textAlignFallback="left"}}this._allCells.forEach(function(cell){cell._content.style.textAlign=textAlign;if(getComputedStyle(cell._content).textAlign!==textAlign){cell._content.style.textAlign=textAlignFallback}})}},{key:"_hiddenChanged",value:function _hiddenChanged(hidden){var _this8=this;if(this.parentElement&&this.parentElement._columnPropChanged){this.parentElement._columnPropChanged("hidden",hidden)}this._allCells.forEach(function(cell){return _this8._toggleAttribute("hidden",hidden,cell)});if(!!hidden!==!!this._previousHidden&&this._grid){this._grid._updateLastFrozen&&this._grid._updateLastFrozen();this._grid.notifyResize&&this._grid.notifyResize()}this._previousHidden=hidden}}]);return ColumnBaseMixin}(superClass)};_exports.ColumnBaseMixin=ColumnBaseMixin;var GridColumnElement=function(_ColumnBaseMixin){babelHelpers.inherits(GridColumnElement,_ColumnBaseMixin);function GridColumnElement(){babelHelpers.classCallCheck(this,GridColumnElement);return babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(GridColumnElement).apply(this,arguments))}babelHelpers.createClass(GridColumnElement,null,[{key:"is",get:function get(){return"vaadin-grid-column"}},{key:"properties",get:function get(){return{width:{type:String,value:"100px"},flexGrow:{type:Number,value:1},renderer:Function,path:{type:String},_bodyTemplate:{type:Object},_cells:Array}}}]);return GridColumnElement}(ColumnBaseMixin(_polymerElement.PolymerElement));_exports.GridColumnElement=GridColumnElement;customElements.define(GridColumnElement.is,GridColumnElement)});