@aemforms/af-core 0.22.18 → 0.22.20
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/browser/afb-events.js +151 -0
- package/lib/browser/afb-runtime.js +3620 -0
- package/lib/cjs/index.cjs +8886 -0
- package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +11 -68
- package/lib/{BaseNode.js → esm/BaseNode.js} +86 -182
- package/lib/esm/Checkbox.d.ts +79 -0
- package/lib/esm/Checkbox.js +27 -0
- package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
- package/lib/esm/CheckboxGroup.js +23 -0
- package/lib/esm/Container.d.ts +53 -0
- package/lib/{Container.js → esm/Container.js} +76 -124
- package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
- package/lib/esm/DateField.js +21 -0
- package/lib/{Field.d.ts → esm/Field.d.ts} +44 -98
- package/lib/{Field.js → esm/Field.js} +172 -206
- package/lib/esm/Fieldset.d.ts +16 -0
- package/lib/esm/Fieldset.js +45 -0
- package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
- package/lib/esm/FileObject.js +26 -0
- package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
- package/lib/esm/FileUpload.js +108 -0
- package/lib/esm/Form.d.ts +113 -0
- package/lib/esm/Form.js +176 -0
- package/lib/esm/FormInstance.d.ts +13 -0
- package/lib/esm/FormInstance.js +81 -0
- package/lib/esm/FormMetaData.d.ts +7 -0
- package/lib/esm/FormMetaData.js +10 -0
- package/lib/esm/InstanceManager.d.ts +9 -0
- package/lib/esm/InstanceManager.js +31 -0
- package/lib/esm/Node.d.ts +7 -0
- package/lib/esm/Node.js +16 -0
- package/lib/esm/Scriptable.d.ts +17 -0
- package/lib/{Scriptable.js → esm/Scriptable.js} +12 -55
- package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
- package/lib/{controller → esm/controller}/EventQueue.js +10 -26
- package/lib/esm/controller/Events.d.ts +85 -0
- package/lib/esm/controller/Events.js +149 -0
- package/lib/{controller → esm/controller}/Logger.d.ts +0 -6
- package/lib/{controller → esm/controller}/Logger.js +5 -11
- package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
- package/lib/{data → esm/data}/DataGroup.js +20 -35
- package/lib/{data → esm/data}/DataValue.d.ts +2 -8
- package/lib/esm/data/DataValue.js +46 -0
- package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
- package/lib/esm/data/EmptyDataValue.js +29 -0
- package/lib/esm/index.d.ts +21 -0
- package/lib/esm/index.js +21 -0
- package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +2 -24
- package/lib/{rules → esm/rules}/FunctionRuntime.js +44 -114
- package/lib/esm/rules/RuleEngine.d.ts +12 -0
- package/lib/esm/rules/RuleEngine.js +47 -0
- package/lib/{types → esm/types}/Json.d.ts +6 -22
- package/lib/esm/types/Json.js +7 -0
- package/lib/esm/types/Model.d.ts +131 -0
- package/lib/esm/types/Model.js +8 -0
- package/lib/esm/types/index.d.ts +2 -0
- package/lib/esm/types/index.js +2 -0
- package/lib/{utils → esm/utils}/DataRefParser.d.ts +2 -5
- package/lib/{utils → esm/utils}/DataRefParser.js +22 -49
- package/lib/{utils → esm/utils}/Fetch.d.ts +1 -0
- package/lib/esm/utils/Fetch.js +61 -0
- package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
- package/lib/esm/utils/FormCreationUtils.js +74 -0
- package/lib/esm/utils/FormUtils.d.ts +12 -0
- package/lib/esm/utils/FormUtils.js +187 -0
- package/lib/esm/utils/JsonUtils.d.ts +11 -0
- package/lib/esm/utils/JsonUtils.js +76 -0
- package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
- package/lib/esm/utils/LogUtils.js +6 -0
- package/lib/esm/utils/SchemaUtils.d.ts +3 -0
- package/lib/esm/utils/SchemaUtils.js +71 -0
- package/lib/esm/utils/TranslationUtils.d.ts +11 -0
- package/lib/esm/utils/TranslationUtils.js +115 -0
- package/lib/esm/utils/ValidationUtils.d.ts +19 -0
- package/lib/{utils → esm/utils}/ValidationUtils.js +29 -187
- package/package.json +17 -10
- package/lib/Checkbox.d.ts +0 -88
- package/lib/Checkbox.js +0 -49
- package/lib/CheckboxGroup.js +0 -43
- package/lib/Container.d.ts +0 -199
- package/lib/DateField.js +0 -35
- package/lib/Fieldset.d.ts +0 -34
- package/lib/Fieldset.js +0 -113
- package/lib/FileObject.js +0 -39
- package/lib/FileUpload.js +0 -155
- package/lib/Form.d.ts +0 -262
- package/lib/Form.js +0 -230
- package/lib/FormInstance.d.ts +0 -38
- package/lib/FormInstance.js +0 -119
- package/lib/FormMetaData.d.ts +0 -11
- package/lib/FormMetaData.js +0 -28
- package/lib/Node.d.ts +0 -12
- package/lib/Node.js +0 -27
- package/lib/Scriptable.d.ts +0 -31
- package/lib/controller/Controller.d.ts +0 -223
- package/lib/controller/Controller.js +0 -287
- package/lib/controller/index.d.ts +0 -1
- package/lib/controller/index.js +0 -24
- package/lib/data/DataValue.js +0 -52
- package/lib/data/EmptyDataValue.js +0 -46
- package/lib/index.d.ts +0 -28
- package/lib/index.js +0 -63
- package/lib/rules/RuleEngine.d.ts +0 -23
- package/lib/rules/RuleEngine.js +0 -62
- package/lib/types/Json.js +0 -19
- package/lib/types/Model.d.ts +0 -379
- package/lib/types/Model.js +0 -20
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -25
- package/lib/utils/Fetch.js +0 -29
- package/lib/utils/FormUtils.d.ts +0 -47
- package/lib/utils/FormUtils.js +0 -257
- package/lib/utils/JsonUtils.d.ts +0 -62
- package/lib/utils/JsonUtils.js +0 -143
- package/lib/utils/LogUtils.js +0 -17
- package/lib/utils/SchemaUtils.d.ts +0 -16
- package/lib/utils/SchemaUtils.js +0 -92
- package/lib/utils/TranslationUtils.d.ts +0 -41
- package/lib/utils/TranslationUtils.js +0 -185
- package/lib/utils/ValidationUtils.d.ts +0 -170
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default class DataValue {
|
|
2
|
+
$_name;
|
|
3
|
+
$_value;
|
|
4
|
+
$_type;
|
|
5
|
+
$_fields = [];
|
|
6
|
+
constructor($_name, $_value, $_type = typeof $_value) {
|
|
7
|
+
this.$_name = $_name;
|
|
8
|
+
this.$_value = $_value;
|
|
9
|
+
this.$_type = $_type;
|
|
10
|
+
}
|
|
11
|
+
valueOf() {
|
|
12
|
+
return this.$_value;
|
|
13
|
+
}
|
|
14
|
+
get $name() {
|
|
15
|
+
return this.$_name;
|
|
16
|
+
}
|
|
17
|
+
get $value() {
|
|
18
|
+
const enabled = this.$_fields.find(x => x.enabled !== false);
|
|
19
|
+
if (!enabled && this.$_fields.length) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return this.$_value;
|
|
23
|
+
}
|
|
24
|
+
setValue(typedValue, originalValue, fromField) {
|
|
25
|
+
this.$_value = typedValue;
|
|
26
|
+
this.$_fields.forEach(x => {
|
|
27
|
+
if (fromField !== x) {
|
|
28
|
+
x.value = originalValue;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
get $type() {
|
|
33
|
+
return this.$_type;
|
|
34
|
+
}
|
|
35
|
+
$bindToField(field) {
|
|
36
|
+
if (this.$_fields.indexOf(field) === -1) {
|
|
37
|
+
this.$_fields.push(field);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
$convertToDataValue() {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
get $isDataGroup() {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import DataValue from './DataValue.js';
|
|
2
|
+
const value = Symbol('NullValue');
|
|
3
|
+
class NullDataValueClass extends DataValue {
|
|
4
|
+
constructor() {
|
|
5
|
+
super('', value, 'null');
|
|
6
|
+
}
|
|
7
|
+
setValue() {
|
|
8
|
+
}
|
|
9
|
+
$bindToField() {
|
|
10
|
+
}
|
|
11
|
+
$length() {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
$convertToDataValue() {
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
$addDataNode() {
|
|
18
|
+
}
|
|
19
|
+
$removeDataNode() {
|
|
20
|
+
}
|
|
21
|
+
$getDataNode() {
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
$containsDataNode() {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const NullDataValue = new NullDataValueClass();
|
|
29
|
+
export default NullDataValue;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from './FormInstance.js';
|
|
2
|
+
export * from './types/index.js';
|
|
3
|
+
export * from './controller/Events.js';
|
|
4
|
+
export * from './utils/TranslationUtils.js';
|
|
5
|
+
export * from './utils/JsonUtils.js';
|
|
6
|
+
export * from './utils/SchemaUtils.js';
|
|
7
|
+
import { getFileSizeInBytes, extractFileInfo, isEmpty } from './utils/FormUtils.js';
|
|
8
|
+
import { BaseNode } from './BaseNode.js';
|
|
9
|
+
import Checkbox from './Checkbox.js';
|
|
10
|
+
import CheckboxGroup from './CheckboxGroup.js';
|
|
11
|
+
import Container from './Container.js';
|
|
12
|
+
import Field from './Field.js';
|
|
13
|
+
import { Fieldset } from './Fieldset.js';
|
|
14
|
+
import { FileObject } from './FileObject.js';
|
|
15
|
+
import FileUpload from './FileUpload.js';
|
|
16
|
+
import FormMetaData from './FormMetaData.js';
|
|
17
|
+
import Node from './Node.js';
|
|
18
|
+
import Scriptable from './Scriptable.js';
|
|
19
|
+
import Form from './Form.js';
|
|
20
|
+
import { FunctionRuntime, request } from './rules/FunctionRuntime.js';
|
|
21
|
+
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, FunctionRuntime, request, isEmpty };
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from './FormInstance.js';
|
|
2
|
+
export * from './types/index.js';
|
|
3
|
+
export * from './controller/Events.js';
|
|
4
|
+
export * from './utils/TranslationUtils.js';
|
|
5
|
+
export * from './utils/JsonUtils.js';
|
|
6
|
+
export * from './utils/SchemaUtils.js';
|
|
7
|
+
import { getFileSizeInBytes, extractFileInfo, isEmpty } from './utils/FormUtils.js';
|
|
8
|
+
import { BaseNode } from './BaseNode.js';
|
|
9
|
+
import Checkbox from './Checkbox.js';
|
|
10
|
+
import CheckboxGroup from './CheckboxGroup.js';
|
|
11
|
+
import Container from './Container.js';
|
|
12
|
+
import Field from './Field.js';
|
|
13
|
+
import { Fieldset } from './Fieldset.js';
|
|
14
|
+
import { FileObject } from './FileObject.js';
|
|
15
|
+
import FileUpload from './FileUpload.js';
|
|
16
|
+
import FormMetaData from './FormMetaData.js';
|
|
17
|
+
import Node from './Node.js';
|
|
18
|
+
import Scriptable from './Scriptable.js';
|
|
19
|
+
import Form from './Form.js';
|
|
20
|
+
import { FunctionRuntime, request } from './rules/FunctionRuntime.js';
|
|
21
|
+
export { Form, BaseNode, Checkbox, CheckboxGroup, Container, Field, Fieldset, FileObject, FileUpload, FormMetaData, Node, Scriptable, getFileSizeInBytes, extractFileInfo, FunctionRuntime, request, isEmpty };
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
declare type HTTP_VERB = 'GET' | 'POST';
|
|
2
|
-
/**
|
|
3
|
-
* Implementation of generic request API. This API can be used to make external web request
|
|
4
|
-
* @param context expression execution context(consists of current form, current field, current event)
|
|
5
|
-
* @param uri request URI
|
|
6
|
-
* @param httpVerb http verb (for example, GET or POST)
|
|
7
|
-
* @param payload request payload
|
|
8
|
-
* @param success success handler
|
|
9
|
-
* @param error error handler
|
|
10
|
-
* @param headers headers
|
|
11
|
-
* @private
|
|
12
|
-
*/
|
|
13
2
|
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<void>;
|
|
14
3
|
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data', input_data?: any) => Promise<void>;
|
|
15
|
-
declare type CustomFunction = Function;
|
|
16
|
-
declare type FunctionDefinition = {
|
|
4
|
+
export declare type CustomFunction = Function;
|
|
5
|
+
export declare type FunctionDefinition = {
|
|
17
6
|
_func: CustomFunction;
|
|
18
7
|
_signature: Array<any>;
|
|
19
8
|
};
|
|
20
|
-
/**
|
|
21
|
-
* Implementation of function runtime
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
9
|
declare class FunctionRuntimeImpl {
|
|
25
10
|
private customFunctions;
|
|
26
11
|
registerFunctions(functions: {
|
|
@@ -56,13 +41,6 @@ declare class FunctionRuntimeImpl {
|
|
|
56
41
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
57
42
|
_signature: never[];
|
|
58
43
|
};
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
* @name dispatchEvent
|
|
62
|
-
* @param [element] element on which to trigger the event. If not defined the event will be triggered on entire form
|
|
63
|
-
* @param eventName name of the event to trigger
|
|
64
|
-
* @param payload payload to pass in the event
|
|
65
|
-
*/
|
|
66
44
|
dispatchEvent: {
|
|
67
45
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
68
46
|
_signature: never[];
|
|
@@ -1,31 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
-
*/
|
|
9
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
13
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
14
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
15
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.FunctionRuntime = exports.submit = exports.request = void 0;
|
|
20
|
-
/**
|
|
21
|
-
* Implementation of function runtime in rule engine
|
|
22
|
-
*/
|
|
23
|
-
//import {jsonString} from '../utils/JsonUtils';
|
|
24
|
-
const Controller_1 = require("../controller/Controller");
|
|
25
|
-
const Fetch_1 = require("../utils/Fetch");
|
|
26
|
-
const FileObject_1 = require("../FileObject");
|
|
27
|
-
const FormUtils_1 = require("../utils/FormUtils");
|
|
28
|
-
const JsonUtils_1 = require("../utils/JsonUtils");
|
|
1
|
+
import { AddInstance, AddItem, Change, Click, CustomEvent, RemoveInstance, RemoveItem, Reset, Submit } from '../controller/Events.js';
|
|
2
|
+
import { request as fRequest } from '../utils/Fetch.js';
|
|
3
|
+
import { FileObject } from '../FileObject.js';
|
|
4
|
+
import { getAttachments } from '../utils/FormUtils.js';
|
|
5
|
+
import { jsonString } from '../utils/JsonUtils.js';
|
|
29
6
|
const getCustomEventName = (name) => {
|
|
30
7
|
const eName = name;
|
|
31
8
|
if (eName.length > 0 && eName.startsWith('custom:')) {
|
|
@@ -33,19 +10,7 @@ const getCustomEventName = (name) => {
|
|
|
33
10
|
}
|
|
34
11
|
return eName;
|
|
35
12
|
};
|
|
36
|
-
|
|
37
|
-
* Implementation of generic request API. This API can be used to make external web request
|
|
38
|
-
* @param context expression execution context(consists of current form, current field, current event)
|
|
39
|
-
* @param uri request URI
|
|
40
|
-
* @param httpVerb http verb (for example, GET or POST)
|
|
41
|
-
* @param payload request payload
|
|
42
|
-
* @param success success handler
|
|
43
|
-
* @param error error handler
|
|
44
|
-
* @param headers headers
|
|
45
|
-
* @private
|
|
46
|
-
*/
|
|
47
|
-
const request = (context, uri, httpVerb, payload, success, error, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
-
var _a;
|
|
13
|
+
export const request = async (context, uri, httpVerb, payload, success, error, headers) => {
|
|
49
14
|
const endpoint = uri;
|
|
50
15
|
const requestOptions = {
|
|
51
16
|
method: httpVerb
|
|
@@ -53,8 +18,7 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
53
18
|
let result;
|
|
54
19
|
let inputPayload;
|
|
55
20
|
try {
|
|
56
|
-
if (payload && payload instanceof
|
|
57
|
-
// todo: have to implement array type
|
|
21
|
+
if (payload && payload instanceof FileObject && payload.data instanceof File) {
|
|
58
22
|
const formData = new FormData();
|
|
59
23
|
formData.append(payload.name, payload.data);
|
|
60
24
|
inputPayload = formData;
|
|
@@ -65,13 +29,15 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
65
29
|
else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
|
|
66
30
|
const headerNames = Object.keys(headers);
|
|
67
31
|
if (headerNames.length > 0) {
|
|
68
|
-
requestOptions.headers =
|
|
69
|
-
|
|
32
|
+
requestOptions.headers = {
|
|
33
|
+
...headers,
|
|
34
|
+
...(headerNames.indexOf('Content-Type') === -1 ? { 'Content-Type': 'application/json' } : {})
|
|
35
|
+
};
|
|
70
36
|
}
|
|
71
37
|
else {
|
|
72
38
|
requestOptions.headers = { 'Content-Type': 'application/json' };
|
|
73
39
|
}
|
|
74
|
-
const contentType =
|
|
40
|
+
const contentType = requestOptions?.headers?.['Content-Type'] || 'application/json';
|
|
75
41
|
if (contentType === 'application/json') {
|
|
76
42
|
inputPayload = JSON.stringify(payload);
|
|
77
43
|
}
|
|
@@ -82,24 +48,22 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
82
48
|
inputPayload = urlEncoded(payload);
|
|
83
49
|
}
|
|
84
50
|
}
|
|
85
|
-
result =
|
|
51
|
+
result = await fRequest(endpoint, inputPayload, requestOptions);
|
|
86
52
|
}
|
|
87
53
|
catch (e) {
|
|
88
|
-
//todo: define error payload
|
|
89
54
|
context.form.logger.error('Error invoking a rest API');
|
|
90
55
|
const eName = getCustomEventName(error);
|
|
91
|
-
context.form.dispatch(new
|
|
56
|
+
context.form.dispatch(new CustomEvent(eName, {}, true));
|
|
92
57
|
return;
|
|
93
58
|
}
|
|
94
59
|
const eName = getCustomEventName(success);
|
|
95
|
-
context.form.dispatch(new
|
|
96
|
-
}
|
|
97
|
-
exports.request = request;
|
|
60
|
+
context.form.dispatch(new CustomEvent(eName, result, true));
|
|
61
|
+
};
|
|
98
62
|
const urlEncoded = (data) => {
|
|
99
63
|
const formData = new URLSearchParams();
|
|
100
64
|
Object.entries(data).forEach(([key, value]) => {
|
|
101
65
|
if (value != null && typeof value === 'object') {
|
|
102
|
-
formData.append(key,
|
|
66
|
+
formData.append(key, jsonString(value));
|
|
103
67
|
}
|
|
104
68
|
else {
|
|
105
69
|
formData.append(key, value);
|
|
@@ -107,26 +71,19 @@ const urlEncoded = (data) => {
|
|
|
107
71
|
});
|
|
108
72
|
return formData;
|
|
109
73
|
};
|
|
110
|
-
/**
|
|
111
|
-
* Create multi part form data using form data and form attachments
|
|
112
|
-
* @param data form data
|
|
113
|
-
* @param attachments form events
|
|
114
|
-
* @private
|
|
115
|
-
*/
|
|
116
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
117
74
|
const multipartFormData = (data, attachments) => {
|
|
118
75
|
const formData = new FormData();
|
|
119
76
|
Object.entries(data).forEach(([key, value]) => {
|
|
120
77
|
if (value != null && typeof value === 'object') {
|
|
121
|
-
formData.append(key,
|
|
78
|
+
formData.append(key, jsonString(value));
|
|
122
79
|
}
|
|
123
80
|
else {
|
|
124
81
|
formData.append(key, value);
|
|
125
82
|
}
|
|
126
83
|
});
|
|
127
84
|
const addAttachmentToFormData = (objValue, formData) => {
|
|
128
|
-
if (
|
|
129
|
-
let attIdentifier = `${objValue
|
|
85
|
+
if (objValue?.data instanceof File) {
|
|
86
|
+
let attIdentifier = `${objValue?.dataRef}/${objValue?.name}`;
|
|
130
87
|
if (!attIdentifier.startsWith('/')) {
|
|
131
88
|
attIdentifier = `/${attIdentifier}`;
|
|
132
89
|
}
|
|
@@ -134,7 +91,6 @@ const multipartFormData = (data, attachments) => {
|
|
|
134
91
|
}
|
|
135
92
|
};
|
|
136
93
|
if (attachments) {
|
|
137
|
-
// @ts-ignore
|
|
138
94
|
Object.keys(attachments).reduce((acc, curr) => {
|
|
139
95
|
const objValue = attachments[curr];
|
|
140
96
|
if (objValue && objValue instanceof Array) {
|
|
@@ -147,69 +103,54 @@ const multipartFormData = (data, attachments) => {
|
|
|
147
103
|
}
|
|
148
104
|
return formData;
|
|
149
105
|
};
|
|
150
|
-
const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null) =>
|
|
106
|
+
export const submit = async (context, success, error, submitAs = 'multipart/form-data', input_data = null) => {
|
|
151
107
|
const endpoint = context.form.action;
|
|
152
108
|
let data = input_data;
|
|
153
109
|
if (typeof data != 'object' || data == null) {
|
|
154
110
|
data = context.form.exportData();
|
|
155
111
|
}
|
|
156
|
-
|
|
157
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
158
|
-
const attachments = (0, FormUtils_1.getAttachments)(context.form);
|
|
112
|
+
const attachments = getAttachments(context.form);
|
|
159
113
|
let submitContentType = submitAs;
|
|
160
|
-
|
|
114
|
+
const submitDataAndMetaData = { 'data': data, 'submitMetadata': { 'lang': context.form.lang } };
|
|
115
|
+
let formData = submitDataAndMetaData;
|
|
161
116
|
if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
|
|
162
|
-
formData = multipartFormData(
|
|
117
|
+
formData = multipartFormData(submitDataAndMetaData, attachments);
|
|
163
118
|
submitContentType = 'multipart/form-data';
|
|
164
119
|
}
|
|
165
|
-
|
|
166
|
-
formData = { 'data': data };
|
|
167
|
-
}
|
|
168
|
-
// submitContentType = submitAs;
|
|
169
|
-
// note: don't send multipart/form-data let browser decide on the content type
|
|
170
|
-
yield (0, exports.request)(context, endpoint, 'POST', formData, success, error, {
|
|
120
|
+
await request(context, endpoint, 'POST', formData, success, error, {
|
|
171
121
|
'Content-Type': submitContentType
|
|
172
122
|
});
|
|
173
|
-
}
|
|
174
|
-
exports.submit = submit;
|
|
175
|
-
/**
|
|
176
|
-
* Helper function to create an action
|
|
177
|
-
* @param name name of the event
|
|
178
|
-
* @param payload event payload
|
|
179
|
-
* @param dispatch true to trigger the event on all the fields in DFS order starting from the top level form element, false otherwise
|
|
180
|
-
* @private
|
|
181
|
-
*/
|
|
123
|
+
};
|
|
182
124
|
const createAction = (name, payload = {}) => {
|
|
183
125
|
switch (name) {
|
|
184
126
|
case 'change':
|
|
185
|
-
return new
|
|
127
|
+
return new Change(payload);
|
|
186
128
|
case 'submit':
|
|
187
|
-
return new
|
|
129
|
+
return new Submit(payload);
|
|
188
130
|
case 'click':
|
|
189
|
-
return new
|
|
131
|
+
return new Click(payload);
|
|
190
132
|
case 'addItem':
|
|
191
|
-
return new
|
|
133
|
+
return new AddItem(payload);
|
|
192
134
|
case 'removeItem':
|
|
193
|
-
return new
|
|
135
|
+
return new RemoveItem(payload);
|
|
136
|
+
case 'reset':
|
|
137
|
+
return new Reset(payload);
|
|
138
|
+
case 'addInstance':
|
|
139
|
+
return new AddInstance(payload);
|
|
140
|
+
case 'removeInstance':
|
|
141
|
+
return new RemoveInstance(payload);
|
|
194
142
|
default:
|
|
195
143
|
console.error('invalid action');
|
|
196
144
|
}
|
|
197
145
|
};
|
|
198
|
-
/**
|
|
199
|
-
* Implementation of function runtime
|
|
200
|
-
* @private
|
|
201
|
-
*/
|
|
202
146
|
class FunctionRuntimeImpl {
|
|
203
|
-
|
|
204
|
-
this.customFunctions = {};
|
|
205
|
-
}
|
|
147
|
+
customFunctions = {};
|
|
206
148
|
registerFunctions(functions) {
|
|
207
149
|
Object.entries(functions).forEach(([name, funcDef]) => {
|
|
208
150
|
let finalFunction = funcDef;
|
|
209
151
|
if (typeof funcDef === 'function') {
|
|
210
152
|
finalFunction = {
|
|
211
153
|
_func: (args) => {
|
|
212
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
213
154
|
return funcDef(...args);
|
|
214
155
|
},
|
|
215
156
|
_signature: []
|
|
@@ -230,7 +171,6 @@ class FunctionRuntimeImpl {
|
|
|
230
171
|
});
|
|
231
172
|
}
|
|
232
173
|
getFunctions() {
|
|
233
|
-
// todo: remove these once json-formula exposes a way to call them from custom functions
|
|
234
174
|
function isArray(obj) {
|
|
235
175
|
if (obj !== null) {
|
|
236
176
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
@@ -285,7 +225,6 @@ class FunctionRuntimeImpl {
|
|
|
285
225
|
},
|
|
286
226
|
getData: {
|
|
287
227
|
_func: (args, data, interpreter) => {
|
|
288
|
-
// deprecated. left for backward compatability.
|
|
289
228
|
interpreter.globals.form.logger.warn('The `getData` function is depricated. Use `exportData` instead.');
|
|
290
229
|
return interpreter.globals.form.exportData();
|
|
291
230
|
},
|
|
@@ -309,12 +248,11 @@ class FunctionRuntimeImpl {
|
|
|
309
248
|
},
|
|
310
249
|
submitForm: {
|
|
311
250
|
_func: (args, data, interpreter) => {
|
|
312
|
-
// success: string, error: string, submit_as: 'json' | 'multipart' = 'json', data: any = null
|
|
313
251
|
const success = toString(args[0]);
|
|
314
252
|
const error = toString(args[1]);
|
|
315
253
|
const submit_as = args.length > 2 ? toString(args[2]) : 'multipart/form-data';
|
|
316
254
|
const submit_data = args.length > 3 ? valueOf(args[3]) : null;
|
|
317
|
-
interpreter.globals.form.dispatch(new
|
|
255
|
+
interpreter.globals.form.dispatch(new Submit({
|
|
318
256
|
success,
|
|
319
257
|
error,
|
|
320
258
|
submit_as,
|
|
@@ -324,7 +262,6 @@ class FunctionRuntimeImpl {
|
|
|
324
262
|
},
|
|
325
263
|
_signature: []
|
|
326
264
|
},
|
|
327
|
-
// todo: only supports application/json for now
|
|
328
265
|
request: {
|
|
329
266
|
_func: (args, data, interpreter) => {
|
|
330
267
|
const uri = toString(args[0]);
|
|
@@ -341,18 +278,11 @@ class FunctionRuntimeImpl {
|
|
|
341
278
|
success = valueOf(args[4]);
|
|
342
279
|
error = valueOf(args[5]);
|
|
343
280
|
}
|
|
344
|
-
|
|
281
|
+
request(interpreter.globals, uri, httpVerb, payload, success, error, headers);
|
|
345
282
|
return {};
|
|
346
283
|
},
|
|
347
284
|
_signature: []
|
|
348
285
|
},
|
|
349
|
-
/**
|
|
350
|
-
*
|
|
351
|
-
* @name dispatchEvent
|
|
352
|
-
* @param [element] element on which to trigger the event. If not defined the event will be triggered on entire form
|
|
353
|
-
* @param eventName name of the event to trigger
|
|
354
|
-
* @param payload payload to pass in the event
|
|
355
|
-
*/
|
|
356
286
|
dispatchEvent: {
|
|
357
287
|
_func: (args, data, interpreter) => {
|
|
358
288
|
const element = args[0];
|
|
@@ -366,7 +296,7 @@ class FunctionRuntimeImpl {
|
|
|
366
296
|
}
|
|
367
297
|
let event;
|
|
368
298
|
if (eventName.startsWith('custom:')) {
|
|
369
|
-
event = new
|
|
299
|
+
event = new CustomEvent(eventName.substring('custom:'.length), payload, dispatch);
|
|
370
300
|
}
|
|
371
301
|
else {
|
|
372
302
|
event = createAction(eventName, payload);
|
|
@@ -384,7 +314,7 @@ class FunctionRuntimeImpl {
|
|
|
384
314
|
_signature: []
|
|
385
315
|
}
|
|
386
316
|
};
|
|
387
|
-
return
|
|
317
|
+
return { ...defaultFunctions, ...this.customFunctions };
|
|
388
318
|
}
|
|
389
319
|
}
|
|
390
|
-
|
|
320
|
+
export const FunctionRuntime = new FunctionRuntimeImpl();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseModel } from '../types/index.js';
|
|
2
|
+
declare class RuleEngine {
|
|
3
|
+
private _context;
|
|
4
|
+
private _globalNames;
|
|
5
|
+
private formulaEngine;
|
|
6
|
+
private debugInfo;
|
|
7
|
+
constructor();
|
|
8
|
+
compileRule(rule: string): any;
|
|
9
|
+
execute(node: any, data: any, globals: any, useValueOf?: boolean): any;
|
|
10
|
+
trackDependency(subscriber: BaseModel): void;
|
|
11
|
+
}
|
|
12
|
+
export default RuleEngine;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Formula from '@adobe/json-formula';
|
|
2
|
+
import { FunctionRuntime } from './FunctionRuntime.js';
|
|
3
|
+
class RuleEngine {
|
|
4
|
+
_context;
|
|
5
|
+
_globalNames = [
|
|
6
|
+
'$form',
|
|
7
|
+
'$field',
|
|
8
|
+
'$event'
|
|
9
|
+
];
|
|
10
|
+
formulaEngine;
|
|
11
|
+
debugInfo = [];
|
|
12
|
+
constructor() {
|
|
13
|
+
const customFunctions = FunctionRuntime.getFunctions();
|
|
14
|
+
this.formulaEngine = new Formula(customFunctions, undefined, this.debugInfo);
|
|
15
|
+
}
|
|
16
|
+
compileRule(rule) {
|
|
17
|
+
return this.formulaEngine.compile(rule, this._globalNames);
|
|
18
|
+
}
|
|
19
|
+
execute(node, data, globals, useValueOf = false) {
|
|
20
|
+
const oldContext = this._context;
|
|
21
|
+
this._context = globals;
|
|
22
|
+
let res = undefined;
|
|
23
|
+
try {
|
|
24
|
+
res = this.formulaEngine.run(node, data, 'en-US', globals);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
this._context?.form?.logger?.error(err);
|
|
28
|
+
}
|
|
29
|
+
while (this.debugInfo.length > 0) {
|
|
30
|
+
this._context?.form?.logger?.debug(this.debugInfo.pop());
|
|
31
|
+
}
|
|
32
|
+
let finalRes = res;
|
|
33
|
+
if (useValueOf) {
|
|
34
|
+
if (typeof res === 'object' && res !== null) {
|
|
35
|
+
finalRes = Object.getPrototypeOf(res).valueOf.call(res);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
this._context = oldContext;
|
|
39
|
+
return finalRes;
|
|
40
|
+
}
|
|
41
|
+
trackDependency(subscriber) {
|
|
42
|
+
if (this._context && this._context.field !== undefined && this._context.field !== subscriber) {
|
|
43
|
+
subscriber._addDependent(this._context.field);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export default RuleEngine;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines generic types based on `adaptive form specification`
|
|
3
|
-
*/
|
|
4
|
-
/** Type for `items property` based on `adaptive form specification` */
|
|
5
1
|
export declare type Items<T> = {
|
|
6
2
|
[key: string]: T;
|
|
7
3
|
};
|
|
8
|
-
/** Type alias for primitive types */
|
|
9
4
|
export declare type Primitives = string | number | boolean | null | undefined;
|
|
10
|
-
/** Type for `label` based on `adaptive form specification` */
|
|
11
5
|
export declare type Label = {
|
|
12
6
|
value: string;
|
|
13
7
|
richText?: boolean;
|
|
14
8
|
visible?: boolean;
|
|
15
9
|
};
|
|
16
|
-
/** Type for `constraint properties` which can be translated based on `adaptive form specification` */
|
|
17
10
|
declare type TranslationConstraintsJson = {
|
|
18
11
|
enumNames?: string[];
|
|
19
12
|
enum?: any[];
|
|
20
13
|
};
|
|
21
|
-
/** Type for `constraint properties` based on `adaptive form specification` */
|
|
22
14
|
export declare type ConstraintsJson = TranslationConstraintsJson & {
|
|
23
15
|
accept?: string[];
|
|
24
16
|
enforceEnum?: boolean;
|
|
@@ -29,6 +21,8 @@ export declare type ConstraintsJson = TranslationConstraintsJson & {
|
|
|
29
21
|
maxLength?: number;
|
|
30
22
|
maximum?: number;
|
|
31
23
|
maxItems?: number;
|
|
24
|
+
minOccur?: number;
|
|
25
|
+
maxOccur?: number;
|
|
32
26
|
minLength?: number;
|
|
33
27
|
minimum?: number;
|
|
34
28
|
minItems?: number;
|
|
@@ -39,7 +33,6 @@ export declare type ConstraintsJson = TranslationConstraintsJson & {
|
|
|
39
33
|
validationExpression?: string;
|
|
40
34
|
uniqueItems?: boolean;
|
|
41
35
|
};
|
|
42
|
-
/** Type for `constraint messages` based on `adaptive form specification` */
|
|
43
36
|
export declare type ConstraintsMessages = {
|
|
44
37
|
accept?: string;
|
|
45
38
|
enum?: string;
|
|
@@ -53,22 +46,20 @@ export declare type ConstraintsMessages = {
|
|
|
53
46
|
minLength?: string;
|
|
54
47
|
minimum?: string;
|
|
55
48
|
minItems?: string;
|
|
49
|
+
uniqueItems?: string;
|
|
56
50
|
pattern?: string;
|
|
57
51
|
required?: string;
|
|
58
52
|
step?: string;
|
|
59
53
|
type?: string;
|
|
60
54
|
validationExpression?: string;
|
|
61
55
|
};
|
|
62
|
-
/** Type for `constraint messages` based on `adaptive form specification` */
|
|
63
56
|
export declare type RulesJson = {
|
|
64
57
|
rules?: Items<string>;
|
|
65
58
|
events?: Items<string[] | string | undefined>;
|
|
66
59
|
};
|
|
67
|
-
/** Type for `generic form properties` which can be translated based on `adaptive form specification` */
|
|
68
60
|
declare type TranslationBaseJson = {
|
|
69
61
|
description?: string;
|
|
70
62
|
};
|
|
71
|
-
/** Type for `generic form properties` based on `adaptive form specification` */
|
|
72
63
|
export declare type BaseJson = TranslationBaseJson & RulesJson & ConstraintsJson & {
|
|
73
64
|
dataRef?: string | null;
|
|
74
65
|
':type'?: string;
|
|
@@ -82,15 +73,15 @@ export declare type BaseJson = TranslationBaseJson & RulesJson & ConstraintsJson
|
|
|
82
73
|
properties?: {
|
|
83
74
|
[key: string]: any;
|
|
84
75
|
};
|
|
76
|
+
repeatable?: boolean;
|
|
85
77
|
screenReaderText?: string;
|
|
86
78
|
tooltip?: string;
|
|
87
79
|
altText?: string;
|
|
80
|
+
viewType?: string;
|
|
88
81
|
};
|
|
89
|
-
/** Type for `form field properties`which can be translated based on `adaptive form specification` */
|
|
90
82
|
declare type TranslationFieldJson = {
|
|
91
83
|
placeholder?: string;
|
|
92
84
|
};
|
|
93
|
-
/** Type for `form field properties` based on `adaptive form specification` */
|
|
94
85
|
export declare type FieldJson = BaseJson & TranslationFieldJson & {
|
|
95
86
|
readOnly?: boolean;
|
|
96
87
|
valid?: boolean;
|
|
@@ -102,34 +93,27 @@ export declare type FieldJson = BaseJson & TranslationFieldJson & {
|
|
|
102
93
|
displayValue?: string;
|
|
103
94
|
emptyValue?: 'null' | 'undefined' | '';
|
|
104
95
|
};
|
|
105
|
-
/** Type for `form container properties` based on `adaptive form specification` */
|
|
106
96
|
export declare type ContainerJson = BaseJson & {
|
|
107
97
|
items: Array<FieldJson | ContainerJson>;
|
|
108
98
|
initialItems?: number;
|
|
109
99
|
activeChild?: string;
|
|
110
100
|
};
|
|
111
|
-
/** Type for `form metadata` based on `adaptive form specification` */
|
|
112
101
|
export declare type MetaDataJson = {
|
|
113
102
|
version?: string;
|
|
114
103
|
grammar?: string;
|
|
115
|
-
locale?: string;
|
|
116
104
|
};
|
|
117
|
-
/** Type for `form fieldset` based on `adaptive form specification` */
|
|
118
105
|
export declare type FieldsetJson = ContainerJson & {
|
|
119
106
|
'type'?: 'array' | 'object';
|
|
120
107
|
};
|
|
121
|
-
/** Type for `form model` based on `adaptive form specification` */
|
|
122
108
|
export declare type FormJson = ContainerJson & {
|
|
123
109
|
metadata?: MetaDataJson;
|
|
124
110
|
data?: any;
|
|
125
111
|
title?: string;
|
|
126
112
|
action?: string;
|
|
127
113
|
adaptiveForm?: string;
|
|
114
|
+
lang?: string;
|
|
128
115
|
};
|
|
129
|
-
/** Type for all properties which can be translated based on `adaptive form specification` */
|
|
130
116
|
export declare type TranslationJson = TranslationBaseJson & TranslationFieldJson & TranslationConstraintsJson;
|
|
131
|
-
/** Constant for all properties which can be translated based on `adaptive form specification` */
|
|
132
117
|
export declare const translationProps: string[];
|
|
133
|
-
/** Constant for all properties which are constraints based on `adaptive form specification` */
|
|
134
118
|
export declare const constraintProps: string[];
|
|
135
119
|
export {};
|