@arcgis/core 4.28.0-next.20230720 → 4.28.0-next.20230721

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 (261) hide show
  1. package/Color.js +1 -1
  2. package/analysis/AreaMeasurementAnalysis.js +1 -1
  3. package/arcade/arcadeCompiler.js +1 -1
  4. package/arcade/featureSetUtils.js +1 -1
  5. package/arcade/featureset/actions/Top.js +1 -1
  6. package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
  7. package/arcade/featureset/support/FeatureSet.js +1 -1
  8. package/arcade/featureset/support/FeatureSetIterator.js +1 -1
  9. package/arcade/functions/convertdirection.js +1 -1
  10. package/arcade/functions/featuresetbase.js +1 -1
  11. package/arcade/functions/geomasync.js +1 -1
  12. package/arcade/functions/geomsync.js +1 -1
  13. package/arcade/lib/comment-handler.js +1 -1
  14. package/arcade/lib/parser.js +1 -1
  15. package/arcade/lib/scanner.js +1 -1
  16. package/assets/esri/core/workers/RemoteClient.js +1 -1
  17. package/assets/esri/core/workers/chunks/{75c28da8d0b02d612d69.js → 040b3fc9c9c0736dd893.js} +1 -1
  18. package/assets/esri/core/workers/chunks/0652f6a8d5221e978033.js +1 -0
  19. package/assets/esri/core/workers/chunks/{c13b332afdb3f6be1ec9.js → 092fda62b6f62c2e4869.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{57e0ad037188bd2997e7.js → 0af18a96cbd4e2d35436.js} +1 -1
  21. package/assets/esri/core/workers/chunks/0b5eeec0f66c87a46a0c.js +1 -0
  22. package/assets/esri/core/workers/chunks/{68e568b67b6fb34393db.js → 0cad2b991d0d0fd07846.js} +1 -1
  23. package/assets/esri/core/workers/chunks/0dccbc6c2559fdc0c2ad.js +1 -0
  24. package/assets/esri/core/workers/chunks/256a82f6f6e1405fbcc6.js +1 -0
  25. package/assets/esri/core/workers/chunks/{bb9213899049e1db90da.js → 2c57c9bd71637c5bed8a.js} +1 -1
  26. package/assets/esri/core/workers/chunks/2cdbabcbfe32286ec78d.js +1 -0
  27. package/assets/esri/core/workers/chunks/{2b1c83453a862e01954b.js → 2d9d80b2d0042a9c09fb.js} +1 -1
  28. package/assets/esri/core/workers/chunks/2f9aec2238ff6cb99e09.js +1 -0
  29. package/assets/esri/core/workers/chunks/{7dbd3e6406fb3e3a1a8f.js → 3cf748c025f3936c1cb2.js} +1 -1
  30. package/assets/esri/core/workers/chunks/4481d1103363434f16da.js +1 -0
  31. package/assets/esri/core/workers/chunks/5ae325e6a795c72eac6c.js +1 -0
  32. package/assets/esri/core/workers/chunks/5e4dde2886a1027b4b96.js +1 -0
  33. package/assets/esri/core/workers/chunks/730eb7e5f617fdab4f10.js +1 -0
  34. package/assets/esri/core/workers/chunks/{5a2e6bed9431cf4f42b1.js → 740dc67038f554431f1b.js} +1 -1
  35. package/assets/esri/core/workers/chunks/{09178454bda15bb7929a.js → 7fbdfd1527582c52f9b6.js} +1 -1
  36. package/assets/esri/core/workers/chunks/{1c026947505a9ff94a53.js → 807742f38885fa90b4fe.js} +1 -1
  37. package/assets/esri/core/workers/chunks/82dfbc175b52c7a10475.js +1 -0
  38. package/assets/esri/core/workers/chunks/870a05451e074b58f19a.js +1 -0
  39. package/assets/esri/core/workers/chunks/8c5a8c1dfb086069bb06.js +1 -0
  40. package/assets/esri/core/workers/chunks/99a5a434e0bad48c7a5c.js +1 -0
  41. package/assets/esri/core/workers/chunks/9a5916c66dad91d01d5b.js +1 -0
  42. package/assets/esri/core/workers/chunks/9c133fd8c1fbd0295b86.js +1 -0
  43. package/assets/esri/core/workers/chunks/9cddb504079d396779ea.js +1 -0
  44. package/assets/esri/core/workers/chunks/a3a1d4f32e518e97d071.js +1 -0
  45. package/assets/esri/core/workers/chunks/{9548aa449fe3a300c015.js → a4fa40dc77e116c954ac.js} +1 -1
  46. package/assets/esri/core/workers/chunks/a54ec9929a7db879d5db.js +1 -0
  47. package/assets/esri/core/workers/chunks/afc5b84693757fda2bc8.js +1 -0
  48. package/assets/esri/core/workers/chunks/{591b5c277cfd3a4101a4.js → b08f2a4aa94087c6c367.js} +1 -1
  49. package/assets/esri/core/workers/chunks/c0e12f6a7bb2360e4c21.js +1 -0
  50. package/assets/esri/core/workers/chunks/c8e656cd470a17f538e9.js +1 -0
  51. package/assets/esri/core/workers/chunks/d0e203405f95e14b1399.js +1 -0
  52. package/assets/esri/core/workers/chunks/{ec72f492f24e67e008ae.js → d8e58dc14d3495f0830c.js} +1 -1
  53. package/assets/esri/core/workers/chunks/ddc393a012588f799f42.js +1 -0
  54. package/assets/esri/core/workers/chunks/de3baa85b1639c25458d.js +1 -0
  55. package/assets/esri/core/workers/chunks/e66cea26064ba8353af0.js +1 -0
  56. package/assets/esri/core/workers/chunks/ea478f2f4a19463e13fd.js +1 -0
  57. package/assets/esri/core/workers/chunks/eba197e45507f56f3ed0.js +1 -0
  58. package/assets/esri/core/workers/chunks/ebd006fcd568a7731115.js +1 -0
  59. package/assets/esri/core/workers/chunks/ef9a9a7d66d818720e20.js +1 -0
  60. package/assets/esri/core/workers/chunks/f3b458f55236566c940b.js +1 -0
  61. package/assets/esri/core/workers/chunks/fd0a91b9e0216cc269c3.js +1 -0
  62. package/assets/esri/core/workers/chunks/{a4fe220a912b1f428e49.js → fdd6403a8390d629392b.js} +1 -1
  63. package/assets/esri/themes/base/widgets/_Directions.scss +13 -7
  64. package/assets/esri/themes/dark/main.css +1 -1
  65. package/assets/esri/themes/light/main.css +1 -1
  66. package/assets/esri/themes/light/view.css +1 -1
  67. package/chunks/array.js +1 -1
  68. package/core/Collection.js +1 -1
  69. package/core/accessorSupport/decorators/subclass.js +1 -1
  70. package/core/accessorSupport/ensureType.js +1 -1
  71. package/core/accessorSupport/get.js +1 -1
  72. package/core/accessorSupport/tracking.js +1 -1
  73. package/core/accessorSupport/utils.js +1 -1
  74. package/core/libs/rbush/PooledRBush.js +1 -1
  75. package/core/urlUtils.js +1 -1
  76. package/geometry/GeometryCursor.js +1 -1
  77. package/geometry/support/TileClipper.js +1 -1
  78. package/geometry/support/geodesicUtils.js +1 -1
  79. package/interfaces.d.ts +7 -1
  80. package/layers/LinkChartLayer.js +1 -1
  81. package/layers/VectorTileLayer.js +1 -1
  82. package/layers/VoxelLayer.js +1 -1
  83. package/layers/WCSLayer.js +1 -1
  84. package/layers/effects/EffectView.js +1 -1
  85. package/layers/graphics/sources/geojson/geojson.js +1 -1
  86. package/layers/knowledgeGraph/KnowledgeGraphLayerDataManager.js +1 -1
  87. package/layers/mixins/ArcGISCachedService.js +1 -1
  88. package/layers/support/ElevationQuery.js +1 -1
  89. package/layers/support/MultidimensionalSubset.js +1 -1
  90. package/layers/support/TileInfo.js +1 -1
  91. package/layers/support/TileInfoTilemapCache.js +1 -1
  92. package/layers/support/TilemapCache.js +1 -1
  93. package/layers/support/rasterDatasets/multidimensionalUtils.js +1 -1
  94. package/layers/support/rasterDatasets/pamParser.js +1 -1
  95. package/layers/support/rasterDatasets/wcsCoverageParser.js +1 -1
  96. package/layers/support/rasterFormats/Raw.js +1 -1
  97. package/layers/support/rasterFormats/TiffDecoder.js +1 -1
  98. package/layers/support/rasterFunctions/ExtractBandFunction.js +1 -1
  99. package/layers/support/rasterFunctions/colormaps.js +1 -1
  100. package/layers/support/rasterFunctions/pixelUtils.js +1 -1
  101. package/layers/support/rasterFunctions/rasterProjectionHelper.js +1 -1
  102. package/layers/video/VideoController.js +1 -1
  103. package/layers/voxel/VoxelDimension.js +1 -1
  104. package/layers/voxel/VoxelTransferFunctionStyle.js +1 -1
  105. package/layers/voxel/VoxelVolume.js +1 -1
  106. package/package.json +1 -1
  107. package/renderers/support/RasterSymbolizer.js +1 -1
  108. package/renderers/support/colorRampUtils.js +1 -1
  109. package/renderers/visualVariables/support/visualVariableUtils.js +1 -1
  110. package/rest/query/operations/pbfDehydratedFeatureSet.js +1 -1
  111. package/rest/query/operations/pbfJSONFeatureSet.js +1 -1
  112. package/rest/support/generateRendererUtils.js +1 -1
  113. package/smartMapping/raster/renderers/classBreaks.js +1 -1
  114. package/smartMapping/renderers/color.js +1 -1
  115. package/smartMapping/renderers/support/utils.js +1 -1
  116. package/smartMapping/renderers/type.js +1 -1
  117. package/smartMapping/renderers/univariateColorSize.js +1 -1
  118. package/smartMapping/support/adapters/support/utils.js +1 -1
  119. package/statistics/utils.js +1 -1
  120. package/support/revision.js +1 -1
  121. package/symbols/cim/CIMSymbolDrawHelper.js +1 -1
  122. package/symbols/cim/GeometryWalker.js +1 -1
  123. package/symbols/cim/cimAnalyzer.js +1 -1
  124. package/symbols/cim/effects/EffectArrow.js +1 -1
  125. package/symbols/cim/effects/EffectControlMeasureLine.js +1 -1
  126. package/symbols/support/symbolUtils.js +1 -1
  127. package/views/2d/constraints/ZoomConstraint.js +1 -1
  128. package/views/2d/engine/flow/dataUtils.js +1 -1
  129. package/views/2d/engine/flow/utils.js +1 -1
  130. package/views/2d/engine/vectorTiles/VectorTile.js +1 -1
  131. package/views/2d/engine/vectorTiles/VectorTileContainer.js +1 -1
  132. package/views/2d/engine/vectorTiles/expression/expression.js +1 -1
  133. package/views/2d/engine/vectorTiles/style/VectorTileSource.js +1 -1
  134. package/views/2d/engine/vectorTiles/tileInfoUtils.js +1 -1
  135. package/views/2d/engine/webgl/TurboLine.js +1 -1
  136. package/views/2d/engine/webgl/mesh/MeshData.js +1 -1
  137. package/views/2d/engine/webgl/mesh/templates/shapingUtils.js +1 -1
  138. package/views/2d/interactive/editingTools/ControlPointsTransformTool.js +1 -1
  139. package/views/2d/interactive/editingTools/draw/DrawGraphicTool2D.js +1 -1
  140. package/views/2d/layers/BaseLayerView2D.js +1 -1
  141. package/views/2d/layers/BaseLayerViewGL2D.js +1 -1
  142. package/views/2d/layers/BitmapTileLayerView2D.js +1 -1
  143. package/views/2d/layers/MediaLayerView2D.js +1 -1
  144. package/views/2d/layers/TileLayerView2D.js +1 -1
  145. package/views/2d/layers/VectorTileLayerView2D.js +1 -1
  146. package/views/2d/layers/WMTSLayerView2D.js +1 -1
  147. package/views/2d/layers/features/support/rendererUtils.js +1 -1
  148. package/views/2d/layers/imagery/BaseImageryTileSubView2D.js +1 -1
  149. package/views/2d/layers/support/vectorTileDebugUtils.js +5 -0
  150. package/views/2d/tiling/TileInfoView.js +1 -1
  151. package/views/2d/tiling/TileInfoViewPOT.js +1 -1
  152. package/views/2d/tiling/TileQueue.js +1 -1
  153. package/views/2d/tiling.js +1 -1
  154. package/views/3d/analysis/Slice/sliceToolUtils.js +1 -1
  155. package/views/3d/environment/ChapmanAtmosphere.js +1 -1
  156. package/views/3d/interactive/editingTools/moveGraphic/GraphicMoveTool.js +1 -1
  157. package/views/3d/layers/ImageryTileLayerView3D.js +1 -1
  158. package/views/3d/layers/TiledLayerView3D.js +1 -1
  159. package/views/3d/layers/VectorTileLayerView3D.js +1 -1
  160. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  161. package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
  162. package/views/3d/layers/support/featureReference.js +1 -1
  163. package/views/3d/support/LaserLineRenderer.js +1 -1
  164. package/views/3d/terrain/Overlay.js +1 -1
  165. package/views/3d/terrain/OverlayFramebufferObject.js +1 -1
  166. package/views/3d/terrain/OverlayRenderTarget.js +1 -1
  167. package/views/3d/terrain/OverlayRenderer.js +1 -1
  168. package/views/3d/terrain/TerrainRenderer.js +1 -1
  169. package/views/3d/terrain/TileCompositor.js +1 -1
  170. package/views/3d/terrain/TileRenderer.js +1 -1
  171. package/views/3d/terrain/TilingScheme.js +1 -1
  172. package/views/3d/webgl-engine/collections/Component/ComponentData.js +1 -1
  173. package/views/3d/webgl-engine/core/shaderModules/interfaces.js +1 -1
  174. package/views/3d/webgl-engine/effects/ScreenSpaceGeometry.js +1 -1
  175. package/views/3d/webgl-engine/effects/SmaaRenderPass.js +1 -1
  176. package/views/3d/webgl-engine/lib/CompositingHelper.js +1 -1
  177. package/views/3d/webgl-engine/lib/GeometryUtil.js +1 -1
  178. package/views/3d/webgl-engine/lib/PathBuilder.js +1 -1
  179. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  180. package/views/3d/webgl-engine/lib/RenderingContext.js +1 -1
  181. package/views/3d/webgl-engine/lib/SortedRenderGeometryRenderer.js +1 -1
  182. package/views/3d/webgl-engine/lib/WebGLLayer.js +1 -1
  183. package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
  184. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  185. package/views/3d/webgl-engine/parts/requireUtils.js +1 -1
  186. package/views/MapView.js +1 -1
  187. package/views/animation/pointToPoint/Path.js +1 -1
  188. package/views/draw/DrawOperation.js +1 -1
  189. package/views/draw/support/Reshape.js +1 -1
  190. package/views/draw/support/createUtils.js +1 -1
  191. package/views/interactive/SegmentLabels.js +1 -1
  192. package/views/interactive/editGeometry/EditGeometry.js +1 -1
  193. package/views/interactive/editGeometry/EditGeometryOperations.js +1 -1
  194. package/views/interactive/editGeometry/operations/UndoGroup.js +1 -1
  195. package/views/layers/GroupLayerView.js +1 -1
  196. package/views/webgl/ProgramCache.js +1 -1
  197. package/webscene/spec-certification/api.js +1 -1
  198. package/webscene/spec-certification/spec.js +1 -1
  199. package/webscene/spec-certification/utils.js +1 -1
  200. package/widgets/BuildingExplorer/BuildingNumericFilterViewModel.js +1 -1
  201. package/widgets/BuildingExplorer/BuildingPhase.js +1 -1
  202. package/widgets/BuildingExplorer/support/validation.js +1 -1
  203. package/widgets/Directions/support/resources.js +1 -1
  204. package/widgets/Directions.js +1 -1
  205. package/widgets/Editor/UpdateRecordWorkflow.js +1 -1
  206. package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
  207. package/widgets/FeatureForm/FieldInput.js +1 -1
  208. package/widgets/FeatureForm/FormExpressionsManager.js +1 -1
  209. package/widgets/FeatureForm.js +1 -1
  210. package/widgets/Features.js +1 -1
  211. package/widgets/Histogram/HistogramViewModel.js +1 -1
  212. package/widgets/HistogramRangeSlider/HistogramRangeSliderViewModel.js +1 -1
  213. package/widgets/Legend/styles/Card.js +1 -1
  214. package/widgets/Legend/styles/support/univariateUtils.js +1 -1
  215. package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
  216. package/widgets/Legend/support/colorRampUtils.js +1 -1
  217. package/widgets/Legend/support/sizeRampUtils.js +1 -1
  218. package/widgets/Legend/support/utils.js +1 -1
  219. package/widgets/Popup.js +1 -1
  220. package/widgets/ScaleRangeSlider/ScaleRangeSliderViewModel.js +1 -1
  221. package/widgets/ScaleRangeSlider/ScaleRanges.js +1 -1
  222. package/widgets/ValuePicker/ValuePickerSlider.js +1 -1
  223. package/widgets/smartMapping/ClassedSizeSlider.js +1 -1
  224. package/widgets/smartMapping/ColorSizeSlider.js +1 -1
  225. package/widgets/smartMapping/HeatmapSlider/HeatmapSliderViewModel.js +1 -1
  226. package/widgets/smartMapping/SizeSlider.js +1 -1
  227. package/widgets/smartMapping/SmartMappingPrimaryHandleSliderViewModel.js +1 -1
  228. package/widgets/smartMapping/SmartMappingSliderViewModel.js +1 -1
  229. package/assets/esri/core/workers/chunks/0210f4c2e1f3ed13041b.js +0 -1
  230. package/assets/esri/core/workers/chunks/07bb40162d97d098bc19.js +0 -1
  231. package/assets/esri/core/workers/chunks/0a18317566c1fcb68422.js +0 -1
  232. package/assets/esri/core/workers/chunks/0de65e03db8c611af9fb.js +0 -1
  233. package/assets/esri/core/workers/chunks/1a60d23a92bcf91dbb22.js +0 -1
  234. package/assets/esri/core/workers/chunks/205a0b34b698d5329854.js +0 -1
  235. package/assets/esri/core/workers/chunks/25211d5904ee9d5f4a9d.js +0 -1
  236. package/assets/esri/core/workers/chunks/26b12d1ea713c1e07701.js +0 -1
  237. package/assets/esri/core/workers/chunks/2bfa7ee324c32a56b0d3.js +0 -1
  238. package/assets/esri/core/workers/chunks/4510a17839405146130b.js +0 -1
  239. package/assets/esri/core/workers/chunks/524156c3f5383c2dd0e3.js +0 -1
  240. package/assets/esri/core/workers/chunks/59666ecb7c2c1f5a13b2.js +0 -1
  241. package/assets/esri/core/workers/chunks/5c005c9514354c77ec27.js +0 -1
  242. package/assets/esri/core/workers/chunks/620ec5c75561183d3d73.js +0 -1
  243. package/assets/esri/core/workers/chunks/68512670816f59c0e6a5.js +0 -1
  244. package/assets/esri/core/workers/chunks/6c7374ebc18b46b3480a.js +0 -1
  245. package/assets/esri/core/workers/chunks/75ba2af92da232067adb.js +0 -1
  246. package/assets/esri/core/workers/chunks/7c1f0598a016516dcec3.js +0 -1
  247. package/assets/esri/core/workers/chunks/8dcec8d1b670d2b7ea2b.js +0 -1
  248. package/assets/esri/core/workers/chunks/8e07dfb6fc2673b640cb.js +0 -1
  249. package/assets/esri/core/workers/chunks/9050b167355588b7003d.js +0 -1
  250. package/assets/esri/core/workers/chunks/9230d68799f0b0b9ef36.js +0 -1
  251. package/assets/esri/core/workers/chunks/af4083f2aad5f5d49dde.js +0 -1
  252. package/assets/esri/core/workers/chunks/b0a57718a0765d1c8df0.js +0 -1
  253. package/assets/esri/core/workers/chunks/b431b81a7bf45dd527da.js +0 -1
  254. package/assets/esri/core/workers/chunks/bda311ad48efdb265939.js +0 -1
  255. package/assets/esri/core/workers/chunks/d5cce09fbe16cbb8fee4.js +0 -1
  256. package/assets/esri/core/workers/chunks/da547c3cabe4a89c3ce6.js +0 -1
  257. package/assets/esri/core/workers/chunks/dd295fa57b45b7ec4ec5.js +0 -1
  258. package/assets/esri/core/workers/chunks/f553b464e969d45bf451.js +0 -1
  259. package/assets/esri/core/workers/chunks/f5865294983eb160de8c.js +0 -1
  260. package/assets/esri/core/workers/chunks/fdb7b1fbdb6fe091ad83.js +0 -1
  261. package/views/2d/tiling/PagedTileQueue.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{on as t,pausable as s}from"../core/events.js";import{makeHandle as i}from"../core/handleUtils.js";import{assertIsSome as o}from"../core/maybe.js";import{watch as r,initial as n,when as a,on as l}from"../core/reactiveUtils.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import{cast as d}from"../core/accessorSupport/decorators/cast.js";import"../core/arrayUtils.js";import"../core/has.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import{defaultUnitPropertyMetadata as h}from"../properties/defaultUnit.js";import p from"../rest/support/Stop.js";import v from"../symbols/SimpleMarkerSymbol.js";import m from"./Search.js";import _ from"./Widget.js";import g from"./Directions/DirectionsViewModel.js";import{SaveLayer as S}from"./Directions/components/SaveLayer.js";import{formatDistance as y,formatDuration as w}from"./Directions/support/directionsUtils.js";import{DepartureTimeOption as M,CSS as f,getIconPath as b}from"./Directions/support/resources.js";import{isArcGISWorldGeocoder as T,meteredArcGISLocatorUrl as C}from"./Search/support/locatorUtils.js";import{loadCalciteComponents as k}from"./support/componentsUtils.js";import D from"./support/DatePicker.js";import{Heading as I,incrementHeadingLevel as P}from"./support/Heading.js";import R from"./support/TimePicker.js";import{accessibleHandler as L}from"./support/decorators/accessibleHandler.js";import{messageBundle as B}from"./support/decorators/messageBundle.js";import{tsx as H}from"./support/jsxFactory.js";import"./support/widgetUtils.js";import A from"sortablejs";import{formatNumber as j}from"../intl/number.js";import{formatDate as E,convertDateFormatToIntlOptions as x}from"../intl/date.js";const O={departureTime:!0,layerDetails:!0,printButton:!1,saveAsButton:!0,saveButton:!0,stops:!0,traveMode:!0};function U(e){const t=e.getTimezoneOffset(),s=t>0?"-":"+",i=60,o=Math.abs(Math.floor(t/i)),r=Math.abs(Math.floor(t)%i),n={minimumIntegerDigits:2};return`GMT${s}${j(o,n)}${j(r,n)}`}function z(e){return!!e.composedPath?.().find((e=>e.classList?.contains("esri-search__suggestions-list")))}const $="search-term",F="date-time-picker",N=100,K=500;let V=class extends _{constructor(e,t){super(e,t),this._activeStop=null,this._activeManeuver=null,this._autoStopRemovalDelay=N,this._autoStopRemovalTimeoutId=void 0,this._departureTimeOption=M.NOW,this._datePicker=new D,this._focusedManeuver=null,this._newPlaceholderStop=null,this._pointerDownUpHandle=null,this._pointerPressedSearchSuggestionStop=null,this._renderSavePopoverFunction=null,this._saveAsButtonNode=null,this._saveLayer=new S,this._sections=null,this._sortable=null,this._stopsToSearches=new Map,this._timePicker=new R,this._viewClickHandle=null,this.headingLevel=2,this.iconClass=f.widgetIcon,this.icon=null,this.messages=null,this.messagesCommon=null,this.messagesUnits=null,this.searchProperties=null,this.viewModel=new g,this.visibleElements={...O},this._setUpDragAndDropStops=e=>{this._sortable=A.create(e,{draggable:`.${f.validStopRow}`,ghostClass:f.stopRowGhost,handle:`.${f.stopHandle}`,onEnd:this._handleStopInputDragEnd})},this._handleDragHandlePointerDown=()=>this.viewModel.layer?.stops.forEach((e=>this.acquireSearch(e).activeMenu="none")),this._handleStopInputDragEnd=({oldIndex:e,newIndex:t,target:s})=>{if(e===t||null==t||null==e)return;const{children:i}=s,o=i[t],r=i[e],n=t-e<0;s.insertBefore(o,n?r.nextElementSibling:r);const{stops:a}=this.viewModel.layer;a.reorder(a.at(e),t);for(const l of a)l.sequence=null;this._getDirections()}}initialize(){this.addHandles([r((()=>this.viewModel.layer?.routeInfo),(()=>{this._activeManeuver=null,this._focusedManeuver=null,this._sections=this._getSections(),this.scheduleRender()}),n),a((()=>this.view),((e,s)=>{if(s&&(this._viewClickHandle=null,null!=s&&this.removeHandles(s)),e){const s=this._prepPointerDownUpClick(),i=this._prepViewClick();s.pause(),i.pause();const o=e.surface;this.addHandles([t(o,"mousedown",(()=>this._autoStopRemovalDelay=K)),t(o,"mouseup",(()=>this._autoStopRemovalDelay=N)),s,i],e),this._pointerDownUpHandle=s,this._viewClickHandle=i}}),n),a((()=>null==this.viewModel.serviceDescription),(()=>{try{this.viewModel.load()}catch{}}),n),r((()=>this._saveLayer.state),(()=>{this.scheduleRender()}))]),this.when((()=>{this.destroyed||this.visibleElements.saveAsButton&&(this._renderSavePopoverFunction=this._renderSavePopover.bind(this),this._projector.append(document.body,this._renderSavePopoverFunction))}))}loadDependencies(){return k({button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),link:()=>import("@esri/calcite-components/dist/components/calcite-link.js"),popover:()=>import("@esri/calcite-components/dist/components/calcite-popover.js")})}destroy(){this._datePicker.destroy(),this._timePicker.destroy();for(const e of this._stopsToSearches.values())e.destroy();this._sortable?.destroy(),null!=this._renderSavePopoverFunction&&this._projector.detach(this._renderSavePopoverFunction)}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 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}castVisibleElements(e){return{...O,...e}}acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const s=this._stopsToSearches.get(e);return s.view=t,this._overrideDefaultSources(s),s}const s=new m({view:t,resultGraphicEnabled:!1,popupEnabled:!1,...this.searchProperties});return this._normalizeSearchSources(s),this.addHandles([l((()=>s.allSources),"change",(()=>this._normalizeSearchSources(s))),s.on("select-result",(()=>{e.geometry=s.selectedResult?.feature.geometry,e.name=s.selectedResult?.name,this._getDirections()})),s.on("search-focus",(()=>this._handleStopInputFocus(s,e))),s.on("search-blur",(()=>this._handleStopInputBlur(s,e))),s.on("search-clear",(()=>{e.geometry=null,e.name=null,this._activeStop=e,this.viewModel.layer?.removeResult()})),r((()=>s.searchTerm),(t=>{e.name=t}))],s),this._stopsToSearches.set(e,s),s}getDirections(){return this.viewModel.getDirections()}render(){return H("div",{class:this.classes(f.base,f.scroller)},this._renderPanelContent())}save(){return this.viewModel.save()}saveAs(e,t={}){return this.viewModel.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_renderPanelContent(){const{layer:e,serviceDescription:t,state:s}=this.viewModel,i="initializing"===s,o="error"===s&&!t,r="unauthenticated"===s,n={[f.panelContentLoading]:i,[f.panelContentError]:o||!e,[f.panelContentSignIn]:r},a=i?"presentation":"group",l=e?r?this._renderSignIn():o?this._renderMessage(this._getErrorMessage()):i?this._renderLoader():this._renderReadyContent():this._renderMessage(this.messages.missingLayer);return H("div",{class:this.classes(f.panelContent,n),role:a},l)}_renderReadyContent(){return[this._renderStopsContainer(),this._renderTravelModeOptions(),this._renderDepartureTimeControls(),this._renderSaveContainer(),this._renderSectionSplitter(),this._renderDirectionsContainer()]}_renderSignIn(){return H("div",{key:"sign-in",class:f.signInContent},H(I,{class:f.contentTitle,level:this.headingLevel},this.messages.widgetLabel),this._renderPlaceholder(),H(I,{level:P(this.headingLevel)},this.messages.signInRequired),H("button",{class:this.classes(f.button,f.buttonSecondary,f.signInButton),tabIndex:0,onclick:this._handleSignInClick,bind:this,type:"button"},this.messagesCommon.auth.signIn))}_handleSignInClick(){this.viewModel.load().catch((()=>{}))}_renderTravelModeOptions(){if(!this.visibleElements.traveMode)return null;const{selectedTravelMode:e,travelModes:t}=this.viewModel;if(0===t.length)return null;const s=null!=e?e.name:this.messages.travelMode;return H("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(f.travelMode,this._saveLayer.opened&&f.buttonDisabled),key:"esri-directions__travel-mode-controls",role:"group"},H("select",{"aria-label":s,bind:this,class:this.classes(f.travelModeSelect,f.select),key:"esri-directions__travel-mode-options",onchange:this._handleTravelModeChange,title:s},t.map(((t,s)=>H("option",{key:`esri-directions__travel-mode-${s}`,"data-mode":t,selected:e===t,value:`${s}`},t.name)))))}_handleTravelModeChange(e){const t=e.currentTarget;this.viewModel.selectedTravelMode=q(t.item(t.selectedIndex)),this._getDirections()}_renderStopsContainer(){return this.visibleElements.stops?H("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(f.section,this._saveLayer.opened&&f.buttonDisabled),key:"esri-directions__stops-container",role:"group"},this._renderStops()):null}_renderDepartureTimeControls(){if(!this.visibleElements.departureTime)return null;const{messages:{departAt:e,departureTime:t,leaveNow:s,timeUnspecified:i}}=this;return H("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(f.departureTime,this._saveLayer.opened&&f.buttonDisabled),key:"esri-directions__departure-time-controls",role:"group"},H("select",{"aria-label":t,bind:this,class:this.classes(f.departureTimeSelect,f.select),onchange:this._handleDepartureOptionChange,title:t},H("option",{value:M.NOW,selected:this._departureTimeOption===M.NOW},s),H("option",{value:M.DEPART_AT,selected:this._departureTimeOption===M.DEPART_AT},e),H("option",{value:M.UNSPECIFIED,selected:this._departureTimeOption===M.UNSPECIFIED},i)),this._departureTimeOption===M.DEPART_AT?this._renderTimeControls():null)}_renderStops(){const{stops:e}=this.viewModel.layer;let t=0;for(const o of this._stopsToSearches.keys())e.includes(o)||this._disposeSearch(o);for(const o of e){const e=this.acquireSearch(o);"none"!==e.activeMenu&&(t+=1),null!=o.name&&(e.searchTerm=o.name)}const s=e.toArray().map(((s,i)=>{const o=e.length,r=i>1&&null==s.geometry,n={[f.stopsIcon]:i>=0&&i<o-1,[f.lastStopIcon]:i===o-1},a={[f.lastStopIconContainer]:i===o-1},l={[f.validStopRow]:!r},c=e.at(i+1),d=c&&null!=c.geometry,u=i===o-1,h=i===o-2,p=2===o&&0===i||o>2&&!u&&!h||o>2&&h&&d||o>2&&u&&null==s.geometry,v=o<3,m=this.acquireSearch(s),{messages:_}=this,{removeStop:g,reverseStops:S,unlocated:y}=_,w=null!=s.geometry&&null!=s.name?s.name:y,M=j(i+1),b=`${_.stopLabel} ${M} (${w})`,T=`${this.id}__stop--${i}`,C=!!m.searchTerm&&!!m.selectedResult&&null!=s.geometry&&m.selectedResult.name===s.name,k={zIndex:"none"!==m.activeMenu?""+t--:""};return H("li",{"aria-label":b,afterCreate:this._handleStopFieldCreation,bind:this,class:this.classes(f.stopRow,l),id:T,key:i,"data-stop-index":i,styles:k},H("div",{class:f.stopHandle},H("span",{"aria-hidden":"true",class:this.classes(f.stopIcon,f.handleIcon,f.stopHandleIcon,f.interactiveStopIcon),onpointerdown:this._handleDragHandlePointerDown}),H("div",{bind:this,"aria-labelledby":T,class:this.classes(f.stopIconContainer,a),"data-stop-index":i,onclick:this._handleStopIconClick,onkeydown:this._handleStopIconClick,role:"button"},H("span",{class:this.classes(f.stopIcon,n),tabindex:C?"0":null}))),H("div",{class:f.stopInput},m.render()),H("div",{class:f.stopOptions,role:"group"},H("div",{"aria-label":g,class:f.removeStopButton,bind:this,"data-stop-index":i,hidden:v,onkeydown:this._handleRemoveStop,onclick:this._handleRemoveStop,role:"button",tabIndex:0,title:g},H("span",{"aria-hidden":"true",class:this.classes(f.stopIcon,f.removeStop,f.removeStopIcon,f.interactiveStopIcon)}),H("span",{class:f.screenReaderText},"removeStopTitle")),H("div",{"aria-label":S,class:f.reverseStops,bind:this,hidden:p,onkeydown:this._handleReverseStops,onclick:this._handleReverseStops,role:"button",tabIndex:0,title:S},H("span",{"aria-hidden":"true",class:this.classes(f.stopIcon,f.reverseStopIcon,f.interactiveStopIcon)}),H("span",{class:f.screenReaderText},"removeStopTitle"))))})),i=this._renderAddStop();return H("div",null,H("ol",{class:f.stops,role:"group",afterCreate:this._setUpDragAndDropStops},s),i)}_renderAddStop(){const e=this.viewModel.layer?.stops;if(!e)return null;const t=e.filter((({geometry:e})=>null!=e)),s=e.at(-1);return t.length>1&&t.length<this.maxStops&&null!=s&&null!=s.geometry?H("div",{class:f.toolbarSection},H("div",{class:f.toolbarButtons},H("calcite-button",{appearance:"outline",class:f.addStopButton,kind:"neutral",scale:"s",round:!0,iconStart:"plus",key:f.addStopButton,onclick:()=>{this._addNewPlaceholder()},label:this.messages.addStop,width:"full"},this.messages.addStop))):null}_handleStopIconClick(e){const t=G(e.currentTarget),s=null!=t?this.viewModel.layer?.stops.at(t):void 0;s?.geometry&&this._centerAtStop(s)}_handleClearRouteClick(){this.viewModel.reset()}_centerAtStop(e){this.viewModel.centerAt(e)}_handleStopFieldCreation(e){const t=this._newPlaceholderStop;if(!t)return;const s=G(e),i=null!=s?this.viewModel.layer?.stops.at(s):void 0;if(t===i){const e=this.acquireSearch(i);e.when((()=>{this.renderNow(),e.focus()}))}this._newPlaceholderStop=null}_handleStopInputBlur(e,t){if(this._saveLayer.opened)return;this.removeHandles($);if(!!e.selectedResult&&null!=t.geometry&&null!=e.selectedResult?.feature.geometry&&t.geometry===e.selectedResult?.feature.geometry)return void this._pointerDownUpHandle?.pause();const s=null==t.geometry&&null==e.selectedResult?.feature.geometry,i=null!=t.geometry&&null!=e.selectedResult?.feature.geometry&&t.geometry!==e.selectedResult?.feature.geometry;if((s||i)&&"none"===e.activeMenu&&e.searchTerm)return e.search(),void this._pointerDownUpHandle?.pause();e.searchTerm||(this._viewClickHandle?.resume(),clearTimeout(this._autoStopRemovalTimeoutId),this._autoStopRemovalTimeoutId=setTimeout((()=>{this.destroyed||(this._viewClickHandle?.pause(),"searching"!==e.viewModel.state?this._pointerPressedSearchSuggestionStop||(null!=t.geometry&&(t.geometry=null,this._getDirections()),this.scheduleRender()):this._pointerDownUpHandle?.pause())}),this._autoStopRemovalDelay))}_handleStopInputFocus(e,t){this._pointerDownUpHandle?.resume();const{view:s}=this;if(this.hasHandles($)||!s)return;const o=s.cursor;this.addHandles([i((()=>{s.cursor=o})),r((()=>e.searchTerm),(t=>{e.destroyed||(s.cursor=t.length?o:"copy")}),n)],$),this._activeStop=t}_prepViewClick(){const{view:e}=this.viewModel;o(e),o(e.surface);const t=s(e,"click",this._handleViewClick.bind(this)),i=s(e.surface,"click",(()=>{clearTimeout(this._autoStopRemovalTimeoutId),i.pause()}));return{remove(){i.remove(),t.remove()},pause(){i.pause(),t.pause()},resume(){i.resume(),t.resume()}}}_prepPointerDownUpClick(){const e=s(document,"pointerdown",(e=>{this._pointerPressedSearchSuggestionStop=z(e)?this._activeStop:null})),t=s(document,"pointerup",(e=>{this._pointerDownUpHandle?.pause();const t=z(e),s=this._activeStop;t||s!==this._pointerPressedSearchSuggestionStop||this._removeStop(s),this.scheduleRender(),this._pointerPressedSearchSuggestionStop=t?s:null}));return{remove(){t.remove(),e.remove()},pause(){t.pause(),e.pause()},resume(){e.resume()}}}_handleViewClick(e){e.stopPropagation();const t=this._activeStop,s=t?this._stopsToSearches.get(t):null;t&&s&&!s.searchTerm&&(s.search(e.mapPoint).then((e=>{const i=e?.results[0].results;if(!i)return;const{feature:o,name:r}=i[0];t.geometry=o.geometry,t.name=r,s.searchTerm=r})),this.scheduleRender()),this._viewClickHandle?.pause(),clearTimeout(this._autoStopRemovalTimeoutId)}_addNewPlaceholder(){if(this._pointerDownUpHandle?.pause(),this._newPlaceholderStop)return;const e=new p({symbol:new v});this.viewModel.layer?.stops.add(e),this._newPlaceholderStop=e}_handleReverseStops(){this._reverseStops()}_reverseStops(){const e=this.viewModel.layer?.stops??[];e.reverse();for(const t of e)t.sequence=null;this._getDirections()}_handleRemoveStop(e){const{layer:t}=this.viewModel;if(!t)return;const s=G(e.currentTarget);if(null==s)return;const{stops:i,routeInfo:o}=t,r=i.at(s);this._removeStop(r),null==r.geometry&&null!=o||this._getDirections()}_removeStop(e){const{stops:t}=this.viewModel.layer;!e||t.length<=2||(this._disposeSearch(e),t.remove(e))}_handleDepartureOptionChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);s.value===M.NOW?(this._departureTimeOption=M.NOW,this.viewModel.departureTime=M.NOW,this.removeHandles(F),this._getDirections()):s.value===M.DEPART_AT?(this._departureTimeOption=M.DEPART_AT,this.addHandles(r((()=>[this._datePicker.value,this._timePicker.value]),(()=>{this._updateDepartureTime(),this._getDirections()}),n),F)):(this._departureTimeOption=M.UNSPECIFIED,this.viewModel.departureTime=null,this._getDirections())}_updateDepartureTime(){const e=this._datePicker.value,t=this._timePicker.value;e&&t&&(this.viewModel.departureTime=new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()))}_renderTimeControls(){return H("div",{class:f.departureTimeControls,key:"esri-directions__time-controls",role:"group"},this._datePicker.render(),this._timePicker.render())}_renderSectionSplitter(){return H("div",{class:f.sectionSplitter})}_renderSaveContainer(){const{saveButton:e,saveAsButton:t,printButton:s,layerDetails:i}=this.visibleElements;return e||t||s||i?H("div",{class:f.saveSection,key:f.saveSection},this._renderSaveButtons(),this._renderRouteLayerDetailsLink()):null}_renderSaveButtons(){const{saveButton:e,saveAsButton:t,printButton:s}=this.visibleElements;return e||t||s?H("div",{class:f.saveButtons,key:f.saveButtons},this._renderSaveButton(),this._renderSaveAsButton(),this._renderPrintButton()):null}_renderSaveButton(){if(!this.visibleElements.saveButton)return null;const{portalItem:e,routeInfo:t}=this.viewModel.layer,s=e?.itemControl,i=null!=t&&("admin"===s||"update"===s);return H("calcite-button",{appearance:"outline",class:f.saveButton,disabled:!i,iconStart:"save",key:f.saveButton,onclick:()=>{this._handleSaveButtonClick()},label:this.messagesCommon.save,width:"full"},this.messagesCommon.save)}_renderSaveAsButton(){if(!this.visibleElements.saveAsButton)return null;const e=null==this.viewModel.layer.routeInfo;return H("div",{class:f.saveAsButtonPopover,key:f.saveAsButtonPopover},H("calcite-button",{afterCreate:e=>{this._saveAsButtonNode=e},appearance:"outline",class:f.saveAsButton,disabled:e,iconStart:"duplicate",key:f.saveAsButton,onclick:()=>this._handleSaveAsButtonClick(),label:this.messagesCommon.saveAs,width:"full"},this.messagesCommon.saveAs))}_renderSavePopover(){return H("calcite-popover",{label:this._saveLayer.label,open:this._saveLayer.opened,overlayPositioning:"fixed",referenceElement:this._saveAsButtonNode},this._saveLayer.render())}_handleSaveAsButtonClick(){this._saveLayer.opened?this._saveLayer.close():this._saveLayer.open(this.viewModel.layer)}_renderPrintButton(){return this.visibleElements.printButton?H("calcite-button",{appearance:"outline",class:f.printButton,iconStart:"print",key:f.printButton,label:this.messagesCommon.print}):null}_renderRouteLayerDetailsLink(){if(!this.visibleElements.layerDetails)return null;const{portalItem:e}=this.viewModel.layer;if(!e)return null;const{id:t,portal:{url:s}}=e,i=`${s}/home/item.html?id=${t}`;return H("calcite-link",{class:f.layerDetailsLink,href:i,key:f.layerDetailsLink,target:"_blank"},this.messages.viewLayerDetails)}_handleSaveButtonClick(){this.viewModel.layer.save()}_renderDirectionsContainer(){return H("div",{class:this.classes(f.directionsSection,f.section),key:"esri-directions__container"},this._renderDirectionsContainerContent())}_renderLoader(){return H("div",{class:f.loader,key:"loader"})}_renderWarningCard(){return H("div",{class:f.warningCard,role:"alert"},H("div",{class:f.warningHeader},H("span",{class:f.warningIcon,"aria-hidden":"true"}),H(I,{class:f.warningHeading,level:this.headingLevel},this.messagesCommon.warning)),H("div",{class:f.warningMessage},this._getErrorMessage()))}_renderDirectionsContainerContent(){const{layer:e,state:t}=this.viewModel,s="routing"===t;return"error"===t?this._renderWarningCard():s?this._renderLoader():null!=e.directionLines?H("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(f.summary,this._saveLayer.opened&&f.buttonDisabled),key:"esri-directions__summary",role:"group"},this._renderCosts(),this._renderRouteActions(),this._renderManeuverSections()):H("div",{key:"esri-directions__placeholder",class:f.emptyContent},this._renderPlaceholder(),H(I,{class:f.message,level:this.headingLevel},this.messages.directionsPlaceholder))}_renderPlaceholder(){return H("svg",{class:f.emptyIllustration,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256"},H("path",{fill:"currentcolor",d:"M192 36c-15.477 0-24 6.034-24 16.99v45.822l24 24 24-24v-45.82C216 42.033 207.477 36 192 36zm20 61.155l-20 20-20-20V52.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM192 52a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zM92 140.99C92 130.035 83.477 124 68 124s-24 6.034-24 16.99v45.822l24 24 24-24zm-4 44.165l-20 20-20-20V140.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM68 140a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zm84-44h16v4h-16zm-24 80h4v12h-12v-4h8zm0-28h4v16h-4zm0-52h12v4h-8v8h-4zm0 24h4v16h-4zm-36 64h16v4H92z"}))}_renderMessage(e){return H(I,{class:f.messageHeading,level:this.headingLevel},e)}_renderRouteActions(){return H("div",{class:f.routeActions},H("button",{"aria-label":this.messages.clearRoute,class:this.classes(f.clearRouteButton,f.button,f.buttonTertiary),tabIndex:0,onclick:this._handleClearRouteClick,bind:this,type:"button"},this.messages.clearRoute))}_getSections(){const{layer:e}=this.viewModel;if(!e)return null;const{directionPoints:t,directionLines:s,stops:i}=e;if(null==t||null==s)return null;const o=[];let r=null;for(const n of t){const{objectId:e,stopId:t}=n;if(null!=t){const e=i.find((({objectId:e})=>e===t)),s=0===o.length;null!=r&&r.stop===e||(r={stop:e,directions:[],open:s},o.push(r));continue}if(null==r)continue;const a=s.find((({directionPointId:t})=>t===e));null!=a&&r.directions.push({directionPoint:n,directionLine:a})}return o}_renderManeuverSections(){return null==this._sections?null:H("div",{class:f.maneuvers,role:"group"},this._sections.map(((e,t)=>{const{open:s}=e;let i;e.directions.length>0&&s&&(i=H("ol",{class:f.maneuverList},e.directions.map((e=>this._renderManeuver(e)))));const o=this._sections.length>2,r=t===this._sections.length-1,n={[f.collapsibleSection]:o},a={[f.openIcon]:!s,[f.closeIcon]:s};let l;if(o&&!r){const t=s?this.messagesCommon.close:this.messagesCommon.open;l=H("header",{class:this.classes(f.maneuverSectionHeader,f.maneuverSectionToggle),key:f.maneuverSectionHeader},H("div",{"aria-expanded":s.toString(),"aria-label":t,bind:this,class:f.maneuverSectionHeaderButton,"data-maneuver-section":e,onkeydown:this._handleSectionToggle,onclick:this._handleSectionToggle,role:"button",tabIndex:0,title:t},H(I,{class:f.maneuverSectionTitle,level:this.headingLevel},e.stop.name),H("span",{"aria-hidden":"true",class:this.classes(a)})))}else l=H("header",{class:f.maneuverSectionHeader,key:f.maneuverSectionHeader},H(I,{class:f.maneuverSectionTitle,level:this.headingLevel},e.stop.name));return H("section",{class:this.classes(f.maneuverSection,n),key:t},l,i)})))}_handleSectionToggle(e){const t=Y(e.currentTarget);t&&(t.open=!t.open)}_renderCosts(){const e=this._getCostSummary(),{directionPoints:t}=this.viewModel.layer;if(null==t||null==e)return null;const s=t.at(-1).arrivalTime,{distance:i,duration:o}=e,{eta:r,primaryCosts:n,secondaryCosts:a,zoomToRoute:l}=this.messages,c=x("short-time"),d=null!=s?`<strong>${E(s,c)}</strong> ${U(s)}`:"";return H("div",{"aria-label":l,bind:this,class:f.directionCosts,onkeydown:this._handleSummaryInteraction,onclick:this._handleSummaryInteraction,role:"button",tabIndex:0,title:l},H("div",{class:f.costsDetails,role:"group"},H("div",{class:f.primaryCosts,title:n},o),H("div",{class:f.verticalSplitter}),H("div",{class:f.secondaryCosts,title:a},i)),H("div",{innerHTML:d,title:r}))}_handleSummaryInteraction(){this._activeManeuver=null,this._focusedManeuver=null,this.viewModel.clearHighlights(),this.zoomToRoute()}_getErrorMessage(){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}}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){e.viewModel.defaultSources.forEach((e=>{e.autoNavigate=!1}))}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.locationType??="street",T(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=C))}_disposeSearch(e){if(!e||!this._stopsToSearches.has(e))return;const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}_renderManeuver(e){const{directionPoint:t,directionLine:s}=e,{distance:i,duration:o}=s,{messages:r,messagesUnits:n,unit:a}=this,l=y(n,i??0,a),c=w(o??0),d=l&&c?`${l}&nbsp;&middot;&nbsp;${c}`:`${l}${c}`,u=this._getFormattedManeuverText(t),{objectId:h,directionPointType:p}=t,v=b(p),m=`esri-directions__maneuver-${h}`,_=`esri-directions__intermediate-costs-${h}`,g={[f.maneuverActive]:this._activeManeuver===s};return H("li",{"aria-labelledby":`${m} ${_}`,bind:this,class:this.classes(f.maneuver,g),"data-maneuver":s,key:s,onclick:this._handleManeuverClick,onkeydown:this._handleManeuverClick,onfocus:this._handleManeuverFocus,onmouseover:this._handleManeuverMouseOver,onmouseout:this._handleManeuverMouseOut,onblur:this._handleManeuverBlur,tabIndex:0},null!=v&&H("img",{alt:"",class:f.maneuverIcon,src:v}),H("div",{class:f.maneuverCostsContainer},H("span",{id:m,innerHTML:u??""}),H("div",{class:f.maneuverCosts},H("div",{class:f.horizontalSplitter}),H("div",{"aria-hidden":"true",id:_,class:f.intermediateCost,innerHTML:d,title:r.intermediateCosts}))))}_handleManeuverClick(e){const t=J(e.currentTarget);if(!t)return;if(this._activeManeuver===t)return this._activeManeuver=null,void this.zoomToRoute();this._activeManeuver=t;const{geometry:s}=t;this.viewModel.centerAt(s),this.viewModel.highlight(t)}_handleManeuverMouseOver(e){if(this._activeManeuver||this._focusedManeuver)return;const t=J(e.currentTarget);t&&this.viewModel.highlight(t)}_handleManeuverMouseOut(){this._activeManeuver||this._focusedManeuver||this.viewModel.clearHighlights()}_handleManeuverBlur(){this._activeManeuver||(this._focusedManeuver=null,this.viewModel.clearHighlights())}_handleManeuverFocus(e){if(this._activeManeuver)return;const t=J(e.currentTarget);t&&(this._focusedManeuver=t,this.viewModel.highlight(t))}_getFormattedManeuverText(e){const{displayText:t,name:s,intersectingName:i}=e;if(null==t)return"";let o=t;return null!=s&&o.includes(s)&&(o=o.replace(s,`<strong>${s}</strong>`)),null!=i&&o.includes(i)&&(o=o.replace(i,`<strong>${i}</strong>`)),o}_getCostSummary(){const{messagesUnits:e,unit:t,viewModel:s}=this,{routeInfo:i}=s.layer;if(null==i)return null;const o=i.totalDistance??0,r=i.totalDuration??0;return{distance:y(e,o,t),duration:w(r)}}async _getDirections(){const e=this.viewModel.layer?.stops.filter((({geometry:e})=>null!=e));if(e&&!(e.length<2))try{await this.viewModel.getDirections()}catch{}}};e([c()],V.prototype,"apiKey",null),e([c(h)],V.prototype,"defaultUnit",void 0),e([c()],V.prototype,"goToOverride",null),e([c()],V.prototype,"headingLevel",void 0),e([c()],V.prototype,"iconClass",void 0),e([c()],V.prototype,"icon",void 0),e([c()],V.prototype,"label",null),e([c({readOnly:!0})],V.prototype,"lastRoute",null),e([c()],V.prototype,"layer",null),e([c()],V.prototype,"maxStops",null),e([c(),B("esri/widgets/Directions/t9n/Directions")],V.prototype,"messages",void 0),e([c(),B("esri/t9n/common")],V.prototype,"messagesCommon",void 0),e([c(),B("esri/core/t9n/Units")],V.prototype,"messagesUnits",void 0),e([c()],V.prototype,"searchProperties",void 0),e([c()],V.prototype,"unit",null),e([c()],V.prototype,"view",null),e([c({type:g})],V.prototype,"viewModel",void 0),e([c()],V.prototype,"visibleElements",void 0),e([d("visibleElements")],V.prototype,"castVisibleElements",null),e([L()],V.prototype,"_handleStopIconClick",null),e([L()],V.prototype,"_handleClearRouteClick",null),e([L()],V.prototype,"_handleReverseStops",null),e([L()],V.prototype,"_handleRemoveStop",null),e([L()],V.prototype,"_handleSectionToggle",null),e([L()],V.prototype,"_handleSummaryInteraction",null),e([L()],V.prototype,"_handleManeuverClick",null),V=e([u("esri.widgets.Directions")],V);const W=V;function q(e){return e?.["data-mode"]}function G(e){return e?.["data-stop-index"]}function Y(e){return e?.["data-maneuver-section"]}function J(e){return e?.["data-maneuver"]}export{W as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{on as t,pausable as s}from"../core/events.js";import{makeHandle as i}from"../core/handleUtils.js";import{assertIsSome as o}from"../core/maybe.js";import{watch as r,initial as n,when as a,on as l}from"../core/reactiveUtils.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import{cast as d}from"../core/accessorSupport/decorators/cast.js";import"../core/arrayUtils.js";import"../core/has.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import{defaultUnitPropertyMetadata as h}from"../properties/defaultUnit.js";import p from"../rest/support/Stop.js";import v from"../symbols/SimpleMarkerSymbol.js";import m from"./Search.js";import _ from"./Widget.js";import g from"./Directions/DirectionsViewModel.js";import{SaveLayer as S}from"./Directions/components/SaveLayer.js";import{formatDistance as y,formatDuration as w}from"./Directions/support/directionsUtils.js";import{DepartureTimeOption as M,CSS as f,getIconName as b}from"./Directions/support/resources.js";import{isArcGISWorldGeocoder as T,meteredArcGISLocatorUrl as C}from"./Search/support/locatorUtils.js";import{loadCalciteComponents as k}from"./support/componentsUtils.js";import D from"./support/DatePicker.js";import{Heading as I,incrementHeadingLevel as P}from"./support/Heading.js";import R from"./support/TimePicker.js";import{accessibleHandler as L}from"./support/decorators/accessibleHandler.js";import{messageBundle as B}from"./support/decorators/messageBundle.js";import{tsx as H}from"./support/jsxFactory.js";import"./support/widgetUtils.js";import E from"sortablejs";import{formatNumber as A}from"../intl/number.js";import{formatDate as j,convertDateFormatToIntlOptions as x}from"../intl/date.js";const O={departureTime:!0,layerDetails:!0,printButton:!1,saveAsButton:!0,saveButton:!0,stops:!0,traveMode:!0};function U(e){const t=e.getTimezoneOffset(),s=t>0?"-":"+",i=60,o=Math.abs(Math.floor(t/i)),r=Math.abs(Math.floor(t)%i),n={minimumIntegerDigits:2};return`GMT${s}${A(o,n)}${A(r,n)}`}function z(e){return!!e.composedPath?.().find((e=>e.classList?.contains("esri-search__suggestions-list")))}const $="search-term",F="date-time-picker",N=100,K=500;let V=class extends _{constructor(e,t){super(e,t),this._activeStop=null,this._activeManeuver=null,this._autoStopRemovalDelay=N,this._autoStopRemovalTimeoutId=void 0,this._departureTimeOption=M.NOW,this._datePicker=new D,this._focusedManeuver=null,this._newPlaceholderStop=null,this._pointerDownUpHandle=null,this._pointerPressedSearchSuggestionStop=null,this._renderSavePopoverFunction=null,this._saveAsButtonNode=null,this._saveLayer=new S,this._sections=null,this._sortable=null,this._stopsToSearches=new Map,this._timePicker=new R,this._viewClickHandle=null,this.headingLevel=2,this.iconClass=f.widgetIcon,this.icon=null,this.messages=null,this.messagesCommon=null,this.messagesUnits=null,this.searchProperties=null,this.viewModel=new g,this.visibleElements={...O},this._setUpDragAndDropStops=e=>{this._sortable=E.create(e,{draggable:`.${f.validStopRow}`,ghostClass:f.stopRowGhost,handle:`.${f.stopHandle}`,onEnd:this._handleStopInputDragEnd})},this._handleDragHandlePointerDown=()=>this.viewModel.layer?.stops.forEach((e=>this.acquireSearch(e).activeMenu="none")),this._handleStopInputDragEnd=({oldIndex:e,newIndex:t,target:s})=>{if(e===t||null==t||null==e)return;const{children:i}=s,o=i[t],r=i[e],n=t-e<0;s.insertBefore(o,n?r.nextElementSibling:r);const{stops:a}=this.viewModel.layer;a.reorder(a.at(e),t);for(const l of a)l.sequence=null;this._getDirections()}}initialize(){this.addHandles([r((()=>this.viewModel.layer?.routeInfo),(()=>{this._activeManeuver=null,this._focusedManeuver=null,this._sections=this._getSections(),this.scheduleRender()}),n),a((()=>this.view),((e,s)=>{if(s&&(this._viewClickHandle=null,null!=s&&this.removeHandles(s)),e){const s=this._prepPointerDownUpClick(),i=this._prepViewClick();s.pause(),i.pause();const o=e.surface;this.addHandles([t(o,"mousedown",(()=>this._autoStopRemovalDelay=K)),t(o,"mouseup",(()=>this._autoStopRemovalDelay=N)),s,i],e),this._pointerDownUpHandle=s,this._viewClickHandle=i}}),n),a((()=>null==this.viewModel.serviceDescription),(()=>{try{this.viewModel.load()}catch{}}),n),r((()=>this._saveLayer.state),(()=>{this.scheduleRender()}))]),this.when((()=>{this.destroyed||this.visibleElements.saveAsButton&&(this._renderSavePopoverFunction=this._renderSavePopover.bind(this),this._projector.append(document.body,this._renderSavePopoverFunction))}))}loadDependencies(){return k({button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),link:()=>import("@esri/calcite-components/dist/components/calcite-link.js"),popover:()=>import("@esri/calcite-components/dist/components/calcite-popover.js")})}destroy(){this._datePicker.destroy(),this._timePicker.destroy();for(const e of this._stopsToSearches.values())e.destroy();this._sortable?.destroy(),null!=this._renderSavePopoverFunction&&this._projector.detach(this._renderSavePopoverFunction)}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 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}castVisibleElements(e){return{...O,...e}}acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const s=this._stopsToSearches.get(e);return s.view=t,this._overrideDefaultSources(s),s}const s=new m({view:t,resultGraphicEnabled:!1,popupEnabled:!1,...this.searchProperties});return this._normalizeSearchSources(s),this.addHandles([l((()=>s.allSources),"change",(()=>this._normalizeSearchSources(s))),s.on("select-result",(()=>{e.geometry=s.selectedResult?.feature.geometry,e.name=s.selectedResult?.name,this._getDirections()})),s.on("search-focus",(()=>this._handleStopInputFocus(s,e))),s.on("search-blur",(()=>this._handleStopInputBlur(s,e))),s.on("search-clear",(()=>{e.geometry=null,e.name=null,this._activeStop=e,this.viewModel.layer?.removeResult()})),r((()=>s.searchTerm),(t=>{e.name=t}))],s),this._stopsToSearches.set(e,s),s}getDirections(){return this.viewModel.getDirections()}render(){return H("div",{class:this.classes(f.base,f.scroller)},this._renderPanelContent())}save(){return this.viewModel.save()}saveAs(e,t={}){return this.viewModel.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_renderPanelContent(){const{layer:e,serviceDescription:t,state:s}=this.viewModel,i="initializing"===s,o="error"===s&&!t,r="unauthenticated"===s,n={[f.panelContentLoading]:i,[f.panelContentError]:o||!e,[f.panelContentSignIn]:r},a=i?"presentation":"group",l=e?r?this._renderSignIn():o?this._renderMessage(this._getErrorMessage()):i?this._renderLoader():this._renderReadyContent():this._renderMessage(this.messages.missingLayer);return H("div",{class:this.classes(f.panelContent,n),role:a},l)}_renderReadyContent(){return[this._renderStopsContainer(),this._renderTravelModeOptions(),this._renderDepartureTimeControls(),this._renderSaveContainer(),this._renderSectionSplitter(),this._renderDirectionsContainer()]}_renderSignIn(){return H("div",{key:"sign-in",class:f.signInContent},H(I,{class:f.contentTitle,level:this.headingLevel},this.messages.widgetLabel),this._renderPlaceholder(),H(I,{level:P(this.headingLevel)},this.messages.signInRequired),H("button",{class:this.classes(f.button,f.buttonSecondary,f.signInButton),tabIndex:0,onclick:this._handleSignInClick,bind:this,type:"button"},this.messagesCommon.auth.signIn))}_handleSignInClick(){this.viewModel.load().catch((()=>{}))}_renderTravelModeOptions(){if(!this.visibleElements.traveMode)return null;const{selectedTravelMode:e,travelModes:t}=this.viewModel;if(0===t.length)return null;const s=null!=e?e.name:this.messages.travelMode;return H("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(f.travelMode,this._saveLayer.opened&&f.buttonDisabled),key:"esri-directions__travel-mode-controls",role:"group"},H("select",{"aria-label":s,bind:this,class:this.classes(f.travelModeSelect,f.select),key:"esri-directions__travel-mode-options",onchange:this._handleTravelModeChange,title:s},t.map(((t,s)=>H("option",{key:`esri-directions__travel-mode-${s}`,"data-mode":t,selected:e===t,value:`${s}`},t.name)))))}_handleTravelModeChange(e){const t=e.currentTarget;this.viewModel.selectedTravelMode=q(t.item(t.selectedIndex)),this._getDirections()}_renderStopsContainer(){return this.visibleElements.stops?H("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(f.section,this._saveLayer.opened&&f.buttonDisabled),key:"esri-directions__stops-container",role:"group"},this._renderStops()):null}_renderDepartureTimeControls(){if(!this.visibleElements.departureTime)return null;const{messages:{departAt:e,departureTime:t,leaveNow:s,timeUnspecified:i}}=this;return H("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(f.departureTime,this._saveLayer.opened&&f.buttonDisabled),key:"esri-directions__departure-time-controls",role:"group"},H("select",{"aria-label":t,bind:this,class:this.classes(f.departureTimeSelect,f.select),onchange:this._handleDepartureOptionChange,title:t},H("option",{value:M.NOW,selected:this._departureTimeOption===M.NOW},s),H("option",{value:M.DEPART_AT,selected:this._departureTimeOption===M.DEPART_AT},e),H("option",{value:M.UNSPECIFIED,selected:this._departureTimeOption===M.UNSPECIFIED},i)),this._departureTimeOption===M.DEPART_AT?this._renderTimeControls():null)}_renderStops(){const{stops:e}=this.viewModel.layer;let t=0;for(const o of this._stopsToSearches.keys())e.includes(o)||this._disposeSearch(o);for(const o of e){const e=this.acquireSearch(o);"none"!==e.activeMenu&&(t+=1),null!=o.name&&(e.searchTerm=o.name)}const s=e.toArray().map(((s,i)=>{const o=e.length,r=i>1&&null==s.geometry,n={[f.stopsIcon]:i>=0&&i<o-1,[f.lastStopIcon]:i===o-1},a={[f.lastStopIconContainer]:i===o-1},l={[f.validStopRow]:!r},c=e.at(i+1),d=c&&null!=c.geometry,u=i===o-1,h=i===o-2,p=2===o&&0===i||o>2&&!u&&!h||o>2&&h&&d||o>2&&u&&null==s.geometry,v=o<3,m=this.acquireSearch(s),{messages:_}=this,{removeStop:g,reverseStops:S,unlocated:y}=_,w=null!=s.geometry&&null!=s.name?s.name:y,M=A(i+1),b=`${_.stopLabel} ${M} (${w})`,T=`${this.id}__stop--${i}`,C=!!m.searchTerm&&!!m.selectedResult&&null!=s.geometry&&m.selectedResult.name===s.name,k={zIndex:"none"!==m.activeMenu?""+t--:""};return H("li",{"aria-label":b,afterCreate:this._handleStopFieldCreation,bind:this,class:this.classes(f.stopRow,l),id:T,key:i,"data-stop-index":i,styles:k},H("div",{class:f.stopHandle},H("span",{"aria-hidden":"true",class:this.classes(f.stopIcon,f.handleIcon,f.stopHandleIcon,f.interactiveStopIcon),onpointerdown:this._handleDragHandlePointerDown}),H("div",{bind:this,"aria-labelledby":T,class:this.classes(f.stopIconContainer,a),"data-stop-index":i,onclick:this._handleStopIconClick,onkeydown:this._handleStopIconClick,role:"button"},H("span",{class:this.classes(f.stopIcon,n),tabindex:C?"0":null}))),H("div",{class:f.stopInput},m.render()),H("div",{class:f.stopOptions,role:"group"},H("div",{"aria-label":g,class:f.removeStopButton,bind:this,"data-stop-index":i,hidden:v,onkeydown:this._handleRemoveStop,onclick:this._handleRemoveStop,role:"button",tabIndex:0,title:g},H("span",{"aria-hidden":"true",class:this.classes(f.stopIcon,f.removeStop,f.removeStopIcon,f.interactiveStopIcon)}),H("span",{class:f.screenReaderText},"removeStopTitle")),H("div",{"aria-label":S,class:f.reverseStops,bind:this,hidden:p,onkeydown:this._handleReverseStops,onclick:this._handleReverseStops,role:"button",tabIndex:0,title:S},H("span",{"aria-hidden":"true",class:this.classes(f.stopIcon,f.reverseStopIcon,f.interactiveStopIcon)}),H("span",{class:f.screenReaderText},"removeStopTitle"))))})),i=this._renderAddStop();return H("div",null,H("ol",{class:f.stops,role:"group",afterCreate:this._setUpDragAndDropStops},s),i)}_renderAddStop(){const e=this.viewModel.layer?.stops;if(!e)return null;const t=e.filter((({geometry:e})=>null!=e)),s=e.at(-1);return t.length>1&&t.length<this.maxStops&&null!=s&&null!=s.geometry?H("div",{class:f.toolbarSection},H("div",{class:f.toolbarButtons},H("calcite-button",{appearance:"outline",class:f.addStopButton,kind:"neutral",scale:"s",round:!0,iconStart:"plus",key:f.addStopButton,onclick:()=>{this._addNewPlaceholder()},label:this.messages.addStop,width:"full"},this.messages.addStop))):null}_handleStopIconClick(e){const t=G(e.currentTarget),s=null!=t?this.viewModel.layer?.stops.at(t):void 0;s?.geometry&&this._centerAtStop(s)}_handleClearRouteClick(){this.viewModel.reset()}_centerAtStop(e){this.viewModel.centerAt(e)}_handleStopFieldCreation(e){const t=this._newPlaceholderStop;if(!t)return;const s=G(e),i=null!=s?this.viewModel.layer?.stops.at(s):void 0;if(t===i){const e=this.acquireSearch(i);e.when((()=>{this.renderNow(),e.focus()}))}this._newPlaceholderStop=null}_handleStopInputBlur(e,t){if(this._saveLayer.opened)return;this.removeHandles($);if(!!e.selectedResult&&null!=t.geometry&&null!=e.selectedResult?.feature.geometry&&t.geometry===e.selectedResult?.feature.geometry)return void this._pointerDownUpHandle?.pause();const s=null==t.geometry&&null==e.selectedResult?.feature.geometry,i=null!=t.geometry&&null!=e.selectedResult?.feature.geometry&&t.geometry!==e.selectedResult?.feature.geometry;if((s||i)&&"none"===e.activeMenu&&e.searchTerm)return e.search(),void this._pointerDownUpHandle?.pause();e.searchTerm||(this._viewClickHandle?.resume(),clearTimeout(this._autoStopRemovalTimeoutId),this._autoStopRemovalTimeoutId=setTimeout((()=>{this.destroyed||(this._viewClickHandle?.pause(),"searching"!==e.viewModel.state?this._pointerPressedSearchSuggestionStop||(null!=t.geometry&&(t.geometry=null,this._getDirections()),this.scheduleRender()):this._pointerDownUpHandle?.pause())}),this._autoStopRemovalDelay))}_handleStopInputFocus(e,t){this._pointerDownUpHandle?.resume();const{view:s}=this;if(this.hasHandles($)||!s)return;const o=s.cursor;this.addHandles([i((()=>{s.cursor=o})),r((()=>e.searchTerm),(t=>{e.destroyed||(s.cursor=t.length?o:"copy")}),n)],$),this._activeStop=t}_prepViewClick(){const{view:e}=this.viewModel;o(e),o(e.surface);const t=s(e,"click",this._handleViewClick.bind(this)),i=s(e.surface,"click",(()=>{clearTimeout(this._autoStopRemovalTimeoutId),i.pause()}));return{remove(){i.remove(),t.remove()},pause(){i.pause(),t.pause()},resume(){i.resume(),t.resume()}}}_prepPointerDownUpClick(){const e=s(document,"pointerdown",(e=>{this._pointerPressedSearchSuggestionStop=z(e)?this._activeStop:null})),t=s(document,"pointerup",(e=>{this._pointerDownUpHandle?.pause();const t=z(e),s=this._activeStop;t||s!==this._pointerPressedSearchSuggestionStop||this._removeStop(s),this.scheduleRender(),this._pointerPressedSearchSuggestionStop=t?s:null}));return{remove(){t.remove(),e.remove()},pause(){t.pause(),e.pause()},resume(){e.resume()}}}_handleViewClick(e){e.stopPropagation();const t=this._activeStop,s=t?this._stopsToSearches.get(t):null;t&&s&&!s.searchTerm&&(s.search(e.mapPoint).then((e=>{const i=e?.results[0].results;if(!i)return;const{feature:o,name:r}=i[0];t.geometry=o.geometry,t.name=r,s.searchTerm=r})),this.scheduleRender()),this._viewClickHandle?.pause(),clearTimeout(this._autoStopRemovalTimeoutId)}_addNewPlaceholder(){if(this._pointerDownUpHandle?.pause(),this._newPlaceholderStop)return;const e=new p({symbol:new v});this.viewModel.layer?.stops.add(e),this._newPlaceholderStop=e}_handleReverseStops(){this._reverseStops()}_reverseStops(){const e=this.viewModel.layer?.stops??[];e.reverse();for(const t of e)t.sequence=null;this._getDirections()}_handleRemoveStop(e){const{layer:t}=this.viewModel;if(!t)return;const s=G(e.currentTarget);if(null==s)return;const{stops:i,routeInfo:o}=t,r=i.at(s);this._removeStop(r),null==r.geometry&&null!=o||this._getDirections()}_removeStop(e){const{stops:t}=this.viewModel.layer;!e||t.length<=2||(this._disposeSearch(e),t.remove(e))}_handleDepartureOptionChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);s.value===M.NOW?(this._departureTimeOption=M.NOW,this.viewModel.departureTime=M.NOW,this.removeHandles(F),this._getDirections()):s.value===M.DEPART_AT?(this._departureTimeOption=M.DEPART_AT,this.addHandles(r((()=>[this._datePicker.value,this._timePicker.value]),(()=>{this._updateDepartureTime(),this._getDirections()}),n),F)):(this._departureTimeOption=M.UNSPECIFIED,this.viewModel.departureTime=null,this._getDirections())}_updateDepartureTime(){const e=this._datePicker.value,t=this._timePicker.value;e&&t&&(this.viewModel.departureTime=new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()))}_renderTimeControls(){return H("div",{class:f.departureTimeControls,key:"esri-directions__time-controls",role:"group"},this._datePicker.render(),this._timePicker.render())}_renderSectionSplitter(){return H("div",{class:f.sectionSplitter})}_renderSaveContainer(){const{saveButton:e,saveAsButton:t,printButton:s,layerDetails:i}=this.visibleElements;return e||t||s||i?H("div",{class:f.saveSection,key:f.saveSection},this._renderSaveButtons(),this._renderRouteLayerDetailsLink()):null}_renderSaveButtons(){const{saveButton:e,saveAsButton:t,printButton:s}=this.visibleElements;return e||t||s?H("div",{class:f.saveButtons,key:f.saveButtons},this._renderSaveButton(),this._renderSaveAsButton(),this._renderPrintButton()):null}_renderSaveButton(){if(!this.visibleElements.saveButton)return null;const{portalItem:e,routeInfo:t}=this.viewModel.layer,s=e?.itemControl,i=null!=t&&("admin"===s||"update"===s);return H("calcite-button",{appearance:"outline",class:f.saveButton,disabled:!i,iconStart:"save",key:f.saveButton,onclick:()=>{this._handleSaveButtonClick()},label:this.messagesCommon.save,width:"full"},this.messagesCommon.save)}_renderSaveAsButton(){if(!this.visibleElements.saveAsButton)return null;const e=null==this.viewModel.layer.routeInfo;return H("div",{class:f.saveAsButtonPopover,key:f.saveAsButtonPopover},H("calcite-button",{afterCreate:e=>{this._saveAsButtonNode=e},appearance:"outline",class:f.saveAsButton,disabled:e,iconStart:"duplicate",key:f.saveAsButton,onclick:()=>this._handleSaveAsButtonClick(),label:this.messagesCommon.saveAs,width:"full"},this.messagesCommon.saveAs))}_renderSavePopover(){return H("calcite-popover",{label:this._saveLayer.label,open:this._saveLayer.opened,overlayPositioning:"fixed",referenceElement:this._saveAsButtonNode},this._saveLayer.render())}_handleSaveAsButtonClick(){this._saveLayer.opened?this._saveLayer.close():this._saveLayer.open(this.viewModel.layer)}_renderPrintButton(){return this.visibleElements.printButton?H("calcite-button",{appearance:"outline",class:f.printButton,iconStart:"print",key:f.printButton,label:this.messagesCommon.print}):null}_renderRouteLayerDetailsLink(){if(!this.visibleElements.layerDetails)return null;const{portalItem:e}=this.viewModel.layer;if(!e)return null;const{id:t,portal:{url:s}}=e,i=`${s}/home/item.html?id=${t}`;return H("calcite-link",{class:f.layerDetailsLink,href:i,key:f.layerDetailsLink,target:"_blank"},this.messages.viewLayerDetails)}_handleSaveButtonClick(){this.viewModel.layer.save()}_renderDirectionsContainer(){return H("div",{class:this.classes(f.directionsSection,f.section),key:"esri-directions__container"},this._renderDirectionsContainerContent())}_renderLoader(){return H("div",{class:f.loader,key:"loader"})}_renderWarningCard(){return H("div",{class:f.warningCard,role:"alert"},H("div",{class:f.warningHeader},H("span",{class:f.warningIcon,"aria-hidden":"true"}),H(I,{class:f.warningHeading,level:this.headingLevel},this.messagesCommon.warning)),H("div",{class:f.warningMessage},this._getErrorMessage()))}_renderDirectionsContainerContent(){const{layer:e,state:t}=this.viewModel,s="routing"===t;return"error"===t?this._renderWarningCard():s?this._renderLoader():null!=e.directionLines?H("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(f.summary,this._saveLayer.opened&&f.buttonDisabled),key:"esri-directions__summary",role:"group"},this._renderCosts(),this._renderRouteActions(),this._renderManeuverSections()):H("div",{key:"esri-directions__placeholder",class:f.emptyContent},this._renderPlaceholder(),H(I,{class:f.message,level:this.headingLevel},this.messages.directionsPlaceholder))}_renderPlaceholder(){return H("svg",{class:f.emptyIllustration,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256"},H("path",{fill:"currentcolor",d:"M192 36c-15.477 0-24 6.034-24 16.99v45.822l24 24 24-24v-45.82C216 42.033 207.477 36 192 36zm20 61.155l-20 20-20-20V52.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM192 52a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zM92 140.99C92 130.035 83.477 124 68 124s-24 6.034-24 16.99v45.822l24 24 24-24zm-4 44.165l-20 20-20-20V140.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM68 140a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zm84-44h16v4h-16zm-24 80h4v12h-12v-4h8zm0-28h4v16h-4zm0-52h12v4h-8v8h-4zm0 24h4v16h-4zm-36 64h16v4H92z"}))}_renderMessage(e){return H(I,{class:f.messageHeading,level:this.headingLevel},e)}_renderRouteActions(){return H("div",{class:f.routeActions},H("button",{"aria-label":this.messages.clearRoute,class:this.classes(f.clearRouteButton,f.button,f.buttonTertiary),tabIndex:0,onclick:this._handleClearRouteClick,bind:this,type:"button"},this.messages.clearRoute))}_getSections(){const{layer:e}=this.viewModel;if(!e)return null;const{directionPoints:t,directionLines:s,stops:i}=e;if(null==t||null==s)return null;const o=[];let r=null;for(const n of t){const{objectId:e,stopId:t}=n;if(null!=t){const e=i.find((({objectId:e})=>e===t)),s=0===o.length;null!=r&&r.stop===e||(r={stop:e,directions:[],open:s},o.push(r));continue}if(null==r)continue;const a=s.find((({directionPointId:t})=>t===e));null!=a&&r.directions.push({directionPoint:n,directionLine:a})}return o}_renderManeuverSections(){return null==this._sections?null:H("div",{class:f.maneuvers,role:"group"},this._sections.map(((e,t)=>{const{open:s}=e;let i;e.directions.length>0&&s&&(i=H("ol",{class:f.maneuverList},e.directions.map((e=>this._renderManeuver(e)))));const o=this._sections.length>2,r=t===this._sections.length-1,n={[f.collapsibleSection]:o},a={[f.openIcon]:!s,[f.closeIcon]:s};let l;if(o&&!r){const t=s?this.messagesCommon.close:this.messagesCommon.open;l=H("header",{class:this.classes(f.maneuverSectionHeader,f.maneuverSectionToggle),key:f.maneuverSectionHeader},H("div",{"aria-expanded":s.toString(),"aria-label":t,bind:this,class:f.maneuverSectionHeaderButton,"data-maneuver-section":e,onkeydown:this._handleSectionToggle,onclick:this._handleSectionToggle,role:"button",tabIndex:0,title:t},H(I,{class:f.maneuverSectionTitle,level:this.headingLevel},e.stop.name),H("span",{"aria-hidden":"true",class:this.classes(a)})))}else l=H("header",{class:f.maneuverSectionHeader,key:f.maneuverSectionHeader},H(I,{class:f.maneuverSectionTitle,level:this.headingLevel},e.stop.name));return H("section",{class:this.classes(f.maneuverSection,n),key:t},l,i)})))}_handleSectionToggle(e){const t=Y(e.currentTarget);t&&(t.open=!t.open)}_renderCosts(){const e=this._getCostSummary(),{directionPoints:t}=this.viewModel.layer;if(null==t||null==e)return null;const{distance:s,duration:i}=e,{primaryCosts:o,secondaryCosts:r,zoomToRoute:n}=this.messages,a=this._renderEta();return H("div",{"aria-label":n,bind:this,class:f.directionCosts,onkeydown:this._handleSummaryInteraction,onclick:this._handleSummaryInteraction,role:"button",tabIndex:0,title:n},H("div",{class:f.costsDetails,role:"group"},H("div",{class:f.primaryCosts,title:o},i),H("div",{class:f.verticalSplitter}),H("div",{class:f.secondaryCosts,title:r},s)),a)}_renderEta(){const{directionPoints:e}=this.viewModel.layer,{eta:t}=this.messages;if(null==e)return null;const s=e.at(-1).arrivalTime,i=x("short-time");return s&&this._departureTimeOption!==M.UNSPECIFIED?H("div",{class:f.arrivalTimeContainer,title:t},H("span",{class:f.arrivalTime},j(s,i))," ",U(s)):null}_handleSummaryInteraction(){this._activeManeuver=null,this._focusedManeuver=null,this.viewModel.clearHighlights(),this.zoomToRoute()}_getErrorMessage(){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}}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){e.viewModel.defaultSources.forEach((e=>{e.autoNavigate=!1}))}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.locationType??="street",T(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=C))}_disposeSearch(e){if(!e||!this._stopsToSearches.has(e))return;const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}_renderManeuver(e){const{directionPoint:t,directionLine:s}=e,{distance:i,duration:o}=s,{messages:r,messagesUnits:n,unit:a}=this,l=y(n,i??0,a),c=w(o??0),d=l&&c?`${l}&nbsp;&middot;&nbsp;${c}`:`${l}${c}`,u=this._getFormattedManeuverText(t),{objectId:h,directionPointType:p}=t,v=b(p),m=`esri-directions__maneuver-${h}`,_=`esri-directions__intermediate-costs-${h}`,g={[f.maneuverActive]:this._activeManeuver===s};return H("li",{"aria-labelledby":`${m} ${_}`,bind:this,class:this.classes(f.maneuver,g),"data-maneuver":s,key:s,onclick:this._handleManeuverClick,onkeydown:this._handleManeuverClick,onfocus:this._handleManeuverFocus,onmouseover:this._handleManeuverMouseOver,onmouseout:this._handleManeuverMouseOut,onblur:this._handleManeuverBlur,tabIndex:0},v&&H("calcite-icon",{alt:"",class:f.maneuverIcon,icon:v}),H("div",{class:f.maneuverCostsContainer},H("span",{id:m,innerHTML:u??""}),H("div",{class:f.maneuverCosts},H("div",{class:f.horizontalSplitter}),H("div",{"aria-hidden":"true",id:_,class:f.intermediateCost,innerHTML:d,title:r.intermediateCosts}))))}_handleManeuverClick(e){const t=J(e.currentTarget);if(!t)return;if(this._activeManeuver===t)return this._activeManeuver=null,void this.zoomToRoute();this._activeManeuver=t;const{geometry:s}=t;this.viewModel.centerAt(s),this.viewModel.highlight(t)}_handleManeuverMouseOver(e){if(this._activeManeuver||this._focusedManeuver)return;const t=J(e.currentTarget);t&&this.viewModel.highlight(t)}_handleManeuverMouseOut(){this._activeManeuver||this._focusedManeuver||this.viewModel.clearHighlights()}_handleManeuverBlur(){this._activeManeuver||(this._focusedManeuver=null,this.viewModel.clearHighlights())}_handleManeuverFocus(e){if(this._activeManeuver)return;const t=J(e.currentTarget);t&&(this._focusedManeuver=t,this.viewModel.highlight(t))}_getFormattedManeuverText(e){const{displayText:t,name:s,intersectingName:i}=e;if(null==t)return"";let o=t;return null!=s&&o.includes(s)&&(o=o.replace(s,`<strong>${s}</strong>`)),null!=i&&o.includes(i)&&(o=o.replace(i,`<strong>${i}</strong>`)),o}_getCostSummary(){const{messagesUnits:e,unit:t,viewModel:s}=this,{routeInfo:i}=s.layer;if(null==i)return null;const o=i.totalDistance??0,r=i.totalDuration??0;return{distance:y(e,o,t),duration:w(r)}}async _getDirections(){const e=this.viewModel.layer?.stops.filter((({geometry:e})=>null!=e));if(e&&!(e.length<2))try{await this.viewModel.getDirections()}catch{}}};e([c()],V.prototype,"apiKey",null),e([c(h)],V.prototype,"defaultUnit",void 0),e([c()],V.prototype,"goToOverride",null),e([c()],V.prototype,"headingLevel",void 0),e([c()],V.prototype,"iconClass",void 0),e([c()],V.prototype,"icon",void 0),e([c()],V.prototype,"label",null),e([c({readOnly:!0})],V.prototype,"lastRoute",null),e([c()],V.prototype,"layer",null),e([c()],V.prototype,"maxStops",null),e([c(),B("esri/widgets/Directions/t9n/Directions")],V.prototype,"messages",void 0),e([c(),B("esri/t9n/common")],V.prototype,"messagesCommon",void 0),e([c(),B("esri/core/t9n/Units")],V.prototype,"messagesUnits",void 0),e([c()],V.prototype,"searchProperties",void 0),e([c()],V.prototype,"unit",null),e([c()],V.prototype,"view",null),e([c({type:g})],V.prototype,"viewModel",void 0),e([c()],V.prototype,"visibleElements",void 0),e([d("visibleElements")],V.prototype,"castVisibleElements",null),e([L()],V.prototype,"_handleStopIconClick",null),e([L()],V.prototype,"_handleClearRouteClick",null),e([L()],V.prototype,"_handleReverseStops",null),e([L()],V.prototype,"_handleRemoveStop",null),e([L()],V.prototype,"_handleSectionToggle",null),e([L()],V.prototype,"_handleSummaryInteraction",null),e([L()],V.prototype,"_handleManeuverClick",null),V=e([u("esri.widgets.Directions")],V);const W=V;function q(e){return e?.["data-mode"]}function G(e){return e?.["data-stop-index"]}function Y(e){return e?.["data-maneuver-section"]}function J(e){return e?.["data-maneuver"]}export{W 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.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Error.js";import{abortHandle as a}from"../../core/handleUtils.js";import{isAborted as r}from"../../core/promiseUtils.js";import{watch as i}from"../../core/reactiveUtils.js";import{property as s}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as o}from"../../core/accessorSupport/decorators/subclass.js";import{getEffectiveLayerCapabilities as l,getEffectiveEditingEnabled as d}from"../../layers/support/layerUtils.js";import{sceneLayerEditingEnabled as n,i3sPatchingEnabled as c}from"../../support/featureFlags.js";import u from"./UpdateRecordWorkflowData.js";import p from"./Workflow.js";import{fetchFullFeature as m}from"./workflowUtils.js";var h;const f={exit:Symbol()},g="esri.widgets.Editor.UpdateRecordWorkflow";let w=h=class extends p{constructor(e){super(e),this.fullFeature=null,this.type="update-table-record"}async initialize(){const{data:e}=this,{edits:i}=e,s=i.feature,o=new AbortController;this.addHandles(a(o)),this._updatingHandles.addPromise(m(s,e.viewModel.view.spatialReference,o.signal).then((e=>{r(o)||this._onFullFeatureLoaded(e)}),(e=>this.cancel({force:!0,error:new t("editor:failed-to-fetch-full-feature","Failed to retrieve all information for this feature. The update cannot proceed.",{detail:{error:e}})}))))}get editableItem(){return this.data.editableItem}get hasPendingEdits(){return this.data.edits.modified}get shouldShowAttachments(){return this.editableItem.attachmentsOnUpdateEnabled}get shouldAllowAttachmentEditing(){return this.editableItem.supports.includes("update")}get reliesOnOwnerAdminPrivileges(){const{layer:e}=this.editableItem,t=e.capabilities?.operations.supportsUpdate,a=l(e)?.operations.supportsUpdate;return d(e)&&!e.editingEnabled||!!a&&!t}async deleteAndCommit(){return this.data.edits.stageDelete(),this.commit()}async enter(){this._configureAttachmentsViewModel(),this._configureFeatureFormViewModel()}exit(e){this.removeHandles(f.exit)}_configureAttachmentsViewModel(){const{data:e,fullFeature:t}=this,{attachmentsCapabilities:a,viewModel:r}=e,{attachmentsViewModel:s}=r;s.set({capabilities:a,graphic:t,filesEnabled:!1,mode:"view"}),this.addHandles(i((()=>s.mode),(e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}})),f.exit)}_configureFeatureFormViewModel(){const{edits:e,formTemplate:t,viewModel:{featureFormViewModel:a,view:r}}=this.data;a.set({arcadeEditType:"UPDATE",feature:this.fullFeature,formTemplate:t,map:r?.map,spatialReference:r.spatialReference});const{initialFeature:i}=e;i&&a.overrideInitialFeature(i),this.addHandles(a.on("value-change",(()=>{e.updateAttributes(a.getValues()),this.fullFeature.attributes=e.feature.attributes})),f.exit)}_onFullFeatureLoaded(e){this.fullFeature=e;const{edits:t}=this.data;t.updateAttributes(e.attributes),t.trackChanges()}static async create(e){const t=new h({data:await u.create(e),onCommit:this._onCommitFactory(e.applyEdits)});return t._set("steps",this._createWorkflowSteps(t)),t}static _createWorkflowSteps(e){const{attachmentsViewModel:t}=e.data.viewModel;return[{id:"editing-attributes",async setUp(){},async tearDown(){}},{id:"adding-attachment",async setUp(){},async tearDown(){t.mode="view"}},{id:"editing-attachment",async setUp(){},async tearDown(){t.mode="view"}}]}};w._onCommitFactory=e=>async t=>{const{edits:a}=t,{feature:r}=a;if(!r)return;const i=r.sourceLayer,s=r.clone();if(!a.attributesModified||a.stagedForDelete){const e=i.objectIdField;if(s.attributes={[e]:r.getAttribute(e)},n()&&c()&&"scene"===i.type&&null!=i.infoFor3D){const e=i.associatedLayer?.globalIdField;null!=e&&s.setAttribute(e,r.getAttribute(e))}}a.geometryModified&&!a.stagedForDelete||(s.geometry=null);const o=a.stagedForDelete?"deleteFeatures":"updateFeatures";await e(i,{[o]:[s]})},e([s()],w.prototype,"editableItem",null),e([s()],w.prototype,"fullFeature",void 0),e([s()],w.prototype,"hasPendingEdits",null),e([s()],w.prototype,"shouldShowAttachments",null),e([s()],w.prototype,"shouldAllowAttachmentEditing",null),e([s()],w.prototype,"reliesOnOwnerAdminPrivileges",null),w=h=e([o(g)],w);export{f as HANDLE_KEYS,w as UpdateRecordWorkflow};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Error.js";import{abortHandle as r}from"../../core/handleUtils.js";import{isAborted as i}from"../../core/promiseUtils.js";import{watch as a}from"../../core/reactiveUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import{getEffectiveLayerCapabilities as n,getEffectiveEditingEnabled as l}from"../../layers/support/layerUtils.js";import{sceneLayerEditingEnabled as d,i3sPatchingEnabled as c}from"../../support/featureFlags.js";import u from"./UpdateRecordWorkflowData.js";import p from"./Workflow.js";import{fetchFullFeature as m}from"./workflowUtils.js";var h;const f={exit:Symbol()},g="esri.widgets.Editor.UpdateRecordWorkflow";let w=h=class extends p{constructor(e){super(e),this.fullFeature=null,this.type="update-table-record"}async initialize(){const{data:e}=this,{edits:a}=e,o=a.feature,s=new AbortController;this.addHandles(r(s)),this._updatingHandles.addPromise(m(o,e.viewModel.view.spatialReference,s.signal).then((e=>{i(s)||this._onFullFeatureLoaded(e)}),(e=>this.cancel({force:!0,error:new t("editor:failed-to-fetch-full-feature","Failed to retrieve all information for this feature. The update cannot proceed.",{detail:{error:e}})}))))}get editableItem(){return this.data.editableItem}get hasPendingEdits(){const{edits:e,viewModel:t}=this.data,{geometryModified:r,initialFeature:i,modified:a}=e;if(r)return!0;if(!a||!i)return!1;const{allFieldInputs:o}=t.featureFormViewModel;return o.some((e=>y(e,i)))}get shouldShowAttachments(){return this.editableItem.attachmentsOnUpdateEnabled}get shouldAllowAttachmentEditing(){return this.editableItem.supports.includes("update")}get reliesOnOwnerAdminPrivileges(){const{layer:e}=this.editableItem,t=e.capabilities?.operations.supportsUpdate,r=n(e)?.operations.supportsUpdate;return l(e)&&!e.editingEnabled||!!r&&!t}async deleteAndCommit(){return this.data.edits.stageDelete(),this.commit()}async enter(){this._configureAttachmentsViewModel(),this._configureFeatureFormViewModel()}exit(e){this.removeHandles(f.exit)}_configureAttachmentsViewModel(){const{data:e,fullFeature:t}=this,{attachmentsCapabilities:r,viewModel:i}=e,{attachmentsViewModel:o}=i;o.set({capabilities:r,graphic:t,filesEnabled:!1,mode:"view"}),this.addHandles(a((()=>o.mode),(e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}})),f.exit)}_configureFeatureFormViewModel(){const{edits:e,formTemplate:t,viewModel:{featureFormViewModel:r,view:i}}=this.data;r.set({arcadeEditType:"UPDATE",feature:this.fullFeature,formTemplate:t,map:i?.map,spatialReference:i.spatialReference});const{initialFeature:a}=e;a&&r.overrideInitialFeature(a),this.addHandles(r.on("value-change",(()=>{e.updateAttributes(r.getValues()),this.fullFeature.attributes=e.feature.attributes})),f.exit)}_onFullFeatureLoaded(e){this.fullFeature=e;const{edits:t}=this.data;t.updateAttributes(e.attributes),t.trackChanges()}static async create(e){const t=new h({data:await u.create(e),onCommit:this._onCommitFactory(e.applyEdits)});return t._set("steps",this._createWorkflowSteps(t)),t}static _createWorkflowSteps(e){const{attachmentsViewModel:t}=e.data.viewModel;return[{id:"editing-attributes",async setUp(){},async tearDown(){}},{id:"adding-attachment",async setUp(){},async tearDown(){t.mode="view"}},{id:"editing-attachment",async setUp(){},async tearDown(){t.mode="view"}}]}};function y(e,t){return e.value!==t.getAttribute(e.name)&&!e.valueOriginIsExpression}w._onCommitFactory=e=>async t=>{const{edits:r}=t,{feature:i}=r;if(!i)return;const a=i.sourceLayer,o=i.clone();if(!r.attributesModified||r.stagedForDelete){const e=a.objectIdField;if(o.attributes={[e]:i.getAttribute(e)},d()&&c()&&"scene"===a.type&&null!=a.infoFor3D){const e=a.associatedLayer?.globalIdField;null!=e&&o.setAttribute(e,i.getAttribute(e))}}r.geometryModified&&!r.stagedForDelete||(o.geometry=null);const s=r.stagedForDelete?"deleteFeatures":"updateFeatures";await e(a,{[s]:[o]})},e([o()],w.prototype,"editableItem",null),e([o()],w.prototype,"fullFeature",void 0),e([o()],w.prototype,"hasPendingEdits",null),e([o()],w.prototype,"shouldShowAttachments",null),e([o()],w.prototype,"shouldAllowAttachmentEditing",null),e([o()],w.prototype,"reliesOnOwnerAdminPrivileges",null),w=h=e([s(g)],w);export{f as HANDLE_KEYS,w as UpdateRecordWorkflow};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{deprecatedProperty as n}from"../../core/deprecate.js";import s from"../../core/Evented.js";import i from"../../core/Logger.js";import{destroyMaybe as o}from"../../core/maybe.js";import{EsriPromiseMixin as r}from"../../core/Promise.js";import{watch as a}from"../../core/reactiveUtils.js";import{templateHasKey as l}from"../../core/string.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as c}from"../../core/support/UpdatingHandles.js";import d from"../../form/FormTemplate.js";import h from"../../layers/support/ContingentValue.js";import{isEditableLayer as f}from"../../layers/support/editableLayers.js";import m from"../../layers/support/LayerContingentValuesCache.js";import{flattenFieldInputs as g,flattenRelationshipInputs as y,parseFormTemplateString as _,isGroupInput as v,isGroupElement as C,isFieldElement as I,isRelationshipElement as F,isRelationshipInput as E,isFieldInput as x,getNormalizedFeatureTypeInfo as b}from"./featureFormUtils.js";import V from"./FieldInput.js";import{createFormExpressionArcadeExecutor as w}from"./FormExpressionArcadeExecutor.js";import{FormExpressionsManager as j}from"./FormExpressionsManager.js";import A from"./GroupInput.js";import T from"./RelationshipInput.js";const M=new t({attributes:{}}),R=["editableExpression","requiredExpression","valueExpression","visibilityExpression"],N=["visibilityExpression"],L=["editableExpression","visibilityExpression"],S="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",k="#JSAPI_CONTINGENT_VALUE_ANY_HASH",H="#JSAPI_CONTINGENT_VALUE_NULL_HASH",P="esri.widgets.FeatureForm.FeatureFormViewModel",U=i.getLogger(P);let G=class extends(r(s.EventedAccessor)){constructor(e){super(e),this._expressionExecutorLookup=new Map,this._expressionsManager=null,this._contingentValuesCache=null,this._featureClone=M.clone(),this._initialFeature=M.clone(),this._updatingHandles=new c,this.arcadeEditType="NA",this.contingencyConstraintViolations=new Map,this.disabled=!1,this.inputs=[],this.map=null,this.relatedRecordCallbacks=null,this.strict=!1}initialize(){const e=a((()=>[this.layer,!!this.layer?.loaded,this.formTemplate,this.feature,this.arcadeEditType]),(([e,t])=>{null!=e&&(t?this._updateInputs():e.load().catch((()=>{})))}),{equals:([e,t,n,s,i],[o,r,a,l,u])=>e===o&&t===r&&n===a&&s===l&&i===u,initial:!0}),t=a((()=>this._arcadeContextInfo),(e=>{null!=this._expressionsManager&&(this._expressionsManager.arcadeContextInfo=e)})),n=a((()=>this.layer),(e=>{const t="subtype-sublayer"===e?.type?e.parent:"feature"===e?.type?e:null;t&&this.addResolvingPromise(m.createLoadedLayerContingentValuesCache(t).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.addHandles([e,t,n])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this._updatingHandles.destroy()}get _expressionInfosLookup(){return new Map(this.formTemplate?.expressionInfos?.map((e=>[e.name,e])))}get activeRelationshipInput(){return this.allRelationshipInputs.find((e=>e.relationshipId===this.relationshipId))}get _arcadeContextInfo(){const{_initialFeature:e,arcadeEditType:t,layer:n,map:s,spatialReference:i}=this;return{layer:f(n)?n:null,originalFeature:e,editType:t,map:s,spatialReference:i}}get allFieldInputs(){return g(this.inputs)}get allRelationshipInputs(){return y(this.inputs)}get _layerFieldsByName(){return new Map(this.layer?.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){this._featureClone=e?e.clone():M.clone(),this._initialFeature=this._featureClone.clone(),e?(this._resetFieldInputValues(this._featureClone),this.allRelationshipInputs.forEach((t=>t.feature=e))):(this.inputs.forEach((e=>e.destroy())),this.inputs.length=0),this.contingencyConstraintViolations.clear(),null!=this._expressionsManager&&(this._expressionsManager.resetExecutors(),this._expressionsManager.feature=this._featureClone,this._updatingHandles.addPromise(this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated())))),this._set("feature",e)}get fieldsWithContingentValues(){if(null==this._contingentValuesCache)return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get formDescription(){const{formTemplate:e,layer:t}=this;return null!=e&&e.description&&t?_(e.description,this.getValues(),t.fieldsIndex):null}get formTitle(){const{formTemplate:e,layer:t}=this;return null!=e&&e.title&&t?_(e.title,this.getValues(),t.fieldsIndex):null}formHeaderVisible(){const{activeRelationshipInput:e,formDescription:t,formTitle:n}=this;return!(e||!t&&!n)}set inputFields(e){n(U,"inputFields",{replacement:"FeatureFormViewModel.inputs",version:"4.27"}),this.inputs=e}get inputFields(){return n(U,"inputFields",{replacement:"FeatureFormViewModel.inputs",version:"4.27"}),this.inputs}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){this._override("layer",e)}get relationshipId(){return this._get("relationshipId")}set relationshipId(e){const t=this.allRelationshipInputs;if(null!=e&&e===this.relationshipId||t.forEach((e=>e.showAllEnabled=!1)),null!=e){const n=t.find((t=>t.relationshipId===e));n&&(n.showAllEnabled=!0)}this._set("relationshipId",e)}get spatialReference(){return this.layer?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){return this.layer?.loaded?"ready":"disabled"}get submittable(){return!!this.valid||this.allFieldInputs.filter((e=>!e.valid)).every((({submittable:e})=>e))}get updating(){return this._updatingHandles.updating}get valid(){const e=this.allFieldInputs;return e.length>0&&e.every((({valid:e})=>e))}get view(){return n(U,"view",{replacement:"FeatureForm.map",version:"4.27"}),this._get("view")}set view(e){n(U,"view",{replacement:"FeatureForm.map",version:"4.27"}),this._set("view",e),e?.map&&(this.map=e.map)}findField(e){return this.allFieldInputs.find((t=>t.name===e))}getValue(e){const{_featureClone:t,layer:n}=this,s=!!n?.getField(e);return t.getAttribute(e)??(s?null:void 0)}setValue(e,t){const{_featureClone:n,strict:s}=this,i=this.findField(e);t=""===t?null:t,i&&n.getAttribute(e)!==t&&(i.value=t,s&&!i.valid||(this._afterValueChange(i),null!=this._expressionsManager&&this._updatingHandles.addPromise(this._expressionsManager.evaluateInvalidated([i.name]).finally((()=>this._afterExpressionsEvaluated())))))}getValues(){return{...this._featureClone.attributes}}overrideInitialFeature(e){this._initialFeature=e}submit(){const e=this.allFieldInputs,t=new Set(e.filter((e=>e.valid)).map((({name:e})=>e))),n=e.filter((e=>!e.valid)).map((({name:e})=>e)),s=this.getValues();if(this.validateContingencyConstraints(s,{includeIncompleteViolations:!0}).length>0)for(const[i,o]of this.contingencyConstraintViolations.entries())"error"===o.type&&(t.delete(i),n.push(i));this.emit("submit",{valid:[...t],invalid:n,values:s})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,s=new Map;if(this.contingencyConstraintViolations=s,null==n)return[];const{invalid:i,incomplete:o}=n.validateContingencyConstraints(e),r=[...i,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)s.set(e,a);return r}notifyFeatureGeometryChanged(){const{_expressionsManager:e,feature:t,_featureClone:n}=this;n.geometry=t.geometry,null!=e&&this._updatingHandles.addPromise(e.evaluateInvalidatedByGeometry().finally((()=>this._afterExpressionsEvaluated())))}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}_updateInputs(){const{_featureClone:e,_initialFeature:t,arcadeEditType:n,formTemplate:s,inputs:i,layer:o}=this;if(!o)return;const r={arcadeEditType:n,feature:e,initialFeature:t,layer:o},a=i.slice(),l=null!=s&&s.elements&&s.elements.length>0?this._updateInputsUsingFormElements(a,s.elements,r):this._updateInputsUsingLayerFields(a,o?.fields,r);this.inputs=l}_updateInputsUsingFormElements(e,t,n){const s=new Map;for(const r of e)if(v(r)){s.set(r.element,r);for(const e of r.inputs)e.element&&s.set(e.element,e)}else r.element&&s.set(r.element,r);const i=new Map,o=this._updateInputsUsingFormElementsRecursive({existingInputsByElement:s,updatedElements:t.filter(O),sharedInitializationProperties:n,group:null,newExpressionExecutorPromises:i});this._updatingHandles.addPromise(Promise.all(Array.from(i.values())).then((()=>{const e=Array.from(this._expressionExecutorLookup.values()),t=g(o);return this._createExpressionsManager(e,t),this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated()))})));for(const[r,a]of s.entries())s.delete(r),a.destroy();return o}_updateInputsUsingFormElementsRecursive(e){const{existingInputsByElement:t,updatedElements:n,sharedInitializationProperties:s,group:i,newExpressionExecutorPromises:o}=e,r=[];for(const a of n){const e=t.has(a),n=e?t.get(a):C(a)?this._makeGroupInputFromElement(a,s):I(a)?this._makeFieldInputFromElement(a,s,i):F(a)?this._makeRelationshipInputFromElement(a,s,i):null;if(n){if(r.push(n),e)if(t.delete(a),v(n)){const{feature:e}=s;n.set({feature:e})}else if(E(n)){const e=this.relationshipId===a.relationshipId;n.set(s),n.set({map:this.map,showAllEnabled:e})}else n.set(s);else this._assignExpressionExecutors(n,a,o);if(C(a)){const e=a.elements.filter((e=>O(e)));n.inputs=this._updateInputsUsingFormElementsRecursive({existingInputsByElement:t,updatedElements:e,sharedInitializationProperties:s,group:n,newExpressionExecutorPromises:o})}}}return r}_updateInputsUsingLayerFields(e,t,n){if(!Array.isArray(t))return i.getLogger(this).warn(this.declaredClass,"No attribute fields found."),[];const s=new Map;for(const i of e)if(v(i)){for(const e of i.inputs)e.destroy();i.inputs.length=0,i.destroy()}else E(i)?i.destroy():x(i)&&(null!==i.element?i.destroy():s.set(i.field,i));const o=[],{arcadeEditType:r,feature:a,initialFeature:l,layer:u}=n;for(const i of t){const e=s.get(i)??new V({arcadeEditType:r,field:i,feature:a,initialFeature:l,layer:u,value:a?.getAttribute(i.name)??null});o.push(e),s.delete(i)}for(const[i,p]of s.entries())s.delete(i),p.destroy();return o}_resetFieldInputValues(e){for(const t of this.allFieldInputs)t.value=e.getAttribute(t.name)}_makeFieldInputFromElement(e,t,n){const{arcadeEditType:s,feature:i,initialFeature:o,layer:r}=t,{fieldName:a}=e,l=a&&this._layerFieldsByName.get(a);return l?new V({arcadeEditType:s,element:e,field:l,value:i?.getAttribute(e.fieldName)??null,feature:i,initialFeature:o,layer:r,group:n}):null}_makeGroupInputFromElement(e,t){const{feature:n,layer:s}=t;return new A({element:e,inputs:[],feature:n,layer:s})}_makeRelationshipInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o}=t;return new T({element:e,feature:i,group:n,layer:o,map:s})}_assignExpressionExecutors(e,t,n){const s=C(t)?N:F(t)?L:R,i=[];for(const o of s){const s=t[o],{_expressionExecutorLookup:i}=this;if(null!=s&&""!==s){const t=`${o}Executor`,r=this._expressionInfosLookup.get(s)?.expression??s;if(i.has(r))e[t]=i.get(r);else if(n.has(r)){const s=n.get(r).then((n=>(e[t]=n,n)));n.set(r,s)}else{const s=w(r,this.layer).then((n=>(e[t]=n,i.set(r,n),n)));n.set(r,s)}}}return i}_createExpressionsManager(e,t){const{_arcadeContextInfo:n,_featureClone:s}=this;this._expressionsManager=new j({executors:e,feature:s,arcadeContextInfo:n,fieldInputs:t})}_afterValueChange(e){const{name:t,value:n}=e,{_featureClone:s,formTemplate:i,layer:o}=this;if(!o)return;const r=s.getAttribute(t);s.setAttribute(t,n);const{typeFieldName:a,types:u}=b(o);if(t===a&&n!==r){if("subtype-sublayer"===o.type){const e=o.parent?.findSublayerForFeature(s);s.sourceLayer=this.feature.sourceLayer=e}const e=new Set;for(const t of u)if(t.domains&&"object"==typeof t.domains)for(const n of Object.keys(t.domains))e.add(n);for(const t of e){const e=this.findField(t);e&&e.notifyChange("domain")}}if(null!=i){const{description:e,title:n}=i;n&&l(n,t)&&this.notifyChange("formTitle"),e&&l(e,t)&&this.notifyChange("formDescription")}this._emitChangeEvent(e)}_afterExpressionsEvaluated(){const{_featureClone:e}=this;for(const t of this.allFieldInputs)t.value!==e.getAttribute(t.name)&&this._afterValueChange(t)}_joinContingentValues(){const e=this._contingentValuesCache;if(null==e)return[];const{typeFieldName:t}=b(this.layer),n=t?this.getValue(t):null,s=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:i}=r,o=[];for(const s of e)s.isRetired||null!=s.subtype&&s.subtype.code!==n||o.push({values:s.values});o.length>0&&s.push({name:i,fields:t,contingencies:o})}const[i,o]=this._generateJoinPlan(s);return[...i.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],s=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const i=t.get(e),o=l,r=[i.name,o.name].sort().join("|");if(s.has(r))continue;n.push([i,o]),s.add(r),t.set(e,o)}else t.set(e,l);const i=new Set(n.flat()),o=new Set(e);for(const l of i)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),s=r.get(t);for(const i of s)n.add(i),a.set(i,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let s=t.shift(),i=this._generateJoinKey(n.fields,s.fields),o=new Set([...n.fields,...s.fields]),r=new Map;for(const l of n.contingencies){const[e]=this._hashContingency(l,i.codedValueFields,!0);r.has(e)?r.get(e)?.push(l):r.set(e,[l])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of s.contingencies){const[n,s]=this._hashContingency(t,i.codedValueFields),o=s?this._findMatchingContingenciesWithAnyHashMask(r,n):r.get(n);if(r.has(k)&&o?.push(...this._findMatchingContingenciesContainingAny(t,r.get(k),i.codedValueFields)),null!=o)for(const r of o){const n=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(r,t,i.rangeFields):this._joinContingencies(r,t);if(null==n)break;const[s]=this._hashContingency(n,a.codedValueFields,!0);e.has(s)?e.get(s)?.push(n):e.set(s,[n])}}r=e,s=n,i=a,o=new Set([...o,...s.fields])}const a=[];for(const l of s.contingencies){const[e,t]=this._hashContingency(l,i.codedValueFields),n=t?this._findMatchingContingenciesWithAnyHashMask(r,e):r.get(e);if(r.has(k)&&n.push(...this._findMatchingContingenciesContainingAny(l,r.get(k),i.codedValueFields)),null!=n)for(const s of n){const e=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(s,l,i.rangeFields):this._joinContingencies(s,l);null!=e&&a.push(e)}}return a}_joinContingencies(e,t){const n={values:{...e.values,...t.values}};for(const[s,i]of Object.entries(n.values))"any"===i.objectType&&null!=e.values[s]&&(n.values[s]=e.values[s]);return n}_joinContingenciesWithRangeDomains(e,t,n){const s=this._joinContingencies(e,t);for(const i of n){const n=e.values[i],o=t.values[i],{leftIsNull:r,rightIsNull:a,bothAreNull:l,leftIsAny:u,rightIsAny:p,bothAreAny:c,leftIsRange:d,rightIsRange:f}=this._compareObjectTypes(n.objectType,o.objectType);if(l||c)continue;if(r&&p||a&&u){s.values[i]=new h({objectType:"null"});continue}if(r&&f||a&&d)return null;u?(n.minValue=-1/0,n.maxValue=1/0):p&&(o.minValue=-1/0,o.maxValue=1/0);const m=Math.max(n.minValue,o.minValue),g=Math.min(n.maxValue,o.maxValue);if(m>g)return null;s.values[i]=new h({objectType:"range",minValue:m,maxValue:g})}return s}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const s=t.values[n],i=e.values[n];return"any"===s.objectType||"any"===i.objectType||s.codedValue?.code===i.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),s=[];for(const[i,o]of e){if(i===k)break;n.test(i)&&s.push(...o)}return s}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,s=Array.isArray(t)?new Set(t):t,i=n.size<s.size?n:s,o=i===n?s:n,r=new Set,a=new Set;for(const l of i)if(o.has(l)){const e=this.layer?.getFieldDomain(l,{feature:this.feature});if(null==e)continue;switch(e.type){case"coded-value":r.add(l);break;case"range":a.add(l)}}return{codedValueFields:[...r],rangeFields:[...a]}}_hashContingency(e,t,n=!1){if(t.length<1)return[S,!1];const s=[];let i=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[k,!0];i=!0,s.push(`${o}:.*`)}else"null"===t.objectType?s.push(`${o}:${H}`):s.push(`${o}:${t.codedValue?.code}`)}return[s.sort().join("&"),i]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}};function O(e){return"field"===e.type||"group"===e.type||"relationship"===e.type||(i.getLogger(P).warn("form-info::unsupported-element-type","Only element types 'field', 'group' and 'relationship' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}e([u()],G.prototype,"_expressionInfosLookup",null),e([u()],G.prototype,"_featureClone",void 0),e([u()],G.prototype,"activeRelationshipInput",null),e([u()],G.prototype,"_arcadeContextInfo",null),e([u({readOnly:!0})],G.prototype,"allFieldInputs",null),e([u()],G.prototype,"allRelationshipInputs",null),e([u()],G.prototype,"_layerFieldsByName",null),e([u()],G.prototype,"arcadeEditType",void 0),e([u()],G.prototype,"contingencyConstraintViolations",void 0),e([u()],G.prototype,"disabled",void 0),e([u()],G.prototype,"feature",null),e([u()],G.prototype,"fieldsWithContingentValues",null),e([u({type:d})],G.prototype,"formTemplate",null),e([u()],G.prototype,"formDescription",null),e([u()],G.prototype,"formTitle",null),e([u()],G.prototype,"formHeaderVisible",null),e([u()],G.prototype,"inputs",void 0),e([u()],G.prototype,"inputFields",null),e([u()],G.prototype,"joinedContingentValues",null),e([u()],G.prototype,"layer",null),e([u()],G.prototype,"map",void 0),e([u()],G.prototype,"relatedRecordCallbacks",void 0),e([u()],G.prototype,"relationshipId",null),e([u()],G.prototype,"spatialReference",null),e([u()],G.prototype,"state",null),e([u()],G.prototype,"strict",void 0),e([u()],G.prototype,"submittable",null),e([u()],G.prototype,"updating",null),e([u()],G.prototype,"valid",null),e([u()],G.prototype,"view",null),e([u()],G.prototype,"getValues",null),e([u()],G.prototype,"submit",null),G=e([p(P)],G);const $=G;export{$ as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{deprecatedProperty as n}from"../../core/deprecate.js";import s from"../../core/Evented.js";import i from"../../core/Logger.js";import{destroyMaybe as o}from"../../core/maybe.js";import{EsriPromiseMixin as r}from"../../core/Promise.js";import{watch as a}from"../../core/reactiveUtils.js";import{templateHasKey as l}from"../../core/string.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as c}from"../../core/support/UpdatingHandles.js";import d from"../../form/FormTemplate.js";import h from"../../layers/support/ContingentValue.js";import{isEditableLayer as f}from"../../layers/support/editableLayers.js";import m from"../../layers/support/LayerContingentValuesCache.js";import{flattenFieldInputs as g,flattenRelationshipInputs as y,parseFormTemplateString as _,isGroupInput as v,isGroupElement as I,isFieldElement as E,isRelationshipElement as C,isRelationshipInput as x,isFieldInput as F,getNormalizedFeatureTypeInfo as b}from"./featureFormUtils.js";import V from"./FieldInput.js";import{createFormExpressionArcadeExecutor as w}from"./FormExpressionArcadeExecutor.js";import{FormExpressionsManager as j}from"./FormExpressionsManager.js";import A from"./GroupInput.js";import T from"./RelationshipInput.js";const M=new t({attributes:{}}),R=["editableExpression","requiredExpression","valueExpression","visibilityExpression"],N=["visibilityExpression"],S=["editableExpression","visibilityExpression"],L="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",k="#JSAPI_CONTINGENT_VALUE_ANY_HASH",U="#JSAPI_CONTINGENT_VALUE_NULL_HASH",H="esri.widgets.FeatureForm.FeatureFormViewModel",P=i.getLogger(H);let G=class extends(r(s.EventedAccessor)){constructor(e){super(e),this._expressionExecutorsInUse=new Set,this._expressionExecutorLookup=new Map,this._expressionsManager=null,this._contingentValuesCache=null,this._featureClone=M.clone(),this._initialFeature=M.clone(),this._updatingHandles=new c,this.arcadeEditType="NA",this.contingencyConstraintViolations=new Map,this.disabled=!1,this.inputs=[],this.map=null,this.relatedRecordCallbacks=null,this.strict=!1}initialize(){const e=a((()=>[this.layer,!!this.layer?.loaded,this.formTemplate,this.feature,this.arcadeEditType]),(async([e,t])=>{null!=e&&(t?this._updatingHandles.addPromise(this._updateInputs()):e.load().catch((()=>{})))}),{equals:([e,t,n,s,i],[o,r,a,l,u])=>e===o&&t===r&&n===a&&s===l&&i===u,initial:!0}),t=a((()=>this._arcadeContextInfo),(e=>{null!=this._expressionsManager&&(this._expressionsManager.arcadeContextInfo=e)})),n=a((()=>this.layer),(e=>{const t="subtype-sublayer"===e?.type?e.parent:"feature"===e?.type?e:null;t&&this.addResolvingPromise(m.createLoadedLayerContingentValuesCache(t).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.addHandles([e,t,n])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this._updatingHandles.destroy()}get _expressionInfosLookup(){return new Map(this.formTemplate?.expressionInfos?.map((e=>[e.name,e])))}get activeRelationshipInput(){return this.allRelationshipInputs.find((e=>e.relationshipId===this.relationshipId))}get _arcadeContextInfo(){const{_initialFeature:e,arcadeEditType:t,layer:n,map:s,spatialReference:i}=this;return{layer:f(n)?n:null,originalFeature:e,editType:t,map:s,spatialReference:i}}get allFieldInputs(){return g(this.inputs)}get allRelationshipInputs(){return y(this.inputs)}get _layerFieldsByName(){return new Map(this.layer?.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){this._featureClone=e?e.clone():M.clone(),this._initialFeature=this._featureClone.clone(),this._expressionsManager&&(this._expressionsManager.feature=this._featureClone),e?(this._resetFieldInputValues(this._featureClone),this.allRelationshipInputs.forEach((t=>t.feature=e))):(this.inputs.forEach((e=>e.destroy())),this.inputs.length=0),this.contingencyConstraintViolations.clear(),this._set("feature",e)}get fieldsWithContingentValues(){if(null==this._contingentValuesCache)return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get formDescription(){const{formTemplate:e,layer:t}=this;return null!=e&&e.description&&t?_(e.description,this.getValues(),t.fieldsIndex):null}get formTitle(){const{formTemplate:e,layer:t}=this;return null!=e&&e.title&&t?_(e.title,this.getValues(),t.fieldsIndex):null}formHeaderVisible(){const{activeRelationshipInput:e,formDescription:t,formTitle:n}=this;return!(e||!t&&!n)}set inputFields(e){n(P,"inputFields",{replacement:"FeatureFormViewModel.inputs",version:"4.27"}),this.inputs=e}get inputFields(){return n(P,"inputFields",{replacement:"FeatureFormViewModel.inputs",version:"4.27"}),this.inputs}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){this._override("layer",e)}get relationshipId(){return this._get("relationshipId")}set relationshipId(e){const t=this.allRelationshipInputs;if(null!=e&&e===this.relationshipId||t.forEach((e=>e.showAllEnabled=!1)),null!=e){const n=t.find((t=>t.relationshipId===e));n&&(n.showAllEnabled=!0)}this._set("relationshipId",e)}get spatialReference(){return this.layer?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){return this.layer?.loaded?"ready":"disabled"}get submittable(){return!!this.valid||this.allFieldInputs.filter((e=>!e.valid)).every((({submittable:e})=>e))}get updating(){return this._updatingHandles.updating}get valid(){const e=this.allFieldInputs;return e.length>0&&e.every((({valid:e})=>e))}get view(){return n(P,"view",{replacement:"FeatureForm.map",version:"4.27"}),this._get("view")}set view(e){n(P,"view",{replacement:"FeatureForm.map",version:"4.27"}),this._set("view",e),e?.map&&(this.map=e.map)}findField(e){return this.allFieldInputs.find((t=>t.name===e))}getValue(e){const{_featureClone:t,layer:n}=this,s=!!n?.getField(e);return t.getAttribute(e)??(s?null:void 0)}setValue(e,t){const{_featureClone:n,strict:s}=this,i=this.findField(e);t=""===t?null:t,i&&n.getAttribute(e)!==t&&(i.value=t,s&&!i.valid||(this._afterValueChange(i),null!=this._expressionsManager&&this._updatingHandles.addPromise(this._expressionsManager.evaluateInvalidated([i.name]).finally((()=>this._afterExpressionsEvaluated())))))}getValues(){return{...this._featureClone.attributes}}overrideInitialFeature(e){this._initialFeature=e}submit(){const e=this.allFieldInputs,t=new Set(e.filter((e=>e.valid)).map((({name:e})=>e))),n=e.filter((e=>!e.valid)).map((({name:e})=>e)),s=this.getValues();if(this.validateContingencyConstraints(s,{includeIncompleteViolations:!0}).length>0)for(const[i,o]of this.contingencyConstraintViolations.entries())"error"===o.type&&(t.delete(i),n.push(i));this.emit("submit",{valid:[...t],invalid:n,values:s})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,s=new Map;if(this.contingencyConstraintViolations=s,null==n)return[];const{invalid:i,incomplete:o}=n.validateContingencyConstraints(e),r=[...i,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)s.set(e,a);return r}notifyFeatureGeometryChanged(){const{_expressionsManager:e,feature:t,_featureClone:n}=this;n.geometry=t.geometry,null!=e&&this._updatingHandles.addPromise(e.evaluateInvalidatedByGeometry().finally((()=>this._afterExpressionsEvaluated())))}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}async _updateInputs(){this._stopExpressions();const{_featureClone:e,_initialFeature:t,arcadeEditType:n,formTemplate:s,inputs:i,layer:o}=this;if(!o)return;const r={arcadeEditType:n,feature:e,initialFeature:t,layer:o},a=i.slice(),l=null!=s&&s.elements&&s.elements.length>0?await this._updateInputsUsingFormElements(a,s.elements,r):this._updateInputsUsingLayerFields(a,o?.fields,r);this.inputs=l,await this._startExpressions()}async _updateInputsUsingFormElements(e,t,n){const s=new Map;for(const r of e)if(v(r)){s.set(r.element,r);for(const e of r.inputs)e.element&&s.set(e.element,e)}else r.element&&s.set(r.element,r);const i=new Map,o=this._updateInputsUsingFormElementsRecursive({existingInputsByElement:s,updatedElements:t.filter(O),sharedInitializationProperties:n,group:null,newExpressionExecutorPromises:i});for(const[r,a]of s.entries())s.delete(r),a.destroy();return await Promise.all(Array.from(i.values())),o}_updateInputsUsingFormElementsRecursive(e){const{existingInputsByElement:t,updatedElements:n,sharedInitializationProperties:s,group:i,newExpressionExecutorPromises:o}=e,r=[];for(const a of n){const e=t.has(a),n=e?t.get(a):I(a)?this._makeGroupInputFromElement(a,s):E(a)?this._makeFieldInputFromElement(a,s,i):C(a)?this._makeRelationshipInputFromElement(a,s,i):null;if(n){if(r.push(n),this._assignExpressionExecutors(n,a,o),e)if(t.delete(a),v(n)){const{feature:e}=s;n.set({feature:e})}else if(x(n)){const e=this.relationshipId===a.relationshipId;n.set(s),n.set({map:this.map,showAllEnabled:e})}else n.set(s);if(I(a)){const e=a.elements.filter((e=>O(e)));n.inputs=this._updateInputsUsingFormElementsRecursive({existingInputsByElement:t,updatedElements:e,sharedInitializationProperties:s,group:n,newExpressionExecutorPromises:o})}}}return r}_updateInputsUsingLayerFields(e,t,n){if(!Array.isArray(t))return i.getLogger(this).warn(this.declaredClass,"No attribute fields found."),[];const s=new Map;for(const i of e)if(v(i)){for(const e of i.inputs)e.destroy();i.inputs.length=0,i.destroy()}else x(i)?i.destroy():F(i)&&(null!==i.element?i.destroy():s.set(i.field,i));const o=[],{arcadeEditType:r,feature:a,initialFeature:l,layer:u}=n;for(const i of t){const e=s.get(i)??new V({arcadeEditType:r,field:i,feature:a,initialFeature:l,layer:u,value:a?.getAttribute(i.name)??null});o.push(e),s.delete(i)}for(const[i,p]of s.entries())s.delete(i),p.destroy();return o}_resetFieldInputValues(e){for(const t of this.allFieldInputs)t.value=e.getAttribute(t.name)}_makeFieldInputFromElement(e,t,n){const{arcadeEditType:s,feature:i,initialFeature:o,layer:r}=t,{fieldName:a}=e,l=a&&this._layerFieldsByName.get(a);return l?new V({arcadeEditType:s,element:e,field:l,value:i?.getAttribute(e.fieldName)??null,feature:i,initialFeature:o,layer:r,group:n}):null}_makeGroupInputFromElement(e,t){const{feature:n,layer:s}=t;return new A({element:e,inputs:[],feature:n,layer:s})}_makeRelationshipInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o}=t;return new T({element:e,feature:i,group:n,layer:o,map:s})}_assignExpressionExecutors(e,t,n){const s=I(t)?N:C(t)?S:R,i=[];for(const o of s){const s=`${o}Executor`;if(e[s]){this._useExecutor(e[s]);continue}const i=t[o],{_expressionExecutorLookup:r}=this;if(null!=i&&""!==i){const t=this._expressionInfosLookup.get(i)?.expression??i;if(r.has(t))e[s]=this._useExecutor(r.get(t));else if(n.has(t)){const i=n.get(t).then((t=>(e[s]=t,t)));n.set(t,i)}else{const i=w(t,this.layer).then((n=>(e[s]=this._useExecutor(n),r.set(t,n),n)));n.set(t,i)}}}return i}_createExpressionsManager(e){const{_arcadeContextInfo:t,_featureClone:n,allFieldInputs:s}=this;this._expressionsManager=new j({executors:e,feature:n,arcadeContextInfo:t,fieldInputs:s})}async _startExpressions(){if(0===this._expressionExecutorsInUse.size)return;const e=Array.from(this._expressionExecutorsInUse);this._createExpressionsManager(e),await this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated()))}_stopExpressions(){this._expressionsManager=o(this._expressionsManager),this._expressionExecutorsInUse.clear()}_useExecutor(e){return this._expressionExecutorsInUse.add(e),e}_afterValueChange(e){const{name:t,value:n}=e,{_featureClone:s,formTemplate:i,layer:o}=this;if(!o)return;const r=s.getAttribute(t);s.setAttribute(t,n);const{typeFieldName:a,types:u}=b(o);if(t===a&&n!==r){if("subtype-sublayer"===o.type){const e=o.parent?.findSublayerForFeature(s);s.sourceLayer=this.feature.sourceLayer=e}const e=new Set;for(const t of u)if(t.domains&&"object"==typeof t.domains)for(const n of Object.keys(t.domains))e.add(n);for(const t of e){const e=this.findField(t);e&&e.notifyChange("domain")}}if(null!=i){const{description:e,title:n}=i;n&&l(n,t)&&this.notifyChange("formTitle"),e&&l(e,t)&&this.notifyChange("formDescription")}this._emitChangeEvent(e)}_afterExpressionsEvaluated(){const{_featureClone:e}=this;for(const t of this.allFieldInputs)t.value!==e.getAttribute(t.name)&&this._afterValueChange(t)}_joinContingentValues(){const e=this._contingentValuesCache;if(null==e)return[];const{typeFieldName:t}=b(this.layer),n=t?this.getValue(t):null,s=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:i}=r,o=[];for(const s of e)s.isRetired||null!=s.subtype&&s.subtype.code!==n||o.push({values:s.values});o.length>0&&s.push({name:i,fields:t,contingencies:o})}const[i,o]=this._generateJoinPlan(s);return[...i.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],s=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const i=t.get(e),o=l,r=[i.name,o.name].sort().join("|");if(s.has(r))continue;n.push([i,o]),s.add(r),t.set(e,o)}else t.set(e,l);const i=new Set(n.flat()),o=new Set(e);for(const l of i)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),s=r.get(t);for(const i of s)n.add(i),a.set(i,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let s=t.shift(),i=this._generateJoinKey(n.fields,s.fields),o=new Set([...n.fields,...s.fields]),r=new Map;for(const l of n.contingencies){const[e]=this._hashContingency(l,i.codedValueFields,!0);r.has(e)?r.get(e)?.push(l):r.set(e,[l])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of s.contingencies){const[n,s]=this._hashContingency(t,i.codedValueFields),o=s?this._findMatchingContingenciesWithAnyHashMask(r,n):r.get(n);if(r.has(k)&&o?.push(...this._findMatchingContingenciesContainingAny(t,r.get(k),i.codedValueFields)),null!=o)for(const r of o){const n=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(r,t,i.rangeFields):this._joinContingencies(r,t);if(null==n)break;const[s]=this._hashContingency(n,a.codedValueFields,!0);e.has(s)?e.get(s)?.push(n):e.set(s,[n])}}r=e,s=n,i=a,o=new Set([...o,...s.fields])}const a=[];for(const l of s.contingencies){const[e,t]=this._hashContingency(l,i.codedValueFields),n=t?this._findMatchingContingenciesWithAnyHashMask(r,e):r.get(e);if(r.has(k)&&n.push(...this._findMatchingContingenciesContainingAny(l,r.get(k),i.codedValueFields)),null!=n)for(const s of n){const e=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(s,l,i.rangeFields):this._joinContingencies(s,l);null!=e&&a.push(e)}}return a}_joinContingencies(e,t){const n={values:{...e.values,...t.values}};for(const[s,i]of Object.entries(n.values))"any"===i.objectType&&null!=e.values[s]&&(n.values[s]=e.values[s]);return n}_joinContingenciesWithRangeDomains(e,t,n){const s=this._joinContingencies(e,t);for(const i of n){const n=e.values[i],o=t.values[i],{leftIsNull:r,rightIsNull:a,bothAreNull:l,leftIsAny:u,rightIsAny:p,bothAreAny:c,leftIsRange:d,rightIsRange:f}=this._compareObjectTypes(n.objectType,o.objectType);if(l||c)continue;if(r&&p||a&&u){s.values[i]=new h({objectType:"null"});continue}if(r&&f||a&&d)return null;u?(n.minValue=-1/0,n.maxValue=1/0):p&&(o.minValue=-1/0,o.maxValue=1/0);const m=Math.max(n.minValue,o.minValue),g=Math.min(n.maxValue,o.maxValue);if(m>g)return null;s.values[i]=new h({objectType:"range",minValue:m,maxValue:g})}return s}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const s=t.values[n],i=e.values[n];return"any"===s.objectType||"any"===i.objectType||s.codedValue?.code===i.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),s=[];for(const[i,o]of e){if(i===k)break;n.test(i)&&s.push(...o)}return s}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,s=Array.isArray(t)?new Set(t):t,i=n.size<s.size?n:s,o=i===n?s:n,r=new Set,a=new Set;for(const l of i)if(o.has(l)){const e=this.layer?.getFieldDomain(l,{feature:this.feature});if(null==e)continue;switch(e.type){case"coded-value":r.add(l);break;case"range":a.add(l)}}return{codedValueFields:[...r],rangeFields:[...a]}}_hashContingency(e,t,n=!1){if(t.length<1)return[L,!1];const s=[];let i=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[k,!0];i=!0,s.push(`${o}:.*`)}else"null"===t.objectType?s.push(`${o}:${U}`):s.push(`${o}:${t.codedValue?.code}`)}return[s.sort().join("&"),i]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}};function O(e){return"field"===e.type||"group"===e.type||"relationship"===e.type||(i.getLogger(H).warn("form-info::unsupported-element-type","Only element types 'field', 'group' and 'relationship' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}e([u()],G.prototype,"_expressionInfosLookup",null),e([u()],G.prototype,"_featureClone",void 0),e([u()],G.prototype,"activeRelationshipInput",null),e([u()],G.prototype,"_arcadeContextInfo",null),e([u({readOnly:!0})],G.prototype,"allFieldInputs",null),e([u()],G.prototype,"allRelationshipInputs",null),e([u()],G.prototype,"_layerFieldsByName",null),e([u()],G.prototype,"arcadeEditType",void 0),e([u()],G.prototype,"contingencyConstraintViolations",void 0),e([u()],G.prototype,"disabled",void 0),e([u()],G.prototype,"feature",null),e([u()],G.prototype,"fieldsWithContingentValues",null),e([u({type:d})],G.prototype,"formTemplate",null),e([u()],G.prototype,"formDescription",null),e([u()],G.prototype,"formTitle",null),e([u()],G.prototype,"formHeaderVisible",null),e([u()],G.prototype,"inputs",void 0),e([u()],G.prototype,"inputFields",null),e([u()],G.prototype,"joinedContingentValues",null),e([u()],G.prototype,"layer",null),e([u()],G.prototype,"map",void 0),e([u()],G.prototype,"relatedRecordCallbacks",void 0),e([u()],G.prototype,"relationshipId",null),e([u()],G.prototype,"spatialReference",null),e([u()],G.prototype,"state",null),e([u()],G.prototype,"strict",void 0),e([u()],G.prototype,"submittable",null),e([u()],G.prototype,"updating",null),e([u()],G.prototype,"valid",null),e([u()],G.prototype,"view",null),e([u()],G.prototype,"getValues",null),e([u()],G.prototype,"submit",null),G=e([p(H)],G);const $=G;export{$ as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as i}from"../../core/accessorSupport/decorators/subclass.js";import{CodedValue as l}from"../../layers/support/CodedValue.js";import r from"../../layers/support/CodedValueDomain.js";import"../../layers/support/Domain.js";import"../../layers/support/InheritedDomain.js";import"../../layers/support/RangeDomain.js";import{getDomainRange as n,validateDomainValue as s}from"../../layers/support/domainUtils.js";import{isFieldVisibleByDefault as o,getLowerCaseEditTrackingFields as a,isNumericField as u,isStringField as p,isDateField as d,getFieldRange as m,TypeValidationError as y,validateFieldValue as h}from"../../layers/support/fieldUtils.js";import{isRelatableFeatureSupportedLayer as c}from"../Feature/support/featureUtils.js";import f from"./EditableInput.js";import{getNormalizedFeatureTypeInfo as g,isFieldElementWithTextInput as E,LengthValidationError as v}from"./featureFormUtils.js";var x;!function(e){e.Text="text",e.Number="number",e.Date="date",e.Unsupported="unsupported"}(x||(x={}));const b="__internal-type-based-coded-value-domain__";let _=class extends f{constructor(e){super(e),this._storedValue=null,this.error=null,this.field=null,this.group=null,this.requiredExpressionExecutor=null,this.type="field",this.valueExpressionExecutor=null}get _dateRange(){const{element:e}=this;if("datetime-picker"===e?.input?.type){const{max:t,min:i}=e.input;return{max:t,min:i}}return{min:null,max:null}}get _configAllowsEdits(){const{element:e,layer:t,name:i}=this;if(null!=e)return e.editableExpression?!!this.evaluatedEditableExpression:!1!==e.editable;if(t?.userHasUpdateItemPrivileges)return!0;const l=t&&"popupTemplate"in t?t?.popupTemplate?.fieldInfos?.find((({fieldName:e})=>e===i)):null;return l?.isEditable??!0}get _layerAndFieldAllowEdits(){return this.layerAllowsEdits&&this.field?.editable}get _isVisibleByDefault(){const{field:e,layer:t}=this;return!!e?.visible&&o(e,t)}get _isEditTrackingField(){return a(this.layer).includes(this.name?.toLowerCase())}get _shouldUseValueExpression(){return this._layerAndFieldAllowEdits&&!this._configAllowsEdits&&null!=this.valueExpressionExecutor}get dataType(){const{field:e}=this;return u(e)?x.Number:p(e)?x.Text:d(e)?x.Date:x.Unsupported}get dateDataType(){if(this.dataType===x.Date)return"date"!==this.field.type?"string":"number"}get domain(){const{layer:e}=this,{typeFieldName:t,types:i}=g(e);if(t===this.name&&null==this.field.domain)return new r({name:b,codedValues:i.map((({code:e,name:t})=>new l({code:e,name:t})))});const{feature:n}=this,s=e?.getFieldDomain(this.name,{feature:n}),o=this.element?.domain;return null!=o&&this._isDomainCompatible(o)?o:s}get editable(){return!!this._layerAndFieldAllowEdits&&(this.evaluatedEditableExpression??this._configAllowsEdits)}get evaluatedRequiredExpression(){const{requiredExpressionExecutor:e}=this;return null!=e?!!e.lastEvaluatedValue:null}get evaluatedValueExpression(){const{valueExpressionExecutor:e}=this;return null!=e?e.lastEvaluatedValue:null}get hint(){return this.element?.hint}get includeDate(){return!(this.dataType!==x.Date||"time-only"===this.field.type)}get includeTime(){const{element:e,field:t}=this;if(this.dataType!==x.Date)return!1;if("time-only"===t.type)return!0;if("date-only"===t.type)return!1;const i="datetime-picker"===e?.input?.type?e.input.includeTime:void 0;return void 0===i||i}get includeTimestamp(){return"timestamp-offset"===this.field.type}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get inputType(){return this.element?.input?.type}get isRelationshipKeyField(){const{field:e,layer:t}=this;return c(t)&&!!t.relationships?.some((t=>t.keyField===e.name))}get label(){return this.element?.label||this.field.alias||this.field.name}get maxLength(){const e=-1;if(this.dataType===x.Date)return e;const{field:t,element:i}=this,l=t?.length,r=E(i)?i.input.maxLength:NaN;return null!=r&&!isNaN(r)&&r>=e&&(l===e||r<=l)?r:l}get minLength(){const e=-1;if(this.dataType===x.Date)return e;const{field:t,element:i}=this,l=t?.length,r=E(i)?i.input.minLength:NaN;return null!=r&&!isNaN(r)&&r>=e&&(l===e||r<=l)?r:e}get name(){return this.field?.name}get range(){const{_dateRange:e,domain:t,field:i}=this,{max:l,min:r}=e,s=null!=l&&T(l)?l.getTime():null,o=null!=r&&T(r)?r.getTime():null,a=n(t)||m(i);if(!a)return{max:s,min:o};const u=a.max===Number.MAX_VALUE?null:a.max,p=a.min===Number.MIN_VALUE?null:a.min;return{max:null!=s&&(null===u||null!=u&&s<u)?s:u,min:null!=o&&(null===p||null!=p&&o>p)?o:p}}get required(){const{editable:e,evaluatedRequiredExpression:t,field:i,visible:l}=this;return!!e&&(!1===i?.nullable||!(!l||null==t)&&t)}set required(e){this._overrideIfSome("required",e)}get submittable(){const{field:e,required:t,valid:i,value:l}=this;return(!t||null!=l)&&(!!i||this.initialFeature.getAttribute(e.name)===l)}get updating(){const{editableExpressionExecutor:e,valueExpressionExecutor:t}=this;return null!=t&&t.updating||null!=e&&e.updating}get valid(){const e=this.editable?this._validate():null;return this._set("error",e),null===e}get value(){if(this._shouldUseValueExpression){const e=this.evaluatedValueExpression;if(this.dataType===x.Date){if(e instanceof Date)return e.getTime();if("number"!=typeof e)return parseInt(e,10)}return null!=e&&"object"==typeof e?e.toString():e}return this._storedValue}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e)}get visible(){return!this._isEditTrackingField&&(null!=this.evaluatedVisibilityExpression?this.evaluatedVisibilityExpression:null!=this.element||this._isVisibleByDefault)}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===e?.type){const i=typeof e.codedValues[0].code;if("string"===i&&p(t)||"number"===i&&u(t))return!0}return!!("range"===e?.type&&u(t)||d(t))}_validate(){const{dataType:e,domain:t,field:i,initialFeature:l,minLength:r,required:n,valid:o,value:a}=this,u=n&&null==a,p=void 0!==o;return!u&&l.getAttribute(i.name)===a&&p?null:u?y.INVALID_TYPE:"text"===e&&r>-1&&"string"==typeof a&&a.length<r?v.TOO_SHORT:t?null!==a||n?s(t,a):null:h(i,a)}};e([t()],_.prototype,"_storedValue",void 0),e([t()],_.prototype,"_configAllowsEdits",null),e([t()],_.prototype,"_layerAndFieldAllowEdits",null),e([t()],_.prototype,"_isVisibleByDefault",null),e([t()],_.prototype,"_isEditTrackingField",null),e([t()],_.prototype,"_shouldUseValueExpression",null),e([t()],_.prototype,"dataType",null),e([t()],_.prototype,"dateDataType",null),e([t()],_.prototype,"domain",null),e([t()],_.prototype,"editable",null),e([t({readOnly:!0})],_.prototype,"error",void 0),e([t()],_.prototype,"evaluatedRequiredExpression",null),e([t()],_.prototype,"evaluatedValueExpression",null),e([t()],_.prototype,"field",void 0),e([t()],_.prototype,"group",void 0),e([t({readOnly:!0})],_.prototype,"hint",null),e([t()],_.prototype,"includeDate",null),e([t()],_.prototype,"includeTime",null),e([t()],_.prototype,"includeTimestamp",null),e([t()],_.prototype,"initialFeature",null),e([t({readOnly:!0})],_.prototype,"inputType",null),e([t()],_.prototype,"label",null),e([t()],_.prototype,"maxLength",null),e([t()],_.prototype,"minLength",null),e([t({readOnly:!0})],_.prototype,"name",null),e([t()],_.prototype,"range",null),e([t()],_.prototype,"required",null),e([t()],_.prototype,"requiredExpressionExecutor",void 0),e([t()],_.prototype,"submittable",null),e([t({readOnly:!0})],_.prototype,"type",void 0),e([t()],_.prototype,"updating",null),e([t()],_.prototype,"valid",null),e([t({value:null})],_.prototype,"value",null),e([t()],_.prototype,"valueExpressionExecutor",void 0),e([t()],_.prototype,"visible",null),_=e([i("esri.widgets.FeatureForm.FieldInput")],_);const T=e=>e&&!Number.isNaN(e.valueOf()),V=_;export{V as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import{property as t}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as i}from"../../core/accessorSupport/decorators/subclass.js";import{CodedValue as l}from"../../layers/support/CodedValue.js";import r from"../../layers/support/CodedValueDomain.js";import"../../layers/support/Domain.js";import"../../layers/support/InheritedDomain.js";import"../../layers/support/RangeDomain.js";import{getDomainRange as n,validateDomainValue as s}from"../../layers/support/domainUtils.js";import{isFieldVisibleByDefault as o,getLowerCaseEditTrackingFields as u,isNumericField as a,isStringField as p,isDateField as d,getFieldRange as m,TypeValidationError as y,validateFieldValue as h}from"../../layers/support/fieldUtils.js";import{isRelatableFeatureSupportedLayer as c}from"../Feature/support/featureUtils.js";import g from"./EditableInput.js";import{getNormalizedFeatureTypeInfo as f,isFieldElementWithTextInput as E,LengthValidationError as v}from"./featureFormUtils.js";var x;!function(e){e.Text="text",e.Number="number",e.Date="date",e.Unsupported="unsupported"}(x||(x={}));const b="__internal-type-based-coded-value-domain__";let _=class extends g{constructor(e){super(e),this._storedValue=null,this._valueOriginIsExpression=!1,this.error=null,this.field=null,this.group=null,this.requiredExpressionExecutor=null,this.type="field",this.valueExpressionExecutor=null}get _dateRange(){const{element:e}=this;if("datetime-picker"===e?.input?.type){const{max:t,min:i}=e.input;return{max:t,min:i}}return{min:null,max:null}}get _configAllowsEdits(){const{element:e,layer:t,name:i}=this;if(null!=e)return e.editableExpression?!!this.evaluatedEditableExpression:!1!==e.editable;if(t?.userHasUpdateItemPrivileges)return!0;const l=t&&"popupTemplate"in t?t?.popupTemplate?.fieldInfos?.find((({fieldName:e})=>e===i)):null;return l?.isEditable??!0}get _layerAndFieldAllowEdits(){return this.layerAllowsEdits&&this.field?.editable}get _isVisibleByDefault(){const{field:e,layer:t}=this;return!!e?.visible&&o(e,t)}get _isEditTrackingField(){return u(this.layer).includes(this.name?.toLowerCase())}get _shouldUseValueExpression(){return this._layerAndFieldAllowEdits&&!this._configAllowsEdits&&null!=this.valueExpressionExecutor}get dataType(){const{field:e}=this;return a(e)?x.Number:p(e)?x.Text:d(e)?x.Date:x.Unsupported}get dateDataType(){if(this.dataType===x.Date)return"date"!==this.field.type?"string":"number"}get domain(){const{layer:e}=this,{typeFieldName:t,types:i}=f(e);if(t===this.name&&null==this.field.domain)return new r({name:b,codedValues:i.map((({code:e,name:t})=>new l({code:e,name:t})))});const{feature:n}=this,s=e?.getFieldDomain(this.name,{feature:n}),o=this.element?.domain;return null!=o&&this._isDomainCompatible(o)?o:s}get editable(){return!!this._layerAndFieldAllowEdits&&(this.evaluatedEditableExpression??this._configAllowsEdits)}get evaluatedRequiredExpression(){const{requiredExpressionExecutor:e}=this;return null!=e?!!e.lastEvaluatedValue:null}get evaluatedValueExpression(){const{valueExpressionExecutor:e}=this;return null!=e?e.lastEvaluatedValue:null}get hint(){return this.element?.hint}get includeDate(){return!(this.dataType!==x.Date||"time-only"===this.field.type)}get includeTime(){const{element:e,field:t}=this;if(this.dataType!==x.Date)return!1;if("time-only"===t.type)return!0;if("date-only"===t.type)return!1;const i="datetime-picker"===e?.input?.type?e.input.includeTime:void 0;return void 0===i||i}get includeTimestamp(){return"timestamp-offset"===this.field.type}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get inputType(){return this.element?.input?.type}get isRelationshipKeyField(){const{field:e,layer:t}=this;return c(t)&&!!t.relationships?.some((t=>t.keyField===e.name))}get label(){return this.element?.label||this.field.alias||this.field.name}get maxLength(){const e=-1;if(this.dataType===x.Date)return e;const{field:t,element:i}=this,l=t?.length,r=E(i)?i.input.maxLength:NaN;return null!=r&&!isNaN(r)&&r>=e&&(l===e||r<=l)?r:l}get minLength(){const e=-1;if(this.dataType===x.Date)return e;const{field:t,element:i}=this,l=t?.length,r=E(i)?i.input.minLength:NaN;return null!=r&&!isNaN(r)&&r>=e&&(l===e||r<=l)?r:e}get name(){return this.field?.name}get range(){const{_dateRange:e,domain:t,field:i}=this,{max:l,min:r}=e,s=null!=l&&T(l)?l.getTime():null,o=null!=r&&T(r)?r.getTime():null,u=n(t)||m(i);if(!u)return{max:s,min:o};const a=u.max===Number.MAX_VALUE?null:u.max,p=u.min===Number.MIN_VALUE?null:u.min;return{max:null!=s&&(null===a||null!=a&&s<a)?s:a,min:null!=o&&(null===p||null!=p&&o>p)?o:p}}get required(){const{editable:e,evaluatedRequiredExpression:t,field:i,visible:l}=this;return!!e&&(!1===i?.nullable||!(!l||null==t)&&t)}set required(e){this._overrideIfSome("required",e)}get submittable(){const{field:e,required:t,valid:i,value:l}=this;return(!t||null!=l)&&(!!i||this.initialFeature.getAttribute(e.name)===l)}get updating(){const{editableExpressionExecutor:e,valueExpressionExecutor:t}=this;return null!=t&&t.updating||null!=e&&e.updating}get valid(){const e=this.editable?this._validate():null;return this._set("error",e),null===e}get value(){if(this._shouldUseValueExpression){this._valueOriginIsExpression=!0;const e=this.evaluatedValueExpression;if(this.dataType===x.Date){if(e instanceof Date)return e.getTime();if("number"!=typeof e)return parseInt(e,10)}return null!=e&&"object"==typeof e?e.toString():e}return this._valueOriginIsExpression=!1,this._storedValue}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e)}get valueOriginIsExpression(){return this._valueOriginIsExpression}get visible(){return!this._isEditTrackingField&&(null!=this.evaluatedVisibilityExpression?this.evaluatedVisibilityExpression:null!=this.element||this._isVisibleByDefault)}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===e?.type){const i=typeof e.codedValues[0].code;if("string"===i&&p(t)||"number"===i&&a(t))return!0}return!!("range"===e?.type&&a(t)||d(t))}_validate(){const{dataType:e,domain:t,field:i,initialFeature:l,minLength:r,required:n,valid:o,value:u}=this,a=n&&null==u,p=void 0!==o;return!a&&l.getAttribute(i.name)===u&&p?null:a?y.INVALID_TYPE:"text"===e&&r>-1&&"string"==typeof u&&u.length<r?v.TOO_SHORT:t?null!==u||n?s(t,u):null:h(i,u)}};e([t()],_.prototype,"_storedValue",void 0),e([t()],_.prototype,"_configAllowsEdits",null),e([t()],_.prototype,"_layerAndFieldAllowEdits",null),e([t()],_.prototype,"_isVisibleByDefault",null),e([t()],_.prototype,"_isEditTrackingField",null),e([t()],_.prototype,"_shouldUseValueExpression",null),e([t()],_.prototype,"_valueOriginIsExpression",void 0),e([t()],_.prototype,"dataType",null),e([t()],_.prototype,"dateDataType",null),e([t()],_.prototype,"domain",null),e([t()],_.prototype,"editable",null),e([t({readOnly:!0})],_.prototype,"error",void 0),e([t()],_.prototype,"evaluatedRequiredExpression",null),e([t()],_.prototype,"evaluatedValueExpression",null),e([t()],_.prototype,"field",void 0),e([t()],_.prototype,"group",void 0),e([t({readOnly:!0})],_.prototype,"hint",null),e([t()],_.prototype,"includeDate",null),e([t()],_.prototype,"includeTime",null),e([t()],_.prototype,"includeTimestamp",null),e([t()],_.prototype,"initialFeature",null),e([t({readOnly:!0})],_.prototype,"inputType",null),e([t()],_.prototype,"label",null),e([t()],_.prototype,"maxLength",null),e([t()],_.prototype,"minLength",null),e([t({readOnly:!0})],_.prototype,"name",null),e([t()],_.prototype,"range",null),e([t()],_.prototype,"required",null),e([t()],_.prototype,"requiredExpressionExecutor",void 0),e([t()],_.prototype,"submittable",null),e([t({readOnly:!0})],_.prototype,"type",void 0),e([t()],_.prototype,"updating",null),e([t()],_.prototype,"valid",null),e([t({value:null})],_.prototype,"value",null),e([t()],_.prototype,"valueExpressionExecutor",void 0),e([t()],_.prototype,"valueOriginIsExpression",null),e([t()],_.prototype,"visible",null),_=e([i("esri.widgets.FeatureForm.FieldInput")],_);const T=e=>e&&!Number.isNaN(e.valueOf()),V=_;export{V 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.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Accessor.js";import{getOrCreateMapValue as s}from"../../core/MapUtils.js";import{isAbortError as r,createResolver as o}from"../../core/promiseUtils.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as n}from"../../core/accessorSupport/decorators/subclass.js";const i="#JSAPI_FORM_EXPRESSIONS_MANAGER_GEOMETRY",l="esri.widgets.FeatureForm.FormExpressionsManager";let c=class extends t{constructor(e){super(e),this._fieldReferencesLookup=new Map,this._fieldsAffectedLookup=new Map,this._latestFieldValues={...e.feature.attributes}}initialize(){this._dependencyGraph=this._buildDependencyGraph()}get _baseContext(){const{editType:e,layer:t,map:s,originalFeature:r,spatialReference:o}=this.arcadeContextInfo,a="feature"===t?.type?t:"scene"===t?.type&&null!=t.associatedLayer?t.associatedLayer:void 0;return[{$originalfeature:r,$editcontext:{editType:e},$layer:a,$featureset:a,$datastore:t?.url,$map:s},{spatialReference:o??void 0}]}set feature(e){this._latestFieldValues={...e?.attributes},this._set("feature",e)}evaluateAll(){return this._evaluate(this.executors)}evaluateExpressions(e){return this._evaluate(e)}evaluateInvalidated(e){const{_fieldReferencesLookup:t,_latestFieldValues:s,feature:r}=this,o=new Set;for(const a of e)if(s[a]=r.getAttribute(a),t.has(a))for(const e of t.get(a))o.add(e);return this._evaluate([...o])}async evaluateInvalidatedByGeometry(){if(this._fieldReferencesLookup.has(i))return this._evaluate([...this._fieldReferencesLookup.get(i)])}resetExecutors(){for(const e of this.executors)e.reset()}_buildDependencyGraph(){const{_fieldReferencesLookup:e,_fieldsAffectedLookup:t,executors:r}=this,o=new Map(this.fieldInputs.map((e=>[e.name,e]))),a=new Map(r.map((e=>[e,new Array])));for(const n of r){for(const r of n.fieldsUsed){s(e,r,(()=>new Set)).add(n);const i=o.get(r),l=i?.valueExpressionExecutor,c=i?.editableExpressionExecutor;if(null!=l&&l!==n){a.get(l).push(n);s(t,l,(()=>new Set)).add(i)}if(null!=c&&c!==n){a.get(c).push(n);s(t,c,(()=>new Set)).add(i)}}if(n.geometryUsed){s(e,i,(()=>new Set)).add(n)}}return a}async _evaluate(e){const t=new Map,{_dependencyGraph:s,_fieldsAffectedLookup:o,_latestFieldValues:a}=this;for(const r of e)u(r,t,s);for(const[i,{resolver:l,dependencyPromises:c}]of t){Promise.all(c).then((async()=>{const[e,t]=this._makeContext(a);return i.executeAsync(e,t)})).then((()=>{if(o.has(i))for(const e of o.get(i))this._latestFieldValues[e.name]=e.value;l.resolve()}),(e=>{!e||r(e)||p(e)||i.markStale(),l.reject(e)}))}const n=(await Promise.allSettled(Array.from(t.values(),(({resolver:e})=>e.promise)))).filter((e=>"rejected"===e.status&&!(r(e.reason)||p(e.reason))));if(n.length>0)throw new AggregateError(n,"One or more expression executions failed")}_makeContext(e){const[t,s]=this._baseContext,r=this.feature.clone();return r.attributes=e,[{...t,$feature:r},s]}};e([a()],c.prototype,"_baseContext",null),e([a()],c.prototype,"feature",null),e([a()],c.prototype,"executors",void 0),e([a()],c.prototype,"fieldInputs",void 0),e([a()],c.prototype,"arcadeContextInfo",void 0),c=e([n(l)],c);const u=(e,t,s)=>{if(t.has(e))return;const r=o();t.set(e,{resolver:r,dependencyPromises:[]}),e.abort();const a=s.get(e);for(const o of a)u(o,t,s),t.get(o).dependencyPromises.push(r.promise)},p=e=>e&&"object"==typeof e&&"message"in e&&"Cancelled"===e.message;export{c as FormExpressionsManager};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Accessor.js";import{getOrCreateMapValue as s}from"../../core/MapUtils.js";import{isAbortError as r,createResolver as o}from"../../core/promiseUtils.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as n}from"../../core/accessorSupport/decorators/subclass.js";const i="#JSAPI_FORM_EXPRESSIONS_MANAGER_GEOMETRY",c="esri.widgets.FeatureForm.FormExpressionsManager";let l=class extends t{constructor(e){super(e),this._fieldReferencesLookup=new Map,this._fieldsAffectedLookup=new Map,this._latestFieldValues={...e.feature.attributes}}initialize(){this._dependencyGraph=this._buildDependencyGraph()}destroy(){this.resetExecutors()}get _baseContext(){const{editType:e,layer:t,map:s,originalFeature:r,spatialReference:o}=this.arcadeContextInfo,a="feature"===t?.type?t:"scene"===t?.type&&null!=t.associatedLayer?t.associatedLayer:void 0;return[{$originalfeature:r,$editcontext:{editType:e},$layer:a,$featureset:a,$datastore:t?.url,$map:s},{spatialReference:o??void 0}]}set feature(e){this._latestFieldValues={...e?.attributes},this._set("feature",e)}evaluateAll(){return this._evaluate(this.executors)}evaluateExpressions(e){return this._evaluate(e)}evaluateInvalidated(e){const{_fieldReferencesLookup:t,_latestFieldValues:s,feature:r}=this,o=new Set;for(const a of e)if(s[a]=r.getAttribute(a),t.has(a))for(const e of t.get(a))o.add(e);return this._evaluate([...o])}async evaluateInvalidatedByGeometry(){if(this._fieldReferencesLookup.has(i))return this._evaluate([...this._fieldReferencesLookup.get(i)])}resetExecutors(){for(const e of this.executors)e.reset()}_buildDependencyGraph(){const{_fieldReferencesLookup:e,_fieldsAffectedLookup:t,executors:r}=this,o=new Map(this.fieldInputs.map((e=>[e.name,e]))),a=new Map(r.map((e=>[e,new Array])));for(const n of r){for(const r of n.fieldsUsed){s(e,r,(()=>new Set)).add(n);const i=o.get(r),c=i?.valueExpressionExecutor,l=i?.editableExpressionExecutor;if(null!=c&&c!==n){a.get(c).push(n);s(t,c,(()=>new Set)).add(i)}if(null!=l&&l!==n){a.get(l).push(n);s(t,l,(()=>new Set)).add(i)}}if(n.geometryUsed){s(e,i,(()=>new Set)).add(n)}}return a}async _evaluate(e){const t=new Map,{_dependencyGraph:s,_fieldsAffectedLookup:o,_latestFieldValues:a}=this;for(const r of e)u(r,t,s);for(const[i,{resolver:c,dependencyPromises:l}]of t){Promise.all(l).then((async()=>{const[e,t]=this._makeContext(a);return i.executeAsync(e,t)})).then((()=>{if(o.has(i))for(const e of o.get(i))this._latestFieldValues[e.name]=e.value;c.resolve()}),(e=>{!e||r(e)||p(e)||i.markStale(),c.reject(e)}))}const n=(await Promise.allSettled(Array.from(t.values(),(({resolver:e})=>e.promise)))).filter((e=>"rejected"===e.status&&!(r(e.reason)||p(e.reason))));if(n.length>0)throw new AggregateError(n,"One or more expression executions failed")}_makeContext(e){const[t,s]=this._baseContext,r=this.feature.clone();return r.attributes=e,[{...t,$feature:r},s]}};e([a()],l.prototype,"_baseContext",null),e([a()],l.prototype,"feature",null),e([a()],l.prototype,"executors",void 0),e([a()],l.prototype,"fieldInputs",void 0),e([a()],l.prototype,"arcadeContextInfo",void 0),l=e([n(c)],l);const u=(e,t,s)=>{if(t.has(e))return;const r=o();t.set(e,{resolver:r,dependencyPromises:[]}),e.abort();const a=s.get(e);for(const o of a)u(o,t,s),t.get(o).dependencyPromises.push(r.promise)},p=e=>e&&"object"==typeof e&&"message"in e&&"Cancelled"===e.message;export{l as FormExpressionsManager};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import{neverReached as i}from"../core/compilerUtils.js";import{deprecatedProperty as n}from"../core/deprecate.js";import s from"../core/Logger.js";import{watch as o}from"../core/reactiveUtils.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import r from"./Widget.js";import{CSS as d}from"./FeatureForm/css.js";import{isGroupInput as u,isFieldInput as c,isRelationshipInput as p,isInputInGroupInput as m,isFieldElementWithInputType as h,formatDateFieldValue as v,getErrorMessageForFieldInput as _,getIconForFeature as b,isNumberFieldInput as g}from"./FeatureForm/featureFormUtils.js";import f from"./FeatureForm/FeatureFormViewModel.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{Heading as y,incrementHeadingLevel as F}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as w}from"./support/decorators/messageBundle.js";import{vmEvent as R}from"./support/decorators/vmEvent.js";import{tsx as I}from"./support/jsxFactory.js";import{DateTime as O}from"luxon";import{substitute as V}from"../intl/substitute.js";import{getLocale as M}from"../intl/locale.js";const k="TT",D="data-field-name",x="latn",T=e=>"valueAsDate"in e,N="esri.widgets.FeatureForm",L=s.getLogger(N);let E=class extends r{constructor(e,t){super(e,t),this._activeNumberFieldEdit=null,this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName="",this._inputsWithInvalidCodedValue=new Map,this._inputsWithInvalidSwitchValue=new Set,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new f,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,relatedRecordCallbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,relatedRecordCallbacks:n}=this;i&&n?.addRelatedRecord&&n.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._handleInputInput=e=>{this._saveValueFromComponent(e.currentTarget)},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupClick=this._onGroupClick.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._handleNumberInputMouseDown=this._handleNumberInputMouseDown.bind(this)}initialize(){this.addHandles([o((()=>this.feature),(()=>{const e=this._getFocusableInput("forward");this._focusedFieldName=e?.name||"",this._inputsWithChanges.clear(),this._inputsWithInvalidCodedValue.clear(),this._inputsWithInvalidSwitchValue.clear(),this._dateComponentMap.clear(),this._attemptFocusOnNextRender=!0})),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._inputsWithChanges.add(e))),this._focusedFieldName=t,this._attemptFocusOnNextRender=!0,this.scheduleRender()}})),o((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange()))])}loadDependencies(){return C({button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox.js"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker.js"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message.js"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),progress:()=>import("@esri/calcite-components/dist/components/calcite-progress.js"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch.js")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const e=this.relatedRecordCallbacks;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get relatedRecordCallbacks(){return this.viewModel.relatedRecordCallbacks}set relatedRecordCallbacks(e){this.viewModel.relatedRecordCallbacks=e}get relationshipId(){return this.viewModel.relationshipId}set relationshipId(e){this.viewModel.relationshipId=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get view(){return n(L,"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view}set view(e){n(L,"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view=e}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return I("div",{class:this.classes(d.base,d.widget,d.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return I("form",{class:d.form,novalidate:!0,onsubmit:this._onFormSubmit,onkeydown:this._onFormKeyDown},this._renderHeader(),this._renderContent())}_renderHeader(){const e=this.viewModel;if(!e.formHeaderVisible)return;const t=null!=e.formTitle&&I(y,{key:"title",level:this.headingLevel},e.formTitle),i=null!=e.formDescription&&I("p",{class:d.description,key:"description"},e.formDescription);return I("div",{class:d.formHeader},t,i)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderActiveRelationshipInput(e.activeRelationshipInput):e.inputs.filter(t).filter((e=>e.visible)).map(((e,t)=>u(e)?this._renderGroup(e,t):c(e)?this._renderLabeledField(e):p(e)?this._renderRelationshipInput(e):void 0))}_renderActiveRelationshipInput(e){return this._renderRelationshipInput(e)}_renderDescriptionOrEmpty(e,t){return null==e?null:I("div",{class:this.classes(d.description),id:t},e)}_renderGroup(e,t){const{formTemplate:i,disabled:n}=this,{description:s,inputs:o,label:a,state:l}=e,r=o.filter((e=>e.visible)),u=this.viewModel.findField(this._focusedFieldName),m=!(!u||u.group!==e),h=`${this.id}_group_${t}`,v=`${this.id}_group-label_${t}`,_=`${this.id}_group-description_${t}`,b=this._renderDescriptionOrEmpty(s,_),g="sequential"===this.groupDisplay,f=g?m:"expanded"===l,C=f?d.collapseIcon:d.expandIcon;return I("fieldset",{"aria-expanded":f.toString(),"aria-labelledby":v,"aria-describedby":s?_:"",class:this.classes(d.group,g?d.groupSequential:null,f?null:d.groupCollapsed,m?d.groupActive:null,n?d.inputDisabled:null),disabled:n,"data-group":e,id:h,key:t,onclick:this._onGroupClick},I("button",{role:g?"presentation":void 0,class:d.groupHeader,type:"button",tabIndex:g?-1:0},I("div",{class:d.groupTitle},I(y,{class:d.groupLabel,id:v,level:null!=i&&i.title?F(this.headingLevel):this.headingLevel},a),b),g?null:I("span",{class:this.classes(C,d.groupToggleIcon)})),r.map((e=>c(e)?this._renderLabeledField(e):p(e)?this._renderRelationshipInput(e):void 0)))}_getFocusableInput(e,t){const i=this.viewModel.allFieldInputs,n="forward"===e?i:i.slice().reverse();let s;if(!t||p(t))s=0;else if(u(t)){const e=t.inputs.find(c);s=e?n.indexOf(e):0}else{let i;if(m(t)&&"collapsed"===t.group.state){const n=t.group.inputs.filter(c);i="forward"===e?n.at(-1):n[0]}else i=t;s=n.indexOf(i)+1}for(let o=s;o<n.length;o++){const e=n[o];if(e.visible&&c(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:n,layer:s}=e;return I("label",{key:`${s.id}-${i.uid}-${e.name}`,class:d.label},[n,"unsupported"!==t?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e)])}_renderFieldInput(e){const{dataType:t,domain:i,element:n,inputType:s,name:o,updating:a,value:l}=e,r=this.getCommonInputProps(e);if("coded-value"===i?.type){if(h(n,"switch")){if(!(this._inputsWithInvalidSwitchValue.has(o)||null==l||n.input.onValue!==l&&n.input.offValue!==l))return this._renderSwitchComponent(e,r);this._inputsWithInvalidSwitchValue.add(o)}return"radio-buttons"===s?this._renderRadioButtonComponents(e,i.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),r):this._renderComboBoxComponent(e,this._getFieldValueOptions(o,i),r)}if("datetime-picker"===s||"date"===t)return this._renderDateComponents(e,r);const u="number"===t?I("input",{type:"number",...r,value:null!=this._activeNumberFieldEdit&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${r.value}`}):"text-area"===s?I("textarea",{...r}):I("input",{type:"text",...r});return a?I("div",{key:`${r.key}-input-updating-wrapper`,class:d.fieldInputWrapper},u,I("div",{class:d.fieldInputLoader},I("calcite-progress",{type:"indeterminate"}))):u}_renderDateComponents(e,t){const{dateDataType:i,includeTime:n,label:s,name:o,valid:a,value:l}=e,{class:r,max:u,min:c,key:p,readOnly:m,required:h}=t;if("string"===i)return this._renderReadOnlyComponent(e,v(e.field,t.value));const{date:_,time:b}=this._formatValueForDateInputs(l),g=null!=u?this._formatValueForDateInputs(u):void 0,f=null!=c?this._formatValueForDateInputs(c):void 0,C=g?.date??void 0,y=f?.date??void 0,F={afterCreate:this._afterDateComponentCreateOrUpdate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!a,label:s,numberingSystem:x,overlayPositioning:"fixed",readOnly:m,required:h,tabIndex:0,[D]:o};return I("div",{key:`${p}-date-time-container`,class:d.dateInputContainer},I("calcite-input-date-picker",{bind:this,...F,class:this.classes(r,d.inputDate),"data-date-part":"date",key:`${p}-date-input`,valueAsDate:_??void 0,maxAsDate:C,minAsDate:y,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target),onblur:e=>this._saveValueFromDateComponent(e.target,!0)}),n?I("calcite-input-time-picker",{bind:this,...F,class:this.classes(r,d.inputTime),"data-date-part":"time",key:`${p}-time-input`,value:b??void 0,step:1,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target),onfocus:e=>{e.target.calciteTimePickerEl&&(e.target.calciteTimePickerEl.showSecond=!0)},onblur:e=>this._saveValueFromDateComponent(e.target,!0)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return I("input",{afterCreate:i.afterCreate,afterUpdate:i.afterUpdate,class:this.classes(d.input,d.fieldInput,d.inputDisabled),onfocus:i.onfocus,readOnly:!0,tabIndex:i.tabIndex,type:"text",value:null!=t?`${t}`:i.value,[D]:i[D]})}_renderComboBoxComponent(e,t,i){const{element:n,required:s,value:o,name:a}=e,{messages:l,messagesTemplates:r,viewModel:d,_inputsWithChanges:u}=this,c=t.map((e=>e.map((({name:e,value:t})=>I("calcite-combobox-item",{key:`#${t}`,selected:o===t,textLabel:e,value:`${t}`}))))),[p,m]=c;this._registerIncompatibleValue(o,t.flat(),e,(e=>{m.unshift(I("calcite-combobox-item",{key:"incompatible-option",readOnly:!0,textLabel:`${e}`,value:`${e}`}))}));const v=m.length>0?[I("calcite-combobox-item-group",{key:"recommended",label:l.recommended},p),I("calcite-combobox-item-group",{key:"other",label:r.other},m)]:p,_=null==n,b=h(n,"combo-box"),g=_||b&&n.input?.showNoValueOption,f="INSERT"===d.arcadeEditType,C=u.has(a),y=null==o&&(!f||C);if(!s&&g){const e="",t=b&&n.input.noValueOptionLabel||l.empty;v.unshift(I("calcite-combobox-item",{value:e,textLabel:l.empty,selected:y,key:"empty-option"},t))}return I("calcite-combobox",{...i,selectionMode:"single",disabled:i.readOnly,allowCustomValues:!1,clearDisabled:!0,onCalciteComboboxChange:({target:e})=>{y&&0===e.selectedItems.length?this._ignoreDeselectionOfNoValueOption(e):this._saveValueFromComponent(e)}},v)}_registerIncompatibleValue(e,t,{name:i},n){const s=this._inputsWithInvalidCodedValue,o=s.has(i);(o||null!=e&&""!==e&&!t.some((t=>t.value===e)))&&(o||s.set(i,e),n?.(e))}_renderRadioButtonComponents(e,t,i){const{element:n,name:s,required:o,value:a}=e,l=t.map((({name:e,value:t})=>this._renderRadioButtonComponent({key:e,label:e,name:s,value:t,selected:t===a,props:i})));this._registerIncompatibleValue(a,t,e);const r=null==n,u=h(n,"radio-buttons"),c=r||u&&n.input?.showNoValueOption;if(!o&&c){const e="",t=u&&n.input.noValueOptionLabel||this.messages.empty,o=a===e||null===a;l.unshift(this._renderRadioButtonComponent({key:"empty-option",label:t,name:s,value:e,selected:o,props:i}))}return I("div",{key:`${i.key}-radio`,class:d.inputRadioGroup},l)}_renderSwitchComponent(e,t){const{value:i}=e,n=!!h(e.element,"switch")&&i===e.element.input.onValue;return I("calcite-switch",{...t,class:d.inputSwitch,onCalciteSwitchChange:e=>this._saveValueFromComponent(e.target),checked:n,disabled:t.readOnly})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:n,label:s,props:o}){return I("label",{key:e,class:d.inputRadioLabel},I("input",{...o,class:d.inputRadio,name:t,type:"radio",value:`${i}`,checked:n,disabled:o.readOnly,onchange:e=>this._saveValueFromComponent(e.target)}),s)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.valid?_(e,this.messages):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?I("calcite-input-message",{status:"invalid",icon:!0},i):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:n}=e,{relatedRecordCallbacks:s}=this;if(!n||!s?.showAllRelatedRecords)return;const o=this.messages;return I("calcite-list-item",{description:V(o.totalCount,{count:t}),label:o.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},I("calcite-icon",{slot:"content-end",scale:"s",icon:"list"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:n}=e,{relatedRecordCallbacks:s}=this;if(t&&s?.addRelatedRecord&&n)return I("calcite-button",{alignment:"center",appearance:"outline-fill",class:d.centeredButton,disabled:e.updating,iconStart:"plus",key:`${i}-add-button`,round:!0,scale:"s",width:"half",onclick:()=>this._onAddRelatedRecordsClick(i,n)},this.messages.addRecord)}_renderRelatedRecordListItem(e,t){const{feature:i,description:n,title:s}=e,{feature:o,relatedRecordCallbacks:a}=this,l=()=>{a?.editRelatedRecord&&o&&a.editRelatedRecord({parentFeature:o,relationshipId:t,relatedFeature:i})};return I("calcite-list-item",{bind:this,description:n,label:s,key:`${t}-${i.uid}`,value:s,onclick:l},I("calcite-icon",{slot:"content-start",scale:"m",icon:b(i)}),I("calcite-icon",{slot:"content-end",scale:"s",icon:"chevron-right"}))}_renderRelationshipInput(e){if(!this._relatedRecordsEnabled||!e.editable)return;const{featureCount:t,relationshipId:i,showAllEnabled:n}=e,s=n?null:this._renderDescriptionOrEmpty(e.description),o=t>0?this._renderRelatedRecordsList(e):e.loaded?this._renderNoRelatedRecordsNotice():void 0;return I("label",{class:this.classes(d.label,d.relationshipLabel),key:`relationship-${i}-container`},I("div",null,this._renderRelatedRecordsHeaderContainer(e),s,o),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return I("div",{class:d.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},I("span",null,e.label),t?I("calcite-loader",{label:this.messagesCommon?.loading,inline:!0,key:"loader",scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return I("calcite-list",{class:d.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoRelatedRecordsNotice(){return I("calcite-notice",{open:!0,scale:"s",kind:"brand",icon:"information",width:"full"},I("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return I("div",{key:"feature-observer",class:d.listObserver,bind:this,afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved})}getCommonInputProps(e){const{disabled:t,groupDisplay:i}=this,{dataType:n,editable:s,group:o,hint:a,label:l,maxLength:r,minLength:u,name:c,required:p,valid:m,value:h}=e,v=this._inputsWithChanges.has(c),_=!s||t,b="all"===i&&null!=o&&"collapsed"===o.state;return{afterCreate:this._afterComponentCreateOrUpdate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":m?"false":"true",class:this.classes(d.input,d.fieldInput,_?d.inputDisabled:null,v&&!m?d.inputInvalid:null),key:c,label:l,minlength:u>-1?`${u}`:"",maxlength:r>-1?`${r}`:"",...e.range,readOnly:_,value:null==h?"":`${h}`,[D]:c,onfocus:this._onComponentFocus,oninput:this._handleInputInput,onblur:this._onComponentBlur,onkeydown:this._onComponentKeyDown,onmousedown:"number"===n?this._handleNumberInputMouseDown:void 0,placeholder:"number"===n||"text"===n?a??void 0:"",required:p,tabIndex:b?-1:0}}_handleNumberInputMouseDown({target:e}){e.focus(),this.scheduleRender()}_getFieldValueOptions(e,t){const i=t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),n=this.viewModel.fieldsWithContingentValues.has(e)?this._getContingentValueOptions(e):[];if(n.length>0){const e=new Set(n.map((e=>e.value)));return[n,i.filter((t=>!e.has(t.value)))]}return[i,[]]}_getContingentValueOptions(e){const t={};for(const s of this.viewModel.allFieldInputs){const{name:i,value:n}=s;null!=n&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=n)}const i=this.viewModel.joinedContingentValues.slice(),n=new Map;for(const s of i){const i=s.values[e];if(null==i||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:o,name:a}=i.codedValue&&"null"!==i.objectType?i.codedValue:{code:"",name:this.messages.empty};if(n.has(o))continue;Object.entries(t).every((([e,t])=>!s.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,s.values[e])))&&n.set(o,{name:a,value:o})}return[...n.values()]}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(D))}_afterDateComponentCreateOrUpdate(e){const{name:t}=this._getFieldInputFromHTMLElement(e),i=this._dateComponentMap.get(t),n=T(e);null!=i?n?i.date=e:i.time=e:this._dateComponentMap.set(t,{[n?"date":"time"]:e}),this._afterComponentCreateOrUpdate(e)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),n=t.findField(this._focusedFieldName),s=this._inputsWithInvalidCodedValue.get(i.name)===i.value;this._attemptFocusOnNextRender&&n===i&&("radio-buttons"!==i.inputType||s||e.checked)&&(this._attemptFocusOnNextRender=!1,m(i)&&(i.group.state="expanded"),e.focus())}_onComponentFocus(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);this._focusedFieldName=i.name,g(i)&&(this._activeNumberFieldEdit={fieldName:i.name,input:t,value:t.value})}_onComponentBlur(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);"number"===i.dataType&&null!=this._activeNumberFieldEdit&&(this._activeNumberFieldEdit.input.value=`${i.value}`,this._activeNumberFieldEdit=null),this._saveValueFromComponent(t),this.scheduleRender()}_saveValueFromDateComponent(e,t=!1){const{name:i}=this._getFieldInputFromHTMLElement(e);if(!this._dateComponentMap.has(i))return;const n=this._dateComponentMap.get(i);if(!n||!n.date)return;const s=this._getFieldValueFromDateComponent(e),o=this._getFieldValueFromDateComponents(n.date,n.time);this.viewModel.getValue(i)!==o&&(null!==s&&null!==o?this._updateFieldValue(i,o):t&&this._updateFieldValue(i,null))}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e);null!=this._activeNumberFieldEdit&&g(t)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(t.name,this._parseValue(e))}_onComponentKeyDown(e){const{key:t,altKey:i,ctrlKey:n,metaKey:s}=e,o=this._getFieldInputFromHTMLElement(e.target);if("Enter"===t)m(o)&&"collapsed"===o.group.state&&(o.group.state="expanded");else{const{type:a}=o.field,l="single"===a||"double"===a;if(("integer"===a||"small-integer"===a||l)&&(!i&&!n&&!s)&&1===t.length){const i=Number(t),n=["-","+"],s=["e","."],o=l?[...n,...s]:n;isNaN(i)&&!o.includes(t)&&e.preventDefault()}}}_updateFieldValue(e,t){if(this.viewModel.setValue(e,t),this._inputsWithChanges.add(e),this.viewModel.fieldsWithContingentValues.has(e)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>null!=t)));this.viewModel.validateContingencyConstraints(e)}}_parseValue(e){const t=this._getFieldInputFromHTMLElement(e),i=e.value;if(h(t.element,"switch")&&"CALCITE-COMBOBOX"!==e.tagName)return e.checked?t.element.input.onValue:t.element.input.offValue;return"radio-buttons"===t.inputType&&"radio"===e.type&&!e.checked?t.value:"number"===t.dataType?i?parseFloat(i):null:i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:i}=e;0===i.length&&t&&"selected"in t?t.selected=!0:L.warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupClick(e){const t=e.currentTarget["data-group"],i="expanded"===t.state,n="sequential"===this.groupDisplay,s=`.${d.groupHeader}`;if(!(i&&!e.target.closest(s))){if(this._focusedFieldName=this._getFocusableInput("forward",t)?.name||"",n){const n=e.target.closest(s);if(i&&!n)return;this.viewModel.inputs.forEach((e=>{u(e)&&e!==t&&(e.state="collapsed")}))}t.state=i?"collapsed":"expanded",this._attemptFocusOnNextRender=n,this.scheduleRender()}}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_getDefaultLocaleOptions(){return{locale:M(),numberingSystem:x}}_getFieldValueFromDateComponents(e,t){const i=this._getDateTimeFromComponent(e),n=this._getDateTimeFromComponent(t);if(!i&&!n)return null;const s=this._getFieldInputFromHTMLElement(e).range,o=Date.now(),a=null!=s.max&&s.max<o?s.max:o,l=O.fromMillis(a,this._getDefaultLocaleOptions()),r=i||l,{year:d,month:u,day:c}=r,{hour:p,minute:m,second:h}=n||l,v=r.set({year:d,month:u,day:c,hour:p,minute:m,second:h});return v.isValid?v.toMillis():null}_getDateTimeFromComponent(e){if(!e)return null;let t=null;if(T(e)){const i=e.valueAsDate;if(!i||Array.isArray(i))return null;t=O.fromJSDate(i)}else{if(!e.value)return null;t=O.fromFormat(e.value,k,this._getDefaultLocaleOptions())}return t??null}_getFieldValueFromDateComponent(e){return this._dateTimeToFieldValue(this._getDateTimeFromComponent(e))}_dateTimeToFieldValue(e){return e?.isValid?e.toMillis():null}_dateTimeFromFieldValue(e){return null===e?null:O.fromMillis(e,this._getDefaultLocaleOptions())}_formatValueForDateInputs(e){if(null==e||isNaN(e))return{date:null,time:null};const t=this._dateTimeFromFieldValue(e);return t?{date:t.toJSDate(),time:t.toFormat(k,this._getDefaultLocaleOptions())}:{date:null,time:null}}_valueIsValidContingentValue(e,t){switch(t.objectType){case"any":return!0;case"null":return null==e;case"code":return e===t.codedValue?.code;case"range":return null!=e&&null!=t.minValue&&null!=t.maxValue&&+e>=t.minValue&&+e<=t.maxValue;default:return i(t.objectType),!1}}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}async _onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;if(!e)return;const{showAllEnabled:t,updating:i}=e;this._listObserverNode&&!i&&t&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}};e([a()],E.prototype,"_listObserverNode",void 0),e([a()],E.prototype,"_relatedRecordsEnabled",null),e([a()],E.prototype,"disabled",null),e([a()],E.prototype,"feature",null),e([a()],E.prototype,"formTemplate",null),e([a()],E.prototype,"groupDisplay",void 0),e([a()],E.prototype,"headingLevel",void 0),e([a()],E.prototype,"label",null),e([a()],E.prototype,"layer",null),e([a()],E.prototype,"map",null),e([a(),w("esri/widgets/FeatureForm/t9n/FeatureForm")],E.prototype,"messages",void 0),e([a(),w("esri/t9n/common")],E.prototype,"messagesCommon",void 0),e([a(),w("esri/widgets/Feature/t9n/Feature")],E.prototype,"messagesFeature",void 0),e([a(),w("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],E.prototype,"messagesTemplates",void 0),e([a()],E.prototype,"relatedRecordCallbacks",null),e([a()],E.prototype,"relationshipId",null),e([a()],E.prototype,"spatialReference",null),e([a()],E.prototype,"strict",null),e([a()],E.prototype,"view",null),e([a(),R(["value-change","submit"])],E.prototype,"viewModel",void 0),E=e([l(N)],E);const j=E;export{j as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import{neverReached as i}from"../core/compilerUtils.js";import{deprecatedProperty as n}from"../core/deprecate.js";import s from"../core/Logger.js";import{watch as o}from"../core/reactiveUtils.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import r from"./Widget.js";import{CSS as d}from"./FeatureForm/css.js";import{isGroupInput as u,isFieldInput as c,isRelationshipInput as p,isInputInGroupInput as m,isFieldElementWithInputType as h,formatDateFieldValue as v,getErrorMessageForFieldInput as _,getIconForFeature as b,isNumberFieldInput as g}from"./FeatureForm/featureFormUtils.js";import f from"./FeatureForm/FeatureFormViewModel.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{Heading as y,incrementHeadingLevel as F}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as w}from"./support/decorators/messageBundle.js";import{vmEvent as R}from"./support/decorators/vmEvent.js";import{tsx as I}from"./support/jsxFactory.js";import{DateTime as O}from"luxon";import{substitute as V}from"../intl/substitute.js";import{getLocale as M}from"../intl/locale.js";const k="TT",D="data-field-name",x="latn",T=e=>"valueAsDate"in e,N="esri.widgets.FeatureForm",L=s.getLogger(N);let E=class extends r{constructor(e,t){super(e,t),this._activeNumberFieldEdit=null,this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName="",this._inputsWithInvalidCodedValue=new Map,this._inputsWithInvalidSwitchValue=new Set,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new f,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,relatedRecordCallbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,relatedRecordCallbacks:n}=this;i&&n?.addRelatedRecord&&n.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._handleInputInput=e=>{this._saveValueFromComponent(e.currentTarget)},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupClick=this._onGroupClick.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._handleNumberInputMouseDown=this._handleNumberInputMouseDown.bind(this)}initialize(){this.addHandles([o((()=>this.feature),(()=>{const e=this._getFocusableInput("forward");this._focusedFieldName=e?.name||"",this._inputsWithChanges.clear(),this._inputsWithInvalidCodedValue.clear(),this._inputsWithInvalidSwitchValue.clear(),this._dateComponentMap.clear(),this._attemptFocusOnNextRender=!0})),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._inputsWithChanges.add(e))),this._focusedFieldName=t,this._attemptFocusOnNextRender=!0,this.scheduleRender()}})),o((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange()))])}loadDependencies(){return C({button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox.js"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker.js"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message.js"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),progress:()=>import("@esri/calcite-components/dist/components/calcite-progress.js"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch.js")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const e=this.relatedRecordCallbacks;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get relatedRecordCallbacks(){return this.viewModel.relatedRecordCallbacks}set relatedRecordCallbacks(e){this.viewModel.relatedRecordCallbacks=e}get relationshipId(){return this.viewModel.relationshipId}set relationshipId(e){this.viewModel.relationshipId=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get view(){return n(L,"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view}set view(e){n(L,"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view=e}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return I("div",{class:this.classes(d.base,d.widget,d.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return I("form",{class:d.form,novalidate:!0,onsubmit:this._onFormSubmit,onkeydown:this._onFormKeyDown},this._renderHeader(),this._renderContent())}_renderHeader(){const e=this.viewModel;if(!e.formHeaderVisible)return;const t=null!=e.formTitle&&I(y,{key:"title",level:this.headingLevel},e.formTitle),i=null!=e.formDescription&&I("p",{class:d.description,key:"description"},e.formDescription);return I("div",{class:d.formHeader},t,i)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderActiveRelationshipInput(e.activeRelationshipInput):e.inputs.filter(t).filter((e=>e.visible)).map(((e,t)=>u(e)?this._renderGroup(e,t):c(e)?this._renderLabeledField(e):p(e)?this._renderRelationshipInput(e):void 0))}_renderActiveRelationshipInput(e){return this._renderRelationshipInput(e)}_renderDescriptionOrEmpty(e,t){return null==e?null:I("div",{class:this.classes(d.description),id:t},e)}_renderGroup(e,t){const{formTemplate:i,disabled:n}=this,{description:s,inputs:o,label:a,state:l}=e,r=o.filter((e=>e.visible)),u=this.viewModel.findField(this._focusedFieldName),m=!(!u||u.group!==e),h=`${this.id}_group_${t}`,v=`${this.id}_group-label_${t}`,_=`${this.id}_group-description_${t}`,b=this._renderDescriptionOrEmpty(s,_),g="sequential"===this.groupDisplay,f=g?m:"expanded"===l,C=f?d.collapseIcon:d.expandIcon;return I("fieldset",{"aria-expanded":f.toString(),"aria-labelledby":v,"aria-describedby":s?_:"",class:this.classes(d.group,g?d.groupSequential:null,f?null:d.groupCollapsed,m?d.groupActive:null,n?d.inputDisabled:null),disabled:n,"data-group":e,id:h,key:t,onclick:this._onGroupClick},I("button",{role:g?"presentation":void 0,class:d.groupHeader,type:"button",tabIndex:g?-1:0},I("div",{class:d.groupTitle},I(y,{class:d.groupLabel,id:v,level:null!=i&&i.title?F(this.headingLevel):this.headingLevel},a),b),g?null:I("span",{class:this.classes(C,d.groupToggleIcon)})),r.map((e=>c(e)?this._renderLabeledField(e):p(e)?this._renderRelationshipInput(e):void 0)))}_getFocusableInput(e,t){const i=this.viewModel.allFieldInputs,n="forward"===e?i:i.slice().reverse();let s;if(!t||p(t))s=0;else if(u(t)){const e=t.inputs.find(c);s=e?n.indexOf(e):0}else{let i;if(m(t)&&"collapsed"===t.group.state){const n=t.group.inputs.filter(c);i="forward"===e?n[n.length-1]:n[0]}else i=t;s=n.indexOf(i)+1}for(let o=s;o<n.length;o++){const e=n[o];if(e.visible&&c(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:n,layer:s}=e;return I("label",{key:`${s.id}-${i.uid}-${e.name}`,class:d.label},[n,"unsupported"!==t?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e)])}_renderFieldInput(e){const{dataType:t,domain:i,element:n,inputType:s,name:o,updating:a,value:l}=e,r=this.getCommonInputProps(e);if("coded-value"===i?.type){if(h(n,"switch")){if(!(this._inputsWithInvalidSwitchValue.has(o)||null==l||n.input.onValue!==l&&n.input.offValue!==l))return this._renderSwitchComponent(e,r);this._inputsWithInvalidSwitchValue.add(o)}return"radio-buttons"===s?this._renderRadioButtonComponents(e,i.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),r):this._renderComboBoxComponent(e,this._getFieldValueOptions(o,i),r)}if("datetime-picker"===s||"date"===t)return this._renderDateComponents(e,r);const u="number"===t?I("input",{type:"number",...r,value:null!=this._activeNumberFieldEdit&&this._activeNumberFieldEdit.fieldName===e.name?this._activeNumberFieldEdit.value:`${r.value}`}):"text-area"===s?I("textarea",{...r}):I("input",{type:"text",...r});return a?I("div",{key:`${r.key}-input-updating-wrapper`,class:d.fieldInputWrapper},u,I("div",{class:d.fieldInputLoader},I("calcite-progress",{type:"indeterminate"}))):u}_renderDateComponents(e,t){const{dateDataType:i,includeTime:n,label:s,name:o,valid:a,value:l}=e,{class:r,max:u,min:c,key:p,readOnly:m,required:h}=t;if("string"===i)return this._renderReadOnlyComponent(e,v(e.field,t.value));const{date:_,time:b}=this._formatValueForDateInputs(l),g=null!=u?this._formatValueForDateInputs(u):void 0,f=null!=c?this._formatValueForDateInputs(c):void 0,C=g?.date??void 0,y=f?.date??void 0,F={afterCreate:this._afterDateComponentCreateOrUpdate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!a,label:s,numberingSystem:x,overlayPositioning:"fixed",readOnly:m,required:h,tabIndex:0,[D]:o};return I("div",{key:`${p}-date-time-container`,class:d.dateInputContainer},I("calcite-input-date-picker",{bind:this,...F,class:this.classes(r,d.inputDate),"data-date-part":"date",key:`${p}-date-input`,valueAsDate:_??void 0,maxAsDate:C,minAsDate:y,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target),onblur:e=>this._saveValueFromDateComponent(e.target,!0)}),n?I("calcite-input-time-picker",{bind:this,...F,class:this.classes(r,d.inputTime),"data-date-part":"time",key:`${p}-time-input`,value:b??void 0,step:1,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target),onfocus:e=>{e.target.calciteTimePickerEl&&(e.target.calciteTimePickerEl.showSecond=!0)},onblur:e=>this._saveValueFromDateComponent(e.target,!0)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return I("input",{afterCreate:i.afterCreate,afterUpdate:i.afterUpdate,class:this.classes(d.input,d.fieldInput,d.inputDisabled),onfocus:i.onfocus,readOnly:!0,tabIndex:i.tabIndex,type:"text",value:null!=t?`${t}`:i.value,[D]:i[D]})}_renderComboBoxComponent(e,t,i){const{element:n,required:s,value:o,name:a}=e,{messages:l,messagesTemplates:r,viewModel:d,_inputsWithChanges:u}=this,c=t.map((e=>e.map((({name:e,value:t})=>I("calcite-combobox-item",{key:`#${t}`,selected:o===t,textLabel:e,value:`${t}`}))))),[p,m]=c;this._registerIncompatibleValue(o,t.flat(),e,(e=>{m.unshift(I("calcite-combobox-item",{key:"incompatible-option",readOnly:!0,textLabel:`${e}`,value:`${e}`}))}));const v=m.length>0?[I("calcite-combobox-item-group",{key:"recommended",label:l.recommended},p),I("calcite-combobox-item-group",{key:"other",label:r.other},m)]:p,_=null==n,b=h(n,"combo-box"),g=_||b&&n.input?.showNoValueOption,f="INSERT"===d.arcadeEditType,C=u.has(a),y=null==o&&(!f||C);if(!s&&g){const e="",t=b&&n.input.noValueOptionLabel||l.empty;v.unshift(I("calcite-combobox-item",{value:e,textLabel:l.empty,selected:y,key:"empty-option"},t))}return I("calcite-combobox",{...i,selectionMode:"single",disabled:i.readOnly,allowCustomValues:!1,clearDisabled:!0,onCalciteComboboxChange:({target:e})=>{y&&0===e.selectedItems.length?this._ignoreDeselectionOfNoValueOption(e):this._saveValueFromComponent(e)}},v)}_registerIncompatibleValue(e,t,{name:i},n){const s=this._inputsWithInvalidCodedValue,o=s.has(i);(o||null!=e&&""!==e&&!t.some((t=>t.value===e)))&&(o||s.set(i,e),n?.(e))}_renderRadioButtonComponents(e,t,i){const{element:n,name:s,required:o,value:a}=e,l=t.map((({name:e,value:t})=>this._renderRadioButtonComponent({key:e,label:e,name:s,value:t,selected:t===a,props:i})));this._registerIncompatibleValue(a,t,e);const r=null==n,u=h(n,"radio-buttons"),c=r||u&&n.input?.showNoValueOption;if(!o&&c){const e="",t=u&&n.input.noValueOptionLabel||this.messages.empty,o=a===e||null===a;l.unshift(this._renderRadioButtonComponent({key:"empty-option",label:t,name:s,value:e,selected:o,props:i}))}return I("div",{key:`${i.key}-radio`,class:d.inputRadioGroup},l)}_renderSwitchComponent(e,t){const{value:i}=e,n=!!h(e.element,"switch")&&i===e.element.input.onValue;return I("calcite-switch",{...t,class:d.inputSwitch,onCalciteSwitchChange:e=>this._saveValueFromComponent(e.target),checked:n,disabled:t.readOnly})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:n,label:s,props:o}){return I("label",{key:e,class:d.inputRadioLabel},I("input",{...o,class:d.inputRadio,name:t,type:"radio",value:`${i}`,checked:n,disabled:o.readOnly,onchange:e=>this._saveValueFromComponent(e.target)}),s)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.valid?_(e,this.messages):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?I("calcite-input-message",{status:"invalid",icon:!0},i):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:n}=e,{relatedRecordCallbacks:s}=this;if(!n||!s?.showAllRelatedRecords)return;const o=this.messages;return I("calcite-list-item",{description:V(o.totalCount,{count:t}),label:o.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},I("calcite-icon",{slot:"content-end",scale:"s",icon:"list"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:n}=e,{relatedRecordCallbacks:s}=this;if(t&&s?.addRelatedRecord&&n)return I("calcite-button",{alignment:"center",appearance:"outline-fill",class:d.centeredButton,disabled:e.updating,iconStart:"plus",key:`${i}-add-button`,round:!0,scale:"s",width:"half",onclick:()=>this._onAddRelatedRecordsClick(i,n)},this.messages.addRecord)}_renderRelatedRecordListItem(e,t){const{feature:i,description:n,title:s}=e,{feature:o,relatedRecordCallbacks:a}=this,l=()=>{a?.editRelatedRecord&&o&&a.editRelatedRecord({parentFeature:o,relationshipId:t,relatedFeature:i})};return I("calcite-list-item",{bind:this,description:n,label:s,key:`${t}-${i.uid}`,value:s,onclick:l},I("calcite-icon",{slot:"content-start",scale:"m",icon:b(i)}),I("calcite-icon",{slot:"content-end",scale:"s",icon:"chevron-right"}))}_renderRelationshipInput(e){if(!this._relatedRecordsEnabled||!e.editable)return;const{featureCount:t,relationshipId:i,showAllEnabled:n}=e,s=n?null:this._renderDescriptionOrEmpty(e.description),o=t>0?this._renderRelatedRecordsList(e):e.loaded?this._renderNoRelatedRecordsNotice():void 0;return I("label",{class:this.classes(d.label,d.relationshipLabel),key:`relationship-${i}-container`},I("div",null,this._renderRelatedRecordsHeaderContainer(e),s,o),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return I("div",{class:d.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},I("span",null,e.label),t?I("calcite-loader",{label:this.messagesCommon?.loading,inline:!0,key:"loader",scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return I("calcite-list",{class:d.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoRelatedRecordsNotice(){return I("calcite-notice",{open:!0,scale:"s",kind:"brand",icon:"information",width:"full"},I("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return I("div",{key:"feature-observer",class:d.listObserver,bind:this,afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved})}getCommonInputProps(e){const{disabled:t,groupDisplay:i}=this,{dataType:n,editable:s,group:o,hint:a,label:l,maxLength:r,minLength:u,name:c,required:p,valid:m,value:h}=e,v=this._inputsWithChanges.has(c),_=!s||t,b="all"===i&&null!=o&&"collapsed"===o.state;return{afterCreate:this._afterComponentCreateOrUpdate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":m?"false":"true",class:this.classes(d.input,d.fieldInput,_?d.inputDisabled:null,v&&!m?d.inputInvalid:null),key:c,label:l,minlength:u>-1?`${u}`:"",maxlength:r>-1?`${r}`:"",...e.range,readOnly:_,value:null==h?"":`${h}`,[D]:c,onfocus:this._onComponentFocus,oninput:this._handleInputInput,onblur:this._onComponentBlur,onkeydown:this._onComponentKeyDown,onmousedown:"number"===n?this._handleNumberInputMouseDown:void 0,placeholder:"number"===n||"text"===n?a??void 0:"",required:p,tabIndex:b?-1:0}}_handleNumberInputMouseDown({target:e}){e.focus(),this.scheduleRender()}_getFieldValueOptions(e,t){const i=t.codedValues.map((({code:e,name:t})=>({value:e,name:t}))),n=this.viewModel.fieldsWithContingentValues.has(e)?this._getContingentValueOptions(e):[];if(n.length>0){const e=new Set(n.map((e=>e.value)));return[n,i.filter((t=>!e.has(t.value)))]}return[i,[]]}_getContingentValueOptions(e){const t={};for(const s of this.viewModel.allFieldInputs){const{name:i,value:n}=s;null!=n&&i!==e&&this.viewModel.fieldsWithContingentValues.has(i)&&(t[i]=n)}const i=this.viewModel.joinedContingentValues.slice(),n=new Map;for(const s of i){const i=s.values[e];if(null==i||"code"!==i.objectType&&"null"!==i.objectType)continue;const{code:o,name:a}=i.codedValue&&"null"!==i.objectType?i.codedValue:{code:"",name:this.messages.empty};if(n.has(o))continue;Object.entries(t).every((([e,t])=>!s.values.hasOwnProperty(e)||this._valueIsValidContingentValue(t,s.values[e])))&&n.set(o,{name:a,value:o})}return[...n.values()]}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(D))}_afterDateComponentCreateOrUpdate(e){const{name:t}=this._getFieldInputFromHTMLElement(e),i=this._dateComponentMap.get(t),n=T(e);null!=i?n?i.date=e:i.time=e:this._dateComponentMap.set(t,{[n?"date":"time"]:e}),this._afterComponentCreateOrUpdate(e)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),n=t.findField(this._focusedFieldName),s=this._inputsWithInvalidCodedValue.get(i.name)===i.value;this._attemptFocusOnNextRender&&n===i&&("radio-buttons"!==i.inputType||s||e.checked)&&(this._attemptFocusOnNextRender=!1,m(i)&&(i.group.state="expanded"),e.focus())}_onComponentFocus(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);this._focusedFieldName=i.name,g(i)&&(this._activeNumberFieldEdit={fieldName:i.name,input:t,value:t.value})}_onComponentBlur(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);"number"===i.dataType&&null!=this._activeNumberFieldEdit&&(this._activeNumberFieldEdit.input.value=`${i.value}`,this._activeNumberFieldEdit=null),this._saveValueFromComponent(t),this.scheduleRender()}_saveValueFromDateComponent(e,t=!1){const{name:i}=this._getFieldInputFromHTMLElement(e);if(!this._dateComponentMap.has(i))return;const n=this._dateComponentMap.get(i);if(!n||!n.date)return;const s=this._getFieldValueFromDateComponent(e),o=this._getFieldValueFromDateComponents(n.date,n.time);this.viewModel.getValue(i)!==o&&(null!==s&&null!==o?this._updateFieldValue(i,o):t&&this._updateFieldValue(i,null))}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e);null!=this._activeNumberFieldEdit&&g(t)&&(this._activeNumberFieldEdit.value=e.value),this._updateFieldValue(t.name,this._parseValue(e))}_onComponentKeyDown(e){const{key:t,altKey:i,ctrlKey:n,metaKey:s}=e,o=this._getFieldInputFromHTMLElement(e.target);if("Enter"===t)m(o)&&"collapsed"===o.group.state&&(o.group.state="expanded");else{const{type:a}=o.field,l="single"===a||"double"===a;if(("integer"===a||"small-integer"===a||l)&&(!i&&!n&&!s)&&1===t.length){const i=Number(t),n=["-","+"],s=["e","."],o=l?[...n,...s]:n;isNaN(i)&&!o.includes(t)&&e.preventDefault()}}}_updateFieldValue(e,t){if(this.viewModel.setValue(e,t),this._inputsWithChanges.add(e),this.viewModel.fieldsWithContingentValues.has(e)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>null!=t)));this.viewModel.validateContingencyConstraints(e)}}_parseValue(e){const t=this._getFieldInputFromHTMLElement(e),i=e.value;if(h(t.element,"switch")&&"CALCITE-COMBOBOX"!==e.tagName)return e.checked?t.element.input.onValue:t.element.input.offValue;return"radio-buttons"===t.inputType&&"radio"===e.type&&!e.checked?t.value:"number"===t.dataType?i?parseFloat(i):null:i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:i}=e;0===i.length&&t&&"selected"in t?t.selected=!0:L.warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupClick(e){const t=e.currentTarget["data-group"],i="expanded"===t.state,n="sequential"===this.groupDisplay,s=`.${d.groupHeader}`;if(!(i&&!e.target.closest(s))){if(this._focusedFieldName=this._getFocusableInput("forward",t)?.name||"",n){const n=e.target.closest(s);if(i&&!n)return;this.viewModel.inputs.forEach((e=>{u(e)&&e!==t&&(e.state="collapsed")}))}t.state=i?"collapsed":"expanded",this._attemptFocusOnNextRender=n,this.scheduleRender()}}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_getDefaultLocaleOptions(){return{locale:M(),numberingSystem:x}}_getFieldValueFromDateComponents(e,t){const i=this._getDateTimeFromComponent(e),n=this._getDateTimeFromComponent(t);if(!i&&!n)return null;const s=this._getFieldInputFromHTMLElement(e).range,o=Date.now(),a=null!=s.max&&s.max<o?s.max:o,l=O.fromMillis(a,this._getDefaultLocaleOptions()),r=i||l,{year:d,month:u,day:c}=r,{hour:p,minute:m,second:h}=n||l,v=r.set({year:d,month:u,day:c,hour:p,minute:m,second:h});return v.isValid?v.toMillis():null}_getDateTimeFromComponent(e){if(!e)return null;let t=null;if(T(e)){const i=e.valueAsDate;if(!i||Array.isArray(i))return null;t=O.fromJSDate(i)}else{if(!e.value)return null;t=O.fromFormat(e.value,k,this._getDefaultLocaleOptions())}return t??null}_getFieldValueFromDateComponent(e){return this._dateTimeToFieldValue(this._getDateTimeFromComponent(e))}_dateTimeToFieldValue(e){return e?.isValid?e.toMillis():null}_dateTimeFromFieldValue(e){return null===e?null:O.fromMillis(e,this._getDefaultLocaleOptions())}_formatValueForDateInputs(e){if(null==e||isNaN(e))return{date:null,time:null};const t=this._dateTimeFromFieldValue(e);return t?{date:t.toJSDate(),time:t.toFormat(k,this._getDefaultLocaleOptions())}:{date:null,time:null}}_valueIsValidContingentValue(e,t){switch(t.objectType){case"any":return!0;case"null":return null==e;case"code":return e===t.codedValue?.code;case"range":return null!=e&&null!=t.minValue&&null!=t.maxValue&&+e>=t.minValue&&+e<=t.maxValue;default:return i(t.objectType),!1}}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}async _onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;if(!e)return;const{showAllEnabled:t,updating:i}=e;this._listObserverNode&&!i&&t&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}};e([a()],E.prototype,"_listObserverNode",void 0),e([a()],E.prototype,"_relatedRecordsEnabled",null),e([a()],E.prototype,"disabled",null),e([a()],E.prototype,"feature",null),e([a()],E.prototype,"formTemplate",null),e([a()],E.prototype,"groupDisplay",void 0),e([a()],E.prototype,"headingLevel",void 0),e([a()],E.prototype,"label",null),e([a()],E.prototype,"layer",null),e([a()],E.prototype,"map",null),e([a(),w("esri/widgets/FeatureForm/t9n/FeatureForm")],E.prototype,"messages",void 0),e([a(),w("esri/t9n/common")],E.prototype,"messagesCommon",void 0),e([a(),w("esri/widgets/Feature/t9n/Feature")],E.prototype,"messagesFeature",void 0),e([a(),w("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],E.prototype,"messagesTemplates",void 0),e([a()],E.prototype,"relatedRecordCallbacks",null),e([a()],E.prototype,"relationshipId",null),e([a()],E.prototype,"spatialReference",null),e([a()],E.prototype,"strict",null),e([a()],E.prototype,"view",null),e([a(),R(["value-change","submit"])],E.prototype,"viewModel",void 0),E=e([l(N)],E);const j=E;export{j as default};