@aemforms/af-core 0.22.64 → 0.22.65
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/DateField.d.ts +4 -0
- package/lib/DateField.js +21 -3
- package/lib/Form.d.ts +3 -1
- package/lib/Form.js +63 -6
- package/lib/Scriptable.js +3 -3
- package/lib/rules/FunctionRuntime.js +3 -2
- package/lib/rules/RuleEngine.d.ts +6 -2
- package/lib/rules/RuleEngine.js +14 -5
- package/lib/types/Model.d.ts +4 -0
- package/lib/types/Model.js +6 -1
- package/lib/utils/CoercionUtils.d.ts +1 -0
- package/lib/utils/CoercionUtils.js +21 -0
- package/package.json +2 -2
package/lib/DateField.d.ts
CHANGED
package/lib/DateField.js
CHANGED
|
@@ -6,9 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const Field_1 = __importDefault(require("./Field"));
|
|
7
7
|
const af_formatters_1 = require("@aemforms/af-formatters");
|
|
8
8
|
class DateField extends Field_1.default {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this._dataFormat = 'yyyy-MM-dd';
|
|
12
|
+
}
|
|
9
13
|
_applyDefaults() {
|
|
10
14
|
super._applyDefaults();
|
|
11
|
-
|
|
15
|
+
this.locale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
12
16
|
if (!this._jsonModel.editFormat) {
|
|
13
17
|
this._jsonModel.editFormat = 'short';
|
|
14
18
|
}
|
|
@@ -16,10 +20,24 @@ class DateField extends Field_1.default {
|
|
|
16
20
|
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
17
21
|
}
|
|
18
22
|
if (!this._jsonModel.placeholder) {
|
|
19
|
-
this._jsonModel.placeholder = (0, af_formatters_1.parseDateSkeleton)(this._jsonModel.editFormat, locale);
|
|
23
|
+
this._jsonModel.placeholder = (0, af_formatters_1.parseDateSkeleton)(this._jsonModel.editFormat, this.locale);
|
|
20
24
|
}
|
|
21
25
|
if (!this._jsonModel.description) {
|
|
22
|
-
this._jsonModel.description = `To enter today's date use ${(0, af_formatters_1.formatDate)(new Date(), locale, this._jsonModel.editFormat)}`;
|
|
26
|
+
this._jsonModel.description = `To enter today's date use ${(0, af_formatters_1.formatDate)(new Date(), this.locale, this._jsonModel.editFormat)}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
get value() {
|
|
30
|
+
return super.value;
|
|
31
|
+
}
|
|
32
|
+
set value(value) {
|
|
33
|
+
if (typeof value === 'number') {
|
|
34
|
+
const coercedValue = (0, af_formatters_1.numberToDatetime)(value);
|
|
35
|
+
if (!isNaN(coercedValue)) {
|
|
36
|
+
super.value = (0, af_formatters_1.formatDate)(coercedValue, this.locale, this._dataFormat);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
super.value = value;
|
|
23
41
|
}
|
|
24
42
|
}
|
|
25
43
|
}
|
package/lib/Form.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ import SubmitMetaData from './SubmitMetaData';
|
|
|
5
5
|
import EventQueue from './controller/EventQueue';
|
|
6
6
|
import { Logger, LogLevel } from './controller/Logger';
|
|
7
7
|
import RuleEngine from './rules/RuleEngine';
|
|
8
|
+
import { FocusOption } from './types/Model';
|
|
8
9
|
declare class Form extends Container<FormJson> implements FormModel {
|
|
10
|
+
#private;
|
|
9
11
|
private _ruleEngine;
|
|
10
12
|
private _eventQueue;
|
|
11
13
|
private _fields;
|
|
@@ -21,7 +23,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
21
23
|
exportData(): any;
|
|
22
24
|
resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
|
|
23
25
|
exportSubmitMetaData(): SubmitMetaData;
|
|
24
|
-
setFocus(field: BaseModel): void;
|
|
26
|
+
setFocus(field: BaseModel, focusOption: FocusOption): void;
|
|
25
27
|
getState(): {
|
|
26
28
|
description?: string | undefined;
|
|
27
29
|
} & import("./types/Json").RulesJson & {
|
package/lib/Form.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
2
7
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
9
|
};
|
|
10
|
+
var _Form_instances, _Form_getNavigableChildren, _Form_getFirstNavigableChild, _Form_setActiveFirstDeepChild, _Form_getNextItem, _Form_getPreviousItem;
|
|
5
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
12
|
const Container_1 = __importDefault(require("./Container"));
|
|
7
13
|
const FormMetaData_1 = __importDefault(require("./FormMetaData"));
|
|
@@ -12,11 +18,13 @@ const FormUtils_1 = require("./utils/FormUtils");
|
|
|
12
18
|
const DataGroup_1 = __importDefault(require("./data/DataGroup"));
|
|
13
19
|
const FunctionRuntime_1 = require("./rules/FunctionRuntime");
|
|
14
20
|
const Events_1 = require("./controller/Events");
|
|
21
|
+
const Model_1 = require("./types/Model");
|
|
15
22
|
class Form extends Container_1.default {
|
|
16
23
|
constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue_1.default(), logLevel = 'off') {
|
|
17
24
|
super(n, { fieldFactory: fieldFactory });
|
|
18
25
|
this._ruleEngine = _ruleEngine;
|
|
19
26
|
this._eventQueue = _eventQueue;
|
|
27
|
+
_Form_instances.add(this);
|
|
20
28
|
this._fields = {};
|
|
21
29
|
this._invalidFields = [];
|
|
22
30
|
this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
|
|
@@ -73,14 +81,35 @@ class Form extends Container_1.default {
|
|
|
73
81
|
submitMetaInstance = new SubmitMetaData_1.default(this.form.lang, captchaInfoObj);
|
|
74
82
|
return submitMetaInstance;
|
|
75
83
|
}
|
|
76
|
-
setFocus(field) {
|
|
77
|
-
const parent = field.parent;
|
|
84
|
+
setFocus(field, focusOption) {
|
|
85
|
+
const parent = (field.isContainer ? field : field.parent);
|
|
78
86
|
const currentField = field;
|
|
79
|
-
if (
|
|
80
|
-
|
|
87
|
+
if (focusOption && parent !== null) {
|
|
88
|
+
const navigableChidren = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getNavigableChildren).call(this, parent.items);
|
|
89
|
+
let activeChild = parent.activeChild;
|
|
90
|
+
let currActiveChildIndex = activeChild !== null ? navigableChidren.indexOf(activeChild) : -1;
|
|
91
|
+
if (parent.activeChild === null) {
|
|
92
|
+
parent.activeChild = navigableChidren[0];
|
|
93
|
+
currActiveChildIndex = 0;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (focusOption === Model_1.FocusOption.NEXT_ITEM) {
|
|
97
|
+
activeChild = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getNextItem).call(this, currActiveChildIndex, navigableChidren);
|
|
98
|
+
}
|
|
99
|
+
else if (focusOption === Model_1.FocusOption.PREVIOUS_ITEM) {
|
|
100
|
+
activeChild = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getPreviousItem).call(this, currActiveChildIndex, navigableChidren);
|
|
101
|
+
}
|
|
102
|
+
if (activeChild !== null) {
|
|
103
|
+
__classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, activeChild);
|
|
104
|
+
}
|
|
81
105
|
}
|
|
82
|
-
|
|
83
|
-
parent.activeChild
|
|
106
|
+
else {
|
|
107
|
+
if (parent != null && parent.activeChild != null) {
|
|
108
|
+
parent.activeChild = null;
|
|
109
|
+
}
|
|
110
|
+
while (parent != null && parent.activeChild != currentField) {
|
|
111
|
+
parent.activeChild = currentField;
|
|
112
|
+
}
|
|
84
113
|
}
|
|
85
114
|
}
|
|
86
115
|
getState() {
|
|
@@ -203,4 +232,32 @@ class Form extends Container_1.default {
|
|
|
203
232
|
return this._jsonModel.title || '';
|
|
204
233
|
}
|
|
205
234
|
}
|
|
235
|
+
_Form_instances = new WeakSet(), _Form_getNavigableChildren = function _Form_getNavigableChildren(children) {
|
|
236
|
+
return children.filter(child => child.visible === true);
|
|
237
|
+
}, _Form_getFirstNavigableChild = function _Form_getFirstNavigableChild(container) {
|
|
238
|
+
const navigableChidren = __classPrivateFieldGet(this, _Form_instances, "m", _Form_getNavigableChildren).call(this, container.items);
|
|
239
|
+
if (navigableChidren) {
|
|
240
|
+
return navigableChidren[0];
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
}, _Form_setActiveFirstDeepChild = function _Form_setActiveFirstDeepChild(currentField) {
|
|
244
|
+
if (!currentField.isContainer) {
|
|
245
|
+
const parent = currentField.parent;
|
|
246
|
+
parent.activeChild = currentField;
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
let currentActiveChild = currentField.activeChild;
|
|
250
|
+
currentActiveChild = (currentActiveChild === null) ? __classPrivateFieldGet(this, _Form_instances, "m", _Form_getFirstNavigableChild).call(this, currentField) : currentField.activeChild;
|
|
251
|
+
__classPrivateFieldGet(this, _Form_instances, "m", _Form_setActiveFirstDeepChild).call(this, currentActiveChild);
|
|
252
|
+
}, _Form_getNextItem = function _Form_getNextItem(currIndex, navigableChidren) {
|
|
253
|
+
if (currIndex < (navigableChidren.length - 1)) {
|
|
254
|
+
return navigableChidren[currIndex + 1];
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}, _Form_getPreviousItem = function _Form_getPreviousItem(currIndex, navigableChidren) {
|
|
258
|
+
if (currIndex > 0) {
|
|
259
|
+
return navigableChidren[currIndex - 1];
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
};
|
|
206
263
|
exports.default = Form;
|
package/lib/Scriptable.js
CHANGED
|
@@ -15,7 +15,7 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
15
15
|
const eString = rule || this.getRules()[eName];
|
|
16
16
|
if (typeof eString === 'string' && eString.length > 0) {
|
|
17
17
|
try {
|
|
18
|
-
this._rules[eName] = this.ruleEngine.compileRule(eString);
|
|
18
|
+
this._rules[eName] = this.ruleEngine.compileRule(eString, this.lang);
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
21
21
|
this.form.logger.error(`Unable to compile rule \`"${eName}" : "${eString}"\` Exception : ${e}`);
|
|
@@ -37,7 +37,7 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
37
37
|
if (typeof eString !== 'undefined' && eString.length > 0) {
|
|
38
38
|
this._events[eName] = eString.map(x => {
|
|
39
39
|
try {
|
|
40
|
-
return this.ruleEngine.compileRule(x);
|
|
40
|
+
return this.ruleEngine.compileRule(x, this.lang);
|
|
41
41
|
}
|
|
42
42
|
catch (e) {
|
|
43
43
|
this.form.logger.error(`Unable to compile expression \`"${eName}" : "${eString}"\` Exception : ${e}`);
|
|
@@ -144,7 +144,7 @@ class Scriptable extends BaseNode_1.BaseNode {
|
|
|
144
144
|
'$field': this.getRuleNode(),
|
|
145
145
|
'field': this
|
|
146
146
|
};
|
|
147
|
-
const node = this.ruleEngine.compileRule(expr);
|
|
147
|
+
const node = this.ruleEngine.compileRule(expr, this.lang);
|
|
148
148
|
return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext);
|
|
149
149
|
}
|
|
150
150
|
executeAction(action) {
|
|
@@ -247,9 +247,10 @@ class FunctionRuntimeImpl {
|
|
|
247
247
|
setFocus: {
|
|
248
248
|
_func: (args, data, interpreter) => {
|
|
249
249
|
const element = args[0];
|
|
250
|
+
const flag = args[1];
|
|
250
251
|
try {
|
|
251
|
-
const field = interpreter.globals.form.getElement(element.$id);
|
|
252
|
-
interpreter.globals.form.setFocus(field);
|
|
252
|
+
const field = interpreter.globals.form.getElement(element === null || element === void 0 ? void 0 : element.$id) || interpreter.globals.field;
|
|
253
|
+
interpreter.globals.form.setFocus(field, flag);
|
|
253
254
|
}
|
|
254
255
|
catch (e) {
|
|
255
256
|
interpreter.globals.form.logger.error('Invalid argument passed in setFocus. An element is expected');
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { BaseModel } from '../types/index';
|
|
2
|
+
import Formula from '@adobe/json-formula';
|
|
2
3
|
declare class RuleEngine {
|
|
3
4
|
private _context;
|
|
4
5
|
private _globalNames;
|
|
5
|
-
private
|
|
6
|
+
private readonly customFunctions;
|
|
6
7
|
private debugInfo;
|
|
7
8
|
constructor();
|
|
8
|
-
compileRule(rule: string):
|
|
9
|
+
compileRule(rule: string, locale?: string): {
|
|
10
|
+
formula: Formula;
|
|
11
|
+
ast: any;
|
|
12
|
+
};
|
|
9
13
|
execute(node: any, data: any, globals: any, useValueOf?: boolean): any;
|
|
10
14
|
trackDependency(subscriber: BaseModel): void;
|
|
11
15
|
}
|
package/lib/rules/RuleEngine.js
CHANGED
|
@@ -5,6 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const json_formula_1 = __importDefault(require("@adobe/json-formula"));
|
|
7
7
|
const FunctionRuntime_1 = require("./FunctionRuntime");
|
|
8
|
+
const CoercionUtils_1 = require("../utils/CoercionUtils");
|
|
9
|
+
function getStringToNumberFn(locale) {
|
|
10
|
+
if (locale == null) {
|
|
11
|
+
const localeOptions = new Intl.DateTimeFormat().resolvedOptions();
|
|
12
|
+
locale = localeOptions.locale;
|
|
13
|
+
}
|
|
14
|
+
return (str) => (0, CoercionUtils_1.stringToNumber)(str, locale);
|
|
15
|
+
}
|
|
8
16
|
class RuleEngine {
|
|
9
17
|
constructor() {
|
|
10
18
|
this._globalNames = [
|
|
@@ -13,19 +21,20 @@ class RuleEngine {
|
|
|
13
21
|
'$event'
|
|
14
22
|
];
|
|
15
23
|
this.debugInfo = [];
|
|
16
|
-
|
|
17
|
-
this.formulaEngine = new json_formula_1.default(customFunctions, undefined, this.debugInfo);
|
|
24
|
+
this.customFunctions = FunctionRuntime_1.FunctionRuntime.getFunctions();
|
|
18
25
|
}
|
|
19
|
-
compileRule(rule) {
|
|
20
|
-
|
|
26
|
+
compileRule(rule, locale) {
|
|
27
|
+
const formula = new json_formula_1.default(this.customFunctions, getStringToNumberFn(locale), this.debugInfo);
|
|
28
|
+
return { formula, ast: formula.compile(rule, this._globalNames) };
|
|
21
29
|
}
|
|
22
30
|
execute(node, data, globals, useValueOf = false) {
|
|
23
31
|
var _a, _b, _c, _d, _e, _f;
|
|
32
|
+
const { formula, ast } = node;
|
|
24
33
|
const oldContext = this._context;
|
|
25
34
|
this._context = globals;
|
|
26
35
|
let res = undefined;
|
|
27
36
|
try {
|
|
28
|
-
res =
|
|
37
|
+
res = formula.run(ast, data, 'en-US', globals);
|
|
29
38
|
}
|
|
30
39
|
catch (err) {
|
|
31
40
|
(_c = (_b = (_a = this._context) === null || _a === void 0 ? void 0 : _a.form) === null || _b === void 0 ? void 0 : _b.logger) === null || _c === void 0 ? void 0 : _c.error(err);
|
package/lib/types/Model.d.ts
CHANGED
|
@@ -133,4 +133,8 @@ export declare class ValidationError implements IValidationError {
|
|
|
133
133
|
errorMessages: Array<string>;
|
|
134
134
|
constructor(fieldName?: string, errorMessages?: Array<any>);
|
|
135
135
|
}
|
|
136
|
+
export declare enum FocusOption {
|
|
137
|
+
NEXT_ITEM = "nextItem",
|
|
138
|
+
PREVIOUS_ITEM = "previousItem"
|
|
139
|
+
}
|
|
136
140
|
export {};
|
package/lib/types/Model.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = void 0;
|
|
3
|
+
exports.FocusOption = exports.ValidationError = void 0;
|
|
4
4
|
class ValidationError {
|
|
5
5
|
constructor(fieldName = '', errorMessages = []) {
|
|
6
6
|
this.errorMessages = errorMessages;
|
|
@@ -8,3 +8,8 @@ class ValidationError {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.ValidationError = ValidationError;
|
|
11
|
+
var FocusOption;
|
|
12
|
+
(function (FocusOption) {
|
|
13
|
+
FocusOption["NEXT_ITEM"] = "nextItem";
|
|
14
|
+
FocusOption["PREVIOUS_ITEM"] = "previousItem";
|
|
15
|
+
})(FocusOption = exports.FocusOption || (exports.FocusOption = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stringToNumber(str: string, language: string): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringToNumber = void 0;
|
|
4
|
+
const af_formatters_1 = require("@aemforms/af-formatters");
|
|
5
|
+
function stringToNumber(str, language) {
|
|
6
|
+
if (str === null) {
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
const n = +str;
|
|
10
|
+
if (!isNaN(n)) {
|
|
11
|
+
return n;
|
|
12
|
+
}
|
|
13
|
+
if (language) {
|
|
14
|
+
const date = (0, af_formatters_1.parseDefaultDate)(str, language, true);
|
|
15
|
+
if (date !== str) {
|
|
16
|
+
return (0, af_formatters_1.datetimeToNumber)(date);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
exports.stringToNumber = stringToNumber;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.65",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@adobe/json-formula": "0.1.50",
|
|
38
|
-
"@aemforms/af-formatters": "^0.22.
|
|
38
|
+
"@aemforms/af-formatters": "^0.22.65"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@babel/preset-env": "^7.20.2",
|