@arcgis/core 4.28.0-rc.2 → 4.28.0-rc.3

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 (123) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/{0e354096ad8817971eed.js → 02d235849ba93541d7ad.js} +1 -1
  3. package/assets/esri/core/workers/chunks/0422c5160491fbcf01dc.js +1 -0
  4. package/assets/esri/core/workers/chunks/224e79f6c172da444e0a.js +1 -0
  5. package/assets/esri/core/workers/chunks/{ca3d5803cdf035d7389d.js → 30776102fbab294bfe7b.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{61dec8399919b278b636.js → 3ac9001b19a90faf5573.js} +1 -1
  7. package/assets/esri/core/workers/chunks/41081c921037e543a22f.js +1 -0
  8. package/assets/esri/core/workers/chunks/4564a7885d045a850887.js +1 -0
  9. package/assets/esri/core/workers/chunks/4adf3a8c6b49c381a633.js +1 -0
  10. package/assets/esri/core/workers/chunks/{2721aa6b6941b28b9758.js → 63c8bf00120a4e67f5b0.js} +1 -1
  11. package/assets/esri/core/workers/chunks/74951370a341f02d3714.js +1 -0
  12. package/assets/esri/core/workers/chunks/{fa6103e3d4e857b0035b.js → 78e2fa121760383b08ec.js} +9 -6
  13. package/assets/esri/core/workers/chunks/7b8377b3a9f78f9d3613.js +1 -0
  14. package/assets/esri/core/workers/chunks/{fd28400141a6751327ae.js → 7cf7f2b991a7cbdad2ce.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{1a723bb4a341f645e5fe.js → 83b8141f0c80e3448012.js} +1 -1
  16. package/assets/esri/core/workers/chunks/934c32c49bb9e21482fd.js +1 -0
  17. package/assets/esri/core/workers/chunks/969a82b674eda9f8720f.js +1 -0
  18. package/assets/esri/core/workers/chunks/a1e16c33f1843dbdce26.js +1 -0
  19. package/assets/esri/core/workers/chunks/{d07235ce2765a25b9be4.js → a50ec5b647a160199cb2.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{77923afde29ae1ff10ca.js → b6e86e179f99b5cf8dff.js} +1 -1
  21. package/assets/esri/core/workers/chunks/c3ddf5dbc34f118002df.js +1 -0
  22. package/assets/esri/core/workers/chunks/{7b3d5f044c96e2c2af11.js → d191267d91a53db42956.js} +1 -1
  23. package/assets/esri/core/workers/chunks/ffa330a19a09679212fb.js +1 -0
  24. package/assets/esri/themes/base/widgets/_BasemapGallery.scss +3 -9
  25. package/assets/esri/themes/base/widgets/_Legend.scss +1 -1
  26. package/assets/esri/themes/base/widgets/_TimeZoneLabel.scss +3 -3
  27. package/assets/esri/themes/dark/main.css +1 -1
  28. package/assets/esri/themes/light/main.css +1 -1
  29. package/assets/esri/themes/light/view.css +1 -1
  30. package/geometry/support/meshUtils/georeference.js +1 -1
  31. package/interfaces.d.ts +1254 -262
  32. package/kernel.js +1 -1
  33. package/layers/GroupLayer.js +1 -1
  34. package/layers/SceneLayer.js +1 -1
  35. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  36. package/layers/graphics/data/queryValidationUtils.js +1 -1
  37. package/layers/mixins/ArcGISMapService.js +1 -1
  38. package/layers/save/groupLayerUtils.js +1 -1
  39. package/layers/save/utils.js +1 -1
  40. package/layers/support/ImageElement.js +1 -1
  41. package/layers/support/Sublayer.js +1 -1
  42. package/layers/support/Subtype.d.ts +4 -0
  43. package/layers/support/Subtype.js +1 -1
  44. package/layers/support/imageryRendererUtils.js +1 -1
  45. package/networks/Network.js +1 -1
  46. package/package.json +1 -1
  47. package/portal/support/jsonContext.js +1 -1
  48. package/portal/support/layersLoader.js +1 -1
  49. package/rest/featureService/FeatureService.d.ts +4 -0
  50. package/rest/featureService/FeatureService.js +1 -1
  51. package/rest/featureService/utils.d.ts +4 -0
  52. package/rest/query/operations/query.js +1 -1
  53. package/support/basemapUtils.js +1 -1
  54. package/support/revision.js +1 -1
  55. package/versionManagement/VersionManagementService.d.ts +4 -0
  56. package/versionManagement/VersionManagementService.js +1 -1
  57. package/views/2d/engine/vectorTiles/VTLPainter3D.js +1 -1
  58. package/views/2d/engine/webgl/Overlay.js +1 -1
  59. package/views/2d/input/handlers/KeyPan.js +1 -1
  60. package/views/2d/interactive/editingTools/manipulations/DragManipulation.js +1 -1
  61. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  62. package/views/3d/interactive/editingTools/transformGraphic/ExtentTransformTool.js +1 -1
  63. package/views/3d/interactive/visualElements/LineVisualElement.js +1 -1
  64. package/views/3d/layers/I3SMeshView3D.js +1 -1
  65. package/views/3d/layers/MediaLayerView3D.js +1 -1
  66. package/views/3d/layers/SceneLayerWorker.js +1 -1
  67. package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
  68. package/views/3d/layers/graphics/defaultSymbolComplexity.js +1 -1
  69. package/views/3d/layers/graphics/elevationAlignPointsInFeatures.js +1 -1
  70. package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
  71. package/views/3d/support/MemoryController.js +1 -1
  72. package/views/3d/support/PBFDecoder.js +1 -1
  73. package/views/3d/support/ResourceController.js +1 -1
  74. package/views/3d/terrain/OverlayFramebufferObject.js +1 -1
  75. package/views/3d/webgl-engine/core/FBOCache.js +1 -1
  76. package/views/3d/webgl-engine/core/FBOPool.js +5 -0
  77. package/views/3d/webgl-engine/core/shaderLibrary/attributes/InstancedDoublePrecision.glsl.js +9 -6
  78. package/views/3d/webgl-engine/effects/ssao/SSAO.js +1 -1
  79. package/views/3d/webgl-engine/lib/Camera.js +1 -1
  80. package/views/3d/webgl-engine/lib/OffscreenRendering.js +1 -1
  81. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  82. package/views/3d/webgl-engine/lib/Texture.js +1 -1
  83. package/views/3d/webgl-engine/lib/textureUtils.js +1 -1
  84. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  85. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  86. package/views/3d/webgl-engine/parts/ScreenshotManager.js +1 -1
  87. package/views/3d/webgl-engine/shaders/sources/edgeRenderer/EdgeUtil.glsl.js +1 -1
  88. package/views/draw/DrawOperation.js +1 -1
  89. package/views/draw/support/Reshape.js +1 -1
  90. package/views/interactive/snapping/FeatureSnappingEngine.js +1 -1
  91. package/views/interactive/snapping/featureSources/FeatureCollectionSnappingSource.js +1 -1
  92. package/views/interactive/snapping/featureSources/GraphicsSnappingSource.js +1 -1
  93. package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceSnappingSourceWorker.js +1 -1
  94. package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceSnappingSourceWorkerHandle.js +1 -1
  95. package/views/interactive/snapping/featureSources/snappingCandidateElevationAlignment.js +1 -1
  96. package/widgets/BasemapGallery.js +1 -1
  97. package/widgets/DirectionalPad.js +1 -1
  98. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  99. package/widgets/Editor/EditorViewModel.js +1 -1
  100. package/widgets/Editor/UpdateWorkflow.js +1 -1
  101. package/widgets/Editor/workflowUtils.js +1 -1
  102. package/widgets/FeatureForm.js +1 -1
  103. package/widgets/Features.js +1 -1
  104. package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
  105. package/widgets/OrientedImageryViewer.js +1 -1
  106. package/widgets/TimeSlider.js +1 -1
  107. package/widgets/TimeZoneLabel.js +1 -1
  108. package/widgets/UtilityNetworkTrace/UtilityNetworkTraceViewModel.js +1 -1
  109. package/widgets/UtilityNetworkTrace.js +1 -1
  110. package/assets/esri/core/workers/chunks/00da3c16741a9bc47f3a.js +0 -1
  111. package/assets/esri/core/workers/chunks/0e4646d14fa0775bf463.js +0 -1
  112. package/assets/esri/core/workers/chunks/4e0bf30da4281070e453.js +0 -1
  113. package/assets/esri/core/workers/chunks/51b8913dff24e693bd25.js +0 -1
  114. package/assets/esri/core/workers/chunks/5e907ec0ee1565b5fbbc.js +0 -1
  115. package/assets/esri/core/workers/chunks/7388fd97e7b1a2142744.js +0 -1
  116. package/assets/esri/core/workers/chunks/92d8f75e616afa5c761e.js +0 -1
  117. package/assets/esri/core/workers/chunks/a877a4826cd6a46ec99b.js +0 -1
  118. package/assets/esri/core/workers/chunks/b251d8a856dc8b9406e0.js +0 -1
  119. package/assets/esri/core/workers/chunks/d8c696da42f8f8919b83.js +0 -1
  120. package/assets/esri/core/workers/chunks/fac3e57784d7f37053af.js +0 -1
  121. package/assets/esri/core/workers/chunks/fc95b1a36ed68b851400.js +0 -1
  122. package/widgets/DirectionalPad/DirectionalPadViewModel.d.ts +0 -4
  123. package/widgets/DirectionalPad.d.ts +0 -4
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import{createTask as t}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import{deprecated as r}from"../../core/deprecate.js";import i from"../../core/Error.js";import s from"../../core/Evented.js";import{makeHandle as o}from"../../core/handleUtils.js";import n from"../../core/Logger.js";import{abortMaybe as l}from"../../core/maybe.js";import{throwIfAborted as d}from"../../core/promiseUtils.js";import{watch as p,on as c,when as u,whenOnce as h,syncAndInitial as w,initial as f}from"../../core/reactiveUtils.js";import{property as m}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as k}from"../../core/support/UpdatingHandles.js";import v from"../../layers/GraphicsLayer.js";import{isEditableLayer as g}from"../../layers/support/editableLayers.js";import{isTable as W,getOwningPortalUrl as _,getEffectiveLayerCapabilities as b,isFeatureLayer as F}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as C}from"../../portal/support/urlUtils.js";import E from"../Attachments/AttachmentsViewModel.js";import I from"./CreateFeaturesWorkflow.js";import U from"./CreateWorkflow.js";import{workflowDeprecation as A}from"./deprecationUtils.js";import M from"./UpdateWorkflow.js";import{whenEditorLayerView as T}from"./workflowUtils.js";import{formTemplateHasInvalidFields as V}from"../FeatureForm/featureFormUtils.js";import O from"../FeatureForm/FeatureFormViewModel.js";import j from"../FeatureTemplates/FeatureTemplatesViewModel.js";import L from"../Sketch/SketchViewModel.js";import S from"../Spinner/SpinnerViewModel.js";const P="esri.widgets.Editor.EditorViewModel",D=n.getLogger(P),x=["create","create-features","update"];function G(e,t,a){D.error(new i(e,t,a))}function H(e,t){return e?e.find((e=>e.layer===t)):void 0}let N=class extends s.EventedAccessor{constructor(e){super(e),this._editableItems=new a,this._sketchGraphicsLayer=new v({listMode:"hide",internal:!0}),this._updateEditableItemsTask=null,this._updatingHandles=new k,this._featureTemplatesViewModelLocked=!1,this._syncFeatureTemplatesOnNextUnlock=!1,this.activeWorkflow=null,this._activityQueue=[],this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new E({capabilities:{editing:!0}}),this.featureFormViewModel=new O,this.featureTemplatesViewModel=new j({disabledItemFunction:({layer:e})=>this._itemIsSuspended(e)}),this.sketchViewModel=new L({layer:this._sketchGraphicsLayer}),this.spinnerViewModel=new S,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.useDeprecatedCreateWorkflow=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:e}=this;if(e.submit(),!e.submittable)return;const t=e.getValues();e.validateContingencyConstraints(t,{includeIncompleteViolations:!0}).length>0||await(this.activeWorkflow?.save())},this.selectFeature=(e,t=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=e,t&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([p((()=>{const e=this.view?.map?.editableLayers.filter((({parent:e,visible:t})=>e&&"visible"in e?t&&e.visible:t)),t=this.view?.allLayerViews,a=t?.filter((t=>!!e?.includes(t.layer)&&!t.suspended));return[e,a,this.layerInfos,this.allowedWorkflows,this.hideTemplatesForInactiveLayers]}),(()=>this._updateEditableItems()),w),c((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),c((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),c((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),u((()=>this.view?.map),(e=>e.add(this._sketchGraphicsLayer)),f),p((()=>this.view?.timeZone),(e=>this.featureFormViewModel.timeZone=e)),p((()=>this._editableItems.toArray()),(()=>{const{activeWorkflow:e}=this;if(this.syncFeatureTemplates(),!e)return;const{stepId:t}=e;"create"!==e.type?"update"===e.type&&("awaiting-feature-to-update"===t&&!this.canUpdate||"awaiting-update-feature-candidate"===t&&!e.data.candidates.some((e=>{const t=this._editableItems.find((t=>t.layer===e.layer));return t&&t.supports.includes("update")})))&&this._cancelWorkflow():"awaiting-feature-creation-info"!==t||this.canCreate||this._cancelWorkflow()})),p((()=>this.page),((e,t)=>{const a=[...this.pageStack];if(-1===a.indexOf(e))a.push(e);else for(;a.length&&a.at(-1)!==e;)a.pop();this.pageStack=a}),w),u((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),c((()=>this.featureTemplatesViewModel),"select",(async({item:e,oldItem:t})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(t,{emit:!1})}}if(!e)return;const r={layer:e.layer,template:e.template};if(e.supportsUpload)return this.featureTemplatesViewModel.select(t,{emit:!1}),this.startCreateFeaturesWorkflow(r);this.useDeprecatedCreateWorkflow?this.startCreateWorkflowAtFeatureCreation(r):this.startCreateFeaturesWorkflowAtFeatureCreation(r)})),c((()=>this.view),"key-down",(e=>{"Escape"===e.key&&this.activeWorkflow?.keyboardCancellationEnabled&&this.back()}))])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateEditableItemsTask=l(this._updateEditableItemsTask),this._updatingHandles.destroy()}get allowedWorkflows(){return this._get("allowedWorkflows")}set allowedWorkflows(e){e&&0!==e.length||(e=[...x]),this._set("allowedWorkflows",e)}get canCreate(){return this._editableItems.some((e=>e.supports.includes("create")&&!e.suspended))}get canUpdate(){return this._editableItems.some((({attachmentsOnUpdateEnabled:e,layer:t,supports:a,suspended:r})=>{const i=!r&&(a.includes("update")||a.includes("delete")||e),s=t.parent,o=!(s&&"visible"in s)||!!s.visible;return t.visible&&o&&i}))}get editableItems(){return this._editableItems}get labelOptions(){return this.sketchViewModel.labelOptions}set labelOptions(e){this.sketchViewModel.labelOptions=e}set layerInfos(e){e?.some((e=>("allowAttachments"in e&&r(D,"Property: layerInfo.allowAttachments",{replacement:"layerInfo.attachmentsOnCreateEnabled or layerInfo.attachmentsOnUpdateEnabled",version:"4.26"}),!0))),this._set("layerInfos",e)}get snappingOptions(){return this.sketchViewModel.snappingOptions}set snappingOptions(e){this.sketchViewModel.snappingOptions=e}get state(){if(!this.view?.ready)return"disabled";const e=this.attachmentsViewModel.mode;if("add"===e)return"adding-attachment";if("edit"===e)return"editing-attachment";const{activeWorkflow:t}=this;return t?"update"===t.type&&t.activeWorkflow?.stepId?t.activeWorkflow.stepId:t.stepId:"ready"}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchViewModel.tooltipOptions}set tooltipOptions(e){this.sketchViewModel.tooltipOptions=e}set view(e){this.sketchViewModel.view=e,this.spinnerViewModel.view=e,this._set("view",e)}get page(){const{activeWorkflow:e,state:t}=this;if("update"===e?.type&&"awaiting-feature-to-update"===e.stepId)return"ready";if("create-features"===e?.type&&0===e.numPendingFeatures){const t=e.data.upload;if(t)return"default"===t.state?"ready":"creating-features-upload-details"}return t??"disabled"}get featureFormDisabled(){const{activeWorkflow:e}=this;return"update"===e?.type&&!1===e.activeEditableItem?.attributeUpdatesEnabled}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:e}=this;return!!e&&"update"===e.type&&!!e.activeEditableItem?.supports.includes("delete")}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}async startCreateWorkflowAtFeatureTypeSelection(){if(A(D,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),await h((()=>!this.updating)),!this.canCreate)return void G("editing:unsupported-workflow","Create workflow is unsupported or disabled.");await this._cancelWorkflow();const e=this._createCreateWorkflow();await e.start(),this._set("activeWorkflow",e)}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateWorkflowAtFeatureCreation(e){if(A(D,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),await h((()=>!this.updating)),!this.canCreate)return void G("editing:unsupported-workflow","Create workflow is unsupported or disabled.");await this._cancelWorkflow();const t=this._createCreateWorkflow("awaiting-feature-to-create");t.data.creationInfo=e,await t.start(),this._set("activeWorkflow",t)}async startCreateFeaturesWorkflowAtFeatureCreation(e){return this.startCreateFeaturesWorkflow(e,"creating-features")}async startCreateFeaturesWorkflow(e,t="awaiting-feature-creation-info"){if(await h((()=>!this.updating)),!this.canCreate)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");await this._cancelWorkflow();const a=this._createCreateFeaturesWorkflow(e,t);await a.start(),this._set("activeWorkflow",a)}async startCreateWorkflowAtFeatureEdit(e){if(A(D,"startCreateWorkflowAtFeatureEdit"),await h((()=>!this.updating)),!this.canCreate)return void G("editing:unsupported-workflow","Create workflow is unsupported or disabled.");await this._cancelWorkflow();const t=this._createCreateWorkflow("editing-new-feature");t.data.edits.feature=e,await t.start(),this._set("activeWorkflow",t)}async startCreateFeaturesWorkflowAtFeatureEdit(e){await h((()=>!this.updating));const{initialFeature:t}=e,a=t.sourceLayer,r=a?this.findEditableItemForLayer(a):void 0;if(!this.canCreate||!r)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");await this._cancelWorkflow();const s=this._createCreateFeaturesWorkflow({initialFeature:t,layer:r.layer,maxFeatures:1},"creating-features");await s.start(),this._set("activeWorkflow",s)}async startUpdateWorkflowAtFeatureSelection(){if(await h((()=>!this.updating)),!this.canUpdate)return void G("editing:unsupported-workflow","Update workflow is unsupported or disabled.");await this._cancelWorkflow();const e=this._createUpdateWorkflow();await e.start(),this._set("activeWorkflow",e)}async startUpdateWorkflowAtMultipleFeatureSelection(e){if(await h((()=>!this.updating)),!this.canUpdate)return void G("editing:unsupported-workflow","Update workflow is unsupported or disabled.");await this._cancelWorkflow();const t=this._createUpdateWorkflow("awaiting-update-feature-candidate");t.data.candidates=e,await t.start(),this._set("activeWorkflow",t)}async startUpdateWorkflowAtFeatureEdit(e){if(await h((()=>!this.updating)),!this.canUpdate)return void G("editing:unsupported-workflow","Update workflow is unsupported or disabled.");await this._cancelWorkflow();const t=this._createUpdateWorkflow("editing-existing-feature");t.data.rootFeature=e,await t.start(),this._set("activeWorkflow",t)}async deleteFeatureFromWorkflow(){const{activeWorkflow:e}=this;e&&"update"===e.type?await e.deleteActiveFeature():G("editing:unsupported-workflow","Deleting requires an active update workflow.")}async cancelWorkflow(e){return this._cancelWorkflow({warnIfNoWorkflow:!0,...e})}findEditableItemForLayer(e){const t="subtype-sublayer"===e.type?e.parent:e;return this._editableItems.find((e=>e.layer===t))}itemHasInvalidFormTemplate(e){return!!e&&(this.findEditableItemForLayer(e.layer)?.hasInvalidFormTemplate??!1)}itemHasUnsupportedFields(e){return!!e&&(this.findEditableItemForLayer(e.layer)?.hasUnsupportedFields??!1)}syncFeatureTemplates(){if(this._featureTemplatesViewModelLocked)return void(this._syncFeatureTemplatesOnNextUnlock=!0);const e=[];for(const{layer:t,supports:a}of this._editableItems)t.loaded&&a.includes("create")&&!W(t)&&e.push(t);this.featureTemplatesViewModel.layers=e}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}lockFeatureTemplatesViewModel(){return this._featureTemplatesViewModelLocked=!0,o((()=>{this._featureTemplatesViewModelLocked=!1,this._syncFeatureTemplatesOnNextUnlock&&(this.syncFeatureTemplates(),this._syncFeatureTemplatesOnNextUnlock=!1)}))}async _updateEditableItems(){l(this._updateEditableItemsTask);const e=t((async e=>{const t=this.view?.allLayerViews,r=this.view?.map,i=r?.editableLayers.toArray()??[],s=r?.allTables.toArray().filter(F)??[];await Promise.allSettled(s.map((e=>e.load())));const o=s.filter((e=>g(e))),n=[...i.reverse(),...o.reverse()].filter((e=>"mesh"!==e.geometryType||"3d"===this.view?.type));if(!t||!i)return;const l=[],p=[];for(const a of n){const r=t.find((e=>e.layer===a)),i=r?l:p,s=!!r?.suspended;if(!s||!this.hideTemplatesForInactiveLayers)if("subtype-group"===a.type){await a.loadAll(),d(e);for(let e=a.sublayers.length-1;e>=0;--e)i.push(this._makeEditableItemForLayer(a.sublayers.at(e),s))}else i.push(this._makeEditableItemForLayer(a,s))}if(e.aborted)return;const c=this._editableItems;this._editableItems=new a(l.concat(p)),c.destroy()}));this._updatingHandles.addPromise(e.promise),this._updateEditableItemsTask=e}async _cancelWorkflow(e){const t=this.activeWorkflow;if(!t)return void(e?.warnIfNoWorkflow&&G("editing:no-active-workflow","There is no active workflow to cancel."));if(!e||!1!==e.force)return this.emit("workflow-cancel"),this._set("activeWorkflow",null),void await t.cancel(e);await t.cancel(e),this._set("activeWorkflow",null)}_createCreateFeaturesWorkflow(e,t){return I.create({viewModel:this,creationInfo:e,startAt:t,applyEditsCallback:(e,t,a)=>this._applyEdits(e,t,a),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)})}_createCreateWorkflow(e){return U.create(this,e,((e,t,a)=>this._applyEdits(e,t,a)))}_createUpdateWorkflow(e){return M.create({viewModel:this,startAt:e,applyEditsCallback:(e,t,a)=>this._applyEdits(e,t,a),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)})}_addAttachments(e,t){const a=t.map((t=>this._addAttachment(e,t.feature,t.attachment)))??[];return Promise.all(a)}async _addAttachment(e,t,a){let r=null;if("geojson"===e.type||"scene"===e.type||"oriented-imagery"===e.type)throw new i("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(e.addAttachment?.(t,a).catch((e=>{throw e?.error||e})))??null,r))),r}async _applyEdits(e,t,a){let r=null;const i=e.url?await _(e.url):null,s={returnServiceEditsOption:(!i||!C(i))&&!RegExp("/hosted/","i").test(e.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const i=await T(a,e).catch((()=>null));return r=await e.applyEdits(t,s),i&&await h((()=>!i.updating)),r})),r}_queueOperation(e){this._activityQueue.push(e),this.notifyChange("syncing");const t=(e,t)=>{const a=t.indexOf(e);a>-1&&t.splice(a,1)};return e().then((e=>{if(null!=e&&"error"in e&&null!=e.error)throw e.error;if(null!=e&&"addFeatureResults"in e){const{addFeatureResults:t,deleteFeatureResults:a,updateFeatureResults:r}=e,i=t.find((e=>!!e.error))||r.find((e=>!!e.error))||a.find((e=>!!e.error));if(i)throw i.error}return e})).catch((a=>{G("editing:operation-error","An error occurred.",{error:a});const r={error:a,retry:()=>(t(r,this.failures),this._queueOperation(e)),cancel:()=>{t(r,this.failures)}};this._set("failures",[...this.failures,r])})).then((()=>{t(e,this._activityQueue),this.notifyChange("syncing")}))}_makeEditableItemForLayer(e,t=!0){const a=b(e),r=a?.operations,i=H(this.layerInfos,e),s=V(e),o=s||t,{allowedWorkflows:n}=this,l=n.includes("create")||n.includes("create-features"),d=n.includes("update"),p=e=>!i||!1!==i.enabled&&!1!==i[e],c=l&&!!r?.supportsAdd&&p("addEnabled"),u=d&&!!r?.supportsUpdate&&p("updateEnabled"),h=!o&&d&&!!r?.supportsDelete&&p("deleteEnabled"),w=[];c&&w.push("create"),u&&w.push("update"),h&&w.push("delete");const f=u&&!o&&(!i||!1!==i.attributeUpdatesEnabled),m=u&&!o&&!!a?.editing?.supportsGeometryUpdate&&(!i||!1!==i.geometryUpdatesEnabled),y=!(!a?.data?.supportsAttachment||i&&!1===i.allowAttachments);return{layer:e,supports:w,suspended:t,attributeUpdatesEnabled:f,geometryUpdatesEnabled:m,hasAttachments:y,attachmentsOnCreateEnabled:y&&l&&(!i||!1!==i.attachmentsOnCreateEnabled),attachmentsOnUpdateEnabled:!o&&y&&(!i||!1!==i.attachmentsOnUpdateEnabled),hasInvalidFormTemplate:s,hasUnsupportedFields:!1}}_itemIsSuspended(e){return this.findEditableItemForLayer(e)?.suspended??!1}};e([m()],N.prototype,"_editableItems",void 0),e([m({readOnly:!0})],N.prototype,"activeWorkflow",void 0),e([m({readOnly:!0})],N.prototype,"_activityQueue",void 0),e([m({value:[...x]})],N.prototype,"allowedWorkflows",null),e([m({readOnly:!0})],N.prototype,"canCreate",null),e([m({readOnly:!0})],N.prototype,"canUpdate",null),e([m()],N.prototype,"editableItems",null),e([m({readOnly:!0})],N.prototype,"failures",void 0),e([m()],N.prototype,"hideTemplatesForInactiveLayers",void 0),e([m()],N.prototype,"attachmentsViewModel",void 0),e([m()],N.prototype,"featureFormViewModel",void 0),e([m()],N.prototype,"featureTemplatesViewModel",void 0),e([m()],N.prototype,"labelOptions",null),e([m()],N.prototype,"layerInfos",null),e([m()],N.prototype,"sketchViewModel",void 0),e([m()],N.prototype,"snappingOptions",null),e([m()],N.prototype,"spinnerViewModel",void 0),e([m()],N.prototype,"state",null),e([m({readOnly:!0})],N.prototype,"syncing",null),e([m()],N.prototype,"updating",null),e([m()],N.prototype,"tooltipOptions",null),e([m()],N.prototype,"view",null),e([m()],N.prototype,"pageStack",void 0),e([m()],N.prototype,"showDiscardEditsPrompt",void 0),e([m()],N.prototype,"_candidateCommitted",void 0),e([m()],N.prototype,"page",null),e([m()],N.prototype,"featureFormDisabled",null),e([m()],N.prototype,"canGoBack",null),e([m()],N.prototype,"shouldShowDeleteButton",null),e([m()],N.prototype,"hasPendingEdits",null),e([m()],N.prototype,"useDeprecatedCreateWorkflow",void 0),N=e([y(P)],N);const q=N;export{q as default};
5
+ import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import{deprecated as r}from"../../core/deprecate.js";import i from"../../core/Error.js";import s from"../../core/Evented.js";import{makeHandle as o}from"../../core/handleUtils.js";import n from"../../core/Logger.js";import{abortMaybe as l}from"../../core/maybe.js";import{throwIfAborted as d}from"../../core/promiseUtils.js";import{watch as p,on as c,when as u,whenOnce as h,syncAndInitial as w,initial as f}from"../../core/reactiveUtils.js";import{property as m}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as k}from"../../core/support/UpdatingHandles.js";import v from"../../layers/GraphicsLayer.js";import{isEditableLayer as g}from"../../layers/support/editableLayers.js";import{isTable as W,getOwningPortalUrl as _,getEffectiveLayerCapabilities as b,isFeatureLayer as F}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as C}from"../../portal/support/urlUtils.js";import E from"../Attachments/AttachmentsViewModel.js";import I from"./CreateFeaturesWorkflow.js";import U from"./CreateWorkflow.js";import{workflowDeprecation as A}from"./deprecationUtils.js";import M from"./UpdateWorkflow.js";import{whenEditorLayerView as T}from"./workflowUtils.js";import{formTemplateHasInvalidFields as V}from"../FeatureForm/featureFormUtils.js";import O from"../FeatureForm/FeatureFormViewModel.js";import j from"../FeatureTemplates/FeatureTemplatesViewModel.js";import L from"../Sketch/SketchViewModel.js";import S from"../Spinner/SpinnerViewModel.js";const P="esri.widgets.Editor.EditorViewModel",D=n.getLogger(P),x=["create","create-features","update"];function G(t,e,a){D.error(new i(t,e,a))}function H(t,e){return t?t.find((t=>t.layer===e)):void 0}let N=class extends s.EventedAccessor{constructor(t){super(t),this._editableItems=new a,this._sketchGraphicsLayer=new v({listMode:"hide",internal:!0}),this._updateEditableItemsTask=null,this._updatingHandles=new k,this._featureTemplatesViewModelLocked=!1,this._syncFeatureTemplatesOnNextUnlock=!1,this.activeWorkflow=null,this._activityQueue=[],this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new E({capabilities:{editing:!0}}),this.featureFormViewModel=new O,this.featureTemplatesViewModel=new j({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.sketchViewModel=new L({layer:this._sketchGraphicsLayer}),this.spinnerViewModel=new S,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.useDeprecatedCreateWorkflow=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t.submit(),!t.submittable)return;const e=t.getValues();t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0||await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([p((()=>{const t=this.view?.map?.editableLayers.filter((({parent:t,visible:e})=>t&&"visible"in t?e&&t.visible:e)),e=this.view?.allLayerViews,a=e?.filter((e=>!!t?.includes(e.layer)&&!e.suspended));return[t,a,this.layerInfos,this.allowedWorkflows,this.hideTemplatesForInactiveLayers]}),(()=>this._updateEditableItems()),w),c((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),c((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),c((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),u((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),f),p((()=>this.view?.timeZone),(t=>this.featureFormViewModel.timeZone=t)),p((()=>this._editableItems.toArray()),(()=>{const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdate||"awaiting-update-feature-candidate"===e&&!t.data.candidates.some((t=>{const e=this._editableItems.find((e=>e.layer===t.layer));return e&&e.supports.includes("update")})))&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()})),p((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),w),u((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),c((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const r={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(r);this.useDeprecatedCreateWorkflow?this.startCreateWorkflowAtFeatureCreation(r):this.startCreateFeaturesWorkflowAtFeatureCreation(r)})),c((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())}))])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateEditableItemsTask=l(this._updateEditableItemsTask),this._updatingHandles.destroy()}get allowedWorkflows(){return this._get("allowedWorkflows")}set allowedWorkflows(t){t&&0!==t.length||(t=[...x]),this._set("allowedWorkflows",t)}get canCreate(){return this._editableItems.some((t=>t.supports.includes("create")&&!t.suspended))}get canUpdate(){return this._editableItems.some((({attachmentsOnUpdateEnabled:t,layer:e,supports:a,suspended:r})=>{const i=!r&&(a.includes("update")||a.includes("delete")||t),s=e.parent,o=!(s&&"visible"in s)||!!s.visible;return e.visible&&o&&i}))}get editableItems(){return this._editableItems}get labelOptions(){return this.sketchViewModel.labelOptions}set labelOptions(t){this.sketchViewModel.labelOptions=t}set layerInfos(t){t?.some((t=>("allowAttachments"in t&&r(D,"Property: layerInfo.allowAttachments",{replacement:"layerInfo.attachmentsOnCreateEnabled or layerInfo.attachmentsOnUpdateEnabled",version:"4.26"}),!0))),this._set("layerInfos",t)}get snappingOptions(){return this.sketchViewModel.snappingOptions}set snappingOptions(t){this.sketchViewModel.snappingOptions=t}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchViewModel.tooltipOptions}set tooltipOptions(t){this.sketchViewModel.tooltipOptions=t}set view(t){this.sketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditableItem?.attributeUpdatesEnabled}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditableItem?.supports.includes("delete")}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}async startCreateWorkflowAtFeatureTypeSelection(){if(A(D,"startCreateWorkflowAtFeatureTypeSelection","startCreateFeaturesWorkflowAtFeatureTypeSelection"),await h((()=>!this.updating)),!this.canCreate)return void G("editing:unsupported-workflow","Create workflow is unsupported or disabled.");await this._cancelWorkflow();const t=this._createCreateWorkflow();await t.start(),this._set("activeWorkflow",t)}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateWorkflowAtFeatureCreation(t){if(A(D,"startCreateWorkflowAtFeatureCreation","startCreateFeaturesWorkflowAtFeatureCreation"),await h((()=>!this.updating)),!this.canCreate)return void G("editing:unsupported-workflow","Create workflow is unsupported or disabled.");await this._cancelWorkflow();const e=this._createCreateWorkflow("awaiting-feature-to-create");e.data.creationInfo=t,await e.start(),this._set("activeWorkflow",e)}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await h((()=>!this.updating)),!this.canCreate)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");await this._cancelWorkflow();const a=this._createCreateFeaturesWorkflow(t,e);await a.start(),this._set("activeWorkflow",a)}async startCreateWorkflowAtFeatureEdit(t){if(A(D,"startCreateWorkflowAtFeatureEdit"),await h((()=>!this.updating)),!this.canCreate)return void G("editing:unsupported-workflow","Create workflow is unsupported or disabled.");await this._cancelWorkflow();const e=this._createCreateWorkflow("editing-new-feature");e.data.edits.feature=t,await e.start(),this._set("activeWorkflow",e)}async startCreateFeaturesWorkflowAtFeatureEdit(t){await h((()=>!this.updating));const{initialFeature:e}=t,a=e.sourceLayer,r=a?this.findEditableItemForLayer(a):void 0;if(!this.canCreate||!r)throw new i("editing:unsupported-workflow","Creating features is unsupported or disabled.");await this._cancelWorkflow();const s=this._createCreateFeaturesWorkflow({initialFeature:e,layer:r.layer,maxFeatures:1},"creating-features");await s.start(),this._set("activeWorkflow",s)}async startUpdateWorkflowAtFeatureSelection(){if(await h((()=>!this.updating)),!this.canUpdate)return void G("editing:unsupported-workflow","Update workflow is unsupported or disabled.");await this._cancelWorkflow();const t=this._createUpdateWorkflow();await t.start(),this._set("activeWorkflow",t)}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await h((()=>!this.updating)),!this.canUpdate)return void G("editing:unsupported-workflow","Update workflow is unsupported or disabled.");await this._cancelWorkflow();const e=this._createUpdateWorkflow("awaiting-update-feature-candidate");e.data.candidates=t,await e.start(),this._set("activeWorkflow",e)}async startUpdateWorkflowAtFeatureEdit(t){if(await h((()=>!this.updating)),!this.canUpdate)return void G("editing:unsupported-workflow","Update workflow is unsupported or disabled.");await this._cancelWorkflow();const e=this._createUpdateWorkflow("editing-existing-feature");e.data.rootFeature=t,await e.start(),this._set("activeWorkflow",e)}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():G("editing:unsupported-workflow","Deleting requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditableItemForLayer(t){const e="subtype-sublayer"===t.type?t.parent:t;return this._editableItems.find((t=>t.layer===e))}itemHasInvalidFormTemplate(t){return!!t&&(this.findEditableItemForLayer(t.layer)?.hasInvalidFormTemplate??!1)}itemHasUnsupportedFields(t){return!!t&&(this.findEditableItemForLayer(t.layer)?.hasUnsupportedFields??!1)}syncFeatureTemplates(){if(this._featureTemplatesViewModelLocked)return void(this._syncFeatureTemplatesOnNextUnlock=!0);const t=[];for(const{layer:e,supports:a}of this._editableItems)e.loaded&&a.includes("create")&&!W(e)&&t.push(e);this.featureTemplatesViewModel.layers=t}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}lockFeatureTemplatesViewModel(){return this._featureTemplatesViewModelLocked=!0,o((()=>{this._featureTemplatesViewModelLocked=!1,this._syncFeatureTemplatesOnNextUnlock&&(this.syncFeatureTemplates(),this._syncFeatureTemplatesOnNextUnlock=!1)}))}async _updateEditableItems(){l(this._updateEditableItemsTask);const t=e((async t=>{const e=this.view?.allLayerViews,r=this.view?.map,i=r?.editableLayers.toArray()??[],s=r?.allTables.toArray().filter(F)??[];await Promise.allSettled(s.map((t=>t.load())));const o=s.filter((t=>g(t))),n=[...i.reverse(),...o.reverse()].filter((t=>"mesh"!==t.geometryType||"3d"===this.view?.type));if(!e||!i)return;const l=[],p=[];for(const a of n){const r=e.find((t=>t.layer===a)),i=r?l:p,s=!!r?.suspended;if(!s||!this.hideTemplatesForInactiveLayers)if("subtype-group"===a.type){await a.loadAll(),d(t);for(let t=a.sublayers.length-1;t>=0;--t)i.push(this._makeEditableItemForLayer(a.sublayers.at(t),s))}else i.push(this._makeEditableItemForLayer(a,s))}if(t.aborted)return;const c=this._editableItems;this._editableItems=new a(l.concat(p)),c.destroy()}));this._updatingHandles.addPromise(t.promise),this._updateEditableItemsTask=t}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&G("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force)return this.emit("workflow-cancel"),this._set("activeWorkflow",null),void await e.cancel(t);await e.cancel(t),this._set("activeWorkflow",null)}_createCreateFeaturesWorkflow(t,e){return I.create({viewModel:this,creationInfo:t,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createCreateWorkflow(t){return U.create(this,t,((t,e,a)=>this._applyEdits(t,e,a)))}_createUpdateWorkflow(t){return M.create({viewModel:this,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let r=null;if("geojson"===t.type||"scene"===t.type||"oriented-imagery"===t.type)throw new i("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,r))),r}async _applyEdits(t,e,a){let r=null;const i=t.url?await _(t.url):null,s={returnServiceEditsOption:(!i||!C(i))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const i=await T(a,t).catch((()=>null));return r=await t.applyEdits(e,s),i&&await h((()=>!i.updating)),r})),r}_queueOperation(t){this._activityQueue.push(t),this.notifyChange("syncing");const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>{if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:r}=t,i=e.find((t=>!!t.error))||r.find((t=>!!t.error))||a.find((t=>!!t.error));if(i)throw i.error}return t})).catch((a=>{G("editing:operation-error","An error occurred.",{error:a});const r={error:a,retry:()=>(e(r,this.failures),this._queueOperation(t)),cancel:()=>{e(r,this.failures)}};this._set("failures",[...this.failures,r])})).then((()=>{e(t,this._activityQueue),this.notifyChange("syncing")}))}_makeEditableItemForLayer(t,e=!0){const a=b(t),r=a?.operations,i=H(this.layerInfos,t),s=V(t),o=s||e,{allowedWorkflows:n}=this,l=n.includes("create")||n.includes("create-features"),d=n.includes("update"),p=t=>!i||!1!==i.enabled&&!1!==i[t],c=l&&!!r?.supportsAdd&&p("addEnabled"),u=d&&!!r?.supportsUpdate&&p("updateEnabled"),h=!o&&d&&!!r?.supportsDelete&&p("deleteEnabled"),w=[];c&&w.push("create"),u&&w.push("update"),h&&w.push("delete");const f=u&&!o&&(!i||!1!==i.attributeUpdatesEnabled),m=u&&!o&&!!a?.editing?.supportsGeometryUpdate&&(!i||!1!==i.geometryUpdatesEnabled),y=!(!a?.data?.supportsAttachment||i&&!1===i.allowAttachments);return{layer:t,supports:w,suspended:e,attributeUpdatesEnabled:f,geometryUpdatesEnabled:m,hasAttachments:y,attachmentsOnCreateEnabled:y&&l&&(!i||!1!==i.attachmentsOnCreateEnabled),attachmentsOnUpdateEnabled:!o&&y&&(!i||!1!==i.attachmentsOnUpdateEnabled),hasInvalidFormTemplate:s,hasUnsupportedFields:!1}}_itemIsSuspended(t){return this.findEditableItemForLayer(t)?.suspended??!1}};t([m()],N.prototype,"_editableItems",void 0),t([m({readOnly:!0})],N.prototype,"activeWorkflow",void 0),t([m({readOnly:!0})],N.prototype,"_activityQueue",void 0),t([m({value:[...x]})],N.prototype,"allowedWorkflows",null),t([m({readOnly:!0})],N.prototype,"canCreate",null),t([m({readOnly:!0})],N.prototype,"canUpdate",null),t([m()],N.prototype,"editableItems",null),t([m({readOnly:!0})],N.prototype,"failures",void 0),t([m()],N.prototype,"hideTemplatesForInactiveLayers",void 0),t([m()],N.prototype,"attachmentsViewModel",void 0),t([m()],N.prototype,"featureFormViewModel",void 0),t([m()],N.prototype,"featureTemplatesViewModel",void 0),t([m()],N.prototype,"labelOptions",null),t([m()],N.prototype,"layerInfos",null),t([m()],N.prototype,"sketchViewModel",void 0),t([m()],N.prototype,"snappingOptions",null),t([m()],N.prototype,"spinnerViewModel",void 0),t([m()],N.prototype,"state",null),t([m({readOnly:!0})],N.prototype,"syncing",null),t([m()],N.prototype,"updating",null),t([m()],N.prototype,"tooltipOptions",null),t([m()],N.prototype,"view",null),t([m()],N.prototype,"pageStack",void 0),t([m()],N.prototype,"showDiscardEditsPrompt",void 0),t([m()],N.prototype,"_candidateCommitted",void 0),t([m()],N.prototype,"page",null),t([m()],N.prototype,"featureFormDisabled",null),t([m()],N.prototype,"canGoBack",null),t([m()],N.prototype,"shouldShowDeleteButton",null),t([m()],N.prototype,"hasPendingEdits",null),t([m()],N.prototype,"useDeprecatedCreateWorkflow",void 0),N=t([y(P)],N);const q=N;export{q as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as o}from"../../core/handleUtils.js";import r from"../../core/Logger.js";import{abortMaybe as i}from"../../core/maybe.js";import{onAbort as s,createAbortError as n,throwIfAborted as l,debounce as d}from"../../core/promiseUtils.js";import c from"../../core/Queue.js";import{whenOnce as p,watch as u,sync as w}from"../../core/reactiveUtils.js";import{last as h}from"../../core/SetUtils.js";import{property as f}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as m}from"../../core/accessorSupport/decorators/subclass.js";import{isEditableLayer as k}from"../../layers/support/editableLayers.js";import{isSubtypeGroupLayer as g,isTable as v}from"../../layers/support/layerUtils.js";import y from"../../views/draw/support/HighlightHelper.js";import b from"./CreateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as W}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as C}from"./UpdateRecordWorkflow.js";import _ from"./UpdateWorkflowData.js";import S from"./Workflow.js";import{createWorkflowSteps as F,fetchCandidates as A}from"./workflowUtils.js";import{isGraphicForRelatableFeatureSupportedLayer as M}from"../Feature/support/featureUtils.js";import{getAllTemplatesForLayer as U}from"../support/templateUtils.js";var j;const I="esri.widgets.Editor.UpdateWorkflow",E=r.getLogger(I);let R=j=class extends S{constructor(e){super(e),this._workflowStack=new c(h),this._sketchStack=new c(h),this.type="update"}get activeEditableItem(){return this.activeWorkflow?.data.editableItem??void 0}get activeWorkflow(){return this._workflowStack.last()}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return!!this.activeEditableItem?.attachmentsOnUpdateEnabled}get shouldAllowAttachmentEditing(){return!!this.activeEditableItem?.supports.includes("update")}get hasPendingEdits(){return Array.from(this._workflowStack).some((e=>e.hasPendingEdits))}get helpMessage(){return"awaiting-feature-to-update"===this.stepId?"select":void 0}get reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return!!this.activeEditableItem?.hasInvalidFormTemplate}get hasUnsupportedFields(){return!!this.activeEditableItem?.hasUnsupportedFields}async back(e=(()=>Promise.resolve(!0))){const{featureFormViewModel:t}=this.data.viewModel;if(null==t.relationshipId)if(this.activeWorkflow){if(this.activeWorkflow.hasPendingEdits){if(!await e())return}this.activeWorkflow.hasPreviousStep?await this.activeWorkflow.previous({cancelCurrentStep:!0}):await this.cancelActiveWorkflow({force:!0})}else this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0});else t.relationshipId=null}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflow()}async commit(){await this._drainWorkflowStack((e=>e.commit())),await super.commit()}static create(e){const{viewModel:t,startAt:a,addAttachmentsCallback:o,applyEditsCallback:r}=e,i=new j({data:new _({addAttachmentsCallback:o,applyEditsCallback:r,viewModel:t}),onCommit:async()=>{}});return i._set("steps",this._createWorkflowSteps(i,a)),i}async save(){this.nestedWorkflowCount>1?(await(this.activeWorkflow?.commit()),await this._popWorkflow()):await this.commit()}async startCreatingRelatedRecord(e){try{const t=await this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:t})}}async startUpdating(e){try{const t=await this._createNestedUpdateWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:t})}}async deleteActiveFeature(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");P(e)?await e.deleteAndCommit():await e.cancel(),1===this.nestedWorkflowCount?await this.reset():await this._popWorkflow()}async cancelAll(){await this._drainWorkflowStack((e=>e.cancel({force:!0})))}async _createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:o,applyEditsCallback:r,viewModel:i}=this.data;if(!k(t))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const s=this._getCreationInfoForNestedCreateFeaturesWorkflow(e),n=s.template||s.initialFeature?"creating-features":"awaiting-feature-creation-info",l="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0;return b.create({addAttachmentsCallback:o,applyEditsCallback:r,creationInfo:s,isNested:!0,parent:l,startAt:n,viewModel:i})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:o}=e;if(!k(o)||g(o))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const r={layer:o,maxFeatures:1},i=this._makeRelatedRecordAttributes(e),s=U(o);return s?.length>0?(r.attributeOverrides=i,1===s.length&&(r.template=s[0])):r.initialFeature=new t({sourceLayer:o,attributes:i}),r}async _createNestedUpdateWorkflow(e){const t=v(e.sourceLayer)?C:W,{applyEditsCallback:a,viewModel:o}=this.data,r="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,i=await t.create({feature:e,parent:r,viewModel:o,applyEdits:a});return await p((()=>!i.updating)),i}async _drainWorkflowStack(e){const t=this._workflowStack,a=[];for(;t.length>0;){const o=t.pop();this._sketchStack.pop();const r=e(o).then((()=>o.destroy()));this._updatingHandles.addPromise(r),a.push(r)}await Promise.all(a)}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:a,relationshipId:o}=e;if(!M(t))return;const r=a.relationships?.find((e=>e.id===o));if(!r)return void x("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the destination layer.");if("origin"===r.role)return void x("unsupported-role","Creating new related records in the 'origin' table of a relationship is not yet supported");const i=t.sourceLayer;r.relatedTableId!==i.layerId&&x("invalid-argument-combination","The given parent feature does not belong to the relationship designated by the given relationship ID.");const s=i.relationships?.find((e=>e.id===o));if(!s)return void x("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=t.getAttribute(s.keyField);return n||x("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field."),{[r.keyField]:n}}async _popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop();const e=await this._reconcileWorkflowStack();if(e.failureCount>0)throw new a("editor:next-workflow-failed","Popped the top workflow, but the next workflow in the stack failed to activate",e)}async _pushWorkflow(e){const t=this._workflowRequiresSketchViewModel(e);this.activeWorkflow?.exit({removeSketchHandles:t});const o=this._sketchStack,r=await(e?.start()),i=o.peek();r?(i?.exit(),o.push(r)):o.push(this._cloneSketchController(i)),this._workflowStack.push(e);const s=await this._reconcileWorkflowStack();if(s.failureCount>0)throw new a("editor:failed-to-start-updating-feature","Failed to enter the provided workflow.",s)}async _reconcileWorkflowStack(){const e=this._workflowStack,t=this._sketchStack;try{const a=e.peek();return await(a?.enter()),await(t.peek()?.enter()),{activeWorkflow:a,failureCount:0}}catch(a){e.pop().destroy(),t.pop();const{activeWorkflow:o,failureCount:r}=await this._reconcileWorkflowStack();return{activeWorkflow:o,failureCount:r+1}}}_cloneSketchController(e){return{enter:e?.enter??(async()=>{}),exit:e?.exit??(async()=>{})}}_workflowRequiresSketchViewModel(e){const{type:t}=e;return"update-feature"===t||"create-features"===t&&!v(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:r}=e;return F(["awaiting-feature-to-update","awaiting-update-feature-candidate","editing-existing-feature","adding-attachment","editing-attachment"],t,{"awaiting-feature-to-update":()=>({id:"awaiting-feature-to-update",async setUp(){const{spinnerViewModel:t}=r.viewModel,a=r.viewModel.view;let d=null;e.addHandles(o((()=>{d=i(d)})),this.id),r.rootFeature=null,r.candidates=[];const c=a.on("immediate-click",(async o=>{o.stopPropagation(),t.location=o.mapPoint,t.visible=!0,d?.abort();const{editableItems:i}=r.viewModel;d=new AbortController;const c=await new Promise(((e,t)=>{s(d?.signal,(()=>t(n()))),e(A(i,a,o,d?.signal))}));l(d),r.candidates=c.filter((e=>"fulfilled"===e.status)).flatMap((e=>e.value)),t.visible=1===r.candidates.length,0!==r.candidates.length&&(1===r.candidates.length?(r.rootFeature=r.candidates[0],e.go("editing-existing-feature").catch((()=>{})).then((()=>t.visible=!1))):e.next())}));a.focus(),e.addHandles(c,this.id)},async tearDown(){0===r.candidates.length&&(r.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){r.rootFeature=null;const{view:t}=r.viewModel;if(!t)return;const a=new y({view:t});e.addHandles([u((()=>r.rootFeature),((e,t)=>{a.remove(t),a.add(e)}),w),o((()=>a.removeAll()))],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){const{rootFeature:t,viewModel:i}=e.data;if(!t)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until the root feature is defined");await e.startUpdating(t),i.spinnerViewModel.visible=!1;const s=d((async()=>{await p((()=>!e.updating)),e.previous()})),{featureFormViewModel:n}=r.viewModel,l=n.relatedRecordCallbacks;n.relatedRecordCallbacks={addRelatedRecord:async t=>{await e.startCreatingRelatedRecord(t),n.relationshipId=null},editRelatedRecord:async({relatedFeature:t})=>{await e.startUpdating(t),n.relationshipId=null},showAllRelatedRecords:e=>n.relationshipId=e.relationshipId},e.addHandles([o((()=>n.relatedRecordCallbacks=l)),u((()=>e.nestedWorkflowCount),((e,t)=>{0===e&&0!==t&&s()}),w)],this.id)},async tearDown(){await e.cancelAll(),e.removeHandles(this.id)}}),"adding-attachment":()=>({id:"adding-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){r.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){r.viewModel.attachmentsViewModel.mode="view"}})})}};e([f()],R.prototype,"activeEditableItem",null),e([f()],R.prototype,"activeWorkflow",null),e([f()],R.prototype,"nestedWorkflowCount",null),e([f()],R.prototype,"shouldShowAttachments",null),e([f()],R.prototype,"shouldAllowAttachmentEditing",null),e([f()],R.prototype,"hasPendingEdits",null),e([f()],R.prototype,"helpMessage",null),e([f()],R.prototype,"reliesOnOwnerAdminPrivileges",null),e([f()],R.prototype,"hasInvalidFormTemplate",null),e([f()],R.prototype,"hasUnsupportedFields",null),R=j=e([m(I)],R);const x=(e,t)=>E.warn(`editor:${e}`,t,"The create operation will be allowed to proceed, but the resulting feature may not be related to the given parent feature."),P=e=>!!e&&/update-/.test(e.type),H=R;export{H as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import a from"../../core/Error.js";import{makeHandle as o}from"../../core/handleUtils.js";import r from"../../core/Logger.js";import{abortMaybe as i}from"../../core/maybe.js";import{onAbort as s,createAbortError as n,throwIfAborted as l,debounce as d}from"../../core/promiseUtils.js";import c from"../../core/Queue.js";import{whenOnce as p,watch as u,sync as w}from"../../core/reactiveUtils.js";import{last as h}from"../../core/SetUtils.js";import{property as f}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{subclass as m}from"../../core/accessorSupport/decorators/subclass.js";import{isEditableLayer as k}from"../../layers/support/editableLayers.js";import{isSubtypeGroupLayer as g,isTable as v}from"../../layers/support/layerUtils.js";import y from"../../views/draw/support/HighlightHelper.js";import b from"./CreateFeaturesWorkflow.js";import{UpdateFeatureWorkflow as W}from"./UpdateFeatureWorkflow.js";import{UpdateRecordWorkflow as C}from"./UpdateRecordWorkflow.js";import _ from"./UpdateWorkflowData.js";import S from"./Workflow.js";import{createWorkflowSteps as F,fetchCandidates as M}from"./workflowUtils.js";import{isGraphicForRelatableFeatureSupportedLayer as A}from"../Feature/support/featureUtils.js";import{getAllTemplatesForLayer as U}from"../support/templateUtils.js";var j;const I="esri.widgets.Editor.UpdateWorkflow",E=r.getLogger(I);let R=j=class extends S{constructor(e){super(e),this._workflowStack=new c(h),this._sketchStack=new c(h),this.type="update"}get activeEditableItem(){return this.activeWorkflow?.data.editableItem??void 0}get activeWorkflow(){return this._workflowStack.last()}get nestedWorkflowCount(){return this._workflowStack.length}get shouldShowAttachments(){return!!this.activeEditableItem?.attachmentsOnUpdateEnabled}get shouldAllowAttachmentEditing(){return!!this.activeEditableItem?.supports.includes("update")}get hasPendingEdits(){return Array.from(this._workflowStack).some((e=>e.hasPendingEdits))}get helpMessage(){return this.activeWorkflow?.helpMessage?this.activeWorkflow.helpMessage:"awaiting-feature-to-update"===this.stepId?"select":void 0}get reliesOnOwnerAdminPrivileges(){return this.activeWorkflow?.reliesOnOwnerAdminPrivileges??!1}get hasInvalidFormTemplate(){return!!this.activeEditableItem?.hasInvalidFormTemplate}get hasUnsupportedFields(){return!!this.activeEditableItem?.hasUnsupportedFields}async back(e=(()=>Promise.resolve(!0))){const{featureFormViewModel:t}=this.data.viewModel;if(null==t.relationshipId)if(this.activeWorkflow){if(this.activeWorkflow.hasPendingEdits){if(!await e())return}this.activeWorkflow.hasPreviousStep?await this.activeWorkflow.previous({cancelCurrentStep:!0}):await this.cancelActiveWorkflow({force:!0})}else this.hasPreviousStep?await this.previous({cancelCurrentStep:!0}):await this.cancel({force:!0});else t.relationshipId=null}async cancelActiveWorkflow(e){await(this.activeWorkflow?.cancel(e)),await this._popWorkflow()}async commit(){await this._drainWorkflowStack((e=>e.commit())),await super.commit()}static create(e){const{viewModel:t,startAt:a,addAttachmentsCallback:o,applyEditsCallback:r}=e,i=new j({data:new _({addAttachmentsCallback:o,applyEditsCallback:r,viewModel:t}),onCommit:async()=>{}});return i._set("steps",this._createWorkflowSteps(i,a)),i}async save(){this.nestedWorkflowCount>1?(await(this.activeWorkflow?.commit()),await this._popWorkflow()):await this.commit()}async startCreatingRelatedRecord(e){try{const t=await this._createNestedCreateFeaturesWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-creating","Could not begin updating the provided feature or table record.",{error:t})}}async startUpdating(e){try{const t=await this._createNestedUpdateWorkflow(e);await this._pushWorkflow(t)}catch(t){throw new a("editor:unable-to-start-updating","Could not begin updating the provided feature or table record.",{error:t})}}async deleteActiveFeature(){const{activeWorkflow:e}=this;if(!e)throw new a("editor:nothing-to-delete","There is no feature to delete");P(e)?await e.deleteAndCommit():await e.cancel(),1===this.nestedWorkflowCount?await this.reset():await this._popWorkflow()}async cancelAll(){await this._drainWorkflowStack((e=>e.cancel({force:!0})))}async _createNestedCreateFeaturesWorkflow(e){const{relatedLayer:t}=e,{addAttachmentsCallback:o,applyEditsCallback:r,viewModel:i}=this.data;if(!k(t))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const s=this._getCreationInfoForNestedCreateFeaturesWorkflow(e),n=s.template||s.initialFeature?"creating-features":"awaiting-feature-creation-info",l="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0;return b.create({addAttachmentsCallback:o,applyEditsCallback:r,creationInfo:s,isNested:!0,parent:l,startAt:n,viewModel:i})}_getCreationInfoForNestedCreateFeaturesWorkflow(e){const{relatedLayer:o}=e;if(!k(o)||g(o))throw new a("editor:unsupported-layer","Editing is not supported on the provided layer");const r={layer:o,maxFeatures:1},i=this._makeRelatedRecordAttributes(e),s=U(o);return s?.length>0?(r.attributeOverrides=i,1===s.length&&(r.template=s[0])):r.initialFeature=new t({sourceLayer:o,attributes:i}),r}async _createNestedUpdateWorkflow(e){const t=v(e.sourceLayer)?C:W,{applyEditsCallback:a,viewModel:o}=this.data,r="create-features"!==this.activeWorkflow?.type?this.activeWorkflow:void 0,i=await t.create({feature:e,parent:r,viewModel:o,applyEdits:a});return await p((()=>!i.updating)),i}async _drainWorkflowStack(e){const t=this._workflowStack,a=[];for(;t.length>0;){const o=t.pop();this._sketchStack.pop();const r=e(o).then((()=>o.destroy()));this._updatingHandles.addPromise(r),a.push(r)}await Promise.all(a)}_makeRelatedRecordAttributes(e){const{parentFeature:t,relatedLayer:a,relationshipId:o}=e;if(!A(t))return;const r=a.relationships?.find((e=>e.id===o));if(!r)return void x("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the destination layer.");if("origin"===r.role)return void x("unsupported-role","Creating new related records in the 'origin' table of a relationship is not yet supported");const i=t.sourceLayer;r.relatedTableId!==i.layerId&&x("invalid-argument-combination","The given parent feature does not belong to the relationship designated by the given relationship ID.");const s=i.relationships?.find((e=>e.id===o));if(!s)return void x("relationship-not-found","Could not begin creating a related record because the relationship specified could not be found on the origin layer.");const n=t.getAttribute(s.keyField);return n||x("no-key-on-origin-feature","The given parent feature does not have a value for the relationship's origin primary key field."),{[r.keyField]:n}}async _popWorkflow(){this._workflowStack.pop()?.destroy(),this._sketchStack.pop();const e=await this._reconcileWorkflowStack();if(e.failureCount>0)throw new a("editor:next-workflow-failed","Popped the top workflow, but the next workflow in the stack failed to activate",e)}async _pushWorkflow(e){const t=this._workflowRequiresSketchViewModel(e);this.activeWorkflow?.exit({removeSketchHandles:t});const o=this._sketchStack,r=await(e?.start()),i=o.peek();r?(i?.exit(),o.push(r)):o.push(this._cloneSketchController(i)),this._workflowStack.push(e);const s=await this._reconcileWorkflowStack();if(s.failureCount>0)throw new a("editor:failed-to-start-updating-feature","Failed to enter the provided workflow.",s)}async _reconcileWorkflowStack(){const e=this._workflowStack,t=this._sketchStack;try{const a=e.peek();return await(a?.enter()),await(t.peek()?.enter()),{activeWorkflow:a,failureCount:0}}catch(a){e.pop().destroy(),t.pop();const{activeWorkflow:o,failureCount:r}=await this._reconcileWorkflowStack();return{activeWorkflow:o,failureCount:r+1}}}_cloneSketchController(e){return{enter:e?.enter??(async()=>{}),exit:e?.exit??(async()=>{})}}_workflowRequiresSketchViewModel(e){const{type:t}=e;return"update-feature"===t||"create-features"===t&&!v(e.data.creationInfo?.layer)}static _createWorkflowSteps(e,t="awaiting-feature-to-update"){const{data:r}=e;return F(["awaiting-feature-to-update","awaiting-update-feature-candidate","editing-existing-feature","adding-attachment","editing-attachment"],t,{"awaiting-feature-to-update":()=>({id:"awaiting-feature-to-update",async setUp(){const{spinnerViewModel:t}=r.viewModel,a=r.viewModel.view;let d=null;e.addHandles(o((()=>{d=i(d)})),this.id),r.rootFeature=null,r.candidates=[];const c=a.on("immediate-click",(async o=>{o.stopPropagation(),t.location=o.mapPoint,t.visible=!0,d?.abort();const{editableItems:i}=r.viewModel;d=new AbortController;const c=await new Promise(((e,t)=>{s(d?.signal,(()=>t(n()))),e(M(i,a,o,d?.signal))}));l(d),r.candidates=c.filter((e=>"fulfilled"===e.status)).flatMap((e=>e.value)),t.visible=1===r.candidates.length,0!==r.candidates.length&&(1===r.candidates.length?(r.rootFeature=r.candidates[0],e.go("editing-existing-feature").catch((()=>{})).then((()=>t.visible=!1))):e.next())}));a.focus(),e.addHandles(c,this.id)},async tearDown(){0===r.candidates.length&&(r.viewModel.spinnerViewModel.visible=!1),e.removeHandles(this.id)}}),"awaiting-update-feature-candidate":()=>({id:"awaiting-update-feature-candidate",async setUp(){r.rootFeature=null;const{view:t}=r.viewModel;if(!t)return;const a=new y({view:t});e.addHandles([u((()=>r.rootFeature),((e,t)=>{a.remove(t),a.add(e)}),w),o((()=>a.removeAll()))],this.id)},async tearDown(){e.removeHandles(this.id)}}),"editing-existing-feature":()=>({id:"editing-existing-feature",async setUp(){const{rootFeature:t,viewModel:i}=e.data;if(!t)throw new a("editor:no-feature-specified","Cannot setup the 'updating-existing-feature' step until the root feature is defined");await e.startUpdating(t),i.spinnerViewModel.visible=!1;const s=d((async()=>{await p((()=>!e.updating)),e.previous()})),{featureFormViewModel:n}=r.viewModel,l=n.relatedRecordCallbacks;n.relatedRecordCallbacks={addRelatedRecord:async t=>{await e.startCreatingRelatedRecord(t),n.relationshipId=null},editRelatedRecord:async({relatedFeature:t})=>{await e.startUpdating(t),n.relationshipId=null},showAllRelatedRecords:e=>n.relationshipId=e.relationshipId},e.addHandles([o((()=>n.relatedRecordCallbacks=l)),u((()=>e.nestedWorkflowCount),((e,t)=>{0===e&&0!==t&&s()}),w)],this.id)},async tearDown(){await e.cancelAll(),e.removeHandles(this.id)}}),"adding-attachment":()=>({id:"adding-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){r.viewModel.attachmentsViewModel.mode="view"}}),"editing-attachment":()=>({id:"editing-attachment",parent:"editing-existing-feature",async setUp(){},async tearDown(){r.viewModel.attachmentsViewModel.mode="view"}})})}};e([f()],R.prototype,"activeEditableItem",null),e([f()],R.prototype,"activeWorkflow",null),e([f()],R.prototype,"nestedWorkflowCount",null),e([f()],R.prototype,"shouldShowAttachments",null),e([f()],R.prototype,"shouldAllowAttachmentEditing",null),e([f()],R.prototype,"hasPendingEdits",null),e([f()],R.prototype,"helpMessage",null),e([f()],R.prototype,"reliesOnOwnerAdminPrivileges",null),e([f()],R.prototype,"hasInvalidFormTemplate",null),e([f()],R.prototype,"hasUnsupportedFields",null),R=j=e([m(I)],R);const x=(e,t)=>E.warn(`editor:${e}`,t,"The create operation will be allowed to proceed, but the resulting feature may not be related to the given parent feature."),P=e=>!!e&&/update-/.test(e.type),H=R;export{H as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../Graphic.js";import{addMany as t}from"../../core/arrayUtils.js";import{createTask as r}from"../../core/asyncUtils.js";import"../../core/has.js";import{handlesGroup as i,makeHandle as a}from"../../core/handleUtils.js";import{clone as n}from"../../core/lang.js";import{whenOrAbort as s,throwIfAborted as l,debounce as o}from"../../core/promiseUtils.js";import{watch as c,whenOnce as u}from"../../core/reactiveUtils.js";import{px2pt as p}from"../../core/screenUtils.js";import{diff as y}from"../../core/accessorSupport/diffUtils.js";import{featureHasFields as d,fixFields as f,getDisplayFieldName as m}from"../../layers/support/fieldUtils.js";import{calculateTolerance as h}from"../../renderers/support/clickToleranceUtils.js";import{meterIn as b}from"../../renderers/support/lengthUtils.js";import{getTransformationType as g,TransformationType as w}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import{getRotationAngle as v,getSize as S}from"../../renderers/visualVariables/support/visualVariableUtils.js";import{sceneLayerEditingEnabled as j,i3sPatchingEnabled as U}from"../../support/featureFlags.js";import{to3D as V}from"../../symbols/support/symbolConversion.js";import{getDisplayedSymbol as I}from"../../symbols/support/symbolUtils.js";import{GraphicState as z}from"../../views/3d/layers/graphics/GraphicState.js";import{createQueryGeometry as F}from"../../views/support/drapedUtils.js";import{hitTestSelectSimilarDistance as L,filterGraphicHits as T}from"../../views/support/hitTestSelectUtils.js";function x(e){const t=e.sourceLayer;if(!t||"feature"!==t.type||!C(t.renderer))return{rotation:null,size:null};let r=null,i=null;const a=t.renderer.getVisualVariablesForType("rotation").filter((t=>(!t.axis||"heading"===t.axis)&&t.field&&!t.valueExpression&&null!=v(t,e)));1===a.length&&(r=k(a[0],t));const n=t.renderer.getVisualVariablesForType("size").filter((t=>t.field&&!t.useSymbolValue&&!t.valueExpression&&g(t)===w.RealWorldSize&&null!=S(t,e)));return 1===n.length&&(i=M(n[0],t)),{rotation:r,size:i}}function k(e,t){const r="heading"===(e.axis||"heading")&&"arithmetic"===e.rotationType?-1:1,i=e.field,a=t.fields&&t.fields.filter((e=>e.name===i)),n=a&&1===a.length?a[0].type:"double",s={initial:0,current:0};return{field:i,fieldType:n,getDefault:()=>Promise.resolve(0),getValue:e=>(s.current=s.initial-r*e,O((s.current+360)%360,n)),initValue:e=>{s.initial=null!=e?e:s.current,s.current=0},isUpdatingInteractively:!1,rotationType:e.rotationType??"geographic"}}function E(e,t){switch(t){case"width":return e[0];case"depth":return e[1];case"height":return e[2];default:return e[2]||e[1]||e[0]}}async function A(e,t,r){if(null==t)return 0;const{symbol:i}=V(t);if(null==i||"web-style"===i.type||"cim"===i.type)return 0;const a=i.symbolLayers.at(0);if(!a)return 0;switch(a.type){case"icon":{const{computeIconLayerResourceSize:e}=await import("../../symbols/support/symbolLayerUtils.js");return a.size||Math.min(ie.icon,(await e(a,ie.icon))[0])||ie.icon}case"text":return a.size||ie.text;case"line":return a.size||ie.line;case"object":{const{computeObjectLayerResourceSize:t}=await import("../../symbols/support/symbolLayerUtils.js");return E(await t(a,e.scale/ie.viewScaleSizeFactor),r)}case"path":return(null!=a.width?a.width:a.height)||e.scale/ie.viewScaleSizeFactor;case"extrude":return a.size||e.scale/ie.viewScaleSizeFactor;default:return 0}}function M(e,t){const r=e.field,i=e.axis,a=t.fields&&t.fields.filter((e=>e.name===r)),n=a&&1===a.length?a[0].type:"double",s={updating:!1,initial:0,current:0},l=b[e.valueUnit]??1;let o;return o="area"===e.valueRepresentation?e=>(e*l/2)**2*Math.PI:"radius"===e.valueRepresentation||"distance"===e.valueRepresentation?e=>e*l/2:e=>e*l,{field:r,fieldType:n,getDefault:async(e,t)=>O(o(await A(t,e,i)),n),getValue:(e,t)=>(s.initial||(s.initial=t.pixelSizeAt(t.center)),s.current=s.initial*e,O(s.current,n)),initValue:e=>{s.initial=null!=e?e:s.current,s.current=0},isUpdatingInteractively:!1,displayUnit:le(e.valueUnit),axis:e.axis}}function O(e,t){switch(t){case"small-integer":case"integer":case"long":return Math.round(e);case"double":case"single":return e;default:return 0}}function C(e){switch(e?.type){case"class-breaks":case"simple":case"unique-value":case"dot-density":case"dictionary":case"pie-chart":return!0;default:return!1}}async function P(e,t,r){const i=await I(e,{useSourceLayer:!0,ignoreGraphicSymbol:!0,webStyleCache:t,scale:r});null!=y(e.symbol,i)&&(e.symbol=i)}function R(e){if(!e)throw new Error("no geometry type");return"multipatch"===e?"mesh":e}async function D(e,t,r,n){(await G(e,t,n)).remove();const s=e.on("create",(async i=>{if("cancel"===i.state){(await G(e,t,n)).remove()}if("complete"===i.state){const a=i.graphic;a.sourceLayer||(a.sourceLayer=t.layer),a.attributes||(a.attributes={...t.template?.prototype.attributes});const s="2d"===e.view?.type?e.view?.scale:null;await P(a,n,s),r(a)}}));return i([s,a((()=>e.cancel()))])}async function G(e,t,r){const i=t.layer,n={...t.template?.prototype.attributes,...t.attributeOverrides};let s=null;const{view:l}=e,u="2d"===l?.type;if(await Z(e,i,n,r,u?l.scale:null),u){const t=o((t=>Z(e,i,n,r,t)));s=c((()=>l.scale),(e=>t(e)))}const{data:p,editing:y}=i.capabilities;return e.layer.elevationInfo=i.elevationInfo,await e.create(R(i.geometryType),{graphicProperties:{attributes:n,sourceLayer:i},hasZ:p.supportsZ,defaultZ:y.zDefault??e.defaultCreateOptions.defaultZ,geometryToPlace:t.geometryToPlace??void 0}),s??a()}async function Z(t,r,i,a,n){const s=new e({sourceLayer:r,attributes:i}),{rotation:l,size:o}=x(s);let c=await I(s,{useSourceLayer:!0,webStyleCache:a,scale:n}),u=!1;for(const e of[o,l]){if(null==e)continue;null==i[e.field]&&(i[e.field]=await e.getDefault(c,t.view),u=!0)}switch(u&&(c=await I(s,{useSourceLayer:!0,webStyleCache:a,scale:n})),c?.type){case"simple-fill":case"polygon-3d":t.polygonSymbol=c;break;case"simple-line":case"line-3d":t.polylineSymbol=c;break;case"simple-marker":case"picture-marker":case"point-3d":case"cim":t.pointSymbol=c;break;case"mesh-3d":t.meshSymbol=c}q(t.tooltipOptions,o,l)}function q(e,t,r){e.visualVariables=null!=t||null!=r?{size:null!=t?{unit:t.displayUnit,axis:t.axis,valueType:t.fieldType}:null,rotation:null!=r?{valueType:r.fieldType,rotationType:r.rotationType??"geographic"}:null}:null}function Q(e,t){return e?e.find((e=>e.layer===t)):void 0}async function B(e,t,r,i){switch(t.type){case"3d":return W(e,t,r,i);case"2d":return _(e,t,r,i)}}async function W(e,r,i,a){if(0===e.length)return[];const{updatable:n,graphicsByLayer:l}=await i.async((async()=>{const{results:t}=await s(L(r,i),a),n=new Map,l=e=>{const t=e.layer,r=n.get(t);if(!r){const e=new Array;return n.set(t,e),e}return r};T(t).forEach((({graphic:e})=>l(e).push(e)));const o=e.filter((({supports:e,layer:t})=>e.includes("update")&&n.has(t)));return 0!==o.length&&i.stopPropagation(),{updatable:o,graphicsByLayer:n}}));return s(Promise.allSettled(n.map((async({layer:e})=>{const r=l.get(e),i=H(e);if(r.every((e=>d(i,e))))return r;const n=[];for(const a of r){n.push(a.getObjectId());const e=Object.keys(a.attributes);t(i,e)}const s=e.createQuery();return s.returnGeometry=!1,s.objectIds=n,s.outFields=f(e.fieldsIndex,i),e.queryFeatures(s,{signal:a}).then((({features:e})=>e))}))),a)}async function _(e,t,r,i){if(0===e.length)return[];let a=null;const n=await r.async((async()=>{const{results:n}=await s(t.hitTest(r),i);if(0===n.length)return[];const l=new Set;a=T(n),a.forEach((({graphic:e})=>e&&l.add(e.layer)));const o=e.items.filter((({layer:e,supports:t,attachmentsOnUpdateEnabled:r})=>l.has(e)&&(t.includes("update")||t.includes("delete")||r)));return o.length>0&&r.stopPropagation(),o}));return s(Promise.allSettled(n.map((async({layer:e})=>{const n=e.createQuery();n.returnGeometry=!1,n.outFields=H(e);const s="renderer"in e?h({renderer:e.renderer,event:r}):0;n.geometry=F(r.mapPoint,s,t),n.outSpatialReference=t.spatialReference;const{features:l}=await e.queryFeatures(n,{signal:i});return a?.forEach((({graphic:t})=>{t.layer!==e||l.some((e=>e.getObjectId()===t.getObjectId()))||l.push(t)})),l}))),i)}function H(e){return f(e.fieldsIndex,[e.objectIdField,m({displayField:"displayField"in e?e.displayField:null,fields:e.fields})])}async function J(e,t,r){const{sourceLayer:i}=e,a=i.createQuery();a.objectIds=[e.getAttribute(i.objectIdField)],a.outFields=["*"],a.outSpatialReference=t,a.returnM=i.capabilities.data.supportsM,a.returnZ=i.capabilities.data.supportsZ,j()&&U()&&"scene"===i.type&&null!=i.infoFor3D&&(a.returnGeometry=!0,a.formatOf3DObjects="3D_glb");const n=await i.queryFeatures(a,{signal:r});l(r);return n.features[0]}async function K(e){const{graphic:t,sketchViewModel:r,sourceLayer:i,visualVariables:a,webStyleCache:n}=e;let s=!1;const{rotation:l,size:o}=a;if([l,o].forEach((async e=>{if(null==e)return;const i=t.getAttribute(e.field);if(null!=i)e.initValue(i);else{const i=await e.getDefault(t.symbol,r.view);e.initValue(i),t.setAttribute(e.field,i),s=!0}})),s){const e="2d"===r.view?.type?r.view.scale:null;await P(t,n,e)}const c={multipleSelectionEnabled:!1};return"point"===i.geometryType&&(c.enableRotation=null!=l,c.enableScaling=null!=o),q(r.tooltipOptions,o,l),r.layer.elevationInfo=i.elevationInfo,r.update(t,c)}function N(e){return null==e||"rotate-start"!==e.type&&"rotate"!==e.type&&"rotate-stop"!==e.type?null:e}function X(e){return null==e||"scale-start"!==e.type&&"scale"!==e.type&&"scale-stop"!==e.type?null:e}async function Y(e,t,r,i,a){if(null==t.geometry||"point"!==t.geometry?.type)return;const n=i.rotation,s=N(r.toolEventInfo);if(null!=n&&null!=s)if("rotate-stop"===s.type)n.isUpdatingInteractively=!1,n.initValue();else{n.isUpdatingInteractively=!0;const{field:r,getValue:i}=n;t.setAttribute(r,i(s.angle,e))}const l=i.size,o=X(r.toolEventInfo);if(null!=l&&null!=o)if("scale-stop"===o.type)l.isUpdatingInteractively=!1,l.initValue();else{l.isUpdatingInteractively=!0;const{field:r,getValue:i}=l;t.setAttribute(r,i(o.xScale,e))}await P(t,a,"2d"===e.type?e.scale:null)}async function $({feature:e,featureClone:t,visualVariableAttributes:r,sketchViewModel:n,view:s,onUpdate:l,webStyleCache:u}){await P(t,u,"2d"===s.type?s.scale:null);let p=null;if("2d"===n?.view?.type){const e=o((e=>P(t,u,e)));p=c((()=>n?.view?.scale),(t=>e(t)))}s.map.add(n.layer);const y=t.sourceLayer,d=pe(s,y);await re(s,t),await K({graphic:t,sketchViewModel:n,sourceLayer:y,visualVariables:r,webStyleCache:u});let f=null;d.then((e=>f=e)).catch((()=>{}));const m=r.size,h=r.rotation,b=c((()=>e.attributes),(async e=>{let r=!1;for(const i in e){const a=e[i];a!==t.getAttribute(i)&&(t.setAttribute(i,a),null==m||m.isUpdatingInteractively||m.field!==i||m.initValue(a),null==h||h.isUpdatingInteractively||h.field!==i||h.initValue(a),(null==f||f.requiredFields.includes(i))&&(r=!0))}r&&await P(t,u,"2d"===s.type?s.scale:null)})),g=n.on("update",(async e=>{const t=e.graphics[0];if("complete"===e.state)return K({graphic:t,sketchViewModel:n,sourceLayer:y,visualVariables:r,webStyleCache:u});await Y(s,t,e,r,u),l(fe(t),e)})),w=n.on(["undo","redo"],(async e=>{l(fe(e.graphics[0]),e)}));return i([w,g,a((()=>n.cancel())),b,p])}function ee(e,t,n){const s=e.view;e.layer.add(n);const o=t.sourceLayer,c=t.layer,p=t.getAttribute(c.objectIdField);let y=null;function d(e){y?.abort(),y=r((async t=>{const r=await pe(s,o);l(t),r.setVisibility?.(p,e)}))}return d(!1),i([te(s,n,(e=>d(!e))),a((async()=>{d(!0);try{const e=await pe(s,o);await u((()=>!e.updating))}finally{e.layer.remove(n)}}))])}function te(e,t,r){if("3d"===e.type){const a=new z({graphic:t});return i([e.trackGraphicState(a),c((()=>a.displaying),r)])}return c((()=>t.visible),r)}async function re(e,t){if("3d"===e.type){const r=new z({graphic:t}),i=e.trackGraphicState(r);await u((()=>r.displaying)),i.remove()}else await u((()=>t.visible))}const ie={icon:p(24),text:p(12),line:p(1),viewScaleSizeFactor:100};function ae(e,t,r){let i=!1;return e.filter((e=>!!i||(i=e===t,i))).map((e=>r[e]()))}function ne(e){if(1!==e.length)return null;const t=e[0];if("items"in t){const e=t;return 1===e.items.length?e.items[0]:null}return t}function se(e,t){if(e.viewModel.syncFeatureTemplates(),"awaiting-feature-creation-info"===t[0].id){const r=ne(e.viewModel.featureTemplatesViewModel.items);null==r||r.supportsUpload||(e.creationInfo=r,t.shift())}return t}function le(e){switch(e){case"unknown":case"decimal-degrees":return null;default:return e}}function oe(e){e.filesEnabled=!0,e.mode="view",e.capabilities={editing:!0,operations:{add:!0,update:!0,delete:!0}}}function ce(e){const{creationInfo:t,viewModel:r}=e;if(!t)return!1;const{layer:i}=t,a=r.editableItems.find((e=>e.layer===i));if(a)return a.attachmentsOnCreateEnabled;const n=i.capabilities?.data,s=r.layerInfos?.find((e=>e.layer===i));return!(!(n&&"supportsAttachment"in n&&n.supportsAttachment)||s&&(!1===s.allowAttachments||!1===s.attachmentsOnUpdateEnabled))}const ue=e=>/-stop/.test(e)||/vertex-/.test(e),pe=(e,t)=>{const r="subtype-sublayer"===t.type?t.parent:t;return e.whenLayerView(r)};function ye(e){return"createInteractiveEditSession"in e}const de=Symbol();function fe(e){const t=e.geometry;if("mesh"===t?.type){const r=e.cloneShallow();return r.attributes=n(e.attributes),r.geometry=t.cloneShallow(),r.geometry.transform=t.transform?.clone()??null,r}return e.clone()}function me(e){const t=e.cursor;return e.cursor="progress",a((()=>e.cursor=t))}export{de as UsesSketchViewModelSymbol,se as avoidFeatureTemplateSelectionWithOnlyOneItem,ye as canCreateInteractiveEditSession,fe as cloneGraphicExceptMesh,ae as createWorkflowSteps,B as fetchCandidates,J as fetchFullFeature,Q as findLayerInfo,x as getVisualVariableAttributes,ue as isTerminalUpdateEventType,oe as prepareAttachmentsForCreateWorkflow,D as setUpFeatureAdd,$ as setUpGeometryUpdate,ce as shouldShowAttachmentsForCreateWorkflow,me as showProgressCursor,ie as sizeDefaults,le as sizeVariableUnitToLengthUnit,G as startCreatingNewFeature,K as startUpdatingFeature,ee as swapForEditingSession,P as updateGraphicSymbolWhenRequired,Y as visualVariableInteractiveUpdate,pe as whenEditorLayerView,re as whenGraphicDisplayed};
5
+ import e from"../../Graphic.js";import{addMany as t}from"../../core/arrayUtils.js";import{createTask as r}from"../../core/asyncUtils.js";import"../../core/has.js";import{handlesGroup as i,makeHandle as a}from"../../core/handleUtils.js";import{clone as n}from"../../core/lang.js";import{whenOrAbort as s,throwIfAborted as l,debounce as o}from"../../core/promiseUtils.js";import{watch as c,whenOnce as u}from"../../core/reactiveUtils.js";import{px2pt as p}from"../../core/screenUtils.js";import{diff as y}from"../../core/accessorSupport/diffUtils.js";import{featureHasFields as d,fixFields as f,getDisplayFieldName as m}from"../../layers/support/fieldUtils.js";import{calculateTolerance as h}from"../../renderers/support/clickToleranceUtils.js";import{meterIn as b}from"../../renderers/support/lengthUtils.js";import{getTransformationType as g,TransformationType as w}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import{getRotationAngle as v,getSize as S}from"../../renderers/visualVariables/support/visualVariableUtils.js";import{sceneLayerEditingEnabled as j,i3sPatchingEnabled as U}from"../../support/featureFlags.js";import{to3D as V}from"../../symbols/support/symbolConversion.js";import{getDisplayedSymbol as I}from"../../symbols/support/symbolUtils.js";import{GraphicState as z}from"../../views/3d/layers/graphics/GraphicState.js";import{createQueryGeometry as F}from"../../views/support/drapedUtils.js";import{hitTestSelectSimilarDistance as L,filterGraphicHits as T}from"../../views/support/hitTestSelectUtils.js";function x(e){const t=e.sourceLayer;if(!t||"feature"!==t.type||!C(t.renderer))return{rotation:null,size:null};let r=null,i=null;const a=t.renderer.getVisualVariablesForType("rotation").filter((t=>(!t.axis||"heading"===t.axis)&&t.field&&!t.valueExpression&&null!=v(t,e)));1===a.length&&(r=k(a[0],t));const n=t.renderer.getVisualVariablesForType("size").filter((t=>t.field&&!t.useSymbolValue&&!t.valueExpression&&g(t)===w.RealWorldSize&&null!=S(t,e)));return 1===n.length&&(i=M(n[0],t)),{rotation:r,size:i}}function k(e,t){const r="heading"===(e.axis||"heading")&&"arithmetic"===e.rotationType?-1:1,i=e.field,a=t.fields&&t.fields.filter((e=>e.name===i)),n=a&&1===a.length?a[0].type:"double",s={initial:0,current:0};return{field:i,fieldType:n,getDefault:()=>Promise.resolve(0),getValue:e=>(s.current=s.initial-r*e,O((s.current+360)%360,n)),initValue:e=>{s.initial=null!=e?e:s.current,s.current=0},isUpdatingInteractively:!1,rotationType:e.rotationType??"geographic"}}function E(e,t){switch(t){case"width":return e[0];case"depth":return e[1];case"height":return e[2];default:return e[2]||e[1]||e[0]}}async function A(e,t,r){if(null==t)return 0;const{symbol:i}=V(t);if(null==i||"web-style"===i.type||"cim"===i.type)return 0;const a=i.symbolLayers.at(0);if(!a)return 0;switch(a.type){case"icon":{const{computeIconLayerResourceSize:e}=await import("../../symbols/support/symbolLayerUtils.js");return a.size||Math.min(ie.icon,(await e(a,ie.icon))[0])||ie.icon}case"text":return a.size||ie.text;case"line":return a.size||ie.line;case"object":{const{computeObjectLayerResourceSize:t}=await import("../../symbols/support/symbolLayerUtils.js");return E(await t(a,e.scale/ie.viewScaleSizeFactor),r)}case"path":return(null!=a.width?a.width:a.height)||e.scale/ie.viewScaleSizeFactor;case"extrude":return a.size||e.scale/ie.viewScaleSizeFactor;default:return 0}}function M(e,t){const r=e.field,i=e.axis,a=t.fields&&t.fields.filter((e=>e.name===r)),n=a&&1===a.length?a[0].type:"double",s={updating:!1,initial:0,current:0},l=b[e.valueUnit]??1;let o;return o="area"===e.valueRepresentation?e=>(e*l/2)**2*Math.PI:"radius"===e.valueRepresentation||"distance"===e.valueRepresentation?e=>e*l/2:e=>e*l,{field:r,fieldType:n,getDefault:async(e,t)=>O(o(await A(t,e,i)),n),getValue:(e,t)=>(s.initial||(s.initial=t.pixelSizeAt(t.center)),s.current=s.initial*e,O(s.current,n)),initValue:e=>{s.initial=null!=e?e:s.current,s.current=0},isUpdatingInteractively:!1,displayUnit:le(e.valueUnit),axis:e.axis}}function O(e,t){switch(t){case"small-integer":case"integer":case"long":return Math.round(e);case"double":case"single":return e;default:return 0}}function C(e){switch(e?.type){case"class-breaks":case"simple":case"unique-value":case"dot-density":case"dictionary":case"pie-chart":return!0;default:return!1}}async function P(e,t,r){const i=await I(e,{useSourceLayer:!0,ignoreGraphicSymbol:!0,webStyleCache:t,scale:r});null!=y(e.symbol,i)&&(e.symbol=i)}function R(e){if(!e)throw new Error("no geometry type");return"multipatch"===e?"mesh":e}async function D(e,t,r,n){(await G(e,t,n)).remove();const s=e.on("create",(async i=>{if("cancel"===i.state){(await G(e,t,n)).remove()}if("complete"===i.state){const a=i.graphic;a.sourceLayer||(a.sourceLayer=t.layer),a.attributes||(a.attributes={...t.template?.prototype.attributes});const s="2d"===e.view?.type?e.view?.scale:null;await P(a,n,s),r(a)}}));return i([s,a((()=>e.cancel()))])}async function G(e,t,r){const i=t.layer,n={...t.template?.prototype.attributes,...t.attributeOverrides};let s=null;const{view:l}=e,u="2d"===l?.type;if(await Z(e,i,n,r,u?l.scale:null),u){const t=o((t=>Z(e,i,n,r,t)));s=c((()=>l.scale),(e=>t(e)))}const{data:p,editing:y}=i.capabilities;return e.layer.elevationInfo=i.elevationInfo,await e.create(R(i.geometryType),{graphicProperties:{attributes:n,sourceLayer:i},hasZ:p.supportsZ,defaultZ:(u?y.zDefault:null)??e.defaultCreateOptions.defaultZ,geometryToPlace:t.geometryToPlace??void 0}),s??a()}async function Z(t,r,i,a,n){const s=new e({sourceLayer:r,attributes:i}),{rotation:l,size:o}=x(s);let c=await I(s,{useSourceLayer:!0,webStyleCache:a,scale:n}),u=!1;for(const e of[o,l]){if(null==e)continue;null==i[e.field]&&(i[e.field]=await e.getDefault(c,t.view),u=!0)}switch(u&&(c=await I(s,{useSourceLayer:!0,webStyleCache:a,scale:n})),c?.type){case"simple-fill":case"polygon-3d":t.polygonSymbol=c;break;case"simple-line":case"line-3d":t.polylineSymbol=c;break;case"simple-marker":case"picture-marker":case"point-3d":case"cim":t.pointSymbol=c;break;case"mesh-3d":t.meshSymbol=c}q(t.tooltipOptions,o,l)}function q(e,t,r){e.visualVariables=null!=t||null!=r?{size:null!=t?{unit:t.displayUnit,axis:t.axis,valueType:t.fieldType}:null,rotation:null!=r?{valueType:r.fieldType,rotationType:r.rotationType??"geographic"}:null}:null}function Q(e,t){return e?e.find((e=>e.layer===t)):void 0}async function B(e,t,r,i){switch(t.type){case"3d":return W(e,t,r,i);case"2d":return _(e,t,r,i)}}async function W(e,r,i,a){if(0===e.length)return[];const{updatable:n,graphicsByLayer:l}=await i.async((async()=>{const{results:t}=await s(L(r,i),a),n=new Map,l=e=>{const t=e.layer,r=n.get(t);if(!r){const e=new Array;return n.set(t,e),e}return r};T(t).forEach((({graphic:e})=>l(e).push(e)));const o=e.filter((({supports:e,layer:t})=>e.includes("update")&&n.has(t)));return 0!==o.length&&i.stopPropagation(),{updatable:o,graphicsByLayer:n}}));return s(Promise.allSettled(n.map((async({layer:e})=>{const r=l.get(e),i=H(e);if(r.every((e=>d(i,e))))return r;const n=[];for(const a of r){n.push(a.getObjectId());const e=Object.keys(a.attributes);t(i,e)}const s=e.createQuery();return s.returnGeometry=!1,s.objectIds=n,s.outFields=f(e.fieldsIndex,i),e.queryFeatures(s,{signal:a}).then((({features:e})=>e))}))),a)}async function _(e,t,r,i){if(0===e.length)return[];let a=null;const n=await r.async((async()=>{const{results:n}=await s(t.hitTest(r),i);if(0===n.length)return[];const l=new Set;a=T(n),a.forEach((({graphic:e})=>e&&l.add(e.layer)));const o=e.items.filter((({layer:e,supports:t,attachmentsOnUpdateEnabled:r})=>l.has(e)&&(t.includes("update")||t.includes("delete")||r)));return o.length>0&&r.stopPropagation(),o}));return s(Promise.allSettled(n.map((async({layer:e})=>{const n=e.createQuery();n.returnGeometry=!1,n.outFields=H(e);const s="renderer"in e?h({renderer:e.renderer,event:r}):0;n.geometry=F(r.mapPoint,s,t),n.outSpatialReference=t.spatialReference;const{features:l}=await e.queryFeatures(n,{signal:i});return a?.forEach((({graphic:t})=>{t.layer!==e||l.some((e=>e.getObjectId()===t.getObjectId()))||l.push(t)})),l}))),i)}function H(e){return f(e.fieldsIndex,[e.objectIdField,m({displayField:"displayField"in e?e.displayField:null,fields:e.fields})])}async function J(e,t,r){const{sourceLayer:i}=e,a=i.createQuery();a.objectIds=[e.getAttribute(i.objectIdField)],a.outFields=["*"],a.outSpatialReference=t,a.returnM=i.capabilities.data.supportsM,a.returnZ=i.capabilities.data.supportsZ,j()&&U()&&"scene"===i.type&&null!=i.infoFor3D&&(a.returnGeometry=!0,a.formatOf3DObjects="3D_glb");const n=await i.queryFeatures(a,{signal:r});l(r);return n.features[0]}async function K(e){const{graphic:t,sketchViewModel:r,sourceLayer:i,visualVariables:a,webStyleCache:n}=e;let s=!1;const{rotation:l,size:o}=a;if([l,o].forEach((async e=>{if(null==e)return;const i=t.getAttribute(e.field);if(null!=i)e.initValue(i);else{const i=await e.getDefault(t.symbol,r.view);e.initValue(i),t.setAttribute(e.field,i),s=!0}})),s){const e="2d"===r.view?.type?r.view.scale:null;await P(t,n,e)}const c={multipleSelectionEnabled:!1};return"point"===i.geometryType&&(c.enableRotation=null!=l,c.enableScaling=null!=o),q(r.tooltipOptions,o,l),r.layer.elevationInfo=i.elevationInfo,r.update(t,c)}function N(e){return null==e||"rotate-start"!==e.type&&"rotate"!==e.type&&"rotate-stop"!==e.type?null:e}function X(e){return null==e||"scale-start"!==e.type&&"scale"!==e.type&&"scale-stop"!==e.type?null:e}async function Y(e,t,r,i,a){if(null==t.geometry||"point"!==t.geometry?.type)return;const n=i.rotation,s=N(r.toolEventInfo);if(null!=n&&null!=s)if("rotate-stop"===s.type)n.isUpdatingInteractively=!1,n.initValue();else{n.isUpdatingInteractively=!0;const{field:r,getValue:i}=n;t.setAttribute(r,i(s.angle,e))}const l=i.size,o=X(r.toolEventInfo);if(null!=l&&null!=o)if("scale-stop"===o.type)l.isUpdatingInteractively=!1,l.initValue();else{l.isUpdatingInteractively=!0;const{field:r,getValue:i}=l;t.setAttribute(r,i(o.xScale,e))}await P(t,a,"2d"===e.type?e.scale:null)}async function $({feature:e,featureClone:t,visualVariableAttributes:r,sketchViewModel:n,view:s,onUpdate:l,webStyleCache:u}){await P(t,u,"2d"===s.type?s.scale:null);let p=null;if("2d"===n?.view?.type){const e=o((e=>P(t,u,e)));p=c((()=>n?.view?.scale),(t=>e(t)))}s.map.add(n.layer);const y=t.sourceLayer,d=pe(s,y);await re(s,t),await K({graphic:t,sketchViewModel:n,sourceLayer:y,visualVariables:r,webStyleCache:u});let f=null;d.then((e=>f=e)).catch((()=>{}));const m=r.size,h=r.rotation,b=c((()=>e.attributes),(async e=>{let r=!1;for(const i in e){const a=e[i];a!==t.getAttribute(i)&&(t.setAttribute(i,a),null==m||m.isUpdatingInteractively||m.field!==i||m.initValue(a),null==h||h.isUpdatingInteractively||h.field!==i||h.initValue(a),(null==f||f.requiredFields.includes(i))&&(r=!0))}r&&await P(t,u,"2d"===s.type?s.scale:null)})),g=n.on("update",(async e=>{const t=e.graphics[0];if("complete"===e.state)return K({graphic:t,sketchViewModel:n,sourceLayer:y,visualVariables:r,webStyleCache:u});await Y(s,t,e,r,u),l(fe(t),e)})),w=n.on(["undo","redo"],(async e=>{l(fe(e.graphics[0]),e)}));return i([w,g,a((()=>n.cancel())),b,p])}function ee(e,t,n){const s=e.view;e.layer.add(n);const o=t.sourceLayer,c=t.layer,p=t.getAttribute(c.objectIdField);let y=null;function d(e){y?.abort(),y=r((async t=>{const r=await pe(s,o);l(t),r.setVisibility?.(p,e)}))}return d(!1),i([te(s,n,(e=>d(!e))),a((async()=>{d(!0);try{const e=await pe(s,o);await u((()=>!e.updating))}finally{e.layer.remove(n)}}))])}function te(e,t,r){if("3d"===e.type){const a=new z({graphic:t});return i([e.trackGraphicState(a),c((()=>a.displaying),r)])}return c((()=>t.visible),r)}async function re(e,t){if("3d"===e.type){const r=new z({graphic:t}),i=e.trackGraphicState(r);await u((()=>r.displaying)),i.remove()}else await u((()=>t.visible))}const ie={icon:p(24),text:p(12),line:p(1),viewScaleSizeFactor:100};function ae(e,t,r){let i=!1;return e.filter((e=>!!i||(i=e===t,i))).map((e=>r[e]()))}function ne(e){if(1!==e.length)return null;const t=e[0];if("items"in t){const e=t;return 1===e.items.length?e.items[0]:null}return t}function se(e,t){if(e.viewModel.syncFeatureTemplates(),"awaiting-feature-creation-info"===t[0].id){const r=ne(e.viewModel.featureTemplatesViewModel.items);null==r||r.supportsUpload||(e.creationInfo=r,t.shift())}return t}function le(e){switch(e){case"unknown":case"decimal-degrees":return null;default:return e}}function oe(e){e.filesEnabled=!0,e.mode="view",e.capabilities={editing:!0,operations:{add:!0,update:!0,delete:!0}}}function ce(e){const{creationInfo:t,viewModel:r}=e;if(!t)return!1;const{layer:i}=t,a=r.editableItems.find((e=>e.layer===i));if(a)return a.attachmentsOnCreateEnabled;const n=i.capabilities?.data,s=r.layerInfos?.find((e=>e.layer===i));return!(!(n&&"supportsAttachment"in n&&n.supportsAttachment)||s&&(!1===s.allowAttachments||!1===s.attachmentsOnUpdateEnabled))}const ue=e=>/-stop/.test(e)||/vertex-/.test(e),pe=(e,t)=>{const r="subtype-sublayer"===t.type?t.parent:t;return e.whenLayerView(r)};function ye(e){return"createInteractiveEditSession"in e}const de=Symbol();function fe(e){const t=e.geometry;if("mesh"===t?.type){const r=e.cloneShallow();return r.attributes=n(e.attributes),r.geometry=t.cloneShallow(),r.geometry.transform=t.transform?.clone()??null,r}return e.clone()}function me(e){const t=e.cursor;return e.cursor="progress",a((()=>e.cursor=t))}export{de as UsesSketchViewModelSymbol,se as avoidFeatureTemplateSelectionWithOnlyOneItem,ye as canCreateInteractiveEditSession,fe as cloneGraphicExceptMesh,ae as createWorkflowSteps,B as fetchCandidates,J as fetchFullFeature,Q as findLayerInfo,x as getVisualVariableAttributes,ue as isTerminalUpdateEventType,oe as prepareAttachmentsForCreateWorkflow,D as setUpFeatureAdd,$ as setUpGeometryUpdate,ce as shouldShowAttachmentsForCreateWorkflow,me as showProgressCursor,ie as sizeDefaults,le as sizeVariableUnitToLengthUnit,G as startCreatingNewFeature,K as startUpdatingFeature,ee as swapForEditingSession,P as updateGraphicSymbolWhenRequired,Y as visualVariableInteractiveUpdate,pe as whenEditorLayerView,re as whenGraphicDisplayed};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import{deprecatedProperty as i}from"../core/deprecate.js";import o from"../core/Logger.js";import{watch as n,whenOnce as a}from"../core/reactiveUtils.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/has.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{isIntegerField as l}from"../layers/support/fieldUtils.js";import d from"./Widget.js";import{css as p}from"./FeatureForm/css.js";import{isGroupInput as c,isFieldInput as u,isRelationshipInput as m,isInputInGroupInput as h,isFieldElementWithInputType as v,getErrorMessageForFieldInput as _,getIconForFeature as g,isNumberFieldInput as b}from"./FeatureForm/featureFormUtils.js";import f from"./FeatureForm/FeatureFormViewModel.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{getLabelForDateFieldValue as y,numberingSystem as F,prepareISOFieldValueForDateComponents as R,prepareUnixFieldValueForDateComponents as w,getISOFieldValueFromDateComponents as O,getUnixFieldValueFromDateComponents as k}from"./support/dateUtils.js";import{globalCss as I}from"./support/globalCss.js";import{Heading as M,incrementHeadingLevel as D}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as V}from"./support/decorators/messageBundle.js";import{vmEvent as x}from"./support/decorators/vmEvent.js";import{tsx as N}from"./support/jsxFactory.js";import{substitute as L}from"../intl/substitute.js";const T="data-field-name",j="esri.widgets.FeatureForm",S=o.getLogger(j);let E=class extends d{constructor(e,t){super(e,t),this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName=null,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new f,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,relatedRecordCallbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,relatedRecordCallbacks:o}=this;i&&o?.addRelatedRecord&&o.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupToggle=this._onGroupToggle.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreate=this._afterComponentCreate.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this)}initialize(){this.addHandles([n((()=>this.feature),(()=>{a((()=>!this.viewModel.updating)).then((()=>{const e=this._getFocusableInput("forward");this._inputsWithChanges.clear(),this._dateComponentMap.clear(),this._syncGroupInputStates(),this._focusedFieldName=e?.name||null,this._attemptFocusOnNextRender=!0}))})),n((()=>this.groupDisplay),(()=>this._syncGroupInputStates())),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._inputsWithChanges.add(e))),this._focusedFieldName=t,this._attemptFocusOnNextRender=!0,this.scheduleRender()}})),n((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange()))])}loadDependencies(){return C({block:()=>import("@esri/calcite-components/dist/components/calcite-block.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox.js"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),input:()=>import("@esri/calcite-components/dist/components/calcite-input.js"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker.js"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message.js"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number.js"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker.js"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone.js"),label:()=>import("@esri/calcite-components/dist/components/calcite-label.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),progress:()=>import("@esri/calcite-components/dist/components/calcite-progress.js"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button.js"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group.js"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch.js")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const e=this.relatedRecordCallbacks;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get relatedRecordCallbacks(){return this.viewModel.relatedRecordCallbacks}set relatedRecordCallbacks(e){this.viewModel.relatedRecordCallbacks=e}get relationshipId(){return this.viewModel.relationshipId}set relationshipId(e){this.viewModel.relationshipId=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get view(){return i(S,"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view}set view(e){i(S,"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view=e}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return N("div",{class:this.classes(p.base,I.widget,I.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return N("form",{class:p.form,novalidate:!0,onkeydown:this._onFormKeyDown,onsubmit:this._onFormSubmit},this._renderHeader(),this._renderContent())}_renderHeader(){const e=this.viewModel;if(!e.formHeaderVisible)return;const t=null!=e.formTitle&&N(M,{key:"title",level:this.headingLevel},e.formTitle),i=null!=e.formDescription&&N("p",{class:p.description,key:"description"},e.formDescription);return N("div",{class:p.formHeader},t,i)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderActiveRelationshipInput(e.activeRelationshipInput):e.inputs.filter(t).filter((e=>e.visible)).map(((e,t)=>c(e)?this._renderGroup(e,t):u(e)?this._renderLabeledField(e):m(e)?this._renderRelationshipInput(e):void 0))}_renderActiveRelationshipInput(e){return this._renderRelationshipInput(e)}_renderDescriptionOrEmpty(e,t){return null==e?null:N("div",{class:this.classes(p.description),id:t},e)}_renderGroup(e,t){const{disabled:i,formTemplate:o,headingLevel:n}=this,{description:a,inputs:s,label:r,open:l}=e,d=s.filter((e=>e.visible)),c=this.viewModel.findField(this._focusedFieldName),h=c?.group===e,v=`${this.id}_group_${t}`,_="sequential"===this.groupDisplay;return N("calcite-block",{class:this.classes(p.group,_?p.groupSequential:null,h?p.groupActive:null,i?p.inputDisabled:null),collapsible:!0,"data-group":e,description:a||void 0,disabled:i,heading:`${r}`,headingLevel:o?.title?D(n):n,id:v,key:v,open:l,onCalciteBlockToggle:({target:t})=>this._onGroupToggle(t,e)},d.map((e=>u(e)?this._renderLabeledField(e):m(e)?this._renderRelationshipInput(e):void 0)))}_getFocusableInput(e,t){const i=this.viewModel.allFieldInputs,o="forward"===e?i:i.slice().reverse();let n;if(!t||m(t))n=0;else if(c(t)){const e=t.inputs.find(u);n=e?o.indexOf(e):0}else{let i;if(h(t)&&!t.group.open){const o=t.group.inputs.filter(u);i="forward"===e?o[o.length-1]:o[0]}else i=t;n=o.indexOf(i)+1}for(let a=n;a<o.length;a++){const e=o[a];if(e.visible&&u(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:o,layer:n,required:a}=e,s={"aria-label":a?L(this.messages.requiredFieldLabel,{name:o}):o,class:p.label,key:`${n.id}-${i.uid}-${e.name}`},r=[N("div",{class:p.labelTextContent,key:"labelTextContainer"},o,a?N("span",{"aria-hidden":"true",title:this.messagesCommon.required},"*"):void 0),"unsupported"!==t?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e)];return"date"===t&&"coded-value"!==e.domain?.type?N("label",{...s},r):N("calcite-label",{...s},r)}_renderFieldInput(e){const{dataType:t,domain:i,inputType:o,name:n,updating:a}=e,s=this.getCommonInputProps(e);if("coded-value"===i?.type){const t=this.viewModel.getFieldValueOptionsForField(n,this.messages.empty);return"switch"!==o||e.hasInvalidSwitchValue?"radio-buttons"===o?this._renderRadioButtonComponents(e,t.flat(),s):this._renderComboBoxComponent(e,t,s):this._renderSwitchComponent(e,s)}if("datetime-picker"===o||"date"===t)return this._renderDateComponents(e,s);const r="number"===t?this._renderNumberComponent(e,s):this._renderStringComponent(e,s);return a?N("div",{class:p.fieldInputWrapper,key:`${s.key}-input-updating-wrapper`},r,N("div",{class:p.fieldInputLoader},N("calcite-progress",{type:"indeterminate"}))):r}_renderStringComponent(e,t){return N("calcite-input",{...t,type:"text-area"===e.inputType?"textarea":"text",onCalciteInputInput:e=>this._saveValueFromComponent(e.target)})}_renderNumberComponent(e,t){return N("calcite-input-number",{...t,integer:l(e.field),type:"number",onCalciteInputNumberInput:e=>this._saveValueFromComponent(e.target)})}_renderDateComponents(e,t){const{field:i}=e;switch(i.type){case"date":return this._renderDateFieldCompnents(e,t);case"date-only":return this._renderDateOnlyFieldComponent(e,t);case"time-only":return this._renderTimeOnlyFieldComponent(e,t);case"timestamp-offset":return this._renderTimestampOffsetFieldComponents(e,t);default:return this._renderReadOnlyComponent(e,y(e.field,t.value,{timeZone:this.timeZone}))}}_renderDateOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:n,max:a,min:s,key:r,readOnly:l}=t;return N("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:n,"data-date-part":"date","data-field-name":t[T],key:`${r}-date-input`,max:null!=a?`${a}`:void 0,min:null!=s?`${s}`:void 0,numberingSystem:F,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:l,value:null!=o?`${o}`:void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)})}_renderTimeOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:n,key:a,readOnly:s}=t;return N("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:n,"data-date-part":"time","data-field-name":t[T],key:`${a}-time-input`,numberingSystem:F,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:s,step:e.timeStep,value:null!=o?`${o}`:void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)})}_renderTimestampOffsetFieldComponents(e,t){const{name:i,valid:o,value:n}=e,{class:a,key:s,readOnly:r}=t,l=null!=n?`${n}`:void 0,{dateAsString:d,time:c,timeZoneOffset:u}=R(l),m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!o,numberingSystem:F,overlayPositioning:"fixed",readOnly:r,[T]:i,onfocus:this._onComponentFocus};return N("div",{class:p.dateInputContainer,key:`${s}-date-time-container`},N("calcite-input-date-picker",{...m,class:a,"data-date-part":"date",key:`${s}-date-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:d??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)}),N("calcite-input-time-picker",{...m,class:a,"data-date-part":"time",key:`${s}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:e.timeStep,value:c??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)}),e.includeTimeOffset?N("calcite-input-time-zone",{...m,class:a,"data-date-part":"timeZone",key:`${s}-timezone-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:u??"0",onCalciteInputTimeZoneChange:e=>this._saveValueFromDateComponent(e.target)}):null)}_renderDateFieldCompnents(e,t){const{includeTime:i,name:o,valid:n,value:a}=e,{class:s,max:r,min:l,key:d,readOnly:c}=t,{timeZone:u}=this,m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!n,numberingSystem:F,overlayPositioning:"fixed",readOnly:c,[T]:o,onfocus:this._onComponentFocus},{dateAsString:h,time:v}=w(a,u),_=null!=r?w(r,u):void 0,g=null!=l?w(l,u):void 0;return N("div",{class:p.dateInputContainer,key:`${d}-date-time-container`},N("calcite-input-date-picker",{...m,class:s,"data-date-part":"date",key:`${d}-date-input`,max:_?.dateAsString??void 0,min:g?.dateAsString??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:h??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)}),i?N("calcite-input-time-picker",{...m,class:s,"data-date-part":"time",key:`${d}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:1,value:v??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return N("calcite-input",{...i,class:this.classes(p.fieldInput,p.inputDisabled),readOnly:!0,type:"text",value:null!=t?`${t}`:i.value})}_renderComboBoxComponent(e,t,i){const{value:o,name:n}=e,{messages:a,messagesTemplates:s,viewModel:r,_inputsWithChanges:l}=this,d=t.map((e=>e.map((({name:e,value:t})=>N("calcite-combobox-item",{key:`#${t}`,selected:o===t,textLabel:e,value:`${t}`}))))),[p,c]=d;this.viewModel.fieldsWithInvalidCodedValue.has(e)&&c.unshift(N("calcite-combobox-item",{key:"incompatible-option",readOnly:!0,textLabel:`${e.value}`,value:`${e.value}`}));const u=c.length>0?[N("calcite-combobox-item-group",{key:"recommended",label:a.recommended},p),N("calcite-combobox-item-group",{key:"other",label:s.other},c)]:p,m="INSERT"===r.arcadeEditType,h=l.has(n),v=null==o&&(!m||h);if(e.showNoValueOptionEnabled){const t="",i=e.showNoValueLabel||a.empty;u.unshift(N("calcite-combobox-item",{key:"empty-option",selected:v,textLabel:a.empty,value:t},i))}const _=m&&e.showNoValueOptionEnabled&&!h?()=>{}:i.onblur;return N("calcite-combobox",{...i,allowCustomValues:!1,clearDisabled:!0,disabled:i.readOnly,onblur:_,overlayPositioning:"fixed",selectionMode:"single",onCalciteComboboxChange:({target:e})=>{v&&0===e.selectedItems.length?this._ignoreDeselectionOfNoValueOption(e):this._saveValueFromComponent(e)}},u)}_renderRadioButtonComponents(e,t,i){const{name:o,value:n}=e,a=t.map((({name:e,value:t})=>this._renderRadioButtonComponent({key:e,label:e,name:o,value:t,selected:t===n,props:i})));if(e.showNoValueOptionEnabled){const t="",s=e.showNoValueLabel||this.messages.empty,r=n===t||null===n;a.unshift(this._renderRadioButtonComponent({key:"empty-option",label:s,name:o,value:t,selected:r,props:i}))}return N("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:p.inputRadioGroup,"data-field-name":i[T],key:`${i.key}-radio-group`,layout:"vertical",name:i.key,required:i.required},a)}_renderSwitchComponent(e,t){const{value:i}=e,o=!!v(e.element,"switch")&&i===e.element.input.onValue;return N("calcite-switch",{...t,checked:o,class:p.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldName=null},onCalciteSwitchChange:e=>this._saveValueFromComponent(e.target)})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:o,label:n,props:a}){return N("calcite-label",{class:p.inputRadioLabel,key:e,layout:"inline"},N("calcite-radio-button",{...a,afterCreate:void 0,afterUpdate:void 0,checked:o,class:p.inputRadio,disabled:a.readOnly,name:t,onblur:()=>{this._focusedFieldName=null},value:i,onCalciteRadioButtonChange:({target:e})=>{e.checked&&this._saveValueFromComponent(e)}}),n)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.valid?_(e,this.messages,this.timeZone):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?N("calcite-input-message",{icon:!0,status:"invalid"},i):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:o}=e,{relatedRecordCallbacks:n}=this;if(!o||!n?.showAllRelatedRecords)return;const a=this.messages;return N("calcite-list-item",{description:L(a.totalCount,{count:t}),label:a.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},N("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:o}=e,{messages:n,relatedRecordCallbacks:a}=this;if(t&&a?.addRelatedRecord&&o)return N("calcite-button",{alignment:"center",appearance:"outline-fill",class:p.centeredButton,disabled:e.updating||!e.originHasValidKey,iconStart:"plus",key:`${i}-add-button`,onclick:()=>this._onAddRelatedRecordsClick(i,o),round:!0,scale:"s",width:"half"},e.relatedLayerIsTable?n.addRecord:n.addFeature)}_renderRelatedRecordListItem(e,t){const{feature:i,description:o,title:n}=e,{feature:a,relatedRecordCallbacks:s}=this,{highlightHelper:r}=this.viewModel,l=()=>{r?.removeAll(),s?.editRelatedRecord&&a&&s.editRelatedRecord({parentFeature:a,relationshipId:t,relatedFeature:i})},d=r?()=>r.add(i):void 0,p=r?()=>r.remove(i):void 0;return N("calcite-list-item",{bind:this,description:o,key:`${t}-${i.uid}`,label:n,onclick:l,onmouseenter:d,onmouseleave:p,value:n},N("calcite-icon",{icon:g(i),scale:"m",slot:"content-start"}),N("calcite-icon",{icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderRelationshipInput(e){if(!this._relatedRecordsEnabled||!e.editable)return;const{featureCount:t,relationshipId:i,showAllEnabled:o}=e,n=o?null:this._renderDescriptionOrEmpty(e.description),a=t>0?this._renderRelatedRecordsList(e):e.loaded?e.originHasValidKey?this._renderNoRelatedRecordsNotice():this._renderNoValidOriginKeyNotice(e):void 0;return N("calcite-label",{class:this.classes(p.label,p.relatedRecordsLabel),key:`relationship-${i}-container`},N("div",null,this._renderRelatedRecordsHeaderContainer(e),n,a),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return N("div",{class:p.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},N("span",null,e.label),t?N("calcite-loader",{inline:!0,key:"loader",label:this.messagesCommon?.loading,scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return N("calcite-list",{class:p.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoValidOriginKeyNotice(e){const{messages:t}=this,i=e.relatedLayerIsTable?t.noOriginKeyRecord:t.noOriginKeyFeature,o=e.relationship?.keyField,n=this.viewModel.findField(o),a=n?.label,s=L(i,{relatedLayerName:e.relatedLayer?.title,originKeyField:a});return N("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},N("div",{slot:"message"},s))}_renderNoRelatedRecordsNotice(){return N("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},N("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return N("div",{afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved,bind:this,class:p.listObserver,key:"feature-observer"})}getCommonInputProps(e){const{disabled:t}=this,{editable:i,hint:o,label:n,maxLength:a,minLength:s,name:r,range:{max:l,min:d},required:c,valid:u,value:m}=e,h=this._inputsWithChanges.has(r),v=!i||t;return{afterCreate:this._afterComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":u?"false":"true",class:this.classes(p.fieldInput,v?p.inputDisabled:null,h&&!u?p.inputInvalid:null),key:r,label:n,max:null!=l?l:void 0,min:null!=d?d:void 0,maxLength:a>-1?a:void 0,minLength:s>-1?s:void 0,placeholder:o??void 0,readOnly:v,required:c,value:null==m?"":`${m}`,onblur:this._onComponentBlur,onfocus:this._onComponentFocus,onkeydown:this._onComponentKeyDown,[T]:r}}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(T))}_afterDateComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e),i=e.dataset.datePart,o=this._dateComponentMap.get(t.name);if("valueAsDate"in e&&null!=e.value){const t=e.value,i=new ResizeObserver((()=>{e.value=void 0,e.value=t,i.unobserve(e)}));i.observe(e)}if(null!=o)switch(i){case"date":o.date=e;break;case"time":o.time=e;break;case"timeZone":o.timeZone=e}else this._dateComponentMap.set(t.name,{[i]:e});this._afterDateComponentCreateOrUpdate(e)}_afterDateComponentCreateOrUpdate(e){this._afterComponentCreateOrUpdate(e)}_afterComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e);b(t)&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._afterComponentCreateOrUpdate(e)}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,i=e.querySelector("calcite-radio-button"),o=t||i;o&&this._afterComponentCreateOrUpdate(o)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),o=t.findField(this._focusedFieldName);this._attemptFocusOnNextRender&&o===i&&(this._attemptFocusOnNextRender=!1,h(i)&&(i.group.open=!0),e.setFocus())}_onComponentFocus(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);this._focusedFieldName=i.name}_onComponentBlur(e){const t=e.target;this._focusedFieldName=null,this._saveValueFromComponent(t)}_saveValueFromDateComponent(e){const t=this._getFieldInputFromHTMLElement(e),i=t.field.type,{name:o}=t,n=this._dateComponentMap.get(o);if(!n)return;const a=this.viewModel.getValue(o);let s=null;s="date-only"===i||"time-only"===i?e.value:"timestamp-offset"===i?null!=e.value?O({dateComponent:n.date,timeComponent:n.time,timeZoneComponent:n.timeZone,oldValue:a}):null:null!=e.value?k({oldValue:a,dateComponent:n.date,timeComponent:n.time,timeZone:this.timeZone,max:t.range?.max,min:t.range?.min}):null,null!==s&&e.value?a!==s&&this._updateFieldValue(o,s):this._updateFieldValue(o,null)}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e);this._updateFieldValue(t.name,this._parseValue(e))}_onComponentKeyDown({key:e,target:t}){const i=this._getFieldInputFromHTMLElement(t);"Enter"===e&&h(i)&&!i.group.open&&(i.group.open=!0)}_updateFieldValue(e,t){if(this.viewModel.setValue(e,t),this._inputsWithChanges.add(e),this.viewModel.fieldsWithContingentValues.has(e)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>null!=t)));this.viewModel.validateContingencyConstraints(e)}}_parseValue(e){const t=this._getFieldInputFromHTMLElement(e),i=e.value;return v(t.element,"switch")?e.checked?t.element.input.onValue:t.element.input.offValue:null==i||""===i?null:"number"===t.dataType?"-0"===i||"-0."===i||"-0,"===i?i:parseFloat(i):"date"===t.field.type?parseFloat(i):i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:i}=e;0===i.length&&t&&"selected"in t?t.selected=!0:S.warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupToggle(e,t){e.open?(t.open=!0,this._focusedFieldName=this._getFocusableInput("forward",t)?.name||null,this._attemptFocusOnNextRender=!0,"sequential"===this.groupDisplay&&this.viewModel.allGroupInputs.forEach((e=>{e!==t&&(e.open=!1)}))):t.open=!1,this.scheduleRender()}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}_onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;e&&this._listObserverNode&&e.showAllEnabled&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}_syncGroupInputStates(){if("sequential"!==this.groupDisplay)return;const e=this.viewModel.allGroupInputs;if(!e.length)return;const t=e.filter((e=>e.open));0===t.length?e[0].open=!0:t.length>1&&t.slice(1).forEach((e=>e.open=!1))}};e([s()],E.prototype,"_listObserverNode",void 0),e([s()],E.prototype,"_relatedRecordsEnabled",null),e([s()],E.prototype,"disabled",null),e([s()],E.prototype,"feature",null),e([s()],E.prototype,"formTemplate",null),e([s()],E.prototype,"groupDisplay",void 0),e([s()],E.prototype,"headingLevel",void 0),e([s()],E.prototype,"label",null),e([s()],E.prototype,"layer",null),e([s()],E.prototype,"map",null),e([s(),V("esri/widgets/FeatureForm/t9n/FeatureForm")],E.prototype,"messages",void 0),e([s(),V("esri/t9n/common")],E.prototype,"messagesCommon",void 0),e([s(),V("esri/widgets/Feature/t9n/Feature")],E.prototype,"messagesFeature",void 0),e([s(),V("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],E.prototype,"messagesTemplates",void 0),e([s()],E.prototype,"relatedRecordCallbacks",null),e([s()],E.prototype,"relationshipId",null),e([s()],E.prototype,"spatialReference",null),e([s()],E.prototype,"strict",null),e([s()],E.prototype,"timeZone",null),e([s()],E.prototype,"view",null),e([s(),x(["value-change","submit"])],E.prototype,"viewModel",void 0),E=e([r(j)],E);const U=E;export{U as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import{deprecatedProperty as i}from"../core/deprecate.js";import o from"../core/Logger.js";import{watch as n,whenOnce as a}from"../core/reactiveUtils.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/has.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{isIntegerField as l}from"../layers/support/fieldUtils.js";import d from"./Widget.js";import{css as p}from"./FeatureForm/css.js";import{isGroupInput as c,isFieldInput as u,isRelationshipInput as m,isInputInGroupInput as h,isFieldElementWithInputType as v,getErrorMessageForFieldInput as _,getIconForFeature as g,isNumberFieldInput as b}from"./FeatureForm/featureFormUtils.js";import f from"./FeatureForm/FeatureFormViewModel.js";import{loadCalciteComponents as C}from"./support/componentsUtils.js";import{getLabelForDateFieldValue as y,numberingSystem as F,prepareISOFieldValueForDateComponents as R,prepareUnixFieldValueForDateComponents as w,getISOFieldValueFromDateComponents as O,getUnixFieldValueFromDateComponents as k}from"./support/dateUtils.js";import{globalCss as I}from"./support/globalCss.js";import{Heading as M,incrementHeadingLevel as D}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as x}from"./support/decorators/messageBundle.js";import{vmEvent as V}from"./support/decorators/vmEvent.js";import{tsx as N}from"./support/jsxFactory.js";import{substitute as L}from"../intl/substitute.js";const T="data-field-name",j="esri.widgets.FeatureForm",S=o.getLogger(j);let E=class extends d{constructor(e,t){super(e,t),this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName=null,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new f,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,relatedRecordCallbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,relatedRecordCallbacks:o}=this;i&&o?.addRelatedRecord&&o.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupToggle=this._onGroupToggle.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreate=this._afterComponentCreate.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this)}initialize(){this.addHandles([n((()=>this.feature),(()=>{a((()=>!this.viewModel.updating)).then((()=>{const e=this._getFocusableInput("forward");this._inputsWithChanges.clear(),this._dateComponentMap.clear(),this._syncGroupInputStates(),this._focusedFieldName=e?.name||null,this._attemptFocusOnNextRender=!0}))})),n((()=>this.groupDisplay),(()=>this._syncGroupInputStates())),this.on("submit",(e=>{if(e.invalid.length>0){const[t]=e.invalid;e.invalid.forEach((e=>this._inputsWithChanges.add(e))),this._focusedFieldName=t,this._attemptFocusOnNextRender=!0,this.scheduleRender()}})),n((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange()))])}loadDependencies(){return C({block:()=>import("@esri/calcite-components/dist/components/calcite-block.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox.js"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group.js"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon.js"),input:()=>import("@esri/calcite-components/dist/components/calcite-input.js"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker.js"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message.js"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number.js"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker.js"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone.js"),label:()=>import("@esri/calcite-components/dist/components/calcite-label.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader.js"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice.js"),progress:()=>import("@esri/calcite-components/dist/components/calcite-progress.js"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button.js"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group.js"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch.js")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const e=this.relatedRecordCallbacks;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get relatedRecordCallbacks(){return this.viewModel.relatedRecordCallbacks}set relatedRecordCallbacks(e){this.viewModel.relatedRecordCallbacks=e}get relationshipId(){return this.viewModel.relationshipId}set relationshipId(e){this.viewModel.relationshipId=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get view(){return i(S,"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view}set view(e){i(S,"view",{replacement:"Use FeatureForm.map instead.",version:"4.27"}),this.viewModel.view=e}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return N("div",{class:this.classes(p.base,I.widget,I.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return N("form",{class:p.form,novalidate:!0,onkeydown:this._onFormKeyDown,onsubmit:this._onFormSubmit},this._renderHeader(),this._renderContent())}_renderHeader(){const e=this.viewModel;if(!e.formHeaderVisible)return;const t=null!=e.formTitle&&N(M,{key:"title",level:this.headingLevel},e.formTitle),i=null!=e.formDescription&&N("p",{class:p.description,key:"description"},e.formDescription);return N("div",{class:p.formHeader},t,i)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderActiveRelationshipInput(e.activeRelationshipInput):e.inputs.filter(t).filter((e=>e.visible)).map(((e,t)=>c(e)?this._renderGroup(e,t):u(e)?this._renderLabeledField(e):m(e)?this._renderRelationshipInput(e):void 0))}_renderActiveRelationshipInput(e){return this._renderRelationshipInput(e)}_renderDescriptionOrEmpty(e,t){return null==e?null:N("div",{class:this.classes(p.description),id:t},e)}_renderGroup(e,t){const{disabled:i,formTemplate:o,headingLevel:n}=this,{description:a,inputs:s,label:r,open:l}=e,d=s.filter((e=>e.visible)),c=this.viewModel.findField(this._focusedFieldName),h=c?.group===e,v=`${this.id}_group_${t}`,_="sequential"===this.groupDisplay;return N("calcite-block",{class:this.classes(p.group,_?p.groupSequential:null,h?p.groupActive:null,i?p.inputDisabled:null),collapsible:!0,"data-group":e,description:a||void 0,disabled:i,heading:`${r}`,headingLevel:o?.title?D(n):n,id:v,key:v,open:l,onCalciteBlockToggle:({target:t})=>this._onGroupToggle(t,e)},d.map((e=>u(e)?this._renderLabeledField(e):m(e)?this._renderRelationshipInput(e):void 0)))}_getFocusableInput(e,t){const i=this.viewModel.allFieldInputs,o="forward"===e?i:i.slice().reverse();let n;if(!t||m(t))n=0;else if(c(t)){const e=t.inputs.find(u);n=e?o.indexOf(e):0}else{let i;if(h(t)&&!t.group.open){const o=t.group.inputs.filter(u);i="forward"===e?o[o.length-1]:o[0]}else i=t;n=o.indexOf(i)+1}for(let a=n;a<o.length;a++){const e=o[a];if(e.visible&&u(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:o,layer:n,required:a}=e,s={"aria-label":a?L(this.messages.requiredFieldLabel,{name:o}):o,class:p.label,key:`${n.id}-${i.uid}-${e.name}`},r=[N("div",{class:p.labelTextContent,key:"labelTextContainer"},o,a?N("span",{"aria-hidden":"true",title:this.messagesCommon.required},"*"):void 0),"unsupported"!==t?this._renderFieldInput(e):this._renderReadOnlyComponent(e),this._renderAuxiliaryText(e)];return"date"===t&&"coded-value"!==e.domain?.type?N("label",{...s},r):N("calcite-label",{...s},r)}_renderFieldInput(e){const{dataType:t,domain:i,inputType:o,name:n,updating:a}=e,s=this.getCommonInputProps(e);if("coded-value"===i?.type){const t=this.viewModel.getFieldValueOptionsForField(n,this.messages.empty);return"switch"!==o||e.hasInvalidSwitchValue?"radio-buttons"===o?this._renderRadioButtonComponents(e,t.flat(),s):this._renderComboBoxComponent(e,t,s):this._renderSwitchComponent(e,s)}if("datetime-picker"===o||"date"===t)return this._renderDateComponents(e,s);const r="number"===t?this._renderNumberComponent(e,s):this._renderStringComponent(e,s);return a?N("div",{class:p.fieldInputWrapper,key:`${s.key}-input-updating-wrapper`},r,N("div",{class:p.fieldInputLoader},N("calcite-progress",{type:"indeterminate"}))):r}_renderStringComponent(e,t){return N("calcite-input",{...t,type:"text-area"===e.inputType?"textarea":"text",onCalciteInputInput:e=>this._saveValueFromComponent(e.target)})}_renderNumberComponent(e,t){return N("calcite-input-number",{...t,integer:l(e.field),type:"number",onCalciteInputNumberInput:e=>this._saveValueFromComponent(e.target)})}_renderDateComponents(e,t){const{field:i}=e;switch(i.type){case"date":return this._renderDateFieldCompnents(e,t);case"date-only":return this._renderDateOnlyFieldComponent(e,t);case"time-only":return this._renderTimeOnlyFieldComponent(e,t);case"timestamp-offset":return this._renderTimestampOffsetFieldComponents(e,t);default:return this._renderReadOnlyComponent(e,y(e.field,t.value,{timeZone:this.timeZone}))}}_renderDateOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:n,max:a,min:s,key:r,readOnly:l}=t;return N("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:n,"data-date-part":"date","data-field-name":t[T],key:`${r}-date-input`,max:null!=a?`${a}`:void 0,min:null!=s?`${s}`:void 0,numberingSystem:F,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:l,value:null!=o?`${o}`:void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)})}_renderTimeOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:n,key:a,readOnly:s}=t;return N("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:n,"data-date-part":"time","data-field-name":t[T],key:`${a}-time-input`,numberingSystem:F,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:s,step:e.timeStep,value:null!=o?`${o}`:void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)})}_renderTimestampOffsetFieldComponents(e,t){const{name:i,valid:o,value:n}=e,{class:a,key:s,readOnly:r}=t,l=null!=n?`${n}`:void 0,{dateAsString:d,time:c,timeZoneOffset:u}=R(l),m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!o,numberingSystem:F,overlayPositioning:"fixed",readOnly:r,[T]:i,onfocus:this._onComponentFocus};return N("div",{class:p.dateInputContainer,key:`${s}-date-time-container`},N("calcite-input-date-picker",{...m,class:a,"data-date-part":"date",key:`${s}-date-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:d??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)}),N("calcite-input-time-picker",{...m,class:a,"data-date-part":"time",key:`${s}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:e.timeStep,value:c??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)}),e.includeTimeOffset?N("calcite-input-time-zone",{...m,class:a,"data-date-part":"timeZone",key:`${s}-timezone-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:u??"0",onCalciteInputTimeZoneChange:e=>this._saveValueFromDateComponent(e.target)}):null)}_renderDateFieldCompnents(e,t){const{includeTime:i,name:o,valid:n,value:a}=e,{class:s,max:r,min:l,key:d,readOnly:c}=t,{timeZone:u}=this,m={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!n,numberingSystem:F,overlayPositioning:"fixed",readOnly:c,[T]:o,onfocus:this._onComponentFocus},{dateAsString:h,time:v}=w(a,u),_=null!=r?w(r,u):void 0,g=null!=l?w(l,u):void 0;return N("div",{class:p.dateInputContainer,key:`${d}-date-time-container`},N("calcite-input-date-picker",{...m,class:s,"data-date-part":"date",key:`${d}-date-input`,max:_?.dateAsString??void 0,min:g?.dateAsString??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:h??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.target)}),i?N("calcite-input-time-picker",{...m,class:s,"data-date-part":"time",key:`${d}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:1,value:v??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.target)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return N("calcite-input",{...i,class:this.classes(p.fieldInput,p.inputDisabled),readOnly:!0,type:"text",value:null!=t?`${t}`:i.value})}_renderComboBoxComponent(e,t,i){const{value:o,name:n}=e,{messages:a,messagesTemplates:s,viewModel:r,_inputsWithChanges:l}=this,d=t.map((e=>e.map((({name:e,value:t})=>N("calcite-combobox-item",{key:`#${t}`,selected:o===t,textLabel:e,value:`${t}`}))))),[p,c]=d;this.viewModel.fieldsWithInvalidCodedValue.has(e)&&c.unshift(N("calcite-combobox-item",{key:"incompatible-option",readOnly:!0,textLabel:`${e.value}`,value:`${e.value}`}));const u=c.length>0?[N("calcite-combobox-item-group",{key:"recommended",label:a.recommended},p),N("calcite-combobox-item-group",{key:"other",label:s.other},c)]:p,m="INSERT"===r.arcadeEditType,h=l.has(n),v=null==o&&(!m||h);if(e.showNoValueOptionEnabled){const t="",i=e.showNoValueLabel||a.empty;u.unshift(N("calcite-combobox-item",{key:"empty-option",selected:v,textLabel:a.empty,value:t},i))}const _=m&&e.showNoValueOptionEnabled&&!h?()=>{}:i.onblur;return N("calcite-combobox",{...i,allowCustomValues:!1,clearDisabled:!0,disabled:i.readOnly,onblur:_,overlayPositioning:"fixed",selectionMode:"single",onCalciteComboboxChange:({target:e})=>{v&&0===e.selectedItems.length?this._ignoreDeselectionOfNoValueOption(e):this._saveValueFromComponent(e)}},u)}_renderRadioButtonComponents(e,t,i){const{name:o,value:n}=e,a=t.map((({name:e,value:t})=>this._renderRadioButtonComponent({key:e,label:e,name:o,value:t,selected:t===n,props:i})));if(e.showNoValueOptionEnabled){const t="",s=e.showNoValueLabel||this.messages.empty,r=n===t||null===n;a.unshift(this._renderRadioButtonComponent({key:"empty-option",label:s,name:o,value:t,selected:r,props:i}))}return N("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:p.inputRadioGroup,"data-field-name":i[T],key:`${i.key}-radio-group`,layout:"vertical",name:i.key,required:i.required},a)}_renderSwitchComponent(e,t){const{value:i}=e,o=!!v(e.element,"switch")&&i===e.element.input.onValue;return N("calcite-switch",{...t,checked:o,class:p.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldName=null},onCalciteSwitchChange:e=>this._saveValueFromComponent(e.target)})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:o,label:n,props:a}){return N("calcite-label",{class:p.inputRadioLabel,key:e,layout:"inline"},N("calcite-radio-button",{...a,afterCreate:void 0,afterUpdate:void 0,checked:o,class:p.inputRadio,disabled:a.readOnly,name:t,onblur:()=>{this._focusedFieldName=null},value:i,onCalciteRadioButtonChange:({target:e})=>{e.checked&&this._saveValueFromComponent(e)}}),n)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.valid?_(e,this.messages,this.timeZone):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?N("calcite-input-message",{icon:!0,status:"invalid"},i):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:o}=e,{relatedRecordCallbacks:n}=this;if(!o||!n?.showAllRelatedRecords)return;const a=this.messages;return N("calcite-list-item",{description:L(a.totalCount,{count:t}),label:a.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},N("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:o}=e,{messages:n,relatedRecordCallbacks:a}=this;if(t&&a?.addRelatedRecord&&o)return N("calcite-button",{alignment:"center",appearance:"outline-fill",class:p.centeredButton,disabled:e.updating||!e.originHasValidKey,iconStart:"plus",key:`${i}-add-button`,onclick:()=>this._onAddRelatedRecordsClick(i,o),round:!0,scale:"s",width:"half"},e.relatedLayerIsTable?n.addRecord:n.addFeature)}_renderRelatedRecordListItem(e,t){const{feature:i,description:o,title:n}=e,{feature:a,relatedRecordCallbacks:s}=this,{highlightHelper:r}=this.viewModel,l=()=>{r?.removeAll(),s?.editRelatedRecord&&a&&s.editRelatedRecord({parentFeature:a,relationshipId:t,relatedFeature:i})},d=r?()=>r.add(i):void 0,p=r?()=>r.remove(i):void 0;return N("calcite-list-item",{bind:this,description:o,key:`${t}-${i.uid}`,label:n,onclick:l,onmouseenter:d,onmouseleave:p,value:n},N("calcite-icon",{icon:g(i),scale:"m",slot:"content-start"}),N("calcite-icon",{icon:"chevron-right",scale:"s",slot:"content-end"}))}_renderRelationshipInput(e){if(!this._relatedRecordsEnabled||!e.editable)return;const{featureCount:t,relationshipId:i,showAllEnabled:o}=e,n=o?null:this._renderDescriptionOrEmpty(e.description),a=t>0?this._renderRelatedRecordsList(e):e.loaded?e.originHasValidKey?this._renderNoRelatedRecordsNotice():this._renderNoValidOriginKeyNotice(e):void 0;return N("calcite-label",{class:this.classes(p.label,p.relatedRecordsLabel),key:`relationship-${i}-container`},N("div",null,this._renderRelatedRecordsHeaderContainer(e),n,a),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return N("div",{class:p.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},N("span",null,e.label),t?N("calcite-loader",{inline:!0,key:"loader",label:this.messagesCommon?.loading,scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return N("calcite-list",{class:p.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoValidOriginKeyNotice(e){const{messages:t}=this,i=e.relatedLayerIsTable?t.noOriginKeyRecord:t.noOriginKeyFeature,o=e.relationship?.keyField,n=this.viewModel.findField(o),a=e.layer?.fieldsIndex.get(o),s=n?.label||a?.alias||o,r=L(i,{relatedLayerName:e.relatedLayer?.title,originKeyField:s});return N("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},N("div",{slot:"message"},r))}_renderNoRelatedRecordsNotice(){return N("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},N("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return N("div",{afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved,bind:this,class:p.listObserver,key:"feature-observer"})}getCommonInputProps(e){const{disabled:t}=this,{editable:i,hint:o,label:n,maxLength:a,minLength:s,name:r,range:{max:l,min:d},required:c,valid:u,value:m}=e,h=this._inputsWithChanges.has(r),v=!i||t;return{afterCreate:this._afterComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":u?"false":"true",class:this.classes(p.fieldInput,v?p.inputDisabled:null,h&&!u?p.inputInvalid:null),key:r,label:n,max:null!=l?l:void 0,min:null!=d?d:void 0,maxLength:a>-1?a:void 0,minLength:s>-1?s:void 0,placeholder:o??void 0,readOnly:v,required:c,value:null==m?"":`${m}`,onblur:this._onComponentBlur,onfocus:this._onComponentFocus,onkeydown:this._onComponentKeyDown,[T]:r}}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(T))}_afterDateComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e),i=e.dataset.datePart,o=this._dateComponentMap.get(t.name);if("valueAsDate"in e&&null!=e.value){const t=e.value,i=new ResizeObserver((()=>{e.value=void 0,e.value=t,i.unobserve(e)}));i.observe(e)}if(null!=o)switch(i){case"date":o.date=e;break;case"time":o.time=e;break;case"timeZone":o.timeZone=e}else this._dateComponentMap.set(t.name,{[i]:e});this._afterDateComponentCreateOrUpdate(e)}_afterDateComponentCreateOrUpdate(e){this._afterComponentCreateOrUpdate(e)}_afterComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e);b(t)&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._afterComponentCreateOrUpdate(e)}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,i=e.querySelector("calcite-radio-button"),o=t||i;o&&this._afterComponentCreateOrUpdate(o)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),o=t.findField(this._focusedFieldName);this._attemptFocusOnNextRender&&o===i&&(this._attemptFocusOnNextRender=!1,h(i)&&(i.group.open=!0),e.setFocus())}_onComponentFocus(e){const t=e.target,i=this._getFieldInputFromHTMLElement(t);this._focusedFieldName=i.name}_onComponentBlur(e){const t=e.target;this._focusedFieldName=null,this._saveValueFromComponent(t)}_saveValueFromDateComponent(e){const t=this._getFieldInputFromHTMLElement(e),i=t.field.type,{name:o}=t,n=this._dateComponentMap.get(o);if(!n)return;const a=this.viewModel.getValue(o);let s=null;s="date-only"===i||"time-only"===i?e.value:"timestamp-offset"===i?null!=e.value?O({dateComponent:n.date,timeComponent:n.time,timeZoneComponent:n.timeZone,oldValue:a}):null:null!=e.value?k({oldValue:a,dateComponent:n.date,timeComponent:n.time,timeZone:this.timeZone,max:t.range?.max,min:t.range?.min}):null,null!==s&&e.value?a!==s&&this._updateFieldValue(o,s):this._updateFieldValue(o,null)}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e);this._updateFieldValue(t.name,this._parseValue(e))}_onComponentKeyDown({key:e,target:t}){const i=this._getFieldInputFromHTMLElement(t);"Enter"===e&&h(i)&&!i.group.open&&(i.group.open=!0)}_updateFieldValue(e,t){if(this.viewModel.setValue(e,t),this._inputsWithChanges.add(e),this.viewModel.fieldsWithContingentValues.has(e)){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>null!=t)));this.viewModel.validateContingencyConstraints(e)}}_parseValue(e){const t=this._getFieldInputFromHTMLElement(e),i=e.value;return v(t.element,"switch")?e.checked?t.element.input.onValue:t.element.input.offValue:null==i||""===i?null:"number"===t.dataType?"-0"===i||"-0."===i||"-0,"===i?i:parseFloat(i):"date"===t.field.type?parseFloat(i):i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:i}=e;0===i.length&&t&&"selected"in t?t.selected=!0:S.warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupToggle(e,t){e.open?(t.open=!0,this._focusedFieldName=this._getFocusableInput("forward",t)?.name||null,this._attemptFocusOnNextRender=!0,"sequential"===this.groupDisplay&&this.viewModel.allGroupInputs.forEach((e=>{e!==t&&(e.open=!1)}))):t.open=!1,this.scheduleRender()}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}_onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;e&&this._listObserverNode&&e.showAllEnabled&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}_syncGroupInputStates(){if("sequential"!==this.groupDisplay)return;const e=this.viewModel.allGroupInputs;if(!e.length)return;const t=e.filter((e=>e.open));0===t.length?e[0].open=!0:t.length>1&&t.slice(1).forEach((e=>e.open=!1))}};e([s()],E.prototype,"_listObserverNode",void 0),e([s()],E.prototype,"_relatedRecordsEnabled",null),e([s()],E.prototype,"disabled",null),e([s()],E.prototype,"feature",null),e([s()],E.prototype,"formTemplate",null),e([s()],E.prototype,"groupDisplay",void 0),e([s()],E.prototype,"headingLevel",void 0),e([s()],E.prototype,"label",null),e([s()],E.prototype,"layer",null),e([s()],E.prototype,"map",null),e([s(),x("esri/widgets/FeatureForm/t9n/FeatureForm")],E.prototype,"messages",void 0),e([s(),x("esri/t9n/common")],E.prototype,"messagesCommon",void 0),e([s(),x("esri/widgets/Feature/t9n/Feature")],E.prototype,"messagesFeature",void 0),e([s(),x("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],E.prototype,"messagesTemplates",void 0),e([s()],E.prototype,"relatedRecordCallbacks",null),e([s()],E.prototype,"relationshipId",null),e([s()],E.prototype,"spatialReference",null),e([s()],E.prototype,"strict",null),e([s()],E.prototype,"timeZone",null),e([s()],E.prototype,"view",null),e([s(),V(["value-change","submit"])],E.prototype,"viewModel",void 0),E=e([r(j)],E);const U=E;export{U as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.28/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import t from"../core/Collection.js";import{eventKey as i}from"../core/events.js";import o from"../core/Logger.js";import{watch as s,when as r}from"../core/reactiveUtils.js";import{throttle as n}from"../core/throttle.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/has.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import d from"./Feature.js";import c from"./Spinner.js";import u from"./Widget.js";import{css as h}from"./Feature/resources.js";import{FeatureContentMixin as p}from"./Feature/support/FeatureContentMixin.js";import{css as m}from"./Features/css.js";import v from"./Features/FeaturesRelatedRecords.js";import g from"./Features/FeaturesViewModel.js";import w from"./Features/FeaturesVisibleElements.js";import{ActionsCollection as _}from"./Popup/actions.js";import{getPointFromGeometry as f}from"./Popup/actionUtils.js";import{loadCalciteComponents as F}from"./support/componentsUtils.js";import{globalCss as M}from"./support/globalCss.js";import{Heading as b}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as y}from"./support/decorators/messageBundle.js";import{vmEvent as I}from"./support/decorators/vmEvent.js";import{tsx as C}from"./support/jsxFactory.js";import{substitute as A}from"../intl/substitute.js";import{formatNumber as x}from"../intl/number.js";const R="selected-index",j=0,N="features-spinner";let k=class extends(p(u)){constructor(e,i){super(e,i),this._featureMenuIntersectionObserverCallback=([e])=>{e?.isIntersecting&&null!=this.viewModel.featurePage&&this.viewModel.featurePage++},this._featureMenuIntersectionObserver=new IntersectionObserver(this._featureMenuIntersectionObserverCallback,{root:window.document}),this._featureMenuIntersectionObserverNode=null,this._focusFeatureMenuFlowItem=!1,this._spinner=null,this._feature=null,this._relatedRecordsFlowItems=new t,this._relatedRecordsWidget=new v({flowItems:this._relatedRecordsFlowItems}),this._focusRootFlowItem=!1,this._rootFlowItemNode=null,this._featureMenuViewportNode=null,this.collapsed=!1,this.icon=null,this.featureNavigationTop=!1,this.headerActions=new _,this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.responsiveActionsEnabled=!1,this.viewModel=new g,this.visibleElements=new w,this._renderAction=(e,t)=>{const i=this._getActionTitle(e),{type:o,active:s,uid:r,disabled:n,indicator:a}=e;return e.visible?C("calcite-action",{active:"toggle"===o&&e.value,appearance:"solid",bind:this,"data-action-uid":r,disabled:n,icon:this._getActionIcon(e),indicator:a,key:`action-${t}`,loading:s,onclick:this._triggerAction,scale:"s",text:i,title:this._hideActionText?i:void 0},this._getFallbackIcon(e)):null},this._openFeatureMenu=()=>{this.featureMenuOpen=!0},this._previousFeature=()=>{this.viewModel.selectedFeatureIndex--},this._nextFeature=()=>{this.viewModel.selectedFeatureIndex++},this._handleFeatureMenuBack=()=>{this._focusRootFlowItem=!0,this.featureMenuOpen=!1,this.viewModel.browseClusterEnabled=!1},this._displaySpinnerThrottled=n((()=>this._displaySpinner()),j),this._addSelectedFeatureIndexHandle(),this.addHandles([this._displaySpinnerThrottled,s((()=>this.viewModel?.active),(()=>this._toggleScreenLocationEnabled())),s((()=>this.viewModel?.active),(e=>this._relatedRecordsWidget.closed=!e)),s((()=>this.visibleElements?.closeButton),(e=>this._relatedRecordsWidget.closable=e)),s((()=>this.visibleElements?.spinner),(e=>this._spinnerEnabledChange(e))),s((()=>this.viewModel?.view),((e,t)=>this._viewChange(e,t))),s((()=>this.viewModel?.view?.ready),((e,t)=>this._viewReadyChange(e??!1,t??!1))),s((()=>[this.viewModel?.waitingForResult,this.viewModel?.location]),(()=>{this._hideSpinner(),this._displaySpinnerThrottled()})),s((()=>this.selectedFeatureWidget),(()=>this._destroyRelatedRecordsFlowItemWidgets())),s((()=>{const e=this.selectedFeatureWidget?.viewModel;return[e?.title,e?.state]}),(()=>this._setTitleFromFeatureWidget())),s((()=>{const e=this.selectedFeatureWidget?.viewModel;return[e?.content,e?.state]}),(()=>this._setContentFromFeatureWidget())),s((()=>this.viewModel?.featureViewModels),(()=>this._featureMenuViewportScrollTop())),this._relatedRecordsWidget.on("close",(()=>this.close())),this._relatedRecordsWidget.on("exit",(()=>this._destroyRelatedRecordsFlowItemWidgets())),this._relatedRecordsWidget.on("open-related-feature",(({feature:e})=>this._openRelatedFeature(e)))])}loadDependencies(){return F({action:()=>import("@esri/calcite-components/dist/components/calcite-action.js"),"action-bar":()=>import("@esri/calcite-components/dist/components/calcite-action-bar.js"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow.js"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),"list-item-group":()=>import("@esri/calcite-components/dist/components/calcite-list-item-group.js"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader.js")})}destroy(){this._destroyRelatedRecordsFlowItemWidgets(),this._destroySelectedFeatureWidget(),this._destroySpinner(),this._unobserveFeatureMenuObserver(),this._featureMenuIntersectionObserver?.disconnect(),this._relatedRecordsWidget?.destroy()}get _hideActionText(){if(!this.responsiveActionsEnabled)return!1;const e=this.view?.widthBreakpoint;return"xsmall"===e||"small"===e||"medium"===e}get _featureNavigationVisible(){return this.viewModel.active&&this.viewModel.featureCount>1&&this.visibleElements.featureNavigation}get _isCollapsed(){return this._collapseEnabled&&this.collapsed}get _collapseEnabled(){return this.visibleElements.collapseButton&&!!this.title&&!!this.content}get content(){return this.viewModel.content}set content(e){this.viewModel.content=e}get featureMenuOpen(){return this.viewModel.featureMenuOpen}set featureMenuOpen(e){this.viewModel.featureMenuOpen=e}get features(){return this.viewModel.features}set features(e){this.viewModel.features=e}get location(){return this.viewModel.location}set location(e){this.viewModel.location=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get promises(){return this.viewModel.promises}set promises(e){this.viewModel.promises=e}get selectedFeature(){return this.viewModel.selectedFeature}get selectedFeatureIndex(){return this.viewModel.selectedFeatureIndex}set selectedFeatureIndex(e){this.viewModel.selectedFeatureIndex=e}get selectedFeatureWidget(){const{_feature:e,headingLevel:t,_relatedRecordsFlowItems:i}=this,{selectedFeatureViewModel:o}=this.viewModel,s={title:!1};return o?(e?(e.viewModel=o,e.visibleElements=s):this._feature=new d({flowItems:i,headingLevel:t+1,viewModel:o,visibleElements:s}),this._feature):null}get title(){return this.viewModel.title}set title(e){this.viewModel.title=e}get updateLocationEnabled(){return this.viewModel.updateLocationEnabled}set updateLocationEnabled(e){this.viewModel.updateLocationEnabled=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}get visible(){return this.viewModel.visible}set visible(e){this.viewModel.visible=e}blur(){const{active:e}=this.viewModel;e||o.getLogger(this.declaredClass).warn("Features can only be blurred when currently active."),this._rootFlowItemNode?.blur()}clear(){return this.viewModel.clear()}close(){this.viewModel.visible=!1}fetchFeatures(e,t){return this.viewModel.fetchFeatures(e,t)}focus(){const{container:e}=this,{active:t}=this.viewModel;if(t||o.getLogger(this.declaredClass).warn("Features can only be blurred when currently active."),!e)return;const i=e.querySelectorAll("calcite-flow-item"),s=i[i?.length-1];this.scheduleRender(),requestAnimationFrame((()=>s?.setFocus()))}next(){return this.viewModel.next()}open(e){this.removeHandles(R);const t={collapsed:e?.collapsed??!1};this.set(t),this.viewModel.open(e),this.addHandles(r((()=>!this.viewModel.waitingForResult),(()=>this._addSelectedFeatureIndexHandle()),{once:!0}))}previous(){return this.viewModel.previous()}triggerAction(e){return this.viewModel.triggerAction(e)}render(){return C("div",{class:this.classes(m.base,M.widget,M.panel)},this._renderHeader(),this._renderContentContainer())}_renderFeatureNavigation(){return[this._renderPagination(),this._renderFeatureMenuButton()]}_renderHeader(){return!this.featureMenuOpen&&this.featureNavigationTop&&this._featureNavigationVisible?C("div",{class:m.header,key:"header-actions"},this._renderFeatureNavigation()):null}_renderFooter(){return this.featureMenuOpen||this.featureNavigationTop||!this._featureNavigationVisible?null:C("div",{class:m.footer,key:"footer-actions",slot:"footer"},this._renderFeatureNavigation())}_renderFeatureMenuButton(){const{messages:e,viewModel:t}=this,{featureCount:i,selectedFeatureIndex:o,pendingPromisesCount:s}=t;return C("calcite-action",{appearance:"solid",bind:this,icon:"list",key:"feature-menu-button",label:e.selectFeature,loading:s>0,onclick:this._openFeatureMenu,scale:"s",text:A(e.pageText,{index:x(o+1),total:x(i)}),textEnabled:!0,title:e.selectFeature})}_renderPagination(){const{previous:e,next:t}=this.messagesCommon.pagination;return C("calcite-action-bar",{class:m.paginationActionBar,expandDisabled:!0,key:"pagination-action-bar",layout:"horizontal",overflowActionsDisabled:!0,scale:"s"},C("calcite-action-group",{scale:"s"},C("calcite-action",{appearance:"solid",class:m.paginationPrevious,icon:"chevron-left",iconFlipRtl:!0,label:e,onclick:this._previousFeature,scale:"s",text:e,title:e}),C("calcite-action",{appearance:"solid",icon:"chevron-right",iconFlipRtl:!0,label:t,onclick:this._nextFeature,scale:"s",text:t,title:t})))}_renderFeatureMenuItem(e){const{selectedFeatureViewModel:t,featureViewModels:i}=this.viewModel,o=e===t,s=i.indexOf(e);return C("calcite-list-item",{bind:this,"data-feature-index":s,key:`feature-menu-item-${e.uid}`,onblur:this._removeActiveFeature,onfocus:this._setActiveFeature,onmouseleave:this._removeActiveFeature,onmouseover:this._setActiveFeature,selected:o,onCalciteListItemSelect:this._selectFeature},C("span",{innerHTML:e.title||this.messagesCommon.untitled,slot:"content"}))}_groupResultsByLayer(){const{featureViewModels:e}=this.viewModel,t=new Map;return e.forEach((e=>{const i=e?.graphic;if(!i)return;const o=i.sourceLayer??i.layer,s=t.get(o)??[];t.set(o,[...s,e])})),t}_renderFeatureMenu(){const{featureViewModels:e}=this.viewModel,t=this._groupResultsByLayer();return e.length?C("calcite-list",{selectionAppearance:"icon",selectionMode:"single"},Array.from(t.keys()).map((e=>C("calcite-list-item-group",{heading:e?.title??this.messagesCommon.untitled,key:e?.uid||"untitled"},t.get(e)?.map((e=>this._renderFeatureMenuItem(e))))))):null}_renderHeaderAction(e,t){return e.visible?C("calcite-action",{active:"toggle"===e.type&&e.value,appearance:"solid",bind:this,"data-action-uid":e.uid,disabled:e.disabled,icon:e.icon||"",indicator:e.indicator,key:`header-action-${t}`,loading:e.active,onclick:this._triggerHeaderAction,scale:"m",slot:"header-actions-end",text:e.title||"",title:e.title||""}):null}_renderHeaderActions(){return this.headerActions.map(((e,t)=>this._renderHeaderAction(e,t))).toArray()}_renderContentFeature(){const{headingLevel:e,visibleElements:t,_isCollapsed:i,_collapseEnabled:o,featureNavigationTop:s}=this,{title:r,active:n}=this.viewModel,a=t.heading&&r?r:"";return C("calcite-flow-item",{afterCreate:this._focusRootFlowItemNode,afterUpdate:this._focusRootFlowItemNode,bind:this,class:this.classes({[m.contentFeature]:!0,[m.flowItemCollapsed]:i}),closable:t.closeButton,closed:!n,collapsed:i,collapseDirection:s?"down":"up",collapsible:o,headingLevel:e,key:"root-flow-item",onkeydown:this._onMainKeydown,onCalciteFlowItemClose:this.close,onCalciteFlowItemToggle:this._handleCollapseToggle},a?C(b,{class:this.classes(m.featuresHeading,M.heading),innerHTML:a,key:"header-content",level:this.headingLevel,slot:"header-content"}):null,this._renderHeaderActions(),this._renderActionBar(),C("div",{class:this.classes(m.container,m.contentContainer)},this._renderContent()),this._renderFooter())}_renderFeatureMenuContainer(){const{viewModel:e,featureMenuOpen:t,messages:i,messagesCommon:o}=this,{active:s,featureViewModels:r,pendingPromisesCount:n}=e;return t?C("calcite-flow-item",{afterCreate:this._focusFeatureMenuFlowItemNode,afterUpdate:this._focusFeatureMenuFlowItemNode,bind:this,closable:!1,closed:!s,description:A(i.total,{total:r.length}),heading:i.selectFeature,key:"feature-menu",loading:e.waitingForContents,onCalciteFlowItemBack:this._handleFeatureMenuBack},n>0?C("calcite-loader",{class:m.loader,inline:!0,key:"feature-menu-loader",label:o.loading,scale:"m",slot:"header-actions-end"}):null,C("div",{class:m.container},this._renderFeatureMenu()),C("div",{afterCreate:this._featureMenuIntersectionObserverCreated,bind:this,class:m.featureMenuObserver}),C("calcite-button",{appearance:"transparent",onclick:this._handleFeatureMenuBack,slot:"footer-actions",width:"full"},o.back)):null}_renderContentContainer(){const{content:e}=this.viewModel;return C("calcite-flow",{key:e??"content"},this._renderContentFeature(),this._renderFeatureMenuContainer(),this._relatedRecordsWidget.render())}_getIconStyles(e){return{"background-image":e?`url(${e})`:""}}_getActionImage(e){const{selectedFeature:t}=this,i=t?.attributes,{image:o}=e;return o&&i?A(o,i):o??""}_getFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const o=this._getActionImage(e),s={[m.icon]:!!t,[m.actionImage]:!!o};return t&&(s[t]=!0),o||t?C("span",{"aria-hidden":"true",class:this.classes(m.icon,s),key:"icon",styles:o?this._getIconStyles(o):{}}):null}_renderActionBar(){return!this._isCollapsed&&this.visibleElements.actionBar&&this.viewModel.allActions?.length?C("calcite-action-bar",{expandDisabled:!0,expanded:!this._hideActionText,key:"header-action-bar",scale:"s",slot:"action-bar"},C("calcite-action-group",{overlayPositioning:"fixed",scale:"s"},this._renderActions())):null}_renderActions(){return this.viewModel.allActions.toArray().map(this._renderAction)}_renderContent(){const e=this.viewModel?.content;return e?"string"==typeof e?C("div",{class:h.contentNode,innerHTML:e,key:e}):this.renderNodeContent(e):null}_handleCollapseToggle(){this.collapsed=!this.collapsed}async _openRelatedFeature(e){await e.viewModel.updateGeometry();const t=e.graphic,i=t?.geometry;if(null==i||null==t)return;this._destroyRelatedRecordsFlowItemWidgets(),await this.viewModel.zoomTo({target:i});const o=f(i);this.open({features:[t],location:null!=o?o:void 0})}_focusRootFlowItemNode(e){this._rootFlowItemNode=e,this._focusRootFlowItem&&(this._focusRootFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusFeatureMenuFlowItemNode(e){this._featureMenuViewportNode=e,this._focusFeatureMenuFlowItem&&(this._focusFeatureMenuFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_setActiveFeature(e){const{viewModel:t}=this,i=e.currentTarget["data-feature-index"];t.activeFeature=t.features?.[i]||null}_removeActiveFeature(){this.viewModel.activeFeature=null}_selectFeature(e){const t=e.currentTarget["data-feature-index"];isNaN(t)||(this.viewModel.selectedFeatureIndex=t),this.featureMenuOpen=!1,this._focusFeatureMenuFlowItem=!0}_unobserveFeatureMenuObserver(){this._featureMenuIntersectionObserverNode&&this._featureMenuIntersectionObserver.unobserve(this._featureMenuIntersectionObserverNode)}_featureMenuIntersectionObserverCreated(e){this._unobserveFeatureMenuObserver(),this._featureMenuIntersectionObserver.observe(e),this._featureMenuIntersectionObserverNode=e}_getActionIcon(e){return e.icon?e.icon:e.image||e.className?void 0:"question"}_getActionTitle(e){const{messages:t,selectedFeature:i,messagesCommon:o}=this,{id:s}=e,r=i?.attributes,n=e.title??"",a="zoom-to-feature"===s?A(n,{messages:t}):"remove-selected-feature"===s?A(n,{messages:o}):"zoom-to-clustered-features"===s||"browse-clustered-features"===s?A(n,{messages:t}):e.title;return a&&r?A(a,r):a??""}_onMainKeydown(e){const t=i(e);"ArrowLeft"===t&&(e.stopPropagation(),this.previous()),"ArrowRight"===t&&(e.stopPropagation(),this.next())}_featureMenuViewportScrollTop(){this._featureMenuViewportNode&&this._featureMenuViewportNode.scrollContentTo({top:0})}_setContentFromFeatureWidget(){const{selectedFeatureWidget:e}=this;e&&(this.viewModel.content=e)}_setTitleFromFeatureWidget(){const{selectedFeatureWidget:e,messagesCommon:t}=this,i=e?.viewModel;e&&(this.viewModel.title="error"===i?.state?t?.errorMessage:i?.title||"")}_addSelectedFeatureIndexHandle(){const e=s((()=>this.viewModel?.selectedFeatureIndex),((e,t)=>this._selectedFeatureIndexUpdated(e,t)));this.addHandles(e,R)}_selectedFeatureIndexUpdated(e,t){const{featureCount:i}=this.viewModel;i&&e!==t&&-1!==e&&(this._destroyRelatedRecordsFlowItemWidgets(),this.featureMenuOpen=!1,this._rootFlowItemNode&&this._rootFlowItemNode.scrollContentTo({top:0}))}_triggerHeaderAction(e){const t=e.currentTarget;if(t.disabled)return;const i=t.dataset.actionUid,o=this.headerActions.find((({uid:e})=>e===i));o&&!o.disabled&&("toggle"===o?.type&&(o.value=!o.value),this.emit("trigger-header-action",{action:o}))}_triggerAction(e){const t=e.currentTarget;if(t.disabled)return;const i=t.dataset.actionUid,{allActions:o}=this.viewModel,s=o.findIndex((e=>e.uid===i)),r=o.at(s);r&&"toggle"===r.type&&(r.value=!r.value),this.viewModel.triggerAction(s)}_createSpinner(e){e&&(this._spinner=new c({view:e}),e.ui.add(this._spinner,{key:N,position:"manual",internal:!0}))}_wireUpView(e){this._destroySpinner(),e&&this.visibleElements?.spinner&&this._createSpinner(e)}_hideSpinner(){const{_spinner:e}=this;e&&(e.location=null,e.hide())}_viewReadyChange(e,t){e?this._wireUpView(this.viewModel?.view):t&&this.viewModel.clear()}_viewChange(e,t){e&&t&&this.viewModel.clear()}_destroySelectedFeatureWidget(){const{_feature:e}=this;e&&(e.viewModel=null,!e.destroyed&&e.destroy()),this._feature=null}_destroyRelatedRecordsFlowItemWidgets(){this._relatedRecordsFlowItems.removeAll().forEach((e=>{"showAllEnabled"in e.viewModel&&(e.viewModel.showAllEnabled=!1),e.viewModel=null,e.destroy()}))}_toggleScreenLocationEnabled(){const{viewModel:e}=this;e&&(e.screenLocationEnabled=e.active)}_displaySpinner(){const{_spinner:e}=this;if(!e)return;const{location:t,waitingForResult:i}=this.viewModel;i&&t?e.show({location:t}):e.hide()}_destroySpinner(){const{_spinner:e,view:t}=this;e&&(t?.ui?.remove(e,N),e.destroy(),this._spinner=null)}_spinnerEnabledChange(e){this._destroySpinner(),e&&this._createSpinner(this.viewModel?.view)}};e([a()],k.prototype,"_focusFeatureMenuFlowItem",void 0),e([a()],k.prototype,"_relatedRecordsFlowItems",void 0),e([a()],k.prototype,"_focusRootFlowItem",void 0),e([a()],k.prototype,"_hideActionText",null),e([a()],k.prototype,"_featureNavigationVisible",null),e([a()],k.prototype,"_isCollapsed",null),e([a()],k.prototype,"_collapseEnabled",null),e([a()],k.prototype,"collapsed",void 0),e([a()],k.prototype,"content",null),e([a()],k.prototype,"icon",void 0),e([a()],k.prototype,"featureMenuOpen",null),e([a()],k.prototype,"featureNavigationTop",void 0),e([a()],k.prototype,"features",null),e([a({type:_})],k.prototype,"headerActions",void 0),e([a()],k.prototype,"headingLevel",void 0),e([a()],k.prototype,"location",null),e([a()],k.prototype,"label",null),e([a(),y("esri/widgets/Features/t9n/Features")],k.prototype,"messages",void 0),e([a(),y("esri/t9n/common")],k.prototype,"messagesCommon",void 0),e([a()],k.prototype,"promises",null),e([a()],k.prototype,"responsiveActionsEnabled",void 0),e([a({readOnly:!0})],k.prototype,"selectedFeature",null),e([a()],k.prototype,"selectedFeatureIndex",null),e([a({readOnly:!0})],k.prototype,"selectedFeatureWidget",null),e([a()],k.prototype,"title",null),e([a()],k.prototype,"updateLocationEnabled",null),e([a()],k.prototype,"view",null),e([a({type:g}),I(["triggerAction","trigger-action"])],k.prototype,"viewModel",void 0),e([a({type:w,nonNullable:!0})],k.prototype,"visibleElements",void 0),e([a()],k.prototype,"visible",null),k=e([l("esri.widgets.Features")],k);const E=k;export{E as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import t from"../core/Collection.js";import{eventKey as i}from"../core/events.js";import o from"../core/Logger.js";import{watch as s,when as r}from"../core/reactiveUtils.js";import{throttle as n}from"../core/throttle.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/has.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import d from"./Feature.js";import c from"./Spinner.js";import u from"./Widget.js";import{css as h}from"./Feature/resources.js";import{FeatureContentMixin as p}from"./Feature/support/FeatureContentMixin.js";import{css as m}from"./Features/css.js";import v from"./Features/FeaturesRelatedRecords.js";import g from"./Features/FeaturesViewModel.js";import w from"./Features/FeaturesVisibleElements.js";import{ActionsCollection as _}from"./Popup/actions.js";import{getPointFromGeometry as f}from"./Popup/actionUtils.js";import{loadCalciteComponents as F}from"./support/componentsUtils.js";import{globalCss as M}from"./support/globalCss.js";import{Heading as b}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as y}from"./support/decorators/messageBundle.js";import{vmEvent as I}from"./support/decorators/vmEvent.js";import{tsx as C}from"./support/jsxFactory.js";import{substitute as A}from"../intl/substitute.js";import{formatNumber as x}from"../intl/number.js";const R="selected-index",j=0,N="features-spinner";let k=class extends(p(u)){constructor(e,i){super(e,i),this._featureMenuIntersectionObserverCallback=([e])=>{e?.isIntersecting&&null!=this.viewModel.featurePage&&this.viewModel.featurePage++},this._featureMenuIntersectionObserver=new IntersectionObserver(this._featureMenuIntersectionObserverCallback,{root:window.document}),this._featureMenuIntersectionObserverNode=null,this._focusFeatureMenuFlowItem=!1,this._spinner=null,this._feature=null,this._relatedRecordsFlowItems=new t,this._relatedRecordsWidget=new v({flowItems:this._relatedRecordsFlowItems}),this._focusRootFlowItem=!1,this._rootFlowItemNode=null,this._featureMenuViewportNode=null,this.collapsed=!1,this.icon=null,this.featureNavigationTop=!1,this.headerActions=new _,this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.responsiveActionsEnabled=!1,this.viewModel=new g,this.visibleElements=new w,this._renderAction=(e,t)=>{const i=this._getActionTitle(e),{type:o,active:s,uid:r,disabled:n,indicator:a}=e;return e.visible?C("calcite-action",{active:"toggle"===o&&e.value,appearance:"solid",bind:this,"data-action-uid":r,disabled:n,icon:this._getActionIcon(e),indicator:a,key:`action-${t}`,loading:s,onclick:this._triggerAction,scale:"s",text:i,title:this._hideActionText?i:void 0},this._getFallbackIcon(e)):null},this._openFeatureMenu=()=>{this.featureMenuOpen=!0},this._previousFeature=()=>{this.viewModel.selectedFeatureIndex--},this._nextFeature=()=>{this.viewModel.selectedFeatureIndex++},this._handleFeatureMenuBack=()=>{this._focusRootFlowItem=!0,this.featureMenuOpen=!1,this.viewModel.browseClusterEnabled=!1},this._displaySpinnerThrottled=n((()=>this._displaySpinner()),j),this._addSelectedFeatureIndexHandle(),this.addHandles([this._displaySpinnerThrottled,s((()=>this.viewModel?.active),(()=>this._toggleScreenLocationEnabled())),s((()=>this.viewModel?.active),(e=>this._relatedRecordsWidget.closed=!e)),s((()=>this.visibleElements?.closeButton),(e=>this._relatedRecordsWidget.closable=e)),s((()=>this.visibleElements?.spinner),(e=>this._spinnerEnabledChange(e))),s((()=>this.viewModel?.view),((e,t)=>this._viewChange(e,t))),s((()=>this.viewModel?.view?.ready),((e,t)=>this._viewReadyChange(e??!1,t??!1))),s((()=>[this.viewModel?.waitingForResult,this.viewModel?.location]),(()=>{this._hideSpinner(),this._displaySpinnerThrottled()})),s((()=>this.selectedFeatureWidget),(()=>this._destroyRelatedRecordsFlowItemWidgets())),s((()=>{const e=this.selectedFeatureWidget?.viewModel;return[e?.title,e?.state]}),(()=>this._setTitleFromFeatureWidget())),s((()=>{const e=this.selectedFeatureWidget?.viewModel;return[e?.content,e?.state]}),(()=>this._setContentFromFeatureWidget())),s((()=>this.viewModel?.featureViewModels),(()=>this._featureMenuViewportScrollTop())),this._relatedRecordsWidget.on("close",(()=>this.close())),this._relatedRecordsWidget.on("exit",(()=>this._destroyRelatedRecordsFlowItemWidgets())),this._relatedRecordsWidget.on("open-related-feature",(({feature:e})=>this._openRelatedFeature(e)))])}loadDependencies(){return F({action:()=>import("@esri/calcite-components/dist/components/calcite-action.js"),"action-bar":()=>import("@esri/calcite-components/dist/components/calcite-action-bar.js"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group.js"),button:()=>import("@esri/calcite-components/dist/components/calcite-button.js"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow.js"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item.js"),list:()=>import("@esri/calcite-components/dist/components/calcite-list.js"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item.js"),"list-item-group":()=>import("@esri/calcite-components/dist/components/calcite-list-item-group.js"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader.js")})}destroy(){this._destroyRelatedRecordsFlowItemWidgets(),this._destroySelectedFeatureWidget(),this._destroySpinner(),this._unobserveFeatureMenuObserver(),this._featureMenuIntersectionObserver?.disconnect(),this._relatedRecordsWidget?.destroy()}get _hideActionText(){if(!this.responsiveActionsEnabled)return!1;const e=this.view?.widthBreakpoint;return"xsmall"===e||"small"===e||"medium"===e}get _featureNavigationVisible(){return this.viewModel.active&&this.viewModel.featureCount>1&&this.visibleElements.featureNavigation}get _isCollapsed(){return this._collapseEnabled&&this.collapsed}get _collapseEnabled(){return this.visibleElements.collapseButton&&!!this.title&&!!this.content}get content(){return this.viewModel.content}set content(e){this.viewModel.content=e}get featureMenuOpen(){return this.viewModel.featureMenuOpen}set featureMenuOpen(e){this.viewModel.featureMenuOpen=e}get features(){return this.viewModel.features}set features(e){this.viewModel.features=e}get location(){return this.viewModel.location}set location(e){this.viewModel.location=e}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get promises(){return this.viewModel.promises}set promises(e){this.viewModel.promises=e}get selectedFeature(){return this.viewModel.selectedFeature}get selectedFeatureIndex(){return this.viewModel.selectedFeatureIndex}set selectedFeatureIndex(e){this.viewModel.selectedFeatureIndex=e}get selectedFeatureWidget(){const{_feature:e,headingLevel:t,_relatedRecordsFlowItems:i}=this,{selectedFeatureViewModel:o}=this.viewModel,s={title:!1};return o?(e?(e.viewModel=o,e.visibleElements=s):this._feature=new d({flowItems:i,headingLevel:t+1,viewModel:o,visibleElements:s}),this._feature):null}get title(){return this.viewModel.title}set title(e){this.viewModel.title=e}get updateLocationEnabled(){return this.viewModel.updateLocationEnabled}set updateLocationEnabled(e){this.viewModel.updateLocationEnabled=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}get visible(){return this.viewModel.visible}set visible(e){this.viewModel.visible=e}blur(){const{active:e}=this.viewModel;e||o.getLogger(this.declaredClass).warn("Features can only be blurred when currently active."),this._rootFlowItemNode?.blur()}clear(){return this.viewModel.clear()}close(){this.viewModel.visible=!1}fetchFeatures(e,t){return this.viewModel.fetchFeatures(e,t)}focus(){const{container:e}=this,{active:t}=this.viewModel;if(t||o.getLogger(this.declaredClass).warn("Features can only be blurred when currently active."),!e)return;const i=e.querySelectorAll("calcite-flow-item"),s=i[i?.length-1];this.scheduleRender(),requestAnimationFrame((()=>s?.setFocus()))}next(){return this.viewModel.next()}open(e){this.removeHandles(R);const t={collapsed:e?.collapsed??!1};this.set(t),this.viewModel.open(e),this.addHandles(r((()=>!this.viewModel.waitingForResult),(()=>this._addSelectedFeatureIndexHandle()),{once:!0}))}previous(){return this.viewModel.previous()}triggerAction(e){return this.viewModel.triggerAction(e)}render(){return C("div",{class:this.classes(m.base,M.widget,M.panel)},this._renderHeader(),this._renderContentContainer())}_renderFeatureNavigation(){return[this._renderPagination(),this._renderFeatureMenuButton()]}_renderHeader(){return!this.featureMenuOpen&&this.featureNavigationTop&&this._featureNavigationVisible?C("div",{class:m.header,key:"header-actions"},this._renderFeatureNavigation()):null}_renderFooter(){return this.featureMenuOpen||this.featureNavigationTop||!this._featureNavigationVisible?null:C("div",{class:m.footer,key:"footer-actions",slot:"footer"},this._renderFeatureNavigation())}_renderFeatureMenuButton(){const{messages:e,viewModel:t}=this,{featureCount:i,selectedFeatureIndex:o,pendingPromisesCount:s}=t;return C("calcite-action",{appearance:"solid",bind:this,icon:"list",key:"feature-menu-button",label:e.selectFeature,loading:s>0,onclick:this._openFeatureMenu,scale:"s",text:A(e.pageText,{index:x(o+1),total:x(i)}),textEnabled:!0,title:e.selectFeature})}_renderPagination(){const{previous:e,next:t}=this.messagesCommon.pagination;return C("calcite-action-bar",{class:m.paginationActionBar,expandDisabled:!0,key:"pagination-action-bar",layout:"horizontal",overflowActionsDisabled:!0,scale:"s"},C("calcite-action-group",{scale:"s"},C("calcite-action",{appearance:"solid",class:m.paginationPrevious,icon:"chevron-left",iconFlipRtl:!0,label:e,onclick:this._previousFeature,scale:"s",text:e,title:e}),C("calcite-action",{appearance:"solid",icon:"chevron-right",iconFlipRtl:!0,label:t,onclick:this._nextFeature,scale:"s",text:t,title:t})))}_renderFeatureMenuItem(e){const{selectedFeatureViewModel:t,featureViewModels:i}=this.viewModel,o=e===t,s=i.indexOf(e);return C("calcite-list-item",{bind:this,"data-feature-index":s,key:`feature-menu-item-${e.uid}`,onblur:this._removeActiveFeature,onfocus:this._setActiveFeature,onmouseleave:this._removeActiveFeature,onmouseover:this._setActiveFeature,selected:o,onCalciteListItemSelect:this._selectFeature},C("span",{innerHTML:e.title||this.messagesCommon.untitled,slot:"content"}))}_groupResultsByLayer(){const{featureViewModels:e}=this.viewModel,t=new Map;return e.forEach((e=>{const i=e?.graphic;if(!i)return;const o=i.sourceLayer??i.layer,s=t.get(o)??[];t.set(o,[...s,e])})),t}_renderFeatureMenu(){const{featureViewModels:e}=this.viewModel,t=this._groupResultsByLayer();return e.length?C("calcite-list",{selectionAppearance:"icon",selectionMode:"single"},Array.from(t.keys()).map((e=>C("calcite-list-item-group",{heading:e?.title??this.messagesCommon.untitled,key:e?.uid||"untitled"},t.get(e)?.map((e=>this._renderFeatureMenuItem(e))))))):null}_renderHeaderAction(e,t){return e.visible?C("calcite-action",{active:"toggle"===e.type&&e.value,appearance:"solid",bind:this,"data-action-uid":e.uid,disabled:e.disabled,icon:e.icon||"",indicator:e.indicator,key:`header-action-${t}`,loading:e.active,onclick:this._triggerHeaderAction,scale:"m",slot:"header-actions-end",text:e.title||"",title:e.title||""}):null}_renderHeaderActions(){return this.headerActions.map(((e,t)=>this._renderHeaderAction(e,t))).toArray()}_renderContentFeature(){const{headingLevel:e,visibleElements:t,_isCollapsed:i,_collapseEnabled:o,featureNavigationTop:s}=this,{title:r,active:n}=this.viewModel,a=t.heading&&r?r:"";return C("calcite-flow-item",{afterCreate:this._focusRootFlowItemNode,afterUpdate:this._focusRootFlowItemNode,bind:this,class:this.classes({[m.contentFeature]:!0,[m.flowItemCollapsed]:i}),closable:t.closeButton,closed:!n,collapsed:i,collapseDirection:s?"down":"up",collapsible:o,headingLevel:e,key:"root-flow-item",onkeydown:this._onMainKeydown,onCalciteFlowItemClose:this.close,onCalciteFlowItemToggle:this._handleCollapseToggle},a?C(b,{class:this.classes(m.featuresHeading,M.heading),innerHTML:a,key:"header-content",level:this.headingLevel,slot:"header-content"}):null,this._renderHeaderActions(),this._renderActionBar(),i?null:C("div",{class:this.classes(m.container,m.contentContainer)},this._renderContent()),this._renderFooter())}_renderFeatureMenuContainer(){const{viewModel:e,featureMenuOpen:t,messages:i,messagesCommon:o}=this,{active:s,featureViewModels:r,pendingPromisesCount:n}=e;return t?C("calcite-flow-item",{afterCreate:this._focusFeatureMenuFlowItemNode,afterUpdate:this._focusFeatureMenuFlowItemNode,bind:this,closable:!1,closed:!s,description:A(i.total,{total:r.length}),heading:i.selectFeature,key:"feature-menu",loading:e.waitingForContents,onCalciteFlowItemBack:this._handleFeatureMenuBack},n>0?C("calcite-loader",{class:m.loader,inline:!0,key:"feature-menu-loader",label:o.loading,scale:"m",slot:"header-actions-end"}):null,C("div",{class:m.container},this._renderFeatureMenu()),C("div",{afterCreate:this._featureMenuIntersectionObserverCreated,bind:this,class:m.featureMenuObserver}),C("calcite-button",{appearance:"transparent",onclick:this._handleFeatureMenuBack,slot:"footer-actions",width:"full"},o.back)):null}_renderContentContainer(){return C("calcite-flow",{key:"content-container"},this._renderContentFeature(),this._renderFeatureMenuContainer(),this._relatedRecordsWidget.render())}_getIconStyles(e){return{"background-image":e?`url(${e})`:""}}_getActionImage(e){const{selectedFeature:t}=this,i=t?.attributes,{image:o}=e;return o&&i?A(o,i):o??""}_getFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const o=this._getActionImage(e),s={[m.icon]:!!t,[m.actionImage]:!!o};return t&&(s[t]=!0),o||t?C("span",{"aria-hidden":"true",class:this.classes(m.icon,s),key:"icon",styles:o?this._getIconStyles(o):{}}):null}_renderActionBar(){return!this._isCollapsed&&this.visibleElements.actionBar&&this.viewModel.allActions?.length?C("calcite-action-bar",{expandDisabled:!0,expanded:!this._hideActionText,key:"header-action-bar",scale:"s",slot:"action-bar"},C("calcite-action-group",{overlayPositioning:"fixed",scale:"s"},this._renderActions())):null}_renderActions(){return this.viewModel.allActions.toArray().map(this._renderAction)}_renderContent(){const e=this.viewModel?.content;return e?"string"==typeof e?C("div",{class:h.contentNode,innerHTML:e,key:e}):this.renderNodeContent(e):null}_handleCollapseToggle(){this.collapsed=!this.collapsed}async _openRelatedFeature(e){await e.viewModel.updateGeometry();const t=e.graphic,i=t?.geometry;if(null==i||null==t)return;this._destroyRelatedRecordsFlowItemWidgets(),await this.viewModel.zoomTo({target:i});const o=f(i);this.open({features:[t],location:null!=o?o:void 0})}_focusRootFlowItemNode(e){this._rootFlowItemNode=e,this._focusRootFlowItem&&(this._focusRootFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_focusFeatureMenuFlowItemNode(e){this._featureMenuViewportNode=e,this._focusFeatureMenuFlowItem&&(this._focusFeatureMenuFlowItem=!1,requestAnimationFrame((()=>e?.setFocus())))}_setActiveFeature(e){const{viewModel:t}=this,i=e.currentTarget["data-feature-index"];t.activeFeature=t.features?.[i]||null}_removeActiveFeature(){this.viewModel.activeFeature=null}_selectFeature(e){const t=e.currentTarget["data-feature-index"];isNaN(t)||(this.viewModel.selectedFeatureIndex=t),this.featureMenuOpen=!1,this._focusFeatureMenuFlowItem=!0}_unobserveFeatureMenuObserver(){this._featureMenuIntersectionObserverNode&&this._featureMenuIntersectionObserver.unobserve(this._featureMenuIntersectionObserverNode)}_featureMenuIntersectionObserverCreated(e){this._unobserveFeatureMenuObserver(),this._featureMenuIntersectionObserver.observe(e),this._featureMenuIntersectionObserverNode=e}_getActionIcon(e){return e.icon?e.icon:e.image||e.className?void 0:"question"}_getActionTitle(e){const{messages:t,selectedFeature:i,messagesCommon:o}=this,{id:s}=e,r=i?.attributes,n=e.title??"",a="zoom-to-feature"===s?A(n,{messages:t}):"remove-selected-feature"===s?A(n,{messages:o}):"zoom-to-clustered-features"===s||"browse-clustered-features"===s?A(n,{messages:t}):e.title;return a&&r?A(a,r):a??""}_onMainKeydown(e){const t=i(e);"ArrowLeft"===t&&(e.stopPropagation(),this.previous()),"ArrowRight"===t&&(e.stopPropagation(),this.next())}_featureMenuViewportScrollTop(){this._featureMenuViewportNode&&this._featureMenuViewportNode.scrollContentTo({top:0})}_setContentFromFeatureWidget(){const{selectedFeatureWidget:e}=this;e&&(this.viewModel.content=e)}_setTitleFromFeatureWidget(){const{selectedFeatureWidget:e,messagesCommon:t}=this,i=e?.viewModel;e&&(this.viewModel.title="error"===i?.state?t?.errorMessage:i?.title||"")}_addSelectedFeatureIndexHandle(){const e=s((()=>this.viewModel?.selectedFeatureIndex),((e,t)=>this._selectedFeatureIndexUpdated(e,t)));this.addHandles(e,R)}_selectedFeatureIndexUpdated(e,t){const{featureCount:i}=this.viewModel;i&&e!==t&&-1!==e&&(this._destroyRelatedRecordsFlowItemWidgets(),this.featureMenuOpen=!1,this._rootFlowItemNode&&this._rootFlowItemNode.scrollContentTo({top:0}))}_triggerHeaderAction(e){const t=e.currentTarget;if(t.disabled)return;const i=t.dataset.actionUid,o=this.headerActions.find((({uid:e})=>e===i));o&&!o.disabled&&("toggle"===o?.type&&(o.value=!o.value),this.emit("trigger-header-action",{action:o}))}_triggerAction(e){const t=e.currentTarget;if(t.disabled)return;const i=t.dataset.actionUid,{allActions:o}=this.viewModel,s=o.findIndex((e=>e.uid===i)),r=o.at(s);r&&"toggle"===r.type&&(r.value=!r.value),this.viewModel.triggerAction(s)}_createSpinner(e){e&&(this._spinner=new c({view:e}),e.ui.add(this._spinner,{key:N,position:"manual",internal:!0}))}_wireUpView(e){this._destroySpinner(),e&&this.visibleElements?.spinner&&this._createSpinner(e)}_hideSpinner(){const{_spinner:e}=this;e&&(e.location=null,e.hide())}_viewReadyChange(e,t){e?this._wireUpView(this.viewModel?.view):t&&this.viewModel.clear()}_viewChange(e,t){e&&t&&this.viewModel.clear()}_destroySelectedFeatureWidget(){const{_feature:e}=this;e&&(e.viewModel=null,!e.destroyed&&e.destroy()),this._feature=null}_destroyRelatedRecordsFlowItemWidgets(){this._relatedRecordsFlowItems.removeAll().forEach((e=>{"showAllEnabled"in e.viewModel&&(e.viewModel.showAllEnabled=!1),e.viewModel=null,e.destroy()}))}_toggleScreenLocationEnabled(){const{viewModel:e}=this;e&&(e.screenLocationEnabled=e.active)}_displaySpinner(){const{_spinner:e}=this;if(!e)return;const{location:t,waitingForResult:i}=this.viewModel;i&&t?e.show({location:t}):e.hide()}_destroySpinner(){const{_spinner:e,view:t}=this;e&&(t?.ui?.remove(e,N),e.destroy(),this._spinner=null)}_spinnerEnabledChange(e){this._destroySpinner(),e&&this._createSpinner(this.viewModel?.view)}};e([a()],k.prototype,"_focusFeatureMenuFlowItem",void 0),e([a()],k.prototype,"_relatedRecordsFlowItems",void 0),e([a()],k.prototype,"_focusRootFlowItem",void 0),e([a()],k.prototype,"_hideActionText",null),e([a()],k.prototype,"_featureNavigationVisible",null),e([a()],k.prototype,"_isCollapsed",null),e([a()],k.prototype,"_collapseEnabled",null),e([a()],k.prototype,"collapsed",void 0),e([a()],k.prototype,"content",null),e([a()],k.prototype,"icon",void 0),e([a()],k.prototype,"featureMenuOpen",null),e([a()],k.prototype,"featureNavigationTop",void 0),e([a()],k.prototype,"features",null),e([a({type:_})],k.prototype,"headerActions",void 0),e([a()],k.prototype,"headingLevel",void 0),e([a()],k.prototype,"location",null),e([a()],k.prototype,"label",null),e([a(),y("esri/widgets/Features/t9n/Features")],k.prototype,"messages",void 0),e([a(),y("esri/t9n/common")],k.prototype,"messagesCommon",void 0),e([a()],k.prototype,"promises",null),e([a()],k.prototype,"responsiveActionsEnabled",void 0),e([a({readOnly:!0})],k.prototype,"selectedFeature",null),e([a()],k.prototype,"selectedFeatureIndex",null),e([a({readOnly:!0})],k.prototype,"selectedFeatureWidget",null),e([a()],k.prototype,"title",null),e([a()],k.prototype,"updateLocationEnabled",null),e([a()],k.prototype,"view",null),e([a({type:g}),I(["triggerAction","trigger-action"])],k.prototype,"viewModel",void 0),e([a({type:w,nonNullable:!0})],k.prototype,"visibleElements",void 0),e([a()],k.prototype,"visible",null),k=e([l("esri.widgets.Features")],k);const E=k;export{E as default};