@arcgis/core 4.33.0-next.20250206 → 4.33.0-next.20250207

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 (115) hide show
  1. package/arcade.js +1 -1
  2. package/assets/esri/core/workers/RemoteClient.js +1 -1
  3. package/assets/esri/core/workers/chunks/0a8e388e96af44deeabb.js +1 -0
  4. package/assets/esri/core/workers/chunks/{38cd7745b8ef1b8b6196.js → 12d6baeffd55a98a7c75.js} +1 -1
  5. package/assets/esri/core/workers/chunks/143a193fa3a6e645c8ac.js +1 -0
  6. package/assets/esri/core/workers/chunks/308ec51ff4a66f7fcb0d.js.LICENSE.txt +1 -1
  7. package/assets/esri/core/workers/chunks/{72cf9192292e5c85c6df.js → 32d3657dcae89b740f8b.js} +2 -2
  8. package/assets/esri/core/workers/chunks/{72cf9192292e5c85c6df.js.LICENSE.txt → 32d3657dcae89b740f8b.js.LICENSE.txt} +1 -1
  9. package/assets/esri/core/workers/chunks/354531dc2f0dea2ad96f.js.LICENSE.txt +1 -1
  10. package/assets/esri/core/workers/chunks/35e4af82a08b4eadbfab.js +1 -0
  11. package/assets/esri/core/workers/chunks/369a2b8484a8807bde38.js +1 -0
  12. package/assets/esri/core/workers/chunks/4040158835f9036967cd.js +2 -0
  13. package/assets/esri/core/workers/chunks/{1a2e1a414e651e988435.js.LICENSE.txt → 4040158835f9036967cd.js.LICENSE.txt} +1 -6
  14. package/assets/esri/core/workers/chunks/459af0c3d62c3ed11c19.js +1 -0
  15. package/assets/esri/core/workers/chunks/53810519ff5922b42cd2.js +1 -0
  16. package/assets/esri/core/workers/chunks/{15f850c9a1154fc57e5a.js → 5721557a1d8eab23a55b.js} +1 -1
  17. package/assets/esri/core/workers/chunks/594d923400fd74881833.js +1 -0
  18. package/assets/esri/core/workers/chunks/62a1d60ad4bf6469c4dd.js +1 -0
  19. package/assets/esri/core/workers/chunks/{81aa8cc289fd02ca4da6.js → 7058001bf66f9f3d5d45.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{e8ae8a11d8439e2a66ad.js → 706f867a9034d62a8ef7.js} +1 -1
  21. package/assets/esri/core/workers/chunks/77764ca90bdd13ee2167.js.LICENSE.txt +1 -1
  22. package/assets/esri/core/workers/chunks/{1ab83753d9eec0463461.js → 7b367bb0ed9c218ca595.js} +1 -1
  23. package/assets/esri/core/workers/chunks/8191dd3d7451b2e7b95e.js +1 -0
  24. package/assets/esri/core/workers/chunks/8c32cee395da0a7b9a8e.js +1 -0
  25. package/assets/esri/core/workers/chunks/{48ecc5a74fecbb2b9c6f.js → 8d8f5f08d730270e1165.js} +1 -1
  26. package/assets/esri/core/workers/chunks/94225d92afbdb10dfedb.js +1 -0
  27. package/assets/esri/core/workers/chunks/94490937dca566fe2640.js +1 -0
  28. package/assets/esri/core/workers/chunks/{b9ce0049e27a3e1ed9f9.js → 9b2fab133786e5d47631.js} +1 -1
  29. package/assets/esri/core/workers/chunks/{28374a64790342e1b5ae.js → 9d61590c4d21c7421925.js} +1 -1
  30. package/assets/esri/core/workers/chunks/b21b152fa15896577242.js.LICENSE.txt +1 -1
  31. package/assets/esri/core/workers/chunks/{5a25cef6355fd20e44e7.js → b765670b47d209d7655a.js} +2 -2
  32. package/assets/esri/core/workers/chunks/{5a25cef6355fd20e44e7.js.LICENSE.txt → b765670b47d209d7655a.js.LICENSE.txt} +1 -1
  33. package/assets/esri/core/workers/chunks/d29c3bf29fcd7fa31f1a.js +1 -0
  34. package/assets/esri/core/workers/chunks/d339dee99c4820b63f39.js +1 -0
  35. package/assets/esri/core/workers/chunks/de1f3c4b8000c2d73013.js +1 -0
  36. package/assets/esri/core/workers/chunks/e4b3f2d5c43518b0cde7.js +1 -0
  37. package/assets/esri/core/workers/chunks/e5e3b6d00d27b5bb354f.js +1 -0
  38. package/assets/esri/core/workers/chunks/f14b318bab5efcf43419.js +1 -0
  39. package/assets/esri/core/workers/chunks/{24e47f748f0e4f815c6e.js → f32ca4381e804cc3481e.js} +1 -1
  40. package/assets/esri/core/workers/chunks/f9070edd8e0b2a57af79.js +1 -0
  41. package/assets/esri/themes/base/widgets/_ItemList.scss +6 -0
  42. package/assets/esri/themes/dark/main.css +1 -1
  43. package/assets/esri/themes/light/main.css +1 -1
  44. package/assets/esri/themes/light/view.css +1 -1
  45. package/interfaces.d.ts +58 -56
  46. package/layers/FeatureLayer.js +1 -1
  47. package/layers/SubtypeGroupLayer.js +1 -1
  48. package/layers/WCSLayer.js +1 -1
  49. package/layers/graphics/data/QueryEngineCapabilities.js +1 -1
  50. package/layers/graphics/sources/FeatureLayerSource.js +1 -1
  51. package/layers/graphics/sources/geojson/GeoJSONSourceWorker.js +1 -1
  52. package/layers/graphics/sources/support/MemorySourceWorker.js +1 -1
  53. package/layers/graphics/sources/support/clientSideDefaults.js +1 -1
  54. package/layers/graphics/sources/support/sourceUtils.js +1 -1
  55. package/layers/mixins/BlendLayer.js +1 -1
  56. package/layers/mixins/FeatureLayerBase.js +1 -1
  57. package/layers/mixins/OperationalLayer.js +1 -1
  58. package/layers/mixins/operationalLayerModuleMap.js +1 -1
  59. package/layers/support/SubtypeSublayer.js +1 -1
  60. package/layers/support/arcadeUtils.js +1 -1
  61. package/layers/support/commonProperties.js +1 -1
  62. package/layers/support/layersCreator.js +1 -1
  63. package/package.json +2 -2
  64. package/portal/support/layersLoader.js +1 -1
  65. package/portal/support/loadUtils.js +1 -1
  66. package/rest/imageService.js +1 -1
  67. package/rest/support/ImageSampleParameters.js +1 -1
  68. package/rest/support/ImageSampleResult.js +1 -1
  69. package/rest/support/ImageVolumeResult.js +1 -1
  70. package/support/TablesMixin.js +1 -1
  71. package/support/revision.js +1 -1
  72. package/symbols/cim/cimAnalyzer.js +1 -1
  73. package/symbols/cim/fitVectorMarker.js +5 -0
  74. package/symbols/support/previewCIMSymbol.js +1 -1
  75. package/views/2d/engine/webgl/TextureManager.js +1 -1
  76. package/views/2d/layers/features/schema/SourceSchema.js +1 -1
  77. package/views/2d/layers/features/sources/FeatureSource.js +1 -1
  78. package/views/2d/layers/features/sources/FeatureSourceQueryInfo.js +1 -1
  79. package/views/2d/layers/features/sources/strategies/DrillDownTileLoadStrategy.js +1 -1
  80. package/views/2d/layers/features/sources/strategies/PagedTileLoadStrategy.js +1 -1
  81. package/views/2d/layers/features/sources/strategies/ParquetLoadStrategy.js +1 -1
  82. package/views/2d/layers/features/sources/strategies/SnapshotLoadStrategy.js +1 -1
  83. package/views/2d/layers/features/sources/strategies/StreamLoadStrategy.js +1 -1
  84. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  85. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  86. package/widgets/Editor/EditorViewModel.js +1 -1
  87. package/widgets/Editor/UpdateWorkflow.js +1 -1
  88. package/widgets/Editor/VisibleElements.js +1 -1
  89. package/widgets/Editor/components/FeatureList.js +1 -1
  90. package/widgets/Editor/components/UpdateFeaturePanelContent.js +1 -1
  91. package/widgets/Editor/workflowUtils.js +1 -1
  92. package/widgets/Editor.js +1 -1
  93. package/widgets/Feature/support/arcadeFeatureUtils.js +1 -1
  94. package/widgets/Sketch.js +1 -1
  95. package/widgets/support/UtilityNetworkAssociations/UtilityNetworkAssociationsViewModel.js +1 -1
  96. package/assets/esri/core/workers/chunks/07bff9e742f3e5877f3f.js +0 -1
  97. package/assets/esri/core/workers/chunks/1a2e1a414e651e988435.js +0 -2
  98. package/assets/esri/core/workers/chunks/287362f9af132fafe4de.js +0 -1
  99. package/assets/esri/core/workers/chunks/2adc533dadcb018a9755.js +0 -1
  100. package/assets/esri/core/workers/chunks/2ea5e5e6c4660a06b516.js +0 -1
  101. package/assets/esri/core/workers/chunks/3984bf01f055fc42bfbf.js +0 -1
  102. package/assets/esri/core/workers/chunks/41cd1a5c99ab3bbd1fb4.js +0 -1
  103. package/assets/esri/core/workers/chunks/5e7f16b312077ca8c18d.js +0 -1
  104. package/assets/esri/core/workers/chunks/6ef2514a6b7bbfb8e37d.js +0 -1
  105. package/assets/esri/core/workers/chunks/82d26884127ed772cc4b.js +0 -1
  106. package/assets/esri/core/workers/chunks/918bdba41fa470cf77fd.js +0 -1
  107. package/assets/esri/core/workers/chunks/91d2bdfa6e34c10b7f50.js +0 -1
  108. package/assets/esri/core/workers/chunks/991e0f619f1f81f94d56.js +0 -1
  109. package/assets/esri/core/workers/chunks/9a27824d94df702e6e28.js +0 -1
  110. package/assets/esri/core/workers/chunks/c1fd87af3129873369fd.js +0 -1
  111. package/assets/esri/core/workers/chunks/c4c2b94e5cee7b824093.js +0 -1
  112. package/assets/esri/core/workers/chunks/c85374360ac5e169af16.js +0 -1
  113. package/assets/esri/core/workers/chunks/c94ec324ecad77c53a87.js +0 -1
  114. package/assets/esri/core/workers/chunks/d175953337fa655dc6b0.js +0 -1
  115. package/assets/esri/core/workers/chunks/e26dc0c1654316bb1558.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{handlesGroup as t}from"../../../../../../core/handleUtils.js";import{isAborted as e,throwIfAborted as s,onAbort as o}from"../../../../../../core/promiseUtils.js";import{ATileLoadStrategy as r}from"./ATileLoadStrategy.js";import{PagedTileSourceChunk as a}from"./chunks/PagedTileSourceChunk.js";import{FeatureSetReaderJSON as i}from"../../support/FeatureSetReaderJSON.js";class n{constructor(e,s){this.subscription=e,this._pages=new Set,this._controller=new AbortController,this._done=!1,this._handles=t([o(e.signal,(()=>this._controller.abort())),o(s,(()=>this._controller.abort()))])}destroy(){this._controller.abort(),this._handles.remove()}get pageStart(){let t=-1;for(const e of this._pages.values())t=Math.max(t,e);return t+1}get done(){return this._done}get options(){return{signal:this._controller.signal}}add(t,e){this._pages.add(t),this._done=this._done||e}}class l extends r{constructor(){super(...arguments),this._loadStates=new Map}destroy(){super.destroy();for(const t of this._loadStates.values())t.destroy();this._loadStates.clear()}get about(){return{willQueryAllFeatures:!1,willQueryFullResolutionGeometry:!1}}async load(t){this._loadStates.has(t.key.id)||this._loadStates.set(t.key.id,new n(t,this._options));const s=this._loadStates.get(t.key.id);let o;try{await this._fetchPages(s)}catch(l){o=l}const r=new a(i.empty(this._metadata),null,t.tile,-1,!0);if(e(s.options)||this._addChunk(r),o)throw o}unload(t){super.unload(t),this._loadStates.get(t.key.id)?.destroy(),this._loadStates.delete(t.key.id)}async _fetchPages(t){const e=4,o=20;let r=0,a=t.pageStart,i=1;for(;r<o&&!t.done;){const o=[];for(let e=0;e<i;e++)o.push(this._fetchChunk(t,a++));const n=await Promise.all(o);for(const e of n)(0!==e.size()||e.first)&&(t.add(e.page,!e.reader.exceededTransferLimit),s(t.options),this._addChunk(e));r++,i=Math.min(i+1,e)}}async _fetchChunk(t,e){const s=t.subscription.tile,o=this._queryInfo.createPagedTileQuery(s,e),r=await this._fetch(o,t.options,{chunkId:`${s.id}-${e}`});return new a(r,o.inner.toJSON(),s,e,!1)}}export{l as PagedTileLoadStrategy};
5
+ import{handlesGroup as t}from"../../../../../../core/handleUtils.js";import{isAborted as e,throwIfAborted as s,onAbort as o}from"../../../../../../core/promiseUtils.js";import{ATileLoadStrategy as r}from"./ATileLoadStrategy.js";import{PagedTileSourceChunk as a}from"./chunks/PagedTileSourceChunk.js";import{FeatureSetReaderJSON as i}from"../../support/FeatureSetReaderJSON.js";class n{constructor(e,s){this.subscription=e,this._pages=new Set,this._controller=new AbortController,this._done=!1,this._handles=t([o(e.signal,(()=>this._controller.abort())),o(s,(()=>this._controller.abort()))])}destroy(){this._controller.abort(),this._handles.remove()}get pageStart(){let t=-1;for(const e of this._pages.values())t=Math.max(t,e);return t+1}get done(){return this._done}get options(){return{signal:this._controller.signal}}add(t,e){this._pages.add(t),this._done=this._done||e}}class l extends r{constructor(){super(...arguments),this._loadStates=new Map}destroy(){super.destroy();for(const t of this._loadStates.values())t.destroy();this._loadStates.clear()}get about(){return{supportsDisplayFilter:!0,willQueryAllFeatures:!1,willQueryFullResolutionGeometry:!1}}async load(t){this._loadStates.has(t.key.id)||this._loadStates.set(t.key.id,new n(t,this._options));const s=this._loadStates.get(t.key.id);let o;try{await this._fetchPages(s)}catch(l){o=l}const r=new a(i.empty(this._metadata),null,t.tile,-1,!0);if(e(s.options)||this._addChunk(r),o)throw o}unload(t){super.unload(t),this._loadStates.get(t.key.id)?.destroy(),this._loadStates.delete(t.key.id)}async _fetchPages(t){const e=4,o=20;let r=0,a=t.pageStart,i=1;for(;r<o&&!t.done;){const o=[];for(let e=0;e<i;e++)o.push(this._fetchChunk(t,a++));const n=await Promise.all(o);for(const e of n)(0!==e.size()||e.first)&&(t.add(e.page,!e.reader.exceededTransferLimit),s(t.options),this._addChunk(e));r++,i=Math.min(i+1,e)}}async _fetchChunk(t,e){const s=t.subscription.tile,o=this._queryInfo.createPagedTileQuery(s,e),r=await this._fetch(o,t.options,{chunkId:`${s.id}-${e}`});return new a(r,o.inner.toJSON(),s,e,!1)}}export{l as PagedTileLoadStrategy};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{throwIfAborted as e}from"../../../../../../core/promiseUtils.js";import{difference as t,union as s}from"../../../../../../core/SetUtils.js";import i from"../../../../../../layers/support/FieldsIndex.js";import{ParquetFile as a}from"../../../../../../libs/parquet/parquet.js";import{ALoadStrategy as r}from"./ALoadStrategy.js";import{FeatureSnapshotSourceChunk as l}from"./chunks/FeatureSnapshotSourceChunk.js";import{FeatureSetReaderJSON as o}from"../../support/FeatureSetReaderJSON.js";import{FeatureSetReaderParquet as n}from"../../support/FeatureSetReaderParquet.js";class m extends r{constructor(e,t,s,i){super(i),this._service=e,this._metadata=t,this._schema=s,this._chunkId=0,this._files=[],this._availableFields=new Set(s.mutable.availableFields);const{geometryInfo:a}=this._service;if("location"===a.type)this._availableFields.add(a.latitudeFieldName),this._availableFields.add(a.longitudeFieldName);else if(null!=a.multiscale&&a.multiscale.levels.length>=1){const e=a.multiscale.levels[0];this._availableFields.add(e.column)}else this._availableFields.add(a.primaryFieldName)}destroy(){for(const e of this._files)e.destroy()}get about(){return{willQueryAllFeatures:!0,willQueryFullResolutionGeometry:!0}}async updateFields(e){await this._promise;const i=new Set(e),a=t(i,this._availableFields);this._availableFields=s(a,this._availableFields),a.size&&await Promise.all(this._files.map((e=>{const t=Array.from(a).map((t=>e.metadata.getFieldIndex(t)));return e.inner.updateChunks(new Uint16Array(t))})))}async load(e){return null==this._promise&&(this._promise=this._download().then((()=>{this._loadHigherResGeometry()}))),this._promise}unload(e){}async addParquetFile(e){this._insert(e)}async _loadHigherResGeometry(){const{geometryInfo:e}=this._service;if("geometry"===e.type){if(!(null!=e.multiscale&&e.multiscale.levels.length>=1))return;await this.updateFields([e.primaryFieldName])}const t=Array.from(this._store.chunks());this._store.clear();for(const s of t)this._store.insert(s);this._store.refresh()}async _insert(t){const s=await a.create(t,{geometryInfo:this._service.geometryInfo,outSpatialReference:this._service.outSpatialReference,getCustomParameters:()=>this._schema.mutable.dataFilter.customParameters}),{geometryInfo:r}=this._service;e(this._options);const{fields:o,timeZoneByFieldName:m}=this._service.metadata.fieldsIndex,d=o.map((e=>({...e,index:s.metadata.getFieldIndex(e.name)}))),h=i.fromJSON({fields:d,timeZoneByFieldName:m}),u=new Uint16Array(Array.from(this._availableFields.values()).map((e=>h.get(e)?.index)).filter((e=>null!=e)));await s.inner.readChunksWithCallback(u,(e=>{const t=this._chunkId++,s=new n(this._metadata,h,r,e,t),i=new l(s,null,t,!1);this._store.insert(i)})),this._files.push(s)}async _download(){try{await Promise.all(this._service.source.urls.map((e=>this._insert(e))));const e=new l(o.empty(this._metadata),null,-1,!0);this._store.insert(e)}catch(e){throw console.error(e),e}}}export{m as ParquetLoadStrategy};
5
+ import{throwIfAborted as e}from"../../../../../../core/promiseUtils.js";import{difference as t,union as s}from"../../../../../../core/SetUtils.js";import i from"../../../../../../layers/support/FieldsIndex.js";import{ParquetFile as a}from"../../../../../../libs/parquet/parquet.js";import{ALoadStrategy as r}from"./ALoadStrategy.js";import{FeatureSnapshotSourceChunk as l}from"./chunks/FeatureSnapshotSourceChunk.js";import{FeatureSetReaderJSON as o}from"../../support/FeatureSetReaderJSON.js";import{FeatureSetReaderParquet as n}from"../../support/FeatureSetReaderParquet.js";class m extends r{constructor(e,t,s,i){super(i),this._service=e,this._metadata=t,this._schema=s,this._chunkId=0,this._files=[],this._availableFields=new Set(s.mutable.availableFields);const{geometryInfo:a}=this._service;if("location"===a.type)this._availableFields.add(a.latitudeFieldName),this._availableFields.add(a.longitudeFieldName);else if(null!=a.multiscale&&a.multiscale.levels.length>=1){const e=a.multiscale.levels[0];this._availableFields.add(e.column)}else this._availableFields.add(a.primaryFieldName)}destroy(){for(const e of this._files)e.destroy()}get about(){return{supportsDisplayFilter:!1,willQueryAllFeatures:!0,willQueryFullResolutionGeometry:!0}}async updateFields(e){await this._promise;const i=new Set(e),a=t(i,this._availableFields);this._availableFields=s(a,this._availableFields),a.size&&await Promise.all(this._files.map((e=>{const t=Array.from(a).map((t=>e.metadata.getFieldIndex(t)));return e.inner.updateChunks(new Uint16Array(t))})))}async load(e){return null==this._promise&&(this._promise=this._download().then((()=>{this._loadHigherResGeometry()}))),this._promise}unload(e){}async addParquetFile(e){this._insert(e)}async _loadHigherResGeometry(){const{geometryInfo:e}=this._service;if("geometry"===e.type){if(!(null!=e.multiscale&&e.multiscale.levels.length>=1))return;await this.updateFields([e.primaryFieldName])}const t=Array.from(this._store.chunks());this._store.clear();for(const s of t)this._store.insert(s);this._store.refresh()}async _insert(t){const s=await a.create(t,{geometryInfo:this._service.geometryInfo,outSpatialReference:this._service.outSpatialReference,getCustomParameters:()=>this._schema.mutable.dataFilter.customParameters}),{geometryInfo:r}=this._service;e(this._options);const{fields:o,timeZoneByFieldName:m}=this._service.metadata.fieldsIndex,d=o.map((e=>({...e,index:s.metadata.getFieldIndex(e.name)}))),h=i.fromJSON({fields:d,timeZoneByFieldName:m}),u=new Uint16Array(Array.from(this._availableFields.values()).map((e=>h.get(e)?.index)).filter((e=>null!=e)));await s.inner.readChunksWithCallback(u,(e=>{const t=this._chunkId++,s=new n(this._metadata,h,r,e,t),i=new l(s,null,t,!1);this._store.insert(i)})),this._files.push(s)}async _download(){try{await Promise.all(this._service.source.urls.map((e=>this._insert(e))));const e=new l(o.empty(this._metadata),null,-1,!0);this._store.insert(e)}catch(e){throw console.error(e),e}}}export{m as ParquetLoadStrategy};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import t from"../../../../../../core/Error.js";import{throwIfAborted as e}from"../../../../../../core/promiseUtils.js";import r from"../../../../../../core/RandomLCG.js";import{AFetchLoadStrategy as o}from"./AFetchLoadStrategy.js";import{FeatureSnapshotSourceChunk as s}from"./chunks/FeatureSnapshotSourceChunk.js";import{FeatureSetReaderJSON as n}from"../../support/FeatureSetReaderJSON.js";class a extends o{constructor(t,e,o,s,n,a){super(t,e,o,n,a),this._random=new r(1e3),this._featureCount=s}get about(){return{willQueryAllFeatures:!0,willQueryFullResolutionGeometry:!0}}load(t){return null==this._promise&&(this._promise=this._downloadPages(this._featureCount)),this._promise}unload(t){}async _downloadPages(e){const r=Math.ceil(e/this._queryInfo.pageSize),o=Array.from({length:r},((t,e)=>e)).sort(((t,e)=>this._random.getInt()-this._random.getInt())),a=await Promise.all(o.map((t=>this._downloadPage(t)))),i=new s(n.empty(this._metadata),null,-1,!0);this._store.insert(i);const u=a.filter((t=>t));if(u.length)throw new t("featurelayer-query","Encountered errors when downloading data",{errors:u})}async _downloadPage(t){try{const r=this._queryInfo.createPagedQuery(t),o=await this._fetch(r,this._options,{chunkId:t.toString()}),n=new s(o,r.inner.toJSON(),t,!1);return e(this._options),this._store.insert(n),null}catch(r){return r}}}export{a as SnapshotLoadStrategy};
5
+ import t from"../../../../../../core/Error.js";import{throwIfAborted as e}from"../../../../../../core/promiseUtils.js";import r from"../../../../../../core/RandomLCG.js";import{AFetchLoadStrategy as o}from"./AFetchLoadStrategy.js";import{FeatureSnapshotSourceChunk as s}from"./chunks/FeatureSnapshotSourceChunk.js";import{FeatureSetReaderJSON as n}from"../../support/FeatureSetReaderJSON.js";class a extends o{constructor(t,e,o,s,n,a){super(t,e,o,n,a),this._random=new r(1e3),this._featureCount=s}get about(){return{supportsDisplayFilter:!1,willQueryAllFeatures:!0,willQueryFullResolutionGeometry:!0}}load(t){return null==this._promise&&(this._promise=this._downloadPages(this._featureCount)),this._promise}unload(t){}async _downloadPages(e){const r=Math.ceil(e/this._queryInfo.pageSize),o=Array.from({length:r},((t,e)=>e)).sort(((t,e)=>this._random.getInt()-this._random.getInt())),a=await Promise.all(o.map((t=>this._downloadPage(t)))),i=new s(n.empty(this._metadata),null,-1,!0);this._store.insert(i);const u=a.filter((t=>t));if(u.length)throw new t("featurelayer-query","Encountered errors when downloading data",{errors:u})}async _downloadPage(t){try{const r=this._queryInfo.createPagedQuery(t),o=await this._fetch(r,this._options,{chunkId:t.toString()}),n=new s(o,r.inner.toJSON(),t,!1);return e(this._options),this._store.insert(n),null}catch(r){return r}}}export{a as SnapshotLoadStrategy};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../../../../core/Evented.js";import{handlesGroup as t}from"../../../../../../core/handleUtils.js";import"../../../../../../core/has.js";import{destroyMaybe as s}from"../../../../../../core/maybe.js";import{StreamFeatureManager as n}from"../../../../../../layers/graphics/data/StreamFeatureManager.js";import{createConnection as o}from"../../../../../../layers/graphics/sources/connections/createConnection.js";import{internalTimeReceivedField as i}from"../../../../../../layers/support/streamLayerUtils.js";import{StreamConnectionState as r}from"../StreamConnectionState.js";import{StreamFeatureStore as a}from"../StreamFeatureStore.js";import{ALoadStrategy as c}from"./ALoadStrategy.js";import{StreamSourceChunk as h}from"./chunks/StreamSourceChunk.js";class m extends c{constructor(t,s,o,c,h){super(o),this._service=t,this._dataFilter=s,this._streamOptions=c,this._metadata=h,this._connectionState=new r,this._forceRefresh=!1,this.events=new e;const{objectIdField:m,timeInfo:d}=this._metadata,{purgeOptions:_}=s;this._stagingStore=new a(this._metadata.weakCloneWithAdditionalFields([{name:i,alias:"timeReceived",type:"esriFieldTypeDate"}]),(e=>this.events.emit("features-updated",e))),this._manager=new n(this._stagingStore,m,d,_),this.connect()}destroy(){super.destroy(),this.disconnect()}get about(){return{willQueryAllFeatures:!1,willQueryFullResolutionGeometry:!1}}get connectionStatus(){return this._connectionState.connectionStatus}get errorString(){return this._connectionState?.errorString}async refresh(){const e=null!=this._chunk;this._manager.checkForUpdates()||!e||this._forceRefresh?(this._chunk&&this._store.remove(this._chunk),this._forceRefresh=!1,this._chunk=new h(this._stagingStore.reader),this._store.insert(this._chunk),this.events.emit("tick")):this.events.emit("tick")}async updateFields(e){throw new Error("Updating available fields not supported for StreamLayer")}async load(e){}unload(e){}disconnect(){this._connection=s(this._connection),this._connectionState.connection=null,this._handlesGroup?.remove()}connect(){if(null!=this._connection)return;const{geometryType:e,spatialReference:s}=this._metadata,{maxReconnectionAttempts:n,maxReconnectionInterval:i,geometryDefinition:r,definitionExpression:a,customParameters:c}=this._dataFilter;this._connection=o(this._service.source,s,this._streamOptions.outSR,e,a,r,n,i,c),this._handlesGroup=t([this._connection.on("data-received",(e=>this._onFeature(e))),this._connection.on("message-received",(e=>this._onWebSocketMessage(e)))]),this._connectionState.connection=this._connection}clear(){this._manager.checkForUpdates(),this._stagingStore.clear(),this._forceRefresh=!0}updateCustomParameters(e){this._connection?.updateCustomParameters(e)}sendMessageToSocket(e){this._connection?.sendMessageToSocket(e)}sendMessageToClient(e){this._connection?.sendMessageToClient(e)}_onWebSocketMessage(e){if("type"in e)switch(e.type){case"delete":if(e.objectIds)for(const t of e.objectIds)this._manager.removeById(t);if(e.trackIds)for(const t of e.trackIds)this._manager.removeByTrackId(t);break;case"clear":this.clear()}this.events.emit("message-received",e)}_onFeature(e){try{this._manager.add(e),this.events.emit("data-received",e)}catch(t){}}}export{m as StreamLoadStrategy};
5
+ import e from"../../../../../../core/Evented.js";import{handlesGroup as t}from"../../../../../../core/handleUtils.js";import"../../../../../../core/has.js";import{destroyMaybe as s}from"../../../../../../core/maybe.js";import{StreamFeatureManager as n}from"../../../../../../layers/graphics/data/StreamFeatureManager.js";import{createConnection as i}from"../../../../../../layers/graphics/sources/connections/createConnection.js";import{internalTimeReceivedField as o}from"../../../../../../layers/support/streamLayerUtils.js";import{StreamConnectionState as r}from"../StreamConnectionState.js";import{StreamFeatureStore as a}from"../StreamFeatureStore.js";import{ALoadStrategy as c}from"./ALoadStrategy.js";import{StreamSourceChunk as h}from"./chunks/StreamSourceChunk.js";class m extends c{constructor(t,s,i,c,h){super(i),this._service=t,this._dataFilter=s,this._streamOptions=c,this._metadata=h,this._connectionState=new r,this._forceRefresh=!1,this.events=new e;const{objectIdField:m,timeInfo:d}=this._metadata,{purgeOptions:_}=s;this._stagingStore=new a(this._metadata.weakCloneWithAdditionalFields([{name:o,alias:"timeReceived",type:"esriFieldTypeDate"}]),(e=>this.events.emit("features-updated",e))),this._manager=new n(this._stagingStore,m,d,_),this.connect()}destroy(){super.destroy(),this.disconnect()}get about(){return{supportsDisplayFilter:!1,willQueryAllFeatures:!1,willQueryFullResolutionGeometry:!1}}get connectionStatus(){return this._connectionState.connectionStatus}get errorString(){return this._connectionState?.errorString}async refresh(){const e=null!=this._chunk;this._manager.checkForUpdates()||!e||this._forceRefresh?(this._chunk&&this._store.remove(this._chunk),this._forceRefresh=!1,this._chunk=new h(this._stagingStore.reader),this._store.insert(this._chunk),this.events.emit("tick")):this.events.emit("tick")}async updateFields(e){throw new Error("Updating available fields not supported for StreamLayer")}async load(e){}unload(e){}disconnect(){this._connection=s(this._connection),this._connectionState.connection=null,this._handlesGroup?.remove()}connect(){if(null!=this._connection)return;const{geometryType:e,spatialReference:s}=this._metadata,{maxReconnectionAttempts:n,maxReconnectionInterval:o,geometryDefinition:r,definitionExpression:a,customParameters:c}=this._dataFilter;this._connection=i(this._service.source,s,this._streamOptions.outSR,e,a,r,n,o,c),this._handlesGroup=t([this._connection.on("data-received",(e=>this._onFeature(e))),this._connection.on("message-received",(e=>this._onWebSocketMessage(e)))]),this._connectionState.connection=this._connection}clear(){this._manager.checkForUpdates(),this._stagingStore.clear(),this._forceRefresh=!0}updateCustomParameters(e){this._connection?.updateCustomParameters(e)}sendMessageToSocket(e){this._connection?.sendMessageToSocket(e)}sendMessageToClient(e){this._connection?.sendMessageToClient(e)}_onWebSocketMessage(e){if("type"in e)switch(e.type){case"delete":if(e.objectIds)for(const t of e.objectIds)this._manager.removeById(t);if(e.trackIds)for(const t of e.trackIds)this._manager.removeByTrackId(t);break;case"clear":this.clear()}this.events.emit("message-received",e)}_onFeature(e){try{this._manager.add(e),this.events.emit("data-received",e)}catch(t){}}}export{m as StreamLoadStrategy};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import r from"../../../../core/Evented.js";import{unpackFloatRGBA as s}from"../../../../core/floatRGBA.js";import has from"../../../../core/has.js";import i from"../../../../core/Logger.js";import{removeMaybe as n,destroyMaybe as o}from"../../../../core/maybe.js";import{watch as a,initial as h,syncAndInitial as d}from"../../../../core/reactiveUtils.js";import{addFrameTask as p}from"../../../../core/scheduling.js";import{Milliseconds as c}from"../../../../core/time.js";import{property as l}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/RandomLCG.js";import{subclass as m}from"../../../../core/accessorSupport/decorators/subclass.js";import{isMoon as u,isMars as _}from"../../../../geometry/support/spatialReferenceUtils.js";import{ViewingMode as f}from"../../../ViewingMode.js";import{ChapmanAtmosphere as g}from"../../environment/ChapmanAtmosphere.js";import{CloudsComposition as v}from"../../environment/CloudsComposition.js";import{Fog as w}from"../../environment/Fog.js";import{LocalAtmosphere as x}from"../../environment/LocalAtmosphere.js";import y from"../../environment/MarsAtmosphere.js";import{ComponentObjectCollection as j}from"../collections/Component/ComponentObjectCollection.js";import{ShaderTechniqueConstructionContext as R}from"../core/shaderTechnique/ShaderTechniqueConstructionContext.js";import{ShaderTechniqueRepository as b}from"../core/shaderTechnique/ShaderTechniqueRepository.js";import{ObjectAndLayerIDRenderNode as A}from"../effects/geometry/ObjectAndLayerIDRenderNode.js";import{olidEnabled as T}from"../effects/geometry/olidUtils.js";import{RenderOccludedRenderNode as C}from"../effects/geometry/RenderOccludedRenderNode.js";import{Haze as S}from"../effects/haze/Haze.js";import{Highlight as O}from"../effects/highlight/Highlight.js";import{ShadowHighlight as U}from"../effects/highlight/ShadowHighlight.js";import{Magnifier as q}from"../effects/magnifier/Magnifier.js";import{SMAA as D}from"../effects/smaa/SMAA.js";import{SSAO as L}from"../effects/ssao/SSAO.js";import{Stars as M}from"../effects/stars/Stars.js";import{RenderRequestType as k}from"../lib/basicInterfaces.js";import E from"../lib/CompositingHelper.js";import{GLMaterialRepository as F}from"../lib/GLMaterialRepository.js";import{ObjectAndLayerIdRenderHelper as H}from"../lib/ObjectAndLayerIdRenderHelper.js";import{Renderer as W}from"../lib/Renderer.js";import{RenderingContext as B}from"../lib/RenderingContext.js";import{TextureRepository as G}from"../lib/TextureRepository.js";import{createMarkerTextureRepository as N}from"../materials/markerTextureRepository.js";import{createStippleTextureRepository as I}from"../materials/stippleTextureRepository.js";import{WaterTextureRepository as P}from"../materials/internal/WaterTextureRepository.js";import{getContextCache as z}from"./contextCache.js";import{removeLoadedShaderModules as K}from"./renderUtils.js";import{ScreenshotManager as V,ScreenshotContext as Q}from"./ScreenshotManager.js";import{contextCache as X}from"./testUtils.js";import{RenderState as J}from"../../../support/RenderState.js";let Y=class extends t{constructor(e){super(e),this.events=new r,this.waterTextures=new P,this.olidRenderHelper=T()?new H:null,this._needsUpdate=!0,this._needsRender=!0,this._idleSuspend=!0,this._needsWaterReflectionUpdate=!1,this._lastAnimationUpdate=0,this._savedFadeDuration=c(0);const t=e.stage;try{this._initializeContext(t)}catch(n){return void console.error("Failed to initialize context",n)}const{memoryController:s}=t.view.resourceController;this.stippleTextures=I(this._rctx,s),this.markerTextures=N(this._rctx,s),this._techniques=new b(new R(this._rctx,t.viewingMode,this.stippleTextures,this.waterTextures,this.markerTextures)),this._textures=new G(t,this._techniques,this._rctx),this.addHandles(this._textures.events.on("changed",(e=>this.requestRender(e)))),this._materials=new F(this._textures,this._techniques,(()=>this.requestRender()),(()=>this.requestRender())),this._compositingHelper=new E(this._rctx,this._techniques),this.renderer=new W(t,this._materials,this._techniques,this._rctx,this._compositingHelper,(e=>this.requestRender(e))),this.addHandles([a((()=>t.view.ready),(e=>{e&&this._createRenderNodes()}),h),a((()=>this.waterTextures?.updating),(()=>this.requestRender()),h),a((()=>t.view.qualityProfile),(e=>this.renderer?.updateRenderFeatures(e)),d)]);const i={renderScene:(e,t,r,s)=>this.renderer.render(e,t,r,s),requestRenderScene:e=>this.requestRender(e),prepareOverlay:()=>t.options.screenshot.prepareOverlay(),renderOverlay:(e,r,s)=>t.options.screenshot.renderOverlay(e,r,s)};this._screenshotManager=new V(this._rctx,i,(e=>this.events.emit("force-camera-for-screenshot",e))),this._registerFrameTask(t)}destroy(){this._container.contains(this._canvas)&&this._container.removeChild(this._canvas),this._frameTask=n(this._frameTask),this._techniques=o(this._techniques),this._componentObjects=o(this._componentObjects),this._screenshotManager=o(this._screenshotManager),o(this.renderer),this._textures=o(this._textures),o(this.waterTextures),o(this.markerTextures),o(this.stippleTextures),this._canvas=null,this._rctx=o(this._rctx)}_createRenderNodes(){const{view:e,viewingMode:t}=this.stage;new M({view:e}),u(e.spatialReference)||(t===f.Local?new x({view:e}):_(e.spatialReference)?new y({view:e}):(new g({view:e}),new v({view:e}),new S({view:e}),new w({view:e}))),new L({view:e,isEnabled:()=>this.renderer.hasSSAO}),new D({view:e,isEnabled:()=>this.renderer.hasSMAA}),new q({view:e}),new O({view:e}),new U({view:e,viewingMode:t}),new C({view:e}),T()&&new A({view:e})}requestRender(e=k.UPDATE){this._needsRender=!0,e===k.UPDATE&&(this._needsUpdate=!0)}get updating(){return this._needsUpdate||this._needsWaterReflectionUpdate||this.renderer.updating||this._textures.updating||this.waterTextures.updating}get textures(){return this._textures}get techniques(){return this._techniques}get compositingHelper(){return this._compositingHelper}setIdleSuspend(e){this._idleSuspend!==e&&(this._idleSuspend=e,this.requestRender())}get renderingContext(){return this._rctx}get capabilities(){return this._rctx.capabilities}get canvas(){return this._canvas}takeScreenshot(e){return this._screenshotManager.takeScreenshot(e).then((e=>e[0]))}takeScreenshotWithOID(e){return e.objectAndLayerIdColor=!0,this._screenshotManager.takeScreenshot(e)}getAlpha(){return!!this._rctx.contextAttributes.alpha}getMinimalDepthForArea(e,t,r,i,n,o=n){const a=i.constrainWindowSize(t,r,n*i.pixelRatio,o*i.pixelRatio),h=this._ensureLinearDepthArrayBuffer(a);this.renderer.readMainDepth(a,h);const d=(e,t,r)=>s(t,e)*(r[1]-r[0])+r[0];let p=Number.MAX_VALUE;for(let s=0;s<a[2]*a[3];s++){const e=d(4*s,h,i.nearFar);p>e&&e!==i.nearFar[0]&&e!==i.nearFar[1]&&(p=e)}if(e){const s=e.pickDepth(t*i.pixelRatio,r*i.pixelRatio,i);null!=s&&p>s&&s!==i.nearFar[0]&&s!==i.nearFar[1]&&(p=s)}return p===Number.MAX_VALUE?void 0:p}_ensureLinearDepthArrayBuffer(e){const t=4*e[2]*e[3];return(null==this._tmpDepthBuffer||this._tmpDepthBuffer.byteLength<t)&&(this._tmpDepthBuffer=new Uint8Array(t)),this._tmpDepthBuffer}async reloadShaders(){K(),await this._techniques.reloadAll(),this.renderer.overlay?.reloadShaders(),this.requestRender()}_registerFrameTask(e){const t=e.view.state;let r=!1,s=k.BACKGROUND,i=!1;const n={preRender:({time:i})=>{r=this.updating,s=this._needsUpdate?k.UPDATE:k.BACKGROUND,e.commitSyncLayers(),i=this._testTime??i;(c(i-this._lastAnimationUpdate)>this.renderer.animationTimestep||null!=t.forcedAnimationTime||r||this._needsRender)&&(this.renderer.updateAnimation(t,i)&&this.requestRender(k.BACKGROUND),this._lastAnimationUpdate=i)},render:({time:e})=>{if((this._needsRender||!this._idleSuspend||!this.renderer.isCameraFinal||this._needsWaterReflectionUpdate)&&t.camera.fullWidth>0&&t.camera.fullHeight>0){const r=this._needsUpdate&&this._idleSuspend&&this.renderer.isCameraFinal;this._needsRender=!1,this._needsUpdate=!1,this._needsWaterReflectionUpdate=!1,e=this._testTime??e,this.renderer.render(t,e),i=!0,r&&this.renderer.hasReflections&&(this.requestRender(k.BACKGROUND),this._needsWaterReflectionUpdate=!0)}},update:({time:e})=>{this._textures.update();const r=new Q(t,this.renderer.fboCache);e=this._testTime??e,this._screenshotManager.update(r,e)},finish:()=>{i&&(this.renderer.finish(t.mode===J.IDLE?s:k.UPDATE),i=!1)}};this._frameTask=p(n)}_initializeContext(e){const t=e.options;this._canvas=t.canvas??document.createElement("canvas"),this._canvas.setAttribute("style","width: 100%; height:100%; display:block;");const r={alpha:t.alpha||!1,premultipliedAlpha:!0,antialias:!1,depth:!0,stencil:t.stencil??!0,powerPreference:"high-performance",preserveDrawingBuffer:t.preserveDrawingBuffer??!1},s=this._canvas.getContext("webgl2",r);null!=s?(this._rctx=Z(s,e),this._loadShaderOnlyExtensions(),!t.alpha&&this._rctx.contextAttributes.alpha&&i.getLogger(this).error("WebGL context has alpha channel even though no alpha channel was requested"),!this._rctx.contextAttributes.alpha&&has("safari")>=11&&(this._container.style.backgroundColor="black"),e.container.contains(this._canvas)||e.container.appendChild(this._canvas)):i.getLogger(this).error("A WebGL2 context could not be created.")}_loadShaderOnlyExtensions(){this._rctx.capabilities.enable("textureFloatLinear")}get _container(){return this.stage.container}get _viewingMode(){return this.stage.viewingMode}getObjectAndLayerIdColor(e){return this.olidRenderHelper?.getObjectAndLayerIdColor(e)}get componentObjectCollection(){return null==this._componentObjects&&(this._componentObjects=new j(this.renderer.renderPassManager,this._viewingMode)),this._componentObjects}set componentObjectCollection(e){this._componentObjects=e}updateQualitySettings(e){null!=this._testTime&&(this._savedFadeDuration=e.fadeDuration,e.fadeDuration=c(0))}set testTime(e){this._testTime=e,null==e?this.stage.view.qualitySettings.fadeDuration=this._savedFadeDuration:this.updateQualitySettings(this.stage.view.qualitySettings)}get testTime(){return this._testTime}};function Z(e,t){const r=(e,r)=>t.view.resourceController.memoryController.newCache(e,r),s={disabledExtensions:t.options.deactivatedWebGLExtensions||{},debugWebGLExtensions:t.options.debugWebGLExtensions||{},maxAnisotropy:8,newCache:r};if(X.enabled){let t=$.get(e);return t?(t.configure(s),t.ref(),t):(t=new B(e,s),$.set(e,t),t.ref(),t)}return new B(e,s)}e([l({type:Boolean,readOnly:!0})],Y.prototype,"updating",null),e([l({constructOnly:!0})],Y.prototype,"stage",void 0),e([l()],Y.prototype,"_rctx",void 0),e([l()],Y.prototype,"_canvas",void 0),e([l()],Y.prototype,"stippleTextures",void 0),e([l()],Y.prototype,"markerTextures",void 0),e([l()],Y.prototype,"waterTextures",void 0),e([l({readOnly:!0})],Y.prototype,"olidRenderHelper",void 0),e([l()],Y.prototype,"_textures",void 0),e([l({readOnly:!0})],Y.prototype,"renderer",void 0),e([l()],Y.prototype,"_screenshotManager",void 0),e([l()],Y.prototype,"componentObjectCollection",null),e([l()],Y.prototype,"_componentObjects",void 0),e([l()],Y.prototype,"_needsUpdate",void 0),e([l()],Y.prototype,"_needsWaterReflectionUpdate",void 0),Y=e([m("esri.views.3d.webgl-engine.parts.RenderView")],Y);const $=z();export{Y as RenderView};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import r from"../../../../core/Evented.js";import{unpackFloatRGBA as s}from"../../../../core/floatRGBA.js";import has from"../../../../core/has.js";import i from"../../../../core/Logger.js";import{removeMaybe as n,destroyMaybe as o}from"../../../../core/maybe.js";import{watch as a,initial as h,syncAndInitial as d}from"../../../../core/reactiveUtils.js";import{addFrameTask as p}from"../../../../core/scheduling.js";import{Milliseconds as c}from"../../../../core/time.js";import{property as l}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/RandomLCG.js";import{subclass as m}from"../../../../core/accessorSupport/decorators/subclass.js";import{isMoon as u,isMars as f}from"../../../../geometry/support/spatialReferenceUtils.js";import{ViewingMode as _}from"../../../ViewingMode.js";import{ChapmanAtmosphere as g}from"../../environment/ChapmanAtmosphere.js";import{CloudsComposition as w}from"../../environment/CloudsComposition.js";import{Fog as v}from"../../environment/Fog.js";import{LocalAtmosphere as x}from"../../environment/LocalAtmosphere.js";import y from"../../environment/MarsAtmosphere.js";import{ComponentObjectCollection as j}from"../collections/Component/ComponentObjectCollection.js";import{ShaderTechniqueConstructionContext as R}from"../core/shaderTechnique/ShaderTechniqueConstructionContext.js";import{ShaderTechniqueRepository as b}from"../core/shaderTechnique/ShaderTechniqueRepository.js";import{ObjectAndLayerIDRenderNode as A}from"../effects/geometry/ObjectAndLayerIDRenderNode.js";import{olidEnabled as T}from"../effects/geometry/olidUtils.js";import{RenderOccludedRenderNode as C}from"../effects/geometry/RenderOccludedRenderNode.js";import{Haze as S}from"../effects/haze/Haze.js";import{Highlight as O}from"../effects/highlight/Highlight.js";import{ShadowHighlight as U}from"../effects/highlight/ShadowHighlight.js";import{Magnifier as q}from"../effects/magnifier/Magnifier.js";import{SMAA as D}from"../effects/smaa/SMAA.js";import{SSAO as L}from"../effects/ssao/SSAO.js";import{Stars as M}from"../effects/stars/Stars.js";import{RenderRequestType as k}from"../lib/basicInterfaces.js";import E from"../lib/CompositingHelper.js";import{GLMaterialRepository as F}from"../lib/GLMaterialRepository.js";import{ObjectAndLayerIdRenderHelper as H}from"../lib/ObjectAndLayerIdRenderHelper.js";import{Renderer as W}from"../lib/Renderer.js";import{RenderingContext as B}from"../lib/RenderingContext.js";import{TextureRepository as G}from"../lib/TextureRepository.js";import{createMarkerTextureRepository as N}from"../materials/markerTextureRepository.js";import{createStippleTextureRepository as I}from"../materials/stippleTextureRepository.js";import{WaterTextureRepository as P}from"../materials/internal/WaterTextureRepository.js";import{getContextCache as z}from"./contextCache.js";import{removeLoadedShaderModules as K}from"./renderUtils.js";import{ScreenshotManager as V,ScreenshotContext as Q}from"./ScreenshotManager.js";import{contextCache as X}from"./testUtils.js";import{RenderState as J}from"../../../support/RenderState.js";let Y=class extends t{constructor(e){super(e),this.events=new r,this.waterTextures=new P,this.olidRenderHelper=T()?new H:null,this._needsUpdate=!0,this._needsRender=!0,this._idleSuspend=!0,this._needsWaterReflectionUpdate=!1,this._lastAnimationUpdate=0,this._savedFadeDuration=c(0);const t=e.stage;try{this._initializeContext(t)}catch(n){return void console.error("Failed to initialize context",n)}const{memoryController:s}=t.view.resourceController;this.stippleTextures=I(this._rctx,s),this.markerTextures=N(this._rctx,s),this._techniques=new b(new R(this._rctx,t.viewingMode,this.stippleTextures,this.waterTextures,this.markerTextures)),this._textures=new G(t,this._techniques,this._rctx),this.addHandles(this._textures.events.on("changed",(e=>this.requestRender(e)))),this._materials=new F(this._textures,this._techniques,(()=>this.requestRender()),(()=>this.requestRender())),this._compositingHelper=new E(this._rctx,this._techniques),this.renderer=new W(t,this._materials,this._techniques,this._rctx,this._compositingHelper,(e=>this.requestRender(e))),this.addHandles([a((()=>t.view.ready),(e=>{e&&this._createRenderNodes()}),h),a((()=>this.waterTextures?.updating),(()=>this.requestRender()),h),a((()=>t.view.qualityProfile),(e=>this.renderer?.updateRenderFeatures(e)),d)]);const i={renderScene:(e,t,r,s)=>this.renderer.render(e,t,r,s),requestRenderScene:e=>this.requestRender(e),prepareOverlay:()=>t.options.screenshot.prepareOverlay(),renderOverlay:(e,r,s)=>t.options.screenshot.renderOverlay(e,r,s)};this._screenshotManager=new V(this._rctx,i,(e=>this.events.emit("force-camera-for-screenshot",e))),this._registerFrameTask(t)}destroy(){const e=this.stage?.container;e?.contains(this._canvas)&&e.removeChild(this._canvas),this._frameTask=n(this._frameTask),this._techniques=o(this._techniques),this._componentObjects=o(this._componentObjects),this._screenshotManager=o(this._screenshotManager),o(this.renderer),this._textures=o(this._textures),o(this.waterTextures),o(this.markerTextures),o(this.stippleTextures),this._canvas=null,this._rctx=o(this._rctx)}_createRenderNodes(){const{view:e,viewingMode:t}=this.stage;new M({view:e}),u(e.spatialReference)||(t===_.Local?new x({view:e}):f(e.spatialReference)?new y({view:e}):(new g({view:e}),new w({view:e}),new S({view:e}),new v({view:e}))),new L({view:e,isEnabled:()=>this.renderer.hasSSAO}),new D({view:e,isEnabled:()=>this.renderer.hasSMAA}),new q({view:e}),new O({view:e}),new U({view:e,viewingMode:t}),new C({view:e}),T()&&new A({view:e})}requestRender(e=k.UPDATE){this._needsRender=!0,e===k.UPDATE&&(this._needsUpdate=!0)}get updating(){return this._needsUpdate||this._needsWaterReflectionUpdate||this.renderer.updating||this._textures.updating||this.waterTextures.updating}get textures(){return this._textures}get techniques(){return this._techniques}get compositingHelper(){return this._compositingHelper}setIdleSuspend(e){this._idleSuspend!==e&&(this._idleSuspend=e,this.requestRender())}get renderingContext(){return this._rctx}get capabilities(){return this._rctx.capabilities}get canvas(){return this._canvas}takeScreenshot(e){return this._screenshotManager.takeScreenshot(e).then((e=>e[0]))}takeScreenshotWithOID(e){return e.objectAndLayerIdColor=!0,this._screenshotManager.takeScreenshot(e)}getAlpha(){return!!this._rctx.contextAttributes.alpha}getMinimalDepthForArea(e,t,r,i,n,o=n){const a=i.constrainWindowSize(t,r,n*i.pixelRatio,o*i.pixelRatio),h=this._ensureLinearDepthArrayBuffer(a);this.renderer.readMainDepth(a,h);const d=(e,t,r)=>s(t,e)*(r[1]-r[0])+r[0];let p=Number.MAX_VALUE;for(let s=0;s<a[2]*a[3];s++){const e=d(4*s,h,i.nearFar);p>e&&e!==i.nearFar[0]&&e!==i.nearFar[1]&&(p=e)}if(e){const s=e.pickDepth(t*i.pixelRatio,r*i.pixelRatio,i);null!=s&&p>s&&s!==i.nearFar[0]&&s!==i.nearFar[1]&&(p=s)}return p===Number.MAX_VALUE?void 0:p}_ensureLinearDepthArrayBuffer(e){const t=4*e[2]*e[3];return(null==this._tmpDepthBuffer||this._tmpDepthBuffer.byteLength<t)&&(this._tmpDepthBuffer=new Uint8Array(t)),this._tmpDepthBuffer}async reloadShaders(){K(),await this._techniques.reloadAll(),this.renderer.overlay?.reloadShaders(),this.requestRender()}_registerFrameTask(e){const t=e.view.state;let r=!1,s=k.BACKGROUND,i=!1;const n={preRender:({time:i})=>{r=this.updating,s=this._needsUpdate?k.UPDATE:k.BACKGROUND,e.commitSyncLayers(),i=this._testTime??i;(c(i-this._lastAnimationUpdate)>this.renderer.animationTimestep||null!=t.forcedAnimationTime||r||this._needsRender)&&(this.renderer.updateAnimation(t,i)&&this.requestRender(k.BACKGROUND),this._lastAnimationUpdate=i)},render:({time:e})=>{if((this._needsRender||!this._idleSuspend||!this.renderer.isCameraFinal||this._needsWaterReflectionUpdate)&&t.camera.fullWidth>0&&t.camera.fullHeight>0){const r=this._needsUpdate&&this._idleSuspend&&this.renderer.isCameraFinal;this._needsRender=!1,this._needsUpdate=!1,this._needsWaterReflectionUpdate=!1,e=this._testTime??e,this.renderer.render(t,e),i=!0,r&&this.renderer.hasReflections&&(this.requestRender(k.BACKGROUND),this._needsWaterReflectionUpdate=!0)}},update:({time:e})=>{this._textures.update();const r=new Q(t,this.renderer.fboCache);e=this._testTime??e,this._screenshotManager.update(r,e)},finish:()=>{i&&(this.renderer.finish(t.mode===J.IDLE?s:k.UPDATE),i=!1)}};this._frameTask=p(n)}_initializeContext(e){const{options:t}=e,r=t.canvas??document.createElement("canvas");r.setAttribute("style","width: 100%; height:100%; display:block;"),this._canvas=r;const s={alpha:t.alpha||!1,premultipliedAlpha:!0,antialias:!1,depth:!0,stencil:t.stencil??!0,powerPreference:"high-performance",preserveDrawingBuffer:t.preserveDrawingBuffer??!1},n=r.getContext("webgl2",s);if(null==n)return void i.getLogger(this).error("A WebGL2 context could not be created.");this._rctx=Z(n,e),this._loadShaderOnlyExtensions(),!t.alpha&&this._rctx.contextAttributes.alpha&&i.getLogger(this).error("WebGL context has alpha channel even though no alpha channel was requested");const{container:o}=e;!this._rctx.contextAttributes.alpha&&has("safari")>=11&&(o.style.backgroundColor="black"),o.contains(r)||o.appendChild(r)}_loadShaderOnlyExtensions(){this._rctx.capabilities.enable("textureFloatLinear")}get _viewingMode(){return this.stage.viewingMode}getObjectAndLayerIdColor(e){return this.olidRenderHelper?.getObjectAndLayerIdColor(e)}get componentObjectCollection(){return null==this._componentObjects&&(this._componentObjects=new j(this.renderer.renderPassManager,this._viewingMode)),this._componentObjects}set componentObjectCollection(e){this._componentObjects=e}updateQualitySettings(e){null!=this._testTime&&(this._savedFadeDuration=e.fadeDuration,e.fadeDuration=c(0))}set testTime(e){this._testTime=e,null==e?this.stage.view.qualitySettings.fadeDuration=this._savedFadeDuration:this.updateQualitySettings(this.stage.view.qualitySettings)}get testTime(){return this._testTime}};function Z(e,t){const r=(e,r)=>t.view.resourceController.memoryController.newCache(e,r),s={disabledExtensions:t.options.deactivatedWebGLExtensions||{},debugWebGLExtensions:t.options.debugWebGLExtensions||{},maxAnisotropy:8,newCache:r};if(X.enabled){let t=$.get(e);return t?(t.configure(s),t.ref(),t):(t=new B(e,s),$.set(e,t),t.ref(),t)}return new B(e,s)}e([l({type:Boolean,readOnly:!0})],Y.prototype,"updating",null),e([l({constructOnly:!0})],Y.prototype,"stage",void 0),e([l()],Y.prototype,"_rctx",void 0),e([l()],Y.prototype,"_canvas",void 0),e([l()],Y.prototype,"stippleTextures",void 0),e([l()],Y.prototype,"markerTextures",void 0),e([l()],Y.prototype,"waterTextures",void 0),e([l({readOnly:!0})],Y.prototype,"olidRenderHelper",void 0),e([l()],Y.prototype,"_textures",void 0),e([l({readOnly:!0})],Y.prototype,"renderer",void 0),e([l()],Y.prototype,"_screenshotManager",void 0),e([l()],Y.prototype,"componentObjectCollection",null),e([l()],Y.prototype,"_componentObjects",void 0),e([l()],Y.prototype,"_needsUpdate",void 0),e([l()],Y.prototype,"_needsWaterReflectionUpdate",void 0),Y=e([m("esri.views.3d.webgl-engine.parts.RenderView")],Y);const $=z();export{Y as RenderView};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i,handlesGroup as r,abortHandle as s}from"../../core/handleUtils.js";import"../../core/has.js";import{removeMaybe as o,destroyMaybe as n}from"../../core/maybe.js";import{debounce as l}from"../../core/promiseUtils.js";import{watch as d,when as c,initial as u,whenOnce as h,syncAndInitial as p}from"../../core/reactiveUtils.js";import{generateBracedUUID as m}from"../../core/uuid.js";import{property as f}from"../../core/accessorSupport/decorators/property.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as w}from"../../core/accessorSupport/decorators/subclass.js";import{isSharedTemplateOrMetadata as g}from"../../editing/templateUtils.js";import y from"../../layers/GraphicsLayer.js";import{isTable as v}from"../../layers/support/layerUtils.js";import{getDrawHelpMessage as F}from"../../views/draw/support/helpMessageUtils.js";import _ from"../../views/draw/support/HighlightHelper.js";import M from"../../views/interactive/sketch/SketchOptions.js";import b from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as V}from"../../views/support/HighlightDefaults.js";import k from"./CreateFeaturesWorkflowData.js";import{isModelUpload as I,handleModelUpload as S}from"./modelUploadUtils.js";import C from"./Workflow.js";import{startCreatingNewFeature as H,findLayerInfo as A,updateGraphicSymbolWhenRequired as P,isTerminalUpdateEventType as j,getVisualVariableAttributes as E,startUpdatingFeatureGeometry as U,createWorkflowSteps as T,avoidFeatureTemplateSelectionWithOnlyOneItem as O,prepareAttachmentsForCreateFeaturesWorkflow as D,showProgressCursor as L,visualVariableInteractiveUpdate as x}from"./workflowUtils.js";import W from"../FeatureForm/FeatureFormViewModel.js";import G from"../Sketch/SketchViewModel.js";var N;const z=Symbol(),R=Symbol(),Z=Symbol(),q=Symbol(),K={point:["point"],multipoint:["multipoint"],polygon:["polygon","freehandPolygon","rectangle","circle"],polyline:["polyline","freehandPolyline"],mesh:[],multipatch:[]};let B=N=class extends C{constructor(e){super(e),this.type="create-features",this.createFeatureState="create-new",this.data=void 0,this.isNested=!1,this._getDrawMeshHelpMessage=void 0,this._webStyleCache=new Map,this._featureFormHandle=null,this._visualVariableAttributes={rotation:null,size:null},this._featureFormViewModel=new W,this._sketchViewModel=null,this._attachmentFileInfos=new Map,this._isActive=!0,this._updateGraphicDebounced=l(((e,t,a)=>P(e,t,a)))}initialize(){this.isNested&&(this._isActive=!1),this._initializeSketchViewModel()}destroy(){this._sketchViewModel.destroy()}get featureFormViewModel(){return this._featureFormViewModel}get hasPendingEdits(){if(this.pendingFeatures.some((e=>!!this.data.getEditsForPendingFeature(e)?.modified)))return!0;const{creationInfo:e,upload:t}=this.data,a=this._sketchViewModel,{activeComponent:i}=a,r=a.createGraphic?.geometry?.type;return!("polyline"!==r&&"polygon"!==r&&"multipoint"!==r||"draw-2d"!==i?.type&&"draw-3d"!==i?.type)&&i.drawOperation.committedVertices.length>0||(!(!t||"pending"!==t.state&&"success"!==t.state)||!!e?.geometryToPlace)}get helpMessage(){const{creationInfo:e,viewModel:t}=this.data;if("creating-features"!==this.stepId||!e)return;const a=e.layer.geometryType,i=this._sketchViewModel.createGraphic;if("mesh"===a){this._getDrawMeshHelpMessage||import("../../views/draw/support/helpMessageUtils3d.js").then((e=>{this._getDrawMeshHelpMessage=e.getDrawMeshHelpMessage}));const{view:e}=t;return"3d"===e?.type?this._getDrawMeshHelpMessage?.(i,e):void 0}const r=this._sketchViewModel.activeCreateToolDrawMode,s=this._sketchViewModel.activeTool;return F("rectangle"===s?"rectangle":"circle"===s?"circle":a,i?.geometry,r)}get layer(){return this.data.creationInfo?.layer}get numPendingFeatures(){return this.pendingFeatures.length}get parent(){return this.data.parent}get parentLayer(){return this.parent?.data.editorItem.layer}get pendingFeatures(){return this.data.pendingFeatures}get keyboardCancellationEnabled(){return 0===this.numPendingFeatures}get reliesOnOwnerAdminPrivileges(){return this.data.editorItem?.capabilities.create.reliesOnOwnerAdminPrivileges??!1}get shouldShowAttachments(){return(this.data.selectedPendingFeature&&this.data.editorItem?.capabilities.create.attachments.enabled)??!1}get shouldAllowAttachmentEditing(){return this.shouldShowAttachments}get sketchViewModel(){return this._sketchViewModel}get test(){}get availableCreateTools(){const e=this.data.creationInfo?.layer.geometryType,t=this.data.viewModel.view;return e?this.data.creationInfo?.maxFeatures&&this.data.creationInfo.maxFeatures<=this.numPendingFeatures||"2d"!==t?.type&&"multipoint"===e?[]:[...K[e]]:[]}async enter(){this._isActive=!0,"awaiting-feature-creation-info"!==this.stepId&&this._setUpCreatingFeaturesStep()}exit(){this._isActive=!1,this.removeHandles([Z])}async updatePendingFeature(e){if(e!==this.data.selectedPendingFeature)return this._sketchViewModel.cancel(),this._startUpdating({feature:e})}async start(){return await super.start(),v(this.data.creationInfo?.layer)?null:{enter:async()=>{},exit:async()=>{},viewModel:this._sketchViewModel}}async save(){const{featureFormViewModel:e}=this;if(e.pendingSubtypeChoice)return;e.submit(),this._stashValidationState();const t=this.data.selectedPendingFeature,a=this._hasValidationErrors(t)?t:this.data.pendingFeatures.find((e=>this._hasValidationErrors(e)));return a?(await this._startUpdating({feature:a}),void e?.submit()):super.save()}cancelFeature(e){this.data.removePendingFeature(e),this.sketchViewModel.layer.graphics.remove(e)}static create(e){const{addAttachmentsCallback:t,applyEditsCallback:a,isNested:i,creationInfo:r,parent:s,snappingManager:o,startAt:n,viewModel:l}=e,d=e.sketchOptions??new M,c=r?.layer,u=c?l.findEditorItemForLayer(c):void 0,h=new N({data:new k({creationInfo:r,editorItem:u,parent:s,sketchOptions:d,snappingManager:o,viewModel:l}),isNested:i,onCommit:async e=>{const{creationInfo:i}=e;if(!i)return;h._sketchViewModel.cancel();const r=e.pendingFeatures.toArray(),{layer:s}=i,o=s.capabilities?.editing.supportsGlobalId&&"globalIdField"in s,n=h._attachmentFileInfos;if(o){const e=Y(r,s,n);return void await a(s,e,{globalIdUsed:!0})}const l=await a(s,{addFeatures:r});if(n.size>0){const e=l?.addFeatureResults??[];await t(s,X(r,e,s,n))}}});return h._set("steps",this._createWorkflowSteps(h,n)),h}_fadeExistingFeatures(e){if("effect"in e){const t=e.effect;return e.effect="saturate(0.6) opacity(0.8)",i((()=>e.effect=t))}const t=e.opacity;return e.opacity=.7,i((()=>e.opacity=t))}async _startCreating(){this.removeHandles(R);const{creationInfo:e}=this.data;if(!e)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";const a=await H(this._sketchViewModel,this._webStyleCache,e);this.addHandles(a,R)}async _clearSelectedFeature(){const e=this._featureFormViewModel.pendingSubtypeChoice;e&&(e.resolve("undo"),await e.promise),this._stashValidationState(),this.data.selectedPendingFeature=null,this._featureFormViewModel.feature=null;const t=this.data.viewModel.attachmentsViewModel;"add"!==t.mode&&"edit"!==t.mode||this.data.viewModel.activeWorkflow?.previous()}_stashValidationState(){const e=this._featureFormViewModel.feature,t=e&&this.data.getEditsForPendingFeature(e);t&&(t.submittable=this._featureFormViewModel.submittable)}async _selectFeatureForUpdate({feature:e,initialFeature:t=e}){this._stashValidationState();const{data:a,pendingFeatures:i,_webStyleCache:s}=this;i.includes(e)||a.addPendingFeature(e,t),a.selectedPendingFeature=e;const{_featureFormViewModel:n,_sketchViewModel:l}=this,{creationInfo:c,viewModel:u}=a,{attachmentsViewModel:h,layerInfos:p,view:m}=u;if(!m||!c)return;const f=c.layer,w=A(p,f),g=w?.formTemplate,y=m.spatialReference;n.set({arcadeEditType:"INSERT",feature:e,formTemplate:g,spatialReference:y,map:m.map}),"add"!==h.mode&&"edit"!==h.mode||u.activeWorkflow?.previous(),h.graphic=e,h.fileInfos.removeAll(),h.mode="view";if((this._attachmentFileInfos.get(e)||[]).forEach((({file:e,form:t})=>h.addFile(e,t))),await P(e,s,"2d"===m.type?m.scale:null),this.removeHandles(R),o(this._featureFormHandle),"2d"===m.type){const t=d((()=>m.scale),(t=>this._updateGraphicDebounced(e,s,t)));this.addHandles(t,R)}const v=a.getEditsForPendingFeature(e);this._featureFormHandle=r([n.on("value-change",(async()=>{v?.updateAttributes(n.getValues()),await P(e,s,"2d"===m.type?m.scale:null)})),l.on(["update","undo","redo"],(e=>{("undo"===e.type||"redo"===e.type||"update"===e.type&&null!=e.toolEventInfo&&j(e.toolEventInfo.type))&&n.notifyFeatureGeometryChanged()})),d((()=>n.feature?.sourceLayer),(t=>e.sourceLayer=t))]),this.createFeatureState="update-pending",this._visualVariableAttributes=E(e)}async _startUpdating({feature:e,initialFeature:t=e}){await this._selectFeatureForUpdate({feature:e,initialFeature:t});const{_sketchViewModel:a,data:i}=this,{creationInfo:r,viewModel:s}=i,{view:o}=s;if(!o||!r)return;const n=r.layer;return v(n)?void 0:U({graphic:e,sketchViewModel:a,sourceLayer:n,visualVariables:this._visualVariableAttributes,webStyleCache:this._webStyleCache})}static _createWorkflowSteps(e,t="awaiting-feature-creation-info"){const{data:a}=e,i=T(["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&&(I(t)?e.addHandles(await S({view:r,data:a,next:()=>e.next(),cancel:()=>i.cancelWorkflow({warnIfNoWorkflow:!1})}),this.id):(a.parent&&t&&(e.addHandles(i.lockFeatureTemplatesViewModel(),this.id),i.featureTemplatesViewModel.layers=[t.layer]),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,R])}}),"creating-features":()=>({id:"creating-features",async setUp(){e._isActive&&await e._setUpCreatingFeaturesStep()},async tearDown(t){const{viewModel:i}=a;t.canceled&&(e.removeHandles([Z,z,R,q]),i.attachmentsViewModel.fileInfos.removeAll(),e._attachmentFileInfos.clear())}}),"adding-attachment":()=>({id:"adding-attachment",parent:"creating-features",async setUp(){},async tearDown(){const{attachmentsViewModel:t}=a.viewModel,{graphic:i,fileInfos:r}=t;e._attachmentFileInfos.set(i,r.toArray()),t.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"creating-features",async setUp(){},async tearDown(){const{attachmentsViewModel:t}=a.viewModel,{graphic:i,fileInfos:r}=t;e._attachmentFileInfos.set(i,r.toArray()),t.mode="view"}})});return O(a,i)}static _configureSketchViewModel(e){const{data:t}=e,{creationInfo:a,viewModel:s}=t,{view:o}=s,n=e._sketchViewModel,l=[];if(!o)return i();"2d"===o.type&&a&&l.push(e._fadeExistingFeatures(a.layer));const u=async t=>{if("cancel"===t.state&&null!==o.activeTool&&o.activeTool!==e.sketchViewModel.activeComponent&&(await e._waitForActiveToolCleared(),await e._startCreating()),"complete"===t.state&&t.graphic){const a=t.graphic,i=t.graphic.clone();return i.geometry=null,await e._waitForActiveToolCleared(),void await e._selectFeatureForUpdate({feature:a,initialFeature:i})}},h=async i=>{const{attachmentsViewModel:r}=s,{_featureFormViewModel:n}=e;if(i.graphics.length>1)return void await e._clearSelectedFeature();const l=i.graphics[0];if("complete"===i.state){const{submittable:t}=n;if(e.numPendingFeatures!==a?.maxFeatures&&t||n.submit(),await e._clearSelectedFeature(),"add"!==r.mode&&"edit"!==r.mode||s.activeWorkflow?.previous(),!i.aborted&&o.activeTool===e.sketchViewModel.activeComponent&&(await e.sketchViewModel.wait(),"ready"===e.sketchViewModel.state&&"mesh"!==e.data.creationInfo?.layer.geometryType))return e._startCreating()}else{if("start"===i.state)return l.sourceLayer=t.creationInfo?.layer,e._selectFeatureForUpdate({feature:l});if("active"===i.state){await e.updatePendingFeature(l);const t=e._visualVariableAttributes;await x(o,l,i,t,e._webStyleCache);const a=l.attributes,{rotation:r,size:s}=t;if(null!=r){const{field:e}=r;n.setValue(e,a[e])}if(null!=s){const{field:e}=s;n.setValue(e,a[e])}}}},p=async a=>{if(a.graphics.forEach((e=>{t.removePendingFeature(e)})),!I(t.creationInfo))return e._startCreating()},m=async()=>(I(t.creationInfo)&&await e.data.viewModel.back(),e._startCreating());l.push(n.on("create",(t=>e._updatingHandles.addPromise(u(t)))),n.on("update",(t=>e._updatingHandles.addPromise(h(t)))),n.on("delete",(t=>e._updatingHandles.addPromise(p(t)))),c((()=>!e.numPendingFeatures),(()=>e._updatingHandles.addPromise(m()))),J(n,t),...Q(t)),l.push(d((()=>[e._featureFormViewModel.feature,e._featureFormViewModel.submittable]),(()=>{e._stashValidationState()})));const f=r(l);return n.addHandles(f),f}_initializeSketchViewModel(){const{data:e}=this,{view:t}=e.viewModel,a=new y({elevationInfo:e.creationInfo?.layer.elevationInfo,internal:!0,listMode:"hide"}),r=new G({layer:a,creationMode:"update",sketchOptions:e.sketchOptions,snappingManager:e.snappingManager,updateOnGraphicClick:!1,defaultUpdateOptions:{multipleSelectionEnabled:!1},view:t});this._sketchViewModel=r,t?.map.add(a),this.addHandles([i((()=>{t?.destroyed||t?.map.remove(a),a.destroy()})),d((()=>this.numPendingFeatures>0),(e=>this._sketchViewModel.updateOnGraphicClick=e),u)])}_hasValidationErrors(e){return!!e&&(!this.data.isSubmittable(e)||!!this._featureFormViewModel.validateContingencyConstraints(e.attributes,{includeIncompleteViolations:!0})?.length)}async _setUpCreatingFeaturesStep(){if(this.hasHandles(Z))return;const{data:e,sketchViewModel:s}=this,{creationInfo:n,viewModel:l}=e,{attachmentsViewModel:c,view:h}=l;if(!h||!n?.layer)throw new a("missing-parameters","CreateFeaturesWorkflow requires a view and creationInfo.");const{initialFeature:p,layer:m}=n,f=[];this._featureFormHandle=o(this._featureFormHandle),this._visualVariableAttributes={rotation:null,size:null},this.data.editorItem=l.findEditorItemForLayer(n.layer),D(c),f.push(d((()=>c.mode),(e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}})));const w=L(h);f.push(w);const y=v(n.layer);try{if(y){const{template:e}=n;if(e&&g(e))throw new a("Shared templates are not yet supported");const i=p??new t({attributes:{...e?.prototype.attributes,...n.attributeOverrides},sourceLayer:m});await this._startUpdating({feature:i})}else f.push(N._configureSketchViewModel(this)),p?(s.layer.add(p),await this._startUpdating({feature:p})):await this._startCreating()}finally{w.remove()}const F=i((()=>{for(const t of e.pendingFeatures)s.layer.remove(t),e.removePendingFeature(t)})),_=d((()=>h?.timeZone),(e=>this._featureFormViewModel.timeZone=e),u),M=i((()=>{I(n)&&l.cancelWorkflow({warnIfNoWorkflow:!1})}));this._featureFormHandle&&f.push(this._featureFormHandle),this.addHandles(f,this._handleKeys.beforeCommit),this.addHandles([i((()=>c.fileInfos.removeAll())),r(f),M,F,_],Z)}async _waitForActiveToolCleared(){const e=this.data.viewModel.view;if(null==e?.activeTool)return;const t=new AbortController;this.addHandles(s(t),q),await h((()=>null==e?.activeTool),t.signal),t.abort()}};function J(e,t){let a=null;const s=()=>e.snappingOptions.featureSources,o=()=>(a=new b({layer:e.layer}),s().add(a),a),l=()=>{null!=a&&(s().remove(a),a=n(a))};return r([d((()=>{const e=t.creationInfo?.layer,a=s().find((t=>t.layer===e));return{hasFeatureLayerSource:!!a,enabled:a?.enabled??!1}}),(({hasFeatureLayerSource:e,enabled:t})=>{if(!e)return l();a??=o(),a.enabled=t}),p),i(l)])}function Q(e){const t=e.viewModel.view;if(!t)return[];const a=[];if("3d"===t.type){const r=new _({view:t});a.push(d((()=>e.selectedPendingFeature),((e,t)=>{r.remove(e),r.add(t)})),i((()=>r.destroy())))}const r=new _({view:t,highlightName:V});return a.push(d((()=>e.temporaryHighlightFeature),(e=>{r.removeAll(),r.add(e)})),i((()=>r.destroy()))),a}function X(e,t,a,i){const r=[];return t.forEach(((t,s)=>{if(!t.error){const o=e[s],n=i.get(o)||[];o.attributes[a.objectIdField]=t.objectId,n.forEach((({form:e})=>r.push({feature:o,attachment:e})))}})),r}function Y(e,t,a){const i=[],r=t.globalIdField;return e.forEach(((t,s)=>{e[s].attributes[r]??=m(),(a?.get(t)||[]).forEach((({file:e})=>i.push({feature:t,attachment:{globalId:m(),data:e}})))})),i.length?{addFeatures:e,addAttachments:i}:{addFeatures:e}}e([f()],B.prototype,"createFeatureState",void 0),e([f()],B.prototype,"data",void 0),e([f({constructOnly:!0})],B.prototype,"isNested",void 0),e([f()],B.prototype,"featureFormViewModel",null),e([f()],B.prototype,"hasPendingEdits",null),e([f()],B.prototype,"_getDrawMeshHelpMessage",void 0),e([f()],B.prototype,"helpMessage",null),e([f()],B.prototype,"layer",null),e([f()],B.prototype,"parent",null),e([f()],B.prototype,"parentLayer",null),e([f()],B.prototype,"keyboardCancellationEnabled",null),e([f()],B.prototype,"reliesOnOwnerAdminPrivileges",null),e([f()],B.prototype,"shouldShowAttachments",null),e([f()],B.prototype,"shouldAllowAttachmentEditing",null),e([f()],B.prototype,"sketchViewModel",null),e([f()],B.prototype,"availableCreateTools",null),B=N=e([w("esri.widgets.Editor.CreateFeaturesWorkflow")],B);const $=B;export{$ as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i,handlesGroup as r,abortHandle as s}from"../../core/handleUtils.js";import"../../core/has.js";import{removeMaybe as o,destroyMaybe as n}from"../../core/maybe.js";import{debounce as l}from"../../core/promiseUtils.js";import{watch as d,when as c,initial as u,whenOnce as h,syncAndInitial as p}from"../../core/reactiveUtils.js";import{generateBracedUUID as m}from"../../core/uuid.js";import{property as f}from"../../core/accessorSupport/decorators/property.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as w}from"../../core/accessorSupport/decorators/subclass.js";import{isSharedTemplateOrMetadata as g}from"../../editing/templateUtils.js";import y from"../../layers/GraphicsLayer.js";import{isTable as v}from"../../layers/support/layerUtils.js";import{getDrawHelpMessage as F}from"../../views/draw/support/helpMessageUtils.js";import _ from"../../views/draw/support/HighlightHelper.js";import M from"../../views/interactive/sketch/SketchOptions.js";import b from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as V}from"../../views/support/HighlightDefaults.js";import k from"./CreateFeaturesWorkflowData.js";import{isModelUpload as I,handleModelUpload as S}from"./modelUploadUtils.js";import C from"./Workflow.js";import{startCreatingNewFeature as P,findLayerInfo as H,updateGraphicSymbolWhenRequired as A,isTerminalUpdateEventType as j,getVisualVariableAttributes as E,startUpdatingFeatureGeometry as U,createWorkflowSteps as T,avoidFeatureTemplateSelectionWithOnlyOneItem as O,prepareAttachmentsForCreateFeaturesWorkflow as D,showProgressCursor as L,visualVariableInteractiveUpdate as x}from"./workflowUtils.js";import W from"../FeatureForm/FeatureFormViewModel.js";import G from"../Sketch/SketchViewModel.js";var N;const z=Symbol(),R=Symbol(),Z=Symbol(),q=Symbol(),K={point:["point"],multipoint:["multipoint"],polygon:["polygon","freehandPolygon","rectangle","circle"],polyline:["polyline","freehandPolyline"],mesh:[],multipatch:[]};let B=N=class extends C{constructor(e){super(e),this.type="create-features",this.createFeatureState="create-new",this.data=void 0,this.isNested=!1,this._getDrawMeshHelpMessage=void 0,this._webStyleCache=new Map,this._featureFormHandle=null,this._visualVariableAttributes={rotation:null,size:null},this._featureFormViewModel=new W,this._sketchViewModel=null,this._attachmentFileInfos=new Map,this._isActive=!0,this._updateGraphicDebounced=l(((e,t,a)=>A(e,t,a)))}initialize(){this.isNested&&(this._isActive=!1),this._initializeSketchViewModel()}destroy(){this._sketchViewModel.destroy()}get featureFormViewModel(){return this._featureFormViewModel}get hasPendingEdits(){if(this.pendingFeatures.some((e=>!!this.data.getEditsForPendingFeature(e)?.modified)))return!0;const{creationInfo:e,upload:t}=this.data,a=this._sketchViewModel,{activeComponent:i}=a,r=a.createGraphic?.geometry?.type;return!("polyline"!==r&&"polygon"!==r&&"multipoint"!==r||"draw-2d"!==i?.type&&"draw-3d"!==i?.type)&&i.drawOperation.committedVertices.length>0||(!(!t||"pending"!==t.state&&"success"!==t.state)||!!e?.geometryToPlace)}get hasPreviousStep(){return"update-pending"===this.createFeatureState&&!!this.data.selectedPendingFeature}get helpMessage(){const{creationInfo:e,viewModel:t}=this.data;if("creating-features"!==this.stepId||!e)return;const a=e.layer.geometryType,i=this._sketchViewModel.createGraphic;if("mesh"===a){this._getDrawMeshHelpMessage||import("../../views/draw/support/helpMessageUtils3d.js").then((e=>{this._getDrawMeshHelpMessage=e.getDrawMeshHelpMessage}));const{view:e}=t;return"3d"===e?.type?this._getDrawMeshHelpMessage?.(i,e):void 0}const r=this._sketchViewModel.activeCreateToolDrawMode,s=this._sketchViewModel.activeTool;return F("rectangle"===s?"rectangle":"circle"===s?"circle":a,i?.geometry,r)}get layer(){return this.data.creationInfo?.layer}get numPendingFeatures(){return this.pendingFeatures.length}get parent(){return this.data.parent}get parentLayer(){return this.parent?.data.editorItem.layer}get pendingFeatures(){return this.data.pendingFeatures}get keyboardCancellationEnabled(){return 0===this.numPendingFeatures}get reliesOnOwnerAdminPrivileges(){return this.data.editorItem?.capabilities.create.reliesOnOwnerAdminPrivileges??!1}get shouldShowAttachments(){return(this.data.selectedPendingFeature&&this.data.editorItem?.capabilities.create.attachments.enabled)??!1}get shouldAllowAttachmentEditing(){return this.shouldShowAttachments}get sketchViewModel(){return this._sketchViewModel}get test(){}get availableCreateTools(){const e=this.data.creationInfo?.layer.geometryType,t=this.data.viewModel.view;return e?this.data.creationInfo?.maxFeatures&&this.data.creationInfo.maxFeatures<=this.numPendingFeatures||"2d"!==t?.type&&"multipoint"===e?[]:[...K[e]]:[]}async enter(){this._isActive=!0,"awaiting-feature-creation-info"!==this.stepId&&this._setUpCreatingFeaturesStep()}exit(){this._isActive=!1,this.removeHandles([Z])}async updatePendingFeature(e){if(e!==this.data.selectedPendingFeature)return this._sketchViewModel.cancel(),this._startUpdating({feature:e})}async start(){return await super.start(),v(this.data.creationInfo?.layer)?null:{enter:async()=>{},exit:async()=>{},viewModel:this._sketchViewModel}}async save(){const{featureFormViewModel:e}=this;if(e.pendingSubtypeChoice)return;e.submit(),this._stashValidationState();const t=this.data.selectedPendingFeature,a=this._hasValidationErrors(t)?t:this.data.pendingFeatures.find((e=>this._hasValidationErrors(e)));return a?(await this._startUpdating({feature:a}),void e?.submit()):super.save()}back(e){return"update-pending"===this.createFeatureState&&this.data.selectedPendingFeature&&!I(this.data.creationInfo)?this._clearSelectedFeature():super.back(e)}previous(e){return"update-pending"===this.createFeatureState&&this.data.selectedPendingFeature&&!I(this.data.creationInfo)?this._clearSelectedFeature():super.previous(e)}cancelFeature(e){this.data.removePendingFeature(e),this.sketchViewModel.layer.graphics.remove(e)}static create(e){const{addAttachmentsCallback:t,applyEditsCallback:a,isNested:i,creationInfo:r,parent:s,snappingManager:o,startAt:n,viewModel:l}=e,d=e.sketchOptions??new M,c=r?.layer,u=c?l.findEditorItemForLayer(c):void 0,h=new N({data:new k({creationInfo:r,editorItem:u,parent:s,sketchOptions:d,snappingManager:o,viewModel:l}),isNested:i,onCommit:async e=>{const{creationInfo:i}=e;if(!i)return;h._sketchViewModel.cancel();const r=e.pendingFeatures.toArray(),{layer:s}=i,o=s.capabilities?.editing.supportsGlobalId&&"globalIdField"in s,n=h._attachmentFileInfos;if(o){const e=Y(r,s,n);return void await a(s,e,{globalIdUsed:!0})}const l=await a(s,{addFeatures:r});if(n.size>0){const e=l?.addFeatureResults??[];await t(s,X(r,e,s,n))}}});return h._set("steps",this._createWorkflowSteps(h,n)),h}_fadeExistingFeatures(e){if("effect"in e){const t=e.effect;return e.effect="saturate(0.6) opacity(0.8)",i((()=>e.effect=t))}const t=e.opacity;return e.opacity=.7,i((()=>e.opacity=t))}async _startCreating(){this.removeHandles(R);const{creationInfo:e}=this.data;if(!e)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";const a=await P(this._sketchViewModel,this._webStyleCache,e);this.addHandles(a,R)}async _clearSelectedFeature(){const e=this._featureFormViewModel.pendingSubtypeChoice;e&&(e.resolve("undo"),await e.promise),this._stashValidationState(),this.sketchViewModel.cancel(),this.data.selectedPendingFeature=null,this._featureFormViewModel.feature=null;const t=this.data.viewModel.attachmentsViewModel;"add"!==t.mode&&"edit"!==t.mode||this.data.viewModel.activeWorkflow?.previous()}_stashValidationState(){const e=this._featureFormViewModel.feature,t=e&&this.data.getEditsForPendingFeature(e);t&&(t.submittable=this._featureFormViewModel.submittable)}async _selectFeatureForUpdate({feature:e,initialFeature:t=e}){this._stashValidationState();const{data:a,pendingFeatures:i,_webStyleCache:s}=this;i.includes(e)||a.addPendingFeature(e,t),a.selectedPendingFeature=e;const{_featureFormViewModel:n,_sketchViewModel:l}=this,{creationInfo:c,viewModel:u}=a,{attachmentsViewModel:h,layerInfos:p,view:m}=u;if(!m||!c)return;const f=c.layer,w=H(p,f),g=w?.formTemplate,y=m.spatialReference;n.set({arcadeEditType:"INSERT",feature:e,formTemplate:g,spatialReference:y,map:m.map}),"add"!==h.mode&&"edit"!==h.mode||u.activeWorkflow?.previous(),h.graphic=e,h.fileInfos.removeAll(),h.mode="view";if((this._attachmentFileInfos.get(e)||[]).forEach((({file:e,form:t})=>h.addFile(e,t))),await A(e,s,"2d"===m.type?m.scale:null),this.removeHandles(R),o(this._featureFormHandle),"2d"===m.type){const t=d((()=>m.scale),(t=>this._updateGraphicDebounced(e,s,t)));this.addHandles(t,R)}const v=a.getEditsForPendingFeature(e);this._featureFormHandle=r([n.on("value-change",(async()=>{v?.updateAttributes(n.getValues()),await A(e,s,"2d"===m.type?m.scale:null)})),l.on(["update","undo","redo"],(e=>{("undo"===e.type||"redo"===e.type||"update"===e.type&&null!=e.toolEventInfo&&j(e.toolEventInfo.type))&&n.notifyFeatureGeometryChanged()})),d((()=>n.feature?.sourceLayer),(t=>e.sourceLayer=t))]),this.createFeatureState="update-pending",this._visualVariableAttributes=E(e)}async _startUpdating({feature:e,initialFeature:t=e}){await this._selectFeatureForUpdate({feature:e,initialFeature:t});const{_sketchViewModel:a,data:i}=this,{creationInfo:r,viewModel:s}=i,{view:o}=s;if(!o||!r)return;const n=r.layer;return v(n)?void 0:U({graphic:e,sketchViewModel:a,sourceLayer:n,visualVariables:this._visualVariableAttributes,webStyleCache:this._webStyleCache})}static _createWorkflowSteps(e,t="awaiting-feature-creation-info"){const{data:a}=e,i=T(["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&&(I(t)?e.addHandles(await S({view:r,data:a,next:()=>e.next(),cancel:()=>i.cancelWorkflow({warnIfNoWorkflow:!1})}),this.id):(a.parent&&t&&(e.addHandles(i.lockFeatureTemplatesViewModel(),this.id),i.featureTemplatesViewModel.layers=[t.layer]),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,R])}}),"creating-features":()=>({id:"creating-features",async setUp(){e._isActive&&await e._setUpCreatingFeaturesStep()},async tearDown(t){const{viewModel:i}=a;t.canceled&&(e.removeHandles([Z,z,R,q]),i.attachmentsViewModel.fileInfos.removeAll(),e._attachmentFileInfos.clear())}}),"adding-attachment":()=>({id:"adding-attachment",parent:"creating-features",async setUp(){},async tearDown(){const{attachmentsViewModel:t}=a.viewModel,{graphic:i,fileInfos:r}=t;e._attachmentFileInfos.set(i,r.toArray()),t.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"creating-features",async setUp(){},async tearDown(){const{attachmentsViewModel:t}=a.viewModel,{graphic:i,fileInfos:r}=t;e._attachmentFileInfos.set(i,r.toArray()),t.mode="view"}})});return O(a,i)}static _configureSketchViewModel(e){const{data:t}=e,{creationInfo:a,viewModel:s}=t,{view:o}=s,n=e._sketchViewModel,l=[];if(!o)return i();"2d"===o.type&&a&&l.push(e._fadeExistingFeatures(a.layer));const u=async t=>{if("cancel"===t.state&&null!==o.activeTool&&o.activeTool!==e.sketchViewModel.activeComponent&&(await e._waitForActiveToolCleared(),await e._startCreating()),"complete"===t.state&&t.graphic){const a=t.graphic,i=t.graphic.clone();return i.geometry=null,await e._waitForActiveToolCleared(),void await e._selectFeatureForUpdate({feature:a,initialFeature:i})}},h=async i=>{const{attachmentsViewModel:r}=s,{_featureFormViewModel:n}=e;if(i.graphics.length>1)return void await e._clearSelectedFeature();const l=i.graphics[0];if("complete"===i.state){const{submittable:t}=n;if(e.numPendingFeatures!==a?.maxFeatures&&t||n.submit(),await e._clearSelectedFeature(),"add"!==r.mode&&"edit"!==r.mode||s.activeWorkflow?.previous(),!i.aborted&&o.activeTool===e.sketchViewModel.activeComponent&&(await e.sketchViewModel.wait(),"ready"===e.sketchViewModel.state&&"mesh"!==e.data.creationInfo?.layer.geometryType))return e._startCreating()}else{if("start"===i.state)return l.sourceLayer=t.creationInfo?.layer,e._selectFeatureForUpdate({feature:l});if("active"===i.state){await e.updatePendingFeature(l);const t=e._visualVariableAttributes;await x(o,l,i,t,e._webStyleCache);const a=l.attributes,{rotation:r,size:s}=t;if(null!=r){const{field:e}=r;n.setValue(e,a[e])}if(null!=s){const{field:e}=s;n.setValue(e,a[e])}}}},p=async a=>{if(a.graphics.forEach((e=>{t.removePendingFeature(e)})),!I(t.creationInfo))return e._startCreating()},m=async()=>{if(I(t.creationInfo))try{await e.data.viewModel.back()}catch{}return e._startCreating()};l.push(n.on("create",(t=>e._updatingHandles.addPromise(u(t)))),n.on("update",(t=>e._updatingHandles.addPromise(h(t)))),n.on("delete",(t=>e._updatingHandles.addPromise(p(t)))),c((()=>!e.numPendingFeatures),(()=>e._updatingHandles.addPromise(m()))),J(n,t),...Q(t)),l.push(d((()=>[e._featureFormViewModel.feature,e._featureFormViewModel.submittable]),(()=>{e._stashValidationState()})));const f=r(l);return n.addHandles(f),f}_initializeSketchViewModel(){const{data:e}=this,{view:t}=e.viewModel,a=new y({elevationInfo:e.creationInfo?.layer.elevationInfo,internal:!0,listMode:"hide"}),r=new G({layer:a,creationMode:"update",sketchOptions:e.sketchOptions,snappingManager:e.snappingManager,updateOnGraphicClick:!1,defaultUpdateOptions:{multipleSelectionEnabled:!1},view:t});this._sketchViewModel=r,t?.map.add(a),this.addHandles([i((()=>{t?.destroyed||t?.map.remove(a),a.destroy()})),d((()=>this.numPendingFeatures>0),(e=>this._sketchViewModel.updateOnGraphicClick=e),u)])}_hasValidationErrors(e){return!!e&&(!this.data.isSubmittable(e)||!!this._featureFormViewModel.validateContingencyConstraints(e.attributes,{includeIncompleteViolations:!0})?.length)}async _setUpCreatingFeaturesStep(){if(this.hasHandles(Z))return;const{data:e,sketchViewModel:s}=this,{creationInfo:n,viewModel:l}=e,{attachmentsViewModel:c,view:h}=l;if(!h||!n?.layer)throw new a("missing-parameters","CreateFeaturesWorkflow requires a view and creationInfo.");const{initialFeature:p,layer:m}=n,f=[];this._featureFormHandle=o(this._featureFormHandle),this._visualVariableAttributes={rotation:null,size:null},this.data.editorItem=l.findEditorItemForLayer(n.layer),D(c),f.push(d((()=>c.mode),(e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}})));const w=L(h);f.push(w);const y=v(n.layer);try{if(y){const{template:e}=n;if(e&&g(e))throw new a("Shared templates are not yet supported");const i=p??new t({attributes:{...e?.prototype.attributes,...n.attributeOverrides},sourceLayer:m});await this._startUpdating({feature:i})}else f.push(N._configureSketchViewModel(this)),p?(s.layer.add(p),await this._startUpdating({feature:p})):await this._startCreating()}finally{w.remove()}const F=i((()=>{for(const t of e.pendingFeatures)s.layer.remove(t),e.removePendingFeature(t)})),_=d((()=>h?.timeZone),(e=>this._featureFormViewModel.timeZone=e),u),M=i((()=>{I(n)&&l.cancelWorkflow({warnIfNoWorkflow:!1})}));this._featureFormHandle&&f.push(this._featureFormHandle),this.addHandles(f,this._handleKeys.beforeCommit),this.addHandles([i((()=>c.fileInfos.removeAll())),r(f),M,F,_],Z)}async _waitForActiveToolCleared(){const e=this.data.viewModel.view;if(null==e?.activeTool)return;const t=new AbortController;this.addHandles(s(t),q),await h((()=>null==e?.activeTool),t.signal),t.abort()}};function J(e,t){let a=null;const s=()=>e.snappingOptions.featureSources,o=()=>(a=new b({layer:e.layer}),s().add(a),a),l=()=>{null!=a&&(s().remove(a),a=n(a))};return r([d((()=>{const e=t.creationInfo?.layer,a=s().find((t=>t.layer===e));return{hasFeatureLayerSource:!!a,enabled:a?.enabled??!1}}),(({hasFeatureLayerSource:e,enabled:t})=>{if(!e)return l();a??=o(),a.enabled=t}),p),i(l)])}function Q(e){const t=e.viewModel.view;if(!t)return[];const a=[];if("3d"===t.type){const r=new _({view:t});a.push(d((()=>e.selectedPendingFeature),((e,t)=>{r.remove(e),r.add(t)})),i((()=>r.destroy())))}const r=new _({view:t,highlightName:V});return a.push(d((()=>e.temporaryHighlightFeature),(e=>{r.removeAll(),r.add(e)})),i((()=>r.destroy()))),a}function X(e,t,a,i){const r=[];return t.forEach(((t,s)=>{if(!t.error){const o=e[s],n=i.get(o)||[];o.attributes[a.objectIdField]=t.objectId,n.forEach((({form:e})=>r.push({feature:o,attachment:e})))}})),r}function Y(e,t,a){const i=[],r=t.globalIdField;return e.forEach(((t,s)=>{e[s].attributes[r]??=m(),(a?.get(t)||[]).forEach((({file:e})=>i.push({feature:t,attachment:{globalId:m(),data:e}})))})),i.length?{addFeatures:e,addAttachments:i}:{addFeatures:e}}e([f()],B.prototype,"createFeatureState",void 0),e([f()],B.prototype,"data",void 0),e([f({constructOnly:!0})],B.prototype,"isNested",void 0),e([f()],B.prototype,"featureFormViewModel",null),e([f()],B.prototype,"hasPendingEdits",null),e([f()],B.prototype,"hasPreviousStep",null),e([f()],B.prototype,"_getDrawMeshHelpMessage",void 0),e([f()],B.prototype,"helpMessage",null),e([f()],B.prototype,"layer",null),e([f()],B.prototype,"parent",null),e([f()],B.prototype,"parentLayer",null),e([f()],B.prototype,"keyboardCancellationEnabled",null),e([f()],B.prototype,"reliesOnOwnerAdminPrivileges",null),e([f()],B.prototype,"shouldShowAttachments",null),e([f()],B.prototype,"shouldAllowAttachmentEditing",null),e([f()],B.prototype,"sketchViewModel",null),e([f()],B.prototype,"availableCreateTools",null),B=N=e([w("esri.widgets.Editor.CreateFeaturesWorkflow")],B);const $=B;export{$ as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import i from"../../core/Error.js";import r from"../../core/Evented.js";import{makeHandle as s}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{abortMaybe as n,removeMaybe as l,destroyMaybe as p}from"../../core/maybe.js";import{throwIfAborted as d,createResolver as c}from"../../core/promiseUtils.js";import{watch as u,on as h,when as w,whenOnce as f,syncAndInitial as m,initial as y,sync as k}from"../../core/reactiveUtils.js";import{property as g}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as v}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as _}from"../../core/support/UpdatingHandles.js";import W from"../../layers/GraphicsLayer.js";import{isEditableLayer as F}from"../../layers/support/editableLayers.js";import{isFeatureLayer as E,getOwningPortalUrl as M}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as I}from"../../portal/support/urlUtils.js";import b from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as C}from"../../views/interactive/snapping/SnappingManager.js";import V from"../../views/interactive/snapping/SnappingOptions.js";import A from"../Attachments/AttachmentsViewModel.js";import U from"./CreateFeaturesWorkflow.js";import O from"./UpdateWorkflow.js";import{isUpdateWorkflow as T,whenEditorLayerView as L}from"./workflowUtils.js";import S from"./support/EditorItem.js";import j from"../FeatureTemplates/FeatureTemplatesViewModel.js";import P from"../Sketch/SketchViewModel.js";import R from"../Spinner/SpinnerViewModel.js";const H="esri.widgets.Editor.EditorViewModel",x=()=>o.getLogger(H);function D(t,e,a){x().error(new i(t,e,a))}function G(t,e){return t?.find((t=>t.layer===e))}let q=class extends r.EventedAccessor{constructor(t){super(t),this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new W({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updatingHandles=new _,this._featureTemplatesViewModelLocked=!1,this.activeWorkflow=null,this._activityQueue=new a,this.editorItems=new a,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new A({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new j({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.layerInfos=null,this.ownSketchViewModel=new P({layer:this._sketchGraphicsLayer}),this.sketchOptions=new b,this.snappingOptions=new V({attributeRulesEnabled:!0}),this.spinnerViewModel=new R,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t&&"create-features"!==this.activeWorkflow?.type){if(t.submit(),!t.submittable||t.pendingSubtypeChoice)return;const e=t.getValues();if(t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0)return}await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([u((()=>{const t=this.view,e=t?.map?.editableLayers,a=t?.allLayerViews,i=a?.filter((t=>!!e?.includes(t.layer)));return[e,i,this.layerInfos]}),(()=>this._updateEditorItems()),m),u((()=>this.hideTemplatesForInactiveLayers),(()=>this.syncFeatureTemplates())),h((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),h((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),h((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),w((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),y),h((()=>this.editorItems),"change",(()=>this._afterEditorItemsChange())),u((()=>[this.canCreate,this.canUpdateVisible]),(()=>this._afterEditorItemsChange())),u((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),m),w((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),h((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const i={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(i);this.startCreateFeaturesWorkflowAtFeatureCreation(i)})),h((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),h((()=>this.sketchViewModel),["create","delete","update"],(t=>{const{activeWorkflow:e}=this,a="update"===e?.type,i=a?e.activeWorkflow?.layer:e?.layer,r=a?e?.activeWorkflow?.parentLayer:void 0,s=`sketch-${t.type}`;this.emit(s,{type:s,detail:t,layer:i,parentLayer:r})}),k),u((()=>this.view),(t=>{if(this._snappingManager=p(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new C({view:t,options:e}),this.ownSketchViewModel.snappingManager=this._snappingManager}),m),u((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),m)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=n(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=l(this._sketchEventListenerHandle)}get activeLeafWorkflow(){const t=this.activeWorkflow;return t&&T(t)?t.activeWorkflow??t:t}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get canUpdateVisible(){return this.editorItems.some((t=>t.supportsUpdateWorkflow&&t.visible))}get featureTemplatesLayers(){const t=new a;for(const e of this.editorItems){const a=e.supportsCreateFeaturesWorkflow&&!e.isTable,i=this.hideTemplatesForInactiveLayers&&!e.visible;a&&!i&&t.push(e.layer)}return t}get featureFormViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeFeatureFormViewModel:"create-features"===t?.type?t.featureFormViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(t){this.sketchOptions.labels=t}get sketchViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeSketchViewModel:"create-features"===t?.type?t.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?.stepId?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(t){this.sketchOptions.tooltips=t}get valueOptions(){return this.sketchOptions.values}set valueOptions(t){this.sketchOptions.values=t}set view(t){this.ownSketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel.associatedLayer)return"viewing-associated-features";if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel.associationId)return"viewing-associated-layers";if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditorItem?.capabilities.update.attributes}get featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditorItem?.capabilities.delete.enabled}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}get snappingManager(){return this._snappingManager}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await f((()=>!this.updating)),!this.canCreate)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();try{await this._cancelWorkflow();const a=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",a),await a.start()}catch(r){this._logErrorAndCancelWorkflow(r)}finally{a.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(t){await f((()=>!this.updating));const e=this._createUpdatingResolver();try{const{initialFeature:e}=t,a=e.sourceLayer=e.layer,r=a?this.findEditorItemForLayer(a):void 0;if(!r?.supportsCreateFeaturesWorkflow)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const s=this._createCreateFeaturesWorkflow({initialFeature:e,layer:r.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",s),await s.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await f((()=>!this.updating)),!this.canUpdate)return void D("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow();this._set("activeWorkflow",t),await t.start()}catch(e){this._logErrorAndCancelWorkflow(e)}finally{t.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await f((()=>!this.updating)),!this.canUpdate)return void D("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("awaiting-update-feature-candidate");e.data.candidates=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureEdit(t){if(await f((()=>!this.updating)),!this.canUpdate)return void D("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("editing-existing-feature");e.data.rootFeature=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():D("editing:unsupported-workflow","Deleting a feature requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveAssociation():D("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){return this.editorItems.find((e=>e.layer===t))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelLocked||(this.featureTemplatesViewModel.layers=this.featureTemplatesLayers.toArray())}zoomTo(t){const e=t??this.sketchViewModel?.updateGraphics.toArray();e&&this.view?.goTo(e)}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}lockFeatureTemplatesViewModel(){return this._featureTemplatesViewModelLocked=!0,s((()=>{this._featureTemplatesViewModelLocked=!1,this.syncFeatureTemplates()}))}async _getEditorItemCandidates(t){const{view:e}=this;if(!e?.map)return[];const{map:a}=e,i=a.editableLayers.toArray()??[],r=a.allTables.toArray().filter(E)??[];return await Promise.allSettled([...i.map((t=>"subtype-group"===t.type?t.loadAll():Promise.resolve())),...r.map((t=>t.load()))]),d(t),[...i.reverse(),...r.reverse()].filter((t=>F(t)&&("mesh"!==t.geometryType||"3d"===e.type))).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}async _updateEditorItems(){n(this._updateItemsTask);const{view:t}=this,a=e((async e=>{if(!t?.map||!t?.allLayerViews)return;const a=await this._getEditorItemCandidates(e);if(!a.length)return void this._drainEditorItems();const i=[],r=[],s=[],{layerInfos:o}=this;for(const l of a){const e=G(o,l),a=await L(t,l).catch((()=>null));(e?i:a?r:s).push(new S({layer:l,layerInfo:e,layerView:a}))}o?.length&&i.sort(((t,e)=>o.findIndex((({layer:e})=>e===t.layer))-o.findIndex((({layer:t})=>t===e.layer))));const n=[...i,...r,...s];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(a.promise),this._updateItemsTask=a}_afterEditorItemsChange(){const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create-features"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===e&&!t.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&D("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force)return this.emit("workflow-cancel"),this._set("activeWorkflow",null),void await e.cancel(t);await e.cancel(t),this._set("activeWorkflow",null)}_createCreateFeaturesWorkflow(t,e){return U.create({viewModel:this,creationInfo:t,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createUpdateWorkflow(t){return O.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),applyEditsAssociationCallback:(t,e,a)=>this._applyEditsAssociation(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let r=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new i("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,r))),r}async _applyEdits(t,e,a){let i=null;const r=t.url?await M(t.url):null,s={returnServiceEditsOption:(!r||!I(r))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const r=await L(a,t).catch((()=>null));return i=await t.applyEdits(e,s),r&&await f((()=>!r.updating)),i})),i}async _applyEditsAssociation(t,e,a){let i=null;const r={globalIdUsed:!0,...a};return await this._queueOperation((async()=>i=await t.applyEdits(e,r))),i}_queueOperation(t){this._activityQueue.push(t);const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>(Array.isArray(t)?t.forEach((t=>this._handleEditsResultError(t))):this._handleEditsResultError(t),t))).catch((a=>{D("editing:operation-error","An error occurred.",{error:a});const i={error:a,retry:()=>(e(i,this.failures),this._queueOperation(t)),cancel:()=>{e(i,this.failures)}};this._set("failures",[...this.failures,i])})).then((()=>{e(t,this._activityQueue)}))}_handleEditsResultError(t){if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:i}=t,r=e.find((t=>!!t.error))||i.find((t=>!!t.error))||a.find((t=>!!t.error));if(r)throw r.error}}_createUpdatingResolver(){const t=c();return this._updatingHandles.addPromise(t.promise),t}_logErrorAndCancelWorkflow(t){const{name:e,message:a,details:i}=t;D(e??"editing:workflow-start-failed",a??void 0,i??t),this._cancelWorkflow({force:!0})}_itemIsSuspended(t){const e=this.findEditorItemForLayer(t);return null!=e&&(!e.visible||e.disabled)}};t([g()],q.prototype,"_snappingManager",void 0),t([g({readOnly:!0})],q.prototype,"activeWorkflow",void 0),t([g()],q.prototype,"activeLeafWorkflow",null),t([g({readOnly:!0})],q.prototype,"_activityQueue",void 0),t([g({readOnly:!0})],q.prototype,"canCreate",null),t([g()],q.prototype,"canCreateVisible",null),t([g({readOnly:!0})],q.prototype,"canUpdate",null),t([g()],q.prototype,"canUpdateVisible",null),t([g()],q.prototype,"featureTemplatesLayers",null),t([g()],q.prototype,"editorItems",void 0),t([g({readOnly:!0})],q.prototype,"failures",void 0),t([g()],q.prototype,"hideTemplatesForInactiveLayers",void 0),t([g({type:A})],q.prototype,"attachmentsViewModel",void 0),t([g()],q.prototype,"featureFormViewModel",null),t([g({type:j})],q.prototype,"featureTemplatesViewModel",void 0),t([g()],q.prototype,"labelOptions",null),t([g()],q.prototype,"layerInfos",void 0),t([g()],q.prototype,"ownSketchViewModel",void 0),t([g()],q.prototype,"sketchOptions",void 0),t([g()],q.prototype,"sketchViewModel",null),t([g({type:V,nonNullable:!0})],q.prototype,"snappingOptions",void 0),t([g()],q.prototype,"spinnerViewModel",void 0),t([g()],q.prototype,"state",null),t([g({readOnly:!0})],q.prototype,"syncing",null),t([g()],q.prototype,"updating",null),t([g()],q.prototype,"tooltipOptions",null),t([g()],q.prototype,"valueOptions",null),t([g()],q.prototype,"view",null),t([g()],q.prototype,"pageStack",void 0),t([g()],q.prototype,"showDiscardEditsPrompt",void 0),t([g()],q.prototype,"_candidateCommitted",void 0),t([g()],q.prototype,"page",null),t([g()],q.prototype,"featureFormDisabled",null),t([g()],q.prototype,"featureFormHasAssociation",null),t([g()],q.prototype,"canGoBack",null),t([g()],q.prototype,"shouldShowDeleteButton",null),t([g()],q.prototype,"hasPendingEdits",null),t([g()],q.prototype,"snappingManager",null),q=t([v(H)],q);const B=q;export{B as default};
5
+ import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import i from"../../core/Error.js";import r from"../../core/Evented.js";import{makeHandle as o}from"../../core/handleUtils.js";import s from"../../core/Logger.js";import{abortMaybe as n,removeMaybe as l,destroyMaybe as p}from"../../core/maybe.js";import{throwIfAborted as d,createResolver as c}from"../../core/promiseUtils.js";import{watch as u,on as h,when as w,whenOnce as f,syncAndInitial as m,initial as y,sync as k}from"../../core/reactiveUtils.js";import{property as g}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as v}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as _}from"../../core/support/UpdatingHandles.js";import W from"../../layers/GraphicsLayer.js";import{isEditableLayer as F}from"../../layers/support/editableLayers.js";import{isFeatureLayer as E,getOwningPortalUrl as M}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as I}from"../../portal/support/urlUtils.js";import b from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as C}from"../../views/interactive/snapping/SnappingManager.js";import V from"../../views/interactive/snapping/SnappingOptions.js";import A from"../Attachments/AttachmentsViewModel.js";import U from"./CreateFeaturesWorkflow.js";import O from"./UpdateWorkflow.js";import{isUpdateWorkflow as T,whenEditorLayerView as L}from"./workflowUtils.js";import S from"./support/EditorItem.js";import j from"../FeatureTemplates/FeatureTemplatesViewModel.js";import P from"../Sketch/SketchViewModel.js";import R from"../Spinner/SpinnerViewModel.js";const G="esri.widgets.Editor.EditorViewModel",H=()=>s.getLogger(G);function x(t,e,a){H().error(new i(t,e,a))}function D(t,e){return t?.find((t=>t.layer===e))}let q=class extends r.EventedAccessor{constructor(t){super(t),this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new W({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updatingHandles=new _,this._featureTemplatesViewModelLocked=!1,this.activeWorkflow=null,this._activityQueue=new a,this.editorItems=new a,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new A({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new j({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.layerInfos=null,this.ownSketchViewModel=new P({layer:this._sketchGraphicsLayer}),this.sketchOptions=new b,this.snappingOptions=new V({attributeRulesEnabled:!0}),this.spinnerViewModel=new R,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t&&"create-features"!==this.activeWorkflow?.type){if(t.submit(),!t.submittable||t.pendingSubtypeChoice)return;const e=t.getValues();if(t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0)return}await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([u((()=>{const t=this.view,e=t?.map?.editableLayers,a=t?.allLayerViews,i=a?.filter((t=>!!e?.includes(t.layer)));return[e,i,this.layerInfos]}),(()=>this._updateEditorItems()),m),u((()=>this.hideTemplatesForInactiveLayers),(()=>this.syncFeatureTemplates())),h((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),h((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),h((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),w((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),y),h((()=>this.editorItems),"change",(()=>this._afterEditorItemsChange())),u((()=>[this.canCreate,this.canUpdateVisible]),(()=>this._afterEditorItemsChange())),u((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),m),w((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),h((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const i={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(i);this.startCreateFeaturesWorkflowAtFeatureCreation(i)})),h((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),h((()=>this.sketchViewModel),["create","delete","update"],(t=>{const{activeWorkflow:e}=this,a="update"===e?.type,i=a?e.activeWorkflow?.layer:e?.layer,r=a?e?.activeWorkflow?.parentLayer:void 0,o=`sketch-${t.type}`;this.emit(o,{type:o,detail:t,layer:i,parentLayer:r})}),k),u((()=>this.view),(t=>{if(this._snappingManager=p(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new C({view:t,options:e}),this.ownSketchViewModel.snappingManager=this._snappingManager}),m),u((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),m)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=n(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=l(this._sketchEventListenerHandle)}get activeLeafWorkflow(){const t=this.activeWorkflow;return t&&T(t)?t.activeWorkflow??t:t}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get canUpdateVisible(){return this.editorItems.some((t=>t.supportsUpdateWorkflow&&t.visible))}get featureTemplatesLayers(){const t=new a;for(const e of this.editorItems){const a=e.supportsCreateFeaturesWorkflow&&!e.isTable,i=this.hideTemplatesForInactiveLayers&&!e.visible;a&&!i&&t.push(e.layer)}return t}get featureFormViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeFeatureFormViewModel:"create-features"===t?.type?t.featureFormViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(t){this.sketchOptions.labels=t}get sketchViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeSketchViewModel:"create-features"===t?.type?t.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?.stepId?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(t){this.sketchOptions.tooltips=t}get valueOptions(){return this.sketchOptions.values}set valueOptions(t){this.sketchOptions.values=t}set view(t){this.ownSketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get canZoomTo(){const t=this.sketchViewModel,e=t?.createGraphic?.geometry?.type;return!(!t?.updateGraphics?.length&&"multipoint"!==e)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel.associatedLayer)return"viewing-associated-features";if("update"===t?.type&&null!=t?.activeWorkflow?.featureFormViewModel.associationId)return"viewing-associated-layers";if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditorItem?.capabilities.update.attributes}get featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditorItem?.capabilities.delete.enabled}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}get snappingManager(){return this._snappingManager}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await f((()=>!this.updating)),!this.canCreate)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();try{await this._cancelWorkflow();const a=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",a),await a.start()}catch(r){this._logErrorAndCancelWorkflow(r)}finally{a.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(t){await f((()=>!this.updating));const e=this._createUpdatingResolver();try{const{initialFeature:e}=t,a=e.sourceLayer=e.layer,r=a?this.findEditorItemForLayer(a):void 0;if(!r?.supportsCreateFeaturesWorkflow)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const o=this._createCreateFeaturesWorkflow({initialFeature:e,layer:r.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",o),await o.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await f((()=>!this.updating)),!this.canUpdate)return void x("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow();this._set("activeWorkflow",t),await t.start()}catch(e){this._logErrorAndCancelWorkflow(e)}finally{t.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await f((()=>!this.updating)),!this.canUpdate)return void x("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("awaiting-update-feature-candidate");e.data.candidates=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async startUpdateWorkflowAtFeatureEdit(t){if(await f((()=>!this.updating)),!this.canUpdate)return void x("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow("editing-existing-feature");e.data.rootFeature=t,this._set("activeWorkflow",e),await e.start()}catch(a){this._logErrorAndCancelWorkflow(a)}finally{e.resolve()}}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():x("editing:unsupported-workflow","Deleting a feature requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveAssociation():x("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){return this.editorItems.find((e=>e.layer===t))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelLocked||(this.featureTemplatesViewModel.layers=this.featureTemplatesLayers.toArray())}zoomTo(t){const e=this.sketchViewModel,a=t??(e?.updateGraphics.length?e?.updateGraphics.toArray():e?.createGraphic);a&&this.view?.goTo(a)}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}lockFeatureTemplatesViewModel(){return this._featureTemplatesViewModelLocked=!0,o((()=>{this._featureTemplatesViewModelLocked=!1,this.syncFeatureTemplates()}))}async _getEditorItemCandidates(t){const{view:e}=this;if(!e?.map)return[];const{map:a}=e,i=a.editableLayers.toArray()??[],r=a.allTables.toArray().filter(E)??[];return await Promise.allSettled([...i.map((t=>"subtype-group"===t.type?t.loadAll():Promise.resolve())),...r.map((t=>t.load()))]),d(t),[...i.reverse(),...r.reverse()].filter((t=>F(t)&&("mesh"!==t.geometryType||"3d"===e.type))).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}async _updateEditorItems(){n(this._updateItemsTask);const{view:t}=this,a=e((async e=>{if(!t?.map||!t?.allLayerViews)return;const a=await this._getEditorItemCandidates(e);if(!a.length)return void this._drainEditorItems();const i=[],r=[],o=[],{layerInfos:s}=this;for(const l of a){const e=D(s,l),a=await L(t,l).catch((()=>null));(e?i:a?r:o).push(new S({layer:l,layerInfo:e,layerView:a}))}s?.length&&i.sort(((t,e)=>s.findIndex((({layer:e})=>e===t.layer))-s.findIndex((({layer:t})=>t===e.layer))));const n=[...i,...r,...o];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(a.promise),this._updateItemsTask=a}_afterEditorItemsChange(){const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create-features"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===e&&!t.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&x("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force)return this.emit("workflow-cancel"),this._set("activeWorkflow",null),void await e.cancel(t);await e.cancel(t),this._set("activeWorkflow",null)}_createCreateFeaturesWorkflow(t,e){return U.create({viewModel:this,creationInfo:t,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createUpdateWorkflow(t){return O.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),applyEditsAssociationCallback:(t,e,a)=>this._applyEditsAssociation(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let r=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new i("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,r))),r}async _applyEdits(t,e,a){let i=null;const r=t.url?await M(t.url):null,o={returnServiceEditsOption:(!r||!I(r))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const r=await L(a,t).catch((()=>null));return i=await t.applyEdits(e,o),r&&await f((()=>!r.updating)),i})),i}async _applyEditsAssociation(t,e,a){let i=null;const r={globalIdUsed:!0,...a};return await this._queueOperation((async()=>i=await t.applyEdits(e,r))),i}_queueOperation(t){this._activityQueue.push(t);const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>(Array.isArray(t)?t.forEach((t=>this._handleEditsResultError(t))):this._handleEditsResultError(t),t))).catch((a=>{x("editing:operation-error","An error occurred.",{error:a});const i={error:a,retry:()=>(e(i,this.failures),this._queueOperation(t)),cancel:()=>{e(i,this.failures)}};this._set("failures",[...this.failures,i])})).then((()=>{e(t,this._activityQueue)}))}_handleEditsResultError(t){if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:i}=t,r=e.find((t=>!!t.error))||i.find((t=>!!t.error))||a.find((t=>!!t.error));if(r)throw r.error}}_createUpdatingResolver(){const t=c();return this._updatingHandles.addPromise(t.promise),t}_logErrorAndCancelWorkflow(t){const{name:e,message:a,details:i}=t;x(e??"editing:workflow-start-failed",a??void 0,i??t),this._cancelWorkflow({force:!0})}_itemIsSuspended(t){const e=this.findEditorItemForLayer(t);return null!=e&&(!e.visible||e.disabled)}};t([g()],q.prototype,"_snappingManager",void 0),t([g({readOnly:!0})],q.prototype,"activeWorkflow",void 0),t([g()],q.prototype,"activeLeafWorkflow",null),t([g({readOnly:!0})],q.prototype,"_activityQueue",void 0),t([g({readOnly:!0})],q.prototype,"canCreate",null),t([g()],q.prototype,"canCreateVisible",null),t([g({readOnly:!0})],q.prototype,"canUpdate",null),t([g()],q.prototype,"canUpdateVisible",null),t([g()],q.prototype,"featureTemplatesLayers",null),t([g()],q.prototype,"editorItems",void 0),t([g({readOnly:!0})],q.prototype,"failures",void 0),t([g()],q.prototype,"hideTemplatesForInactiveLayers",void 0),t([g({type:A})],q.prototype,"attachmentsViewModel",void 0),t([g()],q.prototype,"featureFormViewModel",null),t([g({type:j})],q.prototype,"featureTemplatesViewModel",void 0),t([g()],q.prototype,"labelOptions",null),t([g()],q.prototype,"layerInfos",void 0),t([g()],q.prototype,"ownSketchViewModel",void 0),t([g()],q.prototype,"sketchOptions",void 0),t([g()],q.prototype,"sketchViewModel",null),t([g({type:V,nonNullable:!0})],q.prototype,"snappingOptions",void 0),t([g()],q.prototype,"spinnerViewModel",void 0),t([g()],q.prototype,"state",null),t([g({readOnly:!0})],q.prototype,"syncing",null),t([g()],q.prototype,"updating",null),t([g()],q.prototype,"tooltipOptions",null),t([g()],q.prototype,"valueOptions",null),t([g()],q.prototype,"view",null),t([g()],q.prototype,"canZoomTo",null),t([g()],q.prototype,"pageStack",void 0),t([g()],q.prototype,"showDiscardEditsPrompt",void 0),t([g()],q.prototype,"_candidateCommitted",void 0),t([g()],q.prototype,"page",null),t([g()],q.prototype,"featureFormDisabled",null),t([g()],q.prototype,"featureFormHasAssociation",null),t([g()],q.prototype,"canGoBack",null),t([g()],q.prototype,"shouldShowDeleteButton",null),t([g()],q.prototype,"hasPendingEdits",null),t([g()],q.prototype,"snappingManager",null),q=t([v(G)],q);const B=q;export{B as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{abortMaybe as r}from"../../core/maybe.js";import{createResolver as s,onAbort as n,createAbortError as l,throwIfAborted as d,debounce as c}from"../../core/promiseUtils.js";import p from"../../core/Queue.js";import{whenOnce as u,when as h,watch as w,sync as f}from"../../core/reactiveUtils.js";import{last as g}from"../../core/SetUtils.js";import{property as m}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as k}from"../../core/accessorSupport/decorators/subclass.js";import{getAllStandardFeatureTemplatesForLayer as v}from"../../editing/templateUtils.js";import{isEditableLayer as y}from"../../layers/support/editableLayers.js";import{isFeatureLayer as W,isSubtypeSublayer as b,isSubtypeGroupLayer as C,isTable as _}from"../../layers/support/layerUtils.js";import{createFeatureServices as M}from"../../rest/featureService/utils.js";import A from"../../views/draw/support/HighlightHelper.js";import{ViewEventPriorities as F}from"../../views/input/InputManager.js";import S from"../../views/interactive/sketch/SketchOptions.js";import{temporaryHighlightName as I}from"../../views/support/HighlightDefaults.js";import j from"./CreateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as E}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as U}from"./UpdateRecordWorkflow.js";import P from"./UpdateWorkflowData.js";import L from"./Workflow.js";import{createWorkflowSteps as V,fetchCandidates as x}from"./workflowUtils.js";import{isGraphicForRelatableFeatureSupportedLayer as O}from"../Feature/support/featureUtils.js";var R;const T="esri.widgets.Editor.UpdateWorkflow",H=()=>o.getLogger(T);let D=R=class extends L{constructor(e){super(e),this._workflowStack=new p(g),this._sketchStack=new p(g),this.data=void 0,this.type="update"}get activeEditorItem(){return this.activeWorkflow?.data.editorItem??void 0}get activeFeatureFormViewModel(){return this.activeWorkflow?.featureFormViewModel}get activeSketchViewModel(){return this._sketchStack.peek()?.viewModel}get canDeleteAssociation(){const{activeFeatureFormViewModel:e}=this;if(!this.activeWorkflow||!this.data.viewModel.view||!e)return!1;const{activeAssociation:t,feature:a}=e;return!(!t||!a?.sourceLayer||!W(a?.sourceLayer)&&!b(a?.sourceLayer))}get activeWorkflow(){return this._workflowStack.last()}get updating(){return this._updatingHandles.updating||!!this.activeWorkflow?.updating}get hasPreviousStep(){const e=this.activeWorkflow?.featureFormViewModel;return this._stepIndex>0||this.nestedWorkflowCount>1||null!=e?.relationshipId||"view"!==this.data.viewModel.attachmentsViewModel.mode||null!=e?.associationId||null!=e?.associatedLayer}get hasUpdatableCandidates(){const{candidates:e,viewModel:t}=this.data;return e.some((({layer:e})=>t.findEditorItemForLayer(e)?.supportsUpdateWorkflow))}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return!!this.activeEditorItem?.capabilities.attachments.enabled}get shouldAllowAttachmentEditing(){return!!this.activeEditorItem?.capabilities.update.attachments.enabled}get hasPendingEdits(){return Array.from(this._workflowStack).some((e=>e.hasPendingEdits))}get helpMessage(){return this.activeWorkflow?.helpMessage?this.activeWorkflow.helpMessage:"awaiting-feature-to-update"===this.stepId?"select":void 0}get reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return!!this.activeEditorItem?.hasInvalidFormTemplate}async back(e=()=>Promise.resolve(!0)){const{activeWorkflow:t}=this,a=t?.featureFormViewModel;if(null==a?.relationshipId)if(null==a?.associatedLayer)if(null==a?.associationId)if(t){if(t.hasPendingEdits){if(!await e())return}t.hasPreviousStep?await t.previous({cancelCurrentStep:!0}):await this.cancelActiveWorkflow({force:!0})}else this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0});else a.associationId=null;else a.associatedLayer=null;else a.relationshipId=null}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflow()}async commit(){await this._drainWorkflowStack((e=>e.commit())),await super.commit()}static create(e){const{viewModel:t,snappingManager:a,startAt:i,addAttachmentsCallback:o,applyEditsCallback:r,applyEditsAssociationCallback:s}=e,n=e.sketchOptions??new S,l=new R({data:new P({addAttachmentsCallback:o,applyEditsCallback:r,applyEditsAssociationCallback:s,sketchOptions:n,snappingManager:a,viewModel:t}),onCommit:async()=>{}});return l._set("steps",this._createWorkflowSteps(l,i)),l}async save(){this.nestedWorkflowCount>1?(await(this.activeWorkflow?.commit()),await this._popWorkflow()):await this.commit()}async startCreatingRelatedRecord(e){try{const t=await this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:t})}}async startUpdating(e,t){try{const a=await this._createNestedUpdateWorkflow(e,t);await this._pushWorkflow(a)}catch(i){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:i})}}async deleteActiveFeature(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");G(e)?await e.deleteAndCommit():await e.cancel(),1===this.nestedWorkflowCount?await this.reset():(await this._popWorkflow(),await this._returnToPageWithContent())}async deleteActiveAssociation(){if(!this.canDeleteAssociation)throw new a("editor:nothing-to-delete","There is no association to delete");await this._deleteActiveAssociation(),await this._popWorkflow(),await this._returnToPageWithContent()}async cancelAll(){await this._drainWorkflowStack((e=>e.cancel({force:!0})))}async _deleteActiveAssociation(){const{activeFeatureFormViewModel:e,data:t}=this,{activeAssociation:i,feature:o}=e,{applyEditsAssociationCallback:r}=t,{sourceLayer:s}=o,n=b(s)&&s.parent?s.parent:s,l=M([n]),d=l.values().next().value?.featureService;if(!d)throw new a("editor:failed-to-delete-association","Could not retrieve feature service needed to delete association");await(d?.load());const{utilityNetwork:c}=e.allAssociationInputs[0],p=c?.generateDeleteAssociations([i]);if(!p)throw new a("editor:failed-to-delete-association","Could not create payload needed to delete association");const u=c?.gdbVersion??void 0;await r(d,[p],{gdbVersion:u})}async _returnToPageWithContent(){const{activeFeatureFormViewModel:e}=this;if(!e?.activeAssociationInput)return;const{activeAssociationInput:t,associationId:a}=e;await t.refresh(),t.associatedLayer&&!t.associatedFeatures?.length&&(e.associatedLayer=null),null==a||t.associatedFeatureInfos.size||(e.associationId=null)}async _createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:i,applyEditsCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data;if(!y(t))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const l=this._getCreationInfoForNestedCreateFeaturesWorkflow(e),d=l.template||l.initialFeature?"creating-features":"awaiting-feature-creation-info",c="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0;return j.create({addAttachmentsCallback:i,applyEditsCallback:o,creationInfo:l,isNested:!0,parent:c,sketchOptions:r,snappingManager:s,startAt:d,viewModel:n})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:i}=e;if(!y(i)||C(i))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const o={layer:i,maxFeatures:1},r=this._makeRelatedRecordAttributes(e),s=v(i);return s?.length>0?(o.attributeOverrides=r,1===s.length&&(o.template=s[0])):o.initialFeature=new t({sourceLayer:i,attributes:r}),o}async _createNestedUpdateWorkflow(e,t){const a=_(e.sourceLayer)?U:E,{applyEditsCallback:i,applyEditsAssociationCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data,l="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,d=await a.create({association:t,feature:e,parent:l,sketchOptions:r,snappingManager:s,viewModel:n,applyEdits:i,applyEditsAssociation:o,featureFormCallbacks:{addRelatedRecord:async e=>await this.startCreatingRelatedRecord(e),editRelatedRecord:async({relatedFeature:e})=>await this.startUpdating(e),selectAssociatedFeature:async({feature:e,association:t})=>await this.startUpdating(e,t)}});return await u((()=>!d.updating)),d}async _drainWorkflowStack(e){const t=this._workflowStack,a=[];for(;t.length>0;){const i=t.pop();this._sketchStack.pop();const o=e(i).then((()=>i.destroy()));this._updatingHandles.addPromise(o),a.push(o)}await Promise.all(a)}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:a,relationshipId:i}=e;if(!O(t))return;const o=a.relationships?.find((e=>e.id===i));if(!o)return void q("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the destination layer.");if("origin"===o.role)return void q("unsupported-role","Creating new related records in the 'origin' table of a relationship is not yet supported");const r=t.sourceLayer;o.relatedTableId!==r.layerId&&q("invalid-argument-combination","The given parent feature does not belong to the relationship designated by the given relationship ID.");const s=r.relationships?.find((e=>e.id===i));if(!s)return void q("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=N(r,s),l=t.getAttribute(n);l||q("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field.");const d=N(a,o);return{[d]:l}}async _popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop();const e=await this._reconcileWorkflowStack();if(e.failureCount>0)throw new a("editor:next-workflow-failed","Popped the top workflow, but the next workflow in the stack failed to activate",e)}async _pushWorkflow(e){const t=this._workflowRequiresSketchViewModel(e);this.activeWorkflow?.exit({removeSketchHandles:t});const i=this._sketchStack,o=await(e?.start()),r=i.peek();o?(r?.exit(),i.push(o)):i.push(this._cloneSketchController(r)),this._workflowStack.push(e);const s=await this._reconcileWorkflowStack();if(s.failureCount>0)throw new a("editor:failed-to-start-updating-feature","Failed to enter the provided workflow.",s)}async _reconcileWorkflowStack(){const e=this._workflowStack,t=this._sketchStack;try{const a=e.peek();return await(a?.enter()),await(t.peek()?.enter()),{activeWorkflow:a,failureCount:0}}catch(a){e.pop().destroy(),t.pop();const{activeWorkflow:i,failureCount:o}=await this._reconcileWorkflowStack();return{activeWorkflow:i,failureCount:o+1}}}_cloneSketchController(e){return{enter:e?.enter??(async()=>{}),exit:e?.exit??(async()=>{}),viewModel:e?.viewModel}}_workflowRequiresSketchViewModel(e){const{type:t}=e;return"update-feature"===t||"create-features"===t&&!_(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:o}=e;return V(["awaiting-feature-to-update","awaiting-update-feature-candidate","editing-existing-feature","adding-attachment","editing-attachment"],t,{"awaiting-feature-to-update":()=>({id:"awaiting-feature-to-update",async setUp(){const{spinnerViewModel:t}=o.viewModel,a=o.viewModel.view;a.activeTool=null;let c=null;e.addHandles(i((()=>{c=r(c)})),this.id),o.rootFeature=null,o.candidates=[];const p=a.on("immediate-click",(async i=>{const r=s();e._updatingHandles.addPromise(r.promise);try{t.location=i.mapPoint,t.visible=!0,c?.abort();const{editorItems:r}=o.viewModel;c=new AbortController;const s=await i.async((()=>new Promise(((e,t)=>{n(c?.signal,(()=>t(l()))),e(x(r,a,i,c?.signal))}))));if(d(c),o.candidates=s.filter((e=>"fulfilled"===e.status)).flatMap((e=>e.value)).filter((e=>!e.isAggregate)),t.visible=1===o.candidates.length,0===o.candidates.length)return;i.stopPropagation(),1===o.candidates.length?(o.rootFeature=o.candidates[0],e.go("editing-existing-feature").catch((()=>{})).then((()=>t.visible=!1))):e.next()}finally{r.resolve()}}),F.TOOL),u=h((()=>null!=a.activeTool),(()=>e.cancel({force:!0})),{once:!0});a.focus(),e.addHandles([p,u],this.id)},async tearDown(){0===o.candidates.length&&(o.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){o.rootFeature=null;const{view:t}=o.viewModel;if(!t)return;const a=new A({view:t,highlightName:I});e.addHandles([w((()=>o.rootFeature),((e,t)=>{a.remove(t),a.add(e)}),f),i((()=>a.removeAll()))],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){const{rootFeature:t,viewModel:i}=e.data;if(!t)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until the root feature is defined");await e.startUpdating(t),i.spinnerViewModel.visible=!1;const o=c((async()=>{await u((()=>!e.updating)),e.previous()}));e.addHandles([w((()=>e.nestedWorkflowCount),((e,t)=>{0===e&&0!==t&&o()}),f)],this.id)},async tearDown(){await e.cancelAll(),e.removeHandles(this.id)}}),"adding-attachment":()=>({id:"adding-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}})})}};function N(e,{keyField:t}){return e.getField(t)?.name??t}e([m()],D.prototype,"activeEditorItem",null),e([m()],D.prototype,"activeFeatureFormViewModel",null),e([m()],D.prototype,"activeSketchViewModel",null),e([m()],D.prototype,"canDeleteAssociation",null),e([m()],D.prototype,"activeWorkflow",null),e([m()],D.prototype,"updating",null),e([m()],D.prototype,"data",void 0),e([m()],D.prototype,"hasPreviousStep",null),e([m()],D.prototype,"hasUpdatableCandidates",null),e([m()],D.prototype,"nestedWorkflowCount",null),e([m()],D.prototype,"shouldShowAttachments",null),e([m()],D.prototype,"shouldAllowAttachmentEditing",null),e([m()],D.prototype,"hasPendingEdits",null),e([m()],D.prototype,"helpMessage",null),e([m()],D.prototype,"reliesOnOwnerAdminPrivileges",null),e([m()],D.prototype,"hasInvalidFormTemplate",null),D=R=e([k(T)],D);const q=(e,t)=>H().warn(`editor:${e}`,t,"The create operation will be allowed to proceed, but the resulting feature may not be related to the given parent feature."),G=e=>!!e&&/update-/.test(e.type),z=D;export{z as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as i}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{abortMaybe as r}from"../../core/maybe.js";import{createResolver as s,onAbort as n,createAbortError as l,throwIfAborted as d,debounce as c}from"../../core/promiseUtils.js";import p from"../../core/Queue.js";import{whenOnce as u,when as w,watch as h,sync as f}from"../../core/reactiveUtils.js";import{last as g}from"../../core/SetUtils.js";import{property as m}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as k}from"../../core/accessorSupport/decorators/subclass.js";import{getAllStandardFeatureTemplatesForLayer as v}from"../../editing/templateUtils.js";import{isEditableLayer as y}from"../../layers/support/editableLayers.js";import{isFeatureLayer as W,isSubtypeSublayer as b,isSubtypeGroupLayer as C,isTable as _}from"../../layers/support/layerUtils.js";import{createFeatureServices as M}from"../../rest/featureService/utils.js";import A from"../../views/draw/support/HighlightHelper.js";import{ViewEventPriorities as S}from"../../views/input/InputManager.js";import F from"../../views/interactive/sketch/SketchOptions.js";import{temporaryHighlightName as I}from"../../views/support/HighlightDefaults.js";import j from"./CreateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as E}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as U}from"./UpdateRecordWorkflow.js";import P from"./UpdateWorkflowData.js";import L from"./Workflow.js";import{createWorkflowSteps as V,fetchCandidates as x}from"./workflowUtils.js";import{findUtilityNetwork as O,isGraphicForRelatableFeatureSupportedLayer as R}from"../Feature/support/featureUtils.js";var T;const H="esri.widgets.Editor.UpdateWorkflow",D=()=>o.getLogger(H);let N=T=class extends L{constructor(e){super(e),this._workflowStack=new p(g),this._sketchStack=new p(g),this.data=void 0,this.type="update"}get activeEditorItem(){return this.activeWorkflow?.data.editorItem??void 0}get activeFeatureFormViewModel(){return this.activeWorkflow?.featureFormViewModel}get activeSketchViewModel(){return this._sketchStack.peek()?.viewModel}get canDeleteAssociation(){const{activeFeatureFormViewModel:e}=this;if(!this.activeWorkflow||!this.data.viewModel.view?.map||!e)return!1;const{activeAssociation:t,feature:a}=e;return!(!t||!a?.sourceLayer||!W(a?.sourceLayer)&&!b(a?.sourceLayer))}get activeWorkflow(){return this._workflowStack.last()}get updating(){return this._updatingHandles.updating||!!this.activeWorkflow?.updating}get hasPreviousStep(){const e=this.activeWorkflow?.featureFormViewModel;return this._stepIndex>0||this.nestedWorkflowCount>1||null!=e?.relationshipId||"view"!==this.data.viewModel.attachmentsViewModel.mode||null!=e?.associationId||null!=e?.associatedLayer}get hasUpdatableCandidates(){const{candidates:e,viewModel:t}=this.data;return e.some((({layer:e})=>t.findEditorItemForLayer(e)?.supportsUpdateWorkflow))}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return!!this.activeEditorItem?.capabilities.attachments.enabled}get shouldAllowAttachmentEditing(){return!!this.activeEditorItem?.capabilities.update.attachments.enabled}get hasPendingEdits(){return Array.from(this._workflowStack).some((e=>e.hasPendingEdits))}get helpMessage(){return this.activeWorkflow?.helpMessage?this.activeWorkflow.helpMessage:"awaiting-feature-to-update"===this.stepId?"select":void 0}get reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return!!this.activeEditorItem?.hasInvalidFormTemplate}async back(e=()=>Promise.resolve(!0)){const{activeWorkflow:t}=this,a=t?.featureFormViewModel;if(null==a?.relationshipId)if(null==a?.associatedLayer)if(null==a?.associationId)if("create-features"===t?.type&&t.hasPreviousStep)await t.previous({cancelCurrentStep:!0});else if(t){if(t.hasPendingEdits){if(!await e())return}t.hasPreviousStep?await t.previous({cancelCurrentStep:!0}):await this.cancelActiveWorkflow({force:!0})}else this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0});else a.associationId=null;else a.associatedLayer=null;else a.relationshipId=null}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflow()}async commit(){await this._drainWorkflowStack((e=>e.commit())),await super.commit()}static create(e){const{viewModel:t,snappingManager:a,startAt:i,addAttachmentsCallback:o,applyEditsCallback:r,applyEditsAssociationCallback:s}=e,n=e.sketchOptions??new F,l=new T({data:new P({addAttachmentsCallback:o,applyEditsCallback:r,applyEditsAssociationCallback:s,sketchOptions:n,snappingManager:a,viewModel:t}),onCommit:async()=>{}});return l._set("steps",this._createWorkflowSteps(l,i)),l}async save(){this.nestedWorkflowCount>1?(await(this.activeWorkflow?.commit()),await this._popWorkflow()):await this.commit()}async startCreatingRelatedRecord(e){try{const t=await this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:t})}}async startUpdating(e,t){try{const a=await this._createNestedUpdateWorkflow(e,t);await this._pushWorkflow(a)}catch(i){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:i})}}async deleteActiveFeature(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");z(e)?await e.deleteAndCommit():await e.cancel(),1===this.nestedWorkflowCount?await this.reset():(await this._popWorkflow(),await this._returnToPageWithContent())}async deleteActiveAssociation(){if(!this.canDeleteAssociation)throw new a("editor:nothing-to-delete","There is no association to delete");await this._deleteActiveAssociation(),await this._popWorkflow(),await this._returnToPageWithContent()}async cancelAll(){await this._drainWorkflowStack((e=>e.cancel({force:!0})))}async _deleteActiveAssociation(){const{activeFeatureFormViewModel:e,data:t}=this,{activeAssociation:i,feature:o}=e,{applyEditsAssociationCallback:r,viewModel:s}=t,{sourceLayer:n}=o,l=b(n)&&n.parent?n.parent:n,d=M([l]),c=d.values().next().value?.featureService;if(!c)throw new a("editor:failed-to-delete-association","Could not retrieve feature service needed to delete association");await(c?.load());const p=s.view.map,u=O(p,l),w=u?.generateDeleteAssociations([i]);if(!w)throw new a("editor:failed-to-delete-association","Could not create payload needed to delete association");const h=u?.gdbVersion??void 0;await r(c,[w],{gdbVersion:h})}async _returnToPageWithContent(){const{activeFeatureFormViewModel:e}=this;if(!e?.activeAssociationInput)return;const{activeAssociationInput:t,associationId:a}=e;await t.refresh(),t.associatedLayer&&!t.associatedFeatures?.length&&(e.associatedLayer=null),null==a||t.associatedFeatureInfos.size||(e.associationId=null)}async _createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:i,applyEditsCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data;if(!y(t))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const l=this._getCreationInfoForNestedCreateFeaturesWorkflow(e),d=l.template||l.initialFeature?"creating-features":"awaiting-feature-creation-info",c="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0;return j.create({addAttachmentsCallback:i,applyEditsCallback:o,creationInfo:l,isNested:!0,parent:c,sketchOptions:r,snappingManager:s,startAt:d,viewModel:n})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:i}=e;if(!y(i)||C(i))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const o={layer:i,maxFeatures:1},r=this._makeRelatedRecordAttributes(e),s=v(i);return s?.length>0?(o.attributeOverrides=r,1===s.length&&(o.template=s[0])):o.initialFeature=new t({sourceLayer:i,attributes:r}),o}async _createNestedUpdateWorkflow(e,t){const a=_(e.sourceLayer)?U:E,{applyEditsCallback:i,applyEditsAssociationCallback:o,sketchOptions:r,snappingManager:s,viewModel:n}=this.data,l="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,d=await a.create({association:t,feature:e,parent:l,sketchOptions:r,snappingManager:s,viewModel:n,applyEdits:i,applyEditsAssociation:o,featureFormCallbacks:{addRelatedRecord:async e=>await this.startCreatingRelatedRecord(e),editRelatedRecord:async({relatedFeature:e})=>await this.startUpdating(e),selectAssociatedFeature:async({feature:e,association:t})=>await this.startUpdating(e,t)}});return await u((()=>!d.updating)),d}async _drainWorkflowStack(e){const t=this._workflowStack,a=[];for(;t.length>0;){const i=t.pop();this._sketchStack.pop();const o=e(i).then((()=>i.destroy()));this._updatingHandles.addPromise(o),a.push(o)}await Promise.all(a)}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:a,relationshipId:i}=e;if(!R(t))return;const o=a.relationships?.find((e=>e.id===i));if(!o)return void G("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the destination layer.");if("origin"===o.role)return void G("unsupported-role","Creating new related records in the 'origin' table of a relationship is not yet supported");const r=t.sourceLayer;o.relatedTableId!==r.layerId&&G("invalid-argument-combination","The given parent feature does not belong to the relationship designated by the given relationship ID.");const s=r.relationships?.find((e=>e.id===i));if(!s)return void G("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=q(r,s),l=t.getAttribute(n);l||G("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field.");const d=q(a,o);return{[d]:l}}async _popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop();const e=await this._reconcileWorkflowStack();if(e.failureCount>0)throw new a("editor:next-workflow-failed","Popped the top workflow, but the next workflow in the stack failed to activate",e)}async _pushWorkflow(e){const t=this._workflowRequiresSketchViewModel(e);this.activeWorkflow?.exit({removeSketchHandles:t});const i=this._sketchStack,o=await(e?.start()),r=i.peek();o?(r?.exit(),i.push(o)):i.push(this._cloneSketchController(r)),this._workflowStack.push(e);const s=await this._reconcileWorkflowStack();if(s.failureCount>0)throw new a("editor:failed-to-start-updating-feature","Failed to enter the provided workflow.",s)}async _reconcileWorkflowStack(){const e=this._workflowStack,t=this._sketchStack;try{const a=e.peek();return await(a?.enter()),await(t.peek()?.enter()),{activeWorkflow:a,failureCount:0}}catch(a){e.pop().destroy(),t.pop();const{activeWorkflow:i,failureCount:o}=await this._reconcileWorkflowStack();return{activeWorkflow:i,failureCount:o+1}}}_cloneSketchController(e){return{enter:e?.enter??(async()=>{}),exit:e?.exit??(async()=>{}),viewModel:e?.viewModel}}_workflowRequiresSketchViewModel(e){const{type:t}=e;return"update-feature"===t||"create-features"===t&&!_(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:o}=e;return V(["awaiting-feature-to-update","awaiting-update-feature-candidate","editing-existing-feature","adding-attachment","editing-attachment"],t,{"awaiting-feature-to-update":()=>({id:"awaiting-feature-to-update",async setUp(){const{spinnerViewModel:t}=o.viewModel,a=o.viewModel.view;a.activeTool=null;let c=null;e.addHandles(i((()=>{c=r(c)})),this.id),o.rootFeature=null,o.candidates=[];const p=a.on("immediate-click",(async i=>{const r=s();e._updatingHandles.addPromise(r.promise);try{t.location=i.mapPoint,t.visible=!0,c?.abort();const{editorItems:r}=o.viewModel;c=new AbortController;const s=await i.async((()=>new Promise(((e,t)=>{n(c?.signal,(()=>t(l()))),e(x(r,a,i,c?.signal))}))));if(d(c),o.candidates=s.filter((e=>"fulfilled"===e.status)).flatMap((e=>e.value)).filter((e=>!e.isAggregate)),t.visible=1===o.candidates.length,0===o.candidates.length)return;i.stopPropagation(),1===o.candidates.length?(o.rootFeature=o.candidates[0],e.go("editing-existing-feature").catch((()=>{})).then((()=>t.visible=!1))):e.next()}finally{r.resolve()}}),S.TOOL),u=w((()=>null!=a.activeTool),(()=>e.cancel({force:!0})),{once:!0});a.focus(),e.addHandles([p,u],this.id)},async tearDown(){0===o.candidates.length&&(o.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){o.rootFeature=null;const{view:t}=o.viewModel;if(!t)return;const a=new A({view:t,highlightName:I});e.addHandles([h((()=>o.rootFeature),((e,t)=>{a.remove(t),a.add(e)}),f),i((()=>a.removeAll()))],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){const{rootFeature:t,viewModel:i}=e.data;if(!t)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until the root feature is defined");await e.startUpdating(t),i.spinnerViewModel.visible=!1;const o=c((async()=>{await u((()=>!e.updating)),e.previous()}));e.addHandles([h((()=>e.nestedWorkflowCount),((e,t)=>{0===e&&0!==t&&o()}),f)],this.id)},async tearDown(){await e.cancelAll(),e.removeHandles(this.id)}}),"adding-attachment":()=>({id:"adding-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){o.viewModel.attachmentsViewModel.mode="view"}})})}};function q(e,{keyField:t}){return e.getField(t)?.name??t}e([m()],N.prototype,"activeEditorItem",null),e([m()],N.prototype,"activeFeatureFormViewModel",null),e([m()],N.prototype,"activeSketchViewModel",null),e([m()],N.prototype,"canDeleteAssociation",null),e([m()],N.prototype,"activeWorkflow",null),e([m()],N.prototype,"updating",null),e([m()],N.prototype,"data",void 0),e([m()],N.prototype,"hasPreviousStep",null),e([m()],N.prototype,"hasUpdatableCandidates",null),e([m()],N.prototype,"nestedWorkflowCount",null),e([m()],N.prototype,"shouldShowAttachments",null),e([m()],N.prototype,"shouldAllowAttachmentEditing",null),e([m()],N.prototype,"hasPendingEdits",null),e([m()],N.prototype,"helpMessage",null),e([m()],N.prototype,"reliesOnOwnerAdminPrivileges",null),e([m()],N.prototype,"hasInvalidFormTemplate",null),N=T=e([k(H)],N);const G=(e,t)=>D().warn(`editor:${e}`,t,"The create operation will be allowed to proceed, but the resulting feature may not be related to the given parent feature."),z=e=>!!e&&/update-/.test(e.type),Q=N;export{Q as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as o}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import l from"../support/SnappingControls/VisibleElements.js";let n=class extends e{constructor(o){super(o),this.createFeaturesSection=!0,this.directionModePicker=!1,this.editFeaturesSection=!0,this.flow=!0,this.labelsToggle=!0,this.settingsMenu=!0,this.snappingControls=!0,this.snappingControlsElements=new l,this.tooltipsToggle=!0,this.undoRedoButtons=!0,this.sketch=!0}};o([t({type:Boolean,nonNullable:!0})],n.prototype,"createFeaturesSection",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"directionModePicker",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"editFeaturesSection",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"flow",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"labelsToggle",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"settingsMenu",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"snappingControls",void 0),o([t({type:l,nonNullable:!0})],n.prototype,"snappingControlsElements",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"tooltipsToggle",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"undoRedoButtons",void 0),o([t({type:Boolean,nonNullable:!0})],n.prototype,"sketch",void 0),n=o([s("esri.widgets.Editor.VisibleElements")],n);const r=n;export{r as default};
5
+ import{_ as o}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import n from"../support/SnappingControls/VisibleElements.js";let l=class extends e{constructor(o){super(o),this.createFeaturesSection=!0,this.directionModePicker=!1,this.editFeaturesSection=!0,this.flow=!0,this.labelsToggle=!0,this.settingsMenu=!0,this.snappingControls=!0,this.snappingControlsElements=new n,this.tooltipsToggle=!0,this.undoRedoButtons=!0,this.sketch=!0,this.zoomToButton=!0}};o([t({type:Boolean,nonNullable:!0})],l.prototype,"createFeaturesSection",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"directionModePicker",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"editFeaturesSection",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"flow",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"labelsToggle",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"settingsMenu",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"snappingControls",void 0),o([t({type:n,nonNullable:!0})],l.prototype,"snappingControlsElements",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"tooltipsToggle",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"undoRedoButtons",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"sketch",void 0),o([t({type:Boolean,nonNullable:!0})],l.prototype,"zoomToButton",void 0),l=o([s("esri.widgets.Editor.VisibleElements")],l);const p=l;export{p as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{isSome as e}from"../../../core/arrayUtils.js";import{getDisplayFieldName as t}from"../../../layers/support/fieldUtils.js";import{loadPanelContentComponents as r,PanelContentSection as l,PanelContent as o}from"./PanelContent.js";import{ItemList as a}from"../../support/ItemList.js";import"../../support/widgetUtils.js";import{tsx as s}from"../../support/jsxFactory.js";const i=()=>r();function n({editorItems:t,filterText:r,id:i,messagesTemplates:n,onFilterTextChange:m,onSelectFeature:c,workflow:u}){const f=new Map,p=u.data.candidates;let y=0;p.map((e=>({label:d(e),id:e.attributes[e.layer.objectIdField],data:e}))).filter((({label:e,data:l})=>{const o=r.toLowerCase(),{title:a}=l.layer,s=t.find((e=>e.layer===l.sourceLayer));return s?s.supportsUpdateWorkflow&&(!o||e?.toLowerCase().includes(o)||a?.toLowerCase().includes(o)):null})).filter(e).forEach((e=>{y++;const t=e.data.layer;f.has(t)?f.get(t)?.items.push(e):f.set(t,{id:`${t.id}`,label:t.title??"",items:[e]})}));const h=t.toArray().map((({layer:e})=>f.get(e))).filter(e),I=y>10||r.length>0;return s(o,{key:"feature-list"},s(l,null,a({enableListScroll:!1,filterEnabled:I,filterText:r,id:i,items:h,messages:{filterPlaceholder:n.filterPlaceholder,noItems:n.noItems,noMatches:n.noMatches},onFilterChange:e=>m(e),onItemMouseEnter:e=>c(e.data),onItemMouseLeave:()=>c(null),onItemSelect:e=>c(e.data,!0)})))}function d(e){const r=e.layer;if(!r)return null;const l=r.fieldsIndex.get(r.objectIdField),o=l.alias||l.name,{attributes:a}=e,s=t(r);return s&&a[s]&&`${a[s]}`||`${o}: ${a[l.name]}`}export{n as FeatureList,i as loadFeatureListComponents};
5
+ import{isSome as e}from"../../../core/arrayUtils.js";import{getDisplayFieldName as t}from"../../../layers/support/fieldUtils.js";import{loadPanelContentComponents as o,PanelContentSection as r,PanelContent as a}from"./PanelContent.js";import{loadCalciteComponents as s}from"../../support/componentsUtils.js";import{ItemList as l}from"../../support/ItemList.js";import"../../support/widgetUtils.js";import{tsx as n}from"../../support/jsxFactory.js";const i=()=>Promise.all([o(),s({action:()=>import("@esri/calcite-components/dist/components/calcite-action")})]);function c({editorItems:t,filterText:o,id:s,messagesTemplates:i,onFilterTextChange:c,onSelectFeature:p,onZoomTo:u,workflow:f,editorMessages:y}){const j=new Map,I=f.data.candidates;let b=0;I.map((e=>({label:m(e),id:e.attributes[e.layer.objectIdField],data:e}))).filter((({label:e,data:r})=>{const a=o.toLowerCase(),{title:s}=r.layer,l=t.find((e=>e.layer===r.sourceLayer));return l?l.supportsUpdateWorkflow&&(!a||e?.toLowerCase().includes(a)||s?.toLowerCase().includes(a)):null})).filter(e).forEach((e=>{b++;const t=e.data.layer;j.has(t)?j.get(t)?.items.push(e):j.set(t,{id:`${t.id}`,label:t.title??"",items:[e]})}));const g=t.toArray().map((({layer:e})=>j.get(e))).filter(e),h=b>10||o.length>0;return n(a,{key:"feature-list"},n(r,null,l({enableListScroll:!1,filterEnabled:h,filterText:o,id:s,items:g,messages:{filterPlaceholder:i.filterPlaceholder,noItems:i.noItems,noMatches:i.noMatches},onFilterChange:e=>c(e),onItemMouseEnter:e=>p(e.data),onItemMouseLeave:()=>p(null),onItemSelect:e=>p(e.data,!0),renderItemActionEnd:e=>d(e.data,u,y.zoomTo)})))}function m(e){const o=e.layer;if(!o)return null;const r=o.fieldsIndex.get(o.objectIdField),a=r.alias||r.name,{attributes:s}=e,l=t(o);return l&&s[l]&&`${s[l]}`||`${a}: ${s[r.name]}`}function d(e,t,o){return n("calcite-action",{appearance:"transparent",icon:"zoom-to-object",onclick:()=>t(e),scale:"s",slot:"actions-end",text:o,title:o})}export{c as FeatureList,i as loadFeatureListComponents};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{substitute as e}from"../../../intl/substitute.js";import{loadFooterActionsComponents as t,FooterActions as o}from"./FooterActions.js";import{loadNoticesComponents as n,Notices as a}from"./Notices.js";import{loadPanelContentComponents as s,PanelContentSection as i,PanelContentSectionGroup as r,PanelContent as l}from"./PanelContent.js";import u from"./PendingFeatureList.js";import{Heading as d,incrementHeadingLevel as p}from"../../support/Heading.js";import"../../support/widgetUtils.js";import{tsx as c,tsxFragment as m}from"../../support/jsxFactory.js";const f=()=>Promise.all([t(),n(),s()]);function h({editorViewModel:t,headingLevel:n,messages:s,messagesCommon:f,onDelete:h,onDeleteAssociation:y,onSave:g,renderAttachments:w,renderFeatureForm:b,renderSketchToolbar:k}){const{activeLeafWorkflow:v,activeWorkflow:F,featureFormViewModel:A,syncing:j}=t;if(!v||!F||!A)return null;const S=v.type.includes("update"),C=S&&!v.hasPendingEdits||j||A.updating,L=S?f.update:f.create,P="create-features"===v?.type?v.numPendingFeatures:0,D="create-features"!==v?.type||!!v.data.selectedPendingFeature,T=P>1?e(s.createFeaturesTemplate,{numFeatures:P}):L,H="shouldShowAttachments"in v&&v.shouldShowAttachments&&!A.activeRelationshipInput,x=A.inputs.every((e=>!e.visible))&&!H,B=x?c(i,null,"create-features"===v.type?c(u,{headingLevel:n,key:"pending-feature-list",workflow:v}):void 0):c(i,{key:"panel-content-section"},c(a,{messages:s,workflow:F}),c(r,null,D||"create-features"!==v.type?b():c(u,{headingLevel:n,key:"pending-feature-list",workflow:v}),H?c("div",{key:"attachments"},c(d,{level:p(n)},s.attachments),w()):null)),I={onClick:g,disabled:C,label:T,type:"button"},M={appearance:"outline",onClick:h,disabled:j,kind:"danger",label:f.delete,type:"button"},V={...M,onClick:y,label:s.deleteAssociationTitle,type:"button"},W={...M,primaryLabel:f.delete,primaryText:f.delete,dropdownItems:[{onClick:y,label:s.deleteAssociationTitle}],type:"split-button"};return c(m,null,x||"create-features"===v.type||"update"===v.type?k():void 0,c(l,{key:"attribute-panel-content"},B),c(o,{buttons:[I,t.shouldShowDeleteButton&&!t.featureFormHasAssociation?M:void 0,!t.shouldShowDeleteButton&&t.featureFormHasAssociation?V:void 0,t.shouldShowDeleteButton&&t.featureFormHasAssociation?W:void 0]}))}export{h as UpdateFeaturePanelContent,f as loadUpdateFeaturePanelContentComponents};
5
+ import{substitute as e}from"../../../intl/substitute.js";import{loadFooterActionsComponents as t,FooterActions as o}from"./FooterActions.js";import{loadNoticesComponents as n,Notices as i}from"./Notices.js";import{loadPanelContentComponents as s,PanelContentSection as a,PanelContentSectionGroup as r,PanelContent as l}from"./PanelContent.js";import u from"./PendingFeatureList.js";import{Heading as d,incrementHeadingLevel as p}from"../../support/Heading.js";import"../../support/widgetUtils.js";import{tsx as c,tsxFragment as m}from"../../support/jsxFactory.js";const f=()=>Promise.all([t(),n(),s()]);function h({editorViewModel:t,headingLevel:n,messages:s,messagesCommon:f,onDelete:h,onDeleteAssociation:y,onSave:g,renderAttachments:w,renderFeatureForm:b,renderSketchToolbar:k}){const{activeLeafWorkflow:v,activeWorkflow:F,featureFormViewModel:A,syncing:j}=t;if(!v||!F||!A)return null;const S=v.type.includes("update"),C=S&&!v.hasPendingEdits||j||A.updating,L=S?f.update:f.create,P="create-features"===v?.type?v.numPendingFeatures:0,D="create-features"!==v?.type||!!v.data.selectedPendingFeature,T=P>1?e(s.createFeaturesTemplate,{numFeatures:P}):L,H="shouldShowAttachments"in v&&v.shouldShowAttachments&&!A.activeRelationshipInput,x=A.inputs.every((e=>!e.visible))&&!H,B=x?c(a,null,"create-features"===v.type?c(u,{headingLevel:n,key:"pending-feature-list",workflow:v}):void 0):c(a,{key:"panel-content-section"},c(i,{messages:s,workflow:F}),c(r,null,D||"create-features"!==v.type?b():c(u,{headingLevel:n,key:"pending-feature-list",workflow:v}),H?c("div",{key:"attachments"},c(d,{level:p(n)},s.attachments),w()):null)),I={onClick:g,disabled:C,label:T,type:"button"},M={appearance:"outline",onClick:h,disabled:j,kind:"danger",label:f.delete,type:"button"},V={...M,onClick:y,label:s.deleteAssociationTitle,type:"button"},W={...M,primaryLabel:f.delete,primaryText:f.delete,dropdownItems:[{onClick:y,label:s.deleteAssociationTitle}],type:"split-button"};return c(m,null,x?k():void 0,c(l,{key:"attribute-panel-content"},B),c(o,{buttons:[I,t.shouldShowDeleteButton&&!t.featureFormHasAssociation?M:void 0,!t.shouldShowDeleteButton&&t.featureFormHasAssociation?V:void 0,t.shouldShowDeleteButton&&t.featureFormHasAssociation?W:void 0]}))}export{h as UpdateFeaturePanelContent,f as loadUpdateFeaturePanelContentComponents};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../Graphic.js";import{addMany as t}from"../../core/arrayUtils.js";import{createTask as r}from"../../core/asyncUtils.js";import"../../core/has.js";import i from"../../core/Error.js";import{makeHandle as n,handlesGroup as a,abortHandle as o}from"../../core/handleUtils.js";import{clone as l}from"../../core/lang.js";import{whenOrAbort as s,throwIfAborted as c,debounce as u}from"../../core/promiseUtils.js";import{watch as p,whenOnce as y}from"../../core/reactiveUtils.js";import{px2pt as d}from"../../core/screenUtils.js";import{diff as f}from"../../core/accessorSupport/diffUtils.js";import{isSharedTemplateOrMetadata as m,getAllStandardFeatureTemplatesForLayer as g}from"../../editing/templateUtils.js";import{featureHasFields as h,fixFields as b,getDisplayFieldName as w}from"../../layers/support/fieldUtils.js";import{calculateTolerance as v}from"../../renderers/support/clickToleranceUtils.js";import{meterIn as S}from"../../renderers/support/lengthUtils.js";import{getTransformationType as j,TransformationType as I}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import{getRotationAngle as U,getSize as V}from"../../renderers/visualVariables/support/visualVariableUtils.js";import{to3D as T}from"../../symbols/support/symbolConversion.js";import{getDisplayedSymbol as O}from"../../symbols/support/symbolUtils.js";import{GraphicState as z}from"../../views/3d/layers/graphics/GraphicState.js";import{defaultDrawingMode as F}from"../../views/draw/DrawingMode.js";import{createQueryGeometry as L}from"../../views/support/drapedUtils.js";import{hitTestSelectSimilarDistance as x,filterGraphicHits as P}from"../../views/support/hitTestSelectUtils.js";function A(e){return"update"===e.type}function k(e){const t=e.sourceLayer;if(!t||"feature"!==t.type||!G(t.renderer))return{rotation:null,size:null};let r=null,i=null;const n=t.renderer.getVisualVariablesForType("rotation").filter((t=>(!t.axis||"heading"===t.axis)&&t.field&&!t.valueExpression&&null!=U(t,e)));1===n.length&&(r=R(n[0],t));const a=t.renderer.getVisualVariablesForType("size").filter((t=>t.field&&!t.useSymbolValue&&!t.valueExpression&&j(t)===I.RealWorldSize&&null!=V(t,e)));return 1===a.length&&(i=C(a[0],t)),{rotation:r,size:i}}function R(e,t){const r="heading"===(e.axis||"heading")&&"arithmetic"===e.rotationType?-1:1,i=e.field,n=t.fields&&t.fields.filter((e=>e.name===i)),a=n&&1===n.length?n[0].type:"double",o={initial:0,current:0};return{field:i,fieldType:a,getDefault:()=>Promise.resolve(0),getValue:e=>(o.current=o.initial-r*e,D((o.current+360)%360,a)),setInitialValue:e=>{o.initial=e,o.current=0},isUpdatingInteractively:!1,rotationType:e.rotationType??"geographic"}}function E(e,t){switch(t){case"width":return e[0];case"depth":return e[1];case"height":return e[2];default:return e[2]||e[1]||e[0]}}async function M(e,t,r){if(null==t)return 0;const{symbol:i}=T(t);if(null==i||"web-style"===i.type||"cim"===i.type)return 0;const n=i.symbolLayers.at(0);if(!n)return 0;switch(n.type){case"icon":{const{computeIconLayerResourceSize:e}=await import("../../symbols/support/symbolLayerUtils.js");return n.size||Math.min(le.icon,(await e(n,le.icon))[0])||le.icon}case"text":return n.size||le.text;case"line":return n.size||le.line;case"object":{const{computeObjectLayerResourceSize:t}=await import("../../symbols/support/symbolLayerUtils.js");return E(await t(n,e.scale/le.viewScaleSizeFactor),r)}case"path":return(null!=n.width?n.width:n.height)||e.scale/le.viewScaleSizeFactor;case"extrude":return n.size||e.scale/le.viewScaleSizeFactor;default:return 0}}function C(e,t){const r=e.field,i=e.axis,n=t.fields&&t.fields.filter((e=>e.name===r)),a=n&&1===n.length?n[0].type:"double",o={initial:0,current:0},l=S[e.valueUnit]??1;let s;return s="area"===e.valueRepresentation?e=>(e*l/2)**2*Math.PI:"radius"===e.valueRepresentation||"distance"===e.valueRepresentation?e=>e*l/2:e=>e*l,{field:r,fieldType:a,getDefault:async(e,t)=>D(s(await M(t,e,i)),a),getValue:(e,t)=>(o.initial||(o.initial=t.pixelSizeAt(t.center)),o.current=o.initial*e,D(o.current,a)),setInitialValue:e=>{o.initial=e,o.current=0},isUpdatingInteractively:!1,displayUnit:ue(e.valueUnit),axis:e.axis}}function D(e,t){switch(t){case"small-integer":case"integer":case"long":return Math.round(e);case"double":case"single":return e;default:return 0}}function G(e){switch(e?.type){case"class-breaks":case"simple":case"unique-value":case"dot-density":case"dictionary":case"pie-chart":return!0;default:return!1}}async function Z(e,t,r){const i=await O(e,{useSourceLayer:!0,ignoreGraphicSymbol:!0,webStyleCache:t,scale:r});null!=f(e.symbol,i)&&(e.symbol=i)}function q(e,t){if(!e||!t)throw new Error("no geometry type");if("multipatch"===e)return{tool:"mesh",createOptions:{mode:"hybrid"}};if(m(t)){switch(t.defaultTool){case"freehand":case"line":case"stream-line":return{tool:"polyline"===e?"freehandPolyline":"freehandPolygon",createOptions:{mode:"freehand"}};case"autocomplete-freehand-polygons":case"stream-polygon":return{tool:"freehandPolygon",createOptions:{mode:"freehand"}};case"autocomplete-polygons":case"difference-polygon":case"create-structures":case"polygon":case"trace":return{tool:"polygon"===e?"polygon":"polyline",createOptions:{mode:F}};case"circle":return{tool:"circle",createOptions:{mode:F,preserveAspectRatio:!0}};case"ellipse":return{tool:"circle",createOptions:{mode:F,preserveAspectRatio:!1}};case"create-points-along-line":case"multipoint":return{tool:"multipoint",createOptions:{mode:F}};case"radial-line":case"right-angle-line":case"split":case"two-point-line":return{tool:"polyline",createOptions:{mode:F}};case"rectangle":case"regular-polygon":case"right-angle-polygon":return{tool:"rectangle",createOptions:{mode:F}};case"elevation-point-from-contour":case"elevation-point-from-dem":case"parcel-seed":case"point-and-rotation":case"point-at-end-of-line":return{tool:"point",createOptions:{mode:F}}}}else{const r=t.drawingTool;if("circle"===r||"ellipse"===r){const e=new Map;return e.set("circle",{preserveAspectRatio:"circle"===r}),{tool:"circle",createOptions:{mode:F,optionsPerTool:e}}}if("rectangle"===r)return{tool:"rectangle",createOptions:{mode:F}};if("freehand"===r)return{tool:"polygon"===e?"freehandPolygon":"freehandPolyline",createOptions:{mode:F}}}return{tool:e,createOptions:{mode:F}}}async function Q(e,t,r){const i=r.layer,a=B(r);let o=null;const{view:l}=e,s="2d"===l?.type;if(await W(e,i,a,t,s?l.scale:null),s){const r=u((r=>W(e,i,a,t,r)));o=p((()=>l.scale),(e=>r(e)))}const{data:c,editing:y}=i.capabilities;e.layer.elevationInfo=i.elevationInfo;const d=q(i.geometryType,r.template);return e.defaultCreateOptions={graphicProperties:{attributes:a,sourceLayer:i},mode:d.createOptions.mode,optionsPerTool:d.createOptions.optionsPerTool,preserveAspectRatio:d.createOptions.preserveAspectRatio,hasZ:c.supportsZ,defaultZ:(s?y.zDefault:null)??e.defaultCreateOptions.defaultZ},null==r.geometryToPlace?await e.create(d.tool):await e.place(r.geometryToPlace,{graphicProperties:{attributes:a,sourceLayer:i}}),o??n()}function B(e){const{template:t}=e;if(t&&m(t))throw new i("Shared templates are not yet supported");return{...t?.prototype.attributes,...e.attributeOverrides}}async function W(t,r,i,n,a){const o=new e({sourceLayer:r,attributes:i}),{rotation:l,size:s}=k(o);let c=await O(o,{useSourceLayer:!0,webStyleCache:n,scale:a}),u=!1;for(const e of[s,l]){if(null==e)continue;null==i[e.field]&&(i[e.field]=await e.getDefault(c,t.view),u=!0)}switch(u&&(c=await O(o,{useSourceLayer:!0,webStyleCache:n,scale:a})),c?.type){case"simple-fill":case"polygon-3d":t.polygonSymbol=c;break;case"simple-line":case"line-3d":t.polylineSymbol=c;break;case"simple-marker":case"picture-marker":case"point-3d":case"cim":t.pointSymbol=c;break;case"mesh-3d":t.meshSymbol=c}H(t.tooltipOptions,s,l)}function H(e,t,r){e.visualVariables=null!=t||null!=r?{size:null!=t?{unit:t.displayUnit,axis:t.axis,valueType:t.fieldType}:null,rotation:null!=r?{valueType:r.fieldType,rotationType:r.rotationType??"geographic"}:null}:null}function J(e,t){return e?.find((e=>e.layer===t))}async function K(e,t,r,i){switch(t.type){case"3d":return N(e,t,r,i);case"2d":return X(e,t,r,i)}}async function N(e,r,i,n){if(0===e.length)return[];const{updatable:a,graphicsByLayer:o}=await i.async((async()=>{const{results:t}=await s(x(r,i),n),a=new Map,o=e=>{const t=e.layer,r=a.get(t);if(!r){const e=new Array;return a.set(t,e),e}return r};P(t).forEach((({graphic:e})=>o(e).push(e)));const l=e.filter((({capabilities:e,layer:t})=>e.update.enabled&&a.has(t)));return 0!==l.length&&i.stopPropagation(),{updatable:l,graphicsByLayer:a}}));return s(Promise.allSettled(a.map((async({layer:e})=>{const r=o.get(e),i=Y(e);if(r.every((e=>h(i,e))))return r;const a=[];for(const n of r){a.push(n.getObjectId());const e=Object.keys(n.attributes);t(i,e)}const l=e.createQuery();return l.returnGeometry=!1,l.objectIds=a,l.outFields=b(e.fieldsIndex,i),e.queryFeatures(l,{signal:n}).then((({features:e})=>e))}))),n)}async function X(e,t,r,i){if(0===e.length)return[];const{mapPoint:n}=r;if(null==n)return[];let a=null;const o=await r.async((async()=>{const{results:n}=await s(t.hitTest(r),i);if(0===n.length)return[];const o=new Set;a=P(n),a.forEach((({graphic:e})=>e&&o.add(e.layer)));const l=e.filter((e=>o.has(e.layer)&&e.supportsUpdateWorkflow));return l.length>0&&r.stopPropagation(),l}));return s(Promise.allSettled(o.map((async({layer:e})=>{const o=e.createQuery();o.returnGeometry=!1,o.outFields=Y(e);const l="renderer"in e?v({renderer:e.renderer,pointerType:r.pointerType}):0;o.geometry=L(n,l,t),o.outSpatialReference=t.spatialReference;const{features:s}=await e.queryFeatures(o,{signal:i});return a?.forEach((({graphic:t})=>{t.layer!==e||s.some((e=>e.getObjectId()===t.getObjectId()))||s.push(t)})),s}))),i)}function Y(e){return b(e.fieldsIndex,[e.objectIdField,w({displayField:"displayField"in e?e.displayField:null,fields:e.fields})])}async function $(e,t,r){const{sourceLayer:i}=e,n=i.createQuery();n.objectIds=[e.getAttribute(i.objectIdField)],n.outFields=["*"],n.returnM=i.capabilities.data.supportsM,n.returnZ=i.capabilities.data.supportsZ,"scene"===i.type&&null!=i.infoFor3D||(n.outSpatialReference=t);const a=await i.queryFeatures(n,{signal:r});c(r);return a.features[0]}async function _(e){const{graphic:t,sketchViewModel:r,sourceLayer:i,visualVariables:n,webStyleCache:a}=e;let o=!1;const{rotation:l,size:s}=n;if([l,s].forEach((async e=>{if(null==e)return;const i=t.getAttribute(e.field);if(null!=i)e.setInitialValue(i);else{const i=await e.getDefault(t.symbol,r.view);e.setInitialValue(i),t.setAttribute(e.field,i),o=!0}})),o){const e="2d"===r.view?.type?r.view.scale:null;await Z(t,a,e)}const c={multipleSelectionEnabled:!1};return"point"===i.geometryType&&(c.enableRotation=null!=l,c.enableScaling=null!=s),H(r.tooltipOptions,s,l),r.layer.elevationInfo=i.elevationInfo,r.update(t,c)}function ee(e){return null==e||"rotate-start"!==e.type&&"rotate"!==e.type&&"rotate-stop"!==e.type?null:e}function te(e){return null==e||"scale-start"!==e.type&&"scale"!==e.type&&"scale-stop"!==e.type?null:e}async function re(e,t,r,i,n){if(null==t.geometry||"point"!==t.geometry?.type)return;const a=i.rotation,o=ee(r.toolEventInfo);if(null!=a&&null!=o){const{field:r,getValue:i}=a;"rotate-stop"===o.type?(a.isUpdatingInteractively=!1,a.setInitialValue(t.getAttribute(r))):(a.isUpdatingInteractively=!0,t.setAttribute(r,i(o.angle,e)))}const l=i.size,s=te(r.toolEventInfo);if(null!=l&&null!=s){const{field:r,getValue:i}=l;"scale-stop"===s.type?(l.isUpdatingInteractively=!1,l.setInitialValue(t.getAttribute(r))):(l.isUpdatingInteractively=!0,t.setAttribute(r,i(s.xScale,e)))}await Z(t,n,"2d"===e.type?e.scale:null)}async function ie({feature:e,featureClone:t,visualVariableAttributes:r,sketchViewModel:i,view:l,onUpdate:s,webStyleCache:c,addUpdatingPromise:d,addHandle:f}){await Z(t,c,"2d"===l.type?l.scale:null);let m=null;if("2d"===i?.view?.type){const e=u((e=>Z(t,c,e)));m=p((()=>i?.view?.scale),(t=>e(t)))}const g=t.sourceLayer,h=de(l,g);await _({graphic:t,sketchViewModel:i,sourceLayer:g,visualVariables:r,webStyleCache:c});let b=null;h.then((e=>b=e)).catch((()=>{}));const w=r.size,v=r.rotation,S=p((()=>e.attributes),(async e=>{let r=!1;for(const i in e){const n=e[i];n!==t.getAttribute(i)&&(t.setAttribute(i,n),null==w||w.isUpdatingInteractively||w.field!==i||w.setInitialValue(n),null==v||v.isUpdatingInteractively||v.field!==i||v.setInitialValue(n),(null==b||b.requiredFields.includes(i))&&(r=!0))}r&&await Z(t,c,"2d"===l.type?l.scale:null)})),j=i.on("update",(async e=>{const t=e.graphics[0],n={graphic:t,sketchViewModel:i,sourceLayer:g,visualVariables:r,webStyleCache:c};if("complete"===e.state){if(null===l.activeTool)return _(n);const e=new AbortController,t=o(e);return f(t),d(y((()=>null===l.activeTool),e.signal).then((()=>(e.abort(),_(n)))))}await re(l,t,e,r,c),s(me(t),e)})),I=i.on(["undo","redo"],(async e=>{s(me(e.graphics[0]),e)}));return a([I,j,n((()=>i.cancel())),S,m])}async function ne(e,t,i){const o=e.view;e.layer.add(i);const l=t.sourceLayer,s=t.layer,u=t.getAttribute(s.objectIdField);let p=null;function d(e){p?.abort(),p=r((async t=>{const r=await de(o,l);c(t),r.setVisibility?.(u,e)}))}return await oe(o,i),d(!1),a([ae(o,i,(e=>d(!e))),n((async()=>{d(!0);try{const e=await de(o,l);await y((()=>!e.updating))}finally{e.layer.remove(i)}}))])}function ae(e,t,r){if("3d"===e.type){const i=new z({graphic:t});return a([e.trackGraphicState(i),p((()=>i.displaying),r)])}return p((()=>t.visible),r)}async function oe(e,t){if("3d"===e.type){const r=new z({graphic:t}),i=e.trackGraphicState(r);await y((()=>r.displaying||r.error)),i.remove()}else await y((()=>t.visible))}const le={icon:d(24),text:d(12),line:d(1),viewScaleSizeFactor:100};function se(e,t,r){let i=!1;return e.filter((e=>!!i||(i=e===t,i))).map((e=>r[e]()))}function ce(e,t){e.viewModel.syncFeatureTemplates();const r=e.creationInfo;if("awaiting-feature-creation-info"===t[0].id&&r){const e=r.layer,i=g(e);1===i.length&&"scene"!==e.type&&(r.template=i[0],t.shift())}return t}function ue(e){return"unknown"===e?null:e}function pe(e){e.filesEnabled=!0,e.mode="view",e.capabilities={editing:!0,operations:{add:!0,update:!0,delete:!0}}}const ye=e=>/-stop/.test(e)||/vertex-/.test(e),de=(e,t)=>{const r="subtype-sublayer"===t.type?t.parent:t;return e.whenLayerView(r)};function fe(e){return"createInteractiveEditSession"in e}function me(e){const t=e.geometry;if("mesh"===t?.type){const r=e.cloneShallow();return r.attributes=l(e.attributes),r.geometry=t.cloneShallow(),r.geometry.transform=t.transform?.clone()??null,r}return e.clone()}function ge(e){const t=e.cursor;return e.cursor="progress",n((()=>e.cursor=t))}export{ce as avoidFeatureTemplateSelectionWithOnlyOneItem,fe as canCreateInteractiveEditSession,me as cloneGraphicExceptMesh,se as createWorkflowSteps,K as fetchCandidates,$ as fetchFullFeature,J as findLayerInfo,B as getCreationAttributes,k as getVisualVariableAttributes,ye as isTerminalUpdateEventType,A as isUpdateWorkflow,pe as prepareAttachmentsForCreateFeaturesWorkflow,ie as setUpGeometryUpdate,ge as showProgressCursor,le as sizeDefaults,ue as sizeVariableUnitToLengthUnit,Q as startCreatingNewFeature,_ as startUpdatingFeatureGeometry,ne as swapForEditingSession,Z as updateGraphicSymbolWhenRequired,re as visualVariableInteractiveUpdate,de as whenEditorLayerView,oe as whenGraphicDisplayed};
5
+ import e from"../../Graphic.js";import{addMany as t}from"../../core/arrayUtils.js";import{createTask as r}from"../../core/asyncUtils.js";import"../../core/has.js";import i from"../../core/Error.js";import{makeHandle as n,handlesGroup as a,abortHandle as o}from"../../core/handleUtils.js";import{clone as l}from"../../core/lang.js";import{whenOrAbort as s,throwIfAborted as c,debounce as u}from"../../core/promiseUtils.js";import{watch as p,whenOnce as y}from"../../core/reactiveUtils.js";import{px2pt as d}from"../../core/screenUtils.js";import{diff as f}from"../../core/accessorSupport/diffUtils.js";import{isSharedTemplateOrMetadata as m,getAllStandardFeatureTemplatesForLayer as g}from"../../editing/templateUtils.js";import{featureHasFields as h,fixFields as b,getDisplayFieldName as w}from"../../layers/support/fieldUtils.js";import{calculateTolerance as v}from"../../renderers/support/clickToleranceUtils.js";import{meterIn as S}from"../../renderers/support/lengthUtils.js";import{getTransformationType as j,TransformationType as I}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import{getRotationAngle as U,getSize as V}from"../../renderers/visualVariables/support/visualVariableUtils.js";import{to3D as T}from"../../symbols/support/symbolConversion.js";import{getDisplayedSymbol as O}from"../../symbols/support/symbolUtils.js";import{GraphicState as z}from"../../views/3d/layers/graphics/GraphicState.js";import{defaultDrawingMode as F}from"../../views/draw/DrawingMode.js";import{createQueryGeometry as L}from"../../views/support/drapedUtils.js";import{hitTestSelectSimilarDistance as x,filterGraphicHits as P}from"../../views/support/hitTestSelectUtils.js";function A(e){return"update"===e.type}function k(e){const t=e.sourceLayer;if(!t||"feature"!==t.type||!G(t.renderer))return{rotation:null,size:null};let r=null,i=null;const n=t.renderer.getVisualVariablesForType("rotation").filter((t=>(!t.axis||"heading"===t.axis)&&t.field&&!t.valueExpression&&null!=U(t,e)));1===n.length&&(r=R(n[0],t));const a=t.renderer.getVisualVariablesForType("size").filter((t=>t.field&&!t.useSymbolValue&&!t.valueExpression&&j(t)===I.RealWorldSize&&null!=V(t,e)));return 1===a.length&&(i=C(a[0],t)),{rotation:r,size:i}}function R(e,t){const r="heading"===(e.axis||"heading")&&"arithmetic"===e.rotationType?-1:1,i=e.field,n=t.fields&&t.fields.filter((e=>e.name===i)),a=n&&1===n.length?n[0].type:"double",o={initial:0,current:0};return{field:i,fieldType:a,getDefault:()=>Promise.resolve(0),getValue:e=>(o.current=o.initial-r*e,D((o.current+360)%360,a)),setInitialValue:e=>{o.initial=e,o.current=0},isUpdatingInteractively:!1,rotationType:e.rotationType??"geographic"}}function E(e,t){switch(t){case"width":return e[0];case"depth":return e[1];case"height":return e[2];default:return e[2]||e[1]||e[0]}}async function M(e,t,r){if(null==t)return 0;const{symbol:i}=T(t);if(null==i||"web-style"===i.type||"cim"===i.type)return 0;const n=i.symbolLayers.at(0);if(!n)return 0;switch(n.type){case"icon":{const{computeIconLayerResourceSize:e}=await import("../../symbols/support/symbolLayerUtils.js");return n.size||Math.min(le.icon,(await e(n,le.icon))[0])||le.icon}case"text":return n.size||le.text;case"line":return n.size||le.line;case"object":{const{computeObjectLayerResourceSize:t}=await import("../../symbols/support/symbolLayerUtils.js");return E(await t(n,e.scale/le.viewScaleSizeFactor),r)}case"path":return(null!=n.width?n.width:n.height)||e.scale/le.viewScaleSizeFactor;case"extrude":return n.size||e.scale/le.viewScaleSizeFactor;default:return 0}}function C(e,t){const r=e.field,i=e.axis,n=t.fields&&t.fields.filter((e=>e.name===r)),a=n&&1===n.length?n[0].type:"double",o={initial:0,current:0},l=S[e.valueUnit]??1;let s;return s="area"===e.valueRepresentation?e=>(e*l/2)**2*Math.PI:"radius"===e.valueRepresentation||"distance"===e.valueRepresentation?e=>e*l/2:e=>e*l,{field:r,fieldType:a,getDefault:async(e,t)=>D(s(await M(t,e,i)),a),getValue:(e,t)=>(o.initial||(o.initial=t.pixelSizeAt(t.center)),o.current=o.initial*e,D(o.current,a)),setInitialValue:e=>{o.initial=e,o.current=0},isUpdatingInteractively:!1,displayUnit:ue(e.valueUnit),axis:e.axis}}function D(e,t){switch(t){case"small-integer":case"integer":case"long":return Math.round(e);case"double":case"single":return e;default:return 0}}function G(e){switch(e?.type){case"class-breaks":case"simple":case"unique-value":case"dot-density":case"dictionary":case"pie-chart":return!0;default:return!1}}async function Z(e,t,r){const i=await O(e,{useSourceLayer:!0,ignoreGraphicSymbol:!0,webStyleCache:t,scale:r});null!=f(e.symbol,i)&&(e.symbol=i)}function q(e,t){if(!e||!t)throw new Error("no geometry type");if("multipatch"===e)return{tool:"mesh",createOptions:{mode:"hybrid"}};const r=new Map;r.set("circle",{mode:"freehand"}),r.set("rectangle",{mode:"freehand"});const i={mode:F,optionsPerTool:r};if(m(t)){switch(t.defaultTool){case"freehand":case"line":case"stream-line":return{tool:"polyline"===e?"freehandPolyline":"freehandPolygon",createOptions:i};case"autocomplete-freehand-polygons":case"stream-polygon":return{tool:"freehandPolygon",createOptions:i};case"autocomplete-polygons":case"difference-polygon":case"create-structures":case"polygon":case"trace":return{tool:"polygon"===e?"polygon":"polyline",createOptions:i};case"circle":return r.get("circle").preserveAspectRatio=!0,{tool:"circle",createOptions:i};case"ellipse":return r.get("circle").preserveAspectRatio=!1,{tool:"circle",createOptions:i};case"create-points-along-line":case"multipoint":return{tool:"multipoint",createOptions:i};case"radial-line":case"right-angle-line":case"split":case"two-point-line":return{tool:"polyline",createOptions:i};case"rectangle":case"regular-polygon":case"right-angle-polygon":return{tool:"rectangle",createOptions:i};case"elevation-point-from-contour":case"elevation-point-from-dem":case"parcel-seed":case"point-and-rotation":case"point-at-end-of-line":return{tool:"point",createOptions:i}}}else{const n=t.drawingTool;if("circle"===n||"ellipse"===n)return r.get("circle").preserveAspectRatio="circle"===n,{tool:"circle",createOptions:i};if("rectangle"===n)return{tool:"rectangle",createOptions:i};if("freehand"===n)return{tool:"polygon"===e?"freehandPolygon":"freehandPolyline",createOptions:i}}return{tool:e,createOptions:i}}async function Q(e,t,r){const i=r.layer,a=B(r);let o=null;const{view:l}=e,s="2d"===l?.type;if(await W(e,i,a,t,s?l.scale:null),s){const r=u((r=>W(e,i,a,t,r)));o=p((()=>l.scale),(e=>r(e)))}const{data:c,editing:y}=i.capabilities;e.layer.elevationInfo=i.elevationInfo;const d=q(i.geometryType,r.template);return e.defaultCreateOptions={graphicProperties:{attributes:a,sourceLayer:i},mode:d.createOptions.mode,optionsPerTool:d.createOptions.optionsPerTool,preserveAspectRatio:d.createOptions.preserveAspectRatio,hasZ:c.supportsZ,defaultZ:(s?y.zDefault:null)??e.defaultCreateOptions.defaultZ},null==r.geometryToPlace?await e.create(d.tool):await e.place(r.geometryToPlace,{graphicProperties:{attributes:a,sourceLayer:i}}),o??n()}function B(e){const{template:t}=e;if(t&&m(t))throw new i("Shared templates are not yet supported");return{...t?.prototype.attributes,...e.attributeOverrides}}async function W(t,r,i,n,a){const o=new e({sourceLayer:r,attributes:i}),{rotation:l,size:s}=k(o);let c=await O(o,{useSourceLayer:!0,webStyleCache:n,scale:a}),u=!1;for(const e of[s,l]){if(null==e)continue;null==i[e.field]&&(i[e.field]=await e.getDefault(c,t.view),u=!0)}switch(u&&(c=await O(o,{useSourceLayer:!0,webStyleCache:n,scale:a})),c?.type){case"simple-fill":case"polygon-3d":t.polygonSymbol=c;break;case"simple-line":case"line-3d":t.polylineSymbol=c;break;case"simple-marker":case"picture-marker":case"point-3d":case"cim":t.pointSymbol=c;break;case"mesh-3d":t.meshSymbol=c}H(t.tooltipOptions,s,l)}function H(e,t,r){e.visualVariables=null!=t||null!=r?{size:null!=t?{unit:t.displayUnit,axis:t.axis,valueType:t.fieldType}:null,rotation:null!=r?{valueType:r.fieldType,rotationType:r.rotationType??"geographic"}:null}:null}function J(e,t){return e?.find((e=>e.layer===t))}async function K(e,t,r,i){switch(t.type){case"3d":return N(e,t,r,i);case"2d":return X(e,t,r,i)}}async function N(e,r,i,n){if(0===e.length)return[];const{updatable:a,graphicsByLayer:o}=await i.async((async()=>{const{results:t}=await s(x(r,i),n),a=new Map,o=e=>{const t=e.layer,r=a.get(t);if(!r){const e=new Array;return a.set(t,e),e}return r};P(t).forEach((({graphic:e})=>o(e).push(e)));const l=e.filter((({capabilities:e,layer:t})=>e.update.enabled&&a.has(t)));return 0!==l.length&&i.stopPropagation(),{updatable:l,graphicsByLayer:a}}));return s(Promise.allSettled(a.map((async({layer:e})=>{const r=o.get(e),i=Y(e);if(r.every((e=>h(i,e))))return r;const a=[];for(const n of r){a.push(n.getObjectId());const e=Object.keys(n.attributes);t(i,e)}const l=e.createQuery();return l.returnGeometry=!1,l.objectIds=a,l.outFields=b(e.fieldsIndex,i),e.queryFeatures(l,{signal:n}).then((({features:e})=>e))}))),n)}async function X(e,t,r,i){if(0===e.length)return[];const{mapPoint:n}=r;if(null==n)return[];let a=null;const o=await r.async((async()=>{const{results:n}=await s(t.hitTest(r),i);if(0===n.length)return[];const o=new Set;a=P(n),a.forEach((({graphic:e})=>e&&o.add(e.layer)));const l=e.filter((e=>o.has(e.layer)&&e.supportsUpdateWorkflow));return l.length>0&&r.stopPropagation(),l}));return s(Promise.allSettled(o.map((async({layer:e})=>{const o=e.createQuery();o.returnGeometry=!1,o.outFields=Y(e);const l="renderer"in e?v({renderer:e.renderer,pointerType:r.pointerType}):0;o.geometry=L(n,l,t),o.outSpatialReference=t.spatialReference;const{features:s}=await e.queryFeatures(o,{signal:i});return a?.forEach((({graphic:t})=>{t.layer!==e||s.some((e=>e.getObjectId()===t.getObjectId()))||s.push(t)})),s}))),i)}function Y(e){return b(e.fieldsIndex,[e.objectIdField,w({displayField:"displayField"in e?e.displayField:null,fields:e.fields})])}async function $(e,t,r){const{sourceLayer:i}=e,n=i.createQuery();n.objectIds=[e.getAttribute(i.objectIdField)],n.outFields=["*"],n.returnM=i.capabilities.data.supportsM,n.returnZ=i.capabilities.data.supportsZ,"scene"===i.type&&null!=i.infoFor3D||(n.outSpatialReference=t);const a=await i.queryFeatures(n,{signal:r});c(r);return a.features[0]}async function _(e){const{graphic:t,sketchViewModel:r,sourceLayer:i,visualVariables:n,webStyleCache:a}=e;let o=!1;const{rotation:l,size:s}=n;if([l,s].forEach((async e=>{if(null==e)return;const i=t.getAttribute(e.field);if(null!=i)e.setInitialValue(i);else{const i=await e.getDefault(t.symbol,r.view);e.setInitialValue(i),t.setAttribute(e.field,i),o=!0}})),o){const e="2d"===r.view?.type?r.view.scale:null;await Z(t,a,e)}const c={multipleSelectionEnabled:!1};return"point"===i.geometryType&&(c.enableRotation=null!=l,c.enableScaling=null!=s),H(r.tooltipOptions,s,l),r.layer.elevationInfo=i.elevationInfo,r.update(t,c)}function ee(e){return null==e||"rotate-start"!==e.type&&"rotate"!==e.type&&"rotate-stop"!==e.type?null:e}function te(e){return null==e||"scale-start"!==e.type&&"scale"!==e.type&&"scale-stop"!==e.type?null:e}async function re(e,t,r,i,n){if(null==t.geometry||"point"!==t.geometry?.type)return;const a=i.rotation,o=ee(r.toolEventInfo);if(null!=a&&null!=o){const{field:r,getValue:i}=a;"rotate-stop"===o.type?(a.isUpdatingInteractively=!1,a.setInitialValue(t.getAttribute(r))):(a.isUpdatingInteractively=!0,t.setAttribute(r,i(o.angle,e)))}const l=i.size,s=te(r.toolEventInfo);if(null!=l&&null!=s){const{field:r,getValue:i}=l;"scale-stop"===s.type?(l.isUpdatingInteractively=!1,l.setInitialValue(t.getAttribute(r))):(l.isUpdatingInteractively=!0,t.setAttribute(r,i(s.xScale,e)))}await Z(t,n,"2d"===e.type?e.scale:null)}async function ie({feature:e,featureClone:t,visualVariableAttributes:r,sketchViewModel:i,view:l,onUpdate:s,webStyleCache:c,addUpdatingPromise:d,addHandle:f}){await Z(t,c,"2d"===l.type?l.scale:null);let m=null;if("2d"===i?.view?.type){const e=u((e=>Z(t,c,e)));m=p((()=>i?.view?.scale),(t=>e(t)))}const g=t.sourceLayer,h=de(l,g);await _({graphic:t,sketchViewModel:i,sourceLayer:g,visualVariables:r,webStyleCache:c});let b=null;h.then((e=>b=e)).catch((()=>{}));const w=r.size,v=r.rotation,S=p((()=>e.attributes),(async e=>{let r=!1;for(const i in e){const n=e[i];n!==t.getAttribute(i)&&(t.setAttribute(i,n),null==w||w.isUpdatingInteractively||w.field!==i||w.setInitialValue(n),null==v||v.isUpdatingInteractively||v.field!==i||v.setInitialValue(n),(null==b||b.requiredFields.includes(i))&&(r=!0))}r&&await Z(t,c,"2d"===l.type?l.scale:null)})),j=i.on("update",(async e=>{const t=e.graphics[0],n={graphic:t,sketchViewModel:i,sourceLayer:g,visualVariables:r,webStyleCache:c};if("complete"===e.state){if(null===l.activeTool)return _(n);const e=new AbortController,t=o(e);return f(t),d(y((()=>null===l.activeTool),e.signal).then((()=>(e.abort(),_(n)))))}await re(l,t,e,r,c),s(me(t),e)})),I=i.on(["undo","redo"],(async e=>{s(me(e.graphics[0]),e)}));return a([I,j,n((()=>i.cancel())),S,m])}async function ne(e,t,i){const o=e.view;e.layer.add(i);const l=t.sourceLayer,s=t.layer,u=t.getAttribute(s.objectIdField);let p=null;function d(e){p?.abort(),p=r((async t=>{const r=await de(o,l);c(t),r.setVisibility?.(u,e)}))}return await oe(o,i),d(!1),a([ae(o,i,(e=>d(!e))),n((async()=>{d(!0);try{const e=await de(o,l);await y((()=>!e.updating))}finally{e.layer.remove(i)}}))])}function ae(e,t,r){if("3d"===e.type){const i=new z({graphic:t});return a([e.trackGraphicState(i),p((()=>i.displaying),r)])}return p((()=>t.visible),r)}async function oe(e,t){if("3d"===e.type){const r=new z({graphic:t}),i=e.trackGraphicState(r);await y((()=>r.displaying||r.error)),i.remove()}else await y((()=>t.visible))}const le={icon:d(24),text:d(12),line:d(1),viewScaleSizeFactor:100};function se(e,t,r){let i=!1;return e.filter((e=>!!i||(i=e===t,i))).map((e=>r[e]()))}function ce(e,t){e.viewModel.syncFeatureTemplates();const r=e.creationInfo;if("awaiting-feature-creation-info"===t[0].id&&r){const e=r.layer,i=g(e);1===i.length&&"scene"!==e.type&&(r.template=i[0],t.shift())}return t}function ue(e){return"unknown"===e?null:e}function pe(e){e.filesEnabled=!0,e.mode="view",e.capabilities={editing:!0,operations:{add:!0,update:!0,delete:!0}}}const ye=e=>/-stop/.test(e)||/vertex-/.test(e),de=(e,t)=>{const r="subtype-sublayer"===t.type?t.parent:t;return e.whenLayerView(r)};function fe(e){return"createInteractiveEditSession"in e}function me(e){const t=e.geometry;if("mesh"===t?.type){const r=e.cloneShallow();return r.attributes=l(e.attributes),r.geometry=t.cloneShallow(),r.geometry.transform=t.transform?.clone()??null,r}return e.clone()}function ge(e){const t=e.cursor;return e.cursor="progress",n((()=>e.cursor=t))}export{ce as avoidFeatureTemplateSelectionWithOnlyOneItem,fe as canCreateInteractiveEditSession,me as cloneGraphicExceptMesh,se as createWorkflowSteps,K as fetchCandidates,$ as fetchFullFeature,J as findLayerInfo,B as getCreationAttributes,k as getVisualVariableAttributes,ye as isTerminalUpdateEventType,A as isUpdateWorkflow,pe as prepareAttachmentsForCreateFeaturesWorkflow,ie as setUpGeometryUpdate,ge as showProgressCursor,le as sizeDefaults,ue as sizeVariableUnitToLengthUnit,Q as startCreatingNewFeature,_ as startUpdatingFeatureGeometry,ne as swapForEditingSession,Z as updateGraphicSymbolWhenRequired,re as visualVariableInteractiveUpdate,de as whenEditorLayerView,oe as whenGraphicDisplayed};