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