/*
    *
    * Wijmo Library 5.20181.462
    * 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";function tryGetModuleWijmoInput(){let e;return(e=window.wijmo)&&e.input}Object.defineProperty(exports,"__esModule",{value:!0});const wjcCore=require("wijmo/wijmo"),wjcSelfRef=require("wijmo/wijmo.grid");var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.grid=wjcSelf,wjcCore.culture.FlexGrid=window.wijmo.culture.FlexGrid||{groupHeaderFormat:"{name}: <b>{value}</b> ({count:n0} items)"};var HeadersVisibility;!function(e){e[e.None=0]="None",e[e.Column=1]="Column",e[e.Row=2]="Row",e[e.All=3]="All"}(HeadersVisibility=exports.HeadersVisibility||(exports.HeadersVisibility={}));class FlexGrid extends wjcCore.Control{constructor(e,t){super(e,null,!0),this._szClient=new wjcCore.Size(0,0),this._ptScrl=new wjcCore.Point(0,0),this._cellPadding=3,this._clipToScreen=!1,this._autoGenCols=!0,this._autoClipboard=!0,this._autoScroll=!0,this._readOnly=!1,this._indent=14,this._autoSizeMode=AutoSizeMode.Both,this._hdrVis=HeadersVisibility.All,this._alSorting=!0,this._alAddNew=!1,this._alDelete=!1,this._alResizing=AllowResizing.Columns,this._alDragging=AllowDragging.Columns,this._alMerging=AllowMerging.None,this._ssHdr=HeadersVisibility.None,this._shSort=!0,this._shGroups=!0,this._shAlt=!0,this._shErr=!0,this._shDropDown=!0,this._valEdt=!0,this._deferResizing=!1,this._pSel=!0,this._pOutline=!0,this._vt=0,this.itemsSourceChanging=new wjcCore.Event,this.itemsSourceChanged=new wjcCore.Event,this.scrollPositionChanged=new wjcCore.Event,this.selectionChanging=new wjcCore.Event,this.selectionChanged=new wjcCore.Event,this.loadingRows=new wjcCore.Event,this.loadedRows=new wjcCore.Event,this.updatingLayout=new wjcCore.Event,this.updatedLayout=new wjcCore.Event,this.resizingColumn=new wjcCore.Event,this.resizedColumn=new wjcCore.Event,this.autoSizingColumn=new wjcCore.Event,this.autoSizedColumn=new wjcCore.Event,this.draggingColumn=new wjcCore.Event,this.draggingColumnOver=new wjcCore.Event,this.draggedColumn=new wjcCore.Event,this.resizingRow=new wjcCore.Event,this.resizedRow=new wjcCore.Event,this.autoSizingRow=new wjcCore.Event,this.autoSizedRow=new wjcCore.Event,this.draggingRow=new wjcCore.Event,this.draggingRowOver=new wjcCore.Event,this.draggedRow=new wjcCore.Event,this.groupCollapsedChanging=new wjcCore.Event,this.groupCollapsedChanged=new wjcCore.Event,this.sortingColumn=new wjcCore.Event,this.sortedColumn=new wjcCore.Event,this.beginningEdit=new wjcCore.Event,this.prepareCellForEdit=new wjcCore.Event,this.cellEditEnding=new wjcCore.Event,this.cellEditEnded=new wjcCore.Event,this.rowEditStarting=new wjcCore.Event,this.rowEditStarted=new wjcCore.Event,this.rowEditEnding=new wjcCore.Event,this.rowEditEnded=new wjcCore.Event,this.rowAdded=new wjcCore.Event,this.deletingRow=new wjcCore.Event,this.deletedRow=new wjcCore.Event,this.copying=new wjcCore.Event,this.copied=new wjcCore.Event,this.pasting=new wjcCore.Event,this.pasted=new wjcCore.Event,this.pastingCell=new wjcCore.Event,this.pastedCell=new wjcCore.Event,this.formatItem=new wjcCore.Event,this.updatingView=new wjcCore.Event,this.updatedView=new wjcCore.Event,this._mappedColumns=null;let i=this.hostElement;wjcCore.isIE()&&(i.style.borderRadius="0");let s=this.getTemplate();this.applyTemplate("wj-control wj-content wj-flexgrid",s,{_root:"root",_eSz:"sz",_eCt:"cells",_fCt:"fcells",_eTL:"tl",_eBL:"bl",_eCHdr:"ch",_eRHdr:"rh",_eCFtr:"cf",_eTLCt:"tlcells",_eBLCt:"blcells",_eCHdrCt:"chcells",_eCFtrCt:"cfcells",_eRHdrCt:"rhcells",_eMarquee:"marquee",_eFocus:"focus"}),this._tabIndex=i.tabIndex,i.tabIndex=-1;let l=this._getDefaultRowHeight();this.deferUpdate(()=>{this._rows=new RowCollection(this,l),this._cols=new ColumnCollection(this,4*l),this._hdrRows=new RowCollection(this,l),this._hdrCols=new ColumnCollection(this,Math.round(1.25*l)),this._ftrRows=new RowCollection(this,l),this._gpTL=new GridPanel(this,CellType.TopLeft,this._hdrRows,this._hdrCols,this._eTLCt),this._gpCHdr=new GridPanel(this,CellType.ColumnHeader,this._hdrRows,this._cols,this._eCHdrCt),this._gpRHdr=new GridPanel(this,CellType.RowHeader,this._rows,this._hdrCols,this._eRHdrCt),this._gpCells=new GridPanel(this,CellType.Cell,this._rows,this._cols,this._eCt),this._gpBL=new GridPanel(this,CellType.BottomLeft,this._ftrRows,this._hdrCols,this._eBLCt),this._gpCFtr=new GridPanel(this,CellType.ColumnFooter,this._ftrRows,this._cols,this._eCFtrCt),this._hdrRows.push(new Row),this._hdrCols.push(new Column),this._hdrCols[0].align="center",this._cf=new CellFactory,this._keyHdl=new _KeyboardHandler(this),this._mouseHdl=new _MouseHandler(this),this._edtHdl=new _EditHandler(this),this._selHdl=new _SelectionHandler(this),this._addHdl=new _AddNewHandler(this),this._mrgMgr=new MergeManager(this),this._bndSortConverter=this._sortConverter.bind(this),this._bndScroll=this._scroll.bind(this),wjcCore.setAttribute(this.cells.hostElement,"role","grid"),this.selectionMode=SelectionMode.CellRange,this.initialize(t)}),this.addEventListener(this._root,"scroll",e=>{this._updateScrollPosition()&&(this.finishEditing(),this._updateContent(!0))}),this.addEventListener(i,"focus",e=>{if(i.tabIndex>-1){let t=e.target;if(t instanceof HTMLElement&&t.tabIndex<0)return void this._setFocus(!0)}},!0)}_handleResize(){this._rcBounds=null,super._handleResize()}get headersVisibility(){return this._hdrVis}set headersVisibility(e){(e=wjcCore.asEnum(e,HeadersVisibility))!=this._hdrVis&&(this._hdrVis=e,this.invalidate())}get stickyHeaders(){return this._stickyHdr}set stickyHeaders(e){e!=this._stickyHdr&&(this._stickyHdr=wjcCore.asBoolean(e),this._updateStickyHeaders(),this.invalidate())}get preserveSelectedState(){return this._pSel}set preserveSelectedState(e){this._pSel=wjcCore.asBoolean(e)}get preserveOutlineState(){return this._pOutline}set preserveOutlineState(e){this._pOutline=wjcCore.asBoolean(e)}get virtualizationThreshold(){return this._vt}set virtualizationThreshold(e){this._vt=wjcCore.asNumber(e)}get autoGenerateColumns(){return this._autoGenCols}set autoGenerateColumns(e){this._autoGenCols=wjcCore.asBoolean(e)}get autoClipboard(){return this._autoClipboard}set autoClipboard(e){this._autoClipboard=wjcCore.asBoolean(e)}get autoScroll(){return this._autoScroll}set autoScroll(e){this._autoScroll=wjcCore.asBoolean(e)}get columnLayout(){let e=FlexGrid._getSerializableProperties(Column),t=new Column,i=[];for(let s=0;s<this.columns.length;s++){let l=this.columns[s],o={};for(let i=0;i<e.length;i++){let s=e[i],n=l[s];n!=t[s]&&wjcCore.isPrimitive(n)&&"size"!=s&&(o[s]=n)}i.push(o)}return JSON.stringify({columns:i})}set columnLayout(e){let t=JSON.parse(wjcCore.asString(e));if(!t||null==t.columns)throw"Invalid columnLayout data.";this.columns.clear(),this.initialize(t)}get isReadOnly(){return this._readOnly}set isReadOnly(e){e!=this._readOnly&&(this._readOnly=wjcCore.asBoolean(e),this.finishEditing(),this.invalidate(!0),this._addHdl.updateNewRowTemplate(),wjcCore.toggleClass(this.hostElement,"wj-state-readonly",this.isReadOnly),this._setAria("readonly",this.isReadOnly?"true":null))}get imeEnabled(){return null!=this._imeHdl}set imeEnabled(e){wjcCore.asBoolean(e)!=this.imeEnabled&&this.finishEditing()&&(this._imeHdl&&(this._imeHdl.dispose(),this._imeHdl=null),e&&(this._imeHdl=new _ImeHandler(this)))}get allowResizing(){return this._alResizing}set allowResizing(e){this._alResizing=wjcCore.asEnum(e,AllowResizing)}get deferResizing(){return this._deferResizing}set deferResizing(e){this._deferResizing=wjcCore.asBoolean(e)}get autoSizeMode(){return this._autoSizeMode}set autoSizeMode(e){this._autoSizeMode=wjcCore.asEnum(e,AutoSizeMode)}get quickAutoSize(){return this._quickSize}set quickAutoSize(e){this._quickSize=wjcCore.asBoolean(e,!0)}_getQuickAutoSize(){return wjcCore.isBoolean(this._quickSize)?this._quickSize:!this.formatItem.hasHandlers&&null==this.itemFormatter}get allowSorting(){return this._alSorting}set allowSorting(e){this._alSorting=wjcCore.asBoolean(e)}get allowAddNew(){return this._alAddNew}set allowAddNew(e){e!=this._alAddNew&&(this._alAddNew=wjcCore.asBoolean(e),this._addHdl.updateNewRowTemplate())}get newRowAtTop(){return this._addHdl.newRowAtTop}set newRowAtTop(e){this._addHdl.newRowAtTop=wjcCore.asBoolean(e)}get allowDelete(){return this._alDelete}set allowDelete(e){e!=this._alDelete&&(this._alDelete=wjcCore.asBoolean(e))}get allowMerging(){return this._alMerging}set allowMerging(e){(e=wjcCore.asEnum(e,AllowMerging))!=this._alMerging&&(this._alMerging=e,this.invalidate())}get showSelectedHeaders(){return this._ssHdr}set showSelectedHeaders(e){(e=wjcCore.asEnum(e,HeadersVisibility))!=this._ssHdr&&(this._ssHdr=e,this.invalidate())}get showMarquee(){return!this._eMarquee.style.display}set showMarquee(e){if(e!=this.showMarquee){let t=this._eMarquee.style;t.visibility="collapse",t.display=wjcCore.asBoolean(e)?"":"none",this.invalidate()}}get showSort(){return this._shSort}set showSort(e){e!=this._shSort&&(this._shSort=wjcCore.asBoolean(e),this.invalidate())}get showGroups(){return this._shGroups}set showGroups(e){e!=this._shGroups&&(this._shGroups=wjcCore.asBoolean(e),this._bindGrid(!1))}get showAlternatingRows(){return this._shAlt}set showAlternatingRows(e){e!=this._shAlt&&(this._shAlt=wjcCore.asBoolean(e),this.invalidate())}get showErrors(){return this._shErr}set showErrors(e){e!=this._shErr&&(this._clearCells(),this._shErr=wjcCore.asBoolean(e))}get itemValidator(){return this._itemValidator}set itemValidator(e){e!=this.itemValidator&&(this._itemValidator=wjcCore.asFunction(e),this.invalidate())}get validateEdits(){return this._valEdt}set validateEdits(e){this._valEdt=wjcCore.asBoolean(e)}get groupHeaderFormat(){return this._gHdrFmt}set groupHeaderFormat(e){e!=this._gHdrFmt&&(this._gHdrFmt=wjcCore.asString(e),this._bindGrid(!1))}get allowDragging(){return this._alDragging}set allowDragging(e){(e=wjcCore.asEnum(e,AllowDragging))!=this._alDragging&&(this._alDragging=e,this.invalidate())}get itemsSource(){return this._items}set itemsSource(e){if(e!=this._items){let t=new wjcCore.CancelEventArgs;if(this.onItemsSourceChanging(t)){if(this._cv){let e=wjcCore.tryCast(this._cv,wjcCore.CollectionView);e&&e.sortConverter==this._bndSortConverter&&(e.sortConverter=null),this._cv.currentChanged.removeHandler(this._cvCurrentChanged,this),this._cv.collectionChanged.removeHandler(this._cvCollectionChanged,this),this._cv=null}if(this._items=e,this._cv=this._getCollectionView(e),this._lastCount=0,this._cv){this._cv.currentChanged.addHandler(this._cvCurrentChanged,this),this._cv.collectionChanged.addHandler(this._cvCollectionChanged,this);let e=wjcCore.tryCast(this._cv,wjcCore.CollectionView);e&&!e.sortConverter&&(e.sortConverter=this._bndSortConverter)}this._bindGrid(!0);let i=SelectionMode;this.selectionMode==i.ListBox&&(this.selectionMode=i.CellRange,this.selectionMode=i.ListBox),this.onItemsSourceChanged(t)}}}get collectionView(){return this._cv}get editableCollectionView(){return wjcCore.tryCast(this._cv,"IEditableCollectionView")}get childItemsPath(){return this._childItemsPath}set childItemsPath(e){e!=this._childItemsPath&&(wjcCore.assert(null==e||wjcCore.isArray(e)||wjcCore.isString(e),"childItemsPath should be an array or a string."),this._childItemsPath=e,this._bindGrid(!0))}get rowHeaderPath(){return this._rowHdrPath?this._rowHdrPath.path:null}set rowHeaderPath(e){e!=this.rowHeaderPath&&(e=wjcCore.asString(e),this._rowHdrPath=e?new wjcCore.Binding(e):null,this.invalidate())}get cells(){return this._gpCells}get columnHeaders(){return this._gpCHdr}get columnFooters(){return this._gpCFtr}get rowHeaders(){return this._gpRHdr}get topLeftCells(){return this._gpTL}get bottomLeftCells(){return this._gpBL}get rows(){return this._rows}get columns(){return this._cols}getColumn(e){return this.columns.getColumn(e)}get frozenRows(){return this.rows.frozen}set frozenRows(e){this.rows.frozen=e}get frozenColumns(){return this.columns.frozen}set frozenColumns(e){this.columns.frozen=e}get cloneFrozenCells(){return this._fzClone}set cloneFrozenCells(e){e!=this.cloneFrozenCells&&(this._fzClone=wjcCore.asBoolean(e,!0),this.invalidate())}get sortRowIndex(){return this._sortRowIndex}set sortRowIndex(e){e!=this._sortRowIndex&&(this._sortRowIndex=wjcCore.asNumber(e,!0),this.invalidate())}get scrollPosition(){return this._ptScrl.clone()}set scrollPosition(e){let t=this._root,i=-e.x;if(this.rightToLeft)switch(FlexGrid._getRtlMode()){case"rev":i=t.scrollWidth-t.clientWidth+e.x;break;case"neg":i=e.x;break;default:i=-e.x}t.scrollLeft=i,t.scrollTop=-e.y}get clientSize(){return this._szClient}get controlRect(){return this._rcBounds||(this._rcBounds=wjcCore.getElementRect(this._root)),this._rcBounds}get scrollSize(){return new wjcCore.Size(this._gpCells.width,this._heightBrowser)}get viewRange(){return this._gpCells.viewRange}get cellFactory(){return this._cf}set cellFactory(e){e!=this._cf&&(this._clearCells(),this._cf=wjcCore.asType(e,CellFactory,!1))}get itemFormatter(){return this._itemFormatter}set itemFormatter(e){e!=this._itemFormatter&&(this._clearCells(),this._itemFormatter=wjcCore.asFunction(e))}canEditCell(e,t){return this._edtHdl._allowEditing(e,t)}getCellData(e,t,i){return this.cells.getCellData(e,t,i)}getCellBoundingRect(e,t,i){return this.cells.getCellBoundingRect(e,t,i)}setCellData(e,t,i,s=!0,l=!0){return this.cells.setCellData(e,t,i,s,l)}hitTest(e,t){return wjcCore.isNumber(e)&&wjcCore.isNumber(t)&&(e=new wjcCore.Point(e,t)),wjcCore.isBoolean(t)&&t&&(this._rcBounds=null),new HitTestInfo(this,e)}getClipString(e){return this._edtHdl.getClipString(e)}setClipString(e,t){this._edtHdl.setClipString(e,t)}focus(){this._setFocus(!1)}dispose(){this.finishEditing(!0),this.itemsSource=null,super.dispose()}refresh(e=!0){super.refresh(e),this.finishEditing(),e&&(this._updateColumnTypes(),this.scrollPosition=this._ptScrl),this.refreshCells(e)}refreshCells(e,t,i){this.isUpdating||(e?this._updateLayout():this._updateContent(t,i))}autoSizeColumn(e,t=!1,i=4){this.autoSizeColumns(e,e,t,i)}autoSizeColumns(e,t,i=!1,s=4){let l=0,o=i?this.topLeftCells:this.columnHeaders,n=i?this.bottomLeftCells:this.columnFooters,r=i?this.rowHeaders:this.cells,a=this.viewRange;e=null==e?0:wjcCore.asInt(e),t=null==t?r.columns.length-1:wjcCore.asInt(t),a.row=Math.max(0,a.row-1e3),a.row2=Math.min(a.row2+1e3,this.rows.length-1),this.finishEditing()&&this.columns.deferUpdate(()=>{wjcCore.setCss(this._eCt,{width:this._gpCells.width});let i=document.createElement("div");i.setAttribute(FlexGrid._WJS_MEASURE,"true"),i.style.visibility="hidden",r.hostElement.parentElement.appendChild(i);let h=this._getCanvasContext();for(let d=e;d<=t&&d>-1&&d<r.columns.length;d++){let e=r.columns[d];if(e.isVisible){if(l=0,this.autoSizeMode&AutoSizeMode.Headers){for(let e=0;e<o.rows.length;e++)if(o.rows[e].isVisible){let t=this._getDesiredWidth(o,e,d,i);l=Math.max(l,t)}for(let e=0;e<n.rows.length;e++)if(n.rows[e].isVisible){let t=this._getDesiredWidth(n,e,d,i);l=Math.max(l,t)}}if(this.autoSizeMode&AutoSizeMode.Cells&&a.isValid)if(e._getQuickAutoSize()){let e=this._getWidestRow(r,a,d,h),t=this._getDesiredWidth(r,e,d,i);l=Math.max(l,t)}else for(let e=a.row;e<=a.row2&&e<r.rows.length;e++)if(r.rows[e].isVisible){let t=this._getDesiredWidth(r,e,d,i);l=Math.max(l,t)}l>0&&(e.width=l+s+2)}}this.cellFactory.disposeCell(i),wjcCore.removeChild(i)})}autoSizeRow(e,t=!1,i=0){this.autoSizeRows(e,e,t,i)}autoSizeRows(e,t,i=!1,s=0){let l=0,o=i?this.topLeftCells:this.rowHeaders,n=i?this.columnHeaders:this.cells;i=wjcCore.asBoolean(i),s=wjcCore.asNumber(s),e=null==e?0:wjcCore.asInt(e),t=null==t?n.rows.length-1:wjcCore.asInt(t),this.finishEditing()&&this.rows.deferUpdate(()=>{wjcCore.setCss(this._eCt,{width:this._gpCells.width});let i=document.createElement("div");i.setAttribute(FlexGrid._WJS_MEASURE,"true"),i.style.visibility="hidden",n.hostElement.appendChild(i);let r={};for(let a=e;a<=t&&a>-1&&a<n.rows.length;a++)n.rows[a].isVisible&&(l=0,this.autoSizeMode&AutoSizeMode.Headers&&(l=this._getDesiredRowHeight(o,a,i,r)),this.autoSizeMode&AutoSizeMode.Cells&&(l=Math.max(l,this._getDesiredRowHeight(n,a,i,r))),l+=s,n.rows[a].height=l>n.rows.defaultSize?l:null);this.cellFactory.disposeCell(i),wjcCore.removeChild(i)})}get treeIndent(){return this._indent}set treeIndent(e){e!=this._indent&&(this._indent=wjcCore.asNumber(e,!1,!0),this.columns.onCollectionChanged())}collapseGroupsToLevel(e){this.finishEditing()&&this.deferUpdate(()=>{let t=this.rows;t.deferUpdate(()=>{for(let i=0;i<t.length;i++){let s=t[i];s instanceof GroupRow&&(s.isCollapsed=s.level>=e)}})})}get selectionMode(){return this._selHdl.selectionMode}set selectionMode(e){(e=wjcCore.asEnum(e,SelectionMode))!=this.selectionMode&&(this._clearCells(),this._selHdl.selectionMode=e)}get selection(){return this._selHdl.selection.clone()}set selection(e){this._selHdl.selection=e}select(e,t=!0){this._selHdl.select(e,t)}getSelectedState(e,t){return this.cells.getSelectedState(e,t,null)}get selectedRows(){let e=[];if(this.selectionMode==SelectionMode.ListBox)for(let t=0;t<this.rows.length;t++)this.rows[t].isSelected&&e.push(this.rows[t]);else if(this.rows.length){let t=this.selection;for(let i=t.topRow;i>-1&&i<=t.bottomRow;i++)e.push(this.rows[i])}return e}set selectedRows(e){wjcCore.assert(this.selectionMode==SelectionMode.ListBox,"This property can be set only in ListBox mode."),e=wjcCore.asArray(e),this.deferUpdate(()=>{for(let t=0,i=!0;t<this.rows.length;t++){let s=this.rows[t],l=e&&e.indexOf(s)>-1;l&&i&&(i=!1,this.select(t,this.selection.col)),s.isSelected=l}})}get selectedItems(){let e=this.selectedRows;for(let t=0;t<e.length;t++)e[t]=e[t].dataItem;return e}set selectedItems(e){wjcCore.assert(this.selectionMode==SelectionMode.ListBox,"This property can be set only in ListBox mode."),e=wjcCore.asArray(e),this.deferUpdate(()=>{for(let t=0,i=!0;t<this.rows.length;t++){let s=this.rows[t],l=e&&e.indexOf(s.dataItem)>-1;l&&i&&(i=!1,this.select(t,this.selection.col)),s.isSelected=l}})}scrollIntoView(e,t,i){null==this._maxOffsetY&&this._updateLayout();let s=this.scrollPosition,l=this._szClient.width,o=this._szClient.height-this._gpCFtr.rows.getTotalSize(),n=this.cells._getFrozenPos();if((e=wjcCore.asInt(e))>-1&&e<this._rows.length&&e>=this._rows.frozen){let t=this._rows[e],i=this.cells.height>o?Math.round(t.pos/(this.cells.height-o)*100)/100:0,l=Math.round(this._maxOffsetY*i),r=t.pos-l,a=r+t.renderSize-1;a>o-s.y&&(s.y=Math.max(-r,o-a)),r-n.y<-s.y&&(s.y=-(r-n.y))}if((t=wjcCore.asInt(t))>-1&&t<this._cols.length&&t>=this._cols.frozen){let e=this._cols[t],i=e.pos+e.renderSize-1;i>-s.x+l&&(s.x=Math.max(-e.pos,l-i)),e.pos-n.x<-s.x&&(s.x=-(e.pos-n.x))}return!s.equals(this._ptScrl)&&(this.scrollPosition=s,i&&(this._updateScrollPosition(),this.refresh()),!0)}isRangeValid(e){return e.isValid&&e.bottomRow<this.rows.length&&e.rightCol<this.columns.length}startEditing(e=!0,t,i,s){return this._edtHdl.startEditing(e,t,i,s)}finishEditing(e){return this._edtHdl.finishEditing(e)}get activeEditor(){return this._edtHdl.activeEditor}get editRange(){return this._edtHdl.editRange}get mergeManager(){return this._mrgMgr}set mergeManager(e){e!=this._mrgMgr&&(this._mrgMgr=wjcCore.asType(e,MergeManager,!0),this.invalidate())}getMergedRange(e,t,i,s=!0){return this._mrgMgr?this._mrgMgr.getMergedRange(e,t,i,s):null}get keyActionTab(){return this._keyHdl._kaTab}set keyActionTab(e){this._keyHdl._kaTab=wjcCore.asEnum(e,KeyAction)}get keyActionEnter(){return this._keyHdl._kaEnter}set keyActionEnter(e){this._keyHdl._kaEnter=wjcCore.asEnum(e,KeyAction)}get showDropDown(){return this._shDropDown}set showDropDown(e){e!=this._shDropDown&&(this._shDropDown=wjcCore.asBoolean(e,!0),this.invalidate())}toggleDropDownList(){this._tglDropDown||(this._tglDropDown=!0,this._edtHdl._toggleListBox(null),this._tglDropDown=!1)}onItemsSourceChanging(e){return this.itemsSourceChanging.raise(this,e),!e.cancel}onItemsSourceChanged(e){this.itemsSourceChanged.raise(this,e)}onScrollPositionChanged(e){this.scrollPositionChanged.raise(this,e)}onSelectionChanging(e){return this.selectionChanging.raise(this,e),!e.cancel}onSelectionChanged(e){this.selectionChanged.raise(this,e)}onLoadingRows(e){return this.loadingRows.raise(this,e),!e.cancel}onLoadedRows(e){this.loadedRows.raise(this,e)}onUpdatingLayout(e){return this.updatingLayout.raise(this,e),!e.cancel}onUpdatedLayout(e){this.updatedLayout.raise(this,e)}onResizingColumn(e){return this.resizingColumn.raise(this,e),!e.cancel}onResizedColumn(e){this.resizedColumn.raise(this,e)}onAutoSizingColumn(e){return this.autoSizingColumn.raise(this,e),!e.cancel}onAutoSizedColumn(e){this.autoSizedColumn.raise(this,e)}onDraggingColumn(e){return this.draggingColumn.raise(this,e),!e.cancel}onDraggingColumnOver(e){return this.draggingColumnOver.raise(this,e),!e.cancel}onDraggedColumn(e){this.draggedColumn.raise(this,e)}onResizingRow(e){return this.resizingRow.raise(this,e),!e.cancel}onResizedRow(e){this.resizedRow.raise(this,e)}onAutoSizingRow(e){return this.autoSizingRow.raise(this,e),!e.cancel}onAutoSizedRow(e){this.autoSizedRow.raise(this,e)}onDraggingRow(e){return this.draggingRow.raise(this,e),!e.cancel}onDraggingRowOver(e){return this.draggingRowOver.raise(this,e),!e.cancel}onDraggedRow(e){this.draggedRow.raise(this,e)}onGroupCollapsedChanging(e){return this.groupCollapsedChanging.raise(this,e),!e.cancel}onGroupCollapsedChanged(e){this.groupCollapsedChanged.raise(this,e)}onSortingColumn(e){return this.sortingColumn.raise(this,e),!e.cancel}onSortedColumn(e){this.sortedColumn.raise(this,e)}onBeginningEdit(e){return this.beginningEdit.raise(this,e),!e.cancel}onPrepareCellForEdit(e){this.prepareCellForEdit.raise(this,e)}onCellEditEnding(e){return this.cellEditEnding.raise(this,e),!e.cancel&&!e.stayInEditMode}onCellEditEnded(e){this.cellEditEnded.raise(this,e)}onRowEditStarting(e){this.rowEditStarting.raise(this,e)}onRowEditStarted(e){this.rowEditStarted.raise(this,e)}onRowEditEnding(e){this.rowEditEnding.raise(this,e)}onRowEditEnded(e){this.rowEditEnded.raise(this,e)}onRowAdded(e){return this.rowAdded.raise(this,e),!e.cancel}onDeletingRow(e){return this.deletingRow.raise(this,e),!e.cancel}onDeletedRow(e){this.deletedRow.raise(this,e)}onCopying(e){return this.copying.raise(this,e),!e.cancel}onCopied(e){this.copied.raise(this,e)}onPasting(e){return this.pasting.raise(this,e),!e.cancel}onPasted(e){this.pasted.raise(this,e)}onPastingCell(e){return this.pastingCell.raise(this,e),!e.cancel}onPastedCell(e){this.pastedCell.raise(this,e)}onFormatItem(e){this.formatItem.raise(this,e)}onUpdatingView(e){return this.updatingView.raise(this,e),!e.cancel}onUpdatedView(e){this.updatedView.raise(this,e)}_getShowErrors(){return this.showErrors&&this._hasValidation}_getHasValidation(){return this._hasValidation}_getError(e,t,i){if(wjcCore.isFunction(this.itemValidator)){if(e==this.cells)return this.itemValidator(t,i);if(e==this.rowHeaders)for(i=0;i<this.columns.length;i++){let e=this.itemValidator(t,i);if(e)return e}}let s=this._cv,l=s?s.getError:null;if(wjcCore.isFunction(l)){let s=e.rows,o=this.columns,n=s[t].dataItem;if(n)for(;t<s.length&&s[t].dataItem==n;t++){if(e==this.cells)return l(n,this._getBindingColumn(this.cells,t,o[i]).binding);if(e==this.rowHeaders)for(i=0;i<o.length;i++){let e=l(n,this._getBindingColumn(this.cells,t,o[i]).binding);if(e)return e}}}return null}_setAria(e,t){wjcCore.setAttribute(this.cells.hostElement,"aria-"+e,t)}_setFocus(e){if(this.hostElement&&(e||!this.containsFocus())){let e=wjcCore.getActiveElement(),t=this.activeEditor,i=this._activeCell,s=this._eFocus,l="tabindex";if(t)wjcCore.contains(t,e)||(t.focus(),s.removeAttribute(l));else if(i){if(!wjcCore.contains(i,e)&&e!=this._root){let e=!1;wjcCore.isIE()&&(this._setFocusNoScroll(i),e=!0),e||(i.tabIndex=this._tabIndex,i.focus()),s.removeAttribute(l)}}else wjcCore.contains(s,e)||e==this._root||(s.tabIndex=this._tabIndex,s.focus());this.containsFocus()||(s.tabIndex=this._tabIndex,s.focus())}}_setFocusNoScroll(e){if(e.tabIndex=this._tabIndex,wjcCore.supportsFocusOptions())e.focus({preventScroll:!0});else{let t=this.scrollPosition,i=e.style,s=i.position;i.position="fixed",e.focus(),i.position=s,this.scrollPosition=t}this._fixScroll()}_getDefaultRowHeight(){let e=this._eFocus,t=null;e.scrollHeight||(e=(t=wjcCore.createElement('<div class="wj-flexgrid"><div class="wj-cell">0</div></div>',document.body)).children[0]);let i=e.scrollHeight+2;return(isNaN(i)||i<=6)&&(i=28),wjcCore.removeChild(t),i}_getDefaultCellPadding(){let e=getComputedStyle(this._eFocus);return parseInt(this.rightToLeft?e.paddingRight:e.paddingLeft)}_getCollectionView(e){return wjcCore.asCollectionView(e)}_getCanvasContext(){let e=document.createElement("canvas").getContext("2d"),t=getComputedStyle(this.hostElement);return e.font=t.fontSize+" "+t.fontFamily.split(",")[0],e}_getWidestRow(e,t,i,s){let l=0,o=0,n=e.columns[i].dataType==wjcCore.DataType.Boolean;for(let r=t.row;r<=t.row2;r++)if(e.rows[r].isVisible){let t=e.getCellData(r,i,!0),a=s.measureText(t).width;if(a>o&&(o=a,l=r),n)break}return l}_getDesiredWidth(e,t,i,s){let l=this.getMergedRange(e,t,i,!1),o=s.style;return this.cellFactory.updateCell(e,t,i,s,l),o.width=o.top=o.left="",s.offsetWidth/(l&&l.columnSpan>1?l.columnSpan:1)}_getDesiredHeight(e,t,i,s){let l=this.getMergedRange(e,t,i,!1),o=s.style;return this.cellFactory.updateCell(e,t,i,s,l),o.height=o.top=o.left="",s.offsetHeight/(l&&l.rowSpan>1?l.rowSpan:1)}_getDesiredRowHeight(e,t,i,s){let l=0;for(let o=0;o<e.columns.length;o++){let n=e.columns[o];if(n.isVisible){let r,a=this.getMergedRange(e,t,o,!1),h={ct:e.cellType,col:o,rng:a&&a.rowSpan>1?a.rowSpan:1,content:n.dataType==wjcCore.DataType.Number?"1":e.getCellData(t,o,!0)},d=JSON.stringify(h);null==(r=s[d])&&(r=this._getDesiredHeight(e,t,o,i),s[d]=r),l=Math.max(l,r)}}return l}_getSortRowIndex(){return null!=this._sortRowIndex?this._sortRowIndex:this.columnHeaders.rows.length-1}_sortConverter(e,t,i,s){let l;if(s){if(this._mappedColumns=null,this._cv){let e=this._cv.sortDescriptions;for(let t=0;t<e.length;t++)(l=this.getColumn(e[t].property))&&l.dataMap&&(this._mappedColumns||(this._mappedColumns={}),this._mappedColumns[l.binding]=l.dataMap)}this._mouseHdl._htDown&&this._mouseHdl._htDown.col>-1&&(l=this.columns[this._mouseHdl._htDown.col],this._mappedColumns&&l.dataMap&&(this._mappedColumns[l.binding]=l.dataMap))}if(this._mappedColumns){let t=this._mappedColumns[e.property];t&&t.sortByDisplayValues&&(i=t.getDisplayValue(i))}return i}_bindGrid(e){if(this.finishEditing(),this.deferUpdate(()=>{0==this._lastCount&&wjcCore.hasItems(this._cv)&&(e=!0);let t,i=this.selectionMode==SelectionMode.ListBox;this.preserveSelectedState&&i&&!this.childItemsPath&&(t=this.selectedItems);let s;if(this.preserveOutlineState&&wjcCore.isFunction(window.Map)&&this.rows.maxGroupLevel>-1){s=new Map;for(let e=0;e<this.rows.length;e++){let t=this.rows[e];if(t instanceof GroupRow&&t.isCollapsed&&t.dataItem){let e=t.dataItem;e instanceof wjcCore.CollectionViewGroup&&(e=e._path),s.set(e,!0)}}}e&&this.columns.deferUpdate(()=>{this._bindColumns()});let l=new wjcCore.CancelEventArgs;this.onLoadingRows(l)&&(this.rows.deferUpdate(()=>{this._bindRows()}),this.onLoadedRows(l));let o=0;if(t&&t.length)for(let e=0;e<this.rows.length&&o<t.length;e++)t.indexOf(this.rows[e].dataItem)>-1&&(this.rows[e].isSelected=!0,o++);if(i&&0==o&&this._lastCount>0){let e=this.selection;for(let t=e.topRow;t<=e.bottomRow&&t>-1&&t<this.rows.length;t++)this.rows[t].isSelected=!0}s&&this.rows.deferUpdate(()=>{for(let e=0;e<this.rows.length;e++){let t=this.rows[e];if(t instanceof GroupRow){let e=t.dataItem;e instanceof wjcCore.CollectionViewGroup&&(e=e._path),s.get(e)&&(t.isCollapsed=!0)}}}),!this._lastCount&&this._cv&&this._cv.items&&(this._lastCount=this._cv.items.length)}),!this.rows.length){let e=this._selHdl.selection;e.row=e.row2=-1}this._cv&&this._syncSelection(e)}_cvCollectionChanged(e,t){if(this.autoGenerateColumns&&0==this.columns.length)this._bindGrid(!0);else if(this.childItemsPath&&t.action!=wjcCore.NotifyCollectionChangedAction.Change)this._bindGrid(!1);else{switch(t.action){case wjcCore.NotifyCollectionChangedAction.Change:return void this.invalidate();case wjcCore.NotifyCollectionChangedAction.Add:if(t.index==this._cv.items.length-1){let e=this.rows.length;return this.rows[e-1]instanceof _NewRowTemplate&&e--,void this.rows.insert(e,new Row(t.item))}wjcCore.assert(!1,"added item should be the last one.");break;case wjcCore.NotifyCollectionChangedAction.Remove:let e=this._findRow(t.item);if(e>-1)return this.rows.removeAt(e),void this._syncSelection(!1);wjcCore.assert(!1,"removed item not found on grid.")}this._bindGrid(!1)}}_cvCurrentChanged(e,t){this._syncSelection(!1)}_syncSelection(e){if(this._cv&&this.selectionMode!=SelectionMode.None){let t=this.selection,i=t.row>-1&&t.row<this.rows.length?this.rows[t.row].dataItem:null;if(i instanceof wjcCore.CollectionViewGroup&&(i=null),(i!=this._cv.currentItem||e)&&(!this.childItemsPath||!this.editableCollectionView||!this.editableCollectionView.currentAddItem)){let e=this._getRowIndex(this._cv.currentPosition);e==t.row&&this.childItemsPath||(t.row=t.row2=e,this.select(t,!1),this.selectionMode&&this.scrollIntoView(t.row,-1))}}}_getRowIndex(e){if(this._cv){if(e>-1){let t=this._cv.items[e];for(;e<this.rows.length;e++)if(this.rows[e].dataItem===t)return e;return-1}{if(1==this.rows.length&&this.rows[0]instanceof _NewRowTemplate)return 0;let e=this.selection.row,t=e>-1?this.rows[e]:null;return t&&(t instanceof GroupRow||null==t.dataItem)?e:-1}}return this.selection.row}_getCvIndex(e){if(this._cv&&e>-1&&e<this.rows.length){let t=this._cv.items,i=this.rows[e].dataItem;for(e=Math.min(e,t.length-1);e>-1;e--)if(t[e]===i)return e}return-1}_findRow(e){for(let t=0;t<this.rows.length;t++)if(this.rows[t].dataItem==e)return t;return-1}_updateLayout(){let e=new wjcCore.CancelEventArgs;if(!this.onUpdatingLayout(e))return;this._hasValidation=wjcCore.isFunction(this._itemValidator)||this._cv&&wjcCore.isFunction(this._cv.getError);let t=this._hdrVis&HeadersVisibility.Row?this._hdrCols.getTotalSize():0,i=this._hdrVis&HeadersVisibility.Column?this._hdrRows.getTotalSize():0,s=this._ftrRows.getTotalSize(),l=this._rows.getTotalSize()+s;l<1&&(l=1),this._heightBrowser=Math.min(l,FlexGrid._getMaxSupportedCssHeight()),this._maxOffsetY=Math.max(0,l-this._heightBrowser),this._cellPadding=this._getDefaultCellPadding();let o=this._heightBrowser+i-s,n=this._gpCells.width,r=this._heightBrowser;!n&&this.rows.length&&(n=.1),!r&&this.columns.length&&(r=.1),this.rightToLeft?(wjcCore.setCss(this._eTL,{right:0,top:0,width:t,height:i}),wjcCore.setCss(this._eCHdr,{right:t,top:0,height:i}),wjcCore.setCss(this._eRHdr,{right:0,top:i,width:t}),wjcCore.setCss(this._eCt,{right:t,top:i,width:n,height:r}),wjcCore.setCss(this._fCt,{right:t,top:i}),wjcCore.setCss(this._eBL,{right:0,top:o,width:t,height:s}),wjcCore.setCss(this._eCFtr,{right:t,top:o,height:s})):(wjcCore.setCss(this._eTL,{left:0,top:0,width:t,height:i}),wjcCore.setCss(this._eCHdr,{left:t,top:0,height:i}),wjcCore.setCss(this._eRHdr,{left:0,top:i,width:t}),wjcCore.setCss(this._eCt,{left:t,top:i,width:n,height:r}),wjcCore.setCss(this._fCt,{left:t,top:i}),wjcCore.setCss(this._eBL,{left:0,top:o,width:t,height:s}),wjcCore.setCss(this._eCFtr,{left:t,top:o,height:s})),this._stickyHdr&&this._updateStickyHeaders();let a=this.frozenRows||this.frozenColumns?"3":"";wjcCore.setCss([this._eTL,this._eBL,this._eCHdr,this._eCFtr,this._eRHdr,this._eMarquee],{zIndex:a});let h=this._root,d=h.offsetWidth-h.clientWidth,c=h.offsetHeight-h.clientHeight;wjcCore.setCss(this._eSz,{width:t+d+this._gpCells.width,height:i+c+this._heightBrowser});let g=null;this.columns._updateStarSizes(h.clientWidth-t)&&(g=h.clientWidth,wjcCore.setCss(this._eCt,{width:this._gpCells.width})),this._szClient=new wjcCore.Size(h.clientWidth-t,h.clientHeight-i),this._rcBounds=null,this._updateScrollHandler(),this._updateContent(!1),d=h.offsetWidth-h.clientWidth,c=h.offsetHeight-h.clientHeight,wjcCore.setCss(this._eSz,{width:t+d+this._gpCells.width,height:i+c+this._heightBrowser}),this._szClient=new wjcCore.Size(h.clientWidth-t,h.clientHeight-i),g&&g!=h.clientWidth&&this.columns._updateStarSizes(h.clientWidth-t)&&(wjcCore.setCss(this._eCt,{width:this._gpCells.width}),this._updateContent(!1)),wjcCore.setCss([this._eCHdr,this._eCFtr,this._fCt],{width:this._szClient.width}),wjcCore.setCss([this._eRHdr,this._fCt],{height:this._szClient.height}),s&&(o=Math.min(o,this._szClient.height+i-s),wjcCore.setCss([this._eBL,this._eCFtr],{top:o})),this.onUpdatedLayout(e)}_updateStickyHeaders(){let e=!1,t=0;if(this._stickyHdr){let i=0,s=null;for(let e=this.hostElement;e;e=e.parentElement){let t=e.getBoundingClientRect();null==s&&(s=t.top),i=Math.max(i,t.top)}t=-(s=Math.max(0,i-s-1)),e=s>0,this._rcBounds=null}this._eTL.style.top=this._eCHdr.style.top=e?-t+"px":"",wjcCore.toggleClass(this._eTL,FlexGrid._WJS_STICKY,e),wjcCore.toggleClass(this._eCHdr,FlexGrid._WJS_STICKY,e)}_updateScrollHandler(){this._clipToScreen=this._getClipToScreen();let e=this._stickyHdr||this._clipToScreen;e!=this._scrollHandlerAttached&&(this._scrollHandlerAttached=e,e?this.addEventListener(window,"scroll",this._bndScroll,!0):this.removeEventListener(window,"scroll",this._bndScroll,!0))}_getClipToScreen(){if(this.rows.length<=FlexGrid._MIN_VIRT_ROWS)return!1;if(this._root.clientHeight!=this._root.scrollHeight)return!1;for(let e=this.hostElement;e&&e!=document.documentElement;e=e.parentElement)if("auto"==getComputedStyle(e).overflow)return!1;return!0}_scroll(e){wjcCore.contains(e.target,this.hostElement)&&(this._clipToScreen&&(this._afScrl&&cancelAnimationFrame(this._afScrl),this._afScrl=requestAnimationFrame(()=>{this._afScrl=null,this.finishEditing(),this._updateContent(!0)})),this._stickyHdr&&(this._afSticky&&cancelAnimationFrame(this._afSticky),this._afSticky=requestAnimationFrame(()=>{this._afSticky=null;let e=new wjcCore.CancelEventArgs;this.onUpdatingLayout(e)&&(this._updateStickyHeaders(),this.onUpdatedLayout(e))})))}_updateScrollPosition(){let e=this._root,t=e.scrollTop,i=e.scrollLeft;this.rightToLeft&&"rev"==FlexGrid._getRtlMode()&&(i=e.scrollWidth-e.clientWidth-i);let s=new wjcCore.Point(-Math.abs(i),-t);return!this._ptScrl.equals(s)&&(this._ptScrl=s,this.onScrollPositionChanged(),!0)}_updateContent(e,t){let i=this._root,s=this.hostElement,l=this.cells.hostElement,o=wjcCore.getActiveElement(),n=wjcCore.contains(s,o)?o:null,r=this._activeCell,a=new wjcCore.CancelEventArgs;if(!this.onUpdatingView(a))return;if(wjcCore.setAttribute(l,"role",this.rows.maxGroupLevel<0?"grid":"treegrid"),this._offsetY=0,this._heightBrowser>this._szClient.height){let e=Math.round(-this._ptScrl.y/(this._heightBrowser-this._szClient.height)*100)/100;this._offsetY=Math.round(this._maxOffsetY*e)}this._updateScrollPosition();let h=this._gpCells._updateContent(e,t,this._offsetY);if(this._hdrVis&HeadersVisibility.Column&&(!t||this._ssHdr&HeadersVisibility.Column)&&this._gpCHdr._updateContent(e,t,0),this._hdrVis&HeadersVisibility.Row&&(!t||this._ssHdr&HeadersVisibility.Row)&&this._gpRHdr._updateContent(e,t,this._offsetY),this._hdrVis&&!t&&this._gpTL._updateContent(e,t,0),this._gpCFtr.rows.length&&(this._gpBL._updateContent(e,t,0),this._gpCFtr._updateContent(e,t,0)),this.showMarquee){let e=this._selHdl.selection,t=this._eMarquee;if(this.isRangeValid(e)){let i=this._getMarqueeRect(e),s=t.firstChild,o=t.offsetWidth-s.offsetWidth,n=t.offsetHeight-s.offsetHeight;wjcCore.setCss(t,{left:i.left+l.offsetLeft-o/2,top:i.top+l.offsetTop-n/2,width:i.width+o,height:i.height+n,visibility:i.width>0&&i.height>0?"":"collapse"})}else wjcCore.setCss(t,{left:0,top:0,width:0,height:0,visibility:"collapse"})}if(this._useFrozenDiv()&&(this._updateFrozenCells(t),h&&wjcCore.hasClass(h,"wj-frozen")&&(h=null)),this._fCt.style.display=this._fCt.firstChild?"":"none",this._activeCell=h,n)if(n!=i&&n!=this._eFocus&&wjcCore.contains(s,n)&&!wjcCore.contains(l,n)){if(wjcCore.getActiveElement()!=n&&n.focus(),wjcCore.isIE()&&n instanceof HTMLInputElement&&!n.type.match(/checkbox|radio|range/i)){let e=n.selectionStart,t=n.selectionEnd;n.setSelectionRange(e,t)}}else{let e=h!=r;this._setFocus(e)}!n&&h&&(h.tabIndex=this._tabIndex),r&&r!=h&&r.removeAttribute("tabindex"),this._fixScroll(),this._rcBounds=null,this.onUpdatedView(a)}_fixScroll(){[this.hostElement,this._root?this._root.parentElement:null].forEach(e=>{e&&e.scrollTop&&(e.scrollTop=0)})}_clearCells(){for(let e in this)if("_"==e[0]){let t=this[e];t instanceof GridPanel&&t._clearCells()}this.invalidate()}_useFrozenDiv(){return wjcCore.isBoolean(this._fzClone)?this._fzClone:wjcCore.isIE()||wjcCore.isFirefox()||wjcCore.isSafari()||wjcCore.isMobile()}_updateFrozenCells(e){if(this.frozenRows||this.frozenColumns){let t=this._eCt.querySelectorAll(".wj-frozen");if(e&&this._fCt.children.length==t.length){for(let e=0;e<t.length;e++)this._fCt.children[e].className=t[e].className;return}if(wjcCore.setText(this._fCt,null),!this.activeEditor)for(let e=0;e<t.length;e++){let i=t[e].cloneNode(!0);i.style.pointerEvents="auto",this._fCt.appendChild(i)}}else wjcCore.setText(this._fCt,null)}_getMarqueeRect(e){let t=this.getMergedRange(this.cells,e.topRow,e.leftCol)||new CellRange(e.topRow,e.leftCol),i=this.getMergedRange(this.cells,e.bottomRow,e.rightCol)||new CellRange(e.bottomRow,e.rightCol),s=this.cells.getCellBoundingRect(t.topRow,t.leftCol,!0),l=this.cells.getCellBoundingRect(i.bottomRow,i.rightCol,!0);if(this.rows.frozen){let t=Math.min(this.rows.length,this.rows.frozen),i=this.cells.getCellBoundingRect(t-1,0,!0);e.topRow>=t&&s.top<i.bottom&&(s.top=i.bottom),e.bottomRow>=t&&l.bottom<i.bottom&&(l.height=i.bottom-l.top)}if(this.columns.frozen){let t=Math.min(this.columns.length,this.columns.frozen),i=this.cells.getCellBoundingRect(0,t-1,!0);this.rightToLeft?(e.leftCol>=t&&s.right>i.left&&(s.left=i.left-s.width),e.rightCol>=t&&l.left>i.left&&(l.left=i.left)):(e.leftCol>=t&&s.left<i.right&&(s.left=i.right),e.rightCol>=t&&l.right<i.right&&(l.width=i.right-l.left))}return this.rightToLeft?new wjcCore.Rect(l.left,s.top,s.right-l.left,l.bottom-s.top):new wjcCore.Rect(s.left,s.top,l.right-s.left,l.bottom-s.top)}_bindColumns(){for(let e=0;e<this.columns.length;e++)this.columns[e]._getFlag(RowColFlags.AutoGenerated)&&(this.columns.removeAt(e),e--);let e=this._cv,t=e?e.sourceCollection:null,i=t&&t.length?t[0]:null;if(i&&this.autoGenerateColumns)for(let e in i){let s=null;for(let l=0;l<t.length&&l<1e3&&null==s;l++)if(s=t[l][e],wjcCore.isPrimitive(s)){let t=new Column;t._setFlag(RowColFlags.AutoGenerated,!0),t.binding=t.name=e,t.header=wjcCore.toHeaderCase(e),t.dataType=wjcCore.getType(s),t.dataType==wjcCore.DataType.Number&&(t.width=80);let l=Object.getOwnPropertyDescriptor(i,e);!l||l.writable||wjcCore.isFunction(l.set)||t._setFlag(RowColFlags.ReadOnly,!0),this.columns.push(t)}}this._updateColumnTypes()}_updateColumnTypes(){let e=this._cv;if(wjcCore.hasItems(e)){let t=e.items[0],i=this.columns;for(let e=0;e<i.length;e++){let s=i[e];null==s.dataType&&s._binding&&(s.dataType=wjcCore.getType(s._binding.getValue(t)))}}}_getBindingColumn(e,t,i){return i}_getRowHeaderPath(){return this._rowHdrPath}_bindRows(){this.rows.clear();let e=this._cv;if(e&&e.items){let t=e.items,i=e.groups;if(this.childItemsPath)for(let e=0;e<t.length;e++)this._addNode(t,e,0);else if(null!=i&&i.length>0&&this.showGroups)for(let e=0;e<i.length;e++)this._addGroup(i[e]);else for(let e=0;e<t.length;e++)this._addBoundRow(t,e)}}_addBoundRow(e,t){this.rows.push(new Row(e[t]))}_addNode(e,t,i){let s=new GroupRow,l=this.childItemsPath,o=wjcCore.isArray(l)?l[i]:l,n=e[t],r=n[o];if(s.dataItem=n,s.level=i,this.rows.push(s),wjcCore.isArray(r))for(let e=0;e<r.length;e++)this._addNode(r,e,i+1)}_addGroup(e){let t=new GroupRow;if(t.level=e.level,t.dataItem=e,this.rows.push(t),e.isBottomLevel){let t=e.items;for(let e=0;e<t.length;e++)this._addBoundRow(t,e)}else for(let t=0;t<e.groups.length;t++)this._addGroup(e.groups[t])}static _getSerializableProperties(e){let t=[];for(e=e.prototype;e!=Object.prototype;e=Object.getPrototypeOf(e)){let i=Object.getOwnPropertyNames(e);for(let s=0;s<i.length;s++){let l=i[s],o=Object.getOwnPropertyDescriptor(e,l);o&&o.set&&o.get&&"_"!=l[0]&&!l.match(/disabled|required/)&&t.push(l)}}return t}_copy(e,t){if("columns"==e){this.columns.clear();let e=wjcCore.asArray(t);for(let t=0;t<e.length;t++){let i=new Column;wjcCore.copy(i,e[t]),this.columns.push(i)}return!0}return!1}_isInputElement(e){if(e instanceof HTMLElement){if("true"==e.contentEditable)return!0;let t=e.tagName.match(/^(BUTTON|A|INPUT|TEXTAREA|SELECT|OPTION)$/i);return t&&t.length>0}return!1}_wantsInput(e){return this._isInputElement(e)&&!this.activeEditor&&!this._edtHdl._isNativeCheckbox(e)&&!wjcCore.hasClass(e,"wj-grid-ime")&&wjcCore.contains(document.body,e)}static _getMaxSupportedCssHeight(){if(!FlexGrid._maxCssHeight){let e=335e5;wjcCore.isIE()?e=15e5:wjcCore.isFirefox()&&(e=175e5),FlexGrid._maxCssHeight=e}return FlexGrid._maxCssHeight}static _getRtlMode(){if(!FlexGrid._rtlMode){let e=wjcCore.createElement('<div dir="rtl" style="visibility:hidden;width:100px;height:100px;overflow:auto"><div style="width:2000px;height:2000px"></div></div>');document.body.appendChild(e);let t=e.scrollLeft;e.scrollLeft=-1e3;let i=e.scrollLeft;wjcCore.removeChild(e),FlexGrid._rtlMode=i<0?"neg":t>0?"rev":"std"}return FlexGrid._rtlMode}}FlexGrid._WJS_STICKY="wj-state-sticky",FlexGrid._WJS_MEASURE="wj-state-measuring",FlexGrid._WJS_UPDATING="wj-state-updating",FlexGrid._MIN_VIRT_ROWS=200,FlexGrid.controlTemplate='<div style="position:relative;width:100%;height:100%;overflow:hidden;max-width:inherit;max-height:inherit"><div wj-part="focus" aria-hidden="true" class="wj-cell" style="position:fixed;opacity:0;pointer-events:none;left:-10px;top:-10px">0</div><div wj-part="root" style="position:absolute;width:100%;height:100%;overflow:auto;max-width:inherit;max-height:inherit;-webkit-overflow-scrolling:touch;"><div wj-part="cells" class="wj-cells" style="position:absolute"></div><div wj-part="marquee" aria-hidden="true" class="wj-marquee" style="display:none;pointer-events:none;"><div style="width:100%;height:100%"></div></div></div><div wj-part="fcells" aria-hidden="true" class="wj-cells" style="position:absolute;pointer-events:none;overflow:hidden"></div><div wj-part="rh" aria-hidden="true" style="position:absolute;overflow:hidden;outline:none"><div wj-part="rhcells" class="wj-rowheaders" style="position:relative"></div></div><div wj-part="cf" aria-hidden="true" style="position:absolute;overflow:hidden;outline:none"><div wj-part="cfcells" class="wj-colfooters" style="position:relative"></div></div><div wj-part="ch" aria-hidden="true" style="position:absolute;overflow:hidden;outline:none"><div wj-part="chcells" class="wj-colheaders" style="position:relative"></div></div><div wj-part="bl" aria-hidden="true" style="position:absolute;overflow:hidden;outline:none"><div wj-part="blcells" class="wj-bottomleft" style="position:relative"></div></div><div wj-part="tl" aria-hidden="true" style="position:absolute;overflow:hidden;outline:none"><div wj-part="tlcells" class="wj-topleft" style="position:relative"></div></div><div wj-part="sz" aria-hidden="true" style="position:relative;visibility:hidden"></div></div>',exports.FlexGrid=FlexGrid;class CellRangeEventArgs extends wjcCore.CancelEventArgs{constructor(e,t,i){super(),this._p=wjcCore.asType(e,GridPanel,!0),this._rng=wjcCore.asType(t,CellRange,!0),this._data=i}get panel(){return this._p}get range(){return this._rng.clone()}get row(){return this._rng.row}get col(){return this._rng.col}get data(){return this._data}set data(e){this._data=e}}exports.CellRangeEventArgs=CellRangeEventArgs;class FormatItemEventArgs extends CellRangeEventArgs{constructor(e,t,i){super(e,t),this._cell=wjcCore.asType(i,HTMLElement)}get cell(){return this._cell}}exports.FormatItemEventArgs=FormatItemEventArgs;class CellEditEndingEventArgs extends CellRangeEventArgs{constructor(){super(...arguments),this._stayInEditMode=!1,this._refresh=!0}get stayInEditMode(){return this._stayInEditMode}set stayInEditMode(e){this._stayInEditMode=wjcCore.asBoolean(e)}get refresh(){return this._refresh}set refresh(e){this._refresh=wjcCore.asBoolean(e)}}exports.CellEditEndingEventArgs=CellEditEndingEventArgs;var CellType;!function(e){e[e.None=0]="None",e[e.Cell=1]="Cell",e[e.ColumnHeader=2]="ColumnHeader",e[e.RowHeader=3]="RowHeader",e[e.TopLeft=4]="TopLeft",e[e.ColumnFooter=5]="ColumnFooter",e[e.BottomLeft=6]="BottomLeft"}(CellType=exports.CellType||(exports.CellType={}));class GridPanel{constructor(e,t,i,s,l){this._offsetY=0,this._g=wjcCore.asType(e,FlexGrid),this._ct=wjcCore.asInt(t),this._rows=wjcCore.asType(i,RowCollection),this._cols=wjcCore.asType(s,ColumnCollection),this._e=wjcCore.asType(l,HTMLElement),this._vrb=new CellRange}get grid(){return this._g}get cellType(){return this._ct}get viewRange(){return this._getViewRange()}get width(){return this._cols.getTotalSize()}get height(){return this._rows.getTotalSize()}get rows(){return this._rows}get columns(){return this._cols}getCellData(e,t,i){let s,l=this._rows[wjcCore.asNumber(e,!1,!0)],o=null;if(wjcCore.isString(t)&&(t=this._cols.indexOf(t))<0)throw"Invalid column name or binding.";s=this._cols[wjcCore.asNumber(t,!1,!0)];let n=this._g?this._g._getBindingColumn(this,e,s):s;if(!n.binding||!l.dataItem||l.dataItem instanceof wjcCore.CollectionViewGroup?l._ubv&&(o=l._ubv[s._hash]):o=n._binding.getValue(l.dataItem),null==o)switch(this._ct){case CellType.ColumnHeader:e!=this._rows.length-1&&n==s||(o=n.header);break;case CellType.ColumnFooter:if(n.aggregate!=wjcCore.Aggregate.None&&l instanceof GroupRow){let e=this._g.collectionView;if(e){let t=wjcCore.tryCast(e,wjcCore.CollectionView);o=t?t.getAggregate(n.aggregate,n.binding):wjcCore.getAggregate(n.aggregate,e.items,n.binding)}}break;case CellType.Cell:if(n.aggregate!=wjcCore.Aggregate.None&&l instanceof GroupRow){let e=wjcCore.tryCast(l.dataItem,wjcCore.CollectionViewGroup);e&&(o=e.getAggregate(n.aggregate,n.binding,this._g.collectionView))}}return i&&(this.cellType==CellType.Cell&&n.dataMap&&(o=n.dataMap.getDisplayValue(o)),o=null!=o?wjcCore.Globalize.format(o,n.format):""),o}setCellData(e,t,i,s=!0,l=!0){let o,n=this._rows[wjcCore.asNumber(e,!1,!0)];if(wjcCore.isString(t)&&(t=this._cols.indexOf(t))<0)throw"Invalid column name or binding.";o=this._cols[wjcCore.asNumber(t,!1,!0)];let r=this._g?this._g._getBindingColumn(this,e,o):o;if(this._ct==CellType.Cell){if(r.dataMap&&null!=i&&(r.isRequired||""!=i)){let e=r.dataMap,t=e.getKeyValue(i);if(null==t&&null==e.getDisplayValue(null)){if(e.getDisplayValue(i)!=i);else if(!e.isEditable||e.displayMemberPath!=e.selectedValuePath)return!1}else i=t}let l=wjcCore.DataType.Object;if(r.dataType)l=r.dataType;else{let i=this.getCellData(e,t,!1);l=wjcCore.getType(i)}if(wjcCore.isBoolean(r.isRequired))if(r.isRequired||""!==i&&null!==i){if(r.isRequired&&(""===i||null===i))return!1}else i=null,s=!1;if(s&&(i=wjcCore.changeType(i,l,r.format),l!=wjcCore.DataType.Object&&wjcCore.getType(i)!=l))return!1}if(n.dataItem&&r.binding){let e=r._binding,t=n.dataItem,s=e.getValue(t);if(i!==s&&!wjcCore.DateTime.equals(i,s)){e.setValue(t,i);let s=this._g.collectionView;if(s instanceof wjcCore.CollectionView&&t!=s.currentEditItem){let e=new wjcCore.NotifyCollectionChangedEventArgs(wjcCore.NotifyCollectionChangedAction.Change,t,s.items.indexOf(t));s.onCollectionChanged(e)}}}else n._ubv||(n._ubv={}),n._ubv[o._hash]=i;return l&&this._g&&this._g.invalidate(),!0}getCellBoundingRect(e,t,i){let s=this.rows[e],l=this.columns[t],o=new wjcCore.Rect(l.pos,s.pos,l.renderSize,s.renderSize);if(this._g.rightToLeft&&(o.left=this.hostElement.clientWidth-o.right,!wjcCore.isIE()&&!wjcCore.isFirefox())){let e=this.hostElement.parentElement;o.left-=e.offsetWidth-e.clientWidth}if(!i){let e=this.hostElement.getBoundingClientRect();o.left+=e.left,o.top+=e.top-this._offsetY}return e<this.rows.frozen&&(o.top-=this._g.scrollPosition.y),t<this.columns.frozen&&(o.left-=this._g.scrollPosition.x*(this._g.rightToLeft?-1:1)),o}getCellElement(e,t){let i=this.hostElement.children,s=Math.min(e+2,i.length);for(let l=0;l<s;l++){let s=i[l].children,o=Math.min(t+2,s.length);for(let i=0;i<o;i++){let l=s[i],o=l[GridPanel._INDEX_KEY];if(o&&(o.row==e&&o.col==t||o.rng&&o.rng.contains(e,t)))return l}}return null}getSelectedState(e,t,i){let s=this._g,l=s.selectionMode,o=s._selHdl.selection,n=SelectionMode,r=SelectedState;if(l!=n.None)switch(this._ct){case CellType.Cell:if(i||(i=s.getMergedRange(this,e,t)),i){if(i.contains(o.row,o.col))return s.showMarquee?r.None:r.Cursor;if(i.intersects(o))return r.Selected}if(o.row==e&&o.col==t)return s.showMarquee?r.Active:r.Cursor;if(s.rows[e].isSelected||s.columns[t].isSelected)return r.Selected;if(i)switch(l){case n.Row:case n.RowRange:case n.ListBox:if(i.containsRow(o.row))return r.Selected}return o=s._selHdl._adjustSelection(o),l==SelectionMode.ListBox?r.None:o.containsRow(e)&&o.containsColumn(t)?r.Selected:r.None;case CellType.ColumnHeader:if(s.showSelectedHeaders&HeadersVisibility.Column&&(s.columns[t].isSelected||o.containsColumn(t)||o.intersectsColumn(i))&&(i&&(e=i.bottomRow),e==this.rows.length-1))return r.Selected;break;case CellType.RowHeader:if(s.showSelectedHeaders&HeadersVisibility.Row&&(s.rows[e].isSelected||o.containsRow(e)||o.intersectsRow(i))&&(i&&(t=i.rightCol),t==this.columns.length-1))return r.Selected}return r.None}get hostElement(){return this._e}_getOffsetY(){return this._offsetY}_updateContent(e,t,i){let s=this._g,l=this._e,o=this._rows,n=this._cols,r=this._ct;if(r==CellType.ColumnHeader||r==CellType.ColumnFooter||r==CellType.RowHeader){let e=s._ptScrl,t=l.style;r==CellType.RowHeader?t.top=e.y+"px":s.rightToLeft?t.right=e.x+"px":t.left=e.x+"px"}this._offsetY!=i&&(e=!1,this._offsetY=i);let a=this._getViewRange(),h=a;if(o.length<=s.virtualizationThreshold)h=new CellRange(0,0,o.length-1,n.length-1);else if(h.isValid&&s.isTouching){h=new CellRange(Math.max(a.row-6,o.frozen),Math.max(a.col-1,n.frozen),Math.min(a.row2+6,o.length-1),Math.min(a.col2+1,n.length-1))}if(e&&!t&&this._vrb.contains(a)&&!o.frozen&&!n.frozen)return this._activeCell;e&&h.equals(this._vrb)||(t=!1),e&&!t&&this._ct!=CellType.TopLeft&&this._reorderCells(h,this._vrb),this._activeCell=null,this._vru=a,this._vrb=h,this._cf=s.cellFactory;let d=0;this._ct==CellType.Cell&&(d=this._renderColHdrRow(h,t));for(let e=0;e<o.frozen&&e<o.length;e++)d=this._renderRow(e,h,t,d);for(let e=h.topRow;e<=h.bottomRow&&e>-1;e++)d=this._renderRow(e,h,t,d);for(;l.childElementCount>d;){let e=l.lastElementChild;l.removeChild(e),this._removeExtraCells(e,0)}return this._activeCell}_updateScrollPosition(){let e=this._g,t=e._ptScrl,i=this.hostElement.style;this.cellType==CellType.RowHeader?i.top=t.y+"px":e.rightToLeft?i.right=t.x+"px":i.left=t.x+"px"}_clearCells(){let e=this.hostElement;for(let t=e.childElementCount-1;t>=0;t--){let i=e.children[t];e.removeChild(i);for(let e=i.childElementCount-1;e>=0;e--)this._cf.disposeCell(i.children[e])}}_reorderCells(e,t){if(!(this._rows.frozen>0||this._cols.frozen>0||e.columnSpan!=t.columnSpan||e.rowSpan!=t.rowSpan)&&t.isValid&&e.isValid&&e.intersects(t)&&e.row!=t.row){let i=e.row-t.row,s=Math.max(1,e.rowSpan-1),l=this._e;if(0!=i&&Math.abs(i)<s){let e=this._ct==CellType.Cell?1:0,t=l.childElementCount;if(i>0){let s=e,o=Math.min(e+i,t-1),n=this._createRange(s,o);n&&o<t-1&&l.appendChild(n.extractContents())}if(i<0){let s=t,o=Math.max(e,s+i),n=this._createRange(o,s);if(n&&o>e){let t=l.children[e];l.insertBefore(n.extractContents(),t)}}}}}_createRange(e,t){let i,s=this._e.childElementCount;return t>e&&t<=s&&e>-1&&((i=document.createRange()).setStart(this._e,e),i.setEnd(this._e,t)),i}_renderColHdrRow(e,t){let i=this._e.children[0];i||(i=wjcCore.createElement('<div class="wj-row" tabindex="-1" role="row"></div>',this._e)),wjcCore.setAttribute(i,"aria-selected",null);let s=0,l=this._g._getRowHeaderPath();l&&(s=this._renderRowHdrCell(i,-1,l.path));for(let l=0;l<this.columns.frozen&&l<this.columns.length;l++)s=this._renderColHdrCell(i,l,e,t,s);for(let l=e.leftCol;l<=e.rightCol&&l>-1;l++)s=this._renderColHdrCell(i,l,e,t,s);return this._removeExtraCells(i,s),1}_renderColHdrCell(e,t,i,s,l){let o=this.columns[t];if(o.renderSize<=0)return l;let n=e.children[l];n||(n=wjcCore.createElement('<div class="wj-cell" tabindex="-1" role="columnheader"></div>',e)),s||(n.textContent=this.columns[t].header,wjcCore.setCss(n,{position:"fixed",top:-32e3,height:.1,left:o.pos,width:o.renderWidth,overflow:"hidden",opacity:"0",pointerEvents:"none"}));let r=this.grid;if(r.allowSorting){let e="none";switch(r._getBindingColumn(this,0,o).currentSort){case"+":e="ascending";break;case"-":e="descending"}wjcCore.setAttribute(n,"aria-sort",e)}return r.isReadOnly||(wjcCore.setAttribute(n,"aria-readonly",o.isReadOnly),wjcCore.setAttribute(n,"aria-required",o.getIsRequired())),n[GridPanel._INDEX_KEY]={row:-1,col:t,panel:this},l+1}_renderRowHdrCell(e,t,i){let s=e.children[0];return s||(s=wjcCore.createElement('<div class="wj-cell" tabindex="-1"></div>',e)),s.setAttribute("role",t<0?"columnheader":"rowheader"),s.textContent=i?i.toString():"",wjcCore.setCss(s,{position:"fixed",left:-32e3,top:-32e3,width:.1,height:.1,overflow:"hidden",opacity:"0"}),s[GridPanel._INDEX_KEY]={row:t,col:-1,panel:this},1}_renderRow(e,t,i,s){let l=this._g,o=this.rows[e];if(o.renderSize<=0)return s;let n=this._e.children[s];if(n||(n=wjcCore.createElement('<div class="wj-row" tabindex="-1"></div>',this._e),this._ct==CellType.Cell&&n.setAttribute("role","row")),this._ct==CellType.Cell){let t=SelectionMode;switch(l.selectionMode){case t.Row:case t.RowRange:case t.ListBox:let i=o.isSelected||this._g._selHdl.selection.containsRow(e);wjcCore.setAttribute(n,"aria-selected",!!i)}wjcCore.setAttribute(n,"aria-level",o instanceof GroupRow?o.level+1:null),wjcCore.setAttribute(n,"aria-expanded",o instanceof GroupRow?!o.isCollapsed:null)}let r=0;if(this._ct==CellType.Cell){let t=this._g._getRowHeaderPath();t&&(r=this._renderRowHdrCell(n,e,t.getValue(o.dataItem)))}for(let s=0;s<this.columns.frozen&&s<this.columns.length;s++)r=this._renderCell(n,e,s,t,i,r);for(let s=t.leftCol;s<=t.rightCol&&s>-1;s++)r=this._renderCell(n,e,s,t,i,r);return this._removeExtraCells(n,r),s+1}_renderCell(e,t,i,s,l,o){let n=this._g,r=n.getMergedRange(this,t,i);if(r){for(let e=Math.max(s.row,r.row);e<t;e++)if(this.rows[e].isVisible)return o;for(let e=Math.max(s.col,r.col);e<i;e++)if(this.columns[e].isVisible)return o}let a=this.columns[i];if(a.renderSize<=0&&(!r||r.getRenderSize(this).width<=0))return o;let h=e.children[o],d=SelectedState,c=this.getSelectedState(t,i,r),g=c==d.Cursor||c==d.Active;return h&&l?(wjcCore.toggleClass(h,"wj-state-active",g),wjcCore.toggleClass(h,"wj-state-selected",c==d.Cursor),wjcCore.toggleClass(h,"wj-state-multi-selected",c==d.Selected),g&&(this._activeCell=h),o+1):(h||((h=document.createElement("div")).tabIndex=-1,e.appendChild(h)),g&&(this._activeCell=h),this._ct==CellType.Cell&&(wjcCore.setAttribute(h,"role","gridcell"),wjcCore.setAttribute(h,"aria-selected",c!=d.None),wjcCore.setAttribute(h,"aria-readonly",!n.canEditCell(t,i)||null),wjcCore.setAttribute(h,"aria-required",a.getIsRequired())),n.cellFactory.updateCell(this,t,i,h,r),h[GridPanel._INDEX_KEY]={row:t,col:i,rng:r,panel:this},o+1)}_removeExtraCells(e,t){for(;e.childElementCount>t;){let t=e.lastElementChild;e.removeChild(t),this._cf.disposeCell(t)}}_getViewRange(){let e=this._g,t=e._ptScrl,i=this._rows,s=this._cols,l=new CellRange(0,0,i.length-1,s.length-1);if(this._ct==CellType.Cell||this._ct==CellType.RowHeader){let s=-t.y+this._offsetY,o=e._szClient.height,n=Math.min(i.frozen,i.length-1);if(n>0){let e=i[n-1].pos;s+=e,o-=e}if(l.row=Math.min(i.length-1,Math.max(i.frozen,i.getItemAt(s+1))),l.row2=i.getItemAt(s+o),e._clipToScreen){let t=e.hostElement.getBoundingClientRect();t.top<0&&(l.row=Math.max(l.row,i.getItemAt(-t.top-e._ptScrl.y)-1)),t.bottom>innerHeight&&(l.row2=Math.min(l.row2,i.getItemAt(-t.top-e._ptScrl.y+innerHeight)+1))}}if(this._ct==CellType.Cell||this._ct==CellType.ColumnHeader){let i=-t.x,o=e._szClient.width,n=Math.min(s.frozen,s.length-1);if(n>0){let e=s[n-1].pos;i+=e,o-=e}l.col=Math.min(s.length-1,Math.max(s.frozen,s.getItemAt(i+1))),l.col2=s.getItemAt(i+o)}return i.length<=i.frozen&&(l.row=l.row2=-1),s.length<=s.frozen&&(l.col=l.col2=-1),l}_getFrozenPos(){let e=this._rows.frozen,t=this._cols.frozen,i=e>0?this._rows[e-1]:null,s=t>0?this._cols[t-1]:null,l=i?i.pos+i.renderSize:0,o=s?s.pos+s.renderSize:0;return new wjcCore.Point(o,l)}}GridPanel._INDEX_KEY="wj-cell-index",exports.GridPanel=GridPanel;class CellFactory{updateCell(e,t,i,s,l,o){let n=e.grid,r=n.rightToLeft,a=CellType,h=e.rows,d=e.columns,c=h[t],g=d[i],w=t,u=i,_=c instanceof GroupRow?c:null,C=c instanceof _NewRowTemplate?c:null,p=g.renderWidth,m=c.renderHeight,f=e.cellType,R="wj-cell",v={display:""};if(0!=o&&s.firstElementChild&&(1==s.childNodes.length&&"checkbox"==s.firstElementChild.type||(s.textContent="")),l&&!l.isSingleCell){t=l.row,i=l.col,w=l.row2,u=l.col2,c=h[t],g=d[i],_=c instanceof GroupRow?c:null;let s=l.getRenderSize(e);m=s.height,p=s.width}let y=n._getBindingColumn(e,t,g),S=y.dataType==wjcCore.DataType.Boolean&&!y.dataMap,j=g.pos,E=c.pos;if(n._useFrozenDiv()&&f==a.Cell&&!n.editRange?(t<h.frozen&&i>=d.frozen&&(j+=n._ptScrl.x),i<d.frozen&&t>=h.frozen&&(E+=n._ptScrl.y)):(t<h.frozen&&(E-=n._ptScrl.y),i<d.frozen&&(j-=n._ptScrl.x)),r?v.right=j+"px":v.left=j+"px",v.top=E-e._getOffsetY()+"px",v.width=p+"px",v.height=m+"px",v.zIndex="",(t<h.frozen||i<d.frozen)&&(v.zIndex=t<h.frozen&&i<d.frozen?2:1),f==a.Cell?(_&&(R+=" wj-group"),n.showAlternatingRows&&c.visibleIndex%2!=0&&(l&&l.row!=l.row2||(R+=" wj-alt")),(t<h.frozen||i<d.frozen)&&(R+=" wj-frozen"),C&&(R+=" wj-new"),c.cssClass&&(R+=" "+c.cssClass),y.cssClass&&(R+=" "+y.cssClass)):(R+=" wj-header",n.showAlternatingRows&&t%2!=0&&(R+=" wj-header-alt")),(f==a.Cell||f==a.RowHeader)&&n._getShowErrors()){let l=n._getError(e,t,i);wjcCore.setAttribute(s,"title",l),l&&(R+=" wj-state-invalid")}let b=SelectedState,x=e.getSelectedState(t,i,l);switch(x!=b.None&&f==a.Cell&&!S&&n.editRange&&n.editRange.contains(t,i)&&(x=b.None),x){case b.Active:R+=" wj-state-active";break;case b.Cursor:R+=" wj-state-selected wj-state-active";break;case b.Selected:R+=" wj-state-multi-selected"}if(w==h.frozen-1&&(R+=" wj-frozen-row"),u==d.frozen-1&&(R+=" wj-frozen-col"),(y.wordWrap||c.wordWrap)&&(R+=" wj-wrap"),(y.multiLine||c.multiLine)&&(R+=" wj-multiline"),v.textAlign=y.getAlignment(),v.textAlignLast=v.textJustify="","justify-all"==v.textAlign&&(v.textAlign=v.textAlignLast="justify",v.textJustify="distribute"),v.paddingLeft=v.paddingRight=v.paddingTop=v.paddingBottom="",f==a.Cell&&n.rows.maxGroupLevel>-1&&i==n.columns.firstVisibleIndex&&n.treeIndent){let e=_?Math.max(0,_.level):n.rows.maxGroupLevel+1,t=n.treeIndent*e+n._cellPadding;r?v.paddingRight=t+"px":v.paddingLeft=t+"px"}if(0!=o){let l=e.getCellData(t,i,!1),o=e.getCellData(t,i,!0);if(f==a.Cell&&i==n.columns.firstVisibleIndex&&_&&_.hasChildren&&!this._isEditingCell(n,t,i))o||(o=_.getGroupHeader()),s.innerHTML=this._getTreeIcon(_)+" "+o,v.textAlign="";else if(f==a.ColumnHeader&&y.currentSort&&n.showSort&&(w==n._getSortRowIndex()||y!=g))R+=" wj-sort-"+("+"==y.currentSort?"asc":"desc"),s.innerHTML=wjcCore.escapeHtml(o)+"&nbsp;"+this._getSortIcon(y);else if(f!=a.RowHeader||i!=n.rowHeaders.columns.length-1||o)if(f!=a.Cell||y.dataType!=wjcCore.DataType.Boolean||y.dataMap||_&&!wjcCore.isBoolean(l))if(f==a.Cell&&this._isEditingCell(n,t,i)){let l=y.inputType;if(y.inputType||(l=y.dataType!=wjcCore.DataType.Number||y.dataMap?"text":"tel"),!y.dataMap&&!y.mask){let s=e.getCellData(t,i,!1);if(wjcCore.isNumber(s)){let e=s.toString(),t=y.format;if(t&&s!=Math.round(s)){let i=e.match(/\.(\d+)/)[1].length;t=t.replace(/([a-z])(\d*)(.*)/gi,"$01"+i+"$3")}o=wjcCore.Globalize.formatNumber(s,t,!0)}}s.innerHTML=(y.multiLine||c.multiLine)&&"checkbox"!=l?"<textarea></textarea>":'<input type="'+l+'"/>';let r=s.children[0];wjcCore.addClass(r,"wj-grid-editor wj-form-control"),wjcCore.disableAutoComplete(r),r.value=o,r.required=y.getIsRequired(),y.maxLength&&(r.maxLength=y.maxLength),r.style.textAlign=y.getAlignment(),v.paddingTop=v.paddingBottom="0px",y.mask&&new wjcCore._MaskProvider(r,y.mask),n._edtHdl._edt=r}else f==a.Cell&&(c.isContentHtml||y.isContentHtml)?s.innerHTML=o:s.textContent=o||"";else{let e=s.firstChild;e instanceof HTMLInputElement&&"checkbox"==e.type||(s.innerHTML='<input type="checkbox" class="wj-cell-check" tabindex="-1"/>',e=s.firstChild),e.checked=1==l,e.indeterminate=null==l,e.disabled=!n.canEditCell(t,i),e.disabled&&(e.style.cursor="default"),n.editRange&&n.editRange.contains(t,i)&&(n._edtHdl._edt=e)}else{let e=n.editableCollectionView,t=e?e.currentEditItem:null;t&&c.dataItem==t?s.innerHTML='<span class="wj-glyph-pencil"></span>':c instanceof _NewRowTemplate&&(s.innerHTML='<span class="wj-glyph-asterisk"></span>')}if(f==a.Cell&&tryGetModuleWijmoInput()&&y.dataMap&&n.showDropDown&&0!=y.showDropDown&&n.canEditCell(t,i)){CellFactory._ddIcon||(CellFactory._ddIcon=wjcCore.createElement('<div role="button" class="'+CellFactory._WJC_DROPDOWN+'"><span class="wj-glyph-down"></span></div>'));let e=CellFactory._ddIcon.cloneNode(!0);s.appendChild(e)}}let z=!1;switch(f){case a.RowHeader:z=!_&&!C&&c.allowDragging&&0!=(n.allowDragging&AllowDragging.Rows),wjcCore.setAttribute(s,"draggable",z?"true":null);break;case a.ColumnHeader:z=g.allowDragging&&0!=(n.allowDragging&AllowDragging.Columns),wjcCore.setAttribute(s,"draggable",z?"true":null)}s.className!=R&&(s.className=R);let M=s.style;for(var T in v)M[T]=v[T];if(n._edtHdl._edt&&n._edtHdl._edt.parentElement==s){let e=n._root,t=e.getBoundingClientRect(),i=s.getBoundingClientRect(),l=t.top+e.clientHeight-i.top,o=t.left+e.clientWidth-i.left;i.height>l&&(s.style.height=l+"px"),i.width>o&&(s.style.width=o+"px")}if(n.itemFormatter&&n.itemFormatter(e,t,i,s),n.formatItem.hasHandlers){let l=CellFactory._fmtRng;l?l.setRange(t,i,w,u):l=CellFactory._fmtRng=new CellRange(t,i,w,u);let o=new FormatItemEventArgs(e,l,s);n.onFormatItem(o)}}disposeCell(e){}getEditorValue(e){let t=e._edtHdl._edt;if(t instanceof HTMLInputElement&&"checkbox"==t.type)return t.checked;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement){let e=t.maxLength;return wjcCore.isNumber(e)&&e>-1&&t.value.length>e?t.value.substr(0,e):t.value}return null}_isEditingCell(e,t,i){return e.editRange&&e.editRange.contains(t,i)}_getTreeIcon(e){let t="wj-glyph-"+(e.isCollapsed?"":"down-")+(e.grid.rightToLeft?"left":"right");return'<span class="'+CellFactory._WJC_COLLAPSE+" "+t+'"></span>'}_getSortIcon(e){return'<span class="wj-glyph-'+("+"==e.currentSort?"up":"down")+'"></span>'}}CellFactory._WJC_COLLAPSE="wj-elem-collapse",CellFactory._WJC_DROPDOWN="wj-elem-dropdown",exports.CellFactory=CellFactory;class CellRange{constructor(e=-1,t=-1,i=e,s=t){this.setRange(e,t,i,s)}setRange(e=-1,t=-1,i=e,s=t){this._row=wjcCore.asInt(e),this._col=wjcCore.asInt(t),this._row2=wjcCore.asInt(i),this._col2=wjcCore.asInt(s)}get row(){return this._row}set row(e){this._row=wjcCore.asInt(e)}get col(){return this._col}set col(e){this._col=wjcCore.asInt(e)}get row2(){return this._row2}set row2(e){this._row2=wjcCore.asInt(e)}get col2(){return this._col2}set col2(e){this._col2=wjcCore.asInt(e)}clone(){return new CellRange(this._row,this._col,this._row2,this._col2)}get rowSpan(){return Math.abs(this._row2-this._row)+1}get columnSpan(){return Math.abs(this._col2-this._col)+1}get topRow(){return Math.min(this._row,this._row2)}get bottomRow(){return Math.max(this._row,this._row2)}get leftCol(){return Math.min(this._col,this._col2)}get rightCol(){return Math.max(this._col,this._col2)}get isValid(){return this._row>-1&&this._col>-1&&this._row2>-1&&this._col2>-1}get isSingleCell(){return this._row==this._row2&&this._col==this._col2}contains(e,t){let i=wjcCore.tryCast(e,CellRange);if(i)return i.topRow>=this.topRow&&i.bottomRow<=this.bottomRow&&i.leftCol>=this.leftCol&&i.rightCol<=this.rightCol;if(wjcCore.isInt(e)&&wjcCore.isInt(t))return e>=this.topRow&&e<=this.bottomRow&&t>=this.leftCol&&t<=this.rightCol;throw"contains expects a CellRange or row/column indices."}containsRow(e){return wjcCore.asInt(e)>=this.topRow&&e<=this.bottomRow}containsColumn(e){return wjcCore.asInt(e)>=this.leftCol&&e<=this.rightCol}intersects(e){return this.intersectsRow(e)&&this.intersectsColumn(e)}intersectsRow(e){return e&&!(this.bottomRow<e.topRow||this.topRow>e.bottomRow)}intersectsColumn(e){return e&&!(this.rightCol<e.leftCol||this.leftCol>e.rightCol)}getRenderSize(e){let t=new wjcCore.Size(0,0);if(this.isValid){for(let i=this.topRow;i<=this.bottomRow;i++)t.height+=e.rows[i].renderSize;for(let i=this.leftCol;i<=this.rightCol;i++)t.width+=e.columns[i].renderSize}return t}equals(e){return e instanceof CellRange&&this._row==e._row&&this._col==e._col&&this._row2==e._row2&&this._col2==e._col2}}exports.CellRange=CellRange;var RowColFlags;!function(e){e[e.Visible=1]="Visible",e[e.AllowResizing=2]="AllowResizing",e[e.AllowDragging=4]="AllowDragging",e[e.AllowMerging=8]="AllowMerging",e[e.AllowSorting=16]="AllowSorting",e[e.AutoGenerated=32]="AutoGenerated",e[e.Collapsed=64]="Collapsed",e[e.ParentCollapsed=128]="ParentCollapsed",e[e.Selected=256]="Selected",e[e.ReadOnly=512]="ReadOnly",e[e.HtmlContent=1024]="HtmlContent",e[e.WordWrap=2048]="WordWrap",e[e.MultiLine=4096]="MultiLine",e[e.HasTemplate=8192]="HasTemplate",e[e.RowDefault=3]="RowDefault",e[e.ColumnDefault=23]="ColumnDefault"}(RowColFlags=exports.RowColFlags||(exports.RowColFlags={}));class RowCol{constructor(){this._list=null,this._pos=0,this._idx=-1,this._vidx=-1}get visible(){return this._getFlag(RowColFlags.Visible)}set visible(e){this._setFlag(RowColFlags.Visible,e)}get isVisible(){return!!this._getFlag(RowColFlags.Visible)&&(!this._getFlag(RowColFlags.ParentCollapsed)||this instanceof _NewRowTemplate)}get pos(){return this._list&&this._list._dirty&&this._list._update(),this._pos}get index(){return this._list&&this._list._dirty&&this._list._update(),this._idx}get visibleIndex(){return this._list&&this._list._dirty&&this._list._update(),this.isVisible?this._vidx:-1}get size(){return this._sz}set size(e){e!=this._sz&&(this._sz=wjcCore.asNumber(e,!0),this.onPropertyChanged())}get renderSize(){if(!this.isVisible)return 0;let e=this._sz,t=this._list;return t&&((null==e||e<0)&&(e=Math.round(t.defaultSize)),null!=t.minSize&&e<t.minSize&&(e=t.minSize),null!=t.maxSize&&e>t.maxSize&&(e=t.maxSize)),null!=this._szMin&&e<this._szMin&&(e=this._szMin),null!=this._szMax&&e>this._szMax&&(e=this._szMax),Math.round(e)}get allowResizing(){return this._getFlag(RowColFlags.AllowResizing)}set allowResizing(e){this._setFlag(RowColFlags.AllowResizing,e)}get allowDragging(){return this._getFlag(RowColFlags.AllowDragging)}set allowDragging(e){this._setFlag(RowColFlags.AllowDragging,e)}get allowMerging(){return this._getFlag(RowColFlags.AllowMerging)}set allowMerging(e){this._setFlag(RowColFlags.AllowMerging,e)}get isSelected(){return this._getFlag(RowColFlags.Selected)}set isSelected(e){if(this._setFlag(RowColFlags.Selected,e,!0)){let e=this.grid;e&&e.refreshCells(!1,!0,!0)}}get isReadOnly(){return this._getFlag(RowColFlags.ReadOnly)}set isReadOnly(e){this._setFlag(RowColFlags.ReadOnly,e)}get isContentHtml(){return this._getFlag(RowColFlags.HtmlContent)}set isContentHtml(e){this.isContentHtml!=e&&(this._setFlag(RowColFlags.HtmlContent,e),this.grid&&this.grid.invalidate())}get wordWrap(){return this._getFlag(RowColFlags.WordWrap)}set wordWrap(e){this._setFlag(RowColFlags.WordWrap,e)}get multiLine(){return this._getFlag(RowColFlags.MultiLine)}set multiLine(e){this._setFlag(RowColFlags.MultiLine,e)}get cssClass(){return this._cssClass}set cssClass(e){e!=this._cssClass&&(this._cssClass=wjcCore.asString(e),this.grid&&this.grid.invalidate())}get grid(){return this._list?this._list._g:null}get collectionView(){return this.grid?this.grid.collectionView:null}onPropertyChanged(){this._list&&(this._list._dirty=!0,this.grid.invalidate())}_getFlag(e){return 0!=(this._f&e)}_setFlag(e,t,i){return t!=this._getFlag(e)&&(this._f=t?this._f|e:this._f&~e,i||this.onPropertyChanged(),!0)}}exports.RowCol=RowCol;class Column extends RowCol{constructor(e){super(),this._f=RowColFlags.ColumnDefault,this._hash=Column._ctr.toString(36),Column._ctr++,e&&wjcCore.copy(this,e)}get name(){return this._name}set name(e){this._name=e}get dataType(){return this._type}set dataType(e){e=wjcCore.asEnum(e,wjcCore.DataType),this._type!=e&&(this._type=e,this.grid&&this.grid.invalidate())}get isRequired(){return this._required}set isRequired(e){this._required=wjcCore.asBoolean(e,!0)}get showDropDown(){return this._showDropDown}set showDropDown(e){e!=this._showDropDown&&(this._showDropDown=wjcCore.asBoolean(e,!0),this.grid&&this.grid.invalidate())}get dropDownCssClass(){return this._ddCssClass}set dropDownCssClass(e){this._ddCssClass=wjcCore.asString(e)}get inputType(){return this._inpType}set inputType(e){this._inpType=wjcCore.asString(e,!0)}get mask(){return this._mask}set mask(e){this._mask=wjcCore.asString(e,!0)}get maxLength(){return this._maxLen}set maxLength(e){this._maxLen=wjcCore.asNumber(e,!0,!0)}get binding(){return this._binding?this._binding.path:null}set binding(e){if(e!=this.binding){let t=wjcCore.asString(e);if(this._binding=t?new wjcCore.Binding(t):null,!this._type&&this.grid&&this._binding){let e=this.grid.collectionView;if(e&&e.sourceCollection&&e.sourceCollection.length){let t=e.sourceCollection[0];this._type=wjcCore.getType(this._binding.getValue(t))}}this.onPropertyChanged()}}get sortMemberPath(){return this._bindingSort?this._bindingSort.path:null}set sortMemberPath(e){if(e!=this.sortMemberPath){let t=wjcCore.asString(e);this._bindingSort=t?new wjcCore.Binding(t):null,this.onPropertyChanged()}}get width(){return null!=this._szStar?this._szStar:this.size}set width(e){null!=Column._parseStarSize(e)?(this._szStar=e,this.onPropertyChanged()):(this._szStar=null,this.size=wjcCore.asNumber(e,!0))}get minWidth(){return this._szMin}set minWidth(e){e!=this._szMin&&(this._szMin=wjcCore.asNumber(e,!0,!0),this.onPropertyChanged())}get maxWidth(){return this._szMax}set maxWidth(e){e!=this._szMax&&(this._szMax=wjcCore.asNumber(e,!0,!0),this.onPropertyChanged())}get quickAutoSize(){return this._quickSize}set quickAutoSize(e){this._quickSize=wjcCore.asBoolean(e,!0)}_getQuickAutoSize(){return!!this.grid._getQuickAutoSize()&&(wjcCore.isBoolean(this._quickSize)?this._quickSize:!(this.isContentHtml||this._getFlag(RowColFlags.HasTemplate)||this.wordWrap||this.multiLine))}get renderWidth(){return this.renderSize}get align(){return this._align}set align(e){this._align!=e&&(this._align=e,this.onPropertyChanged())}getAlignment(){let e=this._align;if(null==e&&(e="",!this._map))switch(this._type){case wjcCore.DataType.Boolean:e="center";break;case wjcCore.DataType.Number:e="right"}return e}getIsRequired(){return null!=this._required?this._required:this.dataType!=wjcCore.DataType.String||(null!=this.dataMap||null!=this._mask&&this._mask.length>0)}get header(){return this._hdr?this._hdr:this.binding}set header(e){this._hdr!=e&&(this._hdr=e,this.onPropertyChanged())}get dataMap(){return this._map}set dataMap(e){this._map!=e&&(this._map&&this._map.mapChanged.removeHandler(this.onPropertyChanged,this),wjcCore.isArray(e)&&(e=new DataMap(e,null,null)),this._map=wjcCore.asType(e,DataMap,!0),this._map&&this._map.mapChanged.addHandler(this.onPropertyChanged,this),this.onPropertyChanged())}get format(){return this._fmt}set format(e){this._fmt!=e&&(this._fmt=e,this.onPropertyChanged())}get allowSorting(){return this._getFlag(RowColFlags.AllowSorting)}set allowSorting(e){this._setFlag(RowColFlags.AllowSorting,e)}get currentSort(){let e=this.grid?this.grid.collectionView:null,t=e?e.sortDescriptions:null,i=t&&t.length?this._getBindingSort():null;if(i)for(let e=0;e<t.length;e++)if(t[e].property==i)return t[e].ascending?"+":"-";return null}get aggregate(){return null!=this._agg?this._agg:wjcCore.Aggregate.None}set aggregate(e){(e=wjcCore.asEnum(e,wjcCore.Aggregate))!=this._agg&&(this._agg=e,this.onPropertyChanged())}_getBindingSort(){return this.sortMemberPath?this.sortMemberPath:this.binding?this.binding:null}static _parseStarSize(e){if(wjcCore.isString(e)&&e.length>0&&"*"==e[e.length-1]){let t=1==e.length?1:1*e.substr(0,e.length-1);if(t>0&&!isNaN(t))return t}return null}}Column._ctr=0,exports.Column=Column;class Row extends RowCol{constructor(e){super(),this._f=RowColFlags.ColumnDefault,this._data=e}get dataItem(){return this._data}set dataItem(e){this._data=e}get height(){return this.size}set height(e){this.size=e}get renderHeight(){return this.renderSize}}exports.Row=Row;class GroupRow extends Row{constructor(){super(),this._level=-1,this.isReadOnly=!0}get level(){return this._level}set level(e){wjcCore.asInt(e),e!=this._level&&(this._level=e,this.onPropertyChanged())}get hasChildren(){if(null!=this.grid&&null!=this._list){this._list._update();let e=this.index<this._list.length-1?this._list[this.index+1]:null,t=wjcCore.tryCast(e,GroupRow),i=wjcCore.tryCast(e,_NewRowTemplate);return null!=e&&null==i&&(null==t||t.level>this.level)}return!0}get isCollapsed(){return this._getFlag(RowColFlags.Collapsed)}set isCollapsed(e){wjcCore.asBoolean(e),e!=this.isCollapsed&&null!=this._list&&this._setCollapsed(e)}getGroupHeader(){let e=this.grid,t=e.groupHeaderFormat||wjcCore.culture.FlexGrid.groupHeaderFormat,i=wjcCore.tryCast(this.dataItem,wjcCore.CollectionViewGroup);if(i&&t){let s=i.groupDescription.propertyName,l=i.name,o=e.getColumn(s),n=this.isContentHtml;o&&(n=n||o.isContentHtml,o.header&&(s=o.header),o.dataMap?l=o.dataMap.getDisplayValue(l):o.format&&(l=wjcCore.Globalize.format(l,o.format)));let r=i.getAggregate(wjcCore.Aggregate.CntAll,null,e.collectionView);return wjcCore.format(t,{name:wjcCore.escapeHtml(s),value:n?l:wjcCore.escapeHtml(l),level:i.level,count:r})}return""}_setCollapsed(e){let t=this.grid,i=t.rows,s=this.getCellRange(),l=new CellRangeEventArgs(t.cells,new CellRange(this.index,-1));t.onGroupCollapsedChanging(l)&&(t.deferUpdate(()=>{i.deferUpdate(()=>{this._setFlag(RowColFlags.Collapsed,e,!0);for(let t=s.topRow+1;t<=s.bottomRow&&t>-1&&t<i.length;t++){i[t]._setFlag(RowColFlags.ParentCollapsed,e,!0);let s=i[t];s instanceof GroupRow&&s.isCollapsed&&(t=s.getCellRange().bottomRow)}})}),t.onGroupCollapsedChanged(l))}getCellRange(){let e=this._list,t=this.index,i=e.length-1;for(let s=t+1;s<=i;s++){let t=wjcCore.tryCast(e[s],GroupRow);if(null!=t&&t.level<=this.level){i=s-1;break}}return new CellRange(t,0,i,this.grid.columns.length-1)}}exports.GroupRow=GroupRow;class RowColCollection extends wjcCore.ObservableArray{constructor(e,t){super(),this._frozen=0,this._vlen=0,this._szDef=28,this._szTot=0,this._dirty=!1,this._g=wjcCore.asType(e,FlexGrid),this._szDef=wjcCore.asNumber(t,!1,!0)}get defaultSize(){return this._szDef}set defaultSize(e){this._szDef!=e&&(this._szDef=wjcCore.asNumber(e,!1,!0),this._dirty=!0,this._g.invalidate())}get frozen(){return this._frozen}set frozen(e){e!=this._frozen&&(this._frozen=wjcCore.asNumber(e,!1,!0),this._dirty=!0,this._g.invalidate())}isFrozen(e){return e<this.frozen}get minSize(){return this._szMin}set minSize(e){e!=this._szMin&&(this._szMin=wjcCore.asNumber(e,!0,!0),this._dirty=!0,this._g.invalidate())}get maxSize(){return this._szMax}set maxSize(e){e!=this._szMax&&(this._szMax=wjcCore.asNumber(e,!0,!0),this._dirty=!0,this._g.invalidate())}getTotalSize(){return this._dirty&&this._update(),this._szTot}get visibleLength(){return this._dirty&&this._update(),this._vlen}getItemAt(e){if(this._dirty&&this._update(),e<=0&&this.length>0&&this[0].renderSize)return 0;e=Math.round(e);let t,i,s=this.length,l=0,o=s-1;for(;l<=o;)if(t=l+o>>>1,(i=this[t])._pos>e&&t>0)o=t-1;else{if(!(i._pos+i.renderSize<=e&&t<s-1)){for(;t>0&&!this[t].renderSize;)t--;for(;t<s-1&&!this[t].renderSize;)t++;return t}l=t+1}return o}getNextCell(e,t,i){let s,l=SelMove;switch(t){case l.Next:for(s=e+1;s<this.length;s++)if(this[s].renderSize>0)return s;break;case l.Prev:for(s=e-1;s>=0;s--)if(this[s].renderSize>0)return s;break;case l.End:for(s=this.length-1;s>=0;s--)if(this[s].renderSize>0)return s;break;case l.Home:for(s=0;s<this.length;s++)if(this[s].renderSize>0)return s;break;case l.NextPage:return(s=this.getItemAt(this[e].pos+i))<0?this.getNextCell(e,SelMove.End,i):s==e&&s<this.length-1&&this[s+1].renderSize?s+1:s;case l.PrevPage:return(s=this.getItemAt(this[e].pos-i))<0?this.getNextCell(e,SelMove.Home,i):s==e&&s>0&&this[s-1].renderSize?s-1:s}return e}canMoveElement(e,t){if(t==e)return!1;if(e<0||e>=this.length||t>=this.length)return!1;t<0&&(t=this.length-1);let i=Math.min(e,t),s=Math.max(e,t);for(let e=i;e<=s;e++)if(!this[e].allowDragging)return!1;return!(this[t]instanceof _NewRowTemplate)}moveElement(e,t){if(this.canMoveElement(e,t)){let i=this[e];this.removeAt(e),t<0&&(t=this.length),this.insert(t,i)}}onCollectionChanged(e=wjcCore.NotifyCollectionChangedEventArgs.reset){this._dirty=!0,this._g.invalidate(),super.onCollectionChanged(e)}push(e){return e._list=this,super.push(e)}splice(e,t,i){return i&&(i._list=this),super.splice(e,t,i)}beginUpdate(){this._update(),super.beginUpdate()}_update(){if(this._dirty&&!this.isUpdating){this._dirty=!1;let e,t,i=0,s=0;for(let l=0;l<this.length;l++)(t=this[l])._idx=l,t._vidx=i,t._list=this,t._pos=s,(e=t.renderSize)>0&&(s+=e,i++);return this._vlen=i,this._szTot=s,!0}return!1}}exports.RowColCollection=RowColCollection;class ColumnCollection extends RowColCollection{constructor(){super(...arguments),this._firstVisible=-1}getColumn(e){let t=wjcCore.isNumber(e)?e:this.indexOf(e);return t>-1?this[t]:null}indexOf(e){if(e instanceof Column)return super.indexOf(e);for(let t=0;t<this.length;t++)if(this[t].name==e)return t;for(let t=0;t<this.length;t++)if(this[t].binding==e)return t;return-1}get firstVisibleIndex(){return this._dirty&&this._update(),this._firstVisible}_update(){if(super._update()){this._firstVisible=-1;for(let e=0;e<this.length;e++)if(this[e].visible){this._firstVisible=e;break}return!0}return!1}_updateStarSizes(e){let t,i=0;for(let s=0;s<this.length;s++){let l=this[s];l.isVisible&&(l._szStar?(i+=Column._parseStarSize(l._szStar),t=l):e-=l.renderWidth)}if(t){let s=e;for(let l=0;l<this.length;l++){let o=this[l];o.isVisible&&o._szStar&&(o==t&&s>0?o._sz=s:(o._sz=Math.max(0,Math.round(Column._parseStarSize(o._szStar)/i*e)),s-=o.renderWidth))}return this._dirty=!0,this._update(),!0}return!1}}exports.ColumnCollection=ColumnCollection;class RowCollection extends RowColCollection{constructor(){super(...arguments),this._maxLevel=-1}get maxGroupLevel(){return this._dirty&&this._update(),this._maxLevel}_update(){if(super._update()){this._maxLevel=-1;for(let e=0;e<this.length;e++){let t=wjcCore.tryCast(this[e],GroupRow);t&&t.level>this._maxLevel&&(this._maxLevel=t.level)}return!0}return!1}}exports.RowCollection=RowCollection;class HitTestInfo{constructor(e,t){this._row=-1,this._col=-1,this._edge=0;let i;if(t instanceof Element&&wjcCore.closest(t,".wj-flexgrid")==e.hostElement&&(e=t),e instanceof Element&&!(e instanceof FlexGrid)){let t=wjcCore.closest(e,".wj-cell"),i=t?t[GridPanel._INDEX_KEY]:null;return void(i&&(this._row=i.row,this._col=i.col,this._rng=i.rng,this._p=i.panel,this._g=i.panel.grid))}if(e instanceof FlexGrid)i=this._g=e;else{if(!(e instanceof GridPanel))throw"First parameter should be a FlexGrid or GridPanel.";this._p=e,i=this._g=this._p.grid}let s;t instanceof MouseEvent&&(s=t,"mousedown"==t.type&&(i._rcBounds=null)),t=wjcCore.mouseToPage(t),this._pt=t.clone();let l=i.controlRect,o=i._szClient,n=i.topLeftCells,r=i._eTL,a=i.headersVisibility,h=HeadersVisibility,d=a&h.Row?n.columns.getTotalSize():0,c=a&h.Column?n.rows.getTotalSize():0,g=a&h.Column?c+r.offsetTop:0,w=i._eBL,u=w.offsetHeight;if(t.x-=l.left,t.y-=l.top,this._g.rightToLeft&&(t.x=l.width-t.x),!this._p&&t.x>=0&&t.y>=r.offsetTop&&o&&t.x<=o.width+d&&t.y<=o.height+g&&(t.y<g?this._p=t.x<d?i.topLeftCells:i.columnHeaders:t.y<w.offsetTop?this._p=t.x<d?i.rowHeaders:i.cells:this._p=t.x<d?i.bottomLeftCells:i.columnFooters),null!=this._p){let e=this._p.rows,s=this._p.columns,l=this._p.cellType,o=CellType,n=this._p._getFrozenPos(),r=l==o.TopLeft||l==o.ColumnHeader?c:l==o.BottomLeft||l==o.ColumnFooter?u:e.getTotalSize(),a=l==o.TopLeft||l==o.BottomLeft||l==o.RowHeader?d:s.getTotalSize();l==o.RowHeader||l==o.Cell?(t.y-=c,(t.y>n.y||n.y<=0)&&(t.y-=i._ptScrl.y,t.y+=this._p._getOffsetY())):l!=o.BottomLeft&&l!=o.ColumnFooter||(t.y-=w.offsetTop),l!=o.ColumnHeader&&l!=o.Cell&&l!=o.ColumnFooter||(t.x-=d,(t.x>n.x||n.x<=0)&&(t.x-=i._ptScrl.x)),l!=o.ColumnHeader&&l!=o.TopLeft||(t.y-=g-c),this._edge=0;let h=HitTestInfo._SZEDGE[this._g.isTouching?1:0];if(this._g.isTouching&&(h=HitTestInfo._SZEDGE[1],t.x-=h/2),this._row=t.y>r?-1:e.getItemAt(t.y),this._col=t.x>a?-1:s.getItemAt(t.x),this._row<0||this._col<0)return void(this._p=null);if(this._col>-1){let e=s[this._col];t.x-e.pos<=h&&(this._edge|=1),e.pos+e.renderSize-t.x<=h&&(this._edge|=4)}if(this._row>-1){let i=e[this._row];t.y-i.pos<=h&&(this._edge|=2),i.pos+i.renderSize-t.y<=h&&(this._edge|=8)}}if(!(8&this._edge)&&s instanceof MouseEvent){let e=wjcCore.closest(s.target,".wj-cell"),t=e?e[GridPanel._INDEX_KEY]:null;t&&!t.rng&&t.panel==this._p&&this._row!=t.row&&(this._row=t.row)}}get point(){return this._pt}get cellType(){return this._p?this._p.cellType:CellType.None}get panel(){return this._p}get grid(){return this._p?this._p.grid:null}get row(){return this._row}get col(){return this._col}get range(){return this._rng||(this._rng=new CellRange(this._row,this._col)),this._rng}get edgeLeft(){return 0!=(1&this._edge)}get edgeTop(){return 0!=(2&this._edge)}get edgeRight(){return 0!=(4&this._edge)}get edgeBottom(){return 0!=(8&this._edge)}}HitTestInfo._SZEDGE=[5,30],exports.HitTestInfo=HitTestInfo;var AllowMerging;!function(e){e[e.None=0]="None",e[e.Cells=1]="Cells",e[e.ColumnHeaders=2]="ColumnHeaders",e[e.RowHeaders=4]="RowHeaders",e[e.AllHeaders=6]="AllHeaders",e[e.All=7]="All"}(AllowMerging=exports.AllowMerging||(exports.AllowMerging={}));class MergeManager{constructor(e){this._g=e}getMergedRange(e,t,i,s=!0){let l,o,n=e.cellType,r=e.columns,a=e.rows,h=a[t],d=r[i];if(h instanceof _NewRowTemplate)return null;if(h instanceof GroupRow&&h.dataItem instanceof wjcCore.CollectionViewGroup){if(l=new CellRange(t,i),d.aggregate==wjcCore.Aggregate.None){for(;l.col>0&&r[l.col-1].aggregate==wjcCore.Aggregate.None&&l.col!=r.frozen;)l.col--;for(;l.col2<r.length-1&&r[l.col2+1].aggregate==wjcCore.Aggregate.None&&l.col2+1!=r.frozen;)l.col2++}for(;l.col<i&&!r[l.col].visible;)l.col++;return l.isSingleCell?null:l}let c=!1;switch(this._g.allowMerging){case AllowMerging.None:c=!0;break;case AllowMerging.Cells:c=n!=CellType.Cell;break;case AllowMerging.ColumnHeaders:c=n!=CellType.ColumnHeader&&n!=CellType.TopLeft;break;case AllowMerging.RowHeaders:c=n!=CellType.RowHeader&&n!=CellType.TopLeft;break;case AllowMerging.AllHeaders:c=n==CellType.Cell}if(c)return null;if(r[i].allowMerging){l=new CellRange(t,i);let r=0,h=a.length-1;t>=a.frozen?!s||n!=CellType.Cell&&n!=CellType.RowHeader||(r=(o=e._getViewRange()).topRow,h=o.bottomRow):h=a.frozen-1;for(let s=t-1;s>=r&&this._mergeCell(e,s,i,t,i);s--)l.row=s;for(let s=t+1;s<=h&&this._mergeCell(e,t,i,s,i);s++)l.row2=s;for(;l.row<t&&!a[l.row].visible;)l.row++;if(!l.isSingleCell)return l}if(a[t].allowMerging){l=new CellRange(t,i);let a=0,h=r.length-1;i>=r.frozen?!s||n!=CellType.Cell&&n!=CellType.ColumnHeader||(a=(o=e._getViewRange()).leftCol,h=o.rightCol):h=r.frozen-1;for(let s=i-1;s>=a&&this._mergeCell(e,t,s,t,i);s--)l.col=s;for(let s=i+1;s<=h&&this._mergeCell(e,t,i,t,s);s++)l.col2=s;for(;l.col<i&&!r[l.col].visible;)l.col++;if(!l.isSingleCell)return l}return null}_mergeCell(e,t,i,s,l){let o=e.rows[t],n=e.rows[s];if(o instanceof GroupRow||o instanceof _NewRowTemplate||n instanceof GroupRow||n instanceof _NewRowTemplate)return!1;if(t!=s&&e.rows.isFrozen(t)!=e.rows.isFrozen(s))return!1;if(i!=l&&e.columns.isFrozen(i)!=e.columns.isFrozen(l))return!1;if(t!=s){if(i>0&&(o.allowMerging&&this._mergeCell(e,t,i-1,t,i)||n.allowMerging&&this._mergeCell(e,s,i-1,s,i)))return!1;if(l<e.columns.length-1&&(o.allowMerging&&this._mergeCell(e,t,l,t,l+1)||n.allowMerging&&this._mergeCell(e,s,l,s,l+1)))return!1}return e.getCellData(t,i,!0)==e.getCellData(s,l,!0)}}exports.MergeManager=MergeManager;class DataMap{constructor(e,t,i){if(this.mapChanged=new wjcCore.Event,wjcCore.isArray(e)&&!t&&!i){let s=[];for(let t=0;t<e.length;t++)s.push({value:e[t]});e=s,t=i="value"}this._cv=wjcCore.asCollectionView(e),this._keyPath=wjcCore.asString(t,!1),this._displayPath=wjcCore.asString(i,!1),this._cv.collectionChanged.addHandler(this.onMapChanged,this)}get sortByDisplayValues(){return 1!=this._sortByKey}set sortByDisplayValues(e){this._sortByKey=!wjcCore.asBoolean(e)}get collectionView(){return this._cv}get selectedValuePath(){return this._keyPath}get displayMemberPath(){return this._displayPath}getKeyValue(e){let t=this._displayPath,i=this._indexOf(e,t,!0);return i<0&&(i=this._indexOf(e,t,!1)),i>-1?this._cv.sourceCollection[i][this._keyPath]:null}getDisplayValue(e){if(!this._hash){this._hash={};let e=this._cv.sourceCollection;if(e&&this._keyPath&&this._displayPath)for(let t=e.length-1;t>=0;t--){let i=e[t],s=i[this._keyPath],l=i[this._displayPath];this._hash[s]=l}}let t=this._hash[e];return null!=t?t:e}getDisplayValues(e){let t=[];if(this._cv&&this._displayPath){let e=this._cv.items;for(let i=0;i<e.length;i++)t.push(e[i][this._displayPath])}return t}getKeyValues(){let e=[];if(this._cv&&this._keyPath){let t=this._cv.items;for(let i=0;i<t.length;i++)e.push(t[i][this._keyPath])}return e}get isEditable(){return this._editable}set isEditable(e){this._editable=wjcCore.asBoolean(e)}onMapChanged(e){this._hash=null,this.mapChanged.raise(this,e)}_indexOf(e,t,i){let s=-1,l=-1;if(this._cv&&t){let o=null!=e?e.toString():"",n=i?o:o.toLowerCase(),r=this._cv.sourceCollection;for(let a=0;a<r.length;a++){let h=r[a],d=h[t];if(d==e?s=a:i||d.length!=n.length||d.toLowerCase()!=n?null!=d&&d.toString()==o&&(s=a):s=a,s==a){if(!this._cv.filter||this._cv.filter(h))return s;l<0&&(l=s)}}}return l}}exports.DataMap=DataMap;var SelectionMode;!function(e){e[e.None=0]="None",e[e.Cell=1]="Cell",e[e.CellRange=2]="CellRange",e[e.Row=3]="Row",e[e.RowRange=4]="RowRange",e[e.ListBox=5]="ListBox"}(SelectionMode=exports.SelectionMode||(exports.SelectionMode={}));var SelectedState;!function(e){e[e.None=0]="None",e[e.Selected=1]="Selected",e[e.Cursor=2]="Cursor",e[e.Active=3]="Active"}(SelectedState=exports.SelectedState||(exports.SelectedState={}));var SelMove;!function(e){e[e.None=0]="None",e[e.Next=1]="Next",e[e.Prev=2]="Prev",e[e.NextPage=3]="NextPage",e[e.PrevPage=4]="PrevPage",e[e.Home=5]="Home",e[e.End=6]="End",e[e.NextCell=7]="NextCell",e[e.PrevCell=8]="PrevCell"}(SelMove=exports.SelMove||(exports.SelMove={}));class _SelectionHandler{constructor(e){this._sel=new CellRange(0,0),this._mode=SelectionMode.CellRange,this._g=e}get selectionMode(){return this._mode}set selectionMode(e){if(e!=this._mode){let t=SelectionMode;if(e==t.ListBox||this._mode==t.ListBox){let t=this._g.rows;for(let i=0;i<t.length;i++){let s=t[i],l=e==SelectionMode.ListBox&&this._sel.containsRow(i);s._setFlag(RowColFlags.Selected,l,!0)}}switch(e){case t.None:this._sel.setRange(-1,-1);break;case t.Cell:this._sel.row2=this._sel.row,this._sel.col2=this._sel.col;break;case t.Row:this._sel.row2=this._sel.row}this._mode=e,this._g.invalidate()}}get selection(){return this._sel}set selection(e){this.select(e)}select(e,t=!0){wjcCore.isNumber(e)&&wjcCore.isNumber(t)&&(e=new CellRange(e,t),t=!0),e=wjcCore.asType(e,CellRange);let i=this._g,s=this._sel,l=e,o=!1,n=SelectionMode;switch(i.selectionMode){case n.Cell:e.row2=e.row,e.col2=e.col;break;case n.Row:e.row2=e.row;break;case n.ListBox:o=!0}let r=l.equals(s);if(o&&l.row>-1&&!i.rows[l.row].isSelected&&(r=!1),r)return void(t&&i.scrollIntoView(l.row,l.col));let a=new CellRangeEventArgs(i.cells,l);if(i.onSelectionChanging(a)){if(o&&(l.row!=s.row||l.rowSpan>1||s.rowSpan>1)){for(let e=0;e<i.rows.length;e++)i.rows[e]._setFlag(RowColFlags.Selected,l.containsRow(e),!0);i.refreshCells(!1,!0,!0)}if(l.row=Math.min(l.row,i.rows.length-1),l.row2=Math.min(l.row2,i.rows.length-1),this._sel=l,i.refreshCells(!1,!0,!0),t&&i.scrollIntoView(l.row,l.col),i.collectionView){let e=i._getCvIndex(l.row);i.collectionView.moveCurrentToPosition(e)}i.onSelectionChanged(a)}}moveSelection(e,t,i){let s,l,o=this._g,n=o.rows,r=o.columns,a=this._getReferenceCell(e,t,i),h=Math.max(0,o._szClient.height-o.columnHeaders.height);if(t==SelMove.NextCell)l=r.getNextCell(a.col,SelMove.Next,h),s=a.row,l==a.col&&(s=n.getNextCell(s,SelMove.Next,h))>a.row&&(l=r.getNextCell(0,SelMove.Next,h),l=r.getNextCell(l,SelMove.Prev,h)),o.select(s,l);else if(t==SelMove.PrevCell)l=r.getNextCell(a.col,SelMove.Prev,h),s=a.row,l==a.col&&(s=n.getNextCell(s,SelMove.Prev,h))<a.row&&(l=r.getNextCell(r.length-1,SelMove.Prev,h),l=r.getNextCell(l,SelMove.Next,h)),o.select(s,l);else if(s=n.getNextCell(a.row,e,h),l=r.getNextCell(a.col,t,h),i){let e=o._selHdl._sel;o.select(new CellRange(s,l,e.row2,e.col2))}else o.select(s,l)}_getReferenceCell(e,t,i){let s=this._g,l=s._selHdl._sel,o=s.getMergedRange(s.cells,l.row,l.col);if(!o||o.isSingleCell)return l;switch(o=o.clone(),e){case SelMove.Next:case SelMove.NextCell:o.row=o.bottomRow;break;case SelMove.None:o.row=l.row}switch(t){case SelMove.Next:case SelMove.NextCell:o.col=o.rightCol;break;case SelMove.None:o.col=l.col}return o}_adjustSelection(e){switch(this._mode){case SelectionMode.Cell:return new CellRange(e.row,e.col,e.row,e.col);case SelectionMode.Row:return new CellRange(e.row,0,e.row,this._g.columns.length-1);case SelectionMode.RowRange:case SelectionMode.ListBox:return new CellRange(e.row,0,e.row2,this._g.columns.length-1)}return e}}exports._SelectionHandler=_SelectionHandler;var KeyAction;!function(e){e[e.None=0]="None",e[e.MoveDown=1]="MoveDown",e[e.MoveAcross=2]="MoveAcross",e[e.Cycle=3]="Cycle",e[e.CycleOut=4]="CycleOut"}(KeyAction=exports.KeyAction||(exports.KeyAction={}));class _KeyboardHandler{constructor(e){this._kaTab=KeyAction.None,this._kaEnter=KeyAction.MoveDown,this._g=e;let t=e.hostElement;e.addEventListener(t,"keypress",this._keypress.bind(this)),e.addEventListener(t,"keydown",this._keydown.bind(this))}_keydown(e){let t=this._g,i=t.selection,s=e.ctrlKey||e.metaKey,l=e.shiftKey,o=(e.target,!0);if(this._altDown=!1,t._wantsInput(e.target))return;let n=e.defaultPrevented&&!(e.target instanceof HTMLInputElement);if(!t.isRangeValid(i)||n)return;if(t.activeEditor&&t._edtHdl._keydown(e))return;let r=wjcCore.tryCast(t.rows[i.row],GroupRow),a=t.editableCollectionView,h=e.keyCode;if(t.autoClipboard){if(s&&(67==h||45==h)){let s=new CellRangeEventArgs(t.cells,i);if(t.onCopying(s)){let e=t.getClipString()+"\r\n";wjcCore.Clipboard.copy(e),t.onCopied(s)}return void e.stopPropagation()}if(s&&86==h||l&&45==h)return t.isReadOnly||wjcCore.Clipboard.paste(e=>{t.setClipString(e)}),void e.stopPropagation()}if(t.rightToLeft)switch(h){case wjcCore.Key.Left:h=wjcCore.Key.Right;break;case wjcCore.Key.Right:h=wjcCore.Key.Left}let d=SelMove,c=SelectionMode;switch(h){case wjcCore.Key.Space:if(l&&i.isValid)switch(t.selectionMode){case c.CellRange:case c.Row:case c.RowRange:case c.ListBox:t.select(new CellRange(i.row,0,i.row,t.columns.length-1))}else if(s&&i.isValid)switch(t.selectionMode){case c.CellRange:t.select(new CellRange(0,i.col,t.rows.length-1,i.col))}else(o=this._startEditing(!0,e))&&setTimeout(()=>{let e=t.activeEditor;e&&(e.disabled||e.readOnly?t.finishEditing():"checkbox"==e.type?(e.checked=!e.checked,t.finishEditing()):wjcCore.setSelectionRange(e,e.value.length))});break;case 65:if(s)switch(t.selectionMode){case c.CellRange:case c.Row:case c.RowRange:case c.ListBox:t.select(new CellRange(0,0,t.rows.length-1,t.columns.length-1))}else o=!1;break;case wjcCore.Key.Left:s||e.altKey?o=!1:i.isValid&&0==i.col&&null!=r&&!r.isCollapsed&&r.hasChildren?r.isCollapsed=!0:this._moveSel(d.None,s?d.Home:d.Prev,l);break;case wjcCore.Key.Right:s||e.altKey?o=!1:i.isValid&&0==i.col&&null!=r&&r.isCollapsed?r.isCollapsed=!1:this._moveSel(d.None,s?d.End:d.Next,l);break;case wjcCore.Key.Up:s?o=!1:(this._altDown=e.altKey,e.altKey?o=t._edtHdl._toggleListBox(e):this._moveSel(d.Prev,d.None,l));break;case wjcCore.Key.Down:s?o=!1:(this._altDown=e.altKey,e.altKey?o=t._edtHdl._toggleListBox(e):this._moveSel(d.Next,d.None,l));break;case wjcCore.Key.PageUp:if(this._altDown=e.altKey,this._moveSel(e.altKey?d.Home:d.PrevPage,d.None,l),t.rows.frozen&&t.selection.row<t.rows.frozen){let e=t.scrollPosition;e.y&&(t.scrollPosition=new wjcCore.Point(e.x,0))}break;case wjcCore.Key.PageDown:this._altDown=e.altKey,this._moveSel(e.altKey?d.End:d.NextPage,d.None,l);break;case wjcCore.Key.Home:this._moveSel(s?d.Home:d.None,d.Home,l);break;case wjcCore.Key.End:this._moveSel(s?d.End:d.None,d.End,l);break;case wjcCore.Key.Tab:o=this._performKeyAction(t.keyActionTab,l);break;case wjcCore.Key.Enter:o=this._performKeyAction(t.keyActionEnter,l),!l&&a&&null!=a.currentEditItem&&t._edtHdl._commitRowEdits();break;case wjcCore.Key.Escape:if(o=!1,a&&(a.currentAddItem||a.currentEditItem)){let e=new CellRangeEventArgs(t.cells,t.selection);e.cancel=!0,t.onRowEditEnding(e),a.currentAddItem&&a.cancelNew(),a.currentEditItem&&a.cancelEdit(),t.onRowEditEnded(e),o=!0}t._mouseHdl.resetMouseState();break;case wjcCore.Key.Delete:case wjcCore.Key.Back:o=this._deleteSel(e);break;case wjcCore.Key.F2:o=this._startEditing(!0,e);break;case wjcCore.Key.F4:o=t._edtHdl._toggleListBox(e);break;default:o=!1}o&&(t.containsFocus()||t.focus(),e.preventDefault(),e.stopPropagation())}_performKeyAction(e,t){let i=KeyAction,s=SelMove;switch(e){case i.MoveDown:return this._moveSel(t?s.Prev:s.Next,s.None,!1),!0;case i.MoveAcross:return this._moveSel(s.None,t?s.Prev:s.Next,!1),!0;case i.Cycle:return this._moveSel(s.None,t?s.PrevCell:s.NextCell,!1),!0;case i.CycleOut:let l=this._g.selection;return this._moveSel(s.None,t?s.PrevCell:s.NextCell,!1),!l.equals(this._g.selection)}return!1}_keypress(e){let t=this._g;if(!t._wantsInput(e.target)&&!e.defaultPrevented)if(this._altDown)e.preventDefault();else if(t.activeEditor)t._edtHdl._keypress(e);else if(e.charCode>wjcCore.Key.Space&&this._startEditing(!1,e)&&t.activeEditor){let i=wjcCore.getActiveElement();if(i instanceof HTMLInputElement&&"checkbox"!=i.type){let s=t._selHdl.selection,l=t.getCellData(s.row,s.col,!0),o=t.getCellData(s.row,s.col,!1);i.value=String.fromCharCode(e.charCode),wjcCore.isNumber(o)&&l.indexOf("%")>-1&&(i.value+="%"),wjcCore.setSelectionRange(i,1),i.dispatchEvent(t._edtHdl._evtInput),t._edtHdl._keypress(e),e.preventDefault()}}}_moveSel(e,t,i){this._g.selectionMode!=SelectionMode.None&&this._g._selHdl.moveSelection(e,t,i)}_deleteSel(e){let t=this._g,i=t.editableCollectionView,s=t.selection,l=t.rows,o=[],n=new CellRange,r=new CellEditEndingEventArgs(t.cells,n,e),a=SelectionMode;if(t.allowDelete&&!t.isReadOnly&&(null==i||i.canRemove&&!i.isAddingNew&&!i.isEditingItem))switch(t.selectionMode){case a.CellRange:if(0==s.leftCol&&s.rightCol==t.columns.length-1)for(let e=s.topRow;e>-1&&e<=s.bottomRow;e++)o.push(l[e]);break;case a.ListBox:for(let e=0;e<l.length;e++)l[e].isSelected&&o.push(l[e]);break;case a.Row:s.topRow>-1&&o.push(l[s.topRow]);break;case a.RowRange:for(let e=s.topRow;e>-1&&e<=s.bottomRow;e++)o.push(l[e])}if(o.length>0){if(t.deferUpdate(()=>{i&&i.beginUpdate();for(let e=o.length-1;e>=0;e--){let s=o[e];n.setRange(s.index,-1),t.onDeletingRow(r)&&(i&&s.dataItem?i.remove(s.dataItem):t.rows.removeAt(s.index),t.onDeletedRow(r))}i&&i.endUpdate()}),t.selectionMode==a.ListBox){let e=t.selection.row;e>-1&&e<t.rows.length&&(t.rows[e].isSelected=!0)}return t.childItemsPath&&t.collectionView&&t.collectionView.refresh(),!0}if(!t.isReadOnly&&0==o.length){let e=!1,l=t.scrollPosition;return t.deferUpdate(()=>{for(let l=s.topRow;l<=s.bottomRow;l++){let o=t.rows[l];if(!o.isReadOnly)for(let a=s.leftCol;a<=s.rightCol;a++){let s=t._getBindingColumn(t.cells,l,t.columns[a]);if(!s.getIsRequired()&&!s.isReadOnly&&t.getCellData(l,a,!0)&&(n.setRange(l,a),r.cancel=!1,t.onBeginningEdit(r))){if(i){let s=i.currentEditItem;!e&&s&&s!=o.dataItem&&(e=!0,i.beginUpdate()),s=o.dataItem,i.editItem(s),t._edtHdl._edItem=s}t.setCellData(l,a,"",!0,!1),t.onCellEditEnding(r),t.onCellEditEnded(r)}}}t.selection=s,t.scrollPosition=l,e&&i.endUpdate()}),!0}return!1}_startEditing(e,t,i,s){return this._g._edtHdl.startEditing(e,i,s,!0,t)}}exports._KeyboardHandler=_KeyboardHandler;const _AR_ALLCELLS=4,_WJC_DRAGSRC="wj-state-dragsrc";var AllowResizing;!function(e){e[e.None=0]="None",e[e.Columns=1]="Columns",e[e.Rows=2]="Rows",e[e.Both=3]="Both",e[e.ColumnsAllCells=4|e.Columns]="ColumnsAllCells",e[e.RowsAllCells=4|e.Rows]="RowsAllCells",e[e.BothAllCells=4|e.Both]="BothAllCells"}(AllowResizing=exports.AllowResizing||(exports.AllowResizing={}));var AutoSizeMode;!function(e){e[e.None=0]="None",e[e.Headers=1]="Headers",e[e.Cells=2]="Cells",e[e.Both=3]="Both"}(AutoSizeMode=exports.AutoSizeMode||(exports.AutoSizeMode={}));var AllowDragging;!function(e){e[e.None=0]="None",e[e.Columns=1]="Columns",e[e.Rows=2]="Rows",e[e.Both=3]="Both"}(AllowDragging=exports.AllowDragging||(exports.AllowDragging={}));class _MouseHandler{constructor(e){this._tsLast=0;let t=e.hostElement;this._g=e,this._dvMarker=wjcCore.createElement('<div class="wj-marker">&nbsp;</div>'),e.addEventListener(t,"mousedown",t=>{if(e._rcBounds=null,!t.defaultPrevented&&0==t.button){let l=t.target;if(!e.containsFocus()){let t=l instanceof HTMLElement&&l.tabIndex>-1?l:e._eFocus;e._setFocusNoScroll(t)}if(setTimeout(()=>{t.defaultPrevented||e.focus()}),wjcCore.closest(t.target,".wj-flexgrid")!=e.hostElement||!e.activeEditor&&e._isInputElement(l)){let i=e.hitTest(t);switch(i.cellType){case CellType.Cell:e.select(i.range);break;case CellType.ColumnHeader:case CellType.ColumnFooter:e.scrollIntoView(-1,i.col);break;case CellType.RowHeader:e.scrollIntoView(i.row,-1)}return}let o=document;e.removeEventListener(o,"mousemove"),e.removeEventListener(o,"mouseup"),e.addEventListener(o,"mousemove",i),e.addEventListener(o,"mouseup",s),this._isDown=!0,this._mousedown(t)}});let i=e=>{this._mousemove(e)},s=t=>{this._isDown=!1,e.removeEventListener(document,"mousemove"),e.removeEventListener(document,"mouseup"),this._mouseup(t)};e.addEventListener(t,"mouseup",e=>{this._tsLast=Date.now()}),e.addEventListener(t,"mouseenter",t=>{e._rcBounds=null}),e.addEventListener(t,"mousemove",this._hover.bind(this)),e.addEventListener(t,"dblclick",this._dblclick.bind(this)),e.addEventListener(t,"click",this._click.bind(this)),e.addEventListener(t,"selectstart",t=>{e._isInputElement(t.target)||t.preventDefault()}),e.addEventListener(t,"wheel",t=>{let i=e.cells.hostElement.parentElement,s=t.deltaY;if(s&&!t.ctrlKey&&!t.metaKey&&i.scrollHeight>i.offsetHeight&&wjcCore.closest(t.target,".wj-flexgrid")==e.hostElement){switch(t.deltaMode){case 1:i.scrollTop+=e.rows.defaultSize*(s<0?-1:1);break;case 2:i.scrollTop+=i.clientHeight*(s<0?-1:1);break;case 0:default:wjcCore.isSafari()&&(s=wjcCore.clamp(s,-150,150)),i.scrollTop+=s}t.preventDefault(),t.stopImmediatePropagation()}}),e.addEventListener(t,"dragstart",this._dragstart.bind(this)),e.addEventListener(t,"dragover",this._dragover.bind(this)),e.addEventListener(t,"dragleave",this._dragover.bind(this)),e.addEventListener(t,"drop",this._drop.bind(this)),e.addEventListener(t,"dragend",this._dragend.bind(this)),this._enableTouchResizing()}resetMouseState(){this._dragSource&&wjcCore.removeClass(this._dragSource,_WJC_DRAGSRC),this._showDragMarker(null);let e=this._g.hostElement;e&&(e.style.cursor="");let t=this._g;t.removeEventListener(document,"mousemove"),t.removeEventListener(document,"mouseup"),this._tsLast=Date.now(),this._eMouse=null,this._isDown=null,this._htDown=null,this._lbSelRows=null,this._szRowCol=null,this._szArgs=null,this._dragSource=null}_enableTouchResizing(){let e=this._g,t=e.hostElement,i="ontouchstart"in window?["touchstart","touchmove","touchend"]:"onpointerdown"in window?["pointerdown","pointermove","pointerup"]:null;i&&(e.addEventListener(t,i[0],i=>{if((null==i.pointerType||"touch"==i.pointerType)&&!wjcCore.closest(i.target,".wj-elem-filter")){var s=wjcCore.closest(i.target,".wj-cell");s instanceof HTMLElement&&(e._rcBounds=null,this._htDown=null,this._hover(i),this._szRowCol&&(s.removeAttribute("draggable"),t.style.touchAction="none",this._mousedown(i),i.preventDefault()))}}),e.addEventListener(t,i[1],e=>{null!=e.pointerType&&"touch"!=e.pointerType||this._szRowCol&&(this._mousemove(e),e.preventDefault())}),e.addEventListener(t,i[2],e=>{if(wjcCore.Control._touching=!1,(null==e.pointerType||"touch"==e.pointerType)&&this._szRowCol){if(this._szArgs)this._finishResizing(this._eMouse);else{let t=wjcCore.closest(e.target,".wj-cell");t instanceof HTMLElement&&t.click()}this.resetMouseState(),t.style.touchAction=""}}))}_mousedown(e){let t=this._g,i=t.hitTest(e),s=i.cellType,l=e.ctrlKey||e.metaKey,o=e.target;if(this._selDown=t.selection,i.panel==t.cells){if(wjcCore.closestClass(o,CellFactory._WJC_DROPDOWN))return t._edtHdl._toggleListBox(e,i.range),void e.preventDefault();if(t.editRange&&t.editRange.contains(i.range))return}let n=wjcCore.getActiveElement();if(o!=n||!t._isInputElement(o)){if(s==CellType.None)return t.finishEditing(),void(o!=t._root&&o!=t._fCt&&t._edtHdl._commitRowEdits());if(this._htDown=i,this._eMouse=e,null!=this._szRowCol)return n!=t._eFocus&&(t._eFocus.tabIndex=0,t._eFocus.focus()),void this._handleResizing(e);switch(s){case CellType.Cell:l&&t.selectionMode==SelectionMode.ListBox&&this._startListBoxSelection(i.row),this._mouseSelect(e,e.shiftKey);break;case CellType.RowHeader:0==(this._g.allowDragging&AllowDragging.Rows)&&(l&&t.selectionMode==SelectionMode.ListBox&&this._startListBoxSelection(i.row),this._mouseSelect(e,e.shiftKey),e.preventDefault(),t.focus())}if(s==CellType.Cell&&t.rows.maxGroupLevel>-1&&wjcCore.closestClass(o,CellFactory._WJC_COLLAPSE)){let e=wjcCore.tryCast(t.rows[i.row],GroupRow);if(e)return l?t.collapseGroupsToLevel(e.isCollapsed?e.level+1:e.level):e.isCollapsed=!e.isCollapsed,void this.resetMouseState()}}}_mousemove(e){if(null!=this._htDown){if(0==e.buttons&&this._eMouse&&e.timeStamp-this._eMouse.timeStamp>600)return void this.resetMouseState();if(this._eMouse=e,this._szRowCol)this._handleResizing(e);else switch(this._htDown.cellType){case CellType.Cell:this._mouseSelect(e,!0);break;case CellType.RowHeader:0==(this._g.allowDragging&AllowDragging.Rows)&&this._mouseSelect(e,!0)}}}_mouseup(e){if(this._g.isTouching&&(this._dragSource||e.target instanceof HTMLHtmlElement))return;let t=this._g,i=t.hitTest(e),s=this._htDown,l=SelectionMode;if(s&&!e.defaultPrevented)if(this._szArgs)this._finishResizing(e);else if(s.panel!=t.topLeftCells||this._szArgs)s.panel!=t.columnHeaders||e.dataTransfer?s.panel==t.cells&&(e.ctrlKey||e.metaKey||e.shiftKey||i.panel==s.panel&&i.range.equals(s.range)&&t.selection.equals(this._selDown)&&t._edtHdl.startEditing(!0,i.row,i.col,!0,e)):i.panel==s.panel&&i.col==s.col&&!i.edgeRight&&i.col>-1&&this._clickSort(e,i);else if(i.panel==s.panel&&i.row==s.row&&i.col==s.col&&t.rows.length&&t.columns.length)switch(t.selectionMode){case l.CellRange:case l.RowRange:case l.ListBox:t.select(new CellRange(0,0,t.rows.length-1,t.columns.length-1))}this.resetMouseState()}_click(e){Date.now()-this._tsLast>50&&!e.pointerType&&this._handleClick(e)}_handleClick(e){let t=this._g,i=e.target,s=new HitTestInfo(i,null),l=s.panel;if(!e.defaultPrevented&&s.grid==t&&!t._isInputElement(i))if(l==t.topLeftCells)t.select(new CellRange(0,0,t.rows.length-1,t.columns.length-1));else if(l==t.columnHeaders)this._clickSort(e,s);else if(l==t.rowHeaders)t.select(new CellRange(s.row,0,s.row,t.columns.length-1));else if(l==t.cells)if(s.row<0)this._clickSort(e,s);else if(wjcCore.closestClass(i,CellFactory._WJC_COLLAPSE)){let i=t.rows[s.row];i instanceof GroupRow&&(e.ctrlKey?t.collapseGroupsToLevel(i.isCollapsed?i.level+1:i.level):i.isCollapsed=!i.isCollapsed)}else wjcCore.closestClass(i,CellFactory._WJC_DROPDOWN)?t._edtHdl._toggleListBox(e,s.range):t.select(s.range)}_clickSort(e,t){let i=this._g,s=i.collectionView,l=e.ctrlKey||e.metaKey;if(!s||!s.canSort||!i.allowSorting)return;t.range.bottomRow;let o=t.panel.columns[t.col],n=i._getBindingColumn(t.panel,t.row,o),r=n?n._getBindingSort():null;if(!n.allowSorting||!r)return;let a=t.grid.collectionView.sortDescriptions,h=null;for(let e=0;e<a.length;e++)if(a[e].property==r){h=!a[e].ascending;break}if(null==h){if(l)return;h=!0}let d=new CellRangeEventArgs(t.panel,t.range);i.onSortingColumn(d)&&(i._edtHdl._commitRowEdits(),l?a.clear():a.splice(0,a.length,new wjcCore.SortDescription(r,h)),i.onSortedColumn(d))}_dblclick(e){let t,i=this._g,s=i.hitTest(e),l=s.cellType,o=i.selection,n=s.range;if(!e.defaultPrevented)if(s.edgeRight&&i.allowResizing&AllowResizing.Columns){if(l==CellType.ColumnHeader||l==CellType.Cell&&4&i.allowResizing){e.preventDefault(),e.ctrlKey&&o.containsColumn(s.col)&&(n=o);for(let e=n.leftCol;e<=n.rightCol;e++)i.columns[e].allowResizing&&(t=new CellRangeEventArgs(i.cells,new CellRange(-1,e)),i.onAutoSizingColumn(t)&&i.onResizingColumn(t)&&(i.autoSizeColumn(e),i.onResizedColumn(t),i.onAutoSizedColumn(t)))}else l==CellType.TopLeft&&s.panel.columns[s.col].allowResizing&&(e.preventDefault(),t=new CellRangeEventArgs(s.panel,new CellRange(-1,s.col)),i.onAutoSizingColumn(t)&&i.onResizingColumn(t)&&(i.autoSizeColumn(s.col,!0),i.onAutoSizedColumn(t),i.onResizedColumn(t)));this.resetMouseState()}else if(s.edgeBottom&&i.allowResizing&AllowResizing.Rows){if(l==CellType.RowHeader||l==CellType.Cell&&4&i.allowResizing){e.ctrlKey&&o.containsRow(s.row)&&(n=o);for(let e=n.topRow;e<=n.bottomRow;e++)i.rows[e].allowResizing&&(t=new CellRangeEventArgs(i.cells,new CellRange(e,-1)),i.onAutoSizingRow(t)&&i.onResizingRow(t)&&(i.autoSizeRow(e),i.onResizedRow(t),i.onAutoSizedRow(t)))}else l==CellType.TopLeft&&s.panel.rows[s.row].allowResizing&&(t=new CellRangeEventArgs(s.panel,new CellRange(s.row,-1)),i.onAutoSizingRow(t)&&i.onResizingRow(t)&&(i.autoSizeRow(s.row,!0),i.onResizedRow(t),i.onAutoSizedRow(t)));this.resetMouseState()}else;}_hover(e){if(null==this._htDown){let t=this._g,i=t.hitTest(e),s=(i.panel,i.cellType),l="";return this._szRowCol=null,(s==CellType.ColumnHeader||s==CellType.TopLeft||s==CellType.Cell&&4&t.allowResizing)&&i.edgeRight&&0!=(t.allowResizing&AllowResizing.Columns)&&(this._szRowCol=this._getResizeCol(i)),(s==CellType.RowHeader||s==CellType.TopLeft||s==CellType.Cell&&4&t.allowResizing)&&i.edgeBottom&&0!=(t.allowResizing&AllowResizing.Rows)&&(this._szRowCol=this._getResizeRow(i)),this._szRowCol instanceof Column?l="col-resize":this._szRowCol instanceof Row&&(l="row-resize"),this._szStart=this._szRowCol?this._szRowCol.renderSize:0,t.hostElement.style.cursor=l,i}return null}_getResizeCol(e){let t=e.panel.columns,i=t[e.col];for(let s=e.col+1;s<t.length;s++){let e=t[s];if(e.visible){e.size<1&&(i=e);break}}if(e.col==t.length-1&&(e.cellType==CellType.TopLeft||e.cellType==CellType.RowHeader)){t=this._g.columns;for(let e=0;e<t.length;e++){let s=t[e];if(s.visible){s.size<1&&(i=s);break}}}return i.allowResizing?i:null}_getResizeRow(e){let t=e.panel.rows,i=t[e.row];for(let s=e.row+1;s<t.length;s++){let e=t[s];if(e.visible){e.size<1&&(i=e);break}}if(e.row==t.length-1&&(e.cellType==CellType.TopLeft||e.cellType==CellType.ColumnHeader)){t=this._g.rows;for(let e=0;e<t.length;e++){let s=t[e];if(s.visible){s.size<1&&(i=s);break}}}return i.allowResizing?i:null}_mouseSelect(e,t){let i=this._g;if(this._htDown&&this._htDown.panel&&i.selectionMode!=SelectionMode.None){let s=new HitTestInfo(this._htDown.panel,e);this._handleSelection(s,t),!wjcCore.isIE9()&&e.button>=0&&e.target!=i._root&&(s=new HitTestInfo(i,e)).cellType!=CellType.Cell&&s.cellType!=CellType.RowHeader&&setTimeout(()=>{this._mouseSelect(this._eMouse,t)},100)}}_handleResizing(e){if(e.preventDefault(),this._szRowCol instanceof Column){let t=this._g,i=wjcCore.mouseToPage(e).x,s=Math.round(Math.max(_MouseHandler._SZ_MIN,this._szStart+(i-this._htDown.point.x)*(t.rightToLeft?-1:1)));if(this._szRowCol.renderSize!=s){if(null==this._szArgs){let e=t.rowHeaders.columns.indexOf(this._szRowCol)>-1?t.rowHeaders:t.cells;this._szArgs=new CellRangeEventArgs(e,new CellRange(-1,this._szRowCol.index))}this._szArgs.cancel=!1,t.onResizingColumn(this._szArgs)&&(t.deferResizing?this._showResizeMarker(s):this._szRowCol.width=s)}}if(this._szRowCol instanceof Row){let t=this._g,i=wjcCore.mouseToPage(e).y,s=Math.round(Math.max(_MouseHandler._SZ_MIN,this._szStart+(i-this._htDown.point.y)));if(this._szRowCol.renderSize!=s){if(null==this._szArgs){let e=t.columnHeaders.rows.indexOf(this._szRowCol)>-1?t.columnHeaders:t.cells;this._szArgs=new CellRangeEventArgs(e,new CellRange(this._szRowCol.index,-1))}this._szArgs.cancel=!1,t.onResizingRow(this._szArgs)&&(t.deferResizing?this._showResizeMarker(s):this._szRowCol.height=s)}}}_dragstart(e){let t=this._g,i=this._htDown,s=AllowDragging;if(i){if(this._dragSource=null,!this._szRowCol){let l=new CellRangeEventArgs(i.panel,i.range);if(i.cellType==CellType.ColumnHeader&&t.allowDragging&s.Columns&&i.col>-1&&t.columns[i.col].allowDragging)t.onDraggingColumn(l)?this._dragSource=e.target:e.preventDefault();else if(i.cellType==CellType.RowHeader&&t.allowDragging&s.Rows&&i.row>-1&&t.rows[i.row].allowDragging){let s=t.rows[i.row];s instanceof GroupRow||s instanceof _NewRowTemplate||(t.onDraggingRow(l)?this._dragSource=e.target:e.preventDefault())}else i.cellType==CellType.TopLeft&&t.allowDragging&s.Columns&&i.col>-1&&t.topLeftCells.columns[i.col].allowDragging&&(t.onDraggingColumn(l)?this._dragSource=e.target:e.preventDefault())}this._dragSource&&e.dataTransfer&&!e.defaultPrevented&&(wjcCore._startDrag(e.dataTransfer,"move"),e.stopPropagation(),wjcCore.addClass(this._dragSource,_WJC_DRAGSRC),t.beginUpdate(),this._updating=!0)}}_dragend(e){this._updating&&(this._g.endUpdate(),this._updating=!1),this.resetMouseState()}_dragover(e){let t=this._g,i=t.hitTest(e),s=!1,l=CellType,o=new CellRangeEventArgs(i.panel,i.range,this._htDown);if(this._htDown&&i.cellType==this._htDown.cellType&&(i.cellType==l.ColumnHeader?(o.cancel=!t.columns.canMoveElement(this._htDown.col,i.col),s=t.onDraggingColumnOver(o)):i.cellType==l.RowHeader?(o.cancel=!t.rows.canMoveElement(this._htDown.row,i.row),s=t.onDraggingRowOver(o)):i.cellType==l.TopLeft&&(o.cancel=!t.topLeftCells.columns.canMoveElement(this._htDown.col,i.col),s=t.onDraggingColumnOver(o))),s?(e.dataTransfer.dropEffect="move",this._showDragMarker(i),e.preventDefault(),e.stopPropagation()):this._showDragMarker(null),this._htDown&&t.autoScroll){let i=t._rcBounds,s=t.scrollPosition,l=wjcCore.Control._DRAG_SCROLL_EDGE,o=wjcCore.Control._DRAG_SCROLL_STEP;this._htDown.panel==t.columnHeaders?(e.pageX-i.left<l&&(s.x+=o),i.right-e.pageX<l&&(s.x-=o)):this._htDown.panel==t.rowHeaders&&(e.pageY-i.top<l&&(s.y+=o),i.bottom-e.pageY<l&&(s.y-=o)),s.equals(t._ptScrl)||(t.scrollPosition=s)}}_drop(e){let t=this._g,i=t.hitTest(e),s=CellType;if(this._htDown&&i.cellType==this._htDown.cellType){let e=t.selection,l=new CellRangeEventArgs(i.panel,i.range,this._htDown);i.cellType==s.ColumnHeader?(t.columns.moveElement(this._htDown.col,i.col),t.select(e.row,i.col),t.onDraggedColumn(l)):i.cellType==s.RowHeader?(t.rows.moveElement(this._htDown.row,i.row),t.select(i.row,e.col),t.onDraggedRow(l)):i.cellType==s.TopLeft&&(t.topLeftCells.columns.moveElement(this._htDown.col,i.col),t.onDraggedColumn(l))}this.resetMouseState()}_showResizeMarker(e){let t=this._g,i=this._dvMarker,s=t.cells.hostElement;i.parentElement!=s&&s.appendChild(i);let l,o=this._szArgs.panel.cellType,n=CellType;this._szRowCol instanceof Column?(l={left:this._szRowCol.pos+e-1,top:-1e3,right:"",bottom:0,width:3,height:""},t.rightToLeft&&(l.left=s.clientWidth-l.left-l.width),o!=n.TopLeft&&o!=n.RowHeader||(l.left-=t.topLeftCells.hostElement.offsetWidth)):(l={left:-1e3,top:this._szRowCol.pos+e-1,right:0,bottom:"",width:"",height:3},o!=n.TopLeft&&o!=n.ColumnHeader||(l.top-=t.topLeftCells.hostElement.offsetHeight)),wjcCore.setCss(i,l)}_showDragMarker(e){let t=this._g,i=this._dvMarker;if(!e||!e.panel)return wjcCore.removeChild(i),void(this._rngTarget=null);if(e.range.equals(this._rngTarget))return;this._rngTarget=e.range;let s=e.panel.hostElement;i.parentElement!=s&&s.appendChild(i);let l=CellType,o={left:0,top:0,width:6,height:6,right:"",bottom:""};switch(e.cellType){case l.TopLeft:case l.ColumnHeader:o.height=e.panel.height;let s=e.panel.columns[e.col];o.left=s.pos-o.width/2,e.col>this._htDown.col&&(o.left+=s.renderWidth),t.rightToLeft&&(o.left=i.parentElement.clientWidth-o.left-o.width);break;case l.RowHeader:o.width=e.panel.width;let n=e.panel.rows[e.row];o.top=n.pos-o.height/2,e.row>this._htDown.row&&(o.top+=n.renderHeight)}wjcCore.setCss(i,o)}_finishResizing(e){let t=this._g,i=t.selection,s=this._szArgs,l=this._eMouse&&this._eMouse.ctrlKey,o=CellType;if(s&&!s.cancel){if(s.col>-1){let n=s.col,r=wjcCore.mouseToPage(e).x,a=Math.round(Math.max(_MouseHandler._SZ_MIN,this._szStart+(r-this._htDown.point.x)*(this._g.rightToLeft?-1:1)));if(s.panel.columns[n].width=Math.round(a),t.onResizedColumn(s),l&&this._htDown.cellType==o.ColumnHeader&&i.containsColumn(n))for(let e=i.leftCol;e<=i.rightCol;e++)t.columns[e].allowResizing&&e!=n&&(s=new CellRangeEventArgs(t.cells,new CellRange(-1,e)),t.onResizingColumn(s)&&(t.columns[e].size=t.columns[n].size,t.onResizedColumn(s)))}if(s.row>-1){let n=s.row,r=wjcCore.mouseToPage(e).y,a=Math.round(Math.max(_MouseHandler._SZ_MIN,this._szStart+(r-this._htDown.point.y)));if(s.panel.rows[n].height=Math.round(a),t.onResizedRow(s),l&&this._htDown.cellType==o.RowHeader&&i.containsRow(n))for(let e=i.topRow;e<=i.bottomRow;e++)t.rows[e].allowResizing&&e!=n&&(s=new CellRangeEventArgs(t.cells,new CellRange(e,-1)),t.onResizingRow(s)&&(t.rows[e].size=t.rows[n].size,t.onResizedRow(s)))}}}_startListBoxSelection(e){let t=this._g.rows;this._lbSelState=!t[e].isSelected,this._lbSelRows={};for(let e=0;e<t.length;e++)t[e].isSelected&&(this._lbSelRows[e]=!0)}_handleSelection(e,t){let i=this._g,s=i.rows,l=i._selHdl.selection,o=new CellRange(e.row,e.col);if(e.row>-1&&e.col>-1)if(null!=this._lbSelRows){let t=!1;o=new CellRange(e.row,e.col,this._htDown.row,this._htDown.col);for(let e=0;e<s.length;e++){let n=o.containsRow(e)?this._lbSelState:null!=this._lbSelRows[e];if(n!=s[e].isSelected){let o=new CellRangeEventArgs(i.cells,new CellRange(e,l.col,e,l.col2));i.onSelectionChanging(o)&&(s[e]._setFlag(RowColFlags.Selected,n,!0),t=!0,i.onSelectionChanged(o))}}t&&i.refreshCells(!1,!0,!0),i.scrollIntoView(e.row,e.col)}else e.cellType==CellType.RowHeader&&(o.col=0,o.col2=i.columns.length-1),t&&(o.row2=l.row2,o.col2=l.col2),i.select(o)}}_MouseHandler._SZ_MIN=0,exports._MouseHandler=_MouseHandler;const _WJC_CHECKBOX="wj-cell-check";class _EditHandler{constructor(e){this._fullEdit=!1,this._list=null,this._g=e,this._evtInput=document.createEvent("HTMLEvents"),this._evtInput.initEvent("input",!0,!1),e.selectionChanging.addHandler((t,i)=>{if(this.finishEditing()){let t=e._selHdl.selection.row;if(t!=i.row){let s=e.rows.length;(t>-1&&t<s?e.rows[t].dataItem:null)!=(i.row>-1&&i.row<s?e.rows[i.row].dataItem:null)&&this._commitRowEdits()}}else i.cancel=!0}),e.lostFocus.addHandler(()=>{if(!e.containsFocus()){let e=wjcCore.getActiveElement();e&&"fixed"==getComputedStyle(e).position||this._commitRowEdits()}}),e.addEventListener(e.hostElement,"mousedown",t=>{if(t.defaultPrevented||0!=t.button)return;if(e._mouseHdl._szRowCol)return;e.selection;let i=e.hitTest(t);if(i.cellType!=CellType.Cell&&i.cellType!=CellType.None)this.finishEditing();else if(i.cellType!=CellType.None){let e=wjcCore.tryCast(t.target,HTMLInputElement);this._isNativeCheckbox(e)&&(e!=this.activeEditor&&(t.preventDefault(),this.startEditing(!1,i.row,i.col,!0,t)&&(e=this.activeEditor)),!e||"checkbox"!=e.type||e.disabled||e.readOnly||(e.checked=!e.checked,e.focus(),this.finishEditing()))}},!0),e.addEventListener(e.hostElement,"click",e=>{this._isNativeCheckbox(e.target)&&e.preventDefault()})}startEditing(e=!0,t,i,s,l){let o=this._g;if(t=wjcCore.asNumber(t,!0,!0),i=wjcCore.asNumber(i,!0,!0),null==t&&(t=o.selection.row),null==i&&(i=o.selection.col),null==s&&(s=!0),!this._allowEditing(t,i))return!1;let n=o.getMergedRange(o.cells,t,i,!1);n||(n=new CellRange(t,i));let r=o.rows[t].dataItem;if(o.select(n,!0),!o.rows[t]||r!=o.rows[t].dataItem)return!1;if(n.equals(this._rng))return!0;if(this.activeEditor&&!this.finishEditing())return!1;let a=new CellRangeEventArgs(o.cells,n,l);if(!o.onBeginningEdit(a))return!1;let h=o.editableCollectionView,d=!1;h&&((d=(r=o.rows[t].dataItem)!=h.currentEditItem)&&o.onRowEditStarting(a),h.editItem(r),d&&(o.onRowEditStarted(a),this._edItem=r)),this._fullEdit=wjcCore.asBoolean(e),this._rng=n,this._list=null;let c=o.columns[i].dataMap;c&&(this._list=c.getDisplayValues(r)),n.isSingleCell?this._updateEditorCell(t,i,d):o.refresh(!1);let g=this._edt;if(g){if("checkbox"==g.type)this._fullEdit=!1;else if(s){let e=wjcCore.culture.Globalize.numberFormat["%"]||"%";if(wjcCore.isNumber(o.getCellData(t,i,!1))&&g.value.indexOf(e)>-1){let t=g.value,i=0,s=t.length;for(;s>0&&t[s-1]==e;)s--;for(;i<s&&t[i]==e;)i++;wjcCore.setSelectionRange(g,i,s)}else wjcCore.setSelectionRange(g,0,g.value.length);o._setFocusNoScroll(g)}if(o.onPrepareCellForEdit(a),g.disabled||g.readOnly)return!1}return null!=g&&!g.disabled&&!g.readOnly}finishEditing(e){let t=this._edt;if(!t)return this._removeListBox(),!0;let i=this._g,s=this._rng,l=new CellEditEndingEventArgs(i.cells,s),o=i.containsFocus(),n=i.hostElement.querySelector(".wj-control.wj-state-focused");if(n){let e=wjcCore.Control.getControl(n);e&&e.onLostFocus(l)}if(l.cancel=e,!e&&i.validateEdits){let e=this._getValidationError();if(e){l.cancel=!0;let i=t.parentElement;i&&(wjcCore.toggleClass(i,"wj-state-invalid",!0),i.title=e,l.stayInEditMode=!0)}}if(!i.onCellEditEnding(l)&&l.stayInEditMode)return o?setTimeout(()=>{t.select()}):t.select(),!1;if(!l.cancel){l.data=i.cells.getCellData(s.topRow,s.leftCol,!1);let e=i.cellFactory.getEditorValue(i);for(let t=s.topRow;t<=s.bottomRow&&t<i.rows.length;t++)for(let l=s.leftCol;l<=s.rightCol&&l<i.columns.length;l++)i.cells.setCellData(t,l,e,!0,!1)}this._edt=null,this._rng=null,this._list=null,this._removeListBox();let r=wjcCore.closest(t,".wj-cell");return wjcCore.contains(r,wjcCore.getActiveElement())&&r.focus(),l.cancel||!l.refresh?this._updateEditorCell(s.row,s.col,!1):i.refresh(!1),o&&i.focus(),i.onCellEditEnded(l),!0}get activeEditor(){return this._edt}get editRange(){return this._rng}getClipString(e){let t=this._g,i="",s=!0,l=SelectionMode;if(!e)switch(e=t.selection,t.selectionMode){case l.Row:case l.RowRange:e.col=0,e.col2=t.columns.length-1;break;case l.ListBox:e.col=0,e.col2=t.columns.length-1;for(let s=0;s<t.rows.length;s++)t.rows[s].isSelected&&t.rows[s].isVisible&&(e.row=e.row2=s,i&&(i+="\n"),i+=this.getClipString(e));return i}for(let l=(e=wjcCore.asType(e,CellRange)).topRow;l<=e.bottomRow;l++)if(t.rows[l].isVisible){s||(i+="\n"),s=!1;for(let s=e.leftCol,o=!0;s<=e.rightCol;s++){if(!t.columns[s].isVisible)continue;o||(i+="\t"),o=!1;let e=t.cells.getCellData(l,s,!0).toString();(e=e.replace(/\t/g," ")).indexOf("\n")>-1&&(e='"'+e.replace(/"/g,'""')+'"'),i+=e}}return i}setClipString(e,t){let i=this._g,s=null==t,l=SelectionMode;if(!t)switch(t=i.selection,i.selectionMode){case l.Row:case l.RowRange:case l.ListBox:t.col=0,t.col2=i.columns.length-1}t=wjcCore.asType(t,CellRange);let o=this._parseClipString(wjcCore.asString(e));s&&!t.isSingleCell&&o.length&&this._expandClipRows(o,t);let n=new CellRange(t.topRow,t.leftCol,t.topRow+o.length-1,t.leftCol+o[0].length-1),r=new CellRangeEventArgs(i.cells,n);if(!i.onPasting(r))return!1;n=new CellRange(t.topRow,t.leftCol);let a=i.editableCollectionView,h=t.topRow,d=!1;i.deferUpdate(()=>{a&&a.beginUpdate();for(let e=0;e<o.length&&h<i.rows.length;e++,h++){if(!i.rows[h].isVisible){e--;continue}let s=o[e],l=t.leftCol;for(let e=0;e<s.length&&l<i.columns.length;e++,l++){let t=i.columns[l];if(t.isVisible){if(this._allowEditing(h,l)){let o=s[e];t.maxLength&&(o=o.substr(0,t.maxLength));let r=new CellRangeEventArgs(i.cells,new CellRange(h,l),o);i.onPastingCell(r)&&(a&&(a.editItem(i.rows[h].dataItem),this._edItem=a.currentEditItem),i.cells.setCellData(h,l,r.data)&&(i.onPastedCell(r),d=!0)),n.row2=Math.max(n.row2,h),n.col2=Math.max(n.col2,l)}}else e--}}a&&a.endUpdate(),i.select(n),i.onPasted(r)})}_isNativeCheckbox(e){return e instanceof HTMLInputElement&&"checkbox"==e.type&&!e.disabled&&!e.readOnly&&wjcCore.hasClass(e,_WJC_CHECKBOX)&&wjcCore.closest(e,".wj-flexgrid")==this._g.hostElement}_parseClipString(e){let t=[];e=(e=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n")).replace(/\n+$/g,"");let i=0,s=0;for(i=0;i<e.length;i++){let o='"'==e[i]&&e[i+1]>=" ",n=!1,r=!1;for(s=i;s<e.length&&!r;s++){var l=e[s];switch(l){case'"':o&&(n=!n);break;case"\t":case"\n":n||(this._parseClipCell(t,e,i,s,"\n"==l),i=s,r=!0)}}if(s==e.length){this._parseClipCell(t,e,i,e.length,!1);break}}return 0==t.length&&t.push([""]),t}_parseClipCell(e,t,i,s,l){e.length||e.push([]);let o=t.substr(i,s-i),n=o.length;n>1&&'"'==o[0]&&'"'==o[n-1]&&(o=(o=o.substr(1,n-2)).replace(/""/g,'"')),e[e.length-1].push(o),l&&e.push([])}_expandClipRows(e,t){let i=e.length,s=0;for(let t=0;t<i;t++)s=Math.max(s,e[t].length);let l=this._g,o=0,n=0;for(let e=t.topRow;e<=t.bottomRow;e++)l.rows[e].isVisible&&o++;for(let e=t.leftCol;e<=t.rightCol;e++)l.columns[e].isVisible&&n++;if((o>1||n>1)&&(1==o&&(o=i),1==n&&(n=s),n%s==0&&o%i==0)){for(let t=s;t<n;t++)for(let l=0;l<i;l++)e[l].push(e[l%i][t%s]);for(let t=i;t<o;t++)e.push(e[t%i])}}_updateEditorCell(e,t,i){let s=this._g,l=s.cells.getCellElement(e,t),o=s._useFrozenDiv()&&(e<s.frozenRows||t<s.frozenColumns);if(!l||o||s._hasPendingUpdates())s.refresh(!1);else if(this._updateCell(l),(i=i||s._getHasValidation())&&s.headersVisibility&HeadersVisibility.Row){let t=s.rowHeaders,i=t.columns.length-1,l=t.getCellElement(e,i);l&&this._updateCell(l)}}_updateCell(e){var t=new HitTestInfo(e,null),i=FlexGrid._WJS_UPDATING;t.panel&&(wjcCore.addClass(e,i),t.grid.cellFactory.updateCell(t.panel,t.row,t.col,e,t.range),wjcCore.removeClass(e,i))}_getValidationError(){let e=this._g;if(e._getHasValidation()){let t=this._rng.row,i=this._rng.col,s=e.cellFactory.getEditorValue(e),l=e.getCellData(t,i,!1);if(e.setCellData(t,i,s,!0,!1)){let s=e._getError(e.cells,t,i);return e.setCellData(t,i,l,!0,!1),s}}return null}_allowEditing(e,t){let i=this._g;if(i.isReadOnly||i.selectionMode==SelectionMode.None)return!1;if(e<0||e>=i.rows.length||i.rows[e].isReadOnly||!i.rows[e].isVisible)return!1;if(t<0||t>=i.columns.length)return!1;let s=i._getBindingColumn(i.cells,e,i.columns[t]);return!(!s||s.isReadOnly||!s.isVisible)}_commitRowEdits(){let e=this._g;if(this.finishEditing()&&this._edItem){let t=e.editableCollectionView;if(t&&t.currentEditItem){let i=new CellRangeEventArgs(e.cells,e.selection);e.onRowEditEnding(i),t.commitEdit(),e.onRowEditEnded(i)}this._edItem=null}}_keydown(e){let t=this._edt;switch(e.keyCode){case wjcCore.Key.F2:return this._fullEdit=!this._fullEdit,e.preventDefault(),!0;case wjcCore.Key.F4:return this._toggleListBox(e),e.preventDefault(),!0;case wjcCore.Key.Space:return!t||"checkbox"!=t.type||t.disabled||t.readOnly||(t.checked=!t.checked,this.finishEditing(),e.preventDefault()),!0;case wjcCore.Key.Enter:if(e.preventDefault(),t&&e.altKey){let t=e.target;if(t instanceof HTMLTextAreaElement){var i=t.value,s=t.selectionStart,l=t.selectionEnd;return t.value=i.substr(0,s)+"\n"+i.substr(l),wjcCore.setSelectionRange(t,s+1),!0}}return!this.finishEditing();case wjcCore.Key.Tab:return e.preventDefault(),!this.finishEditing();case wjcCore.Key.Escape:return e.preventDefault(),this.finishEditing(!0),!0;case wjcCore.Key.Up:case wjcCore.Key.Down:case wjcCore.Key.Left:case wjcCore.Key.Right:case wjcCore.Key.PageUp:case wjcCore.Key.PageDown:case wjcCore.Key.Home:case wjcCore.Key.End:if(this._lbx)return this._keydownListBox(e);if(e.altKey)switch(e.keyCode){case wjcCore.Key.Up:case wjcCore.Key.Down:return this._toggleListBox(e),e.preventDefault(),!0}if(!this._fullEdit&&this.finishEditing())return!1}return!0}_keydownListBox(e){let t=!0;if(this._lbx)switch(e.keyCode){case wjcCore.Key.Up:e.altKey?this._toggleListBox(e):this._lbx.selectedIndex>0&&this._lbx.selectedIndex--;break;case wjcCore.Key.Down:e.altKey?this._toggleListBox(e):this._lbx.selectedIndex++;break;case wjcCore.Key.Home:case wjcCore.Key.PageUp:this._lbx.selectedIndex=0;break;case wjcCore.Key.End:case wjcCore.Key.PageDown:this._lbx.selectedIndex=this._lbx.collectionView.items.length-1;break;default:t=!1}return!!t&&(e.preventDefault(),!0)}_keypress(e){let t=this._edt;if(t&&"checkbox"!=t.type&&this._list&&this._list.length>0&&e.charCode>=32&&wjcCore.getActiveElement()==t){let i=t.selectionStart,s=t.value.substr(0,i);e.target==t&&(s+=String.fromCharCode(e.charCode),i++);let l=this._findString(this._list,s,!0);l<0&&(l=this._findString(this._list,s,!1)),l>-1&&(t.value=this._list[l],wjcCore.setSelectionRange(t,i,t.value.length),t.dispatchEvent(this._evtInput),e.preventDefault())}}_findString(e,t,i){i||(t=t.toLowerCase());for(let s=0;s<e.length;s++){let l=e[s];if(i||(l=l.toLowerCase()),0==l.indexOf(t))return s}return-1}_toggleListBox(e,t){let i=this._g,s=i._selHdl.selection;if(t||(t=s),this._lbx&&(this._removeListBox(),s.contains(t)))return i.activeEditor?i.activeEditor.focus():i.containsFocus()||i.focus(),!0;let l=i.isTouching,o=i._getBindingColumn(i.cells,t.row,i.columns[t.col]);return!(!tryGetModuleWijmoInput()||!o.dataMap||!1===o.showDropDown)&&(!(!tryGetModuleWijmoInput()||!this.startEditing(!0,t.row,t.col,!l,e))&&(this._lbx=this._createListBox(),this._lbx.showSelection(),l&&this._lbx.focus(),!0))}_createListBox(){let e=this._g,t=this._rng,i=e.rows[t.row],s=e._getBindingColumn(e.cells,t.row,e.columns[t.col]),l=document.createElement("div"),o=new(tryGetModuleWijmoInput().ListBox)(l);this._removeListBox(),wjcCore.addClass(l,"wj-dropdown-panel wj-grid-listbox"),o.maxHeight=4*i.renderHeight,o.isContentHtml=s.isContentHtml,o.itemsSource=s.dataMap.getDisplayValues(i.dataItem),o.selectedValue=e.activeEditor?e.activeEditor.value:e.getCellData(t.row,t.col,!0),wjcCore.addClass(l,s.dropDownCssClass),o.addEventListener(o.hostElement,"click",()=>{this._removeListBox(),e.focus(),this.finishEditing()}),o.lostFocus.addHandler(()=>{this._removeListBox()}),o.selectedIndexChanged.addHandler(()=>{let t=e.activeEditor;t&&(t.value=this._lbx.selectedValue,t.dispatchEvent(this._evtInput),wjcCore.setSelectionRange(t,0,t.value.length))});let n=e.cells.getCellElement(t.row,t.col);return n?wjcCore.showPopup(l,n,!1,!1,!1):(wjcCore.showPopup(l,e.getCellBoundingRect(t.row,t.col)),l[wjcCore.Control._OWNR_KEY]=e.hostElement),o}_removeListBox(){let e=this._lbx;e&&(this._lbx=null,wjcCore.hidePopup(e.hostElement,()=>{e.dispose()}))}}exports._EditHandler=_EditHandler;class _AddNewHandler{constructor(e){this._nrt=new _NewRowTemplate,this._g=e,this._keydownBnd=this._keydown.bind(this),this._attach()}get newRowAtTop(){return this._top}set newRowAtTop(e){e!=this.newRowAtTop&&(this._top=wjcCore.asBoolean(e),this.updateNewRowTemplate())}updateNewRowTemplate(){let e=this._g,t=e.editableCollectionView,i=e.rows,s=t&&t.canAddNew&&e.allowAddNew&&!e.isReadOnly,l=i.indexOf(this._nrt),o=this._top?0:i.length-1,n=!1;if(!s&&l>-1){let t=e.selection;t.row==l&&e.select(t.row-1,t.col),i.removeAt(l)}else s&&(l<0?n=!0:l!=o&&(i.removeAt(l),n=!0),n&&(this._top?i.insert(0,this._nrt):i.push(this._nrt)),this._nrt&&this._nrt._setFlag(RowColFlags.ParentCollapsed,!1))}_attach(){let e=this._g;e&&(e.beginningEdit.addHandler(this._beginningEdit,this),e.pastingCell.addHandler(this._beginningEdit,this),e.rowEditEnded.addHandler(this._rowEditEnded,this),e.loadedRows.addHandler(this.updateNewRowTemplate,this),e.hostElement.addEventListener("keydown",this._keydownBnd,!0))}_detach(){let e=this._g;e&&(e.beginningEdit.removeHandler(this._beginningEdit),e.pastingCell.removeHandler(this._beginningEdit),e.rowEditEnded.removeHandler(this._rowEditEnded),e.loadedRows.removeHandler(this.updateNewRowTemplate),e.hostElement.removeEventListener("keydown",this._keydownBnd,!0))}_keydown(e){e.defaultPrevented||e.keyCode!=wjcCore.Key.Escape||null==this._g.activeEditor&&this._top&&this._nrt.dataItem&&(this._nrt.dataItem=null,this._g.invalidate())}_beginningEdit(e,t){if(!t.cancel){let e=this._g.rows[t.row];if(wjcCore.tryCast(e,_NewRowTemplate)){let i=this._g.editableCollectionView;if(i&&i.canAddNew)if(this._top){if(null==this._nrt.dataItem){let e=null,t=i.sourceCollection,s=i.newItemCreator;e=wjcCore.isFunction(s)?s():t&&t.length?new t[0].constructor:{},this._nrt.dataItem=e}}else{let s=i.currentAddItem&&i.currentAddItem==e.dataItem?i.currentAddItem:i.addNew();i.moveCurrentTo(s),this.updateNewRowTemplate(),this._g.refresh(!0),this._g.onRowAdded(t),t.cancel&&i.cancelNew()}}}}_rowEditEnded(e,t){let i=this._g.editableCollectionView,s=this._nrt.dataItem;if(i)if(i.isAddingNew)i.commitNew();else if(s&&!t.cancel){this._nrt.dataItem=null;let e=i.addNew();for(let t in s)e[t]=s[t];this._g.onRowAdded(t),t.cancel?i.cancelNew():i.commitNew(),setTimeout(()=>{this._g.select(0,this._g.columns.firstVisibleIndex),this.updateNewRowTemplate()},20)}}}exports._AddNewHandler=_AddNewHandler;class _NewRowTemplate extends Row{}exports._NewRowTemplate=_NewRowTemplate;class _ImeHandler{constructor(e){this._compStartBnd=this._compositionstart.bind(this),this._updateImeFocusBnd=this._updateImeFocus.bind(this),this._mouseDownBnd=this._mousedown.bind(this),this._mouseUpBnd=this._mouseup.bind(this),this._g=e,this._tbx=wjcCore.createElement('<input class="wj-grid-editor wj-form-control wj-grid-ime"/>'),wjcCore.disableAutoComplete(this._tbx),wjcCore.setCss(this._tbx,_ImeHandler._cssHidden),e.cells.hostElement.parentElement.appendChild(this._tbx),this._updateImeFocus();let t=e.hostElement,i=e.addEventListener.bind(this);i(this._tbx,"compositionstart",this._compStartBnd),i(t,"blur",this._updateImeFocusBnd),i(t,"focus",this._updateImeFocusBnd),i(t,"mousedown",this._mouseDownBnd,!0),i(t,"mouseup",this._mouseUpBnd,!0),e.cellEditEnded.addHandler(this._cellEditEnded,this),e.selectionChanged.addHandler(this._updateImeFocus,this)}dispose(){let e=this._g,t=e.hostElement,i=e.removeEventListener.bind(this);i(this._tbx,"compositionstart",this._compStartBnd),i(t,"blur",this._updateImeFocusBnd),i(t,"focus",this._updateImeFocusBnd),i(t,"mousedown",this._mouseDownBnd),i(t,"mouseup",this._mouseUpBnd),e.cellEditEnded.removeHandler(this._cellEditEnded),e.selectionChanged.removeHandler(this._updateImeFocus),wjcCore.removeChild(this._tbx)}_cellEditEnded(){wjcCore.setCss(this._tbx,_ImeHandler._cssHidden),this._tbx.value=""}_compositionstart(){let e=this._g;if(null==e.activeEditor){let t=e._selHdl.selection;if(e.startEditing(!1,t.row,t.col,!1)){t=e.editRange;let i=e.cells.hostElement,s=e.columns[t.col].pos+i.offsetLeft,l=e.rows[t.row].pos+i.offsetTop,o=e.getCellBoundingRect(t.row,t.col);if(!t.isSingleCell){let i=e.cells.getCellElement(t.row,t.col);o.width=i.offsetWidth,o.height=i.offsetHeight}t.row<e.frozenRows&&(l+=i.parentElement.scrollTop),t.col<e.frozenColumns&&(s+=i.parentElement.scrollLeft);let n=e.activeEditor,r=n&&n.parentElement?n.parentElement.style.zIndex:"";wjcCore.setCss(this._tbx,{position:"absolute",pointerEvents:"",opacity:"",left:s,top:l,width:o.width-1,height:o.height-1,zIndex:r}),n instanceof HTMLInputElement&&"minLength,maxLength,pattern".split(",").forEach(e=>{wjcCore.setAttribute(this._tbx,e,n.getAttribute(e))}),e._edtHdl._edt=this._tbx}}}_mousedown(e){this._isMouseDown=!0,this._updateImeFocus()}_mouseup(e){this._isMouseDown=!1,this._updateImeFocus()}_updateImeFocus(){let e=this._g,t=wjcCore.getActiveElement();if(!e.activeEditor&&!e.isTouching&&!this._isMouseDown&&wjcCore.closest(t,".wj-flexgrid")==e.hostElement){let e=this._tbx;this._enableIme()?t!=e&&(e.disabled=!1,e.select()):e.disabled=!0}}_enableIme(){let e=this._g,t=e.selection,i=t.isValid?e._getBindingColumn(e.cells,t.row,e.columns[t.col]):null;return!!e.canEditCell(t.row,t.col)&&!(!i||i.dataType==wjcCore.DataType.Boolean)}}_ImeHandler._cssHidden={position:"fixed",pointerEvents:"none",opacity:0,left:-10,top:-10,width:0},exports._ImeHandler=_ImeHandler;