@arcgis/core 5.2.0-next.97 → 5.2.0-next.99

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.
Files changed (68) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/{1201bb22a2bfd7d7ecba.js → 3c0421a4a0ee3a3c63f8.js} +1 -1
  3. package/assets/esri/core/workers/chunks/{d453627894e6e5b02023.js → 53a6bfebf3904dd7cad9.js} +1 -1
  4. package/assets/esri/core/workers/chunks/{ca8061e0a6d78d646ebf.js → 89234e3c7917f1befe10.js} +1 -1
  5. package/assets/esri/core/workers/chunks/8f53053d26210837ec34.js +1 -0
  6. package/assets/esri/core/workers/chunks/{6ceb17eada151230abf7.js → a88aa26a7bee1fe7aea2.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{5d6733dcee9c2ef00072.js → c511af7afe08a78e2a4d.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{6319413b89e23f671487.js → cf49a13522d61da31d8f.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{dd55737fba0a8fe68101.js → d7659d2b2aea0dd1202d.js} +3 -3
  10. package/assets/esri/core/workers/chunks/{5d7625eb9997cd0dff09.js → d785434bbeab89cd64ba.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{471027e4280bd51167b0.js → eb222dc01344ed07719e.js} +1 -1
  12. package/assets/esri/core/workers/chunks/efdb0bcdb8d547868ecb.js +1 -0
  13. package/assets/esri/core/workers/chunks/{374d726fdd0a9848cea5.js → f2cbcd1b0e77e733a8e0.js} +1 -1
  14. package/assets/esri/libs/librust-parquet/pkg/bundle_bg.wasm +0 -0
  15. package/chunks/GlobalIllumination.glsl.js +3 -3
  16. package/chunks/bundle.js +1 -1
  17. package/config.js +1 -1
  18. package/kernel.js +1 -1
  19. package/layers/graphics/sources/parquet/FileProvider.js +1 -1
  20. package/layers/graphics/sources/parquet/ParquetFileInfo.js +1 -1
  21. package/layers/graphics/sources/support/ParquetSourceWorker.js +1 -1
  22. package/layers/parquet.js +2 -0
  23. package/libs/{parquet → librust-parquet}/loadParquetModule.js +1 -1
  24. package/libs/{text → librust-text}/loadTextModule.js +1 -1
  25. package/package.json +2 -2
  26. package/rest/featureService/types.d.ts +3 -1
  27. package/rest/featureService/utils.d.ts +3 -1
  28. package/rest/featureService/utils.js +1 -1
  29. package/support/revision.js +1 -1
  30. package/versionManagement/VersionManagementService.js +1 -1
  31. package/versionManagement/VersionManager.js +1 -1
  32. package/versionManagement/versionAdapters/AnnotationFeatureLayerVersionAdapter.js +2 -0
  33. package/versionManagement/versionAdapters/DimensionFeatureLayerVersionAdapter.js +2 -0
  34. package/versionManagement/versionAdapters/types.d.ts +4 -2
  35. package/versionManagement/versionAdapters/utils.d.ts +4 -2
  36. package/versionManagement/versionAdapters/utils.js +1 -1
  37. package/views/2d/engine/webgl/GlyphMosaic.js +1 -1
  38. package/views/2d/engine/webgl/GlyphWorker.js +1 -1
  39. package/views/2d/engine/webgl/Overlay.js +1 -1
  40. package/views/2d/interactive/editingTools/manipulations/ScaleManipulation.js +1 -1
  41. package/views/2d/layers/VectorTileLayerView2D.js +1 -1
  42. package/views/2d/layers/features/sources/strategies/ParquetSnapshotLoadStrategy.js +1 -1
  43. package/views/2d/layers/features/sources/strategies/ParquetTileLoadStrategy.js +1 -1
  44. package/views/2d/layers/features/support/FeatureSetReaderParquet.js +1 -1
  45. package/views/3d/layers/VectorTileLayerView3D.js +1 -1
  46. package/views/View.js +1 -1
  47. package/views/support/drapedUtils.js +1 -1
  48. package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.d.ts +12 -3
  49. package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.js +1 -1
  50. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  51. package/widgets/Editor/MergeFeaturesWorkflow.js +1 -1
  52. package/widgets/Editor/SplitFeatureWorkflow.js +1 -1
  53. package/widgets/Editor/UpdateFeaturesWorkflow.js +1 -1
  54. package/widgets/Editor/UpdateRecordWorkflow.js +1 -1
  55. package/widgets/Editor/legacy/CreateFeaturesWorkflow.js +1 -1
  56. package/widgets/Editor/legacy/MergeFeaturesWorkflow.js +1 -1
  57. package/widgets/Editor/legacy/SplitFeatureWorkflow.js +1 -1
  58. package/widgets/Editor/legacy/UpdateFeaturesWorkflow.js +1 -1
  59. package/widgets/Editor/legacy/UpdateRecordWorkflow.js +1 -1
  60. package/widgets/FeatureForm/FeatureFormViewModel.d.ts +15 -3
  61. package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
  62. package/widgets/Sketch/SelectionToolVisibilityMap.d.ts +2 -2
  63. package/widgets/Sketch/SelectionToolVisibilityMap.js +1 -1
  64. package/assets/esri/core/workers/chunks/6cc03ef97d7731153b9a.js +0 -1
  65. package/assets/esri/core/workers/chunks/93a7cf23f73b23fc7802.js +0 -1
  66. package/assets/esri/libs/parquet/pkg/bundle_bg.wasm +0 -0
  67. package/libs/parquet/parquet.js +0 -2
  68. /package/assets/esri/libs/{text → librust-text}/pkg/bundle_bg.wasm +0 -0
package/views/View.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../Map.js";import{createTask as i}from"../core/asyncUtils.js";import r from"../core/Collection.js";import s from"../core/CollectionFlattener.js";import{referenceSetter as a}from"../core/collectionUtils.js";import o from"../core/Error.js";import{EventedMixin as n}from"../core/Evented.js";import l from"../core/Handles.js";import{makeHandle as p}from"../core/handleUtils.js";import has from"../core/has.js";import{isLoadable as h}from"../core/Loadable.js";import d from"../core/Logger.js";import{destroyMaybe as y,abortMaybe as u}from"../core/maybe.js";import{EsriPromise as m}from"../core/Promise.js";import{after as c}from"../core/promiseUtils.js";import g from"../core/ReactiveSet.js";import{watch as f,sync as w,whenOnce as v,when as _,syncAndInitial as M}from"../core/reactiveUtils.js";import{property as V,subclass as b}from"../core/accessorSupport/decorators.js";import{owningCollectionProperty as R}from"../core/support/OwningCollection.js";import{UpdatingHandles as S}from"../core/support/UpdatingHandles.js";import T from"../geometry/Extent.js";import j from"../geometry/HeightModelInfo.js";import E from"../geometry/SpatialReference.js";import{equals as L}from"../geometry/support/spatialReferenceUtils.js";import{AnalysesCollection as x}from"../support/AnalysesCollection.js";import{GraphicsCollection as C}from"../support/GraphicsCollection.js";import{system as F}from"../time/constants.js";import k from"../time/TimeExtent.js";import{isTimeZoneValid as O}from"../time/timeZoneUtils.js";import H from"./BasemapView.js";import I from"./Magnifier.js";import Z from"./SelectionManager.js";import W from"./Theme.js";import{ToolViewManager as q}from"./ToolViewManager.js";import{GlyphMosaic as A}from"./2d/engine/webgl/GlyphMosaic.js";import{makeDefaultHighlightOptions as P}from"./3d/support/DefaultHighlights.js";import D from"./input/Input.js";import{ViewEvents as U}from"./input/ViewEvents.js";import z from"./navigation/Navigation.js";import{deduplicateAttributionItems as G}from"./support/attributionUtils.js";import{DefaultsFromMap as N}from"./support/DefaultsFromMap.js";import{defaultHighlightName as $}from"./support/HighlightDefaults.js";import B from"./support/HighlightOptions.js";import J from"./support/LayerViewManager.js";import K from"./support/RequiredFieldsOptions.js";import{checkWebAssemblyRequirements as Q}from"./support/WebAssemblyRequirements.js";import{checkWebGLRequirements as X}from"./support/WebGLRequirements.js";var Y;let ee=class extends(n(m)){static{Y=this}constructor(e){super(e),this._userSpatialReference=null,this.handles=new l,this.updatingHandles=new S,this.allLayerViews=new s({getCollections:()=>this.layerviewCollections,getChildrenFunction:ie}),this.animationsEnabled=!0,this.attributionVisible=!0,this.basemapView=null,this.dependencies={popup:void 0},this.displayFilterEnabled=!0,this.fatalError=null,this.graphics=new C,this.typeSpecificPreconditionsReady=!0,this.layerViews=new r,this.magnifier=new I,this.padding={left:0,top:0,right:0,bottom:0},this.ready=!1,this._readyStateWaitingTask=null,this.type=null,this.scale=null,this.updating=!1,this.initialExtentRequired=!0,this._lowPriorityCursorHandles=new r,this._highPriorityCursorHandles=new r,this.input=new D,this.navigation=new z,this.layerViewManager=null,this.analysisViewManager=null,this.isHeightModelInfoRequired=!1,this.width=null,this.height=null,this.resizing=!1,this.suspended=!1,this.viewEvents=new U(this),this.requiredFieldsOptions=new K,this._isValid=!1,this._readyCycleForced=!1,this._lockedSpatialReference=null,this._userTimeZone=null,this._lockedTimeZone=null,this._userTimeExtent=null,this._lockedTimeExtent=null,this._glyphMosaic=null,this.theme=null,this.registeredComponents=new g,this.handles.add(f(()=>this.preconditionsReady,e=>{const t=this.ready;if(e?(this._lockedSpatialReference=this.spatialReference,this._lockedTimeZone=this.timeZone,this._lockedTimeExtent=this.timeExtent,Y.views.add(this)):(this._lockedSpatialReference=null,Y.views.remove(this)),this.notifyChange("spatialReference"),!e&&t)this.toolViewManager?.detach(),this.analysisViewManager?.detach(),this.layerViewManager?.clear(),this._glyphMosaic?.dispose(),this._teardown();else if(e&&!t){try{this._startup()}catch(i){return void queueMicrotask(()=>{this.fatalError=new o("view:startup-error","View._startup failed",i)})}this._glyphMosaic=new A(1024,1024,!0),this.analysisViewManager?.attach(),this.toolViewManager.attach()}},w)),this.analyses=new x}initialize(){this.addResolvingPromise(Promise.all([this.loadAsyncDependencies(),this.validate()]).then(()=>(this._isValid=!0,v(()=>this.ready)))),this.basemapView=new H({view:this}),this.layerViewManager=new J({view:this,layerViewFilter:e=>this.layerViewFilter?.(e)??!0,layerViewImporter:{importLayerView:e=>this.importLayerView(e),hasLayerViewModule:e=>this.hasLayerViewModule(e)},layerviewMapping:this._layerToLayerviewMapping}),this.toolViewManager=new q({view:this}),this.selectionManager=new Z({view:this}),this.addHandles([_(()=>"map-content-error"===this.readyState&&!this.spatialReference,()=>{d.getLogger(this).warn("#spatialReference","no spatial reference could be derived from the currently added map layers")}),f(()=>this.initialExtentRequired,e=>this.defaultsFromMap.required={...this.defaultsFromMap.required,extent:e},M),f(()=>this.ready,e=>{this.defaultsFromMap&&(this.defaultsFromMap.suspended=e,this.defaultsFromMap.userSpatialReference=e?this.spatialReference:this._userSpatialReference)},w),f(()=>this._userSpatialReference,e=>{this.defaultsFromMap&&(this.defaultsFromMap.userSpatialReference=e)},M)])}get _layerToLayerviewMapping(){return Y._layerToLayerview}static{this._layerToLayerview=[["view.map.basemap.baseLayers","view.basemapView.baseLayerViews"],["view.map.basemap.groundLayers","view.basemapView.groundLayerViews"],["view.map.basemap.referenceLayers","view.basemapView.referenceLayerViews"],["view.map.layers","view.layerViews"]]}destroy(){this.destroyed||(Y.views.remove(this),this.viewEvents.destroy(),this.allLayerViews.destroy(),this.navigation&&(this.navigation.destroy(),this._set("navigation",null)),this.graphics=y(this.graphics),this.analyses=y(this.analyses),this.defaultsFromMap.destroy(),this._set("defaultsFromMap",null),this.analysisViewManager=y(this.analysisViewManager),this.toolViewManager=y(this.toolViewManager),this.layerViewManager=y(this.layerViewManager),this.selectionManager=y(this.selectionManager),this.basemapView=y(this.basemapView),this.layerViews.destroyAll(),this.invalidate(),this.handles.destroy(),this.map=y(this.map),this.updatingHandles.destroy())}_startup(){this._set("ready",!0)}_teardown(){this._set("ready",!1)}whenReady(){return Promise.resolve(this)}toMap(){return d.getLogger(this).error("#toMap()","Not implemented on this instance of View"),null}get activeTool(){return this.toolViewManager?.activeTool}set activeTool(e){this.toolViewManager&&(this.toolViewManager.activeTool=e)}get layerviewCollections(){return[this.basemapView?.baseLayerViews,this.basemapView?.groundLayerViews,this.layerViews,this.basemapView?.referenceLayerViews]}get analyses(){return this._get("analyses")}set analyses(e){this._set("analyses",e)}get animation(){return this._get("animation")}set animation(e){this._set("animation",e)}get attributionItems(){return this.suspended?[]:G(this._get("attributionItems"),this.getAttributionItems())}get center(){return null}get defaultsFromMapSettings(){return{}}get defaultsFromMap(){return new N({required:{tileInfo:!1,heightModelInfo:!1,extent:!1},map:()=>this.map,getSpatialReferenceSupport:(e,t)=>this.getSpatialReferenceSupport(e,t),...this.defaultsFromMapSettings})}get extent(){return this._get("extent")}set extent(e){this._set("extent",e)}get heightModelInfo(){return this.getDefaultHeightModelInfo()}get glyphMosaic(){return this._glyphMosaic}get highlights(){return this._get("highlights")??P()}set highlights(e){this._set("highlights",a(e,this._get("highlights"),r.ofType(B)))}get defaultHighlight(){return this.highlights.find(({name:e})=>e===$)}get interacting(){return this.navigating}get navigating(){return!1}get preconditionsReady(){if(this.destroying||this.destroyed)return!1;const{map:e,spatialReference:t}=this;return!(this.fatalError||!this._isValid||this._readyCycleForced||!e||h(e)&&!e.loaded||0===this.width||0===this.height||!t||!this._validateSpatialReference(t)||!this._lockedSpatialReference&&!this.defaultsFromMap?.ready||!this.typeSpecificPreconditionsReady)}get resolution(){return 0}set map(e){e!==this._get("map")&&(e?.destroyed&&(d.getLogger(this).warn("#map","The provided map is already destroyed",{map:e}),e=null),h(e)&&e.load().catch(()=>{}),this.constructed&&!this.destroyed&&(this.forceReadyCycle(),this._lockedSpatialReference=null),this._set("map",e))}get canZoomIn(){return!!this.ready}get canZoomOut(){return!!this.ready}get readyState(){if(this.destroyed)return this._get("readyState");if(!this.map)return"missing-map";if("container"in this&&!this.container)return"missing-container";if(this.fatalError)return"rendering-error";if((this.defaultsFromMap?.ready??!1)&&!this.spatialReference){const e=!("loaded"in this.map)||this.map.loaded,t=this.map.ground.loaded,r=this.map.basemap?.loaded??!0;return e&&r&&t&&!this.map?.allLayers.length?"empty-map":(this._readyStateWaitingTask||(this._readyStateWaitingTask=i(e=>c(has("view-readyState-waiting-delay"),null,e)),this.addHandles(this._readyStateWaitingTask),this.addHandles(this._readyStateWaitingTask,"ready-state-task")),this._readyStateWaitingTask?.finished?"map-content-error":"loading")}return this._readyStateWaitingTask=u(this._readyStateWaitingTask),this.removeHandles("ready-state-task"),this.ready?"ready":"loading"}get spatialReference(){const{_userSpatialReference:e}=this;if(e&&null!==e.vcsWkid)return e;const t=e||this._lockedSpatialReference||this.getDefaultSpatialReference()||null;if(t&&this.defaultsFromMap?.required?.heightModelInfo){const e=t.clone();return e.vcsWkid=this.defaultsFromMap.vcsWkid,e.latestVcsWkid=this.defaultsFromMap.latestVcsWkid,e}return t}set spatialReference(e){const t=!L(e,this._get("spatialReference"));this._set("_userSpatialReference",e),t&&(this._set("spatialReference",e),this._spatialReferenceChanged(this.spatialReference))}_spatialReferenceChanged(e){}get stationary(){return!this.animation&&!this.navigating&&!this.resizing}get timeExtent(){return this._userTimeExtent??this._lockedTimeExtent??this.getDefaultTimeExtent()??null}set timeExtent(e){this._userTimeExtent=e}get timeZone(){return this._userTimeZone??this._lockedTimeZone??this.getDefaultTimeZone()??F}set timeZone(e){this._userTimeZone=e,O(e)||d.getLogger(this).warn("#timeZone",`the parsed value '${e}' may not be a valid IANA time zone`)}get tools(){return this.toolViewManager?.tools}get initialExtent(){return this.defaultsFromMap?.extent}get cursor(){return this.toolViewManager?.cursor??this._highPriorityCursorHandles.at(-1)?.cursor??this._lowPriorityCursorHandles.at(-1)?.cursor??"default"}acquireCursor(e,t="low"){const i="high"===t?this._highPriorityCursorHandles:this._lowPriorityCursorHandles,r={cursor:e},s=p(()=>i.remove(r));return i.add(r),this.addHandles(s),s}get size(){return[this.width,this.height]}get effectiveTheme(){return this.theme??new W}registerComponent(e){this.registeredComponents.add(e)}unregisterComponent(e){this.registeredComponents.delete(e)}whenLayerView(e){return this.layerViewManager?.whenLayerView(e)??Promise.reject()}getAttributionItems(){return this.allLayerViews.items.flatMap(e=>e.attributionItems)}getDefaultSpatialReference(){return this.defaultsFromMap?.spatialReference}getDefaultHeightModelInfo(){return(this.map&&"heightModelInfo"in this.map?this.map.heightModelInfo:void 0)??this.defaultsFromMap?.heightModelInfo??null}getDefaultTimeZone(){return null}getDefaultTimeExtent(){return null}getSurface(){return null}importLayerView(e){throw new o("view:importLayerView-missing","importLayerView() not implemented")}hasLayerViewModule(e){return!1}async validate(){const e=X(this.type);if(e)throw this._displayWebGLError(),d.getLogger(this).warn("#validate()",e.message),e;const t=await Q();if(t)throw d.getLogger(this).warn("#validate()",t.message),t}async loadAsyncDependencies(){}invalidate(){this._isValid=!1}getSpatialReferenceSupport(){return{constraints:null}}_validateSpatialReference(e){return null!=this.getSpatialReferenceSupport(e)}when(e,t){return this.isResolved()&&!this.ready&&d.getLogger(this).warn("#when()","Calling view.when() while the view is no longer ready but was already resolved once will resolve immediately. Use reactiveUtils.whenOnce(() => view.ready).then(...) instead."),super.when(e,t)}forceReadyCycle(){this.ready&&(_(()=>this.destroyed||!1===this.preconditionsReady,()=>this._readyCycleForced=!1,{once:!0}),this._readyCycleForced=!0)}on(e,t){return super.on(e,t)}addAndActivateTool(e){this.toolViewManager.tools.add(e),this.activeTool=e}tryFatalErrorRecovery(){this.fatalError=null}static{this.views=new r}_displayWebGLError(){const e=document.createElement("div");e.setAttribute("style","display: flex; flex-direction: column; gap: 8px; padding: 20px; height: 100%; justify-content: center; color: black; background: white; font-family: sans-serif;");const t=document.createElement("div");t.innerHTML="Unable to display map. WebGL2 support is required.",t.setAttribute("style","font-size: 24px; font-weight: bold;");const i=document.createElement("div");i.innerHTML="Ensure that your browser and hardware meet the minimum requirements.",i.setAttribute("style","font-size: 18px;");const r=document.createElement("a");r.innerHTML="https://esriurl.com/webgl-faq",r.target="_blank",r.setAttribute("style","font-size: 18px;"),r.href="https://esriurl.com/webgl-faq",e.appendChild(t),e.appendChild(i),e.appendChild(r);const s=this.getSurface();s&&s.appendChild(e)}};e([V()],ee.prototype,"_userSpatialReference",void 0),e([V()],ee.prototype,"activeTool",null),e([V({readOnly:!0})],ee.prototype,"allLayerViews",void 0),e([V({readOnly:!0})],ee.prototype,"layerviewCollections",null),e([V(R(x,"analyses"))],ee.prototype,"analyses",null),e([V()],ee.prototype,"animation",null),e([V()],ee.prototype,"animationsEnabled",void 0),e([V({readOnly:!0})],ee.prototype,"attributionItems",null),e([V()],ee.prototype,"attributionVisible",void 0),e([V()],ee.prototype,"basemapView",void 0),e([V()],ee.prototype,"center",null),e([V()],ee.prototype,"defaultsFromMapSettings",null),e([V()],ee.prototype,"defaultsFromMap",null),e([V()],ee.prototype,"dependencies",void 0),e([V()],ee.prototype,"displayFilterEnabled",void 0),e([V({type:T})],ee.prototype,"extent",null),e([V()],ee.prototype,"fatalError",void 0),e([V(R(C,"graphics"))],ee.prototype,"graphics",void 0),e([V({readOnly:!0,type:j})],ee.prototype,"heightModelInfo",null),e([V({readOnly:!0,type:A})],ee.prototype,"glyphMosaic",null),e([V({type:r.ofType(B)})],ee.prototype,"highlights",null),e([V({readOnly:!0})],ee.prototype,"interacting",null),e([V({constructOnly:!0})],ee.prototype,"layerViewFilter",void 0),e([V({readOnly:!0})],ee.prototype,"navigating",null),e([V({readOnly:!0})],ee.prototype,"preconditionsReady",null),e([V({readOnly:!0})],ee.prototype,"typeSpecificPreconditionsReady",void 0),e([V({type:r,readOnly:!0})],ee.prototype,"layerViews",void 0),e([V()],ee.prototype,"resolution",null),e([V({type:I})],ee.prototype,"magnifier",void 0),e([V({value:null,type:t})],ee.prototype,"map",null),e([V()],ee.prototype,"padding",void 0),e([V({readOnly:!0})],ee.prototype,"ready",void 0),e([V({readOnly:!0})],ee.prototype,"canZoomIn",null),e([V({readOnly:!0})],ee.prototype,"canZoomOut",null),e([V()],ee.prototype,"_readyStateWaitingTask",void 0),e([V({readOnly:!0})],ee.prototype,"readyState",null),e([V({type:E})],ee.prototype,"spatialReference",null),e([V()],ee.prototype,"stationary",null),e([V({type:k})],ee.prototype,"timeExtent",null),e([V({type:String,nonNullable:!0})],ee.prototype,"timeZone",null),e([V()],ee.prototype,"tools",null),e([V()],ee.prototype,"toolViewManager",void 0),e([V({readOnly:!0})],ee.prototype,"type",void 0),e([V({type:Number})],ee.prototype,"scale",void 0),e([V({readOnly:!0})],ee.prototype,"updating",void 0),e([V({readOnly:!0})],ee.prototype,"initialExtentRequired",void 0),e([V({readOnly:!0})],ee.prototype,"initialExtent",null),e([V()],ee.prototype,"cursor",null),e([V({readOnly:!0})],ee.prototype,"input",void 0),e([V({type:z,nonNullable:!0})],ee.prototype,"navigation",void 0),e([V()],ee.prototype,"layerViewManager",void 0),e([V()],ee.prototype,"analysisViewManager",void 0),e([V()],ee.prototype,"selectionManager",void 0),e([V()],ee.prototype,"width",void 0),e([V()],ee.prototype,"height",void 0),e([V({readOnly:!0})],ee.prototype,"resizing",void 0),e([V({value:null,readOnly:!0})],ee.prototype,"size",null),e([V({readOnly:!0})],ee.prototype,"suspended",void 0),e([V({readOnly:!0})],ee.prototype,"viewEvents",void 0),e([V()],ee.prototype,"_isValid",void 0),e([V()],ee.prototype,"_readyCycleForced",void 0),e([V()],ee.prototype,"_lockedSpatialReference",void 0),e([V()],ee.prototype,"_userTimeZone",void 0),e([V()],ee.prototype,"_lockedTimeZone",void 0),e([V()],ee.prototype,"_userTimeExtent",void 0),e([V()],ee.prototype,"_lockedTimeExtent",void 0),e([V({type:W})],ee.prototype,"theme",void 0),e([V({readOnly:!0,type:W})],ee.prototype,"effectiveTheme",null),e([V({readOnly:!0})],ee.prototype,"registeredComponents",void 0),ee=Y=e([b("esri.views.View")],ee);const te=globalThis.$arcgis;function ie(e){return e.layerViews}te&&!te.views&&Object.defineProperty(te,"views",{configurable:!1,enumerable:!0,writable:!1,value:ee.views});export{ee as default};
2
+ import{__decorate as e}from"tslib";import t from"../Map.js";import{createTask as i}from"../core/asyncUtils.js";import r from"../core/Collection.js";import s from"../core/CollectionFlattener.js";import{referenceSetter as a}from"../core/collectionUtils.js";import o from"../core/Error.js";import{EventedMixin as n}from"../core/Evented.js";import l from"../core/Handles.js";import{makeHandle as p}from"../core/handleUtils.js";import has from"../core/has.js";import{isLoadable as h}from"../core/Loadable.js";import d from"../core/Logger.js";import{destroyMaybe as y,abortMaybe as u}from"../core/maybe.js";import{EsriPromise as m}from"../core/Promise.js";import{after as c}from"../core/promiseUtils.js";import g from"../core/ReactiveSet.js";import{watch as f,sync as w,whenOnce as v,when as _,syncAndInitial as M}from"../core/reactiveUtils.js";import{property as V,subclass as b}from"../core/accessorSupport/decorators.js";import{owningCollectionProperty as R}from"../core/support/OwningCollection.js";import{UpdatingHandles as S}from"../core/support/UpdatingHandles.js";import T from"../geometry/Extent.js";import j from"../geometry/HeightModelInfo.js";import E from"../geometry/SpatialReference.js";import{equals as L}from"../geometry/support/spatialReferenceUtils.js";import{AnalysesCollection as x}from"../support/AnalysesCollection.js";import{GraphicsCollection as C}from"../support/GraphicsCollection.js";import{system as F}from"../time/constants.js";import k from"../time/TimeExtent.js";import{isTimeZoneValid as O}from"../time/timeZoneUtils.js";import H from"./BasemapView.js";import I from"./Magnifier.js";import Z from"./SelectionManager.js";import W from"./Theme.js";import{ToolViewManager as q}from"./ToolViewManager.js";import{GlyphMosaic as A}from"./2d/engine/webgl/GlyphMosaic.js";import{makeDefaultHighlightOptions as P}from"./3d/support/DefaultHighlights.js";import D from"./input/Input.js";import{ViewEvents as U}from"./input/ViewEvents.js";import z from"./navigation/Navigation.js";import{deduplicateAttributionItems as G}from"./support/attributionUtils.js";import{DefaultsFromMap as N}from"./support/DefaultsFromMap.js";import{defaultHighlightName as $}from"./support/HighlightDefaults.js";import B from"./support/HighlightOptions.js";import J from"./support/LayerViewManager.js";import K from"./support/RequiredFieldsOptions.js";import{checkWebAssemblyRequirements as Q}from"./support/WebAssemblyRequirements.js";import{checkWebGLRequirements as X}from"./support/WebGLRequirements.js";var Y;let ee=class extends(n(m)){static{Y=this}constructor(e){super(e),this._userSpatialReference=null,this.handles=new l,this.updatingHandles=new S,this.allLayerViews=new s({getCollections:()=>this.layerviewCollections,getChildrenFunction:ie}),this.animationsEnabled=!0,this.attributionVisible=!0,this.basemapView=null,this.dependencies={popup:void 0},this.displayFilterEnabled=!0,this.fatalError=null,this.graphics=new C,this.typeSpecificPreconditionsReady=!0,this.layerViews=new r,this.magnifier=new I,this.padding={left:0,top:0,right:0,bottom:0},this.ready=!1,this._readyStateWaitingTask=null,this.type=null,this.scale=null,this.updating=!1,this.initialExtentRequired=!0,this._lowPriorityCursorHandles=new r,this._highPriorityCursorHandles=new r,this.input=new D,this.navigation=new z,this.layerViewManager=null,this.analysisViewManager=null,this.isHeightModelInfoRequired=!1,this.width=null,this.height=null,this.resizing=!1,this.suspended=!1,this.viewEvents=new U(this),this.requiredFieldsOptions=new K,this._isValid=!1,this._readyCycleForced=!1,this._lockedSpatialReference=null,this._userTimeZone=null,this._lockedTimeZone=null,this._userTimeExtent=null,this._lockedTimeExtent=null,this._glyphMosaic=null,this.theme=null,this.registeredComponents=new g,this.handles.add(f(()=>this.preconditionsReady,e=>{const t=this.ready;if(e?(this._lockedSpatialReference=this.spatialReference,this._lockedTimeZone=this.timeZone,this._lockedTimeExtent=this.timeExtent,Y.views.add(this)):(this._lockedSpatialReference=null,Y.views.remove(this)),this.notifyChange("spatialReference"),!e&&t)this.toolViewManager?.detach(),this.analysisViewManager?.detach(),this.layerViewManager?.clear(),this._glyphMosaic?.dispose(),this._teardown();else if(e&&!t){try{this._startup()}catch(i){return void queueMicrotask(()=>{this.fatalError=new o("view:startup-error","View._startup failed",i)})}this._glyphMosaic=new A(1024,1024,!0),this.analysisViewManager?.attach(),this.toolViewManager.attach()}},w)),this.analyses=new x}initialize(){this.addResolvingPromise(Promise.all([this.loadAsyncDependencies(),this.validate()]).then(()=>(this._isValid=!0,v(()=>this.ready)))),this.basemapView=new H({view:this}),this.layerViewManager=new J({view:this,layerViewFilter:e=>this.layerViewFilter?.(e)??!0,layerViewImporter:{importLayerView:e=>this.importLayerView(e),hasLayerViewModule:e=>this.hasLayerViewModule(e)},layerviewMapping:this._layerToLayerviewMapping}),this.toolViewManager=new q({view:this}),this.selectionManager=new Z({view:this}),this.addHandles([_(()=>"map-content-error"===this.readyState&&!this.spatialReference,()=>{d.getLogger(this).warn("#spatialReference","no spatial reference could be derived from the currently added map layers")}),f(()=>this.initialExtentRequired,e=>this.defaultsFromMap.required={...this.defaultsFromMap.required,extent:e},M),f(()=>this.ready,e=>{this.defaultsFromMap&&(this.defaultsFromMap.suspended=e,this.defaultsFromMap.userSpatialReference=e?this.spatialReference:this._userSpatialReference)},w),f(()=>this._userSpatialReference,e=>{this.defaultsFromMap&&(this.defaultsFromMap.userSpatialReference=e)},M)])}get _layerToLayerviewMapping(){return Y._layerToLayerview}static{this._layerToLayerview=[["view.map.basemap.baseLayers","view.basemapView.baseLayerViews"],["view.map.basemap.groundLayers","view.basemapView.groundLayerViews"],["view.map.basemap.referenceLayers","view.basemapView.referenceLayerViews"],["view.map.layers","view.layerViews"]]}destroy(){this.destroyed||(Y.views.remove(this),this.viewEvents.destroy(),this.allLayerViews.destroy(),this.navigation&&(this.navigation.destroy(),this._set("navigation",null)),this.graphics=y(this.graphics),this.analyses=y(this.analyses),this.defaultsFromMap.destroy(),this._set("defaultsFromMap",null),this.analysisViewManager=y(this.analysisViewManager),this.toolViewManager=y(this.toolViewManager),this.layerViewManager=y(this.layerViewManager),this.selectionManager=y(this.selectionManager),this.basemapView=y(this.basemapView),this.layerViews.destroyAll(),this.invalidate(),this.handles.destroy(),this.map=y(this.map),this.updatingHandles.destroy())}_startup(){this._set("ready",!0)}_teardown(){this._set("ready",!1)}whenReady(){return Promise.resolve(this)}toMap(){return d.getLogger(this).error("#toMap()","Not implemented on this instance of View"),null}get activeTool(){return this.toolViewManager?.activeTool}set activeTool(e){this.toolViewManager&&(this.toolViewManager.activeTool=e)}get layerviewCollections(){return[this.basemapView?.baseLayerViews,this.basemapView?.groundLayerViews,this.layerViews,this.basemapView?.referenceLayerViews]}get analyses(){return this._get("analyses")}set analyses(e){this._set("analyses",e)}get animation(){return this._get("animation")}set animation(e){this._set("animation",e)}get attributionItems(){return this.suspended?[]:G(this._get("attributionItems"),this.getAttributionItems())}get center(){return null}get defaultsFromMapSettings(){return{}}get defaultsFromMap(){return new N({required:{tileInfo:!1,heightModelInfo:!1,extent:!1},map:()=>this.map,getSpatialReferenceSupport:(e,t)=>this.getSpatialReferenceSupport(e,t),...this.defaultsFromMapSettings})}get extent(){return this._get("extent")}set extent(e){this._set("extent",e)}get heightModelInfo(){return this.getDefaultHeightModelInfo()}glyphMosaic(){return this._glyphMosaic}get highlights(){return this._get("highlights")??P()}set highlights(e){this._set("highlights",a(e,this._get("highlights"),r.ofType(B)))}get defaultHighlight(){return this.highlights.find(({name:e})=>e===$)}get interacting(){return this.navigating}get navigating(){return!1}get preconditionsReady(){if(this.destroying||this.destroyed)return!1;const{map:e,spatialReference:t}=this;return!(this.fatalError||!this._isValid||this._readyCycleForced||!e||h(e)&&!e.loaded||0===this.width||0===this.height||!t||!this._validateSpatialReference(t)||!this._lockedSpatialReference&&!this.defaultsFromMap?.ready||!this.typeSpecificPreconditionsReady)}get resolution(){return 0}set map(e){e!==this._get("map")&&(e?.destroyed&&(d.getLogger(this).warn("#map","The provided map is already destroyed",{map:e}),e=null),h(e)&&e.load().catch(()=>{}),this.constructed&&!this.destroyed&&(this.forceReadyCycle(),this._lockedSpatialReference=null),this._set("map",e))}get canZoomIn(){return!!this.ready}get canZoomOut(){return!!this.ready}get readyState(){if(this.destroyed)return this._get("readyState");if(!this.map)return"missing-map";if("container"in this&&!this.container)return"missing-container";if(this.fatalError)return"rendering-error";if((this.defaultsFromMap?.ready??!1)&&!this.spatialReference){const e=!("loaded"in this.map)||this.map.loaded,t=this.map.ground.loaded,r=this.map.basemap?.loaded??!0;return e&&r&&t&&!this.map?.allLayers.length?"empty-map":(this._readyStateWaitingTask||(this._readyStateWaitingTask=i(e=>c(has("view-readyState-waiting-delay"),null,e)),this.addHandles(this._readyStateWaitingTask),this.addHandles(this._readyStateWaitingTask,"ready-state-task")),this._readyStateWaitingTask?.finished?"map-content-error":"loading")}return this._readyStateWaitingTask=u(this._readyStateWaitingTask),this.removeHandles("ready-state-task"),this.ready?"ready":"loading"}get spatialReference(){const{_userSpatialReference:e}=this;if(e&&null!==e.vcsWkid)return e;const t=e||this._lockedSpatialReference||this.getDefaultSpatialReference()||null;if(t&&this.defaultsFromMap?.required?.heightModelInfo){const e=t.clone();return e.vcsWkid=this.defaultsFromMap.vcsWkid,e.latestVcsWkid=this.defaultsFromMap.latestVcsWkid,e}return t}set spatialReference(e){const t=!L(e,this._get("spatialReference"));this._set("_userSpatialReference",e),t&&(this._set("spatialReference",e),this._spatialReferenceChanged(this.spatialReference))}_spatialReferenceChanged(e){}get stationary(){return!this.animation&&!this.navigating&&!this.resizing}get timeExtent(){return this._userTimeExtent??this._lockedTimeExtent??this.getDefaultTimeExtent()??null}set timeExtent(e){this._userTimeExtent=e}get timeZone(){return this._userTimeZone??this._lockedTimeZone??this.getDefaultTimeZone()??F}set timeZone(e){this._userTimeZone=e,O(e)||d.getLogger(this).warn("#timeZone",`the parsed value '${e}' may not be a valid IANA time zone`)}get tools(){return this.toolViewManager?.tools}get initialExtent(){return this.defaultsFromMap?.extent}get cursor(){return this.toolViewManager?.cursor??this._highPriorityCursorHandles.at(-1)?.cursor??this._lowPriorityCursorHandles.at(-1)?.cursor??"default"}acquireCursor(e,t="low"){const i="high"===t?this._highPriorityCursorHandles:this._lowPriorityCursorHandles,r={cursor:e},s=p(()=>i.remove(r));return i.add(r),this.addHandles(s),s}get size(){return[this.width,this.height]}get effectiveTheme(){return this.theme??new W}registerComponent(e){this.registeredComponents.add(e)}unregisterComponent(e){this.registeredComponents.delete(e)}whenLayerView(e){return this.layerViewManager?.whenLayerView(e)??Promise.reject()}getAttributionItems(){return this.allLayerViews.items.flatMap(e=>e.attributionItems)}getDefaultSpatialReference(){return this.defaultsFromMap?.spatialReference}getDefaultHeightModelInfo(){return(this.map&&"heightModelInfo"in this.map?this.map.heightModelInfo:void 0)??this.defaultsFromMap?.heightModelInfo??null}getDefaultTimeZone(){return null}getDefaultTimeExtent(){return null}getSurface(){return null}importLayerView(e){throw new o("view:importLayerView-missing","importLayerView() not implemented")}hasLayerViewModule(e){return!1}async validate(){const e=X(this.type);if(e)throw this._displayWebGLError(),d.getLogger(this).warn("#validate()",e.message),e;const t=await Q();if(t)throw d.getLogger(this).warn("#validate()",t.message),t}async loadAsyncDependencies(){}invalidate(){this._isValid=!1}getSpatialReferenceSupport(){return{constraints:null}}_validateSpatialReference(e){return null!=this.getSpatialReferenceSupport(e)}when(e,t){return this.isResolved()&&!this.ready&&d.getLogger(this).warn("#when()","Calling view.when() while the view is no longer ready but was already resolved once will resolve immediately. Use reactiveUtils.whenOnce(() => view.ready).then(...) instead."),super.when(e,t)}forceReadyCycle(){this.ready&&(_(()=>this.destroyed||!1===this.preconditionsReady,()=>this._readyCycleForced=!1,{once:!0}),this._readyCycleForced=!0)}on(e,t){return super.on(e,t)}addAndActivateTool(e){this.toolViewManager.tools.add(e),this.activeTool=e}tryFatalErrorRecovery(){this.fatalError=null}static{this.views=new r}_displayWebGLError(){const e=document.createElement("div");e.setAttribute("style","display: flex; flex-direction: column; gap: 8px; padding: 20px; height: 100%; justify-content: center; color: black; background: white; font-family: sans-serif;");const t=document.createElement("div");t.innerHTML="Unable to display map. WebGL2 support is required.",t.setAttribute("style","font-size: 24px; font-weight: bold;");const i=document.createElement("div");i.innerHTML="Ensure that your browser and hardware meet the minimum requirements.",i.setAttribute("style","font-size: 18px;");const r=document.createElement("a");r.innerHTML="https://esriurl.com/webgl-faq",r.target="_blank",r.setAttribute("style","font-size: 18px;"),r.href="https://esriurl.com/webgl-faq",e.appendChild(t),e.appendChild(i),e.appendChild(r);const s=this.getSurface();s&&s.appendChild(e)}};e([V()],ee.prototype,"_userSpatialReference",void 0),e([V()],ee.prototype,"activeTool",null),e([V({readOnly:!0})],ee.prototype,"allLayerViews",void 0),e([V({readOnly:!0})],ee.prototype,"layerviewCollections",null),e([V(R(x,"analyses"))],ee.prototype,"analyses",null),e([V()],ee.prototype,"animation",null),e([V()],ee.prototype,"animationsEnabled",void 0),e([V({readOnly:!0})],ee.prototype,"attributionItems",null),e([V()],ee.prototype,"attributionVisible",void 0),e([V()],ee.prototype,"basemapView",void 0),e([V()],ee.prototype,"center",null),e([V()],ee.prototype,"defaultsFromMapSettings",null),e([V()],ee.prototype,"defaultsFromMap",null),e([V()],ee.prototype,"dependencies",void 0),e([V()],ee.prototype,"displayFilterEnabled",void 0),e([V({type:T})],ee.prototype,"extent",null),e([V()],ee.prototype,"fatalError",void 0),e([V(R(C,"graphics"))],ee.prototype,"graphics",void 0),e([V({readOnly:!0,type:j})],ee.prototype,"heightModelInfo",null),e([V({type:r.ofType(B)})],ee.prototype,"highlights",null),e([V({readOnly:!0})],ee.prototype,"interacting",null),e([V({constructOnly:!0})],ee.prototype,"layerViewFilter",void 0),e([V({readOnly:!0})],ee.prototype,"navigating",null),e([V({readOnly:!0})],ee.prototype,"preconditionsReady",null),e([V({readOnly:!0})],ee.prototype,"typeSpecificPreconditionsReady",void 0),e([V({type:r,readOnly:!0})],ee.prototype,"layerViews",void 0),e([V()],ee.prototype,"resolution",null),e([V({type:I})],ee.prototype,"magnifier",void 0),e([V({value:null,type:t})],ee.prototype,"map",null),e([V()],ee.prototype,"padding",void 0),e([V({readOnly:!0})],ee.prototype,"ready",void 0),e([V({readOnly:!0})],ee.prototype,"canZoomIn",null),e([V({readOnly:!0})],ee.prototype,"canZoomOut",null),e([V()],ee.prototype,"_readyStateWaitingTask",void 0),e([V({readOnly:!0})],ee.prototype,"readyState",null),e([V({type:E})],ee.prototype,"spatialReference",null),e([V()],ee.prototype,"stationary",null),e([V({type:k})],ee.prototype,"timeExtent",null),e([V({type:String,nonNullable:!0})],ee.prototype,"timeZone",null),e([V()],ee.prototype,"tools",null),e([V()],ee.prototype,"toolViewManager",void 0),e([V({readOnly:!0})],ee.prototype,"type",void 0),e([V({type:Number})],ee.prototype,"scale",void 0),e([V({readOnly:!0})],ee.prototype,"updating",void 0),e([V({readOnly:!0})],ee.prototype,"initialExtentRequired",void 0),e([V({readOnly:!0})],ee.prototype,"initialExtent",null),e([V()],ee.prototype,"cursor",null),e([V({readOnly:!0})],ee.prototype,"input",void 0),e([V({type:z,nonNullable:!0})],ee.prototype,"navigation",void 0),e([V()],ee.prototype,"layerViewManager",void 0),e([V()],ee.prototype,"analysisViewManager",void 0),e([V()],ee.prototype,"selectionManager",void 0),e([V()],ee.prototype,"width",void 0),e([V()],ee.prototype,"height",void 0),e([V({readOnly:!0})],ee.prototype,"resizing",void 0),e([V({value:null,readOnly:!0})],ee.prototype,"size",null),e([V({readOnly:!0})],ee.prototype,"suspended",void 0),e([V({readOnly:!0})],ee.prototype,"viewEvents",void 0),e([V()],ee.prototype,"_isValid",void 0),e([V()],ee.prototype,"_readyCycleForced",void 0),e([V()],ee.prototype,"_lockedSpatialReference",void 0),e([V()],ee.prototype,"_userTimeZone",void 0),e([V()],ee.prototype,"_lockedTimeZone",void 0),e([V()],ee.prototype,"_userTimeExtent",void 0),e([V()],ee.prototype,"_lockedTimeExtent",void 0),e([V({type:W})],ee.prototype,"theme",void 0),e([V({readOnly:!0,type:W})],ee.prototype,"effectiveTheme",null),e([V({readOnly:!0})],ee.prototype,"registeredComponents",void 0),ee=Y=e([b("esri.views.View")],ee);const te=globalThis.$arcgis;function ie(e){return e.layerViews}te&&!te.views&&Object.defineProperty(te,"views",{configurable:!1,enumerable:!0,writable:!1,value:ee.views});export{ee as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{getMetersPerUnitForSR as e}from"../../core/units.js";import t from"../../geometry/Extent.js";import{calculateTolerance as n}from"../../renderers/support/clickToleranceUtils.js";function r(n,r,i,a=new t){let o=0;if("2d"===i.type)o=r*(i.resolution??0);else if("3d"===i.type){const t=i.overlayPixelSizeInMapUnits(n),{groundSpatialReference:a}=i;o=null==a||a.equals(i.spatialReference)?r*t:e(a)/e(i.spatialReference)}const s=n.x-o,l=n.y-o,c=n.x+o,m=n.y+o,{spatialReference:p}=i;return a.xmin=Math.min(s,c),a.ymin=Math.min(l,m),a.xmax=Math.max(s,c),a.ymax=Math.max(l,m),a.spatialReference=p,a}function i(e,t,i){const o=i.toMap(e);if(null==o)return!1;return r(o,n(),i,a).intersects(t)}let a=new t;function o(){a=new t}export{o as cleanupDrapedUtils,r as createQueryGeometry,i as intersectsDrapedGeometry};
2
+ import{getMetersPerUnitForSR as e}from"../../core/units.js";import t from"../../geometry/Extent.js";import{tryProject as n}from"../../geometry/projectionUtils.js";import{getClosestDenormalizedXToReference as r}from"../../geometry/support/normalizeUtils.js";import{calculateTolerance as i}from"../../renderers/support/clickToleranceUtils.js";function o(n,r,i,o=new t){let a=0;if("2d"===i.type)a=r*(i.resolution??0);else if("3d"===i.type){const t=i.overlayPixelSizeInMapUnits(n),{groundSpatialReference:o}=i;a=null==o||o.equals(i.spatialReference)?r*t:e(o)/e(i.spatialReference)}const s=n.x-a,l=n.y-a,m=n.x+a,p=n.y+a,{spatialReference:c}=i;return o.xmin=Math.min(s,m),o.ymin=Math.min(l,p),o.xmax=Math.max(s,m),o.ymax=Math.max(l,p),o.spatialReference=c,o}function a(e,t,a){const l=a.toMap(e);if(null==l)return!1;const m=n(t.extent?.center??l,a.spatialReference)??l;l.x=r(l.x,m.x,a.spatialReference);return o(l,i(),a,s).intersects(t)}let s=new t;function l(){s=new t}export{l as cleanupDrapedUtils,o as createQueryGeometry,a as intersectsDrapedGeometry};
@@ -11,11 +11,12 @@ import type UtilityNetworkAssociationsElementInput from "./inputs/UtilityNetwork
11
11
  import type { EventedAccessor } from "../../core/Evented.js";
12
12
  import type { FieldValue } from "../../layers/support/fieldUtils.js";
13
13
  import type { TimeZone } from "../../time/types.js";
14
+ import type { MapViewOrSceneView } from "../../views/MapViewOrSceneView.js";
14
15
  import type { AssociationsLayerUnion, AttachmentsChangeEvent, AttributeFormSupportedLayerInfo, AttributeFormSupportedLayerUnion, BatchAttributeFormMode, BatchAttributeFormState, PendingAttachmentEdits, SelectedAttachmentIdentifier, SelectedAttachmentDetails, SubmitEvent, ValueChangeEvent, ValuesChangeEvent } from "./types.js";
15
16
  import type { FormInput } from "./inputs/types.js";
16
17
  import type { EditType } from "../support/forms/types.js";
17
18
 
18
- export interface BatchAttributeFormViewModelProperties extends Partial<Pick<BatchAttributeFormViewModel, "activeFeatureIndex" | "attachmentsEnabled" | "disabled" | "editType" | "features" | "layerInfos" | "map" | "readOnly" | "selectedAttachment" | "selectedAttachmentAddElementId" | "selectedAttachmentListElementId" | "showingSelectedAttachmentReplacePage" | "submitHasBeenAttempted" | "timeZone" | "userHasChangedValues">> {}
19
+ export interface BatchAttributeFormViewModelProperties extends Partial<Pick<BatchAttributeFormViewModel, "activeFeatureIndex" | "attachmentsEnabled" | "disabled" | "editType" | "features" | "layerInfos" | "map" | "readOnly" | "selectedAttachment" | "selectedAttachmentAddElementId" | "selectedAttachmentListElementId" | "showingSelectedAttachmentReplacePage" | "submitHasBeenAttempted" | "timeZone" | "userHasChangedValues" | "view">> {}
19
20
 
20
21
  export interface BatchAttributeFormViewModelEvents {
21
22
  /**
@@ -193,6 +194,7 @@ export default class BatchAttributeFormViewModel extends EventedAccessor {
193
194
  get layers(): AttributeFormSupportedLayerUnion[];
194
195
  /**
195
196
  * A reference to the associated [Map](https://developers.arcgis.com/javascript/latest/references/core/Map/).
197
+ * By default, this is inherited from the associated [MapView](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/) or [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/).
196
198
  *
197
199
  * > [!WARNING]
198
200
  * >
@@ -260,10 +262,11 @@ export default class BatchAttributeFormViewModel extends EventedAccessor {
260
262
  */
261
263
  accessor submitHasBeenAttempted: boolean;
262
264
  /**
263
- * The time zone used to interpret date values in the form. If this property is `null` or set to `"unknown"`, date values are displayed in the time zone specified by the layer's [FeatureLayer.preferredTimeZone](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#preferredTimeZone). If none is provided there, date values are interpreted in UTC.
265
+ * The time zone used to interpret date values in the form. By default, the time zone is inherited from the associated [MapView](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/#timeZone) or [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/#timeZone).
266
+ *
267
+ * If no time zone is inherited or the resolved value is `unknown`, date values are displayed in the time zone specified by the layer's [FeatureLayer.preferredTimeZone](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#preferredTimeZone). If none is provided there, date values are interpreted in UTC.
264
268
  *
265
269
  * @see [FeatureLayer.preferredTimeZone](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#preferredTimeZone)
266
- * @see [View2D.timeZone](https://developers.arcgis.com/javascript/latest/references/core/views/View2D/#timeZone)
267
270
  */
268
271
  accessor timeZone: TimeZone | null | undefined;
269
272
  /**
@@ -282,6 +285,12 @@ export default class BatchAttributeFormViewModel extends EventedAccessor {
282
285
  accessor userHasChangedValues: boolean;
283
286
  /** Returns true if all fields for all features in the form are valid, with no validation errors present. */
284
287
  get valid(): boolean;
288
+ /**
289
+ * A reference to the [MapView](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/) or [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/) associated with the form.
290
+ *
291
+ * @internal
292
+ */
293
+ accessor view: MapViewOrSceneView | null | undefined;
285
294
  /**
286
295
  * An array of inputs in the active form that are currently visible to the user.
287
296
  * This array includes only those inputs that are not hidden by visibility settings or expressions.
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{pushIfSome as t}from"../../core/arrayUtils.js";import{createTask as s}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import i from"../../core/Error.js";import{EventedAccessor as n}from"../../core/Evented.js";import r from"../../core/Logger.js";import{getOrCreateMapValue as o}from"../../core/MapUtils.js";import{destroyMaybe as l,abortMaybe as h}from"../../core/maybe.js";import{throwIfAborted as c,whenOrAbort as p,ignoreAbortErrors as u,isAbortError as d}from"../../core/promiseUtils.js";import m from"../../core/ReactiveMap.js";import{on as g,sync as y,watch as f,syncAndInitial as v,initial as _,whenOnce as A}from"../../core/reactiveUtils.js";import{property as F,subclass as I}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as w}from"../../core/support/UpdatingHandles.js";import x from"../../geometry/SpatialReference.js";import{getGraphicLayer as E}from"../../graphic/graphicOriginUtils.js";import{isSubtypeGroupLayer as C,isSubtypeSublayer as T,isFeatureLayer as M,getSubtypesFromLayer as k}from"../../layers/support/layerUtils.js";import{system as b}from"../../time/constants.js";import{getAttachmentKey as V}from"./attachmentUtils.js";import{getLayerTimeZone as S,getEffectiveTimeZone as L,createReactiveGraphic as R,isAttributeFormSupportedLayerWithAttachments as H,layerSupportsAttachments as P,queryAttachmentsForElements as j}from"./batchAttributeFormUtils.js";import{ReactiveContingentValuesManager as U}from"./ReactiveContingentValuesManager.js";import{parseFormTemplateString as O}from"./stringUtils.js";import{ValueChangeTransaction as G}from"./ValueChangeTransaction.js";import{ArcadeExecutorProvider as B}from"./expressions/ArcadeExecutorProvider.js";import{ExpressionsManager as D}from"./expressions/ExpressionsManager.js";import{ExpressionsModel as N}from"./expressions/ExpressionsModel.js";import W from"./inputs/BatchFormInputs.js";import{createBatchFormInputsFromBatchFormTemplate as Z,mergeBatchFormInputsFromNewTemplate as $}from"./inputs/support/createBatchFormInputs.js";import{isGroupInput as K,isFieldInput as z}from"./inputs/support/inputUtils.js";import q from"./templates/BatchFormTemplate.js";import{createBatchFormTemplate as J}from"./templates/support/createBatchFormTemplate.js";import{isExcludedFromSharedForm as Q,isGroupElementTemplate as X}from"./templates/support/templateUtils.js";import{ContingentValuesManager as Y,isLayerWithContingentValues as ee}from"../support/ContingentValuesManager.js";import{isEmptyValue as te}from"../support/forms/formUtils.js";function se(e,t){return e?.find(e=>e.layer===t)}let ae=class extends n{constructor(e){super(e),this._attachmentCache=new m,this.activeFeatureIndex=-1,this.attachmentsEnabled=!1,this.callbacks=null,this.disabled=!1,this.editType="NA",this.features=new a,this._hasAsyncArcadeExpressions=!1,this.highlightHelper=null,this.maximumFeatureCount=2e3,this.maximumFeatureCountWithComplexForms=50,this.map=null,this.pageStack=[],this.readOnly=!1,this.pendingSubtypeChoice=null,this.spatialReference=null,this.submitHasBeenAttempted=!1,this.timeZone=null,this.userHasChangedValues=!1,this.layerInfos=null,this._arcadeExecutorProvider=new B,this._activeAssociation=null,this._activeAssociationsInput=null,this._activeRelationshipInput=null,this._ownContingentValuesManager=null,this._activeFormInputsByElementId=new Map,this._emptyForm=new W({inputs:[]}),this._emptyFormTemplate=new q({elements:[]}),this._featureFormMap=new m,this._prepareTask=null,this._layerTemplateUpdateTask=null,this._syncAttachmentsTask=null,this._reactiveGraphicLookup=new m,this._updatingHandles=new w,this._submitTask=null,this._layerTemplateMap=new m,this._workingFeatures=new a,this._expressionsManager=new D({arcadeContext:{editType:"NA",spatialReference:null,map:null,timeZone:b}}),this._getExternalErrorForFeature=(e,t)=>this._reactiveContingentValuesManager.getViolationTypeForField(e,t),this._getFieldValueOptionsForFeature=e=>this._reactiveContingentValuesManager.getAndWatchFieldValueOptions(e),this.sharedForm=this._emptyForm,this.sharedFormTemplate=this._emptyFormTemplate}initialize(){this.contingentValuesManager||(this.contingentValuesManager=this._ownContingentValuesManager=new Y),this.addHandles([g(()=>this.features,"after-changes",()=>{this.goHome(),this.notifyChange("layers"),this._prepare()},y),f(()=>[this.attachmentsEnabled,this.features,this.map,this.timeZone,this.editType],()=>this._prepare(),y),f(()=>this.activeForm,()=>{this.goHome(),this._activeFormInputsByElementId.clear(),this._syncAttachments()},y),f(()=>this.activeFeature,()=>{this.goHome()},y),f(()=>this.page,e=>{const t=[...this.pageStack];if(t.includes(e))for(;t.length&&t.at(-1)!==e;)t.pop();else t.push(e);this.pageStack=t},v),f(()=>this.contingentValuesManager,e=>{l(this._reactiveContingentValuesManager),this._reactiveContingentValuesManager=new U({manager:e})},_)]),this._prepare()}destroy(){this._prepareTask=h(this._prepareTask),this.pendingSubtypeChoice?.reject(),this._layerTemplateUpdateTask=h(this._layerTemplateUpdateTask),this._syncAttachmentsTask=h(this._syncAttachmentsTask),this._workingFeatures.destroyAll(),l(this._expressionsManager),l(this._reactiveContingentValuesManager),this._updatingHandles.destroy(),this._reactiveGraphicLookup=new m,this._emptyForm.destroy(),this._emptyFormTemplate.destroy(),this._ownContingentValuesManager=l(this._ownContingentValuesManager),this.highlightHelper?.removeAll()}get activeFeature(){const e=this.activeFeatureIndex;return e<0?null:this.features.at(e)}get activeForm(){if("batch"===this.mode)return this.sharedForm;const e=this._workingFeatures.at(this.activeFeatureIndex);if(!e)return this._emptyForm;const t=this._featureFormMap.get(e);if(t)return t;const s=this._makeBatchFormInputsForFeature(e);return s!==this._emptyForm&&this._featureFormMap.set(e,s),s}get activeLayer(){const{activeFeature:e}=this;if(!e)return null;return E(e)??null}get activeAssociation(){return this._activeAssociation}get activeAssociationsInput(){return this._activeAssociationsInput}get activeAssociationType(){return this.activeAssociationsInput?.activeAssociationType}get activeRelationshipInput(){return this._activeRelationshipInput}get calculating(){return this._expressionsManager.calculating}get expressionsManager(){return this._expressionsManager}get canGoBack(){return this.pageStack.length>1}get expressionEvaluationFailed(){return this._expressionsManager.expressionEvaluationFailed}get hasNonActiveInvalidFeatures(){if("batch"===this.mode)return!1;const{activeFeature:e}=this;return this.invalidFeatures.some(t=>t!==e)}get hasAsyncArcadeExpressions(){return this._hasAsyncArcadeExpressions}get hasTooManyFeatures(){return this._workingFeatures.length>this.maximumFeatureCount}get hasTooManyComplexFeatures(){return this._workingFeatures.length>this.maximumFeatureCountWithComplexForms&&this.hasAsyncArcadeExpressions}get invalidFeatures(){return this.sharedForm.invalidFeatures}get hasVisibleInputs(){return this.visibleInputs.length>0}get hasLayersWithContingentValues(){const e=this.contingentValuesManager;for(const t of this.layers)if(e.getFieldsWithContingentValues(t).size>0)return!0;return!1}get formDescription(){return this._computeFormHeaderField(this.activeForm?.description)}get formTitle(){return this._computeFormHeaderField(this.activeForm?.title)}get effectiveTimeZone(){const{activeLayer:e,timeZone:t}=this;if(!e)return t??"system";const s=S(e);return L(t,s)}get visibleInputs(){return this.activeForm.inputs.filter(e=>e.visible)}get noVisibleElementsReason(){if(this.hasVisibleInputs)return null;if(0===this.activeForm.inputs.length)return"noElements";const e=new Set;for(const t of this.activeForm.inputs)switch(t.visibilityCode){case"hidden:not-in-all-layers":case"hidden:no-domain-in-common":e.add("noElementsInCommon");break;case"hidden:field-definition":case"hidden:group-visibility-expression:all-features":case"hidden:visibility-expression:all-features":e.add("allElementsHidden");break;case"hidden:group-visibility-expression:some-features":case"hidden:visibility-expression:some-features":return"elementsHiddenInSome"}return e.has("allElementsHidden")?"allElementsHidden":"noElementsInCommon"}get page(){return this.showingSelectedAttachmentReplacePage&&this.selectedAttachmentDetails?"replacing-attachment":this.selectedAttachmentDetails?"viewing-attachment-details":this.selectedAttachmentAddInput?"adding-attachments":this.selectedAttachmentListInput?"viewing-attachments":this.activeAssociationsInput?.associatedLayer?"viewing-associated-features":this.activeAssociationsInput?"viewing-associated-layers":this.activeRelationshipInput?.showAllRelatedRecords?"viewing-related-records":this.activeRelationshipInput?.showAllCategories?"viewing-related-categories":"default"}get subtypes(){const e=this.activeLayer;return C(e)||T(e)||M(e)?k(e):[]}get status(){const e=this._prepareTask;return null==e?"not-loaded":e.finished?null!=e.error?"failed":"loaded":"loading"}get updating(){return this._updatingHandles.updating||this.calculating}get valid(){return this.sharedForm.valid&&Array.from(this._featureFormMap.values()).every(e=>e.valid)}get layers(){return Array.from(this._layersSet)}get mode(){return this.activeFeatureIndex>-1?"single":"batch"}submit(){if(this.submitHasBeenAttempted=!0,this.validateContingentValues(this._workingFeatures),!this._hasPendingAttachmentHydration)return this._emitSubmit(),Promise.resolve();if(this._submitTask)return this._submitTask.promise;const e=s(async()=>{await Promise.all(this._allAttachmentInputs.map(e=>e.waitForPendingAttachmentUpdateData())),this._emitSubmit()});return this._submitTask=e,e.promise.finally(()=>{this._submitTask===e&&(this._submitTask=null)}),e.promise}get selectedAttachment(){return this._get("selectedAttachment")??null}set selectedAttachment(e){this.showingSelectedAttachmentReplacePage=!1,this._set("selectedAttachment",e),null!=e&&(this.selectedAttachmentAddElementId=null)}get selectedAttachmentAddElementId(){return this._get("selectedAttachmentAddElementId")??null}set selectedAttachmentAddElementId(e){this.showingSelectedAttachmentReplacePage=!1,this._set("selectedAttachmentAddElementId",e),null!=e&&(this.selectedAttachment=null,this.selectedAttachmentListElementId=null)}get selectedAttachmentListElementId(){return this._get("selectedAttachmentListElementId")??null}set selectedAttachmentListElementId(e){this._set("selectedAttachmentListElementId",e),null!=e&&(this.selectedAttachment=null,this.selectedAttachmentAddElementId=null)}get selectedAttachmentListInput(){const e=this.selectedAttachmentListElementId,t=this.activeForm;if(!e||!t)return null;const s=t.allAttachmentElementInputs.find(t=>t.template.elementId===e)||null;return s?.attachments.length?s:null}get showingSelectedAttachmentReplacePage(){return this._get("showingSelectedAttachmentReplacePage")??!1}set showingSelectedAttachmentReplacePage(e){this._set("showingSelectedAttachmentReplacePage",e&&null!=this.selectedAttachmentDetails)}get selectedAttachmentAddInput(){const e=this.selectedAttachmentAddElementId,t=this.activeForm;return e&&t&&t.allAttachmentElementInputs.find(t=>t.template.elementId===e)||null}get selectedAttachmentDetails(){const e=this.selectedAttachment,t=this.activeForm;if(!e||!t)return null;const s=t.allAttachmentElementInputs.find(t=>t.template.elementId===e.elementId);if(!s)return null;const a=s.attachments.findIndex(t=>V(t)===e.attachmentKey);if(-1===a)return null;return{attachment:s.attachments[a],input:s}}get _allAttachmentInputs(){const e=[...this.sharedForm.allAttachmentElementInputs];for(const t of this._featureFormMap.values())e.push(...t.allAttachmentElementInputs);return e}get _hasPendingAttachmentHydration(){return this._allAttachmentInputs.some(e=>e.hasPendingAttachmentUpdateData)}get _layersSet(){const e=new Set;for(const t of this._workingFeatures){const s=E(t.plainGraphic);s&&e.add(s)}return e}applyStashedAttachmentEdits(e){const t=this._allAttachmentInputs;for(const s of e){const e=t.find(e=>e.label===s.label&&e.attachmentKeyword===s.keywords);e&&e.applyStashedEdits(s)}}findFieldInput(e){if(null==e)return;const t=this._activeFormInputsByElementId;if(t.has(e))return t.get(e);const s=this.activeForm.allFieldInputs.find(t=>t.template.elementId===e);return void 0!==s?(t.set(e,s),s):void 0}getFirstVisibleInvalidFieldInput(){if(this.hasVisibleInputs&&!this.activeForm.valid)for(const e of this.visibleInputs){if(K(e)){const t=e.inputs.find(e=>z(e)&&!e.valid);if(t)return{input:t,groupInput:e}}if(z(e)&&!e.valid)return{input:e}}}getFieldInputValue(e){return this.findFieldInput(e)?.value}getValues(e){const t=this._reactiveGraphicLookup.get(e);if(!t)throw new i("feature-not-found","The given feature is not present in the BatchAttributeForm");return{...t.attributes}}async goBack(){switch(this.page){case"replacing-attachment":return void this.setShowingSelectedAttachmentReplacePage(!1);case"viewing-attachment-details":return void this.setSelectedAttachment(null);case"adding-attachments":return void this.setSelectedAttachmentAddElementId(null);case"viewing-attachments":return void this.setSelectedAttachmentListElementId(null);case"viewing-associated-features":return void this.setActiveAssociationsLayer(null);case"viewing-associated-layers":return void this.setActiveAssociationsInput(null);case"viewing-related-categories":case"viewing-related-records":return void this.clearActiveRelationshipCategoryOrInput();default:return}}async goHome(){this.setShowingSelectedAttachmentReplacePage(!1),this.setSelectedAttachment(null),this.setSelectedAttachmentAddElementId(null),this.setSelectedAttachmentListElementId(null),this.setActiveAssociationsLayer(null),this.setActiveAssociationsInput(null),this.clearAllRelationshipSettings()}notifyGeometriesChanged(e){const t=[];for(const s of e){const e=this._reactiveGraphicLookup.get(s);e&&(t.push(e),e.geometry=s.geometry)}this._updatingHandles.consumePromise(this._valueChangeTransaction(async e=>this._expressionsManager.runGeometryDependentExpressions(t,e),"user"))}async overrideOriginalFeature(e,t){await(this._prepareTask?.promise);const s=this._reactiveGraphicLookup.get(e);s&&(s.original=t,this._updatingHandles.consumePromise(this._valueChangeTransaction(e=>this._expressionsManager.runOriginalFeatureDependentExpressions(s,e),"expression")))}async setFieldInputValue(e,t){const{fieldName:s}=e;await this._updatingHandles.addPromise(this._valueChangeTransaction(async a=>{for(const i of e.features)a.setValue(i,s,t)},"user",e))}async setFieldInputValuePerFeature(e,t){await this._updatingHandles.addPromise(this._valueChangeTransaction(async s=>{for(const[a,i]of t)s.setValue(a,e.fieldName,i);s.hasChanges&&(e.userHasChangedValue=!0)},"user",e))}async setValueForFieldName(e,t,s){await this._updatingHandles.addPromise(this._valueChangeTransaction(async a=>{for(const i of s){const s=this._reactiveGraphicLookup.get(i);s&&a.setValue(s,e,t)}},"user",e))}async setValuePerFeatureForFieldName(e,t){await this._updatingHandles.addPromise(this._valueChangeTransaction(async s=>{for(const[a,i]of t){const t=this._reactiveGraphicLookup.get(a);t&&s.setValue(t,e,i)}},"user",e))}async setFieldValue(e,t){const s=this.activeForm.allFieldInputs.find(t=>t.fieldName===e);if(null==s)throw new i("no-field-input-found",`Cannot set the value of FieldInput with field name: ${e} because none was found in the active form`);await this.setFieldInputValue(s,t)}async setValue(e,t){const s=this.findFieldInput(e);if(null==s)throw new i("no-FieldInput-found",`Cannot set the value of FieldInput with ID: ${e} because none was found in the active form`);await this.setFieldInputValue(s,t)}async applySubtypeDefaults(e){const{defaultValues:t}=e,{allFieldInputs:s}=this.activeForm;await this._updatingHandles.addPromise(this._valueChangeTransaction(async e=>{for(const a of s){const{fieldName:s}=a,i=t[s];if(null!=i)for(const t of a.features)e.setValue(t,s,i)}},"user"))}async handleSubtypeChanged(e){const t=this._workingFeatures.at(e);if(t)return this._updatingHandles.addPromise(this._handleSubtypeChanged(t))}async stageAddAttachments(e,t){if(0===t.length)return[];const s=this._findAttachmentInput(e);if(!s)return[];const a=await this._updatingHandles.addPromise(s.stageAddAttachments(t,this._expressionsManager.arcadeContext));return 0===a.length||(this.userHasChangedValues=!0,this._emitAttachmentsChange(s)),a}stageDeleteAttachment(e,t){const s=this._findAttachmentInput(e);if(!s)return;const a=this._findAttachment(s,t);a&&(s.stageDeleteAttachment(a),this.userHasChangedValues=!0,this._emitAttachmentsChange(s))}async stageRenameAttachment(e,t,s){const a=this._findAttachmentInput(e);if(!a)return;const i=this._findAttachment(a,t);i&&(a.stageRenameAttachment(i,s.trim()),this.userHasChangedValues=!0,await a.ensureStagedUpdateData(i),this._emitAttachmentsChange(a))}async stageReplaceAttachment(e,t,s){const a=this._findAttachmentInput(e);if(!a)return!1;const i=this._findAttachment(a,t);if(!i)return!1;return!!await this._updatingHandles.addPromise(a.stageReplaceAttachment(i,s,this._expressionsManager.arcadeContext))&&(this.userHasChangedValues=!0,this._emitAttachmentsChange(a),!0)}clearAttachmentChanges(e){const t=this._findAttachmentInput(e);t&&(t.clearAttachmentChanges(),this._emitAttachmentsChange(t))}setActiveAssociation(e){this._activeAssociation=e}setActiveAssociationsInput(e){this._activeAssociationsInput=e}setActiveAssociationsLayer(e){this._activeAssociationsInput?.setAssociatedLayer(e)}setActiveAssociationType(e){this._activeAssociationsInput?.setActiveAssociationType(e)}setActiveRelationshipInput(e){e||this._activeRelationshipInput?.setActiveCategory(null),this._activeRelationshipInput=e}setActiveRelationshipCategory(e,t){t.setActiveCategory(e),this.setActiveRelationshipInput(t)}clearAllRelationshipSettings(){const e=this.activeRelationshipInput;e&&(e.setActiveCategory(null),e.setShowAllCategories(!1),e.setShowAllRelatedRecords(!1),this._activeRelationshipInput=null)}clearActiveRelationshipCategoryOrInput(){const e=this.activeRelationshipInput;e&&(e.showAllRelatedRecords?e.showAllCategories?e.setActiveCategory(null):this.setActiveRelationshipInput(null):e.showAllCategories&&(e.setShowAllCategories(!1),this.setActiveRelationshipInput(null)))}resetAttachmentChanges(e,t){const s=this._findAttachmentInput(e);if(!s||!s.editable)return;const a=this._findAttachment(s,t);a&&(s.discardStagedEdits(a),this._emitAttachmentsChange(s))}setSelectedAttachment(e){this.selectedAttachment=e??null}setShowingSelectedAttachmentReplacePage(e){this.showingSelectedAttachmentReplacePage=e}setSelectedAttachmentAddElementId(e){this.selectedAttachmentAddElementId=e??null}setSelectedAttachmentListElementId(e){this.selectedAttachmentListElementId=e??null}userChangesHaveMadeFeatureInvalid(e){return!!this._reactiveGraphicLookup.get(e)?.userChangesHaveMadeInvalid}validate(){return!1}validateContingentValues(e,t=!1){if(t&&!this.submitHasBeenAttempted)for(const s of e)this._reactiveContingentValuesManager.validateContingenciesForNonNullFields(s);else for(const s of e)this._reactiveContingentValuesManager.validateContingencyConstraints(s,{includeIncompleteViolations:!0})}_makeBatchFormInputsForFeature(e){const t=this._layerTemplateMap.get(e.layer);return t?Z(t,{allFeatures:new a([e]),expressionsManager:this._expressionsManager,getExternalErrorForFeature:this._getExternalErrorForFeature,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}):this._emptyForm}async _ensureLayerTemplate(e,t){const{_layersSet:s,contingentValuesManager:a}=this,i=e.layer;let n=!1;for(const r of this._layerTemplateMap.keys())s.has(r)||(this._layerTemplateMap.delete(r),this._expressionsManager.layerExpressionsModelMap.delete(r),a.resetOptionsForLayer(r),ee(r)&&a.resetViolationsForLayer(r),n=!0);this._layerTemplateMap.has(i)||(await this._prepareLayer(i,t),c(t),a.layers.add(i),n=!0),n&&(this._prepareSharedFormTemplate(),$(this.sharedForm,this.sharedFormTemplate,{allFeatures:this._workingFeatures,expressionsManager:this._expressionsManager,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}),this._recomputeHasAsyncArcadeExpressions(),await A(()=>!a.updating,t))}_recomputeHasAsyncArcadeExpressions(){this._hasAsyncArcadeExpressions=!1;for(const e of this._expressionsManager.layerExpressionsModelMap.values())for(const t of e.arcadeExecutorUses.keys())if(t.isAsync)return void(this._hasAsyncArcadeExpressions=!0)}_computeFormHeaderField(e){const{activeFeature:t,activeLayer:s}=this;return e&&s&&t?O({attributes:t?.attributes,label:e,layer:s,timeZone:this.effectiveTimeZone}):null}_makeSubmitResults(){const e=new Map;for(const[s,a]of this._reactiveGraphicLookup){const i=[],n=[],r=this._featureFormMap.get(a)?.allAttachmentElementInputs??[];for(const e of r)t(i,e.toSubmitEdits()),e.valid||n.push(e.template.elementId);e.set(s,{feature:s,values:{...a.attributes},invalidFields:[],attachmentEdits:i,invalidAttachmentElementIds:n})}for(const t of this.sharedForm.allFieldInputs)for(const s of t.invalidFeatures)e.get(s)?.invalidFields.push(t.fieldName);return Array.from(e.values())}async _handleSubtypeChanged(e){const t=e.layer;if(this.contingentValuesManager.resetOptionsForFeature(t,e.plainGraphic),ee(t)&&this.contingentValuesManager.resetViolationsForFeature(t,e.plainGraphic),!T(t))return;const a=t.parent?.findSublayerForFeature(e.plainGraphic);if(!a)return;this._layerTemplateUpdateTask=h(this._layerTemplateUpdateTask);const i=s(async t=>{c(t),e.source.sourceLayer=a,e.source.origin=a.graphicOrigin,await this._ensureLayerTemplate(e,t),c(t),this._featureFormMap.get(e)?.destroy(),this._featureFormMap.set(e,this._makeBatchFormInputsForFeature(e)),await p(this._valueChangeTransaction(t=>this._expressionsManager.runAllExpressions([e],t),"user"),t),c(t)});this._layerTemplateUpdateTask=i,await u(this._updatingHandles.addPromise(i.promise))}_emitSubmit(){this.emit("submit",{name:"submit",results:this._makeSubmitResults(),valid:this.valid})}_findAttachmentInput(e){const t=this.activeForm.allAttachmentElementInputs.find(t=>t.template.elementId===e);return t||r.getLogger(this).error(`Attachment input not found for elementId '${e}'`),t}_findAttachment(e,t){const s=e.findAttachment(t);return s||r.getLogger(this).error(`Attachment '${t}' not found for attachment element '${e.template.elementId}'`),s}_makeAttachmentEdits(e){const s=[];for(const a of e.allAttachmentElementInputs)t(s,a.toSubmitEdits());return s}_emitAttachmentsChange(e){const t=e.single.feature;if(!t)return;const s=this._featureFormMap.get(t);this.emit("attachments-change",{name:"attachments-change",feature:t.source,attachmentEdits:this._makeAttachmentEdits(s??this.activeForm),valid:this.valid})}async _valueChangeTransaction(e,t,s){const a=new G(this,t,"string"==typeof s?s:s?.fieldName);if(await e(a),"user"===t&&await this._expressionsManager.runExpressionsDependentOnChangedFields(a),await a.close(),a.hasChanges&&s){const e="string"==typeof s?this.activeForm.allFieldInputs.find(e=>e.fieldName===s):s;e&&(e.userHasChangedValue=!0)}}_prepare(){this.pendingSubtypeChoice?.reject(),this._hasAsyncArcadeExpressions=!1,this._prepareTask=h(this._prepareTask),this._layerTemplateUpdateTask=h(this._layerTemplateUpdateTask),this._layerTemplateMap.clear(),this._updateWorkingFeatures(),l(this._expressionsManager),this.userHasChangedValues=!1,this._expressionsManager=new D({arcadeContext:{editType:this.editType,spatialReference:this.spatialReference??x.WebMercator,map:this.map,timeZone:this.timeZone||"system"}});const{layers:e}=this;if(0===e.length)return;const t=s(async t=>{try{c(t),this._updateWorkingFeatures(),this.contingentValuesManager.layers.addMany(e),await Promise.all(e.map(e=>e.load()));for(const s of e)await this._prepareLayer(s,t);if(this.hasTooManyComplexFeatures)throw new i("too-many-features-with-complex-forms","There are too many features to load into the form with the configured complexity");if(this.hasTooManyFeatures)throw new i("too-many-features","There are too many features to load into the form.");this._prepareSharedFormTemplate(),this.sharedForm=Z(this.sharedFormTemplate,{allFeatures:this._workingFeatures,expressionsManager:this._expressionsManager,getExternalErrorForFeature:this._getExternalErrorForFeature,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}),await this._valueChangeTransaction(async e=>await this._expressionsManager.runAllExpressions(this._workingFeatures.toArray(),e),"expression"),await A(()=>!this.contingentValuesManager.updating)}catch(s){throw d(s)||r.getLogger(this).error("Failed preparing form",s),s}});this._updatingHandles.consumePromise(t.promise),this._prepareTask=t}async _prepareLayer(e,t){const s=se(this.layerInfos,e),a=await J(e,{arcadeExecutorProvider:this._arcadeExecutorProvider,formTimeZone:this.timeZone,attachmentsEnabled:this.attachmentsEnabled},s?.formTemplate);c(t),this._layerTemplateMap.set(e,a);const i=a.getExpressionExecutorsForLayer(e);if(this._expressionsManager.layerExpressionsModelMap.set(e,new N({preserveFieldValuesWhenHidden:a.preserveFieldValuesWhenHidden,executorMap:i,fieldsIndex:e.fieldsIndex})),!this._hasAsyncArcadeExpressions)for(const n of i.values())if(n&&(this._hasAsyncArcadeExpressions=!0===(n.editableExpression?.isAsync||n.requiredExpression?.isAsync||n.valueExpression?.isAsync||n.visibilityExpression?.isAsync),this._hasAsyncArcadeExpressions))break}_prepareSharedFormTemplate(){const e=new Map;for(const t of this._layerTemplateMap.values())for(const s of t.elements){if(Q(s))continue;const t=s.clone();X(t)&&(t.elements=t.elements.filter(e=>!Q(e)));const{elementId:a}=t;e.has(a)?e.get(a).foldIn(t):e.set(a,t)}this.sharedFormTemplate=new q({elements:Array.from(e.values())})}_updateWorkingFeatures(){this._workingFeatures.destroyAll(),this._reactiveContingentValuesManager.reset();for(const t of this._featureFormMap.values())t.destroy();this._featureFormMap.clear(),this._attachmentCache.clear();const{features:e}=this;if(this._reactiveGraphicLookup=new m,0!==e.length){this._workingFeatures.addMany(e.map(R));for(const e of this._workingFeatures)this._reactiveGraphicLookup.set(e.source,e)}}async _syncAttachments(){const{activeFeature:e,activeLayer:t,activeForm:a}=this;if(!(e&&a&&H(t)&&P(t)))return;const i=e.getObjectId();if(null==i)return;const n=this._attachmentCache.get(t),r=a.allAttachmentElementInputs;if(!r.length)return;const l=s(async e=>{let s;if(n){const e=n.get(i);e&&(s=e)}if(!s){s=await j(t,i,r,e);o(this._attachmentCache,t,()=>new m).set(i,s)}for(const t of r)t.applyFetchedAttachments(oe(t,s))});this._syncAttachmentsTask=l,await u(l.promise)}get test(){return{expressionsManager:this._expressionsManager,reactiveGraphicLookup:this._reactiveGraphicLookup,syncAttachmentsTask:this._syncAttachmentsTask}}};e([F()],ae.prototype,"_attachmentCache",void 0),e([F({readOnly:!0})],ae.prototype,"activeFeature",null),e([F()],ae.prototype,"activeFeatureIndex",void 0),e([F({readOnly:!0})],ae.prototype,"activeForm",null),e([F({readOnly:!0})],ae.prototype,"activeLayer",null),e([F()],ae.prototype,"activeAssociation",null),e([F()],ae.prototype,"activeAssociationsInput",null),e([F()],ae.prototype,"activeAssociationType",null),e([F()],ae.prototype,"activeRelationshipInput",null),e([F()],ae.prototype,"attachmentsEnabled",void 0),e([F()],ae.prototype,"callbacks",void 0),e([F()],ae.prototype,"disabled",void 0),e([F()],ae.prototype,"calculating",null),e([F()],ae.prototype,"canGoBack",null),e([F()],ae.prototype,"contingentValuesManager",void 0),e([F()],ae.prototype,"editType",void 0),e([F()],ae.prototype,"features",void 0),e([F()],ae.prototype,"expressionEvaluationFailed",null),e([F()],ae.prototype,"hasNonActiveInvalidFeatures",null),e([F()],ae.prototype,"hasAsyncArcadeExpressions",null),e([F()],ae.prototype,"_hasAsyncArcadeExpressions",void 0),e([F()],ae.prototype,"invalidFeatures",null),e([F()],ae.prototype,"hasVisibleInputs",null),e([F()],ae.prototype,"hasLayersWithContingentValues",null),e([F()],ae.prototype,"formDescription",null),e([F()],ae.prototype,"formTitle",null),e([F()],ae.prototype,"effectiveTimeZone",null),e([F()],ae.prototype,"highlightHelper",void 0),e([F()],ae.prototype,"maximumFeatureCount",void 0),e([F()],ae.prototype,"maximumFeatureCountWithComplexForms",void 0),e([F()],ae.prototype,"visibleInputs",null),e([F()],ae.prototype,"map",void 0),e([F()],ae.prototype,"noVisibleElementsReason",null),e([F()],ae.prototype,"page",null),e([F()],ae.prototype,"pageStack",void 0),e([F()],ae.prototype,"readOnly",void 0),e([F()],ae.prototype,"pendingSubtypeChoice",void 0),e([F()],ae.prototype,"subtypes",null),e([F()],ae.prototype,"spatialReference",void 0),e([F()],ae.prototype,"submitHasBeenAttempted",void 0),e([F()],ae.prototype,"timeZone",void 0),e([F()],ae.prototype,"updating",null),e([F()],ae.prototype,"valid",null),e([F()],ae.prototype,"layers",null),e([F()],ae.prototype,"mode",null),e([F()],ae.prototype,"sharedForm",void 0),e([F()],ae.prototype,"sharedFormTemplate",void 0),e([F()],ae.prototype,"selectedAttachment",null),e([F()],ae.prototype,"selectedAttachmentAddElementId",null),e([F()],ae.prototype,"selectedAttachmentListElementId",null),e([F()],ae.prototype,"selectedAttachmentListInput",null),e([F()],ae.prototype,"showingSelectedAttachmentReplacePage",null),e([F()],ae.prototype,"selectedAttachmentAddInput",null),e([F()],ae.prototype,"selectedAttachmentDetails",null),e([F()],ae.prototype,"userHasChangedValues",void 0),e([F()],ae.prototype,"layerInfos",void 0),e([F()],ae.prototype,"_arcadeExecutorProvider",void 0),e([F()],ae.prototype,"_activeAssociation",void 0),e([F()],ae.prototype,"_activeAssociationsInput",void 0),e([F()],ae.prototype,"_activeRelationshipInput",void 0),e([F()],ae.prototype,"_prepareTask",void 0),e([F()],ae.prototype,"_reactiveGraphicLookup",void 0),e([F()],ae.prototype,"_allAttachmentInputs",null),e([F()],ae.prototype,"_hasPendingAttachmentHydration",null),e([F()],ae.prototype,"_layerTemplateMap",void 0),e([F()],ae.prototype,"_layersSet",null),e([F()],ae.prototype,"_workingFeatures",void 0),e([F()],ae.prototype,"_expressionsManager",void 0),ae=e([I("esri.widgets.BatchAttributeForm.BatchAttributeFormViewModel")],ae);const ie=ae;function ne(e){return null!=e&&e.trim().length>0}function re(e,t){const s=e.keywords;return ne(s)&&s.toLowerCase()===t}function oe(e,t){const s="attachment"===e.input?.type?e.input.attachmentAssociationType:"exact",a=e.attachmentKeyword;if("any"===s)return t;if("exactOrNone"===s){if(te(a))return t.filter(e=>!ne(e.keywords));const e=a.toLowerCase();return t.filter(t=>!ne(t.keywords)||re(t,e))}if(te(a))return t;const i=a.toLowerCase();return t.filter(e=>re(e,i))}export{ie as default};
2
+ import{__decorate as e}from"tslib";import{pushIfSome as t}from"../../core/arrayUtils.js";import{createTask as s}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import i from"../../core/Error.js";import{EventedAccessor as n}from"../../core/Evented.js";import r from"../../core/Logger.js";import{getOrCreateMapValue as o}from"../../core/MapUtils.js";import{destroyMaybe as l,abortMaybe as h}from"../../core/maybe.js";import{throwIfAborted as c,whenOrAbort as p,ignoreAbortErrors as u,isAbortError as m}from"../../core/promiseUtils.js";import d from"../../core/ReactiveMap.js";import{on as g,sync as y,watch as f,syncAndInitial as v,initial as _,whenOnce as A}from"../../core/reactiveUtils.js";import{property as F,subclass as I}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as w}from"../../core/support/UpdatingHandles.js";import x from"../../geometry/SpatialReference.js";import{getGraphicLayer as E}from"../../graphic/graphicOriginUtils.js";import{isSubtypeGroupLayer as C,isSubtypeSublayer as T,isFeatureLayer as M,getSubtypesFromLayer as k}from"../../layers/support/layerUtils.js";import{system as b}from"../../time/constants.js";import{getAttachmentKey as V}from"./attachmentUtils.js";import{getLayerTimeZone as S,getEffectiveTimeZone as L,createReactiveGraphic as R,isAttributeFormSupportedLayerWithAttachments as H,layerSupportsAttachments as P,queryAttachmentsForElements as j}from"./batchAttributeFormUtils.js";import{ReactiveContingentValuesManager as U}from"./ReactiveContingentValuesManager.js";import{parseFormTemplateString as O}from"./stringUtils.js";import{ValueChangeTransaction as G}from"./ValueChangeTransaction.js";import{ArcadeExecutorProvider as B}from"./expressions/ArcadeExecutorProvider.js";import{ExpressionsManager as D}from"./expressions/ExpressionsManager.js";import{ExpressionsModel as N}from"./expressions/ExpressionsModel.js";import Z from"./inputs/BatchFormInputs.js";import{createBatchFormInputsFromBatchFormTemplate as W,mergeBatchFormInputsFromNewTemplate as $}from"./inputs/support/createBatchFormInputs.js";import{isGroupInput as K,isFieldInput as z}from"./inputs/support/inputUtils.js";import q from"./templates/BatchFormTemplate.js";import{createBatchFormTemplate as J}from"./templates/support/createBatchFormTemplate.js";import{isExcludedFromSharedForm as Q,isGroupElementTemplate as X}from"./templates/support/templateUtils.js";import{ContingentValuesManager as Y,isLayerWithContingentValues as ee}from"../support/ContingentValuesManager.js";import{isEmptyValue as te}from"../support/forms/formUtils.js";function se(e,t){return e?.find(e=>e.layer===t)}let ae=class extends n{constructor(e){super(e),this._attachmentCache=new d,this.activeFeatureIndex=-1,this.attachmentsEnabled=!1,this.callbacks=null,this.disabled=!1,this.editType="NA",this.features=new a,this._hasAsyncArcadeExpressions=!1,this.highlightHelper=null,this.maximumFeatureCount=2e3,this.maximumFeatureCountWithComplexForms=50,this.pageStack=[],this.readOnly=!1,this.pendingSubtypeChoice=null,this.spatialReference=null,this.submitHasBeenAttempted=!1,this.view=null,this.userHasChangedValues=!1,this.layerInfos=null,this._arcadeExecutorProvider=new B,this._activeAssociation=null,this._activeAssociationsInput=null,this._activeRelationshipInput=null,this._ownContingentValuesManager=null,this._activeFormInputsByElementId=new Map,this._emptyForm=new Z({inputs:[]}),this._emptyFormTemplate=new q({elements:[]}),this._featureFormMap=new d,this._prepareTask=null,this._layerTemplateUpdateTask=null,this._syncAttachmentsTask=null,this._reactiveGraphicLookup=new d,this._updatingHandles=new w,this._submitTask=null,this._layerTemplateMap=new d,this._workingFeatures=new a,this._expressionsManager=new D({arcadeContext:{editType:"NA",spatialReference:null,map:null,timeZone:b}}),this._getExternalErrorForFeature=(e,t)=>this._reactiveContingentValuesManager.getViolationTypeForField(e,t),this._getFieldValueOptionsForFeature=e=>this._reactiveContingentValuesManager.getAndWatchFieldValueOptions(e),this.sharedForm=this._emptyForm,this.sharedFormTemplate=this._emptyFormTemplate}initialize(){this.contingentValuesManager||(this.contingentValuesManager=this._ownContingentValuesManager=new Y),this.addHandles([g(()=>this.features,"after-changes",()=>{this.goHome(),this.notifyChange("layers"),this._prepare()},y),f(()=>[this.attachmentsEnabled,this.features,this.map,this.timeZone,this.editType],()=>this._prepare(),y),f(()=>this.activeForm,()=>{this.goHome(),this._activeFormInputsByElementId.clear(),this._syncAttachments()},y),f(()=>this.activeFeature,()=>{this.goHome()},y),f(()=>this.page,e=>{const t=[...this.pageStack];if(t.includes(e))for(;t.length&&t.at(-1)!==e;)t.pop();else t.push(e);this.pageStack=t},v),f(()=>this.contingentValuesManager,e=>{l(this._reactiveContingentValuesManager),this._reactiveContingentValuesManager=new U({manager:e})},_)]),this._prepare()}destroy(){this._prepareTask=h(this._prepareTask),this.pendingSubtypeChoice?.reject(),this._layerTemplateUpdateTask=h(this._layerTemplateUpdateTask),this._syncAttachmentsTask=h(this._syncAttachmentsTask),this._workingFeatures.destroyAll(),l(this._expressionsManager),l(this._reactiveContingentValuesManager),this._updatingHandles.destroy(),this._reactiveGraphicLookup=new d,this._emptyForm.destroy(),this._emptyFormTemplate.destroy(),this._ownContingentValuesManager=l(this._ownContingentValuesManager),this.highlightHelper?.removeAll()}get activeFeature(){const e=this.activeFeatureIndex;return e<0?null:this.features.at(e)}get activeForm(){if("batch"===this.mode)return this.sharedForm;const e=this._workingFeatures.at(this.activeFeatureIndex);if(!e)return this._emptyForm;const t=this._featureFormMap.get(e);if(t)return t;const s=this._makeBatchFormInputsForFeature(e);return s!==this._emptyForm&&this._featureFormMap.set(e,s),s}get activeLayer(){const{activeFeature:e}=this;if(!e)return null;return E(e)??null}get activeAssociation(){return this._activeAssociation}get activeAssociationsInput(){return this._activeAssociationsInput}get activeAssociationType(){return this.activeAssociationsInput?.activeAssociationType}get activeRelationshipInput(){return this._activeRelationshipInput}get calculating(){return this._expressionsManager.calculating}get expressionsManager(){return this._expressionsManager}get canGoBack(){return this.pageStack.length>1}get expressionEvaluationFailed(){return this._expressionsManager.expressionEvaluationFailed}get hasNonActiveInvalidFeatures(){if("batch"===this.mode)return!1;const{activeFeature:e}=this;return this.invalidFeatures.some(t=>t!==e)}get hasAsyncArcadeExpressions(){return this._hasAsyncArcadeExpressions}get hasTooManyFeatures(){return this._workingFeatures.length>this.maximumFeatureCount}get hasTooManyComplexFeatures(){return this._workingFeatures.length>this.maximumFeatureCountWithComplexForms&&this.hasAsyncArcadeExpressions}get invalidFeatures(){return this.sharedForm.invalidFeatures}get hasVisibleInputs(){return this.visibleInputs.length>0}get hasLayersWithContingentValues(){const e=this.contingentValuesManager;for(const t of this.layers)if(e.getFieldsWithContingentValues(t).size>0)return!0;return!1}get formDescription(){return this._computeFormHeaderField(this.activeForm?.description)}get formTitle(){return this._computeFormHeaderField(this.activeForm?.title)}get effectiveTimeZone(){const{activeLayer:e,timeZone:t}=this;if(!e)return t??"system";const s=S(e);return L(t,s)}get visibleInputs(){return this.activeForm.inputs.filter(e=>e.visible)}get map(){return this.view?.map??null}set map(e){this._override("map",e)}get noVisibleElementsReason(){if(this.hasVisibleInputs)return null;if(0===this.activeForm.inputs.length)return"noElements";const e=new Set;for(const t of this.activeForm.inputs)switch(t.visibilityCode){case"hidden:not-in-all-layers":case"hidden:no-domain-in-common":e.add("noElementsInCommon");break;case"hidden:field-definition":case"hidden:group-visibility-expression:all-features":case"hidden:visibility-expression:all-features":e.add("allElementsHidden");break;case"hidden:group-visibility-expression:some-features":case"hidden:visibility-expression:some-features":return"elementsHiddenInSome"}return e.has("allElementsHidden")?"allElementsHidden":"noElementsInCommon"}get page(){return this.showingSelectedAttachmentReplacePage&&this.selectedAttachmentDetails?"replacing-attachment":this.selectedAttachmentDetails?"viewing-attachment-details":this.selectedAttachmentAddInput?"adding-attachments":this.selectedAttachmentListInput?"viewing-attachments":this.activeAssociationsInput?.associatedLayer?"viewing-associated-features":this.activeAssociationsInput?"viewing-associated-layers":this.activeRelationshipInput?.showAllRelatedRecords?"viewing-related-records":this.activeRelationshipInput?.showAllCategories?"viewing-related-categories":"default"}get subtypes(){const e=this.activeLayer;return C(e)||T(e)||M(e)?k(e):[]}get status(){const e=this._prepareTask;return null==e?"not-loaded":e.finished?null!=e.error?"failed":"loaded":"loading"}get timeZone(){return this.view?.timeZone??null}set timeZone(e){this._overrideIfSome("timeZone",e)}get updating(){return this._updatingHandles.updating||this.calculating}get valid(){return this.sharedForm.valid&&Array.from(this._featureFormMap.values()).every(e=>e.valid)}get layers(){return Array.from(this._layersSet)}get mode(){return this.activeFeatureIndex>-1?"single":"batch"}submit(){if(this.submitHasBeenAttempted=!0,this.validateContingentValues(this._workingFeatures),!this._hasPendingAttachmentHydration)return this._emitSubmit(),Promise.resolve();if(this._submitTask)return this._submitTask.promise;const e=s(async()=>{await Promise.all(this._allAttachmentInputs.map(e=>e.waitForPendingAttachmentUpdateData())),this._emitSubmit()});return this._submitTask=e,e.promise.finally(()=>{this._submitTask===e&&(this._submitTask=null)}),e.promise}get selectedAttachment(){return this._get("selectedAttachment")??null}set selectedAttachment(e){this.showingSelectedAttachmentReplacePage=!1,this._set("selectedAttachment",e),null!=e&&(this.selectedAttachmentAddElementId=null)}get selectedAttachmentAddElementId(){return this._get("selectedAttachmentAddElementId")??null}set selectedAttachmentAddElementId(e){this.showingSelectedAttachmentReplacePage=!1,this._set("selectedAttachmentAddElementId",e),null!=e&&(this.selectedAttachment=null,this.selectedAttachmentListElementId=null)}get selectedAttachmentListElementId(){return this._get("selectedAttachmentListElementId")??null}set selectedAttachmentListElementId(e){this._set("selectedAttachmentListElementId",e),null!=e&&(this.selectedAttachment=null,this.selectedAttachmentAddElementId=null)}get selectedAttachmentListInput(){const e=this.selectedAttachmentListElementId,t=this.activeForm;if(!e||!t)return null;const s=t.allAttachmentElementInputs.find(t=>t.template.elementId===e)||null;return s?.attachments.length?s:null}get showingSelectedAttachmentReplacePage(){return this._get("showingSelectedAttachmentReplacePage")??!1}set showingSelectedAttachmentReplacePage(e){this._set("showingSelectedAttachmentReplacePage",e&&null!=this.selectedAttachmentDetails)}get selectedAttachmentAddInput(){const e=this.selectedAttachmentAddElementId,t=this.activeForm;return e&&t&&t.allAttachmentElementInputs.find(t=>t.template.elementId===e)||null}get selectedAttachmentDetails(){const e=this.selectedAttachment,t=this.activeForm;if(!e||!t)return null;const s=t.allAttachmentElementInputs.find(t=>t.template.elementId===e.elementId);if(!s)return null;const a=s.attachments.findIndex(t=>V(t)===e.attachmentKey);if(-1===a)return null;return{attachment:s.attachments[a],input:s}}get _allAttachmentInputs(){const e=[...this.sharedForm.allAttachmentElementInputs];for(const t of this._featureFormMap.values())e.push(...t.allAttachmentElementInputs);return e}get _hasPendingAttachmentHydration(){return this._allAttachmentInputs.some(e=>e.hasPendingAttachmentUpdateData)}get _layersSet(){const e=new Set;for(const t of this._workingFeatures){const s=E(t.plainGraphic);s&&e.add(s)}return e}applyStashedAttachmentEdits(e){const t=this._allAttachmentInputs;for(const s of e){const e=t.find(e=>e.label===s.label&&e.attachmentKeyword===s.keywords);e&&e.applyStashedEdits(s)}}findFieldInput(e){if(null==e)return;const t=this._activeFormInputsByElementId;if(t.has(e))return t.get(e);const s=this.activeForm.allFieldInputs.find(t=>t.template.elementId===e);return void 0!==s?(t.set(e,s),s):void 0}getFirstVisibleInvalidFieldInput(){if(this.hasVisibleInputs&&!this.activeForm.valid)for(const e of this.visibleInputs){if(K(e)){const t=e.inputs.find(e=>z(e)&&!e.valid);if(t)return{input:t,groupInput:e}}if(z(e)&&!e.valid)return{input:e}}}getFieldInputValue(e){return this.findFieldInput(e)?.value}getValues(e){const t=this._reactiveGraphicLookup.get(e);if(!t)throw new i("feature-not-found","The given feature is not present in the BatchAttributeForm");return{...t.attributes}}async goBack(){switch(this.page){case"replacing-attachment":return void this.setShowingSelectedAttachmentReplacePage(!1);case"viewing-attachment-details":return void this.setSelectedAttachment(null);case"adding-attachments":return void this.setSelectedAttachmentAddElementId(null);case"viewing-attachments":return void this.setSelectedAttachmentListElementId(null);case"viewing-associated-features":return void this.setActiveAssociationsLayer(null);case"viewing-associated-layers":return void this.setActiveAssociationsInput(null);case"viewing-related-categories":case"viewing-related-records":return void this.clearActiveRelationshipCategoryOrInput();default:return}}async goHome(){this.setShowingSelectedAttachmentReplacePage(!1),this.setSelectedAttachment(null),this.setSelectedAttachmentAddElementId(null),this.setSelectedAttachmentListElementId(null),this.setActiveAssociationsLayer(null),this.setActiveAssociationsInput(null),this.clearAllRelationshipSettings()}notifyGeometriesChanged(e){const t=[];for(const s of e){const e=this._reactiveGraphicLookup.get(s);e&&(t.push(e),e.geometry=s.geometry)}this._updatingHandles.consumePromise(this._valueChangeTransaction(async e=>this._expressionsManager.runGeometryDependentExpressions(t,e),"user"))}async overrideOriginalFeature(e,t){await(this._prepareTask?.promise);const s=this._reactiveGraphicLookup.get(e);s&&(s.original=t,this._updatingHandles.consumePromise(this._valueChangeTransaction(e=>this._expressionsManager.runOriginalFeatureDependentExpressions(s,e),"expression")))}async setFieldInputValue(e,t){const{fieldName:s}=e;await this._updatingHandles.addPromise(this._valueChangeTransaction(async a=>{for(const i of e.features)a.setValue(i,s,t)},"user",e))}async setFieldInputValuePerFeature(e,t){await this._updatingHandles.addPromise(this._valueChangeTransaction(async s=>{for(const[a,i]of t)s.setValue(a,e.fieldName,i);s.hasChanges&&(e.userHasChangedValue=!0)},"user",e))}async setValueForFieldName(e,t,s){await this._updatingHandles.addPromise(this._valueChangeTransaction(async a=>{for(const i of s){const s=this._reactiveGraphicLookup.get(i);s&&a.setValue(s,e,t)}},"user",e))}async setValuePerFeatureForFieldName(e,t){await this._updatingHandles.addPromise(this._valueChangeTransaction(async s=>{for(const[a,i]of t){const t=this._reactiveGraphicLookup.get(a);t&&s.setValue(t,e,i)}},"user",e))}async setFieldValue(e,t){const s=this.activeForm.allFieldInputs.find(t=>t.fieldName===e);if(null==s)throw new i("no-field-input-found",`Cannot set the value of FieldInput with field name: ${e} because none was found in the active form`);await this.setFieldInputValue(s,t)}async setValue(e,t){const s=this.findFieldInput(e);if(null==s)throw new i("no-FieldInput-found",`Cannot set the value of FieldInput with ID: ${e} because none was found in the active form`);await this.setFieldInputValue(s,t)}async applySubtypeDefaults(e){const{defaultValues:t}=e,{allFieldInputs:s}=this.activeForm;await this._updatingHandles.addPromise(this._valueChangeTransaction(async e=>{for(const a of s){const{fieldName:s}=a,i=t[s];if(null!=i)for(const t of a.features)e.setValue(t,s,i)}},"user"))}async handleSubtypeChanged(e){const t=this._workingFeatures.at(e);if(t)return this._updatingHandles.addPromise(this._handleSubtypeChanged(t))}async stageAddAttachments(e,t){if(0===t.length)return[];const s=this._findAttachmentInput(e);if(!s)return[];const a=await this._updatingHandles.addPromise(s.stageAddAttachments(t,this._expressionsManager.arcadeContext));return 0===a.length||(this.userHasChangedValues=!0,this._emitAttachmentsChange(s)),a}stageDeleteAttachment(e,t){const s=this._findAttachmentInput(e);if(!s)return;const a=this._findAttachment(s,t);a&&(s.stageDeleteAttachment(a),this.userHasChangedValues=!0,this._emitAttachmentsChange(s))}async stageRenameAttachment(e,t,s){const a=this._findAttachmentInput(e);if(!a)return;const i=this._findAttachment(a,t);i&&(a.stageRenameAttachment(i,s.trim()),this.userHasChangedValues=!0,await a.ensureStagedUpdateData(i),this._emitAttachmentsChange(a))}async stageReplaceAttachment(e,t,s){const a=this._findAttachmentInput(e);if(!a)return!1;const i=this._findAttachment(a,t);if(!i)return!1;return!!await this._updatingHandles.addPromise(a.stageReplaceAttachment(i,s,this._expressionsManager.arcadeContext))&&(this.userHasChangedValues=!0,this._emitAttachmentsChange(a),!0)}clearAttachmentChanges(e){const t=this._findAttachmentInput(e);t&&(t.clearAttachmentChanges(),this._emitAttachmentsChange(t))}setActiveAssociation(e){this._activeAssociation=e}setActiveAssociationsInput(e){this._activeAssociationsInput=e}setActiveAssociationsLayer(e){this._activeAssociationsInput?.setAssociatedLayer(e)}setActiveAssociationType(e){this._activeAssociationsInput?.setActiveAssociationType(e)}setActiveRelationshipInput(e){e||this._activeRelationshipInput?.setActiveCategory(null),this._activeRelationshipInput=e}setActiveRelationshipCategory(e,t){t.setActiveCategory(e),this.setActiveRelationshipInput(t)}clearAllRelationshipSettings(){const e=this.activeRelationshipInput;e&&(e.setActiveCategory(null),e.setShowAllCategories(!1),e.setShowAllRelatedRecords(!1),this._activeRelationshipInput=null)}clearActiveRelationshipCategoryOrInput(){const e=this.activeRelationshipInput;e&&(e.showAllRelatedRecords?e.showAllCategories?e.setActiveCategory(null):this.setActiveRelationshipInput(null):e.showAllCategories&&(e.setShowAllCategories(!1),this.setActiveRelationshipInput(null)))}resetAttachmentChanges(e,t){const s=this._findAttachmentInput(e);if(!s||!s.editable)return;const a=this._findAttachment(s,t);a&&(s.discardStagedEdits(a),this._emitAttachmentsChange(s))}setSelectedAttachment(e){this.selectedAttachment=e??null}setShowingSelectedAttachmentReplacePage(e){this.showingSelectedAttachmentReplacePage=e}setSelectedAttachmentAddElementId(e){this.selectedAttachmentAddElementId=e??null}setSelectedAttachmentListElementId(e){this.selectedAttachmentListElementId=e??null}userChangesHaveMadeFeatureInvalid(e){return!!this._reactiveGraphicLookup.get(e)?.userChangesHaveMadeInvalid}validate(){return!1}validateContingentValues(e,t=!1){if(t&&!this.submitHasBeenAttempted)for(const s of e)this._reactiveContingentValuesManager.validateContingenciesForNonNullFields(s);else for(const s of e)this._reactiveContingentValuesManager.validateContingencyConstraints(s,{includeIncompleteViolations:!0})}_makeBatchFormInputsForFeature(e){const t=this._layerTemplateMap.get(e.layer);return t?W(t,{allFeatures:new a([e]),expressionsManager:this._expressionsManager,getExternalErrorForFeature:this._getExternalErrorForFeature,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}):this._emptyForm}async _ensureLayerTemplate(e,t){const{_layersSet:s,contingentValuesManager:a}=this,i=e.layer;let n=!1;for(const r of this._layerTemplateMap.keys())s.has(r)||(this._layerTemplateMap.delete(r),this._expressionsManager.layerExpressionsModelMap.delete(r),a.resetOptionsForLayer(r),ee(r)&&a.resetViolationsForLayer(r),n=!0);this._layerTemplateMap.has(i)||(await this._prepareLayer(i,t),c(t),a.layers.add(i),n=!0),n&&(this._prepareSharedFormTemplate(),$(this.sharedForm,this.sharedFormTemplate,{allFeatures:this._workingFeatures,expressionsManager:this._expressionsManager,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}),this._recomputeHasAsyncArcadeExpressions(),await A(()=>!a.updating,t))}_recomputeHasAsyncArcadeExpressions(){this._hasAsyncArcadeExpressions=!1;for(const e of this._expressionsManager.layerExpressionsModelMap.values())for(const t of e.arcadeExecutorUses.keys())if(t.isAsync)return void(this._hasAsyncArcadeExpressions=!0)}_computeFormHeaderField(e){const{activeFeature:t,activeLayer:s}=this;return e&&s&&t?O({attributes:t?.attributes,label:e,layer:s,timeZone:this.effectiveTimeZone}):null}_makeSubmitResults(){const e=new Map;for(const[s,a]of this._reactiveGraphicLookup){const i=[],n=[],r=this._featureFormMap.get(a)?.allAttachmentElementInputs??[];for(const e of r)t(i,e.toSubmitEdits()),e.valid||n.push(e.template.elementId);e.set(s,{feature:s,values:{...a.attributes},invalidFields:[],attachmentEdits:i,invalidAttachmentElementIds:n})}for(const t of this.sharedForm.allFieldInputs)for(const s of t.invalidFeatures)e.get(s)?.invalidFields.push(t.fieldName);return Array.from(e.values())}async _handleSubtypeChanged(e){const t=e.layer;if(this.contingentValuesManager.resetOptionsForFeature(t,e.plainGraphic),ee(t)&&this.contingentValuesManager.resetViolationsForFeature(t,e.plainGraphic),!T(t))return;const a=t.parent?.findSublayerForFeature(e.plainGraphic);if(!a)return;this._layerTemplateUpdateTask=h(this._layerTemplateUpdateTask);const i=s(async t=>{c(t),e.source.sourceLayer=a,e.source.origin=a.graphicOrigin,await this._ensureLayerTemplate(e,t),c(t),this._featureFormMap.get(e)?.destroy(),this._featureFormMap.set(e,this._makeBatchFormInputsForFeature(e)),await p(this._valueChangeTransaction(t=>this._expressionsManager.runAllExpressions([e],t),"user"),t),c(t)});this._layerTemplateUpdateTask=i,await u(this._updatingHandles.addPromise(i.promise))}_emitSubmit(){this.emit("submit",{name:"submit",results:this._makeSubmitResults(),valid:this.valid})}_findAttachmentInput(e){const t=this.activeForm.allAttachmentElementInputs.find(t=>t.template.elementId===e);return t||r.getLogger(this).error(`Attachment input not found for elementId '${e}'`),t}_findAttachment(e,t){const s=e.findAttachment(t);return s||r.getLogger(this).error(`Attachment '${t}' not found for attachment element '${e.template.elementId}'`),s}_makeAttachmentEdits(e){const s=[];for(const a of e.allAttachmentElementInputs)t(s,a.toSubmitEdits());return s}_emitAttachmentsChange(e){const t=e.single.feature;if(!t)return;const s=this._featureFormMap.get(t);this.emit("attachments-change",{name:"attachments-change",feature:t.source,attachmentEdits:this._makeAttachmentEdits(s??this.activeForm),valid:this.valid})}async _valueChangeTransaction(e,t,s){const a=new G(this,t,"string"==typeof s?s:s?.fieldName);if(await e(a),"user"===t&&await this._expressionsManager.runExpressionsDependentOnChangedFields(a),await a.close(),a.hasChanges&&s){const e="string"==typeof s?this.activeForm.allFieldInputs.find(e=>e.fieldName===s):s;e&&(e.userHasChangedValue=!0)}}_prepare(){this.pendingSubtypeChoice?.reject(),this._hasAsyncArcadeExpressions=!1,this._prepareTask=h(this._prepareTask),this._layerTemplateUpdateTask=h(this._layerTemplateUpdateTask),this._layerTemplateMap.clear(),this._updateWorkingFeatures(),l(this._expressionsManager),this.userHasChangedValues=!1,this._expressionsManager=new D({arcadeContext:{editType:this.editType,spatialReference:this.spatialReference??x.WebMercator,map:this.map,timeZone:this.timeZone||"system"}});const{layers:e}=this;if(0===e.length)return;const t=s(async t=>{try{c(t),this._updateWorkingFeatures(),this.contingentValuesManager.layers.addMany(e),await Promise.all(e.map(e=>e.load()));for(const s of e)await this._prepareLayer(s,t);if(this.hasTooManyComplexFeatures)throw new i("too-many-features-with-complex-forms","There are too many features to load into the form with the configured complexity");if(this.hasTooManyFeatures)throw new i("too-many-features","There are too many features to load into the form.");this._prepareSharedFormTemplate(),this.sharedForm=W(this.sharedFormTemplate,{allFeatures:this._workingFeatures,expressionsManager:this._expressionsManager,getExternalErrorForFeature:this._getExternalErrorForFeature,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}),await this._valueChangeTransaction(async e=>await this._expressionsManager.runAllExpressions(this._workingFeatures.toArray(),e),"expression"),await A(()=>!this.contingentValuesManager.updating)}catch(s){throw m(s)||r.getLogger(this).error("Failed preparing form",s),s}});this._updatingHandles.consumePromise(t.promise),this._prepareTask=t}async _prepareLayer(e,t){const s=se(this.layerInfos,e),a=await J(e,{arcadeExecutorProvider:this._arcadeExecutorProvider,formTimeZone:this.timeZone,attachmentsEnabled:this.attachmentsEnabled},s?.formTemplate);c(t),this._layerTemplateMap.set(e,a);const i=a.getExpressionExecutorsForLayer(e);if(this._expressionsManager.layerExpressionsModelMap.set(e,new N({preserveFieldValuesWhenHidden:a.preserveFieldValuesWhenHidden,executorMap:i,fieldsIndex:e.fieldsIndex})),!this._hasAsyncArcadeExpressions)for(const n of i.values())if(n&&(this._hasAsyncArcadeExpressions=!0===(n.editableExpression?.isAsync||n.requiredExpression?.isAsync||n.valueExpression?.isAsync||n.visibilityExpression?.isAsync),this._hasAsyncArcadeExpressions))break}_prepareSharedFormTemplate(){const e=new Map;for(const t of this._layerTemplateMap.values())for(const s of t.elements){if(Q(s))continue;const t=s.clone();X(t)&&(t.elements=t.elements.filter(e=>!Q(e)));const{elementId:a}=t;e.has(a)?e.get(a).foldIn(t):e.set(a,t)}this.sharedFormTemplate=new q({elements:Array.from(e.values())})}_updateWorkingFeatures(){this._workingFeatures.destroyAll(),this._reactiveContingentValuesManager.reset();for(const t of this._featureFormMap.values())t.destroy();this._featureFormMap.clear(),this._attachmentCache.clear();const{features:e}=this;if(this._reactiveGraphicLookup=new d,0!==e.length){this._workingFeatures.addMany(e.map(R));for(const e of this._workingFeatures)this._reactiveGraphicLookup.set(e.source,e)}}async _syncAttachments(){const{activeFeature:e,activeLayer:t,activeForm:a}=this;if(!(e&&a&&H(t)&&P(t)))return;const i=e.getObjectId();if(null==i)return;const n=this._attachmentCache.get(t),r=a.allAttachmentElementInputs;if(!r.length)return;const l=s(async e=>{let s;if(n){const e=n.get(i);e&&(s=e)}if(!s){s=await j(t,i,r,e);o(this._attachmentCache,t,()=>new d).set(i,s)}for(const t of r)t.applyFetchedAttachments(oe(t,s))});this._syncAttachmentsTask=l,await u(l.promise)}get test(){return{expressionsManager:this._expressionsManager,reactiveGraphicLookup:this._reactiveGraphicLookup,syncAttachmentsTask:this._syncAttachmentsTask}}};e([F()],ae.prototype,"_attachmentCache",void 0),e([F({readOnly:!0})],ae.prototype,"activeFeature",null),e([F()],ae.prototype,"activeFeatureIndex",void 0),e([F({readOnly:!0})],ae.prototype,"activeForm",null),e([F({readOnly:!0})],ae.prototype,"activeLayer",null),e([F()],ae.prototype,"activeAssociation",null),e([F()],ae.prototype,"activeAssociationsInput",null),e([F()],ae.prototype,"activeAssociationType",null),e([F()],ae.prototype,"activeRelationshipInput",null),e([F()],ae.prototype,"attachmentsEnabled",void 0),e([F()],ae.prototype,"callbacks",void 0),e([F()],ae.prototype,"disabled",void 0),e([F()],ae.prototype,"calculating",null),e([F()],ae.prototype,"canGoBack",null),e([F()],ae.prototype,"contingentValuesManager",void 0),e([F()],ae.prototype,"editType",void 0),e([F()],ae.prototype,"features",void 0),e([F()],ae.prototype,"expressionEvaluationFailed",null),e([F()],ae.prototype,"hasNonActiveInvalidFeatures",null),e([F()],ae.prototype,"hasAsyncArcadeExpressions",null),e([F()],ae.prototype,"_hasAsyncArcadeExpressions",void 0),e([F()],ae.prototype,"invalidFeatures",null),e([F()],ae.prototype,"hasVisibleInputs",null),e([F()],ae.prototype,"hasLayersWithContingentValues",null),e([F()],ae.prototype,"formDescription",null),e([F()],ae.prototype,"formTitle",null),e([F()],ae.prototype,"effectiveTimeZone",null),e([F()],ae.prototype,"highlightHelper",void 0),e([F()],ae.prototype,"maximumFeatureCount",void 0),e([F()],ae.prototype,"maximumFeatureCountWithComplexForms",void 0),e([F()],ae.prototype,"visibleInputs",null),e([F()],ae.prototype,"map",null),e([F()],ae.prototype,"noVisibleElementsReason",null),e([F()],ae.prototype,"page",null),e([F()],ae.prototype,"pageStack",void 0),e([F()],ae.prototype,"readOnly",void 0),e([F()],ae.prototype,"pendingSubtypeChoice",void 0),e([F()],ae.prototype,"subtypes",null),e([F()],ae.prototype,"spatialReference",void 0),e([F()],ae.prototype,"submitHasBeenAttempted",void 0),e([F()],ae.prototype,"timeZone",null),e([F()],ae.prototype,"view",void 0),e([F()],ae.prototype,"updating",null),e([F()],ae.prototype,"valid",null),e([F()],ae.prototype,"layers",null),e([F()],ae.prototype,"mode",null),e([F()],ae.prototype,"sharedForm",void 0),e([F()],ae.prototype,"sharedFormTemplate",void 0),e([F()],ae.prototype,"selectedAttachment",null),e([F()],ae.prototype,"selectedAttachmentAddElementId",null),e([F()],ae.prototype,"selectedAttachmentListElementId",null),e([F()],ae.prototype,"selectedAttachmentListInput",null),e([F()],ae.prototype,"showingSelectedAttachmentReplacePage",null),e([F()],ae.prototype,"selectedAttachmentAddInput",null),e([F()],ae.prototype,"selectedAttachmentDetails",null),e([F()],ae.prototype,"userHasChangedValues",void 0),e([F()],ae.prototype,"layerInfos",void 0),e([F()],ae.prototype,"_arcadeExecutorProvider",void 0),e([F()],ae.prototype,"_activeAssociation",void 0),e([F()],ae.prototype,"_activeAssociationsInput",void 0),e([F()],ae.prototype,"_activeRelationshipInput",void 0),e([F()],ae.prototype,"_prepareTask",void 0),e([F()],ae.prototype,"_reactiveGraphicLookup",void 0),e([F()],ae.prototype,"_allAttachmentInputs",null),e([F()],ae.prototype,"_hasPendingAttachmentHydration",null),e([F()],ae.prototype,"_layerTemplateMap",void 0),e([F()],ae.prototype,"_layersSet",null),e([F()],ae.prototype,"_workingFeatures",void 0),e([F()],ae.prototype,"_expressionsManager",void 0),ae=e([I("esri.widgets.BatchAttributeForm.BatchAttributeFormViewModel")],ae);const ie=ae;function ne(e){return null!=e&&e.trim().length>0}function re(e,t){const s=e.keywords;return ne(s)&&s.toLowerCase()===t}function oe(e,t){const s="attachment"===e.input?.type?e.input.attachmentAssociationType:"exact",a=e.attachmentKeyword;if("any"===s)return t;if("exactOrNone"===s){if(te(a))return t.filter(e=>!ne(e.keywords));const e=a.toLowerCase();return t.filter(t=>!ne(t.keywords)||re(t,e))}if(te(a))return t;const i=a.toLowerCase();return t.filter(e=>re(e,i))}export{ie as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../Graphic.js";import a from"../../core/Collection.js";import i from"../../core/Error.js";import{makeHandle as r,handlesGroup as s,abortHandle as n}from"../../core/handleUtils.js";import"../../core/has.js";import o from"../../core/Logger.js";import{removeMaybe as l,destroyMaybe as d}from"../../core/maybe.js";import{isPromiseLike as c,debounce as u}from"../../core/promiseUtils.js";import{whenOnce as p,watch as h,initial as m,sync as f,syncAndInitial as g}from"../../core/reactiveUtils.js";import{generateBracedUUID as w}from"../../core/uuid.js";import{property as y,subclass as v}from"../../core/accessorSupport/decorators.js";import{isSharedTemplateOrMetadata as F,isSharedTemplate as _,getCreationAttributes as M,isStandardFeatureTemplate as b}from"../../editing/templateUtils.js";import{getFullTemplate as I}from"../../editing/sharedTemplates/templateLoader.js";import V from"../../layers/GraphicsLayer.js";import{isSceneLayer as k,isTable as S}from"../../layers/support/layerUtils.js";import{isNumber as T}from"../../support/guards.js";import{getDisplayedSymbol as P}from"../../symbols/support/symbolUtils.js";import{updateGraphicSymbolWhenRequired as E}from"../../views/draw/support/editingSessionUtils.js";import{getDrawHelpMessage as U}from"../../views/draw/support/helpMessageUtils.js";import A from"../../views/draw/support/HighlightHelper.js";import H from"../../views/interactive/sketch/SketchOptions.js";import C from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as L}from"../../views/support/HighlightDefaults.js";import O from"../BatchAttributeForm/BatchAttributeFormViewModel.js";import j from"./CreateFeaturesWorkflowData.js";import{isModelUpload as x,handleModelUpload as D}from"./modelUploadUtils.js";import z from"./Workflow.js";import{activeSketchToolDrawsUnsupportedCurve as R,createToolFromGeometryType as G,containsUnsupportedCurve as W,findEditorItemForLayer as N,getServiceEditsFromWorkflowData as B,getServiceInfoForLayer as K,orderEditsByRelationshipDependencies as Z,getServiceLayersById as q,startCreatingNewFeature as J,syncUpdateOptions as Q,findLayerInfo as X,handleFormValuesChangeEvent as Y,isTerminalUpdateEventType as $,getVisualVariableAttributes as ee,startUpdatingFeatureGeometry as te,createWorkflowSteps as ae,avoidFeatureTemplateSelectionWithOnlyOneItem as ie,setUpSketchCreateWatchers as re,setRelationshipFields as se,showProgressCursor as ne,setVisualVariablesAndElevationInfoForUpdate as oe,visualVariableInteractiveUpdate as le}from"./workflowUtils.js";import{makeServiceEditsWithAttachments as de,makeEditsWithAttachments as ce,parseEditResultsAndCollectAddAttachmentData as ue}from"./support/attachmentUtils.js";import pe from"../Sketch/SketchViewModel.js";var he;const me=Symbol(),fe=Symbol(),ge=Symbol(),we=Symbol(),ye={point:["point"],multipoint:["multipoint"],polygon:["polygon","freehandPolygon","rectangle","circle"],polyline:["polyline","freehandPolyline"],mesh:[],multipatch:[]};let ve=he=class extends z{constructor(e){super(e),this.type="create-features",this.createFeatureState="create-new",this.data=void 0,this.isNested=!1,this._getDrawMeshHelpMessage=void 0,this._featureFormHandle=null,this._visualVariableAttributes={rotation:null,size:null},this._formViewModel=new O({attachmentsEnabled:!0}),this._sketchLayer=null,this._sketchViewModel=null,this._isActive=!0}initialize(){this.isNested&&(this._isActive=!1),this._initializeSketchViewModel()}destroy(){this._sketchViewModel.destroy()}get allowSave(){return!this.updating}get curveResizeDisabled(){return this.data.curveResizeDisabled}get curveUpdatesDisabled(){return this.data.curveUpdatesDisabled}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return!!this.data.editorItem?.hasInvalidFormTemplate}get hasPendingEdits(){if(this.pendingFeatures.some(e=>!!this.data.getEditsForPendingFeature(e)?.modified))return!0;const{creationInfo:e,upload:t}=this.data,{activeComponent:a,createGraphic:i}=this._sketchViewModel,r=i?.geometry?.type;return!("polyline"!==r&&"polygon"!==r&&"multipoint"!==r||"draw-2d"!==a?.type&&"draw-3d"!==a?.type)&&a.drawOperation.committedVertices.length>0||(!(!t||"pending"!==t.state&&"success"!==t.state)||!!e?.geometryToPlace)}get hasPreviousStep(){return this.formViewModel.canGoBack||this._stepIndex>0||"update-pending"===this.createFeatureState&&!!this.data.selectedPendingFeature&&!this.parent&&!x(this.data.creationInfo)}get helpMessage(){const{creationInfo:e,viewModel:t}=this.data;if("creating-features"!==this.stepId||!e)return;const{_sketchViewModel:a}=this,{drawTool:i,isUsingLegacyCreateTools:r}=a;if(!r)return i?.helpMessageKey??"noTool";const s=e.layer.geometryType,n=a.createGraphic;if("mesh"===s){this._getDrawMeshHelpMessage||import("../../views/draw/support/helpMessageUtils3d.js").then(e=>{this._getDrawMeshHelpMessage=e.getDrawMeshHelpMessage});const{view:e}=t;return"3d"===e?.type?this._getDrawMeshHelpMessage?.(n,e):void 0}const{activeCreateToolDrawMode:o,activeTool:l}=a;return U("rectangle"===l||"circle"===l?l:s,n?.geometry,o)}get noticeMessage(){if(R(this._sketchViewModel,this.data.editorItem))return"curveToolDensifyWarning"}get layer(){return this.data.creationInfo?.layer}get numPendingFeatures(){return this.pendingFeatures.length}get numPendingFeaturesExcludingHidden(){return this.pendingFeatures.filter(e=>this.data.isDisplayable(e)).length}get parent(){return this.data.parent}get pendingFeatures(){return this.data.pendingFeatures}get keyboardCancellationEnabled(){return 0===this.numPendingFeatures}get reliesOnOwnerAdminPrivileges(){return this.data.editorItem?.capabilities.create.reliesOnOwnerAdminPrivileges??!1}get saveActionLabel(){return"create"}get shouldShowAttachments(){return(this.data.selectedPendingFeature&&this.data.editorItem?.capabilities.create.attachments.enabled)??!1}get shouldAllowAttachmentEditing(){return this.shouldShowAttachments}get sketchUpdateOptions(){const{editorItem:e}=this.data;return{enableScaling:!this.curveResizeDisabled,multipleSelectionEnabled:!1,reshapeOptions:{enableCreateCurveFromStraightEdge:!k(e?.layer)&&!!e?.capabilities.supportsTrueCurve}}}get sketchViewModel(){return this._sketchViewModel}get test(){}get availableCreateTools(){const e=this.data.creationInfo?.layer.geometryType,t=this.data.viewModel.view;if(!e)return[];if(this.data.creationInfo?.maxFeatures&&this.data.creationInfo.maxFeatures<=this.numPendingFeatures)return[];if(F(this.data.fullTemplate)){const{tool:t}=G(e,this.data.fullTemplate);return[t]}return"2d"!==t?.type&&"multipoint"===e?[]:[...ye[e]]}getUpdating(){return!!this._sketchViewModel?.updating}async enter(){this._isActive=!0,"awaiting-feature-creation-info"!==this.stepId&&await this._updatingHandles.addPromise(this._setUpCreatingFeaturesStep())}exit(){this._isActive=!1,this.removeHandles([ge])}async updatePendingFeature(e){if(e!==this.data.selectedPendingFeature)return this._sketchViewModel.cancel(),this._startUpdating({feature:e})}async start(){return await super.start(),S(this.data.creationInfo?.layer)?null:{enter:async()=>{},exit:async()=>{},viewModel:this._sketchViewModel}}async save(e){const{formViewModel:t}=this;if(t.pendingSubtypeChoice)return;await t.submit(),this._stashValidationState();const a=this.data.selectedPendingFeature,i=this._hasValidationErrors(a)?a:this.data.pendingFeatures.find(e=>this._hasValidationErrors(e));if(i)return await this._startUpdating({feature:i}),void await(t?.submit());const{pendingFeatures:r,editorItem:s}=this.data;if(s&&e&&W(r.toArray(),s)){if(!await e("curveEditingDensifyPrompt"))return this.reset()}return super.save()}back(e){return this._formViewModel.canGoBack?this._formViewModel.goBack():"update-pending"!==this.createFeatureState||!this.data.selectedPendingFeature||x(this.data.creationInfo)||this.parent?super.back(e):this._clearSelectedFeature()}previous(e){return this._formViewModel.canGoBack?this._formViewModel.goBack():"update-pending"===this.createFeatureState&&this.data.selectedPendingFeature&&!x(this.data.creationInfo)?this._clearSelectedFeature():super.previous(e)}cancelFeature(e){this.data.isSharedTemplateWorkflow?o.getLogger(this).warn("Cannot cancel individual features created by shared templates."):(this.data.removePendingFeature(e),this.sketchViewModel.removeGraphic(e))}static create(e){const{applyEdits:t,applyEditsFeatureService:a,addAttachmentsCallback:i,isNested:r,creationInfo:s,parent:n,snappingManager:o,startAt:l,viewModel:d}=e,c=e.sketchOptions??new H,u=s?.layer,p=u?N(d.editorItems,u):void 0,h=new he({data:new j({creationInfo:s,editorItem:p,parent:n,sketchOptions:c,snappingManager:o,viewModel:d}),isNested:r,onCommit:async e=>{const{creationInfo:r}=e;if(!r)return;h._sketchViewModel.cancel();const s=e.pendingFeatures.toArray(),{layer:n}=r,o=n.capabilities?.editing.supportsGlobalId&&"globalIdField"in n,{fullTemplate:l}=e,c=B(h.data),u=_(l)&&c;if(o){if(Me(s),u){let t=de(c,e);const i=await(K(n,d.view)?.load());i&&(t=Z({edits:t,serviceInfo:i,view:d.view,findOriginalFeature:t=>e.getEditsForPendingFeature(t)?.initialFeature??t})),await a(l.featureService,t,{globalIdUsed:!0,honorSequenceOfEdits:!0,gdbVersion:l.layer.gdbVersion??void 0})}else await t(n,ce(s,e),{globalIdUsed:!0});return}const p=u?await a(l.featureService,c,{gdbVersion:l.layer.gdbVersion??void 0}):[await t(n,{addFeatures:s})];p?.length&&e.attachmentsModified&&!o&&await Promise.all(p.map(t=>{if(!t?.addFeatureResults)return;const a=ue(s,t.addFeatureResults,n,e);return i(n,a)}))}});return h._set("steps",this._createWorkflowSteps(h,l)),h}_fadeExistingFeatures(e){if("effect"in e){const t=e.effect;return e.effect="saturate(0.6) opacity(0.8)",r(()=>e.effect=t)}const t=e.opacity;return e.opacity=.7,r(()=>e.opacity=t)}async _initializeFullTemplateAndExecutorInfo(e){const{creationInfo:t}=e,{view:a}=e.viewModel;if(!t||!a)return null;const i=await I(a,t.template);if(e.fullTemplate=i,i&&_(i)){const{createTemplateExecutor:r}=await(import("../../editing/sharedTemplates/executor/createTemplateExecutor.js")),s={completionResults:[],executor:await r(i),serviceLayersById:q(t.layer,a)};e.templateExecutorInfo=s}return i}async _startCreating(){this.removeHandles(fe);const{data:e}=this;if(!e.creationInfo)return;const t=this.data.creationInfo?.maxFeatures;if(t&&this.numPendingFeatures>=t)return this.sketchViewModel.cancel(),void(this.numPendingFeatures&&await this._startUpdating({feature:this.pendingFeatures.at(-1)}));this.createFeatureState="create-new",await J(this._sketchViewModel,this._sketchLayer,e)}async _clearSelectedFeature(){const e=this._formViewModel.pendingSubtypeChoice;e&&(e.resolve("undo"),await e.promise),this._stashValidationState(),this.sketchViewModel.cancel(),this.data.selectedPendingFeature=null,this._featureFormHandle=l(this._featureFormHandle),this._formViewModel.features=new a,this._formViewModel.activeFeatureIndex=-1}_stashValidationState(){const e=this._formViewModel.activeFeature,t=e&&this.data.getEditsForPendingFeature(e);t&&(t.submittable=this._formViewModel.valid)}async _selectFeatureForUpdate({feature:e,initialFeature:t=e}){this._stashValidationState();const{data:i,pendingFeatures:r}=this;r.includes(e)||i.addPendingFeature(e,t),i.selectedPendingFeature=e;const{_formViewModel:n,_sketchViewModel:o,sketchUpdateOptions:d}=this,{creationInfo:c,viewModel:u}=i,{layerInfos:m,view:f}=u;if(!f||!c)return;Q(o,d),l(this._featureFormHandle);const g=e.sourceLayer,w=X(m,g),y=f.spatialReference;n.set({editType:"INSERT",features:new a([e]),activeFeatureIndex:0,layerInfos:w?[w]:null,spatialReference:y,map:f.map}),await p(()=>!1===n.updating),await E(e,"2d"===f.type?f.scale:null);const v=i.getEditsForPendingFeature(e);v?.attachmentsModified&&n.applyStashedAttachmentEdits(v.attachmentEdits),this._featureFormHandle=s([n.on("values-change",Y({filter:e=>e===v?.feature,forEachValueChange:(e,t)=>{if(T(t)){const a=this._visualVariableAttributes;a.size&&!a.size.isUpdatingInteractively&&e===a.size.field&&a.size.setInitialValue(t),a.rotation&&!a.rotation.isUpdatingInteractively&&e===a.rotation.field&&a.rotation.setInitialValue(t)}},forEachFeature:e=>{v?.updateAttributes(n.getValues(e)),E(e,"2d"===f.type?f.scale:null)}})),n.on("attachments-change",e=>v?.setAttachmentEdits(e.attachmentEdits)),o.on(["update","undo","redo"],t=>{("undo"===t.type||"redo"===t.type||"update"===t.type&&null!=t.toolEventInfo&&$(t.toolEventInfo.type))&&n.notifyGeometriesChanged([e])}),h(()=>n.activeFeature?.sourceLayer,t=>e.sourceLayer=t),h(()=>[n.activeFeature,n.valid],()=>this._stashValidationState())]),this.createFeatureState="update-pending"}async _startUpdating({feature:e,initialFeature:t=e}){await this._selectFeatureForUpdate({feature:e,initialFeature:t});const{_sketchLayer:a,_sketchViewModel:i,data:r}=this,{creationInfo:s,viewModel:n}=r,{view:o}=n;if(!o||!s)return;const l=e.sourceLayer??s.layer;return S(l)?void 0:(this._visualVariableAttributes=ee(e),te({graphic:e,sketchLayer:a,sketchViewModel:i,sourceLayer:l,updateOptions:this.sketchUpdateOptions,visualVariables:this._visualVariableAttributes}))}static _createWorkflowSteps(e,t="awaiting-feature-creation-info"){const{data:a}=e,i=ae(["awaiting-feature-creation-info","creating-features","adding-attachment","editing-attachment"],t,{"awaiting-feature-creation-info":()=>({id:"awaiting-feature-creation-info",async setUp(){const{creationInfo:t,viewModel:i}=a,{view:r}=i;r&&(x(t)?e.addHandles(await D({view:r,data:a,next:()=>e.next(),cancel:()=>i.cancelWorkflow({warnIfNoWorkflow:!1})}),this.id):(a.parent&&t&&e.addHandles(i.restrictFeatureTemplatesViewModelToLayer(t.layer),this.id),e.addHandles(i.featureTemplatesViewModel.on("select",({item:t})=>{t&&(a.creationInfo={...a.creationInfo,layer:t.layer,template:t.template},e.next())}),this.id)))},async tearDown(){e.removeHandles(this.id)}}),"creating-features":()=>({id:"creating-features",async setUp(){e._isActive&&await e._setUpCreatingFeaturesStep()},async tearDown(t){t.canceled&&e.removeHandles([ge,me,fe,we])}}),"adding-attachment":()=>({id:"adding-attachment",parent:"creating-features",async setUp(){},async tearDown(){}}),"editing-attachment":()=>({id:"editing-attachment",parent:"creating-features",async setUp(){},async tearDown(){}})});return ie(a,i)}static _configureSketchViewModel(e){const{data:t,_sketchLayer:a,_sketchViewModel:i}=e,{creationInfo:n,viewModel:o}=t,{view:l}=o,d=[];if(!l)return r();if("2d"===l.type){n&&d.push(e._fadeExistingFeatures(n.layer));const t=u((e,t)=>Promise.all(e.map(e=>E(e,t))));d.push(h(()=>l.scale,e=>t(a.graphics,e)))}const c=M(t.fullTemplate,n?.attributeOverrides,n?.layer),p=h(()=>i.createGraphic&&i.activeComponent,()=>{i.createGraphic&&i.activeComponent&&!e.hasHandles(fe)&&e._updatingHandles.consumePromise(re({creationAttributes:c,data:t,sketchViewModel:i,view:l}).then(t=>e.addHandles(t,fe)))}),m=async t=>{if("cancel"!==t.state&&"complete"!==t.state||e.removeHandles(fe),"cancel"===t.state&&null!==l.activeTool&&l.activeTool!==e.sketchViewModel.activeComponent&&(await e._waitForActiveToolCleared(),await e._startCreating()),"complete"===t.state&&t.graphic){const a=await e._processEdits(t.graphic,{scale:"2d"===l.type?l.scale:null,useSourceLayer:!0});a&&(await e._waitForActiveToolCleared(),await e._startUpdating({feature:a}))}},f=async r=>{const{_formViewModel:s}=e;if(r.graphics.length>1)return void await e._clearSelectedFeature();const o=r.graphics[0];if("complete"===r.state){if(e.numPendingFeatures!==n?.maxFeatures&&s.valid||s.submit(),await e._clearSelectedFeature(),null==e.data.selectedPendingFeature&&(null==l.activeTool||l.activeTool===e.sketchViewModel.activeComponent)&&(await e.sketchViewModel.wait(),"ready"===e.sketchViewModel.state&&"mesh"!==e.data.creationInfo?.layer.geometryType))return e._startCreating()}else{if("start"===r.state)return o.sourceLayer??=t.creationInfo?.layer,await oe({graphic:o,sketchLayer:a,sketchViewModel:i,visualVariables:e._visualVariableAttributes,sourceLayer:o.sourceLayer}),e._selectFeatureForUpdate({feature:o});if("active"===r.state){await e.updatePendingFeature(o);const t=e._visualVariableAttributes;le(l,o,r,t)&&await E(o,"2d"===l.type?l.scale:null);const a=o.attributes,{rotation:i,size:n}=t;if(null!=i){const{field:t}=i;e._updatingHandles.consumePromise(s.setFieldValue(t,a[t]))}if(null!=n){const{field:t}=n;e._updatingHandles.consumePromise(s.setFieldValue(t,a[t]))}}}},g=async a=>{if(a.graphics.forEach(e=>{t.removePendingFeature(e)}),!x(t.creationInfo))return e._startCreating()},w=async()=>{if(x(t.creationInfo))try{await e.data.viewModel.back()}catch{}return e._startCreating()};d.push(p,i.on("create",t=>e._updatingHandles.addPromise(m(t))),i.on("update",t=>e._updatingHandles.addPromise(f(t))),i.on("delete",t=>e._updatingHandles.addPromise(g(t))),e._updatingHandles.addWhen(()=>!e.numPendingFeatures,()=>e._updatingHandles.addPromise(w())),r(()=>{i.cancel()}),Fe(i,a,t),..._e(t));const y=s(d);return i.addHandles(y),y}_initializeSketchViewModel(){const{data:e}=this,{view:t}=e.viewModel,a=new V({elevationInfo:e.creationInfo?.layer.elevationInfo,internal:!0,listMode:"hide",title:"createFeaturesWorkflow-internal"}),i=new pe({layer:a,creationMode:"single",sketchOptions:e.sketchOptions,snappingManager:e.snappingManager,useLegacyCreateTools:e.viewModel.useLegacyCreateTools,updateOnGraphicClick:!1,defaultUpdateOptions:this.sketchUpdateOptions,view:t});this._sketchLayer=a,this._sketchViewModel=i,t?.map.add(a),this.addHandles([r(()=>{t?.destroyed||t?.map.remove(a),d(a)}),h(()=>this.numPendingFeatures>0,e=>this._sketchViewModel.updateOnGraphicClick=e,m),h(()=>this.sketchUpdateOptions,e=>{i.defaultUpdateOptions=e,Q(i,e)},f)])}_hasValidationErrors(e){return!!e&&!this.data.isSubmittable(e)}async _processEdits(e,t){const{data:i,_formViewModel:r,_sketchLayer:s}=this,{layerInfos:n,view:o}=i.viewModel;r.editType="INSERT",r.map=o?.map,r.spatialReference=o?.spatialReference;const{templateExecutorInfo:l}=i;if(!l){const t=e.clone();return t.geometry=null,await this._addAndInitializeEdits(e,t),e}s.remove(e);const{executor:d}=l,u=d(e.geometry,"completion"),h=c(u)?await u:u;l.completionResults.push(h),se(h.relationships),r.editType="INSERT",r.map=o?.map,r.spatialReference=o?.spatialReference,h.primary&&i.creationInfo?.attributeOverrides&&(h.primary.graphic.attributes={...h.primary.graphic.attributes,...i.creationInfo.attributeOverrides});for(const a of h.edits){let e=null;if(a.addFeatures)for(const i of a.addFeatures){const a=i.clone();a.geometry=null,null!=i.geometry&&(i.symbol=await P(i,t),s.add(i)),i.sourceLayer!==e?.layer&&(e=X(n,i.sourceLayer));const r=!!h.associationGraphics?.has(i);await this._addAndInitializeEdits(i,a,e,r)}}r.features=new a,r.activeFeatureIndex=-1,await p(()=>!r.updating);return h.edits.reduce((e,t)=>e+(t.addFeatures?.length??0),0)>1?null:h.primary?.graphic}async _addAndInitializeEdits(e,t,i,r=!1){const{data:s,_formViewModel:n}=this,{layerInfos:o}=s.viewModel,l=s.addPendingFeature(e,t,{isAssociation:r});i??=X(o,e.sourceLayer),n.features=new a([e]),n.activeFeatureIndex=0,n.layerInfos=i?[i]:null,await p(()=>!n.updating),l.updateAttributes(n.getValues(e)),l.submittable=n.valid}async _setUpCreatingFeaturesStep(){if(this.hasHandles(ge))return;const{data:e,sketchViewModel:a}=this,{creationInfo:n,viewModel:o}=e,{view:d}=o;if(!d||!n?.layer)throw new i("missing-parameters","CreateFeaturesWorkflow requires a view and creationInfo.");const{initialFeature:c,layer:u}=n,p=[],f=[];this._featureFormHandle=l(this._featureFormHandle),this._visualVariableAttributes={rotation:null,size:null},e.editorItem=N(o.editorItems,n.layer),n.template&&(null==e.fullTemplate&&await this._initializeFullTemplateAndExecutorInfo(e),f.push(r(()=>{e.templateExecutorInfo&&(e.templateExecutorInfo.completionResults=[])}))),a.allowDeleteKey=!e.isSharedTemplateWorkflow;const g=ne(d);p.push(g);const w=S(n.layer),{template:y}=n,v=!y||b(y)||F(y)&&"feature"===y.type,_=w&&v;try{if(_){const a=c??new t({attributes:M(e.fullTemplate,n.attributeOverrides,u),sourceLayer:u}),i=await this._processEdits(a);i&&await this._startUpdating({feature:i})}else p.push(he._configureSketchViewModel(this)),c?(x(n)&&n.geometryToPlace&&(c.attributes=M(e.fullTemplate,n.attributeOverrides,u)),a.addGraphic(c),await this._startUpdating({feature:c})):await this._startCreating()}finally{g.remove()}const I=r(()=>{for(const t of e.pendingFeatures)a.removeGraphic(t),e.removePendingFeature(t)}),V=h(()=>d?.timeZone,e=>{this._formViewModel.timeZone=e,this.data.timeZone=e},m),k=r(()=>{x(n)&&o.cancelWorkflow({warnIfNoWorkflow:!1})});this._featureFormHandle&&p.push(this._featureFormHandle),this.addHandles(p,this._handleKeys.beforeCommit),this.addHandles(f,this._handleKeys.afterCommit),this.addHandles([s(p),s(f),k,I,V],ge)}async _waitForActiveToolCleared(){const e=this.data.viewModel.view;if(null==e?.activeTool)return;const t=new AbortController;this.addHandles(n(t),we),await p(()=>null==e?.activeTool,t.signal),t.abort()}};function Fe(e,t,a){let i=null;const n=()=>e.snappingOptions.featureSources,o=()=>(i=new C({layer:t}),n().add(i),i),l=()=>{null!=i&&(n().remove(i),i=d(i))};return s([h(()=>{const e=a.creationInfo?.layer,t=n().find(t=>t.layer===e);return{hasFeatureLayerSource:!!t,enabled:t?.enabled??!1}},({hasFeatureLayerSource:e,enabled:t})=>{if(!e)return l();i??=o(),i.enabled=t},g),r(l)])}function _e(e){const t=e.viewModel.view;if(!t)return[];const a=[];if("3d"===t.type){const i=new A({view:t});a.push(h(()=>e.selectedPendingFeature,(e,t)=>{i.remove(e),i.add(t)}),r(()=>i.destroy()))}const i=new A({view:t,highlightName:L});return a.push(h(()=>e.temporaryHighlightFeature,e=>{i.removeAll(),i.add(e)}),r(()=>i.destroy())),a}function Me(e){for(const t of e){const{sourceLayer:e}=t;e&&"globalIdField"in e&&null!=e.globalIdField&&(t.attributes[e.globalIdField]??=w())}}e([y()],ve.prototype,"allowSave",null),e([y()],ve.prototype,"createFeatureState",void 0),e([y()],ve.prototype,"curveResizeDisabled",null),e([y()],ve.prototype,"curveUpdatesDisabled",null),e([y()],ve.prototype,"data",void 0),e([y({constructOnly:!0})],ve.prototype,"isNested",void 0),e([y()],ve.prototype,"formViewModel",null),e([y()],ve.prototype,"hasInvalidFormTemplate",null),e([y()],ve.prototype,"hasPendingEdits",null),e([y()],ve.prototype,"hasPreviousStep",null),e([y()],ve.prototype,"_getDrawMeshHelpMessage",void 0),e([y()],ve.prototype,"helpMessage",null),e([y()],ve.prototype,"noticeMessage",null),e([y()],ve.prototype,"layer",null),e([y()],ve.prototype,"parent",null),e([y()],ve.prototype,"keyboardCancellationEnabled",null),e([y()],ve.prototype,"reliesOnOwnerAdminPrivileges",null),e([y()],ve.prototype,"saveActionLabel",null),e([y()],ve.prototype,"shouldShowAttachments",null),e([y()],ve.prototype,"shouldAllowAttachmentEditing",null),e([y()],ve.prototype,"sketchUpdateOptions",null),e([y()],ve.prototype,"sketchViewModel",null),e([y()],ve.prototype,"availableCreateTools",null),ve=he=e([v("esri.widgets.Editor.CreateFeaturesWorkflow")],ve);const be=ve;export{be as default};
2
+ import{__decorate as e}from"tslib";import t from"../../Graphic.js";import a from"../../core/Collection.js";import i from"../../core/Error.js";import{makeHandle as r,handlesGroup as s,abortHandle as n}from"../../core/handleUtils.js";import"../../core/has.js";import o from"../../core/Logger.js";import{removeMaybe as l,destroyMaybe as d}from"../../core/maybe.js";import{isPromiseLike as c,debounce as u}from"../../core/promiseUtils.js";import{whenOnce as p,watch as h,initial as m,sync as f,syncAndInitial as g}from"../../core/reactiveUtils.js";import{generateBracedUUID as w}from"../../core/uuid.js";import{property as y,subclass as v}from"../../core/accessorSupport/decorators.js";import{isSharedTemplateOrMetadata as F,isSharedTemplate as _,getCreationAttributes as M,isStandardFeatureTemplate as b}from"../../editing/templateUtils.js";import{getFullTemplate as I}from"../../editing/sharedTemplates/templateLoader.js";import V from"../../layers/GraphicsLayer.js";import{isSceneLayer as k,isTable as S}from"../../layers/support/layerUtils.js";import{isNumber as T}from"../../support/guards.js";import{getDisplayedSymbol as P}from"../../symbols/support/symbolUtils.js";import{updateGraphicSymbolWhenRequired as E}from"../../views/draw/support/editingSessionUtils.js";import{getDrawHelpMessage as U}from"../../views/draw/support/helpMessageUtils.js";import A from"../../views/draw/support/HighlightHelper.js";import H from"../../views/interactive/sketch/SketchOptions.js";import C from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as L}from"../../views/support/HighlightDefaults.js";import O from"../BatchAttributeForm/BatchAttributeFormViewModel.js";import j from"./CreateFeaturesWorkflowData.js";import{isModelUpload as x,handleModelUpload as D}from"./modelUploadUtils.js";import z from"./Workflow.js";import{activeSketchToolDrawsUnsupportedCurve as R,createToolFromGeometryType as G,containsUnsupportedCurve as W,findEditorItemForLayer as N,getServiceEditsFromWorkflowData as B,getServiceInfoForLayer as K,orderEditsByRelationshipDependencies as q,getServiceLayersById as Z,startCreatingNewFeature as J,syncUpdateOptions as Q,findLayerInfo as X,handleFormValuesChangeEvent as Y,isTerminalUpdateEventType as $,getVisualVariableAttributes as ee,startUpdatingFeatureGeometry as te,createWorkflowSteps as ae,avoidFeatureTemplateSelectionWithOnlyOneItem as ie,setUpSketchCreateWatchers as re,setRelationshipFields as se,showProgressCursor as ne,setVisualVariablesAndElevationInfoForUpdate as oe,visualVariableInteractiveUpdate as le}from"./workflowUtils.js";import{makeServiceEditsWithAttachments as de,makeEditsWithAttachments as ce,parseEditResultsAndCollectAddAttachmentData as ue}from"./support/attachmentUtils.js";import pe from"../Sketch/SketchViewModel.js";var he;const me=Symbol(),fe=Symbol(),ge=Symbol(),we=Symbol(),ye={point:["point"],multipoint:["multipoint"],polygon:["polygon","freehandPolygon","rectangle","circle"],polyline:["polyline","freehandPolyline"],mesh:[],multipatch:[]};let ve=he=class extends z{constructor(e){super(e),this.type="create-features",this.createFeatureState="create-new",this.data=void 0,this.isNested=!1,this._getDrawMeshHelpMessage=void 0,this._featureFormHandle=null,this._visualVariableAttributes={rotation:null,size:null},this._formViewModel=new O({attachmentsEnabled:!0}),this._sketchLayer=null,this._sketchViewModel=null,this._isActive=!0}initialize(){this.isNested&&(this._isActive=!1),this._initializeSketchViewModel()}destroy(){this._sketchViewModel.destroy()}get allowSave(){return!this.updating}get curveResizeDisabled(){return this.data.curveResizeDisabled}get curveUpdatesDisabled(){return this.data.curveUpdatesDisabled}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return!!this.data.editorItem?.hasInvalidFormTemplate}get hasPendingEdits(){if(this.pendingFeatures.some(e=>!!this.data.getEditsForPendingFeature(e)?.modified))return!0;const{creationInfo:e,upload:t}=this.data,{activeComponent:a,createGraphic:i}=this._sketchViewModel,r=i?.geometry?.type;return!("polyline"!==r&&"polygon"!==r&&"multipoint"!==r||"draw-2d"!==a?.type&&"draw-3d"!==a?.type)&&a.drawOperation.committedVertices.length>0||(!(!t||"pending"!==t.state&&"success"!==t.state)||!!e?.geometryToPlace)}get hasPreviousStep(){return this.formViewModel.canGoBack||this._stepIndex>0||"update-pending"===this.createFeatureState&&!!this.data.selectedPendingFeature&&!this.parent&&!x(this.data.creationInfo)}get helpMessage(){const{creationInfo:e,viewModel:t}=this.data;if("creating-features"!==this.stepId||!e)return;const{_sketchViewModel:a}=this,{drawTool:i,isUsingLegacyCreateTools:r}=a;if(!r)return i?.helpMessageKey??"noTool";const s=e.layer.geometryType,n=a.createGraphic;if("mesh"===s){this._getDrawMeshHelpMessage||import("../../views/draw/support/helpMessageUtils3d.js").then(e=>{this._getDrawMeshHelpMessage=e.getDrawMeshHelpMessage});const{view:e}=t;return"3d"===e?.type?this._getDrawMeshHelpMessage?.(n,e):void 0}const{activeCreateToolDrawMode:o,activeTool:l}=a;return U("rectangle"===l||"circle"===l?l:s,n?.geometry,o)}get noticeMessage(){if(R(this._sketchViewModel,this.data.editorItem))return"curveToolDensifyWarning"}get layer(){return this.data.creationInfo?.layer}get numPendingFeatures(){return this.pendingFeatures.length}get numPendingFeaturesExcludingHidden(){return this.pendingFeatures.filter(e=>this.data.isDisplayable(e)).length}get parent(){return this.data.parent}get pendingFeatures(){return this.data.pendingFeatures}get keyboardCancellationEnabled(){return 0===this.numPendingFeatures}get reliesOnOwnerAdminPrivileges(){return this.data.editorItem?.capabilities.create.reliesOnOwnerAdminPrivileges??!1}get saveActionLabel(){return"create"}get shouldShowAttachments(){return(this.data.selectedPendingFeature&&this.data.editorItem?.capabilities.create.attachments.enabled)??!1}get shouldAllowAttachmentEditing(){return this.shouldShowAttachments}get sketchUpdateOptions(){const{editorItem:e}=this.data;return{enableScaling:!this.curveResizeDisabled,multipleSelectionEnabled:!1,reshapeOptions:{enableCreateCurveFromStraightEdge:!k(e?.layer)&&!!e?.capabilities.supportsTrueCurve}}}get sketchViewModel(){return this._sketchViewModel}get test(){}get availableCreateTools(){const e=this.data.creationInfo?.layer.geometryType,t=this.data.viewModel.view;if(!e)return[];if(this.data.creationInfo?.maxFeatures&&this.data.creationInfo.maxFeatures<=this.numPendingFeatures)return[];if(F(this.data.fullTemplate)){const{tool:t}=G(e,this.data.fullTemplate);return[t]}return"2d"!==t?.type&&"multipoint"===e?[]:[...ye[e]]}getUpdating(){return!!this._sketchViewModel?.updating}async enter(){this._isActive=!0,"awaiting-feature-creation-info"!==this.stepId&&await this._updatingHandles.addPromise(this._setUpCreatingFeaturesStep())}exit(){this._isActive=!1,this.removeHandles([ge])}async updatePendingFeature(e){if(e!==this.data.selectedPendingFeature)return this._sketchViewModel.cancel(),this._startUpdating({feature:e})}async start(){return await super.start(),S(this.data.creationInfo?.layer)?null:{enter:async()=>{},exit:async()=>{},viewModel:this._sketchViewModel}}async save(e){const{formViewModel:t}=this;if(t.pendingSubtypeChoice)return;await t.submit(),this._stashValidationState();const a=this.data.selectedPendingFeature,i=this._hasValidationErrors(a)?a:this.data.pendingFeatures.find(e=>this._hasValidationErrors(e));if(i)return await this._startUpdating({feature:i}),void await(t?.submit());const{pendingFeatures:r,editorItem:s}=this.data;if(s&&e&&W(r.toArray(),s)){if(!await e("curveEditingDensifyPrompt"))return this.reset()}return super.save()}back(e){return this._formViewModel.canGoBack?this._formViewModel.goBack():"update-pending"!==this.createFeatureState||!this.data.selectedPendingFeature||x(this.data.creationInfo)||this.parent?super.back(e):this._clearSelectedFeature()}previous(e){return this._formViewModel.canGoBack?this._formViewModel.goBack():"update-pending"===this.createFeatureState&&this.data.selectedPendingFeature&&!x(this.data.creationInfo)?this._clearSelectedFeature():super.previous(e)}cancelFeature(e){this.data.isSharedTemplateWorkflow?o.getLogger(this).warn("Cannot cancel individual features created by shared templates."):(this.data.removePendingFeature(e),this.sketchViewModel.removeGraphic(e))}static create(e){const{applyEdits:t,applyEditsFeatureService:a,addAttachmentsCallback:i,isNested:r,creationInfo:s,parent:n,snappingManager:o,startAt:l,viewModel:d}=e,c=e.sketchOptions??new H,u=s?.layer,p=u?N(d.editorItems,u):void 0,h=new he({data:new j({creationInfo:s,editorItem:p,parent:n,sketchOptions:c,snappingManager:o,viewModel:d}),isNested:r,onCommit:async e=>{const{creationInfo:r}=e;if(!r)return;h._sketchViewModel.cancel();const s=e.pendingFeatures.toArray(),{layer:n}=r,o=n.capabilities?.editing.supportsGlobalId&&"globalIdField"in n,{fullTemplate:l}=e,c=B(h.data),u=_(l)&&c;if(o){if(Me(s),u){let t=de(c,e);const i=await(K(n,d.view)?.load());i&&(t=q({edits:t,serviceInfo:i,view:d.view,findOriginalFeature:t=>e.getEditsForPendingFeature(t)?.initialFeature??t})),await a(l.featureService,t,{globalIdUsed:!0,honorSequenceOfEdits:!0,gdbVersion:l.layer.gdbVersion??void 0})}else await t(n,ce(s,e),{globalIdUsed:!0});return}const p=u?await a(l.featureService,c,{gdbVersion:l.layer.gdbVersion??void 0}):[await t(n,{addFeatures:s})];p?.length&&e.attachmentsModified&&!o&&await Promise.all(p.map(t=>{if(!t?.addFeatureResults)return;const a=ue(s,t.addFeatureResults,n,e);return i(n,a)}))}});return h._set("steps",this._createWorkflowSteps(h,l)),h}_fadeExistingFeatures(e){if("effect"in e){const t=e.effect;return e.effect="saturate(0.6) opacity(0.8)",r(()=>e.effect=t)}const t=e.opacity;return e.opacity=.7,r(()=>e.opacity=t)}async _initializeFullTemplateAndExecutorInfo(e){const{creationInfo:t}=e,{view:a}=e.viewModel;if(!t||!a)return null;const i=await I(a,t.template);if(e.fullTemplate=i,i&&_(i)){const{createTemplateExecutor:r}=await(import("../../editing/sharedTemplates/executor/createTemplateExecutor.js")),s={completionResults:[],executor:await r(i),serviceLayersById:Z(t.layer,a)};e.templateExecutorInfo=s}return i}async _startCreating(){this.removeHandles(fe);const{data:e}=this;if(!e.creationInfo)return;const t=this.data.creationInfo?.maxFeatures;if(t&&this.numPendingFeatures>=t)return this.sketchViewModel.cancel(),void(this.numPendingFeatures&&await this._startUpdating({feature:this.pendingFeatures.at(-1)}));this.createFeatureState="create-new",await J(this._sketchViewModel,this._sketchLayer,e)}async _clearSelectedFeature(){const e=this._formViewModel.pendingSubtypeChoice;e&&(e.resolve("undo"),await e.promise),this._stashValidationState(),this.sketchViewModel.cancel(),this.data.selectedPendingFeature=null,this._featureFormHandle=l(this._featureFormHandle),this._formViewModel.features=new a,this._formViewModel.activeFeatureIndex=-1}_stashValidationState(){const e=this._formViewModel.activeFeature,t=e&&this.data.getEditsForPendingFeature(e);t&&(t.submittable=this._formViewModel.valid)}async _selectFeatureForUpdate({feature:e,initialFeature:t=e}){this._stashValidationState();const{data:i,pendingFeatures:r}=this;r.includes(e)||i.addPendingFeature(e,t),i.selectedPendingFeature=e;const{_formViewModel:n,_sketchViewModel:o,sketchUpdateOptions:d}=this,{creationInfo:c,viewModel:u}=i,{layerInfos:m,view:f}=u;if(!f||!c)return;Q(o,d),l(this._featureFormHandle);const g=e.sourceLayer,w=X(m,g),y=f.spatialReference;n.set({editType:"INSERT",features:new a([e]),activeFeatureIndex:0,layerInfos:w?[w]:null,spatialReference:y,view:f}),await p(()=>!1===n.updating),await E(e,"2d"===f.type?f.scale:null);const v=i.getEditsForPendingFeature(e);v?.attachmentsModified&&n.applyStashedAttachmentEdits(v.attachmentEdits),this._featureFormHandle=s([n.on("values-change",Y({filter:e=>e===v?.feature,forEachValueChange:(e,t)=>{if(T(t)){const a=this._visualVariableAttributes;a.size&&!a.size.isUpdatingInteractively&&e===a.size.field&&a.size.setInitialValue(t),a.rotation&&!a.rotation.isUpdatingInteractively&&e===a.rotation.field&&a.rotation.setInitialValue(t)}},forEachFeature:e=>{v?.updateAttributes(n.getValues(e)),E(e,"2d"===f.type?f.scale:null)}})),n.on("attachments-change",e=>v?.setAttachmentEdits(e.attachmentEdits)),o.on(["update","undo","redo"],t=>{("undo"===t.type||"redo"===t.type||"update"===t.type&&null!=t.toolEventInfo&&$(t.toolEventInfo.type))&&n.notifyGeometriesChanged([e])}),h(()=>n.activeFeature?.sourceLayer,t=>e.sourceLayer=t),h(()=>[n.activeFeature,n.valid],()=>this._stashValidationState())]),this.createFeatureState="update-pending"}async _startUpdating({feature:e,initialFeature:t=e}){await this._selectFeatureForUpdate({feature:e,initialFeature:t});const{_sketchLayer:a,_sketchViewModel:i,data:r}=this,{creationInfo:s,viewModel:n}=r,{view:o}=n;if(!o||!s)return;const l=e.sourceLayer??s.layer;return S(l)?void 0:(this._visualVariableAttributes=ee(e),te({graphic:e,sketchLayer:a,sketchViewModel:i,sourceLayer:l,updateOptions:this.sketchUpdateOptions,visualVariables:this._visualVariableAttributes}))}static _createWorkflowSteps(e,t="awaiting-feature-creation-info"){const{data:a}=e,i=ae(["awaiting-feature-creation-info","creating-features","adding-attachment","editing-attachment"],t,{"awaiting-feature-creation-info":()=>({id:"awaiting-feature-creation-info",async setUp(){const{creationInfo:t,viewModel:i}=a,{view:r}=i;r&&(x(t)?e.addHandles(await D({view:r,data:a,next:()=>e.next(),cancel:()=>i.cancelWorkflow({warnIfNoWorkflow:!1})}),this.id):(a.parent&&t&&e.addHandles(i.restrictFeatureTemplatesViewModelToLayer(t.layer),this.id),e.addHandles(i.featureTemplatesViewModel.on("select",({item:t})=>{t&&(a.creationInfo={...a.creationInfo,layer:t.layer,template:t.template},e.next())}),this.id)))},async tearDown(){e.removeHandles(this.id)}}),"creating-features":()=>({id:"creating-features",async setUp(){e._isActive&&await e._setUpCreatingFeaturesStep()},async tearDown(t){t.canceled&&e.removeHandles([ge,me,fe,we])}}),"adding-attachment":()=>({id:"adding-attachment",parent:"creating-features",async setUp(){},async tearDown(){}}),"editing-attachment":()=>({id:"editing-attachment",parent:"creating-features",async setUp(){},async tearDown(){}})});return ie(a,i)}static _configureSketchViewModel(e){const{data:t,_sketchLayer:a,_sketchViewModel:i}=e,{creationInfo:n,viewModel:o}=t,{view:l}=o,d=[];if(!l)return r();if("2d"===l.type){n&&d.push(e._fadeExistingFeatures(n.layer));const t=u((e,t)=>Promise.all(e.map(e=>E(e,t))));d.push(h(()=>l.scale,e=>t(a.graphics,e)))}const c=M(t.fullTemplate,n?.attributeOverrides,n?.layer),p=h(()=>i.createGraphic&&i.activeComponent,()=>{i.createGraphic&&i.activeComponent&&!e.hasHandles(fe)&&e._updatingHandles.consumePromise(re({creationAttributes:c,data:t,sketchViewModel:i,view:l}).then(t=>e.addHandles(t,fe)))}),m=async t=>{if("cancel"!==t.state&&"complete"!==t.state||e.removeHandles(fe),"cancel"===t.state&&null!==l.activeTool&&l.activeTool!==e.sketchViewModel.activeComponent&&(await e._waitForActiveToolCleared(),await e._startCreating()),"complete"===t.state&&t.graphic){const a=await e._processEdits(t.graphic,{scale:"2d"===l.type?l.scale:null,useSourceLayer:!0});a&&(await e._waitForActiveToolCleared(),await e._startUpdating({feature:a}))}},f=async r=>{const{_formViewModel:s}=e;if(r.graphics.length>1)return void await e._clearSelectedFeature();const o=r.graphics[0];if("complete"===r.state){if(e.numPendingFeatures!==n?.maxFeatures&&s.valid||s.submit(),await e._clearSelectedFeature(),null==e.data.selectedPendingFeature&&(null==l.activeTool||l.activeTool===e.sketchViewModel.activeComponent)&&(await e.sketchViewModel.wait(),"ready"===e.sketchViewModel.state&&"mesh"!==e.data.creationInfo?.layer.geometryType))return e._startCreating()}else{if("start"===r.state)return o.sourceLayer??=t.creationInfo?.layer,await oe({graphic:o,sketchLayer:a,sketchViewModel:i,visualVariables:e._visualVariableAttributes,sourceLayer:o.sourceLayer}),e._selectFeatureForUpdate({feature:o});if("active"===r.state){await e.updatePendingFeature(o);const t=e._visualVariableAttributes;le(l,o,r,t)&&await E(o,"2d"===l.type?l.scale:null);const a=o.attributes,{rotation:i,size:n}=t;if(null!=i){const{field:t}=i;e._updatingHandles.consumePromise(s.setFieldValue(t,a[t]))}if(null!=n){const{field:t}=n;e._updatingHandles.consumePromise(s.setFieldValue(t,a[t]))}}}},g=async a=>{if(a.graphics.forEach(e=>{t.removePendingFeature(e)}),!x(t.creationInfo))return e._startCreating()},w=async()=>{if(x(t.creationInfo))try{await e.data.viewModel.back()}catch{}return e._startCreating()};d.push(p,i.on("create",t=>e._updatingHandles.addPromise(m(t))),i.on("update",t=>e._updatingHandles.addPromise(f(t))),i.on("delete",t=>e._updatingHandles.addPromise(g(t))),e._updatingHandles.addWhen(()=>!e.numPendingFeatures,()=>e._updatingHandles.addPromise(w())),r(()=>{i.cancel()}),Fe(i,a,t),..._e(t));const y=s(d);return i.addHandles(y),y}_initializeSketchViewModel(){const{data:e}=this,{view:t}=e.viewModel,a=new V({elevationInfo:e.creationInfo?.layer.elevationInfo,internal:!0,listMode:"hide",title:"createFeaturesWorkflow-internal"}),i=new pe({layer:a,creationMode:"single",sketchOptions:e.sketchOptions,snappingManager:e.snappingManager,useLegacyCreateTools:e.viewModel.useLegacyCreateTools,updateOnGraphicClick:!1,defaultUpdateOptions:this.sketchUpdateOptions,view:t});this._sketchLayer=a,this._sketchViewModel=i,t?.map.add(a),this.addHandles([r(()=>{t?.destroyed||t?.map.remove(a),d(a)}),h(()=>this.numPendingFeatures>0,e=>this._sketchViewModel.updateOnGraphicClick=e,m),h(()=>this.sketchUpdateOptions,e=>{i.defaultUpdateOptions=e,Q(i,e)},f)])}_hasValidationErrors(e){return!!e&&!this.data.isSubmittable(e)}async _processEdits(e,t){const{data:i,_formViewModel:r,_sketchLayer:s}=this,{layerInfos:n,view:o}=i.viewModel;r.editType="INSERT",r.spatialReference=o?.spatialReference,r.view=o;const{templateExecutorInfo:l}=i;if(!l){const t=e.clone();return t.geometry=null,await this._addAndInitializeEdits(e,t),e}s.remove(e);const{executor:d}=l,u=d(e.geometry,"completion"),h=c(u)?await u:u;l.completionResults.push(h),se(h.relationships),r.editType="INSERT",r.spatialReference=o?.spatialReference,r.view=o,h.primary&&i.creationInfo?.attributeOverrides&&(h.primary.graphic.attributes={...h.primary.graphic.attributes,...i.creationInfo.attributeOverrides});for(const a of h.edits){let e=null;if(a.addFeatures)for(const i of a.addFeatures){const a=i.clone();a.geometry=null,null!=i.geometry&&(i.symbol=await P(i,t),s.add(i)),i.sourceLayer!==e?.layer&&(e=X(n,i.sourceLayer));const r=!!h.associationGraphics?.has(i);await this._addAndInitializeEdits(i,a,e,r)}}r.features=new a,r.activeFeatureIndex=-1,await p(()=>!r.updating);return h.edits.reduce((e,t)=>e+(t.addFeatures?.length??0),0)>1?null:h.primary?.graphic}async _addAndInitializeEdits(e,t,i,r=!1){const{data:s,_formViewModel:n}=this,{layerInfos:o}=s.viewModel,l=s.addPendingFeature(e,t,{isAssociation:r});i??=X(o,e.sourceLayer),n.features=new a([e]),n.activeFeatureIndex=0,n.layerInfos=i?[i]:null,await p(()=>!n.updating),l.updateAttributes(n.getValues(e)),l.submittable=n.valid}async _setUpCreatingFeaturesStep(){if(this.hasHandles(ge))return;const{data:e,sketchViewModel:a}=this,{creationInfo:n,viewModel:o}=e,{view:d}=o;if(!d||!n?.layer)throw new i("missing-parameters","CreateFeaturesWorkflow requires a view and creationInfo.");const{initialFeature:c,layer:u}=n,p=[],f=[];this._featureFormHandle=l(this._featureFormHandle),this._visualVariableAttributes={rotation:null,size:null},e.editorItem=N(o.editorItems,n.layer),n.template&&(null==e.fullTemplate&&await this._initializeFullTemplateAndExecutorInfo(e),f.push(r(()=>{e.templateExecutorInfo&&(e.templateExecutorInfo.completionResults=[])}))),a.allowDeleteKey=!e.isSharedTemplateWorkflow;const g=ne(d);p.push(g);const w=S(n.layer),{template:y}=n,v=!y||b(y)||F(y)&&"feature"===y.type,_=w&&v;try{if(_){const a=c??new t({attributes:M(e.fullTemplate,n.attributeOverrides,u),sourceLayer:u}),i=await this._processEdits(a);i&&await this._startUpdating({feature:i})}else p.push(he._configureSketchViewModel(this)),c?(x(n)&&n.geometryToPlace&&(c.attributes=M(e.fullTemplate,n.attributeOverrides,u)),a.addGraphic(c),await this._startUpdating({feature:c})):await this._startCreating()}finally{g.remove()}const I=r(()=>{for(const t of e.pendingFeatures)a.removeGraphic(t),e.removePendingFeature(t)}),V=h(()=>d?.timeZone,e=>this.data.timeZone=e,m),k=r(()=>{x(n)&&o.cancelWorkflow({warnIfNoWorkflow:!1})});this._featureFormHandle&&p.push(this._featureFormHandle),this.addHandles(p,this._handleKeys.beforeCommit),this.addHandles(f,this._handleKeys.afterCommit),this.addHandles([s(p),s(f),k,I,V],ge)}async _waitForActiveToolCleared(){const e=this.data.viewModel.view;if(null==e?.activeTool)return;const t=new AbortController;this.addHandles(n(t),we),await p(()=>null==e?.activeTool,t.signal),t.abort()}};function Fe(e,t,a){let i=null;const n=()=>e.snappingOptions.featureSources,o=()=>(i=new C({layer:t}),n().add(i),i),l=()=>{null!=i&&(n().remove(i),i=d(i))};return s([h(()=>{const e=a.creationInfo?.layer,t=n().find(t=>t.layer===e);return{hasFeatureLayerSource:!!t,enabled:t?.enabled??!1}},({hasFeatureLayerSource:e,enabled:t})=>{if(!e)return l();i??=o(),i.enabled=t},g),r(l)])}function _e(e){const t=e.viewModel.view;if(!t)return[];const a=[];if("3d"===t.type){const i=new A({view:t});a.push(h(()=>e.selectedPendingFeature,(e,t)=>{i.remove(e),i.add(t)}),r(()=>i.destroy()))}const i=new A({view:t,highlightName:L});return a.push(h(()=>e.temporaryHighlightFeature,e=>{i.removeAll(),i.add(e)}),r(()=>i.destroy())),a}function Me(e){for(const t of e){const{sourceLayer:e}=t;e&&"globalIdField"in e&&null!=e.globalIdField&&(t.attributes[e.globalIdField]??=w())}}e([y()],ve.prototype,"allowSave",null),e([y()],ve.prototype,"createFeatureState",void 0),e([y()],ve.prototype,"curveResizeDisabled",null),e([y()],ve.prototype,"curveUpdatesDisabled",null),e([y()],ve.prototype,"data",void 0),e([y({constructOnly:!0})],ve.prototype,"isNested",void 0),e([y()],ve.prototype,"formViewModel",null),e([y()],ve.prototype,"hasInvalidFormTemplate",null),e([y()],ve.prototype,"hasPendingEdits",null),e([y()],ve.prototype,"hasPreviousStep",null),e([y()],ve.prototype,"_getDrawMeshHelpMessage",void 0),e([y()],ve.prototype,"helpMessage",null),e([y()],ve.prototype,"noticeMessage",null),e([y()],ve.prototype,"layer",null),e([y()],ve.prototype,"parent",null),e([y()],ve.prototype,"keyboardCancellationEnabled",null),e([y()],ve.prototype,"reliesOnOwnerAdminPrivileges",null),e([y()],ve.prototype,"saveActionLabel",null),e([y()],ve.prototype,"shouldShowAttachments",null),e([y()],ve.prototype,"shouldAllowAttachmentEditing",null),e([y()],ve.prototype,"sketchUpdateOptions",null),e([y()],ve.prototype,"sketchViewModel",null),e([y()],ve.prototype,"availableCreateTools",null),ve=he=e([v("esri.widgets.Editor.CreateFeaturesWorkflow")],ve);const be=ve;export{be as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import r from"../../core/Error.js";import{makeHandle as i,handlesGroup as a,destroyHandle as o}from"../../core/handleUtils.js";import{destroyMaybe as s}from"../../core/maybe.js";import{whenOnce as n,watch as l,initial as d}from"../../core/reactiveUtils.js";import{property as h,subclass as u}from"../../core/accessorSupport/decorators.js";import m from"../../layers/GraphicsLayer.js";import{updateGraphicSymbolWhenRequired as p}from"../../views/draw/support/editingSessionUtils.js";import c from"../../views/draw/support/HighlightHelper.js";import{temporaryHighlightName as f}from"../../views/support/HighlightDefaults.js";import w from"../BatchAttributeForm/BatchAttributeFormViewModel.js";import y from"./Edits.js";import g from"./MergeFeaturesWorkflowData.js";import v from"./Workflow.js";import{handleFormValuesChangeEvent as F,makeMinimalAttributes as _}from"./workflowUtils.js";import{assertViewNot3D as M,assertMergeWorkflowCapabilities as k,assertMinimumFeatureCount as I,assertFeaturesAreFromSameLayer as j,InvalidKeyFeatureError as H}from"./support/errors.js";import{mergeFeatures as E}from"./support/mergeFeaturesUtils.js";var V;const b=Symbol();let A=V=class extends v{constructor(e){super(e),this.type="merge-features",this._formViewModel=null,this._graphicsLayer=null,this._highlightHelper=null}initialize(){const e=this.data.viewModel.view;this._highlightHelper=e?new c({view:e}):null,this._initializeFormViewModel(),this._initializeGraphicsLayer(),this._createAndInitializeEdits(this.data.keyFeature)}destroy(){const e=this._graphicsLayer,{view:t}=this.data.viewModel;t?.destroyed||t?.map.remove(e),this._graphicsLayer=s(this._graphicsLayer),this._formViewModel?.destroy(),this._highlightHelper?.destroy()}get formViewModel(){return this._formViewModel}get hasPendingEdits(){return!1}get layer(){return this.data.editorItem.layer}get parent(){return this.data.parent}get shouldShowAttachments(){return this.data.editorItem.capabilities.attachments.enabled}static async create(e){const{applyEdits:t,applyEditsFeatureService:r,...i}=e,{editorItem:a,features:o}=i;if(M(i.viewModel,"merge-features"),k(a),I(o,2),j(o),i.keyFeature&&!o.includes(i.keyFeature))throw new H;const s=await E(o),n=new V({data:new g({...i,mergedGeometry:s}),onCommit:z(t)});return n._set("steps",L()),n}async enter(){}exit(){}isKeyFeature(e){return this.data.keyFeature===e}isTemporaryHighlightFeature(e){return this.data.temporaryHighlightFeature===e}async setKeyFeature(e){const{data:t}=this;if(e!==t.keyFeature){if(!t.features.includes(e))throw new H;t.keyFeature=e,await this._createAndInitializeEdits(e)}}async start(){return await n(()=>!this.updating),await super.start(),this._makeSketchController()}getFeatureTitle(e){return this.data.getFeatureTitle(e)}async _createAndInitializeEdits(e){const{data:t}=this,r=e.clone();r.geometry=t.mergedGeometry;const i=new y({feature:r});t.edits=i;const a=t.getInitialFeature(e)||e;i.trackChanges(a),await this._setFeatureOnFormViewModel(r,a)}_initializeFormViewModel(){const{data:e}=this,t=e.viewModel.view,r=e.editorItem.layerInfo?[e.editorItem.layerInfo]:null,i=new w({attachmentsEnabled:!0,editType:"UPDATE",highlightHelper:this._highlightHelper,layerInfos:r,map:t?.map,readOnly:!0,spatialReference:t?.spatialReference,timeZone:e.timeZone});this._formViewModel=i,this.addHandles(i.on("values-change",F({filter:t=>t===e.edits?.feature,forEachFeature:e=>{p(e,t?.scale)},forEachValueChange:(t,r)=>e.edits?.setAttribute(t,r)})))}_initializeGraphicsLayer(){const{data:e}=this,{view:t}=e.viewModel,r=new m({elevationInfo:e.editorItem.layer.elevationInfo,internal:!0,listMode:"hide",title:"mergeFeaturesWorkflow-internal"});this._graphicsLayer=r,t?.map.add(r)}_makeSketchController(){return{enter:async()=>{this.addHandles(U(this.data),b)},exit:()=>{this.removeHandles(b)}}}async _setFeatureOnFormViewModel(e,r){const i=this._formViewModel;i.features=new t([e]),i.activeFeatureIndex=0,await i.overrideOriginalFeature(e,r),await n(()=>!i.updating)}};e([h()],A.prototype,"formViewModel",null),e([h()],A.prototype,"hasPendingEdits",null),e([h()],A.prototype,"layer",null),e([h()],A.prototype,"parent",null),e([h()],A.prototype,"shouldShowAttachments",null),e([h()],A.prototype,"type",void 0),e([h()],A.prototype,"_formViewModel",void 0),e([h()],A.prototype,"_graphicsLayer",void 0),e([h()],A.prototype,"_highlightHelper",void 0),A=V=e([u("esri.widgets.Editor.MergeFeaturesWorkflow")],A);const S=A;function L(){return[{id:"choosing-key-feature",async setUp(){},async tearDown(){}}]}function z(e){return async t=>{const{edits:i,keyFeature:a}=t,o=i?.feature?.cloneShallow(),s=t.editorItem.layer;if(!i||!o)throw new r("editing:missing-feature","Workflow data has no edits to submit.");i.attributesModified||(o.attributes=_(o,t.editorItem.layer));const n=[];for(const e of t.features){if(e===a)continue;const t=e.cloneShallow();t.attributes=_(t,s),t.geometry=null,n.push(t)}await e(s,{updateFeatures:[o],deleteFeatures:n})}}function U(e){const t=e.viewModel.view;if(!t)return i();const r=new c({view:t});for(const i of e.features)r.add(i);const s=new c({view:t,highlightName:f}),n=l(()=>e.keyFeature,e=>{s.removeAll(),s.add(e)},d),h=new c({view:t,highlightName:f}),u=l(()=>e.temporaryHighlightFeature,e=>{h.removeAll(),e&&h.add(e)});return a([o(r),n,o(s),u,o(h)])}export{S as default};
2
+ import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import r from"../../core/Error.js";import{makeHandle as i,handlesGroup as a,destroyHandle as o}from"../../core/handleUtils.js";import{destroyMaybe as s}from"../../core/maybe.js";import{whenOnce as n,watch as l,initial as d}from"../../core/reactiveUtils.js";import{property as h,subclass as u}from"../../core/accessorSupport/decorators.js";import m from"../../layers/GraphicsLayer.js";import{updateGraphicSymbolWhenRequired as p}from"../../views/draw/support/editingSessionUtils.js";import c from"../../views/draw/support/HighlightHelper.js";import{temporaryHighlightName as w}from"../../views/support/HighlightDefaults.js";import f from"../BatchAttributeForm/BatchAttributeFormViewModel.js";import y from"./Edits.js";import g from"./MergeFeaturesWorkflowData.js";import v from"./Workflow.js";import{handleFormValuesChangeEvent as F,makeMinimalAttributes as _}from"./workflowUtils.js";import{assertViewNot3D as M,assertMergeWorkflowCapabilities as k,assertMinimumFeatureCount as I,assertFeaturesAreFromSameLayer as j,InvalidKeyFeatureError as H}from"./support/errors.js";import{mergeFeatures as E}from"./support/mergeFeaturesUtils.js";var V;const b=Symbol();let A=V=class extends v{constructor(e){super(e),this.type="merge-features",this._formViewModel=null,this._graphicsLayer=null,this._highlightHelper=null}initialize(){const e=this.data.viewModel.view;this._highlightHelper=e?new c({view:e}):null,this._initializeFormViewModel(),this._initializeGraphicsLayer(),this._createAndInitializeEdits(this.data.keyFeature)}destroy(){const e=this._graphicsLayer,{view:t}=this.data.viewModel;t?.destroyed||t?.map.remove(e),this._graphicsLayer=s(this._graphicsLayer),this._formViewModel?.destroy(),this._highlightHelper?.destroy()}get formViewModel(){return this._formViewModel}get hasPendingEdits(){return!1}get layer(){return this.data.editorItem.layer}get parent(){return this.data.parent}get shouldShowAttachments(){return this.data.editorItem.capabilities.attachments.enabled}static async create(e){const{applyEdits:t,applyEditsFeatureService:r,...i}=e,{editorItem:a,features:o}=i;if(M(i.viewModel,"merge-features"),k(a),I(o,2),j(o),i.keyFeature&&!o.includes(i.keyFeature))throw new H;const s=await E(o),n=new V({data:new g({...i,mergedGeometry:s}),onCommit:z(t)});return n._set("steps",L()),n}async enter(){}exit(){}isKeyFeature(e){return this.data.keyFeature===e}isTemporaryHighlightFeature(e){return this.data.temporaryHighlightFeature===e}async setKeyFeature(e){const{data:t}=this;if(e!==t.keyFeature){if(!t.features.includes(e))throw new H;t.keyFeature=e,await this._createAndInitializeEdits(e)}}async start(){return await n(()=>!this.updating),await super.start(),this._makeSketchController()}getFeatureTitle(e){return this.data.getFeatureTitle(e)}async _createAndInitializeEdits(e){const{data:t}=this,r=e.clone();r.geometry=t.mergedGeometry;const i=new y({feature:r});t.edits=i;const a=t.getInitialFeature(e)||e;i.trackChanges(a),await this._setFeatureOnFormViewModel(r,a)}_initializeFormViewModel(){const{data:e}=this,t=e.viewModel.view,r=e.editorItem.layerInfo?[e.editorItem.layerInfo]:null,i=new f({attachmentsEnabled:!0,editType:"UPDATE",highlightHelper:this._highlightHelper,layerInfos:r,readOnly:!0,spatialReference:t?.spatialReference,view:t});this._formViewModel=i,this.addHandles(i.on("values-change",F({filter:t=>t===e.edits?.feature,forEachFeature:e=>{p(e,t?.scale)},forEachValueChange:(t,r)=>e.edits?.setAttribute(t,r)})))}_initializeGraphicsLayer(){const{data:e}=this,{view:t}=e.viewModel,r=new m({elevationInfo:e.editorItem.layer.elevationInfo,internal:!0,listMode:"hide",title:"mergeFeaturesWorkflow-internal"});this._graphicsLayer=r,t?.map.add(r)}_makeSketchController(){return{enter:async()=>{this.addHandles(U(this.data),b)},exit:()=>{this.removeHandles(b)}}}async _setFeatureOnFormViewModel(e,r){const i=this._formViewModel;i.features=new t([e]),i.activeFeatureIndex=0,await i.overrideOriginalFeature(e,r),await n(()=>!i.updating)}};e([h()],A.prototype,"formViewModel",null),e([h()],A.prototype,"hasPendingEdits",null),e([h()],A.prototype,"layer",null),e([h()],A.prototype,"parent",null),e([h()],A.prototype,"shouldShowAttachments",null),e([h()],A.prototype,"type",void 0),e([h()],A.prototype,"_formViewModel",void 0),e([h()],A.prototype,"_graphicsLayer",void 0),e([h()],A.prototype,"_highlightHelper",void 0),A=V=e([u("esri.widgets.Editor.MergeFeaturesWorkflow")],A);const S=A;function L(){return[{id:"choosing-key-feature",async setUp(){},async tearDown(){}}]}function z(e){return async t=>{const{edits:i,keyFeature:a}=t,o=i?.feature?.cloneShallow(),s=t.editorItem.layer;if(!i||!o)throw new r("editing:missing-feature","Workflow data has no edits to submit.");i.attributesModified||(o.attributes=_(o,t.editorItem.layer));const n=[];for(const e of t.features){if(e===a)continue;const t=e.cloneShallow();t.attributes=_(t,s),t.geometry=null,n.push(t)}await e(s,{updateFeatures:[o],deleteFeatures:n})}}function U(e){const t=e.viewModel.view;if(!t)return i();const r=new c({view:t});for(const i of e.features)r.add(i);const s=new c({view:t,highlightName:w}),n=l(()=>e.keyFeature,e=>{s.removeAll(),s.add(e)},d),h=new c({view:t,highlightName:w}),u=l(()=>e.temporaryHighlightFeature,e=>{h.removeAll(),e&&h.add(e)});return a([o(r),n,o(s),u,o(h)])}export{S as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import i from"../../core/Error.js";import{makeHandle as r,handlesGroup as a,destroyHandle as o}from"../../core/handleUtils.js";import"../../core/has.js";import{destroyMaybe as s}from"../../core/maybe.js";import{debounce as n}from"../../core/promiseUtils.js";import{watch as l,whenOnce as d,on as p,initial as u}from"../../core/reactiveUtils.js";import{property as c,subclass as h}from"../../core/accessorSupport/decorators.js";import m from"../../layers/GraphicsLayer.js";import{swapForEditingSession as y,updateGraphicSymbolWhenRequired as w}from"../../views/draw/support/editingSessionUtils.js";import{getDrawHelpMessage as g}from"../../views/draw/support/helpMessageUtils.js";import f from"../../views/draw/support/HighlightHelper.js";import v from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as _}from"../../views/support/HighlightDefaults.js";import F from"../BatchAttributeForm/BatchAttributeFormViewModel.js";import M from"./Edits.js";import S from"./SplitFeatureWorkflowData.js";import b from"./Workflow.js";import{activeSketchToolDrawsUnsupportedCurve as k,containsUnsupportedCurve as I,createWorkflowSteps as T,handleFormValuesChangeEvent as V,makeMinimalAttributes as E}from"./workflowUtils.js";import{assertViewNot3D as G,assertSplitWorkflowCapabilities as H}from"./support/errors.js";import{getCompatibleSpitterGeometryType as j,ensureSplittableGeometry as x,makeNewFeatureAttributes as C,splitGeometry as U,canSplitByPoint as L,isSplitterGeometry as W}from"./support/splitFeatureUtils.js";import O from"../Sketch/SketchViewModel.js";import{getDrawToolGeometryTypeFromCreateTool as A}from"../Sketch/support/sketchUtils.js";var P;const z=Symbol(),D=Symbol();let R=P=class extends b{constructor(e){super(e),this.defaultSplitterGeometryType=null,this.type="split-feature",this._activeFeature=null,this._formViewModel=null,this._graphicsLayer=null,this._highlightHelper=null,this._lastSplitterGeometryWasInvalid=!1,this._sketchViewModel=null}initialize(){const e=this.data.viewModel.view;this._highlightHelper=e?new f({view:e,highlightName:_}):null,this._initializeFormViewModel();const t=this._initializeGraphicsLayer();this._initializeSketchViewModel(t)}destroy(){const e=this._graphicsLayer,{view:t}=this.data.viewModel;t?.destroyed||t?.map.remove(e),this._graphicsLayer=s(this._graphicsLayer),this._formViewModel.destroy(),this._sketchViewModel.destroy(),this._highlightHelper?.destroy()}get activeFeature(){return this._activeFeature}get allowSave(){const{data:e}=this;return null!=e.existingFeatureEdits&&null!=e.newFeatureEdits&&!this.updating}get availableCreateTools(){const e=["polyline","polygon","rectangle","circle","freehandPolyline","freehandPolygon"];switch(this.data.editorItem.layer.geometryType){case"polygon":case"multipoint":return e;case"polyline":return["point",...e];default:return[]}}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return!!this.data.editorItem?.hasInvalidFormTemplate}get hasPreviousStep(){return null!==this._activeFeature||this._stepIndex>0}get helpMessage(){const{activeCreateToolDrawMode:e,activeTool:t,createGraphic:i,drawTool:r,isUsingLegacyCreateTools:a}=this._sketchViewModel;if(!a)return r?.helpMessageKey??"noTool";const o=A(t);return"mesh"!==o?g(o,i?.geometry,e):void 0}get layer(){return this.data.editorItem.layer}get parent(){return this.data.parent}get sketchUpdateOptions(){return{enableScaling:!this.curveResizeDisabled,multipleSelectionEnabled:!1}}get updating(){return this._updatingHandles.updating||this._formViewModel.updating||this._sketchViewModel.updating}get noticeMessage(){return this._splittingMayIntroduceCurves&&k(this._sketchViewModel,this.data.editorItem)?"curveToolDensifyWarning":this._lastSplitterGeometryWasInvalid?"invalidSplitterGeometry":void 0}get _splittingMayIntroduceCurves(){return"polygon"===this.data.editorItem.layer.geometryType}async back(e){if(this.activeFeature)return await this.setActiveFeature(null);await super.back(e)}static create(e){const{applyEdits:t,applyEditsFeatureService:r,defaultSplitterGeometryType:a,startAt:o,...s}=e;if(G(e.viewModel,"split-feature"),H(s.editorItem),"reviewing-features"===o){if(!s.splitterGeometry)throw new i("editing:split-geometry-required","Must provide the split geometry to start at the 'reviewing-features' step.");const e=j(x(s.feature.geometry),s.splitterGeometry.type);if(s.splitterGeometry.type!==e)throw new i("editing:incompatible-split-geometries",`Geometry of type '${s.splitterGeometry.type}' cannot be used to split geometry of type '${s.feature.geometry?.type}'.`)}const n=new P({data:new S(s),defaultSplitterGeometryType:a,onCommit:B(e.applyEdits)});return n._set("steps",P._createWorkflowSteps(n,o)),n}async enter(){}exit(){if("reviewing-features"!==this.stepId)throw new i("editing:invalid-exit-state","The SplitFeatureWorkflow can only be exited when in the 'reviewing-features' step.")}async setActiveFeature(e){const t=this._activeFeature;if(e===t)return;const r=this.data,a=t?r.getEditsForFeature(t):null;if(a&&(a.submittable=this._formViewModel.valid),this._activeFeature=e,null==e)return;const o=this.data.getRoleForFeature(e);if(!o)throw new i("editing:unknown-feature","The provided feature is not part of this workflow.");await this._setFeatureOnFormViewModel(e,o)}async commit(e){const{newFeatureEdits:t,existingFeatureEdits:i,editorItem:r}=this.data,a=[i?.feature,t?.feature].filter(e=>!!e);if(e&&I(a,r)){if(!await e("curveEditingDensifyPrompt"))return this.reset()}return super.commit()}async start(){return await super.start(),this._makeSketchController()}async _createAndInitializeEdits({newPart:e,remainingPart:t}){const{data:i}=this,r=i.feature,a=this._formViewModel,o=r.clone();o.geometry=t;const s=new M({feature:o});i.existingFeatureEdits=s,s.trackChanges(i.initialFeature),await this._setFeatureOnFormViewModel(o,"existing"),s.submittable=a.valid;const n=r.clone();n.geometry=e,n.attributes=C(r.attributes,i.editorItem.layer);const l=new M({feature:n});return i.newFeatureEdits=l,l.trackChanges(),await this._setFeatureOnFormViewModel(n,"new"),l.submittable=a.valid,{featureToCreate:n,featureToUpdate:o}}static _createWorkflowSteps(e,t="drawing-splitter-geometry"){const{data:r}=e;return T(["drawing-splitter-geometry","reviewing-features"],t,{"drawing-splitter-geometry":()=>({id:"drawing-splitter-geometry",async setUp(){const t=x(r.feature.geometry),a=j(t,e.defaultSplitterGeometryType),{snappingManager:o}=r;L(t)&&o&&e.addHandles(Z(o,e.layer));const s=e._sketchViewModel;e.addHandles([p(()=>s,"create",async t=>{if("start"===t.state&&e._lastSplitterGeometryWasInvalid&&(e._lastSplitterGeometryWasInvalid=!1),"complete"===t.state){e._graphicsLayer.removeAll();const o=t.graphic?.geometry;try{if(!W(o))throw new i("editing:invalid-split-geometry","The geometry produced by the Sketch operation cannot be used for splitting.");r.splitterGeometry=o,r.splitResult=await e._updatingHandles.addPromise(e._executeSplit(o)),await e.next()}catch(a){e._lastSplitterGeometryWasInvalid=!0,await s.create(t.tool)}}}),l(()=>s.activeTool,(t,i)=>{"point"===t&&!e.hasHandles(z)&&o?e.addHandles($(o,e.layer),z):"point"===i&&e.removeHandles(z)})],this.id),await s.create(a)},async tearDown(){e.removeHandles(this.id)}}),"reviewing-features":()=>({id:"reviewing-features",async setUp(){const t=r.splitterGeometry;if(!t)throw new i("editing:missing-splitter-geometry","The `splitterGeometry` property of the workflow's data must be set in order to start the 'reviewing-features' step.");const a=r.splitResult??await e._executeSplit(t),{featureToCreate:o,featureToUpdate:s}=await e._createAndInitializeEdits(a),n=await e._displayFeatureGraphics(s,o);e.addHandles(n,this.id)},async tearDown(){e.removeHandles(this.id)}})})}async _displayFeatureGraphics(e,t){const{data:i,_graphicsLayer:o}=this,s=i.viewModel.view,d=[];if(!e||!t||!s)return r();const p=n(i=>Promise.all([w(e,i),w(t,i)]));return await p("2d"===s.type?s.scale:null),"2d"===s.type&&d.push(l(()=>s.scale,e=>p(e))),o.add(t),d.push(r(()=>o.remove(t))),d.push(await y(o,s,i.feature,e)),a(d)}async _executeSplit(e){const{data:t}=this,{feature:r}=t,a=r.geometry;if(!a)throw new i("editing:feature-has-no-geometry","Cannot split the provided feature as it has no geometry.");const o=await U(a,e);if(!o||!o.newPart)throw new i("editing:split-failed","The split operation did not produce a valid result.");return o}_initializeFormViewModel(){const{data:e}=this,t=e.viewModel.view,i=e.editorItem.layerInfo?[e.editorItem.layerInfo]:null,r=new F({activeFeatureIndex:0,highlightHelper:this._highlightHelper,layerInfos:i,map:t?.map,spatialReference:t?.spatialReference,timeZone:e.timeZone});this._formViewModel=r,this.addHandles(r.on("values-change",V({forEachFeature:e=>{w(e,t?.scale)},forEachValueChange:(t,i,r)=>e.getEditsForFeature(r)?.setAttribute(t,i)})))}_initializeGraphicsLayer(){const{data:e}=this,{view:t}=e.viewModel,i=new m({elevationInfo:e.editorItem.layer.elevationInfo,internal:!0,listMode:"hide",title:"splitFeatureWorkflow-internal"});return this._graphicsLayer=i,t?.map.add(i),i}_initializeSketchViewModel(e){const{data:t}=this,{view:i}=t.viewModel;this._sketchViewModel=new O({layer:e,creationMode:"single",sketchOptions:t.sketchOptions,snappingManager:t.snappingManager,useLegacyCreateTools:t.viewModel.useLegacyCreateTools,updateOnGraphicClick:!1,defaultUpdateOptions:this.sketchUpdateOptions,view:i})}_makeSketchController(){return{enter:async()=>this.addHandles(q(this)),exit:()=>this.removeHandles(D),viewModel:this._sketchViewModel}}async _setFeatureOnFormViewModel(e,i){const r=this._formViewModel;r.features=new t([e]),r.activeFeatureIndex=0,"existing"===i?(r.editType="UPDATE",r.overrideOriginalFeature(e,this.data.initialFeature)):r.editType="INSERT",await d(()=>!r.updating)}get test(){}};e([c()],R.prototype,"activeFeature",null),e([c()],R.prototype,"allowSave",null),e([c()],R.prototype,"availableCreateTools",null),e([c()],R.prototype,"defaultSplitterGeometryType",void 0),e([c()],R.prototype,"formViewModel",null),e([c()],R.prototype,"hasInvalidFormTemplate",null),e([c()],R.prototype,"hasPreviousStep",null),e([c()],R.prototype,"helpMessage",null),e([c()],R.prototype,"layer",null),e([c()],R.prototype,"parent",null),e([c()],R.prototype,"sketchUpdateOptions",null),e([c()],R.prototype,"type",void 0),e([c()],R.prototype,"updating",null),e([c()],R.prototype,"noticeMessage",null),e([c()],R.prototype,"_activeFeature",void 0),e([c()],R.prototype,"_formViewModel",void 0),e([c()],R.prototype,"_graphicsLayer",void 0),e([c()],R.prototype,"_highlightHelper",void 0),e([c()],R.prototype,"_lastSplitterGeometryWasInvalid",void 0),e([c()],R.prototype,"_sketchViewModel",void 0),e([c()],R.prototype,"_splittingMayIntroduceCurves",null),R=P=e([h("esri.widgets.Editor.SplitFeatureWorkflow")],R);const N=R;function B(e){return async t=>{const{existingFeatureEdits:r,newFeatureEdits:a}=t,o=r?.feature?.cloneShallow(),s=a?.feature?.cloneShallow(),n=t.editorItem.layer;if(null==o||null==s)throw new i("editing:missing-features","Expected both a feature to update and a feature to add for the split operation.");r?.attributesModified||(o.attributes=E(o,t.editorItem.layer)),await e(n,{addFeatures:[s],updateFeatures:[o]})}}function Z(e,t){if(e.options.featureSources.some(e=>e.layer===t))return r();const i=new v({enabled:!1,layer:t});return e.options.featureSources.add(i),r(()=>{e.options.featureSources.remove(i),i.destroy()})}function $(e,t){const{options:i}=e,a=i.enabled;i.enabled=!0;const o=i.featureEnabled;i.featureEnabled=!0;const s=i.distance;i.distance=15;const n=new Map;for(const r of i.featureSources)n.set(r,r.enabled),r.layer===t?r.enabled=!0:r.enabled=!1;return r(()=>{i.enabled=a,i.featureEnabled=o,i.distance=s;for(const[e,t]of n)e.enabled=t})}function q(e){const t=e.data,{feature:i,viewModel:s}=t,{view:n}=s;if(!n)return r();const d=new f({view:n}),p=l(()=>e.stepId,e=>{switch(d.removeAll(),e){case"drawing-splitter-geometry":d.add(i);break;case"reviewing-features":d.add(t.existingFeatureEdits?.feature),d.add(t.newFeatureEdits?.feature)}},u),c=new f({view:n,highlightName:_}),h=l(()=>t.temporaryHighlightFeature,(t,i)=>{i&&i!==e.activeFeature&&c.remove(i),t&&c.add(t)}),m=l(()=>e.activeFeature,(e,i)=>{i&&i!==t.temporaryHighlightFeature&&c.remove(i),e&&c.add(e)});return a([p,h,m,o(d),o(c)])}export{N as default};
2
+ import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import i from"../../core/Error.js";import{makeHandle as r,handlesGroup as a,destroyHandle as o}from"../../core/handleUtils.js";import"../../core/has.js";import{destroyMaybe as s}from"../../core/maybe.js";import{debounce as n}from"../../core/promiseUtils.js";import{watch as l,whenOnce as d,on as p,initial as u}from"../../core/reactiveUtils.js";import{property as c,subclass as h}from"../../core/accessorSupport/decorators.js";import m from"../../layers/GraphicsLayer.js";import{swapForEditingSession as y,updateGraphicSymbolWhenRequired as w}from"../../views/draw/support/editingSessionUtils.js";import{getDrawHelpMessage as g}from"../../views/draw/support/helpMessageUtils.js";import f from"../../views/draw/support/HighlightHelper.js";import v from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as _}from"../../views/support/HighlightDefaults.js";import F from"../BatchAttributeForm/BatchAttributeFormViewModel.js";import M from"./Edits.js";import S from"./SplitFeatureWorkflowData.js";import b from"./Workflow.js";import{activeSketchToolDrawsUnsupportedCurve as k,containsUnsupportedCurve as I,createWorkflowSteps as T,handleFormValuesChangeEvent as V,makeMinimalAttributes as E}from"./workflowUtils.js";import{assertViewNot3D as G,assertSplitWorkflowCapabilities as H}from"./support/errors.js";import{getCompatibleSpitterGeometryType as j,ensureSplittableGeometry as x,makeNewFeatureAttributes as C,splitGeometry as U,canSplitByPoint as L,isSplitterGeometry as W}from"./support/splitFeatureUtils.js";import O from"../Sketch/SketchViewModel.js";import{getDrawToolGeometryTypeFromCreateTool as A}from"../Sketch/support/sketchUtils.js";var P;const z=Symbol(),D=Symbol();let R=P=class extends b{constructor(e){super(e),this.defaultSplitterGeometryType=null,this.type="split-feature",this._activeFeature=null,this._formViewModel=null,this._graphicsLayer=null,this._highlightHelper=null,this._lastSplitterGeometryWasInvalid=!1,this._sketchViewModel=null}initialize(){const e=this.data.viewModel.view;this._highlightHelper=e?new f({view:e,highlightName:_}):null,this._initializeFormViewModel();const t=this._initializeGraphicsLayer();this._initializeSketchViewModel(t)}destroy(){const e=this._graphicsLayer,{view:t}=this.data.viewModel;t?.destroyed||t?.map.remove(e),this._graphicsLayer=s(this._graphicsLayer),this._formViewModel.destroy(),this._sketchViewModel.destroy(),this._highlightHelper?.destroy()}get activeFeature(){return this._activeFeature}get allowSave(){const{data:e}=this;return null!=e.existingFeatureEdits&&null!=e.newFeatureEdits&&!this.updating}get availableCreateTools(){const e=["polyline","polygon","rectangle","circle","freehandPolyline","freehandPolygon"];switch(this.data.editorItem.layer.geometryType){case"polygon":case"multipoint":return e;case"polyline":return["point",...e];default:return[]}}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return!!this.data.editorItem?.hasInvalidFormTemplate}get hasPreviousStep(){return null!==this._activeFeature||this._stepIndex>0}get helpMessage(){const{activeCreateToolDrawMode:e,activeTool:t,createGraphic:i,drawTool:r,isUsingLegacyCreateTools:a}=this._sketchViewModel;if(!a)return r?.helpMessageKey??"noTool";const o=A(t);return"mesh"!==o?g(o,i?.geometry,e):void 0}get layer(){return this.data.editorItem.layer}get parent(){return this.data.parent}get sketchUpdateOptions(){return{enableScaling:!this.curveResizeDisabled,multipleSelectionEnabled:!1}}get updating(){return this._updatingHandles.updating||this._formViewModel.updating||this._sketchViewModel.updating}get noticeMessage(){return this._splittingMayIntroduceCurves&&k(this._sketchViewModel,this.data.editorItem)?"curveToolDensifyWarning":this._lastSplitterGeometryWasInvalid?"invalidSplitterGeometry":void 0}get _splittingMayIntroduceCurves(){return"polygon"===this.data.editorItem.layer.geometryType}async back(e){if(this.activeFeature)return await this.setActiveFeature(null);await super.back(e)}static create(e){const{applyEdits:t,applyEditsFeatureService:r,defaultSplitterGeometryType:a,startAt:o,...s}=e;if(G(e.viewModel,"split-feature"),H(s.editorItem),"reviewing-features"===o){if(!s.splitterGeometry)throw new i("editing:split-geometry-required","Must provide the split geometry to start at the 'reviewing-features' step.");const e=j(x(s.feature.geometry),s.splitterGeometry.type);if(s.splitterGeometry.type!==e)throw new i("editing:incompatible-split-geometries",`Geometry of type '${s.splitterGeometry.type}' cannot be used to split geometry of type '${s.feature.geometry?.type}'.`)}const n=new P({data:new S(s),defaultSplitterGeometryType:a,onCommit:B(e.applyEdits)});return n._set("steps",P._createWorkflowSteps(n,o)),n}async enter(){}exit(){if("reviewing-features"!==this.stepId)throw new i("editing:invalid-exit-state","The SplitFeatureWorkflow can only be exited when in the 'reviewing-features' step.")}async setActiveFeature(e){const t=this._activeFeature;if(e===t)return;const r=this.data,a=t?r.getEditsForFeature(t):null;if(a&&(a.submittable=this._formViewModel.valid),this._activeFeature=e,null==e)return;const o=this.data.getRoleForFeature(e);if(!o)throw new i("editing:unknown-feature","The provided feature is not part of this workflow.");await this._setFeatureOnFormViewModel(e,o)}async commit(e){const{newFeatureEdits:t,existingFeatureEdits:i,editorItem:r}=this.data,a=[i?.feature,t?.feature].filter(e=>!!e);if(e&&I(a,r)){if(!await e("curveEditingDensifyPrompt"))return this.reset()}return super.commit()}async start(){return await super.start(),this._makeSketchController()}async _createAndInitializeEdits({newPart:e,remainingPart:t}){const{data:i}=this,r=i.feature,a=this._formViewModel,o=r.clone();o.geometry=t;const s=new M({feature:o});i.existingFeatureEdits=s,s.trackChanges(i.initialFeature),await this._setFeatureOnFormViewModel(o,"existing"),s.submittable=a.valid;const n=r.clone();n.geometry=e,n.attributes=C(r.attributes,i.editorItem.layer);const l=new M({feature:n});return i.newFeatureEdits=l,l.trackChanges(),await this._setFeatureOnFormViewModel(n,"new"),l.submittable=a.valid,{featureToCreate:n,featureToUpdate:o}}static _createWorkflowSteps(e,t="drawing-splitter-geometry"){const{data:r}=e;return T(["drawing-splitter-geometry","reviewing-features"],t,{"drawing-splitter-geometry":()=>({id:"drawing-splitter-geometry",async setUp(){const t=x(r.feature.geometry),a=j(t,e.defaultSplitterGeometryType),{snappingManager:o}=r;L(t)&&o&&e.addHandles($(o,e.layer));const s=e._sketchViewModel;e.addHandles([p(()=>s,"create",async t=>{if("start"===t.state&&e._lastSplitterGeometryWasInvalid&&(e._lastSplitterGeometryWasInvalid=!1),"complete"===t.state){e._graphicsLayer.removeAll();const o=t.graphic?.geometry;try{if(!W(o))throw new i("editing:invalid-split-geometry","The geometry produced by the Sketch operation cannot be used for splitting.");r.splitterGeometry=o,r.splitResult=await e._updatingHandles.addPromise(e._executeSplit(o)),await e.next()}catch(a){e._lastSplitterGeometryWasInvalid=!0,await s.create(t.tool)}}}),l(()=>s.activeTool,(t,i)=>{"point"===t&&!e.hasHandles(z)&&o?e.addHandles(q(o,e.layer),z):"point"===i&&e.removeHandles(z)})],this.id),await s.create(a)},async tearDown(){e.removeHandles(this.id)}}),"reviewing-features":()=>({id:"reviewing-features",async setUp(){const t=r.splitterGeometry;if(!t)throw new i("editing:missing-splitter-geometry","The `splitterGeometry` property of the workflow's data must be set in order to start the 'reviewing-features' step.");const a=r.splitResult??await e._executeSplit(t),{featureToCreate:o,featureToUpdate:s}=await e._createAndInitializeEdits(a),n=await e._displayFeatureGraphics(s,o);e.addHandles(n,this.id)},async tearDown(){e.removeHandles(this.id)}})})}async _displayFeatureGraphics(e,t){const{data:i,_graphicsLayer:o}=this,s=i.viewModel.view,d=[];if(!e||!t||!s)return r();const p=n(i=>Promise.all([w(e,i),w(t,i)]));return await p("2d"===s.type?s.scale:null),"2d"===s.type&&d.push(l(()=>s.scale,e=>p(e))),o.add(t),d.push(r(()=>o.remove(t))),d.push(await y(o,s,i.feature,e)),a(d)}async _executeSplit(e){const{data:t}=this,{feature:r}=t,a=r.geometry;if(!a)throw new i("editing:feature-has-no-geometry","Cannot split the provided feature as it has no geometry.");const o=await U(a,e);if(!o||!o.newPart)throw new i("editing:split-failed","The split operation did not produce a valid result.");return o}_initializeFormViewModel(){const{data:e}=this,t=e.viewModel.view,i=e.editorItem.layerInfo?[e.editorItem.layerInfo]:null,r=new F({activeFeatureIndex:0,highlightHelper:this._highlightHelper,layerInfos:i,spatialReference:t?.spatialReference,view:t});this._formViewModel=r,this.addHandles(r.on("values-change",V({forEachFeature:e=>{w(e,t?.scale)},forEachValueChange:(t,i,r)=>e.getEditsForFeature(r)?.setAttribute(t,i)})))}_initializeGraphicsLayer(){const{data:e}=this,{view:t}=e.viewModel,i=new m({elevationInfo:e.editorItem.layer.elevationInfo,internal:!0,listMode:"hide",title:"splitFeatureWorkflow-internal"});return this._graphicsLayer=i,t?.map.add(i),i}_initializeSketchViewModel(e){const{data:t}=this,{view:i}=t.viewModel;this._sketchViewModel=new O({layer:e,creationMode:"single",sketchOptions:t.sketchOptions,snappingManager:t.snappingManager,useLegacyCreateTools:t.viewModel.useLegacyCreateTools,updateOnGraphicClick:!1,defaultUpdateOptions:this.sketchUpdateOptions,view:i})}_makeSketchController(){return{enter:async()=>this.addHandles(K(this)),exit:()=>this.removeHandles(D),viewModel:this._sketchViewModel}}async _setFeatureOnFormViewModel(e,i){const r=this._formViewModel;r.features=new t([e]),r.activeFeatureIndex=0,"existing"===i?(r.editType="UPDATE",r.overrideOriginalFeature(e,this.data.initialFeature)):r.editType="INSERT",await d(()=>!r.updating)}get test(){}};e([c()],R.prototype,"activeFeature",null),e([c()],R.prototype,"allowSave",null),e([c()],R.prototype,"availableCreateTools",null),e([c()],R.prototype,"defaultSplitterGeometryType",void 0),e([c()],R.prototype,"formViewModel",null),e([c()],R.prototype,"hasInvalidFormTemplate",null),e([c()],R.prototype,"hasPreviousStep",null),e([c()],R.prototype,"helpMessage",null),e([c()],R.prototype,"layer",null),e([c()],R.prototype,"parent",null),e([c()],R.prototype,"sketchUpdateOptions",null),e([c()],R.prototype,"type",void 0),e([c()],R.prototype,"updating",null),e([c()],R.prototype,"noticeMessage",null),e([c()],R.prototype,"_activeFeature",void 0),e([c()],R.prototype,"_formViewModel",void 0),e([c()],R.prototype,"_graphicsLayer",void 0),e([c()],R.prototype,"_highlightHelper",void 0),e([c()],R.prototype,"_lastSplitterGeometryWasInvalid",void 0),e([c()],R.prototype,"_sketchViewModel",void 0),e([c()],R.prototype,"_splittingMayIntroduceCurves",null),R=P=e([h("esri.widgets.Editor.SplitFeatureWorkflow")],R);const N=R;function B(e){return async t=>{const{existingFeatureEdits:r,newFeatureEdits:a}=t,o=r?.feature?.cloneShallow(),s=a?.feature?.cloneShallow(),n=t.editorItem.layer;if(null==o||null==s)throw new i("editing:missing-features","Expected both a feature to update and a feature to add for the split operation.");r?.attributesModified||(o.attributes=E(o,t.editorItem.layer)),await e(n,{addFeatures:[s],updateFeatures:[o]})}}function $(e,t){if(e.options.featureSources.some(e=>e.layer===t))return r();const i=new v({enabled:!1,layer:t});return e.options.featureSources.add(i),r(()=>{e.options.featureSources.remove(i),i.destroy()})}function q(e,t){const{options:i}=e,a=i.enabled;i.enabled=!0;const o=i.featureEnabled;i.featureEnabled=!0;const s=i.distance;i.distance=15;const n=new Map;for(const r of i.featureSources)n.set(r,r.enabled),r.layer===t?r.enabled=!0:r.enabled=!1;return r(()=>{i.enabled=a,i.featureEnabled=o,i.distance=s;for(const[e,t]of n)e.enabled=t})}function K(e){const t=e.data,{feature:i,viewModel:s}=t,{view:n}=s;if(!n)return r();const d=new f({view:n}),p=l(()=>e.stepId,e=>{switch(d.removeAll(),e){case"drawing-splitter-geometry":d.add(i);break;case"reviewing-features":d.add(t.existingFeatureEdits?.feature),d.add(t.newFeatureEdits?.feature)}},u),c=new f({view:n,highlightName:_}),h=l(()=>t.temporaryHighlightFeature,(t,i)=>{i&&i!==e.activeFeature&&c.remove(i),t&&c.add(t)}),m=l(()=>e.activeFeature,(e,i)=>{i&&i!==t.temporaryHighlightFeature&&c.remove(i),e&&c.add(e)});return a([p,h,m,o(d),o(c)])}export{N as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import r from"../../core/Error.js";import o from"../../core/Logger.js";import{destroyMaybe as i}from"../../core/maybe.js";import{whenOnce as s}from"../../core/reactiveUtils.js";import{property as a,subclass as n}from"../../core/accessorSupport/decorators.js";import{isSceneLayer as l,isTable as d}from"../../layers/support/layerUtils.js";import u from"../BatchAttributeForm/BatchAttributeFormViewModel.js";import p from"./UpdateFeaturesWorkflowData.js";import c from"./Workflow.js";import{handleFormValuesChangeEvent as h,whenEditorLayerView as f,findEditorItemForLayer as m}from"./workflowUtils.js";import{MultipleSourceLayersError as g}from"./support/errors.js";import{SketchController as y}from"./support/SketchController.js";var w;const F=()=>o.getLogger("esri.widgets.Editor.UpdateFeaturesWorkflow"),v=Symbol();let b=w=class extends c{constructor(e){super(e),this.type="update-features",this._formViewModel=null,this._sketchController=null}async initialize(){this._initializeFormViewModel();try{await this._updatingHandles.addPromise((async()=>{const{fullFeatures:e}=await this.data.when();this._formViewModel.features=new t(e),this._initializeVisuals(e)})())}catch(e){this.cancel({force:!0,error:new r("update-features-workflow:initialize","Failed to initialize the workflow data.",e)})}}destroy(){this._sketchController=i(this._sketchController),this._formViewModel.destroy()}get curveUpdatesDisabled(){return this.data.curveUpdatesDisabled}get features(){return this.data.features}get featureInfos(){return this.data.featureInfos}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return this.data.editorItems.some(e=>e.hasInvalidFormTemplate)}get hasPendingEdits(){const{data:e}=this;return e.fullFeatures.some(t=>!!e.getPendingEditsForFeature(t)?.modified)}get parent(){return this.data.parent}get saveActionLabel(){return"update"}get selectedFeature(){return this.data.selectedFeature}get sketchUpdateOptions(){const{data:e}=this,t=e.fullFeatures,r=_(e),o=e.getEditorItemForLayer(r),i=!this.selectedFeature||t.length>1;return{multipleSelectionEnabled:!1,reshapeOptions:{enableCreateCurveFromStraightEdge:!l(r)&&!!o?.capabilities.supportsTrueCurve},tool:i?"move":void 0}}get sketchViewModel(){return this._sketchController?.viewModel}get supportsMergeFeaturesWorkflow(){const e=this.data,{fullFeatures:t,layers:r}=e;return!(1!==r.length||t.length<2)&&(!this.curveUpdatesDisabled&&!!e.getEditorItemForLayer(r[0])?.supportsMergeFeaturesWorkflow)}getUpdating(){return!!this._sketchController?.updating}get viewGraphics(){return this._sketchController?.sketchGraphics??this.data.fullFeatures}static create(e){const{applyEdits:t,applyEditsFeatureService:r,...o}=e,{features:i,featureInfos:s,viewModel:a}=o,n=new Set;function l(e){const t=m(a.editorItems,e);t&&n.add(t)}s?.length?s.forEach(({layer:e})=>l(e)):i?.length&&(F().warn("editor:update-features-workflow-data-features","UpdateFeaturesWorkflow: 'features' is deprecrated, use 'featureInfos'"),i.forEach(e=>l(e.sourceLayer??e.layer)));const d=Array.from(n),u=new w({data:new p({...o,editorItems:d}),onCommit:E(e.applyEdits)});return u._set("steps",M()),u}async deleteAndCommit(){return this.data.stageDelete(),this.commit()}async enter(){}exit(e){}async reset(){}async save(){const{formViewModel:e}=this;await e.submit(),e.valid&&await super.save()}async start(){await super.start(),await s(()=>!this.updating);const e=this._sketchController;if(e)return e;const{data:t}=this,{view:r}=t.viewModel,o=_(t);return!r||d(o)?{enter:async()=>{},exit:()=>{}}:{enter:()=>this._initializeHighlights(t.fullFeatures,o,r),exit:()=>this.removeHandles(v)}}_initializeFormViewModel(){const{data:e}=this,t=e.viewModel.view,r=e.getEditorItemForLayer(_(e)),o=r?.layerInfo?[r.layerInfo]:null,i=new u({editType:"UPDATE",map:t?.map,readOnly:!1===r?.capabilities.update.attributes,spatialReference:t?.spatialReference,timeZone:e.timeZone,layerInfos:o});this._formViewModel=i,this.addHandles(i.on("values-change",h({forEachFeature:(t,r)=>{const o=e.getPendingEditsForFeature(t);if(o){for(const{fieldName:e,value:t}of r)o.setAttribute(e,t);this._sketchController?.notifyAttributesChanged(t,r)}}})));const s=t=>{e.getPendingEditsForFeature(t.feature)?.setAttachmentEdits(t.attachmentEdits)};this.addHandles(i.on("attachments-change",s))}async _initializeHighlights(e,t,r){const o=await f(r,t);this.addHandles(o.highlight(e),v)}_initializeSketchController(e,t,r){const{data:o}=this,i=new y({defaultUpdateOptions:this.sketchUpdateOptions,sourceLayer:t,view:r,features:e,useLegacyCreateTools:o.viewModel.useLegacyCreateTools,onGeometriesUpdated:e=>{const t=[];for(const{feature:r,geometry:i}of e)o.getPendingEditsForFeature(r)?.updateGeometry(i),t.push(r);this._formViewModel.notifyGeometriesChanged(t)},onVisualVariableAttributesUpdated:()=>{F().warnOnce("editor:batch-update-visual-variables","UpdateFeaturesWorkflow does not currently support modifying visual variables through the scale and rotate tools.")}});this._sketchController=i}_initializeVisuals(e){const{data:t}=this,{view:r}=t.viewModel;if(!r)return;const o=_(t);if(d(o))return;const i=t.getEditorItemForLayer(o);i?.capabilities.update.geometry&&!this.curveUpdatesDisabled&&this._initializeSketchController(e,o,r)}};e([a()],b.prototype,"curveUpdatesDisabled",null),e([a()],b.prototype,"features",null),e([a()],b.prototype,"featureInfos",null),e([a()],b.prototype,"formViewModel",null),e([a()],b.prototype,"hasInvalidFormTemplate",null),e([a()],b.prototype,"hasPendingEdits",null),e([a()],b.prototype,"parent",null),e([a()],b.prototype,"saveActionLabel",null),e([a()],b.prototype,"selectedFeature",null),e([a()],b.prototype,"sketchUpdateOptions",null),e([a()],b.prototype,"sketchViewModel",null),e([a()],b.prototype,"supportsMergeFeaturesWorkflow",null),e([a()],b.prototype,"type",void 0),e([a()],b.prototype,"viewGraphics",null),e([a()],b.prototype,"_formViewModel",void 0),e([a()],b.prototype,"_sketchController",void 0),b=w=e([n("esri.widgets.Editor.UpdateFeaturesWorkflow")],b);const k=b;function M(){return[{id:"editing-features",async setUp(){},async tearDown(){}}]}function E(e){return async t=>{const r=_(t),o=[],i=[];for(const e of t.fullFeatures){const r=t.getPendingEditsForFeature(e),s=r?.stagedForDelete;if(!r?.modified&&!s)continue;const a=e.clone();if(!r?.attributesModified||s){const t=e.sourceLayer;if(!t){F().warn("Feature has no sourceLayer. It will not be included in any applyEdits payload.");continue}const r=t.objectIdField;if(a.attributes={[r]:e.getAttribute(r)},"scene"===t.type&&null!=t.infoFor3D){const r=t.associatedLayer?.globalIdField;null!=r&&a.setAttribute(r,e.getAttribute(r))}}r?.geometryModified&&!s||(a.geometry=null),s?i.push(a):(r?.attributesModified||r?.geometryModified)&&o.push(a)}if(0===o.length&&0===i.length)return void F().warn("No edits to apply. Workflow will finish without sending an applyEdits request.");const s={};o.length&&(s.updateFeatures=o),i.length&&(s.deleteFeatures=i),await e(r,s)}}function _(e){if(e.layers.length>1)throw new g;return e.layers[0]}export{k as default};
2
+ import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import r from"../../core/Error.js";import o from"../../core/Logger.js";import{destroyMaybe as i}from"../../core/maybe.js";import{whenOnce as s}from"../../core/reactiveUtils.js";import{property as a,subclass as n}from"../../core/accessorSupport/decorators.js";import{isSceneLayer as l,isTable as d}from"../../layers/support/layerUtils.js";import u from"../BatchAttributeForm/BatchAttributeFormViewModel.js";import p from"./UpdateFeaturesWorkflowData.js";import c from"./Workflow.js";import{handleFormValuesChangeEvent as h,whenEditorLayerView as f,findEditorItemForLayer as m}from"./workflowUtils.js";import{MultipleSourceLayersError as g}from"./support/errors.js";import{SketchController as y}from"./support/SketchController.js";var w;const F=()=>o.getLogger("esri.widgets.Editor.UpdateFeaturesWorkflow"),v=Symbol();let b=w=class extends c{constructor(e){super(e),this.type="update-features",this._formViewModel=null,this._sketchController=null}async initialize(){this._initializeFormViewModel();try{await this._updatingHandles.addPromise((async()=>{const{fullFeatures:e}=await this.data.when();this._formViewModel.features=new t(e),this._initializeVisuals(e)})())}catch(e){this.cancel({force:!0,error:new r("update-features-workflow:initialize","Failed to initialize the workflow data.",e)})}}destroy(){this._sketchController=i(this._sketchController),this._formViewModel.destroy()}get curveUpdatesDisabled(){return this.data.curveUpdatesDisabled}get features(){return this.data.features}get featureInfos(){return this.data.featureInfos}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return this.data.editorItems.some(e=>e.hasInvalidFormTemplate)}get hasPendingEdits(){const{data:e}=this;return e.fullFeatures.some(t=>!!e.getPendingEditsForFeature(t)?.modified)}get parent(){return this.data.parent}get saveActionLabel(){return"update"}get selectedFeature(){return this.data.selectedFeature}get sketchUpdateOptions(){const{data:e}=this,t=e.fullFeatures,r=_(e),o=e.getEditorItemForLayer(r),i=!this.selectedFeature||t.length>1;return{multipleSelectionEnabled:!1,reshapeOptions:{enableCreateCurveFromStraightEdge:!l(r)&&!!o?.capabilities.supportsTrueCurve},tool:i?"move":void 0}}get sketchViewModel(){return this._sketchController?.viewModel}get supportsMergeFeaturesWorkflow(){const e=this.data,{fullFeatures:t,layers:r}=e;return!(1!==r.length||t.length<2)&&(!this.curveUpdatesDisabled&&!!e.getEditorItemForLayer(r[0])?.supportsMergeFeaturesWorkflow)}getUpdating(){return!!this._sketchController?.updating}get viewGraphics(){return this._sketchController?.sketchGraphics??this.data.fullFeatures}static create(e){const{applyEdits:t,applyEditsFeatureService:r,...o}=e,{features:i,featureInfos:s,viewModel:a}=o,n=new Set;function l(e){const t=m(a.editorItems,e);t&&n.add(t)}s?.length?s.forEach(({layer:e})=>l(e)):i?.length&&(F().warn("editor:update-features-workflow-data-features","UpdateFeaturesWorkflow: 'features' is deprecrated, use 'featureInfos'"),i.forEach(e=>l(e.sourceLayer??e.layer)));const d=Array.from(n),u=new w({data:new p({...o,editorItems:d}),onCommit:E(e.applyEdits)});return u._set("steps",M()),u}async deleteAndCommit(){return this.data.stageDelete(),this.commit()}async enter(){}exit(e){}async reset(){}async save(){const{formViewModel:e}=this;await e.submit(),e.valid&&await super.save()}async start(){await super.start(),await s(()=>!this.updating);const e=this._sketchController;if(e)return e;const{data:t}=this,{view:r}=t.viewModel,o=_(t);return!r||d(o)?{enter:async()=>{},exit:()=>{}}:{enter:()=>this._initializeHighlights(t.fullFeatures,o,r),exit:()=>this.removeHandles(v)}}_initializeFormViewModel(){const{data:e}=this,t=e.viewModel.view,r=e.getEditorItemForLayer(_(e)),o=r?.layerInfo?[r.layerInfo]:null,i=new u({editType:"UPDATE",readOnly:!1===r?.capabilities.update.attributes,spatialReference:t?.spatialReference,view:t,layerInfos:o});this._formViewModel=i,this.addHandles(i.on("values-change",h({forEachFeature:(t,r)=>{const o=e.getPendingEditsForFeature(t);if(o){for(const{fieldName:e,value:t}of r)o.setAttribute(e,t);this._sketchController?.notifyAttributesChanged(t,r)}}})));const s=t=>{e.getPendingEditsForFeature(t.feature)?.setAttachmentEdits(t.attachmentEdits)};this.addHandles(i.on("attachments-change",s))}async _initializeHighlights(e,t,r){const o=await f(r,t);this.addHandles(o.highlight(e),v)}_initializeSketchController(e,t,r){const{data:o}=this,i=new y({defaultUpdateOptions:this.sketchUpdateOptions,sourceLayer:t,view:r,features:e,useLegacyCreateTools:o.viewModel.useLegacyCreateTools,onGeometriesUpdated:e=>{const t=[];for(const{feature:r,geometry:i}of e)o.getPendingEditsForFeature(r)?.updateGeometry(i),t.push(r);this._formViewModel.notifyGeometriesChanged(t)},onVisualVariableAttributesUpdated:()=>{F().warnOnce("editor:batch-update-visual-variables","UpdateFeaturesWorkflow does not currently support modifying visual variables through the scale and rotate tools.")}});this._sketchController=i}_initializeVisuals(e){const{data:t}=this,{view:r}=t.viewModel;if(!r)return;const o=_(t);if(d(o))return;const i=t.getEditorItemForLayer(o);i?.capabilities.update.geometry&&!this.curveUpdatesDisabled&&this._initializeSketchController(e,o,r)}};e([a()],b.prototype,"curveUpdatesDisabled",null),e([a()],b.prototype,"features",null),e([a()],b.prototype,"featureInfos",null),e([a()],b.prototype,"formViewModel",null),e([a()],b.prototype,"hasInvalidFormTemplate",null),e([a()],b.prototype,"hasPendingEdits",null),e([a()],b.prototype,"parent",null),e([a()],b.prototype,"saveActionLabel",null),e([a()],b.prototype,"selectedFeature",null),e([a()],b.prototype,"sketchUpdateOptions",null),e([a()],b.prototype,"sketchViewModel",null),e([a()],b.prototype,"supportsMergeFeaturesWorkflow",null),e([a()],b.prototype,"type",void 0),e([a()],b.prototype,"viewGraphics",null),e([a()],b.prototype,"_formViewModel",void 0),e([a()],b.prototype,"_sketchController",void 0),b=w=e([n("esri.widgets.Editor.UpdateFeaturesWorkflow")],b);const k=b;function M(){return[{id:"editing-features",async setUp(){},async tearDown(){}}]}function E(e){return async t=>{const r=_(t),o=[],i=[];for(const e of t.fullFeatures){const r=t.getPendingEditsForFeature(e),s=r?.stagedForDelete;if(!r?.modified&&!s)continue;const a=e.clone();if(!r?.attributesModified||s){const t=e.sourceLayer;if(!t){F().warn("Feature has no sourceLayer. It will not be included in any applyEdits payload.");continue}const r=t.objectIdField;if(a.attributes={[r]:e.getAttribute(r)},"scene"===t.type&&null!=t.infoFor3D){const r=t.associatedLayer?.globalIdField;null!=r&&a.setAttribute(r,e.getAttribute(r))}}r?.geometryModified&&!s||(a.geometry=null),s?i.push(a):(r?.attributesModified||r?.geometryModified)&&o.push(a)}if(0===o.length&&0===i.length)return void F().warn("No edits to apply. Workflow will finish without sending an applyEdits request.");const s={};o.length&&(s.updateFeatures=o),i.length&&(s.deleteFeatures=i),await e(r,s)}}function _(e){if(e.layers.length>1)throw new g;return e.layers[0]}export{k as default};