@arcgis/core 5.0.0-next.130 → 5.0.0-next.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/applications/Components/OrientedImageryViewer/galleryUtils.d.ts +45 -15
- package/applications/Components/QuantityFormatter.d.ts +11 -11
- package/applications/Components/SelectionOperation.d.ts +11 -11
- package/applications/Components/SketchTooltipControls.d.ts +9 -9
- package/applications/Components/actionUtils.d.ts +2 -1
- package/applications/Components/analysisUtils.d.ts +27 -26
- package/applications/Components/applySetUtils.d.ts +40 -40
- package/applications/Components/arcadeEditorUtils.d.ts +3 -3
- package/applications/Components/arcadeFeatureUtils.d.ts +12 -12
- package/applications/Components/baUtils.d.ts +8 -8
- package/applications/Components/basemapUtils.d.ts +2 -2
- package/applications/Components/clipboard.d.ts +14 -14
- package/applications/Components/drawUtils.d.ts +3 -3
- package/applications/Components/editUtils.d.ts +14 -14
- package/applications/Components/featureUtils.d.ts +10 -10
- package/applications/Components/fieldFormatUtils.d.ts +2 -2
- package/applications/Components/fontUtils.d.ts +2 -2
- package/applications/Components/formatUtils.d.ts +2 -2
- package/applications/Components/getDefaultUnits.d.ts +2 -2
- package/applications/Components/gfxUtils.d.ts +5 -1
- package/applications/Components/imageryUtils.d.ts +35 -35
- package/applications/Components/layerOriginUtils.d.ts +5 -5
- package/applications/Components/layersEffectsJsonUtils.d.ts +2 -2
- package/applications/Components/previewSymbol2D.d.ts +2 -2
- package/applications/Components/rasterFunctionEditorUtils.d.ts +40 -40
- package/applications/Components/reactiveUtils.d.ts +14 -13
- package/applications/Components/sanitizerUtils.d.ts +2 -2
- package/applications/Components/stringUtils.d.ts +5 -5
- package/applications/Components/styleUtils.d.ts +2 -2
- package/applications/Components/svgUtils.d.ts +4 -4
- package/applications/Components/symbolUtils.d.ts +47 -11
- package/applications/Components/templateUtils.d.ts +73 -17
- package/applications/Components/templateUtils.js +1 -1
- package/applications/Components/testUtils.d.ts +3 -3
- package/applications/Components/unitUtils.d.ts +1 -1
- package/applications/Components/viewUtils.d.ts +2 -2
- package/applications/Components/webStyleSymbolUtils.d.ts +2 -2
- package/applications/Excalibur/imageryLayerUtils.d.ts +3 -3
- package/applications/Excalibur/videoViewUtils.d.ts +8 -8
- package/applications/Excalibur/widgetUtils.d.ts +2 -2
- package/applications/ExperienceBuilder/sketchUtils.d.ts +7 -7
- package/applications/KnowledgeStudio/dataModelVisualization.d.ts +20 -8
- package/applications/KnowledgeStudio/generalSdkInternalAccess.d.ts +21 -21
- package/applications/KnowledgeStudio/generalSharedKgUtils.d.ts +35 -35
- package/applications/KnowledgeStudio/layerInternalAccessUtils.d.ts +9 -9
- package/applications/KnowledgeStudio/reshape.d.ts +40 -40
- package/applications/KnowledgeStudio/resourceSerializationUtils.d.ts +11 -11
- package/applications/MapViewer/layerUtils.d.ts +2 -2
- package/applications/MapViewer/mediaUtils.d.ts +13 -13
- package/applications/MapViewer/templateUtils.d.ts +20 -20
- package/applications/PortalApp/layerUtils.d.ts +2 -2
- package/applications/SceneViewer/colorUtils.d.ts +2 -2
- package/applications/SceneViewer/devEnvironmentUtils.d.ts +4 -3
- package/applications/SceneViewer/layerUtils.d.ts +3 -3
- package/applications/SceneViewer/sceneViewerUtils.d.ts +34 -34
- package/applications/SceneViewer/symbolUtils.d.ts +2 -2
- package/applications/Urban/LineImagePattern3D.d.ts +3 -2
- package/applications/Urban/imagePatternUtils.d.ts +4 -4
- package/applications/Urban/meshUtils.d.ts +2 -2
- package/applications/WebEditor/sketchUtils.d.ts +8 -8
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/1dcd057695f8db79eca2.js +1 -0
- package/assets/esri/core/workers/chunks/1f3074ab4dc6e2eff97e.js +1 -0
- package/assets/esri/core/workers/chunks/{5746140c33cb206ad4b8.js → 22181db586c6ccbcb279.js} +1 -1
- package/assets/esri/core/workers/chunks/58ef550435cef99d99ff.js +1 -0
- package/assets/esri/core/workers/chunks/{56e3c34ebdee61ff4b33.js → 75bf83c6367227712a11.js} +1 -1
- package/assets/esri/core/workers/chunks/844771d532b5352dc848.js +1 -0
- package/assets/esri/core/workers/chunks/{9332db133a0925d522fe.js → b9c9dd3621b92212b104.js} +1 -1
- package/assets/esri/core/workers/chunks/c3e4f8664988e50bda55.js +1 -0
- package/assets/esri/core/workers/chunks/cf100c80b75ba74b479c.js +1 -0
- package/assets/esri/core/workers/chunks/ef8cc520d3977759b80c.js +1 -0
- package/config.js +1 -1
- package/geometry/support/curves/curveUtils.js +1 -1
- package/geometry/support/curves/densifyCurvedGeometry.js +1 -1
- package/graphic/graphicOriginUtils.js +1 -1
- package/kernel.js +1 -1
- package/layers/WMTSLayer.js +1 -1
- package/layers/graphics/editingSupport.js +1 -1
- package/layers/support/Sublayer.d.ts +3 -0
- package/package.json +1 -1
- package/rest/featureService/FeatureService.js +1 -1
- package/smartMapping/support/utils.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/cim/GeometryWalker.js +1 -1
- package/symbols/cim/effects/EffectDashes.js +1 -1
- package/symbols/cim/placements/PlacementAlongLineSameSize.js +1 -1
- package/symbols/cim/placements/PlacementAtRatioPositions.js +1 -1
- package/symbols/cim/rasterizingUtils.js +1 -1
- package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
- package/views/View.d.ts +13 -2
- package/views/draw/support/Reshape.js +1 -1
- package/views/draw/support/reshapeUtils.js +1 -1
- package/views/interactive/support/utils.js +1 -1
- package/widgets/Attribution/AttributionViewModel.d.ts +3 -1
- package/widgets/Attribution/AttributionViewModel.js +1 -1
- package/widgets/Attribution.d.ts +1 -1
- package/widgets/Attribution.js +1 -1
- package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
- package/widgets/Editor/EditorViewModel.d.ts +2 -22
- package/widgets/Editor/EditorViewModel.js +1 -1
- package/widgets/Editor/SplitFeatureWorkflow.js +1 -1
- package/widgets/Editor/UpdateWorkflow.js +1 -1
- package/widgets/Editor/Workflow.js +1 -1
- package/widgets/Editor/support/SketchController.js +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Editor.d.ts +10 -15
- package/widgets/Editor.js +1 -1
- package/widgets/FeatureTable/FeatureTableViewModel.d.ts +0 -15
- package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
- package/widgets/FeatureTable/support/types.d.ts +0 -1
- package/widgets/FeatureTable.d.ts +1 -19
- package/widgets/FeatureTable.js +1 -1
- package/widgets/HistogramRangeSlider.d.ts +1 -1
- package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
- package/widgets/OrientedImageryViewer/adapters/sketch/MeasurementAdapter.js +1 -1
- package/widgets/OrientedImageryViewer/adapters/view/MapViewAdapter.js +1 -1
- package/widgets/PanoramicVideoViewer.js +1 -1
- package/widgets/PanoramicViewer/PanoramicVideoViewerViewModel.js +1 -1
- package/widgets/PanoramicViewer/support/PanoramicMedia.js +1 -1
- package/widgets/PanoramicViewer/support/PanoramicTileNode.js +1 -1
- package/widgets/PanoramicViewer/support/PanoramicTilePyramid.js +1 -1
- package/widgets/PanoramicViewer/utils.js +1 -1
- package/widgets/Sketch/SketchViewModel.d.ts +4 -22
- package/widgets/Sketch/SketchViewModel.js +1 -1
- package/widgets/Sketch/support/PluginManager.js +1 -1
- package/widgets/Sketch.d.ts +10 -17
- package/widgets/Sketch.js +1 -1
- package/assets/esri/core/workers/chunks/5a8b3e5977c233d5c9d0.js +0 -1
- package/assets/esri/core/workers/chunks/71ad08a5b69cf2e6714e.js +0 -1
- package/assets/esri/core/workers/chunks/7ec83fc059325e207825.js +0 -1
- package/assets/esri/core/workers/chunks/a7d4d257f49f3b153c26.js +0 -1
- package/assets/esri/core/workers/chunks/bf2bfc0d78be8c185d58.js +0 -1
- package/assets/esri/core/workers/chunks/e081d6f21a2c01ccaf61.js +0 -1
- package/assets/esri/core/workers/chunks/eae1c098c16e2faaf90d.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import{isSome as t}from"../../core/arrayUtils.js";import{createTask as i}from"../../core/asyncUtils.js";import o from"../../core/Collection.js";import{deprecatedFunction as r}from"../../core/deprecate.js";import a from"../../core/Error.js";import{EventedAccessor as s}from"../../core/Evented.js";import{abortHandle as n,makeHandle as l}from"../../core/handleUtils.js";import"../../core/has.js";import c from"../../core/Logger.js";import{destroyMaybe as d,abortMaybe as p,removeMaybe as h}from"../../core/maybe.js";import{throwIfAborted as u,createResolver as w}from"../../core/promiseUtils.js";import f from"../../core/ReactiveMap.js";import{watch as m,syncAndInitial as y,initial as g,on as k,when as v,sync as _,whenOnce as W}from"../../core/reactiveUtils.js";import{property as M,subclass as T}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as F}from"../../core/support/UpdatingHandles.js";import{getTemplatesForLayers as b}from"../../editing/templateUtils.js";import{getGraphicLayer as V}from"../../graphic/graphicOriginUtils.js";import S from"../../layers/GraphicsLayer.js";import{isEditableLayer as I}from"../../layers/support/editableLayers.js";import{isFeatureLayer as L,isSubtypeGroupLayer as E,getOwningPortalUrl as A}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as C}from"../../portal/support/urlUtils.js";import U from"../../views/SelectionManager.js";import O from"../../views/interactive/sketch/SketchLabelOptions.js";import j from"../../views/interactive/sketch/SketchOptions.js";import R from"../../views/interactive/sketch/SketchTooltipOptions.js";import P from"../../views/interactive/sketch/SketchValueOptions.js";import{SnappingManager as H}from"../../views/interactive/snapping/SnappingManager.js";import q from"../../views/interactive/snapping/SnappingOptions.js";import{isISelectableLayer as x}from"../../views/support/selectionUtils.js";import G from"../Attachments/AttachmentsViewModel.js";import D from"./CreateFeaturesWorkflow.js";import B from"./UpdateWorkflow.js";import{getLayersFromWorkflow as N,isCreateFeaturesWorkflow as Q,isUpdateRecordWorkflow as z,isUpdateFeaturesWorkflow as Z,isMergeFeaturesWorkflow as $,isSplitFeatureWorkflow as J,isUpdateWorkflow as K,isFeatureFormViewModel as X,findEditorItemForLayerOrThrow as Y,toFeatureInfos as ee,fetchFullFeaturesByObjectId as te,fetchFullFeatures as ie,findEditorItemForLayer as oe,whenEditorLayerView as re,isBatchAttributeFormViewModel as ae}from"./workflowUtils.js";import se from"./support/EditorItem.js";import{assertViewNot3D as ne,MultipleSourceLayersError as le,InsufficientFeatureCountError as ce,MissingOriginLayerError as de,assertMergeWorkflowCapabilities as pe,FetchFullFeatureError as he,assertSplitWorkflowCapabilities as ue}from"./support/errors.js";import{makeTemplateGroupInfoForLayer as we}from"../FeatureTemplates/featureTemplatesUtils.js";import fe from"../FeatureTemplates/FeatureTemplatesViewModel.js";import me from"../Sketch/SketchViewModel.js";import ye from"../Spinner/SpinnerViewModel.js";import{goTo as ge}from"../support/goToUtils.js";import{isFeatureItem as ke,isLayerItem as ve}from"../support/SelectionList/selectionListUtils.js";import _e from"../support/SelectionList/SelectionListViewModel.js";import We from"../support/SelectionToolbar/SelectionToolbarViewModel.js";function Me(e,t){return e?.find(e=>e.layer===t)}let Te=class extends s{constructor(e){super(e),this._defaultSelectionManager=new U,this._queuedSelectionTool=null,this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new S({listMode:"hide",internal:!0,title:"Editor sketch layer"}),this._snappingManager=null,this._templatesByLayer=new Map,this._updateItemsTask=null,this._updateTemplatesTask=null,this._updatingHandles=new F,this._featureTemplatesViewModelIsRestricted=!1,this.activeWorkflow=null,this._activityQueue=new o,this.editorItems=new o,this.editorItemsLayerMap=new f,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new G({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new fe({disabledItemFunction:({layer:e})=>this._itemIsSuspended(e)}),this.layerInfos=null,this.useLegacyCreateTools=!0,this.ownSketchViewModel=new me({layer:this._sketchGraphicsLayer,useLegacyCreateTools:this.useLegacyCreateTools}),this.selectionListViewModel=new _e,this.selectionManager=null,this.selectionToolbarViewModel=new We({continuousSelectionEnabled:!0,defaultOperationType:"replace",persistSelection:!1,returnGeometry:!1}),this.sketchOptions=new j,this.snappingOptions=new q({attributeRulesEnabled:!0}),this.spinnerViewModel=new ye,this.syncViewSelection=!1,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{if("viewing-selection-list"===this.state)return this.selectionListViewModel.filterText=void 0,void this.effectiveSelectionManager.clear();this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>await(this.activeWorkflow?.save()),this.selectFeature=(e,t=!1)=>{const i=this.activeWorkflow;if(this._candidateCommitted||"update"!==i?.type)return;const{rootFeatures:o}=i.data;o.removeAll(),e&&o.add(e),t&&(i.next(),this._candidateCommitted=!0)}}initialize(){this.addHandles([m(()=>{const e=this.view,t=e?.map?.editableLayers.toArray(),i=e?.allLayerViews,o=i?.filter(e=>!!t?.includes(e.layer));return[t,o,this.layerInfos]},()=>this._updateEditorItems(),y),m(()=>this.hideTemplatesForInactiveLayers,()=>this.syncFeatureTemplates()),m(()=>this._selectionSources,()=>this._syncSelectionSources(),g),k(()=>this.activeWorkflow,"cancel",()=>this.emit("workflow-cancel")),k(()=>this.activeWorkflow,"commit",()=>this.emit("workflow-commit")),k(()=>this.activeWorkflow,"complete",()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)}),v(()=>!this.activeWorkflow&&this._queuedSelectionTool,()=>this._queuedSelectionTool&&this.selectionToolbarViewModel.activateTool(this._queuedSelectionTool)),m(()=>this.activeWorkflow,e=>this._defaultSelectionManager.highlightEnabled=!e),v(()=>this.view?.map,e=>e.add(this._sketchGraphicsLayer),g),k(()=>this.editorItems,"change",()=>this._afterEditorItemsChange()),m(()=>[this.canCreate,this.canUpdateVisible],()=>this._afterEditorItemsChange()),m(()=>this.page,(e,t)=>{const i=[...this.pageStack];if(-1===i.indexOf(e))i.push(e);else for(;i.length&&i.at(-1)!==e;)i.pop();this.pageStack=i},y),v(()=>"awaiting-update-feature-candidate"===this.state,()=>this._candidateCommitted=!1),k(()=>this.featureTemplatesViewModel,"select",async({item:e,oldItem:t})=>{const{activeWorkflow:i}=this;if(i){if("update"===i.type&&"awaiting-feature-creation-info"===i.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(t,{emit:!1})}}if(!e)return;const o={layer:e.layer,template:e.template};if(e.supportsUpload)return this.featureTemplatesViewModel.select(t,{emit:!1}),this.startCreateFeaturesWorkflow(o);await this.startCreateFeaturesWorkflowAtFeatureCreation(o)}),m(()=>[this.view,this.featureTemplatesViewModel],([e,t])=>{t.view=e},y),k(()=>this.view,"key-down",e=>{"Escape"===e.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(e.stopPropagation(),this.back())}),k(()=>this.sketchViewModel,["create","delete","update"],e=>{const{activeWorkflow:t}=this,i=N(t),o=`sketch-${e.type}`;this.emit(o,{type:o,detail:e,layer:i[0],layers:i})},_),m(()=>this.view,e=>{if(this._snappingManager=d(this._snappingManager),!e)return;const t=this.snappingOptions;this._snappingManager=new H({view:e,options:t}),this.ownSketchViewModel.snappingManager=this._snappingManager},y),m(()=>this.snappingOptions,e=>{this._snappingManager&&(this._snappingManager.options=e)},y),k(()=>this.selectionToolbarViewModel,"complete",e=>this._onSelectionComplete(e)),m(()=>({view:this.view,selectionManager:this.effectiveSelectionManager,selectionListViewModel:this.selectionListViewModel,selectionToolbarViewModel:this.selectionToolbarViewModel}),({view:e,selectionManager:t,selectionListViewModel:i,selectionToolbarViewModel:o})=>{t.view=e,i.view=e,o.view=e},y),m(()=>this.effectiveSelectionManager,e=>{this.selectionListViewModel.selectionManager=e,this.selectionToolbarViewModel.selectionManager=e},y)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then(()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null}),this._updateItemsTask=p(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=h(this._sketchEventListenerHandle),this.selectionListViewModel?.destroy(),this.selectionToolbarViewModel?.destroy(),this._defaultSelectionManager.destroy()}get _featureTemplatesLayersAndTables(){const e=new o;for(const t of this.editorItems){const i=this.hideTemplatesForInactiveLayers&&!t.visible;t.supportsCreateFeaturesWorkflow&&!i&&e.push(t.layer)}return e}get _selectionSources(){const e=new o;if(this.syncViewSelection||this.selectionManager)return e;for(const t of this.editorItems)x(t.layer)&&t.supportsUpdateWorkflow&&e.push(t.layer);return e}get activeFeatureCount(){const e=this.activeLeafWorkflow;return Q(e)?e.pendingFeatures.length:z(e)&&e.data.edits.feature?1:Z(e)?e.data.fullFeatures.length:$(e)?e.data.features.length:J(e)?2:0}get activeLeafWorkflow(){const e=this.activeWorkflow;return e&&K(e)?e.activeWorkflow??e:e}get canCreate(){return this.editorItems.some(e=>e.supportsCreateFeaturesWorkflow)}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some(e=>e.supportsUpdateWorkflow)}get canUpdateVisible(){return this.editorItems.some(e=>e.supportsUpdateWorkflow&&e.visible)}get featureTemplatesLayers(){return this._featureTemplatesLayersAndTables.filter(e=>"scene"===e.type||!e.isTable)}get effectiveSelectionManager(){const e=this.view;return e&&this.syncViewSelection?e.selectionManager:this.selectionManager??this._defaultSelectionManager}get featureFormViewModel(){const e=this.activeWorkflow?.formViewModel;return X(e)?e:null}get formViewModel(){return this.activeWorkflow?.formViewModel}get utilityNetworkAssociationAddAssociationViewModel(){const{activeWorkflow:e}=this;return"update"===e?.type?e.activeUtilityNetworkAssociationAddAssociationViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(e){this.sketchOptions.labels=e}get isUsingLegacyCreateTools(){return this.useLegacyCreateTools||"2d"!==this.view?.type}get sketchViewModel(){const{activeWorkflow:e}=this;return"update"===e?.type?e.activeSketchViewModel:"create-features"===e?.type?e.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const e=this.attachmentsViewModel.mode;if("add"===e)return"adding-attachment";if("edit"===e)return"editing-attachment";const{activeWorkflow:t}=this,i=!t?.stepId;return this.effectiveSelectionManager.count&&i?"viewing-selection-list":i?"ready":"update"===t.type&&t.activeWorkflow?.stepId?t.activeWorkflow.stepId:t.stepId}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(e){this.sketchOptions.tooltips=e}get valueOptions(){return this.sketchOptions.values}set valueOptions(e){this.sketchOptions.values=e}set view(e){this.ownSketchViewModel.view=e,this.spinnerViewModel.view=e,this._set("view",e)}get canZoomTo(){return this._getWorkingFeatures().some(e=>e.geometry)}get page(){const{activeWorkflow:e,state:t}=this;if("update"===e?.type&&X(e.formViewModel)){const{associatedLayer:t,associationId:i}=e.formViewModel;if(t||null!=i)return"viewing-associated-features"}if("update"===e?.type&&"awaiting-feature-to-update"===e.stepId)return"ready";if("create-features"===e?.type&&0===e.numPendingFeatures){const t=e.data.upload;if(t)return"default"===t.state?"ready":"creating-features-upload-details"}return t??"disabled"}get featureFormDisabled(){const{activeLeafWorkflow:e}=this;if(z(e))return!1===e.data.editorItem?.capabilities.update.attributes||!0===e.formViewModel.disabled;if(Z(e)){const{formViewModel:t}=e;return t.disabled||t.readOnly}return!1}get featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeLeafWorkflow:e}=this;if(z(e)){const{data:t}=e;return t.editorItem?.capabilities.delete.enabled&&!t.readOnly}return!!Z(e)&&e.data.editorItems.every(e=>e.capabilities.delete.enabled)}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}get snappingManager(){return this._snappingManager}activateSelectionTool(e){return this.selectionToolbarViewModel.activateTool(e)}cancelSelectionTool(){this.selectionToolbarViewModel.cancel()}getTemplatesForLayer(e){return this._templatesByLayer.get(e)??[]}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(e){return this.startCreateFeaturesWorkflow(e,"creating-features")}async startCreateFeaturesWorkflow(e,t="awaiting-feature-creation-info"){if(await W(()=>!this.updating),!this.canCreate)throw new a("editing:unsupported-workflow","Creating features is unsupported or disabled.");const i=this._createUpdatingResolver();try{await this._cancelWorkflow();const i=this._createCreateFeaturesWorkflow(e,t);this._set("activeWorkflow",i),await i.start()}catch(o){this._logErrorAndCancelWorkflow(o)}finally{i.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(e){await W(()=>!this.updating);const t=this._createUpdatingResolver();try{const{initialFeature:t}=e,i=t.sourceLayer=t.layer,o=i?Y(this.editorItems,i):void 0;if(!o?.supportsCreateFeaturesWorkflow)throw new a("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const r=this._createCreateFeaturesWorkflow({initialFeature:t,layer:o.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",r),await r.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startMergeFeaturesWorkflow(e,t={}){await W(()=>!this.updating),ne(this,"merge-features");const i=Array.isArray(e)?ee(e):[e];if(i.length>1)throw new le;if(0===i.length||i[0].objectIds.length<2)throw new ce(2);const r=i[0],a=r.layer;if(!a)throw new de;const s=Y(this.editorItems,a);pe(s);const l=this._createUpdatingResolver(),c=new AbortController;this.addHandles(n(c));try{await this._cancelWorkflow(),this.cancelSelectionTool();const e=await te(r.objectIds,a,this.view?.spatialReference,c.signal);if(e.length!==r.objectIds.length)throw new he;let i;if(t.keyFeature){const o=t.keyFeature.getObjectId();i=e.find(e=>e.getObjectId()===o)??t.keyFeature}const s=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o(e),rootWorkflowOptions:{type:"merge",props:{...t,keyFeature:i}}});this._set("activeWorkflow",s),this.addHandles(this._destroyWorkflowOnCommit(s)),await s.start()}catch(d){this._logErrorAndCancelWorkflow(d)}finally{l.resolve()}}async startSplitFeatureWorkflow(e,t={}){await W(()=>!this.updating),ne(this,"split-feature");const i=V(e);if(!i)throw new de;const r=Y(this.editorItems,i);ue(r);const a=this._createUpdatingResolver(),s=new AbortController;this.addHandles(n(s));try{await this._cancelWorkflow(),this.cancelSelectionTool();const r=await ie([e],i,this.view?.spatialReference,s.signal);if(1!==r.length)throw new he;const a=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o(r),rootWorkflowOptions:{type:"split",props:t}});this._set("activeWorkflow",a),this.addHandles(this._destroyWorkflowOnCommit(a)),await a.start()}catch(l){this._logErrorAndCancelWorkflow(l)}finally{a.resolve()}}async startUpdateFeaturesWorkflow(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update features workflow is unsupported or disabled.");const t=Array.isArray(e)?ee(e):[e];if(t.length>1)throw new le;const i=this._createUpdatingResolver();try{await this._cancelWorkflow(),this.cancelSelectionTool();const e=this._createUpdateWorkflow("editing-existing-feature",{rootFeatureInfos:t,rootWorkflowOptions:{type:"update-multiple"}});e.addHandles(this._destroyWorkflowOnCommit(e)),this._set("activeWorkflow",e),await e.start()}catch(o){this._logErrorAndCancelWorkflow(o)}finally{i.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow();this._set("activeWorkflow",e),await e.start()}catch(t){this._logErrorAndCancelWorkflow(t)}finally{e.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow("awaiting-update-feature-candidate");t.data.candidates=e,this._set("activeWorkflow",t),await t.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startUpdateWorkflowAtFeatureEdit(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow(),this.cancelSelectionTool();const t=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o([e])});t.addHandles(this._destroyWorkflowOnCommit(t)),this._set("activeWorkflow",t),await t.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startUpdateWorkflowWithActiveSelection(){const{selectionListViewModel:e}=this;if(!e.visibleFeatureCount||!e.visibleLayerCount)throw new a("editing:missing-selection","Unable to determine visible selection.");if(e.visibleLayerCount>1)throw new a("editing:features-different-layers","Cannot start workflow with features from different layers.");const t=e.layerItems.find(e=>e.visible);t&&await this._startUpdateWorkflowWithLayerItem(t,"update")}async deleteFeatureFromWorkflow(){r(c.getLogger(this),"EditorViewModel.deleteFeatureFromWorkflow is deprecated. Use EditorViewModel.deleteFeatures instead.",{version:"4.33",replacement:"EditorViewModel.deleteFeatures",warnOnce:!0}),await this.deleteFeatures()}async deleteFeatures(){const e=this.activeWorkflow;if(K(e))return e.deleteActiveFeatures();this._logError("editing:unsupported-workflow","Deleting features requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:e}=this;e&&"update"===e.type?await e.deleteActiveAssociation():this._logError("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(e){return this._cancelWorkflow({warnIfNoWorkflow:!0,...e})}itemHasInvalidFormTemplate(e){return null!=e&&!0===oe(this.editorItems,e.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelIsRestricted||this._updateTemplates()}zoomTo(e){const{view:i,sketchViewModel:o}=this;if(!i)return;const r=void 0,a=e??o?.createGraphic;if(a)"mesh"===a.geometry?.type?ge(i,a.geometry,r):ge(i,a,r);else{const e=this._getWorkingFeatures();"3d"===i.type&&e?.some(e=>"mesh"===e.geometry?.type)?ge(i,e.map(e=>e.geometry).filter(t),r):e&&ge(i,e,r)}}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}async onSelectionListItemSelect(e){ke(e)&&await this.startUpdateWorkflowAtFeatureEdit(e.graphic)}async onSelectionListMenuItemSelect(e,t){ke(e)?await this.startUpdateWorkflowAtFeatureEdit(e.graphic):ve(e)&&await this._startUpdateWorkflowWithLayerItem(e,t)}restrictFeatureTemplatesViewModelToLayer(e){return this._featureTemplatesViewModelIsRestricted=!0,this._setFeatureTemplatesViewModelLayers([e]),l(()=>{this._featureTemplatesViewModelIsRestricted=!1,this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)})}async _getEditorItemCandidates(e){const{view:t}=this;if(!t?.map)return[];const{map:i}=t,o=i.editableLayers.toArray(),r=i.allTables.toArray().filter(e=>L(e)||E(e));return await Promise.allSettled([...o.flatMap(e=>this._getLayerLoadPromise(e)),...r.flatMap(e=>this._getLayerLoadPromise(e))]),u(e),[...o.reverse(),...r.reverse()].filter(e=>I(e)&&("mesh"!==e.geometryType||"3d"===t.type)).flatMap(e=>"subtype-group"===e.type?e.sublayers.toArray():e)}_getLayerLoadPromise(e){return E(e)?e.loadAll():e.load()}_drainEditorItems(){this.editorItems.drain(e=>e.destroy())}_updateEditorItems(){p(this._updateItemsTask);const{view:e}=this,t=i(async t=>{if(!e?.map||!e?.allLayerViews)return;const i=await this._getEditorItemCandidates(t);if(!i.length)return this._drainEditorItems(),void this.editorItemsLayerMap.clear();const o=[],r=[],a=[],{editorItemsLayerMap:s,layerInfos:n}=this;for(const c of i){const t=Me(n,c),i=await re(e,c).catch(()=>null),l=t?o:i?r:a,d=new se({layer:c,layerInfo:t,layerView:i});l.push(d),s.set(c,d)}n?.length&&o.sort((e,t)=>n.findIndex(({layer:t})=>t===e.layer)-n.findIndex(({layer:e})=>e===t.layer));const l=[...o,...r,...a];t.aborted||(this._drainEditorItems(),this.editorItems.addMany(l))});this._updatingHandles.addPromise(t.promise),this._updateItemsTask=t}_updateTemplates(){p(this._updateTemplatesTask);const e=i(async e=>{const t=this._templatesByLayer,i=this._featureTemplatesLayersAndTables.filter(e=>!t.has(e));if(i.length>0){const o=await b({layers:i.toArray(),view:this.view,signal:e,queryOptions:{returnVisibleTemplatesOnly:!0}});for(const{layer:e,templates:i}of o)t.set(e,i)}this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)});this._updatingHandles.addPromise(e.promise),this._updateTemplatesTask=e}_setFeatureTemplatesViewModelLayers(e){const t=this._templatesByLayer,i=[];for(const o of e){const e=t.get(o);e&&e.length>0&&i.push(we(o,e))}this.featureTemplatesViewModel.templateInfos=i}_afterEditorItemsChange(){const{activeWorkflow:e}=this;if(this.syncFeatureTemplates(),!e)return;const{stepId:t}=e;"create-features"!==e.type?"update"===e.type&&("awaiting-feature-to-update"===t&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===t&&!e.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==t||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(e){const t=this.activeWorkflow;if(!t)return void(e?.warnIfNoWorkflow&&this._logError("editing:no-active-workflow","There is no active workflow to cancel."));if(!e||!1!==e.force){this.emit("workflow-cancel"),this._set("activeWorkflow",null);try{await t.cancel(e)}finally{t.destroy()}}else try{await t.cancel(e),this._set("activeWorkflow",null),t.destroy()}catch(i){}}_createCreateFeaturesWorkflow(e,t){return D.create({viewModel:this,creationInfo:e,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEdits:(e,t,i)=>this._applyEdits(e,t,i),applyEditsFeatureService:(e,t,i)=>this._applyEditsFeatureService(e,t,i),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)})}_createUpdateWorkflow(e,t){const i=B.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,...t,applyEdits:(e,t,i)=>this._applyEdits(e,t,i),applyEditsFeatureService:(e,t,i)=>this._applyEditsFeatureService(e,t,i),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)});return i}_addAttachments(e,t){const i=t.map(t=>this._addAttachment(e,t.feature,t.attachment))??[];return Promise.all(i)}async _addAttachment(e,t,i){let o=null;if(!("addAttachment"in e)||null==e.capabilities?.attachment)throw new a("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation(async()=>(o=await(e.addAttachment?.(t,i).catch(e=>{throw e?.error||e}))??null,o)),o}async _applyEdits(e,t,i){let o=null;const r=e.url?await A(e.url):null,a={returnServiceEditsOption:(!r||!C(r))&&!/\/hosted\//i.test(e.url)?"original-and-current-features":void 0,editsRespectTrueCurves:!0,...i};return await this._queueOperation(async()=>{const{view:i}=this;if(!i)return null;const r=await re(i,e).catch(()=>null);return o=await e.applyEdits(t,a),r&&await W(()=>!r.updating),o}),o}async _applyEditsFeatureService(e,t,i){let o=null;return await this._queueOperation(async()=>o=await e.applyEdits(t,i)),o}_destroyWorkflowOnCommit(e){return k(()=>e,"commit",()=>{e.destroy(),this.activeWorkflow===e&&this._set("activeWorkflow",null)})}_queueOperation(e){this._activityQueue.push(e);const t=(e,t)=>{const i=t.indexOf(e);i>-1&&t.splice(i,1)};return e().then(e=>(Array.isArray(e)?e.forEach(e=>this._handleEditsResultError(e)):this._handleEditsResultError(e),e)).catch(i=>{this._logError("editing:operation-error","An error occurred.",{error:i});const o={error:i,retry:()=>(t(o,this.failures),this._queueOperation(e)),cancel:()=>{t(o,this.failures)}};this._set("failures",[...this.failures,o])}).then(()=>{t(e,this._activityQueue)})}_handleEditsResultError(e){if(null!=e&&"error"in e&&null!=e.error)throw e.error;if(null!=e&&"addFeatureResults"in e){const{addFeatureResults:t,deleteFeatureResults:i,updateFeatureResults:o}=e,r=t.find(e=>!!e.error)||o.find(e=>!!e.error)||i.find(e=>!!e.error);if(r)throw r.error}}_createUpdatingResolver(){const e=w();return this._updatingHandles.addPromise(e.promise),e}_logErrorAndCancelWorkflow(e){const{name:t,message:i,details:o}=e;this._logError(t??"editing:workflow-start-failed",i??void 0,o??e),this._cancelWorkflow({force:!0})}_itemIsSuspended(e){const t=Y(this.editorItems,e);return null!=t&&(!t.visible||t.disabled)}_logError(e,t,i){c.getLogger(this).error(new a(e,t,i))}_syncSelectionSources(){this._defaultSelectionManager.sources.items=this._selectionSources.toArray()}async _onSelectionComplete(e){if(e.aborted)return;const{operationType:t,selection:i}=e,{effectiveSelectionManager:o}=this;this._queuedSelectionTool=void 0;const r=[],a=[];i.forEach(e=>{const t=V(e),i=this.editorItemsLayerMap.get(t);i?.editable&&a.push(e),!1!==i?.visible&&r.push(e)});const s=1===a.length;if("ready"===this.state&&s&&"replace"===t)return this._queuedSelectionTool=e.toolName,this.startUpdateWorkflowAtFeatureEdit(a[0]);switch(t){case"remove":o.updateSelection({current:[],added:[],removed:r});break;case"replace":o.clear(),o.updateSelection({current:r,added:[],removed:[]});break;case"add":o.updateSelection({current:r,added:[],removed:[]})}}async _startUpdateWorkflowWithLayerItem(e,t){if(!e.objectIds?.length)return;const i=e.featureItems.filter(e=>e.visible).map(e=>e.graphic),o=this.selectionListViewModel.filterText;if(1===i.length)return await this.startUpdateWorkflowAtFeatureEdit(i[0]);let r;if(null!=o&&""!==o){const e=ee(i);if(e.length>1)throw new le;if(r=e[0],!r)throw new ce("merge"===t?2:1)}else r={layer:e.layer,objectIds:e.objectIds};"update"===t?await this.startUpdateFeaturesWorkflow(r):"merge"===t&&await this.startMergeFeaturesWorkflow(r)}_getWorkingFeatures(){const{sketchViewModel:e}=this;if(e?.createGraphic)return[e.createGraphic];if(e?.updateGraphics?.length)return e.updateGraphics.toArray();const{formViewModel:t}=this;if(X(t)&&t.feature)return[t.feature];if(ae(t)){if(t.activeFeature)return[t.activeFeature];if(t.features.length)return t.features.toArray()}return[]}};e([M()],Te.prototype,"_defaultSelectionManager",void 0),e([M()],Te.prototype,"_featureTemplatesLayersAndTables",null),e([M()],Te.prototype,"_queuedSelectionTool",void 0),e([M()],Te.prototype,"_snappingManager",void 0),e([M()],Te.prototype,"_selectionSources",null),e([M()],Te.prototype,"activeFeatureCount",null),e([M({readOnly:!0})],Te.prototype,"activeWorkflow",void 0),e([M()],Te.prototype,"activeLeafWorkflow",null),e([M({readOnly:!0})],Te.prototype,"_activityQueue",void 0),e([M({readOnly:!0})],Te.prototype,"canCreate",null),e([M()],Te.prototype,"canCreateVisible",null),e([M({readOnly:!0})],Te.prototype,"canUpdate",null),e([M()],Te.prototype,"canUpdateVisible",null),e([M()],Te.prototype,"featureTemplatesLayers",null),e([M()],Te.prototype,"editorItems",void 0),e([M()],Te.prototype,"editorItemsLayerMap",void 0),e([M()],Te.prototype,"effectiveSelectionManager",null),e([M({readOnly:!0})],Te.prototype,"failures",void 0),e([M()],Te.prototype,"hideTemplatesForInactiveLayers",void 0),e([M({type:G})],Te.prototype,"attachmentsViewModel",void 0),e([M()],Te.prototype,"featureFormViewModel",null),e([M()],Te.prototype,"formViewModel",null),e([M()],Te.prototype,"utilityNetworkAssociationAddAssociationViewModel",null),e([M({type:fe})],Te.prototype,"featureTemplatesViewModel",void 0),e([M({type:O})],Te.prototype,"labelOptions",null),e([M()],Te.prototype,"layerInfos",void 0),e([M({constructOnly:!0})],Te.prototype,"useLegacyCreateTools",void 0),e([M()],Te.prototype,"isUsingLegacyCreateTools",null),e([M()],Te.prototype,"ownSketchViewModel",void 0),e([M()],Te.prototype,"selectionListViewModel",void 0),e([M()],Te.prototype,"selectionManager",void 0),e([M()],Te.prototype,"selectionToolbarViewModel",void 0),e([M()],Te.prototype,"sketchOptions",void 0),e([M()],Te.prototype,"sketchViewModel",null),e([M({type:q,nonNullable:!0})],Te.prototype,"snappingOptions",void 0),e([M()],Te.prototype,"spinnerViewModel",void 0),e([M()],Te.prototype,"state",null),e([M({readOnly:!0})],Te.prototype,"syncing",null),e([M()],Te.prototype,"syncViewSelection",void 0),e([M()],Te.prototype,"updating",null),e([M({type:R})],Te.prototype,"tooltipOptions",null),e([M({type:P})],Te.prototype,"valueOptions",null),e([M()],Te.prototype,"view",null),e([M()],Te.prototype,"canZoomTo",null),e([M()],Te.prototype,"pageStack",void 0),e([M()],Te.prototype,"showDiscardEditsPrompt",void 0),e([M()],Te.prototype,"_candidateCommitted",void 0),e([M()],Te.prototype,"page",null),e([M()],Te.prototype,"featureFormDisabled",null),e([M()],Te.prototype,"featureFormHasAssociation",null),e([M()],Te.prototype,"canGoBack",null),e([M()],Te.prototype,"shouldShowDeleteButton",null),e([M()],Te.prototype,"hasPendingEdits",null),e([M()],Te.prototype,"snappingManager",null),Te=e([T("esri.widgets.Editor.EditorViewModel")],Te);const Fe=Te;export{Fe as default};
|
|
2
|
+
import{__decorate as e}from"tslib";import{isSome as t}from"../../core/arrayUtils.js";import{createTask as i}from"../../core/asyncUtils.js";import o from"../../core/Collection.js";import{deprecatedFunction as r}from"../../core/deprecate.js";import a from"../../core/Error.js";import{EventedAccessor as s}from"../../core/Evented.js";import{abortHandle as n,makeHandle as l}from"../../core/handleUtils.js";import"../../core/has.js";import c from"../../core/Logger.js";import{destroyMaybe as d,abortMaybe as p,removeMaybe as h}from"../../core/maybe.js";import{throwIfAborted as u,createResolver as w}from"../../core/promiseUtils.js";import f from"../../core/ReactiveMap.js";import{watch as m,syncAndInitial as y,initial as g,on as k,when as v,sync as _,whenOnce as W}from"../../core/reactiveUtils.js";import{property as M,subclass as T}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as F}from"../../core/support/UpdatingHandles.js";import{getTemplatesForLayers as b}from"../../editing/templateUtils.js";import{getGraphicLayer as V}from"../../graphic/graphicOriginUtils.js";import S from"../../layers/GraphicsLayer.js";import{isEditableLayer as I}from"../../layers/support/editableLayers.js";import{isFeatureLayer as L,isSubtypeGroupLayer as E,getOwningPortalUrl as C}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as A}from"../../portal/support/urlUtils.js";import U from"../../views/SelectionManager.js";import O from"../../views/interactive/sketch/SketchLabelOptions.js";import j from"../../views/interactive/sketch/SketchOptions.js";import P from"../../views/interactive/sketch/SketchTooltipOptions.js";import R from"../../views/interactive/sketch/SketchValueOptions.js";import{SnappingManager as H}from"../../views/interactive/snapping/SnappingManager.js";import q from"../../views/interactive/snapping/SnappingOptions.js";import{isISelectableLayer as x}from"../../views/support/selectionUtils.js";import G from"../Attachments/AttachmentsViewModel.js";import D from"./CreateFeaturesWorkflow.js";import B from"./UpdateWorkflow.js";import{getLayersFromWorkflow as N,isCreateFeaturesWorkflow as Q,isUpdateRecordWorkflow as z,isUpdateFeaturesWorkflow as Z,isMergeFeaturesWorkflow as $,isSplitFeatureWorkflow as J,isUpdateWorkflow as K,isFeatureFormViewModel as X,findEditorItemForLayerOrThrow as Y,toFeatureInfos as ee,fetchFullFeaturesByObjectId as te,fetchFullFeatures as ie,findEditorItemForLayer as oe,whenEditorLayerView as re,isBatchAttributeFormViewModel as ae}from"./workflowUtils.js";import se from"./support/EditorItem.js";import{assertViewNot3D as ne,MultipleSourceLayersError as le,InsufficientFeatureCountError as ce,MissingOriginLayerError as de,assertMergeWorkflowCapabilities as pe,FetchFullFeatureError as he,assertSplitWorkflowCapabilities as ue}from"./support/errors.js";import{makeTemplateGroupInfoForLayer as we}from"../FeatureTemplates/featureTemplatesUtils.js";import fe from"../FeatureTemplates/FeatureTemplatesViewModel.js";import me from"../Sketch/SketchViewModel.js";import ye from"../Spinner/SpinnerViewModel.js";import{goTo as ge}from"../support/goToUtils.js";import{isFeatureItem as ke,isLayerItem as ve}from"../support/SelectionList/selectionListUtils.js";import _e from"../support/SelectionList/SelectionListViewModel.js";import We from"../support/SelectionToolbar/SelectionToolbarViewModel.js";function Me(e,t){return e?.find(e=>e.layer===t)}let Te=class extends s{constructor(e){super(e),this._defaultSelectionManager=new U,this._queuedSelectionTool=null,this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new S({listMode:"hide",internal:!0,title:"Editor sketch layer"}),this._snappingManager=null,this._templatesByLayer=new Map,this._updateItemsTask=null,this._updateTemplatesTask=null,this._updatingHandles=new F,this._featureTemplatesViewModelIsRestricted=!1,this.activeWorkflow=null,this._activityQueue=new o,this.editorItems=new o,this.editorItemsLayerMap=new f,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new G({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new fe({disabledItemFunction:({layer:e})=>this._itemIsSuspended(e)}),this.layerInfos=null,this.ownSketchViewModel=new me({layer:this._sketchGraphicsLayer,useLegacyCreateTools:this._get("useLegacyCreateTools")??!0}),this.selectionListViewModel=new _e,this.selectionManager=null,this.selectionToolbarViewModel=new We({continuousSelectionEnabled:!0,defaultOperationType:"replace",persistSelection:!1,returnGeometry:!1}),this.sketchOptions=new j,this.snappingOptions=new q({attributeRulesEnabled:!0}),this.spinnerViewModel=new ye,this.syncViewSelection=!1,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this.showConfirmationPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{if("viewing-selection-list"===this.state)return this.selectionListViewModel.filterText=void 0,void this.effectiveSelectionManager.clear();this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>await(this.activeWorkflow?.save(this.showConfirmationPrompt)),this.selectFeature=(e,t=!1)=>{const i=this.activeWorkflow;if(this._candidateCommitted||"update"!==i?.type)return;const{rootFeatures:o}=i.data;o.removeAll(),e&&o.add(e),t&&(i.next(),this._candidateCommitted=!0)}}initialize(){this.addHandles([m(()=>{const e=this.view,t=e?.map?.editableLayers.toArray(),i=e?.allLayerViews,o=i?.filter(e=>!!t?.includes(e.layer));return[t,o,this.layerInfos]},()=>this._updateEditorItems(),y),m(()=>this.hideTemplatesForInactiveLayers,()=>this.syncFeatureTemplates()),m(()=>this._selectionSources,()=>this._syncSelectionSources(),g),k(()=>this.activeWorkflow,"cancel",()=>this.emit("workflow-cancel")),k(()=>this.activeWorkflow,"commit",()=>this.emit("workflow-commit")),k(()=>this.activeWorkflow,"complete",()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)}),v(()=>!this.activeWorkflow&&this._queuedSelectionTool,()=>this._queuedSelectionTool&&this.selectionToolbarViewModel.activateTool(this._queuedSelectionTool)),m(()=>this.activeWorkflow,e=>this._defaultSelectionManager.highlightEnabled=!e),v(()=>this.view?.map,e=>e.add(this._sketchGraphicsLayer),g),k(()=>this.editorItems,"change",()=>this._afterEditorItemsChange()),m(()=>[this.canCreate,this.canUpdateVisible],()=>this._afterEditorItemsChange()),m(()=>this.page,(e,t)=>{const i=[...this.pageStack];if(-1===i.indexOf(e))i.push(e);else for(;i.length&&i.at(-1)!==e;)i.pop();this.pageStack=i},y),v(()=>"awaiting-update-feature-candidate"===this.state,()=>this._candidateCommitted=!1),k(()=>this.featureTemplatesViewModel,"select",async({item:e,oldItem:t})=>{const{activeWorkflow:i}=this;if(i){if("update"===i.type&&"awaiting-feature-creation-info"===i.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(t,{emit:!1})}}if(!e)return;const o={layer:e.layer,template:e.template};if(e.supportsUpload)return this.featureTemplatesViewModel.select(t,{emit:!1}),this.startCreateFeaturesWorkflow(o);await this.startCreateFeaturesWorkflowAtFeatureCreation(o)}),m(()=>[this.view,this.featureTemplatesViewModel],([e,t])=>{t.view=e},y),k(()=>this.view,"key-down",e=>{"Escape"===e.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(e.stopPropagation(),this.back())}),k(()=>this.sketchViewModel,["create","delete","update"],e=>{const{activeWorkflow:t}=this,i=N(t),o=`sketch-${e.type}`;this.emit(o,{type:o,detail:e,layer:i[0],layers:i})},_),m(()=>this.view,e=>{if(this._snappingManager=d(this._snappingManager),!e)return;const t=this.snappingOptions;this._snappingManager=new H({view:e,options:t}),this.ownSketchViewModel.snappingManager=this._snappingManager},y),m(()=>this.snappingOptions,e=>{this._snappingManager&&(this._snappingManager.options=e)},y),k(()=>this.selectionToolbarViewModel,"complete",e=>this._onSelectionComplete(e)),m(()=>({view:this.view,selectionManager:this.effectiveSelectionManager,selectionListViewModel:this.selectionListViewModel,selectionToolbarViewModel:this.selectionToolbarViewModel}),({view:e,selectionManager:t,selectionListViewModel:i,selectionToolbarViewModel:o})=>{t.view=e,i.view=e,o.view=e},y),m(()=>this.effectiveSelectionManager,e=>{this.selectionListViewModel.selectionManager=e,this.selectionToolbarViewModel.selectionManager=e},y)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then(()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null}),this._updateItemsTask=p(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=h(this._sketchEventListenerHandle),this.selectionListViewModel?.destroy(),this.selectionToolbarViewModel?.destroy(),this._defaultSelectionManager.destroy()}get _featureTemplatesLayersAndTables(){const e=new o;for(const t of this.editorItems){const i=this.hideTemplatesForInactiveLayers&&!t.visible;t.supportsCreateFeaturesWorkflow&&!i&&e.push(t.layer)}return e}get _selectionSources(){const e=new o;if(this.syncViewSelection||this.selectionManager)return e;for(const t of this.editorItems)x(t.layer)&&t.supportsUpdateWorkflow&&e.push(t.layer);return e}get activeFeatureCount(){const e=this.activeLeafWorkflow;return Q(e)?e.pendingFeatures.length:z(e)&&e.data.edits.feature?1:Z(e)?e.data.fullFeatures.length:$(e)?e.data.features.length:J(e)?2:0}get activeLeafWorkflow(){const e=this.activeWorkflow;return e&&K(e)?e.activeWorkflow??e:e}get canCreate(){return this.editorItems.some(e=>e.supportsCreateFeaturesWorkflow)}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some(e=>e.supportsUpdateWorkflow)}get canUpdateVisible(){return this.editorItems.some(e=>e.supportsUpdateWorkflow&&e.visible)}get featureTemplatesLayers(){return this._featureTemplatesLayersAndTables.filter(e=>"scene"===e.type||!e.isTable)}get effectiveSelectionManager(){const e=this.view;return e&&this.syncViewSelection?e.selectionManager:this.selectionManager??this._defaultSelectionManager}get featureFormViewModel(){const e=this.activeWorkflow?.formViewModel;return X(e)?e:null}get formViewModel(){return this.activeWorkflow?.formViewModel}get utilityNetworkAssociationAddAssociationViewModel(){const{activeWorkflow:e}=this;return"update"===e?.type?e.activeUtilityNetworkAssociationAddAssociationViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(e){this.sketchOptions.labels=e}get useLegacyCreateTools(){return this.ownSketchViewModel.useLegacyCreateTools}set useLegacyCreateTools(e){this.ownSketchViewModel.useLegacyCreateTools=e}get isUsingLegacyCreateTools(){return this.useLegacyCreateTools||"2d"!==this.view?.type}get sketchViewModel(){const{activeWorkflow:e}=this;return"update"===e?.type?e.activeSketchViewModel:"create-features"===e?.type?e.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const e=this.attachmentsViewModel.mode;if("add"===e)return"adding-attachment";if("edit"===e)return"editing-attachment";const{activeWorkflow:t}=this,i=!t?.stepId;return this.effectiveSelectionManager.count&&i?"viewing-selection-list":i?"ready":"update"===t.type&&t.activeWorkflow?.stepId?t.activeWorkflow.stepId:t.stepId}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(e){this.sketchOptions.tooltips=e}get valueOptions(){return this.sketchOptions.values}set valueOptions(e){this.sketchOptions.values=e}set view(e){this.ownSketchViewModel.view=e,this.spinnerViewModel.view=e,this._set("view",e)}get canZoomTo(){return this._getWorkingFeatures().some(e=>e.geometry)}get page(){const{activeWorkflow:e,state:t}=this;if("update"===e?.type&&X(e.formViewModel)){const{associatedLayer:t,associationId:i}=e.formViewModel;if(t||null!=i)return"viewing-associated-features"}if("update"===e?.type&&"awaiting-feature-to-update"===e.stepId)return"ready";if("create-features"===e?.type&&0===e.numPendingFeatures){const t=e.data.upload;if(t)return"default"===t.state?"ready":"creating-features-upload-details"}return t??"disabled"}get featureFormDisabled(){const{activeLeafWorkflow:e}=this;if(z(e))return!1===e.data.editorItem?.capabilities.update.attributes||!0===e.formViewModel.disabled;if(Z(e)){const{formViewModel:t}=e;return t.disabled||t.readOnly}return!1}get featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeLeafWorkflow:e}=this;if(z(e)){const{data:t}=e;return t.editorItem?.capabilities.delete.enabled&&!t.readOnly}return!!Z(e)&&e.data.editorItems.every(e=>e.capabilities.delete.enabled)}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}get snappingManager(){return this._snappingManager}activateSelectionTool(e){return this.selectionToolbarViewModel.activateTool(e)}cancelSelectionTool(){this.selectionToolbarViewModel.cancel()}getTemplatesForLayer(e){return this._templatesByLayer.get(e)??[]}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(e){return this.startCreateFeaturesWorkflow(e,"creating-features")}async startCreateFeaturesWorkflow(e,t="awaiting-feature-creation-info"){if(await W(()=>!this.updating),!this.canCreate)throw new a("editing:unsupported-workflow","Creating features is unsupported or disabled.");const i=this._createUpdatingResolver();try{await this._cancelWorkflow();const i=this._createCreateFeaturesWorkflow(e,t);this._set("activeWorkflow",i),await i.start()}catch(o){this._logErrorAndCancelWorkflow(o)}finally{i.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(e){await W(()=>!this.updating);const t=this._createUpdatingResolver();try{const{initialFeature:t}=e,i=t.sourceLayer=t.layer,o=i?Y(this.editorItems,i):void 0;if(!o?.supportsCreateFeaturesWorkflow)throw new a("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const r=this._createCreateFeaturesWorkflow({initialFeature:t,layer:o.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",r),await r.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startMergeFeaturesWorkflow(e,t={}){await W(()=>!this.updating),ne(this,"merge-features");const i=Array.isArray(e)?ee(e):[e];if(i.length>1)throw new le;if(0===i.length||i[0].objectIds.length<2)throw new ce(2);const r=i[0],a=r.layer;if(!a)throw new de;const s=Y(this.editorItems,a);pe(s);const l=this._createUpdatingResolver(),c=new AbortController;this.addHandles(n(c));try{await this._cancelWorkflow(),this.cancelSelectionTool();const e=await te(r.objectIds,a,this.view?.spatialReference,c.signal);if(e.length!==r.objectIds.length)throw new he;let i;if(t.keyFeature){const o=t.keyFeature.getObjectId();i=e.find(e=>e.getObjectId()===o)??t.keyFeature}const s=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o(e),rootWorkflowOptions:{type:"merge",props:{...t,keyFeature:i}}});this._set("activeWorkflow",s),this.addHandles(this._destroyWorkflowOnCommit(s)),await s.start()}catch(d){this._logErrorAndCancelWorkflow(d)}finally{l.resolve()}}async startSplitFeatureWorkflow(e,t={}){await W(()=>!this.updating),ne(this,"split-feature");const i=V(e);if(!i)throw new de;const r=Y(this.editorItems,i);ue(r);const a=this._createUpdatingResolver(),s=new AbortController;this.addHandles(n(s));try{await this._cancelWorkflow(),this.cancelSelectionTool();const r=await ie([e],i,this.view?.spatialReference,s.signal);if(1!==r.length)throw new he;const a=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o(r),rootWorkflowOptions:{type:"split",props:t}});this._set("activeWorkflow",a),this.addHandles(this._destroyWorkflowOnCommit(a)),await a.start()}catch(l){this._logErrorAndCancelWorkflow(l)}finally{a.resolve()}}async startUpdateFeaturesWorkflow(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update features workflow is unsupported or disabled.");const t=Array.isArray(e)?ee(e):[e];if(t.length>1)throw new le;const i=this._createUpdatingResolver();try{await this._cancelWorkflow(),this.cancelSelectionTool();const e=this._createUpdateWorkflow("editing-existing-feature",{rootFeatureInfos:t,rootWorkflowOptions:{type:"update-multiple"}});e.addHandles(this._destroyWorkflowOnCommit(e)),this._set("activeWorkflow",e),await e.start()}catch(o){this._logErrorAndCancelWorkflow(o)}finally{i.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow();this._set("activeWorkflow",e),await e.start()}catch(t){this._logErrorAndCancelWorkflow(t)}finally{e.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow("awaiting-update-feature-candidate");t.data.candidates=e,this._set("activeWorkflow",t),await t.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startUpdateWorkflowAtFeatureEdit(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow(),this.cancelSelectionTool();const t=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o([e])});t.addHandles(this._destroyWorkflowOnCommit(t)),this._set("activeWorkflow",t),await t.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startUpdateWorkflowWithActiveSelection(){const{selectionListViewModel:e}=this;if(!e.visibleFeatureCount||!e.visibleLayerCount)throw new a("editing:missing-selection","Unable to determine visible selection.");if(e.visibleLayerCount>1)throw new a("editing:features-different-layers","Cannot start workflow with features from different layers.");const t=e.layerItems.find(e=>e.visible);t&&await this._startUpdateWorkflowWithLayerItem(t,"update")}async deleteFeatureFromWorkflow(){r(c.getLogger(this),"EditorViewModel.deleteFeatureFromWorkflow is deprecated. Use EditorViewModel.deleteFeatures instead.",{version:"4.33",replacement:"EditorViewModel.deleteFeatures",warnOnce:!0}),await this.deleteFeatures()}async deleteFeatures(){const e=this.activeWorkflow;if(K(e))return e.deleteActiveFeatures();this._logError("editing:unsupported-workflow","Deleting features requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:e}=this;e&&"update"===e.type?await e.deleteActiveAssociation():this._logError("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(e){return this._cancelWorkflow({warnIfNoWorkflow:!0,...e})}itemHasInvalidFormTemplate(e){return null!=e&&!0===oe(this.editorItems,e.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelIsRestricted||this._updateTemplates()}zoomTo(e){const{view:i,sketchViewModel:o}=this;if(!i)return;const r=void 0,a=e??o?.createGraphic;if(a)"mesh"===a.geometry?.type?ge(i,a.geometry,r):ge(i,a,r);else{const e=this._getWorkingFeatures();"3d"===i.type&&e?.some(e=>"mesh"===e.geometry?.type)?ge(i,e.map(e=>e.geometry).filter(t),r):e&&ge(i,e,r)}}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}async onSelectionListItemSelect(e){ke(e)&&await this.startUpdateWorkflowAtFeatureEdit(e.graphic)}async onSelectionListMenuItemSelect(e,t){ke(e)?await this.startUpdateWorkflowAtFeatureEdit(e.graphic):ve(e)&&await this._startUpdateWorkflowWithLayerItem(e,t)}restrictFeatureTemplatesViewModelToLayer(e){return this._featureTemplatesViewModelIsRestricted=!0,this._setFeatureTemplatesViewModelLayers([e]),l(()=>{this._featureTemplatesViewModelIsRestricted=!1,this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)})}async _getEditorItemCandidates(e){const{view:t}=this;if(!t?.map)return[];const{map:i}=t,o=i.editableLayers.toArray(),r=i.allTables.toArray().filter(e=>L(e)||E(e));return await Promise.allSettled([...o.flatMap(e=>this._getLayerLoadPromise(e)),...r.flatMap(e=>this._getLayerLoadPromise(e))]),u(e),[...o.reverse(),...r.reverse()].filter(e=>I(e)&&("mesh"!==e.geometryType||"3d"===t.type)).flatMap(e=>"subtype-group"===e.type?e.sublayers.toArray():e)}_getLayerLoadPromise(e){return E(e)?e.loadAll():e.load()}_drainEditorItems(){this.editorItems.drain(e=>e.destroy())}_updateEditorItems(){p(this._updateItemsTask);const{view:e}=this,t=i(async t=>{if(!e?.map||!e?.allLayerViews)return;const i=await this._getEditorItemCandidates(t);if(!i.length)return this._drainEditorItems(),void this.editorItemsLayerMap.clear();const o=[],r=[],a=[],{editorItemsLayerMap:s,layerInfos:n}=this;for(const c of i){const t=Me(n,c),i=await re(e,c).catch(()=>null),l=t?o:i?r:a,d=new se({layer:c,layerInfo:t,layerView:i});l.push(d),s.set(c,d)}n?.length&&o.sort((e,t)=>n.findIndex(({layer:t})=>t===e.layer)-n.findIndex(({layer:e})=>e===t.layer));const l=[...o,...r,...a];t.aborted||(this._drainEditorItems(),this.editorItems.addMany(l))});this._updatingHandles.addPromise(t.promise),this._updateItemsTask=t}_updateTemplates(){p(this._updateTemplatesTask);const e=i(async e=>{const t=this._templatesByLayer,i=this._featureTemplatesLayersAndTables.filter(e=>!t.has(e));if(i.length>0){const o=await b({layers:i.toArray(),view:this.view,signal:e,queryOptions:{returnVisibleTemplatesOnly:!0}});for(const{layer:e,templates:i}of o)t.set(e,i)}this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)});this._updatingHandles.addPromise(e.promise),this._updateTemplatesTask=e}_setFeatureTemplatesViewModelLayers(e){const t=this._templatesByLayer,i=[];for(const o of e){const e=t.get(o);e&&e.length>0&&i.push(we(o,e))}this.featureTemplatesViewModel.templateInfos=i}_afterEditorItemsChange(){const{activeWorkflow:e}=this;if(this.syncFeatureTemplates(),!e)return;const{stepId:t}=e;"create-features"!==e.type?"update"===e.type&&("awaiting-feature-to-update"===t&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===t&&!e.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==t||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(e){const t=this.activeWorkflow;if(!t)return void(e?.warnIfNoWorkflow&&this._logError("editing:no-active-workflow","There is no active workflow to cancel."));if(!e||!1!==e.force){this.emit("workflow-cancel"),this._set("activeWorkflow",null);try{await t.cancel(e)}finally{t.destroy()}}else try{await t.cancel(e),this._set("activeWorkflow",null),t.destroy()}catch(i){}}_createCreateFeaturesWorkflow(e,t){return D.create({viewModel:this,creationInfo:e,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEdits:(e,t,i)=>this._applyEdits(e,t,i),applyEditsFeatureService:(e,t,i)=>this._applyEditsFeatureService(e,t,i),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)})}_createUpdateWorkflow(e,t){const i=B.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,...t,applyEdits:(e,t,i)=>this._applyEdits(e,t,i),applyEditsFeatureService:(e,t,i)=>this._applyEditsFeatureService(e,t,i),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)});return i}_addAttachments(e,t){const i=t.map(t=>this._addAttachment(e,t.feature,t.attachment))??[];return Promise.all(i)}async _addAttachment(e,t,i){let o=null;if(!("addAttachment"in e)||null==e.capabilities?.attachment)throw new a("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation(async()=>(o=await(e.addAttachment?.(t,i).catch(e=>{throw e?.error||e}))??null,o)),o}async _applyEdits(e,t,i){let o=null;const r=e.url?await C(e.url):null,a={returnServiceEditsOption:(!r||!A(r))&&!/\/hosted\//i.test(e.url)?"original-and-current-features":void 0,editsRespectTrueCurves:!0,...i};return await this._queueOperation(async()=>{const{view:i}=this;if(!i)return null;const r=await re(i,e).catch(()=>null);return o=await e.applyEdits(t,a),r&&await W(()=>!r.updating),o}),o}async _applyEditsFeatureService(e,t,i){let o=null;return await this._queueOperation(async()=>o=await e.applyEdits(t,i)),o}_destroyWorkflowOnCommit(e){return k(()=>e,"commit",()=>{e.destroy(),this.activeWorkflow===e&&this._set("activeWorkflow",null)})}_queueOperation(e){this._activityQueue.push(e);const t=(e,t)=>{const i=t.indexOf(e);i>-1&&t.splice(i,1)};return e().then(e=>(Array.isArray(e)?e.forEach(e=>this._handleEditsResultError(e)):this._handleEditsResultError(e),e)).catch(i=>{this._logError("editing:operation-error","An error occurred.",{error:i});const o={error:i,retry:()=>(t(o,this.failures),this._queueOperation(e)),cancel:()=>{t(o,this.failures)}};this._set("failures",[...this.failures,o])}).then(()=>{t(e,this._activityQueue)})}_handleEditsResultError(e){if(null!=e&&"error"in e&&null!=e.error)throw e.error;if(null!=e&&"addFeatureResults"in e){const{addFeatureResults:t,deleteFeatureResults:i,updateFeatureResults:o}=e,r=t.find(e=>!!e.error)||o.find(e=>!!e.error)||i.find(e=>!!e.error);if(r)throw r.error}}_createUpdatingResolver(){const e=w();return this._updatingHandles.addPromise(e.promise),e}_logErrorAndCancelWorkflow(e){const{name:t,message:i,details:o}=e;this._logError(t??"editing:workflow-start-failed",i??void 0,o??e),this._cancelWorkflow({force:!0})}_itemIsSuspended(e){const t=Y(this.editorItems,e);return null!=t&&(!t.visible||t.disabled)}_logError(e,t,i){c.getLogger(this).error(new a(e,t,i))}_syncSelectionSources(){this._defaultSelectionManager.sources.items=this._selectionSources.toArray()}async _onSelectionComplete(e){if(e.aborted)return;const{operationType:t,selection:i}=e,{effectiveSelectionManager:o}=this;this._queuedSelectionTool=void 0;const r=[],a=[];i.forEach(e=>{const t=V(e),i=this.editorItemsLayerMap.get(t);i?.editable&&a.push(e),!1!==i?.visible&&r.push(e)});const s=1===a.length;if("ready"===this.state&&s&&"replace"===t)return this._queuedSelectionTool=e.toolName,this.startUpdateWorkflowAtFeatureEdit(a[0]);switch(t){case"remove":o.updateSelection({current:[],added:[],removed:r});break;case"replace":o.clear(),o.updateSelection({current:r,added:[],removed:[]});break;case"add":o.updateSelection({current:r,added:[],removed:[]})}}async _startUpdateWorkflowWithLayerItem(e,t){if(!e.objectIds?.length)return;const i=e.featureItems.filter(e=>e.visible).map(e=>e.graphic),o=this.selectionListViewModel.filterText;if(1===i.length)return await this.startUpdateWorkflowAtFeatureEdit(i[0]);let r;if(null!=o&&""!==o){const e=ee(i);if(e.length>1)throw new le;if(r=e[0],!r)throw new ce("merge"===t?2:1)}else r={layer:e.layer,objectIds:e.objectIds};"update"===t?await this.startUpdateFeaturesWorkflow(r):"merge"===t&&await this.startMergeFeaturesWorkflow(r)}_getWorkingFeatures(){const{sketchViewModel:e}=this;if(e?.createGraphic)return[e.createGraphic];if(e?.updateGraphics?.length)return e.updateGraphics.toArray();const{formViewModel:t}=this;if(X(t)&&t.feature)return[t.feature];if(ae(t)){if(t.activeFeature)return[t.activeFeature];if(t.features.length)return t.features.toArray()}return[]}};e([M()],Te.prototype,"_defaultSelectionManager",void 0),e([M()],Te.prototype,"_featureTemplatesLayersAndTables",null),e([M()],Te.prototype,"_queuedSelectionTool",void 0),e([M()],Te.prototype,"_snappingManager",void 0),e([M()],Te.prototype,"_selectionSources",null),e([M()],Te.prototype,"activeFeatureCount",null),e([M({readOnly:!0})],Te.prototype,"activeWorkflow",void 0),e([M()],Te.prototype,"activeLeafWorkflow",null),e([M({readOnly:!0})],Te.prototype,"_activityQueue",void 0),e([M({readOnly:!0})],Te.prototype,"canCreate",null),e([M()],Te.prototype,"canCreateVisible",null),e([M({readOnly:!0})],Te.prototype,"canUpdate",null),e([M()],Te.prototype,"canUpdateVisible",null),e([M()],Te.prototype,"featureTemplatesLayers",null),e([M()],Te.prototype,"editorItems",void 0),e([M()],Te.prototype,"editorItemsLayerMap",void 0),e([M()],Te.prototype,"effectiveSelectionManager",null),e([M({readOnly:!0})],Te.prototype,"failures",void 0),e([M()],Te.prototype,"hideTemplatesForInactiveLayers",void 0),e([M({type:G})],Te.prototype,"attachmentsViewModel",void 0),e([M()],Te.prototype,"featureFormViewModel",null),e([M()],Te.prototype,"formViewModel",null),e([M()],Te.prototype,"utilityNetworkAssociationAddAssociationViewModel",null),e([M({type:fe})],Te.prototype,"featureTemplatesViewModel",void 0),e([M({type:O})],Te.prototype,"labelOptions",null),e([M()],Te.prototype,"layerInfos",void 0),e([M()],Te.prototype,"useLegacyCreateTools",null),e([M()],Te.prototype,"isUsingLegacyCreateTools",null),e([M()],Te.prototype,"ownSketchViewModel",void 0),e([M()],Te.prototype,"selectionListViewModel",void 0),e([M()],Te.prototype,"selectionManager",void 0),e([M()],Te.prototype,"selectionToolbarViewModel",void 0),e([M()],Te.prototype,"sketchOptions",void 0),e([M()],Te.prototype,"sketchViewModel",null),e([M({type:q,nonNullable:!0})],Te.prototype,"snappingOptions",void 0),e([M()],Te.prototype,"spinnerViewModel",void 0),e([M()],Te.prototype,"state",null),e([M({readOnly:!0})],Te.prototype,"syncing",null),e([M()],Te.prototype,"syncViewSelection",void 0),e([M()],Te.prototype,"updating",null),e([M({type:P})],Te.prototype,"tooltipOptions",null),e([M({type:R})],Te.prototype,"valueOptions",null),e([M()],Te.prototype,"view",null),e([M()],Te.prototype,"canZoomTo",null),e([M()],Te.prototype,"pageStack",void 0),e([M()],Te.prototype,"showDiscardEditsPrompt",void 0),e([M()],Te.prototype,"showConfirmationPrompt",void 0),e([M()],Te.prototype,"_candidateCommitted",void 0),e([M()],Te.prototype,"page",null),e([M()],Te.prototype,"featureFormDisabled",null),e([M()],Te.prototype,"featureFormHasAssociation",null),e([M()],Te.prototype,"canGoBack",null),e([M()],Te.prototype,"shouldShowDeleteButton",null),e([M()],Te.prototype,"hasPendingEdits",null),e([M()],Te.prototype,"snappingManager",null),Te=e([T("esri.widgets.Editor.EditorViewModel")],Te);const Fe=Te;export{Fe as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../core/Error.js";import{makeHandle as i,handlesGroup as r,destroyHandle as a}from"../../core/handleUtils.js";import"../../core/has.js";import{destroyMaybe as o}from"../../core/maybe.js";import{debounce as s}from"../../core/promiseUtils.js";import{watch as l,on as n,whenOnce as p,initial as d}from"../../core/reactiveUtils.js";import{property as u,subclass as c}from"../../core/accessorSupport/decorators.js";import h from"../../layers/GraphicsLayer.js";import{getDrawHelpMessage as m}from"../../views/draw/support/helpMessageUtils.js";import y from"../../views/draw/support/HighlightHelper.js";import w from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as g}from"../../views/support/HighlightDefaults.js";import f from"./Edits.js";import v from"./SplitFeatureWorkflowData.js";import _ from"./Workflow.js";import{activeSketchToolDrawsUnsupportedCurve as F,createWorkflowSteps as M,swapForEditingSession as b,updateGraphicSymbolWhenRequired as S,makeMinimalAttributes as k}from"./workflowUtils.js";import{assertViewNot3D as T,assertSplitWorkflowCapabilities as I}from"./support/errors.js";import{getCompatibleSpitterGeometryType as V,ensureSplittableGeometry as G,makeNewFeatureAttributes as E,splitGeometry as H,canSplitByPoint as C,isSplitterGeometry as j}from"./support/splitFeatureUtils.js";import x from"../FeatureForm/FeatureFormViewModel.js";import U from"../Sketch/SketchViewModel.js";import{getDrawToolGeometryTypeFromCreateTool as L}from"../Sketch/support/sketchUtils.js";var W;const O=Symbol(),z=Symbol();let P=W=class extends _{constructor(e){super(e),this.defaultSplitterGeometryType=null,this.type="split-feature",this._activeFeature=null,this._formViewModel=null,this._graphicsLayer=null,this._highlightHelper=null,this._lastSplitterGeometryWasInvalid=!1,this._sketchViewModel=null,this._webStyleCache=new Map}initialize(){const e=this.data.viewModel.view;this._highlightHelper=e?new y({view:e,highlightName:g}):null,this._initializeFormViewModel();const t=this._initializeGraphicsLayer();this._initializeSketchViewModel(t)}destroy(){const e=this._graphicsLayer,{view:t}=this.data.viewModel;t?.destroyed||t?.map.remove(e),this._graphicsLayer=o(this._graphicsLayer),this._formViewModel.destroy(),this._sketchViewModel.destroy(),this._highlightHelper?.destroy()}get activeFeature(){return this._activeFeature}get allowSave(){const{data:e}=this;return null!=e.existingFeatureEdits&&null!=e.newFeatureEdits&&!this.updating}get availableCreateTools(){const e=["polyline","polygon","rectangle","circle","freehandPolyline","freehandPolygon"];switch(this.data.editorItem.layer.geometryType){case"polygon":case"multipoint":return e;case"polyline":return["point",...e];default:return[]}}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return!!this.data.editorItem?.hasInvalidFormTemplate}get hasPreviousStep(){return null!==this._activeFeature||this._stepIndex>0}get helpMessage(){const{activeCreateToolDrawMode:e,activeTool:t,createGraphic:i,drawTool:r,isUsingLegacyCreateTools:a}=this._sketchViewModel;if(!a)return r?.helpMessageKey??"noTool";const o=L(t);return"mesh"!==o?m(o,i?.geometry,e):void 0}get layer(){return this.data.editorItem.layer}get parent(){return this.data.parent}get sketchUpdateOptions(){return{enableScaling:!this.curveResizeDisabled,multipleSelectionEnabled:!1}}get updating(){return this._updatingHandles.updating||this._formViewModel.updating||this._sketchViewModel.updating}get noticeMessage(){return this._splittingMayIntroduceCurves&&F(this._sketchViewModel,this.data.editorItem)?"curveToolDensifyWarning":this._lastSplitterGeometryWasInvalid?"invalidSplitterGeometry":void 0}get _splittingMayIntroduceCurves(){return"polygon"===this.data.editorItem.layer.geometryType}async back(e){return this.activeFeature?await this.setActiveFeature(null):await super.back(e)}static create(e){const{applyEdits:i,applyEditsFeatureService:r,defaultSplitterGeometryType:a,startAt:o,...s}=e;if(T(e.viewModel,"split-feature"),I(s.editorItem),"reviewing-features"===o){if(!s.splitterGeometry)throw new t("editing:split-geometry-required","Must provide the split geometry to start at the 'reviewing-features' step.");const e=V(G(s.feature.geometry),s.splitterGeometry.type);if(s.splitterGeometry.type!==e)throw new t("editing:incompatible-split-geometries",`Geometry of type '${s.splitterGeometry.type}' cannot be used to split geometry of type '${s.feature.geometry?.type}'.`)}const l=new W({data:new v(s),defaultSplitterGeometryType:a,onCommit:D(e.applyEdits)});return l._set("steps",W._createWorkflowSteps(l,o)),l}async enter(){}exit(){if("reviewing-features"!==this.stepId)throw new t("editing:invalid-exit-state","The SplitFeatureWorkflow can only be exited when in the 'reviewing-features' step.")}async setActiveFeature(e){const i=this._activeFeature;if(e===i)return;const r=this.data,a=i?r.getEditsForFeature(i):null;if(a&&(a.submittable=this._formViewModel.submittable),this._activeFeature=e,null==e)return;const o=this.data.getRoleForFeature(e);if(!o)throw new t("editing:unknown-feature","The provided feature is not part of this workflow.");await this._setFeatureOnFormViewModel(e,o)}async start(){return await super.start(),this._makeSketchController()}async _createAndInitializeEdits({newPart:e,remainingPart:t}){const{data:i}=this,r=i.feature,a=this._formViewModel,o=r.clone();o.geometry=t;const s=new f({feature:o});i.existingFeatureEdits=s,s.trackChanges(i.initialFeature),await this._setFeatureOnFormViewModel(o,"existing"),s.submittable=a.submittable;const l=r.clone();l.geometry=e,l.attributes=E(r.attributes,i.editorItem.layer);const n=new f({feature:l});return i.newFeatureEdits=n,n.trackChanges(),await this._setFeatureOnFormViewModel(l,"new"),n.submittable=a.submittable,{featureToCreate:l,featureToUpdate:o}}static _createWorkflowSteps(e,i="drawing-splitter-geometry"){const{data:r}=e;return M(["drawing-splitter-geometry","reviewing-features"],i,{"drawing-splitter-geometry":()=>({id:"drawing-splitter-geometry",async setUp(){const i=G(r.feature.geometry),a=V(i,e.defaultSplitterGeometryType),{snappingManager:o}=r;C(i)&&o&&e.addHandles(R(o,e.layer));const s=e._sketchViewModel;e.addHandles([n(()=>s,"create",async i=>{if("start"===i.state&&e._lastSplitterGeometryWasInvalid&&(e._lastSplitterGeometryWasInvalid=!1),"complete"===i.state){e._graphicsLayer.removeAll();const o=i.graphic?.geometry;try{if(!j(o))throw new t("editing:invalid-split-geometry","The geometry produced by the Sketch operation cannot be used for splitting.");r.splitterGeometry=o,r.splitResult=await e._updatingHandles.addPromise(e._executeSplit(o)),await e.next()}catch(a){e._lastSplitterGeometryWasInvalid=!0,await s.create(i.tool)}}}),l(()=>s.activeTool,(t,i)=>{"point"===t&&!e.hasHandles(O)&&o?e.addHandles(N(o,e.layer),O):"point"===i&&e.removeHandles(O)})],this.id),await s.create(a)},async tearDown(){e.removeHandles(this.id)}}),"reviewing-features":()=>({id:"reviewing-features",async setUp(){const i=r.splitterGeometry;if(!i)throw new t("editing:missing-splitter-geometry","The `splitterGeometry` property of the workflow's data must be set in order to start the 'reviewing-features' step.");const a=r.splitResult??await e._executeSplit(i),{featureToCreate:o,featureToUpdate:s}=await e._createAndInitializeEdits(a),l=await e._displayFeatureGraphics(s,o);e.addHandles(l,this.id)},async tearDown(){e.removeHandles(this.id)}})})}async _displayFeatureGraphics(e,t){const{data:a,_graphicsLayer:o}=this,n=a.viewModel.view,p=[];if(!e||!t||!n)return i();const d=s(i=>Promise.all([S(e,this._webStyleCache,i),S(t,this._webStyleCache,i)]));return await d("2d"===n.type?n.scale:null),"2d"===n.type&&p.push(l(()=>n.scale,e=>d(e))),o.add(t),p.push(i(()=>o.remove(t))),p.push(await b(o,n,a.feature,e)),r(p)}async _executeSplit(e){const{data:i}=this,{feature:r}=i,a=r.geometry;if(!a)throw new t("editing:feature-has-no-geometry","Cannot split the provided feature as it has no geometry.");const o=await H(a,e);if(!o||!o.newPart)throw new t("editing:split-failed","The split operation did not produce a valid result.");return o}_initializeFormViewModel(){const{data:e,_webStyleCache:t}=this,i=e.viewModel.view,r=new x({formTemplate:e.editorItem.formTemplate,highlightHelper:this._highlightHelper,map:i?.map,spatialReference:i?.spatialReference,timeZone:e.timeZone});this._formViewModel=r,this.addHandles(n(()=>r,"value-change",({feature:r,fieldName:a,value:o})=>{r&&(e.getEditsForFeature(r)?.setAttribute(a,o),S(r,t,i?.scale))}))}_initializeGraphicsLayer(){const{data:e}=this,{view:t}=e.viewModel,i=new h({elevationInfo:e.editorItem.layer.elevationInfo,internal:!0,listMode:"hide",title:"splitFeatureWorkflow-internal"});return this._graphicsLayer=i,t?.map.add(i),i}_initializeSketchViewModel(e){const{data:t}=this,{view:i}=t.viewModel;this._sketchViewModel=new U({layer:e,creationMode:"single",sketchOptions:t.sketchOptions,snappingManager:t.snappingManager,useLegacyCreateTools:t.viewModel.useLegacyCreateTools,updateOnGraphicClick:!1,defaultUpdateOptions:this.sketchUpdateOptions,view:i})}_makeSketchController(){return{enter:async()=>this.addHandles(Z(this)),exit:()=>this.removeHandles(z),viewModel:this._sketchViewModel}}async _setFeatureOnFormViewModel(e,t){const{data:i}=this,r=this._formViewModel;r.feature=e,"existing"===t?(r.editType="UPDATE",r.overrideInitialFeature(i.initialFeature)):r.editType="INSERT",await p(()=>!r.updating)}get test(){}};e([u()],P.prototype,"activeFeature",null),e([u()],P.prototype,"allowSave",null),e([u()],P.prototype,"availableCreateTools",null),e([u()],P.prototype,"defaultSplitterGeometryType",void 0),e([u()],P.prototype,"formViewModel",null),e([u()],P.prototype,"hasInvalidFormTemplate",null),e([u()],P.prototype,"hasPreviousStep",null),e([u()],P.prototype,"helpMessage",null),e([u()],P.prototype,"layer",null),e([u()],P.prototype,"parent",null),e([u()],P.prototype,"sketchUpdateOptions",null),e([u()],P.prototype,"type",void 0),e([u()],P.prototype,"updating",null),e([u()],P.prototype,"noticeMessage",null),e([u()],P.prototype,"_activeFeature",void 0),e([u()],P.prototype,"_formViewModel",void 0),e([u()],P.prototype,"_graphicsLayer",void 0),e([u()],P.prototype,"_highlightHelper",void 0),e([u()],P.prototype,"_lastSplitterGeometryWasInvalid",void 0),e([u()],P.prototype,"_sketchViewModel",void 0),e([u()],P.prototype,"_splittingMayIntroduceCurves",null),P=W=e([c("esri.widgets.Editor.SplitFeatureWorkflow")],P);const A=P;function D(e){return async i=>{const{existingFeatureEdits:r,newFeatureEdits:a}=i,o=r?.feature?.cloneShallow(),s=a?.feature?.cloneShallow(),l=i.editorItem.layer;if(null==o||null==s)throw new t("editing:missing-features","Expected both a feature to update and a feature to add for the split operation.");r?.attributesModified||(o.attributes=k(o,i.editorItem.layer)),await e(l,{addFeatures:[s],updateFeatures:[o]})}}function R(e,t){if(e.options.featureSources.some(e=>e.layer===t))return i();const r=new w({enabled:!1,layer:t});return e.options.featureSources.add(r),i(()=>{e.options.featureSources.remove(r),r.destroy()})}function N(e,t){const{options:r}=e,a=r.enabled;r.enabled=!0;const o=r.featureEnabled;r.featureEnabled=!0;const s=r.distance;r.distance=15;const l=new Map;for(const i of r.featureSources)l.set(i,i.enabled),i.layer===t?i.enabled=!0:i.enabled=!1;return i(()=>{r.enabled=a,r.featureEnabled=o,r.distance=s;for(const[e,t]of l)e.enabled=t})}function Z(e){const t=e.data,{feature:o,viewModel:s}=t,{view:n}=s;if(!n)return i();const p=new y({view:n}),u=l(()=>e.stepId,e=>{switch(p.removeAll(),e){case"drawing-splitter-geometry":p.add(o);break;case"reviewing-features":p.add(t.existingFeatureEdits?.feature),p.add(t.newFeatureEdits?.feature)}},d),c=new y({view:n,highlightName:g}),h=l(()=>t.temporaryHighlightFeature,(t,i)=>{i&&i!==e.activeFeature&&c.remove(i),t&&c.add(t)}),m=l(()=>e.activeFeature,(e,i)=>{i&&i!==t.temporaryHighlightFeature&&c.remove(i),e&&c.add(e)});return r([u,h,m,a(p),a(c)])}export{A as default};
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../core/Error.js";import{makeHandle as i,handlesGroup as r,destroyHandle as a}from"../../core/handleUtils.js";import"../../core/has.js";import{destroyMaybe as o}from"../../core/maybe.js";import{debounce as s}from"../../core/promiseUtils.js";import{watch as n,on as l,whenOnce as p,initial as d}from"../../core/reactiveUtils.js";import{property as u,subclass as c}from"../../core/accessorSupport/decorators.js";import h from"../../layers/GraphicsLayer.js";import{getDrawHelpMessage as m}from"../../views/draw/support/helpMessageUtils.js";import y from"../../views/draw/support/HighlightHelper.js";import w from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as g}from"../../views/support/HighlightDefaults.js";import f from"./Edits.js";import v from"./SplitFeatureWorkflowData.js";import _ from"./Workflow.js";import{activeSketchToolDrawsUnsupportedCurve as F,containsUnsupportedCurve as M,createWorkflowSteps as b,swapForEditingSession as S,updateGraphicSymbolWhenRequired as k,makeMinimalAttributes as T}from"./workflowUtils.js";import{assertViewNot3D as I,assertSplitWorkflowCapabilities as V}from"./support/errors.js";import{getCompatibleSpitterGeometryType as E,ensureSplittableGeometry as G,makeNewFeatureAttributes as H,splitGeometry as C,canSplitByPoint as j,isSplitterGeometry as x}from"./support/splitFeatureUtils.js";import U from"../FeatureForm/FeatureFormViewModel.js";import L from"../Sketch/SketchViewModel.js";import{getDrawToolGeometryTypeFromCreateTool as W}from"../Sketch/support/sketchUtils.js";var O;const P=Symbol(),z=Symbol();let A=O=class extends _{constructor(e){super(e),this.defaultSplitterGeometryType=null,this.type="split-feature",this._activeFeature=null,this._formViewModel=null,this._graphicsLayer=null,this._highlightHelper=null,this._lastSplitterGeometryWasInvalid=!1,this._sketchViewModel=null,this._webStyleCache=new Map}initialize(){const e=this.data.viewModel.view;this._highlightHelper=e?new y({view:e,highlightName:g}):null,this._initializeFormViewModel();const t=this._initializeGraphicsLayer();this._initializeSketchViewModel(t)}destroy(){const e=this._graphicsLayer,{view:t}=this.data.viewModel;t?.destroyed||t?.map.remove(e),this._graphicsLayer=o(this._graphicsLayer),this._formViewModel.destroy(),this._sketchViewModel.destroy(),this._highlightHelper?.destroy()}get activeFeature(){return this._activeFeature}get allowSave(){const{data:e}=this;return null!=e.existingFeatureEdits&&null!=e.newFeatureEdits&&!this.updating}get availableCreateTools(){const e=["polyline","polygon","rectangle","circle","freehandPolyline","freehandPolygon"];switch(this.data.editorItem.layer.geometryType){case"polygon":case"multipoint":return e;case"polyline":return["point",...e];default:return[]}}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return!!this.data.editorItem?.hasInvalidFormTemplate}get hasPreviousStep(){return null!==this._activeFeature||this._stepIndex>0}get helpMessage(){const{activeCreateToolDrawMode:e,activeTool:t,createGraphic:i,drawTool:r,isUsingLegacyCreateTools:a}=this._sketchViewModel;if(!a)return r?.helpMessageKey??"noTool";const o=W(t);return"mesh"!==o?m(o,i?.geometry,e):void 0}get layer(){return this.data.editorItem.layer}get parent(){return this.data.parent}get sketchUpdateOptions(){return{enableScaling:!this.curveResizeDisabled,multipleSelectionEnabled:!1}}get updating(){return this._updatingHandles.updating||this._formViewModel.updating||this._sketchViewModel.updating}get noticeMessage(){return this._splittingMayIntroduceCurves&&F(this._sketchViewModel,this.data.editorItem)?"curveToolDensifyWarning":this._lastSplitterGeometryWasInvalid?"invalidSplitterGeometry":void 0}get _splittingMayIntroduceCurves(){return"polygon"===this.data.editorItem.layer.geometryType}async back(e){return this.activeFeature?await this.setActiveFeature(null):await super.back(e)}static create(e){const{applyEdits:i,applyEditsFeatureService:r,defaultSplitterGeometryType:a,startAt:o,...s}=e;if(I(e.viewModel,"split-feature"),V(s.editorItem),"reviewing-features"===o){if(!s.splitterGeometry)throw new t("editing:split-geometry-required","Must provide the split geometry to start at the 'reviewing-features' step.");const e=E(G(s.feature.geometry),s.splitterGeometry.type);if(s.splitterGeometry.type!==e)throw new t("editing:incompatible-split-geometries",`Geometry of type '${s.splitterGeometry.type}' cannot be used to split geometry of type '${s.feature.geometry?.type}'.`)}const n=new O({data:new v(s),defaultSplitterGeometryType:a,onCommit:R(e.applyEdits)});return n._set("steps",O._createWorkflowSteps(n,o)),n}async enter(){}exit(){if("reviewing-features"!==this.stepId)throw new t("editing:invalid-exit-state","The SplitFeatureWorkflow can only be exited when in the 'reviewing-features' step.")}async setActiveFeature(e){const i=this._activeFeature;if(e===i)return;const r=this.data,a=i?r.getEditsForFeature(i):null;if(a&&(a.submittable=this._formViewModel.submittable),this._activeFeature=e,null==e)return;const o=this.data.getRoleForFeature(e);if(!o)throw new t("editing:unknown-feature","The provided feature is not part of this workflow.");await this._setFeatureOnFormViewModel(e,o)}async commit(e){const{newFeatureEdits:t,existingFeatureEdits:i,editorItem:r}=this.data,a=[i?.feature,t?.feature].filter(e=>!!e);if(e&&M(a,r)){if(!await e("curveEditingDensifyPrompt"))return this.reset()}return super.commit()}async start(){return await super.start(),this._makeSketchController()}async _createAndInitializeEdits({newPart:e,remainingPart:t}){const{data:i}=this,r=i.feature,a=this._formViewModel,o=r.clone();o.geometry=t;const s=new f({feature:o});i.existingFeatureEdits=s,s.trackChanges(i.initialFeature),await this._setFeatureOnFormViewModel(o,"existing"),s.submittable=a.submittable;const n=r.clone();n.geometry=e,n.attributes=H(r.attributes,i.editorItem.layer);const l=new f({feature:n});return i.newFeatureEdits=l,l.trackChanges(),await this._setFeatureOnFormViewModel(n,"new"),l.submittable=a.submittable,{featureToCreate:n,featureToUpdate:o}}static _createWorkflowSteps(e,i="drawing-splitter-geometry"){const{data:r}=e;return b(["drawing-splitter-geometry","reviewing-features"],i,{"drawing-splitter-geometry":()=>({id:"drawing-splitter-geometry",async setUp(){const i=G(r.feature.geometry),a=E(i,e.defaultSplitterGeometryType),{snappingManager:o}=r;j(i)&&o&&e.addHandles(N(o,e.layer));const s=e._sketchViewModel;e.addHandles([l(()=>s,"create",async i=>{if("start"===i.state&&e._lastSplitterGeometryWasInvalid&&(e._lastSplitterGeometryWasInvalid=!1),"complete"===i.state){e._graphicsLayer.removeAll();const o=i.graphic?.geometry;try{if(!x(o))throw new t("editing:invalid-split-geometry","The geometry produced by the Sketch operation cannot be used for splitting.");r.splitterGeometry=o,r.splitResult=await e._updatingHandles.addPromise(e._executeSplit(o)),await e.next()}catch(a){e._lastSplitterGeometryWasInvalid=!0,await s.create(i.tool)}}}),n(()=>s.activeTool,(t,i)=>{"point"===t&&!e.hasHandles(P)&&o?e.addHandles(Z(o,e.layer),P):"point"===i&&e.removeHandles(P)})],this.id),await s.create(a)},async tearDown(){e.removeHandles(this.id)}}),"reviewing-features":()=>({id:"reviewing-features",async setUp(){const i=r.splitterGeometry;if(!i)throw new t("editing:missing-splitter-geometry","The `splitterGeometry` property of the workflow's data must be set in order to start the 'reviewing-features' step.");const a=r.splitResult??await e._executeSplit(i),{featureToCreate:o,featureToUpdate:s}=await e._createAndInitializeEdits(a),n=await e._displayFeatureGraphics(s,o);e.addHandles(n,this.id)},async tearDown(){e.removeHandles(this.id)}})})}async _displayFeatureGraphics(e,t){const{data:a,_graphicsLayer:o}=this,l=a.viewModel.view,p=[];if(!e||!t||!l)return i();const d=s(i=>Promise.all([k(e,this._webStyleCache,i),k(t,this._webStyleCache,i)]));return await d("2d"===l.type?l.scale:null),"2d"===l.type&&p.push(n(()=>l.scale,e=>d(e))),o.add(t),p.push(i(()=>o.remove(t))),p.push(await S(o,l,a.feature,e)),r(p)}async _executeSplit(e){const{data:i}=this,{feature:r}=i,a=r.geometry;if(!a)throw new t("editing:feature-has-no-geometry","Cannot split the provided feature as it has no geometry.");const o=await C(a,e);if(!o||!o.newPart)throw new t("editing:split-failed","The split operation did not produce a valid result.");return o}_initializeFormViewModel(){const{data:e,_webStyleCache:t}=this,i=e.viewModel.view,r=new U({formTemplate:e.editorItem.formTemplate,highlightHelper:this._highlightHelper,map:i?.map,spatialReference:i?.spatialReference,timeZone:e.timeZone});this._formViewModel=r,this.addHandles(l(()=>r,"value-change",({feature:r,fieldName:a,value:o})=>{r&&(e.getEditsForFeature(r)?.setAttribute(a,o),k(r,t,i?.scale))}))}_initializeGraphicsLayer(){const{data:e}=this,{view:t}=e.viewModel,i=new h({elevationInfo:e.editorItem.layer.elevationInfo,internal:!0,listMode:"hide",title:"splitFeatureWorkflow-internal"});return this._graphicsLayer=i,t?.map.add(i),i}_initializeSketchViewModel(e){const{data:t}=this,{view:i}=t.viewModel;this._sketchViewModel=new L({layer:e,creationMode:"single",sketchOptions:t.sketchOptions,snappingManager:t.snappingManager,useLegacyCreateTools:t.viewModel.useLegacyCreateTools,updateOnGraphicClick:!1,defaultUpdateOptions:this.sketchUpdateOptions,view:i})}_makeSketchController(){return{enter:async()=>this.addHandles($(this)),exit:()=>this.removeHandles(z),viewModel:this._sketchViewModel}}async _setFeatureOnFormViewModel(e,t){const{data:i}=this,r=this._formViewModel;r.feature=e,"existing"===t?(r.editType="UPDATE",r.overrideInitialFeature(i.initialFeature)):r.editType="INSERT",await p(()=>!r.updating)}get test(){}};e([u()],A.prototype,"activeFeature",null),e([u()],A.prototype,"allowSave",null),e([u()],A.prototype,"availableCreateTools",null),e([u()],A.prototype,"defaultSplitterGeometryType",void 0),e([u()],A.prototype,"formViewModel",null),e([u()],A.prototype,"hasInvalidFormTemplate",null),e([u()],A.prototype,"hasPreviousStep",null),e([u()],A.prototype,"helpMessage",null),e([u()],A.prototype,"layer",null),e([u()],A.prototype,"parent",null),e([u()],A.prototype,"sketchUpdateOptions",null),e([u()],A.prototype,"type",void 0),e([u()],A.prototype,"updating",null),e([u()],A.prototype,"noticeMessage",null),e([u()],A.prototype,"_activeFeature",void 0),e([u()],A.prototype,"_formViewModel",void 0),e([u()],A.prototype,"_graphicsLayer",void 0),e([u()],A.prototype,"_highlightHelper",void 0),e([u()],A.prototype,"_lastSplitterGeometryWasInvalid",void 0),e([u()],A.prototype,"_sketchViewModel",void 0),e([u()],A.prototype,"_splittingMayIntroduceCurves",null),A=O=e([c("esri.widgets.Editor.SplitFeatureWorkflow")],A);const D=A;function R(e){return async i=>{const{existingFeatureEdits:r,newFeatureEdits:a}=i,o=r?.feature?.cloneShallow(),s=a?.feature?.cloneShallow(),n=i.editorItem.layer;if(null==o||null==s)throw new t("editing:missing-features","Expected both a feature to update and a feature to add for the split operation.");r?.attributesModified||(o.attributes=T(o,i.editorItem.layer)),await e(n,{addFeatures:[s],updateFeatures:[o]})}}function N(e,t){if(e.options.featureSources.some(e=>e.layer===t))return i();const r=new w({enabled:!1,layer:t});return e.options.featureSources.add(r),i(()=>{e.options.featureSources.remove(r),r.destroy()})}function Z(e,t){const{options:r}=e,a=r.enabled;r.enabled=!0;const o=r.featureEnabled;r.featureEnabled=!0;const s=r.distance;r.distance=15;const n=new Map;for(const i of r.featureSources)n.set(i,i.enabled),i.layer===t?i.enabled=!0:i.enabled=!1;return i(()=>{r.enabled=a,r.featureEnabled=o,r.distance=s;for(const[e,t]of n)e.enabled=t})}function $(e){const t=e.data,{feature:o,viewModel:s}=t,{view:l}=s;if(!l)return i();const p=new y({view:l}),u=n(()=>e.stepId,e=>{switch(p.removeAll(),e){case"drawing-splitter-geometry":p.add(o);break;case"reviewing-features":p.add(t.existingFeatureEdits?.feature),p.add(t.newFeatureEdits?.feature)}},d),c=new y({view:l,highlightName:g}),h=n(()=>t.temporaryHighlightFeature,(t,i)=>{i&&i!==e.activeFeature&&c.remove(i),t&&c.add(t)}),m=n(()=>e.activeFeature,(e,i)=>{i&&i!==t.temporaryHighlightFeature&&c.remove(i),e&&c.add(e)});return r([u,h,m,a(p),a(c)])}export{D as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../Graphic.js";import{remove as i}from"../../core/arrayUtils.js";import a from"../../core/Error.js";import{makeHandle as o}from"../../core/handleUtils.js";import r from"../../core/Logger.js";import{abortMaybe as s}from"../../core/maybe.js";import{createResolver as n,onAbort as l,createAbortError as d,throwIfAborted as c,debounce as p}from"../../core/promiseUtils.js";import u from"../../core/Queue.js";import{whenOnce as w,watch as h,sync as f,on as g,when as v}from"../../core/reactiveUtils.js";import{last as k}from"../../core/SetUtils.js";import{property as m,subclass as y}from"../../core/accessorSupport/decorators.js";import{getGraphicLayer as W}from"../../graphic/graphicOriginUtils.js";import{isEditableLayer as A}from"../../layers/support/editableLayers.js";import{isFeatureLayer as _,isSubtypeSublayer as b,isSubtypeGroupLayer as S,isTable as C}from"../../layers/support/layerUtils.js";import{createFeatureServices as M}from"../../rest/featureService/utils.js";import F from"../../views/draw/support/HighlightHelper.js";import{ViewEventPriorities as U}from"../../views/input/InputManager.js";import{temporaryHighlightName as R}from"../../views/support/HighlightDefaults.js";import E from"./CreateFeaturesWorkflow.js";import I from"./MergeFeaturesWorkflow.js";import j from"./SplitFeatureWorkflow.js";import V from"./UpdateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as P}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as L}from"./UpdateRecordWorkflow.js";import N from"./UpdateWorkflowData.js";import O from"./Workflow.js";import{isFeatureFormViewModel as T,findEditorItemForLayer as x,isSplitFeatureWorkflow as D,workflowInfluencesOutcomeOfParent as H,isAnyUpdateLeafWorkflow as z,isUpdateRecordWorkflow as q,isParentWorkflow as G,findEditorItemForLayerOrThrow as Q,createWorkflowSteps as $,fetchCandidates as B,isUpdateFeaturesWorkflowOptions as J,toFeatureInfos as K,isMergeWorkflowOptions as X,isSplitWorkflowOptions as Y}from"./workflowUtils.js";import{assertFeaturesAreFromSameLayer as Z}from"./support/errors.js";import{findUtilityNetwork as ee,isGraphicForRelatableFeatureSupportedLayer as te}from"../Feature/support/featureUtils.js";var ie;let ae=ie=class extends O{constructor(e){super(e),this._workflowStack=new u(k),this._sketchStack=new u(k),this.data=void 0,this.type="update"}destroy(){this._drainWorkflowStack(e=>e.cancel({force:!0}))}get formViewModel(){return this.activeWorkflow?.formViewModel}get activeUtilityNetworkAssociationAddAssociationViewModel(){return"add-association"===this.activeWorkflow?.type?this.activeWorkflow.utilityNetworkAssociationAddAssociationViewModel:null}get activeSketchViewModel(){return this._sketchStack.peek()?.viewModel}get canDeleteAssociation(){const{formViewModel:e}=this;if(!this.activeWorkflow||!this.data.viewModel.view?.map||!T(e))return!1;const{activeAssociation:t,feature:i}=e;return!(!t||!i?.sourceLayer||!_(i?.sourceLayer)&&!b(i?.sourceLayer))}get activeWorkflow(){return this._workflowStack.last()}get updating(){return this._updatingHandles.updating||!!this.activeWorkflow?.updating}get hasPreviousStep(){const e=this.activeWorkflow?.formViewModel;return this._stepIndex>0||this.nestedWorkflowCount>1||this.activeWorkflow?.hasPreviousStep||"view"!==this.data.viewModel.attachmentsViewModel.mode||T(e)&&(null!=e.relationshipId||null!=e.associationId||null!=e.associatedLayer)}get hasUpdatableCandidates(){const{candidates:e,viewModel:t}=this.data;return e.some(({layer:e})=>x(t.editorItems,e)?.supportsUpdateWorkflow)}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return this.activeWorkflow?.shouldShowAttachments??!1}get shouldAllowAttachmentEditing(){return this.activeWorkflow?.shouldAllowAttachmentEditing??!1}get hasPendingEdits(){return Array.from(this._workflowStack).some(e=>e.hasPendingEdits)}get helpMessage(){return this.activeWorkflow?.helpMessage?this.activeWorkflow.helpMessage:"awaiting-feature-to-update"===this.stepId?"select":void 0}get noticeMessage(){return this.activeWorkflow?.noticeMessage}get reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return this.activeWorkflow?.hasInvalidFormTemplate??!1}get curveResizeDisabled(){return this.activeWorkflow?.curveResizeDisabled??!1}get curveUpdatesDisabled(){return this.activeWorkflow?.curveUpdatesDisabled??!1}async back(e=()=>Promise.resolve(!0)){const{activeWorkflow:t}=this,i=t?.formViewModel;if(T(i)){if(i?.activeRelationshipInput){const e=i.activeRelationshipInput;if(e.activeCategory)return void(e.activeCategory=null);if(null!=i.relationshipId)return void(i.relationshipId=null);if(e.showAllEnabled)return void(e.showAllEnabled=!1)}if("add-association"===t?.type){const{activeUtilityNetworkAssociationAddAssociationViewModel:e}=this;if(e?.filterOptionsVisible)return void(e.filterOptionsVisible=!1);e?.featureSpatialItems.length&&e.reset()}if(null!=i?.associatedLayer)return void(i.associatedLayer=null);if(null!=i?.associationId)return void(i.associationId=null)}if("create-features"===t?.type&&t.hasPreviousStep)await t.previous({cancelCurrentStep:!0});else{if(D(t)&&t.hasPreviousStep)return await t.back();if(t){if(t.hasPendingEdits){if(!await e())return}t.hasPreviousStep?await t.previous({cancelCurrentStep:!0}):await this.cancelActiveWorkflow({force:!0})}else this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0})}}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflowAndReconcile()}async commit(){await this._drainWorkflowStack(e=>e.commit()),await super.commit()}static create(e){const{startAt:t,applyEdits:i,applyEditsFeatureService:a,...o}=e,r=new ie({data:new N({applyEditsCallback:i,applyEditsFeatureServiceCallback:a,...o}),onCommit:async()=>{}});return r._set("steps",this._createWorkflowSteps(r,t)),r}async save(){const{formViewModel:e}=this;if(e&&(e.submit(),!e.submittable||T(e)&&re(e)))return;if(this.nestedWorkflowCount<2)return await this.commit();const{activeWorkflow:t}=this;if(await(t?.commit()),!H(t))return void await this._popWorkflowAndReconcile();this._popWorkflow();const i=this._workflowStack.peek();if(i&&i===t?.parent&&(await i.cancel(),this._popWorkflow(),0===this.nestedWorkflowCount))return await this.commit();await this._reconcileWorkflowStack()}async startCreatingRelatedRecord(e){const t=this._makeUpdatingResolver();try{const t=this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflowAndReconcile(t)}catch(i){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:i})}finally{t.resolve()}}async startMergingFeatures(e,t){const i=this._makeUpdatingResolver();try{const i=await this._createNestedMergeFeaturesWorkflow(e,t);await this._pushWorkflowAndReconcile(i)}catch(o){throw new a("editor:unable-to-start-merging","Could not begin merging the provided features.",{error:o})}finally{i.resolve()}}async startSplittingFeature(e,t){const i=this._makeUpdatingResolver();try{const i=await this._createNestedSplitFeatureWorkflow(e,t);await this._pushWorkflowAndReconcile(i)}catch(o){throw new a("editor:unable-to-start-splitting","Could not begin splitting the provided feature.",{error:o})}finally{i.resolve()}}async startUpdatingSingle(e,t){const i=this._makeUpdatingResolver();try{const i=await this._createNestedUpdateWorkflow(e,t);await this._pushWorkflowAndReconcile(i)}catch(o){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:o})}finally{i.resolve()}}async startUpdatingMultiple(e,t){const i=this._makeUpdatingResolver();try{const i=await this._createNestedUpdateFeaturesWorkflow(e,t);await this._pushWorkflowAndReconcile(i)}catch(o){throw new a("editor:unable-to-start-updating","Could not begin updating the provided features or table records.",{error:o})}finally{i.resolve()}}async startAddAssociation(e,t,i){const o=this._makeUpdatingResolver();try{const a=await this._createNestedAddAssociationWorkflow(e,t,i);await this._pushWorkflowAndReconcile(a)}catch(r){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:r})}finally{o.resolve()}}async deleteActiveFeatures(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");const t=z(e);if(t){e.data.stageDelete();const t=q(e)?e.data.edits.feature?[e.data.edits.feature]:[]:e.data.features;this._removeFeaturesFromCandidates(t)}else await e.cancel();this.nestedWorkflowCount<2?t?await this.commit():await this.cancel({force:!0}):(t&&await e.commit(),await this._popWorkflowAndReconcile(),await this._returnToPageWithContent())}async deleteActiveAssociation(){if(!this.canDeleteAssociation)throw new a("editor:nothing-to-delete","There is no association to delete");await this._deleteActiveAssociation(),await this._popWorkflowAndReconcile(),await this._returnToPageWithContent()}async cancelAll(){await this._drainWorkflowStack(e=>e.cancel({force:!0}))}async _deleteActiveAssociation(){const{formViewModel:e}=this;if(!T(e))throw new a("editing:failed-to-delete-association","The active workflow does not support editing associations");const{activeAssociation:t,feature:i}=e,{applyEditsFeatureServiceCallback:o,viewModel:r}=this.data,{sourceLayer:s}=i,n=b(s)&&s.parent?s.parent:s,l=M([n]),d=l.values().next().value?.featureService;if(!d)throw new a("editor:failed-to-delete-association","Could not retrieve feature service needed to delete association");await(d?.load());const c=r.view.map,p=ee(c,n);await(p?.networkSystemLayers.loadAssociationsTable());const u=p?.generateDeleteAssociations([t]);if(!u)throw new a("editor:failed-to-delete-association","Could not create payload needed to delete association");const w=p?.gdbVersion??void 0;await o(d,[u],{gdbVersion:w,globalIdUsed:!0})}_removeFeaturesFromCandidates(e){const{candidates:t}=this.data;if(0!==t.length&&0!==e.length)for(const a of e)i(t,a)}async _returnToPageWithContent(){const{formViewModel:e}=this;if(!T(e)||!e?.activeAssociationInput)return;const{activeAssociationInput:t,associationId:i}=e;await t.refresh(),t.associatedLayer&&!t.associatedFeatures?.length&&(e.associatedLayer=null),null==i||t.associatedFeatureInfos.size||(e.associationId=null)}_createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:i,applyEditsCallback:o,applyEditsFeatureServiceCallback:r,sketchOptions:s,snappingManager:n,viewModel:l}=this.data;if(!A(t))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const d=this._getCreationInfoForNestedCreateFeaturesWorkflow(e),c=d.template||d.initialFeature?"creating-features":"awaiting-feature-creation-info",p=G(this.activeWorkflow)?this.activeWorkflow:void 0;return E.create({addAttachmentsCallback:i,applyEdits:o,applyEditsFeatureService:r,creationInfo:d,isNested:!0,parent:p,sketchOptions:s,snappingManager:n,startAt:c,viewModel:l})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:i}=e;if(!A(i)||S(i))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const{viewModel:o}=this.data,r={layer:i,maxFeatures:1},s=this._makeRelatedRecordAttributes(e),n=o.getTemplatesForLayer(i);return n?.length>0?(r.attributeOverrides=s,1===n.length&&(r.template=n[0])):r.initialFeature=new t({sourceLayer:i,attributes:s}),r}async _createNestedUpdateWorkflow(e,t={}){const i=C(e.sourceLayer)?L:P,{applyEditsCallback:a,applyEditsFeatureServiceCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data,l=G(this.activeWorkflow)?this.activeWorkflow:void 0,d=await i.create({feature:e,parent:l,sketchOptions:r,snappingManager:s,viewModel:n,applyEdits:a,applyEditsFeatureService:o,featureFormCallbacks:{addRelatedRecord:e=>{this.startCreatingRelatedRecord(e)},editRelatedRecord:({relatedFeature:e,readOnly:t})=>{this.startUpdatingSingle(e,{readOnly:t})},selectAssociatedFeature:async({feature:e,association:t})=>await this.startUpdatingSingle(e,{association:t}),addAssociation:e=>{this.startAddAssociation(e.feature,e.utilityNetwork,e.associationType)}},...t});return await w(()=>!d.updating),d}async _createNestedUpdateFeaturesWorkflow(e,t={}){const{applyEditsCallback:i,applyEditsFeatureServiceCallback:a,viewModel:o}=this.data,r=V.create({applyEdits:i,applyEditsFeatureService:a,featureInfos:e,viewModel:o,...t});return await w(()=>!r.updating),r}async _createNestedAddAssociationWorkflow(e,t,i){const{AddAssociationWorkflow:o}=await import("./AddAssociationWorkflow.js"),{applyEditsCallback:r,applyEditsFeatureServiceCallback:s,viewModel:n}=this.data,l=G(this.activeWorkflow)?this.activeWorkflow:void 0,{formViewModel:d}=this,c=T(d)?d.activeAssociationInput:null;if(!c)throw new a("editing:unable-to-add-association","There is no active association input in the current workflow's form.");const p=await o.create({utilityNetwork:t,associationType:i,feature:e,parent:l,viewModel:n,associationInput:c,applyEdits:r,applyEditsFeatureService:s});return await w(()=>!p.updating),p}async _createNestedMergeFeaturesWorkflow(e,t){const{applyEditsCallback:i,applyEditsFeatureServiceCallback:a,viewModel:o}=this.data;Z(e);const r=Q(this.data.viewModel.editorItems,W(e[0])),s=G(this.activeWorkflow)?this.activeWorkflow:void 0,n=await I.create({applyEdits:i,applyEditsFeatureService:a,editorItem:r,features:e,parent:s,viewModel:o,...t});return await w(()=>!n.updating),n}async _createNestedSplitFeatureWorkflow(e,t){const{applyEditsCallback:i,applyEditsFeatureServiceCallback:a,sketchOptions:o,snappingManager:r,viewModel:s}=this.data,n=G(this.activeWorkflow)?this.activeWorkflow:void 0,l=Q(s.editorItems,e.sourceLayer),d=j.create({applyEdits:i,applyEditsFeatureService:a,editorItem:l,feature:e,parent:n,sketchOptions:o,snappingManager:r,viewModel:s,...t});return await w(()=>!d.updating),d}async _drainWorkflowStack(e){const t=this._workflowStack,i=[];for(const a of t){const t=e(a).finally(()=>a.destroy());this._updatingHandles.addPromise(t),i.push(t)}await Promise.all(i),this._workflowStack.clear(),this._sketchStack.clear()}_makeUpdatingResolver(){const e=n();return this._updatingHandles.addPromise(e.promise),e}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:i,relationshipId:a}=e;if(!te(t))return;const o=i.relationships?.find(e=>e.id===a);if(!o)return void this._logContinuingWithoutRelationshipWarning("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the destination layer.");if("origin"===o.role)return void this._logContinuingWithoutRelationshipWarning("unsupported-role","Creating new related records in the 'origin' table of a relationship is not yet supported");const r=t.sourceLayer;o.relatedTableId!==r.layerId&&this._logContinuingWithoutRelationshipWarning("invalid-argument-combination","The given parent feature does not belong to the relationship designated by the given relationship ID.");const s=r.relationships?.find(e=>e.id===a);if(!s)return void this._logContinuingWithoutRelationshipWarning("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=oe(r,s),l=t.getAttribute(n);l||this._logContinuingWithoutRelationshipWarning("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field.");const d=oe(i,o);return{[d]:l}}_popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop()}async _popWorkflowAndReconcile(){this._popWorkflow();const e=await this._reconcileWorkflowStack();if(e.failureCount>0)throw new a("editor:next-workflow-failed","Popped the top workflow, but the next workflow in the stack failed to activate",e)}async _pushWorkflowAndReconcile(e){const t=this._workflowRequiresSketchViewModel(e);this.activeWorkflow?.exit({removeSketchHandles:t});const i=this._sketchStack,o=await(e?.start()),r=i.peek();o?(r?.exit(),i.push(o)):i.push(this._cloneSketchController(r)),this._workflowStack.push(e);const s=await this._reconcileWorkflowStack();if(s.failureCount>0)throw new a("editor:failed-to-start-updating-feature","Failed to enter the provided workflow.",s)}async _reconcileWorkflowStack(){const e=this._workflowStack,t=this._sketchStack;try{const i=e.peek();return await(i?.enter()),await(t.peek()?.enter()),{activeWorkflow:i,failureCount:0}}catch(i){e.pop().destroy(),t.pop();const{activeWorkflow:a,failureCount:o}=await this._reconcileWorkflowStack();return{activeWorkflow:a,failureCount:o+1}}}_cloneSketchController(e){return{enter:e?.enter??(async()=>{}),exit:e?.exit??(async()=>{}),viewModel:e?.viewModel}}_workflowRequiresSketchViewModel(e){const{type:t}=e;return"update-feature"===t||"create-features"===t&&!C(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:i}=e;return $(["awaiting-feature-to-update","awaiting-update-feature-candidate","editing-existing-feature","adding-attachment","editing-attachment"],t,{"awaiting-feature-to-update":()=>({id:"awaiting-feature-to-update",async setUp(){const{spinnerViewModel:t}=i.viewModel,a=i.viewModel.view;a.activeTool=null;let r=null;e.addHandles(o(()=>{r=s(r)}),this.id),i.rootFeatures.removeAll(),i.candidates=[];const p=a.on("immediate-click",async o=>{const s=n();e._updatingHandles.addPromise(s.promise);try{t.location=o.mapPoint,t.visible=!0,r?.abort();const{editorItems:s}=i.viewModel;r=new AbortController;const n=await o.defer(()=>new Promise((e,t)=>{l(r?.signal,()=>t(d())),e(B(s,a,o,r?.signal))}));if(c(r),i.candidates=n.filter(e=>"fulfilled"===e.status).flatMap(e=>e.value).filter(e=>!e.isAggregate),t.visible=1===i.candidates.length,0===i.candidates.length)return;if(o.stopPropagation(),1===i.candidates.length){const{rootFeatures:a}=i;a.removeAll(),a.add(i.candidates[0]),e.go("editing-existing-feature").catch(()=>{}).then(()=>t.visible=!1)}else e.next()}finally{s.resolve()}},U.TOOL),u=v(()=>null!=a.activeTool,()=>e.cancel({force:!0}),{once:!0});a.focus(),e.addHandles([p,u],this.id)},async tearDown(){0===i.candidates.length&&(i.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){i.rootFeatures.removeAll();const{view:t}=i.viewModel;if(!t)return;const a=new F({view:t,highlightName:R});e.addHandles([g(()=>i.rootFeatures,"change",({added:e,removed:t})=>{t.forEach(e=>a.remove(e)),e.forEach(e=>a.add(e))},f),o(()=>a.removeAll())],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){await se(e);const{data:t}=e;t.viewModel.spinnerViewModel.visible=!1;const i=p(async()=>{await w(()=>!e.updating),e.previous()});e.addHandles([h(()=>e.nestedWorkflowCount,(e,t)=>{0===e&&0!==t&&i()},f)],this.id)},async tearDown(){await e.cancelAll(),e.removeHandles(this.id)}}),"adding-attachment":()=>({id:"adding-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){i.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){i.viewModel.attachmentsViewModel.mode="view"}})})}_logContinuingWithoutRelationshipWarning(e,t){r.getLogger(this).warn(`editor:${e}`,t,"The create operation will be allowed to proceed, but the resulting feature may not be related to the given parent feature.")}};function oe(e,{keyField:t}){return e.getField(t)?.name??t}function re(e){if(e.pendingSubtypeChoice)return!0;const t=e.getValues();return e.validateContingencyConstraints(t,{includeIncompleteViolations:!0}).length>0}async function se(e){const{data:t}=e,{rootWorkflowOptions:i}=t;if(J(i)){const{rootFeatureInfos:o}=t,r=o.length>0?o:K(t.rootFeatures.toArray());if(0===r.length)throw new a("editing:invalid-parameter","Must supply `rootFeatureInfos` or `rootFeatures` when root workflow type is 'update-multiple'");return await e.startUpdatingMultiple(r,i.props)}const{rootFeatures:o}=t,r=o.getItemAt(0);if(!r)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until one or more root features are provided");X(i)?await e.startMergingFeatures(o.toArray(),i.props):Y(i)?await e.startSplittingFeature(r,i.props):await e.startUpdatingSingle(r)}e([m()],ae.prototype,"formViewModel",null),e([m()],ae.prototype,"activeUtilityNetworkAssociationAddAssociationViewModel",null),e([m()],ae.prototype,"activeSketchViewModel",null),e([m()],ae.prototype,"canDeleteAssociation",null),e([m()],ae.prototype,"activeWorkflow",null),e([m()],ae.prototype,"updating",null),e([m()],ae.prototype,"data",void 0),e([m()],ae.prototype,"hasPreviousStep",null),e([m()],ae.prototype,"hasUpdatableCandidates",null),e([m()],ae.prototype,"nestedWorkflowCount",null),e([m()],ae.prototype,"shouldShowAttachments",null),e([m()],ae.prototype,"shouldAllowAttachmentEditing",null),e([m()],ae.prototype,"hasPendingEdits",null),e([m()],ae.prototype,"helpMessage",null),e([m()],ae.prototype,"noticeMessage",null),e([m()],ae.prototype,"reliesOnOwnerAdminPrivileges",null),e([m()],ae.prototype,"hasInvalidFormTemplate",null),e([m()],ae.prototype,"curveResizeDisabled",null),e([m()],ae.prototype,"curveUpdatesDisabled",null),ae=ie=e([y("esri.widgets.Editor.UpdateWorkflow")],ae);const ne=ae;export{ne as default};
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../Graphic.js";import{remove as i}from"../../core/arrayUtils.js";import a from"../../core/Error.js";import{makeHandle as o}from"../../core/handleUtils.js";import r from"../../core/Logger.js";import{abortMaybe as s}from"../../core/maybe.js";import{createResolver as n,onAbort as l,createAbortError as d,throwIfAborted as c,debounce as p}from"../../core/promiseUtils.js";import u from"../../core/Queue.js";import{whenOnce as w,watch as h,sync as f,on as g,when as v}from"../../core/reactiveUtils.js";import{last as k}from"../../core/SetUtils.js";import{property as m,subclass as y}from"../../core/accessorSupport/decorators.js";import{getGraphicLayer as W}from"../../graphic/graphicOriginUtils.js";import{isEditableLayer as A}from"../../layers/support/editableLayers.js";import{isFeatureLayer as _,isSubtypeSublayer as b,isSubtypeGroupLayer as S,isTable as C}from"../../layers/support/layerUtils.js";import{createFeatureServices as M}from"../../rest/featureService/utils.js";import F from"../../views/draw/support/HighlightHelper.js";import{ViewEventPriorities as U}from"../../views/input/InputManager.js";import{temporaryHighlightName as R}from"../../views/support/HighlightDefaults.js";import E from"./CreateFeaturesWorkflow.js";import I from"./MergeFeaturesWorkflow.js";import j from"./SplitFeatureWorkflow.js";import V from"./UpdateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as P}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as L}from"./UpdateRecordWorkflow.js";import N from"./UpdateWorkflowData.js";import O from"./Workflow.js";import{isFeatureFormViewModel as T,findEditorItemForLayer as x,isSplitFeatureWorkflow as D,workflowInfluencesOutcomeOfParent as H,isAnyUpdateLeafWorkflow as z,isUpdateRecordWorkflow as q,isParentWorkflow as G,findEditorItemForLayerOrThrow as Q,createWorkflowSteps as $,fetchCandidates as B,isUpdateFeaturesWorkflowOptions as J,toFeatureInfos as K,isMergeWorkflowOptions as X,isSplitWorkflowOptions as Y}from"./workflowUtils.js";import{assertFeaturesAreFromSameLayer as Z}from"./support/errors.js";import{findUtilityNetwork as ee,isGraphicForRelatableFeatureSupportedLayer as te}from"../Feature/support/featureUtils.js";var ie;let ae=ie=class extends O{constructor(e){super(e),this._workflowStack=new u(k),this._sketchStack=new u(k),this.data=void 0,this.type="update"}destroy(){this._drainWorkflowStack(e=>e.cancel({force:!0}))}get formViewModel(){return this.activeWorkflow?.formViewModel}get activeUtilityNetworkAssociationAddAssociationViewModel(){return"add-association"===this.activeWorkflow?.type?this.activeWorkflow.utilityNetworkAssociationAddAssociationViewModel:null}get activeSketchViewModel(){return this._sketchStack.peek()?.viewModel}get canDeleteAssociation(){const{formViewModel:e}=this;if(!this.activeWorkflow||!this.data.viewModel.view?.map||!T(e))return!1;const{activeAssociation:t,feature:i}=e;return!(!t||!i?.sourceLayer||!_(i?.sourceLayer)&&!b(i?.sourceLayer))}get activeWorkflow(){return this._workflowStack.last()}get updating(){return this._updatingHandles.updating||!!this.activeWorkflow?.updating}get hasPreviousStep(){const e=this.activeWorkflow?.formViewModel;return this._stepIndex>0||this.nestedWorkflowCount>1||this.activeWorkflow?.hasPreviousStep||"view"!==this.data.viewModel.attachmentsViewModel.mode||T(e)&&(null!=e.relationshipId||null!=e.associationId||null!=e.associatedLayer)}get hasUpdatableCandidates(){const{candidates:e,viewModel:t}=this.data;return e.some(({layer:e})=>x(t.editorItems,e)?.supportsUpdateWorkflow)}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return this.activeWorkflow?.shouldShowAttachments??!1}get shouldAllowAttachmentEditing(){return this.activeWorkflow?.shouldAllowAttachmentEditing??!1}get hasPendingEdits(){return Array.from(this._workflowStack).some(e=>e.hasPendingEdits)}get helpMessage(){return this.activeWorkflow?.helpMessage?this.activeWorkflow.helpMessage:"awaiting-feature-to-update"===this.stepId?"select":void 0}get noticeMessage(){return this.activeWorkflow?.noticeMessage}get reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return this.activeWorkflow?.hasInvalidFormTemplate??!1}get curveResizeDisabled(){return this.activeWorkflow?.curveResizeDisabled??!1}get curveUpdatesDisabled(){return this.activeWorkflow?.curveUpdatesDisabled??!1}async back(e=()=>Promise.resolve(!0)){const{activeWorkflow:t}=this,i=t?.formViewModel;if(T(i)){if(i?.activeRelationshipInput){const e=i.activeRelationshipInput;if(e.activeCategory)return void(e.activeCategory=null);if(null!=i.relationshipId)return void(i.relationshipId=null);if(e.showAllEnabled)return void(e.showAllEnabled=!1)}if("add-association"===t?.type){const{activeUtilityNetworkAssociationAddAssociationViewModel:e}=this;if(e?.filterOptionsVisible)return void(e.filterOptionsVisible=!1);e?.featureSpatialItems.length&&e.reset()}if(null!=i?.associatedLayer)return void(i.associatedLayer=null);if(null!=i?.associationId)return void(i.associationId=null)}if("create-features"===t?.type&&t.hasPreviousStep)await t.previous({cancelCurrentStep:!0});else{if(D(t)&&t.hasPreviousStep)return await t.back();if(t){if(t.hasPendingEdits){if(!await e())return}t.hasPreviousStep?await t.previous({cancelCurrentStep:!0}):await this.cancelActiveWorkflow({force:!0})}else this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0})}}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflowAndReconcile()}async commit(){await this._drainWorkflowStack(e=>e.commit()),await super.commit()}static create(e){const{startAt:t,applyEdits:i,applyEditsFeatureService:a,...o}=e,r=new ie({data:new N({applyEditsCallback:i,applyEditsFeatureServiceCallback:a,...o}),onCommit:async()=>{}});return r._set("steps",this._createWorkflowSteps(r,t)),r}async save(e){const{formViewModel:t}=this;if(t&&(t.submit(),!t.submittable||T(t)&&re(t)))return;if(this.nestedWorkflowCount<2)return await this.commit();const{activeWorkflow:i}=this;if(await(i?.commit(e)),!H(i))return void await this._popWorkflowAndReconcile();this._popWorkflow();const a=this._workflowStack.peek();if(a&&a===i?.parent&&(await a.cancel(),this._popWorkflow(),0===this.nestedWorkflowCount))return await this.commit();await this._reconcileWorkflowStack()}async startCreatingRelatedRecord(e){const t=this._makeUpdatingResolver();try{const t=this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflowAndReconcile(t)}catch(i){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:i})}finally{t.resolve()}}async startMergingFeatures(e,t){const i=this._makeUpdatingResolver();try{const i=await this._createNestedMergeFeaturesWorkflow(e,t);await this._pushWorkflowAndReconcile(i)}catch(o){throw new a("editor:unable-to-start-merging","Could not begin merging the provided features.",{error:o})}finally{i.resolve()}}async startSplittingFeature(e,t){const i=this._makeUpdatingResolver();try{const i=await this._createNestedSplitFeatureWorkflow(e,t);await this._pushWorkflowAndReconcile(i)}catch(o){throw new a("editor:unable-to-start-splitting","Could not begin splitting the provided feature.",{error:o})}finally{i.resolve()}}async startUpdatingSingle(e,t){const i=this._makeUpdatingResolver();try{const i=await this._createNestedUpdateWorkflow(e,t);await this._pushWorkflowAndReconcile(i)}catch(o){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:o})}finally{i.resolve()}}async startUpdatingMultiple(e,t){const i=this._makeUpdatingResolver();try{const i=await this._createNestedUpdateFeaturesWorkflow(e,t);await this._pushWorkflowAndReconcile(i)}catch(o){throw new a("editor:unable-to-start-updating","Could not begin updating the provided features or table records.",{error:o})}finally{i.resolve()}}async startAddAssociation(e,t,i){const o=this._makeUpdatingResolver();try{const a=await this._createNestedAddAssociationWorkflow(e,t,i);await this._pushWorkflowAndReconcile(a)}catch(r){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:r})}finally{o.resolve()}}async deleteActiveFeatures(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");const t=z(e);if(t){e.data.stageDelete();const t=q(e)?e.data.edits.feature?[e.data.edits.feature]:[]:e.data.features;this._removeFeaturesFromCandidates(t)}else await e.cancel();this.nestedWorkflowCount<2?t?await this.commit():await this.cancel({force:!0}):(t&&await e.commit(),await this._popWorkflowAndReconcile(),await this._returnToPageWithContent())}async deleteActiveAssociation(){if(!this.canDeleteAssociation)throw new a("editor:nothing-to-delete","There is no association to delete");await this._deleteActiveAssociation(),await this._popWorkflowAndReconcile(),await this._returnToPageWithContent()}async cancelAll(){await this._drainWorkflowStack(e=>e.cancel({force:!0}))}async _deleteActiveAssociation(){const{formViewModel:e}=this;if(!T(e))throw new a("editing:failed-to-delete-association","The active workflow does not support editing associations");const{activeAssociation:t,feature:i}=e,{applyEditsFeatureServiceCallback:o,viewModel:r}=this.data,{sourceLayer:s}=i,n=b(s)&&s.parent?s.parent:s,l=M([n]),d=l.values().next().value?.featureService;if(!d)throw new a("editor:failed-to-delete-association","Could not retrieve feature service needed to delete association");await(d?.load());const c=r.view.map,p=ee(c,n);await(p?.networkSystemLayers.loadAssociationsTable());const u=p?.generateDeleteAssociations([t]);if(!u)throw new a("editor:failed-to-delete-association","Could not create payload needed to delete association");const w=p?.gdbVersion??void 0;await o(d,[u],{gdbVersion:w,globalIdUsed:!0})}_removeFeaturesFromCandidates(e){const{candidates:t}=this.data;if(0!==t.length&&0!==e.length)for(const a of e)i(t,a)}async _returnToPageWithContent(){const{formViewModel:e}=this;if(!T(e)||!e?.activeAssociationInput)return;const{activeAssociationInput:t,associationId:i}=e;await t.refresh(),t.associatedLayer&&!t.associatedFeatures?.length&&(e.associatedLayer=null),null==i||t.associatedFeatureInfos.size||(e.associationId=null)}_createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:i,applyEditsCallback:o,applyEditsFeatureServiceCallback:r,sketchOptions:s,snappingManager:n,viewModel:l}=this.data;if(!A(t))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const d=this._getCreationInfoForNestedCreateFeaturesWorkflow(e),c=d.template||d.initialFeature?"creating-features":"awaiting-feature-creation-info",p=G(this.activeWorkflow)?this.activeWorkflow:void 0;return E.create({addAttachmentsCallback:i,applyEdits:o,applyEditsFeatureService:r,creationInfo:d,isNested:!0,parent:p,sketchOptions:s,snappingManager:n,startAt:c,viewModel:l})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:i}=e;if(!A(i)||S(i))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const{viewModel:o}=this.data,r={layer:i,maxFeatures:1},s=this._makeRelatedRecordAttributes(e),n=o.getTemplatesForLayer(i);return n?.length>0?(r.attributeOverrides=s,1===n.length&&(r.template=n[0])):r.initialFeature=new t({sourceLayer:i,attributes:s}),r}async _createNestedUpdateWorkflow(e,t={}){const i=C(e.sourceLayer)?L:P,{applyEditsCallback:a,applyEditsFeatureServiceCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data,l=G(this.activeWorkflow)?this.activeWorkflow:void 0,d=await i.create({feature:e,parent:l,sketchOptions:r,snappingManager:s,viewModel:n,applyEdits:a,applyEditsFeatureService:o,featureFormCallbacks:{addRelatedRecord:e=>{this.startCreatingRelatedRecord(e)},editRelatedRecord:({relatedFeature:e,readOnly:t})=>{this.startUpdatingSingle(e,{readOnly:t})},selectAssociatedFeature:async({feature:e,association:t})=>await this.startUpdatingSingle(e,{association:t}),addAssociation:e=>{this.startAddAssociation(e.feature,e.utilityNetwork,e.associationType)}},...t});return await w(()=>!d.updating),d}async _createNestedUpdateFeaturesWorkflow(e,t={}){const{applyEditsCallback:i,applyEditsFeatureServiceCallback:a,viewModel:o}=this.data,r=V.create({applyEdits:i,applyEditsFeatureService:a,featureInfos:e,viewModel:o,...t});return await w(()=>!r.updating),r}async _createNestedAddAssociationWorkflow(e,t,i){const{AddAssociationWorkflow:o}=await import("./AddAssociationWorkflow.js"),{applyEditsCallback:r,applyEditsFeatureServiceCallback:s,viewModel:n}=this.data,l=G(this.activeWorkflow)?this.activeWorkflow:void 0,{formViewModel:d}=this,c=T(d)?d.activeAssociationInput:null;if(!c)throw new a("editing:unable-to-add-association","There is no active association input in the current workflow's form.");const p=await o.create({utilityNetwork:t,associationType:i,feature:e,parent:l,viewModel:n,associationInput:c,applyEdits:r,applyEditsFeatureService:s});return await w(()=>!p.updating),p}async _createNestedMergeFeaturesWorkflow(e,t){const{applyEditsCallback:i,applyEditsFeatureServiceCallback:a,viewModel:o}=this.data;Z(e);const r=Q(this.data.viewModel.editorItems,W(e[0])),s=G(this.activeWorkflow)?this.activeWorkflow:void 0,n=await I.create({applyEdits:i,applyEditsFeatureService:a,editorItem:r,features:e,parent:s,viewModel:o,...t});return await w(()=>!n.updating),n}async _createNestedSplitFeatureWorkflow(e,t){const{applyEditsCallback:i,applyEditsFeatureServiceCallback:a,sketchOptions:o,snappingManager:r,viewModel:s}=this.data,n=G(this.activeWorkflow)?this.activeWorkflow:void 0,l=Q(s.editorItems,e.sourceLayer),d=j.create({applyEdits:i,applyEditsFeatureService:a,editorItem:l,feature:e,parent:n,sketchOptions:o,snappingManager:r,viewModel:s,...t});return await w(()=>!d.updating),d}async _drainWorkflowStack(e){const t=this._workflowStack,i=[];for(const a of t){const t=e(a).finally(()=>a.destroy());this._updatingHandles.addPromise(t),i.push(t)}await Promise.all(i),this._workflowStack.clear(),this._sketchStack.clear()}_makeUpdatingResolver(){const e=n();return this._updatingHandles.addPromise(e.promise),e}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:i,relationshipId:a}=e;if(!te(t))return;const o=i.relationships?.find(e=>e.id===a);if(!o)return void this._logContinuingWithoutRelationshipWarning("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the destination layer.");if("origin"===o.role)return void this._logContinuingWithoutRelationshipWarning("unsupported-role","Creating new related records in the 'origin' table of a relationship is not yet supported");const r=t.sourceLayer;o.relatedTableId!==r.layerId&&this._logContinuingWithoutRelationshipWarning("invalid-argument-combination","The given parent feature does not belong to the relationship designated by the given relationship ID.");const s=r.relationships?.find(e=>e.id===a);if(!s)return void this._logContinuingWithoutRelationshipWarning("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=oe(r,s),l=t.getAttribute(n);l||this._logContinuingWithoutRelationshipWarning("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field.");const d=oe(i,o);return{[d]:l}}_popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop()}async _popWorkflowAndReconcile(){this._popWorkflow();const e=await this._reconcileWorkflowStack();if(e.failureCount>0)throw new a("editor:next-workflow-failed","Popped the top workflow, but the next workflow in the stack failed to activate",e)}async _pushWorkflowAndReconcile(e){const t=this._workflowRequiresSketchViewModel(e);this.activeWorkflow?.exit({removeSketchHandles:t});const i=this._sketchStack,o=await(e?.start()),r=i.peek();o?(r?.exit(),i.push(o)):i.push(this._cloneSketchController(r)),this._workflowStack.push(e);const s=await this._reconcileWorkflowStack();if(s.failureCount>0)throw new a("editor:failed-to-start-updating-feature","Failed to enter the provided workflow.",s)}async _reconcileWorkflowStack(){const e=this._workflowStack,t=this._sketchStack;try{const i=e.peek();return await(i?.enter()),await(t.peek()?.enter()),{activeWorkflow:i,failureCount:0}}catch(i){e.pop().destroy(),t.pop();const{activeWorkflow:a,failureCount:o}=await this._reconcileWorkflowStack();return{activeWorkflow:a,failureCount:o+1}}}_cloneSketchController(e){return{enter:e?.enter??(async()=>{}),exit:e?.exit??(async()=>{}),viewModel:e?.viewModel}}_workflowRequiresSketchViewModel(e){const{type:t}=e;return"update-feature"===t||"create-features"===t&&!C(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:i}=e;return $(["awaiting-feature-to-update","awaiting-update-feature-candidate","editing-existing-feature","adding-attachment","editing-attachment"],t,{"awaiting-feature-to-update":()=>({id:"awaiting-feature-to-update",async setUp(){const{spinnerViewModel:t}=i.viewModel,a=i.viewModel.view;a.activeTool=null;let r=null;e.addHandles(o(()=>{r=s(r)}),this.id),i.rootFeatures.removeAll(),i.candidates=[];const p=a.on("immediate-click",async o=>{const s=n();e._updatingHandles.addPromise(s.promise);try{t.location=o.mapPoint,t.visible=!0,r?.abort();const{editorItems:s}=i.viewModel;r=new AbortController;const n=await o.defer(()=>new Promise((e,t)=>{l(r?.signal,()=>t(d())),e(B(s,a,o,r?.signal))}));if(c(r),i.candidates=n.filter(e=>"fulfilled"===e.status).flatMap(e=>e.value).filter(e=>!e.isAggregate),t.visible=1===i.candidates.length,0===i.candidates.length)return;if(o.stopPropagation(),1===i.candidates.length){const{rootFeatures:a}=i;a.removeAll(),a.add(i.candidates[0]),e.go("editing-existing-feature").catch(()=>{}).then(()=>t.visible=!1)}else e.next()}finally{s.resolve()}},U.TOOL),u=v(()=>null!=a.activeTool,()=>e.cancel({force:!0}),{once:!0});a.focus(),e.addHandles([p,u],this.id)},async tearDown(){0===i.candidates.length&&(i.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){i.rootFeatures.removeAll();const{view:t}=i.viewModel;if(!t)return;const a=new F({view:t,highlightName:R});e.addHandles([g(()=>i.rootFeatures,"change",({added:e,removed:t})=>{t.forEach(e=>a.remove(e)),e.forEach(e=>a.add(e))},f),o(()=>a.removeAll())],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){await se(e);const{data:t}=e;t.viewModel.spinnerViewModel.visible=!1;const i=p(async()=>{await w(()=>!e.updating),e.previous()});e.addHandles([h(()=>e.nestedWorkflowCount,(e,t)=>{0===e&&0!==t&&i()},f)],this.id)},async tearDown(){await e.cancelAll(),e.removeHandles(this.id)}}),"adding-attachment":()=>({id:"adding-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){i.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){i.viewModel.attachmentsViewModel.mode="view"}})})}_logContinuingWithoutRelationshipWarning(e,t){r.getLogger(this).warn(`editor:${e}`,t,"The create operation will be allowed to proceed, but the resulting feature may not be related to the given parent feature.")}};function oe(e,{keyField:t}){return e.getField(t)?.name??t}function re(e){if(e.pendingSubtypeChoice)return!0;const t=e.getValues();return e.validateContingencyConstraints(t,{includeIncompleteViolations:!0}).length>0}async function se(e){const{data:t}=e,{rootWorkflowOptions:i}=t;if(J(i)){const{rootFeatureInfos:o}=t,r=o.length>0?o:K(t.rootFeatures.toArray());if(0===r.length)throw new a("editing:invalid-parameter","Must supply `rootFeatureInfos` or `rootFeatures` when root workflow type is 'update-multiple'");return await e.startUpdatingMultiple(r,i.props)}const{rootFeatures:o}=t,r=o.getItemAt(0);if(!r)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until one or more root features are provided");X(i)?await e.startMergingFeatures(o.toArray(),i.props):Y(i)?await e.startSplittingFeature(r,i.props):await e.startUpdatingSingle(r)}e([m()],ae.prototype,"formViewModel",null),e([m()],ae.prototype,"activeUtilityNetworkAssociationAddAssociationViewModel",null),e([m()],ae.prototype,"activeSketchViewModel",null),e([m()],ae.prototype,"canDeleteAssociation",null),e([m()],ae.prototype,"activeWorkflow",null),e([m()],ae.prototype,"updating",null),e([m()],ae.prototype,"data",void 0),e([m()],ae.prototype,"hasPreviousStep",null),e([m()],ae.prototype,"hasUpdatableCandidates",null),e([m()],ae.prototype,"nestedWorkflowCount",null),e([m()],ae.prototype,"shouldShowAttachments",null),e([m()],ae.prototype,"shouldAllowAttachmentEditing",null),e([m()],ae.prototype,"hasPendingEdits",null),e([m()],ae.prototype,"helpMessage",null),e([m()],ae.prototype,"noticeMessage",null),e([m()],ae.prototype,"reliesOnOwnerAdminPrivileges",null),e([m()],ae.prototype,"hasInvalidFormTemplate",null),e([m()],ae.prototype,"curveResizeDisabled",null),e([m()],ae.prototype,"curveUpdatesDisabled",null),ae=ie=e([y("esri.widgets.Editor.UpdateWorkflow")],ae);const ne=ae;export{ne as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as t}from"tslib";import e from"../../core/Error.js";import{EventedAccessor as s}from"../../core/Evented.js";import{throwIfNotAbortError as i,createResolver as n}from"../../core/promiseUtils.js";import{property as o,subclass as r}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as a}from"../../core/support/UpdatingHandles.js";let p=class extends s{constructor(t){super(t),this._indexHistory=[],this._lastStepIndex=-1,this._stepIndex=-1,this._updatingHandles=new a,this._handleKeys={afterCommit:"after-commit",beforeCommit:"before-commit"},this.data=void 0,this.started=!1,this.steps=[],this.type=null,this._pendingOperation=null}destroy(){this._updatingHandles.destroy()}get curveResizeDisabled(){return!1}get curveUpdatesDisabled(){return!1}get formViewModel(){return null}get hasNextStep(){const{steps:t}=this;return!!(t&&this._stepIndex<t.filter(t=>!t.parent).length-1)}get hasPreviousStep(){return this._stepIndex>0}get reliesOnOwnerAdminPrivileges(){return!1}get hasInvalidFormTemplate(){return!1}get shouldShowAttachments(){return!1}get shouldAllowAttachmentEditing(){return!1}get stepId(){const{steps:t}=this,e=t&&t[this._stepIndex];return e&&e.id}get allowSave(){return!this.updating}get helpMessage(){}get noticeMessage(){}get hasPendingEdits(){return!1}get keyboardCancellationEnabled(){return!0}get saveActionLabel(){return"submit"}get sketchUpdateOptions(){return{}}get updating(){return this._updatingHandles.updating||!!this.formViewModel?.updating}async back(t=()=>Promise.resolve(!0)){if(this.hasPendingEdits){if(!await t())return}this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0})}async cancel(t={force:!0}){return!1!==t.force?this._cancel(t):new Promise((s,i)=>{this.emit("cancel-request",{controller:{allow:()=>{this._cancel({...t,force:!0}).then(s)},deny:()=>i(new e("workflow:cancel-denied","Request to cancel workflow was denied."))}})})}async commit(){this.removeHandles(this._handleKeys.beforeCommit),this.onCommit&&await this.onCommit(this.data),this.removeHandles(this._handleKeys.afterCommit),this.emit("commit")}async go(t){const{steps:e}=this,s=e.findIndex(e=>e.id===t);this._indexHistory.push(this._stepIndex),await this._go(s)}async next(){this._indexHistory.push(this._stepIndex),await this._go(this._stepIndex+1)}async previous(t={cancelCurrentStep:!1}){await this._go(this._indexHistory.pop(),t.cancelCurrentStep)}async reset(){await this._cancel({emitCancelEvent:!1}),await this.start()}async save(){await this.commit(),await this.reset()}async start(){this._set("started",!0);const t=-1===this._stepIndex?0:this._stepIndex;await this._go(t)}async _cancel({emitCancelEvent:t=!0,error:e}={}){this.started&&(this._set("started",!1),await this._transaction(()=>this.steps[this._stepIndex]?.tearDown({canceled:!0}))),this.removeHandles([this._handleKeys.afterCommit,this._handleKeys.beforeCommit]),this._resetIndexing(t),t&&this.emit("cancel",{error:e})}_go(t=-1,e=!1){return this._transaction(async()=>{const{steps:s}=this;if(!(t<=-1||t>=s.length)){if(!this.started)return this._stepIndex=t,void this._notifyStepProps();this._lastStepIndex>-1&&await s[this._lastStepIndex].tearDown({canceled:e});try{await s[t].setUp()}catch(n){i(n)}this._lastStepIndex=t,this._stepIndex=t,this._notifyStepProps()}})}async _transaction(t){const e=this._pendingOperation,s=n(),i=(e??Promise.resolve()).then(()=>s.promise);this._pendingOperation=i,this._updatingHandles.addPromise(i);try{e&&await e,await t()}finally{s.resolve(),i===this._pendingOperation&&(this._pendingOperation=null)}}_resetIndexing(t=!0){this._stepIndex=-1,this._lastStepIndex=-1,this._indexHistory.length=0,t&&this._notifyStepProps()}_notifyStepProps(){this.notifyChange("stepId"),this.notifyChange("hasPreviousStep"),this.notifyChange("hasNextStep")}};t([o()],p.prototype,"curveResizeDisabled",null),t([o()],p.prototype,"curveUpdatesDisabled",null),t([o()],p.prototype,"data",void 0),t([o()],p.prototype,"formViewModel",null),t([o()],p.prototype,"hasNextStep",null),t([o()],p.prototype,"hasPreviousStep",null),t([o()],p.prototype,"onCommit",void 0),t([o()],p.prototype,"reliesOnOwnerAdminPrivileges",null),t([o()],p.prototype,"hasInvalidFormTemplate",null),t([o()],p.prototype,"shouldShowAttachments",null),t([o()],p.prototype,"shouldAllowAttachmentEditing",null),t([o()],p.prototype,"started",void 0),t([o({readOnly:!0})],p.prototype,"stepId",null),t([o()],p.prototype,"steps",void 0),t([o({readOnly:!0})],p.prototype,"type",void 0),t([o()],p.prototype,"allowSave",null),t([o()],p.prototype,"helpMessage",null),t([o()],p.prototype,"noticeMessage",null),t([o()],p.prototype,"hasPendingEdits",null),t([o()],p.prototype,"keyboardCancellationEnabled",null),t([o()],p.prototype,"sketchUpdateOptions",null),t([o()],p.prototype,"updating",null),p=t([r("esri.widgets.Editor.Workflow")],p);const l=p;export{l as default};
|
|
2
|
+
import{__decorate as t}from"tslib";import e from"../../core/Error.js";import{EventedAccessor as s}from"../../core/Evented.js";import{throwIfNotAbortError as i,createResolver as n}from"../../core/promiseUtils.js";import{property as o,subclass as r}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as a}from"../../core/support/UpdatingHandles.js";let p=class extends s{constructor(t){super(t),this._indexHistory=[],this._lastStepIndex=-1,this._stepIndex=-1,this._updatingHandles=new a,this._handleKeys={afterCommit:"after-commit",beforeCommit:"before-commit"},this.data=void 0,this.started=!1,this.steps=[],this.type=null,this._pendingOperation=null}destroy(){this._updatingHandles.destroy()}get curveResizeDisabled(){return!1}get curveUpdatesDisabled(){return!1}get formViewModel(){return null}get hasNextStep(){const{steps:t}=this;return!!(t&&this._stepIndex<t.filter(t=>!t.parent).length-1)}get hasPreviousStep(){return this._stepIndex>0}get reliesOnOwnerAdminPrivileges(){return!1}get hasInvalidFormTemplate(){return!1}get shouldShowAttachments(){return!1}get shouldAllowAttachmentEditing(){return!1}get stepId(){const{steps:t}=this,e=t&&t[this._stepIndex];return e&&e.id}get allowSave(){return!this.updating}get helpMessage(){}get noticeMessage(){}get hasPendingEdits(){return!1}get keyboardCancellationEnabled(){return!0}get saveActionLabel(){return"submit"}get sketchUpdateOptions(){return{}}get updating(){return this._updatingHandles.updating||!!this.formViewModel?.updating}async back(t=()=>Promise.resolve(!0)){if(this.hasPendingEdits){if(!await t())return}this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0})}async cancel(t={force:!0}){return!1!==t.force?this._cancel(t):new Promise((s,i)=>{this.emit("cancel-request",{controller:{allow:()=>{this._cancel({...t,force:!0}).then(s)},deny:()=>i(new e("workflow:cancel-denied","Request to cancel workflow was denied."))}})})}async commit(){this.removeHandles(this._handleKeys.beforeCommit),this.onCommit&&await this.onCommit(this.data),this.removeHandles(this._handleKeys.afterCommit),this.emit("commit")}async go(t){const{steps:e}=this,s=e.findIndex(e=>e.id===t);this._indexHistory.push(this._stepIndex),await this._go(s)}async next(){this._indexHistory.push(this._stepIndex),await this._go(this._stepIndex+1)}async previous(t={cancelCurrentStep:!1}){await this._go(this._indexHistory.pop(),t.cancelCurrentStep)}async reset(){await this._cancel({emitCancelEvent:!1}),await this.start()}async save(t){await this.commit(),await this.reset()}async start(){this._set("started",!0);const t=-1===this._stepIndex?0:this._stepIndex;await this._go(t)}async _cancel({emitCancelEvent:t=!0,error:e}={}){this.started&&(this._set("started",!1),await this._transaction(()=>this.steps[this._stepIndex]?.tearDown({canceled:!0}))),this.removeHandles([this._handleKeys.afterCommit,this._handleKeys.beforeCommit]),this._resetIndexing(t),t&&this.emit("cancel",{error:e})}_go(t=-1,e=!1){return this._transaction(async()=>{const{steps:s}=this;if(!(t<=-1||t>=s.length)){if(!this.started)return this._stepIndex=t,void this._notifyStepProps();this._lastStepIndex>-1&&await s[this._lastStepIndex].tearDown({canceled:e});try{await s[t].setUp()}catch(n){i(n)}this._lastStepIndex=t,this._stepIndex=t,this._notifyStepProps()}})}async _transaction(t){const e=this._pendingOperation,s=n(),i=(e??Promise.resolve()).then(()=>s.promise);this._pendingOperation=i,this._updatingHandles.addPromise(i);try{e&&await e,await t()}finally{s.resolve(),i===this._pendingOperation&&(this._pendingOperation=null)}}_resetIndexing(t=!0){this._stepIndex=-1,this._lastStepIndex=-1,this._indexHistory.length=0,t&&this._notifyStepProps()}_notifyStepProps(){this.notifyChange("stepId"),this.notifyChange("hasPreviousStep"),this.notifyChange("hasNextStep")}};t([o()],p.prototype,"curveResizeDisabled",null),t([o()],p.prototype,"curveUpdatesDisabled",null),t([o()],p.prototype,"data",void 0),t([o()],p.prototype,"formViewModel",null),t([o()],p.prototype,"hasNextStep",null),t([o()],p.prototype,"hasPreviousStep",null),t([o()],p.prototype,"onCommit",void 0),t([o()],p.prototype,"reliesOnOwnerAdminPrivileges",null),t([o()],p.prototype,"hasInvalidFormTemplate",null),t([o()],p.prototype,"shouldShowAttachments",null),t([o()],p.prototype,"shouldAllowAttachmentEditing",null),t([o()],p.prototype,"started",void 0),t([o({readOnly:!0})],p.prototype,"stepId",null),t([o()],p.prototype,"steps",void 0),t([o({readOnly:!0})],p.prototype,"type",void 0),t([o()],p.prototype,"allowSave",null),t([o()],p.prototype,"helpMessage",null),t([o()],p.prototype,"noticeMessage",null),t([o()],p.prototype,"hasPendingEdits",null),t([o()],p.prototype,"keyboardCancellationEnabled",null),t([o()],p.prototype,"sketchUpdateOptions",null),t([o()],p.prototype,"updating",null),p=t([r("esri.widgets.Editor.Workflow")],p);const l=p;export{l as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{isSome as i}from"../../../core/arrayUtils.js";import{abortHandle as s}from"../../../core/handleUtils.js";import{debounce as a}from"../../../core/promiseUtils.js";import r from"../../../core/ReactiveMap.js";import{whenOnce as o,watch as
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{isSome as i}from"../../../core/arrayUtils.js";import{abortHandle as s}from"../../../core/handleUtils.js";import{debounce as a}from"../../../core/promiseUtils.js";import r from"../../../core/ReactiveMap.js";import{whenOnce as o,watch as l}from"../../../core/reactiveUtils.js";import{property as n,subclass as p}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as d}from"../../../core/support/UpdatingHandles.js";import c from"../../../layers/GraphicsLayer.js";import{isSceneLayer as h}from"../../../layers/support/layerUtils.js";import u from"../../../views/interactive/sketch/SketchOptions.js";import{getVisualVariablesForLayer as y,updateGraphicSymbolWhenRequired as m,setVisualVariablesAndElevationInfoForUpdate as v,swapForEditingSession as g,visualVariableInteractiveUpdate as f,getSizeVariableAttribute as _,getRotationVariableAttribute as b}from"../workflowUtils.js";import w from"../../Sketch/SketchViewModel.js";const k=Symbol();let U=class extends t{constructor(e){super(e),this.features=[],this.onGeometriesUpdated=()=>{},this.onVisualVariableAttributesUpdated=()=>{},this.sketchOptions=new u,this.snappingManager=null,this.sourceLayer=null,this.view=null,this.viewModel=null,this.useLegacyCreateTools=!1,this._nextUpdateSubset=[],this._sketchGraphicsMap=new r,this._sketchLayer=null,this._updatingHandles=new d,this._visualVariableAttributes=new Map,this._visualVariablesForLayer=null,this._webStyleCache=new Map}async initialize(){this._visualVariablesForLayer=y(this.sourceLayer),this._nextUpdateSubset=this.features,this._initializeSketchGraphics(),this._initializeSketchLayer(),await this._updatingHandles.addPromise(this._initializeSketchViewModel())}destroy(){const{_sketchLayer:e,view:t}=this;t?.destroyed||t?.map.remove(e),this._updatingHandles.destroy(),e.destroy(),this.viewModel.destroy()}get defaultUpdateOptions(){const e=this.sourceLayer;return{multipleSelectionEnabled:!1,reshapeOptions:{enableCreateCurveFromStraightEdge:!h(e)&&e.capabilities?.data.supportsTrueCurve}}}set defaultUpdateOptions(e){this._set("defaultUpdateOptions",e)}get sketchGraphics(){return Array.from(this._sketchGraphicsMap.values())}get updating(){return this._updatingHandles.updating}async enter(){await this.startUpdatingFeatures(this._nextUpdateSubset)}async exit(){this._completeCurrentOperation()}notifyAttributesChanged({features:e,fieldName:t}){const i=this._webStyleCache,s=this.view.scale,a=this._updatingHandles;for(const r of e){const e=this._sketchGraphicsMap.get(r),o=r.getAttribute(t);if(!e||e.getAttribute(t)===o)continue;e.setAttribute(t,o);const l=this._visualVariableAttributes.get(r);null==l?.size||l.size.isUpdatingInteractively||l.size.field!==t||l.size.setInitialValue(o),null==l?.rotation||l.rotation.isUpdatingInteractively||l.rotation.field!==t||l.rotation.setInitialValue(o),a.addPromise(m(e,i,s))}}async startUpdatingFeatures(e){const{onGeometriesUpdated:t,onVisualVariableAttributesUpdated:a,_sketchGraphicsMap:r,_sketchLayer:l,sourceLayer:n,view:p,viewModel:d,_webStyleCache:c}=this,h=e.map(e=>r.get(e)).filter(i),u={...this.defaultUpdateOptions};this._completeCurrentOperation();let y=null;if(1===e.length){const t=e[0],i=this._visualVariableAttributes.get(t);!(!i?.rotation&&!i?.size)&&(await v({graphic:h[0],sketchLayer:l,sketchViewModel:d,sourceLayer:n,visualVariables:i,webStyleCache:c}),"point"===n.geometryType&&(u.enableRotation=null!=i.rotation,u.enableScaling=null!=i.size,y=async e=>{const s=e.graphics[0];f(p,s,e,i)&&(a?.([{feature:t,attributes:s.attributes}],e),this._updatingHandles.addPromise(m(s,c,"2d"===p.type?p.scale:null)))}))}else u.tool="move";const g=()=>d.update(h,u),_=d.on("update",a=>{if("complete"===a.state){if(null===p.activeTool)return void g();const e=new AbortController,t=s(e);return this.addHandles(t,k),void this._updatingHandles.addPromise(o(()=>null===p.activeTool,e.signal).then(async()=>{e.signal.aborted||(e.abort(),await g())}))}const l=e.map(e=>{const t=r.get(e);return t?{feature:e,geometry:t.geometry}:null}).filter(i);t(l,a),y?.(a)});await g(),this._nextUpdateSubset=this.features,this.addHandles(_,k),d.addHandles(_)}_completeCurrentOperation(){this.removeHandles(k),this.viewModel.complete()}_initializeSketchGraphics(){const{features:e,_sketchGraphicsMap:t,sourceLayer:i,_visualVariableAttributes:s}=this,a=this._visualVariablesForLayer,r=a.rotation?.field,o=a.size?.field,l={rotation:r?i.getField(r):null,size:o?i.getField(o):null},n=!(!l.rotation&&!l.size);for(const p of e)t.set(p,p.clone()),n&&s.set(p,L(a,l))}_initializeSketchLayer(){const{view:e}=this,t=new c({elevationInfo:this.sourceLayer.elevationInfo,internal:!0,listMode:"hide",title:"SketchController layer"});this._sketchLayer=t,e.map.add(t),this._updatingHandles.addPromise(e.whenLayerView(t))}async _initializeSketchViewModel(){const{defaultUpdateOptions:e,sketchOptions:t,snappingManager:i,useLegacyCreateTools:s,view:r,_sketchGraphicsMap:o,_sketchLayer:n,_webStyleCache:p}=this,d=Array.from(o.entries()),c=new w({allowDeleteKey:!1,defaultUpdateOptions:e,layer:n,sketchOptions:t,snappingManager:i,useLegacyCreateTools:s,updateOnGraphicClick:!1,view:r});this.viewModel=c;const h=a(e=>Promise.all(d.map(([,t])=>m(t,p,e))));await h("2d"===r.type?r.scale:null),"2d"===r.type&&this.addHandles(l(()=>r.scale,e=>h(e))),this.addHandles(await Promise.all(d.map(([e,t])=>g(n,r,e,t))))}};function L({rotation:e,size:t},i){return{rotation:e?b(e,i.rotation):null,size:t?_(t,i.size):null}}e([n()],U.prototype,"defaultUpdateOptions",null),e([n()],U.prototype,"features",void 0),e([n()],U.prototype,"onGeometriesUpdated",void 0),e([n()],U.prototype,"onVisualVariableAttributesUpdated",void 0),e([n()],U.prototype,"sketchGraphics",null),e([n()],U.prototype,"sketchOptions",void 0),e([n()],U.prototype,"snappingManager",void 0),e([n()],U.prototype,"sourceLayer",void 0),e([n()],U.prototype,"updating",null),e([n()],U.prototype,"view",void 0),e([n()],U.prototype,"viewModel",void 0),e([n()],U.prototype,"useLegacyCreateTools",void 0),e([n()],U.prototype,"_nextUpdateSubset",void 0),e([n()],U.prototype,"_sketchGraphicsMap",void 0),e([n()],U.prototype,"_sketchLayer",void 0),e([n()],U.prototype,"_visualVariablesForLayer",void 0),U=e([p("esri.widgets.Editor.support.SketchController")],U);export{U as SketchController};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
|
|
2
|
-
import e from"../../Color.js";import t from"../../Graphic.js";import{isSome as r,equals as n,addMany as o}from"../../core/arrayUtils.js";import{createTask as a}from"../../core/asyncUtils.js";import i from"../../core/Error.js";import{handlesGroup as s,makeHandle as l,abortHandle as c}from"../../core/handleUtils.js";import{clone as u}from"../../core/lang.js";import p from"../../core/Logger.js";import{getOrCreateMapValue as d}from"../../core/MapUtils.js";import{debounce as f,isPromiseLike as y,throwIfAborted as m,whenOrAbort as h}from"../../core/promiseUtils.js";import{watch as b,on as g,whenOnce as w}from"../../core/reactiveUtils.js";import{px2pt as I}from"../../core/screenUtils.js";import{addMany as v}from"../../core/SetUtils.js";import{diff as T}from"../../core/accessorSupport/diffUtils.js";import{isSharedTemplateOrMetadata as F,isSharedGroupTemplate as j,getCreationAttributes as S,isSharedPresetTemplate as k}from"../../editing/templateUtils.js";import A from"../../layers/GraphicsLayer.js";import{featureHasFields as L,fixFields as U,getDisplayFieldName as V}from"../../layers/support/fieldUtils.js";import{isSubtypeSublayer as M,isGraphicsLayer as O,isSceneLayer as x}from"../../layers/support/layerUtils.js";import{calculateTolerance as q}from"../../renderers/support/clickToleranceUtils.js";import{meterIn as z}from"../../renderers/support/lengthUtils.js";import{isRenderer as C}from"../../renderers/support/typeUtils.js";import{getTransformationType as E}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import{isGraphic as P}from"../../support/graphicInstanceUtils.js";import D from"../../symbols/SimpleFillSymbol.js";import R from"../../symbols/SimpleLineSymbol.js";import G from"../../symbols/SimpleMarkerSymbol.js";import{to3D as B}from"../../symbols/support/symbolConversion.js";import{getDisplayedSymbol as Z}from"../../symbols/support/symbolUtils.js";import{getServices as N}from"../../undoredo/support/Services.js";import{GraphicState as Q}from"../../views/3d/layers/graphics/GraphicState.js";import{defaultDrawingMode as W}from"../../views/draw/drawingModes.js";import{createQueryGeometry as $}from"../../views/support/drapedUtils.js";import{filterGraphicHits as H,hitTestSelectSimilarDistance as J}from"../../views/support/hitTestSelectUtils.js";import{dependencySort as K}from"./support/dependencySort.js";import{isDrawGraphicTool as X}from"../Sketch/support/sketchUtils.js";const Y=()=>p.getLogger("esri.widgets.Editor.workflowUtils");function _(e){return ae(e)||ne(e)}function ee(e){return!!e&&"features"in e}function te(e){return null!=e&&"create-features"===e.type}function re(e){return!!e&&"feature"in e}function ne(e){return null!=e&&"update-features"===e.type}function oe(e){return null!=e&&"update-feature"===e.type}function ae(e){return null!=e&&e.type.includes("update-")&&"fullFeature"in e}function ie(e){return null!=e&&"update"===e.type}function se(e){return null!=e&&"merge-features"===e.type}function le(e){return null!=e&&"split-feature"===e.type}function ce(e){const t=e?.type;return"update-feature"===t||"update-table-record"===t||"update-features"===t||"split-feature"===t}function ue(e){return"merge"===e?.type}function pe(e){return"split"===e?.type}function de(e){return se(e)||le(e)}function fe(e){return"update-multiple"===e?.type}function ye(e){const t=e&&"renderer"in e?e.renderer:null;if(!ve(t))return{rotation:null,size:null};const r=t.getVisualVariablesForType("rotation").filter(e=>(!e.axis||"heading"===e.axis)&&e.field&&!e.valueExpression),n=t.getVisualVariablesForType("size").filter(e=>e.field&&!e.useSymbolValue&&!e.valueExpression&&"real-world-size"===E(e));return{rotation:1===r.length?r[0]:null,size:1===n.length?n[0]:null}}function me(e){const t=e.sourceLayer;if(!(t&&"renderer"in t&&ve(t.renderer)))return{rotation:null,size:null};const{rotation:r,size:n}=ye(t);let o=null,a=null;if(r){const e=t.fields?.filter(e=>e.name===r.field),n=1===e?.length?e[0]:null;o=he(r,n)}if(n){const e=t.fields?.filter(e=>e.name===n.field),r=1===e?.length?e[0]:null;a=we(n,r)}return{rotation:o,size:a}}function he(e,t){const r="heading"===(e.axis||"heading")&&"arithmetic"===e.rotationType?-1:1,n=t?.type??"double",o={initial:0,current:0};return{field:e.field,fieldType:n,getDefaultValue:()=>Promise.resolve(0),getValue:e=>(o.current=o.initial-r*e,Ie((o.current+360)%360,n)),setInitialValue:e=>{o.initial=e,o.current=0},isUpdatingInteractively:!1,rotationType:e.rotationType??"geographic"}}function be(e,t){switch(t){case"width":return e[0];case"depth":return e[1];case"height":return e[2];default:return e[2]||e[1]||e[0]}}async function ge(e,t,r){if(null==t)return 0;const{symbol:n}=B(t);if(null==n||"web-style"===n.type||"cim"===n.type)return 0;const o=n.symbolLayers.at(0);if(!o)return 0;switch(o.type){case"icon":{const{computeIconLayerResourceSize:e}=await import("../../symbols/support/symbolLayerUtils.js");return Math.min(st.icon,(await e(o,st.icon))[0])||st.icon}case"text":return st.text;case"line":return st.line;case"object":{const{computeObjectLayerResourceSize:t}=await import("../../symbols/support/symbolLayerUtils.js");return be(await t(o,e.scale/st.viewScaleSizeFactor),r)}case"path":case"extrude":return e.scale/st.viewScaleSizeFactor;default:return 0}}function we(e,t){const r=e.axis,n=t?.type??"double",o={initial:0,current:0},a=z[e.valueUnit]??1;let i;return i="area"===e.valueRepresentation?e=>(e*a/2)**2*Math.PI:"radius"===e.valueRepresentation||"distance"===e.valueRepresentation?e=>e*a/2:e=>e*a,{field:e.field,fieldType:n,getDefaultValue:async(e,t)=>Ie(i(await ge(t,e,r)),n),getValue:(e,t)=>(o.initial||(o.initial=t.pixelSizeAt(t.center)),o.current=o.initial*e,Ie(o.current,n)),setInitialValue:e=>{o.initial=e,o.current=0},isUpdatingInteractively:!1,displayUnit:ut(e.valueUnit),axis:e.axis}}function Ie(e,t){switch(t){case"small-integer":case"integer":case"long":return Math.round(e);case"double":case"single":return e;default:return 0}}function ve(e){if(!C(e))return!1;switch(e?.type){case"class-breaks":case"simple":case"unique-value":case"dot-density":case"dictionary":case"pie-chart":return!0;default:return!1}}async function Te(e,t,r){const n=await Z(e,{useSourceLayer:!0,ignoreGraphicSymbol:!0,webStyleCache:t,scale:r});null!=T(e.symbol,n)&&(e.symbol=n)}function Fe(e,t){if(!e||!t)throw new Error("no geometry type");if("multipatch"===e)return{tool:"mesh",createOptions:{mode:"hybrid"}};const r=new Map;r.set("circle",{mode:"freehand"}),r.set("rectangle",{mode:"freehand"});const n={mode:W,optionsPerTool:r};if(F(t)){const o=t.defaultTool,a=j(t)?t.definition?.inputGeometryType??e:e;switch(o){case"freehand":case"stream-line":return{tool:"polyline"===a?"freehandPolyline":"freehandPolygon",createOptions:n};case"autocomplete-freehand-polygons":case"stream-polygon":return{tool:"freehandPolygon",createOptions:n};case"autocomplete-polygons":case"difference-polygon":case"create-structures":case"polygon":case"trace":return{tool:"polygon"===a?"polygon":"polyline",createOptions:n};case"circle":return r.get("circle").preserveAspectRatio=!0,{tool:"circle",createOptions:n};case"ellipse":return r.get("circle").preserveAspectRatio=!1,{tool:"circle",createOptions:n};case"create-points-along-line":case"multipoint":return{tool:"multipoint",createOptions:n};case"line":case"radial-line":case"right-angle-line":case"split":case"two-point-line":return{tool:"polyline",createOptions:n};case"rectangle":case"regular-polygon":case"right-angle-polygon":return{tool:"rectangle",createOptions:n};case"elevation-point-from-contour":case"elevation-point-from-dem":case"parcel-seed":case"point":case"point-and-rotation":case"point-at-end-of-line":return{tool:"point",createOptions:n}}}else{const o=t.drawingTool;if("circle"===o||"ellipse"===o)return r.get("circle").preserveAspectRatio="circle"===o,{tool:"circle",createOptions:n};if("rectangle"===o)return{tool:"rectangle",createOptions:n};if("freehand"===o)return{tool:"polygon"===e?"freehandPolygon":"freehandPolyline",createOptions:n}}return{tool:e,createOptions:n}}async function je(e,t,r,n){const{creationInfo:o,fullTemplate:a}=r;if(!o)throw new i("featureworkflow","No creation info provided.");const s=o.layer,l=S(a,o.attributeOverrides),{view:c}=e,u="2d"===c?.type;j(a)||k(a)||await Be(e,s,l,n,u?c.scale:null);const{capabilities:p}=s;t.elevationInfo=s.elevationInfo;const d=Fe(s.geometryType,a);e.defaultCreateOptions={graphicProperties:{attributes:l,sourceLayer:s},mode:d.createOptions.mode,optionsPerTool:d.createOptions.optionsPerTool,preserveAspectRatio:d.createOptions.preserveAspectRatio,hasZ:p.data.supportsZ,defaultZ:(u?p.editing.zDefault:null)??e.defaultCreateOptions.defaultZ},null==o.geometryToPlace?await e.create(d.tool):await e.place(o.geometryToPlace,{graphicProperties:{attributes:l,sourceLayer:s}})}async function Se(e){return s([ke(e),Ae(e)])}function ke({creationAttributes:e,data:t,sketchViewModel:r,view:n,webStyleCache:o}){const{creationInfo:a}=t,{fullTemplate:i}=t;if(!a||"2d"!==n?.type||j(i)||k(i))return null;const s=f(t=>Be(r,a.layer,e,o,t));return b(()=>n.scale,e=>s(e))}function Ae({data:t,sketchViewModel:r,view:n}){const{templateExecutorInfo:o}=t;if(!o)return null;const a=r.activeComponent;if(!n||!X(a))return Y().error(new i("featureworkflow","Failed to set up template feedback.")),null;const c=new A({effect:"saturate(0.6) opacity(0.8)",listMode:"hide",title:"Shared Template Feedback Graphics"});n.map?.add(c);const{executor:u,serviceLayersById:p}=o,d=n.theme?.accentColor??new e([255,165,0,1]);return s([g(()=>a,["cursor-update","vertex-add"],()=>{c.removeAll();const e=a.graphic?.geometry;if(!e||!Le(e))return;const t=u(e,"digitizing");if(!y(t))for(const r of t.edits){const e=p.get(r.id);if(e&&r.addFeatures&&0!==r.addFeatures.length)for(const t of e)if(!t.isTable)for(const e of r.addFeatures){const t=Ue(e,d);t&&c.add(t)}}}),l(()=>{n.map.remove(c),c.destroy()})])}function Le(e){switch(e.type){case"point":case"multipoint":return!0;case"polyline":return e.paths[0].length>1;case"polygon":{const t=e.rings[0];return n(t.at(0),t.at(-1))?t.length>2:t.length>1}default:return!1}}function Ue(e,r){let n=null;switch(e.geometry?.type){case"point":case"multipoint":n=new G({angle:0,color:r,outline:new R({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:1}),path:"undefined",size:8,style:"circle",xoffset:0,yoffset:0});break;case"polygon":n=new D({color:r,outline:new R({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:3}),style:"none"});break;case"polyline":n=new R({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:2});break;default:return null}return new t({geometry:e.geometry,symbol:n,attributes:{...e.attributes}})}function Ve(e,t){const r=N(t),n=M(e)?e.parent:e;return r.tablesAndLayersLookup.get(n)}function Me(e,t){const r=Ve(e,t);if(!r)return new Map;const n=new Map;for(const o of r.layersAndTables)d(n,o.layerId,()=>[]).push(o);return n}function Oe(e){const t=e.objectIdField,r=e.globalIdField??"";return{id:e.layerId,identifierFields:{objectIdField:t,globalIdField:r},addFeatures:[],deleteAttachments:[],addAttachments:[],deleteFeatures:[],updateFeatures:[]}}function xe(e){const{edits:t,serviceInfo:n,view:o,findOriginalFeature:a}=e,i=qe(n.layersAndTables),s=n.layersAndTables.toArray(),{allEditData:l,editDataByLayerIdMap:c,editDataByIdMap:u}=Ce(t,i,a),p=Ee(l,ze(s,c),c);if(o&&Re(l,p,o),0===p.length)return t;const d=K(p,{continueOnCircularDependency:!0}).map(e=>u.get(e)).filter(r),f=new Map;for(const r of d)f.set(r.uniqueId,r);const y=[];for(const r of l)f.has(r.uniqueId)||y.push(r);const m=[];let h=null;for(const r of d){const{layer:e}=r;switch(null==h?h=Oe(e):h.id!==e.layerId&&(m.push(h),h=Oe(e)),r.operationType){case"add":case"modify":h.addFeatures.push(r.after);break;case"delete":h.deleteFeatures.push(r.before)}}null!==h&&m.push(h);for(const r of y){const e=r.layer.layerId,t=m.find(t=>t.id===e)??Oe(r.layer);switch(m.includes(t)||m.push(t),r.operationType){case"add":t.addFeatures.push(r.after);break;case"modify":t.updateFeatures.push(r.after);break;case"delete":t.deleteFeatures.push(r.before);break;case"deleteAttachment":t.deleteAttachments.push(r.attachmentId);break;case"addAttachment":t.addAttachments.push(r.attachment)}}for(const r of m)void 0!==r.deleteAttachments&&0===r.deleteAttachments.length&&delete r.deleteAttachments,void 0!==r.addAttachments&&0===r.addAttachments.length&&delete r.addAttachments;return m}function qe(e){const t=new Map;for(const r of e)t.set(r.layerId,r);return t}function ze(e,t){const r=new Map;for(const n of e)for(const e of n.relationships??[])if(r.set(Pe(n,e),""),t.has(e.relatedTableId)){const o=t.get(e.relatedTableId);if(o.length>0)for(const t of o[0].layer.relationships??[])if(t.id===e.id){r.set(Pe(n,e),t.keyField);break}}return r}function Ce(e,t,r){const n=new Map,o=[],a=new Map;let s=1;for(const l of e){const e=[],c=t.get(l.id);if(!c)throw new i("featureworkflow",`Failed to prepare applyEdits payload. Layer with id ${l.id} not found.`);for(const t of l.addFeatures??[])e.push({uniqueId:"T"+s++,operationType:"add",layer:c,after:t});for(const t of l.deleteFeatures??[])e.push({uniqueId:"T"+s++,operationType:"delete",before:t,layer:c});for(const t of l.deleteAttachments??[])e.push({uniqueId:"T"+s++,operationType:"deleteAttachment",attachmentId:t,layer:c});for(const t of l.addAttachments??[])e.push({uniqueId:"T"+s++,operationType:"addAttachment",attachment:t,layer:c});for(const t of l.updateFeatures??[])e.push({uniqueId:"T"+s++,operationType:"modify",before:r(t),after:t,layer:c});n.set(c.layerId,e);for(const t of e)o.push(t),a.set(t.uniqueId,t)}return{allEditData:o,editDataByIdMap:a,editDataByLayerIdMap:n}}function Ee(e,t,r){const n=[];for(const o of e){const e=o.layer.relationships??[],{uniqueId:a}=o;for(const i of e){const e=i.keyField;if("origin"===i.role){const s=r.get(i.relatedTableId);if(!s||0===s.length)continue;const l=Pe(o.layer,i),c=t.get(l);if(void 0===c||""===c)continue;switch(o.operationType){case"add":for(const t of s)t!==o&&("add"!==t.operationType&&"modify"!==t.operationType||t.after.attributes[c]===o.after.attributes[e]&&n.push([a,t.uniqueId]));break;case"modify":if(o.before.attributes[e]!==o.after.attributes[e])for(const t of s){const r=t.uniqueId;t!==o&&("delete"===t.operationType?t.before.attributes[c]===o.before.attributes[e]?n.push([r,a]):t.before.attributes[c]===o.after.attributes[e]&&n.push([a,r]):"add"===t.operationType?t.after.attributes[c]===o.after.attributes[e]?n.push([a,r]):t.after.attributes[c]===o.before.attributes[e]&&n.push([r,a]):"modify"===t.operationType&&(t.before.attributes[c]!==t.after.attributes[c]?t.after.attributes[c]===o.after.attributes[e]?n.push([a,r]):n.push([r,a]):n.push([a,r])))}break;case"delete":for(const t of s)t!==o&&("delete"!==t.operationType&&"modify"!==t.operationType||t.before.attributes[c]===o.before.attributes[e]&&n.push([t.uniqueId,a]))}}}}return n}function Pe(e,t){return`${e.layerId}:${t.id}`}function De(e,t){return!!(t?.map&&"utilityNetworks"in t.map&&t.map.utilityNetworks?.length&&t.map.utilityNetworks.some(t=>!(!t.loaded||!e.url?.startsWith(t.featureServiceUrl)||e.layerId!==t.networkSystemLayers.associationsTableId)))}function Re(e,t,r){const n=[];for(const a of e)De(a.layer,r)&&n.push(a);if(0===n.length)return;let o=[];for(const a of n){const r=a.layer;switch(a.operationType){case"delete":o=[...Ge(a.before.attributes[r.fieldsIndex.get("fromglobalid").name],e),...Ge(a.before.attributes[r.fieldsIndex.get("toglobalid").name],e)];for(const e of o)t.push([a.uniqueId,e.uniqueId]);break;case"add":o=[...Ge(a.after.attributes[r.fieldsIndex.get("fromglobalid").name],e),...Ge(a.after.attributes[r.fieldsIndex.get("toglobalid").name],e)];for(const e of o)t.push([e.uniqueId,a.uniqueId])}}}function Ge(e,t){const r=[],n=t.filter(({layer:e})=>""!==e.globalIdField&&null!=e.globalIdField);for(const o of n){const t=o.layer.globalIdField;("before"in o&&o.before?.attributes[t]===e||"after"in o&&o.after?.attributes[t]===e)&&r.push(o)}return r}async function Be(e,r,n,o,a){const i=new t({sourceLayer:r,attributes:n}),{rotation:s,size:l}=me(i);let c=await Z(i,{useSourceLayer:!0,webStyleCache:o,scale:a}),u=!1;for(const t of[l,s]){if(null==t)continue;null==n[t.field]&&(n[t.field]=await t.getDefaultValue(c,e.view),u=!0)}switch(u&&(c=await Z(i,{useSourceLayer:!0,webStyleCache:o,scale:a})),c?.type){case"simple-fill":case"polygon-3d":e.polygonSymbol=c;break;case"simple-line":case"line-3d":e.polylineSymbol=c;break;case"simple-marker":case"picture-marker":case"point-3d":case"cim":e.pointSymbol=c;break;case"mesh-3d":e.meshSymbol=c}Ze(e.tooltipOptions,l,s)}function Ze(e,t,r){e.visualVariables=null!=t||null!=r?{size:null!=t?{unit:t.displayUnit,axis:t.axis,valueType:t.fieldType}:null,rotation:null!=r?{valueType:r.fieldType,rotationType:r.rotationType??"geographic"}:null}:null}function Ne(e,t){return e.find(e=>e.layer===t)}function Qe(e,t){const r=Ne(e,t);if(null==r)throw new i("no-editorItem-found","The EditorViewModel provided did not have an EditorItem associated with the specified layer");return r}function We(e,t){return e?.find(e=>e.layer===t)}async function $e(e,t,r,n){switch(t.type){case"3d":return He(e,t,r,n);case"2d":return Je(e,t,r,n)}}async function He(e,t,r,n){if(0===e.length)return[];const{updatable:a,graphicsByLayer:i}=await r.defer(async()=>{const{results:o}=await h(J(t,r),n),a=new Map,i=e=>{const t=e.layer,r=a.get(t);if(!r){const e=new Array;return a.set(t,e),e}return r};H(o).forEach(({graphic:e})=>i(e).push(e));const s=e.filter(({capabilities:e,layer:t})=>e.update.enabled&&a.has(t));return 0!==s.length&&r.stopPropagation(),{updatable:s,graphicsByLayer:a}});return h(Promise.allSettled(a.map(async({layer:e})=>{const t=i.get(e),r=Ke(e);if(t.every(e=>L(e,r)))return t;const a=[];for(const n of t){a.push(n.getObjectId());const e=Object.keys(n.attributes);o(r,e)}const s=e.createQuery();return s.returnGeometry=!1,s.objectIds=a,s.outFields=U(e.fieldsIndex,r),e.queryFeatures(s,{signal:n}).then(({features:e})=>e)})),n)}async function Je(e,t,r,n){if(0===e.length)return[];const{mapPoint:o}=r;if(null==o)return[];let a=null;const i=await r.defer(async()=>{const{results:o}=await h(t.hitTest(r),n);if(0===o.length)return[];const i=new Set;a=H(o),a.forEach(({graphic:e})=>e&&i.add(e.layer));const s=e.filter(e=>i.has(e.layer)&&e.supportsUpdateWorkflow);return s.length>0&&r.stopPropagation(),s});return h(Promise.allSettled(i.map(async({layer:e})=>{const i=e.createQuery();i.returnGeometry=!0,i.outFields=Ke(e);const s="renderer"in e?q({renderer:e.renderer,pointerType:r.pointerType}):0;i.geometry=$(o,s,t),i.outSpatialReference=t.spatialReference;const{features:l}=await e.queryFeatures(i,{signal:n});return a?.forEach(({graphic:t})=>{t.layer!==e||l.some(e=>e.getObjectId()===t.getObjectId())||l.push(t)}),l})),n)}function Ke(e){return U(e.fieldsIndex,[e.objectIdField,V({displayField:"displayField"in e?e.displayField:null,fields:e.fields})])}async function Xe(e,t,n,o){return Ye(e.map(e=>e.getObjectId()??e.attributes[t.objectIdField]).filter(r),t,n,o)}async function Ye(e,t,r,n){const o=t.createQuery();o.objectIds=e,o.outFields=["*"],o.returnM=t.capabilities.data.supportsM,o.returnZ=t.capabilities.data.supportsZ,o.returnGeometry=!0,x(t)&&null!=t.infoFor3D||(o.outSpatialReference=r),!x(t)&&t.capabilities?.data.supportsTrueCurve&&(o.returnTrueCurves=!0);const a=await t.queryFeatures(o,{signal:n});return m(n),a.features}async function _e(e){const{graphic:t,sketchViewModel:r,sourceLayer:n,updateOptions:o,visualVariables:a}=e;await et(e);const i={multipleSelectionEnabled:!1,...o};return"point"===n.geometryType&&(i.enableRotation=null!=a.rotation,i.enableScaling=null!=a.size),r.update(t,i)}async function et(e){const{graphic:t,sketchLayer:r,sketchViewModel:n,sourceLayer:o,visualVariables:a,webStyleCache:i}=e;let s=!1;const{rotation:l,size:c}=a;for(const u of[l,c]){if(null==u)continue;const e=t.getAttribute(u.field);if(null!=e)u.setInitialValue(e);else{const e=await u.getDefaultValue(t.symbol,n.view);u.setInitialValue(e),t.setAttribute(u.field,e),s=!0}}if(s){const e="2d"===n.view?.type?n.view.scale:null;await Te(t,i,e)}Ze(n.tooltipOptions,c,l),r.elevationInfo=o.elevationInfo}function tt(e){return null==e||"rotate-start"!==e.type&&"rotate"!==e.type&&"rotate-stop"!==e.type?null:e}function rt(e){return null==e||"scale-start"!==e.type&&"scale"!==e.type&&"scale-stop"!==e.type?null:e}function nt(e,t,r,n){if(null==t.geometry||"point"!==t.geometry?.type)return!1;const o=t.attributes;let a=!1;const i=n.rotation,s=tt(r.toolEventInfo);if(null!=i&&null!=s){const{field:r,getValue:n}=i;if("rotate-stop"===s.type)i.isUpdatingInteractively=!1,i.setInitialValue(t.getAttribute(r));else{i.isUpdatingInteractively=!0;const l=n(s.angle,e);l!==o[r]&&t.setAttribute(r,l),a=!0}}const l=n.size,c=rt(r.toolEventInfo);if(null!=l&&null!=c){const{field:r,getValue:n}=l;if("scale-stop"===c.type)l.isUpdatingInteractively=!1,l.setInitialValue(t.getAttribute(r));else{l.isUpdatingInteractively=!0;const i=n(c.xScale,e);i!==o[r]&&t.setAttribute(r,i),a=!0}}return a}async function ot({feature:e,featureClone:t,sketchLayer:r,sketchViewModel:n,updateOptions:o,view:a,visualVariableAttributes:i,webStyleCache:u,addHandle:p,addUpdatingPromise:d,onUpdate:y}){await Te(t,u,"2d"===a.type?a.scale:null);let m=null;if("2d"===n?.view?.type){const e=f(e=>Te(t,u,e));m=b(()=>n?.view?.scale,t=>e(t))}const h=t.sourceLayer,g=ft(a,h);await _e({graphic:t,sketchLayer:r,sketchViewModel:n,sourceLayer:h,updateOptions:o,visualVariables:i,webStyleCache:u});let I=null;g.then(e=>I=e).catch(()=>{});const v=i.size,T=i.rotation,F=b(()=>e.attributes,async e=>{let r=!1;for(const n in e){const o=e[n];o!==t.getAttribute(n)&&(t.setAttribute(n,o),null==v||v.isUpdatingInteractively||v.field!==n||v.setInitialValue(o),null==T||T.isUpdatingInteractively||T.field!==n||T.setInitialValue(o),(null==I||I.requiredFields.includes(n))&&(r=!0))}r&&await Te(t,u,"2d"===a.type?a.scale:null)}),j=n.on("update",async e=>{const t=e.graphics[0],s={graphic:t,sketchLayer:r,sketchViewModel:n,sourceLayer:h,updateOptions:o,visualVariables:i,webStyleCache:u};if("complete"===e.state){if(null===a.activeTool)return _e(s);const e=new AbortController,t=c(e);return p(t),d(w(()=>null===a.activeTool,e.signal).then(async()=>{if(!e.signal.aborted)return e.abort(),_e(s)}))}nt(a,t,e,i)&&await Te(t,u,"2d"===a.type?a.scale:null),y(mt(t),e)}),S=n.on(["undo","redo"],e=>{y(mt(e.graphics[0]),e)});return s([S,j,l(()=>n.cancel()),F,m])}async function at(e,t,r,n){e.add(n);const o=r.sourceLayer,i=r.layer??o,c=r.getAttribute(o.objectIdField);let u=null;function p(e){u?.abort(),O(i)?r.visible=e:u=a(async r=>{const n=await ft(t,i);m(r),n.setVisibility?.(c,e)})}return await it(t,n),p(!1),s([l(async()=>{p(!0);try{if(!t.destroyed){const e=await ft(t,i).catch(()=>{});e&&!e.destroyed&&await w(()=>!e.updating)}}finally{e.remove(n)}})])}async function it(e,t){if("3d"===e.type){const r=new Q({graphic:t}),n=e.trackGraphicState(r);await w(()=>r.displaying||r.error),n.remove()}else await w(()=>t.visible)}const st={icon:I(24),text:I(12),line:I(1),viewScaleSizeFactor:100};function lt(e,t,r){let n=!1;return e.filter(e=>!!n||(n=e===t,n)).map(e=>r[e]())}function ct(e,t){e.viewModel.syncFeatureTemplates();const r=e.creationInfo;if("awaiting-feature-creation-info"===t[0].id&&r){const n=r.layer,o=e.viewModel.getTemplatesForLayer(n);1===o.length&&"scene"!==n.type&&(r.template=o[0],t.shift())}return t}function ut(e){return"unknown"===e?null:e}function pt(e){e.filesEnabled=!0,e.mode="view",e.capabilities={editing:!0,operations:{add:!0,update:!0,delete:!0}}}const dt=e=>e.includes("-stop")||e.includes("vertex-"),ft=(e,t)=>{const r="subtype-sublayer"===t.type?t.parent:t;return e.whenLayerView(r)};function yt(e){return"createInteractiveEditSession"in e}function mt(e){const t=e.geometry;if("mesh"===t?.type){const r=e.cloneShallow();return r.attributes=u(e.attributes),r.geometry=t.cloneShallow(),r.geometry.transform=t.transform?.clone()??null,r}return e.clone()}function ht(e){return e.acquireCursor("progress")}function bt(e){for(const t of e){const{destinationGraphic:e,destinationField:r,sourceGraphic:n,sourceField:o}=t;e.setAttribute(r,n.getAttribute(o))}}function gt(e){const t=e.templateExecutorInfo?.completionResults;return t?.length?(t.forEach(e=>bt(e.relationships)),t.flatMap(e=>e.edits)):null}function wt(e){const t=ie(e)?e.activeWorkflow:e;if(null==t)return[];if(ne(t))return t.data.layers;const r=t.layer;return r?[r]:[]}function It({attributes:e},t){const r=new Set;r.add(t.objectIdField),"uniqueIdFields"in t&&t.uniqueIdFields&&t.uniqueIdFields.length>0&&v(r,t.uniqueIdFields);const n={};for(const o of r)null!=e[o]&&(n[o]=e[o]);if("scene"===t.type&&null!=t.infoFor3D){const r=t.associatedLayer?.globalIdField;null!=r&&(e[r]=e[r])}return n}function vt(e){if(!Tt(e))return e;const t=new Map;for(const r of e){const e=r.getObjectId();if(null!=e){const n=r.sourceLayer??r.layer;d(t,n,()=>[]).push(e)}}return Array.from(t.entries()).map(([e,t])=>({layer:e,objectIds:t}))}function Tt(e){return 0===e.length||P(e[0])}function Ft({drawTool:e},t){const r=e?.mostDownstreamPlugin?.configuration?.curveTypes;if(!t||!r||0===r.length)return!1;const n=new Set(t.capabilities.supportedCurveTypes);return r.some(e=>!n.has(e))}export{Ft as activeSketchToolDrawsUnsupportedCurve,Re as appendAllUtilityNetworkAssociationRelationships,ct as avoidFeatureTemplateSelectionWithOnlyOneItem,yt as canCreateInteractiveEditSession,mt as cloneGraphicExceptMesh,qe as createLayerIdMap,ze as createRelationshipKeyMap,Fe as createToolFromGeometryType,lt as createWorkflowSteps,$e as fetchCandidates,Xe as fetchFullFeatures,Ye as fetchFullFeaturesByObjectId,Ee as findAllDependencies,Ge as findChangesByGlobalId,Ne as findEditorItemForLayer,Qe as findEditorItemForLayerOrThrow,We as findLayerInfo,Pe as generateHashForRelationship,wt as getLayersFromWorkflow,he as getRotationVariableAttribute,gt as getServiceEditsFromWorkflowData,Ve as getServiceInfoForLayer,Me as getServiceLayersById,we as getSizeVariableAttribute,me as getVisualVariableAttributes,ye as getVisualVariablesForLayer,_ as isAnyUpdateLeafWorkflow,ee as isBatchAttributeFormViewModel,te as isCreateFeaturesWorkflow,re as isFeatureFormViewModel,Tt as isGraphicsArray,se as isMergeFeaturesWorkflow,ue as isMergeWorkflowOptions,ce as isParentWorkflow,le as isSplitFeatureWorkflow,pe as isSplitWorkflowOptions,dt as isTerminalUpdateEventType,oe as isUpdateFeatureWorkflow,ne as isUpdateFeaturesWorkflow,fe as isUpdateFeaturesWorkflowOptions,ae as isUpdateRecordWorkflow,ie as isUpdateWorkflow,De as isUtilityNetworkAssociationsTable,It as makeMinimalAttributes,xe as orderEditsByRelationshipDependencies,pt as prepareAttachmentsForCreateFeaturesWorkflow,bt as setRelationshipFields,ot as setUpGeometryUpdate,Se as setUpSketchCreateWatchers,et as setVisualVariablesAndElevationInfoForUpdate,ht as showProgressCursor,st as sizeDefaults,ut as sizeVariableUnitToLengthUnit,je as startCreatingNewFeature,_e as startUpdatingFeatureGeometry,at as swapForEditingSession,vt as toFeatureInfos,Te as updateGraphicSymbolWhenRequired,nt as visualVariableInteractiveUpdate,ft as whenEditorLayerView,it as whenGraphicDisplayed,de as workflowInfluencesOutcomeOfParent};
|
|
2
|
+
import e from"../../Color.js";import t from"../../Graphic.js";import{isSome as r,equals as n,addMany as o}from"../../core/arrayUtils.js";import{createTask as i}from"../../core/asyncUtils.js";import a from"../../core/Error.js";import{handlesGroup as s,makeHandle as l,abortHandle as c}from"../../core/handleUtils.js";import{clone as u}from"../../core/lang.js";import p from"../../core/Logger.js";import{getOrCreateMapValue as d}from"../../core/MapUtils.js";import{debounce as f,isPromiseLike as y,throwIfAborted as m,whenOrAbort as h}from"../../core/promiseUtils.js";import{watch as b,on as g,whenOnce as w}from"../../core/reactiveUtils.js";import{px2pt as I}from"../../core/screenUtils.js";import{addMany as v}from"../../core/SetUtils.js";import{diff as T}from"../../core/accessorSupport/diffUtils.js";import{isSharedTemplateOrMetadata as F,isSharedGroupTemplate as j,getCreationAttributes as S,isSharedPresetTemplate as k}from"../../editing/templateUtils.js";import{isCurvedGeometry as A,hasUnsupportedCurve as L}from"../../geometry/support/curves/curveUtils.js";import U from"../../layers/GraphicsLayer.js";import{featureHasFields as V,fixFields as M,getDisplayFieldName as O}from"../../layers/support/fieldUtils.js";import{isSubtypeSublayer as x,isGraphicsLayer as q,isSceneLayer as z}from"../../layers/support/layerUtils.js";import{calculateTolerance as C}from"../../renderers/support/clickToleranceUtils.js";import{meterIn as E}from"../../renderers/support/lengthUtils.js";import{isRenderer as P}from"../../renderers/support/typeUtils.js";import{getTransformationType as D}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import{isGraphic as R}from"../../support/graphicInstanceUtils.js";import G from"../../symbols/SimpleFillSymbol.js";import B from"../../symbols/SimpleLineSymbol.js";import Z from"../../symbols/SimpleMarkerSymbol.js";import{to3D as N}from"../../symbols/support/symbolConversion.js";import{getDisplayedSymbol as Q}from"../../symbols/support/symbolUtils.js";import{getServices as W}from"../../undoredo/support/Services.js";import{GraphicState as $}from"../../views/3d/layers/graphics/GraphicState.js";import{defaultDrawingMode as H}from"../../views/draw/drawingModes.js";import{createQueryGeometry as J}from"../../views/support/drapedUtils.js";import{filterGraphicHits as K,hitTestSelectSimilarDistance as X}from"../../views/support/hitTestSelectUtils.js";import{dependencySort as Y}from"./support/dependencySort.js";import{isDrawGraphicTool as _}from"../Sketch/support/sketchUtils.js";const ee=()=>p.getLogger("esri.widgets.Editor.workflowUtils");function te(e){return se(e)||ie(e)}function re(e){return!!e&&"features"in e}function ne(e){return null!=e&&"create-features"===e.type}function oe(e){return!!e&&"feature"in e}function ie(e){return null!=e&&"update-features"===e.type}function ae(e){return null!=e&&"update-feature"===e.type}function se(e){return null!=e&&e.type.includes("update-")&&"fullFeature"in e}function le(e){return null!=e&&"update"===e.type}function ce(e){return null!=e&&"merge-features"===e.type}function ue(e){return null!=e&&"split-feature"===e.type}function pe(e){const t=e?.type;return"update-feature"===t||"update-table-record"===t||"update-features"===t||"split-feature"===t}function de(e){return"merge"===e?.type}function fe(e){return"split"===e?.type}function ye(e){return ce(e)||ue(e)}function me(e){return"update-multiple"===e?.type}function he(e){const t=e&&"renderer"in e?e.renderer:null;if(!Fe(t))return{rotation:null,size:null};const r=t.getVisualVariablesForType("rotation").filter(e=>(!e.axis||"heading"===e.axis)&&e.field&&!e.valueExpression),n=t.getVisualVariablesForType("size").filter(e=>e.field&&!e.useSymbolValue&&!e.valueExpression&&"real-world-size"===D(e));return{rotation:1===r.length?r[0]:null,size:1===n.length?n[0]:null}}function be(e){const t=e.sourceLayer;if(!(t&&"renderer"in t&&Fe(t.renderer)))return{rotation:null,size:null};const{rotation:r,size:n}=he(t);let o=null,i=null;if(r){const e=t.fields?.filter(e=>e.name===r.field),n=1===e?.length?e[0]:null;o=ge(r,n)}if(n){const e=t.fields?.filter(e=>e.name===n.field),r=1===e?.length?e[0]:null;i=ve(n,r)}return{rotation:o,size:i}}function ge(e,t){const r="heading"===(e.axis||"heading")&&"arithmetic"===e.rotationType?-1:1,n=t?.type??"double",o={initial:0,current:0};return{field:e.field,fieldType:n,getDefaultValue:()=>Promise.resolve(0),getValue:e=>(o.current=o.initial-r*e,Te((o.current+360)%360,n)),setInitialValue:e=>{o.initial=e,o.current=0},isUpdatingInteractively:!1,rotationType:e.rotationType??"geographic"}}function we(e,t){switch(t){case"width":return e[0];case"depth":return e[1];case"height":return e[2];default:return e[2]||e[1]||e[0]}}async function Ie(e,t,r){if(null==t)return 0;const{symbol:n}=N(t);if(null==n||"web-style"===n.type||"cim"===n.type)return 0;const o=n.symbolLayers.at(0);if(!o)return 0;switch(o.type){case"icon":{const{computeIconLayerResourceSize:e}=await import("../../symbols/support/symbolLayerUtils.js");return Math.min(ct.icon,(await e(o,ct.icon))[0])||ct.icon}case"text":return ct.text;case"line":return ct.line;case"object":{const{computeObjectLayerResourceSize:t}=await import("../../symbols/support/symbolLayerUtils.js");return we(await t(o,e.scale/ct.viewScaleSizeFactor),r)}case"path":case"extrude":return e.scale/ct.viewScaleSizeFactor;default:return 0}}function ve(e,t){const r=e.axis,n=t?.type??"double",o={initial:0,current:0},i=E[e.valueUnit]??1;let a;return a="area"===e.valueRepresentation?e=>(e*i/2)**2*Math.PI:"radius"===e.valueRepresentation||"distance"===e.valueRepresentation?e=>e*i/2:e=>e*i,{field:e.field,fieldType:n,getDefaultValue:async(e,t)=>Te(a(await Ie(t,e,r)),n),getValue:(e,t)=>(o.initial||(o.initial=t.pixelSizeAt(t.center)),o.current=o.initial*e,Te(o.current,n)),setInitialValue:e=>{o.initial=e,o.current=0},isUpdatingInteractively:!1,displayUnit:dt(e.valueUnit),axis:e.axis}}function Te(e,t){switch(t){case"small-integer":case"integer":case"long":return Math.round(e);case"double":case"single":return e;default:return 0}}function Fe(e){if(!P(e))return!1;switch(e?.type){case"class-breaks":case"simple":case"unique-value":case"dot-density":case"dictionary":case"pie-chart":return!0;default:return!1}}async function je(e,t,r){const n=await Q(e,{useSourceLayer:!0,ignoreGraphicSymbol:!0,webStyleCache:t,scale:r});null!=T(e.symbol,n)&&(e.symbol=n)}function Se(e,t){if(!e||!t)throw new Error("no geometry type");if("multipatch"===e)return{tool:"mesh",createOptions:{mode:"hybrid"}};const r=new Map;r.set("circle",{mode:"freehand"}),r.set("rectangle",{mode:"freehand"});const n={mode:H,optionsPerTool:r};if(F(t)){const o=t.defaultTool,i=j(t)?t.definition?.inputGeometryType??e:e;switch(o){case"freehand":case"stream-line":return{tool:"polyline"===i?"freehandPolyline":"freehandPolygon",createOptions:n};case"autocomplete-freehand-polygons":case"stream-polygon":return{tool:"freehandPolygon",createOptions:n};case"autocomplete-polygons":case"difference-polygon":case"create-structures":case"polygon":case"trace":return{tool:"polygon"===i?"polygon":"polyline",createOptions:n};case"circle":return r.get("circle").preserveAspectRatio=!0,{tool:"circle",createOptions:n};case"ellipse":return r.get("circle").preserveAspectRatio=!1,{tool:"circle",createOptions:n};case"create-points-along-line":case"multipoint":return{tool:"multipoint",createOptions:n};case"line":case"radial-line":case"right-angle-line":case"split":case"two-point-line":return{tool:"polyline",createOptions:n};case"rectangle":case"regular-polygon":case"right-angle-polygon":return{tool:"rectangle",createOptions:n};case"elevation-point-from-contour":case"elevation-point-from-dem":case"parcel-seed":case"point":case"point-and-rotation":case"point-at-end-of-line":return{tool:"point",createOptions:n}}}else{const o=t.drawingTool;if("circle"===o||"ellipse"===o)return r.get("circle").preserveAspectRatio="circle"===o,{tool:"circle",createOptions:n};if("rectangle"===o)return{tool:"rectangle",createOptions:n};if("freehand"===o)return{tool:"polygon"===e?"freehandPolygon":"freehandPolyline",createOptions:n}}return{tool:e,createOptions:n}}async function ke(e,t,r,n){const{creationInfo:o,fullTemplate:i}=r;if(!o)throw new a("featureworkflow","No creation info provided.");const s=o.layer,l=S(i,o.attributeOverrides),{view:c}=e,u="2d"===c?.type;j(i)||k(i)||await Ne(e,s,l,n,u?c.scale:null);const{capabilities:p}=s;t.elevationInfo=s.elevationInfo;const d=Se(s.geometryType,i);e.defaultCreateOptions={graphicProperties:{attributes:l,sourceLayer:s},mode:d.createOptions.mode,optionsPerTool:d.createOptions.optionsPerTool,preserveAspectRatio:d.createOptions.preserveAspectRatio,hasZ:p.data.supportsZ,defaultZ:(u?p.editing.zDefault:null)??e.defaultCreateOptions.defaultZ},null==o.geometryToPlace?await e.create(d.tool):await e.place(o.geometryToPlace,{graphicProperties:{attributes:l,sourceLayer:s}})}async function Ae(e){return s([Le(e),Ue(e)])}function Le({creationAttributes:e,data:t,sketchViewModel:r,view:n,webStyleCache:o}){const{creationInfo:i}=t,{fullTemplate:a}=t;if(!i||"2d"!==n?.type||j(a)||k(a))return null;const s=f(t=>Ne(r,i.layer,e,o,t));return b(()=>n.scale,e=>s(e))}function Ue({data:t,sketchViewModel:r,view:n}){const{templateExecutorInfo:o}=t;if(!o)return null;const i=r.activeComponent;if(!n||!_(i))return ee().error(new a("featureworkflow","Failed to set up template feedback.")),null;const c=new U({effect:"saturate(0.6) opacity(0.8)",listMode:"hide",title:"Shared Template Feedback Graphics"});n.map?.add(c);const{executor:u,serviceLayersById:p}=o,d=n.theme?.accentColor??new e([255,165,0,1]);return s([g(()=>i,["cursor-update","vertex-add"],()=>{c.removeAll();const e=i.graphic?.geometry;if(!e||!Ve(e))return;const t=u(e,"digitizing");if(!y(t))for(const r of t.edits){const e=p.get(r.id);if(e&&r.addFeatures&&0!==r.addFeatures.length)for(const t of e)if(!t.isTable)for(const e of r.addFeatures){const t=Me(e,d);t&&c.add(t)}}}),l(()=>{n.map.remove(c),c.destroy()})])}function Ve(e){switch(e.type){case"point":case"multipoint":return!0;case"polyline":return e.paths[0].length>1;case"polygon":{const t=e.rings[0];return n(t.at(0),t.at(-1))?t.length>2:t.length>1}default:return!1}}function Me(e,r){let n=null;switch(e.geometry?.type){case"point":case"multipoint":n=new Z({angle:0,color:r,outline:new B({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:1}),path:"undefined",size:8,style:"circle",xoffset:0,yoffset:0});break;case"polygon":n=new G({color:r,outline:new B({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:3}),style:"none"});break;case"polyline":n=new B({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:2});break;default:return null}return new t({geometry:e.geometry,symbol:n,attributes:{...e.attributes}})}function Oe(e,t){const r=W(t),n=x(e)?e.parent:e;return r.tablesAndLayersLookup.get(n)}function xe(e,t){const r=Oe(e,t);if(!r)return new Map;const n=new Map;for(const o of r.layersAndTables)d(n,o.layerId,()=>[]).push(o);return n}function qe(e){const t=e.objectIdField,r=e.globalIdField??"";return{id:e.layerId,identifierFields:{objectIdField:t,globalIdField:r},addFeatures:[],deleteAttachments:[],addAttachments:[],deleteFeatures:[],updateFeatures:[]}}function ze(e){const{edits:t,serviceInfo:n,view:o,findOriginalFeature:i}=e,a=Ce(n.layersAndTables),s=n.layersAndTables.toArray(),{allEditData:l,editDataByLayerIdMap:c,editDataByIdMap:u}=Pe(t,a,i),p=De(l,Ee(s,c),c);if(o&&Be(l,p,o),0===p.length)return t;const d=Y(p,{continueOnCircularDependency:!0}).map(e=>u.get(e)).filter(r),f=new Map;for(const r of d)f.set(r.uniqueId,r);const y=[];for(const r of l)f.has(r.uniqueId)||y.push(r);const m=[];let h=null;for(const r of d){const{layer:e}=r;switch(null==h?h=qe(e):h.id!==e.layerId&&(m.push(h),h=qe(e)),r.operationType){case"add":case"modify":h.addFeatures.push(r.after);break;case"delete":h.deleteFeatures.push(r.before)}}null!==h&&m.push(h);for(const r of y){const e=r.layer.layerId,t=m.find(t=>t.id===e)??qe(r.layer);switch(m.includes(t)||m.push(t),r.operationType){case"add":t.addFeatures.push(r.after);break;case"modify":t.updateFeatures.push(r.after);break;case"delete":t.deleteFeatures.push(r.before);break;case"deleteAttachment":t.deleteAttachments.push(r.attachmentId);break;case"addAttachment":t.addAttachments.push(r.attachment)}}for(const r of m)void 0!==r.deleteAttachments&&0===r.deleteAttachments.length&&delete r.deleteAttachments,void 0!==r.addAttachments&&0===r.addAttachments.length&&delete r.addAttachments;return m}function Ce(e){const t=new Map;for(const r of e)t.set(r.layerId,r);return t}function Ee(e,t){const r=new Map;for(const n of e)for(const e of n.relationships??[])if(r.set(Re(n,e),""),t.has(e.relatedTableId)){const o=t.get(e.relatedTableId);if(o.length>0)for(const t of o[0].layer.relationships??[])if(t.id===e.id){r.set(Re(n,e),t.keyField);break}}return r}function Pe(e,t,r){const n=new Map,o=[],i=new Map;let s=1;for(const l of e){const e=[],c=t.get(l.id);if(!c)throw new a("featureworkflow",`Failed to prepare applyEdits payload. Layer with id ${l.id} not found.`);for(const t of l.addFeatures??[])e.push({uniqueId:"T"+s++,operationType:"add",layer:c,after:t});for(const t of l.deleteFeatures??[])e.push({uniqueId:"T"+s++,operationType:"delete",before:t,layer:c});for(const t of l.deleteAttachments??[])e.push({uniqueId:"T"+s++,operationType:"deleteAttachment",attachmentId:t,layer:c});for(const t of l.addAttachments??[])e.push({uniqueId:"T"+s++,operationType:"addAttachment",attachment:t,layer:c});for(const t of l.updateFeatures??[])e.push({uniqueId:"T"+s++,operationType:"modify",before:r(t),after:t,layer:c});n.set(c.layerId,e);for(const t of e)o.push(t),i.set(t.uniqueId,t)}return{allEditData:o,editDataByIdMap:i,editDataByLayerIdMap:n}}function De(e,t,r){const n=[];for(const o of e){const e=o.layer.relationships??[],{uniqueId:i}=o;for(const a of e){const e=a.keyField;if("origin"===a.role){const s=r.get(a.relatedTableId);if(!s||0===s.length)continue;const l=Re(o.layer,a),c=t.get(l);if(void 0===c||""===c)continue;switch(o.operationType){case"add":for(const t of s)t!==o&&("add"!==t.operationType&&"modify"!==t.operationType||t.after.attributes[c]===o.after.attributes[e]&&n.push([i,t.uniqueId]));break;case"modify":if(o.before.attributes[e]!==o.after.attributes[e])for(const t of s){const r=t.uniqueId;t!==o&&("delete"===t.operationType?t.before.attributes[c]===o.before.attributes[e]?n.push([r,i]):t.before.attributes[c]===o.after.attributes[e]&&n.push([i,r]):"add"===t.operationType?t.after.attributes[c]===o.after.attributes[e]?n.push([i,r]):t.after.attributes[c]===o.before.attributes[e]&&n.push([r,i]):"modify"===t.operationType&&(t.before.attributes[c]!==t.after.attributes[c]?t.after.attributes[c]===o.after.attributes[e]?n.push([i,r]):n.push([r,i]):n.push([i,r])))}break;case"delete":for(const t of s)t!==o&&("delete"!==t.operationType&&"modify"!==t.operationType||t.before.attributes[c]===o.before.attributes[e]&&n.push([t.uniqueId,i]))}}}}return n}function Re(e,t){return`${e.layerId}:${t.id}`}function Ge(e,t){return!!(t?.map&&"utilityNetworks"in t.map&&t.map.utilityNetworks?.length&&t.map.utilityNetworks.some(t=>!(!t.loaded||!e.url?.startsWith(t.featureServiceUrl)||e.layerId!==t.networkSystemLayers.associationsTableId)))}function Be(e,t,r){const n=[];for(const i of e)Ge(i.layer,r)&&n.push(i);if(0===n.length)return;let o=[];for(const i of n){const r=i.layer;switch(i.operationType){case"delete":o=[...Ze(i.before.attributes[r.fieldsIndex.get("fromglobalid").name],e),...Ze(i.before.attributes[r.fieldsIndex.get("toglobalid").name],e)];for(const e of o)t.push([i.uniqueId,e.uniqueId]);break;case"add":o=[...Ze(i.after.attributes[r.fieldsIndex.get("fromglobalid").name],e),...Ze(i.after.attributes[r.fieldsIndex.get("toglobalid").name],e)];for(const e of o)t.push([e.uniqueId,i.uniqueId])}}}function Ze(e,t){const r=[],n=t.filter(({layer:e})=>""!==e.globalIdField&&null!=e.globalIdField);for(const o of n){const t=o.layer.globalIdField;("before"in o&&o.before?.attributes[t]===e||"after"in o&&o.after?.attributes[t]===e)&&r.push(o)}return r}async function Ne(e,r,n,o,i){const a=new t({sourceLayer:r,attributes:n}),{rotation:s,size:l}=be(a);let c=await Q(a,{useSourceLayer:!0,webStyleCache:o,scale:i}),u=!1;for(const t of[l,s]){if(null==t)continue;null==n[t.field]&&(n[t.field]=await t.getDefaultValue(c,e.view),u=!0)}switch(u&&(c=await Q(a,{useSourceLayer:!0,webStyleCache:o,scale:i})),c?.type){case"simple-fill":case"polygon-3d":e.polygonSymbol=c;break;case"simple-line":case"line-3d":e.polylineSymbol=c;break;case"simple-marker":case"picture-marker":case"point-3d":case"cim":e.pointSymbol=c;break;case"mesh-3d":e.meshSymbol=c}Qe(e.tooltipOptions,l,s)}function Qe(e,t,r){e.visualVariables=null!=t||null!=r?{size:null!=t?{unit:t.displayUnit,axis:t.axis,valueType:t.fieldType}:null,rotation:null!=r?{valueType:r.fieldType,rotationType:r.rotationType??"geographic"}:null}:null}function We(e,t){return e.find(e=>e.layer===t)}function $e(e,t){const r=We(e,t);if(null==r)throw new a("no-editorItem-found","The EditorViewModel provided did not have an EditorItem associated with the specified layer");return r}function He(e,t){return e?.find(e=>e.layer===t)}async function Je(e,t,r,n){switch(t.type){case"3d":return Ke(e,t,r,n);case"2d":return Xe(e,t,r,n)}}async function Ke(e,t,r,n){if(0===e.length)return[];const{updatable:i,graphicsByLayer:a}=await r.defer(async()=>{const{results:o}=await h(X(t,r),n),i=new Map,a=e=>{const t=e.layer,r=i.get(t);if(!r){const e=new Array;return i.set(t,e),e}return r};K(o).forEach(({graphic:e})=>a(e).push(e));const s=e.filter(({capabilities:e,layer:t})=>e.update.enabled&&i.has(t));return 0!==s.length&&r.stopPropagation(),{updatable:s,graphicsByLayer:i}});return h(Promise.allSettled(i.map(async({layer:e})=>{const t=a.get(e),r=Ye(e);if(t.every(e=>V(e,r)))return t;const i=[];for(const n of t){i.push(n.getObjectId());const e=Object.keys(n.attributes);o(r,e)}const s=e.createQuery();return s.returnGeometry=!1,s.objectIds=i,s.outFields=M(e.fieldsIndex,r),e.queryFeatures(s,{signal:n}).then(({features:e})=>e)})),n)}async function Xe(e,t,r,n){if(0===e.length)return[];const{mapPoint:o}=r;if(null==o)return[];let i=null;const a=await r.defer(async()=>{const{results:o}=await h(t.hitTest(r),n);if(0===o.length)return[];const a=new Set;i=K(o),i.forEach(({graphic:e})=>e&&a.add(e.layer));const s=e.filter(e=>a.has(e.layer)&&e.supportsUpdateWorkflow);return s.length>0&&r.stopPropagation(),s});return h(Promise.allSettled(a.map(async({layer:e})=>{const a=e.createQuery();a.returnGeometry=!0,a.outFields=Ye(e);const s="renderer"in e?C({renderer:e.renderer,pointerType:r.pointerType}):0;a.geometry=J(o,s,t),a.outSpatialReference=t.spatialReference;const{features:l}=await e.queryFeatures(a,{signal:n});return i?.forEach(({graphic:t})=>{t.layer!==e||l.some(e=>e.getObjectId()===t.getObjectId())||l.push(t)}),l})),n)}function Ye(e){return M(e.fieldsIndex,[e.objectIdField,O({displayField:"displayField"in e?e.displayField:null,fields:e.fields})])}async function _e(e,t,n,o){return et(e.map(e=>e.getObjectId()??e.attributes[t.objectIdField]).filter(r),t,n,o)}async function et(e,t,r,n){const o=t.createQuery();o.objectIds=e,o.outFields=["*"],o.returnM=t.capabilities.data.supportsM,o.returnZ=t.capabilities.data.supportsZ,o.returnGeometry=!0,z(t)&&null!=t.infoFor3D||(o.outSpatialReference=r),!z(t)&&t.capabilities?.data.supportsTrueCurve&&(o.returnTrueCurves=!0);const i=await t.queryFeatures(o,{signal:n});return m(n),i.features}async function tt(e){const{graphic:t,sketchViewModel:r,sourceLayer:n,updateOptions:o,visualVariables:i}=e;await rt(e);const a={multipleSelectionEnabled:!1,...o};return"point"===n.geometryType&&(a.enableRotation=null!=i.rotation,a.enableScaling=null!=i.size),r.update(t,a)}async function rt(e){const{graphic:t,sketchLayer:r,sketchViewModel:n,sourceLayer:o,visualVariables:i,webStyleCache:a}=e;let s=!1;const{rotation:l,size:c}=i;for(const u of[l,c]){if(null==u)continue;const e=t.getAttribute(u.field);if(null!=e)u.setInitialValue(e);else{const e=await u.getDefaultValue(t.symbol,n.view);u.setInitialValue(e),t.setAttribute(u.field,e),s=!0}}if(s){const e="2d"===n.view?.type?n.view.scale:null;await je(t,a,e)}Qe(n.tooltipOptions,c,l),r.elevationInfo=o.elevationInfo}function nt(e){return null==e||"rotate-start"!==e.type&&"rotate"!==e.type&&"rotate-stop"!==e.type?null:e}function ot(e){return null==e||"scale-start"!==e.type&&"scale"!==e.type&&"scale-stop"!==e.type?null:e}function it(e,t,r,n){if(null==t.geometry||"point"!==t.geometry?.type)return!1;const o=t.attributes;let i=!1;const a=n.rotation,s=nt(r.toolEventInfo);if(null!=a&&null!=s){const{field:r,getValue:n}=a;if("rotate-stop"===s.type)a.isUpdatingInteractively=!1,a.setInitialValue(t.getAttribute(r));else{a.isUpdatingInteractively=!0;const l=n(s.angle,e);l!==o[r]&&t.setAttribute(r,l),i=!0}}const l=n.size,c=ot(r.toolEventInfo);if(null!=l&&null!=c){const{field:r,getValue:n}=l;if("scale-stop"===c.type)l.isUpdatingInteractively=!1,l.setInitialValue(t.getAttribute(r));else{l.isUpdatingInteractively=!0;const a=n(c.xScale,e);a!==o[r]&&t.setAttribute(r,a),i=!0}}return i}async function at({feature:e,featureClone:t,sketchLayer:r,sketchViewModel:n,updateOptions:o,view:i,visualVariableAttributes:a,webStyleCache:u,addHandle:p,addUpdatingPromise:d,onUpdate:y}){await je(t,u,"2d"===i.type?i.scale:null);let m=null;if("2d"===n?.view?.type){const e=f(e=>je(t,u,e));m=b(()=>n?.view?.scale,t=>e(t))}const h=t.sourceLayer,g=mt(i,h);await tt({graphic:t,sketchLayer:r,sketchViewModel:n,sourceLayer:h,updateOptions:o,visualVariables:a,webStyleCache:u});let I=null;g.then(e=>I=e).catch(()=>{});const v=a.size,T=a.rotation,F=b(()=>e.attributes,async e=>{let r=!1;for(const n in e){const o=e[n];o!==t.getAttribute(n)&&(t.setAttribute(n,o),null==v||v.isUpdatingInteractively||v.field!==n||v.setInitialValue(o),null==T||T.isUpdatingInteractively||T.field!==n||T.setInitialValue(o),(null==I||I.requiredFields.includes(n))&&(r=!0))}r&&await je(t,u,"2d"===i.type?i.scale:null)}),j=n.on("update",async e=>{const t=e.graphics[0],s={graphic:t,sketchLayer:r,sketchViewModel:n,sourceLayer:h,updateOptions:o,visualVariables:a,webStyleCache:u};if("complete"===e.state){if(null===i.activeTool)return tt(s);const e=new AbortController,t=c(e);return p(t),d(w(()=>null===i.activeTool,e.signal).then(async()=>{if(!e.signal.aborted)return e.abort(),tt(s)}))}it(i,t,e,a)&&await je(t,u,"2d"===i.type?i.scale:null),y(bt(t),e)}),S=n.on(["undo","redo"],e=>{y(bt(e.graphics[0]),e)});return s([S,j,l(()=>n.cancel()),F,m])}async function st(e,t,r,n){e.add(n);const o=r.sourceLayer,a=r.layer??o,c=r.getAttribute(o.objectIdField);let u=null;function p(e){u?.abort(),q(a)?r.visible=e:u=i(async r=>{const n=await mt(t,a);m(r),n.setVisibility?.(c,e)})}return await lt(t,n),p(!1),s([l(async()=>{p(!0);try{if(!t.destroyed){const e=await mt(t,a).catch(()=>{});e&&!e.destroyed&&await w(()=>!e.updating)}}finally{e.remove(n)}})])}async function lt(e,t){if("3d"===e.type){const r=new $({graphic:t}),n=e.trackGraphicState(r);await w(()=>r.displaying||r.error),n.remove()}else await w(()=>t.visible)}const ct={icon:I(24),text:I(12),line:I(1),viewScaleSizeFactor:100};function ut(e,t,r){let n=!1;return e.filter(e=>!!n||(n=e===t,n)).map(e=>r[e]())}function pt(e,t){e.viewModel.syncFeatureTemplates();const r=e.creationInfo;if("awaiting-feature-creation-info"===t[0].id&&r){const n=r.layer,o=e.viewModel.getTemplatesForLayer(n);1===o.length&&"scene"!==n.type&&(r.template=o[0],t.shift())}return t}function dt(e){return"unknown"===e?null:e}function ft(e){e.filesEnabled=!0,e.mode="view",e.capabilities={editing:!0,operations:{add:!0,update:!0,delete:!0}}}const yt=e=>e.includes("-stop")||e.includes("vertex-"),mt=(e,t)=>{const r="subtype-sublayer"===t.type?t.parent:t;return e.whenLayerView(r)};function ht(e){return"createInteractiveEditSession"in e}function bt(e){const t=e.geometry;if("mesh"===t?.type){const r=e.cloneShallow();return r.attributes=u(e.attributes),r.geometry=t.cloneShallow(),r.geometry.transform=t.transform?.clone()??null,r}return e.clone()}function gt(e){return e.acquireCursor("progress")}function wt(e){for(const t of e){const{destinationGraphic:e,destinationField:r,sourceGraphic:n,sourceField:o}=t;e.setAttribute(r,n.getAttribute(o))}}function It(e){const t=e.templateExecutorInfo?.completionResults;return t?.length?(t.forEach(e=>wt(e.relationships)),t.flatMap(e=>e.edits)):null}function vt(e){const t=le(e)?e.activeWorkflow:e;if(null==t)return[];if(ie(t))return t.data.layers;const r=t.layer;return r?[r]:[]}function Tt({attributes:e},t){const r=new Set;r.add(t.objectIdField),"uniqueIdFields"in t&&t.uniqueIdFields&&t.uniqueIdFields.length>0&&v(r,t.uniqueIdFields);const n={};for(const o of r)null!=e[o]&&(n[o]=e[o]);if("scene"===t.type&&null!=t.infoFor3D){const r=t.associatedLayer?.globalIdField;null!=r&&(e[r]=e[r])}return n}function Ft(e){if(!jt(e))return e;const t=new Map;for(const r of e){const e=r.getObjectId();if(null!=e){const n=r.sourceLayer??r.layer;d(t,n,()=>[]).push(e)}}return Array.from(t.entries()).map(([e,t])=>({layer:e,objectIds:t}))}function jt(e){return 0===e.length||R(e[0])}function St({drawTool:e},t){const r=e?.mostDownstreamPlugin?.configuration?.curveTypes;if(!t||!r||0===r.length)return!1;const n=new Set(t.capabilities.supportedCurveTypes);return r.some(e=>!n.has(e))}function kt(e,t){const r=new Set(t.capabilities.supportedCurveTypes);return e.some(({geometry:e})=>e&&A(e)&&L(e,r))}export{St as activeSketchToolDrawsUnsupportedCurve,Be as appendAllUtilityNetworkAssociationRelationships,pt as avoidFeatureTemplateSelectionWithOnlyOneItem,ht as canCreateInteractiveEditSession,bt as cloneGraphicExceptMesh,kt as containsUnsupportedCurve,Ce as createLayerIdMap,Ee as createRelationshipKeyMap,Se as createToolFromGeometryType,ut as createWorkflowSteps,Je as fetchCandidates,_e as fetchFullFeatures,et as fetchFullFeaturesByObjectId,De as findAllDependencies,Ze as findChangesByGlobalId,We as findEditorItemForLayer,$e as findEditorItemForLayerOrThrow,He as findLayerInfo,Re as generateHashForRelationship,vt as getLayersFromWorkflow,ge as getRotationVariableAttribute,It as getServiceEditsFromWorkflowData,Oe as getServiceInfoForLayer,xe as getServiceLayersById,ve as getSizeVariableAttribute,be as getVisualVariableAttributes,he as getVisualVariablesForLayer,te as isAnyUpdateLeafWorkflow,re as isBatchAttributeFormViewModel,ne as isCreateFeaturesWorkflow,oe as isFeatureFormViewModel,jt as isGraphicsArray,ce as isMergeFeaturesWorkflow,de as isMergeWorkflowOptions,pe as isParentWorkflow,ue as isSplitFeatureWorkflow,fe as isSplitWorkflowOptions,yt as isTerminalUpdateEventType,ae as isUpdateFeatureWorkflow,ie as isUpdateFeaturesWorkflow,me as isUpdateFeaturesWorkflowOptions,se as isUpdateRecordWorkflow,le as isUpdateWorkflow,Ge as isUtilityNetworkAssociationsTable,Tt as makeMinimalAttributes,ze as orderEditsByRelationshipDependencies,ft as prepareAttachmentsForCreateFeaturesWorkflow,wt as setRelationshipFields,at as setUpGeometryUpdate,Ae as setUpSketchCreateWatchers,rt as setVisualVariablesAndElevationInfoForUpdate,gt as showProgressCursor,ct as sizeDefaults,dt as sizeVariableUnitToLengthUnit,ke as startCreatingNewFeature,tt as startUpdatingFeatureGeometry,st as swapForEditingSession,Ft as toFeatureInfos,je as updateGraphicSymbolWhenRequired,it as visualVariableInteractiveUpdate,mt as whenEditorLayerView,lt as whenGraphicDisplayed,ye as workflowInfluencesOutcomeOfParent};
|