@vertigis/arcgis-extensions 37.2.0 → 37.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/AppConfig.schema.json +0 -16
  2. package/data/Feature.js +1 -1
  3. package/data/FeatureSet.js +1 -1
  4. package/data/FieldExtension.js +1 -1
  5. package/data/PopupContentExtension.d.ts +0 -1
  6. package/data/PopupContentExtension.js +1 -1
  7. package/declarations/arcgis-js-api-extensions/index.d.ts +19 -1
  8. package/docs/html/assets/search.js +1 -1
  9. package/docs/html/classes/Entity.EntityBase.html +9 -5
  10. package/docs/html/classes/Hyperlink.Hyperlink.html +9 -5
  11. package/docs/html/classes/LanguageResources.LanguageResources.html +9 -5
  12. package/docs/html/classes/data_ArcGISServiceTableExtension.ArcGISServiceTableExtension.html +9 -5
  13. package/docs/html/classes/data_Attachment.Attachment.html +9 -5
  14. package/docs/html/classes/data_Feature.Feature.html +9 -5
  15. package/docs/html/classes/data_FeatureList.FeatureList.html +7 -3
  16. package/docs/html/classes/data_FeatureSet.FeatureSet.html +9 -5
  17. package/docs/html/classes/data_FeatureSettings.FeatureSettings.html +9 -5
  18. package/docs/html/classes/data_FeatureSourceBase.FeatureSourceBase.html +9 -5
  19. package/docs/html/classes/data_FeatureSourceBase.RelationshipCollection.html +7 -3
  20. package/docs/html/classes/data_FeatureStream.FeatureStream.html +10 -6
  21. package/docs/html/classes/data_FieldExtension.FieldExtension.html +9 -5
  22. package/docs/html/classes/data_PopupContentExtension.PopupContentExtension.html +15 -6
  23. package/docs/html/classes/data_RelationshipBase.RelationshipBase.html +9 -5
  24. package/docs/html/classes/data_Schema.Schema.html +9 -5
  25. package/docs/html/classes/data_TaskSettings.TaskSettings.html +9 -5
  26. package/docs/html/classes/data__TableExtension.TableExtension.html +9 -5
  27. package/docs/html/classes/data__TableExtension.TableFeatureSettings.html +9 -5
  28. package/docs/html/classes/data__TableExtension.TableSchema.html +9 -5
  29. package/docs/html/classes/layer_preset_LayerPreset.LayerPreset.html +9 -5
  30. package/docs/html/classes/layer_preset_LayerPresetSettings.LayerPresetSetting.html +9 -5
  31. package/docs/html/classes/mapping_ArcGISSublayerExtension.ArcGISSublayerExtension.html +9 -5
  32. package/docs/html/classes/mapping_ArcGISSublayerExtension.ArcGISSublayerRelationshipCollection.html +7 -3
  33. package/docs/html/classes/mapping_BasemapExtension.BasemapExtension.html +9 -5
  34. package/docs/html/classes/mapping_Bookmark.Bookmark.html +9 -5
  35. package/docs/html/classes/mapping_BuildingComponentSublayerExtension.BuildingComponentSublayerExtension.html +9 -5
  36. package/docs/html/classes/mapping_BuildingComponentSublayerExtension.BuildingComponentSublayerSchema.html +9 -5
  37. package/docs/html/classes/mapping_BuildingGroupSublayerExtension.BuildingGroupSublayerExtension.html +9 -5
  38. package/docs/html/classes/mapping_BuildingGroupSublayerExtension.BuildingGroupSublayerSchema.html +9 -5
  39. package/docs/html/classes/mapping_BuildingSceneLayerExtension.BuildingSceneLayerExtension.html +9 -5
  40. package/docs/html/classes/mapping_BuildingSceneLayerExtension.BuildingSceneLayerReadOnlySchema.html +9 -5
  41. package/docs/html/classes/mapping_BuildingSublayerExtension.BuildingSublayerExtension.html +9 -5
  42. package/docs/html/classes/mapping_BuildingSublayerExtension.BuildingSublayerFeatureSettings.html +9 -5
  43. package/docs/html/classes/mapping_BuildingSublayerExtension.BuildingSublayerSchema.html +9 -5
  44. package/docs/html/classes/mapping_CSVLayerExtension.CSVLayerExtension.html +9 -5
  45. package/docs/html/classes/mapping_ElevationLayerExtension.ElevationLayerExtension.html +9 -5
  46. package/docs/html/classes/mapping_FeatureCollectionLayerExtension.FeatureCollectionLayerExtension.html +9 -5
  47. package/docs/html/classes/mapping_FeatureLayerExtension.FeatureLayerExtension.html +9 -5
  48. package/docs/html/classes/mapping_FeatureLayerExtensionBase.FeatureLayerExtensionBase.html +9 -5
  49. package/docs/html/classes/mapping_FeatureLayerExtensionBase.FeatureLayerReadOnlySchema.html +9 -5
  50. package/docs/html/classes/mapping_FeatureLayerExtensionBase.FeatureLayerSchema.html +9 -5
  51. package/docs/html/classes/mapping_GeoRSSLayerExtension.GeoRSSLayerExtension.html +9 -5
  52. package/docs/html/classes/mapping_GraphicsLayerExtension.GraphicsLayerExtension.html +9 -5
  53. package/docs/html/classes/mapping_GroundExtension.GroundExtension.html +9 -5
  54. package/docs/html/classes/mapping_GroupLayerExtension.GroupLayerExtension.html +9 -5
  55. package/docs/html/classes/mapping_GroupLayerExtension.GroupLayerExtensionCollection.html +7 -3
  56. package/docs/html/classes/mapping_ImageryLayerExtension.ImageryLayerExtension.html +9 -5
  57. package/docs/html/classes/mapping_ImageryTileLayerExtension.ImageryTileLayerExtension.html +9 -5
  58. package/docs/html/classes/mapping_IntegratedMeshLayerExtension.IntegratedMeshLayerExtension.html +9 -5
  59. package/docs/html/classes/mapping_KMLLayerExtension.KMLLayerExtension.html +9 -5
  60. package/docs/html/classes/mapping_KMLSublayerExtension.KMLSublayerExtension.html +9 -5
  61. package/docs/html/classes/mapping_MapConstraints.MapConstraints.html +9 -5
  62. package/docs/html/classes/mapping_MapExtension.MapExtension.html +9 -5
  63. package/docs/html/classes/mapping_MapImageLayerExtension.MapImageLayerExtension.html +9 -5
  64. package/docs/html/classes/mapping_MapImageSublayerExtension.MapImageSublayerExtension.html +9 -5
  65. package/docs/html/classes/mapping_OpenStreetMapLayerExtension.OpenStreetMapLayerExtension.html +9 -5
  66. package/docs/html/classes/mapping_PointCloudLayerExtension.PointCloudLayerExtension.html +9 -5
  67. package/docs/html/classes/mapping_SceneLayerExtension.SceneLayerExtension.html +9 -5
  68. package/docs/html/classes/mapping_StreamLayerExtension.StreamLayerExtension.html +9 -5
  69. package/docs/html/classes/mapping_StreamLayerExtension.StreamLayerSchema.html +9 -5
  70. package/docs/html/classes/mapping_SubtypeGroupLayerExtension.SubtypeGroupLayerExtension.html +9 -5
  71. package/docs/html/classes/mapping_SubtypeGroupLayerExtension.SubtypeGroupLayerRelationshipCollection.html +7 -3
  72. package/docs/html/classes/mapping_SubtypeSublayerExtension.SubtypeSublayerExtension.html +9 -5
  73. package/docs/html/classes/mapping_SubtypeSublayerExtension.SubtypeSublayerRelationshipCollection.html +7 -3
  74. package/docs/html/classes/mapping_SubtypeSublayerExtension.SubtypeSublayerSchema.html +9 -5
  75. package/docs/html/classes/mapping_TileLayerExtension.TileLayerExtension.html +9 -5
  76. package/docs/html/classes/mapping_TileSublayerExtension.TileSublayerExtension.html +9 -5
  77. package/docs/html/classes/mapping_UnsupportedLayerExtension.UnsupportedLayerExtension.html +9 -5
  78. package/docs/html/classes/mapping_VectorTileLayerExtension.VectorTileLayerExtension.html +9 -5
  79. package/docs/html/classes/mapping_WMSLayerExtension.WMSLayerExtension.html +9 -5
  80. package/docs/html/classes/mapping_WMSSublayerExtension.WMSSublayerExtension.html +9 -5
  81. package/docs/html/classes/mapping_WMTSLayerExtension.WMTSLayerExtension.html +9 -5
  82. package/docs/html/classes/mapping_WMTSSublayerExtension.WMTSSublayerExtension.html +9 -5
  83. package/docs/html/classes/mapping_WebTileLayerExtension.WebTileLayerExtension.html +9 -5
  84. package/docs/html/classes/mapping__LayerExtension.LayerExtension.html +9 -5
  85. package/docs/html/classes/mapping__LayerExtension.LayerExtensionSchema.html +9 -5
  86. package/docs/html/classes/mapping__SublayerExtension.SubSublayerExtensionCollection.html +7 -3
  87. package/docs/html/classes/mapping__SublayerExtension.SublayerExtension.html +9 -5
  88. package/docs/html/classes/mapping__SublayerExtension.SublayerSchema.html +9 -5
  89. package/docs/html/classes/mapping_support_ArrayWrappedCollection.ArrayWrappedCollection.html +7 -3
  90. package/docs/html/classes/mapping_support_LayerListSettings.ExtensionBaseLayerListSettings.html +9 -5
  91. package/docs/html/classes/mapping_support_LayerListSettings.LayerListSettings.html +9 -5
  92. package/docs/html/classes/mapping_support__LayerExtensionCollection.LayerExtensionCollectionBase.html +7 -3
  93. package/docs/html/classes/mapping_support__SublayerExtensionCollection.SublayerExtensionCollectionBase.html +7 -3
  94. package/docs/html/classes/menus_Menu.Menu.html +9 -5
  95. package/docs/html/classes/menus_MenuItem.MenuItem.html +9 -5
  96. package/docs/html/classes/support_FormatSettings.FormatSettings.html +9 -5
  97. package/docs/html/classes/support_InitializableBase.InitializableBase.html +9 -5
  98. package/docs/html/classes/support_InitializableCollectionProxy.InitializableCollectionProxy.html +7 -3
  99. package/docs/html/classes/support_Observable.Observable.html +14 -10
  100. package/docs/html/classes/support_ReadOnlyInitializableCollection.ReadOnlyInitializableCollection.html +7 -3
  101. package/docs/html/classes/support_Serializable.SerializableBase.html +9 -5
  102. package/docs/html/classes/support_Settings.Settings.html +9 -5
  103. package/docs/html/classes/support__ArcGISRelationshipCollection.ArcGISRelationshipCollection.html +7 -3
  104. package/docs/html/classes/tasks_geocoding_ArcGISGeocoder.ArcGISGeocoder.html +9 -5
  105. package/docs/html/classes/tasks_geocoding_Geocoder.Geocoder.html +9 -5
  106. package/docs/html/classes/tasks_query_ArcGISRelationship.ArcGISRelationship.html +9 -5
  107. package/docs/html/classes/tasks_query_QueryBasedRelationship.QueryBasedRelationship.html +9 -5
  108. package/docs/html/classes/utilities_CollectionProxy.CollectionProxy.html +7 -3
  109. package/docs/html/classes/utilities_CopyOnWriteCollection.CopyOnWriteCollection.html +7 -3
  110. package/docs/html/classes/utilities_MapTransformCollection.MapTransformCollection.html +7 -3
  111. package/docs/html/classes/utilities_ObservableMap.ObservableMap.html +9 -5
  112. package/docs/html/classes/utilities_ObservableSet.ObservableSet.html +9 -5
  113. package/docs/html/classes/utilities_ObservableWeakSet.ObservableWeakSet.html +9 -5
  114. package/docs/html/classes/utilities_ReadOnlyCollection.ReadOnlyCollection.html +7 -3
  115. package/docs/html/classes/utilities_ReadOnlyMap.ReadOnlyMap.html +9 -5
  116. package/docs/html/classes/utilities_asyncIterable.AsyncQueue.html +1 -1
  117. package/docs/html/classes/utilities_date.DateFormatter.html +9 -5
  118. package/docs/html/classes/utilities_number.NumberFormatter.html +9 -5
  119. package/docs/html/functions/utilities_watch.watchEach.html +66 -4
  120. package/docs/html/interfaces/data_Feature.PresentableAttributes.html +5 -1
  121. package/docs/html/interfaces/data__Relationship.Relationship-1.html +9 -5
  122. package/docs/html/variables/version.version.html +1 -1
  123. package/layer-preset/LayerPreset.js +1 -1
  124. package/mapping/BuildingComponentSublayerExtension.js +1 -1
  125. package/mapping/MapExtension.js +1 -1
  126. package/mapping/SubtypeSublayerExtension.js +1 -1
  127. package/mapping/_SublayerExtension.js +1 -1
  128. package/mapping/support/LayerListSettings.js +1 -1
  129. package/package.json +1 -1
  130. package/portal/SubtypeGroupLayer.js +1 -1
  131. package/portal/WMSLayer.js +1 -1
  132. package/support/Observable.d.ts +9 -25
  133. package/support/Observable.js +1 -1
  134. package/support/Settings.js +1 -1
  135. package/utilities/watch.d.ts +13 -1
  136. package/utilities/watch.js +1 -1
  137. package/version.d.ts +1 -1
  138. package/version.js +1 -1
@@ -2043,10 +2043,6 @@
2043
2043
  "_alternate": {
2044
2044
  "$ref": "#/definitions/MenuItemState"
2045
2045
  },
2046
- "_changed": {
2047
- "$ref": "#/definitions/Set",
2048
- "description": "Properties that have changed since the last notification."
2049
- },
2050
2046
  "_description": {
2051
2047
  "type": "string"
2052
2048
  },
@@ -2094,14 +2090,6 @@
2094
2090
  "_menu": {
2095
2091
  "$ref": "#/definitions/Menu"
2096
2092
  },
2097
- "_notifyPending": {
2098
- "description": "Determines whether a notification task is scheduled.",
2099
- "type": "boolean"
2100
- },
2101
- "_observers": {
2102
- "$ref": "#/definitions/Map",
2103
- "description": "Property observers keyed by property name."
2104
- },
2105
2093
  "_submenu": {
2106
2094
  "$ref": "#/definitions/Menu"
2107
2095
  },
@@ -2202,7 +2190,6 @@
2202
2190
  "required": [
2203
2191
  "_action",
2204
2192
  "_alternate",
2205
- "_changed",
2206
2193
  "_description",
2207
2194
  "_destroyPromise",
2208
2195
  "_failureMode",
@@ -2216,8 +2203,6 @@
2216
2203
  "_isToggled",
2217
2204
  "_itemType",
2218
2205
  "_menu",
2219
- "_notifyPending",
2220
- "_observers",
2221
2206
  "_submenu",
2222
2207
  "_title",
2223
2208
  "action",
@@ -2601,7 +2586,6 @@
2601
2586
  },
2602
2587
  "type": "object"
2603
2588
  },
2604
- "Set": {},
2605
2589
  "SublayerExtension": {
2606
2590
  "description": "Extends the capabilities of an Esri Sublayer object."
2607
2591
  },
package/data/Feature.js CHANGED
@@ -1 +1 @@
1
- import{__decorate}from"tslib";import Graphic from"@arcgis/core/Graphic";import*as Arcade from"@arcgis/core/arcade/arcade";import{EntityBase}from"../Entity.js";import{Hyperlink}from"../Hyperlink.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{ItemType}from"../ItemType.js";import{toEsriApiGeometry,toPortalGeometry}from"../portal/Geometry.js";import{serializable}from"../support/Serializable.js";import{MapTransformCollection}from"../utilities/MapTransformCollection.js";import{ObservableMap}from"../utilities/ObservableMap.js";import{ReadOnlyMap}from"../utilities/ReadOnlyMap.js";import{arcadeScriptUsesGeometry,isArcadeScriptAsync,runArcadeExpression,runAsyncArcadeExpression}from"../utilities/arcade.js";import{flatten,groupBy}from"../utilities/array.js";import{checkArg}from"../utilities/checkArg.js";import{Collection,compare}from"../utilities/collection.js";import{parse as parseDate,esriFormatToGeocortexFormat}from"../utilities/date.js";import{isCodedValueDomain}from"../utilities/esri.js";import{some,map as mapIterable,concat,forEach,find}from"../utilities/iterable.js";import{getLogger}from"../utilities/log.js";import{parse as parseNumber,NumberFormat}from"../utilities/number.js";import{map as promiseMap}from"../utilities/promise.js";import{format as formatString}from"../utilities/string.js";import{FeatureSettings}from"./FeatureSettings.js";import{fieldWithArcadeXRegex,fieldWithRelationshipRegex,Schema}from"./Schema.js";const log=getLogger("geocortex.api.data.Feature");export const SCORE_FIELD="_score";export const SCORE_FIELD_ORIGINAL="_score_original";let Feature=class extends EntityBase{constructor(e){super(e),this._itemType=ItemType.FEATURE,this._expressionFieldValues=new ObservableMap,this._expressionValuesUpdatePending=!1,this.settings=new FeatureSettings,this.settings._setFeature(this),this.schema=new Schema,this.schema._featureSettings=this.settings,this.attachments=new Collection,this.attributes=new ObservableMap,this._relatedFeatures=new ObservableMap,this.expressionFieldValues=new ExpressionFieldsValuesImpl(this._expressionFieldValues,this)}get geometry(){return this._geometry}set geometry(e){this._notifyChange("geometryType"),this._geometry=toEsriApiGeometry(e),this.schema.spatialReference=this._geometry?.spatialReference}get geometryType(){return this.geometry?this.geometry.type:void 0}get source(){return this._source}set source(e){this._source&&this.settings.parent===this._source.featureSettings&&(this.settings.parent=void 0),this._source&&this.schema.parent===this._source.schema&&(this.schema.parent=void 0),this._source=e,this.settings.parent||(this.settings.parent=e?e.featureSettings:void 0),this.schema.parent||(this.schema.parent=e?e.schema:void 0)}get primaryKey(){const e=this.attributes.get(this.schema.primaryKeyField);return null!=e?`${e}`:void 0}get hasGlobalId(){return!!this.schema.fields.find((e=>"global-id"===e.type))}get globalId(){const e=this.schema.fields.find((e=>"global-id"===e.type));return e?this.attributes.get(e.name):void 0}set globalId(e){const t=this.schema.fields.find((e=>"global-id"===e.type));if(!t)throw new InvalidOperationError("Cannot set global ID on feature -- no global ID field.");this.attributes.set(t.name,e)}get presentableAttributes(){return this._presentableAttributes=this._presentableAttributes||new PresentableAttributesImpl(this),this._presentableAttributes}get title(){return this.format(this._title||"")}get description(){return this.format(this._description)}get hyperlinks(){return this._hyperlinks||(this._hyperlinks=new HyperlinksCollection(this))}get relatedFeatures(){return this._relatedFeatures}get type(){if(this.schema.typeIdField&&this.attributes.has(this.schema.typeIdField)){const e=this.attributes.get(this.schema.typeIdField);return this.schema.types.find((t=>t.id===e))}}get _hydrationStatus(){return this._featureHydrationStatus?this._featureHydrationStatus:this.source?.capabilities?.supportsQuery&&1===this.attributes.size&&void 0!==this.primaryKey?"dehydrated":"hydrated"}set _hydrationStatus(e){this._featureHydrationStatus=e}get _key(){return`${this.source?.id}//${this.primaryKey??this.globalId??this.id}`}get _title(){let e;return this.settings.popupTemplate&&(e="function"==typeof this.settings.popupTemplate.title?this.settings.popupTemplate.title():this.settings.popupTemplate.title),e||this.schema.displayField&&this.presentableAttributes.get(this.schema.displayField)||""}get _description(){if(this.settings.popupTemplate?.content){if("string"==typeof this.settings.popupTemplate.content)return this.settings.popupTemplate.content;if(Array.isArray(this.settings.popupTemplate.content)){const e=this.settings.popupTemplate.content.find((e=>"text"===e.type));if(e)return e.text}}return""}format(e,...t){let s="string"==typeof e?{format:e}:e;checkArg("options",s).isNotMissing();const{format:r}=s;checkArg("format",r).isNotMissing();let i=s.format.replace(escapedBraceRegex,escapedBracePlaceholder);return i=i.replace(fieldTokenRegex,((e,t,r,i,a)=>formatAttribute(this,t||r,i,{...s,format:a?`{0:${a}}`:"{0}"}))),i=i.replace(escapedBracePlaceholderRegex,"{{"),s={...s},s.format=i,formatString(s,...t)}clearExpressionInfos(){this._expressionFieldValues.clear()}async fetchExpressionInfos(e=!1){const{expressionInfos:t}=this.settings.popupTemplate??{};if(t)return await Promise.all(t.map((async e=>{try{const t=this.source?.layer??this.source?.sublayer;let s=this.source?.mapExtension;if(!s){const e=this.source?.layerExtension;s=e?.mapExtension}this._expressionFieldValues.set(e.name,await runAsyncArcadeExpression(e.expression,{layer:t,map:s?.map,feature:this,spatialReference:this.schema.spatialReference}))}catch(t){t instanceof Error&&log.error({message:"Error evaluating expression '{0}': {1}.",error:t},e.name,t.message),this._expressionFieldValues.set(e.name,invalidRelationshipOrExpression)}}))),e?this.attributes.on("change",(async e=>{this._expressionValuesUpdatePending||(this._expressionValuesUpdatePending=!0,setTimeout((async()=>{this._expressionValuesUpdatePending=!1,await this.fetchExpressionInfos()}),0))})):void 0}async fetchRelatedFeatures(e,t){if(!this.source)return;let s=[];if(e){const t=new Set(Array.isArray(e)?e:[e]);for(const e of t){const t="string"==typeof e?this.source.relationships.find((t=>t.id===e)):e;if(!t||!this.source.relationships.includes(t))throw new InvalidOperationError("Relationship not found in feature source.");s.push(t)}}else s=this.source.relationships.toArray();const r=await promiseMap(s,(async e=>[e,await e.getRelatedFeatures(this,t)]));for(const e of r)this._relatedFeatures.set(e[0],e[1])}async fetchAttachments(){if(this.source){const e=await this.source.getAttachments(this);compare(this.attachments,e,{equals:(e,t)=>e.id===t.id,onMissing:(e,t)=>this.attachments.remove(e),onNew:(e,t)=>this.attachments.add(e),onMatch:(e,t,s,r)=>{this.attachments.splice(s,1,t)}})}}async addAttachment(e){return this.source?.addAttachment(this,e)}async deleteAttachments(e){return this.source?.deleteAttachments(this,e)}_getSerializableProperties(){return{...super._getSerializableProperties(),attributes:{serializeModes:["project"],serialize:e=>{const t={};if("project"===e&&this.primaryKey&&this.source?.capabilities.supportsQuery)t[this.schema.primaryKeyField]=this.primaryKey;else for(const[e,s]of this.attributes.entries())t[e]=s;return t},deserialize:e=>{if(this.attributes.clear(),e instanceof Map)e.forEach(((e,t)=>{this.attributes.set(t,e)}));else for(const[t,s]of Object.entries(e))this.attributes.set(t,s)}},geometry:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("geometry"):toPortalGeometry(this.geometry),deserialize:e=>this.geometry=toEsriApiGeometry(e)},settings:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("settings"):this.settings.toJSON(e)},schema:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("schema"):this.schema.toJSON(e)},source:["project"]}}_watchProperty(e,t,s,r){if("title"===e||"description"===e){const i=super._watchProperty(e,t,s,r),a="title"===e?"settings.popupTemplate.title":"settings.popupTemplate.content",o=this.watch(a,(()=>{this._notifyChange(e)})),n=this.presentableAttributes.on("change",(()=>{this._notifyChange(e)}));return{remove(){i.remove(),o.remove(),n.remove()}}}return super._watchProperty(e,t,s,r)}async _onInitialize(){const e=this._findRelationshipIds(this._title,this._description),t=this.source?this.source.relationships.map((e=>e.id)).toArray():[],s=[];for(const r of e)t.includes(r)?s.push(this.fetchRelatedFeatures(r)):log.error("Could not find relationship '{0}' referenced in feature title or description.",r);await Promise.all(s)}_findRelationshipIds(...e){const t=[];for(const s of e){let e;const r=s.replace(escapedBraceRegex,escapedBracePlaceholder);for(;e=relationshipIdRegex.exec(r),null!==e;){const s=e[0];t.includes(s)||t.push(e[1])}}return t}};Feature=__decorate([serializable],Feature);export{Feature};export function toFeature(e,t){const s=new Feature(t);if(e.attributes)for(const t of Object.keys(e.attributes))s.attributes.set(t,e.attributes[t]);return s.geometry=e.geometry,e.popupTemplate&&(s.settings.popupTemplate=e.popupTemplate),s}export function toGraphic(e){const t=new Graphic;t.attributes={};for(const s of e.attributes.keys())t.attributes[s]=e.attributes.get(s);return e.source?.layer&&(t.layer=e.source?.layer),t.geometry=e.geometry,e.settings.popupTemplate&&(t.popupTemplate=e.settings.popupTemplate),t}const ERR_PRESENTABLE_ATTRIBUTES_READONLY="Presentable attributes are read-only.",ERR_HYPERLINK_READONLY="Feature hyperlinks are read-only. Modify the feature's hyperlink templates instead.";class ExpressionFieldsValuesImpl extends ReadOnlyMap{constructor(e,t){super(e),this._feature=t}get(e){if(!super.has(e)){const{spatialReference:t}=this._feature.schema,s=this._feature.settings.popupTemplate?.expressionInfos?.find((t=>t.name===e));if(!s)return;(async()=>{try{if(isArcadeScriptAsync(s.expression,t)){const r=this._feature.source?.layer??this._feature.source?.sublayer;let i=this._feature.source?.mapExtension;if(!i){const e=this._feature.source?.layerExtension;i=e?.mapExtension}this._originalMap.set(e,await runAsyncArcadeExpression(s.expression,{feature:this._feature,layer:r,map:i?.map,spatialReference:t}))}else arcadeScriptUsesGeometry(s.expression,t)&&await Arcade.enableGeometrySupport(),this._originalMap.set(e,runArcadeExpression(s.expression,{feature:this._feature,spatialReference:t}))}catch(t){t instanceof Error&&log.error({message:"Error evaluating expression '{0}': {1}.",error:t},e,t.message),this._originalMap.set(e,invalidRelationshipOrExpression)}})()}return super.get(e)}}class PresentableAttributesImpl extends ReadOnlyMap{constructor(e){super(new ObservableMap),this._feature=e}get size(){return this._feature.attributes.size+this._feature.schema.fields._expressionFieldsLength}clear(){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}delete(e){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}forEach(e,t){checkArg("callback",e).isNotMissing();for(const s of this.keys())e.call(t,this.get(s),s,this)}get(e){const t=this._getFieldExtensionFormat(e);return this._formatAttribute(e,t)}has(e){return some(this.keys(),(t=>t===e))}set(...e){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}*entries(){yield*mapIterable(this.keys(),(e=>[e,this.get(e)]))}*keys(){const e=this._feature.schema.fields.expressionFields.map((e=>e.name)),t=[];this._feature.source?.relationships&&this._feature.source.relationships.filter((e=>"one-to-one"===e.cardinality||"many-to-one"===e.cardinality)).forEach((e=>t.push(...e.relatedSource.schema.fields.map((t=>`relationships/${e.id}/${t.name}`)).toArray()))),yield*concat(this._feature.attributes.keys(),e.toArray(),t)}*values(){yield*mapIterable(this.keys(),(e=>this.get(e)))}[(Symbol.toStringTag,Symbol.iterator)](){return this.entries()}toJSON(){return Array.from(this.entries())}on(e,t){if(checkArg("callback",t).isNotMissing(),!this._numObservers){const e=new Map,t=new Set,s=()=>{t.forEach((e=>e.remove())),t.clear()},r=()=>{const t={added:Array.from(this.entries()).filter((t=>t[1]!==e.get(t[0]))),removed:Array.from(e.entries()).filter((e=>!this.has(e[0])||e[1]!==this.get(e[0]))),target:this};(t.added.length||t.removed.length)&&(this.emit("change",t),i())},i=()=>{e.clear(),s(),forEach(this.keys(),(s=>{const i=this._getFieldExtension(s);let a="{0}";if(i){const e=i.watch("format",(()=>{r()}));t.add(e),i.format&&(a=i.format)}e.set(s,this._formatAttribute(s,a))}))};i();const a=this._feature.attributes.on("change",(()=>{r()})),o=this._feature.schema.fieldExtensions.on("change",(()=>{r()})),n=this._feature.settings.formatSettings.watch(["numberFormat","dateFormat","locale"],(()=>{r()})),l=this._feature.expressionFieldValues.on("change",(()=>{r()})),p=this._feature.schema.fields.on("change",(e=>{(e.added?.some((e=>null!==e.name.match(fieldWithArcadeXRegex)))||e.removed?.some((e=>null!==e.name.match(fieldWithArcadeXRegex))))&&r()})),h=this._feature.settings.watch("popupTemplate",(()=>{r()}));this._onAllObserversRemoved=()=>{l.remove(),a.remove(),o.remove(),p.remove(),n.remove(),h.remove(),e.clear(),s()}}const s=super.on("change",t);return this._numObservers++,{remove:()=>{s.remove(),this._numObservers--,this._numObservers||this._onAllObserversRemoved()}}}watch(e,t){if("size"===e){const e=this._feature.attributes.watch("size",((e,s)=>{t(e+this._feature.schema.fields._expressionFieldsLength,s+this._feature.schema.fields._expressionFieldsLength,"size",this)})),s=this._feature.schema.fields.watch("_expressionFieldsLength",((e,s)=>{t(e+this._feature.attributes.size,s+this._feature.attributes.size,"size",this)}));return{remove:()=>{e.remove(),s.remove()}}}return super.watch(e,t)}_getFieldExtension(e){const t=this._feature.schema.findFieldByName(e);if(t)return this._feature.schema.fieldExtensions.forField(t)}_getFieldExtensionFormat(e){const t=this._getFieldExtension(e);return t?t.format:"{0}"}_formatAttribute(e,t){const s=e.match(fieldWithArcadeXRegex),r=e.match(fieldWithRelationshipRegex);if(s)return formatAttribute(this._feature,"expression",s[1],{format:t});if(r){const[,e,s]=r;return formatAttribute(this._feature,e,s,{format:t})}return formatAttribute(this._feature,void 0,e,{format:t})}}const fieldTokenRegex=/\{(?:relationships[\\/](\w\w*)[\\/])?(?:(expression)[\\/])?([a-zA-Z][.\w]*)(?::([^}]*))?\}/g,relationshipIdRegex=/\{relationships\/(\w\w*)[\\/]([^}]*)\}/g,escapedBraceRegex=/{{/g,escapedBracePlaceholder="\0MAGIC\0",escapedBracePlaceholderRegex=new RegExp(escapedBracePlaceholder,"g"),invalidRelationshipOrExpression="#INVALID";class HyperlinksCollection extends MapTransformCollection{constructor(e){super(e.settings.hyperlinkTemplates,(e=>this._getHyperlink(e))),this._feature=e}_getHyperlink(e){return this._hyperlinks=this._hyperlinks||new WeakMap,this._hyperlinks.has(e)||this._hyperlinks.set(e,new FeatureHyperlink(this._feature,e)),this._hyperlinks.get(e)}}let FeatureHyperlink=class extends Hyperlink{constructor(e,t){super(t.toJSON()),this._feature=e,this._template=t}get url(){return this._template.url?this._feature.format(this._template.url):this._template.url}set url(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get text(){return this._template.text?this._feature.format(this._template.text):this._template.text}set text(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get iconUrl(){return this._template.iconUrl?this._feature.format(this._template.iconUrl):this._template.iconUrl}set iconUrl(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get target(){return this._template.target?this._feature.format(this._template.target):this._template.target}set target(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get tooltip(){return this._template.tooltip?this._feature.format(this._template.tooltip):this._template.tooltip}set tooltip(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}_watchProperty(e,t,s,r){const i=super._watchProperty(e,t,s,r),a=this._template.watch(e,(()=>{this._notifyChange(e)})),o=this._feature.presentableAttributes.on("change",(()=>{this._notifyChange(e)}));return{remove:()=>{i.remove(),a.remove(),o.remove()}}}_getSerializableProperties(){return{}}};function formatAttribute(e,t,s,r={format:"{0}"}){if("expression"!==t){if(t){const i=find(e.relatedFeatures.keys(),(e=>e.id===t));if(!i)return log.debug("Could not resolve related field '{0}/{1}",t,s),invalidRelationshipOrExpression;const a=Array.from(e.relatedFeatures.get(i));return"many-to-one"===i.cardinality||"one-to-one"===i.cardinality?a.length<1?(log.debug("Could not resolve related field '{0}/{1}",t,s),invalidRelationshipOrExpression):formatAttributeValue(a[0],s,r):a.map((e=>formatAttributeValue(e,s,r))).filter((e=>""!==e)).join(",")}return formatAttributeValue(e,s,r)}if(!e.settings.popupTemplate?.expressionInfos?.find((e=>e.name===s)))return log.debug("Could not find expression '{0}'.",s),invalidRelationshipOrExpression;try{const t=e.expressionFieldValues.get(s)??r.defaultExpressionValue??"",i=e.schema.findFieldByName(`expression/${s}`);let a=r;if(i){const t=e.schema.fieldExtensions.forField(i);a=formatOptionsForField(e,s,formatOptionsFromSettings(t.formatSettings),a)}return formatValue(e,t,a)}catch(e){if(e instanceof Error)return log.error({message:"Error evaluating expression '{0}': {1}.",error:e},s,e.message),invalidRelationshipOrExpression;throw e}}function formatAttributeValue(e,t,s){let r=e.attributes.get(t);if(null==r)return"";const i=e.schema.findFieldByName(t);let a={format:"{0}"};const o=e.type?.domains?.[t];if(t===e.schema.typeIdField)r=e.type?e.type.name:r;else if(isCodedValueDomain(o)){const e=o.codedValues.find((e=>`${e.code}`==`${r.toString()}`));r=e?e.name:r}else if(i)if(isCodedValueDomain(i.domain)){const e=i.domain.codedValues.find((e=>`${e.code}`==`${r.toString()}`));e&&(r=e.name)}else{switch(i.type){case"integer":case"small-integer":case"single":case"double":r=parseNumber(r);break;case"date":r=parseDate({timeZone:e.schema.timeZone},r);break;default:r=`${r.toString()}`}a=formatOptionsFromSettings(e.schema.fieldExtensions.forField(i).formatSettings)}return formatValue(e,r,formatOptionsForField(e,t,a,s))}function formatValue(e,t,s){let r=s;if("number"==typeof t||t instanceof Date){r={...formatOptionsFromSettings(e.settings.formatSettings),...s}}return"{0}"===r.format&&"string"==typeof t?t:formatString(r,t)}function formatOptionsFromSettings(e){return{format:"{0}",dateFormat:e.dateFormat,numberFormat:e.numberFormat,currency:e.currency,fractionalDigits:e.fractionalDigits,locale:e.locale,timeZone:e.timeZone}}function formatOptionsForField(e,t,s,r){const{popupTemplate:i}=e.settings,a=i?.fieldInfos?i.fieldInfos.find((e=>e.fieldName===t)):void 0,o=a?a.format:void 0;let n;return o&&(n={format:"{0}",numberFormat:o.digitSeparator?NumberFormat.NUMBER:NumberFormat.FIXED_POINT,dateFormat:esriFormatToGeocortexFormat(o.dateFormat),fractionalDigits:o.places}),{...n,...s,...r}}FeatureHyperlink=__decorate([serializable],FeatureHyperlink);export async function resolveRelatedFeatures(e){const t=groupBy(e,(e=>e.source));await Promise.all(flatten([...t.keys()].map((e=>e.relationships.toArray()))).map((e=>(async e=>{[...(await e.getAllRelatedFeatures(t.get(e.source))).entries()].forEach((([t,s])=>{t.relatedFeatures.set(e,s)}))})(e))))}
1
+ import{__decorate}from"tslib";import Graphic from"@arcgis/core/Graphic";import*as Arcade from"@arcgis/core/arcade/arcade";import{EntityBase}from"../Entity.js";import{Hyperlink}from"../Hyperlink.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{ItemType}from"../ItemType.js";import{toEsriApiGeometry,toPortalGeometry}from"../portal/Geometry.js";import{serializable}from"../support/Serializable.js";import{MapTransformCollection}from"../utilities/MapTransformCollection.js";import{ObservableMap}from"../utilities/ObservableMap.js";import{ReadOnlyMap}from"../utilities/ReadOnlyMap.js";import{arcadeScriptUsesGeometry,isArcadeScriptAsync,runArcadeExpression,runAsyncArcadeExpression}from"../utilities/arcade.js";import{flatten,groupBy}from"../utilities/array.js";import{checkArg}from"../utilities/checkArg.js";import{Collection,compare}from"../utilities/collection.js";import{parse as parseDate,esriFormatToGeocortexFormat}from"../utilities/date.js";import{isCodedValueDomain}from"../utilities/esri.js";import{some,map as mapIterable,concat,forEach,find}from"../utilities/iterable.js";import{getLogger}from"../utilities/log.js";import{parse as parseNumber,NumberFormat}from"../utilities/number.js";import{map as promiseMap}from"../utilities/promise.js";import{format as formatString}from"../utilities/string.js";import{FeatureSettings}from"./FeatureSettings.js";import{fieldWithArcadeXRegex,fieldWithRelationshipRegex,Schema}from"./Schema.js";const log=getLogger("geocortex.api.data.Feature");export const SCORE_FIELD="_score";export const SCORE_FIELD_ORIGINAL="_score_original";let Feature=class extends EntityBase{constructor(e){super(e),this._itemType=ItemType.FEATURE,this._expressionFieldValues=new ObservableMap,this._expressionValuesUpdatePending=!1,this.settings=new FeatureSettings,this.settings._setFeature(this),this.schema=new Schema,this.schema._featureSettings=this.settings,this.attachments=new Collection,this.attributes=new ObservableMap,this._relatedFeatures=new ObservableMap,this.expressionFieldValues=new ExpressionFieldsValuesImpl(this._expressionFieldValues,this)}get geometry(){return this._geometry}set geometry(e){this.notifyChange("geometryType"),this._geometry=toEsriApiGeometry(e),this.schema.spatialReference=this._geometry?.spatialReference}get geometryType(){return this.geometry?this.geometry.type:void 0}get source(){return this._source}set source(e){this._source&&this.settings.parent===this._source.featureSettings&&(this.settings.parent=void 0),this._source&&this.schema.parent===this._source.schema&&(this.schema.parent=void 0),this._source=e,this.settings.parent||(this.settings.parent=e?e.featureSettings:void 0),this.schema.parent||(this.schema.parent=e?e.schema:void 0)}get primaryKey(){const e=this.attributes.get(this.schema.primaryKeyField);return null!=e?`${e}`:void 0}get hasGlobalId(){return!!this.schema.fields.find((e=>"global-id"===e.type))}get globalId(){const e=this.schema.fields.find((e=>"global-id"===e.type));return e?this.attributes.get(e.name):void 0}set globalId(e){const t=this.schema.fields.find((e=>"global-id"===e.type));if(!t)throw new InvalidOperationError("Cannot set global ID on feature -- no global ID field.");this.attributes.set(t.name,e)}get presentableAttributes(){return this._presentableAttributes=this._presentableAttributes||new PresentableAttributesImpl(this),this._presentableAttributes}get title(){return this.format(this._title||"")}get description(){return this.format(this._description)}get hyperlinks(){return this._hyperlinks||(this._hyperlinks=new HyperlinksCollection(this))}get relatedFeatures(){return this._relatedFeatures}get type(){if(this.schema.typeIdField&&this.attributes.has(this.schema.typeIdField)){const e=this.attributes.get(this.schema.typeIdField);return this.schema.types.find((t=>t.id===e))}}get _hydrationStatus(){return this._featureHydrationStatus?this._featureHydrationStatus:this.source?.capabilities?.supportsQuery&&1===this.attributes.size&&void 0!==this.primaryKey?"dehydrated":"hydrated"}set _hydrationStatus(e){this._featureHydrationStatus=e}get _key(){return`${this.source?.id}//${this.primaryKey??this.globalId??this.id}`}get _title(){let e;return this.settings.popupTemplate&&(e="function"==typeof this.settings.popupTemplate.title?this.settings.popupTemplate.title():this.settings.popupTemplate.title),e||this.schema.displayField&&this.presentableAttributes.get(this.schema.displayField)||""}get _description(){if(this.settings.popupTemplate?.content){if("string"==typeof this.settings.popupTemplate.content)return this.settings.popupTemplate.content;if(Array.isArray(this.settings.popupTemplate.content)){const e=this.settings.popupTemplate.content.find((e=>"text"===e.type));if(e)return e.text}}return""}format(e,...t){let s="string"==typeof e?{format:e}:e;checkArg("options",s).isNotMissing();const{format:r}=s;checkArg("format",r).isNotMissing();let i=s.format.replace(escapedBraceRegex,escapedBracePlaceholder);return i=i.replace(fieldTokenRegex,((e,t,r,i,a)=>formatAttribute(this,t||r,i,{...s,format:a?`{0:${a}}`:"{0}"}))),i=i.replace(escapedBracePlaceholderRegex,"{{"),s={...s},s.format=i,formatString(s,...t)}clearExpressionInfos(){this._expressionFieldValues.clear()}async fetchExpressionInfos(e=!1){const{expressionInfos:t}=this.settings.popupTemplate??{};if(t)return await Promise.all(t.map((async e=>{try{const t=this.source?.layer??this.source?.sublayer;let s=this.source?.mapExtension;if(!s){const e=this.source?.layerExtension;s=e?.mapExtension}this._expressionFieldValues.set(e.name,await runAsyncArcadeExpression(e.expression,{layer:t,map:s?.map,feature:this,spatialReference:this.schema.spatialReference}))}catch(t){t instanceof Error&&log.error({message:"Error evaluating expression '{0}': {1}.",error:t},e.name,t.message),this._expressionFieldValues.set(e.name,invalidRelationshipOrExpression)}}))),e?this.attributes.on("change",(async e=>{this._expressionValuesUpdatePending||(this._expressionValuesUpdatePending=!0,setTimeout((async()=>{this._expressionValuesUpdatePending=!1,await this.fetchExpressionInfos()}),0))})):void 0}async fetchRelatedFeatures(e,t){if(!this.source)return;let s=[];if(e){const t=new Set(Array.isArray(e)?e:[e]);for(const e of t){const t="string"==typeof e?this.source.relationships.find((t=>t.id===e)):e;if(!t||!this.source.relationships.includes(t))throw new InvalidOperationError("Relationship not found in feature source.");s.push(t)}}else s=this.source.relationships.toArray();const r=await promiseMap(s,(async e=>[e,await e.getRelatedFeatures(this,t)]));for(const e of r)this._relatedFeatures.set(e[0],e[1])}async fetchAttachments(){if(this.source){const e=await this.source.getAttachments(this);compare(this.attachments,e,{equals:(e,t)=>e.id===t.id,onMissing:(e,t)=>this.attachments.remove(e),onNew:(e,t)=>this.attachments.add(e),onMatch:(e,t,s,r)=>{this.attachments.splice(s,1,t)}})}}async addAttachment(e){return this.source?.addAttachment(this,e)}async deleteAttachments(e){return this.source?.deleteAttachments(this,e)}_getSerializableProperties(){return{...super._getSerializableProperties(),attributes:{serializeModes:["project"],serialize:e=>{const t={};if("project"===e&&this.primaryKey&&this.source?.capabilities.supportsQuery)t[this.schema.primaryKeyField]=this.primaryKey;else for(const[e,s]of this.attributes.entries())t[e]=s;return t},deserialize:e=>{if(this.attributes.clear(),e instanceof Map)e.forEach(((e,t)=>{this.attributes.set(t,e)}));else for(const[t,s]of Object.entries(e))this.attributes.set(t,s)}},geometry:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("geometry"):toPortalGeometry(this.geometry),deserialize:e=>this.geometry=toEsriApiGeometry(e)},settings:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("settings"):this.settings.toJSON(e)},schema:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("schema"):this.schema.toJSON(e)},source:["project"]}}_watchProperty(e,t,s,r){if("title"===e||"description"===e){const i=super._watchProperty(e,t,s,r),a="title"===e?"settings.popupTemplate.title":"settings.popupTemplate.content",o=this.watch(a,(()=>{this.notifyChange(e)})),n=this.presentableAttributes.on("change",(()=>{this.notifyChange(e)}));return{remove(){i.remove(),o.remove(),n.remove()}}}return super._watchProperty(e,t,s,r)}async _onInitialize(){const e=this._findRelationshipIds(this._title,this._description),t=this.source?this.source.relationships.map((e=>e.id)).toArray():[],s=[];for(const r of e)t.includes(r)?s.push(this.fetchRelatedFeatures(r)):log.error("Could not find relationship '{0}' referenced in feature title or description.",r);await Promise.all(s)}_findRelationshipIds(...e){const t=[];for(const s of e){let e;const r=s.replace(escapedBraceRegex,escapedBracePlaceholder);for(;e=relationshipIdRegex.exec(r),null!==e;){const s=e[0];t.includes(s)||t.push(e[1])}}return t}};Feature=__decorate([serializable],Feature);export{Feature};export function toFeature(e,t){const s=new Feature(t);if(e.attributes)for(const t of Object.keys(e.attributes))s.attributes.set(t,e.attributes[t]);return s.geometry=e.geometry,e.popupTemplate&&(s.settings.popupTemplate=e.popupTemplate),s}export function toGraphic(e){const t=new Graphic;t.attributes={};for(const s of e.attributes.keys())t.attributes[s]=e.attributes.get(s);return e.source?.layer&&(t.layer=e.source?.layer),t.geometry=e.geometry,e.settings.popupTemplate&&(t.popupTemplate=e.settings.popupTemplate),t}const ERR_PRESENTABLE_ATTRIBUTES_READONLY="Presentable attributes are read-only.",ERR_HYPERLINK_READONLY="Feature hyperlinks are read-only. Modify the feature's hyperlink templates instead.";class ExpressionFieldsValuesImpl extends ReadOnlyMap{constructor(e,t){super(e),this._feature=t}get(e){if(!super.has(e)){const{spatialReference:t}=this._feature.schema,s=this._feature.settings.popupTemplate?.expressionInfos?.find((t=>t.name===e));if(!s)return;(async()=>{try{if(isArcadeScriptAsync(s.expression,t)){const r=this._feature.source?.layer??this._feature.source?.sublayer;let i=this._feature.source?.mapExtension;if(!i){const e=this._feature.source?.layerExtension;i=e?.mapExtension}this._originalMap.set(e,await runAsyncArcadeExpression(s.expression,{feature:this._feature,layer:r,map:i?.map,spatialReference:t}))}else arcadeScriptUsesGeometry(s.expression,t)&&await Arcade.enableGeometrySupport(),this._originalMap.set(e,runArcadeExpression(s.expression,{feature:this._feature,spatialReference:t}))}catch(t){t instanceof Error&&log.error({message:"Error evaluating expression '{0}': {1}.",error:t},e,t.message),this._originalMap.set(e,invalidRelationshipOrExpression)}})()}return super.get(e)}}class PresentableAttributesImpl extends ReadOnlyMap{constructor(e){super(new ObservableMap),this._feature=e}get size(){return this._feature.attributes.size+this._feature.schema.fields._expressionFieldsLength}clear(){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}delete(e){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}forEach(e,t){checkArg("callback",e).isNotMissing();for(const s of this.keys())e.call(t,this.get(s),s,this)}get(e){const t=this._getFieldExtensionFormat(e);return this._formatAttribute(e,t)}has(e){return some(this.keys(),(t=>t===e))}set(...e){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}*entries(){yield*mapIterable(this.keys(),(e=>[e,this.get(e)]))}*keys(){const e=this._feature.schema.fields.expressionFields.map((e=>e.name)),t=[];this._feature.source?.relationships&&this._feature.source.relationships.filter((e=>"one-to-one"===e.cardinality||"many-to-one"===e.cardinality)).forEach((e=>t.push(...e.relatedSource.schema.fields.map((t=>`relationships/${e.id}/${t.name}`)).toArray()))),yield*concat(this._feature.attributes.keys(),e.toArray(),t)}*values(){yield*mapIterable(this.keys(),(e=>this.get(e)))}[(Symbol.toStringTag,Symbol.iterator)](){return this.entries()}toJSON(){return Array.from(this.entries())}on(e,t){if(checkArg("callback",t).isNotMissing(),!this._numObservers){const e=new Map,t=new Set,s=()=>{t.forEach((e=>e.remove())),t.clear()},r=()=>{const t={added:Array.from(this.entries()).filter((t=>t[1]!==e.get(t[0]))),removed:Array.from(e.entries()).filter((e=>!this.has(e[0])||e[1]!==this.get(e[0]))),target:this};(t.added.length||t.removed.length)&&(this.emit("change",t),i())},i=()=>{e.clear(),s(),forEach(this.keys(),(s=>{const i=this._getFieldExtension(s);let a="{0}";if(i){const e=i.watch("format",(()=>{r()}));t.add(e),i.format&&(a=i.format)}e.set(s,this._formatAttribute(s,a))}))};i();const a=this._feature.attributes.on("change",(()=>{r()})),o=this._feature.schema.fieldExtensions.on("change",(()=>{r()})),n=this._feature.settings.formatSettings.watch(["numberFormat","dateFormat","locale"],(()=>{r()})),l=this._feature.expressionFieldValues.on("change",(()=>{r()})),p=this._feature.schema.fields.on("change",(e=>{(e.added?.some((e=>null!==e.name.match(fieldWithArcadeXRegex)))||e.removed?.some((e=>null!==e.name.match(fieldWithArcadeXRegex))))&&r()})),h=this._feature.settings.watch("popupTemplate",(()=>{r()}));this._onAllObserversRemoved=()=>{l.remove(),a.remove(),o.remove(),p.remove(),n.remove(),h.remove(),e.clear(),s()}}const s=super.on("change",t);return this._numObservers++,{remove:()=>{s.remove(),this._numObservers--,this._numObservers||this._onAllObserversRemoved()}}}watch(e,t){if("size"===e){const e=this._feature.attributes.watch("size",((e,s)=>{t(e+this._feature.schema.fields._expressionFieldsLength,s+this._feature.schema.fields._expressionFieldsLength,"size",this)})),s=this._feature.schema.fields.watch("_expressionFieldsLength",((e,s)=>{t(e+this._feature.attributes.size,s+this._feature.attributes.size,"size",this)}));return{remove:()=>{e.remove(),s.remove()}}}return super.watch(e,t)}_getFieldExtension(e){const t=this._feature.schema.findFieldByName(e);if(t)return this._feature.schema.fieldExtensions.forField(t)}_getFieldExtensionFormat(e){const t=this._getFieldExtension(e);return t?t.format:"{0}"}_formatAttribute(e,t){const s=e.match(fieldWithArcadeXRegex),r=e.match(fieldWithRelationshipRegex);if(s)return formatAttribute(this._feature,"expression",s[1],{format:t});if(r){const[,e,s]=r;return formatAttribute(this._feature,e,s,{format:t})}return formatAttribute(this._feature,void 0,e,{format:t})}}const fieldTokenRegex=/\{(?:relationships[\\/](\w\w*)[\\/])?(?:(expression)[\\/])?([a-zA-Z][.\w]*)(?::([^}]*))?\}/g,relationshipIdRegex=/\{relationships\/(\w\w*)[\\/]([^}]*)\}/g,escapedBraceRegex=/{{/g,escapedBracePlaceholder="\0MAGIC\0",escapedBracePlaceholderRegex=new RegExp(escapedBracePlaceholder,"g"),invalidRelationshipOrExpression="#INVALID";class HyperlinksCollection extends MapTransformCollection{constructor(e){super(e.settings.hyperlinkTemplates,(e=>this._getHyperlink(e))),this._feature=e}_getHyperlink(e){return this._hyperlinks=this._hyperlinks||new WeakMap,this._hyperlinks.has(e)||this._hyperlinks.set(e,new FeatureHyperlink(this._feature,e)),this._hyperlinks.get(e)}}let FeatureHyperlink=class extends Hyperlink{constructor(e,t){super(t.toJSON()),this._feature=e,this._template=t}get url(){return this._template.url?this._feature.format(this._template.url):this._template.url}set url(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get text(){return this._template.text?this._feature.format(this._template.text):this._template.text}set text(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get iconUrl(){return this._template.iconUrl?this._feature.format(this._template.iconUrl):this._template.iconUrl}set iconUrl(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get target(){return this._template.target?this._feature.format(this._template.target):this._template.target}set target(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get tooltip(){return this._template.tooltip?this._feature.format(this._template.tooltip):this._template.tooltip}set tooltip(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}_watchProperty(e,t,s,r){const i=super._watchProperty(e,t,s,r),a=this._template.watch(e,(()=>{this.notifyChange(e)})),o=this._feature.presentableAttributes.on("change",(()=>{this.notifyChange(e)}));return{remove:()=>{i.remove(),a.remove(),o.remove()}}}_getSerializableProperties(){return{}}};function formatAttribute(e,t,s,r={format:"{0}"}){if("expression"!==t){if(t){const i=find(e.relatedFeatures.keys(),(e=>e.id===t));if(!i)return log.debug("Could not resolve related field '{0}/{1}",t,s),invalidRelationshipOrExpression;const a=Array.from(e.relatedFeatures.get(i));return"many-to-one"===i.cardinality||"one-to-one"===i.cardinality?a.length<1?(log.debug("Could not resolve related field '{0}/{1}",t,s),invalidRelationshipOrExpression):formatAttributeValue(a[0],s,r):a.map((e=>formatAttributeValue(e,s,r))).filter((e=>""!==e)).join(",")}return formatAttributeValue(e,s,r)}if(!e.settings.popupTemplate?.expressionInfos?.find((e=>e.name===s)))return log.debug("Could not find expression '{0}'.",s),invalidRelationshipOrExpression;try{const t=e.expressionFieldValues.get(s)??r.defaultExpressionValue??"",i=e.schema.findFieldByName(`expression/${s}`);let a=r;if(i){const t=e.schema.fieldExtensions.forField(i);a=formatOptionsForField(e,s,formatOptionsFromSettings(t.formatSettings),a)}return formatValue(e,t,a)}catch(e){if(e instanceof Error)return log.error({message:"Error evaluating expression '{0}': {1}.",error:e},s,e.message),invalidRelationshipOrExpression;throw e}}function formatAttributeValue(e,t,s){let r=e.attributes.get(t);if(null==r)return"";const i=e.schema.findFieldByName(t);let a={format:"{0}"};const o=e.type?.domains?.[t];if(t===e.schema.typeIdField)r=e.type?e.type.name:r;else if(isCodedValueDomain(o)){const e=o.codedValues.find((e=>`${e.code}`==`${r.toString()}`));r=e?e.name:r}else if(i)if(isCodedValueDomain(i.domain)){const e=i.domain.codedValues.find((e=>`${e.code}`==`${r.toString()}`));e&&(r=e.name)}else{switch(i.type){case"integer":case"small-integer":case"single":case"double":r=parseNumber(r);break;case"date":r=parseDate({timeZone:e.schema.timeZone},r);break;default:r=`${r.toString()}`}a=formatOptionsFromSettings(e.schema.fieldExtensions.forField(i).formatSettings)}return formatValue(e,r,formatOptionsForField(e,t,a,s))}function formatValue(e,t,s){let r=s;if("number"==typeof t||t instanceof Date){r={...formatOptionsFromSettings(e.settings.formatSettings),...s}}return"{0}"===r.format&&"string"==typeof t?t:formatString(r,t)}function formatOptionsFromSettings(e){return{format:"{0}",dateFormat:e.dateFormat,numberFormat:e.numberFormat,currency:e.currency,fractionalDigits:e.fractionalDigits,locale:e.locale,timeZone:e.timeZone}}function formatOptionsForField(e,t,s,r){const{popupTemplate:i}=e.settings,a=i?.fieldInfos?i.fieldInfos.find((e=>e.fieldName===t)):void 0,o=a?a.format:void 0;let n;return o&&(n={format:"{0}",numberFormat:o.digitSeparator?NumberFormat.NUMBER:NumberFormat.FIXED_POINT,dateFormat:esriFormatToGeocortexFormat(o.dateFormat),fractionalDigits:o.places}),{...n,...s,...r}}FeatureHyperlink=__decorate([serializable],FeatureHyperlink);export async function resolveRelatedFeatures(e){const t=groupBy(e,(e=>e.source));await Promise.all(flatten([...t.keys()].map((e=>e.relationships.toArray()))).map((e=>(async e=>{[...(await e.getAllRelatedFeatures(t.get(e.source))).entries()].forEach((([t,s])=>{t.relatedFeatures.set(e,s)}))})(e))))}
@@ -1 +1 @@
1
- var FeatureSet_1;import{__decorate}from"tslib";import Collection from"@arcgis/core/core/Collection";import{generateId}from"../Entity.js";import{isFeature,ItemType}from"../ItemType.js";import{Observable}from"../support/Observable.js";import{assignProperties,filterJSONProperties,getDefaults,getSerializableProperties,serializable}from"../support/Serializable.js";import{ObservableMap}from"../utilities/ObservableMap.js";import{groupBy}from"../utilities/array.js";import{toArray,from,empty}from"../utilities/asyncIterable.js";import{compare,find}from"../utilities/iterable.js";import{getLogger}from"../utilities/log.js";import{watchEach}from"../utilities/watch.js";import{Feature}from"./Feature.js";import{FeatureSettings}from"./FeatureSettings.js";import{Schema}from"./Schema.js";const log=getLogger("feature-set");let FeatureSet=FeatureSet_1=class extends Observable{constructor(e){super(),this.settings=new FeatureSettings,this.schema=new Schema,this._rehydratingFeatureCount=0,this._rehydratingFeatures=new Collection,this._features=new ObservableMap,this.schema._featureSettings=this.settings,this.id=e?.id??generateId(),watchEach(this._rehydratingFeatures,"_featureHydrationStatus",((e,t,r,s)=>{if(this._rehydratingFeatureCount--,!this._rehydratingFeatureCount){const e=this._rehydratingFeatures.toArray();this.addMany(e),this.emit("feature-hydration-complete",e)}})),this.on("dehydrated-features-added",(async e=>{this._rehydratingFeatures.addMany(e);const t=groupBy(e,(e=>e.source)),r=groupBy(await toArray(from([...t.entries()].map((([e,t])=>{let r;try{r=e?.getFeatures(t.map((e=>e.primaryKey)).filter((e=>!!e)))??empty()}catch(t){r=empty(),log.error({error:t,message:`Failed to hydrate features from source '${e?.title??e?.id}`})}return r})))),(e=>e.source));[...t.entries()].forEach((([e,t])=>{const s=r.get(e);t.forEach((e=>{const t=s?.find((t=>t.primaryKey===e.primaryKey));t&&(e.geometry=t.geometry,[...t.attributes.entries()].forEach((([t,r])=>{e.attributes.set(t,r)}))),e._hydrationStatus=void 0}))}))})),this.assignProperties(e)}get size(){return this._features.size}get source(){return this._source}set source(e){this._source&&this.settings.parent===this._source.featureSettings&&(this.settings.parent=void 0),this._source&&this.schema.parent===this._source.schema&&(this.settings.parent=void 0),this._source=e,this.settings.parent||(this.settings.parent=e?e.featureSettings:void 0),this.schema.parent||(this.schema.parent=e?e.schema:void 0)}get itemType(){return ItemType.FEATURE_SET}static async fromFeatureStream(e,t){const r=new FeatureSet_1(t);for await(const t of e)r.add(t);return r}on(e,t){return super.on(e,t)}assignProperties(e){assignProperties(this._getSerializableProperties(),this,e)}has(e){return this._features.has(e._key)}entries(){return[...this._features].map((([e,t])=>[t,t]))[Symbol.iterator]()}keys(){return this._features.values()}values(){return this._features.values()}toJSON(e="all"){return filterJSONProperties(this._getSerializableProperties(),this,e)}toItemUri(){return`item://${encodeURIComponent(ItemType.FEATURE_SET)}/${encodeURIComponent(this.id)}`}add(e){return this._add(e)}addMany(e){const t=[],r=[];for(const s of e){const e=this._features.get(s._key);s!==e&&(this._add(s,!1),t.push(s),e&&r.push(e))}return t.length&&(this._notifyChange("size"),this.emit("change",{added:t,removed:r,moved:[],target:this})),this}clear(){const e=Array.from(this.values());this._features.clear(),this._notifyChange("size"),this.emit("change",{added:[],removed:e,moved:[],target:this})}delete(e){return this._delete(e)}deleteMany(e){const t=[];for(const r of e){const e=this._features.get(r._key);this._delete(r,!1)&&t.push(e)}return t.length&&(this._notifyChange("size"),this.emit("change",{added:[],removed:t,moved:[],target:this})),!!t.length}forEach(e,t){this._features.forEach((t=>e(t,t,this)),t)}findById(e){return find(this,(t=>t.id===e))}findByPrimaryKey(e){return find(this,(t=>t.primaryKey===e))}getSerializableProperties(e="all"){return getSerializableProperties(this._getSerializableProperties(),e)}getDefaults(){return getDefaults(this._getSerializableProperties())}getDefault(e){return this.getDefaults()[e]}[(Symbol.toStringTag,Symbol.iterator)](){return this._features.values()[Symbol.iterator]()}_add(e,t=!0){const r=this._features.get(e._key);return r&&r!==e&&this._delete(r,!1),this._features.set(e._key,e),t&&r!==e&&(this._notifyChange("size"),this.emit("change",{added:[e],removed:r?[r]:[],moved:[],target:this})),this.source&&!e.source&&(e.source=this.source),e.schema.parent||(e.schema.parent=this.schema),e.settings.parent||(e.settings.parent=this.settings),this}_delete(e,t=!0){if(!this.has(e))return!1;const r=this._features.get(e._key);return this._features.delete(e._key),t&&(this._notifyChange("size"),this.emit("change",{added:[],removed:[r],moved:[],target:this})),e.schema.parent===this.schema&&(e.schema.parent=void 0),e.settings.parent===this.settings&&(e.settings.parent=void 0),!0}_getSerializableProperties(){return{id:["project"],features:{serializeModes:["project"],serialize:()=>[...this],deserialize:e=>{const t=[],r=[];compare(this._rehydratingFeatures.concat([...this]),e,{onNew:e=>{if(isFeature(e))"dehydrated"===e._hydrationStatus?(e._hydrationStatus="rehydrating",this._rehydratingFeatureCount++,t.push(e)):"rehydrating"===e._hydrationStatus?(this._rehydratingFeatureCount++,this._rehydratingFeatures.push(e)):(r.push(e),this.add(e));else{const t=new Feature(e);r.push(t),this.add(t)}},onMatch:(e,r)=>{isFeature(r)?"dehydrated"===e._hydrationStatus?(e._hydrationStatus="rehydrating",this._rehydratingFeatureCount++,t.push(e)):e!==r&&this.add(r):e.assignProperties(r)},onMissing:e=>{this.delete(e)},equals:(e,t)=>isFeature(t)?e._key===t._key:e.id===t.id}),t.length?this.emit("dehydrated-features-added",t):this._rehydratingFeatureCount||this.emit("feature-hydration-complete",r)}},title:["project"],source:[],schema:[],settings:[]}}};FeatureSet=FeatureSet_1=__decorate([serializable],FeatureSet);export{FeatureSet};
1
+ var FeatureSet_1;import{__decorate}from"tslib";import Collection from"@arcgis/core/core/Collection";import{generateId}from"../Entity.js";import{isFeature,ItemType}from"../ItemType.js";import{Observable}from"../support/Observable.js";import{assignProperties,filterJSONProperties,getDefaults,getSerializableProperties,serializable}from"../support/Serializable.js";import{ObservableMap}from"../utilities/ObservableMap.js";import{groupBy}from"../utilities/array.js";import{toArray,from,empty}from"../utilities/asyncIterable.js";import{compare,find}from"../utilities/iterable.js";import{getLogger}from"../utilities/log.js";import{watchEach}from"../utilities/watch.js";import{Feature}from"./Feature.js";import{FeatureSettings}from"./FeatureSettings.js";import{Schema}from"./Schema.js";const log=getLogger("feature-set");let FeatureSet=FeatureSet_1=class extends Observable{constructor(e){super(),this.settings=new FeatureSettings,this.schema=new Schema,this._rehydratingFeatureCount=0,this._rehydratingFeatures=new Collection,this._features=new ObservableMap,this.schema._featureSettings=this.settings,this.id=e?.id??generateId(),watchEach(this._rehydratingFeatures,"_featureHydrationStatus",((e,t,r,s)=>{if(this._rehydratingFeatureCount--,!this._rehydratingFeatureCount){const e=this._rehydratingFeatures.toArray();this.addMany(e),this.emit("feature-hydration-complete",e)}})),this.on("dehydrated-features-added",(async e=>{this._rehydratingFeatures.addMany(e);const t=groupBy(e,(e=>e.source)),r=groupBy(await toArray(from([...t.entries()].map((([e,t])=>{let r;try{r=e?.getFeatures(t.map((e=>e.primaryKey)).filter((e=>!!e)))??empty()}catch(t){r=empty(),log.error({error:t,message:`Failed to hydrate features from source '${e?.title??e?.id}`})}return r})))),(e=>e.source));[...t.entries()].forEach((([e,t])=>{const s=r.get(e);t.forEach((e=>{const t=s?.find((t=>t.primaryKey===e.primaryKey));t&&(e.geometry=t.geometry,[...t.attributes.entries()].forEach((([t,r])=>{e.attributes.set(t,r)}))),e._hydrationStatus=void 0}))}))})),this.assignProperties(e)}get size(){return this._features.size}get source(){return this._source}set source(e){this._source&&this.settings.parent===this._source.featureSettings&&(this.settings.parent=void 0),this._source&&this.schema.parent===this._source.schema&&(this.settings.parent=void 0),this._source=e,this.settings.parent||(this.settings.parent=e?e.featureSettings:void 0),this.schema.parent||(this.schema.parent=e?e.schema:void 0)}get itemType(){return ItemType.FEATURE_SET}static async fromFeatureStream(e,t){const r=new FeatureSet_1(t);for await(const t of e)r.add(t);return r}on(e,t){return super.on(e,t)}assignProperties(e){assignProperties(this._getSerializableProperties(),this,e)}has(e){return this._features.has(e._key)}entries(){return[...this._features].map((([e,t])=>[t,t]))[Symbol.iterator]()}keys(){return this._features.values()}values(){return this._features.values()}toJSON(e="all"){return filterJSONProperties(this._getSerializableProperties(),this,e)}toItemUri(){return`item://${encodeURIComponent(ItemType.FEATURE_SET)}/${encodeURIComponent(this.id)}`}add(e){return this._add(e)}addMany(e){const t=[],r=[];for(const s of e){const e=this._features.get(s._key);s!==e&&(this._add(s,!1),t.push(s),e&&r.push(e))}return t.length&&(this.notifyChange("size"),this.emit("change",{added:t,removed:r,moved:[],target:this})),this}clear(){const e=Array.from(this.values());this._features.clear(),this.notifyChange("size"),this.emit("change",{added:[],removed:e,moved:[],target:this})}delete(e){return this._delete(e)}deleteMany(e){const t=[];for(const r of e){const e=this._features.get(r._key);this._delete(r,!1)&&t.push(e)}return t.length&&(this.notifyChange("size"),this.emit("change",{added:[],removed:t,moved:[],target:this})),!!t.length}forEach(e,t){this._features.forEach((t=>e(t,t,this)),t)}findById(e){return find(this,(t=>t.id===e))}findByPrimaryKey(e){return find(this,(t=>t.primaryKey===e))}getSerializableProperties(e="all"){return getSerializableProperties(this._getSerializableProperties(),e)}getDefaults(){return getDefaults(this._getSerializableProperties())}getDefault(e){return this.getDefaults()[e]}[(Symbol.toStringTag,Symbol.iterator)](){return this._features.values()[Symbol.iterator]()}_add(e,t=!0){const r=this._features.get(e._key);return r&&r!==e&&this._delete(r,!1),this._features.set(e._key,e),t&&r!==e&&(this.notifyChange("size"),this.emit("change",{added:[e],removed:r?[r]:[],moved:[],target:this})),this.source&&!e.source&&(e.source=this.source),e.schema.parent||(e.schema.parent=this.schema),e.settings.parent||(e.settings.parent=this.settings),this}_delete(e,t=!0){if(!this.has(e))return!1;const r=this._features.get(e._key);return this._features.delete(e._key),t&&(this.notifyChange("size"),this.emit("change",{added:[],removed:[r],moved:[],target:this})),e.schema.parent===this.schema&&(e.schema.parent=void 0),e.settings.parent===this.settings&&(e.settings.parent=void 0),!0}_getSerializableProperties(){return{id:["project"],features:{serializeModes:["project"],serialize:()=>[...this],deserialize:e=>{const t=[],r=[];compare(this._rehydratingFeatures.concat([...this]),e,{onNew:e=>{if(isFeature(e))"dehydrated"===e._hydrationStatus?(e._hydrationStatus="rehydrating",this._rehydratingFeatureCount++,t.push(e)):"rehydrating"===e._hydrationStatus?(this._rehydratingFeatureCount++,this._rehydratingFeatures.push(e)):(r.push(e),this.add(e));else{const t=new Feature(e);r.push(t),this.add(t)}},onMatch:(e,r)=>{isFeature(r)?"dehydrated"===e._hydrationStatus?(e._hydrationStatus="rehydrating",this._rehydratingFeatureCount++,t.push(e)):e!==r&&this.add(r):e.assignProperties(r)},onMissing:e=>{this.delete(e)},equals:(e,t)=>isFeature(t)?e._key===t._key:e.id===t.id}),t.length?this.emit("dehydrated-features-added",t):this._rehydratingFeatureCount||this.emit("feature-hydration-complete",r)}},title:["project"],source:[],schema:[],settings:[]}}};FeatureSet=FeatureSet_1=__decorate([serializable],FeatureSet);export{FeatureSet};
@@ -1 +1 @@
1
- var FieldExtension_1;import{__decorate}from"tslib";import EsriField from"@arcgis/core/layers/support/Field";import{EntityBase}from"../Entity.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{isFieldExtension,ItemType}from"../ItemType.js";import{Field as PortalField}from"../portal/Field.js";import{FormatSettings}from"../support/FormatSettings.js";import{serializable}from"../support/Serializable.js";import{esriFormatToGeocortexFormat}from"../utilities/date.js";import{isField}from"../utilities/esri.js";import{NumberFormat}from"../utilities/number.js";import{deepClone}from"../utilities/object.js";import{fieldWithArcadeXRegex}from"./Schema.js";export const _fieldExtensionMap=new WeakMap;let FieldExtension=FieldExtension_1=class extends EntityBase{constructor(e){super(e),this.format="{0}",this.formatSettings=new FieldExtensionFormatSettings(this),this.searchable=!0,this._itemType=ItemType.FIELD_EXTENSION;const{field:i}=e??{};isField(i)?this._setField(i):"string"==typeof i?this._deferredFieldProperties={$ref:i}:i?i.$ref?this._deferredFieldProperties=i:this._setField(PortalField.toEsriApiField(i)):this._setField(new EsriField),this.watch("_schema.featureSource",(()=>this.notifyChange("fieldInfo"))),this.watch("_schema._featureSettings",(e=>{this.formatSettings.parent=e?e.formatSettings:void 0}),!0)}get field(){return this._field}get schema(){return this._schema}get fieldInfo(){if(this._fieldInfo)return this._fieldInfo;if(!this.field||!this.field.name)return;const e=this._schema?._featureSettings?.popupTemplate,i=e?.fieldInfos||[];return this._fieldInfo=i.find((e=>e.fieldName===this.field.name)),this._fieldInfo}static matchesRef(e,i){return isFieldExtension(e)?(e.field?.name??e._deferredFieldProperties?.$ref)===i.$ref:e.name===i.$ref}_setSchema(e){this._schema=e,this._resolveField(),this.notifyChange("schema"),this.notifyChange("fieldInfo")}_resolveField(){if(this._field||!this._deferredFieldProperties||!this._schema)return;const e=this._schema.fields.find((e=>FieldExtension_1.matchesRef(e,this._deferredFieldProperties)));e&&(this._setField(e),this.assignProperties({field:this._deferredFieldProperties}),this._originalRef=this._deferredFieldProperties.$ref,delete this._deferredFieldProperties,_fieldExtensionMap.set(e,this))}_getSerializableProperties(){return{...super._getSerializableProperties(),field:{serializeModes:["initial"],serialize:()=>this.field?this._originalRef?{$ref:this._originalRef}:this._schema?.fields.includes(this._field)&&this.field.name?{$ref:this.field.name}:PortalField.fromEsriApiField(this.field):this._deferredFieldProperties?deepClone(this._deferredFieldProperties):void 0,deserialize:e=>{if(isField(e)){if(e!==this.field)throw new Error("Property 'field' is read-only.")}else e&&this.field&&PortalField.applyToEsriApiField(e,this.field)}},searchable:{serializeModes:["initial"],isDefault:e=>e!==this._isArcadeExpressionField},format:{serializeModes:["initial"],default:"{0}"},formatSettings:"initial"}}async _onInitialize(){if(this._resolveField(),!this._field){const e=this._deferredFieldProperties.$ref;throw this._schema?new InvalidOperationError(`Field not found with name: ${e}. Field does not exist.`):new InvalidOperationError(`Field not found with name: ${e}. Field does not have a parent schema.`)}}_setField(e){this._field=e,this._isArcadeExpressionField&&(this.searchable=!1),this._notifyChange("field"),this._notifyChange("fieldInfo")}get _isArcadeExpressionField(){return!!this._field&&!!this._field.name&&!!this._field.name.match(fieldWithArcadeXRegex)}};FieldExtension=FieldExtension_1=__decorate([serializable],FieldExtension);export{FieldExtension};let FieldExtensionFormatSettings=class extends FormatSettings{constructor(e,i){super(i),this.fieldExtension=e,e.watch("fieldInfo.format.places",(()=>this._notifyChange("fractionalDigits"))),e.watch("fieldInfo.format.digitSeparator",(()=>this._notifyChange("numberFormat"))),e.watch("fieldInfo.format.dateFormat",(()=>this._notifyChange("dateFormat")))}get fractionalDigits(){const e=this.fieldExtension.fieldInfo?.format?.places;return!this.isModified("fractionalDigits")&&this.useFieldInfo&&e?e:this._getSetting("fractionalDigits")}set fractionalDigits(e){this._setSetting("fractionalDigits",e)}get numberFormat(){const e=this.fieldExtension.fieldInfo?.format?.digitSeparator;return!this.isModified("numberFormat")&&this.useFieldInfo&&e?e?NumberFormat.NUMBER:NumberFormat.FIXED_POINT:this._getSetting("numberFormat")}set numberFormat(e){this._setSetting("numberFormat",e)}get dateFormat(){const e=this.fieldExtension.fieldInfo?.format?.dateFormat;return!this.isModified("dateFormat")&&this.useFieldInfo&&e?esriFormatToGeocortexFormat(e):this._getSetting("dateFormat")}set dateFormat(e){this._setSetting("dateFormat",e)}};FieldExtensionFormatSettings=__decorate([serializable],FieldExtensionFormatSettings);
1
+ var FieldExtension_1;import{__decorate}from"tslib";import EsriField from"@arcgis/core/layers/support/Field";import{EntityBase}from"../Entity.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{isFieldExtension,ItemType}from"../ItemType.js";import{Field as PortalField}from"../portal/Field.js";import{FormatSettings}from"../support/FormatSettings.js";import{serializable}from"../support/Serializable.js";import{esriFormatToGeocortexFormat}from"../utilities/date.js";import{isField}from"../utilities/esri.js";import{NumberFormat}from"../utilities/number.js";import{deepClone}from"../utilities/object.js";import{fieldWithArcadeXRegex}from"./Schema.js";export const _fieldExtensionMap=new WeakMap;let FieldExtension=FieldExtension_1=class extends EntityBase{constructor(e){super(e),this.format="{0}",this.formatSettings=new FieldExtensionFormatSettings(this),this.searchable=!0,this._itemType=ItemType.FIELD_EXTENSION;const{field:i}=e??{};isField(i)?this._setField(i):"string"==typeof i?this._deferredFieldProperties={$ref:i}:i?i.$ref?this._deferredFieldProperties=i:this._setField(PortalField.toEsriApiField(i)):this._setField(new EsriField),this.watch("_schema.featureSource",(()=>this.notifyChange("fieldInfo"))),this.watch("_schema._featureSettings",(e=>{this.formatSettings.parent=e?e.formatSettings:void 0}),!0)}get field(){return this._field}get schema(){return this._schema}get fieldInfo(){if(this._fieldInfo)return this._fieldInfo;if(!this.field||!this.field.name)return;const e=this._schema?._featureSettings?.popupTemplate,i=e?.fieldInfos||[];return this._fieldInfo=i.find((e=>e.fieldName===this.field.name)),this._fieldInfo}static matchesRef(e,i){return isFieldExtension(e)?(e.field?.name??e._deferredFieldProperties?.$ref)===i.$ref:e.name===i.$ref}_setSchema(e){this._schema=e,this._resolveField(),this.notifyChange("schema"),this.notifyChange("fieldInfo")}_resolveField(){if(this._field||!this._deferredFieldProperties||!this._schema)return;const e=this._schema.fields.find((e=>FieldExtension_1.matchesRef(e,this._deferredFieldProperties)));e&&(this._setField(e),this.assignProperties({field:this._deferredFieldProperties}),this._originalRef=this._deferredFieldProperties.$ref,delete this._deferredFieldProperties,_fieldExtensionMap.set(e,this))}_getSerializableProperties(){return{...super._getSerializableProperties(),field:{serializeModes:["initial"],serialize:()=>this.field?this._originalRef?{$ref:this._originalRef}:this._schema?.fields.includes(this._field)&&this.field.name?{$ref:this.field.name}:PortalField.fromEsriApiField(this.field):this._deferredFieldProperties?deepClone(this._deferredFieldProperties):void 0,deserialize:e=>{if(isField(e)){if(e!==this.field)throw new Error("Property 'field' is read-only.")}else e&&this.field&&PortalField.applyToEsriApiField(e,this.field)}},searchable:{serializeModes:["initial"],isDefault:e=>e!==this._isArcadeExpressionField},format:{serializeModes:["initial"],default:"{0}"},formatSettings:"initial"}}async _onInitialize(){if(this._resolveField(),!this._field){const e=this._deferredFieldProperties.$ref;throw this._schema?new InvalidOperationError(`Field not found with name: ${e}. Field does not exist.`):new InvalidOperationError(`Field not found with name: ${e}. Field does not have a parent schema.`)}}_setField(e){this._field=e,this._isArcadeExpressionField&&(this.searchable=!1),this.notifyChange("field"),this.notifyChange("fieldInfo")}get _isArcadeExpressionField(){return!!this._field&&!!this._field.name&&!!this._field.name.match(fieldWithArcadeXRegex)}};FieldExtension=FieldExtension_1=__decorate([serializable],FieldExtension);export{FieldExtension};let FieldExtensionFormatSettings=class extends FormatSettings{constructor(e,i){super(i),this.fieldExtension=e,e.watch("fieldInfo.format.places",(()=>this.notifyChange("fractionalDigits"))),e.watch("fieldInfo.format.digitSeparator",(()=>this.notifyChange("numberFormat"))),e.watch("fieldInfo.format.dateFormat",(()=>this.notifyChange("dateFormat")))}get fractionalDigits(){const e=this.fieldExtension.fieldInfo?.format?.places;return!this.isModified("fractionalDigits")&&this.useFieldInfo&&e?e:this._getSetting("fractionalDigits")}set fractionalDigits(e){this._setSetting("fractionalDigits",e)}get numberFormat(){const e=this.fieldExtension.fieldInfo?.format?.digitSeparator;return!this.isModified("numberFormat")&&this.useFieldInfo&&e?e?NumberFormat.NUMBER:NumberFormat.FIXED_POINT:this._getSetting("numberFormat")}set numberFormat(e){this._setSetting("numberFormat",e)}get dateFormat(){const e=this.fieldExtension.fieldInfo?.format?.dateFormat;return!this.isModified("dateFormat")&&this.useFieldInfo&&e?esriFormatToGeocortexFormat(e):this._getSetting("dateFormat")}set dateFormat(e){this._setSetting("dateFormat",e)}};FieldExtensionFormatSettings=__decorate([serializable],FieldExtensionFormatSettings);
@@ -78,7 +78,6 @@ export declare class PopupContentExtension extends EntityBase<PopupContentExtens
78
78
  protected readonly _itemType: string;
79
79
  private _content;
80
80
  private _featureSettings;
81
- private _deferredContentProperties;
82
81
  private _originalRef;
83
82
  private get _index();
84
83
  /**
@@ -1 +1 @@
1
- var PopupContentExtension_1;import{__decorate}from"tslib";import Content from"@arcgis/core/popup/content/Content.js";import{EntityBase}from"../Entity.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{ItemType}from"../ItemType.js";import{PopupContent}from"../portal/PopupInfo.js";import{serializable}from"../support/Serializable.js";import{Collection}from"../support/esri.js";import{compare}from"../utilities/array.js";import{isCustomContent,isExpressionContent,isPopupContent,isTextContent}from"../utilities/esri.js";import{deepClone}from"../utilities/object.js";export const _popupContentExtensionMap=new WeakMap;let PopupContentExtension=PopupContentExtension_1=class extends EntityBase{constructor(t){super(t),this.summaryHiddenFields=new Collection,this._itemType=ItemType.POPUP_CONTENT_EXTENSION;const{content:e,visibleInSummary:n}=t??{};isPopupContent(e)?this._setContent(e):"string"==typeof e?this._deferredContentProperties={$ref:e}:e?e.$ref?this._deferredContentProperties=e:this._setContent(PopupContent.toEsriApiPopupContent(e)):this._setContent(new Content),this.visibleInSummary=n??this._getDefaultSummaryVisibility()}get content(){return this._content}get featureSettings(){return this._featureSettings}get _index(){return Array.isArray(this.featureSettings.popupTemplate?.content)?this.featureSettings.popupTemplate.content.indexOf(this.content):-1}static matchesRef(t,e,n){const i=t.map(((t,e)=>contentToRef(t,t instanceof PopupContentExtension_1?t._index:e))),o=i[e],{type:r,index:s,title:p,text:a}=n.$ref;if(r!==o.type)return!1;if("text"===r&&a===o.text)return!0;if(p&&p===o.title)return!0;if("number"==typeof s&&s===o.index)return!0;return 1===i.map(((t,e)=>t.type===r?t.index:void 0)).filter((t=>"number"==typeof t)).length}_setFeatureSettings(t){this._featureSettings=t,this._resolveContent(),this.notifyChange("featureSettings")}_resolveContent(){if(this._content||!this._deferredContentProperties||!this._featureSettings)return;const t=this._featureSettings._popupContent.find(((t,e)=>PopupContentExtension_1.matchesRef(this.featureSettings._popupContent.toArray(),e,this._deferredContentProperties)));t&&(this._setContent(t),this.assignProperties({content:this._deferredContentProperties}),this._originalRef={...this._deferredContentProperties.$ref},delete this._deferredContentProperties,_popupContentExtensionMap.set(t,this))}_getSerializableProperties(){return{...super._getSerializableProperties(),content:{serializeModes:["initial"],serialize:()=>this.content?this._originalRef?{$ref:this._originalRef}:this._featureSettings?._popupContent.includes(this._content)?{$ref:contentToRef(this.content,this._index)}:PopupContent.fromEsriApiPopupContent(this.content):this._deferredContentProperties?deepClone(this._deferredContentProperties):void 0,deserialize:t=>{if(isPopupContent(t)){if(t!==this.content)throw new Error("Property 'popupContent' is read-only.")}else t&&this.content&&PopupContent.applyToEsriApiPopupContent(t,this.content)}},visibleInSummary:{serializeModes:["initial"],isDefault:(t,e)=>t===this._getDefaultSummaryVisibility()},summaryHiddenFields:{serializeModes:["initial"],serialize:()=>this.summaryHiddenFields.toArray(),deserialize:t=>{compare(this.summaryHiddenFields,t,{onMatch:(t,e,n,i)=>{this.summaryHiddenFields.reorder(t,i)},onMissing:t=>this.summaryHiddenFields.remove(t),onNew:t=>this.summaryHiddenFields.add(t)})}}}}async _onInitialize(){if(this._resolveContent(),!this._content){const t=this._deferredContentProperties.$ref;throw this._featureSettings?new InvalidOperationError(`PopupContent not found with reference: ${JSON.stringify(t)}. PopupContent does not exist.`):new InvalidOperationError(`PopupContent not found with reference: ${JSON.stringify(t)}. PopupContent does not have a parent featureSettings.`)}}_setContent(t){this._content=t,this._notifyChange("content")}_getDefaultSummaryVisibility(){return"text"===(this.content?.type??this._deferredContentProperties?.type??this._deferredContentProperties?.$ref?.type)}};PopupContentExtension=PopupContentExtension_1=__decorate([serializable],PopupContentExtension);export{PopupContentExtension};function contentToRef(t,e){const n=t instanceof PopupContentExtension?t.content:t,i={type:n.type};return e>=0&&(i.index=e),isExpressionContent(n)?i.title=n.expressionInfo.title:isTextContent(n)?i.text=n.text:isCustomContent(n)||(i.title=n.title),i}
1
+ var PopupContentExtension_1;import{__decorate}from"tslib";import Content from"@arcgis/core/popup/content/Content.js";import{EntityBase}from"../Entity.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{ItemType}from"../ItemType.js";import{PopupContent}from"../portal/PopupInfo.js";import{serializable}from"../support/Serializable.js";import{Collection}from"../support/esri.js";import{compare}from"../utilities/array.js";import{isCustomContent,isExpressionContent,isPopupContent,isTextContent}from"../utilities/esri.js";import{deepClone}from"../utilities/object.js";export const _popupContentExtensionMap=new WeakMap;let PopupContentExtension=PopupContentExtension_1=class extends EntityBase{constructor(t){super(t),this.summaryHiddenFields=new Collection,this._itemType=ItemType.POPUP_CONTENT_EXTENSION;const{content:e,visibleInSummary:n}=t??{};isPopupContent(e)?this._setContent(e):"string"==typeof e?this._deferredContentProperties={$ref:e}:e?e.$ref?this._deferredContentProperties=e:this._setContent(PopupContent.toEsriApiPopupContent(e)):this._setContent(new Content),this.visibleInSummary=n??this._getDefaultSummaryVisibility()}get content(){return this._content}get featureSettings(){return this._featureSettings}get _index(){return Array.isArray(this.featureSettings.popupTemplate?.content)?this.featureSettings.popupTemplate.content.indexOf(this.content):-1}static matchesRef(t,e,n){const i=t.map(((t,e)=>contentToRef(t,t instanceof PopupContentExtension_1?t._index:e))),o=i[e],{type:r,index:s,title:p,text:a}=n.$ref;if(r!==o.type)return!1;if("text"===r&&a===o.text)return!0;if(p&&p===o.title)return!0;if("number"==typeof s&&s===o.index)return!0;return 1===i.map(((t,e)=>t.type===r?t.index:void 0)).filter((t=>"number"==typeof t)).length}_setFeatureSettings(t){this._featureSettings=t,this._resolveContent(),this.notifyChange("featureSettings")}_resolveContent(){if(this._content||!this._deferredContentProperties||!this._featureSettings)return;const t=this._featureSettings._popupContent.find(((t,e)=>PopupContentExtension_1.matchesRef(this.featureSettings._popupContent.toArray(),e,this._deferredContentProperties)));t&&(this._setContent(t),this.assignProperties({content:this._deferredContentProperties}),this._originalRef={...this._deferredContentProperties.$ref},delete this._deferredContentProperties,_popupContentExtensionMap.set(t,this))}_getSerializableProperties(){return{...super._getSerializableProperties(),content:{serializeModes:["initial"],serialize:()=>this.content?this._originalRef?{$ref:this._originalRef}:this._featureSettings?._popupContent.includes(this._content)?{$ref:contentToRef(this.content,this._index)}:PopupContent.fromEsriApiPopupContent(this.content):this._deferredContentProperties?deepClone(this._deferredContentProperties):void 0,deserialize:t=>{if(isPopupContent(t)){if(t!==this.content)throw new Error("Property 'popupContent' is read-only.")}else t&&this.content&&PopupContent.applyToEsriApiPopupContent(t,this.content)}},visibleInSummary:{serializeModes:["initial"],isDefault:(t,e)=>t===this._getDefaultSummaryVisibility()},summaryHiddenFields:{serializeModes:["initial"],serialize:()=>this.summaryHiddenFields.toArray(),deserialize:t=>{compare(this.summaryHiddenFields,t,{onMatch:(t,e,n,i)=>{this.summaryHiddenFields.reorder(t,i)},onMissing:t=>this.summaryHiddenFields.remove(t),onNew:t=>this.summaryHiddenFields.add(t)})}}}}async _onInitialize(){if(this._resolveContent(),!this._content){const t=this._deferredContentProperties.$ref;throw this._featureSettings?new InvalidOperationError(`PopupContent not found with reference: ${JSON.stringify(t)}. PopupContent does not exist.`):new InvalidOperationError(`PopupContent not found with reference: ${JSON.stringify(t)}. PopupContent does not have a parent featureSettings.`)}}_setContent(t){this._content=t,this.notifyChange("content")}_getDefaultSummaryVisibility(){return"text"===(this.content?.type??this._deferredContentProperties?.type??this._deferredContentProperties?.$ref?.type)}};PopupContentExtension=PopupContentExtension_1=__decorate([serializable],PopupContentExtension);export{PopupContentExtension};function contentToRef(t,e){const n=t instanceof PopupContentExtension?t.content:t;if(!n)return t._deferredContentProperties?.$ref;const i={type:n.type};return e>=0&&(i.index=e),isExpressionContent(n)?i.title=n.expressionInfo.title:isTextContent(n)?i.text=n.text:isCustomContent(n)||(i.title=n.title),i}
@@ -1,4 +1,22 @@
1
- declare module "@arcgis/core/core/workers/utils";
1
+ declare module "@arcgis/core/core/accessorSupport/tracking" {
2
+ export function trackAccess(accessorProp: unknown): void;
3
+ }
4
+
5
+ declare module "@arcgis/core/core/accessorSupport/Property" {
6
+ interface Properties {
7
+ host: __esri.Accessor;
8
+ }
9
+ export class Property {
10
+ constructor(properties: Properties, propertyName: string, metadata: unknown);
11
+ propertyName: string;
12
+ properties: Properties;
13
+ observe(observer: unknown): IHandle;
14
+ invalidate(): void;
15
+ commit(): void;
16
+ }
17
+ }
18
+
19
+ declare module "@arcgis/core/core/workers/utils";
2
20
  declare module "@arcgis/core/core/Warning" {
3
21
  interface Warning {}
4
22