@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.
Files changed (48) hide show
  1. package/dist/Player.native.js +469 -4094
  2. package/dist/Player.native.js.map +1 -1
  3. package/dist/cjs/index.cjs +293 -407
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/index.legacy-esm.js +291 -409
  6. package/dist/index.mjs +291 -409
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +4 -8
  9. package/src/binding/__tests__/resolver.test.ts +4 -4
  10. package/src/binding-grammar/{ebnf → __tests__/ebnf}/index.ts +2 -2
  11. package/src/binding-grammar/__tests__/parser.test.ts +2 -2
  12. package/src/binding-grammar/{parsimmon → __tests__/parsimmon}/index.ts +2 -2
  13. package/src/binding-grammar/index.ts +0 -2
  14. package/src/plugins/default-view-plugin.ts +4 -0
  15. package/src/view/__tests__/view.immutable.test.ts +8 -1
  16. package/src/view/__tests__/view.test.ts +59 -1
  17. package/src/view/parser/__tests__/parser.test.ts +16 -1
  18. package/src/view/parser/index.ts +46 -262
  19. package/src/view/parser/utils.ts +23 -3
  20. package/src/view/plugins/__tests__/__snapshots__/asset.test.ts.snap +215 -0
  21. package/src/view/plugins/__tests__/__snapshots__/multi-node.test.ts.snap +67 -0
  22. package/src/view/plugins/__tests__/__snapshots__/template.test.ts.snap +56 -54
  23. package/src/view/plugins/__tests__/applicability.test.ts +24 -16
  24. package/src/view/plugins/__tests__/asset.test.ts +140 -0
  25. package/src/view/plugins/__tests__/multi-node.test.ts +38 -0
  26. package/src/view/plugins/__tests__/template.test.ts +48 -388
  27. package/src/view/plugins/applicability.ts +39 -23
  28. package/src/view/plugins/asset.ts +42 -0
  29. package/src/view/plugins/index.ts +3 -1
  30. package/src/view/plugins/multi-node.ts +73 -0
  31. package/src/view/plugins/switch.ts +81 -50
  32. package/src/view/plugins/{template-plugin.ts → template.ts} +38 -24
  33. package/src/view/resolver/__tests__/edgecases.test.ts +14 -1
  34. package/src/view/view.ts +2 -7
  35. package/types/binding-grammar/index.d.ts +0 -2
  36. package/types/view/parser/index.d.ts +6 -11
  37. package/types/view/parser/utils.d.ts +11 -2
  38. package/types/view/plugins/applicability.d.ts +1 -0
  39. package/types/view/plugins/asset.d.ts +8 -0
  40. package/types/view/plugins/index.d.ts +3 -1
  41. package/types/view/plugins/multi-node.d.ts +8 -0
  42. package/types/view/plugins/switch.d.ts +2 -1
  43. package/types/view/plugins/{template-plugin.d.ts → template.d.ts} +2 -2
  44. package/types/binding-grammar/ebnf/index.d.ts +0 -4
  45. package/types/binding-grammar/ebnf/types.d.ts +0 -75
  46. package/types/binding-grammar/parsimmon/index.d.ts +0 -4
  47. /package/src/binding-grammar/{ebnf → __tests__/ebnf}/binding.ebnf +0 -0
  48. /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.0",
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.0",
7
- "@player-ui/make-flow": "0.8.0-next.0",
8
- "@player-ui/types": "0.8.0-next.0",
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 { parseParsimmon } from "../../binding-grammar";
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 = parseParsimmon(binding);
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 = parseParsimmon("foo.{{BASE_PATH}}.bar");
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 = parseParsimmon("foo.bar.`exp()`");
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 "../ast";
11
+ } from "../../ast";
12
12
  import {
13
13
  toValue,
14
14
  toQuery,
15
15
  toPath,
16
16
  toConcatenatedNode,
17
17
  toExpression,
18
- } from "../ast";
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 "../parsimmon";
10
- import { parse as parseEBNF } from "../ebnf";
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 "../ast";
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 "../ast";
11
+ } from "../../ast";
12
12
 
13
13
  const doubleQuote = P.string('"');
14
14
  const singleQuote = P.string("'");
@@ -1,4 +1,2 @@
1
1
  export * from "./ast";
2
- export { parse as parseParsimmon } from "./parsimmon";
3
- export { parse as parseEBNF } from "./ebnf";
4
2
  export { parse as parseCustom } from "./custom";
@@ -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 { ApplicabilityPlugin, StringResolverPlugin, ViewInstance } from "..";
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 { SwitchPlugin, ApplicabilityPlugin, TemplatePlugin } from "../..";
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();