@player-ui/player 0.8.0-next.1 → 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 (37) hide show
  1. package/dist/Player.native.js +246 -252
  2. package/dist/Player.native.js.map +1 -1
  3. package/dist/cjs/index.cjs +208 -268
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/index.legacy-esm.js +206 -270
  6. package/dist/index.mjs +206 -270
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +4 -4
  9. package/src/plugins/default-view-plugin.ts +4 -0
  10. package/src/view/__tests__/view.immutable.test.ts +8 -1
  11. package/src/view/__tests__/view.test.ts +59 -1
  12. package/src/view/parser/__tests__/parser.test.ts +16 -1
  13. package/src/view/parser/index.ts +46 -262
  14. package/src/view/parser/utils.ts +23 -3
  15. package/src/view/plugins/__tests__/__snapshots__/asset.test.ts.snap +215 -0
  16. package/src/view/plugins/__tests__/__snapshots__/multi-node.test.ts.snap +67 -0
  17. package/src/view/plugins/__tests__/__snapshots__/template.test.ts.snap +56 -54
  18. package/src/view/plugins/__tests__/applicability.test.ts +24 -16
  19. package/src/view/plugins/__tests__/asset.test.ts +140 -0
  20. package/src/view/plugins/__tests__/multi-node.test.ts +38 -0
  21. package/src/view/plugins/__tests__/template.test.ts +48 -388
  22. package/src/view/plugins/applicability.ts +39 -23
  23. package/src/view/plugins/asset.ts +42 -0
  24. package/src/view/plugins/index.ts +3 -1
  25. package/src/view/plugins/multi-node.ts +73 -0
  26. package/src/view/plugins/switch.ts +81 -50
  27. package/src/view/plugins/{template-plugin.ts → template.ts} +38 -24
  28. package/src/view/resolver/__tests__/edgecases.test.ts +14 -1
  29. package/src/view/view.ts +2 -7
  30. package/types/view/parser/index.d.ts +6 -11
  31. package/types/view/parser/utils.d.ts +11 -2
  32. package/types/view/plugins/applicability.d.ts +1 -0
  33. package/types/view/plugins/asset.d.ts +8 -0
  34. package/types/view/plugins/index.d.ts +3 -1
  35. package/types/view/plugins/multi-node.d.ts +8 -0
  36. package/types/view/plugins/switch.d.ts +2 -1
  37. package/types/view/plugins/{template-plugin.d.ts → template.d.ts} +2 -2
@@ -0,0 +1,215 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`asset > applicability 1`] = `
4
+ {
5
+ "children": [
6
+ {
7
+ "path": [
8
+ "asset",
9
+ ],
10
+ "value": {
11
+ "children": [
12
+ {
13
+ "path": [
14
+ "values",
15
+ ],
16
+ "value": {
17
+ "override": true,
18
+ "parent": [Circular],
19
+ "type": "multi-node",
20
+ "values": [
21
+ {
22
+ "expression": "{{foo}}",
23
+ "parent": [Circular],
24
+ "type": "applicability",
25
+ "value": {
26
+ "parent": [Circular],
27
+ "type": "value",
28
+ "value": {
29
+ "value": "foo",
30
+ },
31
+ },
32
+ },
33
+ {
34
+ "parent": [Circular],
35
+ "type": "value",
36
+ "value": {
37
+ "value": "bar",
38
+ },
39
+ },
40
+ ],
41
+ },
42
+ },
43
+ ],
44
+ "parent": [Circular],
45
+ "type": "asset",
46
+ "value": undefined,
47
+ },
48
+ },
49
+ ],
50
+ "type": "value",
51
+ "value": undefined,
52
+ }
53
+ `;
54
+
55
+ exports[`asset > multi-node 1`] = `
56
+ {
57
+ "children": [
58
+ {
59
+ "path": [
60
+ "asset",
61
+ ],
62
+ "value": {
63
+ "children": [
64
+ {
65
+ "path": [
66
+ "values",
67
+ ],
68
+ "value": {
69
+ "override": true,
70
+ "parent": [Circular],
71
+ "type": "multi-node",
72
+ "values": [
73
+ {
74
+ "children": [
75
+ {
76
+ "path": [
77
+ "asset",
78
+ ],
79
+ "value": {
80
+ "parent": [Circular],
81
+ "type": "asset",
82
+ "value": {
83
+ "id": "value-1",
84
+ "type": "text",
85
+ "value": "First value in the collection",
86
+ },
87
+ },
88
+ },
89
+ ],
90
+ "parent": [Circular],
91
+ "type": "value",
92
+ "value": undefined,
93
+ },
94
+ ],
95
+ },
96
+ },
97
+ ],
98
+ "parent": [Circular],
99
+ "type": "asset",
100
+ "value": {
101
+ "id": "foo",
102
+ "type": "collection",
103
+ },
104
+ },
105
+ },
106
+ ],
107
+ "type": "value",
108
+ "value": undefined,
109
+ }
110
+ `;
111
+
112
+ exports[`asset > object 1`] = `
113
+ {
114
+ "children": [
115
+ {
116
+ "path": [
117
+ "asset",
118
+ ],
119
+ "value": {
120
+ "parent": [Circular],
121
+ "type": "asset",
122
+ "value": {
123
+ "type": "bar",
124
+ },
125
+ },
126
+ },
127
+ ],
128
+ "type": "value",
129
+ "value": undefined,
130
+ }
131
+ `;
132
+
133
+ exports[`asset > switch 1`] = `
134
+ {
135
+ "children": [
136
+ {
137
+ "path": [
138
+ "title",
139
+ "asset",
140
+ ],
141
+ "value": {
142
+ "parent": [Circular],
143
+ "type": "asset",
144
+ "value": {
145
+ "id": "test",
146
+ "type": "text",
147
+ "value": "test-text.",
148
+ },
149
+ },
150
+ },
151
+ ],
152
+ "type": "value",
153
+ "value": {
154
+ "id": "toughView",
155
+ "type": "view",
156
+ },
157
+ }
158
+ `;
159
+
160
+ exports[`asset > template 1`] = `
161
+ {
162
+ "children": [
163
+ {
164
+ "path": [
165
+ "asset",
166
+ ],
167
+ "value": {
168
+ "children": [
169
+ {
170
+ "path": [
171
+ "values",
172
+ ],
173
+ "value": {
174
+ "override": false,
175
+ "parent": [Circular],
176
+ "type": "multi-node",
177
+ "values": [
178
+ {
179
+ "parent": [Circular],
180
+ "type": "value",
181
+ "value": {
182
+ "value": "{{foo.bar.0}}",
183
+ },
184
+ },
185
+ {
186
+ "parent": [Circular],
187
+ "type": "value",
188
+ "value": {
189
+ "value": "{{foo.bar.1}}",
190
+ },
191
+ },
192
+ {
193
+ "parent": [Circular],
194
+ "type": "value",
195
+ "value": {
196
+ "value": "{{foo.bar.2}}",
197
+ },
198
+ },
199
+ ],
200
+ },
201
+ },
202
+ ],
203
+ "parent": [Circular],
204
+ "type": "asset",
205
+ "value": {
206
+ "id": "foo",
207
+ "type": "collection",
208
+ },
209
+ },
210
+ },
211
+ ],
212
+ "type": "value",
213
+ "value": undefined,
214
+ }
215
+ `;
@@ -0,0 +1,67 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`multi-node > multi-node collection 1`] = `
4
+ {
5
+ "children": [
6
+ {
7
+ "path": [
8
+ "values",
9
+ ],
10
+ "value": {
11
+ "override": true,
12
+ "parent": [Circular],
13
+ "type": "multi-node",
14
+ "values": [
15
+ {
16
+ "children": [
17
+ {
18
+ "path": [
19
+ "asset",
20
+ ],
21
+ "value": {
22
+ "parent": [Circular],
23
+ "type": "asset",
24
+ "value": {
25
+ "id": "value-1",
26
+ "type": "text",
27
+ "value": "First value in the collection",
28
+ },
29
+ },
30
+ },
31
+ ],
32
+ "parent": [Circular],
33
+ "type": "value",
34
+ "value": undefined,
35
+ },
36
+ {
37
+ "children": [
38
+ {
39
+ "path": [
40
+ "asset",
41
+ ],
42
+ "value": {
43
+ "parent": [Circular],
44
+ "type": "asset",
45
+ "value": {
46
+ "id": "value-2",
47
+ "type": "text",
48
+ "value": "Second value in the collection",
49
+ },
50
+ },
51
+ },
52
+ ],
53
+ "parent": [Circular],
54
+ "type": "value",
55
+ "value": undefined,
56
+ },
57
+ ],
58
+ },
59
+ },
60
+ ],
61
+ "type": "value",
62
+ "value": {
63
+ "id": "foo",
64
+ "type": "collection",
65
+ },
66
+ }
67
+ `;
@@ -1,67 +1,69 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`dynamic templates > Works with template items plus value items > Should show template item first when coming before values on lexical order 1`] = `
4
- {
5
- "asset": {
6
- "id": "overviewItem3",
7
- "label": {
8
- "asset": {
9
- "id": "overviewItem3-label",
10
- "type": "text",
11
- "value": "1099-A",
12
- },
4
+ [
5
+ {
6
+ "asset": {
7
+ "id": "value-0",
8
+ "type": "text",
9
+ "value": "item 1",
13
10
  },
14
- "type": "overviewItem",
15
- "values": [
16
- {
17
- "asset": {
18
- "id": "overviewItem3-year",
19
- "type": "text",
20
- "value": "Desciption of concept 1099 1",
21
- },
22
- },
23
- {
24
- "asset": {
25
- "id": "loverviewItem3-cy",
26
- "type": "text",
27
- "value": "4000",
28
- },
29
- },
30
- ],
31
11
  },
32
- }
12
+ {
13
+ "asset": {
14
+ "id": "value-1",
15
+ "type": "text",
16
+ "value": "item 2",
17
+ },
18
+ },
19
+ {
20
+ "asset": {
21
+ "id": "value-2",
22
+ "type": "text",
23
+ "value": "First value in the collection",
24
+ },
25
+ },
26
+ {
27
+ "asset": {
28
+ "id": "value-3",
29
+ "type": "text",
30
+ "value": "Second value in the collection",
31
+ },
32
+ },
33
+ ]
33
34
  `;
34
35
 
35
36
  exports[`dynamic templates > Works with template items plus value items > Should show template item last when coming after values on lexical order 1`] = `
36
- {
37
- "asset": {
38
- "id": "overviewItem1",
39
- "label": {
40
- "asset": {
41
- "id": "overviewItem1-label",
42
- "type": "text",
43
- "value": "First Summary",
44
- },
37
+ [
38
+ {
39
+ "asset": {
40
+ "id": "value-2",
41
+ "type": "text",
42
+ "value": "First value in the collection",
45
43
  },
46
- "type": "overviewItem",
47
- "values": [
48
- {
49
- "asset": {
50
- "id": "overviewItem1-year",
51
- "type": "text",
52
- "value": "Desciption of year summary 1",
53
- },
54
- },
55
- {
56
- "asset": {
57
- "id": "loverviewItem1-cy",
58
- "type": "text",
59
- "value": "14000",
60
- },
61
- },
62
- ],
63
44
  },
64
- }
45
+ {
46
+ "asset": {
47
+ "id": "value-3",
48
+ "type": "text",
49
+ "value": "Second value in the collection",
50
+ },
51
+ },
52
+ {
53
+ "asset": {
54
+ "id": "value-0",
55
+ "type": "text",
56
+ "value": "item 1",
57
+ },
58
+ },
59
+ {
60
+ "asset": {
61
+ "id": "value-1",
62
+ "type": "text",
63
+ "value": "item 2",
64
+ },
65
+ },
66
+ ]
65
67
  `;
66
68
 
67
69
  exports[`templates > works with nested templates 1`] = `
@@ -8,7 +8,7 @@ import type { Resolve } from "../../resolver";
8
8
  import { Resolver } from "../../resolver";
9
9
  import type { Node } from "../../parser";
10
10
  import { Parser } from "../../parser";
11
- import { ApplicabilityPlugin, StringResolverPlugin } from "..";
11
+ import { ApplicabilityPlugin, MultiNodePlugin, StringResolverPlugin } from "..";
12
12
 
13
13
  const parseBinding = new BindingParser().parse;
14
14
 
@@ -37,8 +37,10 @@ describe("applicability", () => {
37
37
  it("undefined does not remove asset", () => {
38
38
  const aP = new ApplicabilityPlugin();
39
39
  const sP = new StringResolverPlugin();
40
+ const mnP = new MultiNodePlugin();
40
41
 
41
42
  aP.applyParser(parser);
43
+ mnP.applyParser(parser);
42
44
 
43
45
  const root = parser.parseObject({
44
46
  asset: {
@@ -70,6 +72,7 @@ describe("applicability", () => {
70
72
 
71
73
  it("removes empty objects", () => {
72
74
  new ApplicabilityPlugin().applyParser(parser);
75
+ new MultiNodePlugin().applyParser(parser);
73
76
  const root = parser.parseObject({
74
77
  asset: {
75
78
  values: [
@@ -245,21 +248,26 @@ describe("applicability", () => {
245
248
  });
246
249
  });
247
250
 
248
- it("determines if nodeType is applicability", () => {
249
- new ApplicabilityPlugin().applyParser(parser);
250
- const nodeTest = {
251
- applicability: "{{bar}} == true",
252
- };
253
- const nodeType = parser.hooks.determineNodeType.call(nodeTest);
254
- expect(nodeType).toStrictEqual("applicability");
255
- });
251
+ it("does not return field object if applicability node does not resolve", () => {
252
+ const applicabilityPlugin = new ApplicabilityPlugin();
253
+ const stringResolverPlugin = new StringResolverPlugin();
256
254
 
257
- it("Does not return a nodeType", () => {
258
- new ApplicabilityPlugin().applyParser(parser);
259
- const nodeTest = {
260
- value: "foo",
261
- };
262
- const nodeType = parser.hooks.determineNodeType.call(nodeTest);
263
- expect(nodeType).toBe(undefined);
255
+ applicabilityPlugin.applyParser(parser);
256
+ const root = parser.parseObject({
257
+ id: "foo",
258
+ fields: {
259
+ applicability: "{{foo.bar}}",
260
+ },
261
+ } as any);
262
+ const resolver = new Resolver(root as Node.Node, resolverOptions);
263
+
264
+ applicabilityPlugin.applyResolver(resolver);
265
+ stringResolverPlugin.applyResolver(resolver);
266
+
267
+ const resolved = resolver.update();
268
+
269
+ expect(resolved).toStrictEqual({
270
+ id: "foo",
271
+ });
264
272
  });
265
273
  });
@@ -0,0 +1,140 @@
1
+ import { describe, it, expect, beforeEach } from "vitest";
2
+ import { BindingParser } from "../../../binding";
3
+ import type { DataModelWithParser } from "../../../data";
4
+ import { LocalModel, withParser } from "../../../data";
5
+ import { ExpressionEvaluator } from "../../../expressions";
6
+ import { SchemaController } from "../../../schema";
7
+ import { Parser } from "../../parser";
8
+ import type { Options } from "../options";
9
+ import {
10
+ MultiNodePlugin,
11
+ AssetPlugin,
12
+ ApplicabilityPlugin,
13
+ TemplatePlugin,
14
+ SwitchPlugin,
15
+ } from "..";
16
+
17
+ describe("asset", () => {
18
+ let parser: Parser;
19
+
20
+ beforeEach(() => {
21
+ parser = new Parser();
22
+ new AssetPlugin().applyParser(parser);
23
+ });
24
+
25
+ it("object", () => {
26
+ expect(parser.parseObject({ asset: { type: "bar" } })).toMatchSnapshot();
27
+ });
28
+
29
+ it("applicability", () => {
30
+ new ApplicabilityPlugin().applyParser(parser);
31
+ new MultiNodePlugin().applyParser(parser);
32
+
33
+ expect(
34
+ parser.parseObject({
35
+ asset: {
36
+ values: [
37
+ {
38
+ applicability: "{{foo}}",
39
+ value: "foo",
40
+ },
41
+ {
42
+ value: "bar",
43
+ },
44
+ ],
45
+ },
46
+ }),
47
+ ).toMatchSnapshot();
48
+ });
49
+
50
+ it("multi-node", () => {
51
+ new MultiNodePlugin().applyParser(parser);
52
+
53
+ expect(
54
+ parser.parseObject({
55
+ asset: {
56
+ id: "foo",
57
+ type: "collection",
58
+ values: [
59
+ {
60
+ asset: {
61
+ id: "value-1",
62
+ type: "text",
63
+ value: "First value in the collection",
64
+ },
65
+ },
66
+ ],
67
+ },
68
+ }),
69
+ ).toMatchSnapshot();
70
+ });
71
+
72
+ it("template", () => {
73
+ const parseBinding = new BindingParser().parse;
74
+ const model: DataModelWithParser = withParser(
75
+ new LocalModel(),
76
+ parseBinding,
77
+ );
78
+ const expressionEvaluator: ExpressionEvaluator = new ExpressionEvaluator({
79
+ model,
80
+ });
81
+ const options: Options = {
82
+ evaluate: expressionEvaluator.evaluate,
83
+ schema: new SchemaController(),
84
+ data: {
85
+ format: (binding, val) => val,
86
+ formatValue: (val) => val,
87
+ model,
88
+ },
89
+ };
90
+ new TemplatePlugin(options).applyParser(parser);
91
+
92
+ const petNames = ["Ginger", "Daisy", "Afra"];
93
+ model.set([["foo.bar", petNames]]);
94
+
95
+ expect(
96
+ parser.parseObject({
97
+ asset: {
98
+ id: "foo",
99
+ type: "collection",
100
+ template: [
101
+ {
102
+ data: "foo.bar",
103
+ output: "values",
104
+ value: {
105
+ value: "{{foo.bar._index_}}",
106
+ },
107
+ },
108
+ ],
109
+ },
110
+ }),
111
+ ).toMatchSnapshot();
112
+ });
113
+
114
+ it("switch", () => {
115
+ new SwitchPlugin({
116
+ evaluate: () => {
117
+ return true;
118
+ },
119
+ } as any).applyParser(parser);
120
+
121
+ expect(
122
+ parser.parseObject({
123
+ id: "toughView",
124
+ type: "view",
125
+ title: {
126
+ staticSwitch: [
127
+ {
128
+ case: "'true'",
129
+ asset: {
130
+ id: "test",
131
+ type: "text",
132
+ value: "test-text.",
133
+ },
134
+ },
135
+ ],
136
+ },
137
+ }),
138
+ ).toMatchSnapshot();
139
+ });
140
+ });
@@ -0,0 +1,38 @@
1
+ import { describe, it, expect, beforeEach } from "vitest";
2
+ import { Parser } from "../../parser";
3
+ import { MultiNodePlugin, AssetPlugin } from "..";
4
+
5
+ describe("multi-node", () => {
6
+ let parser: Parser;
7
+
8
+ beforeEach(() => {
9
+ parser = new Parser();
10
+ new AssetPlugin().applyParser(parser);
11
+ new MultiNodePlugin().applyParser(parser);
12
+ });
13
+
14
+ it("multi-node collection", () => {
15
+ expect(
16
+ parser.parseObject({
17
+ id: "foo",
18
+ type: "collection",
19
+ values: [
20
+ {
21
+ asset: {
22
+ id: "value-1",
23
+ type: "text",
24
+ value: "First value in the collection",
25
+ },
26
+ },
27
+ {
28
+ asset: {
29
+ id: "value-2",
30
+ type: "text",
31
+ value: "Second value in the collection",
32
+ },
33
+ },
34
+ ],
35
+ }),
36
+ ).toMatchSnapshot();
37
+ });
38
+ });