@player-ui/player 0.3.0-next.3 → 0.3.0-next.4
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/index.cjs.js +4128 -891
- package/dist/index.d.ts +1227 -50
- package/dist/index.esm.js +4065 -836
- package/package.json +9 -15
- package/src/binding/binding.ts +108 -0
- package/src/binding/index.ts +188 -0
- package/src/binding/resolver.ts +157 -0
- package/src/binding/utils.ts +51 -0
- package/src/binding-grammar/ast.ts +113 -0
- package/src/binding-grammar/custom/index.ts +304 -0
- package/src/binding-grammar/ebnf/binding.ebnf +22 -0
- package/src/binding-grammar/ebnf/index.ts +186 -0
- package/src/binding-grammar/ebnf/types.ts +104 -0
- package/src/binding-grammar/index.ts +4 -0
- package/src/binding-grammar/parsimmon/index.ts +78 -0
- package/src/controllers/constants/index.ts +85 -0
- package/src/controllers/constants/utils.ts +37 -0
- package/src/{data.ts → controllers/data.ts} +6 -6
- package/src/controllers/flow/controller.ts +95 -0
- package/src/controllers/flow/flow.ts +205 -0
- package/src/controllers/flow/index.ts +2 -0
- package/src/controllers/index.ts +5 -0
- package/src/{validation → controllers/validation}/binding-tracker.ts +5 -5
- package/src/{validation → controllers/validation}/controller.ts +15 -14
- package/src/{validation → controllers/validation}/index.ts +0 -0
- package/src/{view → controllers/view}/asset-transform.ts +2 -3
- package/src/{view → controllers/view}/controller.ts +9 -8
- package/src/controllers/view/index.ts +4 -0
- package/src/{view → controllers/view}/store.ts +0 -0
- package/src/{view → controllers/view}/types.ts +2 -1
- package/src/data/dependency-tracker.ts +187 -0
- package/src/data/index.ts +4 -0
- package/src/data/local-model.ts +41 -0
- package/src/data/model.ts +216 -0
- package/src/data/noop-model.ts +18 -0
- package/src/expressions/evaluator-functions.ts +29 -0
- package/src/expressions/evaluator.ts +405 -0
- package/src/expressions/index.ts +3 -0
- package/src/expressions/parser.ts +889 -0
- package/src/expressions/types.ts +200 -0
- package/src/expressions/utils.ts +8 -0
- package/src/index.ts +9 -12
- package/src/logger/consoleLogger.ts +49 -0
- package/src/logger/index.ts +5 -0
- package/src/logger/noopLogger.ts +13 -0
- package/src/logger/proxyLogger.ts +25 -0
- package/src/logger/tapableLogger.ts +38 -0
- package/src/logger/types.ts +6 -0
- package/src/player.ts +21 -18
- package/src/plugins/flow-exp-plugin.ts +2 -3
- package/src/schema/index.ts +2 -0
- package/src/schema/schema.ts +220 -0
- package/src/schema/types.ts +60 -0
- package/src/string-resolver/index.ts +188 -0
- package/src/types.ts +11 -13
- package/src/utils/index.ts +1 -0
- package/src/utils/replaceParams.ts +17 -0
- package/src/validator/index.ts +3 -0
- package/src/validator/registry.ts +20 -0
- package/src/validator/types.ts +75 -0
- package/src/validator/validation-middleware.ts +114 -0
- package/src/view/builder/index.ts +81 -0
- package/src/view/index.ts +5 -4
- package/src/view/parser/index.ts +318 -0
- package/src/view/parser/types.ts +141 -0
- package/src/view/plugins/applicability.ts +78 -0
- package/src/view/plugins/index.ts +5 -0
- package/src/view/plugins/options.ts +4 -0
- package/src/view/plugins/plugin.ts +21 -0
- package/src/view/plugins/string-resolver.ts +149 -0
- package/src/view/plugins/switch.ts +120 -0
- package/src/view/plugins/template-plugin.ts +172 -0
- package/src/view/resolver/index.ts +397 -0
- package/src/view/resolver/types.ts +161 -0
- package/src/view/resolver/utils.ts +57 -0
- package/src/view/view.ts +149 -0
- package/src/utils/desc.d.ts +0 -2
package/src/view/view.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { SyncHook } from 'tapable-ts';
|
|
2
|
+
import type { View as ViewType } from '@player-ui/types';
|
|
3
|
+
import type { BindingInstance, BindingFactory } from '../binding';
|
|
4
|
+
import type { ValidationProvider, ValidationObject } from '../validator';
|
|
5
|
+
import type { Logger } from '../logger';
|
|
6
|
+
import type { Resolve } from './resolver';
|
|
7
|
+
import { Resolver, toNodeResolveOptions } from './resolver';
|
|
8
|
+
import type { Node } from './parser';
|
|
9
|
+
import { Parser } from './parser';
|
|
10
|
+
import {
|
|
11
|
+
TemplatePlugin,
|
|
12
|
+
StringResolverPlugin,
|
|
13
|
+
ApplicabilityPlugin,
|
|
14
|
+
SwitchPlugin,
|
|
15
|
+
} from './plugins';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Manages the view level validations
|
|
19
|
+
*/
|
|
20
|
+
class CrossfieldProvider implements ValidationProvider {
|
|
21
|
+
private allValidations = new Set<ValidationObject>();
|
|
22
|
+
private byBinding = new Map<BindingInstance, Array<ValidationObject>>();
|
|
23
|
+
private logger?: Logger;
|
|
24
|
+
|
|
25
|
+
constructor(initialView: ViewType, parser: BindingFactory, logger?: Logger) {
|
|
26
|
+
this.logger = logger;
|
|
27
|
+
this.parse(initialView, parser);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private parse(contentView: ViewType, parser: BindingFactory) {
|
|
31
|
+
const xfieldRefs = contentView.validation;
|
|
32
|
+
|
|
33
|
+
if (xfieldRefs === undefined) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!Array.isArray(xfieldRefs)) {
|
|
38
|
+
this.logger?.warn(
|
|
39
|
+
`Unable to register view validations for id: ${contentView.id}. 'validation' property must be an Array.`
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Grab the validations from the view (as authored) and parse out the ones that have a _ref_ (to a binding)
|
|
46
|
+
// Group them all by binding to make it easier to return than later
|
|
47
|
+
|
|
48
|
+
xfieldRefs.forEach((vRef) => {
|
|
49
|
+
// x-field validations by default are triggered by navigating away from the page
|
|
50
|
+
// the reference can also override that _or_ the severity
|
|
51
|
+
const withDefaults: ValidationObject = {
|
|
52
|
+
trigger: 'navigation',
|
|
53
|
+
severity: 'error',
|
|
54
|
+
...vRef,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
this.allValidations.add(withDefaults);
|
|
58
|
+
|
|
59
|
+
// The validation reference contains a _ref_ (a binding)
|
|
60
|
+
const { ref } = vRef;
|
|
61
|
+
|
|
62
|
+
if (ref) {
|
|
63
|
+
/** Group together validations by binding */
|
|
64
|
+
const parsed = parser(ref);
|
|
65
|
+
|
|
66
|
+
if (this.byBinding.has(parsed)) {
|
|
67
|
+
this.byBinding.get(parsed)?.push(withDefaults);
|
|
68
|
+
} else {
|
|
69
|
+
this.byBinding.set(parsed, [withDefaults]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getValidationsForBinding(binding: BindingInstance) {
|
|
76
|
+
return this.byBinding.get(binding);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A stateful view instance from an content */
|
|
81
|
+
export class ViewInstance implements ValidationProvider {
|
|
82
|
+
public hooks = {
|
|
83
|
+
onUpdate: new SyncHook<[ViewType]>(),
|
|
84
|
+
parser: new SyncHook<[Parser]>(),
|
|
85
|
+
resolver: new SyncHook<[Resolver]>(),
|
|
86
|
+
templatePlugin: new SyncHook<[TemplatePlugin]>(),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
private resolver?: Resolver;
|
|
90
|
+
public readonly initialView: ViewType;
|
|
91
|
+
public readonly resolverOptions: Resolve.ResolverOptions;
|
|
92
|
+
private rootNode?: Node.Node;
|
|
93
|
+
|
|
94
|
+
private validationProvider?: CrossfieldProvider;
|
|
95
|
+
|
|
96
|
+
private templatePlugin: TemplatePlugin;
|
|
97
|
+
|
|
98
|
+
// TODO might want to add a version/timestamp to this to compare updates
|
|
99
|
+
public lastUpdate: Record<string, any> | undefined;
|
|
100
|
+
|
|
101
|
+
constructor(initialView: ViewType, resolverOptions: Resolve.ResolverOptions) {
|
|
102
|
+
this.initialView = initialView;
|
|
103
|
+
this.resolverOptions = resolverOptions;
|
|
104
|
+
const pluginOptions = toNodeResolveOptions(resolverOptions);
|
|
105
|
+
new SwitchPlugin(pluginOptions).apply(this);
|
|
106
|
+
new ApplicabilityPlugin().apply(this);
|
|
107
|
+
new StringResolverPlugin().apply(this);
|
|
108
|
+
this.templatePlugin = new TemplatePlugin(pluginOptions);
|
|
109
|
+
this.templatePlugin.apply(this);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public update(changes?: Set<BindingInstance>) {
|
|
113
|
+
if (this.rootNode === undefined) {
|
|
114
|
+
/** On initialization of the view, also create a validation parser */
|
|
115
|
+
this.validationProvider = new CrossfieldProvider(
|
|
116
|
+
this.initialView,
|
|
117
|
+
this.resolverOptions.parseBinding,
|
|
118
|
+
this.resolverOptions.logger
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
this.hooks.templatePlugin.call(this.templatePlugin);
|
|
122
|
+
|
|
123
|
+
const parser = new Parser();
|
|
124
|
+
this.hooks.parser.call(parser);
|
|
125
|
+
this.rootNode = parser.parseView(this.initialView);
|
|
126
|
+
|
|
127
|
+
this.resolver = new Resolver(this.rootNode, {
|
|
128
|
+
...this.resolverOptions,
|
|
129
|
+
parseNode: parser.parseObject.bind(parser),
|
|
130
|
+
});
|
|
131
|
+
this.hooks.resolver.call(this.resolver);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const update = this.resolver?.update(changes);
|
|
135
|
+
|
|
136
|
+
if (this.lastUpdate === update) {
|
|
137
|
+
return this.lastUpdate;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.lastUpdate = update;
|
|
141
|
+
this.hooks.onUpdate.call(update);
|
|
142
|
+
|
|
143
|
+
return update;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getValidationsForBinding(binding: BindingInstance) {
|
|
147
|
+
return this.validationProvider?.getValidationsForBinding(binding);
|
|
148
|
+
}
|
|
149
|
+
}
|
package/src/utils/desc.d.ts
DELETED