@aemforms/af-core 0.22.132 → 0.22.134

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.
@@ -1314,15 +1314,20 @@ class BaseNode {
1314
1314
  _tokens = [];
1315
1315
  _eventSource = EventSource.CODE;
1316
1316
  _fragment = '$form';
1317
+ _idSet;
1318
+ createIdSet() {
1319
+ return new Set();
1320
+ }
1317
1321
  get isContainer() {
1318
1322
  return false;
1319
1323
  }
1320
1324
  constructor(params, _options) {
1321
1325
  this._options = _options;
1326
+ this._idSet = this.createIdSet();
1322
1327
  this[qualifiedName] = null;
1323
1328
  this._jsonModel = {
1324
1329
  ...params,
1325
- id: 'id' in params ? params.id : this.form.getUniqueId()
1330
+ id: this.form.getUniqueId(params?.id)
1326
1331
  };
1327
1332
  if (this.parent?.isFragment) {
1328
1333
  this._fragment = this.parent.qualifiedName;
@@ -2740,6 +2745,7 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2740
2745
  };
2741
2746
  const targetField = context.$field || null;
2742
2747
  const targetEvent = context.$event || null;
2748
+ response.submitter = targetField;
2743
2749
  const enhancedPayload = {
2744
2750
  request: response.originalRequest,
2745
2751
  response,
@@ -2752,7 +2758,12 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2752
2758
  context.form.dispatch(new SubmitSuccess(response, true));
2753
2759
  }
2754
2760
  else {
2755
- context.form.dispatch(new CustomEvent(eName, response, true));
2761
+ if (context.field) {
2762
+ context.field.dispatch(new CustomEvent(eName, response, true));
2763
+ }
2764
+ else {
2765
+ context.form.dispatch(new CustomEvent(eName, response, true));
2766
+ }
2756
2767
  }
2757
2768
  context.form.dispatch(new RequestSuccess(enhancedPayload, false));
2758
2769
  }
@@ -2764,7 +2775,12 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2764
2775
  context.form.dispatch(new SubmitFailure(response, true));
2765
2776
  }
2766
2777
  else {
2767
- context.form.dispatch(new CustomEvent(eName, response, true));
2778
+ if (context.field) {
2779
+ context.field.dispatch(new CustomEvent(eName, response, true));
2780
+ }
2781
+ else {
2782
+ context.form.dispatch(new CustomEvent(eName, response, true));
2783
+ }
2768
2784
  }
2769
2785
  context.form.dispatch(new RequestFailure(enhancedPayload, false));
2770
2786
  }
@@ -3575,6 +3591,9 @@ class Form extends Container {
3575
3591
  }
3576
3592
  }
3577
3593
  resolveQualifiedName(qualifiedName) {
3594
+ if (this.qualifiedName === qualifiedName) {
3595
+ return this;
3596
+ }
3578
3597
  let foundFormElement = null;
3579
3598
  this.visit(formElement => {
3580
3599
  if (formElement.qualifiedName === qualifiedName) {
@@ -3714,11 +3733,20 @@ class Form extends Container {
3714
3733
  get ruleEngine() {
3715
3734
  return this._ruleEngine;
3716
3735
  }
3717
- getUniqueId() {
3736
+ getUniqueId(id) {
3737
+ if (id && !this._idSet?.has(id)) {
3738
+ this._idSet?.add(id);
3739
+ return id;
3740
+ }
3718
3741
  if (this._ids == null) {
3719
3742
  return '';
3720
3743
  }
3721
- return this._ids.next().value;
3744
+ const newId = this._ids.next().value;
3745
+ this._idSet?.add(newId);
3746
+ return newId;
3747
+ }
3748
+ clearIdRegistry() {
3749
+ this._idSet?.clear();
3722
3750
  }
3723
3751
  fieldAdded(field) {
3724
3752
  if (field.fieldType === 'captcha' && !this._captcha) {
@@ -21,6 +21,8 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
21
21
  private _tokens;
22
22
  _eventSource: EventSource;
23
23
  protected _fragment: string;
24
+ protected _idSet: Set<string> | undefined;
25
+ protected createIdSet(): Set<string> | undefined;
24
26
  get isContainer(): boolean;
25
27
  constructor(params: T, _options: {
26
28
  form: FormModel;
@@ -123,7 +123,8 @@ declare class Form extends Container<FormJson> implements FormModel {
123
123
  isTransparent(): boolean;
124
124
  get form(): FormModel;
125
125
  get ruleEngine(): RuleEngine;
126
- getUniqueId(): string;
126
+ getUniqueId(id?: string): string;
127
+ clearIdRegistry(): void;
127
128
  fieldAdded(field: FieldModel | FieldsetModel): void;
128
129
  visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
129
130
  traverseChild(container: Container<any>, callBack: (field: FieldModel | FieldsetModel) => void): void;
@@ -126,7 +126,7 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
126
126
  readonly specVersion: Version;
127
127
  exportData(): any;
128
128
  getElement(id: string): FieldModel | FormModel | FieldsetModel;
129
- getUniqueId(): string;
129
+ getUniqueId(id?: string): string;
130
130
  getEventQueue(): EventQueue;
131
131
  visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
132
132
  resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
package/lib/BaseNode.d.ts CHANGED
@@ -21,6 +21,8 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
21
21
  private _tokens;
22
22
  _eventSource: EventSource;
23
23
  protected _fragment: string;
24
+ protected _idSet: Set<string> | undefined;
25
+ protected createIdSet(): Set<string> | undefined;
24
26
  get isContainer(): boolean;
25
27
  constructor(params: T, _options: {
26
28
  form: FormModel;
package/lib/BaseNode.js CHANGED
@@ -124,8 +124,9 @@ class BaseNode {
124
124
  this._tokens = [];
125
125
  this._eventSource = index_1.EventSource.CODE;
126
126
  this._fragment = '$form';
127
+ this._idSet = this.createIdSet();
127
128
  this[exports.qualifiedName] = null;
128
- this._jsonModel = Object.assign(Object.assign({}, params), { id: 'id' in params ? params.id : this.form.getUniqueId() });
129
+ this._jsonModel = Object.assign(Object.assign({}, params), { id: this.form.getUniqueId(params === null || params === void 0 ? void 0 : params.id) });
129
130
  if ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isFragment) {
130
131
  this._fragment = this.parent.qualifiedName;
131
132
  }
@@ -133,6 +134,9 @@ class BaseNode {
133
134
  this._fragment = this.parent.fragment;
134
135
  }
135
136
  }
137
+ createIdSet() {
138
+ return new Set();
139
+ }
136
140
  get isContainer() {
137
141
  return false;
138
142
  }
package/lib/Form.d.ts CHANGED
@@ -123,7 +123,8 @@ declare class Form extends Container<FormJson> implements FormModel {
123
123
  isTransparent(): boolean;
124
124
  get form(): FormModel;
125
125
  get ruleEngine(): RuleEngine;
126
- getUniqueId(): string;
126
+ getUniqueId(id?: string): string;
127
+ clearIdRegistry(): void;
127
128
  fieldAdded(field: FieldModel | FieldsetModel): void;
128
129
  visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
129
130
  traverseChild(container: Container<any>, callBack: (field: FieldModel | FieldsetModel) => void): void;
package/lib/Form.js CHANGED
@@ -141,6 +141,9 @@ class Form extends Container_1.default {
141
141
  }
142
142
  }
143
143
  resolveQualifiedName(qualifiedName) {
144
+ if (this.qualifiedName === qualifiedName) {
145
+ return this;
146
+ }
144
147
  let foundFormElement = null;
145
148
  this.visit(formElement => {
146
149
  if (formElement.qualifiedName === qualifiedName) {
@@ -237,11 +240,22 @@ class Form extends Container_1.default {
237
240
  get ruleEngine() {
238
241
  return this._ruleEngine;
239
242
  }
240
- getUniqueId() {
243
+ getUniqueId(id) {
244
+ var _a, _b, _c;
245
+ if (id && !((_a = this._idSet) === null || _a === void 0 ? void 0 : _a.has(id))) {
246
+ (_b = this._idSet) === null || _b === void 0 ? void 0 : _b.add(id);
247
+ return id;
248
+ }
241
249
  if (this._ids == null) {
242
250
  return '';
243
251
  }
244
- return this._ids.next().value;
252
+ const newId = this._ids.next().value;
253
+ (_c = this._idSet) === null || _c === void 0 ? void 0 : _c.add(newId);
254
+ return newId;
255
+ }
256
+ clearIdRegistry() {
257
+ var _a;
258
+ (_a = this._idSet) === null || _a === void 0 ? void 0 : _a.clear();
245
259
  }
246
260
  fieldAdded(field) {
247
261
  if (field.fieldType === 'captcha' && !this._captcha) {
@@ -82,6 +82,7 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
82
82
  response.originalRequest = Object.assign({ url: endpoint, method: httpVerb }, encryptOutput);
83
83
  const targetField = context.$field || null;
84
84
  const targetEvent = context.$event || null;
85
+ response.submitter = targetField;
85
86
  const enhancedPayload = {
86
87
  request: response.originalRequest,
87
88
  response,
@@ -94,7 +95,12 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
94
95
  context.form.dispatch(new Events_1.SubmitSuccess(response, true));
95
96
  }
96
97
  else {
97
- context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
98
+ if (context.field) {
99
+ context.field.dispatch(new Events_1.CustomEvent(eName, response, true));
100
+ }
101
+ else {
102
+ context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
103
+ }
98
104
  }
99
105
  context.form.dispatch(new Events_1.RequestSuccess(enhancedPayload, false));
100
106
  }
@@ -106,7 +112,12 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
106
112
  context.form.dispatch(new Events_1.SubmitFailure(response, true));
107
113
  }
108
114
  else {
109
- context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
115
+ if (context.field) {
116
+ context.field.dispatch(new Events_1.CustomEvent(eName, response, true));
117
+ }
118
+ else {
119
+ context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
120
+ }
110
121
  }
111
122
  context.form.dispatch(new Events_1.RequestFailure(enhancedPayload, false));
112
123
  }
@@ -126,7 +126,7 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
126
126
  readonly specVersion: Version;
127
127
  exportData(): any;
128
128
  getElement(id: string): FieldModel | FormModel | FieldsetModel;
129
- getUniqueId(): string;
129
+ getUniqueId(id?: string): string;
130
130
  getEventQueue(): EventQueue;
131
131
  visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
132
132
  resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.132",
3
+ "version": "0.22.134",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@adobe/json-formula": "0.1.50",
40
- "@aemforms/af-formatters": "^0.22.132"
40
+ "@aemforms/af-formatters": "^0.22.134"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",