@blocklet/pages-kit-inner-components 0.7.5 → 0.7.7
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/chunks/{components-CnPdZJ2Z.js → components-aaduHC9E.js} +5 -5
- package/lib/cjs/chunks/site-state-DlfM55ST.js +1 -0
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/project-html.js +1 -1
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/chunks/{components-CcZk17uO.js → components-D4ywfyMi.js} +168 -164
- package/lib/es/chunks/{site-state-Ct2OR_RE.js → site-state-BR3S4pMJ.js} +499 -475
- package/lib/es/components.js +1 -1
- package/lib/es/project-html.js +1 -1
- package/lib/es/resources.js +2 -2
- package/lib/es/site-state.js +2 -2
- package/package.json +6 -6
- package/lib/cjs/chunks/site-state-D9DYye_t.js +0 -1
|
@@ -4,42 +4,42 @@ import { promises as y } from "fs";
|
|
|
4
4
|
import J, { join as N } from "path";
|
|
5
5
|
import h from "@blocklet/sdk/lib/config";
|
|
6
6
|
import q from "lodash/isNil";
|
|
7
|
-
import { getComponentMountPoint as
|
|
7
|
+
import { getComponentMountPoint as ee } from "@blocklet/pages-kit/builtin/utils";
|
|
8
8
|
import { PreloadComponentScriptModule as P } from "@blocklet/pages-kit/types";
|
|
9
9
|
import { BuiltinModules as A } from "@blocklet/pages-kit/utils/builtin";
|
|
10
|
-
import { componentUMDName as
|
|
11
|
-
import
|
|
12
|
-
import { LRUCache as
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import { joinURL as O, getQuery as
|
|
16
|
-
import
|
|
17
|
-
import { isRelativeModule as
|
|
10
|
+
import { componentUMDName as te, RenderNestedComponent as $, mergeComponent as oe } from "@blocklet/pages-kit/utils/property";
|
|
11
|
+
import ne from "lodash/isEmpty";
|
|
12
|
+
import { LRUCache as re } from "lru-cache";
|
|
13
|
+
import se, { Headers as ce } from "node-fetch";
|
|
14
|
+
import L from "p-limit";
|
|
15
|
+
import { joinURL as O, getQuery as ae, withQuery as ie, parseURL as k, withHttps as pe } from "ufo";
|
|
16
|
+
import le from "@blocklet/logger";
|
|
17
|
+
import { isRelativeModule as ue, createBuiltinModuleTransformer as de } from "@blocklet/pages-kit/utils/typescript/builtin-module-transformer";
|
|
18
18
|
import "@blocklet/sdk/lib/component";
|
|
19
19
|
h.env.mode;
|
|
20
20
|
h.env.TRANSLATE_ADDITIONAL_PROMPT || process.env.TRANSLATE_ADDITIONAL_PROMPT;
|
|
21
21
|
h.env.PAGE_CONTENT_ADDITIONAL_PROMPT || process.env.PAGE_CONTENT_ADDITIONAL_PROMPT;
|
|
22
|
-
const
|
|
22
|
+
const nt = "image-bin";
|
|
23
23
|
h.env.INIT_TEMPLATE_PATH;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
24
|
+
const rt = process.env.DATABASE_URL || J.join(h.env.dataDir, "db/pages-kit.db"), F = h, st = () => h.env.tenantMode === "multiple", ct = () => (q(F.env.preferences.multiTenantAllProjectAccessPassports) ? [] : F.env.preferences.multiTenantAllProjectAccessPassports?.split(",")) || [], me = J.join(h.env.dataDir, "fs-memoize-cache"), fe = h.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", g = le("pages-kit"), he = me, we = fe, v = 30 * 24 * 60 * 60 * 1e3, ge = 24 * 60 * 60 * 1e3, K = async (e = "") => {
|
|
25
|
+
const t = N(he, e);
|
|
26
26
|
try {
|
|
27
|
-
if (!(await y.stat(
|
|
28
|
-
throw new Error(`${
|
|
27
|
+
if (!(await y.stat(t)).isDirectory())
|
|
28
|
+
throw new Error(`${t} is not a directory`);
|
|
29
29
|
} catch {
|
|
30
|
-
await y.mkdir(
|
|
30
|
+
await y.mkdir(t, { recursive: !0 });
|
|
31
31
|
}
|
|
32
|
-
return
|
|
33
|
-
}, U = (
|
|
34
|
-
const o = Y("md5").update(
|
|
35
|
-
return N(
|
|
36
|
-
},
|
|
37
|
-
const
|
|
32
|
+
return t;
|
|
33
|
+
}, U = (e, ...t) => e.keyGenerator ? e.keyGenerator(...t) : JSON.stringify([e.subdir || "", ...t]), ye = (e, t) => {
|
|
34
|
+
const o = Y("md5").update(t).digest("hex");
|
|
35
|
+
return N(e, `${we}-${o}.json`);
|
|
36
|
+
}, xe = async (e = "") => {
|
|
37
|
+
const t = await K(e), o = Date.now();
|
|
38
38
|
try {
|
|
39
|
-
const n = await y.readdir(
|
|
39
|
+
const n = await y.readdir(t);
|
|
40
40
|
await Promise.all(
|
|
41
41
|
n.filter((s) => s.endsWith(".json")).map(async (s) => {
|
|
42
|
-
const r = N(
|
|
42
|
+
const r = N(t, s);
|
|
43
43
|
try {
|
|
44
44
|
const l = await y.readFile(r, "utf-8"), a = JSON.parse(l);
|
|
45
45
|
a.createdAt && o - a.createdAt > v && await y.unlink(r);
|
|
@@ -53,20 +53,20 @@ const re = process.env.DATABASE_URL || J.join(h.env.dataDir, "db/pages-kit.db"),
|
|
|
53
53
|
})
|
|
54
54
|
);
|
|
55
55
|
} catch (n) {
|
|
56
|
-
console.error(`Failed to cleanup cache in ${
|
|
56
|
+
console.error(`Failed to cleanup cache in ${t}:`, n);
|
|
57
57
|
}
|
|
58
|
-
},
|
|
59
|
-
const
|
|
58
|
+
}, Se = (() => {
|
|
59
|
+
const e = /* @__PURE__ */ new Set();
|
|
60
60
|
return setInterval(async () => {
|
|
61
|
-
await Promise.all(Array.from(
|
|
62
|
-
},
|
|
63
|
-
|
|
61
|
+
await Promise.all(Array.from(e).map((n) => xe(n)));
|
|
62
|
+
}, ge).unref(), (n) => {
|
|
63
|
+
e.add(n);
|
|
64
64
|
};
|
|
65
65
|
})();
|
|
66
|
-
function j(
|
|
67
|
-
return
|
|
66
|
+
function j(e, t) {
|
|
67
|
+
return t.subdir && Se(t.subdir), X(
|
|
68
68
|
async (...n) => {
|
|
69
|
-
const s = await K(
|
|
69
|
+
const s = await K(t.subdir || ""), r = U(t, ...n), l = ye(s, r);
|
|
70
70
|
try {
|
|
71
71
|
const a = await y.readFile(l, "utf-8"), { value: m, createdAt: i } = JSON.parse(a);
|
|
72
72
|
if (i && Date.now() - i > v)
|
|
@@ -74,27 +74,27 @@ function j(t, e) {
|
|
|
74
74
|
}), new Error("Cache expired");
|
|
75
75
|
return m;
|
|
76
76
|
} catch {
|
|
77
|
-
const m = await
|
|
77
|
+
const m = await e(...n), i = JSON.stringify({ value: m, createdAt: Date.now() });
|
|
78
78
|
return y.writeFile(l, i, "utf-8").catch((f) => {
|
|
79
79
|
console.error("Failed to write fs cache:", f);
|
|
80
80
|
}), m;
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
|
-
keyGenerator: (...n) => U(
|
|
85
|
-
lruOptions:
|
|
84
|
+
keyGenerator: (...n) => U(t, ...n),
|
|
85
|
+
lruOptions: t.lruOptions || {
|
|
86
86
|
max: 100,
|
|
87
87
|
ttl: v
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
|
-
const G = async () => await import("typescript"),
|
|
92
|
+
const G = async () => await import("typescript"), Ce = async () => await import("esbuild"), Ee = async () => (await import("postcss")).default, Pe = async () => (await import("tailwindcss")).default, Te = async () => (await import("autoprefixer")).default, be = !1, Me = async (e, { componentId: t }) => {
|
|
93
93
|
const o = `@tailwind components;
|
|
94
94
|
@tailwind utilities;
|
|
95
|
-
`, n = `.CustomComponent_${
|
|
95
|
+
`, n = `.CustomComponent_${t}`, s = await Ee(), r = await Pe(), l = await Te();
|
|
96
96
|
return (await s([
|
|
97
|
-
r({ content: [{ raw:
|
|
97
|
+
r({ content: [{ raw: e, extension: "tsx" }] }),
|
|
98
98
|
l({
|
|
99
99
|
overrideBrowserslist: ["> 1%", "last 2 versions"],
|
|
100
100
|
stats: {}
|
|
@@ -107,27 +107,27 @@ const G = async () => await import("typescript"), Ct = async () => await import(
|
|
|
107
107
|
// FIXME: cssnano use browserslist, it is not working with the fs isolation
|
|
108
108
|
// cssnano({ preset: 'default' }),
|
|
109
109
|
]).process(o)).css;
|
|
110
|
-
},
|
|
111
|
-
const o = await
|
|
110
|
+
}, ve = async (e, { componentId: t }) => {
|
|
111
|
+
const o = await Me(e, { componentId: t });
|
|
112
112
|
return `export const __PagesKit_CSS__ = ${JSON.stringify(o)};
|
|
113
113
|
|
|
114
|
-
${
|
|
114
|
+
${e}
|
|
115
115
|
`;
|
|
116
116
|
}, H = j(
|
|
117
|
-
async (
|
|
117
|
+
async (e, t) => {
|
|
118
118
|
let o = await G();
|
|
119
119
|
try {
|
|
120
|
-
let n = o.transpileModule(
|
|
120
|
+
let n = o.transpileModule(e, {
|
|
121
121
|
compilerOptions: {
|
|
122
122
|
jsx: o.JsxEmit.React,
|
|
123
123
|
target: o.ScriptTarget.ES2016,
|
|
124
124
|
module: o.ModuleKind.ESNext
|
|
125
125
|
},
|
|
126
126
|
transformers: {
|
|
127
|
-
before: [
|
|
127
|
+
before: [de(o)]
|
|
128
128
|
}
|
|
129
129
|
}).outputText;
|
|
130
|
-
if (
|
|
130
|
+
if (t.tailwind && (n = await ve(n, { componentId: t.componentId })), t.module === P.ESM) return n;
|
|
131
131
|
const s = o.transpileModule(n, {
|
|
132
132
|
compilerOptions: {
|
|
133
133
|
jsx: o.JsxEmit.React,
|
|
@@ -136,7 +136,7 @@ ${t}
|
|
|
136
136
|
moduleResolution: o.ModuleResolutionKind.Node16
|
|
137
137
|
}
|
|
138
138
|
}).outputText;
|
|
139
|
-
return
|
|
139
|
+
return t.module === P.CJS ? s : W(t.moduleName, s);
|
|
140
140
|
} catch (n) {
|
|
141
141
|
throw new Error(n);
|
|
142
142
|
} finally {
|
|
@@ -146,8 +146,8 @@ ${t}
|
|
|
146
146
|
{
|
|
147
147
|
subdir: "transpileModule"
|
|
148
148
|
}
|
|
149
|
-
),
|
|
150
|
-
let { build: o } = await
|
|
149
|
+
), _e = async (e, t) => {
|
|
150
|
+
let { build: o } = await Ce(), n = null;
|
|
151
151
|
try {
|
|
152
152
|
const r = (await o({
|
|
153
153
|
entryPoints: ["index.tsx"],
|
|
@@ -162,10 +162,10 @@ ${t}
|
|
|
162
162
|
setup(m) {
|
|
163
163
|
m.onResolve({ filter: /.*/ }, (i) => i.path === "index.tsx" ? { path: "index.tsx", namespace: "vfs" } : i.path === "./component" ? { path: "component.tsx", namespace: "vfs" } : null), m.onLoad({ filter: /.*/, namespace: "vfs" }, async (i) => {
|
|
164
164
|
if (i.path === "index.tsx")
|
|
165
|
-
return { contents: `export { ${
|
|
165
|
+
return { contents: `export { ${t} } from './component'`, loader: "tsx" };
|
|
166
166
|
if (i.path === "component.tsx")
|
|
167
|
-
return { contents:
|
|
168
|
-
if (
|
|
167
|
+
return { contents: e, loader: "tsx" };
|
|
168
|
+
if (ue(i.path)) {
|
|
169
169
|
const f = i.path.split("/").pop();
|
|
170
170
|
}
|
|
171
171
|
return null;
|
|
@@ -184,19 +184,19 @@ ${t}
|
|
|
184
184
|
} finally {
|
|
185
185
|
o = null, n = null;
|
|
186
186
|
}
|
|
187
|
-
},
|
|
188
|
-
`export\\s+\\{[^}]*(?:\\w+\\s+as\\s+${
|
|
187
|
+
}, Ie = (e, t) => new RegExp(
|
|
188
|
+
`export\\s+\\{[^}]*(?:\\w+\\s+as\\s+${t}\\b|\\b${t}\\b)[^}]*\\}`,
|
|
189
189
|
"m"
|
|
190
|
-
).test(
|
|
191
|
-
async (
|
|
192
|
-
const o = await
|
|
193
|
-
return
|
|
190
|
+
).test(e) ? e : void 0, V = j(
|
|
191
|
+
async (e, t) => {
|
|
192
|
+
const o = await _e(e, t);
|
|
193
|
+
return Ie(o, t);
|
|
194
194
|
},
|
|
195
195
|
{
|
|
196
196
|
subdir: "extractExportValueSchema"
|
|
197
197
|
}
|
|
198
|
-
), W = (
|
|
199
|
-
var ${
|
|
198
|
+
), W = (e, t) => `// GENERATED FILE. DO NOT EDIT.
|
|
199
|
+
var ${e} = async function () {
|
|
200
200
|
|
|
201
201
|
const exports = {};
|
|
202
202
|
let moduleExports = null;
|
|
@@ -205,7 +205,7 @@ var ${t} = async function () {
|
|
|
205
205
|
const module = { exports: moduleExports };
|
|
206
206
|
|
|
207
207
|
// execute component code
|
|
208
|
-
${
|
|
208
|
+
${t}
|
|
209
209
|
|
|
210
210
|
// handle possible module.exports
|
|
211
211
|
if (module.exports && module.exports !== moduleExports) {
|
|
@@ -222,39 +222,43 @@ var ${t} = async function () {
|
|
|
222
222
|
return exports;
|
|
223
223
|
};
|
|
224
224
|
`, Q = async () => {
|
|
225
|
-
const { Sandbox:
|
|
226
|
-
return
|
|
225
|
+
const { Sandbox: e } = await import("@blocklet/quickjs");
|
|
226
|
+
return e;
|
|
227
227
|
};
|
|
228
|
-
function
|
|
229
|
-
return
|
|
228
|
+
function Oe(e) {
|
|
229
|
+
return e?.type === "react-component";
|
|
230
230
|
}
|
|
231
|
-
const E = new
|
|
231
|
+
const E = new re({
|
|
232
232
|
max: 600,
|
|
233
233
|
ttl: 1e3 * 60 * 60 * 24 * 7
|
|
234
234
|
// default ttl is 7 days
|
|
235
|
-
}),
|
|
236
|
-
function z(
|
|
237
|
-
g.info("clear preload components cache", { cacheKey:
|
|
235
|
+
}), Ae = 60 * 60, B = 10;
|
|
236
|
+
function z(e) {
|
|
237
|
+
g.info("clear preload components cache", { cacheKey: e }), E.delete(e);
|
|
238
238
|
}
|
|
239
|
-
function
|
|
240
|
-
|
|
241
|
-
|
|
239
|
+
function at(e) {
|
|
240
|
+
let t = 0;
|
|
241
|
+
for (const o of E.keys())
|
|
242
|
+
o.includes(e) && (t++, z(o));
|
|
243
|
+
g.info(`clear preload components cache by mode ${e}, cleared ${t} entries`);
|
|
242
244
|
}
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
245
|
+
function it(e) {
|
|
246
|
+
let t = 0;
|
|
247
|
+
for (const o of E.keys())
|
|
248
|
+
o.includes(e) && (t++, z(o));
|
|
249
|
+
g.info(`clear preload components cache by instanceId ${e}, cleared ${t} entries`);
|
|
246
250
|
}
|
|
247
|
-
function
|
|
248
|
-
mode:
|
|
249
|
-
instanceId:
|
|
251
|
+
function Ne({
|
|
252
|
+
mode: e,
|
|
253
|
+
instanceId: t,
|
|
250
254
|
componentId: o,
|
|
251
255
|
locale: n
|
|
252
256
|
}) {
|
|
253
|
-
return ["getPreloadComponents",
|
|
257
|
+
return ["getPreloadComponents", e, t, o, n].join("-");
|
|
254
258
|
}
|
|
255
|
-
async function
|
|
256
|
-
mode:
|
|
257
|
-
req:
|
|
259
|
+
async function pt({
|
|
260
|
+
mode: e,
|
|
261
|
+
req: t,
|
|
258
262
|
state: o,
|
|
259
263
|
locale: n,
|
|
260
264
|
instances: s,
|
|
@@ -265,22 +269,22 @@ async function pe({
|
|
|
265
269
|
config: { defaultLocale: a }
|
|
266
270
|
} = o;
|
|
267
271
|
if (!a) return null;
|
|
268
|
-
const m =
|
|
272
|
+
const m = L(6), i = (await Promise.all(
|
|
269
273
|
s.map(
|
|
270
274
|
(p) => m(async () => {
|
|
271
275
|
try {
|
|
272
|
-
const u =
|
|
273
|
-
mode:
|
|
276
|
+
const u = Ne({
|
|
277
|
+
mode: e,
|
|
274
278
|
instanceId: p.id,
|
|
275
279
|
componentId: p.componentId,
|
|
276
280
|
locale: n
|
|
277
281
|
});
|
|
278
|
-
if (
|
|
282
|
+
if (e !== "draft" && p.useCache && E.has(u))
|
|
279
283
|
return g.info(`get preload component from cache: ${u}`), E.get(u);
|
|
280
284
|
const d = _({ state: o, componentId: p.componentId });
|
|
281
285
|
if (!d) return null;
|
|
282
|
-
const S = await
|
|
283
|
-
req:
|
|
286
|
+
const S = await je({
|
|
287
|
+
req: t,
|
|
284
288
|
state: o,
|
|
285
289
|
componentId: d.id,
|
|
286
290
|
locale: n,
|
|
@@ -289,8 +293,8 @@ async function pe({
|
|
|
289
293
|
});
|
|
290
294
|
if (!S) return null;
|
|
291
295
|
const T = { instanceId: p.id, preload: S };
|
|
292
|
-
if (
|
|
293
|
-
let C =
|
|
296
|
+
if (e !== "draft" && p.useCache) {
|
|
297
|
+
let C = Ae;
|
|
294
298
|
p.cacheDuration && (C = p.cacheDuration), g.info(`set preload component to cache(${C}s): ${u}`), E.set(u, T, {
|
|
295
299
|
ttl: C * 1e3
|
|
296
300
|
});
|
|
@@ -309,28 +313,28 @@ async function pe({
|
|
|
309
313
|
i.reduce((p, u) => ({ ...p, ...u.preload.components }), {})
|
|
310
314
|
);
|
|
311
315
|
async function x() {
|
|
312
|
-
const p =
|
|
316
|
+
const p = L(10), u = await Promise.all(
|
|
313
317
|
f.map(
|
|
314
318
|
(d) => p(async () => {
|
|
315
|
-
const S = r === P.ESM, T = r === P.UMD_FN, C = r === P.CJS,
|
|
316
|
-
let
|
|
319
|
+
const S = r === P.ESM, T = r === P.UMD_FN, C = r === P.CJS, b = S ? "" : te({ componentId: d.component.id }), D = Le(d.component);
|
|
320
|
+
let M = {
|
|
317
321
|
module: r,
|
|
318
322
|
script: "",
|
|
319
|
-
moduleName:
|
|
323
|
+
moduleName: b
|
|
320
324
|
};
|
|
321
325
|
if (D && d.component.renderer?.type === "react-component" && S && d.component.renderer?.script)
|
|
322
|
-
|
|
326
|
+
M.script = d.component.renderer?.script;
|
|
323
327
|
else if (D && d.component.renderer?.type === "react-component" && (C || T) && d.component.renderer?.cjsScript) {
|
|
324
328
|
const R = d.component.renderer.cjsScript;
|
|
325
|
-
|
|
329
|
+
M.script = C ? R : W(b, R);
|
|
326
330
|
} else
|
|
327
|
-
|
|
331
|
+
M = S ? {
|
|
328
332
|
// ESM
|
|
329
333
|
module: r,
|
|
330
334
|
script: await H(d.script, {
|
|
331
335
|
componentId: d.component.id,
|
|
332
336
|
module: r,
|
|
333
|
-
tailwind:
|
|
337
|
+
tailwind: e !== "draft"
|
|
334
338
|
})
|
|
335
339
|
} : {
|
|
336
340
|
// CJS OR UMD
|
|
@@ -338,12 +342,12 @@ async function pe({
|
|
|
338
342
|
script: await H(d.script, {
|
|
339
343
|
componentId: d.component.id,
|
|
340
344
|
module: r,
|
|
341
|
-
moduleName:
|
|
342
|
-
tailwind:
|
|
345
|
+
moduleName: b,
|
|
346
|
+
tailwind: e !== "draft"
|
|
343
347
|
}),
|
|
344
|
-
moduleName:
|
|
348
|
+
moduleName: b
|
|
345
349
|
};
|
|
346
|
-
return [d.component.id, { component: d.component, script:
|
|
350
|
+
return [d.component.id, { component: d.component, script: M }];
|
|
347
351
|
})
|
|
348
352
|
)
|
|
349
353
|
);
|
|
@@ -360,36 +364,36 @@ async function pe({
|
|
|
360
364
|
}))
|
|
361
365
|
};
|
|
362
366
|
}
|
|
363
|
-
async function
|
|
364
|
-
req:
|
|
365
|
-
state:
|
|
367
|
+
async function je({
|
|
368
|
+
req: e,
|
|
369
|
+
state: t,
|
|
366
370
|
componentId: o,
|
|
367
371
|
locale: n,
|
|
368
372
|
defaultLocale: s,
|
|
369
373
|
properties: r
|
|
370
374
|
}) {
|
|
371
|
-
const { supportedLocales: l } =
|
|
375
|
+
const { supportedLocales: l } = t, a = _({ state: t, componentId: o });
|
|
372
376
|
if (!a) return null;
|
|
373
377
|
const m = l.some((f) => f.locale === n) ? n : s;
|
|
374
378
|
if (!m) return null;
|
|
375
|
-
const i = await Z({ req:
|
|
379
|
+
const i = await Z({ req: e, state: t, componentId: o, locale: m, defaultLocale: s, properties: r });
|
|
376
380
|
return i ? {
|
|
377
381
|
component: a,
|
|
378
382
|
...i
|
|
379
383
|
} : null;
|
|
380
384
|
}
|
|
381
|
-
const
|
|
385
|
+
const De = 20;
|
|
382
386
|
async function Z({
|
|
383
|
-
req:
|
|
384
|
-
depth:
|
|
387
|
+
req: e,
|
|
388
|
+
depth: t = 0,
|
|
385
389
|
state: o,
|
|
386
390
|
componentId: n,
|
|
387
391
|
locale: s,
|
|
388
392
|
defaultLocale: r,
|
|
389
393
|
properties: l
|
|
390
394
|
}) {
|
|
391
|
-
if (
|
|
392
|
-
const a =
|
|
395
|
+
if (t > De) throw new RangeError("max component depth exceeded");
|
|
396
|
+
const a = Re({ state: o, componentId: n, properties: l, locale: s });
|
|
393
397
|
if (!a) return null;
|
|
394
398
|
const { props: m, component: i } = a, f = {
|
|
395
399
|
locale: s || r,
|
|
@@ -397,17 +401,17 @@ async function Z({
|
|
|
397
401
|
props: { ...m }
|
|
398
402
|
};
|
|
399
403
|
try {
|
|
400
|
-
const x =
|
|
404
|
+
const x = Oe(i.renderer) ? i.renderer.getServerSideProps : void 0, c = await $e({ ...a, req: e, getServerSideProps: x });
|
|
401
405
|
c?.props && Object.assign(f.props, c.props);
|
|
402
406
|
} catch (x) {
|
|
403
407
|
g.error("preload data at server side error", { componentId: n, name: a.component.name }, { error: x });
|
|
404
408
|
}
|
|
405
409
|
return await Promise.all(
|
|
406
410
|
Object.entries(m).map(async ([x, c]) => {
|
|
407
|
-
if (c?.type ===
|
|
411
|
+
if (c?.type === $) {
|
|
408
412
|
const w = await Z({
|
|
409
|
-
req:
|
|
410
|
-
depth:
|
|
413
|
+
req: e,
|
|
414
|
+
depth: t + 1,
|
|
411
415
|
state: o,
|
|
412
416
|
componentId: c.componentId,
|
|
413
417
|
locale: s,
|
|
@@ -416,7 +420,7 @@ async function Z({
|
|
|
416
420
|
});
|
|
417
421
|
w && (Object.assign(f.components, w.components), Object.assign(f.props, {
|
|
418
422
|
[x]: {
|
|
419
|
-
type:
|
|
423
|
+
type: $,
|
|
420
424
|
componentId: c.componentId,
|
|
421
425
|
props: w.props
|
|
422
426
|
}
|
|
@@ -425,40 +429,40 @@ async function Z({
|
|
|
425
429
|
})
|
|
426
430
|
), f;
|
|
427
431
|
}
|
|
428
|
-
function
|
|
429
|
-
state:
|
|
430
|
-
componentId:
|
|
432
|
+
function Re({
|
|
433
|
+
state: e,
|
|
434
|
+
componentId: t,
|
|
431
435
|
locale: o,
|
|
432
436
|
properties: n
|
|
433
437
|
}) {
|
|
434
|
-
const s = _({ state:
|
|
438
|
+
const s = _({ state: e, componentId: t });
|
|
435
439
|
if (!s) return null;
|
|
436
|
-
const r =
|
|
437
|
-
componentId:
|
|
438
|
-
getComponent: (l) => _({ state:
|
|
440
|
+
const r = oe({
|
|
441
|
+
componentId: t,
|
|
442
|
+
getComponent: (l) => _({ state: e, componentId: l }),
|
|
439
443
|
locale: o,
|
|
440
|
-
defaultLocale:
|
|
444
|
+
defaultLocale: e.config.defaultLocale,
|
|
441
445
|
properties: n
|
|
442
446
|
});
|
|
443
447
|
return r ? { component: s, script: r.script, props: { locale: o, ...r.props } } : null;
|
|
444
448
|
}
|
|
445
|
-
function _({ state:
|
|
446
|
-
return
|
|
449
|
+
function _({ state: e, componentId: t }) {
|
|
450
|
+
return e.components[t]?.data ?? e.resources.components?.[t]?.component;
|
|
447
451
|
}
|
|
448
|
-
function
|
|
449
|
-
const o =
|
|
450
|
-
return Object.values(
|
|
452
|
+
function lt({ state: e, name: t }) {
|
|
453
|
+
const o = t.toLowerCase();
|
|
454
|
+
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;
|
|
451
455
|
}
|
|
452
|
-
async function
|
|
453
|
-
component:
|
|
454
|
-
script:
|
|
456
|
+
async function $e({
|
|
457
|
+
component: e,
|
|
458
|
+
script: t,
|
|
455
459
|
props: o,
|
|
456
460
|
req: n,
|
|
457
461
|
getServerSideProps: s
|
|
458
462
|
}) {
|
|
459
|
-
if (!s && !
|
|
463
|
+
if (!s && !t?.includes("getServerSideProps"))
|
|
460
464
|
return null;
|
|
461
|
-
const r = s ?? await V(
|
|
465
|
+
const r = s ?? await V(t, "getServerSideProps");
|
|
462
466
|
if (!r) return null;
|
|
463
467
|
const a = (r.match(/export\s*{\s*(\w+)\s+as\s+getServerSideProps\s*}/) || r.match(/export\s*{\s*getServerSideProps\s*}/))?.[1] || "getServerSideProps", m = new Promise((c) => {
|
|
464
468
|
setTimeout(() => {
|
|
@@ -490,7 +494,7 @@ try {
|
|
|
490
494
|
if (originalFetch) globalThis.fetch = originalFetch;
|
|
491
495
|
}
|
|
492
496
|
}`,
|
|
493
|
-
filename: `${
|
|
497
|
+
filename: `${e.name || e.id}.js`,
|
|
494
498
|
moduleLoader: (c) => {
|
|
495
499
|
if (c === "@blocklet/pages-kit/builtin/utils")
|
|
496
500
|
return ` const { joinURL, withQuery, getQuery, getComponentMountPoint } = globalThis
|
|
@@ -502,7 +506,7 @@ try {
|
|
|
502
506
|
return I[c];
|
|
503
507
|
if (c in A) {
|
|
504
508
|
const w = A[c];
|
|
505
|
-
return
|
|
509
|
+
return ne(w) ? void 0 : w;
|
|
506
510
|
}
|
|
507
511
|
},
|
|
508
512
|
global: {
|
|
@@ -519,10 +523,10 @@ try {
|
|
|
519
523
|
g.error(...c);
|
|
520
524
|
}
|
|
521
525
|
},
|
|
522
|
-
getComponentMountPoint:
|
|
526
|
+
getComponentMountPoint: ee,
|
|
523
527
|
joinURL: O,
|
|
524
|
-
withQuery:
|
|
525
|
-
getQuery:
|
|
528
|
+
withQuery: ie,
|
|
529
|
+
getQuery: ae,
|
|
526
530
|
window: {
|
|
527
531
|
blocklet: f
|
|
528
532
|
},
|
|
@@ -533,17 +537,17 @@ try {
|
|
|
533
537
|
{
|
|
534
538
|
// NOTE: IMPORTANT! place location and fetch (has side effect) at the args not global
|
|
535
539
|
// because the global is shared between all runtime and just init once
|
|
536
|
-
location: { href: O(
|
|
540
|
+
location: { href: O(pe(n.hostname), n.originalUrl) },
|
|
537
541
|
fetch: (c, { ...w } = {}) => {
|
|
538
542
|
const p = typeof c == "string" && c.startsWith("/") ? O(h.env.appUrl, c) : c;
|
|
539
543
|
if (typeof p == "string" && k(p).host === k(h.env.appUrl).host) {
|
|
540
544
|
const u = n.get("cookie");
|
|
541
545
|
if (u) {
|
|
542
|
-
const d = new
|
|
546
|
+
const d = new ce(w.headers);
|
|
543
547
|
d.set("cookie", u), w.headers = d;
|
|
544
548
|
}
|
|
545
549
|
}
|
|
546
|
-
return
|
|
550
|
+
return se(p, {
|
|
547
551
|
...w,
|
|
548
552
|
timeout: B * 1e3
|
|
549
553
|
}).then((u) => ({
|
|
@@ -562,11 +566,11 @@ try {
|
|
|
562
566
|
})
|
|
563
567
|
]);
|
|
564
568
|
}
|
|
565
|
-
const
|
|
566
|
-
async (
|
|
567
|
-
if (!
|
|
569
|
+
const ut = j(
|
|
570
|
+
async (e, t, o, n) => {
|
|
571
|
+
if (!e?.includes(t) && !n)
|
|
568
572
|
return null;
|
|
569
|
-
const s = n ?? await V(
|
|
573
|
+
const s = n ?? await V(e, t);
|
|
570
574
|
if (s)
|
|
571
575
|
try {
|
|
572
576
|
let r = await Q();
|
|
@@ -575,41 +579,41 @@ const ue = j(
|
|
|
575
579
|
code: `
|
|
576
580
|
${s}
|
|
577
581
|
|
|
578
|
-
export function get${
|
|
579
|
-
return ${
|
|
582
|
+
export function get${t}SchemaWrapper() {
|
|
583
|
+
return ${t};
|
|
580
584
|
}
|
|
581
585
|
`,
|
|
582
586
|
filename: `${o}.js`,
|
|
583
|
-
functionName: `get${
|
|
587
|
+
functionName: `get${t}SchemaWrapper`
|
|
584
588
|
}).finally(() => {
|
|
585
589
|
r = null;
|
|
586
590
|
});
|
|
587
591
|
} catch (r) {
|
|
588
|
-
return g.error(`获取 ${
|
|
592
|
+
return g.error(`获取 ${t} 失败`, { componentId: o, error: r }), null;
|
|
589
593
|
}
|
|
590
594
|
return null;
|
|
591
595
|
},
|
|
592
596
|
{
|
|
593
597
|
subdir: "getExportSchemaValueFromCode"
|
|
594
598
|
}
|
|
595
|
-
),
|
|
599
|
+
), Le = (e) => !!(e.renderer?.type === "react-component" && e.version && e.version >= 2);
|
|
596
600
|
export {
|
|
597
|
-
|
|
601
|
+
Ae as C,
|
|
598
602
|
B as G,
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
603
|
+
nt as I,
|
|
604
|
+
ct as a,
|
|
605
|
+
ut as b,
|
|
606
|
+
at as c,
|
|
607
|
+
rt as d,
|
|
604
608
|
z as e,
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
609
|
+
it as f,
|
|
610
|
+
pt as g,
|
|
611
|
+
Ne as h,
|
|
612
|
+
st as i,
|
|
613
|
+
je as j,
|
|
610
614
|
_ as k,
|
|
611
615
|
g as l,
|
|
612
616
|
j as m,
|
|
613
|
-
|
|
614
|
-
|
|
617
|
+
lt as n,
|
|
618
|
+
Le as s
|
|
615
619
|
};
|