@player-ui/check-path-plugin 0.4.0 → 0.4.1-next.1

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/index.cjs.js CHANGED
@@ -10,6 +10,8 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
10
10
 
11
11
  var dlv__default = /*#__PURE__*/_interopDefaultLegacy(dlv);
12
12
 
13
+ const CheckPathPluginSymbol = Symbol.for("CheckPathPlugin");
14
+
13
15
  function createMatcher(match) {
14
16
  if (typeof match === "string" || typeof match === "number") {
15
17
  return partialMatchRegistry.createObjectMatcher({ type: match });
@@ -26,14 +28,13 @@ function getParent(node, viewInfo) {
26
28
  }
27
29
  const { parent } = working;
28
30
  if (parent && (parent.type === player.NodeType.Asset || parent.type === player.NodeType.View)) {
29
- const sourceNode = viewInfo.resolver.getSourceNode(parent);
30
- const viewOrAsset = (sourceNode == null ? void 0 : sourceNode.type) === player.NodeType.Applicability ? sourceNode.value : viewInfo.resolver.getSourceNode(parent);
31
- return viewOrAsset != null ? viewOrAsset : parent;
31
+ return parent;
32
32
  }
33
33
  }
34
34
  class CheckPathPlugin {
35
35
  constructor() {
36
36
  this.name = "check-path";
37
+ this.symbol = CheckPathPluginSymbol;
37
38
  }
38
39
  apply(player$1) {
39
40
  player$1.hooks.viewController.tap(this.name, (viewController) => {
@@ -71,11 +72,10 @@ class CheckPathPlugin {
71
72
  if (!assetNode || !this.viewInfo) {
72
73
  return void 0;
73
74
  }
74
- let potentialMatch = getParent(assetNode, this.viewInfo);
75
+ let potentialMatch = getParent(assetNode);
75
76
  if (query === void 0) {
76
77
  if (potentialMatch) {
77
- const resolved = this.viewInfo.resolvedMap.get(potentialMatch);
78
- return resolved == null ? void 0 : resolved.value;
78
+ return this.getAssetFromAssetNode(potentialMatch);
79
79
  }
80
80
  return;
81
81
  }
@@ -87,19 +87,19 @@ class CheckPathPlugin {
87
87
  throw new Error("Recursion depth exceeded. Check for cycles in the AST graph");
88
88
  }
89
89
  const matcher = createMatcher(parentQuery);
90
- const resolved = this.viewInfo.resolvedMap.get(potentialMatch);
91
- if (resolved && matcher(resolved.value)) {
90
+ const resolved = this.getAssetFromAssetNode(potentialMatch);
91
+ if (resolved && matcher(resolved)) {
92
92
  if (queryArray.length === 0) {
93
- return resolved.value;
93
+ return resolved;
94
94
  }
95
95
  parentQuery = queryArray.shift();
96
96
  }
97
- potentialMatch = getParent(potentialMatch, this.viewInfo);
97
+ potentialMatch = getParent(potentialMatch);
98
98
  }
99
99
  return void 0;
100
100
  }
101
101
  getParentProp(id) {
102
- var _a, _b, _c, _d;
102
+ var _a, _b, _c;
103
103
  const assetNode = (_a = this.viewInfo) == null ? void 0 : _a.assetIdMap.get(id);
104
104
  if (!assetNode || !this.viewInfo) {
105
105
  return;
@@ -107,15 +107,15 @@ class CheckPathPlugin {
107
107
  let working = assetNode;
108
108
  let parent;
109
109
  while (working) {
110
- parent = (working == null ? void 0 : working.parent) && ((_b = this.viewInfo.resolvedMap.get(working.parent)) == null ? void 0 : _b.resolved);
110
+ parent = working == null ? void 0 : working.parent;
111
111
  if (parent && (parent.type === player.NodeType.Asset || parent.type === player.NodeType.View)) {
112
112
  break;
113
113
  }
114
114
  working = working == null ? void 0 : working.parent;
115
115
  }
116
116
  if (parent && "children" in parent) {
117
- const childProp = (_c = parent.children) == null ? void 0 : _c.find((child) => child.value === working);
118
- return (_d = childProp == null ? void 0 : childProp.path) == null ? void 0 : _d[0];
117
+ const childProp = (_b = parent.children) == null ? void 0 : _b.find((child) => child.value === working);
118
+ return (_c = childProp == null ? void 0 : childProp.path) == null ? void 0 : _c[0];
119
119
  }
120
120
  return void 0;
121
121
  }
@@ -131,15 +131,15 @@ class CheckPathPlugin {
131
131
  return Boolean(this.getParent(id, query));
132
132
  }
133
133
  findChildPath(node, query, includeSelfMatch = true) {
134
- var _a, _b, _c, _d;
134
+ var _a, _b;
135
135
  if (query.length === 0) {
136
136
  return true;
137
137
  }
138
138
  const [first, ...rest] = query;
139
139
  const matcher = createMatcher(first);
140
140
  if (node.type === player.NodeType.Asset || node.type === player.NodeType.View || node.type === player.NodeType.Applicability) {
141
- const resolved = node.type === player.NodeType.Applicability ? (_a = this.viewInfo) == null ? void 0 : _a.resolvedMap.get(node.value) : (_b = this.viewInfo) == null ? void 0 : _b.resolvedMap.get(node);
142
- const includesSelf = (_c = includeSelfMatch && resolved && matcher(resolved.value)) != null ? _c : false;
141
+ const resolvedValue = this.getResolvedValue(node);
142
+ const includesSelf = (_a = includeSelfMatch && matcher(resolvedValue)) != null ? _a : false;
143
143
  const childQuery = includesSelf ? rest : query;
144
144
  if (childQuery.length === 0 && includesSelf) {
145
145
  return true;
@@ -153,7 +153,7 @@ class CheckPathPlugin {
153
153
  }
154
154
  } else if (node.type === player.NodeType.MultiNode && node.values.some((childNode) => this.findChildPath(childNode, query))) {
155
155
  return true;
156
- } else if ("children" in node && ((_d = node.children) == null ? void 0 : _d.some((childNode) => this.findChildPath(childNode.value, query)))) {
156
+ } else if ("children" in node && ((_b = node.children) == null ? void 0 : _b.some((childNode) => this.findChildPath(childNode.value, query)))) {
157
157
  return true;
158
158
  }
159
159
  return false;
@@ -168,14 +168,18 @@ class CheckPathPlugin {
168
168
  return this.findChildPath(assetNode, queryArray, false);
169
169
  }
170
170
  getAsset(id) {
171
- var _a, _b, _c;
171
+ var _a;
172
172
  const assetNode = (_a = this.viewInfo) == null ? void 0 : _a.assetIdMap.get(id);
173
173
  if (!assetNode)
174
174
  return;
175
+ return this.getAssetFromAssetNode(assetNode);
176
+ }
177
+ getAssetFromAssetNode(assetNode) {
178
+ var _a, _b;
175
179
  const sourceNode = this.getSourceAssetNode(assetNode);
176
180
  if (!sourceNode)
177
181
  return;
178
- return (_c = (_b = this.viewInfo) == null ? void 0 : _b.resolvedMap.get(sourceNode)) == null ? void 0 : _c.value;
182
+ return (_b = (_a = this.viewInfo) == null ? void 0 : _a.resolvedMap.get(sourceNode)) == null ? void 0 : _b.value;
179
183
  }
180
184
  getPath(id, query) {
181
185
  var _a, _b;
@@ -195,34 +199,35 @@ class CheckPathPlugin {
195
199
  return (_a2 = parent.children) == null ? void 0 : _a2.find((n) => n.value === working);
196
200
  };
197
201
  while (working !== void 0) {
198
- const parent = (working == null ? void 0 : working.parent) && this.viewInfo.resolvedMap.get(working.parent);
199
- const parentNode = parent == null ? void 0 : parent.resolved;
200
- if (parentNode) {
201
- if (parentNode.type === player.NodeType.MultiNode) {
202
- const index = parentNode.values.indexOf(working);
202
+ const { parent } = working;
203
+ if (parent) {
204
+ if (parent.type === player.NodeType.MultiNode) {
205
+ const index = parent.values.indexOf(working);
203
206
  if (index !== -1) {
204
- const actualIndex = index - parentNode.values.slice(0, index).reduce((undefCount, next) => {
205
- var _a2, _b2;
206
- return ((_b2 = (_a2 = this.viewInfo) == null ? void 0 : _a2.resolvedMap.get(next)) == null ? void 0 : _b2.value) === void 0 ? undefCount + 1 : undefCount;
207
- }, 0);
207
+ const actualIndex = index - parent.values.slice(0, index).reduce((undefCount, next) => this.getResolvedValue(next) === void 0 ? undefCount + 1 : undefCount, 0);
208
208
  path = [actualIndex, ...path];
209
209
  }
210
- } else if ("children" in parentNode) {
211
- const childProp = findWorkingChild(parentNode);
210
+ } else if ("children" in parent) {
211
+ const childProp = findWorkingChild(parent);
212
212
  path = [...(_b = childProp == null ? void 0 : childProp.path) != null ? _b : [], ...path];
213
213
  }
214
- }
215
- if (parentQuery) {
216
- const matcher = createMatcher(parentQuery);
217
- if (matcher(parent == null ? void 0 : parent.value)) {
218
- parentQuery = queryArray.shift();
219
- if (!parentQuery)
220
- return path;
214
+ if (parentQuery) {
215
+ const matcher = createMatcher(parentQuery);
216
+ if (matcher(this.getResolvedValue(parent))) {
217
+ parentQuery = queryArray.shift();
218
+ if (!parentQuery)
219
+ return path;
220
+ }
221
221
  }
222
222
  }
223
223
  working = working.parent;
224
224
  }
225
- return queryArray.length === 0 ? path : void 0;
225
+ return parentQuery ? void 0 : path;
226
+ }
227
+ getResolvedValue(node) {
228
+ var _a, _b;
229
+ const sourceNode = this.getSourceAssetNode(node);
230
+ return (_b = (_a = this.viewInfo) == null ? void 0 : _a.resolvedMap.get(sourceNode != null ? sourceNode : node)) == null ? void 0 : _b.value;
226
231
  }
227
232
  }
228
233
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PlayerPlugin, Player } from '@player-ui/player';
1
+ import { PlayerPlugin, Player, Node } from '@player-ui/player';
2
2
  import { Asset } from '@player-ui/types';
3
3
 
4
4
  declare type QueryFunction = (asset: Asset) => boolean;
@@ -10,6 +10,7 @@ declare type Query = QueryFunction | string | object;
10
10
  declare class CheckPathPlugin implements PlayerPlugin {
11
11
  name: string;
12
12
  private viewInfo?;
13
+ readonly symbol: symbol;
13
14
  apply(player: Player): void;
14
15
  /**
15
16
  * Starts at the asset with the given id, and walks backwards _up_ the tree until it finds a match for the parent
@@ -46,11 +47,16 @@ declare class CheckPathPlugin implements PlayerPlugin {
46
47
  hasChildContext(id: string, query: Query | Array<Query>): boolean;
47
48
  /** Get the asset represented by id */
48
49
  getAsset(id: string): Asset | undefined;
50
+ /**
51
+ * Gets the value for an asset from an asset node
52
+ */
53
+ getAssetFromAssetNode(assetNode: Node.Asset | Node.View): Asset | undefined;
49
54
  /**
50
55
  * Get the path of the asset in the view upto
51
56
  * the asset that matches the query or to the view if no query is provided
52
57
  */
53
58
  getPath(id: string, query?: Query | Array<Query>): Array<string | number> | undefined;
59
+ private getResolvedValue;
54
60
  }
55
61
 
56
62
  export { CheckPathPlugin, Query, QueryFunction };
package/dist/index.esm.js CHANGED
@@ -2,6 +2,8 @@ import { NodeType } from '@player-ui/player';
2
2
  import { createObjectMatcher } from '@player-ui/partial-match-registry';
3
3
  import dlv from 'dlv';
4
4
 
5
+ const CheckPathPluginSymbol = Symbol.for("CheckPathPlugin");
6
+
5
7
  function createMatcher(match) {
6
8
  if (typeof match === "string" || typeof match === "number") {
7
9
  return createObjectMatcher({ type: match });
@@ -18,14 +20,13 @@ function getParent(node, viewInfo) {
18
20
  }
19
21
  const { parent } = working;
20
22
  if (parent && (parent.type === NodeType.Asset || parent.type === NodeType.View)) {
21
- const sourceNode = viewInfo.resolver.getSourceNode(parent);
22
- const viewOrAsset = (sourceNode == null ? void 0 : sourceNode.type) === NodeType.Applicability ? sourceNode.value : viewInfo.resolver.getSourceNode(parent);
23
- return viewOrAsset != null ? viewOrAsset : parent;
23
+ return parent;
24
24
  }
25
25
  }
26
26
  class CheckPathPlugin {
27
27
  constructor() {
28
28
  this.name = "check-path";
29
+ this.symbol = CheckPathPluginSymbol;
29
30
  }
30
31
  apply(player) {
31
32
  player.hooks.viewController.tap(this.name, (viewController) => {
@@ -63,11 +64,10 @@ class CheckPathPlugin {
63
64
  if (!assetNode || !this.viewInfo) {
64
65
  return void 0;
65
66
  }
66
- let potentialMatch = getParent(assetNode, this.viewInfo);
67
+ let potentialMatch = getParent(assetNode);
67
68
  if (query === void 0) {
68
69
  if (potentialMatch) {
69
- const resolved = this.viewInfo.resolvedMap.get(potentialMatch);
70
- return resolved == null ? void 0 : resolved.value;
70
+ return this.getAssetFromAssetNode(potentialMatch);
71
71
  }
72
72
  return;
73
73
  }
@@ -79,19 +79,19 @@ class CheckPathPlugin {
79
79
  throw new Error("Recursion depth exceeded. Check for cycles in the AST graph");
80
80
  }
81
81
  const matcher = createMatcher(parentQuery);
82
- const resolved = this.viewInfo.resolvedMap.get(potentialMatch);
83
- if (resolved && matcher(resolved.value)) {
82
+ const resolved = this.getAssetFromAssetNode(potentialMatch);
83
+ if (resolved && matcher(resolved)) {
84
84
  if (queryArray.length === 0) {
85
- return resolved.value;
85
+ return resolved;
86
86
  }
87
87
  parentQuery = queryArray.shift();
88
88
  }
89
- potentialMatch = getParent(potentialMatch, this.viewInfo);
89
+ potentialMatch = getParent(potentialMatch);
90
90
  }
91
91
  return void 0;
92
92
  }
93
93
  getParentProp(id) {
94
- var _a, _b, _c, _d;
94
+ var _a, _b, _c;
95
95
  const assetNode = (_a = this.viewInfo) == null ? void 0 : _a.assetIdMap.get(id);
96
96
  if (!assetNode || !this.viewInfo) {
97
97
  return;
@@ -99,15 +99,15 @@ class CheckPathPlugin {
99
99
  let working = assetNode;
100
100
  let parent;
101
101
  while (working) {
102
- parent = (working == null ? void 0 : working.parent) && ((_b = this.viewInfo.resolvedMap.get(working.parent)) == null ? void 0 : _b.resolved);
102
+ parent = working == null ? void 0 : working.parent;
103
103
  if (parent && (parent.type === NodeType.Asset || parent.type === NodeType.View)) {
104
104
  break;
105
105
  }
106
106
  working = working == null ? void 0 : working.parent;
107
107
  }
108
108
  if (parent && "children" in parent) {
109
- const childProp = (_c = parent.children) == null ? void 0 : _c.find((child) => child.value === working);
110
- return (_d = childProp == null ? void 0 : childProp.path) == null ? void 0 : _d[0];
109
+ const childProp = (_b = parent.children) == null ? void 0 : _b.find((child) => child.value === working);
110
+ return (_c = childProp == null ? void 0 : childProp.path) == null ? void 0 : _c[0];
111
111
  }
112
112
  return void 0;
113
113
  }
@@ -123,15 +123,15 @@ class CheckPathPlugin {
123
123
  return Boolean(this.getParent(id, query));
124
124
  }
125
125
  findChildPath(node, query, includeSelfMatch = true) {
126
- var _a, _b, _c, _d;
126
+ var _a, _b;
127
127
  if (query.length === 0) {
128
128
  return true;
129
129
  }
130
130
  const [first, ...rest] = query;
131
131
  const matcher = createMatcher(first);
132
132
  if (node.type === NodeType.Asset || node.type === NodeType.View || node.type === NodeType.Applicability) {
133
- const resolved = node.type === NodeType.Applicability ? (_a = this.viewInfo) == null ? void 0 : _a.resolvedMap.get(node.value) : (_b = this.viewInfo) == null ? void 0 : _b.resolvedMap.get(node);
134
- const includesSelf = (_c = includeSelfMatch && resolved && matcher(resolved.value)) != null ? _c : false;
133
+ const resolvedValue = this.getResolvedValue(node);
134
+ const includesSelf = (_a = includeSelfMatch && matcher(resolvedValue)) != null ? _a : false;
135
135
  const childQuery = includesSelf ? rest : query;
136
136
  if (childQuery.length === 0 && includesSelf) {
137
137
  return true;
@@ -145,7 +145,7 @@ class CheckPathPlugin {
145
145
  }
146
146
  } else if (node.type === NodeType.MultiNode && node.values.some((childNode) => this.findChildPath(childNode, query))) {
147
147
  return true;
148
- } else if ("children" in node && ((_d = node.children) == null ? void 0 : _d.some((childNode) => this.findChildPath(childNode.value, query)))) {
148
+ } else if ("children" in node && ((_b = node.children) == null ? void 0 : _b.some((childNode) => this.findChildPath(childNode.value, query)))) {
149
149
  return true;
150
150
  }
151
151
  return false;
@@ -160,14 +160,18 @@ class CheckPathPlugin {
160
160
  return this.findChildPath(assetNode, queryArray, false);
161
161
  }
162
162
  getAsset(id) {
163
- var _a, _b, _c;
163
+ var _a;
164
164
  const assetNode = (_a = this.viewInfo) == null ? void 0 : _a.assetIdMap.get(id);
165
165
  if (!assetNode)
166
166
  return;
167
+ return this.getAssetFromAssetNode(assetNode);
168
+ }
169
+ getAssetFromAssetNode(assetNode) {
170
+ var _a, _b;
167
171
  const sourceNode = this.getSourceAssetNode(assetNode);
168
172
  if (!sourceNode)
169
173
  return;
170
- return (_c = (_b = this.viewInfo) == null ? void 0 : _b.resolvedMap.get(sourceNode)) == null ? void 0 : _c.value;
174
+ return (_b = (_a = this.viewInfo) == null ? void 0 : _a.resolvedMap.get(sourceNode)) == null ? void 0 : _b.value;
171
175
  }
172
176
  getPath(id, query) {
173
177
  var _a, _b;
@@ -187,34 +191,35 @@ class CheckPathPlugin {
187
191
  return (_a2 = parent.children) == null ? void 0 : _a2.find((n) => n.value === working);
188
192
  };
189
193
  while (working !== void 0) {
190
- const parent = (working == null ? void 0 : working.parent) && this.viewInfo.resolvedMap.get(working.parent);
191
- const parentNode = parent == null ? void 0 : parent.resolved;
192
- if (parentNode) {
193
- if (parentNode.type === NodeType.MultiNode) {
194
- const index = parentNode.values.indexOf(working);
194
+ const { parent } = working;
195
+ if (parent) {
196
+ if (parent.type === NodeType.MultiNode) {
197
+ const index = parent.values.indexOf(working);
195
198
  if (index !== -1) {
196
- const actualIndex = index - parentNode.values.slice(0, index).reduce((undefCount, next) => {
197
- var _a2, _b2;
198
- return ((_b2 = (_a2 = this.viewInfo) == null ? void 0 : _a2.resolvedMap.get(next)) == null ? void 0 : _b2.value) === void 0 ? undefCount + 1 : undefCount;
199
- }, 0);
199
+ const actualIndex = index - parent.values.slice(0, index).reduce((undefCount, next) => this.getResolvedValue(next) === void 0 ? undefCount + 1 : undefCount, 0);
200
200
  path = [actualIndex, ...path];
201
201
  }
202
- } else if ("children" in parentNode) {
203
- const childProp = findWorkingChild(parentNode);
202
+ } else if ("children" in parent) {
203
+ const childProp = findWorkingChild(parent);
204
204
  path = [...(_b = childProp == null ? void 0 : childProp.path) != null ? _b : [], ...path];
205
205
  }
206
- }
207
- if (parentQuery) {
208
- const matcher = createMatcher(parentQuery);
209
- if (matcher(parent == null ? void 0 : parent.value)) {
210
- parentQuery = queryArray.shift();
211
- if (!parentQuery)
212
- return path;
206
+ if (parentQuery) {
207
+ const matcher = createMatcher(parentQuery);
208
+ if (matcher(this.getResolvedValue(parent))) {
209
+ parentQuery = queryArray.shift();
210
+ if (!parentQuery)
211
+ return path;
212
+ }
213
213
  }
214
214
  }
215
215
  working = working.parent;
216
216
  }
217
- return queryArray.length === 0 ? path : void 0;
217
+ return parentQuery ? void 0 : path;
218
+ }
219
+ getResolvedValue(node) {
220
+ var _a, _b;
221
+ const sourceNode = this.getSourceAssetNode(node);
222
+ return (_b = (_a = this.viewInfo) == null ? void 0 : _a.resolvedMap.get(sourceNode != null ? sourceNode : node)) == null ? void 0 : _b.value;
218
223
  }
219
224
  }
220
225
 
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@player-ui/check-path-plugin",
3
- "version": "0.4.0",
3
+ "version": "0.4.1-next.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
7
7
  },
8
8
  "peerDependencies": {
9
- "@player-ui/player": "0.4.0"
9
+ "@player-ui/player": "0.4.1-next.1"
10
10
  },
11
11
  "dependencies": {
12
- "@player-ui/partial-match-registry": "0.4.0",
12
+ "@player-ui/partial-match-registry": "0.4.1-next.1",
13
13
  "dlv": "^1.1.3",
14
14
  "tapable-ts": "^0.2.3",
15
15
  "@babel/runtime": "7.15.4"
@@ -55,6 +55,14 @@
55
55
  {
56
56
  "name": "Kelly Harrop",
57
57
  "url": "https://github.com/kharrop"
58
+ },
59
+ {
60
+ "name": "Alejandro Fimbres",
61
+ "url": "https://github.com/lexfm"
62
+ },
63
+ {
64
+ "name": "Rafael Campos",
65
+ "url": "https://github.com/rafbcampos"
58
66
  }
59
67
  ],
60
68
  "bundle": "./dist/check-path-plugin.prod.js"
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import type { Player, PlayerPlugin, Node, Resolver } from '@player-ui/player';
3
3
  import type { Asset } from '@player-ui/types';
4
4
  import { createObjectMatcher } from '@player-ui/partial-match-registry';
5
5
  import dlv from 'dlv';
6
+ import { CheckPathPluginSymbol } from './symbols';
6
7
 
7
8
  export type QueryFunction = (asset: Asset) => boolean;
8
9
  export type Query = QueryFunction | string | object;
@@ -51,7 +52,7 @@ interface ViewInfo {
51
52
  */
52
53
  function getParent(
53
54
  node: Node.Node,
54
- viewInfo: ViewInfo
55
+ viewInfo?: ViewInfo
55
56
  ): Node.ViewOrAsset | undefined {
56
57
  let working = node;
57
58
 
@@ -69,12 +70,7 @@ function getParent(
69
70
  parent &&
70
71
  (parent.type === NodeType.Asset || parent.type === NodeType.View)
71
72
  ) {
72
- const sourceNode = viewInfo.resolver.getSourceNode(parent);
73
- const viewOrAsset =
74
- sourceNode?.type === NodeType.Applicability
75
- ? sourceNode.value
76
- : viewInfo.resolver.getSourceNode(parent);
77
- return (viewOrAsset ?? parent) as Node.ViewOrAsset;
73
+ return parent;
78
74
  }
79
75
  }
80
76
 
@@ -85,6 +81,7 @@ function getParent(
85
81
  export class CheckPathPlugin implements PlayerPlugin {
86
82
  name = 'check-path';
87
83
  private viewInfo?: ViewInfo;
84
+ public readonly symbol = CheckPathPluginSymbol;
88
85
 
89
86
  apply(player: Player) {
90
87
  player.hooks.viewController.tap(this.name, (viewController) => {
@@ -139,14 +136,12 @@ export class CheckPathPlugin implements PlayerPlugin {
139
136
  return undefined;
140
137
  }
141
138
 
142
- let potentialMatch = getParent(assetNode, this.viewInfo);
139
+ let potentialMatch = getParent(assetNode);
143
140
 
144
141
  // Handle the case of an empty query (just get the immediate parent)
145
142
  if (query === undefined) {
146
143
  if (potentialMatch) {
147
- const resolved = this.viewInfo.resolvedMap.get(potentialMatch);
148
-
149
- return resolved?.value;
144
+ return this.getAssetFromAssetNode(potentialMatch);
150
145
  }
151
146
 
152
147
  return;
@@ -166,18 +161,18 @@ export class CheckPathPlugin implements PlayerPlugin {
166
161
  }
167
162
 
168
163
  const matcher = createMatcher(parentQuery);
169
- const resolved = this.viewInfo.resolvedMap.get(potentialMatch);
164
+ const resolved = this.getAssetFromAssetNode(potentialMatch);
170
165
 
171
- if (resolved && matcher(resolved.value)) {
166
+ if (resolved && matcher(resolved)) {
172
167
  // This is the last match.
173
168
  if (queryArray.length === 0) {
174
- return resolved.value;
169
+ return resolved;
175
170
  }
176
171
 
177
172
  parentQuery = queryArray.shift();
178
173
  }
179
174
 
180
- potentialMatch = getParent(potentialMatch, this.viewInfo);
175
+ potentialMatch = getParent(potentialMatch);
181
176
  }
182
177
 
183
178
  return undefined;
@@ -200,9 +195,7 @@ export class CheckPathPlugin implements PlayerPlugin {
200
195
  let parent;
201
196
 
202
197
  while (working) {
203
- parent =
204
- working?.parent &&
205
- this.viewInfo.resolvedMap.get(working.parent)?.resolved;
198
+ parent = working?.parent;
206
199
 
207
200
  if (
208
201
  parent &&
@@ -263,12 +256,9 @@ export class CheckPathPlugin implements PlayerPlugin {
263
256
  node.type === NodeType.View ||
264
257
  node.type === NodeType.Applicability
265
258
  ) {
266
- const resolved =
267
- node.type === NodeType.Applicability
268
- ? this.viewInfo?.resolvedMap.get(node.value)
269
- : this.viewInfo?.resolvedMap.get(node);
259
+ const resolvedValue = this.getResolvedValue(node);
270
260
  const includesSelf =
271
- (includeSelfMatch && resolved && matcher(resolved.value)) ?? false;
261
+ (includeSelfMatch && matcher(resolvedValue)) ?? false;
272
262
  const childQuery = includesSelf ? rest : query;
273
263
 
274
264
  if (childQuery.length === 0 && includesSelf) {
@@ -329,6 +319,15 @@ export class CheckPathPlugin implements PlayerPlugin {
329
319
  const assetNode = this.viewInfo?.assetIdMap.get(id);
330
320
  if (!assetNode) return;
331
321
 
322
+ return this.getAssetFromAssetNode(assetNode);
323
+ }
324
+
325
+ /**
326
+ * Gets the value for an asset from an asset node
327
+ */
328
+ public getAssetFromAssetNode(
329
+ assetNode: Node.Asset | Node.View
330
+ ): Asset | undefined {
332
331
  const sourceNode = this.getSourceAssetNode(assetNode);
333
332
  if (!sourceNode) return;
334
333
 
@@ -367,23 +366,20 @@ export class CheckPathPlugin implements PlayerPlugin {
367
366
  };
368
367
 
369
368
  while (working !== undefined) {
370
- const parent =
371
- working?.parent && this.viewInfo.resolvedMap.get(working.parent);
369
+ const { parent } = working;
372
370
 
373
- const parentNode = parent?.resolved;
374
-
375
- if (parentNode) {
376
- if (parentNode.type === NodeType.MultiNode) {
377
- const index = parentNode.values.indexOf(working);
371
+ if (parent) {
372
+ if (parent.type === NodeType.MultiNode) {
373
+ const index = parent.values.indexOf(working);
378
374
 
379
375
  if (index !== -1) {
380
376
  const actualIndex =
381
377
  index -
382
- parentNode.values
378
+ parent.values
383
379
  .slice(0, index)
384
380
  .reduce(
385
381
  (undefCount, next) =>
386
- this.viewInfo?.resolvedMap.get(next)?.value === undefined
382
+ this.getResolvedValue(next) === undefined
387
383
  ? undefCount + 1
388
384
  : undefCount,
389
385
  0
@@ -391,18 +387,17 @@ export class CheckPathPlugin implements PlayerPlugin {
391
387
 
392
388
  path = [actualIndex, ...path];
393
389
  }
394
- } else if ('children' in parentNode) {
395
- const childProp = findWorkingChild(parentNode);
390
+ } else if ('children' in parent) {
391
+ const childProp = findWorkingChild(parent);
396
392
  path = [...(childProp?.path ?? []), ...path];
397
393
  }
398
- }
399
-
400
- if (parentQuery) {
401
- const matcher = createMatcher(parentQuery);
402
394
 
403
- if (matcher(parent?.value)) {
404
- parentQuery = queryArray.shift();
405
- if (!parentQuery) return path;
395
+ if (parentQuery) {
396
+ const matcher = createMatcher(parentQuery);
397
+ if (matcher(this.getResolvedValue(parent))) {
398
+ parentQuery = queryArray.shift();
399
+ if (!parentQuery) return path;
400
+ }
406
401
  }
407
402
  }
408
403
 
@@ -411,6 +406,11 @@ export class CheckPathPlugin implements PlayerPlugin {
411
406
 
412
407
  /* if at the end all queries haven't been consumed,
413
408
  it means we couldn't find a path till the matching query */
414
- return queryArray.length === 0 ? path : undefined;
409
+ return parentQuery ? undefined : path;
410
+ }
411
+
412
+ private getResolvedValue(node: Node.Node) {
413
+ const sourceNode = this.getSourceAssetNode(node);
414
+ return this.viewInfo?.resolvedMap.get(sourceNode ?? node)?.value;
415
415
  }
416
416
  }
package/src/symbols.ts ADDED
@@ -0,0 +1 @@
1
+ export const CheckPathPluginSymbol = Symbol.for('CheckPathPlugin');