@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.
Files changed (214) hide show
  1. package/dist/Player.native.js +11630 -0
  2. package/dist/Player.native.js.map +1 -0
  3. package/dist/cjs/index.cjs +5626 -0
  4. package/dist/cjs/index.cjs.map +1 -0
  5. package/dist/{index.esm.js → index.legacy-esm.js} +2044 -1667
  6. package/dist/{index.cjs.js → index.mjs} +2052 -1761
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +29 -63
  9. package/src/__tests__/data.test.ts +498 -0
  10. package/src/__tests__/flow.test.ts +312 -0
  11. package/src/__tests__/helpers/action-exp.plugin.ts +22 -0
  12. package/src/__tests__/helpers/actions.flow.ts +67 -0
  13. package/src/__tests__/helpers/binding.plugin.ts +125 -0
  14. package/src/__tests__/helpers/expression.plugin.ts +88 -0
  15. package/src/__tests__/helpers/transform-plugin.ts +19 -0
  16. package/src/__tests__/helpers/validation.flow.ts +56 -0
  17. package/src/__tests__/player.test.ts +597 -0
  18. package/src/__tests__/string-resolver.test.ts +186 -0
  19. package/src/__tests__/validation.test.ts +3555 -0
  20. package/src/__tests__/view.test.ts +715 -0
  21. package/src/binding/__tests__/binding.test.ts +113 -0
  22. package/src/binding/__tests__/index.test.ts +208 -0
  23. package/src/binding/__tests__/resolver.test.ts +83 -0
  24. package/src/binding/binding.ts +6 -6
  25. package/src/binding/index.ts +34 -34
  26. package/src/binding/resolver.ts +19 -19
  27. package/src/binding/utils.ts +7 -7
  28. package/src/binding-grammar/__tests__/parser.test.ts +64 -0
  29. package/src/binding-grammar/__tests__/test-utils/ast-cases.ts +198 -0
  30. package/src/binding-grammar/__tests__/test-utils/perf-test.ts +66 -0
  31. package/src/binding-grammar/ast.ts +11 -11
  32. package/src/binding-grammar/custom/index.ts +19 -22
  33. package/src/binding-grammar/ebnf/index.ts +20 -21
  34. package/src/binding-grammar/ebnf/types.ts +13 -13
  35. package/src/binding-grammar/index.ts +4 -4
  36. package/src/binding-grammar/parsimmon/index.ts +14 -14
  37. package/src/controllers/constants/__tests__/index.test.ts +106 -0
  38. package/src/controllers/constants/index.ts +3 -3
  39. package/src/controllers/constants/utils.ts +4 -4
  40. package/src/controllers/data/controller.ts +22 -22
  41. package/src/controllers/data/index.ts +1 -1
  42. package/src/controllers/data/utils.ts +7 -7
  43. package/src/controllers/flow/__tests__/controller.test.ts +195 -0
  44. package/src/controllers/flow/__tests__/flow.test.ts +381 -0
  45. package/src/controllers/flow/controller.ts +13 -13
  46. package/src/controllers/flow/flow.ts +23 -23
  47. package/src/controllers/flow/index.ts +2 -2
  48. package/src/controllers/index.ts +5 -5
  49. package/src/controllers/validation/binding-tracker.ts +71 -59
  50. package/src/controllers/validation/controller.ts +104 -104
  51. package/src/controllers/validation/index.ts +2 -2
  52. package/src/controllers/view/asset-transform.ts +20 -20
  53. package/src/controllers/view/controller.ts +27 -27
  54. package/src/controllers/view/index.ts +4 -4
  55. package/src/controllers/view/store.ts +3 -3
  56. package/src/controllers/view/types.ts +7 -7
  57. package/src/data/__tests__/__snapshots__/dependency-tracker.test.ts.snap +64 -0
  58. package/src/data/__tests__/dependency-tracker.test.ts +146 -0
  59. package/src/data/__tests__/local-model.test.ts +46 -0
  60. package/src/data/__tests__/model.test.ts +78 -0
  61. package/src/data/dependency-tracker.ts +16 -16
  62. package/src/data/index.ts +4 -4
  63. package/src/data/local-model.ts +6 -6
  64. package/src/data/model.ts +17 -17
  65. package/src/data/noop-model.ts +1 -1
  66. package/src/expressions/__tests__/__snapshots__/parser.test.ts.snap +854 -0
  67. package/src/expressions/__tests__/evaluator-functions.test.ts +47 -0
  68. package/src/expressions/__tests__/evaluator.test.ts +410 -0
  69. package/src/expressions/__tests__/parser.test.ts +115 -0
  70. package/src/expressions/__tests__/utils.test.ts +44 -0
  71. package/src/expressions/evaluator-functions.ts +6 -6
  72. package/src/expressions/evaluator.ts +71 -67
  73. package/src/expressions/index.ts +4 -4
  74. package/src/expressions/parser.ts +102 -105
  75. package/src/expressions/types.ts +29 -21
  76. package/src/expressions/utils.ts +32 -21
  77. package/src/index.ts +13 -13
  78. package/src/logger/__tests__/consoleLogger.test.ts +46 -0
  79. package/src/logger/__tests__/noopLogger.test.ts +13 -0
  80. package/src/logger/__tests__/proxyLogger.test.ts +31 -0
  81. package/src/logger/__tests__/tapableLogger.test.ts +41 -0
  82. package/src/logger/consoleLogger.ts +9 -9
  83. package/src/logger/index.ts +5 -5
  84. package/src/logger/noopLogger.ts +1 -1
  85. package/src/logger/proxyLogger.ts +6 -6
  86. package/src/logger/tapableLogger.ts +7 -7
  87. package/src/logger/types.ts +2 -2
  88. package/src/player.ts +60 -58
  89. package/src/plugins/default-exp-plugin.ts +10 -10
  90. package/src/plugins/default-view-plugin.ts +29 -0
  91. package/src/plugins/flow-exp-plugin.ts +6 -6
  92. package/src/schema/__tests__/schema.test.ts +243 -0
  93. package/src/schema/index.ts +2 -2
  94. package/src/schema/schema.ts +24 -24
  95. package/src/schema/types.ts +4 -4
  96. package/src/string-resolver/__tests__/index.test.ts +361 -0
  97. package/src/string-resolver/index.ts +17 -17
  98. package/src/types.ts +17 -17
  99. package/src/utils/__tests__/replaceParams.test.ts +33 -0
  100. package/src/utils/index.ts +1 -1
  101. package/src/utils/replaceParams.ts +1 -1
  102. package/src/validator/__tests__/binding-map-splice.test.ts +53 -0
  103. package/src/validator/__tests__/validation-middleware.test.ts +127 -0
  104. package/src/validator/binding-map-splice.ts +5 -5
  105. package/src/validator/index.ts +4 -4
  106. package/src/validator/registry.ts +1 -1
  107. package/src/validator/types.ts +13 -13
  108. package/src/validator/validation-middleware.ts +15 -15
  109. package/src/view/__tests__/view.immutable.test.ts +269 -0
  110. package/src/view/__tests__/view.test.ts +959 -0
  111. package/src/view/builder/index.test.ts +69 -0
  112. package/src/view/builder/index.ts +3 -3
  113. package/src/view/index.ts +5 -5
  114. package/src/view/parser/__tests__/__snapshots__/parser.test.ts.snap +394 -0
  115. package/src/view/parser/__tests__/parser.test.ts +264 -0
  116. package/src/view/parser/index.ts +43 -33
  117. package/src/view/parser/types.ts +11 -11
  118. package/src/view/parser/utils.ts +5 -5
  119. package/src/view/plugins/__tests__/__snapshots__/template.test.ts.snap +278 -0
  120. package/src/view/plugins/__tests__/applicability.test.ts +265 -0
  121. package/src/view/plugins/__tests__/string.test.ts +122 -0
  122. package/src/view/plugins/__tests__/template.test.ts +724 -0
  123. package/src/view/plugins/applicability.ts +19 -19
  124. package/src/view/plugins/index.ts +4 -5
  125. package/src/view/plugins/options.ts +1 -1
  126. package/src/view/plugins/string-resolver.ts +22 -22
  127. package/src/view/plugins/switch.ts +22 -23
  128. package/src/view/plugins/template-plugin.ts +26 -27
  129. package/src/view/resolver/__tests__/dependencies.test.ts +321 -0
  130. package/src/view/resolver/__tests__/edgecases.test.ts +626 -0
  131. package/src/view/resolver/index.ts +42 -42
  132. package/src/view/resolver/types.ts +21 -20
  133. package/src/view/resolver/utils.ts +9 -9
  134. package/src/view/view.ts +32 -22
  135. package/types/binding/binding.d.ts +50 -0
  136. package/types/binding/index.d.ts +29 -0
  137. package/types/binding/resolver.d.ts +26 -0
  138. package/types/binding/utils.d.ts +12 -0
  139. package/types/binding-grammar/ast.d.ts +67 -0
  140. package/types/binding-grammar/custom/index.d.ts +4 -0
  141. package/types/binding-grammar/ebnf/index.d.ts +4 -0
  142. package/types/binding-grammar/ebnf/types.d.ts +75 -0
  143. package/types/binding-grammar/index.d.ts +5 -0
  144. package/types/binding-grammar/parsimmon/index.d.ts +4 -0
  145. package/types/controllers/constants/index.d.ts +45 -0
  146. package/types/controllers/constants/utils.d.ts +6 -0
  147. package/types/controllers/data/controller.d.ts +45 -0
  148. package/types/controllers/data/index.d.ts +2 -0
  149. package/types/controllers/data/utils.d.ts +14 -0
  150. package/types/controllers/flow/controller.d.ts +25 -0
  151. package/types/controllers/flow/flow.d.ts +50 -0
  152. package/types/controllers/flow/index.d.ts +3 -0
  153. package/types/controllers/index.d.ts +6 -0
  154. package/types/controllers/validation/binding-tracker.d.ts +32 -0
  155. package/types/controllers/validation/controller.d.ts +151 -0
  156. package/types/controllers/validation/index.d.ts +3 -0
  157. package/types/controllers/view/asset-transform.d.ts +19 -0
  158. package/types/controllers/view/controller.d.ts +37 -0
  159. package/types/controllers/view/index.d.ts +5 -0
  160. package/types/controllers/view/store.d.ts +20 -0
  161. package/types/controllers/view/types.d.ts +16 -0
  162. package/types/data/dependency-tracker.d.ts +49 -0
  163. package/types/data/index.d.ts +5 -0
  164. package/types/data/local-model.d.ts +16 -0
  165. package/types/data/model.d.ts +86 -0
  166. package/types/data/noop-model.d.ts +13 -0
  167. package/types/expressions/evaluator-functions.d.ts +15 -0
  168. package/types/expressions/evaluator.d.ts +52 -0
  169. package/types/expressions/index.d.ts +5 -0
  170. package/types/expressions/parser.d.ts +10 -0
  171. package/types/expressions/types.d.ts +144 -0
  172. package/types/expressions/utils.d.ts +12 -0
  173. package/types/index.d.ts +14 -0
  174. package/types/logger/consoleLogger.d.ts +17 -0
  175. package/types/logger/index.d.ts +6 -0
  176. package/types/logger/noopLogger.d.ts +10 -0
  177. package/types/logger/proxyLogger.d.ts +15 -0
  178. package/types/logger/tapableLogger.d.ts +23 -0
  179. package/types/logger/types.d.ts +6 -0
  180. package/types/player.d.ts +101 -0
  181. package/types/plugins/default-exp-plugin.d.ts +9 -0
  182. package/types/plugins/default-view-plugin.d.ts +9 -0
  183. package/types/plugins/flow-exp-plugin.d.ts +11 -0
  184. package/types/schema/index.d.ts +3 -0
  185. package/types/schema/schema.d.ts +36 -0
  186. package/types/schema/types.d.ts +38 -0
  187. package/types/string-resolver/index.d.ts +30 -0
  188. package/types/types.d.ts +73 -0
  189. package/types/utils/index.d.ts +2 -0
  190. package/types/utils/replaceParams.d.ts +9 -0
  191. package/types/validator/binding-map-splice.d.ts +10 -0
  192. package/types/validator/index.d.ts +5 -0
  193. package/types/validator/registry.d.ts +11 -0
  194. package/types/validator/types.d.ts +53 -0
  195. package/types/validator/validation-middleware.d.ts +36 -0
  196. package/types/view/builder/index.d.ts +35 -0
  197. package/types/view/index.d.ts +6 -0
  198. package/types/view/parser/index.d.ts +52 -0
  199. package/types/view/parser/types.d.ts +109 -0
  200. package/types/view/parser/utils.d.ts +6 -0
  201. package/types/view/plugins/applicability.d.ts +10 -0
  202. package/types/view/plugins/index.d.ts +5 -0
  203. package/types/view/plugins/options.d.ts +4 -0
  204. package/types/view/plugins/string-resolver.d.ts +13 -0
  205. package/types/view/plugins/switch.d.ts +14 -0
  206. package/types/view/plugins/template-plugin.d.ts +33 -0
  207. package/types/view/resolver/index.d.ts +73 -0
  208. package/types/view/resolver/types.d.ts +129 -0
  209. package/types/view/resolver/utils.d.ts +11 -0
  210. package/types/view/view.d.ts +37 -0
  211. package/dist/index.d.ts +0 -1814
  212. package/dist/player.dev.js +0 -11472
  213. package/dist/player.prod.js +0 -2
  214. package/src/view/plugins/plugin.ts +0 -21
@@ -0,0 +1,321 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { BindingParser } from "../../../binding";
3
+ import { ExpressionEvaluator } from "../../../expressions";
4
+ import { LocalModel, withParser } from "../../../data";
5
+ import { SchemaController } from "../../../schema";
6
+ import { Resolver } from "..";
7
+ import { Parser } from "../../parser";
8
+ import { StringResolverPlugin } from "../../plugins";
9
+
10
+ const actions = {
11
+ id: "action",
12
+ type: "collection",
13
+ values: [
14
+ {
15
+ asset: {
16
+ id: "action-1",
17
+ type: "action",
18
+ label: {
19
+ asset: {
20
+ id: "action-label-1",
21
+ type: "text",
22
+ value: "Clicked {{count1}} times",
23
+ },
24
+ },
25
+ },
26
+ },
27
+ {
28
+ asset: {
29
+ id: "action-2",
30
+ type: "action",
31
+ label: {
32
+ asset: {
33
+ id: "action-label-2",
34
+ type: "text",
35
+ value: "Clicked {{count2}} times",
36
+ },
37
+ },
38
+ },
39
+ },
40
+ ],
41
+ };
42
+
43
+ describe("resolver", () => {
44
+ it("works with child dependencies", () => {
45
+ const model = new LocalModel({
46
+ count1: 0,
47
+ count2: 0,
48
+ });
49
+ const parser = new Parser();
50
+ const bindingParser = new BindingParser();
51
+ const count1Binding = bindingParser.parse("count1");
52
+ const count2Binding = bindingParser.parse("count2");
53
+ const rootNode = parser.parseObject(actions);
54
+
55
+ const resolver = new Resolver(rootNode!, {
56
+ model,
57
+ parseBinding: bindingParser.parse.bind(bindingParser),
58
+ parseNode: parser.parseObject.bind(parser),
59
+ evaluator: new ExpressionEvaluator({
60
+ model: withParser(model, bindingParser.parse),
61
+ }),
62
+ schema: new SchemaController(),
63
+ });
64
+
65
+ new StringResolverPlugin().applyResolver(resolver);
66
+
67
+ const firstUpdate = resolver.update();
68
+
69
+ expect(firstUpdate).toStrictEqual({
70
+ id: "action",
71
+ type: "collection",
72
+ values: [
73
+ {
74
+ asset: {
75
+ id: "action-1",
76
+ type: "action",
77
+ label: {
78
+ asset: {
79
+ id: "action-label-1",
80
+ type: "text",
81
+ value: "Clicked 0 times",
82
+ },
83
+ },
84
+ },
85
+ },
86
+ {
87
+ asset: {
88
+ id: "action-2",
89
+ type: "action",
90
+ label: {
91
+ asset: {
92
+ id: "action-label-2",
93
+ type: "text",
94
+ value: "Clicked 0 times",
95
+ },
96
+ },
97
+ },
98
+ },
99
+ ],
100
+ });
101
+
102
+ model.set([[count1Binding, 1]]);
103
+ const secondUpdate = resolver.update(new Set([count1Binding]));
104
+ expect(secondUpdate).toStrictEqual({
105
+ id: "action",
106
+ type: "collection",
107
+ values: [
108
+ {
109
+ asset: {
110
+ id: "action-1",
111
+ type: "action",
112
+ label: {
113
+ asset: {
114
+ id: "action-label-1",
115
+ type: "text",
116
+ value: "Clicked 1 times",
117
+ },
118
+ },
119
+ },
120
+ },
121
+ {
122
+ asset: {
123
+ id: "action-2",
124
+ type: "action",
125
+ label: {
126
+ asset: {
127
+ id: "action-label-2",
128
+ type: "text",
129
+ value: "Clicked 0 times",
130
+ },
131
+ },
132
+ },
133
+ },
134
+ ],
135
+ });
136
+
137
+ model.set([[count2Binding, 1]]);
138
+
139
+ const thirdUpdate = resolver.update(new Set([count2Binding]));
140
+
141
+ expect(thirdUpdate).toStrictEqual({
142
+ id: "action",
143
+ type: "collection",
144
+ values: [
145
+ {
146
+ asset: {
147
+ id: "action-1",
148
+ type: "action",
149
+ label: {
150
+ asset: {
151
+ id: "action-label-1",
152
+ type: "text",
153
+ value: "Clicked 1 times",
154
+ },
155
+ },
156
+ },
157
+ },
158
+ {
159
+ asset: {
160
+ id: "action-2",
161
+ type: "action",
162
+ label: {
163
+ asset: {
164
+ id: "action-label-2",
165
+ type: "text",
166
+ value: "Clicked 1 times",
167
+ },
168
+ },
169
+ },
170
+ },
171
+ ],
172
+ });
173
+
174
+ model.set([[count1Binding, 2]]);
175
+ const fourthUpdate = resolver.update(new Set([count1Binding]));
176
+ expect(fourthUpdate).toStrictEqual({
177
+ id: "action",
178
+ type: "collection",
179
+ values: [
180
+ {
181
+ asset: {
182
+ id: "action-1",
183
+ type: "action",
184
+ label: {
185
+ asset: {
186
+ id: "action-label-1",
187
+ type: "text",
188
+ value: "Clicked 2 times",
189
+ },
190
+ },
191
+ },
192
+ },
193
+ {
194
+ asset: {
195
+ id: "action-2",
196
+ type: "action",
197
+ label: {
198
+ asset: {
199
+ id: "action-label-2",
200
+ type: "text",
201
+ value: "Clicked 1 times",
202
+ },
203
+ },
204
+ },
205
+ },
206
+ ],
207
+ });
208
+ });
209
+
210
+ it("tracks nested dependencies", () => {
211
+ const view = {
212
+ id: "collection",
213
+ type: "collection",
214
+ values: [
215
+ {
216
+ asset: {
217
+ id: "value-1",
218
+ type: "text",
219
+ value: "Clicked {{stuff[{{count}}].value}} times",
220
+ },
221
+ },
222
+ ],
223
+ };
224
+ const model = new LocalModel({
225
+ stuff: [{ value: "first" }, { value: "second" }, { value: "third" }],
226
+ count: 0,
227
+ });
228
+ const parser = new Parser();
229
+ const bindingParser = new BindingParser({ get: model.get, set: model.set });
230
+
231
+ const countBinding = bindingParser.parse("count");
232
+ const rootNode = parser.parseObject(view);
233
+
234
+ const resolver = new Resolver(rootNode!, {
235
+ model,
236
+ parseBinding: bindingParser.parse.bind(bindingParser),
237
+ parseNode: parser.parseObject.bind(parser),
238
+ evaluator: new ExpressionEvaluator({
239
+ model: withParser(model, bindingParser.parse),
240
+ }),
241
+ schema: new SchemaController(),
242
+ });
243
+
244
+ new StringResolverPlugin().applyResolver(resolver);
245
+
246
+ const firstUpdate = resolver.update();
247
+ expect(firstUpdate.values[0].asset.value).toBe("Clicked first times");
248
+
249
+ model.set([[countBinding, 1]]);
250
+
251
+ const secondUpdate = resolver.update(new Set([countBinding]));
252
+ expect(secondUpdate.values[0].asset.value).toBe("Clicked second times");
253
+ });
254
+ it("resolves values in an array", () => {
255
+ const view = {
256
+ id: "custom",
257
+ type: "custom",
258
+ values: [0, 1],
259
+ };
260
+ const model = new LocalModel({
261
+ stuff: [{ value: "first" }, { value: "second" }, { value: "third" }],
262
+ count: 0,
263
+ });
264
+ const parser = new Parser();
265
+ const bindingParser = new BindingParser({ get: model.get, set: model.set });
266
+
267
+ const rootNode = parser.parseObject(view);
268
+
269
+ const resolver = new Resolver(rootNode!, {
270
+ model,
271
+ parseBinding: bindingParser.parse.bind(bindingParser),
272
+ parseNode: parser.parseObject.bind(parser),
273
+ evaluator: new ExpressionEvaluator({
274
+ model: withParser(model, bindingParser.parse),
275
+ }),
276
+ schema: new SchemaController(),
277
+ });
278
+
279
+ new StringResolverPlugin().applyResolver(resolver);
280
+
281
+ const firstUpdate = resolver.update();
282
+ expect(firstUpdate.values).toStrictEqual([0, 1]);
283
+ });
284
+
285
+ it("works with expression strings in arrays", () => {
286
+ const model = new LocalModel({
287
+ showProgress1: false,
288
+ showProgress2: true,
289
+ });
290
+ const parser = new Parser();
291
+ const bindingParser = new BindingParser();
292
+ const rootNode = parser.parseObject({
293
+ id: "progress",
294
+ type: "progress",
295
+ progressAmount: [
296
+ "@[ conditional({{showProgress1}}, 'local.progress', '') ]@",
297
+ "@[ conditional({{showProgress2}}, 'local.progress', '') ]@",
298
+ ],
299
+ });
300
+
301
+ const resolver = new Resolver(rootNode!, {
302
+ model,
303
+ parseBinding: bindingParser.parse.bind(bindingParser),
304
+ parseNode: parser.parseObject.bind(parser),
305
+ evaluator: new ExpressionEvaluator({
306
+ model: withParser(model, bindingParser.parse),
307
+ }),
308
+ schema: new SchemaController(),
309
+ });
310
+
311
+ new StringResolverPlugin().applyResolver(resolver);
312
+
313
+ const firstUpdate = resolver.update();
314
+
315
+ expect(firstUpdate).toStrictEqual({
316
+ id: "progress",
317
+ type: "progress",
318
+ progressAmount: ["", "local.progress"],
319
+ });
320
+ });
321
+ });