@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
@@ -1,15 +1,15 @@
1
- import { omit } from 'timm';
2
- import type { ViewPlugin, View } from './plugin';
3
- import type { Options } from './options';
4
- import type { Resolver } from '../resolver';
5
- import type { Node, ParseObjectOptions, Parser } from '../parser';
6
- import { NodeType } from '../parser';
1
+ import { omit } from "timm";
2
+ import type { Options } from "./options";
3
+ import type { Resolver } from "../resolver";
4
+ import type { Node, ParseObjectOptions, Parser } from "../parser";
5
+ import { NodeType } from "../parser";
6
+ import { ViewInstance, ViewPlugin } from "../view";
7
7
 
8
8
  /** A view plugin to remove inapplicable assets from the tree */
9
9
  export default class ApplicabilityPlugin implements ViewPlugin {
10
10
  applyResolver(resolver: Resolver) {
11
11
  resolver.hooks.beforeResolve.tap(
12
- 'applicability',
12
+ "applicability",
13
13
  (node: Node.Node | null, options: Options) => {
14
14
  let newNode = node;
15
15
 
@@ -24,31 +24,31 @@ export default class ApplicabilityPlugin implements ViewPlugin {
24
24
  }
25
25
 
26
26
  return newNode;
27
- }
27
+ },
28
28
  );
29
29
  }
30
30
 
31
31
  applyParser(parser: Parser) {
32
32
  /** Switches resolved during the parsing phase are static */
33
- parser.hooks.determineNodeType.tap('applicability', (obj: any) => {
34
- if (Object.prototype.hasOwnProperty.call(obj, 'applicability')) {
33
+ parser.hooks.determineNodeType.tap("applicability", (obj: any) => {
34
+ if (Object.prototype.hasOwnProperty.call(obj, "applicability")) {
35
35
  return NodeType.Applicability;
36
36
  }
37
37
  });
38
38
 
39
39
  parser.hooks.parseNode.tap(
40
- 'applicability',
40
+ "applicability",
41
41
  (
42
42
  obj: any,
43
43
  nodeType: Node.ChildrenTypes,
44
44
  options: ParseObjectOptions,
45
- determinedNodeType: null | NodeType
45
+ determinedNodeType: null | NodeType,
46
46
  ) => {
47
47
  if (determinedNodeType === NodeType.Applicability) {
48
48
  const parsedApplicability = parser.parseObject(
49
- omit(obj, 'applicability'),
49
+ omit(obj, "applicability"),
50
50
  nodeType,
51
- options
51
+ options,
52
52
  );
53
53
  if (parsedApplicability !== null) {
54
54
  const applicabilityNode = parser.createASTNode(
@@ -57,7 +57,7 @@ export default class ApplicabilityPlugin implements ViewPlugin {
57
57
  expression: (obj as any).applicability,
58
58
  value: parsedApplicability,
59
59
  },
60
- obj
60
+ obj,
61
61
  );
62
62
 
63
63
  if (applicabilityNode?.type === NodeType.Applicability) {
@@ -67,12 +67,12 @@ export default class ApplicabilityPlugin implements ViewPlugin {
67
67
  return applicabilityNode;
68
68
  }
69
69
  }
70
- }
70
+ },
71
71
  );
72
72
  }
73
73
 
74
- apply(view: View) {
75
- view.hooks.resolver.tap('applicability', this.applyResolver.bind(this));
76
- view.hooks.parser.tap('applicability', this.applyParser.bind(this));
74
+ apply(view: ViewInstance) {
75
+ view.hooks.resolver.tap("applicability", this.applyResolver.bind(this));
76
+ view.hooks.parser.tap("applicability", this.applyParser.bind(this));
77
77
  }
78
78
  }
@@ -1,5 +1,4 @@
1
- export { default as TemplatePlugin } from './template-plugin';
2
- export { default as StringResolverPlugin } from './string-resolver';
3
- export { default as ApplicabilityPlugin } from './applicability';
4
- export { default as SwitchPlugin } from './switch';
5
- export type { ViewPlugin } from './plugin';
1
+ export { default as TemplatePlugin } from "./template-plugin";
2
+ export { default as StringResolverPlugin } from "./string-resolver";
3
+ export { default as ApplicabilityPlugin } from "./applicability";
4
+ export { default as SwitchPlugin } from "./switch";
@@ -1,4 +1,4 @@
1
- import type { Resolve } from '../resolver';
1
+ import type { Resolve } from "../resolver";
2
2
 
3
3
  /** Config options that are required to resolve/update a view */
4
4
  export type Options = Resolve.NodeResolveOptions;
@@ -1,10 +1,10 @@
1
- import { set } from 'timm';
2
- import { resolveDataRefs } from '../../string-resolver';
3
- import type { Options } from './options';
4
- import type { View, ViewPlugin } from './plugin';
5
- import type { Node } from '../parser';
6
- import { NodeType } from '../parser';
7
- import type { Resolver } from '../resolver';
1
+ import { set } from "timm";
2
+ import { resolveDataRefs } from "../../string-resolver";
3
+ import type { Options } from "./options";
4
+ import type { Node } from "../parser";
5
+ import { NodeType } from "../parser";
6
+ import type { Resolver } from "../resolver";
7
+ import { ViewInstance, ViewPlugin } from "../view";
8
8
 
9
9
  /** Create a function that checks for a start/end sequence in a string */
10
10
  const createPatternMatcher = (start: string, end: string) => {
@@ -25,8 +25,8 @@ const createPatternMatcher = (start: string, end: string) => {
25
25
  };
26
26
  };
27
27
 
28
- const bindingResolveLookup = createPatternMatcher('{{', '}}');
29
- const expressionResolveLookup = createPatternMatcher('@[', ']@');
28
+ const bindingResolveLookup = createPatternMatcher("{{", "}}");
29
+ const expressionResolveLookup = createPatternMatcher("@[", "]@");
30
30
 
31
31
  /** Check to see if a string contains a reference to dynamic content */
32
32
  function hasSomethingToResolve(str: string) {
@@ -47,17 +47,17 @@ function resolveString(str: string, resolveOptions: Options) {
47
47
  export function resolveAllRefs(
48
48
  node: any,
49
49
  resolveOptions: Options,
50
- propertiesToSkip: Set<string | number>
50
+ propertiesToSkip: Set<string | number>,
51
51
  ): any {
52
52
  if (
53
53
  node === null ||
54
54
  node === undefined ||
55
- (typeof node !== 'object' && typeof node !== 'string')
55
+ (typeof node !== "object" && typeof node !== "string")
56
56
  ) {
57
57
  return node;
58
58
  }
59
59
 
60
- if (typeof node === 'string') {
60
+ if (typeof node === "string") {
61
61
  return resolveString(node, resolveOptions);
62
62
  }
63
63
 
@@ -72,9 +72,9 @@ export function resolveAllRefs(
72
72
 
73
73
  let newVal = val;
74
74
 
75
- if (typeof val === 'object') {
75
+ if (typeof val === "object") {
76
76
  newVal = resolveAllRefs(val, resolveOptions, propertiesToSkip);
77
- } else if (typeof val === 'string') {
77
+ } else if (typeof val === "string") {
78
78
  newVal = resolveString(val, resolveOptions);
79
79
  }
80
80
 
@@ -89,14 +89,14 @@ export function resolveAllRefs(
89
89
  /** Traverse up the node tree finding the first available 'path' */
90
90
  const findBasePath = (
91
91
  node: Node.Node,
92
- resolver: Resolver
92
+ resolver: Resolver,
93
93
  ): Node.PathSegment[] => {
94
94
  const parentNode = node.parent;
95
95
  if (!parentNode) {
96
96
  return [];
97
97
  }
98
98
 
99
- if ('children' in parentNode) {
99
+ if ("children" in parentNode) {
100
100
  const original = resolver.getSourceNode(node);
101
101
  return (
102
102
  parentNode.children?.find((child) => child.value === original)?.path ?? []
@@ -119,7 +119,7 @@ export default class StringResolverPlugin implements ViewPlugin {
119
119
  }
120
120
 
121
121
  applyResolver(resolver: Resolver) {
122
- resolver.hooks.resolve.tap('string-resolver', (value, node, options) => {
122
+ resolver.hooks.resolve.tap("string-resolver", (value, node, options) => {
123
123
  if (node.type === NodeType.Empty || node.type === NodeType.Unknown) {
124
124
  return null;
125
125
  }
@@ -133,7 +133,7 @@ export default class StringResolverPlugin implements ViewPlugin {
133
133
  let propsToSkip: Set<string>;
134
134
  if (node.type === NodeType.Asset || node.type === NodeType.View) {
135
135
  propsToSkip = new Set(
136
- node.plugins?.stringResolver?.propertiesToSkip ?? ['exp']
136
+ node.plugins?.stringResolver?.propertiesToSkip ?? ["exp"],
137
137
  );
138
138
  if (node.value?.id) {
139
139
  this.propertiesToSkipCache.set(node.value.id, propsToSkip);
@@ -146,10 +146,10 @@ export default class StringResolverPlugin implements ViewPlugin {
146
146
  this.propertiesToSkipCache.has(node.parent.parent.value.id)
147
147
  ) {
148
148
  propsToSkip = this.propertiesToSkipCache.get(
149
- node.parent.parent.value.id
149
+ node.parent.parent.value.id,
150
150
  ) as Set<string>;
151
151
  } else {
152
- propsToSkip = new Set(['exp']);
152
+ propsToSkip = new Set(["exp"]);
153
153
  }
154
154
 
155
155
  const nodePath = findBasePath(node, resolver);
@@ -169,7 +169,7 @@ export default class StringResolverPlugin implements ViewPlugin {
169
169
  });
170
170
  }
171
171
 
172
- apply(view: View) {
173
- view.hooks.resolver.tap('string-resolver', this.applyResolver.bind(this));
172
+ apply(view: ViewInstance) {
173
+ view.hooks.resolver.tap("string-resolver", this.applyResolver.bind(this));
174
174
  }
175
175
  }
@@ -1,8 +1,8 @@
1
- import type { View, ViewPlugin } from './plugin';
2
- import type { Options } from './options';
3
- import type { Parser, Node, ParseObjectOptions } from '../parser';
4
- import { EMPTY_NODE, NodeType } from '../parser';
5
- import type { Resolver } from '../resolver';
1
+ import type { Options } from "./options";
2
+ import type { Parser, Node, ParseObjectOptions } from "../parser";
3
+ import { EMPTY_NODE, NodeType } from "../parser";
4
+ import type { Resolver } from "../resolver";
5
+ import { ViewInstance, ViewPlugin } from "../view";
6
6
 
7
7
  /** A view plugin to resolve switches */
8
8
  export default class SwitchPlugin implements ViewPlugin {
@@ -15,7 +15,6 @@ export default class SwitchPlugin implements ViewPlugin {
15
15
  private resolveSwitch(node: Node.Switch, options: Options): Node.Node {
16
16
  for (const switchCase of node.cases) {
17
17
  const isApplicable = options.evaluate(switchCase.case);
18
-
19
18
  if (isApplicable) {
20
19
  return switchCase.value;
21
20
  }
@@ -26,7 +25,7 @@ export default class SwitchPlugin implements ViewPlugin {
26
25
 
27
26
  applyParser(parser: Parser) {
28
27
  /** Switches resolved during the parsing phase are static */
29
- parser.hooks.onCreateASTNode.tap('switch', (node) => {
28
+ parser.hooks.onCreateASTNode.tap("switch", (node) => {
30
29
  if (node && node.type === NodeType.Switch && !node.dynamic) {
31
30
  return this.resolveSwitch(node, this.options);
32
31
  }
@@ -34,27 +33,27 @@ export default class SwitchPlugin implements ViewPlugin {
34
33
  return node;
35
34
  });
36
35
 
37
- parser.hooks.determineNodeType.tap('switch', (obj) => {
36
+ parser.hooks.determineNodeType.tap("switch", (obj) => {
38
37
  if (
39
- Object.prototype.hasOwnProperty.call(obj, 'dynamicSwitch') ||
40
- Object.prototype.hasOwnProperty.call(obj, 'staticSwitch')
38
+ Object.prototype.hasOwnProperty.call(obj, "dynamicSwitch") ||
39
+ Object.prototype.hasOwnProperty.call(obj, "staticSwitch")
41
40
  ) {
42
41
  return NodeType.Switch;
43
42
  }
44
43
  });
45
44
 
46
45
  parser.hooks.parseNode.tap(
47
- 'switch',
46
+ "switch",
48
47
  (
49
48
  obj: any,
50
- nodeType: Node.ChildrenTypes,
49
+ _nodeType: Node.ChildrenTypes,
51
50
  options: ParseObjectOptions,
52
- determinedNodeType: null | NodeType
51
+ determinedNodeType: null | NodeType,
53
52
  ) => {
54
53
  if (determinedNodeType === NodeType.Switch) {
55
- const dynamic = 'dynamicSwitch' in obj;
54
+ const dynamic = "dynamicSwitch" in obj;
56
55
  const switchContent =
57
- 'dynamicSwitch' in obj ? obj.dynamicSwitch : obj.staticSwitch;
56
+ "dynamicSwitch" in obj ? obj.dynamicSwitch : obj.staticSwitch;
58
57
 
59
58
  const cases: Node.SwitchCase[] = [];
60
59
 
@@ -70,7 +69,7 @@ export default class SwitchPlugin implements ViewPlugin {
70
69
  const value = parser.parseObject(
71
70
  switchBody,
72
71
  NodeType.Value,
73
- options
72
+ options,
74
73
  );
75
74
 
76
75
  if (value) {
@@ -79,7 +78,7 @@ export default class SwitchPlugin implements ViewPlugin {
79
78
  value: value as Node.Value,
80
79
  });
81
80
  }
82
- }
81
+ },
83
82
  );
84
83
 
85
84
  const switchAST = parser.hooks.onCreateASTNode.call(
@@ -88,7 +87,7 @@ export default class SwitchPlugin implements ViewPlugin {
88
87
  dynamic,
89
88
  cases,
90
89
  },
91
- obj
90
+ obj,
92
91
  );
93
92
 
94
93
  if (switchAST?.type === NodeType.Switch) {
@@ -104,13 +103,13 @@ export default class SwitchPlugin implements ViewPlugin {
104
103
 
105
104
  return switchAST ?? null;
106
105
  }
107
- }
106
+ },
108
107
  );
109
108
  }
110
109
 
111
110
  applyResolver(resolver: Resolver) {
112
111
  /** Switches resolved during the parsing phase are dynamic */
113
- resolver.hooks.beforeResolve.tap('switch', (node, options) => {
112
+ resolver.hooks.beforeResolve.tap("switch", (node, options) => {
114
113
  if (node && node.type === NodeType.Switch && node.dynamic) {
115
114
  return this.resolveSwitch(node, options);
116
115
  }
@@ -119,8 +118,8 @@ export default class SwitchPlugin implements ViewPlugin {
119
118
  });
120
119
  }
121
120
 
122
- apply(view: View) {
123
- view.hooks.parser.tap('switch', this.applyParser.bind(this));
124
- view.hooks.resolver.tap('switch', this.applyResolver.bind(this));
121
+ apply(view: ViewInstance) {
122
+ view.hooks.parser.tap("switch", this.applyParser.bind(this));
123
+ view.hooks.resolver.tap("switch", this.applyResolver.bind(this));
125
124
  }
126
125
  }
@@ -1,10 +1,9 @@
1
- import { SyncWaterfallHook } from 'tapable-ts';
2
- import type { Node, ParseObjectOptions, Parser } from '../parser';
3
- import { NodeType } from '../parser';
4
- import type { ViewPlugin } from '.';
5
- import type { View } from './plugin';
6
- import type { Options } from './options';
7
- import type { Resolver } from '../resolver';
1
+ import { SyncWaterfallHook } from "tapable-ts";
2
+ import type { Node, ParseObjectOptions, Parser } from "../parser";
3
+ import { NodeType } from "../parser";
4
+ import type { Options } from "./options";
5
+ import type { Resolver } from "../resolver";
6
+ import { ViewInstance, ViewPlugin } from "../view";
8
7
 
9
8
  export interface TemplateItemInfo {
10
9
  /** The index of the data for the current iteration of the template */
@@ -24,7 +23,7 @@ export interface TemplateSubstitution {
24
23
 
25
24
  export type TemplateSubstitutionsFunc = (
26
25
  baseSubstitutions: TemplateSubstitution[],
27
- templateItemInfo: TemplateItemInfo
26
+ templateItemInfo: TemplateItemInfo,
28
27
  ) => TemplateSubstitution[];
29
28
 
30
29
  /** A view plugin to resolve/manage templates */
@@ -44,7 +43,7 @@ export default class TemplatePlugin implements ViewPlugin {
44
43
  private parseTemplate(
45
44
  parseObject: any,
46
45
  node: Node.Template,
47
- options: Options
46
+ options: Options,
48
47
  ): Node.Node | null {
49
48
  const { template, depth } = node;
50
49
  const data = options.data.model.get(node.data);
@@ -64,7 +63,7 @@ export default class TemplatePlugin implements ViewPlugin {
64
63
  this.hooks.resolveTemplateSubstitutions.call(
65
64
  [
66
65
  {
67
- expression: new RegExp(`_index${depth || ''}_`),
66
+ expression: new RegExp(`_index${depth || ""}_`),
68
67
  value: String(index),
69
68
  },
70
69
  ],
@@ -72,14 +71,14 @@ export default class TemplatePlugin implements ViewPlugin {
72
71
  depth,
73
72
  data: dataItem,
74
73
  index,
75
- }
74
+ },
76
75
  );
77
76
  let templateStr = JSON.stringify(template);
78
77
 
79
78
  for (const { expression, value } of templateSubstitutions) {
80
- let flags = 'g';
81
- if (typeof expression === 'object') {
82
- flags = `${expression.flags}${expression.global ? '' : 'g'}`;
79
+ let flags = "g";
80
+ if (typeof expression === "object") {
81
+ flags = `${expression.flags}${expression.global ? "" : "g"}`;
83
82
  }
84
83
 
85
84
  templateStr = templateStr.replace(new RegExp(expression, flags), value);
@@ -104,31 +103,31 @@ export default class TemplatePlugin implements ViewPlugin {
104
103
  }
105
104
 
106
105
  applyParser(parser: Parser) {
107
- parser.hooks.onCreateASTNode.tap('template', (node) => {
106
+ parser.hooks.onCreateASTNode.tap("template", (node) => {
108
107
  if (node && node.type === NodeType.Template && !node.dynamic) {
109
108
  return this.parseTemplate(
110
109
  parser.parseObject.bind(parser),
111
110
  node,
112
- this.options
111
+ this.options,
113
112
  );
114
113
  }
115
114
 
116
115
  return node;
117
116
  });
118
117
 
119
- parser.hooks.determineNodeType.tap('template', (obj: any) => {
120
- if (obj === 'template') {
118
+ parser.hooks.determineNodeType.tap("template", (obj: any) => {
119
+ if (obj === "template") {
121
120
  return NodeType.Template;
122
121
  }
123
122
  });
124
123
 
125
124
  parser.hooks.parseNode.tap(
126
- 'template',
125
+ "template",
127
126
  (
128
127
  obj: any,
129
- nodeType: Node.ChildrenTypes,
128
+ _nodeType: Node.ChildrenTypes,
130
129
  options: ParseObjectOptions,
131
- determinedNodeType: null | NodeType
130
+ determinedNodeType: null | NodeType,
132
131
  ) => {
133
132
  if (determinedNodeType === NodeType.Template) {
134
133
  const templateNode = parser.createASTNode(
@@ -139,19 +138,19 @@ export default class TemplatePlugin implements ViewPlugin {
139
138
  template: obj.value,
140
139
  dynamic: obj.dynamic ?? false,
141
140
  },
142
- obj
141
+ obj,
143
142
  );
144
143
 
145
144
  if (templateNode) {
146
145
  return templateNode;
147
146
  }
148
147
  }
149
- }
148
+ },
150
149
  );
151
150
  }
152
151
 
153
152
  applyResolverHooks(resolver: Resolver) {
154
- resolver.hooks.beforeResolve.tap('template', (node, options) => {
153
+ resolver.hooks.beforeResolve.tap("template", (node, options) => {
155
154
  if (node && node.type === NodeType.Template && node.dynamic) {
156
155
  return this.parseTemplate(options.parseNode, node, options);
157
156
  }
@@ -160,8 +159,8 @@ export default class TemplatePlugin implements ViewPlugin {
160
159
  });
161
160
  }
162
161
 
163
- apply(view: View) {
164
- view.hooks.parser.tap('template', this.applyParser.bind(this));
165
- view.hooks.resolver.tap('template', this.applyResolverHooks.bind(this));
162
+ apply(view: ViewInstance) {
163
+ view.hooks.parser.tap("template", this.applyParser.bind(this));
164
+ view.hooks.resolver.tap("template", this.applyResolverHooks.bind(this));
166
165
  }
167
166
  }