@koordinates/xstate-tree 4.8.0 → 4.8.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.
@@ -96,19 +96,34 @@ function buildCreateRoute(history, basePath) {
96
96
  },
97
97
  // @ts-ignore :cry:
98
98
  matches(suppliedUrl, search) {
99
- var _a, _b, _c, _d;
99
+ var _a, _b, _c, _d, _e;
100
100
  const fullUrl = suppliedUrl.endsWith("/")
101
101
  ? suppliedUrl
102
102
  : suppliedUrl + "/";
103
103
  let url = fullUrl;
104
104
  const parentRoutes = getParentArray();
105
105
  let params = {};
106
+ const parsedQuery = (0, query_string_1.parse)(search);
106
107
  while (parentRoutes.length) {
107
108
  const parentRoute = parentRoutes.shift();
108
109
  const parentMatch = parentRoute.matcher(url, undefined);
109
110
  if (parentMatch === false) {
110
111
  return false;
111
112
  }
113
+ // Evaluate parent's canMatch predicate if provided
114
+ if (parentRoute.canMatch) {
115
+ const accumulatedParams = {
116
+ ...params,
117
+ ...((_a = parentMatch.params) !== null && _a !== void 0 ? _a : {}),
118
+ };
119
+ const canMatchResult = parentRoute.canMatch({
120
+ params: accumulatedParams,
121
+ query: parsedQuery,
122
+ });
123
+ if (!canMatchResult) {
124
+ return false;
125
+ }
126
+ }
112
127
  url = url.slice(parentMatch.matchLength);
113
128
  // All routes assume the url starts with a /
114
129
  // so if the parent route matches the / in the url, which consumes it
@@ -116,7 +131,7 @@ function buildCreateRoute(history, basePath) {
116
131
  if (!url.startsWith("/")) {
117
132
  url = "/" + url;
118
133
  }
119
- params = { ...params, ...((_a = parentMatch.params) !== null && _a !== void 0 ? _a : {}) };
134
+ params = { ...params, ...((_b = parentMatch.params) !== null && _b !== void 0 ? _b : {}) };
120
135
  }
121
136
  const matches = matcher(url, (0, query_string_1.parse)(search));
122
137
  // if there is any URL left after matching this route, the last to match
@@ -126,7 +141,7 @@ function buildCreateRoute(history, basePath) {
126
141
  }
127
142
  const fullParams = {
128
143
  ...params,
129
- ...((_b = matches.params) !== null && _b !== void 0 ? _b : {}),
144
+ ...((_c = matches.params) !== null && _c !== void 0 ? _c : {}),
130
145
  };
131
146
  if (fullParamsSchema) {
132
147
  fullParamsSchema.parse(fullParams);
@@ -138,7 +153,7 @@ function buildCreateRoute(history, basePath) {
138
153
  if (canMatch) {
139
154
  const canMatchResult = canMatch({
140
155
  params: fullParams,
141
- query: (_c = matches.query) !== null && _c !== void 0 ? _c : {},
156
+ query: (_d = matches.query) !== null && _d !== void 0 ? _d : {},
142
157
  });
143
158
  if (!canMatchResult) {
144
159
  return false;
@@ -148,7 +163,7 @@ function buildCreateRoute(history, basePath) {
148
163
  originalUrl: `${fullUrl}${search}`,
149
164
  type: event,
150
165
  params: fullParams,
151
- query: (_d = matches.query) !== null && _d !== void 0 ? _d : {},
166
+ query: (_e = matches.query) !== null && _e !== void 0 ? _e : {},
152
167
  };
153
168
  },
154
169
  // @ts-ignore :cry:
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@koordinates/xstate-tree",
3
3
  "main": "lib/index.js",
4
4
  "types": "lib/xstate-tree.d.ts",
5
- "version": "4.8.0",
5
+ "version": "4.8.1",
6
6
  "license": "MIT",
7
7
  "description": "Build UIs with Actors using xstate and React",
8
8
  "keywords": [