@aemforms/af-core 0.22.163 → 0.22.165
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/esm/afb-runtime.js +70 -17
- package/esm/types/src/BaseNode.d.ts +3 -2
- package/esm/types/src/Container.d.ts +1 -0
- package/esm/types/src/Field.d.ts +1 -0
- package/esm/types/src/types/Json.d.ts +1 -1
- package/esm/types/src/types/Model.d.ts +3 -1
- package/lib/BaseNode.d.ts +3 -2
- package/lib/BaseNode.js +19 -7
- package/lib/Container.d.ts +1 -0
- package/lib/Container.js +6 -0
- package/lib/Field.d.ts +1 -0
- package/lib/Field.js +33 -6
- package/lib/Form.js +3 -3
- package/lib/rules/RuleEngine.js +14 -7
- package/lib/types/Json.d.ts +1 -1
- package/lib/types/Json.js +1 -1
- package/lib/types/Model.d.ts +3 -1
- package/package.json +2 -2
package/esm/afb-runtime.js
CHANGED
|
@@ -57,7 +57,7 @@ const defaultConstraintTypeMessages = Object.freeze({
|
|
|
57
57
|
[ConstraintType.RANGE_UNDERFLOW]: 'Value must be greater than or equal to ${0}.',
|
|
58
58
|
[ConstraintType.TYPE_MISMATCH]: 'Please enter a valid value.',
|
|
59
59
|
[ConstraintType.VALUE_MISSING]: 'Please fill in this field.',
|
|
60
|
-
[ConstraintType.STEP_MISMATCH]: 'Please enter a valid value.',
|
|
60
|
+
[ConstraintType.STEP_MISMATCH]: 'Please enter a valid value. The two nearest valid values are ${0} and ${1}.',
|
|
61
61
|
[ConstraintType.FORMAT_MISMATCH]: 'Specify the value in allowed format : ${0}.',
|
|
62
62
|
[ConstraintType.ACCEPT_MISMATCH]: 'The specified file type not supported.',
|
|
63
63
|
[ConstraintType.FILE_SIZE_MISMATCH]: 'File too large. Reduce size and try again.',
|
|
@@ -1457,6 +1457,7 @@ class BaseNode {
|
|
|
1457
1457
|
_ruleNode;
|
|
1458
1458
|
_lang = '';
|
|
1459
1459
|
_callbacks = {};
|
|
1460
|
+
_onlyViewNotify;
|
|
1460
1461
|
_dependents = [];
|
|
1461
1462
|
_jsonModel;
|
|
1462
1463
|
_tokens = [];
|
|
@@ -1647,12 +1648,13 @@ class BaseNode {
|
|
|
1647
1648
|
};
|
|
1648
1649
|
});
|
|
1649
1650
|
}
|
|
1650
|
-
subscribe(callback, eventName = 'change') {
|
|
1651
|
+
subscribe(callback, eventName = 'change', dependentType = 'view') {
|
|
1651
1652
|
this._callbacks[eventName] = this._callbacks[eventName] || [];
|
|
1652
|
-
|
|
1653
|
+
const entry = { callback, dependentType };
|
|
1654
|
+
this._callbacks[eventName].push(entry);
|
|
1653
1655
|
return {
|
|
1654
1656
|
unsubscribe: () => {
|
|
1655
|
-
this._callbacks[eventName] = this._callbacks[eventName].filter(x => x !== callback);
|
|
1657
|
+
this._callbacks[eventName] = this._callbacks[eventName].filter(x => x.callback !== callback);
|
|
1656
1658
|
}
|
|
1657
1659
|
};
|
|
1658
1660
|
}
|
|
@@ -1680,7 +1682,7 @@ class BaseNode {
|
|
|
1680
1682
|
dependent.dispatch(new ExecuteRule());
|
|
1681
1683
|
}
|
|
1682
1684
|
}
|
|
1683
|
-
});
|
|
1685
|
+
}, 'change', 'model');
|
|
1684
1686
|
this._dependents.push({ node: dependent, propertyName, subscription });
|
|
1685
1687
|
}
|
|
1686
1688
|
}
|
|
@@ -1692,10 +1694,17 @@ class BaseNode {
|
|
|
1692
1694
|
}
|
|
1693
1695
|
}
|
|
1694
1696
|
queueEvent(action) {
|
|
1697
|
+
if (this._onlyViewNotify) {
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1695
1700
|
const actionWithTarget = new ActionImplWithTarget(action, this);
|
|
1696
1701
|
this.form.getEventQueue().queue(this, actionWithTarget, ['valid', 'invalid'].indexOf(actionWithTarget.type) > -1);
|
|
1697
1702
|
}
|
|
1698
1703
|
dispatch(action) {
|
|
1704
|
+
if (this._onlyViewNotify) {
|
|
1705
|
+
this.notifyDependents(new ActionImplWithTarget(action, this));
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1699
1708
|
this.queueEvent(action);
|
|
1700
1709
|
this.form.getEventQueue().runPendingQueue();
|
|
1701
1710
|
}
|
|
@@ -1724,10 +1733,14 @@ class BaseNode {
|
|
|
1724
1733
|
});
|
|
1725
1734
|
this._jsonModel._dependents = undefined;
|
|
1726
1735
|
}
|
|
1727
|
-
const
|
|
1728
|
-
|
|
1736
|
+
const onlyView = this._onlyViewNotify;
|
|
1737
|
+
const entries = this._callbacks[action.type] || [];
|
|
1738
|
+
const toRun = onlyView
|
|
1739
|
+
? entries.filter(e => e.dependentType === 'view' || e.dependentType === undefined)
|
|
1740
|
+
: entries;
|
|
1741
|
+
toRun.forEach(({ callback }) => {
|
|
1729
1742
|
this.withDependencyTrackingControl(true, () => {
|
|
1730
|
-
|
|
1743
|
+
callback(new ActionImplWithTarget(action, this));
|
|
1731
1744
|
});
|
|
1732
1745
|
});
|
|
1733
1746
|
}
|
|
@@ -2530,6 +2543,9 @@ class Container extends Scriptable {
|
|
|
2530
2543
|
x.reset();
|
|
2531
2544
|
});
|
|
2532
2545
|
}
|
|
2546
|
+
get valid() {
|
|
2547
|
+
return this.items.every((item) => item.valid);
|
|
2548
|
+
}
|
|
2533
2549
|
validate() {
|
|
2534
2550
|
return this.items.flatMap(x => {
|
|
2535
2551
|
return x.validate();
|
|
@@ -2666,6 +2682,9 @@ __decorate([
|
|
|
2666
2682
|
__decorate([
|
|
2667
2683
|
dependencyTracked()
|
|
2668
2684
|
], Container.prototype, "minItems", null);
|
|
2685
|
+
__decorate([
|
|
2686
|
+
dependencyTracked()
|
|
2687
|
+
], Container.prototype, "valid", null);
|
|
2669
2688
|
__decorate([
|
|
2670
2689
|
dependencyTracked()
|
|
2671
2690
|
], Container.prototype, "activeChild", null);
|
|
@@ -4202,13 +4221,13 @@ class Form extends Container {
|
|
|
4202
4221
|
if (this._invalidFields.indexOf(action.target.id) === -1) {
|
|
4203
4222
|
this._invalidFields.push(action.target.id);
|
|
4204
4223
|
}
|
|
4205
|
-
}, 'invalid');
|
|
4224
|
+
}, 'invalid', 'model');
|
|
4206
4225
|
field.subscribe((action) => {
|
|
4207
4226
|
const index = this._invalidFields.indexOf(action.target.id);
|
|
4208
4227
|
if (index > -1) {
|
|
4209
4228
|
this._invalidFields.splice(index, 1);
|
|
4210
4229
|
}
|
|
4211
|
-
}, 'valid');
|
|
4230
|
+
}, 'valid', 'model');
|
|
4212
4231
|
field.subscribe((action) => {
|
|
4213
4232
|
const field = action.target.getState();
|
|
4214
4233
|
if (action.payload.changes.length > 0 && field) {
|
|
@@ -4233,7 +4252,7 @@ class Form extends Container {
|
|
|
4233
4252
|
const fieldChangedAction = new FieldChanged(changes, field, action.payload.eventSource);
|
|
4234
4253
|
this.notifyDependents(fieldChangedAction);
|
|
4235
4254
|
}
|
|
4236
|
-
});
|
|
4255
|
+
}, 'change', 'model');
|
|
4237
4256
|
}
|
|
4238
4257
|
visit(callBack) {
|
|
4239
4258
|
this.traverseChild(this, callBack);
|
|
@@ -4380,6 +4399,13 @@ class RuleEngine {
|
|
|
4380
4399
|
this._context = globals;
|
|
4381
4400
|
let res = undefined;
|
|
4382
4401
|
try {
|
|
4402
|
+
this._context?.form?.logger?.info({
|
|
4403
|
+
message: 'Executing rule',
|
|
4404
|
+
expression: eString,
|
|
4405
|
+
fieldName: this._context.field?.name,
|
|
4406
|
+
fieldId: this._context.field?.id,
|
|
4407
|
+
eventType: this._context?.$event?.type
|
|
4408
|
+
});
|
|
4383
4409
|
res = formula.run(ast, data, 'en-US', globals);
|
|
4384
4410
|
}
|
|
4385
4411
|
catch (err) {
|
|
@@ -4876,7 +4902,12 @@ class Field extends Scriptable {
|
|
|
4876
4902
|
if (updates.valid) {
|
|
4877
4903
|
this.triggerValidationEvent(updates);
|
|
4878
4904
|
}
|
|
4879
|
-
const
|
|
4905
|
+
const allChanges = changes.concat(Object.values(updates));
|
|
4906
|
+
const changesWithCurrentState = allChanges.map((change) => {
|
|
4907
|
+
const valueToUse = change.propertyName === 'value' ? this._jsonModel.value : change.currentValue;
|
|
4908
|
+
return { ...change, currentValue: valueToUse };
|
|
4909
|
+
});
|
|
4910
|
+
const changeAction = new Change({ changes: changesWithCurrentState, eventSource: this._eventSource });
|
|
4880
4911
|
this.dispatch(changeAction);
|
|
4881
4912
|
}
|
|
4882
4913
|
}
|
|
@@ -4942,10 +4973,32 @@ class Field extends Scriptable {
|
|
|
4942
4973
|
const afConstraintKey = constraint;
|
|
4943
4974
|
const html5ConstraintType = constraintKeys[afConstraintKey];
|
|
4944
4975
|
const constraintTypeMessages = getConstraintTypeMessages();
|
|
4945
|
-
|
|
4976
|
+
const customMessage = this._jsonModel.constraintMessages?.[afConstraintKey === 'exclusiveMaximum' ? 'maximum' :
|
|
4946
4977
|
afConstraintKey === 'exclusiveMinimum' ? 'minimum' :
|
|
4947
|
-
afConstraintKey]
|
|
4948
|
-
|
|
4978
|
+
afConstraintKey];
|
|
4979
|
+
if (customMessage) {
|
|
4980
|
+
const stepValues = constraint === 'step' ? this._getStepMessageValues() : [this._jsonModel[afConstraintKey]];
|
|
4981
|
+
return replaceTemplatePlaceholders(customMessage, stepValues.length === 2 ? stepValues : [this._jsonModel.step]);
|
|
4982
|
+
}
|
|
4983
|
+
if (constraint === 'step') {
|
|
4984
|
+
const stepValues = this._getStepMessageValues();
|
|
4985
|
+
if (stepValues.length === 2) {
|
|
4986
|
+
return replaceTemplatePlaceholders(constraintTypeMessages[html5ConstraintType], stepValues);
|
|
4987
|
+
}
|
|
4988
|
+
return 'Please enter a valid value.';
|
|
4989
|
+
}
|
|
4990
|
+
return replaceTemplatePlaceholders(constraintTypeMessages[html5ConstraintType], [this._jsonModel[afConstraintKey]]);
|
|
4991
|
+
}
|
|
4992
|
+
_getStepMessageValues() {
|
|
4993
|
+
const result = this.checkStep();
|
|
4994
|
+
if (!result.valid
|
|
4995
|
+
&& result.prev != null
|
|
4996
|
+
&& result.next != null
|
|
4997
|
+
&& Number.isFinite(result.prev)
|
|
4998
|
+
&& Number.isFinite(result.next)) {
|
|
4999
|
+
return [result.prev, result.next];
|
|
5000
|
+
}
|
|
5001
|
+
return [];
|
|
4949
5002
|
}
|
|
4950
5003
|
get errorMessage() {
|
|
4951
5004
|
return this._jsonModel.errorMessage;
|
|
@@ -5005,7 +5058,7 @@ class Field extends Scriptable {
|
|
|
5005
5058
|
let next, prev;
|
|
5006
5059
|
if (!valid) {
|
|
5007
5060
|
next = (Math.ceil(qt) * fStep + fIVal) / factor;
|
|
5008
|
-
prev =
|
|
5061
|
+
prev = next - step;
|
|
5009
5062
|
}
|
|
5010
5063
|
return {
|
|
5011
5064
|
valid,
|
|
@@ -5156,7 +5209,7 @@ class Field extends Scriptable {
|
|
|
5156
5209
|
else {
|
|
5157
5210
|
valid = this.checkEnum(value, Constraints);
|
|
5158
5211
|
constraint = 'enum';
|
|
5159
|
-
if (valid && this.type === 'number') {
|
|
5212
|
+
if (valid && (this.type === 'number' || this.type === 'integer')) {
|
|
5160
5213
|
valid = this.checkStep().valid;
|
|
5161
5214
|
constraint = 'step';
|
|
5162
5215
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
|
|
1
|
+
import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, DependentType, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
|
|
2
2
|
import { PropertiesManager } from './PropertiesManager.js';
|
|
3
3
|
import DataGroup from './data/DataGroup';
|
|
4
4
|
import DataValue from './data/DataValue';
|
|
@@ -15,6 +15,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
15
15
|
private _ruleNode;
|
|
16
16
|
private _lang?;
|
|
17
17
|
private _callbacks;
|
|
18
|
+
_onlyViewNotify?: boolean;
|
|
18
19
|
private _dependents;
|
|
19
20
|
protected _jsonModel: T & {
|
|
20
21
|
id: string;
|
|
@@ -83,7 +84,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
83
84
|
qualifiedName: any;
|
|
84
85
|
id: string;
|
|
85
86
|
};
|
|
86
|
-
subscribe(callback: callbackFn, eventName?: string): {
|
|
87
|
+
subscribe(callback: callbackFn, eventName?: string, dependentType?: DependentType): {
|
|
87
88
|
unsubscribe: () => void;
|
|
88
89
|
};
|
|
89
90
|
_addDependent(dependent: BaseModel, propertyName?: string): void;
|
|
@@ -179,6 +179,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
179
179
|
removeItem(action: Action): void;
|
|
180
180
|
queueEvent(action: Action): void;
|
|
181
181
|
reset(): void;
|
|
182
|
+
get valid(): boolean;
|
|
182
183
|
validate(): import("./types/Model").ValidationError[];
|
|
183
184
|
dispatch(action: Action): void;
|
|
184
185
|
importData(dataModel: any): void;
|
package/esm/types/src/Field.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
65
65
|
valueOf(): any;
|
|
66
66
|
toString(): any;
|
|
67
67
|
getErrorMessage(constraint: keyof (ConstraintsMessages)): string;
|
|
68
|
+
private _getStepMessageValues;
|
|
68
69
|
get errorMessage(): string | undefined;
|
|
69
70
|
set errorMessage(e: string | undefined);
|
|
70
71
|
set constraintMessage(constraint: {
|
|
@@ -179,7 +179,7 @@ export declare const getConstraintTypeMessages: () => {
|
|
|
179
179
|
rangeUnderflow: "Value must be greater than or equal to ${0}.";
|
|
180
180
|
typeMismatch: "Please enter a valid value.";
|
|
181
181
|
valueMissing: "Please fill in this field.";
|
|
182
|
-
stepMismatch: "Please enter a valid value.";
|
|
182
|
+
stepMismatch: "Please enter a valid value. The two nearest valid values are ${0} and ${1}.";
|
|
183
183
|
formatMismatch: "Specify the value in allowed format : ${0}.";
|
|
184
184
|
acceptMismatch: "The specified file type not supported.";
|
|
185
185
|
fileSizeMismatch: "File too large. Reduce size and try again.";
|
|
@@ -38,8 +38,9 @@ export interface Action {
|
|
|
38
38
|
readonly currentTarget: FormModel | FieldModel | FieldsetModel;
|
|
39
39
|
}
|
|
40
40
|
export type callbackFn = (action: Action) => void;
|
|
41
|
+
export type DependentType = 'view' | 'model';
|
|
41
42
|
export interface WithController {
|
|
42
|
-
subscribe(callback: callbackFn, eventName?: string): Subscription;
|
|
43
|
+
subscribe(callback: callbackFn, eventName?: string, dependentType?: DependentType): Subscription;
|
|
43
44
|
dispatch(action: Action): void;
|
|
44
45
|
}
|
|
45
46
|
export type FormCreationMode = 'create' | 'restore';
|
|
@@ -80,6 +81,7 @@ export interface BaseModel extends ConstraintsJson, WithController {
|
|
|
80
81
|
ruleNodeReference(): any;
|
|
81
82
|
_initialize(mode?: FormCreationMode): any;
|
|
82
83
|
_addDependent(dependent: BaseModel, propertyName?: string): any;
|
|
84
|
+
_onlyViewNotify?: boolean;
|
|
83
85
|
_eventSource: EventSource;
|
|
84
86
|
readonly fragment: string;
|
|
85
87
|
}
|
package/lib/BaseNode.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
|
|
1
|
+
import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, DependentType, FormCreationMode, FormModel, Primitives, ValidationError, EventSource } from './types/index';
|
|
2
2
|
import { PropertiesManager } from './PropertiesManager.js';
|
|
3
3
|
import DataGroup from './data/DataGroup';
|
|
4
4
|
import DataValue from './data/DataValue';
|
|
@@ -15,6 +15,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
15
15
|
private _ruleNode;
|
|
16
16
|
private _lang?;
|
|
17
17
|
private _callbacks;
|
|
18
|
+
_onlyViewNotify?: boolean;
|
|
18
19
|
private _dependents;
|
|
19
20
|
protected _jsonModel: T & {
|
|
20
21
|
id: string;
|
|
@@ -83,7 +84,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
83
84
|
qualifiedName: any;
|
|
84
85
|
id: string;
|
|
85
86
|
};
|
|
86
|
-
subscribe(callback: callbackFn, eventName?: string): {
|
|
87
|
+
subscribe(callback: callbackFn, eventName?: string, dependentType?: DependentType): {
|
|
87
88
|
unsubscribe: () => void;
|
|
88
89
|
};
|
|
89
90
|
_addDependent(dependent: BaseModel, propertyName?: string): void;
|
package/lib/BaseNode.js
CHANGED
|
@@ -298,12 +298,13 @@ class BaseNode {
|
|
|
298
298
|
} : {}));
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
|
-
subscribe(callback, eventName = 'change') {
|
|
301
|
+
subscribe(callback, eventName = 'change', dependentType = 'view') {
|
|
302
302
|
this._callbacks[eventName] = this._callbacks[eventName] || [];
|
|
303
|
-
|
|
303
|
+
const entry = { callback, dependentType };
|
|
304
|
+
this._callbacks[eventName].push(entry);
|
|
304
305
|
return {
|
|
305
306
|
unsubscribe: () => {
|
|
306
|
-
this._callbacks[eventName] = this._callbacks[eventName].filter(x => x !== callback);
|
|
307
|
+
this._callbacks[eventName] = this._callbacks[eventName].filter(x => x.callback !== callback);
|
|
307
308
|
}
|
|
308
309
|
};
|
|
309
310
|
}
|
|
@@ -331,7 +332,7 @@ class BaseNode {
|
|
|
331
332
|
dependent.dispatch(new Events_1.ExecuteRule());
|
|
332
333
|
}
|
|
333
334
|
}
|
|
334
|
-
});
|
|
335
|
+
}, 'change', 'model');
|
|
335
336
|
this._dependents.push({ node: dependent, propertyName, subscription });
|
|
336
337
|
}
|
|
337
338
|
}
|
|
@@ -343,10 +344,17 @@ class BaseNode {
|
|
|
343
344
|
}
|
|
344
345
|
}
|
|
345
346
|
queueEvent(action) {
|
|
347
|
+
if (this._onlyViewNotify) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
346
350
|
const actionWithTarget = new ActionImplWithTarget(action, this);
|
|
347
351
|
this.form.getEventQueue().queue(this, actionWithTarget, ['valid', 'invalid'].indexOf(actionWithTarget.type) > -1);
|
|
348
352
|
}
|
|
349
353
|
dispatch(action) {
|
|
354
|
+
if (this._onlyViewNotify) {
|
|
355
|
+
this.notifyDependents(new ActionImplWithTarget(action, this));
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
350
358
|
this.queueEvent(action);
|
|
351
359
|
this.form.getEventQueue().runPendingQueue();
|
|
352
360
|
}
|
|
@@ -376,10 +384,14 @@ class BaseNode {
|
|
|
376
384
|
});
|
|
377
385
|
this._jsonModel._dependents = undefined;
|
|
378
386
|
}
|
|
379
|
-
const
|
|
380
|
-
|
|
387
|
+
const onlyView = this._onlyViewNotify;
|
|
388
|
+
const entries = this._callbacks[action.type] || [];
|
|
389
|
+
const toRun = onlyView
|
|
390
|
+
? entries.filter(e => e.dependentType === 'view' || e.dependentType === undefined)
|
|
391
|
+
: entries;
|
|
392
|
+
toRun.forEach(({ callback }) => {
|
|
381
393
|
this.withDependencyTrackingControl(true, () => {
|
|
382
|
-
|
|
394
|
+
callback(new ActionImplWithTarget(action, this));
|
|
383
395
|
});
|
|
384
396
|
});
|
|
385
397
|
}
|
package/lib/Container.d.ts
CHANGED
|
@@ -179,6 +179,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
179
179
|
removeItem(action: Action): void;
|
|
180
180
|
queueEvent(action: Action): void;
|
|
181
181
|
reset(): void;
|
|
182
|
+
get valid(): boolean;
|
|
182
183
|
validate(): import("./types/Model").ValidationError[];
|
|
183
184
|
dispatch(action: Action): void;
|
|
184
185
|
importData(dataModel: any): void;
|
package/lib/Container.js
CHANGED
|
@@ -347,6 +347,9 @@ class Container extends Scriptable_1.default {
|
|
|
347
347
|
x.reset();
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
|
+
get valid() {
|
|
351
|
+
return this.items.every((item) => item.valid);
|
|
352
|
+
}
|
|
350
353
|
validate() {
|
|
351
354
|
return this.items.flatMap(x => {
|
|
352
355
|
return x.validate();
|
|
@@ -487,6 +490,9 @@ __decorate([
|
|
|
487
490
|
__decorate([
|
|
488
491
|
(0, BaseNode_1.dependencyTracked)()
|
|
489
492
|
], Container.prototype, "minItems", null);
|
|
493
|
+
__decorate([
|
|
494
|
+
(0, BaseNode_1.dependencyTracked)()
|
|
495
|
+
], Container.prototype, "valid", null);
|
|
490
496
|
__decorate([
|
|
491
497
|
(0, BaseNode_1.dependencyTracked)()
|
|
492
498
|
], Container.prototype, "activeChild", null);
|
package/lib/Field.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
65
65
|
valueOf(): any;
|
|
66
66
|
toString(): any;
|
|
67
67
|
getErrorMessage(constraint: keyof (ConstraintsMessages)): string;
|
|
68
|
+
private _getStepMessageValues;
|
|
68
69
|
get errorMessage(): string | undefined;
|
|
69
70
|
set errorMessage(e: string | undefined);
|
|
70
71
|
set constraintMessage(constraint: {
|
package/lib/Field.js
CHANGED
|
@@ -404,7 +404,12 @@ class Field extends Scriptable_1.default {
|
|
|
404
404
|
if (updates.valid) {
|
|
405
405
|
this.triggerValidationEvent(updates);
|
|
406
406
|
}
|
|
407
|
-
const
|
|
407
|
+
const allChanges = changes.concat(Object.values(updates));
|
|
408
|
+
const changesWithCurrentState = allChanges.map((change) => {
|
|
409
|
+
const valueToUse = change.propertyName === 'value' ? this._jsonModel.value : change.currentValue;
|
|
410
|
+
return Object.assign(Object.assign({}, change), { currentValue: valueToUse });
|
|
411
|
+
});
|
|
412
|
+
const changeAction = new Events_1.Change({ changes: changesWithCurrentState, eventSource: this._eventSource });
|
|
408
413
|
this.dispatch(changeAction);
|
|
409
414
|
}
|
|
410
415
|
}
|
|
@@ -473,10 +478,32 @@ class Field extends Scriptable_1.default {
|
|
|
473
478
|
const afConstraintKey = constraint;
|
|
474
479
|
const html5ConstraintType = types_1.constraintKeys[afConstraintKey];
|
|
475
480
|
const constraintTypeMessages = (0, types_1.getConstraintTypeMessages)();
|
|
476
|
-
|
|
481
|
+
const customMessage = (_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[afConstraintKey === 'exclusiveMaximum' ? 'maximum' :
|
|
477
482
|
afConstraintKey === 'exclusiveMinimum' ? 'minimum' :
|
|
478
|
-
afConstraintKey]
|
|
479
|
-
|
|
483
|
+
afConstraintKey];
|
|
484
|
+
if (customMessage) {
|
|
485
|
+
const stepValues = constraint === 'step' ? this._getStepMessageValues() : [this._jsonModel[afConstraintKey]];
|
|
486
|
+
return (0, FormUtils_1.replaceTemplatePlaceholders)(customMessage, stepValues.length === 2 ? stepValues : [this._jsonModel.step]);
|
|
487
|
+
}
|
|
488
|
+
if (constraint === 'step') {
|
|
489
|
+
const stepValues = this._getStepMessageValues();
|
|
490
|
+
if (stepValues.length === 2) {
|
|
491
|
+
return (0, FormUtils_1.replaceTemplatePlaceholders)(constraintTypeMessages[html5ConstraintType], stepValues);
|
|
492
|
+
}
|
|
493
|
+
return 'Please enter a valid value.';
|
|
494
|
+
}
|
|
495
|
+
return (0, FormUtils_1.replaceTemplatePlaceholders)(constraintTypeMessages[html5ConstraintType], [this._jsonModel[afConstraintKey]]);
|
|
496
|
+
}
|
|
497
|
+
_getStepMessageValues() {
|
|
498
|
+
const result = this.checkStep();
|
|
499
|
+
if (!result.valid
|
|
500
|
+
&& result.prev != null
|
|
501
|
+
&& result.next != null
|
|
502
|
+
&& Number.isFinite(result.prev)
|
|
503
|
+
&& Number.isFinite(result.next)) {
|
|
504
|
+
return [result.prev, result.next];
|
|
505
|
+
}
|
|
506
|
+
return [];
|
|
480
507
|
}
|
|
481
508
|
get errorMessage() {
|
|
482
509
|
return this._jsonModel.errorMessage;
|
|
@@ -532,7 +559,7 @@ class Field extends Scriptable_1.default {
|
|
|
532
559
|
let next, prev;
|
|
533
560
|
if (!valid) {
|
|
534
561
|
next = (Math.ceil(qt) * fStep + fIVal) / factor;
|
|
535
|
-
prev =
|
|
562
|
+
prev = next - step;
|
|
536
563
|
}
|
|
537
564
|
return {
|
|
538
565
|
valid,
|
|
@@ -683,7 +710,7 @@ class Field extends Scriptable_1.default {
|
|
|
683
710
|
else {
|
|
684
711
|
valid = this.checkEnum(value, Constraints);
|
|
685
712
|
constraint = 'enum';
|
|
686
|
-
if (valid && this.type === 'number') {
|
|
713
|
+
if (valid && (this.type === 'number' || this.type === 'integer')) {
|
|
687
714
|
valid = this.checkStep().valid;
|
|
688
715
|
constraint = 'step';
|
|
689
716
|
}
|
package/lib/Form.js
CHANGED
|
@@ -270,13 +270,13 @@ class Form extends Container_1.default {
|
|
|
270
270
|
if (this._invalidFields.indexOf(action.target.id) === -1) {
|
|
271
271
|
this._invalidFields.push(action.target.id);
|
|
272
272
|
}
|
|
273
|
-
}, 'invalid');
|
|
273
|
+
}, 'invalid', 'model');
|
|
274
274
|
field.subscribe((action) => {
|
|
275
275
|
const index = this._invalidFields.indexOf(action.target.id);
|
|
276
276
|
if (index > -1) {
|
|
277
277
|
this._invalidFields.splice(index, 1);
|
|
278
278
|
}
|
|
279
|
-
}, 'valid');
|
|
279
|
+
}, 'valid', 'model');
|
|
280
280
|
field.subscribe((action) => {
|
|
281
281
|
const field = action.target.getState();
|
|
282
282
|
if (action.payload.changes.length > 0 && field) {
|
|
@@ -301,7 +301,7 @@ class Form extends Container_1.default {
|
|
|
301
301
|
const fieldChangedAction = new Events_1.FieldChanged(changes, field, action.payload.eventSource);
|
|
302
302
|
this.notifyDependents(fieldChangedAction);
|
|
303
303
|
}
|
|
304
|
-
});
|
|
304
|
+
}, 'change', 'model');
|
|
305
305
|
}
|
|
306
306
|
visit(callBack) {
|
|
307
307
|
this.traverseChild(this, callBack);
|
package/lib/rules/RuleEngine.js
CHANGED
|
@@ -30,18 +30,25 @@ class RuleEngine {
|
|
|
30
30
|
return { formula, ast: formula.compile(rule, this._globalNames) };
|
|
31
31
|
}
|
|
32
32
|
execute(node, data, globals, useValueOf = false, eString) {
|
|
33
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
33
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
34
34
|
const { formula, ast } = node;
|
|
35
35
|
const oldContext = this._context;
|
|
36
36
|
this._context = globals;
|
|
37
37
|
let res = undefined;
|
|
38
38
|
try {
|
|
39
|
+
(_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.info({
|
|
40
|
+
message: 'Executing rule',
|
|
41
|
+
expression: eString,
|
|
42
|
+
fieldName: (_d = this._context.field) === null || _d === void 0 ? void 0 : _d.name,
|
|
43
|
+
fieldId: (_e = this._context.field) === null || _e === void 0 ? void 0 : _e.id,
|
|
44
|
+
eventType: (_g = (_f = this._context) === null || _f === void 0 ? void 0 : _f.$event) === null || _g === void 0 ? void 0 : _g.type
|
|
45
|
+
});
|
|
39
46
|
res = formula.run(ast, data, 'en-US', globals);
|
|
40
47
|
}
|
|
41
48
|
catch (err) {
|
|
42
|
-
(
|
|
43
|
-
if ((
|
|
44
|
-
const field = (
|
|
49
|
+
(_k = (_j = (_h = this._context) === null || _h === void 0 ? void 0 : _h.form) === null || _j === void 0 ? void 0 : _j.logger) === null || _k === void 0 ? void 0 : _k.error(err);
|
|
50
|
+
if ((_l = this._context) === null || _l === void 0 ? void 0 : _l.form) {
|
|
51
|
+
const field = (_m = this._context) === null || _m === void 0 ? void 0 : _m.field;
|
|
45
52
|
const fieldName = field === null || field === void 0 ? void 0 : field.name;
|
|
46
53
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
47
54
|
const fullError = fieldName
|
|
@@ -50,7 +57,7 @@ class RuleEngine {
|
|
|
50
57
|
const errorPayload = {
|
|
51
58
|
name: fieldName,
|
|
52
59
|
error: fullError,
|
|
53
|
-
event: (
|
|
60
|
+
event: (_p = (_o = this._context) === null || _o === void 0 ? void 0 : _o.$event) === null || _p === void 0 ? void 0 : _p.type,
|
|
54
61
|
rule: eString,
|
|
55
62
|
stack: err instanceof Error ? err.stack : undefined
|
|
56
63
|
};
|
|
@@ -58,9 +65,9 @@ class RuleEngine {
|
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
67
|
if (this.debugInfo.length) {
|
|
61
|
-
(
|
|
68
|
+
(_s = (_r = (_q = this._context) === null || _q === void 0 ? void 0 : _q.form) === null || _r === void 0 ? void 0 : _r.logger) === null || _s === void 0 ? void 0 : _s.warn(`Form rule expression string: ${eString}`);
|
|
62
69
|
while (this.debugInfo.length > 0) {
|
|
63
|
-
(
|
|
70
|
+
(_v = (_u = (_t = this._context) === null || _t === void 0 ? void 0 : _t.form) === null || _u === void 0 ? void 0 : _u.logger) === null || _v === void 0 ? void 0 : _v.warn(this.debugInfo.pop());
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
let finalRes = res;
|
package/lib/types/Json.d.ts
CHANGED
|
@@ -179,7 +179,7 @@ export declare const getConstraintTypeMessages: () => {
|
|
|
179
179
|
rangeUnderflow: "Value must be greater than or equal to ${0}.";
|
|
180
180
|
typeMismatch: "Please enter a valid value.";
|
|
181
181
|
valueMissing: "Please fill in this field.";
|
|
182
|
-
stepMismatch: "Please enter a valid value.";
|
|
182
|
+
stepMismatch: "Please enter a valid value. The two nearest valid values are ${0} and ${1}.";
|
|
183
183
|
formatMismatch: "Specify the value in allowed format : ${0}.";
|
|
184
184
|
acceptMismatch: "The specified file type not supported.";
|
|
185
185
|
fileSizeMismatch: "File too large. Reduce size and try again.";
|
package/lib/types/Json.js
CHANGED
|
@@ -56,7 +56,7 @@ const defaultConstraintTypeMessages = Object.freeze({
|
|
|
56
56
|
[exports.ConstraintType.RANGE_UNDERFLOW]: 'Value must be greater than or equal to ${0}.',
|
|
57
57
|
[exports.ConstraintType.TYPE_MISMATCH]: 'Please enter a valid value.',
|
|
58
58
|
[exports.ConstraintType.VALUE_MISSING]: 'Please fill in this field.',
|
|
59
|
-
[exports.ConstraintType.STEP_MISMATCH]: 'Please enter a valid value.',
|
|
59
|
+
[exports.ConstraintType.STEP_MISMATCH]: 'Please enter a valid value. The two nearest valid values are ${0} and ${1}.',
|
|
60
60
|
[exports.ConstraintType.FORMAT_MISMATCH]: 'Specify the value in allowed format : ${0}.',
|
|
61
61
|
[exports.ConstraintType.ACCEPT_MISMATCH]: 'The specified file type not supported.',
|
|
62
62
|
[exports.ConstraintType.FILE_SIZE_MISMATCH]: 'File too large. Reduce size and try again.',
|
package/lib/types/Model.d.ts
CHANGED
|
@@ -38,8 +38,9 @@ export interface Action {
|
|
|
38
38
|
readonly currentTarget: FormModel | FieldModel | FieldsetModel;
|
|
39
39
|
}
|
|
40
40
|
export declare type callbackFn = (action: Action) => void;
|
|
41
|
+
export declare type DependentType = 'view' | 'model';
|
|
41
42
|
export interface WithController {
|
|
42
|
-
subscribe(callback: callbackFn, eventName?: string): Subscription;
|
|
43
|
+
subscribe(callback: callbackFn, eventName?: string, dependentType?: DependentType): Subscription;
|
|
43
44
|
dispatch(action: Action): void;
|
|
44
45
|
}
|
|
45
46
|
export declare type FormCreationMode = 'create' | 'restore';
|
|
@@ -80,6 +81,7 @@ export interface BaseModel extends ConstraintsJson, WithController {
|
|
|
80
81
|
ruleNodeReference(): any;
|
|
81
82
|
_initialize(mode?: FormCreationMode): any;
|
|
82
83
|
_addDependent(dependent: BaseModel, propertyName?: string): any;
|
|
84
|
+
_onlyViewNotify?: boolean;
|
|
83
85
|
_eventSource: EventSource;
|
|
84
86
|
readonly fragment: string;
|
|
85
87
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.165",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@adobe/json-formula": "0.1.50",
|
|
40
|
-
"@aemforms/af-formatters": "^0.22.
|
|
40
|
+
"@aemforms/af-formatters": "^0.22.165"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|