// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("../chunks/tslib.es6 ../core/arrayUtils ../core/Collection ../core/collectionUtils ../core/Evented ../core/MapUtils ../core/maybe ../core/ReactiveMap ../core/reactiveUtils ../core/SetUtils ../core/accessorSupport/decorators/property ../core/has ../core/Logger ../core/accessorSupport/decorators/subclass ../layers/support/layerUtils ../rest/support/Query ./support/selectionUtils".split(" "),function(n,r,t,A,k,B,v,C,w,D,p,G,H,E,m,x,q){k=class extends k.EventedAccessor{constructor(a){super(a); this._selectionMap=new C;this._sources=new t;this._trashCan=[];this._layerEditHandles=new t;this._vizTaskId=0;this.showHighlight=!0}initialize(){this.addHandles([w.watch(()=>[this.view,this.showHighlight],()=>this._refreshVisualization()),w.on(()=>this.sources,"change",b=>{const c=this._selectionMap;for(const e of b.removed)c.delete(e);this._refreshListeners();this._refreshVisualization()},{onListenerAdd:()=>this._refreshListeners()})]);const a=new t;this.view.when().then(()=>{this.view.map&&(this.view.map.allLayers.flatten(b=> "sublayers"in b&&b.sublayers?b.sublayers:null).forEach(b=>{(q.isSelectableLayer(b)&&!m.isSubtypeGroupLayer(b)||m.isSubtypeSublayer(b))&&a.add(b)}),this.sources=a)})}destroy(){this._layerEditHandles.drain(v.removeMaybe)}get selections(){return Array.from(this._selectionMap.entries()).map(a=>{const [b,c]=a;return{layer:b,selection:[...c.selection]}})}get count(){let a=0;for(const b of this._selectionMap.values())a+=b.selection.length;return a}get hasSelection(){return 0a.includes(d.layer)):f).filter(d=>0{const {layer:h,selection:l}=d;d=m.isSubtypeSublayer(h)?h.parent:h;return null==d||void 0===d?.when?null:"layer"===c?y(d,l,b):z(d)?null:(d=await e.whenLayerView(d).catch(()=>null))?y(d,l,b):null});return(await Promise.all(g)).filter(d=>null!=d)}updateSelection(a){var b=new Map;for(const [d,h]of this._selectionMap)b.set(d, [...h.selection]);var c=!1,e=a.current.concat(a.added);for(var f of e){var g=f.sourceLayer;e=f.getObjectId();this.sources.includes(g)&&(q.isSelectableLayer(g)||m.isSubtypeSublayer(g))&&null!==e&&(g=B.getOrCreateMapValue(b,g,()=>[]),g.includes(e)||(g.push(e),c=!0))}for(const d of a.removed)f=d.sourceLayer,a=d.getObjectId(),this.sources.includes(f)&&(q.isSelectableLayer(f)||m.isSubtypeSublayer(f))&&null!==a&&(f=b.get(f),a=f?.indexOf(a),void 0!==a&&0<=a&&(f?.splice(a,1),c=!0));if(c){const {_selectionMap:d, _trashCan:h}=this;c=[];for(const [l,u]of b)b=d.get(l),void 0!==b&&h.push(b),d.set(l,{selection:u}),c.push({layer:l,selection:u,...r.difference(void 0!==b?b.selection:[],u)});this._onSelectionChange(c)}}setSelection(a,b){this._setSelection(a,b)}getSelection(a){return this._selectionMap.get(a)?.selection}appendToSelection(a,b){var c=this._selectionMap.get(a);c=void 0!==c?[...c.selection]:[];for(const e of b)c.includes(e)||c.push(e);this._setSelection(a,c)}removeFromSelection(a,b){const c=this._selectionMap.get(a); if(c){var e=[];for(const f of c.selection)b.includes(f)||e.push(f);this._setSelection(a,e)}}toggleInSelection(a,b){var c=this._selectionMap.get(a);c&&0!==c.selection.length?(c=new Set(c.selection),b=new Set(b),b=D.symmetricDifference(c,b),this._setSelection(a,Array.from(b))):this._setSelection(a,b)}clear(){var a=this._selectionMap.values();this._trashCan.push(...a);a=[];for(const [b,c]of this._selectionMap.entries())a.push({layer:b,added:[],removed:[...c.selection],selection:[]});this._selectionMap.clear(); this._onSelectionChange(a)}_onSelectionChange(a){this._refreshVisualization();this.emit("selection-change",{view:this.view,changes:a})}_refreshVisualization(){if(null!=this.view&&null!=this.sources){for(this._vizTaskId++;0 {d?.highlightHandle?.remove();null!=d&&e&&f===this._vizTaskId&&"highlight"in l&&"function"===typeof l.highlight&&0{d?.highlightHandle?.remove()})}}}_refreshListeners(){this._layerEditHandles.drain(v.removeMaybe);for(const b of this.sources){var a=m.isSubtypeSublayer(b)?b.parent:b;null!=a&&q.isSelectableLayer(a)&&(a=a.on("edits",c=>{this._handleEditChanges(c,b)}),this._layerEditHandles.push(a))}}_handleEditChanges(a, b){void 0!==a.deletedFeatures&&0null==c.error).map(c=>c.objectId).filter(r.isSome),this.removeFromSelection(b,a))}_setSelection(a,b){if(!this.sources.includes(a))throw Error(`Cannot set selection on layer ${a.title} because it is not in 'sources'`);const c=this._selectionMap.get(a);void 0!==c&&F(c,{selection:b})||(void 0!==c&&this._trashCan.push(c),this._selectionMap.set(a,{selection:[...b]}),a={layer:a,selection:[...b], ...r.difference(void 0!==c?c.selection:[],b)},this._onSelectionChange([a]))}};n.__decorate([p.property({readOnly:!0,nonNullable:!0})],k.prototype,"selections",null);n.__decorate([p.property({readOnly:!0,nonNullable:!0})],k.prototype,"count",null);n.__decorate([p.property({constructOnly:!0,nonNullable:!0})],k.prototype,"view",void 0);n.__decorate([p.property({readOnly:!0,nonNullable:!0})],k.prototype,"hasSelection",null);n.__decorate([p.property()],k.prototype,"showHighlight",void 0);n.__decorate([p.property()], k.prototype,"sources",null);k=n.__decorate([E.subclass("esri.views.SelectionManager")],k);const z=a=>m.isSubtypeSublayer(a)?!0===a.parent?.isTable:a.isTable,F=(a,b)=>{if(null!=a||null!=b){if(null!=a&&null==b||null==a&&null!=b)return!1;if(null!=a&&null!=b&&null!=a.selection&&null!=b.selection){a=[...a.selection];b=[...b.selection];if(a.length!==b.length)return!1;a.sort();b.sort();for(let c=0;cvoid 0===a.layer?void 0===a?null:await a.queryFeatures(new x({...c, objectIds:b})).then(e=>({data:e,layer:a})):void 0===a?null:await a.queryFeatures(new x({...c,objectIds:b})).then(e=>({data:e,layer:a.layer}));return k});