@arcgis/core 5.2.0-next.144 → 5.2.0-next.146

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 (138) hide show
  1. package/analysis/AreaMeasurementAnalysis.d.ts +11 -1
  2. package/analysis/DirectLineMeasurementAnalysis.d.ts +11 -1
  3. package/analysis/DistanceMeasurementAnalysis.d.ts +8 -0
  4. package/arcade/featureSetUtils.js +1 -1
  5. package/arcgisGlobal.d.ts +5 -5
  6. package/assets/esri/core/workers/RemoteClient.js +1 -1
  7. package/assets/esri/core/workers/chunks/{1ede8666d804c553803e.js → 0b6941781e35ce0f7274.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{a0d459bdb91ee892d4b6.js → 116293b1ee788a89ce1e.js} +1 -1
  9. package/assets/esri/core/workers/chunks/18f20fd43ec9ce03cef1.js +1 -0
  10. package/assets/esri/core/workers/chunks/{8959a825f5e1ce6f38ac.js → 1c65ab9ed611c322ce27.js} +1 -1
  11. package/assets/esri/core/workers/chunks/257910cca66dc5df465e.js +1 -0
  12. package/assets/esri/core/workers/chunks/2e096537a3a5555a4a93.js +1 -0
  13. package/assets/esri/core/workers/chunks/{8ba32d3a0df4a206ef1c.js → 392bcef780df52fb4cca.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{d4926545193414cf2f16.js → 4ed8655770a3e018e366.js} +1 -1
  15. package/assets/esri/core/workers/chunks/505227797bcf2a1d908d.js +1 -0
  16. package/assets/esri/core/workers/chunks/532a1b6ff9a7c950e325.js +1 -0
  17. package/assets/esri/core/workers/chunks/56a24061589f4a968818.js +1 -0
  18. package/assets/esri/core/workers/chunks/{5b3cfe95314a75a735c1.js → 588e677f33df86a595bf.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{25e6013e2c095629b236.js → 58c252289411b0d86473.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{1c0975c2dd1d0e2710bb.js → 6883a5c6883eccaddf64.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{f74e32d2ffe81778826b.js → 6c1d5577a17a5c8ccf39.js} +1 -1
  22. package/assets/esri/core/workers/chunks/6c83398cf586ecea0eb1.js +1 -0
  23. package/assets/esri/core/workers/chunks/{e521bb9ee2030245c3ce.js → 6f358116f79021ff9687.js} +1 -1
  24. package/assets/esri/core/workers/chunks/76196c414e48834f7b92.js +1 -0
  25. package/assets/esri/core/workers/chunks/{cbe6c0f32608cb504695.js → 776ae25a34352d3468bc.js} +1 -1
  26. package/assets/esri/core/workers/chunks/77ebacfdf8e57f2e03f1.js +1118 -0
  27. package/assets/esri/core/workers/chunks/794e5a67a88cb10c1a19.js +1 -0
  28. package/assets/esri/core/workers/chunks/943a0f140813ee4ab04a.js +1 -0
  29. package/assets/esri/core/workers/chunks/{fccbb902fe08448f91de.js → 9c1e69ac82e2bf746191.js} +1 -1
  30. package/assets/esri/core/workers/chunks/aba42885c5d6b2b5fe7f.js +1 -0
  31. package/assets/esri/core/workers/chunks/b61008f28b788f759e2a.js +1 -0
  32. package/assets/esri/core/workers/chunks/{402a82c77420254831bc.js → b7d77dd2abb255fd2e5a.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{8b54589f173259c1ba55.js → b8054adc45bca069b948.js} +1 -1
  34. package/assets/esri/core/workers/chunks/ba48045a81acc4cda927.js +1 -0
  35. package/assets/esri/core/workers/chunks/d21257d2e2a37266c0f7.js +1 -0
  36. package/assets/esri/core/workers/chunks/d4f038e04c42aed588c1.js +1 -0
  37. package/assets/esri/core/workers/chunks/d90a3bfd45b5ed4092e0.js +1 -0
  38. package/assets/esri/core/workers/chunks/{43fc42405167a5537039.js → f095cf98940e3f95d51e.js} +1 -1
  39. package/assets/esri/themes/base/widgets/_OrientedImageryViewer.scss +0 -2
  40. package/assets/esri/themes/dark/main.css +1 -1
  41. package/assets/esri/themes/light/main.css +1 -1
  42. package/assets/esri/themes/light/view.css +1 -1
  43. package/assets/esri/widgets/BatchAttributeForm/t9n/messages.en.json +1 -1
  44. package/{basemaps/BasemapCollection.d.ts → basemapGallery/BasemapGalleryModel.d.ts} +8 -8
  45. package/{basemaps/BasemapCollection.js → basemapGallery/BasemapGalleryModel.js} +1 -1
  46. package/{basemaps → basemapGallery}/BasemapsSource.d.ts +1 -1
  47. package/{basemaps → basemapGallery}/BasemapsSource.js +1 -1
  48. package/{basemaps → basemapGallery}/LocalBasemapsSource.d.ts +2 -2
  49. package/{basemaps → basemapGallery}/LocalBasemapsSource.js +1 -1
  50. package/{basemaps → basemapGallery}/PortalBasemapsSource.d.ts +2 -2
  51. package/{basemaps → basemapGallery}/PortalBasemapsSource.js +1 -1
  52. package/{basemaps → basemapGallery}/support/BasemapItem.d.ts +2 -2
  53. package/{basemaps → basemapGallery}/support/BasemapItem.js +1 -1
  54. package/{basemaps → basemapGallery}/types.d.ts +2 -2
  55. package/chunks/GlobalIllumination.glsl.js +4 -2
  56. package/chunks/GlobalIlluminationBlur.glsl.js +3 -5
  57. package/chunks/GlobalIlluminationUpscale.glsl.js +1 -1
  58. package/config.js +1 -1
  59. package/core/colorUtils.js +1 -1
  60. package/form/elements/inputs/DynamicChoiceInput.d.ts +35 -5
  61. package/kernel.js +1 -1
  62. package/layers/ParquetLayer.d.ts +9 -8
  63. package/layers/ParquetLayer.js +1 -1
  64. package/layers/graphics/sources/FeatureLayerSource.js +1 -1
  65. package/layers/graphics/transferFeatures.js +1 -1
  66. package/layers/raster/datasets/TIFFRaster.js +1 -1
  67. package/layers/support/ParquetPortalItemData.d.ts +2 -0
  68. package/layers/support/ParquetPortalItemData.js +1 -1
  69. package/layers/support/PortalItemData.d.ts +21 -0
  70. package/layers/support/parquetUtils.d.ts +1 -1
  71. package/layers/support/types.d.ts +1 -1
  72. package/package.json +2 -2
  73. package/symbols/cim/cimAnalyzer.js +1 -1
  74. package/views/2d/analysis/AreaMeasurementAnalysisView2D.d.ts +4 -4
  75. package/views/2d/analysis/DistanceMeasurementAnalysisView2D.d.ts +4 -4
  76. package/views/2d/layers/features/sources/strategies/FeatureDrillDownTileLoadStrategy.js +1 -1
  77. package/views/2d/layers/features/support/FeatureSetReader.js +1 -1
  78. package/views/3d/analysis/LineOfSight/LineOfSightEditTool.js +1 -1
  79. package/views/3d/analysis/LineOfSight/LineOfSightItemTool.js +1 -1
  80. package/views/3d/analysis/ViewshedAnalysisView3D.d.ts +3 -0
  81. package/views/3d/analysis/VolumeMeasurementAnalysisView3D.d.ts +2 -1
  82. package/views/3d/interactive/editingTools/move/MoveTool3D.js +1 -1
  83. package/views/3d/layers/support/FeatureMemory.js +1 -1
  84. package/views/3d/layers/support/FeatureTile.js +1 -1
  85. package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
  86. package/views/3d/layers/support/featureTileQuery3D.js +1 -1
  87. package/views/3d/support/PBFDecoder.js +1 -1
  88. package/views/3d/webgl-engine/core/shaderLibrary/shading/ReadGlobalIllumination.glsl.js +16 -11
  89. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIllumination.js +1 -1
  90. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIlluminationColorQuantization.glsl.js +2 -2
  91. package/views/SceneView.d.ts +4 -10
  92. package/views/View.d.ts +4 -12
  93. package/views/interactive/options/SnappingOptions.d.ts +29 -12
  94. package/views/interactive/options/TooltipOptions.d.ts +9 -1
  95. package/views/interactive/options/ValueOptions.d.ts +9 -2
  96. package/views/interactive/options/ViewOptions.d.ts +82 -6
  97. package/views/interactive/support/Units.d.ts +1 -0
  98. package/widgets/BasemapGallery/BasemapGalleryViewModel.d.ts +2 -2
  99. package/widgets/BasemapGallery/BasemapGalleryViewModel.js +1 -1
  100. package/widgets/BasemapGallery/support/BasemapGalleryItem.d.ts +3 -3
  101. package/widgets/BasemapGallery/support/LocalBasemapsSource.d.ts +2 -2
  102. package/widgets/BasemapGallery/support/PortalBasemapsSource.d.ts +2 -2
  103. package/widgets/BasemapGallery/types.d.ts +3 -3
  104. package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.js +1 -1
  105. package/widgets/BatchAttributeForm/expressions/ExpressionsManager.js +1 -1
  106. package/widgets/BatchAttributeForm/expressions/expressionUtils.js +1 -1
  107. package/widgets/BatchAttributeForm/inputs/FieldInput.d.ts +6 -0
  108. package/widgets/BatchAttributeForm/inputs/FieldInput.js +1 -1
  109. package/widgets/BatchAttributeForm/inputs/support/DynamicChoiceController.js +1 -1
  110. package/widgets/BatchAttributeForm/inputs/support/createBatchFormInputs.js +1 -1
  111. package/widgets/BatchAttributeForm.js +1 -1
  112. package/widgets/Editor/EditorViewModel.d.ts +13 -8
  113. package/widgets/Editor.d.ts +9 -9
  114. package/widgets/FeatureForm.d.ts +2 -2
  115. package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
  116. package/widgets/Sketch/SketchViewModel.d.ts +13 -8
  117. package/widgets/Sketch.d.ts +9 -9
  118. package/assets/esri/core/workers/chunks/14a3808427deaaa85bf2.js +0 -1
  119. package/assets/esri/core/workers/chunks/1b551ef3d84d9c1e93f9.js +0 -1
  120. package/assets/esri/core/workers/chunks/260dcb79dfd0f981949f.js +0 -1
  121. package/assets/esri/core/workers/chunks/303676d1b10676c9cab4.js +0 -1
  122. package/assets/esri/core/workers/chunks/37a636f61cfe89c6bfd1.js +0 -1
  123. package/assets/esri/core/workers/chunks/4097edb2ad522dff50ce.js +0 -1
  124. package/assets/esri/core/workers/chunks/4a0216ee6382d9276f1c.js +0 -1
  125. package/assets/esri/core/workers/chunks/55766692b578e60dd70e.js +0 -1742
  126. package/assets/esri/core/workers/chunks/57970d43cdcc5cf57a30.js +0 -1
  127. package/assets/esri/core/workers/chunks/5fd099ca1024707387b2.js +0 -1
  128. package/assets/esri/core/workers/chunks/68e24fa3f564c2a5c9fd.js +0 -1
  129. package/assets/esri/core/workers/chunks/8e7a33cc1f83063043f2.js +0 -1
  130. package/assets/esri/core/workers/chunks/a23272a7a47a95f6ddea.js +0 -1
  131. package/assets/esri/core/workers/chunks/cbdebdfa5f2cded29d0d.js +0 -1
  132. package/assets/esri/core/workers/chunks/cfae60b9d2f2939e9c16.js +0 -1
  133. package/assets/esri/core/workers/chunks/d56780290e0218d3e9de.js +0 -1
  134. package/assets/esri/core/workers/chunks/de24fc414a3f243d675e.js +0 -1
  135. package/assets/esri/core/workers/chunks/e22d45aeef293a5ffb78.js +0 -1
  136. package/assets/esri/core/workers/chunks/ea746d9bbea170719a1c.js +0 -1
  137. package/assets/esri/core/workers/chunks/f0c0c02730fe0d948fc1.js +0 -1
  138. /package/{basemaps → basemapGallery}/support/basemapCompatibilityUtils.js +0 -0
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{pushIfSome as t}from"../../core/arrayUtils.js";import{createTask as n}from"../../core/asyncUtils.js";import r from"../../core/Collection.js";import i from"../../core/Error.js";import{EventedAccessor as a}from"../../core/Evented.js";import o from"../../core/Logger.js";import{getOrCreateMapValue as s}from"../../core/MapUtils.js";import{destroyMaybe as c,abortMaybe as l}from"../../core/maybe.js";import{throwIfAborted as u,whenOrAbort as ee,ignoreAbortErrors as d,isAbortError as f}from"../../core/promiseUtils.js";import p from"../../core/ReactiveMap.js";import{on as te,sync as m,watch as h,syncAndInitial as g,initial as _,whenOnce as v}from"../../core/reactiveUtils.js";import{property as y,subclass as b}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as ne}from"../../core/support/UpdatingHandles.js";import x from"../../geometry/SpatialReference.js";import{getGraphicLayer as S}from"../../graphic/graphicOriginUtils.js";import{isSubtypeGroupLayer as C,isSubtypeSublayer as w,isFeatureLayer as re,getSubtypesFromLayer as ie}from"../../layers/support/layerUtils.js";import{system as T}from"../../time/constants.js";import{getAttachmentKey as E}from"./attachmentUtils.js";import{getLayerTimeZone as D,getEffectiveTimeZone as O,createReactiveGraphic as k,isAttributeFormSupportedLayerWithAttachments as A,layerSupportsAttachments as j,queryAttachmentsForElements as M}from"./batchAttributeFormUtils.js";import{ReactiveContingentValuesManager as N}from"./ReactiveContingentValuesManager.js";import{parseFormTemplateString as P}from"./stringUtils.js";import{ValueChangeTransaction as F}from"./ValueChangeTransaction.js";import{ArcadeExecutorProvider as I}from"./expressions/ArcadeExecutorProvider.js";import{ExpressionsManager as L}from"./expressions/ExpressionsManager.js";import{ExpressionsModel as R}from"./expressions/ExpressionsModel.js";import z from"./inputs/BatchFormInputs.js";import{createBatchFormInputsFromBatchFormTemplate as B,mergeBatchFormInputsFromNewTemplate as V}from"./inputs/support/createBatchFormInputs.js";import{isGroupInput as H,isFieldInput as U}from"./inputs/support/inputUtils.js";import W from"./templates/BatchFormTemplate.js";import{createBatchFormTemplate as G}from"./templates/support/createBatchFormTemplate.js";import{isExcludedFromSharedForm as K,isGroupElementTemplate as q}from"./templates/support/templateUtils.js";import{ContingentValuesManager as J,isLayerWithContingentValues as Y}from"../support/ContingentValuesManager.js";import{isEmptyValue as X}from"../support/forms/formUtils.js";function ae(e,t){return e?.find(e=>e.layer===t)}let Z=class extends a{constructor(e){super(e),this._attachmentCache=new p,this.activeFeatureIndex=-1,this.attachmentsEnabled=!1,this.callbacks=null,this.disabled=!1,this.editType=`NA`,this.features=new r,this._hasAsyncArcadeExpressions=!1,this.highlightHelper=null,this.maximumFeatureCount=2e3,this.maximumFeatureCountWithComplexForms=50,this.pageStack=[],this.readOnly=!1,this.pendingSubtypeChoice=null,this.spatialReference=null,this.submitHasBeenAttempted=!1,this.view=null,this.userHasChangedValues=!1,this.layerInfos=null,this._arcadeExecutorProvider=new I,this._activeAssociation=null,this._activeAssociationsInput=null,this._activeRelationshipInput=null,this._ownContingentValuesManager=null,this._activeFormInputsByElementId=new Map,this._emptyForm=new z({inputs:[]}),this._emptyFormTemplate=new W({elements:[]}),this._featureFormMap=new p,this._prepareTask=null,this._layerTemplateUpdateTask=null,this._syncAttachmentsTask=null,this._reactiveGraphicLookup=new p,this._updatingHandles=new ne,this._submitTask=null,this._layerTemplateMap=new p,this._workingFeatures=new r,this._expressionsManager=new L({arcadeContext:{editType:`NA`,spatialReference:null,map:null,timeZone:T}}),this._getExternalErrorForFeature=(e,t)=>this._reactiveContingentValuesManager.getViolationTypeForField(e,t),this._getFieldValueOptionsForFeature=e=>this._reactiveContingentValuesManager.getAndWatchFieldValueOptions(e),this.sharedForm=this._emptyForm,this.sharedFormTemplate=this._emptyFormTemplate}initialize(){this.contingentValuesManager||=this._ownContingentValuesManager=new J,this.addHandles([te(()=>this.features,`after-changes`,()=>{this.goHome(),this.notifyChange(`layers`),this._prepare()},m),h(()=>[this.attachmentsEnabled,this.features,this.map,this.timeZone,this.editType],()=>this._prepare(),m),h(()=>this.activeForm,()=>{this.goHome(),this._activeFormInputsByElementId.clear(),this._syncAttachments()},m),h(()=>this.activeFeature,()=>{this.goHome()},m),h(()=>this.page,e=>{let t=[...this.pageStack];if(!t.includes(e))t.push(e);else for(;t.length&&t.at(-1)!==e;)t.pop();this.pageStack=t},g),h(()=>this.contingentValuesManager,e=>{c(this._reactiveContingentValuesManager),this._reactiveContingentValuesManager=new N({manager:e})},_)]),this._prepare()}destroy(){this._prepareTask=l(this._prepareTask),this.pendingSubtypeChoice?.reject(),this._layerTemplateUpdateTask=l(this._layerTemplateUpdateTask),this._syncAttachmentsTask=l(this._syncAttachmentsTask),this._workingFeatures.destroyAll(),c(this._expressionsManager),c(this._reactiveContingentValuesManager),this._updatingHandles.destroy(),this._reactiveGraphicLookup=new p,this._emptyForm.destroy(),this._emptyFormTemplate.destroy(),this._ownContingentValuesManager=c(this._ownContingentValuesManager),this.highlightHelper?.removeAll()}get activeFeature(){let e=this.activeFeatureIndex;return e<0?null:this.features.at(e)}get activeForm(){if(this.mode===`batch`)return this.sharedForm;let e=this._workingFeatures.at(this.activeFeatureIndex);if(!e)return this._emptyForm;let t=this._featureFormMap.get(e);if(t)return t;let n=this._makeBatchFormInputsForFeature(e);return n!==this._emptyForm&&this._featureFormMap.set(e,n),n}get activeLayer(){let{activeFeature:e}=this;return e?S(e)??null:null}get activeAssociation(){return this._activeAssociation}get activeAssociationsInput(){return this._activeAssociationsInput}get activeAssociationType(){return this.activeAssociationsInput?.activeAssociationType}get activeRelationshipInput(){return this._activeRelationshipInput}get calculating(){return this._expressionsManager.calculating}get expressionsManager(){return this._expressionsManager}get canGoBack(){return this.pageStack.length>1}get expressionEvaluationFailed(){return this._expressionsManager.expressionEvaluationFailed}get hasNonActiveInvalidFeatures(){if(this.mode===`batch`)return!1;let{activeFeature:e}=this;return this.invalidFeatures.some(t=>t!==e)}get hasAsyncArcadeExpressions(){return this._hasAsyncArcadeExpressions}get hasTooManyFeatures(){return this._workingFeatures.length>this.maximumFeatureCount}get hasTooManyComplexFeatures(){return this._workingFeatures.length>this.maximumFeatureCountWithComplexForms&&this.hasAsyncArcadeExpressions}get invalidFeatures(){return this.sharedForm.invalidFeatures}get hasVisibleInputs(){return this.visibleInputs.length>0}get hasLayersWithContingentValues(){let e=this.contingentValuesManager;for(let t of this.layers)if(e.getFieldsWithContingentValues(t).size>0)return!0;return!1}get formDescription(){return this._computeFormHeaderField(this.activeForm?.description)}get formTitle(){return this._computeFormHeaderField(this.activeForm?.title)}get effectiveTimeZone(){let{activeLayer:e,timeZone:t}=this;if(!e)return t??`system`;let n=D(e);return O(t,n)}get visibleInputs(){return this.activeForm.inputs.filter(e=>e.visible)}get map(){return this.view?.map??null}set map(e){this._override(`map`,e)}get noVisibleElementsReason(){if(this.hasVisibleInputs)return null;if(this.activeForm.inputs.length===0)return`noElements`;let e=new Set;for(let t of this.activeForm.inputs)switch(t.visibilityCode){case`hidden:not-in-all-layers`:case`hidden:no-domain-in-common`:e.add(`noElementsInCommon`);break;case`hidden:field-definition`:case`hidden:group-visibility-expression:all-features`:case`hidden:visibility-expression:all-features`:e.add(`allElementsHidden`);break;case`hidden:group-visibility-expression:some-features`:case`hidden:visibility-expression:some-features`:return`elementsHiddenInSome`}return e.has(`allElementsHidden`)?`allElementsHidden`:`noElementsInCommon`}get page(){return this.showingSelectedAttachmentReplacePage&&this.selectedAttachmentDetails?`replacing-attachment`:this.selectedAttachmentDetails?`viewing-attachment-details`:this.selectedAttachmentAddInput?`adding-attachments`:this.selectedAttachmentListInput?`viewing-attachments`:this.activeAssociationsInput?.associatedLayer?`viewing-associated-features`:this.activeAssociationsInput?`viewing-associated-layers`:this.activeRelationshipInput?.showAllRelatedRecords?`viewing-related-records`:this.activeRelationshipInput?.showAllCategories?`viewing-related-categories`:`default`}get subtypes(){let e=this.activeLayer;return C(e)||w(e)||re(e)?ie(e):[]}get status(){let e=this._prepareTask;return e==null?`not-loaded`:e.finished?e.error==null?`loaded`:`failed`:`loading`}get timeZone(){return this.view?.timeZone??null}set timeZone(e){this._overrideIfSome(`timeZone`,e)}get updating(){return this._updatingHandles.updating||this.calculating}get valid(){return this.sharedForm.valid&&Array.from(this._featureFormMap.values()).every(e=>e.valid)}get layers(){return Array.from(this._layersSet)}get mode(){return this.activeFeatureIndex>-1?`single`:`batch`}submit(){if(this.submitHasBeenAttempted=!0,this.sharedForm.touchAll(),this._featureFormMap.forEach(e=>e.touchAll()),this.validateContingentValues(this._workingFeatures),!this._hasPendingAttachmentHydration)return this._emitSubmit(),Promise.resolve();if(this._submitTask)return this._submitTask.promise;let e=n(async()=>{await Promise.all(this._allAttachmentInputs.map(e=>e.waitForPendingAttachmentUpdateData())),this._emitSubmit()});return this._submitTask=e,e.promise.finally(()=>{this._submitTask===e&&(this._submitTask=null)}),e.promise}get selectedAttachment(){return this._get(`selectedAttachment`)??null}set selectedAttachment(e){this.showingSelectedAttachmentReplacePage=!1,this._set(`selectedAttachment`,e),e!=null&&(this.selectedAttachmentAddElementId=null)}get selectedAttachmentAddElementId(){return this._get(`selectedAttachmentAddElementId`)??null}set selectedAttachmentAddElementId(e){this.showingSelectedAttachmentReplacePage=!1,this._set(`selectedAttachmentAddElementId`,e),e!=null&&(this.selectedAttachment=null,this.selectedAttachmentListElementId=null)}get selectedAttachmentListElementId(){return this._get(`selectedAttachmentListElementId`)??null}set selectedAttachmentListElementId(e){this._set(`selectedAttachmentListElementId`,e),e!=null&&(this.selectedAttachment=null,this.selectedAttachmentAddElementId=null)}get selectedAttachmentListInput(){let e=this.selectedAttachmentListElementId,t=this.activeForm;if(!e||!t)return null;let n=t.allAttachmentElementInputs.find(t=>t.template.elementId===e)||null;return n?.attachments.length?n:null}get showingSelectedAttachmentReplacePage(){return this._get(`showingSelectedAttachmentReplacePage`)??!1}set showingSelectedAttachmentReplacePage(e){this._set(`showingSelectedAttachmentReplacePage`,e&&this.selectedAttachmentDetails!=null)}get selectedAttachmentAddInput(){let e=this.selectedAttachmentAddElementId,t=this.activeForm;return!e||!t?null:t.allAttachmentElementInputs.find(t=>t.template.elementId===e)||null}get selectedAttachmentDetails(){let e=this.selectedAttachment,t=this.activeForm;if(!e||!t)return null;let n=t.allAttachmentElementInputs.find(t=>t.template.elementId===e.elementId);if(!n)return null;let r=n.attachments.findIndex(t=>E(t)===e.attachmentKey);return r===-1?null:{attachment:n.attachments[r],input:n}}get _allAttachmentInputs(){let e=[...this.sharedForm.allAttachmentElementInputs];for(let t of this._featureFormMap.values())e.push(...t.allAttachmentElementInputs);return e}get _hasPendingAttachmentHydration(){return this._allAttachmentInputs.some(e=>e.hasPendingAttachmentUpdateData)}get _layersSet(){let e=new Set;for(let t of this._workingFeatures){let n=S(t.plainGraphic);n&&e.add(n)}return e}applyStashedAttachmentEdits(e){let t=this._allAttachmentInputs;for(let n of e){let e=t.find(e=>e.label===n.label&&e.attachmentKeyword===n.keywords);e&&e.applyStashedEdits(n)}}findFieldInput(e){if(e==null)return;let t=this._activeFormInputsByElementId;if(t.has(e))return t.get(e);let n=this.activeForm.allFieldInputs.find(t=>t.template.elementId===e);if(n!==void 0)return t.set(e,n),n}getFirstVisibleInvalidFieldInput(){if(this.hasVisibleInputs&&!this.activeForm.valid)for(let e of this.visibleInputs){if(H(e)){let t=e.inputs.find(e=>U(e)&&!e.valid);if(t)return{input:t,groupInput:e}}if(U(e)&&!e.valid)return{input:e}}}getFieldInputValue(e){return this.findFieldInput(e)?.value}getValues(e){let t=this._reactiveGraphicLookup.get(e);if(!t)throw new i(`feature-not-found`,`The given feature is not present in the BatchAttributeForm`);return{...t.attributes}}async goBack(){switch(this.page){case`replacing-attachment`:this.setShowingSelectedAttachmentReplacePage(!1);return;case`viewing-attachment-details`:this.setSelectedAttachment(null);return;case`adding-attachments`:this.setSelectedAttachmentAddElementId(null);return;case`viewing-attachments`:this.setSelectedAttachmentListElementId(null);return;case`viewing-associated-features`:this.setActiveAssociationsLayer(null);return;case`viewing-associated-layers`:this.setActiveAssociationsInput(null);return;case`viewing-related-categories`:case`viewing-related-records`:this.clearActiveRelationshipCategoryOrInput();return;default:return}}async goHome(){this.setShowingSelectedAttachmentReplacePage(!1),this.setSelectedAttachment(null),this.setSelectedAttachmentAddElementId(null),this.setSelectedAttachmentListElementId(null),this.setActiveAssociationsLayer(null),this.setActiveAssociationsInput(null),this.clearAllRelationshipSettings()}notifyGeometriesChanged(e){let t=[];for(let n of e){let e=this._reactiveGraphicLookup.get(n);e&&(t.push(e),e.geometry=n.geometry)}this._updatingHandles.consumePromise(this._valueChangeTransaction(async e=>this._expressionsManager.runGeometryDependentExpressions(t,e),`user`))}async overrideOriginalFeature(e,t){await this._prepareTask?.promise;let n=this._reactiveGraphicLookup.get(e);n&&(n.original=t,this._updatingHandles.consumePromise(this._valueChangeTransaction(e=>this._expressionsManager.runOriginalFeatureDependentExpressions(n,e),`expression`)))}async setFieldInputValue(e,t){let{fieldName:n}=e;await this._updatingHandles.addPromise(this._valueChangeTransaction(async r=>{for(let i of e.features)r.setValue(i,n,t)},`user`,e))}async setFieldInputValuePerFeature(e,t){await this._updatingHandles.addPromise(this._valueChangeTransaction(async n=>{for(let[r,i]of t)n.setValue(r,e.fieldName,i);n.hasChanges&&(e.userHasChangedValue=!0)},`user`,e))}async setValueForFieldName(e,t,n){await this._updatingHandles.addPromise(this._valueChangeTransaction(async r=>{for(let i of n){let n=this._reactiveGraphicLookup.get(i);n&&r.setValue(n,e,t)}},`user`,e))}async setValuePerFeatureForFieldName(e,t){await this._updatingHandles.addPromise(this._valueChangeTransaction(async n=>{for(let[r,i]of t){let t=this._reactiveGraphicLookup.get(r);t&&n.setValue(t,e,i)}},`user`,e))}async setFieldValue(e,t){let n=this.activeForm.allFieldInputs.find(t=>t.fieldName===e);if(n==null)throw new i(`no-field-input-found`,`Cannot set the value of FieldInput with field name: ${e} because none was found in the active form`);await this.setFieldInputValue(n,t)}async setValue(e,t){let n=this.findFieldInput(e);if(n==null)throw new i(`no-FieldInput-found`,`Cannot set the value of FieldInput with ID: ${e} because none was found in the active form`);await this.setFieldInputValue(n,t)}async applySubtypeDefaults(e){let{defaultValues:t}=e,{allFieldInputs:n}=this.activeForm;await this._updatingHandles.addPromise(this._valueChangeTransaction(async e=>{for(let r of n){let{fieldName:n}=r,i=t[n];if(i!=null)for(let t of r.features)e.setValue(t,n,i)}},`user`))}async handleSubtypeChanged(e){let t=this._workingFeatures.at(e);if(t)return this._updatingHandles.addPromise(this._handleSubtypeChanged(t))}async stageAddAttachments(e,t){if(t.length===0)return[];let n=this._findAttachmentInput(e);if(!n)return[];let r=await this._updatingHandles.addPromise(n.stageAddAttachments(t,this._expressionsManager.arcadeContext));return r.length===0?r:(this.userHasChangedValues=!0,this._emitAttachmentsChange(n),r)}stageDeleteAttachment(e,t){let n=this._findAttachmentInput(e);if(!n)return;let r=this._findAttachment(n,t);r&&(n.stageDeleteAttachment(r),this.userHasChangedValues=!0,this._emitAttachmentsChange(n))}async stageRenameAttachment(e,t,n){let r=this._findAttachmentInput(e);if(!r)return;let i=this._findAttachment(r,t);i&&(r.stageRenameAttachment(i,n.trim()),this.userHasChangedValues=!0,await r.ensureStagedUpdateData(i),this._emitAttachmentsChange(r))}async stageReplaceAttachment(e,t,n){let r=this._findAttachmentInput(e);if(!r)return!1;let i=this._findAttachment(r,t);return!i||!await this._updatingHandles.addPromise(r.stageReplaceAttachment(i,n,this._expressionsManager.arcadeContext))?!1:(this.userHasChangedValues=!0,this._emitAttachmentsChange(r),!0)}clearAttachmentChanges(e){let t=this._findAttachmentInput(e);t&&(t.clearAttachmentChanges(),this._emitAttachmentsChange(t))}setActiveAssociation(e){this._activeAssociation=e}setActiveAssociationsInput(e){this._activeAssociationsInput=e}setActiveAssociationsLayer(e){this._activeAssociationsInput?.setAssociatedLayer(e)}setActiveAssociationType(e){this._activeAssociationsInput?.setActiveAssociationType(e)}setActiveRelationshipInput(e){e||this._activeRelationshipInput?.setActiveCategory(null),this._activeRelationshipInput=e}setActiveRelationshipCategory(e,t){t.setActiveCategory(e),this.setActiveRelationshipInput(t)}clearAllRelationshipSettings(){let e=this.activeRelationshipInput;e&&(e.setActiveCategory(null),e.setShowAllCategories(!1),e.setShowAllRelatedRecords(!1),this._activeRelationshipInput=null)}clearActiveRelationshipCategoryOrInput(){let e=this.activeRelationshipInput;e&&(e.showAllRelatedRecords?e.showAllCategories?e.setActiveCategory(null):this.setActiveRelationshipInput(null):e.showAllCategories&&(e.setShowAllCategories(!1),this.setActiveRelationshipInput(null)))}resetAttachmentChanges(e,t){let n=this._findAttachmentInput(e);if(!n||!n.editable)return;let r=this._findAttachment(n,t);r&&(n.discardStagedEdits(r),this._emitAttachmentsChange(n))}setSelectedAttachment(e){this.selectedAttachment=e??null}setShowingSelectedAttachmentReplacePage(e){this.showingSelectedAttachmentReplacePage=e}setSelectedAttachmentAddElementId(e){this.selectedAttachmentAddElementId=e??null}setSelectedAttachmentListElementId(e){this.selectedAttachmentListElementId=e??null}userChangesHaveMadeFeatureInvalid(e){return!!this._reactiveGraphicLookup.get(e)?.userChangesHaveMadeInvalid}validate(){return!1}validateContingentValues(e,t=!1){if(t&&!this.submitHasBeenAttempted)for(let t of e)this._reactiveContingentValuesManager.validateContingenciesForNonNullFields(t);else for(let t of e)this._reactiveContingentValuesManager.validateContingencyConstraints(t,{includeIncompleteViolations:!0})}_makeBatchFormInputsForFeature(e){let t=this._layerTemplateMap.get(e.layer);return t?B(t,{allFeatures:new r([e]),expressionsManager:this._expressionsManager,getExternalErrorForFeature:this._getExternalErrorForFeature,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}):this._emptyForm}async _ensureLayerTemplate(e,t){let{_layersSet:n,contingentValuesManager:r}=this,i=e.layer,a=!1;for(let e of this._layerTemplateMap.keys())n.has(e)||(this._layerTemplateMap.delete(e),this._expressionsManager.layerExpressionsModelMap.delete(e),r.resetOptionsForLayer(e),Y(e)&&r.resetViolationsForLayer(e),a=!0);this._layerTemplateMap.has(i)||(await this._prepareLayer(i,t),u(t),r.layers.add(i),a=!0),a&&(this._prepareSharedFormTemplate(),V(this.sharedForm,this.sharedFormTemplate,{allFeatures:this._workingFeatures,expressionsManager:this._expressionsManager,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}),this._recomputeHasAsyncArcadeExpressions(),await v(()=>!r.updating,t))}_recomputeHasAsyncArcadeExpressions(){this._hasAsyncArcadeExpressions=!1;for(let e of this._expressionsManager.layerExpressionsModelMap.values())for(let t of e.arcadeExecutorUses.keys())if(t.isAsync){this._hasAsyncArcadeExpressions=!0;return}}_computeFormHeaderField(e){let{activeFeature:t,activeLayer:n}=this;return!e||!n||!t?null:P({attributes:t?.attributes,label:e,layer:n,timeZone:this.effectiveTimeZone})}_makeSubmitResults(){let e=new Map;for(let[n,r]of this._reactiveGraphicLookup){let i=[],a=[],o=this._featureFormMap.get(r)?.allAttachmentElementInputs??[];for(let e of o)t(i,e.toSubmitEdits()),e.valid||a.push(e.template.elementId);e.set(n,{feature:n,values:{...r.attributes},invalidFields:[],attachmentEdits:i,invalidAttachmentElementIds:a})}for(let t of this.sharedForm.allFieldInputs)for(let n of t.invalidFeatures)e.get(n)?.invalidFields.push(t.fieldName);return Array.from(e.values())}async _handleSubtypeChanged(e){let t=e.layer;if(this.contingentValuesManager.resetOptionsForFeature(t,e.plainGraphic),Y(t)&&this.contingentValuesManager.resetViolationsForFeature(t,e.plainGraphic),!w(t))return;let r=t.parent?.findSublayerForFeature(e.plainGraphic);if(!r)return;this._layerTemplateUpdateTask=l(this._layerTemplateUpdateTask);let i=n(async t=>{u(t),e.source.sourceLayer=r,e.source.origin=r.graphicOrigin,await this._ensureLayerTemplate(e,t),u(t),this._featureFormMap.get(e)?.destroy(),this._featureFormMap.set(e,this._makeBatchFormInputsForFeature(e)),await ee(this._valueChangeTransaction(t=>this._expressionsManager.runAllExpressions([e],t),`user`),t),u(t)});this._layerTemplateUpdateTask=i,await d(this._updatingHandles.addPromise(i.promise))}_emitSubmit(){this.emit(`submit`,{name:`submit`,results:this._makeSubmitResults(),valid:this.valid})}_findAttachmentInput(e){let t=this.activeForm.allAttachmentElementInputs.find(t=>t.template.elementId===e);return t||o.getLogger(this).error(`Attachment input not found for elementId '${e}'`),t}_findAttachment(e,t){let n=e.findAttachment(t);return n||o.getLogger(this).error(`Attachment '${t}' not found for attachment element '${e.template.elementId}'`),n}_makeAttachmentEdits(e){let n=[];for(let r of e.allAttachmentElementInputs)t(n,r.toSubmitEdits());return n}_emitAttachmentsChange(e){let t=e.single.feature;if(!t)return;let n=this._featureFormMap.get(t);this.emit(`attachments-change`,{name:`attachments-change`,feature:t.source,attachmentEdits:this._makeAttachmentEdits(n??this.activeForm),valid:this.valid})}async _valueChangeTransaction(e,t,n){let r=typeof n==`string`?n:n?.fieldName,i=new F(this,t,r);if(await e(i),t===`user`&&await this._expressionsManager.runExpressionsDependentOnChangedFields(i),await i.close(),i.hasChanges&&n){let e=typeof n==`string`?this.activeForm.allFieldInputs.find(e=>e.fieldName===n):n;e&&(e.userHasChangedValue=!0)}}_prepare(){this.pendingSubtypeChoice?.reject(),this._hasAsyncArcadeExpressions=!1,this._prepareTask=l(this._prepareTask),this._layerTemplateUpdateTask=l(this._layerTemplateUpdateTask),this._layerTemplateMap.clear(),this._updateWorkingFeatures(),c(this._expressionsManager),this.userHasChangedValues=!1,this._expressionsManager=new L({arcadeContext:{editType:this.editType,spatialReference:this.spatialReference??x.WebMercator,map:this.map,timeZone:this.timeZone||`system`}});let{layers:e}=this;if(e.length===0)return;let t=n(async t=>{try{u(t),this._updateWorkingFeatures(),this.contingentValuesManager.layers.addMany(e),await Promise.all(e.map(e=>e.load()));for(let n of e)await this._prepareLayer(n,t);if(this.hasTooManyComplexFeatures)throw new i(`too-many-features-with-complex-forms`,`There are too many features to load into the form with the configured complexity`);if(this.hasTooManyFeatures)throw new i(`too-many-features`,`There are too many features to load into the form.`);this._prepareSharedFormTemplate(),this.sharedForm=B(this.sharedFormTemplate,{allFeatures:this._workingFeatures,expressionsManager:this._expressionsManager,getExternalErrorForFeature:this._getExternalErrorForFeature,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}),await this._valueChangeTransaction(async e=>await this._expressionsManager.runAllExpressions(this._workingFeatures.toArray(),e),`expression`),await v(()=>!this.contingentValuesManager.updating)}catch(e){throw f(e)||o.getLogger(this).error(`Failed preparing form`,e),e}});this._updatingHandles.consumePromise(t.promise),this._prepareTask=t}async _prepareLayer(e,t){let n=ae(this.layerInfos,e),r=await G(e,{arcadeExecutorProvider:this._arcadeExecutorProvider,formTimeZone:this.timeZone,attachmentsEnabled:this.attachmentsEnabled},n?.formTemplate);u(t),this._layerTemplateMap.set(e,r);let i=r.getExpressionExecutorsForLayer(e);if(this._expressionsManager.layerExpressionsModelMap.set(e,new R({preserveFieldValuesWhenHidden:r.preserveFieldValuesWhenHidden,executorMap:i,fieldsIndex:e.fieldsIndex})),!this._hasAsyncArcadeExpressions){for(let e of i.values())if(e&&(this._hasAsyncArcadeExpressions=(e.editableExpression?.isAsync||e.requiredExpression?.isAsync||e.valueExpression?.isAsync||e.visibilityExpression?.isAsync)===!0,this._hasAsyncArcadeExpressions))break}}_prepareSharedFormTemplate(){let e=new Map;for(let t of this._layerTemplateMap.values())for(let n of t.elements){if(K(n))continue;let t=n.clone();q(t)&&(t.elements=t.elements.filter(e=>!K(e)));let{elementId:r}=t;e.has(r)?e.get(r).foldIn(t):e.set(r,t)}this.sharedFormTemplate=new W({elements:Array.from(e.values())})}_updateWorkingFeatures(){this._workingFeatures.destroyAll(),this._reactiveContingentValuesManager.reset();for(let e of this._featureFormMap.values())e.destroy();this._featureFormMap.clear(),this._attachmentCache.clear();let{features:e}=this;if(this._reactiveGraphicLookup=new p,e.length!==0){this._workingFeatures.addMany(e.map(k));for(let e of this._workingFeatures)this._reactiveGraphicLookup.set(e.source,e)}}async _syncAttachments(){let{activeFeature:e,activeLayer:t,activeForm:r}=this;if(!e||!r||!A(t)||!j(t))return;let i=e.getObjectId();if(i==null)return;let a=this._attachmentCache.get(t),o=r.allAttachmentElementInputs;if(!o.length)return;let c=n(async e=>{let n;if(a){let e=a.get(i);e&&(n=e)}n||(n=await M(t,i,o,e),s(this._attachmentCache,t,()=>new p).set(i,n));for(let e of o)e.applyFetchedAttachments(se(e,n))});this._syncAttachmentsTask=c,await d(c.promise)}get test(){return{expressionsManager:this._expressionsManager,reactiveGraphicLookup:this._reactiveGraphicLookup,syncAttachmentsTask:this._syncAttachmentsTask}}};e([y()],Z.prototype,`_attachmentCache`,void 0),e([y({readOnly:!0})],Z.prototype,`activeFeature`,null),e([y()],Z.prototype,`activeFeatureIndex`,void 0),e([y({readOnly:!0})],Z.prototype,`activeForm`,null),e([y({readOnly:!0})],Z.prototype,`activeLayer`,null),e([y()],Z.prototype,`activeAssociation`,null),e([y()],Z.prototype,`activeAssociationsInput`,null),e([y()],Z.prototype,`activeAssociationType`,null),e([y()],Z.prototype,`activeRelationshipInput`,null),e([y()],Z.prototype,`attachmentsEnabled`,void 0),e([y()],Z.prototype,`callbacks`,void 0),e([y()],Z.prototype,`disabled`,void 0),e([y()],Z.prototype,`calculating`,null),e([y()],Z.prototype,`canGoBack`,null),e([y()],Z.prototype,`contingentValuesManager`,void 0),e([y()],Z.prototype,`editType`,void 0),e([y()],Z.prototype,`features`,void 0),e([y()],Z.prototype,`expressionEvaluationFailed`,null),e([y()],Z.prototype,`hasNonActiveInvalidFeatures`,null),e([y()],Z.prototype,`hasAsyncArcadeExpressions`,null),e([y()],Z.prototype,`_hasAsyncArcadeExpressions`,void 0),e([y()],Z.prototype,`invalidFeatures`,null),e([y()],Z.prototype,`hasVisibleInputs`,null),e([y()],Z.prototype,`hasLayersWithContingentValues`,null),e([y()],Z.prototype,`formDescription`,null),e([y()],Z.prototype,`formTitle`,null),e([y()],Z.prototype,`effectiveTimeZone`,null),e([y()],Z.prototype,`highlightHelper`,void 0),e([y()],Z.prototype,`maximumFeatureCount`,void 0),e([y()],Z.prototype,`maximumFeatureCountWithComplexForms`,void 0),e([y()],Z.prototype,`visibleInputs`,null),e([y()],Z.prototype,`map`,null),e([y()],Z.prototype,`noVisibleElementsReason`,null),e([y()],Z.prototype,`page`,null),e([y()],Z.prototype,`pageStack`,void 0),e([y()],Z.prototype,`readOnly`,void 0),e([y()],Z.prototype,`pendingSubtypeChoice`,void 0),e([y()],Z.prototype,`subtypes`,null),e([y()],Z.prototype,`spatialReference`,void 0),e([y()],Z.prototype,`submitHasBeenAttempted`,void 0),e([y()],Z.prototype,`timeZone`,null),e([y()],Z.prototype,`view`,void 0),e([y()],Z.prototype,`updating`,null),e([y()],Z.prototype,`valid`,null),e([y()],Z.prototype,`layers`,null),e([y()],Z.prototype,`mode`,null),e([y()],Z.prototype,`sharedForm`,void 0),e([y()],Z.prototype,`sharedFormTemplate`,void 0),e([y()],Z.prototype,`selectedAttachment`,null),e([y()],Z.prototype,`selectedAttachmentAddElementId`,null),e([y()],Z.prototype,`selectedAttachmentListElementId`,null),e([y()],Z.prototype,`selectedAttachmentListInput`,null),e([y()],Z.prototype,`showingSelectedAttachmentReplacePage`,null),e([y()],Z.prototype,`selectedAttachmentAddInput`,null),e([y()],Z.prototype,`selectedAttachmentDetails`,null),e([y()],Z.prototype,`userHasChangedValues`,void 0),e([y()],Z.prototype,`layerInfos`,void 0),e([y()],Z.prototype,`_arcadeExecutorProvider`,void 0),e([y()],Z.prototype,`_activeAssociation`,void 0),e([y()],Z.prototype,`_activeAssociationsInput`,void 0),e([y()],Z.prototype,`_activeRelationshipInput`,void 0),e([y()],Z.prototype,`_prepareTask`,void 0),e([y()],Z.prototype,`_reactiveGraphicLookup`,void 0),e([y()],Z.prototype,`_allAttachmentInputs`,null),e([y()],Z.prototype,`_hasPendingAttachmentHydration`,null),e([y()],Z.prototype,`_layerTemplateMap`,void 0),e([y()],Z.prototype,`_layersSet`,null),e([y()],Z.prototype,`_workingFeatures`,void 0),e([y()],Z.prototype,`_expressionsManager`,void 0),Z=e([b(`esri.widgets.BatchAttributeForm.BatchAttributeFormViewModel`)],Z);const oe=Z;function Q(e){return e!=null&&e.trim().length>0}function $(e,t){let n=e.keywords;return Q(n)&&n.toLowerCase()===t}function se(e,t){let n=e.input?.type===`attachment`?e.input.attachmentAssociationType:`exact`,r=e.attachmentKeyword;if(n===`any`)return t;if(n===`exactOrNone`){if(X(r))return t.filter(e=>!Q(e.keywords));let e=r.toLowerCase();return t.filter(t=>!Q(t.keywords)||$(t,e))}if(X(r))return t;let i=r.toLowerCase();return t.filter(e=>$(e,i))}export{oe as default};
2
+ import{__decorate as e}from"tslib";import{pushIfSome as t}from"../../core/arrayUtils.js";import{createTask as n}from"../../core/asyncUtils.js";import r from"../../core/Collection.js";import i from"../../core/Error.js";import{EventedAccessor as a}from"../../core/Evented.js";import o from"../../core/Logger.js";import{getOrCreateMapValue as s}from"../../core/MapUtils.js";import{destroyMaybe as c,abortMaybe as l}from"../../core/maybe.js";import{throwIfAborted as u,whenOrAbort as ee,ignoreAbortErrors as d,isAbortError as f}from"../../core/promiseUtils.js";import p from"../../core/ReactiveMap.js";import{on as te,sync as m,watch as h,syncAndInitial as g,initial as _,whenOnce as v}from"../../core/reactiveUtils.js";import{property as y,subclass as b}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as ne}from"../../core/support/UpdatingHandles.js";import x from"../../geometry/SpatialReference.js";import{getGraphicLayer as S}from"../../graphic/graphicOriginUtils.js";import{isSubtypeGroupLayer as C,isSubtypeSublayer as w,isFeatureLayer as re,getSubtypesFromLayer as ie}from"../../layers/support/layerUtils.js";import{system as T}from"../../time/constants.js";import{getAttachmentKey as E}from"./attachmentUtils.js";import{getLayerTimeZone as D,getEffectiveTimeZone as O,createReactiveGraphic as k,isAttributeFormSupportedLayerWithAttachments as A,layerSupportsAttachments as j,queryAttachmentsForElements as M}from"./batchAttributeFormUtils.js";import{ReactiveContingentValuesManager as N}from"./ReactiveContingentValuesManager.js";import{parseFormTemplateString as P}from"./stringUtils.js";import{ValueChangeTransaction as F}from"./ValueChangeTransaction.js";import{ArcadeExecutorProvider as I}from"./expressions/ArcadeExecutorProvider.js";import{ExpressionsManager as L}from"./expressions/ExpressionsManager.js";import{ExpressionsModel as R}from"./expressions/ExpressionsModel.js";import z from"./inputs/BatchFormInputs.js";import{createBatchFormInputsFromBatchFormTemplate as B,mergeBatchFormInputsFromNewTemplate as V}from"./inputs/support/createBatchFormInputs.js";import{isGroupInput as H,isFieldInput as U}from"./inputs/support/inputUtils.js";import W from"./templates/BatchFormTemplate.js";import{createBatchFormTemplate as G}from"./templates/support/createBatchFormTemplate.js";import{isExcludedFromSharedForm as K,isGroupElementTemplate as q}from"./templates/support/templateUtils.js";import{ContingentValuesManager as J,isLayerWithContingentValues as Y}from"../support/ContingentValuesManager.js";import{isEmptyValue as X}from"../support/forms/formUtils.js";function ae(e,t){return e?.find(e=>e.layer===t)}let Z=class extends a{constructor(e){super(e),this._attachmentCache=new p,this.activeFeatureIndex=-1,this.attachmentsEnabled=!1,this.callbacks=null,this.disabled=!1,this.editType=`NA`,this.features=new r,this._hasAsyncArcadeExpressions=!1,this.highlightHelper=null,this.maximumFeatureCount=2e3,this.maximumFeatureCountWithComplexForms=50,this.pageStack=[],this.readOnly=!1,this.pendingSubtypeChoice=null,this.spatialReference=null,this.submitHasBeenAttempted=!1,this.view=null,this.userHasChangedValues=!1,this.layerInfos=null,this._arcadeExecutorProvider=new I,this._activeAssociation=null,this._activeAssociationsInput=null,this._activeRelationshipInput=null,this._ownContingentValuesManager=null,this._activeFormInputsByElementId=new Map,this._emptyForm=new z({inputs:[]}),this._emptyFormTemplate=new W({elements:[]}),this._featureFormMap=new p,this._prepareTask=null,this._layerTemplateUpdateTask=null,this._syncAttachmentsTask=null,this._reactiveGraphicLookup=new p,this._updatingHandles=new ne,this._submitTask=null,this._layerTemplateMap=new p,this._workingFeatures=new r,this._expressionsManager=new L({arcadeContext:{editType:`NA`,spatialReference:null,map:null,timeZone:T}}),this._getExternalErrorForFeature=(e,t)=>this._reactiveContingentValuesManager.getViolationTypeForField(e,t),this._getFieldValueOptionsForFeature=e=>this._reactiveContingentValuesManager.getAndWatchFieldValueOptions(e),this._requestDeferredExpressionEvaluation=async({features:e,getExecutor:t})=>this._valueChangeTransaction(n=>this._expressionsManager.requestDeferredExecution(e,t,n),`user`),this.sharedForm=this._emptyForm,this.sharedFormTemplate=this._emptyFormTemplate}initialize(){this.contingentValuesManager||=this._ownContingentValuesManager=new J,this.addHandles([te(()=>this.features,`after-changes`,()=>{this.goHome(),this.notifyChange(`layers`),this._prepare()},m),h(()=>[this.attachmentsEnabled,this.features,this.map,this.timeZone,this.editType],()=>this._prepare(),m),h(()=>this.activeForm,()=>{this.goHome(),this._activeFormInputsByElementId.clear(),this._syncAttachments()},m),h(()=>this.activeFeature,()=>{this.goHome()},m),h(()=>this.page,e=>{let t=[...this.pageStack];if(!t.includes(e))t.push(e);else for(;t.length&&t.at(-1)!==e;)t.pop();this.pageStack=t},g),h(()=>this.contingentValuesManager,e=>{c(this._reactiveContingentValuesManager),this._reactiveContingentValuesManager=new N({manager:e})},_)]),this._prepare()}destroy(){this._prepareTask=l(this._prepareTask),this.pendingSubtypeChoice?.reject(),this._layerTemplateUpdateTask=l(this._layerTemplateUpdateTask),this._syncAttachmentsTask=l(this._syncAttachmentsTask),this._workingFeatures.destroyAll(),c(this._expressionsManager),c(this._reactiveContingentValuesManager),this._updatingHandles.destroy(),this._reactiveGraphicLookup=new p,this._emptyForm.destroy(),this._emptyFormTemplate.destroy(),this._ownContingentValuesManager=c(this._ownContingentValuesManager),this.highlightHelper?.removeAll()}get activeFeature(){let e=this.activeFeatureIndex;return e<0?null:this.features.at(e)}get activeForm(){if(this.mode===`batch`)return this.sharedForm;let e=this._workingFeatures.at(this.activeFeatureIndex);if(!e)return this._emptyForm;let t=this._featureFormMap.get(e);if(t)return t;let n=this._makeBatchFormInputsForFeature(e);return n!==this._emptyForm&&this._featureFormMap.set(e,n),n}get activeLayer(){let{activeFeature:e}=this;return e?S(e)??null:null}get activeAssociation(){return this._activeAssociation}get activeAssociationsInput(){return this._activeAssociationsInput}get activeAssociationType(){return this.activeAssociationsInput?.activeAssociationType}get activeRelationshipInput(){return this._activeRelationshipInput}get calculating(){return this._expressionsManager.calculating}get expressionsManager(){return this._expressionsManager}get canGoBack(){return this.pageStack.length>1}get expressionEvaluationFailed(){return this._expressionsManager.expressionEvaluationFailed}get hasNonActiveInvalidFeatures(){if(this.mode===`batch`)return!1;let{activeFeature:e}=this;return this.invalidFeatures.some(t=>t!==e)}get hasAsyncArcadeExpressions(){return this._hasAsyncArcadeExpressions}get hasTooManyFeatures(){return this._workingFeatures.length>this.maximumFeatureCount}get hasTooManyComplexFeatures(){return this._workingFeatures.length>this.maximumFeatureCountWithComplexForms&&this.hasAsyncArcadeExpressions}get invalidFeatures(){return this.sharedForm.invalidFeatures}get hasVisibleInputs(){return this.visibleInputs.length>0}get hasLayersWithContingentValues(){let e=this.contingentValuesManager;for(let t of this.layers)if(e.getFieldsWithContingentValues(t).size>0)return!0;return!1}get formDescription(){return this._computeFormHeaderField(this.activeForm?.description)}get formTitle(){return this._computeFormHeaderField(this.activeForm?.title)}get effectiveTimeZone(){let{activeLayer:e,timeZone:t}=this;if(!e)return t??`system`;let n=D(e);return O(t,n)}get visibleInputs(){return this.activeForm.inputs.filter(e=>e.visible)}get map(){return this.view?.map??null}set map(e){this._override(`map`,e)}get noVisibleElementsReason(){if(this.hasVisibleInputs)return null;if(this.activeForm.inputs.length===0)return`noElements`;let e=new Set;for(let t of this.activeForm.inputs)switch(t.visibilityCode){case`hidden:not-in-all-layers`:case`hidden:no-domain-in-common`:e.add(`noElementsInCommon`);break;case`hidden:field-definition`:case`hidden:group-visibility-expression:all-features`:case`hidden:visibility-expression:all-features`:e.add(`allElementsHidden`);break;case`hidden:group-visibility-expression:some-features`:case`hidden:visibility-expression:some-features`:return`elementsHiddenInSome`}return e.has(`allElementsHidden`)?`allElementsHidden`:`noElementsInCommon`}get page(){return this.showingSelectedAttachmentReplacePage&&this.selectedAttachmentDetails?`replacing-attachment`:this.selectedAttachmentDetails?`viewing-attachment-details`:this.selectedAttachmentAddInput?`adding-attachments`:this.selectedAttachmentListInput?`viewing-attachments`:this.activeAssociationsInput?.associatedLayer?`viewing-associated-features`:this.activeAssociationsInput?`viewing-associated-layers`:this.activeRelationshipInput?.showAllRelatedRecords?`viewing-related-records`:this.activeRelationshipInput?.showAllCategories?`viewing-related-categories`:`default`}get subtypes(){let e=this.activeLayer;return C(e)||w(e)||re(e)?ie(e):[]}get status(){let e=this._prepareTask;return e==null?`not-loaded`:e.finished?e.error==null?`loaded`:`failed`:`loading`}get timeZone(){return this.view?.timeZone??null}set timeZone(e){this._overrideIfSome(`timeZone`,e)}get updating(){return this._updatingHandles.updating||this.calculating}get valid(){return this.sharedForm.valid&&Array.from(this._featureFormMap.values()).every(e=>e.valid)}get layers(){return Array.from(this._layersSet)}get mode(){return this.activeFeatureIndex>-1?`single`:`batch`}submit(){if(this.submitHasBeenAttempted=!0,this.sharedForm.touchAll(),this._featureFormMap.forEach(e=>e.touchAll()),this.validateContingentValues(this._workingFeatures),!this._hasPendingAttachmentHydration)return this._emitSubmit(),Promise.resolve();if(this._submitTask)return this._submitTask.promise;let e=n(async()=>{await Promise.all(this._allAttachmentInputs.map(e=>e.waitForPendingAttachmentUpdateData())),this._emitSubmit()});return this._submitTask=e,e.promise.finally(()=>{this._submitTask===e&&(this._submitTask=null)}),e.promise}get selectedAttachment(){return this._get(`selectedAttachment`)??null}set selectedAttachment(e){this.showingSelectedAttachmentReplacePage=!1,this._set(`selectedAttachment`,e),e!=null&&(this.selectedAttachmentAddElementId=null)}get selectedAttachmentAddElementId(){return this._get(`selectedAttachmentAddElementId`)??null}set selectedAttachmentAddElementId(e){this.showingSelectedAttachmentReplacePage=!1,this._set(`selectedAttachmentAddElementId`,e),e!=null&&(this.selectedAttachment=null,this.selectedAttachmentListElementId=null)}get selectedAttachmentListElementId(){return this._get(`selectedAttachmentListElementId`)??null}set selectedAttachmentListElementId(e){this._set(`selectedAttachmentListElementId`,e),e!=null&&(this.selectedAttachment=null,this.selectedAttachmentAddElementId=null)}get selectedAttachmentListInput(){let e=this.selectedAttachmentListElementId,t=this.activeForm;if(!e||!t)return null;let n=t.allAttachmentElementInputs.find(t=>t.template.elementId===e)||null;return n?.attachments.length?n:null}get showingSelectedAttachmentReplacePage(){return this._get(`showingSelectedAttachmentReplacePage`)??!1}set showingSelectedAttachmentReplacePage(e){this._set(`showingSelectedAttachmentReplacePage`,e&&this.selectedAttachmentDetails!=null)}get selectedAttachmentAddInput(){let e=this.selectedAttachmentAddElementId,t=this.activeForm;return!e||!t?null:t.allAttachmentElementInputs.find(t=>t.template.elementId===e)||null}get selectedAttachmentDetails(){let e=this.selectedAttachment,t=this.activeForm;if(!e||!t)return null;let n=t.allAttachmentElementInputs.find(t=>t.template.elementId===e.elementId);if(!n)return null;let r=n.attachments.findIndex(t=>E(t)===e.attachmentKey);return r===-1?null:{attachment:n.attachments[r],input:n}}get _allAttachmentInputs(){let e=[...this.sharedForm.allAttachmentElementInputs];for(let t of this._featureFormMap.values())e.push(...t.allAttachmentElementInputs);return e}get _hasPendingAttachmentHydration(){return this._allAttachmentInputs.some(e=>e.hasPendingAttachmentUpdateData)}get _layersSet(){let e=new Set;for(let t of this._workingFeatures){let n=S(t.plainGraphic);n&&e.add(n)}return e}applyStashedAttachmentEdits(e){let t=this._allAttachmentInputs;for(let n of e){let e=t.find(e=>e.label===n.label&&e.attachmentKeyword===n.keywords);e&&e.applyStashedEdits(n)}}findFieldInput(e){if(e==null)return;let t=this._activeFormInputsByElementId;if(t.has(e))return t.get(e);let n=this.activeForm.allFieldInputs.find(t=>t.template.elementId===e);if(n!==void 0)return t.set(e,n),n}getFirstVisibleInvalidFieldInput(){if(this.hasVisibleInputs&&!this.activeForm.valid)for(let e of this.visibleInputs){if(H(e)){let t=e.inputs.find(e=>U(e)&&!e.valid);if(t)return{input:t,groupInput:e}}if(U(e)&&!e.valid)return{input:e}}}getFieldInputValue(e){return this.findFieldInput(e)?.value}getValues(e){let t=this._reactiveGraphicLookup.get(e);if(!t)throw new i(`feature-not-found`,`The given feature is not present in the BatchAttributeForm`);return{...t.attributes}}async goBack(){switch(this.page){case`replacing-attachment`:this.setShowingSelectedAttachmentReplacePage(!1);return;case`viewing-attachment-details`:this.setSelectedAttachment(null);return;case`adding-attachments`:this.setSelectedAttachmentAddElementId(null);return;case`viewing-attachments`:this.setSelectedAttachmentListElementId(null);return;case`viewing-associated-features`:this.setActiveAssociationsLayer(null);return;case`viewing-associated-layers`:this.setActiveAssociationsInput(null);return;case`viewing-related-categories`:case`viewing-related-records`:this.clearActiveRelationshipCategoryOrInput();return;default:return}}async goHome(){this.setShowingSelectedAttachmentReplacePage(!1),this.setSelectedAttachment(null),this.setSelectedAttachmentAddElementId(null),this.setSelectedAttachmentListElementId(null),this.setActiveAssociationsLayer(null),this.setActiveAssociationsInput(null),this.clearAllRelationshipSettings()}notifyGeometriesChanged(e){let t=[];for(let n of e){let e=this._reactiveGraphicLookup.get(n);e&&(t.push(e),e.geometry=n.geometry)}this._updatingHandles.consumePromise(this._valueChangeTransaction(async e=>this._expressionsManager.runGeometryDependentExpressions(t,e),`user`))}async overrideOriginalFeature(e,t){await this._prepareTask?.promise;let n=this._reactiveGraphicLookup.get(e);n&&(n.original=t,this._updatingHandles.consumePromise(this._valueChangeTransaction(e=>this._expressionsManager.runOriginalFeatureDependentExpressions(n,e),`expression`)))}async setFieldInputValue(e,t){let{fieldName:n}=e;await this._updatingHandles.addPromise(this._valueChangeTransaction(async r=>{for(let i of e.features)r.setValue(i,n,t)},`user`,e))}async setFieldInputValuePerFeature(e,t){await this._updatingHandles.addPromise(this._valueChangeTransaction(async n=>{for(let[r,i]of t)n.setValue(r,e.fieldName,i);n.hasChanges&&(e.userHasChangedValue=!0)},`user`,e))}async setValueForFieldName(e,t,n){await this._updatingHandles.addPromise(this._valueChangeTransaction(async r=>{for(let i of n){let n=this._reactiveGraphicLookup.get(i);n&&r.setValue(n,e,t)}},`user`,e))}async setValuePerFeatureForFieldName(e,t){await this._updatingHandles.addPromise(this._valueChangeTransaction(async n=>{for(let[r,i]of t){let t=this._reactiveGraphicLookup.get(r);t&&n.setValue(t,e,i)}},`user`,e))}async setFieldValue(e,t){let n=this.activeForm.allFieldInputs.find(t=>t.fieldName===e);if(n==null)throw new i(`no-field-input-found`,`Cannot set the value of FieldInput with field name: ${e} because none was found in the active form`);await this.setFieldInputValue(n,t)}async setValue(e,t){let n=this.findFieldInput(e);if(n==null)throw new i(`no-FieldInput-found`,`Cannot set the value of FieldInput with ID: ${e} because none was found in the active form`);await this.setFieldInputValue(n,t)}async applySubtypeDefaults(e){let{defaultValues:t}=e,{allFieldInputs:n}=this.activeForm;await this._updatingHandles.addPromise(this._valueChangeTransaction(async e=>{for(let r of n){let{fieldName:n}=r,i=t[n];if(i!=null)for(let t of r.features)e.setValue(t,n,i)}},`user`))}async handleSubtypeChanged(e){let t=this._workingFeatures.at(e);if(t)return this._updatingHandles.addPromise(this._handleSubtypeChanged(t))}async stageAddAttachments(e,t){if(t.length===0)return[];let n=this._findAttachmentInput(e);if(!n)return[];let r=await this._updatingHandles.addPromise(n.stageAddAttachments(t,this._expressionsManager.arcadeContext));return r.length===0?r:(this.userHasChangedValues=!0,this._emitAttachmentsChange(n),r)}stageDeleteAttachment(e,t){let n=this._findAttachmentInput(e);if(!n)return;let r=this._findAttachment(n,t);r&&(n.stageDeleteAttachment(r),this.userHasChangedValues=!0,this._emitAttachmentsChange(n))}async stageRenameAttachment(e,t,n){let r=this._findAttachmentInput(e);if(!r)return;let i=this._findAttachment(r,t);i&&(r.stageRenameAttachment(i,n.trim()),this.userHasChangedValues=!0,await r.ensureStagedUpdateData(i),this._emitAttachmentsChange(r))}async stageReplaceAttachment(e,t,n){let r=this._findAttachmentInput(e);if(!r)return!1;let i=this._findAttachment(r,t);return!i||!await this._updatingHandles.addPromise(r.stageReplaceAttachment(i,n,this._expressionsManager.arcadeContext))?!1:(this.userHasChangedValues=!0,this._emitAttachmentsChange(r),!0)}clearAttachmentChanges(e){let t=this._findAttachmentInput(e);t&&(t.clearAttachmentChanges(),this._emitAttachmentsChange(t))}setActiveAssociation(e){this._activeAssociation=e}setActiveAssociationsInput(e){this._activeAssociationsInput=e}setActiveAssociationsLayer(e){this._activeAssociationsInput?.setAssociatedLayer(e)}setActiveAssociationType(e){this._activeAssociationsInput?.setActiveAssociationType(e)}setActiveRelationshipInput(e){e||this._activeRelationshipInput?.setActiveCategory(null),this._activeRelationshipInput=e}setActiveRelationshipCategory(e,t){t.setActiveCategory(e),this.setActiveRelationshipInput(t)}clearAllRelationshipSettings(){let e=this.activeRelationshipInput;e&&(e.setActiveCategory(null),e.setShowAllCategories(!1),e.setShowAllRelatedRecords(!1),this._activeRelationshipInput=null)}clearActiveRelationshipCategoryOrInput(){let e=this.activeRelationshipInput;e&&(e.showAllRelatedRecords?e.showAllCategories?e.setActiveCategory(null):this.setActiveRelationshipInput(null):e.showAllCategories&&(e.setShowAllCategories(!1),this.setActiveRelationshipInput(null)))}resetAttachmentChanges(e,t){let n=this._findAttachmentInput(e);if(!n||!n.editable)return;let r=this._findAttachment(n,t);r&&(n.discardStagedEdits(r),this._emitAttachmentsChange(n))}setSelectedAttachment(e){this.selectedAttachment=e??null}setShowingSelectedAttachmentReplacePage(e){this.showingSelectedAttachmentReplacePage=e}setSelectedAttachmentAddElementId(e){this.selectedAttachmentAddElementId=e??null}setSelectedAttachmentListElementId(e){this.selectedAttachmentListElementId=e??null}userChangesHaveMadeFeatureInvalid(e){return!!this._reactiveGraphicLookup.get(e)?.userChangesHaveMadeInvalid}validate(){return!1}validateContingentValues(e,t=!1){if(t&&!this.submitHasBeenAttempted)for(let t of e)this._reactiveContingentValuesManager.validateContingenciesForNonNullFields(t);else for(let t of e)this._reactiveContingentValuesManager.validateContingencyConstraints(t,{includeIncompleteViolations:!0})}_makeBatchFormInputsForFeature(e){let t=this._layerTemplateMap.get(e.layer);return t?B(t,{allFeatures:new r([e]),expressionsManager:this._expressionsManager,requestDeferredExpressionEvaluation:this._requestDeferredExpressionEvaluation,getExternalErrorForFeature:this._getExternalErrorForFeature,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map}):this._emptyForm}async _ensureLayerTemplate(e,t){let{_layersSet:n,contingentValuesManager:r}=this,i=e.layer,a=!1;for(let e of this._layerTemplateMap.keys())n.has(e)||(this._layerTemplateMap.delete(e),this._expressionsManager.layerExpressionsModelMap.delete(e),r.resetOptionsForLayer(e),Y(e)&&r.resetViolationsForLayer(e),a=!0);this._layerTemplateMap.has(i)||(await this._prepareLayer(i,t),u(t),r.layers.add(i),a=!0),a&&(this._prepareSharedFormTemplate(),V(this.sharedForm,this.sharedFormTemplate,{allFeatures:this._workingFeatures,expressionsManager:this._expressionsManager,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,requestDeferredExpressionEvaluation:this._requestDeferredExpressionEvaluation,map:this.map}),this._recomputeHasAsyncArcadeExpressions(),await v(()=>!r.updating,t))}_recomputeHasAsyncArcadeExpressions(){this._hasAsyncArcadeExpressions=!1;for(let e of this._expressionsManager.layerExpressionsModelMap.values())for(let t of e.arcadeExecutorUses.keys())if(t.isAsync){this._hasAsyncArcadeExpressions=!0;return}}_computeFormHeaderField(e){let{activeFeature:t,activeLayer:n}=this;return!e||!n||!t?null:P({attributes:t?.attributes,label:e,layer:n,timeZone:this.effectiveTimeZone})}_makeSubmitResults(){let e=new Map;for(let[n,r]of this._reactiveGraphicLookup){let i=[],a=[],o=this._featureFormMap.get(r)?.allAttachmentElementInputs??[];for(let e of o)t(i,e.toSubmitEdits()),e.valid||a.push(e.template.elementId);e.set(n,{feature:n,values:{...r.attributes},invalidFields:[],attachmentEdits:i,invalidAttachmentElementIds:a})}for(let t of this.sharedForm.allFieldInputs)for(let n of t.invalidFeatures)e.get(n)?.invalidFields.push(t.fieldName);return Array.from(e.values())}async _handleSubtypeChanged(e){let t=e.layer;if(this.contingentValuesManager.resetOptionsForFeature(t,e.plainGraphic),Y(t)&&this.contingentValuesManager.resetViolationsForFeature(t,e.plainGraphic),!w(t))return;let r=t.parent?.findSublayerForFeature(e.plainGraphic);if(!r)return;this._layerTemplateUpdateTask=l(this._layerTemplateUpdateTask);let i=n(async t=>{u(t),e.source.sourceLayer=r,e.source.origin=r.graphicOrigin,await this._ensureLayerTemplate(e,t),u(t),this._featureFormMap.get(e)?.destroy(),this._featureFormMap.set(e,this._makeBatchFormInputsForFeature(e)),await ee(this._valueChangeTransaction(t=>this._expressionsManager.runAllExpressions([e],t),`user`),t),u(t)});this._layerTemplateUpdateTask=i,await d(this._updatingHandles.addPromise(i.promise))}_emitSubmit(){this.emit(`submit`,{name:`submit`,results:this._makeSubmitResults(),valid:this.valid})}_findAttachmentInput(e){let t=this.activeForm.allAttachmentElementInputs.find(t=>t.template.elementId===e);return t||o.getLogger(this).error(`Attachment input not found for elementId '${e}'`),t}_findAttachment(e,t){let n=e.findAttachment(t);return n||o.getLogger(this).error(`Attachment '${t}' not found for attachment element '${e.template.elementId}'`),n}_makeAttachmentEdits(e){let n=[];for(let r of e.allAttachmentElementInputs)t(n,r.toSubmitEdits());return n}_emitAttachmentsChange(e){let t=e.single.feature;if(!t)return;let n=this._featureFormMap.get(t);this.emit(`attachments-change`,{name:`attachments-change`,feature:t.source,attachmentEdits:this._makeAttachmentEdits(n??this.activeForm),valid:this.valid})}async _valueChangeTransaction(e,t,n){let r=typeof n==`string`?n:n?.fieldName,i=new F(this,t,r);if(await e(i),t===`user`&&await this._expressionsManager.runExpressionsDependentOnChangedFields(i),await i.close(),i.hasChanges&&n){let e=typeof n==`string`?this.activeForm.allFieldInputs.find(e=>e.fieldName===n):n;e&&(e.userHasChangedValue=!0)}}_prepare(){this.pendingSubtypeChoice?.reject(),this._hasAsyncArcadeExpressions=!1,this._prepareTask=l(this._prepareTask),this._layerTemplateUpdateTask=l(this._layerTemplateUpdateTask),this._layerTemplateMap.clear(),this._updateWorkingFeatures(),c(this._expressionsManager),this.userHasChangedValues=!1,this._expressionsManager=new L({arcadeContext:{editType:this.editType,spatialReference:this.spatialReference??x.WebMercator,map:this.map,timeZone:this.timeZone||`system`}});let{layers:e}=this;if(e.length===0)return;let t=n(async t=>{try{u(t),this._updateWorkingFeatures(),this.contingentValuesManager.layers.addMany(e),await Promise.all(e.map(e=>e.load()));for(let n of e)await this._prepareLayer(n,t);if(this.hasTooManyComplexFeatures)throw new i(`too-many-features-with-complex-forms`,`There are too many features to load into the form with the configured complexity`);if(this.hasTooManyFeatures)throw new i(`too-many-features`,`There are too many features to load into the form.`);this._prepareSharedFormTemplate(),this.sharedForm=B(this.sharedFormTemplate,{allFeatures:this._workingFeatures,expressionsManager:this._expressionsManager,getExternalErrorForFeature:this._getExternalErrorForFeature,getFieldValueOptionsForFeature:this._getFieldValueOptionsForFeature,map:this.map,requestDeferredExpressionEvaluation:this._requestDeferredExpressionEvaluation}),await this._valueChangeTransaction(async e=>await this._expressionsManager.runAllExpressions(this._workingFeatures.toArray(),e),`expression`),await v(()=>!this.contingentValuesManager.updating)}catch(e){throw f(e)||o.getLogger(this).error(`Failed preparing form`,e),e}});this._updatingHandles.consumePromise(t.promise),this._prepareTask=t}async _prepareLayer(e,t){let n=ae(this.layerInfos,e),r=await G(e,{arcadeExecutorProvider:this._arcadeExecutorProvider,formTimeZone:this.timeZone,attachmentsEnabled:this.attachmentsEnabled},n?.formTemplate);u(t),this._layerTemplateMap.set(e,r);let i=r.getExpressionExecutorsForLayer(e);if(this._expressionsManager.layerExpressionsModelMap.set(e,new R({preserveFieldValuesWhenHidden:r.preserveFieldValuesWhenHidden,executorMap:i,fieldsIndex:e.fieldsIndex})),!this._hasAsyncArcadeExpressions){for(let e of i.values())if(e&&(this._hasAsyncArcadeExpressions=(e.editableExpression?.isAsync||e.requiredExpression?.isAsync||e.valueExpression?.isAsync||e.visibilityExpression?.isAsync)===!0,this._hasAsyncArcadeExpressions))break}}_prepareSharedFormTemplate(){let e=new Map;for(let t of this._layerTemplateMap.values())for(let n of t.elements){if(K(n))continue;let t=n.clone();q(t)&&(t.elements=t.elements.filter(e=>!K(e)));let{elementId:r}=t;e.has(r)?e.get(r).foldIn(t):e.set(r,t)}this.sharedFormTemplate=new W({elements:Array.from(e.values())})}_updateWorkingFeatures(){this._workingFeatures.destroyAll(),this._reactiveContingentValuesManager.reset();for(let e of this._featureFormMap.values())e.destroy();this._featureFormMap.clear(),this._attachmentCache.clear();let{features:e}=this;if(this._reactiveGraphicLookup=new p,e.length!==0){this._workingFeatures.addMany(e.map(k));for(let e of this._workingFeatures)this._reactiveGraphicLookup.set(e.source,e)}}async _syncAttachments(){let{activeFeature:e,activeLayer:t,activeForm:r}=this;if(!e||!r||!A(t)||!j(t))return;let i=e.getObjectId();if(i==null)return;let a=this._attachmentCache.get(t),o=r.allAttachmentElementInputs;if(!o.length)return;let c=n(async e=>{let n;if(a){let e=a.get(i);e&&(n=e)}n||(n=await M(t,i,o,e),s(this._attachmentCache,t,()=>new p).set(i,n));for(let e of o)e.applyFetchedAttachments(se(e,n))});this._syncAttachmentsTask=c,await d(c.promise)}get test(){return{expressionsManager:this._expressionsManager,reactiveGraphicLookup:this._reactiveGraphicLookup,syncAttachmentsTask:this._syncAttachmentsTask,arcadeExecutorProvider:this._arcadeExecutorProvider,requestDeferredExpressionEvaluation:this._requestDeferredExpressionEvaluation}}};e([y()],Z.prototype,`_attachmentCache`,void 0),e([y({readOnly:!0})],Z.prototype,`activeFeature`,null),e([y()],Z.prototype,`activeFeatureIndex`,void 0),e([y({readOnly:!0})],Z.prototype,`activeForm`,null),e([y({readOnly:!0})],Z.prototype,`activeLayer`,null),e([y()],Z.prototype,`activeAssociation`,null),e([y()],Z.prototype,`activeAssociationsInput`,null),e([y()],Z.prototype,`activeAssociationType`,null),e([y()],Z.prototype,`activeRelationshipInput`,null),e([y()],Z.prototype,`attachmentsEnabled`,void 0),e([y()],Z.prototype,`callbacks`,void 0),e([y()],Z.prototype,`disabled`,void 0),e([y()],Z.prototype,`calculating`,null),e([y()],Z.prototype,`canGoBack`,null),e([y()],Z.prototype,`contingentValuesManager`,void 0),e([y()],Z.prototype,`editType`,void 0),e([y()],Z.prototype,`features`,void 0),e([y()],Z.prototype,`expressionEvaluationFailed`,null),e([y()],Z.prototype,`hasNonActiveInvalidFeatures`,null),e([y()],Z.prototype,`hasAsyncArcadeExpressions`,null),e([y()],Z.prototype,`_hasAsyncArcadeExpressions`,void 0),e([y()],Z.prototype,`invalidFeatures`,null),e([y()],Z.prototype,`hasVisibleInputs`,null),e([y()],Z.prototype,`hasLayersWithContingentValues`,null),e([y()],Z.prototype,`formDescription`,null),e([y()],Z.prototype,`formTitle`,null),e([y()],Z.prototype,`effectiveTimeZone`,null),e([y()],Z.prototype,`highlightHelper`,void 0),e([y()],Z.prototype,`maximumFeatureCount`,void 0),e([y()],Z.prototype,`maximumFeatureCountWithComplexForms`,void 0),e([y()],Z.prototype,`visibleInputs`,null),e([y()],Z.prototype,`map`,null),e([y()],Z.prototype,`noVisibleElementsReason`,null),e([y()],Z.prototype,`page`,null),e([y()],Z.prototype,`pageStack`,void 0),e([y()],Z.prototype,`readOnly`,void 0),e([y()],Z.prototype,`pendingSubtypeChoice`,void 0),e([y()],Z.prototype,`subtypes`,null),e([y()],Z.prototype,`spatialReference`,void 0),e([y()],Z.prototype,`submitHasBeenAttempted`,void 0),e([y()],Z.prototype,`timeZone`,null),e([y()],Z.prototype,`view`,void 0),e([y()],Z.prototype,`updating`,null),e([y()],Z.prototype,`valid`,null),e([y()],Z.prototype,`layers`,null),e([y()],Z.prototype,`mode`,null),e([y()],Z.prototype,`sharedForm`,void 0),e([y()],Z.prototype,`sharedFormTemplate`,void 0),e([y()],Z.prototype,`selectedAttachment`,null),e([y()],Z.prototype,`selectedAttachmentAddElementId`,null),e([y()],Z.prototype,`selectedAttachmentListElementId`,null),e([y()],Z.prototype,`selectedAttachmentListInput`,null),e([y()],Z.prototype,`showingSelectedAttachmentReplacePage`,null),e([y()],Z.prototype,`selectedAttachmentAddInput`,null),e([y()],Z.prototype,`selectedAttachmentDetails`,null),e([y()],Z.prototype,`userHasChangedValues`,void 0),e([y()],Z.prototype,`layerInfos`,void 0),e([y()],Z.prototype,`_arcadeExecutorProvider`,void 0),e([y()],Z.prototype,`_activeAssociation`,void 0),e([y()],Z.prototype,`_activeAssociationsInput`,void 0),e([y()],Z.prototype,`_activeRelationshipInput`,void 0),e([y()],Z.prototype,`_prepareTask`,void 0),e([y()],Z.prototype,`_reactiveGraphicLookup`,void 0),e([y()],Z.prototype,`_allAttachmentInputs`,null),e([y()],Z.prototype,`_hasPendingAttachmentHydration`,null),e([y()],Z.prototype,`_layerTemplateMap`,void 0),e([y()],Z.prototype,`_layersSet`,null),e([y()],Z.prototype,`_workingFeatures`,void 0),e([y()],Z.prototype,`_expressionsManager`,void 0),Z=e([b(`esri.widgets.BatchAttributeForm.BatchAttributeFormViewModel`)],Z);const oe=Z;function Q(e){return e!=null&&e.trim().length>0}function $(e,t){let n=e.keywords;return Q(n)&&n.toLowerCase()===t}function se(e,t){let n=e.input?.type===`attachment`?e.input.attachmentAssociationType:`exact`,r=e.attachmentKeyword;if(n===`any`)return t;if(n===`exactOrNone`){if(X(r))return t.filter(e=>!Q(e.keywords));let e=r.toLowerCase();return t.filter(t=>!Q(t.keywords)||$(t,e))}if(X(r))return t;let i=r.toLowerCase();return t.filter(e=>$(e,i))}export{oe as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import n from"../../../core/Error.js";import r from"../../../core/Logger.js";import{getOrCreateMapValue as i}from"../../../core/MapUtils.js";import{whenOrAbort as a,settleWithPromise as o}from"../../../core/promiseUtils.js";import s from"../../../core/ReactiveMap.js";import{addMany as c,first as l}from"../../../core/SetUtils.js";import{property as u,subclass as d}from"../../../core/accessorSupport/decorators.js";import{makeArcadeContext as f,castArcadeValue as p}from"./expressionUtils.js";import{makeUseId as m}from"../inputs/support/inputUtils.js";import{isFieldElementTemplate as h,isGroupElementTemplate as g}from"../templates/support/templateUtils.js";let _=null;const v=()=>r.getLogger(`esri.widgets.BatchAttributeForm.expressions.ExpressionsManager`);let y=class extends t{constructor(e){super(e),this.calculating=!1,this.arcadeContext=null,this._abortController=new AbortController,this.layerExpressionsModelMap=new Map,this.outcomes=new s,this.expressionEvaluationFailed=!1}destroy(){this.abort()}abort(){this._abortController.abort()}async runAllExpressions(e,t){return this._evaluateSpecifiedExecutorsForEachFeature(e,x,t)}async runGeometryDependentExpressions(e,t){return this._evaluateSpecifiedExecutorsForEachFeature(e,S,t)}async runOriginalFeatureDependentExpressions(e,t){return this._evaluateSpecifiedExecutorsForEachFeature([e],C,t)}async runExpressionsDependentOnChangedFields(e){try{this.calculating=!0;let t=Array.from(e.changes).map(([t,n])=>this.runExpressionsDependentOnChangedFieldsForFeature([...n.keys()],t,e));D(await Promise.allSettled(t))}catch(e){v().error(e),this.expressionEvaluationFailed=!0}finally{this.calculating=!1}}async runExpressionsDependentOnChangedFieldsForFeature(e,t,n){if(this._abortController.signal.aborted)return;let r=this.layerExpressionsModelMap.get(t.layer);if(!r||r.components.length===0)return;let i=T(r,e);i.length!==0&&await this.evaluateAffectedExecutors([...i],t,r,n)}async evaluateAffectedExecutors(e,t,n,r){let o=new Map,c=i(this.outcomes,t,()=>new s);for(let r of e){let e=N(r,c,n);e&&(e.invalidated||=!0);let a=n.dependencyGraphComponents.get(r);a&&i(o,a,()=>this.createSccEvaluator({scc:a,feature:t,evaluatorMap:o,expressionModel:n}))}let l=[...o.values()],u={transaction:r,previousOutcomes:new s},d=l.map(e=>e.evaluate(u));D(await a(Promise.allSettled(d),this._abortController))}createSccEvaluator({scc:e,feature:t,evaluatorMap:n,expressionModel:r}){let a=i(this.outcomes,t,()=>new s),o=new b(e,t,this.arcadeContext,r,a,this._abortController);for(let a of e.adjacencyList)i(n,a,()=>this.createSccEvaluator({scc:a,feature:t,evaluatorMap:n,expressionModel:r})).dependencies.push(o);return o}async _evaluateSpecifiedExecutorsForEachFeature(e,t,n){this.calculating=!0;try{let r=[];for(let i of e){let{layer:e}=i,a=this.layerExpressionsModelMap.get(e);a&&a.components.length!==0&&r.push(this.evaluateAffectedExecutors(t(a,e),i,a,n))}D(await a(Promise.allSettled(r),this._abortController))}catch(e){v().error(e),this.expressionEvaluationFailed=!0}finally{this.calculating=!1}}};e([u()],y.prototype,`calculating`,void 0),e([u({constructOnly:!0})],y.prototype,`arcadeContext`,void 0),e([u()],y.prototype,`_abortController`,void 0),e([u()],y.prototype,`layerExpressionsModelMap`,void 0),e([u()],y.prototype,`outcomes`,void 0),e([u()],y.prototype,`expressionEvaluationFailed`,void 0),y=e([d(`esri.widgets.BatchAttributeForm.expressions.ExpressionsManager`)],y);class b{constructor(e,t,n,r,i,a){this.scc=e,this.feature=t,this.arcadeContextInfo=n,this.expressionsModel=r,this.outcomes=i,this._abortController=a,this._resolver=null,this.dependencies=[]}get baseContext(){return f(this.arcadeContextInfo,this.feature,this._abortController.signal)}evaluate(e){return this._resolver||(this._resolver=Promise.withResolvers(),o(this._resolver,this._evaluate(e))),this._resolver.promise}async _evaluate(e){_===null&&(_=await import(`../../../arcade/languageUtils.js`));let t=[],n=this.dependencies.map(t=>t.evaluate(e));D(await a(Promise.allSettled(n),this._abortController));let{executors:r}=this.scc;if(r.size===1?await this._evaluateSingleExecutorComponent({context:e,executor:l(r),errorsToReport:t}):await this._evaluateMultiExecutorComponent({context:e,errorsToReport:t}),t.length>0)throw E(t)}async _evaluateMultiExecutorComponent({context:e,errorsToReport:t}){let{transaction:n}=e,r=new Map,i=!0,a=0;for(;i&&a<3;){i=!1,a++;for(let a of this.scc.executors){let o=this._findOutcome(a)??{status:`not-run`,invalidated:!0};o.invalidated||=this._invalidatedSinceCheckpoint(a,n,r.get(a)),this._shouldEvaluate(o)&&(i=!0,r.set(a,n.currentCheckpoint),await this._performEvaluation({context:e,executor:a,errorsToReport:t}))}}}async _evaluateSingleExecutorComponent({context:e,executor:t,errorsToReport:n}){let r=this._findOutcome(t)??{status:`not-run`,invalidated:!0};r.invalidated||=this._invalidatedSinceCheckpoint(t,e.transaction),this._shouldEvaluate(r)&&await this._performEvaluation({context:e,executor:t,errorsToReport:n})}async _performEvaluation({context:e,executor:t,errorsToReport:r}){let{variables:i,executeContext:a}=this.baseContext,o=null,s=null;try{o=t.isAsync?await t.executeAsync(i,a):t.execute(i,a),s={result:o,status:`success`}}catch(e){s={error:e,status:`error`}}let{transaction:c,previousOutcomes:l}=e,{outcomes:u}=this,d=this.expressionsModel.arcadeExecutorUses.get(t)??[];for(let e of d){let t=m(e),n=u.get(t);n&&l.set(t,n),u.set(m(e),s);let r=this.expressionsModel.elementTemplateMap.get(e.elementId);switch(e.executorPurpose){case`editableExpression`:if(s.result===!1&&n?.result!==!1){let e=u.get(m({elementId:r.elementId,executorPurpose:`valueExpression`}));if(e){let{fieldName:t}=r,n=w(this.feature,t),i=p(e.result,n,this.arcadeContextInfo.timeZone,_);c.setValue(this.feature,t,i)}}break;case`valueExpression`:{if(s?.status===`error`)continue;let e=r.getExpressionExecutorsForLayer(this.feature.layer),t=!0;if(e?.editableExpression&&(t=u.get(m({elementId:r.elementId,executorPurpose:`editableExpression`}))?.result===!1),t){let e=r.fieldName,t=this.feature.getAttribute(e)??null;try{let n=w(this.feature,e),r=p(s.result,n,this.arcadeContextInfo.timeZone,_);r!==t&&c.setValue(this.feature,e,r)}catch(t){v().error(`Failed to set calculated value for field '${e}'`,t)}}}break;case`visibilityExpression`:!this.expressionsModel.preserveFieldValuesWhenHidden&&n?.result===!0&&s.result===!1&&c.originActor===`user`&&O(r,this.feature,u,{transaction:c,previousOutcomes:l})}}if(s?.status===`error`){let e=new Set;for(let t of d){let n=this.expressionsModel.elementTemplateMap.get(t.elementId);if(n)switch(t.executorPurpose){case`editableExpression`:e.add(n.label+` - Editable expression`);break;case`requiredExpression`:e.add(n.label+` - Required expression`);break;case`valueExpression`:e.add(n.label+` - Value expression`);break;case`visibilityExpression`:e.add(n.label+` - Visibility expression`)}}r.push(e.size>0?new n(`expression-evaluation-failed`,`Arcade evaluation failed (`+[...e].join(`,`)+`)`):new n(`expression-evaluation-failed`,`Arcade evaluation failed `))}}_invalidatedSinceCheckpoint(e,t,n=-1){let r=t.changesForFeature(this.feature);return!r||r.size===0?!1:this.scc.getFieldsReferenced(e).values().some(e=>r.has(e)&&r.get(e)>n)}_shouldEvaluate(e){return!this._abortController.signal.aborted&&!!e.invalidated}_findOutcome(e){return N(e,this.outcomes,this.expressionsModel)}}function x(e){return Array.from(e.dependencyGraphComponents.keys())}function S(e){return Array.from(e.geometryReferences)}function C(e){return Array.from(e.originalFeatureReferences)}function w(e,t){let r=e.layer.fieldsIndex.get(t);if(!r)throw new n(`field-not-found`,`Field '${t}' not found on layer.`);return r}function T(e,t){let n=new Set;for(let r of t)c(n,e.fieldReferencesMap.get(r));return Array.from(n)}function E(e){return AggregateError(e,`One or more expression executions failed. First error message: ${e[0].message}`)}function D(e){let t=[],n=new Set;for(let r of e){if(r.status===`fulfilled`)continue;let e=r.reason instanceof AggregateError?r.reason.errors:[r.reason];for(let r of e)n.has(r)||(n.add(r),t.push(r))}if(t.length>0)throw E(t)}function O(e,t,n,r){h(e)?k(e,t,n,r):g(e)&&A(e,t,n,r)}function k(e,t,n,r){let{group:i}=e;(!i||M(i,n,r.previousOutcomes))&&j(t,e,r)}function A(e,t,n,r){for(let i of e.elements)h(i)&&M(i,n,r.previousOutcomes)&&j(t,i,r)}function j(e,{fieldName:t},n){n.transaction.setValue(e,t,null)}function M(e,t,n){let r=m({elementId:e.elementId,executorPurpose:`visibilityExpression`}),i=n.get(r)??t.get(r);return!i||!!i.result}function N(e,t,n){let r=n.arcadeExecutorUses.get(e);if(r)for(let e of r){let n=t.get(m(e));if(n)return n}}export{y as ExpressionsManager};
2
+ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import n from"../../../core/Error.js";import r from"../../../core/Logger.js";import{getOrCreateMapValue as i}from"../../../core/MapUtils.js";import{whenOrAbort as a,settleWithPromise as o}from"../../../core/promiseUtils.js";import s from"../../../core/ReactiveMap.js";import{addMany as c,first as l}from"../../../core/SetUtils.js";import{property as u,subclass as d}from"../../../core/accessorSupport/decorators.js";import{makeArcadeContext as f,castArcadeValue as p,isDeferredExpressionType as m}from"./expressionUtils.js";import{makeUseId as h}from"../inputs/support/inputUtils.js";import{isFieldElementTemplate as g,isGroupElementTemplate as _}from"../templates/support/templateUtils.js";let v=null;const y=()=>r.getLogger(`esri.widgets.BatchAttributeForm.expressions.ExpressionsManager`);let b=class extends t{constructor(e){super(e),this.calculating=!1,this.arcadeContext=null,this._abortController=new AbortController,this.layerExpressionsModelMap=new Map,this.outcomes=new s,this.expressionEvaluationFailed=!1}destroy(){this.abort()}abort(){this._abortController.abort()}async runAllExpressions(e,t){return this._evaluateSpecifiedExecutorsForEachFeature(e,S,t)}async requestDeferredExecution(e,t,n){return this._evaluateSpecifiedExecutorsForEachFeature(e,(e,n)=>{let r=t(n);return r?[r]:[]},n,!0)}async runGeometryDependentExpressions(e,t){return this._evaluateSpecifiedExecutorsForEachFeature(e,C,t)}async runOriginalFeatureDependentExpressions(e,t){return this._evaluateSpecifiedExecutorsForEachFeature([e],w,t)}async runExpressionsDependentOnChangedFields(e){try{this.calculating=!0;let t=Array.from(e.changes).map(([t,n])=>this.runExpressionsDependentOnChangedFieldsForFeature([...n.keys()],t,e));O(await Promise.allSettled(t))}catch(e){y().error(e),this.expressionEvaluationFailed=!0}finally{this.calculating=!1}}async runExpressionsDependentOnChangedFieldsForFeature(e,t,n){if(this._abortController.signal.aborted)return;let r=this.layerExpressionsModelMap.get(t.layer);if(!r||r.components.length===0)return;let i=E(r,e);i.length!==0&&await this.evaluateAffectedExecutors([...i],t,r,n)}async evaluateAffectedExecutors(e,t,n,r,o=!1){let c=new Map,l=i(this.outcomes,t,()=>new s);for(let r of e){if(!o){let e=P(r,l,n);e&&(e.invalidated=!0)}let e=n.dependencyGraphComponents.get(r);e&&i(c,e,()=>this.createSccEvaluator({scc:e,feature:t,evaluatorMap:c,expressionModel:n}))}let u=[...c.values()],d={transaction:r,previousOutcomes:new s,isDeferred:o},f=u.map(e=>e.evaluate(d));O(await a(Promise.allSettled(f),this._abortController))}createSccEvaluator({scc:e,feature:t,evaluatorMap:n,expressionModel:r}){let a=i(this.outcomes,t,()=>new s),o=new x(e,t,this.arcadeContext,r,a,this._abortController);for(let a of e.adjacencyList)i(n,a,()=>this.createSccEvaluator({scc:a,feature:t,evaluatorMap:n,expressionModel:r})).dependencies.push(o);return o}async _evaluateSpecifiedExecutorsForEachFeature(e,t,n,r=!1){r||(this.calculating=!0);try{let i=[];for(let a of e){let{layer:e}=a,o=this.layerExpressionsModelMap.get(e);o&&o.components.length!==0&&i.push(this.evaluateAffectedExecutors(t(o,e),a,o,n,r))}O(await a(Promise.allSettled(i),this._abortController))}catch(e){y().error(e),this.expressionEvaluationFailed=!0}finally{this.calculating=!1}}};e([u()],b.prototype,`calculating`,void 0),e([u({constructOnly:!0})],b.prototype,`arcadeContext`,void 0),e([u()],b.prototype,`_abortController`,void 0),e([u()],b.prototype,`layerExpressionsModelMap`,void 0),e([u()],b.prototype,`outcomes`,void 0),e([u()],b.prototype,`expressionEvaluationFailed`,void 0),b=e([d(`esri.widgets.BatchAttributeForm.expressions.ExpressionsManager`)],b);class x{constructor(e,t,n,r,i,a){this.scc=e,this.feature=t,this.arcadeContextInfo=n,this.expressionsModel=r,this.outcomes=i,this._abortController=a,this._resolver=null,this.dependencies=[]}get baseContext(){return f(this.arcadeContextInfo,this.feature,this._abortController.signal)}evaluate(e){return this._resolver||(this._resolver=Promise.withResolvers(),o(this._resolver,this._evaluate(e))),this._resolver.promise}async _evaluate(e){v===null&&(v=await import(`../../../arcade/languageUtils.js`));let t=[],n=this.dependencies.map(t=>t.evaluate(e));O(await a(Promise.allSettled(n),this._abortController));let{executors:r}=this.scc;if(r.size===1?await this._evaluateSingleExecutorComponent({context:e,executor:l(r),errorsToReport:t}):await this._evaluateMultiExecutorComponent({context:e,errorsToReport:t}),t.length>0)throw D(t)}async _evaluateMultiExecutorComponent({context:e,errorsToReport:t}){let{transaction:n}=e,r=new Map,i=!0,a=0;for(;i&&a<3;){i=!1,a++;for(let a of this.scc.executors){let o=this._findOutcome(a)??{status:`not-run`,invalidated:!0};o.invalidated||=this._invalidatedSinceCheckpoint(a,n,r.get(a)),this._shouldEvaluate(a,o,e)&&(i=!0,r.set(a,n.currentCheckpoint),await this._performEvaluation({context:e,executor:a,errorsToReport:t}))}}}async _evaluateSingleExecutorComponent({context:e,executor:t,errorsToReport:n}){let r=this._findOutcome(t)??{status:`not-run`,invalidated:!0};r.invalidated||=this._invalidatedSinceCheckpoint(t,e.transaction),this._shouldEvaluate(t,r,e)&&await this._performEvaluation({context:e,executor:t,errorsToReport:n})}async _performEvaluation({context:e,executor:t,errorsToReport:r}){let{variables:i,executeContext:a}=this.baseContext,o=null,s=null;try{o=t.isAsync?await t.executeAsync(i,a):t.execute(i,a),s={result:o,status:`success`}}catch(e){s={error:e,status:`error`}}let{transaction:c,previousOutcomes:l}=e,{outcomes:u}=this,d=this.expressionsModel.arcadeExecutorUses.get(t)??[];for(let t of d){let n=h(t),r=u.get(n);r&&l.set(n,r),u.set(h(t),s);let i=this.expressionsModel.elementTemplateMap.get(t.elementId);switch(t.executorPurpose){case`editableExpression`:if(s.result===!1&&r?.result!==!1){let e=u.get(h({elementId:i.elementId,executorPurpose:`valueExpression`}));if(e){let{fieldName:t}=i,n=T(this.feature,t),r=p(e.result,n,this.arcadeContextInfo.timeZone,v);c.setValue(this.feature,t,r)}}break;case`valueExpression`:{if(s?.status===`error`)continue;let e=i.getExpressionExecutorsForLayer(this.feature.layer),t=!0;if(e?.editableExpression&&(t=u.get(h({elementId:i.elementId,executorPurpose:`editableExpression`}))?.result===!1),t){let e=i.fieldName,t=this.feature.getAttribute(e)??null;try{let n=T(this.feature,e),r=p(s.result,n,this.arcadeContextInfo.timeZone,v);r!==t&&c.setValue(this.feature,e,r)}catch(t){y().error(`Failed to set calculated value for field '${e}'`,t)}}}break;case`visibilityExpression`:!this.expressionsModel.preserveFieldValuesWhenHidden&&r?.result===!0&&s.result===!1&&c.originActor===`user`&&k(i,this.feature,u,e)}}if(s?.status===`error`){let e=new Set;for(let t of d){let n=this.expressionsModel.elementTemplateMap.get(t.elementId);if(n)switch(t.executorPurpose){case`editableExpression`:e.add(n.label+` - Editable expression`);break;case`requiredExpression`:e.add(n.label+` - Required expression`);break;case`valueExpression`:e.add(n.label+` - Value expression`);break;case`visibilityExpression`:e.add(n.label+` - Visibility expression`)}}r.push(e.size>0?new n(`expression-evaluation-failed`,`Arcade evaluation failed (`+[...e].join(`,`)+`)`):new n(`expression-evaluation-failed`,`Arcade evaluation failed `))}}_invalidatedSinceCheckpoint(e,t,n=-1){let r=t.changesForFeature(this.feature);return!r||r.size===0?!1:this.scc.getFieldsReferenced(e).values().some(e=>r.has(e)&&r.get(e)>n)}_shouldEvaluate(e,t,{isDeferred:n}){return this._abortController.signal.aborted||F(this.expressionsModel.arcadeExecutorUses.get(e))&&!n?!1:!!t.invalidated}_findOutcome(e){return P(e,this.outcomes,this.expressionsModel)}}function S(e){return Array.from(e.dependencyGraphComponents.keys())}function C(e){return Array.from(e.geometryReferences)}function w(e){return Array.from(e.originalFeatureReferences)}function T(e,t){let r=e.layer.fieldsIndex.get(t);if(!r)throw new n(`field-not-found`,`Field '${t}' not found on layer.`);return r}function E(e,t){let n=new Set;for(let r of t)c(n,e.fieldReferencesMap.get(r));return Array.from(n)}function D(e){return AggregateError(e,`One or more expression executions failed. First error message: ${e[0].message}`)}function O(e){let t=[],n=new Set;for(let r of e){if(r.status===`fulfilled`)continue;let e=r.reason instanceof AggregateError?r.reason.errors:[r.reason];for(let r of e)n.has(r)||(n.add(r),t.push(r))}if(t.length>0)throw D(t)}function k(e,t,n,r){g(e)?A(e,t,n,r):_(e)&&j(e,t,n,r)}function A(e,t,n,r){let{group:i}=e;(!i||N(i,n,r.previousOutcomes))&&M(t,e,r)}function j(e,t,n,r){for(let i of e.elements)g(i)&&N(i,n,r.previousOutcomes)&&M(t,i,r)}function M(e,{fieldName:t},n){n.transaction.setValue(e,t,null)}function N(e,t,n){let r=h({elementId:e.elementId,executorPurpose:`visibilityExpression`}),i=n.get(r)??t.get(r);return!i||!!i.result}function P(e,t,n){let r=n.arcadeExecutorUses.get(e);if(r)for(let e of r){let n=t.get(h(e));if(n)return n}}function F(e){return e?.every(e=>m(e.executorPurpose))??!1}export{b as ExpressionsManager};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../../../core/Error.js";import{DateOnly as t}from"../../../core/sql/DateOnly.js";import{TimeOnly as n}from"../../../core/sql/TimeOnly.js";import{isDynamicChoiceInput as r}from"../../../form/elements/inputs/inputUtils.js";import{isFieldElement as i}from"../../../form/support/formUtils.js";async function a({element:e,expressionInfos:t,provider:n}){let a={};if(e.visibilityExpression){let r=t.get(e.visibilityExpression);a.visibilityExpression=r?await n.getArcadeExecutor(r.expression):void 0}if(`editableExpression`in e&&e.editableExpression){let r=t.get(e.editableExpression);a.editableExpression=r?await n.getArcadeExecutor(r.expression):void 0}if(`requiredExpression`in e&&e.requiredExpression){let r=t.get(e.requiredExpression);a.requiredExpression=r?await n.getArcadeExecutor(r.expression):void 0}if(`valueExpression`in e&&e.valueExpression){let r=t.get(e.valueExpression);a.valueExpression=r?await n.getArcadeExecutor(r.expression):void 0}let o=i(e)?e.input:void 0;if(o&&r(o)&&o.choiceExpression){let e=t.get(o.choiceExpression);a.choiceExpression=e?await n.getArcadeExecutor(e.expression):void 0}return a}function o(e){return new Map(e?.map(e=>[e.name,e]))}function s(r,i,a,o){if(r===null)return null;switch(i.type){case`big-integer`:case`integer`:case`long`:case`oid`:case`small-integer`:{let e=c(r,o);return e==null?null:Math.floor(e)}case`single`:case`double`:return c(r,o);case`global-id`:case`guid`:case`string`:return o.toString(r);case`date`:{let t=l(r,a,o);if(t)return t.getTime();let n=c(r,o);if(n!==null&&!Number.isNaN(n)&&Number.isInteger(n))return n;throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a date`)}case`date-only`:{if(o.isDateOnly(r))return r.toStorageFormat();let n=l(r,a,o);if(!n)throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a date-only string`);return t.fromDateTime(n.toDateTime()).toStorageFormat()}case`time-only`:{if(o.isTime(r))return r.toStorageString();if(o.isDate(r))return n.fromDateTime(r.toDateTime()).toStorageString();let t=n.fromString(o.toString(r));if(!t)throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a time-only string`);return t.toStorageString()}case`timestamp-offset`:{let t=l(r,a,o);if(!t)throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a timestamp-offset string`);return t.toISOString(!1)}}throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a value matching field type`)}function c(e,t){if(e===``)return null;let n=t.toNumber(e);return Number.isNaN(n)?null:n}function l(e,t,n){if(n.isDate(e))return e;if(n.isDateOnly(e))return e.toArcadeDate();let r=n.toString(e),i=n.toDate(r,t);return!i||!/\d{4}-\d{2}-\d{2}/.test(r)?null:i}function u(e,t,n){let{editType:r,map:i,spatialReference:a,timeZone:o}=e,s=t.layer,c=s?.type===`scene`&&s.associatedLayer!=null?s.associatedLayer:s;return{variables:{$originalfeature:t.original,$editcontext:{editType:r},$layer:c,$featureset:c,$datastore:c?.url,$feature:t.plainGraphic,$map:i},executeContext:{rawOutput:!0,spatialReference:a??void 0,timeZone:o,abortSignal:n}}}export{s as castArcadeValue,u as makeArcadeContext,a as makeExecutorSetForFormElement,o as makeExpressionInfosMap};
2
+ import e from"../../../core/Error.js";import{DateOnly as t}from"../../../core/sql/DateOnly.js";import{TimeOnly as n}from"../../../core/sql/TimeOnly.js";import{isDynamicChoiceInput as r}from"../../../form/elements/inputs/inputUtils.js";import{isFieldElement as i}from"../../../form/support/formUtils.js";async function a({element:e,expressionInfos:t,provider:n}){let a={};if(e.visibilityExpression){let r=t.get(e.visibilityExpression);a.visibilityExpression=r?await n.getArcadeExecutor(r.expression):void 0}if(`editableExpression`in e&&e.editableExpression){let r=t.get(e.editableExpression);a.editableExpression=r?await n.getArcadeExecutor(r.expression):void 0}if(`requiredExpression`in e&&e.requiredExpression){let r=t.get(e.requiredExpression);a.requiredExpression=r?await n.getArcadeExecutor(r.expression):void 0}if(`valueExpression`in e&&e.valueExpression){let r=t.get(e.valueExpression);a.valueExpression=r?await n.getArcadeExecutor(r.expression):void 0}let o=i(e)?e.input:void 0;if(o&&r(o)&&o.choiceExpression){let e=t.get(o.choiceExpression);a.choiceExpression=e?await n.getArcadeExecutor(e.expression):void 0}return a}function o(e){return new Map(e?.map(e=>[e.name,e]))}function s(r,i,a,o){if(r===null)return null;switch(i.type){case`big-integer`:case`integer`:case`long`:case`oid`:case`small-integer`:{let e=c(r,o);return e==null?null:Math.floor(e)}case`single`:case`double`:return c(r,o);case`global-id`:case`guid`:case`string`:return o.toString(r);case`date`:{let t=l(r,a,o);if(t)return t.getTime();let n=c(r,o);if(n!==null&&!Number.isNaN(n)&&Number.isInteger(n))return n;throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a date`)}case`date-only`:{if(o.isDateOnly(r))return r.toStorageFormat();let n=l(r,a,o);if(!n)throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a date-only string`);return t.fromDateTime(n.toDateTime()).toStorageFormat()}case`time-only`:{if(o.isTime(r))return r.toStorageString();if(o.isDate(r))return n.fromDateTime(r.toDateTime()).toStorageString();let t=n.fromString(o.toString(r));if(!t)throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a time-only string`);return t.toStorageString()}case`timestamp-offset`:{let t=l(r,a,o);if(!t)throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a timestamp-offset string`);return t.toISOString(!1)}}throw new e(`unsupported-value-type`,`Unable to convert value ${r} to a value matching field type`)}function c(e,t){if(e===``)return null;let n=t.toNumber(e);return Number.isNaN(n)?null:n}function l(e,t,n){if(n.isDate(e))return e;if(n.isDateOnly(e))return e.toArcadeDate();let r=n.toString(e),i=n.toDate(r,t);return!i||!/\d{4}-\d{2}-\d{2}/.test(r)?null:i}function u(e,t,n){let{editType:r,map:i,spatialReference:a,timeZone:o}=e,s=t.layer,c=s?.type===`scene`&&s.associatedLayer!=null?s.associatedLayer:s;return{variables:{$originalfeature:t.original,$editcontext:{editType:r},$layer:c,$featureset:c,$datastore:c?.url,$feature:t.plainGraphic,$map:i},executeContext:{rawOutput:!0,spatialReference:a??void 0,timeZone:o,abortSignal:n}}}function d(e){return e===`choiceExpression`}export{s as castArcadeValue,d as isDeferredExpressionType,u as makeArcadeContext,a as makeExecutorSetForFormElement,o as makeExpressionInfosMap};
@@ -23,6 +23,12 @@ export interface FieldInputProperties extends EditableInputProperties, Partial<P
23
23
  * @see [BatchFormInputs](https://developers.arcgis.com/javascript/latest/references/core/widgets/BatchAttributeForm/inputs/BatchFormInputs/)
24
24
  */
25
25
  export default class FieldInput extends EditableInput<any> {
26
+ /**
27
+ * @deprecated
28
+ * since 5.2. This is a read-only class. Instances should be
29
+ * created and accessed via
30
+ * [BatchAttributeFormViewModel](https://developers.arcgis.com/javascript/latest/references/core/widgets/BatchAttributeForm/BatchAttributeFormViewModel/)
31
+ */
26
32
  constructor(properties: FieldInputProperties);
27
33
  /**
28
34
  * The type of data displayed by the field input. Possible values are listed below.
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{isSome as t}from"../../../core/arrayUtils.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{property as r,subclass as i}from"../../../core/accessorSupport/decorators.js";import{isDynamicChoiceInput as a,isMultipleChoiceInput as o}from"../../../form/elements/inputs/inputUtils.js";import s from"../../../layers/support/CodedValue.js";import c from"../../../layers/support/CodedValueDomain.js";import{getDomainRange as l,validateDomainValue as u,dateTimeFieldValuesToNumericRange as d,isDomainValidForField as f}from"../../../layers/support/domainUtils.js";import{getFieldRange as p,isDateOnlyField as m,isTimeOnlyField as h,isTimestampOffsetField as g}from"../../../layers/support/fieldUtils.js";import{supportsFieldConfiguration as _}from"../../../layers/support/layerUtils.js";import v from"../../../layers/support/RangeDomain.js";import{isNumber as y}from"../../../support/guards.js";import b from"./EditableInput.js";import{isMultipleChoiceController as x}from"./support/controllerUtils.js";import S from"./support/DynamicChoiceController.js";import{MultiFeatureError as C,getFieldInputDataType as w,visibilityCodeToBoolean as T,isFieldInputWithShowNoValueOptionInput as E,isWarning as D,isContingentValuesError as O,FormValidationWarning as k,differentValuesString as A}from"./support/inputUtils.js";import j from"./support/MultipleChoiceController.js";import{otherChoiceCheckedPlaceholderValue as M}from"./support/multipleChoiceInputUtils.js";import{timeResolutionToStepMap as N}from"../../support/dateUtils.js";import{valuesAreEquivalent as P,getMaxLength as F,getMinLength as I,dateIsValid as L,validateFormValue as R}from"../../support/forms/formUtils.js";let z=class extends b{constructor(e){super(e),this.getExternalErrorForFeature=null,this.getFieldValueOptionsForFeature=null,this.group=null,this.inputController=null,this.touched=!1,this.type=`field`,this.userHasChangedValue=!1,this._hasIntersectionWithElementFieldDomain=!1}destroy(){this.inputController=n(this.inputController)}initialize(){this.input&&(a(this.input)&&(this.inputController=new S({fieldInput:this})),o(this.input)&&(this.inputController=new j({fieldInput:this})))}get compositeError(){if(this.valid)return null;let{errors:e}=this;if(e.length<this.features.length)return C.DIFFERENT_ERRORS;let t=e[0];for(let n of e)if(n.error!==t.error)return C.DIFFERENT_ERRORS;return t.error}get dataType(){return w(this.field)}get domain(){let e=this._allDomains.toArray();return this.calculateDomain(e)}get distinctValues(){if(this.featuresHaveSameValue)return[this.value];let e=new Set;for(let t of this.features)e.add(t.getAttribute(this.fieldName));return Array.from(e)}get editable(){return this.field.editable?this._evaluatedEditableExpression??!0:!1}get label(){let{label:e}=this.template,t=this._computeStringLiteralText(e);if(t)return t;let{field:n,layers:r}=this;if(r.length===1){let e=r[0];if(_(e)){let t=e.getFieldAlias(n.name);if(t!=null&&t!==``)return t}}return n.alias||n.name}get effectiveVisible(){return T(this.effectiveVisibilityCode)}get effectiveVisibilityCode(){let{visibilityCode:e}=this;if(e!==`visible`)return e;let{group:t}=this;if(t==null)return e;let n=t.visibilityCode;return n===`hidden:visibility-expression:all-features`?`hidden:group-visibility-expression:all-features`:n===`hidden:visibility-expression:some-features`?`hidden:group-visibility-expression:some-features`:e}get errors(){return this._validate()}get featuresHaveSameValue(){let{fieldName:e}=this,t=this.features.at(0)?.getAttribute(e);return this.features.every(n=>P(n.getAttribute(e),t))}get field(){return this.template.field}get fieldName(){return this.field.name}get input(){return this.template.input}get invalidFeatures(){return this.errors.map(e=>e.feature)}get isSubtypeField(){return this.layers.some(e=>{if(e&&`subtypeField`in e){let{subtypeField:t,fieldsIndex:n}=e;return(n.get(t)?.name??t)===this.fieldName}return!1})}get showNoValueOptionEnabled(){let{input:e}=this;return this.required?!1:!E(e)||e?.showNoValueOption===!0}get showNoValueLabel(){let{input:e}=this;return E(e)?e?.noValueOptionLabel:null}get includeTime(){let{template:e,field:t}=this;return this.dataType===`date`?t.type===`time-only`?!0:t.type===`date-only`?!1:e.input?.type!==`datetime-picker`||e.input.includeTime:!1}get includeTimeOffset(){if(this.field.type!==`timestamp-offset`)return!1;let{input:e}=this;return!e||e.type===`timestampoffset-picker`&&e.includeTimeOffset}get inputType(){return this.input?.type}get maxLength(){return F({dataType:this.dataType,field:this.field,input:this.input})}get minLength(){return I({dataType:this.dataType,field:this.field,input:this.input})}get multipleChoiceOtherChoiceCheckboxState(){return V(this.inputController)?.otherChoiceCheckboxState??{checked:!1,indeterminate:!1}}get placeholder(){return this.template.hint}get range(){if(this.dataType===`date`)return this._dateRange;let{domain:e,field:t}=this;if(e){let n=l(t,e);return{max:n?.max,min:n?.min}}let n=this._allDomains.toArray().every(e=>!e)?p(t):null;return{max:n?.max===Number.MAX_VALUE?null:n?.max??null,min:n?.min===-Number.MAX_VALUE?null:n?.min??null}}get required(){if(!this.editable)return!1;if(!this.field.nullable||this.isSubtypeField)return!0;let e=this.visible&&this.group?.visible!==!1,t=this._evaluatedRequiredExpression;return e&&t!=null?t:!1}get status(){let{validationMessage:e}=this;return e?D(e)?`idle`:`invalid`:this.valid?`valid`:`idle`}get timeResolution(){let e=this.input;if(!(!e||e.type!==`timestampoffset-picker`&&e.type!==`time-picker`))return e.timeResolution??`minutes`}get timeStep(){return this.timeResolution==null?void 0:N.get(this.timeResolution)}get userInvalid(){return this.errors.some(({error:e})=>O(e))?!0:!this.valid&&this.touched}get valid(){return this.errors.length===0||!this.editable}get validationMessage(){return this.valueIsOutOfDomain&&this.touched?k.OUT_OF_SUBTYPE_DOMAIN:this.userInvalid?this.compositeError??void 0:void 0}get value(){return this.featuresHaveSameValue?this.features.at(0)?.getAttribute(this.fieldName)??null:A}get valueIsOutOfDomain(){let{domain:e,value:t,field:n}=this;return!e||t==null?!1:u(n,t,e)!==null}get visibilityCode(){return this.field.visible?this._fieldShouldHaveDomain&&this.domain==null?`hidden:no-domain-in-common`:this._baseVisibilityCode:`hidden:field-definition`}get codedValueDomainOptions(){return this.domain?.type===`coded-value`?this.domain.codedValues.map(({name:e,code:t})=>({name:e,value:t})):[]}getExplicitMultipleChoiceOtherChoiceCheckedState(){return V(this.inputController)?.getExplicitOtherChoiceCheckedState()}getMultipleChoiceOtherChoiceRenderState(e){let t=V(this.inputController)?.otherChoiceRenderState;return t?{...t,label:t.label??e}:{fieldName:void 0,hint:``,label:e,shouldShow:!1,checkboxState:{checked:!1,indeterminate:!1},value:null,normalizedValue:null,maxLength:void 0,status:`idle`}}hasExplicitMultipleChoiceOtherChoiceCheckedState(){return V(this.inputController)?.hasExplicitOtherChoiceCheckedState()??!1}initializeExplicitMultipleChoiceOtherChoiceCheckedState(){V(this.inputController)?.initializeExplicitOtherChoiceCheckedState()}setExplicitMultipleChoiceOtherChoiceCheckedState(e){V(this.inputController)?.setExplicitOtherChoiceCheckedState(e)}get codedValueOptions(){let{getFieldValueOptionsForFeature:e}=this;if(this.features.length===1&&e){let t=this.features.at(0);return e({domain:this.domain??void 0,feature:t,fieldName:this.fieldName,layer:t.layer})}let t=this.codedValueDomainOptions,{value:n}=this;return{recommended:t,other:[],unsupported:n!=null&&n!==A&&!t.some(e=>e.value===n)?[{name:`${n}`,value:n}]:[],containsEmptyOption:!1}}get _evaluatedRequiredExpression(){let e=!1,t=!0,n=this.template;for(let r of this.features){if(n.getExpressionExecutorsForLayer(r.layer)?.requiredExpression==null)continue;t=!1;let i=this._lookupEvaluatedExpression(r,`requiredExpression`);if(i?.status!==`success`){e=!0;continue}e||=i.result===!0}return t?null:e}get _allDomains(){let e=this.template.domain;return this.features.map(t=>{let n=t.layer.getFieldDomain(this.fieldName,{feature:t.plainGraphic});return n?.type===`range`||e?.type===`range`?n??this.template.domain:n})}get _fieldShouldHaveDomain(){return this._hasIntersectionWithElementFieldDomain?!0:this._allDomains.some(t)}get _dateFormRange(){if(this.dataType!==`date`)return{};let{input:e}=this;if(!e)return{};let{type:t}=e,n={};if((t===`date-picker`||t===`time-picker`||t===`timestampoffset-picker`)&&(n=d(this.field,e.max,e.min)),t===`datetime-picker`){let{max:t,min:r}=e;n={max:t!=null&&L(t)?t.getTime():null,min:r!=null&&L(r)?r.getTime():null}}return{min:n.min,max:n.max,rawMax:n?.rawMax??null,rawMin:n?.rawMin??null}}get _dateRange(){let{_dateFormRange:e,template:t,field:n,domain:r}=this;if(this.dataType!==`date`)return{};if(!r)return this._fieldShouldHaveDomain?{}:e;let i=l(n,r);if(!i)return e;let{max:a,min:o,rawMax:s,rawMin:c}=e,{type:u}=t.field;if(u===`date`){let{max:e,min:t}=i;return{max:y(a)&&(e===null||e!=null&&a<=e)?a:e??null,min:y(o)&&(t===null||t!=null&&o>=t)?o:t??null}}if(u===`date-only`||u===`time-only`||u===`timestamp-offset`){let{max:e,min:t,rawMax:n,rawMin:r}=i,l=y(a)&&s&&(e==null||a<e),u=y(o)&&c&&(t==null||o>t);return{max:l?a:e,min:u?o:t,rawMax:l?s:n,rawMin:u?c:r}}return{}}touch(){this.touched=!0}_validate(){let{dataType:e,fieldName:t,maxLength:n,minLength:r,range:i}=this,a=[],o=x(this.inputController)?this.inputController:void 0,s=o?.input;for(let c of this.features){let{layer:l}=c,u=l.getField(t)??this.field,d=l.getFieldDomain(t,{feature:c.plainGraphic}),f=this.calculateDomain([d]),p=!f||f.type===`coded-value`?null:f,m=this._requiredForFeature(c),h=c.getAttribute(t),g=R(h,{dataType:e,domain:p,field:u,maxLength:n,minLength:r,multipleChoice:s,range:i,required:m})??this.getExternalErrorForFeature?.(c,t);if(!g&&s&&o){let{otherChoice:e}=s,t=o.otherChoiceFieldName,n=o.shouldShowOtherChoice,r=o.otherChoiceEffectiveCheckboxState;if(n&&e&&t&&r.checked){let e=l.getField(t),n=c.getAttribute(t),r=n===M?null:n;if(e){let t=w(e);g=R(r,{dataType:t,domain:e.domain,field:e,maxLength:F({dataType:t,field:e,input:null}),minLength:I({dataType:t,field:e,input:null}),multipleChoice:null,range:{max:void 0,min:void 0},required:!0})}}}g&&a.push({error:g,feature:c.source})}return a}_editableForFeature(e){if(!this.field.editable)return!1;if(this.template.getExpressionExecutorsForLayer(e.layer)?.editableExpression==null)return!0;let t=this._lookupEvaluatedExpression(e,`editableExpression`);return t?.status===`success`&&t.result===!0}_effectiveVisibleFeature(e){if(this.group&&!this.group.visibleForFeature(e))return!1;if(this.template.getExpressionExecutorsForLayer(e.layer)?.visibilityExpression==null)return!0;let t=this._lookupEvaluatedExpression(e,`visibilityExpression`);return t?.status===`success`&&t.result===!0}_requiredForFeature(e){if(!this._editableForFeature(e))return!1;if(!this.field.nullable||this.isSubtypeField)return!0;let t=this._effectiveVisibleFeature(e);if(this.template.getExpressionExecutorsForLayer(e.layer)?.requiredExpression==null)return!1;let n=this._lookupEvaluatedExpression(e,`requiredExpression`);return n?.status===`success`?t&&n.result===!0:t}calculateDomain(e){let t=e.find(e=>e!=null),n=this.template.domain;if(!t)return n&&f(this.field,n)?n:null;switch(t.type){case`coded-value`:if(e.some(e=>!e)){if(!n)return null;e=e.filter(e=>e!==null)}break;case`range`:e=e.filter(e=>e!==null)}if(!e.every(e=>e?.type===t?.type))return null;let r=null;switch(t?.type){case`range`:r=this._intersectRangeDomains(e);break;case`coded-value`:r=this._intersectCodedValueDomains(e)}return r}_intersectCodedValueDomains(e){if(!e.length)return null;let t=new Map(e[0].codedValues.map(({code:e,name:t})=>[e,t])),n=this.template.domain?new Map(this.template.domain.codedValues.map(({code:e,name:t})=>[e,t])):null;for(let n of e)for(let[e,r]of t)if(!n.codedValues.some(t=>t.code===e&&t.name===r)){t.delete(e);continue}let r=t;if(n){r=new Map;for(let[e,i]of n)t.has(e)&&r.set(e,i)}let i=Array.from(r.entries()).map(([e,t])=>new s({code:e,name:t}));return i.length?new c({codedValues:i}):null}_intersectRangeDomains(e){if(!e.length)return null;let t=e[0];for(let n=1;n<e.length;n++){if(!t)return null;t=this._findMinMaxValuesBetweenTwoDomains(t,e[n])}if(t&&!f(this.field,t))return null;let{domain:n}=this.template;if(t&&n&&n instanceof v){let e=this._findMinMaxValuesBetweenTwoDomains(t,n);return this._hasIntersectionWithElementFieldDomain=!!e,e}return t}_getMinMaxFromRangeDomain(e){let t=e.minValue,n=e.maxValue,{field:r}=this;return m(r)||h(r)||g(r)?d(r,n,t):{min:t!=null&&typeof t==`number`?t:null,max:n!=null&&typeof n==`number`?n:null}}_findMinMaxValuesBetweenTwoDomains(e,t){let n=new v,r=this._getMinMaxFromRangeDomain(e),i=this._getMinMaxFromRangeDomain(t),{field:a}=this,o=this._getValidRangeValue(r.min,-1/0),s=this._getValidRangeValue(r.max,1/0),c=this._getValidRangeValue(i.min,-1/0),l=this._getValidRangeValue(i.max,1/0);return n.minValue=Math.max(o,c),n.maxValue=Math.min(s,l),n.minValue===-1/0||n.maxValue===1/0||n.minValue>n.maxValue?null:((m(a)||h(a)||g(a))&&(n.minValue=Number(r.min)>Number(i.min)?r.rawMin:i.rawMin,n.maxValue=Number(r.max)<Number(i.max)?r.rawMax:i.rawMax),n.name=`intersection`,n)}_getValidRangeValue(e,t){return y(e)?e:t}};e([r()],z.prototype,`dataType`,null),e([r()],z.prototype,`domain`,null),e([r()],z.prototype,`distinctValues`,null),e([r()],z.prototype,`editable`,null),e([r()],z.prototype,`label`,null),e([r()],z.prototype,`effectiveVisible`,null),e([r()],z.prototype,`effectiveVisibilityCode`,null),e([r()],z.prototype,`errors`,null),e([r()],z.prototype,`featuresHaveSameValue`,null),e([r()],z.prototype,`field`,null),e([r()],z.prototype,`fieldName`,null),e([r()],z.prototype,`getExternalErrorForFeature`,void 0),e([r()],z.prototype,`getFieldValueOptionsForFeature`,void 0),e([r()],z.prototype,`group`,void 0),e([r()],z.prototype,`input`,null),e([r()],z.prototype,`inputController`,void 0),e([r()],z.prototype,`invalidFeatures`,null),e([r()],z.prototype,`isSubtypeField`,null),e([r()],z.prototype,`showNoValueOptionEnabled`,null),e([r()],z.prototype,`showNoValueLabel`,null),e([r()],z.prototype,`includeTime`,null),e([r()],z.prototype,`includeTimeOffset`,null),e([r({readOnly:!0})],z.prototype,`inputType`,null),e([r()],z.prototype,`maxLength`,null),e([r()],z.prototype,`minLength`,null),e([r()],z.prototype,`multipleChoiceOtherChoiceCheckboxState`,null),e([r()],z.prototype,`placeholder`,null),e([r()],z.prototype,`range`,null),e([r()],z.prototype,`required`,null),e([r()],z.prototype,`status`,null),e([r()],z.prototype,`timeResolution`,null),e([r()],z.prototype,`timeStep`,null),e([r()],z.prototype,`touched`,void 0),e([r({readOnly:!0})],z.prototype,`type`,void 0),e([r()],z.prototype,`userHasChangedValue`,void 0),e([r()],z.prototype,`userInvalid`,null),e([r()],z.prototype,`valid`,null),e([r()],z.prototype,`validationMessage`,null),e([r()],z.prototype,`value`,null),e([r()],z.prototype,`valueIsOutOfDomain`,null),e([r()],z.prototype,`visibilityCode`,null),e([r()],z.prototype,`codedValueDomainOptions`,null),e([r()],z.prototype,`codedValueOptions`,null),e([r()],z.prototype,`_evaluatedRequiredExpression`,null),e([r()],z.prototype,`_hasIntersectionWithElementFieldDomain`,void 0),e([r()],z.prototype,`_allDomains`,null),e([r()],z.prototype,`_fieldShouldHaveDomain`,null),e([r()],z.prototype,`_dateFormRange`,null),e([r()],z.prototype,`_dateRange`,null),z=e([i(`esri.widgets.BatchAttributeForm.inputs.FieldInput`)],z);const B=z;function V(e){return x(e)?e:null}export{B as default};
2
+ import{__decorate as e}from"tslib";import{isSome as t}from"../../../core/arrayUtils.js";import n from"../../../core/Logger.js";import{destroyMaybe as r}from"../../../core/maybe.js";import{property as i,subclass as a}from"../../../core/accessorSupport/decorators.js";import{isDynamicChoiceInput as o,isMultipleChoiceInput as s}from"../../../form/elements/inputs/inputUtils.js";import c from"../../../layers/support/CodedValue.js";import l from"../../../layers/support/CodedValueDomain.js";import{getDomainRange as u,validateDomainValue as d,dateTimeFieldValuesToNumericRange as f,isDomainValidForField as p}from"../../../layers/support/domainUtils.js";import{getFieldRange as m,isDateOnlyField as h,isTimeOnlyField as g,isTimestampOffsetField as _}from"../../../layers/support/fieldUtils.js";import{supportsFieldConfiguration as v}from"../../../layers/support/layerUtils.js";import y from"../../../layers/support/RangeDomain.js";import{isNumber as b}from"../../../support/guards.js";import x from"./EditableInput.js";import{isMultipleChoiceController as S}from"./support/controllerUtils.js";import C from"./support/DynamicChoiceController.js";import{MultiFeatureError as w,getFieldInputDataType as T,visibilityCodeToBoolean as E,isFieldInputWithShowNoValueOptionInput as D,isWarning as O,isContingentValuesError as k,FormValidationWarning as A,differentValuesString as j}from"./support/inputUtils.js";import M from"./support/MultipleChoiceController.js";import{otherChoiceCheckedPlaceholderValue as N}from"./support/multipleChoiceInputUtils.js";import{timeResolutionToStepMap as P}from"../../support/dateUtils.js";import{valuesAreEquivalent as F,getMaxLength as I,getMinLength as L,dateIsValid as R,validateFormValue as z}from"../../support/forms/formUtils.js";let B=class extends x{constructor(e){super(e),this.getExternalErrorForFeature=null,this.getFieldValueOptionsForFeature=null,this.group=null,this.inputController=null,this.touched=!1,this.type=`field`,this.userHasChangedValue=!1,this._hasIntersectionWithElementFieldDomain=!1}destroy(){this.inputController=r(this.inputController)}initialize(){if(this.input){if(o(this.input)){let{requestDeferredExpressionEvaluation:e}=this;e?this.inputController=new C({fieldInput:this,requestDeferredExpressionEvaluation:e}):n.getLogger(this).error(`requestDeferredExpressionEvaluation callback is required for dynamic choice inputs.`)}s(this.input)&&(this.inputController=new M({fieldInput:this}))}}get compositeError(){if(this.valid)return null;let{errors:e}=this;if(e.length<this.features.length)return w.DIFFERENT_ERRORS;let t=e[0];for(let n of e)if(n.error!==t.error)return w.DIFFERENT_ERRORS;return t.error}get dataType(){return T(this.field)}get domain(){let e=this._allDomains.toArray();return this.calculateDomain(e)}get distinctValues(){if(this.featuresHaveSameValue)return[this.value];let e=new Set;for(let t of this.features)e.add(t.getAttribute(this.fieldName));return Array.from(e)}get editable(){return this.field.editable?this._evaluatedEditableExpression??!0:!1}get label(){let{label:e}=this.template,t=this._computeStringLiteralText(e);if(t)return t;let{field:n,layers:r}=this;if(r.length===1){let e=r[0];if(v(e)){let t=e.getFieldAlias(n.name);if(t!=null&&t!==``)return t}}return n.alias||n.name}get effectiveVisible(){return E(this.effectiveVisibilityCode)}get effectiveVisibilityCode(){let{visibilityCode:e}=this;if(e!==`visible`)return e;let{group:t}=this;if(t==null)return e;let n=t.visibilityCode;return n===`hidden:visibility-expression:all-features`?`hidden:group-visibility-expression:all-features`:n===`hidden:visibility-expression:some-features`?`hidden:group-visibility-expression:some-features`:e}get errors(){return this._validate()}get featuresHaveSameValue(){let{fieldName:e}=this,t=this.features.at(0)?.getAttribute(e);return this.features.every(n=>F(n.getAttribute(e),t))}get field(){return this.template.field}get fieldName(){return this.field.name}get input(){return this.template.input}get invalidFeatures(){return this.errors.map(e=>e.feature)}get isSubtypeField(){return this.layers.some(e=>{if(e&&`subtypeField`in e){let{subtypeField:t,fieldsIndex:n}=e;return(n.get(t)?.name??t)===this.fieldName}return!1})}get showNoValueOptionEnabled(){let{input:e}=this;return this.required?!1:!D(e)||e?.showNoValueOption===!0}get showNoValueLabel(){let{input:e}=this;return D(e)?e?.noValueOptionLabel:null}get includeTime(){let{template:e,field:t}=this;return this.dataType===`date`?t.type===`time-only`?!0:t.type===`date-only`?!1:e.input?.type!==`datetime-picker`||e.input.includeTime:!1}get includeTimeOffset(){if(this.field.type!==`timestamp-offset`)return!1;let{input:e}=this;return!e||e.type===`timestampoffset-picker`&&e.includeTimeOffset}get inputType(){return this.input?.type}get maxLength(){return I({dataType:this.dataType,field:this.field,input:this.input})}get minLength(){return L({dataType:this.dataType,field:this.field,input:this.input})}get multipleChoiceOtherChoiceCheckboxState(){return H(this.inputController)?.otherChoiceCheckboxState??{checked:!1,indeterminate:!1}}get placeholder(){return this.template.hint}get range(){if(this.dataType===`date`)return this._dateRange;let{domain:e,field:t}=this;if(e){let n=u(t,e);return{max:n?.max,min:n?.min}}let n=this._allDomains.toArray().every(e=>!e)?m(t):null;return{max:n?.max===Number.MAX_VALUE?null:n?.max??null,min:n?.min===-Number.MAX_VALUE?null:n?.min??null}}get required(){if(!this.editable)return!1;if(!this.field.nullable||this.isSubtypeField)return!0;let e=this.visible&&this.group?.visible!==!1,t=this._evaluatedRequiredExpression;return e&&t!=null?t:!1}get status(){let{validationMessage:e}=this;return e?O(e)?`idle`:`invalid`:this.valid?`valid`:`idle`}get timeResolution(){let e=this.input;if(!(!e||e.type!==`timestampoffset-picker`&&e.type!==`time-picker`))return e.timeResolution??`minutes`}get timeStep(){return this.timeResolution==null?void 0:P.get(this.timeResolution)}get userInvalid(){return this.errors.some(({error:e})=>k(e))?!0:!this.valid&&this.touched}get valid(){return this.errors.length===0||!this.editable}get validationMessage(){return this.valueIsOutOfDomain&&this.touched?A.OUT_OF_SUBTYPE_DOMAIN:this.userInvalid?this.compositeError??void 0:void 0}get value(){return this.featuresHaveSameValue?this.features.at(0)?.getAttribute(this.fieldName)??null:j}get valueIsOutOfDomain(){let{domain:e,value:t,field:n}=this;return!e||t==null?!1:d(n,t,e)!==null}get visibilityCode(){return this.field.visible?this._fieldShouldHaveDomain&&this.domain==null?`hidden:no-domain-in-common`:this._baseVisibilityCode:`hidden:field-definition`}get codedValueDomainOptions(){return this.domain?.type===`coded-value`?this.domain.codedValues.map(({name:e,code:t})=>({name:e,value:t})):[]}getExplicitMultipleChoiceOtherChoiceCheckedState(){return H(this.inputController)?.getExplicitOtherChoiceCheckedState()}getMultipleChoiceOtherChoiceRenderState(e){let t=H(this.inputController)?.otherChoiceRenderState;return t?{...t,label:t.label??e}:{fieldName:void 0,hint:``,label:e,shouldShow:!1,checkboxState:{checked:!1,indeterminate:!1},value:null,normalizedValue:null,maxLength:void 0,status:`idle`}}hasExplicitMultipleChoiceOtherChoiceCheckedState(){return H(this.inputController)?.hasExplicitOtherChoiceCheckedState()??!1}initializeExplicitMultipleChoiceOtherChoiceCheckedState(){H(this.inputController)?.initializeExplicitOtherChoiceCheckedState()}setExplicitMultipleChoiceOtherChoiceCheckedState(e){H(this.inputController)?.setExplicitOtherChoiceCheckedState(e)}get codedValueOptions(){let{getFieldValueOptionsForFeature:e}=this;if(this.features.length===1&&e){let t=this.features.at(0);return e({domain:this.domain??void 0,feature:t,fieldName:this.fieldName,layer:t.layer})}let t=this.codedValueDomainOptions,{value:n}=this;return{recommended:t,other:[],unsupported:n!=null&&n!==j&&!t.some(e=>e.value===n)?[{name:`${n}`,value:n}]:[],containsEmptyOption:!1}}get _evaluatedRequiredExpression(){let e=!1,t=!0,n=this.template;for(let r of this.features){if(n.getExpressionExecutorsForLayer(r.layer)?.requiredExpression==null)continue;t=!1;let i=this._lookupEvaluatedExpression(r,`requiredExpression`);if(i?.status!==`success`){e=!0;continue}e||=i.result===!0}return t?null:e}get _allDomains(){let e=this.template.domain;return this.features.map(t=>{let n=t.layer.getFieldDomain(this.fieldName,{feature:t.plainGraphic});return n?.type===`range`||e?.type===`range`?n??this.template.domain:n})}get _fieldShouldHaveDomain(){return this._hasIntersectionWithElementFieldDomain?!0:this._allDomains.some(t)}get _dateFormRange(){if(this.dataType!==`date`)return{};let{input:e}=this;if(!e)return{};let{type:t}=e,n={};if((t===`date-picker`||t===`time-picker`||t===`timestampoffset-picker`)&&(n=f(this.field,e.max,e.min)),t===`datetime-picker`){let{max:t,min:r}=e;n={max:t!=null&&R(t)?t.getTime():null,min:r!=null&&R(r)?r.getTime():null}}return{min:n.min,max:n.max,rawMax:n?.rawMax??null,rawMin:n?.rawMin??null}}get _dateRange(){let{_dateFormRange:e,template:t,field:n,domain:r}=this;if(this.dataType!==`date`)return{};if(!r)return this._fieldShouldHaveDomain?{}:e;let i=u(n,r);if(!i)return e;let{max:a,min:o,rawMax:s,rawMin:c}=e,{type:l}=t.field;if(l===`date`){let{max:e,min:t}=i;return{max:b(a)&&(e===null||e!=null&&a<=e)?a:e??null,min:b(o)&&(t===null||t!=null&&o>=t)?o:t??null}}if(l===`date-only`||l===`time-only`||l===`timestamp-offset`){let{max:e,min:t,rawMax:n,rawMin:r}=i,l=b(a)&&s&&(e==null||a<e),u=b(o)&&c&&(t==null||o>t);return{max:l?a:e,min:u?o:t,rawMax:l?s:n,rawMin:u?c:r}}return{}}touch(){this.touched=!0}_validate(){let{dataType:e,fieldName:t,maxLength:n,minLength:r,range:i}=this,a=[],o=S(this.inputController)?this.inputController:void 0,s=o?.input;for(let c of this.features){let{layer:l}=c,u=l.getField(t)??this.field,d=l.getFieldDomain(t,{feature:c.plainGraphic}),f=this.calculateDomain([d]),p=!f||f.type===`coded-value`?null:f,m=this._requiredForFeature(c),h=c.getAttribute(t),g=z(h,{dataType:e,domain:p,field:u,maxLength:n,minLength:r,multipleChoice:s,range:i,required:m})??this.getExternalErrorForFeature?.(c,t);if(!g&&s&&o){let{otherChoice:e}=s,t=o.otherChoiceFieldName,n=o.shouldShowOtherChoice,r=o.otherChoiceEffectiveCheckboxState;if(n&&e&&t&&r.checked){let e=l.getField(t),n=c.getAttribute(t),r=n===N?null:n;if(e){let t=T(e);g=z(r,{dataType:t,domain:e.domain,field:e,maxLength:I({dataType:t,field:e,input:null}),minLength:L({dataType:t,field:e,input:null}),multipleChoice:null,range:{max:void 0,min:void 0},required:!0})}}}g&&a.push({error:g,feature:c.source})}return a}_editableForFeature(e){if(!this.field.editable)return!1;if(this.template.getExpressionExecutorsForLayer(e.layer)?.editableExpression==null)return!0;let t=this._lookupEvaluatedExpression(e,`editableExpression`);return t?.status===`success`&&t.result===!0}_effectiveVisibleFeature(e){if(this.group&&!this.group.visibleForFeature(e))return!1;if(this.template.getExpressionExecutorsForLayer(e.layer)?.visibilityExpression==null)return!0;let t=this._lookupEvaluatedExpression(e,`visibilityExpression`);return t?.status===`success`&&t.result===!0}_requiredForFeature(e){if(!this._editableForFeature(e))return!1;if(!this.field.nullable||this.isSubtypeField)return!0;let t=this._effectiveVisibleFeature(e);if(this.template.getExpressionExecutorsForLayer(e.layer)?.requiredExpression==null)return!1;let n=this._lookupEvaluatedExpression(e,`requiredExpression`);return n?.status===`success`?t&&n.result===!0:t}calculateDomain(e){let t=e.find(e=>e!=null),n=this.template.domain;if(!t)return n&&p(this.field,n)?n:null;switch(t.type){case`coded-value`:if(e.some(e=>!e)){if(!n)return null;e=e.filter(e=>e!==null)}break;case`range`:e=e.filter(e=>e!==null)}if(!e.every(e=>e?.type===t?.type))return null;let r=null;switch(t?.type){case`range`:r=this._intersectRangeDomains(e);break;case`coded-value`:r=this._intersectCodedValueDomains(e)}return r}_intersectCodedValueDomains(e){if(!e.length)return null;let t=new Map(e[0].codedValues.map(({code:e,name:t})=>[e,t])),n=this.template.domain?new Map(this.template.domain.codedValues.map(({code:e,name:t})=>[e,t])):null;for(let n of e)for(let[e,r]of t)if(!n.codedValues.some(t=>t.code===e&&t.name===r)){t.delete(e);continue}let r=t;if(n){r=new Map;for(let[e,i]of n)t.has(e)&&r.set(e,i)}let i=Array.from(r.entries()).map(([e,t])=>new c({code:e,name:t}));return i.length?new l({codedValues:i}):null}_intersectRangeDomains(e){if(!e.length)return null;let t=e[0];for(let n=1;n<e.length;n++){if(!t)return null;t=this._findMinMaxValuesBetweenTwoDomains(t,e[n])}if(t&&!p(this.field,t))return null;let{domain:n}=this.template;if(t&&n&&n instanceof y){let e=this._findMinMaxValuesBetweenTwoDomains(t,n);return this._hasIntersectionWithElementFieldDomain=!!e,e}return t}_getMinMaxFromRangeDomain(e){let t=e.minValue,n=e.maxValue,{field:r}=this;return h(r)||g(r)||_(r)?f(r,n,t):{min:t!=null&&typeof t==`number`?t:null,max:n!=null&&typeof n==`number`?n:null}}_findMinMaxValuesBetweenTwoDomains(e,t){let n=new y,r=this._getMinMaxFromRangeDomain(e),i=this._getMinMaxFromRangeDomain(t),{field:a}=this,o=this._getValidRangeValue(r.min,-1/0),s=this._getValidRangeValue(r.max,1/0),c=this._getValidRangeValue(i.min,-1/0),l=this._getValidRangeValue(i.max,1/0);return n.minValue=Math.max(o,c),n.maxValue=Math.min(s,l),n.minValue===-1/0||n.maxValue===1/0||n.minValue>n.maxValue?null:((h(a)||g(a)||_(a))&&(n.minValue=Number(r.min)>Number(i.min)?r.rawMin:i.rawMin,n.maxValue=Number(r.max)<Number(i.max)?r.rawMax:i.rawMax),n.name=`intersection`,n)}_getValidRangeValue(e,t){return b(e)?e:t}};e([i()],B.prototype,`dataType`,null),e([i()],B.prototype,`domain`,null),e([i()],B.prototype,`distinctValues`,null),e([i()],B.prototype,`editable`,null),e([i()],B.prototype,`label`,null),e([i()],B.prototype,`effectiveVisible`,null),e([i()],B.prototype,`effectiveVisibilityCode`,null),e([i()],B.prototype,`errors`,null),e([i()],B.prototype,`featuresHaveSameValue`,null),e([i()],B.prototype,`field`,null),e([i()],B.prototype,`fieldName`,null),e([i()],B.prototype,`getExternalErrorForFeature`,void 0),e([i()],B.prototype,`getFieldValueOptionsForFeature`,void 0),e([i()],B.prototype,`group`,void 0),e([i()],B.prototype,`input`,null),e([i()],B.prototype,`inputController`,void 0),e([i()],B.prototype,`invalidFeatures`,null),e([i()],B.prototype,`isSubtypeField`,null),e([i()],B.prototype,`showNoValueOptionEnabled`,null),e([i()],B.prototype,`showNoValueLabel`,null),e([i()],B.prototype,`includeTime`,null),e([i()],B.prototype,`includeTimeOffset`,null),e([i({readOnly:!0})],B.prototype,`inputType`,null),e([i()],B.prototype,`maxLength`,null),e([i()],B.prototype,`minLength`,null),e([i()],B.prototype,`multipleChoiceOtherChoiceCheckboxState`,null),e([i()],B.prototype,`placeholder`,null),e([i()],B.prototype,`range`,null),e([i()],B.prototype,`requestDeferredExpressionEvaluation`,void 0),e([i()],B.prototype,`required`,null),e([i()],B.prototype,`status`,null),e([i()],B.prototype,`timeResolution`,null),e([i()],B.prototype,`timeStep`,null),e([i()],B.prototype,`touched`,void 0),e([i({readOnly:!0})],B.prototype,`type`,void 0),e([i()],B.prototype,`userHasChangedValue`,void 0),e([i()],B.prototype,`userInvalid`,null),e([i()],B.prototype,`valid`,null),e([i()],B.prototype,`validationMessage`,null),e([i()],B.prototype,`value`,null),e([i()],B.prototype,`valueIsOutOfDomain`,null),e([i()],B.prototype,`visibilityCode`,null),e([i()],B.prototype,`codedValueDomainOptions`,null),e([i()],B.prototype,`codedValueOptions`,null),e([i()],B.prototype,`_evaluatedRequiredExpression`,null),e([i()],B.prototype,`_hasIntersectionWithElementFieldDomain`,void 0),e([i()],B.prototype,`_allDomains`,null),e([i()],B.prototype,`_fieldShouldHaveDomain`,null),e([i()],B.prototype,`_dateFormRange`,null),e([i()],B.prototype,`_dateRange`,null),B=e([a(`esri.widgets.BatchAttributeForm.inputs.FieldInput`)],B);const V=B;function H(e){return S(e)?e:null}export{V as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{createTask as n}from"../../../../core/asyncUtils.js";import r from"../../../../core/Logger.js";import{getOrCreateMapValue as i}from"../../../../core/MapUtils.js";import{abortMaybe as a}from"../../../../core/maybe.js";import{ignoreAbortErrors as o,throwIfAborted as s}from"../../../../core/promiseUtils.js";import{property as c,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as u}from"../../../../core/support/UpdatingHandles.js";import{validateDomainValue as d}from"../../../../layers/support/domainUtils.js";import{makeArcadeContext as f,castArcadeValue as p}from"../../expressions/expressionUtils.js";let m=class extends t{constructor(e){super(e),this.filterValue=``,this._choices=[],this._evaluated=!1,this._choicesByCode=new Map,this._expressionTask=null,this._interactionActive=!1,this._updatingHandles=new u}destroy(){a(this._expressionTask),this._updatingHandles.destroy()}get arcadeContextInfo(){return this.fieldInput.expressionsManager.arcadeContext}get choices(){return this._choices}get evaluating(){return this._updatingHandles.updating}get evaluated(){return this._evaluated}get inputValue(){if(this._interactionActive)return this.filterValue;let e=this.fieldInput.value;return e==null?``:this.getLabel(e)}get features(){return this.fieldInput.features}get filteredChoices(){let e=this.choices,t=this.filterValue.trim().toLocaleLowerCase();return t?e.filter((e,n)=>this._normalizedChoiceNames[n].includes(t)):e}get input(){return this.fieldInput.input}get _normalizedChoiceNames(){return this._choices.map(({code:e,name:t})=>`${t}\n${this.getLabel(e)}`.toLocaleLowerCase())}beginInteraction(){this._interactionActive||(this._interactionActive=!0,this.filterValue=``,this.evaluateChoiceExpression())}getChoice(e){return this._choicesByCode.get(e)}getLabel(e){let t=this.fieldInput.domain;return t?.type===`coded-value`?t.getName(e)??this.getChoice(e)?.name??String(e):this.getChoice(e)?.name??String(e)}endInteraction(){this._interactionActive=!1,this.filterValue=``}async evaluateChoiceExpression(){this._expressionTask=a(this._expressionTask);let e=n(e=>this._evaluateChoiceExpression(e));this._expressionTask=e;try{return await o(this._updatingHandles.addPromise(e.promise))??this.choices}finally{this._expressionTask===e&&(this._expressionTask=null)}}async _evaluateChoiceExpression(e){let t=await import(`../../../../arcade/languageUtils.js`);s(e);let n=this.arcadeContextInfo,r=this.fieldInput.field,a=Array(this.features.length),o=new Map,c;this.features.forEach((t,r)=>{let s=this.fieldInput.template.getExpressionExecutorsForLayer(t.layer)?.choiceExpression;if(!s){a[r]=[];return}let l=f(n,t,e);c||=l.executeContext,i(o,s,()=>[]).push({index:r,variables:l.variables})});for(let[i,l]of o){let o=await i.executeAsyncBatch(l,({variables:e})=>e,c);s(e);for(let e=0;e<o.length;e++){let i=o[e];if(i.status===`rejected`){a[l[e].index]=[];continue}a[l[e].index]=this._parseChoices(i.value,n,r,t)}}let l=this.fieldInput.domain,u=_(g(a)).filter(({code:e})=>d(r,e,l)===null);return this._choicesByCode=new Map(u.map(e=>[e.code,e])),this._choices=u,this._evaluated=!0,u}_parseChoices(e,t,n,r){if(!v(e,r))return b(this),[];let i=y(e,`choices`),a=r.isImmutableArray(i)?i.toArray():Array.isArray(i)?i:[],o=[];for(let e of a){if(!v(e,r)){b(this);continue}let i=y(e,`name`),a=y(e,`code`);if(typeof i!=`string`||a===void 0||r.isVoid(a)||r.isFunctionParameter(a)){b(this);continue}let s=p(a,n,t.timeZone,r);s!=null&&o.push({name:i,code:s})}return o}};e([c()],m.prototype,`arcadeContextInfo`,null),e([c()],m.prototype,`choices`,null),e([c()],m.prototype,`evaluating`,null),e([c()],m.prototype,`evaluated`,null),e([c()],m.prototype,`inputValue`,null),e([c()],m.prototype,`features`,null),e([c({constructOnly:!0})],m.prototype,`fieldInput`,void 0),e([c()],m.prototype,`filteredChoices`,null),e([c()],m.prototype,`filterValue`,void 0),e([c()],m.prototype,`input`,null),e([c()],m.prototype,`_choices`,void 0),e([c()],m.prototype,`_evaluated`,void 0),e([c()],m.prototype,`_interactionActive`,void 0),e([c()],m.prototype,`_normalizedChoiceNames`,null),m=e([l(`esri.widgets.BatchAttributeForm.inputs.support.DynamicChoiceController`)],m);const h=m;function g(e){let[t,...n]=e;if(!t)return[];let r=t;for(let e of n.sort((e,t)=>e.length-t.length)){if(!e.length)return[];let t=new Map;for(let{code:n,name:r}of e)i(t,n,()=>new Set).add(r);if(r=r.filter(({code:e,name:n})=>t.get(e)?.has(n)),!r.length)break}return r}function _(e){let t=new Set;return e.filter(({code:e})=>!t.has(e)&&(t.add(e),!0))}function v(e,t){return t.isDictionary(e)&&typeof e.field==`function`&&typeof e.keys==`function`}function y(e,t){let n=e.keys().find(e=>e.toLowerCase()===t);return n==null?void 0:e.field(n)}function b(e){r.getLogger(e).error(`Value returned by choice expression does not conform to specification.`)}export{h as default};
2
+ import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{createTask as n}from"../../../../core/asyncUtils.js";import r from"../../../../core/Logger.js";import{getOrCreateMapValue as i}from"../../../../core/MapUtils.js";import{abortMaybe as a}from"../../../../core/maybe.js";import{ignoreAbortErrors as o,throwIfAborted as s}from"../../../../core/promiseUtils.js";import{property as c,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as u}from"../../../../core/support/UpdatingHandles.js";import{validateDomainValue as d}from"../../../../layers/support/domainUtils.js";import{castArcadeValue as f}from"../../expressions/expressionUtils.js";import{makeUseId as p}from"./inputUtils.js";import{isEmptyValue as m}from"../../../support/forms/formUtils.js";let h=class extends t{constructor(e){super(e),this.initialEvaluationInProgress=!1,this.filterValue=``,this._choices=[],this._evaluated=!1,this._choicesByCode=new Map,this._expressionTask=null,this._interactionActive=!1,this._updatingHandles=new u}initialize(){!this._codedValueDomain&&!m(this.fieldInput.value)&&(this.initialEvaluationInProgress=!0,this.evaluateChoiceExpression().finally(()=>{this.initialEvaluationInProgress=!1}))}destroy(){a(this._expressionTask),this._updatingHandles.destroy()}get arcadeContextInfo(){return this.fieldInput.expressionsManager.arcadeContext}get choices(){return this._choices}get evaluating(){return this._updatingHandles.updating}get evaluated(){return this._evaluated}get inputValue(){if(this._interactionActive)return this.filterValue;let e=this.fieldInput.value;return e==null?``:this.getLabel(e)}get features(){return this.fieldInput.features}get filteredChoices(){let e=this.choices,t=this.filterValue.trim().toLocaleLowerCase();return t?e.filter((e,n)=>this._normalizedChoiceNames[n].includes(t)):e}get input(){return this.fieldInput.input}get _codedValueDomain(){let e=this.fieldInput.domain;return e?.type===`coded-value`?e:null}get _normalizedChoiceNames(){return this._choices.map(({code:e,name:t})=>`${t}\n${this.getLabel(e)}`.toLocaleLowerCase())}beginInteraction(){this._interactionActive||(this._interactionActive=!0,this.filterValue=``,this.evaluateChoiceExpression())}getChoice(e){return this._choicesByCode.get(e)}getLabel(e){let t=this._codedValueDomain;return t?t.getName(e)??this.getChoice(e)?.name??String(e):this.getChoice(e)?.name??String(e)}endInteraction(){this._interactionActive=!1,this.filterValue=``}async evaluateChoiceExpression(){this._expressionTask=a(this._expressionTask);let e=n(e=>this._evaluateChoiceExpression(e));this._expressionTask=e;try{return await o(this._updatingHandles.addPromise(e.promise))??this.choices}finally{this._expressionTask===e&&(this._expressionTask=null)}}async _evaluateChoiceExpression(e){let t=await import(`../../../../arcade/languageUtils.js`);s(e);let n=this.arcadeContextInfo,r=this.fieldInput.field,i=this.fieldInput.template;await this.requestDeferredExpressionEvaluation({features:this.features.toArray(),getExecutor:e=>i.getExpressionExecutorsForLayer(e)?.choiceExpression}),this._evaluated=!0;let a=[];for(let e of this.features){let i=this._lookupExpressionOutcome(e),o=i?.result?this._parseChoices(i.result,n,r,t):[];if(o.length===0)return[];a.push(o)}let o=this.fieldInput.domain,c=v(_(a)).filter(({code:e})=>d(r,e,o)===null);return this._choicesByCode=new Map(c.map(e=>[e.code,e])),this._choices=c,c}_lookupExpressionOutcome(e){return this.fieldInput.expressionsManager.outcomes.get(e)?.get(p({elementId:this.fieldInput.template.elementId,executorPurpose:`choiceExpression`}))}_parseChoices(e,t,n,r){if(!y(e,r))return x(this),[];let i=b(e,`choices`),a=r.isImmutableArray(i)?i.toArray():Array.isArray(i)?i:[],o=[];for(let e of a){if(!y(e,r)){x(this);continue}let i=b(e,`name`),a=b(e,`code`);if(typeof i!=`string`||a===void 0||r.isVoid(a)||r.isFunctionParameter(a)){x(this);continue}let s=f(a,n,t.timeZone,r);s!=null&&o.push({name:i,code:s})}return o}};e([c()],h.prototype,`arcadeContextInfo`,null),e([c()],h.prototype,`choices`,null),e([c()],h.prototype,`evaluating`,null),e([c()],h.prototype,`evaluated`,null),e([c()],h.prototype,`initialEvaluationInProgress`,void 0),e([c()],h.prototype,`inputValue`,null),e([c()],h.prototype,`features`,null),e([c({constructOnly:!0})],h.prototype,`fieldInput`,void 0),e([c()],h.prototype,`filteredChoices`,null),e([c()],h.prototype,`filterValue`,void 0),e([c()],h.prototype,`input`,null),e([c()],h.prototype,`requestDeferredExpressionEvaluation`,void 0),e([c()],h.prototype,`_choices`,void 0),e([c()],h.prototype,`_codedValueDomain`,null),e([c()],h.prototype,`_evaluated`,void 0),e([c()],h.prototype,`_choicesByCode`,void 0),e([c()],h.prototype,`_interactionActive`,void 0),e([c()],h.prototype,`_normalizedChoiceNames`,null),h=e([l(`esri.widgets.BatchAttributeForm.inputs.support.DynamicChoiceController`)],h);const g=h;function _(e){let[t,...n]=e;if(!t||t.length===0)return[];let r=t;for(let e of n.sort((e,t)=>e.length-t.length)){if(!e.length)return[];let t=new Map;for(let{code:n,name:r}of e)i(t,n,()=>new Set).add(r);if(r=r.filter(({code:e,name:n})=>t.get(e)?.has(n)),!r.length)break}return r}function v(e){let t=new Set;return e.filter(({code:e})=>!t.has(e)&&(t.add(e),!0))}function y(e,t){return t.isDictionary(e)&&typeof e.field==`function`&&typeof e.keys==`function`}function b(e,t){let n=e.keys().find(e=>e.toLowerCase()===t);return n==null?void 0:e.field(n)}function x(e){r.getLogger(e).error(`Value returned by choice expression does not conform to specification.`)}export{g as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../../../../core/Error.js";import t from"../AttachmentElementInput.js";import n from"../BatchFormInputs.js";import r from"../FieldInput.js";import i from"../GroupInput.js";import a from"../RelationshipElementInput.js";import o from"../TextElementInput.js";import s from"../UtilityNetworkAssociationsElementInput.js";import{isMultipleChoiceController as c}from"./controllerUtils.js";import{hashGroupElementTemplateWithoutChildren as l}from"../../templates/support/hashElementTemplate.js";import{isFieldElementTemplate as u,isGroupElementTemplate as d,isRelationshipElementTemplate as f,isTextElementTemplate as p,isAttachmentElementTemplate as m,isUtilityNetworkAssociationsElementTemplate as h}from"../../templates/support/templateUtils.js";function g(e,t){let r=new n({inputs:e.elements.map(e=>S(e,t)),template:e});return x(r),r}function _(e,t,n){let r=g(t,n),{mergedInputs:i}=v(e.inputs,r.inputs,e.staleInputs);e.template=t,e.inputs=i,x(e)}function v(e,t,n){let r=new Set,i=[],a=new Map(e.map(e=>[b(e),e]));for(let e of t){let t=b(e);r.add(t);let o=a.get(t);if(o){y(o,e),i.push(o),e.destroy();continue}let s=n.get(t);if(s){y(s,e),i.push(s),n.delete(t),e.destroy();continue}i.push(e)}for(let t of e){let e=b(t);r.has(e)||n.set(e,t)}return{mergedInputs:i}}function y(e,t){if(e.features=t.features,e.existsInAllLayers=t.existsInAllLayers,e instanceof r&&t instanceof r&&e.template.foldIn(t.template),e.type!==`group`||t.type!==`group`)return;let{mergedInputs:n}=v(e.inputs,t.inputs,e.staleInputs);e.inputs=n;for(let t of n)t.group=e}function b(e){return e.type===`group`?l(e.template):e.template.elementId}function x(e){let t=e.allFieldInputs,n=new Set(t.map(e=>e.fieldName));for(let e of t){let t=c(e.inputController)?e.inputController:null,r=t?.otherChoiceFieldName;if(!r)continue;let i=e.layers[0]?.getField(r)?.name??r;n.has(i)&&(t.shouldShowOtherChoice=!1)}}function S(n,c){let{allFeatures:l,expressionsManager:g,getFieldValueOptionsForFeature:_,getExternalErrorForFeature:v,map:y}=c,b=new Set(n.layers),x=l.filter(e=>b.has(e.layer)),C=x.length===l.length;if(u(n))return new r({existsInAllLayers:C,features:x,template:n,expressionsManager:g,getExternalErrorForFeature:v,getFieldValueOptionsForFeature:_});if(d(n)){let e=n.elements.map(e=>S(e,c));return new i({existsInAllLayers:C,features:x,inputs:e,template:n,expressionsManager:g})}if(f(n))return new a({existsInAllLayers:C,features:x,map:y,template:n,expressionsManager:g});if(p(n))return new o({existsInAllLayers:C,features:x,template:n,expressionsManager:g});if(m(n))return new t({existsInAllLayers:C,features:x,template:n,expressionsManager:g});if(h(n))return new s({existsInAllLayers:C,features:x,template:n,expressionsManager:g,map:y});throw new e(`batch-attribute-form:unsupported-element-template`,`The type of form element template provided is not supported`)}export{g as createBatchFormInputsFromBatchFormTemplate,_ as mergeBatchFormInputsFromNewTemplate};
2
+ import e from"../../../../core/Error.js";import t from"../AttachmentElementInput.js";import n from"../BatchFormInputs.js";import r from"../FieldInput.js";import i from"../GroupInput.js";import a from"../RelationshipElementInput.js";import o from"../TextElementInput.js";import s from"../UtilityNetworkAssociationsElementInput.js";import{isMultipleChoiceController as c}from"./controllerUtils.js";import{hashGroupElementTemplateWithoutChildren as l}from"../../templates/support/hashElementTemplate.js";import{isFieldElementTemplate as u,isGroupElementTemplate as d,isRelationshipElementTemplate as f,isTextElementTemplate as p,isAttachmentElementTemplate as m,isUtilityNetworkAssociationsElementTemplate as h}from"../../templates/support/templateUtils.js";function g(e,t){let r=new n({inputs:e.elements.map(e=>S(e,t)),template:e});return x(r),r}function _(e,t,n){let r=g(t,n),{mergedInputs:i}=v(e.inputs,r.inputs,e.staleInputs);e.template=t,e.inputs=i,x(e)}function v(e,t,n){let r=new Set,i=[],a=new Map(e.map(e=>[b(e),e]));for(let e of t){let t=b(e);r.add(t);let o=a.get(t);if(o){y(o,e),i.push(o),e.destroy();continue}let s=n.get(t);if(s){y(s,e),i.push(s),n.delete(t),e.destroy();continue}i.push(e)}for(let t of e){let e=b(t);r.has(e)||n.set(e,t)}return{mergedInputs:i}}function y(e,t){if(e.features=t.features,e.existsInAllLayers=t.existsInAllLayers,e instanceof r&&t instanceof r&&e.template.foldIn(t.template),e.type!==`group`||t.type!==`group`)return;let{mergedInputs:n}=v(e.inputs,t.inputs,e.staleInputs);e.inputs=n;for(let t of n)t.group=e}function b(e){return e.type===`group`?l(e.template):e.template.elementId}function x(e){let t=e.allFieldInputs,n=new Set(t.map(e=>e.fieldName));for(let e of t){let t=c(e.inputController)?e.inputController:null,r=t?.otherChoiceFieldName;if(!r)continue;let i=e.layers[0]?.getField(r)?.name??r;n.has(i)&&(t.shouldShowOtherChoice=!1)}}function S(n,c){let{allFeatures:l,expressionsManager:g,getFieldValueOptionsForFeature:_,getExternalErrorForFeature:v,map:y,requestDeferredExpressionEvaluation:b}=c,x=new Set(n.layers),C=l.filter(e=>x.has(e.layer)),w=C.length===l.length;if(u(n))return new r({existsInAllLayers:w,features:C,template:n,expressionsManager:g,getExternalErrorForFeature:v,getFieldValueOptionsForFeature:_,requestDeferredExpressionEvaluation:b});if(d(n)){let e=n.elements.map(e=>S(e,c));return new i({existsInAllLayers:w,features:C,inputs:e,template:n,expressionsManager:g})}if(f(n))return new a({existsInAllLayers:w,features:C,map:y,template:n,expressionsManager:g});if(p(n))return new o({existsInAllLayers:w,features:C,template:n,expressionsManager:g});if(m(n))return new t({existsInAllLayers:w,features:C,template:n,expressionsManager:g});if(h(n))return new s({existsInAllLayers:w,features:C,template:n,expressionsManager:g,map:y});throw new e(`batch-attribute-form:unsupported-element-template`,`The type of form element template provided is not supported`)}export{g as createBatchFormInputsFromBatchFormTemplate,_ as mergeBatchFormInputsFromNewTemplate};