@player-ui/player 0.8.0--canary.307.9621 → 0.8.0-next.0
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/Player.native.js +11630 -0
- package/dist/Player.native.js.map +1 -0
- package/dist/cjs/index.cjs +5626 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{index.esm.js → index.legacy-esm.js} +2044 -1667
- package/dist/{index.cjs.js → index.mjs} +2052 -1761
- package/dist/index.mjs.map +1 -0
- package/package.json +29 -63
- package/src/__tests__/data.test.ts +498 -0
- package/src/__tests__/flow.test.ts +312 -0
- package/src/__tests__/helpers/action-exp.plugin.ts +22 -0
- package/src/__tests__/helpers/actions.flow.ts +67 -0
- package/src/__tests__/helpers/binding.plugin.ts +125 -0
- package/src/__tests__/helpers/expression.plugin.ts +88 -0
- package/src/__tests__/helpers/transform-plugin.ts +19 -0
- package/src/__tests__/helpers/validation.flow.ts +56 -0
- package/src/__tests__/player.test.ts +597 -0
- package/src/__tests__/string-resolver.test.ts +186 -0
- package/src/__tests__/validation.test.ts +3555 -0
- package/src/__tests__/view.test.ts +715 -0
- package/src/binding/__tests__/binding.test.ts +113 -0
- package/src/binding/__tests__/index.test.ts +208 -0
- package/src/binding/__tests__/resolver.test.ts +83 -0
- package/src/binding/binding.ts +6 -6
- package/src/binding/index.ts +34 -34
- package/src/binding/resolver.ts +19 -19
- package/src/binding/utils.ts +7 -7
- package/src/binding-grammar/__tests__/parser.test.ts +64 -0
- package/src/binding-grammar/__tests__/test-utils/ast-cases.ts +198 -0
- package/src/binding-grammar/__tests__/test-utils/perf-test.ts +66 -0
- package/src/binding-grammar/ast.ts +11 -11
- package/src/binding-grammar/custom/index.ts +19 -22
- package/src/binding-grammar/ebnf/index.ts +20 -21
- package/src/binding-grammar/ebnf/types.ts +13 -13
- package/src/binding-grammar/index.ts +4 -4
- package/src/binding-grammar/parsimmon/index.ts +14 -14
- package/src/controllers/constants/__tests__/index.test.ts +106 -0
- package/src/controllers/constants/index.ts +3 -3
- package/src/controllers/constants/utils.ts +4 -4
- package/src/controllers/data/controller.ts +22 -22
- package/src/controllers/data/index.ts +1 -1
- package/src/controllers/data/utils.ts +7 -7
- package/src/controllers/flow/__tests__/controller.test.ts +195 -0
- package/src/controllers/flow/__tests__/flow.test.ts +381 -0
- package/src/controllers/flow/controller.ts +13 -13
- package/src/controllers/flow/flow.ts +23 -23
- package/src/controllers/flow/index.ts +2 -2
- package/src/controllers/index.ts +5 -5
- package/src/controllers/validation/binding-tracker.ts +71 -59
- package/src/controllers/validation/controller.ts +104 -104
- package/src/controllers/validation/index.ts +2 -2
- package/src/controllers/view/asset-transform.ts +20 -20
- package/src/controllers/view/controller.ts +27 -27
- package/src/controllers/view/index.ts +4 -4
- package/src/controllers/view/store.ts +3 -3
- package/src/controllers/view/types.ts +7 -7
- package/src/data/__tests__/__snapshots__/dependency-tracker.test.ts.snap +64 -0
- package/src/data/__tests__/dependency-tracker.test.ts +146 -0
- package/src/data/__tests__/local-model.test.ts +46 -0
- package/src/data/__tests__/model.test.ts +78 -0
- package/src/data/dependency-tracker.ts +16 -16
- package/src/data/index.ts +4 -4
- package/src/data/local-model.ts +6 -6
- package/src/data/model.ts +17 -17
- package/src/data/noop-model.ts +1 -1
- package/src/expressions/__tests__/__snapshots__/parser.test.ts.snap +854 -0
- package/src/expressions/__tests__/evaluator-functions.test.ts +47 -0
- package/src/expressions/__tests__/evaluator.test.ts +410 -0
- package/src/expressions/__tests__/parser.test.ts +115 -0
- package/src/expressions/__tests__/utils.test.ts +44 -0
- package/src/expressions/evaluator-functions.ts +6 -6
- package/src/expressions/evaluator.ts +71 -67
- package/src/expressions/index.ts +4 -4
- package/src/expressions/parser.ts +102 -105
- package/src/expressions/types.ts +29 -21
- package/src/expressions/utils.ts +32 -21
- package/src/index.ts +13 -13
- package/src/logger/__tests__/consoleLogger.test.ts +46 -0
- package/src/logger/__tests__/noopLogger.test.ts +13 -0
- package/src/logger/__tests__/proxyLogger.test.ts +31 -0
- package/src/logger/__tests__/tapableLogger.test.ts +41 -0
- package/src/logger/consoleLogger.ts +9 -9
- package/src/logger/index.ts +5 -5
- package/src/logger/noopLogger.ts +1 -1
- package/src/logger/proxyLogger.ts +6 -6
- package/src/logger/tapableLogger.ts +7 -7
- package/src/logger/types.ts +2 -2
- package/src/player.ts +60 -58
- package/src/plugins/default-exp-plugin.ts +10 -10
- package/src/plugins/default-view-plugin.ts +29 -0
- package/src/plugins/flow-exp-plugin.ts +6 -6
- package/src/schema/__tests__/schema.test.ts +243 -0
- package/src/schema/index.ts +2 -2
- package/src/schema/schema.ts +24 -24
- package/src/schema/types.ts +4 -4
- package/src/string-resolver/__tests__/index.test.ts +361 -0
- package/src/string-resolver/index.ts +17 -17
- package/src/types.ts +17 -17
- package/src/utils/__tests__/replaceParams.test.ts +33 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/replaceParams.ts +1 -1
- package/src/validator/__tests__/binding-map-splice.test.ts +53 -0
- package/src/validator/__tests__/validation-middleware.test.ts +127 -0
- package/src/validator/binding-map-splice.ts +5 -5
- package/src/validator/index.ts +4 -4
- package/src/validator/registry.ts +1 -1
- package/src/validator/types.ts +13 -13
- package/src/validator/validation-middleware.ts +15 -15
- package/src/view/__tests__/view.immutable.test.ts +269 -0
- package/src/view/__tests__/view.test.ts +959 -0
- package/src/view/builder/index.test.ts +69 -0
- package/src/view/builder/index.ts +3 -3
- package/src/view/index.ts +5 -5
- package/src/view/parser/__tests__/__snapshots__/parser.test.ts.snap +394 -0
- package/src/view/parser/__tests__/parser.test.ts +264 -0
- package/src/view/parser/index.ts +43 -33
- package/src/view/parser/types.ts +11 -11
- package/src/view/parser/utils.ts +5 -5
- package/src/view/plugins/__tests__/__snapshots__/template.test.ts.snap +278 -0
- package/src/view/plugins/__tests__/applicability.test.ts +265 -0
- package/src/view/plugins/__tests__/string.test.ts +122 -0
- package/src/view/plugins/__tests__/template.test.ts +724 -0
- package/src/view/plugins/applicability.ts +19 -19
- package/src/view/plugins/index.ts +4 -5
- package/src/view/plugins/options.ts +1 -1
- package/src/view/plugins/string-resolver.ts +22 -22
- package/src/view/plugins/switch.ts +22 -23
- package/src/view/plugins/template-plugin.ts +26 -27
- package/src/view/resolver/__tests__/dependencies.test.ts +321 -0
- package/src/view/resolver/__tests__/edgecases.test.ts +626 -0
- package/src/view/resolver/index.ts +42 -42
- package/src/view/resolver/types.ts +21 -20
- package/src/view/resolver/utils.ts +9 -9
- package/src/view/view.ts +32 -22
- package/types/binding/binding.d.ts +50 -0
- package/types/binding/index.d.ts +29 -0
- package/types/binding/resolver.d.ts +26 -0
- package/types/binding/utils.d.ts +12 -0
- package/types/binding-grammar/ast.d.ts +67 -0
- package/types/binding-grammar/custom/index.d.ts +4 -0
- package/types/binding-grammar/ebnf/index.d.ts +4 -0
- package/types/binding-grammar/ebnf/types.d.ts +75 -0
- package/types/binding-grammar/index.d.ts +5 -0
- package/types/binding-grammar/parsimmon/index.d.ts +4 -0
- package/types/controllers/constants/index.d.ts +45 -0
- package/types/controllers/constants/utils.d.ts +6 -0
- package/types/controllers/data/controller.d.ts +45 -0
- package/types/controllers/data/index.d.ts +2 -0
- package/types/controllers/data/utils.d.ts +14 -0
- package/types/controllers/flow/controller.d.ts +25 -0
- package/types/controllers/flow/flow.d.ts +50 -0
- package/types/controllers/flow/index.d.ts +3 -0
- package/types/controllers/index.d.ts +6 -0
- package/types/controllers/validation/binding-tracker.d.ts +32 -0
- package/types/controllers/validation/controller.d.ts +151 -0
- package/types/controllers/validation/index.d.ts +3 -0
- package/types/controllers/view/asset-transform.d.ts +19 -0
- package/types/controllers/view/controller.d.ts +37 -0
- package/types/controllers/view/index.d.ts +5 -0
- package/types/controllers/view/store.d.ts +20 -0
- package/types/controllers/view/types.d.ts +16 -0
- package/types/data/dependency-tracker.d.ts +49 -0
- package/types/data/index.d.ts +5 -0
- package/types/data/local-model.d.ts +16 -0
- package/types/data/model.d.ts +86 -0
- package/types/data/noop-model.d.ts +13 -0
- package/types/expressions/evaluator-functions.d.ts +15 -0
- package/types/expressions/evaluator.d.ts +52 -0
- package/types/expressions/index.d.ts +5 -0
- package/types/expressions/parser.d.ts +10 -0
- package/types/expressions/types.d.ts +144 -0
- package/types/expressions/utils.d.ts +12 -0
- package/types/index.d.ts +14 -0
- package/types/logger/consoleLogger.d.ts +17 -0
- package/types/logger/index.d.ts +6 -0
- package/types/logger/noopLogger.d.ts +10 -0
- package/types/logger/proxyLogger.d.ts +15 -0
- package/types/logger/tapableLogger.d.ts +23 -0
- package/types/logger/types.d.ts +6 -0
- package/types/player.d.ts +101 -0
- package/types/plugins/default-exp-plugin.d.ts +9 -0
- package/types/plugins/default-view-plugin.d.ts +9 -0
- package/types/plugins/flow-exp-plugin.d.ts +11 -0
- package/types/schema/index.d.ts +3 -0
- package/types/schema/schema.d.ts +36 -0
- package/types/schema/types.d.ts +38 -0
- package/types/string-resolver/index.d.ts +30 -0
- package/types/types.d.ts +73 -0
- package/types/utils/index.d.ts +2 -0
- package/types/utils/replaceParams.d.ts +9 -0
- package/types/validator/binding-map-splice.d.ts +10 -0
- package/types/validator/index.d.ts +5 -0
- package/types/validator/registry.d.ts +11 -0
- package/types/validator/types.d.ts +53 -0
- package/types/validator/validation-middleware.d.ts +36 -0
- package/types/view/builder/index.d.ts +35 -0
- package/types/view/index.d.ts +6 -0
- package/types/view/parser/index.d.ts +52 -0
- package/types/view/parser/types.d.ts +109 -0
- package/types/view/parser/utils.d.ts +6 -0
- package/types/view/plugins/applicability.d.ts +10 -0
- package/types/view/plugins/index.d.ts +5 -0
- package/types/view/plugins/options.d.ts +4 -0
- package/types/view/plugins/string-resolver.d.ts +13 -0
- package/types/view/plugins/switch.d.ts +14 -0
- package/types/view/plugins/template-plugin.d.ts +33 -0
- package/types/view/resolver/index.d.ts +73 -0
- package/types/view/resolver/types.d.ts +129 -0
- package/types/view/resolver/utils.d.ts +11 -0
- package/types/view/view.d.ts +37 -0
- package/dist/index.d.ts +0 -1814
- package/dist/player.dev.js +0 -11472
- package/dist/player.prod.js +0 -2
- package/src/view/plugins/plugin.ts +0 -21
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Validation } from
|
|
2
|
-
import { SyncHook, SyncWaterfallHook } from
|
|
3
|
-
import { setIn } from
|
|
4
|
-
|
|
5
|
-
import type { BindingInstance, BindingFactory } from
|
|
6
|
-
import { isBinding } from
|
|
7
|
-
import type { DataModelWithParser, DataModelMiddleware } from
|
|
8
|
-
import type { SchemaController } from
|
|
1
|
+
import type { Validation } from "@player-ui/types";
|
|
2
|
+
import { SyncHook, SyncWaterfallHook } from "tapable-ts";
|
|
3
|
+
import { setIn } from "timm";
|
|
4
|
+
|
|
5
|
+
import type { BindingInstance, BindingFactory } from "../../binding";
|
|
6
|
+
import { isBinding } from "../../binding";
|
|
7
|
+
import type { DataModelWithParser, DataModelMiddleware } from "../../data";
|
|
8
|
+
import type { SchemaController } from "../../schema";
|
|
9
9
|
import type {
|
|
10
10
|
ErrorValidationResponse,
|
|
11
11
|
ValidationObject,
|
|
@@ -15,30 +15,30 @@ import type {
|
|
|
15
15
|
ValidationResponse,
|
|
16
16
|
WarningValidationResponse,
|
|
17
17
|
StrongOrWeakBinding,
|
|
18
|
-
} from
|
|
18
|
+
} from "../../validator";
|
|
19
19
|
import {
|
|
20
20
|
ValidationMiddleware,
|
|
21
21
|
ValidatorRegistry,
|
|
22
22
|
removeBindingAndChildrenFromMap,
|
|
23
|
-
} from
|
|
24
|
-
import type { Logger } from
|
|
25
|
-
import { ProxyLogger } from
|
|
26
|
-
import type { Resolve, ViewInstance } from
|
|
27
|
-
import { caresAboutDataChanges } from
|
|
28
|
-
import { replaceParams } from
|
|
29
|
-
import { resolveDataRefs } from
|
|
23
|
+
} from "../../validator";
|
|
24
|
+
import type { Logger } from "../../logger";
|
|
25
|
+
import { ProxyLogger } from "../../logger";
|
|
26
|
+
import type { Resolve, ViewInstance } from "../../view";
|
|
27
|
+
import { caresAboutDataChanges } from "../../view";
|
|
28
|
+
import { replaceParams } from "../../utils";
|
|
29
|
+
import { resolveDataRefs } from "../../string-resolver";
|
|
30
30
|
import type {
|
|
31
31
|
ExpressionEvaluatorOptions,
|
|
32
32
|
ExpressionType,
|
|
33
|
-
} from
|
|
34
|
-
import type { BindingTracker } from
|
|
35
|
-
import { ValidationBindingTrackerViewPlugin } from
|
|
33
|
+
} from "../../expressions";
|
|
34
|
+
import type { BindingTracker } from "./binding-tracker";
|
|
35
|
+
import { ValidationBindingTrackerViewPlugin } from "./binding-tracker";
|
|
36
36
|
|
|
37
|
-
export const SCHEMA_VALIDATION_PROVIDER_NAME =
|
|
38
|
-
export const VIEW_VALIDATION_PROVIDER_NAME =
|
|
37
|
+
export const SCHEMA_VALIDATION_PROVIDER_NAME = "schema";
|
|
38
|
+
export const VIEW_VALIDATION_PROVIDER_NAME = "view";
|
|
39
39
|
|
|
40
40
|
export const VALIDATION_PROVIDER_NAME_SYMBOL: unique symbol = Symbol.for(
|
|
41
|
-
|
|
41
|
+
"validation-provider-name",
|
|
42
42
|
);
|
|
43
43
|
|
|
44
44
|
export type ValidationObjectWithSource = ValidationObjectWithHandler & {
|
|
@@ -48,12 +48,12 @@ export type ValidationObjectWithSource = ValidationObjectWithHandler & {
|
|
|
48
48
|
|
|
49
49
|
type SimpleValidatorContext = Omit<
|
|
50
50
|
ValidatorContext,
|
|
51
|
-
|
|
51
|
+
"validation" | "schemaType"
|
|
52
52
|
>;
|
|
53
53
|
|
|
54
54
|
interface BaseActiveValidation<T> {
|
|
55
55
|
/** The validation is being actively shown */
|
|
56
|
-
state:
|
|
56
|
+
state: "active";
|
|
57
57
|
|
|
58
58
|
/** The validation response */
|
|
59
59
|
response: T;
|
|
@@ -70,7 +70,7 @@ type ActiveError = BaseActiveValidation<ErrorValidationResponse>;
|
|
|
70
70
|
*/
|
|
71
71
|
type StatefulWarning = {
|
|
72
72
|
/** A common key to differentiate between errors and warnings */
|
|
73
|
-
type:
|
|
73
|
+
type: "warning";
|
|
74
74
|
|
|
75
75
|
/** The underlying validation this tracks */
|
|
76
76
|
value: ValidationObjectWithSource;
|
|
@@ -80,7 +80,7 @@ type StatefulWarning = {
|
|
|
80
80
|
} & (
|
|
81
81
|
| {
|
|
82
82
|
/** warnings start with no state, but can active or dismissed */
|
|
83
|
-
state:
|
|
83
|
+
state: "none" | "dismissed";
|
|
84
84
|
}
|
|
85
85
|
| ActiveWarning
|
|
86
86
|
);
|
|
@@ -88,7 +88,7 @@ type StatefulWarning = {
|
|
|
88
88
|
/** Errors that keep track of their state */
|
|
89
89
|
type StatefulError = {
|
|
90
90
|
/** A common key to differentiate between errors and warnings */
|
|
91
|
-
type:
|
|
91
|
+
type: "error";
|
|
92
92
|
|
|
93
93
|
/** The underlying validation this tracks */
|
|
94
94
|
value: ValidationObjectWithSource;
|
|
@@ -98,7 +98,7 @@ type StatefulError = {
|
|
|
98
98
|
} & (
|
|
99
99
|
| {
|
|
100
100
|
/** Errors start with no state an can be activated */
|
|
101
|
-
state:
|
|
101
|
+
state: "none";
|
|
102
102
|
}
|
|
103
103
|
| ActiveError
|
|
104
104
|
);
|
|
@@ -114,12 +114,12 @@ function isSubset<T>(subset: Set<T>, containingSet: Set<T>): boolean {
|
|
|
114
114
|
|
|
115
115
|
/** Helper for initializing a validation object that tracks state */
|
|
116
116
|
function createStatefulValidationObject(
|
|
117
|
-
obj: ValidationObjectWithSource
|
|
117
|
+
obj: ValidationObjectWithSource,
|
|
118
118
|
): StatefulValidationObject {
|
|
119
119
|
return {
|
|
120
120
|
value: obj,
|
|
121
121
|
type: obj.severity,
|
|
122
|
-
state:
|
|
122
|
+
state: "none",
|
|
123
123
|
isBlockingNavigation: false,
|
|
124
124
|
};
|
|
125
125
|
}
|
|
@@ -156,7 +156,7 @@ class ValidatedBinding {
|
|
|
156
156
|
possibleValidations: Array<ValidationObjectWithSource>,
|
|
157
157
|
onDismiss?: () => void,
|
|
158
158
|
log?: Logger,
|
|
159
|
-
weakBindings?: Set<BindingInstance
|
|
159
|
+
weakBindings?: Set<BindingInstance>,
|
|
160
160
|
) {
|
|
161
161
|
this.onDismiss = onDismiss;
|
|
162
162
|
possibleValidations.forEach((vObj) => {
|
|
@@ -173,7 +173,7 @@ class ValidatedBinding {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
private checkIfBlocking(statefulObj: StatefulValidationObject) {
|
|
176
|
-
if (statefulObj.state ===
|
|
176
|
+
if (statefulObj.state === "active") {
|
|
177
177
|
const { isBlockingNavigation } = statefulObj;
|
|
178
178
|
return isBlockingNavigation;
|
|
179
179
|
}
|
|
@@ -183,7 +183,7 @@ class ValidatedBinding {
|
|
|
183
183
|
|
|
184
184
|
public getAll(): Array<ValidationResponse> {
|
|
185
185
|
return this.applicableValidations.reduce((all, statefulObj) => {
|
|
186
|
-
if (statefulObj.state ===
|
|
186
|
+
if (statefulObj.state === "active" && statefulObj.response) {
|
|
187
187
|
all.push({
|
|
188
188
|
...statefulObj.response,
|
|
189
189
|
blocking: this.checkIfBlocking(statefulObj),
|
|
@@ -196,10 +196,10 @@ class ValidatedBinding {
|
|
|
196
196
|
|
|
197
197
|
public get(): ValidationResponse | undefined {
|
|
198
198
|
const firstInvalid = this.applicableValidations.find((statefulObj) => {
|
|
199
|
-
return statefulObj.state ===
|
|
199
|
+
return statefulObj.state === "active" && statefulObj.response;
|
|
200
200
|
});
|
|
201
201
|
|
|
202
|
-
if (firstInvalid?.state ===
|
|
202
|
+
if (firstInvalid?.state === "active") {
|
|
203
203
|
return {
|
|
204
204
|
...firstInvalid.response,
|
|
205
205
|
blocking: this.checkIfBlocking(firstInvalid),
|
|
@@ -210,12 +210,12 @@ class ValidatedBinding {
|
|
|
210
210
|
private runApplicableValidations(
|
|
211
211
|
runner: ValidationRunner,
|
|
212
212
|
canDismiss: boolean,
|
|
213
|
-
phase: Validation.Trigger
|
|
213
|
+
phase: Validation.Trigger,
|
|
214
214
|
) {
|
|
215
215
|
// If the currentState is not load, skip those
|
|
216
216
|
this.applicableValidations = this.applicableValidations.map(
|
|
217
217
|
(originalValue) => {
|
|
218
|
-
if (originalValue.state ===
|
|
218
|
+
if (originalValue.state === "dismissed") {
|
|
219
219
|
// Don't rerun any dismissed warnings
|
|
220
220
|
return originalValue;
|
|
221
221
|
}
|
|
@@ -223,32 +223,32 @@ class ValidatedBinding {
|
|
|
223
223
|
// treat all warnings the same and block it once (unless blocking is true)
|
|
224
224
|
const blocking =
|
|
225
225
|
originalValue.value.blocking ??
|
|
226
|
-
((originalValue.value.severity ===
|
|
226
|
+
((originalValue.value.severity === "warning" && "once") || true);
|
|
227
227
|
|
|
228
228
|
const obj = setIn(
|
|
229
229
|
originalValue,
|
|
230
|
-
[
|
|
231
|
-
blocking
|
|
230
|
+
["value", "blocking"],
|
|
231
|
+
blocking,
|
|
232
232
|
) as StatefulValidationObject;
|
|
233
233
|
|
|
234
234
|
const isBlockingNavigation =
|
|
235
|
-
blocking === true || (blocking ===
|
|
235
|
+
blocking === true || (blocking === "once" && !canDismiss);
|
|
236
236
|
|
|
237
237
|
if (
|
|
238
|
-
phase ===
|
|
239
|
-
obj.state ===
|
|
238
|
+
phase === "navigation" &&
|
|
239
|
+
obj.state === "active" &&
|
|
240
240
|
obj.value.blocking !== true
|
|
241
241
|
) {
|
|
242
|
-
if (obj.value.severity ===
|
|
242
|
+
if (obj.value.severity === "warning") {
|
|
243
243
|
const warn = obj as ActiveWarning;
|
|
244
244
|
if (
|
|
245
245
|
warn.dismissable &&
|
|
246
246
|
warn.response.dismiss &&
|
|
247
|
-
(warn.response.blocking !==
|
|
247
|
+
(warn.response.blocking !== "once" || !warn.response.blocking)
|
|
248
248
|
) {
|
|
249
249
|
warn.response.dismiss();
|
|
250
250
|
} else {
|
|
251
|
-
if (warn?.response.blocking ===
|
|
251
|
+
if (warn?.response.blocking === "once") {
|
|
252
252
|
warn.response.blocking = false;
|
|
253
253
|
}
|
|
254
254
|
|
|
@@ -264,63 +264,63 @@ class ValidatedBinding {
|
|
|
264
264
|
const newState = {
|
|
265
265
|
type: obj.type,
|
|
266
266
|
value: obj.value,
|
|
267
|
-
state: response ?
|
|
267
|
+
state: response ? "active" : "none",
|
|
268
268
|
isBlockingNavigation,
|
|
269
269
|
dismissable:
|
|
270
|
-
obj.value.severity ===
|
|
270
|
+
obj.value.severity === "warning" && phase === "navigation",
|
|
271
271
|
response: response
|
|
272
272
|
? {
|
|
273
273
|
...obj.value,
|
|
274
|
-
message: response.message ??
|
|
274
|
+
message: response.message ?? "Something is broken",
|
|
275
275
|
severity: obj.value.severity,
|
|
276
|
-
displayTarget: obj.value.displayTarget ??
|
|
276
|
+
displayTarget: obj.value.displayTarget ?? "field",
|
|
277
277
|
}
|
|
278
278
|
: undefined,
|
|
279
279
|
} as StatefulValidationObject;
|
|
280
280
|
|
|
281
|
-
if (newState.state ===
|
|
281
|
+
if (newState.state === "active" && obj.value.severity === "warning") {
|
|
282
282
|
(newState.response as WarningValidationResponse).dismiss = () => {
|
|
283
|
-
(newState as StatefulWarning).state =
|
|
283
|
+
(newState as StatefulWarning).state = "dismissed";
|
|
284
284
|
this.onDismiss?.();
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
return newState;
|
|
289
|
-
}
|
|
289
|
+
},
|
|
290
290
|
);
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
public update(
|
|
294
294
|
phase: Validation.Trigger,
|
|
295
295
|
canDismiss: boolean,
|
|
296
|
-
runner: ValidationRunner
|
|
296
|
+
runner: ValidationRunner,
|
|
297
297
|
) {
|
|
298
298
|
const newApplicableValidations: StatefulValidationObject[] = [];
|
|
299
299
|
|
|
300
|
-
if (phase ===
|
|
300
|
+
if (phase === "load" && this.currentPhase !== undefined) {
|
|
301
301
|
// Tried to run the 'load' phase twice. Aborting
|
|
302
302
|
return;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
if (this.currentPhase ===
|
|
305
|
+
if (this.currentPhase === "navigation" || phase === this.currentPhase) {
|
|
306
306
|
// Already added all the types. No need to continue adding new validations
|
|
307
307
|
this.runApplicableValidations(runner, canDismiss, phase);
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
if (phase ===
|
|
312
|
-
this.currentPhase =
|
|
311
|
+
if (phase === "load") {
|
|
312
|
+
this.currentPhase = "load";
|
|
313
313
|
this.applicableValidations = [...this.validationsByState.load];
|
|
314
|
-
} else if (phase ===
|
|
315
|
-
this.currentPhase =
|
|
314
|
+
} else if (phase === "change" && this.currentPhase === "load") {
|
|
315
|
+
this.currentPhase = "change";
|
|
316
316
|
// The transition to the 'change' type can only come from a 'load' type
|
|
317
317
|
this.applicableValidations = [
|
|
318
318
|
...this.applicableValidations,
|
|
319
319
|
...this.validationsByState.change,
|
|
320
320
|
];
|
|
321
321
|
} else if (
|
|
322
|
-
phase ===
|
|
323
|
-
(this.currentPhase ===
|
|
322
|
+
phase === "navigation" &&
|
|
323
|
+
(this.currentPhase === "load" || this.currentPhase === "change")
|
|
324
324
|
) {
|
|
325
325
|
// Can transition to a nav state from a change or load
|
|
326
326
|
|
|
@@ -329,8 +329,8 @@ class ValidatedBinding {
|
|
|
329
329
|
this.applicableValidations.forEach((element) => {
|
|
330
330
|
if (
|
|
331
331
|
!(
|
|
332
|
-
element.type ===
|
|
333
|
-
element.state ===
|
|
332
|
+
element.type === "error" &&
|
|
333
|
+
element.state === "active" &&
|
|
334
334
|
element.isBlockingNavigation === false
|
|
335
335
|
)
|
|
336
336
|
) {
|
|
@@ -341,9 +341,9 @@ class ValidatedBinding {
|
|
|
341
341
|
this.applicableValidations = [
|
|
342
342
|
...newApplicableValidations,
|
|
343
343
|
...this.validationsByState.navigation,
|
|
344
|
-
...(this.currentPhase ===
|
|
344
|
+
...(this.currentPhase === "load" ? this.validationsByState.change : []),
|
|
345
345
|
];
|
|
346
|
-
this.currentPhase =
|
|
346
|
+
this.currentPhase = "navigation";
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
this.runApplicableValidations(runner, canDismiss, phase);
|
|
@@ -391,7 +391,7 @@ export class ValidationController implements BindingTracker {
|
|
|
391
391
|
source: string;
|
|
392
392
|
/** The provider itself */
|
|
393
393
|
provider: ValidationProvider;
|
|
394
|
-
}
|
|
394
|
+
}>,
|
|
395
395
|
],
|
|
396
396
|
{
|
|
397
397
|
/** The view this is triggered for */
|
|
@@ -444,7 +444,7 @@ export class ValidationController implements BindingTracker {
|
|
|
444
444
|
delete: (binding, options, next) => {
|
|
445
445
|
this.validations = removeBindingAndChildrenFromMap(
|
|
446
446
|
this.validations,
|
|
447
|
-
binding
|
|
447
|
+
binding,
|
|
448
448
|
);
|
|
449
449
|
|
|
450
450
|
return next?.delete(binding, options);
|
|
@@ -456,11 +456,11 @@ export class ValidationController implements BindingTracker {
|
|
|
456
456
|
return;
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
this.updateValidationsForBinding(binding,
|
|
459
|
+
this.updateValidationsForBinding(binding, "change", this.options);
|
|
460
460
|
const strongValidation = this.getValidationForBinding(binding);
|
|
461
461
|
|
|
462
462
|
// return validation issues directly on bindings first
|
|
463
|
-
if (strongValidation?.get()?.severity ===
|
|
463
|
+
if (strongValidation?.get()?.severity === "error") {
|
|
464
464
|
return strongValidation.get();
|
|
465
465
|
}
|
|
466
466
|
|
|
@@ -470,9 +470,9 @@ export class ValidationController implements BindingTracker {
|
|
|
470
470
|
if (
|
|
471
471
|
caresAboutDataChanges(
|
|
472
472
|
new Set([binding]),
|
|
473
|
-
weakValidation.weakBindings
|
|
473
|
+
weakValidation.weakBindings,
|
|
474
474
|
) &&
|
|
475
|
-
weakValidation?.get()?.severity ===
|
|
475
|
+
weakValidation?.get()?.severity === "error"
|
|
476
476
|
) {
|
|
477
477
|
weakValidation?.weakBindings.forEach((weakBinding) => {
|
|
478
478
|
if (weakBinding === strongBinding) {
|
|
@@ -494,7 +494,7 @@ export class ValidationController implements BindingTracker {
|
|
|
494
494
|
return newInvalidBindings;
|
|
495
495
|
}
|
|
496
496
|
},
|
|
497
|
-
{ logger: new ProxyLogger(() => this.options?.logger) }
|
|
497
|
+
{ logger: new ProxyLogger(() => this.options?.logger) },
|
|
498
498
|
),
|
|
499
499
|
];
|
|
500
500
|
}
|
|
@@ -513,10 +513,10 @@ export class ValidationController implements BindingTracker {
|
|
|
513
513
|
source: VIEW_VALIDATION_PROVIDER_NAME,
|
|
514
514
|
provider: {
|
|
515
515
|
getValidationsForBinding: (
|
|
516
|
-
binding: BindingInstance
|
|
516
|
+
binding: BindingInstance,
|
|
517
517
|
): Array<ValidationObject> | undefined => {
|
|
518
518
|
return this.viewValidationProvider?.getValidationsForBinding?.(
|
|
519
|
-
binding
|
|
519
|
+
binding,
|
|
520
520
|
);
|
|
521
521
|
},
|
|
522
522
|
|
|
@@ -567,11 +567,11 @@ export class ValidationController implements BindingTracker {
|
|
|
567
567
|
|
|
568
568
|
this.updateValidationsForBinding(
|
|
569
569
|
binding,
|
|
570
|
-
|
|
570
|
+
"load",
|
|
571
571
|
this.options,
|
|
572
572
|
() => {
|
|
573
573
|
view.update(new Set([binding]));
|
|
574
|
-
}
|
|
574
|
+
},
|
|
575
575
|
);
|
|
576
576
|
|
|
577
577
|
this.hooks.onTrackBinding.call(binding);
|
|
@@ -589,7 +589,7 @@ export class ValidationController implements BindingTracker {
|
|
|
589
589
|
binding: BindingInstance,
|
|
590
590
|
trigger: Validation.Trigger,
|
|
591
591
|
validationContext?: SimpleValidatorContext,
|
|
592
|
-
onDismiss?: () => void
|
|
592
|
+
onDismiss?: () => void,
|
|
593
593
|
): void {
|
|
594
594
|
const context = validationContext ?? this.options;
|
|
595
595
|
|
|
@@ -597,7 +597,7 @@ export class ValidationController implements BindingTracker {
|
|
|
597
597
|
throw new Error(`Context is required for executing validations`);
|
|
598
598
|
}
|
|
599
599
|
|
|
600
|
-
if (trigger ===
|
|
600
|
+
if (trigger === "load") {
|
|
601
601
|
// Get all of the validations from each provider
|
|
602
602
|
const possibleValidations = this.getValidationProviders().reduce<
|
|
603
603
|
Array<ValidationObjectWithSource>
|
|
@@ -608,7 +608,7 @@ export class ValidationController implements BindingTracker {
|
|
|
608
608
|
?.map((valObj) => ({
|
|
609
609
|
...valObj,
|
|
610
610
|
[VALIDATION_PROVIDER_NAME_SYMBOL]: provider.source,
|
|
611
|
-
})) ?? [])
|
|
611
|
+
})) ?? []),
|
|
612
612
|
);
|
|
613
613
|
|
|
614
614
|
return vals;
|
|
@@ -623,8 +623,8 @@ export class ValidationController implements BindingTracker {
|
|
|
623
623
|
new ValidatedBinding(
|
|
624
624
|
possibleValidations,
|
|
625
625
|
onDismiss,
|
|
626
|
-
this.options?.logger
|
|
627
|
-
)
|
|
626
|
+
this.options?.logger,
|
|
627
|
+
),
|
|
628
628
|
);
|
|
629
629
|
}
|
|
630
630
|
|
|
@@ -641,7 +641,7 @@ export class ValidationController implements BindingTracker {
|
|
|
641
641
|
});
|
|
642
642
|
|
|
643
643
|
// Also run any validations that binding or sub-binding is a weak binding of
|
|
644
|
-
if (trigger !==
|
|
644
|
+
if (trigger !== "load") {
|
|
645
645
|
this.validations.forEach((validation, vBinding) => {
|
|
646
646
|
if (
|
|
647
647
|
vBinding !== binding &&
|
|
@@ -651,7 +651,7 @@ export class ValidationController implements BindingTracker {
|
|
|
651
651
|
const response = this.validationRunner(
|
|
652
652
|
validationObj,
|
|
653
653
|
vBinding,
|
|
654
|
-
context
|
|
654
|
+
context,
|
|
655
655
|
);
|
|
656
656
|
return response ? { message: response.message } : undefined;
|
|
657
657
|
});
|
|
@@ -663,10 +663,10 @@ export class ValidationController implements BindingTracker {
|
|
|
663
663
|
validationRunner(
|
|
664
664
|
validationObj: ValidationObjectWithHandler,
|
|
665
665
|
binding: BindingInstance,
|
|
666
|
-
context: SimpleValidatorContext | undefined = this.options
|
|
666
|
+
context: SimpleValidatorContext | undefined = this.options,
|
|
667
667
|
) {
|
|
668
668
|
if (!context) {
|
|
669
|
-
throw new Error(
|
|
669
|
+
throw new Error("No context provided to validation runner");
|
|
670
670
|
}
|
|
671
671
|
|
|
672
672
|
const handler =
|
|
@@ -689,7 +689,7 @@ export class ValidationController implements BindingTracker {
|
|
|
689
689
|
...context,
|
|
690
690
|
evaluate: (
|
|
691
691
|
exp: ExpressionType,
|
|
692
|
-
options: ExpressionEvaluatorOptions = { model }
|
|
692
|
+
options: ExpressionEvaluatorOptions = { model },
|
|
693
693
|
) => context.evaluate(exp, options),
|
|
694
694
|
model,
|
|
695
695
|
validation: validationObj,
|
|
@@ -697,9 +697,9 @@ export class ValidationController implements BindingTracker {
|
|
|
697
697
|
},
|
|
698
698
|
context.model.get(binding, {
|
|
699
699
|
includeInvalid: true,
|
|
700
|
-
formatted: validationObj.dataTarget ===
|
|
700
|
+
formatted: validationObj.dataTarget === "formatted",
|
|
701
701
|
}),
|
|
702
|
-
validationObj
|
|
702
|
+
validationObj,
|
|
703
703
|
);
|
|
704
704
|
|
|
705
705
|
this.weakBindingTracker = weakBindings;
|
|
@@ -725,7 +725,7 @@ export class ValidationController implements BindingTracker {
|
|
|
725
725
|
}
|
|
726
726
|
|
|
727
727
|
private updateValidationsForView(trigger: Validation.Trigger): void {
|
|
728
|
-
const isNavigationTrigger = trigger ===
|
|
728
|
+
const isNavigationTrigger = trigger === "navigation";
|
|
729
729
|
const lastActiveBindings = this.activeBindings;
|
|
730
730
|
|
|
731
731
|
/** Run validations for all bindings in view */
|
|
@@ -758,8 +758,8 @@ export class ValidationController implements BindingTracker {
|
|
|
758
758
|
private get activeBindings(): Set<BindingInstance> {
|
|
759
759
|
return new Set(
|
|
760
760
|
Array.from(this.getBindings()).filter(
|
|
761
|
-
(b) => this.validations.get(b)?.get() !== undefined
|
|
762
|
-
)
|
|
761
|
+
(b) => this.validations.get(b)?.get() !== undefined,
|
|
762
|
+
),
|
|
763
763
|
);
|
|
764
764
|
}
|
|
765
765
|
|
|
@@ -784,7 +784,7 @@ export class ValidationController implements BindingTracker {
|
|
|
784
784
|
}
|
|
785
785
|
|
|
786
786
|
/** Executes all known validations for the tracked bindings using the given model */
|
|
787
|
-
validateView(trigger: Validation.Trigger =
|
|
787
|
+
validateView(trigger: Validation.Trigger = "navigation"): {
|
|
788
788
|
/** Indicating if the view can proceed without error */
|
|
789
789
|
canTransition: boolean;
|
|
790
790
|
|
|
@@ -801,11 +801,11 @@ export class ValidationController implements BindingTracker {
|
|
|
801
801
|
const allValidations = this.getValidationForBinding(b)?.getAll();
|
|
802
802
|
|
|
803
803
|
allValidations?.forEach((v) => {
|
|
804
|
-
if (trigger ===
|
|
804
|
+
if (trigger === "navigation" && v.blocking) {
|
|
805
805
|
this.options?.logger.debug(
|
|
806
806
|
`Validation on binding: ${b.asString()} is preventing navigation. ${JSON.stringify(
|
|
807
|
-
v
|
|
808
|
-
)}
|
|
807
|
+
v,
|
|
808
|
+
)}`,
|
|
809
809
|
);
|
|
810
810
|
|
|
811
811
|
canTransition = false;
|
|
@@ -825,7 +825,7 @@ export class ValidationController implements BindingTracker {
|
|
|
825
825
|
|
|
826
826
|
/** Get the current tracked validation for the given binding */
|
|
827
827
|
public getValidationForBinding(
|
|
828
|
-
binding: BindingInstance
|
|
828
|
+
binding: BindingInstance,
|
|
829
829
|
): ValidatedBinding | undefined {
|
|
830
830
|
return this.validations.get(binding);
|
|
831
831
|
}
|
|
@@ -834,7 +834,7 @@ export class ValidationController implements BindingTracker {
|
|
|
834
834
|
return {
|
|
835
835
|
_getValidationForBinding: (binding) => {
|
|
836
836
|
return this.getValidationForBinding(
|
|
837
|
-
isBinding(binding) ? binding : parser(binding)
|
|
837
|
+
isBinding(binding) ? binding : parser(binding),
|
|
838
838
|
);
|
|
839
839
|
},
|
|
840
840
|
getAll: () => {
|
|
@@ -859,23 +859,23 @@ export class ValidationController implements BindingTracker {
|
|
|
859
859
|
return validationMapping.size === 0 ? undefined : validationMapping;
|
|
860
860
|
},
|
|
861
861
|
get() {
|
|
862
|
-
throw new Error(
|
|
862
|
+
throw new Error("Error Access be provided by the view plugin");
|
|
863
863
|
},
|
|
864
864
|
getValidationsForBinding() {
|
|
865
|
-
throw new Error(
|
|
865
|
+
throw new Error("Error rollup should be provided by the view plugin");
|
|
866
866
|
},
|
|
867
867
|
getChildren() {
|
|
868
|
-
throw new Error(
|
|
868
|
+
throw new Error("Error rollup should be provided by the view plugin");
|
|
869
869
|
},
|
|
870
870
|
getValidationsForSection() {
|
|
871
|
-
throw new Error(
|
|
871
|
+
throw new Error("Error rollup should be provided by the view plugin");
|
|
872
872
|
},
|
|
873
873
|
track: () => {
|
|
874
|
-
throw new Error(
|
|
874
|
+
throw new Error("Tracking should be provided by the view plugin");
|
|
875
875
|
},
|
|
876
876
|
register: () => {
|
|
877
877
|
throw new Error(
|
|
878
|
-
|
|
878
|
+
"Section functionality should be provided by the view plugin",
|
|
879
879
|
);
|
|
880
880
|
},
|
|
881
881
|
type: (binding) =>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./controller";
|
|
2
|
+
export * from "./binding-tracker";
|