@plasmicapp/loader-react 1.0.162 → 1.0.165

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.
@@ -1,5 +1,5 @@
1
1
  import * as PlasmicHost from '@plasmicapp/host';
2
- import { registerComponent, registerGlobalContext, registerTrait } from '@plasmicapp/host';
2
+ import { PageParamsProvider, registerComponent, registerGlobalContext, registerTrait } from '@plasmicapp/host';
3
3
  export { DataCtxReader, DataProvider, PageParamsProvider, PlasmicCanvasContext, PlasmicCanvasHost, repeatedElement, useDataEnv, usePlasmicCanvasContext, useSelector, useSelectors } from '@plasmicapp/host';
4
4
  import * as PlasmicQuery from '@plasmicapp/query';
5
5
  import { PlasmicQueryDataProvider, PlasmicPrepassContext } from '@plasmicapp/query';
@@ -1126,19 +1126,72 @@ function useIsMounted() {
1126
1126
  }, []);
1127
1127
  return isMounted;
1128
1128
  }
1129
+ /**
1130
+ * Check if `lookup` resolves to `pagePath`. If it's a match, return an object
1131
+ * containing path params; otherwise, returns false.
1132
+ *
1133
+ * For example,
1134
+ * - `matchesPagePath("/hello/[name]", "/hello/world")` -> `{params: {name:
1135
+ * "world"}}`
1136
+ * - `matchesPagePath("/hello/[name]", "/")` -> `false`
1137
+ * - `matchesPagePath("/", "")` -> `{params: {}}`
1138
+ */
1139
+
1140
+ function matchesPagePath(pagePath, lookup) {
1141
+ var _lookup$match;
1142
+
1143
+ // Remove trailing slashes from both `pagePath` and `lookup`.
1144
+ pagePath = pagePath.replace(/^\/*/, '').replace(/\/*$/, '');
1145
+ lookup = lookup.replace(/^\/*/, '').replace(/\/*$/, ''); // paramNames will contain a list of parameter names; e.g. if pagePath
1146
+ // is "/products/[slug]/[variant]" it will contain ["slug", "variant"].
1147
+
1148
+ var paramNames = (pagePath.match(/\[([^\]]*)\]/g) || []).map(function (group) {
1149
+ return group.slice(1, -1);
1150
+ });
1151
+ var pagePathRegExp = new RegExp('^' + pagePath.replace(/\[[^\]]*\]/g, '([^/]+)') + '$');
1152
+ var maybeVals = (_lookup$match = lookup.match(pagePathRegExp)) == null ? void 0 : _lookup$match.slice(1);
1153
+
1154
+ if (!maybeVals) {
1155
+ return false;
1156
+ }
1157
+
1158
+ var params = {};
1159
+
1160
+ for (var i = 0; i < paramNames.length; i++) {
1161
+ params[paramNames[i]] = maybeVals[i];
1162
+ }
1163
+
1164
+ return {
1165
+ params: params
1166
+ };
1167
+ }
1129
1168
 
1130
1169
  function matchesCompMeta(lookup, meta) {
1131
1170
  if (lookup.projectId && meta.projectId !== lookup.projectId) {
1132
1171
  return false;
1133
1172
  }
1134
1173
 
1135
- 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;
1174
+ 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));
1136
1175
  }
1137
1176
 
1138
1177
  function getCompMetas(metas, lookup) {
1139
1178
  var full = toFullLookup(lookup);
1140
1179
  return metas.filter(function (meta) {
1141
1180
  return matchesCompMeta(full, meta);
1181
+ }).map(function (meta) {
1182
+ if (isNameSpec(full) || !meta.path) {
1183
+ return meta;
1184
+ }
1185
+
1186
+ var match = matchesPagePath(meta.path, full.path);
1187
+
1188
+ if (!match) {
1189
+ return meta;
1190
+ }
1191
+
1192
+ return _extends({}, meta, {
1193
+ params: match.params
1194
+ });
1142
1195
  });
1143
1196
  }
1144
1197
  function getLookupSpecName(lookup) {
@@ -1343,7 +1396,9 @@ function PlasmicRootProvider(props) {
1343
1396
  suspenseForQueryData = props.suspenseForQueryData,
1344
1397
  globalContextsProps = props.globalContextsProps,
1345
1398
  variation = props.variation,
1346
- translator = props.translator;
1399
+ translator = props.translator,
1400
+ pageParams = props.pageParams,
1401
+ pageQuery = props.pageQuery;
1347
1402
  var loader = props.loader.__internal;
1348
1403
 
1349
1404
  if (prefetchedData) {
@@ -1399,7 +1454,10 @@ function PlasmicRootProvider(props) {
1399
1454
  loader: loader,
1400
1455
  prefetchedData: prefetchedData,
1401
1456
  skipFonts: skipFonts
1402
- }), children));
1457
+ }), createElement(PageParamsProvider, {
1458
+ params: pageParams,
1459
+ query: pageQuery
1460
+ }, children)));
1403
1461
  }
1404
1462
  /**
1405
1463
  * Inject all css modules as <style/> tags. We can't use the usual styleInjector postcss