@plasmicapp/loader-react 1.0.302 → 1.0.303
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.esm.js +1400 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js.map +2 -2
- package/dist/loader-react-server.d.ts +5 -0
- package/dist/react-server.esm.js +441 -0
- package/dist/react-server.esm.js.map +7 -0
- package/dist/react-server.js.map +2 -2
- package/package.json +17 -12
|
@@ -0,0 +1,1400 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __async = (__this, __arguments, generator) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var fulfilled = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var rejected = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.throw(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/loader.ts
|
|
55
|
+
import * as PlasmicDataSourcesContext from "@plasmicapp/data-sources-context";
|
|
56
|
+
import * as PlasmicHost from "@plasmicapp/host";
|
|
57
|
+
import {
|
|
58
|
+
registerComponent,
|
|
59
|
+
registerGlobalContext,
|
|
60
|
+
registerToken,
|
|
61
|
+
registerTrait,
|
|
62
|
+
stateHelpersKeys,
|
|
63
|
+
unstable_registerFunction
|
|
64
|
+
} from "@plasmicapp/host";
|
|
65
|
+
import {
|
|
66
|
+
PlasmicModulesFetcher,
|
|
67
|
+
PlasmicTracker,
|
|
68
|
+
Registry
|
|
69
|
+
} from "@plasmicapp/loader-core";
|
|
70
|
+
import { internal_getCachedBundleInNodeServer } from "@plasmicapp/loader-fetcher";
|
|
71
|
+
import { getActiveVariation, getExternalIds } from "@plasmicapp/loader-splits";
|
|
72
|
+
import * as PlasmicQuery from "@plasmicapp/query";
|
|
73
|
+
import React3 from "react";
|
|
74
|
+
import ReactDOM from "react-dom";
|
|
75
|
+
import * as jsxDevRuntime from "react/jsx-dev-runtime";
|
|
76
|
+
import * as jsxRuntime from "react/jsx-runtime";
|
|
77
|
+
|
|
78
|
+
// src/utils.tsx
|
|
79
|
+
import pascalcase from "pascalcase";
|
|
80
|
+
import * as React from "react";
|
|
81
|
+
var isBrowser = typeof window !== "undefined";
|
|
82
|
+
function useForceUpdate() {
|
|
83
|
+
const [, setTick] = React.useState(0);
|
|
84
|
+
const update = React.useCallback(() => {
|
|
85
|
+
setTick((tick) => tick + 1);
|
|
86
|
+
}, []);
|
|
87
|
+
return update;
|
|
88
|
+
}
|
|
89
|
+
function useStableLookupSpec(spec) {
|
|
90
|
+
return useStableLookupSpecs(spec)[0];
|
|
91
|
+
}
|
|
92
|
+
function useStableLookupSpecs(...specs) {
|
|
93
|
+
const [stableSpecs, setStableSpecs] = React.useState(specs);
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
if (specs.length !== stableSpecs.length || specs.some((s, i) => !areLookupSpecsEqual(s, stableSpecs[i]))) {
|
|
96
|
+
setStableSpecs(specs);
|
|
97
|
+
}
|
|
98
|
+
}, [specs, stableSpecs]);
|
|
99
|
+
return stableSpecs;
|
|
100
|
+
}
|
|
101
|
+
function areLookupSpecsEqual(spec1, spec2) {
|
|
102
|
+
if (spec1 === spec2) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (typeof spec1 !== typeof spec2) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const fullSpec1 = toFullLookup(spec1);
|
|
109
|
+
const fullSpec2 = toFullLookup(spec2);
|
|
110
|
+
return (isNameSpec(fullSpec1) && isNameSpec(fullSpec2) && fullSpec1.name === fullSpec2.name && fullSpec1.isCode === fullSpec2.isCode || isPathSpec(fullSpec1) && isPathSpec(fullSpec2) && fullSpec1.path === fullSpec2.path) && fullSpec1.projectId === fullSpec2.projectId;
|
|
111
|
+
}
|
|
112
|
+
function isNameSpec(lookup) {
|
|
113
|
+
return "name" in lookup;
|
|
114
|
+
}
|
|
115
|
+
function isPathSpec(lookup) {
|
|
116
|
+
return "path" in lookup;
|
|
117
|
+
}
|
|
118
|
+
function toFullLookup(lookup) {
|
|
119
|
+
const namePart = typeof lookup === "string" ? lookup : lookup.name;
|
|
120
|
+
const projectId = typeof lookup === "string" ? void 0 : lookup.projectId;
|
|
121
|
+
const codeComponent = typeof lookup === "string" ? void 0 : lookup.isCode;
|
|
122
|
+
if (codeComponent !== true && namePart.startsWith("/")) {
|
|
123
|
+
return { path: normalizePath(namePart), projectId };
|
|
124
|
+
} else {
|
|
125
|
+
return {
|
|
126
|
+
name: codeComponent ? namePart : normalizeName(namePart),
|
|
127
|
+
rawName: namePart.trim(),
|
|
128
|
+
projectId,
|
|
129
|
+
isCode: codeComponent
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function normalizePath(path) {
|
|
134
|
+
return path.trim();
|
|
135
|
+
}
|
|
136
|
+
function normalizeName(name) {
|
|
137
|
+
return pascalcase(name).trim();
|
|
138
|
+
}
|
|
139
|
+
function useIsMounted() {
|
|
140
|
+
const ref = React.useRef(false);
|
|
141
|
+
const isMounted = React.useCallback(() => ref.current, []);
|
|
142
|
+
React.useEffect(() => {
|
|
143
|
+
ref.current = true;
|
|
144
|
+
return () => {
|
|
145
|
+
ref.current = false;
|
|
146
|
+
};
|
|
147
|
+
}, []);
|
|
148
|
+
return isMounted;
|
|
149
|
+
}
|
|
150
|
+
function matchesPagePath(pagePath, lookup) {
|
|
151
|
+
var _a;
|
|
152
|
+
pagePath = pagePath.replace(/^\/*/, "").replace(/\/*$/, "");
|
|
153
|
+
lookup = lookup.replace(/^\/*/, "").replace(/\/*$/, "");
|
|
154
|
+
const paramNames = (pagePath.match(/\[([^\]]*)\]/g) || []).map(
|
|
155
|
+
(group) => group.slice(1, -1)
|
|
156
|
+
);
|
|
157
|
+
const pagePathRegExp = new RegExp(
|
|
158
|
+
"^" + pagePath.replace(/\[[^\]]*\]/g, "([^/]+)") + "$"
|
|
159
|
+
);
|
|
160
|
+
const maybeVals = (_a = lookup.match(pagePathRegExp)) == null ? void 0 : _a.slice(1);
|
|
161
|
+
if (!maybeVals) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const params = {};
|
|
165
|
+
for (let i = 0; i < paramNames.length; i++) {
|
|
166
|
+
params[paramNames[i]] = maybeVals[i];
|
|
167
|
+
}
|
|
168
|
+
return { params };
|
|
169
|
+
}
|
|
170
|
+
function isDynamicPagePath(path) {
|
|
171
|
+
return !!path.match(/\[[^/]*\]/);
|
|
172
|
+
}
|
|
173
|
+
function matchesCompMeta(lookup, meta) {
|
|
174
|
+
if (lookup.projectId && meta.projectId !== lookup.projectId) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return isNameSpec(lookup) ? (lookup.name === meta.name || lookup.rawName === meta.name || lookup.rawName === meta.displayName) && (lookup.isCode == null || lookup.isCode === meta.isCode) : !!(meta.path && matchesPagePath(meta.path, lookup.path));
|
|
178
|
+
}
|
|
179
|
+
function getCompMetas(metas, lookup) {
|
|
180
|
+
const full = toFullLookup(lookup);
|
|
181
|
+
return metas.filter((meta) => matchesCompMeta(full, meta)).map((meta) => {
|
|
182
|
+
if (isNameSpec(full) || !meta.path) {
|
|
183
|
+
return meta;
|
|
184
|
+
}
|
|
185
|
+
const match = matchesPagePath(meta.path, full.path);
|
|
186
|
+
if (!match) {
|
|
187
|
+
return meta;
|
|
188
|
+
}
|
|
189
|
+
return __spreadProps(__spreadValues({}, meta), { params: match.params });
|
|
190
|
+
}).sort(
|
|
191
|
+
(meta1, meta2) => (
|
|
192
|
+
// We sort the matched component metas by the number of path params, so
|
|
193
|
+
// if there are two pages `/products/foo` and `/products/[slug]`,
|
|
194
|
+
// the first one will have higher precedence.
|
|
195
|
+
Array.from(Object.keys(meta1.params || {})).length - Array.from(Object.keys(meta2.params || {})).length
|
|
196
|
+
)
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
function getLookupSpecName(lookup) {
|
|
200
|
+
if (typeof lookup === "string") {
|
|
201
|
+
return lookup;
|
|
202
|
+
} else if (lookup.projectId) {
|
|
203
|
+
return `${lookup.name} (project ${lookup.projectId})`;
|
|
204
|
+
} else {
|
|
205
|
+
return lookup.name;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function uniq(elements) {
|
|
209
|
+
return Array.from(new Set(elements));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/component-lookup.ts
|
|
213
|
+
function getFirstCompMeta(metas, lookup) {
|
|
214
|
+
const filtered = getCompMetas(metas, lookup);
|
|
215
|
+
return filtered.length === 0 ? void 0 : filtered[0];
|
|
216
|
+
}
|
|
217
|
+
var ComponentLookup = class {
|
|
218
|
+
constructor(bundle, registry) {
|
|
219
|
+
this.bundle = bundle;
|
|
220
|
+
this.registry = registry;
|
|
221
|
+
}
|
|
222
|
+
getComponentMeta(spec) {
|
|
223
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
224
|
+
return compMeta;
|
|
225
|
+
}
|
|
226
|
+
getComponent(spec, opts = {}) {
|
|
227
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
228
|
+
if (!compMeta) {
|
|
229
|
+
throw new Error(`Component not found: ${spec}`);
|
|
230
|
+
}
|
|
231
|
+
const moduleName = compMeta.entry;
|
|
232
|
+
if (!this.registry.hasModule(moduleName, opts)) {
|
|
233
|
+
throw new Error(`Component not yet fetched: ${compMeta.name}`);
|
|
234
|
+
}
|
|
235
|
+
const entry = this.registry.load(moduleName, {
|
|
236
|
+
forceOriginal: opts.forceOriginal
|
|
237
|
+
});
|
|
238
|
+
return !opts.forceOriginal && typeof (entry == null ? void 0 : entry.getPlasmicComponent) === "function" ? entry.getPlasmicComponent() : entry.default;
|
|
239
|
+
}
|
|
240
|
+
hasComponent(spec) {
|
|
241
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
242
|
+
if (compMeta) {
|
|
243
|
+
return this.registry.hasModule(compMeta.entry);
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
getGlobalContexts() {
|
|
248
|
+
const customGlobalMetas = this.bundle.globalGroups.filter(
|
|
249
|
+
(m) => m.type === "global-user-defined"
|
|
250
|
+
);
|
|
251
|
+
return customGlobalMetas.map((meta) => ({
|
|
252
|
+
meta,
|
|
253
|
+
context: this.registry.load(meta.contextFile).default
|
|
254
|
+
}));
|
|
255
|
+
}
|
|
256
|
+
getGlobalContextsProvider(spec) {
|
|
257
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
258
|
+
const projectMeta = compMeta ? this.bundle.projects.find((x) => x.id === compMeta.projectId) : void 0;
|
|
259
|
+
if (!projectMeta || !projectMeta.globalContextsProviderFileName || !this.registry.hasModule(projectMeta.globalContextsProviderFileName)) {
|
|
260
|
+
return void 0;
|
|
261
|
+
}
|
|
262
|
+
const entry = this.registry.load(
|
|
263
|
+
projectMeta.globalContextsProviderFileName
|
|
264
|
+
);
|
|
265
|
+
return typeof (entry == null ? void 0 : entry.getPlasmicComponent) === "function" ? entry.getPlasmicComponent() : entry.default;
|
|
266
|
+
}
|
|
267
|
+
getRootProvider() {
|
|
268
|
+
const entry = this.registry.load("root-provider.js");
|
|
269
|
+
return entry.default;
|
|
270
|
+
}
|
|
271
|
+
getCss() {
|
|
272
|
+
return this.bundle.modules.browser.filter(
|
|
273
|
+
(mod) => mod.type === "asset" && mod.fileName.endsWith("css")
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
getRemoteFonts() {
|
|
277
|
+
return this.bundle.projects.flatMap((p) => p.remoteFonts);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// src/PlasmicRootProvider.tsx
|
|
282
|
+
import { PageParamsProvider } from "@plasmicapp/host";
|
|
283
|
+
import { PlasmicQueryDataProvider } from "@plasmicapp/query";
|
|
284
|
+
import * as React2 from "react";
|
|
285
|
+
|
|
286
|
+
// src/variation.ts
|
|
287
|
+
function getPlasmicCookieValues() {
|
|
288
|
+
return Object.fromEntries(
|
|
289
|
+
document.cookie.split("; ").filter((cookie) => cookie.includes("plasmic:")).map((cookie) => cookie.split("=")).map(([key, value]) => [key.split(":")[1], value])
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
function updatePlasmicCookieValue(key, value) {
|
|
293
|
+
document.cookie = `plasmic:${key}=${value}`;
|
|
294
|
+
}
|
|
295
|
+
function ensureVariationCookies(variation = {}) {
|
|
296
|
+
Object.keys(variation).map((variationKey) => {
|
|
297
|
+
const sliceId = variation[variationKey];
|
|
298
|
+
updatePlasmicCookieValue(variationKey, sliceId);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
var getGlobalVariantsFromSplits = (splits, variation) => {
|
|
302
|
+
const globalVariants = [];
|
|
303
|
+
Object.keys(variation).map((variationKey) => {
|
|
304
|
+
const [_type, splitId] = variationKey.split(".");
|
|
305
|
+
const sliceId = variation[variationKey];
|
|
306
|
+
const split = splits.find(
|
|
307
|
+
(s) => s.id === splitId || s.externalId === splitId
|
|
308
|
+
);
|
|
309
|
+
if (split) {
|
|
310
|
+
const slice = split.slices.find((s) => s.id === sliceId || s.externalId === sliceId);
|
|
311
|
+
if (slice) {
|
|
312
|
+
slice.contents.map((x) => {
|
|
313
|
+
globalVariants.push({
|
|
314
|
+
name: x.group,
|
|
315
|
+
value: x.variant,
|
|
316
|
+
projectId: x.projectId
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
return globalVariants;
|
|
323
|
+
};
|
|
324
|
+
var mergeGlobalVariantsSpec = (target, from) => {
|
|
325
|
+
let result = [...target];
|
|
326
|
+
const existingGlobalVariants = new Set(
|
|
327
|
+
target.map((t) => {
|
|
328
|
+
var _a;
|
|
329
|
+
return `${t.name}-${(_a = t.projectId) != null ? _a : ""}`;
|
|
330
|
+
})
|
|
331
|
+
);
|
|
332
|
+
const newGlobals = from.filter(
|
|
333
|
+
(t) => {
|
|
334
|
+
var _a;
|
|
335
|
+
return !existingGlobalVariants.has(`${t.name}-${(_a = t.projectId) != null ? _a : ""}`);
|
|
336
|
+
}
|
|
337
|
+
);
|
|
338
|
+
if (newGlobals.length > 0) {
|
|
339
|
+
result = [...result, ...newGlobals];
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// src/PlasmicRootProvider.tsx
|
|
345
|
+
var PlasmicRootContext = React2.createContext(void 0);
|
|
346
|
+
function PlasmicRootProvider(props) {
|
|
347
|
+
const {
|
|
348
|
+
globalVariants,
|
|
349
|
+
prefetchedData,
|
|
350
|
+
children,
|
|
351
|
+
skipCss,
|
|
352
|
+
skipFonts,
|
|
353
|
+
prefetchedQueryData,
|
|
354
|
+
suspenseForQueryData,
|
|
355
|
+
globalContextsProps,
|
|
356
|
+
variation,
|
|
357
|
+
translator,
|
|
358
|
+
Head,
|
|
359
|
+
Link,
|
|
360
|
+
pageParams,
|
|
361
|
+
pageQuery,
|
|
362
|
+
suspenseFallback,
|
|
363
|
+
disableLoadingBoundary
|
|
364
|
+
} = props;
|
|
365
|
+
const loader = props.loader.__internal;
|
|
366
|
+
if (prefetchedData) {
|
|
367
|
+
loader.registerPrefetchedBundle(prefetchedData == null ? void 0 : prefetchedData.bundle);
|
|
368
|
+
}
|
|
369
|
+
const [splits, setSplits] = React2.useState(loader.getActiveSplits());
|
|
370
|
+
const forceUpdate = useForceUpdate();
|
|
371
|
+
const watcher = React2.useMemo(
|
|
372
|
+
() => ({
|
|
373
|
+
onDataFetched: () => {
|
|
374
|
+
setSplits(loader.getActiveSplits());
|
|
375
|
+
forceUpdate();
|
|
376
|
+
}
|
|
377
|
+
}),
|
|
378
|
+
[loader, forceUpdate]
|
|
379
|
+
);
|
|
380
|
+
React2.useEffect(() => {
|
|
381
|
+
loader.subscribePlasmicRoot(watcher);
|
|
382
|
+
return () => loader.unsubscribePlasmicRoot(watcher);
|
|
383
|
+
}, [watcher, loader]);
|
|
384
|
+
React2.useEffect(() => {
|
|
385
|
+
ensureVariationCookies(variation);
|
|
386
|
+
loader.trackRender({
|
|
387
|
+
renderCtx: {
|
|
388
|
+
// We track the provider as a single entity
|
|
389
|
+
rootComponentId: "provider",
|
|
390
|
+
teamIds: loader.getTeamIds(),
|
|
391
|
+
projectIds: loader.getProjectIds()
|
|
392
|
+
},
|
|
393
|
+
variation
|
|
394
|
+
});
|
|
395
|
+
}, [loader, variation]);
|
|
396
|
+
const { user, userAuthToken, isUserLoading, authRedirectUri } = props;
|
|
397
|
+
const value = React2.useMemo(
|
|
398
|
+
() => ({
|
|
399
|
+
globalVariants: mergeGlobalVariantsSpec(
|
|
400
|
+
globalVariants != null ? globalVariants : [],
|
|
401
|
+
getGlobalVariantsFromSplits(splits, variation != null ? variation : {})
|
|
402
|
+
),
|
|
403
|
+
globalContextsProps,
|
|
404
|
+
loader,
|
|
405
|
+
variation,
|
|
406
|
+
translator,
|
|
407
|
+
Head,
|
|
408
|
+
Link,
|
|
409
|
+
user,
|
|
410
|
+
userAuthToken,
|
|
411
|
+
isUserLoading,
|
|
412
|
+
authRedirectUri,
|
|
413
|
+
suspenseFallback,
|
|
414
|
+
disableLoadingBoundary
|
|
415
|
+
}),
|
|
416
|
+
[
|
|
417
|
+
globalVariants,
|
|
418
|
+
variation,
|
|
419
|
+
globalContextsProps,
|
|
420
|
+
loader,
|
|
421
|
+
splits,
|
|
422
|
+
translator,
|
|
423
|
+
Head,
|
|
424
|
+
Link,
|
|
425
|
+
user,
|
|
426
|
+
userAuthToken,
|
|
427
|
+
isUserLoading,
|
|
428
|
+
authRedirectUri,
|
|
429
|
+
suspenseFallback,
|
|
430
|
+
disableLoadingBoundary
|
|
431
|
+
]
|
|
432
|
+
);
|
|
433
|
+
return /* @__PURE__ */ React2.createElement(
|
|
434
|
+
PlasmicQueryDataProvider,
|
|
435
|
+
{
|
|
436
|
+
prefetchedCache: prefetchedQueryData,
|
|
437
|
+
suspense: suspenseForQueryData
|
|
438
|
+
},
|
|
439
|
+
/* @__PURE__ */ React2.createElement(PlasmicRootContext.Provider, { value }, !skipCss && /* @__PURE__ */ React2.createElement(
|
|
440
|
+
PlasmicCss,
|
|
441
|
+
{
|
|
442
|
+
loader,
|
|
443
|
+
prefetchedData,
|
|
444
|
+
skipFonts
|
|
445
|
+
}
|
|
446
|
+
), /* @__PURE__ */ React2.createElement(PageParamsProvider, { params: pageParams, query: pageQuery }, children))
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
var PlasmicCss = React2.memo(function PlasmicCss2(props) {
|
|
450
|
+
const { loader, prefetchedData, skipFonts } = props;
|
|
451
|
+
const [useScopedCss, setUseScopedCss] = React2.useState(!!prefetchedData);
|
|
452
|
+
const builtCss = buildCss(loader, {
|
|
453
|
+
scopedCompMetas: useScopedCss && prefetchedData ? prefetchedData.bundle.components : void 0,
|
|
454
|
+
skipFonts
|
|
455
|
+
});
|
|
456
|
+
const forceUpdate = useForceUpdate();
|
|
457
|
+
const watcher = React2.useMemo(
|
|
458
|
+
() => ({
|
|
459
|
+
onDataFetched: () => {
|
|
460
|
+
setUseScopedCss(false);
|
|
461
|
+
forceUpdate();
|
|
462
|
+
}
|
|
463
|
+
}),
|
|
464
|
+
[loader, forceUpdate]
|
|
465
|
+
);
|
|
466
|
+
React2.useEffect(() => {
|
|
467
|
+
loader.subscribePlasmicRoot(watcher);
|
|
468
|
+
return () => loader.unsubscribePlasmicRoot(watcher);
|
|
469
|
+
}, [watcher, loader]);
|
|
470
|
+
return /* @__PURE__ */ React2.createElement("style", { dangerouslySetInnerHTML: { __html: builtCss } });
|
|
471
|
+
});
|
|
472
|
+
function buildCss(loader, opts) {
|
|
473
|
+
const { scopedCompMetas, skipFonts } = opts;
|
|
474
|
+
const cssFiles = scopedCompMetas && /* @__PURE__ */ new Set([
|
|
475
|
+
"entrypoint.css",
|
|
476
|
+
...scopedCompMetas.map((c) => c.cssFile)
|
|
477
|
+
]);
|
|
478
|
+
const cssModules = loader.getLookup().getCss().filter((f) => !cssFiles || cssFiles.has(f.fileName));
|
|
479
|
+
const getPri = (fileName) => fileName === "entrypoint.css" ? 0 : 1;
|
|
480
|
+
const compareModules = (a, b) => getPri(a.fileName) !== getPri(b.fileName) ? getPri(a.fileName) - getPri(b.fileName) : a.fileName.localeCompare(b.fileName);
|
|
481
|
+
cssModules.sort(compareModules);
|
|
482
|
+
const remoteFonts = loader.getLookup().getRemoteFonts();
|
|
483
|
+
return `
|
|
484
|
+
${skipFonts ? "" : remoteFonts.map((f) => `@import url('${f.url}');`).join("\n")}
|
|
485
|
+
${cssModules.map((mod) => mod.source).join("\n")}
|
|
486
|
+
`;
|
|
487
|
+
}
|
|
488
|
+
function usePlasmicRootContext() {
|
|
489
|
+
return React2.useContext(PlasmicRootContext);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// src/global-variants.ts
|
|
493
|
+
function createUseGlobalVariant(name, projectId) {
|
|
494
|
+
return () => {
|
|
495
|
+
var _a;
|
|
496
|
+
const rootContext = usePlasmicRootContext();
|
|
497
|
+
if (!rootContext) {
|
|
498
|
+
return void 0;
|
|
499
|
+
}
|
|
500
|
+
const loader = rootContext.loader;
|
|
501
|
+
const spec = [
|
|
502
|
+
...loader.getGlobalVariants(),
|
|
503
|
+
...(_a = rootContext.globalVariants) != null ? _a : []
|
|
504
|
+
].find(
|
|
505
|
+
(spec2) => spec2.name === name && (!spec2.projectId || spec2.projectId === projectId)
|
|
506
|
+
);
|
|
507
|
+
return spec ? spec.value : void 0;
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/bundles.ts
|
|
512
|
+
import {
|
|
513
|
+
getBundleSubset
|
|
514
|
+
} from "@plasmicapp/loader-core";
|
|
515
|
+
function getUsedComps(allComponents, entryCompIds) {
|
|
516
|
+
const q = [...entryCompIds];
|
|
517
|
+
const seenIds = new Set(entryCompIds);
|
|
518
|
+
const componentMetaById = new Map(
|
|
519
|
+
allComponents.map((meta) => [meta.id, meta])
|
|
520
|
+
);
|
|
521
|
+
const usedComps = [];
|
|
522
|
+
while (q.length > 0) {
|
|
523
|
+
const [id] = q.splice(0, 1);
|
|
524
|
+
const meta = componentMetaById.get(id);
|
|
525
|
+
if (!meta) {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
usedComps.push(meta);
|
|
529
|
+
meta.usedComponents.forEach((usedCompId) => {
|
|
530
|
+
if (!seenIds.has(usedCompId)) {
|
|
531
|
+
seenIds.add(usedCompId);
|
|
532
|
+
q.push(usedCompId);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
return usedComps;
|
|
537
|
+
}
|
|
538
|
+
function prepComponentData(bundle, compMetas, opts) {
|
|
539
|
+
if (compMetas.length === 0) {
|
|
540
|
+
return {
|
|
541
|
+
entryCompMetas: bundle.components,
|
|
542
|
+
bundle,
|
|
543
|
+
remoteFontUrls: []
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
const usedComps = getUsedComps(
|
|
547
|
+
bundle.components,
|
|
548
|
+
compMetas.map((compMeta) => compMeta.id)
|
|
549
|
+
);
|
|
550
|
+
const compPaths = usedComps.map((compMeta) => compMeta.entry);
|
|
551
|
+
const subBundle = getBundleSubset(
|
|
552
|
+
bundle,
|
|
553
|
+
[
|
|
554
|
+
"entrypoint.css",
|
|
555
|
+
...compPaths,
|
|
556
|
+
"root-provider.js",
|
|
557
|
+
...bundle.projects.map((x) => x.globalContextsProviderFileName).filter((x) => !!x),
|
|
558
|
+
// We need to explicitly include global context provider components
|
|
559
|
+
// to make sure they are kept in bundle.components. That's because
|
|
560
|
+
// for esbuild, just the globalContextsProviderFileName is not enough,
|
|
561
|
+
// because it will import a chunk that includes the global context
|
|
562
|
+
// component, instead of importing that global context component's
|
|
563
|
+
// entry file. And because nothing depends on the global context component's
|
|
564
|
+
// entry file, we end up excluding the global context component from
|
|
565
|
+
// bundle.components, which then makes its substitution not work.
|
|
566
|
+
// Instead, we forcibly include it here (we'll definitely need it anyway!).
|
|
567
|
+
...bundle.components.filter((c) => c.isGlobalContextProvider).map((c) => c.entry),
|
|
568
|
+
...bundle.globalGroups.map((g) => g.contextFile)
|
|
569
|
+
],
|
|
570
|
+
opts
|
|
571
|
+
);
|
|
572
|
+
const remoteFontUrls = [];
|
|
573
|
+
subBundle.projects.forEach(
|
|
574
|
+
(p) => remoteFontUrls.push(...p.remoteFonts.map((f) => f.url))
|
|
575
|
+
);
|
|
576
|
+
return {
|
|
577
|
+
entryCompMetas: compMetas,
|
|
578
|
+
bundle: subBundle,
|
|
579
|
+
remoteFontUrls
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
function mergeBundles(target, from) {
|
|
583
|
+
var _a;
|
|
584
|
+
const existingCompIds = new Set(target.components.map((c) => c.id));
|
|
585
|
+
const newCompMetas = from.components.filter(
|
|
586
|
+
(m) => !existingCompIds.has(m.id)
|
|
587
|
+
);
|
|
588
|
+
if (newCompMetas.length > 0) {
|
|
589
|
+
target = __spreadProps(__spreadValues({}, target), { components: [...target.components, ...newCompMetas] });
|
|
590
|
+
}
|
|
591
|
+
const existingProjects = new Set(target.projects.map((p) => p.id));
|
|
592
|
+
const newProjects = from.projects.filter((p) => !existingProjects.has(p.id));
|
|
593
|
+
if (newProjects.length > 0) {
|
|
594
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
595
|
+
projects: [...target.projects, ...newProjects]
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
const existingModules = {
|
|
599
|
+
browser: new Set(target.modules.browser.map((m) => m.fileName)),
|
|
600
|
+
server: new Set(target.modules.server.map((m) => m.fileName))
|
|
601
|
+
};
|
|
602
|
+
const newModules = {
|
|
603
|
+
browser: from.modules.browser.filter(
|
|
604
|
+
(m) => !existingModules.browser.has(m.fileName)
|
|
605
|
+
),
|
|
606
|
+
server: from.modules.server.filter(
|
|
607
|
+
(m) => !existingModules.server.has(m.fileName)
|
|
608
|
+
)
|
|
609
|
+
};
|
|
610
|
+
if (newModules.browser.length > 0 || newModules.server.length > 0) {
|
|
611
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
612
|
+
modules: {
|
|
613
|
+
browser: [...target.modules.browser, ...newModules.browser],
|
|
614
|
+
server: [...target.modules.server, ...newModules.server]
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
const existingGlobalIds = new Set(target.globalGroups.map((g) => g.id));
|
|
619
|
+
const newGlobals = from.globalGroups.filter(
|
|
620
|
+
(g) => !existingGlobalIds.has(g.id)
|
|
621
|
+
);
|
|
622
|
+
if (newGlobals.length > 0) {
|
|
623
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
624
|
+
globalGroups: [...target.globalGroups, ...newGlobals]
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
const existingExternals = new Set(target.external);
|
|
628
|
+
const newExternals = target.external.filter((x) => !existingExternals.has(x));
|
|
629
|
+
if (newExternals.length > 0) {
|
|
630
|
+
target = __spreadProps(__spreadValues({}, target), { external: [...target.external, ...newExternals] });
|
|
631
|
+
}
|
|
632
|
+
const existingSplitIds = new Set(target.activeSplits.map((s) => s.id));
|
|
633
|
+
const newSplits = (_a = from.activeSplits.filter((s) => !existingSplitIds.has(s.id))) != null ? _a : [];
|
|
634
|
+
if (newSplits.length > 0) {
|
|
635
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
636
|
+
activeSplits: [...target.activeSplits, ...newSplits]
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
return target;
|
|
640
|
+
}
|
|
641
|
+
var convertBundlesToComponentRenderData = (bundles, compMetas) => {
|
|
642
|
+
if (bundles.length === 0) {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
const mergedBundles = bundles.reduce((prev, cur) => mergeBundles(prev, cur));
|
|
646
|
+
return prepComponentData(mergedBundles, compMetas);
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
// src/loader-react-server.ts
|
|
650
|
+
var ReactServerPlasmicComponentLoader = class {
|
|
651
|
+
constructor(args) {
|
|
652
|
+
this.bundle = {
|
|
653
|
+
modules: {
|
|
654
|
+
browser: [],
|
|
655
|
+
server: []
|
|
656
|
+
},
|
|
657
|
+
components: [],
|
|
658
|
+
globalGroups: [],
|
|
659
|
+
external: [],
|
|
660
|
+
projects: [],
|
|
661
|
+
activeSplits: []
|
|
662
|
+
};
|
|
663
|
+
this.opts = args.opts;
|
|
664
|
+
this.fetcher = args.fetcher;
|
|
665
|
+
this.tracker = args.tracker;
|
|
666
|
+
this.onBundleMerged = args.onBundleMerged;
|
|
667
|
+
this.onBundleFetched = args.onBundleFetched;
|
|
668
|
+
}
|
|
669
|
+
maybeGetCompMetas(...specs) {
|
|
670
|
+
const found = /* @__PURE__ */ new Set();
|
|
671
|
+
const missing = [];
|
|
672
|
+
for (const spec of specs) {
|
|
673
|
+
const filteredMetas = getCompMetas(this.bundle.components, spec);
|
|
674
|
+
if (filteredMetas.length > 0) {
|
|
675
|
+
filteredMetas.forEach((meta) => found.add(meta));
|
|
676
|
+
} else {
|
|
677
|
+
missing.push(spec);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return { found: Array.from(found.keys()), missing };
|
|
681
|
+
}
|
|
682
|
+
maybeFetchComponentData(...args) {
|
|
683
|
+
return __async(this, null, function* () {
|
|
684
|
+
const { specs, opts } = parseFetchComponentDataArgs(...args);
|
|
685
|
+
const returnWithSpecsToFetch = (specsToFetch) => __async(this, null, function* () {
|
|
686
|
+
yield this.fetchMissingData({ missingSpecs: specsToFetch });
|
|
687
|
+
const { found: existingMetas2, missing: missingSpecs2 } = this.maybeGetCompMetas(...specs);
|
|
688
|
+
if (missingSpecs2.length > 0) {
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
return prepComponentData(this.bundle, existingMetas2, opts);
|
|
692
|
+
});
|
|
693
|
+
if (this.opts.alwaysFresh) {
|
|
694
|
+
return yield returnWithSpecsToFetch(specs);
|
|
695
|
+
}
|
|
696
|
+
const { found: existingMetas, missing: missingSpecs } = this.maybeGetCompMetas(...specs);
|
|
697
|
+
if (missingSpecs.length === 0) {
|
|
698
|
+
return prepComponentData(this.bundle, existingMetas, opts);
|
|
699
|
+
}
|
|
700
|
+
return yield returnWithSpecsToFetch(missingSpecs);
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
fetchComponentData(...args) {
|
|
704
|
+
return __async(this, null, function* () {
|
|
705
|
+
const { specs, opts } = parseFetchComponentDataArgs(...args);
|
|
706
|
+
const data = yield this.maybeFetchComponentData(specs, opts);
|
|
707
|
+
if (!data) {
|
|
708
|
+
const { missing: missingSpecs } = this.maybeGetCompMetas(...specs);
|
|
709
|
+
throw new Error(
|
|
710
|
+
`Unable to find components ${missingSpecs.map(getLookupSpecName).join(", ")}`
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
return data;
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
fetchPages(opts) {
|
|
717
|
+
return __async(this, null, function* () {
|
|
718
|
+
this.maybeReportClientSideFetch(
|
|
719
|
+
() => `Plasmic: fetching all page metadata in the browser`
|
|
720
|
+
);
|
|
721
|
+
const data = yield this.fetchAllData();
|
|
722
|
+
return data.components.filter(
|
|
723
|
+
(comp) => comp.isPage && comp.path && ((opts == null ? void 0 : opts.includeDynamicPages) || !isDynamicPagePath(comp.path))
|
|
724
|
+
);
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
fetchComponents() {
|
|
728
|
+
return __async(this, null, function* () {
|
|
729
|
+
this.maybeReportClientSideFetch(
|
|
730
|
+
() => `Plasmic: fetching all component metadata in the browser`
|
|
731
|
+
);
|
|
732
|
+
const data = yield this.fetchAllData();
|
|
733
|
+
return data.components;
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
getActiveSplits() {
|
|
737
|
+
return this.bundle.activeSplits;
|
|
738
|
+
}
|
|
739
|
+
fetchMissingData(opts) {
|
|
740
|
+
return __async(this, null, function* () {
|
|
741
|
+
this.maybeReportClientSideFetch(
|
|
742
|
+
() => `Plasmic: fetching missing components in the browser: ${opts.missingSpecs.map((spec) => getLookupSpecName(spec)).join(", ")}`
|
|
743
|
+
);
|
|
744
|
+
return this.fetchAllData();
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
maybeReportClientSideFetch(mkMsg) {
|
|
748
|
+
if (isBrowser && this.opts.onClientSideFetch) {
|
|
749
|
+
const msg = mkMsg();
|
|
750
|
+
if (this.opts.onClientSideFetch === "warn") {
|
|
751
|
+
console.warn(msg);
|
|
752
|
+
} else {
|
|
753
|
+
throw new Error(msg);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
fetchAllData() {
|
|
758
|
+
return __async(this, null, function* () {
|
|
759
|
+
var _a;
|
|
760
|
+
const bundle = yield this.fetcher.fetchAllData();
|
|
761
|
+
this.tracker.trackFetch();
|
|
762
|
+
this.mergeBundle(bundle);
|
|
763
|
+
(_a = this.onBundleFetched) == null ? void 0 : _a.call(this);
|
|
764
|
+
return bundle;
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
mergeBundle(bundle) {
|
|
768
|
+
var _a;
|
|
769
|
+
this.bundle = mergeBundles(bundle, this.bundle);
|
|
770
|
+
(_a = this.onBundleMerged) == null ? void 0 : _a.call(this);
|
|
771
|
+
}
|
|
772
|
+
getBundle() {
|
|
773
|
+
return this.bundle;
|
|
774
|
+
}
|
|
775
|
+
clearCache() {
|
|
776
|
+
this.bundle = {
|
|
777
|
+
modules: {
|
|
778
|
+
browser: [],
|
|
779
|
+
server: []
|
|
780
|
+
},
|
|
781
|
+
components: [],
|
|
782
|
+
globalGroups: [],
|
|
783
|
+
external: [],
|
|
784
|
+
projects: [],
|
|
785
|
+
activeSplits: []
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
function parseFetchComponentDataArgs(...args) {
|
|
790
|
+
let specs;
|
|
791
|
+
let opts;
|
|
792
|
+
if (Array.isArray(args[0])) {
|
|
793
|
+
specs = args[0];
|
|
794
|
+
opts = args[1];
|
|
795
|
+
} else {
|
|
796
|
+
specs = args;
|
|
797
|
+
opts = void 0;
|
|
798
|
+
}
|
|
799
|
+
return { specs, opts };
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/loader.ts
|
|
803
|
+
var SUBSTITUTED_COMPONENTS = {};
|
|
804
|
+
var REGISTERED_CODE_COMPONENT_HELPERS = {};
|
|
805
|
+
var SUBSTITUTED_GLOBAL_VARIANT_HOOKS = {};
|
|
806
|
+
var REGISTERED_CUSTOM_FUNCTIONS = {};
|
|
807
|
+
function customFunctionImportAlias(meta) {
|
|
808
|
+
const customFunctionPrefix = `__fn_`;
|
|
809
|
+
return meta.namespace ? `${customFunctionPrefix}${meta.namespace}__${meta.name}` : `${customFunctionPrefix}${meta.name}`;
|
|
810
|
+
}
|
|
811
|
+
var InternalPlasmicComponentLoader = class {
|
|
812
|
+
constructor(opts) {
|
|
813
|
+
this.opts = opts;
|
|
814
|
+
this.registry = new Registry();
|
|
815
|
+
this.subs = [];
|
|
816
|
+
this.roots = [];
|
|
817
|
+
this.globalVariants = [];
|
|
818
|
+
this.tracker = new PlasmicTracker({
|
|
819
|
+
projectIds: opts.projects.map((p) => p.id),
|
|
820
|
+
platform: opts.platform,
|
|
821
|
+
preview: opts.preview
|
|
822
|
+
});
|
|
823
|
+
this.reactServerLoader = new ReactServerPlasmicComponentLoader({
|
|
824
|
+
opts,
|
|
825
|
+
fetcher: new PlasmicModulesFetcher(opts),
|
|
826
|
+
tracker: this.tracker,
|
|
827
|
+
onBundleMerged: () => {
|
|
828
|
+
this.refreshRegistry();
|
|
829
|
+
},
|
|
830
|
+
onBundleFetched: () => {
|
|
831
|
+
this.roots.forEach((watcher) => {
|
|
832
|
+
var _a;
|
|
833
|
+
return (_a = watcher.onDataFetched) == null ? void 0 : _a.call(watcher);
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
this.registerModules({
|
|
838
|
+
react: React3,
|
|
839
|
+
"react-dom": ReactDOM,
|
|
840
|
+
"react/jsx-runtime": jsxRuntime,
|
|
841
|
+
"react/jsx-dev-runtime": jsxDevRuntime,
|
|
842
|
+
// Also inject @plasmicapp/query and @plasmicapp/host to use the
|
|
843
|
+
// same contexts here and in loader-downloaded code.
|
|
844
|
+
"@plasmicapp/query": PlasmicQuery,
|
|
845
|
+
"@plasmicapp/data-sources-context": PlasmicDataSourcesContext,
|
|
846
|
+
"@plasmicapp/host": PlasmicHost,
|
|
847
|
+
"@plasmicapp/loader-runtime-registry": {
|
|
848
|
+
components: SUBSTITUTED_COMPONENTS,
|
|
849
|
+
globalVariantHooks: SUBSTITUTED_GLOBAL_VARIANT_HOOKS,
|
|
850
|
+
codeComponentHelpers: REGISTERED_CODE_COMPONENT_HELPERS,
|
|
851
|
+
functions: REGISTERED_CUSTOM_FUNCTIONS
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
getBundle() {
|
|
856
|
+
return this.reactServerLoader.getBundle();
|
|
857
|
+
}
|
|
858
|
+
setGlobalVariants(globalVariants) {
|
|
859
|
+
this.globalVariants = globalVariants;
|
|
860
|
+
}
|
|
861
|
+
getGlobalVariants() {
|
|
862
|
+
return this.globalVariants;
|
|
863
|
+
}
|
|
864
|
+
registerModules(modules) {
|
|
865
|
+
if (Object.keys(modules).some(
|
|
866
|
+
(name) => this.registry.getRegisteredModule(name) !== modules[name]
|
|
867
|
+
)) {
|
|
868
|
+
if (!this.registry.isEmpty()) {
|
|
869
|
+
console.warn(
|
|
870
|
+
"Calling PlasmicComponentLoader.registerModules() after Plasmic component has rendered; starting over."
|
|
871
|
+
);
|
|
872
|
+
this.registry.clear();
|
|
873
|
+
}
|
|
874
|
+
for (const key of Object.keys(modules)) {
|
|
875
|
+
this.registry.register(key, modules[key]);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
substituteComponent(component, name) {
|
|
880
|
+
this.internalSubstituteComponent(component, name, void 0);
|
|
881
|
+
}
|
|
882
|
+
internalSubstituteComponent(component, name, codeComponentHelpers) {
|
|
883
|
+
if (!this.registry.isEmpty()) {
|
|
884
|
+
console.warn(
|
|
885
|
+
"Calling PlasmicComponentLoader.registerSubstitution() after Plasmic component has rendered; starting over."
|
|
886
|
+
);
|
|
887
|
+
this.registry.clear();
|
|
888
|
+
}
|
|
889
|
+
this.subs.push({ lookup: name, component, codeComponentHelpers });
|
|
890
|
+
}
|
|
891
|
+
registerComponent(component, meta) {
|
|
892
|
+
var _a, _b;
|
|
893
|
+
const stateHelpers = Object.fromEntries(
|
|
894
|
+
Object.entries((_a = meta.states) != null ? _a : {}).filter(
|
|
895
|
+
([_, stateSpec]) => Object.keys(stateSpec).some((key) => stateHelpersKeys.includes(key))
|
|
896
|
+
).map(([stateName, stateSpec]) => [
|
|
897
|
+
stateName,
|
|
898
|
+
Object.fromEntries(
|
|
899
|
+
stateHelpersKeys.filter((key) => key in stateSpec).map((key) => [key, stateSpec[key]])
|
|
900
|
+
)
|
|
901
|
+
])
|
|
902
|
+
);
|
|
903
|
+
const helpers = { states: stateHelpers };
|
|
904
|
+
this.internalSubstituteComponent(
|
|
905
|
+
component,
|
|
906
|
+
{ name: meta.name, isCode: true },
|
|
907
|
+
Object.keys(stateHelpers).length > 0 ? helpers : void 0
|
|
908
|
+
);
|
|
909
|
+
registerComponent(component, __spreadValues(__spreadProps(__spreadValues({}, meta), {
|
|
910
|
+
// Import path is not used as we will use component substitution
|
|
911
|
+
importPath: (_b = meta.importPath) != null ? _b : ""
|
|
912
|
+
}), Object.keys(stateHelpers).length > 0 ? {
|
|
913
|
+
componentHelpers: {
|
|
914
|
+
helpers,
|
|
915
|
+
importPath: "",
|
|
916
|
+
importName: ""
|
|
917
|
+
}
|
|
918
|
+
} : {}));
|
|
919
|
+
}
|
|
920
|
+
unstable_registerFunction(fn, meta) {
|
|
921
|
+
var _a;
|
|
922
|
+
unstable_registerFunction(fn, __spreadProps(__spreadValues({}, meta), {
|
|
923
|
+
importPath: (_a = meta.importPath) != null ? _a : ""
|
|
924
|
+
}));
|
|
925
|
+
REGISTERED_CUSTOM_FUNCTIONS[customFunctionImportAlias(meta)] = fn;
|
|
926
|
+
}
|
|
927
|
+
registerGlobalContext(context, meta) {
|
|
928
|
+
var _a;
|
|
929
|
+
this.substituteComponent(context, { name: meta.name, isCode: true });
|
|
930
|
+
registerGlobalContext(context, __spreadProps(__spreadValues({}, meta), {
|
|
931
|
+
importPath: (_a = meta.importPath) != null ? _a : ""
|
|
932
|
+
}));
|
|
933
|
+
}
|
|
934
|
+
registerTrait(trait, meta) {
|
|
935
|
+
registerTrait(trait, meta);
|
|
936
|
+
}
|
|
937
|
+
registerToken(token) {
|
|
938
|
+
registerToken(token);
|
|
939
|
+
}
|
|
940
|
+
registerPrefetchedBundle(bundle) {
|
|
941
|
+
if (!isBrowser) {
|
|
942
|
+
const cachedBundle = internal_getCachedBundleInNodeServer(this.opts);
|
|
943
|
+
if (cachedBundle) {
|
|
944
|
+
this.reactServerLoader.mergeBundle(cachedBundle);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
this.reactServerLoader.mergeBundle(bundle);
|
|
948
|
+
}
|
|
949
|
+
subscribePlasmicRoot(watcher) {
|
|
950
|
+
this.roots.push(watcher);
|
|
951
|
+
}
|
|
952
|
+
unsubscribePlasmicRoot(watcher) {
|
|
953
|
+
const index = this.roots.indexOf(watcher);
|
|
954
|
+
if (index >= 0) {
|
|
955
|
+
this.roots.splice(index, 1);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
clearCache() {
|
|
959
|
+
this.reactServerLoader.clearCache();
|
|
960
|
+
this.registry.clear();
|
|
961
|
+
}
|
|
962
|
+
getLookup() {
|
|
963
|
+
return new ComponentLookup(this.getBundle(), this.registry);
|
|
964
|
+
}
|
|
965
|
+
maybeFetchComponentData(...args) {
|
|
966
|
+
return this.reactServerLoader.maybeFetchComponentData(...args);
|
|
967
|
+
}
|
|
968
|
+
fetchComponentData(...args) {
|
|
969
|
+
return this.reactServerLoader.fetchComponentData(...args);
|
|
970
|
+
}
|
|
971
|
+
fetchPages(opts) {
|
|
972
|
+
return this.reactServerLoader.fetchPages(opts);
|
|
973
|
+
}
|
|
974
|
+
fetchComponents() {
|
|
975
|
+
return this.reactServerLoader.fetchComponents();
|
|
976
|
+
}
|
|
977
|
+
getActiveSplits() {
|
|
978
|
+
return this.reactServerLoader.getActiveSplits();
|
|
979
|
+
}
|
|
980
|
+
trackConversion(value = 0) {
|
|
981
|
+
this.tracker.trackConversion(value);
|
|
982
|
+
}
|
|
983
|
+
getActiveVariation(opts) {
|
|
984
|
+
return __async(this, null, function* () {
|
|
985
|
+
yield this.reactServerLoader.fetchComponents();
|
|
986
|
+
return getActiveVariation(__spreadProps(__spreadValues({}, opts), {
|
|
987
|
+
splits: this.getBundle().activeSplits
|
|
988
|
+
}));
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
getTeamIds() {
|
|
992
|
+
return uniq(
|
|
993
|
+
this.getBundle().projects.map(
|
|
994
|
+
(p) => p.teamId ? `${p.teamId}${p.indirect ? "@indirect" : ""}` : null
|
|
995
|
+
).filter((x) => !!x)
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
getProjectIds() {
|
|
999
|
+
return uniq(
|
|
1000
|
+
this.getBundle().projects.map(
|
|
1001
|
+
(p) => `${p.id}${p.indirect ? "@indirect" : ""}`
|
|
1002
|
+
)
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
trackRender(opts) {
|
|
1006
|
+
this.tracker.trackRender(opts);
|
|
1007
|
+
}
|
|
1008
|
+
refreshRegistry() {
|
|
1009
|
+
for (const sub of this.subs) {
|
|
1010
|
+
const metas = getCompMetas(this.getBundle().components, sub.lookup);
|
|
1011
|
+
metas.forEach((meta) => {
|
|
1012
|
+
SUBSTITUTED_COMPONENTS[meta.id] = sub.component;
|
|
1013
|
+
if (sub.codeComponentHelpers) {
|
|
1014
|
+
REGISTERED_CODE_COMPONENT_HELPERS[meta.id] = sub.codeComponentHelpers;
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
for (const globalGroup of this.getBundle().globalGroups) {
|
|
1019
|
+
if (globalGroup.type !== "global-screen") {
|
|
1020
|
+
SUBSTITUTED_GLOBAL_VARIANT_HOOKS[globalGroup.id] = createUseGlobalVariant(globalGroup.name, globalGroup.projectId);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
this.registry.updateModules(this.getBundle());
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
var PlasmicComponentLoader = class {
|
|
1027
|
+
constructor(internal) {
|
|
1028
|
+
this.warnedRegisterComponent = false;
|
|
1029
|
+
this.__internal = internal;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Sets global variants to be used for all components. Note that
|
|
1033
|
+
* this is not reactive, and will not re-render all components
|
|
1034
|
+
* already mounted; instead, it should be used to activate global
|
|
1035
|
+
* variants that should always be activated for the lifetime of this
|
|
1036
|
+
* app. If you'd like to reactively change the global variants,
|
|
1037
|
+
* you should specify them via <PlasmicRootProvider />
|
|
1038
|
+
*/
|
|
1039
|
+
setGlobalVariants(globalVariants) {
|
|
1040
|
+
this.__internal.setGlobalVariants(globalVariants);
|
|
1041
|
+
}
|
|
1042
|
+
registerModules(modules) {
|
|
1043
|
+
this.__internal.registerModules(modules);
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Register custom components that should be swapped in for
|
|
1047
|
+
* components defined in your project. You can use this to
|
|
1048
|
+
* swap in / substitute a Plasmic component with a "real" component.
|
|
1049
|
+
*/
|
|
1050
|
+
substituteComponent(component, name) {
|
|
1051
|
+
this.__internal.substituteComponent(component, name);
|
|
1052
|
+
}
|
|
1053
|
+
registerComponent(component, metaOrName) {
|
|
1054
|
+
if (metaOrName && typeof metaOrName === "object" && "props" in metaOrName) {
|
|
1055
|
+
this.__internal.registerComponent(component, metaOrName);
|
|
1056
|
+
} else {
|
|
1057
|
+
if (process.env.NODE_ENV === "development" && !this.warnedRegisterComponent) {
|
|
1058
|
+
console.warn(
|
|
1059
|
+
`PlasmicLoader: Using deprecated method \`registerComponent\` for component substitution. Please consider using \`substituteComponent\` instead.`
|
|
1060
|
+
);
|
|
1061
|
+
this.warnedRegisterComponent = true;
|
|
1062
|
+
}
|
|
1063
|
+
this.substituteComponent(component, metaOrName);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
unstable_registerFunction(fn, meta) {
|
|
1067
|
+
this.__internal.unstable_registerFunction(fn, meta);
|
|
1068
|
+
}
|
|
1069
|
+
registerGlobalContext(context, meta) {
|
|
1070
|
+
this.__internal.registerGlobalContext(context, meta);
|
|
1071
|
+
}
|
|
1072
|
+
registerTrait(trait, meta) {
|
|
1073
|
+
this.__internal.registerTrait(trait, meta);
|
|
1074
|
+
}
|
|
1075
|
+
registerToken(token) {
|
|
1076
|
+
this.__internal.registerToken(token);
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Pre-fetches component data needed to for PlasmicLoader to render
|
|
1080
|
+
* these components. Should be passed into PlasmicRootProvider as
|
|
1081
|
+
* the prefetchedData prop.
|
|
1082
|
+
*
|
|
1083
|
+
* You can look up a component either by:
|
|
1084
|
+
* - the name of the component
|
|
1085
|
+
* - the path for a page component
|
|
1086
|
+
* - an array of strings that make up parts of the path
|
|
1087
|
+
* - object { name: "name_or_path", projectId: ...}, to specify which project
|
|
1088
|
+
* to use, if multiple projects have the same component name
|
|
1089
|
+
*
|
|
1090
|
+
* Throws an Error if a specified component to fetch does not exist in
|
|
1091
|
+
* the Plasmic project.
|
|
1092
|
+
*/
|
|
1093
|
+
fetchComponentData(...specs) {
|
|
1094
|
+
return __async(this, null, function* () {
|
|
1095
|
+
return this.__internal.fetchComponentData(...specs);
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Like fetchComponentData(), but returns null instead of throwing an Error
|
|
1100
|
+
* when a component is not found. Useful when you are implementing a catch-all
|
|
1101
|
+
* page and want to check if a specific path had been defined for Plasmic.
|
|
1102
|
+
*/
|
|
1103
|
+
maybeFetchComponentData(...specs) {
|
|
1104
|
+
return __async(this, null, function* () {
|
|
1105
|
+
return this.__internal.maybeFetchComponentData(...specs);
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Returns all the page component metadata for these projects.
|
|
1110
|
+
*/
|
|
1111
|
+
fetchPages(opts) {
|
|
1112
|
+
return __async(this, null, function* () {
|
|
1113
|
+
return this.__internal.fetchPages(opts);
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Returns all components metadata for these projects.
|
|
1118
|
+
*/
|
|
1119
|
+
fetchComponents() {
|
|
1120
|
+
return __async(this, null, function* () {
|
|
1121
|
+
return this.__internal.fetchComponents();
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
_getActiveVariation(opts) {
|
|
1125
|
+
return __async(this, null, function* () {
|
|
1126
|
+
return this.__internal.getActiveVariation(opts);
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
getActiveVariation(opts) {
|
|
1130
|
+
return __async(this, null, function* () {
|
|
1131
|
+
return this._getActiveVariation({
|
|
1132
|
+
traits: opts.traits,
|
|
1133
|
+
getKnownValue: (key) => {
|
|
1134
|
+
if (opts.known) {
|
|
1135
|
+
return opts.known[key];
|
|
1136
|
+
} else {
|
|
1137
|
+
const cookies = getPlasmicCookieValues();
|
|
1138
|
+
return cookies[key];
|
|
1139
|
+
}
|
|
1140
|
+
},
|
|
1141
|
+
updateKnownValue: (key, value) => {
|
|
1142
|
+
if (!opts.known) {
|
|
1143
|
+
updatePlasmicCookieValue(key, value);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
getExternalVariation(variation) {
|
|
1150
|
+
return getExternalIds(this.getActiveSplits(), variation);
|
|
1151
|
+
}
|
|
1152
|
+
getActiveSplits() {
|
|
1153
|
+
return this.__internal.getActiveSplits();
|
|
1154
|
+
}
|
|
1155
|
+
trackConversion(value = 0) {
|
|
1156
|
+
this.__internal.trackConversion(value);
|
|
1157
|
+
}
|
|
1158
|
+
clearCache() {
|
|
1159
|
+
return this.__internal.clearCache();
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
// src/index.ts
|
|
1164
|
+
import {
|
|
1165
|
+
DataCtxReader,
|
|
1166
|
+
DataProvider,
|
|
1167
|
+
PageParamsProvider as PageParamsProvider2,
|
|
1168
|
+
PlasmicCanvasContext,
|
|
1169
|
+
PlasmicCanvasHost,
|
|
1170
|
+
repeatedElement,
|
|
1171
|
+
useDataEnv,
|
|
1172
|
+
usePlasmicCanvasContext,
|
|
1173
|
+
useSelector,
|
|
1174
|
+
useSelectors
|
|
1175
|
+
} from "@plasmicapp/host";
|
|
1176
|
+
import { usePlasmicQueryData } from "@plasmicapp/query";
|
|
1177
|
+
|
|
1178
|
+
// src/PlasmicComponent.tsx
|
|
1179
|
+
import * as React5 from "react";
|
|
1180
|
+
|
|
1181
|
+
// src/usePlasmicComponent.tsx
|
|
1182
|
+
import * as React4 from "react";
|
|
1183
|
+
function usePlasmicComponent(spec, opts = {}) {
|
|
1184
|
+
const rootContext = usePlasmicRootContext();
|
|
1185
|
+
if (!rootContext) {
|
|
1186
|
+
throw new Error(
|
|
1187
|
+
`You can only use usePlasmicComponent if wrapped in <PlasmicRootProvider />`
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
const loader = rootContext.loader;
|
|
1191
|
+
const lookup = loader.getLookup();
|
|
1192
|
+
const component = lookup.hasComponent(spec) ? lookup.getComponent(spec, opts) : void 0;
|
|
1193
|
+
const stableSpec = useStableLookupSpec(spec);
|
|
1194
|
+
const isMounted = useIsMounted();
|
|
1195
|
+
const forceUpdate = useForceUpdate();
|
|
1196
|
+
React4.useEffect(() => {
|
|
1197
|
+
if (!component) {
|
|
1198
|
+
(() => __async(this, null, function* () {
|
|
1199
|
+
yield loader.fetchComponentData(stableSpec);
|
|
1200
|
+
if (isMounted()) {
|
|
1201
|
+
forceUpdate();
|
|
1202
|
+
}
|
|
1203
|
+
}))();
|
|
1204
|
+
}
|
|
1205
|
+
}, [component, stableSpec]);
|
|
1206
|
+
return component;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// src/PlasmicComponent.tsx
|
|
1210
|
+
var PlasmicComponentContext = React5.createContext(false);
|
|
1211
|
+
function PlasmicComponent(props) {
|
|
1212
|
+
const { component, projectId, componentProps, forceOriginal } = props;
|
|
1213
|
+
const rootContext = usePlasmicRootContext();
|
|
1214
|
+
const isRootLoader = !React5.useContext(PlasmicComponentContext);
|
|
1215
|
+
if (!rootContext) {
|
|
1216
|
+
throw new Error(
|
|
1217
|
+
`You must use <PlasmicRootProvider/> at the root of your app`
|
|
1218
|
+
);
|
|
1219
|
+
}
|
|
1220
|
+
const _a = rootContext, {
|
|
1221
|
+
loader,
|
|
1222
|
+
globalContextsProps,
|
|
1223
|
+
variation,
|
|
1224
|
+
userAuthToken,
|
|
1225
|
+
isUserLoading,
|
|
1226
|
+
authRedirectUri,
|
|
1227
|
+
translator
|
|
1228
|
+
} = _a, rest = __objRest(_a, [
|
|
1229
|
+
"loader",
|
|
1230
|
+
"globalContextsProps",
|
|
1231
|
+
"variation",
|
|
1232
|
+
"userAuthToken",
|
|
1233
|
+
"isUserLoading",
|
|
1234
|
+
"authRedirectUri",
|
|
1235
|
+
"translator"
|
|
1236
|
+
]);
|
|
1237
|
+
const Component = usePlasmicComponent(
|
|
1238
|
+
{ name: component, projectId, isCode: false },
|
|
1239
|
+
{ forceOriginal }
|
|
1240
|
+
);
|
|
1241
|
+
React5.useEffect(() => {
|
|
1242
|
+
if (isRootLoader) {
|
|
1243
|
+
const meta = loader.getLookup().getComponentMeta({ name: component, projectId });
|
|
1244
|
+
if (meta) {
|
|
1245
|
+
loader.trackRender({
|
|
1246
|
+
renderCtx: {
|
|
1247
|
+
rootProjectId: meta.projectId,
|
|
1248
|
+
rootComponentId: meta.id,
|
|
1249
|
+
rootComponentName: component,
|
|
1250
|
+
teamIds: loader.getTeamIds(),
|
|
1251
|
+
projectIds: loader.getProjectIds()
|
|
1252
|
+
},
|
|
1253
|
+
variation
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}, [component, projectId, loader, variation]);
|
|
1258
|
+
const element = React5.useMemo(() => {
|
|
1259
|
+
var _a2;
|
|
1260
|
+
if (!Component) {
|
|
1261
|
+
return null;
|
|
1262
|
+
}
|
|
1263
|
+
let element2 = /* @__PURE__ */ React5.createElement(Component, __spreadValues({}, componentProps));
|
|
1264
|
+
if (isRootLoader) {
|
|
1265
|
+
const lookup = loader.getLookup();
|
|
1266
|
+
const ReactWebRootProvider = lookup.getRootProvider();
|
|
1267
|
+
const GlobalContextsProvider = lookup.getGlobalContextsProvider({
|
|
1268
|
+
name: component,
|
|
1269
|
+
projectId
|
|
1270
|
+
});
|
|
1271
|
+
element2 = /* @__PURE__ */ React5.createElement(
|
|
1272
|
+
ReactWebRootProvider,
|
|
1273
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
1274
|
+
userAuthToken,
|
|
1275
|
+
isUserLoading,
|
|
1276
|
+
authRedirectUri,
|
|
1277
|
+
i18n: {
|
|
1278
|
+
translator,
|
|
1279
|
+
tagPrefix: (_a2 = loader.opts.i18n) == null ? void 0 : _a2.tagPrefix
|
|
1280
|
+
}
|
|
1281
|
+
}),
|
|
1282
|
+
/* @__PURE__ */ React5.createElement(
|
|
1283
|
+
MaybeWrap,
|
|
1284
|
+
{
|
|
1285
|
+
cond: !!GlobalContextsProvider,
|
|
1286
|
+
wrapper: (children) => /* @__PURE__ */ React5.createElement(GlobalContextsProvider, __spreadValues({}, globalContextsProps), children)
|
|
1287
|
+
},
|
|
1288
|
+
/* @__PURE__ */ React5.createElement(PlasmicComponentContext.Provider, { value: true }, element2)
|
|
1289
|
+
)
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1292
|
+
return element2;
|
|
1293
|
+
}, [
|
|
1294
|
+
Component,
|
|
1295
|
+
componentProps,
|
|
1296
|
+
loader,
|
|
1297
|
+
isRootLoader,
|
|
1298
|
+
component,
|
|
1299
|
+
projectId,
|
|
1300
|
+
globalContextsProps,
|
|
1301
|
+
userAuthToken,
|
|
1302
|
+
// Just use the token to memo, `user` should be derived from it
|
|
1303
|
+
isUserLoading,
|
|
1304
|
+
authRedirectUri
|
|
1305
|
+
]);
|
|
1306
|
+
return element;
|
|
1307
|
+
}
|
|
1308
|
+
function MaybeWrap(props) {
|
|
1309
|
+
return props.cond ? props.wrapper(props.children) : props.children;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// src/index.ts
|
|
1313
|
+
import { extractPlasmicQueryData as extractPlasmicQueryData2, plasmicPrepass } from "@plasmicapp/prepass";
|
|
1314
|
+
|
|
1315
|
+
// src/render.tsx
|
|
1316
|
+
import React6 from "react";
|
|
1317
|
+
import ReactDOM2 from "react-dom";
|
|
1318
|
+
import { renderToString as reactRenderToString } from "react-dom/server";
|
|
1319
|
+
import { extractPlasmicQueryData } from "@plasmicapp/prepass";
|
|
1320
|
+
function renderToElement(_0, _1, _2) {
|
|
1321
|
+
return __async(this, arguments, function* (loader, target, lookup, opts = {}) {
|
|
1322
|
+
return new Promise((resolve) => {
|
|
1323
|
+
const element = makeElement(loader, lookup, opts);
|
|
1324
|
+
ReactDOM2.render(element, target, () => resolve());
|
|
1325
|
+
});
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
function renderToString(loader, lookup, opts = {}) {
|
|
1329
|
+
const element = makeElement(loader, lookup, opts);
|
|
1330
|
+
return reactRenderToString(element);
|
|
1331
|
+
}
|
|
1332
|
+
function extractPlasmicQueryDataFromElement(_0, _1) {
|
|
1333
|
+
return __async(this, arguments, function* (loader, lookup, opts = {}) {
|
|
1334
|
+
const element = makeElement(loader, lookup, opts);
|
|
1335
|
+
return extractPlasmicQueryData(element);
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
function hydrateFromElement(_0, _1, _2) {
|
|
1339
|
+
return __async(this, arguments, function* (loader, target, lookup, opts = {}) {
|
|
1340
|
+
return new Promise((resolve) => {
|
|
1341
|
+
const element = makeElement(loader, lookup, opts);
|
|
1342
|
+
ReactDOM2.hydrate(element, target, () => resolve());
|
|
1343
|
+
});
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
function makeElement(loader, lookup, opts = {}) {
|
|
1347
|
+
return /* @__PURE__ */ React6.createElement(
|
|
1348
|
+
PlasmicRootProvider,
|
|
1349
|
+
{
|
|
1350
|
+
loader,
|
|
1351
|
+
prefetchedData: opts.prefetchedData,
|
|
1352
|
+
globalVariants: opts.globalVariants,
|
|
1353
|
+
prefetchedQueryData: opts.prefetchedQueryData,
|
|
1354
|
+
pageParams: opts.pageParams,
|
|
1355
|
+
pageQuery: opts.pageQuery
|
|
1356
|
+
},
|
|
1357
|
+
/* @__PURE__ */ React6.createElement(
|
|
1358
|
+
PlasmicComponent,
|
|
1359
|
+
{
|
|
1360
|
+
component: typeof lookup === "string" ? lookup : lookup.name,
|
|
1361
|
+
projectId: typeof lookup === "string" ? void 0 : lookup.projectId,
|
|
1362
|
+
componentProps: opts.componentProps
|
|
1363
|
+
}
|
|
1364
|
+
)
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// src/index.ts
|
|
1369
|
+
function initPlasmicLoader(opts) {
|
|
1370
|
+
const internal = new InternalPlasmicComponentLoader(opts);
|
|
1371
|
+
return new PlasmicComponentLoader(internal);
|
|
1372
|
+
}
|
|
1373
|
+
export {
|
|
1374
|
+
DataCtxReader,
|
|
1375
|
+
DataProvider,
|
|
1376
|
+
InternalPlasmicComponentLoader,
|
|
1377
|
+
PageParamsProvider2 as PageParamsProvider,
|
|
1378
|
+
PlasmicCanvasContext,
|
|
1379
|
+
PlasmicCanvasHost,
|
|
1380
|
+
PlasmicComponent,
|
|
1381
|
+
PlasmicComponentLoader,
|
|
1382
|
+
PlasmicRootProvider,
|
|
1383
|
+
convertBundlesToComponentRenderData,
|
|
1384
|
+
extractPlasmicQueryData2 as extractPlasmicQueryData,
|
|
1385
|
+
extractPlasmicQueryDataFromElement,
|
|
1386
|
+
hydrateFromElement,
|
|
1387
|
+
initPlasmicLoader,
|
|
1388
|
+
matchesPagePath,
|
|
1389
|
+
plasmicPrepass,
|
|
1390
|
+
renderToElement,
|
|
1391
|
+
renderToString,
|
|
1392
|
+
repeatedElement,
|
|
1393
|
+
useDataEnv,
|
|
1394
|
+
usePlasmicCanvasContext,
|
|
1395
|
+
usePlasmicComponent,
|
|
1396
|
+
usePlasmicQueryData,
|
|
1397
|
+
useSelector,
|
|
1398
|
+
useSelectors
|
|
1399
|
+
};
|
|
1400
|
+
//# sourceMappingURL=index.esm.js.map
|