UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.19 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 e}from"../../../chunks/tslib.es6.js";import{deprecatedProperty as t}from"../../../core/deprecate.js";import r from"../../../core/Evented.js";import{handlesGroup as o}from"../../../core/handleUtils.js";import s from"../../../core/Logger.js";import{removeMaybe as i}from"../../../core/maybe.js";import{watch as a}from"../../../core/reactiveUtils.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{isKnowledgeGraphLayer as l,isLinkChartLayer as p}from"../../../layers/support/layerUtils.js";import{findLayerView as u}from"../../../views/draw/support/layerUtils.js";import{isSelectableLayerView2D as h}from"../../../views/support/layerViewUtils.js";import d from"../Selector2D/SelectionOperation.js";let m=class extends r.EventedAccessor{constructor(e){super(e),this._operationHandlesGroup=null,this.activeOperation=null,this.layerViewPreferenceEnabled=!0,this.sources=null}initialize(){this.addHandles([a((()=>this._sources),(e=>{this.activeOperation&&(this.activeOperation.sources=e)}))])}destroy(){this._operationHandlesGroup=i(this._operationHandlesGroup)}get _sources(){const{layerViewPreferenceEnabled:e,sources:t,view:r}=this;return r&&t?.length?t.flatMap((t=>{if(h(t))return t;if(l(t)||p(t)){const o=t.layers||[],s=o.map((t=>{const o=u(r,t)||void 0;return e&&h(o)?o:t}));return s.length?s.toArray():o.length?o.toArray():t}if(!e)return t;const o=u(r,t)||void 0;return h(o)?o:t})):[]}get layers(){return t(s.getLogger(this),"layers",{replacement:"Use SelectionToolbar.sources instead."}),this.sources}set layers(e){t(s.getLogger(this),"layers",{replacement:"Use SelectionToolbar.sources instead."}),this.sources=e}get state(){const{_sources:e,view:t}=this,r=!e?.length&&!t?.selectionManager.sources.length;return this.activeOperation?"active":t?.ready&&!r?"ready":"disabled"}cancel(){"active"===this.state&&(this.activeOperation?.cancel(),this._set("activeOperation",null))}activate(e){const{_sources:t,state:r,view:s}=this,i=!t?.length&&!s?.selectionManager.sources.length;if("disabled"===r||i||!this.view)return;"active"===r&&this.cancel();const a=new d({view:this.view,sources:t,options:e});return this._operationHandlesGroup=o([a.selection.on("change",(e=>this.emit("selection-change",e))),a.once("complete",(e=>this._onOperationComplete(e)))]),this._set("activeOperation",a),a}_onOperationComplete(e){this._operationHandlesGroup=i(this._operationHandlesGroup),this._set("activeOperation",null),this.emit("complete",e)}};e([n()],m.prototype,"_sources",null),e([n({readOnly:!0})],m.prototype,"activeOperation",void 0),e([n()],m.prototype,"layers",null),e([n()],m.prototype,"layerViewPreferenceEnabled",void 0),e([n()],m.prototype,"sources",void 0),e([n({readOnly:!0})],m.prototype,"state",null),e([n()],m.prototype,"view",void 0),m=e([c("esri.widgets.support.SelectionToolbar.SelectionToolbarViewModel")],m);const v=m;export{v as default};