@aemforms/af-core 0.22.17 → 0.22.19

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.
@@ -9,7 +9,7 @@ export default class DataValue {
9
9
  private $_name;
10
10
  private $_value;
11
11
  private $_type;
12
- private $_fields;
12
+ $_fields: Array<FieldModel>;
13
13
  constructor($_name: string | number, $_value: any, $_type?: string);
14
14
  valueOf(): any;
15
15
  get $name(): string | number;
@@ -24,6 +24,10 @@ class DataValue {
24
24
  return this.$_name;
25
25
  }
26
26
  get $value() {
27
+ const enabled = this.$_fields.find(x => x.enabled !== false);
28
+ if (!enabled && this.$_fields.length) {
29
+ return undefined;
30
+ }
27
31
  return this.$_value;
28
32
  }
29
33
  setValue(typedValue, originalValue, fromField) {
@@ -191,6 +191,12 @@ const createAction = (name, payload = {}) => {
191
191
  return new Controller_1.AddItem(payload);
192
192
  case 'removeItem':
193
193
  return new Controller_1.RemoveItem(payload);
194
+ case 'reset':
195
+ return new Controller_1.Reset(payload);
196
+ case 'addInstance':
197
+ return new Controller_1.AddInstance(payload);
198
+ case 'removeInstance':
199
+ return new Controller_1.RemoveInstance(payload);
194
200
  default:
195
201
  console.error('invalid action');
196
202
  }
@@ -29,6 +29,8 @@ export declare type ConstraintsJson = TranslationConstraintsJson & {
29
29
  maxLength?: number;
30
30
  maximum?: number;
31
31
  maxItems?: number;
32
+ minOccur?: number;
33
+ maxOccur?: number;
32
34
  minLength?: number;
33
35
  minimum?: number;
34
36
  minItems?: number;
@@ -82,6 +84,10 @@ export declare type BaseJson = TranslationBaseJson & RulesJson & ConstraintsJson
82
84
  properties?: {
83
85
  [key: string]: any;
84
86
  };
87
+ repeatable?: boolean;
88
+ screenReaderText?: string;
89
+ tooltip?: string;
90
+ altText?: string;
85
91
  };
86
92
  /** Type for `form field properties`which can be translated based on `adaptive form specification` */
87
93
  declare type TranslationFieldJson = {
@@ -37,16 +37,17 @@ interface WithState<T> {
37
37
  /**
38
38
  * {@link State | state} of the form object
39
39
  */
40
- getState: () => State<T>;
40
+ getState: () => any;
41
41
  }
42
- /** Generic type for a form object state */
43
- export declare type State<T> = T extends ContainerJson ? T & {
44
- id: string;
45
- items: Array<State<FieldJson | ContainerJson>>;
46
- } : T & {
42
+ declare type stateProps = {
47
43
  id: string;
44
+ index: number;
48
45
  ':type': string;
49
46
  };
47
+ /** Generic type for a form object state */
48
+ export declare type State<T> = stateProps & (T extends ContainerJson ? T & {
49
+ items: Array<State<FieldJson | ContainerJson>>;
50
+ } : T);
50
51
  /**
51
52
  * @private
52
53
  */
@@ -190,11 +191,19 @@ export interface BaseModel extends ConstraintsJson, WithController {
190
191
  * Default value of the Field.
191
192
  */
192
193
  readonly default?: any;
194
+ /**
195
+ * Field is repeatable or not
196
+ */
197
+ readonly repeatable?: boolean;
193
198
  /**
194
199
  * Validates the given form field
195
200
  * @returns list of {@link ValidationError | validation errors}
196
201
  */
197
202
  validate(): Array<ValidationError>;
203
+ /**
204
+ * Resets the form model
205
+ */
206
+ reset(): any;
198
207
  /**
199
208
  * Imports data to the form field
200
209
  * @private
@@ -332,6 +341,12 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
332
341
  * @private
333
342
  */
334
343
  getEventQueue(): EventQueue;
344
+ /**
345
+ * visits each element in the form
346
+ * @param callBack a function which is invoked on each form element
347
+ * (including container type elements) visited
348
+ */
349
+ visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
335
350
  }
336
351
  /**
337
352
  * Defines file object interface.
@@ -344,7 +359,7 @@ export interface IFileObject {
344
359
  /**
345
360
  * Media type of the file data
346
361
  */
347
- type: string;
362
+ mediaType: string;
348
363
  /**
349
364
  * Data of the file attachment. It can be uri or any file interface specific to channel (in web, it is file object).
350
365
  */
@@ -1,3 +1,9 @@
1
+ /**
2
+ *
3
+ * @param url
4
+ * @param data
5
+ * @param options
6
+ */
1
7
  export declare const request: (url: string, data?: any, options?: RequestOptions) => any;
2
8
  export declare type RequestOptions = {
3
9
  contentType?: string;
@@ -5,3 +11,4 @@ export declare type RequestOptions = {
5
11
  headers?: any;
6
12
  mode?: string;
7
13
  };
14
+ export declare const convertQueryString: (endpoint: string, payload: string | null) => string;
@@ -6,24 +6,82 @@
6
6
  *
7
7
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
8
  */
9
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
+ return new (P || (P = Promise))(function (resolve, reject) {
12
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16
+ });
17
+ };
9
18
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.request = void 0;
19
+ exports.convertQueryString = exports.request = void 0;
20
+ /**
21
+ *
22
+ * @param url
23
+ * @param data
24
+ * @param options
25
+ */
11
26
  const request = (url, data = null, options = {}) => {
12
27
  const opts = Object.assign(Object.assign({}, defaultRequestOptions), options);
13
- return fetch(url, Object.assign(Object.assign({}, opts), { body: data })).then((response) => {
14
- var _a;
28
+ const updatedUrl = opts.method === 'GET' && data ? (0, exports.convertQueryString)(url, data) : url;
29
+ if (opts.method !== 'GET') {
30
+ opts.body = data;
31
+ }
32
+ return fetch(updatedUrl, Object.assign({}, opts)).then((response) => __awaiter(void 0, void 0, void 0, function* () {
33
+ var _a, _b, _c;
34
+ let body;
15
35
  if (!response.ok) {
16
- throw new Error(response.statusText);
17
- }
18
- if ((_a = response === null || response === void 0 ? void 0 : response.headers.get('Content-Type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
19
- return response.json();
36
+ console.error(`Error fetching response from ${url} : ${response.statusText}`);
37
+ body = response.statusText;
20
38
  }
21
39
  else {
22
- return response.text();
40
+ if ((_b = (_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a.get('Content-Type')) === null || _b === void 0 ? void 0 : _b.includes('application/json')) {
41
+ body = yield response.json();
42
+ }
43
+ else {
44
+ body = yield response.text();
45
+ }
23
46
  }
24
- });
47
+ const headers = {};
48
+ (_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c.forEach((value, key) => {
49
+ headers[key] = value;
50
+ });
51
+ return {
52
+ status: response.status,
53
+ body,
54
+ headers
55
+ };
56
+ }));
25
57
  };
26
58
  exports.request = request;
27
59
  const defaultRequestOptions = {
28
60
  method: 'GET'
29
61
  };
62
+ const convertQueryString = (endpoint, payload) => {
63
+ if (!payload) {
64
+ return endpoint;
65
+ }
66
+ let updatedPayload = {};
67
+ try {
68
+ updatedPayload = JSON.parse(payload);
69
+ }
70
+ catch (err) {
71
+ console.log('Query params invalid');
72
+ }
73
+ const params = [];
74
+ Object.keys(updatedPayload).forEach((key) => {
75
+ if (Array.isArray(updatedPayload[key])) {
76
+ params.push(`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(updatedPayload[key]))}`);
77
+ }
78
+ else {
79
+ params.push(`${encodeURIComponent(key)}=${encodeURIComponent(updatedPayload[key])}`);
80
+ }
81
+ });
82
+ if (!params.length) {
83
+ return endpoint;
84
+ }
85
+ return endpoint.includes('?') ? `${endpoint}&${params.join('&')}` : `${endpoint}?${params.join('&')}`;
86
+ };
87
+ exports.convertQueryString = convertQueryString;
@@ -0,0 +1,11 @@
1
+ import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel } from '../types';
2
+ /**
3
+ * Creates a child model inside the given parent
4
+ * @param child
5
+ * @param options
6
+ * @private
7
+ */
8
+ export declare const createChild: (child: FieldsetJson | FieldJson, options: {
9
+ form: FormModel;
10
+ parent: ContainerModel;
11
+ }, repeatableInstance?: boolean) => FieldModel | FieldsetModel;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2022 Adobe, Inc.
4
+ *
5
+ * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
+ *
7
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+ */
9
+ var __rest = (this && this.__rest) || function (s, e) {
10
+ var t = {};
11
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
12
+ t[p] = s[p];
13
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
14
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
15
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
16
+ t[p[i]] = s[p[i]];
17
+ }
18
+ return t;
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.createChild = void 0;
25
+ const InstanceManager_1 = require("../InstanceManager");
26
+ const Fieldset_1 = require("../Fieldset");
27
+ const JsonUtils_1 = require("./JsonUtils");
28
+ const FileUpload_1 = __importDefault(require("../FileUpload"));
29
+ const Checkbox_1 = __importDefault(require("../Checkbox"));
30
+ const CheckboxGroup_1 = __importDefault(require("../CheckboxGroup"));
31
+ const DateField_1 = __importDefault(require("../DateField"));
32
+ const Field_1 = __importDefault(require("../Field"));
33
+ /**
34
+ * Creates a child model inside the given parent
35
+ * @param child
36
+ * @param options
37
+ * @private
38
+ */
39
+ const createChild = (child, options, repeatableInstance = false) => {
40
+ let retVal;
41
+ // if repeatable is set
42
+ if ((0, JsonUtils_1.isRepeatable)(child) && !repeatableInstance) {
43
+ const childItemsWithMinAndMaxOccur = Object.assign(Object.assign({}, child), ('items' in child && { 'type': 'object' }));
44
+ // remove minOccur and maxOccur from child items
45
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
+ const { minOccur, maxOccur } = childItemsWithMinAndMaxOccur, childItems = __rest(childItemsWithMinAndMaxOccur, ["minOccur", "maxOccur"]);
47
+ const newJson = Object.assign({
48
+ minItems: child.minOccur || 0,
49
+ maxItems: child.maxOccur || -1,
50
+ fieldType: child.fieldType,
51
+ type: 'array',
52
+ name: child.name,
53
+ dataRef: child.dataRef // can't destructure entire child here
54
+ }, {
55
+ 'items': [childItems]
56
+ });
57
+ retVal = new InstanceManager_1.InstanceManager(newJson, options);
58
+ }
59
+ else if ('items' in child) {
60
+ retVal = new Fieldset_1.Fieldset(child, options);
61
+ }
62
+ else {
63
+ if ((0, JsonUtils_1.isFile)(child) || child.fieldType === 'file-input') {
64
+ // @ts-ignore
65
+ retVal = new FileUpload_1.default(child, options);
66
+ }
67
+ else if ((0, JsonUtils_1.isCheckbox)(child)) {
68
+ retVal = new Checkbox_1.default(child, options);
69
+ }
70
+ else if ((0, JsonUtils_1.isCheckboxGroup)(child)) {
71
+ retVal = new CheckboxGroup_1.default(child, options);
72
+ }
73
+ else if ((0, JsonUtils_1.isDateField)(child)) {
74
+ retVal = new DateField_1.default(child, options);
75
+ }
76
+ else {
77
+ retVal = new Field_1.default(child, options);
78
+ }
79
+ }
80
+ options.form.fieldAdded(retVal);
81
+ return retVal;
82
+ };
83
+ exports.createChild = createChild;
@@ -150,7 +150,7 @@ const extractFileInfo = (file) => {
150
150
  // case: file object
151
151
  retVal = {
152
152
  name: file.name,
153
- type: file.type,
153
+ mediaType: file.type,
154
154
  size: file.size,
155
155
  data: file
156
156
  };
@@ -162,7 +162,7 @@ const extractFileInfo = (file) => {
162
162
  const { blob, name } = result;
163
163
  retVal = {
164
164
  name: name,
165
- type: blob.type,
165
+ mediaType: blob.type,
166
166
  size: blob.size,
167
167
  data: blob
168
168
  };
@@ -174,6 +174,9 @@ const extractFileInfo = (file) => {
174
174
  try {
175
175
  jFile = JSON.parse(file);
176
176
  retVal = jFile;
177
+ if (!retVal.mediaType) {
178
+ retVal.mediaType = retVal.type;
179
+ }
177
180
  }
178
181
  catch (ex) {
179
182
  // do nothing
@@ -185,7 +188,7 @@ const extractFileInfo = (file) => {
185
188
  const blob = result.blob;
186
189
  retVal = {
187
190
  name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
188
- type: jFile === null || jFile === void 0 ? void 0 : jFile.type,
191
+ mediaType: (jFile === null || jFile === void 0 ? void 0 : jFile.type) || (jFile === null || jFile === void 0 ? void 0 : jFile.mediaType),
189
192
  size: blob.size,
190
193
  data: blob
191
194
  };
@@ -196,7 +199,7 @@ const extractFileInfo = (file) => {
196
199
  const fileName = jFile.split('/').pop();
197
200
  retVal = {
198
201
  name: fileName,
199
- type: 'application/octet-stream',
202
+ mediaType: 'application/octet-stream',
200
203
  size: 0,
201
204
  data: jFile
202
205
  };
@@ -205,7 +208,7 @@ const extractFileInfo = (file) => {
205
208
  // todo: just added for ease of integration for the view layer
206
209
  retVal = {
207
210
  name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
208
- type: jFile === null || jFile === void 0 ? void 0 : jFile.type,
211
+ mediaType: (jFile === null || jFile === void 0 ? void 0 : jFile.type) || (jFile === null || jFile === void 0 ? void 0 : jFile.mediaType),
209
212
  size: jFile === null || jFile === void 0 ? void 0 : jFile.size,
210
213
  data: jFile === null || jFile === void 0 ? void 0 : jFile.data
211
214
  };
@@ -60,3 +60,4 @@ export declare function checkIfKeyAdded(currentObj: any, prevObj: any, objKey: s
60
60
  * @return json string
61
61
  */
62
62
  export declare const jsonString: (obj: any) => string;
63
+ export declare const isRepeatable: (obj: FieldsetJson | FieldJson) => boolean;
@@ -7,7 +7,7 @@
7
7
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isDateField = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
10
+ exports.isRepeatable = exports.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isDateField = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
11
11
  /**
12
12
  * Defines generic utilities to interact with form model definition which is represented as json
13
13
  */
@@ -141,3 +141,17 @@ const jsonString = (obj) => {
141
141
  return JSON.stringify(obj, null, 2);
142
142
  };
143
143
  exports.jsonString = jsonString;
144
+ const isRepeatable = (obj) => {
145
+ return ((obj.repeatable &&
146
+ // case0: both are undefined
147
+ ((obj.minOccur === undefined && obj.maxOccur === undefined) ||
148
+ // case1: if minOccur is specified and maxOccur specified is not equal to zero, then it is repeatable
149
+ (obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.maxOccur !== 0) ||
150
+ // case2: if both specified and both equal to zero, then it is not repeatable
151
+ (obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.minOccur !== 0 && obj.maxOccur !== 0) ||
152
+ // case3: only if minOccur is specified, then it should be greater than zero for repeatable
153
+ (obj.minOccur !== undefined && obj.minOccur >= 0) ||
154
+ // case4: only if maxOccur is specified, then it should be non-zero for repeatable
155
+ (obj.maxOccur !== undefined && obj.maxOccur !== 0))) || false);
156
+ };
157
+ exports.isRepeatable = isRepeatable;
@@ -49,6 +49,11 @@ exports.isDataUrl = isDataUrl;
49
49
  * @returns {@link ValidationResult | Validation result}
50
50
  */
51
51
  const checkNumber = (inputVal) => {
52
+ if (inputVal === '' || inputVal == null) {
53
+ return {
54
+ value: '', valid: true
55
+ };
56
+ }
52
57
  let value = parseFloat(inputVal);
53
58
  const valid = !isNaN(value);
54
59
  if (!valid) {
@@ -58,7 +63,16 @@ const checkNumber = (inputVal) => {
58
63
  value, valid
59
64
  };
60
65
  };
66
+ /**
67
+ *
68
+ * @param inputVal
69
+ */
61
70
  const checkInteger = (inputVal) => {
71
+ if (inputVal == '' || inputVal == null) {
72
+ return {
73
+ value: '', valid: true
74
+ };
75
+ }
62
76
  let value = parseFloat(inputVal);
63
77
  const valid = !isNaN(value) && Math.round(value) === value;
64
78
  if (!valid) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.17",
3
+ "version": "0.22.19",
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.44",
38
- "@aemforms/af-formatters": "^0.22.17"
38
+ "@aemforms/af-formatters": "^0.22.19"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/jest": "^27.5.1",