UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 5.8 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as t}from"../../../chunks/tslib.es6.js";import e from"../../../core/Collection.js";import{referenceSetter as o}from"../../../core/collectionUtils.js";import i from"../../../core/Evented.js";import{property as l}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as n}from"../../../core/accessorSupport/decorators/subclass.js";import{isGroupColumn as s,isFieldColumn as r,isRelationshipColumn as u}from"../support/columnUtils.js";import{uniqueColumnNames as d,isPageIndexValid as h}from"../support/tableUtils.js";let a=class extends i.EventedAccessor{constructor(t){super(t),this.cellPartNameGenerator=(t,e)=>{let o="";e?.item&&this.rowHighlightIds.includes(e.item.objectId)&&(o+=" highlight");const i=this.findColumn(t?.path);return i?(i.invalid&&(o+=" invalid"),i.textWrap&&(o+=" text-wrap"),"editInfo"in i&&i.editInfo&&i.editInfo.rowData?.index===e.index&&(o+=" editing"),o):o},this.columnPerformanceModeEnabled=!0,this.columnReorderingEnabled=!0,this.columns=new e,this.dataProvider=async(t,e)=>{const{store:o}=this;if(!e)return;if(!o)return void(e&&e([]));e(await o.fetchItems(t))},this.maxSize=null,this.multipleSelectionEnabled=!0,this.multiSortEnabled=!1,this.paginationEnabled=!1,this.rowDetailsRenderer=null,this.store=null}get actionColumn(){return this.allColumns.find((t=>t.fieldName===d.action))}get allColumns(){return this.columns.toArray().flatMap((t=>[t,...s(t)&&t.columns?.length?t.columns:[]]))}get allVisibleColumns(){return this.allColumns.filter((t=>!t.hidden))}get columnMenuIsOpen(){return this.allColumns.some((t=>t.menuIsOpen))}get editing(){return this.editableColumns.some((t=>t.editInfo))}get editableColumns(){return this.allColumns.filter((t=>"editable"in t))}get effectiveSize(){const{filterBySelectionEnabled:t,highlightIds:e,objectIds:o,pageSize:i,size:l}=this;if(this.paginationEnabled){const n=this.pageCount===this.pageIndex+1?l%i:i;return t?Math.min(e.length,n):o.length?Math.min(o.length,n):n}return t?e.length:o.length?o.length:l}get fieldColumns(){return this.allColumns.filter((t=>r(t)))}get filterBySelectionEnabled(){return!!this._get("filterBySelectionEnabled")}set filterBySelectionEnabled(t){this._set("filterBySelectionEnabled",t)}get groupColumns(){return this.columns.toArray().filter((t=>s(t)))}get hasInvalidColumnConfiguration(){return this.visibleColumns.every((t=>t.frozen||t.frozenToEnd))}get highlightIds(){return this._get("highlightIds")||new e}set highlightIds(t){const i=Array.isArray(t)?new e(t):t;this.multipleSelectionEnabled||i.splice(1,i.length-1),this._set("highlightIds",o(i,this._get("highlightIds"),e))}get objectIds(){return this._get("objectIds")??new e}set objectIds(t){this._set("objectIds",o(t,this._get("objectIds"),e))}get pageCount(){const{pageSize:t,size:e}=this;return 0===e||0===t?1:Math.ceil(e/t)}get pageIndex(){return this._get("pageIndex")||0}set pageIndex(t){const{pageCount:e}=this;h(t,e)&&this._set("pageIndex",t)}get pageSize(){return this._get("pageSize")??50}set pageSize(t){this.store?.set("pageSize",t),this._set("pageSize",t)}get relationshipColumns(){return this.allColumns.filter((t=>u(t)))}get rowHighlightIds(){return this._get("rowHighlightIds")||new e}set rowHighlightIds(t){this._set("rowHighlightIds",o(t,this._get("rowHighlightIds"),e))}get size(){const t=this.store?.count??0,{maxSize:e}=this;return null!=t&&null!=e?Math.min(e,t):t}get state(){return this.store?.state??"disabled"}get visibleColumns(){return this.columns.toArray().filter((t=>!t.hidden))}closeColumnMenus(){this.allColumns.forEach((t=>t.closeMenu()))}sortColumn(t,e){if(!t)return;const o=this.findColumn(t);o&&(o.direction=e)}hideColumn(t){const e=this.findColumn(t);!1===e?.hidden&&(e.hidden=!0)}showColumn(t){const e=this.findColumn(t);e?.hidden&&(e.hidden=!1)}showAllColumns(){this.allColumns.forEach((t=>{t.hidden&&(t.hidden=!1)}))}findColumn(t){return this.allColumns.find((e=>e.fieldName===t))}refresh(){this.store&&(this.store.reset(),this.store.load())}toggleColumnVisibility(t){const e=this.findColumn(t);e&&(e.hidden=!e.hidden)}};t([l()],a.prototype,"actionColumn",null),t([l()],a.prototype,"allColumns",null),t([l()],a.prototype,"allVisibleColumns",null),t([l()],a.prototype,"cellPartNameGenerator",void 0),t([l()],a.prototype,"columnMenuIsOpen",null),t([l()],a.prototype,"columnPerformanceModeEnabled",void 0),t([l()],a.prototype,"columnReorderingEnabled",void 0),t([l()],a.prototype,"columns",void 0),t([l()],a.prototype,"dataProvider",void 0),t([l()],a.prototype,"editing",null),t([l()],a.prototype,"editableColumns",null),t([l()],a.prototype,"effectiveSize",null),t([l()],a.prototype,"fieldColumns",null),t([l()],a.prototype,"filterBySelectionEnabled",null),t([l()],a.prototype,"groupColumns",null),t([l()],a.prototype,"hasInvalidColumnConfiguration",null),t([l()],a.prototype,"highlightIds",null),t([l()],a.prototype,"maxSize",void 0),t([l()],a.prototype,"multipleSelectionEnabled",void 0),t([l()],a.prototype,"multiSortEnabled",void 0),t([l()],a.prototype,"objectIds",null),t([l()],a.prototype,"pageCount",null),t([l()],a.prototype,"pageIndex",null),t([l()],a.prototype,"pageSize",null),t([l()],a.prototype,"paginationEnabled",void 0),t([l()],a.prototype,"relationshipColumns",null),t([l()],a.prototype,"rowHighlightIds",null),t([l()],a.prototype,"rowDetailsRenderer",void 0),t([l({readOnly:!0})],a.prototype,"size",null),t([l()],a.prototype,"store",void 0),t([l({readOnly:!0})],a.prototype,"state",null),t([l()],a.prototype,"visibleColumns",null),a=t([n("esri.widgets.FeatureTable.Grid.GridViewModel")],a);const p=a;export{p as default};