@plasmicapp/loader-react 1.0.341 → 1.0.343

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.
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
24
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
25
37
  var __export = (target, all) => {
26
38
  for (var name in all)
27
39
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -67,14 +79,27 @@ var __async = (__this, __arguments, generator) => {
67
79
  // src/react-server.ts
68
80
  var react_server_exports = {};
69
81
  __export(react_server_exports, {
70
- ReactServerPlasmicComponentLoader: () => ReactServerPlasmicComponentLoader,
82
+ InternalPlasmicComponentLoader: () => InternalPrepassPlasmicLoader,
83
+ PlasmicComponentLoader: () => PlasmicComponentLoader,
84
+ __EXPERMIENTAL__extractPlasmicQueryData: () => extractPlasmicQueryData,
71
85
  convertBundlesToComponentRenderData: () => convertBundlesToComponentRenderData,
72
86
  initPlasmicLoader: () => initPlasmicLoader,
73
87
  matchesPagePath: () => matchesPagePath
74
88
  });
75
89
  module.exports = __toCommonJS(react_server_exports);
76
90
  var import_server_only = require("server-only");
91
+
92
+ // src/loader-server.tsx
93
+ var import_loader_core3 = require("@plasmicapp/loader-core");
94
+ var import_react = __toESM(require("react"));
95
+ var import_react_dom = __toESM(require("react-dom"));
96
+ var jsxDevRuntime = __toESM(require("react/jsx-dev-runtime"));
97
+ var jsxRuntime = __toESM(require("react/jsx-runtime"));
98
+
99
+ // src/loader-shared.ts
77
100
  var import_loader_core2 = require("@plasmicapp/loader-core");
101
+ var import_loader_fetcher = require("@plasmicapp/loader-fetcher");
102
+ var import_loader_splits = require("@plasmicapp/loader-splits");
78
103
 
79
104
  // src/bundles.ts
80
105
  var import_loader_core = require("@plasmicapp/loader-core");
@@ -146,7 +171,7 @@ function prepComponentData(bundle, compMetas, opts) {
146
171
  };
147
172
  }
148
173
  function mergeBundles(target, from) {
149
- var _a;
174
+ var _a2;
150
175
  const existingCompIds = new Set(target.components.map((c) => c.id));
151
176
  const newCompMetas = from.components.filter(
152
177
  (m) => !existingCompIds.has(m.id)
@@ -190,13 +215,8 @@ function mergeBundles(target, from) {
190
215
  globalGroups: [...target.globalGroups, ...newGlobals]
191
216
  });
192
217
  }
193
- const existingExternals = new Set(target.external);
194
- const newExternals = target.external.filter((x) => !existingExternals.has(x));
195
- if (newExternals.length > 0) {
196
- target = __spreadProps(__spreadValues({}, target), { external: [...target.external, ...newExternals] });
197
- }
198
218
  const existingSplitIds = new Set(target.activeSplits.map((s) => s.id));
199
- const newSplits = (_a = from.activeSplits.filter((s) => !existingSplitIds.has(s.id))) != null ? _a : [];
219
+ const newSplits = (_a2 = from.activeSplits.filter((s) => !existingSplitIds.has(s.id))) != null ? _a2 : [];
200
220
  if (newSplits.length > 0) {
201
221
  target = __spreadProps(__spreadValues({}, target), {
202
222
  activeSplits: [...target.activeSplits, ...newSplits]
@@ -305,10 +325,169 @@ function getLookupSpecName(lookup) {
305
325
  return lookup.name;
306
326
  }
307
327
  }
328
+ function uniq(elements) {
329
+ return Array.from(new Set(elements));
330
+ }
331
+ function uniqBy(elements, iterator) {
332
+ const vis = /* @__PURE__ */ new Set();
333
+ const filtered = [];
334
+ for (const elt of elements) {
335
+ const key = iterator(elt);
336
+ if (!vis.has(key)) {
337
+ vis.add(key);
338
+ filtered.push(elt);
339
+ }
340
+ }
341
+ return filtered;
342
+ }
343
+
344
+ // src/component-lookup.ts
345
+ function getFirstCompMeta(metas, lookup) {
346
+ const filtered = getCompMetas(metas, lookup);
347
+ return filtered.length === 0 ? void 0 : filtered[0];
348
+ }
349
+ var ComponentLookup = class {
350
+ constructor(bundle, registry) {
351
+ this.bundle = bundle;
352
+ this.registry = registry;
353
+ }
354
+ getComponentMeta(spec) {
355
+ const compMeta = getFirstCompMeta(this.bundle.components, spec);
356
+ return compMeta;
357
+ }
358
+ getComponent(spec, opts = {}) {
359
+ const compMeta = getFirstCompMeta(this.bundle.components, spec);
360
+ if (!compMeta) {
361
+ throw new Error(`Component not found: ${spec}`);
362
+ }
363
+ const moduleName = compMeta.entry;
364
+ if (!this.registry.hasModule(moduleName, opts)) {
365
+ throw new Error(`Component not yet fetched: ${compMeta.name}`);
366
+ }
367
+ const entry = this.registry.load(moduleName, {
368
+ forceOriginal: opts.forceOriginal
369
+ });
370
+ return !opts.forceOriginal && typeof (entry == null ? void 0 : entry.getPlasmicComponent) === "function" ? entry.getPlasmicComponent() : entry.default;
371
+ }
372
+ hasComponent(spec) {
373
+ const compMeta = getFirstCompMeta(this.bundle.components, spec);
374
+ if (compMeta) {
375
+ return this.registry.hasModule(compMeta.entry);
376
+ }
377
+ return false;
378
+ }
379
+ getGlobalContexts() {
380
+ const customGlobalMetas = this.bundle.globalGroups.filter(
381
+ (m) => m.type === "global-user-defined"
382
+ );
383
+ return customGlobalMetas.map((meta) => ({
384
+ meta,
385
+ context: this.registry.load(meta.contextFile).default
386
+ }));
387
+ }
388
+ getGlobalContextsProvider(spec) {
389
+ const compMeta = getFirstCompMeta(this.bundle.components, spec);
390
+ const projectMeta = compMeta ? this.bundle.projects.find((x) => x.id === compMeta.projectId) : void 0;
391
+ if (!projectMeta || !projectMeta.globalContextsProviderFileName || !this.registry.hasModule(projectMeta.globalContextsProviderFileName)) {
392
+ return void 0;
393
+ }
394
+ const entry = this.registry.load(
395
+ projectMeta.globalContextsProviderFileName
396
+ );
397
+ return typeof (entry == null ? void 0 : entry.getPlasmicComponent) === "function" ? entry.getPlasmicComponent() : entry.default;
398
+ }
399
+ getRootProvider() {
400
+ const entry = this.registry.load("root-provider.js");
401
+ return entry.default;
402
+ }
403
+ getCss() {
404
+ return this.bundle.modules.browser.filter(
405
+ (mod) => mod.type === "asset" && mod.fileName.endsWith("css")
406
+ );
407
+ }
408
+ getRemoteFonts() {
409
+ return this.bundle.projects.flatMap((p) => p.remoteFonts);
410
+ }
411
+ };
412
+
413
+ // src/variation.ts
414
+ function getPlasmicCookieValues() {
415
+ return Object.fromEntries(
416
+ document.cookie.split("; ").filter((cookie) => cookie.includes("plasmic:")).map((cookie) => cookie.split("=")).map(([key, value]) => [key.split(":")[1], value])
417
+ );
418
+ }
419
+ function updatePlasmicCookieValue(key, value) {
420
+ document.cookie = `plasmic:${key}=${value}`;
421
+ }
422
+ var getGlobalVariantsFromSplits = (splits, variation) => {
423
+ const globalVariants = [];
424
+ Object.keys(variation).map((variationKey) => {
425
+ const [_type, splitId] = variationKey.split(".");
426
+ const sliceId = variation[variationKey];
427
+ const split = splits.find(
428
+ (s) => s.id === splitId || s.externalId === splitId
429
+ );
430
+ if (split) {
431
+ const slice = split.slices.find((s) => s.id === sliceId || s.externalId === sliceId);
432
+ if (slice) {
433
+ slice.contents.map((x) => {
434
+ globalVariants.push({
435
+ name: x.group,
436
+ value: x.variant,
437
+ projectId: x.projectId
438
+ });
439
+ });
440
+ }
441
+ }
442
+ });
443
+ return globalVariants;
444
+ };
445
+ var mergeGlobalVariantsSpec = (target, from) => {
446
+ let result = [...target];
447
+ const existingGlobalVariants = new Set(
448
+ target.map((t) => {
449
+ var _a2;
450
+ return `${t.name}-${(_a2 = t.projectId) != null ? _a2 : ""}`;
451
+ })
452
+ );
453
+ const newGlobals = from.filter(
454
+ (t) => {
455
+ var _a2;
456
+ return !existingGlobalVariants.has(`${t.name}-${(_a2 = t.projectId) != null ? _a2 : ""}`);
457
+ }
458
+ );
459
+ if (newGlobals.length > 0) {
460
+ result = [...result, ...newGlobals];
461
+ }
462
+ return result;
463
+ };
308
464
 
309
- // src/loader-react-server.ts
310
- var ReactServerPlasmicComponentLoader = class {
465
+ // src/loader-shared.ts
466
+ var SUBSTITUTED_COMPONENTS = {};
467
+ var REGISTERED_CODE_COMPONENT_HELPERS = {};
468
+ var SUBSTITUTED_GLOBAL_VARIANT_HOOKS = {};
469
+ var REGISTERED_CUSTOM_FUNCTIONS = {};
470
+ function customFunctionImportAlias(meta) {
471
+ const customFunctionPrefix = `__fn_`;
472
+ return meta.namespace ? `${customFunctionPrefix}${meta.namespace}__${meta.name}` : `${customFunctionPrefix}${meta.name}`;
473
+ }
474
+ function parseFetchComponentDataArgs(...args) {
475
+ let specs;
476
+ let opts;
477
+ if (Array.isArray(args[0])) {
478
+ specs = args[0];
479
+ opts = args[1];
480
+ } else {
481
+ specs = args;
482
+ opts = void 0;
483
+ }
484
+ return { specs, opts };
485
+ }
486
+ var BaseInternalPlasmicComponentLoader = class {
311
487
  constructor(args) {
488
+ this.registry = new import_loader_core2.Registry();
489
+ this.globalVariants = [];
490
+ this.subs = [];
312
491
  this.bundle = {
313
492
  modules: {
314
493
  browser: [],
@@ -316,7 +495,6 @@ var ReactServerPlasmicComponentLoader = class {
316
495
  },
317
496
  components: [],
318
497
  globalGroups: [],
319
- external: [],
320
498
  projects: [],
321
499
  activeSplits: [],
322
500
  bundleKey: null,
@@ -327,6 +505,7 @@ var ReactServerPlasmicComponentLoader = class {
327
505
  this.tracker = args.tracker;
328
506
  this.onBundleMerged = args.onBundleMerged;
329
507
  this.onBundleFetched = args.onBundleFetched;
508
+ this.registerModules(args.builtinModules);
330
509
  }
331
510
  maybeGetCompMetas(...specs) {
332
511
  const found = /* @__PURE__ */ new Set();
@@ -421,19 +600,58 @@ var ReactServerPlasmicComponentLoader = class {
421
600
  }
422
601
  fetchAllData() {
423
602
  return __async(this, null, function* () {
424
- var _a;
603
+ var _a2;
425
604
  const bundle = yield this.fetcher.fetchAllData();
426
605
  this.tracker.trackFetch();
427
606
  this.mergeBundle(bundle);
428
- (_a = this.onBundleFetched) == null ? void 0 : _a.call(this);
607
+ (_a2 = this.onBundleFetched) == null ? void 0 : _a2.call(this);
429
608
  return bundle;
430
609
  });
431
610
  }
432
- mergeBundle(bundle) {
433
- var _a, _b;
434
- this.bundle = bundle;
435
- this.bundle.bundleKey = (_a = this.bundle.bundleKey) != null ? _a : null;
436
- (_b = this.onBundleMerged) == null ? void 0 : _b.call(this);
611
+ mergeBundle(newBundle) {
612
+ var _a2, _b, _c, _d, _e;
613
+ newBundle.bundleKey = (_a2 = newBundle.bundleKey) != null ? _a2 : null;
614
+ if (newBundle.bundleKey && this.bundle.bundleKey && newBundle.bundleKey !== this.bundle.bundleKey) {
615
+ console.warn(
616
+ `Plasmic Error: Different code export hashes. This can happen if your app is using different loaders with different project IDs or project versions.
617
+ Conflicting values:
618
+ ${newBundle.bundleKey}
619
+ ${this.bundle.bundleKey}`
620
+ );
621
+ }
622
+ const bundles = [this.bundle, newBundle];
623
+ this.bundle = {
624
+ activeSplits: uniqBy(
625
+ bundles.flatMap((bundle) => bundle.activeSplits),
626
+ (split) => split.id
627
+ ),
628
+ components: uniqBy(
629
+ bundles.flatMap((bundle) => bundle.components),
630
+ (c) => c.id
631
+ ),
632
+ globalGroups: uniqBy(
633
+ bundles.flatMap((bundle) => bundle.globalGroups),
634
+ (g) => g.id
635
+ ),
636
+ modules: {
637
+ browser: uniqBy(
638
+ bundles.flatMap((bundle) => bundle.modules.browser),
639
+ (m) => m.fileName
640
+ ),
641
+ server: uniqBy(
642
+ bundles.flatMap((bundle) => bundle.modules.server),
643
+ (m) => m.fileName
644
+ )
645
+ },
646
+ projects: uniqBy(
647
+ bundles.flatMap((bundle) => bundle.projects),
648
+ (p) => p.id
649
+ ),
650
+ // Avoid `undefined` as it cannot be serialized as JSON
651
+ bundleKey: (_c = (_b = newBundle.bundleKey) != null ? _b : this.bundle.bundleKey) != null ? _c : null,
652
+ deferChunksByDefault: (_d = newBundle.deferChunksByDefault) != null ? _d : false
653
+ };
654
+ (_e = this.onBundleMerged) == null ? void 0 : _e.call(this);
437
655
  }
438
656
  getBundle() {
439
657
  return this.bundle;
@@ -446,37 +664,866 @@ var ReactServerPlasmicComponentLoader = class {
446
664
  },
447
665
  components: [],
448
666
  globalGroups: [],
449
- external: [],
450
667
  projects: [],
451
668
  activeSplits: [],
452
669
  bundleKey: null,
453
670
  deferChunksByDefault: false
454
671
  };
672
+ this.registry.clear();
673
+ }
674
+ registerModules(modules) {
675
+ if (Object.keys(modules).some(
676
+ (name) => this.registry.getRegisteredModule(name) !== modules[name]
677
+ )) {
678
+ if (!this.registry.isEmpty()) {
679
+ console.warn(
680
+ "Calling PlasmicComponentLoader.registerModules() after Plasmic component has rendered; starting over."
681
+ );
682
+ this.registry.clear();
683
+ }
684
+ for (const key of Object.keys(modules)) {
685
+ this.registry.register(key, modules[key]);
686
+ }
687
+ }
688
+ }
689
+ substituteComponent(component, name) {
690
+ this.internalSubstituteComponent(component, name, void 0);
691
+ }
692
+ internalSubstituteComponent(component, name, codeComponentHelpers) {
693
+ if (!this.isRegistryEmpty()) {
694
+ console.warn(
695
+ "Calling PlasmicComponentLoader.registerSubstitution() after Plasmic component has rendered; starting over."
696
+ );
697
+ this.clearRegistry();
698
+ }
699
+ this.subs.push({ lookup: name, component, codeComponentHelpers });
700
+ }
701
+ refreshRegistry() {
702
+ for (const sub of this.subs) {
703
+ const metas = getCompMetas(this.getBundle().components, sub.lookup);
704
+ metas.forEach((meta) => {
705
+ SUBSTITUTED_COMPONENTS[meta.id] = sub.component;
706
+ if (sub.codeComponentHelpers) {
707
+ REGISTERED_CODE_COMPONENT_HELPERS[meta.id] = sub.codeComponentHelpers;
708
+ }
709
+ });
710
+ }
711
+ this.registry.updateModules(this.getBundle());
712
+ }
713
+ isRegistryEmpty() {
714
+ return this.registry.isEmpty();
715
+ }
716
+ clearRegistry() {
717
+ this.registry.clear();
718
+ }
719
+ setGlobalVariants(globalVariants) {
720
+ this.globalVariants = globalVariants;
721
+ }
722
+ getGlobalVariants() {
723
+ return this.globalVariants;
724
+ }
725
+ registerPrefetchedBundle(bundle) {
726
+ if (!isBrowser) {
727
+ const cachedBundle = (0, import_loader_fetcher.internal_getCachedBundleInNodeServer)(this.opts);
728
+ if (cachedBundle) {
729
+ this.mergeBundle(cachedBundle);
730
+ }
731
+ }
732
+ this.mergeBundle(bundle);
733
+ }
734
+ getLookup() {
735
+ return new ComponentLookup(this.getBundle(), this.registry);
736
+ }
737
+ trackConversion(value = 0) {
738
+ this.tracker.trackConversion(value);
739
+ }
740
+ getActiveVariation(opts) {
741
+ return __async(this, null, function* () {
742
+ yield this.fetchComponents();
743
+ return (0, import_loader_splits.getActiveVariation)(__spreadProps(__spreadValues({}, opts), {
744
+ splits: this.getBundle().activeSplits
745
+ }));
746
+ });
747
+ }
748
+ getTeamIds() {
749
+ return uniq(
750
+ this.getBundle().projects.map(
751
+ (p) => p.teamId ? `${p.teamId}${p.indirect ? "@indirect" : ""}` : null
752
+ ).filter((x) => !!x)
753
+ );
754
+ }
755
+ getProjectIds() {
756
+ return uniq(
757
+ this.getBundle().projects.map(
758
+ (p) => `${p.id}${p.indirect ? "@indirect" : ""}`
759
+ )
760
+ );
761
+ }
762
+ trackRender(opts) {
763
+ this.tracker.trackRender(opts);
455
764
  }
456
765
  };
457
- function parseFetchComponentDataArgs(...args) {
458
- let specs;
459
- let opts;
460
- if (Array.isArray(args[0])) {
461
- specs = args[0];
462
- opts = args[1];
766
+ var PlasmicComponentLoader = class {
767
+ constructor(internal) {
768
+ this.warnedRegisterComponent = false;
769
+ this.__internal = internal;
770
+ }
771
+ /**
772
+ * Sets global variants to be used for all components. Note that
773
+ * this is not reactive, and will not re-render all components
774
+ * already mounted; instead, it should be used to activate global
775
+ * variants that should always be activated for the lifetime of this
776
+ * app. If you'd like to reactively change the global variants,
777
+ * you should specify them via <PlasmicRootProvider />
778
+ */
779
+ setGlobalVariants(globalVariants) {
780
+ this.__internal.setGlobalVariants(globalVariants);
781
+ }
782
+ registerModules(modules) {
783
+ this.__internal.registerModules(modules);
784
+ }
785
+ /**
786
+ * Register custom components that should be swapped in for
787
+ * components defined in your project. You can use this to
788
+ * swap in / substitute a Plasmic component with a "real" component.
789
+ */
790
+ substituteComponent(component, name) {
791
+ this.__internal.substituteComponent(component, name);
792
+ }
793
+ registerComponent(component, metaOrName) {
794
+ if (metaOrName && typeof metaOrName === "object" && "props" in metaOrName) {
795
+ this.__internal.registerComponent(component, metaOrName);
796
+ } else {
797
+ if (process.env.NODE_ENV === "development" && !this.warnedRegisterComponent) {
798
+ console.warn(
799
+ `PlasmicLoader: Using deprecated method \`registerComponent\` for component substitution. Please consider using \`substituteComponent\` instead.`
800
+ );
801
+ this.warnedRegisterComponent = true;
802
+ }
803
+ this.substituteComponent(component, metaOrName);
804
+ }
805
+ }
806
+ registerFunction(fn, meta) {
807
+ this.__internal.registerFunction(fn, meta);
808
+ }
809
+ registerGlobalContext(context, meta) {
810
+ this.__internal.registerGlobalContext(context, meta);
811
+ }
812
+ registerTrait(trait, meta) {
813
+ this.__internal.registerTrait(trait, meta);
814
+ }
815
+ registerToken(token) {
816
+ this.__internal.registerToken(token);
817
+ }
818
+ fetchComponentData(...args) {
819
+ return this.__internal.fetchComponentData(...args);
820
+ }
821
+ maybeFetchComponentData(...args) {
822
+ return __async(this, null, function* () {
823
+ return this.__internal.maybeFetchComponentData(...args);
824
+ });
825
+ }
826
+ /**
827
+ * Returns all the page component metadata for these projects.
828
+ */
829
+ fetchPages(opts) {
830
+ return __async(this, null, function* () {
831
+ return this.__internal.fetchPages(opts);
832
+ });
833
+ }
834
+ /**
835
+ * Returns all components metadata for these projects.
836
+ */
837
+ fetchComponents() {
838
+ return __async(this, null, function* () {
839
+ return this.__internal.fetchComponents();
840
+ });
841
+ }
842
+ _getActiveVariation(opts) {
843
+ return __async(this, null, function* () {
844
+ return this.__internal.getActiveVariation(opts);
845
+ });
846
+ }
847
+ getActiveVariation(opts) {
848
+ return __async(this, null, function* () {
849
+ return this._getActiveVariation({
850
+ traits: opts.traits,
851
+ getKnownValue: (key) => {
852
+ if (opts.known) {
853
+ return opts.known[key];
854
+ } else {
855
+ const cookies = getPlasmicCookieValues();
856
+ return cookies[key];
857
+ }
858
+ },
859
+ updateKnownValue: (key, value) => {
860
+ if (!opts.known) {
861
+ updatePlasmicCookieValue(key, value);
862
+ }
863
+ }
864
+ });
865
+ });
866
+ }
867
+ getChunksUrl(bundle, modules) {
868
+ return this.__internal.getChunksUrl(bundle, modules);
869
+ }
870
+ getExternalVariation(variation, filters) {
871
+ return (0, import_loader_splits.getExternalIds)(this.getActiveSplits(), variation, filters);
872
+ }
873
+ getActiveSplits() {
874
+ return this.__internal.getActiveSplits();
875
+ }
876
+ trackConversion(value = 0) {
877
+ this.__internal.trackConversion(value);
878
+ }
879
+ clearCache() {
880
+ return this.__internal.clearCache();
881
+ }
882
+ };
883
+
884
+ // src/swr-util.ts
885
+ function swrSerialize(key) {
886
+ if (typeof key === "function") {
887
+ try {
888
+ key = key();
889
+ } catch (err) {
890
+ key = "";
891
+ }
892
+ }
893
+ const args = [].concat(key);
894
+ key = typeof key == "string" ? key : (Array.isArray(key) ? key.length : key) ? stableHash(key) : "";
895
+ return [key, args];
896
+ }
897
+ var table = /* @__PURE__ */ new WeakMap();
898
+ var counter = 0;
899
+ function stableHash(arg) {
900
+ const type = typeof arg;
901
+ const constructor = arg && arg.constructor;
902
+ const isDate = constructor == Date;
903
+ let result;
904
+ let index;
905
+ if (Object(arg) === arg && !isDate && constructor != RegExp) {
906
+ result = table.get(arg);
907
+ if (result)
908
+ return result;
909
+ result = ++counter + "~";
910
+ table.set(arg, result);
911
+ if (constructor == Array) {
912
+ result = "@";
913
+ for (index = 0; index < arg.length; index++) {
914
+ result += stableHash(arg[index]) + ",";
915
+ }
916
+ table.set(arg, result);
917
+ }
918
+ if (constructor == Object) {
919
+ result = "#";
920
+ const keys = Object.keys(arg).sort();
921
+ while ((index = keys.pop()) !== void 0) {
922
+ if (arg[index] !== void 0) {
923
+ result += index + ":" + stableHash(arg[index]) + ",";
924
+ }
925
+ }
926
+ table.set(arg, result);
927
+ }
463
928
  } else {
464
- specs = args;
465
- opts = void 0;
929
+ result = isDate ? arg.toJSON() : type == "symbol" ? arg.toString() : type == "string" ? JSON.stringify(arg) : "" + arg;
466
930
  }
467
- return { specs, opts };
931
+ return result;
932
+ }
933
+
934
+ // src/loader-server.tsx
935
+ var noop = () => {
936
+ };
937
+ var identity = (x) => x;
938
+ var unreachable = () => {
939
+ debugger;
940
+ throw new Error("Unreachable code");
941
+ };
942
+ var REACT_PROVIDER_TYPE = typeof Symbol === "function" && Symbol.for ? Symbol.for("react.provider") : 60109;
943
+ var FakeRootProviderContext = {
944
+ _currentValue: void 0
945
+ // default value
946
+ };
947
+ var FakeDataContext = {
948
+ _currentValue: void 0
949
+ // default value
950
+ };
951
+ var FakePlasmicComponentContext = {
952
+ _currentValue: false
953
+ // default value
954
+ };
955
+ var FakePlasmicPrepassContext = {
956
+ _currentValue: void 0
957
+ };
958
+ var mkMetaName = (name) => `__plasmic_meta_${name}`;
959
+ function FakeDataCtxReader({ children }) {
960
+ const $ctx = getPrepassContextEnv().readContextValue(FakeDataContext);
961
+ return children($ctx);
962
+ }
963
+ function FakeDataProvider({
964
+ name,
965
+ data,
966
+ hidden,
967
+ advanced,
968
+ label,
969
+ children
970
+ }) {
971
+ var _a2;
972
+ const { readContextValue, setContextValue } = getPrepassContextEnv();
973
+ const existingEnv = (_a2 = readContextValue(FakeDataContext)) != null ? _a2 : {};
974
+ if (!name) {
975
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
976
+ } else {
977
+ setContextValue(FakeDataContext, __spreadProps(__spreadValues({}, existingEnv), {
978
+ [name]: data,
979
+ [mkMetaName(name)]: { hidden, advanced, label }
980
+ }));
981
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
982
+ }
983
+ }
984
+ var fakeApplySelector = (rawData, selector) => {
985
+ if (!selector) {
986
+ return void 0;
987
+ }
988
+ let curData = rawData;
989
+ for (const key of selector.split(".")) {
990
+ curData = curData == null ? void 0 : curData[key];
991
+ }
992
+ return curData;
993
+ };
994
+ function fakeUseSelector(selector) {
995
+ const rawData = getPrepassContextEnv().readContextValue(FakeDataContext);
996
+ return fakeApplySelector(rawData, selector);
997
+ }
998
+ function fakeUseSelectors(selectors = {}) {
999
+ const rawData = getPrepassContextEnv().readContextValue(FakeDataContext);
1000
+ return Object.fromEntries(
1001
+ Object.entries(selectors).filter(([key, selector]) => !!key && !!selector).map(([key, selector]) => [
1002
+ key,
1003
+ fakeApplySelector(rawData, selector)
1004
+ ])
1005
+ );
1006
+ }
1007
+ function fakeUsePlasmicDataConfig() {
1008
+ const cache = getPrepassContextEnv().readContextValue(
1009
+ FakePlasmicPrepassContext
1010
+ );
1011
+ return { cache };
1012
+ }
1013
+ var fakeUseMutablePlasmicQueryData = (unserializedKey, fetcher) => {
1014
+ const [key, args] = swrSerialize(unserializedKey);
1015
+ if (!key) {
1016
+ return {
1017
+ isValidating: false,
1018
+ mutate: () => __async(void 0, null, function* () {
1019
+ }),
1020
+ data: void 0
1021
+ };
1022
+ }
1023
+ const cache = fakeUsePlasmicDataConfig().cache;
1024
+ if (cache.has(key)) {
1025
+ return {
1026
+ isValidating: false,
1027
+ mutate: () => __async(void 0, null, function* () {
1028
+ }),
1029
+ data: cache.get(key)
1030
+ };
1031
+ }
1032
+ const response = fetcher(...args);
1033
+ if (response && typeof response.then == "function") {
1034
+ throw response.then((data) => cache.set(key, data));
1035
+ } else {
1036
+ cache.set(key, response);
1037
+ return {
1038
+ isValidating: false,
1039
+ mutate: () => __async(void 0, null, function* () {
1040
+ }),
1041
+ data: cache.get(key)
1042
+ };
1043
+ }
1044
+ };
1045
+ var _a;
1046
+ var FakeReactComponent = (_a = class {
1047
+ constructor() {
1048
+ this.context = void 0;
1049
+ this.props = {};
1050
+ this.setState = (v) => void (this.state = v);
1051
+ this.forceUpdate = noop;
1052
+ this.render = () => null;
1053
+ this.state = {};
1054
+ this.refs = {};
1055
+ }
1056
+ initRender(props) {
1057
+ this.props = props;
1058
+ const dispatcher = import_react.default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
1059
+ const [state, setState] = dispatcher.useState({});
1060
+ this.state = state;
1061
+ this.setState = setState;
1062
+ if (this.constructor.contextType) {
1063
+ this.context = dispatcher.useContext(
1064
+ this.constructor.contextType
1065
+ );
1066
+ }
1067
+ }
1068
+ }, _a.contextType = void 0, _a);
1069
+ var fakeCreateElement = (originalCreateElement) => (type, ...args) => {
1070
+ if (Object.prototype.isPrototypeOf.call(FakeReactComponent, type)) {
1071
+ return originalCreateElement((props) => {
1072
+ const instance = new type();
1073
+ instance.initRender(props);
1074
+ return instance.render();
1075
+ }, ...args);
1076
+ }
1077
+ return originalCreateElement(type, ...args);
1078
+ };
1079
+ var InternalPrepassPlasmicLoader = class extends BaseInternalPlasmicComponentLoader {
1080
+ constructor(opts) {
1081
+ super({
1082
+ opts,
1083
+ tracker: new import_loader_core3.PlasmicTracker({
1084
+ projectIds: opts.projects.map((p) => p.id),
1085
+ platform: opts.platform,
1086
+ preview: opts.preview,
1087
+ nativeFetch: opts.nativeFetch
1088
+ }),
1089
+ onBundleMerged: () => {
1090
+ this.refreshRegistry();
1091
+ },
1092
+ fetcher: new import_loader_core3.PlasmicModulesFetcher(opts),
1093
+ builtinModules: {
1094
+ react: __spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues({}, import_react.default), { isRSC: true }), {
1095
+ createContext: (defaultValue) => {
1096
+ const context = {
1097
+ _currentValue: defaultValue,
1098
+ displayName: "FakeContext",
1099
+ Provider: ({ value, children }) => {
1100
+ getPrepassContextEnv().setContextValue(context, value);
1101
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
1102
+ },
1103
+ Consumer: ({ children }) => children(getPrepassContextEnv().readContextValue(context))
1104
+ };
1105
+ return context;
1106
+ }
1107
+ }), Object.fromEntries(
1108
+ [
1109
+ "useCallback",
1110
+ "useContext",
1111
+ "useEffect",
1112
+ "useImperativeHandle",
1113
+ "useDebugValue",
1114
+ "useInsertionEffect",
1115
+ "useLayoutEffect",
1116
+ "useMemo",
1117
+ "useSyncExternalStore",
1118
+ "useReducer",
1119
+ "useRef",
1120
+ "useState"
1121
+ ].map((hook) => [
1122
+ hook,
1123
+ (...args) => {
1124
+ const dispatcher = import_react.default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
1125
+ return dispatcher[hook](...args);
1126
+ }
1127
+ ])
1128
+ )), {
1129
+ useDeferredValue: (v) => v,
1130
+ useTransition: () => [
1131
+ false,
1132
+ (f) => {
1133
+ f();
1134
+ }
1135
+ ],
1136
+ createFactory: (type) => import_react.default.createElement.bind(null, type),
1137
+ Component: FakeReactComponent,
1138
+ PureComponent: FakeReactComponent,
1139
+ createElement: fakeCreateElement(import_react.default.createElement)
1140
+ }),
1141
+ "react-dom": import_react_dom.default,
1142
+ "react/jsx-runtime": __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, jsxRuntime), jsxRuntime.jsx ? { jsx: fakeCreateElement(jsxRuntime.jsx) } : {}), jsxRuntime.jsxs ? { jsxs: fakeCreateElement(jsxRuntime.jsxs) } : {}), jsxRuntime.jsxDEV ? { jsxDEV: fakeCreateElement(jsxRuntime.jsxDEV) } : {}),
1143
+ "react/jsx-dev-runtime": __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, jsxDevRuntime), jsxDevRuntime.jsx ? { jsx: fakeCreateElement(jsxDevRuntime.jsx) } : {}), jsxDevRuntime.jsxs ? { jsxs: fakeCreateElement(jsxDevRuntime.jsxs) } : {}), jsxDevRuntime.jsxDEV ? { jsxDEV: fakeCreateElement(jsxDevRuntime.jsxDEV) } : {}),
1144
+ "@plasmicapp/query": {
1145
+ addLoadingStateListener: () => noop,
1146
+ isPlasmicPrepass: () => true,
1147
+ PlasmicPrepassContext: {},
1148
+ PlasmicQueryDataProvider: ({ children }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children),
1149
+ useMutablePlasmicQueryData: fakeUseMutablePlasmicQueryData,
1150
+ usePlasmicDataConfig: fakeUsePlasmicDataConfig,
1151
+ usePlasmicQueryData: fakeUseMutablePlasmicQueryData,
1152
+ useSWRConfig: unreachable,
1153
+ wrapLoadingFetcher: identity
1154
+ },
1155
+ "@plasmicapp/data-sources-context": (() => {
1156
+ const FakePlasmicDataSourceContext = {
1157
+ _currentValue: void 0
1158
+ // default value
1159
+ };
1160
+ return {
1161
+ PlasmicDataSourceContextProvider: Object.assign(
1162
+ ({ children, value }) => {
1163
+ const { setContextValue } = getPrepassContextEnv();
1164
+ setContextValue(FakePlasmicDataSourceContext, value);
1165
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
1166
+ },
1167
+ {
1168
+ $$typeof: REACT_PROVIDER_TYPE,
1169
+ _context: FakePlasmicDataSourceContext
1170
+ }
1171
+ ),
1172
+ useCurrentUser: () => {
1173
+ var _a2;
1174
+ const { readContextValue } = getPrepassContextEnv();
1175
+ const ctx = readContextValue(FakePlasmicDataSourceContext);
1176
+ return (_a2 = ctx == null ? void 0 : ctx.user) != null ? _a2 : {
1177
+ isLoggedIn: false
1178
+ };
1179
+ },
1180
+ usePlasmicDataSourceContext: () => {
1181
+ const { readContextValue } = getPrepassContextEnv();
1182
+ return readContextValue(FakePlasmicDataSourceContext);
1183
+ }
1184
+ };
1185
+ })(),
1186
+ "@plasmicapp/host": (() => {
1187
+ return {
1188
+ applySelector: fakeApplySelector,
1189
+ DataContext: FakeDataContext,
1190
+ DataCtxReader: FakeDataCtxReader,
1191
+ DataProvider: FakeDataProvider,
1192
+ GlobalActionsContext: {
1193
+ _currentValue: void 0
1194
+ // default value
1195
+ },
1196
+ GlobalActionsProvider: ({ children }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children),
1197
+ mkMetaName,
1198
+ mkMetaValue: identity,
1199
+ PageParamsProvider: ({ children }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children),
1200
+ PlasmicCanvasContext: { _currentValue: false },
1201
+ PlasmicCanvasHost: () => null,
1202
+ PlasmicLinkProvider: ({ children }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children),
1203
+ registerComponent: noop,
1204
+ registerFunction: noop,
1205
+ registerGlobalContext: noop,
1206
+ registerToken: noop,
1207
+ registerTrait: noop,
1208
+ repeatedElement: unreachable,
1209
+ stateHelpersKeys: ["initFunc", "onChangeArgsToValue", "onMutate"],
1210
+ unstable_registerFetcher: noop,
1211
+ useDataEnv: () => getPrepassContextEnv().readContextValue(FakeDataContext),
1212
+ useGlobalActions: () => new Proxy(
1213
+ {},
1214
+ {
1215
+ get: () => noop
1216
+ }
1217
+ ),
1218
+ usePlasmicCanvasContext: () => false,
1219
+ usePlasmicLink: () => (props) => /* @__PURE__ */ import_react.default.createElement("a", __spreadValues({}, props)),
1220
+ usePlasmicLinkMaybe: () => void 0,
1221
+ useSelector: fakeUseSelector,
1222
+ useSelectors: fakeUseSelectors
1223
+ };
1224
+ })(),
1225
+ "@plasmicapp/loader-runtime-registry": {
1226
+ components: SUBSTITUTED_COMPONENTS,
1227
+ globalVariantHooks: SUBSTITUTED_GLOBAL_VARIANT_HOOKS,
1228
+ codeComponentHelpers: REGISTERED_CODE_COMPONENT_HELPERS,
1229
+ functions: REGISTERED_CUSTOM_FUNCTIONS
1230
+ }
1231
+ }
1232
+ });
1233
+ this.registerTrait = noop;
1234
+ this.registerToken = noop;
1235
+ }
1236
+ registerComponent(component, meta) {
1237
+ var _a2;
1238
+ const stateHelpers = Object.fromEntries(
1239
+ Object.entries((_a2 = meta.states) != null ? _a2 : {}).filter(
1240
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1241
+ ([_, stateSpec]) => (
1242
+ // `initFunc` is the only helper function used in RSC phase
1243
+ "initFunc" in stateSpec
1244
+ )
1245
+ ).map(([stateName, stateSpec]) => [
1246
+ stateName,
1247
+ { initFunc: stateSpec.initFunc }
1248
+ ])
1249
+ );
1250
+ const helpers = { states: stateHelpers };
1251
+ this.internalSubstituteComponent(
1252
+ meta.getServerInfo ? (props) => {
1253
+ var _a3;
1254
+ const { readContextValue } = getPrepassContextEnv();
1255
+ const serverInfo = (_a3 = meta.getServerInfo) == null ? void 0 : _a3.call(meta, props, {
1256
+ readContext: readContextValue,
1257
+ readDataEnv: () => readContextValue(FakeDataContext),
1258
+ readDataSelector: fakeUseSelector,
1259
+ readDataSelectors: fakeUseSelectors,
1260
+ fetchData: fakeUseMutablePlasmicQueryData
1261
+ });
1262
+ if (serverInfo && serverInfo.children) {
1263
+ const contents = [];
1264
+ const children = Array.isArray(serverInfo.children) ? serverInfo.children : [serverInfo.children];
1265
+ children.forEach((childData) => {
1266
+ contents.push(
1267
+ /* @__PURE__ */ import_react.default.createElement(ContextAndDataProviderWrapper, { contextAndData: childData }, childData.node)
1268
+ );
1269
+ });
1270
+ return /* @__PURE__ */ import_react.default.createElement(ContextAndDataProviderWrapper, { contextAndData: serverInfo }, contents);
1271
+ } else {
1272
+ return /* @__PURE__ */ import_react.default.createElement(
1273
+ ContextAndDataProviderWrapper,
1274
+ {
1275
+ contextAndData: serverInfo != null ? serverInfo : {}
1276
+ },
1277
+ Object.values(props).flat(Infinity).filter(
1278
+ (v) => v && typeof v == "object" && v.$$typeof && import_react.default.isValidElement(v)
1279
+ )
1280
+ );
1281
+ }
1282
+ } : component,
1283
+ { name: meta.name, isCode: true },
1284
+ Object.keys(stateHelpers).length > 0 ? helpers : void 0
1285
+ );
1286
+ }
1287
+ registerFunction(fn, meta) {
1288
+ REGISTERED_CUSTOM_FUNCTIONS[customFunctionImportAlias(meta)] = fn;
1289
+ }
1290
+ registerGlobalContext(context, meta) {
1291
+ this.substituteComponent(context, { name: meta.name, isCode: true });
1292
+ }
1293
+ refreshRegistry() {
1294
+ for (const globalGroup of this.getBundle().globalGroups) {
1295
+ if (globalGroup.type !== "global-screen") {
1296
+ SUBSTITUTED_GLOBAL_VARIANT_HOOKS[globalGroup.id] = () => {
1297
+ var _a2;
1298
+ const rootContext = getPrepassContextEnv().readContextValue(
1299
+ FakeRootProviderContext
1300
+ );
1301
+ const loader = this;
1302
+ const { name, projectId } = globalGroup;
1303
+ const spec = [
1304
+ ...loader.getGlobalVariants(),
1305
+ ...(_a2 = rootContext.globalVariants) != null ? _a2 : []
1306
+ ].find(
1307
+ (s) => s.name === name && (!s.projectId || s.projectId === projectId)
1308
+ );
1309
+ return spec ? spec.value : void 0;
1310
+ };
1311
+ }
1312
+ }
1313
+ super.refreshRegistry();
1314
+ }
1315
+ };
1316
+ function handlePrepassPlasmicRootComponent(props) {
1317
+ var _a2;
1318
+ const {
1319
+ globalVariants,
1320
+ globalContextsProps,
1321
+ variation,
1322
+ translator,
1323
+ Head,
1324
+ Link,
1325
+ pageRoute,
1326
+ pageParams,
1327
+ pageQuery,
1328
+ suspenseFallback,
1329
+ disableLoadingBoundary,
1330
+ user,
1331
+ userAuthToken,
1332
+ isUserLoading,
1333
+ authRedirectUri
1334
+ } = props;
1335
+ const loader = props.loader.__internal;
1336
+ const splits = loader.getActiveSplits();
1337
+ const value = {
1338
+ globalVariants: mergeGlobalVariantsSpec(
1339
+ globalVariants != null ? globalVariants : [],
1340
+ getGlobalVariantsFromSplits(splits, variation != null ? variation : {})
1341
+ ),
1342
+ globalContextsProps,
1343
+ loader,
1344
+ variation,
1345
+ translator,
1346
+ Head,
1347
+ Link,
1348
+ user,
1349
+ userAuthToken,
1350
+ isUserLoading,
1351
+ authRedirectUri,
1352
+ suspenseFallback,
1353
+ disableLoadingBoundary
1354
+ };
1355
+ const { setContextValue, readContextValue } = getPrepassContextEnv();
1356
+ setContextValue(FakeRootProviderContext, value);
1357
+ const existingEnv = (_a2 = readContextValue(FakeDataContext)) != null ? _a2 : {};
1358
+ const fixCatchallParams = (params) => {
1359
+ const newParams = {};
1360
+ for (const [key, val] of Object.entries(params)) {
1361
+ if (!val) {
1362
+ continue;
1363
+ }
1364
+ if (key.startsWith("...")) {
1365
+ newParams[key.slice(3)] = typeof val === "string" ? val.replace(/^\/|\/$/g, "").split("/") : val;
1366
+ } else {
1367
+ newParams[key] = val;
1368
+ }
1369
+ }
1370
+ return newParams;
1371
+ };
1372
+ const mkPathFromRouteAndParams = (route, params) => {
1373
+ if (!params) {
1374
+ return route;
1375
+ }
1376
+ let path = route;
1377
+ for (const [key, val] of Object.entries(params)) {
1378
+ if (typeof val === "string") {
1379
+ path = path.replace(`[${key}]`, val);
1380
+ } else if (Array.isArray(val)) {
1381
+ if (path.includes(`[[...${key}]]`)) {
1382
+ path = path.replace(`[[...${key}]]`, val.join("/"));
1383
+ } else if (path.includes(`[...${key}]`)) {
1384
+ path = path.replace(`[...${key}]`, val.join("/"));
1385
+ }
1386
+ }
1387
+ }
1388
+ return path;
1389
+ };
1390
+ const fixedParams = fixCatchallParams(pageParams != null ? pageParams : {});
1391
+ setContextValue(FakeDataContext, __spreadProps(__spreadValues({}, existingEnv), {
1392
+ ["pageRoute"]: pageRoute,
1393
+ [mkMetaName("pageRoute")]: { advanced: true, label: "Page route" },
1394
+ ["pagePath"]: pageRoute ? mkPathFromRouteAndParams(pageRoute, fixedParams) : void 0,
1395
+ [mkMetaName("pagePath")]: { label: "Page path" },
1396
+ ["params"]: __spreadValues(__spreadValues({}, existingEnv.params), fixedParams),
1397
+ [mkMetaName("params")]: { label: "Page URL path params" },
1398
+ ["query"]: __spreadValues(__spreadValues({}, existingEnv.query), pageQuery),
1399
+ [mkMetaName("query")]: { label: "Page URL query params" }
1400
+ }));
1401
+ }
1402
+ function handlePrepassPlasmicComponent(props) {
1403
+ var _b;
1404
+ const { component, projectId, componentProps, forceOriginal } = props;
1405
+ const { setContextValue, readContextValue } = getPrepassContextEnv();
1406
+ const rootContext = readContextValue(
1407
+ FakeRootProviderContext
1408
+ );
1409
+ const isRootLoader = !readContextValue(FakePlasmicComponentContext);
1410
+ if (!rootContext) {
1411
+ throw new Error(
1412
+ `You must use <PlasmicRootProvider/> at the root of your app`
1413
+ );
1414
+ }
1415
+ const _a2 = rootContext, {
1416
+ loader,
1417
+ globalContextsProps,
1418
+ userAuthToken,
1419
+ isUserLoading,
1420
+ authRedirectUri,
1421
+ translator
1422
+ } = _a2, rest = __objRest(_a2, [
1423
+ "loader",
1424
+ "globalContextsProps",
1425
+ "userAuthToken",
1426
+ "isUserLoading",
1427
+ "authRedirectUri",
1428
+ "translator"
1429
+ ]);
1430
+ const spec = { name: component, projectId, isCode: false };
1431
+ const opts = { forceOriginal };
1432
+ const lookup = loader.getLookup();
1433
+ if (!lookup.hasComponent(spec)) {
1434
+ return null;
1435
+ }
1436
+ const Component = lookup.getComponent(spec, opts);
1437
+ let element = /* @__PURE__ */ import_react.default.createElement(Component, __spreadValues({}, componentProps));
1438
+ if (isRootLoader) {
1439
+ const ReactWebRootProvider = lookup.getRootProvider();
1440
+ const GlobalContextsProvider = lookup.getGlobalContextsProvider({
1441
+ name: component,
1442
+ projectId
1443
+ });
1444
+ setContextValue(FakePlasmicComponentContext, true);
1445
+ element = /* @__PURE__ */ import_react.default.createElement(
1446
+ ReactWebRootProvider,
1447
+ __spreadProps(__spreadValues({}, rest), {
1448
+ userAuthToken,
1449
+ isUserLoading,
1450
+ authRedirectUri,
1451
+ i18n: {
1452
+ translator,
1453
+ tagPrefix: (_b = loader.opts.i18n) == null ? void 0 : _b.tagPrefix
1454
+ }
1455
+ }),
1456
+ element
1457
+ );
1458
+ if (GlobalContextsProvider) {
1459
+ element = /* @__PURE__ */ import_react.default.createElement(GlobalContextsProvider, __spreadValues({}, globalContextsProps), element);
1460
+ }
1461
+ }
1462
+ return element;
1463
+ }
1464
+ function handlePlasmicPrepassContext({
1465
+ cache
1466
+ }) {
1467
+ getPrepassContextEnv().setContextValue(FakePlasmicPrepassContext, cache);
1468
+ }
1469
+ function getPrepassContextEnv() {
1470
+ return globalThis.__ssrPrepassEnv;
1471
+ }
1472
+ function ContextAndDataProviderWrapper({
1473
+ children,
1474
+ contextAndData
1475
+ }) {
1476
+ var _a2;
1477
+ const { setContextValue, readContextValue } = getPrepassContextEnv();
1478
+ const contexts = contextAndData.providedContexts ? Array.isArray(contextAndData.providedContexts) ? contextAndData.providedContexts : [contextAndData.providedContexts] : [];
1479
+ const providedData = contextAndData.providedData ? Array.isArray(contextAndData.providedData) ? contextAndData.providedData : [contextAndData.providedData] : [];
1480
+ contexts.forEach((context) => {
1481
+ setContextValue(context.contextKey, context.value);
1482
+ });
1483
+ let $ctx = (_a2 = readContextValue(FakeDataContext)) != null ? _a2 : {};
1484
+ providedData.forEach(({ name, data }) => {
1485
+ $ctx = __spreadProps(__spreadValues({}, $ctx), {
1486
+ [name]: data
1487
+ });
1488
+ });
1489
+ setContextValue(FakeDataContext, $ctx);
1490
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
1491
+ }
1492
+
1493
+ // src/prepass-server.ts
1494
+ var import_prepass = require("@plasmicapp/prepass");
1495
+ function extractPlasmicQueryData(element, loader) {
1496
+ return __async(this, null, function* () {
1497
+ return yield (0, import_prepass.extractPlasmicQueryData)(
1498
+ element,
1499
+ (elt) => handleClientComponentRef(elt, loader, element)
1500
+ );
1501
+ });
1502
+ }
1503
+ function handleClientComponentRef(elt, loader, rootElement) {
1504
+ var _a2, _b;
1505
+ try {
1506
+ const refId = elt.type.$$id;
1507
+ if (refId.includes("PlasmicRootProvider") || elt === rootElement) {
1508
+ const props = elt.props;
1509
+ if (props.prefetchedData) {
1510
+ handlePrepassPlasmicRootComponent(__spreadProps(__spreadValues({}, props), { loader }));
1511
+ }
1512
+ return;
1513
+ } else if (refId.includes("PlasmicComponent") && ((_a2 = elt.props) == null ? void 0 : _a2.component) != null) {
1514
+ return handlePrepassPlasmicComponent(elt.props);
1515
+ } else if (refId.includes("PlasmicPrepassContext") && ((_b = elt.props) == null ? void 0 : _b.cache) != null) {
1516
+ return handlePlasmicPrepassContext(elt.props);
1517
+ }
1518
+ } catch (err) {
1519
+ console.warn("Error processing client reference: ", err);
1520
+ }
1521
+ return;
468
1522
  }
469
1523
 
470
1524
  // src/react-server.ts
471
1525
  function initPlasmicLoader(opts) {
472
- return new ReactServerPlasmicComponentLoader({
473
- opts,
474
- fetcher: new import_loader_core2.PlasmicModulesFetcher(opts),
475
- tracker: new import_loader_core2.PlasmicTracker({
476
- projectIds: opts.projects.map((p) => p.id),
477
- platform: opts.platform,
478
- preview: opts.preview
479
- })
480
- });
1526
+ const internal = new InternalPrepassPlasmicLoader(opts);
1527
+ return new PlasmicComponentLoader(internal);
481
1528
  }
482
1529
  //# sourceMappingURL=react-server.js.map