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