@vertigis/arcgis-extensions 53.5.2 → 53.6.1

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 (26) hide show
  1. package/data/FeatureSet.js +1 -1
  2. package/data/Schema.d.ts +10 -0
  3. package/data/Schema.js +1 -1
  4. package/docs/html/assets/search.js +1 -1
  5. package/docs/html/classes/data_Schema.Schema.html +7 -2
  6. package/docs/html/classes/data__TableExtension.TableSchema.html +8 -3
  7. package/docs/html/classes/mapping_BuildingComponentSublayerExtension.BuildingComponentSublayerSchema.html +8 -3
  8. package/docs/html/classes/mapping_BuildingGroupSublayerExtension.BuildingGroupSublayerSchema.html +8 -3
  9. package/docs/html/classes/mapping_BuildingSceneLayerExtension.BuildingSceneLayerReadOnlySchema.html +7 -2
  10. package/docs/html/classes/mapping_BuildingSublayerExtension.BuildingSublayerSchema.html +8 -3
  11. package/docs/html/classes/mapping_FeatureLayerExtensionBase.FeatureLayerReadOnlySchema.html +7 -2
  12. package/docs/html/classes/mapping_FeatureLayerExtensionBase.FeatureLayerSchema.html +7 -2
  13. package/docs/html/classes/mapping_MapNotesSublayerExtension.MapNotesSublayerExtensionSchema.html +8 -3
  14. package/docs/html/classes/mapping_RouteLayerExtension.RouteLayerExtensionSchema.html +7 -2
  15. package/docs/html/classes/mapping_StreamLayerExtension.StreamLayerSchema.html +7 -2
  16. package/docs/html/classes/mapping_SubtypeGroupLayerExtension.SubtypeGroupLayerSchema.html +7 -2
  17. package/docs/html/classes/mapping_SubtypeSublayerExtension.SubtypeSublayerSchema.html +8 -3
  18. package/docs/html/classes/mapping__LayerExtension.LayerExtensionReadOnlySchema.html +7 -2
  19. package/docs/html/classes/mapping__LayerExtension.LayerExtensionSchema.html +7 -2
  20. package/docs/html/classes/mapping__SublayerExtension.SublayerSchema.html +8 -3
  21. package/docs/html/variables/version.version.html +1 -1
  22. package/mapping/ArcGISSublayerExtension.js +1 -1
  23. package/package.json +1 -1
  24. package/utilities/esri.js +1 -1
  25. package/version.d.ts +1 -1
  26. package/version.js +1 -1
@@ -1 +1 @@
1
- var e;import{__decorate as t}from"tslib";import r from"@arcgis/core/core/Collection";import{Evented as s}from"@arcgis/core/core/Evented.js";import{generateId as i}from"../Entity.js";import{isFeature as a,ItemType as h}from"../ItemType.js";import{assignProperties as o,assignPropertiesAsync as n,filterJSONProperties as u,getDefaults as d,getSerializableProperties as c,serializable as m}from"../support/Serializable.js";import{notifyChange as g,observable as l,watchEach as y}from"../support/observableUtils.js";import{ObservableMap as p}from"../utilities/ObservableMap.js";import{groupBy as _}from"../utilities/array.js";import{toArray as f,from as S,empty as v}from"../utilities/asyncIterable.js";import{compare as b,find as F}from"../utilities/iterable.js";import{getLogger as z}from"../utilities/log.js";import{Feature as j}from"./Feature.js";import{FeatureSettings as E}from"./FeatureSettings.js";import{Schema as P}from"./Schema.js";const k=z("feature-set");let C=e=class extends(l(s)){[Symbol.toStringTag];id;title;get size(){return this._features.size}get source(){return this._source}set source(e){this._source===e||null==this._source&&null==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))}settings=new E;schema=new P;get itemType(){return h.FEATURE_SET}_source;_rehydratingFeatureCount=0;_rehydratingFeatures=new r;_features=new p;constructor(e){super(),this.schema._featureSettings=this.settings,this.id=e?.id??i(),y(this._rehydratingFeatures,"[]._hydrationStatus",(()=>{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=_(e,(e=>e.source)),r=_(await f(S([...t.entries()].map((([e,t])=>{let r;try{r=e?.getFeatures(t.map((e=>e.primaryKey)).filter((e=>!!e)))??v()}catch(t){r=v(),k.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)}static async fromFeatureStream(t,r){const s=new e(r);for await(const e of t)s.add(e);return s}assignProperties(e){o(this._getSerializableProperties(),this,e)}async assignPropertiesAsync(e){return n(this._getSerializableProperties(),this,e)}async finishAssignProperties(){}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 u(this._getSerializableProperties(),this,e)}toItemUri(){return`item://${encodeURIComponent(h.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&&(g(this,"size"),this.emit("change",{added:t,removed:r,moved:[],target:this})),this}clear(){const e=Array.from(this.values());this._features.clear(),g(this,"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&&(g(this,"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 F(this,(t=>t.id===e))}findByPrimaryKey(e){return F(this,(t=>t.primaryKey===e))}getSerializableProperties(e="all"){return c(this._getSerializableProperties(),e)}getDefaults(){return d(this._getSerializableProperties())}getDefault(e){return this.getDefaults()[e]}[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&&(g(this,"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&&(g(this,"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=[];b(this._rehydratingFeatures.concat([...this]),e,{onNew:e=>{if(a(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 j(e);r.push(t),this.add(t)}},onMatch:(e,r)=>{a(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)=>a(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:[]}}};C=e=t([m],C);export{C as FeatureSet};
1
+ var e;import{__decorate as t}from"tslib";import r from"@arcgis/core/core/Collection";import{Evented as s}from"@arcgis/core/core/Evented.js";import{generateId as i}from"../Entity.js";import{isFeature as a,ItemType as h}from"../ItemType.js";import{assignProperties as o,assignPropertiesAsync as n,filterJSONProperties as u,getDefaults as d,getSerializableProperties as c,serializable as m}from"../support/Serializable.js";import{notifyChange as g,observable as l,watchEach as p}from"../support/observableUtils.js";import{ObservableMap as y}from"../utilities/ObservableMap.js";import{groupBy as _}from"../utilities/array.js";import{toArray as f,from as S,empty as v}from"../utilities/asyncIterable.js";import{compare as b,find as F}from"../utilities/iterable.js";import{getLogger as z}from"../utilities/log.js";import{Feature as j}from"./Feature.js";import{FeatureSettings as E}from"./FeatureSettings.js";import{Schema as P}from"./Schema.js";const C=z("feature-set");let k=e=class extends(l(s)){[Symbol.toStringTag];id;title;get size(){return this._features.size}get source(){return this._source}set source(e){this._source===e||null==this._source&&null==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))}settings=new E;schema=new P;get itemType(){return h.FEATURE_SET}_source;_rehydratingFeatureCount=0;_rehydratingFeatures=new r;_features=new y;constructor(e){super(),this.schema._featureSettings=this.settings,this.id=e?.id??i(),p(this._rehydratingFeatures,"[]._hydrationStatus",(()=>{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=_(e,(e=>e.source)),r=_(await f(S([...t.entries()].map((([e,t])=>{let r;try{r=e?.getFeatures(t.map((e=>e.primaryKey)).filter((e=>!!e)))??v()}catch(t){r=v(),C.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)}static async fromFeatureStream(t,r){const s=new e(r);for await(const e of t)s.add(e);return s}assignProperties(e){o(this._getSerializableProperties(),this,e)}async assignPropertiesAsync(e){return n(this._getSerializableProperties(),this,e)}async finishAssignProperties(){}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 u(this._getSerializableProperties(),this,e)}toItemUri(){return`item://${encodeURIComponent(h.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&&(g(this,"size"),this.emit("change",{added:t,removed:r,moved:[],target:this})),this}clear(){const e=Array.from(this.values());this._features.clear(),g(this,"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&&(g(this,"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 F(this,(t=>t.id===e))}findByPrimaryKey(e){return F(this,(t=>t.primaryKey===e))}getSerializableProperties(e="all"){return c(this._getSerializableProperties(),e)}getDefaults(){return d(this._getSerializableProperties())}getDefault(e){return this.getDefaults()[e]}[Symbol.iterator](){return this._features.values()[Symbol.iterator]()}_add(e,t=!0){const r=e._key,s=this._features.get(r);return s&&s!==e&&this._delete(s,!1),this._features.set(r,e),t&&s!==e&&(g(this,"size"),this.emit("change",{added:[e],removed:s?[s]:[],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&&(g(this,"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=[];b(this._rehydratingFeatures.concat([...this]),e,{onNew:e=>{if(a(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 j(e);r.push(t),this.add(t)}},onMatch:(e,r)=>{a(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)=>a(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:[]}}};k=e=t([m],k);export{k as FeatureSet};
package/data/Schema.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import PopupTemplate from "@arcgis/core/PopupTemplate";
2
2
  import Collection from "@arcgis/core/core/Collection";
3
+ import type { ResourceHandle } from "@arcgis/core/core/Handles.js";
3
4
  import type SpatialReference from "@arcgis/core/geometry/SpatialReference";
4
5
  import FeatureType from "@arcgis/core/layers/support/FeatureType";
5
6
  import Field from "@arcgis/core/layers/support/Field";
@@ -119,6 +120,15 @@ export declare class Schema extends Settings<SchemaProperties> {
119
120
  * A collection of Field objects describing each field in the schema.
120
121
  */
121
122
  readonly fields: FieldCollection;
123
+ /**
124
+ * A set of watch handles that get cleaned up when the class instance is
125
+ * destroyed.
126
+ */
127
+ protected readonly _watchHandles: ResourceHandle[];
128
+ /**
129
+ * A cache of the primary key field name used to speed up lookup.
130
+ */
131
+ protected _primaryKeyField: string | undefined;
122
132
  /**
123
133
  * The spatial reference of the schema. Can be defined using a well-known ID
124
134
  * (WKID) or well-known text (WKT).
package/data/Schema.js CHANGED
@@ -1 +1 @@
1
- var e;import{__decorate as i}from"tslib";import t from"@arcgis/core/PopupTemplate";import s from"@arcgis/core/core/Collection";import o from"@arcgis/core/layers/support/FeatureType";import l from"@arcgis/core/layers/support/Field";import d from"@arcgis/core/popup/FieldInfo";import{InvalidOperationError as n}from"../InvalidOperationError.js";import{isFieldExtension as r}from"../ItemType.js";import{jsonToGeometryType as a}from"../json/GeometryJson.js";import{InitializableCollectionProxy as h}from"../support/InitializableCollectionProxy.js";import{filterJSONProperties as m,isDefault as f,serializable as p,shouldExcludeDefaults as c}from"../support/Serializable.js";import{Settings as _}from"../support/Settings.js";import{createIHandle as u,notifyChange as g,onWatch as F,watch as y}from"../support/observableUtils.js";import{CaseInsensitiveObservableMap as x}from"../utilities/CaseInsensitiveObservableMap.js";import{CollectionProxy as v}from"../utilities/CollectionProxy.js";import{ReadOnlyCollection as b}from"../utilities/ReadOnlyCollection.js";import S from"../utilities/_ReferenceCountedHandle.js";import{checkArg as T}from"../utilities/checkArg.js";import{compare as z}from"../utilities/collection.js";import{isFeatureType as w,isField as I}from"../utilities/esri.js";import{fieldWithArcadeXRegex as N,fieldWithRelationshipRegex as E,getArcadeExpressionFromField as A}from"../utilities/field.js";import{ERR_TIME_ZONE_INVALID as j,isValidTimeZone as H}from"../utilities/format/date.js";import{objectKeys as C}from"../utilities/object.js";import{caseInsensitiveEquals as R}from"../utilities/string.js";import{_fieldExtensionMap as M,FieldExtension as O}from"./FieldExtension.js";const B=new Map;B.set("objectid","oid"),B.set("oid","oid"),B.set("fid","oid"),B.set("shape","geometry"),B.set("shape__length","double"),B.set("shape_length","double"),B.set("shape__area","double"),B.set("shape_area","double"),B.set("area","double"),B.set("perimeter","double"),B.set("length","double"),B.set("fnode_","double"),B.set("tnode_","double"),B.set("lpoly_","double"),B.set("rpoly_","double"),B.set("cover_","integer"),B.set("cover_id","integer"),B.set("idtic","integer"),B.set("xtic","double"),B.set("ytic","double"),B.set("xmin","double"),B.set("ymin","double"),B.set("xmax","double"),B.set("ymax","double"),B.set("arc_","double"),B.set("subclass_","integer"),B.set("subclass_id","integer"),B.set("routelink","integer"),B.set("arclink","integer"),B.set("f_meas","double"),B.set("t_meas","double"),B.set("f_pos","double"),B.set("t_pos","double"),B.set("f_meas","double"),B.set("globalid","global-id"),B.set("guid","guid");export{N as fieldWithArcadeXRegex,E as fieldWithRelationshipRegex};const P=new WeakMap;let Z=e=class extends _{fieldExtensions;fields;get spatialReference(){return this._getSetting("spatialReference")}set spatialReference(e){this._setSetting("spatialReference",e)}get primaryKeyField(){const e=this._getSetting("primaryKeyField");if(!e){const e=this.fields.filter((e=>"oid"===e.type));if(1===e.length)return e.getItemAt(0).name}return e}set primaryKeyField(e){this._setSetting("primaryKeyField",e)}get displayField(){return this._getSetting("displayField",this.primaryKeyField)}set displayField(e){!this._featureSettings?.popupTemplate||this._featureSettings.popupTemplate.title&&this._featureSettings.popupTemplate.title!==`{${this.displayField}}`||(this._featureSettings.popupTemplate.title=`{${e}}`),this._setSetting("displayField",e)}get geometryType(){return this._getSetting("geometryType")}set geometryType(e){this._setSetting("geometryType",e)}get hasGeometry(){return void 0!==this.geometryType&&null!==this.geometryType}get timeZone(){return this._getSetting("timeZone","UTC")}set timeZone(e){T("timeZone",e).satisfies((e=>H(e)),j(e)),this._setSetting("timeZone",e)}get typeIdField(){return this._getSetting("typeIdField")}set typeIdField(e){this._setSetting("typeIdField",e)}get types(){return this._getCollectionSetting("types")}get _fields(){return this._getCollectionSetting("_fields")}_featureSettings;_alwaysSerializeFieldExtensions;constructor(e){super(e),this.fieldExtensions=new K(this),this.fields=new J(this)}static createFieldInfoFromField(e){let i=!0;const t=e.name.toLowerCase();return("oid"===e.type||"geometry"===e.type||B.has(t)&&B.get(t)===e.type)&&(i=!1),new d({visible:i,fieldName:e.name,format:void 0,label:e.alias,stringFieldOption:void 0,tooltip:void 0,isEditable:e.editable})}destroy(){this.parent=void 0,this.fieldExtensions?.destroy(),this.fields?.destroy(),super.destroy()}findFieldByName(e){return this.fields.findFieldByName(e)}toJSON(e="all"){const i=m(this._getSerializableProperties(),this,e)||{};let t=i.fieldExtensions;this.parent&&(t=t?.filter((e=>{const i=this.parent;return!i?.fieldExtensions?.some((i=>i.id===e.id))})));const{fields:s}=i;if(i)for(const e of C(i))this.isModified(e)||delete i[e];if(s&&(i.fields=s),t?.length&&(i.fieldExtensions=t),!c(e)||!f(i))return i}createPopupTemplate(){const e=this.createAllFieldInfos();return new t({fieldInfos:e,content:[{type:"fields"},{type:"attachments"}]})}createAllFieldInfos(){return this.fields.toArray().filter((e=>!!e.name)).map((i=>e.createFieldInfoFromField(i)))}_getSerializableProperties(){return{geometryType:{serialize:!1,deserialize:e=>{this.geometryType=e?a(e):void 0}},spatialReference:{serialize:!1},primaryKeyField:{serialize:!1},displayField:{serialize:!1},typeIdField:{serialize:!1},fields:{serializeModes:["initial","project"],serialize:()=>this.isModified("_fields")?this.fields.toArray().map((e=>e.toJSON())):void 0,deserialize:e=>{if(!e)return;const i=e.map((e=>I(e)?e:l.fromJSON(e)));z(this.fields,i,{onNew:(e,i)=>{this.fields.add(e,i)},onMatch:(e,i,t,s)=>{e!==i&&(e.alias=i.alias,e.editable=i.editable,e.length=i.length,e.nullable=i.nullable,e.type=i.type),t!==s&&this.fields.reorder(e,s)},onMissing:e=>{this.fields.remove(e)},equals:(e,i)=>R(e.name,i.name)})}},fieldExtensions:{serializeModes:["initial"],serialize:e=>this.fieldExtensions.toArray().map((i=>i.toJSON(e))).filter((e=>this._alwaysSerializeFieldExtensions||!(e&&2===Object.keys(e).length&&e.id&&e.field))),deserialize:e=>{e&&z(this.fieldExtensions,e,{onNew:(e,i)=>{this.fieldExtensions.add(r(e)?e:new O(e),i)},onMatch:(e,i,t,s)=>{r(i)||e.assignProperties(i),t!==s&&this.fieldExtensions.reorder(e,s)},onMissing:e=>{this._alwaysSerializeFieldExtensions&&this.fieldExtensions.remove(e)},equals:(e,i)=>r(i)?i===e:!(!i?.field||!O.matchesRef(e,i.field))||e.id===i.id})}},types:{serialize:!1,deserialize:e=>{if(!e)return;const i=e.map((e=>w(e)||!e?e:o.fromJSON(e)));z(this.types,i,{onNew:(e,i)=>{this.types.add(e,i)},onMatch:(e,i,t,s)=>{e!==i&&(e.name=i.name,e.templates=i.templates?[...i.templates]:[],e.domains=i.domains),t!==s&&this.types.reorder(e,s)},onMissing:e=>{this.types.remove(e)},equals:(e,i)=>e.id===i.id})}},timeZone:{serialize:!1,deserialize:e=>{e&&(this.timeZone=e)}}}}};Z=e=i([p],Z);export{Z as Schema};class J extends v{_schema;_fieldNameToField=new x;_expressionFields=new s;_expressionFieldsReadOnly=new b(this._expressionFields);get _expressionFieldsLength(){return this.expressionFields.length}get expressionFields(){return this._expressionFieldsReadOnly}get _popupTemplate(){return this._schema._featureSettings?this._schema._featureSettings.popupTemplate:void 0}constructor(e){super(new s),this._schema=e,this._handles.add(F(this,"length",(()=>y(this._schema,"_fields.length",(()=>g(this,"length")),{sync:!0})))),this._handles.add(y(this._schema,"_fields",(e=>{if(this._handles.remove("schema-field-collection-schema-fields"),null!=e){this._handles.add([e.on("after-add",(i=>{this._collection.add(i.item,e.indexOf(i.item)),this._fieldNameToField.set(i.item.name,i.item)})),e.on("after-remove",(e=>{this._collection.remove(e.item),this._fieldNameToField.delete(e.item.name)}))],"schema-field-collection-schema-fields");for(const i of this._collection)e.includes(i)||(this._collection.remove(i),this._fieldNameToField.delete(i.name));for(const i of e)this._collection.includes(i)||(this._collection.add(i),this._fieldNameToField.set(i.name,i))}else for(const e of this._collection.filter((e=>!this._expressionFields.includes(e))))this._collection.remove(e),this._fieldNameToField.delete(e.name)}),{sync:!0,initial:!0})),this._generateExpressionFields(),this._handles.add([y(this._schema,"_featureSettings.popupTemplate.fieldInfos",(()=>{this._generateExpressionFields()}),{sync:!0}),y(this._schema,"_featureSettings.popupTemplate.expressionInfos",(()=>{this._generateExpressionFields()}),{sync:!0})])}clone(){return new J(this._schema)}add(e,i){T("field",e).isNotMissing();const t=A(e.name);if(t){if(!this._popupTemplate)throw new n("Cannot create a field that references an arcade expression without a feature source and popup template.");const i=this._popupTemplate.expressionInfos.find((e=>R(e.name,t)));if(!i)throw new n("Cannot create a field that references a non-existent arcade expression.");this._popupTemplate.fieldInfos||(this._popupTemplate.fieldInfos=[]);let s=this._popupTemplate.fieldInfos.find((i=>R(i.fieldName,e.name)));s||(s=new d({fieldName:e.name,label:i.title}),this._popupTemplate.fieldInfos.push(s));const o=P.get(s);P.set(s,e),null!=this._expressionFields&&(this._expressionFields.remove(o),this._expressionFields.includes(e)||(this._expressionFields.add(e),this._collection.add(e),this._fieldNameToField.set(e.name,e))),g(this,"_expressionFieldsLength")}else this._schema._fields.add(e,i);return this}destroy(){this._fieldNameToField.clear(),this._expressionFields.removeAll(),this._collection.removeAll(),super.destroy()}removeAt(e){T("index",e).isNotMissing();const i=this.getItemAt(e);if(!i)return;if(A(i.name)){const e=this._popupTemplate.fieldInfos.findIndex((e=>R(e.fieldName,i.name)));this._popupTemplate.fieldInfos.splice(e,1),this._expressionFields.remove(i),this._collection.remove(i),this._fieldNameToField.delete(i.name),g(this,"_expressionFieldsLength")}else this._schema._fields.remove(i);return i}reorder(e,i){if(e&&this._schema._fields.includes(e))return this._schema._fields.reorder(e,i),this._collection.reorder(e,i),e}sort(e){return this._schema._fields.sort(e),this._collection.sort(((i,t)=>this._expressionFields.includes(i)&&this._expressionFields.includes(t)?0:this._expressionFields.includes(i)?1:this._expressionFields.includes(t)?-1:e(i,t))),this}findFieldByName(e){return this._fieldNameToField.get(e)}_generateExpressionFields(){if(!this._popupTemplate?.fieldInfos||!this._popupTemplate?.expressionInfos){for(const e of this._expressionFields)this._collection.remove(e),this._fieldNameToField.delete(e.name);return void this._expressionFields.removeAll()}const e=this._expressionFields.slice();for(const i of this._popupTemplate.fieldInfos){const t=A(i.fieldName);if(null==t)continue;const s=this._popupTemplate.expressionInfos.find((e=>R(e.name,t)));if(null==s)continue;let o=P.get(i);null==o&&(o=new l({name:i.fieldName,alias:i.label||s.title||i.fieldName,type:"number"===s.returnType?"double":"string",editable:!1})),this._expressionFields.includes(o)?e.remove(o):(P.set(i,o),this._expressionFields.add(o),this._collection.add(o),this._fieldNameToField.set(o.name,o),e.remove(o))}for(const i of e)this._expressionFields.remove(i),this._collection.remove(i),this._fieldNameToField.delete(i.name)}}class K extends h{get _collection(){return this._schema.fields.map((e=>this._forField(e))).concat(Array.from(this._uninitializedFieldExtensions))}_schema;_uninitializedFieldExtensions=new Set;_onChangeSchemaFieldsHandle=new S((()=>this._schema.fields.on("change",(e=>{const i={added:(e.added||[]).map((e=>this._forField(e))),moved:(e.moved||[]).map((e=>this._forField(e))),removed:(e.removed||[]).map((e=>this._forField(e))),target:this};this.emit("change",i)}))));_onBeforeAddSchemaFieldsHandle=new S((()=>this._schema.fields.on("before-add",(e=>{this.emit("before-add",{...e,item:this._forField(e.item)})}))));_onBeforeRemoveSchemaFieldsHandle=new S((()=>this._schema.fields.on("before-remove",(e=>{this.emit("before-remove",{...e,item:this._forField(e.item)})}))));_onBeforeChangesSchemaFieldsHandle=new S((()=>this._schema.fields.on("before-changes",(e=>{this.emit("before-changes",{...e,item:this._forField(e.item)})}))));_onAfterAddSchemaFieldsHandle=new S((()=>this._schema.fields.on("after-add",(e=>{this.emit("after-add",{...e,item:this._forField(e.item)})}))));_onAfterRemoveSchemaFieldsHandle=new S((()=>this._schema.fields.on("after-remove",(e=>{this.emit("after-remove",{...e,item:this._forField(e.item)})}))));_onAfterChangesSchemaFieldsHandle=new S((()=>this._schema.fields.on("after-changes",(e=>{this.emit("after-changes",{...e,target:this})}))));constructor(e){super(),this._schema=e,this._handles.add(F(this,"length",(()=>y(this._schema.fields,"length",(()=>g(this,"length")),{sync:!0}))))}async destroy(){this._onChangeSchemaFieldsHandle.destroy(),this._onBeforeAddSchemaFieldsHandle.destroy(),this._onBeforeRemoveSchemaFieldsHandle.destroy(),this._onBeforeChangesSchemaFieldsHandle.destroy(),this._onAfterAddSchemaFieldsHandle.destroy(),this._onAfterRemoveSchemaFieldsHandle.destroy(),this._onAfterChangesSchemaFieldsHandle.destroy();const e=[];for(const i of this._schema.fields){const t=M.get(i);t&&t.schema===this._schema&&(M.delete(i),this._onRemoved(t),e.push(t.destroy()))}this._uninitializedFieldExtensions.forEach((i=>{this._onRemoved(i),e.push(i.destroy())})),this._uninitializedFieldExtensions.clear(),await Promise.all(e),super.destroy()}forField(e){if(T("field",e).isNotMissing(),this._schema.fields.includes(e))return this._forField(e)}add(e,i){if(T("fieldX",e).isNotMissing(),e.schema&&e.schema.fieldExtensions.remove(e),e._setSchema(this._schema),e.field){const t=M.get(e.field);if(M.set(e.field,e),t&&t!==e&&this._onRemoved(t),this._schema.fields.includes(e.field))if(void 0===i){const i={added:[e],moved:[],removed:t?[t]:[],target:this};this.emit("change",i),this.emit("after-add",{item:e}),this.emit("after-changes",{})}else this._schema.fields.reorder(e.field,i);else this._schema.fields.add(e.field,i)}else{this._uninitializedFieldExtensions.add(e);const i={added:[e],moved:[],removed:[],target:this};this.emit("change",i),this.emit("after-add",{item:e}),this.emit("after-changes",{})}return this._onAdded(e),this}removeAt(e){const i=this.getItemAt(e);if(void 0!==i){if(this._uninitializedFieldExtensions.has(i)){this._uninitializedFieldExtensions.delete(i);const e={added:[],moved:[],removed:[i],target:this};this.emit("change",e),this.emit("after-remove",{item:i}),this.emit("after-changes",{})}else this._schema.fields.remove(i.field);return this._onRemoved(i),i}}reorder(e,i){if(e&&this._schema.fields.includes(e.field))return this._schema.fields.reorder(e.field,i),e}sort(e){return this._schema.fields.sort(((i,t)=>e(this._forField(i),this._forField(t)))),this}on(e,i){const t=[];return"change"===e?t.push(this._onChangeSchemaFieldsHandle.add()):"before-add"===e?t.push(this._onBeforeAddSchemaFieldsHandle.add()):"before-remove"===e?t.push(this._onBeforeRemoveSchemaFieldsHandle.add()):"before-changes"===e?t.push(this._onBeforeChangesSchemaFieldsHandle.add()):"after-add"===e?t.push(this._onAfterAddSchemaFieldsHandle.add()):"after-remove"===e?t.push(this._onAfterRemoveSchemaFieldsHandle.add()):"after-changes"===e&&t.push(this._onAfterChangesSchemaFieldsHandle.add()),t.push(super.on(e,i)),u(t)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.field}_onAdded(e){}_onRemoved(e){e.schema===this._schema&&e._setSchema(void 0)}_forField(e){if(this._uninitializedFieldExtensions.size)for(const e of this._uninitializedFieldExtensions)e._resolveField(),e.field&&(M.set(e.field,e),this._uninitializedFieldExtensions.delete(e));if(!M.has(e)){const i=new O({field:e});M.set(e,i),i._setSchema(this._schema),this._onAdded(i),i.initialize()}return M.get(e)}}
1
+ var e;import{__decorate as i}from"tslib";import t from"@arcgis/core/PopupTemplate";import s from"@arcgis/core/core/Collection";import o from"@arcgis/core/layers/support/FeatureType";import l from"@arcgis/core/layers/support/Field";import d from"@arcgis/core/popup/FieldInfo";import{InvalidOperationError as n}from"../InvalidOperationError.js";import{isFieldExtension as r}from"../ItemType.js";import{jsonToGeometryType as a}from"../json/GeometryJson.js";import{InitializableCollectionProxy as h}from"../support/InitializableCollectionProxy.js";import{filterJSONProperties as m,isDefault as f,serializable as p,shouldExcludeDefaults as c}from"../support/Serializable.js";import{Settings as _}from"../support/Settings.js";import{createIHandle as u,notifyChange as g,onWatch as F,watch as y}from"../support/observableUtils.js";import{CaseInsensitiveObservableMap as x}from"../utilities/CaseInsensitiveObservableMap.js";import{CollectionProxy as v}from"../utilities/CollectionProxy.js";import{ReadOnlyCollection as b}from"../utilities/ReadOnlyCollection.js";import S from"../utilities/_ReferenceCountedHandle.js";import{checkArg as T}from"../utilities/checkArg.js";import{compare as w}from"../utilities/collection.js";import{isFeatureType as z,isField as I}from"../utilities/esri.js";import{fieldWithArcadeXRegex as N,fieldWithRelationshipRegex as E,getArcadeExpressionFromField as A}from"../utilities/field.js";import{ERR_TIME_ZONE_INVALID as j,isValidTimeZone as H}from"../utilities/format/date.js";import{objectKeys as C}from"../utilities/object.js";import{caseInsensitiveEquals as R}from"../utilities/string.js";import{_fieldExtensionMap as M,FieldExtension as K}from"./FieldExtension.js";const O=new Map;O.set("objectid","oid"),O.set("oid","oid"),O.set("fid","oid"),O.set("shape","geometry"),O.set("shape__length","double"),O.set("shape_length","double"),O.set("shape__area","double"),O.set("shape_area","double"),O.set("area","double"),O.set("perimeter","double"),O.set("length","double"),O.set("fnode_","double"),O.set("tnode_","double"),O.set("lpoly_","double"),O.set("rpoly_","double"),O.set("cover_","integer"),O.set("cover_id","integer"),O.set("idtic","integer"),O.set("xtic","double"),O.set("ytic","double"),O.set("xmin","double"),O.set("ymin","double"),O.set("xmax","double"),O.set("ymax","double"),O.set("arc_","double"),O.set("subclass_","integer"),O.set("subclass_id","integer"),O.set("routelink","integer"),O.set("arclink","integer"),O.set("f_meas","double"),O.set("t_meas","double"),O.set("f_pos","double"),O.set("t_pos","double"),O.set("f_meas","double"),O.set("globalid","global-id"),O.set("guid","guid");export{N as fieldWithArcadeXRegex,E as fieldWithRelationshipRegex};const B=new WeakMap;let P=e=class extends _{fieldExtensions;fields;_featureSettings;_alwaysSerializeFieldExtensions;_watchHandles=[];_primaryKeyField;get spatialReference(){return this._getSetting("spatialReference")}set spatialReference(e){this._setSetting("spatialReference",e)}get primaryKeyField(){if(!this._primaryKeyField){const e=this._getSetting("primaryKeyField");if(e)this._primaryKeyField=e;else{const e=this.fields.filter((e=>"oid"===e.type));1===e.length&&(this._primaryKeyField=e.getItemAt(0).name)}}return this._primaryKeyField}set primaryKeyField(e){this._primaryKeyField=e,this._setSetting("primaryKeyField",e)}get displayField(){return this._getSetting("displayField",this.primaryKeyField)}set displayField(e){!this._featureSettings?.popupTemplate||this._featureSettings.popupTemplate.title&&this._featureSettings.popupTemplate.title!==`{${this.displayField}}`||(this._featureSettings.popupTemplate.title=`{${e}}`),this._setSetting("displayField",e)}get geometryType(){return this._getSetting("geometryType")}set geometryType(e){this._setSetting("geometryType",e)}get hasGeometry(){return void 0!==this.geometryType&&null!==this.geometryType}get timeZone(){return this._getSetting("timeZone","UTC")}set timeZone(e){T("timeZone",e).satisfies((e=>H(e)),j(e)),this._setSetting("timeZone",e)}get typeIdField(){return this._getSetting("typeIdField")}set typeIdField(e){this._setSetting("typeIdField",e)}get types(){return this._getCollectionSetting("types")}get _fields(){return this._getCollectionSetting("_fields")}constructor(e){super(e),this.fieldExtensions=new J(this),this.fields=new Z(this),this._primaryKeyField=void 0,this._handles.add(this.fields.on("before-changes",(()=>{this._primaryKeyField=void 0})))}static createFieldInfoFromField(e){let i=!0;const t=e.name.toLowerCase();return("oid"===e.type||"geometry"===e.type||O.has(t)&&O.get(t)===e.type)&&(i=!1),new d({visible:i,fieldName:e.name,format:void 0,label:e.alias,stringFieldOption:void 0,tooltip:void 0,isEditable:e.editable})}destroy(){this.parent=void 0,this.fieldExtensions?.destroy(),this.fields?.destroy(),super.destroy()}findFieldByName(e){return this.fields.findFieldByName(e)}toJSON(e="all"){const i=m(this._getSerializableProperties(),this,e)||{};let t=i.fieldExtensions;this.parent&&(t=t?.filter((e=>{const i=this.parent;return!i?.fieldExtensions?.some((i=>i.id===e.id))})));const{fields:s}=i;if(i)for(const e of C(i))this.isModified(e)||delete i[e];if(s&&(i.fields=s),t?.length&&(i.fieldExtensions=t),!c(e)||!f(i))return i}createPopupTemplate(){const e=this.createAllFieldInfos();return new t({fieldInfos:e,content:[{type:"fields"},{type:"attachments"}]})}createAllFieldInfos(){return this.fields.toArray().filter((e=>!!e.name)).map((i=>e.createFieldInfoFromField(i)))}_getSerializableProperties(){return{geometryType:{serialize:!1,deserialize:e=>{this.geometryType=e?a(e):void 0}},spatialReference:{serialize:!1},primaryKeyField:{serialize:!1},displayField:{serialize:!1},typeIdField:{serialize:!1},fields:{serializeModes:["initial","project"],serialize:()=>this.isModified("_fields")?this.fields.toArray().map((e=>e.toJSON())):void 0,deserialize:e=>{if(!e)return;const i=e.map((e=>I(e)?e:l.fromJSON(e)));w(this.fields,i,{onNew:(e,i)=>{this.fields.add(e,i)},onMatch:(e,i,t,s)=>{e!==i&&(e.alias=i.alias,e.editable=i.editable,e.length=i.length,e.nullable=i.nullable,e.type=i.type),t!==s&&this.fields.reorder(e,s)},onMissing:e=>{this.fields.remove(e)},equals:(e,i)=>R(e.name,i.name)})}},fieldExtensions:{serializeModes:["initial"],serialize:e=>this.fieldExtensions.toArray().map((i=>i.toJSON(e))).filter((e=>this._alwaysSerializeFieldExtensions||!(e&&2===Object.keys(e).length&&e.id&&e.field))),deserialize:e=>{e&&w(this.fieldExtensions,e,{onNew:(e,i)=>{this.fieldExtensions.add(r(e)?e:new K(e),i)},onMatch:(e,i,t,s)=>{r(i)||e.assignProperties(i),t!==s&&this.fieldExtensions.reorder(e,s)},onMissing:e=>{this._alwaysSerializeFieldExtensions&&this.fieldExtensions.remove(e)},equals:(e,i)=>r(i)?i===e:!(!i?.field||!K.matchesRef(e,i.field))||e.id===i.id})}},types:{serialize:!1,deserialize:e=>{if(!e)return;const i=e.map((e=>z(e)||!e?e:o.fromJSON(e)));w(this.types,i,{onNew:(e,i)=>{this.types.add(e,i)},onMatch:(e,i,t,s)=>{e!==i&&(e.name=i.name,e.templates=i.templates?[...i.templates]:[],e.domains=i.domains),t!==s&&this.types.reorder(e,s)},onMissing:e=>{this.types.remove(e)},equals:(e,i)=>e.id===i.id})}},timeZone:{serialize:!1,deserialize:e=>{e&&(this.timeZone=e)}}}}};P=e=i([p],P);export{P as Schema};class Z extends v{_schema;_fieldNameToField=new x;_expressionFields=new s;_expressionFieldsReadOnly=new b(this._expressionFields);get _expressionFieldsLength(){return this.expressionFields.length}get expressionFields(){return this._expressionFieldsReadOnly}get _popupTemplate(){return this._schema._featureSettings?this._schema._featureSettings.popupTemplate:void 0}constructor(e){super(new s),this._schema=e,this._handles.add(F(this,"length",(()=>y(this._schema,"_fields.length",(()=>g(this,"length")),{sync:!0})))),this._handles.add(y(this._schema,"_fields",(e=>{if(this._handles.remove("schema-field-collection-schema-fields"),null!=e){this._handles.add([e.on("after-add",(i=>{this._collection.add(i.item,e.indexOf(i.item)),this._fieldNameToField.set(i.item.name,i.item)})),e.on("after-remove",(e=>{this._collection.remove(e.item),this._fieldNameToField.delete(e.item.name)}))],"schema-field-collection-schema-fields");for(const i of this._collection)e.includes(i)||(this._collection.remove(i),this._fieldNameToField.delete(i.name));for(const i of e)this._collection.includes(i)||(this._collection.add(i),this._fieldNameToField.set(i.name,i))}else for(const e of this._collection.filter((e=>!this._expressionFields.includes(e))))this._collection.remove(e),this._fieldNameToField.delete(e.name)}),{sync:!0,initial:!0})),this._generateExpressionFields(),this._handles.add([y(this._schema,"_featureSettings.popupTemplate.fieldInfos",(()=>{this._generateExpressionFields()}),{sync:!0}),y(this._schema,"_featureSettings.popupTemplate.expressionInfos",(()=>{this._generateExpressionFields()}),{sync:!0})])}clone(){return new Z(this._schema)}add(e,i){T("field",e).isNotMissing();const t=A(e.name);if(t){if(!this._popupTemplate)throw new n("Cannot create a field that references an arcade expression without a feature source and popup template.");const i=this._popupTemplate.expressionInfos.find((e=>R(e.name,t)));if(!i)throw new n("Cannot create a field that references a non-existent arcade expression.");this._popupTemplate.fieldInfos||(this._popupTemplate.fieldInfos=[]);let s=this._popupTemplate.fieldInfos.find((i=>R(i.fieldName,e.name)));s||(s=new d({fieldName:e.name,label:i.title}),this._popupTemplate.fieldInfos.push(s));const o=B.get(s);B.set(s,e),null!=this._expressionFields&&(this._expressionFields.remove(o),this._expressionFields.includes(e)||(this._expressionFields.add(e),this._collection.add(e),this._fieldNameToField.set(e.name,e))),g(this,"_expressionFieldsLength")}else this._schema._fields.add(e,i);return this}destroy(){this._fieldNameToField.clear(),this._expressionFields.removeAll(),this._collection.removeAll(),super.destroy()}removeAt(e){T("index",e).isNotMissing();const i=this.getItemAt(e);if(!i)return;if(A(i.name)){const e=this._popupTemplate.fieldInfos.findIndex((e=>R(e.fieldName,i.name)));this._popupTemplate.fieldInfos.splice(e,1),this._expressionFields.remove(i),this._collection.remove(i),this._fieldNameToField.delete(i.name),g(this,"_expressionFieldsLength")}else this._schema._fields.remove(i);return i}reorder(e,i){if(e&&this._schema._fields.includes(e))return this._schema._fields.reorder(e,i),this._collection.reorder(e,i),e}sort(e){return this._schema._fields.sort(e),this._collection.sort(((i,t)=>this._expressionFields.includes(i)&&this._expressionFields.includes(t)?0:this._expressionFields.includes(i)?1:this._expressionFields.includes(t)?-1:e(i,t))),this}findFieldByName(e){return this._fieldNameToField.get(e)}_generateExpressionFields(){if(!this._popupTemplate?.fieldInfos||!this._popupTemplate?.expressionInfos){for(const e of this._expressionFields)this._collection.remove(e),this._fieldNameToField.delete(e.name);return void this._expressionFields.removeAll()}const e=this._expressionFields.slice();for(const i of this._popupTemplate.fieldInfos){const t=A(i.fieldName);if(null==t)continue;const s=this._popupTemplate.expressionInfos.find((e=>R(e.name,t)));if(null==s)continue;let o=B.get(i);null==o&&(o=new l({name:i.fieldName,alias:i.label||s.title||i.fieldName,type:"number"===s.returnType?"double":"string",editable:!1})),this._expressionFields.includes(o)?e.remove(o):(B.set(i,o),this._expressionFields.add(o),this._collection.add(o),this._fieldNameToField.set(o.name,o),e.remove(o))}for(const i of e)this._expressionFields.remove(i),this._collection.remove(i),this._fieldNameToField.delete(i.name)}}class J extends h{get _collection(){return this._schema.fields.map((e=>this._forField(e))).concat(Array.from(this._uninitializedFieldExtensions))}_schema;_uninitializedFieldExtensions=new Set;_onChangeSchemaFieldsHandle=new S((()=>this._schema.fields.on("change",(e=>{const i={added:(e.added||[]).map((e=>this._forField(e))),moved:(e.moved||[]).map((e=>this._forField(e))),removed:(e.removed||[]).map((e=>this._forField(e))),target:this};this.emit("change",i)}))));_onBeforeAddSchemaFieldsHandle=new S((()=>this._schema.fields.on("before-add",(e=>{this.emit("before-add",{...e,item:this._forField(e.item)})}))));_onBeforeRemoveSchemaFieldsHandle=new S((()=>this._schema.fields.on("before-remove",(e=>{this.emit("before-remove",{...e,item:this._forField(e.item)})}))));_onBeforeChangesSchemaFieldsHandle=new S((()=>this._schema.fields.on("before-changes",(e=>{this.emit("before-changes",{...e,item:this._forField(e.item)})}))));_onAfterAddSchemaFieldsHandle=new S((()=>this._schema.fields.on("after-add",(e=>{this.emit("after-add",{...e,item:this._forField(e.item)})}))));_onAfterRemoveSchemaFieldsHandle=new S((()=>this._schema.fields.on("after-remove",(e=>{this.emit("after-remove",{...e,item:this._forField(e.item)})}))));_onAfterChangesSchemaFieldsHandle=new S((()=>this._schema.fields.on("after-changes",(e=>{this.emit("after-changes",{...e,target:this})}))));constructor(e){super(),this._schema=e,this._handles.add(F(this,"length",(()=>y(this._schema.fields,"length",(()=>g(this,"length")),{sync:!0}))))}async destroy(){this._onChangeSchemaFieldsHandle.destroy(),this._onBeforeAddSchemaFieldsHandle.destroy(),this._onBeforeRemoveSchemaFieldsHandle.destroy(),this._onBeforeChangesSchemaFieldsHandle.destroy(),this._onAfterAddSchemaFieldsHandle.destroy(),this._onAfterRemoveSchemaFieldsHandle.destroy(),this._onAfterChangesSchemaFieldsHandle.destroy();const e=[];for(const i of this._schema.fields){const t=M.get(i);t&&t.schema===this._schema&&(M.delete(i),this._onRemoved(t),e.push(t.destroy()))}this._uninitializedFieldExtensions.forEach((i=>{this._onRemoved(i),e.push(i.destroy())})),this._uninitializedFieldExtensions.clear(),await Promise.all(e),super.destroy()}forField(e){if(T("field",e).isNotMissing(),this._schema.fields.includes(e))return this._forField(e)}add(e,i){if(T("fieldX",e).isNotMissing(),e.schema&&e.schema.fieldExtensions.remove(e),e._setSchema(this._schema),e.field){const t=M.get(e.field);if(M.set(e.field,e),t&&t!==e&&this._onRemoved(t),this._schema.fields.includes(e.field))if(void 0===i){const i={added:[e],moved:[],removed:t?[t]:[],target:this};this.emit("change",i),this.emit("after-add",{item:e}),this.emit("after-changes",{})}else this._schema.fields.reorder(e.field,i);else this._schema.fields.add(e.field,i)}else{this._uninitializedFieldExtensions.add(e);const i={added:[e],moved:[],removed:[],target:this};this.emit("change",i),this.emit("after-add",{item:e}),this.emit("after-changes",{})}return this._onAdded(e),this}removeAt(e){const i=this.getItemAt(e);if(void 0!==i){if(this._uninitializedFieldExtensions.has(i)){this._uninitializedFieldExtensions.delete(i);const e={added:[],moved:[],removed:[i],target:this};this.emit("change",e),this.emit("after-remove",{item:i}),this.emit("after-changes",{})}else this._schema.fields.remove(i.field);return this._onRemoved(i),i}}reorder(e,i){if(e&&this._schema.fields.includes(e.field))return this._schema.fields.reorder(e.field,i),e}sort(e){return this._schema.fields.sort(((i,t)=>e(this._forField(i),this._forField(t)))),this}on(e,i){const t=[];return"change"===e?t.push(this._onChangeSchemaFieldsHandle.add()):"before-add"===e?t.push(this._onBeforeAddSchemaFieldsHandle.add()):"before-remove"===e?t.push(this._onBeforeRemoveSchemaFieldsHandle.add()):"before-changes"===e?t.push(this._onBeforeChangesSchemaFieldsHandle.add()):"after-add"===e?t.push(this._onAfterAddSchemaFieldsHandle.add()):"after-remove"===e?t.push(this._onAfterRemoveSchemaFieldsHandle.add()):"after-changes"===e&&t.push(this._onAfterChangesSchemaFieldsHandle.add()),t.push(super.on(e,i)),u(t)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.field}_onAdded(e){}_onRemoved(e){e.schema===this._schema&&e._setSchema(void 0)}_forField(e){if(this._uninitializedFieldExtensions.size)for(const e of this._uninitializedFieldExtensions)e._resolveField(),e.field&&(M.set(e.field,e),this._uninitializedFieldExtensions.delete(e));if(!M.has(e)){const i=new K({field:e});M.set(e,i),i._setSchema(this._schema),this._onAdded(i),i.initialize()}return M.get(e)}}