@plasmicapp/loader-react 1.0.327 → 1.0.329

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.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AssetModule } from '@plasmicapp/loader-core';
2
2
  import { CodeComponentMeta as CodeComponentMeta_2 } from '@plasmicapp/host';
3
+ import { CodeModule } from '@plasmicapp/loader-fetcher';
3
4
  import { ComponentMeta } from '@plasmicapp/loader-core';
4
5
  import { CustomFunctionMeta as CustomFunctionMeta_2 } from '@plasmicapp/host';
5
6
  import { DataCtxReader } from '@plasmicapp/host';
@@ -239,6 +240,7 @@ export declare class InternalPlasmicComponentLoader {
239
240
  fetchPages(opts?: FetchPagesOpts): Promise<PageMeta_2[]>;
240
241
  fetchComponents(): Promise<ComponentMeta[]>;
241
242
  getActiveSplits(): Split[];
243
+ getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]): string;
242
244
  trackConversion(value?: number): void;
243
245
  getActiveVariation(opts: {
244
246
  traits: Record<string, string | number | boolean>;
@@ -260,11 +262,12 @@ export declare class InternalPlasmicComponentLoader {
260
262
  * "world"}}`
261
263
  * - `matchesPagePath("/hello/[name]", "/")` -> `false`
262
264
  * - `matchesPagePath("/hello/[...catchall]", "/hello/a/b/c")` -> `{params: {catchall: ["a", "b", "c"]}}`
265
+ * - `matchesPagePath("/hello/[[...catchall]]", "/hello/")` -> `{params: {catchall: []}}`
263
266
  * - `matchesPagePath("/", "")` -> `{params: {}}`
264
267
  */
265
- export declare function matchesPagePath(pagePath: string, lookup: string): {
268
+ export declare function matchesPagePath(pattern: string, path: string): false | {
266
269
  params: Record<string, string | string[]>;
267
- } | false;
270
+ };
268
271
 
269
272
  export { PageMeta }
270
273
 
@@ -374,6 +377,7 @@ export declare class PlasmicComponentLoader {
374
377
  known?: Record<string, string>;
375
378
  traits: Record<string, string | number | boolean>;
376
379
  }): Promise<Record<string, string>>;
380
+ getChunksUrl(bundle: LoaderBundleOutput, modules: CodeModule[]): string;
377
381
  getExternalVariation(variation: Record<string, string>, filters?: Parameters<typeof getExternalIds>[2]): Record<string, string>;
378
382
  getActiveSplits(): Split[];
379
383
  trackConversion(value?: number): void;
package/dist/index.esm.js CHANGED
@@ -67,7 +67,9 @@ import {
67
67
  PlasmicTracker,
68
68
  Registry
69
69
  } from "@plasmicapp/loader-core";
70
- import { internal_getCachedBundleInNodeServer } from "@plasmicapp/loader-fetcher";
70
+ import {
71
+ internal_getCachedBundleInNodeServer
72
+ } from "@plasmicapp/loader-fetcher";
71
73
  import { getActiveVariation, getExternalIds } from "@plasmicapp/loader-splits";
72
74
  import * as PlasmicQuery from "@plasmicapp/query";
73
75
  import React3 from "react";
@@ -147,26 +149,27 @@ function useIsMounted() {
147
149
  }, []);
148
150
  return isMounted;
149
151
  }
150
- function matchesPagePath(pagePath, lookup) {
151
- var _a;
152
- pagePath = pagePath.replace(/^\/*/, "").replace(/\/*$/, "");
153
- lookup = lookup.replace(/^\/*/, "").replace(/\/*$/, "");
154
- const paramNames = (pagePath.match(/\[([^\]]*)\]/g) || []).map(
155
- (group) => group.slice(1, -1)
156
- );
157
- const pagePathRegExp = new RegExp(
158
- "^/?" + pagePath.replace(/\[\.\.\.[^\]]*\]/g, "(.+)").replace(/\[[^\]]*\]/g, "([^/]+)") + "$"
159
- );
160
- const maybeVals = (_a = lookup.replace(/[?].*/, "").match(pagePathRegExp)) == null ? void 0 : _a.slice(1);
161
- if (!maybeVals) {
152
+ function matchesPagePath(pattern, path) {
153
+ const normalizedPattern = "/" + pattern.replace(/^\/|\/$/g, "");
154
+ const normalizedPath = "/" + path.replace(/^\/|\/$/g, "");
155
+ const regexString = normalizedPattern.replace(/\/\[\[\.\.\.(\w+)]]/g, "(?:/([^]*))?").replace(/\/\[\.\.\.(\w+)]/g, "/([^]*)").replace(/\[(\w+)]/g, "([^/]+)").replace(/\//g, "\\/");
156
+ const regex = new RegExp(`^/?${regexString}$`);
157
+ const match = normalizedPath.match(regex);
158
+ if (!match)
162
159
  return false;
163
- }
160
+ const slugNames = [...pattern.matchAll(/\[\.?\.?\.?(\w+)]/g)].map(
161
+ (m) => m[1]
162
+ );
164
163
  const params = {};
165
- for (let i = 0; i < paramNames.length; i++) {
166
- if (paramNames[i].startsWith("...")) {
167
- params[paramNames[i].slice(3)] = maybeVals[i].split("/");
168
- } else {
169
- params[paramNames[i]] = maybeVals[i];
164
+ for (let i = 0; i < slugNames.length; i++) {
165
+ const slugName = slugNames[i];
166
+ const value = match[i + 1];
167
+ if (pattern.includes(`[[...${slugName}]]`)) {
168
+ params[slugName] = value ? value.split("/").filter(Boolean) : [];
169
+ } else if (pattern.includes(`[...${slugName}]`)) {
170
+ params[slugName] = value.split("/").filter(Boolean);
171
+ } else if (value !== void 0) {
172
+ params[slugName] = value;
170
173
  }
171
174
  }
172
175
  return { params };
@@ -673,7 +676,8 @@ var ReactServerPlasmicComponentLoader = class {
673
676
  globalGroups: [],
674
677
  external: [],
675
678
  projects: [],
676
- activeSplits: []
679
+ activeSplits: [],
680
+ bundleUrlQuery: null
677
681
  };
678
682
  this.opts = args.opts;
679
683
  this.fetcher = args.fetcher;
@@ -751,6 +755,9 @@ var ReactServerPlasmicComponentLoader = class {
751
755
  getActiveSplits() {
752
756
  return this.bundle.activeSplits;
753
757
  }
758
+ getChunksUrl(bundle, modules) {
759
+ return this.fetcher.getChunksUrl(bundle, modules);
760
+ }
754
761
  fetchMissingData(opts) {
755
762
  return __async(this, null, function* () {
756
763
  this.maybeReportClientSideFetch(
@@ -780,9 +787,10 @@ var ReactServerPlasmicComponentLoader = class {
780
787
  });
781
788
  }
782
789
  mergeBundle(bundle) {
783
- var _a;
790
+ var _a, _b;
784
791
  this.bundle = bundle;
785
- (_a = this.onBundleMerged) == null ? void 0 : _a.call(this);
792
+ this.bundle.bundleUrlQuery = (_a = this.bundle.bundleUrlQuery) != null ? _a : null;
793
+ (_b = this.onBundleMerged) == null ? void 0 : _b.call(this);
786
794
  }
787
795
  getBundle() {
788
796
  return this.bundle;
@@ -797,7 +805,8 @@ var ReactServerPlasmicComponentLoader = class {
797
805
  globalGroups: [],
798
806
  external: [],
799
807
  projects: [],
800
- activeSplits: []
808
+ activeSplits: [],
809
+ bundleUrlQuery: null
801
810
  };
802
811
  }
803
812
  };
@@ -993,6 +1002,9 @@ var InternalPlasmicComponentLoader = class {
993
1002
  getActiveSplits() {
994
1003
  return this.reactServerLoader.getActiveSplits();
995
1004
  }
1005
+ getChunksUrl(bundle, modules) {
1006
+ return this.reactServerLoader.getChunksUrl(bundle, modules);
1007
+ }
996
1008
  trackConversion(value = 0) {
997
1009
  this.tracker.trackConversion(value);
998
1010
  }
@@ -1162,6 +1174,9 @@ var PlasmicComponentLoader = class {
1162
1174
  });
1163
1175
  });
1164
1176
  }
1177
+ getChunksUrl(bundle, modules) {
1178
+ return this.__internal.getChunksUrl(bundle, modules);
1179
+ }
1165
1180
  getExternalVariation(variation, filters) {
1166
1181
  return getExternalIds(this.getActiveSplits(), variation, filters);
1167
1182
  }