@aemforms/af-core 0.22.19 → 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} +10 -69
- package/lib/{BaseNode.js → esm/BaseNode.js} +84 -184
- 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/{Container.d.ts → esm/Container.d.ts} +12 -59
- package/lib/{Container.js → esm/Container.js} +54 -116
- 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} +39 -104
- package/lib/{Field.js → esm/Field.js} +142 -208
- 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/{Form.d.ts → esm/Form.d.ts} +19 -85
- 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} +11 -54
- 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 +15 -34
- package/lib/{data → esm/data}/DataValue.d.ts +1 -7
- 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 +41 -117
- 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 +3 -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 +0 -6
- 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/DateField.js +0 -35
- package/lib/Fieldset.d.ts +0 -24
- package/lib/Fieldset.js +0 -74
- package/lib/FileObject.js +0 -39
- package/lib/FileUpload.js +0 -155
- package/lib/Form.js +0 -252
- package/lib/FormInstance.d.ts +0 -38
- package/lib/FormInstance.js +0 -127
- package/lib/FormMetaData.d.ts +0 -11
- package/lib/FormMetaData.js +0 -28
- package/lib/InstanceManager.d.ts +0 -16
- package/lib/InstanceManager.js +0 -53
- 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 -255
- package/lib/controller/Controller.js +0 -328
- package/lib/controller/index.d.ts +0 -1
- package/lib/controller/index.js +0 -24
- package/lib/data/DataValue.js +0 -56
- 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 -393
- 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 -87
- package/lib/utils/FormCreationUtils.d.ts +0 -11
- package/lib/utils/FormCreationUtils.js +0 -83
- package/lib/utils/FormUtils.d.ts +0 -47
- package/lib/utils/FormUtils.js +0 -257
- package/lib/utils/JsonUtils.d.ts +0 -63
- package/lib/utils/JsonUtils.js +0 -157
- 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,75 +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);
|
|
194
136
|
case 'reset':
|
|
195
|
-
return new
|
|
137
|
+
return new Reset(payload);
|
|
196
138
|
case 'addInstance':
|
|
197
|
-
return new
|
|
139
|
+
return new AddInstance(payload);
|
|
198
140
|
case 'removeInstance':
|
|
199
|
-
return new
|
|
141
|
+
return new RemoveInstance(payload);
|
|
200
142
|
default:
|
|
201
143
|
console.error('invalid action');
|
|
202
144
|
}
|
|
203
145
|
};
|
|
204
|
-
/**
|
|
205
|
-
* Implementation of function runtime
|
|
206
|
-
* @private
|
|
207
|
-
*/
|
|
208
146
|
class FunctionRuntimeImpl {
|
|
209
|
-
|
|
210
|
-
this.customFunctions = {};
|
|
211
|
-
}
|
|
147
|
+
customFunctions = {};
|
|
212
148
|
registerFunctions(functions) {
|
|
213
149
|
Object.entries(functions).forEach(([name, funcDef]) => {
|
|
214
150
|
let finalFunction = funcDef;
|
|
215
151
|
if (typeof funcDef === 'function') {
|
|
216
152
|
finalFunction = {
|
|
217
153
|
_func: (args) => {
|
|
218
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
219
154
|
return funcDef(...args);
|
|
220
155
|
},
|
|
221
156
|
_signature: []
|
|
@@ -236,7 +171,6 @@ class FunctionRuntimeImpl {
|
|
|
236
171
|
});
|
|
237
172
|
}
|
|
238
173
|
getFunctions() {
|
|
239
|
-
// todo: remove these once json-formula exposes a way to call them from custom functions
|
|
240
174
|
function isArray(obj) {
|
|
241
175
|
if (obj !== null) {
|
|
242
176
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
@@ -291,7 +225,6 @@ class FunctionRuntimeImpl {
|
|
|
291
225
|
},
|
|
292
226
|
getData: {
|
|
293
227
|
_func: (args, data, interpreter) => {
|
|
294
|
-
// deprecated. left for backward compatability.
|
|
295
228
|
interpreter.globals.form.logger.warn('The `getData` function is depricated. Use `exportData` instead.');
|
|
296
229
|
return interpreter.globals.form.exportData();
|
|
297
230
|
},
|
|
@@ -315,12 +248,11 @@ class FunctionRuntimeImpl {
|
|
|
315
248
|
},
|
|
316
249
|
submitForm: {
|
|
317
250
|
_func: (args, data, interpreter) => {
|
|
318
|
-
// success: string, error: string, submit_as: 'json' | 'multipart' = 'json', data: any = null
|
|
319
251
|
const success = toString(args[0]);
|
|
320
252
|
const error = toString(args[1]);
|
|
321
253
|
const submit_as = args.length > 2 ? toString(args[2]) : 'multipart/form-data';
|
|
322
254
|
const submit_data = args.length > 3 ? valueOf(args[3]) : null;
|
|
323
|
-
interpreter.globals.form.dispatch(new
|
|
255
|
+
interpreter.globals.form.dispatch(new Submit({
|
|
324
256
|
success,
|
|
325
257
|
error,
|
|
326
258
|
submit_as,
|
|
@@ -330,7 +262,6 @@ class FunctionRuntimeImpl {
|
|
|
330
262
|
},
|
|
331
263
|
_signature: []
|
|
332
264
|
},
|
|
333
|
-
// todo: only supports application/json for now
|
|
334
265
|
request: {
|
|
335
266
|
_func: (args, data, interpreter) => {
|
|
336
267
|
const uri = toString(args[0]);
|
|
@@ -347,18 +278,11 @@ class FunctionRuntimeImpl {
|
|
|
347
278
|
success = valueOf(args[4]);
|
|
348
279
|
error = valueOf(args[5]);
|
|
349
280
|
}
|
|
350
|
-
|
|
281
|
+
request(interpreter.globals, uri, httpVerb, payload, success, error, headers);
|
|
351
282
|
return {};
|
|
352
283
|
},
|
|
353
284
|
_signature: []
|
|
354
285
|
},
|
|
355
|
-
/**
|
|
356
|
-
*
|
|
357
|
-
* @name dispatchEvent
|
|
358
|
-
* @param [element] element on which to trigger the event. If not defined the event will be triggered on entire form
|
|
359
|
-
* @param eventName name of the event to trigger
|
|
360
|
-
* @param payload payload to pass in the event
|
|
361
|
-
*/
|
|
362
286
|
dispatchEvent: {
|
|
363
287
|
_func: (args, data, interpreter) => {
|
|
364
288
|
const element = args[0];
|
|
@@ -372,7 +296,7 @@ class FunctionRuntimeImpl {
|
|
|
372
296
|
}
|
|
373
297
|
let event;
|
|
374
298
|
if (eventName.startsWith('custom:')) {
|
|
375
|
-
event = new
|
|
299
|
+
event = new CustomEvent(eventName.substring('custom:'.length), payload, dispatch);
|
|
376
300
|
}
|
|
377
301
|
else {
|
|
378
302
|
event = createAction(eventName, payload);
|
|
@@ -390,7 +314,7 @@ class FunctionRuntimeImpl {
|
|
|
390
314
|
_signature: []
|
|
391
315
|
}
|
|
392
316
|
};
|
|
393
|
-
return
|
|
317
|
+
return { ...defaultFunctions, ...this.customFunctions };
|
|
394
318
|
}
|
|
395
319
|
}
|
|
396
|
-
|
|
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;
|
|
@@ -41,7 +33,6 @@ export declare type ConstraintsJson = TranslationConstraintsJson & {
|
|
|
41
33
|
validationExpression?: string;
|
|
42
34
|
uniqueItems?: boolean;
|
|
43
35
|
};
|
|
44
|
-
/** Type for `constraint messages` based on `adaptive form specification` */
|
|
45
36
|
export declare type ConstraintsMessages = {
|
|
46
37
|
accept?: string;
|
|
47
38
|
enum?: string;
|
|
@@ -55,22 +46,20 @@ export declare type ConstraintsMessages = {
|
|
|
55
46
|
minLength?: string;
|
|
56
47
|
minimum?: string;
|
|
57
48
|
minItems?: string;
|
|
49
|
+
uniqueItems?: string;
|
|
58
50
|
pattern?: string;
|
|
59
51
|
required?: string;
|
|
60
52
|
step?: string;
|
|
61
53
|
type?: string;
|
|
62
54
|
validationExpression?: string;
|
|
63
55
|
};
|
|
64
|
-
/** Type for `constraint messages` based on `adaptive form specification` */
|
|
65
56
|
export declare type RulesJson = {
|
|
66
57
|
rules?: Items<string>;
|
|
67
58
|
events?: Items<string[] | string | undefined>;
|
|
68
59
|
};
|
|
69
|
-
/** Type for `generic form properties` which can be translated based on `adaptive form specification` */
|
|
70
60
|
declare type TranslationBaseJson = {
|
|
71
61
|
description?: string;
|
|
72
62
|
};
|
|
73
|
-
/** Type for `generic form properties` based on `adaptive form specification` */
|
|
74
63
|
export declare type BaseJson = TranslationBaseJson & RulesJson & ConstraintsJson & {
|
|
75
64
|
dataRef?: string | null;
|
|
76
65
|
':type'?: string;
|
|
@@ -88,12 +77,11 @@ export declare type BaseJson = TranslationBaseJson & RulesJson & ConstraintsJson
|
|
|
88
77
|
screenReaderText?: string;
|
|
89
78
|
tooltip?: string;
|
|
90
79
|
altText?: string;
|
|
80
|
+
viewType?: string;
|
|
91
81
|
};
|
|
92
|
-
/** Type for `form field properties`which can be translated based on `adaptive form specification` */
|
|
93
82
|
declare type TranslationFieldJson = {
|
|
94
83
|
placeholder?: string;
|
|
95
84
|
};
|
|
96
|
-
/** Type for `form field properties` based on `adaptive form specification` */
|
|
97
85
|
export declare type FieldJson = BaseJson & TranslationFieldJson & {
|
|
98
86
|
readOnly?: boolean;
|
|
99
87
|
valid?: boolean;
|
|
@@ -105,34 +93,27 @@ export declare type FieldJson = BaseJson & TranslationFieldJson & {
|
|
|
105
93
|
displayValue?: string;
|
|
106
94
|
emptyValue?: 'null' | 'undefined' | '';
|
|
107
95
|
};
|
|
108
|
-
/** Type for `form container properties` based on `adaptive form specification` */
|
|
109
96
|
export declare type ContainerJson = BaseJson & {
|
|
110
97
|
items: Array<FieldJson | ContainerJson>;
|
|
111
98
|
initialItems?: number;
|
|
112
99
|
activeChild?: string;
|
|
113
100
|
};
|
|
114
|
-
/** Type for `form metadata` based on `adaptive form specification` */
|
|
115
101
|
export declare type MetaDataJson = {
|
|
116
102
|
version?: string;
|
|
117
103
|
grammar?: string;
|
|
118
|
-
locale?: string;
|
|
119
104
|
};
|
|
120
|
-
/** Type for `form fieldset` based on `adaptive form specification` */
|
|
121
105
|
export declare type FieldsetJson = ContainerJson & {
|
|
122
106
|
'type'?: 'array' | 'object';
|
|
123
107
|
};
|
|
124
|
-
/** Type for `form model` based on `adaptive form specification` */
|
|
125
108
|
export declare type FormJson = ContainerJson & {
|
|
126
109
|
metadata?: MetaDataJson;
|
|
127
110
|
data?: any;
|
|
128
111
|
title?: string;
|
|
129
112
|
action?: string;
|
|
130
113
|
adaptiveForm?: string;
|
|
114
|
+
lang?: string;
|
|
131
115
|
};
|
|
132
|
-
/** Type for all properties which can be translated based on `adaptive form specification` */
|
|
133
116
|
export declare type TranslationJson = TranslationBaseJson & TranslationFieldJson & TranslationConstraintsJson;
|
|
134
|
-
/** Constant for all properties which can be translated based on `adaptive form specification` */
|
|
135
117
|
export declare const translationProps: string[];
|
|
136
|
-
/** Constant for all properties which are constraints based on `adaptive form specification` */
|
|
137
118
|
export declare const constraintProps: string[];
|
|
138
119
|
export {};
|