@arcgis/core 4.33.0-next.20250423 → 4.33.0-next.20250424
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/Graphic.js +1 -1
- package/WebScene.js +1 -1
- package/analysis/Analysis.d.ts +4 -0
- package/analysis/Analysis.js +1 -1
- package/analysis/SliceAnalysis.js +1 -1
- package/analysis/SlicePlane.js +1 -1
- package/analysis/support/AnalysisOriginWebScene.d.ts +4 -0
- package/analysis/support/AnalysisOriginWebScene.js +5 -0
- package/analysis/support/SliceAnalysisExcludedLayer.js +5 -0
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{d4d011eea16a89a5aad9.js → 0219c3f9408d3fa3c9a0.js} +1 -1
- package/assets/esri/core/workers/chunks/{4f8782b3b6ad414409e8.js → 0a48b9734ab4c64a6f4f.js} +1 -1
- package/assets/esri/core/workers/chunks/{ccc50f28f217e50cc2c3.js → 1427e7953c3d8c87c5e8.js} +1 -1
- package/assets/esri/core/workers/chunks/{184d7c8ea818bec5c462.js → 146b3699a9e8b1f2dcc2.js} +1 -1
- package/assets/esri/core/workers/chunks/{8ba7d44eff348004f084.js → 1a6d2d090b643a87408a.js} +1 -1
- package/assets/esri/core/workers/chunks/1b8cc83aa1179245b2dc.js +1 -0
- package/assets/esri/core/workers/chunks/{5e5225623977e61fd0ef.js → 213adc87c843d627c5d6.js} +1 -1
- package/assets/esri/core/workers/chunks/{fa8a3c75f9b41d31559b.js → 265f69d153b7b6f07e42.js} +1 -1
- package/assets/esri/core/workers/chunks/{769b66cca8347f0f84db.js → 279bbd61b32577693a4a.js} +1 -1
- package/assets/esri/core/workers/chunks/290b065b377f9d2ee058.js +1 -0
- package/assets/esri/core/workers/chunks/29d3245261a7223124ed.js +1 -0
- package/assets/esri/core/workers/chunks/335b539893569e3d7b82.js +1 -0
- package/assets/esri/core/workers/chunks/5958af341014e13475d2.js +1 -0
- package/assets/esri/core/workers/chunks/60f7cd05e88701f43d3f.js +1 -0
- package/assets/esri/core/workers/chunks/{26e0a0a13060cd3e4291.js → 626ba3a7dee952308566.js} +1 -1
- package/assets/esri/core/workers/chunks/7cd32b10ed0e18e44ef2.js +1 -0
- package/assets/esri/core/workers/chunks/7ffa68d69c138db1295d.js +1 -0
- package/assets/esri/core/workers/chunks/91f8547a13f0461045ef.js +1 -0
- package/assets/esri/core/workers/chunks/9661ee8569ee208e6237.js +1 -0
- package/assets/esri/core/workers/chunks/974742af7beb000c4b4a.js +1 -0
- package/assets/esri/core/workers/chunks/{e27fa1e84f16b7f19a90.js → 9850ff14bd9c7da81c65.js} +1 -1
- package/assets/esri/core/workers/chunks/{a276980c06d5d311a37e.js → 9f416cc5673665f8c37c.js} +1 -1
- package/assets/esri/core/workers/chunks/a0c51c4c30a5f749dfc6.js +1 -0
- package/assets/esri/core/workers/chunks/{fdcbd28f38bc485ac5e3.js → ab6ecd8eeec5ff761b34.js} +1 -1
- package/assets/esri/core/workers/chunks/{5bdd5ae2d2f23ef6b331.js → c87e2a63b96e0da77dfe.js} +1 -1
- package/assets/esri/core/workers/chunks/cc4dd739c4c7e3ccea3f.js +1 -0
- package/assets/esri/core/workers/chunks/d3a74087e076a3ae76ca.js +1 -0
- package/assets/esri/core/workers/chunks/{26fcbe053194bd78fcc3.js → d8474dca270b25705699.js} +1 -1
- package/assets/esri/core/workers/chunks/{7c42281188b874ffcdad.js → db5913824d5e5a2a8365.js} +1 -1
- package/assets/esri/core/workers/chunks/{48a1bb1e171dd06a7c6e.js → dd94585508f49863dc15.js} +1 -1
- package/assets/esri/core/workers/chunks/{9408a72968cbd985dd24.js → f2cef954b58c6604642c.js} +34 -34
- package/chunks/BloomBlur.glsl.js +7 -7
- package/chunks/BloomComposition.glsl.js +24 -25
- package/chunks/cameraUtilsSpherical.js +1 -1
- package/chunks/sphere.js +1 -1
- package/core/Collection.js +1 -1
- package/core/JSONSupport.js +1 -1
- package/core/SetUtils.js +1 -1
- package/{views/webgl/GLObjectType.js → core/support/jsonUtils.js} +1 -1
- package/core/urlUtils.js +1 -1
- package/geometry/Mesh.js +1 -1
- package/geometry/support/normalizeUtilsSync.js +1 -1
- package/geometry/support/sphere.js +1 -1
- package/interfaces.d.ts +344 -111
- package/layers/DimensionLayer.js +1 -1
- package/layers/RouteLayer.js +1 -1
- package/layers/SubtypeGroupLayer.js +1 -1
- package/layers/ViewshedLayer.js +1 -1
- package/layers/graphics/data/QueryEngine.js +1 -1
- package/layers/orientedImagery/transformations/imageToWorld.js +1 -1
- package/layers/orientedImagery/transformations/utils.js +1 -1
- package/layers/support/FieldsIndex.js +1 -1
- package/layers/support/VideoElement.js +1 -1
- package/layers/support/rasterDatasets/FunctionRaster.js +1 -1
- package/layers/support/rasterDatasets/TIFFRaster.js +1 -1
- package/layers/support/rasterFormats/TiffDecoder.js +1 -1
- package/layers/support/rasterFormats/{TiffTags.js → tiffTag.js} +1 -1
- package/layers/support/rasterFunctions/BandArithmeticFunction.js +1 -1
- package/layers/support/rasterFunctions/BaseRasterFunction.js +1 -1
- package/layers/support/rasterFunctions/ExtractBandFunction.js +1 -1
- package/layers/support/rasterFunctions/NDVIFunction.js +1 -1
- package/layers/support/rasterFunctions/RemapFunction.js +1 -1
- package/layers/support/rasterFunctions/rasterFunctionHelper.js +1 -1
- package/layers/support/videoUtils.js +5 -0
- package/package.json +1 -1
- package/portal/schemas/definitions.js +1 -1
- package/renderers/UniqueValueRenderer.js +1 -1
- package/renderers/support/colorRampUtils.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/IconSymbol3DLayer.js +1 -1
- package/symbols/cim/effects/EffectTaperedPolygon.js +1 -1
- package/views/2d/engine/webgl/meshing/Mesh.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/typed/TypedShaderProgram.js +1 -1
- package/views/2d/engine/webgl/textureUtils.js +1 -1
- package/views/2d/layers/MediaLayerView2D.js +1 -1
- package/views/2d/layers/TileLayerView2D.js +1 -1
- package/views/2d/layers/support/DebugOverlay.js +1 -1
- package/views/3d/analysis/LineOfSightAnalysisView3D.js +1 -1
- package/views/3d/analysis/Slice/SliceTool.js +1 -1
- package/views/3d/analysis/Slice/SliceVisualization.js +1 -1
- package/views/3d/analysis/SliceAnalysisView3D.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedAnalysisVisualization.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedVisualization.js +1 -1
- package/views/3d/analysis/ViewshedAnalysisView3D.js +1 -1
- package/views/3d/camera/constraintUtils/distance.js +1 -1
- package/views/3d/camera/intersectionUtils.js +1 -1
- package/views/3d/environment/ChapmanAtmosphere.js +1 -1
- package/views/3d/environment/atmosphereUtils.js +1 -1
- package/views/3d/interactive/visualElements/DrapedVisualElementResources.js +1 -1
- package/views/3d/interactive/visualElements/EngineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/ExtendedLineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/LabelVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/LaserlineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/LineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/MarkerVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/MeasurementAreaVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/MeasurementArrowVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/OutlineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/ParallelLineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/PointVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/SlicePlaneVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/VerticesVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/ViewshedShapeVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/VisualElement.js +1 -1
- package/views/3d/interactive/visualElements/VisualElementResources.js +1 -1
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/graphics/Deconflictor.js +1 -1
- package/views/3d/layers/i3s/I3SMeshViewFilter.js +1 -1
- package/views/3d/state/ConstraintsManager.js +1 -1
- package/views/3d/state/NearFarHeuristic.js +1 -1
- package/views/3d/state/ViewState.js +1 -1
- package/views/3d/state/ViewStateManager.js +1 -1
- package/views/3d/state/utils/navigationUtils.js +1 -1
- package/views/3d/support/cameraUtilsSpherical.js +1 -1
- package/views/3d/support/geometryUtils/sphere.js +1 -1
- package/views/3d/terrain/OverlayRenderTargets.js +1 -1
- package/views/3d/webgl/ManagedDepthTexture.js +1 -1
- package/views/3d/webgl-engine/core/FBOCache.js +1 -1
- package/views/3d/webgl-engine/core/FBOCacheFormats.js +5 -0
- package/views/3d/webgl-engine/core/shaderLibrary/Laserline.glsl.js +12 -14
- package/views/3d/webgl-engine/core/shaderLibrary/output/Emissions.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/bloom/BloomRenderNode.js +1 -1
- package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +1 -1
- package/views/3d/webgl-engine/effects/focusArea/FocusAreaMaskNode.js +1 -1
- package/views/3d/webgl-engine/effects/geometry/RenderOccludedRenderNode.js +1 -1
- package/views/3d/webgl-engine/effects/haze/Haze.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/Highlight.js +1 -1
- package/views/3d/webgl-engine/effects/laserlines/LaserLineRenderer.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAA.js +1 -1
- package/views/3d/webgl-engine/effects/ssao/SSAO.js +1 -1
- package/views/3d/webgl-engine/lib/DepthRange.js +1 -1
- package/views/3d/webgl-engine/lib/MainFramebuffer.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/ShadowMap.js +1 -1
- package/views/3d/webgl-engine/lib/Texture.js +1 -1
- package/views/3d/webgl-engine/lib/Viewshed.js +1 -1
- package/views/3d/webgl-engine/lib/ViewshedShadowMap.js +1 -1
- package/views/3d/webgl-engine/lib/depthRangeUtils.js +1 -1
- package/views/3d/webgl-engine/parts/RenderView.js +1 -1
- package/views/SceneView.js +1 -1
- package/views/VideoView.js +1 -1
- package/views/webgl/FBOAttachmentType.js +5 -0
- package/views/webgl/FramebufferObject.js +1 -1
- package/views/webgl/Renderbuffer.js +1 -1
- package/views/webgl/RenderbufferDescriptor.js +1 -1
- package/views/webgl/Texture.js +1 -1
- package/views/webgl/TextureDescriptor.js +1 -1
- package/views/webgl/textureUtils.js +1 -1
- package/webscene/InitialViewProperties.js +1 -1
- package/webscene/Presentation.js +1 -1
- package/webscene/Slide.js +1 -1
- package/webscene/SlideLegendInfo.js +1 -1
- package/webscene/background/ColorBackground.js +1 -1
- package/webscene/spec-certification/api.js +1 -1
- package/webscene/spec-certification/compare.js +1 -1
- package/webscene/spec-certification/index.js +1 -1
- package/webscene/spec-certification/spec.js +1 -1
- package/webscene/spec-certification/utils.js +1 -1
- package/webscene/support/Description.js +1 -1
- package/webscene/support/SlideElements.js +1 -1
- package/webscene/support/SlideEnvironment.js +1 -1
- package/webscene/support/SlideGround.js +1 -1
- package/webscene/support/SlideVisibleLayer.js +1 -1
- package/webscene/support/Title.js +1 -1
- package/webscene/support/analysisUtils.js +5 -0
- package/widgets/BatchAttributeForm/expressions/ExpressionsManager.js +1 -1
- package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
- package/widgets/Editor/EditorViewModel.js +1 -1
- package/widgets/Editor/UpdateWorkflow.js +1 -1
- package/widgets/Editor/support/SketchController.js +5 -0
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Feature/FeatureUtilityNetworkAssociationList.js +1 -1
- package/widgets/FeatureForm/FeatureFormUtilityNetworkAssociations/FeatureFormUtilityNetworkAssociationList.js +1 -1
- package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
- package/widgets/FeatureTable.js +1 -1
- package/widgets/LayerList/LayerListItem.js +1 -1
- package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
- package/widgets/Widget.js +1 -1
- package/widgets/support/SelectionList.js +1 -1
- package/widgets/support/SnappingControls.js +1 -1
- package/assets/esri/core/workers/chunks/244d2196bac5ef279436.js +0 -1
- package/assets/esri/core/workers/chunks/32f2e0c88046b39916cc.js +0 -1
- package/assets/esri/core/workers/chunks/388a763da712ca71ccf4.js +0 -1
- package/assets/esri/core/workers/chunks/5ffc3ca6c6a4d32e1282.js +0 -1
- package/assets/esri/core/workers/chunks/642a595353a86f3717e3.js +0 -1
- package/assets/esri/core/workers/chunks/93e9dfd1ba8f393c6c47.js +0 -1
- package/assets/esri/core/workers/chunks/95379fdd6917c8a84c71.js +0 -1
- package/assets/esri/core/workers/chunks/9b21dc4659922cc577cb.js +0 -1
- package/assets/esri/core/workers/chunks/a197c86d42cc9ce21924.js +0 -1
- package/assets/esri/core/workers/chunks/d81bebbb6fe000200d35.js +0 -1
- package/assets/esri/core/workers/chunks/dd8e72d6784a8ebc115d.js +0 -1
- package/assets/esri/core/workers/chunks/e9fba86036b8fe700a41.js +0 -1
- package/views/webgl/formats.js +0 -5
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as t}from"../../chunks/tslib.es6.js";import{isSome as e}from"../../core/arrayUtils.js";import{createTask as a}from"../../core/asyncUtils.js";import i from"../../core/Collection.js";import r from"../../core/Error.js";import s from"../../core/Evented.js";import{makeHandle as o}from"../../core/handleUtils.js";import n from"../../core/Logger.js";import{abortMaybe as l,removeMaybe as p,destroyMaybe as d}from"../../core/maybe.js";import{throwIfAborted as c,createResolver as u}from"../../core/promiseUtils.js";import{watch as h,on as f,when as w,whenOnce as m,syncAndInitial as y,initial as g,sync as k}from"../../core/reactiveUtils.js";import{property as v}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import{subclass as _}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as W}from"../../core/support/UpdatingHandles.js";import{getTemplatesForLayers as F}from"../../editing/templateUtils.js";import M from"../../layers/GraphicsLayer.js";import{isEditableLayer as E}from"../../layers/support/editableLayers.js";import{isFeatureLayer as I,isSubtypeGroupLayer as T,getOwningPortalUrl as b}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as V}from"../../portal/support/urlUtils.js";import A from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as C}from"../../views/interactive/snapping/SnappingManager.js";import L from"../../views/interactive/snapping/SnappingOptions.js";import U from"../Attachments/AttachmentsViewModel.js";import O from"./CreateFeaturesWorkflow.js";import S from"./UpdateWorkflow.js";import{isUpdateWorkflow as j,whenEditorLayerView as P}from"./workflowUtils.js";import R from"./support/EditorItem.js";import{makeTemplateGroupInfoForLayer as H}from"../FeatureTemplates/featureTemplatesUtils.js";import G from"../FeatureTemplates/FeatureTemplatesViewModel.js";import x from"../Sketch/SketchViewModel.js";import D from"../Spinner/SpinnerViewModel.js";import{goTo as B}from"../support/goToUtils.js";const q="esri.widgets.Editor.EditorViewModel",N=()=>n.getLogger(q);function Q(t,e,a){N().error(new r(t,e,a))}function z(t,e){return t?.find((t=>t.layer===e))}let Z=class extends s.EventedAccessor{constructor(t){super(t),this._templatesByLayer=new Map,this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new M({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updateTemplatesTask=null,this._updatingHandles=new W,this._featureTemplatesViewModelIsRestricted=!1,this.activeWorkflow=null,this._activityQueue=new i,this.editorItems=new i,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new U({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new G({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.layerInfos=null,this.ownSketchViewModel=new x({layer:this._sketchGraphicsLayer}),this.sketchOptions=new A,this.snappingOptions=new L({attributeRulesEnabled:!0}),this.spinnerViewModel=new D,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t&&"create-features"!==this.activeWorkflow?.type){if(t.submit(),!t.submittable||t.pendingSubtypeChoice)return;const e=t.getValues();if(t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0)return}await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([h((()=>{const t=this.view,e=t?.map?.editableLayers.toArray(),a=t?.allLayerViews,i=a?.filter((t=>!!e?.includes(t.layer)));return[e,i,this.layerInfos]}),(()=>this._updateEditorItems()),y),h((()=>this.hideTemplatesForInactiveLayers),(()=>this.syncFeatureTemplates())),f((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),f((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),f((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),w((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),g),f((()=>this.editorItems),"change",(()=>this._afterEditorItemsChange())),h((()=>[this.canCreate,this.canUpdateVisible]),(()=>this._afterEditorItemsChange())),h((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),y),w((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),f((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const i={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(i);this.startCreateFeaturesWorkflowAtFeatureCreation(i)})),h((()=>[this.view,this.featureTemplatesViewModel]),(([t,e])=>{e.view=t}),y),f((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),f((()=>this.sketchViewModel),["create","delete","update"],(t=>{const{activeWorkflow:e}=this,a="update"===e?.type,i=a?e.activeWorkflow?.layer:e?.layer,r=a?e?.activeWorkflow?.parentLayer:void 0,s=`sketch-${t.type}`;this.emit(s,{type:s,detail:t,layer:i,parentLayer:r})}),k),h((()=>this.view),(t=>{if(this._snappingManager=d(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new C({view:t,options:e}),this.ownSketchViewModel.snappingManager=this._snappingManager}),y),h((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),y)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=l(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=p(this._sketchEventListenerHandle)}get _featureTemplatesLayersAndTables(){const t=new i;for(const e of this.editorItems){const a=this.hideTemplatesForInactiveLayers&&!e.visible;e.supportsCreateFeaturesWorkflow&&!a&&t.push(e.layer)}return t}get activeLeafWorkflow(){const t=this.activeWorkflow;return t&&j(t)?t.activeWorkflow??t:t}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get canUpdateVisible(){return this.editorItems.some((t=>t.supportsUpdateWorkflow&&t.visible))}get featureTemplatesLayers(){return this._featureTemplatesLayersAndTables.filter((t=>"scene"===t.type||!t.isTable))}get featureFormViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeFeatureFormViewModel:"create-features"===t?.type?t.featureFormViewModel:null}get utilityNetworkAssociationAddAssociationViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeUtilityNetworkAssociationAddAssociationViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(t){this.sketchOptions.labels=t}get sketchViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeSketchViewModel:"create-features"===t?.type?t.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?.stepId?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}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(t){this.sketchOptions.tooltips=t}get valueOptions(){return this.sketchOptions.values}set valueOptions(t){this.sketchOptions.values=t}set view(t){this.ownSketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get canZoomTo(){const t=this.sketchViewModel,e=t?.createGraphic?.geometry?.type;return!(!t?.updateGraphics?.length&&"multipoint"!==e)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel?.associatedLayer)return"viewing-associated-features";if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel?.associationId)return"viewing-associated-layers";if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditorItem?.capabilities.update.attributes}get featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditorItem?.capabilities.delete.enabled}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}get snappingManager(){return this._snappingManager}getTemplatesForLayer(t){return this._templatesByLayer.get(t)??[]}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await m((()=>!this.updating)),!this.canCreate)throw new r("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();try{await this._cancelWorkflow();const a=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",a),await a.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{a.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(t){await m((()=>!this.updating));const e=this._createUpdatingResolver();try{const{initialFeature:e}=t,a=e.sourceLayer=e.layer,i=a?this.findEditorItemForLayer(a):void 0;if(!i?.supportsCreateFeaturesWorkflow)throw new r("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const s=this._createCreateFeaturesWorkflow({initialFeature:e,layer:i.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",s),await s.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await m((()=>!this.updating)),!this.canUpdate)return void Q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow();this._set("activeWorkflow",t),await t.start()}catch(e){this._logErrorAndCancelWorkflow(e)}finally{t.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await m((()=>!this.updating)),!this.canUpdate)return void Q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("awaiting-update-feature-candidate");e.data.candidates=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureEdit(t){if(await m((()=>!this.updating)),!this.canUpdate)return void Q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("editing-existing-feature");e.data.rootFeature=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():Q("editing:unsupported-workflow","Deleting a feature requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveAssociation():Q("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){return this.editorItems.find((e=>e.layer===t))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelIsRestricted||this._updateTemplates()}zoomTo(t){const a=this.sketchViewModel,i=t?t.geometry:a?.updateGraphics.length?a?.updateGraphics.toArray().map((t=>t.geometry)).filter(e):a?.createGraphic?.geometry;i&&this.view&&B(this.view,i)}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()))}restrictFeatureTemplatesViewModelToLayer(t){return this._featureTemplatesViewModelIsRestricted=!0,this._setFeatureTemplatesViewModelLayers([t]),o((()=>{this._featureTemplatesViewModelIsRestricted=!1,this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)}))}async _getEditorItemCandidates(t){const{view:e}=this;if(!e?.map)return[];const{map:a}=e,i=a.editableLayers.toArray(),r=a.allTables.toArray().filter((t=>I(t)||T(t)));return await Promise.allSettled([...i.flatMap((t=>this._getLayerLoadPromise(t))),...r.flatMap((t=>this._getLayerLoadPromise(t)))]),c(t),[...i.reverse(),...r.reverse()].filter((t=>E(t)&&("mesh"!==t.geometryType||"3d"===e.type))).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_getLayerLoadPromise(t){return T(t)?t.loadAll():t.load()}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}_updateEditorItems(){l(this._updateItemsTask);const{view:t}=this,e=a((async e=>{if(!t?.map||!t?.allLayerViews)return;const a=await this._getEditorItemCandidates(e);if(!a.length)return void this._drainEditorItems();const i=[],r=[],s=[],{layerInfos:o}=this;for(const l of a){const e=z(o,l),a=await P(t,l).catch((()=>null));(e?i:a?r:s).push(new R({layer:l,layerInfo:e,layerView:a}))}o?.length&&i.sort(((t,e)=>o.findIndex((({layer:e})=>e===t.layer))-o.findIndex((({layer:t})=>t===e.layer))));const n=[...i,...r,...s];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(e.promise),this._updateItemsTask=e}_updateTemplates(){l(this._updateTemplatesTask);const t=a((async t=>{const e=this._templatesByLayer,a=this._featureTemplatesLayersAndTables.filter((t=>!e.has(t)));if(a.length>0){const i=await F(a.toArray(),this.view,t);for(const{layer:t,templates:a}of i)e.set(t,a)}this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)}));this._updatingHandles.addPromise(t.promise),this._updateTemplatesTask=t}_setFeatureTemplatesViewModelLayers(t){const e=this._templatesByLayer,a=[];for(const i of t){const t=e.get(i);t&&t.length>0&&a.push(H(i,t))}this.featureTemplatesViewModel.templateInfos=a}_afterEditorItemsChange(){const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create-features"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===e&&!t.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&Q("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force){this.emit("workflow-cancel"),this._set("activeWorkflow",null);try{await e.cancel(t)}finally{e.destroy()}}else try{await e.cancel(t),this._set("activeWorkflow",null),e.destroy()}catch(a){}}_createCreateFeaturesWorkflow(t,e){return O.create({viewModel:this,creationInfo:t,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),applyEditsFeatureServiceCallback:(t,e,a)=>this._applyEditsFeatureService(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createUpdateWorkflow(t){return S.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),applyEditsFeatureServiceCallback:(t,e,a)=>this._applyEditsFeatureService(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let i=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new r("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(i=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,i))),i}async _applyEdits(t,e,a){let i=null;const r=t.url?await b(t.url):null,s={returnServiceEditsOption:(!r||!V(r))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const r=await P(a,t).catch((()=>null));return i=await t.applyEdits(e,s),r&&await m((()=>!r.updating)),i})),i}async _applyEditsFeatureService(t,e,a){let i=null;return await this._queueOperation((async()=>i=await t.applyEdits(e,a))),i}_queueOperation(t){this._activityQueue.push(t);const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>(Array.isArray(t)?t.forEach((t=>this._handleEditsResultError(t))):this._handleEditsResultError(t),t))).catch((a=>{Q("editing:operation-error","An error occurred.",{error:a});const i={error:a,retry:()=>(e(i,this.failures),this._queueOperation(t)),cancel:()=>{e(i,this.failures)}};this._set("failures",[...this.failures,i])})).then((()=>{e(t,this._activityQueue)}))}_handleEditsResultError(t){if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:i}=t,r=e.find((t=>!!t.error))||i.find((t=>!!t.error))||a.find((t=>!!t.error));if(r)throw r.error}}_createUpdatingResolver(){const t=u();return this._updatingHandles.addPromise(t.promise),t}_logErrorAndCancelWorkflow(t){const{name:e,message:a,details:i}=t;Q(e??"editing:workflow-start-failed",a??void 0,i??t),this._cancelWorkflow({force:!0})}_itemIsSuspended(t){const e=this.findEditorItemForLayer(t);return null!=e&&(!e.visible||e.disabled)}};t([v()],Z.prototype,"_featureTemplatesLayersAndTables",null),t([v()],Z.prototype,"_snappingManager",void 0),t([v({readOnly:!0})],Z.prototype,"activeWorkflow",void 0),t([v()],Z.prototype,"activeLeafWorkflow",null),t([v({readOnly:!0})],Z.prototype,"_activityQueue",void 0),t([v({readOnly:!0})],Z.prototype,"canCreate",null),t([v()],Z.prototype,"canCreateVisible",null),t([v({readOnly:!0})],Z.prototype,"canUpdate",null),t([v()],Z.prototype,"canUpdateVisible",null),t([v()],Z.prototype,"featureTemplatesLayers",null),t([v()],Z.prototype,"editorItems",void 0),t([v({readOnly:!0})],Z.prototype,"failures",void 0),t([v()],Z.prototype,"hideTemplatesForInactiveLayers",void 0),t([v({type:U})],Z.prototype,"attachmentsViewModel",void 0),t([v()],Z.prototype,"featureFormViewModel",null),t([v()],Z.prototype,"utilityNetworkAssociationAddAssociationViewModel",null),t([v({type:G})],Z.prototype,"featureTemplatesViewModel",void 0),t([v()],Z.prototype,"labelOptions",null),t([v()],Z.prototype,"layerInfos",void 0),t([v()],Z.prototype,"ownSketchViewModel",void 0),t([v()],Z.prototype,"sketchOptions",void 0),t([v()],Z.prototype,"sketchViewModel",null),t([v({type:L,nonNullable:!0})],Z.prototype,"snappingOptions",void 0),t([v()],Z.prototype,"spinnerViewModel",void 0),t([v()],Z.prototype,"state",null),t([v({readOnly:!0})],Z.prototype,"syncing",null),t([v()],Z.prototype,"updating",null),t([v()],Z.prototype,"tooltipOptions",null),t([v()],Z.prototype,"valueOptions",null),t([v()],Z.prototype,"view",null),t([v()],Z.prototype,"canZoomTo",null),t([v()],Z.prototype,"pageStack",void 0),t([v()],Z.prototype,"showDiscardEditsPrompt",void 0),t([v()],Z.prototype,"_candidateCommitted",void 0),t([v()],Z.prototype,"page",null),t([v()],Z.prototype,"featureFormDisabled",null),t([v()],Z.prototype,"featureFormHasAssociation",null),t([v()],Z.prototype,"canGoBack",null),t([v()],Z.prototype,"shouldShowDeleteButton",null),t([v()],Z.prototype,"hasPendingEdits",null),t([v()],Z.prototype,"snappingManager",null),Z=t([_(q)],Z);const $=Z;export{$ as default};
|
|
5
|
+
import{_ as t}from"../../chunks/tslib.es6.js";import{isSome as e}from"../../core/arrayUtils.js";import{createTask as a}from"../../core/asyncUtils.js";import r from"../../core/Collection.js";import i from"../../core/Error.js";import s from"../../core/Evented.js";import{makeHandle as o}from"../../core/handleUtils.js";import n from"../../core/Logger.js";import{abortMaybe as l,removeMaybe as p,destroyMaybe as d}from"../../core/maybe.js";import{throwIfAborted as c,createResolver as u}from"../../core/promiseUtils.js";import{watch as h,on as f,when as w,whenOnce as m,syncAndInitial as y,initial as g,sync as k}from"../../core/reactiveUtils.js";import{property as v}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import{subclass as _}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as W}from"../../core/support/UpdatingHandles.js";import{getTemplatesForLayers as F}from"../../editing/templateUtils.js";import E from"../../layers/GraphicsLayer.js";import{isEditableLayer as M}from"../../layers/support/editableLayers.js";import{isFeatureLayer as I,isSubtypeGroupLayer as T,getOwningPortalUrl as b}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as V}from"../../portal/support/urlUtils.js";import A from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as C}from"../../views/interactive/snapping/SnappingManager.js";import L from"../../views/interactive/snapping/SnappingOptions.js";import U from"../Attachments/AttachmentsViewModel.js";import O from"./CreateFeaturesWorkflow.js";import S from"./UpdateWorkflow.js";import{isUpdateWorkflow as j,whenEditorLayerView as P}from"./workflowUtils.js";import R from"./support/EditorItem.js";import{makeTemplateGroupInfoForLayer as H}from"../FeatureTemplates/featureTemplatesUtils.js";import G from"../FeatureTemplates/FeatureTemplatesViewModel.js";import x from"../Sketch/SketchViewModel.js";import D from"../Spinner/SpinnerViewModel.js";import{goTo as B}from"../support/goToUtils.js";function q(t,e){return t?.find((t=>t.layer===e))}let N=class extends s.EventedAccessor{constructor(t){super(t),this._templatesByLayer=new Map,this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new E({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updateTemplatesTask=null,this._updatingHandles=new W,this._featureTemplatesViewModelIsRestricted=!1,this.activeWorkflow=null,this._activityQueue=new r,this.editorItems=new r,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new U({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new G({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.layerInfos=null,this.ownSketchViewModel=new x({layer:this._sketchGraphicsLayer}),this.sketchOptions=new A,this.snappingOptions=new L({attributeRulesEnabled:!0}),this.spinnerViewModel=new D,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t&&"create-features"!==this.activeWorkflow?.type){if(t.submit(),!t.submittable||t.pendingSubtypeChoice)return;const e=t.getValues();if(t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0)return}await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([h((()=>{const t=this.view,e=t?.map?.editableLayers.toArray(),a=t?.allLayerViews,r=a?.filter((t=>!!e?.includes(t.layer)));return[e,r,this.layerInfos]}),(()=>this._updateEditorItems()),y),h((()=>this.hideTemplatesForInactiveLayers),(()=>this.syncFeatureTemplates())),f((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),f((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),f((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),w((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),g),f((()=>this.editorItems),"change",(()=>this._afterEditorItemsChange())),h((()=>[this.canCreate,this.canUpdateVisible]),(()=>this._afterEditorItemsChange())),h((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),y),w((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),f((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const r={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(r);this.startCreateFeaturesWorkflowAtFeatureCreation(r)})),h((()=>[this.view,this.featureTemplatesViewModel]),(([t,e])=>{e.view=t}),y),f((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),f((()=>this.sketchViewModel),["create","delete","update"],(t=>{const{activeWorkflow:e}=this,a="update"===e?.type,r=a?e.activeWorkflow?.layer:e?.layer,i=a?e?.activeWorkflow?.parentLayer:void 0,s=`sketch-${t.type}`;this.emit(s,{type:s,detail:t,layer:r,parentLayer:i})}),k),h((()=>this.view),(t=>{if(this._snappingManager=d(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new C({view:t,options:e}),this.ownSketchViewModel.snappingManager=this._snappingManager}),y),h((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),y)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=l(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=p(this._sketchEventListenerHandle)}get _featureTemplatesLayersAndTables(){const t=new r;for(const e of this.editorItems){const a=this.hideTemplatesForInactiveLayers&&!e.visible;e.supportsCreateFeaturesWorkflow&&!a&&t.push(e.layer)}return t}get activeLeafWorkflow(){const t=this.activeWorkflow;return t&&j(t)?t.activeWorkflow??t:t}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get canUpdateVisible(){return this.editorItems.some((t=>t.supportsUpdateWorkflow&&t.visible))}get featureTemplatesLayers(){return this._featureTemplatesLayersAndTables.filter((t=>"scene"===t.type||!t.isTable))}get featureFormViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeFeatureFormViewModel:"create-features"===t?.type?t.featureFormViewModel:null}get utilityNetworkAssociationAddAssociationViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeUtilityNetworkAssociationAddAssociationViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(t){this.sketchOptions.labels=t}get sketchViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeSketchViewModel:"create-features"===t?.type?t.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?.stepId?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}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(t){this.sketchOptions.tooltips=t}get valueOptions(){return this.sketchOptions.values}set valueOptions(t){this.sketchOptions.values=t}set view(t){this.ownSketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get canZoomTo(){const t=this.sketchViewModel,e=t?.createGraphic?.geometry?.type;return!(!t?.updateGraphics?.length&&"multipoint"!==e)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel?.associatedLayer)return"viewing-associated-features";if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel?.associationId)return"viewing-associated-layers";if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditorItem?.capabilities.update.attributes}get featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditorItem?.capabilities.delete.enabled}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}get snappingManager(){return this._snappingManager}getTemplatesForLayer(t){return this._templatesByLayer.get(t)??[]}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await m((()=>!this.updating)),!this.canCreate)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();try{await this._cancelWorkflow();const a=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",a),await a.start()}catch(r){this._logErrorAndCancelWorkflow(r)}finally{a.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(t){await m((()=>!this.updating));const e=this._createUpdatingResolver();try{const{initialFeature:e}=t,a=e.sourceLayer=e.layer,r=a?this.findEditorItemForLayer(a):void 0;if(!r?.supportsCreateFeaturesWorkflow)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const s=this._createCreateFeaturesWorkflow({initialFeature:e,layer:r.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",s),await s.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await m((()=>!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();this._set("activeWorkflow",t),await t.start()}catch(e){this._logErrorAndCancelWorkflow(e)}finally{t.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await m((()=>!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("awaiting-update-feature-candidate");e.data.candidates=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureEdit(t){if(await m((()=>!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("editing-existing-feature");e.data.rootFeature=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():this._logError("editing:unsupported-workflow","Deleting a feature requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveAssociation():this._logError("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){return this.editorItems.find((e=>e.layer===t))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelIsRestricted||this._updateTemplates()}zoomTo(t){const a=this.sketchViewModel,r=t?t.geometry:a?.updateGraphics.length?a?.updateGraphics.toArray().map((t=>t.geometry)).filter(e):a?.createGraphic?.geometry;r&&this.view&&B(this.view,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()))}restrictFeatureTemplatesViewModelToLayer(t){return this._featureTemplatesViewModelIsRestricted=!0,this._setFeatureTemplatesViewModelLayers([t]),o((()=>{this._featureTemplatesViewModelIsRestricted=!1,this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)}))}async _getEditorItemCandidates(t){const{view:e}=this;if(!e?.map)return[];const{map:a}=e,r=a.editableLayers.toArray(),i=a.allTables.toArray().filter((t=>I(t)||T(t)));return await Promise.allSettled([...r.flatMap((t=>this._getLayerLoadPromise(t))),...i.flatMap((t=>this._getLayerLoadPromise(t)))]),c(t),[...r.reverse(),...i.reverse()].filter((t=>M(t)&&("mesh"!==t.geometryType||"3d"===e.type))).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_getLayerLoadPromise(t){return T(t)?t.loadAll():t.load()}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}_updateEditorItems(){l(this._updateItemsTask);const{view:t}=this,e=a((async e=>{if(!t?.map||!t?.allLayerViews)return;const a=await this._getEditorItemCandidates(e);if(!a.length)return void this._drainEditorItems();const r=[],i=[],s=[],{layerInfos:o}=this;for(const l of a){const e=q(o,l),a=await P(t,l).catch((()=>null));(e?r:a?i:s).push(new R({layer:l,layerInfo:e,layerView:a}))}o?.length&&r.sort(((t,e)=>o.findIndex((({layer:e})=>e===t.layer))-o.findIndex((({layer:t})=>t===e.layer))));const n=[...r,...i,...s];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(e.promise),this._updateItemsTask=e}_updateTemplates(){l(this._updateTemplatesTask);const t=a((async t=>{const e=this._templatesByLayer,a=this._featureTemplatesLayersAndTables.filter((t=>!e.has(t)));if(a.length>0){const r=await F(a.toArray(),this.view,t);for(const{layer:t,templates:a}of r)e.set(t,a)}this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)}));this._updatingHandles.addPromise(t.promise),this._updateTemplatesTask=t}_setFeatureTemplatesViewModelLayers(t){const e=this._templatesByLayer,a=[];for(const r of t){const t=e.get(r);t&&t.length>0&&a.push(H(r,t))}this.featureTemplatesViewModel.templateInfos=a}_afterEditorItemsChange(){const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create-features"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===e&&!t.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&this._logError("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force){this.emit("workflow-cancel"),this._set("activeWorkflow",null);try{await e.cancel(t)}finally{e.destroy()}}else try{await e.cancel(t),this._set("activeWorkflow",null),e.destroy()}catch(a){}}_createCreateFeaturesWorkflow(t,e){return O.create({viewModel:this,creationInfo:t,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),applyEditsFeatureServiceCallback:(t,e,a)=>this._applyEditsFeatureService(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createUpdateWorkflow(t){return S.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),applyEditsFeatureServiceCallback:(t,e,a)=>this._applyEditsFeatureService(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let r=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new i("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,r))),r}async _applyEdits(t,e,a){let r=null;const i=t.url?await b(t.url):null,s={returnServiceEditsOption:(!i||!V(i))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const i=await P(a,t).catch((()=>null));return r=await t.applyEdits(e,s),i&&await m((()=>!i.updating)),r})),r}async _applyEditsFeatureService(t,e,a){let r=null;return await this._queueOperation((async()=>r=await t.applyEdits(e,a))),r}_queueOperation(t){this._activityQueue.push(t);const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>(Array.isArray(t)?t.forEach((t=>this._handleEditsResultError(t))):this._handleEditsResultError(t),t))).catch((a=>{this._logError("editing:operation-error","An error occurred.",{error:a});const r={error:a,retry:()=>(e(r,this.failures),this._queueOperation(t)),cancel:()=>{e(r,this.failures)}};this._set("failures",[...this.failures,r])})).then((()=>{e(t,this._activityQueue)}))}_handleEditsResultError(t){if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:r}=t,i=e.find((t=>!!t.error))||r.find((t=>!!t.error))||a.find((t=>!!t.error));if(i)throw i.error}}_createUpdatingResolver(){const t=u();return this._updatingHandles.addPromise(t.promise),t}_logErrorAndCancelWorkflow(t){const{name:e,message:a,details:r}=t;this._logError(e??"editing:workflow-start-failed",a??void 0,r??t),this._cancelWorkflow({force:!0})}_itemIsSuspended(t){const e=this.findEditorItemForLayer(t);return null!=e&&(!e.visible||e.disabled)}_logError(t,e,a){n.getLogger(this).error(new i(t,e,a))}};t([v()],N.prototype,"_featureTemplatesLayersAndTables",null),t([v()],N.prototype,"_snappingManager",void 0),t([v({readOnly:!0})],N.prototype,"activeWorkflow",void 0),t([v()],N.prototype,"activeLeafWorkflow",null),t([v({readOnly:!0})],N.prototype,"_activityQueue",void 0),t([v({readOnly:!0})],N.prototype,"canCreate",null),t([v()],N.prototype,"canCreateVisible",null),t([v({readOnly:!0})],N.prototype,"canUpdate",null),t([v()],N.prototype,"canUpdateVisible",null),t([v()],N.prototype,"featureTemplatesLayers",null),t([v()],N.prototype,"editorItems",void 0),t([v({readOnly:!0})],N.prototype,"failures",void 0),t([v()],N.prototype,"hideTemplatesForInactiveLayers",void 0),t([v({type:U})],N.prototype,"attachmentsViewModel",void 0),t([v()],N.prototype,"featureFormViewModel",null),t([v()],N.prototype,"utilityNetworkAssociationAddAssociationViewModel",null),t([v({type:G})],N.prototype,"featureTemplatesViewModel",void 0),t([v()],N.prototype,"labelOptions",null),t([v()],N.prototype,"layerInfos",void 0),t([v()],N.prototype,"ownSketchViewModel",void 0),t([v()],N.prototype,"sketchOptions",void 0),t([v()],N.prototype,"sketchViewModel",null),t([v({type:L,nonNullable:!0})],N.prototype,"snappingOptions",void 0),t([v()],N.prototype,"spinnerViewModel",void 0),t([v()],N.prototype,"state",null),t([v({readOnly:!0})],N.prototype,"syncing",null),t([v()],N.prototype,"updating",null),t([v()],N.prototype,"tooltipOptions",null),t([v()],N.prototype,"valueOptions",null),t([v()],N.prototype,"view",null),t([v()],N.prototype,"canZoomTo",null),t([v()],N.prototype,"pageStack",void 0),t([v()],N.prototype,"showDiscardEditsPrompt",void 0),t([v()],N.prototype,"_candidateCommitted",void 0),t([v()],N.prototype,"page",null),t([v()],N.prototype,"featureFormDisabled",null),t([v()],N.prototype,"featureFormHasAssociation",null),t([v()],N.prototype,"canGoBack",null),t([v()],N.prototype,"shouldShowDeleteButton",null),t([v()],N.prototype,"hasPendingEdits",null),t([v()],N.prototype,"snappingManager",null),N=t([_("esri.widgets.Editor.EditorViewModel")],N);const Q=N;export{Q as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{abortMaybe as r}from"../../core/maybe.js";import{createResolver as s,onAbort as n,createAbortError as l,throwIfAborted as d,debounce as c}from"../../core/promiseUtils.js";import p from"../../core/Queue.js";import{whenOnce as u,when as w,watch as h,sync as f}from"../../core/reactiveUtils.js";import{last as v}from"../../core/SetUtils.js";import{property as k}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as g}from"../../core/accessorSupport/decorators/subclass.js";import{isEditableLayer as m}from"../../layers/support/editableLayers.js";import{isFeatureLayer as y,isSubtypeSublayer as W,isSubtypeGroupLayer as b,isTable as A}from"../../layers/support/layerUtils.js";import{createFeatureServices as C}from"../../rest/featureService/utils.js";import _ from"../../views/draw/support/HighlightHelper.js";import{ViewEventPriorities as M}from"../../views/input/InputManager.js";import S from"../../views/interactive/sketch/SketchOptions.js";import{temporaryHighlightName as F}from"../../views/support/HighlightDefaults.js";import I from"./CreateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as E}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as j}from"./UpdateRecordWorkflow.js";import U from"./UpdateWorkflowData.js";import P from"./Workflow.js";import{createWorkflowSteps as V,fetchCandidates as L}from"./workflowUtils.js";import{findUtilityNetwork as x,isGraphicForRelatableFeatureSupportedLayer as T}from"../Feature/support/featureUtils.js";var H;const O="esri.widgets.Editor.UpdateWorkflow",R=()=>o.getLogger(O);let N=H=class extends P{constructor(e){super(e),this._workflowStack=new p(v),this._sketchStack=new p(v),this.data=void 0,this.type="update"}destroy(){this._drainWorkflowStack((e=>e.cancel({force:!0})))}get activeEditorItem(){return this.activeWorkflow?.data.editorItem??void 0}get activeFeatureFormViewModel(){return this.activeWorkflow?.featureFormViewModel}get activeUtilityNetworkAssociationAddAssociationViewModel(){return"add-association"===this.activeWorkflow?.type?this.activeWorkflow.utilityNetworkAssociationAddAssociationViewModel:null}get activeSketchViewModel(){return this._sketchStack.peek()?.viewModel}get canDeleteAssociation(){const{activeFeatureFormViewModel:e}=this;if(!this.activeWorkflow||!this.data.viewModel.view?.map||!e)return!1;const{activeAssociation:t,feature:a}=e;return!(!t||!a?.sourceLayer||!y(a?.sourceLayer)&&!W(a?.sourceLayer))}get activeWorkflow(){return this._workflowStack.last()}get updating(){return this._updatingHandles.updating||!!this.activeWorkflow?.updating}get hasPreviousStep(){const e=this.activeWorkflow?.featureFormViewModel;return this._stepIndex>0||this.nestedWorkflowCount>1||null!=e?.relationshipId||"view"!==this.data.viewModel.attachmentsViewModel.mode||null!=e?.associationId||null!=e?.associatedLayer}get hasUpdatableCandidates(){const{candidates:e,viewModel:t}=this.data;return e.some((({layer:e})=>t.findEditorItemForLayer(e)?.supportsUpdateWorkflow))}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return!!this.activeEditorItem?.capabilities.attachments.enabled}get shouldAllowAttachmentEditing(){return!!this.activeEditorItem?.capabilities.update.attachments.enabled}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 reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return!!this.activeEditorItem?.hasInvalidFormTemplate}async back(e=()=>Promise.resolve(!0)){const{activeWorkflow:t}=this,a=t?.featureFormViewModel;if(a?.activeRelationshipInput){const e=a.activeRelationshipInput;if(e.activeCategory)return void(e.activeCategory=null);if(null!=a.relationshipId)return void(a.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==a?.associatedLayer)if(null==a?.associationId)if("create-features"===t?.type&&t.hasPreviousStep)await t.previous({cancelCurrentStep:!0});else 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});else a.associationId=null;else a.associatedLayer=null}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflow()}async commit(){await this._drainWorkflowStack((e=>e.commit())),await super.commit()}static create(e){const{viewModel:t,snappingManager:a,startAt:i,addAttachmentsCallback:o,applyEditsCallback:r,applyEditsFeatureServiceCallback:s}=e,n=e.sketchOptions??new S,l=new H({data:new U({addAttachmentsCallback:o,applyEditsCallback:r,applyEditsFeatureServiceCallback:s,sketchOptions:n,snappingManager:a,viewModel:t}),onCommit:async()=>{}});return l._set("steps",this._createWorkflowSteps(l,i)),l}async save(){this.nestedWorkflowCount>1?(await(this.activeWorkflow?.commit()),await this._popWorkflow()):await this.commit()}async startCreatingRelatedRecord(e){try{const t=await this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:t})}}async startUpdating(e,t){try{const a=await this._createNestedUpdateWorkflow(e,t);await this._pushWorkflow(a)}catch(i){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:i})}}async startAddAssociation(e,t,i){try{const a=await this._createNestedAddAssociationWorkflow(e,t,i);await this._pushWorkflow(a)}catch(o){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:o})}}async deleteActiveFeature(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");G(e)?await e.deleteAndCommit():await e.cancel(),1===this.nestedWorkflowCount?await this.reset():(await this._popWorkflow(),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._popWorkflow(),await this._returnToPageWithContent()}async cancelAll(){await this._drainWorkflowStack((e=>e.cancel({force:!0})))}async _deleteActiveAssociation(){const{activeFeatureFormViewModel:e,data:t}=this,{activeAssociation:i,feature:o}=e,{applyEditsFeatureServiceCallback:r,viewModel:s}=t,{sourceLayer:n}=o,l=W(n)&&n.parent?n.parent:n,d=C([l]),c=d.values().next().value?.featureService;if(!c)throw new a("editor:failed-to-delete-association","Could not retrieve feature service needed to delete association");await(c?.load());const p=s.view.map,u=x(p,l);await(u?.networkSystemLayers.loadAssociationsTable());const w=u?.generateDeleteAssociations([i]);if(!w)throw new a("editor:failed-to-delete-association","Could not create payload needed to delete association");const h=u?.gdbVersion??void 0;await r(c,[w],{gdbVersion:h,globalIdUsed:!0})}async _returnToPageWithContent(){const{activeFeatureFormViewModel:e}=this;if(!e?.activeAssociationInput)return;const{activeAssociationInput:t,associationId:a}=e;await t.refresh(),t.associatedLayer&&!t.associatedFeatures?.length&&(e.associatedLayer=null),null==a||t.associatedFeatureInfos.size||(e.associationId=null)}async _createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:i,applyEditsCallback:o,applyEditsFeatureServiceCallback:r,sketchOptions:s,snappingManager:n,viewModel:l}=this.data;if(!m(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="create-features"!==this.activeWorkflow?.type&&"add-association"!==this.activeWorkflow?.type?this.activeWorkflow:void 0;return I.create({addAttachmentsCallback:i,applyEditsCallback:o,applyEditsFeatureServiceCallback:r,creationInfo:d,isNested:!0,parent:p,sketchOptions:s,snappingManager:n,startAt:c,viewModel:l})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:i}=e;if(!m(i)||b(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 a=A(e.sourceLayer)?j:E,{applyEditsCallback:i,applyEditsFeatureServiceCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data,l="create-features"!==this.activeWorkflow?.type&&"add-association"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,d=await a.create({association:t,feature:e,parent:l,sketchOptions:r,snappingManager:s,viewModel:n,applyEdits:i,applyEditsFeatureService:o,featureFormCallbacks:{addRelatedRecord:async e=>await this._updatingHandles.addPromise(this.startCreatingRelatedRecord(e)),editRelatedRecord:async({relatedFeature:e})=>await this._updatingHandles.addPromise(this.startUpdating(e)),selectAssociatedFeature:async({feature:e,association:t})=>await this._updatingHandles.addPromise(this.startUpdating(e,t)),addAssociation:async e=>await this._updatingHandles.addPromise(this.startAddAssociation(e.feature,e.utilityNetwork,e.associationType))}});return await u((()=>!d.updating)),d}async _createNestedAddAssociationWorkflow(e,t,a){const{AddAssociationWorkflow:i}=await import("./AddAssociationWorkflow.js"),{applyEditsCallback:o,applyEditsFeatureServiceCallback:r,viewModel:s}=this.data,n="create-features"!==this.activeWorkflow?.type&&"add-association"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,l=this.activeFeatureFormViewModel?.activeAssociationInput,d=await i.create({utilityNetwork:t,associationType:a,feature:e,parent:n,viewModel:s,associationInput:l,applyEdits:o,applyEditsFeatureService:r});return await u((()=>!d.updating)),d}async _drainWorkflowStack(e){const t=this._workflowStack,a=[];for(;t.length>0;){const i=t.pop();this._sketchStack.pop();const o=e(i).then((()=>i.destroy()));this._updatingHandles.addPromise(o),a.push(o)}await Promise.all(a)}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:a,relationshipId:i}=e;if(!T(t))return;const o=a.relationships?.find((e=>e.id===i));if(!o)return void q("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 q("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&&q("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===i));if(!s)return void q("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=D(r,s),l=t.getAttribute(n);l||q("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field.");const d=D(a,o);return{[d]:l}}async _popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop();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 _pushWorkflow(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 a=e.peek();return await(a?.enter()),await(t.peek()?.enter()),{activeWorkflow:a,failureCount:0}}catch(a){e.pop().destroy(),t.pop();const{activeWorkflow:i,failureCount:o}=await this._reconcileWorkflowStack();return{activeWorkflow:i,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&&!A(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:o}=e;return V(["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}=o.viewModel,a=o.viewModel.view;a.activeTool=null;let c=null;e.addHandles(i((()=>{c=r(c)})),this.id),o.rootFeature=null,o.candidates=[];const p=a.on("immediate-click",(async i=>{const r=s();e._updatingHandles.addPromise(r.promise);try{t.location=i.mapPoint,t.visible=!0,c?.abort();const{editorItems:r}=o.viewModel;c=new AbortController;const s=await i.async((()=>new Promise(((e,t)=>{n(c?.signal,(()=>t(l()))),e(L(r,a,i,c?.signal))}))));if(d(c),o.candidates=s.filter((e=>"fulfilled"===e.status)).flatMap((e=>e.value)).filter((e=>!e.isAggregate)),t.visible=1===o.candidates.length,0===o.candidates.length)return;i.stopPropagation(),1===o.candidates.length?(o.rootFeature=o.candidates[0],e.go("editing-existing-feature").catch((()=>{})).then((()=>t.visible=!1))):e.next()}finally{r.resolve()}}),M.TOOL),u=w((()=>null!=a.activeTool),(()=>e.cancel({force:!0})),{once:!0});a.focus(),e.addHandles([p,u],this.id)},async tearDown(){0===o.candidates.length&&(o.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){o.rootFeature=null;const{view:t}=o.viewModel;if(!t)return;const a=new _({view:t,highlightName:F});e.addHandles([h((()=>o.rootFeature),((e,t)=>{a.remove(t),a.add(e)}),f),i((()=>a.removeAll()))],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){const{rootFeature:t,viewModel:i}=e.data;if(!t)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until the root feature is defined");await e.startUpdating(t),i.spinnerViewModel.visible=!1;const o=c((async()=>{await u((()=>!e.updating)),e.previous()}));e.addHandles([h((()=>e.nestedWorkflowCount),((e,t)=>{0===e&&0!==t&&o()}),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(){o.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}})})}};function D(e,{keyField:t}){return e.getField(t)?.name??t}e([k()],N.prototype,"activeEditorItem",null),e([k()],N.prototype,"activeFeatureFormViewModel",null),e([k()],N.prototype,"activeUtilityNetworkAssociationAddAssociationViewModel",null),e([k()],N.prototype,"activeSketchViewModel",null),e([k()],N.prototype,"canDeleteAssociation",null),e([k()],N.prototype,"activeWorkflow",null),e([k()],N.prototype,"updating",null),e([k()],N.prototype,"data",void 0),e([k()],N.prototype,"hasPreviousStep",null),e([k()],N.prototype,"hasUpdatableCandidates",null),e([k()],N.prototype,"nestedWorkflowCount",null),e([k()],N.prototype,"shouldShowAttachments",null),e([k()],N.prototype,"shouldAllowAttachmentEditing",null),e([k()],N.prototype,"hasPendingEdits",null),e([k()],N.prototype,"helpMessage",null),e([k()],N.prototype,"reliesOnOwnerAdminPrivileges",null),e([k()],N.prototype,"hasInvalidFormTemplate",null),N=H=e([g(O)],N);const q=(e,t)=>R().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."),G=e=>!!e&&/update-/.test(e.type),z=N;export{z as default};
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{abortMaybe as r}from"../../core/maybe.js";import{createResolver as s,onAbort as n,createAbortError as l,throwIfAborted as d,debounce as c}from"../../core/promiseUtils.js";import p from"../../core/Queue.js";import{whenOnce as u,when as h,watch as w,sync as f}from"../../core/reactiveUtils.js";import{last as g}from"../../core/SetUtils.js";import{property as v}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as k}from"../../core/accessorSupport/decorators/subclass.js";import{isEditableLayer as m}from"../../layers/support/editableLayers.js";import{isFeatureLayer as y,isSubtypeSublayer as W,isSubtypeGroupLayer as b,isTable as A}from"../../layers/support/layerUtils.js";import{createFeatureServices as C}from"../../rest/featureService/utils.js";import _ from"../../views/draw/support/HighlightHelper.js";import{ViewEventPriorities as M}from"../../views/input/InputManager.js";import S from"../../views/interactive/sketch/SketchOptions.js";import{temporaryHighlightName as F}from"../../views/support/HighlightDefaults.js";import I from"./CreateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as E}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as j}from"./UpdateRecordWorkflow.js";import U from"./UpdateWorkflowData.js";import P from"./Workflow.js";import{createWorkflowSteps as V,fetchCandidates as R}from"./workflowUtils.js";import{findUtilityNetwork as L,isGraphicForRelatableFeatureSupportedLayer as x}from"../Feature/support/featureUtils.js";var T;let H=T=class extends P{constructor(e){super(e),this._workflowStack=new p(g),this._sketchStack=new p(g),this.data=void 0,this.type="update"}destroy(){this._drainWorkflowStack((e=>e.cancel({force:!0})))}get activeEditorItem(){return this.activeWorkflow?.data.editorItem??void 0}get activeFeatureFormViewModel(){return this.activeWorkflow?.featureFormViewModel}get activeUtilityNetworkAssociationAddAssociationViewModel(){return"add-association"===this.activeWorkflow?.type?this.activeWorkflow.utilityNetworkAssociationAddAssociationViewModel:null}get activeSketchViewModel(){return this._sketchStack.peek()?.viewModel}get canDeleteAssociation(){const{activeFeatureFormViewModel:e}=this;if(!this.activeWorkflow||!this.data.viewModel.view?.map||!e)return!1;const{activeAssociation:t,feature:a}=e;return!(!t||!a?.sourceLayer||!y(a?.sourceLayer)&&!W(a?.sourceLayer))}get activeWorkflow(){return this._workflowStack.last()}get updating(){return this._updatingHandles.updating||!!this.activeWorkflow?.updating}get hasPreviousStep(){const e=this.activeWorkflow?.featureFormViewModel;return this._stepIndex>0||this.nestedWorkflowCount>1||null!=e?.relationshipId||"view"!==this.data.viewModel.attachmentsViewModel.mode||null!=e?.associationId||null!=e?.associatedLayer}get hasUpdatableCandidates(){const{candidates:e,viewModel:t}=this.data;return e.some((({layer:e})=>t.findEditorItemForLayer(e)?.supportsUpdateWorkflow))}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return!!this.activeEditorItem?.capabilities.attachments.enabled}get shouldAllowAttachmentEditing(){return!!this.activeEditorItem?.capabilities.update.attachments.enabled}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 reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return!!this.activeEditorItem?.hasInvalidFormTemplate}async back(e=()=>Promise.resolve(!0)){const{activeWorkflow:t}=this,a=t?.featureFormViewModel;if(a?.activeRelationshipInput){const e=a.activeRelationshipInput;if(e.activeCategory)return void(e.activeCategory=null);if(null!=a.relationshipId)return void(a.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==a?.associatedLayer)if(null==a?.associationId)if("create-features"===t?.type&&t.hasPreviousStep)await t.previous({cancelCurrentStep:!0});else 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});else a.associationId=null;else a.associatedLayer=null}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflow()}async commit(){await this._drainWorkflowStack((e=>e.commit())),await super.commit()}static create(e){const{viewModel:t,snappingManager:a,startAt:i,addAttachmentsCallback:o,applyEditsCallback:r,applyEditsFeatureServiceCallback:s}=e,n=e.sketchOptions??new S,l=new T({data:new U({addAttachmentsCallback:o,applyEditsCallback:r,applyEditsFeatureServiceCallback:s,sketchOptions:n,snappingManager:a,viewModel:t}),onCommit:async()=>{}});return l._set("steps",this._createWorkflowSteps(l,i)),l}async save(){this.nestedWorkflowCount>1?(await(this.activeWorkflow?.commit()),await this._popWorkflow()):await this.commit()}async startCreatingRelatedRecord(e){try{const t=await this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:t})}}async startUpdating(e,t){try{const a=await this._createNestedUpdateWorkflow(e,t);await this._pushWorkflow(a)}catch(i){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:i})}}async startAddAssociation(e,t,i){try{const a=await this._createNestedAddAssociationWorkflow(e,t,i);await this._pushWorkflow(a)}catch(o){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:o})}}async deleteActiveFeature(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");N(e)?await e.deleteAndCommit():await e.cancel(),1===this.nestedWorkflowCount?await this.reset():(await this._popWorkflow(),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._popWorkflow(),await this._returnToPageWithContent()}async cancelAll(){await this._drainWorkflowStack((e=>e.cancel({force:!0})))}async _deleteActiveAssociation(){const{activeFeatureFormViewModel:e,data:t}=this,{activeAssociation:i,feature:o}=e,{applyEditsFeatureServiceCallback:r,viewModel:s}=t,{sourceLayer:n}=o,l=W(n)&&n.parent?n.parent:n,d=C([l]),c=d.values().next().value?.featureService;if(!c)throw new a("editor:failed-to-delete-association","Could not retrieve feature service needed to delete association");await(c?.load());const p=s.view.map,u=L(p,l);await(u?.networkSystemLayers.loadAssociationsTable());const h=u?.generateDeleteAssociations([i]);if(!h)throw new a("editor:failed-to-delete-association","Could not create payload needed to delete association");const w=u?.gdbVersion??void 0;await r(c,[h],{gdbVersion:w,globalIdUsed:!0})}async _returnToPageWithContent(){const{activeFeatureFormViewModel:e}=this;if(!e?.activeAssociationInput)return;const{activeAssociationInput:t,associationId:a}=e;await t.refresh(),t.associatedLayer&&!t.associatedFeatures?.length&&(e.associatedLayer=null),null==a||t.associatedFeatureInfos.size||(e.associationId=null)}async _createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:i,applyEditsCallback:o,applyEditsFeatureServiceCallback:r,sketchOptions:s,snappingManager:n,viewModel:l}=this.data;if(!m(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="create-features"!==this.activeWorkflow?.type&&"add-association"!==this.activeWorkflow?.type?this.activeWorkflow:void 0;return I.create({addAttachmentsCallback:i,applyEditsCallback:o,applyEditsFeatureServiceCallback:r,creationInfo:d,isNested:!0,parent:p,sketchOptions:s,snappingManager:n,startAt:c,viewModel:l})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:i}=e;if(!m(i)||b(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 a=A(e.sourceLayer)?j:E,{applyEditsCallback:i,applyEditsFeatureServiceCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data,l="create-features"!==this.activeWorkflow?.type&&"add-association"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,d=await a.create({association:t,feature:e,parent:l,sketchOptions:r,snappingManager:s,viewModel:n,applyEdits:i,applyEditsFeatureService:o,featureFormCallbacks:{addRelatedRecord:async e=>await this._updatingHandles.addPromise(this.startCreatingRelatedRecord(e)),editRelatedRecord:async({relatedFeature:e})=>await this._updatingHandles.addPromise(this.startUpdating(e)),selectAssociatedFeature:async({feature:e,association:t})=>await this._updatingHandles.addPromise(this.startUpdating(e,t)),addAssociation:async e=>await this._updatingHandles.addPromise(this.startAddAssociation(e.feature,e.utilityNetwork,e.associationType))}});return await u((()=>!d.updating)),d}async _createNestedAddAssociationWorkflow(e,t,a){const{AddAssociationWorkflow:i}=await import("./AddAssociationWorkflow.js"),{applyEditsCallback:o,applyEditsFeatureServiceCallback:r,viewModel:s}=this.data,n="create-features"!==this.activeWorkflow?.type&&"add-association"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,l=this.activeFeatureFormViewModel?.activeAssociationInput,d=await i.create({utilityNetwork:t,associationType:a,feature:e,parent:n,viewModel:s,associationInput:l,applyEdits:o,applyEditsFeatureService:r});return await u((()=>!d.updating)),d}async _drainWorkflowStack(e){const t=this._workflowStack,a=[];for(;t.length>0;){const i=t.pop();this._sketchStack.pop();const o=e(i).then((()=>i.destroy()));this._updatingHandles.addPromise(o),a.push(o)}await Promise.all(a)}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:a,relationshipId:i}=e;if(!x(t))return;const o=a.relationships?.find((e=>e.id===i));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===i));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=O(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=O(a,o);return{[d]:l}}async _popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop();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 _pushWorkflow(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 a=e.peek();return await(a?.enter()),await(t.peek()?.enter()),{activeWorkflow:a,failureCount:0}}catch(a){e.pop().destroy(),t.pop();const{activeWorkflow:i,failureCount:o}=await this._reconcileWorkflowStack();return{activeWorkflow:i,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&&!A(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:o}=e;return V(["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}=o.viewModel,a=o.viewModel.view;a.activeTool=null;let c=null;e.addHandles(i((()=>{c=r(c)})),this.id),o.rootFeature=null,o.candidates=[];const p=a.on("immediate-click",(async i=>{const r=s();e._updatingHandles.addPromise(r.promise);try{t.location=i.mapPoint,t.visible=!0,c?.abort();const{editorItems:r}=o.viewModel;c=new AbortController;const s=await i.async((()=>new Promise(((e,t)=>{n(c?.signal,(()=>t(l()))),e(R(r,a,i,c?.signal))}))));if(d(c),o.candidates=s.filter((e=>"fulfilled"===e.status)).flatMap((e=>e.value)).filter((e=>!e.isAggregate)),t.visible=1===o.candidates.length,0===o.candidates.length)return;i.stopPropagation(),1===o.candidates.length?(o.rootFeature=o.candidates[0],e.go("editing-existing-feature").catch((()=>{})).then((()=>t.visible=!1))):e.next()}finally{r.resolve()}}),M.TOOL),u=h((()=>null!=a.activeTool),(()=>e.cancel({force:!0})),{once:!0});a.focus(),e.addHandles([p,u],this.id)},async tearDown(){0===o.candidates.length&&(o.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){o.rootFeature=null;const{view:t}=o.viewModel;if(!t)return;const a=new _({view:t,highlightName:F});e.addHandles([w((()=>o.rootFeature),((e,t)=>{a.remove(t),a.add(e)}),f),i((()=>a.removeAll()))],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){const{rootFeature:t,viewModel:i}=e.data;if(!t)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until the root feature is defined");await e.startUpdating(t),i.spinnerViewModel.visible=!1;const o=c((async()=>{await u((()=>!e.updating)),e.previous()}));e.addHandles([w((()=>e.nestedWorkflowCount),((e,t)=>{0===e&&0!==t&&o()}),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(){o.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}})})}_logContinuingWithoutRelationshipWarning(e,t){o.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 O(e,{keyField:t}){return e.getField(t)?.name??t}e([v()],H.prototype,"activeEditorItem",null),e([v()],H.prototype,"activeFeatureFormViewModel",null),e([v()],H.prototype,"activeUtilityNetworkAssociationAddAssociationViewModel",null),e([v()],H.prototype,"activeSketchViewModel",null),e([v()],H.prototype,"canDeleteAssociation",null),e([v()],H.prototype,"activeWorkflow",null),e([v()],H.prototype,"updating",null),e([v()],H.prototype,"data",void 0),e([v()],H.prototype,"hasPreviousStep",null),e([v()],H.prototype,"hasUpdatableCandidates",null),e([v()],H.prototype,"nestedWorkflowCount",null),e([v()],H.prototype,"shouldShowAttachments",null),e([v()],H.prototype,"shouldAllowAttachmentEditing",null),e([v()],H.prototype,"hasPendingEdits",null),e([v()],H.prototype,"helpMessage",null),e([v()],H.prototype,"reliesOnOwnerAdminPrivileges",null),e([v()],H.prototype,"hasInvalidFormTemplate",null),H=T=e([k("esri.widgets.Editor.UpdateWorkflow")],H);const N=e=>!!e&&/update-/.test(e.type),D=H;export{D as default};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{isSome as i}from"../../../core/arrayUtils.js";import s from"../../../core/Error.js";import{abortHandle as o}from"../../../core/handleUtils.js";import{debounce as r}from"../../../core/promiseUtils.js";import{whenOnce as a,watch as n}from"../../../core/reactiveUtils.js";import{first as l}from"../../../core/SetUtils.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import{subclass as p}from"../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as h}from"../../../core/support/UpdatingHandles.js";import d from"../../../layers/GraphicsLayer.js";import u from"../../../views/interactive/sketch/SketchOptions.js";import{getVisualVariablesForLayer as y,updateGraphicSymbolWhenRequired as m,setVisualVariablesAndElevationInfoForUpdate as w,swapForEditingSession as v,getRotationVariableAttribute as f,getSizeVariableAttribute as g,visualVariableInteractiveUpdate as b}from"../workflowUtils.js";import k from"../../Sketch/SketchViewModel.js";const _=Symbol();let S=class extends t{constructor(e){super(e),this.features=[],this.onSketchUpdate=()=>{},this.sketchOptions=new u,this.snappingManager=null,this.sourceLayer=null,this.view=null,this.viewModel=null,this._sketchGraphics=new Map,this._sketchLayer=null,this._updatingHandles=new h,this._visualVariableAttributes=new Map,this._visualVariablesForLayer=null,this._webStyleCache=new Map}async initialize(){this._visualVariablesForLayer=y(this.sourceLayer),this._initializeSketchGraphics(),this._initializeSketchLayer(),await this._updatingHandles.addPromise(this._initializeSketchViewModel())}destroy(){const{_sketchLayer:e,view:t}=this;t?.destroyed||t?.map.remove(e),e.destroy(),this.viewModel.destroy()}get updating(){return this._updatingHandles.updating}async enter(){throw new Error("enter() not implemented")}async exit(){throw new Error("exit() not implemented")}notifyAttributesChanged({features:e,fieldName:t}){const i=this._webStyleCache,s=this.view.scale;for(const o of e){const e=this._sketchGraphics.get(o),r=o.getAttribute(t);if(!e||e.getAttribute(t)===r)continue;e.setAttribute(t,r);const a=this._visualVariableAttributes.get(o);null==a?.size||a.size.isUpdatingInteractively||a.size.field!==t||a.size.setInitialValue(r),null==a?.rotation||a.rotation.isUpdatingInteractively||a.rotation.field!==t||a.rotation.setInitialValue(r),m(e,i,s)}}async startUpdatingFeatures(e,t,s){const{_sketchGraphics:r,sourceLayer:n,view:l,viewModel:c,_webStyleCache:p}=this,h=e.map((e=>r.get(e))).filter(i),d={multipleSelectionEnabled:!1};this.removeHandles(_),c.complete();let u=null;if(1===e.length){const t=e[0],i=this._visualVariableAttributes.get(t);!(!i?.rotation&&!i?.size)&&(w({sketchViewModel:c,graphic:h[0],sourceLayer:n,visualVariables:i,webStyleCache:p}),"point"===n.geometryType&&(d.enableRotation=null!=i.rotation,d.enableScaling=null!=i.size,u=async e=>{const o=e.graphics[0];b(l,o,e,i)&&(s?.(t,o.attributes,e),await m(o,p,"2d"===l.type?l.scale:null))}))}const y=()=>c.update(h,d);await y();const v=c.on("update",(i=>{if("complete"===i.state){if(null===l.activeTool)return void y();const e=new AbortController,t=o(e);return this.addHandles(t,_),void this._updatingHandles.addPromise(a((()=>null===l.activeTool),e.signal).then((async()=>{e.signal.aborted||(e.abort(),await y())})))}for(const s of e){const e=r.get(s);e&&t?.(s,e.geometry,i)}u?.(i)}));this.addHandles(v,_),c.addHandles(v)}_initializeSketchGraphics(){const{features:e,_sketchGraphics:t,sourceLayer:i,_visualVariableAttributes:s}=this,o=this._visualVariablesForLayer,r=o.rotation?.field,a=o.size?.field,n={rotation:r?i.getField(r):null,size:a?i.getField(a):null},l=!(!n.rotation&&!n.size);for(const c of e)t.set(c,c.clone()),l&&s.set(c,z(o,n))}_initializeSketchLayer(){const e=new d({elevationInfo:this.sourceLayer.elevationInfo,internal:!0,listMode:"hide"});this._sketchLayer=e,this.view.map.add(e)}async _initializeSketchViewModel(){const{_sketchGraphics:e,view:t,_webStyleCache:i}=this,s=Array.from(e.entries()),o=new k({allowDeleteKey:!1,layer:this._sketchLayer,sketchOptions:this.sketchOptions,snappingManager:this.snappingManager,updateOnGraphicClick:!1,view:this.view});this.viewModel=o;const a=r((e=>Promise.all(s.map((([,t])=>m(t,i,e))))));await a("2d"===t.type?t.scale:null),"2d"===t.type&&this.addHandles(n((()=>t.scale),(e=>a(e)))),this.addHandles(await Promise.all(s.map((([e,t])=>v(o,e,t)))))}};function L({features:e,sketchOptions:t,snappingManager:i,view:o}){const r=new Set(e.map((e=>e.sourceLayer)));if(1!==r.size)throw new s("editor:features-must-belong-to-same-layer","All features must belong to the same layer.");const a=l(r);return new S({view:o,features:e,sketchOptions:t,snappingManager:i,sourceLayer:a})}function z({rotation:e,size:t},i){return{rotation:e?f(e,i.rotation):null,size:t?g(t,i.size):null}}e([c()],S.prototype,"features",void 0),e([c()],S.prototype,"onSketchUpdate",void 0),e([c()],S.prototype,"sketchOptions",void 0),e([c()],S.prototype,"snappingManager",void 0),e([c()],S.prototype,"sourceLayer",void 0),e([c()],S.prototype,"updating",null),e([c()],S.prototype,"view",void 0),e([c()],S.prototype,"viewModel",void 0),e([c()],S.prototype,"_sketchGraphics",void 0),e([c()],S.prototype,"_sketchLayer",void 0),e([c()],S.prototype,"_visualVariablesForLayer",void 0),S=e([p("esri.widgets.Editor.support.SketchController")],S);export{S as SketchController,L as createSketchController};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../Color.js";import t from"../../Graphic.js";import{isSome as r,addMany as a,equals as o}from"../../core/arrayUtils.js";import{createTask as n}from"../../core/asyncUtils.js";import"../../core/has.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{whenOrAbort as f,throwIfAborted as y,debounce as m,isPromiseLike as h}from"../../core/promiseUtils.js";import{watch as g,on as b,whenOnce as w}from"../../core/reactiveUtils.js";import{px2pt as v}from"../../core/screenUtils.js";import{diff as I}from"../../core/accessorSupport/diffUtils.js";import{isSharedTemplateOrMetadata as T,isSharedGroupTemplate as S,isSharedPresetTemplate as j,isStandardFeatureTemplate as F,isSharedFeatureTemplate as k,isSharedTemplate as A}from"../../editing/templateUtils.js";import{getSharedTemplateProvider as V}from"../../editing/sharedTemplates/SharedTemplateProvider.js";import U from"../../layers/GraphicsLayer.js";import{featureHasFields as L,fixFields as M,getDisplayFieldName as O}from"../../layers/support/fieldUtils.js";import{isSubtypeSublayer as x}from"../../layers/support/layerUtils.js";import{calculateTolerance as q}from"../../renderers/support/clickToleranceUtils.js";import{meterIn as P}from"../../renderers/support/lengthUtils.js";import{getTransformationType as z,TransformationType as E}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import C from"../../symbols/SimpleFillSymbol.js";import R from"../../symbols/SimpleLineSymbol.js";import D from"../../symbols/SimpleMarkerSymbol.js";import{to3D as G}from"../../symbols/support/symbolConversion.js";import{getDisplayedSymbol as B}from"../../symbols/support/symbolUtils.js";import{getServices as N}from"../../undoredo/support/Services.js";import{GraphicState as Z}from"../../views/3d/layers/graphics/GraphicState.js";import{defaultDrawingMode as Q}from"../../views/draw/DrawingMode.js";import{createQueryGeometry as W}from"../../views/support/drapedUtils.js";import{hitTestSelectSimilarDistance as $,filterGraphicHits as J}from"../../views/support/hitTestSelectUtils.js";import{dependencySort as H}from"./support/dependencySort.js";import{isDrawGraphicTool as K}from"../Sketch/support/sketchUtils.js";const X=()=>p.getLogger("esri.widgets.Editor.workflowUtils");function Y(e){return"update"===e.type}function _(e){const t=e.sourceLayer;if(!t||"feature"!==t.type||!ne(t.renderer))return{rotation:null,size:null};let r=null,a=null;const o=t.renderer.getVisualVariablesForType("rotation").filter((e=>(!e.axis||"heading"===e.axis)&&e.field&&!e.valueExpression));1===o.length&&(r=ee(o[0],t));const n=t.renderer.getVisualVariablesForType("size").filter((e=>e.field&&!e.useSymbolValue&&!e.valueExpression&&z(e)===E.RealWorldSize));return 1===n.length&&(a=ae(n[0],t)),{rotation:r,size:a}}function ee(e,t){const r="heading"===(e.axis||"heading")&&"arithmetic"===e.rotationType?-1:1,a=e.field,o=t.fields&&t.fields.filter((e=>e.name===a)),n=o&&1===o.length?o[0].type:"double",i={initial:0,current:0};return{field:a,fieldType:n,getDefaultValue:()=>Promise.resolve(0),getValue:e=>(i.current=i.initial-r*e,oe((i.current+360)%360,n)),setInitialValue:e=>{i.initial=e,i.current=0},isUpdatingInteractively:!1,rotationType:e.rotationType??"geographic"}}function te(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 re(e,t,r){if(null==t)return 0;const{symbol:a}=G(t);if(null==a||"web-style"===a.type||"cim"===a.type)return 0;const o=a.symbolLayers.at(0);if(!o)return 0;switch(o.type){case"icon":{const{computeIconLayerResourceSize:e}=await import("../../symbols/support/symbolLayerUtils.js");return Math.min(Qe.icon,(await e(o,Qe.icon))[0])||Qe.icon}case"text":return Qe.text;case"line":return Qe.line;case"object":{const{computeObjectLayerResourceSize:t}=await import("../../symbols/support/symbolLayerUtils.js");return te(await t(o,e.scale/Qe.viewScaleSizeFactor),r)}case"path":case"extrude":return e.scale/Qe.viewScaleSizeFactor;default:return 0}}function ae(e,t){const r=e.field,a=e.axis,o=t.fields&&t.fields.filter((e=>e.name===r)),n=o&&1===o.length?o[0].type:"double",i={initial:0,current:0},s=P[e.valueUnit]??1;let l;return l="area"===e.valueRepresentation?e=>(e*s/2)**2*Math.PI:"radius"===e.valueRepresentation||"distance"===e.valueRepresentation?e=>e*s/2:e=>e*s,{field:r,fieldType:n,getDefaultValue:async(e,t)=>oe(l(await re(t,e,a)),n),getValue:(e,t)=>(i.initial||(i.initial=t.pixelSizeAt(t.center)),i.current=i.initial*e,oe(i.current,n)),setInitialValue:e=>{i.initial=e,i.current=0},isUpdatingInteractively:!1,displayUnit:Je(e.valueUnit),axis:e.axis}}function oe(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 ne(e){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 ie(e,t,r){const a=await B(e,{useSourceLayer:!0,ignoreGraphicSymbol:!0,webStyleCache:t,scale:r});null!=I(e.symbol,a)&&(e.symbol=a)}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 a={mode:Q,optionsPerTool:r};if(T(t)){const o=t.defaultTool,n=S(t)?t.definition?.inputGeometryType??e:e;switch(o){case"freehand":case"stream-line":return{tool:"polyline"===n?"freehandPolyline":"freehandPolygon",createOptions:a};case"autocomplete-freehand-polygons":case"stream-polygon":return{tool:"freehandPolygon",createOptions:a};case"autocomplete-polygons":case"difference-polygon":case"create-structures":case"polygon":case"trace":return{tool:"polygon"===n?"polygon":"polyline",createOptions:a};case"circle":return r.get("circle").preserveAspectRatio=!0,{tool:"circle",createOptions:a};case"ellipse":return r.get("circle").preserveAspectRatio=!1,{tool:"circle",createOptions:a};case"create-points-along-line":case"multipoint":return{tool:"multipoint",createOptions:a};case"line":case"radial-line":case"right-angle-line":case"split":case"two-point-line":return{tool:"polyline",createOptions:a};case"rectangle":case"regular-polygon":case"right-angle-polygon":return{tool:"rectangle",createOptions:a};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:a}}}else{const o=t.drawingTool;if("circle"===o||"ellipse"===o)return r.get("circle").preserveAspectRatio="circle"===o,{tool:"circle",createOptions:a};if("rectangle"===o)return{tool:"rectangle",createOptions:a};if("freehand"===o)return{tool:"polygon"===e?"freehandPolygon":"freehandPolyline",createOptions:a}}return{tool:e,createOptions:a}}async function le(e,t,r){const{creationInfo:a,fullTemplate:o}=t;if(!a)throw new i("featureworkflow","No creation info provided.");const n=a.layer,s=ke(o,a.attributeOverrides),{view:l}=e,c="2d"===l?.type;S(o)||j(o)||await Ae(e,n,s,r,c?l.scale:null);const{capabilities:u}=n;e.layer.elevationInfo=n.elevationInfo;const p=se(n.geometryType,o);e.defaultCreateOptions={graphicProperties:{attributes:s,sourceLayer:n},mode:p.createOptions.mode,optionsPerTool:p.createOptions.optionsPerTool,preserveAspectRatio:p.createOptions.preserveAspectRatio,hasZ:u.data.supportsZ,defaultZ:(c?u.editing.zDefault:null)??e.defaultCreateOptions.defaultZ},null==a.geometryToPlace?await e.create(p.tool):await e.place(a.geometryToPlace,{graphicProperties:{attributes:s,sourceLayer:n}})}async function ce(e){return s([await ue(e),await pe(e)])}async function ue({creationAttributes:e,data:t,sketchViewModel:r,view:a,webStyleCache:o}){const{creationInfo:n}=t,{fullTemplate:i}=t;if(!n||"2d"!==a?.type||S(i)||j(i))return null;const s=m((t=>Ae(r,n.layer,e,o,t)));return g((()=>a.scale),(e=>s(e)))}async function pe({data:t,sketchViewModel:r,view:a}){const{templateExecutorInfo:o}=t;if(!o)return null;const n=r.activeComponent;if(!a||!K(n))return X().error(new i("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"});a.map?.add(c);const{executor:u,serviceLayersById:p}=o,d=a.theme?.accentColor??new e([255,165,0,1]);return s([b((()=>n),["cursor-update","vertex-add"],(()=>{c.removeAll();const e=n.graphic?.geometry;if(!e||!de(e))return;const t=u(e,"digitizing");if(!h(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=fe(e,d);t&&c.add(t)}}})),l((()=>{a.map.remove(c),c.destroy()}))])}function de(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 o(t.at(0),t.at(-1))?t.length>2:t.length>1}default:return!1}}function fe(e,r){let a=null;switch(e.geometry?.type){case"point":case"multipoint":a=new D({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":a=new C({color:r,outline:new R({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:3}),style:"none"});break;case"polyline":a=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:a,attributes:{...e.attributes}})}async function ye(e,t){const r=await N(t).load(),a=x(e)?e.parent:e;return r.tablesAndLayersLookup.get(a)}async function me(e,t){const r=await ye(e,t);if(!r)return new Map;const a=new Map;for(const o of r.layersAndTables)d(a,o.layerId,(()=>[])).push(o);return a}function he(e){const t=e.objectIdField,r=e.globalIdField??"";return{id:e.layerId,identifierFields:{objectIdField:t,globalIdField:r},addFeatures:[],deleteAttachments:[],addAttachments:[],deleteFeatures:[],updateFeatures:[]}}function ge(e){const{edits:t,serviceInfo:a,view:o,findOriginalFeature:n}=e,i=be(a.layersAndTables),s=a.layersAndTables.toArray(),{allEditData:l,editDataByLayerIdMap:c,editDataByIdMap:u}=ve(t,i,n),p=Ie(l,we(s,c),c);if(je(l,p,o),0===p.length)return t;const d=H(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=he(e):h.id!==e.layerId&&(m.push(h),h=he(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))??he(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 be(e){const t=new Map;for(const r of e)t.set(r.layerId,r);return t}function we(e,t){const r=new Map;for(const a of e)for(const e of a.relationships??[])if(r.set(Te(a,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(Te(a,e),t.keyField);break}}return r}function ve(e,t,r){const a=new Map,o=[],n=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});a.set(c.layerId,e);for(const t of e)o.push(t),n.set(t.uniqueId,t)}return{allEditData:o,editDataByIdMap:n,editDataByLayerIdMap:a}}function Ie(e,t,r){const a=[];for(const o of e){const e=o.layer.relationships??[],{uniqueId:n}=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=Te(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]&&a.push([n,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]?a.push([r,n]):t.before.attributes[c]===o.after.attributes[e]&&a.push([n,r]):"add"===t.operationType?t.after.attributes[c]===o.after.attributes[e]?a.push([n,r]):t.after.attributes[c]===o.before.attributes[e]&&a.push([r,n]):"modify"===t.operationType&&(t.before.attributes[c]!==t.after.attributes[c]?t.after.attributes[c]===o.after.attributes[e]?a.push([n,r]):a.push([r,n]):a.push([n,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]&&a.push([t.uniqueId,n]))}}}}return a}function Te(e,t){return`${e.layerId}:${t.id}`}function Se(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 je(e,t,r){const a=[];for(const n of e)Se(n.layer,r)&&a.push(n);if(0===a.length)return;let o=[];for(const n of a){const r=n.layer;switch(n.operationType){case"delete":o=[...Fe(n.before.attributes[r.fieldsIndex.get("fromglobalid").name],e),...Fe(n.before.attributes[r.fieldsIndex.get("toglobalid").name],e)];for(const e of o)t.push([n.uniqueId,e.uniqueId]);break;case"add":o=[...Fe(n.after.attributes[r.fieldsIndex.get("fromglobalid").name],e),...Fe(n.after.attributes[r.fieldsIndex.get("toglobalid").name],e)];for(const e of o)t.push([e.uniqueId,n.uniqueId])}}}function Fe(e,t){const r=[],a=t.filter((({layer:e})=>""!==e.globalIdField&&null!=e.globalIdField));for(const o of a){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}function ke(e,t={}){return S(e)||j(e)?{}:F(e)?{...e.prototype.attributes,...t}:k(e)?{...e.definition?.defaultValues,...t}:{...t}}async function Ae(e,r,a,o,n){const i=new t({sourceLayer:r,attributes:a}),{rotation:s,size:l}=_(i);let c=await B(i,{useSourceLayer:!0,webStyleCache:o,scale:n}),u=!1;for(const t of[l,s]){if(null==t)continue;null==a[t.field]&&(a[t.field]=await t.getDefaultValue(c,e.view),u=!0)}switch(u&&(c=await B(i,{useSourceLayer:!0,webStyleCache:o,scale:n})),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}Ve(e.tooltipOptions,l,s)}function Ve(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 Ue(e,t){return e?.find((e=>e.layer===t))}async function Le(e,t,r,a){switch(t.type){case"3d":return Me(e,t,r,a);case"2d":return Oe(e,t,r,a)}}async function Me(e,t,r,o){if(0===e.length)return[];const{updatable:n,graphicsByLayer:i}=await r.async((async()=>{const{results:a}=await f($(t,r),o),n=new Map,i=e=>{const t=e.layer,r=n.get(t);if(!r){const e=new Array;return n.set(t,e),e}return r};J(a).forEach((({graphic:e})=>i(e).push(e)));const s=e.filter((({capabilities:e,layer:t})=>e.update.enabled&&n.has(t)));return 0!==s.length&&r.stopPropagation(),{updatable:s,graphicsByLayer:n}}));return f(Promise.allSettled(n.map((async({layer:e})=>{const t=i.get(e),r=xe(e);if(t.every((e=>L(r,e))))return t;const n=[];for(const o of t){n.push(o.getObjectId());const e=Object.keys(o.attributes);a(r,e)}const s=e.createQuery();return s.returnGeometry=!1,s.objectIds=n,s.outFields=M(e.fieldsIndex,r),e.queryFeatures(s,{signal:o}).then((({features:e})=>e))}))),o)}async function Oe(e,t,r,a){if(0===e.length)return[];const{mapPoint:o}=r;if(null==o)return[];let n=null;const i=await r.async((async()=>{const{results:o}=await f(t.hitTest(r),a);if(0===o.length)return[];const i=new Set;n=J(o),n.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 f(Promise.allSettled(i.map((async({layer:e})=>{const i=e.createQuery();i.returnGeometry=!0,i.outFields=xe(e);const s="renderer"in e?q({renderer:e.renderer,pointerType:r.pointerType}):0;i.geometry=W(o,s,t),i.outSpatialReference=t.spatialReference;const{features:l}=await e.queryFeatures(i,{signal:a});return n?.forEach((({graphic:t})=>{t.layer!==e||l.some((e=>e.getObjectId()===t.getObjectId()))||l.push(t)})),l}))),a)}function xe(e){return M(e.fieldsIndex,[e.objectIdField,O({displayField:"displayField"in e?e.displayField:null,fields:e.fields})])}async function qe(e,t,a,o){const n=t.createQuery();n.objectIds=e.map((e=>e.getObjectId())).filter(r),n.outFields=["*"],n.returnM=t.capabilities.data.supportsM,n.returnZ=t.capabilities.data.supportsZ,"scene"===t.type&&null!=t.infoFor3D||(n.outSpatialReference=a);const i=await t.queryFeatures(n,{signal:o});return y(o),i.features}function Pe(e){const t=new Map;for(const r of e){const e=r.sourceLayer,a=x(e)?e.parent:e;d(t,a,(()=>[])).push(r)}return t}async function ze(e){const{graphic:t,sketchViewModel:r,sourceLayer:a,visualVariables:o}=e;await Ee(e);const n={multipleSelectionEnabled:!1};return"point"===a.geometryType&&(n.enableRotation=null!=o.rotation,n.enableScaling=null!=o.size),r.update(t,n)}async function Ee(e){const{graphic:t,sketchViewModel:r,sourceLayer:a,visualVariables:o,webStyleCache:n}=e;let i=!1;const{rotation:s,size:l}=o;for(const c of[s,l]){if(null==c)continue;const e=t.getAttribute(c.field);if(null!=e)c.setInitialValue(e);else{const e=await c.getDefaultValue(t.symbol,r.view);c.setInitialValue(e),t.setAttribute(c.field,e),i=!0}}if(i){const e="2d"===r.view?.type?r.view.scale:null;await ie(t,n,e)}Ve(r.tooltipOptions,l,s),r.layer.elevationInfo=a.elevationInfo}function Ce(e){return null==e||"rotate-start"!==e.type&&"rotate"!==e.type&&"rotate-stop"!==e.type?null:e}function Re(e){return null==e||"scale-start"!==e.type&&"scale"!==e.type&&"scale-stop"!==e.type?null:e}async function De(e,t,r,a,o){if(null==t.geometry||"point"!==t.geometry?.type)return;const n=a.rotation,i=Ce(r.toolEventInfo);if(null!=n&&null!=i){const{field:r,getValue:a}=n;"rotate-stop"===i.type?(n.isUpdatingInteractively=!1,n.setInitialValue(t.getAttribute(r))):(n.isUpdatingInteractively=!0,t.setAttribute(r,a(i.angle,e)))}const s=a.size,l=Re(r.toolEventInfo);if(null!=s&&null!=l){const{field:r,getValue:a}=s;"scale-stop"===l.type?(s.isUpdatingInteractively=!1,s.setInitialValue(t.getAttribute(r))):(s.isUpdatingInteractively=!0,t.setAttribute(r,a(l.xScale,e)))}await ie(t,o,"2d"===e.type?e.scale:null)}async function Ge({feature:e,featureClone:t,visualVariableAttributes:r,sketchViewModel:a,view:o,onUpdate:n,webStyleCache:i,addUpdatingPromise:u,addHandle:p}){await ie(t,i,"2d"===o.type?o.scale:null);let d=null;if("2d"===a?.view?.type){const e=m((e=>ie(t,i,e)));d=g((()=>a?.view?.scale),(t=>e(t)))}const f=t.sourceLayer,y=Xe(o,f);await ze({graphic:t,sketchViewModel:a,sourceLayer:f,visualVariables:r,webStyleCache:i});let h=null;y.then((e=>h=e)).catch((()=>{}));const b=r.size,v=r.rotation,I=g((()=>e.attributes),(async e=>{let r=!1;for(const a in e){const o=e[a];o!==t.getAttribute(a)&&(t.setAttribute(a,o),null==b||b.isUpdatingInteractively||b.field!==a||b.setInitialValue(o),null==v||v.isUpdatingInteractively||v.field!==a||v.setInitialValue(o),(null==h||h.requiredFields.includes(a))&&(r=!0))}r&&await ie(t,i,"2d"===o.type?o.scale:null)})),T=a.on("update",(async e=>{const t=e.graphics[0],s={graphic:t,sketchViewModel:a,sourceLayer:f,visualVariables:r,webStyleCache:i};if("complete"===e.state){if(null===o.activeTool)return ze(s);const e=new AbortController,t=c(e);return p(t),u(w((()=>null===o.activeTool),e.signal).then((()=>(e.abort(),ze(s)))))}await De(o,t,e,r,i),n(_e(t),e)})),S=a.on(["undo","redo"],(async e=>{n(_e(e.graphics[0]),e)}));return s([S,T,l((()=>a.cancel())),I,d])}async function Be(e,t,r){const a=e.view;e.layer.add(r);const o=t.sourceLayer,i=t.layer,c=t.getAttribute(i.objectIdField);let u=null;function p(e){u?.abort(),u=n((async t=>{const r=await Xe(a,o);y(t),r.setVisibility?.(c,e)}))}return await Ze(a,r),p(!1),s([Ne(a,r,(e=>p(!e))),l((async()=>{p(!0);try{const e=await Xe(a,o);await w((()=>!e.updating))}finally{e.layer.remove(r)}}))])}function Ne(e,t,r){if("3d"===e.type){const a=new Z({graphic:t});return s([e.trackGraphicState(a),g((()=>a.displaying),r)])}return g((()=>t.visible),r)}async function Ze(e,t){if("3d"===e.type){const r=new Z({graphic:t}),a=e.trackGraphicState(r);await w((()=>r.displaying||r.error)),a.remove()}else await w((()=>t.visible))}const Qe={icon:v(24),text:v(12),line:v(1),viewScaleSizeFactor:100};function We(e,t,r){let a=!1;return e.filter((e=>!!a||(a=e===t,a))).map((e=>r[e]()))}function $e(e,t){e.viewModel.syncFeatureTemplates();const r=e.creationInfo;if("awaiting-feature-creation-info"===t[0].id&&r){const a=r.layer,o=e.viewModel.getTemplatesForLayer(a);1===o.length&&"scene"!==a.type&&(r.template=o[0],t.shift())}return t}function Je(e){return"unknown"===e?null:e}function He(e){e.filesEnabled=!0,e.mode="view",e.capabilities={editing:!0,operations:{add:!0,update:!0,delete:!0}}}const Ke=e=>/-stop/.test(e)||/vertex-/.test(e),Xe=(e,t)=>{const r="subtype-sublayer"===t.type?t.parent:t;return e.whenLayerView(r)};function Ye(e){return"createInteractiveEditSession"in e}function _e(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 et(e){const t=e.cursor;return e.cursor="progress",l((()=>e.cursor=t))}async function tt(e,t){const{template:r}=e;if(null==r)return null;if(A(r))return r.load();if(T(r)){const e=(await import("../../editing/sharedTemplates/SharedTemplate.js")).default,a=V(t,{makeSharedTemplateFromJSON:t=>e.fromJSON(t)}),o=await a.getTemplates({templateIds:[r.templateId],featureService:r.featureService});if(0===o.length)throw new i("editor:failed-to-load-template","Unable to load the provided template");return o[0].load()}return r}function rt(e){for(const t of e){const{destinationGraphic:e,destinationField:r,sourceGraphic:a,sourceField:o}=t;e.setAttribute(r,a.getAttribute(o))}}function at(e){const t=e.templateExecutorInfo?.completionResults;return t?.length?(t.forEach((e=>rt(e.relationships))),t.flatMap((e=>e.edits))):null}export{je as appendAllUtilityNetworkAssociationRelationships,$e as avoidFeatureTemplateSelectionWithOnlyOneItem,Ye as canCreateInteractiveEditSession,_e as cloneGraphicExceptMesh,be as createLayerIdMap,we as createRelationshipKeyMap,se as createToolFromGeometryType,We as createWorkflowSteps,Le as fetchCandidates,qe as fetchFullFeatures,Ie as findAllDependencies,Fe as findChangesByGlobalId,Ue as findLayerInfo,Te as generateHashForRelationship,ke as getCreationAttributes,tt as getFullTemplateForCreationInfo,at as getServiceEditsFromWorkflowData,ye as getServiceInfoForLayer,me as getServiceLayersById,_ as getVisualVariableAttributes,Pe as groupFeaturesByLayer,Ke as isTerminalUpdateEventType,Y as isUpdateWorkflow,Se as isUtilityNetworkAssociationsTable,ge as orderEditsByRelationshipDependencies,He as prepareAttachmentsForCreateFeaturesWorkflow,rt as setRelationshipFields,Ge as setUpGeometryUpdate,ce as setUpSketchCreateWatchers,Ee as setVisualVariablesAndElevationInfoForUpdate,et as showProgressCursor,Qe as sizeDefaults,Je as sizeVariableUnitToLengthUnit,le as startCreatingNewFeature,ze as startUpdatingFeatureGeometry,Be as swapForEditingSession,ie as updateGraphicSymbolWhenRequired,De as visualVariableInteractiveUpdate,Xe as whenEditorLayerView,Ze as whenGraphicDisplayed};
|
|
5
|
+
import e from"../../Color.js";import t from"../../Graphic.js";import{isSome as r,addMany as a,equals as n}from"../../core/arrayUtils.js";import{createTask as o}from"../../core/asyncUtils.js";import"../../core/has.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{whenOrAbort as f,throwIfAborted as y,debounce as m,isPromiseLike as h}from"../../core/promiseUtils.js";import{watch as g,on as b,whenOnce as w}from"../../core/reactiveUtils.js";import{px2pt as v}from"../../core/screenUtils.js";import{diff as I}from"../../core/accessorSupport/diffUtils.js";import{isSharedTemplateOrMetadata as T,isSharedGroupTemplate as S,isSharedPresetTemplate as j,isStandardFeatureTemplate as F,isSharedFeatureTemplate as k,isSharedTemplate as A}from"../../editing/templateUtils.js";import{getSharedTemplateProvider as U}from"../../editing/sharedTemplates/SharedTemplateProvider.js";import V from"../../layers/GraphicsLayer.js";import{featureHasFields as L,fixFields as M,getDisplayFieldName as O}from"../../layers/support/fieldUtils.js";import{isSubtypeSublayer as x}from"../../layers/support/layerUtils.js";import{calculateTolerance as z}from"../../renderers/support/clickToleranceUtils.js";import{meterIn as q}from"../../renderers/support/lengthUtils.js";import{isRenderer as P}from"../../renderers/support/typeUtils.js";import{getTransformationType as E,TransformationType as C}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import R from"../../symbols/SimpleFillSymbol.js";import D from"../../symbols/SimpleLineSymbol.js";import G from"../../symbols/SimpleMarkerSymbol.js";import{to3D as B}from"../../symbols/support/symbolConversion.js";import{getDisplayedSymbol as N}from"../../symbols/support/symbolUtils.js";import{getServices as Z}from"../../undoredo/support/Services.js";import{GraphicState as Q}from"../../views/3d/layers/graphics/GraphicState.js";import{defaultDrawingMode as W}from"../../views/draw/DrawingMode.js";import{createQueryGeometry as $}from"../../views/support/drapedUtils.js";import{hitTestSelectSimilarDistance as J,filterGraphicHits as H}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"update"===e.type}function ee(e){if(!(e&&"renderer"in e&&se(e.renderer)))return{rotation:null,size:null};const t=e.renderer.getVisualVariablesForType("rotation").filter((e=>(!e.axis||"heading"===e.axis)&&e.field&&!e.valueExpression)),r=e.renderer.getVisualVariablesForType("size").filter((e=>e.field&&!e.useSymbolValue&&!e.valueExpression&&E(e)===C.RealWorldSize));return{rotation:1===t.length?t[0]:null,size:1===r.length?r[0]:null}}function te(e){const t=e.sourceLayer;if(!(t&&"renderer"in t&&se(t.renderer)))return{rotation:null,size:null};const{rotation:r,size:a}=ee(t);let n=null,o=null;if(r){const e=t.fields?.filter((e=>e.name===r.field)),a=1===e?.length?e[0]:null;n=re(r,a)}if(a){const e=t.fields?.filter((e=>e.name===a.field)),r=1===e?.length?e[0]:null;o=oe(a,r)}return{rotation:n,size:o}}function re(e,t){const r="heading"===(e.axis||"heading")&&"arithmetic"===e.rotationType?-1:1,a=t?.type??"double",n={initial:0,current:0};return{field:e.field,fieldType:a,getDefaultValue:()=>Promise.resolve(0),getValue:e=>(n.current=n.initial-r*e,ie((n.current+360)%360,a)),setInitialValue:e=>{n.initial=e,n.current=0},isUpdatingInteractively:!1,rotationType:e.rotationType??"geographic"}}function ae(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 ne(e,t,r){if(null==t)return 0;const{symbol:a}=B(t);if(null==a||"web-style"===a.type||"cim"===a.type)return 0;const n=a.symbolLayers.at(0);if(!n)return 0;switch(n.type){case"icon":{const{computeIconLayerResourceSize:e}=await import("../../symbols/support/symbolLayerUtils.js");return Math.min($e.icon,(await e(n,$e.icon))[0])||$e.icon}case"text":return $e.text;case"line":return $e.line;case"object":{const{computeObjectLayerResourceSize:t}=await import("../../symbols/support/symbolLayerUtils.js");return ae(await t(n,e.scale/$e.viewScaleSizeFactor),r)}case"path":case"extrude":return e.scale/$e.viewScaleSizeFactor;default:return 0}}function oe(e,t){const r=e.axis,a=t?.type??"double",n={initial:0,current:0},o=q[e.valueUnit]??1;let i;return i="area"===e.valueRepresentation?e=>(e*o/2)**2*Math.PI:"radius"===e.valueRepresentation||"distance"===e.valueRepresentation?e=>e*o/2:e=>e*o,{field:e.field,fieldType:a,getDefaultValue:async(e,t)=>ie(i(await ne(t,e,r)),a),getValue:(e,t)=>(n.initial||(n.initial=t.pixelSizeAt(t.center)),n.current=n.initial*e,ie(n.current,a)),setInitialValue:e=>{n.initial=e,n.current=0},isUpdatingInteractively:!1,displayUnit:Ke(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 se(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 le(e,t,r){const a=await N(e,{useSourceLayer:!0,ignoreGraphicSymbol:!0,webStyleCache:t,scale:r});null!=I(e.symbol,a)&&(e.symbol=a)}function ce(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 a={mode:W,optionsPerTool:r};if(T(t)){const n=t.defaultTool,o=S(t)?t.definition?.inputGeometryType??e:e;switch(n){case"freehand":case"stream-line":return{tool:"polyline"===o?"freehandPolyline":"freehandPolygon",createOptions:a};case"autocomplete-freehand-polygons":case"stream-polygon":return{tool:"freehandPolygon",createOptions:a};case"autocomplete-polygons":case"difference-polygon":case"create-structures":case"polygon":case"trace":return{tool:"polygon"===o?"polygon":"polyline",createOptions:a};case"circle":return r.get("circle").preserveAspectRatio=!0,{tool:"circle",createOptions:a};case"ellipse":return r.get("circle").preserveAspectRatio=!1,{tool:"circle",createOptions:a};case"create-points-along-line":case"multipoint":return{tool:"multipoint",createOptions:a};case"line":case"radial-line":case"right-angle-line":case"split":case"two-point-line":return{tool:"polyline",createOptions:a};case"rectangle":case"regular-polygon":case"right-angle-polygon":return{tool:"rectangle",createOptions:a};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:a}}}else{const n=t.drawingTool;if("circle"===n||"ellipse"===n)return r.get("circle").preserveAspectRatio="circle"===n,{tool:"circle",createOptions:a};if("rectangle"===n)return{tool:"rectangle",createOptions:a};if("freehand"===n)return{tool:"polygon"===e?"freehandPolygon":"freehandPolyline",createOptions:a}}return{tool:e,createOptions:a}}async function ue(e,t,r){const{creationInfo:a,fullTemplate:n}=t;if(!a)throw new i("featureworkflow","No creation info provided.");const o=a.layer,s=Ue(n,a.attributeOverrides),{view:l}=e,c="2d"===l?.type;S(n)||j(n)||await Ve(e,o,s,r,c?l.scale:null);const{capabilities:u}=o;e.layer.elevationInfo=o.elevationInfo;const p=ce(o.geometryType,n);e.defaultCreateOptions={graphicProperties:{attributes:s,sourceLayer:o},mode:p.createOptions.mode,optionsPerTool:p.createOptions.optionsPerTool,preserveAspectRatio:p.createOptions.preserveAspectRatio,hasZ:u.data.supportsZ,defaultZ:(c?u.editing.zDefault:null)??e.defaultCreateOptions.defaultZ},null==a.geometryToPlace?await e.create(p.tool):await e.place(a.geometryToPlace,{graphicProperties:{attributes:s,sourceLayer:o}})}async function pe(e){return s([await de(e),await fe(e)])}async function de({creationAttributes:e,data:t,sketchViewModel:r,view:a,webStyleCache:n}){const{creationInfo:o}=t,{fullTemplate:i}=t;if(!o||"2d"!==a?.type||S(i)||j(i))return null;const s=m((t=>Ve(r,o.layer,e,n,t)));return g((()=>a.scale),(e=>s(e)))}async function fe({data:t,sketchViewModel:r,view:a}){const{templateExecutorInfo:n}=t;if(!n)return null;const o=r.activeComponent;if(!a||!X(o))return Y().error(new i("featureworkflow","Failed to set up template feedback.")),null;const c=new V({effect:"saturate(0.6) opacity(0.8)",listMode:"hide",title:"Shared Template Feedback Graphics"});a.map?.add(c);const{executor:u,serviceLayersById:p}=n,d=a.theme?.accentColor??new e([255,165,0,1]);return s([b((()=>o),["cursor-update","vertex-add"],(()=>{c.removeAll();const e=o.graphic?.geometry;if(!e||!ye(e))return;const t=u(e,"digitizing");if(!h(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((()=>{a.map.remove(c),c.destroy()}))])}function ye(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 a=null;switch(e.geometry?.type){case"point":case"multipoint":a=new G({angle:0,color:r,outline:new D({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":a=new R({color:r,outline:new D({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:3}),style:"none"});break;case"polyline":a=new D({cap:"round",color:r,join:"round",miterLimit:1,style:"solid",width:2});break;default:return null}return new t({geometry:e.geometry,symbol:a,attributes:{...e.attributes}})}async function he(e,t){const r=await Z(t).load(),a=x(e)?e.parent:e;return r.tablesAndLayersLookup.get(a)}async function ge(e,t){const r=await he(e,t);if(!r)return new Map;const a=new Map;for(const n of r.layersAndTables)d(a,n.layerId,(()=>[])).push(n);return a}function be(e){const t=e.objectIdField,r=e.globalIdField??"";return{id:e.layerId,identifierFields:{objectIdField:t,globalIdField:r},addFeatures:[],deleteAttachments:[],addAttachments:[],deleteFeatures:[],updateFeatures:[]}}function we(e){const{edits:t,serviceInfo:a,view:n,findOriginalFeature:o}=e,i=ve(a.layersAndTables),s=a.layersAndTables.toArray(),{allEditData:l,editDataByLayerIdMap:c,editDataByIdMap:u}=Te(t,i,o),p=Se(l,Ie(s,c),c);if(ke(l,p,n),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=be(e):h.id!==e.layerId&&(m.push(h),h=be(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))??be(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 ve(e){const t=new Map;for(const r of e)t.set(r.layerId,r);return t}function Ie(e,t){const r=new Map;for(const a of e)for(const e of a.relationships??[])if(r.set(je(a,e),""),t.has(e.relatedTableId)){const n=t.get(e.relatedTableId);if(n.length>0)for(const t of n[0].layer.relationships??[])if(t.id===e.id){r.set(je(a,e),t.keyField);break}}return r}function Te(e,t,r){const a=new Map,n=[],o=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});a.set(c.layerId,e);for(const t of e)n.push(t),o.set(t.uniqueId,t)}return{allEditData:n,editDataByIdMap:o,editDataByLayerIdMap:a}}function Se(e,t,r){const a=[];for(const n of e){const e=n.layer.relationships??[],{uniqueId:o}=n;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=je(n.layer,i),c=t.get(l);if(void 0===c||""===c)continue;switch(n.operationType){case"add":for(const t of s)t!==n&&("add"!==t.operationType&&"modify"!==t.operationType||t.after.attributes[c]===n.after.attributes[e]&&a.push([o,t.uniqueId]));break;case"modify":if(n.before.attributes[e]!==n.after.attributes[e])for(const t of s){const r=t.uniqueId;t!==n&&("delete"===t.operationType?t.before.attributes[c]===n.before.attributes[e]?a.push([r,o]):t.before.attributes[c]===n.after.attributes[e]&&a.push([o,r]):"add"===t.operationType?t.after.attributes[c]===n.after.attributes[e]?a.push([o,r]):t.after.attributes[c]===n.before.attributes[e]&&a.push([r,o]):"modify"===t.operationType&&(t.before.attributes[c]!==t.after.attributes[c]?t.after.attributes[c]===n.after.attributes[e]?a.push([o,r]):a.push([r,o]):a.push([o,r])))}break;case"delete":for(const t of s)t!==n&&("delete"!==t.operationType&&"modify"!==t.operationType||t.before.attributes[c]===n.before.attributes[e]&&a.push([t.uniqueId,o]))}}}}return a}function je(e,t){return`${e.layerId}:${t.id}`}function Fe(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 ke(e,t,r){const a=[];for(const o of e)Fe(o.layer,r)&&a.push(o);if(0===a.length)return;let n=[];for(const o of a){const r=o.layer;switch(o.operationType){case"delete":n=[...Ae(o.before.attributes[r.fieldsIndex.get("fromglobalid").name],e),...Ae(o.before.attributes[r.fieldsIndex.get("toglobalid").name],e)];for(const e of n)t.push([o.uniqueId,e.uniqueId]);break;case"add":n=[...Ae(o.after.attributes[r.fieldsIndex.get("fromglobalid").name],e),...Ae(o.after.attributes[r.fieldsIndex.get("toglobalid").name],e)];for(const e of n)t.push([e.uniqueId,o.uniqueId])}}}function Ae(e,t){const r=[],a=t.filter((({layer:e})=>""!==e.globalIdField&&null!=e.globalIdField));for(const n of a){const t=n.layer.globalIdField;("before"in n&&n.before?.attributes[t]===e||"after"in n&&n.after?.attributes[t]===e)&&r.push(n)}return r}function Ue(e,t={}){return S(e)||j(e)?{}:F(e)?{...e.prototype.attributes,...t}:k(e)?{...e.definition?.defaultValues,...t}:{...t}}async function Ve(e,r,a,n,o){const i=new t({sourceLayer:r,attributes:a}),{rotation:s,size:l}=te(i);let c=await N(i,{useSourceLayer:!0,webStyleCache:n,scale:o}),u=!1;for(const t of[l,s]){if(null==t)continue;null==a[t.field]&&(a[t.field]=await t.getDefaultValue(c,e.view),u=!0)}switch(u&&(c=await N(i,{useSourceLayer:!0,webStyleCache:n,scale:o})),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}Le(e.tooltipOptions,l,s)}function Le(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 Me(e,t){return e?.find((e=>e.layer===t))}async function Oe(e,t,r,a){switch(t.type){case"3d":return xe(e,t,r,a);case"2d":return ze(e,t,r,a)}}async function xe(e,t,r,n){if(0===e.length)return[];const{updatable:o,graphicsByLayer:i}=await r.async((async()=>{const{results:a}=await f(J(t,r),n),o=new Map,i=e=>{const t=e.layer,r=o.get(t);if(!r){const e=new Array;return o.set(t,e),e}return r};H(a).forEach((({graphic:e})=>i(e).push(e)));const s=e.filter((({capabilities:e,layer:t})=>e.update.enabled&&o.has(t)));return 0!==s.length&&r.stopPropagation(),{updatable:s,graphicsByLayer:o}}));return f(Promise.allSettled(o.map((async({layer:e})=>{const t=i.get(e),r=qe(e);if(t.every((e=>L(r,e))))return t;const o=[];for(const n of t){o.push(n.getObjectId());const e=Object.keys(n.attributes);a(r,e)}const s=e.createQuery();return s.returnGeometry=!1,s.objectIds=o,s.outFields=M(e.fieldsIndex,r),e.queryFeatures(s,{signal:n}).then((({features:e})=>e))}))),n)}async function ze(e,t,r,a){if(0===e.length)return[];const{mapPoint:n}=r;if(null==n)return[];let o=null;const i=await r.async((async()=>{const{results:n}=await f(t.hitTest(r),a);if(0===n.length)return[];const i=new Set;o=H(n),o.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 f(Promise.allSettled(i.map((async({layer:e})=>{const i=e.createQuery();i.returnGeometry=!0,i.outFields=qe(e);const s="renderer"in e?z({renderer:e.renderer,pointerType:r.pointerType}):0;i.geometry=$(n,s,t),i.outSpatialReference=t.spatialReference;const{features:l}=await e.queryFeatures(i,{signal:a});return o?.forEach((({graphic:t})=>{t.layer!==e||l.some((e=>e.getObjectId()===t.getObjectId()))||l.push(t)})),l}))),a)}function qe(e){return M(e.fieldsIndex,[e.objectIdField,O({displayField:"displayField"in e?e.displayField:null,fields:e.fields})])}async function Pe(e,t,a,n){const o=t.createQuery();o.objectIds=e.map((e=>e.getObjectId())).filter(r),o.outFields=["*"],o.returnM=t.capabilities.data.supportsM,o.returnZ=t.capabilities.data.supportsZ,"scene"===t.type&&null!=t.infoFor3D||(o.outSpatialReference=a);const i=await t.queryFeatures(o,{signal:n});return y(n),i.features}function Ee(e){const t=new Map;for(const r of e){const e=r.sourceLayer,a=x(e)?e.parent:e;d(t,a,(()=>[])).push(r)}return t}async function Ce(e){const{graphic:t,sketchViewModel:r,sourceLayer:a,visualVariables:n}=e;await Re(e);const o={multipleSelectionEnabled:!1};return"point"===a.geometryType&&(o.enableRotation=null!=n.rotation,o.enableScaling=null!=n.size),r.update(t,o)}async function Re(e){const{graphic:t,sketchViewModel:r,sourceLayer:a,visualVariables:n,webStyleCache:o}=e;let i=!1;const{rotation:s,size:l}=n;for(const c of[s,l]){if(null==c)continue;const e=t.getAttribute(c.field);if(null!=e)c.setInitialValue(e);else{const e=await c.getDefaultValue(t.symbol,r.view);c.setInitialValue(e),t.setAttribute(c.field,e),i=!0}}if(i){const e="2d"===r.view?.type?r.view.scale:null;await le(t,o,e)}Le(r.tooltipOptions,l,s),r.layer.elevationInfo=a.elevationInfo}function De(e){return null==e||"rotate-start"!==e.type&&"rotate"!==e.type&&"rotate-stop"!==e.type?null:e}function Ge(e){return null==e||"scale-start"!==e.type&&"scale"!==e.type&&"scale-stop"!==e.type?null:e}function Be(e,t,r,a){if(null==t.geometry||"point"!==t.geometry?.type)return!1;const n=t.attributes;let o=!1;const i=a.rotation,s=De(r.toolEventInfo);if(null!=i&&null!=s){const{field:r,getValue:a}=i;if("rotate-stop"===s.type)i.isUpdatingInteractively=!1,i.setInitialValue(t.getAttribute(r));else{i.isUpdatingInteractively=!0;const l=a(s.angle,e);l!==n[r]&&(t.setAttribute(r,l),o=!0)}}const l=a.size,c=Ge(r.toolEventInfo);if(null!=l&&null!=c){const{field:r,getValue:a}=l;if("scale-stop"===c.type)l.isUpdatingInteractively=!1,l.setInitialValue(t.getAttribute(r));else{l.isUpdatingInteractively=!0;const i=a(c.xScale,e);i!==n[r]&&(t.setAttribute(r,i),o=!0)}}return o}async function Ne({feature:e,featureClone:t,visualVariableAttributes:r,sketchViewModel:a,view:n,onUpdate:o,webStyleCache:i,addUpdatingPromise:u,addHandle:p}){await le(t,i,"2d"===n.type?n.scale:null);let d=null;if("2d"===a?.view?.type){const e=m((e=>le(t,i,e)));d=g((()=>a?.view?.scale),(t=>e(t)))}const f=t.sourceLayer,y=_e(n,f);await Ce({graphic:t,sketchViewModel:a,sourceLayer:f,visualVariables:r,webStyleCache:i});let h=null;y.then((e=>h=e)).catch((()=>{}));const b=r.size,v=r.rotation,I=g((()=>e.attributes),(async e=>{let r=!1;for(const a in e){const n=e[a];n!==t.getAttribute(a)&&(t.setAttribute(a,n),null==b||b.isUpdatingInteractively||b.field!==a||b.setInitialValue(n),null==v||v.isUpdatingInteractively||v.field!==a||v.setInitialValue(n),(null==h||h.requiredFields.includes(a))&&(r=!0))}r&&await le(t,i,"2d"===n.type?n.scale:null)})),T=a.on("update",(async e=>{const t=e.graphics[0],s={graphic:t,sketchViewModel:a,sourceLayer:f,visualVariables:r,webStyleCache:i};if("complete"===e.state){if(null===n.activeTool)return Ce(s);const e=new AbortController,t=c(e);return p(t),u(w((()=>null===n.activeTool),e.signal).then((async()=>{if(!e.signal.aborted)return e.abort(),Ce(s)})))}Be(n,t,e,r)&&await le(t,i,"2d"===n.type?n.scale:null),o(tt(t),e)})),S=a.on(["undo","redo"],(async e=>{o(tt(e.graphics[0]),e)}));return s([S,T,l((()=>a.cancel())),I,d])}async function Ze(e,t,r){const a=e.view;e.layer.add(r);const n=t.sourceLayer,i=t.layer,c=t.getAttribute(i.objectIdField);let u=null;function p(e){u?.abort(),u=o((async t=>{const r=await _e(a,n);y(t),r.setVisibility?.(c,e)}))}return await We(a,r),p(!1),s([Qe(a,r,(e=>p(!e))),l((async()=>{p(!0);try{const e=await _e(a,n);await w((()=>!e.updating))}finally{e.layer.remove(r)}}))])}function Qe(e,t,r){if("3d"===e.type){const a=new Q({graphic:t});return s([e.trackGraphicState(a),g((()=>a.displaying),r)])}return g((()=>t.visible),r)}async function We(e,t){if("3d"===e.type){const r=new Q({graphic:t}),a=e.trackGraphicState(r);await w((()=>r.displaying||r.error)),a.remove()}else await w((()=>t.visible))}const $e={icon:v(24),text:v(12),line:v(1),viewScaleSizeFactor:100};function Je(e,t,r){let a=!1;return e.filter((e=>!!a||(a=e===t,a))).map((e=>r[e]()))}function He(e,t){e.viewModel.syncFeatureTemplates();const r=e.creationInfo;if("awaiting-feature-creation-info"===t[0].id&&r){const a=r.layer,n=e.viewModel.getTemplatesForLayer(a);1===n.length&&"scene"!==a.type&&(r.template=n[0],t.shift())}return t}function Ke(e){return"unknown"===e?null:e}function Xe(e){e.filesEnabled=!0,e.mode="view",e.capabilities={editing:!0,operations:{add:!0,update:!0,delete:!0}}}const Ye=e=>/-stop/.test(e)||/vertex-/.test(e),_e=(e,t)=>{const r="subtype-sublayer"===t.type?t.parent:t;return e.whenLayerView(r)};function et(e){return"createInteractiveEditSession"in e}function tt(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 rt(e){const t=e.cursor;return e.cursor="progress",l((()=>e.cursor=t))}async function at(e,t){const{template:r}=e;if(null==r)return null;if(A(r))return r.load();if(T(r)){const e=(await import("../../editing/sharedTemplates/SharedTemplate.js")).default,a=U(t,{makeSharedTemplateFromJSON:t=>e.fromJSON(t)}),n=await a.getTemplates({templateIds:[r.templateId],featureService:r.featureService});if(0===n.length)throw new i("editor:failed-to-load-template","Unable to load the provided template");return n[0].load()}return r}function nt(e){for(const t of e){const{destinationGraphic:e,destinationField:r,sourceGraphic:a,sourceField:n}=t;e.setAttribute(r,a.getAttribute(n))}}function ot(e){const t=e.templateExecutorInfo?.completionResults;return t?.length?(t.forEach((e=>nt(e.relationships))),t.flatMap((e=>e.edits))):null}export{ke as appendAllUtilityNetworkAssociationRelationships,He as avoidFeatureTemplateSelectionWithOnlyOneItem,et as canCreateInteractiveEditSession,tt as cloneGraphicExceptMesh,ve as createLayerIdMap,Ie as createRelationshipKeyMap,ce as createToolFromGeometryType,Je as createWorkflowSteps,Oe as fetchCandidates,Pe as fetchFullFeatures,Se as findAllDependencies,Ae as findChangesByGlobalId,Me as findLayerInfo,je as generateHashForRelationship,Ue as getCreationAttributes,at as getFullTemplateForCreationInfo,re as getRotationVariableAttribute,ot as getServiceEditsFromWorkflowData,he as getServiceInfoForLayer,ge as getServiceLayersById,oe as getSizeVariableAttribute,te as getVisualVariableAttributes,ee as getVisualVariablesForLayer,Ee as groupFeaturesByLayer,Ye as isTerminalUpdateEventType,_ as isUpdateWorkflow,Fe as isUtilityNetworkAssociationsTable,we as orderEditsByRelationshipDependencies,Xe as prepareAttachmentsForCreateFeaturesWorkflow,nt as setRelationshipFields,Ne as setUpGeometryUpdate,pe as setUpSketchCreateWatchers,Re as setVisualVariablesAndElevationInfoForUpdate,rt as showProgressCursor,$e as sizeDefaults,Ke as sizeVariableUnitToLengthUnit,ue as startCreatingNewFeature,Ce as startUpdatingFeatureGeometry,Ze as swapForEditingSession,le as updateGraphicSymbolWhenRequired,Be as visualVariableInteractiveUpdate,_e as whenEditorLayerView,We as whenGraphicDisplayed};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import{stripHTML as t}from"../../core/string.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import{getFeaturePopupTitle as o}from"../../support/popupUtils.js";import l from"./FeatureUtilityNetworkAssociations/VisibleElements.js";import{loadCalciteComponents as r}from"../support/componentsUtils.js";import{globalCss as n}from"../support/globalCss.js";import"../support/widgetUtils.js";import{tsx as a,tsxFragment as c}from"../support/jsxFactory.js";import d from"../support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js";import p from"../support/UtilityNetworkAssociations/UtilityNetworkAssociationList.js";import{formatPercentAlong as u}from"../support/UtilityNetworkAssociations/utils/formatPercentAlong.js";import{isConnectivity as m}from"../support/UtilityNetworkAssociations/utils/isConnectivity.js";import{isConnectivityMidspan as h}from"../support/UtilityNetworkAssociations/utils/isConnectivityMidspan.js";import{substitute as w}from"../../intl/substitute.js";var f;const y="esri-feature-utility-network-associations",b={base:y,listItemHidden:`${y}__list-item--hidden`},v="nested";let g=f=class extends p{constructor(e,t){super(e,t),this.description=null,this.flowItems=null,this.flowType="feature-utility-network-association-type",this.listType=null,this.parentFeatureViewModel=null,this.title=null,this.viewModel=new d,this.visibleElements=new l}initialize(){this.setUpObserver()}loadDependencies(){return r({chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip")})}destroy(){this.tooltipReferenceMap.clear()}render(){const e=this.viewModel.associationViewModels,{state:t,showAllEnabled:i}=this.viewModel,{state:s}=this.parentFeatureViewModel??{};return a("div",{class:this.classes(b.base,n.widget)},"loading"===t||"querying"===t||"loading"===s?this.renderLoading():a("calcite-list",{displayMode:v,label:this.selectedLayer?.title??this.messagesCommon.untitled},i&&this.selectedLayer?a(c,null,this.renderFilter(),this.renderFeatureCountWarning(),this._renderAssociatedFeatureListPage(),this.renderFeatureObserver()):Array.from(e.keys(),(t=>this._renderTypeList(t,e.get(t))))))}_showAllAssociations(e){const{flowItems:t,viewModel:i,description:s}=this;if(!t||!e)return;i.showAllEnabled=!0;const o=new f({selectedLayer:e,title:e?.title,flowItems:t,parentFeatureViewModel:this.parentFeatureViewModel,featureVisibleElements:this.featureVisibleElements,description:s,visibleElements:new l({title:!1,description:!1}),viewModel:i});t.push(o)}_renderAssociatedFeatureListPage(){const e=this.viewModel.associationViewModels.get(this.selectedLayer).filter((e=>o(e.featureViewModel).toLowerCase().includes(this.filterText))).slice(0,this.endIndex);return[...this._renderTooltips(e),...this._renderAssociatedFeatureList(e)]}_renderItemTooltip(e){const{tooltipReferenceMap:t}=this;return m(e.association)?a("calcite-tooltip",{key:`tooltip-${e.featureViewModel.uid}`,overlayPositioning:"fixed",referenceElement:t.get(e.featureViewModel.uid)},this.getConnectivityTooltip(e.association.associationType)):null}_renderAssociatedFeature(e){const{featureViewModel:i}=e,s=o(i),l="loading"===i.state,r=this._findFlowItem(i),n=r<0&&this._isParentFeature(i),c=n||r>=0;return a("calcite-list-item",{class:l?b.listItemHidden:void 0,description:t(e.terminalName??""),key:`associated-feature-type-${i.uid}`,label:t(s),onCalciteListItemSelect:()=>this._handleFeatureClick(n,r,i)},m(e.association)?this.renderConnectivityIcon(e.association.associationType,e.featureViewModel.uid):null,h(e.association)?a("calcite-chip",{label:u(e.association),scale:"s",slot:"content-end"},u(e.association)):null,this._renderChevronIconNode(c))}async _selectAssociation(e){const{flowItems:t,featureVisibleElements:i}=this;if(!t)return;e.abilities={utilityNetworkAssociationsContent:!0};const{default:s}=await import("../Feature.js");t.push(new s({flowItems:t,flowType:"feature-association",viewModel:e,visibleElements:i}))}_handleFeatureClick(e,t,i){if(e)this.flowItems.drain((e=>{"showAllEnabled"in e.viewModel&&(e.viewModel.showAllEnabled=!1),e.viewModel=null,e.destroy()}));else if(t<0||!this.flowItems)this._selectAssociation(i);else for(;this.flowItems.length>t+1;){const e=this.flowItems.pop();e&&("showAllEnabled"in e.viewModel&&(e.viewModel.showAllEnabled=!1),e.viewModel=null,e.destroy())}}_featureViewModelMatch(e,t){const i=e.graphic,s=i?.layer;let o=null;"subtype-sublayer"===s?.type&&s.parent?o=s.parent.globalIdField??null:s&&"globalIdField"in s&&(o=s.globalIdField);const l=o?i?.attributes[o]:null,r=t.graphic,n=r?.layer;let a=null;"subtype-sublayer"===n?.type&&n.parent?a=n.parent.globalIdField??null:n&&"globalIdField"in n&&(a=n.globalIdField);const c=a?r?.attributes[a]:null;return l&&c&&l===c}_isParentFeature(e){const t=this.flowItems?.getItemAt(0);if(!t)return!1;const i=t.parentFeatureViewModel;return this._featureViewModelMatch(i,e)}_findFlowItem(e){return this.flowItems?.findIndex((t=>{if("feature-association"!==t.flowType)return!1;const i=t.viewModel;return this._featureViewModelMatch(i,e)}))??-1}_renderTooltips(e){return e.toArray().map((e=>this._renderItemTooltip(e)))}_renderAssociatedFeatureList(e){return e.toArray().map((e=>this._renderAssociatedFeature(e)))}_renderChevronIconNode(e){return a("calcite-icon",{flipRtl:!0,icon:e?"move-up":"chevron-right",scale:"s",slot:"content-end"})}_renderTypeList(e,t){const{messagesFeature:i}=this,{displayCount:s}=this.viewModel,o=t.slice(0,s),l=o.length<t.length;return a("calcite-list-item",{key:"show-all",label:e.title,
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import{stripHTML as t}from"../../core/string.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import{getFeaturePopupTitle as o}from"../../support/popupUtils.js";import l from"./FeatureUtilityNetworkAssociations/VisibleElements.js";import{loadCalciteComponents as r}from"../support/componentsUtils.js";import{globalCss as n}from"../support/globalCss.js";import"../support/widgetUtils.js";import{tsx as a,tsxFragment as c}from"../support/jsxFactory.js";import d from"../support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js";import p from"../support/UtilityNetworkAssociations/UtilityNetworkAssociationList.js";import{formatPercentAlong as u}from"../support/UtilityNetworkAssociations/utils/formatPercentAlong.js";import{isConnectivity as m}from"../support/UtilityNetworkAssociations/utils/isConnectivity.js";import{isConnectivityMidspan as h}from"../support/UtilityNetworkAssociations/utils/isConnectivityMidspan.js";import{substitute as w}from"../../intl/substitute.js";var f;const y="esri-feature-utility-network-associations",b={base:y,listItemHidden:`${y}__list-item--hidden`},v="nested";let g=f=class extends p{constructor(e,t){super(e,t),this.description=null,this.flowItems=null,this.flowType="feature-utility-network-association-type",this.listType=null,this.parentFeatureViewModel=null,this.title=null,this.viewModel=new d,this.visibleElements=new l}initialize(){this.setUpObserver()}loadDependencies(){return r({chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip")})}destroy(){this.tooltipReferenceMap.clear()}render(){const e=this.viewModel.associationViewModels,{state:t,showAllEnabled:i}=this.viewModel,{state:s}=this.parentFeatureViewModel??{};return a("div",{class:this.classes(b.base,n.widget)},"loading"===t||"querying"===t||"loading"===s?this.renderLoading():a("calcite-list",{displayMode:v,label:this.selectedLayer?.title??this.messagesCommon.untitled},i&&this.selectedLayer?a(c,null,this.renderFilter(),this.renderFeatureCountWarning(),this._renderAssociatedFeatureListPage(),this.renderFeatureObserver()):Array.from(e.keys(),(t=>this._renderTypeList(t,e.get(t))))))}_showAllAssociations(e){const{flowItems:t,viewModel:i,description:s}=this;if(!t||!e)return;i.showAllEnabled=!0;const o=new f({selectedLayer:e,title:e?.title,flowItems:t,parentFeatureViewModel:this.parentFeatureViewModel,featureVisibleElements:this.featureVisibleElements,description:s,visibleElements:new l({title:!1,description:!1}),viewModel:i});t.push(o)}_renderAssociatedFeatureListPage(){const e=this.viewModel.associationViewModels.get(this.selectedLayer).filter((e=>o(e.featureViewModel).toLowerCase().includes(this.filterText))).slice(0,this.endIndex);return[...this._renderTooltips(e),...this._renderAssociatedFeatureList(e)]}_renderItemTooltip(e){const{tooltipReferenceMap:t}=this;return m(e.association)?a("calcite-tooltip",{key:`tooltip-${e.featureViewModel.uid}`,overlayPositioning:"fixed",referenceElement:t.get(e.featureViewModel.uid)},this.getConnectivityTooltip(e.association.associationType)):null}_renderAssociatedFeature(e){const{featureViewModel:i}=e,s=o(i),l="loading"===i.state,r=this._findFlowItem(i),n=r<0&&this._isParentFeature(i),c=n||r>=0;return a("calcite-list-item",{class:l?b.listItemHidden:void 0,description:t(e.terminalName??""),key:`associated-feature-type-${i.uid}`,label:t(s),onCalciteListItemSelect:()=>this._handleFeatureClick(n,r,i)},m(e.association)?this.renderConnectivityIcon(e.association.associationType,e.featureViewModel.uid):null,h(e.association)?a("calcite-chip",{label:u(e.association),scale:"s",slot:"content-end"},u(e.association)):null,this._renderChevronIconNode(c))}async _selectAssociation(e){const{flowItems:t,featureVisibleElements:i}=this;if(!t)return;e.abilities={utilityNetworkAssociationsContent:!0};const{default:s}=await import("../Feature.js");t.push(new s({flowItems:t,flowType:"feature-association",viewModel:e,visibleElements:i}))}_handleFeatureClick(e,t,i){if(e)this.flowItems.drain((e=>{"showAllEnabled"in e.viewModel&&(e.viewModel.showAllEnabled=!1),e.viewModel=null,e.destroy()}));else if(t<0||!this.flowItems)this._selectAssociation(i);else for(;this.flowItems.length>t+1;){const e=this.flowItems.pop();e&&("showAllEnabled"in e.viewModel&&(e.viewModel.showAllEnabled=!1),e.viewModel=null,e.destroy())}}_featureViewModelMatch(e,t){const i=e.graphic,s=i?.layer;let o=null;"subtype-sublayer"===s?.type&&s.parent?o=s.parent.globalIdField??null:s&&"globalIdField"in s&&(o=s.globalIdField);const l=o?i?.attributes[o]:null,r=t.graphic,n=r?.layer;let a=null;"subtype-sublayer"===n?.type&&n.parent?a=n.parent.globalIdField??null:n&&"globalIdField"in n&&(a=n.globalIdField);const c=a?r?.attributes[a]:null;return l&&c&&l===c}_isParentFeature(e){const t=this.flowItems?.getItemAt(0);if(!t)return!1;const i=t.parentFeatureViewModel;return this._featureViewModelMatch(i,e)}_findFlowItem(e){return this.flowItems?.findIndex((t=>{if("feature-association"!==t.flowType)return!1;const i=t.viewModel;return this._featureViewModelMatch(i,e)}))??-1}_renderTooltips(e){return e.toArray().map((e=>this._renderItemTooltip(e)))}_renderAssociatedFeatureList(e){return e.toArray().map((e=>this._renderAssociatedFeature(e)))}_renderChevronIconNode(e){return a("calcite-icon",{flipRtl:!0,icon:e?"move-up":"chevron-right",scale:"s",slot:"content-end"})}_renderTypeList(e,t){const{messagesFeature:i}=this,{displayCount:s}=this.viewModel,o=t.slice(0,s),l=o.length<t.length;return a("calcite-list-item",{expanded:!0,key:"show-all",label:e.title,value:e.id},a("calcite-chip",{label:String(t.length),scale:"s",slot:"content-end"},t.length),a("calcite-list",{group:e.id,label:e.title??""},[this._renderTooltips(o),this._renderAssociatedFeatureList(o)],l?a("calcite-list-item",{description:w(i?.numberRecords,{number:t.length.toString()}),key:"show-all-item",label:i.showAll,onCalciteListItemSelect:()=>this._showAllAssociations(e)},a("calcite-icon",{icon:"list",scale:"s",slot:"content-end"})):null))}};e([i()],g.prototype,"description",void 0),e([i()],g.prototype,"featureVisibleElements",void 0),e([i()],g.prototype,"flowItems",void 0),e([i()],g.prototype,"flowType",void 0),e([i()],g.prototype,"listType",void 0),e([i()],g.prototype,"parentFeatureViewModel",void 0),e([i()],g.prototype,"title",void 0),e([i({type:d})],g.prototype,"viewModel",void 0),e([i({type:l,nonNullable:!0})],g.prototype,"visibleElements",void 0),g=f=e([s("esri.widgets.Feature.FeatureUtilityNetworkAssociationList")],g);const M=g;export{M as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as t}from"../../../chunks/tslib.es6.js";import"../../../intl.js";import{stripHTML as e}from"../../../core/string.js";import{property as s}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as i}from"../../../core/accessorSupport/decorators/subclass.js";import{getFeatureFormTitle as o}from"../featureFormUtils.js";import r from"../UtilityNetworkAssociationInput.js";import{AssociationDetails as a}from"./AssociationDetails.js";import n from"./VisibleElements.js";import{loadCalciteComponents as c}from"../../support/componentsUtils.js";import{globalCss as l}from"../../support/globalCss.js";import{Heading as d}from"../../support/Heading.js";import"../../support/widgetUtils.js";import{messageBundle as p}from"../../support/decorators/messageBundle.js";import{tsx as u,tsxFragment as m}from"../../support/jsxFactory.js";import h from"../../support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js";import y from"../../support/UtilityNetworkAssociations/UtilityNetworkAssociationList.js";import{formatPercentAlong as g}from"../../support/UtilityNetworkAssociations/utils/formatPercentAlong.js";import{isConnectivity as f}from"../../support/UtilityNetworkAssociations/utils/isConnectivity.js";import{isConnectivityMidspan as F}from"../../support/UtilityNetworkAssociations/utils/isConnectivityMidspan.js";import{substitute as v}from"../../../intl/substitute.js";const _="esri-feature-form-utility-network-association-list",L={base:_,header:`${_}__header`,headingContent:`${_}__heading-content`,listContainer:`${_}__list-container`};let A=class extends y{constructor(t,e){super(t,e),this._isLoadingSelectFeature=!1,this.associationInput=null,this.headingLevel=5,this.messagesFeatureForm=null,this.onSelectLayer=()=>{},this.onSelectFeature=async()=>{},this.onAddAssociation=()=>{},this.viewModel=new h,this.visibleElements=new n}initialize(){this.setUpObserver()}loadDependencies(){return c({chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),fab:()=>import("@esri/calcite-components/dist/components/calcite-fab"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip")})}get associatedFeatureCount(){const{associationInput:t}=this;if(!t)return 0;const{associatedFeatureInfos:e,associatedLayer:s}=t,i=s?e.get(s):null;return i?i.length:0}render(){const{associationInput:t}=this;if(!t)return u("div",{class:this.classes(L.base,l.widget)});const{associatedLayer:e}=t,{state:s}=this.viewModel;return u("div",{class:this.classes(L.base,l.widget)},"loading"===s||"querying"===s?this.renderLoading():e?this._renderFeatureList(t,e):this._renderLayerList(t))}_renderLayerList(t){const{associatedFeatureInfos:e,editable:s}=t;return u("div",{class:L.listContainer},u("calcite-list",{label:this.messagesFeatureForm?.associations.associatedLayers},Array.from(e.keys(),(e=>this._renderLayerItem(t,e)))),s?u("calcite-fab",{appearance:"outline-fill",icon:"plus",key:`${t.uid}-add-button`,kind:"neutral",onclick:()=>this.onAddAssociation({feature:t.feature,associationType:t.activeAssociationType,utilityNetwork:t.utilityNetwork}),text:this.messagesCommon.add,textEnabled:!0}):null)}_renderFeatureList(t,e){return u(m,null,this._renderHeader(t,e),u("div",{class:L.listContainer},this.renderFeatureCountWarning(),u("calcite-list",{label:this.messagesFeatureForm?.associations.associatedFeatures},this._renderAssociatedFeatureListPage(t,e),this.renderFeatureObserver())))}_renderLayerTitle(t){return t.title?u(d,{key:"title",level:this.headingLevel},u("div",{class:L.headingContent},u("calcite-icon",{icon:"layer"}),t.title)):null}_renderTotal(t,e){const{messagesFeature:s}=this,{associatedFeatureInfos:i}=t,o=i.get(e),r=v(s?.numberRecords,{number:o?.length??"0"});return u("div",{key:e.id},r)}_renderHeader(t,e){const{messagesFeatureForm:s}=this,{activeAssociationType:i,featureItem:o,feature:r}=t;return u("div",{class:L.header,key:"filter"},this.visibleElements.associationDetails?u(a,{associationType:i?.type,feature:r,heading:o?.label,messages:s.associations}):void 0,this._renderLayerTitle(e),this.renderFilter(),this._renderTotal(t,e))}_renderAssociatedFeatureListPage(t,e){const{filterText:s,endIndex:i}=this,r=this.messagesCommon.untitled,a=t.associatedFeatureInfos.get(e)?.filter((t=>o(t,r).toLowerCase().includes(s)??!1)).slice(0,i).toArray()??[];return[...this._renderTooltips(a),...this._renderAssociatedFeatureList(a)]}_renderItemTooltip(t){const{tooltipReferenceMap:e}=this,s=t.feature.uid.toString();return f(t.association)?u("calcite-tooltip",{key:`tooltip-${s}`,overlayPositioning:"fixed",referenceElement:e.get(s)},this.getConnectivityTooltip(t.association.associationType)):null}_renderAssociatedFeature(t){const s=this.messagesCommon.untitled,i=o(t,s),r=t.feature.uid.toString();return u("calcite-list-item",{description:e(t.terminalName??""),key:`associated-feature-type-${r}`,label:e(i),onCalciteListItemSelect:()=>this._selectAssociation(t)},f(t.association)?this.renderConnectivityIcon(t.association.associationType,r):null,F(t.association)?u("calcite-chip",{label:g(t.association),scale:"s",slot:"content-end"},g(t.association)):null,u("calcite-icon",{flipRtl:!0,icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderTooltips(t){return t.map((t=>this._renderItemTooltip(t)))}_renderAssociatedFeatureList(t){return t.map((t=>this._renderAssociatedFeature(t)))}_renderLayerItem(t,e){const{associatedFeatureInfos:s}=t,i=s.get(e)?.length??0;return u("calcite-list-item",{key:`${e.id}-show-all`,label:e.title??this.messagesCommon.untitled,
|
|
5
|
+
import{_ as t}from"../../../chunks/tslib.es6.js";import"../../../intl.js";import{stripHTML as e}from"../../../core/string.js";import{property as s}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as i}from"../../../core/accessorSupport/decorators/subclass.js";import{getFeatureFormTitle as o}from"../featureFormUtils.js";import r from"../UtilityNetworkAssociationInput.js";import{AssociationDetails as a}from"./AssociationDetails.js";import n from"./VisibleElements.js";import{loadCalciteComponents as c}from"../../support/componentsUtils.js";import{globalCss as l}from"../../support/globalCss.js";import{Heading as d}from"../../support/Heading.js";import"../../support/widgetUtils.js";import{messageBundle as p}from"../../support/decorators/messageBundle.js";import{tsx as u,tsxFragment as m}from"../../support/jsxFactory.js";import h from"../../support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js";import y from"../../support/UtilityNetworkAssociations/UtilityNetworkAssociationList.js";import{formatPercentAlong as g}from"../../support/UtilityNetworkAssociations/utils/formatPercentAlong.js";import{isConnectivity as f}from"../../support/UtilityNetworkAssociations/utils/isConnectivity.js";import{isConnectivityMidspan as F}from"../../support/UtilityNetworkAssociations/utils/isConnectivityMidspan.js";import{substitute as v}from"../../../intl/substitute.js";const _="esri-feature-form-utility-network-association-list",L={base:_,header:`${_}__header`,headingContent:`${_}__heading-content`,listContainer:`${_}__list-container`};let A=class extends y{constructor(t,e){super(t,e),this._isLoadingSelectFeature=!1,this.associationInput=null,this.headingLevel=5,this.messagesFeatureForm=null,this.onSelectLayer=()=>{},this.onSelectFeature=async()=>{},this.onAddAssociation=()=>{},this.viewModel=new h,this.visibleElements=new n}initialize(){this.setUpObserver()}loadDependencies(){return c({chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),fab:()=>import("@esri/calcite-components/dist/components/calcite-fab"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip")})}get associatedFeatureCount(){const{associationInput:t}=this;if(!t)return 0;const{associatedFeatureInfos:e,associatedLayer:s}=t,i=s?e.get(s):null;return i?i.length:0}render(){const{associationInput:t}=this;if(!t)return u("div",{class:this.classes(L.base,l.widget)});const{associatedLayer:e}=t,{state:s}=this.viewModel;return u("div",{class:this.classes(L.base,l.widget)},"loading"===s||"querying"===s?this.renderLoading():e?this._renderFeatureList(t,e):this._renderLayerList(t))}_renderLayerList(t){const{associatedFeatureInfos:e,editable:s}=t;return u("div",{class:L.listContainer},u("calcite-list",{label:this.messagesFeatureForm?.associations.associatedLayers},Array.from(e.keys(),(e=>this._renderLayerItem(t,e)))),s?u("calcite-fab",{appearance:"outline-fill",icon:"plus",key:`${t.uid}-add-button`,kind:"neutral",onclick:()=>this.onAddAssociation({feature:t.feature,associationType:t.activeAssociationType,utilityNetwork:t.utilityNetwork}),text:this.messagesCommon.add,textEnabled:!0}):null)}_renderFeatureList(t,e){return u(m,null,this._renderHeader(t,e),u("div",{class:L.listContainer},this.renderFeatureCountWarning(),u("calcite-list",{label:this.messagesFeatureForm?.associations.associatedFeatures},this._renderAssociatedFeatureListPage(t,e),this.renderFeatureObserver())))}_renderLayerTitle(t){return t.title?u(d,{key:"title",level:this.headingLevel},u("div",{class:L.headingContent},u("calcite-icon",{icon:"layer"}),t.title)):null}_renderTotal(t,e){const{messagesFeature:s}=this,{associatedFeatureInfos:i}=t,o=i.get(e),r=v(s?.numberRecords,{number:o?.length??"0"});return u("div",{key:e.id},r)}_renderHeader(t,e){const{messagesFeatureForm:s}=this,{activeAssociationType:i,featureItem:o,feature:r}=t;return u("div",{class:L.header,key:"filter"},this.visibleElements.associationDetails?u(a,{associationType:i?.type,feature:r,heading:o?.label,messages:s.associations}):void 0,this._renderLayerTitle(e),this.renderFilter(),this._renderTotal(t,e))}_renderAssociatedFeatureListPage(t,e){const{filterText:s,endIndex:i}=this,r=this.messagesCommon.untitled,a=t.associatedFeatureInfos.get(e)?.filter((t=>o(t,r).toLowerCase().includes(s)??!1)).slice(0,i).toArray()??[];return[...this._renderTooltips(a),...this._renderAssociatedFeatureList(a)]}_renderItemTooltip(t){const{tooltipReferenceMap:e}=this,s=t.feature.uid.toString();return f(t.association)?u("calcite-tooltip",{key:`tooltip-${s}`,overlayPositioning:"fixed",referenceElement:e.get(s)},this.getConnectivityTooltip(t.association.associationType)):null}_renderAssociatedFeature(t){const s=this.messagesCommon.untitled,i=o(t,s),r=t.feature.uid.toString();return u("calcite-list-item",{description:e(t.terminalName??""),key:`associated-feature-type-${r}`,label:e(i),onCalciteListItemSelect:()=>this._selectAssociation(t)},f(t.association)?this.renderConnectivityIcon(t.association.associationType,r):null,F(t.association)?u("calcite-chip",{label:g(t.association),scale:"s",slot:"content-end"},g(t.association)):null,u("calcite-icon",{flipRtl:!0,icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderTooltips(t){return t.map((t=>this._renderItemTooltip(t)))}_renderAssociatedFeatureList(t){return t.map((t=>this._renderAssociatedFeature(t)))}_renderLayerItem(t,e){const{associatedFeatureInfos:s}=t,i=s.get(e)?.length??0;return u("calcite-list-item",{expanded:!0,key:`${e.id}-show-all`,label:e.title??this.messagesCommon.untitled,value:e.id,onCalciteListItemSelect:()=>this._showAllAssociations(e)},u("calcite-chip",{label:i.toString(),scale:"s",slot:"content-end"},i),u("calcite-icon",{flipRtl:!0,icon:"chevron-right",scale:"s",slot:"content-end"}))}async _selectAssociation(t){this._isLoadingSelectFeature||(this._isLoadingSelectFeature=!0,await this.onSelectFeature({feature:t.feature,association:t.association}),this._isLoadingSelectFeature=!1)}_showAllAssociations(t){this.onSelectLayer({layer:t,associationInput:this.associationInput})}};t([s()],A.prototype,"associatedFeatureCount",null),t([s({type:r})],A.prototype,"associationInput",void 0),t([s()],A.prototype,"headingLevel",void 0),t([s(),p("esri/widgets/FeatureForm/t9n/FeatureForm")],A.prototype,"messagesFeatureForm",void 0),t([s({constructOnly:!0})],A.prototype,"onSelectLayer",void 0),t([s({constructOnly:!0})],A.prototype,"onSelectFeature",void 0),t([s({constructOnly:!0})],A.prototype,"onAddAssociation",void 0),t([s({type:h})],A.prototype,"viewModel",void 0),t([s({type:n,nonNullable:!0})],A.prototype,"visibleElements",void 0),A=t([i("esri.widgets.FeatureForm.FeatureFormUtilityNetworkAssociations.FeatureFormUtilityNetworkAssociationList")],A);const b=A;export{b as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{neverReached as n}from"../../core/compilerUtils.js";import s from"../../core/Evented.js";import i from"../../core/Logger.js";import{destroyMaybe as o}from"../../core/maybe.js";import r from"../../core/Promise.js";import{debounce as a}from"../../core/promiseUtils.js";import{watch as l,whenOnce as u,on as p,syncAndInitial as c}from"../../core/reactiveUtils.js";import{templateHasKey as h}from"../../core/string.js";import{property as d}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as f}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as m}from"../../core/support/UpdatingHandles.js";import y from"../../form/FormTemplate.js";import{isUtilityNetworkAssociationsElement as g,isGroupElement as _,isFieldElement as v,isRelationshipElement as I,isTextElement as x}from"../../form/support/formUtils.js";import E from"../../layers/support/ContingentValue.js";import{isEditableLayer as C}from"../../layers/support/editableLayers.js";import F from"../../layers/support/LayerContingentValuesCache.js";import{utc as b,unknown as V,system as w}from"../../time/constants.js";import{flattenAssociationInputs as A,flattenFieldInputs as j,isGroupInput as T,flattenRelationshipInputs as M,parseFormTemplateString as k,isRelationshipInput as N,isFieldInput as L,isTextElementInput as R,getNormalizedFeatureTypeInfo as S,valueIsValidContingentValue as U}from"./featureFormUtils.js";import Z from"./FieldInput.js";import{FormExpressionsManager as H}from"./FormExpressionsManager.js";import P from"./GroupInput.js";import O from"./RelationshipInput.js";import W from"./TextElementInput.js";import{createFormExpressionArcadeExecutor as G}from"../support/forms/expressions/FormExpressionArcadeExecutor.js";const $=new t({attributes:{}}),D={field:["editableExpression","requiredExpression","valueExpression","visibilityExpression"],group:["visibilityExpression"],relationship:["editableExpression","visibilityExpression"],text:["visibilityExpression"],utilityNetworkAssociations:["editableExpression","visibilityExpression"]},z="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",J="#JSAPI_CONTINGENT_VALUE_ANY_HASH",B="#JSAPI_CONTINGENT_VALUE_NULL_HASH",K="esri.widgets.FeatureForm.FeatureFormViewModel",Y=()=>i.getLogger(K);let q=class extends(r.EsriPromiseMixin(s.EventedAccessor)){constructor(e){super(e),this._expressionExecutorsInUse=new Set,this._expressionExecutorLookup=new Map,this._expressionsManager=null,this._contingentValuesCache=null,this._featureClone=$.clone(),this._initialFeature=$.clone(),this._timeZone=null,this._updatingHandles=new m,this.activeAssociation=null,this.arcadeEditType="NA",this.contingencyConstraintViolations=new Map,this.disabled=!1,this.highlightHelper=null,this.inputs=[],this.map=null,this.callbacks=null,this.strict=!1,this.pendingSubtypeChoice=null,this._updateInputs=a((async()=>{this._stopExpressions();const{_featureClone:e,_initialFeature:t,arcadeEditType:n,formTemplate:s,inputs:i,layer:o,timeZone:r}=this;if(!o)return;const a={arcadeEditType:n,feature:e,initialFeature:t,layer:o,timeZone:r},l=i.slice(),u=s?.elements&&s.elements.length>0?await this._updateInputsUsingFormElements(l,s.elements,a):this._updateInputsUsingLayerFields(l,o?.fields,a);this.inputs=u,await this._startExpressions()}))}initialize(){const e=l((()=>[this.layer,!!this.layer?.loaded,this.formTemplate,this.feature,this.timeZone,this.arcadeEditType]),(([e,t])=>{null!=e&&(t?this._updatingHandles.addPromise(this._updateInputs()):e.load().catch((()=>{})))}),c),t=l((()=>this._arcadeContextInfo),(e=>{null!=this._expressionsManager&&(this._expressionsManager.arcadeContextInfo=e,this._evaluateExpressions((e=>e.evaluateAll())))})),n=l((()=>this.layer),(e=>{const t="subtype-sublayer"===e?.type?e.parent:"feature"===e?.type?e:null;t&&this.addResolvingPromise(F.createLoadedLayerContingentValuesCache(t).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.addHandles([e,t,n])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this.highlightHelper?.removeAll(),this._updatingHandles.destroy()}get _expressionInfosLookup(){return new Map(this.formTemplate?.expressionInfos?.map((e=>[e.name,e])))}get activeAssociationInput(){return this.allAssociationInputs.find((e=>e.uid===this.associationId))}get activeRelationshipInput(){return this.allRelationshipInputs.find((e=>e.relationshipId===this.relationshipId||e.activeCategory||e.showAllEnabled))}get _arcadeContextInfo(){const{_initialFeature:e,arcadeEditType:t,layer:n,map:s,spatialReference:i,timeZone:o}=this;return{layer:C(n)?n:null,originalFeature:e,editType:t,map:s,spatialReference:i,timeZone:o}}get associationId(){return this._get("associationId")}set associationId(e){null==e&&this.activeAssociationInput?.viewModel&&(this.activeAssociationInput.associatedLayer=null,this.activeAssociationInput.viewModel.activeAssociationType=null),this._set("associationId",e)}get associatedLayer(){return this.activeAssociationInput?.associatedLayer}set associatedLayer(e){this.activeAssociationInput&&(this.activeAssociationInput.associatedLayer=e)}get allAssociationInputs(){return A(this.inputs)}get allFieldInputs(){return j(this.inputs)}get allGroupInputs(){return this.inputs.filter(T)}get allRelationshipInputs(){return M(this.inputs)}get _layerFieldsByName(){return new Map(this.layer?.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){const t=this._get("feature");this._featureClone=e?e.clone():$.clone(),this._initialFeature=this._featureClone.clone(),this._expressionsManager&&(this._expressionsManager.feature=this._featureClone),e?(this._resetFieldInputValues(this._featureClone),this.allRelationshipInputs.forEach((t=>t.feature=e))):(this.inputs.forEach((e=>e.destroy())),this.inputs.length=0),t!==e&&(this.pendingSubtypeChoice=null),this.contingencyConstraintViolations.clear(),this._set("feature",e)}get fieldsWithContingentValues(){if(null==this._contingentValuesCache)return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get formDescription(){const{formTemplate:e,layer:t}=this;return e?.description&&t?k({label:e.description,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formTitle(){const{formTemplate:e,layer:t}=this;return e?.title&&t?k({label:e.title,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formHeaderVisible(){const{activeRelationshipInput:e,activeAssociationInput:t,formDescription:n,formTitle:s}=this;return!(e||t||!n&&!s)}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){this._override("layer",e)}get relationshipId(){return this._get("relationshipId")}set relationshipId(e){const t=this.allRelationshipInputs;if(null!=e&&e===this.relationshipId||t.forEach((e=>{e.showAllEnabled=!1,e.activeCategory=null})),null!=e){const n=t.find((t=>t.relationshipId===e));n&&(n.showAllEnabled=!0)}this._set("relationshipId",e)}get spatialReference(){return this.layer?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){return this.layer?.loaded?"ready":"disabled"}get submittable(){return!!this.valid||this.allFieldInputs.filter((e=>!e.valid)).every((({submittable:e})=>e))}get timeZone(){const{layer:e}=this;if(e&&"datesInUnknownTimezone"in e&&e.datesInUnknownTimezone)return b;const t=e&&"preferredTimeZone"in e&&e.preferredTimeZone;return this._timeZone===V?t||b:this._timeZone||w}set timeZone(e){this._timeZone=e}get updating(){return this._updatingHandles.updating}get valid(){const e=this.allFieldInputs;return e.length>0&&e.every((({valid:e})=>e))}findField(e){return this.allFieldInputs.find((t=>t.name===e))}getFieldValueOptionsForField(e,t){const n=this.findField(e);if(!n)return[[],[],[]];const s="coded-value"===n.domain?.type?n.domain.codedValues.map((({name:e,code:t})=>({name:e,value:t}))):[],i=null==n.value||s.some((e=>e.value===n.value))?[]:[{name:`${n.value}`,value:n.value}],o=this.fieldsWithContingentValues.has(e)?this._getContingentValueOptionsForField(e,t):[];if(o.length>0){const e=new Set(o.map((e=>e.value)));return[o,s.filter((t=>!e.has(t.value))),i]}return[s,[],i]}getValue(e){const t=this.layer?.getField(e);if(null!=t)return this._featureClone.getAttribute(t.name)??null}setValue(e,t){const{_featureClone:n,strict:s}=this,i=this.findField(e);t=""===t?null:t,i&&n.getAttribute(e)!==t&&(i.value=t,s&&!i.valid||(this._afterValueChange(i),this._evaluateExpressions((t=>t.evaluateInvalidated([e])))))}getValues(){return{...this._featureClone.attributes}}overrideInitialFeature(e){this._initialFeature=e}submit(){const e=this.allFieldInputs,t=new Set(e.filter((e=>e.valid)).map((({name:e})=>e))),n=e.filter((e=>!e.valid)).map((({name:e})=>e)),s=this.getValues();if(this.validateContingencyConstraints(s,{includeIncompleteViolations:!0}).length>0)for(const[i,o]of this.contingencyConstraintViolations.entries())"error"===o.type&&(t.delete(i),n.push(i));this.notifyChange("submittable"),this.notifyChange("valid"),this.emit("submit",{valid:[...t],invalid:n,values:s})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,s=new Map;if(this.contingencyConstraintViolations=s,null==n)return[];const{invalid:i,incomplete:o}=n.validateContingencyConstraints(e),r=[...i,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)s.set(e,a);return r}notifyFeatureGeometryChanged(){const{feature:e,_featureClone:t}=this;e&&(t.geometry=e.geometry,this._evaluateExpressions((e=>e.evaluateInvalidatedByGeometry())))}applySubtypeDefaults(e){const{defaultValues:t}=e,{allFieldInputs:n}=this;for(const{name:s}of n){const e=t[s];null!=e&&this.setValue(s,e)}}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}async _evaluateExpressions(e){const t=this._expressionsManager;null!=t&&await this._updatingHandles.addPromise(e(t).finally((()=>this._afterExpressionsEvaluated())))}async _updateInputsUsingFormElements(e,t,n){const s=new Map;for(const r of e)if(T(r)){s.set(r.element,r);for(const e of r.inputs)e.element&&s.set(e.element,e)}else r.element&&s.set(r.element,r);const i=new Map,o=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:s,updatedElements:t.filter(Q),sharedInitializationProperties:n,group:null,newExpressionExecutorPromises:i});for(const[r,a]of s.entries())s.delete(r),a.destroy();return await Promise.all(Array.from(i.values())),o}async _updateInputsUsingFormElementsRecursive(e){const{existingInputsByElement:t,updatedElements:n,sharedInitializationProperties:s,group:i,newExpressionExecutorPromises:o}=e,r=[];for(const a of n){const e=t.has(a),n=e?t.get(a):g(a)?await this._makeUtilityNetworkAssociationInputFromElement(a,s,i):this._makeInputFromElement(a,s,i);if(n){if(r.push(n),await u((()=>!n.updating)),this._assignExpressionExecutors(n,a,o),e)if(t.delete(a),T(n)){const{feature:e,timeZone:t}=s;n.set({feature:e,timeZone:t})}else if(N(n)){const e=this.relationshipId===a.relationshipId;n.set(s),n.set({map:this.map,showAllEnabled:e})}else g(n)?(n.set(s),n.set({map:this.map})):n.set(s);if(_(a)){const e=a.elements.filter((e=>Q(e)));n.inputs=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:t,updatedElements:e,sharedInitializationProperties:s,group:n,newExpressionExecutorPromises:o})}}}return r}_updateInputsUsingLayerFields(e,t,n){if(!Array.isArray(t))return Y().warn(this.declaredClass,"No attribute fields found."),[];const s=new Map;for(const o of e)if(T(o)){for(const e of o.inputs)e.destroy();o.inputs.length=0,o.destroy()}else N(o)?o.destroy():L(o)&&(null!==o.element?o.destroy():s.set(o.field,o));const i=[];for(const o of t){const e=n.feature?.getAttribute(o.name)??null,t=s.get(o)??new Z({field:o,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden});i.push(t.set({...n,value:e})),s.delete(o)}for(const[o,r]of s.entries())s.delete(o),r.destroy();return i}_resetFieldInputValues(e){for(const t of this.allFieldInputs)t.value=e.getAttribute(t.name)}_makeInputFromElement(e,t,s){return _(e)?X(e,t):v(e)?this._makeFieldInputFromElement(e,t,s):I(e)?this._makeRelationshipInputFromElement(e,t,s):g(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):x(e)?ee(e,t):g(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):n()}_makeFieldInputFromElement(e,t,n){const{arcadeEditType:s,feature:i,initialFeature:o,layer:r,timeZone:a}=t,{fieldName:l}=e,u=l&&this._layerFieldsByName.get(l);return u?new Z({arcadeEditType:s,element:e,field:u,value:i?.getAttribute(e.fieldName)??null,feature:i,initialFeature:o,layer:r,group:n,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden,timeZone:a}):null}_makeRelationshipInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t,a=new O({element:e,feature:i,group:n,layer:o,map:s,timeZone:r});return a.addHandles(p((()=>a.relatedLayer),"edits",(()=>this._evaluateExpressions((e=>e.evaluateAsyncExpressions()))))),a}async _makeUtilityNetworkAssociationInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t;return new(0,(await import("./UtilityNetworkAssociationInput.js")).default)({element:e,feature:i,group:n,layer:o,map:s,timeZone:r})}_assignExpressionExecutors(e,t,n){const s=D[t.type],i=[];for(const o of s){const s=`${o}Executor`;if(e[s]){this._useExecutor(e[s]);continue}const r=t[o];if(null!=r&&""!==r){const t=this._expressionInfosLookup.get(r)?.expression??r;i.push(this._getOrCreateExecutorForExpression(t,n).then((t=>{e[s]=this._useExecutor(t)})))}}return R(e)&&i.push(...this._assignTextElementExpressionExecutors(e,n)),i}_assignTextElementExpressionExecutors(e,t){const{_expressionInfosLookup:n}=this,s=[];for(const o of e.expressionsUsed){const r=n.get(o);null!=r?s.push(this._getOrCreateExecutorForExpression(r.expression,t).then((t=>e.setExpressionExecutor(o,this._useExecutor(t))))):i.getLogger(this).error("feature-form:expression-not-found",`Could not find expressionInfo object with name '${o}'`)}for(const i of e.fieldsUsed){const n=`return $feature['${i}'];`;s.push(this._getOrCreateExecutorForExpression(n,t).then((t=>e.setFieldExecutor(i,this._useExecutor(t)))))}return s}async _getOrCreateExecutorForExpression(e,t){const{_expressionExecutorLookup:n}=this;if(n.has(e))return n.get(e);if(t.has(e))return t.get(e);const s=G(e,this.layer);t.set(e,s);const i=await s;return n.set(e,i),i}_createExpressionsManager(e){const{_arcadeContextInfo:t,_featureClone:n,allFieldInputs:s,formTemplate:i}=this;this._expressionsManager=new H({executors:e,feature:n,arcadeContextInfo:t,fieldInputs:s,preserveFieldValuesWhenHidden:!0===i?.preserveFieldValuesWhenHidden})}async _startExpressions(){if(0===this._expressionExecutorsInUse.size)return;const e=Array.from(this._expressionExecutorsInUse);this._createExpressionsManager(e),this._evaluateExpressions((e=>e.evaluateAll()))}_stopExpressions(){this._expressionsManager=o(this._expressionsManager),this._expressionExecutorsInUse.clear()}_useExecutor(e){return this._expressionExecutorsInUse.add(e),e}_afterValueChange(e){const{name:t,value:n}=e,{_featureClone:s,formTemplate:i,layer:o}=this;if(!o)return;const r=s.getAttribute(t);s.setAttribute(t,n);const{typeFieldName:a,types:l}=S(o);if((e.isSubtypeField||t===a)&&n!==r){if("subtype-sublayer"===o.type){const e=o.parent?.findSublayerForFeature(s);e&&(this.feature&&(this.feature.sourceLayer=e),s.sourceLayer=e)}const e=new Set;for(const t of l)if(t.domains&&"object"==typeof t.domains)for(const n of Object.keys(t.domains))e.add(n);for(const t of e){const e=this.findField(t);e&&e.notifyChange("domain")}this.notifyChange("joinedContingentValues")}if(null!=i){const{description:e,title:n}=i;n&&h(n,t)&&this.notifyChange("formTitle"),e&&h(e,t)&&this.notifyChange("formDescription")}this._emitChangeEvent(e)}_afterExpressionsEvaluated(){const{_featureClone:e}=this;for(const t of this.allFieldInputs)t.value!==e.getAttribute(t.name)&&this._afterValueChange(t)}_joinContingentValues(){const e=this._contingentValuesCache;if(null==e)return[];const{typeFieldName:t}=S(this.layer),n=t?this.getValue(t):null,s=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:i}=r,o=[];for(const s of e)s.isRetired||null!=s.subtype&&s.subtype.code!==n||o.push({values:s.values});o.length>0&&s.push({name:i,fields:t,contingencies:o})}const[i,o]=this._generateJoinPlan(s);return[...i.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],s=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const i=t.get(e),o=l,r=[i.name,o.name].sort().join("|");if(s.has(r))continue;n.push([i,o]),s.add(r),t.set(e,o)}else t.set(e,l);const i=new Set(n.flat()),o=new Set(e);for(const l of i)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),s=r.get(t);for(const i of s)n.add(i),a.set(i,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let s=t.shift(),i=this._generateJoinKey(n.fields,s.fields),o=new Set([...n.fields,...s.fields]),r=new Map;for(const l of n.contingencies){const[e]=this._hashContingency(l,i.codedValueFields,!0);r.has(e)?r.get(e)?.push(l):r.set(e,[l])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of s.contingencies){const[n,s]=this._hashContingency(t,i.codedValueFields),o=s?this._findMatchingContingenciesWithAnyHashMask(r,n):r.get(n);if(r.has(J)&&o?.push(...this._findMatchingContingenciesContainingAny(t,r.get(J),i.codedValueFields)),null!=o)for(const r of o){const n=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(r,t,i.rangeFields):this._joinContingencies(r,t);if(null==n)break;const[s]=this._hashContingency(n,a.codedValueFields,!0);e.has(s)?e.get(s)?.push(n):e.set(s,[n])}}r=e,s=n,i=a,o=new Set([...o,...s.fields])}const a=[];for(const l of s.contingencies){const[e,t]=this._hashContingency(l,i.codedValueFields),n=t?this._findMatchingContingenciesWithAnyHashMask(r,e):r.get(e);if(r.has(J)&&n.push(...this._findMatchingContingenciesContainingAny(l,r.get(J),i.codedValueFields)),null!=n)for(const s of n){const e=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(s,l,i.rangeFields):this._joinContingencies(s,l);null!=e&&a.push(e)}}return a}_joinContingencies(e,t){const n={values:{...e.values,...t.values}};for(const[s,i]of Object.entries(n.values))"any"===i.objectType&&null!=e.values[s]&&(n.values[s]=e.values[s]);return n}_joinContingenciesWithRangeDomains(e,t,n){const s=this._joinContingencies(e,t);for(const i of n){const n=e.values[i],o=t.values[i],{leftIsNull:r,rightIsNull:a,bothAreNull:l,leftIsAny:u,rightIsAny:p,bothAreAny:c,leftIsRange:h,rightIsRange:d}=this._compareObjectTypes(n.objectType,o.objectType);if(l||c)continue;if(r&&p||a&&u){s.values[i]=new E({objectType:"null"});continue}if(r&&d||a&&h)return null;u?(n.minValue=-1/0,n.maxValue=1/0):p&&(o.minValue=-1/0,o.maxValue=1/0);const f=Math.max(n.minValue,o.minValue),m=Math.min(n.maxValue,o.maxValue);if(f>m)return null;s.values[i]=new E({objectType:"range",minValue:f,maxValue:m})}return s}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const s=t.values[n],i=e.values[n];return"any"===s.objectType||"any"===i.objectType||s.codedValue?.code===i.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),s=[];for(const[i,o]of e){if(i===J)break;n.test(i)&&s.push(...o)}return s}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,s=Array.isArray(t)?new Set(t):t,i=n.size<s.size?n:s,o=i===n?s:n,{feature:r}=this,a=new Set,l=new Set;for(const u of i)if(o.has(u)){const e=this.layer?.getFieldDomain(u,{feature:r??void 0,excludeImpliedDomains:!0});if(null==e)continue;switch(e.type){case"coded-value":a.add(u);break;case"range":l.add(u)}}return{codedValueFields:[...a],rangeFields:[...l]}}_contingencyIsValid(e,t){const n={};for(const{name:s,value:i}of this.allFieldInputs)this.fieldsWithContingentValues.has(s)&&null!=i&&s!==e&&(n[s]=i);return Object.entries(n).every((([e,n])=>!t.values.hasOwnProperty(e)||U(n,t.values[e])))}_getContingentValueOptionsForField(e,t){const n=this.joinedContingentValues.slice(),s=new Map,i={code:"",name:t??"No value"};for(const o of n){const t=o.values[e];if("code"===t?.objectType||"null"===t?.objectType){const{code:n,name:r}=t.codedValue&&"null"!==t.objectType?t.codedValue:i;!s.has(n)&&this._contingencyIsValid(e,o)&&s.set(n,{name:r,value:n})}}return[...s.values()]}_hashContingency(e,t,n=!1){if(t.length<1)return[z,!1];const s=[];let i=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[J,!0];i=!0,s.push(`${o}:.*`)}else"null"===t.objectType?s.push(`${o}:${B}`):s.push(`${o}:${t.codedValue?.code}`)}return[s.sort().join("&"),i]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}get test(){return{featureClone:this._featureClone}}};function Q(e){return"field"===e.type||"group"===e.type||"relationship"===e.type||"text"===e.type||"utilityNetworkAssociations"===e.type||(Y().warn("form-info::unsupported-element-type","Only element types 'field', 'group' and 'relationship' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}function X(e,t){const{feature:n,layer:s}=t;return new P({element:e,inputs:[],feature:n,layer:s})}function ee(e,t,n=null){const{feature:s,layer:i,timeZone:o}=t;return new W({element:e,feature:s,group:n,layer:i,timeZone:o})}e([d()],q.prototype,"_expressionInfosLookup",null),e([d()],q.prototype,"_featureClone",void 0),e([d()],q.prototype,"_timeZone",void 0),e([d()],q.prototype,"activeAssociation",void 0),e([d()],q.prototype,"activeAssociationInput",null),e([d()],q.prototype,"activeRelationshipInput",null),e([d()],q.prototype,"_arcadeContextInfo",null),e([d()],q.prototype,"associationId",null),e([d()],q.prototype,"associatedLayer",null),e([d()],q.prototype,"allAssociationInputs",null),e([d()],q.prototype,"allFieldInputs",null),e([d()],q.prototype,"allGroupInputs",null),e([d()],q.prototype,"allRelationshipInputs",null),e([d()],q.prototype,"_layerFieldsByName",null),e([d()],q.prototype,"arcadeEditType",void 0),e([d()],q.prototype,"contingencyConstraintViolations",void 0),e([d()],q.prototype,"disabled",void 0),e([d()],q.prototype,"feature",null),e([d()],q.prototype,"fieldsWithContingentValues",null),e([d({type:y})],q.prototype,"formTemplate",null),e([d()],q.prototype,"formDescription",null),e([d()],q.prototype,"formTitle",null),e([d()],q.prototype,"formHeaderVisible",null),e([d()],q.prototype,"highlightHelper",void 0),e([d()],q.prototype,"inputs",void 0),e([d()],q.prototype,"joinedContingentValues",null),e([d()],q.prototype,"layer",null),e([d()],q.prototype,"map",void 0),e([d()],q.prototype,"callbacks",void 0),e([d()],q.prototype,"relationshipId",null),e([d()],q.prototype,"spatialReference",null),e([d()],q.prototype,"state",null),e([d()],q.prototype,"strict",void 0),e([d()],q.prototype,"submittable",null),e([d()],q.prototype,"timeZone",null),e([d()],q.prototype,"updating",null),e([d()],q.prototype,"valid",null),e([d()],q.prototype,"pendingSubtypeChoice",void 0),e([d()],q.prototype,"getValues",null),e([d()],q.prototype,"submit",null),e([d()],q.prototype,"test",null),q=e([f(K)],q);const te=q;export{te as default};
|
|
5
|
+
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{neverReached as n}from"../../core/compilerUtils.js";import s from"../../core/Evented.js";import i from"../../core/Logger.js";import{destroyMaybe as o}from"../../core/maybe.js";import r from"../../core/Promise.js";import{debounce as a}from"../../core/promiseUtils.js";import{watch as l,whenOnce as u,on as p,syncAndInitial as c}from"../../core/reactiveUtils.js";import{templateHasKey as h}from"../../core/string.js";import{property as d}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as f}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as m}from"../../core/support/UpdatingHandles.js";import y from"../../form/FormTemplate.js";import{isUtilityNetworkAssociationsElement as g,isGroupElement as _,isFieldElement as v,isRelationshipElement as I,isTextElement as E}from"../../form/support/formUtils.js";import x from"../../layers/support/ContingentValue.js";import{isEditableLayer as C}from"../../layers/support/editableLayers.js";import F from"../../layers/support/LayerContingentValuesCache.js";import{utc as b,unknown as V,system as w}from"../../time/constants.js";import{flattenAssociationInputs as A,flattenFieldInputs as j,isGroupInput as T,flattenRelationshipInputs as M,parseFormTemplateString as k,isRelationshipInput as N,isFieldInput as S,isTextElementInput as L,getNormalizedFeatureTypeInfo as R,valueIsValidContingentValue as U}from"./featureFormUtils.js";import Z from"./FieldInput.js";import{FormExpressionsManager as H}from"./FormExpressionsManager.js";import P from"./GroupInput.js";import O from"./RelationshipInput.js";import W from"./TextElementInput.js";import{createFormExpressionArcadeExecutor as G}from"../support/forms/expressions/FormExpressionArcadeExecutor.js";const $=new t({attributes:{}}),D={field:["editableExpression","requiredExpression","valueExpression","visibilityExpression"],group:["visibilityExpression"],relationship:["editableExpression","visibilityExpression"],text:["visibilityExpression"],utilityNetworkAssociations:["editableExpression","visibilityExpression"]},z="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",J="#JSAPI_CONTINGENT_VALUE_ANY_HASH",B="#JSAPI_CONTINGENT_VALUE_NULL_HASH";let K=class extends(r.EsriPromiseMixin(s.EventedAccessor)){constructor(e){super(e),this._expressionExecutorsInUse=new Set,this._expressionExecutorLookup=new Map,this._expressionsManager=null,this._contingentValuesCache=null,this._featureClone=$.clone(),this._initialFeature=$.clone(),this._timeZone=null,this._updatingHandles=new m,this.activeAssociation=null,this.arcadeEditType="NA",this.contingencyConstraintViolations=new Map,this.disabled=!1,this.highlightHelper=null,this.inputs=[],this.map=null,this.callbacks=null,this.strict=!1,this.pendingSubtypeChoice=null,this._updateInputs=a((async()=>{this._stopExpressions();const{_featureClone:e,_initialFeature:t,arcadeEditType:n,formTemplate:s,inputs:i,layer:o,timeZone:r}=this;if(!o)return;const a={arcadeEditType:n,feature:e,initialFeature:t,layer:o,timeZone:r},l=i.slice(),u=s?.elements&&s.elements.length>0?await this._updateInputsUsingFormElements(l,s.elements,a):this._updateInputsUsingLayerFields(l,o?.fields,a);this.inputs=u,await this._startExpressions()}))}initialize(){const e=l((()=>[this.layer,!!this.layer?.loaded,this.formTemplate,this.feature,this.timeZone,this.arcadeEditType]),(([e,t])=>{null!=e&&(t?this._updatingHandles.addPromise(this._updateInputs()):e.load().catch((()=>{})))}),c),t=l((()=>this._arcadeContextInfo),(e=>{null!=this._expressionsManager&&(this._expressionsManager.arcadeContextInfo=e,this._evaluateExpressions((e=>e.evaluateAll())))})),n=l((()=>this.layer),(e=>{const t="subtype-sublayer"===e?.type?e.parent:"feature"===e?.type?e:null;t&&this.addResolvingPromise(F.createLoadedLayerContingentValuesCache(t).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.addHandles([e,t,n])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this.highlightHelper?.removeAll(),this._updatingHandles.destroy()}get _expressionInfosLookup(){return new Map(this.formTemplate?.expressionInfos?.map((e=>[e.name,e])))}get activeAssociationInput(){return this.allAssociationInputs.find((e=>e.uid===this.associationId))}get activeRelationshipInput(){return this.allRelationshipInputs.find((e=>e.relationshipId===this.relationshipId||e.activeCategory||e.showAllEnabled))}get _arcadeContextInfo(){const{_initialFeature:e,arcadeEditType:t,layer:n,map:s,spatialReference:i,timeZone:o}=this;return{layer:C(n)?n:null,originalFeature:e,editType:t,map:s,spatialReference:i,timeZone:o}}get associationId(){return this._get("associationId")}set associationId(e){null==e&&this.activeAssociationInput?.viewModel&&(this.activeAssociationInput.associatedLayer=null,this.activeAssociationInput.viewModel.activeAssociationType=null),this._set("associationId",e)}get associatedLayer(){return this.activeAssociationInput?.associatedLayer}set associatedLayer(e){this.activeAssociationInput&&(this.activeAssociationInput.associatedLayer=e)}get allAssociationInputs(){return A(this.inputs)}get allFieldInputs(){return j(this.inputs)}get allGroupInputs(){return this.inputs.filter(T)}get allRelationshipInputs(){return M(this.inputs)}get _layerFieldsByName(){return new Map(this.layer?.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){const t=this._get("feature");this._featureClone=e?e.clone():$.clone(),this._initialFeature=this._featureClone.clone(),this._expressionsManager&&(this._expressionsManager.feature=this._featureClone),e?(this._resetFieldInputValues(this._featureClone),this.allRelationshipInputs.forEach((t=>t.feature=e))):(this.inputs.forEach((e=>e.destroy())),this.inputs.length=0),t!==e&&(this.pendingSubtypeChoice=null),this.contingencyConstraintViolations.clear(),this._set("feature",e)}get fieldsWithContingentValues(){if(null==this._contingentValuesCache)return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get formDescription(){const{formTemplate:e,layer:t}=this;return e?.description&&t?k({label:e.description,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formTitle(){const{formTemplate:e,layer:t}=this;return e?.title&&t?k({label:e.title,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formHeaderVisible(){const{activeRelationshipInput:e,activeAssociationInput:t,formDescription:n,formTitle:s}=this;return!(e||t||!n&&!s)}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){this._override("layer",e)}get relationshipId(){return this._get("relationshipId")}set relationshipId(e){const t=this.allRelationshipInputs;if(null!=e&&e===this.relationshipId||t.forEach((e=>{e.showAllEnabled=!1,e.activeCategory=null})),null!=e){const n=t.find((t=>t.relationshipId===e));n&&(n.showAllEnabled=!0)}this._set("relationshipId",e)}get spatialReference(){return this.layer?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){return this.layer?.loaded?"ready":"disabled"}get submittable(){return!!this.valid||this.allFieldInputs.filter((e=>!e.valid)).every((({submittable:e})=>e))}get timeZone(){const{layer:e}=this;if(e&&"datesInUnknownTimezone"in e&&e.datesInUnknownTimezone)return b;const t=e&&"preferredTimeZone"in e&&e.preferredTimeZone;return this._timeZone===V?t||b:this._timeZone||w}set timeZone(e){this._timeZone=e}get updating(){return this._updatingHandles.updating}get valid(){const e=this.allFieldInputs;return e.length>0&&e.every((({valid:e})=>e))}findField(e){return this.allFieldInputs.find((t=>t.name===e))}getFieldValueOptionsForField(e,t){const n=this.findField(e);if(!n)return[[],[],[]];const s="coded-value"===n.domain?.type?n.domain.codedValues.map((({name:e,code:t})=>({name:e,value:t}))):[],i=null==n.value||s.some((e=>e.value===n.value))?[]:[{name:`${n.value}`,value:n.value}],o=this.fieldsWithContingentValues.has(e)?this._getContingentValueOptionsForField(e,t):[];if(o.length>0){const e=new Set(o.map((e=>e.value)));return[o,s.filter((t=>!e.has(t.value))),i]}return[s,[],i]}getValue(e){const t=this.layer?.getField(e);if(null!=t)return this._featureClone.getAttribute(t.name)??null}setValue(e,t){const{_featureClone:n,strict:s}=this,i=this.findField(e);t=""===t?null:t,i&&n.getAttribute(e)!==t&&(i.value=t,s&&!i.valid||(this._afterValueChange(i),this._evaluateExpressions((t=>t.evaluateInvalidated([e])))))}getValues(){return{...this._featureClone.attributes}}overrideInitialFeature(e){this._initialFeature=e}submit(){const e=this.allFieldInputs,t=new Set(e.filter((e=>e.valid)).map((({name:e})=>e))),n=e.filter((e=>!e.valid)).map((({name:e})=>e)),s=this.getValues();if(this.validateContingencyConstraints(s,{includeIncompleteViolations:!0}).length>0)for(const[i,o]of this.contingencyConstraintViolations.entries())"error"===o.type&&(t.delete(i),n.push(i));this.notifyChange("submittable"),this.notifyChange("valid"),this.emit("submit",{valid:[...t],invalid:n,values:s})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,s=new Map;if(this.contingencyConstraintViolations=s,null==n)return[];const{invalid:i,incomplete:o}=n.validateContingencyConstraints(e),r=[...i,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)s.set(e,a);return r}notifyFeatureGeometryChanged(){const{feature:e,_featureClone:t}=this;e&&(t.geometry=e.geometry,this._evaluateExpressions((e=>e.evaluateInvalidatedByGeometry())))}applySubtypeDefaults(e){const{defaultValues:t}=e,{allFieldInputs:n}=this;for(const{name:s}of n){const e=t[s];null!=e&&this.setValue(s,e)}}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}async _evaluateExpressions(e){const t=this._expressionsManager;null!=t&&await this._updatingHandles.addPromise(e(t).finally((()=>this._afterExpressionsEvaluated())))}async _updateInputsUsingFormElements(e,t,n){const s=new Map;for(const r of e)if(T(r)){s.set(r.element,r);for(const e of r.inputs)e.element&&s.set(e.element,e)}else r.element&&s.set(r.element,r);const i=new Map,o=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:s,updatedElements:t.filter((e=>this._isSupportedElement(e))),sharedInitializationProperties:n,group:null,newExpressionExecutorPromises:i});for(const[r,a]of s.entries())s.delete(r),a.destroy();return await Promise.all(Array.from(i.values())),o}async _updateInputsUsingFormElementsRecursive(e){const{existingInputsByElement:t,updatedElements:n,sharedInitializationProperties:s,group:i,newExpressionExecutorPromises:o}=e,r=[];for(const a of n){const e=t.has(a),n=e?t.get(a):g(a)?await this._makeUtilityNetworkAssociationInputFromElement(a,s,i):this._makeInputFromElement(a,s,i);if(n){if(r.push(n),await u((()=>!n.updating)),this._assignExpressionExecutors(n,a,o),e)if(t.delete(a),T(n)){const{feature:e,timeZone:t}=s;n.set({feature:e,timeZone:t})}else if(N(n)){const e=this.relationshipId===a.relationshipId;n.set(s),n.set({map:this.map,showAllEnabled:e})}else g(n)?(n.set(s),n.set({map:this.map})):n.set(s);if(_(a)){const e=a.elements.filter((e=>this._isSupportedElement(e)));n.inputs=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:t,updatedElements:e,sharedInitializationProperties:s,group:n,newExpressionExecutorPromises:o})}}}return r}_updateInputsUsingLayerFields(e,t,n){if(!Array.isArray(t))return i.getLogger(this).warn(this.declaredClass,"No attribute fields found."),[];const s=new Map;for(const i of e)if(T(i)){for(const e of i.inputs)e.destroy();i.inputs.length=0,i.destroy()}else N(i)?i.destroy():S(i)&&(null!==i.element?i.destroy():s.set(i.field,i));const o=[];for(const i of t){const e=n.feature?.getAttribute(i.name)??null,t=s.get(i)??new Z({field:i,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden});o.push(t.set({...n,value:e})),s.delete(i)}for(const[i,r]of s.entries())s.delete(i),r.destroy();return o}_resetFieldInputValues(e){for(const t of this.allFieldInputs)t.value=e.getAttribute(t.name)}_makeInputFromElement(e,t,s){return _(e)?Y(e,t):v(e)?this._makeFieldInputFromElement(e,t,s):I(e)?this._makeRelationshipInputFromElement(e,t,s):g(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):E(e)?q(e,t):g(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):n()}_makeFieldInputFromElement(e,t,n){const{arcadeEditType:s,feature:i,initialFeature:o,layer:r,timeZone:a}=t,{fieldName:l}=e,u=l&&this._layerFieldsByName.get(l);return u?new Z({arcadeEditType:s,element:e,field:u,value:i?.getAttribute(e.fieldName)??null,feature:i,initialFeature:o,layer:r,group:n,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden,timeZone:a}):null}_makeRelationshipInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t,a=new O({element:e,feature:i,group:n,layer:o,map:s,timeZone:r});return a.addHandles(p((()=>a.relatedLayer),"edits",(()=>this._evaluateExpressions((e=>e.evaluateAsyncExpressions()))))),a}async _makeUtilityNetworkAssociationInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t;return new(0,(await import("./UtilityNetworkAssociationInput.js")).default)({element:e,feature:i,group:n,layer:o,map:s,timeZone:r})}_assignExpressionExecutors(e,t,n){const s=D[t.type],i=[];for(const o of s){const s=`${o}Executor`;if(e[s]){this._useExecutor(e[s]);continue}const r=t[o];if(null!=r&&""!==r){const t=this._expressionInfosLookup.get(r)?.expression??r;i.push(this._getOrCreateExecutorForExpression(t,n).then((t=>{e[s]=this._useExecutor(t)})))}}return L(e)&&i.push(...this._assignTextElementExpressionExecutors(e,n)),i}_assignTextElementExpressionExecutors(e,t){const{_expressionInfosLookup:n}=this,s=[];for(const o of e.expressionsUsed){const r=n.get(o);null!=r?s.push(this._getOrCreateExecutorForExpression(r.expression,t).then((t=>e.setExpressionExecutor(o,this._useExecutor(t))))):i.getLogger(this).error("feature-form:expression-not-found",`Could not find expressionInfo object with name '${o}'`)}for(const i of e.fieldsUsed){const n=`return $feature['${i}'];`;s.push(this._getOrCreateExecutorForExpression(n,t).then((t=>e.setFieldExecutor(i,this._useExecutor(t)))))}return s}async _getOrCreateExecutorForExpression(e,t){const{_expressionExecutorLookup:n}=this;if(n.has(e))return n.get(e);if(t.has(e))return t.get(e);const s=G(e,this.layer);t.set(e,s);const i=await s;return n.set(e,i),i}_createExpressionsManager(e){const{_arcadeContextInfo:t,_featureClone:n,allFieldInputs:s,formTemplate:i}=this;this._expressionsManager=new H({executors:e,feature:n,arcadeContextInfo:t,fieldInputs:s,preserveFieldValuesWhenHidden:!0===i?.preserveFieldValuesWhenHidden})}async _startExpressions(){if(0===this._expressionExecutorsInUse.size)return;const e=Array.from(this._expressionExecutorsInUse);this._createExpressionsManager(e),this._evaluateExpressions((e=>e.evaluateAll()))}_stopExpressions(){this._expressionsManager=o(this._expressionsManager),this._expressionExecutorsInUse.clear()}_useExecutor(e){return this._expressionExecutorsInUse.add(e),e}_afterValueChange(e){const{name:t,value:n}=e,{_featureClone:s,formTemplate:i,layer:o}=this;if(!o)return;const r=s.getAttribute(t);s.setAttribute(t,n);const{typeFieldName:a,types:l}=R(o);if((e.isSubtypeField||t===a)&&n!==r){if("subtype-sublayer"===o.type){const e=o.parent?.findSublayerForFeature(s);e&&(this.feature&&(this.feature.sourceLayer=e),s.sourceLayer=e)}const e=new Set;for(const t of l)if(t.domains&&"object"==typeof t.domains)for(const n of Object.keys(t.domains))e.add(n);for(const t of e){const e=this.findField(t);e&&e.notifyChange("domain")}this.notifyChange("joinedContingentValues")}if(null!=i){const{description:e,title:n}=i;n&&h(n,t)&&this.notifyChange("formTitle"),e&&h(e,t)&&this.notifyChange("formDescription")}this._emitChangeEvent(e)}_afterExpressionsEvaluated(){const{_featureClone:e}=this;for(const t of this.allFieldInputs)t.value!==e.getAttribute(t.name)&&this._afterValueChange(t)}_joinContingentValues(){const e=this._contingentValuesCache;if(null==e)return[];const{typeFieldName:t}=R(this.layer),n=t?this.getValue(t):null,s=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:i}=r,o=[];for(const s of e)s.isRetired||null!=s.subtype&&s.subtype.code!==n||o.push({values:s.values});o.length>0&&s.push({name:i,fields:t,contingencies:o})}const[i,o]=this._generateJoinPlan(s);return[...i.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],s=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const i=t.get(e),o=l,r=[i.name,o.name].sort().join("|");if(s.has(r))continue;n.push([i,o]),s.add(r),t.set(e,o)}else t.set(e,l);const i=new Set(n.flat()),o=new Set(e);for(const l of i)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),s=r.get(t);for(const i of s)n.add(i),a.set(i,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let s=t.shift(),i=this._generateJoinKey(n.fields,s.fields),o=new Set([...n.fields,...s.fields]),r=new Map;for(const l of n.contingencies){const[e]=this._hashContingency(l,i.codedValueFields,!0);r.has(e)?r.get(e)?.push(l):r.set(e,[l])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of s.contingencies){const[n,s]=this._hashContingency(t,i.codedValueFields),o=s?this._findMatchingContingenciesWithAnyHashMask(r,n):r.get(n);if(r.has(J)&&o?.push(...this._findMatchingContingenciesContainingAny(t,r.get(J),i.codedValueFields)),null!=o)for(const r of o){const n=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(r,t,i.rangeFields):this._joinContingencies(r,t);if(null==n)break;const[s]=this._hashContingency(n,a.codedValueFields,!0);e.has(s)?e.get(s)?.push(n):e.set(s,[n])}}r=e,s=n,i=a,o=new Set([...o,...s.fields])}const a=[];for(const l of s.contingencies){const[e,t]=this._hashContingency(l,i.codedValueFields),n=t?this._findMatchingContingenciesWithAnyHashMask(r,e):r.get(e);if(r.has(J)&&n.push(...this._findMatchingContingenciesContainingAny(l,r.get(J),i.codedValueFields)),null!=n)for(const s of n){const e=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(s,l,i.rangeFields):this._joinContingencies(s,l);null!=e&&a.push(e)}}return a}_joinContingencies(e,t){const n={values:{...e.values,...t.values}};for(const[s,i]of Object.entries(n.values))"any"===i.objectType&&null!=e.values[s]&&(n.values[s]=e.values[s]);return n}_joinContingenciesWithRangeDomains(e,t,n){const s=this._joinContingencies(e,t);for(const i of n){const n=e.values[i],o=t.values[i],{leftIsNull:r,rightIsNull:a,bothAreNull:l,leftIsAny:u,rightIsAny:p,bothAreAny:c,leftIsRange:h,rightIsRange:d}=this._compareObjectTypes(n.objectType,o.objectType);if(l||c)continue;if(r&&p||a&&u){s.values[i]=new x({objectType:"null"});continue}if(r&&d||a&&h)return null;u?(n.minValue=-1/0,n.maxValue=1/0):p&&(o.minValue=-1/0,o.maxValue=1/0);const f=Math.max(n.minValue,o.minValue),m=Math.min(n.maxValue,o.maxValue);if(f>m)return null;s.values[i]=new x({objectType:"range",minValue:f,maxValue:m})}return s}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const s=t.values[n],i=e.values[n];return"any"===s.objectType||"any"===i.objectType||s.codedValue?.code===i.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),s=[];for(const[i,o]of e){if(i===J)break;n.test(i)&&s.push(...o)}return s}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,s=Array.isArray(t)?new Set(t):t,i=n.size<s.size?n:s,o=i===n?s:n,{feature:r}=this,a=new Set,l=new Set;for(const u of i)if(o.has(u)){const e=this.layer?.getFieldDomain(u,{feature:r??void 0,excludeImpliedDomains:!0});if(null==e)continue;switch(e.type){case"coded-value":a.add(u);break;case"range":l.add(u)}}return{codedValueFields:[...a],rangeFields:[...l]}}_contingencyIsValid(e,t){const n={};for(const{name:s,value:i}of this.allFieldInputs)this.fieldsWithContingentValues.has(s)&&null!=i&&s!==e&&(n[s]=i);return Object.entries(n).every((([e,n])=>!t.values.hasOwnProperty(e)||U(n,t.values[e])))}_getContingentValueOptionsForField(e,t){const n=this.joinedContingentValues.slice(),s=new Map,i={code:"",name:t??"No value"};for(const o of n){const t=o.values[e];if("code"===t?.objectType||"null"===t?.objectType){const{code:n,name:r}=t.codedValue&&"null"!==t.objectType?t.codedValue:i;!s.has(n)&&this._contingencyIsValid(e,o)&&s.set(n,{name:r,value:n})}}return[...s.values()]}_hashContingency(e,t,n=!1){if(t.length<1)return[z,!1];const s=[];let i=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[J,!0];i=!0,s.push(`${o}:.*`)}else"null"===t.objectType?s.push(`${o}:${B}`):s.push(`${o}:${t.codedValue?.code}`)}return[s.sort().join("&"),i]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}_isSupportedElement(e){return"field"===e.type||"group"===e.type||"relationship"===e.type||"text"===e.type||"utilityNetworkAssociations"===e.type||(i.getLogger(this).warn("form-info::unsupported-element-type","Only element types 'field', 'group' and 'relationship' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}get test(){return{featureClone:this._featureClone}}};function Y(e,t){const{feature:n,layer:s}=t;return new P({element:e,inputs:[],feature:n,layer:s})}function q(e,t,n=null){const{feature:s,layer:i,timeZone:o}=t;return new W({element:e,feature:s,group:n,layer:i,timeZone:o})}e([d()],K.prototype,"_expressionInfosLookup",null),e([d()],K.prototype,"_featureClone",void 0),e([d()],K.prototype,"_timeZone",void 0),e([d()],K.prototype,"activeAssociation",void 0),e([d()],K.prototype,"activeAssociationInput",null),e([d()],K.prototype,"activeRelationshipInput",null),e([d()],K.prototype,"_arcadeContextInfo",null),e([d()],K.prototype,"associationId",null),e([d()],K.prototype,"associatedLayer",null),e([d()],K.prototype,"allAssociationInputs",null),e([d()],K.prototype,"allFieldInputs",null),e([d()],K.prototype,"allGroupInputs",null),e([d()],K.prototype,"allRelationshipInputs",null),e([d()],K.prototype,"_layerFieldsByName",null),e([d()],K.prototype,"arcadeEditType",void 0),e([d()],K.prototype,"contingencyConstraintViolations",void 0),e([d()],K.prototype,"disabled",void 0),e([d()],K.prototype,"feature",null),e([d()],K.prototype,"fieldsWithContingentValues",null),e([d({type:y})],K.prototype,"formTemplate",null),e([d()],K.prototype,"formDescription",null),e([d()],K.prototype,"formTitle",null),e([d()],K.prototype,"formHeaderVisible",null),e([d()],K.prototype,"highlightHelper",void 0),e([d()],K.prototype,"inputs",void 0),e([d()],K.prototype,"joinedContingentValues",null),e([d()],K.prototype,"layer",null),e([d()],K.prototype,"map",void 0),e([d()],K.prototype,"callbacks",void 0),e([d()],K.prototype,"relationshipId",null),e([d()],K.prototype,"spatialReference",null),e([d()],K.prototype,"state",null),e([d()],K.prototype,"strict",void 0),e([d()],K.prototype,"submittable",null),e([d()],K.prototype,"timeZone",null),e([d()],K.prototype,"updating",null),e([d()],K.prototype,"valid",null),e([d()],K.prototype,"pendingSubtypeChoice",void 0),e([d()],K.prototype,"getValues",null),e([d()],K.prototype,"submit",null),e([d()],K.prototype,"test",null),K=e([f("esri.widgets.FeatureForm.FeatureFormViewModel")],K);const Q=K;export{Q as default};
|