@aemforms/af-core 0.22.15 → 0.22.17
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 +11 -0
- package/lib/BaseNode.js +51 -2
- package/lib/Checkbox.d.ts +8 -0
- package/lib/Container.d.ts +43 -7
- package/lib/Container.js +24 -0
- package/lib/Field.d.ts +12 -12
- package/lib/Field.js +33 -38
- package/lib/FileObject.d.ts +3 -2
- package/lib/FileObject.js +8 -2
- package/lib/FileUpload.d.ts +2 -12
- package/lib/FileUpload.js +25 -130
- package/lib/Form.d.ts +8 -18
- package/lib/Form.js +12 -35
- package/lib/FormInstance.d.ts +1 -1
- package/lib/FormInstance.js +3 -25
- package/lib/Scriptable.js +1 -1
- package/lib/controller/Controller.d.ts +1 -0
- package/lib/controller/Controller.js +3 -0
- package/lib/controller/EventQueue.d.ts +1 -1
- package/lib/controller/EventQueue.js +2 -2
- package/lib/controller/Logger.d.ts +17 -0
- package/lib/controller/Logger.js +36 -0
- package/lib/data/DataValue.d.ts +1 -1
- package/lib/data/DataValue.js +4 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +4 -1
- package/lib/rules/FunctionRuntime.d.ts +8 -4
- package/lib/rules/FunctionRuntime.js +85 -26
- package/lib/rules/RuleEngine.js +2 -5
- package/lib/types/Json.d.ts +1 -0
- package/lib/types/Model.d.ts +7 -2
- package/lib/utils/FormUtils.d.ts +4 -12
- package/lib/utils/FormUtils.js +56 -52
- package/lib/utils/ValidationUtils.d.ts +17 -0
- package/lib/utils/ValidationUtils.js +87 -11
- package/package.json +3 -2
package/lib/FileUpload.js
CHANGED
|
@@ -22,8 +22,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
const Controller_1 = require("./controller/Controller");
|
|
23
23
|
const Field_1 = __importDefault(require("./Field"));
|
|
24
24
|
const FormUtils_1 = require("./utils/FormUtils");
|
|
25
|
-
const ValidationUtils_1 = require("./utils/ValidationUtils");
|
|
26
25
|
const FileObject_1 = require("./FileObject");
|
|
26
|
+
const ValidationUtils_1 = require("./utils/ValidationUtils");
|
|
27
27
|
function addNameToDataURL(dataURL, name) {
|
|
28
28
|
return dataURL.replace(';base64', `;name=${encodeURIComponent(name)};base64`);
|
|
29
29
|
}
|
|
@@ -32,7 +32,7 @@ function processFiles(files) {
|
|
|
32
32
|
}
|
|
33
33
|
function processFile(file) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const { name, size,
|
|
35
|
+
const { name, size, type } = file;
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
37
37
|
const fileObj = yield new Promise((resolve, reject) => {
|
|
38
38
|
const reader = new FileReader();
|
|
@@ -40,7 +40,7 @@ function processFile(file) {
|
|
|
40
40
|
resolve(new FileObject_1.FileObject({
|
|
41
41
|
// @ts-ignore
|
|
42
42
|
data: addNameToDataURL(event.target.result, name),
|
|
43
|
-
|
|
43
|
+
type,
|
|
44
44
|
name,
|
|
45
45
|
size
|
|
46
46
|
}));
|
|
@@ -99,124 +99,23 @@ class FileUpload extends Field_1.default {
|
|
|
99
99
|
return acc;
|
|
100
100
|
}, {});
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
case 'string':
|
|
106
|
-
return { valid: true, value: value };
|
|
107
|
-
default:
|
|
108
|
-
return ValidationUtils_1.Constraints.type(type, value);
|
|
109
|
-
}
|
|
102
|
+
getInternalType() {
|
|
103
|
+
var _a;
|
|
104
|
+
return ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) ? 'file[]' : 'file';
|
|
110
105
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
let
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
accepts = Array.isArray(accepts) ? accepts : accepts.split(',');
|
|
118
|
-
accepts.forEach((accept) => {
|
|
119
|
-
const trimmedAccept = accept.trim();
|
|
120
|
-
const prefixAccept = trimmedAccept.split('/')[0];
|
|
121
|
-
const suffixAccept = trimmedAccept.split('.')[1];
|
|
122
|
-
if ((trimmedAccept.includes('*') && type.startsWith(prefixAccept)) ||
|
|
123
|
-
(trimmedAccept.includes('.') && type.endsWith(suffixAccept)) ||
|
|
124
|
-
(trimmedAccept === type)) {
|
|
125
|
-
validFileType = true;
|
|
106
|
+
getDataNodeValue(typedValue) {
|
|
107
|
+
var _a;
|
|
108
|
+
let dataNodeValue = typedValue;
|
|
109
|
+
if (dataNodeValue != null) {
|
|
110
|
+
if (this.type === 'string') {
|
|
111
|
+
dataNodeValue = (_a = dataNodeValue.data) === null || _a === void 0 ? void 0 : _a.toString();
|
|
126
112
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
acceptCheck(value) {
|
|
131
|
-
const tempValue = value instanceof Array ? value : [value];
|
|
132
|
-
const invalidFile = tempValue.some((file) => !this.checkFileType(file.type || file.mediaType));
|
|
133
|
-
return {
|
|
134
|
-
valid: !invalidFile,
|
|
135
|
-
value
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
get value() {
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
this.ruleEngine.trackDependency(this);
|
|
141
|
-
if (this._jsonModel.value === undefined) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
let val = this._jsonModel.value;
|
|
145
|
-
// always return file object irrespective of data schema
|
|
146
|
-
if (val != null) {
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
val = this.coerce((val instanceof Array ? val : [val])
|
|
149
|
-
.map(file => {
|
|
150
|
-
let retVal = file;
|
|
151
|
-
if (!(retVal instanceof FileObject_1.FileObject)) {
|
|
152
|
-
retVal = new FileObject_1.FileObject({
|
|
153
|
-
'name': file.name,
|
|
154
|
-
'mediaType': file.mediaType,
|
|
155
|
-
'size': file.size,
|
|
156
|
-
'data': file.data
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
// define serialization here
|
|
160
|
-
/*
|
|
161
|
-
Object.defineProperty(retVal, 'data', {
|
|
162
|
-
get: async function() {
|
|
163
|
-
if (file.data instanceof File) {
|
|
164
|
-
return processFile(file);
|
|
165
|
-
} else {
|
|
166
|
-
return file.data;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
*/
|
|
171
|
-
return retVal;
|
|
172
|
-
}));
|
|
173
|
-
}
|
|
174
|
-
return val;
|
|
175
|
-
}
|
|
176
|
-
set value(value) {
|
|
177
|
-
if (value !== undefined) {
|
|
178
|
-
// store file list here
|
|
179
|
-
const typeRes = this.typeCheck(value);
|
|
180
|
-
const acceptRes = this.acceptCheck(value);
|
|
181
|
-
let fileInfoPayload = (0, FormUtils_1.extractFileInfo)(value);
|
|
182
|
-
fileInfoPayload = this.coerce(fileInfoPayload);
|
|
183
|
-
const changes = this._setProperty('value', fileInfoPayload, false);
|
|
184
|
-
if (changes.length > 0) {
|
|
185
|
-
const dataNode = this.getDataNode();
|
|
186
|
-
if (typeof dataNode !== 'undefined') {
|
|
187
|
-
let val = this._jsonModel.value;
|
|
188
|
-
const retVal = (val instanceof Array ? val : [val]).map(file => {
|
|
189
|
-
if (this.type === 'file' || this.type === 'file[]') {
|
|
190
|
-
return file;
|
|
191
|
-
}
|
|
192
|
-
else if (this.type === 'string' || this.type === 'string[]') {
|
|
193
|
-
// @ts-ignore
|
|
194
|
-
return file.data.toString();
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
val = this.coerce(retVal);
|
|
198
|
-
if (dataNode !== undefined) {
|
|
199
|
-
dataNode.setValue(val, this._jsonModel.value);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
let updates;
|
|
203
|
-
if (typeRes.valid && acceptRes.valid) {
|
|
204
|
-
updates = this.evaluateConstraints();
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
const changes = {
|
|
208
|
-
'valid': typeRes.valid && acceptRes.valid,
|
|
209
|
-
'errorMessage': typeRes.valid && acceptRes.valid ? '' : this.getErrorMessage('type')
|
|
210
|
-
};
|
|
211
|
-
updates = this._applyUpdates(['valid', 'errorMessage'], changes);
|
|
212
|
-
}
|
|
213
|
-
if (updates.valid) {
|
|
214
|
-
this.triggerValidationEvent(updates);
|
|
215
|
-
}
|
|
216
|
-
const changeAction = new Controller_1.Change({ changes: changes.concat(Object.values(updates)) });
|
|
217
|
-
this.dispatch(changeAction);
|
|
113
|
+
else if (this.type === 'string[]') {
|
|
114
|
+
dataNodeValue = dataNodeValue instanceof Array ? dataNodeValue : [dataNodeValue];
|
|
115
|
+
dataNodeValue = dataNodeValue.map((_) => { var _a; return (_a = _ === null || _ === void 0 ? void 0 : _.data) === null || _a === void 0 ? void 0 : _a.toString(); });
|
|
218
116
|
}
|
|
219
117
|
}
|
|
118
|
+
return dataNodeValue;
|
|
220
119
|
}
|
|
221
120
|
_serialize() {
|
|
222
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -229,28 +128,24 @@ class FileUpload extends Field_1.default {
|
|
|
229
128
|
return filesInfo;
|
|
230
129
|
});
|
|
231
130
|
}
|
|
232
|
-
coerce(val) {
|
|
233
|
-
let retVal = val;
|
|
234
|
-
if ((this.type === 'string' || this.type === 'file') && retVal instanceof Array) {
|
|
235
|
-
// @ts-ignore
|
|
236
|
-
retVal = val[0];
|
|
237
|
-
}
|
|
238
|
-
return retVal;
|
|
239
|
-
}
|
|
240
131
|
importData(dataModel) {
|
|
241
132
|
this._bindToDataModel(dataModel);
|
|
242
133
|
const dataNode = this.getDataNode();
|
|
243
134
|
if (dataNode !== undefined) {
|
|
244
135
|
const value = dataNode === null || dataNode === void 0 ? void 0 : dataNode.$value;
|
|
245
|
-
let newValue = value;
|
|
246
136
|
// only if not undefined, proceed further
|
|
247
137
|
if (value != null) {
|
|
248
|
-
const
|
|
249
|
-
|
|
138
|
+
const res = ValidationUtils_1.Constraints.type(this.getInternalType(), value);
|
|
139
|
+
if (!res.valid) {
|
|
140
|
+
this.form.logger.error(`unable to bind ${this.name} to data`);
|
|
141
|
+
}
|
|
250
142
|
// is this needed ?
|
|
251
|
-
this.form.getEventQueue().queue(this, (0, Controller_1.propertyChange)('value',
|
|
143
|
+
this.form.getEventQueue().queue(this, (0, Controller_1.propertyChange)('value', res.value, this._jsonModel.value));
|
|
144
|
+
this._jsonModel.value = res.value;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this._jsonModel.value = null;
|
|
252
148
|
}
|
|
253
|
-
this._jsonModel.value = newValue;
|
|
254
149
|
}
|
|
255
150
|
}
|
|
256
151
|
}
|
package/lib/Form.d.ts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
1
|
import Container from './Container';
|
|
2
|
-
import { Action, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormJson, FormModel, Items } from './types';
|
|
2
|
+
import { Action, BaseModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormJson, FormModel, Items } from './types';
|
|
3
3
|
import FormMetaData from './FormMetaData';
|
|
4
4
|
import EventQueue from './controller/EventQueue';
|
|
5
|
+
import { Logger, LogLevel } from './controller/Logger';
|
|
5
6
|
import RuleEngine from './rules/RuleEngine';
|
|
6
|
-
declare type LogFunction = 'info' | 'warn' | 'error' | 'debug';
|
|
7
|
-
/**
|
|
8
|
-
* Logging levels.
|
|
9
|
-
*/
|
|
10
|
-
export declare type LogLevel = 'off' | LogFunction;
|
|
11
|
-
/**
|
|
12
|
-
* @private
|
|
13
|
-
*/
|
|
14
|
-
export declare class Logger {
|
|
15
|
-
debug(msg: string): void;
|
|
16
|
-
info(msg: string): void;
|
|
17
|
-
warn(msg: string): void;
|
|
18
|
-
error(msg: string): void;
|
|
19
|
-
log(msg: string, level: LogFunction): void;
|
|
20
|
-
private logLevel;
|
|
21
|
-
constructor(logLevel?: LogLevel);
|
|
22
|
-
}
|
|
23
7
|
/**
|
|
24
8
|
* Defines `form model` which implements {@link FormModel | form model}
|
|
25
9
|
*/
|
|
@@ -54,6 +38,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
54
38
|
protected _createChild(child: FieldsetJson | FieldJson): FieldModel | FieldsetModel;
|
|
55
39
|
importData(dataModel: any): void;
|
|
56
40
|
exportData(): any;
|
|
41
|
+
setFocus(field: BaseModel): void;
|
|
57
42
|
/**
|
|
58
43
|
* Returns the current state of the form
|
|
59
44
|
*
|
|
@@ -104,6 +89,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
104
89
|
} & {
|
|
105
90
|
items: (FieldJson | import("./types").ContainerJson)[];
|
|
106
91
|
initialItems?: number | undefined;
|
|
92
|
+
activeChild?: string | undefined;
|
|
107
93
|
} & {
|
|
108
94
|
metadata?: import("./types").MetaDataJson | undefined;
|
|
109
95
|
data?: any;
|
|
@@ -287,6 +273,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
287
273
|
} & {
|
|
288
274
|
items: (FieldJson | import("./types").ContainerJson)[];
|
|
289
275
|
initialItems?: number | undefined;
|
|
276
|
+
activeChild?: string | undefined;
|
|
290
277
|
} & {
|
|
291
278
|
id: string;
|
|
292
279
|
items: (({
|
|
@@ -381,9 +368,11 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
381
368
|
} & {
|
|
382
369
|
items: (FieldJson | import("./types").ContainerJson)[];
|
|
383
370
|
initialItems?: number | undefined;
|
|
371
|
+
activeChild?: string | undefined;
|
|
384
372
|
} & any))[];
|
|
385
373
|
}))[];
|
|
386
374
|
initialItems?: number | undefined;
|
|
375
|
+
activeChild?: string | undefined;
|
|
387
376
|
id: string;
|
|
388
377
|
})[];
|
|
389
378
|
id: string;
|
|
@@ -421,6 +410,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
421
410
|
*/
|
|
422
411
|
submit(action: Action, context: any): void;
|
|
423
412
|
getElement(id: string): FieldModel | FieldsetModel | this;
|
|
413
|
+
get qualifiedName(): string;
|
|
424
414
|
/**
|
|
425
415
|
* @private
|
|
426
416
|
*/
|
package/lib/Form.js
CHANGED
|
@@ -10,48 +10,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.Logger = void 0;
|
|
14
13
|
const Container_1 = __importDefault(require("./Container"));
|
|
15
14
|
const FormMetaData_1 = __importDefault(require("./FormMetaData"));
|
|
16
15
|
const Fieldset_1 = require("./Fieldset");
|
|
17
16
|
const EventQueue_1 = __importDefault(require("./controller/EventQueue"));
|
|
17
|
+
const Logger_1 = require("./controller/Logger");
|
|
18
18
|
const FormUtils_1 = require("./utils/FormUtils");
|
|
19
19
|
const DataGroup_1 = __importDefault(require("./data/DataGroup"));
|
|
20
20
|
const FunctionRuntime_1 = require("./rules/FunctionRuntime");
|
|
21
21
|
const controller_1 = require("./controller");
|
|
22
|
-
const levels = {
|
|
23
|
-
off: 0,
|
|
24
|
-
debug: 1,
|
|
25
|
-
info: 2,
|
|
26
|
-
warn: 3,
|
|
27
|
-
error: 4
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* @private
|
|
31
|
-
*/
|
|
32
|
-
class Logger {
|
|
33
|
-
constructor(logLevel = 'off') {
|
|
34
|
-
this.logLevel = levels[logLevel];
|
|
35
|
-
}
|
|
36
|
-
debug(msg) {
|
|
37
|
-
this.log(msg, 'debug');
|
|
38
|
-
}
|
|
39
|
-
info(msg) {
|
|
40
|
-
this.log(msg, 'info');
|
|
41
|
-
}
|
|
42
|
-
warn(msg) {
|
|
43
|
-
this.log(msg, 'warn');
|
|
44
|
-
}
|
|
45
|
-
error(msg) {
|
|
46
|
-
this.log(msg, 'error');
|
|
47
|
-
}
|
|
48
|
-
log(msg, level) {
|
|
49
|
-
if (this.logLevel !== 0 && this.logLevel <= levels[level]) {
|
|
50
|
-
console[level](msg);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.Logger = Logger;
|
|
55
22
|
/**
|
|
56
23
|
* Defines `form model` which implements {@link FormModel | form model}
|
|
57
24
|
*/
|
|
@@ -77,7 +44,7 @@ class Form extends Container_1.default {
|
|
|
77
44
|
*/
|
|
78
45
|
this._invalidFields = [];
|
|
79
46
|
this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
|
|
80
|
-
this._logger = new Logger(logLevel);
|
|
47
|
+
this._logger = new Logger_1.Logger(logLevel);
|
|
81
48
|
this.queueEvent(new controller_1.Initialize());
|
|
82
49
|
this.queueEvent(new controller_1.ExecuteRule());
|
|
83
50
|
this._ids = (0, FormUtils_1.IdGenerator)();
|
|
@@ -107,6 +74,13 @@ class Form extends Container_1.default {
|
|
|
107
74
|
var _a;
|
|
108
75
|
return (_a = this.getDataNode()) === null || _a === void 0 ? void 0 : _a.$value;
|
|
109
76
|
}
|
|
77
|
+
setFocus(field) {
|
|
78
|
+
const parent = field.parent;
|
|
79
|
+
const currentField = field;
|
|
80
|
+
while (parent != null && parent.activeChild != currentField) {
|
|
81
|
+
parent.activeChild = currentField;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
110
84
|
/**
|
|
111
85
|
* Returns the current state of the form
|
|
112
86
|
*
|
|
@@ -231,6 +205,9 @@ class Form extends Container_1.default {
|
|
|
231
205
|
}
|
|
232
206
|
return this._fields[id];
|
|
233
207
|
}
|
|
208
|
+
get qualifiedName() {
|
|
209
|
+
return '$form';
|
|
210
|
+
}
|
|
234
211
|
/**
|
|
235
212
|
* @private
|
|
236
213
|
*/
|
package/lib/FormInstance.d.ts
CHANGED
package/lib/FormInstance.js
CHANGED
|
@@ -6,39 +6,17 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
-
}
|
|
15
|
-
Object.defineProperty(o, k2, desc);
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
-
__setModuleDefault(result, mod);
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
32
9
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
11
|
};
|
|
35
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
13
|
exports.fetchForm = exports.validateFormData = exports.validateFormInstance = exports.createFormInstance = void 0;
|
|
37
|
-
const Form_1 =
|
|
14
|
+
const Form_1 = __importDefault(require("./Form"));
|
|
38
15
|
const JsonUtils_1 = require("./utils/JsonUtils");
|
|
39
16
|
const Fetch_1 = require("./utils/Fetch");
|
|
40
17
|
const RuleEngine_1 = __importDefault(require("./rules/RuleEngine"));
|
|
41
18
|
const EventQueue_1 = __importDefault(require("./controller/EventQueue"));
|
|
19
|
+
const Logger_1 = require("./controller/Logger");
|
|
42
20
|
/**
|
|
43
21
|
* Creates form instance using form model definition as per `adaptive form specification`
|
|
44
22
|
* @param formModel form model definition
|
|
@@ -52,7 +30,7 @@ const createFormInstance = (formModel, callback, logLevel = 'error', fModel = un
|
|
|
52
30
|
try {
|
|
53
31
|
let f = fModel;
|
|
54
32
|
if (f == null) {
|
|
55
|
-
f = new Form_1.default(Object.assign({}, formModel), new RuleEngine_1.default(), new EventQueue_1.default(new
|
|
33
|
+
f = new Form_1.default(Object.assign({}, formModel), new RuleEngine_1.default(), new EventQueue_1.default(new Logger_1.Logger(logLevel)), logLevel);
|
|
56
34
|
}
|
|
57
35
|
const formData = formModel === null || formModel === void 0 ? void 0 : formModel.data;
|
|
58
36
|
if (formData) {
|
package/lib/Scriptable.js
CHANGED
|
@@ -148,7 +148,7 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
148
148
|
if (node) {
|
|
149
149
|
updates = this.ruleEngine.execute(node, this.getExpressionScope(), context);
|
|
150
150
|
}
|
|
151
|
-
if (typeof updates !== 'undefined') {
|
|
151
|
+
if (typeof updates !== 'undefined' && updates != null) {
|
|
152
152
|
this.applyUpdates(updates);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -57,6 +57,7 @@ export declare class Change extends ActionImpl {
|
|
|
57
57
|
* @param [dispatch] true to trigger the event on all the fields in DFS order starting from the top level form element, false otherwise
|
|
58
58
|
*/
|
|
59
59
|
constructor(payload: ChangePayload, dispatch?: boolean);
|
|
60
|
+
withAdditionalChange(change: Change): Change;
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Implementation of `invalid` event. The invalid event is triggered when a Field’s value becomes invalid after a change event or whenever its value property change
|
|
@@ -60,6 +60,9 @@ class Change extends ActionImpl {
|
|
|
60
60
|
constructor(payload, dispatch = false) {
|
|
61
61
|
super(payload, 'change', { dispatch });
|
|
62
62
|
}
|
|
63
|
+
withAdditionalChange(change) {
|
|
64
|
+
return new Change(this.payload.changes.concat(change.payload.changes), this.metadata);
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
exports.Change = Change;
|
|
65
68
|
/**
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Action, BaseJson } from '../types';
|
|
5
5
|
import { BaseNode } from '../BaseNode';
|
|
6
|
-
import { Logger } from '
|
|
6
|
+
import { Logger } from './Logger';
|
|
7
7
|
/**
|
|
8
8
|
* Implementation of event queue. When a user event, like change or click, is captured the expression to be evaluated
|
|
9
9
|
* must be put in an Event Queue and then evaluated.
|
|
@@ -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
|
-
const
|
|
10
|
+
const Logger_1 = require("./Logger");
|
|
11
11
|
/**
|
|
12
12
|
* Implementation of event node
|
|
13
13
|
* @private
|
|
@@ -39,7 +39,7 @@ class EventNode {
|
|
|
39
39
|
* @private
|
|
40
40
|
*/
|
|
41
41
|
class EventQueue {
|
|
42
|
-
constructor(logger = new
|
|
42
|
+
constructor(logger = new Logger_1.Logger('off')) {
|
|
43
43
|
this.logger = logger;
|
|
44
44
|
this._isProcessing = false;
|
|
45
45
|
this._pendingEvents = [];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare type LogFunction = 'info' | 'warn' | 'error' | 'debug';
|
|
2
|
+
/**
|
|
3
|
+
* Logging levels.
|
|
4
|
+
*/
|
|
5
|
+
export declare type LogLevel = 'off' | LogFunction;
|
|
6
|
+
/**
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare class Logger {
|
|
10
|
+
debug(msg: string): void;
|
|
11
|
+
info(msg: string): void;
|
|
12
|
+
warn(msg: string): void;
|
|
13
|
+
error(msg: string): void;
|
|
14
|
+
log(msg: string, level: LogFunction): void;
|
|
15
|
+
private logLevel;
|
|
16
|
+
constructor(logLevel?: LogLevel);
|
|
17
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const levels = {
|
|
5
|
+
off: 0,
|
|
6
|
+
debug: 1,
|
|
7
|
+
info: 2,
|
|
8
|
+
warn: 3,
|
|
9
|
+
error: 4
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
class Logger {
|
|
15
|
+
constructor(logLevel = 'off') {
|
|
16
|
+
this.logLevel = levels[logLevel];
|
|
17
|
+
}
|
|
18
|
+
debug(msg) {
|
|
19
|
+
this.log(msg, 'debug');
|
|
20
|
+
}
|
|
21
|
+
info(msg) {
|
|
22
|
+
this.log(msg, 'info');
|
|
23
|
+
}
|
|
24
|
+
warn(msg) {
|
|
25
|
+
this.log(msg, 'warn');
|
|
26
|
+
}
|
|
27
|
+
error(msg) {
|
|
28
|
+
this.log(msg, 'error');
|
|
29
|
+
}
|
|
30
|
+
log(msg, level) {
|
|
31
|
+
if (this.logLevel !== 0 && this.logLevel <= levels[level]) {
|
|
32
|
+
console[level](msg);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.Logger = Logger;
|
package/lib/data/DataValue.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export default class DataValue {
|
|
|
14
14
|
valueOf(): any;
|
|
15
15
|
get $name(): string | number;
|
|
16
16
|
get $value(): any;
|
|
17
|
-
setValue(typedValue: any, originalValue: any): void;
|
|
17
|
+
setValue(typedValue: any, originalValue: any, fromField: FieldModel): void;
|
|
18
18
|
get $type(): string;
|
|
19
19
|
$bindToField(field: FieldModel): void;
|
|
20
20
|
$convertToDataValue(): DataValue;
|
package/lib/data/DataValue.js
CHANGED
|
@@ -26,10 +26,12 @@ class DataValue {
|
|
|
26
26
|
get $value() {
|
|
27
27
|
return this.$_value;
|
|
28
28
|
}
|
|
29
|
-
setValue(typedValue, originalValue) {
|
|
29
|
+
setValue(typedValue, originalValue, fromField) {
|
|
30
30
|
this.$_value = typedValue;
|
|
31
31
|
this.$_fields.forEach(x => {
|
|
32
|
-
x
|
|
32
|
+
if (fromField !== x) {
|
|
33
|
+
x.value = originalValue;
|
|
34
|
+
}
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
get $type() {
|
package/lib/index.d.ts
CHANGED
|
@@ -24,4 +24,5 @@ import FormMetaData from './FormMetaData';
|
|
|
24
24
|
import Node from './Node';
|
|
25
25
|
import Scriptable from './Scriptable';
|
|
26
26
|
import Form from './Form';
|
|
27
|
-
|
|
27
|
+
import { FunctionRuntime, request } from './rules/FunctionRuntime';
|
|
28
|
+
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, FunctionRuntime, request };
|
package/lib/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.extractFileInfo = exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
|
|
27
|
+
exports.request = exports.FunctionRuntime = exports.extractFileInfo = exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
|
|
28
28
|
__exportStar(require("./FormInstance"), exports);
|
|
29
29
|
__exportStar(require("./types/index"), exports);
|
|
30
30
|
__exportStar(require("./controller/index"), exports);
|
|
@@ -58,3 +58,6 @@ const Scriptable_1 = __importDefault(require("./Scriptable"));
|
|
|
58
58
|
exports.Scriptable = Scriptable_1.default;
|
|
59
59
|
const Form_1 = __importDefault(require("./Form"));
|
|
60
60
|
exports.Form = Form_1.default;
|
|
61
|
+
const FunctionRuntime_1 = require("./rules/FunctionRuntime");
|
|
62
|
+
Object.defineProperty(exports, "FunctionRuntime", { enumerable: true, get: function () { return FunctionRuntime_1.FunctionRuntime; } });
|
|
63
|
+
Object.defineProperty(exports, "request", { enumerable: true, get: function () { return FunctionRuntime_1.request; } });
|
|
@@ -7,10 +7,10 @@ declare type HTTP_VERB = 'GET' | 'POST';
|
|
|
7
7
|
* @param payload request payload
|
|
8
8
|
* @param success success handler
|
|
9
9
|
* @param error error handler
|
|
10
|
-
* @param
|
|
10
|
+
* @param headers headers
|
|
11
11
|
* @private
|
|
12
12
|
*/
|
|
13
|
-
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string,
|
|
13
|
+
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<void>;
|
|
14
14
|
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data', input_data?: any) => Promise<void>;
|
|
15
15
|
declare type CustomFunction = Function;
|
|
16
16
|
declare type FunctionDefinition = {
|
|
@@ -32,6 +32,10 @@ declare class FunctionRuntimeImpl {
|
|
|
32
32
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
|
|
33
33
|
_signature: never[];
|
|
34
34
|
};
|
|
35
|
+
setFocus: {
|
|
36
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => void;
|
|
37
|
+
_signature: never[];
|
|
38
|
+
};
|
|
35
39
|
getData: {
|
|
36
40
|
_func: (args: unknown, data: unknown, interpreter: any) => any;
|
|
37
41
|
_signature: never[];
|
|
@@ -65,5 +69,5 @@ declare class FunctionRuntimeImpl {
|
|
|
65
69
|
};
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
|
-
declare const FunctionRuntime: FunctionRuntimeImpl;
|
|
69
|
-
export
|
|
72
|
+
export declare const FunctionRuntime: FunctionRuntimeImpl;
|
|
73
|
+
export {};
|