SketchViewModel.js 47 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../../chunks/tslib.es6.js";import{symbolTypes as t}from"../../symbols.js";import o from"../../core/Collection.js";import"../../core/has.js";import i from"../../core/Error.js";import a from"../../core/Evented.js";import r from"../../core/Handles.js";import s from"../../core/Logger.js";import{destroyMaybe as n,isSome as p,unwrap as l,abortMaybe as h,isNone as c,unwrapOr as d,get as u}from"../../core/maybe.js";import{createAbortError as y,whenOrAbort as m}from"../../core/promiseUtils.js";import{on as g,watch as v,when as f,whenOnce as _,syncAndInitial as w}from"../../core/reactiveUtils.js";import{property as b}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as G}from"../../core/accessorSupport/decorators/subclass.js";import{canProjectWithoutEngine as T,isLoaded as O,load as E,project as S}from"../../geometry/projection.js";import{getReferenceEllipsoid as A}from"../../geometry/projectionEllipsoid.js";import{geometryToCoordinates as k}from"../../geometry/support/coordsUtils.js";import{equals as C}from"../../geometry/support/spatialReferenceUtils.js";import H from"../../layers/GraphicsLayer.js";import{SupportedGraphicResult as I,isSupportedGraphicResultMessage as R}from"../../views/3d/interactive/editingTools/isSupportedGraphicUtils.js";import{isSupportedGraphic as D}from"../../views/3d/interactive/editingTools/moveGraphic/isSupportedGraphic.js";import{isSupportedGraphic as M}from"../../views/3d/interactive/editingTools/reshapeGraphic/isSupportedGraphic.js";import{isSupportedGraphic as U}from"../../views/3d/interactive/editingTools/transformGraphic/isSupportedGraphic.js";import{addUniqueLayer as P}from"../../views/draw/support/layerUtils.js";import{ViewEventPriorities as x}from"../../views/input/InputManager.js";import{SKETCH_KEYS as j}from"../../views/interactive/keybindings.js";import L from"../../views/interactive/sketch/SketchLabelOptions.js";import F from"../../views/interactive/sketch/SketchTooltipOptions.js";import{SnappingManager as V}from"../../views/interactive/snapping/SnappingManager.js";import W from"../../views/interactive/snapping/SnappingOptions.js";import{findFirstGraphicHit as K}from"../../views/support/hitTestSelectUtils.js";import{createScreenPointFromEvent as q}from"../../views/support/screenUtils.js";import{CreateOperationHandle as Z,UpdateOperationHandle as z}from"./support/OperationHandle.js";import N from"../../symbols/SimpleMarkerSymbol.js";import B from"../../symbols/SimpleFillSymbol.js";import $ from"../../symbols/SimpleLineSymbol.js";const Y={defaultZ:0},J={reshapeOptions:{edgeOperation:"split",shapeOperation:"move",vertexOperation:"move"},enableMoveAllGraphics:!0,enableRotation:!0,enableScaling:!0,multipleSelectionEnabled:!0,preserveAspectRatio:!1,toggleToolOnClick:!0,enableZ:!0,tool:"transform"};let Q=class extends a.EventedAccessor{constructor(e){super(e),this._numUpdating=0,this._handles=new r,this._internalGraphicsLayer=new H({listMode:"hide",internal:!0,title:"SVM Internal"}),this._operationHandle=null,this._viewHandles=new r,this.activeFillSymbol=null,this.activeLineSymbol=null,this.activeVertexSymbol=null,this.allowDeleteKey=!0,this.labelOptions=new L,this.layer=null,this.pointSymbol=new N({style:"circle",size:6,color:[255,255,255],outline:{color:[50,50,50],width:1}}),this.polygonSymbol=new B({color:[150,150,150,.2],outline:{color:[50,50,50],width:2}}),this.polylineSymbol=new $({color:[130,130,130,1],width:2}),this._snappingManager=null,this.tooltipOptions=new F,this.updateGraphics=new o,this.updateOnGraphicClick=!0,this.updatePointSymbol=new N({size:10,color:[0,200,255,.5],outline:{color:"black",width:1}}),this.updatePolygonSymbol=new B({color:[12,207,255,.2],outline:{join:"round",color:[12,207,255],width:2}}),this.updatePolylineSymbol=new $({color:[12,207,255],width:2}),this.vertexSymbol=new N({style:"circle",size:6,color:[255,255,255],outline:{color:[50,50,50],width:1}}),this._moduleLoaderAbortController=null,this._viewReadyAbortController=null,this._originalAutoOpenEnabled=null,this.defaultCreateOptions=Y,this.defaultUpdateOptions=J,this.snappingOptions=new W}initialize(){this._handles.add([g((()=>this.view?.map?.layers),"change",(e=>{e.removed.includes(this.layer)&&this.cancel()})),g((()=>this.layer?.graphics),"change",(e=>{if(p(this._operationHandle))for(const t of e.removed)this.updateGraphics.includes(t)&&(this.updateGraphics.length>1?this._operationHandle.removeFromSelection(t):this._operationHandle.cancel())})),v((()=>this.layer?.elevationInfo??null),(e=>{e!==this._internalGraphicsLayer.elevationInfo&&(this.cancel(),this._internalGraphicsLayer.elevationInfo=e)}),w),v((()=>this.view),(e=>{n(this._snappingManager),e&&(this._snappingManager=new V({view:e,options:this.snappingOptions}),"2d"===e.type?import("../../views/2d/interactive/editingTools.js"):"3d"===e.type&&(import("../../views/3d/interactive/editingTools.js"),import("../../views/3d/layers/GraphicsLayerView3D.js")))}),w),v((()=>this.view?.spatialReference),((e,t)=>{e&&t&&!e.equals(t)&&this.cancel()}))])}destroy(){this.cancel(),this._handles=n(this._handles),this._viewHandles=n(this._viewHandles),this._removeDefaultLayer(),this._snappingManager=n(this._snappingManager),this._set("view",null),this.emit("destroy")}get _defaultUpdateTool(){return"3d"===this.view.type?"move":"transform"}get updating(){return this._numUpdating>0}get activeTool(){return this._operationHandle&&this._operationHandle.tool?this._operationHandle.tool:null}get activeComponent(){return this._operationHandle?this._operationHandle.activeComponent:null}get createGraphic(){return!p(this.activeComponent)||"draw-3d"!==this.activeComponent.type&&"draw-2d"!==this.activeComponent.type?this._get("createGraphic"):l(this.activeComponent.graphic)}get defaultCreateOptions(){return this._get("defaultCreateOptions")}set defaultCreateOptions(e){this._set("defaultCreateOptions",{...Y,...e})}get defaultUpdateOptions(){return this._get("defaultUpdateOptions")}set defaultUpdateOptions(e){this._set("defaultUpdateOptions",{...J,...e,reshapeOptions:{...J.reshapeOptions,...e?.reshapeOptions}})}set snappingOptions(e){p(this._snappingManager)&&(this._snappingManager.options=e),this._set("snappingOptions",e)}get state(){const e=!(!this.view?.ready||!this.layer),t=this._operationHandle;return e&&t?"active":e?"ready":"disabled"}get view(){return this._get("view")}set view(e){const t=this._get("view");if(t){const{container:e,map:o}=t;e&&(t.cursor=null),o&&o.remove(this._internalGraphicsLayer),this._viewHandles.removeAll(),this.cancel()}const o="view-ready";this._handles.remove(o),e&&this._handles.add(f((()=>e.ready),(t=>{this._viewHandles.removeAll(),t&&this._viewHandles.add(this._generateViewHandles(e))}),w),o),this._set("view",e)}cancel(){this._moduleLoaderAbortController=h(this._moduleLoaderAbortController),this._viewReadyAbortController=h(this._viewReadyAbortController),this._operationHandle&&this._operationHandle.cancel()}complete(){this._operationHandle&&this._operationHandle.complete()}delete(){const{state:e,updateGraphics:t}=this;if("active"===e&&t.length){const{activeTool:e,layer:o}=this,i=t.toArray();o.removeMany(i),this.cancel(),this._emitDeleteEvent({graphics:i,tool:e})}}async create(e,t){if(this.cancel(),await this._waitViewReady(),"disabled"===this.state)throw this.layer||this._logError("sketch:missing-property","Property 'layer' is missing on SketchViewModel."),this.view||this._logError("sketch:missing-property","Property 'view' is missing on SketchViewModel."),y();if(p(this.view.activeTool)&&(this.view.activeTool=null),!e)return void this._logError("sketch:missing-parameter","Missing parameter 'tool'.");P(this.view,this._internalGraphicsLayer);const o=await this._setupCreateOperation(e,t);if(c(o)||this.destroyed)return void this.view.map.remove(this._internalGraphicsLayer);const i=()=>{if(o===this._operationHandle){const t=this.createGraphic,i=this._operationHandle.cancelled;this._operationHandle.destroy(),this._operationHandle=null,this._set("createGraphic",null),this.view&&this.view.map&&this.view.map.remove(this._internalGraphicsLayer),o.cancelled||null==t||this.layer.add(t),this.emit("create",{graphic:t,state:i?"cancel":"complete",tool:e,toolEventInfo:null,type:"create"})}};o.on("complete",i),this._operationHandle=o,this.view.ready&&this.view.focus()}async update(e,t){this.cancel(),await this._waitViewReady();const{layer:o,view:i,state:a}=this;if("disabled"===a)throw i||this._logError("sketch:missing-property","Property 'view' is missing on SketchViewModel."),o||this._logError("sketch:missing-property","Property 'layer' is missing on SketchViewModel."),y();p(this.view.activeTool)&&(this.view.activeTool=null);const r=Array.isArray(e)?e:[e];if(null==e||!r||!r.length)return void this._logError("sketch:missing-parameter","Missing parameter 'graphics'.");if(r.some((e=>e.layer!==o?(this._logError("sketch:invalid-parameter","Parameter 'graphics' contains one or more graphics missing from the supplied GraphicsLayer."),!0):!!c(e.geometry)&&(this._logError("sketch:invalid-parameter","Parameter 'graphics' contains one or more graphics with an unsupported geometry."),!0))))return;const s=await this._setupUpdateOperation(r,t);this.destroyed||c(s)||ae(s)||(P(this.view,this._internalGraphicsLayer),this._setUpdateOperationHandle(s,t),this.emit("update",{graphics:r,state:"start",aborted:!1,tool:s.tool,toolEventInfo:null,type:"update"}))}async _updateSpatialReference(e){this._beginAsyncOperation(),e=Array.isArray(e)?e:[e];for(const t of e)p(t.geometry)&&"mesh"!==t.geometry.type&&!C(t.geometry.spatialReference,this.view.spatialReference)&&(T(t.geometry.spatialReference,this.view.spatialReference)||O()||await E(),t.geometry=S(t.geometry,this.view.spatialReference));this._endAsyncOperation()}undo(){this.canUndo()&&this._operationHandle.undo()}redo(){this.canRedo()&&this._operationHandle.redo()}canUndo(){return!(!this._operationHandle||!this._operationHandle.canUndo())}canRedo(){return!(!this._operationHandle||!this._operationHandle.canRedo())}toggleUpdateTool(){this._operationHandle&&this._operationHandle.toggleTool&&this._operationHandle.toggleTool()}async _getFirstHit(e){const t=this.view;if("2d"===t.type){const t=[];this.view.map.allLayers.forEach((e=>{"vector-tile"!==e.type&&"imagery"!==e.type||t.push(e)}));const o=await this.view.hitTest(e,{exclude:t});return K(o.results)}const o=[this.view.map.ground];t.map.allLayers.forEach((e=>{"integrated-mesh"===e.type&&o.push(e)}));const i=await t.hitTest(e,{exclude:o});if(i.results.length>0){const e=i.results[0];if(p(e)&&"graphic"===e.type&&e.graphic&&(!i.ground.mapPoint||t.map.ground.opacity<1||i.ground.distance-d(e.distance,0)>-Math.min(3*i.ground.distance,"global"===t.viewingMode?A(t.renderCoordsHelper.spatialReference).radius/t.renderCoordsHelper.unitInMeters:Number.POSITIVE_INFINITY)))return e}return null}_generateViewHandles(e){return[e.on("immediate-click",(async t=>{const o="active"===this.state&&"create"===this._operationHandle.type;if("disabled"===this.state||o||!this.updateOnGraphicClick)return;this._beginAsyncOperation();const i=await t.async((()=>this._getFirstHit(q(t))));let a=null;if(p(i)){const o=i.graphic;this.updateGraphics.includes(o)||o.layer===this.layer?(t.stopPropagation(),a=o):"2d"!==e.type||this._isComponentGraphic(o)||"active"!==this.state||this.cancel()}else"active"===this.state&&this.cancel();p(a)&&!this.updateGraphics.includes(a)&&await this.update([a],{...this.defaultUpdateOptions,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions}}),this._endAsyncOperation()}),x.WIDGET)]}async _setupCreateOperation(e,t){const o={hasZ:"3d"===this.view.type,...this.defaultCreateOptions,...t},i=await this._setupDrawGraphicTool(e,this.view,o);return c(i)?null:(this.view.tools.add(i),this.view.activeTool=i,this._setupCreateOperationHandle(i))}async _setupDrawGraphicTool(e,t,o){if("multipoint"===e&&"3d"===t.type)return this._logError("sketch:create","Multipoint geometries are not supported in SceneView."),null;const i="rectangle"!==e,a="rectangle"!==e;this.snappingOptions.enabledToggled=!1;const r={view:t,mode:"rectangle"===e||"circle"===e?"hybrid":"click",...o,snapToScene:!1,geometryType:e,graphicSymbol:this._getGraphicSymbolFromTool(e),snappingManager:this._snappingManager,forceUniformSize:a,centered:i};return"2d"===this.view.type?this._makeDrawGraphicTool2D(r):this._makeDrawGraphicTool3D(r)}async _makeDrawGraphicTool2D(e){const t=await this._requireModule(import("../../views/2d/interactive/editingTools.js"));return ae(t)||this.destroyed?null:new t.module.DrawGraphicTool2D({...e,activeVertexSymbol:this.activeVertexSymbol,regularVerticesSymbol:this.vertexSymbol,activeLineSymbol:this.activeLineSymbol,activeFillSymbol:X(e.geometryType)?this.activeFillSymbol:null,tooltipOptions:this.tooltipOptions})}async _makeDrawGraphicTool3D(e){const t=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(ae(t)||this.destroyed)return null;const{elevationInfo:o}=this.layer;return new t.module.DrawGraphicTool3D({...e,elevationInfo:o,snapToScene:!p(o)||"absolute-height"===o.mode,labelOptions:this.labelOptions,tooltipOptions:this.tooltipOptions})}_setupCreateOperationHandle(e){let t=null;const o=e.forceUniformSize,i=e.centered,a=[this.view.on("key-down",(t=>{if(t.key===j.pan)t.stopPropagation(),t.repeat||(e.enabled=!1);else if(t.key===j.complete)t.stopPropagation(),e.completeCreateOperation();else if(t.key!==j.vertexAdd||t.repeat)t.key===j.undo?(t.stopPropagation(),r.undo()):t.key===j.redo?(t.stopPropagation(),r.redo()):t.key!==j.snappingToggle||"rectangle"===e.geometryType||"circle"===e.geometryType||t.repeat?t.key!==j.constraint||"rectangle"!==e.geometryType&&"circle"!==e.geometryType||t.repeat?t.key===j.center&&(t.repeat||(e.centered=!i,t.stopPropagation())):(e.forceUniformSize=!o,t.stopPropagation()):(this.snappingOptions.enabledToggled=!0,t.stopPropagation());else{const o=e.drawOperation.geometryType;"polyline"!==o&&"polygon"!==o&&"multipoint"!==o||(t.stopPropagation(),e.drawOperation.commitStagedVertex())}}),x.WIDGET),this.view.on("key-up",(t=>{t.key===j.pan?e.enabled=!0:t.key===j.snappingToggle&&"rectangle"!==e.geometryType&&"circle"!==e.geometryType?(this.snappingOptions.enabledToggled=!1,t.stopPropagation()):t.key!==j.constraint||"rectangle"!==e.geometryType&&"circle"!==e.geometryType?t.key===j.center&&(e.centered=i,t.stopPropagation()):(e.forceUniformSize=o,t.stopPropagation())}),x.WIDGET),e.on("vertex-add",(o=>{switch(t=c(t)?"start":"active",o.operation){case"apply":this.emit("create",{graphic:l(e.graphic),state:t,tool:this.activeTool,toolEventInfo:o,type:"create"});break;case"undo":this._emitUndoEvent({graphics:[l(e.graphic)],tool:e.geometryType});break;case"redo":this._emitRedoEvent({graphics:[l(e.graphic)],tool:e.geometryType})}})),e.on("cursor-update",(t=>{e.drawOperation.numCommittedVertices>0&&this.emit("create",{graphic:l(e.graphic),state:"active",tool:this.activeTool,toolEventInfo:{coordinates:t.vertices[0].coordinates,type:"cursor-update"},type:"create"})})),e.on("vertex-remove",(t=>{switch(t.operation){case"apply":this.emit("create",{graphic:l(e.graphic),state:"active",tool:this.activeTool,toolEventInfo:t,type:"create"});break;case"undo":this._emitUndoEvent({graphics:[l(e.graphic)],tool:e.geometryType});break;case"redo":this._emitRedoEvent({graphics:[l(e.graphic)],tool:e.geometryType})}})),e.on("complete",(e=>{this._set("createGraphic",l(e.graphic)),t="complete",e.aborted?r&&r.cancel():r&&r.complete()})),v((()=>this._getGraphicSymbolFromTool(e.geometryType)),(t=>{e.graphicSymbol=t}))],r=new Z({activeComponent:e,tool:e.geometryType,type:"create",onEnd:()=>{a.forEach((e=>e.remove())),a.length=0,this.view.tools?.remove(e)},undo:()=>{e.canUndo&&e.undo()},redo:()=>{e.canRedo&&e.redo()},canUndo:()=>e.canUndo,canRedo:()=>e.canRedo});return r}_getGraphicSymbolFromTool(e){switch(e){case"point":case"multipoint":return this.pointSymbol;case"polyline":return this.polylineSymbol;case"circle":case"rectangle":case"polygon":return this.polygonSymbol;default:return null}}async _setupUpdateOperation(e,t){const{layer:o,view:i}=this,a={tool:this._defaultUpdateTool,...this.defaultUpdateOptions,...t,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions,...t?.reshapeOptions}};let r=a.tool;for(const s of e)o.remove(s),o.add(s);if("3d"===i.type){if(0===e.length)return null;switch(r){case"move":return this._setupMove3DOperation(e,a,i,r);case"reshape":{if(e.length>1)return this._logError("sketch:reshape-multiple","Reshape operation does not support multiple graphics."),null;const t=M(e[0]);return t===I.SUPPORTED?this._setupReshape3DOperation(e[0],a,i):(this._logError("sketch:reshape",`Reshape operation not supported for provided graphic(s) (${R(t)}).`),null)}case"transform":return this._setupGraphicTransform3DOperation(e,a,i)}}switch(r){case"move":return this._setupMove2DOperation(e,a,i);case"reshape":{if(e.length>1)return this._logError("sketch:reshape-multiple","Reshape operation does not support multiple graphics."),null;const t=M(e[0]);return t===I.SUPPORTED?this._setupTransformOrReshape2DOperation(e,r,a,i):(this._logError("sketch:reshape",`Reshape operation not supported for provided graphic(s) (${R(t)}).`),null)}case"transform":if(1===e.length){const t=u(e[0].geometry,"type");"point"!==t&&"multipoint"!==t||(r="reshape")}return this._setupTransformOrReshape2DOperation(e,r,a,i)}}async _setupMove3DOperation(e,t,o,i,a=!1){for(const l of e){const e=D(l);if(e!==I.SUPPORTED)return this._logError("sketch:move",`Move operation not supported for provided graphic(s) (${R(e)}).`),null}const r=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(ae(r))return r;const s=new r.module.GraphicMoveTool({view:o,enableZ:t.enableZ,snappingManager:this._snappingManager,tooltipOptions:this.tooltipOptions});this.view.tools.add(s),s.graphics.addMany(e),a||this.updateGraphics.addMany(e);const n=[],p=new z({activeComponent:s,tool:i,type:"update",onEnd:()=>{n.forEach((e=>e.remove())),n.length=0,this.view.tools?.remove(s),s.destroyed||s.destroy()},undo:()=>{ee(p,this.updateGraphics.toArray()),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:i})},redo:()=>{te(p,this.updateGraphics.toArray()),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:i})},addToSelection:e=>{this.updateGraphics.push(e),s.graphics.push(e),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:"selection-change"},type:"update"})},removeFromSelection:e=>{const t=this.updateGraphics.indexOf(e);p.history.undo.forEach((e=>e.updates.splice(t,1))),p.history.redo.forEach((e=>e.updates.splice(t,1))),this.updateGraphics.remove(e),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:"selection-change"},type:"update"}),0!==this.updateGraphics.length?s.graphics.remove(e):p.complete()},toggleTool:async()=>{if(1!==this.updateGraphics.length||!1===t.toggleToolOnClick)return;if("transform"!==i)return;const e=this.updateGraphics.getItemAt(0);if(M(e)!==I.SUPPORTED)return;const a=await this._setupReshape3DOperation(e,t,o,!0);ae(a)||(p.onEnd(),p.destroy(),this._setUpdateOperationHandle(a,t))}});return n.push(...this._getHandlesForComponent(p,t),this.view.on("immediate-click",(e=>this._getCommonUpdateOperationClickHandlers(p,e,t)),x.WIDGET),o.on("key-down",(e=>{this._getCommonUpdateOperationKeyDownHandlers(p,e),e.key===j.snappingToggle&&(this.snappingOptions.enabledToggled=!0,e.stopPropagation())}),x.WIDGET),o.on("key-up",(e=>{e.key===j.snappingToggle&&(this.snappingOptions.enabledToggled=!1,e.stopPropagation())}),x.WIDGET)),p}_setupGraphicTransform3DOperation(e,t,o,i=!1){if(1===e.length&&U(e[0])===I.SUPPORTED){const a=e[0],r=a.geometry;if(p(r)&&("point"===r.type||"mesh"===r.type))return this._setupPointTransform3DOperation(a,t,o);if(p(r)&&("polygon"===r.type||"polyline"===r.type))return this._setupPolyTransform3DOperation(a,t,o,i)}return this._setupMove3DOperation(e,t,o,"transform",i)}async _setupPointTransform3DOperation(e,t,o){const i="transform",{enableRotation:a,enableScaling:r,enableZ:s}=t,n=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(ae(n))return n;const p=new n.module.GraphicTransformTool({graphic:e,view:o,enableRotation:a,enableScaling:r,enableZ:s,snappingManager:this._snappingManager,tooltipOptions:this.tooltipOptions});this.view.tools.add(p),this.updateGraphics.add(e);const l=[],h=new z({activeComponent:p,tool:i,type:"update",onEnd:()=>{l.forEach((e=>e.remove())),l.length=0,this.view.tools?.remove(p),p.destroyed||p.destroy()},undo:()=>{ee(h,this.updateGraphics.toArray()),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:i})},redo:()=>{te(h,this.updateGraphics.toArray()),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:i})},addToSelection:async e=>{this.updateGraphics.add(e),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:"selection-change"},type:"update"});const i=await this._setupMove3DOperation(this.updateGraphics.toArray(),t,o,"transform",!0);ae(i)||(h.onEnd(),h.destroy(),this._setUpdateOperationHandle(i,t))},removeFromSelection:e=>{this.updateGraphics.remove(e),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:"selection-change"},type:"update"}),h.complete()},toggleTool:()=>{}});return l.push(...this._getHandlesForComponent(h,t),this.view.on("immediate-click",(e=>this._getCommonUpdateOperationClickHandlers(h,e,t)),x.WIDGET),o.on("key-down",(e=>{this._getCommonUpdateOperationKeyDownHandlers(h,e),e.key===j.snappingToggle&&(this.snappingOptions.enabledToggled=!0,e.stopPropagation())}),x.WIDGET),o.on("key-up",(e=>{e.key===j.snappingToggle&&(this.snappingOptions.enabledToggled=!1,e.stopPropagation())}),x.WIDGET)),h}async _setupPolyTransform3DOperation(e,t,o,i=!1){const a="transform",{enableRotation:r,enableScaling:s,enableZ:n,preserveAspectRatio:p}=t,l=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(ae(l))return l;const h=new l.module.ExtentTransformTool({graphic:e,view:o,enableRotation:r,enableScaling:s,enableZ:n,preserveAspectRatio:p,tooltipOptions:this.tooltipOptions});this.view.tools.add(h),i||this.updateGraphics.add(e);const c=[],d=new z({activeComponent:h,tool:a,type:"update",onEnd:()=>{c.forEach((e=>e.remove())),c.length=0,this.view.tools?.remove(h),h.destroyed||h.destroy()},canUndo:()=>h.canUndo,undo:()=>{h.undo(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:a})},canRedo:()=>h.canRedo,redo:()=>{h.redo(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:a})},addToSelection:async e=>{this.updateGraphics.add(e),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:"selection-change"},type:"update"});const i=await this._setupMove3DOperation(this.updateGraphics.toArray(),t,o,"transform",!0);ae(i)||(d.onEnd(),d.destroy(),this._setUpdateOperationHandle(i,t))},removeFromSelection:e=>{this.updateGraphics.remove(e),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:"selection-change"},type:"update"}),d.complete()},toggleTool:async()=>{if(1!==this.updateGraphics.length||!1===t.toggleToolOnClick)return;const e=this.updateGraphics.getItemAt(0);if(M(e)!==I.SUPPORTED)return;const i=await this._setupReshape3DOperation(e,t,o,!0);ae(i)||(d.onEnd(),d.destroy(),this._setUpdateOperationHandle(i,t))}});return c.push(...this._getHandlesForComponent(d,t),this.view.on("immediate-click",(e=>this._getCommonUpdateOperationClickHandlers(d,e,t)),x.WIDGET),this.view.on("key-down",(e=>this._getCommonUpdateOperationKeyDownHandlers(d,e)),x.WIDGET),this.view.on("key-down",(e=>{e.key!==j.constraint||e.repeat||(h.preserveAspectRatio=!h.preserveAspectRatio,e.stopPropagation())}),x.WIDGET),this.view.on("key-up",(e=>{e.key===j.constraint&&(h.preserveAspectRatio=!h.preserveAspectRatio,e.stopPropagation())}),x.WIDGET)),d}async _setupMove2DOperation(e,t,o){const i="move";this.updateGraphics.addMany(e),await this._updateSpatialReference(e);const a=await this._getGraphicMover(e,t,o);if(ae(a))return a;const r=new z({activeComponent:a,tool:i,type:"update",onEnd:()=>{this._displayDefaultCursor(),p.forEach((e=>e.remove())),n.forEach((e=>e.remove())),p=[],n=[],a.destroy(),this._internalGraphicsLayer?.removeMany([...this.updateGraphics.toArray()])},undo:()=>{const e=this.updateGraphics.toArray();ee(r,e),r.refreshComponent(),this._emitUndoEvent({graphics:e,tool:i})},redo:()=>{const e=this.updateGraphics.toArray();te(r,e),r.refreshComponent(),this._emitRedoEvent({graphics:e,tool:i})},addToSelection:async e=>{await this._updateSpatialReference(e),this.updateGraphics.push(e),a.graphics=this.updateGraphics.toArray(),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:"selection-change"},type:"update"})},removeFromSelection:e=>{const t=this.updateGraphics.indexOf(e);r.history.undo.forEach((e=>e.updates.splice(t,1))),r.history.redo.forEach((e=>e.updates.splice(t,1))),this.updateGraphics.remove(e);const o=this.updateGraphics.toArray();this.emit("update",{graphics:o,state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:"selection-change"},type:"update"}),0!==this.updateGraphics.length?a.graphics=o:r.complete()}});let s=!1,n=[o.on("immediate-click",(e=>this._getCommonUpdateOperationClickHandlers(r,e,t)),x.WIDGET),o.on("key-down",(e=>{this._getCommonUpdateOperationKeyDownHandlers(r,e),e.key!==j.constraint||e.repeat||(s=!0,a.enableMoveAllGraphics=!a.enableMoveAllGraphics)}),x.WIDGET),o.on("key-up",(e=>{e.key===j.constraint&&s&&(s=!1,a.enableMoveAllGraphics=!a.enableMoveAllGraphics)}),x.WIDGET)],p=this._getHandlesForComponent(r,t);return r}async _setupReshape3DOperation(e,t,o,i=!1){const a="reshape",r=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(ae(r))return r;this.snappingOptions.enabledToggled=!1;const s=new r.module.GraphicReshapeTool({view:o,graphic:e,enableZVertex:t.enableZ&&"move"===t.reshapeOptions.vertexOperation,enableZShape:t.enableZ&&"move"===t.reshapeOptions.shapeOperation,enableMoveGraphic:"move"===t.reshapeOptions.shapeOperation||"move-xy"===t.reshapeOptions.shapeOperation,enableMidpoints:"split"===t.reshapeOptions.edgeOperation,enableEdgeOffset:"offset"===t.reshapeOptions.edgeOperation,snappingManager:this._snappingManager,labelOptions:this.labelOptions,tooltipOptions:this.tooltipOptions});o.tools.add(s),i||this.updateGraphics.add(e);const n=[],p=new z({activeComponent:s,tool:a,type:"update",onEnd:()=>{n.forEach((e=>e.remove())),n.length=0,this.view.tools?.remove(s),s.destroyed||s.destroy()},canUndo:()=>s.canUndo,undo:()=>{s.undo(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:a})},canRedo:()=>s.canRedo,redo:()=>{s.redo(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:a})},addToSelection:async e=>{this.updateGraphics.add(e),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:"selection-change"},type:"update"});const i=await this._setupMove3DOperation(this.updateGraphics.toArray(),t,o,"transform",!0);ae(i)||(p.onEnd(),p.destroy(),this._setUpdateOperationHandle(i,t))},removeFromSelection:e=>{this.updateGraphics.remove(e),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:"selection-change"},type:"update"}),p.complete()},toggleTool:async()=>{if(!1===t.toggleToolOnClick)return;const e=await this._setupGraphicTransform3DOperation(this.updateGraphics.toArray(),t,o,!0);ae(e)||(p.onEnd(),p.destroy(),this._setUpdateOperationHandle(e,t))}});return n.push(...this._getHandlesForComponent(p,t),o.on("immediate-click",(e=>this._getCommonUpdateOperationClickHandlers(p,e,t)),x.WIDGET),o.on("key-down",(e=>{this._getCommonUpdateOperationKeyDownHandlers(p,e),e.key===j.snappingToggle&&(this.snappingOptions.enabledToggled=!0,e.stopPropagation())}),x.WIDGET),o.on("key-up",(e=>{e.key===j.snappingToggle&&(this.snappingOptions.enabledToggled=!1,e.stopPropagation())}),x.WIDGET)),p}async _setupTransformOrReshape2DOperation(e,t,o,i){this.updateGraphics.addMany(e),await this._updateSpatialReference(e);const a="transform"===t?await this._getBox(e,o,i):await this._getReshape(e,o,i);if(ae(a))return a;const r=new z({activeComponent:a,type:"update",onEnd:()=>{n.forEach((e=>e.remove())),s.forEach((e=>e.remove())),n=[],s=[],r.activeComponent&&!r.activeComponent.destroyed&&r.activeComponent.destroy(),this._internalGraphicsLayer.removeMany(this.updateGraphics.toArray())},undo:()=>{ee(r,this.updateGraphics.toArray()),r.refreshComponent(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:r.tool})},redo:()=>{te(r,this.updateGraphics.toArray()),r.refreshComponent(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:r.tool})},addToSelection:async e=>{let t=r.activeComponent;if("reshape"===t.type){const t=[...this.updateGraphics,e];this.updateGraphics.removeAll();const a=await this._setupMove2DOperation(t,o,i);if(ae(a))return;r.onEnd(),r.destroy(),this._setUpdateOperationHandle(a,o)}else this.updateGraphics.add(e),t.graphics=this.updateGraphics.toArray(),t.refresh(),r.resetHistory();this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:"selection-change"},type:"update"})},removeFromSelection:async e=>{const t=this.updateGraphics.indexOf(e);r.history.undo.forEach((e=>e.updates.splice(t,1))),r.history.redo.forEach((e=>e.updates.splice(t,1))),this.updateGraphics.remove(e);const o=this.updateGraphics.toArray();if(0===o.length)r.complete();else{const e=o[0].geometry;1!==o.length||!p(e)||"point"!==e.type&&"multipoint"!==e.type?r.activeComponent.graphics=o:r.toggleTool()}this.emit("update",{graphics:o,state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:"selection-change"},type:"update"})},toggleTool:async()=>{if(this.updateGraphics.length>1)return;const e=this.updateGraphics.getItemAt(0),t=e.geometry;if(p(t)&&("reshape"===r.tool&&("point"===t.type||"multipoint"===t.type)||"transform"===r.tool&&"extent"===t.type))return;let a=null;"transform"===r.tool?a=await this._getReshape([e],o,i):"reshape"===r.tool&&(a=await this._getBox([e],o,i)),ae(a)||(r.activeComponent.destroy(),r.activeComponent=a,r.activeComponent&&(n.forEach((e=>e.remove())),n=this._getHandlesForComponent(r,o)))}});let s=[i.on("immediate-click",(e=>this._getCommonUpdateOperationClickHandlers(r,e,o)),x.WIDGET),i.on("key-down",(e=>{if(this._getCommonUpdateOperationKeyDownHandlers(r,e),e.key!==j.snappingToggle||e.repeat||(this.snappingOptions.enabledToggled=!0,e.stopPropagation()),e.key===j.constraint&&!e.repeat&&r){const e=r.activeComponent;e&&"box"===e.type&&(e.preserveAspectRatio=!e.preserveAspectRatio)}}),x.WIDGET),i.on("key-up",(e=>{if(e.key===j.snappingToggle&&"reshape"===r?.activeComponent?.type&&(this.snappingOptions.enabledToggled=!1,e.stopPropagation()),e.key===j.constraint&&r){const e=r.activeComponent;e&&"box"===e.type&&(e.preserveAspectRatio=!e.preserveAspectRatio)}}),x.WIDGET)],n=this._getHandlesForComponent(r,o);return r}async _getGraphicMover(e,t,o){const{enableMoveAllGraphics:i}=t,a=await this._requireModule(import("../../views/draw/support/GraphicMover.js"));return ae(a)?a:new a.module.default({enableMoveAllGraphics:i,highlightsEnabled:!0,indicatorsEnabled:!1,graphics:e,view:o,callbacks:{onGraphicMoveStart:({dx:e,dy:t,graphic:o})=>{this._displayGrabbingCursor(),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:o,type:"move-start"},type:"update"})},onGraphicMove:({dx:e,dy:t,graphic:o})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:o,type:"move"},type:"update"}),onGraphicMoveStop:({dx:e,dy:t,graphic:o})=>{this._displayPointerCursor(),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:o,type:"move-stop"},type:"update"})},onGraphicPointerOver:()=>this._displayPointerCursor(),onGraphicPointerOut:()=>this._displayDefaultCursor()}})}async _getBox(e,t,o){const{enableRotation:i,enableScaling:a,preserveAspectRatio:r}=t,s=await this._requireModule(import("../../views/draw/support/Box.js"));return ae(s)?s:new s.module.default({graphics:e,enableRotation:i,enableScaling:a,preserveAspectRatio:r,layer:this._internalGraphicsLayer,view:o,tooltipOptions:this.tooltipOptions,callbacks:{onMoveStart:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onMove:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onMoveStop:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onScaleStart:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onScale:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onScaleStop:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onRotateStart:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onRotate:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onRotateStop:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"})}})}async _getReshape(e,t,o){const i="split"===t.reshapeOptions?.edgeOperation,a="move"===t.reshapeOptions?.shapeOperation,r=await this._requireModule(import("../../views/draw/support/Reshape.js"));return ae(r)?r:new r.module.default({enableMidpoints:i,enableMovement:a,graphic:e[0],layer:this._internalGraphicsLayer,snappingManager:this._snappingManager,tooltipOptions:this.tooltipOptions,view:o,callbacks:{onReshapeStart:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onReshape:e=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:"update"}),onReshapeStop:({mover:e,type:t})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e,type:t},type:"update"}),onMoveStart:({dx:e,dy:t,mover:o,type:i})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:o,type:i},type:"update"}),onMove:({dx:e,dy:t,mover:o,type:i})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:o,type:i},type:"update"}),onMoveStop:({dx:e,dy:t,mover:o,type:i})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:o,type:i},type:"update"}),onVertexAdd:({added:e,type:t,vertices:o})=>{const i=e.map((e=>k(e.geometry)));this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:i,vertices:o,type:t},type:"update"})},onVertexRemove:({removed:e,type:t,vertices:o})=>{const i=e.map((e=>k(e.geometry)));this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{removed:i,vertices:o,type:t},type:"update"})}}})}_getHandlesForComponent(e,t){const o=e.activeComponent;switch(o.type){case"graphic-mover":return[o.on("graphic-click",(({graphic:t,viewEvent:o})=>{o.native?.shiftKey&&(o.stopPropagation(),e.removeFromSelection(t))})),o.on("graphic-move-start",(t=>e.addToHistory(ie(t.allGraphics))))];case"box":return[o.on("graphic-click",(o=>this._onTransformOrReshape2DGraphicClick(e,t,o))),o.on("move-start",(t=>e.addToHistory(ie(t.graphics)))),o.on("rotate-start",(t=>e.addToHistory(ie(t.graphics)))),o.on("scale-start",(t=>e.addToHistory(ie(t.graphics))))];case"reshape":return[o.on("graphic-click",(o=>this._onTransformOrReshape2DGraphicClick(e,t,o))),o.on("move-start",(t=>e.addToHistory(ie([t.mover])))),o.on("reshape-start",(t=>e.addToHistory(ie([t.graphic])))),o.on("vertex-add",(t=>e.addToHistory(ie([t.oldGraphic])))),o.on("vertex-remove",(t=>e.addToHistory(ie([t.oldGraphic]))))];case"move-3d":return[o.on("graphic-move-start",(t=>{e.addToHistory(ie(t.allGraphics)),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:0,dy:0,mover:t.allGraphics.length>0?t.allGraphics[0]:null,type:"move-start"},type:"update"})})),o.on("graphic-move",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e.dx,dy:e.dy,mover:e.allGraphics.length>0?e.allGraphics[0]:null,type:"move"},type:"update"})})),o.on("graphic-move-stop",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:0,dy:0,mover:e.allGraphics.length>0?e.allGraphics[0]:null,type:"move-stop"},type:"update"})})),o.on("immediate-click",(o=>{o.shiftKey?this._toggleSelection([o.graphic],e,t):e.toggleTool()}))];case"transform-3d":return[o.on("record-undo",(({record:t})=>{e.addToHistory({updates:[t]})})),o.on("graphic-translate-start",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,dx:e.dxScreen,dy:e.dyScreen,type:"move-start"},type:"update"})})),o.on("graphic-translate-stop",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,dx:e.dxScreen,dy:e.dyScreen,type:"move-stop"},type:"update"})})),o.on("graphic-rotate-start",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,angle:e.angle,type:"rotate-start"},type:"update"})})),o.on("graphic-rotate-stop",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,angle:e.angle,type:"rotate-stop"},type:"update"})})),o.on("graphic-scale-start",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,xScale:e.xScale,yScale:e.yScale,type:"scale-start"},type:"update"})})),o.on("graphic-scale-stop",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,xScale:e.xScale,yScale:e.yScale,type:"scale-stop"},type:"update"})})),o.on("graphic-translate",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,dx:e.dxScreen,dy:e.dyScreen,type:"move"},type:"update"})})),o.on("graphic-rotate",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,angle:e.angle,type:"rotate"},type:"update"})})),o.on("graphic-scale",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.graphic,xScale:e.xScale,yScale:e.yScale,type:"scale"},type:"update"})})),o.on("immediate-click",(o=>{o.shiftKey?this._toggleSelection([o.graphic],e,t):e.toggleTool()}))];case"reshape-3d":return[o.on("reshape",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:e,type:"update"})})),o.on("move",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:e,type:"update"})})),o.on("vertex-add",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:e,type:"update"})})),o.on("vertex-remove",(e=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:e,type:"update"})})),o.on("immediate-click",(o=>{o.shiftKey?this._toggleSelection([o.graphic],e,t):e.toggleTool()}))];default:return}}_onTransformOrReshape2DGraphicClick(e,t,o){const{graphic:i,viewEvent:a}=o;return a.native?.shiftKey&&i.layer===this.layer?(a.stopPropagation(),e.removeFromSelection(i)):t.toggleToolOnClick?(a.stopPropagation(),e.toggleTool()):void 0}_setUpdateOperationHandle(e,t){this._operationHandle=e;const o=this.view.map;this._disablePopup(t);const i=()=>{if(e===this._operationHandle){const i=this.updateGraphics.toArray(),a=this._operationHandle.tool;this._operationHandle.destroy(),this._operationHandle=null,this._internalGraphicsLayer.removeMany(this.updateGraphics.toArray()),this.updateGraphics.removeAll(),o&&o.remove(this._internalGraphicsLayer),this._restorePopup(t),this.emit("update",{graphics:i,state:"complete",aborted:e.cancelled,tool:a,toolEventInfo:null,type:"update"})}};e.on("complete",i)}async _getCommonUpdateOperationClickHandlers(e,t,o){const i=q(t),a=await t.async((()=>this._getFirstHit(i)));if(c(a))return void e.complete();if(t.native.shiftKey&&this._toggleSelection([a.graphic],e,o))return void t.stopPropagation();this.updateGraphics.includes(a.graphic)?t.stopPropagation():e.complete()}_toggleSelection(e,t,o){const i=!!o.multipleSelectionEnabled;return e.some((e=>null!=e&&(!(!i||e.layer!==this.layer)&&(this.updateGraphics.includes(e)?t.removeFromSelection(e):t.addToSelection(e),!0))))}_getCommonUpdateOperationKeyDownHandlers(e,t){if(!e)return;const o=t.key;o===j.undo&&e.canUndo()?(t.stopPropagation(),e.undo()):o===j.redo&&e.canRedo()?(t.stopPropagation(),e.redo()):o===j.cancel?(t.stopPropagation(),e.cancel()):this.allowDeleteKey&&j.delete.includes(o)&&this._onDeleteKey(t)}_onDeleteKey(e){if(!this._operationHandle||"update"!==this._operationHandle.type)return;const t=this.activeComponent,o=this.updateGraphics.toArray();c(t)||"reshape-3d"===t.type||("reshape"!==t.type||1===o.length&&"point"===u(o[0].geometry,"type"))&&(e.stopPropagation(),this.delete())}_removeDefaultLayer(){this._internalGraphicsLayer&&(this.view&&this.view.map&&this.view.map.remove(this._internalGraphicsLayer),this._internalGraphicsLayer=n(this._internalGraphicsLayer))}_isComponentGraphic(e){const{activeComponent:t}=this;return!(!e||c(t))&&(e.attributes&&e.attributes.esriSketchTool||"draw-2d"===t.type&&t.graphic===e||("box"===t.type||"reshape"===t.type)&&t.isUIGraphic(e))}_displayPointerCursor(){this.view&&this.view.container&&"pointer"!==this.view.cursor&&(this.view.cursor="pointer")}_displayGrabbingCursor(){this.view&&this.view.container&&"grabbing"!==this.view.cursor&&(this.view.cursor="grabbing")}_displayDefaultCursor(){this.view&&this.view.container&&null!==this.view.cursor&&(this.view.cursor=null)}_logError(e,t,o){s.getLogger(this.declaredClass).error(new i(e,t,o))}async _requireModule(e){const t=new AbortController;this._moduleLoaderAbortController=t;const o=await e;return this._moduleLoaderAbortController!==t||t.signal.aborted?{requireError:"aborted"}:{module:o}}_emitUndoEvent(e){this.emit("undo",{...e,type:"undo"})}_emitRedoEvent(e){this.emit("redo",{...e,type:"redo"})}_emitDeleteEvent(e){this.emit("delete",{...e,type:"delete"})}get test(){return{operationHandle:this._operationHandle,defaultUpdateOptions:J}}wait(){return _((()=>!this.updating))}_beginAsyncOperation(){this._numUpdating+=1,this.notifyChange("updating")}_endAsyncOperation(){this._numUpdating-=1,this.notifyChange("updating")}_disablePopupEnabled(e){return"3d"!==this.view?.type||this.updateOnGraphicClick||p(e)&&e.toggleToolOnClick}_disablePopup(e){if(!this._disablePopupEnabled(e))return;const t=this.view.popup;t&&c(this._originalAutoOpenEnabled)&&(this._originalAutoOpenEnabled=t.autoOpenEnabled,t.autoOpenEnabled=!1)}_restorePopup(e){if(!this._disablePopupEnabled(e))return;const t=this.view.popup;t&&p(this._originalAutoOpenEnabled)&&(t.autoOpenEnabled=this._originalAutoOpenEnabled,this._originalAutoOpenEnabled=null)}async _waitViewReady(){const e=this.view;e&&(h(this._viewReadyAbortController),this._viewReadyAbortController=new AbortController,await m(_((()=>e?.ready)),this._viewReadyAbortController.signal))}};function X(e){return"polygon"===e||"rectangle"===e||"circle"===e}function ee(e,t){oe("undo",e.history.undo,e.history.redo,t)}function te(e,t){oe("redo",e.history.redo,e.history.undo,t)}function oe(e,t,o,i){const a=t.pop().updates,r=[];i.forEach(((t,o)=>{const i=a[o];null!=i&&("geometry"in i&&p(i.geometry)&&(r.push({geometry:t.geometry}),t.geometry=i.geometry),"symbol"in i&&p(i.symbol)&&(r.push({symbol:t.symbol}),t.symbol=i.symbol),"undo"in i&&(r.push(i),i[e](t)))})),o.push({updates:r})}function ie(e){return{updates:e.map((e=>({geometry:e.geometry})))}}function ae(e){return"requireError"in e&&"aborted"===e.requireError}e([b()],Q.prototype,"updating",null),e([b()],Q.prototype,"_operationHandle",void 0),e([b({readOnly:!0})],Q.prototype,"activeTool",null),e([b()],Q.prototype,"activeFillSymbol",void 0),e([b()],Q.prototype,"activeLineSymbol",void 0),e([b()],Q.prototype,"activeVertexSymbol",void 0),e([b()],Q.prototype,"allowDeleteKey",void 0),e([b({readOnly:!0})],Q.prototype,"createGraphic",null),e([b()],Q.prototype,"defaultCreateOptions",null),e([b()],Q.prototype,"defaultUpdateOptions",null),e([b({type:L,nonNullable:!0})],Q.prototype,"labelOptions",void 0),e([b()],Q.prototype,"layer",void 0),e([b({types:t})],Q.prototype,"pointSymbol",void 0),e([b({types:t})],Q.prototype,"polygonSymbol",void 0),e([b({types:t})],Q.prototype,"polylineSymbol",void 0),e([b({type:W,nonNullable:!0})],Q.prototype,"snappingOptions",null),e([b()],Q.prototype,"_snappingManager",void 0),e([b({readOnly:!0})],Q.prototype,"state",null),e([b({type:F,nonNullable:!0})],Q.prototype,"tooltipOptions",void 0),e([b({readOnly:!0})],Q.prototype,"updateGraphics",void 0),e([b()],Q.prototype,"updateOnGraphicClick",void 0),e([b({types:t})],Q.prototype,"updatePointSymbol",void 0),e([b({types:t})],Q.prototype,"updatePolygonSymbol",void 0),e([b({types:t})],Q.prototype,"updatePolylineSymbol",void 0),e([b({types:t})],Q.prototype,"vertexSymbol",void 0),e([b({value:null})],Q.prototype,"view",null),Q=e([G("esri.widgets.Sketch.SketchViewModel")],Q);const re=Q;export{re as default};