@formio/js 5.0.0-dev.5610.11a9aca → 5.0.0-dev.5610.da13e39
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/dist/formio.form.js +10 -10
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.full.js +10 -10
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.utils.js +9 -9
- package/dist/formio.utils.min.js +1 -1
- package/lib/cjs/Element.d.ts +3 -2
- package/lib/cjs/Element.js +4 -3
- package/lib/cjs/utils/Evaluator.d.ts +0 -1
- package/lib/cjs/utils/Evaluator.js +2 -5
- package/lib/cjs/utils/utils.d.ts +3 -2
- package/lib/cjs/utils/utils.js +4 -57
- package/lib/mjs/Element.d.ts +3 -2
- package/lib/mjs/Element.js +4 -3
- package/lib/mjs/utils/Evaluator.d.ts +0 -1
- package/lib/mjs/utils/Evaluator.js +1 -4
- package/lib/mjs/utils/utils.d.ts +3 -2
- package/lib/mjs/utils/utils.js +4 -57
- package/package.json +2 -2
package/lib/cjs/Element.d.ts
CHANGED
|
@@ -233,10 +233,11 @@ export default class Element {
|
|
|
233
233
|
* @param {string|Function|object} func - The function or string to evaluate.
|
|
234
234
|
* @param {object} args - The arguments to pass to the evaluation.
|
|
235
235
|
* @param {string} ret - The name of the variable within the evaluation context to return.
|
|
236
|
-
* @param {boolean}
|
|
236
|
+
* @param {boolean} interpolate - Determines if it should replace all {{ }} token references with actual data.
|
|
237
|
+
* @param {import('@formio/core').EvaluatorOptions} options - The options to pass to the evaluation.
|
|
237
238
|
* @returns {*} - The result of the evaluation.
|
|
238
239
|
*/
|
|
239
|
-
evaluate(func: string | Function | object, args: object, ret: string,
|
|
240
|
+
evaluate(func: string | Function | object, args: object, ret: string, interpolate: boolean, options?: import('@formio/core').EvaluatorOptions): any;
|
|
240
241
|
/**
|
|
241
242
|
* Allow for options to hook into the functionality of this renderer.
|
|
242
243
|
* @returns {*} - The result of the hook function.
|
package/lib/cjs/Element.js
CHANGED
|
@@ -563,11 +563,12 @@ class Element {
|
|
|
563
563
|
* @param {string|Function|object} func - The function or string to evaluate.
|
|
564
564
|
* @param {object} args - The arguments to pass to the evaluation.
|
|
565
565
|
* @param {string} ret - The name of the variable within the evaluation context to return.
|
|
566
|
-
* @param {boolean}
|
|
566
|
+
* @param {boolean} interpolate - Determines if it should replace all {{ }} token references with actual data.
|
|
567
|
+
* @param {import('@formio/core').EvaluatorOptions} options - The options to pass to the evaluation.
|
|
567
568
|
* @returns {*} - The result of the evaluation.
|
|
568
569
|
*/
|
|
569
|
-
evaluate(func, args, ret,
|
|
570
|
-
return FormioUtils.evaluate(func, this.evalContext(args), ret,
|
|
570
|
+
evaluate(func, args, ret, interpolate, options = {}) {
|
|
571
|
+
return FormioUtils.evaluate(func, this.evalContext(args), ret, interpolate, options);
|
|
571
572
|
}
|
|
572
573
|
/**
|
|
573
574
|
* Allow for options to hook into the functionality of this renderer.
|
|
@@ -7,7 +7,7 @@ exports.Evaluator = void 0;
|
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const string_hash_1 = __importDefault(require("string-hash"));
|
|
9
9
|
const utils_1 = require("@formio/core/utils");
|
|
10
|
-
class Evaluator extends utils_1.
|
|
10
|
+
class Evaluator extends utils_1.JSONLogicEvaluator {
|
|
11
11
|
static template(template, hash) {
|
|
12
12
|
hash = hash || (0, string_hash_1.default)(template);
|
|
13
13
|
if (Evaluator.cache[hash]) {
|
|
@@ -37,7 +37,7 @@ class Evaluator extends utils_1.Evaluator {
|
|
|
37
37
|
rawTemplate = String(rawTemplate);
|
|
38
38
|
let template;
|
|
39
39
|
if (Evaluator.noeval || options.noeval) {
|
|
40
|
-
return utils_1.
|
|
40
|
+
return utils_1.JSONLogicEvaluator.interpolateString(rawTemplate, data, _options);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
43
|
template = Evaluator.template(rawTemplate);
|
|
@@ -53,9 +53,6 @@ class Evaluator extends utils_1.Evaluator {
|
|
|
53
53
|
}
|
|
54
54
|
return template;
|
|
55
55
|
}
|
|
56
|
-
static evaluate(func, args) {
|
|
57
|
-
return Array.isArray(args) ? func(...args) : func(args);
|
|
58
|
-
}
|
|
59
56
|
}
|
|
60
57
|
exports.Evaluator = Evaluator;
|
|
61
58
|
Evaluator.cache = {};
|
package/lib/cjs/utils/utils.d.ts
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* @param {Function|string|object} func - The function to evaluate.
|
|
4
4
|
* @param {*} args - A map of arguments to pass to the function.
|
|
5
5
|
* @param {string} ret - The name of the "return" variable in the script.
|
|
6
|
-
* @param {boolean}
|
|
6
|
+
* @param {boolean} interpolate - True if the script should be interpolated before being executed.
|
|
7
|
+
* @param {import('@formio/core').EvaluatorOptions} options - The evaluator options.
|
|
7
8
|
* @returns {*} - The result of the evaluation.
|
|
8
9
|
*/
|
|
9
|
-
export function evaluate(func: Function | string | object, args: any, ret: string,
|
|
10
|
+
export function evaluate(func: Function | string | object, args: any, ret: string, interpolate: boolean, options?: import('@formio/core').EvaluatorOptions): any;
|
|
10
11
|
/**
|
|
11
12
|
* Returns a random compoennt ID.
|
|
12
13
|
* @returns {string} - A random component ID.
|
package/lib/cjs/utils/utils.js
CHANGED
|
@@ -83,65 +83,12 @@ function setPathToComponentAndPerentSchema(component) {
|
|
|
83
83
|
* @param {Function|string|object} func - The function to evaluate.
|
|
84
84
|
* @param {*} args - A map of arguments to pass to the function.
|
|
85
85
|
* @param {string} ret - The name of the "return" variable in the script.
|
|
86
|
-
* @param {boolean}
|
|
86
|
+
* @param {boolean} interpolate - True if the script should be interpolated before being executed.
|
|
87
|
+
* @param {import('@formio/core').EvaluatorOptions} options - The evaluator options.
|
|
87
88
|
* @returns {*} - The result of the evaluation.
|
|
88
89
|
*/
|
|
89
|
-
function evaluate(func, args, ret,
|
|
90
|
-
|
|
91
|
-
const component = args.component ? args.component : { key: 'unknown' };
|
|
92
|
-
if (!args.form && args.instance) {
|
|
93
|
-
args.form = lodash_1.default.get(args.instance, 'root._form', {});
|
|
94
|
-
}
|
|
95
|
-
const componentKey = component.key;
|
|
96
|
-
if (typeof func === 'string') {
|
|
97
|
-
if (ret) {
|
|
98
|
-
func += `;return ${ret}`;
|
|
99
|
-
}
|
|
100
|
-
if (tokenize) {
|
|
101
|
-
// Replace all {{ }} references with actual data.
|
|
102
|
-
func = func.replace(/({{\s+(.*)\s+}})/, (match, $1, $2) => {
|
|
103
|
-
if ($2.indexOf('data.') === 0) {
|
|
104
|
-
return lodash_1.default.get(args.data, $2.replace('data.', ''));
|
|
105
|
-
}
|
|
106
|
-
else if ($2.indexOf('row.') === 0) {
|
|
107
|
-
return lodash_1.default.get(args.row, $2.replace('row.', ''));
|
|
108
|
-
}
|
|
109
|
-
// Support legacy...
|
|
110
|
-
return lodash_1.default.get(args.data, $2);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
func = Evaluator_1.Evaluator.evaluator(func, args);
|
|
115
|
-
args = lodash_1.default.values(args);
|
|
116
|
-
}
|
|
117
|
-
catch (err) {
|
|
118
|
-
console.warn(`An error occured within the custom function for ${componentKey}`, err);
|
|
119
|
-
returnVal = null;
|
|
120
|
-
func = false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (typeof func === 'function') {
|
|
124
|
-
try {
|
|
125
|
-
returnVal = Evaluator_1.Evaluator.evaluate(func, args);
|
|
126
|
-
}
|
|
127
|
-
catch (err) {
|
|
128
|
-
returnVal = null;
|
|
129
|
-
console.warn(`An error occured within custom function for ${componentKey}`, err);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else if (typeof func === 'object') {
|
|
133
|
-
try {
|
|
134
|
-
returnVal = json_logic_js_1.default.apply(func, args);
|
|
135
|
-
}
|
|
136
|
-
catch (err) {
|
|
137
|
-
returnVal = null;
|
|
138
|
-
console.warn(`An error occured within custom function for ${componentKey}`, err);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else if (func) {
|
|
142
|
-
console.warn(`Unknown function type for ${componentKey}`);
|
|
143
|
-
}
|
|
144
|
-
return returnVal;
|
|
90
|
+
function evaluate(func, args, ret, interpolate, options = {}) {
|
|
91
|
+
return Evaluator_1.Evaluator.evaluate(func, args, ret, interpolate, undefined, options);
|
|
145
92
|
}
|
|
146
93
|
exports.evaluate = evaluate;
|
|
147
94
|
/**
|
package/lib/mjs/Element.d.ts
CHANGED
|
@@ -233,10 +233,11 @@ export default class Element {
|
|
|
233
233
|
* @param {string|Function|object} func - The function or string to evaluate.
|
|
234
234
|
* @param {object} args - The arguments to pass to the evaluation.
|
|
235
235
|
* @param {string} ret - The name of the variable within the evaluation context to return.
|
|
236
|
-
* @param {boolean}
|
|
236
|
+
* @param {boolean} interpolate - Determines if it should replace all {{ }} token references with actual data.
|
|
237
|
+
* @param {import('@formio/core').EvaluatorOptions} options - The options to pass to the evaluation.
|
|
237
238
|
* @returns {*} - The result of the evaluation.
|
|
238
239
|
*/
|
|
239
|
-
evaluate(func: string | Function | object, args: object, ret: string,
|
|
240
|
+
evaluate(func: string | Function | object, args: object, ret: string, interpolate: boolean, options?: import('@formio/core').EvaluatorOptions): any;
|
|
240
241
|
/**
|
|
241
242
|
* Allow for options to hook into the functionality of this renderer.
|
|
242
243
|
* @returns {*} - The result of the hook function.
|
package/lib/mjs/Element.js
CHANGED
|
@@ -532,11 +532,12 @@ export default class Element {
|
|
|
532
532
|
* @param {string|Function|object} func - The function or string to evaluate.
|
|
533
533
|
* @param {object} args - The arguments to pass to the evaluation.
|
|
534
534
|
* @param {string} ret - The name of the variable within the evaluation context to return.
|
|
535
|
-
* @param {boolean}
|
|
535
|
+
* @param {boolean} interpolate - Determines if it should replace all {{ }} token references with actual data.
|
|
536
|
+
* @param {import('@formio/core').EvaluatorOptions} options - The options to pass to the evaluation.
|
|
536
537
|
* @returns {*} - The result of the evaluation.
|
|
537
538
|
*/
|
|
538
|
-
evaluate(func, args, ret,
|
|
539
|
-
return FormioUtils.evaluate(func, this.evalContext(args), ret,
|
|
539
|
+
evaluate(func, args, ret, interpolate, options = {}) {
|
|
540
|
+
return FormioUtils.evaluate(func, this.evalContext(args), ret, interpolate, options);
|
|
540
541
|
}
|
|
541
542
|
/**
|
|
542
543
|
* Allow for options to hook into the functionality of this renderer.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import stringHash from 'string-hash';
|
|
3
|
-
import {
|
|
3
|
+
import { JSONLogicEvaluator as CoreEvaluator } from '@formio/core/utils';
|
|
4
4
|
export class Evaluator extends CoreEvaluator {
|
|
5
5
|
static cache = {};
|
|
6
6
|
static protectedEval = false;
|
|
@@ -50,7 +50,4 @@ export class Evaluator extends CoreEvaluator {
|
|
|
50
50
|
}
|
|
51
51
|
return template;
|
|
52
52
|
}
|
|
53
|
-
static evaluate(func, args) {
|
|
54
|
-
return Array.isArray(args) ? func(...args) : func(args);
|
|
55
|
-
}
|
|
56
53
|
}
|
package/lib/mjs/utils/utils.d.ts
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* @param {Function|string|object} func - The function to evaluate.
|
|
4
4
|
* @param {*} args - A map of arguments to pass to the function.
|
|
5
5
|
* @param {string} ret - The name of the "return" variable in the script.
|
|
6
|
-
* @param {boolean}
|
|
6
|
+
* @param {boolean} interpolate - True if the script should be interpolated before being executed.
|
|
7
|
+
* @param {import('@formio/core').EvaluatorOptions} options - The evaluator options.
|
|
7
8
|
* @returns {*} - The result of the evaluation.
|
|
8
9
|
*/
|
|
9
|
-
export function evaluate(func: Function | string | object, args: any, ret: string,
|
|
10
|
+
export function evaluate(func: Function | string | object, args: any, ret: string, interpolate: boolean, options?: import('@formio/core').EvaluatorOptions): any;
|
|
10
11
|
/**
|
|
11
12
|
* Returns a random compoennt ID.
|
|
12
13
|
* @returns {string} - A random component ID.
|
package/lib/mjs/utils/utils.js
CHANGED
|
@@ -46,65 +46,12 @@ function setPathToComponentAndPerentSchema(component) {
|
|
|
46
46
|
* @param {Function|string|object} func - The function to evaluate.
|
|
47
47
|
* @param {*} args - A map of arguments to pass to the function.
|
|
48
48
|
* @param {string} ret - The name of the "return" variable in the script.
|
|
49
|
-
* @param {boolean}
|
|
49
|
+
* @param {boolean} interpolate - True if the script should be interpolated before being executed.
|
|
50
|
+
* @param {import('@formio/core').EvaluatorOptions} options - The evaluator options.
|
|
50
51
|
* @returns {*} - The result of the evaluation.
|
|
51
52
|
*/
|
|
52
|
-
export function evaluate(func, args, ret,
|
|
53
|
-
|
|
54
|
-
const component = args.component ? args.component : { key: 'unknown' };
|
|
55
|
-
if (!args.form && args.instance) {
|
|
56
|
-
args.form = _.get(args.instance, 'root._form', {});
|
|
57
|
-
}
|
|
58
|
-
const componentKey = component.key;
|
|
59
|
-
if (typeof func === 'string') {
|
|
60
|
-
if (ret) {
|
|
61
|
-
func += `;return ${ret}`;
|
|
62
|
-
}
|
|
63
|
-
if (tokenize) {
|
|
64
|
-
// Replace all {{ }} references with actual data.
|
|
65
|
-
func = func.replace(/({{\s+(.*)\s+}})/, (match, $1, $2) => {
|
|
66
|
-
if ($2.indexOf('data.') === 0) {
|
|
67
|
-
return _.get(args.data, $2.replace('data.', ''));
|
|
68
|
-
}
|
|
69
|
-
else if ($2.indexOf('row.') === 0) {
|
|
70
|
-
return _.get(args.row, $2.replace('row.', ''));
|
|
71
|
-
}
|
|
72
|
-
// Support legacy...
|
|
73
|
-
return _.get(args.data, $2);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
func = Evaluator.evaluator(func, args);
|
|
78
|
-
args = _.values(args);
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
console.warn(`An error occured within the custom function for ${componentKey}`, err);
|
|
82
|
-
returnVal = null;
|
|
83
|
-
func = false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (typeof func === 'function') {
|
|
87
|
-
try {
|
|
88
|
-
returnVal = Evaluator.evaluate(func, args);
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
returnVal = null;
|
|
92
|
-
console.warn(`An error occured within custom function for ${componentKey}`, err);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else if (typeof func === 'object') {
|
|
96
|
-
try {
|
|
97
|
-
returnVal = jsonLogic.apply(func, args);
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
returnVal = null;
|
|
101
|
-
console.warn(`An error occured within custom function for ${componentKey}`, err);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else if (func) {
|
|
105
|
-
console.warn(`Unknown function type for ${componentKey}`);
|
|
106
|
-
}
|
|
107
|
-
return returnVal;
|
|
53
|
+
export function evaluate(func, args, ret, interpolate, options = {}) {
|
|
54
|
+
return Evaluator.evaluate(func, args, ret, interpolate, undefined, options);
|
|
108
55
|
}
|
|
109
56
|
/**
|
|
110
57
|
* Returns a random compoennt ID.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formio/js",
|
|
3
|
-
"version": "5.0.0-dev.5610.
|
|
3
|
+
"version": "5.0.0-dev.5610.da13e39",
|
|
4
4
|
"description": "JavaScript powered Forms with JSON Form Builder",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"@formio/bootstrap": "^3.0.0-rc.24",
|
|
83
83
|
"@formio/choices.js": "^10.2.1",
|
|
84
|
-
"@formio/core": "^2.1.0-dev.tt.
|
|
84
|
+
"@formio/core": "^2.1.0-dev.tt.12",
|
|
85
85
|
"@formio/text-mask-addons": "^3.8.0-formio.2",
|
|
86
86
|
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
|
|
87
87
|
"abortcontroller-polyfill": "^1.7.5",
|