@aemforms/af-core 0.22.30 → 0.22.32
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/{esm/BaseNode.d.ts → BaseNode.d.ts} +8 -8
- package/lib/{esm/BaseNode-d78cc1b0.js → BaseNode.js} +72 -97
- package/lib/{esm/Checkbox.d.ts → Checkbox.d.ts} +1 -1
- package/lib/Checkbox.js +29 -0
- package/lib/{esm/CheckboxGroup.d.ts → CheckboxGroup.d.ts} +2 -2
- package/lib/CheckboxGroup.js +24 -0
- package/lib/{esm/Container.d.ts → Container.d.ts} +4 -4
- package/lib/{esm/Container.js → Container.js} +51 -77
- package/lib/{esm/DateField.d.ts → DateField.d.ts} +1 -1
- package/lib/DateField.js +26 -0
- package/lib/{esm/Field.d.ts → Field.d.ts} +10 -9
- package/lib/{esm/Field.js → Field.js} +97 -105
- package/lib/Fieldset.d.ts +72 -0
- package/lib/Fieldset.js +89 -0
- package/lib/{esm/FileObject.d.ts → FileObject.d.ts} +1 -1
- package/lib/FileObject.js +29 -0
- package/lib/{esm/FileUpload.d.ts → FileUpload.d.ts} +3 -3
- package/lib/FileUpload.js +124 -0
- package/lib/{esm/Form.d.ts → Form.d.ts} +13 -13
- package/lib/{esm/Form.js → Form.js} +34 -68
- package/lib/{esm/FormInstance.d.ts → FormInstance.d.ts} +3 -3
- package/lib/FormInstance.js +94 -0
- package/lib/{esm/FormMetaData.d.ts → FormMetaData.d.ts} +2 -2
- package/lib/FormMetaData.js +15 -0
- package/lib/{esm/InstanceManager.d.ts → InstanceManager.d.ts} +2 -2
- package/lib/InstanceManager.js +35 -0
- package/lib/{esm/Node.d.ts → Node.d.ts} +0 -0
- package/lib/Node.js +15 -0
- package/lib/{esm/Scriptable.d.ts → Scriptable.d.ts} +3 -3
- package/lib/{esm/Scriptable.js → Scriptable.js} +17 -38
- package/lib/{esm/controller → controller}/EventQueue.d.ts +3 -3
- package/lib/{esm/controller → controller}/EventQueue.js +8 -32
- package/lib/{esm/controller → controller}/Events.d.ts +2 -2
- package/lib/{esm/controller → controller}/Events.js +22 -26
- package/lib/{esm/controller → controller}/Logger.d.ts +2 -2
- package/lib/controller/Logger.js +33 -0
- package/lib/{esm/data → data}/DataGroup.d.ts +1 -1
- package/lib/{esm/data → data}/DataGroup.js +20 -38
- package/lib/{esm/data → data}/DataValue.d.ts +1 -1
- package/lib/{esm/data → data}/DataValue.js +4 -26
- package/lib/{esm/data → data}/EmptyDataValue.d.ts +1 -1
- package/lib/data/EmptyDataValue.js +34 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.js +57 -0
- package/lib/{esm/rules → rules}/FunctionRuntime.d.ts +3 -3
- package/lib/{esm/rules → rules}/FunctionRuntime.js +52 -63
- package/lib/{esm/rules → rules}/RuleEngine.d.ts +1 -1
- package/lib/rules/RuleEngine.js +51 -0
- package/lib/{esm/types → types}/Json.d.ts +18 -16
- package/lib/types/Json.js +10 -0
- package/lib/{esm/types → types}/Model.d.ts +10 -10
- package/lib/types/Model.js +10 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +18 -0
- package/lib/{esm/utils → utils}/DataRefParser.d.ts +10 -4
- package/lib/{esm/utils → utils}/DataRefParser.js +48 -42
- package/lib/{esm/utils → utils}/Fetch.d.ts +1 -1
- package/lib/utils/Fetch.js +74 -0
- package/lib/{esm/utils → utils}/FormCreationUtils.d.ts +1 -1
- package/lib/utils/FormCreationUtils.js +67 -0
- package/lib/{esm/utils → utils}/FormUtils.d.ts +2 -1
- package/lib/{esm/utils → utils}/FormUtils.js +62 -46
- package/lib/{esm/utils → utils}/JsonUtils.d.ts +1 -1
- package/lib/utils/JsonUtils.js +89 -0
- package/lib/{esm/utils → utils}/LogUtils.d.ts +1 -1
- package/lib/utils/LogUtils.js +10 -0
- package/lib/{esm/utils → utils}/SchemaUtils.d.ts +1 -1
- package/lib/{esm/utils → utils}/SchemaUtils.js +9 -29
- package/lib/{esm/utils → utils}/TranslationUtils.d.ts +2 -2
- package/lib/utils/TranslationUtils.js +125 -0
- package/lib/{esm/utils → utils}/ValidationUtils.d.ts +4 -4
- package/lib/{esm/utils → utils}/ValidationUtils.js +13 -35
- package/package.json +8 -13
- package/lib/cjs/index.cjs +0 -7345
- package/lib/esm/BaseNode.js +0 -26
- package/lib/esm/Checkbox.js +0 -63
- package/lib/esm/CheckboxGroup.js +0 -60
- package/lib/esm/DateField.js +0 -57
- package/lib/esm/Fieldset.d.ts +0 -16
- package/lib/esm/Fieldset.js +0 -78
- package/lib/esm/FileObject.js +0 -48
- package/lib/esm/FileUpload.js +0 -141
- package/lib/esm/FormInstance.js +0 -129
- package/lib/esm/FormMetaData.js +0 -35
- package/lib/esm/InstanceManager.js +0 -58
- package/lib/esm/Node.js +0 -40
- package/lib/esm/controller/Logger.js +0 -52
- package/lib/esm/data/EmptyDataValue.js +0 -51
- package/lib/esm/index.d.ts +0 -21
- package/lib/esm/index.js +0 -55
- package/lib/esm/rules/RuleEngine.js +0 -76
- package/lib/esm/types/Json.js +0 -29
- package/lib/esm/types/Model.js +0 -30
- package/lib/esm/types/index.d.ts +0 -2
- package/lib/esm/types/index.js +0 -22
- package/lib/esm/utils/Fetch.js +0 -83
- package/lib/esm/utils/FormCreationUtils.js +0 -112
- package/lib/esm/utils/JsonUtils.js +0 -99
- package/lib/esm/utils/LogUtils.js +0 -28
- package/lib/esm/utils/TranslationUtils.js +0 -138
|
@@ -1,33 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
+
exports.TOK_GLOBAL = 'Global';
|
|
11
|
+
exports.TOK_REPEATABLE = 'Repeatable';
|
|
28
12
|
const TOK_BRACKET = 'bracket';
|
|
29
13
|
const TOK_NUMBER = 'Number';
|
|
30
14
|
const globalStartToken = '$';
|
|
15
|
+
const repeatableStartToken = '#';
|
|
31
16
|
const identifier = (value, start) => {
|
|
32
17
|
return {
|
|
33
18
|
type: TOK_IDENTIFIER,
|
|
@@ -35,6 +20,7 @@ const identifier = (value, start) => {
|
|
|
35
20
|
start
|
|
36
21
|
};
|
|
37
22
|
};
|
|
23
|
+
exports.identifier = identifier;
|
|
38
24
|
const bracket = (value, start) => {
|
|
39
25
|
return {
|
|
40
26
|
type: TOK_BRACKET,
|
|
@@ -42,13 +28,23 @@ const bracket = (value, start) => {
|
|
|
42
28
|
start
|
|
43
29
|
};
|
|
44
30
|
};
|
|
31
|
+
exports.bracket = bracket;
|
|
45
32
|
const global$ = () => {
|
|
46
33
|
return {
|
|
47
|
-
type: TOK_GLOBAL,
|
|
34
|
+
type: exports.TOK_GLOBAL,
|
|
48
35
|
start: 0,
|
|
49
36
|
value: globalStartToken
|
|
50
37
|
};
|
|
51
38
|
};
|
|
39
|
+
exports.global$ = global$;
|
|
40
|
+
const repeatable = () => {
|
|
41
|
+
return {
|
|
42
|
+
type: exports.TOK_REPEATABLE,
|
|
43
|
+
start: 0,
|
|
44
|
+
value: repeatableStartToken
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
exports.repeatable = repeatable;
|
|
52
48
|
const isAlphaNum = function (ch) {
|
|
53
49
|
return (ch >= 'a' && ch <= 'z')
|
|
54
50
|
|| (ch >= 'A' && ch <= 'Z')
|
|
@@ -58,6 +54,9 @@ const isAlphaNum = function (ch) {
|
|
|
58
54
|
const isGlobal = (prev, stream, pos) => {
|
|
59
55
|
return prev === null && stream[pos] === globalStartToken;
|
|
60
56
|
};
|
|
57
|
+
const isRepeatable = (prev, stream, pos) => {
|
|
58
|
+
return prev === null && stream[pos] === repeatableStartToken;
|
|
59
|
+
};
|
|
61
60
|
const isIdentifier = (stream, pos) => {
|
|
62
61
|
const ch = stream[pos];
|
|
63
62
|
if (ch === '$') {
|
|
@@ -71,17 +70,19 @@ const isNum = (ch) => {
|
|
|
71
70
|
return (ch >= '0' && ch <= '9');
|
|
72
71
|
};
|
|
73
72
|
class Tokenizer {
|
|
74
|
-
stream;
|
|
75
|
-
_current;
|
|
76
|
-
_tokens = [];
|
|
77
|
-
_result_tokens = [];
|
|
78
73
|
constructor(stream) {
|
|
79
74
|
this.stream = stream;
|
|
75
|
+
this._tokens = [];
|
|
76
|
+
this._result_tokens = [];
|
|
80
77
|
this._current = 0;
|
|
81
78
|
}
|
|
82
79
|
_consumeGlobal() {
|
|
83
80
|
this._current += 1;
|
|
84
|
-
return global$();
|
|
81
|
+
return (0, exports.global$)();
|
|
82
|
+
}
|
|
83
|
+
_consumeRepeatable() {
|
|
84
|
+
this._current += 1;
|
|
85
|
+
return (0, exports.repeatable)();
|
|
85
86
|
}
|
|
86
87
|
_consumeUnquotedIdentifier(stream) {
|
|
87
88
|
const start = this._current;
|
|
@@ -89,7 +90,7 @@ class Tokenizer {
|
|
|
89
90
|
while (this._current < stream.length && isAlphaNum(stream[this._current])) {
|
|
90
91
|
this._current += 1;
|
|
91
92
|
}
|
|
92
|
-
return identifier(stream.slice(start, this._current), start);
|
|
93
|
+
return (0, exports.identifier)(stream.slice(start, this._current), start);
|
|
93
94
|
}
|
|
94
95
|
_consumeQuotedIdentifier(stream) {
|
|
95
96
|
const start = this._current;
|
|
@@ -107,7 +108,7 @@ class Tokenizer {
|
|
|
107
108
|
this._current = current;
|
|
108
109
|
}
|
|
109
110
|
this._current += 1;
|
|
110
|
-
return identifier(JSON.parse(stream.slice(start, this._current)), start);
|
|
111
|
+
return (0, exports.identifier)(JSON.parse(stream.slice(start, this._current)), start);
|
|
111
112
|
}
|
|
112
113
|
_consumeNumber(stream) {
|
|
113
114
|
const start = this._current;
|
|
@@ -134,7 +135,7 @@ class Tokenizer {
|
|
|
134
135
|
throw new Error(`unexpected exception at position ${this._current}. Must be a character`);
|
|
135
136
|
}
|
|
136
137
|
this._current++;
|
|
137
|
-
return bracket(value, start);
|
|
138
|
+
return (0, exports.bracket)(value, start);
|
|
138
139
|
}
|
|
139
140
|
tokenize() {
|
|
140
141
|
const stream = this.stream;
|
|
@@ -145,6 +146,11 @@ class Tokenizer {
|
|
|
145
146
|
this._tokens.push(token);
|
|
146
147
|
this._result_tokens.push(token);
|
|
147
148
|
}
|
|
149
|
+
else if (isRepeatable(prev, stream, this._current)) {
|
|
150
|
+
const token = this._consumeRepeatable();
|
|
151
|
+
this._tokens.push(token);
|
|
152
|
+
this._result_tokens.push(token);
|
|
153
|
+
}
|
|
148
154
|
else if (isIdentifier(stream, this._current)) {
|
|
149
155
|
const token = this._consumeUnquotedIdentifier(stream);
|
|
150
156
|
this._tokens.push(token);
|
|
@@ -180,10 +186,11 @@ class Tokenizer {
|
|
|
180
186
|
const tokenize = (stream) => {
|
|
181
187
|
return new Tokenizer(stream).tokenize();
|
|
182
188
|
};
|
|
189
|
+
exports.tokenize = tokenize;
|
|
183
190
|
const resolveData = (data, input, create) => {
|
|
184
191
|
let tokens;
|
|
185
192
|
if (typeof input === 'string') {
|
|
186
|
-
tokens = tokenize(input);
|
|
193
|
+
tokens = (0, exports.tokenize)(input);
|
|
187
194
|
}
|
|
188
195
|
else {
|
|
189
196
|
tokens = input;
|
|
@@ -192,16 +199,16 @@ const resolveData = (data, input, create) => {
|
|
|
192
199
|
let i = 0;
|
|
193
200
|
const createIntermediateNode = (token, nextToken, create) => {
|
|
194
201
|
return nextToken === null ? create :
|
|
195
|
-
(nextToken.type === TOK_BRACKET) ? new
|
|
196
|
-
new
|
|
202
|
+
(nextToken.type === TOK_BRACKET) ? new DataGroup_1.default(token.value, [], 'array') :
|
|
203
|
+
new DataGroup_1.default(token.value, {});
|
|
197
204
|
};
|
|
198
205
|
while (i < tokens.length && result != null) {
|
|
199
206
|
const token = tokens[i];
|
|
200
|
-
if (token.type === TOK_GLOBAL) {
|
|
207
|
+
if (token.type === exports.TOK_GLOBAL) {
|
|
201
208
|
result = data;
|
|
202
209
|
}
|
|
203
210
|
else if (token.type === TOK_IDENTIFIER) {
|
|
204
|
-
if (result instanceof
|
|
211
|
+
if (result instanceof DataGroup_1.default && result.$type === 'object') {
|
|
205
212
|
if (result.$containsDataNode(token.value) && result.$getDataNode(token.value).$value !== null) {
|
|
206
213
|
result = result.$getDataNode(token.value);
|
|
207
214
|
}
|
|
@@ -220,7 +227,7 @@ const resolveData = (data, input, create) => {
|
|
|
220
227
|
}
|
|
221
228
|
}
|
|
222
229
|
else if (token.type === TOK_BRACKET) {
|
|
223
|
-
if (result instanceof
|
|
230
|
+
if (result instanceof DataGroup_1.default && result.$type === 'array') {
|
|
224
231
|
const index = token.value;
|
|
225
232
|
if (index < result.$length) {
|
|
226
233
|
result = result.$getDataNode(index);
|
|
@@ -243,5 +250,4 @@ const resolveData = (data, input, create) => {
|
|
|
243
250
|
}
|
|
244
251
|
return result;
|
|
245
252
|
};
|
|
246
|
-
|
|
247
|
-
export { TOK_GLOBAL, bracket, global$, identifier, resolveData, tokenize };
|
|
253
|
+
exports.resolveData = resolveData;
|
|
@@ -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
|
|
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
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
|
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 {
|
|
43
|
+
return Object.assign(Object.assign({}, x), { 'dataRef': dataRef });
|
|
56
44
|
});
|
|
57
45
|
}
|
|
58
46
|
else if (item.value != null) {
|
|
59
|
-
ret[item.id] = {
|
|
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
|
|
148
|
-
const result = dataURItoBlob(jFile
|
|
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
|
|
153
|
-
mediaType: jFile
|
|
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
|
|
171
|
-
mediaType: jFile
|
|
172
|
-
size: jFile
|
|
173
|
-
data: jFile
|
|
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
|
-
|
|
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
|
|
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;
|