@daouy/loader-react 1.0.409
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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/index.d.ts +728 -0
- package/dist/index.esm.js +1567 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +1566 -0
- package/dist/index.js.map +7 -0
- package/dist/react-server.d.ts +503 -0
- package/dist/react-server.esm.js +1585 -0
- package/dist/react-server.esm.js.map +7 -0
- package/dist/react-server.js +1607 -0
- package/dist/react-server.js.map +7 -0
- package/index.d.ts +1 -0
- package/package.json +89 -0
- package/react-server-conditional.d.ts +4 -0
- package/react-server.d.ts +1 -0
|
@@ -0,0 +1,1585 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
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
|
+
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/react-server.ts
|
|
54
|
+
import "server-only";
|
|
55
|
+
|
|
56
|
+
// src/loader-server.tsx
|
|
57
|
+
import { DaouyModulesFetcher as DaouyModulesFetcher2 } from "@daouy/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 "@daouy/loader-core";
|
|
67
|
+
import {
|
|
68
|
+
internal_getCachedBundleInNodeServer
|
|
69
|
+
} from "@daouy/loader-fetcher";
|
|
70
|
+
import { getActiveVariation, getExternalIds } from "@daouy/loader-splits";
|
|
71
|
+
|
|
72
|
+
// src/bundles.ts
|
|
73
|
+
import {
|
|
74
|
+
getBundleSubset
|
|
75
|
+
} from "@daouy/loader-core";
|
|
76
|
+
|
|
77
|
+
// src/utils.tsx
|
|
78
|
+
import pascalcase from "pascalcase";
|
|
79
|
+
import * as React from "react";
|
|
80
|
+
var isBrowser = typeof window !== "undefined";
|
|
81
|
+
function isNameSpec(lookup) {
|
|
82
|
+
return "name" in lookup;
|
|
83
|
+
}
|
|
84
|
+
function toFullLookup(lookup) {
|
|
85
|
+
const namePart = typeof lookup === "string" ? lookup : lookup.name;
|
|
86
|
+
const projectId = typeof lookup === "string" ? void 0 : lookup.projectId;
|
|
87
|
+
const codeComponent = typeof lookup === "string" ? void 0 : lookup.isCode;
|
|
88
|
+
if (codeComponent !== true && namePart.startsWith("/")) {
|
|
89
|
+
return { path: normalizePath(namePart), projectId };
|
|
90
|
+
} else {
|
|
91
|
+
return {
|
|
92
|
+
name: codeComponent ? namePart : normalizeName(namePart),
|
|
93
|
+
rawName: namePart.trim(),
|
|
94
|
+
projectId,
|
|
95
|
+
isCode: codeComponent
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function normalizePath(path) {
|
|
100
|
+
return path.trim();
|
|
101
|
+
}
|
|
102
|
+
function normalizeName(name) {
|
|
103
|
+
return pascalcase(name).trim();
|
|
104
|
+
}
|
|
105
|
+
function matchesPagePath(pattern, path) {
|
|
106
|
+
const normalizedPattern = "/" + pattern.replace(/^\/|\/$/g, "");
|
|
107
|
+
const normalizedPath = "/" + path.replace(/^\/|\/$/g, "");
|
|
108
|
+
const regexString = normalizedPattern.replace(/\/\[\[\.\.\.([^\]^]+)]]/g, "(?:/([^]*))?").replace(/\/\[\.\.\.([^\]^]+)]/g, "/([^]*)").replace(/\[([^\]^]+)]/g, "([^/]+)").replace(/\//g, "\\/");
|
|
109
|
+
const regex = new RegExp(`^/?${regexString}$`);
|
|
110
|
+
const match = normalizedPath.match(regex);
|
|
111
|
+
if (!match)
|
|
112
|
+
return false;
|
|
113
|
+
const slugNames = [...pattern.matchAll(/\[\.?\.?\.?([^[\]]+)]/g)].map(
|
|
114
|
+
(m) => m[1]
|
|
115
|
+
);
|
|
116
|
+
const params = {};
|
|
117
|
+
for (let i = 0; i < slugNames.length; i++) {
|
|
118
|
+
const slugName = slugNames[i];
|
|
119
|
+
const value = match[i + 1];
|
|
120
|
+
if (pattern.includes(`[[...${slugName}]]`)) {
|
|
121
|
+
params[slugName] = value ? value.split("/").filter(Boolean) : [];
|
|
122
|
+
} else if (pattern.includes(`[...${slugName}]`)) {
|
|
123
|
+
params[slugName] = value.split("/").filter(Boolean);
|
|
124
|
+
} else if (value !== void 0) {
|
|
125
|
+
params[slugName] = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { params };
|
|
129
|
+
}
|
|
130
|
+
function isDynamicPagePath(path) {
|
|
131
|
+
return !!path.match(/\[[^/]*\]/);
|
|
132
|
+
}
|
|
133
|
+
function matchesCompMeta(lookup, meta) {
|
|
134
|
+
if (lookup.projectId && meta.projectId !== lookup.projectId) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
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));
|
|
138
|
+
}
|
|
139
|
+
function getCompMetas(metas, lookup) {
|
|
140
|
+
const full = toFullLookup(lookup);
|
|
141
|
+
return metas.filter((meta) => matchesCompMeta(full, meta)).map(
|
|
142
|
+
(meta) => {
|
|
143
|
+
if (isNameSpec(full) || !meta.path) {
|
|
144
|
+
return meta;
|
|
145
|
+
}
|
|
146
|
+
const match = matchesPagePath(meta.path, full.path);
|
|
147
|
+
if (!match) {
|
|
148
|
+
return meta;
|
|
149
|
+
}
|
|
150
|
+
return __spreadProps(__spreadValues({}, meta), { params: match.params });
|
|
151
|
+
}
|
|
152
|
+
).sort(
|
|
153
|
+
(meta1, meta2) => (
|
|
154
|
+
// We sort the matched component metas by the number of path params, so
|
|
155
|
+
// if there are two pages `/products/foo` and `/products/[slug]`,
|
|
156
|
+
// the first one will have higher precedence.
|
|
157
|
+
Array.from(Object.keys(meta1.params || {})).length - Array.from(Object.keys(meta2.params || {})).length
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
function getLookupSpecName(lookup) {
|
|
162
|
+
if (typeof lookup === "string") {
|
|
163
|
+
return lookup;
|
|
164
|
+
} else if (lookup.projectId) {
|
|
165
|
+
return `${lookup.name} (project ${lookup.projectId})`;
|
|
166
|
+
} else {
|
|
167
|
+
return lookup.name;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function uniq(elements) {
|
|
171
|
+
return Array.from(new Set(elements));
|
|
172
|
+
}
|
|
173
|
+
function intersect(a, b) {
|
|
174
|
+
const setB = new Set(b);
|
|
175
|
+
return a.filter((elt) => setB.has(elt));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/bundles.ts
|
|
179
|
+
function getUsedComps(allComponents, entryCompIds) {
|
|
180
|
+
const q = [...entryCompIds];
|
|
181
|
+
const seenIds = new Set(entryCompIds);
|
|
182
|
+
const componentMetaById = new Map(
|
|
183
|
+
allComponents.map((meta) => [meta.id, meta])
|
|
184
|
+
);
|
|
185
|
+
const usedComps = [];
|
|
186
|
+
while (q.length > 0) {
|
|
187
|
+
const [id] = q.splice(0, 1);
|
|
188
|
+
const meta = componentMetaById.get(id);
|
|
189
|
+
if (!meta) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
usedComps.push(meta);
|
|
193
|
+
meta.usedComponents.forEach((usedCompId) => {
|
|
194
|
+
if (!seenIds.has(usedCompId)) {
|
|
195
|
+
seenIds.add(usedCompId);
|
|
196
|
+
q.push(usedCompId);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return usedComps;
|
|
201
|
+
}
|
|
202
|
+
function prepComponentData(bundle, compMetas, opts) {
|
|
203
|
+
if (compMetas.length === 0) {
|
|
204
|
+
return {
|
|
205
|
+
entryCompMetas: bundle.components,
|
|
206
|
+
bundle,
|
|
207
|
+
remoteFontUrls: []
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const usedComps = getUsedComps(
|
|
211
|
+
bundle.components,
|
|
212
|
+
compMetas.map((compMeta) => compMeta.id)
|
|
213
|
+
);
|
|
214
|
+
const compPaths = usedComps.map((compMeta) => compMeta.entry);
|
|
215
|
+
const subBundle = getBundleSubset(
|
|
216
|
+
bundle,
|
|
217
|
+
[
|
|
218
|
+
"entrypoint.css",
|
|
219
|
+
...compPaths,
|
|
220
|
+
"root-provider.js",
|
|
221
|
+
...bundle.projects.map((x) => x.styleTokensProviderFileName).filter((x) => !!x),
|
|
222
|
+
...bundle.projects.map((x) => x.globalContextsProviderFileName).filter((x) => !!x),
|
|
223
|
+
// We need to explicitly include global context provider components
|
|
224
|
+
// to make sure they are kept in bundle.components. That's because
|
|
225
|
+
// for esbuild, just the globalContextsProviderFileName is not enough,
|
|
226
|
+
// because it will import a chunk that includes the global context
|
|
227
|
+
// component, instead of importing that global context component's
|
|
228
|
+
// entry file. And because nothing depends on the global context component's
|
|
229
|
+
// entry file, we end up excluding the global context component from
|
|
230
|
+
// bundle.components, which then makes its substitution not work.
|
|
231
|
+
// Instead, we forcibly include it here (we'll definitely need it anyway!).
|
|
232
|
+
...bundle.components.filter((c) => c.isGlobalContextProvider).map((c) => c.entry),
|
|
233
|
+
...bundle.globalGroups.map((g) => g.contextFile)
|
|
234
|
+
],
|
|
235
|
+
opts
|
|
236
|
+
);
|
|
237
|
+
const remoteFontUrls = [];
|
|
238
|
+
subBundle.projects.forEach(
|
|
239
|
+
(p) => remoteFontUrls.push(...p.remoteFonts.map((f) => f.url))
|
|
240
|
+
);
|
|
241
|
+
return {
|
|
242
|
+
entryCompMetas: compMetas,
|
|
243
|
+
bundle: subBundle,
|
|
244
|
+
remoteFontUrls
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function mergeBundles(target, from) {
|
|
248
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
249
|
+
const existingProjects = new Set(target.projects.map((p) => p.id));
|
|
250
|
+
const newProjects = from.projects.filter((p) => !existingProjects.has(p.id));
|
|
251
|
+
if (newProjects.length > 0) {
|
|
252
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
253
|
+
projects: [...target.projects, ...newProjects]
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
const existingCompIds = new Set(target.components.map((c) => c.id));
|
|
257
|
+
function shouldIncludeComponentInBundle(c) {
|
|
258
|
+
var _a3;
|
|
259
|
+
if (existingCompIds.has(c.id)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
if (!existingProjects.has(c.projectId)) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
const targetBundleFilteredIds = (_a3 = target.filteredIds[c.projectId]) != null ? _a3 : [];
|
|
266
|
+
return targetBundleFilteredIds.includes(c.id);
|
|
267
|
+
}
|
|
268
|
+
const newCompMetas = from.components.filter(
|
|
269
|
+
(m) => shouldIncludeComponentInBundle(m)
|
|
270
|
+
);
|
|
271
|
+
if (newCompMetas.length > 0) {
|
|
272
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
273
|
+
components: [...target.components, ...newCompMetas]
|
|
274
|
+
});
|
|
275
|
+
target.filteredIds = Object.fromEntries(
|
|
276
|
+
Object.entries(target.filteredIds).map(([k, v]) => [k, [...v]])
|
|
277
|
+
);
|
|
278
|
+
from.projects.forEach((fromProject) => {
|
|
279
|
+
var _a3, _b2;
|
|
280
|
+
const projectId = fromProject.id;
|
|
281
|
+
const fromBundleFilteredIds = (_a3 = from.filteredIds[projectId]) != null ? _a3 : [];
|
|
282
|
+
if (!existingProjects.has(projectId)) {
|
|
283
|
+
target.filteredIds[projectId] = [...fromBundleFilteredIds];
|
|
284
|
+
} else {
|
|
285
|
+
target.filteredIds[projectId] = intersect(
|
|
286
|
+
(_b2 = target.filteredIds[projectId]) != null ? _b2 : [],
|
|
287
|
+
fromBundleFilteredIds
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
const existingModules = {
|
|
293
|
+
browser: new Set(target.modules.browser.map((m) => m.fileName)),
|
|
294
|
+
server: new Set(target.modules.server.map((m) => m.fileName))
|
|
295
|
+
};
|
|
296
|
+
const newModules = {
|
|
297
|
+
browser: from.modules.browser.filter(
|
|
298
|
+
(m) => !existingModules.browser.has(m.fileName)
|
|
299
|
+
),
|
|
300
|
+
server: from.modules.server.filter(
|
|
301
|
+
(m) => !existingModules.server.has(m.fileName)
|
|
302
|
+
)
|
|
303
|
+
};
|
|
304
|
+
if (newModules.browser.length > 0 || newModules.server.length > 0) {
|
|
305
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
306
|
+
modules: {
|
|
307
|
+
browser: [...target.modules.browser, ...newModules.browser],
|
|
308
|
+
server: [...target.modules.server, ...newModules.server]
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
const existingGlobalIds = new Set(target.globalGroups.map((g) => g.id));
|
|
313
|
+
const newGlobals = from.globalGroups.filter(
|
|
314
|
+
(g) => !existingGlobalIds.has(g.id)
|
|
315
|
+
);
|
|
316
|
+
if (newGlobals.length > 0) {
|
|
317
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
318
|
+
globalGroups: [...target.globalGroups, ...newGlobals]
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
const existingSplitIds = new Set(target.activeSplits.map((s) => s.id));
|
|
322
|
+
const newSplits = (_a2 = from.activeSplits.filter(
|
|
323
|
+
// Don't include splits belonging to projects already present
|
|
324
|
+
// in the target bundle
|
|
325
|
+
(s) => !existingSplitIds.has(s.id) && !existingProjects.has(s.projectId)
|
|
326
|
+
)) != null ? _a2 : [];
|
|
327
|
+
if (newSplits.length > 0) {
|
|
328
|
+
target = __spreadProps(__spreadValues({}, target), {
|
|
329
|
+
activeSplits: [...target.activeSplits, ...newSplits]
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
target.bundleKey = (_c = (_b = target.bundleKey) != null ? _b : from.bundleKey) != null ? _c : null;
|
|
333
|
+
target.deferChunksByDefault = (_e = (_d = target.deferChunksByDefault) != null ? _d : from.deferChunksByDefault) != null ? _e : false;
|
|
334
|
+
target.disableRootLoadingBoundaryByDefault = (_g = (_f = target.disableRootLoadingBoundaryByDefault) != null ? _f : from.disableRootLoadingBoundaryByDefault) != null ? _g : false;
|
|
335
|
+
return target;
|
|
336
|
+
}
|
|
337
|
+
var convertBundlesToComponentRenderData = (bundles, compMetas) => {
|
|
338
|
+
if (bundles.length === 0) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
const mergedBundles = bundles.reduce((prev, cur) => mergeBundles(prev, cur));
|
|
342
|
+
return prepComponentData(mergedBundles, compMetas);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/component-lookup.ts
|
|
346
|
+
function getFirstCompMeta(metas, lookup) {
|
|
347
|
+
const filtered = getCompMetas(metas, lookup);
|
|
348
|
+
return filtered.length === 0 ? void 0 : filtered[0];
|
|
349
|
+
}
|
|
350
|
+
var ComponentLookup = class {
|
|
351
|
+
constructor(bundle, registry) {
|
|
352
|
+
this.bundle = bundle;
|
|
353
|
+
this.registry = registry;
|
|
354
|
+
}
|
|
355
|
+
getComponentMeta(spec) {
|
|
356
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
357
|
+
return compMeta;
|
|
358
|
+
}
|
|
359
|
+
getComponent(spec, opts = {}) {
|
|
360
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
361
|
+
if (!compMeta) {
|
|
362
|
+
throw new Error(`Component not found: ${spec}`);
|
|
363
|
+
}
|
|
364
|
+
const moduleName = compMeta.entry;
|
|
365
|
+
if (!this.registry.hasModule(moduleName, opts)) {
|
|
366
|
+
throw new Error(`Component not yet fetched: ${compMeta.name}`);
|
|
367
|
+
}
|
|
368
|
+
const entry = this.registry.load(moduleName, {
|
|
369
|
+
forceOriginal: opts.forceOriginal
|
|
370
|
+
});
|
|
371
|
+
return !opts.forceOriginal && typeof (entry == null ? void 0 : entry.getDaouyComponent) === "function" ? entry.getDaouyComponent() : entry.default;
|
|
372
|
+
}
|
|
373
|
+
hasComponent(spec) {
|
|
374
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
375
|
+
if (compMeta) {
|
|
376
|
+
return this.registry.hasModule(compMeta.entry);
|
|
377
|
+
}
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
getGlobalContexts() {
|
|
381
|
+
const customGlobalMetas = this.bundle.globalGroups.filter(
|
|
382
|
+
(m) => m.type === "global-user-defined"
|
|
383
|
+
);
|
|
384
|
+
return customGlobalMetas.map((meta) => ({
|
|
385
|
+
meta,
|
|
386
|
+
context: this.registry.load(meta.contextFile).default
|
|
387
|
+
}));
|
|
388
|
+
}
|
|
389
|
+
/** Returns StyleTokensProvider if the project has style token overrides. */
|
|
390
|
+
maybeGetStyleTokensProvider(spec, styleTokenOverridesProjectId) {
|
|
391
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
392
|
+
let projectMeta;
|
|
393
|
+
if (styleTokenOverridesProjectId) {
|
|
394
|
+
projectMeta = this.bundle.projects.find(
|
|
395
|
+
(x) => x.id === styleTokenOverridesProjectId
|
|
396
|
+
);
|
|
397
|
+
if (!projectMeta) {
|
|
398
|
+
console.warn(
|
|
399
|
+
`styleTokenOverridesProjectId "${styleTokenOverridesProjectId}" not found. Defaulting to root component's project.`
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (!projectMeta && (compMeta == null ? void 0 : compMeta.projectId)) {
|
|
404
|
+
projectMeta = this.bundle.projects.find(
|
|
405
|
+
(x) => x.id === compMeta.projectId
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
if (!projectMeta || !projectMeta.styleTokensProviderFileName || !this.registry.hasModule(projectMeta.styleTokensProviderFileName) || !projectMeta.hasStyleTokenOverrides) {
|
|
409
|
+
return void 0;
|
|
410
|
+
}
|
|
411
|
+
const entry = this.registry.load(projectMeta.styleTokensProviderFileName);
|
|
412
|
+
return entry.StyleTokensProvider;
|
|
413
|
+
}
|
|
414
|
+
getGlobalContextsProvider(spec) {
|
|
415
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
416
|
+
const projectMeta = compMeta ? this.bundle.projects.find((x) => x.id === compMeta.projectId) : void 0;
|
|
417
|
+
if (!projectMeta || !projectMeta.globalContextsProviderFileName || !this.registry.hasModule(projectMeta.globalContextsProviderFileName)) {
|
|
418
|
+
return void 0;
|
|
419
|
+
}
|
|
420
|
+
const entry = this.registry.load(
|
|
421
|
+
projectMeta.globalContextsProviderFileName
|
|
422
|
+
);
|
|
423
|
+
return typeof (entry == null ? void 0 : entry.getDaouyComponent) === "function" ? entry.getDaouyComponent() : entry.default;
|
|
424
|
+
}
|
|
425
|
+
getRootProvider() {
|
|
426
|
+
const entry = this.registry.load("root-provider.js");
|
|
427
|
+
return entry.default;
|
|
428
|
+
}
|
|
429
|
+
getCss() {
|
|
430
|
+
return this.bundle.modules.browser.filter(
|
|
431
|
+
(mod) => mod.type === "asset" && mod.fileName.endsWith("css")
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
getRemoteFonts() {
|
|
435
|
+
return this.bundle.projects.flatMap((p) => p.remoteFonts);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/variation.ts
|
|
440
|
+
function getDaouyCookieValues() {
|
|
441
|
+
return Object.fromEntries(
|
|
442
|
+
document.cookie.split("; ").filter((cookie) => cookie.includes("daouy:")).map((cookie) => cookie.split("=")).map(([key, value]) => [key.split(":")[1], value])
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
function updateDaouyCookieValue(key, value) {
|
|
446
|
+
document.cookie = `daouy:${key}=${value}`;
|
|
447
|
+
}
|
|
448
|
+
var getGlobalVariantsFromSplits = (splits, variation) => {
|
|
449
|
+
const globalVariants = [];
|
|
450
|
+
Object.keys(variation).map((variationKey) => {
|
|
451
|
+
const [_type, splitId] = variationKey.split(".");
|
|
452
|
+
const sliceId = variation[variationKey];
|
|
453
|
+
const split = splits.find(
|
|
454
|
+
(s) => s.id === splitId || s.externalId === splitId
|
|
455
|
+
);
|
|
456
|
+
if (split) {
|
|
457
|
+
const slice = split.slices.find((s) => s.id === sliceId || s.externalId === sliceId);
|
|
458
|
+
if (slice) {
|
|
459
|
+
slice.contents.map((x) => {
|
|
460
|
+
globalVariants.push({
|
|
461
|
+
name: x.group,
|
|
462
|
+
value: x.variant,
|
|
463
|
+
projectId: x.projectId
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
return globalVariants;
|
|
470
|
+
};
|
|
471
|
+
var mergeGlobalVariantsSpec = (target, from) => {
|
|
472
|
+
let result = [...target];
|
|
473
|
+
const existingGlobalVariants = new Set(
|
|
474
|
+
target.map((t) => {
|
|
475
|
+
var _a2;
|
|
476
|
+
return `${t.name}-${(_a2 = t.projectId) != null ? _a2 : ""}`;
|
|
477
|
+
})
|
|
478
|
+
);
|
|
479
|
+
const newGlobals = from.filter(
|
|
480
|
+
(t) => {
|
|
481
|
+
var _a2;
|
|
482
|
+
return !existingGlobalVariants.has(`${t.name}-${(_a2 = t.projectId) != null ? _a2 : ""}`);
|
|
483
|
+
}
|
|
484
|
+
);
|
|
485
|
+
if (newGlobals.length > 0) {
|
|
486
|
+
result = [...result, ...newGlobals];
|
|
487
|
+
}
|
|
488
|
+
return result;
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// src/loader-shared.ts
|
|
492
|
+
var SUBSTITUTED_COMPONENTS = {};
|
|
493
|
+
var REGISTERED_CODE_COMPONENT_HELPERS = {};
|
|
494
|
+
var SUBSTITUTED_GLOBAL_VARIANT_HOOKS = {};
|
|
495
|
+
var REGISTERED_CUSTOM_FUNCTIONS = {};
|
|
496
|
+
function customFunctionImportAlias(meta) {
|
|
497
|
+
const customFunctionPrefix = `__fn_`;
|
|
498
|
+
return meta.namespace ? `${customFunctionPrefix}${meta.namespace}__${meta.name}` : `${customFunctionPrefix}${meta.name}`;
|
|
499
|
+
}
|
|
500
|
+
function internalSetRegisteredFunction(fn, meta) {
|
|
501
|
+
REGISTERED_CUSTOM_FUNCTIONS[customFunctionImportAlias(meta)] = fn;
|
|
502
|
+
}
|
|
503
|
+
function parseFetchComponentDataArgs(...args) {
|
|
504
|
+
let specs;
|
|
505
|
+
let opts;
|
|
506
|
+
if (Array.isArray(args[0])) {
|
|
507
|
+
specs = args[0];
|
|
508
|
+
opts = args[1];
|
|
509
|
+
} else {
|
|
510
|
+
specs = args;
|
|
511
|
+
opts = void 0;
|
|
512
|
+
}
|
|
513
|
+
return { specs, opts };
|
|
514
|
+
}
|
|
515
|
+
var BaseInternalDaouyComponentLoader = class {
|
|
516
|
+
constructor(args) {
|
|
517
|
+
this.registry = new Registry();
|
|
518
|
+
this.globalVariants = [];
|
|
519
|
+
this.subs = [];
|
|
520
|
+
this.bundle = {
|
|
521
|
+
modules: {
|
|
522
|
+
browser: [],
|
|
523
|
+
server: []
|
|
524
|
+
},
|
|
525
|
+
components: [],
|
|
526
|
+
globalGroups: [],
|
|
527
|
+
projects: [],
|
|
528
|
+
activeSplits: [],
|
|
529
|
+
bundleKey: null,
|
|
530
|
+
deferChunksByDefault: false,
|
|
531
|
+
disableRootLoadingBoundaryByDefault: false,
|
|
532
|
+
filteredIds: {}
|
|
533
|
+
};
|
|
534
|
+
this.opts = args.opts;
|
|
535
|
+
this.fetcher = args.fetcher;
|
|
536
|
+
this.onBundleMerged = args.onBundleMerged;
|
|
537
|
+
this.onBundleFetched = args.onBundleFetched;
|
|
538
|
+
this.registerModules(args.builtinModules);
|
|
539
|
+
}
|
|
540
|
+
maybeGetCompMetas(...specs) {
|
|
541
|
+
const found = /* @__PURE__ */ new Set();
|
|
542
|
+
const missing = [];
|
|
543
|
+
for (const spec of specs) {
|
|
544
|
+
const filteredMetas = getCompMetas(this.bundle.components, spec);
|
|
545
|
+
if (filteredMetas.length > 0) {
|
|
546
|
+
filteredMetas.forEach((meta) => found.add(meta));
|
|
547
|
+
} else {
|
|
548
|
+
missing.push(spec);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return { found: Array.from(found.keys()), missing };
|
|
552
|
+
}
|
|
553
|
+
maybeFetchComponentData(...args) {
|
|
554
|
+
return __async(this, null, function* () {
|
|
555
|
+
const { specs, opts } = parseFetchComponentDataArgs(...args);
|
|
556
|
+
const returnWithSpecsToFetch = (specsToFetch) => __async(this, null, function* () {
|
|
557
|
+
yield this.fetchMissingData({ missingSpecs: specsToFetch });
|
|
558
|
+
const { found: existingMetas2, missing: missingSpecs2 } = this.maybeGetCompMetas(...specs);
|
|
559
|
+
if (missingSpecs2.length > 0) {
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
return prepComponentData(this.bundle, existingMetas2, opts);
|
|
563
|
+
});
|
|
564
|
+
if (this.opts.alwaysFresh) {
|
|
565
|
+
return yield returnWithSpecsToFetch(specs);
|
|
566
|
+
}
|
|
567
|
+
const { found: existingMetas, missing: missingSpecs } = this.maybeGetCompMetas(...specs);
|
|
568
|
+
if (missingSpecs.length === 0) {
|
|
569
|
+
return prepComponentData(this.bundle, existingMetas, opts);
|
|
570
|
+
}
|
|
571
|
+
return yield returnWithSpecsToFetch(missingSpecs);
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
fetchComponentData(...args) {
|
|
575
|
+
return __async(this, null, function* () {
|
|
576
|
+
const { specs, opts } = parseFetchComponentDataArgs(...args);
|
|
577
|
+
const data = yield this.maybeFetchComponentData(specs, opts);
|
|
578
|
+
if (!data) {
|
|
579
|
+
const { missing: missingSpecs } = this.maybeGetCompMetas(...specs);
|
|
580
|
+
throw new Error(
|
|
581
|
+
`Unable to find components ${missingSpecs.map(getLookupSpecName).join(", ")}`
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
return data;
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
fetchPages(opts) {
|
|
588
|
+
return __async(this, null, function* () {
|
|
589
|
+
this.maybeReportClientSideFetch(
|
|
590
|
+
() => `Daouy: fetching all page metadata in the browser`
|
|
591
|
+
);
|
|
592
|
+
const data = yield this.fetchAllData();
|
|
593
|
+
return data.components.filter(
|
|
594
|
+
(comp) => comp.isPage && comp.path && ((opts == null ? void 0 : opts.includeDynamicPages) || !isDynamicPagePath(comp.path))
|
|
595
|
+
);
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
fetchComponents() {
|
|
599
|
+
return __async(this, null, function* () {
|
|
600
|
+
this.maybeReportClientSideFetch(
|
|
601
|
+
() => `Daouy: fetching all component metadata in the browser`
|
|
602
|
+
);
|
|
603
|
+
const data = yield this.fetchAllData();
|
|
604
|
+
return data.components;
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
getActiveSplits() {
|
|
608
|
+
return this.bundle.activeSplits;
|
|
609
|
+
}
|
|
610
|
+
getChunksUrl(bundle, modules) {
|
|
611
|
+
return this.fetcher.getChunksUrl(bundle, modules);
|
|
612
|
+
}
|
|
613
|
+
fetchMissingData(opts) {
|
|
614
|
+
return __async(this, null, function* () {
|
|
615
|
+
this.maybeReportClientSideFetch(
|
|
616
|
+
() => `Daouy: fetching missing components in the browser: ${opts.missingSpecs.map((spec) => getLookupSpecName(spec)).join(", ")}`
|
|
617
|
+
);
|
|
618
|
+
return this.fetchAllData();
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
maybeReportClientSideFetch(mkMsg) {
|
|
622
|
+
if (isBrowser && this.opts.onClientSideFetch) {
|
|
623
|
+
const msg = mkMsg();
|
|
624
|
+
if (this.opts.onClientSideFetch === "warn") {
|
|
625
|
+
console.warn(msg);
|
|
626
|
+
} else {
|
|
627
|
+
throw new Error(msg);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
fetchAllData() {
|
|
632
|
+
return __async(this, null, function* () {
|
|
633
|
+
var _a2;
|
|
634
|
+
const bundle = yield this.fetcher.fetchAllData();
|
|
635
|
+
this.mergeBundle(bundle);
|
|
636
|
+
(_a2 = this.onBundleFetched) == null ? void 0 : _a2.call(this);
|
|
637
|
+
return bundle;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
mergeBundle(newBundle) {
|
|
641
|
+
var _a2, _b;
|
|
642
|
+
newBundle.bundleKey = (_a2 = newBundle.bundleKey) != null ? _a2 : null;
|
|
643
|
+
if (newBundle.bundleKey && this.bundle.bundleKey && newBundle.bundleKey !== this.bundle.bundleKey) {
|
|
644
|
+
console.warn(
|
|
645
|
+
`Daouy Error: Different code export hashes. This can happen if your app is using different loaders with different project IDs or project versions.
|
|
646
|
+
Conflicting values:
|
|
647
|
+
${newBundle.bundleKey}
|
|
648
|
+
${this.bundle.bundleKey}`
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
this.bundle = mergeBundles(newBundle, this.bundle);
|
|
652
|
+
(_b = this.onBundleMerged) == null ? void 0 : _b.call(this);
|
|
653
|
+
}
|
|
654
|
+
getBundle() {
|
|
655
|
+
return this.bundle;
|
|
656
|
+
}
|
|
657
|
+
clearCache() {
|
|
658
|
+
this.bundle = {
|
|
659
|
+
modules: {
|
|
660
|
+
browser: [],
|
|
661
|
+
server: []
|
|
662
|
+
},
|
|
663
|
+
components: [],
|
|
664
|
+
globalGroups: [],
|
|
665
|
+
projects: [],
|
|
666
|
+
activeSplits: [],
|
|
667
|
+
bundleKey: null,
|
|
668
|
+
deferChunksByDefault: false,
|
|
669
|
+
disableRootLoadingBoundaryByDefault: false,
|
|
670
|
+
filteredIds: {}
|
|
671
|
+
};
|
|
672
|
+
this.registry.clear();
|
|
673
|
+
}
|
|
674
|
+
registerModules(modules) {
|
|
675
|
+
if (Object.keys(modules).some(
|
|
676
|
+
(name) => this.registry.getRegisteredModule(name) !== modules[name]
|
|
677
|
+
)) {
|
|
678
|
+
if (!this.registry.isEmpty()) {
|
|
679
|
+
console.warn(
|
|
680
|
+
"Calling DaouyComponentLoader.registerModules() after Daouy component has rendered; starting over."
|
|
681
|
+
);
|
|
682
|
+
this.registry.clear();
|
|
683
|
+
}
|
|
684
|
+
for (const key of Object.keys(modules)) {
|
|
685
|
+
this.registry.register(key, modules[key]);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
substituteComponent(component, name) {
|
|
690
|
+
this.internalSubstituteComponent(component, name, void 0);
|
|
691
|
+
}
|
|
692
|
+
internalSubstituteComponent(component, name, codeComponentHelpers) {
|
|
693
|
+
if (!this.isRegistryEmpty()) {
|
|
694
|
+
console.warn(
|
|
695
|
+
"Calling DaouyComponentLoader.registerSubstitution() after Daouy component has rendered; starting over."
|
|
696
|
+
);
|
|
697
|
+
this.clearRegistry();
|
|
698
|
+
}
|
|
699
|
+
this.subs.push({ lookup: name, component, codeComponentHelpers });
|
|
700
|
+
}
|
|
701
|
+
refreshRegistry() {
|
|
702
|
+
for (const sub of this.subs) {
|
|
703
|
+
const metas = getCompMetas(this.getBundle().components, sub.lookup);
|
|
704
|
+
metas.forEach((meta) => {
|
|
705
|
+
SUBSTITUTED_COMPONENTS[meta.id] = sub.component;
|
|
706
|
+
if (sub.codeComponentHelpers) {
|
|
707
|
+
REGISTERED_CODE_COMPONENT_HELPERS[meta.id] = sub.codeComponentHelpers;
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
this.registry.updateModules(this.getBundle());
|
|
712
|
+
}
|
|
713
|
+
isRegistryEmpty() {
|
|
714
|
+
return this.registry.isEmpty();
|
|
715
|
+
}
|
|
716
|
+
clearRegistry() {
|
|
717
|
+
this.registry.clear();
|
|
718
|
+
}
|
|
719
|
+
setGlobalVariants(globalVariants) {
|
|
720
|
+
this.globalVariants = globalVariants;
|
|
721
|
+
}
|
|
722
|
+
getGlobalVariants() {
|
|
723
|
+
return this.globalVariants;
|
|
724
|
+
}
|
|
725
|
+
registerPrefetchedBundle(bundle) {
|
|
726
|
+
if (!isBrowser) {
|
|
727
|
+
const cachedBundle = internal_getCachedBundleInNodeServer(this.opts);
|
|
728
|
+
if (cachedBundle) {
|
|
729
|
+
this.mergeBundle(cachedBundle);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
this.mergeBundle(bundle);
|
|
733
|
+
}
|
|
734
|
+
getLookup() {
|
|
735
|
+
return new ComponentLookup(this.getBundle(), this.registry);
|
|
736
|
+
}
|
|
737
|
+
trackConversion(_value = 0) {
|
|
738
|
+
}
|
|
739
|
+
getActiveVariation(opts) {
|
|
740
|
+
return __async(this, null, function* () {
|
|
741
|
+
yield this.fetchComponents();
|
|
742
|
+
return getActiveVariation(__spreadProps(__spreadValues({}, opts), {
|
|
743
|
+
splits: this.getBundle().activeSplits
|
|
744
|
+
}));
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
getTeamIds() {
|
|
748
|
+
return uniq(
|
|
749
|
+
this.getBundle().projects.map(
|
|
750
|
+
(p) => p.teamId ? `${p.teamId}${p.indirect ? "@indirect" : ""}` : null
|
|
751
|
+
).filter((x) => !!x)
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
getProjectIds() {
|
|
755
|
+
return uniq(
|
|
756
|
+
this.getBundle().projects.map(
|
|
757
|
+
(p) => `${p.id}${p.indirect ? "@indirect" : ""}`
|
|
758
|
+
)
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
trackRender(_opts) {
|
|
762
|
+
}
|
|
763
|
+
loadServerQueriesModule(fileName) {
|
|
764
|
+
return this.registry.load(fileName);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
var DaouyComponentLoader = class {
|
|
768
|
+
constructor(internal) {
|
|
769
|
+
this.warnedRegisterComponent = false;
|
|
770
|
+
this.__internal = internal;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Sets global variants to be used for all components. Note that
|
|
774
|
+
* this is not reactive, and will not re-render all components
|
|
775
|
+
* already mounted; instead, it should be used to activate global
|
|
776
|
+
* variants that should always be activated for the lifetime of this
|
|
777
|
+
* app. If you'd like to reactively change the global variants,
|
|
778
|
+
* you should specify them via <DaouyRootProvider />
|
|
779
|
+
*/
|
|
780
|
+
setGlobalVariants(globalVariants) {
|
|
781
|
+
this.__internal.setGlobalVariants(globalVariants);
|
|
782
|
+
}
|
|
783
|
+
registerModules(modules) {
|
|
784
|
+
this.__internal.registerModules(modules);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Register custom components that should be swapped in for
|
|
788
|
+
* components defined in your project. You can use this to
|
|
789
|
+
* swap in / substitute a Daouy component with a "real" component.
|
|
790
|
+
*/
|
|
791
|
+
substituteComponent(component, name) {
|
|
792
|
+
this.__internal.substituteComponent(component, name);
|
|
793
|
+
}
|
|
794
|
+
registerComponent(component, metaOrName) {
|
|
795
|
+
if (metaOrName && typeof metaOrName === "object" && "props" in metaOrName) {
|
|
796
|
+
this.__internal.registerComponent(component, metaOrName);
|
|
797
|
+
} else {
|
|
798
|
+
if (process.env.NODE_ENV === "development" && !this.warnedRegisterComponent) {
|
|
799
|
+
console.warn(
|
|
800
|
+
`DaouyLoader: Using deprecated method \`registerComponent\` for component substitution. Please consider using \`substituteComponent\` instead.`
|
|
801
|
+
);
|
|
802
|
+
this.warnedRegisterComponent = true;
|
|
803
|
+
}
|
|
804
|
+
this.substituteComponent(component, metaOrName);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
registerFunction(fn, meta) {
|
|
808
|
+
this.__internal.registerFunction(fn, meta);
|
|
809
|
+
}
|
|
810
|
+
registerGlobalContext(context, meta) {
|
|
811
|
+
this.__internal.registerGlobalContext(context, meta);
|
|
812
|
+
}
|
|
813
|
+
registerTrait(trait, meta) {
|
|
814
|
+
this.__internal.registerTrait(trait, meta);
|
|
815
|
+
}
|
|
816
|
+
registerToken(token) {
|
|
817
|
+
this.__internal.registerToken(token);
|
|
818
|
+
}
|
|
819
|
+
fetchComponentData(...args) {
|
|
820
|
+
return this.__internal.fetchComponentData(...args);
|
|
821
|
+
}
|
|
822
|
+
maybeFetchComponentData(...args) {
|
|
823
|
+
return __async(this, null, function* () {
|
|
824
|
+
return this.__internal.maybeFetchComponentData(...args);
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Returns all the page component metadata for these projects.
|
|
829
|
+
*/
|
|
830
|
+
fetchPages(opts) {
|
|
831
|
+
return __async(this, null, function* () {
|
|
832
|
+
return this.__internal.fetchPages(opts);
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Returns all components metadata for these projects.
|
|
837
|
+
*/
|
|
838
|
+
fetchComponents() {
|
|
839
|
+
return __async(this, null, function* () {
|
|
840
|
+
return this.__internal.fetchComponents();
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
_getActiveVariation(opts) {
|
|
844
|
+
return __async(this, null, function* () {
|
|
845
|
+
return this.__internal.getActiveVariation(opts);
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
getActiveVariation(opts) {
|
|
849
|
+
return __async(this, null, function* () {
|
|
850
|
+
return this._getActiveVariation({
|
|
851
|
+
traits: opts.traits,
|
|
852
|
+
getKnownValue: (key) => {
|
|
853
|
+
if (opts.known) {
|
|
854
|
+
return opts.known[key];
|
|
855
|
+
} else {
|
|
856
|
+
const cookies = getDaouyCookieValues();
|
|
857
|
+
return cookies[key];
|
|
858
|
+
}
|
|
859
|
+
},
|
|
860
|
+
updateKnownValue: (key, value) => {
|
|
861
|
+
if (!opts.known) {
|
|
862
|
+
updateDaouyCookieValue(key, value);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
getChunksUrl(bundle, modules) {
|
|
869
|
+
return this.__internal.getChunksUrl(bundle, modules);
|
|
870
|
+
}
|
|
871
|
+
getExternalVariation(variation, filters) {
|
|
872
|
+
return getExternalIds(this.getActiveSplits(), variation, filters);
|
|
873
|
+
}
|
|
874
|
+
getActiveSplits() {
|
|
875
|
+
return this.__internal.getActiveSplits();
|
|
876
|
+
}
|
|
877
|
+
trackConversion(value = 0) {
|
|
878
|
+
this.__internal.trackConversion(value);
|
|
879
|
+
}
|
|
880
|
+
clearCache() {
|
|
881
|
+
return this.__internal.clearCache();
|
|
882
|
+
}
|
|
883
|
+
getExecFuncModule(renderData, fileNameKey) {
|
|
884
|
+
if (renderData.entryCompMetas.length === 0) {
|
|
885
|
+
return void 0;
|
|
886
|
+
}
|
|
887
|
+
const fileName = renderData.entryCompMetas[0][fileNameKey];
|
|
888
|
+
if (!fileName) {
|
|
889
|
+
return void 0;
|
|
890
|
+
}
|
|
891
|
+
return this.__internal.loadServerQueriesModule(fileName);
|
|
892
|
+
}
|
|
893
|
+
unstable__getServerQueriesData(renderData, $ctx) {
|
|
894
|
+
return __async(this, null, function* () {
|
|
895
|
+
const module = this.getExecFuncModule(
|
|
896
|
+
renderData,
|
|
897
|
+
"serverQueriesExecFuncFileName"
|
|
898
|
+
);
|
|
899
|
+
try {
|
|
900
|
+
const $serverQueries = yield module == null ? void 0 : module.executeServerQueries($ctx);
|
|
901
|
+
return $serverQueries;
|
|
902
|
+
} catch (err) {
|
|
903
|
+
console.error("Error executing server queries function", err);
|
|
904
|
+
return {};
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
unstable__generateMetadata(renderData, props) {
|
|
909
|
+
return __async(this, null, function* () {
|
|
910
|
+
var _a2;
|
|
911
|
+
const module = this.getExecFuncModule(
|
|
912
|
+
renderData,
|
|
913
|
+
"generateMetadataFuncFileName"
|
|
914
|
+
);
|
|
915
|
+
const fallback = ((_a2 = renderData.entryCompMetas[0]) == null ? void 0 : _a2.pageMetadata) || {};
|
|
916
|
+
if (!module) {
|
|
917
|
+
return fallback;
|
|
918
|
+
}
|
|
919
|
+
try {
|
|
920
|
+
const metadata = yield module.generateMetadata(props);
|
|
921
|
+
return metadata;
|
|
922
|
+
} catch (err) {
|
|
923
|
+
return fallback;
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
// src/swr-util.ts
|
|
930
|
+
function swrSerialize(key) {
|
|
931
|
+
if (typeof key === "function") {
|
|
932
|
+
try {
|
|
933
|
+
key = key();
|
|
934
|
+
} catch (err) {
|
|
935
|
+
key = "";
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
const args = [].concat(key);
|
|
939
|
+
key = typeof key == "string" ? key : (Array.isArray(key) ? key.length : key) ? stableHash(key) : "";
|
|
940
|
+
return [key, args];
|
|
941
|
+
}
|
|
942
|
+
var table = /* @__PURE__ */ new WeakMap();
|
|
943
|
+
var counter = 0;
|
|
944
|
+
function stableHash(arg) {
|
|
945
|
+
const type = typeof arg;
|
|
946
|
+
const constructor = arg && arg.constructor;
|
|
947
|
+
const isDate = constructor == Date;
|
|
948
|
+
let result;
|
|
949
|
+
let index;
|
|
950
|
+
if (Object(arg) === arg && !isDate && constructor != RegExp) {
|
|
951
|
+
result = table.get(arg);
|
|
952
|
+
if (result)
|
|
953
|
+
return result;
|
|
954
|
+
result = ++counter + "~";
|
|
955
|
+
table.set(arg, result);
|
|
956
|
+
if (constructor == Array) {
|
|
957
|
+
result = "@";
|
|
958
|
+
for (index = 0; index < arg.length; index++) {
|
|
959
|
+
result += stableHash(arg[index]) + ",";
|
|
960
|
+
}
|
|
961
|
+
table.set(arg, result);
|
|
962
|
+
}
|
|
963
|
+
if (constructor == Object) {
|
|
964
|
+
result = "#";
|
|
965
|
+
const keys = Object.keys(arg).sort();
|
|
966
|
+
while ((index = keys.pop()) !== void 0) {
|
|
967
|
+
if (arg[index] !== void 0) {
|
|
968
|
+
result += index + ":" + stableHash(arg[index]) + ",";
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
table.set(arg, result);
|
|
972
|
+
}
|
|
973
|
+
} else {
|
|
974
|
+
result = isDate ? arg.toJSON() : type == "symbol" ? arg.toString() : type == "string" ? JSON.stringify(arg) : "" + arg;
|
|
975
|
+
}
|
|
976
|
+
return result;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// src/loader-server.tsx
|
|
980
|
+
var noop = () => {
|
|
981
|
+
};
|
|
982
|
+
var identity = (x) => x;
|
|
983
|
+
var unreachable = () => {
|
|
984
|
+
debugger;
|
|
985
|
+
throw new Error("Unreachable code");
|
|
986
|
+
};
|
|
987
|
+
var REACT_PROVIDER_TYPE = typeof Symbol === "function" && Symbol.for ? Symbol.for("react.provider") : 60109;
|
|
988
|
+
var FakeRootProviderContext = {
|
|
989
|
+
_currentValue: void 0
|
|
990
|
+
// default value
|
|
991
|
+
};
|
|
992
|
+
var FakeDataContext = {
|
|
993
|
+
_currentValue: void 0
|
|
994
|
+
// default value
|
|
995
|
+
};
|
|
996
|
+
var FakeDaouyComponentContext = {
|
|
997
|
+
_currentValue: false
|
|
998
|
+
// default value
|
|
999
|
+
};
|
|
1000
|
+
var FakeDaouyPrepassContext = {
|
|
1001
|
+
_currentValue: void 0
|
|
1002
|
+
};
|
|
1003
|
+
var mkMetaName = (name) => `__daouy_meta_${name}`;
|
|
1004
|
+
function FakeDataCtxReader({ children }) {
|
|
1005
|
+
const $ctx = getPrepassContextEnv().readContextValue(FakeDataContext);
|
|
1006
|
+
return children($ctx);
|
|
1007
|
+
}
|
|
1008
|
+
function FakeDataProvider({
|
|
1009
|
+
name,
|
|
1010
|
+
data,
|
|
1011
|
+
hidden,
|
|
1012
|
+
advanced,
|
|
1013
|
+
label,
|
|
1014
|
+
children
|
|
1015
|
+
}) {
|
|
1016
|
+
var _a2;
|
|
1017
|
+
const { readContextValue, setContextValue } = getPrepassContextEnv();
|
|
1018
|
+
const existingEnv = (_a2 = readContextValue(FakeDataContext)) != null ? _a2 : {};
|
|
1019
|
+
if (!name) {
|
|
1020
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, children);
|
|
1021
|
+
} else {
|
|
1022
|
+
setContextValue(FakeDataContext, __spreadProps(__spreadValues({}, existingEnv), {
|
|
1023
|
+
[name]: data,
|
|
1024
|
+
[mkMetaName(name)]: { hidden, advanced, label }
|
|
1025
|
+
}));
|
|
1026
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, children);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
var fakeApplySelector = (rawData, selector) => {
|
|
1030
|
+
if (!selector) {
|
|
1031
|
+
return void 0;
|
|
1032
|
+
}
|
|
1033
|
+
let curData = rawData;
|
|
1034
|
+
for (const key of selector.split(".")) {
|
|
1035
|
+
curData = curData == null ? void 0 : curData[key];
|
|
1036
|
+
}
|
|
1037
|
+
return curData;
|
|
1038
|
+
};
|
|
1039
|
+
function fakeUseSelector(selector) {
|
|
1040
|
+
const rawData = getPrepassContextEnv().readContextValue(FakeDataContext);
|
|
1041
|
+
return fakeApplySelector(rawData, selector);
|
|
1042
|
+
}
|
|
1043
|
+
function fakeUseSelectors(selectors = {}) {
|
|
1044
|
+
const rawData = getPrepassContextEnv().readContextValue(FakeDataContext);
|
|
1045
|
+
return Object.fromEntries(
|
|
1046
|
+
Object.entries(selectors).filter(([key, selector]) => !!key && !!selector).map(([key, selector]) => [
|
|
1047
|
+
key,
|
|
1048
|
+
fakeApplySelector(rawData, selector)
|
|
1049
|
+
])
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
function fakeUseDaouyDataConfig() {
|
|
1053
|
+
const cache = getPrepassContextEnv().readContextValue(
|
|
1054
|
+
FakeDaouyPrepassContext
|
|
1055
|
+
);
|
|
1056
|
+
return { cache };
|
|
1057
|
+
}
|
|
1058
|
+
var fakeUseMutableDaouyQueryData = (unserializedKey, fetcher) => {
|
|
1059
|
+
const [key, args] = swrSerialize(unserializedKey);
|
|
1060
|
+
if (!key) {
|
|
1061
|
+
return {
|
|
1062
|
+
isValidating: false,
|
|
1063
|
+
mutate: () => __async(void 0, null, function* () {
|
|
1064
|
+
}),
|
|
1065
|
+
data: void 0
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
const cache = fakeUseDaouyDataConfig().cache;
|
|
1069
|
+
if (cache.has(key)) {
|
|
1070
|
+
return {
|
|
1071
|
+
isValidating: false,
|
|
1072
|
+
mutate: () => __async(void 0, null, function* () {
|
|
1073
|
+
}),
|
|
1074
|
+
data: cache.get(key)
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
const response = fetcher(...args);
|
|
1078
|
+
if (response && typeof response.then == "function") {
|
|
1079
|
+
throw response.then((data) => cache.set(key, data));
|
|
1080
|
+
} else {
|
|
1081
|
+
cache.set(key, response);
|
|
1082
|
+
return {
|
|
1083
|
+
isValidating: false,
|
|
1084
|
+
mutate: () => __async(void 0, null, function* () {
|
|
1085
|
+
}),
|
|
1086
|
+
data: cache.get(key)
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
var _a;
|
|
1091
|
+
var FakeReactComponent = (_a = class {
|
|
1092
|
+
constructor() {
|
|
1093
|
+
this.context = void 0;
|
|
1094
|
+
this.props = {};
|
|
1095
|
+
this.setState = (v) => void (this.state = v);
|
|
1096
|
+
this.forceUpdate = noop;
|
|
1097
|
+
this.render = () => null;
|
|
1098
|
+
this.state = {};
|
|
1099
|
+
this.refs = {};
|
|
1100
|
+
}
|
|
1101
|
+
initRender(props) {
|
|
1102
|
+
this.props = props;
|
|
1103
|
+
const dispatcher = React2.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
|
|
1104
|
+
const [state, setState] = dispatcher.useState({});
|
|
1105
|
+
this.state = state;
|
|
1106
|
+
this.setState = setState;
|
|
1107
|
+
if (this.constructor.contextType) {
|
|
1108
|
+
this.context = dispatcher.useContext(
|
|
1109
|
+
this.constructor.contextType
|
|
1110
|
+
);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}, _a.contextType = void 0, _a);
|
|
1114
|
+
var fakeCreateElement = (originalCreateElement) => (type, ...args) => {
|
|
1115
|
+
if (Object.prototype.isPrototypeOf.call(FakeReactComponent, type)) {
|
|
1116
|
+
return originalCreateElement((props) => {
|
|
1117
|
+
const instance = new type();
|
|
1118
|
+
instance.initRender(props);
|
|
1119
|
+
return instance.render();
|
|
1120
|
+
}, ...args);
|
|
1121
|
+
}
|
|
1122
|
+
return originalCreateElement(type, ...args);
|
|
1123
|
+
};
|
|
1124
|
+
var InternalPrepassDaouyLoader = class extends BaseInternalDaouyComponentLoader {
|
|
1125
|
+
constructor(opts) {
|
|
1126
|
+
super({
|
|
1127
|
+
opts,
|
|
1128
|
+
onBundleMerged: () => {
|
|
1129
|
+
this.refreshRegistry();
|
|
1130
|
+
},
|
|
1131
|
+
fetcher: new DaouyModulesFetcher2(opts),
|
|
1132
|
+
builtinModules: {
|
|
1133
|
+
react: __spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues({}, React2), { isRSC: true }), {
|
|
1134
|
+
createContext: (defaultValue) => {
|
|
1135
|
+
const context = {
|
|
1136
|
+
_currentValue: defaultValue,
|
|
1137
|
+
displayName: "FakeContext",
|
|
1138
|
+
Provider: ({ value, children }) => {
|
|
1139
|
+
getPrepassContextEnv().setContextValue(context, value);
|
|
1140
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, children);
|
|
1141
|
+
},
|
|
1142
|
+
Consumer: ({ children }) => children(getPrepassContextEnv().readContextValue(context))
|
|
1143
|
+
};
|
|
1144
|
+
return context;
|
|
1145
|
+
}
|
|
1146
|
+
}), Object.fromEntries(
|
|
1147
|
+
[
|
|
1148
|
+
"useCallback",
|
|
1149
|
+
"useContext",
|
|
1150
|
+
"useEffect",
|
|
1151
|
+
"useImperativeHandle",
|
|
1152
|
+
"useDebugValue",
|
|
1153
|
+
"useInsertionEffect",
|
|
1154
|
+
"useLayoutEffect",
|
|
1155
|
+
"useMemo",
|
|
1156
|
+
"useSyncExternalStore",
|
|
1157
|
+
"useReducer",
|
|
1158
|
+
"useRef",
|
|
1159
|
+
"useState"
|
|
1160
|
+
].map((hook) => [
|
|
1161
|
+
hook,
|
|
1162
|
+
(...args) => {
|
|
1163
|
+
const dispatcher = React2.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
|
|
1164
|
+
return dispatcher[hook](...args);
|
|
1165
|
+
}
|
|
1166
|
+
])
|
|
1167
|
+
)), {
|
|
1168
|
+
useDeferredValue: (v) => v,
|
|
1169
|
+
useTransition: () => [
|
|
1170
|
+
false,
|
|
1171
|
+
(f) => {
|
|
1172
|
+
f();
|
|
1173
|
+
}
|
|
1174
|
+
],
|
|
1175
|
+
createFactory: (type) => React2.createElement.bind(null, type),
|
|
1176
|
+
Component: FakeReactComponent,
|
|
1177
|
+
PureComponent: FakeReactComponent,
|
|
1178
|
+
createElement: fakeCreateElement(React2.createElement)
|
|
1179
|
+
}),
|
|
1180
|
+
"react-dom": ReactDOM,
|
|
1181
|
+
"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) } : {}),
|
|
1182
|
+
"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) } : {}),
|
|
1183
|
+
"@daouy/query": {
|
|
1184
|
+
addLoadingStateListener: () => noop,
|
|
1185
|
+
isDaouyPrepass: () => true,
|
|
1186
|
+
DaouyPrepassContext: {},
|
|
1187
|
+
DaouyQueryDataProvider: ({ children }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, children),
|
|
1188
|
+
useMutableDaouyQueryData: fakeUseMutableDaouyQueryData,
|
|
1189
|
+
useDaouyDataConfig: fakeUseDaouyDataConfig,
|
|
1190
|
+
useDaouyQueryData: fakeUseMutableDaouyQueryData,
|
|
1191
|
+
useSWRConfig: unreachable,
|
|
1192
|
+
wrapLoadingFetcher: identity,
|
|
1193
|
+
HeadMetadataContext: {
|
|
1194
|
+
_currentValue: {},
|
|
1195
|
+
displayName: "FakeHeadMetadataContext",
|
|
1196
|
+
Provider: ({ children }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, children),
|
|
1197
|
+
Consumer: ({ children }) => children({})
|
|
1198
|
+
}
|
|
1199
|
+
},
|
|
1200
|
+
"@daouy/data-sources-context": (() => {
|
|
1201
|
+
const FakeDaouyDataSourceContext = {
|
|
1202
|
+
_currentValue: void 0
|
|
1203
|
+
// default value
|
|
1204
|
+
};
|
|
1205
|
+
return {
|
|
1206
|
+
DaouyDataSourceContextProvider: Object.assign(
|
|
1207
|
+
({ children, value }) => {
|
|
1208
|
+
const { setContextValue } = getPrepassContextEnv();
|
|
1209
|
+
setContextValue(FakeDaouyDataSourceContext, value);
|
|
1210
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, children);
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
$$typeof: REACT_PROVIDER_TYPE,
|
|
1214
|
+
_context: FakeDaouyDataSourceContext
|
|
1215
|
+
}
|
|
1216
|
+
),
|
|
1217
|
+
useCurrentUser: () => {
|
|
1218
|
+
var _a2;
|
|
1219
|
+
const { readContextValue } = getPrepassContextEnv();
|
|
1220
|
+
const ctx = readContextValue(FakeDaouyDataSourceContext);
|
|
1221
|
+
return (_a2 = ctx == null ? void 0 : ctx.user) != null ? _a2 : {
|
|
1222
|
+
isLoggedIn: false
|
|
1223
|
+
};
|
|
1224
|
+
},
|
|
1225
|
+
useDaouyDataSourceContext: () => {
|
|
1226
|
+
const { readContextValue } = getPrepassContextEnv();
|
|
1227
|
+
return readContextValue(FakeDaouyDataSourceContext);
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
})(),
|
|
1231
|
+
"@daouy/host": (() => {
|
|
1232
|
+
return {
|
|
1233
|
+
applySelector: fakeApplySelector,
|
|
1234
|
+
DataContext: FakeDataContext,
|
|
1235
|
+
DataCtxReader: FakeDataCtxReader,
|
|
1236
|
+
DataProvider: FakeDataProvider,
|
|
1237
|
+
GlobalActionsContext: {
|
|
1238
|
+
_currentValue: void 0
|
|
1239
|
+
// default value
|
|
1240
|
+
},
|
|
1241
|
+
GlobalActionsProvider: ({ children }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, children),
|
|
1242
|
+
mkMetaName,
|
|
1243
|
+
mkMetaValue: identity,
|
|
1244
|
+
PageParamsProvider: ({ children }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, children),
|
|
1245
|
+
DaouyCanvasContext: { _currentValue: false },
|
|
1246
|
+
DaouyCanvasHost: () => null,
|
|
1247
|
+
DaouyLinkProvider: ({ children }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, children),
|
|
1248
|
+
registerComponent: noop,
|
|
1249
|
+
registerFunction: noop,
|
|
1250
|
+
registerGlobalContext: noop,
|
|
1251
|
+
registerToken: noop,
|
|
1252
|
+
registerTrait: noop,
|
|
1253
|
+
repeatedElement: unreachable,
|
|
1254
|
+
stateHelpersKeys: ["initFunc", "onChangeArgsToValue", "onMutate"],
|
|
1255
|
+
unstable_registerFetcher: noop,
|
|
1256
|
+
useDataEnv: () => getPrepassContextEnv().readContextValue(FakeDataContext),
|
|
1257
|
+
useGlobalActions: () => new Proxy(
|
|
1258
|
+
{},
|
|
1259
|
+
{
|
|
1260
|
+
get: () => noop
|
|
1261
|
+
}
|
|
1262
|
+
),
|
|
1263
|
+
useDaouyTranslator: () => void 0,
|
|
1264
|
+
DaouyTranslatorContext: { _currentValue: void 0 },
|
|
1265
|
+
useDaouyCanvasContext: () => false,
|
|
1266
|
+
useDaouyLink: () => (props) => /* @__PURE__ */ React2.createElement("a", __spreadValues({}, props)),
|
|
1267
|
+
useDaouyLinkMaybe: () => void 0,
|
|
1268
|
+
useSelector: fakeUseSelector,
|
|
1269
|
+
useSelectors: fakeUseSelectors,
|
|
1270
|
+
useDaouyCanvasComponentInfo: () => null
|
|
1271
|
+
};
|
|
1272
|
+
})(),
|
|
1273
|
+
"@daouy/loader-runtime-registry": {
|
|
1274
|
+
components: SUBSTITUTED_COMPONENTS,
|
|
1275
|
+
globalVariantHooks: SUBSTITUTED_GLOBAL_VARIANT_HOOKS,
|
|
1276
|
+
codeComponentHelpers: REGISTERED_CODE_COMPONENT_HELPERS,
|
|
1277
|
+
functions: REGISTERED_CUSTOM_FUNCTIONS
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
this.registerTrait = noop;
|
|
1282
|
+
this.registerToken = noop;
|
|
1283
|
+
}
|
|
1284
|
+
registerComponent(component, meta) {
|
|
1285
|
+
var _a2;
|
|
1286
|
+
const stateHelpers = Object.fromEntries(
|
|
1287
|
+
Object.entries((_a2 = meta.states) != null ? _a2 : {}).filter(
|
|
1288
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1289
|
+
([_, stateSpec]) => (
|
|
1290
|
+
// `initFunc` is the only helper function used in RSC phase
|
|
1291
|
+
"initFunc" in stateSpec
|
|
1292
|
+
)
|
|
1293
|
+
).map(([stateName, stateSpec]) => [
|
|
1294
|
+
stateName,
|
|
1295
|
+
{ initFunc: stateSpec.initFunc }
|
|
1296
|
+
])
|
|
1297
|
+
);
|
|
1298
|
+
const helpers = { states: stateHelpers };
|
|
1299
|
+
this.internalSubstituteComponent(
|
|
1300
|
+
meta.getServerInfo ? (props) => {
|
|
1301
|
+
var _a3;
|
|
1302
|
+
const { readContextValue } = getPrepassContextEnv();
|
|
1303
|
+
const serverInfo = (_a3 = meta.getServerInfo) == null ? void 0 : _a3.call(meta, props, {
|
|
1304
|
+
readContext: readContextValue,
|
|
1305
|
+
readDataEnv: () => readContextValue(FakeDataContext),
|
|
1306
|
+
readDataSelector: fakeUseSelector,
|
|
1307
|
+
readDataSelectors: fakeUseSelectors,
|
|
1308
|
+
fetchData: fakeUseMutableDaouyQueryData
|
|
1309
|
+
});
|
|
1310
|
+
if (serverInfo && serverInfo.children) {
|
|
1311
|
+
const contents = [];
|
|
1312
|
+
const children = Array.isArray(serverInfo.children) ? serverInfo.children : [serverInfo.children];
|
|
1313
|
+
children.forEach((childData) => {
|
|
1314
|
+
contents.push(
|
|
1315
|
+
/* @__PURE__ */ React2.createElement(ContextAndDataProviderWrapper, { contextAndData: childData }, childData.node)
|
|
1316
|
+
);
|
|
1317
|
+
});
|
|
1318
|
+
return /* @__PURE__ */ React2.createElement(ContextAndDataProviderWrapper, { contextAndData: serverInfo }, contents);
|
|
1319
|
+
} else {
|
|
1320
|
+
return /* @__PURE__ */ React2.createElement(
|
|
1321
|
+
ContextAndDataProviderWrapper,
|
|
1322
|
+
{
|
|
1323
|
+
contextAndData: serverInfo != null ? serverInfo : {}
|
|
1324
|
+
},
|
|
1325
|
+
Object.values(props).flat(Infinity).filter(
|
|
1326
|
+
(v) => v && typeof v == "object" && v.$$typeof && React2.isValidElement(v)
|
|
1327
|
+
)
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
} : component,
|
|
1331
|
+
{ name: meta.name, isCode: true },
|
|
1332
|
+
Object.keys(stateHelpers).length > 0 ? helpers : void 0
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
registerFunction(fn, meta) {
|
|
1336
|
+
internalSetRegisteredFunction(fn, meta);
|
|
1337
|
+
}
|
|
1338
|
+
registerGlobalContext(context, meta) {
|
|
1339
|
+
this.substituteComponent(context, { name: meta.name, isCode: true });
|
|
1340
|
+
}
|
|
1341
|
+
refreshRegistry() {
|
|
1342
|
+
for (const globalGroup of this.getBundle().globalGroups) {
|
|
1343
|
+
if (globalGroup.type !== "global-screen") {
|
|
1344
|
+
SUBSTITUTED_GLOBAL_VARIANT_HOOKS[globalGroup.id] = () => {
|
|
1345
|
+
var _a2;
|
|
1346
|
+
const rootContext = getPrepassContextEnv().readContextValue(
|
|
1347
|
+
FakeRootProviderContext
|
|
1348
|
+
);
|
|
1349
|
+
const loader = this;
|
|
1350
|
+
const { name, projectId } = globalGroup;
|
|
1351
|
+
const spec = [
|
|
1352
|
+
...loader.getGlobalVariants(),
|
|
1353
|
+
...(_a2 = rootContext.globalVariants) != null ? _a2 : []
|
|
1354
|
+
].find(
|
|
1355
|
+
(s) => s.name === name && (!s.projectId || s.projectId === projectId)
|
|
1356
|
+
);
|
|
1357
|
+
return spec ? spec.value : void 0;
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
super.refreshRegistry();
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
function handlePrepassDaouyRootComponent(props) {
|
|
1365
|
+
var _a2;
|
|
1366
|
+
const {
|
|
1367
|
+
globalVariants,
|
|
1368
|
+
globalContextsProps,
|
|
1369
|
+
variation,
|
|
1370
|
+
translator,
|
|
1371
|
+
Head,
|
|
1372
|
+
Link,
|
|
1373
|
+
pageRoute,
|
|
1374
|
+
pageParams,
|
|
1375
|
+
pageQuery,
|
|
1376
|
+
suspenseFallback,
|
|
1377
|
+
disableLoadingBoundary,
|
|
1378
|
+
user,
|
|
1379
|
+
userAuthToken,
|
|
1380
|
+
isUserLoading,
|
|
1381
|
+
authRedirectUri
|
|
1382
|
+
} = props;
|
|
1383
|
+
const loader = props.loader.__internal;
|
|
1384
|
+
const splits = loader.getActiveSplits();
|
|
1385
|
+
const value = {
|
|
1386
|
+
globalVariants: mergeGlobalVariantsSpec(
|
|
1387
|
+
globalVariants != null ? globalVariants : [],
|
|
1388
|
+
getGlobalVariantsFromSplits(splits, variation != null ? variation : {})
|
|
1389
|
+
),
|
|
1390
|
+
globalContextsProps,
|
|
1391
|
+
loader,
|
|
1392
|
+
variation,
|
|
1393
|
+
translator,
|
|
1394
|
+
Head,
|
|
1395
|
+
Link,
|
|
1396
|
+
user,
|
|
1397
|
+
userAuthToken,
|
|
1398
|
+
isUserLoading,
|
|
1399
|
+
authRedirectUri,
|
|
1400
|
+
suspenseFallback,
|
|
1401
|
+
disableLoadingBoundary
|
|
1402
|
+
};
|
|
1403
|
+
const { setContextValue, readContextValue } = getPrepassContextEnv();
|
|
1404
|
+
setContextValue(FakeRootProviderContext, value);
|
|
1405
|
+
const existingEnv = (_a2 = readContextValue(FakeDataContext)) != null ? _a2 : {};
|
|
1406
|
+
const fixCatchallParams = (params) => {
|
|
1407
|
+
const newParams = {};
|
|
1408
|
+
for (const [key, val] of Object.entries(params)) {
|
|
1409
|
+
if (!val) {
|
|
1410
|
+
continue;
|
|
1411
|
+
}
|
|
1412
|
+
if (key.startsWith("...")) {
|
|
1413
|
+
newParams[key.slice(3)] = typeof val === "string" ? val.replace(/^\/|\/$/g, "").split("/") : val;
|
|
1414
|
+
} else {
|
|
1415
|
+
newParams[key] = val;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
return newParams;
|
|
1419
|
+
};
|
|
1420
|
+
const mkPathFromRouteAndParams = (route, params) => {
|
|
1421
|
+
if (!params) {
|
|
1422
|
+
return route;
|
|
1423
|
+
}
|
|
1424
|
+
let path = route;
|
|
1425
|
+
for (const [key, val] of Object.entries(params)) {
|
|
1426
|
+
if (typeof val === "string") {
|
|
1427
|
+
path = path.replace(`[${key}]`, val);
|
|
1428
|
+
} else if (Array.isArray(val)) {
|
|
1429
|
+
if (path.includes(`[[...${key}]]`)) {
|
|
1430
|
+
path = path.replace(`[[...${key}]]`, val.join("/"));
|
|
1431
|
+
} else if (path.includes(`[...${key}]`)) {
|
|
1432
|
+
path = path.replace(`[...${key}]`, val.join("/"));
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
return path;
|
|
1437
|
+
};
|
|
1438
|
+
const fixedParams = fixCatchallParams(pageParams != null ? pageParams : {});
|
|
1439
|
+
setContextValue(FakeDataContext, __spreadProps(__spreadValues({}, existingEnv), {
|
|
1440
|
+
["pageRoute"]: pageRoute,
|
|
1441
|
+
[mkMetaName("pageRoute")]: { advanced: true, label: "Page route" },
|
|
1442
|
+
["pagePath"]: pageRoute ? mkPathFromRouteAndParams(pageRoute, fixedParams) : void 0,
|
|
1443
|
+
[mkMetaName("pagePath")]: { label: "Page path" },
|
|
1444
|
+
["params"]: __spreadValues(__spreadValues({}, existingEnv.params), fixedParams),
|
|
1445
|
+
[mkMetaName("params")]: { label: "Page URL path params" },
|
|
1446
|
+
["query"]: __spreadValues(__spreadValues({}, existingEnv.query), pageQuery),
|
|
1447
|
+
[mkMetaName("query")]: { label: "Page URL query params" }
|
|
1448
|
+
}));
|
|
1449
|
+
}
|
|
1450
|
+
function handlePrepassDaouyComponent(props) {
|
|
1451
|
+
var _b;
|
|
1452
|
+
const { component, projectId, componentProps, forceOriginal } = props;
|
|
1453
|
+
const { setContextValue, readContextValue } = getPrepassContextEnv();
|
|
1454
|
+
const rootContext = readContextValue(
|
|
1455
|
+
FakeRootProviderContext
|
|
1456
|
+
);
|
|
1457
|
+
const isRootLoader = !readContextValue(FakeDaouyComponentContext);
|
|
1458
|
+
if (!rootContext) {
|
|
1459
|
+
throw new Error(
|
|
1460
|
+
`You must use <DaouyRootProvider/> at the root of your app`
|
|
1461
|
+
);
|
|
1462
|
+
}
|
|
1463
|
+
const _a2 = rootContext, {
|
|
1464
|
+
loader,
|
|
1465
|
+
globalContextsProps,
|
|
1466
|
+
userAuthToken,
|
|
1467
|
+
isUserLoading,
|
|
1468
|
+
authRedirectUri,
|
|
1469
|
+
translator
|
|
1470
|
+
} = _a2, rest = __objRest(_a2, [
|
|
1471
|
+
"loader",
|
|
1472
|
+
"globalContextsProps",
|
|
1473
|
+
"userAuthToken",
|
|
1474
|
+
"isUserLoading",
|
|
1475
|
+
"authRedirectUri",
|
|
1476
|
+
"translator"
|
|
1477
|
+
]);
|
|
1478
|
+
const spec = { name: component, projectId, isCode: false };
|
|
1479
|
+
const opts = { forceOriginal };
|
|
1480
|
+
const lookup = loader.getLookup();
|
|
1481
|
+
if (!lookup.hasComponent(spec)) {
|
|
1482
|
+
return null;
|
|
1483
|
+
}
|
|
1484
|
+
const Component = lookup.getComponent(spec, opts);
|
|
1485
|
+
let element = /* @__PURE__ */ React2.createElement(Component, __spreadValues({}, componentProps));
|
|
1486
|
+
if (isRootLoader) {
|
|
1487
|
+
const ReactWebRootProvider = lookup.getRootProvider();
|
|
1488
|
+
const GlobalContextsProvider = lookup.getGlobalContextsProvider({
|
|
1489
|
+
name: component,
|
|
1490
|
+
projectId
|
|
1491
|
+
});
|
|
1492
|
+
setContextValue(FakeDaouyComponentContext, true);
|
|
1493
|
+
element = /* @__PURE__ */ React2.createElement(
|
|
1494
|
+
ReactWebRootProvider,
|
|
1495
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
1496
|
+
userAuthToken,
|
|
1497
|
+
isUserLoading,
|
|
1498
|
+
authRedirectUri,
|
|
1499
|
+
i18n: {
|
|
1500
|
+
translator,
|
|
1501
|
+
tagPrefix: (_b = loader.opts.i18n) == null ? void 0 : _b.tagPrefix
|
|
1502
|
+
}
|
|
1503
|
+
}),
|
|
1504
|
+
element
|
|
1505
|
+
);
|
|
1506
|
+
if (GlobalContextsProvider) {
|
|
1507
|
+
element = /* @__PURE__ */ React2.createElement(GlobalContextsProvider, __spreadValues({}, globalContextsProps), element);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return element;
|
|
1511
|
+
}
|
|
1512
|
+
function handleDaouyPrepassContext({
|
|
1513
|
+
cache
|
|
1514
|
+
}) {
|
|
1515
|
+
getPrepassContextEnv().setContextValue(FakeDaouyPrepassContext, cache);
|
|
1516
|
+
}
|
|
1517
|
+
function getPrepassContextEnv() {
|
|
1518
|
+
return globalThis.__ssrPrepassEnv;
|
|
1519
|
+
}
|
|
1520
|
+
function ContextAndDataProviderWrapper({
|
|
1521
|
+
children,
|
|
1522
|
+
contextAndData
|
|
1523
|
+
}) {
|
|
1524
|
+
var _a2;
|
|
1525
|
+
const { setContextValue, readContextValue } = getPrepassContextEnv();
|
|
1526
|
+
const contexts = contextAndData.providedContexts ? Array.isArray(contextAndData.providedContexts) ? contextAndData.providedContexts : [contextAndData.providedContexts] : [];
|
|
1527
|
+
const providedData = contextAndData.providedData ? Array.isArray(contextAndData.providedData) ? contextAndData.providedData : [contextAndData.providedData] : [];
|
|
1528
|
+
contexts.forEach((context) => {
|
|
1529
|
+
setContextValue(context.contextKey, context.value);
|
|
1530
|
+
});
|
|
1531
|
+
let $ctx = (_a2 = readContextValue(FakeDataContext)) != null ? _a2 : {};
|
|
1532
|
+
providedData.forEach(({ name, data }) => {
|
|
1533
|
+
$ctx = __spreadProps(__spreadValues({}, $ctx), {
|
|
1534
|
+
[name]: data
|
|
1535
|
+
});
|
|
1536
|
+
});
|
|
1537
|
+
setContextValue(FakeDataContext, $ctx);
|
|
1538
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, children);
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
// src/prepass-server.ts
|
|
1542
|
+
import { extractDaouyQueryData as internalExtractQueryData } from "@daouy/prepass";
|
|
1543
|
+
function extractDaouyQueryData(element, loader) {
|
|
1544
|
+
return __async(this, null, function* () {
|
|
1545
|
+
return yield internalExtractQueryData(
|
|
1546
|
+
element,
|
|
1547
|
+
(elt) => handleClientComponentRef(elt, loader, element)
|
|
1548
|
+
);
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
function handleClientComponentRef(elt, loader, rootElement) {
|
|
1552
|
+
var _a2, _b;
|
|
1553
|
+
try {
|
|
1554
|
+
const refId = elt.type.$$id;
|
|
1555
|
+
if (refId.includes("DaouyRootProvider") || elt === rootElement) {
|
|
1556
|
+
const props = elt.props;
|
|
1557
|
+
if (props.prefetchedData) {
|
|
1558
|
+
handlePrepassDaouyRootComponent(__spreadProps(__spreadValues({}, props), { loader }));
|
|
1559
|
+
}
|
|
1560
|
+
return;
|
|
1561
|
+
} else if (refId.includes("DaouyComponent") && ((_a2 = elt.props) == null ? void 0 : _a2.component) != null) {
|
|
1562
|
+
return handlePrepassDaouyComponent(elt.props);
|
|
1563
|
+
} else if (refId.includes("DaouyPrepassContext") && ((_b = elt.props) == null ? void 0 : _b.cache) != null) {
|
|
1564
|
+
return handleDaouyPrepassContext(elt.props);
|
|
1565
|
+
}
|
|
1566
|
+
} catch (err) {
|
|
1567
|
+
console.warn("Error processing client reference: ", err);
|
|
1568
|
+
}
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
// src/react-server.ts
|
|
1573
|
+
function initDaouyLoader(opts) {
|
|
1574
|
+
const internal = new InternalPrepassDaouyLoader(opts);
|
|
1575
|
+
return new DaouyComponentLoader(internal);
|
|
1576
|
+
}
|
|
1577
|
+
export {
|
|
1578
|
+
DaouyComponentLoader,
|
|
1579
|
+
InternalPrepassDaouyLoader as InternalDaouyComponentLoader,
|
|
1580
|
+
extractDaouyQueryData as __EXPERMIENTAL__extractDaouyQueryData,
|
|
1581
|
+
convertBundlesToComponentRenderData,
|
|
1582
|
+
initDaouyLoader,
|
|
1583
|
+
matchesPagePath
|
|
1584
|
+
};
|
|
1585
|
+
//# sourceMappingURL=react-server.esm.js.map
|