@aemforms/af-core 0.22.33 → 0.22.35

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.
package/lib/BaseNode.d.ts CHANGED
@@ -72,6 +72,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
72
72
  queueEvent(action: Action): void;
73
73
  dispatch(action: Action): void;
74
74
  notifyDependents(action: Action): void;
75
+ protected isEmpty(value?: any): boolean;
75
76
  _setProperty<T>(prop: string, newValue: T, notify?: boolean, notifyChildren?: (action: Action) => void): any;
76
77
  _bindToDataModel(contextualDataModel: DataGroup): void;
77
78
  private _data?;
package/lib/BaseNode.js CHANGED
@@ -279,6 +279,9 @@ class BaseNode {
279
279
  x(new ActionImplWithTarget(action, this));
280
280
  });
281
281
  }
282
+ isEmpty(value = this._jsonModel.value) {
283
+ return value === undefined || value === null || value === '';
284
+ }
282
285
  _setProperty(prop, newValue, notify = true, notifyChildren = (action) => { }) {
283
286
  const oldValue = this._jsonModel[prop];
284
287
  let isValueSame = false;
package/lib/Field.d.ts CHANGED
@@ -39,7 +39,6 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
39
39
  set maximum(m: number | undefined);
40
40
  get minimum(): number | undefined;
41
41
  set minimum(m: number | undefined);
42
- private isEmpty;
43
42
  private withCategory;
44
43
  get editValue(): any;
45
44
  get displayValue(): any;
package/lib/Field.js CHANGED
@@ -249,9 +249,6 @@ class Field extends Scriptable_1.default {
249
249
  this._setProperty('minimum', m);
250
250
  }
251
251
  }
252
- isEmpty() {
253
- return this._jsonModel.value === undefined || this._jsonModel.value === null || this._jsonModel.value === '';
254
- }
255
252
  withCategory(df) {
256
253
  if (df) {
257
254
  const hasCategory = df === null || df === void 0 ? void 0 : df.match(/^(?:date|num)\|/);
@@ -350,15 +347,13 @@ class Field extends Scriptable_1.default {
350
347
  }
351
348
  reset() {
352
349
  const changes = this.updateDataNodeAndTypedValue(this.default);
353
- if (changes.length > 0) {
354
- const validationStateChanges = {
355
- 'valid': undefined,
356
- 'errorMessage': ''
357
- };
358
- const updates = this._applyUpdates(['valid', 'errorMessage'], validationStateChanges);
359
- const changeAction = new Events_1.Change({ changes: changes.concat(Object.values(updates)) });
360
- this.dispatch(changeAction);
361
- }
350
+ const validationStateChanges = {
351
+ 'valid': undefined,
352
+ 'errorMessage': ''
353
+ };
354
+ const updates = this._applyUpdates(['valid', 'errorMessage'], validationStateChanges);
355
+ const changeAction = new Events_1.Change({ changes: changes.concat(Object.values(updates)) });
356
+ this.dispatch(changeAction);
362
357
  }
363
358
  _updateRuleNodeReference(value) {
364
359
  var _a;
package/lib/Scriptable.js CHANGED
@@ -69,7 +69,10 @@ class Scriptable extends BaseNode_1.BaseNode {
69
69
  if (node) {
70
70
  const newVal = this.ruleEngine.execute(node, scope, context, true);
71
71
  if (BaseNode_1.editableProperties.indexOf(prop) > -1) {
72
- this[prop] = newVal;
72
+ const oldAndNewValueAreEmpty = this.isEmpty() && this.isEmpty(newVal) && prop === 'value';
73
+ if (!oldAndNewValueAreEmpty) {
74
+ this[prop] = newVal;
75
+ }
73
76
  }
74
77
  else {
75
78
  this.form.logger.warn(`${prop} is not a valid editable property.`);
@@ -28,46 +28,44 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
28
28
  const requestOptions = {
29
29
  method: httpVerb
30
30
  };
31
- let result;
32
31
  let inputPayload;
33
- try {
34
- if (payload && payload instanceof FileObject_1.FileObject && payload.data instanceof File) {
35
- const formData = new FormData();
36
- formData.append(payload.name, payload.data);
37
- inputPayload = formData;
32
+ if (payload && payload instanceof FileObject_1.FileObject && payload.data instanceof File) {
33
+ const formData = new FormData();
34
+ formData.append(payload.name, payload.data);
35
+ inputPayload = formData;
36
+ }
37
+ else if (payload instanceof FormData) {
38
+ inputPayload = payload;
39
+ }
40
+ else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
41
+ const headerNames = Object.keys(headers);
42
+ if (headerNames.length > 0) {
43
+ requestOptions.headers = Object.assign(Object.assign({}, headers), (headerNames.indexOf('Content-Type') === -1 ? { 'Content-Type': 'application/json' } : {}));
38
44
  }
39
- else if (payload instanceof FormData) {
40
- inputPayload = payload;
45
+ else {
46
+ requestOptions.headers = { 'Content-Type': 'application/json' };
41
47
  }
42
- else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
43
- const headerNames = Object.keys(headers);
44
- if (headerNames.length > 0) {
45
- requestOptions.headers = Object.assign(Object.assign({}, headers), (headerNames.indexOf('Content-Type') === -1 ? { 'Content-Type': 'application/json' } : {}));
46
- }
47
- else {
48
- requestOptions.headers = { 'Content-Type': 'application/json' };
49
- }
50
- const contentType = ((_a = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) || 'application/json';
51
- if (contentType === 'application/json') {
52
- inputPayload = JSON.stringify(payload);
53
- }
54
- else if (contentType.indexOf('multipart/form-data') > -1) {
55
- inputPayload = multipartFormData(payload);
56
- }
57
- else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
58
- inputPayload = urlEncoded(payload);
59
- }
48
+ const contentType = ((_a = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) || 'application/json';
49
+ if (contentType === 'application/json') {
50
+ inputPayload = JSON.stringify(payload);
60
51
  }
61
- result = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
52
+ else if (contentType.indexOf('multipart/form-data') > -1) {
53
+ inputPayload = multipartFormData(payload);
54
+ }
55
+ else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
56
+ inputPayload = urlEncoded(payload);
57
+ }
58
+ }
59
+ const result = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
60
+ if ((result === null || result === void 0 ? void 0 : result.status) >= 200 && (result === null || result === void 0 ? void 0 : result.status) <= 299) {
61
+ const eName = getCustomEventName(success);
62
+ context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
62
63
  }
63
- catch (e) {
64
+ else {
64
65
  context.form.logger.error('Error invoking a rest API');
65
66
  const eName = getCustomEventName(error);
66
67
  context.form.dispatch(new Events_1.CustomEvent(eName, {}, true));
67
- return;
68
68
  }
69
- const eName = getCustomEventName(success);
70
- context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
71
69
  });
72
70
  exports.request = request;
73
71
  const urlEncoded = (data) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.33",
3
+ "version": "0.22.35",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@adobe/json-formula": "0.1.50",
38
- "@aemforms/af-formatters": "^0.22.33"
38
+ "@aemforms/af-formatters": "^0.22.35"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/preset-env": "^7.20.2",