UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.23 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../core/Collection.js";import s from"../../core/Evented.js";import{watch as i,initial as o}from"../../core/reactiveUtils.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 r}from"../../core/accessorSupport/decorators/subclass.js";import{findLayerListMode as a}from"../LayerList/support/layerListUtils.js";import d from"./ListItem.js";const m={map:"map",layerListMode:"layer-list-mode"},n="hide",c=e.ofType(d);let h=class extends s.EventedAccessor{constructor(t){super(t),this.checkPublishStatusEnabled=!1,this.listItemCreatedFunction=null,this.listModeDisabled=!1,this.tableItems=new c,this.map=null}initialize(){this.addHandles([i((()=>[this.tables,this.map?.allTables.toArray()]),(()=>this._compileList()),o),i((()=>[this.map?.loaded,this.listItemCreatedFunction,this.checkPublishStatusEnabled,this.listModeDisabled]),(()=>this._recompileList()))],m.map)}destroy(){this._removeAllItems(),this.map=null,this.tables=null}get tables(){return this.map?.allTables}set tables(t){this._overrideIfSome("tables",t)}get state(){const{map:t,tables:e}=this;if(!t)return e?"ready":"disabled";const s=t?.loadStatus;return"string"==typeof s?"loaded"===s?"ready":"loading"===s?"loading":"disabled":"ready"}get totalItems(){return this.tableItems.length}triggerAction(t,e){t&&!t.disabled&&this.emit("trigger-action",{action:t,item:e})}_removeAllItems(){this.tableItems.destroyAll()}_getViewableTables(t){return t?this.listModeDisabled?t:t.filter((t=>a(t)!==n)):void 0}_watchTablesListMode(t){this.removeHandles(m.layerListMode),t&&!this.listModeDisabled&&this.addHandles(i((()=>t.filter((t=>"listMode"in t)).map((t=>t.listMode)).toArray()),(()=>this._compileList())),m.layerListMode)}_compileList(){const{tables:t}=this;this._watchTablesListMode(t);const e=this._getViewableTables(t);e?.length?(this._createNewItems(e),this._removeItems(e),this._sortItems(e)):this._removeAllItems()}_createNewItems(t){const{tableItems:e,listItemCreatedFunction:s,checkPublishStatusEnabled:i}=this;t.forEach((t=>{e.some((e=>e.layer===t))||e.add(new d({checkPublishStatusEnabled:i,layer:t,listItemCreatedFunction:s}))}))}_removeItems(t){const{tableItems:e}=this;e.forEach((s=>{if(!s)return;const i=t?.find((t=>s.layer===t));i||(e.remove(s),s.destroy())}))}_sortItems(t){const{tableItems:e}=this;e.sort(((e,s)=>{const i=t.indexOf(e.layer),o=t.indexOf(s.layer);return i>o?-1:i<o?1:0}))}_recompileList(){this._removeAllItems(),this._compileList()}};t([l()],h.prototype,"checkPublishStatusEnabled",void 0),t([l()],h.prototype,"listItemCreatedFunction",void 0),t([l({nonNullable:!0})],h.prototype,"listModeDisabled",void 0),t([l({type:c,readOnly:!0})],h.prototype,"tableItems",void 0),t([l()],h.prototype,"tables",null),t([l()],h.prototype,"map",void 0),t([l({readOnly:!0})],h.prototype,"state",null),t([l()],h.prototype,"totalItems",null),h=t([r("esri.widgets.TableList.TableListViewModel")],h);export{h as default};