@plasmicapp/loader-react 1.0.163 → 1.0.166

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.
@@ -70,6 +70,16 @@ export declare function PlasmicRootProvider(props: {
70
70
  * Translator function to be used for text blocks
71
71
  */
72
72
  translator?: PlasmicTranslator;
73
+ /**
74
+ * Page path parameters (e.g. {slug: "foo"} if page path is
75
+ * /products/[slug] and URI is /products/foo).
76
+ */
77
+ pageParams?: Record<string, string>;
78
+ /**
79
+ * Page query parameters (e.g. {q: "foo"} if page path is
80
+ * /some/path?q=foo).
81
+ */
82
+ pageQuery?: Record<string, string>;
73
83
  }): JSX.Element;
74
84
  export declare function usePlasmicRootContext(): PlasmicRootContextValue | undefined;
75
85
  export {};
@@ -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) {
@@ -1346,7 +1399,9 @@ function PlasmicRootProvider(props) {
1346
1399
  suspenseForQueryData = props.suspenseForQueryData,
1347
1400
  globalContextsProps = props.globalContextsProps,
1348
1401
  variation = props.variation,
1349
- translator = props.translator;
1402
+ translator = props.translator,
1403
+ pageParams = props.pageParams,
1404
+ pageQuery = props.pageQuery;
1350
1405
  var loader = props.loader.__internal;
1351
1406
 
1352
1407
  if (prefetchedData) {
@@ -1402,7 +1457,10 @@ function PlasmicRootProvider(props) {
1402
1457
  loader: loader,
1403
1458
  prefetchedData: prefetchedData,
1404
1459
  skipFonts: skipFonts
1405
- }), children));
1460
+ }), React.createElement(PlasmicHost.PageParamsProvider, {
1461
+ params: pageParams,
1462
+ query: pageQuery
1463
+ }, children)));
1406
1464
  }
1407
1465
  /**
1408
1466
  * Inject all css modules as <style/> tags. We can't use the usual styleInjector postcss