@blocklet/pages-kit-inner-components 0.6.103 → 0.6.105
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/lib/cjs/add-component.js +1 -1
- package/lib/cjs/chunks/components-BmFOXvb0.js +57 -0
- package/lib/cjs/chunks/{draft-data-CkVvOh60.js → draft-data-e1KnFlxv.js} +1 -1
- package/lib/cjs/chunks/{home-DdN3Z-6B.js → home-DHmHyTMb.js} +10 -10
- package/lib/cjs/chunks/{index-B-Wh6PRT.js → index-Cu2Jg8OH.js} +24 -24
- package/lib/cjs/chunks/{publish-button-BtLFUEny.js → publish-button-Do7oJLSH.js} +1 -1
- package/lib/cjs/chunks/site-state-BQySNTiP.js +1 -0
- package/lib/cjs/chunks/state-DU3L5Lve.js +1 -0
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +1 -1
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +3 -3
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/add-component.js +2 -2
- package/lib/es/chunks/components-DLjI_Xlm.js +615 -0
- package/lib/es/chunks/{draft-data-BOoVhbon.js → draft-data-DRdPzuGm.js} +1 -1
- package/lib/es/chunks/{home-DVTVPkSm.js → home-DajDpGXA.js} +123 -123
- package/lib/es/chunks/{index-DENjTU8O.js → index-BpP1FqET.js} +239 -238
- package/lib/es/chunks/{publish-button-BVcMw8Fh.js → publish-button-8kEbdc0k.js} +3 -3
- package/lib/es/chunks/site-state-DS7eIMFg.js +1684 -0
- package/lib/es/chunks/{state-DNdwHwty.js → state-qDCrgEMQ.js} +114 -113
- package/lib/es/components.js +14 -13
- package/lib/es/home.js +3 -3
- package/lib/es/project-html.js +1 -1
- package/lib/es/resources.js +2 -2
- package/lib/es/setting.js +415 -413
- package/lib/es/site-state.js +2 -2
- package/package.json +7 -7
- package/lib/cjs/chunks/components-DsHjikTX.js +0 -57
- package/lib/cjs/chunks/site-state-DlLhHuIr.js +0 -1
- package/lib/cjs/chunks/state-BdtFHk36.js +0 -1
- package/lib/es/chunks/components-BIhMGXjB.js +0 -610
- package/lib/es/chunks/site-state-CN4Kulgk.js +0 -1671
|
@@ -1,610 +0,0 @@
|
|
|
1
|
-
import { memoize as Q, BuiltinModules as v } from "@blocklet/quickjs";
|
|
2
|
-
import { createHash as z } from "crypto";
|
|
3
|
-
import { promises as g } from "fs";
|
|
4
|
-
import U, { join as O } from "path";
|
|
5
|
-
import h from "@blocklet/sdk/lib/config";
|
|
6
|
-
import Z from "lodash/isNil";
|
|
7
|
-
import { getComponentMountPoint as X } from "@blocklet/pages-kit/builtin/utils";
|
|
8
|
-
import { PreloadComponentScriptModule as P } from "@blocklet/pages-kit/types";
|
|
9
|
-
import { BuiltinModules as I } from "@blocklet/pages-kit/utils/builtin";
|
|
10
|
-
import { componentUMDName as Y, RenderNestedComponent as D, mergeComponent as q } from "@blocklet/pages-kit/utils/property";
|
|
11
|
-
import ee from "lodash/isEmpty";
|
|
12
|
-
import { LRUCache as te } from "lru-cache";
|
|
13
|
-
import oe, { Headers as ne } from "node-fetch";
|
|
14
|
-
import { joinURL as _, getQuery as re, withQuery as se, parseURL as R, withHttps as ce } from "ufo";
|
|
15
|
-
import ae from "@blocklet/logger";
|
|
16
|
-
import { isRelativeModule as ie, createBuiltinModuleTransformer as pe } from "@blocklet/pages-kit/utils/typescript/builtin-module-transformer";
|
|
17
|
-
import "@blocklet/sdk/lib/component";
|
|
18
|
-
h.env.mode;
|
|
19
|
-
h.env.TRANSLATE_ADDITIONAL_PROMPT || process.env.TRANSLATE_ADDITIONAL_PROMPT;
|
|
20
|
-
h.env.PAGE_CONTENT_ADDITIONAL_PROMPT || process.env.PAGE_CONTENT_ADDITIONAL_PROMPT;
|
|
21
|
-
const qe = "image-bin";
|
|
22
|
-
h.env.INIT_TEMPLATE_PATH;
|
|
23
|
-
const et = process.env.DATABASE_URL || U.join(h.env.dataDir, "db/pages-kit.db"), $ = h, tt = () => h.env.tenantMode === "multiple", ot = () => (Z($.env.preferences.multiTenantAllProjectAccessPassports) ? [] : $.env.preferences.multiTenantAllProjectAccessPassports?.split(",")) || [], le = U.join(h.env.dataDir, "fs-memoize-cache"), ue = h.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", w = ae("pages-kit"), de = le, me = ue, M = 30 * 24 * 60 * 60 * 1e3, fe = 24 * 60 * 60 * 1e3, H = async (e = "") => {
|
|
24
|
-
const t = O(de, e);
|
|
25
|
-
try {
|
|
26
|
-
if (!(await g.stat(t)).isDirectory())
|
|
27
|
-
throw new Error(`${t} is not a directory`);
|
|
28
|
-
} catch {
|
|
29
|
-
await g.mkdir(t, { recursive: !0 });
|
|
30
|
-
}
|
|
31
|
-
return t;
|
|
32
|
-
}, k = (e, ...t) => e.keyGenerator ? e.keyGenerator(...t) : JSON.stringify([e.subdir || "", ...t]), he = (e, t) => {
|
|
33
|
-
const o = z("md5").update(t).digest("hex");
|
|
34
|
-
return O(e, `${me}-${o}.json`);
|
|
35
|
-
}, we = async (e = "") => {
|
|
36
|
-
const t = await H(e), o = Date.now();
|
|
37
|
-
try {
|
|
38
|
-
const n = await g.readdir(t);
|
|
39
|
-
await Promise.all(
|
|
40
|
-
n.filter((c) => c.endsWith(".json")).map(async (c) => {
|
|
41
|
-
const r = O(t, c);
|
|
42
|
-
try {
|
|
43
|
-
const u = await g.readFile(r, "utf-8"), p = JSON.parse(u);
|
|
44
|
-
p.createdAt && o - p.createdAt > M && await g.unlink(r);
|
|
45
|
-
} catch {
|
|
46
|
-
try {
|
|
47
|
-
const p = await g.stat(r);
|
|
48
|
-
o - p.mtimeMs > M && await g.unlink(r);
|
|
49
|
-
} catch {
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
);
|
|
54
|
-
} catch (n) {
|
|
55
|
-
console.error(`Failed to cleanup cache in ${t}:`, n);
|
|
56
|
-
}
|
|
57
|
-
}, ge = (() => {
|
|
58
|
-
const e = /* @__PURE__ */ new Set();
|
|
59
|
-
return setInterval(async () => {
|
|
60
|
-
await Promise.all(Array.from(e).map((n) => we(n)));
|
|
61
|
-
}, fe).unref(), (n) => {
|
|
62
|
-
e.add(n);
|
|
63
|
-
};
|
|
64
|
-
})();
|
|
65
|
-
function A(e, t) {
|
|
66
|
-
return t.subdir && ge(t.subdir), Q(
|
|
67
|
-
async (...n) => {
|
|
68
|
-
const c = await H(t.subdir || ""), r = k(t, ...n), u = he(c, r);
|
|
69
|
-
try {
|
|
70
|
-
const p = await g.readFile(u, "utf-8"), { value: d, createdAt: l } = JSON.parse(p);
|
|
71
|
-
if (l && Date.now() - l > M)
|
|
72
|
-
throw await g.unlink(u).catch(() => {
|
|
73
|
-
}), new Error("Cache expired");
|
|
74
|
-
return d;
|
|
75
|
-
} catch {
|
|
76
|
-
const d = await e(...n), l = JSON.stringify({ value: d, createdAt: Date.now() });
|
|
77
|
-
return g.writeFile(u, l, "utf-8").catch((m) => {
|
|
78
|
-
console.error("Failed to write fs cache:", m);
|
|
79
|
-
}), d;
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
keyGenerator: (...n) => k(t, ...n),
|
|
84
|
-
lruOptions: t.lruOptions || {
|
|
85
|
-
max: 100,
|
|
86
|
-
ttl: M
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
const B = async () => await import("typescript"), ye = async () => await import("esbuild"), xe = async () => (await import("postcss")).default, Se = async () => (await import("tailwindcss")).default, Ce = async () => (await import("autoprefixer")).default, Ee = !1, Pe = async (e, { componentId: t }) => {
|
|
92
|
-
const o = `@tailwind components;
|
|
93
|
-
@tailwind utilities;
|
|
94
|
-
`, n = `.CustomComponent_${t}`, c = await xe(), r = await Se(), u = await Ce();
|
|
95
|
-
return (await c([
|
|
96
|
-
r({ content: [{ raw: e, extension: "tsx" }] }),
|
|
97
|
-
u({
|
|
98
|
-
overrideBrowserslist: ["> 1%", "last 2 versions"],
|
|
99
|
-
stats: {}
|
|
100
|
-
}),
|
|
101
|
-
(d) => {
|
|
102
|
-
d.walkRules((l) => {
|
|
103
|
-
l.selectors = l.selectors.map((m) => m.replace(/\.(.+)/g, `${n}.$1,${n} .$1`));
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
// FIXME: cssnano use browserslist, it is not working with the fs isolation
|
|
107
|
-
// cssnano({ preset: 'default' }),
|
|
108
|
-
]).process(o)).css;
|
|
109
|
-
}, Te = async (e, { componentId: t }) => {
|
|
110
|
-
const o = await Pe(e, { componentId: t });
|
|
111
|
-
return `export const __PagesKit_CSS__ = ${JSON.stringify(o)};
|
|
112
|
-
|
|
113
|
-
${e}
|
|
114
|
-
`;
|
|
115
|
-
}, L = A(
|
|
116
|
-
async (e, t) => {
|
|
117
|
-
let o = await B();
|
|
118
|
-
try {
|
|
119
|
-
let n = o.transpileModule(e, {
|
|
120
|
-
compilerOptions: {
|
|
121
|
-
jsx: o.JsxEmit.React,
|
|
122
|
-
target: o.ScriptTarget.ES2016,
|
|
123
|
-
module: o.ModuleKind.ESNext
|
|
124
|
-
},
|
|
125
|
-
transformers: {
|
|
126
|
-
before: [pe(o)]
|
|
127
|
-
}
|
|
128
|
-
}).outputText;
|
|
129
|
-
if (t.tailwind && (n = await Te(n, { componentId: t.componentId })), t.module === P.ESM) return n;
|
|
130
|
-
const c = o.transpileModule(n, {
|
|
131
|
-
compilerOptions: {
|
|
132
|
-
jsx: o.JsxEmit.React,
|
|
133
|
-
target: o.ScriptTarget.ES2016,
|
|
134
|
-
module: o.ModuleKind.CommonJS,
|
|
135
|
-
moduleResolution: o.ModuleResolutionKind.Node16
|
|
136
|
-
}
|
|
137
|
-
}).outputText;
|
|
138
|
-
return t.module === P.CJS ? c : K(t.moduleName, c);
|
|
139
|
-
} catch (n) {
|
|
140
|
-
throw new Error(n);
|
|
141
|
-
} finally {
|
|
142
|
-
o = null;
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
subdir: "transpileModule"
|
|
147
|
-
}
|
|
148
|
-
), Me = async (e, t) => {
|
|
149
|
-
let { build: o } = await ye(), n = null;
|
|
150
|
-
try {
|
|
151
|
-
const r = (await o({
|
|
152
|
-
entryPoints: ["index.tsx"],
|
|
153
|
-
external: Object.keys(I),
|
|
154
|
-
format: "esm",
|
|
155
|
-
target: "esnext",
|
|
156
|
-
bundle: !0,
|
|
157
|
-
write: !1,
|
|
158
|
-
plugins: [
|
|
159
|
-
{
|
|
160
|
-
name: "vfs",
|
|
161
|
-
setup(d) {
|
|
162
|
-
d.onResolve({ filter: /.*/ }, (l) => l.path === "index.tsx" ? { path: "index.tsx", namespace: "vfs" } : l.path === "./component" ? { path: "component.tsx", namespace: "vfs" } : null), d.onLoad({ filter: /.*/, namespace: "vfs" }, async (l) => {
|
|
163
|
-
if (l.path === "index.tsx")
|
|
164
|
-
return { contents: `export { ${t} } from './component'`, loader: "tsx" };
|
|
165
|
-
if (l.path === "component.tsx")
|
|
166
|
-
return { contents: e, loader: "tsx" };
|
|
167
|
-
if (ie(l.path)) {
|
|
168
|
-
const m = l.path.split("/").pop();
|
|
169
|
-
}
|
|
170
|
-
return null;
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
})).outputFiles?.[0]?.contents;
|
|
176
|
-
if (!r) throw new Error("Failed to build server code");
|
|
177
|
-
const u = Buffer.from(r).toString();
|
|
178
|
-
return n = await B(), n.transpileModule(u, {
|
|
179
|
-
compilerOptions: { module: n.ModuleKind.ESNext, target: n.ScriptTarget.ES2020 }
|
|
180
|
-
}).outputText;
|
|
181
|
-
} catch (c) {
|
|
182
|
-
throw new Error(c);
|
|
183
|
-
} finally {
|
|
184
|
-
o = null, n = null;
|
|
185
|
-
}
|
|
186
|
-
}, be = (e, t) => new RegExp(
|
|
187
|
-
`export\\s+\\{[^}]*(?:\\w+\\s+as\\s+${t}\\b|\\b${t}\\b)[^}]*\\}`,
|
|
188
|
-
"m"
|
|
189
|
-
).test(e) ? e : void 0, J = A(
|
|
190
|
-
async (e, t) => {
|
|
191
|
-
const o = await Me(e, t);
|
|
192
|
-
return be(o, t);
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
subdir: "extractExportValueSchema"
|
|
196
|
-
}
|
|
197
|
-
), K = (e, t) => `// GENERATED FILE. DO NOT EDIT.
|
|
198
|
-
var ${e} = async function () {
|
|
199
|
-
|
|
200
|
-
const exports = {};
|
|
201
|
-
let moduleExports = null;
|
|
202
|
-
|
|
203
|
-
// add commonjs module compatibility layer
|
|
204
|
-
const module = { exports: moduleExports };
|
|
205
|
-
|
|
206
|
-
// execute component code
|
|
207
|
-
${t}
|
|
208
|
-
|
|
209
|
-
// handle possible module.exports
|
|
210
|
-
if (module.exports && module.exports !== moduleExports) {
|
|
211
|
-
// if module.exports is used, use it first
|
|
212
|
-
return typeof module.exports === 'object' ? module.exports : { default: module.exports };
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// ensure a default export
|
|
216
|
-
if (!('default' in exports) && Object.keys(exports).length === 0) {
|
|
217
|
-
// module has no exports, return null to indicate invalid
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return exports;
|
|
222
|
-
};
|
|
223
|
-
`, G = async () => {
|
|
224
|
-
const { Sandbox: e } = await import("@blocklet/quickjs");
|
|
225
|
-
return e;
|
|
226
|
-
};
|
|
227
|
-
function ve(e) {
|
|
228
|
-
return e?.type === "react-component";
|
|
229
|
-
}
|
|
230
|
-
const C = new te({
|
|
231
|
-
max: 600,
|
|
232
|
-
ttl: 1e3 * 60 * 60 * 24 * 7
|
|
233
|
-
// default ttl is 7 days
|
|
234
|
-
}), _e = 60 * 60, F = 10;
|
|
235
|
-
function V(e) {
|
|
236
|
-
w.info("clear preload components cache", { cacheKey: e }), C.delete(e);
|
|
237
|
-
}
|
|
238
|
-
function nt(e) {
|
|
239
|
-
for (const t of C.keys())
|
|
240
|
-
t.includes(e) && (w.info("clear preload components cache", { cacheKey: t }), V(t));
|
|
241
|
-
}
|
|
242
|
-
function rt(e) {
|
|
243
|
-
for (const t of C.keys())
|
|
244
|
-
t.includes(e) && (w.info("clear preload components cache", { cacheKey: t }), V(t));
|
|
245
|
-
}
|
|
246
|
-
function Ie({
|
|
247
|
-
mode: e,
|
|
248
|
-
instanceId: t,
|
|
249
|
-
componentId: o,
|
|
250
|
-
locale: n
|
|
251
|
-
}) {
|
|
252
|
-
return ["getPreloadComponents", e, t, o, n].join("-");
|
|
253
|
-
}
|
|
254
|
-
async function st({
|
|
255
|
-
mode: e,
|
|
256
|
-
req: t,
|
|
257
|
-
state: o,
|
|
258
|
-
locale: n,
|
|
259
|
-
instances: c,
|
|
260
|
-
module: r
|
|
261
|
-
}) {
|
|
262
|
-
const {
|
|
263
|
-
supportedLocales: u,
|
|
264
|
-
config: { defaultLocale: p }
|
|
265
|
-
} = o;
|
|
266
|
-
if (!p) return null;
|
|
267
|
-
const d = (await Promise.all(
|
|
268
|
-
c.map(async (s) => {
|
|
269
|
-
try {
|
|
270
|
-
const a = Ie({
|
|
271
|
-
mode: e,
|
|
272
|
-
instanceId: s.id,
|
|
273
|
-
componentId: s.componentId,
|
|
274
|
-
locale: n
|
|
275
|
-
});
|
|
276
|
-
if (e !== "draft" && s.useCache && C.has(a))
|
|
277
|
-
return w.info(`get preload component from cache: ${a}`), C.get(a);
|
|
278
|
-
const f = b({ state: o, componentId: s.componentId });
|
|
279
|
-
if (!f) return null;
|
|
280
|
-
const S = await Oe({
|
|
281
|
-
req: t,
|
|
282
|
-
state: o,
|
|
283
|
-
componentId: f.id,
|
|
284
|
-
locale: n,
|
|
285
|
-
defaultLocale: p,
|
|
286
|
-
properties: s.properties
|
|
287
|
-
});
|
|
288
|
-
if (!S) return null;
|
|
289
|
-
const E = { instanceId: s.id, preload: S };
|
|
290
|
-
if (e !== "draft" && s.useCache) {
|
|
291
|
-
let x = _e;
|
|
292
|
-
s.cacheDuration && (x = s.cacheDuration), w.info(`set preload component to cache(${x}s): ${a}`), C.set(a, E, {
|
|
293
|
-
ttl: x * 1e3
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
return E;
|
|
297
|
-
} catch (a) {
|
|
298
|
-
return w.error(
|
|
299
|
-
"get preload component error",
|
|
300
|
-
{ instanceId: s.id, componentId: s.componentId },
|
|
301
|
-
{ error: a }
|
|
302
|
-
), null;
|
|
303
|
-
}
|
|
304
|
-
})
|
|
305
|
-
)).filter((s) => !!s), l = Object.values(
|
|
306
|
-
d.reduce((s, a) => ({ ...s, ...a.preload.components }), {})
|
|
307
|
-
);
|
|
308
|
-
async function m() {
|
|
309
|
-
const s = await Promise.all(
|
|
310
|
-
l.map(async (a) => {
|
|
311
|
-
const f = r === P.ESM, S = r === P.UMD_FN, E = r === P.CJS, x = f ? "" : Y({ componentId: a.component.id }), N = De(a.component);
|
|
312
|
-
let T = {
|
|
313
|
-
module: r,
|
|
314
|
-
script: "",
|
|
315
|
-
moduleName: x
|
|
316
|
-
};
|
|
317
|
-
if (N && a.component.renderer?.type === "react-component" && f && a.component.renderer?.script)
|
|
318
|
-
T.script = a.component.renderer?.script;
|
|
319
|
-
else if (N && a.component.renderer?.type === "react-component" && (E || S) && a.component.renderer?.cjsScript) {
|
|
320
|
-
const j = a.component.renderer.cjsScript;
|
|
321
|
-
T.script = E ? j : K(x, j);
|
|
322
|
-
} else
|
|
323
|
-
T = f ? {
|
|
324
|
-
// ESM
|
|
325
|
-
module: r,
|
|
326
|
-
script: await L(a.script, {
|
|
327
|
-
componentId: a.component.id,
|
|
328
|
-
module: r,
|
|
329
|
-
tailwind: e !== "draft"
|
|
330
|
-
})
|
|
331
|
-
} : {
|
|
332
|
-
// CJS OR UMD
|
|
333
|
-
module: r,
|
|
334
|
-
script: await L(a.script, {
|
|
335
|
-
componentId: a.component.id,
|
|
336
|
-
module: r,
|
|
337
|
-
moduleName: x,
|
|
338
|
-
tailwind: e !== "draft"
|
|
339
|
-
}),
|
|
340
|
-
moduleName: x
|
|
341
|
-
};
|
|
342
|
-
return [a.component.id, { component: a.component, script: T }];
|
|
343
|
-
})
|
|
344
|
-
);
|
|
345
|
-
return Object.fromEntries(s);
|
|
346
|
-
}
|
|
347
|
-
const y = await m();
|
|
348
|
-
return {
|
|
349
|
-
config: { defaultLocale: p, supportedLocales: u },
|
|
350
|
-
components: y,
|
|
351
|
-
instances: d.map((s) => ({
|
|
352
|
-
id: s.instanceId,
|
|
353
|
-
componentId: s.preload.component.id,
|
|
354
|
-
locales: { [s.preload.locale]: { props: s.preload.props } }
|
|
355
|
-
}))
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
async function Oe({
|
|
359
|
-
req: e,
|
|
360
|
-
state: t,
|
|
361
|
-
componentId: o,
|
|
362
|
-
locale: n,
|
|
363
|
-
defaultLocale: c,
|
|
364
|
-
properties: r
|
|
365
|
-
}) {
|
|
366
|
-
const { supportedLocales: u } = t, p = b({ state: t, componentId: o });
|
|
367
|
-
if (!p) return null;
|
|
368
|
-
const d = u.some((m) => m.locale === n) ? n : c;
|
|
369
|
-
if (!d) return null;
|
|
370
|
-
const l = await W({ req: e, state: t, componentId: o, locale: d, defaultLocale: c, properties: r });
|
|
371
|
-
return l ? {
|
|
372
|
-
component: p,
|
|
373
|
-
...l
|
|
374
|
-
} : null;
|
|
375
|
-
}
|
|
376
|
-
const Ae = 20;
|
|
377
|
-
async function W({
|
|
378
|
-
req: e,
|
|
379
|
-
depth: t = 0,
|
|
380
|
-
state: o,
|
|
381
|
-
componentId: n,
|
|
382
|
-
locale: c,
|
|
383
|
-
defaultLocale: r,
|
|
384
|
-
properties: u
|
|
385
|
-
}) {
|
|
386
|
-
if (t > Ae) throw new RangeError("max component depth exceeded");
|
|
387
|
-
const p = Ne({ state: o, componentId: n, properties: u, locale: c });
|
|
388
|
-
if (!p) return null;
|
|
389
|
-
const { props: d, component: l } = p, m = {
|
|
390
|
-
locale: c || r,
|
|
391
|
-
components: { [p.component.id]: { component: p.component, script: p.script } },
|
|
392
|
-
props: { ...d }
|
|
393
|
-
};
|
|
394
|
-
try {
|
|
395
|
-
const y = ve(l.renderer) ? l.renderer.getServerSideProps : void 0, i = await je({ ...p, req: e, getServerSideProps: y });
|
|
396
|
-
i?.props && Object.assign(m.props, i.props);
|
|
397
|
-
} catch (y) {
|
|
398
|
-
w.error("preload data at server side error", { componentId: n, name: p.component.name }, { error: y });
|
|
399
|
-
}
|
|
400
|
-
return await Promise.all(
|
|
401
|
-
Object.entries(d).map(async ([y, i]) => {
|
|
402
|
-
if (i?.type === D) {
|
|
403
|
-
const s = await W({
|
|
404
|
-
req: e,
|
|
405
|
-
depth: t + 1,
|
|
406
|
-
state: o,
|
|
407
|
-
componentId: i.componentId,
|
|
408
|
-
locale: c,
|
|
409
|
-
defaultLocale: r,
|
|
410
|
-
properties: i.properties
|
|
411
|
-
});
|
|
412
|
-
s && (Object.assign(m.components, s.components), Object.assign(m.props, {
|
|
413
|
-
[y]: {
|
|
414
|
-
type: D,
|
|
415
|
-
componentId: i.componentId,
|
|
416
|
-
props: s.props
|
|
417
|
-
}
|
|
418
|
-
}));
|
|
419
|
-
}
|
|
420
|
-
})
|
|
421
|
-
), m;
|
|
422
|
-
}
|
|
423
|
-
function Ne({
|
|
424
|
-
state: e,
|
|
425
|
-
componentId: t,
|
|
426
|
-
locale: o,
|
|
427
|
-
properties: n
|
|
428
|
-
}) {
|
|
429
|
-
const c = b({ state: e, componentId: t });
|
|
430
|
-
if (!c) return null;
|
|
431
|
-
const r = q({
|
|
432
|
-
componentId: t,
|
|
433
|
-
getComponent: (u) => b({ state: e, componentId: u }),
|
|
434
|
-
locale: o,
|
|
435
|
-
defaultLocale: e.config.defaultLocale,
|
|
436
|
-
properties: n
|
|
437
|
-
});
|
|
438
|
-
return r ? { component: c, script: r.script, props: { locale: o, ...r.props } } : null;
|
|
439
|
-
}
|
|
440
|
-
function b({ state: e, componentId: t }) {
|
|
441
|
-
return e.components[t]?.data ?? e.resources.components?.[t]?.component;
|
|
442
|
-
}
|
|
443
|
-
function ct({ state: e, name: t }) {
|
|
444
|
-
const o = t.toLowerCase();
|
|
445
|
-
return Object.values(e.components).find((n) => n.data.name?.toLowerCase() === o)?.data ?? (e.resources.components && Object.values(e.resources.components).find((n) => n.component.name?.toLowerCase() === o))?.component;
|
|
446
|
-
}
|
|
447
|
-
async function je({
|
|
448
|
-
component: e,
|
|
449
|
-
script: t,
|
|
450
|
-
props: o,
|
|
451
|
-
req: n,
|
|
452
|
-
getServerSideProps: c
|
|
453
|
-
}) {
|
|
454
|
-
if (!c && !t?.includes("getServerSideProps"))
|
|
455
|
-
return null;
|
|
456
|
-
const r = c ?? await J(t, "getServerSideProps");
|
|
457
|
-
if (!r) return null;
|
|
458
|
-
const p = (r.match(/export\s*{\s*(\w+)\s+as\s+getServerSideProps\s*}/) || r.match(/export\s*{\s*getServerSideProps\s*}/))?.[1] || "getServerSideProps", d = new Promise((i) => {
|
|
459
|
-
setTimeout(() => {
|
|
460
|
-
i({});
|
|
461
|
-
}, F * 1e3);
|
|
462
|
-
});
|
|
463
|
-
let l = await G();
|
|
464
|
-
const m = {
|
|
465
|
-
componentMountPoints: h.components
|
|
466
|
-
};
|
|
467
|
-
return await Promise.race([
|
|
468
|
-
d,
|
|
469
|
-
l.callFunction({
|
|
470
|
-
code: `${r}
|
|
471
|
-
|
|
472
|
-
export async function getServerSidePropsWrapper(props) {
|
|
473
|
-
const { location, fetch, props: componentProps } = props;
|
|
474
|
-
// 使用局部变量而不是全局变量
|
|
475
|
-
const originalLocation = typeof window !== 'undefined' ? window.location : undefined;
|
|
476
|
-
const originalFetch = globalThis.fetch;
|
|
477
|
-
|
|
478
|
-
try {
|
|
479
|
-
globalThis.location = location;
|
|
480
|
-
globalThis.fetch = fetch;
|
|
481
|
-
return await ${p}(componentProps);
|
|
482
|
-
} finally {
|
|
483
|
-
// 清理全局状态
|
|
484
|
-
if (originalLocation) globalThis.location = originalLocation;
|
|
485
|
-
if (originalFetch) globalThis.fetch = originalFetch;
|
|
486
|
-
}
|
|
487
|
-
}`,
|
|
488
|
-
filename: `${e.name || e.id}.js`,
|
|
489
|
-
moduleLoader: (i) => {
|
|
490
|
-
if (i === "@blocklet/pages-kit/builtin/utils")
|
|
491
|
-
return ` const { joinURL, withQuery, getQuery, getComponentMountPoint } = globalThis
|
|
492
|
-
export { joinURL, withQuery, getQuery, getComponentMountPoint }
|
|
493
|
-
`;
|
|
494
|
-
if (i === "@blocklet/pages-kit/builtin/dayjs")
|
|
495
|
-
return v.dayjs;
|
|
496
|
-
if (i in v)
|
|
497
|
-
return v[i];
|
|
498
|
-
if (i in I) {
|
|
499
|
-
const s = I[i];
|
|
500
|
-
return ee(s) ? void 0 : s;
|
|
501
|
-
}
|
|
502
|
-
},
|
|
503
|
-
global: {
|
|
504
|
-
console: {
|
|
505
|
-
// NOTE: do not return logger.xxx result, it will cause memory leak
|
|
506
|
-
// eslint-disable-next-line prettier/prettier
|
|
507
|
-
log: (...i) => {
|
|
508
|
-
w.info(...i);
|
|
509
|
-
},
|
|
510
|
-
warn: (...i) => {
|
|
511
|
-
w.warn(...i);
|
|
512
|
-
},
|
|
513
|
-
error: (...i) => {
|
|
514
|
-
w.error(...i);
|
|
515
|
-
}
|
|
516
|
-
},
|
|
517
|
-
getComponentMountPoint: X,
|
|
518
|
-
joinURL: _,
|
|
519
|
-
withQuery: se,
|
|
520
|
-
getQuery: re,
|
|
521
|
-
window: {
|
|
522
|
-
blocklet: m
|
|
523
|
-
},
|
|
524
|
-
blocklet: m
|
|
525
|
-
},
|
|
526
|
-
functionName: "getServerSidePropsWrapper",
|
|
527
|
-
args: [
|
|
528
|
-
{
|
|
529
|
-
// NOTE: IMPORTANT! place location and fetch (has side effect) at the args not global
|
|
530
|
-
// because the global is shared between all runtime and just init once
|
|
531
|
-
location: { href: _(ce(n.hostname), n.originalUrl) },
|
|
532
|
-
fetch: (i, { ...s } = {}) => {
|
|
533
|
-
const a = typeof i == "string" && i.startsWith("/") ? _(h.env.appUrl, i) : i;
|
|
534
|
-
if (typeof a == "string" && R(a).host === R(h.env.appUrl).host) {
|
|
535
|
-
const f = n.get("cookie");
|
|
536
|
-
if (f) {
|
|
537
|
-
const S = new ne(s.headers);
|
|
538
|
-
S.set("cookie", f), s.headers = S;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
return oe(a, {
|
|
542
|
-
...s,
|
|
543
|
-
timeout: F * 1e3
|
|
544
|
-
}).then((f) => ({
|
|
545
|
-
ok: f.ok,
|
|
546
|
-
status: f.status,
|
|
547
|
-
statusText: f.statusText,
|
|
548
|
-
headers: Object.fromEntries(f.headers.entries()),
|
|
549
|
-
json: () => f.json()
|
|
550
|
-
}));
|
|
551
|
-
},
|
|
552
|
-
props: o
|
|
553
|
-
}
|
|
554
|
-
]
|
|
555
|
-
}).finally(() => {
|
|
556
|
-
l = null;
|
|
557
|
-
})
|
|
558
|
-
]);
|
|
559
|
-
}
|
|
560
|
-
const at = A(
|
|
561
|
-
async (e, t, o, n) => {
|
|
562
|
-
if (!e?.includes(t) && !n)
|
|
563
|
-
return null;
|
|
564
|
-
const c = n ?? await J(e, t);
|
|
565
|
-
if (c)
|
|
566
|
-
try {
|
|
567
|
-
let r = await G();
|
|
568
|
-
return await r.callFunction({
|
|
569
|
-
cache: !0,
|
|
570
|
-
code: `
|
|
571
|
-
${c}
|
|
572
|
-
|
|
573
|
-
export function get${t}SchemaWrapper() {
|
|
574
|
-
return ${t};
|
|
575
|
-
}
|
|
576
|
-
`,
|
|
577
|
-
filename: `${o}.js`,
|
|
578
|
-
functionName: `get${t}SchemaWrapper`
|
|
579
|
-
}).finally(() => {
|
|
580
|
-
r = null;
|
|
581
|
-
});
|
|
582
|
-
} catch (r) {
|
|
583
|
-
return w.error(`获取 ${t} 失败`, { componentId: o, error: r }), null;
|
|
584
|
-
}
|
|
585
|
-
return null;
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
subdir: "getExportSchemaValueFromCode"
|
|
589
|
-
}
|
|
590
|
-
), De = (e) => !!(e.renderer?.type === "react-component" && e.version && e.version >= 2);
|
|
591
|
-
export {
|
|
592
|
-
_e as C,
|
|
593
|
-
F as G,
|
|
594
|
-
qe as I,
|
|
595
|
-
ot as a,
|
|
596
|
-
at as b,
|
|
597
|
-
nt as c,
|
|
598
|
-
et as d,
|
|
599
|
-
V as e,
|
|
600
|
-
rt as f,
|
|
601
|
-
st as g,
|
|
602
|
-
Ie as h,
|
|
603
|
-
tt as i,
|
|
604
|
-
Oe as j,
|
|
605
|
-
b as k,
|
|
606
|
-
w as l,
|
|
607
|
-
A as m,
|
|
608
|
-
ct as n,
|
|
609
|
-
De as s
|
|
610
|
-
};
|