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