@player-ui/player 0.8.0-next.0 → 0.8.0-next.10
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 +469 -4094
- package/dist/Player.native.js.map +1 -1
- package/dist/cjs/index.cjs +293 -407
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +291 -409
- package/dist/index.mjs +291 -409
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -8
- package/src/binding/__tests__/resolver.test.ts +4 -4
- package/src/binding-grammar/{ebnf → __tests__/ebnf}/index.ts +2 -2
- package/src/binding-grammar/__tests__/parser.test.ts +2 -2
- package/src/binding-grammar/{parsimmon → __tests__/parsimmon}/index.ts +2 -2
- package/src/binding-grammar/index.ts +0 -2
- package/src/plugins/default-view-plugin.ts +4 -0
- package/src/view/__tests__/view.immutable.test.ts +8 -1
- package/src/view/__tests__/view.test.ts +59 -1
- package/src/view/parser/__tests__/parser.test.ts +16 -1
- package/src/view/parser/index.ts +46 -262
- package/src/view/parser/utils.ts +23 -3
- package/src/view/plugins/__tests__/__snapshots__/asset.test.ts.snap +215 -0
- package/src/view/plugins/__tests__/__snapshots__/multi-node.test.ts.snap +67 -0
- package/src/view/plugins/__tests__/__snapshots__/template.test.ts.snap +56 -54
- package/src/view/plugins/__tests__/applicability.test.ts +24 -16
- package/src/view/plugins/__tests__/asset.test.ts +140 -0
- package/src/view/plugins/__tests__/multi-node.test.ts +38 -0
- package/src/view/plugins/__tests__/template.test.ts +48 -388
- package/src/view/plugins/applicability.ts +39 -23
- package/src/view/plugins/asset.ts +42 -0
- package/src/view/plugins/index.ts +3 -1
- package/src/view/plugins/multi-node.ts +73 -0
- package/src/view/plugins/switch.ts +81 -50
- package/src/view/plugins/{template-plugin.ts → template.ts} +38 -24
- package/src/view/resolver/__tests__/edgecases.test.ts +14 -1
- package/src/view/view.ts +2 -7
- package/types/binding-grammar/index.d.ts +0 -2
- package/types/view/parser/index.d.ts +6 -11
- package/types/view/parser/utils.d.ts +11 -2
- package/types/view/plugins/applicability.d.ts +1 -0
- package/types/view/plugins/asset.d.ts +8 -0
- package/types/view/plugins/index.d.ts +3 -1
- package/types/view/plugins/multi-node.d.ts +8 -0
- package/types/view/plugins/switch.d.ts +2 -1
- package/types/view/plugins/{template-plugin.d.ts → template.d.ts} +2 -2
- package/types/binding-grammar/ebnf/index.d.ts +0 -4
- package/types/binding-grammar/ebnf/types.d.ts +0 -75
- package/types/binding-grammar/parsimmon/index.d.ts +0 -4
- /package/src/binding-grammar/{ebnf → __tests__/ebnf}/binding.ebnf +0 -0
- /package/src/binding-grammar/{ebnf → __tests__/ebnf}/types.ts +0 -0
package/package.json
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/player",
|
|
3
|
-
"version": "0.8.0-next.
|
|
3
|
+
"version": "0.8.0-next.10",
|
|
4
4
|
"main": "dist/cjs/index.cjs",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@player-ui/partial-match-registry": "0.8.0-next.
|
|
7
|
-
"@player-ui/make-flow": "0.8.0-next.
|
|
8
|
-
"@player-ui/types": "0.8.0-next.
|
|
6
|
+
"@player-ui/partial-match-registry": "0.8.0-next.10",
|
|
7
|
+
"@player-ui/make-flow": "0.8.0-next.10",
|
|
8
|
+
"@player-ui/types": "0.8.0-next.10",
|
|
9
9
|
"@types/dlv": "^1.1.4",
|
|
10
|
-
"@types/parsimmon": "^1.10.0",
|
|
11
|
-
"arr-flatten": "^1.1.0",
|
|
12
10
|
"dequal": "^2.0.2",
|
|
13
11
|
"dlv": "^1.1.3",
|
|
14
|
-
"ebnf": "^1.9.0",
|
|
15
12
|
"error-polyfill": "^0.1.3",
|
|
16
13
|
"p-defer": "^3.0.0",
|
|
17
|
-
"parsimmon": "^1.12.0",
|
|
18
14
|
"queue-microtask": "^1.2.3",
|
|
19
15
|
"tapable-ts": "^0.2.3",
|
|
20
16
|
"timm": "^1.6.2",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, test, expect, vitest } from "vitest";
|
|
2
2
|
import get from "dlv";
|
|
3
3
|
import type { ParserSuccessResult } from "../../binding-grammar";
|
|
4
|
-
import {
|
|
4
|
+
import { parseCustom } from "../../binding-grammar";
|
|
5
5
|
import { resolveBindingAST } from "../resolver";
|
|
6
6
|
import { getBindingSegments } from "../utils";
|
|
7
7
|
|
|
@@ -33,7 +33,7 @@ const testCases: Array<[string, string]> = [
|
|
|
33
33
|
];
|
|
34
34
|
|
|
35
35
|
test.each(testCases)("Resolving binding: %s", (binding, expectedResolved) => {
|
|
36
|
-
const parsedBinding =
|
|
36
|
+
const parsedBinding = parseCustom(binding);
|
|
37
37
|
expect(parsedBinding.status).toBe(true);
|
|
38
38
|
const actual = resolveBindingAST(
|
|
39
39
|
(parsedBinding as ParserSuccessResult).path,
|
|
@@ -48,7 +48,7 @@ test.each(testCases)("Resolving binding: %s", (binding, expectedResolved) => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
test("works for nested keys", () => {
|
|
51
|
-
const parsedBinding =
|
|
51
|
+
const parsedBinding = parseCustom("foo.{{BASE_PATH}}.bar");
|
|
52
52
|
expect(parsedBinding.status).toBe(true);
|
|
53
53
|
|
|
54
54
|
const resolved = resolveBindingAST(
|
|
@@ -65,7 +65,7 @@ test("works for nested keys", () => {
|
|
|
65
65
|
|
|
66
66
|
describe("expressions", () => {
|
|
67
67
|
test("evaluates expressions as paths", () => {
|
|
68
|
-
const parsedBinding =
|
|
68
|
+
const parsedBinding = parseCustom("foo.bar.`exp()`");
|
|
69
69
|
|
|
70
70
|
const evaluate = vitest.fn().mockReturnValue(100);
|
|
71
71
|
const resolved = resolveBindingAST(
|
|
@@ -8,14 +8,14 @@ import type {
|
|
|
8
8
|
ConcatenatedNode,
|
|
9
9
|
QueryNode,
|
|
10
10
|
ExpressionNode,
|
|
11
|
-
} from "
|
|
11
|
+
} from "../../ast";
|
|
12
12
|
import {
|
|
13
13
|
toValue,
|
|
14
14
|
toQuery,
|
|
15
15
|
toPath,
|
|
16
16
|
toConcatenatedNode,
|
|
17
17
|
toExpression,
|
|
18
|
-
} from "
|
|
18
|
+
} from "../../ast";
|
|
19
19
|
import type {
|
|
20
20
|
ValueToken,
|
|
21
21
|
ModelRefToken,
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
VALID_AST_PARSER_CUSTOM_TESTS,
|
|
7
7
|
} from "./test-utils/ast-cases";
|
|
8
8
|
import type { ParserSuccessResult, ParserFailureResult } from "../ast";
|
|
9
|
-
import { parse as parseParsimmon } from "
|
|
10
|
-
import { parse as parseEBNF } from "
|
|
9
|
+
import { parse as parseParsimmon } from "./parsimmon";
|
|
10
|
+
import { parse as parseEBNF } from "./ebnf";
|
|
11
11
|
import { parse as parseCustom } from "../custom";
|
|
12
12
|
|
|
13
13
|
describe("parsimmon", () => {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import flatten from "arr-flatten";
|
|
2
2
|
import type { Parser } from "parsimmon";
|
|
3
3
|
import P from "parsimmon";
|
|
4
|
-
import type { Parser as BindingParser } from "
|
|
4
|
+
import type { Parser as BindingParser } from "../../ast";
|
|
5
5
|
import {
|
|
6
6
|
toValue,
|
|
7
7
|
toConcatenatedNode,
|
|
8
8
|
toQuery,
|
|
9
9
|
toPath,
|
|
10
10
|
toExpression,
|
|
11
|
-
} from "
|
|
11
|
+
} from "../../ast";
|
|
12
12
|
|
|
13
13
|
const doubleQuote = P.string('"');
|
|
14
14
|
const singleQuote = P.string("'");
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Player, PlayerPlugin } from "../player";
|
|
2
2
|
import {
|
|
3
3
|
ApplicabilityPlugin,
|
|
4
|
+
AssetPlugin,
|
|
5
|
+
MultiNodePlugin,
|
|
4
6
|
StringResolverPlugin,
|
|
5
7
|
SwitchPlugin,
|
|
6
8
|
TemplatePlugin,
|
|
@@ -17,12 +19,14 @@ export class DefaultViewPlugin implements PlayerPlugin {
|
|
|
17
19
|
player.hooks.viewController.tap(this.name, (viewController) => {
|
|
18
20
|
viewController.hooks.view.tap(this.name, (view) => {
|
|
19
21
|
const pluginOptions = toNodeResolveOptions(view.resolverOptions);
|
|
22
|
+
new AssetPlugin().apply(view);
|
|
20
23
|
new SwitchPlugin(pluginOptions).apply(view);
|
|
21
24
|
new ApplicabilityPlugin().apply(view);
|
|
22
25
|
new StringResolverPlugin().apply(view);
|
|
23
26
|
const templatePlugin = new TemplatePlugin(pluginOptions);
|
|
24
27
|
templatePlugin.apply(view);
|
|
25
28
|
view.hooks.onTemplatePluginCreated.call(templatePlugin);
|
|
29
|
+
new MultiNodePlugin().apply(view);
|
|
26
30
|
});
|
|
27
31
|
});
|
|
28
32
|
}
|
|
@@ -3,7 +3,12 @@ import { LocalModel, withParser, PipelinedDataModel } from "../../data";
|
|
|
3
3
|
import { ExpressionEvaluator } from "../../expressions";
|
|
4
4
|
import { BindingParser } from "../../binding";
|
|
5
5
|
import { SchemaController } from "../../schema";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ApplicabilityPlugin,
|
|
8
|
+
AssetPlugin,
|
|
9
|
+
StringResolverPlugin,
|
|
10
|
+
ViewInstance,
|
|
11
|
+
} from "..";
|
|
7
12
|
import { NodeType } from "../parser";
|
|
8
13
|
|
|
9
14
|
const parseBinding = new BindingParser().parse;
|
|
@@ -34,6 +39,7 @@ test("uses the exact same object if nothing changes", () => {
|
|
|
34
39
|
);
|
|
35
40
|
|
|
36
41
|
new StringResolverPlugin().apply(view);
|
|
42
|
+
new AssetPlugin().apply(view);
|
|
37
43
|
|
|
38
44
|
view.hooks.resolver.tap("input", (resolver) => {
|
|
39
45
|
resolver.hooks.resolve.tap("input", (value, astNode, options) => {
|
|
@@ -205,6 +211,7 @@ test("hardcore immutability", () => {
|
|
|
205
211
|
);
|
|
206
212
|
|
|
207
213
|
new StringResolverPlugin().apply(view);
|
|
214
|
+
new AssetPlugin().apply(view);
|
|
208
215
|
|
|
209
216
|
const resolved = view.update();
|
|
210
217
|
|
|
@@ -4,6 +4,7 @@ import { ExpressionEvaluator } from "../../expressions";
|
|
|
4
4
|
import { BindingParser } from "../../binding";
|
|
5
5
|
import { SchemaController } from "../../schema";
|
|
6
6
|
import {
|
|
7
|
+
MultiNodePlugin,
|
|
7
8
|
StringResolverPlugin,
|
|
8
9
|
SwitchPlugin,
|
|
9
10
|
ViewInstance,
|
|
@@ -80,7 +81,7 @@ describe("view", () => {
|
|
|
80
81
|
expect(updated).toBe(resolved);
|
|
81
82
|
});
|
|
82
83
|
|
|
83
|
-
test("works with no valid switch cases in an array", () => {
|
|
84
|
+
test("works with no valid static switch cases in an array", () => {
|
|
84
85
|
const model = withParser(new LocalModel({}), parseBinding);
|
|
85
86
|
const evaluator = new ExpressionEvaluator({ model });
|
|
86
87
|
const schema = new SchemaController();
|
|
@@ -122,6 +123,7 @@ describe("view", () => {
|
|
|
122
123
|
|
|
123
124
|
const pluginOptions = toNodeResolveOptions(view.resolverOptions);
|
|
124
125
|
new SwitchPlugin(pluginOptions).apply(view);
|
|
126
|
+
new MultiNodePlugin().apply(view);
|
|
125
127
|
new StringResolverPlugin().apply(view);
|
|
126
128
|
|
|
127
129
|
const resolved = view.update();
|
|
@@ -132,6 +134,60 @@ describe("view", () => {
|
|
|
132
134
|
});
|
|
133
135
|
});
|
|
134
136
|
|
|
137
|
+
test("works with no valid dynamic switch cases in an array", () => {
|
|
138
|
+
const model = withParser(new LocalModel({}), parseBinding);
|
|
139
|
+
const evaluator = new ExpressionEvaluator({ model });
|
|
140
|
+
const schema = new SchemaController();
|
|
141
|
+
|
|
142
|
+
const view = new ViewInstance(
|
|
143
|
+
{
|
|
144
|
+
id: "test",
|
|
145
|
+
type: "view",
|
|
146
|
+
title: [
|
|
147
|
+
{
|
|
148
|
+
dynamicSwitch: [
|
|
149
|
+
{
|
|
150
|
+
case: false,
|
|
151
|
+
asset: {
|
|
152
|
+
id: "false-case",
|
|
153
|
+
type: "text",
|
|
154
|
+
value: "some text",
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
case: false,
|
|
159
|
+
asset: {
|
|
160
|
+
id: "false-case-2",
|
|
161
|
+
type: "text",
|
|
162
|
+
value: "some text",
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
model,
|
|
171
|
+
parseBinding,
|
|
172
|
+
evaluator,
|
|
173
|
+
schema,
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const pluginOptions = toNodeResolveOptions(view.resolverOptions);
|
|
178
|
+
new SwitchPlugin(pluginOptions).apply(view);
|
|
179
|
+
new MultiNodePlugin().apply(view);
|
|
180
|
+
new StringResolverPlugin().apply(view);
|
|
181
|
+
|
|
182
|
+
const resolved = view.update();
|
|
183
|
+
|
|
184
|
+
expect(resolved).toStrictEqual({
|
|
185
|
+
id: "test",
|
|
186
|
+
title: [],
|
|
187
|
+
type: "view",
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
135
191
|
it("does not return a field object if the case does not resolve an asset", () => {
|
|
136
192
|
const model = withParser(
|
|
137
193
|
new LocalModel({
|
|
@@ -381,6 +437,7 @@ describe("view", () => {
|
|
|
381
437
|
|
|
382
438
|
const pluginOptions = toNodeResolveOptions(view.resolverOptions);
|
|
383
439
|
new SwitchPlugin(pluginOptions).apply(view);
|
|
440
|
+
new MultiNodePlugin().apply(view);
|
|
384
441
|
new StringResolverPlugin().apply(view);
|
|
385
442
|
|
|
386
443
|
const resolved = view.update();
|
|
@@ -735,6 +792,7 @@ describe("view", () => {
|
|
|
735
792
|
|
|
736
793
|
const pluginOptions = toNodeResolveOptions(view.resolverOptions);
|
|
737
794
|
new SwitchPlugin(pluginOptions).apply(view);
|
|
795
|
+
new MultiNodePlugin().apply(view);
|
|
738
796
|
new StringResolverPlugin().apply(view);
|
|
739
797
|
|
|
740
798
|
const resolved = view.update();
|
|
@@ -3,7 +3,13 @@ import { BindingParser } from "../../../binding";
|
|
|
3
3
|
import { LocalModel, withParser } from "../../../data";
|
|
4
4
|
import { SchemaController } from "../../../schema";
|
|
5
5
|
import { NodeType, Parser } from "../index";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
SwitchPlugin,
|
|
8
|
+
ApplicabilityPlugin,
|
|
9
|
+
TemplatePlugin,
|
|
10
|
+
MultiNodePlugin,
|
|
11
|
+
AssetPlugin,
|
|
12
|
+
} from "../..";
|
|
7
13
|
import type { Options } from "../../plugins/options";
|
|
8
14
|
import { ExpressionEvaluator } from "../../../expressions";
|
|
9
15
|
import type { DataModelWithParser } from "../../../data";
|
|
@@ -30,9 +36,11 @@ describe("generates the correct AST", () => {
|
|
|
30
36
|
model,
|
|
31
37
|
},
|
|
32
38
|
};
|
|
39
|
+
new AssetPlugin().applyParser(parser);
|
|
33
40
|
new TemplatePlugin(options).applyParser(parser);
|
|
34
41
|
new ApplicabilityPlugin().applyParser(parser);
|
|
35
42
|
new SwitchPlugin(options).applyParser(parser);
|
|
43
|
+
new MultiNodePlugin().applyParser(parser);
|
|
36
44
|
});
|
|
37
45
|
|
|
38
46
|
test("works with basic objects", () => {
|
|
@@ -154,8 +162,10 @@ describe("parseView", () => {
|
|
|
154
162
|
model,
|
|
155
163
|
},
|
|
156
164
|
};
|
|
165
|
+
new AssetPlugin().applyParser(parser);
|
|
157
166
|
new TemplatePlugin(options).applyParser(parser);
|
|
158
167
|
new ApplicabilityPlugin().applyParser(parser);
|
|
168
|
+
new MultiNodePlugin().applyParser(parser);
|
|
159
169
|
new SwitchPlugin(options).applyParser(parser);
|
|
160
170
|
});
|
|
161
171
|
|
|
@@ -249,8 +259,13 @@ describe("generates the correct AST when using switch plugin", () => {
|
|
|
249
259
|
return true;
|
|
250
260
|
},
|
|
251
261
|
} as any);
|
|
262
|
+
const multiNodePlugin = new MultiNodePlugin();
|
|
263
|
+
const assetPlugin = new AssetPlugin();
|
|
264
|
+
|
|
252
265
|
const parser = new Parser();
|
|
253
266
|
switchPlugin.applyParser(parser);
|
|
267
|
+
multiNodePlugin.applyParser(parser);
|
|
268
|
+
assetPlugin.applyParser(parser);
|
|
254
269
|
|
|
255
270
|
test("works with asset wrapped objects", () => {
|
|
256
271
|
expect(parser.parseObject(toughStaticSwitchView)).toMatchSnapshot();
|