@plasmicapp/loader-react 1.0.161 → 1.0.164

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.
@@ -1129,19 +1129,72 @@ function useIsMounted() {
1129
1129
  }, []);
1130
1130
  return isMounted;
1131
1131
  }
1132
+ /**
1133
+ * Check if `lookup` resolves to `pagePath`. If it's a match, return an object
1134
+ * containing path params; otherwise, returns false.
1135
+ *
1136
+ * For example,
1137
+ * - `matchesPagePath("/hello/[name]", "/hello/world")` -> `{params: {name:
1138
+ * "world"}}`
1139
+ * - `matchesPagePath("/hello/[name]", "/")` -> `false`
1140
+ * - `matchesPagePath("/", "")` -> `{params: {}}`
1141
+ */
1142
+
1143
+ function matchesPagePath(pagePath, lookup) {
1144
+ var _lookup$match;
1145
+
1146
+ // Remove trailing slashes from both `pagePath` and `lookup`.
1147
+ pagePath = pagePath.replace(/^\/*/, '').replace(/\/*$/, '');
1148
+ lookup = lookup.replace(/^\/*/, '').replace(/\/*$/, ''); // paramNames will contain a list of parameter names; e.g. if pagePath
1149
+ // is "/products/[slug]/[variant]" it will contain ["slug", "variant"].
1150
+
1151
+ var paramNames = (pagePath.match(/\[([^\]]*)\]/g) || []).map(function (group) {
1152
+ return group.slice(1, -1);
1153
+ });
1154
+ var pagePathRegExp = new RegExp('^' + pagePath.replace(/\[[^\]]*\]/g, '([^/]+)') + '$');
1155
+ var maybeVals = (_lookup$match = lookup.match(pagePathRegExp)) == null ? void 0 : _lookup$match.slice(1);
1156
+
1157
+ if (!maybeVals) {
1158
+ return false;
1159
+ }
1160
+
1161
+ var params = {};
1162
+
1163
+ for (var i = 0; i < paramNames.length; i++) {
1164
+ params[paramNames[i]] = maybeVals[i];
1165
+ }
1166
+
1167
+ return {
1168
+ params: params
1169
+ };
1170
+ }
1132
1171
 
1133
1172
  function matchesCompMeta(lookup, meta) {
1134
1173
  if (lookup.projectId && meta.projectId !== lookup.projectId) {
1135
1174
  return false;
1136
1175
  }
1137
1176
 
1138
- return isNameSpec(lookup) ? (lookup.name === meta.name || lookup.rawName === meta.name || lookup.rawName === meta.displayName) && (lookup.isCode == null || lookup.isCode === meta.isCode) : lookup.path === meta.path;
1177
+ return isNameSpec(lookup) ? (lookup.name === meta.name || lookup.rawName === meta.name || lookup.rawName === meta.displayName) && (lookup.isCode == null || lookup.isCode === meta.isCode) : !!(meta.path && matchesPagePath(meta.path, lookup.path));
1139
1178
  }
1140
1179
 
1141
1180
  function getCompMetas(metas, lookup) {
1142
1181
  var full = toFullLookup(lookup);
1143
1182
  return metas.filter(function (meta) {
1144
1183
  return matchesCompMeta(full, meta);
1184
+ }).map(function (meta) {
1185
+ if (isNameSpec(full) || !meta.path) {
1186
+ return meta;
1187
+ }
1188
+
1189
+ var match = matchesPagePath(meta.path, full.path);
1190
+
1191
+ if (!match) {
1192
+ return meta;
1193
+ }
1194
+
1195
+ return _extends({}, meta, {
1196
+ params: match.params
1197
+ });
1145
1198
  });
1146
1199
  }
1147
1200
  function getLookupSpecName(lookup) {