@blocklet/pages-kit-inner-components 0.7.4 → 0.7.6

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.
@@ -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 tt } from "@blocklet/pages-kit/builtin/utils";
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 et, RenderNestedComponent as L, mergeComponent as ot } from "@blocklet/pages-kit/utils/property";
11
- import nt from "lodash/isEmpty";
12
- import { LRUCache as rt } from "lru-cache";
13
- import st, { Headers as ct } from "node-fetch";
14
- import $ from "p-limit";
15
- import { joinURL as O, getQuery as at, withQuery as it, parseURL as k, withHttps as pt } from "ufo";
16
- import lt from "@blocklet/logger";
17
- import { isRelativeModule as ut, createBuiltinModuleTransformer as dt } from "@blocklet/pages-kit/utils/typescript/builtin-module-transformer";
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 ne = "image-bin";
22
+ const nt = "image-bin";
23
23
  h.env.INIT_TEMPLATE_PATH;
24
- const re = process.env.DATABASE_URL || J.join(h.env.dataDir, "db/pages-kit.db"), F = h, se = () => h.env.tenantMode === "multiple", ce = () => (q(F.env.preferences.multiTenantAllProjectAccessPassports) ? [] : F.env.preferences.multiTenantAllProjectAccessPassports?.split(",")) || [], mt = J.join(h.env.dataDir, "fs-memoize-cache"), ft = h.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", g = lt("pages-kit"), ht = mt, wt = ft, v = 30 * 24 * 60 * 60 * 1e3, gt = 24 * 60 * 60 * 1e3, K = async (t = "") => {
25
- const e = N(ht, t);
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(e)).isDirectory())
28
- throw new Error(`${e} is not a directory`);
27
+ if (!(await y.stat(t)).isDirectory())
28
+ throw new Error(`${t} is not a directory`);
29
29
  } catch {
30
- await y.mkdir(e, { recursive: !0 });
30
+ await y.mkdir(t, { recursive: !0 });
31
31
  }
32
- return e;
33
- }, U = (t, ...e) => t.keyGenerator ? t.keyGenerator(...e) : JSON.stringify([t.subdir || "", ...e]), yt = (t, e) => {
34
- const o = Y("md5").update(e).digest("hex");
35
- return N(t, `${wt}-${o}.json`);
36
- }, xt = async (t = "") => {
37
- const e = await K(t), o = Date.now();
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(e);
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(e, s);
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 ${e}:`, n);
56
+ console.error(`Failed to cleanup cache in ${t}:`, n);
57
57
  }
58
- }, St = (() => {
59
- const t = /* @__PURE__ */ new Set();
58
+ }, Se = (() => {
59
+ const e = /* @__PURE__ */ new Set();
60
60
  return setInterval(async () => {
61
- await Promise.all(Array.from(t).map((n) => xt(n)));
62
- }, gt).unref(), (n) => {
63
- t.add(n);
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(t, e) {
67
- return e.subdir && St(e.subdir), X(
66
+ function j(e, t) {
67
+ return t.subdir && Se(t.subdir), X(
68
68
  async (...n) => {
69
- const s = await K(e.subdir || ""), r = U(e, ...n), l = yt(s, r);
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 t(...n), i = JSON.stringify({ value: m, createdAt: Date.now() });
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(e, ...n),
85
- lruOptions: e.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"), Ct = async () => await import("esbuild"), Et = async () => (await import("postcss")).default, Pt = async () => (await import("tailwindcss")).default, Tt = async () => (await import("autoprefixer")).default, Mt = !1, bt = async (t, { componentId: e }) => {
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_${e}`, s = await Et(), r = await Pt(), l = await Tt();
95
+ `, n = `.CustomComponent_${t}`, s = await Ee(), r = await Pe(), l = await Te();
96
96
  return (await s([
97
- r({ content: [{ raw: t, extension: "tsx" }] }),
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
- }, vt = async (t, { componentId: e }) => {
111
- const o = await bt(t, { componentId: e });
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
- ${t}
114
+ ${e}
115
115
  `;
116
116
  }, H = j(
117
- async (t, e) => {
117
+ async (e, t) => {
118
118
  let o = await G();
119
119
  try {
120
- let n = o.transpileModule(t, {
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: [dt(o)]
127
+ before: [de(o)]
128
128
  }
129
129
  }).outputText;
130
- if (e.tailwind && (n = await vt(n, { componentId: e.componentId })), e.module === P.ESM) return n;
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 e.module === P.CJS ? s : W(e.moduleName, s);
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
- ), _t = async (t, e) => {
150
- let { build: o } = await Ct(), n = null;
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 { ${e} } from './component'`, loader: "tsx" };
165
+ return { contents: `export { ${t} } from './component'`, loader: "tsx" };
166
166
  if (i.path === "component.tsx")
167
- return { contents: t, loader: "tsx" };
168
- if (ut(i.path)) {
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
- }, It = (t, e) => new RegExp(
188
- `export\\s+\\{[^}]*(?:\\w+\\s+as\\s+${e}\\b|\\b${e}\\b)[^}]*\\}`,
187
+ }, Ie = (e, t) => new RegExp(
188
+ `export\\s+\\{[^}]*(?:\\w+\\s+as\\s+${t}\\b|\\b${t}\\b)[^}]*\\}`,
189
189
  "m"
190
- ).test(t) ? t : void 0, V = j(
191
- async (t, e) => {
192
- const o = await _t(t, e);
193
- return It(o, e);
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 = (t, e) => `// GENERATED FILE. DO NOT EDIT.
199
- var ${t} = async function () {
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
- ${e}
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: t } = await import("@blocklet/quickjs");
226
- return t;
225
+ const { Sandbox: e } = await import("@blocklet/quickjs");
226
+ return e;
227
227
  };
228
- function Ot(t) {
229
- return t?.type === "react-component";
228
+ function Oe(e) {
229
+ return e?.type === "react-component";
230
230
  }
231
- const E = new rt({
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
- }), At = 60 * 60, B = 10;
236
- function z(t) {
237
- g.info("clear preload components cache", { cacheKey: t }), E.delete(t);
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 ae(t) {
240
- for (const e of E.keys())
241
- e.includes(t) && (g.info("clear preload components cache", { cacheKey: e }), z(e));
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 ie(t) {
244
- for (const e of E.keys())
245
- e.includes(t) && (g.info("clear preload components cache", { cacheKey: e }), z(e));
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 Nt({
248
- mode: t,
249
- instanceId: e,
251
+ function Ne({
252
+ mode: e,
253
+ instanceId: t,
250
254
  componentId: o,
251
255
  locale: n
252
256
  }) {
253
- return ["getPreloadComponents", t, e, o, n].join("-");
257
+ return ["getPreloadComponents", e, t, o, n].join("-");
254
258
  }
255
- async function pe({
256
- mode: t,
257
- req: e,
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 = $(6), i = (await Promise.all(
272
+ const m = L(6), i = (await Promise.all(
269
273
  s.map(
270
274
  (p) => m(async () => {
271
275
  try {
272
- const u = Nt({
273
- mode: t,
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 (t !== "draft" && p.useCache && E.has(u))
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 jt({
283
- req: e,
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 (t !== "draft" && p.useCache) {
293
- let C = At;
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 = $(10), u = await Promise.all(
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, M = S ? "" : et({ componentId: d.component.id }), D = $t(d.component);
316
- let b = {
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: M
323
+ moduleName: b
320
324
  };
321
325
  if (D && d.component.renderer?.type === "react-component" && S && d.component.renderer?.script)
322
- b.script = d.component.renderer?.script;
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
- b.script = C ? R : W(M, R);
329
+ M.script = C ? R : W(b, R);
326
330
  } else
327
- b = S ? {
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: t !== "draft"
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: M,
342
- tailwind: t !== "draft"
345
+ moduleName: b,
346
+ tailwind: e !== "draft"
343
347
  }),
344
- moduleName: M
348
+ moduleName: b
345
349
  };
346
- return [d.component.id, { component: d.component, script: b }];
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 jt({
364
- req: t,
365
- state: e,
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 } = e, a = _({ state: e, componentId: o });
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: t, state: e, componentId: o, locale: m, defaultLocale: s, properties: r });
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 Dt = 20;
385
+ const De = 20;
382
386
  async function Z({
383
- req: t,
384
- depth: e = 0,
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 (e > Dt) throw new RangeError("max component depth exceeded");
392
- const a = Rt({ state: o, componentId: n, properties: l, locale: s });
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 = Ot(i.renderer) ? i.renderer.getServerSideProps : void 0, c = await Lt({ ...a, req: t, getServerSideProps: 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 === L) {
411
+ if (c?.type === $) {
408
412
  const w = await Z({
409
- req: t,
410
- depth: e + 1,
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: L,
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 Rt({
429
- state: t,
430
- componentId: e,
432
+ function Re({
433
+ state: e,
434
+ componentId: t,
431
435
  locale: o,
432
436
  properties: n
433
437
  }) {
434
- const s = _({ state: t, componentId: e });
438
+ const s = _({ state: e, componentId: t });
435
439
  if (!s) return null;
436
- const r = ot({
437
- componentId: e,
438
- getComponent: (l) => _({ state: t, componentId: l }),
440
+ const r = oe({
441
+ componentId: t,
442
+ getComponent: (l) => _({ state: e, componentId: l }),
439
443
  locale: o,
440
- defaultLocale: t.config.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: t, componentId: e }) {
446
- return t.components[e]?.data ?? t.resources.components?.[e]?.component;
449
+ function _({ state: e, componentId: t }) {
450
+ return e.components[t]?.data ?? e.resources.components?.[t]?.component;
447
451
  }
448
- function le({ state: t, name: e }) {
449
- const o = e.toLowerCase();
450
- return Object.values(t.components).find((n) => n.data.name?.toLowerCase() === o)?.data ?? (t.resources.components && Object.values(t.resources.components).find((n) => n.component.name?.toLowerCase() === o))?.component;
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 Lt({
453
- component: t,
454
- script: e,
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 && !e?.includes("getServerSideProps"))
463
+ if (!s && !t?.includes("getServerSideProps"))
460
464
  return null;
461
- const r = s ?? await V(e, "getServerSideProps");
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: `${t.name || t.id}.js`,
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 nt(w) ? void 0 : w;
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: tt,
526
+ getComponentMountPoint: ee,
523
527
  joinURL: O,
524
- withQuery: it,
525
- getQuery: at,
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(pt(n.hostname), n.originalUrl) },
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 ct(w.headers);
546
+ const d = new ce(w.headers);
543
547
  d.set("cookie", u), w.headers = d;
544
548
  }
545
549
  }
546
- return st(p, {
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 ue = j(
566
- async (t, e, o, n) => {
567
- if (!t?.includes(e) && !n)
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(t, e);
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${e}SchemaWrapper() {
579
- return ${e};
582
+ export function get${t}SchemaWrapper() {
583
+ return ${t};
580
584
  }
581
585
  `,
582
586
  filename: `${o}.js`,
583
- functionName: `get${e}SchemaWrapper`
587
+ functionName: `get${t}SchemaWrapper`
584
588
  }).finally(() => {
585
589
  r = null;
586
590
  });
587
591
  } catch (r) {
588
- return g.error(`获取 ${e} 失败`, { componentId: o, error: r }), null;
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
- ), $t = (t) => !!(t.renderer?.type === "react-component" && t.version && t.version >= 2);
599
+ ), Le = (e) => !!(e.renderer?.type === "react-component" && e.version && e.version >= 2);
596
600
  export {
597
- At as C,
601
+ Ae as C,
598
602
  B as G,
599
- ne as I,
600
- ce as a,
601
- ue as b,
602
- ae as c,
603
- re as d,
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
- ie as f,
606
- pe as g,
607
- Nt as h,
608
- se as i,
609
- jt as j,
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
- le as n,
614
- $t as s
617
+ lt as n,
618
+ Le as s
615
619
  };