@arcgis/core 4.33.0-next.20250306 → 4.33.0-next.20250307

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 (234) hide show
  1. package/arcade/arcadeAsyncRuntime.js +1 -1
  2. package/arcade/arcadeCompiler.js +1 -1
  3. package/arcade/featureSetUtils.js +1 -1
  4. package/arcade/featureset/actions/GroupBy.js +1 -1
  5. package/arcade/featureset/actions/OrderBy.js +1 -1
  6. package/arcade/functions/aiServices.js +5 -0
  7. package/arcade/functions/date.js +1 -1
  8. package/arcade/functions/feature.js +1 -1
  9. package/arcade/functions/featuresetbase.js +1 -1
  10. package/arcade/functions/featuresetstring.js +1 -1
  11. package/arcade/functions/fieldStats.js +1 -1
  12. package/arcade/functions/geometry.js +1 -1
  13. package/arcade/functions/maths.js +1 -1
  14. package/arcade/functions/string.js +1 -1
  15. package/arcade/languageUtils.js +1 -1
  16. package/arcade/treeAnalysis.js +1 -1
  17. package/arcade.js +1 -1
  18. package/assets/esri/core/workers/RemoteClient.js +1 -1
  19. package/assets/esri/core/workers/chunks/028e2e0fa6971aaaaae8.js +1 -0
  20. package/assets/esri/core/workers/chunks/0576b035c1654a43ad5c.js +1 -0
  21. package/assets/esri/core/workers/chunks/081699532b183db1e7c2.js +1 -0
  22. package/assets/esri/core/workers/chunks/087a09b4c41abef6b516.js +1 -0
  23. package/assets/esri/core/workers/chunks/{7ec2f531217718e76469.js → 0b4e63e705db09dbe171.js} +1 -1
  24. package/assets/esri/core/workers/chunks/0c9e933b392616460e62.js +1 -0
  25. package/assets/esri/core/workers/chunks/{c3d23c45db427a29d596.js → 0f4a2bdf5bb2f4303b7f.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{f995a74bd9b58c069c07.js → 10631680abe7607616ca.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{567aa24d7e99e0b5a6cb.js → 1263391920fbb8926ced.js} +1 -1
  28. package/assets/esri/core/workers/chunks/186387a561364a11e574.js +1 -0
  29. package/assets/esri/core/workers/chunks/1cc7bbd0f4a8cf06050a.js +1 -0
  30. package/assets/esri/core/workers/chunks/1d0473dd43c88ab5776d.js +1 -0
  31. package/assets/esri/core/workers/chunks/{ef46613c3aa363dc1cfc.js → 285e573aa6f3acf70b32.js} +1 -1
  32. package/assets/esri/core/workers/chunks/2bb508701ad8ccc3d6ab.js +1 -0
  33. package/assets/esri/core/workers/chunks/36fe6b8228e622407ec2.js +1 -0
  34. package/assets/esri/core/workers/chunks/37a3533f004bf2e888da.js +1 -0
  35. package/assets/esri/core/workers/chunks/3be465c653236d6d8c1f.js +1 -0
  36. package/assets/esri/core/workers/chunks/3e4204502f6e09483c60.js +1 -0
  37. package/assets/esri/core/workers/chunks/3e9cd82325c473ddbf1f.js +1 -0
  38. package/assets/esri/core/workers/chunks/{370ab4b33fb7292bb3b8.js → 424e2058228e5f6a183d.js} +1 -1
  39. package/assets/esri/core/workers/chunks/4496ef270c700078df0c.js +1 -0
  40. package/assets/esri/core/workers/chunks/458f4c6c8820c1f62f69.js +1 -0
  41. package/assets/esri/core/workers/chunks/49c346d2fb8538990f45.js +1 -0
  42. package/assets/esri/core/workers/chunks/4bb65ef7b3a02ebe416e.js +1 -0
  43. package/assets/esri/core/workers/chunks/4c765464288b6d096d08.js +1 -0
  44. package/assets/esri/core/workers/chunks/4eb1a2433f675bde12ad.js +1 -0
  45. package/assets/esri/core/workers/chunks/4ffdff269aae8c293cb4.js +1 -0
  46. package/assets/esri/core/workers/chunks/55f7b1de8882569861c0.js +1 -0
  47. package/assets/esri/core/workers/chunks/564cc81c232c97646833.js +1 -0
  48. package/assets/esri/core/workers/chunks/5a6f7360183693f8490d.js +1 -0
  49. package/assets/esri/core/workers/chunks/5f8028928ae8e5d27dda.js +1 -0
  50. package/assets/esri/core/workers/chunks/{c03e6e35082beaec02a6.js → 5fa5bfc70512994f5ec1.js} +1 -1
  51. package/assets/esri/core/workers/chunks/605eddec7aac891ed141.js +1 -0
  52. package/assets/esri/core/workers/chunks/66cba22c09f595bba3bf.js +1 -0
  53. package/assets/esri/core/workers/chunks/6cb5ce0a6bb85c624a21.js +1 -0
  54. package/assets/esri/core/workers/chunks/{bf9b45604249520b596a.js → 74c01de62ccaed0666e0.js} +1 -1
  55. package/assets/esri/core/workers/chunks/7a4413a188a8f1affb2f.js +1 -0
  56. package/assets/esri/core/workers/chunks/{b66e8a48ce7098ca43d5.js → 7c3cd6aefd16fcc1a7fd.js} +1 -1
  57. package/assets/esri/core/workers/chunks/7e0e9ca84490a0c67197.js +1 -0
  58. package/assets/esri/core/workers/chunks/{3315de71eb8791189c05.js → 835fa4484c58d9b31c78.js} +1 -1
  59. package/assets/esri/core/workers/chunks/88a7780b1c689afff8bd.js +1 -0
  60. package/assets/esri/core/workers/chunks/8d636075e5aa053940fc.js +1 -0
  61. package/assets/esri/core/workers/chunks/{7ca33e03a2fd217b9443.js → 9dfdd8e91897d166d888.js} +1 -1
  62. package/assets/esri/core/workers/chunks/{790f86ddf57be50e0dd5.js → 9ef509e0853ad41f7690.js} +1 -1
  63. package/assets/esri/core/workers/chunks/a2377969f76640f1d6fe.js +1 -0
  64. package/assets/esri/core/workers/chunks/aa3a45e8228216c1739b.js +1 -0
  65. package/assets/esri/core/workers/chunks/b2289c18c02c868a2939.js +1 -0
  66. package/assets/esri/core/workers/chunks/b5f44cf03c4e5cc07bc4.js +1 -0
  67. package/assets/esri/core/workers/chunks/b948fe33b4d650eea796.js +1 -0
  68. package/assets/esri/core/workers/chunks/bdeac9196f28aff93e68.js +1 -0
  69. package/assets/esri/core/workers/chunks/c591527543fd75a917d4.js +1 -0
  70. package/assets/esri/core/workers/chunks/{ca4af35af02e3804042e.js → c6580fdcdc33153008b0.js} +1 -1
  71. package/assets/esri/core/workers/chunks/{fe8ee1938d196a70d809.js → ca0572fe5614005acceb.js} +1 -1
  72. package/assets/esri/core/workers/chunks/{67c1e2c17ea3ca27248c.js → cbbbaccc0d3683e1c0fe.js} +1 -1
  73. package/assets/esri/core/workers/chunks/ccc6f6f7052985bebdab.js +1 -0
  74. package/assets/esri/core/workers/chunks/d72d993b36daf6ec2a10.js +1 -0
  75. package/assets/esri/core/workers/chunks/eb9d2bb8b44a93347274.js +1 -0
  76. package/assets/esri/core/workers/chunks/f809cbfb744adb4fad29.js +1 -0
  77. package/assets/esri/core/workers/chunks/fa011ad649c05201e92a.js +1 -0
  78. package/assets/esri/core/workers/chunks/fa7ddf3c89cdb8052b26.js +1 -0
  79. package/assets/esri/core/workers/chunks/fdc9bd8f309af610fa62.js +1 -0
  80. package/assets/esri/themes/base/widgets/_ElevationProfile.scss +2 -2
  81. package/assets/esri/themes/dark/main.css +1 -1
  82. package/assets/esri/themes/light/main.css +1 -1
  83. package/assets/esri/themes/light/view.css +1 -1
  84. package/chunks/LineMarker.glsl.js +2 -2
  85. package/chunks/aiServices.js +5 -0
  86. package/chunks/array.js +1 -1
  87. package/chunks/languageUtils.js +1 -1
  88. package/copyright.txt +38 -0
  89. package/editing/sharedTemplates/executor/createTemplateExecutor.js +1 -1
  90. package/interfaces.d.ts +11 -3
  91. package/layers/graphics/controllers/FeatureTileController3D.js +1 -1
  92. package/layers/graphics/data/AttributesBuilder.js +1 -1
  93. package/layers/graphics/data/QueryEngineResult.js +1 -1
  94. package/layers/graphics/data/queryValidationUtils.js +1 -1
  95. package/layers/graphics/editingSupport.js +1 -1
  96. package/layers/support/TitleCreator.js +1 -1
  97. package/layers/support/fieldUtils.js +1 -1
  98. package/layers/support/labelFormatUtils.js +1 -1
  99. package/package.json +1 -1
  100. package/renderers/ClassBreaksRenderer.js +1 -1
  101. package/renderers/DictionaryRenderer.js +1 -1
  102. package/renderers/UniqueValueRenderer.js +1 -1
  103. package/renderers/support/DictionaryControlString.js +5 -0
  104. package/renderers/support/DictionaryLoader.js +1 -1
  105. package/renderers/support/DictionaryScriptEvaluator.js +5 -0
  106. package/rest/featureService/FeatureService.js +1 -1
  107. package/rest/print.js +1 -1
  108. package/rest/support/TranslateContent.js +5 -0
  109. package/rest/support/TranslateParameters.js +5 -0
  110. package/rest/support/TranslateResult.js +5 -0
  111. package/rest/translate.js +5 -0
  112. package/rest/utils.js +1 -1
  113. package/smartMapping/statistics/support/attributeDensity.js +1 -1
  114. package/smartMapping/statistics/support/utils.js +1 -1
  115. package/smartMapping/support/adapters/InMemoryLayerAdapter.js +1 -1
  116. package/smartMapping/support/utils.js +1 -1
  117. package/support/ArcadeExpression.js +5 -0
  118. package/support/loadArcade.js +5 -0
  119. package/support/revision.js +1 -1
  120. package/symbols/cim/OverrideHelper.js +1 -1
  121. package/symbols/cim/cimAnalyzer.js +1 -1
  122. package/symbols/cim/utils.js +1 -1
  123. package/symbols/support/symbolUtils.js +1 -1
  124. package/views/2d/arcade/callExpressionWithCursor.js +1 -1
  125. package/views/2d/arcade/callExpressionWithFeature.js +1 -1
  126. package/views/2d/engine/webgl/mesh/factories/ResourceProxy.js +1 -1
  127. package/views/2d/engine/webgl/shaderGraph/techniques/mesh/MeshWriterInputEvaluator.js +1 -1
  128. package/views/2d/engine/webgl/shaderGraph/techniques/mesh/MeshWriterRegistry.js +1 -1
  129. package/views/2d/engine/webgl/util/DictionaryMatcher.js +1 -1
  130. package/views/2d/engine/webgl/util/MatcherContext.js +1 -1
  131. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  132. package/views/2d/layers/MediaLayerView2D.js +1 -1
  133. package/views/2d/layers/TileLayerView2D.js +1 -1
  134. package/views/2d/layers/features/FeaturePipelineWorker.js +1 -1
  135. package/views/2d/layers/features/Processor.js +1 -1
  136. package/views/2d/layers/features/processor/AAggregateStrategy.js +1 -1
  137. package/views/2d/layers/features/processor/AProcessorStrategy.js +1 -1
  138. package/views/2d/layers/features/processor/TrackStrategy.js +1 -1
  139. package/views/2d/layers/features/schema/processor/MatcherSchema.js +1 -1
  140. package/views/2d/layers/features/schema/processor/symbols/SymbolSchema.js +1 -1
  141. package/views/2d/layers/features/sources/FeatureSource.js +1 -1
  142. package/views/2d/layers/features/sources/strategies/StreamLoadStrategy.js +1 -1
  143. package/views/2d/layers/features/support/AttributeStore.js +1 -1
  144. package/views/2d/layers/features/support/ComputedAttributeStorage.js +1 -1
  145. package/views/2d/layers/features/support/ComputedExpression.js +1 -1
  146. package/views/2d/layers/features/support/DictionaryTemplate.js +5 -0
  147. package/views/2d/layers/graphics/GraphicsView2D.js +1 -1
  148. package/views/3d/environment/EnvironmentManager.js +1 -1
  149. package/views/3d/environment/Precipitation.js +1 -1
  150. package/views/3d/layers/DynamicLayerView3D.js +1 -1
  151. package/views/3d/layers/FeatureLikeLayerView3D.js +1 -1
  152. package/views/3d/layers/GraphicsLayerView3D.js +1 -1
  153. package/views/3d/layers/I3SMeshView3D.js +1 -1
  154. package/views/3d/layers/RouteLayerView3D.js +1 -1
  155. package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
  156. package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
  157. package/views/3d/layers/graphics/Graphics3DPathSymbolLayer.js +1 -1
  158. package/views/3d/layers/graphics/featureExpressionInfoUtils.js +1 -1
  159. package/views/3d/layers/graphics/queryForSymbologySnapping.js +1 -1
  160. package/views/3d/webgl-engine/lib/PathBuilder.js +1 -1
  161. package/views/3d/webgl-engine/lib/PathGeometryData.js +1 -1
  162. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  163. package/views/3d/webgl-engine/materials/PathMaterial.js +1 -1
  164. package/views/VideoView.js +1 -1
  165. package/views/layers/FeatureLayerView.js +1 -1
  166. package/views/layers/support/MapServiceLayerViewHelper.js +1 -1
  167. package/views/overlay/CrosshairOverlayItem.js +1 -1
  168. package/views/support/projectionUtils.js +1 -1
  169. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  170. package/widgets/Editor/CreateFeaturesWorkflowData.js +1 -1
  171. package/widgets/Editor/EditorViewModel.js +1 -1
  172. package/widgets/Editor/Edits.js +1 -1
  173. package/widgets/Editor/UpdateWorkflow.js +1 -1
  174. package/widgets/Editor/components/PendingFeatureList.js +1 -1
  175. package/widgets/Editor/components/UpdateFeaturePanelContent.js +1 -1
  176. package/widgets/Editor/support/dependencySort.js +5 -0
  177. package/widgets/Editor/workflowUtils.js +1 -1
  178. package/widgets/Feature/FeatureRelationship/FeatureRelationshipViewModel.js +1 -1
  179. package/widgets/Feature/FeatureRelationship.js +1 -1
  180. package/widgets/Feature/support/featureUtils.js +1 -1
  181. package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
  182. package/widgets/FeatureForm/RelationshipInput.js +1 -1
  183. package/widgets/FeatureForm.js +1 -1
  184. package/widgets/FeatureTemplates/FeatureTemplatesViewModel.js +1 -1
  185. package/widgets/OrientedImageryViewer/adapters/sketch/MeasurementAdapter.js +1 -1
  186. package/widgets/Popup.js +1 -1
  187. package/widgets/Print.js +1 -1
  188. package/widgets/Sketch.js +1 -1
  189. package/assets/esri/core/workers/chunks/0121702bc9a1f3a85f1f.js +0 -1
  190. package/assets/esri/core/workers/chunks/05b7c739115be0490583.js +0 -1
  191. package/assets/esri/core/workers/chunks/0ce1bfcdcccb679569f8.js +0 -1
  192. package/assets/esri/core/workers/chunks/1007c1a908b6e503e0db.js +0 -1
  193. package/assets/esri/core/workers/chunks/1439f1d84e21e6295e3f.js +0 -1
  194. package/assets/esri/core/workers/chunks/1912d25f8007685c7aee.js +0 -1
  195. package/assets/esri/core/workers/chunks/1bd58eaac6f4906bbdae.js +0 -1
  196. package/assets/esri/core/workers/chunks/2c091edee3601f345f5f.js +0 -1
  197. package/assets/esri/core/workers/chunks/2e40f2527345ad85d800.js +0 -1
  198. package/assets/esri/core/workers/chunks/30f271bbc34f66cbfc23.js +0 -1
  199. package/assets/esri/core/workers/chunks/36b406131cd864567033.js +0 -1
  200. package/assets/esri/core/workers/chunks/4395b7263a299a8020d4.js +0 -1
  201. package/assets/esri/core/workers/chunks/4c15de6b2b8eefd76b61.js +0 -1
  202. package/assets/esri/core/workers/chunks/4c596cb20baaae5166de.js +0 -1
  203. package/assets/esri/core/workers/chunks/4d16b1e50caad0da7838.js +0 -1
  204. package/assets/esri/core/workers/chunks/5802406d0a239a27a9a3.js +0 -1
  205. package/assets/esri/core/workers/chunks/5c86df2a5e16877ba614.js +0 -1
  206. package/assets/esri/core/workers/chunks/62c9171a58160ea099f8.js +0 -1
  207. package/assets/esri/core/workers/chunks/6a4731b47629604a9ca0.js +0 -1
  208. package/assets/esri/core/workers/chunks/7975ada96e4540a37c83.js +0 -1
  209. package/assets/esri/core/workers/chunks/81c507c0d901448835f4.js +0 -1
  210. package/assets/esri/core/workers/chunks/8278d9263e9b7e3bf2d1.js +0 -1
  211. package/assets/esri/core/workers/chunks/8926f672397620591740.js +0 -1
  212. package/assets/esri/core/workers/chunks/8bf623f560b1ed440004.js +0 -1
  213. package/assets/esri/core/workers/chunks/924176d9ab2e070248a8.js +0 -1
  214. package/assets/esri/core/workers/chunks/988efc508c33ca341e49.js +0 -1
  215. package/assets/esri/core/workers/chunks/98cbfc72430a378a9451.js +0 -1
  216. package/assets/esri/core/workers/chunks/9fde9309cb64f1a9301c.js +0 -1
  217. package/assets/esri/core/workers/chunks/a901c445d36f1a9e7df8.js +0 -1
  218. package/assets/esri/core/workers/chunks/ab525991f71240d68471.js +0 -1
  219. package/assets/esri/core/workers/chunks/af27a3f646a4404d3b8d.js +0 -1
  220. package/assets/esri/core/workers/chunks/c15c3fec95f365580902.js +0 -1
  221. package/assets/esri/core/workers/chunks/c1e343cdf85da40ac10e.js +0 -1
  222. package/assets/esri/core/workers/chunks/c3806be4a760735e6082.js +0 -1
  223. package/assets/esri/core/workers/chunks/c3dc8d1958ddc71e1129.js +0 -1
  224. package/assets/esri/core/workers/chunks/c7b0f58550e63ce6ad5b.js +0 -1
  225. package/assets/esri/core/workers/chunks/ccf8a423eee7ef4ffe4c.js +0 -1
  226. package/assets/esri/core/workers/chunks/d24321b1eeabe9ec553c.js +0 -1
  227. package/assets/esri/core/workers/chunks/dd913cb7cf3bb172b34c.js +0 -1
  228. package/assets/esri/core/workers/chunks/e3e049311bced533c853.js +0 -1
  229. package/assets/esri/core/workers/chunks/e3e5a215dcd531b1196f.js +0 -1
  230. package/assets/esri/core/workers/chunks/e8a19f9144df8f155e30.js +0 -1
  231. package/assets/esri/core/workers/chunks/f31986ea5cadfade8344.js +0 -1
  232. package/assets/esri/core/workers/chunks/f350aefc5e348ebad1da.js +0 -1
  233. package/support/arcadeOnDemand.js +0 -5
  234. package/views/3d/layers/support/projectExtentUtils.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{neverReached as n}from"../../core/compilerUtils.js";import s from"../../core/Evented.js";import i from"../../core/Logger.js";import{destroyMaybe as o}from"../../core/maybe.js";import r from"../../core/Promise.js";import{debounce as a}from"../../core/promiseUtils.js";import{watch as l,whenOnce as u,on as p,syncAndInitial as c}from"../../core/reactiveUtils.js";import{templateHasKey as d}from"../../core/string.js";import{property as h}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as f}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as m}from"../../core/support/UpdatingHandles.js";import g from"../../form/FormTemplate.js";import{isUtilityNetworkAssociationsElement as y,isGroupElement as _,isFieldElement as v,isRelationshipElement as I,isTextElement as x}from"../../form/support/formUtils.js";import E from"../../layers/support/ContingentValue.js";import{isEditableLayer as C}from"../../layers/support/editableLayers.js";import F from"../../layers/support/LayerContingentValuesCache.js";import{utc as b,unknown as V,system as w}from"../../time/constants.js";import{flattenAssociationInputs as A,flattenFieldInputs as j,isGroupInput as T,flattenRelationshipInputs as M,parseFormTemplateString as N,isRelationshipInput as k,isFieldInput as L,isTextElementInput as R,getNormalizedFeatureTypeInfo as S,valueIsValidContingentValue as H}from"./featureFormUtils.js";import U from"./FieldInput.js";import{FormExpressionsManager as Z}from"./FormExpressionsManager.js";import P from"./GroupInput.js";import O from"./RelationshipInput.js";import W from"./TextElementInput.js";import G from"./UtilityNetworkAssociationInput.js";import{createFormExpressionArcadeExecutor as $}from"../support/forms/expressions/FormExpressionArcadeExecutor.js";const D=new t({attributes:{}}),z={field:["editableExpression","requiredExpression","valueExpression","visibilityExpression"],group:["visibilityExpression"],relationship:["editableExpression","visibilityExpression"],text:["visibilityExpression"],utilityNetworkAssociations:["editableExpression","visibilityExpression"]},J="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",B="#JSAPI_CONTINGENT_VALUE_ANY_HASH",K="#JSAPI_CONTINGENT_VALUE_NULL_HASH",Y="esri.widgets.FeatureForm.FeatureFormViewModel",q=()=>i.getLogger(Y);let Q=class extends(r.EsriPromiseMixin(s.EventedAccessor)){constructor(e){super(e),this._expressionExecutorsInUse=new Set,this._expressionExecutorLookup=new Map,this._expressionsManager=null,this._contingentValuesCache=null,this._featureClone=D.clone(),this._initialFeature=D.clone(),this._timeZone=null,this._updatingHandles=new m,this.activeAssociation=null,this.arcadeEditType="NA",this.contingencyConstraintViolations=new Map,this.disabled=!1,this.highlightHelper=null,this.inputs=[],this.map=null,this.callbacks=null,this.strict=!1,this.pendingSubtypeChoice=null,this._updateInputs=a((async()=>{this._stopExpressions();const{_featureClone:e,_initialFeature:t,arcadeEditType:n,formTemplate:s,inputs:i,layer:o,timeZone:r}=this;if(!o)return;const a={arcadeEditType:n,feature:e,initialFeature:t,layer:o,timeZone:r},l=i.slice(),u=s?.elements&&s.elements.length>0?await this._updateInputsUsingFormElements(l,s.elements,a):this._updateInputsUsingLayerFields(l,o?.fields,a);this.inputs=u,await this._startExpressions()}))}initialize(){const e=l((()=>[this.layer,!!this.layer?.loaded,this.formTemplate,this.feature,this.timeZone,this.arcadeEditType]),(([e,t])=>{null!=e&&(t?this._updatingHandles.addPromise(this._updateInputs()):e.load().catch((()=>{})))}),c),t=l((()=>this._arcadeContextInfo),(e=>{null!=this._expressionsManager&&(this._expressionsManager.arcadeContextInfo=e,this._updatingHandles.addPromise(this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated()))))})),n=l((()=>this.layer),(e=>{const t="subtype-sublayer"===e?.type?e.parent:"feature"===e?.type?e:null;t&&this.addResolvingPromise(F.createLoadedLayerContingentValuesCache(t).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.addHandles([e,t,n])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this.highlightHelper?.removeAll(),this._updatingHandles.destroy()}get _expressionInfosLookup(){return new Map(this.formTemplate?.expressionInfos?.map((e=>[e.name,e])))}get activeAssociationInput(){return this.allAssociationInputs.find((e=>e.uid===this.associationId))}get activeRelationshipInput(){return this.allRelationshipInputs.find((e=>e.relationshipId===this.relationshipId))}get _arcadeContextInfo(){const{_initialFeature:e,arcadeEditType:t,layer:n,map:s,spatialReference:i,timeZone:o}=this;return{layer:C(n)?n:null,originalFeature:e,editType:t,map:s,spatialReference:i,timeZone:o}}get associationId(){return this._get("associationId")}set associationId(e){null==e&&this.activeAssociationInput?.viewModel&&(this.activeAssociationInput.associatedLayer=null,this.activeAssociationInput.viewModel.activeAssociationType=null),this._set("associationId",e)}get associatedLayer(){return this.activeAssociationInput?.associatedLayer}set associatedLayer(e){this.activeAssociationInput&&(this.activeAssociationInput.associatedLayer=e)}get allAssociationInputs(){return A(this.inputs)}get allFieldInputs(){return j(this.inputs)}get allGroupInputs(){return this.inputs.filter(T)}get allRelationshipInputs(){return M(this.inputs)}get _layerFieldsByName(){return new Map(this.layer?.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){const t=this._get("feature");this._featureClone=e?e.clone():D.clone(),this._initialFeature=this._featureClone.clone(),this._expressionsManager&&(this._expressionsManager.feature=this._featureClone),e?(this._resetFieldInputValues(this._featureClone),this.allRelationshipInputs.forEach((t=>t.feature=e))):(this.inputs.forEach((e=>e.destroy())),this.inputs.length=0),t!==e&&(this.pendingSubtypeChoice=null),this.contingencyConstraintViolations.clear(),this._set("feature",e)}get fieldsWithContingentValues(){if(null==this._contingentValuesCache)return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get formDescription(){const{formTemplate:e,layer:t}=this;return e?.description&&t?N({label:e.description,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formTitle(){const{formTemplate:e,layer:t}=this;return e?.title&&t?N({label:e.title,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formHeaderVisible(){const{activeRelationshipInput:e,activeAssociationInput:t,formDescription:n,formTitle:s}=this;return!(e||t||!n&&!s)}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){this._override("layer",e)}get relationshipId(){return this._get("relationshipId")}set relationshipId(e){const t=this.allRelationshipInputs;if(null!=e&&e===this.relationshipId||t.forEach((e=>e.showAllEnabled=!1)),null!=e){const n=t.find((t=>t.relationshipId===e));n&&(n.showAllEnabled=!0)}this._set("relationshipId",e)}get spatialReference(){return this.layer?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){return this.layer?.loaded?"ready":"disabled"}get submittable(){return!!this.valid||this.allFieldInputs.filter((e=>!e.valid)).every((({submittable:e})=>e))}get timeZone(){const{layer:e}=this;if(e&&"datesInUnknownTimezone"in e&&e.datesInUnknownTimezone)return b;const t=e&&"preferredTimeZone"in e&&e.preferredTimeZone;return this._timeZone===V?t||b:this._timeZone||w}set timeZone(e){this._timeZone=e}get updating(){return this._updatingHandles.updating}get valid(){const e=this.allFieldInputs;return e.length>0&&e.every((({valid:e})=>e))}findField(e){return this.allFieldInputs.find((t=>t.name===e))}getFieldValueOptionsForField(e,t){const n=this.findField(e);if(!n)return[[],[],[]];const s="coded-value"===n.domain?.type?n.domain.codedValues.map((({name:e,code:t})=>({name:e,value:t}))):[],i=null==n.value||s.some((e=>e.value===n.value))?[]:[{name:`${n.value}`,value:n.value}],o=this.fieldsWithContingentValues.has(e)?this._getContingentValueOptionsForField(e,t):[];if(o.length>0){const e=new Set(o.map((e=>e.value)));return[o,s.filter((t=>!e.has(t.value))),i]}return[s,[],i]}getValue(e){const t=this.layer?.getField(e);if(null!=t)return this._featureClone.getAttribute(t.name)??null}setValue(e,t){const{_featureClone:n,strict:s}=this,i=this.findField(e);t=""===t?null:t,i&&n.getAttribute(e)!==t&&(i.value=t,s&&!i.valid||(this._afterValueChange(i),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.notifyChange("submittable"),this.notifyChange("valid"),this.emit("submit",{valid:[...t],invalid:n,values:s})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,s=new Map;if(this.contingencyConstraintViolations=s,null==n)return[];const{invalid:i,incomplete:o}=n.validateContingencyConstraints(e),r=[...i,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)s.set(e,a);return r}notifyFeatureGeometryChanged(){const{_expressionsManager:e,feature:t,_featureClone:n}=this;t&&(n.geometry=t.geometry,null!=e&&this._updatingHandles.addPromise(e.evaluateInvalidatedByGeometry().finally((()=>this._afterExpressionsEvaluated()))))}applySubtypeDefaults(e){const{defaultValues:t}=e,{allFieldInputs:n}=this;for(const{name:s}of n){const e=t[s];null!=e&&this.setValue(s,e)}}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}async _updateInputsUsingFormElements(e,t,n){const s=new Map;for(const r of e)if(T(r)){s.set(r.element,r);for(const e of r.inputs)e.element&&s.set(e.element,e)}else r.element&&s.set(r.element,r);const i=new Map,o=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:s,updatedElements:t.filter(X),sharedInitializationProperties:n,group:null,newExpressionExecutorPromises:i});for(const[r,a]of s.entries())s.delete(r),a.destroy();return await Promise.all(Array.from(i.values())),o}async _updateInputsUsingFormElementsRecursive(e){const{existingInputsByElement:t,updatedElements:n,sharedInitializationProperties:s,group:i,newExpressionExecutorPromises:o}=e,r=[];for(const a of n){const e=t.has(a),n=e?t.get(a):this._makeInputFromElement(a,s,i);if(n){if(r.push(n),await u((()=>!n.updating)),this._assignExpressionExecutors(n,a,o),e)if(t.delete(a),T(n)){const{feature:e,timeZone:t}=s;n.set({feature:e,timeZone:t})}else if(k(n)){const e=this.relationshipId===a.relationshipId;n.set(s),n.set({map:this.map,showAllEnabled:e})}else y(n)?(n.set(s),n.set({map:this.map})):n.set(s);if(_(a)){const e=a.elements.filter((e=>X(e)));n.inputs=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:t,updatedElements:e,sharedInitializationProperties:s,group:n,newExpressionExecutorPromises:o})}}}return r}_updateInputsUsingLayerFields(e,t,n){if(!Array.isArray(t))return q().warn(this.declaredClass,"No attribute fields found."),[];const s=new Map;for(const o of e)if(T(o)){for(const e of o.inputs)e.destroy();o.inputs.length=0,o.destroy()}else k(o)?o.destroy():L(o)&&(null!==o.element?o.destroy():s.set(o.field,o));const i=[];for(const o of t){const e=n.feature?.getAttribute(o.name)??null,t=s.get(o)??new U({field:o,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden});i.push(t.set({...n,value:e})),s.delete(o)}for(const[o,r]of s.entries())s.delete(o),r.destroy();return i}_resetFieldInputValues(e){for(const t of this.allFieldInputs)t.value=e.getAttribute(t.name)}_makeInputFromElement(e,t,s){return _(e)?ee(e,t):v(e)?this._makeFieldInputFromElement(e,t,s):I(e)?this._makeRelationshipInputFromElement(e,t,s):y(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):x(e)?te(e,t):y(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):n()}_makeFieldInputFromElement(e,t,n){const{arcadeEditType:s,feature:i,initialFeature:o,layer:r,timeZone:a}=t,{fieldName:l}=e,u=l&&this._layerFieldsByName.get(l);return u?new U({arcadeEditType:s,element:e,field:u,value:i?.getAttribute(e.fieldName)??null,feature:i,initialFeature:o,layer:r,group:n,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden,timeZone:a}):null}_makeRelationshipInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t,a=new O({element:e,feature:i,group:n,layer:o,map:s,timeZone:r});return a.addHandles(p((()=>a.relatedLayer),"edits",(()=>this._expressionsManager?.evaluateAsyncExpressions()))),a}_makeUtilityNetworkAssociationInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t;return new G({element:e,feature:i,group:n,layer:o,map:s,timeZone:r})}_assignExpressionExecutors(e,t,n){const s=z[t.type],i=[];for(const o of s){const s=`${o}Executor`;if(e[s]){this._useExecutor(e[s]);continue}const r=t[o];if(null!=r&&""!==r){const t=this._expressionInfosLookup.get(r)?.expression??r;i.push(this._getOrCreateExecutorForExpression(t,n).then((t=>{e[s]=this._useExecutor(t)})))}}return R(e)&&i.push(...this._assignTextElementExpressionExecutors(e,n)),i}_assignTextElementExpressionExecutors(e,t){const{_expressionInfosLookup:n}=this,s=[];for(const o of e.expressionsUsed){const r=n.get(o);null!=r?s.push(this._getOrCreateExecutorForExpression(r.expression,t).then((t=>e.setExpressionExecutor(o,this._useExecutor(t))))):i.getLogger(this).error("feature-form:expression-not-found",`Could not find expressionInfo object with name '${o}'`)}for(const i of e.fieldsUsed){const n=`return $feature['${i}'];`;s.push(this._getOrCreateExecutorForExpression(n,t).then((t=>e.setFieldExecutor(i,this._useExecutor(t)))))}return s}async _getOrCreateExecutorForExpression(e,t){const{_expressionExecutorLookup:n}=this;if(n.has(e))return n.get(e);if(t.has(e))return t.get(e);const s=$(e,this.layer);t.set(e,s);const i=await s;return n.set(e,i),i}_createExpressionsManager(e){const{_arcadeContextInfo:t,_featureClone:n,allFieldInputs:s,formTemplate:i}=this;this._expressionsManager=new Z({executors:e,feature:n,arcadeContextInfo:t,fieldInputs:s,preserveFieldValuesWhenHidden:!0===i?.preserveFieldValuesWhenHidden})}async _startExpressions(){if(0===this._expressionExecutorsInUse.size)return;const e=Array.from(this._expressionExecutorsInUse);this._createExpressionsManager(e),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:l}=S(o);if((e.isSubtypeField||t===a)&&n!==r){if("subtype-sublayer"===o.type){const e=o.parent?.findSublayerForFeature(s);e&&(this.feature&&(this.feature.sourceLayer=e),s.sourceLayer=e)}const e=new Set;for(const t of l)if(t.domains&&"object"==typeof t.domains)for(const n of Object.keys(t.domains))e.add(n);for(const t of e){const e=this.findField(t);e&&e.notifyChange("domain")}this.notifyChange("joinedContingentValues")}if(null!=i){const{description:e,title:n}=i;n&&d(n,t)&&this.notifyChange("formTitle"),e&&d(e,t)&&this.notifyChange("formDescription")}this._emitChangeEvent(e)}_afterExpressionsEvaluated(){const{_featureClone:e}=this;for(const t of this.allFieldInputs)t.value!==e.getAttribute(t.name)&&this._afterValueChange(t)}_joinContingentValues(){const e=this._contingentValuesCache;if(null==e)return[];const{typeFieldName:t}=S(this.layer),n=t?this.getValue(t):null,s=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:i}=r,o=[];for(const s of e)s.isRetired||null!=s.subtype&&s.subtype.code!==n||o.push({values:s.values});o.length>0&&s.push({name:i,fields:t,contingencies:o})}const[i,o]=this._generateJoinPlan(s);return[...i.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],s=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const i=t.get(e),o=l,r=[i.name,o.name].sort().join("|");if(s.has(r))continue;n.push([i,o]),s.add(r),t.set(e,o)}else t.set(e,l);const i=new Set(n.flat()),o=new Set(e);for(const l of i)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),s=r.get(t);for(const i of s)n.add(i),a.set(i,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let s=t.shift(),i=this._generateJoinKey(n.fields,s.fields),o=new Set([...n.fields,...s.fields]),r=new Map;for(const l of n.contingencies){const[e]=this._hashContingency(l,i.codedValueFields,!0);r.has(e)?r.get(e)?.push(l):r.set(e,[l])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of s.contingencies){const[n,s]=this._hashContingency(t,i.codedValueFields),o=s?this._findMatchingContingenciesWithAnyHashMask(r,n):r.get(n);if(r.has(B)&&o?.push(...this._findMatchingContingenciesContainingAny(t,r.get(B),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(B)&&n.push(...this._findMatchingContingenciesContainingAny(l,r.get(B),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:h}=this._compareObjectTypes(n.objectType,o.objectType);if(l||c)continue;if(r&&p||a&&u){s.values[i]=new E({objectType:"null"});continue}if(r&&h||a&&d)return null;u?(n.minValue=-1/0,n.maxValue=1/0):p&&(o.minValue=-1/0,o.maxValue=1/0);const f=Math.max(n.minValue,o.minValue),m=Math.min(n.maxValue,o.maxValue);if(f>m)return null;s.values[i]=new E({objectType:"range",minValue:f,maxValue:m})}return s}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const s=t.values[n],i=e.values[n];return"any"===s.objectType||"any"===i.objectType||s.codedValue?.code===i.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),s=[];for(const[i,o]of e){if(i===B)break;n.test(i)&&s.push(...o)}return s}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,s=Array.isArray(t)?new Set(t):t,i=n.size<s.size?n:s,o=i===n?s:n,{feature:r}=this,a=new Set,l=new Set;for(const u of i)if(o.has(u)){const e=this.layer?.getFieldDomain(u,{feature:r??void 0,excludeImpliedDomains:!0});if(null==e)continue;switch(e.type){case"coded-value":a.add(u);break;case"range":l.add(u)}}return{codedValueFields:[...a],rangeFields:[...l]}}_contingencyIsValid(e,t){const n={};for(const{name:s,value:i}of this.allFieldInputs)this.fieldsWithContingentValues.has(s)&&null!=i&&s!==e&&(n[s]=i);return Object.entries(n).every((([e,n])=>!t.values.hasOwnProperty(e)||H(n,t.values[e])))}_getContingentValueOptionsForField(e,t){const n=this.joinedContingentValues.slice(),s=new Map,i={code:"",name:t??"No value"};for(const o of n){const t=o.values[e];if("code"===t?.objectType||"null"===t?.objectType){const{code:n,name:r}=t.codedValue&&"null"!==t.objectType?t.codedValue:i;!s.has(n)&&this._contingencyIsValid(e,o)&&s.set(n,{name:r,value:n})}}return[...s.values()]}_hashContingency(e,t,n=!1){if(t.length<1)return[J,!1];const s=[];let i=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[B,!0];i=!0,s.push(`${o}:.*`)}else"null"===t.objectType?s.push(`${o}:${K}`):s.push(`${o}:${t.codedValue?.code}`)}return[s.sort().join("&"),i]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}get test(){return{featureClone:this._featureClone}}};function X(e){return"field"===e.type||"group"===e.type||"relationship"===e.type||"text"===e.type||"utilityNetworkAssociations"===e.type||(q().warn("form-info::unsupported-element-type","Only element types 'field', 'group' and 'relationship' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}function ee(e,t){const{feature:n,layer:s}=t;return new P({element:e,inputs:[],feature:n,layer:s})}function te(e,t,n=null){const{feature:s,layer:i,timeZone:o}=t;return new W({element:e,feature:s,group:n,layer:i,timeZone:o})}e([h()],Q.prototype,"_expressionInfosLookup",null),e([h()],Q.prototype,"_featureClone",void 0),e([h()],Q.prototype,"_timeZone",void 0),e([h()],Q.prototype,"activeAssociation",void 0),e([h()],Q.prototype,"activeAssociationInput",null),e([h()],Q.prototype,"activeRelationshipInput",null),e([h()],Q.prototype,"_arcadeContextInfo",null),e([h()],Q.prototype,"associationId",null),e([h()],Q.prototype,"associatedLayer",null),e([h()],Q.prototype,"allAssociationInputs",null),e([h()],Q.prototype,"allFieldInputs",null),e([h()],Q.prototype,"allGroupInputs",null),e([h()],Q.prototype,"allRelationshipInputs",null),e([h()],Q.prototype,"_layerFieldsByName",null),e([h()],Q.prototype,"arcadeEditType",void 0),e([h()],Q.prototype,"contingencyConstraintViolations",void 0),e([h()],Q.prototype,"disabled",void 0),e([h()],Q.prototype,"feature",null),e([h()],Q.prototype,"fieldsWithContingentValues",null),e([h({type:g})],Q.prototype,"formTemplate",null),e([h()],Q.prototype,"formDescription",null),e([h()],Q.prototype,"formTitle",null),e([h()],Q.prototype,"formHeaderVisible",null),e([h()],Q.prototype,"highlightHelper",void 0),e([h()],Q.prototype,"inputs",void 0),e([h()],Q.prototype,"joinedContingentValues",null),e([h()],Q.prototype,"layer",null),e([h()],Q.prototype,"map",void 0),e([h()],Q.prototype,"callbacks",void 0),e([h()],Q.prototype,"relationshipId",null),e([h()],Q.prototype,"spatialReference",null),e([h()],Q.prototype,"state",null),e([h()],Q.prototype,"strict",void 0),e([h()],Q.prototype,"submittable",null),e([h()],Q.prototype,"timeZone",null),e([h()],Q.prototype,"updating",null),e([h()],Q.prototype,"valid",null),e([h()],Q.prototype,"pendingSubtypeChoice",void 0),e([h()],Q.prototype,"getValues",null),e([h()],Q.prototype,"submit",null),e([h()],Q.prototype,"test",null),Q=e([f(Y)],Q);const ne=Q;export{ne as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{neverReached as n}from"../../core/compilerUtils.js";import s from"../../core/Evented.js";import i from"../../core/Logger.js";import{destroyMaybe as o}from"../../core/maybe.js";import r from"../../core/Promise.js";import{debounce as a}from"../../core/promiseUtils.js";import{watch as l,whenOnce as u,on as p,syncAndInitial as c}from"../../core/reactiveUtils.js";import{templateHasKey as d}from"../../core/string.js";import{property as h}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as f}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as m}from"../../core/support/UpdatingHandles.js";import g from"../../form/FormTemplate.js";import{isUtilityNetworkAssociationsElement as y,isGroupElement as _,isFieldElement as v,isRelationshipElement as I,isTextElement as x}from"../../form/support/formUtils.js";import E from"../../layers/support/ContingentValue.js";import{isEditableLayer as C}from"../../layers/support/editableLayers.js";import F from"../../layers/support/LayerContingentValuesCache.js";import{utc as b,unknown as V,system as w}from"../../time/constants.js";import{flattenAssociationInputs as A,flattenFieldInputs as j,isGroupInput as T,flattenRelationshipInputs as M,parseFormTemplateString as N,isRelationshipInput as k,isFieldInput as L,isTextElementInput as R,getNormalizedFeatureTypeInfo as S,valueIsValidContingentValue as H}from"./featureFormUtils.js";import U from"./FieldInput.js";import{FormExpressionsManager as Z}from"./FormExpressionsManager.js";import P from"./GroupInput.js";import O from"./RelationshipInput.js";import W from"./TextElementInput.js";import G from"./UtilityNetworkAssociationInput.js";import{createFormExpressionArcadeExecutor as $}from"../support/forms/expressions/FormExpressionArcadeExecutor.js";const D=new t({attributes:{}}),z={field:["editableExpression","requiredExpression","valueExpression","visibilityExpression"],group:["visibilityExpression"],relationship:["editableExpression","visibilityExpression"],text:["visibilityExpression"],utilityNetworkAssociations:["editableExpression","visibilityExpression"]},J="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",B="#JSAPI_CONTINGENT_VALUE_ANY_HASH",K="#JSAPI_CONTINGENT_VALUE_NULL_HASH",Y="esri.widgets.FeatureForm.FeatureFormViewModel",q=()=>i.getLogger(Y);let Q=class extends(r.EsriPromiseMixin(s.EventedAccessor)){constructor(e){super(e),this._expressionExecutorsInUse=new Set,this._expressionExecutorLookup=new Map,this._expressionsManager=null,this._contingentValuesCache=null,this._featureClone=D.clone(),this._initialFeature=D.clone(),this._timeZone=null,this._updatingHandles=new m,this.activeAssociation=null,this.arcadeEditType="NA",this.contingencyConstraintViolations=new Map,this.disabled=!1,this.highlightHelper=null,this.inputs=[],this.map=null,this.callbacks=null,this.strict=!1,this.pendingSubtypeChoice=null,this._updateInputs=a((async()=>{this._stopExpressions();const{_featureClone:e,_initialFeature:t,arcadeEditType:n,formTemplate:s,inputs:i,layer:o,timeZone:r}=this;if(!o)return;const a={arcadeEditType:n,feature:e,initialFeature:t,layer:o,timeZone:r},l=i.slice(),u=s?.elements&&s.elements.length>0?await this._updateInputsUsingFormElements(l,s.elements,a):this._updateInputsUsingLayerFields(l,o?.fields,a);this.inputs=u,await this._startExpressions()}))}initialize(){const e=l((()=>[this.layer,!!this.layer?.loaded,this.formTemplate,this.feature,this.timeZone,this.arcadeEditType]),(([e,t])=>{null!=e&&(t?this._updatingHandles.addPromise(this._updateInputs()):e.load().catch((()=>{})))}),c),t=l((()=>this._arcadeContextInfo),(e=>{null!=this._expressionsManager&&(this._expressionsManager.arcadeContextInfo=e,this._updatingHandles.addPromise(this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated()))))})),n=l((()=>this.layer),(e=>{const t="subtype-sublayer"===e?.type?e.parent:"feature"===e?.type?e:null;t&&this.addResolvingPromise(F.createLoadedLayerContingentValuesCache(t).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.addHandles([e,t,n])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this.highlightHelper?.removeAll(),this._updatingHandles.destroy()}get _expressionInfosLookup(){return new Map(this.formTemplate?.expressionInfos?.map((e=>[e.name,e])))}get activeAssociationInput(){return this.allAssociationInputs.find((e=>e.uid===this.associationId))}get activeRelationshipInput(){return this.allRelationshipInputs.find((e=>e.relationshipId===this.relationshipId||e.activeCategory||e.showAllEnabled))}get _arcadeContextInfo(){const{_initialFeature:e,arcadeEditType:t,layer:n,map:s,spatialReference:i,timeZone:o}=this;return{layer:C(n)?n:null,originalFeature:e,editType:t,map:s,spatialReference:i,timeZone:o}}get associationId(){return this._get("associationId")}set associationId(e){null==e&&this.activeAssociationInput?.viewModel&&(this.activeAssociationInput.associatedLayer=null,this.activeAssociationInput.viewModel.activeAssociationType=null),this._set("associationId",e)}get associatedLayer(){return this.activeAssociationInput?.associatedLayer}set associatedLayer(e){this.activeAssociationInput&&(this.activeAssociationInput.associatedLayer=e)}get allAssociationInputs(){return A(this.inputs)}get allFieldInputs(){return j(this.inputs)}get allGroupInputs(){return this.inputs.filter(T)}get allRelationshipInputs(){return M(this.inputs)}get _layerFieldsByName(){return new Map(this.layer?.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){const t=this._get("feature");this._featureClone=e?e.clone():D.clone(),this._initialFeature=this._featureClone.clone(),this._expressionsManager&&(this._expressionsManager.feature=this._featureClone),e?(this._resetFieldInputValues(this._featureClone),this.allRelationshipInputs.forEach((t=>t.feature=e))):(this.inputs.forEach((e=>e.destroy())),this.inputs.length=0),t!==e&&(this.pendingSubtypeChoice=null),this.contingencyConstraintViolations.clear(),this._set("feature",e)}get fieldsWithContingentValues(){if(null==this._contingentValuesCache)return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get formDescription(){const{formTemplate:e,layer:t}=this;return e?.description&&t?N({label:e.description,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formTitle(){const{formTemplate:e,layer:t}=this;return e?.title&&t?N({label:e.title,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formHeaderVisible(){const{activeRelationshipInput:e,activeAssociationInput:t,formDescription:n,formTitle:s}=this;return!(e||t||!n&&!s)}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){this._override("layer",e)}get relationshipId(){return this._get("relationshipId")}set relationshipId(e){const t=this.allRelationshipInputs;if(null!=e&&e===this.relationshipId||t.forEach((e=>{e.showAllEnabled=!1,e.activeCategory=null})),null!=e){const n=t.find((t=>t.relationshipId===e));n&&(n.showAllEnabled=!0)}this._set("relationshipId",e)}get spatialReference(){return this.layer?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){return this.layer?.loaded?"ready":"disabled"}get submittable(){return!!this.valid||this.allFieldInputs.filter((e=>!e.valid)).every((({submittable:e})=>e))}get timeZone(){const{layer:e}=this;if(e&&"datesInUnknownTimezone"in e&&e.datesInUnknownTimezone)return b;const t=e&&"preferredTimeZone"in e&&e.preferredTimeZone;return this._timeZone===V?t||b:this._timeZone||w}set timeZone(e){this._timeZone=e}get updating(){return this._updatingHandles.updating}get valid(){const e=this.allFieldInputs;return e.length>0&&e.every((({valid:e})=>e))}findField(e){return this.allFieldInputs.find((t=>t.name===e))}getFieldValueOptionsForField(e,t){const n=this.findField(e);if(!n)return[[],[],[]];const s="coded-value"===n.domain?.type?n.domain.codedValues.map((({name:e,code:t})=>({name:e,value:t}))):[],i=null==n.value||s.some((e=>e.value===n.value))?[]:[{name:`${n.value}`,value:n.value}],o=this.fieldsWithContingentValues.has(e)?this._getContingentValueOptionsForField(e,t):[];if(o.length>0){const e=new Set(o.map((e=>e.value)));return[o,s.filter((t=>!e.has(t.value))),i]}return[s,[],i]}getValue(e){const t=this.layer?.getField(e);if(null!=t)return this._featureClone.getAttribute(t.name)??null}setValue(e,t){const{_featureClone:n,strict:s}=this,i=this.findField(e);t=""===t?null:t,i&&n.getAttribute(e)!==t&&(i.value=t,s&&!i.valid||(this._afterValueChange(i),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.notifyChange("submittable"),this.notifyChange("valid"),this.emit("submit",{valid:[...t],invalid:n,values:s})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,s=new Map;if(this.contingencyConstraintViolations=s,null==n)return[];const{invalid:i,incomplete:o}=n.validateContingencyConstraints(e),r=[...i,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)s.set(e,a);return r}notifyFeatureGeometryChanged(){const{_expressionsManager:e,feature:t,_featureClone:n}=this;t&&(n.geometry=t.geometry,null!=e&&this._updatingHandles.addPromise(e.evaluateInvalidatedByGeometry().finally((()=>this._afterExpressionsEvaluated()))))}applySubtypeDefaults(e){const{defaultValues:t}=e,{allFieldInputs:n}=this;for(const{name:s}of n){const e=t[s];null!=e&&this.setValue(s,e)}}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}async _updateInputsUsingFormElements(e,t,n){const s=new Map;for(const r of e)if(T(r)){s.set(r.element,r);for(const e of r.inputs)e.element&&s.set(e.element,e)}else r.element&&s.set(r.element,r);const i=new Map,o=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:s,updatedElements:t.filter(X),sharedInitializationProperties:n,group:null,newExpressionExecutorPromises:i});for(const[r,a]of s.entries())s.delete(r),a.destroy();return await Promise.all(Array.from(i.values())),o}async _updateInputsUsingFormElementsRecursive(e){const{existingInputsByElement:t,updatedElements:n,sharedInitializationProperties:s,group:i,newExpressionExecutorPromises:o}=e,r=[];for(const a of n){const e=t.has(a),n=e?t.get(a):this._makeInputFromElement(a,s,i);if(n){if(r.push(n),await u((()=>!n.updating)),this._assignExpressionExecutors(n,a,o),e)if(t.delete(a),T(n)){const{feature:e,timeZone:t}=s;n.set({feature:e,timeZone:t})}else if(k(n)){const e=this.relationshipId===a.relationshipId;n.set(s),n.set({map:this.map,showAllEnabled:e})}else y(n)?(n.set(s),n.set({map:this.map})):n.set(s);if(_(a)){const e=a.elements.filter((e=>X(e)));n.inputs=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:t,updatedElements:e,sharedInitializationProperties:s,group:n,newExpressionExecutorPromises:o})}}}return r}_updateInputsUsingLayerFields(e,t,n){if(!Array.isArray(t))return q().warn(this.declaredClass,"No attribute fields found."),[];const s=new Map;for(const o of e)if(T(o)){for(const e of o.inputs)e.destroy();o.inputs.length=0,o.destroy()}else k(o)?o.destroy():L(o)&&(null!==o.element?o.destroy():s.set(o.field,o));const i=[];for(const o of t){const e=n.feature?.getAttribute(o.name)??null,t=s.get(o)??new U({field:o,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden});i.push(t.set({...n,value:e})),s.delete(o)}for(const[o,r]of s.entries())s.delete(o),r.destroy();return i}_resetFieldInputValues(e){for(const t of this.allFieldInputs)t.value=e.getAttribute(t.name)}_makeInputFromElement(e,t,s){return _(e)?ee(e,t):v(e)?this._makeFieldInputFromElement(e,t,s):I(e)?this._makeRelationshipInputFromElement(e,t,s):y(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):x(e)?te(e,t):y(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):n()}_makeFieldInputFromElement(e,t,n){const{arcadeEditType:s,feature:i,initialFeature:o,layer:r,timeZone:a}=t,{fieldName:l}=e,u=l&&this._layerFieldsByName.get(l);return u?new U({arcadeEditType:s,element:e,field:u,value:i?.getAttribute(e.fieldName)??null,feature:i,initialFeature:o,layer:r,group:n,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden,timeZone:a}):null}_makeRelationshipInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t,a=new O({element:e,feature:i,group:n,layer:o,map:s,timeZone:r});return a.addHandles(p((()=>a.relatedLayer),"edits",(()=>this._expressionsManager?.evaluateAsyncExpressions()))),a}_makeUtilityNetworkAssociationInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t;return new G({element:e,feature:i,group:n,layer:o,map:s,timeZone:r})}_assignExpressionExecutors(e,t,n){const s=z[t.type],i=[];for(const o of s){const s=`${o}Executor`;if(e[s]){this._useExecutor(e[s]);continue}const r=t[o];if(null!=r&&""!==r){const t=this._expressionInfosLookup.get(r)?.expression??r;i.push(this._getOrCreateExecutorForExpression(t,n).then((t=>{e[s]=this._useExecutor(t)})))}}return R(e)&&i.push(...this._assignTextElementExpressionExecutors(e,n)),i}_assignTextElementExpressionExecutors(e,t){const{_expressionInfosLookup:n}=this,s=[];for(const o of e.expressionsUsed){const r=n.get(o);null!=r?s.push(this._getOrCreateExecutorForExpression(r.expression,t).then((t=>e.setExpressionExecutor(o,this._useExecutor(t))))):i.getLogger(this).error("feature-form:expression-not-found",`Could not find expressionInfo object with name '${o}'`)}for(const i of e.fieldsUsed){const n=`return $feature['${i}'];`;s.push(this._getOrCreateExecutorForExpression(n,t).then((t=>e.setFieldExecutor(i,this._useExecutor(t)))))}return s}async _getOrCreateExecutorForExpression(e,t){const{_expressionExecutorLookup:n}=this;if(n.has(e))return n.get(e);if(t.has(e))return t.get(e);const s=$(e,this.layer);t.set(e,s);const i=await s;return n.set(e,i),i}_createExpressionsManager(e){const{_arcadeContextInfo:t,_featureClone:n,allFieldInputs:s,formTemplate:i}=this;this._expressionsManager=new Z({executors:e,feature:n,arcadeContextInfo:t,fieldInputs:s,preserveFieldValuesWhenHidden:!0===i?.preserveFieldValuesWhenHidden})}async _startExpressions(){if(0===this._expressionExecutorsInUse.size)return;const e=Array.from(this._expressionExecutorsInUse);this._createExpressionsManager(e),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:l}=S(o);if((e.isSubtypeField||t===a)&&n!==r){if("subtype-sublayer"===o.type){const e=o.parent?.findSublayerForFeature(s);e&&(this.feature&&(this.feature.sourceLayer=e),s.sourceLayer=e)}const e=new Set;for(const t of l)if(t.domains&&"object"==typeof t.domains)for(const n of Object.keys(t.domains))e.add(n);for(const t of e){const e=this.findField(t);e&&e.notifyChange("domain")}this.notifyChange("joinedContingentValues")}if(null!=i){const{description:e,title:n}=i;n&&d(n,t)&&this.notifyChange("formTitle"),e&&d(e,t)&&this.notifyChange("formDescription")}this._emitChangeEvent(e)}_afterExpressionsEvaluated(){const{_featureClone:e}=this;for(const t of this.allFieldInputs)t.value!==e.getAttribute(t.name)&&this._afterValueChange(t)}_joinContingentValues(){const e=this._contingentValuesCache;if(null==e)return[];const{typeFieldName:t}=S(this.layer),n=t?this.getValue(t):null,s=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:i}=r,o=[];for(const s of e)s.isRetired||null!=s.subtype&&s.subtype.code!==n||o.push({values:s.values});o.length>0&&s.push({name:i,fields:t,contingencies:o})}const[i,o]=this._generateJoinPlan(s);return[...i.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],s=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const i=t.get(e),o=l,r=[i.name,o.name].sort().join("|");if(s.has(r))continue;n.push([i,o]),s.add(r),t.set(e,o)}else t.set(e,l);const i=new Set(n.flat()),o=new Set(e);for(const l of i)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),s=r.get(t);for(const i of s)n.add(i),a.set(i,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let s=t.shift(),i=this._generateJoinKey(n.fields,s.fields),o=new Set([...n.fields,...s.fields]),r=new Map;for(const l of n.contingencies){const[e]=this._hashContingency(l,i.codedValueFields,!0);r.has(e)?r.get(e)?.push(l):r.set(e,[l])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of s.contingencies){const[n,s]=this._hashContingency(t,i.codedValueFields),o=s?this._findMatchingContingenciesWithAnyHashMask(r,n):r.get(n);if(r.has(B)&&o?.push(...this._findMatchingContingenciesContainingAny(t,r.get(B),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(B)&&n.push(...this._findMatchingContingenciesContainingAny(l,r.get(B),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:h}=this._compareObjectTypes(n.objectType,o.objectType);if(l||c)continue;if(r&&p||a&&u){s.values[i]=new E({objectType:"null"});continue}if(r&&h||a&&d)return null;u?(n.minValue=-1/0,n.maxValue=1/0):p&&(o.minValue=-1/0,o.maxValue=1/0);const f=Math.max(n.minValue,o.minValue),m=Math.min(n.maxValue,o.maxValue);if(f>m)return null;s.values[i]=new E({objectType:"range",minValue:f,maxValue:m})}return s}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const s=t.values[n],i=e.values[n];return"any"===s.objectType||"any"===i.objectType||s.codedValue?.code===i.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),s=[];for(const[i,o]of e){if(i===B)break;n.test(i)&&s.push(...o)}return s}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,s=Array.isArray(t)?new Set(t):t,i=n.size<s.size?n:s,o=i===n?s:n,{feature:r}=this,a=new Set,l=new Set;for(const u of i)if(o.has(u)){const e=this.layer?.getFieldDomain(u,{feature:r??void 0,excludeImpliedDomains:!0});if(null==e)continue;switch(e.type){case"coded-value":a.add(u);break;case"range":l.add(u)}}return{codedValueFields:[...a],rangeFields:[...l]}}_contingencyIsValid(e,t){const n={};for(const{name:s,value:i}of this.allFieldInputs)this.fieldsWithContingentValues.has(s)&&null!=i&&s!==e&&(n[s]=i);return Object.entries(n).every((([e,n])=>!t.values.hasOwnProperty(e)||H(n,t.values[e])))}_getContingentValueOptionsForField(e,t){const n=this.joinedContingentValues.slice(),s=new Map,i={code:"",name:t??"No value"};for(const o of n){const t=o.values[e];if("code"===t?.objectType||"null"===t?.objectType){const{code:n,name:r}=t.codedValue&&"null"!==t.objectType?t.codedValue:i;!s.has(n)&&this._contingencyIsValid(e,o)&&s.set(n,{name:r,value:n})}}return[...s.values()]}_hashContingency(e,t,n=!1){if(t.length<1)return[J,!1];const s=[];let i=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[B,!0];i=!0,s.push(`${o}:.*`)}else"null"===t.objectType?s.push(`${o}:${K}`):s.push(`${o}:${t.codedValue?.code}`)}return[s.sort().join("&"),i]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}get test(){return{featureClone:this._featureClone}}};function X(e){return"field"===e.type||"group"===e.type||"relationship"===e.type||"text"===e.type||"utilityNetworkAssociations"===e.type||(q().warn("form-info::unsupported-element-type","Only element types 'field', 'group' and 'relationship' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}function ee(e,t){const{feature:n,layer:s}=t;return new P({element:e,inputs:[],feature:n,layer:s})}function te(e,t,n=null){const{feature:s,layer:i,timeZone:o}=t;return new W({element:e,feature:s,group:n,layer:i,timeZone:o})}e([h()],Q.prototype,"_expressionInfosLookup",null),e([h()],Q.prototype,"_featureClone",void 0),e([h()],Q.prototype,"_timeZone",void 0),e([h()],Q.prototype,"activeAssociation",void 0),e([h()],Q.prototype,"activeAssociationInput",null),e([h()],Q.prototype,"activeRelationshipInput",null),e([h()],Q.prototype,"_arcadeContextInfo",null),e([h()],Q.prototype,"associationId",null),e([h()],Q.prototype,"associatedLayer",null),e([h()],Q.prototype,"allAssociationInputs",null),e([h()],Q.prototype,"allFieldInputs",null),e([h()],Q.prototype,"allGroupInputs",null),e([h()],Q.prototype,"allRelationshipInputs",null),e([h()],Q.prototype,"_layerFieldsByName",null),e([h()],Q.prototype,"arcadeEditType",void 0),e([h()],Q.prototype,"contingencyConstraintViolations",void 0),e([h()],Q.prototype,"disabled",void 0),e([h()],Q.prototype,"feature",null),e([h()],Q.prototype,"fieldsWithContingentValues",null),e([h({type:g})],Q.prototype,"formTemplate",null),e([h()],Q.prototype,"formDescription",null),e([h()],Q.prototype,"formTitle",null),e([h()],Q.prototype,"formHeaderVisible",null),e([h()],Q.prototype,"highlightHelper",void 0),e([h()],Q.prototype,"inputs",void 0),e([h()],Q.prototype,"joinedContingentValues",null),e([h()],Q.prototype,"layer",null),e([h()],Q.prototype,"map",void 0),e([h()],Q.prototype,"callbacks",void 0),e([h()],Q.prototype,"relationshipId",null),e([h()],Q.prototype,"spatialReference",null),e([h()],Q.prototype,"state",null),e([h()],Q.prototype,"strict",void 0),e([h()],Q.prototype,"submittable",null),e([h()],Q.prototype,"timeZone",null),e([h()],Q.prototype,"updating",null),e([h()],Q.prototype,"valid",null),e([h()],Q.prototype,"pendingSubtypeChoice",void 0),e([h()],Q.prototype,"getValues",null),e([h()],Q.prototype,"submit",null),e([h()],Q.prototype,"test",null),Q=e([f(Y)],Q);const ne=Q;export{ne as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import{watch as t,initial as r,on as i}from"../../core/reactiveUtils.js";import{property as l}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import{getEffectiveLayerCapabilities as o}from"../../layers/support/layerUtils.js";import a from"../Feature/FeatureRelationship/FeatureRelationshipViewModel.js";import{isRelatableFeatureSupportedLayer as n}from"../Feature/support/featureUtils.js";import p from"./EditableInput.js";import{getComputedAttributes as d,parseFormTemplateString as u}from"./featureFormUtils.js";const h=3;let y=class extends p{constructor(e){super(e),this._relationshipVM=null,this.group=null,this.type="relationship",this.addHandles([t((()=>({feature:this.feature,element:this.element,layer:this.layer})),(e=>this._createRelationshipVM(e)),r),i((()=>this.relatedLayer),"edits",(()=>this._relationshipVM?.refresh()))])}destroy(){this._relationshipVM?.destroy()}get canAddRelatedFeature(){const{editable:e,featureCount:t,relationship:r}=this;if(!r||!this.loaded||!this.relatedLayerAllowsAdds)return!1;const{cardinality:i,role:l}=r;return!("one-to-one"===i&&t>0)&&("many-to-many"!==i&&(!("one-to-many"===i&&"destination"===l&&t>0)&&e))}get displayCount(){return this.element.displayCount??h}get displayType(){return this.element.displayType}get editable(){return!!this.relatedLayerAllowsEdits&&(this.evaluatedEditableExpression??!0)}get featureCount(){return this._relationshipVM?.featureCount??0}get loaded(){return"loading"!==this._relationshipVM?.state}get map(){return this._get("map")}set map(e){e&&this._relationshipVM?.set("map",e),this._set("map",e)}get orderByFields(){return this.element.orderByFields}get originHasValidKey(){return!(!this.relationship||!this.feature.getAttribute(this.relationship.keyField))}get relationship(){return this._relationshipVM?.relationship}get relationshipId(){return this.element.relationshipId}get relatedFeatureInfos(){const{_relationshipVM:e,timeZone:t}=this;if(!e?.relatedFeatures?.length||!e?.relatedLayer)return[];const{itemDescriptionFieldName:r,relatedFeatures:i,relatedLayer:l}=e,s=l&&"formTemplate"in l&&l.formTemplate?l.formTemplate.title:void 0;return i.map((e=>{let i;if(r){const s=e.getAttribute(r),o=l.fieldsIndex.get(r);if(o){const e=d({values:[s],fields:[o],timeZone:t??void 0})[r];null!=e&&(i=e.toString())}}return{feature:e,description:i,title:s?u({label:s,attributes:e.attributes,fieldsIndex:l.fieldsIndex,timeZone:t}):void 0}})).toArray()}get relatedLayer(){return this._relationshipVM?.relatedLayer}get relatedLayerIsTable(){return!!this.relatedLayer?.isTable}get relatedLayerAllowsAdds(){const{relatedLayer:e}=this;if(!e||!this.relatedLayerAllowsEdits)return!1;const t=o(e);return!!t?.operations?.supportsAdd}get relatedLayerAllowsEdits(){const{relatedLayer:e}=this;if(!e)return!1;const t=o(e);return!!t?.operations?.supportsEditing}get showAllEnabled(){return this._get("showAllEnabled")}set showAllEnabled(e){this._relationshipVM?.set("showAllEnabled",e),this._set("showAllEnabled",e)}get showAllActionVisible(){return!this.showAllEnabled&&this.featureCount>0&&this.featureCount>this.displayCount}get visible(){const{relationship:e}=this;if(!e)return!1;const{cardinality:t}=e;return"many-to-many"!==t&&(null!=this.evaluatedVisibilityExpression?this.evaluatedVisibilityExpression:null!=this.element)}get updating(){return"loading"===this._relationshipVM?.state||"querying"===this._relationshipVM?.state}incrementPage(){this._relationshipVM&&this._relationshipVM.featurePage++}getRelatedFeatureByObjectId(e){return this._relationshipVM?.getRelatedFeatureByObjectId(e)}_createRelationshipVM(e){const{feature:t,element:r,layer:i}=e;if(this._relationshipVM?.destroy(),!t||!r||!i)return;const{displayCount:l,map:s,orderByFields:o,relationshipId:p,showAllEnabled:d}=this;n(i)&&(this._relationshipVM=new a({graphic:t,displayCount:l,layer:i,map:s,orderByFields:o,relationshipId:p,showAllEnabled:d}))}};e([l()],y.prototype,"_relationshipVM",void 0),e([l()],y.prototype,"canAddRelatedFeature",null),e([l()],y.prototype,"displayCount",null),e([l()],y.prototype,"displayType",null),e([l()],y.prototype,"editable",null),e([l()],y.prototype,"featureCount",null),e([l()],y.prototype,"group",void 0),e([l()],y.prototype,"loaded",null),e([l()],y.prototype,"map",null),e([l()],y.prototype,"orderByFields",null),e([l()],y.prototype,"originHasValidKey",null),e([l()],y.prototype,"relationship",null),e([l()],y.prototype,"relationshipId",null),e([l()],y.prototype,"relatedFeatureInfos",null),e([l()],y.prototype,"relatedLayer",null),e([l()],y.prototype,"relatedLayerIsTable",null),e([l()],y.prototype,"relatedLayerAllowsAdds",null),e([l()],y.prototype,"relatedLayerAllowsEdits",null),e([l()],y.prototype,"showAllEnabled",null),e([l()],y.prototype,"showAllActionVisible",null),e([l({readOnly:!0})],y.prototype,"type",void 0),e([l()],y.prototype,"visible",null),e([l()],y.prototype,"updating",null),y=e([s("esri.widgets.FeatureForm.RelationshipInput")],y);const m=y;export{m as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import{watch as t,initial as r,on as i}from"../../core/reactiveUtils.js";import{property as l}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import{isSubtypeGroupLayer as o,getEffectiveLayerCapabilities as a}from"../../layers/support/layerUtils.js";import n from"../Feature/FeatureRelationship/FeatureRelationshipViewModel.js";import{isRelatableFeatureSupportedLayer as p}from"../Feature/support/featureUtils.js";import d from"./EditableInput.js";import{getComputedAttributes as u,parseFormTemplateString as h}from"./featureFormUtils.js";const y=3;let g=class extends d{constructor(e){super(e),this._relationshipVM=null,this.group=null,this.type="relationship",this.addHandles([t((()=>({feature:this.feature,element:this.element,layer:this.layer})),(e=>this._createRelationshipVM(e)),r),i((()=>this.relatedLayer),"edits",(()=>this._relationshipVM?.refresh()))])}destroy(){this._relationshipVM?.destroy()}get canAddRelatedFeature(){const{editable:e,featureCount:t,relationship:r}=this;if(!r||!this.loaded||!this.relatedLayerAllowsAdds)return!1;if(this.allCategories?.length&&!this.activeCategory)return!1;const{cardinality:i,role:l}=r;return!("one-to-one"===i&&t>0)&&("many-to-many"!==i&&(!("one-to-many"===i&&"destination"===l&&t>0)&&e))}get activeCategory(){return this._relationshipVM?.activeCategory}set activeCategory(e){const t=this._relationshipVM;t&&(t.activeCategory=e)}get allCategories(){const{relatedLayer:e}=this,t=this._relationshipVM?.categories;if(!o(e))return;const r=(e.subtypes??[]).map((({code:e,name:r})=>{const i=t?.find((e=>e.name===r));return{name:r,count:i?.count??0,value:i?.value??e}}));return r.length?r:null}get categories(){return this.showAllEnabled?this.allCategories:this.allCategories?.slice(0,this.displayCount)}get displayCount(){return this.element.displayCount??y}get displayType(){return this.element.displayType}get editable(){return!!this.relatedLayerAllowsEdits&&(this.evaluatedEditableExpression??!0)}get featureCount(){return this._relationshipVM?.featureCount??0}get label(){return this.activeCategory?.name?this.activeCategory.name:this.getFormattedLabel(this.element?.label)}get loaded(){return"loading"!==this._relationshipVM?.state}get map(){return this._get("map")}set map(e){e&&this._relationshipVM?.set("map",e),this._set("map",e)}get orderByFields(){return this.element.orderByFields}get originHasValidKey(){return!(!this.relationship||!this.feature.getAttribute(this.relationship.keyField))}get relationship(){return this._relationshipVM?.relationship}get relationshipId(){return this.element.relationshipId}get relatedFeatureInfos(){const{_relationshipVM:e,timeZone:t}=this;if(!e?.relatedFeatures?.length||!e?.relatedLayer)return[];const{itemDescriptionFieldName:r,relatedFeatures:i,relatedLayer:l}=e,s=l&&"formTemplate"in l&&l.formTemplate?l.formTemplate.title:void 0;return i.map((e=>{let i;if(r){const s=e.getAttribute(r),o=l.fieldsIndex.get(r);if(o){const e=u({values:[s],fields:[o],timeZone:t??void 0})[r];null!=e&&(i=e.toString())}}return{feature:e,description:i,title:s?h({label:s,attributes:e.attributes,fieldsIndex:l.fieldsIndex,timeZone:t}):void 0}})).toArray()}get relatedLayer(){return this._relationshipVM?.relatedLayer}get relatedLayerIsTable(){return!!this.relatedLayer?.isTable}get relatedLayerAllowsAdds(){const{relatedLayer:e}=this;if(!e||!this.relatedLayerAllowsEdits)return!1;const t=a(e);return!!t?.operations?.supportsAdd}get relatedLayerAllowsEdits(){const{relatedLayer:e}=this;if(!e)return!1;const t=a(e);return!!t?.operations?.supportsEditing}get showAllEnabled(){return this._get("showAllEnabled")}set showAllEnabled(e){this._relationshipVM?.set("showAllEnabled",e),this._set("showAllEnabled",e)}get showAllActionVisible(){return!this.showAllEnabled&&this.featureCount>0&&this.featureCount>this.displayCount}get showAllCategoriesVisible(){const e=this.allCategories?.length??0;return!this.showAllEnabled&&e>0&&e>this.displayCount}get visible(){const{relationship:e}=this;if(!e)return!1;const{cardinality:t}=e;return"many-to-many"!==t&&(null!=this.evaluatedVisibilityExpression?this.evaluatedVisibilityExpression:null!=this.element)}get updating(){return"loading"===this._relationshipVM?.state||"querying"===this._relationshipVM?.state}incrementPage(){this._relationshipVM&&this._relationshipVM.featurePage++}getRelatedFeatureByObjectId(e){return this._relationshipVM?.getRelatedFeatureByObjectId(e)}_createRelationshipVM(e){const{feature:t,element:r,layer:i}=e;if(this._relationshipVM?.destroy(),!t||!r||!i)return;const{displayCount:l,map:s,orderByFields:o,relationshipId:a,showAllEnabled:d}=this;p(i)&&(this._relationshipVM=new n({graphic:t,displayCount:l,layer:i,map:s,orderByFields:o,relationshipId:a,showAllEnabled:d}))}};e([l()],g.prototype,"_relationshipVM",void 0),e([l()],g.prototype,"canAddRelatedFeature",null),e([l()],g.prototype,"activeCategory",null),e([l()],g.prototype,"allCategories",null),e([l()],g.prototype,"categories",null),e([l()],g.prototype,"displayCount",null),e([l()],g.prototype,"displayType",null),e([l()],g.prototype,"editable",null),e([l()],g.prototype,"featureCount",null),e([l()],g.prototype,"group",void 0),e([l()],g.prototype,"label",null),e([l()],g.prototype,"loaded",null),e([l()],g.prototype,"map",null),e([l()],g.prototype,"orderByFields",null),e([l()],g.prototype,"originHasValidKey",null),e([l()],g.prototype,"relationship",null),e([l()],g.prototype,"relationshipId",null),e([l()],g.prototype,"relatedFeatureInfos",null),e([l()],g.prototype,"relatedLayer",null),e([l()],g.prototype,"relatedLayerIsTable",null),e([l()],g.prototype,"relatedLayerAllowsAdds",null),e([l()],g.prototype,"relatedLayerAllowsEdits",null),e([l()],g.prototype,"showAllEnabled",null),e([l()],g.prototype,"showAllActionVisible",null),e([l()],g.prototype,"showAllCategoriesVisible",null),e([l({readOnly:!0})],g.prototype,"type",void 0),e([l()],g.prototype,"visible",null),e([l()],g.prototype,"updating",null),g=e([s("esri.widgets.FeatureForm.RelationshipInput")],g);const c=g;export{c as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import"../core/has.js";import i from"../core/Logger.js";import{getOrCreateMapValue as o}from"../core/MapUtils.js";import{createResolver as s}from"../core/promiseUtils.js";import{watch as n,initial as a,whenOnce as r}from"../core/reactiveUtils.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import{subclass as d}from"../core/accessorSupport/decorators/subclass.js";import{isIntegerField as c}from"../layers/support/fieldUtils.js";import{getSubtypesFromLayer as u}from"../layers/support/layerUtils.js";import{isString as p}from"../support/guards.js";import m from"./Widget.js";import{Prompt as h}from"./Editor/components/Prompt.js";import v from"./Feature/FeatureUtilityNetworkAssociations.js";import{css as _}from"./FeatureForm/css.js";import{isGroupInput as b,isFieldInput as g,isRelationshipInput as f,isTextElementInput as y,isUtilityNetworkAssociationInput as C,flattenInputs as F,isInputInGroupInput as w,isFieldElementWithInputType as R,getErrorMessageForFieldInput as k,getIconForFeature as O,isNumberFieldInput as I,subtypeChangeShouldPrompt as N}from"./FeatureForm/featureFormUtils.js";import M from"./FeatureForm/FeatureFormViewModel.js";import L from"./FeatureForm/VisibleElements.js";import T from"./FeatureForm/FeatureFormUtilityNetworkAssociations/FeatureFormUtilityNetworkAssociationList.js";import{loadCalciteComponents as x}from"./support/componentsUtils.js";import{getLabelForDateFieldValue as A,getIntlOptionsForField as D,numberingSystem as V,prepareISOFieldValueForDateComponents as U,prepareUnixFieldValueForDateComponents as S,normalizeTimeOnlyString as E,getISOFieldValueFromDateComponents as j,getUnixFieldValueFromDateComponents as P}from"./support/dateUtils.js";import{globalCss as $}from"./support/globalCss.js";import{Heading as H,incrementHeadingLevel as Z}from"./support/Heading.js";import{setFocus as G}from"./support/widgetUtils.js";import{messageBundle as W}from"./support/decorators/messageBundle.js";import{vmEvent as B}from"./support/decorators/vmEvent.js";import{tsx as K}from"./support/jsxFactory.js";import{substitute as q}from"../intl/substitute.js";const z="data-field-name";let J=class extends m{constructor(e,t){super(e,t),this._associationsWidgetsMap=new Map,this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName=null,this._pendingSubtypeChoice=null,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this._prompt=null,this._featureFormUNAssociationList=null,this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new M,this.visibleElements=new L,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,callbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,callbacks:o}=this;i&&o?.addRelatedRecord&&o.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupToggle=this._onGroupToggle.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreate=this._afterComponentCreate.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this)}initialize(){this.addHandles([n((()=>this.feature),(()=>{this._inputsWithChanges.clear(),this._dateComponentMap.clear(),r((()=>!this.viewModel.updating)).then((()=>{const e=this._getFocusableInput("forward");this._syncGroupInputStates(),this._focusedFieldName=e?.name||null,this._attemptFocusOnNextRender=!0}))})),n((()=>[this._featureFormUNAssociationList,this.visibleElements.associationDetails]),(([e,t])=>{e&&(e.visibleElements.associationDetails=t)}),a),n((()=>this.groupDisplay),(()=>this._syncGroupInputStates())),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()}})),n((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange())),n((()=>this.viewModel.activeAssociationInput),(e=>{e&&this._featureFormUNAssociationList&&(this._featureFormUNAssociationList.associationInput=e,this._featureFormUNAssociationList.viewModel=e.viewModel)}))])}loadDependencies(){return x({block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),"text-area":()=>import("@esri/calcite-components/dist/components/calcite-text-area")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const{callbacks:e}=this;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get _utilityNetworkAssociationsEnabled(){const{callbacks:e}=this;return!(!e?.viewAssociatedLayers||!e.viewAssociatedFeatures)}get _subtypes(){return u(this.layer)}get associationId(){return this.viewModel.associationId}set associationId(e){this.viewModel.associationId=e}get associatedLayer(){return this.viewModel.associatedLayer}set associatedLayer(e){this.viewModel.associatedLayer=e}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 icon(){return"form-field"}set icon(e){this._overrideIfSome("icon",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 callbacks(){return this.viewModel.callbacks}set callbacks(e){this.viewModel.callbacks=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 timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get showPrompt(){return e=>{this._prompt?.cancel?.(),this._prompt=e}}set showPrompt(e){this._overrideIfSome("showPrompt",e)}get clearPrompt(){return()=>this._prompt=null}set clearPrompt(e){this._overrideIfSome("clearPrompt",e)}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return K("div",{class:this.classes(_.base,$.widget,$.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return K("div",null,K("form",{class:_.form,novalidate:!0,onkeydown:this._onFormKeyDown,onsubmit:this._onFormSubmit},this._renderHeader(),this._renderContent()),this._prompt?K(h,{...this._prompt,headingLevel:this.headingLevel}):void 0)}_renderHeader(){const e=this.viewModel,{formTitle:t,formDescription:i}=e;if(!e.formHeaderVisible)return;const o=null!=t&&K(H,{key:"title",level:this.headingLevel},t),s=null!=i&&K("p",{class:_.description,key:"description"},i);return K("div",{class:_.formHeader},o,s)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderRelationshipInput(e.activeRelationshipInput):e.activeAssociationInput?this._renderFeatureFormUtilityNetworkAssociationList():e.inputs.filter(t).filter((e=>e.visible)).map((e=>this._renderInput(e)))}_renderInput(e){return b(e)?this._renderGroup(e):g(e)?this._renderLabeledField(e):f(e)?this._renderRelationshipInput(e):y(e)?this._renderTextElementInput(e):C(e)?this._renderUtilityNetworkAssociationsElementInput(e):void 0}_renderFeatureFormUtilityNetworkAssociationList(){return this._featureFormUNAssociationList?.render()}_selectAssociatedLayer(e){const{feature:t,callbacks:i}=this;t&&i?.viewAssociatedFeatures&&i.viewAssociatedFeatures({associatedLayer:e.layer})}async _selectAssociatedFeature(e){const{feature:t,callbacks:i}=this;t&&i?.selectAssociatedFeature&&await i.selectAssociatedFeature({parentFeature:t,...e})}_onAddAssociation(e){const{feature:t,callbacks:i}=this;t&&i?.addAssociation&&i.addAssociation(e)}_setUpUtilityNetworkAssociationList(){this._featureFormUNAssociationList||(this._featureFormUNAssociationList=new T({onSelectLayer:this._selectAssociatedLayer.bind(this),onSelectFeature:this._selectAssociatedFeature.bind(this),onAddAssociation:this._onAddAssociation.bind(this)}))}_renderUtilityNetworkAssociationsElementInput(e){if(this._utilityNetworkAssociationsEnabled)return this._setUpUtilityNetworkAssociationList(),o(this._associationsWidgetsMap,e,(()=>new v({onSelectAssociationType:({viewModel:t,listType:i})=>{t.activeAssociationType=i;const{feature:o,callbacks:s}=this;o&&s?.viewAssociatedLayers&&s.viewAssociatedLayers({associationId:e.uid})},viewModel:e.associationsViewModel}))).render()}_renderDescriptionOrEmpty(e,t){return null==e?null:K("div",{class:this.classes(_.description),id:t},e)}_renderGroup(e){const{disabled:t,formTemplate:i,headingLevel:o}=this,{description:s,id:n,inputs:a,label:r,open:l}=e,d=a.filter((e=>e.visible)),c=this.viewModel.findField(this._focusedFieldName),u=c?.group===e,p="sequential"===this.groupDisplay;return K("calcite-block",{class:this.classes(_.group,p?_.groupSequential:null,u?_.groupActive:null,t?_.inputDisabled:null),collapsible:!0,"data-group":e,description:s||void 0,disabled:t,heading:r??"",headingLevel:i?.title?Z(o):o,id:n,key:n,open:l,onCalciteBlockToggle:({currentTarget:t})=>this._onGroupToggle(t,e)},d.map((e=>this._renderInput(e))))}_getFocusableInput(e,t){const i=F(this.viewModel.inputs);let o;if("backward"===e&&i.reverse(),t)if(b(t)){const e=t.inputs.find((e=>e.visible));o=e?i.indexOf(e):0}else{let s;if(w(t)&&!t.group.open){const i=t.group.inputs.filter(g);s="forward"===e?i[i.length-1]:i[0]}else s=t;o=i.indexOf(s)+1}else o=0;for(let s=o;s<i.length;s++){const e=i[s];if(e.visible&&g(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:o,layer:s,required:n}=e,a={"aria-label":n?q(this.messages.requiredFieldLabel,{name:o}):o,class:_.label,key:`${s.id}-${i.uid}-${e.name}`},r=[K("div",{class:_.labelTextContent,key:"labelTextContainer"},o,n?K("span",{"aria-hidden":"true",title:this.messagesCommon.required},"*"):void 0),"unsupported"!==t?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e)];return"date"===t&&"coded-value"!==e.domain?.type?K("label",{...a},r):K("calcite-label",{...a},r)}_renderFieldInput(e){const{dataType:t,domain:i,inputType:o,name:s}=e,n=this.getCommonInputProps(e);if("coded-value"===i?.type){const t=this.viewModel.getFieldValueOptionsForField(s,this.messages.empty);return"switch"!==o||e.hasInvalidSwitchValue?"radio-buttons"===o?this._renderRadioButtonComponents(e,t.flat(),n):this._renderComboBoxComponent(e,t,n):this._renderSwitchComponent(e,n)}return"datetime-picker"===o||"date"===t?this._renderDateComponents(e,n):"number"===t?this._renderNumberComponent(e,n):this._renderStringComponent(e,n)}_renderStringComponent(e,t){return"text-area"===e.inputType?t.readOnly?K("calcite-input",{...t,loading:e.updating,type:"textarea",onCalciteInputInput:e=>this._saveValueFromComponent(e.currentTarget)}):K("calcite-text-area",{...t,resize:"vertical",onCalciteTextAreaInput:e=>this._saveValueFromComponent(e.currentTarget)}):K("calcite-input",{...t,loading:e.updating,type:"text",onCalciteInputInput:e=>this._saveValueFromComponent(e.currentTarget)})}_renderNumberComponent(e,t){const i=c(e.field),o=i&&""!==t.value?Math.round(parseFloat(t.value)).toString():t.value;return K("calcite-input-number",{...t,integer:i,loading:e.updating,type:"number",value:o,onCalciteInputNumberInput:e=>this._saveValueFromComponent(e.currentTarget)})}_renderDateComponents(e,t){const{field:i}=e;switch(i.type){case"date":return this._renderDateFieldComponents(e,t);case"date-only":return this._renderDateOnlyFieldComponent(e,t);case"time-only":return this._renderTimeOnlyFieldComponent(e,t);case"timestamp-offset":return this._renderTimestampOffsetFieldComponents(e,t);default:return this._renderReadOnlyComponent(e,A(i,t.value,{timeZone:this.timeZone,...D(i)}))}}_renderDateOnlyFieldComponent(e,t){const{range:i,valid:o,value:s}=e,{class:n,key:a,readOnly:r}=t,{rawMax:l,rawMin:d}=i;return K("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!o,class:n,"data-date-part":"date","data-field-name":t[z],key:`${a}-date-input`,max:p(l)?l:void 0,min:p(d)?d:void 0,numberingSystem:V,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:r,value:null!=s?`${s}`:void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)})}_renderTimeOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:s,key:n,readOnly:a}=t;return K("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:s,"data-date-part":"time","data-field-name":t[z],key:`${n}-time-input`,numberingSystem:V,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:a,step:e.timeStep,value:null!=o?`${o}`:void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)})}_renderTimestampOffsetFieldComponents(e,t){const{name:i,range:o,timeZone:s,valid:n,value:a}=e,{class:r,key:l,readOnly:d}=t,{rawMax:c,rawMin:u}=o,p={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!n,numberingSystem:V,overlayPositioning:"fixed",readOnly:d,[z]:i,onfocus:this._onComponentFocus},m=U(c,s),h=U(u,s),v=U(a,s);return K("div",{class:_.dateInputContainer,key:`${l}-date-time-container`},K("calcite-input-date-picker",{...p,class:r,"data-date-part":"date",key:`${l}-date-input`,max:m?.date??void 0,min:h?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:v.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),K("calcite-input-time-picker",{...p,class:r,"data-date-part":"time",key:`${l}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:e.timeStep,value:v.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),e.includeTimeOffset?K("calcite-input-time-zone",{...p,class:r,"data-date-part":"timeZone",disabled:d,key:`${l}-timezone-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:v.timeZoneOffset??"0",onCalciteInputTimeZoneChange:e=>this._saveValueFromDateComponent(e.currentTarget)}):null)}_renderDateFieldComponents(e,t){const{includeTime:i,name:o,valid:s,value:n}=e,{class:a,key:r,max:l,min:d,readOnly:c}=t,{timeZone:u}=this,p={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!s,numberingSystem:V,overlayPositioning:"fixed",readOnly:c,[z]:o,onfocus:this._onComponentFocus},m=S(n,u),h=S(l,u),v=S(d,u);return K("div",{class:_.dateInputContainer,key:`${r}-date-time-container`},K("calcite-input-date-picker",{...p,class:a,"data-date-part":"date",key:`${r}-date-input`,max:h?.date??void 0,min:v?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:m.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),i?K("calcite-input-time-picker",{...p,class:a,"data-date-part":"time",key:`${r}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:1,value:m.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return K("calcite-input",{...i,class:this.classes(_.fieldInput,_.inputDisabled),readOnly:!0,type:"text",value:null!=t?`${t}`:i.value})}_renderComboBoxComponent(e,t,i){const{value:o,name:s}=e,{viewModel:n,_inputsWithChanges:a}=this,r="INSERT"===n.arcadeEditType,l=a.has(s),d=null==o&&(!r||l),c=r&&e.showNoValueOptionEnabled&&!l?()=>{}:i.onblur;return K("calcite-combobox",{...i,allowCustomValues:!1,clearDisabled:!0,disabled:i.readOnly,onblur:c,overlayPositioning:"fixed",selectionMode:"single",onCalciteComboboxChange:({currentTarget:t})=>{d&&0===t.selectedItems.length?this._ignoreDeselectionOfNoValueOption(t):e.isSubtypeField&&0===t.selectedItems.length?t.value=`${e.value}`:this._saveValueFromComponent(t)}},this.renderComboboxOptionsList(e,t))}renderComboboxOptionsList(e,t){const{value:i,name:o}=e,{messages:s,messagesTemplates:n,viewModel:a,_inputsWithChanges:r}=this,[l,d,c]=t.map((e=>e.map((({name:e,value:t})=>K("calcite-combobox-item",{key:`#${t}`,selected:i===t,textLabel:e,value:`${t}`}))))),u=[];d.length>0&&u.push(K("calcite-combobox-item-group",{key:"other",label:n.other},d)),c.length>0&&u.push(K("calcite-combobox-item-group",{key:"unsupported",label:s.subtypes.unsupportedDomainGroupTitle},c)),u.length>0?u.unshift(K("calcite-combobox-item-group",{key:"recommended",label:s.recommended},l)):u.push(...l);const p="INSERT"===a.arcadeEditType,m=r.has(o),h=null==i&&(!p||m);return e.showNoValueOptionEnabled&&u.unshift(K("calcite-combobox-item",{key:"empty-option",selected:h,textLabel:e.showNoValueLabel||s.empty,value:""})),u}_renderRadioButtonComponents(e,t,i){const{name:o,value:s}=e,n=t.map((({name:e,value:t})=>this._renderRadioButtonComponent({key:e,label:e,name:o,value:t,selected:t===s,props:i})));if(e.showNoValueOptionEnabled){const t="",a=e.showNoValueLabel||this.messages.empty,r=s===t||null===s;n.unshift(this._renderRadioButtonComponent({key:"empty-option",label:a,name:o,value:t,selected:r,props:i}))}return K("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:_.inputRadioGroup,"data-field-name":i[z],key:`${i.key}-radio-group`,layout:"vertical",name:i.key,required:i.required},n)}_renderSwitchComponent(e,t){const{value:i}=e,o=!!R(e.element,"switch")&&i===e.element.input.onValue;return K("calcite-switch",{...t,checked:o,class:_.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldName=null},onCalciteSwitchChange:e=>this._saveValueFromComponent(e.currentTarget)})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:o,label:s,props:n}){return K("calcite-label",{class:_.inputRadioLabel,key:e,layout:"inline"},K("calcite-radio-button",{...n,afterCreate:void 0,afterUpdate:void 0,checked:o,class:_.inputRadio,disabled:n.readOnly,name:t,onblur:()=>{this._focusedFieldName=null},value:i,onCalciteRadioButtonChange:({currentTarget:e})=>{e.checked&&this._saveValueFromComponent(e)}}),s)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.submittable?k(e,this.messages,this.timeZone):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?K("calcite-input-message",{icon:!0,status:"invalid"},i):this._inputsWithChanges.has(t)&&e.valueIsOutOfDomain?K("calcite-input-message",{icon:!0,status:"idle"},this.messages.subtypes.fieldOutOfSubtypeDomainWarning):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:o}=e,{callbacks:s}=this;if(!o||!s?.showAllRelatedRecords)return;const n=this.messages;return K("calcite-list-item",{description:q(n.totalCount,{count:t}),label:n.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},K("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:o}=e,{messages:s,callbacks:n}=this;if(t&&n?.addRelatedRecord&&o)return K("calcite-button",{alignment:"center",appearance:"outline-fill",class:_.centeredButton,disabled:e.updating||!e.originHasValidKey,iconStart:"plus",key:`${i}-add-button`,onclick:()=>{!e.updating&&e.originHasValidKey&&this._onAddRelatedRecordsClick(i,o)},round:!0,scale:"s",width:"full"},e.relatedLayerIsTable?s.addRecord:s.addFeature)}_renderRelatedRecordListItem(e,t){const{feature:i,description:o,title:s}=e,{feature:n,callbacks:a}=this,{highlightHelper:r}=this.viewModel,l=()=>{r?.removeAll(),a?.editRelatedRecord&&n&&a.editRelatedRecord({parentFeature:n,relationshipId:t,relatedFeature:i})},d=r?()=>r.add(i):void 0,c=r?()=>r.remove(i):void 0;return K("calcite-list-item",{bind:this,description:o,key:`${t}-${i.uid}`,label:s,onclick:l,onmouseenter:d,onmouseleave:c,value:s},K("calcite-icon",{icon:O(i),slot:"content-start"}),K("calcite-icon",{icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderRelationshipInput(e){if(!this._relatedRecordsEnabled||!e.editable)return;const{featureCount:t,relationshipId:i,showAllEnabled:o}=e,s=o?null:this._renderDescriptionOrEmpty(e.description),n=t>0?this._renderRelatedRecordsList(e):e.loaded?e.originHasValidKey?this._renderNoRelatedRecordsNotice():this._renderNoValidOriginKeyNotice(e):void 0;return K("calcite-label",{class:this.classes(_.label,_.relatedRecordsLabel),key:`relationship-${i}-container`},K("div",null,this._renderRelatedRecordsHeaderContainer(e),s,n),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return K("div",{class:_.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},K("span",null,e.label),t?K("calcite-loader",{inline:!0,key:"loader",label:this.messagesCommon?.loading,scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return K("calcite-list",{class:_.relatedRecordsList,label:this.messages?.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoValidOriginKeyNotice(e){const{messages:t}=this,i=e.relatedLayerIsTable?t.noOriginKeyRecord:t.noOriginKeyFeature,o=e.relationship?.keyField,s=this.viewModel.findField(o),n=e.layer?.fieldsIndex.get(o),a=s?.label||n?.alias||o,r=q(i,{relatedLayerName:e.relatedLayer?.title,originKeyField:a});return K("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},K("div",{slot:"message"},r))}_renderNoRelatedRecordsNotice(){return K("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},K("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return K("div",{afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved,bind:this,class:_.listObserver,key:"feature-observer"})}_renderTextElementInput(e){return K("div",{class:_.textElement,innerHTML:e.text,key:e.id})}getCommonInputProps(e){const{disabled:t}=this,{editable:i,hint:o,label:s,maxLength:n,minLength:a,name:r,range:{max:l,min:d},required:c,valid:u,value:p}=e,m=this._inputsWithChanges.has(r),h=!i||t;return{afterCreate:this._afterComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":u?"false":"true",class:this.classes(_.fieldInput,h?_.inputDisabled:null),status:m&&!u?"invalid":"idle",key:r,label:s,max:null!=l?l:void 0,min:null!=d?d:void 0,maxLength:n>-1?n:void 0,minLength:a>-1?a:void 0,placeholder:o??void 0,readOnly:h,required:c,value:null==p?"":`${p}`,onblur:this._onComponentBlur,onfocus:this._onComponentFocus,onkeydown:this._onComponentKeyDown,[z]:r}}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(z))}_afterDateComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e),i=e.dataset.datePart,o=this._dateComponentMap.get(t.name);if("valueAsDate"in e&&null!=e.value&&null!=t.value){const i=new ResizeObserver((()=>{switch(e.value=void 0,t.field.type){case"date":e.value=S(t.value,this.timeZone).date??"";break;case"timestamp-offset":e.value=U(t.value,this.timeZone).date??"";break;default:e.value=`${t.value}`}i.unobserve(e)}));i.observe(e)}if(null!=o)switch(i){case"date":o.date=e;break;case"time":o.time=e;break;case"timeZone":o.timeZone=e}else this._dateComponentMap.set(t.name,{[i]:e});this._afterDateComponentCreateOrUpdate(e)}_afterDateComponentCreateOrUpdate(e){this._afterComponentCreateOrUpdate(e)}_afterComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e);I(t)&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._afterComponentCreateOrUpdate(e)}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,i=e.querySelector("calcite-radio-button"),o=t||i;o&&this._afterComponentCreateOrUpdate(o)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),o=t.findField(this._focusedFieldName);this._attemptFocusOnNextRender&&o===i&&(this._attemptFocusOnNextRender=!1,w(i)&&(i.group.open=!0),G(e))}_onComponentFocus(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);this._focusedFieldName=i.name}_onComponentBlur(e){const t=e.target;this._focusedFieldName=null;"readOnly"in t&&t.readOnly||this._saveValueFromComponent(t)}_saveValueFromDateComponent(e){const{timeZone:t}=this,i=this._getFieldInputFromHTMLElement(e),o=i.field.type,{name:s,range:n}=i,a=this._dateComponentMap.get(s);if(!a)return;let r=this.viewModel.getValue(s),l=null;"date-only"===o?l=Array.isArray(e.value)?e.value[0]:e.value:"time-only"===o?(r=E(r),l=E(e.value)):l="timestamp-offset"===o?null!=e.value?j({dateComponent:a.date,timeComponent:a.time,timeZoneComponent:a.timeZone,oldValue:r,defaultTimeZone:t}):null:null!=e.value?P({oldValue:r,dateComponent:a.date,timeComponent:a.time,timeZone:t,max:n.max,min:n.min}):null,null!==l&&e.value?r!==l&&this._updateFieldValue(s,l):this._updateFieldValue(s,null)}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e),i=this._parseValue(e),o=t.value;t.isSubtypeField&&N(this.layer,o,i)?this._pendingSubtypeChoice||i===o||(this._pendingSubtypeChoice=this._handleSubtypeChoice(t,i)):this._updateFieldValue(t.name,i)}async _handleSubtypeChoice(e,t){const{value:i,name:o}=e,{messages:n,viewModel:a,messagesCommon:r,_subtypes:l}=this;if(this._updateFieldValue(o,t),!l?.length)return;const d=l.find((e=>e.code===t)),c=l.find((e=>e.code===i))?.name??`${i}`;if(!d)return;const u=s();a.pendingSubtypeChoice=u;let p="update-fields";const m=[{label:n.subtypes.useDefaultValuesOption,value:"update-fields"},{label:n.subtypes.keepCurrentValuesOption,value:"keep-existing"}],h={context:"info",title:n.subtypes.changeWarningTitle,message:q(n.subtypes.changeWarning,{originalType:c,newType:d.name}),radios:m,defaultRadioSelection:"update-fields",onRadioSelection:e=>p=e,actions:{primary:{label:r.apply,action:()=>u.resolve(p),type:"positive"},secondary:{label:r.cancel,type:"neutral",action:()=>u.resolve("undo")}},cancel:()=>u.reject()};try{this.showPrompt(h);switch(await u.promise){case"update-fields":a.applySubtypeDefaults(d),this._validateContingenciesForNonNullFields();break;case"keep-existing":this._validateContingenciesForNonNullFields();break;case"undo":this._updateFieldValue(e.name,i)}}finally{a.pendingSubtypeChoice=null,this.clearPrompt(),this._pendingSubtypeChoice=null}}_onComponentKeyDown({key:e,target:t}){const i=this._getFieldInputFromHTMLElement(t);"Enter"===e&&w(i)&&!i.group.open&&(i.group.open=!0)}_updateFieldValue(e,t){const i=this.viewModel.getValue(e);this.viewModel.setValue(e,t),this._inputsWithChanges.add(e);i!==t&&this.viewModel.fieldsWithContingentValues.has(e)&&this._validateContingenciesForNonNullFields()}_validateContingenciesForNonNullFields(){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;return R(t.element,"switch")?e.checked?t.element.input.onValue:t.element.input.offValue:null==i||""===i?null:"number"===t.dataType?"-0"===i||"-0."===i||"-0,"===i?i:parseFloat(i):"date"===t.field.type?parseFloat(i):i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:o}=e;0===o.length&&t&&"selected"in t?t.selected=!0:i.getLogger(this).warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupToggle(e,t){e.open?(t.open=!0,this._focusedFieldName=this._getFocusableInput("forward",t)?.name||null,this._attemptFocusOnNextRender=!0,"sequential"===this.groupDisplay&&this.viewModel.allGroupInputs.forEach((e=>{e!==t&&(e.open=!1)}))):t.open=!1,this.scheduleRender()}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}_onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;e&&this._listObserverNode&&e.showAllEnabled&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}_syncGroupInputStates(){if("sequential"!==this.groupDisplay)return;const e=this.viewModel.allGroupInputs;if(!e.length)return;const t=e.filter((e=>e.open));0===t.length?e[0].open=!0:t.length>1&&t.slice(1).forEach((e=>e.open=!1))}get test(){return{inputsWithChanges:this._inputsWithChanges,updateValue:this._saveValueFromComponent.bind(this)}}};e([l()],J.prototype,"_listObserverNode",void 0),e([l()],J.prototype,"_relatedRecordsEnabled",null),e([l()],J.prototype,"_utilityNetworkAssociationsEnabled",null),e([l()],J.prototype,"_prompt",void 0),e([l()],J.prototype,"_subtypes",null),e([l()],J.prototype,"associationId",null),e([l()],J.prototype,"associatedLayer",null),e([l()],J.prototype,"disabled",null),e([l()],J.prototype,"feature",null),e([l()],J.prototype,"_featureFormUNAssociationList",void 0),e([l()],J.prototype,"formTemplate",null),e([l()],J.prototype,"groupDisplay",void 0),e([l()],J.prototype,"headingLevel",void 0),e([l()],J.prototype,"icon",null),e([l()],J.prototype,"label",null),e([l()],J.prototype,"layer",null),e([l()],J.prototype,"map",null),e([l(),W("esri/widgets/FeatureForm/t9n/FeatureForm")],J.prototype,"messages",void 0),e([l(),W("esri/t9n/common")],J.prototype,"messagesCommon",void 0),e([l(),W("esri/widgets/Feature/t9n/Feature")],J.prototype,"messagesFeature",void 0),e([l(),W("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],J.prototype,"messagesTemplates",void 0),e([l()],J.prototype,"callbacks",null),e([l()],J.prototype,"relationshipId",null),e([l()],J.prototype,"spatialReference",null),e([l()],J.prototype,"strict",null),e([l()],J.prototype,"timeZone",null),e([l()],J.prototype,"showPrompt",null),e([l()],J.prototype,"clearPrompt",null),e([l(),B(["value-change","submit"])],J.prototype,"viewModel",void 0),e([l({type:L,nonNullable:!0})],J.prototype,"visibleElements",void 0),e([l()],J.prototype,"test",null),J=e([d("esri.widgets.FeatureForm")],J);const Q=J;export{Q as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import"../core/has.js";import i from"../core/Logger.js";import{getOrCreateMapValue as o}from"../core/MapUtils.js";import{createResolver as s}from"../core/promiseUtils.js";import{watch as n,initial as a,whenOnce as r}from"../core/reactiveUtils.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import{subclass as d}from"../core/accessorSupport/decorators/subclass.js";import{isIntegerField as c}from"../layers/support/fieldUtils.js";import{isSubtypeGroupLayer as u,getSubtypesFromLayer as p}from"../layers/support/layerUtils.js";import{isString as m}from"../support/guards.js";import h from"./Widget.js";import{Prompt as v}from"./Editor/components/Prompt.js";import _ from"./Feature/FeatureUtilityNetworkAssociations.js";import{isRelatableFeatureSupportedLayer as g}from"./Feature/support/featureUtils.js";import{css as b}from"./FeatureForm/css.js";import{isGroupInput as f,isFieldInput as y,isRelationshipInput as C,isTextElementInput as F,isUtilityNetworkAssociationInput as w,flattenInputs as R,isInputInGroupInput as k,isFieldElementWithInputType as I,getErrorMessageForFieldInput as O,getIconForFeature as N,isNumberFieldInput as M,subtypeChangeShouldPrompt as L}from"./FeatureForm/featureFormUtils.js";import T from"./FeatureForm/FeatureFormViewModel.js";import A from"./FeatureForm/VisibleElements.js";import x from"./FeatureForm/FeatureFormUtilityNetworkAssociations/FeatureFormUtilityNetworkAssociationList.js";import{loadCalciteComponents as D}from"./support/componentsUtils.js";import{getLabelForDateFieldValue as V,getIntlOptionsForField as S,numberingSystem as U,prepareISOFieldValueForDateComponents as E,prepareUnixFieldValueForDateComponents as j,normalizeTimeOnlyString as P,getISOFieldValueFromDateComponents as $,getUnixFieldValueFromDateComponents as H}from"./support/dateUtils.js";import{globalCss as Z}from"./support/globalCss.js";import{Heading as G,incrementHeadingLevel as W}from"./support/Heading.js";import{setFocus as B}from"./support/widgetUtils.js";import{messageBundle as K}from"./support/decorators/messageBundle.js";import{vmEvent as q}from"./support/decorators/vmEvent.js";import{tsx as z}from"./support/jsxFactory.js";import{substitute as J}from"../intl/substitute.js";import{formatNumber as Q}from"../intl/number.js";const X="data-field-name";let Y=class extends h{constructor(e,t){super(e,t),this._associationsWidgetsMap=new Map,this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName=null,this._pendingSubtypeChoice=null,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this._prompt=null,this._featureFormUNAssociationList=null,this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new T,this.visibleElements=new A,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,callbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t,i)=>{const{feature:o,callbacks:s}=this;let n=i;if(o&&s?.addRelatedRecord){if(u(i)&&e.activeCategory){const t=e.activeCategory.value,o=i.findSublayerForSubtypeCode(t);o&&g(o)&&(n=o)}s.addRelatedRecord({parentFeature:o,relatedLayer:n,relationshipId:t})}},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupToggle=this._onGroupToggle.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreate=this._afterComponentCreate.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this)}initialize(){this.addHandles([n((()=>this.feature),(()=>{this._inputsWithChanges.clear(),this._dateComponentMap.clear(),r((()=>!this.viewModel.updating)).then((()=>{const e=this._getFocusableInput("forward");this._syncGroupInputStates(),this._focusedFieldName=e?.name||null,this._attemptFocusOnNextRender=!0}))})),n((()=>[this._featureFormUNAssociationList,this.visibleElements.associationDetails]),(([e,t])=>{e&&(e.visibleElements.associationDetails=t)}),a),n((()=>this.groupDisplay),(()=>this._syncGroupInputStates())),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()}})),n((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange())),n((()=>this.viewModel.activeAssociationInput),(e=>{e&&this._featureFormUNAssociationList&&(this._featureFormUNAssociationList.associationInput=e,this._featureFormUNAssociationList.viewModel=e.viewModel)}))])}loadDependencies(){return D({block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),chip:()=>import("@esri/calcite-components/dist/components/calcite-chip"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),"text-area":()=>import("@esri/calcite-components/dist/components/calcite-text-area")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const{callbacks:e}=this;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get _utilityNetworkAssociationsEnabled(){const{callbacks:e}=this;return!(!e?.viewAssociatedLayers||!e.viewAssociatedFeatures)}get _subtypes(){return p(this.layer)}get associationId(){return this.viewModel.associationId}set associationId(e){this.viewModel.associationId=e}get associatedLayer(){return this.viewModel.associatedLayer}set associatedLayer(e){this.viewModel.associatedLayer=e}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 icon(){return"form-field"}set icon(e){this._overrideIfSome("icon",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 callbacks(){return this.viewModel.callbacks}set callbacks(e){this.viewModel.callbacks=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 timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get showPrompt(){return e=>{this._prompt?.cancel?.(),this._prompt=e}}set showPrompt(e){this._overrideIfSome("showPrompt",e)}get clearPrompt(){return()=>this._prompt=null}set clearPrompt(e){this._overrideIfSome("clearPrompt",e)}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return z("div",{class:this.classes(b.base,Z.widget,Z.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return z("div",null,z("form",{class:b.form,novalidate:!0,onkeydown:this._onFormKeyDown,onsubmit:this._onFormSubmit},this._renderHeader(),this._renderContent()),this._prompt?z(v,{...this._prompt,headingLevel:this.headingLevel}):void 0)}_renderHeader(){const e=this.viewModel,{formTitle:t,formDescription:i}=e;if(!e.formHeaderVisible)return;const o=null!=t&&z(G,{key:"title",level:this.headingLevel},t),s=null!=i&&z("p",{class:b.description,key:"description"},i);return z("div",{class:b.formHeader},o,s)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderRelationshipInput(e.activeRelationshipInput):e.activeAssociationInput?this._renderFeatureFormUtilityNetworkAssociationList():e.inputs.filter(t).filter((e=>e.visible)).map((e=>this._renderInput(e)))}_renderInput(e){return f(e)?this._renderGroup(e):y(e)?this._renderLabeledField(e):C(e)?this._renderRelationshipInput(e):F(e)?this._renderTextElementInput(e):w(e)?this._renderUtilityNetworkAssociationsElementInput(e):void 0}_renderFeatureFormUtilityNetworkAssociationList(){return this._featureFormUNAssociationList?.render()}_selectAssociatedLayer(e){const{feature:t,callbacks:i}=this;t&&i?.viewAssociatedFeatures&&i.viewAssociatedFeatures({associatedLayer:e.layer})}async _selectAssociatedFeature(e){const{feature:t,callbacks:i}=this;t&&i?.selectAssociatedFeature&&await i.selectAssociatedFeature({parentFeature:t,...e})}_onAddAssociation(e){const{feature:t,callbacks:i}=this;t&&i?.addAssociation&&i.addAssociation(e)}_setUpUtilityNetworkAssociationList(){this._featureFormUNAssociationList||(this._featureFormUNAssociationList=new x({onSelectLayer:this._selectAssociatedLayer.bind(this),onSelectFeature:this._selectAssociatedFeature.bind(this),onAddAssociation:this._onAddAssociation.bind(this)}))}_renderUtilityNetworkAssociationsElementInput(e){if(this._utilityNetworkAssociationsEnabled)return this._setUpUtilityNetworkAssociationList(),o(this._associationsWidgetsMap,e,(()=>new _({onSelectAssociationType:({viewModel:t,listType:i})=>{t.activeAssociationType=i;const{feature:o,callbacks:s}=this;o&&s?.viewAssociatedLayers&&s.viewAssociatedLayers({associationId:e.uid})},viewModel:e.associationsViewModel}))).render()}_renderDescriptionOrEmpty(e,t){return null==e?null:z("div",{class:this.classes(b.description),id:t},e)}_renderGroup(e){const{disabled:t,formTemplate:i,headingLevel:o}=this,{description:s,id:n,inputs:a,label:r,open:l}=e,d=a.filter((e=>e.visible)),c=this.viewModel.findField(this._focusedFieldName),u=c?.group===e,p="sequential"===this.groupDisplay;return z("calcite-block",{class:this.classes(b.group,p?b.groupSequential:null,u?b.groupActive:null,t?b.inputDisabled:null),collapsible:!0,"data-group":e,description:s||void 0,disabled:t,heading:r??"",headingLevel:i?.title?W(o):o,id:n,key:n,open:l,onCalciteBlockToggle:({currentTarget:t})=>this._onGroupToggle(t,e)},d.map((e=>this._renderInput(e))))}_getFocusableInput(e,t){const i=R(this.viewModel.inputs);let o;if("backward"===e&&i.reverse(),t)if(f(t)){const e=t.inputs.find((e=>e.visible));o=e?i.indexOf(e):0}else{let s;if(k(t)&&!t.group.open){const i=t.group.inputs.filter(y);s="forward"===e?i[i.length-1]:i[0]}else s=t;o=i.indexOf(s)+1}else o=0;for(let s=o;s<i.length;s++){const e=i[s];if(e.visible&&y(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:o,layer:s,required:n}=e,a={"aria-label":n?J(this.messages.requiredFieldLabel,{name:o}):o,class:b.label,key:`${s.id}-${i.uid}-${e.name}`},r=[z("div",{class:b.labelTextContent,key:"labelTextContainer"},o,n?z("span",{"aria-hidden":"true",title:this.messagesCommon.required},"*"):void 0),"unsupported"!==t?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e)];return"date"===t&&"coded-value"!==e.domain?.type?z("label",{...a},r):z("calcite-label",{...a},r)}_renderFieldInput(e){const{dataType:t,domain:i,inputType:o,name:s}=e,n=this.getCommonInputProps(e);if("coded-value"===i?.type){const t=this.viewModel.getFieldValueOptionsForField(s,this.messages.empty);return"switch"!==o||e.hasInvalidSwitchValue?"radio-buttons"===o?this._renderRadioButtonComponents(e,t.flat(),n):this._renderComboBoxComponent(e,t,n):this._renderSwitchComponent(e,n)}return"datetime-picker"===o||"date"===t?this._renderDateComponents(e,n):"number"===t?this._renderNumberComponent(e,n):this._renderStringComponent(e,n)}_renderStringComponent(e,t){return"text-area"===e.inputType?t.readOnly?z("calcite-input",{...t,loading:e.updating,type:"textarea",onCalciteInputInput:e=>this._saveValueFromComponent(e.currentTarget)}):z("calcite-text-area",{...t,resize:"vertical",onCalciteTextAreaInput:e=>this._saveValueFromComponent(e.currentTarget)}):z("calcite-input",{...t,loading:e.updating,type:"text",onCalciteInputInput:e=>this._saveValueFromComponent(e.currentTarget)})}_renderNumberComponent(e,t){const i=c(e.field),o=i&&""!==t.value?Math.round(parseFloat(t.value)).toString():t.value;return z("calcite-input-number",{...t,integer:i,loading:e.updating,type:"number",value:o,onCalciteInputNumberInput:e=>this._saveValueFromComponent(e.currentTarget)})}_renderDateComponents(e,t){const{field:i}=e;switch(i.type){case"date":return this._renderDateFieldComponents(e,t);case"date-only":return this._renderDateOnlyFieldComponent(e,t);case"time-only":return this._renderTimeOnlyFieldComponent(e,t);case"timestamp-offset":return this._renderTimestampOffsetFieldComponents(e,t);default:return this._renderReadOnlyComponent(e,V(i,t.value,{timeZone:this.timeZone,...S(i)}))}}_renderDateOnlyFieldComponent(e,t){const{range:i,valid:o,value:s}=e,{class:n,key:a,readOnly:r}=t,{rawMax:l,rawMin:d}=i;return z("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!o,class:n,"data-date-part":"date","data-field-name":t[X],key:`${a}-date-input`,max:m(l)?l:void 0,min:m(d)?d:void 0,numberingSystem:U,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:r,value:null!=s?`${s}`:void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)})}_renderTimeOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:s,key:n,readOnly:a}=t;return z("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:s,"data-date-part":"time","data-field-name":t[X],key:`${n}-time-input`,numberingSystem:U,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:a,step:e.timeStep,value:null!=o?`${o}`:void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)})}_renderTimestampOffsetFieldComponents(e,t){const{name:i,range:o,timeZone:s,valid:n,value:a}=e,{class:r,key:l,readOnly:d}=t,{rawMax:c,rawMin:u}=o,p={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!n,numberingSystem:U,overlayPositioning:"fixed",readOnly:d,[X]:i,onfocus:this._onComponentFocus},m=E(c,s),h=E(u,s),v=E(a,s);return z("div",{class:b.dateInputContainer,key:`${l}-date-time-container`},z("calcite-input-date-picker",{...p,class:r,"data-date-part":"date",key:`${l}-date-input`,max:m?.date??void 0,min:h?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:v.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),z("calcite-input-time-picker",{...p,class:r,"data-date-part":"time",key:`${l}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:e.timeStep,value:v.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),e.includeTimeOffset?z("calcite-input-time-zone",{...p,class:r,"data-date-part":"timeZone",disabled:d,key:`${l}-timezone-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:v.timeZoneOffset??"0",onCalciteInputTimeZoneChange:e=>this._saveValueFromDateComponent(e.currentTarget)}):null)}_renderDateFieldComponents(e,t){const{includeTime:i,name:o,valid:s,value:n}=e,{class:a,key:r,max:l,min:d,readOnly:c}=t,{timeZone:u}=this,p={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!s,numberingSystem:U,overlayPositioning:"fixed",readOnly:c,[X]:o,onfocus:this._onComponentFocus},m=j(n,u),h=j(l,u),v=j(d,u);return z("div",{class:b.dateInputContainer,key:`${r}-date-time-container`},z("calcite-input-date-picker",{...p,class:a,"data-date-part":"date",key:`${r}-date-input`,max:h?.date??void 0,min:v?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:m.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),i?z("calcite-input-time-picker",{...p,class:a,"data-date-part":"time",key:`${r}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:1,value:m.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return z("calcite-input",{...i,class:this.classes(b.fieldInput,b.inputDisabled),readOnly:!0,type:"text",value:null!=t?`${t}`:i.value})}_renderComboBoxComponent(e,t,i){const{value:o,name:s}=e,{viewModel:n,_inputsWithChanges:a}=this,r="INSERT"===n.arcadeEditType,l=a.has(s),d=null==o&&(!r||l),c=r&&e.showNoValueOptionEnabled&&!l?()=>{}:i.onblur;return z("calcite-combobox",{...i,allowCustomValues:!1,clearDisabled:!0,disabled:i.readOnly,onblur:c,overlayPositioning:"fixed",selectionMode:"single",onCalciteComboboxChange:({currentTarget:t})=>{d&&0===t.selectedItems.length?this._ignoreDeselectionOfNoValueOption(t):e.isSubtypeField&&0===t.selectedItems.length?t.value=`${e.value}`:this._saveValueFromComponent(t)}},this.renderComboboxOptionsList(e,t))}renderComboboxOptionsList(e,t){const{value:i,name:o}=e,{messages:s,messagesTemplates:n,viewModel:a,_inputsWithChanges:r}=this,[l,d,c]=t.map((e=>e.map((({name:e,value:t})=>z("calcite-combobox-item",{key:`#${t}`,selected:i===t,textLabel:e,value:`${t}`}))))),u=[];d.length>0&&u.push(z("calcite-combobox-item-group",{key:"other",label:n.other},d)),c.length>0&&u.push(z("calcite-combobox-item-group",{key:"unsupported",label:s.subtypes.unsupportedDomainGroupTitle},c)),u.length>0?u.unshift(z("calcite-combobox-item-group",{key:"recommended",label:s.recommended},l)):u.push(...l);const p="INSERT"===a.arcadeEditType,m=r.has(o),h=null==i&&(!p||m);return e.showNoValueOptionEnabled&&u.unshift(z("calcite-combobox-item",{key:"empty-option",selected:h,textLabel:e.showNoValueLabel||s.empty,value:""})),u}_renderRadioButtonComponents(e,t,i){const{name:o,value:s}=e,n=t.map((({name:e,value:t})=>this._renderRadioButtonComponent({key:e,label:e,name:o,value:t,selected:t===s,props:i})));if(e.showNoValueOptionEnabled){const t="",a=e.showNoValueLabel||this.messages.empty,r=s===t||null===s;n.unshift(this._renderRadioButtonComponent({key:"empty-option",label:a,name:o,value:t,selected:r,props:i}))}return z("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:b.inputRadioGroup,"data-field-name":i[X],key:`${i.key}-radio-group`,layout:"vertical",name:i.key,required:i.required},n)}_renderSwitchComponent(e,t){const{value:i}=e,o=!!I(e.element,"switch")&&i===e.element.input.onValue;return z("calcite-switch",{...t,checked:o,class:b.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldName=null},onCalciteSwitchChange:e=>this._saveValueFromComponent(e.currentTarget)})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:o,label:s,props:n}){return z("calcite-label",{class:b.inputRadioLabel,key:e,layout:"inline"},z("calcite-radio-button",{...n,afterCreate:void 0,afterUpdate:void 0,checked:o,class:b.inputRadio,disabled:n.readOnly,name:t,onblur:()=>{this._focusedFieldName=null},value:i,onCalciteRadioButtonChange:({currentTarget:e})=>{e.checked&&this._saveValueFromComponent(e)}}),s)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.submittable?O(e,this.messages,this.timeZone):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?z("calcite-input-message",{icon:!0,status:"invalid"},i):this._inputsWithChanges.has(t)&&e.valueIsOutOfDomain?z("calcite-input-message",{icon:!0,status:"idle"},this.messages.subtypes.fieldOutOfSubtypeDomainWarning):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){if(!e.showAllActionVisible||!this.callbacks?.showAllRelatedRecords)return;const t=this.messages;return z("calcite-list-item",{description:J(t.totalCount,{count:e.featureCount}),key:"show-all-related-features",label:t.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(e.relationshipId)},z("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:o}=e,{messages:s,callbacks:n}=this;if(t&&n?.addRelatedRecord&&o)return z("calcite-button",{alignment:"center",appearance:"outline-fill",class:b.centeredButton,disabled:e.updating||!e.originHasValidKey,iconStart:"plus",key:`${i}-add-button`,onclick:()=>{!e.updating&&e.originHasValidKey&&this._onAddRelatedRecordsClick(e,i,o)},round:!0,scale:"s",width:"full"},e.relatedLayerIsTable?s.addRecord:s.addFeature)}_renderRelatedRecordListItem(e,t){const{feature:i,description:o,title:s}=e,{feature:n,callbacks:a}=this,{highlightHelper:r}=this.viewModel,l=()=>{r?.removeAll(),a?.editRelatedRecord&&n&&a.editRelatedRecord({parentFeature:n,relationshipId:t,relatedFeature:i})},d=r?()=>r.add(i):void 0,c=r?()=>r.remove(i):void 0;return z("calcite-list-item",{bind:this,description:o,key:`${t}-${i.uid}`,label:s,onclick:l,onmouseenter:d,onmouseleave:c,value:s},z("calcite-icon",{icon:N(i),slot:"content-start"}),z("calcite-icon",{icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderRelationshipInput(e){if(!this._relatedRecordsEnabled||!e.editable)return;const{relationshipId:t,activeCategory:i}=e,o=i?null:this._renderDescriptionOrEmpty(e.description);return z("calcite-label",{class:this.classes(b.label,b.relatedRecordsLabel),key:`relationship-${t}-container`},z("div",null,this._renderRelatedRecordsHeaderContainer(e),o,this._renderRelationshipInputContent(e)),this._renderAddRelatedRecordButton(e))}_renderRelationshipInputContent(e){return e.featureCount>0?this._renderRelatedRecordsList(e):e.activeCategory&&0===e.featureCount?this._renderNoRelatedRecordsNotice():e.allCategories?.length?this._renderCategoryList(e):e.loaded?e.originHasValidKey?this._renderNoRelatedRecordsNotice():this._renderNoValidOriginKeyNotice(e):void 0}_renderCategoryList(e){return z("calcite-list",{displayMode:"flat",label:this.messages.relatedRecordsList,loading:e.updating},e.categories?.map((t=>this._renderCategory(e,t))),this._renderShowAllCategoriesListItem(e))}_renderCategory(e,t){const{count:i,name:o,value:s}=t,n=Q(i);return z("calcite-list-item",{key:`${o}-${s}`,label:o,onCalciteListItemSelect:()=>this._selectCategory(e,t)},z("calcite-chip",{label:n,scale:"s",slot:"content-end"},n),z("calcite-icon",{flipRtl:!0,icon:"chevron-left",scale:"s",slot:"content-end"}))}_selectCategory(e,t){this.relationshipId=e.relationshipId,e.activeCategory=t}_renderShowAllCategoriesListItem(e){if(!e.showAllCategoriesVisible)return;const t=this.messages;return z("calcite-list-item",{description:J(t.totalCount,{count:e.allCategories?.length??0}),key:"show-all-categories",label:t.showAll,value:!0,onCalciteListItemSelect:()=>e.showAllEnabled=!0},z("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return z("div",{class:b.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},z("span",null,e.label),t?z("calcite-loader",{inline:!0,key:"loader",label:this.messagesCommon?.loading,scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return z("calcite-list",{class:b.relatedRecordsList,label:this.messages?.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoValidOriginKeyNotice(e){const{messages:t}=this,i=e.relatedLayerIsTable?t.noOriginKeyRecord:t.noOriginKeyFeature,o=e.relationship?.keyField,s=this.viewModel.findField(o),n=e.layer?.fieldsIndex.get(o),a=s?.label||n?.alias||o,r=J(i,{relatedLayerName:e.relatedLayer?.title,originKeyField:a});return z("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},z("div",{slot:"message"},r))}_renderNoRelatedRecordsNotice(){return z("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},z("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return z("div",{afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved,bind:this,class:b.listObserver,key:"feature-observer"})}_renderTextElementInput(e){return z("div",{class:b.textElement,innerHTML:e.text,key:e.id})}getCommonInputProps(e){const{disabled:t}=this,{editable:i,hint:o,label:s,maxLength:n,minLength:a,name:r,range:{max:l,min:d},required:c,valid:u,value:p}=e,m=this._inputsWithChanges.has(r),h=!i||t;return{afterCreate:this._afterComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":u?"false":"true",class:this.classes(b.fieldInput,h?b.inputDisabled:null),status:m&&!u?"invalid":"idle",key:r,label:s,max:null!=l?l:void 0,min:null!=d?d:void 0,maxLength:n>-1?n:void 0,minLength:a>-1?a:void 0,placeholder:o??void 0,readOnly:h,required:c,value:null==p?"":`${p}`,onblur:this._onComponentBlur,onfocus:this._onComponentFocus,onkeydown:this._onComponentKeyDown,[X]:r}}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(X))}_afterDateComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e),i=e.dataset.datePart,o=this._dateComponentMap.get(t.name);if("valueAsDate"in e&&null!=e.value&&null!=t.value){const i=new ResizeObserver((()=>{switch(e.value=void 0,t.field.type){case"date":e.value=j(t.value,this.timeZone).date??"";break;case"timestamp-offset":e.value=E(t.value,this.timeZone).date??"";break;default:e.value=`${t.value}`}i.unobserve(e)}));i.observe(e)}if(null!=o)switch(i){case"date":o.date=e;break;case"time":o.time=e;break;case"timeZone":o.timeZone=e}else this._dateComponentMap.set(t.name,{[i]:e});this._afterDateComponentCreateOrUpdate(e)}_afterDateComponentCreateOrUpdate(e){this._afterComponentCreateOrUpdate(e)}_afterComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e);M(t)&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._afterComponentCreateOrUpdate(e)}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,i=e.querySelector("calcite-radio-button"),o=t||i;o&&this._afterComponentCreateOrUpdate(o)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),o=t.findField(this._focusedFieldName);this._attemptFocusOnNextRender&&o===i&&(this._attemptFocusOnNextRender=!1,k(i)&&(i.group.open=!0),B(e))}_onComponentFocus(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);this._focusedFieldName=i.name}_onComponentBlur(e){const t=e.target;this._focusedFieldName=null;"readOnly"in t&&t.readOnly||this._saveValueFromComponent(t)}_saveValueFromDateComponent(e){const{timeZone:t}=this,i=this._getFieldInputFromHTMLElement(e),o=i.field.type,{name:s,range:n}=i,a=this._dateComponentMap.get(s);if(!a)return;let r=this.viewModel.getValue(s),l=null;"date-only"===o?l=Array.isArray(e.value)?e.value[0]:e.value:"time-only"===o?(r=P(r),l=P(e.value)):l="timestamp-offset"===o?null!=e.value?$({dateComponent:a.date,timeComponent:a.time,timeZoneComponent:a.timeZone,oldValue:r,defaultTimeZone:t}):null:null!=e.value?H({oldValue:r,dateComponent:a.date,timeComponent:a.time,timeZone:t,max:n.max,min:n.min}):null,null!==l&&e.value?r!==l&&this._updateFieldValue(s,l):this._updateFieldValue(s,null)}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e),i=this._parseValue(e),o=t.value;t.isSubtypeField&&L(this.layer,o,i)?this._pendingSubtypeChoice||i===o||(this._pendingSubtypeChoice=this._handleSubtypeChoice(t,i)):this._updateFieldValue(t.name,i)}async _handleSubtypeChoice(e,t){const{value:i,name:o}=e,{messages:n,viewModel:a,messagesCommon:r,_subtypes:l}=this;if(this._updateFieldValue(o,t),!l?.length)return;const d=l.find((e=>e.code===t)),c=l.find((e=>e.code===i))?.name??`${i}`;if(!d)return;const u=s();a.pendingSubtypeChoice=u;let p="update-fields";const m=[{label:n.subtypes.useDefaultValuesOption,value:"update-fields"},{label:n.subtypes.keepCurrentValuesOption,value:"keep-existing"}],h={context:"info",title:n.subtypes.changeWarningTitle,message:J(n.subtypes.changeWarning,{originalType:c,newType:d.name}),radios:m,defaultRadioSelection:"update-fields",onRadioSelection:e=>p=e,actions:{primary:{label:r.apply,action:()=>u.resolve(p),type:"positive"},secondary:{label:r.cancel,type:"neutral",action:()=>u.resolve("undo")}},cancel:()=>u.reject()};try{this.showPrompt(h);switch(await u.promise){case"update-fields":a.applySubtypeDefaults(d),this._validateContingenciesForNonNullFields();break;case"keep-existing":this._validateContingenciesForNonNullFields();break;case"undo":this._updateFieldValue(e.name,i)}}finally{a.pendingSubtypeChoice=null,this.clearPrompt(),this._pendingSubtypeChoice=null}}_onComponentKeyDown({key:e,target:t}){const i=this._getFieldInputFromHTMLElement(t);"Enter"===e&&k(i)&&!i.group.open&&(i.group.open=!0)}_updateFieldValue(e,t){const i=this.viewModel.getValue(e);this.viewModel.setValue(e,t),this._inputsWithChanges.add(e);i!==t&&this.viewModel.fieldsWithContingentValues.has(e)&&this._validateContingenciesForNonNullFields()}_validateContingenciesForNonNullFields(){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;return I(t.element,"switch")?e.checked?t.element.input.onValue:t.element.input.offValue:null==i||""===i?null:"number"===t.dataType?"-0"===i||"-0."===i||"-0,"===i?i:parseFloat(i):"date"===t.field.type?parseFloat(i):i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:o}=e;0===o.length&&t&&"selected"in t?t.selected=!0:i.getLogger(this).warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupToggle(e,t){e.open?(t.open=!0,this._focusedFieldName=this._getFocusableInput("forward",t)?.name||null,this._attemptFocusOnNextRender=!0,"sequential"===this.groupDisplay&&this.viewModel.allGroupInputs.forEach((e=>{e!==t&&(e.open=!1)}))):t.open=!1,this.scheduleRender()}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}_onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;e&&this._listObserverNode&&e.showAllEnabled&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}_syncGroupInputStates(){if("sequential"!==this.groupDisplay)return;const e=this.viewModel.allGroupInputs;if(!e.length)return;const t=e.filter((e=>e.open));0===t.length?e[0].open=!0:t.length>1&&t.slice(1).forEach((e=>e.open=!1))}get test(){return{inputsWithChanges:this._inputsWithChanges,updateValue:this._saveValueFromComponent.bind(this)}}};e([l()],Y.prototype,"_listObserverNode",void 0),e([l()],Y.prototype,"_relatedRecordsEnabled",null),e([l()],Y.prototype,"_utilityNetworkAssociationsEnabled",null),e([l()],Y.prototype,"_prompt",void 0),e([l()],Y.prototype,"_subtypes",null),e([l()],Y.prototype,"associationId",null),e([l()],Y.prototype,"associatedLayer",null),e([l()],Y.prototype,"disabled",null),e([l()],Y.prototype,"feature",null),e([l()],Y.prototype,"_featureFormUNAssociationList",void 0),e([l()],Y.prototype,"formTemplate",null),e([l()],Y.prototype,"groupDisplay",void 0),e([l()],Y.prototype,"headingLevel",void 0),e([l()],Y.prototype,"icon",null),e([l()],Y.prototype,"label",null),e([l()],Y.prototype,"layer",null),e([l()],Y.prototype,"map",null),e([l(),K("esri/widgets/FeatureForm/t9n/FeatureForm")],Y.prototype,"messages",void 0),e([l(),K("esri/t9n/common")],Y.prototype,"messagesCommon",void 0),e([l(),K("esri/widgets/Feature/t9n/Feature")],Y.prototype,"messagesFeature",void 0),e([l(),K("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],Y.prototype,"messagesTemplates",void 0),e([l()],Y.prototype,"callbacks",null),e([l()],Y.prototype,"relationshipId",null),e([l()],Y.prototype,"spatialReference",null),e([l()],Y.prototype,"strict",null),e([l()],Y.prototype,"timeZone",null),e([l()],Y.prototype,"showPrompt",null),e([l()],Y.prototype,"clearPrompt",null),e([l(),q(["value-change","submit"])],Y.prototype,"viewModel",void 0),e([l({type:A,nonNullable:!0})],Y.prototype,"visibleElements",void 0),e([l()],Y.prototype,"test",null),Y=e([d("esri.widgets.FeatureForm")],Y);const ee=Y;export{ee as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import s from"../../core/Evented.js";import{abortMaybe as l}from"../../core/maybe.js";import{throwIfAborted as o}from"../../core/promiseUtils.js";import{watch as r,when as i,syncAndInitial as a,sync as n}from"../../core/reactiveUtils.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as m}from"../../core/support/UpdatingHandles.js";import{getTemplatesForLayers as d}from"../../editing/templateUtils.js";import{getEffectiveLayerCapabilities as c,isSubtypeGroupLayer as h}from"../../layers/support/layerUtils.js";import{isTemplateItemGroup as y,mapItemsByTemplate as f,isTemplateGroupInfo as g,loadLayerWithTemplates as _,makeTemplateItemInfos as I,makeGroupItemInfos as F,nullGroupBy as b}from"./featureTemplatesUtils.js";import v from"./TemplateItem.js";import T from"./TemplateItemGroup.js";const j=({layer:t})=>({key:t,label:t.title??""}),B=({layer:t})=>({key:t.geometryType,label:t.geometryType??""});let w=class extends s.EventedAccessor{constructor(t){super(t),this._allItems=[],this._updatingHandles=new m,this._updateTask=null,this.disabled=!1,this.disabledItemFunction=null,this.filterFunction=null,this.selectedItem=null,this.templateInfos=null,this.view=null}initialize(){this._get("groupBy")||(this.groupBy="layer"),this.addHandles([r((()=>[this.templateInfos,this.layers]),(([t],e)=>{t&&t===e?.at(0)||(this._updateTask=l(this._updateTask),t?this._updateAllItems(t):this._getTemplatesAndUpdateAllItems())}),a),r((()=>this._groupByFunction),(()=>{null==this.templateInfos&&(this._updateTask=l(this._updateTask),this._getTemplatesAndUpdateAllItems())}),n),r((()=>this.filterFunction),(t=>{for(const e of this._allItems)y(e)&&(e.filterFunction=t)}),n)])}set groupBy(t){if(this._set("groupBy",t),"function"!=typeof t)switch(t){case"layer":this._groupByFunction=j;break;case"geometry":this._groupByFunction=B;break;default:this._groupByFunction=null}else this._groupByFunction=e=>this._ensureGroupByObject(t(e))}get layers(){return this._get("layers")}set layers(t){const e="layers";if(this.removeHandles(e),t){const s=()=>this.notifyChange("state");this.addHandles(t.map((t=>i((()=>t.loadStatus),s))),e)}this._set("layers",t)}get state(){return this.updating?"loading":0!==this.layers.length||this.templateInfos?.length?"ready":"disabled"}get numberOfFeatureTemplates(){return this._allItems.reduce(((t,e)=>y(e)?t+e.allItems.length:t+1),0)}get items(){const{filterFunction:t}=this;return null==t?this._allItems:this._allItems.filter((e=>y(e)?e.items.length>0:t(e)))}get updating(){return this._updatingHandles.updating}refresh(){this.notifyChange("filterFunction");for(const t of this._allItems)y(t)&&t.reapplyFilter()}select(t,{emit:e=!0}={}){const s=this.selectedItem,l=t?.clone()||null;this._set("selectedItem",l),e&&this.emit("select",{item:l,oldItem:s,template:l?.template??null})}_createItem(t,e){return new v({disabledFunction:this.disabledItemFunction,layer:e,template:t})}_ensureGroupByObject(t){return"string"==typeof t?{key:t,label:t}:t}_updateAllItems(t){const e=this._allItems;if(0===t.length)return k(e),void(this._allItems=[]);const[s,l]=f(e),o=t=>{const e=s.get(t.template);return e?(s.delete(t.template),e):this._createItem(t.template,t.layer)},{filterFunction:r}=this,i=t.map((t=>g(t)?new T({filterFunction:r,label:t.label,allItems:t.templateInfos.map((t=>o(t)))}):o(t)));for(const a of[...s.values(),...l])a.destroy();this._allItems=i}async _getTemplatesFromLayers(t){const e=[],s={signal:t};await Promise.all(this.layers.map((async l=>{await _(l,s),o(t);const r=c(l)?.operations;r?.supportsEditing&&r?.supportsAdd&&(h(l)?e.push(...l.sublayers):e.push(l))})));const l=await d(e,this.view,t);o(t);const r=I(l),i=this._groupByFunction;if(null==i)return r;const a=F(r,i);return 1===a.length&&a[0].label===b.label?a[0].templateInfos:a}async _getTemplatesAndUpdateAllItems(){if(0===this.layers.length)return;const t=e((async t=>{const e=await this._getTemplatesFromLayers(t);o(t),this._updateAllItems(e)}));this._updateTask=t,this._updatingHandles.addPromise(t.promise)}};function k(t){for(const e of t){if(y(e))for(const t of e.items)t.destroy();e.destroy()}}t([p()],w.prototype,"_allItems",void 0),t([p()],w.prototype,"_groupByFunction",void 0),t([p()],w.prototype,"_updatingHandles",void 0),t([p()],w.prototype,"disabled",void 0),t([p()],w.prototype,"disabledItemFunction",void 0),t([p({value:null})],w.prototype,"filterFunction",void 0),t([p()],w.prototype,"groupBy",null),t([p({value:[]})],w.prototype,"layers",null),t([p()],w.prototype,"state",null),t([p({readOnly:!0})],w.prototype,"numberOfFeatureTemplates",null),t([p({readOnly:!0})],w.prototype,"items",null),t([p({readOnly:!0})],w.prototype,"selectedItem",void 0),t([p()],w.prototype,"templateInfos",void 0),t([p()],w.prototype,"updating",null),t([p()],w.prototype,"view",void 0),w=t([u("esri.widgets.FeatureTemplates.FeatureTemplatesViewModel")],w);const A=w;export{A as default};
5
+ import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import s from"../../core/Evented.js";import{abortMaybe as l}from"../../core/maybe.js";import{throwIfAborted as o}from"../../core/promiseUtils.js";import{watch as r,when as i,syncAndInitial as a,sync as n}from"../../core/reactiveUtils.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as m}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as u}from"../../core/support/UpdatingHandles.js";import{getTemplatesForLayers as d,isSharedTemplateOrMetadata as c}from"../../editing/templateUtils.js";import{getEffectiveLayerCapabilities as h,isSubtypeGroupLayer as y}from"../../layers/support/layerUtils.js";import{isTemplateItemGroup as f,mapItemsByTemplate as g,isTemplateGroupInfo as _,loadLayerWithTemplates as I,makeTemplateItemInfos as F,makeGroupItemInfos as b,nullGroupBy as v}from"./featureTemplatesUtils.js";import T from"./TemplateItem.js";import j from"./TemplateItemGroup.js";const B=({layer:t})=>({key:t,label:t.title??""}),w=({layer:t})=>({key:t.geometryType,label:t.geometryType??""});let k=class extends s.EventedAccessor{constructor(t){super(t),this._allItems=[],this._updatingHandles=new u,this._updateTask=null,this.disabled=!1,this.disabledItemFunction=null,this.filterFunction=null,this.selectedItem=null,this.templateInfos=null,this.view=null}initialize(){this._get("groupBy")||(this.groupBy="layer"),this.addHandles([r((()=>[this.templateInfos,this.layers]),(([t],e)=>{t&&t===e?.at(0)||(this._updateTask=l(this._updateTask),t?this._updateAllItems(t):this._getTemplatesAndUpdateAllItems())}),a),r((()=>this._groupByFunction),(()=>{null==this.templateInfos&&(this._updateTask=l(this._updateTask),this._getTemplatesAndUpdateAllItems())}),n),r((()=>this.filterFunction),(t=>{for(const e of this._allItems)f(e)&&(e.filterFunction=t)}),n)])}set groupBy(t){if(this._set("groupBy",t),"function"!=typeof t)switch(t){case"layer":this._groupByFunction=B;break;case"geometry":this._groupByFunction=w;break;default:this._groupByFunction=null}else this._groupByFunction=e=>this._ensureGroupByObject(t(e))}get layers(){return this._get("layers")}set layers(t){const e="layers";if(this.removeHandles(e),t){const s=()=>this.notifyChange("state");this.addHandles(t.map((t=>i((()=>t.loadStatus),s))),e)}this._set("layers",t)}get state(){return this.updating?"loading":0!==this.layers.length||this.templateInfos?.length?"ready":"disabled"}get numberOfFeatureTemplates(){return this._allItems.reduce(((t,e)=>f(e)?t+e.allItems.length:t+1),0)}get items(){const{filterFunction:t}=this;return null==t?this._allItems:this._allItems.filter((e=>f(e)?e.items.length>0:t(e)))}get updating(){return this._updatingHandles.updating}refresh(){this.notifyChange("filterFunction");for(const t of this._allItems)f(t)&&t.reapplyFilter()}select(t,{emit:e=!0}={}){const s=this.selectedItem,l=t?.clone()||null;this._set("selectedItem",l),e&&this.emit("select",{item:l,oldItem:s,template:l?.template??null})}_createItem(t,e){return new T({disabledFunction:this.disabledItemFunction,layer:e,template:t})}_ensureGroupByObject(t){return"string"==typeof t?{key:t,label:t}:t}_updateAllItems(t){const e=this._allItems;if(0===t.length)return A(e),void(this._allItems=[]);const[s,l]=g(e),o=t=>{const e=s.get(t.template);return e?(s.delete(t.template),e):this._createItem(t.template,t.layer)},{filterFunction:r}=this,i=t.filter(U).map((t=>_(t)?new j({filterFunction:r,label:t.label,allItems:t.templateInfos.filter(U).map((t=>o(t)))}):o(t)));for(const a of[...s.values(),...l])a.destroy();this._allItems=i}async _getTemplatesFromLayers(t){const e=[],s={signal:t};await Promise.all(this.layers.map((async l=>{await I(l,s),o(t);const r=h(l)?.operations;r?.supportsEditing&&r?.supportsAdd&&(y(l)?e.push(...l.sublayers):e.push(l))})));const l=await d(e,this.view,t);o(t);const r=F(l),i=this._groupByFunction;if(null==i)return r;const a=b(r,i);return 1===a.length&&a[0].label===v.label?a[0].templateInfos:a}async _getTemplatesAndUpdateAllItems(){if(0===this.layers.length)return;const t=e((async t=>{const e=await this._getTemplatesFromLayers(t);o(t),this._updateAllItems(e)}));this._updateTask=t,this._updatingHandles.addPromise(t.promise)}};function A(t){for(const e of t){if(f(e))for(const t of e.items)t.destroy();e.destroy()}}function U(t){return _(t)?t.templateInfos.some(U):!c(t.template)||!1!==t.template.visible}t([p()],k.prototype,"_allItems",void 0),t([p()],k.prototype,"_groupByFunction",void 0),t([p()],k.prototype,"_updatingHandles",void 0),t([p()],k.prototype,"disabled",void 0),t([p()],k.prototype,"disabledItemFunction",void 0),t([p({value:null})],k.prototype,"filterFunction",void 0),t([p()],k.prototype,"groupBy",null),t([p({value:[]})],k.prototype,"layers",null),t([p()],k.prototype,"state",null),t([p({readOnly:!0})],k.prototype,"numberOfFeatureTemplates",null),t([p({readOnly:!0})],k.prototype,"items",null),t([p({readOnly:!0})],k.prototype,"selectedItem",void 0),t([p()],k.prototype,"templateInfos",void 0),t([p()],k.prototype,"updating",null),t([p()],k.prototype,"view",void 0),k=t([m("esri.widgets.FeatureTemplates.FeatureTemplatesViewModel")],k);const H=k;export{H as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import{createTask as t}from"../../../../core/asyncUtils.js";import a from"../../../../core/Promise.js";import{throwIfAborted as s}from"../../../../core/promiseUtils.js";import{property as i}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as r}from"../../../../core/accessorSupport/decorators/subclass.js";import{load as o}from"../../../../geometry/projection.js";import{convertSphereVertexToPixelLocation as n}from"../../../../layers/orientedImagery/transformations/utils.js";import{SketchHandlerMixin as c}from"../../mixins/SketchHandlerMixin.js";let l=[],u=[],h=0,m=class extends(c(a)){constructor(e){super(e),this.type="measurement",this.measurementArray=[],this.pixelMeasurement=0,this.pixelAreaMeasurement=0,this.polygonVertices=[],this._calculationTask=null,this._distanceCalculation=0,this._areaCalculation=null}initialize(){this.addResolvingPromise(o())}async handleCreate(e){const t=e.toolEventInfo;switch(e.tool){case"polyline":this.handlePolylineEvents(e,t);break;case"polygon":this.handlePolygonEvents(e,t)}}handleDelete(e){this.resetDistanceMeasurements(),this.resetAreaMeasurements()}handleDestroy(){this.resetDistanceMeasurements(),this.resetAreaMeasurements()}cursorUpdatePolylineHandler(e){const{mode:t,activeViewer:a}=this.viewModel;if("none"===t||!a?.imageSize)return;if("default"===t)this.measurementArray.push(e.coordinates);else{const t={x:e.coordinates[0],y:e.coordinates[1],z:e.coordinates[2]},s=n(t,a.imageSize[0],a.imageSize[1]);this.measurementArray.push([s.x,s.y])}const s=u.reduce(((e,t)=>e+t),0)+this.pixelMeasurement;this.viewModel.distanceMeasurementResult=s}async cursorUpdatePolygonHandler(e){const{mode:t,activeViewer:a}=this.viewModel;if("none"===t||!a?.imageSize)return;const s=e.coordinates;if(l=[...this.polygonVertices],"default"===t)l.push(s);else{const e={x:s[0],y:s[1],z:s[2]},t=n(e,a?.imageSize[0],a?.imageSize[1]);l.push([t.x,t.y])}if(l.length<3||!this.viewModel.currentBestFeature||!this.viewModel.activeViewer?.imageSize)return;const i=l[0];l=l.filter(((e,t)=>0===t||t===l.length-1||JSON.stringify(e)!==JSON.stringify(i)));const r=await this._getAreaFromTask(l);r?.area&&r?.perimeter&&(h=r.area)}async handlePolylineEvents(e,t){const a=!this.viewModel.accuracyParametersMissing;if("cancel"===e.state)return this.resetDistanceMeasurements(),this.viewModel.distanceMeasurementResult=0,this.viewModel.distanceAccuracyArray=[],void(this.viewModel.displayNewMeasurementButton=!0);if("complete"===e.state&&e.graphic)return this.viewModel.activeViewer?.addGraphic(e.graphic),this.viewModel.measurementGraphic=e.graphic,void this.resetDistanceMeasurements();switch(t?.type){case"cursor-update":this.cursorUpdatePolylineHandler(t);break;case"vertex-add":if(this.measurementArray.length&&a){const e=await this._getAccuracyFromTask();e&&this.viewModel.distanceAccuracyArray.push(e)}this.vertexUpdatePolylineHandler()}const s=await this._getDistanceFromTask();this.pixelMeasurement=s??this.pixelMeasurement}async handlePolygonEvents(e,t){const a=!this.viewModel.accuracyParametersMissing;if("cancel"===e.state)return this.resetAreaMeasurements(),this.viewModel.areaMeasurementResult=0,this.viewModel.areaMeasurementAccuracy=0,void(this.viewModel.displayNewMeasurementButton=!0);if("complete"===e.state&&e.graphic)return this.viewModel.activeViewer?.addGraphic(e.graphic),this.viewModel.measurementGraphic=e.graphic,void this.resetAreaMeasurements();switch(t?.type){case"vertex-add":await this.vertexAddPolygonHandler(t,a);break;case"cursor-update":await this.cursorUpdatePolygonHandler(t)}this.viewModel.areaMeasurementResult=h>0?h:this.pixelAreaMeasurement}async vertexAddPolygonHandler(e,t){const{mode:a,activeViewer:s}=this.viewModel,i=e.added,r=i[i.length-1];if(!Array.isArray(r)||"none"===a||!s?.imageSize)return;if("default"===a)this.polygonVertices.push(r);else{const e={x:r[0],y:r[1],z:r[2]},t=n(e,s?.imageSize[0],s?.imageSize[1]);this.polygonVertices.push([t.x,t.y])}if(this.polygonVertices.length<3||!this.viewModel.currentBestFeature||!this.viewModel.activeViewer?.imageSize)return;if(t){const e=await this._getAreaAccuracyFromTask(this.polygonVertices);this.viewModel.areaMeasurementAccuracy=e&&e>this.viewModel.areaMeasurementAccuracy?e:this.viewModel.areaMeasurementAccuracy}const o=this.polygonVertices[0];this.polygonVertices=this.polygonVertices.filter(((e,t)=>0===t||t===this.polygonVertices.length-1||JSON.stringify(e)!==JSON.stringify(o)));const c=await this._getAreaFromTask(this.polygonVertices);if(!c?.area||!c?.perimeter)return;const{area:l}=c;this.pixelAreaMeasurement=l}vertexUpdatePolylineHandler(){this.measurementArray=this.measurementArray.slice(-1);const e=u.reduce(((e,t)=>e+t),0)+this.pixelMeasurement;this.viewModel.distanceMeasurementResult=e,this.pixelMeasurement>0&&u.push(this.pixelMeasurement)}resetDistanceMeasurements(){this.measurementArray=[],this.pixelMeasurement=0,u=[]}resetAreaMeasurements(){this.polygonVertices=[],this.pixelAreaMeasurement=0,h=0}async _getAreaFromTask(e){const{mode:a}=this.viewModel;return this._calculationTask?.abort(),this._calculationTask=t((async t=>{this._areaCalculation=null;const i=await this.viewModel.calculateAreaMeasurement(e,a,t);s(t),this._areaCalculation=i})),await this._calculationTask.promise,this._areaCalculation}async _getDistanceFromTask(){const{mode:e}=this.viewModel;return this._calculationTask?.abort(),this._calculationTask=t((async t=>{this._distanceCalculation=0;const a=await this.viewModel.calculateDistanceMeasurement(this.measurementArray,e,t);s(t),this._distanceCalculation=a})),await this._calculationTask.promise,this._distanceCalculation}async _getAccuracyFromTask(){const{mode:e}=this.viewModel;return"none"===e?null:(this._calculationTask?.abort(),this._calculationTask=t((async t=>{this._distanceCalculation=0;const a="default"===e?await this.viewModel.calculateAccuracy(this.measurementArray,"distance",t):await this.viewModel.calculateAccuracyPanoramic(this.measurementArray,"distance",t);s(t),this._distanceCalculation=a})),await this._calculationTask.promise,this._distanceCalculation)}async _getAreaAccuracyFromTask(e){const{mode:a}=this.viewModel;return"none"===a?null:(this._calculationTask?.abort(),this._calculationTask=t((async t=>{this._distanceCalculation=0;const i="default"===a?await this.viewModel.calculateAccuracy(e,"area",t):await this.viewModel.calculateAccuracyPanoramic(e,"area",t);s(t),this._distanceCalculation=i})),await this._calculationTask.promise,this._distanceCalculation)}};e([i()],m.prototype,"type",void 0),e([i()],m.prototype,"measurementArray",void 0),e([i()],m.prototype,"pixelMeasurement",void 0),e([i()],m.prototype,"pixelAreaMeasurement",void 0),e([i()],m.prototype,"polygonVertices",void 0),m=e([r("esri.widgets.OrientedImageryViewer.adapters.sketch.MeasurementAdapter")],m);const d=m;export{d as default};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import{createTask as t}from"../../../../core/asyncUtils.js";import a from"../../../../core/Promise.js";import{throwIfAborted as s}from"../../../../core/promiseUtils.js";import{property as i}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as r}from"../../../../core/accessorSupport/decorators/subclass.js";import{load as o}from"../../../../geometry/projection.js";import{convertSphereVertexToPixelLocation as n}from"../../../../layers/orientedImagery/transformations/utils.js";import{SketchHandlerMixin as c}from"../../mixins/SketchHandlerMixin.js";let l=[],u=[],h=0,m=class extends(c(a)){constructor(e){super(e),this.type="measurement",this.measurementArray=[],this.pixelMeasurement=0,this.pixelAreaMeasurement=0,this.polygonVertices=[],this._calculationTask=null,this._distanceCalculation=0,this._areaCalculation=null}initialize(){this.addResolvingPromise(o())}async handleCreate(e){const t=e.toolEventInfo;switch(e.tool){case"polyline":this.handlePolylineEvents(e,t);break;case"polygon":this.handlePolygonEvents(e,t)}}handleDelete(e){this.resetDistanceMeasurements(),this.resetAreaMeasurements()}handleDestroy(){this.resetDistanceMeasurements(),this.resetAreaMeasurements()}cursorUpdatePolylineHandler(e){const{mode:t,activeViewer:a}=this.viewModel;if("none"===t||!a?.imageSize)return;if("default"===t)this.measurementArray.push(e.coordinates);else{const t={x:e.coordinates[0],y:e.coordinates[1],z:e.coordinates[2]},s=n(t,a.imageSize[0],a.imageSize[1]);this.measurementArray.push([s.x,s.y])}const s=u.reduce(((e,t)=>e+t),0)+this.pixelMeasurement;this.viewModel.distanceMeasurementResult=s}async cursorUpdatePolygonHandler(e){const{mode:t,activeViewer:a}=this.viewModel;if("none"===t||!a?.imageSize)return;const s=e.coordinates;if(l=[...this.polygonVertices],"default"===t)l.push(s);else{const e={x:s[0],y:s[1],z:s[2]},t=n(e,a?.imageSize[0],a?.imageSize[1]);l.push([t.x,t.y])}if(l.length<3||!this.viewModel.currentBestFeature||!this.viewModel.activeViewer?.imageSize)return;const i=l[0];l=l.filter(((e,t)=>0===t||t===l.length-1||JSON.stringify(e)!==JSON.stringify(i)));const r=await this._getAreaFromTask(l);r?.area&&r?.perimeter&&(h=r.area)}async handlePolylineEvents(e,t){const a=!this.viewModel.accuracyParametersMissing;if("cancel"===e.state)return this.resetDistanceMeasurements(),this.viewModel.distanceMeasurementResult=0,this.viewModel.distanceAccuracyArray=[],void(this.viewModel.displayNewMeasurementButton=!0);if("complete"===e.state&&e.graphic)return this.viewModel.activeViewer?.addGraphic(e.graphic),this.viewModel.measurementGraphic=e.graphic,void this.resetDistanceMeasurements();switch(t?.type){case"cursor-update":this.cursorUpdatePolylineHandler(t);break;case"vertex-add":if(this.measurementArray.length&&a){const e=await this._getAccuracyFromTask();e&&this.viewModel.distanceAccuracyArray.push(e)}this.vertexUpdatePolylineHandler()}const s=await this._getDistanceFromTask();this.pixelMeasurement=s??this.pixelMeasurement}async handlePolygonEvents(e,t){const a=!this.viewModel.accuracyParametersMissing;if("cancel"===e.state)return this.resetAreaMeasurements(),this.viewModel.areaMeasurementResult=0,this.viewModel.areaMeasurementAccuracy=0,void(this.viewModel.displayNewMeasurementButton=!0);if("complete"===e.state&&e.graphic){if(this.viewModel.activeViewer?.addGraphic(e.graphic),a){const e=await this._getAreaAccuracyFromTask(this.polygonVertices);this.viewModel.areaMeasurementAccuracy=e&&e>this.viewModel.areaMeasurementAccuracy?e:this.viewModel.areaMeasurementAccuracy}return this.viewModel.measurementGraphic=e.graphic,void this.resetAreaMeasurements()}switch(t?.type){case"vertex-add":await this.vertexAddPolygonHandler(t);break;case"cursor-update":await this.cursorUpdatePolygonHandler(t)}this.viewModel.areaMeasurementResult=h>0?h:this.pixelAreaMeasurement}async vertexAddPolygonHandler(e){const{mode:t,activeViewer:a}=this.viewModel,s=e.added,i=s[s.length-1];if(!Array.isArray(i)||"none"===t||!a?.imageSize)return;if("default"===t)this.polygonVertices.push(i);else{const e={x:i[0],y:i[1],z:i[2]},t=n(e,a?.imageSize[0],a?.imageSize[1]);this.polygonVertices.push([t.x,t.y])}if(this.polygonVertices.length<3||!this.viewModel.currentBestFeature||!this.viewModel.activeViewer?.imageSize)return;const r=this.polygonVertices[0];this.polygonVertices=this.polygonVertices.filter(((e,t)=>0===t||t===this.polygonVertices.length-1||JSON.stringify(e)!==JSON.stringify(r)));const o=await this._getAreaFromTask(this.polygonVertices);if(!o?.area||!o?.perimeter)return;const{area:c}=o;this.pixelAreaMeasurement=c}vertexUpdatePolylineHandler(){this.measurementArray=this.measurementArray.slice(-1);const e=u.reduce(((e,t)=>e+t),0)+this.pixelMeasurement;this.viewModel.distanceMeasurementResult=e,this.pixelMeasurement>0&&u.push(this.pixelMeasurement)}resetDistanceMeasurements(){this.measurementArray=[],this.pixelMeasurement=0,u=[]}resetAreaMeasurements(){this.polygonVertices=[],this.pixelAreaMeasurement=0,h=0}async _getAreaFromTask(e){const{mode:a}=this.viewModel;return this._calculationTask?.abort(),this._calculationTask=t((async t=>{this._areaCalculation=null;const i=await this.viewModel.calculateAreaMeasurement(e,a,t);s(t),this._areaCalculation=i})),await this._calculationTask.promise,this._areaCalculation}async _getDistanceFromTask(){const{mode:e}=this.viewModel;return this._calculationTask?.abort(),this._calculationTask=t((async t=>{this._distanceCalculation=0;const a=await this.viewModel.calculateDistanceMeasurement(this.measurementArray,e,t);s(t),this._distanceCalculation=a})),await this._calculationTask.promise,this._distanceCalculation}async _getAccuracyFromTask(){const{mode:e}=this.viewModel;return"none"===e?null:(this._calculationTask?.abort(),this._calculationTask=t((async t=>{this._distanceCalculation=0;const a="default"===e?await this.viewModel.calculateAccuracy(this.measurementArray,"distance",t):await this.viewModel.calculateAccuracyPanoramic(this.measurementArray,"distance",t);s(t),this._distanceCalculation=a})),await this._calculationTask.promise,this._distanceCalculation)}async _getAreaAccuracyFromTask(e){const{mode:a}=this.viewModel;return"none"===a?null:(this._calculationTask?.abort(),this._calculationTask=t((async t=>{this._distanceCalculation=0;const i="default"===a?await this.viewModel.calculateAccuracy(e,"area",t):await this.viewModel.calculateAccuracyPanoramic(e,"area",t);s(t),this._distanceCalculation=i})),await this._calculationTask.promise,this._distanceCalculation)}};e([i()],m.prototype,"type",void 0),e([i()],m.prototype,"measurementArray",void 0),e([i()],m.prototype,"pixelMeasurement",void 0),e([i()],m.prototype,"pixelAreaMeasurement",void 0),e([i()],m.prototype,"polygonVertices",void 0),m=e([r("esri.widgets.OrientedImageryViewer.adapters.sketch.MeasurementAdapter")],m);const d=m;export{d as default};
package/widgets/Popup.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../chunks/tslib.es6.js";import e from"../core/Logger.js";import{ignoreAbortErrors as i,after as o}from"../core/promiseUtils.js";import{watch as s,initial as n,on as r,whenOnce as l}from"../core/reactiveUtils.js";import{waitAnimationFrame as a}from"../core/scheduling.js";import{stripHTML as d}from"../core/string.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as h}from"../core/accessorSupport/decorators/subclass.js";import u from"../support/actions/ActionButton.js";import p from"./Features.js";import g from"./Widget.js";import v from"./Features/FeaturesViewModel.js";import{css as m}from"./Popup/css.js";import f from"./Popup/PopupViewModel.js";import w from"./Popup/PopupVisibleElements.js";import{globalCss as b}from"./support/globalCss.js";import{isRTL as _}from"./support/widgetUtils.js";import{messageBundle as k}from"./support/decorators/messageBundle.js";import{vmEvent as M}from"./support/decorators/vmEvent.js";import{tsx as y}from"./support/jsxFactory.js";const E=200,C={buttonEnabled:!0,position:"auto",breakpoint:{width:544}};let D=class extends g{constructor(t,e){super(t,e),this._dockAction=new u({id:"popup-dock-action"}),this._featuresWidget=new p({responsiveActionsEnabled:!0}),this._containerNode=null,this._mainContainerNode=null,this._pointerOffsetInPx=16,this._focusAbortController=null,this.alignment="auto",this.dockEnabled=!1,this.headingLevel=2,this.messages=null,this.viewModel=new f,this.visibleElements=new w}initialize(){this.addHandles([s((()=>[this.viewModel?.view?.widthBreakpoint,this.dockEnabled]),(()=>this._handleDockIcon()),n),s((()=>[this.dockEnabled,this.messages?.undock,this.messages?.dock]),(()=>this._handleDockEnabled()),n),s((()=>this.dockOptions),(t=>{const{_dockAction:e}=this,i=this._featuresWidget.headerActions;i.remove(e),t.buttonEnabled&&i.add(e)}),n),s((()=>this.viewModel?.screenLocation),(()=>this._positionContainer())),s((()=>[this.viewModel?.active,this.dockEnabled]),(()=>this._toggleScreenLocationEnabled())),s((()=>[this.viewModel?.screenLocation,this.viewModel?.view?.padding,this.viewModel?.view?.size,this.viewModel?.active,this.viewModel?.location,this.alignment]),(()=>this.reposition())),s((()=>this.viewModel?.view?.size),((t,e)=>this._updateDockEnabledForViewSize(t,e))),s((()=>this.viewModel?.view),((t,e)=>this._viewChange(t,e))),s((()=>this.viewModel?.view?.ready),((t,e)=>this._viewReadyChange(t??!1,e??!1))),s((()=>this.viewModel),(()=>this._featuresWidget.viewModel=this.viewModel),n),s((()=>this._featureNavigationTop),(t=>this._featuresWidget.featureNavigationTop=t),n),s((()=>this.headingLevel),(t=>this._featuresWidget.headingLevel=t),n),s((()=>this.visibleElements.actionBar),(t=>this._featuresWidget.visibleElements.actionBar=!!t),n),s((()=>this.visibleElements.closeButton),(t=>this._featuresWidget.visibleElements.closeButton=!!t),n),s((()=>this.visibleElements.collapseButton),(t=>this._featuresWidget.visibleElements.collapseButton=!!t),n),s((()=>this.visibleElements.heading),(t=>this._featuresWidget.visibleElements.heading=!!t),n),s((()=>this.visibleElements.spinner),(t=>this._featuresWidget.visibleElements.spinner=!!t),n),s((()=>this.visibleElements.featureNavigation),(t=>this._featuresWidget.visibleElements.featureNavigation=!!t),n),s((()=>this.visibleElements.featureListLayerTitle),(t=>this._featuresWidget.visibleElements.featureListLayerTitle=!!t),n),r((()=>this._featuresWidget),"trigger-header-action",(t=>{t.action===this._dockAction&&(this.dockEnabled=!this.dockEnabled)}))])}destroy(){this._dockAction.destroy(),this._featuresWidget&&(this._featuresWidget.viewModel=new v,this._featuresWidget.destroy()),this._focusAbortController?.abort()}get _featureNavigationTop(){const{currentAlignment:t,currentDockPosition:e}=this;return"bottom-left"===t||"bottom-center"===t||"bottom-right"===t||"top-left"===e||"top-center"===e||"top-right"===e}get actions(){return this.viewModel.actions}set actions(t){this.viewModel.actions=t}get active(){return this.viewModel.active}get autoCloseEnabled(){return this.viewModel.autoCloseEnabled}set autoCloseEnabled(t){this.viewModel.autoCloseEnabled=t}get defaultPopupTemplateEnabled(){return this.viewModel.defaultPopupTemplateEnabled}set defaultPopupTemplateEnabled(t){this.viewModel.defaultPopupTemplateEnabled=t}get content(){return this.viewModel.content}set content(t){this.viewModel.content=t}get collapsed(){return this._featuresWidget.collapsed}set collapsed(t){this._featuresWidget.collapsed=t}get currentAlignment(){return this._getCurrentAlignment()}get currentDockPosition(){return this._getCurrentDockPosition()}get dockOptions(){return this._get("dockOptions")||C}set dockOptions(t){const e={...C},i=this.viewModel?.view?.breakpoints,o={};i&&(o.width=i.xsmall,o.height=i.xsmall);const s={...e,...t},n={...e.breakpoint,...o},{breakpoint:r}=s;"object"==typeof r?s.breakpoint={...n,...r}:r&&(s.breakpoint=n),this._set("dockOptions",s),this._setCurrentDockPosition(),this.reposition()}get featureCount(){return this.viewModel.featureCount}get featureMenuOpen(){return this.viewModel.featureMenuOpen}set featureMenuOpen(t){this.viewModel.featureMenuOpen=t}get features(){return this.viewModel.features}set features(t){this.viewModel.features=t}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(t){this.viewModel.goToOverride=t}get highlightEnabled(){return this.viewModel.highlightEnabled}set highlightEnabled(t){this.viewModel.highlightEnabled=t}get icon(){return"popup"}set icon(t){this._overrideIfSome("icon",t)}get initialDisplayMode(){return this.viewModel.initialDisplayMode}set initialDisplayMode(t){this.viewModel.initialDisplayMode=t}get location(){return this.viewModel.location}set location(t){this.viewModel.location=t}get label(){return this.messages?.widgetLabel??""}set label(t){this._overrideIfSome("label",t)}get promises(){return this.viewModel.promises}set promises(t){this.viewModel.promises=t}get selectedFeature(){return this.viewModel.selectedFeature}get selectedDrillInFeature(){return this._featuresWidget.selectedDrillInFeature??null}get selectedFeatureIndex(){return this.viewModel.selectedFeatureIndex}set selectedFeatureIndex(t){this.viewModel.selectedFeatureIndex=t}get selectedFeatureWidget(){return this._featuresWidget.selectedFeatureWidget}get title(){return this.viewModel.title}set title(t){this.viewModel.title=t}get updateLocationEnabled(){return this.viewModel.updateLocationEnabled}set updateLocationEnabled(t){this.viewModel.updateLocationEnabled=t}get view(){return this.viewModel.view}set view(t){this.viewModel.view=t}get visible(){return this.viewModel.visible}set visible(t){this.viewModel.visible=t}blur(){const{active:t}=this.viewModel;t||e.getLogger(this).warn("Popup can only be blurred when currently active."),this._featuresWidget.blur()}clear(){return this.viewModel.clear()}close(){this.visible=!1}fetchFeatures(t,e){return this.viewModel.fetchFeatures(t,e)}focus(){const{active:t}=this.viewModel;t||e.getLogger(this).warn("Popup can only be focused when currently active."),this._handleFocus()}next(){return this.viewModel.next()}open(t){const e=!!t&&!!t.featureMenuOpen,i={collapsed:!!t&&!!t.collapsed,featureMenuOpen:e};this.set(i),this.viewModel.open(t),t?.shouldFocus&&this._handleFocus(!0)}previous(){return this.viewModel.previous()}reposition(){this.renderNow(),this._positionContainer(),this._setCurrentAlignment()}triggerAction(t){return this.viewModel.triggerAction(t)}render(){const{dockEnabled:t,currentAlignment:e,currentDockPosition:i}=this,{active:o,screenLocation:s}=this.viewModel,n=o&&t,r=o&&!t,l=this.selectedFeature?.layer?.title,a=this.selectedFeature?.layer?.id,c={[m.alignTopCenter]:"top-center"===e,[m.alignBottomCenter]:"bottom-center"===e,[m.alignTopLeft]:"top-left"===e,[m.alignBottomLeft]:"bottom-left"===e,[m.alignTopRight]:"top-right"===e,[m.alignBottomRight]:"bottom-right"===e,[m.isDocked]:n,[m.shadow]:r,[m.isDockedTopLeft]:"top-left"===i,[m.isDockedTopCenter]:"top-center"===i,[m.isDockedTopRight]:"top-right"===i,[m.isDockedBottomLeft]:"bottom-left"===i,[m.isDockedBottomCenter]:"bottom-center"===i,[m.isDockedBottomRight]:"bottom-right"===i};return y("div",{afterCreate:this._positionContainer,afterUpdate:this._positionContainer,"aria-hidden":(!o).toString(),"aria-label":d(this.title??""),"aria-modal":"false",bind:this,class:this.classes(m.base,c,{[m.baseHidden]:!s&&!t}),"data-layer-id":a,"data-layer-title":l,role:"dialog"},o?[this._renderMainContainer(),this._renderPointer()]:null)}_renderPointer(){return this.dockEnabled?null:y("div",{class:m.pointer,key:"popup-pointer",role:"presentation"},y("div",{class:this.classes(m.pointerDirection,m.shadow)}))}_renderMainContainer(){const{dockEnabled:t}=this,e={[m.shadow]:t};return y("div",{afterCreate:this._setMainContainerNode,afterUpdate:this._setMainContainerNode,bind:this,class:this.classes(m.main,b.widget,e)},this._featuresWidget.render())}_getAnimationDurationMS(){const{_containerNode:t}=this;return t?1e3*parseFloat(window.getComputedStyle(t).animationDuration):E}async _handleFocus(t=!1){this._focusAbortController?.abort(),this._focusAbortController=new AbortController;const e=this._focusAbortController.signal;t&&await l((()=>!0===this.viewModel?.active),{signal:e}),await i(a(e)),await i(o(this._getAnimationDurationMS(),e)),this._featuresWidget.focus()}_isOutsideView(t){const{popupHeight:e,popupWidth:i,screenLocation:o,side:s,view:n}=t;if(isNaN(i)||isNaN(e)||!n||!o)return!1;const r=n.padding;return"right"===s&&o.x+i/2>n.width-r.right||("left"===s&&o.x-i/2<r.left||("top"===s&&o.y-e<r.top||"bottom"===s&&o.y+e>n.height-r.bottom))}_calculateAutoAlignment(t){if("auto"!==t)return t;const{_pointerOffsetInPx:e,_containerNode:i,_mainContainerNode:o,viewModel:s}=this,{screenLocation:n,view:r}=s;if(null==n||!r||!i)return"top-center";function l(t){return parseInt(t.replaceAll(/[^-\d.]/g,""),10)}const a=o?window.getComputedStyle(o,null):null,d=a?l(a.getPropertyValue("max-height")):0,c=a?l(a.getPropertyValue("height")):0,{height:h,width:u}=i.getBoundingClientRect(),p=u+e,g=Math.max(h,d,c)+e,v=this._isOutsideView({popupHeight:g,popupWidth:p,screenLocation:n,side:"right",view:r}),m=this._isOutsideView({popupHeight:g,popupWidth:p,screenLocation:n,side:"left",view:r}),f=this._isOutsideView({popupHeight:g,popupWidth:p,screenLocation:n,side:"top",view:r}),w=this._isOutsideView({popupHeight:g,popupWidth:p,screenLocation:n,side:"bottom",view:r});return m?f?"bottom-right":"top-right":v?f?"bottom-left":"top-left":f?w?"top-center":"bottom-center":"top-center"}_callCurrentAlignment(t){return"function"==typeof t?t.call(this):t}_getCurrentAlignment(){const{alignment:t,dockEnabled:e}=this;return e||!this.viewModel.active?null:this._calculatePositionResult(this._calculateAutoAlignment(this._callCurrentAlignment(t)))}_setCurrentAlignment(){this._set("currentAlignment",this._getCurrentAlignment())}_setCurrentDockPosition(){this._set("currentDockPosition",this._getCurrentDockPosition())}_calculatePositionResult(t){const e=["left","right"];return _(this.container)&&e.reverse(),t?.replace(/leading/gi,e[0]).replaceAll(/trailing/gi,e[1])}_callDockPosition(t){return"function"==typeof t?t.call(this):t}_getDockPosition(){return this._calculatePositionResult(this._calculateAutoDockPosition(this._callDockPosition(this.dockOptions?.position)))}_getCurrentDockPosition(){return this.dockEnabled&&this.viewModel.active?this._getDockPosition():null}_calculateAutoDockPosition(t){if("auto"!==t)return t;const e=this.viewModel?.view,i=_(this.container)?"top-left":"top-right";if(!e)return i;const o=e.padding||{left:0,right:0,top:0,bottom:0},s=e.width-o.left-o.right,{breakpoints:n}=e;return n&&s<=n.xsmall?"bottom-center":i}_getDockIcon(){const t=this._getDockPosition();if(this.dockEnabled)return"minimize";switch(t){case"top-left":case"bottom-left":return"dock-left";case"top-center":return"maximize";case"bottom-center":return"dock-bottom";default:return"dock-right"}}_handleDockIcon(){this._dockAction.icon=this._getDockIcon()}_handleDockEnabled(){this._dockAction.title=this.dockEnabled?this.messages?.undock:this.messages?.dock}_setMainContainerNode(t){this._mainContainerNode=t}_positionContainer(t=this._containerNode){if(t&&(this._containerNode=t),!this._containerNode)return;const{screenLocation:e}=this.viewModel,{width:i}=this._containerNode.getBoundingClientRect(),o=this._calculatePositionStyle(e,i);o&&Object.assign(this._containerNode.style,o)}_calculateFullWidth(t){const{currentAlignment:e,_pointerOffsetInPx:i}=this;return"top-left"===e||"bottom-left"===e||"top-right"===e||"bottom-right"===e?t+i:t}_calculateAlignmentPosition(t,e,i,o){const{currentAlignment:s,_pointerOffsetInPx:n}=this;if(!i)return;const{padding:r}=i,l=o/2,a=i.height-e,d=i.width-t;return"bottom-center"===s?{top:e+n-r.top,left:t-l-r.left}:"top-left"===s?{bottom:a+n-r.bottom,right:d+n-r.right}:"bottom-left"===s?{top:e+n-r.top,right:d+n-r.right}:"top-right"===s?{bottom:a+n-r.bottom,left:t+n-r.left}:"bottom-right"===s?{top:e+n-r.top,left:t+n-r.left}:"top-center"===s?{bottom:a+n-r.bottom,left:t-l-r.left}:void 0}_calculatePositionStyle(t,e){const{dockEnabled:i,view:o}=this;if(!o)return;if(i)return{left:"",top:"",right:"",bottom:""};if(null==t||!e)return;const s=this._calculateFullWidth(e),n=this._calculateAlignmentPosition(t.x,t.y,o,s);return n?{top:void 0!==n.top?`${n.top}px`:"auto",left:void 0!==n.left?`${n.left}px`:"auto",bottom:void 0!==n.bottom?`${n.bottom}px`:"auto",right:void 0!==n.right?`${n.right}px`:"auto"}:void 0}_viewChange(t,e){t&&e&&(this.close(),this.clear())}_viewReadyChange(t,e){t?this._wireUpView():e&&(this.close(),this.clear())}_wireUpView(){this._setDockEnabledForViewSize(this.dockOptions)}_dockingThresholdCrossed(t,e,i){const[o,s]=t,[n,r]=e,{width:l=0,height:a=0}=i??{};return o<=l&&n>l||o>l&&n<=l||s<=a&&r>a||s>a&&r<=a}_updateDockEnabledForViewSize(t,e){if(!t||!e)return;const i=this.viewModel?.view?.padding||{left:0,right:0,top:0,bottom:0},o=i.left+i.right,s=i.top+i.bottom,n=[],r=[];n[0]=t[0]-o,n[1]=t[1]-s,r[0]=e[0]-o,r[1]=e[1]-s;const{dockOptions:l}=this,a=l.breakpoint;this._dockingThresholdCrossed(n,r,a)&&this._setDockEnabledForViewSize(l),this._setCurrentDockPosition()}_toggleScreenLocationEnabled(){const{dockEnabled:t,viewModel:e}=this;if(!e)return;const i=e.active&&!t;e.screenLocationEnabled=i}_shouldDockAtCurrentViewSize(t){const e=t.breakpoint,i=this.viewModel?.view?.ui;if(!i)return!1;const{width:o,height:s}=i;if(isNaN(o)||isNaN(s))return!1;if(!e)return!1;const n=e.hasOwnProperty("width")&&o<=(e.width??0),r=e.hasOwnProperty("height")&&s<=(e.height??0);return n||r}_setDockEnabledForViewSize(t){t.breakpoint&&(this.dockEnabled=this._shouldDockAtCurrentViewSize(t))}};t([c({readOnly:!0})],D.prototype,"_featureNavigationTop",null),t([c()],D.prototype,"actions",null),t([c({readOnly:!0})],D.prototype,"active",null),t([c()],D.prototype,"alignment",void 0),t([c()],D.prototype,"autoCloseEnabled",null),t([c()],D.prototype,"defaultPopupTemplateEnabled",null),t([c()],D.prototype,"content",null),t([c()],D.prototype,"collapsed",null),t([c({readOnly:!0})],D.prototype,"currentAlignment",null),t([c({readOnly:!0})],D.prototype,"currentDockPosition",null),t([c()],D.prototype,"dockOptions",null),t([c()],D.prototype,"dockEnabled",void 0),t([c({readOnly:!0})],D.prototype,"featureCount",null),t([c()],D.prototype,"featureMenuOpen",null),t([c()],D.prototype,"features",null),t([c()],D.prototype,"goToOverride",null),t([c()],D.prototype,"headingLevel",void 0),t([c()],D.prototype,"highlightEnabled",null),t([c()],D.prototype,"icon",null),t([c()],D.prototype,"initialDisplayMode",null),t([c()],D.prototype,"location",null),t([c()],D.prototype,"label",null),t([c(),k("esri/widgets/Popup/t9n/Popup")],D.prototype,"messages",void 0),t([c()],D.prototype,"promises",null),t([c({readOnly:!0})],D.prototype,"selectedFeature",null),t([c({readOnly:!0})],D.prototype,"selectedDrillInFeature",null),t([c()],D.prototype,"selectedFeatureIndex",null),t([c({readOnly:!0})],D.prototype,"selectedFeatureWidget",null),t([c()],D.prototype,"title",null),t([c()],D.prototype,"updateLocationEnabled",null),t([c()],D.prototype,"view",null),t([c({type:f}),M(["triggerAction","trigger-action"])],D.prototype,"viewModel",void 0),t([c()],D.prototype,"visible",null),t([c({type:w,nonNullable:!0})],D.prototype,"visibleElements",void 0),D=t([h("esri.widgets.Popup")],D);const P=D;export{P as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Logger.js";import{ignoreAbortErrors as i,after as o}from"../core/promiseUtils.js";import{watch as s,initial as n,on as r,whenOnce as l}from"../core/reactiveUtils.js";import{waitAnimationFrame as a}from"../core/scheduling.js";import{stripHTML as d}from"../core/string.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as h}from"../core/accessorSupport/decorators/subclass.js";import u from"../support/actions/ActionButton.js";import p from"./Features.js";import g from"./Widget.js";import v from"./Features/FeaturesViewModel.js";import{css as m}from"./Popup/css.js";import f from"./Popup/PopupViewModel.js";import w from"./Popup/PopupVisibleElements.js";import{globalCss as b}from"./support/globalCss.js";import{isRTL as _}from"./support/widgetUtils.js";import{messageBundle as M}from"./support/decorators/messageBundle.js";import{vmEvent as k}from"./support/decorators/vmEvent.js";import{tsx as y}from"./support/jsxFactory.js";const E=200,C={buttonEnabled:!0,position:"auto",breakpoint:{width:544}};let D=class extends g{constructor(e,t){super(e,t),this._dockAction=new u({id:"popup-dock-action"}),this._featuresWidget=new p({responsiveActionsEnabled:!0}),this._containerNode=null,this._mainContainerNode=null,this._pointerOffsetInPx=16,this._focusAbortController=null,this.alignment="auto",this.dockEnabled=!1,this.headingLevel=2,this.messages=null,this.viewModel=new f,this.visibleElements=new w}initialize(){this.addHandles([s((()=>[this.viewModel?.view?.widthBreakpoint,this.dockEnabled]),(()=>this._handleDockIcon()),n),s((()=>[this.dockEnabled,this.messages?.undock,this.messages?.dock]),(()=>this._handleDockEnabled()),n),s((()=>this.dockOptions),(e=>{const{_dockAction:t}=this,i=this._featuresWidget.headerActions;i.remove(t),e.buttonEnabled&&i.add(t)}),n),s((()=>this.viewModel?.screenLocation),(()=>this._positionContainer())),s((()=>[this.viewModel?.active,this.dockEnabled]),(()=>this._toggleScreenLocationEnabled())),s((()=>[this.viewModel?.screenLocation,this.viewModel?.view?.padding,this.viewModel?.view?.size,this.viewModel?.active,this.viewModel?.location,this.alignment]),(()=>this.reposition())),s((()=>this.viewModel?.view?.size),((e,t)=>this._updateDockEnabledForViewSize(e,t))),s((()=>this.viewModel?.view),((e,t)=>this._viewChange(e,t))),s((()=>this.viewModel?.view?.ready),((e,t)=>this._viewReadyChange(e??!1,t??!1))),s((()=>this.viewModel),(()=>this._featuresWidget.viewModel=this.viewModel),n),s((()=>this._featureNavigationTop),(e=>this._featuresWidget.featureNavigationTop=e),n),s((()=>this.headingLevel),(e=>this._featuresWidget.headingLevel=e),n),s((()=>this.visibleElements.actionBar),(e=>this._featuresWidget.visibleElements.actionBar=!!e),n),s((()=>this.visibleElements.closeButton),(e=>this._featuresWidget.visibleElements.closeButton=!!e),n),s((()=>this.visibleElements.collapseButton),(e=>this._featuresWidget.visibleElements.collapseButton=!!e),n),s((()=>this.visibleElements.heading),(e=>this._featuresWidget.visibleElements.heading=!!e),n),s((()=>this.visibleElements.spinner),(e=>this._featuresWidget.visibleElements.spinner=!!e),n),s((()=>this.visibleElements.featureNavigation),(e=>this._featuresWidget.visibleElements.featureNavigation=!!e),n),s((()=>this.visibleElements.featureMenuHeading),(e=>this._featuresWidget.visibleElements.featureMenuHeading=!!e),n),s((()=>this.visibleElements.featureListLayerTitle),(e=>this._featuresWidget.visibleElements.featureListLayerTitle=!!e),n),r((()=>this._featuresWidget),"trigger-header-action",(e=>{e.action===this._dockAction&&(this.dockEnabled=!this.dockEnabled)}))])}destroy(){this._dockAction.destroy(),this._featuresWidget&&(this._featuresWidget.viewModel=new v,this._featuresWidget.destroy()),this._focusAbortController?.abort()}get _featureNavigationTop(){const{currentAlignment:e,currentDockPosition:t}=this;return"bottom-left"===e||"bottom-center"===e||"bottom-right"===e||"top-left"===t||"top-center"===t||"top-right"===t}get actions(){return this.viewModel.actions}set actions(e){this.viewModel.actions=e}get active(){return this.viewModel.active}get autoCloseEnabled(){return this.viewModel.autoCloseEnabled}set autoCloseEnabled(e){this.viewModel.autoCloseEnabled=e}get defaultPopupTemplateEnabled(){return this.viewModel.defaultPopupTemplateEnabled}set defaultPopupTemplateEnabled(e){this.viewModel.defaultPopupTemplateEnabled=e}get content(){return this.viewModel.content}set content(e){this.viewModel.content=e}get collapsed(){return this._featuresWidget.collapsed}set collapsed(e){this._featuresWidget.collapsed=e}get currentAlignment(){return this._getCurrentAlignment()}get currentDockPosition(){return this._getCurrentDockPosition()}get dockOptions(){return this._get("dockOptions")||C}set dockOptions(e){const t={...C},i=this.viewModel?.view?.breakpoints,o={};i&&(o.width=i.xsmall,o.height=i.xsmall);const s={...t,...e},n={...t.breakpoint,...o},{breakpoint:r}=s;"object"==typeof r?s.breakpoint={...n,...r}:r&&(s.breakpoint=n),this._set("dockOptions",s),this._setCurrentDockPosition(),this.reposition()}get featureCount(){return this.viewModel.featureCount}get featureMenuOpen(){return this.viewModel.featureMenuOpen}set featureMenuOpen(e){this.viewModel.featureMenuOpen=e}get features(){return this.viewModel.features}set features(e){this.viewModel.features=e}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get highlightEnabled(){return this.viewModel.highlightEnabled}set highlightEnabled(e){this.viewModel.highlightEnabled=e}get icon(){return"popup"}set icon(e){this._overrideIfSome("icon",e)}get initialDisplayMode(){return this.viewModel.initialDisplayMode}set initialDisplayMode(e){this.viewModel.initialDisplayMode=e}get location(){return this.viewModel.location}set location(e){this.viewModel.location=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get promises(){return this.viewModel.promises}set promises(e){this.viewModel.promises=e}get selectedFeature(){return this.viewModel.selectedFeature}get selectedDrillInFeature(){return this._featuresWidget.selectedDrillInFeature??null}get selectedFeatureIndex(){return this.viewModel.selectedFeatureIndex}set selectedFeatureIndex(e){this.viewModel.selectedFeatureIndex=e}get selectedFeatureWidget(){return this._featuresWidget.selectedFeatureWidget}get title(){return this.viewModel.title}set title(e){this.viewModel.title=e}get updateLocationEnabled(){return this.viewModel.updateLocationEnabled}set updateLocationEnabled(e){this.viewModel.updateLocationEnabled=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}get visible(){return this.viewModel.visible}set visible(e){this.viewModel.visible=e}blur(){const{active:e}=this.viewModel;e||t.getLogger(this).warn("Popup can only be blurred when currently active."),this._featuresWidget.blur()}clear(){return this.viewModel.clear()}close(){this.visible=!1}fetchFeatures(e,t){return this.viewModel.fetchFeatures(e,t)}focus(){const{active:e}=this.viewModel;e||t.getLogger(this).warn("Popup can only be focused when currently active."),this._handleFocus()}next(){return this.viewModel.next()}open(e){const t=!!e&&!!e.featureMenuOpen,i={collapsed:!!e&&!!e.collapsed,featureMenuOpen:t};this.set(i),this.viewModel.open(e),e?.shouldFocus&&this._handleFocus(!0)}previous(){return this.viewModel.previous()}reposition(){this.renderNow(),this._positionContainer(),this._setCurrentAlignment()}triggerAction(e){return this.viewModel.triggerAction(e)}render(){const{dockEnabled:e,currentAlignment:t,currentDockPosition:i}=this,{active:o,screenLocation:s}=this.viewModel,n=o&&e,r=o&&!e,l=this.selectedFeature?.layer?.title,a=this.selectedFeature?.layer?.id,c={[m.alignTopCenter]:"top-center"===t,[m.alignBottomCenter]:"bottom-center"===t,[m.alignTopLeft]:"top-left"===t,[m.alignBottomLeft]:"bottom-left"===t,[m.alignTopRight]:"top-right"===t,[m.alignBottomRight]:"bottom-right"===t,[m.isDocked]:n,[m.shadow]:r,[m.isDockedTopLeft]:"top-left"===i,[m.isDockedTopCenter]:"top-center"===i,[m.isDockedTopRight]:"top-right"===i,[m.isDockedBottomLeft]:"bottom-left"===i,[m.isDockedBottomCenter]:"bottom-center"===i,[m.isDockedBottomRight]:"bottom-right"===i};return y("div",{afterCreate:this._positionContainer,afterUpdate:this._positionContainer,"aria-hidden":(!o).toString(),"aria-label":d(this.title??""),"aria-modal":"false",bind:this,class:this.classes(m.base,c,{[m.baseHidden]:!s&&!e}),"data-layer-id":a,"data-layer-title":l,role:"dialog"},o?[this._renderMainContainer(),this._renderPointer()]:null)}_renderPointer(){return this.dockEnabled?null:y("div",{class:m.pointer,key:"popup-pointer",role:"presentation"},y("div",{class:this.classes(m.pointerDirection,m.shadow)}))}_renderMainContainer(){const{dockEnabled:e}=this,t={[m.shadow]:e};return y("div",{afterCreate:this._setMainContainerNode,afterUpdate:this._setMainContainerNode,bind:this,class:this.classes(m.main,b.widget,t)},this._featuresWidget.render())}_getAnimationDurationMS(){const{_containerNode:e}=this;return e?1e3*parseFloat(window.getComputedStyle(e).animationDuration):E}async _handleFocus(e=!1){this._focusAbortController?.abort(),this._focusAbortController=new AbortController;const t=this._focusAbortController.signal;e&&await l((()=>!0===this.viewModel?.active),{signal:t}),await i(a(t)),await i(o(this._getAnimationDurationMS(),t)),this._featuresWidget.focus()}_isOutsideView(e){const{popupHeight:t,popupWidth:i,screenLocation:o,side:s,view:n}=e;if(isNaN(i)||isNaN(t)||!n||!o)return!1;const r=n.padding;return"right"===s&&o.x+i/2>n.width-r.right||("left"===s&&o.x-i/2<r.left||("top"===s&&o.y-t<r.top||"bottom"===s&&o.y+t>n.height-r.bottom))}_calculateAutoAlignment(e){if("auto"!==e)return e;const{_pointerOffsetInPx:t,_containerNode:i,_mainContainerNode:o,viewModel:s}=this,{screenLocation:n,view:r}=s;if(null==n||!r||!i)return"top-center";function l(e){return parseInt(e.replaceAll(/[^-\d.]/g,""),10)}const a=o?window.getComputedStyle(o,null):null,d=a?l(a.getPropertyValue("max-height")):0,c=a?l(a.getPropertyValue("height")):0,{height:h,width:u}=i.getBoundingClientRect(),p=u+t,g=Math.max(h,d,c)+t,v=this._isOutsideView({popupHeight:g,popupWidth:p,screenLocation:n,side:"right",view:r}),m=this._isOutsideView({popupHeight:g,popupWidth:p,screenLocation:n,side:"left",view:r}),f=this._isOutsideView({popupHeight:g,popupWidth:p,screenLocation:n,side:"top",view:r}),w=this._isOutsideView({popupHeight:g,popupWidth:p,screenLocation:n,side:"bottom",view:r});return m?f?"bottom-right":"top-right":v?f?"bottom-left":"top-left":f?w?"top-center":"bottom-center":"top-center"}_callCurrentAlignment(e){return"function"==typeof e?e.call(this):e}_getCurrentAlignment(){const{alignment:e,dockEnabled:t}=this;return t||!this.viewModel.active?null:this._calculatePositionResult(this._calculateAutoAlignment(this._callCurrentAlignment(e)))}_setCurrentAlignment(){this._set("currentAlignment",this._getCurrentAlignment())}_setCurrentDockPosition(){this._set("currentDockPosition",this._getCurrentDockPosition())}_calculatePositionResult(e){const t=["left","right"];return _(this.container)&&t.reverse(),e?.replace(/leading/gi,t[0]).replaceAll(/trailing/gi,t[1])}_callDockPosition(e){return"function"==typeof e?e.call(this):e}_getDockPosition(){return this._calculatePositionResult(this._calculateAutoDockPosition(this._callDockPosition(this.dockOptions?.position)))}_getCurrentDockPosition(){return this.dockEnabled&&this.viewModel.active?this._getDockPosition():null}_calculateAutoDockPosition(e){if("auto"!==e)return e;const t=this.viewModel?.view,i=_(this.container)?"top-left":"top-right";if(!t)return i;const o=t.padding||{left:0,right:0,top:0,bottom:0},s=t.width-o.left-o.right,{breakpoints:n}=t;return n&&s<=n.xsmall?"bottom-center":i}_getDockIcon(){const e=this._getDockPosition();if(this.dockEnabled)return"minimize";switch(e){case"top-left":case"bottom-left":return"dock-left";case"top-center":return"maximize";case"bottom-center":return"dock-bottom";default:return"dock-right"}}_handleDockIcon(){this._dockAction.icon=this._getDockIcon()}_handleDockEnabled(){this._dockAction.title=this.dockEnabled?this.messages?.undock:this.messages?.dock}_setMainContainerNode(e){this._mainContainerNode=e}_positionContainer(e=this._containerNode){if(e&&(this._containerNode=e),!this._containerNode)return;const{screenLocation:t}=this.viewModel,{width:i}=this._containerNode.getBoundingClientRect(),o=this._calculatePositionStyle(t,i);o&&Object.assign(this._containerNode.style,o)}_calculateFullWidth(e){const{currentAlignment:t,_pointerOffsetInPx:i}=this;return"top-left"===t||"bottom-left"===t||"top-right"===t||"bottom-right"===t?e+i:e}_calculateAlignmentPosition(e,t,i,o){const{currentAlignment:s,_pointerOffsetInPx:n}=this;if(!i)return;const{padding:r}=i,l=o/2,a=i.height-t,d=i.width-e;return"bottom-center"===s?{top:t+n-r.top,left:e-l-r.left}:"top-left"===s?{bottom:a+n-r.bottom,right:d+n-r.right}:"bottom-left"===s?{top:t+n-r.top,right:d+n-r.right}:"top-right"===s?{bottom:a+n-r.bottom,left:e+n-r.left}:"bottom-right"===s?{top:t+n-r.top,left:e+n-r.left}:"top-center"===s?{bottom:a+n-r.bottom,left:e-l-r.left}:void 0}_calculatePositionStyle(e,t){const{dockEnabled:i,view:o}=this;if(!o)return;if(i)return{left:"",top:"",right:"",bottom:""};if(null==e||!t)return;const s=this._calculateFullWidth(t),n=this._calculateAlignmentPosition(e.x,e.y,o,s);return n?{top:void 0!==n.top?`${n.top}px`:"auto",left:void 0!==n.left?`${n.left}px`:"auto",bottom:void 0!==n.bottom?`${n.bottom}px`:"auto",right:void 0!==n.right?`${n.right}px`:"auto"}:void 0}_viewChange(e,t){e&&t&&(this.close(),this.clear())}_viewReadyChange(e,t){e?this._wireUpView():t&&(this.close(),this.clear())}_wireUpView(){this._setDockEnabledForViewSize(this.dockOptions)}_dockingThresholdCrossed(e,t,i){const[o,s]=e,[n,r]=t,{width:l=0,height:a=0}=i??{};return o<=l&&n>l||o>l&&n<=l||s<=a&&r>a||s>a&&r<=a}_updateDockEnabledForViewSize(e,t){if(!e||!t)return;const i=this.viewModel?.view?.padding||{left:0,right:0,top:0,bottom:0},o=i.left+i.right,s=i.top+i.bottom,n=[],r=[];n[0]=e[0]-o,n[1]=e[1]-s,r[0]=t[0]-o,r[1]=t[1]-s;const{dockOptions:l}=this,a=l.breakpoint;this._dockingThresholdCrossed(n,r,a)&&this._setDockEnabledForViewSize(l),this._setCurrentDockPosition()}_toggleScreenLocationEnabled(){const{dockEnabled:e,viewModel:t}=this;if(!t)return;const i=t.active&&!e;t.screenLocationEnabled=i}_shouldDockAtCurrentViewSize(e){const t=e.breakpoint,i=this.viewModel?.view?.ui;if(!i)return!1;const{width:o,height:s}=i;if(isNaN(o)||isNaN(s))return!1;if(!t)return!1;const n=t.hasOwnProperty("width")&&o<=(t.width??0),r=t.hasOwnProperty("height")&&s<=(t.height??0);return n||r}_setDockEnabledForViewSize(e){e.breakpoint&&(this.dockEnabled=this._shouldDockAtCurrentViewSize(e))}};e([c({readOnly:!0})],D.prototype,"_featureNavigationTop",null),e([c()],D.prototype,"actions",null),e([c({readOnly:!0})],D.prototype,"active",null),e([c()],D.prototype,"alignment",void 0),e([c()],D.prototype,"autoCloseEnabled",null),e([c()],D.prototype,"defaultPopupTemplateEnabled",null),e([c()],D.prototype,"content",null),e([c()],D.prototype,"collapsed",null),e([c({readOnly:!0})],D.prototype,"currentAlignment",null),e([c({readOnly:!0})],D.prototype,"currentDockPosition",null),e([c()],D.prototype,"dockOptions",null),e([c()],D.prototype,"dockEnabled",void 0),e([c({readOnly:!0})],D.prototype,"featureCount",null),e([c()],D.prototype,"featureMenuOpen",null),e([c()],D.prototype,"features",null),e([c()],D.prototype,"goToOverride",null),e([c()],D.prototype,"headingLevel",void 0),e([c()],D.prototype,"highlightEnabled",null),e([c()],D.prototype,"icon",null),e([c()],D.prototype,"initialDisplayMode",null),e([c()],D.prototype,"location",null),e([c()],D.prototype,"label",null),e([c(),M("esri/widgets/Popup/t9n/Popup")],D.prototype,"messages",void 0),e([c()],D.prototype,"promises",null),e([c({readOnly:!0})],D.prototype,"selectedFeature",null),e([c({readOnly:!0})],D.prototype,"selectedDrillInFeature",null),e([c()],D.prototype,"selectedFeatureIndex",null),e([c({readOnly:!0})],D.prototype,"selectedFeatureWidget",null),e([c()],D.prototype,"title",null),e([c()],D.prototype,"updateLocationEnabled",null),e([c()],D.prototype,"view",null),e([c({type:f}),k(["triggerAction","trigger-action"])],D.prototype,"viewModel",void 0),e([c()],D.prototype,"visible",null),e([c({type:w,nonNullable:!0})],D.prototype,"visibleElements",void 0),D=e([h("esri.widgets.Popup")],D);const P=D;export{P as default};