@arcgis/core 4.32.0-next.20241220 → 4.32.0-next.20241221

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 (70) hide show
  1. package/WebLinkChart.js +1 -1
  2. package/assets/esri/core/workers/RemoteClient.js +1 -1
  3. package/assets/esri/core/workers/chunks/127c82cdb229434883b6.js +1 -0
  4. package/assets/esri/core/workers/chunks/16530347bd78dc6c2fcd.js +1 -0
  5. package/assets/esri/core/workers/chunks/{5119811063bfc97fb725.js → 1a713cc601c6fcd97d2f.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{48f6eb3b63fec1d3312d.js → 2d908c115ea18e813b95.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{11052103efe3d53a784e.js → 31d9f0a37a5d0a1c450b.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{e7c3199813070ff30a3d.js → 3bb94da29dac3367ecc6.js} +1 -1
  9. package/assets/esri/core/workers/chunks/3ed7c8138231de3a3b96.js +1 -0
  10. package/assets/esri/core/workers/chunks/{9cc9bac6e02ab241e852.js → 4746b7afa90ea3641e60.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{ce33d2b5f22a5c566661.js → 4b5dbdcad438cb2dd4bf.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{ee1ddf56549bb169509c.js → 6332da54159d72a6ce66.js} +1 -1
  13. package/assets/esri/core/workers/chunks/648d7d8fa19a2e772c89.js +1 -0
  14. package/assets/esri/core/workers/chunks/66b411119b8ffb99b9dc.js +1 -0
  15. package/assets/esri/core/workers/chunks/88c68881cbdf4e911832.js +1 -0
  16. package/assets/esri/core/workers/chunks/8e60de347b209a753c73.js +1 -0
  17. package/assets/esri/core/workers/chunks/{770d233254419b741616.js → 9ad7d095e614e7e8d7f5.js} +1 -1
  18. package/assets/esri/core/workers/chunks/9dd167db3f2e68b71cea.js +1 -0
  19. package/assets/esri/core/workers/chunks/{b15894bff153e0793ef4.js → 9f495ad57cdbfa90c5b8.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{d7b76bc7bff34abc2253.js → a0b3d70a1b0360084593.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{95af4dee29eb196b8ada.js → a90611cdc86190799560.js} +1 -1
  22. package/assets/esri/core/workers/chunks/{e213f4a1c95a33f80cdc.js → aedff36d3fec86abb9fb.js} +1 -1
  23. package/assets/esri/core/workers/chunks/{194013d377e7dd00845f.js → b611f46835edcd6eefcc.js} +1 -1
  24. package/assets/esri/core/workers/chunks/c1c216b0aebe86311fae.js +1 -0
  25. package/assets/esri/core/workers/chunks/{f2b195d04414417682d4.js → cbf57abb537e86c1dd7f.js} +1 -1
  26. package/assets/esri/core/workers/chunks/f9af0473878d960a02f2.js +1 -0
  27. package/assets/esri/core/workers/chunks/fa1c68f2ffcdff7986b6.js +1 -0
  28. package/assets/esri/core/workers/chunks/{0f1a7aeec18db5323365.js → fdd8a5eb07466541f1f9.js} +1 -1
  29. package/form/elements/GroupElement.js +1 -1
  30. package/form/elements/UtilityNetworkAssociationsElement.d.ts +4 -0
  31. package/form/elements/{UtilityNetworkAssociationElement.js → UtilityNetworkAssociationsElement.js} +1 -1
  32. package/form/elements.js +1 -1
  33. package/form/support/formUtils.js +1 -1
  34. package/interfaces.d.ts +178 -67
  35. package/layers/LinkChartLayer.js +1 -1
  36. package/layers/knowledgeGraph/supportUtils.js +1 -1
  37. package/layers/support/VideoElement.js +1 -1
  38. package/linkChart/OrganicLayoutSettings.js +1 -1
  39. package/package.json +1 -1
  40. package/portal/schemas/definitions.js +1 -1
  41. package/rest/knowledgeGraphService.js +1 -1
  42. package/rest/support/fileFormat.js +1 -1
  43. package/support/revision.js +1 -1
  44. package/views/3d/terrain/TileTexture.js +1 -1
  45. package/views/3d/webgl-engine/collections/Component/RenderSubmitSystem.js +1 -1
  46. package/views/3d/webgl-engine/core/renderPasses/RenderPassManager.js +1 -1
  47. package/views/3d/webgl-engine/lib/TextureCompressionWorker.js +1 -1
  48. package/views/3d/webgl-engine/lib/depthRangeUtils.js +1 -1
  49. package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
  50. package/views/support/TextureCompressionHelper.js +1 -1
  51. package/views/webgl/Texture.js +1 -1
  52. package/webscene/Slide.js +1 -1
  53. package/webscene/SlideLegend.d.ts +4 -0
  54. package/webscene/SlideLegend.js +5 -0
  55. package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
  56. package/widgets/FeatureForm.js +1 -1
  57. package/widgets/Print/PrintViewModel.js +1 -1
  58. package/widgets/Print/TemplateOptions.js +1 -1
  59. package/widgets/Print.js +1 -1
  60. package/assets/esri/core/workers/chunks/0e9bd990a8d0691fb9c8.js +0 -1
  61. package/assets/esri/core/workers/chunks/27933d6ffeebb5c13ab7.js +0 -1
  62. package/assets/esri/core/workers/chunks/2c084c0c324e3af56424.js +0 -1
  63. package/assets/esri/core/workers/chunks/48266c87363e7dcaefb3.js +0 -1
  64. package/assets/esri/core/workers/chunks/668679baf519ada9ae28.js +0 -1
  65. package/assets/esri/core/workers/chunks/737f381f2cfeddb96d15.js +0 -1
  66. package/assets/esri/core/workers/chunks/a68068b3151a14c4a0ad.js +0 -1
  67. package/assets/esri/core/workers/chunks/ad99308fb9678cdce917.js +0 -1
  68. package/assets/esri/core/workers/chunks/cc427e8f1b17744b6ea4.js +0 -1
  69. package/assets/esri/core/workers/chunks/dd4bd96dfb7f9921b774.js +0 -1
  70. package/assets/esri/core/workers/chunks/e1a03231e24293e66418.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{neverReached as n}from"../../core/compilerUtils.js";import s from"../../core/Evented.js";import i from"../../core/Logger.js";import{destroyMaybe as o}from"../../core/maybe.js";import r from"../../core/Promise.js";import{watch as a,whenOnce as l,on as u}from"../../core/reactiveUtils.js";import{templateHasKey as p}from"../../core/string.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as h}from"../../core/support/UpdatingHandles.js";import f from"../../form/FormTemplate.js";import{isUtilityNetworkAssociationElement as m,isGroupElement as g,isFieldElement as y,isRelationshipElement as _,isTextElement as x}from"../../form/support/formUtils.js";import v from"../../layers/support/ContingentValue.js";import{isEditableLayer as E}from"../../layers/support/editableLayers.js";import I from"../../layers/support/LayerContingentValuesCache.js";import{utc as C,unknown as F,system as b}from"../../time/timeZoneUtils.js";import{flattenFieldInputs as V,isGroupInput as w,flattenRelationshipInputs as j,parseFormTemplateString as A,isRelationshipInput as T,isFieldInput as M,isTextElementInput as N,getNormalizedFeatureTypeInfo as k,valueIsValidContingentValue as R}from"./featureFormUtils.js";import S from"./FieldInput.js";import{FormExpressionsManager as U}from"./FormExpressionsManager.js";import H from"./GroupInput.js";import Z from"./RelationshipInput.js";import L from"./TextElementInput.js";import P from"./UtilityNetworkAssociationInput.js";import{createFormExpressionArcadeExecutor as O}from"../support/forms/expressions/FormExpressionArcadeExecutor.js";const W=new t({attributes:{}}),G={field:["editableExpression","requiredExpression","valueExpression","visibilityExpression"],group:["visibilityExpression"],relationship:["editableExpression","visibilityExpression"],text:["visibilityExpression"],utilityNetworkAssociations:["editableExpression","visibilityExpression"]},$="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",D="#JSAPI_CONTINGENT_VALUE_ANY_HASH",z="#JSAPI_CONTINGENT_VALUE_NULL_HASH",J="esri.widgets.FeatureForm.FeatureFormViewModel",B=()=>i.getLogger(J);let K=class extends(r.EsriPromiseMixin(s.EventedAccessor)){constructor(e){super(e),this._expressionExecutorsInUse=new Set,this._expressionExecutorLookup=new Map,this._expressionsManager=null,this._contingentValuesCache=null,this._featureClone=W.clone(),this._initialFeature=W.clone(),this._timeZone=null,this._updatingHandles=new h,this.arcadeEditType="NA",this.contingencyConstraintViolations=new Map,this.disabled=!1,this.featureUtilityNetworkAssociationsViewModel=null,this.highlightHelper=null,this.inputs=[],this.map=null,this.callbacks=null,this.strict=!1,this.hasPendingSubtypeChoice=!1}initialize(){const e=a((()=>[this.layer,!!this.layer?.loaded,this.formTemplate,this.feature,this.timeZone,this.arcadeEditType]),(async([e,t])=>{null!=e&&(t?this._updatingHandles.addPromise(this._updateInputs()):e.load().catch((()=>{})))}),{equals:([e,t,n,s,i,o],[r,a,l,u,p,c])=>e===r&&t===a&&n===l&&s===u&&i===p&&o===c,initial:!0}),t=a((()=>this._arcadeContextInfo),(e=>{null!=this._expressionsManager&&(this._expressionsManager.arcadeContextInfo=e,this._updatingHandles.addPromise(this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated()))))})),n=a((()=>this.layer),(e=>{const t="subtype-sublayer"===e?.type?e.parent:"feature"===e?.type?e:null;t&&this.addResolvingPromise(I.createLoadedLayerContingentValuesCache(t).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.addHandles([e,t,n])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this.highlightHelper?.removeAll(),this._updatingHandles.destroy()}get _expressionInfosLookup(){return new Map(this.formTemplate?.expressionInfos?.map((e=>[e.name,e])))}get activeRelationshipInput(){return this.allRelationshipInputs.find((e=>e.relationshipId===this.relationshipId))}get _arcadeContextInfo(){const{_initialFeature:e,arcadeEditType:t,layer:n,map:s,spatialReference:i,timeZone:o}=this;return{layer:E(n)?n:null,originalFeature:e,editType:t,map:s,spatialReference:i,timeZone:o}}get allFieldInputs(){return V(this.inputs)}get allGroupInputs(){return this.inputs.filter(w)}get allRelationshipInputs(){return j(this.inputs)}get _layerFieldsByName(){return new Map(this.layer?.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){const t=this._get("feature");this._featureClone=e?e.clone():W.clone(),this._initialFeature=this._featureClone.clone(),this._expressionsManager&&(this._expressionsManager.feature=this._featureClone),e?(this._resetFieldInputValues(this._featureClone),this.allRelationshipInputs.forEach((t=>t.feature=e))):(this.inputs.forEach((e=>e.destroy())),this.inputs.length=0),t!==e&&(this.hasPendingSubtypeChoice=!1),this.contingencyConstraintViolations.clear(),this._set("feature",e)}get fieldsWithContingentValues(){if(null==this._contingentValuesCache)return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get formDescription(){const{formTemplate:e,layer:t}=this;return e?.description&&t?A({label:e.description,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formTitle(){const{formTemplate:e,layer:t}=this;return e?.title&&t?A({label:e.title,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formHeaderVisible(){const{activeRelationshipInput:e,formDescription:t,formTitle:n}=this;return!(e||!t&&!n)}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){this._override("layer",e)}get relationshipId(){return this._get("relationshipId")}set relationshipId(e){const t=this.allRelationshipInputs;if(null!=e&&e===this.relationshipId||t.forEach((e=>e.showAllEnabled=!1)),null!=e){const n=t.find((t=>t.relationshipId===e));n&&(n.showAllEnabled=!0)}this._set("relationshipId",e)}get spatialReference(){return this.layer?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){return this.layer?.loaded?"ready":"disabled"}get submittable(){return!!this.valid||this.allFieldInputs.filter((e=>!e.valid)).every((({submittable:e})=>e))}get timeZone(){const{layer:e}=this;if(e&&"datesInUnknownTimezone"in e&&e.datesInUnknownTimezone)return C;const t=e&&"preferredTimeZone"in e&&e.preferredTimeZone;return this._timeZone===F?t||C:this._timeZone||b}set timeZone(e){this._timeZone=e}get updating(){return this._updatingHandles.updating}get valid(){const e=this.allFieldInputs;return e.length>0&&e.every((({valid:e})=>e))}findField(e){return this.allFieldInputs.find((t=>t.name===e))}getFieldValueOptionsForField(e,t){const n=this.findField(e);if(!n)return[[],[],[]];const s="coded-value"===n.domain?.type?n.domain.codedValues.map((({name:e,code:t})=>({name:e,value:t}))):[],i=null==n.value||s.some((e=>e.value===n.value))?[]:[{name:`${n.value}`,value:n.value}],o=this.fieldsWithContingentValues.has(e)?this._getContingentValueOptionsForField(e,t):[];if(o.length>0){const e=new Set(o.map((e=>e.value)));return[o,s.filter((t=>!e.has(t.value))),i]}return[s,[],i]}getValue(e){const t=this.layer?.getField(e);if(null!=t)return this._featureClone.getAttribute(t.name)??null}setValue(e,t){const{_featureClone:n,strict:s}=this,i=this.findField(e);t=""===t?null:t,i&&n.getAttribute(e)!==t&&(i.value=t,s&&!i.valid||(this._afterValueChange(i),null!=this._expressionsManager&&this._updatingHandles.addPromise(this._expressionsManager.evaluateInvalidated([i.name]).finally((()=>this._afterExpressionsEvaluated())))))}getValues(){return{...this._featureClone.attributes}}overrideInitialFeature(e){this._initialFeature=e}submit(){const e=this.allFieldInputs,t=new Set(e.filter((e=>e.valid)).map((({name:e})=>e))),n=e.filter((e=>!e.valid)).map((({name:e})=>e)),s=this.getValues();if(this.validateContingencyConstraints(s,{includeIncompleteViolations:!0}).length>0)for(const[i,o]of this.contingencyConstraintViolations.entries())"error"===o.type&&(t.delete(i),n.push(i));this.emit("submit",{valid:[...t],invalid:n,values:s})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,s=new Map;if(this.contingencyConstraintViolations=s,null==n)return[];const{invalid:i,incomplete:o}=n.validateContingencyConstraints(e),r=[...i,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)s.set(e,a);return r}notifyFeatureGeometryChanged(){const{_expressionsManager:e,feature:t,_featureClone:n}=this;t&&(n.geometry=t.geometry,null!=e&&this._updatingHandles.addPromise(e.evaluateInvalidatedByGeometry().finally((()=>this._afterExpressionsEvaluated()))))}applySubtypeDefaults(e){const{defaultValues:t}=e,{allFieldInputs:n}=this;for(const{name:s}of n){const e=t[s];null!=e&&this.setValue(s,e)}}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}async _updateInputs(){this._stopExpressions();const{_featureClone:e,_initialFeature:t,arcadeEditType:n,formTemplate:s,inputs:i,layer:o,timeZone:r}=this;if(!o)return;const a={arcadeEditType:n,feature:e,initialFeature:t,layer:o,timeZone:r},l=i.slice(),u=s?.elements&&s.elements.length>0?await this._updateInputsUsingFormElements(l,s.elements,a):this._updateInputsUsingLayerFields(l,o?.fields,a);this.inputs=u,await this._startExpressions()}async _updateInputsUsingFormElements(e,t,n){const s=new Map;for(const r of e)if(w(r)){s.set(r.element,r);for(const e of r.inputs)e.element&&s.set(e.element,e)}else r.element&&s.set(r.element,r);const i=new Map,o=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:s,updatedElements:t.filter(q),sharedInitializationProperties:n,group:null,newExpressionExecutorPromises:i});for(const[r,a]of s.entries())s.delete(r),a.destroy();return await Promise.all(Array.from(i.values())),o}async _updateInputsUsingFormElementsRecursive(e){const{existingInputsByElement:t,updatedElements:n,sharedInitializationProperties:s,group:i,newExpressionExecutorPromises:o}=e,r=[];for(const a of n){const e=t.has(a),n=e?t.get(a):this._makeInputFromElement(a,s,i);if(n){if(r.push(n),await l((()=>!n.updating)),this._assignExpressionExecutors(n,a,o),e)if(t.delete(a),w(n)){const{feature:e,timeZone:t}=s;n.set({feature:e,timeZone:t})}else if(T(n)){const e=this.relationshipId===a.relationshipId;n.set(s),n.set({map:this.map,showAllEnabled:e})}else m(n)?(n.set(s),n.set({map:this.map})):n.set(s);if(g(a)){const e=a.elements.filter((e=>q(e)));n.inputs=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:t,updatedElements:e,sharedInitializationProperties:s,group:n,newExpressionExecutorPromises:o})}}}return r}_updateInputsUsingLayerFields(e,t,n){if(!Array.isArray(t))return B().warn(this.declaredClass,"No attribute fields found."),[];const s=new Map;for(const o of e)if(w(o)){for(const e of o.inputs)e.destroy();o.inputs.length=0,o.destroy()}else T(o)?o.destroy():M(o)&&(null!==o.element?o.destroy():s.set(o.field,o));const i=[];for(const o of t){const e=n.feature?.getAttribute(o.name)??null,t=s.get(o)??new S({field:o,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden});i.push(t.set({...n,value:e})),s.delete(o)}for(const[o,r]of s.entries())s.delete(o),r.destroy();return i}_resetFieldInputValues(e){for(const t of this.allFieldInputs)t.value=e.getAttribute(t.name)}_makeInputFromElement(e,t,s){return g(e)?Y(e,t):y(e)?this._makeFieldInputFromElement(e,t,s):_(e)?this._makeRelationshipInputFromElement(e,t,s):m(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):x(e)?Q(e,t):m(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):n()}_makeFieldInputFromElement(e,t,n){const{arcadeEditType:s,feature:i,initialFeature:o,layer:r,timeZone:a}=t,{fieldName:l}=e,u=l&&this._layerFieldsByName.get(l);return u?new S({arcadeEditType:s,element:e,field:u,value:i?.getAttribute(e.fieldName)??null,feature:i,initialFeature:o,layer:r,group:n,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden,timeZone:a}):null}_makeRelationshipInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t,a=new Z({element:e,feature:i,group:n,layer:o,map:s,timeZone:r});return a.addHandles(u((()=>a.relatedLayer),"edits",(()=>this._expressionsManager?.evaluateAsyncExpressions()))),a}_makeUtilityNetworkAssociationInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t;return new P({element:e,feature:i,group:n,layer:o,map:s,timeZone:r})}_assignExpressionExecutors(e,t,n){const s=G[t.type],i=[];for(const o of s){const s=`${o}Executor`;if(e[s]){this._useExecutor(e[s]);continue}const r=t[o];if(null!=r&&""!==r){const t=this._expressionInfosLookup.get(r)?.expression??r;i.push(this._getOrCreateExecutorForExpression(t,n).then((t=>{e[s]=this._useExecutor(t)})))}}return N(e)&&i.push(...this._assignTextElementExpressionExecutors(e,n)),i}_assignTextElementExpressionExecutors(e,t){const{_expressionInfosLookup:n}=this,s=[];for(const o of e.expressionsUsed){const r=n.get(o);null!=r?s.push(this._getOrCreateExecutorForExpression(r.expression,t).then((t=>e.setExpressionExecutor(o,this._useExecutor(t))))):i.getLogger(this).error("feature-form:expression-not-found",`Could not find expressionInfo object with name '${o}'`)}for(const i of e.fieldsUsed){const n=`return $feature['${i}'];`;s.push(this._getOrCreateExecutorForExpression(n,t).then((t=>e.setFieldExecutor(i,this._useExecutor(t)))))}return s}async _getOrCreateExecutorForExpression(e,t){const{_expressionExecutorLookup:n}=this;if(n.has(e))return n.get(e);if(t.has(e))return t.get(e);const s=O(e,this.layer);t.set(e,s);const i=await s;return n.set(e,i),i}_createExpressionsManager(e){const{_arcadeContextInfo:t,_featureClone:n,allFieldInputs:s,formTemplate:i}=this;this._expressionsManager=new U({executors:e,feature:n,arcadeContextInfo:t,fieldInputs:s,preserveFieldValuesWhenHidden:!0===i?.preserveFieldValuesWhenHidden})}async _startExpressions(){if(0===this._expressionExecutorsInUse.size)return;const e=Array.from(this._expressionExecutorsInUse);this._createExpressionsManager(e),await this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated()))}_stopExpressions(){this._expressionsManager=o(this._expressionsManager),this._expressionExecutorsInUse.clear()}_useExecutor(e){return this._expressionExecutorsInUse.add(e),e}_afterValueChange(e){const{name:t,value:n}=e,{_featureClone:s,formTemplate:i,layer:o}=this;if(!o)return;const r=s.getAttribute(t);s.setAttribute(t,n);const{typeFieldName:a,types:l}=k(o);if((e.isSubtypeField||t===a)&&n!==r){if("subtype-sublayer"===o.type){const e=o.parent?.findSublayerForFeature(s);this.feature&&(this.feature.sourceLayer=e),s.sourceLayer=e}const e=new Set;for(const t of l)if(t.domains&&"object"==typeof t.domains)for(const n of Object.keys(t.domains))e.add(n);for(const t of e){const e=this.findField(t);e&&e.notifyChange("domain")}this.notifyChange("joinedContingentValues")}if(null!=i){const{description:e,title:n}=i;n&&p(n,t)&&this.notifyChange("formTitle"),e&&p(e,t)&&this.notifyChange("formDescription")}this._emitChangeEvent(e)}_afterExpressionsEvaluated(){const{_featureClone:e}=this;for(const t of this.allFieldInputs)t.value!==e.getAttribute(t.name)&&this._afterValueChange(t)}_joinContingentValues(){const e=this._contingentValuesCache;if(null==e)return[];const{typeFieldName:t}=k(this.layer),n=t?this.getValue(t):null,s=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:i}=r,o=[];for(const s of e)s.isRetired||null!=s.subtype&&s.subtype.code!==n||o.push({values:s.values});o.length>0&&s.push({name:i,fields:t,contingencies:o})}const[i,o]=this._generateJoinPlan(s);return[...i.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],s=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const i=t.get(e),o=l,r=[i.name,o.name].sort().join("|");if(s.has(r))continue;n.push([i,o]),s.add(r),t.set(e,o)}else t.set(e,l);const i=new Set(n.flat()),o=new Set(e);for(const l of i)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),s=r.get(t);for(const i of s)n.add(i),a.set(i,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let s=t.shift(),i=this._generateJoinKey(n.fields,s.fields),o=new Set([...n.fields,...s.fields]),r=new Map;for(const l of n.contingencies){const[e]=this._hashContingency(l,i.codedValueFields,!0);r.has(e)?r.get(e)?.push(l):r.set(e,[l])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of s.contingencies){const[n,s]=this._hashContingency(t,i.codedValueFields),o=s?this._findMatchingContingenciesWithAnyHashMask(r,n):r.get(n);if(r.has(D)&&o?.push(...this._findMatchingContingenciesContainingAny(t,r.get(D),i.codedValueFields)),null!=o)for(const r of o){const n=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(r,t,i.rangeFields):this._joinContingencies(r,t);if(null==n)break;const[s]=this._hashContingency(n,a.codedValueFields,!0);e.has(s)?e.get(s)?.push(n):e.set(s,[n])}}r=e,s=n,i=a,o=new Set([...o,...s.fields])}const a=[];for(const l of s.contingencies){const[e,t]=this._hashContingency(l,i.codedValueFields),n=t?this._findMatchingContingenciesWithAnyHashMask(r,e):r.get(e);if(r.has(D)&&n.push(...this._findMatchingContingenciesContainingAny(l,r.get(D),i.codedValueFields)),null!=n)for(const s of n){const e=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(s,l,i.rangeFields):this._joinContingencies(s,l);null!=e&&a.push(e)}}return a}_joinContingencies(e,t){const n={values:{...e.values,...t.values}};for(const[s,i]of Object.entries(n.values))"any"===i.objectType&&null!=e.values[s]&&(n.values[s]=e.values[s]);return n}_joinContingenciesWithRangeDomains(e,t,n){const s=this._joinContingencies(e,t);for(const i of n){const n=e.values[i],o=t.values[i],{leftIsNull:r,rightIsNull:a,bothAreNull:l,leftIsAny:u,rightIsAny:p,bothAreAny:c,leftIsRange:d,rightIsRange:h}=this._compareObjectTypes(n.objectType,o.objectType);if(l||c)continue;if(r&&p||a&&u){s.values[i]=new v({objectType:"null"});continue}if(r&&h||a&&d)return null;u?(n.minValue=-1/0,n.maxValue=1/0):p&&(o.minValue=-1/0,o.maxValue=1/0);const f=Math.max(n.minValue,o.minValue),m=Math.min(n.maxValue,o.maxValue);if(f>m)return null;s.values[i]=new v({objectType:"range",minValue:f,maxValue:m})}return s}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const s=t.values[n],i=e.values[n];return"any"===s.objectType||"any"===i.objectType||s.codedValue?.code===i.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),s=[];for(const[i,o]of e){if(i===D)break;n.test(i)&&s.push(...o)}return s}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,s=Array.isArray(t)?new Set(t):t,i=n.size<s.size?n:s,o=i===n?s:n,{feature:r}=this,a=new Set,l=new Set;for(const u of i)if(o.has(u)){const e=this.layer?.getFieldDomain(u,{feature:r??void 0,excludeImpliedDomains:!0});if(null==e)continue;switch(e.type){case"coded-value":a.add(u);break;case"range":l.add(u)}}return{codedValueFields:[...a],rangeFields:[...l]}}_contingencyIsValid(e,t){const n={};for(const{name:s,value:i}of this.allFieldInputs)this.fieldsWithContingentValues.has(s)&&null!=i&&s!==e&&(n[s]=i);return Object.entries(n).every((([e,n])=>!t.values.hasOwnProperty(e)||R(n,t.values[e])))}_getContingentValueOptionsForField(e,t){const n=this.joinedContingentValues.slice(),s=new Map,i={code:"",name:t??"No value"};for(const o of n){const t=o.values[e];if("code"===t?.objectType||"null"===t?.objectType){const{code:n,name:r}=t.codedValue&&"null"!==t.objectType?t.codedValue:i;!s.has(n)&&this._contingencyIsValid(e,o)&&s.set(n,{name:r,value:n})}}return[...s.values()]}_hashContingency(e,t,n=!1){if(t.length<1)return[$,!1];const s=[];let i=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[D,!0];i=!0,s.push(`${o}:.*`)}else"null"===t.objectType?s.push(`${o}:${z}`):s.push(`${o}:${t.codedValue?.code}`)}return[s.sort().join("&"),i]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}get test(){return{featureClone:this._featureClone}}};function q(e){return"field"===e.type||"group"===e.type||"relationship"===e.type||"text"===e.type||"utilityNetworkAssociations"===e.type||(B().warn("form-info::unsupported-element-type","Only element types 'field', 'group' and 'relationship' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}function Y(e,t){const{feature:n,layer:s}=t;return new H({element:e,inputs:[],feature:n,layer:s})}function Q(e,t,n=null){const{feature:s,layer:i,timeZone:o}=t;return new L({element:e,feature:s,group:n,layer:i,timeZone:o})}e([c()],K.prototype,"_expressionInfosLookup",null),e([c()],K.prototype,"_featureClone",void 0),e([c()],K.prototype,"_timeZone",void 0),e([c()],K.prototype,"activeRelationshipInput",null),e([c()],K.prototype,"_arcadeContextInfo",null),e([c()],K.prototype,"allFieldInputs",null),e([c()],K.prototype,"allGroupInputs",null),e([c()],K.prototype,"allRelationshipInputs",null),e([c()],K.prototype,"_layerFieldsByName",null),e([c()],K.prototype,"arcadeEditType",void 0),e([c()],K.prototype,"contingencyConstraintViolations",void 0),e([c()],K.prototype,"disabled",void 0),e([c()],K.prototype,"feature",null),e([c()],K.prototype,"featureUtilityNetworkAssociationsViewModel",void 0),e([c()],K.prototype,"fieldsWithContingentValues",null),e([c({type:f})],K.prototype,"formTemplate",null),e([c()],K.prototype,"formDescription",null),e([c()],K.prototype,"formTitle",null),e([c()],K.prototype,"formHeaderVisible",null),e([c()],K.prototype,"highlightHelper",void 0),e([c()],K.prototype,"inputs",void 0),e([c()],K.prototype,"joinedContingentValues",null),e([c()],K.prototype,"layer",null),e([c()],K.prototype,"map",void 0),e([c()],K.prototype,"callbacks",void 0),e([c()],K.prototype,"relationshipId",null),e([c()],K.prototype,"spatialReference",null),e([c()],K.prototype,"state",null),e([c()],K.prototype,"strict",void 0),e([c()],K.prototype,"submittable",null),e([c()],K.prototype,"timeZone",null),e([c()],K.prototype,"updating",null),e([c()],K.prototype,"valid",null),e([c()],K.prototype,"hasPendingSubtypeChoice",void 0),e([c()],K.prototype,"getValues",null),e([c()],K.prototype,"submit",null),e([c()],K.prototype,"test",null),K=e([d(J)],K);const X=K;export{X as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{neverReached as n}from"../../core/compilerUtils.js";import s from"../../core/Evented.js";import i from"../../core/Logger.js";import{destroyMaybe as o}from"../../core/maybe.js";import r from"../../core/Promise.js";import{watch as a,whenOnce as l,on as u}from"../../core/reactiveUtils.js";import{templateHasKey as p}from"../../core/string.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/RandomLCG.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as h}from"../../core/support/UpdatingHandles.js";import f from"../../form/FormTemplate.js";import{isUtilityNetworkAssociationsElement as m,isGroupElement as g,isFieldElement as y,isRelationshipElement as _,isTextElement as x}from"../../form/support/formUtils.js";import v from"../../layers/support/ContingentValue.js";import{isEditableLayer as E}from"../../layers/support/editableLayers.js";import I from"../../layers/support/LayerContingentValuesCache.js";import{utc as C,unknown as F,system as b}from"../../time/timeZoneUtils.js";import{flattenFieldInputs as V,isGroupInput as w,flattenRelationshipInputs as j,parseFormTemplateString as A,isRelationshipInput as T,isFieldInput as M,isTextElementInput as N,getNormalizedFeatureTypeInfo as k,valueIsValidContingentValue as R}from"./featureFormUtils.js";import S from"./FieldInput.js";import{FormExpressionsManager as U}from"./FormExpressionsManager.js";import H from"./GroupInput.js";import Z from"./RelationshipInput.js";import L from"./TextElementInput.js";import P from"./UtilityNetworkAssociationInput.js";import{createFormExpressionArcadeExecutor as O}from"../support/forms/expressions/FormExpressionArcadeExecutor.js";const W=new t({attributes:{}}),G={field:["editableExpression","requiredExpression","valueExpression","visibilityExpression"],group:["visibilityExpression"],relationship:["editableExpression","visibilityExpression"],text:["visibilityExpression"],utilityNetworkAssociations:["editableExpression","visibilityExpression"]},$="#JSAPI_CONTINGENT_VALUE_EMPTY_HASH",D="#JSAPI_CONTINGENT_VALUE_ANY_HASH",z="#JSAPI_CONTINGENT_VALUE_NULL_HASH",J="esri.widgets.FeatureForm.FeatureFormViewModel",B=()=>i.getLogger(J);let K=class extends(r.EsriPromiseMixin(s.EventedAccessor)){constructor(e){super(e),this._expressionExecutorsInUse=new Set,this._expressionExecutorLookup=new Map,this._expressionsManager=null,this._contingentValuesCache=null,this._featureClone=W.clone(),this._initialFeature=W.clone(),this._timeZone=null,this._updatingHandles=new h,this.arcadeEditType="NA",this.contingencyConstraintViolations=new Map,this.disabled=!1,this.featureUtilityNetworkAssociationsViewModel=null,this.highlightHelper=null,this.inputs=[],this.map=null,this.callbacks=null,this.strict=!1,this.hasPendingSubtypeChoice=!1}initialize(){const e=a((()=>[this.layer,!!this.layer?.loaded,this.formTemplate,this.feature,this.timeZone,this.arcadeEditType]),(async([e,t])=>{null!=e&&(t?this._updatingHandles.addPromise(this._updateInputs()):e.load().catch((()=>{})))}),{equals:([e,t,n,s,i,o],[r,a,l,u,p,c])=>e===r&&t===a&&n===l&&s===u&&i===p&&o===c,initial:!0}),t=a((()=>this._arcadeContextInfo),(e=>{null!=this._expressionsManager&&(this._expressionsManager.arcadeContextInfo=e,this._updatingHandles.addPromise(this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated()))))})),n=a((()=>this.layer),(e=>{const t="subtype-sublayer"===e?.type?e.parent:"feature"===e?.type?e:null;t&&this.addResolvingPromise(I.createLoadedLayerContingentValuesCache(t).then((e=>{this._contingentValuesCache=e,this.notifyChange("fieldsWithContingentValues")})))}),{initial:!0});this.addHandles([e,t,n])}destroy(){this.feature=null,this.layer=null,this._contingentValuesCache=o(this._contingentValuesCache),this.highlightHelper?.removeAll(),this._updatingHandles.destroy()}get _expressionInfosLookup(){return new Map(this.formTemplate?.expressionInfos?.map((e=>[e.name,e])))}get activeRelationshipInput(){return this.allRelationshipInputs.find((e=>e.relationshipId===this.relationshipId))}get _arcadeContextInfo(){const{_initialFeature:e,arcadeEditType:t,layer:n,map:s,spatialReference:i,timeZone:o}=this;return{layer:E(n)?n:null,originalFeature:e,editType:t,map:s,spatialReference:i,timeZone:o}}get allFieldInputs(){return V(this.inputs)}get allGroupInputs(){return this.inputs.filter(w)}get allRelationshipInputs(){return j(this.inputs)}get _layerFieldsByName(){return new Map(this.layer?.fields.map((e=>[e.name,e])))}get feature(){return this._get("feature")}set feature(e){const t=this._get("feature");this._featureClone=e?e.clone():W.clone(),this._initialFeature=this._featureClone.clone(),this._expressionsManager&&(this._expressionsManager.feature=this._featureClone),e?(this._resetFieldInputValues(this._featureClone),this.allRelationshipInputs.forEach((t=>t.feature=e))):(this.inputs.forEach((e=>e.destroy())),this.inputs.length=0),t!==e&&(this.hasPendingSubtypeChoice=!1),this.contingencyConstraintViolations.clear(),this._set("feature",e)}get fieldsWithContingentValues(){if(null==this._contingentValuesCache)return new Set;const e=this._contingentValuesCache.fieldGroups.flatMap((e=>e.fields));return new Set(e)}get formTemplate(){return this.layer&&"formTemplate"in this.layer?this.layer.formTemplate:null}set formTemplate(e){void 0===e?this._clearOverride("formTemplate"):this._override("formTemplate",e)}get formDescription(){const{formTemplate:e,layer:t}=this;return e?.description&&t?A({label:e.description,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formTitle(){const{formTemplate:e,layer:t}=this;return e?.title&&t?A({label:e.title,attributes:this.getValues(),fieldsIndex:t.fieldsIndex,timeZone:this.timeZone}):null}get formHeaderVisible(){const{activeRelationshipInput:e,formDescription:t,formTitle:n}=this;return!(e||!t&&!n)}get joinedContingentValues(){return this._joinContingentValues()}get layer(){return this.feature?.sourceLayer&&"applyEdits"in this.feature.sourceLayer?this.feature.sourceLayer:null}set layer(e){this._override("layer",e)}get relationshipId(){return this._get("relationshipId")}set relationshipId(e){const t=this.allRelationshipInputs;if(null!=e&&e===this.relationshipId||t.forEach((e=>e.showAllEnabled=!1)),null!=e){const n=t.find((t=>t.relationshipId===e));n&&(n.showAllEnabled=!0)}this._set("relationshipId",e)}get spatialReference(){return this.layer?.spatialReference??null}set spatialReference(e){this._override("spatialReference",e)}get state(){return this.layer?.loaded?"ready":"disabled"}get submittable(){return!!this.valid||this.allFieldInputs.filter((e=>!e.valid)).every((({submittable:e})=>e))}get timeZone(){const{layer:e}=this;if(e&&"datesInUnknownTimezone"in e&&e.datesInUnknownTimezone)return C;const t=e&&"preferredTimeZone"in e&&e.preferredTimeZone;return this._timeZone===F?t||C:this._timeZone||b}set timeZone(e){this._timeZone=e}get updating(){return this._updatingHandles.updating}get valid(){const e=this.allFieldInputs;return e.length>0&&e.every((({valid:e})=>e))}findField(e){return this.allFieldInputs.find((t=>t.name===e))}getFieldValueOptionsForField(e,t){const n=this.findField(e);if(!n)return[[],[],[]];const s="coded-value"===n.domain?.type?n.domain.codedValues.map((({name:e,code:t})=>({name:e,value:t}))):[],i=null==n.value||s.some((e=>e.value===n.value))?[]:[{name:`${n.value}`,value:n.value}],o=this.fieldsWithContingentValues.has(e)?this._getContingentValueOptionsForField(e,t):[];if(o.length>0){const e=new Set(o.map((e=>e.value)));return[o,s.filter((t=>!e.has(t.value))),i]}return[s,[],i]}getValue(e){const t=this.layer?.getField(e);if(null!=t)return this._featureClone.getAttribute(t.name)??null}setValue(e,t){const{_featureClone:n,strict:s}=this,i=this.findField(e);t=""===t?null:t,i&&n.getAttribute(e)!==t&&(i.value=t,s&&!i.valid||(this._afterValueChange(i),null!=this._expressionsManager&&this._updatingHandles.addPromise(this._expressionsManager.evaluateInvalidated([i.name]).finally((()=>this._afterExpressionsEvaluated())))))}getValues(){return{...this._featureClone.attributes}}overrideInitialFeature(e){this._initialFeature=e}submit(){const e=this.allFieldInputs,t=new Set(e.filter((e=>e.valid)).map((({name:e})=>e))),n=e.filter((e=>!e.valid)).map((({name:e})=>e)),s=this.getValues();if(this.validateContingencyConstraints(s,{includeIncompleteViolations:!0}).length>0)for(const[i,o]of this.contingencyConstraintViolations.entries())"error"===o.type&&(t.delete(i),n.push(i));this.emit("submit",{valid:[...t],invalid:n,values:s})}validateContingencyConstraints(e,t){const{_contingentValuesCache:n}=this,s=new Map;if(this.contingencyConstraintViolations=s,null==n)return[];const{invalid:i,incomplete:o}=n.validateContingencyConstraints(e),r=[...i,...t?.includeIncompleteViolations?o:[]];for(const a of r)for(const e of a.fieldGroup.fields)s.set(e,a);return r}notifyFeatureGeometryChanged(){const{_expressionsManager:e,feature:t,_featureClone:n}=this;t&&(n.geometry=t.geometry,null!=e&&this._updatingHandles.addPromise(e.evaluateInvalidatedByGeometry().finally((()=>this._afterExpressionsEvaluated()))))}applySubtypeDefaults(e){const{defaultValues:t}=e,{allFieldInputs:n}=this;for(const{name:s}of n){const e=t[s];null!=e&&this.setValue(s,e)}}_emitChangeEvent({name:e,valid:t,value:n}){this.emit("value-change",{layer:this.layer,feature:this.feature,fieldName:e,value:n,valid:t})}async _updateInputs(){this._stopExpressions();const{_featureClone:e,_initialFeature:t,arcadeEditType:n,formTemplate:s,inputs:i,layer:o,timeZone:r}=this;if(!o)return;const a={arcadeEditType:n,feature:e,initialFeature:t,layer:o,timeZone:r},l=i.slice(),u=s?.elements&&s.elements.length>0?await this._updateInputsUsingFormElements(l,s.elements,a):this._updateInputsUsingLayerFields(l,o?.fields,a);this.inputs=u,await this._startExpressions()}async _updateInputsUsingFormElements(e,t,n){const s=new Map;for(const r of e)if(w(r)){s.set(r.element,r);for(const e of r.inputs)e.element&&s.set(e.element,e)}else r.element&&s.set(r.element,r);const i=new Map,o=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:s,updatedElements:t.filter(q),sharedInitializationProperties:n,group:null,newExpressionExecutorPromises:i});for(const[r,a]of s.entries())s.delete(r),a.destroy();return await Promise.all(Array.from(i.values())),o}async _updateInputsUsingFormElementsRecursive(e){const{existingInputsByElement:t,updatedElements:n,sharedInitializationProperties:s,group:i,newExpressionExecutorPromises:o}=e,r=[];for(const a of n){const e=t.has(a),n=e?t.get(a):this._makeInputFromElement(a,s,i);if(n){if(r.push(n),await l((()=>!n.updating)),this._assignExpressionExecutors(n,a,o),e)if(t.delete(a),w(n)){const{feature:e,timeZone:t}=s;n.set({feature:e,timeZone:t})}else if(T(n)){const e=this.relationshipId===a.relationshipId;n.set(s),n.set({map:this.map,showAllEnabled:e})}else m(n)?(n.set(s),n.set({map:this.map})):n.set(s);if(g(a)){const e=a.elements.filter((e=>q(e)));n.inputs=await this._updateInputsUsingFormElementsRecursive({existingInputsByElement:t,updatedElements:e,sharedInitializationProperties:s,group:n,newExpressionExecutorPromises:o})}}}return r}_updateInputsUsingLayerFields(e,t,n){if(!Array.isArray(t))return B().warn(this.declaredClass,"No attribute fields found."),[];const s=new Map;for(const o of e)if(w(o)){for(const e of o.inputs)e.destroy();o.inputs.length=0,o.destroy()}else T(o)?o.destroy():M(o)&&(null!==o.element?o.destroy():s.set(o.field,o));const i=[];for(const o of t){const e=n.feature?.getAttribute(o.name)??null,t=s.get(o)??new S({field:o,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden});i.push(t.set({...n,value:e})),s.delete(o)}for(const[o,r]of s.entries())s.delete(o),r.destroy();return i}_resetFieldInputValues(e){for(const t of this.allFieldInputs)t.value=e.getAttribute(t.name)}_makeInputFromElement(e,t,s){return g(e)?Y(e,t):y(e)?this._makeFieldInputFromElement(e,t,s):_(e)?this._makeRelationshipInputFromElement(e,t,s):m(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):x(e)?Q(e,t):m(e)?this._makeUtilityNetworkAssociationInputFromElement(e,t,s):n()}_makeFieldInputFromElement(e,t,n){const{arcadeEditType:s,feature:i,initialFeature:o,layer:r,timeZone:a}=t,{fieldName:l}=e,u=l&&this._layerFieldsByName.get(l);return u?new S({arcadeEditType:s,element:e,field:u,value:i?.getAttribute(e.fieldName)??null,feature:i,initialFeature:o,layer:r,group:n,preservesValueWhenHidden:this.formTemplate?.preserveFieldValuesWhenHidden,timeZone:a}):null}_makeRelationshipInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t,a=new Z({element:e,feature:i,group:n,layer:o,map:s,timeZone:r});return a.addHandles(u((()=>a.relatedLayer),"edits",(()=>this._expressionsManager?.evaluateAsyncExpressions()))),a}_makeUtilityNetworkAssociationInputFromElement(e,t,n=null){const{map:s}=this,{feature:i,layer:o,timeZone:r}=t;return new P({element:e,feature:i,group:n,layer:o,map:s,timeZone:r})}_assignExpressionExecutors(e,t,n){const s=G[t.type],i=[];for(const o of s){const s=`${o}Executor`;if(e[s]){this._useExecutor(e[s]);continue}const r=t[o];if(null!=r&&""!==r){const t=this._expressionInfosLookup.get(r)?.expression??r;i.push(this._getOrCreateExecutorForExpression(t,n).then((t=>{e[s]=this._useExecutor(t)})))}}return N(e)&&i.push(...this._assignTextElementExpressionExecutors(e,n)),i}_assignTextElementExpressionExecutors(e,t){const{_expressionInfosLookup:n}=this,s=[];for(const o of e.expressionsUsed){const r=n.get(o);null!=r?s.push(this._getOrCreateExecutorForExpression(r.expression,t).then((t=>e.setExpressionExecutor(o,this._useExecutor(t))))):i.getLogger(this).error("feature-form:expression-not-found",`Could not find expressionInfo object with name '${o}'`)}for(const i of e.fieldsUsed){const n=`return $feature['${i}'];`;s.push(this._getOrCreateExecutorForExpression(n,t).then((t=>e.setFieldExecutor(i,this._useExecutor(t)))))}return s}async _getOrCreateExecutorForExpression(e,t){const{_expressionExecutorLookup:n}=this;if(n.has(e))return n.get(e);if(t.has(e))return t.get(e);const s=O(e,this.layer);t.set(e,s);const i=await s;return n.set(e,i),i}_createExpressionsManager(e){const{_arcadeContextInfo:t,_featureClone:n,allFieldInputs:s,formTemplate:i}=this;this._expressionsManager=new U({executors:e,feature:n,arcadeContextInfo:t,fieldInputs:s,preserveFieldValuesWhenHidden:!0===i?.preserveFieldValuesWhenHidden})}async _startExpressions(){if(0===this._expressionExecutorsInUse.size)return;const e=Array.from(this._expressionExecutorsInUse);this._createExpressionsManager(e),await this._expressionsManager.evaluateAll().finally((()=>this._afterExpressionsEvaluated()))}_stopExpressions(){this._expressionsManager=o(this._expressionsManager),this._expressionExecutorsInUse.clear()}_useExecutor(e){return this._expressionExecutorsInUse.add(e),e}_afterValueChange(e){const{name:t,value:n}=e,{_featureClone:s,formTemplate:i,layer:o}=this;if(!o)return;const r=s.getAttribute(t);s.setAttribute(t,n);const{typeFieldName:a,types:l}=k(o);if((e.isSubtypeField||t===a)&&n!==r){if("subtype-sublayer"===o.type){const e=o.parent?.findSublayerForFeature(s);this.feature&&(this.feature.sourceLayer=e),s.sourceLayer=e}const e=new Set;for(const t of l)if(t.domains&&"object"==typeof t.domains)for(const n of Object.keys(t.domains))e.add(n);for(const t of e){const e=this.findField(t);e&&e.notifyChange("domain")}this.notifyChange("joinedContingentValues")}if(null!=i){const{description:e,title:n}=i;n&&p(n,t)&&this.notifyChange("formTitle"),e&&p(e,t)&&this.notifyChange("formDescription")}this._emitChangeEvent(e)}_afterExpressionsEvaluated(){const{_featureClone:e}=this;for(const t of this.allFieldInputs)t.value!==e.getAttribute(t.name)&&this._afterValueChange(t)}_joinContingentValues(){const e=this._contingentValuesCache;if(null==e)return[];const{typeFieldName:t}=k(this.layer),n=t?this.getValue(t):null,s=[];for(const r of e.fieldGroups){const{contingencies:e,fields:t,name:i}=r,o=[];for(const s of e)s.isRetired||null!=s.subtype&&s.subtype.code!==n||o.push({values:s.values});o.length>0&&s.push({name:i,fields:t,contingencies:o})}const[i,o]=this._generateJoinPlan(s);return[...i.flatMap((e=>this._joinFieldGroupContingencies(e))),...o.flatMap((e=>e.contingencies))]}_generateJoinPlan(e){const t=new Map,n=[],s=new Set;for(const l of e)for(const e of l.fields)if(t.has(e)){const i=t.get(e),o=l,r=[i.name,o.name].sort().join("|");if(s.has(r))continue;n.push([i,o]),s.add(r),t.set(e,o)}else t.set(e,l);const i=new Set(n.flat()),o=new Set(e);for(const l of i)o.delete(l);const r=new Map,a=new Map;for(const l of new Set(n.flat())){const e=Symbol(l.name);r.set(e,new Set([l])),a.set(l,e)}for(const[l,u]of n){const e=a.get(l),t=a.get(u);if(e===t)continue;const n=r.get(e),s=r.get(t);for(const i of s)n.add(i),a.set(i,e);r.delete(t)}return[[...r.values()].map((e=>[...e])),[...o]]}_joinFieldGroupContingencies(e){const t=e.slice(),n=t.shift();let s=t.shift(),i=this._generateJoinKey(n.fields,s.fields),o=new Set([...n.fields,...s.fields]),r=new Map;for(const l of n.contingencies){const[e]=this._hashContingency(l,i.codedValueFields,!0);r.has(e)?r.get(e)?.push(l):r.set(e,[l])}for(;t.length>0;){const e=new Map,n=t.shift(),a=this._generateJoinKey(o,n.fields);for(const t of s.contingencies){const[n,s]=this._hashContingency(t,i.codedValueFields),o=s?this._findMatchingContingenciesWithAnyHashMask(r,n):r.get(n);if(r.has(D)&&o?.push(...this._findMatchingContingenciesContainingAny(t,r.get(D),i.codedValueFields)),null!=o)for(const r of o){const n=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(r,t,i.rangeFields):this._joinContingencies(r,t);if(null==n)break;const[s]=this._hashContingency(n,a.codedValueFields,!0);e.has(s)?e.get(s)?.push(n):e.set(s,[n])}}r=e,s=n,i=a,o=new Set([...o,...s.fields])}const a=[];for(const l of s.contingencies){const[e,t]=this._hashContingency(l,i.codedValueFields),n=t?this._findMatchingContingenciesWithAnyHashMask(r,e):r.get(e);if(r.has(D)&&n.push(...this._findMatchingContingenciesContainingAny(l,r.get(D),i.codedValueFields)),null!=n)for(const s of n){const e=i.rangeFields.length>0?this._joinContingenciesWithRangeDomains(s,l,i.rangeFields):this._joinContingencies(s,l);null!=e&&a.push(e)}}return a}_joinContingencies(e,t){const n={values:{...e.values,...t.values}};for(const[s,i]of Object.entries(n.values))"any"===i.objectType&&null!=e.values[s]&&(n.values[s]=e.values[s]);return n}_joinContingenciesWithRangeDomains(e,t,n){const s=this._joinContingencies(e,t);for(const i of n){const n=e.values[i],o=t.values[i],{leftIsNull:r,rightIsNull:a,bothAreNull:l,leftIsAny:u,rightIsAny:p,bothAreAny:c,leftIsRange:d,rightIsRange:h}=this._compareObjectTypes(n.objectType,o.objectType);if(l||c)continue;if(r&&p||a&&u){s.values[i]=new v({objectType:"null"});continue}if(r&&h||a&&d)return null;u?(n.minValue=-1/0,n.maxValue=1/0):p&&(o.minValue=-1/0,o.maxValue=1/0);const f=Math.max(n.minValue,o.minValue),m=Math.min(n.maxValue,o.maxValue);if(f>m)return null;s.values[i]=new v({objectType:"range",minValue:f,maxValue:m})}return s}_findMatchingContingenciesContainingAny(e,t,n){return t.filter((t=>n.every((n=>{const s=t.values[n],i=e.values[n];return"any"===s.objectType||"any"===i.objectType||s.codedValue?.code===i.codedValue?.code}))))}_findMatchingContingenciesWithAnyHashMask(e,t){const n=RegExp(`${t}$`),s=[];for(const[i,o]of e){if(i===D)break;n.test(i)&&s.push(...o)}return s}_generateJoinKey(e,t){const n=Array.isArray(e)?new Set(e):e,s=Array.isArray(t)?new Set(t):t,i=n.size<s.size?n:s,o=i===n?s:n,{feature:r}=this,a=new Set,l=new Set;for(const u of i)if(o.has(u)){const e=this.layer?.getFieldDomain(u,{feature:r??void 0,excludeImpliedDomains:!0});if(null==e)continue;switch(e.type){case"coded-value":a.add(u);break;case"range":l.add(u)}}return{codedValueFields:[...a],rangeFields:[...l]}}_contingencyIsValid(e,t){const n={};for(const{name:s,value:i}of this.allFieldInputs)this.fieldsWithContingentValues.has(s)&&null!=i&&s!==e&&(n[s]=i);return Object.entries(n).every((([e,n])=>!t.values.hasOwnProperty(e)||R(n,t.values[e])))}_getContingentValueOptionsForField(e,t){const n=this.joinedContingentValues.slice(),s=new Map,i={code:"",name:t??"No value"};for(const o of n){const t=o.values[e];if("code"===t?.objectType||"null"===t?.objectType){const{code:n,name:r}=t.codedValue&&"null"!==t.objectType?t.codedValue:i;!s.has(n)&&this._contingencyIsValid(e,o)&&s.set(n,{name:r,value:n})}}return[...s.values()]}_hashContingency(e,t,n=!1){if(t.length<1)return[$,!1];const s=[];let i=!1;for(const o of t){const t=e.values[o];if("any"===t.objectType){if(n)return[D,!0];i=!0,s.push(`${o}:.*`)}else"null"===t.objectType?s.push(`${o}:${z}`):s.push(`${o}:${t.codedValue?.code}`)}return[s.sort().join("&"),i]}_compareObjectTypes(e,t){return{leftIsNull:"null"===e,rightIsNull:"null"===t,bothAreNull:"null"===e&&"null"===t,leftIsAny:"any"===e,rightIsAny:"any"===t,bothAreAny:"any"===e&&"any"===t,leftIsRange:"range"===e,rightIsRange:"range"===t}}get test(){return{featureClone:this._featureClone}}};function q(e){return"field"===e.type||"group"===e.type||"relationship"===e.type||"text"===e.type||"utilityNetworkAssociations"===e.type||(B().warn("form-info::unsupported-element-type","Only element types 'field', 'group' and 'relationship' are supported",`Element ${e.label} has unsupported type '${e.type}'`),!1)}function Y(e,t){const{feature:n,layer:s}=t;return new H({element:e,inputs:[],feature:n,layer:s})}function Q(e,t,n=null){const{feature:s,layer:i,timeZone:o}=t;return new L({element:e,feature:s,group:n,layer:i,timeZone:o})}e([c()],K.prototype,"_expressionInfosLookup",null),e([c()],K.prototype,"_featureClone",void 0),e([c()],K.prototype,"_timeZone",void 0),e([c()],K.prototype,"activeRelationshipInput",null),e([c()],K.prototype,"_arcadeContextInfo",null),e([c()],K.prototype,"allFieldInputs",null),e([c()],K.prototype,"allGroupInputs",null),e([c()],K.prototype,"allRelationshipInputs",null),e([c()],K.prototype,"_layerFieldsByName",null),e([c()],K.prototype,"arcadeEditType",void 0),e([c()],K.prototype,"contingencyConstraintViolations",void 0),e([c()],K.prototype,"disabled",void 0),e([c()],K.prototype,"feature",null),e([c()],K.prototype,"featureUtilityNetworkAssociationsViewModel",void 0),e([c()],K.prototype,"fieldsWithContingentValues",null),e([c({type:f})],K.prototype,"formTemplate",null),e([c()],K.prototype,"formDescription",null),e([c()],K.prototype,"formTitle",null),e([c()],K.prototype,"formHeaderVisible",null),e([c()],K.prototype,"highlightHelper",void 0),e([c()],K.prototype,"inputs",void 0),e([c()],K.prototype,"joinedContingentValues",null),e([c()],K.prototype,"layer",null),e([c()],K.prototype,"map",void 0),e([c()],K.prototype,"callbacks",void 0),e([c()],K.prototype,"relationshipId",null),e([c()],K.prototype,"spatialReference",null),e([c()],K.prototype,"state",null),e([c()],K.prototype,"strict",void 0),e([c()],K.prototype,"submittable",null),e([c()],K.prototype,"timeZone",null),e([c()],K.prototype,"updating",null),e([c()],K.prototype,"valid",null),e([c()],K.prototype,"hasPendingSubtypeChoice",void 0),e([c()],K.prototype,"getValues",null),e([c()],K.prototype,"submit",null),e([c()],K.prototype,"test",null),K=e([d(J)],K);const X=K;export{X 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.32/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import"../core/has.js";import i from"../core/Logger.js";import{getOrCreateMapValue as o}from"../core/MapUtils.js";import{createResolver as n}from"../core/promiseUtils.js";import{watch as s,whenOnce as a}from"../core/reactiveUtils.js";import{property as r}from"../core/accessorSupport/decorators/property.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import{isIntegerField as d}from"../layers/support/fieldUtils.js";import{getSubtypesFromLayer as p}from"../layers/support/layerUtils.js";import{isString as u}from"../support/guards.js";import c from"./Widget.js";import{Prompt as m}from"./Editor/components/Prompt.js";import h from"./Feature/FeatureUtilityNetworkAssociations.js";import v from"./Feature/FeatureUtilityNetworkAssociationType.js";import{css as g}from"./FeatureForm/css.js";import{isGroupInput as _,isFieldInput as b,isRelationshipInput as f,isTextElementInput as y,isUtilityNetworkAssociationInput as C,flattenInputs as F,isInputInGroupInput as w,isFieldElementWithInputType as R,getErrorMessageForFieldInput as k,getIconForFeature as O,isNumberFieldInput as I,subtypeChangeShouldPrompt as M}from"./FeatureForm/featureFormUtils.js";import T from"./FeatureForm/FeatureFormViewModel.js";import{loadCalciteComponents as N}from"./support/componentsUtils.js";import{getLabelForDateFieldValue as x,getIntlOptionsForField as V,numberingSystem as D,prepareISOFieldValueForDateComponents as L,prepareUnixFieldValueForDateComponents as S,normalizeTimeOnlyString as U,getISOFieldValueFromDateComponents as E,getUnixFieldValueFromDateComponents as A}from"./support/dateUtils.js";import{globalCss as j}from"./support/globalCss.js";import{Heading as P,incrementHeadingLevel as $}from"./support/Heading.js";import{setFocus as H}from"./support/widgetUtils.js";import{messageBundle as Z}from"./support/decorators/messageBundle.js";import{vmEvent as G}from"./support/decorators/vmEvent.js";import{tsx as W}from"./support/jsxFactory.js";import{substitute as B}from"../intl/substitute.js";const K="data-field-name";let q=class extends c{constructor(e,t){super(e,t),this._associationsWidgetsMap=new Map,this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName=null,this._pendingSubtypeChoice=null,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this._prompt=null,this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new T,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,callbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,callbacks:o}=this;i&&o?.addRelatedRecord&&o.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupToggle=this._onGroupToggle.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreate=this._afterComponentCreate.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this)}initialize(){this.addHandles([s((()=>this.feature),(()=>{this._inputsWithChanges.clear(),this._dateComponentMap.clear(),a((()=>!this.viewModel.updating)).then((()=>{const e=this._getFocusableInput("forward");this._syncGroupInputStates(),this._focusedFieldName=e?.name||null,this._attemptFocusOnNextRender=!0}))})),s((()=>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()}})),s((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange()))])}loadDependencies(){return N({block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),"text-area":()=>import("@esri/calcite-components/dist/components/calcite-text-area")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const{callbacks:e}=this;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get _subtypes(){return p(this.layer)}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get icon(){return"form-field"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get callbacks(){return this.viewModel.callbacks}set callbacks(e){this.viewModel.callbacks=e}get relationshipId(){return this.viewModel.relationshipId}set relationshipId(e){this.viewModel.relationshipId=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get showPrompt(){return e=>{this._prompt?.cancel?.(),this._prompt=e}}set showPrompt(e){this._overrideIfSome("showPrompt",e)}get clearPrompt(){return()=>this._prompt=null}set clearPrompt(e){this._overrideIfSome("clearPrompt",e)}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return W("div",{class:this.classes(g.base,j.widget,j.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return W("div",null,W("form",{class:g.form,novalidate:!0,onkeydown:this._onFormKeyDown,onsubmit:this._onFormSubmit},this._renderHeader(),this._renderContent()),this._prompt?W(m,{...this._prompt,headingLevel:this.headingLevel}):void 0)}_renderHeader(){const e=this.viewModel;if(!e.formHeaderVisible)return;const t=null!=e.formTitle&&W(P,{key:"title",level:this.headingLevel},e.formTitle),i=null!=e.formDescription&&W("p",{class:g.description,key:"description"},e.formDescription);return W("div",{class:g.formHeader},t,i)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderRelationshipInput(e.activeRelationshipInput):e.featureUtilityNetworkAssociationsViewModel?this._renderFeatureUtilityNetworkAssociationType():e.inputs.filter(t).filter((e=>e.visible)).map((e=>this._renderInput(e)))}_renderInput(e){return _(e)?this._renderGroup(e):b(e)?this._renderLabeledField(e):f(e)?this._renderRelationshipInput(e):y(e)?this._renderTextElementInput(e):C(e)?this._renderUtilityNetworkAssociationElementInput(e):void 0}_renderFeatureUtilityNetworkAssociationType(){const{viewModel:e}=this;return new v({viewModel:e.featureUtilityNetworkAssociationsViewModel}).render()}_renderUtilityNetworkAssociationElementInput(e){return o(this._associationsWidgetsMap,e,(()=>new h({onSelectAssociationType:({viewModel:e})=>this.viewModel.featureUtilityNetworkAssociationsViewModel=e,viewModel:e.associationsViewModel}))).render()}_renderDescriptionOrEmpty(e,t){return null==e?null:W("div",{class:this.classes(g.description),id:t},e)}_renderGroup(e){const{disabled:t,formTemplate:i,headingLevel:o}=this,{description:n,id:s,inputs:a,label:r,open:l}=e,d=a.filter((e=>e.visible)),p=this.viewModel.findField(this._focusedFieldName),u=p?.group===e,c="sequential"===this.groupDisplay;return W("calcite-block",{class:this.classes(g.group,c?g.groupSequential:null,u?g.groupActive:null,t?g.inputDisabled:null),collapsible:!0,"data-group":e,description:n||void 0,disabled:t,heading:r??"",headingLevel:i?.title?$(o):o,id:s,key:s,open:l,onCalciteBlockToggle:({currentTarget:t})=>this._onGroupToggle(t,e)},d.map((e=>this._renderInput(e))))}_getFocusableInput(e,t){const i=F(this.viewModel.inputs);let o;if("backward"===e&&i.reverse(),t)if(_(t)){const e=t.inputs.find((e=>e.visible));o=e?i.indexOf(e):0}else{let n;if(w(t)&&!t.group.open){const i=t.group.inputs.filter(b);n="forward"===e?i[i.length-1]:i[0]}else n=t;o=i.indexOf(n)+1}else o=0;for(let n=o;n<i.length;n++){const e=i[n];if(e.visible&&b(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:o,layer:n,required:s}=e,a={"aria-label":s?B(this.messages.requiredFieldLabel,{name:o}):o,class:g.label,key:`${n.id}-${i.uid}-${e.name}`},r=[W("div",{class:g.labelTextContent,key:"labelTextContainer"},o,s?W("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?W("label",{...a},r):W("calcite-label",{...a},r)}_renderFieldInput(e){const{dataType:t,domain:i,inputType:o,name:n}=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)}return"datetime-picker"===o||"date"===t?this._renderDateComponents(e,s):"number"===t?this._renderNumberComponent(e,s):this._renderStringComponent(e,s)}_renderStringComponent(e,t){return"text-area"===e.inputType?t.readOnly?W("calcite-input",{...t,loading:e.updating,type:"textarea",onCalciteInputInput:e=>this._saveValueFromComponent(e.currentTarget)}):W("calcite-text-area",{...t,resize:"vertical",onCalciteTextAreaInput:e=>this._saveValueFromComponent(e.currentTarget)}):W("calcite-input",{...t,loading:e.updating,type:"text",onCalciteInputInput:e=>this._saveValueFromComponent(e.currentTarget)})}_renderNumberComponent(e,t){return W("calcite-input-number",{...t,integer:d(e.field),loading:e.updating,type:"number",onCalciteInputNumberInput:e=>this._saveValueFromComponent(e.currentTarget)})}_renderDateComponents(e,t){const{field:i}=e;switch(i.type){case"date":return this._renderDateFieldComponents(e,t);case"date-only":return this._renderDateOnlyFieldComponent(e,t);case"time-only":return this._renderTimeOnlyFieldComponent(e,t);case"timestamp-offset":return this._renderTimestampOffsetFieldComponents(e,t);default:return this._renderReadOnlyComponent(e,x(i,t.value,{timeZone:this.timeZone,...V(i)}))}}_renderDateOnlyFieldComponent(e,t){const{range:i,valid:o,value:n}=e,{class:s,key:a,readOnly:r}=t,{rawMax:l,rawMin:d}=i;return W("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!o,class:s,"data-date-part":"date","data-field-name":t[K],key:`${a}-date-input`,max:u(l)?l:void 0,min:u(d)?d:void 0,numberingSystem:D,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:r,value:null!=n?`${n}`:void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)})}_renderTimeOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:n,key:s,readOnly:a}=t;return W("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:n,"data-date-part":"time","data-field-name":t[K],key:`${s}-time-input`,numberingSystem:D,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:a,step:e.timeStep,value:null!=o?`${o}`:void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)})}_renderTimestampOffsetFieldComponents(e,t){const{name:i,range:o,timeZone:n,valid:s,value:a}=e,{class:r,key:l,readOnly:d}=t,{rawMax:p,rawMin:u}=o,c={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!s,numberingSystem:D,overlayPositioning:"fixed",readOnly:d,[K]:i,onfocus:this._onComponentFocus},m=L(p,n),h=L(u,n),v=L(a,n);return W("div",{class:g.dateInputContainer,key:`${l}-date-time-container`},W("calcite-input-date-picker",{...c,class:r,"data-date-part":"date",key:`${l}-date-input`,max:m?.date??void 0,min:h?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:v.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),W("calcite-input-time-picker",{...c,class:r,"data-date-part":"time",key:`${l}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:e.timeStep,value:v.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),e.includeTimeOffset?W("calcite-input-time-zone",{...c,class:r,"data-date-part":"timeZone",disabled:d,key:`${l}-timezone-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:v.timeZoneOffset??"0",onCalciteInputTimeZoneChange:e=>this._saveValueFromDateComponent(e.currentTarget)}):null)}_renderDateFieldComponents(e,t){const{includeTime:i,name:o,valid:n,value:s}=e,{class:a,key:r,max:l,min:d,readOnly:p}=t,{timeZone:u}=this,c={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!n,numberingSystem:D,overlayPositioning:"fixed",readOnly:p,[K]:o,onfocus:this._onComponentFocus},m=S(s,u),h=S(l,u),v=S(d,u);return W("div",{class:g.dateInputContainer,key:`${r}-date-time-container`},W("calcite-input-date-picker",{...c,class:a,"data-date-part":"date",key:`${r}-date-input`,max:h?.date??void 0,min:v?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:m.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),i?W("calcite-input-time-picker",{...c,class:a,"data-date-part":"time",key:`${r}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:1,value:m.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return W("calcite-input",{...i,class:this.classes(g.fieldInput,g.inputDisabled),readOnly:!0,type:"text",value:null!=t?`${t}`:i.value})}_renderComboBoxComponent(e,t,i){const{value:o,name:n}=e,{viewModel:s,_inputsWithChanges:a}=this,r="INSERT"===s.arcadeEditType,l=a.has(n),d=null==o&&(!r||l),p=r&&e.showNoValueOptionEnabled&&!l?()=>{}:i.onblur;return W("calcite-combobox",{...i,allowCustomValues:!1,clearDisabled:!0,disabled:i.readOnly,onblur:p,overlayPositioning:"fixed",selectionMode:"single",onCalciteComboboxChange:({currentTarget:t})=>{d&&0===t.selectedItems.length?this._ignoreDeselectionOfNoValueOption(t):e.isSubtypeField&&0===t.selectedItems.length?t.value=`${e.value}`:this._saveValueFromComponent(t)}},this.renderComboboxOptionsList(e,t))}renderComboboxOptionsList(e,t){const{value:i,name:o}=e,{messages:n,messagesTemplates:s,viewModel:a,_inputsWithChanges:r}=this,[l,d,p]=t.map((e=>e.map((({name:e,value:t})=>W("calcite-combobox-item",{key:`#${t}`,selected:i===t,textLabel:e,value:`${t}`}))))),u=[];d.length>0&&u.push(W("calcite-combobox-item-group",{key:"other",label:s.other},d)),p.length>0&&u.push(W("calcite-combobox-item-group",{key:"unsupported",label:n.subtypes.unsupportedDomainGroupTitle},p)),u.length>0?u.unshift(W("calcite-combobox-item-group",{key:"recommended",label:n.recommended},l)):u.push(...l);const c="INSERT"===a.arcadeEditType,m=r.has(o),h=null==i&&(!c||m);return e.showNoValueOptionEnabled&&u.unshift(W("calcite-combobox-item",{key:"empty-option",selected:h,textLabel:e.showNoValueLabel||n.empty,value:""})),u}_renderRadioButtonComponents(e,t,i){const{name:o,value:n}=e,s=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="",a=e.showNoValueLabel||this.messages.empty,r=n===t||null===n;s.unshift(this._renderRadioButtonComponent({key:"empty-option",label:a,name:o,value:t,selected:r,props:i}))}return W("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:g.inputRadioGroup,"data-field-name":i[K],key:`${i.key}-radio-group`,layout:"vertical",name:i.key,required:i.required},s)}_renderSwitchComponent(e,t){const{value:i}=e,o=!!R(e.element,"switch")&&i===e.element.input.onValue;return W("calcite-switch",{...t,checked:o,class:g.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldName=null},onCalciteSwitchChange:e=>this._saveValueFromComponent(e.currentTarget)})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:o,label:n,props:s}){return W("calcite-label",{class:g.inputRadioLabel,key:e,layout:"inline"},W("calcite-radio-button",{...s,afterCreate:void 0,afterUpdate:void 0,checked:o,class:g.inputRadio,disabled:s.readOnly,name:t,onblur:()=>{this._focusedFieldName=null},value:i,onCalciteRadioButtonChange:({currentTarget:e})=>{e.checked&&this._saveValueFromComponent(e)}}),n)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.submittable?k(e,this.messages,this.timeZone):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?W("calcite-input-message",{icon:!0,status:"invalid"},i):this._inputsWithChanges.has(t)&&e.valueIsOutOfDomain?W("calcite-input-message",{icon:!0,status:"idle"},this.messages.subtypes.fieldOutOfSubtypeDomainWarning):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:o}=e,{callbacks:n}=this;if(!o||!n?.showAllRelatedRecords)return;const s=this.messages;return W("calcite-list-item",{description:B(s.totalCount,{count:t}),label:s.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},W("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:o}=e,{messages:n,callbacks:s}=this;if(t&&s?.addRelatedRecord&&o)return W("calcite-button",{alignment:"center",appearance:"outline-fill",class:g.centeredButton,disabled:e.updating||!e.originHasValidKey,iconStart:"plus",key:`${i}-add-button`,onclick:()=>{!e.updating&&e.originHasValidKey&&this._onAddRelatedRecordsClick(i,o)},round:!0,scale:"s",width:"full"},e.relatedLayerIsTable?n.addRecord:n.addFeature)}_renderRelatedRecordListItem(e,t){const{feature:i,description:o,title:n}=e,{feature:s,callbacks:a}=this,{highlightHelper:r}=this.viewModel,l=()=>{r?.removeAll(),a?.editRelatedRecord&&s&&a.editRelatedRecord({parentFeature:s,relationshipId:t,relatedFeature:i})},d=r?()=>r.add(i):void 0,p=r?()=>r.remove(i):void 0;return W("calcite-list-item",{bind:this,description:o,key:`${t}-${i.uid}`,label:n,onclick:l,onmouseenter:d,onmouseleave:p,value:n},W("calcite-icon",{icon:O(i),slot:"content-start"}),W("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),s=t>0?this._renderRelatedRecordsList(e):e.loaded?e.originHasValidKey?this._renderNoRelatedRecordsNotice():this._renderNoValidOriginKeyNotice(e):void 0;return W("calcite-label",{class:this.classes(g.label,g.relatedRecordsLabel),key:`relationship-${i}-container`},W("div",null,this._renderRelatedRecordsHeaderContainer(e),n,s),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return W("div",{class:g.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},W("span",null,e.label),t?W("calcite-loader",{inline:!0,key:"loader",label:this.messagesCommon?.loading,scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return W("calcite-list",{class:g.relatedRecordsList,label:this.messages?.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoValidOriginKeyNotice(e){const{messages:t}=this,i=e.relatedLayerIsTable?t.noOriginKeyRecord:t.noOriginKeyFeature,o=e.relationship?.keyField,n=this.viewModel.findField(o),s=e.layer?.fieldsIndex.get(o),a=n?.label||s?.alias||o,r=B(i,{relatedLayerName:e.relatedLayer?.title,originKeyField:a});return W("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},W("div",{slot:"message"},r))}_renderNoRelatedRecordsNotice(){return W("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},W("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return W("div",{afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved,bind:this,class:g.listObserver,key:"feature-observer"})}_renderTextElementInput(e){return W("div",{class:g.textElement,innerHTML:e.text,key:e.id})}getCommonInputProps(e){const{disabled:t}=this,{editable:i,hint:o,label:n,maxLength:s,minLength:a,name:r,range:{max:l,min:d},required:p,valid:u,value:c}=e,m=this._inputsWithChanges.has(r),h=!i||t;return{afterCreate:this._afterComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":u?"false":"true",class:this.classes(g.fieldInput,h?g.inputDisabled:null),status:m&&!u?"invalid":"idle",key:r,label:n,max:null!=l?l:void 0,min:null!=d?d:void 0,maxLength:s>-1?s:void 0,minLength:a>-1?a:void 0,placeholder:o??void 0,readOnly:h,required:p,value:null==c?"":`${c}`,onblur:this._onComponentBlur,onfocus:this._onComponentFocus,onkeydown:this._onComponentKeyDown,[K]:r}}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(K))}_afterDateComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e),i=e.dataset.datePart,o=this._dateComponentMap.get(t.name);if("valueAsDate"in e&&null!=e.value&&null!=t.value){const i=new ResizeObserver((()=>{switch(e.value=void 0,t.field.type){case"date":e.value=S(t.value,this.timeZone).date??"";break;case"timestamp-offset":e.value=L(t.value,this.timeZone).date??"";break;default:e.value=`${t.value}`}i.unobserve(e)}));i.observe(e)}if(null!=o)switch(i){case"date":o.date=e;break;case"time":o.time=e;break;case"timeZone":o.timeZone=e}else this._dateComponentMap.set(t.name,{[i]:e});this._afterDateComponentCreateOrUpdate(e)}_afterDateComponentCreateOrUpdate(e){this._afterComponentCreateOrUpdate(e)}_afterComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e);I(t)&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._afterComponentCreateOrUpdate(e)}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,i=e.querySelector("calcite-radio-button"),o=t||i;o&&this._afterComponentCreateOrUpdate(o)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),o=t.findField(this._focusedFieldName);this._attemptFocusOnNextRender&&o===i&&(this._attemptFocusOnNextRender=!1,w(i)&&(i.group.open=!0),H(e))}_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{timeZone:t}=this,i=this._getFieldInputFromHTMLElement(e),o=i.field.type,{name:n,range:s}=i,a=this._dateComponentMap.get(n);if(!a)return;let r=this.viewModel.getValue(n),l=null;"date-only"===o?l=Array.isArray(e.value)?e.value[0]:e.value:"time-only"===o?(r=U(r),l=U(e.value)):l="timestamp-offset"===o?null!=e.value?E({dateComponent:a.date,timeComponent:a.time,timeZoneComponent:a.timeZone,oldValue:r,defaultTimeZone:t}):null:null!=e.value?A({oldValue:r,dateComponent:a.date,timeComponent:a.time,timeZone:t,max:s.max,min:s.min}):null,null!==l&&e.value?r!==l&&this._updateFieldValue(n,l):this._updateFieldValue(n,null)}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e),i=this._parseValue(e),o=t.value;t.isSubtypeField&&M(this.layer,o,i)?this._pendingSubtypeChoice||i===o||(this._pendingSubtypeChoice=this._handleSubtypeChoice(t,i)):this._updateFieldValue(t.name,i)}async _handleSubtypeChoice(e,t){const{value:i,name:o}=e,{messages:s,viewModel:a,messagesCommon:r,_subtypes:l}=this;if(this._updateFieldValue(o,t),!l?.length)return;const d=l.find((e=>e.code===t)),p=l.find((e=>e.code===i))?.name??`${i}`;if(!d)return;a.hasPendingSubtypeChoice=!0;const u=n();let c="update-fields";const m=[{label:s.subtypes.useDefaultValuesOption,value:"update-fields"},{label:s.subtypes.keepCurrentValuesOption,value:"keep-existing"}],h={context:"info",title:s.subtypes.changeWarningTitle,message:B(s.subtypes.changeWarning,{originalType:p,newType:d.name}),radios:m,defaultRadioSelection:"update-fields",onRadioSelection:e=>c=e,actions:{primary:{label:r.apply,action:()=>u.resolve(c),type:"positive"},secondary:{label:r.cancel,type:"neutral",action:()=>u.resolve("undo")}},cancel:()=>u.reject()};try{this.showPrompt(h);switch(await u.promise){case"update-fields":a.applySubtypeDefaults(d),this._validateContingenciesForNonNullFields();break;case"keep-existing":this._validateContingenciesForNonNullFields();break;case"undo":this._updateFieldValue(e.name,i)}}finally{a.hasPendingSubtypeChoice=!1,this.clearPrompt(),this._pendingSubtypeChoice=null}}_onComponentKeyDown({key:e,target:t}){const i=this._getFieldInputFromHTMLElement(t);"Enter"===e&&w(i)&&!i.group.open&&(i.group.open=!0)}_updateFieldValue(e,t){const i=this.viewModel.getValue(e);this.viewModel.setValue(e,t),this._inputsWithChanges.add(e);i!==t&&this.viewModel.fieldsWithContingentValues.has(e)&&this._validateContingenciesForNonNullFields()}_validateContingenciesForNonNullFields(){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>null!=t)));this.viewModel.validateContingencyConstraints(e)}_parseValue(e){const t=this._getFieldInputFromHTMLElement(e),i=e.value;return R(t.element,"switch")?e.checked?t.element.input.onValue:t.element.input.offValue:null==i||""===i?null:"number"===t.dataType?"-0"===i||"-0."===i||"-0,"===i?i:parseFloat(i):"date"===t.field.type?parseFloat(i):i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:o}=e;0===o.length&&t&&"selected"in t?t.selected=!0:i.getLogger(this).warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupToggle(e,t){e.open?(t.open=!0,this._focusedFieldName=this._getFocusableInput("forward",t)?.name||null,this._attemptFocusOnNextRender=!0,"sequential"===this.groupDisplay&&this.viewModel.allGroupInputs.forEach((e=>{e!==t&&(e.open=!1)}))):t.open=!1,this.scheduleRender()}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}_onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;e&&this._listObserverNode&&e.showAllEnabled&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}_syncGroupInputStates(){if("sequential"!==this.groupDisplay)return;const e=this.viewModel.allGroupInputs;if(!e.length)return;const t=e.filter((e=>e.open));0===t.length?e[0].open=!0:t.length>1&&t.slice(1).forEach((e=>e.open=!1))}get test(){return{inputsWithChanges:this._inputsWithChanges,updateValue:this._saveValueFromComponent.bind(this)}}};e([r()],q.prototype,"_listObserverNode",void 0),e([r()],q.prototype,"_relatedRecordsEnabled",null),e([r()],q.prototype,"_prompt",void 0),e([r()],q.prototype,"_subtypes",null),e([r()],q.prototype,"disabled",null),e([r()],q.prototype,"feature",null),e([r()],q.prototype,"formTemplate",null),e([r()],q.prototype,"groupDisplay",void 0),e([r()],q.prototype,"headingLevel",void 0),e([r()],q.prototype,"icon",null),e([r()],q.prototype,"label",null),e([r()],q.prototype,"layer",null),e([r()],q.prototype,"map",null),e([r(),Z("esri/widgets/FeatureForm/t9n/FeatureForm")],q.prototype,"messages",void 0),e([r(),Z("esri/t9n/common")],q.prototype,"messagesCommon",void 0),e([r(),Z("esri/widgets/Feature/t9n/Feature")],q.prototype,"messagesFeature",void 0),e([r(),Z("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],q.prototype,"messagesTemplates",void 0),e([r()],q.prototype,"callbacks",null),e([r()],q.prototype,"relationshipId",null),e([r()],q.prototype,"spatialReference",null),e([r()],q.prototype,"strict",null),e([r()],q.prototype,"timeZone",null),e([r()],q.prototype,"showPrompt",null),e([r()],q.prototype,"clearPrompt",null),e([r(),G(["value-change","submit"])],q.prototype,"viewModel",void 0),e([r()],q.prototype,"test",null),q=e([l("esri.widgets.FeatureForm")],q);const z=q;export{z as default};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{isSome as t}from"../core/arrayUtils.js";import"../core/has.js";import i from"../core/Logger.js";import{getOrCreateMapValue as o}from"../core/MapUtils.js";import{createResolver as n}from"../core/promiseUtils.js";import{watch as s,whenOnce as a}from"../core/reactiveUtils.js";import{property as r}from"../core/accessorSupport/decorators/property.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import{isIntegerField as d}from"../layers/support/fieldUtils.js";import{getSubtypesFromLayer as p}from"../layers/support/layerUtils.js";import{isString as u}from"../support/guards.js";import c from"./Widget.js";import{Prompt as m}from"./Editor/components/Prompt.js";import h from"./Feature/FeatureUtilityNetworkAssociations.js";import v from"./Feature/FeatureUtilityNetworkAssociationType.js";import{css as g}from"./FeatureForm/css.js";import{isGroupInput as _,isFieldInput as b,isRelationshipInput as f,isTextElementInput as y,isUtilityNetworkAssociationInput as C,flattenInputs as F,isInputInGroupInput as w,isFieldElementWithInputType as R,getErrorMessageForFieldInput as k,getIconForFeature as O,isNumberFieldInput as I,subtypeChangeShouldPrompt as M}from"./FeatureForm/featureFormUtils.js";import T from"./FeatureForm/FeatureFormViewModel.js";import{loadCalciteComponents as N}from"./support/componentsUtils.js";import{getLabelForDateFieldValue as x,getIntlOptionsForField as V,numberingSystem as D,prepareISOFieldValueForDateComponents as L,prepareUnixFieldValueForDateComponents as S,normalizeTimeOnlyString as U,getISOFieldValueFromDateComponents as E,getUnixFieldValueFromDateComponents as A}from"./support/dateUtils.js";import{globalCss as j}from"./support/globalCss.js";import{Heading as P,incrementHeadingLevel as $}from"./support/Heading.js";import{setFocus as H}from"./support/widgetUtils.js";import{messageBundle as Z}from"./support/decorators/messageBundle.js";import{vmEvent as G}from"./support/decorators/vmEvent.js";import{tsx as W}from"./support/jsxFactory.js";import{substitute as B}from"../intl/substitute.js";const K="data-field-name";let q=class extends c{constructor(e,t){super(e,t),this._associationsWidgetsMap=new Map,this._attemptFocusOnNextRender=!1,this._dateComponentMap=new Map,this._inputsWithChanges=new Set,this._focusedFieldName=null,this._pendingSubtypeChoice=null,this._listObserverNode=null,this._listObserver=new IntersectionObserver((e=>{e.length&&e[0].isIntersecting&&this._incrementRelatedRecordPage()}),{root:window.document}),this._prompt=null,this.groupDisplay="all",this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesFeature=null,this.messagesTemplates=null,this.viewModel=new T,this._onShowAllRelatedRecordsClick=e=>{const{feature:t,callbacks:i}=this;t&&i?.showAllRelatedRecords&&i.showAllRelatedRecords({parentFeature:t,relationshipId:e})},this._onAddRelatedRecordsClick=(e,t)=>{const{feature:i,callbacks:o}=this;i&&o?.addRelatedRecord&&o.addRelatedRecord({parentFeature:i,relatedLayer:t,relationshipId:e})},this._onFormKeyDown=this._onFormKeyDown.bind(this),this._onFormSubmit=this._onFormSubmit.bind(this),this._onGroupToggle=this._onGroupToggle.bind(this),this._onComponentBlur=this._onComponentBlur.bind(this),this._onComponentFocus=this._onComponentFocus.bind(this),this._onComponentKeyDown=this._onComponentKeyDown.bind(this),this._afterComponentCreate=this._afterComponentCreate.bind(this),this._afterComponentCreateOrUpdate=this._afterComponentCreateOrUpdate.bind(this),this._afterDateComponentCreate=this._afterDateComponentCreate.bind(this),this._afterDateComponentCreateOrUpdate=this._afterDateComponentCreateOrUpdate.bind(this),this._afterRadioGroupCreateOrUpdate=this._afterRadioGroupCreateOrUpdate.bind(this)}initialize(){this.addHandles([s((()=>this.feature),(()=>{this._inputsWithChanges.clear(),this._dateComponentMap.clear(),a((()=>!this.viewModel.updating)).then((()=>{const e=this._getFocusableInput("forward");this._syncGroupInputStates(),this._focusedFieldName=e?.name||null,this._attemptFocusOnNextRender=!0}))})),s((()=>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()}})),s((()=>[this.viewModel.activeRelationshipInput,this._listObserverNode]),(()=>this._onObserverChange()))])}loadDependencies(){return N({block:()=>import("@esri/calcite-components/dist/components/calcite-block"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),"combobox-item-group":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item-group"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-message":()=>import("@esri/calcite-components/dist/components/calcite-input-message"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),"input-time-zone":()=>import("@esri/calcite-components/dist/components/calcite-input-time-zone"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),"radio-button":()=>import("@esri/calcite-components/dist/components/calcite-radio-button"),"radio-button-group":()=>import("@esri/calcite-components/dist/components/calcite-radio-button-group"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch"),"text-area":()=>import("@esri/calcite-components/dist/components/calcite-text-area")})}destroy(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode)}get _relatedRecordsEnabled(){const{callbacks:e}=this;return!(!e||!(e.addRelatedRecord||e.editRelatedRecord||e.showAllRelatedRecords))}get _subtypes(){return p(this.layer)}get disabled(){return this.viewModel.disabled}set disabled(e){this.viewModel.disabled=e}get feature(){return this.viewModel.feature}set feature(e){this.viewModel.feature=e}get formTemplate(){return this.viewModel.formTemplate}set formTemplate(e){this.viewModel.formTemplate=e}get icon(){return"form-field"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get callbacks(){return this.viewModel.callbacks}set callbacks(e){this.viewModel.callbacks=e}get relationshipId(){return this.viewModel.relationshipId}set relationshipId(e){this.viewModel.relationshipId=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get strict(){return this.viewModel.strict}set strict(e){this.viewModel.strict=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get showPrompt(){return e=>{this._prompt?.cancel?.(),this._prompt=e}}set showPrompt(e){this._overrideIfSome("showPrompt",e)}get clearPrompt(){return()=>this._prompt=null}set clearPrompt(e){this._overrideIfSome("clearPrompt",e)}getValues(){return this.viewModel.getValues()}submit(){return this.viewModel.submit()}render(){const{state:e}=this.viewModel;return W("div",{class:this.classes(g.base,j.widget,j.panel)},"ready"===e?this._renderForm():null)}_renderForm(){return W("div",null,W("form",{class:g.form,novalidate:!0,onkeydown:this._onFormKeyDown,onsubmit:this._onFormSubmit},this._renderHeader(),this._renderContent()),this._prompt?W(m,{...this._prompt,headingLevel:this.headingLevel}):void 0)}_renderHeader(){const e=this.viewModel;if(!e.formHeaderVisible)return;const t=null!=e.formTitle&&W(P,{key:"title",level:this.headingLevel},e.formTitle),i=null!=e.formDescription&&W("p",{class:g.description,key:"description"},e.formDescription);return W("div",{class:g.formHeader},t,i)}_renderContent(){const{viewModel:e}=this;return e.activeRelationshipInput?this._renderRelationshipInput(e.activeRelationshipInput):e.featureUtilityNetworkAssociationsViewModel?this._renderFeatureUtilityNetworkAssociationType():e.inputs.filter(t).filter((e=>e.visible)).map((e=>this._renderInput(e)))}_renderInput(e){return _(e)?this._renderGroup(e):b(e)?this._renderLabeledField(e):f(e)?this._renderRelationshipInput(e):y(e)?this._renderTextElementInput(e):C(e)?this._renderUtilityNetworkAssociationsElementInput(e):void 0}_renderFeatureUtilityNetworkAssociationType(){const{viewModel:e}=this;return new v({viewModel:e.featureUtilityNetworkAssociationsViewModel}).render()}_renderUtilityNetworkAssociationsElementInput(e){return o(this._associationsWidgetsMap,e,(()=>new h({onSelectAssociationType:({viewModel:e})=>this.viewModel.featureUtilityNetworkAssociationsViewModel=e,viewModel:e.associationsViewModel}))).render()}_renderDescriptionOrEmpty(e,t){return null==e?null:W("div",{class:this.classes(g.description),id:t},e)}_renderGroup(e){const{disabled:t,formTemplate:i,headingLevel:o}=this,{description:n,id:s,inputs:a,label:r,open:l}=e,d=a.filter((e=>e.visible)),p=this.viewModel.findField(this._focusedFieldName),u=p?.group===e,c="sequential"===this.groupDisplay;return W("calcite-block",{class:this.classes(g.group,c?g.groupSequential:null,u?g.groupActive:null,t?g.inputDisabled:null),collapsible:!0,"data-group":e,description:n||void 0,disabled:t,heading:r??"",headingLevel:i?.title?$(o):o,id:s,key:s,open:l,onCalciteBlockToggle:({currentTarget:t})=>this._onGroupToggle(t,e)},d.map((e=>this._renderInput(e))))}_getFocusableInput(e,t){const i=F(this.viewModel.inputs);let o;if("backward"===e&&i.reverse(),t)if(_(t)){const e=t.inputs.find((e=>e.visible));o=e?i.indexOf(e):0}else{let n;if(w(t)&&!t.group.open){const i=t.group.inputs.filter(b);n="forward"===e?i[i.length-1]:i[0]}else n=t;o=i.indexOf(n)+1}else o=0;for(let n=o;n<i.length;n++){const e=i[n];if(e.visible&&b(e))return e}return null}_renderLabeledField(e){const{dataType:t,feature:i,label:o,layer:n,required:s}=e,a={"aria-label":s?B(this.messages.requiredFieldLabel,{name:o}):o,class:g.label,key:`${n.id}-${i.uid}-${e.name}`},r=[W("div",{class:g.labelTextContent,key:"labelTextContainer"},o,s?W("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?W("label",{...a},r):W("calcite-label",{...a},r)}_renderFieldInput(e){const{dataType:t,domain:i,inputType:o,name:n}=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)}return"datetime-picker"===o||"date"===t?this._renderDateComponents(e,s):"number"===t?this._renderNumberComponent(e,s):this._renderStringComponent(e,s)}_renderStringComponent(e,t){return"text-area"===e.inputType?t.readOnly?W("calcite-input",{...t,loading:e.updating,type:"textarea",onCalciteInputInput:e=>this._saveValueFromComponent(e.currentTarget)}):W("calcite-text-area",{...t,resize:"vertical",onCalciteTextAreaInput:e=>this._saveValueFromComponent(e.currentTarget)}):W("calcite-input",{...t,loading:e.updating,type:"text",onCalciteInputInput:e=>this._saveValueFromComponent(e.currentTarget)})}_renderNumberComponent(e,t){return W("calcite-input-number",{...t,integer:d(e.field),loading:e.updating,type:"number",onCalciteInputNumberInput:e=>this._saveValueFromComponent(e.currentTarget)})}_renderDateComponents(e,t){const{field:i}=e;switch(i.type){case"date":return this._renderDateFieldComponents(e,t);case"date-only":return this._renderDateOnlyFieldComponent(e,t);case"time-only":return this._renderTimeOnlyFieldComponent(e,t);case"timestamp-offset":return this._renderTimestampOffsetFieldComponents(e,t);default:return this._renderReadOnlyComponent(e,x(i,t.value,{timeZone:this.timeZone,...V(i)}))}}_renderDateOnlyFieldComponent(e,t){const{range:i,valid:o,value:n}=e,{class:s,key:a,readOnly:r}=t,{rawMax:l,rawMin:d}=i;return W("calcite-input-date-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!o,class:s,"data-date-part":"date","data-field-name":t[K],key:`${a}-date-input`,max:u(l)?l:void 0,min:u(d)?d:void 0,numberingSystem:D,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:r,value:null!=n?`${n}`:void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)})}_renderTimeOnlyFieldComponent(e,t){const{valid:i,value:o}=e,{class:n,key:s,readOnly:a}=t;return W("calcite-input-time-picker",{afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!i,class:n,"data-date-part":"time","data-field-name":t[K],key:`${s}-time-input`,numberingSystem:D,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},onfocus:this._onComponentFocus,overlayPositioning:"fixed",readOnly:a,step:e.timeStep,value:null!=o?`${o}`:void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)})}_renderTimestampOffsetFieldComponents(e,t){const{name:i,range:o,timeZone:n,valid:s,value:a}=e,{class:r,key:l,readOnly:d}=t,{rawMax:p,rawMin:u}=o,c={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!s,numberingSystem:D,overlayPositioning:"fixed",readOnly:d,[K]:i,onfocus:this._onComponentFocus},m=L(p,n),h=L(u,n),v=L(a,n);return W("div",{class:g.dateInputContainer,key:`${l}-date-time-container`},W("calcite-input-date-picker",{...c,class:r,"data-date-part":"date",key:`${l}-date-input`,max:m?.date??void 0,min:h?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:v.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),W("calcite-input-time-picker",{...c,class:r,"data-date-part":"time",key:`${l}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:e.timeStep,value:v.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),e.includeTimeOffset?W("calcite-input-time-zone",{...c,class:r,"data-date-part":"timeZone",disabled:d,key:`${l}-timezone-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:v.timeZoneOffset??"0",onCalciteInputTimeZoneChange:e=>this._saveValueFromDateComponent(e.currentTarget)}):null)}_renderDateFieldComponents(e,t){const{includeTime:i,name:o,valid:n,value:s}=e,{class:a,key:r,max:l,min:d,readOnly:p}=t,{timeZone:u}=this,c={afterCreate:this._afterDateComponentCreate,afterUpdate:this._afterDateComponentCreateOrUpdate,"aria-invalid":!n,numberingSystem:D,overlayPositioning:"fixed",readOnly:p,[K]:o,onfocus:this._onComponentFocus},m=S(s,u),h=S(l,u),v=S(d,u);return W("div",{class:g.dateInputContainer,key:`${r}-date-time-container`},W("calcite-input-date-picker",{...c,class:a,"data-date-part":"date",key:`${r}-date-input`,max:h?.date??void 0,min:v?.date??void 0,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},value:m.date??void 0,onCalciteInputDatePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}),i?W("calcite-input-time-picker",{...c,class:a,"data-date-part":"time",key:`${r}-time-input`,onblur:e=>{this._focusedFieldName=null,this._saveValueFromDateComponent(e.target)},step:1,value:m.time??void 0,onCalciteInputTimePickerChange:e=>this._saveValueFromDateComponent(e.currentTarget)}):null)}_renderReadOnlyComponent(e,t){const i=this.getCommonInputProps(e);return W("calcite-input",{...i,class:this.classes(g.fieldInput,g.inputDisabled),readOnly:!0,type:"text",value:null!=t?`${t}`:i.value})}_renderComboBoxComponent(e,t,i){const{value:o,name:n}=e,{viewModel:s,_inputsWithChanges:a}=this,r="INSERT"===s.arcadeEditType,l=a.has(n),d=null==o&&(!r||l),p=r&&e.showNoValueOptionEnabled&&!l?()=>{}:i.onblur;return W("calcite-combobox",{...i,allowCustomValues:!1,clearDisabled:!0,disabled:i.readOnly,onblur:p,overlayPositioning:"fixed",selectionMode:"single",onCalciteComboboxChange:({currentTarget:t})=>{d&&0===t.selectedItems.length?this._ignoreDeselectionOfNoValueOption(t):e.isSubtypeField&&0===t.selectedItems.length?t.value=`${e.value}`:this._saveValueFromComponent(t)}},this.renderComboboxOptionsList(e,t))}renderComboboxOptionsList(e,t){const{value:i,name:o}=e,{messages:n,messagesTemplates:s,viewModel:a,_inputsWithChanges:r}=this,[l,d,p]=t.map((e=>e.map((({name:e,value:t})=>W("calcite-combobox-item",{key:`#${t}`,selected:i===t,textLabel:e,value:`${t}`}))))),u=[];d.length>0&&u.push(W("calcite-combobox-item-group",{key:"other",label:s.other},d)),p.length>0&&u.push(W("calcite-combobox-item-group",{key:"unsupported",label:n.subtypes.unsupportedDomainGroupTitle},p)),u.length>0?u.unshift(W("calcite-combobox-item-group",{key:"recommended",label:n.recommended},l)):u.push(...l);const c="INSERT"===a.arcadeEditType,m=r.has(o),h=null==i&&(!c||m);return e.showNoValueOptionEnabled&&u.unshift(W("calcite-combobox-item",{key:"empty-option",selected:h,textLabel:e.showNoValueLabel||n.empty,value:""})),u}_renderRadioButtonComponents(e,t,i){const{name:o,value:n}=e,s=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="",a=e.showNoValueLabel||this.messages.empty,r=n===t||null===n;s.unshift(this._renderRadioButtonComponent({key:"empty-option",label:a,name:o,value:t,selected:r,props:i}))}return W("calcite-radio-button-group",{afterCreate:this._afterRadioGroupCreateOrUpdate,afterUpdate:this._afterRadioGroupCreateOrUpdate,class:g.inputRadioGroup,"data-field-name":i[K],key:`${i.key}-radio-group`,layout:"vertical",name:i.key,required:i.required},s)}_renderSwitchComponent(e,t){const{value:i}=e,o=!!R(e.element,"switch")&&i===e.element.input.onValue;return W("calcite-switch",{...t,checked:o,class:g.inputSwitch,disabled:t.readOnly,onblur:()=>{this._focusedFieldName=null},onCalciteSwitchChange:e=>this._saveValueFromComponent(e.currentTarget)})}_renderRadioButtonComponent({key:e,name:t,value:i,selected:o,label:n,props:s}){return W("calcite-label",{class:g.inputRadioLabel,key:e,layout:"inline"},W("calcite-radio-button",{...s,afterCreate:void 0,afterUpdate:void 0,checked:o,class:g.inputRadio,disabled:s.readOnly,name:t,onblur:()=>{this._focusedFieldName=null},value:i,onCalciteRadioButtonChange:({currentTarget:e})=>{e.checked&&this._saveValueFromComponent(e)}}),n)}_renderAuxiliaryText(e){const t=e.name,i=this._inputsWithChanges.has(t)&&!e.submittable?k(e,this.messages,this.timeZone):null!=this.viewModel.contingencyConstraintViolations.get(t)?this.messages.validationErrors.valuesIncompatible:null!=e.valueExpressionExecutor&&e.valueExpressionExecutor.stale?this.messages.valueExpressionError:null;return null!=i?W("calcite-input-message",{icon:!0,status:"invalid"},i):this._inputsWithChanges.has(t)&&e.valueIsOutOfDomain?W("calcite-input-message",{icon:!0,status:"idle"},this.messages.subtypes.fieldOutOfSubtypeDomainWarning):this._renderDescriptionOrEmpty(e.description)}_renderShowAllRelatedRecordsListItem(e){const{featureCount:t,relationshipId:i,showAllActionVisible:o}=e,{callbacks:n}=this;if(!o||!n?.showAllRelatedRecords)return;const s=this.messages;return W("calcite-list-item",{description:B(s.totalCount,{count:t}),label:s.showAll,value:!0,onCalciteListItemSelect:()=>this._onShowAllRelatedRecordsClick(i)},W("calcite-icon",{icon:"list",scale:"s",slot:"content-end"}))}_renderAddRelatedRecordButton(e){const{canAddRelatedFeature:t,relationshipId:i,relatedLayer:o}=e,{messages:n,callbacks:s}=this;if(t&&s?.addRelatedRecord&&o)return W("calcite-button",{alignment:"center",appearance:"outline-fill",class:g.centeredButton,disabled:e.updating||!e.originHasValidKey,iconStart:"plus",key:`${i}-add-button`,onclick:()=>{!e.updating&&e.originHasValidKey&&this._onAddRelatedRecordsClick(i,o)},round:!0,scale:"s",width:"full"},e.relatedLayerIsTable?n.addRecord:n.addFeature)}_renderRelatedRecordListItem(e,t){const{feature:i,description:o,title:n}=e,{feature:s,callbacks:a}=this,{highlightHelper:r}=this.viewModel,l=()=>{r?.removeAll(),a?.editRelatedRecord&&s&&a.editRelatedRecord({parentFeature:s,relationshipId:t,relatedFeature:i})},d=r?()=>r.add(i):void 0,p=r?()=>r.remove(i):void 0;return W("calcite-list-item",{bind:this,description:o,key:`${t}-${i.uid}`,label:n,onclick:l,onmouseenter:d,onmouseleave:p,value:n},W("calcite-icon",{icon:O(i),slot:"content-start"}),W("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),s=t>0?this._renderRelatedRecordsList(e):e.loaded?e.originHasValidKey?this._renderNoRelatedRecordsNotice():this._renderNoValidOriginKeyNotice(e):void 0;return W("calcite-label",{class:this.classes(g.label,g.relatedRecordsLabel),key:`relationship-${i}-container`},W("div",null,this._renderRelatedRecordsHeaderContainer(e),n,s),this._renderAddRelatedRecordButton(e))}_renderRelatedRecordsHeaderContainer(e){const t=e.updating||!e.loaded;return W("div",{class:g.relatedRecordsHeader,key:`relationship-${e.relationshipId}-header`},W("span",null,e.label),t?W("calcite-loader",{inline:!0,key:"loader",label:this.messagesCommon?.loading,scale:"s",type:"indeterminate"}):void 0)}_renderRelatedRecordsList(e){const{relationshipId:t}=e;return W("calcite-list",{class:g.relatedRecordsList,label:this.messages?.relatedRecordsList},e.relatedFeatureInfos.map((e=>this._renderRelatedRecordListItem(e,t))),this._renderShowAllRelatedRecordsListItem(e),this._renderObserverNode())}_renderNoValidOriginKeyNotice(e){const{messages:t}=this,i=e.relatedLayerIsTable?t.noOriginKeyRecord:t.noOriginKeyFeature,o=e.relationship?.keyField,n=this.viewModel.findField(o),s=e.layer?.fieldsIndex.get(o),a=n?.label||s?.alias||o,r=B(i,{relatedLayerName:e.relatedLayer?.title,originKeyField:a});return W("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},W("div",{slot:"message"},r))}_renderNoRelatedRecordsNotice(){return W("calcite-notice",{icon:"information",kind:"brand",open:!0,scale:"s",width:"full"},W("div",{slot:"message"},this.messagesFeature.noRelatedFeatures))}_renderObserverNode(){if(this.viewModel.activeRelationshipInput?.showAllEnabled)return W("div",{afterCreate:this._afterListObserverCreated,afterRemoved:this._afterListObserverRemoved,bind:this,class:g.listObserver,key:"feature-observer"})}_renderTextElementInput(e){return W("div",{class:g.textElement,innerHTML:e.text,key:e.id})}getCommonInputProps(e){const{disabled:t}=this,{editable:i,hint:o,label:n,maxLength:s,minLength:a,name:r,range:{max:l,min:d},required:p,valid:u,value:c}=e,m=this._inputsWithChanges.has(r),h=!i||t;return{afterCreate:this._afterComponentCreate,afterUpdate:this._afterComponentCreateOrUpdate,"aria-invalid":u?"false":"true",class:this.classes(g.fieldInput,h?g.inputDisabled:null),status:m&&!u?"invalid":"idle",key:r,label:n,max:null!=l?l:void 0,min:null!=d?d:void 0,maxLength:s>-1?s:void 0,minLength:a>-1?a:void 0,placeholder:o??void 0,readOnly:h,required:p,value:null==c?"":`${c}`,onblur:this._onComponentBlur,onfocus:this._onComponentFocus,onkeydown:this._onComponentKeyDown,[K]:r}}_getFieldInputFromHTMLElement(e){return this.viewModel.findField(e.getAttribute(K))}_afterDateComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e),i=e.dataset.datePart,o=this._dateComponentMap.get(t.name);if("valueAsDate"in e&&null!=e.value&&null!=t.value){const i=new ResizeObserver((()=>{switch(e.value=void 0,t.field.type){case"date":e.value=S(t.value,this.timeZone).date??"";break;case"timestamp-offset":e.value=L(t.value,this.timeZone).date??"";break;default:e.value=`${t.value}`}i.unobserve(e)}));i.observe(e)}if(null!=o)switch(i){case"date":o.date=e;break;case"time":o.time=e;break;case"timeZone":o.timeZone=e}else this._dateComponentMap.set(t.name,{[i]:e});this._afterDateComponentCreateOrUpdate(e)}_afterDateComponentCreateOrUpdate(e){this._afterComponentCreateOrUpdate(e)}_afterComponentCreate(e){const t=this._getFieldInputFromHTMLElement(e);I(t)&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._afterComponentCreateOrUpdate(e)}_afterRadioGroupCreateOrUpdate(e){const t=e.selectedItem,i=e.querySelector("calcite-radio-button"),o=t||i;o&&this._afterComponentCreateOrUpdate(o)}_afterComponentCreateOrUpdate(e){const{viewModel:t}=this,i=this._getFieldInputFromHTMLElement(e),o=t.findField(this._focusedFieldName);this._attemptFocusOnNextRender&&o===i&&(this._attemptFocusOnNextRender=!1,w(i)&&(i.group.open=!0),H(e))}_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{timeZone:t}=this,i=this._getFieldInputFromHTMLElement(e),o=i.field.type,{name:n,range:s}=i,a=this._dateComponentMap.get(n);if(!a)return;let r=this.viewModel.getValue(n),l=null;"date-only"===o?l=Array.isArray(e.value)?e.value[0]:e.value:"time-only"===o?(r=U(r),l=U(e.value)):l="timestamp-offset"===o?null!=e.value?E({dateComponent:a.date,timeComponent:a.time,timeZoneComponent:a.timeZone,oldValue:r,defaultTimeZone:t}):null:null!=e.value?A({oldValue:r,dateComponent:a.date,timeComponent:a.time,timeZone:t,max:s.max,min:s.min}):null,null!==l&&e.value?r!==l&&this._updateFieldValue(n,l):this._updateFieldValue(n,null)}_saveValueFromComponent(e){const t=this._getFieldInputFromHTMLElement(e),i=this._parseValue(e),o=t.value;t.isSubtypeField&&M(this.layer,o,i)?this._pendingSubtypeChoice||i===o||(this._pendingSubtypeChoice=this._handleSubtypeChoice(t,i)):this._updateFieldValue(t.name,i)}async _handleSubtypeChoice(e,t){const{value:i,name:o}=e,{messages:s,viewModel:a,messagesCommon:r,_subtypes:l}=this;if(this._updateFieldValue(o,t),!l?.length)return;const d=l.find((e=>e.code===t)),p=l.find((e=>e.code===i))?.name??`${i}`;if(!d)return;a.hasPendingSubtypeChoice=!0;const u=n();let c="update-fields";const m=[{label:s.subtypes.useDefaultValuesOption,value:"update-fields"},{label:s.subtypes.keepCurrentValuesOption,value:"keep-existing"}],h={context:"info",title:s.subtypes.changeWarningTitle,message:B(s.subtypes.changeWarning,{originalType:p,newType:d.name}),radios:m,defaultRadioSelection:"update-fields",onRadioSelection:e=>c=e,actions:{primary:{label:r.apply,action:()=>u.resolve(c),type:"positive"},secondary:{label:r.cancel,type:"neutral",action:()=>u.resolve("undo")}},cancel:()=>u.reject()};try{this.showPrompt(h);switch(await u.promise){case"update-fields":a.applySubtypeDefaults(d),this._validateContingenciesForNonNullFields();break;case"keep-existing":this._validateContingenciesForNonNullFields();break;case"undo":this._updateFieldValue(e.name,i)}}finally{a.hasPendingSubtypeChoice=!1,this.clearPrompt(),this._pendingSubtypeChoice=null}}_onComponentKeyDown({key:e,target:t}){const i=this._getFieldInputFromHTMLElement(t);"Enter"===e&&w(i)&&!i.group.open&&(i.group.open=!0)}_updateFieldValue(e,t){const i=this.viewModel.getValue(e);this.viewModel.setValue(e,t),this._inputsWithChanges.add(e);i!==t&&this.viewModel.fieldsWithContingentValues.has(e)&&this._validateContingenciesForNonNullFields()}_validateContingenciesForNonNullFields(){const e=Object.fromEntries(Object.entries(this.getValues()).filter((([e,t])=>null!=t)));this.viewModel.validateContingencyConstraints(e)}_parseValue(e){const t=this._getFieldInputFromHTMLElement(e),i=e.value;return R(t.element,"switch")?e.checked?t.element.input.onValue:t.element.input.offValue:null==i||""===i?null:"number"===t.dataType?"-0"===i||"-0."===i||"-0,"===i?i:parseFloat(i):"date"===t.field.type?parseFloat(i):i}_ignoreDeselectionOfNoValueOption(e){const{firstChild:t,selectedItems:o}=e;0===o.length&&t&&"selected"in t?t.selected=!0:i.getLogger(this).warnOnce("Failed to override user attempt to deselect 'No value' option.")}_onGroupToggle(e,t){e.open?(t.open=!0,this._focusedFieldName=this._getFocusableInput("forward",t)?.name||null,this._attemptFocusOnNextRender=!0,"sequential"===this.groupDisplay&&this.viewModel.allGroupInputs.forEach((e=>{e!==t&&(e.open=!1)}))):t.open=!1,this.scheduleRender()}_onFormSubmit(e){e.preventDefault()}_onFormKeyDown(e){"Enter"===e.key&&this.viewModel.submit()}_afterListObserverCreated(e){this.viewModel.activeRelationshipInput&&(this._listObserverNode=e)}_afterListObserverRemoved(){this._listObserverNode=null}_onObserverChange(){this._listObserverNode&&this._listObserver.unobserve(this._listObserverNode);const e=this.viewModel.activeRelationshipInput;e&&this._listObserverNode&&e.showAllEnabled&&this._listObserver.observe(this._listObserverNode)}_incrementRelatedRecordPage(){const e=this.viewModel.activeRelationshipInput;e?.incrementPage()}_syncGroupInputStates(){if("sequential"!==this.groupDisplay)return;const e=this.viewModel.allGroupInputs;if(!e.length)return;const t=e.filter((e=>e.open));0===t.length?e[0].open=!0:t.length>1&&t.slice(1).forEach((e=>e.open=!1))}get test(){return{inputsWithChanges:this._inputsWithChanges,updateValue:this._saveValueFromComponent.bind(this)}}};e([r()],q.prototype,"_listObserverNode",void 0),e([r()],q.prototype,"_relatedRecordsEnabled",null),e([r()],q.prototype,"_prompt",void 0),e([r()],q.prototype,"_subtypes",null),e([r()],q.prototype,"disabled",null),e([r()],q.prototype,"feature",null),e([r()],q.prototype,"formTemplate",null),e([r()],q.prototype,"groupDisplay",void 0),e([r()],q.prototype,"headingLevel",void 0),e([r()],q.prototype,"icon",null),e([r()],q.prototype,"label",null),e([r()],q.prototype,"layer",null),e([r()],q.prototype,"map",null),e([r(),Z("esri/widgets/FeatureForm/t9n/FeatureForm")],q.prototype,"messages",void 0),e([r(),Z("esri/t9n/common")],q.prototype,"messagesCommon",void 0),e([r(),Z("esri/widgets/Feature/t9n/Feature")],q.prototype,"messagesFeature",void 0),e([r(),Z("esri/widgets/FeatureTemplates/t9n/FeatureTemplates")],q.prototype,"messagesTemplates",void 0),e([r()],q.prototype,"callbacks",null),e([r()],q.prototype,"relationshipId",null),e([r()],q.prototype,"spatialReference",null),e([r()],q.prototype,"strict",null),e([r()],q.prototype,"timeZone",null),e([r()],q.prototype,"showPrompt",null),e([r()],q.prototype,"clearPrompt",null),e([r(),G(["value-change","submit"])],q.prototype,"viewModel",void 0),e([r()],q.prototype,"test",null),q=e([l("esri.widgets.FeatureForm")],q);const z=q;export{z 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.32/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../chunks/tslib.es6.js";import"../../geometry.js";import e from"../../request.js";import{isSome as i}from"../../core/arrayUtils.js";import s from"../../core/Collection.js";import o from"../../core/Error.js";import{JSONMap as a}from"../../core/jsonMap.js";import{clone as r}from"../../core/lang.js";import l from"../../core/Loadable.js";import{isAbortError as n}from"../../core/promiseUtils.js";import p from"../../core/ReactiveMap.js";import{watch as m,initial as h}from"../../core/reactiveUtils.js";import{createScreenPoint as u}from"../../core/screenUtils.js";import{unitType as d,convertUnit as c,getMetersPerUnitForSR as y,inchesPerMeter as f}from"../../core/unitUtils.js";import{property as v}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import{subclass as T}from"../../core/accessorSupport/decorators/subclass.js";import{formatDate as w,convertDateFormatToIntlOptions as _}from"../../intl/date.js";import{getLanguage as I}from"../../intl/locale.js";import g from"../../portal/Portal.js";import O from"../../portal/PortalQueryParams.js";import{reArcGISOnlineDomain as b}from"../../portal/support/urlUtils.js";import{execute as x,getTasks as P}from"../../rest/print.js";import{formatJsonMap as S}from"../../rest/support/fileFormat.js";import{fromJSON as U}from"../../rest/support/layoutTemplate.js";import j from"../../rest/support/PrintParameters.js";import E from"../../rest/support/PrintTemplate.js";import{getExtent as k}from"../../views/2d/viewpointUtils.js";import{ViewEventPriorities as L}from"../../views/input/InputManager.js";import C from"../../views/overlay/BoxOverlayItem.js";import H from"./CustomTemplate.js";import F from"./TemplateOptions.js";import{fetchLayoutTemplateInfos as D}from"./utils.js";import R from"../../geometry/Extent.js";import W from"../../geometry/SpatialReference.js";const A=[30,144,255,255],M=[237,211,23,255],V=[216,48,32,255],q=new Set(["GISProfessionalStdUT","GISProfessionalAdvUT"]),z=/(\/GPServer\/).+/i,G=new a({inch:"inches",foot:"feet",yard:"yards",mile:"miles","nautical-mile":"nautical-miles",millimeter:"millimeters",centimeter:"centimeters",decimeter:"decimeters",meter:"meters",kilometer:"kilometers"}),B=s.ofType(H);function J(t){t.layoutOptions??={},t.layoutOptions.customTextElements??=[];const e="date";if(!t.layoutOptions.customTextElements.find((t=>e in t))){const{customTextElements:e}=t.layoutOptions;let i=w(Date.now(),_("short-date"));"ar"===I()&&(i="‏"+i),e.push({date:i})}}function N(t,e,i){if(!e)return;!(e.visible===i)&&t.layoutOptions&&(t.layoutOptions.elementOverrides?t.layoutOptions.elementOverrides[e.name]={visible:i}:t.layoutOptions.elementOverrides={[e.name]:{visible:i}})}let $=class extends l{constructor(t){super(t),this._serviceTemplateCustomTextElements=null,this._templateIdToCustomTemplate=new p,this._isFreeHand=!1,this._freeHandWidth=0,this._freehandHeight=0,this._asyncPrintTaskUrl=null,this._layoutInfoTaskUrl=null,this.allowedFormats="all",this.allowedLayouts="all",this.browseTemplates=new B,this.defaultTemplates=new B,this.error=null,this.extraParameters=null,this.includeDefaultTemplates=!0,this.outSpatialReference=null,this.portal=g.getDefault(),this.portalTemplateIds=[],this.printServiceTemplates=new B,this.defaultTemplate=null,this.showPrintAreaEnabled=!1,this.printServiceUrl=null,this.printTimeout=12e4,this.templatesInfo=null,this.updateDelay=1e3,this.view=null,this.templateCustomTextElements=null,this.templateOptions=new F}initialize(){this.addHandles([m((()=>[this.showPrintAreaEnabled,this.view]),(()=>{this.showPrintAreaEnabled?this._enablePrintPreview():(this.removeHandles("overlay-handler"),this.view?.overlay?.removeItem(this._getOverlayItem()))})),m((()=>[this.templateOptions.layout,this.templateOptions.layoutItem]),(()=>{this.loaded&&this._processTemplateOptions()}))])}destroy(){this.removeHandles("overlay-handler"),this.view&&(this._overlayItem&&(this.view.overlay?.removeItem(this._overlayItem),this._overlayItem.destroy(),this._overlayItem=null),this.view=null)}get effectivePrintServiceUrl(){return this.printServiceUrl??null}get effectiveTemplateCustomTextElements(){if(!this._serviceTemplateCustomTextElements)return{};const t=r(this._serviceTemplateCustomTextElements);return this.templateCustomTextElements&&Object.keys(this.templateCustomTextElements).forEach((e=>{const i=t[e];if(i){const t=this.templateCustomTextElements?.[e];i.forEach((e=>{const[i]=Object.entries(e)[0];t?.forEach((t=>{const[s,o]=Object.entries(t)[0];i===s&&(e[i]=o)}))}))}})),Object.freeze(t)}get state(){return"loading"===this.loadStatus?"initializing":"failed"===this.loadStatus||this.error?"error":"loaded"===this.loadStatus&&this.view?.ready?"ready":"disabled"}async load(t){return this.addResolvingPromise(this._loadResources(t).catch((t=>this.error=t))),this}async print(t){const{view:e,extraParameters:i,updateDelay:s,outSpatialReference:a}=this;if(!e)throw new o("print:view-required","view is not set");J(t);const r=this._getOverlayItem(),l=t.scalePreserved||!this.showPrintAreaEnabled?void 0:k(new R,e.viewpoint,"map-only"===t.layout?[t.exportOptions.width,t.exportOptions.height]:[r.boxWidth,r.boxHeight]),n=new j({view:e,template:t,extent:l,extraParameters:i,updateDelay:s,outSpatialReference:a});try{const e=!!t.layoutItem?.id&&(this.portalTemplateIds.includes(t.layoutItem.id)||this.browseTemplates.some((e=>e.layoutItem?.id===t.layoutItem?.id)));return await x(e&&this._asyncPrintTaskUrl?this._asyncPrintTaskUrl:this.effectivePrintServiceUrl,n,{timeout:this.printTimeout})}catch(p){throw new o("print:export-error","An error occurred while exporting the web map.",{error:p})}}toPrintTemplate({attributionEnabled:t,author:e,copyright:i,customTextElements:s,dpi:a,forceFeatureAttributes:r,format:l,height:n,id:p,includeTables:m,layout:h,layoutItem:u,legendEnabled:d,northArrowEnabled:c,scale:y,scaleEnabled:f,title:v,width:T}){if(!h&&!u)throw new o("print:layout-required","layout is not set");const w=new E({attributionVisible:t,forceFeatureAttributes:r,format:l,includeTables:m,layout:h,layoutItem:u,layoutOptions:{authorText:e||"",copyrightText:i||"",customTextElements:s,titleText:v||""},outScale:y??0,scalePreserved:f});if(T&&(w.exportOptions.width=T),n&&(w.exportOptions.height=n),a&&(w.exportOptions.dpi=a),w.layoutOptions){d||(w.layoutOptions.legendLayers=[]);const t=this.getLayoutTemplateById(p)?.mapSurroundInfoOptions;if(t){N(w,t.northArrow[0],c);const e=t.scaleBar;for(const t of e)N(w,t,f)}}return w}getLayoutTemplateById(t){return t?this._templateIdToCustomTemplate.get(t):null}async addPortalTemplate(t){if(!this.portal||!t?.id)return;try{t.loaded||await t.load()}catch{return void this.applyTemplate(this.defaultTemplate)}const e=new H({type:"browse-template",layoutInfoTaskUrl:this._layoutInfoTaskUrl,label:t.title,layoutItem:t});this._templateIdToCustomTemplate.set(e.id,e),this.browseTemplates.add(e)}removePortalTemplate(t){t.layoutItem&&this.templateOptions.id===t.layoutItem.id&&(this.defaultTemplate?this.applyTemplate(this.defaultTemplate):this.templateOptions.reset()),this.browseTemplates.remove(t),this._templateIdToCustomTemplate.delete(t.id)}async applyTemplate(t){if(!t)return void this.templateOptions.reset();!t.layout||!this.templatesInfo||this.templatesInfo.layout.choiceList.includes(t.layout)||(this.defaultTemplate?t=this.defaultTemplate:this.templateOptions.reset());const e=t.layout?this.effectiveTemplateCustomTextElements[t.layout]:null;await this.templateOptions.applyTemplate(t,e)}async _loadResources(t){if(this.destroyed)return;await this._loadUrls(t);const[e,i]=await Promise.all([this._getLayoutToLayoutTemplateInfos(t),this._getPrintServiceTemplatesInfo(t)]);await this._loadAllTemplates(e,i,t),this._processPrintServiceTemplatesInfo(i),await this._processTemplateOptions(),this._updateOverLayItem()}async _processTemplateOptions(){const{layout:t,layoutItem:e}=this.templateOptions;if("map-only"!==t&&!this.templateOptions.id)if(e?.id){try{e.loaded||await e.load()}catch{return void this.applyTemplate(this.defaultTemplate)}let t=this._templateIdToCustomTemplate.get(e.id);t||(t=new H({label:e.title,layoutItem:e,layoutInfoTaskUrl:this._layoutInfoTaskUrl}),this._templateIdToCustomTemplate.set(t.id,t)),await this.applyTemplate(t)}else if(t){const t=this.defaultTemplates.find((t=>t.layout===this.templateOptions.layout))??this.printServiceTemplates.find((t=>t.layout===this.templateOptions.layout));await this.applyTemplate(t??this.defaultTemplate)}}async _loadPortal(t){try{await this.portal.load(t)}catch(e){throw new o("print:could-not-load-portal","Cannot load print resource information from portal",{error:e,url:this.effectivePrintServiceUrl})}}async _loadUrls(t){if(this.printServiceUrl)this._set("effectivePrintServiceUrl",this.printServiceUrl),await this._updateLayoutInfoTaskUrl(this.effectivePrintServiceUrl);else{await this._loadPortal(t);const{printTask:e,asyncPrintTask:i,layoutInfoTask:s}=this.portal?.helperServices??{};this._set("effectivePrintServiceUrl",e?.url),this._asyncPrintTaskUrl=i?.url,await this._updateLayoutInfoTaskUrl(s?.url||this.effectivePrintServiceUrl)}const e=this.effectivePrintServiceUrl?.toLowerCase().split("/");if(!e?.includes("gpserver"))throw new o("print:invalid-print-service-url","Can't fetch print templates information from provided URL",{url:this.effectivePrintServiceUrl})}async _updateLayoutInfoTaskUrl(t,e){if(!t)return;const i=(await P(t,e)).find((t=>t.includes("Get Layout Templates Info")));i&&(this._layoutInfoTaskUrl=t.replace(z,`$1${encodeURI(i)}`))}_getPortalDefaultTemplates(t,e){return this.portal?.helperServices?.printTask?.templates?.filter((t=>"map_only"!==t.layout.toLowerCase()&&(!e||e.includes(U(t.layout)))))?.map((e=>{const i=H.fromJSON(e);if(i.type="default-template",i.layoutInfoTaskUrl=this._layoutInfoTaskUrl,i.layout){const e=t.get(i.layout);e&&i.setLayoutTemplateInfo(e)}return i}))??[]}async _getPortalCustomTemplates(t){if(this.printServiceUrl||!this.portal)return[];const{layoutGroupQuery:e,user:i}=this.portal,s=b.test(this.portal.url),o=i?.userLicenseTypeId,a=o&&q.has(o);if(!e||s&&!a)return[];const r=new O({query:e,disableExtraQuery:!0}),l=await this.portal.queryGroups(r,t);if(!l.total)return[];const n=l.results[0],p=new O({num:100,query:"type:Layout",sortField:n.sortField,sortOrder:n.sortOrder??void 0}),m=(await n.queryItems(p,t)).results;if(!m.length)return[];return m.map((t=>(this.portalTemplateIds.push(t.id),new H({type:"default-template",label:t.title,layoutItem:t,layoutInfoTaskUrl:this._layoutInfoTaskUrl}))))}async _loadAllTemplates(t,e,i){let s=!1;const o=e?.layout?.choiceList;if(this.includeDefaultTemplates&&this.portal&&!this.printServiceUrl){const e=this._getPortalDefaultTemplates(t,o);s=!!e.length,this.defaultTemplates.addMany(e);const a=await this._getPortalCustomTemplates(i);this.defaultTemplates.addMany(a);for(const t of this.defaultTemplates)this._templateIdToCustomTemplate.set(t.id,t)}s||t.forEach(((t,e)=>{if(!o||o.includes(e)){const i=new H({type:"print-service-template",layout:e,layoutInfoTaskUrl:this._layoutInfoTaskUrl});i.setLayoutTemplateInfo(t),this.printServiceTemplates.add(i),this._templateIdToCustomTemplate.set(i.id,i)}}))}_processPrintServiceTemplatesInfo(t){this._set("templatesInfo",t);const e=t?.layout?.defaultValue;if(e&&"map-only"!==e){const t=this.defaultTemplates.find((t=>t.layout===e))??this.printServiceTemplates.find((t=>t.layout===e))??this.defaultTemplates.at(0)??this.printServiceTemplates.at(0);this._set("defaultTemplate",t)}}async _getLayoutToLayoutTemplateInfos(t){const e=await D(this._layoutInfoTaskUrl,void 0,t),i=new Map,s={};for(const o of e){const t=U(o.layoutTemplate);i.set(t,o),s[t]=o.layoutOptions.customTextElements}return this._serviceTemplateCustomTextElements=Object.freeze(s),i}async _getPrintServiceTemplatesInfo(t){let i;try{({data:i}=await e(this.effectivePrintServiceUrl,{...t,query:{f:"json"},timeout:this.printTimeout}))}catch(l){throw n(l)?l:new o("print:unavailable-service-info","Can't fetch templates info from service",{error:l})}const{parameters:s}=i,a=s.find((({name:t})=>"Format"===t)),r=s.find((({name:t})=>"Layout_Template"===t));return{format:this._getFormat(a),layout:this._getLayout(r)}}_getFormat(t){const e="all"===this.allowedFormats?t.choiceList:t.choiceList.filter((t=>"string"!=typeof this.allowedFormats&&this.allowedFormats.some((e=>new RegExp(`\\b${e}\\b`,"i").test(t))))),s=(e.length?e:t.choiceList).map((t=>S.fromJSON(t))).filter(i),o=S.fromJSON(t.defaultValue),a=s.some((t=>new RegExp(`\\b${o}\\b`,"i").test(t)))?o:s[0];return{choiceList:s,defaultValue:a}}_getLayout(t){const e=t.choiceList.filter((t=>"map_only"!==t.toLowerCase())),s="all"===this.allowedLayouts?e:e.filter((t=>this.allowedLayouts.includes(U(t)))),o=(s.length?s:e).map(U).filter(i),a=U(t.defaultValue),r=o.includes(a)?a:o.find((t=>/(?=.*letter)(?=.*landscape)/i.test(t)))??o.find((t=>/(?=.*a4)(?=.*landscape)/i.test(t)))??o[0];return{choiceList:o,defaultValue:r}}_getOverlayItem(){return this._overlayItem||(this._overlayItem=new C({strokeDash:[5],strokeWidth:2,strokeColor:[30,144,255,255]})),this._overlayItem}_enablePrintPreview(){if(!this.view?.overlay)return;const t=this.templateOptions,e=this._getOverlayItem();this.addHandles([m((()=>[t.width,t.height,t.scaleEnabled,t.scale,t.layout,t.layoutItem,t.id,t.state,this.view?.scale,this.view?.size,this.view?.state.paddedViewState.size,this.view?.state.padding,this.loaded]),(()=>this._updateOverLayItem()),h),this.view?.on("drag",["Shift"],(t=>this._handleDrag(t)),L.WIDGET),this.view?.on("key-down",["Escape"],(()=>this._resetDrag()),L.WIDGET)],"overlay-handler"),this.view.overlay.addItem(e)}_updateOverLayItem(){if(!this.view)return;const t=this.templateOptions,e=this._getOverlayItem(),i=t.layoutItem?.id??t.layout,s=this.view,o=s.spatialReference,[a,r]=s.state.paddedViewState.size,l=s.state.padding;let n=0,p=0;if("map-only"===i)null!=t.width&&null!=t.height&&(n=t.width,p=t.height);else if(i){const e=t.id?this._templateIdToCustomTemplate.get(t.id):null,{webMapFrameSize:i,pageUnits:s}=e?.layoutTemplateInfo??{};let l=!1;if(i&&s)if(this._isFreeHand){const t=i[0]/i[1];n=this._freeHandWidth,p=this._freehandHeight,n>p?p=n/t:n=p*t}else{const t=G.fromJSON(s.toLowerCase()),e=o.unit;d(t)===d(e)?(n=c(i[0],t,e),p=c(i[1],t,e)):(l=!0,n=i[0],p=i[1])}if(!this._isFreeHand)if(t.scaleEnabled&&t.scale){const e=l?Math.min(a/n,r/p):y(o)*f*t.dpi;n*=e,p*=e}else if(0===n||0===p)n=a,p=r;else{const t=(a-.1*a)/n,e=(r-.1*r)/p,i=Math.min(t,e);n*=i,p*=i}}const{scaleEnabled:m,scale:h}=t,u=m&&h?h/this.view.scale:1;if(e.boxWidth=n*u||a,e.boxHeight=p*u||r,l&&(e.padding=l),e.backgroundWidth=a??0,e.backgroundHeight=r??0,"loading"===this.loadStatus)e.strokeColor=M;else if("loaded"===this.loadStatus)switch(this.templateOptions.state){case"pending":e.strokeColor=M;break;case"ready":e.strokeColor=A;break;case"error":e.strokeColor=V}}_resetDrag(){this._isFreeHand=!1,this._updateOverLayItem()}_handleDrag(t){switch(t.action){case"start":this._start();break;case"update":this._update(t);break;case"end":this._end()}t.stopPropagation()}_start(){this._isFreeHand=!0}_update(t){const e=this._getOverlayItem(),{x:i,y:s}=t,{x:o,y:a}=t.origin;i>o?(e.x=o,e.boxWidth=i-o):(e.x=i,e.boxWidth=o-i),s>a?(e.y=a,e.boxHeight=s-a):(e.y=s,e.boxHeight=a-s)}_end(){const t=this._getOverlayItem();if(!this.view||null==t.x||null==t.y)return;const e=this.view,i=e.toMap(u(t.x+.5*t.boxWidth,t.y+.5*t.boxHeight));t.x=null,t.y=null,e.goTo({center:i}),this._freeHandWidth=t.boxWidth,this._freehandHeight=t.boxHeight,"map-only"===this.templateOptions.layout&&(this.templateOptions.width=this._freeHandWidth,this.templateOptions.height=this._freehandHeight),this.templateOptions.scale=this.view.scale,this._updateOverLayItem()}};t([v()],$.prototype,"_serviceTemplateCustomTextElements",void 0),t([v()],$.prototype,"_templateIdToCustomTemplate",void 0),t([v()],$.prototype,"allowedFormats",void 0),t([v()],$.prototype,"allowedLayouts",void 0),t([v({type:B})],$.prototype,"browseTemplates",void 0),t([v({type:B})],$.prototype,"defaultTemplates",void 0),t([v()],$.prototype,"error",void 0),t([v()],$.prototype,"extraParameters",void 0),t([v()],$.prototype,"includeDefaultTemplates",void 0),t([v({readOnly:!0})],$.prototype,"effectivePrintServiceUrl",null),t([v()],$.prototype,"effectiveTemplateCustomTextElements",null),t([v({type:W})],$.prototype,"outSpatialReference",void 0),t([v({type:g})],$.prototype,"portal",void 0),t([v()],$.prototype,"portalTemplateIds",void 0),t([v({type:B})],$.prototype,"printServiceTemplates",void 0),t([v({readOnly:!0})],$.prototype,"defaultTemplate",void 0),t([v()],$.prototype,"showPrintAreaEnabled",void 0),t([v()],$.prototype,"printServiceUrl",void 0),t([v()],$.prototype,"printTimeout",void 0),t([v({readOnly:!0})],$.prototype,"state",null),t([v({readOnly:!0})],$.prototype,"templatesInfo",void 0),t([v()],$.prototype,"updateDelay",void 0),t([v()],$.prototype,"view",void 0),t([v()],$.prototype,"templateCustomTextElements",void 0),t([v({type:F})],$.prototype,"templateOptions",void 0),$=t([T("esri.widgets.Print.PrintViewModel")],$);const Q=$;export{Q as default};
5
+ import{_ as t}from"../../chunks/tslib.es6.js";import"../../geometry.js";import e from"../../request.js";import{isSome as i}from"../../core/arrayUtils.js";import s from"../../core/Collection.js";import o from"../../core/Error.js";import{JSONMap as a}from"../../core/jsonMap.js";import{clone as r}from"../../core/lang.js";import l from"../../core/Loadable.js";import{isAbortError as n}from"../../core/promiseUtils.js";import p from"../../core/ReactiveMap.js";import{watch as m,initial as h}from"../../core/reactiveUtils.js";import{createScreenPoint as u}from"../../core/screenUtils.js";import{unitType as d,convertUnit as c,getMetersPerUnitForSR as y,inchesPerMeter as f}from"../../core/unitUtils.js";import{property as v}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import{subclass as T}from"../../core/accessorSupport/decorators/subclass.js";import{formatDate as w,convertDateFormatToIntlOptions as _}from"../../intl/date.js";import{getLanguage as I}from"../../intl/locale.js";import g from"../../portal/Portal.js";import O from"../../portal/PortalQueryParams.js";import{reArcGISOnlineDomain as b}from"../../portal/support/urlUtils.js";import{execute as x,getTasks as P}from"../../rest/print.js";import{formatJsonMap as S}from"../../rest/support/fileFormat.js";import{fromJSON as U}from"../../rest/support/layoutTemplate.js";import E from"../../rest/support/PrintParameters.js";import L from"../../rest/support/PrintTemplate.js";import{getExtent as j}from"../../views/2d/viewpointUtils.js";import{ViewEventPriorities as k}from"../../views/input/InputManager.js";import C from"../../views/overlay/BoxOverlayItem.js";import H from"./CustomTemplate.js";import F from"./TemplateOptions.js";import{fetchLayoutTemplateInfos as D}from"./utils.js";import A from"../../geometry/Extent.js";import R from"../../geometry/SpatialReference.js";const W=[30,144,255,255],M=[237,211,23,255],V=[216,48,32,255],q=new Set(["GISProfessionalStdUT","GISProfessionalAdvUT"]),z=/(\/GPServer\/).+/i,G=new a({inch:"inches",foot:"feet",yard:"yards",mile:"miles","nautical-mile":"nautical-miles",millimeter:"millimeters",centimeter:"centimeters",decimeter:"decimeters",meter:"meters",kilometer:"kilometers"}),B=s.ofType(H);function J(t){t.layoutOptions??={},t.layoutOptions.customTextElements??=[];const e="date";if(!t.layoutOptions.customTextElements.find((t=>e in t))){const{customTextElements:e}=t.layoutOptions;let i=w(Date.now(),_("short-date"));"ar"===I()&&(i="‏"+i),e.push({date:i})}}function N(t,e,i){if(!e)return;!(e.visible===i)&&t.layoutOptions&&(t.layoutOptions.elementOverrides?t.layoutOptions.elementOverrides[e.name]={visible:i}:t.layoutOptions.elementOverrides={[e.name]:{visible:i}})}let $=class extends l{constructor(t){super(t),this._serviceTemplateCustomTextElements=null,this._templateIdToCustomTemplate=new p,this._isFreeHand=!1,this._freeHandWidth=0,this._freehandHeight=0,this._asyncPrintTaskUrl=null,this._layoutInfoTaskUrl=null,this._customLayoutOptions=null,this.allowedFormats="all",this.allowedLayouts="all",this.browseTemplates=new B,this.defaultTemplates=new B,this.error=null,this.extraParameters=null,this.includeDefaultTemplates=!0,this.outSpatialReference=null,this.portal=g.getDefault(),this.portalTemplateIds=[],this.printServiceTemplates=new B,this.defaultTemplate=null,this.showPrintAreaEnabled=!1,this.printServiceUrl=null,this.printTimeout=12e4,this.templatesInfo=null,this.updateDelay=1e3,this.view=null,this.templateCustomTextElements=null,this.templateOptions=new F}initialize(){this.addHandles([m((()=>[this.showPrintAreaEnabled,this.view]),(()=>{this.showPrintAreaEnabled?this._enablePrintPreview():(this.removeHandles("overlay-handler"),this.view?.overlay?.removeItem(this._getOverlayItem()))})),m((()=>[this.templateOptions.layout,this.templateOptions.layoutItem]),(()=>{this.loaded&&this._processTemplateOptions()}))])}destroy(){this.removeHandles("overlay-handler"),this.view&&(this._overlayItem&&(this.view.overlay?.removeItem(this._overlayItem),this._overlayItem.destroy(),this._overlayItem=null),this.view=null)}get effectivePrintServiceUrl(){return this.printServiceUrl??null}get effectiveTemplateCustomTextElements(){if(!this._serviceTemplateCustomTextElements)return{};const t=r(this._serviceTemplateCustomTextElements);return this.templateCustomTextElements&&Object.keys(this.templateCustomTextElements).forEach((e=>{const i=t[e];if(i){const t=this.templateCustomTextElements?.[e];i.forEach((e=>{const[i]=Object.entries(e)[0];t?.forEach((t=>{const[s,o]=Object.entries(t)[0];i===s&&(e[i]=o)}))}))}})),Object.freeze(t)}get state(){return"loading"===this.loadStatus?"initializing":"failed"===this.loadStatus||this.error?"error":"loaded"===this.loadStatus&&this.view?.ready?"ready":"disabled"}async load(t){return this.addResolvingPromise(this._loadResources(t).catch((t=>this.error=t))),this}async print(t){const{view:e,extraParameters:i,updateDelay:s,outSpatialReference:a}=this;if(!e)throw new o("print:view-required","view is not set");J(t);const r=this._getOverlayItem(),l=t.scalePreserved||!this.showPrintAreaEnabled?void 0:j(new A,e.viewpoint,"map-only"===t.layout?[t.exportOptions.width,t.exportOptions.height]:[r.boxWidth,r.boxHeight]),n=new E({view:e,template:t,extent:l,extraParameters:i,updateDelay:s,outSpatialReference:a});try{const e=!!t.layoutItem?.id&&(this.portalTemplateIds.includes(t.layoutItem.id)||this.browseTemplates.some((e=>e.layoutItem?.id===t.layoutItem?.id)));return await x(e&&this._asyncPrintTaskUrl?this._asyncPrintTaskUrl:this.effectivePrintServiceUrl,n,{timeout:this.printTimeout})}catch(p){throw new o("print:export-error","An error occurred while exporting the web map.",{error:p})}}toPrintTemplate({attributionEnabled:t,author:e,copyright:i,customTextElements:s,dpi:a,forceFeatureAttributes:r,format:l,height:n,id:p,includeTables:m,layout:h,layoutItem:u,legendEnabled:d,northArrowEnabled:c,scale:y,scaleEnabled:f,title:v,width:T}){if(!h&&!u)throw new o("print:layout-required","layout is not set");const w=new L({attributionVisible:t,forceFeatureAttributes:r,format:l,includeTables:m,layout:h,layoutItem:u,layoutOptions:{authorText:e||"",copyrightText:i||"",customTextElements:s,titleText:v||""},outScale:y??0,scalePreserved:f});if(T&&(w.exportOptions.width=T),n&&(w.exportOptions.height=n),a&&(w.exportOptions.dpi=a),w.layoutOptions){d||(w.layoutOptions.legendLayers=[]);const t=this.getLayoutTemplateById(p)?.mapSurroundInfoOptions;if(t){N(w,t.northArrow[0],c);const e=t.scaleBar;for(const t of e)N(w,t,f)}}return w}getLayoutTemplateById(t){return t?this._templateIdToCustomTemplate.get(t):null}async addPortalTemplate(t){if(!this.portal||!t?.id)return;try{t.loaded||await t.load()}catch{return void this.applyTemplate(this.defaultTemplate)}const e=new H({type:"browse-template",layoutInfoTaskUrl:this._layoutInfoTaskUrl,label:t.title,layoutItem:t});this._templateIdToCustomTemplate.set(e.id,e),this.browseTemplates.add(e)}removePortalTemplate(t){t.layoutItem&&this.templateOptions.id===t.layoutItem.id&&(this.defaultTemplate?this.applyTemplate(this.defaultTemplate):this.templateOptions.reset()),this.browseTemplates.remove(t),this._templateIdToCustomTemplate.delete(t.id)}async applyTemplate(t){if(!t)return void this.templateOptions.reset();!t.layout||!this.templatesInfo||this.templatesInfo.layout.choiceList.includes(t.layout)||(this.defaultTemplate?t=this.defaultTemplate:this.templateOptions.reset());const e=t.layout?this.effectiveTemplateCustomTextElements[t.layout]:void 0;await this.templateOptions.applyTemplate(t,e,this._customLayoutOptions)}async _loadResources(t){if(this.destroyed)return;await this._loadUrls(t);const[e,i]=await Promise.all([this._getLayoutToLayoutTemplateInfos(t),this._getPrintServiceTemplatesInfo(t)]);await this._loadAllTemplates(e,i,t),this._processPrintServiceTemplatesInfo(i),await this._processTemplateOptions(),this._updateOverLayItem()}async _processTemplateOptions(){const{layout:t,layoutItem:e}=this.templateOptions;if("map-only"!==t&&!this.templateOptions.id)if(this._customLayoutOptions={legend:this.templateOptions.legendEnabled,northArrow:this.templateOptions.northArrowEnabled,scaleBar:this.templateOptions.scaleEnabled},e?.id){try{e.loaded||await e.load()}catch{return void this.applyTemplate(this.defaultTemplate)}let t=this._templateIdToCustomTemplate.get(e.id);t||(t=new H({label:e.title,layoutItem:e,layoutInfoTaskUrl:this._layoutInfoTaskUrl}),this._templateIdToCustomTemplate.set(t.id,t)),await this.applyTemplate(t)}else if(t){const t=this.defaultTemplates.find((t=>t.layout===this.templateOptions.layout))??this.printServiceTemplates.find((t=>t.layout===this.templateOptions.layout));await this.applyTemplate(t??this.defaultTemplate)}}async _loadPortal(t){try{await this.portal.load(t)}catch(e){throw new o("print:could-not-load-portal","Cannot load print resource information from portal",{error:e,url:this.effectivePrintServiceUrl})}}async _loadUrls(t){if(this.printServiceUrl)this._set("effectivePrintServiceUrl",this.printServiceUrl),await this._updateLayoutInfoTaskUrl(this.effectivePrintServiceUrl);else{await this._loadPortal(t);const{printTask:e,asyncPrintTask:i,layoutInfoTask:s}=this.portal?.helperServices??{};this._set("effectivePrintServiceUrl",e?.url),this._asyncPrintTaskUrl=i?.url,await this._updateLayoutInfoTaskUrl(s?.url||this.effectivePrintServiceUrl)}const e=this.effectivePrintServiceUrl?.toLowerCase().split("/");if(!e?.includes("gpserver"))throw new o("print:invalid-print-service-url","Can't fetch print templates information from provided URL",{url:this.effectivePrintServiceUrl})}async _updateLayoutInfoTaskUrl(t,e){if(!t)return;const i=(await P(t,e)).find((t=>t.includes("Get Layout Templates Info")));i&&(this._layoutInfoTaskUrl=t.replace(z,`$1${encodeURI(i)}`))}_getPortalDefaultTemplates(t,e){return this.portal?.helperServices?.printTask?.templates?.filter((t=>"map_only"!==t.layout.toLowerCase()&&(!e||e.includes(U(t.layout)))))?.map((e=>{const i=H.fromJSON(e);if(i.type="default-template",i.layoutInfoTaskUrl=this._layoutInfoTaskUrl,i.layout){const e=t.get(i.layout);e&&i.setLayoutTemplateInfo(e)}return i}))??[]}async _getPortalCustomTemplates(t){if(this.printServiceUrl||!this.portal)return[];const{layoutGroupQuery:e,user:i}=this.portal,s=b.test(this.portal.url),o=i?.userLicenseTypeId,a=o&&q.has(o);if(!e||s&&!a)return[];const r=new O({query:e,disableExtraQuery:!0}),l=await this.portal.queryGroups(r,t);if(!l.total)return[];const n=l.results[0],p=new O({num:100,query:"type:Layout",sortField:n.sortField,sortOrder:n.sortOrder??void 0}),m=(await n.queryItems(p,t)).results;if(!m.length)return[];return m.map((t=>(this.portalTemplateIds.push(t.id),new H({type:"default-template",label:t.title,layoutItem:t,layoutInfoTaskUrl:this._layoutInfoTaskUrl}))))}async _loadAllTemplates(t,e,i){let s=!1;const o=e?.layout?.choiceList;if(this.includeDefaultTemplates&&this.portal&&!this.printServiceUrl){const e=this._getPortalDefaultTemplates(t,o);s=!!e.length,this.defaultTemplates.addMany(e);const a=await this._getPortalCustomTemplates(i);this.defaultTemplates.addMany(a);for(const t of this.defaultTemplates)this._templateIdToCustomTemplate.set(t.id,t)}s||t.forEach(((t,e)=>{if(!o||o.includes(e)){const i=new H({type:"print-service-template",layout:e,layoutInfoTaskUrl:this._layoutInfoTaskUrl});i.setLayoutTemplateInfo(t),this.printServiceTemplates.add(i),this._templateIdToCustomTemplate.set(i.id,i)}}))}_processPrintServiceTemplatesInfo(t){this._set("templatesInfo",t);const e=t?.layout?.defaultValue;if(e&&"map-only"!==e){const t=this.defaultTemplates.find((t=>t.layout===e))??this.printServiceTemplates.find((t=>t.layout===e))??this.defaultTemplates.at(0)??this.printServiceTemplates.at(0);this._set("defaultTemplate",t)}}async _getLayoutToLayoutTemplateInfos(t){const e=await D(this._layoutInfoTaskUrl,void 0,t),i=new Map,s={};for(const o of e){const t=U(o.layoutTemplate);i.set(t,o),s[t]=o.layoutOptions.customTextElements}return this._serviceTemplateCustomTextElements=Object.freeze(s),i}async _getPrintServiceTemplatesInfo(t){let i;try{({data:i}=await e(this.effectivePrintServiceUrl,{...t,query:{f:"json"},timeout:this.printTimeout}))}catch(l){throw n(l)?l:new o("print:unavailable-service-info","Can't fetch templates info from service",{error:l})}const{parameters:s}=i,a=s.find((({name:t})=>"Format"===t)),r=s.find((({name:t})=>"Layout_Template"===t));return{format:this._getFormat(a),layout:this._getLayout(r)}}_getFormat(t){const e="all"===this.allowedFormats?t.choiceList:t.choiceList.filter((t=>"string"!=typeof this.allowedFormats&&this.allowedFormats.some((e=>new RegExp(`\\b${e}\\b`,"i").test(t))))),s=(e.length?e:t.choiceList).map((t=>S.fromJSON(t))).filter(i),o=S.fromJSON(t.defaultValue),a=s.some((t=>new RegExp(`\\b${o}\\b`,"i").test(t)))?o:s[0];return{choiceList:s,defaultValue:a}}_getLayout(t){const e=t.choiceList.filter((t=>"map_only"!==t.toLowerCase())),s="all"===this.allowedLayouts?e:e.filter((t=>this.allowedLayouts.includes(U(t)))),o=(s.length?s:e).map(U).filter(i),a=U(t.defaultValue),r=o.includes(a)?a:o.find((t=>/(?=.*letter)(?=.*landscape)/i.test(t)))??o.find((t=>/(?=.*a4)(?=.*landscape)/i.test(t)))??o[0];return{choiceList:o,defaultValue:r}}_getOverlayItem(){return this._overlayItem||(this._overlayItem=new C({strokeDash:[5],strokeWidth:2,strokeColor:[30,144,255,255]})),this._overlayItem}_enablePrintPreview(){if(!this.view?.overlay)return;const t=this.templateOptions,e=this._getOverlayItem();this.addHandles([m((()=>[t.width,t.height,t.scaleEnabled,t.scale,t.layout,t.layoutItem,t.id,t.state,this.view?.scale,this.view?.size,this.view?.state.paddedViewState.size,this.view?.state.padding,this.loaded]),(()=>this._updateOverLayItem()),h),this.view?.on("drag",["Shift"],(t=>this._handleDrag(t)),k.WIDGET),this.view?.on("key-down",["Escape"],(()=>this._resetDrag()),k.WIDGET)],"overlay-handler"),this.view.overlay.addItem(e)}_updateOverLayItem(){if(!this.view)return;const t=this.templateOptions,e=this._getOverlayItem(),i=t.layoutItem?.id??t.layout,s=this.view,o=s.spatialReference,[a,r]=s.state.paddedViewState.size,l=s.state.padding;let n=0,p=0;if("map-only"===i)null!=t.width&&null!=t.height&&(n=t.width,p=t.height);else if(i){const e=t.id?this._templateIdToCustomTemplate.get(t.id):null,{webMapFrameSize:i,pageUnits:s}=e?.layoutTemplateInfo??{};let l=!1;if(i&&s)if(this._isFreeHand){const t=i[0]/i[1];n=this._freeHandWidth,p=this._freehandHeight,n>p?p=n/t:n=p*t}else{const t=G.fromJSON(s.toLowerCase()),e=o.unit;d(t)===d(e)?(n=c(i[0],t,e),p=c(i[1],t,e)):(l=!0,n=i[0],p=i[1])}if(!this._isFreeHand)if(t.scaleEnabled&&t.scale){const e=l?Math.min(a/n,r/p):y(o)*f*t.dpi;n*=e,p*=e}else if(0===n||0===p)n=a,p=r;else{const t=(a-.1*a)/n,e=(r-.1*r)/p,i=Math.min(t,e);n*=i,p*=i}}const{scaleEnabled:m,scale:h}=t,u=m&&h?h/this.view.scale:1;if(e.boxWidth=n*u||a,e.boxHeight=p*u||r,l&&(e.padding=l),e.backgroundWidth=a??0,e.backgroundHeight=r??0,"loading"===this.loadStatus)e.strokeColor=M;else if("loaded"===this.loadStatus)switch(this.templateOptions.state){case"pending":e.strokeColor=M;break;case"ready":e.strokeColor=W;break;case"error":e.strokeColor=V}}_resetDrag(){this._isFreeHand=!1,this._updateOverLayItem()}_handleDrag(t){switch(t.action){case"start":this._start();break;case"update":this._update(t);break;case"end":this._end()}t.stopPropagation()}_start(){this._isFreeHand=!0}_update(t){const e=this._getOverlayItem(),{x:i,y:s}=t,{x:o,y:a}=t.origin;i>o?(e.x=o,e.boxWidth=i-o):(e.x=i,e.boxWidth=o-i),s>a?(e.y=a,e.boxHeight=s-a):(e.y=s,e.boxHeight=a-s)}_end(){const t=this._getOverlayItem();if(!this.view||null==t.x||null==t.y)return;const e=this.view,i=e.toMap(u(t.x+.5*t.boxWidth,t.y+.5*t.boxHeight));t.x=null,t.y=null,e.goTo({center:i}),this._freeHandWidth=t.boxWidth,this._freehandHeight=t.boxHeight,"map-only"===this.templateOptions.layout&&(this.templateOptions.width=this._freeHandWidth,this.templateOptions.height=this._freehandHeight),this.templateOptions.scale=this.view.scale,this._updateOverLayItem()}};t([v()],$.prototype,"_serviceTemplateCustomTextElements",void 0),t([v()],$.prototype,"_templateIdToCustomTemplate",void 0),t([v()],$.prototype,"allowedFormats",void 0),t([v()],$.prototype,"allowedLayouts",void 0),t([v({type:B})],$.prototype,"browseTemplates",void 0),t([v({type:B})],$.prototype,"defaultTemplates",void 0),t([v()],$.prototype,"error",void 0),t([v()],$.prototype,"extraParameters",void 0),t([v()],$.prototype,"includeDefaultTemplates",void 0),t([v({readOnly:!0})],$.prototype,"effectivePrintServiceUrl",null),t([v()],$.prototype,"effectiveTemplateCustomTextElements",null),t([v({type:R})],$.prototype,"outSpatialReference",void 0),t([v({type:g})],$.prototype,"portal",void 0),t([v()],$.prototype,"portalTemplateIds",void 0),t([v({type:B})],$.prototype,"printServiceTemplates",void 0),t([v({readOnly:!0})],$.prototype,"defaultTemplate",void 0),t([v()],$.prototype,"showPrintAreaEnabled",void 0),t([v()],$.prototype,"printServiceUrl",void 0),t([v()],$.prototype,"printTimeout",void 0),t([v({readOnly:!0})],$.prototype,"state",null),t([v({readOnly:!0})],$.prototype,"templatesInfo",void 0),t([v()],$.prototype,"updateDelay",void 0),t([v()],$.prototype,"view",void 0),t([v()],$.prototype,"templateCustomTextElements",void 0),t([v({type:F})],$.prototype,"templateOptions",void 0),$=t([T("esri.widgets.Print.PrintViewModel")],$);const Q=$;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.32/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../chunks/tslib.es6.js";import o from"../../core/Accessor.js";import{clone as e}from"../../core/lang.js";import{property as r}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import l from"../../portal/PortalItem.js";let i=class extends o{constructor(t){super(t),this._abortController=null,this.attributionEnabled=!0,this.author=null,this.copyright=null,this.customTextElements=null,this.dpi=96,this.fileName=null,this.forceFeatureAttributes=!1,this.format="pdf",this.height=null,this.includeTables=!0,this.id=null,this.state="ready",this.layout="letter-ansi-a-landscape",this.layoutItem=null,this.legendEnabled=!0,this.northArrowEnabled=!1,this.scale=null,this.scaleBarEnabled=!1,this.scaleEnabled=!1,this.title=null,this.width=null}async applyTemplate(t,o){if((t?.id!==this.id||"error"===t?.state)&&(this._abortController&&(this._abortController.abort(),this._abortController=null),t)){if(this._set("state","pending"),this._resetMapSurroundInfoOptions(),this._set("id",t.id),this.set({layout:t.layout,layoutItem:t.layoutItem}),!t.layoutOptions&&t.layoutItem){const o=new AbortController;if(this._abortController=o,await t.fetchLayoutItemTemplateInfo({signal:this._abortController.signal}),"loaded"!==t.state){if("error"===t.state&&this._set("state","error"),this._abortController!==o)return;return void(this._abortController=null)}this._abortController=null}this.set({customTextElements:o?e(o):this.customTextElements,format:this.format??t.format,legendEnabled:t.layoutOptions?.legend??this.legendEnabled,northArrowEnabled:t.layoutOptions?.northArrow??this.northArrowEnabled,scaleBarEnabled:t.layoutOptions?.scaleBar??this.scaleBarEnabled}),this._set("state","ready")}}reset(){this._set("id",null),this._set("state","ready"),this.set({layout:null,layoutItem:null,customTextElements:null}),this._resetMapSurroundInfoOptions()}_resetMapSurroundInfoOptions(){this.set({legendEnabled:!0,northArrowEnabled:!1,scaleBarEnabled:!1})}};t([r()],i.prototype,"attributionEnabled",void 0),t([r()],i.prototype,"author",void 0),t([r()],i.prototype,"copyright",void 0),t([r()],i.prototype,"customTextElements",void 0),t([r()],i.prototype,"dpi",void 0),t([r()],i.prototype,"fileName",void 0),t([r()],i.prototype,"forceFeatureAttributes",void 0),t([r()],i.prototype,"format",void 0),t([r()],i.prototype,"height",void 0),t([r()],i.prototype,"includeTables",void 0),t([r({readOnly:!0})],i.prototype,"id",void 0),t([r({readOnly:!0})],i.prototype,"state",void 0),t([r()],i.prototype,"layout",void 0),t([r({type:l})],i.prototype,"layoutItem",void 0),t([r()],i.prototype,"legendEnabled",void 0),t([r()],i.prototype,"northArrowEnabled",void 0),t([r()],i.prototype,"scale",void 0),t([r()],i.prototype,"scaleBarEnabled",void 0),t([r()],i.prototype,"scaleEnabled",void 0),t([r()],i.prototype,"title",void 0),t([r()],i.prototype,"width",void 0),i=t([s("esri.widgets.Print.TemplateOptions")],i);const a=i;export{a as default};
5
+ import{_ as t}from"../../chunks/tslib.es6.js";import o from"../../core/Accessor.js";import{clone as e}from"../../core/lang.js";import{property as r}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import l from"../../portal/PortalItem.js";let i=class extends o{constructor(t){super(t),this._abortController=null,this.attributionEnabled=!0,this.author=null,this.copyright=null,this.customTextElements=null,this.dpi=96,this.fileName=null,this.forceFeatureAttributes=!1,this.format="pdf",this.height=null,this.includeTables=!0,this.id=null,this.state="ready",this.layout="letter-ansi-a-landscape",this.layoutItem=null,this.legendEnabled=!0,this.northArrowEnabled=!1,this.scale=null,this.scaleBarEnabled=!1,this.scaleEnabled=!1,this.title=null,this.width=null}async applyTemplate(t,o,r){if((t?.id!==this.id||"error"===t?.state)&&(this._abortController&&(this._abortController.abort(),this._abortController=null),t)){if(this._set("state","pending"),this._resetMapSurroundInfoOptions(),this._set("id",t.id),this.set({layout:t.layout,layoutItem:t.layoutItem}),!t.layoutOptions&&t.layoutItem){const o=new AbortController;if(this._abortController=o,await t.fetchLayoutItemTemplateInfo({signal:this._abortController.signal}),"loaded"!==t.state){if("error"===t.state&&this._set("state","error"),this._abortController!==o)return;return void(this._abortController=null)}this._abortController=null}this.set({customTextElements:o?e(o):this.customTextElements,format:this.format??t.format,legendEnabled:r?.legend??t.layoutOptions?.legend??this.legendEnabled,northArrowEnabled:r?.northArrow??t.layoutOptions?.northArrow??this.northArrowEnabled,scaleBarEnabled:r?.scaleBar??t.layoutOptions?.scaleBar??this.scaleBarEnabled}),this._set("state","ready")}}reset(){this._set("id",null),this._set("state","ready"),this.set({layout:null,layoutItem:null,customTextElements:null}),this._resetMapSurroundInfoOptions()}_resetMapSurroundInfoOptions(){this.set({legendEnabled:!0,northArrowEnabled:!1,scaleBarEnabled:!1})}};t([r()],i.prototype,"attributionEnabled",void 0),t([r()],i.prototype,"author",void 0),t([r()],i.prototype,"copyright",void 0),t([r()],i.prototype,"customTextElements",void 0),t([r()],i.prototype,"dpi",void 0),t([r()],i.prototype,"fileName",void 0),t([r()],i.prototype,"forceFeatureAttributes",void 0),t([r()],i.prototype,"format",void 0),t([r()],i.prototype,"height",void 0),t([r()],i.prototype,"includeTables",void 0),t([r({readOnly:!0})],i.prototype,"id",void 0),t([r({readOnly:!0})],i.prototype,"state",void 0),t([r()],i.prototype,"layout",void 0),t([r({type:l})],i.prototype,"layoutItem",void 0),t([r()],i.prototype,"legendEnabled",void 0),t([r()],i.prototype,"northArrowEnabled",void 0),t([r()],i.prototype,"scale",void 0),t([r()],i.prototype,"scaleBarEnabled",void 0),t([r()],i.prototype,"scaleEnabled",void 0),t([r()],i.prototype,"title",void 0),t([r()],i.prototype,"width",void 0),i=t([s("esri.widgets.Print.TemplateOptions")],i);const a=i;export{a as default};