@arcgis/core 4.34.0-next.20 → 4.34.0-next.21

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 (176) hide show
  1. package/analysis/VolumeMeasurement/CutFillOptions.js +5 -0
  2. package/analysis/VolumeMeasurement/volumeMeasurementUtils.js +5 -0
  3. package/analysis/VolumeMeasurementAnalysis.d.ts +4 -0
  4. package/analysis/VolumeMeasurementAnalysis.js +5 -0
  5. package/assets/esri/core/workers/RemoteClient.js +1 -1
  6. package/assets/esri/core/workers/chunks/06c3725d6cc21e7e4bcf.js +1 -0
  7. package/assets/esri/core/workers/chunks/{28b525963420f022fb0a.js → 1cc30073f8200b67cff6.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{9432a5466eec397710a4.js → 273ff53a68714e4daad5.js} +1 -1
  9. package/assets/esri/core/workers/chunks/32756905bcf11699b3f7.js +1 -0
  10. package/assets/esri/core/workers/chunks/41f487713c6278d389a1.js +1 -0
  11. package/assets/esri/core/workers/chunks/5b276962c46c57155166.js +1 -0
  12. package/assets/esri/core/workers/chunks/5ce62d9fff80d014d186.js +1 -0
  13. package/assets/esri/core/workers/chunks/5e805c9e9012dd39ec86.js +1 -0
  14. package/assets/esri/core/workers/chunks/66757fc16316a5c50e1e.js +1 -0
  15. package/assets/esri/core/workers/chunks/6a0fbc54638f7de138c1.js +1 -0
  16. package/assets/esri/core/workers/chunks/871fae52d2fddc9e7794.js +1 -0
  17. package/assets/esri/core/workers/chunks/8b19fe829a9dc26fb3fe.js +1 -0
  18. package/assets/esri/core/workers/chunks/8eea6251aa09725e654e.js +1 -0
  19. package/assets/esri/core/workers/chunks/916691122d7fb38497d6.js +1 -0
  20. package/assets/esri/core/workers/chunks/919d2fd7ebc0c840a759.js +1 -0
  21. package/assets/esri/core/workers/chunks/97324f030738fc0d456b.js +1 -0
  22. package/assets/esri/core/workers/chunks/9c510df592befb9ff892.js +1 -0
  23. package/assets/esri/core/workers/chunks/9d2cb559dd9af4e1727c.js +1 -0
  24. package/assets/esri/core/workers/chunks/{2e54be3094e41fd3026d.js → 9eb1a171f5ef1fef42ed.js} +1 -1
  25. package/assets/esri/core/workers/chunks/aba520714efc01bead36.js +1 -0
  26. package/assets/esri/core/workers/chunks/accff253af360c34e8a8.js +1 -0
  27. package/assets/esri/core/workers/chunks/ad3871f497ecea1a08c9.js +1 -0
  28. package/assets/esri/core/workers/chunks/ae6eed26fc932bc08356.js +1 -0
  29. package/assets/esri/core/workers/chunks/c317819ab0544c50c078.js +1 -0
  30. package/assets/esri/core/workers/chunks/fc8bbc571216edd9ef5a.js +1 -0
  31. package/config.js +1 -1
  32. package/core/libs/rbush/PooledRBush.js +1 -1
  33. package/core/scheduling.js +1 -1
  34. package/geometry/support/buffer/BufferView.js +1 -1
  35. package/geometry/support/float16.js +1 -1
  36. package/interfaces.d.ts +1040 -146
  37. package/kernel.js +1 -1
  38. package/layers/SubtypeGroupLayer.js +1 -1
  39. package/layers/graphics/controllers/FeatureTileController3D.js +1 -1
  40. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  41. package/layers/mixins/ArcGISMapService.js +1 -1
  42. package/layers/save/mapImageLayerUtils.js +1 -1
  43. package/layers/support/TilemapCache.js +1 -1
  44. package/layers/support/TitleCreator.js +1 -1
  45. package/layers/support/arcgisLayerUrl.js +1 -1
  46. package/layers/support/rasterFormats/TiffDecoder.js +1 -1
  47. package/package.json +1 -1
  48. package/rest/knowledgeGraph/GraphAddFieldIndexResult.d.ts +4 -0
  49. package/rest/knowledgeGraph/GraphAddPropertyResult.d.ts +4 -0
  50. package/rest/knowledgeGraph/GraphDataModelOperationResult.d.ts +4 -0
  51. package/rest/knowledgeGraph/GraphDeleteFieldIndexResult.d.ts +4 -0
  52. package/rest/knowledgeGraph/GraphDeletePropertyResult.d.ts +4 -0
  53. package/rest/knowledgeGraph/GraphUpdateNamedTypesResult.d.ts +4 -0
  54. package/rest/knowledgeGraph/GraphUpdatePropertyResult.d.ts +4 -0
  55. package/rest/knowledgeGraph/GraphUpdateSearchIndexResult.d.ts +4 -0
  56. package/rest/knowledgeGraphService.d.ts +7 -0
  57. package/support/requestUtils.js +1 -1
  58. package/support/revision.js +1 -1
  59. package/views/2d/engine/ManagedCanvas.js +1 -1
  60. package/views/2d/engine/ParentChildStage.js +5 -0
  61. package/views/2d/engine/Stage.js +1 -1
  62. package/views/2d/engine/webgl/OverlayContainer.js +1 -1
  63. package/views/2d/engine/webgl/OverlayMultipoint.js +1 -1
  64. package/views/2d/engine/webgl/Painter.js +1 -1
  65. package/views/2d/engine/webgl/VideoScreenRenderer.js +5 -0
  66. package/views/2d/engine/webgl/shaderGraph/techniques/TechniqueType.js +1 -1
  67. package/views/2d/engine/webgl/shaderGraph/techniques/shaders/VideoScreenShader.js +5 -0
  68. package/views/2d/engine/webgl/shaderGraph/techniques/videoScreenRenderer/VideoScreenTechnique.js +5 -0
  69. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  70. package/views/2d/layers/MediaLayerView2D.js +1 -1
  71. package/views/2d/layers/TileLayerView2D.js +1 -1
  72. package/views/2d/layers/features/Processor.js +1 -1
  73. package/views/2d/layers/features/processor/AProcessorStrategy.js +1 -1
  74. package/views/2d/layers/features/support/AttributeStore.js +1 -1
  75. package/views/2d/mapViewDeps.js +1 -1
  76. package/views/3d/analysis/AnalysisViewManager3D.js +1 -1
  77. package/views/3d/analysis/VolumeMeasurementAnalysisView3D.d.ts +4 -0
  78. package/views/3d/analysis/VolumeMeasurementAnalysisView3D.js +5 -0
  79. package/views/3d/layers/FeatureLikeLayerView3D.js +1 -1
  80. package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
  81. package/views/3d/layers/graphics/DeconflictAABR.js +1 -1
  82. package/views/3d/layers/graphics/ExtentSet.js +1 -1
  83. package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
  84. package/views/3d/layers/graphics/Graphics3DElevationAlignment.js +1 -1
  85. package/views/3d/layers/graphics/Graphics3DFeatureProcessor.js +1 -1
  86. package/views/3d/layers/graphics/Graphics3DGraphicsPipeline.js +1 -1
  87. package/views/3d/layers/graphics/Labeler.js +1 -1
  88. package/views/3d/layers/graphics/pipeline/Feature3DPipeline.js +1 -1
  89. package/views/3d/layers/i3s/I3SAsyncElevationUpdater.js +1 -1
  90. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  91. package/views/3d/layers/i3s/I3SLodHandling.js +1 -1
  92. package/views/3d/layers/i3s/PointCloudRenderer.js +1 -1
  93. package/views/3d/layers/support/FeatureTileDescriptor.js +1 -1
  94. package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
  95. package/views/3d/layers/support/FeatureTileFetcher3DContext.js +1 -1
  96. package/views/3d/layers/support/FeatureTileTree3D.js +1 -1
  97. package/views/3d/layers/support/FeatureVisibilityFilter.js +1 -1
  98. package/views/3d/layers/support/HeatmapFeatureProcessor.js +1 -1
  99. package/views/3d/state/helpers/SceneIntersectionHelper.js +1 -1
  100. package/views/3d/support/StreamDataLoader.js +1 -1
  101. package/views/3d/support/buffer/InterleavedLayout.js +1 -1
  102. package/views/3d/terrain/OverlayManager.js +1 -1
  103. package/views/3d/terrain/OverlayRenderer.js +1 -1
  104. package/views/3d/terrain/TerrainSurface.js +1 -1
  105. package/views/3d/webgl-engine/Stage.js +1 -1
  106. package/views/3d/webgl-engine/collections/Component/ComponentObjectCollection.js +1 -1
  107. package/views/3d/webgl-engine/core/FBOPool.js +1 -1
  108. package/views/3d/webgl-engine/effects/RenderNodes.js +1 -1
  109. package/views/3d/webgl-engine/effects/RenderPluginManager.js +1 -1
  110. package/views/3d/webgl-engine/effects/geometry/RenderOccludedRenderNode.js +1 -1
  111. package/views/3d/webgl-engine/lib/DefaultVertexBufferLayouts.js +1 -1
  112. package/views/3d/webgl-engine/lib/SortedRenderGeometryRenderer.js +1 -1
  113. package/views/3d/webgl-engine/lib/glUtil3D.js +1 -1
  114. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  115. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  116. package/views/SceneView.js +1 -1
  117. package/views/VideoView.js +1 -1
  118. package/views/View2D.js +1 -1
  119. package/views/Viewport2DBaseMixin.js +5 -0
  120. package/views/Viewport2DMixin.js +1 -1
  121. package/views/layers/FeatureLayerView.js +1 -1
  122. package/views/support/Scheduler.js +1 -1
  123. package/views/video/VideoOperationalDataView.js +5 -0
  124. package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.js +1 -1
  125. package/widgets/BatchAttributeForm/inputs/BatchFormInputs.d.ts +4 -0
  126. package/widgets/BatchAttributeForm/inputs/BatchFormInputs.js +1 -1
  127. package/widgets/BatchAttributeForm/inputs/EditableInput.d.ts +4 -0
  128. package/widgets/BatchAttributeForm/inputs/EditableInput.js +1 -1
  129. package/widgets/BatchAttributeForm/inputs/FieldInput.d.ts +4 -0
  130. package/widgets/BatchAttributeForm/inputs/FieldInput.js +1 -1
  131. package/widgets/BatchAttributeForm/inputs/GroupInput.d.ts +4 -0
  132. package/widgets/BatchAttributeForm/inputs/GroupInput.js +1 -1
  133. package/widgets/BatchAttributeForm/inputs/InputBase.d.ts +4 -0
  134. package/widgets/BatchAttributeForm/inputs/InputBase.js +1 -1
  135. package/widgets/BatchAttributeForm/inputs/support/createBatchFormInputs.js +1 -1
  136. package/widgets/Directions.js +1 -1
  137. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  138. package/widgets/FeatureForm/EditableInput.d.ts +2 -2
  139. package/widgets/FeatureForm/FieldInput.d.ts +2 -2
  140. package/widgets/FeatureForm/GroupInput.d.ts +2 -2
  141. package/widgets/FeatureForm/InputBase.d.ts +2 -2
  142. package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
  143. package/widgets/OrientedImageryViewer/adapters/sketch/MeasurementAdapter.js +1 -1
  144. package/widgets/OrientedImageryViewer/components/ImageLocationWidget.js +1 -1
  145. package/widgets/OrientedImageryViewer/components/ImageMeasurementWidget.js +1 -1
  146. package/widgets/OrientedImageryViewer.js +1 -1
  147. package/widgets/VersionManagement/VersionManagementViewModel.js +1 -1
  148. package/widgets/VideoPlayer.js +1 -1
  149. package/widgets/support/SelectionList/FeatureItem.js +1 -1
  150. package/widgets/support/SelectionList/GroupLayerItem.js +1 -1
  151. package/widgets/support/SelectionList/LayerItem.js +1 -1
  152. package/widgets/support/SelectionList/SelectionListViewModel.js +1 -1
  153. package/widgets/support/SelectionList.js +1 -1
  154. package/widgets/support/Selector2D/SelectionOperation.js +1 -1
  155. package/assets/esri/core/workers/chunks/034950f7d0596e77a7dd.js +0 -1
  156. package/assets/esri/core/workers/chunks/0808b7b2a18331ac0cf6.js +0 -1
  157. package/assets/esri/core/workers/chunks/093938edee5f0532d7da.js +0 -1
  158. package/assets/esri/core/workers/chunks/116bbff428cc2dc1832e.js +0 -1
  159. package/assets/esri/core/workers/chunks/1646699188ed0cd4ce24.js +0 -1
  160. package/assets/esri/core/workers/chunks/2999ae2a7d4d1ad6447b.js +0 -1
  161. package/assets/esri/core/workers/chunks/3541714d448958c9bc38.js +0 -1
  162. package/assets/esri/core/workers/chunks/629a257509b148ff38c0.js +0 -1
  163. package/assets/esri/core/workers/chunks/6b5fc9da8ae34c889b83.js +0 -1
  164. package/assets/esri/core/workers/chunks/707b34e15937c4f7902f.js +0 -1
  165. package/assets/esri/core/workers/chunks/770e609a6bd3533ceda9.js +0 -1
  166. package/assets/esri/core/workers/chunks/851baab753d9c8e967bd.js +0 -1
  167. package/assets/esri/core/workers/chunks/aa6c37f116c07ddca5fb.js +0 -1
  168. package/assets/esri/core/workers/chunks/bc0c3b5a5ab3fcb8f77a.js +0 -1
  169. package/assets/esri/core/workers/chunks/cac281604a41af9b1759.js +0 -1
  170. package/assets/esri/core/workers/chunks/d25c8c30ce4058937d4f.js +0 -1
  171. package/assets/esri/core/workers/chunks/d638ae7814acf6c0fb8e.js +0 -1
  172. package/assets/esri/core/workers/chunks/d6ce99a713afdb03e332.js +0 -1
  173. package/assets/esri/core/workers/chunks/dc3816eef53d17074eab.js +0 -1
  174. package/assets/esri/core/workers/chunks/dd70b060ea4f632c2430.js +0 -1
  175. package/assets/esri/core/workers/chunks/e2e5e8bd3406609d8996.js +0 -1
  176. package/assets/esri/core/workers/chunks/f6c815f7d3ca072172ce.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.34/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import s from"../../../core/Collection.js";import{property as i}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as r}from"../../../core/accessorSupport/decorators/subclass.js";import{visibilityCodeToBoolean as o,InputVisibilityCode as l,makeUseId as a}from"./support/inputUtils.js";let p=class extends t{constructor(e){super(e),this.existsInAllLayers=!0,this.features=new s}get description(){return this.template.description}get featuresHaveSameCalculatedVisibility(){const e=new Set;for(const t of this.features){if(null==this.template.getExpressionExecutorsForLayer(t.layer)?.visibilityExpression){e.add(!0);continue}const s=this._lookupEvaluatedExpression(t,"visibility");if("success"===s?.status){if(e.add(!0===s.result),e.size>1)return!1}else e.add(!1)}return e.size<=1}get label(){return this.template.label}get layers(){return Array.from(new Set(this.features.map(e=>e.layer)))}get visibilityCode(){return this._baseVisibilityCode}get visible(){return o(this.visibilityCode)}get _baseVisibilityCode(){return this.existsInAllLayers?this.featuresHaveSameCalculatedVisibility?!1===this._evaluatedVisibilityExpression?l.HIDDEN_VISIBILITY_EXPRESSION_ALL:l.VISIBLE:l.HIDDEN_VISIBILITY_EXPRESSION_SOME:l.HIDDEN_NOT_IN_ALL_LAYERS}get _evaluatedVisibilityExpression(){let e=!0,t=!0;for(const s of this.features){if(null==this.template.getExpressionExecutorsForLayer(s.layer)?.visibilityExpression){e=e&&!0;continue}t=!1;const i=this._lookupEvaluatedExpression(s,"visibility");"success"===i?.status?e=e&&!0===i.result:e=!1}return t?null:e}_lookupEvaluatedExpression(e,t){return this.expressionsManager.evaluatedExpressions.get(e)?.get(a(this.template.elementId,t))}};e([i({constructOnly:!0})],p.prototype,"expressionsManager",void 0),e([i()],p.prototype,"description",null),e([i()],p.prototype,"existsInAllLayers",void 0),e([i()],p.prototype,"features",void 0),e([i()],p.prototype,"featuresHaveSameCalculatedVisibility",null),e([i()],p.prototype,"label",null),e([i()],p.prototype,"layers",null),e([i({constructOnly:!0})],p.prototype,"template",void 0),e([i()],p.prototype,"visibilityCode",null),e([i()],p.prototype,"visible",null),e([i()],p.prototype,"_baseVisibilityCode",null),e([i()],p.prototype,"_evaluatedVisibilityExpression",null),p=e([r("esri.widgets.BatchAttributeForm.inputs.InputBase")],p);export{p as InputBase};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import s from"../../../core/Collection.js";import{property as i}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as r}from"../../../core/accessorSupport/decorators/subclass.js";import{visibilityCodeToBoolean as o,InputVisibilityCode as l,makeUseId as a}from"./support/inputUtils.js";let p=class extends t{constructor(e){super(e),this.existsInAllLayers=!0,this.features=new s}get description(){return this.template.description}get featuresHaveSameCalculatedVisibility(){const e=new Set;for(const t of this.features){if(null==this.template.getExpressionExecutorsForLayer(t.layer)?.visibilityExpression){e.add(!0);continue}const s=this._lookupEvaluatedExpression(t,"visibility");if("success"===s?.status){if(e.add(!0===s.result),e.size>1)return!1}else e.add(!1)}return e.size<=1}get label(){return this.template.label}get layers(){return Array.from(new Set(this.features.map(e=>e.layer).filter(e=>null!=e&&("feature"===e.type||"geojson"===e.type||"scene"===e.type||"subtype-sublayer"===e.type||"oriented-imagery"===e.type))))}get visibilityCode(){return this._baseVisibilityCode}get visible(){return o(this.visibilityCode)}get _baseVisibilityCode(){return this.existsInAllLayers?this.featuresHaveSameCalculatedVisibility?!1===this._evaluatedVisibilityExpression?l.HIDDEN_VISIBILITY_EXPRESSION_ALL:l.VISIBLE:l.HIDDEN_VISIBILITY_EXPRESSION_SOME:l.HIDDEN_NOT_IN_ALL_LAYERS}get _evaluatedVisibilityExpression(){let e=!0,t=!0;for(const s of this.features){if(null==this.template.getExpressionExecutorsForLayer(s.layer)?.visibilityExpression){e=e&&!0;continue}t=!1;const i=this._lookupEvaluatedExpression(s,"visibility");"success"===i?.status?e=e&&!0===i.result:e=!1}return t?null:e}_lookupEvaluatedExpression(e,t){return this.expressionsManager.evaluatedExpressions.get(e)?.get(a(this.template.elementId,t))}};e([i({constructOnly:!0})],p.prototype,"expressionsManager",void 0),e([i()],p.prototype,"description",null),e([i()],p.prototype,"existsInAllLayers",void 0),e([i()],p.prototype,"features",void 0),e([i()],p.prototype,"featuresHaveSameCalculatedVisibility",null),e([i()],p.prototype,"label",null),e([i()],p.prototype,"layers",null),e([i({constructOnly:!0})],p.prototype,"template",void 0),e([i()],p.prototype,"visibilityCode",null),e([i()],p.prototype,"visible",null),e([i()],p.prototype,"_baseVisibilityCode",null),e([i()],p.prototype,"_evaluatedVisibilityExpression",null),p=e([r("esri.widgets.BatchAttributeForm.inputs.InputBase")],p);export{p as InputBase};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../../core/Error.js";import{BatchFormInputs as t}from"../BatchFormInputs.js";import{FieldInput as r}from"../FieldInput.js";import{GroupInput as s}from"../GroupInput.js";import{isFieldElementTemplate as n,isGroupElementTemplate as o}from"../../templates/support/templateUtils.js";function p(e,r,s){const n=e.elements.map(e=>m(e,r,s));return new t({inputs:n,template:e})}function m(t,p,a){const l=new Set(t.layers),i=p.filter(e=>l.has(e.layer)),u=i.length===p.length;if(n(t))return new r({existsInAllLayers:u,features:i,template:t,expressionsManager:a});if(o(t)){const e=t.elements.map(e=>m(e,p,a));return new s({existsInAllLayers:u,features:i,inputs:e,template:t,expressionsManager:a})}throw new e("batch-attribute-form:unsupported-element-template","The type of form element template provided is not supported")}export{p as createBatchFormInputsFromBatchFormTemplate};
5
+ import e from"../../../../core/Error.js";import t from"../BatchFormInputs.js";import r from"../FieldInput.js";import s from"../GroupInput.js";import{isFieldElementTemplate as n,isGroupElementTemplate as o}from"../../templates/support/templateUtils.js";function p(e,r,s){const n=e.elements.map(e=>m(e,r,s));return new t({inputs:n,template:e})}function m(t,p,a){const l=new Set(t.layers),i=p.filter(e=>l.has(e.layer)),u=i.length===p.length;if(n(t))return new r({existsInAllLayers:u,features:i,template:t,expressionsManager:a});if(o(t)){const e=t.elements.map(e=>m(e,p,a));return new s({existsInAllLayers:u,features:i,inputs:e,template:t,expressionsManager:a})}throw new e("batch-attribute-form:unsupported-element-template","The type of form element template provided is not supported")}export{p as createBatchFormInputsFromBatchFormTemplate};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import{isSome as t}from"../core/arrayUtils.js";import i from"../core/Collection.js";import{addEventListener as s}from"../core/events.js";import{makeHandle as o}from"../core/handleUtils.js";import{destroyMaybe as r}from"../core/maybe.js";import{debounce as n,isAbortError as a}from"../core/promiseUtils.js";import{watch as l,initial as c,on as d}from"../core/reactiveUtils.js";import{escapeRegExpString as h}from"../core/string.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import{onLocaleChange as u,getLocaleLanguage as v}from"../intl/locale.js";import _ from"../portal/Portal.js";import{defaultUnitPropertyMetadata as g}from"../properties/defaultUnit.js";import w from"../rest/support/Stop.js";import y from"../symbols/SimpleMarkerSymbol.js";import b from"./Search.js";import S from"./Widget.js";import{css as f}from"./Directions/css.js";import{DirectionsSearchTool as k}from"./Directions/DirectionsSearchTool.js";import C from"./Directions/DirectionsViewModel.js";import D from"./Directions/DirectionsVisibleElements.js";import{formatDistance as M,formatDuration as I,DepartureTimeOption as T,getIconName as F}from"./Directions/support/directionsUtils.js";import{isArcGISWorldGeocoder as P,meteredArcGISLocatorUrl as x}from"./Search/support/locatorUtils.js";import{loadCalciteComponents as E}from"./support/componentsUtils.js";import{globalCss as R}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as L}from"./support/decorators/messageBundle.js";import{tsx as A}from"./support/jsxFactory.js";function O(e){const{branchName:i,displayText:s,exitName:o,intersectingName:r,name:n,towardName:a}=e;if(null==s)return null;const l=[i,o,r,n,a].filter(t).sort((e,t)=>t.length-e.length).map(e=>h(e));if(!l.length)return s;const c=new RegExp(l.join("|"),"g"),d=s.matchAll(c);let p=0;const m=[];for(const{0:t,index:h}of d)m.push(s.slice(p,h),A("span",{class:f.labelEmphasize,key:`maneuver-${h}`},t)),p=h+t.length;return m.push(s.slice(p)),A("span",null,m)}let N=class extends S{constructor(e,t){super(e,t),this._activeManeuver=null,this._placeholderStops=new i([new w,new w]),this._portalFolderCombobox=null,this._portalFolders=null,this._portalItemNameInput=null,this._portalUserName=null,this._printDocument=null,this._printDocumentParent=null,this._sections=null,this._stopsToSearches=new Map,this._printDocumentOpen=!1,this._currentFlowItem="primary",this._parentFlowItem="primary",this._saveState="initialized",this._searchTool=null,this.headingLevel=2,this.messages=null,this.messagesUnits=null,this.searchProperties=null,this.viewModel=new C,this.visibleElements=new D,this._solveRouteDebounced=n(()=>this._solveRoute())}initialize(){this.addHandles([l(()=>this.viewModel.layer,()=>{try{this.viewModel.load()}catch{}},c),l(()=>this.viewModel.layer?.routeInfo,()=>{this._sections=this._getStopSections()},c),l(()=>this.viewModel.layer?.stops.toArray(),e=>{e&&this.view?.activeTool&&this._searchTool&&this.view.activeTool===this._searchTool&&!e.includes(this._searchTool.stop)&&(this.view.tools.remove(this._searchTool),this._searchTool=null)}),s(window,"beforeprint",this._beforePrint.bind(this)),s(window,"afterprint",this._afterPrint.bind(this))])}loadDependencies(){return E({accordion:()=>import("@esri/calcite-components/dist/components/calcite-accordion"),"accordion-item":()=>import("@esri/calcite-components/dist/components/calcite-accordion-item"),action:()=>import("@esri/calcite-components/dist/components/calcite-action"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu"),"block-section":()=>import("@esri/calcite-components/dist/components/calcite-block-section"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),panel:()=>import("@esri/calcite-components/dist/components/calcite-panel"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch")})}destroy(){this._stopsToSearches.forEach(r)}get apiKey(){return this.viewModel.apiKey}set apiKey(e){this.viewModel.apiKey=e}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get icon(){return"right"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get lastRoute(){return this.viewModel.lastRoute}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get maxStops(){return this.viewModel.maxStops}set maxStops(e){this.viewModel.maxStops=e}get unit(){return this.defaultUnit}set unit(e){this._overrideIfSome("unit",e)}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const i=this._stopsToSearches.get(e);return i.view=t,this._overrideDefaultSources(i),i}const i=new b({icon:"",popupEnabled:!1,resultGraphicEnabled:!1,view:t,...this.searchProperties});return this._normalizeSearchSources(i),this.addHandles([d(()=>i.allSources,"change",()=>this._normalizeSearchSources(i)),i.on("search-clear",()=>{e.geometry=null,e.name=null,this.viewModel.layer?.removeResult()}),i.on("select-result",()=>{const t=i.selectedResult;e.geometry=t?.feature.geometry,e.name=t?.name,this._solveRouteDebounced()}),l(()=>i.searchTerm,t=>{e.name=t}),u(()=>this._normalizeSearchSources(i))],i),this._stopsToSearches.set(e,i),i}getDirections(){return this.viewModel.getDirections()}render(){return A("div",{class:this.classes(f.base,R.widget,R.panel)},A("calcite-flow",null,this._renderPrimaryFlowItem(),this._renderDirectionsFlowItem(),this._renderEditFlowItem(),this._renderSaveFlowItem()),this._renderPrintDocument())}save(){return this.viewModel.save()}saveAs(e,t={}){return this.viewModel.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_afterPrint(){this._printDocumentOpen&&this._printDocument&&this._printDocumentParent?.appendChild(this._printDocument)}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.language=v(),t.locationType??="street",P(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=x))}_beforePrint(){this._printDocumentOpen&&this._printDocument&&document.body.appendChild(this._printDocument)}_disposeSearch(e){if(!e||!this._stopsToSearches.has(e))return;const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}_getEffectiveStops(){return this.viewModel.layer?.stops??this._placeholderStops}_getErrorDescription(){switch(this.viewModel.lastError?.name){case"directions-view-model:unable-to-route":return this.messages.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return this.messages.errors.unableToLoadServiceMetadata;default:return this.messages.errors.unknownError}}_getNetworkFeatureName(e){switch(e.type){case"stop":switch(e.locationType){case"stop":default:return this.messages.networkFeatures.stops.stop;case"waypoint":return this.messages.networkFeatures.stops.waypoint;case"break":return this.messages.networkFeatures.stops.break}case"point-barrier":return this.messages.networkFeatures.pointBarrier;case"polyline-barrier":return this.messages.networkFeatures.polylineBarrier;case"polygon-barrier":return this.messages.networkFeatures.polygonBarrier}}_getRouteCostSummary(){const e=this.viewModel.layer?.routeInfo;if(!e)return null;const t=e.totalDistance??0,i=e.totalDuration??0,{messagesUnits:s,unit:o}=this;return{distance:M(s,t,o),duration:I(i)}}_getStopCostDescription(e){if(!e.directions.length)return;const{totalDistance:t,totalDuration:i}=e.directions.reduce((e,{lines:t})=>{for(const{distance:i,duration:s}of t)e.totalDistance+=i??0,e.totalDuration+=s??0;return e},{totalDistance:0,totalDuration:0}),{messagesUnits:s,unit:o}=this,r=M(s,t,o);return`${I(i)} (${r})`}_getStopSections(){if(!this.viewModel.layer)return null;const{directionPoints:e,directionLines:t,stops:i}=this.viewModel.layer;if(!e||!t)return null;const s=[];let o=null;for(const r of e){const{objectId:e,stopId:n}=r;if(null!=n){const e=i.find(({objectId:e})=>e===n);o&&o.stop===e||(o={stop:e,directions:[]},s.push(o));continue}if(null==o)continue;const a=t.toArray().filter(({directionPointId:t})=>t===e);0!==a.length&&o.directions.push({directionPoint:r,lines:a})}return s}_handleAddStopClick(){const e=new y;this.viewModel.layer?.stops.add(new w({symbol:e}))}_handleAutoSolveChange({target:e}){this.viewModel.autoSolve=e.checked}_handleCreatePolylineBarrierClick(){this.viewModel.create("polyline-barrier")}_handleClearRouteClick(){this._currentFlowItem="primary",this.viewModel.reset()}_handleCreateStopClick(){this.viewModel.create("stop")}_handleDeleteNetworkFeatureClick(e){this.viewModel.remove(e),this.viewModel.autoSolve&&this._solveRouteDebounced()}_handleDeleteStopClick(e){this._getEffectiveStops().remove(e),this._disposeSearch(e),this._solveRouteDebounced()}_handleDepartureDateChange({currentTarget:{value:e}}){Array.isArray(e)||(this.viewModel.departureIsoDate=e,this._solveRouteDebounced())}_handleDepartureTimeChange({currentTarget:{value:e}}){this.viewModel.departureIsoTime=e,this._solveRouteDebounced()}_handleDepartureTimeOptionChange({currentTarget:e}){const{selectedItems:t}=e;t.length&&(this.viewModel.departureOption=t[0].value,this._solveRouteDebounced())}_handleDirectionsFlowItemBackClick(e){e.stopPropagation(),this._currentFlowItem="primary"}_handleDirectionTurnItemSelect(e){this._activeManeuver===e?this.zoomToRoute():(this._activeManeuver=e,this.viewModel.centerAt(e.geometry))}_handleDirectionTurnPointerEnter(e){this.viewModel.highlight(e)}_handleDirectionTurnPointerLeave(){this.viewModel.clearHighlights()}_handleEditFlowItemBackClick(e){e.stopPropagation(),this.viewModel.stopEditing(),this._currentFlowItem="primary"}_handleEditingDoneClick(){this.viewModel.stopEditing(),this._currentFlowItem="primary"}_handleEditRouteClick(){this._currentFlowItem="edit",this.viewModel.startEditing()}_handleItemDetailsClick(){const e=this.viewModel.layer?.portalItem;e&&window.open(`${e.portal.url}/home/item.html?id=${e.id}`,"_blank")}_handleLocateStopClick(e){const{view:t}=this;if(!t)return;const i="directions-search-tool";this.removeHandles(i),this._searchTool=new k({stop:e,view:t}),this.addHandles([this._searchTool.on("click",async t=>{if(t.mapPoint&&this._stopsToSearches.has(e)){const i=this._stopsToSearches.get(e),s=await i.search(t.mapPoint),o=s?.results?.[0].results?.[0];if(o){const{feature:t,name:s}=o;i.searchTerm=s,e.geometry=t.geometry}}this.removeHandles(i)}),o(()=>{this._searchTool&&(this.view?.tools.remove(this._searchTool),this._searchTool=null)})],i),t.addAndActivateTool(this._searchTool)}_handleOptimizeStopOrderToggle({target:{expanded:e}}){this.viewModel.routeParameters.findBestSequence=e,this._solveRouteDebounced()}_handlePanToStopClick(e){this.viewModel.centerAt(e)}_handlePreserveFirstStopChange({target:{checked:e}}){this.viewModel.routeParameters.preserveFirstStop=e,this._solveRouteDebounced()}_handlePreserveLastStopChange({target:{checked:e}}){this.viewModel.routeParameters.preserveLastStop=e,this._solveRouteDebounced()}_handlePrintDocumentAfterCreate(e){e.focus(),this._printDocument=e,this._printDocumentParent=e.parentElement}_handlePrintDocumentClick(){this._printDocumentOpen=!0}_handlePrintDocumentCloseClick(){this._printDocumentOpen=!1}_handlePrintDocumentKeyDown(e){"Escape"===e.key&&(this._printDocumentOpen=!1)}_handlePrintDocumentPrintClick(){document.body.classList.add(f.printMedia),window.print(),document.body.classList.remove(f.printMedia)}_handleResolveRouteClick(){this._solveRouteDebounced()}_handleReverseStopOrderClick(){this._getEffectiveStops().reverse(),this._solveRouteDebounced()}_handleSaveErrorCloseClick(){this._currentFlowItem=this._parentFlowItem}_handleSaveFlowItemBackClick(e){e.stopPropagation(),this._currentFlowItem=this._parentFlowItem}async _handleSaveLayerAs(){const e=_.getDefault();try{await e.signIn()}catch(t){if(a(t)||"identity-manager:user-aborted"===t.name)return;return this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",void(this._saveState="connect-to-portal-error")}this._saveState="fetch-portal-information",this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",this._portalUserName=e.user?.username;try{this._portalFolders=await(e.user?.fetchFolders())}catch{return void(this._saveState="fetch-portal-information-error")}this._saveState="save-layer"}_handleSaveLayerClick(){this.viewModel.layer?.save()}_handleSaveLayerButtonClick(){this._saveState="saving";const{layer:e}=this;if(!e||!this._portalFolders)return;const t=this._portalItemNameInput?.value,i=this._portalFolderCombobox?.value,s=this._portalFolders.find(({id:e})=>e===i);e.saveAs({title:t},{folder:s}).then(()=>{e.title=t,this._currentFlowItem=this._parentFlowItem}).catch(()=>{this._saveState="saving-error"})}_handleSaveLayerCancelClick(){this._currentFlowItem=this._parentFlowItem}_handleSaveLayerFolderCreate(e){this._portalFolderCombobox=e}_handleSaveLayerNameCreate(e){this._portalItemNameInput=e}_handleSignInClick(){this.viewModel.load().catch(()=>{})}_handleStopListReorder({detail:{dragEl:e,newIndex:t}}){this._getEffectiveStops().reorder(e.value,t),this._solveRouteDebounced()}_handleTravelModeChange({currentTarget:{selectedItems:e}}){e.length&&(this.viewModel.selectedTravelMode=e[0].value,this._solveRouteDebounced())}_handleViewDrivingDirectionsClick(){this._currentFlowItem="directions"}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){for(const t of e.viewModel.defaultSources)t.autoNavigate=!1}_renderClearRouteAction(e){return A("calcite-action",{bind:this,icon:"trash",key:"clear-route",onclick:this._handleClearRouteClick,...e,text:this.messages.common.clear,textEnabled:!0})}_renderDeleteStopAction(e){return A("calcite-action",{icon:"trash",onclick:this._handleDeleteStopClick.bind(this,e),scale:"s",slot:"actions-end",text:this.messages.deleteStop,title:this.messages.deleteStop})}_renderDepartureTime(){const{DEPART_AT:e,NOW:t,UNSPECIFIED:i}=T;return A("calcite-label",{class:f.departureTime,key:"departure-time"},this.messages.departureTime,A("calcite-combobox",{bind:this,clearDisabled:!0,label:this.messages.departureTime,overlayPositioning:"fixed",selectionMode:"single-persist",onCalciteComboboxChange:this._handleDepartureTimeOptionChange},A("calcite-combobox-item",{heading:this.messages.leaveNow,key:t,label:this.messages.leaveNow,selected:this.viewModel.departureOption===t,value:t}),A("calcite-combobox-item",{heading:this.messages.departAt,key:e,label:this.messages.departAt,selected:this.viewModel.departureOption===e,value:e}),A("calcite-combobox-item",{heading:this.messages.timeUnspecified,key:i,label:this.messages.timeUnspecified,selected:this.viewModel.departureOption===i,value:i})))}_renderDepartureTimeOptions(){return this.viewModel.departureOption!==T.DEPART_AT?null:A("div",{class:f.departureTimeOptions},A("calcite-input-date-picker",{bind:this,scale:"s",value:this.viewModel.departureIsoDate,onCalciteInputDatePickerChange:this._handleDepartureDateChange}),A("calcite-input-time-picker",{bind:this,scale:"s",value:this.viewModel.departureIsoTime,onCalciteInputTimePickerClose:this._handleDepartureTimeChange}))}_renderDirectionsFlowItem(){if("directions"!==this._currentFlowItem)return null;const e=this._getRouteCostSummary();if(!this._sections||!e)return null;const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel,o=this._sections.at(0)?.stop.name??"",r=this._sections.at(-1)?.stop.name??"";return A("calcite-flow-item",{bind:this,key:"directions-flow-item",overlayPositioning:"fixed",selected:"directions"===this._currentFlowItem,onCalciteFlowItemBack:this._handleDirectionsFlowItemBackClick},A("div",{class:f.directionsHeader,slot:"header-content"},A("div",{class:f.headerStops},A("span",null,this.messages.from)," ",A("span",{class:f.directionsHeaderStopName},o),A("span",null,this.messages.to)," ",A("span",{class:f.directionsHeaderStopName},r)),A("div",{class:f.flexColumn},A("span",null,`${i} (${t})`),s?A("span",null,s):null)),this._renderRouteLayerActions({slot:"header-menu-actions"}),A("calcite-accordion",{class:f.accordion,iconPosition:"start",selectionMode:"single"},this._sections.map((e,t)=>this._renderDirectionSection(e,t))))}_renderDirectionSection(e,t){const{stop:i,directions:s}=e,{name:o}=i,r=0===t,n=this._getStopCostDescription(e);return A("calcite-accordion-item",{description:n,expanded:r,heading:o??"",key:`stop-${t}`},A("calcite-action",{icon:"zoom-to-object",onclick:this._handlePanToStopClick.bind(this,i),slot:"actions-end",text:this.messages.panToStop,title:this.messages.panToStop}),this._renderDirectionTurns(s))}_renderDirectionTurns(e){return A("calcite-list",{label:this.messages.drivingDirections,selectionMode:"none"},e.map((e,t)=>{const{directionPoint:i,lines:s}=e,o=s[0],{distance:r,duration:n}=o,a=M(this.messagesUnits,r??0,this.unit),l=I(n??0),c=a&&l?`${a} | ${l}`:`${a||l}`,d=O(i),h=F(i.directionPointType);return A("calcite-list-item",{class:f.labelNoBottomMargin,key:`driving-direction-${t}`,onpointerenter:this._handleDirectionTurnPointerEnter.bind(this,o),onpointerleave:this._handleDirectionTurnPointerLeave.bind(this),onCalciteListItemSelect:this._handleDirectionTurnItemSelect.bind(this,o)},A("calcite-icon",{icon:h,slot:"content-start"}),A("div",{slot:"content"},A("calcite-label",{layout:"inline",scale:"s"},d),A("calcite-label",{layout:"inline",scale:"s"},c)))}))}_renderEditFlowItem(){return"edit"!==this._currentFlowItem?null:A("calcite-flow-item",{bind:this,heading:this.messages.editRoute,headingLevel:this.headingLevel,key:"edit-flow-item",loading:"routing"===this.viewModel.state,selected:"edit"===this._currentFlowItem,onCalciteFlowItemBack:this._handleEditFlowItemBackClick},A("div",{class:f.flexColumn,key:"edit-container"},A("div",{class:f.editToolbarContainer},A("calcite-label",{layout:"inline",scale:"s"},this.messages.automaticallySolve,A("calcite-switch",{bind:this,checked:this.viewModel.autoSolve,scale:"s",onCalciteSwitchChange:this._handleAutoSolveChange})),A("div",{class:f.editToolbar},A("calcite-action",{bind:this,disabled:!this.viewModel.layer||this.viewModel.layer.stops.length>=this.maxStops,icon:"flag",onclick:this._handleCreateStopClick,scale:"s",text:this.messages.networkFeatures.stops.stop,textEnabled:!0}),A("calcite-action",{bind:this,icon:"line",onclick:this._handleCreatePolylineBarrierClick,scale:"s",text:this.messages.barrier,textEnabled:!0}),A("calcite-action",{bind:this,class:f.solveRoute,disabled:this.viewModel.autoSolve,icon:"refresh",onclick:this._handleResolveRouteClick,scale:"s",text:this.messages.solve,textEnabled:!0}))),A("div",{class:f.selectedFeatureContainer},A("calcite-list",{label:this.messages.selectedNetworkFeatures,scale:"s",selectionMode:"none"},this.viewModel.selectedNetworkFeatures?.toArray().map((e,t)=>A("calcite-list-item",{description:this._getNetworkFeatureName(e),key:`network-feature-${t}`,label:e.name??e.objectId?.toString()??this.messages.unnamed},A("calcite-action",{icon:"trash",onclick:this._handleDeleteNetworkFeatureClick.bind(this,e),scale:"s",slot:"actions-end",text:this.messages.common.delete}))))),A("div",{class:f.editFooter},this._renderEditFooterContent())))}_renderEditFooterContent(){return this.viewModel.lastError?this._renderErrorNotice():A("calcite-button",{appearance:"outline-fill",bind:this,onclick:this._handleEditingDoneClick,width:"full"},this.messages.common.done)}_renderErrorNotice(){return A("calcite-notice",{icon:"exclamation-mark-circle",kind:"danger",open:!0},A("calcite-label",{class:f.labelNoBottomMargin,slot:"message"},this._getErrorDescription()))}_renderFooter(){if(!this.viewModel.layer)return A("div",{class:f.primaryFooter,key:"footer-missing-layer"},A("calcite-notice",{icon:"information",open:!0},A("calcite-label",{class:f.labelNoBottomMargin,slot:"message"},this.messages.missingLayer)));if("unauthenticated"===this.viewModel.state)return A("div",{class:f.primaryFooterCentered,key:"footer-sign-in"},A("calcite-label",null,this.messages.signInRequired),A("calcite-button",{bind:this,onclick:this._handleSignInClick},this.messages.common.auth.signIn));if("routing"===this.viewModel.state)return A("div",{class:this.classes(f.primaryFooter,f.primaryFooterLoader),key:"footer-routing"},A("calcite-loader",{label:this.messages.solve,scale:"s"}));if("error"===this.viewModel.state)return A("div",{class:f.primaryFooter,key:"footer-service-error"},this._renderErrorNotice());if(!this.viewModel.layer?.routeInfo)return A("div",{class:f.primaryFooter,key:"footer-unsolved-route"},A("calcite-notice",{icon:"information",open:!0},A("calcite-label",{class:f.labelNoBottomMargin,slot:"message"},this.messages.directionsPlaceholder)));const e=this._getRouteCostSummary();if(!e||!this.viewModel.layer?.directionPoints)return A("div",{class:f.primaryFooter,key:"footer-invalid-route"},A("calcite-notice",{icon:"exclamation-mark-triangle",kind:"danger",open:!0},A("calcite-label",{class:f.labelNoBottomMargin,slot:"message"},this.messages.invalidRoute)));const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel;return A("div",{class:f.routeItem,key:"footer-directions-summary"},A("button",{"aria-busy":"false","aria-label":this.messages.viewDrivingDirections,"aria-live":"polite",bind:this,class:f.routeItemButton,onclick:this._handleViewDrivingDirectionsClick,title:this.messages.viewDrivingDirections,type:"button"},A("div",{class:f.routeItemButtonContent},A("span",{class:f.routeItemLabel},`${i} (${t})`),A("span",{class:f.routeItemDescription},s)),A("calcite-icon",{flipRtl:!0,icon:"chevron-right",scale:"s"})),A("calcite-action-menu",{label:"test"},A("calcite-action",{icon:"ellipsis",key:"route-actions",slot:"trigger",text:"Route actions"}),this._renderRouteLayerActions()))}_renderInteractiveRouteActions(){return A("div",{class:f.actionContainer,key:f.actionContainer},A("calcite-button",{appearance:"outline",bind:this,class:f.addStopButton,disabled:this._getEffectiveStops().length>=this.maxStops,iconStart:"plus",kind:"neutral",label:this.messages.addStop,onclick:this._handleAddStopClick,title:this.messages.addStop,width:"half"},this.messages.addStop),this.visibleElements.editRouteButton?A("calcite-button",{appearance:"outline",bind:this,class:f.editRouteButton,disabled:"2d"!==this.viewModel.view?.type,iconStart:"pencil",kind:"neutral",label:this.messages.editRoute,onclick:this._handleEditRouteClick,title:this.messages.editRoute,width:"half"},this.messages.editRoute):null)}_renderLocateStopAction(e){if(null!=e.name||null!=e.geometry)return null;const t=this._getEffectiveStops().indexOf(e),i=!!this.view?.activeTool&&this.view.activeTool===this._searchTool&&this._searchTool.stop===e;return A("calcite-action",{active:i,icon:"crosshair",key:`stop-location-action-${t}`,onclick:this._handleLocateStopClick.bind(this,e),scale:"s",slot:"actions-end",text:this.messages.pickALocationOnTheMap,title:this.messages.pickALocationOnTheMap})}_renderOptimizeStopOrder(){const{routeParameters:e}=this.viewModel,{findBestSequence:t,preserveFirstStop:i,preserveLastStop:s}=e;return A("calcite-block-section",{bind:this,class:f.optimizeSection,text:this.messages.optimizeOrder,toggleDisplay:"switch",onCalciteBlockSectionToggle:this._handleOptimizeStopOrderToggle},t?[A("calcite-label",{class:f.optimizeSwitches,key:"preserve-first-stop",layout:"inline-space-between"},this.messages.preserveFirstStop,A("calcite-switch",{bind:this,checked:i,scale:"s",onCalciteSwitchChange:this._handlePreserveFirstStopChange})),A("calcite-label",{class:f.optimizeSwitches,key:"preserve-last-stop",layout:"inline-space-between"},this.messages.preserveLastStop,A("calcite-switch",{bind:this,checked:s,scale:"s",onCalciteSwitchChange:this._handlePreserveLastStopChange}))]:null)}_renderPrimaryFlowItem(){return A("calcite-flow-item",{key:"primary-flow-item",loading:"initializing"===this.viewModel.state,selected:"primary"===this._currentFlowItem},A("calcite-panel",{class:f.primaryFlowItem,disabled:!this.viewModel.layer||"unauthenticated"===this.viewModel.state||"error"===this.viewModel.state&&!this.viewModel.serviceDescription},this._renderStops(),this._renderInteractiveRouteActions(),this._renderSeparator(),this._renderRouteSolveOptions()),this._renderFooter())}_renderPrintDocument(){if(!this._printDocumentOpen)return null;const e=this._getRouteCostSummary();if(!this._sections||!e)return null;const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel,o=this._sections.at(0)?.stop.name??"",r=this._sections.at(-1)?.stop.name??"";return A("div",{afterCreate:this._handlePrintDocumentAfterCreate,bind:this,class:f.printDocument,onkeydown:this._handlePrintDocumentKeyDown,tabindex:0},A("div",{class:f.printBody},A("div",{class:f.printHeader},A("div",{class:f.printHeaderLabel},A("div",{class:f.headerStops},A("span",null,this.messages.from)," ",A("span",{class:f.directionsHeaderStopName},o),A("span",null,this.messages.to)," ",A("span",{class:f.directionsHeaderStopName},r))),A("div",{class:this.classes(f.printHeaderButtons,f.printHideOnPrint)},A("calcite-button",{class:f.printDocumentPrint,iconStart:"print",onclick:this._handlePrintDocumentPrintClick},this.messages.common.print),A("calcite-button",{appearance:"outline",bind:this,class:f.printDocumentClose,iconStart:"x-circle",onclick:this._handlePrintDocumentCloseClick},this.messages.common.close))),A("div",{class:f.directionsHeader},A("span",null,`${i} (${t})`),s?A("span",null,s):null),this._sections.map((e,t)=>this._renderPrintSection(e,t))))}_renderPrintManuever(e,t){const{directionPoint:i,lines:s}=e,{distance:o,duration:r}=s.at(0)??{},n=M(this.messagesUnits,o??0,this.unit),a=I(r??0),l=n&&a?`${n} | ${a}`:`${n||a}`,c=O(i),d=F(i.directionPointType);return A("div",{class:this.classes(f.flexRow,f.printAvoidPageBreak),key:`direction-${t}`},A("calcite-icon",{icon:d}),A("div",{class:f.flexColumn},A("span",null,c),A("span",null,l)))}_renderPrintRouteAction(e){if(!this.visibleElements.printButton)return null;const t=!this.viewModel.layer?.routeInfo;return A("calcite-action",{bind:this,disabled:t,icon:"print",key:"print-route",onclick:this._handlePrintDocumentClick,...e,text:this.messages.common.print,textEnabled:!0})}_renderPrintSection({stop:e,directions:t},i){return A("div",{class:f.printSection,key:`section-${i}`},A("span",{class:f.directionsHeaderStopName},e.name??""),t.map((e,t)=>this._renderPrintManuever(e,t)))}_renderRouteLayerActions(e){return[this._renderClearRouteAction(e),this._renderSaveLayerAction(e),this._renderSaveLayerAsAction(e),this._renderPrintRouteAction(e),this._renderViewItemDetailsAction(e)]}_renderRouteSolveOptions(){return A("div",{class:f.marginInlineMedium,key:"route-solve-options"},this._renderTravelModes(),this._renderDepartureTime(),this._renderDepartureTimeOptions(),this._renderOptimizeStopOrder())}_renderSaveContent(){switch(this._saveState){case"initialized":return this._renderSaveInitialized();case"connect-to-portal":return this._renderSaveProcessing(this.messages.identity.lblSigning);case"connect-to-portal-error":return this._renderSaveError(this.messages.errors.authenticating);case"fetch-portal-information":return this._renderSaveProcessing(this.messages.processing.fetching);case"fetch-portal-information-error":return this._renderSaveError(this.messages.errors.fetching);case"save-layer":return this._renderSaveLayerSettings();case"saving":return this._renderSaveProcessing(this.messages.processing.saving);case"saving-error":return this._renderSaveError(this.messages.errors.saving)}}_renderSaveError(e){return A("calcite-panel",{class:f.paddingMedium,key:"save-layer-error"},A("div",{class:f.saveError},A("calcite-icon",{class:f.saveErrorIcon,icon:"exclamation-mark-triangle",scale:"l",textLabel:this.messages.common.errorMessage}),A("calcite-label",{class:f.saveErrorLabel},e)),A("calcite-button",{appearance:"outline",bind:this,onclick:this._handleSaveErrorCloseClick,slot:"footer-actions",width:"full"},this.messages.common.close))}_renderSaveInitialized(){return A("calcite-panel",{class:f.paddingMedium,key:"save-layer-initialized"})}_renderSaveFlowItem(){return"save"!==this._currentFlowItem?null:A("calcite-flow-item",{bind:this,heading:this.messages.saveLayer,headingLevel:this.headingLevel,key:"save-layer-flow-item",selected:"save"===this._currentFlowItem,onCalciteFlowItemBack:this._handleSaveFlowItemBackClick},this._renderSaveContent())}_renderSaveLayerAction(e){if(!this.visibleElements.saveButton)return null;const t=this.viewModel.layer,i=t?.routeInfo,s=t?.portalItem?.itemControl;return A("calcite-action",{bind:this,disabled:!(!!i&&("admin"===s||"update"===s)),icon:"save",key:"save-route",onclick:this._handleSaveLayerClick,...e,text:this.messages.common.save,textEnabled:!0})}_renderSaveLayerAsAction(e){if(!this.visibleElements.saveAsButton)return null;const t=!this.viewModel.layer?.routeInfo;return A("calcite-action",{disabled:t,icon:"save-as",key:"save-as-route",onclick:()=>{this._handleSaveLayerAs()},...e,text:this.messages.common.saveAs,textEnabled:!0})}_renderSaveLayerSettings(){if(null==this.layer||null==this._portalFolders||null==this._portalUserName)return this._renderSaveInitialized();const{stops:e}=this.layer,t=`${e.at(0).name} - ${e.at(-1).name}`,i=[A("calcite-combobox-item",{heading:`${this._portalUserName} (${this.messages.common.home})`,key:f.folderHome,selected:!0,value:f.folderHome}),...this._portalFolders.map(e=>A("calcite-combobox-item",{heading:e.title??"",key:`${f.folder}-${e.id}`,value:e.id}))];return A("calcite-panel",{key:"save-layer-panel"},A("div",{class:f.paddingMedium},A("calcite-label",null,this.messages.layerName,A("calcite-input",{afterCreate:this._handleSaveLayerNameCreate,bind:this,label:this.messages.layerName,value:t})),A("calcite-label",null,this.messages.saveInFolder,A("calcite-combobox",{afterCreate:this._handleSaveLayerFolderCreate,bind:this,clearDisabled:!0,label:this.messages.saveInFolder,overlayPositioning:"fixed",selectionMode:"single-persist"},i))),A("calcite-button",{bind:this,onclick:this._handleSaveLayerButtonClick,slot:"footer-actions",width:"full"},this.messages.common.save),A("calcite-button",{appearance:"outline",bind:this,onclick:this._handleSaveLayerCancelClick,slot:"footer-actions",width:"full"},this.messages.common.cancel))}_renderSaveProcessing(e){return A("calcite-panel",{class:f.marginInlineMedium,key:"save-layer-processing"},A("calcite-loader",{class:f.saveProcessLoader,label:e,text:e}))}_renderSeparator(){return A("div",{class:f.separator})}_renderStop(e){const t=this.acquireSearch(e);null!=e.name&&(t.searchTerm=e.name);const i=this._getEffectiveStops(),s=this._renderLocateStopAction(e),o=i.length>2&&this._renderDeleteStopAction(e);return A("calcite-list-item",{key:e,value:e},s,o,A("div",{class:f.stopItem,slot:"content"},t.render()))}_renderStops(){const e=this._getEffectiveStops();for(const t of this._stopsToSearches.keys())e.includes(t)||this._disposeSearch(t);return A("div",{class:f.stopContainer,key:f.stopContainer},A("calcite-list",{bind:this,class:f.stopList,dragEnabled:!0,label:this.messages.widgetLabel,scale:"s",onCalciteListOrderChange:this._handleStopListReorder},e.toArray().map(e=>this._renderStop(e))),2===e.length&&A("calcite-action",{bind:this,icon:"arrow-up-down",onclick:this._handleReverseStopOrderClick,scale:"s",text:this.messages.reverseStops,title:this.messages.reverseStops}))}_renderTravelMode(e){const{id:t,name:i}=e;return A("calcite-combobox-item",{heading:i,key:t,label:i,selected:this.viewModel.selectedTravelMode?.id===t,value:e})}_renderTravelModes(){return this.viewModel.travelModes.length?A("calcite-label",{key:"travel-modes"},this.messages.mode,A("calcite-combobox",{bind:this,clearDisabled:!0,label:this.messages.mode,overlayPositioning:"fixed",selectionMode:"single-persist",onCalciteComboboxChange:this._handleTravelModeChange},this.viewModel.travelModes.map(e=>this._renderTravelMode(e)))):null}_renderViewItemDetailsAction(e){return this.visibleElements.layerDetails?A("calcite-action",{bind:this,disabled:!this.viewModel.layer?.portalItem,icon:"launch",key:"open-route-details-link",onclick:this._handleItemDetailsClick,...e,text:this.messages.viewLayerDetails,textEnabled:!0}):null}async _solveRoute(){this.viewModel.updateDepartureTime();if(!((this.viewModel.layer?.stops.filter(({geometry:e})=>!!e).length??0)<2))try{await this.viewModel.getDirections()}catch{}}};e([p()],N.prototype,"_printDocumentOpen",void 0),e([p()],N.prototype,"_currentFlowItem",void 0),e([p()],N.prototype,"_saveState",void 0),e([p()],N.prototype,"_searchTool",void 0),e([p()],N.prototype,"apiKey",null),e([p(g)],N.prototype,"defaultUnit",void 0),e([p()],N.prototype,"goToOverride",null),e([p()],N.prototype,"headingLevel",void 0),e([p()],N.prototype,"icon",null),e([p()],N.prototype,"label",null),e([p({readOnly:!0})],N.prototype,"lastRoute",null),e([p()],N.prototype,"layer",null),e([p()],N.prototype,"maxStops",null),e([p(),L("esri/widgets/Directions/t9n/Directions")],N.prototype,"messages",void 0),e([p(),L("esri/core/t9n/Units")],N.prototype,"messagesUnits",void 0),e([p()],N.prototype,"searchProperties",void 0),e([p()],N.prototype,"unit",null),e([p()],N.prototype,"view",null),e([p({type:C})],N.prototype,"viewModel",void 0),e([p({type:D,nonNullable:!0})],N.prototype,"visibleElements",void 0),N=e([m("esri.widgets.Directions")],N);const j=N;export{j as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import{isSome as t}from"../core/arrayUtils.js";import i from"../core/Collection.js";import{addEventListener as s}from"../core/events.js";import{makeHandle as o}from"../core/handleUtils.js";import{destroyMaybe as r}from"../core/maybe.js";import{debounce as n,isAbortError as a}from"../core/promiseUtils.js";import{watch as l,initial as c,on as d}from"../core/reactiveUtils.js";import{escapeRegExpString as h}from"../core/string.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import{onLocaleChange as u,getLocaleLanguage as v}from"../intl/locale.js";import _ from"../portal/Portal.js";import{defaultUnitPropertyMetadata as g}from"../properties/defaultUnit.js";import w from"../rest/support/Stop.js";import y from"../symbols/SimpleMarkerSymbol.js";import b from"./Search.js";import S from"./Widget.js";import{css as f}from"./Directions/css.js";import{DirectionsSearchTool as k}from"./Directions/DirectionsSearchTool.js";import C from"./Directions/DirectionsViewModel.js";import D from"./Directions/DirectionsVisibleElements.js";import{formatDistance as M,formatDuration as I,DepartureTimeOption as T,getIconName as F}from"./Directions/support/directionsUtils.js";import{isArcGISWorldGeocoder as P,meteredArcGISLocatorUrl as x}from"./Search/support/locatorUtils.js";import{loadCalciteComponents as E}from"./support/componentsUtils.js";import{globalCss as R}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as L}from"./support/decorators/messageBundle.js";import{tsx as A}from"./support/jsxFactory.js";function O(e){const{branchName:i,displayText:s,exitName:o,intersectingName:r,name:n,towardName:a}=e;if(null==s)return null;const l=[i,o,r,n,a].filter(t).sort((e,t)=>t.length-e.length).map(e=>h(e));if(!l.length)return s;const c=new RegExp(l.join("|"),"g"),d=s.matchAll(c);let p=0;const m=[];for(const{0:t,index:h}of d)m.push(s.slice(p,h),A("span",{class:f.labelEmphasize,key:`maneuver-${h}`},t)),p=h+t.length;return m.push(s.slice(p)),A("span",null,m)}let N=class extends S{constructor(e,t){super(e,t),this._activeManeuver=null,this._placeholderStops=new i([new w,new w]),this._portalFolderCombobox=null,this._portalFolders=null,this._portalItemNameInput=null,this._portalUserName=null,this._printDocument=null,this._printDocumentParent=null,this._sections=null,this._stopsToSearches=new Map,this._printDocumentOpen=!1,this._currentFlowItem="primary",this._parentFlowItem="primary",this._saveState="initialized",this._searchTool=null,this.headingLevel=2,this.messages=null,this.messagesUnits=null,this.searchProperties={popupEnabled:!1,resultGraphicEnabled:!1},this.viewModel=new C,this.visibleElements=new D,this._solveRouteDebounced=n(()=>this._solveRoute())}initialize(){this.addHandles([l(()=>this.viewModel.layer,()=>{try{this.viewModel.load()}catch{}},c),l(()=>this.viewModel.layer?.routeInfo,()=>{this._sections=this._getStopSections()},c),l(()=>this.viewModel.layer?.stops.toArray(),e=>{e&&this.view?.activeTool&&this._searchTool&&this.view.activeTool===this._searchTool&&!e.includes(this._searchTool.stop)&&(this.view.tools.remove(this._searchTool),this._searchTool=null)}),s(window,"beforeprint",this._beforePrint.bind(this)),s(window,"afterprint",this._afterPrint.bind(this))])}loadDependencies(){return E({accordion:()=>import("@esri/calcite-components/dist/components/calcite-accordion"),"accordion-item":()=>import("@esri/calcite-components/dist/components/calcite-accordion-item"),action:()=>import("@esri/calcite-components/dist/components/calcite-action"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu"),"block-section":()=>import("@esri/calcite-components/dist/components/calcite-block-section"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),panel:()=>import("@esri/calcite-components/dist/components/calcite-panel"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch")})}destroy(){this._stopsToSearches.forEach(r)}get apiKey(){return this.viewModel.apiKey}set apiKey(e){this.viewModel.apiKey=e}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get icon(){return"right"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get lastRoute(){return this.viewModel.lastRoute}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get maxStops(){return this.viewModel.maxStops}set maxStops(e){this.viewModel.maxStops=e}get unit(){return this.defaultUnit}set unit(e){this._overrideIfSome("unit",e)}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const i=this._stopsToSearches.get(e);return i.view=t,this._overrideDefaultSources(i),i}const i=new b({icon:"",popupEnabled:!1,resultGraphicEnabled:!1,view:t,...this.searchProperties});return this._normalizeSearchSources(i),this.addHandles([d(()=>i.allSources,"change",()=>this._normalizeSearchSources(i)),i.on("search-clear",()=>{e.geometry=null,e.name=null,this.viewModel.layer?.removeResult()}),i.on("select-result",()=>{const t=i.selectedResult;e.geometry=t?.feature.geometry,e.name=t?.name,this._solveRouteDebounced()}),l(()=>i.searchTerm,t=>{e.name=t}),u(()=>this._normalizeSearchSources(i))],i),this._stopsToSearches.set(e,i),i}getDirections(){return this.viewModel.getDirections()}render(){return A("div",{class:this.classes(f.base,R.widget,R.panel)},A("calcite-flow",null,this._renderPrimaryFlowItem(),this._renderDirectionsFlowItem(),this._renderEditFlowItem(),this._renderSaveFlowItem()),this._renderPrintDocument())}save(){return this.viewModel.save()}saveAs(e,t={}){return this.viewModel.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_afterPrint(){this._printDocumentOpen&&this._printDocument&&this._printDocumentParent?.appendChild(this._printDocument)}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.language=v(),t.locationType??="street",P(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=x))}_beforePrint(){this._printDocumentOpen&&this._printDocument&&document.body.appendChild(this._printDocument)}_disposeSearch(e){if(!e||!this._stopsToSearches.has(e))return;const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}_getEffectiveStops(){return this.viewModel.layer?.stops??this._placeholderStops}_getErrorDescription(){switch(this.viewModel.lastError?.name){case"directions-view-model:unable-to-route":return this.messages.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return this.messages.errors.unableToLoadServiceMetadata;default:return this.messages.errors.unknownError}}_getNetworkFeatureName(e){switch(e.type){case"stop":switch(e.locationType){case"stop":default:return this.messages.networkFeatures.stops.stop;case"waypoint":return this.messages.networkFeatures.stops.waypoint;case"break":return this.messages.networkFeatures.stops.break}case"point-barrier":return this.messages.networkFeatures.pointBarrier;case"polyline-barrier":return this.messages.networkFeatures.polylineBarrier;case"polygon-barrier":return this.messages.networkFeatures.polygonBarrier}}_getRouteCostSummary(){const e=this.viewModel.layer?.routeInfo;if(!e)return null;const t=e.totalDistance??0,i=e.totalDuration??0,{messagesUnits:s,unit:o}=this;return{distance:M(s,t,o),duration:I(i)}}_getStopCostDescription(e){if(!e.directions.length)return;const{totalDistance:t,totalDuration:i}=e.directions.reduce((e,{lines:t})=>{for(const{distance:i,duration:s}of t)e.totalDistance+=i??0,e.totalDuration+=s??0;return e},{totalDistance:0,totalDuration:0}),{messagesUnits:s,unit:o}=this,r=M(s,t,o);return`${I(i)} (${r})`}_getStopSections(){if(!this.viewModel.layer)return null;const{directionPoints:e,directionLines:t,stops:i}=this.viewModel.layer;if(!e||!t)return null;const s=[];let o=null;for(const r of e){const{objectId:e,stopId:n}=r;if(null!=n){const e=i.find(({objectId:e})=>e===n);o&&o.stop===e||(o={stop:e,directions:[]},s.push(o));continue}if(null==o)continue;const a=t.toArray().filter(({directionPointId:t})=>t===e);0!==a.length&&o.directions.push({directionPoint:r,lines:a})}return s}_handleAddStopClick(){const e=new y;this.viewModel.layer?.stops.add(new w({symbol:e}))}_handleAutoSolveChange({target:e}){this.viewModel.autoSolve=e.checked}_handleCreatePolylineBarrierClick(){this.viewModel.create("polyline-barrier")}_handleClearRouteClick(){this._currentFlowItem="primary",this.viewModel.reset()}_handleCreateStopClick(){this.viewModel.create("stop")}_handleDeleteNetworkFeatureClick(e){this.viewModel.remove(e),this.viewModel.autoSolve&&this._solveRouteDebounced()}_handleDeleteStopClick(e){this._getEffectiveStops().remove(e),this._disposeSearch(e),this._solveRouteDebounced()}_handleDepartureDateChange({currentTarget:{value:e}}){Array.isArray(e)||(this.viewModel.departureIsoDate=e,this._solveRouteDebounced())}_handleDepartureTimeChange({currentTarget:{value:e}}){this.viewModel.departureIsoTime=e,this._solveRouteDebounced()}_handleDepartureTimeOptionChange({currentTarget:e}){const{selectedItems:t}=e;t.length&&(this.viewModel.departureOption=t[0].value,this._solveRouteDebounced())}_handleDirectionsFlowItemBackClick(e){e.stopPropagation(),this._currentFlowItem="primary"}_handleDirectionTurnItemSelect(e){this._activeManeuver===e?this.zoomToRoute():(this._activeManeuver=e,this.viewModel.centerAt(e.geometry))}_handleDirectionTurnPointerEnter(e){this.viewModel.highlight(e)}_handleDirectionTurnPointerLeave(){this.viewModel.clearHighlights()}_handleEditFlowItemBackClick(e){e.stopPropagation(),this.viewModel.stopEditing(),this._currentFlowItem="primary"}_handleEditingDoneClick(){this.viewModel.stopEditing(),this._currentFlowItem="primary"}_handleEditRouteClick(){this._currentFlowItem="edit",this.viewModel.startEditing()}_handleItemDetailsClick(){const e=this.viewModel.layer?.portalItem;e&&window.open(`${e.portal.url}/home/item.html?id=${e.id}`,"_blank")}_handleLocateStopClick(e){const{view:t}=this;if(!t)return;const i="directions-search-tool";this.removeHandles(i),this._searchTool=new k({stop:e,view:t}),this.addHandles([this._searchTool.on("click",async t=>{if(t.mapPoint&&this._stopsToSearches.has(e)){const i=this._stopsToSearches.get(e),s=await i.search(t.mapPoint),o=s?.results?.[0].results?.[0];if(o){const{feature:t,name:s}=o;i.searchTerm=s,e.geometry=t.geometry}}this.removeHandles(i)}),o(()=>{this._searchTool&&(this.view?.tools.remove(this._searchTool),this._searchTool=null)})],i),t.addAndActivateTool(this._searchTool)}_handleOptimizeStopOrderToggle({target:{expanded:e}}){this.viewModel.routeParameters.findBestSequence=e,this._solveRouteDebounced()}_handlePanToStopClick(e){this.viewModel.centerAt(e)}_handlePreserveFirstStopChange({target:{checked:e}}){this.viewModel.routeParameters.preserveFirstStop=e,this._solveRouteDebounced()}_handlePreserveLastStopChange({target:{checked:e}}){this.viewModel.routeParameters.preserveLastStop=e,this._solveRouteDebounced()}_handlePrintDocumentAfterCreate(e){e.focus(),this._printDocument=e,this._printDocumentParent=e.parentElement}_handlePrintDocumentClick(){this._printDocumentOpen=!0}_handlePrintDocumentCloseClick(){this._printDocumentOpen=!1}_handlePrintDocumentKeyDown(e){"Escape"===e.key&&(this._printDocumentOpen=!1)}_handlePrintDocumentPrintClick(){document.body.classList.add(f.printMedia),window.print(),document.body.classList.remove(f.printMedia)}_handleResolveRouteClick(){this._solveRouteDebounced()}_handleReverseStopOrderClick(){this._getEffectiveStops().reverse(),this._solveRouteDebounced()}_handleSaveErrorCloseClick(){this._currentFlowItem=this._parentFlowItem}_handleSaveFlowItemBackClick(e){e.stopPropagation(),this._currentFlowItem=this._parentFlowItem}async _handleSaveLayerAs(){const e=_.getDefault();try{await e.signIn()}catch(t){if(a(t)||"identity-manager:user-aborted"===t.name)return;return this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",void(this._saveState="connect-to-portal-error")}this._saveState="fetch-portal-information",this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",this._portalUserName=e.user?.username;try{this._portalFolders=await(e.user?.fetchFolders())}catch{return void(this._saveState="fetch-portal-information-error")}this._saveState="save-layer"}_handleSaveLayerClick(){this.viewModel.layer?.save()}_handleSaveLayerButtonClick(){this._saveState="saving";const{layer:e}=this;if(!e||!this._portalFolders)return;const t=this._portalItemNameInput?.value,i=this._portalFolderCombobox?.value,s=this._portalFolders.find(({id:e})=>e===i);e.saveAs({title:t},{folder:s}).then(()=>{e.title=t,this._currentFlowItem=this._parentFlowItem}).catch(()=>{this._saveState="saving-error"})}_handleSaveLayerCancelClick(){this._currentFlowItem=this._parentFlowItem}_handleSaveLayerFolderCreate(e){this._portalFolderCombobox=e}_handleSaveLayerNameCreate(e){this._portalItemNameInput=e}_handleSignInClick(){this.viewModel.load().catch(()=>{})}_handleStopListReorder({detail:{dragEl:e,newIndex:t}}){this._getEffectiveStops().reorder(e.value,t),this._solveRouteDebounced()}_handleTravelModeChange({currentTarget:{selectedItems:e}}){e.length&&(this.viewModel.selectedTravelMode=e[0].value,this._solveRouteDebounced())}_handleViewDrivingDirectionsClick(){this._currentFlowItem="directions"}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){for(const t of e.viewModel.defaultSources)t.autoNavigate=!1}_renderClearRouteAction(e){return A("calcite-action",{bind:this,icon:"trash",key:"clear-route",onclick:this._handleClearRouteClick,...e,text:this.messages.common.clear,textEnabled:!0})}_renderDeleteStopAction(e){return A("calcite-action",{icon:"trash",onclick:this._handleDeleteStopClick.bind(this,e),scale:"s",slot:"actions-end",text:this.messages.deleteStop,title:this.messages.deleteStop})}_renderDepartureTime(){const{DEPART_AT:e,NOW:t,UNSPECIFIED:i}=T;return A("calcite-label",{class:f.departureTime,key:"departure-time"},this.messages.departureTime,A("calcite-combobox",{bind:this,clearDisabled:!0,label:this.messages.departureTime,overlayPositioning:"fixed",selectionMode:"single-persist",onCalciteComboboxChange:this._handleDepartureTimeOptionChange},A("calcite-combobox-item",{heading:this.messages.leaveNow,key:t,label:this.messages.leaveNow,selected:this.viewModel.departureOption===t,value:t}),A("calcite-combobox-item",{heading:this.messages.departAt,key:e,label:this.messages.departAt,selected:this.viewModel.departureOption===e,value:e}),A("calcite-combobox-item",{heading:this.messages.timeUnspecified,key:i,label:this.messages.timeUnspecified,selected:this.viewModel.departureOption===i,value:i})))}_renderDepartureTimeOptions(){return this.viewModel.departureOption!==T.DEPART_AT?null:A("div",{class:f.departureTimeOptions},A("calcite-input-date-picker",{bind:this,scale:"s",value:this.viewModel.departureIsoDate,onCalciteInputDatePickerChange:this._handleDepartureDateChange}),A("calcite-input-time-picker",{bind:this,scale:"s",value:this.viewModel.departureIsoTime,onCalciteInputTimePickerClose:this._handleDepartureTimeChange}))}_renderDirectionsFlowItem(){if("directions"!==this._currentFlowItem)return null;const e=this._getRouteCostSummary();if(!this._sections||!e)return null;const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel,o=this._sections.at(0)?.stop.name??"",r=this._sections.at(-1)?.stop.name??"";return A("calcite-flow-item",{bind:this,key:"directions-flow-item",overlayPositioning:"fixed",selected:"directions"===this._currentFlowItem,onCalciteFlowItemBack:this._handleDirectionsFlowItemBackClick},A("div",{class:f.directionsHeader,slot:"header-content"},A("div",{class:f.headerStops},A("span",null,this.messages.from)," ",A("span",{class:f.directionsHeaderStopName},o),A("span",null,this.messages.to)," ",A("span",{class:f.directionsHeaderStopName},r)),A("div",{class:f.flexColumn},A("span",null,`${i} (${t})`),s?A("span",null,s):null)),this._renderRouteLayerActions({slot:"header-menu-actions"}),A("calcite-accordion",{class:f.accordion,iconPosition:"start",selectionMode:"single"},this._sections.map((e,t)=>this._renderDirectionSection(e,t))))}_renderDirectionSection(e,t){const{stop:i,directions:s}=e,{name:o}=i,r=0===t,n=this._getStopCostDescription(e);return A("calcite-accordion-item",{description:n,expanded:r,heading:o??"",key:`stop-${t}`},A("calcite-action",{icon:"zoom-to-object",onclick:this._handlePanToStopClick.bind(this,i),slot:"actions-end",text:this.messages.panToStop,title:this.messages.panToStop}),this._renderDirectionTurns(s))}_renderDirectionTurns(e){return A("calcite-list",{label:this.messages.drivingDirections,selectionMode:"none"},e.map((e,t)=>{const{directionPoint:i,lines:s}=e,o=s[0],{distance:r,duration:n}=o,a=M(this.messagesUnits,r??0,this.unit),l=I(n??0),c=a&&l?`${a} | ${l}`:`${a||l}`,d=O(i),h=F(i.directionPointType);return A("calcite-list-item",{class:f.labelNoBottomMargin,key:`driving-direction-${t}`,onpointerenter:this._handleDirectionTurnPointerEnter.bind(this,o),onpointerleave:this._handleDirectionTurnPointerLeave.bind(this),onCalciteListItemSelect:this._handleDirectionTurnItemSelect.bind(this,o)},A("calcite-icon",{icon:h,slot:"content-start"}),A("div",{slot:"content"},A("calcite-label",{layout:"inline",scale:"s"},d),A("calcite-label",{layout:"inline",scale:"s"},c)))}))}_renderEditFlowItem(){return"edit"!==this._currentFlowItem?null:A("calcite-flow-item",{bind:this,heading:this.messages.editRoute,headingLevel:this.headingLevel,key:"edit-flow-item",loading:"routing"===this.viewModel.state,selected:"edit"===this._currentFlowItem,onCalciteFlowItemBack:this._handleEditFlowItemBackClick},A("div",{class:f.flexColumn,key:"edit-container"},A("div",{class:f.editToolbarContainer},A("calcite-label",{layout:"inline",scale:"s"},this.messages.automaticallySolve,A("calcite-switch",{bind:this,checked:this.viewModel.autoSolve,scale:"s",onCalciteSwitchChange:this._handleAutoSolveChange})),A("div",{class:f.editToolbar},A("calcite-action",{bind:this,disabled:!this.viewModel.layer||this.viewModel.layer.stops.length>=this.maxStops,icon:"flag",onclick:this._handleCreateStopClick,scale:"s",text:this.messages.networkFeatures.stops.stop,textEnabled:!0}),A("calcite-action",{bind:this,icon:"line",onclick:this._handleCreatePolylineBarrierClick,scale:"s",text:this.messages.barrier,textEnabled:!0}),A("calcite-action",{bind:this,class:f.solveRoute,disabled:this.viewModel.autoSolve,icon:"refresh",onclick:this._handleResolveRouteClick,scale:"s",text:this.messages.solve,textEnabled:!0}))),A("div",{class:f.selectedFeatureContainer},A("calcite-list",{label:this.messages.selectedNetworkFeatures,scale:"s",selectionMode:"none"},this.viewModel.selectedNetworkFeatures?.toArray().map((e,t)=>A("calcite-list-item",{description:this._getNetworkFeatureName(e),key:`network-feature-${t}`,label:e.name??e.objectId?.toString()??this.messages.unnamed},A("calcite-action",{icon:"trash",onclick:this._handleDeleteNetworkFeatureClick.bind(this,e),scale:"s",slot:"actions-end",text:this.messages.common.delete}))))),A("div",{class:f.editFooter},this._renderEditFooterContent())))}_renderEditFooterContent(){return this.viewModel.lastError?this._renderErrorNotice():A("calcite-button",{appearance:"outline-fill",bind:this,onclick:this._handleEditingDoneClick,width:"full"},this.messages.common.done)}_renderErrorNotice(){return A("calcite-notice",{icon:"exclamation-mark-circle",kind:"danger",open:!0},A("calcite-label",{class:f.labelNoBottomMargin,slot:"message"},this._getErrorDescription()))}_renderFooter(){if(!this.viewModel.layer)return A("div",{class:f.primaryFooter,key:"footer-missing-layer"},A("calcite-notice",{icon:"information",open:!0},A("calcite-label",{class:f.labelNoBottomMargin,slot:"message"},this.messages.missingLayer)));if("unauthenticated"===this.viewModel.state)return A("div",{class:f.primaryFooterCentered,key:"footer-sign-in"},A("calcite-label",null,this.messages.signInRequired),A("calcite-button",{bind:this,onclick:this._handleSignInClick},this.messages.common.auth.signIn));if("routing"===this.viewModel.state)return A("div",{class:this.classes(f.primaryFooter,f.primaryFooterLoader),key:"footer-routing"},A("calcite-loader",{label:this.messages.solve,scale:"s"}));if("error"===this.viewModel.state)return A("div",{class:f.primaryFooter,key:"footer-service-error"},this._renderErrorNotice());if(!this.viewModel.layer?.routeInfo)return A("div",{class:f.primaryFooter,key:"footer-unsolved-route"},A("calcite-notice",{icon:"information",open:!0},A("calcite-label",{class:f.labelNoBottomMargin,slot:"message"},this.messages.directionsPlaceholder)));const e=this._getRouteCostSummary();if(!e||!this.viewModel.layer?.directionPoints)return A("div",{class:f.primaryFooter,key:"footer-invalid-route"},A("calcite-notice",{icon:"exclamation-mark-triangle",kind:"danger",open:!0},A("calcite-label",{class:f.labelNoBottomMargin,slot:"message"},this.messages.invalidRoute)));const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel;return A("div",{class:f.routeItem,key:"footer-directions-summary"},A("button",{"aria-busy":"false","aria-label":this.messages.viewDrivingDirections,"aria-live":"polite",bind:this,class:f.routeItemButton,onclick:this._handleViewDrivingDirectionsClick,title:this.messages.viewDrivingDirections,type:"button"},A("div",{class:f.routeItemButtonContent},A("span",{class:f.routeItemLabel},`${i} (${t})`),A("span",{class:f.routeItemDescription},s)),A("calcite-icon",{flipRtl:!0,icon:"chevron-right",scale:"s"})),A("calcite-action-menu",{label:"test"},A("calcite-action",{icon:"ellipsis",key:"route-actions",slot:"trigger",text:"Route actions"}),this._renderRouteLayerActions()))}_renderInteractiveRouteActions(){return A("div",{class:f.actionContainer,key:f.actionContainer},A("calcite-button",{appearance:"outline",bind:this,class:f.addStopButton,disabled:this._getEffectiveStops().length>=this.maxStops,iconStart:"plus",kind:"neutral",label:this.messages.addStop,onclick:this._handleAddStopClick,title:this.messages.addStop,width:"half"},this.messages.addStop),this.visibleElements.editRouteButton?A("calcite-button",{appearance:"outline",bind:this,class:f.editRouteButton,disabled:"2d"!==this.viewModel.view?.type,iconStart:"pencil",kind:"neutral",label:this.messages.editRoute,onclick:this._handleEditRouteClick,title:this.messages.editRoute,width:"half"},this.messages.editRoute):null)}_renderLocateStopAction(e){if(null!=e.name||null!=e.geometry)return null;const t=this._getEffectiveStops().indexOf(e),i=!!this.view?.activeTool&&this.view.activeTool===this._searchTool&&this._searchTool.stop===e;return A("calcite-action",{active:i,icon:"crosshair",key:`stop-location-action-${t}`,onclick:this._handleLocateStopClick.bind(this,e),scale:"s",slot:"actions-end",text:this.messages.pickALocationOnTheMap,title:this.messages.pickALocationOnTheMap})}_renderOptimizeStopOrder(){const{routeParameters:e}=this.viewModel,{findBestSequence:t,preserveFirstStop:i,preserveLastStop:s}=e;return A("calcite-block-section",{bind:this,class:f.optimizeSection,text:this.messages.optimizeOrder,toggleDisplay:"switch",onCalciteBlockSectionToggle:this._handleOptimizeStopOrderToggle},t?[A("calcite-label",{class:f.optimizeSwitches,key:"preserve-first-stop",layout:"inline-space-between"},this.messages.preserveFirstStop,A("calcite-switch",{bind:this,checked:i,scale:"s",onCalciteSwitchChange:this._handlePreserveFirstStopChange})),A("calcite-label",{class:f.optimizeSwitches,key:"preserve-last-stop",layout:"inline-space-between"},this.messages.preserveLastStop,A("calcite-switch",{bind:this,checked:s,scale:"s",onCalciteSwitchChange:this._handlePreserveLastStopChange}))]:null)}_renderPrimaryFlowItem(){return A("calcite-flow-item",{key:"primary-flow-item",loading:"initializing"===this.viewModel.state,selected:"primary"===this._currentFlowItem},A("calcite-panel",{class:f.primaryFlowItem,disabled:!this.viewModel.layer||"unauthenticated"===this.viewModel.state||"error"===this.viewModel.state&&!this.viewModel.serviceDescription},this._renderStops(),this._renderInteractiveRouteActions(),this._renderSeparator(),this._renderRouteSolveOptions()),this._renderFooter())}_renderPrintDocument(){if(!this._printDocumentOpen)return null;const e=this._getRouteCostSummary();if(!this._sections||!e)return null;const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel,o=this._sections.at(0)?.stop.name??"",r=this._sections.at(-1)?.stop.name??"";return A("div",{afterCreate:this._handlePrintDocumentAfterCreate,bind:this,class:f.printDocument,onkeydown:this._handlePrintDocumentKeyDown,tabindex:0},A("div",{class:f.printBody},A("div",{class:f.printHeader},A("div",{class:f.printHeaderLabel},A("div",{class:f.headerStops},A("span",null,this.messages.from)," ",A("span",{class:f.directionsHeaderStopName},o),A("span",null,this.messages.to)," ",A("span",{class:f.directionsHeaderStopName},r))),A("div",{class:this.classes(f.printHeaderButtons,f.printHideOnPrint)},A("calcite-button",{class:f.printDocumentPrint,iconStart:"print",onclick:this._handlePrintDocumentPrintClick},this.messages.common.print),A("calcite-button",{appearance:"outline",bind:this,class:f.printDocumentClose,iconStart:"x-circle",onclick:this._handlePrintDocumentCloseClick},this.messages.common.close))),A("div",{class:f.directionsHeader},A("span",null,`${i} (${t})`),s?A("span",null,s):null),this._sections.map((e,t)=>this._renderPrintSection(e,t))))}_renderPrintManuever(e,t){const{directionPoint:i,lines:s}=e,{distance:o,duration:r}=s.at(0)??{},n=M(this.messagesUnits,o??0,this.unit),a=I(r??0),l=n&&a?`${n} | ${a}`:`${n||a}`,c=O(i),d=F(i.directionPointType);return A("div",{class:this.classes(f.flexRow,f.printAvoidPageBreak),key:`direction-${t}`},A("calcite-icon",{icon:d}),A("div",{class:f.flexColumn},A("span",null,c),A("span",null,l)))}_renderPrintRouteAction(e){if(!this.visibleElements.printButton)return null;const t=!this.viewModel.layer?.routeInfo;return A("calcite-action",{bind:this,disabled:t,icon:"print",key:"print-route",onclick:this._handlePrintDocumentClick,...e,text:this.messages.common.print,textEnabled:!0})}_renderPrintSection({stop:e,directions:t},i){return A("div",{class:f.printSection,key:`section-${i}`},A("span",{class:f.directionsHeaderStopName},e.name??""),t.map((e,t)=>this._renderPrintManuever(e,t)))}_renderRouteLayerActions(e){return[this._renderClearRouteAction(e),this._renderSaveLayerAction(e),this._renderSaveLayerAsAction(e),this._renderPrintRouteAction(e),this._renderViewItemDetailsAction(e)]}_renderRouteSolveOptions(){return A("div",{class:f.marginInlineMedium,key:"route-solve-options"},this._renderTravelModes(),this._renderDepartureTime(),this._renderDepartureTimeOptions(),this._renderOptimizeStopOrder())}_renderSaveContent(){switch(this._saveState){case"initialized":return this._renderSaveInitialized();case"connect-to-portal":return this._renderSaveProcessing(this.messages.identity.lblSigning);case"connect-to-portal-error":return this._renderSaveError(this.messages.errors.authenticating);case"fetch-portal-information":return this._renderSaveProcessing(this.messages.processing.fetching);case"fetch-portal-information-error":return this._renderSaveError(this.messages.errors.fetching);case"save-layer":return this._renderSaveLayerSettings();case"saving":return this._renderSaveProcessing(this.messages.processing.saving);case"saving-error":return this._renderSaveError(this.messages.errors.saving)}}_renderSaveError(e){return A("calcite-panel",{class:f.paddingMedium,key:"save-layer-error"},A("div",{class:f.saveError},A("calcite-icon",{class:f.saveErrorIcon,icon:"exclamation-mark-triangle",scale:"l",textLabel:this.messages.common.errorMessage}),A("calcite-label",{class:f.saveErrorLabel},e)),A("calcite-button",{appearance:"outline",bind:this,onclick:this._handleSaveErrorCloseClick,slot:"footer-actions",width:"full"},this.messages.common.close))}_renderSaveInitialized(){return A("calcite-panel",{class:f.paddingMedium,key:"save-layer-initialized"})}_renderSaveFlowItem(){return"save"!==this._currentFlowItem?null:A("calcite-flow-item",{bind:this,heading:this.messages.saveLayer,headingLevel:this.headingLevel,key:"save-layer-flow-item",selected:"save"===this._currentFlowItem,onCalciteFlowItemBack:this._handleSaveFlowItemBackClick},this._renderSaveContent())}_renderSaveLayerAction(e){if(!this.visibleElements.saveButton)return null;const t=this.viewModel.layer,i=t?.routeInfo,s=t?.portalItem?.itemControl;return A("calcite-action",{bind:this,disabled:!(!!i&&("admin"===s||"update"===s)),icon:"save",key:"save-route",onclick:this._handleSaveLayerClick,...e,text:this.messages.common.save,textEnabled:!0})}_renderSaveLayerAsAction(e){if(!this.visibleElements.saveAsButton)return null;const t=!this.viewModel.layer?.routeInfo;return A("calcite-action",{disabled:t,icon:"save-as",key:"save-as-route",onclick:()=>{this._handleSaveLayerAs()},...e,text:this.messages.common.saveAs,textEnabled:!0})}_renderSaveLayerSettings(){if(null==this.layer||null==this._portalFolders||null==this._portalUserName)return this._renderSaveInitialized();const{stops:e}=this.layer,t=`${e.at(0).name} - ${e.at(-1).name}`,i=[A("calcite-combobox-item",{heading:`${this._portalUserName} (${this.messages.common.home})`,key:f.folderHome,selected:!0,value:f.folderHome}),...this._portalFolders.map(e=>A("calcite-combobox-item",{heading:e.title??"",key:`${f.folder}-${e.id}`,value:e.id}))];return A("calcite-panel",{key:"save-layer-panel"},A("div",{class:f.paddingMedium},A("calcite-label",null,this.messages.layerName,A("calcite-input",{afterCreate:this._handleSaveLayerNameCreate,bind:this,label:this.messages.layerName,value:t})),A("calcite-label",null,this.messages.saveInFolder,A("calcite-combobox",{afterCreate:this._handleSaveLayerFolderCreate,bind:this,clearDisabled:!0,label:this.messages.saveInFolder,overlayPositioning:"fixed",selectionMode:"single-persist"},i))),A("calcite-button",{bind:this,onclick:this._handleSaveLayerButtonClick,slot:"footer-actions",width:"full"},this.messages.common.save),A("calcite-button",{appearance:"outline",bind:this,onclick:this._handleSaveLayerCancelClick,slot:"footer-actions",width:"full"},this.messages.common.cancel))}_renderSaveProcessing(e){return A("calcite-panel",{class:f.marginInlineMedium,key:"save-layer-processing"},A("calcite-loader",{class:f.saveProcessLoader,label:e,text:e}))}_renderSeparator(){return A("div",{class:f.separator})}_renderStop(e){const t=this.acquireSearch(e);null!=e.name&&(t.searchTerm=e.name);const i=this._getEffectiveStops(),s=this._renderLocateStopAction(e),o=i.length>2&&this._renderDeleteStopAction(e);return A("calcite-list-item",{key:e,value:e},s,o,A("div",{class:f.stopItem,slot:"content"},t.render()))}_renderStops(){const e=this._getEffectiveStops();for(const t of this._stopsToSearches.keys())e.includes(t)||this._disposeSearch(t);return A("div",{class:f.stopContainer,key:f.stopContainer},A("calcite-list",{bind:this,class:f.stopList,dragEnabled:!0,label:this.messages.widgetLabel,scale:"s",onCalciteListOrderChange:this._handleStopListReorder},e.toArray().map(e=>this._renderStop(e))),2===e.length&&A("calcite-action",{bind:this,icon:"arrow-up-down",onclick:this._handleReverseStopOrderClick,scale:"s",text:this.messages.reverseStops,title:this.messages.reverseStops}))}_renderTravelMode(e){const{id:t,name:i}=e;return A("calcite-combobox-item",{heading:i,key:t,label:i,selected:this.viewModel.selectedTravelMode?.id===t,value:e})}_renderTravelModes(){return this.viewModel.travelModes.length?A("calcite-label",{key:"travel-modes"},this.messages.mode,A("calcite-combobox",{bind:this,clearDisabled:!0,label:this.messages.mode,overlayPositioning:"fixed",selectionMode:"single-persist",onCalciteComboboxChange:this._handleTravelModeChange},this.viewModel.travelModes.map(e=>this._renderTravelMode(e)))):null}_renderViewItemDetailsAction(e){return this.visibleElements.layerDetails?A("calcite-action",{bind:this,disabled:!this.viewModel.layer?.portalItem,icon:"launch",key:"open-route-details-link",onclick:this._handleItemDetailsClick,...e,text:this.messages.viewLayerDetails,textEnabled:!0}):null}async _solveRoute(){this.viewModel.updateDepartureTime();if(!((this.viewModel.layer?.stops.filter(({geometry:e})=>!!e).length??0)<2))try{await this.viewModel.getDirections()}catch{}}};e([p()],N.prototype,"_printDocumentOpen",void 0),e([p()],N.prototype,"_currentFlowItem",void 0),e([p()],N.prototype,"_saveState",void 0),e([p()],N.prototype,"_searchTool",void 0),e([p()],N.prototype,"apiKey",null),e([p(g)],N.prototype,"defaultUnit",void 0),e([p()],N.prototype,"goToOverride",null),e([p()],N.prototype,"headingLevel",void 0),e([p()],N.prototype,"icon",null),e([p()],N.prototype,"label",null),e([p({readOnly:!0})],N.prototype,"lastRoute",null),e([p()],N.prototype,"layer",null),e([p()],N.prototype,"maxStops",null),e([p(),L("esri/widgets/Directions/t9n/Directions")],N.prototype,"messages",void 0),e([p(),L("esri/core/t9n/Units")],N.prototype,"messagesUnits",void 0),e([p()],N.prototype,"searchProperties",void 0),e([p()],N.prototype,"unit",null),e([p()],N.prototype,"view",null),e([p({type:C})],N.prototype,"viewModel",void 0),e([p({type:D,nonNullable:!0})],N.prototype,"visibleElements",void 0),N=e([m("esri.widgets.Directions")],N);const j=N;export{j 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.34/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 o from"../../core/Logger.js";import{removeMaybe as n,destroyMaybe as l}from"../../core/maybe.js";import{debounce as d,isPromiseLike as c}from"../../core/promiseUtils.js";import{watch as u,when as h,initial as p,whenOnce as m,syncAndInitial as f}from"../../core/reactiveUtils.js";import{generateBracedUUID as w}from"../../core/uuid.js";import{property as g}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import{isSharedTemplateOrMetadata as v,isSharedTemplate as F,isStandardFeatureTemplate as _}from"../../editing/templateUtils.js";import b from"../../layers/GraphicsLayer.js";import{isTable as M}from"../../layers/support/layerUtils.js";import{getDisplayedSymbol as I}from"../../symbols/support/symbolUtils.js";import{getDrawHelpMessage as V}from"../../views/draw/support/helpMessageUtils.js";import k from"../../views/draw/support/HighlightHelper.js";import S from"../../views/interactive/sketch/SketchOptions.js";import C from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as A}from"../../views/support/HighlightDefaults.js";import P from"./CreateFeaturesWorkflowData.js";import{isModelUpload as E,handleModelUpload as T}from"./modelUploadUtils.js";import H from"./Workflow.js";import{createToolFromGeometryType as j,getServiceEditsFromWorkflowData as U,getServiceInfoForLayer as L,orderEditsByRelationshipDependencies as x,getFullTemplateForCreationInfo as O,getServiceLayersById as W,startCreatingNewFeature as D,findLayerInfo as R,updateGraphicSymbolWhenRequired as z,isTerminalUpdateEventType as G,getVisualVariableAttributes as N,startUpdatingFeatureGeometry as K,createWorkflowSteps as Z,avoidFeatureTemplateSelectionWithOnlyOneItem as q,getCreationAttributes as B,setUpSketchCreateWatchers as J,setRelationshipFields as Q,prepareAttachmentsForCreateFeaturesWorkflow as X,showProgressCursor as Y,setVisualVariablesAndElevationInfoForUpdate as $,visualVariableInteractiveUpdate as ee}from"./workflowUtils.js";import te from"../FeatureForm/FeatureFormViewModel.js";import ae from"../Sketch/SketchViewModel.js";var ie;const re=Symbol(),se=Symbol(),oe=Symbol(),ne=Symbol(),le={point:["point"],multipoint:["multipoint"],polygon:["polygon","freehandPolygon","rectangle","circle"],polyline:["polyline","freehandPolyline"],mesh:[],multipatch:[]};let de=ie=class extends H{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 te,this._sketchViewModel=null,this._attachmentFileInfos=new Map,this._isActive=!0}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 this._stepIndex>0||"update-pending"===this.createFeatureState&&!!this.data.selectedPendingFeature&&!this.parent&&!E(this.data.creationInfo)}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 V("rectangle"===s?"rectangle":"circle"===s?"circle":a,i?.geometry,r)}get layer(){return this.data.creationInfo?.layer}get numPendingFeatures(){return this.pendingFeatures.length}get numPendingFeaturesExcludingHidden(){return this.pendingFeatures.filter(e=>this.data.isDisplayable(e)).length}get parent(){return this.data.parent}get 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;if(!e)return[];if(this.data.creationInfo?.maxFeatures&&this.data.creationInfo.maxFeatures<=this.numPendingFeatures)return[];if(v(this.data.fullTemplate)){const{tool:t}=j(e,this.data.fullTemplate);return[t]}return"2d"!==t?.type&&"multipoint"===e?[]:[...le[e]]}get _attachmentsActive(){const e=this.data.viewModel.attachmentsViewModel.mode,t=this.stepId;return this.shouldShowAttachments&&("add"===e||"edit"===e||"adding-attachment"===t||"editing-attachment"===t)}async enter(){this._isActive=!0,"awaiting-feature-creation-info"!==this.stepId&&await this._updatingHandles.addPromise(this._setUpCreatingFeaturesStep())}exit(){this._isActive=!1,this.removeHandles([oe])}async updatePendingFeature(e){if(e!==this.data.selectedPendingFeature)return this._sketchViewModel.cancel(),this._startUpdating({feature:e})}async start(){return await super.start(),M(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||E(this.data.creationInfo)||this._attachmentsActive||this.parent?super.back(e):this._clearSelectedFeature()}previous(e){return"update-pending"!==this.createFeatureState||!this.data.selectedPendingFeature||E(this.data.creationInfo)||this._attachmentsActive?super.previous(e):this._clearSelectedFeature()}cancelFeature(e){this.data.isSharedTemplateWorkflow?o.getLogger(this).warn("Cannot cancel individual features created by shared templates."):(this.data.removePendingFeature(e),this.sketchViewModel.layer.graphics.remove(e))}static create(e){const{addAttachmentsCallback:t,applyEditsCallback:a,applyEditsFeatureServiceCallback:i,isNested:r,creationInfo:s,parent:o,snappingManager:n,startAt:l,viewModel:d}=e,c=e.sketchOptions??new S,u=s?.layer,h=u?d.findEditorItemForLayer(u):void 0,p=new ie({data:new P({creationInfo:s,editorItem:h,parent:o,sketchOptions:c,snappingManager:n,viewModel:d}),isNested:r,onCommit:async e=>{const{creationInfo:r}=e;if(!r)return;p._sketchViewModel.cancel();const s=e.pendingFeatures.toArray(),{layer:o}=r,n=o.capabilities?.editing.supportsGlobalId&&"globalIdField"in o,l=p._attachmentFileInfos,{fullTemplate:c}=e,u=U(p.data),h=F(c)&&u;if(n){if(pe(s),h){let t=fe(u,l);const a=await L(o,d.view);a&&(t=x({edits:t,serviceInfo:a,view:d.view,findOriginalFeature:t=>e.getEditsForPendingFeature(t)?.initialFeature??t})),await i(c.featureService,t,{globalIdUsed:!0,gdbVersion:c.layer.gdbVersion??void 0})}else{const e=me(s,l);await a(o,e,{globalIdUsed:!0})}return}const m=h?await i(c.featureService,u,{gdbVersion:c.layer.gdbVersion??void 0}):[await a(o,{addFeatures:s})];m&&l.size>0&&await Promise.all(m.map(e=>{if(e?.addFeatureResults)return t(o,he(s,e.addFeatureResults,o,l))}))}});return p._set("steps",this._createWorkflowSteps(p,l)),p}_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 _initializeFullTemplateAndExecutorInfo(e){const{creationInfo:t}=e,{view:a}=e.viewModel;if(!t||!a)return null;const i=await O(t,a);if(e.fullTemplate=i,i&&F(i)){const{createTemplateExecutor:r}=await import("../../editing/sharedTemplates/executor/createTemplateExecutor.js"),s={completionResults:[],executor:await r(i),serviceLayersById:await W(t.layer,a)};e.templateExecutorInfo=s}return i}async _startCreating(){this.removeHandles(se);const{data:e}=this;if(!e.creationInfo)return;const t=this.data.creationInfo?.maxFeatures;if(t&&this.numPendingFeatures>=t)return this.sketchViewModel.cancel(),void(this.numPendingFeatures&&await this._startUpdating({feature:this.pendingFeatures.at(-1)}));this.createFeatureState="create-new",await D(this._sketchViewModel,e,this._webStyleCache)}async _clearSelectedFeature(){const e=this._featureFormViewModel.pendingSubtypeChoice;e&&(e.resolve("undo"),await e.promise),this._stashValidationState(),this.sketchViewModel.cancel(),this.data.selectedPendingFeature=null,this._featureFormHandle=n(this._featureFormHandle),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:o,_sketchViewModel:l}=this,{creationInfo:d,viewModel:c}=a,{attachmentsViewModel:h,layerInfos:p,view:m}=c;if(!m||!d)return;n(this._featureFormHandle);const f=e.sourceLayer,w=R(p,f),g=w?.formTemplate,y=m.spatialReference;o.set({editType:"INSERT",feature:e,formTemplate:g,spatialReference:y,map:m.map}),"add"!==h.mode&&"edit"!==h.mode||c.activeWorkflow?.previous(),h.graphic=e,h.fileInfos.removeAll(),h.mode="view";(this._attachmentFileInfos.get(e)||[]).forEach(({file:e,form:t})=>h.addFile(e,t)),await z(e,s,"2d"===m.type?m.scale:null);const v=a.getEditsForPendingFeature(e);this._featureFormHandle=r([o.on("value-change",async()=>{v?.updateAttributes(o.getValues()),await z(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&&G(e.toolEventInfo.type))&&o.notifyFeatureGeometryChanged()}),u(()=>o.feature?.sourceLayer,t=>e.sourceLayer=t),u(()=>[o.feature,o.submittable],()=>this._stashValidationState())]),this.createFeatureState="update-pending"}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=e.sourceLayer??r.layer;return M(n)?void 0:(this._visualVariableAttributes=N(e),K({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=Z(["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&&(E(t)?e.addHandles(await T({view:r,data:a,next:()=>e.next(),cancel:()=>i.cancelWorkflow({warnIfNoWorkflow:!1})}),this.id):(a.parent&&t&&e.addHandles(i.restrictFeatureTemplatesViewModelToLayer(t.layer),this.id),e.addHandles(i.featureTemplatesViewModel.on("select",({item:t})=>{t&&(a.creationInfo={...a.creationInfo,layer:t.layer,template:t.template},e.next())}),this.id)))},async tearDown(){e.removeHandles(this.id)}}),"creating-features":()=>({id:"creating-features",async setUp(){e._isActive&&await e._setUpCreatingFeaturesStep()},async tearDown(t){const{viewModel:i}=a;t.canceled&&(e.removeHandles([oe,re,se,ne]),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 q(a,i)}static _configureSketchViewModel(e){const{data:t}=e,a=e._webStyleCache,{creationInfo:s,viewModel:o}=t,{view:n}=o,l=e._sketchViewModel,c=[];if(!n)return i();if("2d"===n.type){s&&c.push(e._fadeExistingFeatures(s.layer));const t=d((e,t)=>Promise.all(e.map(e=>z(e,a,t))));c.push(u(()=>n.scale,e=>t(l.layer.graphics,e)))}const p=B(t.fullTemplate,s?.attributeOverrides),m=u(()=>l.createGraphic,i=>{i&&!e.hasHandles(se)&&e._updatingHandles.addPromise(J({creationAttributes:p,data:t,sketchViewModel:l,view:n,webStyleCache:a}).then(t=>e.addHandles(t,se)))}),f=async t=>{if("cancel"!==t.state&&"complete"!==t.state||e.removeHandles(se),"cancel"===t.state&&null!==n.activeTool&&n.activeTool!==e.sketchViewModel.activeComponent&&(await e._waitForActiveToolCleared(),await e._startCreating()),"complete"===t.state&&t.graphic){const a=await e._processEdits(t.graphic,{scale:"2d"===n.type?n.scale:null,useSourceLayer:!0,webStyleCache:e._webStyleCache});a&&(await e._waitForActiveToolCleared(),await e._startUpdating({feature:a}))}},w=async a=>{const{attachmentsViewModel:i}=o,{_featureFormViewModel:r}=e;if(a.graphics.length>1)return void await e._clearSelectedFeature();const d=a.graphics[0];if("complete"===a.state){const{submittable:t}=r;if(e.numPendingFeatures!==s?.maxFeatures&&t||r.submit(),await e._clearSelectedFeature(),"add"!==i.mode&&"edit"!==i.mode||o.activeWorkflow?.previous(),!a.aborted&&n.activeTool===e.sketchViewModel.activeComponent&&(await e.sketchViewModel.wait(),"ready"===e.sketchViewModel.state&&"mesh"!==e.data.creationInfo?.layer.geometryType))return e._startCreating()}else{if("start"===a.state)return d.sourceLayer??=t.creationInfo?.layer,await $({sketchViewModel:l,graphic:d,visualVariables:e._visualVariableAttributes,webStyleCache:e._webStyleCache,sourceLayer:d.sourceLayer}),e._selectFeatureForUpdate({feature:d});if("active"===a.state){await e.updatePendingFeature(d);const t=e._visualVariableAttributes;ee(n,d,a,t)&&await z(d,e._webStyleCache,"2d"===n.type?n.scale:null);const i=d.attributes,{rotation:s,size:o}=t;if(null!=s){const{field:e}=s;r.setValue(e,i[e])}if(null!=o){const{field:e}=o;r.setValue(e,i[e])}}}},g=async a=>{if(a.graphics.forEach(e=>{t.removePendingFeature(e)}),!E(t.creationInfo))return e._startCreating()},y=async()=>{if(E(t.creationInfo))try{await e.data.viewModel.back()}catch{}return e._startCreating()};c.push(m,l.on("create",t=>e._updatingHandles.addPromise(f(t))),l.on("update",t=>e._updatingHandles.addPromise(w(t))),l.on("delete",t=>e._updatingHandles.addPromise(g(t))),h(()=>!e.numPendingFeatures,()=>e._updatingHandles.addPromise(y())),i(()=>{l.cancel()}),ce(l,t),...ue(t));const v=r(c);return l.addHandles(v),v}_initializeSketchViewModel(){const{data:e}=this,{view:t}=e.viewModel,a=new b({elevationInfo:e.creationInfo?.layer.elevationInfo,internal:!0,listMode:"hide",title:"createFeaturesWorkflow-internal"}),r=new ae({layer:a,creationMode:"single",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()}),u(()=>this.numPendingFeatures>0,e=>this._sketchViewModel.updateOnGraphicClick=e,p)])}_hasValidationErrors(e){return!!e&&(!this.data.isSubmittable(e)||!!this._featureFormViewModel.validateContingencyConstraints(e.attributes,{includeIncompleteViolations:!0})?.length)}async _processEdits(e,t){const{data:a,_featureFormViewModel:i}=this,{layerInfos:r,view:s}=a.viewModel;i.editType="INSERT",i.map=s?.map,i.spatialReference=s?.spatialReference;const{templateExecutorInfo:o}=a;if(!o){const t=e.clone();return t.geometry=null,await this._addAndInitializeEdits(e,t),e}const n=this.sketchViewModel.layer;n.remove(e);const{executor:l}=o,d=l(e.geometry,"completion"),u=c(d)?await d:d;o.completionResults.push(u),Q(u.relationships),i.editType="INSERT",i.map=s?.map,i.spatialReference=s?.spatialReference,u.primary&&a.creationInfo?.attributeOverrides&&(u.primary.graphic.attributes={...u.primary.graphic.attributes,...a.creationInfo.attributeOverrides});for(const c of u.edits){let e=null;if(c.addFeatures)for(const a of c.addFeatures){const i=a.clone();i.geometry=null,null!=a.geometry&&(a.symbol=await I(a,t),n.add(a)),a.sourceLayer!==e?.layer&&(e=R(r,a.sourceLayer));const s=!!u.associationGraphics?.has(a);await this._addAndInitializeEdits(a,i,e,s)}}i.feature=null,await m(()=>!i.updating);return u.edits.reduce((e,t)=>e+(t.addFeatures?.length??0),0)>1?null:u.primary?.graphic}async _addAndInitializeEdits(e,t,a,i=!1){const{data:r,_featureFormViewModel:s}=this,{layerInfos:o}=r.viewModel,n=r.addPendingFeature(e,t,{isAssociation:i});a??=R(o,e.sourceLayer),s.feature=e,s.formTemplate=a?.formTemplate,await m(()=>!s.updating),n.submittable=s.submittable}async _setUpCreatingFeaturesStep(){if(this.hasHandles(oe))return;const{data:e,sketchViewModel:s}=this,{creationInfo:o,viewModel:l}=e,{attachmentsViewModel:d,view:c}=l;if(!c||!o?.layer)throw new a("missing-parameters","CreateFeaturesWorkflow requires a view and creationInfo.");const{initialFeature:h,layer:m}=o,f=[],w=[];this._featureFormHandle=n(this._featureFormHandle),this._visualVariableAttributes={rotation:null,size:null},e.editorItem=l.findEditorItemForLayer(o.layer),o.template&&(null==e.fullTemplate&&await this._initializeFullTemplateAndExecutorInfo(e),w.push(i(()=>{e.templateExecutorInfo&&(e.templateExecutorInfo.completionResults=[])}))),s.allowDeleteKey=!e.isSharedTemplateWorkflow,X(d),f.push(u(()=>d.mode,e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}}));const g=Y(c);f.push(g);const y=M(o.layer),{template:F}=o,b=!F||_(F)||v(F)&&"feature"===F.type,I=y&&b;try{if(I){const a=h??new t({attributes:B(e.fullTemplate,o.attributeOverrides),sourceLayer:m}),i=await this._processEdits(a);i&&await this._startUpdating({feature:i})}else f.push(ie._configureSketchViewModel(this)),h?(E(o)&&o.geometryToPlace&&(h.attributes=B(e.fullTemplate,o.attributeOverrides)),s.layer.add(h),await this._startUpdating({feature:h})):await this._startCreating()}finally{g.remove()}const V=i(()=>{for(const t of e.pendingFeatures)s.layer.remove(t),e.removePendingFeature(t)}),k=u(()=>c?.timeZone,e=>{this._featureFormViewModel.timeZone=e,this.data.timeZone=e},p),S=i(()=>{E(o)&&l.cancelWorkflow({warnIfNoWorkflow:!1})});this._featureFormHandle&&f.push(this._featureFormHandle),this.addHandles(f,this._handleKeys.beforeCommit),this.addHandles(w,this._handleKeys.afterCommit),this.addHandles([i(()=>d.fileInfos.removeAll()),r(f),r(w),S,V,k],oe)}async _waitForActiveToolCleared(){const e=this.data.viewModel.view;if(null==e?.activeTool)return;const t=new AbortController;this.addHandles(s(t),ne),await m(()=>null==e?.activeTool,t.signal),t.abort()}};function ce(e,t){let a=null;const s=()=>e.snappingOptions.featureSources,o=()=>(a=new C({layer:e.layer}),s().add(a),a),n=()=>{null!=a&&(s().remove(a),a=l(a))};return r([u(()=>{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 n();a??=o(),a.enabled=t},f),i(n)])}function ue(e){const t=e.viewModel.view;if(!t)return[];const a=[];if("3d"===t.type){const r=new k({view:t});a.push(u(()=>e.selectedPendingFeature,(e,t)=>{r.remove(e),r.add(t)}),i(()=>r.destroy()))}const r=new k({view:t,highlightName:A});return a.push(u(()=>e.temporaryHighlightFeature,e=>{r.removeAll(),r.add(e)}),i(()=>r.destroy())),a}function he(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 pe(e){for(const t of e){const{sourceLayer:e}=t;e&&"globalIdField"in e&&null!=e.globalIdField&&(t.attributes[e.globalIdField]??=w())}}function me(e,t){const a=[];if(!t||0===t.size)return{addFeatures:e};for(const[i,r]of t)for(const{file:e}of r)a.push({feature:i,attachment:{globalId:w(),data:e}});return a.length?{addFeatures:e,addAttachments:a}:{addFeatures:e}}function fe(e,t){return e.map(e=>{const{addFeatures:a}=e;if(!a||0===a.length)return e;const i=[];for(const r of a){const e=t.get(r);if(e)for(const{file:t}of e)i.push({feature:r,attachment:{globalId:w(),data:t}})}return i.length?{...e,addAttachments:i}:e})}e([g()],de.prototype,"createFeatureState",void 0),e([g()],de.prototype,"data",void 0),e([g({constructOnly:!0})],de.prototype,"isNested",void 0),e([g()],de.prototype,"featureFormViewModel",null),e([g()],de.prototype,"hasPendingEdits",null),e([g()],de.prototype,"hasPreviousStep",null),e([g()],de.prototype,"_getDrawMeshHelpMessage",void 0),e([g()],de.prototype,"helpMessage",null),e([g()],de.prototype,"layer",null),e([g()],de.prototype,"parent",null),e([g()],de.prototype,"parentLayer",null),e([g()],de.prototype,"keyboardCancellationEnabled",null),e([g()],de.prototype,"reliesOnOwnerAdminPrivileges",null),e([g()],de.prototype,"shouldShowAttachments",null),e([g()],de.prototype,"shouldAllowAttachmentEditing",null),e([g()],de.prototype,"sketchViewModel",null),e([g()],de.prototype,"availableCreateTools",null),e([g()],de.prototype,"_attachmentsActive",null),de=ie=e([y("esri.widgets.Editor.CreateFeaturesWorkflow")],de);const we=de;export{we 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 o from"../../core/Logger.js";import{removeMaybe as n,destroyMaybe as l}from"../../core/maybe.js";import{debounce as d,isPromiseLike as c}from"../../core/promiseUtils.js";import{watch as u,when as h,initial as p,whenOnce as m,syncAndInitial as f}from"../../core/reactiveUtils.js";import{generateBracedUUID as w}from"../../core/uuid.js";import{property as g}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import{isSharedTemplateOrMetadata as v,isSharedTemplate as F,isStandardFeatureTemplate as _}from"../../editing/templateUtils.js";import b from"../../layers/GraphicsLayer.js";import{isTable as M}from"../../layers/support/layerUtils.js";import{isNumber as I}from"../../support/guards.js";import{getDisplayedSymbol as V}from"../../symbols/support/symbolUtils.js";import{getDrawHelpMessage as k}from"../../views/draw/support/helpMessageUtils.js";import S from"../../views/draw/support/HighlightHelper.js";import C from"../../views/interactive/sketch/SketchOptions.js";import A from"../../views/interactive/snapping/FeatureSnappingLayerSource.js";import{temporaryHighlightName as P}from"../../views/support/HighlightDefaults.js";import E from"./CreateFeaturesWorkflowData.js";import{isModelUpload as T,handleModelUpload as H}from"./modelUploadUtils.js";import j from"./Workflow.js";import{createToolFromGeometryType as U,getServiceEditsFromWorkflowData as L,getServiceInfoForLayer as x,orderEditsByRelationshipDependencies as O,getFullTemplateForCreationInfo as z,getServiceLayersById as W,startCreatingNewFeature as D,findLayerInfo as R,updateGraphicSymbolWhenRequired as N,isTerminalUpdateEventType as G,getVisualVariableAttributes as K,startUpdatingFeatureGeometry as Z,createWorkflowSteps as q,avoidFeatureTemplateSelectionWithOnlyOneItem as B,getCreationAttributes as J,setUpSketchCreateWatchers as Q,setRelationshipFields as X,prepareAttachmentsForCreateFeaturesWorkflow as Y,showProgressCursor as $,setVisualVariablesAndElevationInfoForUpdate as ee,visualVariableInteractiveUpdate as te}from"./workflowUtils.js";import ae from"../FeatureForm/FeatureFormViewModel.js";import ie from"../Sketch/SketchViewModel.js";var re;const se=Symbol(),oe=Symbol(),ne=Symbol(),le=Symbol(),de={point:["point"],multipoint:["multipoint"],polygon:["polygon","freehandPolygon","rectangle","circle"],polyline:["polyline","freehandPolyline"],mesh:[],multipatch:[]};let ce=re=class extends j{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 ae,this._sketchViewModel=null,this._attachmentFileInfos=new Map,this._isActive=!0}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 this._stepIndex>0||"update-pending"===this.createFeatureState&&!!this.data.selectedPendingFeature&&!this.parent&&!T(this.data.creationInfo)}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 k("rectangle"===s?"rectangle":"circle"===s?"circle":a,i?.geometry,r)}get layer(){return this.data.creationInfo?.layer}get numPendingFeatures(){return this.pendingFeatures.length}get numPendingFeaturesExcludingHidden(){return this.pendingFeatures.filter(e=>this.data.isDisplayable(e)).length}get parent(){return this.data.parent}get 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;if(!e)return[];if(this.data.creationInfo?.maxFeatures&&this.data.creationInfo.maxFeatures<=this.numPendingFeatures)return[];if(v(this.data.fullTemplate)){const{tool:t}=U(e,this.data.fullTemplate);return[t]}return"2d"!==t?.type&&"multipoint"===e?[]:[...de[e]]}get _attachmentsActive(){const e=this.data.viewModel.attachmentsViewModel.mode,t=this.stepId;return this.shouldShowAttachments&&("add"===e||"edit"===e||"adding-attachment"===t||"editing-attachment"===t)}async enter(){this._isActive=!0,"awaiting-feature-creation-info"!==this.stepId&&await this._updatingHandles.addPromise(this._setUpCreatingFeaturesStep())}exit(){this._isActive=!1,this.removeHandles([ne])}async updatePendingFeature(e){if(e!==this.data.selectedPendingFeature)return this._sketchViewModel.cancel(),this._startUpdating({feature:e})}async start(){return await super.start(),M(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||T(this.data.creationInfo)||this._attachmentsActive||this.parent?super.back(e):this._clearSelectedFeature()}previous(e){return"update-pending"!==this.createFeatureState||!this.data.selectedPendingFeature||T(this.data.creationInfo)||this._attachmentsActive?super.previous(e):this._clearSelectedFeature()}cancelFeature(e){this.data.isSharedTemplateWorkflow?o.getLogger(this).warn("Cannot cancel individual features created by shared templates."):(this.data.removePendingFeature(e),this.sketchViewModel.layer.graphics.remove(e))}static create(e){const{addAttachmentsCallback:t,applyEditsCallback:a,applyEditsFeatureServiceCallback:i,isNested:r,creationInfo:s,parent:o,snappingManager:n,startAt:l,viewModel:d}=e,c=e.sketchOptions??new C,u=s?.layer,h=u?d.findEditorItemForLayer(u):void 0,p=new re({data:new E({creationInfo:s,editorItem:h,parent:o,sketchOptions:c,snappingManager:n,viewModel:d}),isNested:r,onCommit:async e=>{const{creationInfo:r}=e;if(!r)return;p._sketchViewModel.cancel();const s=e.pendingFeatures.toArray(),{layer:o}=r,n=o.capabilities?.editing.supportsGlobalId&&"globalIdField"in o,l=p._attachmentFileInfos,{fullTemplate:c}=e,u=L(p.data),h=F(c)&&u;if(n){if(me(s),h){let t=we(u,l);const a=await x(o,d.view);a&&(t=O({edits:t,serviceInfo:a,view:d.view,findOriginalFeature:t=>e.getEditsForPendingFeature(t)?.initialFeature??t})),await i(c.featureService,t,{globalIdUsed:!0,gdbVersion:c.layer.gdbVersion??void 0})}else{const e=fe(s,l);await a(o,e,{globalIdUsed:!0})}return}const m=h?await i(c.featureService,u,{gdbVersion:c.layer.gdbVersion??void 0}):[await a(o,{addFeatures:s})];m&&l.size>0&&await Promise.all(m.map(e=>{if(e?.addFeatureResults)return t(o,pe(s,e.addFeatureResults,o,l))}))}});return p._set("steps",this._createWorkflowSteps(p,l)),p}_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 _initializeFullTemplateAndExecutorInfo(e){const{creationInfo:t}=e,{view:a}=e.viewModel;if(!t||!a)return null;const i=await z(t,a);if(e.fullTemplate=i,i&&F(i)){const{createTemplateExecutor:r}=await import("../../editing/sharedTemplates/executor/createTemplateExecutor.js"),s={completionResults:[],executor:await r(i),serviceLayersById:await W(t.layer,a)};e.templateExecutorInfo=s}return i}async _startCreating(){this.removeHandles(oe);const{data:e}=this;if(!e.creationInfo)return;const t=this.data.creationInfo?.maxFeatures;if(t&&this.numPendingFeatures>=t)return this.sketchViewModel.cancel(),void(this.numPendingFeatures&&await this._startUpdating({feature:this.pendingFeatures.at(-1)}));this.createFeatureState="create-new",await D(this._sketchViewModel,e,this._webStyleCache)}async _clearSelectedFeature(){const e=this._featureFormViewModel.pendingSubtypeChoice;e&&(e.resolve("undo"),await e.promise),this._stashValidationState(),this.sketchViewModel.cancel(),this.data.selectedPendingFeature=null,this._featureFormHandle=n(this._featureFormHandle),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:o,_sketchViewModel:l}=this,{creationInfo:d,viewModel:c}=a,{attachmentsViewModel:h,layerInfos:p,view:m}=c;if(!m||!d)return;n(this._featureFormHandle);const f=e.sourceLayer,w=R(p,f),g=w?.formTemplate,y=m.spatialReference;o.set({editType:"INSERT",feature:e,formTemplate:g,spatialReference:y,map:m.map}),"add"!==h.mode&&"edit"!==h.mode||c.activeWorkflow?.previous(),h.graphic=e,h.fileInfos.removeAll(),h.mode="view";(this._attachmentFileInfos.get(e)||[]).forEach(({file:e,form:t})=>h.addFile(e,t)),await N(e,s,"2d"===m.type?m.scale:null);const v=a.getEditsForPendingFeature(e);this._featureFormHandle=r([o.on("value-change",async({fieldName:t,value:a})=>{if(v?.updateAttributes(o.getValues()),I(a)){const e=this._visualVariableAttributes;e.size&&!e.size.isUpdatingInteractively&&t===e.size.field&&e.size.setInitialValue(a),e.rotation&&!e.rotation.isUpdatingInteractively&&t===e.rotation.field&&e.rotation.setInitialValue(a)}await N(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&&G(e.toolEventInfo.type))&&o.notifyFeatureGeometryChanged()}),u(()=>o.feature?.sourceLayer,t=>e.sourceLayer=t),u(()=>[o.feature,o.submittable],()=>this._stashValidationState())]),this.createFeatureState="update-pending"}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=e.sourceLayer??r.layer;return M(n)?void 0:(this._visualVariableAttributes=K(e),Z({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=q(["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&&(T(t)?e.addHandles(await H({view:r,data:a,next:()=>e.next(),cancel:()=>i.cancelWorkflow({warnIfNoWorkflow:!1})}),this.id):(a.parent&&t&&e.addHandles(i.restrictFeatureTemplatesViewModelToLayer(t.layer),this.id),e.addHandles(i.featureTemplatesViewModel.on("select",({item:t})=>{t&&(a.creationInfo={...a.creationInfo,layer:t.layer,template:t.template},e.next())}),this.id)))},async tearDown(){e.removeHandles(this.id)}}),"creating-features":()=>({id:"creating-features",async setUp(){e._isActive&&await e._setUpCreatingFeaturesStep()},async tearDown(t){const{viewModel:i}=a;t.canceled&&(e.removeHandles([ne,se,oe,le]),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 B(a,i)}static _configureSketchViewModel(e){const{data:t}=e,a=e._webStyleCache,{creationInfo:s,viewModel:o}=t,{view:n}=o,l=e._sketchViewModel,c=[];if(!n)return i();if("2d"===n.type){s&&c.push(e._fadeExistingFeatures(s.layer));const t=d((e,t)=>Promise.all(e.map(e=>N(e,a,t))));c.push(u(()=>n.scale,e=>t(l.layer.graphics,e)))}const p=J(t.fullTemplate,s?.attributeOverrides),m=u(()=>l.createGraphic,i=>{i&&!e.hasHandles(oe)&&e._updatingHandles.addPromise(Q({creationAttributes:p,data:t,sketchViewModel:l,view:n,webStyleCache:a}).then(t=>e.addHandles(t,oe)))}),f=async t=>{if("cancel"!==t.state&&"complete"!==t.state||e.removeHandles(oe),"cancel"===t.state&&null!==n.activeTool&&n.activeTool!==e.sketchViewModel.activeComponent&&(await e._waitForActiveToolCleared(),await e._startCreating()),"complete"===t.state&&t.graphic){const a=await e._processEdits(t.graphic,{scale:"2d"===n.type?n.scale:null,useSourceLayer:!0,webStyleCache:e._webStyleCache});a&&(await e._waitForActiveToolCleared(),await e._startUpdating({feature:a}))}},w=async a=>{const{attachmentsViewModel:i}=o,{_featureFormViewModel:r}=e;if(a.graphics.length>1)return void await e._clearSelectedFeature();const d=a.graphics[0];if("complete"===a.state){const{submittable:t}=r;if(e.numPendingFeatures!==s?.maxFeatures&&t||r.submit(),await e._clearSelectedFeature(),"add"!==i.mode&&"edit"!==i.mode||o.activeWorkflow?.previous(),!a.aborted&&n.activeTool===e.sketchViewModel.activeComponent&&(await e.sketchViewModel.wait(),"ready"===e.sketchViewModel.state&&"mesh"!==e.data.creationInfo?.layer.geometryType))return e._startCreating()}else{if("start"===a.state)return d.sourceLayer??=t.creationInfo?.layer,await ee({sketchViewModel:l,graphic:d,visualVariables:e._visualVariableAttributes,webStyleCache:e._webStyleCache,sourceLayer:d.sourceLayer}),e._selectFeatureForUpdate({feature:d});if("active"===a.state){await e.updatePendingFeature(d);const t=e._visualVariableAttributes;te(n,d,a,t)&&await N(d,e._webStyleCache,"2d"===n.type?n.scale:null);const i=d.attributes,{rotation:s,size:o}=t;if(null!=s){const{field:e}=s;r.setValue(e,i[e])}if(null!=o){const{field:e}=o;r.setValue(e,i[e])}}}},g=async a=>{if(a.graphics.forEach(e=>{t.removePendingFeature(e)}),!T(t.creationInfo))return e._startCreating()},y=async()=>{if(T(t.creationInfo))try{await e.data.viewModel.back()}catch{}return e._startCreating()};c.push(m,l.on("create",t=>e._updatingHandles.addPromise(f(t))),l.on("update",t=>e._updatingHandles.addPromise(w(t))),l.on("delete",t=>e._updatingHandles.addPromise(g(t))),h(()=>!e.numPendingFeatures,()=>e._updatingHandles.addPromise(y())),i(()=>{l.cancel()}),ue(l,t),...he(t));const v=r(c);return l.addHandles(v),v}_initializeSketchViewModel(){const{data:e}=this,{view:t}=e.viewModel,a=new b({elevationInfo:e.creationInfo?.layer.elevationInfo,internal:!0,listMode:"hide",title:"createFeaturesWorkflow-internal"}),r=new ie({layer:a,creationMode:"single",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()}),u(()=>this.numPendingFeatures>0,e=>this._sketchViewModel.updateOnGraphicClick=e,p)])}_hasValidationErrors(e){return!!e&&(!this.data.isSubmittable(e)||!!this._featureFormViewModel.validateContingencyConstraints(e.attributes,{includeIncompleteViolations:!0})?.length)}async _processEdits(e,t){const{data:a,_featureFormViewModel:i}=this,{layerInfos:r,view:s}=a.viewModel;i.editType="INSERT",i.map=s?.map,i.spatialReference=s?.spatialReference;const{templateExecutorInfo:o}=a;if(!o){const t=e.clone();return t.geometry=null,await this._addAndInitializeEdits(e,t),e}const n=this.sketchViewModel.layer;n.remove(e);const{executor:l}=o,d=l(e.geometry,"completion"),u=c(d)?await d:d;o.completionResults.push(u),X(u.relationships),i.editType="INSERT",i.map=s?.map,i.spatialReference=s?.spatialReference,u.primary&&a.creationInfo?.attributeOverrides&&(u.primary.graphic.attributes={...u.primary.graphic.attributes,...a.creationInfo.attributeOverrides});for(const c of u.edits){let e=null;if(c.addFeatures)for(const a of c.addFeatures){const i=a.clone();i.geometry=null,null!=a.geometry&&(a.symbol=await V(a,t),n.add(a)),a.sourceLayer!==e?.layer&&(e=R(r,a.sourceLayer));const s=!!u.associationGraphics?.has(a);await this._addAndInitializeEdits(a,i,e,s)}}i.feature=null,await m(()=>!i.updating);return u.edits.reduce((e,t)=>e+(t.addFeatures?.length??0),0)>1?null:u.primary?.graphic}async _addAndInitializeEdits(e,t,a,i=!1){const{data:r,_featureFormViewModel:s}=this,{layerInfos:o}=r.viewModel,n=r.addPendingFeature(e,t,{isAssociation:i});a??=R(o,e.sourceLayer),s.feature=e,s.formTemplate=a?.formTemplate,await m(()=>!s.updating),n.submittable=s.submittable}async _setUpCreatingFeaturesStep(){if(this.hasHandles(ne))return;const{data:e,sketchViewModel:s}=this,{creationInfo:o,viewModel:l}=e,{attachmentsViewModel:d,view:c}=l;if(!c||!o?.layer)throw new a("missing-parameters","CreateFeaturesWorkflow requires a view and creationInfo.");const{initialFeature:h,layer:m}=o,f=[],w=[];this._featureFormHandle=n(this._featureFormHandle),this._visualVariableAttributes={rotation:null,size:null},e.editorItem=l.findEditorItemForLayer(o.layer),o.template&&(null==e.fullTemplate&&await this._initializeFullTemplateAndExecutorInfo(e),w.push(i(()=>{e.templateExecutorInfo&&(e.templateExecutorInfo.completionResults=[])}))),s.allowDeleteKey=!e.isSharedTemplateWorkflow,Y(d),f.push(u(()=>d.mode,e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}}));const g=$(c);f.push(g);const y=M(o.layer),{template:F}=o,b=!F||_(F)||v(F)&&"feature"===F.type,I=y&&b;try{if(I){const a=h??new t({attributes:J(e.fullTemplate,o.attributeOverrides),sourceLayer:m}),i=await this._processEdits(a);i&&await this._startUpdating({feature:i})}else f.push(re._configureSketchViewModel(this)),h?(T(o)&&o.geometryToPlace&&(h.attributes=J(e.fullTemplate,o.attributeOverrides)),s.layer.add(h),await this._startUpdating({feature:h})):await this._startCreating()}finally{g.remove()}const V=i(()=>{for(const t of e.pendingFeatures)s.layer.remove(t),e.removePendingFeature(t)}),k=u(()=>c?.timeZone,e=>{this._featureFormViewModel.timeZone=e,this.data.timeZone=e},p),S=i(()=>{T(o)&&l.cancelWorkflow({warnIfNoWorkflow:!1})});this._featureFormHandle&&f.push(this._featureFormHandle),this.addHandles(f,this._handleKeys.beforeCommit),this.addHandles(w,this._handleKeys.afterCommit),this.addHandles([i(()=>d.fileInfos.removeAll()),r(f),r(w),S,V,k],ne)}async _waitForActiveToolCleared(){const e=this.data.viewModel.view;if(null==e?.activeTool)return;const t=new AbortController;this.addHandles(s(t),le),await m(()=>null==e?.activeTool,t.signal),t.abort()}};function ue(e,t){let a=null;const s=()=>e.snappingOptions.featureSources,o=()=>(a=new A({layer:e.layer}),s().add(a),a),n=()=>{null!=a&&(s().remove(a),a=l(a))};return r([u(()=>{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 n();a??=o(),a.enabled=t},f),i(n)])}function he(e){const t=e.viewModel.view;if(!t)return[];const a=[];if("3d"===t.type){const r=new S({view:t});a.push(u(()=>e.selectedPendingFeature,(e,t)=>{r.remove(e),r.add(t)}),i(()=>r.destroy()))}const r=new S({view:t,highlightName:P});return a.push(u(()=>e.temporaryHighlightFeature,e=>{r.removeAll(),r.add(e)}),i(()=>r.destroy())),a}function pe(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 me(e){for(const t of e){const{sourceLayer:e}=t;e&&"globalIdField"in e&&null!=e.globalIdField&&(t.attributes[e.globalIdField]??=w())}}function fe(e,t){const a=[];if(!t||0===t.size)return{addFeatures:e};for(const[i,r]of t)for(const{file:e}of r)a.push({feature:i,attachment:{globalId:w(),data:e}});return a.length?{addFeatures:e,addAttachments:a}:{addFeatures:e}}function we(e,t){return e.map(e=>{const{addFeatures:a}=e;if(!a||0===a.length)return e;const i=[];for(const r of a){const e=t.get(r);if(e)for(const{file:t}of e)i.push({feature:r,attachment:{globalId:w(),data:t}})}return i.length?{...e,addAttachments:i}:e})}e([g()],ce.prototype,"createFeatureState",void 0),e([g()],ce.prototype,"data",void 0),e([g({constructOnly:!0})],ce.prototype,"isNested",void 0),e([g()],ce.prototype,"featureFormViewModel",null),e([g()],ce.prototype,"hasPendingEdits",null),e([g()],ce.prototype,"hasPreviousStep",null),e([g()],ce.prototype,"_getDrawMeshHelpMessage",void 0),e([g()],ce.prototype,"helpMessage",null),e([g()],ce.prototype,"layer",null),e([g()],ce.prototype,"parent",null),e([g()],ce.prototype,"parentLayer",null),e([g()],ce.prototype,"keyboardCancellationEnabled",null),e([g()],ce.prototype,"reliesOnOwnerAdminPrivileges",null),e([g()],ce.prototype,"shouldShowAttachments",null),e([g()],ce.prototype,"shouldAllowAttachmentEditing",null),e([g()],ce.prototype,"sketchViewModel",null),e([g()],ce.prototype,"availableCreateTools",null),e([g()],ce.prototype,"_attachmentsActive",null),ce=re=e([y("esri.widgets.Editor.CreateFeaturesWorkflow")],ce);const ge=ce;export{ge as default};
@@ -1,4 +1,4 @@
1
1
  import "../../interfaces";
2
2
 
3
- import EditableInput = __esri.EditableInput;
4
- export default EditableInput;
3
+ import FeatureFormEditableInput = __esri.FeatureFormEditableInput;
4
+ export default FeatureFormEditableInput;
@@ -1,4 +1,4 @@
1
1
  import "../../interfaces";
2
2
 
3
- import FieldInput = __esri.FieldInput;
4
- export default FieldInput;
3
+ import FeatureFormFieldInput = __esri.FeatureFormFieldInput;
4
+ export default FeatureFormFieldInput;
@@ -1,4 +1,4 @@
1
1
  import "../../interfaces";
2
2
 
3
- import GroupInput = __esri.GroupInput;
4
- export default GroupInput;
3
+ import FeatureFormGroupInput = __esri.FeatureFormGroupInput;
4
+ export default FeatureFormGroupInput;
@@ -1,4 +1,4 @@
1
1
  import "../../interfaces";
2
2
 
3
- import InputBase = __esri.InputBase;
4
- export default InputBase;
3
+ import FeatureFormInputBase = __esri.FeatureFormInputBase;
4
+ export default FeatureFormInputBase;