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