@aemforms/af-core 0.22.31 → 0.22.33

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 (98) hide show
  1. package/lib/{esm/BaseNode.d.ts → BaseNode.d.ts} +6 -6
  2. package/lib/{esm/BaseNode-f84b22c6.js → BaseNode.js} +58 -94
  3. package/lib/{esm/Checkbox.d.ts → Checkbox.d.ts} +1 -1
  4. package/lib/Checkbox.js +29 -0
  5. package/lib/{esm/CheckboxGroup.d.ts → CheckboxGroup.d.ts} +2 -2
  6. package/lib/CheckboxGroup.js +24 -0
  7. package/lib/{esm/Container.d.ts → Container.d.ts} +4 -4
  8. package/lib/{esm/Container.js → Container.js} +51 -77
  9. package/lib/{esm/DateField.d.ts → DateField.d.ts} +1 -1
  10. package/lib/DateField.js +26 -0
  11. package/lib/{esm/Field.d.ts → Field.d.ts} +7 -7
  12. package/lib/{esm/Field.js → Field.js} +84 -104
  13. package/lib/{esm/Fieldset.d.ts → Fieldset.d.ts} +7 -7
  14. package/lib/{esm/Fieldset.js → Fieldset.js} +14 -43
  15. package/lib/{esm/FileObject.d.ts → FileObject.d.ts} +1 -1
  16. package/lib/FileObject.js +29 -0
  17. package/lib/{esm/FileUpload.d.ts → FileUpload.d.ts} +3 -3
  18. package/lib/FileUpload.js +124 -0
  19. package/lib/{esm/Form.d.ts → Form.d.ts} +12 -12
  20. package/lib/{esm/Form.js → Form.js} +34 -65
  21. package/lib/{esm/FormInstance.d.ts → FormInstance.d.ts} +3 -3
  22. package/lib/FormInstance.js +94 -0
  23. package/lib/{esm/FormMetaData.d.ts → FormMetaData.d.ts} +2 -2
  24. package/lib/FormMetaData.js +15 -0
  25. package/lib/{esm/InstanceManager.d.ts → InstanceManager.d.ts} +2 -2
  26. package/lib/InstanceManager.js +35 -0
  27. package/lib/Node.js +15 -0
  28. package/lib/{esm/Scriptable.d.ts → Scriptable.d.ts} +3 -3
  29. package/lib/{esm/Scriptable.js → Scriptable.js} +17 -38
  30. package/lib/{esm/controller → controller}/EventQueue.d.ts +3 -3
  31. package/lib/{esm/controller → controller}/EventQueue.js +8 -32
  32. package/lib/{esm/controller → controller}/Events.d.ts +2 -2
  33. package/lib/{esm/controller → controller}/Events.js +22 -26
  34. package/lib/{esm/controller → controller}/Logger.d.ts +2 -2
  35. package/lib/controller/Logger.js +33 -0
  36. package/lib/{esm/data → data}/DataGroup.d.ts +1 -1
  37. package/lib/{esm/data → data}/DataGroup.js +20 -38
  38. package/lib/{esm/data → data}/DataValue.d.ts +1 -1
  39. package/lib/{esm/data → data}/DataValue.js +4 -26
  40. package/lib/{esm/data → data}/EmptyDataValue.d.ts +1 -1
  41. package/lib/data/EmptyDataValue.js +34 -0
  42. package/lib/index.d.ts +21 -0
  43. package/lib/index.js +57 -0
  44. package/lib/{esm/rules → rules}/FunctionRuntime.d.ts +3 -3
  45. package/lib/{esm/rules → rules}/FunctionRuntime.js +52 -63
  46. package/lib/{esm/rules → rules}/RuleEngine.d.ts +1 -1
  47. package/lib/rules/RuleEngine.js +51 -0
  48. package/lib/{esm/types → types}/Json.d.ts +16 -16
  49. package/lib/types/Json.js +10 -0
  50. package/lib/{esm/types → types}/Model.d.ts +9 -9
  51. package/lib/types/Model.js +10 -0
  52. package/lib/types/index.d.ts +2 -0
  53. package/lib/types/index.js +18 -0
  54. package/lib/{esm/utils → utils}/DataRefParser.d.ts +4 -4
  55. package/lib/{esm/utils → utils}/DataRefParser.js +30 -45
  56. package/lib/{esm/utils → utils}/Fetch.d.ts +1 -1
  57. package/lib/utils/Fetch.js +74 -0
  58. package/lib/{esm/utils → utils}/FormCreationUtils.d.ts +1 -1
  59. package/lib/utils/FormCreationUtils.js +67 -0
  60. package/lib/{esm/utils → utils}/FormUtils.d.ts +2 -1
  61. package/lib/{esm/utils → utils}/FormUtils.js +62 -46
  62. package/lib/{esm/utils → utils}/JsonUtils.d.ts +1 -1
  63. package/lib/utils/JsonUtils.js +89 -0
  64. package/lib/{esm/utils → utils}/LogUtils.d.ts +1 -1
  65. package/lib/utils/LogUtils.js +10 -0
  66. package/lib/{esm/utils → utils}/SchemaUtils.d.ts +1 -1
  67. package/lib/{esm/utils → utils}/SchemaUtils.js +9 -29
  68. package/lib/{esm/utils → utils}/TranslationUtils.d.ts +2 -2
  69. package/lib/utils/TranslationUtils.js +125 -0
  70. package/lib/{esm/utils → utils}/ValidationUtils.d.ts +4 -4
  71. package/lib/{esm/utils → utils}/ValidationUtils.js +13 -35
  72. package/package.json +8 -13
  73. package/lib/cjs/index.cjs +0 -7426
  74. package/lib/esm/BaseNode.js +0 -26
  75. package/lib/esm/Checkbox.js +0 -63
  76. package/lib/esm/CheckboxGroup.js +0 -60
  77. package/lib/esm/DateField.js +0 -57
  78. package/lib/esm/FileObject.js +0 -48
  79. package/lib/esm/FileUpload.js +0 -141
  80. package/lib/esm/FormInstance.js +0 -129
  81. package/lib/esm/FormMetaData.js +0 -35
  82. package/lib/esm/InstanceManager.js +0 -58
  83. package/lib/esm/Node.js +0 -40
  84. package/lib/esm/controller/Logger.js +0 -52
  85. package/lib/esm/data/EmptyDataValue.js +0 -51
  86. package/lib/esm/index.d.ts +0 -21
  87. package/lib/esm/index.js +0 -55
  88. package/lib/esm/rules/RuleEngine.js +0 -76
  89. package/lib/esm/types/Json.js +0 -29
  90. package/lib/esm/types/Model.js +0 -30
  91. package/lib/esm/types/index.d.ts +0 -2
  92. package/lib/esm/types/index.js +0 -22
  93. package/lib/esm/utils/Fetch.js +0 -83
  94. package/lib/esm/utils/FormCreationUtils.js +0 -112
  95. package/lib/esm/utils/JsonUtils.js +0 -99
  96. package/lib/esm/utils/LogUtils.js +0 -28
  97. package/lib/esm/utils/TranslationUtils.js +0 -138
  98. /package/lib/{esm/Node.d.ts → Node.d.ts} +0 -0
@@ -1,31 +1,14 @@
1
- /*************************************************************************
2
- * ADOBE CONFIDENTIAL
3
- * ___________________
4
- *
5
- * Copyright 2022 Adobe
6
- * All Rights Reserved.
7
- *
8
- * NOTICE: All information contained herein is, and remains
9
- * the property of Adobe and its suppliers, if any. The intellectual
10
- * and technical concepts contained herein are proprietary to Adobe
11
- * and its suppliers and are protected by all applicable intellectual
12
- * property laws, including trade secret and copyright laws.
13
- * Dissemination of this information or reproduction of this material
14
- * is strictly forbidden unless prior written permission is obtained
15
- * from Adobe.
16
-
17
- * Adobe permits you to use and modify this file solely in accordance with
18
- * the terms of the Adobe license agreement accompanying it.
19
- *************************************************************************/
20
-
21
- import DataGroup from '../data/DataGroup.js';
22
- import '../data/DataValue.js';
23
- import '../data/EmptyDataValue.js';
24
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveData = exports.tokenize = exports.repeatable = exports.global$ = exports.bracket = exports.identifier = exports.TOK_REPEATABLE = exports.TOK_GLOBAL = void 0;
7
+ const DataGroup_1 = __importDefault(require("../data/DataGroup"));
25
8
  const TOK_DOT = 'DOT';
26
9
  const TOK_IDENTIFIER = 'Identifier';
27
- const TOK_GLOBAL = 'Global';
28
- const TOK_REPEATABLE = 'Repeatable';
10
+ exports.TOK_GLOBAL = 'Global';
11
+ exports.TOK_REPEATABLE = 'Repeatable';
29
12
  const TOK_BRACKET = 'bracket';
30
13
  const TOK_NUMBER = 'Number';
31
14
  const globalStartToken = '$';
@@ -37,6 +20,7 @@ const identifier = (value, start) => {
37
20
  start
38
21
  };
39
22
  };
23
+ exports.identifier = identifier;
40
24
  const bracket = (value, start) => {
41
25
  return {
42
26
  type: TOK_BRACKET,
@@ -44,20 +28,23 @@ const bracket = (value, start) => {
44
28
  start
45
29
  };
46
30
  };
31
+ exports.bracket = bracket;
47
32
  const global$ = () => {
48
33
  return {
49
- type: TOK_GLOBAL,
34
+ type: exports.TOK_GLOBAL,
50
35
  start: 0,
51
36
  value: globalStartToken
52
37
  };
53
38
  };
39
+ exports.global$ = global$;
54
40
  const repeatable = () => {
55
41
  return {
56
- type: TOK_REPEATABLE,
42
+ type: exports.TOK_REPEATABLE,
57
43
  start: 0,
58
44
  value: repeatableStartToken
59
45
  };
60
46
  };
47
+ exports.repeatable = repeatable;
61
48
  const isAlphaNum = function (ch) {
62
49
  return (ch >= 'a' && ch <= 'z')
63
50
  || (ch >= 'A' && ch <= 'Z')
@@ -83,21 +70,19 @@ const isNum = (ch) => {
83
70
  return (ch >= '0' && ch <= '9');
84
71
  };
85
72
  class Tokenizer {
86
- stream;
87
- _current;
88
- _tokens = [];
89
- _result_tokens = [];
90
73
  constructor(stream) {
91
74
  this.stream = stream;
75
+ this._tokens = [];
76
+ this._result_tokens = [];
92
77
  this._current = 0;
93
78
  }
94
79
  _consumeGlobal() {
95
80
  this._current += 1;
96
- return global$();
81
+ return (0, exports.global$)();
97
82
  }
98
83
  _consumeRepeatable() {
99
84
  this._current += 1;
100
- return repeatable();
85
+ return (0, exports.repeatable)();
101
86
  }
102
87
  _consumeUnquotedIdentifier(stream) {
103
88
  const start = this._current;
@@ -105,7 +90,7 @@ class Tokenizer {
105
90
  while (this._current < stream.length && isAlphaNum(stream[this._current])) {
106
91
  this._current += 1;
107
92
  }
108
- return identifier(stream.slice(start, this._current), start);
93
+ return (0, exports.identifier)(stream.slice(start, this._current), start);
109
94
  }
110
95
  _consumeQuotedIdentifier(stream) {
111
96
  const start = this._current;
@@ -123,7 +108,7 @@ class Tokenizer {
123
108
  this._current = current;
124
109
  }
125
110
  this._current += 1;
126
- return identifier(JSON.parse(stream.slice(start, this._current)), start);
111
+ return (0, exports.identifier)(JSON.parse(stream.slice(start, this._current)), start);
127
112
  }
128
113
  _consumeNumber(stream) {
129
114
  const start = this._current;
@@ -150,7 +135,7 @@ class Tokenizer {
150
135
  throw new Error(`unexpected exception at position ${this._current}. Must be a character`);
151
136
  }
152
137
  this._current++;
153
- return bracket(value, start);
138
+ return (0, exports.bracket)(value, start);
154
139
  }
155
140
  tokenize() {
156
141
  const stream = this.stream;
@@ -201,10 +186,11 @@ class Tokenizer {
201
186
  const tokenize = (stream) => {
202
187
  return new Tokenizer(stream).tokenize();
203
188
  };
189
+ exports.tokenize = tokenize;
204
190
  const resolveData = (data, input, create) => {
205
191
  let tokens;
206
192
  if (typeof input === 'string') {
207
- tokens = tokenize(input);
193
+ tokens = (0, exports.tokenize)(input);
208
194
  }
209
195
  else {
210
196
  tokens = input;
@@ -213,16 +199,16 @@ const resolveData = (data, input, create) => {
213
199
  let i = 0;
214
200
  const createIntermediateNode = (token, nextToken, create) => {
215
201
  return nextToken === null ? create :
216
- (nextToken.type === TOK_BRACKET) ? new DataGroup(token.value, [], 'array') :
217
- new DataGroup(token.value, {});
202
+ (nextToken.type === TOK_BRACKET) ? new DataGroup_1.default(token.value, [], 'array') :
203
+ new DataGroup_1.default(token.value, {});
218
204
  };
219
205
  while (i < tokens.length && result != null) {
220
206
  const token = tokens[i];
221
- if (token.type === TOK_GLOBAL) {
207
+ if (token.type === exports.TOK_GLOBAL) {
222
208
  result = data;
223
209
  }
224
210
  else if (token.type === TOK_IDENTIFIER) {
225
- if (result instanceof DataGroup && result.$type === 'object') {
211
+ if (result instanceof DataGroup_1.default && result.$type === 'object') {
226
212
  if (result.$containsDataNode(token.value) && result.$getDataNode(token.value).$value !== null) {
227
213
  result = result.$getDataNode(token.value);
228
214
  }
@@ -241,7 +227,7 @@ const resolveData = (data, input, create) => {
241
227
  }
242
228
  }
243
229
  else if (token.type === TOK_BRACKET) {
244
- if (result instanceof DataGroup && result.$type === 'array') {
230
+ if (result instanceof DataGroup_1.default && result.$type === 'array') {
245
231
  const index = token.value;
246
232
  if (index < result.$length) {
247
233
  result = result.$getDataNode(index);
@@ -264,5 +250,4 @@ const resolveData = (data, input, create) => {
264
250
  }
265
251
  return result;
266
252
  };
267
-
268
- export { TOK_GLOBAL, TOK_REPEATABLE, bracket, global$, identifier, repeatable, resolveData, tokenize };
253
+ exports.resolveData = resolveData;
@@ -1,5 +1,5 @@
1
1
  export declare const request: (url: string, data?: any, options?: RequestOptions) => any;
2
- export type RequestOptions = {
2
+ export declare type RequestOptions = {
3
3
  contentType?: string;
4
4
  method?: 'POST' | 'GET';
5
5
  headers?: any;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.convertQueryString = exports.request = void 0;
13
+ const request = (url, data = null, options = {}) => {
14
+ const opts = Object.assign(Object.assign({}, defaultRequestOptions), options);
15
+ const updatedUrl = opts.method === 'GET' && data ? (0, exports.convertQueryString)(url, data) : url;
16
+ if (opts.method !== 'GET') {
17
+ opts.body = data;
18
+ }
19
+ return fetch(updatedUrl, Object.assign({}, opts)).then((response) => __awaiter(void 0, void 0, void 0, function* () {
20
+ var _a, _b, _c;
21
+ let body;
22
+ if (!response.ok) {
23
+ console.error(`Error fetching response from ${url} : ${response.statusText}`);
24
+ body = response.statusText;
25
+ }
26
+ else {
27
+ 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')) {
28
+ body = yield response.json();
29
+ }
30
+ else {
31
+ body = yield response.text();
32
+ }
33
+ }
34
+ const headers = {};
35
+ (_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c.forEach((value, key) => {
36
+ headers[key] = value;
37
+ });
38
+ return {
39
+ status: response.status,
40
+ body,
41
+ headers
42
+ };
43
+ }));
44
+ };
45
+ exports.request = request;
46
+ const defaultRequestOptions = {
47
+ method: 'GET'
48
+ };
49
+ const convertQueryString = (endpoint, payload) => {
50
+ if (!payload) {
51
+ return endpoint;
52
+ }
53
+ let updatedPayload = {};
54
+ try {
55
+ updatedPayload = JSON.parse(payload);
56
+ }
57
+ catch (err) {
58
+ console.log('Query params invalid');
59
+ }
60
+ const params = [];
61
+ Object.keys(updatedPayload).forEach((key) => {
62
+ if (Array.isArray(updatedPayload[key])) {
63
+ params.push(`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(updatedPayload[key]))}`);
64
+ }
65
+ else {
66
+ params.push(`${encodeURIComponent(key)}=${encodeURIComponent(updatedPayload[key])}`);
67
+ }
68
+ });
69
+ if (!params.length) {
70
+ return endpoint;
71
+ }
72
+ return endpoint.includes('?') ? `${endpoint}&${params.join('&')}` : `${endpoint}?${params.join('&')}`;
73
+ };
74
+ exports.convertQueryString = convertQueryString;
@@ -1,4 +1,4 @@
1
- import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel, IFormFieldFactory } from '../types/index.js';
1
+ import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel, IFormFieldFactory } from '../types/index';
2
2
  declare class FormFieldFactoryImpl implements IFormFieldFactory {
3
3
  createField(child: FieldsetJson | FieldJson, _options: {
4
4
  form: FormModel;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FormFieldFactory = void 0;
7
+ const InstanceManager_1 = require("../InstanceManager");
8
+ const Fieldset_1 = require("../Fieldset");
9
+ const JsonUtils_1 = require("./JsonUtils");
10
+ const FileUpload_1 = __importDefault(require("../FileUpload"));
11
+ const Checkbox_1 = __importDefault(require("../Checkbox"));
12
+ const CheckboxGroup_1 = __importDefault(require("../CheckboxGroup"));
13
+ const DateField_1 = __importDefault(require("../DateField"));
14
+ const Field_1 = __importDefault(require("../Field"));
15
+ const alternateFieldTypeMapping = {
16
+ 'text': 'text-input',
17
+ 'number': 'number-input',
18
+ 'email': 'text-input',
19
+ 'file': 'file-input',
20
+ 'range': 'range',
21
+ 'textarea': 'multiline-input'
22
+ };
23
+ class FormFieldFactoryImpl {
24
+ createField(child, _options) {
25
+ let retVal;
26
+ const options = Object.assign(Object.assign({}, _options), { fieldFactory: this });
27
+ child.fieldType = child.fieldType ? (child.fieldType in alternateFieldTypeMapping ?
28
+ alternateFieldTypeMapping[child.fieldType] : child.fieldType)
29
+ : 'text-input';
30
+ if ((0, JsonUtils_1.isRepeatable)(child)) {
31
+ const newChild = Object.assign(Object.assign(Object.assign({}, child), ('items' in child && { 'type': 'object' })), { minOccur: undefined, maxOccur: undefined, repeatable: undefined, name: undefined });
32
+ const newJson = Object.assign({
33
+ minItems: child.minOccur || 0,
34
+ maxItems: child.maxOccur || -1,
35
+ fieldType: child.fieldType,
36
+ type: 'array',
37
+ name: child.name,
38
+ dataRef: child.dataRef
39
+ }, {
40
+ 'items': [newChild]
41
+ });
42
+ retVal = new InstanceManager_1.InstanceManager(newJson, options);
43
+ }
44
+ else if ('items' in child) {
45
+ retVal = new Fieldset_1.Fieldset(child, options);
46
+ }
47
+ else {
48
+ if ((0, JsonUtils_1.isFile)(child) || child.fieldType === 'file-input') {
49
+ retVal = new FileUpload_1.default(child, options);
50
+ }
51
+ else if ((0, JsonUtils_1.isCheckbox)(child)) {
52
+ retVal = new Checkbox_1.default(child, options);
53
+ }
54
+ else if ((0, JsonUtils_1.isCheckboxGroup)(child)) {
55
+ retVal = new CheckboxGroup_1.default(child, options);
56
+ }
57
+ else if ((0, JsonUtils_1.isDateField)(child)) {
58
+ retVal = new DateField_1.default(child, options);
59
+ }
60
+ else {
61
+ retVal = new Field_1.default(child, options);
62
+ }
63
+ }
64
+ return retVal;
65
+ }
66
+ }
67
+ exports.FormFieldFactory = new FormFieldFactoryImpl();
@@ -1,4 +1,4 @@
1
- import { ContainerModel } from '../types/index.js';
1
+ import { ContainerModel } from '../types/index';
2
2
  export declare const randomWord: (l: number) => string;
3
3
  export declare const isEmpty: (value: any) => boolean;
4
4
  export declare const getAttachments: (input: ContainerModel) => any;
@@ -10,3 +10,4 @@ export declare const dataURItoBlob: (dataURI: string) => {
10
10
  name: string;
11
11
  blob: Blob;
12
12
  } | null;
13
+ export declare const sitesModelToFormModel: (sitesModel: any) => any;
@@ -1,50 +1,38 @@
1
- /*************************************************************************
2
- * ADOBE CONFIDENTIAL
3
- * ___________________
4
- *
5
- * Copyright 2022 Adobe
6
- * All Rights Reserved.
7
- *
8
- * NOTICE: All information contained herein is, and remains
9
- * the property of Adobe and its suppliers, if any. The intellectual
10
- * and technical concepts contained herein are proprietary to Adobe
11
- * and its suppliers and are protected by all applicable intellectual
12
- * property laws, including trade secret and copyright laws.
13
- * Dissemination of this information or reproduction of this material
14
- * is strictly forbidden unless prior written permission is obtained
15
- * from Adobe.
16
-
17
- * Adobe permits you to use and modify this file solely in accordance with
18
- * the terms of the Adobe license agreement accompanying it.
19
- *************************************************************************/
20
-
21
- import { isFile } from './JsonUtils.js';
22
- import { FileObject } from '../FileObject.js';
23
- import '../types/Json.js';
24
- import './SchemaUtils.js';
25
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sitesModelToFormModel = exports.dataURItoBlob = exports.extractFileInfo = exports.isDataUrl = exports.IdGenerator = exports.getFileSizeInBytes = exports.getAttachments = exports.isEmpty = exports.randomWord = void 0;
4
+ const JsonUtils_1 = require("./JsonUtils");
5
+ const FileObject_1 = require("../FileObject");
26
6
  const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
27
7
  const fileSizeRegex = /^(\d*\.?\d+)(\\?(?=[KMGT])([KMGT])(?:i?B)?|B?)$/i;
28
8
  const randomWord = (l) => {
29
9
  const ret = [];
30
10
  for (let i = 0; i <= l; i++) {
31
- const randIndex = Math.floor(Math.random() * (chars.length));
11
+ let randIndex;
12
+ if (i === 0) {
13
+ randIndex = Math.floor(Math.random() * (chars.length - 11));
14
+ }
15
+ else {
16
+ randIndex = Math.floor(Math.random() * (chars.length));
17
+ }
32
18
  ret.push(chars[randIndex]);
33
19
  }
34
20
  return ret.join('');
35
21
  };
22
+ exports.randomWord = randomWord;
36
23
  const isEmpty = (value) => {
37
24
  return value === '' || value === null || value === undefined;
38
25
  };
26
+ exports.isEmpty = isEmpty;
39
27
  const getAttachments = (input) => {
40
28
  const items = input.items || [];
41
- return items?.reduce((acc, item) => {
29
+ return items === null || items === void 0 ? void 0 : items.reduce((acc, item) => {
42
30
  let ret = null;
43
31
  if (item.isContainer) {
44
- ret = getAttachments(item);
32
+ ret = (0, exports.getAttachments)(item);
45
33
  }
46
34
  else {
47
- if (isFile(item.getState())) {
35
+ if ((0, JsonUtils_1.isFile)(item.getState())) {
48
36
  ret = {};
49
37
  const name = item.name || '';
50
38
  const dataRef = (item.dataRef != null)
@@ -52,17 +40,18 @@ const getAttachments = (input) => {
52
40
  : (name.length > 0 ? item.name : undefined);
53
41
  if (item.value instanceof Array) {
54
42
  ret[item.id] = item.value.map((x) => {
55
- return { ...x, 'dataRef': dataRef };
43
+ return Object.assign(Object.assign({}, x), { 'dataRef': dataRef });
56
44
  });
57
45
  }
58
46
  else if (item.value != null) {
59
- ret[item.id] = { ...item.value, 'dataRef': dataRef };
47
+ ret[item.id] = Object.assign(Object.assign({}, item.value), { 'dataRef': dataRef });
60
48
  }
61
49
  }
62
50
  }
63
51
  return Object.assign(acc, ret);
64
52
  }, {});
65
53
  };
54
+ exports.getAttachments = getAttachments;
66
55
  const getFileSizeInBytes = (str) => {
67
56
  let retVal = 0;
68
57
  if (typeof str === 'string') {
@@ -73,6 +62,7 @@ const getFileSizeInBytes = (str) => {
73
62
  }
74
63
  return retVal;
75
64
  };
65
+ exports.getFileSizeInBytes = getFileSizeInBytes;
76
66
  const sizeToBytes = (size, symbol) => {
77
67
  const sizes = { 'KB': 1, 'MB': 2, 'GB': 3, 'TB': 4 };
78
68
  const i = Math.pow(1024, sizes[symbol]);
@@ -82,7 +72,7 @@ const IdGenerator = function* (initial = 50) {
82
72
  const initialize = function () {
83
73
  const arr = [];
84
74
  for (let i = 0; i < initial; i++) {
85
- arr.push(randomWord(10));
75
+ arr.push((0, exports.randomWord)(10));
86
76
  }
87
77
  return arr;
88
78
  };
@@ -103,14 +93,16 @@ const IdGenerator = function* (initial = 50) {
103
93
  }
104
94
  } while (ids.length > 0);
105
95
  };
96
+ exports.IdGenerator = IdGenerator;
106
97
  const isDataUrl = (str) => {
107
98
  const dataUrlRegex = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
108
99
  return dataUrlRegex.exec(str.trim()) != null;
109
100
  };
101
+ exports.isDataUrl = isDataUrl;
110
102
  const extractFileInfo = (file) => {
111
103
  if (file !== null) {
112
104
  let retVal = null;
113
- if (file instanceof FileObject) {
105
+ if (file instanceof FileObject_1.FileObject) {
114
106
  retVal = file;
115
107
  }
116
108
  else if (typeof File !== 'undefined' && file instanceof File) {
@@ -121,8 +113,8 @@ const extractFileInfo = (file) => {
121
113
  data: file
122
114
  };
123
115
  }
124
- else if (typeof file === 'string' && isDataUrl(file)) {
125
- const result = dataURItoBlob(file);
116
+ else if (typeof file === 'string' && (0, exports.isDataUrl)(file)) {
117
+ const result = (0, exports.dataURItoBlob)(file);
126
118
  if (result !== null) {
127
119
  const { blob, name } = result;
128
120
  retVal = {
@@ -144,13 +136,13 @@ const extractFileInfo = (file) => {
144
136
  }
145
137
  catch (ex) {
146
138
  }
147
- if (typeof jFile?.data === 'string' && isDataUrl(jFile?.data)) {
148
- const result = dataURItoBlob(jFile?.data);
139
+ if (typeof (jFile === null || jFile === void 0 ? void 0 : jFile.data) === 'string' && (0, exports.isDataUrl)(jFile === null || jFile === void 0 ? void 0 : jFile.data)) {
140
+ const result = (0, exports.dataURItoBlob)(jFile === null || jFile === void 0 ? void 0 : jFile.data);
149
141
  if (result !== null) {
150
142
  const blob = result.blob;
151
143
  retVal = {
152
- name: jFile?.name,
153
- mediaType: jFile?.type || jFile?.mediaType,
144
+ name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
145
+ mediaType: (jFile === null || jFile === void 0 ? void 0 : jFile.type) || (jFile === null || jFile === void 0 ? void 0 : jFile.mediaType),
154
146
  size: blob.size,
155
147
  data: blob
156
148
  };
@@ -167,15 +159,15 @@ const extractFileInfo = (file) => {
167
159
  }
168
160
  else if (typeof jFile === 'object') {
169
161
  retVal = {
170
- name: jFile?.name,
171
- mediaType: jFile?.type || jFile?.mediaType,
172
- size: jFile?.size,
173
- data: jFile?.data
162
+ name: jFile === null || jFile === void 0 ? void 0 : jFile.name,
163
+ mediaType: (jFile === null || jFile === void 0 ? void 0 : jFile.type) || (jFile === null || jFile === void 0 ? void 0 : jFile.mediaType),
164
+ size: jFile === null || jFile === void 0 ? void 0 : jFile.size,
165
+ data: jFile === null || jFile === void 0 ? void 0 : jFile.data
174
166
  };
175
167
  }
176
168
  }
177
169
  if (retVal !== null && retVal.data != null) {
178
- return new FileObject(retVal);
170
+ return new FileObject_1.FileObject(retVal);
179
171
  }
180
172
  return null;
181
173
  }
@@ -183,6 +175,7 @@ const extractFileInfo = (file) => {
183
175
  return null;
184
176
  }
185
177
  };
178
+ exports.extractFileInfo = extractFileInfo;
186
179
  const dataURItoBlob = (dataURI) => {
187
180
  const regex = /^data:([a-z]+\/[a-z0-9-+.]+)?(?:;name=([^;]+))?(;base64)?,(.+)$/;
188
181
  const groups = regex.exec(dataURI);
@@ -208,5 +201,28 @@ const dataURItoBlob = (dataURI) => {
208
201
  return null;
209
202
  }
210
203
  };
211
-
212
- export { IdGenerator, dataURItoBlob, extractFileInfo, getAttachments, getFileSizeInBytes, isDataUrl, isEmpty, randomWord };
204
+ exports.dataURItoBlob = dataURItoBlob;
205
+ const isFormContainer = (model) => {
206
+ return (':items' in model || 'cqItems' in model) && (':itemsOrder' in model || 'cqItemsOrder' in model) && 'fieldType' in model;
207
+ };
208
+ const sitesModelToFormModel = (sitesModel) => {
209
+ if (!sitesModel || !Object.keys(sitesModel).length) {
210
+ return sitesModel;
211
+ }
212
+ if (isFormContainer(sitesModel)) {
213
+ const itemsArr = [];
214
+ const itemsOrder = sitesModel[':itemsOrder'] || sitesModel.cqItemsOrder;
215
+ const items = sitesModel[':items'] || sitesModel.cqItems;
216
+ itemsOrder.forEach((elemName) => {
217
+ if (isFormContainer(items[elemName])) {
218
+ itemsArr.push((0, exports.sitesModelToFormModel)(items[elemName]));
219
+ }
220
+ else {
221
+ itemsArr.push(items[elemName]);
222
+ }
223
+ });
224
+ sitesModel.items = itemsArr;
225
+ }
226
+ return sitesModel;
227
+ };
228
+ exports.sitesModelToFormModel = sitesModelToFormModel;
@@ -1,4 +1,4 @@
1
- import { FieldsetJson, FieldJson } from '../types/index.js';
1
+ import { FieldsetJson, FieldJson } from '../types/index';
2
2
  export declare const getProperty: <P>(data: any, key: string, def: P) => P;
3
3
  export declare const isFile: (item: FieldsetJson | FieldJson) => boolean;
4
4
  export declare const checkIfConstraintsArePresent: (item: FieldsetJson | FieldJson) => boolean;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRepeatable = exports.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isDateField = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
4
+ const index_1 = require("../types/index");
5
+ const SchemaUtils_1 = require("./SchemaUtils");
6
+ const getProperty = (data, key, def) => {
7
+ if (key in data) {
8
+ return data[key];
9
+ }
10
+ else if (!key.startsWith(':')) {
11
+ const prefixedKey = `:${key}`;
12
+ if (prefixedKey in data) {
13
+ return data[prefixedKey];
14
+ }
15
+ }
16
+ return def;
17
+ };
18
+ exports.getProperty = getProperty;
19
+ const isFile = function (item) {
20
+ return ((item === null || item === void 0 ? void 0 : item.type) === 'file' || (item === null || item === void 0 ? void 0 : item.type) === 'file[]') ||
21
+ (((item === null || item === void 0 ? void 0 : item.type) === 'string' || (item === null || item === void 0 ? void 0 : item.type) === 'string[]') &&
22
+ ((item === null || item === void 0 ? void 0 : item.format) === 'binary' || (item === null || item === void 0 ? void 0 : item.format) === 'data-url'));
23
+ };
24
+ exports.isFile = isFile;
25
+ const checkIfConstraintsArePresent = function (item) {
26
+ return index_1.constraintProps.some(cp => item[cp] !== undefined);
27
+ };
28
+ exports.checkIfConstraintsArePresent = checkIfConstraintsArePresent;
29
+ const isCheckbox = function (item) {
30
+ const fieldType = (item === null || item === void 0 ? void 0 : item.fieldType) || (0, SchemaUtils_1.defaultFieldTypes)(item);
31
+ return fieldType === 'checkbox';
32
+ };
33
+ exports.isCheckbox = isCheckbox;
34
+ const isCheckboxGroup = function (item) {
35
+ const fieldType = (item === null || item === void 0 ? void 0 : item.fieldType) || (0, SchemaUtils_1.defaultFieldTypes)(item);
36
+ return fieldType === 'checkbox-group';
37
+ };
38
+ exports.isCheckboxGroup = isCheckboxGroup;
39
+ const isDateField = function (item) {
40
+ const fieldType = (item === null || item === void 0 ? void 0 : item.fieldType) || (0, SchemaUtils_1.defaultFieldTypes)(item);
41
+ return (fieldType === 'text-input' && (item === null || item === void 0 ? void 0 : item.format) === 'date') || fieldType === 'date-input';
42
+ };
43
+ exports.isDateField = isDateField;
44
+ function deepClone(obj, idGenerator) {
45
+ let result;
46
+ if (obj instanceof Array) {
47
+ result = [];
48
+ result = obj.map(x => deepClone(x, idGenerator));
49
+ }
50
+ else if (typeof obj === 'object' && obj !== null) {
51
+ result = {};
52
+ Object.entries(obj).forEach(([key, value]) => {
53
+ result[key] = deepClone(value, idGenerator);
54
+ });
55
+ }
56
+ else {
57
+ result = obj;
58
+ }
59
+ if (idGenerator && result && result.id) {
60
+ result.id = idGenerator();
61
+ }
62
+ return result;
63
+ }
64
+ exports.deepClone = deepClone;
65
+ function checkIfKeyAdded(currentObj, prevObj, objKey) {
66
+ if (currentObj != null && prevObj != null) {
67
+ const newPrvObj = Object.assign({}, prevObj);
68
+ newPrvObj[objKey] = currentObj[objKey];
69
+ const newJsonStr = (0, exports.jsonString)(currentObj).replace((0, exports.jsonString)(newPrvObj), '');
70
+ return newJsonStr === '';
71
+ }
72
+ else {
73
+ return false;
74
+ }
75
+ }
76
+ exports.checkIfKeyAdded = checkIfKeyAdded;
77
+ const jsonString = (obj) => {
78
+ return JSON.stringify(obj, null, 2);
79
+ };
80
+ exports.jsonString = jsonString;
81
+ const isRepeatable = (obj) => {
82
+ return ((obj.repeatable &&
83
+ ((obj.minOccur === undefined && obj.maxOccur === undefined) ||
84
+ (obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.maxOccur !== 0) ||
85
+ (obj.minOccur !== undefined && obj.maxOccur !== undefined && obj.minOccur !== 0 && obj.maxOccur !== 0) ||
86
+ (obj.minOccur !== undefined && obj.minOccur >= 0) ||
87
+ (obj.maxOccur !== undefined && obj.maxOccur !== 0))) || false);
88
+ };
89
+ exports.isRepeatable = isRepeatable;
@@ -1,4 +1,4 @@
1
- import { callbackFn } from '../types/index.js';
1
+ import { callbackFn } from '../types/index';
2
2
  export declare const logFormCallbacks: (callbacks: {
3
3
  [key: string]: callbackFn[];
4
4
  }) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logFormCallbacks = void 0;
4
+ const logFormCallbacks = (callbacks) => {
5
+ const s = Object.entries(callbacks).map(([id, fn]) => {
6
+ return `${id} : ${fn.length}`;
7
+ }).join(' ');
8
+ console.log(s);
9
+ };
10
+ exports.logFormCallbacks = logFormCallbacks;