@blocklet/pages-kit-inner-components 0.5.32 → 0.5.33

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.
@@ -1,17 +1,17 @@
1
1
  var Ct = Object.defineProperty;
2
- var Tt = (e, n, t) => n in e ? Ct(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var k = (e, n, t) => Tt(e, typeof n != "symbol" ? n + "" : n, t);
4
- import { getComponentMountPoint as Pt } from "@blocklet/pages-kit/builtin/utils";
2
+ var Pt = (e, n, t) => n in e ? Ct(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
+ var k = (e, n, t) => Pt(e, typeof n != "symbol" ? n + "" : n, t);
4
+ import { getComponentMountPoint as Tt } from "@blocklet/pages-kit/builtin/utils";
5
5
  import { PreloadComponentScriptModule as ye } from "@blocklet/pages-kit/types";
6
6
  import { componentUMDName as vt, RenderNestedComponent as ze, mergeComponent as Dt, getComponentDependencies as kt } from "@blocklet/pages-kit/utils/property";
7
7
  import { memoize as at, Sandbox as it, BuiltinModules as jt } from "@blocklet/quickjs";
8
8
  import I from "@blocklet/sdk/lib/config";
9
- import { LRUCache as $e } from "lru-cache";
9
+ import { LRUCache as Me } from "lru-cache";
10
10
  import xt, { Headers as Rt } from "node-fetch";
11
11
  import { joinURL as W, getQuery as Nt, withQuery as Lt, parseURL as Ke, withHttps as _t } from "ufo";
12
12
  import { createHash as te } from "crypto";
13
- import Mt from "@blocklet/logger";
14
- import { promises as V, readFileSync as re, mkdtempSync as $t, existsSync as H, lstatSync as oe, readdirSync as Ut, rmSync as ct, renameSync as Ye, mkdirSync as Y, writeFileSync as we, copyFileSync as Ft, createWriteStream as Bt } from "fs";
13
+ import $t from "@blocklet/logger";
14
+ import { promises as V, readFileSync as re, mkdtempSync as Mt, existsSync as H, lstatSync as oe, readdirSync as Ut, rmSync as ct, renameSync as Ye, mkdirSync as Y, writeFileSync as we, copyFileSync as Ft, createWriteStream as Bt } from "fs";
15
15
  import lt, { join as O, dirname as U, basename as J } from "path";
16
16
  import Gt from "lodash/isNil";
17
17
  import { BuiltinModules as Ht } from "@blocklet/pages-kit/utils/builtin";
@@ -21,7 +21,7 @@ import Wt from "autoprefixer";
21
21
  import * as qt from "esbuild";
22
22
  import Qt from "postcss";
23
23
  import Xt from "tailwindcss";
24
- import M from "typescript";
24
+ import $ from "typescript";
25
25
  import { getYjsValue as ce, syncedStore as Zt } from "@syncedstore/core";
26
26
  import * as z from "yjs";
27
27
  import { setPageDataSource as es } from "@blocklet/pages-kit/utils/data-source";
@@ -59,7 +59,7 @@ I.env.INIT_TEMPLATE_PATH;
59
59
  const Is = process.env.DATABASE_URL || lt.join(I.env.dataDir, "db/pages-kit.db"), Qe = I, Qn = () => I.env.tenantMode === "multiple", Xn = () => {
60
60
  var e;
61
61
  return (Gt(Qe.env.preferences.multiTenantAllProjectAccessPassports) ? [] : (e = Qe.env.preferences.multiTenantAllProjectAccessPassports) == null ? void 0 : e.split(",")) || [];
62
- }, bs = lt.join(I.env.dataDir, "fs-memoize-cache"), As = I.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", S = Mt("pages-kit"), Os = x.sqlite.DATE.parse;
62
+ }, bs = lt.join(I.env.dataDir, "fs-memoize-cache"), As = I.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", S = $t("pages-kit"), Os = x.sqlite.DATE.parse;
63
63
  x.sqlite.DATE.parse = (e, n) => typeof e == "number" ? new Date(e) : Os(e, n);
64
64
  const me = new Ss({
65
65
  dialect: "sqlite",
@@ -153,7 +153,7 @@ se.hasMany(Ce, {
153
153
  foreignKey: "projectId",
154
154
  as: "components"
155
155
  });
156
- const Cs = bs, Ts = As, Le = 7 * 24 * 60 * 60 * 1e3, Ps = 24 * 60 * 60 * 1e3, ft = async (e = "") => {
156
+ const Cs = bs, Ps = As, Le = 7 * 24 * 60 * 60 * 1e3, Ts = 24 * 60 * 60 * 1e3, ft = async (e = "") => {
157
157
  const n = O(Cs, e);
158
158
  try {
159
159
  if (!(await V.stat(n)).isDirectory())
@@ -164,7 +164,7 @@ const Cs = bs, Ts = As, Le = 7 * 24 * 60 * 60 * 1e3, Ps = 24 * 60 * 60 * 1e3, ft
164
164
  return n;
165
165
  }, vs = (e, n) => {
166
166
  const t = te("md5").update(n).digest("hex");
167
- return O(e, `${Ts}-${t}.json`);
167
+ return O(e, `${Ps}-${t}.json`);
168
168
  }, Ds = async (e = "") => {
169
169
  const n = await ft(e), t = Date.now();
170
170
  try {
@@ -173,12 +173,12 @@ const Cs = bs, Ts = As, Le = 7 * 24 * 60 * 60 * 1e3, Ps = 24 * 60 * 60 * 1e3, ft
173
173
  s.filter((o) => o.endsWith(".json")).map(async (o) => {
174
174
  const r = O(n, o);
175
175
  try {
176
- const a = await V.readFile(r, "utf-8"), i = JSON.parse(a);
177
- i.createdAt && t - i.createdAt > Le && await V.unlink(r);
176
+ const i = await V.readFile(r, "utf-8"), d = JSON.parse(i);
177
+ d.createdAt && t - d.createdAt > Le && await V.unlink(r);
178
178
  } catch {
179
179
  try {
180
- const i = await V.stat(r);
181
- t - i.mtimeMs > Le && await V.unlink(r);
180
+ const d = await V.stat(r);
181
+ t - d.mtimeMs > Le && await V.unlink(r);
182
182
  } catch {
183
183
  }
184
184
  }
@@ -191,23 +191,23 @@ const Cs = bs, Ts = As, Le = 7 * 24 * 60 * 60 * 1e3, Ps = 24 * 60 * 60 * 1e3, ft
191
191
  const e = /* @__PURE__ */ new Set();
192
192
  return setInterval(async () => {
193
193
  await Promise.all(Array.from(e).map((s) => Ds(s)));
194
- }, Ps).unref(), (s) => {
194
+ }, Ts).unref(), (s) => {
195
195
  e.add(s);
196
196
  };
197
197
  })();
198
198
  function Be(e, n) {
199
199
  return n.subdir && ks(n.subdir), at(
200
200
  async (...s) => {
201
- const o = await ft(n.subdir || ""), r = n.keyGenerator ? n.keyGenerator(...s) : JSON.stringify(s), a = vs(o, r);
201
+ const o = await ft(n.subdir || ""), r = n.keyGenerator ? n.keyGenerator(...s) : JSON.stringify(s), i = vs(o, r);
202
202
  try {
203
- const i = await V.readFile(a, "utf-8"), { value: p, createdAt: c } = JSON.parse(i);
204
- if (c && Date.now() - c > Le)
205
- throw await V.unlink(a).catch(() => {
203
+ const d = await V.readFile(i, "utf-8"), { value: p, createdAt: a } = JSON.parse(d);
204
+ if (a && Date.now() - a > Le)
205
+ throw await V.unlink(i).catch(() => {
206
206
  }), new Error("Cache expired");
207
207
  return p;
208
208
  } catch {
209
- const p = await e(...s), c = JSON.stringify({ value: p, createdAt: Date.now() });
210
- return V.writeFile(a, c, "utf-8").catch((u) => {
209
+ const p = await e(...s), a = JSON.stringify({ value: p, createdAt: Date.now() });
210
+ return V.writeFile(i, a, "utf-8").catch((u) => {
211
211
  console.error("Failed to write fs cache:", u);
212
212
  }), p;
213
213
  }
@@ -229,8 +229,8 @@ const js = async (e, { componentId: n }) => {
229
229
  stats: {}
230
230
  }),
231
231
  (r) => {
232
- r.walkRules((a) => {
233
- a.selectors = a.selectors.map((i) => i.replace(/\.(.+)/g, `${s}.$1,${s} .$1`));
232
+ r.walkRules((i) => {
233
+ i.selectors = i.selectors.map((d) => d.replace(/\.(.+)/g, `${s}.$1,${s} .$1`));
234
234
  });
235
235
  }
236
236
  // FIXME: cssnano use browserslist, it is not working with the fs isolation
@@ -244,23 +244,23 @@ ${e}
244
244
  `;
245
245
  }, Xe = Be(
246
246
  async (e, n) => {
247
- let t = M.transpileModule(e, {
247
+ let t = $.transpileModule(e, {
248
248
  compilerOptions: {
249
- jsx: M.JsxEmit.React,
250
- target: M.ScriptTarget.ES2016,
251
- module: M.ModuleKind.ESNext
249
+ jsx: $.JsxEmit.React,
250
+ target: $.ScriptTarget.ES2016,
251
+ module: $.ModuleKind.ESNext
252
252
  },
253
253
  transformers: {
254
- before: [Jt(M)]
254
+ before: [Jt($)]
255
255
  }
256
256
  }).outputText;
257
257
  if (n.tailwind && (t = await xs(t, { componentId: n.componentId })), n.module === ye.ESM) return t;
258
- const s = M.transpileModule(t, {
258
+ const s = $.transpileModule(t, {
259
259
  compilerOptions: {
260
- jsx: M.JsxEmit.React,
261
- target: M.ScriptTarget.ES2016,
262
- module: M.ModuleKind.CommonJS,
263
- moduleResolution: M.ModuleResolutionKind.Node16
260
+ jsx: $.JsxEmit.React,
261
+ target: $.ScriptTarget.ES2016,
262
+ module: $.ModuleKind.CommonJS,
263
+ moduleResolution: $.ModuleResolutionKind.Node16
264
264
  }
265
265
  }).outputText;
266
266
  return n.module === ye.CJS ? s : Ns(n.moduleName, s);
@@ -285,8 +285,8 @@ ${e}
285
285
  subdir: "transpileModule"
286
286
  }
287
287
  ), Rs = async (e, n) => {
288
- var a, i;
289
- const s = (i = (a = (await qt.build({
288
+ var i, d;
289
+ const s = (d = (i = (await qt.build({
290
290
  entryPoints: ["index.tsx"],
291
291
  external: Object.keys(Ht),
292
292
  format: "esm",
@@ -297,7 +297,7 @@ ${e}
297
297
  {
298
298
  name: "vfs",
299
299
  setup(p) {
300
- let c = null;
300
+ let a = null;
301
301
  p.onResolve({ filter: /.*/ }, (u) => u.path === "index.tsx" ? { path: "index.tsx", namespace: "vfs" } : u.path === "./component" ? { path: "component.tsx", namespace: "vfs" } : null), p.onLoad({ filter: /.*/, namespace: "vfs" }, async (u) => {
302
302
  var y;
303
303
  if (u.path === "index.tsx")
@@ -305,11 +305,11 @@ ${e}
305
305
  if (u.path === "component.tsx")
306
306
  return { contents: e, loader: "tsx" };
307
307
  if (Vt(u.path)) {
308
- const m = u.path.split("/").pop();
309
- if (c || (c = await Ve({ ensureLoaded: !1 })), (y = c == null ? void 0 : c.chunks) != null && y[m])
308
+ const f = u.path.split("/").pop();
309
+ if (a || (a = await Ve({ ensureLoaded: !1 })), (y = a == null ? void 0 : a.chunks) != null && y[f])
310
310
  try {
311
- const d = re(c.chunks[m], "utf-8");
312
- return S.info("get chunk from local file system", m), { contents: d, loader: "tsx" };
311
+ const l = re(a.chunks[f], "utf-8");
312
+ return S.info("get chunk from local file system", f), { contents: l, loader: "tsx" };
313
313
  } catch {
314
314
  }
315
315
  }
@@ -318,16 +318,19 @@ ${e}
318
318
  }
319
319
  }
320
320
  ]
321
- })).outputFiles) == null ? void 0 : a[0]) == null ? void 0 : i.contents;
321
+ })).outputFiles) == null ? void 0 : i[0]) == null ? void 0 : d.contents;
322
322
  if (!s) throw new Error("Failed to build server code");
323
323
  const o = Buffer.from(s).toString();
324
- return M.transpileModule(o, {
325
- compilerOptions: { module: M.ModuleKind.ESNext, target: M.ScriptTarget.ES2020 }
324
+ return $.transpileModule(o, {
325
+ compilerOptions: { module: $.ModuleKind.ESNext, target: $.ScriptTarget.ES2020 }
326
326
  }).outputText;
327
327
  }, mt = Be(
328
328
  async (e, n) => {
329
329
  const t = await Rs(e, n);
330
- return new RegExp(`export\\s+\\{\\s+${n}\\s+\\}`, "m").test(t) ? t : void 0;
330
+ return new RegExp(
331
+ `export\\s+\\{[^}]*(?:\\w+\\s+as\\s+${n}\\b|\\b${n}\\b)[^}]*\\}`,
332
+ "m"
333
+ ).test(t) ? t : void 0;
331
334
  },
332
335
  {
333
336
  keyGenerator: (e, n) => {
@@ -367,17 +370,17 @@ var ${e} = async function () {
367
370
 
368
371
  return exports;
369
372
  };
370
- `, ue = new $e({
373
+ `, ue = new Me({
371
374
  max: 100
372
375
  }), Ls = 60 * 60, Ze = 60;
373
376
  function _s(e) {
374
377
  S.info("clear preload components cache", { cacheKey: e }), ue.delete(e);
375
378
  }
376
- function Ms(e) {
379
+ function $s(e) {
377
380
  for (const n of ue.keys())
378
381
  n.includes(e) && (S.info("clear preload components cache", { cacheKey: n }), _s(n));
379
382
  }
380
- function $s({
383
+ function Ms({
381
384
  mode: e,
382
385
  instanceId: n,
383
386
  componentId: t,
@@ -394,80 +397,80 @@ async function Zn({
394
397
  module: r
395
398
  }) {
396
399
  const {
397
- supportedLocales: a,
398
- config: { defaultLocale: i }
400
+ supportedLocales: i,
401
+ config: { defaultLocale: d }
399
402
  } = t;
400
- if (!i) return null;
403
+ if (!d) return null;
401
404
  const p = (await Promise.all(
402
- o.map(async (d) => {
405
+ o.map(async (l) => {
403
406
  try {
404
- const l = $s({
407
+ const c = Ms({
405
408
  mode: e,
406
- instanceId: d.id,
407
- componentId: d.componentId,
409
+ instanceId: l.id,
410
+ componentId: l.componentId,
408
411
  locale: s
409
412
  });
410
- if (e !== "draft" && d.useCache && ue.has(l))
411
- return S.info(`get preload component from cache: ${l}`), ue.get(l);
412
- const f = Ee({ state: t, componentId: d.componentId });
413
- if (!f) return null;
413
+ if (e !== "draft" && l.useCache && ue.has(c))
414
+ return S.info(`get preload component from cache: ${c}`), ue.get(c);
415
+ const m = Ee({ state: t, componentId: l.componentId });
416
+ if (!m) return null;
414
417
  const w = await Us({
415
418
  req: n,
416
419
  state: t,
417
- componentId: f.id,
420
+ componentId: m.id,
418
421
  locale: s,
419
- defaultLocale: i,
420
- properties: d.properties
422
+ defaultLocale: d,
423
+ properties: l.properties
421
424
  });
422
425
  if (!w) return null;
423
- const D = { instanceId: d.id, preload: w };
424
- if (e !== "draft" && d.useCache) {
426
+ const D = { instanceId: l.id, preload: w };
427
+ if (e !== "draft" && l.useCache) {
425
428
  let C = Ls;
426
- d.cacheDuration && (C = d.cacheDuration), S.info(`set preload component to cache(${C}s): ${l}`), ue.set(l, D, {
429
+ l.cacheDuration && (C = l.cacheDuration), S.info(`set preload component to cache(${C}s): ${c}`), ue.set(c, D, {
427
430
  ttl: C * 1e3
428
431
  });
429
432
  }
430
433
  return D;
431
- } catch (l) {
432
- return S.error("get preload component error", { instanceId: d.id, componentId: d.componentId }, { error: l }), null;
434
+ } catch (c) {
435
+ return S.error("get preload component error", { instanceId: l.id, componentId: l.componentId }, { error: c }), null;
433
436
  }
434
437
  })
435
- )).filter((d) => !!d), c = Object.values(
436
- p.reduce((d, l) => ({ ...d, ...l.preload.components }), {})
438
+ )).filter((l) => !!l), a = Object.values(
439
+ p.reduce((l, c) => ({ ...l, ...c.preload.components }), {})
437
440
  );
438
441
  async function u() {
439
- const d = await Promise.all(
440
- c.map(async (l) => {
441
- const f = vt({ componentId: l.component.id }), w = r === ye.ESM ? {
442
+ const l = await Promise.all(
443
+ a.map(async (c) => {
444
+ const m = vt({ componentId: c.component.id }), w = r === ye.ESM ? {
442
445
  module: r,
443
- script: await Xe(l.script, {
444
- componentId: l.component.id,
446
+ script: await Xe(c.script, {
447
+ componentId: c.component.id,
445
448
  module: r,
446
449
  tailwind: e !== "draft"
447
450
  })
448
451
  } : {
449
452
  module: r,
450
- script: await Xe(l.script, {
451
- componentId: l.component.id,
453
+ script: await Xe(c.script, {
454
+ componentId: c.component.id,
452
455
  module: r,
453
- moduleName: f,
456
+ moduleName: m,
454
457
  tailwind: e !== "draft"
455
458
  }),
456
- moduleName: f
459
+ moduleName: m
457
460
  };
458
- return [l.component.id, { component: l.component, script: w }];
461
+ return [c.component.id, { component: c.component, script: w }];
459
462
  })
460
463
  );
461
- return Object.fromEntries(d);
464
+ return Object.fromEntries(l);
462
465
  }
463
466
  const y = await u();
464
467
  return {
465
- config: { defaultLocale: i, supportedLocales: a },
468
+ config: { defaultLocale: d, supportedLocales: i },
466
469
  components: y,
467
- instances: p.map((d) => ({
468
- id: d.instanceId,
469
- componentId: d.preload.component.id,
470
- locales: { [d.preload.locale]: { props: d.preload.props } }
470
+ instances: p.map((l) => ({
471
+ id: l.instanceId,
472
+ componentId: l.preload.component.id,
473
+ locales: { [l.preload.locale]: { props: l.preload.props } }
471
474
  }))
472
475
  };
473
476
  }
@@ -479,14 +482,14 @@ async function Us({
479
482
  defaultLocale: o,
480
483
  properties: r
481
484
  }) {
482
- const { supportedLocales: a } = n, i = Ee({ state: n, componentId: t });
483
- if (!i) return null;
484
- const p = a.some((u) => u.locale === s) ? s : o;
485
+ const { supportedLocales: i } = n, d = Ee({ state: n, componentId: t });
486
+ if (!d) return null;
487
+ const p = i.some((u) => u.locale === s) ? s : o;
485
488
  if (!p) return null;
486
- const c = await ht({ req: e, state: n, componentId: t, locale: p, defaultLocale: o, properties: r });
487
- return c ? {
488
- component: i,
489
- ...c
489
+ const a = await ht({ req: e, state: n, componentId: t, locale: p, defaultLocale: o, properties: r });
490
+ return a ? {
491
+ component: d,
492
+ ...a
490
493
  } : null;
491
494
  }
492
495
  const Fs = 20;
@@ -497,26 +500,26 @@ async function ht({
497
500
  componentId: s,
498
501
  locale: o,
499
502
  defaultLocale: r,
500
- properties: a
503
+ properties: i
501
504
  }) {
502
505
  if (n > Fs) throw new RangeError("max component depth exceeded");
503
- const i = Bs({ state: t, componentId: s, properties: a, locale: o });
504
- if (!i) return null;
505
- const { props: p } = i, c = {
506
+ const d = Bs({ state: t, componentId: s, properties: i, locale: o });
507
+ if (!d) return null;
508
+ const { props: p } = d, a = {
506
509
  locale: o || r,
507
- components: { [i.component.id]: { component: i.component, script: i.script } },
510
+ components: { [d.component.id]: { component: d.component, script: d.script } },
508
511
  props: { ...p }
509
512
  };
510
513
  try {
511
- const u = await Gs({ ...i, req: e });
512
- u != null && u.props && Object.assign(c.props, u.props);
514
+ const u = await Gs({ ...d, req: e });
515
+ u != null && u.props && Object.assign(a.props, u.props);
513
516
  } catch (u) {
514
- S.error("preload data at server side error", { componentId: s, name: i.component.name }, { error: u });
517
+ S.error("preload data at server side error", { componentId: s, name: d.component.name }, { error: u });
515
518
  }
516
519
  return await Promise.all(
517
520
  Object.entries(p).map(async ([u, y]) => {
518
521
  if ((y == null ? void 0 : y.type) === ze) {
519
- const m = await ht({
522
+ const f = await ht({
520
523
  req: e,
521
524
  depth: n + 1,
522
525
  state: t,
@@ -525,16 +528,16 @@ async function ht({
525
528
  defaultLocale: r,
526
529
  properties: y.properties
527
530
  });
528
- m && (Object.assign(c.components, m.components), Object.assign(c.props, {
531
+ f && (Object.assign(a.components, f.components), Object.assign(a.props, {
529
532
  [u]: {
530
533
  type: ze,
531
534
  componentId: y.componentId,
532
- props: m.props
535
+ props: f.props
533
536
  }
534
537
  }));
535
538
  }
536
539
  })
537
- ), c;
540
+ ), a;
538
541
  }
539
542
  function Bs({
540
543
  state: e,
@@ -546,7 +549,7 @@ function Bs({
546
549
  if (!o) return null;
547
550
  const r = Dt({
548
551
  componentId: n,
549
- getComponent: (a) => Ee({ state: e, componentId: a }),
552
+ getComponent: (i) => Ee({ state: e, componentId: i }),
550
553
  locale: t,
551
554
  defaultLocale: e.config.defaultLocale,
552
555
  properties: s
@@ -561,11 +564,11 @@ function eo({ state: e, name: n }) {
561
564
  var s, o;
562
565
  const t = n.toLowerCase();
563
566
  return ((s = Object.values(e.components).find((r) => {
564
- var a;
565
- return ((a = r.data.name) == null ? void 0 : a.toLowerCase()) === t;
567
+ var i;
568
+ return ((i = r.data.name) == null ? void 0 : i.toLowerCase()) === t;
566
569
  })) == null ? void 0 : s.data) ?? ((o = e.resources.components && Object.values(e.resources.components).find((r) => {
567
- var a;
568
- return ((a = r.component.name) == null ? void 0 : a.toLowerCase()) === t;
570
+ var i;
571
+ return ((i = r.component.name) == null ? void 0 : i.toLowerCase()) === t;
569
572
  })) == null ? void 0 : o.component);
570
573
  }
571
574
  async function Gs({
@@ -578,13 +581,13 @@ async function Gs({
578
581
  return null;
579
582
  const o = await mt(n, "getServerSideProps");
580
583
  if (!o) return null;
581
- const r = new Promise((i) => {
584
+ const r = o.match(/export\s*{\s*(\w+)\s+as\s+getServerSideProps\s*}/) || o.match(/export\s*{\s*getServerSideProps\s*}/), i = (r == null ? void 0 : r[1]) || "getServerSideProps", d = new Promise((a) => {
582
585
  setTimeout(() => {
583
- i({});
586
+ a({});
584
587
  }, Ze * 1e3);
585
588
  });
586
589
  return await Promise.race([
587
- r,
590
+ d,
588
591
  it.callFunction({
589
592
  code: `${o}
590
593
 
@@ -597,7 +600,7 @@ export async function getServerSidePropsWrapper(props) {
597
600
  try {
598
601
  globalThis.location = location;
599
602
  globalThis.fetch = fetch;
600
- return await getServerSideProps(componentProps);
603
+ return await ${i}(componentProps);
601
604
  } finally {
602
605
  // 清理全局状态
603
606
  if (originalLocation) globalThis.location = originalLocation;
@@ -605,29 +608,29 @@ export async function getServerSidePropsWrapper(props) {
605
608
  }
606
609
  }`,
607
610
  filename: `${e.name || e.id}.js`,
608
- moduleLoader: (i) => {
609
- if (i === "@blocklet/pages-kit/builtin/utils")
611
+ moduleLoader: (a) => {
612
+ if (a === "@blocklet/pages-kit/builtin/utils")
610
613
  return `const { joinURL, withQuery, getQuery, getComponentMountPoint } = globalThis
611
614
  export { joinURL, withQuery, getQuery, getComponentMountPoint }
612
615
  `;
613
- if (i === "@blocklet/pages-kit/builtin/dayjs")
616
+ if (a === "@blocklet/pages-kit/builtin/dayjs")
614
617
  return jt.dayjs;
615
618
  },
616
619
  global: {
617
620
  console: {
618
621
  // NOTE: do not return logger.xxx result, it will cause memory leak
619
622
  // eslint-disable-next-line prettier/prettier
620
- log: (...i) => {
621
- S.info(...i);
623
+ log: (...a) => {
624
+ S.info(...a);
622
625
  },
623
- warn: (...i) => {
624
- S.warn(...i);
626
+ warn: (...a) => {
627
+ S.warn(...a);
625
628
  },
626
- error: (...i) => {
627
- S.error(...i);
629
+ error: (...a) => {
630
+ S.error(...a);
628
631
  }
629
632
  },
630
- getComponentMountPoint: Pt,
633
+ getComponentMountPoint: Tt,
631
634
  joinURL: W,
632
635
  withQuery: Lt,
633
636
  getQuery: Nt
@@ -638,24 +641,24 @@ export { joinURL, withQuery, getQuery, getComponentMountPoint }
638
641
  // NOTE: IMPORTANT! place location and fetch (has side effect) at the args not global
639
642
  // because the global is shared between all runtime and just init once
640
643
  location: { href: W(_t(s.hostname), s.originalUrl) },
641
- fetch: (i, { ...p } = {}) => {
642
- const c = typeof i == "string" && i.startsWith("/") ? W(I.env.appUrl, i) : i;
643
- if (typeof c == "string" && Ke(c).host === Ke(I.env.appUrl).host) {
644
- const u = s.get("cookie");
645
- if (u) {
646
- const y = new Rt(p.headers);
647
- y.set("cookie", u), p.headers = y;
644
+ fetch: (a, { ...u } = {}) => {
645
+ const y = typeof a == "string" && a.startsWith("/") ? W(I.env.appUrl, a) : a;
646
+ if (typeof y == "string" && Ke(y).host === Ke(I.env.appUrl).host) {
647
+ const f = s.get("cookie");
648
+ if (f) {
649
+ const l = new Rt(u.headers);
650
+ l.set("cookie", f), u.headers = l;
648
651
  }
649
652
  }
650
- return xt(c, {
651
- ...p,
653
+ return xt(y, {
654
+ ...u,
652
655
  timeout: Ze * 1e3
653
- }).then((u) => ({
654
- ok: u.ok,
655
- status: u.status,
656
- statusText: u.statusText,
657
- headers: Object.fromEntries(u.headers.entries()),
658
- json: () => u.json()
656
+ }).then((f) => ({
657
+ ok: f.ok,
658
+ status: f.status,
659
+ statusText: f.statusText,
660
+ headers: Object.fromEntries(f.headers.entries()),
661
+ json: () => f.json()
659
662
  }));
660
663
  },
661
664
  props: t
@@ -704,12 +707,12 @@ function Ie(e) {
704
707
  });
705
708
  }
706
709
  function yt() {
707
- return $t(O(I.env.dataDir, "tmp-"));
710
+ return Mt(O(I.env.dataDir, "tmp-"));
708
711
  }
709
712
  function be(e, n, t = []) {
710
713
  return Array.isArray(e) ? e.flatMap((s, o) => be(s, n, [...t, o])) : typeof e == "object" ? e === null ? [] : Object.entries(e).flatMap(([s, o]) => be(o, n, [...t, s])) : n(e) ? [t] : [];
711
714
  }
712
- function $(e) {
715
+ function M(e) {
713
716
  return e.filter((n) => n != null);
714
717
  }
715
718
  function zs(e) {
@@ -738,8 +741,8 @@ function Ks(e) {
738
741
  t.changes.keys.forEach((s, o) => {
739
742
  var r;
740
743
  if (s.action === "add") {
741
- const a = ce((r = e.routes) == null ? void 0 : r[o]);
742
- a && a instanceof z.Map && Ie(a);
744
+ const i = ce((r = e.routes) == null ? void 0 : r[o]);
745
+ i && i instanceof z.Map && Ie(i);
743
746
  }
744
747
  });
745
748
  });
@@ -749,30 +752,30 @@ function Ys(e, n) {
749
752
  for (const s of n || Object.keys(e.routes || {})) {
750
753
  let o = s, r = [];
751
754
  if (s.includes("-")) {
752
- const [a, ...i] = s.split("-");
753
- o = a, r = i || [];
755
+ const [i, ...d] = s.split("-");
756
+ o = i, r = d || [];
754
757
  }
755
758
  if (((t = e.routes) == null ? void 0 : t[o]) !== void 0) {
756
759
  e.routes[o].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
757
- const a = e.routes[o];
758
- if (!a || !a.params || a.params.length === 0)
760
+ const i = e.routes[o];
761
+ if (!i || !i.params || i.params.length === 0)
759
762
  continue;
760
763
  if (s.includes("-") && r.length > 0) {
761
- const i = ts(r, a);
762
- i && (i.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
764
+ const d = ts(r, i);
765
+ d && (d.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
763
766
  }
764
767
  if (!n) {
765
- const i = Ue({
766
- basePath: a.path,
767
- params: a.params,
768
- routeId: a.id,
769
- paramsOptions: a.paramsOptions,
768
+ const d = Ue({
769
+ basePath: i.path,
770
+ params: i.params,
771
+ routeId: i.id,
772
+ paramsOptions: i.paramsOptions,
770
773
  currentIndex: 0,
771
774
  currentParams: [],
772
775
  currentOptionIds: [],
773
776
  result: []
774
777
  });
775
- for (const p of i)
778
+ for (const p of d)
776
779
  p.routeMetaData ?? (p.routeMetaData = {}), p.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
777
780
  }
778
781
  }
@@ -785,7 +788,7 @@ function je({
785
788
  routeId: s,
786
789
  routePathInfo: o
787
790
  }) {
788
- var a, i, p, c, u, y, m, d, l;
791
+ var i, d, p, a, u, y, f, l, c;
789
792
  S.info(
790
793
  `Executing datasource data assembly, routeId: ${s}, routePathInfo: ${JSON.stringify(o)}`
791
794
  );
@@ -794,30 +797,30 @@ function je({
794
797
  id: s,
795
798
  slug: (o == null ? void 0 : o.path) ?? n.path,
796
799
  createdAt: n.createdAt,
797
- updatedAt: ((a = o == null ? void 0 : o.routeMetaData) == null ? void 0 : a.updatedAt) ?? n.updatedAt,
798
- publishedAt: ((i = o == null ? void 0 : o.routeMetaData) == null ? void 0 : i.publishedAt) ?? n.publishedAt,
800
+ updatedAt: ((i = o == null ? void 0 : o.routeMetaData) == null ? void 0 : i.updatedAt) ?? n.updatedAt,
801
+ publishedAt: ((d = o == null ? void 0 : o.routeMetaData) == null ? void 0 : d.publishedAt) ?? n.publishedAt,
799
802
  isPublic: (((p = o == null ? void 0 : o.routeMetaData) == null ? void 0 : p.isPublic) ?? n.isPublic) && n.isPublic
800
803
  };
801
- for (const f of t.supportedLocales) {
804
+ for (const m of t.supportedLocales) {
802
805
  if (n.dataSource) {
803
806
  let w = n.id;
804
807
  o && (w = o.paramOptionIds.join("-"));
805
- const D = ((y = (u = (c = n.dataSource.pathDataMappings) == null ? void 0 : c[w]) == null ? void 0 : u.dataCache) == null ? void 0 : y[f.locale]) ?? ((l = (d = (m = n.dataSource.pathDataMappings) == null ? void 0 : m[w]) == null ? void 0 : d.dataCache) == null ? void 0 : l[t.config.defaultLocale || "en"]);
808
+ const D = ((y = (u = (a = n.dataSource.pathDataMappings) == null ? void 0 : a[w]) == null ? void 0 : u.dataCache) == null ? void 0 : y[m.locale]) ?? ((c = (l = (f = n.dataSource.pathDataMappings) == null ? void 0 : f[w]) == null ? void 0 : l.dataCache) == null ? void 0 : c[t.config.defaultLocale || "en"]);
806
809
  if (!D)
807
810
  continue;
808
- es(r, t, f.locale, D);
811
+ es(r, t, m.locale, D);
809
812
  }
810
813
  o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
811
814
  }
812
815
  return r;
813
816
  }
814
- const { uploadToMediaKit: Ws } = require("@blocklet/uploader-server"), xe = is("abcdefghijklmnopqrstuvwxyz0123456789", 16), Ge = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, fe = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, tt = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, qs = 1e4, Qs = 3e4, he = 0, Re = 1, Xs = 0, Zs = 1, Me = I, de = O(process.env.BLOCKLET_DATA_DIR, "site-state"), to = ["production", "draft"], so = ["production"];
817
+ const { uploadToMediaKit: Ws } = require("@blocklet/uploader-server"), xe = is("abcdefghijklmnopqrstuvwxyz0123456789", 16), Ge = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, fe = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, tt = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, qs = 1e4, Qs = 3e4, he = 0, Re = 1, Xs = 0, Zs = 1, $e = I, de = O(process.env.BLOCKLET_DATA_DIR, "site-state"), to = ["production", "draft"], so = ["production"];
815
818
  function Ae(e) {
816
819
  return (e == null ? void 0 : e.replace(/\//g, "|")) || "";
817
820
  }
818
821
  function en() {
819
822
  var t;
820
- const e = Me.env.languages.map((s) => ({ locale: s.code, name: s.name })), n = (t = e[0]) == null ? void 0 : t.locale;
823
+ const e = $e.env.languages.map((s) => ({ locale: s.code, name: s.name })), n = (t = e[0]) == null ? void 0 : t.locale;
821
824
  return {
822
825
  pageIds: [],
823
826
  pages: {},
@@ -831,7 +834,7 @@ function en() {
831
834
  resources: {}
832
835
  };
833
836
  }
834
- const P = class P extends z.Doc {
837
+ const T = class T extends z.Doc {
835
838
  constructor(t) {
836
839
  super();
837
840
  k(this, "syncedStore");
@@ -840,52 +843,52 @@ const P = class P extends z.Doc {
840
843
  // 延迟释放定时器
841
844
  k(this, "releaseTimer");
842
845
  k(this, "awarenessChangeHandler", ({ added: t, updated: s, removed: o }, r) => {
843
- const a = t.concat(s, o);
846
+ const i = t.concat(s, o);
844
847
  if (r !== null) {
845
- const c = this.conns.get(r);
846
- c && (t.forEach((u) => {
847
- c.add(u);
848
+ const a = this.conns.get(r);
849
+ a && (t.forEach((u) => {
850
+ a.add(u);
848
851
  }), o.forEach((u) => {
849
- c.delete(u);
852
+ a.delete(u);
850
853
  }));
851
854
  }
852
- const i = R.createEncoder();
853
- R.writeVarUint(i, Re), R.writeVarUint8Array(i, qe(this.awareness, a));
854
- const p = R.toUint8Array(i);
855
- this.conns.forEach((c, u) => this.send(u, p));
855
+ const d = R.createEncoder();
856
+ R.writeVarUint(d, Re), R.writeVarUint8Array(d, qe(this.awareness, i));
857
+ const p = R.toUint8Array(d);
858
+ this.conns.forEach((a, u) => this.send(u, p));
856
859
  });
857
860
  k(this, "updateHandler", (t) => {
858
861
  const s = R.createEncoder();
859
862
  R.writeVarUint(s, he), hs(s, t);
860
863
  const o = R.toUint8Array(s);
861
- this.conns.forEach((r, a) => this.send(a, o));
864
+ this.conns.forEach((r, i) => this.send(i, o));
862
865
  });
863
866
  k(this, "ensureDataStructure", () => {
864
867
  var p;
865
- const { supportedLocales: t, pages: s, pageIds: o, config: r, routes: a, routeIds: i } = this.syncedStore;
868
+ const { supportedLocales: t, pages: s, pageIds: o, config: r, routes: i, routeIds: d } = this.syncedStore;
866
869
  {
867
- const c = new Set(Object.keys(s));
870
+ const a = new Set(Object.keys(s));
868
871
  let u = 0;
869
872
  for (; u < o.length; ) {
870
873
  const y = o[u];
871
- c.has(y) ? (c.delete(y), u++) : o.splice(u, 1);
874
+ a.has(y) ? (a.delete(y), u++) : o.splice(u, 1);
872
875
  }
873
876
  }
874
877
  {
875
- const c = new Set(Object.keys(a));
878
+ const a = new Set(Object.keys(i));
876
879
  let u = 0;
877
- for (; u < i.length; ) {
878
- const y = i[u];
879
- c.has(y) ? (c.delete(y), u++) : i.splice(u, 1);
880
+ for (; u < d.length; ) {
881
+ const y = d[u];
882
+ a.has(y) ? (a.delete(y), u++) : d.splice(u, 1);
880
883
  }
881
884
  }
882
- t.splice(0, t.length), t.push(...Me.env.languages.map((c) => ({ locale: c.code, name: c.name }))), r.defaultLocale = (p = t[0]) == null ? void 0 : p.locale;
885
+ t.splice(0, t.length), t.push(...$e.env.languages.map((a) => ({ locale: a.code, name: a.name }))), r.defaultLocale = (p = t[0]) == null ? void 0 : p.locale;
883
886
  {
884
- let c = 0;
887
+ let a = 0;
885
888
  const u = /* @__PURE__ */ new Set();
886
- for (; c < t.length; ) {
887
- const { locale: y } = t[c];
888
- u.has(y) ? t.splice(c, 1) : (c++, u.add(y));
889
+ for (; a < t.length; ) {
890
+ const { locale: y } = t[a];
891
+ u.has(y) ? t.splice(a, 1) : (a++, u.add(y));
889
892
  }
890
893
  }
891
894
  });
@@ -917,17 +920,17 @@ const P = class P extends z.Doc {
917
920
  await ot(o, r, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: t }), r.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Ys(this.syncedStore, s), await this.setState(t, r);
918
921
  });
919
922
  k(this, "mergeState", async (t, s) => {
920
- var i, p, c;
923
+ var d, p, a;
921
924
  const o = JSON.parse(JSON.stringify(s));
922
- (i = t.config).fontFamily ?? (i.fontFamily = {});
923
- const r = (p = o.config) == null ? void 0 : p.fontFamily, a = (c = t.config) == null ? void 0 : c.fontFamily;
924
- t.config.fontFamily.title = (r == null ? void 0 : r.title) || (a == null ? void 0 : a.title), t.config.fontFamily.description = (r == null ? void 0 : r.description) || (a == null ? void 0 : a.description), await new Promise((u, y) => {
925
+ (d = t.config).fontFamily ?? (d.fontFamily = {});
926
+ const r = (p = o.config) == null ? void 0 : p.fontFamily, i = (a = t.config) == null ? void 0 : a.fontFamily;
927
+ t.config.fontFamily.title = (r == null ? void 0 : r.title) || (i == null ? void 0 : i.title), t.config.fontFamily.description = (r == null ? void 0 : r.description) || (i == null ? void 0 : i.description), await new Promise((u, y) => {
925
928
  this.transact(async () => {
926
929
  try {
927
- const m = await ot(t, s);
928
- u(m);
929
- } catch (m) {
930
- y(m);
930
+ const f = await ot(t, s);
931
+ u(f);
932
+ } catch (f) {
933
+ y(f);
931
934
  }
932
935
  });
933
936
  });
@@ -957,17 +960,17 @@ const P = class P extends z.Doc {
957
960
  {
958
961
  const r = R.createEncoder();
959
962
  R.writeVarUint(r, he), gs(r, this), this.send(t, R.toUint8Array(r));
960
- const a = this.awareness.getStates();
961
- if (a.size > 0) {
962
- const i = R.createEncoder();
963
- R.writeVarUint(i, Re), R.writeVarUint8Array(i, qe(this.awareness, Array.from(a.keys()))), this.send(t, R.toUint8Array(i));
963
+ const i = this.awareness.getStates();
964
+ if (i.size > 0) {
965
+ const d = R.createEncoder();
966
+ R.writeVarUint(d, Re), R.writeVarUint8Array(d, qe(this.awareness, Array.from(i.keys()))), this.send(t, R.toUint8Array(d));
964
967
  }
965
968
  }
966
969
  });
967
970
  k(this, "messageListener", (t, s) => {
968
971
  try {
969
- const o = R.createEncoder(), r = ke.createDecoder(s), a = ke.readVarUint(r);
970
- switch (a) {
972
+ const o = R.createEncoder(), r = ke.createDecoder(s), i = ke.readVarUint(r);
973
+ switch (i) {
971
974
  case he:
972
975
  R.writeVarUint(o, he), ys(r, o, this, null), R.length(o) > 1 && (this.ensureDataStructure(), this.send(t, R.toUint8Array(o)));
973
976
  break;
@@ -976,7 +979,7 @@ const P = class P extends z.Doc {
976
979
  break;
977
980
  }
978
981
  default:
979
- S.warn(`Unsupported messageType ${a}`);
982
+ S.warn(`Unsupported messageType ${i}`);
980
983
  }
981
984
  } catch (o) {
982
985
  S.error(o);
@@ -1020,59 +1023,59 @@ const P = class P extends z.Doc {
1020
1023
  });
1021
1024
  }
1022
1025
  static get allShared() {
1023
- return this.projectIds.map((t) => P.shared(t));
1026
+ return this.projectIds.map((t) => T.shared(t));
1024
1027
  }
1025
1028
  static shared(t) {
1026
1029
  if (!t)
1027
1030
  throw new Error("Should provide project context");
1028
- let s = P.sharedInstances[t];
1029
- return s || (s = new P({
1031
+ let s = T.sharedInstances[t];
1032
+ return s || (s = new T({
1030
1033
  path: O(de, t)
1031
- }), P.sharedInstances[t] = s, At({
1034
+ }), T.sharedInstances[t] = s, At({
1032
1035
  projectId: t,
1033
- pages: Te,
1034
- components: Pe
1036
+ pages: Pe,
1037
+ components: Te
1035
1038
  }), s);
1036
1039
  }
1037
1040
  // 轻量级 production 状态获取,不加载 draft 数据
1038
1041
  static async getProductionState(t) {
1039
1042
  var o, r;
1040
- let s = P.productionStates.get(t);
1043
+ let s = T.productionStates.get(t);
1041
1044
  if (!s) {
1042
- const a = O(de, t, "production");
1043
- if (s = await wt(a, { includeResources: !0 }) ?? en(), !((o = s == null ? void 0 : s.config) != null && o.defaultLocale)) {
1045
+ const i = O(de, t, "production");
1046
+ if (s = await wt(i, { includeResources: !0 }) ?? en(), !((o = s == null ? void 0 : s.config) != null && o.defaultLocale)) {
1044
1047
  s.config ?? (s.config = {});
1045
- const i = Me.env.languages.map((p) => ({ locale: p.code, name: p.name }));
1046
- s.config.defaultLocale = (r = i[0]) == null ? void 0 : r.locale;
1048
+ const d = $e.env.languages.map((p) => ({ locale: p.code, name: p.name }));
1049
+ s.config.defaultLocale = (r = d[0]) == null ? void 0 : r.locale;
1047
1050
  }
1048
- P.productionStates.set(t, s);
1051
+ T.productionStates.set(t, s);
1049
1052
  }
1050
1053
  return {
1051
1054
  ...s,
1052
- resources: await Ve().then(async (a) => {
1053
- var y, m;
1054
- const { pages: i, components: p } = rs(a, "pages", "components");
1055
- let c = p;
1055
+ resources: await Ve().then(async (i) => {
1056
+ var y, f;
1057
+ const { pages: d, components: p } = rs(i, "pages", "components");
1058
+ let a = p;
1056
1059
  const u = await se.findByPk(t);
1057
1060
  if (u != null && u.useAllResources)
1058
- c = p;
1061
+ a = p;
1059
1062
  else {
1060
- const l = (await Ce.findAll({ where: { projectId: t } })).map((w) => w.componentId);
1061
- c = Object.fromEntries(
1062
- Object.entries(p || {}).filter(([w]) => l.includes(w))
1063
+ const c = (await Ce.findAll({ where: { projectId: t } })).map((w) => w.componentId);
1064
+ a = Object.fromEntries(
1065
+ Object.entries(p || {}).filter(([w]) => c.includes(w))
1063
1066
  );
1064
1067
  }
1065
- return Object.keys(((y = s == null ? void 0 : s.resources) == null ? void 0 : y.components) || {}).length > 0 && (c = {
1066
- ...c,
1067
- ...(m = s == null ? void 0 : s.resources) == null ? void 0 : m.components
1068
- }), { pages: i, components: c };
1068
+ return Object.keys(((y = s == null ? void 0 : s.resources) == null ? void 0 : y.components) || {}).length > 0 && (a = {
1069
+ ...a,
1070
+ ...(f = s == null ? void 0 : s.resources) == null ? void 0 : f.components
1071
+ }), { pages: d, components: a };
1069
1072
  }).catch(() => ({}))
1070
1073
  };
1071
1074
  }
1072
1075
  destroy() {
1073
1076
  this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, o) => this.closeConn(o)), this.awareness.destroy();
1074
1077
  const t = J(this.options.path);
1075
- delete P.sharedInstances[t], super.destroy();
1078
+ delete T.sharedInstances[t], super.destroy();
1076
1079
  }
1077
1080
  initObserver() {
1078
1081
  zs(this.syncedStore), Ks(this.syncedStore);
@@ -1082,22 +1085,22 @@ const P = class P extends z.Doc {
1082
1085
  }
1083
1086
  static async getStateByProjectId(t, s) {
1084
1087
  if (s === "draft") {
1085
- const o = P.shared(t);
1088
+ const o = T.shared(t);
1086
1089
  return JSON.parse(JSON.stringify(o.syncedStore));
1087
1090
  }
1088
- return P.getProductionState(t);
1091
+ return T.getProductionState(t);
1089
1092
  }
1090
1093
  async getState(t) {
1091
1094
  if (t === "draft")
1092
1095
  return JSON.parse(JSON.stringify(this.syncedStore));
1093
1096
  const s = J(this.options.path);
1094
- return P.getProductionState(s);
1097
+ return T.getProductionState(s);
1095
1098
  }
1096
1099
  async setState(t, s) {
1097
1100
  const o = await on(s, { exportAssets: !1, includeResources: !0 }), r = this.getPublishDir(t);
1098
1101
  if (Y(U(r), { recursive: !0 }), ct(r, { force: !0, recursive: !0 }), Ye(o, r), t === "production") {
1099
- const a = J(this.options.path);
1100
- P.productionStates.set(a, s);
1102
+ const i = J(this.options.path);
1103
+ T.productionStates.set(i, s);
1101
1104
  }
1102
1105
  }
1103
1106
  getPublishDir(t) {
@@ -1113,7 +1116,7 @@ const P = class P extends z.Doc {
1113
1116
  const t = J(this.options.path);
1114
1117
  this.releaseTimer = setTimeout(() => {
1115
1118
  S.info(`[SiteState] releasing instance due to no active connections: ${t}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
1116
- }, P.RELEASE_DELAY), S.info(`[SiteState] scheduled release for project ${t} in ${P.RELEASE_DELAY / 1e3}s`);
1119
+ }, T.RELEASE_DELAY), S.info(`[SiteState] scheduled release for project ${t} in ${T.RELEASE_DELAY / 1e3}s`);
1117
1120
  }
1118
1121
  // 取消延迟释放
1119
1122
  cancelRelease() {
@@ -1124,41 +1127,41 @@ const P = class P extends z.Doc {
1124
1127
  }
1125
1128
  }
1126
1129
  static async pageUrlMap(t, s) {
1127
- var a, i;
1130
+ var i, d;
1128
1131
  let { projectIds: o } = this;
1129
1132
  s && (o = [s]);
1130
1133
  const r = {};
1131
1134
  for (const p of o) {
1132
- const c = await se.findByPk(p);
1133
- if (!c) continue;
1134
- const u = await P.getStateByProjectId(p, t), y = c.slug || p, m = as(
1135
- I.env.languages.map((l) => l.code),
1136
- u.supportedLocales.map((l) => l.locale)
1137
- ), d = (l, f) => {
1138
- y && (r[W("/", y, l)] = {
1139
- ...f,
1135
+ const a = await se.findByPk(p);
1136
+ if (!a) continue;
1137
+ const u = await T.getStateByProjectId(p, t), y = a.slug || p, f = as(
1138
+ I.env.languages.map((c) => c.code),
1139
+ u.supportedLocales.map((c) => c.locale)
1140
+ ), l = (c, m) => {
1141
+ y && (r[W("/", y, c)] = {
1142
+ ...m,
1140
1143
  shouldRedirect: !0,
1141
1144
  mainPage: !0
1142
- }), r[W("/", p, l)] = {
1143
- ...f,
1145
+ }), r[W("/", p, c)] = {
1146
+ ...m,
1144
1147
  shouldRedirect: !0,
1145
1148
  mainPage: !0
1146
1149
  };
1147
- for (const w of m) {
1148
- const D = { ...f, locale: w };
1149
- r[W("/", w, p, l)] = D, y && (r[W("/", w, y, l)] = D);
1150
+ for (const w of f) {
1151
+ const D = { ...m, locale: w };
1152
+ r[W("/", w, p, c)] = D, y && (r[W("/", w, y, c)] = D);
1150
1153
  }
1151
1154
  };
1152
1155
  if (t === "draft")
1153
- for (const l of u.routeIds || []) {
1154
- const f = (a = u == null ? void 0 : u.routes) == null ? void 0 : a[l];
1155
- if (!f) continue;
1156
- if (f.params && f.params.length > 0) {
1156
+ for (const c of u.routeIds || []) {
1157
+ const m = (i = u == null ? void 0 : u.routes) == null ? void 0 : i[c];
1158
+ if (!m) continue;
1159
+ if (m.params && m.params.length > 0) {
1157
1160
  const C = Ue({
1158
- basePath: f.path,
1159
- params: f.params,
1160
- routeId: f.id,
1161
- paramsOptions: f.paramsOptions,
1161
+ basePath: m.path,
1162
+ params: m.params,
1163
+ routeId: m.id,
1164
+ paramsOptions: m.paramsOptions,
1162
1165
  currentIndex: 0,
1163
1166
  currentParams: [],
1164
1167
  currentOptionIds: [],
@@ -1169,48 +1172,48 @@ const P = class P extends z.Doc {
1169
1172
  projectId: p,
1170
1173
  projectSlug: y,
1171
1174
  pageSlug: Q,
1172
- pageId: f.displayTemplateId || "",
1173
- routeId: l,
1175
+ pageId: m.displayTemplateId || "",
1176
+ routeId: c,
1174
1177
  // default locale
1175
- defaultLocale: m == null ? void 0 : m[0],
1176
- locales: m,
1178
+ defaultLocale: f == null ? void 0 : f[0],
1179
+ locales: f,
1177
1180
  publishedAt: u.config.publishedAt,
1178
- isPublic: f.isPublic && ((i = L == null ? void 0 : L.routeMetaData) == null ? void 0 : i.isPublic)
1181
+ isPublic: m.isPublic && ((d = L == null ? void 0 : L.routeMetaData) == null ? void 0 : d.isPublic)
1179
1182
  };
1180
- d(Q, ne);
1183
+ l(Q, ne);
1181
1184
  }
1182
1185
  }
1183
- const w = f.path, D = {
1186
+ const w = m.path, D = {
1184
1187
  projectId: p,
1185
1188
  projectSlug: y,
1186
1189
  pageSlug: w,
1187
- pageId: f.displayTemplateId || "",
1188
- routeId: l,
1190
+ pageId: m.displayTemplateId || "",
1191
+ routeId: c,
1189
1192
  // default locale
1190
- defaultLocale: m == null ? void 0 : m[0],
1191
- locales: m,
1193
+ defaultLocale: f == null ? void 0 : f[0],
1194
+ locales: f,
1192
1195
  publishedAt: u.config.publishedAt,
1193
- isPublic: f.isPublic
1196
+ isPublic: m.isPublic
1194
1197
  };
1195
- d(w, D);
1198
+ l(w, D);
1196
1199
  }
1197
- for (const l of u.pageIds) {
1198
- const f = u.pages[l];
1199
- if (!f || t === "production" && !f.isPublic)
1200
+ for (const c of u.pageIds) {
1201
+ const m = u.pages[c];
1202
+ if (!m || t === "production" && !m.isPublic)
1200
1203
  continue;
1201
- const w = f.slug, D = c.slug || p, C = {
1204
+ const w = m.slug, D = a.slug || p, C = {
1202
1205
  projectId: p,
1203
1206
  projectSlug: D,
1204
1207
  pageSlug: w,
1205
- pageId: l,
1208
+ pageId: c,
1206
1209
  // default locale
1207
- defaultLocale: m == null ? void 0 : m[0],
1208
- locales: m,
1210
+ defaultLocale: f == null ? void 0 : f[0],
1211
+ locales: f,
1209
1212
  publishedAt: u.config.publishedAt,
1210
- isPublic: f.isPublic,
1211
- templateConfig: f.templateConfig
1213
+ isPublic: m.isPublic,
1214
+ templateConfig: m.templateConfig
1212
1215
  };
1213
- d(w, C);
1216
+ l(w, C);
1214
1217
  }
1215
1218
  }
1216
1219
  return r;
@@ -1220,7 +1223,7 @@ const P = class P extends z.Doc {
1220
1223
  }
1221
1224
  static getInstancesSizeInfo() {
1222
1225
  const t = [];
1223
- for (const [s, o] of Object.entries(P.sharedInstances)) {
1226
+ for (const [s, o] of Object.entries(T.sharedInstances)) {
1224
1227
  const r = o.getDocumentSize();
1225
1228
  t.push({
1226
1229
  projectId: s,
@@ -1245,22 +1248,22 @@ const P = class P extends z.Doc {
1245
1248
  }
1246
1249
  // 执行定期检查
1247
1250
  static performPeriodicCheck() {
1248
- const t = Object.keys(P.sharedInstances).length, s = [], o = [];
1249
- for (const [r, a] of Object.entries(P.sharedInstances))
1250
- a.conns.size === 0 ? s.push({ projectId: r, instance: a }) : o.push({ projectId: r, connections: a.conns.size });
1251
+ const t = Object.keys(T.sharedInstances).length, s = [], o = [];
1252
+ for (const [r, i] of Object.entries(T.sharedInstances))
1253
+ i.conns.size === 0 ? s.push({ projectId: r, instance: i }) : o.push({ projectId: r, connections: i.conns.size });
1251
1254
  if (S.info(
1252
1255
  `[SiteState] periodic check summary: total instances: ${t}, with connections: ${o.length}, without connections: ${s.length}`
1253
1256
  ), s.length > 0) {
1254
1257
  S.info(
1255
1258
  `[SiteState] releasing ${s.length} instances without connections:`,
1256
- s.map((a) => a.projectId)
1259
+ s.map((i) => i.projectId)
1257
1260
  );
1258
1261
  let r = 0;
1259
- for (const { projectId: a, instance: i } of s)
1262
+ for (const { projectId: i, instance: d } of s)
1260
1263
  try {
1261
- S.info(`[SiteState] releasing instance due to periodic check: ${a}`), i.destroy(), r++;
1264
+ S.info(`[SiteState] releasing instance due to periodic check: ${i}`), d.destroy(), r++;
1262
1265
  } catch (p) {
1263
- S.error(`[SiteState] failed to release instance ${a} during periodic check:`, p);
1266
+ S.error(`[SiteState] failed to release instance ${i} during periodic check:`, p);
1264
1267
  }
1265
1268
  S.info(
1266
1269
  `[SiteState] periodic check completed: ${r}/${s.length} instances released successfully`
@@ -1268,16 +1271,16 @@ const P = class P extends z.Doc {
1268
1271
  } else t > 0 ? S.debug("[SiteState] periodic check: all instances have active connections") : S.debug("[SiteState] periodic check: no instances exist");
1269
1272
  }
1270
1273
  };
1271
- k(P, "PRODUCTION_CACHE_TTL", 7 * 24 * 60 * 60 * 1e3), // 7 days
1274
+ k(T, "PRODUCTION_CACHE_TTL", 7 * 24 * 60 * 60 * 1e3), // 7 days
1272
1275
  // 延迟释放时间:5分钟
1273
- k(P, "RELEASE_DELAY", 5 * 60 * 1e3), // 定期检查间隔:2 小时
1274
- k(P, "PERIODIC_CHECK_INTERVAL", 2 * 60 * 60 * 1e3), // 2 hours
1275
- k(P, "sharedInstances", {}), k(P, "productionStates", new $e({
1276
+ k(T, "RELEASE_DELAY", 5 * 60 * 1e3), // 定期检查间隔:2 小时
1277
+ k(T, "PERIODIC_CHECK_INTERVAL", 2 * 60 * 60 * 1e3), // 2 hours
1278
+ k(T, "sharedInstances", {}), k(T, "productionStates", new Me({
1276
1279
  max: 100,
1277
- ttl: P.PRODUCTION_CACHE_TTL
1280
+ ttl: T.PRODUCTION_CACHE_TTL
1278
1281
  })), // 定期检查定时器
1279
- k(P, "periodicCheckTimer");
1280
- let q = P;
1282
+ k(T, "periodicCheckTimer");
1283
+ let q = T;
1281
1284
  async function tn(e, n, t) {
1282
1285
  if (!e || !H(e) || !oe(e).isFile())
1283
1286
  return null;
@@ -1324,44 +1327,44 @@ function St(e) {
1324
1327
  async function ge(e, n, t) {
1325
1328
  const { getFilename: s, exportAssets: o } = t, r = O(n, s(e));
1326
1329
  if (Y(U(r), { recursive: !0 }), we(r, ae.stringify(e)), o) {
1327
- const i = be(
1330
+ const d = be(
1328
1331
  e,
1329
1332
  (p) => typeof p == "string" && (Ge.test(p) || fe.test(p))
1330
1333
  ).map((p) => {
1331
- const c = Fe(e, p);
1332
- return St(c);
1334
+ const a = Fe(e, p);
1335
+ return St(a);
1333
1336
  }).flat().filter(Boolean);
1334
- await nn(i, U(r));
1337
+ await nn(d, U(r));
1335
1338
  }
1336
1339
  }
1337
- const st = new $e({
1340
+ const st = new Me({
1338
1341
  max: 20,
1339
1342
  ttl: 30 * 24 * 60 * 60 * 1e3
1340
1343
  });
1341
1344
  async function nt(e, n, t) {
1342
- var i;
1345
+ var d;
1343
1346
  const s = be(
1344
1347
  e,
1345
1348
  (p) => typeof p == "string" && (Ge.test(p) || fe.test(p))
1346
1349
  ), o = cs(2), r = s.map(
1347
1350
  (p) => o(async () => {
1348
1351
  try {
1349
- const c = Fe(e, p), u = St(c);
1352
+ const a = Fe(e, p), u = St(a);
1350
1353
  for (const y of u) {
1351
- const m = J(y), d = t.getFilePath(y, p), l = d ? `${d}:${m}` : m, f = st.get(l);
1352
- if (f) {
1353
- fe.test(c) || We(e, p, f);
1354
+ const f = J(y), l = t.getFilePath(y, p), c = l ? `${l}:${f}` : f, m = st.get(c);
1355
+ if (m) {
1356
+ fe.test(a) || We(e, p, m);
1354
1357
  return;
1355
1358
  }
1356
- const w = await tn(d, m, n);
1357
- w && (fe.test(c) || We(e, p, w), st.set(l, w));
1359
+ const w = await tn(l, f, n);
1360
+ w && (fe.test(a) || We(e, p, w), st.set(c, w));
1358
1361
  }
1359
- } catch (c) {
1360
- S.error(`Failed to process upload for path ${p.join(".")}:`, c.message || c.reason);
1362
+ } catch (a) {
1363
+ S.error(`Failed to process upload for path ${p.join(".")}:`, a.message || a.reason);
1361
1364
  }
1362
1365
  })
1363
- ), a = await Promise.allSettled(r);
1364
- (i = t.onFinish) == null || i.call(t, a);
1366
+ ), i = await Promise.allSettled(r);
1367
+ (d = t.onFinish) == null || d.call(t, i);
1365
1368
  }
1366
1369
  async function on(e, {
1367
1370
  exportAssets: n,
@@ -1369,14 +1372,14 @@ async function on(e, {
1369
1372
  componentIds: s = "all",
1370
1373
  rawConfig: o,
1371
1374
  includeResources: r = !1,
1372
- routeIds: a = "all"
1375
+ routeIds: i = "all"
1373
1376
  } = {}) {
1374
1377
  var le, E, h, A, v, X, b, N, F, Z, K, pe;
1375
- const i = t === "all" ? e.pageIds : t, p = kt({
1378
+ const d = t === "all" ? e.pageIds : t, p = kt({
1376
1379
  state: e,
1377
- pageIds: i,
1380
+ pageIds: d,
1378
1381
  componentIds: s === "all" ? Object.keys(e.components) : s
1379
- }), c = a === "all" ? e.routeIds : a, u = (g) => ({
1382
+ }), a = i === "all" ? e.routeIds : i, u = (g) => ({
1380
1383
  id: g.id,
1381
1384
  name: g.name,
1382
1385
  isTemplateSection: g.isTemplateSection ?? !1,
@@ -1389,7 +1392,7 @@ async function on(e, {
1389
1392
  sectionIds: g.sectionIds
1390
1393
  // 已经废弃,数据在 page.dataSource 中管理
1391
1394
  // properties: section.locales?.[locale] ?? {},
1392
- }), y = (g, T) => {
1395
+ }), y = (g, P) => {
1393
1396
  var j;
1394
1397
  return {
1395
1398
  id: g.id,
@@ -1398,8 +1401,8 @@ async function on(e, {
1398
1401
  publishedAt: g.publishedAt,
1399
1402
  isPublic: g.isPublic ?? !0,
1400
1403
  templateConfig: g.templateConfig,
1401
- meta: ((j = g.locales) == null ? void 0 : j[T]) ?? {},
1402
- sections: $(
1404
+ meta: ((j = g.locales) == null ? void 0 : j[P]) ?? {},
1405
+ sections: M(
1403
1406
  g.sectionIds.map((B) => {
1404
1407
  const _ = g.sections[B];
1405
1408
  return _ && u(_);
@@ -1407,10 +1410,10 @@ async function on(e, {
1407
1410
  ),
1408
1411
  // 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
1409
1412
  dataSource: Object.fromEntries(
1410
- Object.entries(g.dataSource || {}).map(([B, _]) => [B, (_ == null ? void 0 : _[T]) ?? {}])
1413
+ Object.entries(g.dataSource || {}).map(([B, _]) => [B, (_ == null ? void 0 : _[P]) ?? {}])
1411
1414
  )
1412
1415
  };
1413
- }, m = (g) => ({
1416
+ }, f = (g) => ({
1414
1417
  id: g.id,
1415
1418
  createdAt: g.createdAt,
1416
1419
  updatedAt: g.updatedAt,
@@ -1422,15 +1425,15 @@ async function on(e, {
1422
1425
  enabledGenerate: g.enabledGenerate ?? !1,
1423
1426
  displayTemplateId: g.displayTemplateId,
1424
1427
  dataSource: g.dataSource
1425
- }), d = $(
1426
- c.map((g) => {
1427
- const T = e.routes[g];
1428
- return T && m(T);
1428
+ }), l = M(
1429
+ a.map((g) => {
1430
+ const P = e.routes[g];
1431
+ return P && f(P);
1429
1432
  })
1430
- ), l = $(
1433
+ ), c = M(
1431
1434
  e.supportedLocales.map((g) => g.locale).flatMap(
1432
- (g) => i.map((T) => {
1433
- const j = e.pages[T];
1435
+ (g) => d.map((P) => {
1436
+ const j = e.pages[P];
1434
1437
  return j && {
1435
1438
  locale: g,
1436
1439
  slug: j.slug,
@@ -1438,63 +1441,63 @@ async function on(e, {
1438
1441
  };
1439
1442
  })
1440
1443
  )
1441
- ), f = yt(), w = O(f, "pages");
1444
+ ), m = yt(), w = O(m, "pages");
1442
1445
  Y(w, { recursive: !0 });
1443
- const D = O(f, "components");
1446
+ const D = O(m, "components");
1444
1447
  Y(D, { recursive: !0 });
1445
- const C = O(f, "routes");
1448
+ const C = O(m, "routes");
1446
1449
  Y(C, { recursive: !0 });
1447
- for (const { locale: g, slug: T, page: j } of l)
1450
+ for (const { locale: g, slug: P, page: j } of c)
1448
1451
  await ge(j, w, {
1449
- getFilename: () => `${Ae(T) || "index"}.${g}.yml`,
1452
+ getFilename: () => `${Ae(P) || "index"}.${g}.yml`,
1450
1453
  exportAssets: n
1451
1454
  });
1452
- for (const g of d)
1455
+ for (const g of l)
1453
1456
  await ge(g, C, {
1454
1457
  // getFilename: () => `${sanitizeSlug(route.path)}.yml`,
1455
1458
  getFilename: () => `${Ae(g.path) || "index"}.yml`,
1456
1459
  exportAssets: n
1457
1460
  });
1458
1461
  for (const g of p) {
1459
- const T = (le = e.components[g]) == null ? void 0 : le.data;
1460
- T && await ge(T, D, {
1462
+ const P = (le = e.components[g]) == null ? void 0 : le.data;
1463
+ P && await ge(P, D, {
1461
1464
  getFilename: (j) => `${j.name || "unnamed"}.${j.id}.yml`,
1462
1465
  exportAssets: n
1463
1466
  });
1464
1467
  }
1465
- const L = O(f, ".blocklet/pages/pages.config.yml");
1468
+ const L = O(m, ".blocklet/pages/pages.config.yml");
1466
1469
  Y(U(L), { recursive: !0 });
1467
1470
  const Q = {
1468
- pages: $(
1469
- i.map((g) => {
1470
- const T = e.pages[g];
1471
- return T && { id: g, slug: T.slug };
1471
+ pages: M(
1472
+ d.map((g) => {
1473
+ const P = e.pages[g];
1474
+ return P && { id: g, slug: P.slug };
1472
1475
  })
1473
1476
  ),
1474
- routes: $(
1475
- c.map((g) => {
1476
- const T = e.routes[g];
1477
- return T && { id: g, path: T.path };
1477
+ routes: M(
1478
+ a.map((g) => {
1479
+ const P = e.routes[g];
1480
+ return P && { id: g, path: P.path };
1478
1481
  })
1479
1482
  ),
1480
- components: $(
1483
+ components: M(
1481
1484
  p.map((g) => {
1482
1485
  var j;
1483
- const T = (j = e.components[g]) == null ? void 0 : j.data;
1484
- return T && {
1486
+ const P = (j = e.components[g]) == null ? void 0 : j.data;
1487
+ return P && {
1485
1488
  id: g,
1486
- name: T.name
1489
+ name: P.name
1487
1490
  };
1488
1491
  })
1489
1492
  ),
1490
1493
  ...r ? {
1491
1494
  resources: {
1492
- components: $(
1495
+ components: M(
1493
1496
  Object.keys(((E = e.resources) == null ? void 0 : E.components) || {}).filter((g) => p.includes(g)).map((g) => {
1494
- var T, j, B, _;
1497
+ var P, j, B, _;
1495
1498
  return {
1496
1499
  id: g,
1497
- name: (_ = (B = (j = (T = e.resources) == null ? void 0 : T.components) == null ? void 0 : j[g]) == null ? void 0 : B.component) == null ? void 0 : _.name
1500
+ name: (_ = (B = (j = (P = e.resources) == null ? void 0 : P.components) == null ? void 0 : j[g]) == null ? void 0 : B.component) == null ? void 0 : _.name
1498
1501
  };
1499
1502
  })
1500
1503
  )
@@ -1504,20 +1507,20 @@ async function on(e, {
1504
1507
  config: e.config
1505
1508
  };
1506
1509
  we(L, ae.stringify(Q));
1507
- const ne = O(f, "config.source.json");
1510
+ const ne = O(m, "config.source.json");
1508
1511
  if (o && we(ne, JSON.stringify(o)), r) {
1509
- const g = O(f, "resources"), T = O(g, "components");
1510
- Y(T, { recursive: !0 });
1512
+ const g = O(m, "resources"), P = O(g, "components");
1513
+ Y(P, { recursive: !0 });
1511
1514
  for (const _ of Object.keys(((h = e == null ? void 0 : e.resources) == null ? void 0 : h.components) ?? {}).filter(
1512
1515
  (G) => p.includes(G)
1513
1516
  )) {
1514
1517
  const G = (X = (v = (A = e.resources) == null ? void 0 : A.components) == null ? void 0 : v[_]) == null ? void 0 : X.component;
1515
- G && await ge(G, T, {
1518
+ G && await ge(G, P, {
1516
1519
  getFilename: (ee) => `${ee.name || "unnamed"}.${ee.id}.yml`,
1517
1520
  exportAssets: n
1518
1521
  });
1519
1522
  }
1520
- const j = O(f, "chunks");
1523
+ const j = O(m, "chunks");
1521
1524
  Y(j, { recursive: !0 });
1522
1525
  const { chunks: B } = await Ve();
1523
1526
  for (const _ of Object.keys(((b = e == null ? void 0 : e.resources) == null ? void 0 : b.components) ?? {}).filter(
@@ -1538,19 +1541,19 @@ async function on(e, {
1538
1541
  }
1539
1542
  }
1540
1543
  }
1541
- return f;
1544
+ return m;
1542
1545
  }
1543
1546
  async function wt(e, { importAssets: n, includeResources: t } = {}) {
1544
- var r, a, i, p;
1547
+ var r, i, d, p;
1545
1548
  if (!H(e))
1546
1549
  return null;
1547
1550
  let s, o = !1;
1548
1551
  try {
1549
1552
  oe(e).isDirectory() ? s = e : /\.(tgz|gz|tar)$/.test(e) && (o = !0, s = yt(), await ps({ file: e, C: s }));
1550
- const c = Ne("**/.blocklet/pages/pages.config.yml", { cwd: s, absolute: !0 }).at(0), u = c && O(U(c), "../../pages"), y = c && O(U(c), "../../components"), m = c && O(U(c), "../../chunks"), d = c && O(U(c), "../../routes");
1551
- if (!c)
1553
+ const a = Ne("**/.blocklet/pages/pages.config.yml", { cwd: s, absolute: !0 }).at(0), u = a && O(U(a), "../../pages"), y = a && O(U(a), "../../components"), f = a && O(U(a), "../../chunks"), l = a && O(U(a), "../../routes");
1554
+ if (!a)
1552
1555
  return null;
1553
- const l = ae.parse(re(c).toString()), f = (E, h, A) => {
1556
+ const c = ae.parse(re(a).toString()), m = (E, h, A) => {
1554
1557
  let v = O(E, `${h}${A ? `.${A}` : ""}.yml`);
1555
1558
  return (!H(v) || !oe(v).isFile()) && (v = O(E, h, `index${A ? `.${A}` : ""}.yml`), !H(v) || !oe(v)) ? null : ae.parse(re(v).toString());
1556
1559
  }, w = (E, h) => {
@@ -1564,15 +1567,15 @@ async function wt(e, { importAssets: n, includeResources: t } = {}) {
1564
1567
  }, D = (E, h) => {
1565
1568
  let A = O(E, `${h}.yml`);
1566
1569
  return (!H(A) || !oe(A).isFile()) && (A = O(E, h, "index.yml"), !H(A) || !oe(A)) ? null : ae.parse(re(A).toString());
1567
- }, C = $(
1568
- l.pages.map(({ slug: E }) => {
1570
+ }, C = M(
1571
+ c.pages.map(({ slug: E }) => {
1569
1572
  var X;
1570
- const h = $(
1571
- l.supportedLocales.map(({ locale: b }) => {
1572
- const N = u ? f(u, Ae(E), b) : void 0;
1573
+ const h = M(
1574
+ c.supportedLocales.map(({ locale: b }) => {
1575
+ const N = u ? m(u, Ae(E), b) : void 0;
1573
1576
  if (N)
1574
1577
  return { locale: b, page: N };
1575
- const F = u ? f(u, E, b) : void 0;
1578
+ const F = u ? m(u, E, b) : void 0;
1576
1579
  return F && { locale: b, page: F };
1577
1580
  })
1578
1581
  ), A = (X = h[0]) == null ? void 0 : X.page;
@@ -1640,9 +1643,9 @@ async function wt(e, { importAssets: n, includeResources: t } = {}) {
1640
1643
  )
1641
1644
  };
1642
1645
  })
1643
- ), L = $(
1644
- ((r = l == null ? void 0 : l.routes) == null ? void 0 : r.map(({ path: E }) => {
1645
- const h = d ? D(d, Ae(E)) : void 0;
1646
+ ), L = M(
1647
+ ((r = c == null ? void 0 : c.routes) == null ? void 0 : r.map(({ path: E }) => {
1648
+ const h = l ? D(l, Ae(E)) : void 0;
1646
1649
  return {
1647
1650
  ...h,
1648
1651
  id: (h == null ? void 0 : h.id) || xe(),
@@ -1658,7 +1661,7 @@ async function wt(e, { importAssets: n, includeResources: t } = {}) {
1658
1661
  dataSource: (h == null ? void 0 : h.dataSource) ?? {}
1659
1662
  };
1660
1663
  })) ?? []
1661
- ), Q = y ? $(((a = l.components) == null ? void 0 : a.map(({ id: E }) => w(y, E))) ?? []) : [];
1664
+ ), Q = y ? M(((i = c.components) == null ? void 0 : i.map(({ id: E }) => w(y, E))) ?? []) : [];
1662
1665
  if (n) {
1663
1666
  const E = (...h) => {
1664
1667
  S.info(`[${o ? J(e) : J(O(e, "../../../../"))}] importAssets:`, ...h);
@@ -1692,25 +1695,25 @@ async function wt(e, { importAssets: n, includeResources: t } = {}) {
1692
1695
  }
1693
1696
  const ne = {};
1694
1697
  if (t) {
1695
- const E = c && O(U(c), "../../resources/components"), h = $(
1696
- ((p = (i = l.resources) == null ? void 0 : i.components) == null ? void 0 : p.map(({ id: A }) => w(E, A))) ?? []
1698
+ const E = a && O(U(a), "../../resources/components"), h = M(
1699
+ ((p = (d = c.resources) == null ? void 0 : d.components) == null ? void 0 : p.map(({ id: A }) => w(E, A))) ?? []
1697
1700
  );
1698
1701
  h.length > 0 && (ne.components = Object.fromEntries(
1699
1702
  h.map((A, v) => [A.id, { index: v, component: A }])
1700
1703
  ));
1701
1704
  }
1702
1705
  const le = {};
1703
- if (m && H(m)) {
1704
- const E = Ut(m);
1706
+ if (f && H(f)) {
1707
+ const E = Ut(f);
1705
1708
  for (const h of E)
1706
- le[h] = O(m, h);
1709
+ le[h] = O(f, h);
1707
1710
  }
1708
1711
  return {
1709
- supportedLocales: l.supportedLocales,
1712
+ supportedLocales: c.supportedLocales,
1710
1713
  pageIds: C.map((E) => E.id),
1711
1714
  components: Object.fromEntries(Q.map((E, h) => [E.id, { index: h, data: E }])),
1712
1715
  pages: Object.fromEntries(C.map((E) => [E.id, E])),
1713
- config: l.config || {},
1716
+ config: c.config || {},
1714
1717
  resources: ne,
1715
1718
  chunks: le,
1716
1719
  routeIds: L.map((E) => E.id),
@@ -1729,131 +1732,131 @@ async function ot(e, n, {
1729
1732
  publishMode: r = void 0
1730
1733
  } = {}) {
1731
1734
  try {
1732
- r && Ms(r);
1733
- } catch (m) {
1734
- S.error("clear preload page cache error", { error: m });
1735
+ r && $s(r);
1736
+ } catch (f) {
1737
+ S.error("clear preload page cache error", { error: f });
1735
1738
  }
1736
- const { pages: a, pageIds: i, routeIds: p, routes: c, supportedLocales: u } = e;
1739
+ const { pages: i, pageIds: d, routeIds: p, routes: a, supportedLocales: u } = e;
1737
1740
  if (r === "production") {
1738
- let m = t ?? [], d = null;
1739
- for (const l of p ?? []) {
1740
- const f = c == null ? void 0 : c[l];
1741
- if (f != null && f.params && (f == null ? void 0 : f.params.length) > 0 && (f != null && f.paramsOptions) && (f == null ? void 0 : f.paramsOptions.length) > 0) {
1741
+ let f = t ?? [], l = null;
1742
+ for (const c of p ?? []) {
1743
+ const m = a == null ? void 0 : a[c];
1744
+ if (m != null && m.params && (m == null ? void 0 : m.params.length) > 0 && (m != null && m.paramsOptions) && (m == null ? void 0 : m.paramsOptions.length) > 0) {
1742
1745
  const w = Ue({
1743
- basePath: f.path,
1744
- params: f.params,
1745
- routeId: f.id,
1746
- paramsOptions: f.paramsOptions,
1746
+ basePath: m.path,
1747
+ params: m.params,
1748
+ routeId: m.id,
1749
+ paramsOptions: m.paramsOptions,
1747
1750
  currentIndex: 0,
1748
1751
  currentParams: [],
1749
1752
  currentOptionIds: [],
1750
1753
  result: []
1751
- }), D = Object.fromEntries(w.map((C) => [`${l}-${C.paramOptionIds.join("-")}`, C]));
1752
- d = { ...d || {}, ...D }, t || (m = [...m, ...w.map((C) => `${l}-${C.paramOptionIds.join("-")}`)]);
1753
- } else t || m.push(l);
1754
+ }), D = Object.fromEntries(w.map((C) => [`${c}-${C.paramOptionIds.join("-")}`, C]));
1755
+ l = { ...l || {}, ...D }, t || (f = [...f, ...w.map((C) => `${c}-${C.paramOptionIds.join("-")}`)]);
1756
+ } else t || f.push(c);
1754
1757
  }
1755
- S.info("routeIds to be published: ", m);
1756
- for (const l of m) {
1757
- let f = l;
1758
- if (f.includes("-")) {
1759
- const [C] = f.split("-");
1760
- f = C;
1758
+ S.info("routeIds to be published: ", f);
1759
+ for (const c of f) {
1760
+ let m = c;
1761
+ if (m.includes("-")) {
1762
+ const [C] = m.split("-");
1763
+ m = C;
1761
1764
  }
1762
- const w = c == null ? void 0 : c[f];
1765
+ const w = a == null ? void 0 : a[m];
1763
1766
  if (!w) {
1764
- const C = n.pageIds.indexOf(f);
1765
- C !== -1 && o && (n.pageIds.splice(C, 1), delete n.pages[f]);
1767
+ const C = n.pageIds.indexOf(m);
1768
+ C !== -1 && o && (n.pageIds.splice(C, 1), delete n.pages[m]);
1766
1769
  for (const L of n.pageIds)
1767
- L.includes(`${f}-`) && (n.pageIds.splice(n.pageIds.indexOf(L), 1), delete n.pages[L]);
1768
- S.info("delete main route page", f);
1770
+ L.includes(`${m}-`) && (n.pageIds.splice(n.pageIds.indexOf(L), 1), delete n.pages[L]);
1771
+ S.info("delete main route page", m);
1769
1772
  continue;
1770
1773
  }
1771
- if (l.includes("-") && !(d != null && d[l])) {
1772
- const C = n.pageIds.indexOf(l);
1773
- C !== -1 && o && (n.pageIds.splice(C, 1), delete n.pages[l]), S.info("delete page", l);
1774
+ if (c.includes("-") && !(l != null && l[c])) {
1775
+ const C = n.pageIds.indexOf(c);
1776
+ C !== -1 && o && (n.pageIds.splice(C, 1), delete n.pages[c]), S.info("delete page", c);
1774
1777
  continue;
1775
1778
  }
1776
1779
  if (!w.displayTemplateId) {
1777
- S.info("no display template", l);
1780
+ S.info("no display template", c);
1778
1781
  continue;
1779
1782
  }
1780
- const D = a[w.displayTemplateId];
1783
+ const D = i[w.displayTemplateId];
1781
1784
  if (!D) {
1782
- S.info("no template page", l);
1785
+ S.info("no template page", c);
1783
1786
  continue;
1784
1787
  }
1785
- if (n.pageIds.includes(l)) {
1786
- if (S.info("has need update page", l), s === "replace")
1787
- n.pages[l] = je({
1788
+ if (n.pageIds.includes(c)) {
1789
+ if (S.info("has need update page", c), s === "replace")
1790
+ n.pages[c] = je({
1788
1791
  page: D,
1789
1792
  route: w,
1790
1793
  state: e,
1791
- routeId: l,
1792
- routePathInfo: d == null ? void 0 : d[l]
1793
- }), S.info("replace page", l);
1794
+ routeId: c,
1795
+ routePathInfo: l == null ? void 0 : l[c]
1796
+ }), S.info("replace page", c);
1794
1797
  else if (s === "byUpdateTime") {
1795
1798
  const C = n.pages[w.id];
1796
- (!C || w.updatedAt && w.updatedAt > C.updatedAt) && (n.pages[l] = je({
1799
+ (!C || w.updatedAt && w.updatedAt > C.updatedAt) && (n.pages[c] = je({
1797
1800
  page: D,
1798
1801
  route: w,
1799
1802
  state: e,
1800
- routeId: l,
1801
- routePathInfo: d == null ? void 0 : d[l]
1802
- }), S.info("replace page by update time", l));
1803
+ routeId: c,
1804
+ routePathInfo: l == null ? void 0 : l[c]
1805
+ }), S.info("replace page by update time", c));
1803
1806
  }
1804
1807
  } else
1805
- n.pageIds.push(l), n.pages[l] = je({
1808
+ n.pageIds.push(c), n.pages[c] = je({
1806
1809
  page: D,
1807
1810
  route: w,
1808
1811
  state: e,
1809
- routeId: l,
1810
- routePathInfo: d == null ? void 0 : d[l]
1811
- }), S.info("add page", l);
1812
+ routeId: c,
1813
+ routePathInfo: l == null ? void 0 : l[c]
1814
+ }), S.info("add page", c);
1812
1815
  }
1813
1816
  if (o && !t)
1814
- for (const l of n.pageIds)
1815
- m != null && m.includes(l) || (delete n.pages[l], S.info("delete page", l)), n.pageIds = [...n.pageIds].filter((f) => m == null ? void 0 : m.includes(f));
1817
+ for (const c of n.pageIds)
1818
+ f != null && f.includes(c) || (delete n.pages[c], S.info("delete page", c)), n.pageIds = [...n.pageIds].filter((m) => f == null ? void 0 : f.includes(m));
1816
1819
  } else {
1817
- for (const m of i) {
1818
- const d = a[m];
1819
- if (d)
1820
- if (n.pageIds.includes(d.id)) {
1820
+ for (const f of d) {
1821
+ const l = i[f];
1822
+ if (l)
1823
+ if (n.pageIds.includes(l.id)) {
1821
1824
  if (s === "replace")
1822
- n.pages[d.id] = d;
1825
+ n.pages[l.id] = l;
1823
1826
  else if (s === "byUpdateTime") {
1824
- const l = n.pages[d.id];
1825
- (!l || d.updatedAt && d.updatedAt > l.updatedAt) && (n.pages[d.id] = d);
1827
+ const c = n.pages[l.id];
1828
+ (!c || l.updatedAt && l.updatedAt > c.updatedAt) && (n.pages[l.id] = l);
1826
1829
  }
1827
1830
  } else
1828
- n.pageIds.push(d.id), n.pages[d.id] = d;
1831
+ n.pageIds.push(l.id), n.pages[l.id] = l;
1829
1832
  }
1830
- for (const m of p) {
1831
- const d = c[m];
1832
- if (d)
1833
- if (n.routeIds.includes(d.id)) {
1833
+ for (const f of p) {
1834
+ const l = a[f];
1835
+ if (l)
1836
+ if (n.routeIds.includes(l.id)) {
1834
1837
  if (s === "replace")
1835
- n.routes[d.id] = d;
1838
+ n.routes[l.id] = l;
1836
1839
  else if (s === "byUpdateTime") {
1837
- const l = n.routes[d.id];
1838
- (!l || d.updatedAt && d.updatedAt > l.updatedAt) && (n.routes[d.id] = d);
1840
+ const c = n.routes[l.id];
1841
+ (!c || l.updatedAt && l.updatedAt > c.updatedAt) && (n.routes[l.id] = l);
1839
1842
  }
1840
1843
  } else
1841
- n.routeIds.push(d.id), n.routes[d.id] = d;
1844
+ n.routeIds.push(l.id), n.routes[l.id] = l;
1842
1845
  }
1843
1846
  }
1844
1847
  if (n.supportedLocales.splice(0, n.supportedLocales.length), n.supportedLocales.push(...os(u)), o)
1845
- for (const m of Object.keys(n.components))
1846
- delete n.components[m];
1848
+ for (const f of Object.keys(n.components))
1849
+ delete n.components[f];
1847
1850
  let y = JSON.parse(JSON.stringify(e.components));
1848
1851
  y = Object.fromEntries(
1849
1852
  await Promise.all(
1850
- Object.entries(y).map(async ([m, d]) => {
1851
- const l = await Et(d == null ? void 0 : d.data);
1853
+ Object.entries(y).map(async ([f, l]) => {
1854
+ const c = await Et(l == null ? void 0 : l.data);
1852
1855
  return [
1853
- m,
1856
+ f,
1854
1857
  {
1855
- ...d,
1856
- data: l
1858
+ ...l,
1859
+ data: c
1857
1860
  }
1858
1861
  ];
1859
1862
  })
@@ -1884,17 +1887,17 @@ const Et = Be(
1884
1887
  },
1885
1888
  {
1886
1889
  keyGenerator: (e) => {
1887
- var c, u, y, m;
1888
- const n = (e == null ? void 0 : e.id) || "", t = (e == null ? void 0 : e.name) || "", s = ((c = e == null ? void 0 : e.renderer) == null ? void 0 : c.type) || "", o = (e == null ? void 0 : e.properties) || {}, r = (e == null ? void 0 : e.updatedAt) || "", a = te("md5").update(JSON.stringify(o)).digest("hex");
1889
- let i = "", p = "";
1890
- return ((u = e == null ? void 0 : e.renderer) == null ? void 0 : u.type) === "react-component" && (i = te("md5").update(((y = e == null ? void 0 : e.renderer) == null ? void 0 : y.script) || "").digest("hex"), p = te("md5").update(((m = e == null ? void 0 : e.renderer) == null ? void 0 : m.editComponent) || "").digest("hex")), JSON.stringify([
1890
+ var a, u, y, f;
1891
+ const n = (e == null ? void 0 : e.id) || "", t = (e == null ? void 0 : e.name) || "", s = ((a = e == null ? void 0 : e.renderer) == null ? void 0 : a.type) || "", o = (e == null ? void 0 : e.properties) || {}, r = (e == null ? void 0 : e.updatedAt) || "", i = te("md5").update(JSON.stringify(o)).digest("hex");
1892
+ let d = "", p = "";
1893
+ return ((u = e == null ? void 0 : e.renderer) == null ? void 0 : u.type) === "react-component" && (d = te("md5").update(((y = e == null ? void 0 : e.renderer) == null ? void 0 : y.script) || "").digest("hex"), p = te("md5").update(((f = e == null ? void 0 : e.renderer) == null ? void 0 : f.editComponent) || "").digest("hex")), JSON.stringify([
1891
1894
  "checkPropertiesFromCode",
1892
1895
  n,
1893
1896
  t,
1894
1897
  s,
1895
- a,
1896
- r,
1897
1898
  i,
1899
+ r,
1900
+ d,
1898
1901
  p
1899
1902
  ]);
1900
1903
  },
@@ -1905,7 +1908,7 @@ const Et = Be(
1905
1908
  subdir: "checkPropertiesFromCode"
1906
1909
  }
1907
1910
  );
1908
- let Oe, ie, Te, Pe, He;
1911
+ let Oe, ie, Pe, Te, He;
1909
1912
  function It() {
1910
1913
  return Oe = (async () => {
1911
1914
  const e = zt({
@@ -1919,7 +1922,7 @@ function It() {
1919
1922
  const s = t.path ? await wt(t.path, { importAssets: !1 }) : void 0;
1920
1923
  return s ? { blockletId: t.did, state: s, blockletTitle: t.title } : void 0;
1921
1924
  })
1922
- )).filter((t) => !!t), Te = ie.reduce(
1925
+ )).filter((t) => !!t), Pe = ie.reduce(
1923
1926
  (t, s) => Object.assign(
1924
1927
  t,
1925
1928
  Object.fromEntries(
@@ -1937,7 +1940,7 @@ function It() {
1937
1940
  ),
1938
1941
  {}
1939
1942
  );
1940
- Pe = Object.fromEntries(
1943
+ Te = Object.fromEntries(
1941
1944
  await Promise.all(
1942
1945
  Object.entries(n).map(async ([t, s]) => {
1943
1946
  const o = await Et(s.component);
@@ -1960,8 +1963,8 @@ function rn(e) {
1960
1963
  S.error("load resource states error", { error: t });
1961
1964
  }), await (e == null ? void 0 : e({
1962
1965
  states: ie,
1963
- pages: Te,
1964
- components: Pe,
1966
+ pages: Pe,
1967
+ components: Te,
1965
1968
  chunks: He
1966
1969
  }));
1967
1970
  },
@@ -2022,10 +2025,10 @@ async function At({
2022
2025
  if (o != null && o.useAllResources)
2023
2026
  s.syncedStore.resources.components = t;
2024
2027
  else {
2025
- const a = (await Ce.findAll({ where: { projectId: e } })).map((p) => p.componentId), i = Object.fromEntries(
2026
- Object.entries(t || {}).filter(([p]) => a.includes(p))
2028
+ const i = (await Ce.findAll({ where: { projectId: e } })).map((p) => p.componentId), d = Object.fromEntries(
2029
+ Object.entries(t || {}).filter(([p]) => i.includes(p))
2027
2030
  );
2028
- s.syncedStore.resources.components = i;
2031
+ s.syncedStore.resources.components = d;
2029
2032
  }
2030
2033
  S.info(`update [${e}] resource states:`, {
2031
2034
  pages: Object.keys(s.syncedStore.resources.pages || {}).length,
@@ -2038,7 +2041,7 @@ async function no() {
2038
2041
  async function Ve({
2039
2042
  ensureLoaded: e = !0
2040
2043
  } = {}) {
2041
- return e && (Oe ?? (Oe = It()), await Oe), { states: ie, pages: Te, components: Pe, chunks: He };
2044
+ return e && (Oe ?? (Oe = It()), await Oe), { states: ie, pages: Pe, components: Te, chunks: He };
2042
2045
  }
2043
2046
  export {
2044
2047
  gt as C,
@@ -2050,8 +2053,8 @@ export {
2050
2053
  Ve as b,
2051
2054
  Ls as c,
2052
2055
  _s as d,
2053
- Ms as e,
2054
- $s as f,
2056
+ $s as e,
2057
+ Ms as f,
2055
2058
  Zn as g,
2056
2059
  Us as h,
2057
2060
  Qn as i,