@blocklet/pages-kit-inner-components 0.6.20 → 0.6.22

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,43 +1,44 @@
1
- import { d as Le, l as f, I as Ye, c as We, m as Qe, b as Xe } from "./components-BWQM8y6L.js";
2
- import { getYjsValue as V, syncedStore as Ze } from "@syncedstore/core";
1
+ import { d as $e, l as f, I as We, c as Qe, m as Xe, b as Ze } from "./components-BWQM8y6L.js";
2
+ import { getYjsValue as V, syncedStore as et } from "@syncedstore/core";
3
3
  import * as N from "yjs";
4
- import { setPageDataSource as et } from "@blocklet/pages-kit/utils/data-source";
5
- import { getRouteMetaDataByOptionIds as tt, generateParamCombinations as Se } from "@blocklet/pages-kit/utils/route";
6
- import { cloneDeep as st } from "lodash";
7
- import I from "@blocklet/sdk/lib/config";
8
- import { mkdtempSync as at, existsSync as U, readFileSync as H, renameSync as Ce, mkdirSync as _, rmSync as $e, writeFileSync as ee, copyFileSync as ot, lstatSync as B, readdirSync as rt, createWriteStream as nt } from "fs";
9
- import { join as E, basename as j, dirname as L } from "path";
4
+ import { setPageDataSource as tt } from "@blocklet/pages-kit/utils/data-source";
5
+ import { getRouteMetaDataByOptionIds as st, generateParamCombinations as Se } from "@blocklet/pages-kit/utils/route";
6
+ import { cloneDeep as at } from "lodash";
7
+ import b from "@blocklet/sdk/lib/config";
8
+ import { mkdtempSync as ot, existsSync as U, readFileSync as q, renameSync as Ce, mkdirSync as _, rmSync as Ue, writeFileSync as ee, copyFileSync as rt, lstatSync as B, readdirSync as nt, createWriteStream as it } from "fs";
9
+ import { join as E, basename as R, dirname as L } from "path";
10
10
  import { nextId as Oe } from "@blocklet/pages-kit/utils/common";
11
- import { unzipSection as it } from "@blocklet/pages-kit/utils/page-model";
12
- import { getComponentDependencies as ct } from "@blocklet/pages-kit/utils/property";
13
- import { getComponentWebEndpoint as pt, getResources as lt, call as dt } from "@blocklet/sdk/lib/component";
14
- import { reactive as ut } from "@reactivedata/reactive";
11
+ import { unzipSection as ct } from "@blocklet/pages-kit/utils/page-model";
12
+ import { getComponentDependencies as pt } from "@blocklet/pages-kit/utils/property";
13
+ import { getComponentWebEndpoint as lt, getResources as ut, call as dt } from "@blocklet/sdk/lib/component";
14
+ import { reactive as ft } from "@reactivedata/reactive";
15
15
  import { globSync as te } from "glob";
16
- import * as de from "lib0/decoding";
16
+ import * as ue from "lib0/decoding";
17
17
  import * as D from "lib0/encoding";
18
- import ft from "lodash/cloneDeep";
19
- import Ue from "lodash/debounce";
18
+ import mt from "lodash/cloneDeep";
19
+ import Me from "lodash/debounce";
20
20
  import Ie from "lodash/get";
21
- import Ee from "lodash/isEmpty";
21
+ import be from "lodash/isEmpty";
22
22
  import ve from "lodash/set";
23
- import mt from "lodash/union";
24
- import { LRUCache as be } from "lru-cache";
23
+ import gt from "lodash/union";
24
+ import { LRUCache as Ee } from "lru-cache";
25
25
  import ht from "p-limit";
26
- import { DataTypes as k, Sequelize as gt, Model as Me, Op as Ne } from "sequelize";
27
- import { pipeline as yt } from "stream/promises";
28
- import { x as St } from "tar";
29
- import { joinURL as Y } from "ufo";
30
- import It from "wait-on";
31
- import { Awareness as Et, encodeAwarenessUpdate as ke, removeAwarenessStates as bt, applyAwarenessUpdate as wt } from "y-protocols/awareness";
32
- import { writeUpdate as At, writeSyncStep1 as Pt, readSyncMessage as Ct } from "y-protocols/sync";
26
+ import { DataTypes as k, Sequelize as yt, Model as Ne, Op as Fe } from "sequelize";
27
+ import { pipeline as St } from "stream/promises";
28
+ import { x as It } from "tar";
29
+ import { joinURL as H } from "ufo";
30
+ import bt from "wait-on";
31
+ import { Awareness as Et, encodeAwarenessUpdate as je, removeAwarenessStates as wt, applyAwarenessUpdate as At } from "y-protocols/awareness";
32
+ import { writeUpdate as Pt, writeSyncStep1 as Ct, readSyncMessage as Ot } from "y-protocols/sync";
33
33
  import * as G from "yaml";
34
+ import { m as ke } from "./html-DfzaaIYa.js";
34
35
  import "sqlite3";
35
36
  import "@blocklet/pages-kit/types/state";
36
- const Ot = k.sqlite.DATE.parse;
37
- k.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Ot(t, e);
38
- const F = new gt({
37
+ const vt = k.sqlite.DATE.parse;
38
+ k.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : vt(t, e);
39
+ const F = new yt({
39
40
  dialect: "sqlite",
40
- storage: Le,
41
+ storage: $e,
41
42
  benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
42
43
  retry: {
43
44
  match: [/SQLITE_BUSY/],
@@ -59,7 +60,7 @@ process.on("SIGINT", async () => {
59
60
  process.on("SIGTERM", async () => {
60
61
  await F.close(), process.exit(0);
61
62
  });
62
- async function vt(t, e) {
63
+ async function jt(t, e) {
63
64
  try {
64
65
  if (t.getDialect() !== "sqlite")
65
66
  return;
@@ -77,12 +78,12 @@ let me = null;
77
78
  me && clearInterval(me);
78
79
  me = setInterval(
79
80
  async () => {
80
- f.info("Start cleanupSqliteMemory"), await vt(F, Le), f.info("End cleanupSqliteMemory");
81
+ f.info("Start cleanupSqliteMemory"), await jt(F, $e), f.info("End cleanupSqliteMemory");
81
82
  },
82
83
  60 * 1e3 * 10
83
84
  // 10 minutes
84
85
  );
85
- class we extends Me {
86
+ class we extends Ne {
86
87
  // Foreign key to Component
87
88
  }
88
89
  we.init(
@@ -104,11 +105,11 @@ we.init(
104
105
  },
105
106
  { sequelize: F, tableName: "ProjectComponents", timestamps: !1 }
106
107
  );
107
- class M extends Me {
108
+ class M extends Ne {
108
109
  static async getProjectByIdOrSlug(e) {
109
110
  return M.findOne({
110
111
  where: {
111
- [Ne.or]: [{ id: e }, { slug: e }]
112
+ [Fe.or]: [{ id: e }, { slug: e }]
112
113
  }
113
114
  });
114
115
  }
@@ -191,22 +192,22 @@ M.hasMany(we, {
191
192
  foreignKey: "projectId",
192
193
  as: "components"
193
194
  });
194
- const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Te = "page", he = "trigger-reload-project-resource", Fe = kt, Tt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM";
195
+ const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", De = "page", ge = "trigger-reload-project-resource", _e = kt, Dt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM";
195
196
  function se(t) {
196
197
  t.observeDeep((e) => {
197
198
  e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
198
199
  });
199
200
  }
200
- function _e() {
201
- return at(E(I.env.dataDir, "tmp-"));
201
+ function xe() {
202
+ return ot(E(b.env.dataDir, "tmp-"));
202
203
  }
203
204
  function ae(t, e, s = []) {
204
205
  return Array.isArray(t) ? t.flatMap((a, o) => ae(a, e, [...s, o])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([a, o]) => ae(o, e, [...s, a])) : e(t) ? [s] : [];
205
206
  }
206
- function R(t) {
207
+ function T(t) {
207
208
  return t.filter((e) => e != null);
208
209
  }
209
- function Dt(t) {
210
+ function Tt(t) {
210
211
  t.pages && Object.keys(t.pages).forEach((s) => {
211
212
  const a = V(t.pages[s]);
212
213
  a && a instanceof N.Map && se(a);
@@ -236,12 +237,12 @@ function Rt(t) {
236
237
  });
237
238
  });
238
239
  }
239
- function jt(t, e) {
240
+ function Lt(t, e) {
240
241
  for (const s of e || Object.keys(t.routes || {})) {
241
242
  let a = s, o = [];
242
243
  if (s.includes("-")) {
243
- const [r, ...i] = s.split("-");
244
- a = r, o = i || [];
244
+ const [r, ...c] = s.split("-");
245
+ a = r, o = c || [];
245
246
  }
246
247
  if (t.routes?.[a] !== void 0) {
247
248
  t.routes[a].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -249,11 +250,11 @@ function jt(t, e) {
249
250
  if (!r || !r.params || r.params.length === 0)
250
251
  continue;
251
252
  if (s.includes("-") && o.length > 0) {
252
- const i = tt(o, r);
253
- i && (i.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
253
+ const c = st(o, r);
254
+ c && (c.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
254
255
  }
255
256
  if (!e) {
256
- const i = Se({
257
+ const c = Se({
257
258
  basePath: r.path,
258
259
  params: r.params,
259
260
  routeId: r.id,
@@ -263,13 +264,13 @@ function jt(t, e) {
263
264
  currentOptionIds: [],
264
265
  result: []
265
266
  });
266
- for (const c of i)
267
- c.routeMetaData ??= {}, c.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
267
+ for (const l of c)
268
+ l.routeMetaData ??= {}, l.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
268
269
  }
269
270
  }
270
271
  }
271
272
  }
272
- function ue({
273
+ function de({
273
274
  page: t,
274
275
  route: e,
275
276
  state: s,
@@ -280,7 +281,7 @@ function ue({
280
281
  `Executing datasource data assembly, routeId: ${a}, routePathInfo: ${JSON.stringify(o)}`
281
282
  );
282
283
  const r = {
283
- ...st(t),
284
+ ...at(t),
284
285
  id: a,
285
286
  slug: o?.path ?? e.path,
286
287
  createdAt: e.createdAt,
@@ -288,74 +289,51 @@ function ue({
288
289
  publishedAt: o?.routeMetaData?.publishedAt ?? e.publishedAt,
289
290
  isPublic: (o?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
290
291
  };
291
- for (const i of s.supportedLocales) {
292
+ for (const c of s.supportedLocales) {
292
293
  if (e.dataSource) {
293
- let c = e.id;
294
- o && (c = o.paramOptionIds.join("-"));
295
- const l = e.dataSource.pathDataMappings?.[c]?.dataCache?.[i.locale] ?? e.dataSource.pathDataMappings?.[c]?.dataCache?.[s.config.defaultLocale || "en"];
296
- if (!l)
294
+ let l = e.id;
295
+ o && (l = o.paramOptionIds.join("-"));
296
+ const p = e.dataSource.pathDataMappings?.[l]?.dataCache?.[c.locale] ?? e.dataSource.pathDataMappings?.[l]?.dataCache?.[s.config.defaultLocale || "en"];
297
+ if (!p)
297
298
  continue;
298
- et(r, s, i.locale, l);
299
+ tt(r, s, c.locale, p);
299
300
  }
300
301
  o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
301
302
  }
302
303
  return r;
303
304
  }
304
- const Lt = 30 * 60 * 1e3, z = new be({
305
+ const $t = 30 * 60 * 1e3, Y = new Ee({
305
306
  max: 100,
306
- ttl: Lt
307
+ ttl: $t
307
308
  });
308
- function $t(t, e = []) {
309
+ function Ut(t, e = []) {
309
310
  let s = 0;
310
- const a = Array.from(z.keys()), o = [];
311
- for (const r of t) {
312
- o.push(`page-html:prod:${r}:lang-path=none`);
313
- for (const i of e)
314
- o.push(`page-html:prod:/${i}${r}:lang-path=${i}`);
315
- }
316
- for (const r of a) {
317
- const i = r.split(":lang-path=")[0] || "";
318
- for (const c of o) {
319
- const m = (c.split(":lang-path=")[0] || "").replace(/\/:[^/]+/g, "");
320
- if (i.startsWith(m)) {
321
- z.delete(r), s++, f.info(`[Cache CLEAR] key: ${r}`);
311
+ const a = Array.from(Y.keys());
312
+ for (const o of a)
313
+ for (const r of t) {
314
+ if (ke(o, { currentPath: r })) {
315
+ Y.delete(o), s++, f.info(`[Cache CLEAR] key: ${o}`);
322
316
  break;
323
317
  }
318
+ for (const c of e)
319
+ if (ke(o, { currentPath: `/${c}${r}` })) {
320
+ Y.delete(o), s++, f.info(`[Cache CLEAR] key: ${o}`);
321
+ break;
322
+ }
324
323
  }
325
- }
326
- return f.info(`[Cache CLEAR] cleared ${s} entries for patterns:`, o), s;
327
- }
328
- function Ut({
329
- projectId: t,
330
- projectSlug: e,
331
- supportedLocales: s = []
332
- }) {
333
- let a = 0;
334
- const o = Array.from(z.keys()), r = [];
335
- r.push(`page-html:prod:/${t}`), e && e !== t && r.push(`page-html:prod:/${e}`);
336
- for (const i of s)
337
- r.push(`page-html:prod:/${i}/${t}`), e && e !== t && (e !== "/" ? r.push(`page-html:prod:/${i}/${e}`) : r.push(`page-html:prod:/${i}`));
338
- for (const i of o)
339
- for (const c of r)
340
- if (i.startsWith(c)) {
341
- z.delete(i), a++, f.info(`[Cache CLEAR PROJECT] key: ${i}`);
342
- break;
343
- }
344
- return f.info(
345
- `[Cache CLEAR PROJECT] cleared ${a} entries for project ${t}${e ? ` (slug: ${e})` : ""}`
346
- ), a;
324
+ return f.info(`[Cache CLEAR] cleared ${s} entries for paths:`, t), s;
347
325
  }
348
326
  function Mt() {
349
- const t = z.size;
350
- return z.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
327
+ const t = Y.size;
328
+ return Y.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
351
329
  }
352
- I.events.on(I.Events.envUpdate, Mt);
353
- const { uploadToMediaKit: Nt } = require("@blocklet/uploader-server"), Ae = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, W = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, De = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Ft = 1e4, _t = 3e4, X = 0, fe = 1, xt = 0, Bt = 1, ge = I, q = E(process.env.BLOCKLET_DATA_DIR, "site-state"), Os = ["production", "draft"], vs = ["production"];
330
+ b.events.on(b.Events.envUpdate, Mt);
331
+ const { uploadToMediaKit: Nt } = require("@blocklet/uploader-server"), Ae = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, W = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, Te = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Ft = 1e4, _t = 3e4, X = 0, fe = 1, xt = 0, Bt = 1, he = b, K = E(process.env.BLOCKLET_DATA_DIR, "site-state"), vs = ["production", "draft"], js = ["production"];
354
332
  function oe(t) {
355
333
  return t?.replace(/\//g, "|") || "";
356
334
  }
357
335
  function Gt() {
358
- const t = ge.env.languages?.map((s) => ({ locale: s.code, name: s.name })) || [], e = t[0]?.locale || "en";
336
+ const t = he.env.languages?.map((s) => ({ locale: s.code, name: s.name })) || [], e = t[0]?.locale || "en";
359
337
  return {
360
338
  pageIds: [],
361
339
  pages: {},
@@ -369,10 +347,10 @@ function Gt() {
369
347
  resources: {}
370
348
  };
371
349
  }
372
- class C extends N.Doc {
350
+ class O extends N.Doc {
373
351
  constructor(e) {
374
- super(), this.options = e, U(this.draftYjsFilePath) && N.applyUpdate(this, H(this.draftYjsFilePath)), this.syncedStore = ut(
375
- Ze(
352
+ super(), this.options = e, U(this.draftYjsFilePath) && N.applyUpdate(this, q(this.draftYjsFilePath)), this.syncedStore = ft(
353
+ et(
376
354
  {
377
355
  pages: {},
378
356
  pageIds: [],
@@ -395,7 +373,7 @@ class C extends N.Doc {
395
373
  static PERIODIC_CHECK_INTERVAL = 2 * 60 * 60 * 1e3;
396
374
  // 2 hours
397
375
  static sharedInstances = {};
398
- static pageUrlMapCache = new be({
376
+ static pageUrlMapCache = new Ee({
399
377
  max: 100,
400
378
  ttl: 1e3 * 60 * 60 * 24
401
379
  // 1 day
@@ -407,7 +385,7 @@ class C extends N.Doc {
407
385
  if (!e)
408
386
  throw new Error("Should provide project context");
409
387
  try {
410
- const s = E(q, e), a = E(q, `@del-${e}`);
388
+ const s = E(K, e), a = E(K, `@del-${e}`);
411
389
  Ce(s, a);
412
390
  } catch (s) {
413
391
  f.error("Failed to safe delete project state dir:", s);
@@ -419,33 +397,33 @@ class C extends N.Doc {
419
397
  /** @deprecated 不再使用这个 getter 了,仅作为兼容性处理,请使用 getProjectIds 代替 */
420
398
  static get projectIds() {
421
399
  return te("*/", {
422
- cwd: q,
400
+ cwd: K,
423
401
  ignore: ["@del-*", "@tmp-*", ".*", "staging", "production", "@backup-*", "undefined"]
424
402
  // Ignore temp directories and hidden files
425
403
  });
426
404
  }
427
405
  /** @deprecated 不再使用这个 getter 了,仅作为兼容性处理 */
428
406
  static get allShared() {
429
- return this.projectIds.map((e) => C.shared(e));
407
+ return this.projectIds.map((e) => O.shared(e));
430
408
  }
431
409
  static shared(e) {
432
410
  if (!e)
433
411
  throw new Error("Should provide project context");
434
- let s = C.sharedInstances[e];
435
- return s || (s = new C({
436
- path: E(q, e)
437
- }), C.sharedInstances[e] = s, s);
412
+ let s = O.sharedInstances[e];
413
+ return s || (s = new O({
414
+ path: E(K, e)
415
+ }), O.sharedInstances[e] = s, s);
438
416
  }
439
417
  // 轻量级 production 状态获取,不加载 draft 数据
440
418
  static async getProductionState(e) {
441
419
  const s = await M.findByPk(e, {
442
420
  attributes: ["productionState"]
443
421
  });
444
- if (Ee(s?.productionState)) {
445
- const a = E(q, e, "production"), o = await Be(a, { includeResources: !0 }) ?? Gt();
422
+ if (be(s?.productionState)) {
423
+ const a = E(K, e, "production"), o = await Ge(a, { includeResources: !0 }) ?? Gt();
446
424
  if (!o?.config?.defaultLocale) {
447
425
  o.config ??= {};
448
- const r = ge.env.languages?.map((i) => ({ locale: i.code, name: i.name })) || [];
426
+ const r = he.env.languages?.map((c) => ({ locale: c.code, name: c.name })) || [];
449
427
  o.config.defaultLocale = r[0]?.locale;
450
428
  }
451
429
  return o;
@@ -454,33 +432,33 @@ class C extends N.Doc {
454
432
  }
455
433
  destroy() {
456
434
  this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, a) => this.closeConn(a)), this.awareness.destroy();
457
- const e = j(this.options.path);
458
- delete C.sharedInstances[e], super.destroy();
435
+ const e = R(this.options.path);
436
+ delete O.sharedInstances[e], super.destroy();
459
437
  }
460
438
  initObserver() {
461
- Dt(this.syncedStore), Rt(this.syncedStore);
439
+ Tt(this.syncedStore), Rt(this.syncedStore);
462
440
  }
463
441
  get draftYjsFilePath() {
464
442
  return E(this.options.path, "draft.yjs");
465
443
  }
466
444
  static async getStateByProjectId(e, s) {
467
445
  if (s === "draft") {
468
- const a = C.shared(e);
446
+ const a = O.shared(e);
469
447
  return JSON.parse(JSON.stringify(a.syncedStore));
470
448
  }
471
- return C.getProductionState(e);
449
+ return O.getProductionState(e);
472
450
  }
473
451
  async getState(e) {
474
452
  if (e === "draft")
475
453
  return JSON.parse(JSON.stringify(this.syncedStore));
476
- const s = j(this.options.path);
477
- return C.getProductionState(s);
454
+ const s = R(this.options.path);
455
+ return O.getProductionState(s);
478
456
  }
479
457
  async setState(e, s) {
480
458
  const a = await Kt(s, { exportAssets: !1, includeResources: !0 }), o = this.getPublishDir(e);
481
- if (_(L(o), { recursive: !0 }), $e(o, { force: !0, recursive: !0 }), Ce(a, o), e === "production") {
482
- const r = j(this.options.path);
483
- C.pageUrlMapCache.delete(r), await M.update({ productionState: { ...s } }, { where: { id: r } });
459
+ if (_(L(o), { recursive: !0 }), Ue(o, { force: !0, recursive: !0 }), Ce(a, o), e === "production") {
460
+ const r = R(this.options.path);
461
+ O.pageUrlMapCache.delete(r), await M.update({ productionState: { ...s } }, { where: { id: r } });
484
462
  }
485
463
  }
486
464
  getPublishDir(e) {
@@ -494,49 +472,49 @@ class C extends N.Doc {
494
472
  awarenessChangeHandler = ({ added: e, updated: s, removed: a }, o) => {
495
473
  const r = e.concat(s, a);
496
474
  if (o !== null) {
497
- const l = this.conns.get(o);
498
- l && (e.forEach((m) => {
499
- l.add(m);
500
- }), a.forEach((m) => {
501
- l.delete(m);
475
+ const p = this.conns.get(o);
476
+ p && (e.forEach((y) => {
477
+ p.add(y);
478
+ }), a.forEach((y) => {
479
+ p.delete(y);
502
480
  }));
503
481
  }
504
- const i = D.createEncoder();
505
- D.writeVarUint(i, fe), D.writeVarUint8Array(i, ke(this.awareness, r));
506
- const c = D.toUint8Array(i);
507
- this.conns.forEach((l, m) => this.send(m, c));
482
+ const c = D.createEncoder();
483
+ D.writeVarUint(c, fe), D.writeVarUint8Array(c, je(this.awareness, r));
484
+ const l = D.toUint8Array(c);
485
+ this.conns.forEach((p, y) => this.send(y, l));
508
486
  };
509
487
  updateHandler = (e) => {
510
488
  const s = D.createEncoder();
511
- D.writeVarUint(s, X), At(s, e);
489
+ D.writeVarUint(s, X), Pt(s, e);
512
490
  const a = D.toUint8Array(s);
513
491
  this.conns.forEach((o, r) => this.send(r, a));
514
492
  };
515
493
  ensureDataStructure = () => {
516
- const { supportedLocales: e, pages: s, pageIds: a, config: o, routes: r, routeIds: i } = this.syncedStore;
494
+ const { supportedLocales: e, pages: s, pageIds: a, config: o, routes: r, routeIds: c } = this.syncedStore;
517
495
  {
518
- const c = new Set(Object.keys(s));
519
- let l = 0;
520
- for (; l < a.length; ) {
521
- const m = a[l];
522
- c.has(m) ? (c.delete(m), l++) : a.splice(l, 1);
496
+ const l = new Set(Object.keys(s));
497
+ let p = 0;
498
+ for (; p < a.length; ) {
499
+ const y = a[p];
500
+ l.has(y) ? (l.delete(y), p++) : a.splice(p, 1);
523
501
  }
524
502
  }
525
503
  {
526
- const c = new Set(Object.keys(r));
527
- let l = 0;
528
- for (; l < i.length; ) {
529
- const m = i[l];
530
- c.has(m) ? (c.delete(m), l++) : i.splice(l, 1);
504
+ const l = new Set(Object.keys(r));
505
+ let p = 0;
506
+ for (; p < c.length; ) {
507
+ const y = c[p];
508
+ l.has(y) ? (l.delete(y), p++) : c.splice(p, 1);
531
509
  }
532
510
  }
533
- e.splice(0, e.length), e.push(...ge.env.languages.map((c) => ({ locale: c.code, name: c.name }))), o.defaultLocale = e[0]?.locale;
511
+ e.splice(0, e.length), e.push(...he.env.languages.map((l) => ({ locale: l.code, name: l.name }))), o.defaultLocale = e[0]?.locale;
534
512
  {
535
- let c = 0;
536
- const l = /* @__PURE__ */ new Set();
537
- for (; c < e.length; ) {
538
- const { locale: m } = e[c];
539
- l.has(m) ? e.splice(c, 1) : (c++, l.add(m));
513
+ let l = 0;
514
+ const p = /* @__PURE__ */ new Set();
515
+ for (; l < e.length; ) {
516
+ const { locale: y } = e[l];
517
+ p.has(y) ? e.splice(l, 1) : (l++, p.add(y));
540
518
  }
541
519
  }
542
520
  };
@@ -553,7 +531,7 @@ class C extends N.Doc {
553
531
  closeConn = (e) => {
554
532
  if (e.removeAllListeners(), this.conns.has(e)) {
555
533
  const s = this.conns.get(e);
556
- this.conns.delete(e), s && bt(this.awareness, Array.from(s), null);
534
+ this.conns.delete(e), s && wt(this.awareness, Array.from(s), null);
557
535
  }
558
536
  e.close(), this.checkAndScheduleRelease();
559
537
  };
@@ -564,20 +542,20 @@ class C extends N.Doc {
564
542
  // 调度延迟释放
565
543
  scheduleRelease() {
566
544
  this.cancelRelease();
567
- const e = j(this.options.path);
545
+ const e = R(this.options.path);
568
546
  this.releaseTimer = setTimeout(() => {
569
547
  f.info(`[SiteState] releasing instance due to no active connections: ${e}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
570
- }, C.RELEASE_DELAY), f.info(`[SiteState] scheduled release for project ${e} in ${C.RELEASE_DELAY / 1e3}s`);
548
+ }, O.RELEASE_DELAY), f.info(`[SiteState] scheduled release for project ${e} in ${O.RELEASE_DELAY / 1e3}s`);
571
549
  }
572
550
  // 取消延迟释放
573
551
  cancelRelease() {
574
552
  if (this.releaseTimer) {
575
553
  clearTimeout(this.releaseTimer), this.releaseTimer = void 0;
576
- const e = j(this.options.path);
554
+ const e = R(this.options.path);
577
555
  f.info(`[SiteState] cancelled scheduled release for project ${e}`);
578
556
  }
579
557
  }
580
- autoSave = Ue(() => {
558
+ autoSave = Me(() => {
581
559
  _(L(this.draftYjsFilePath), { recursive: !0 }), ee(this.draftYjsFilePath, N.encodeStateAsUpdate(this));
582
560
  }, Ft);
583
561
  save = ({ flush: e = !1 } = {}) => {
@@ -585,42 +563,38 @@ class C extends N.Doc {
585
563
  };
586
564
  publish = async ({ mode: e, routes: s }) => {
587
565
  const a = await this.getState("draft"), o = await this.getState("production");
588
- await je(a, o, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), o.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), jt(this.syncedStore, s), await this.setState(e, o), await this.clearPageCacheForRoutes(s, o);
566
+ await Le(a, o, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), o.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Lt(this.syncedStore, s), await this.setState(e, o), await this.clearPageCacheForRoutes(s, o);
589
567
  };
590
568
  mergeState = async (e, s) => {
591
569
  const a = JSON.parse(JSON.stringify(s));
592
570
  e.config.fontFamily ??= {};
593
571
  const o = a.config?.fontFamily, r = e.config?.fontFamily;
594
- e.config.fontFamily.title = o?.title || r?.title, e.config.fontFamily.description = o?.description || r?.description, await new Promise((i, c) => {
572
+ e.config.fontFamily.title = o?.title || r?.title, e.config.fontFamily.description = o?.description || r?.description, await new Promise((c, l) => {
595
573
  this.transact(async () => {
596
574
  try {
597
- const l = await je(e, s);
598
- i(l);
599
- } catch (l) {
600
- c(l);
575
+ const p = await Le(e, s);
576
+ c(p);
577
+ } catch (p) {
578
+ l(p);
601
579
  }
602
580
  });
603
581
  });
604
582
  };
605
583
  clearPageCacheForRoutes = async (e, s) => {
606
- const a = j(this.options.path), r = (await M.findByPk(a))?.slug || a;
607
- if (f.info(`[SiteState] clearing page cache for project ${a}, routes:`, e || []), !e || e.length === 0) {
608
- Ut({
609
- projectId: a,
610
- projectSlug: r,
611
- supportedLocales: s.supportedLocales.map((m) => m.locale)
612
- });
613
- return;
614
- }
615
- const i = s.supportedLocales.map((m) => m.locale), c = [], l = e.filter((m) => s.pages[m]);
616
- for (const m of l) {
617
- const O = s.pages[m].slug;
618
- r && r !== a && (r === "/" ? c.push(O) : c.push(`/${r}${O}`)), c.push(`/${a}${O}`);
619
- }
620
- if (f.info(`[SiteState] clearing page cache for project ${a}, pathPatterns:`, c), c.length > 0) {
621
- const m = $t(c, i);
622
- f.info(`[SiteState] cleared ${m} page cache entries for project ${a}, routes:`, e);
584
+ const a = R(this.options.path), r = (await M.findByPk(a))?.slug || a;
585
+ let c = e;
586
+ (!c || c.length === 0) && (c = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${a}, routes:`, c || []);
587
+ const l = s.supportedLocales.map((w) => w.locale), p = [], y = c.filter((w) => s.pageIds?.includes(w));
588
+ for (const w of y) {
589
+ const I = s.pages[w].slug;
590
+ r && r !== a && (r === "/" ? p.push(I) : p.push(`/${r}${I}`)), p.push(`/${a}${I}`);
623
591
  }
592
+ if (f.info(`[SiteState] clearing page cache for project ${a}, pathPatterns:`, p), p.length > 0)
593
+ try {
594
+ const w = Ut(p, l);
595
+ f.info(`[SiteState] cleared ${w} page cache entries for project ${a}, routes:`, c);
596
+ } catch {
597
+ }
624
598
  };
625
599
  addConnection = (e) => {
626
600
  if (this.conns.has(e))
@@ -646,23 +620,23 @@ class C extends N.Doc {
646
620
  });
647
621
  {
648
622
  const o = D.createEncoder();
649
- D.writeVarUint(o, X), Pt(o, this), this.send(e, D.toUint8Array(o));
623
+ D.writeVarUint(o, X), Ct(o, this), this.send(e, D.toUint8Array(o));
650
624
  const r = this.awareness.getStates();
651
625
  if (r.size > 0) {
652
- const i = D.createEncoder();
653
- D.writeVarUint(i, fe), D.writeVarUint8Array(i, ke(this.awareness, Array.from(r.keys()))), this.send(e, D.toUint8Array(i));
626
+ const c = D.createEncoder();
627
+ D.writeVarUint(c, fe), D.writeVarUint8Array(c, je(this.awareness, Array.from(r.keys()))), this.send(e, D.toUint8Array(c));
654
628
  }
655
629
  }
656
630
  };
657
631
  messageListener = (e, s) => {
658
632
  try {
659
- const a = D.createEncoder(), o = de.createDecoder(s), r = de.readVarUint(o);
633
+ const a = D.createEncoder(), o = ue.createDecoder(s), r = ue.readVarUint(o);
660
634
  switch (r) {
661
635
  case X:
662
- D.writeVarUint(a, X), Ct(o, a, this, null), D.length(a) > 1 && (this.ensureDataStructure(), this.send(e, D.toUint8Array(a)));
636
+ D.writeVarUint(a, X), Ot(o, a, this, null), D.length(a) > 1 && (this.ensureDataStructure(), this.send(e, D.toUint8Array(a)));
663
637
  break;
664
638
  case fe: {
665
- wt(this.awareness, de.readVarUint8Array(o), e);
639
+ At(this.awareness, ue.readVarUint8Array(o), e);
666
640
  break;
667
641
  }
668
642
  default:
@@ -679,10 +653,10 @@ class C extends N.Doc {
679
653
  s ? a = [s] : a = await this.getProjectIds();
680
654
  let o = {};
681
655
  if (e === "production" && a?.length) {
682
- const r = new Map(a?.map((i) => [i, !0]) || []);
683
- for (const i of a) {
684
- const c = C.pageUrlMapCache.get(i);
685
- c && (o = { ...o, ...c }, r.delete(i));
656
+ const r = new Map(a?.map((c) => [c, !0]) || []);
657
+ for (const c of a) {
658
+ const l = O.pageUrlMapCache.get(c);
659
+ l && (o = { ...o, ...l }, r.delete(c));
686
660
  }
687
661
  a = Array.from(r.keys());
688
662
  }
@@ -690,94 +664,94 @@ class C extends N.Doc {
690
664
  const r = await M.findAll({
691
665
  where: {
692
666
  id: {
693
- [Ne.in]: a
667
+ [Fe.in]: a
694
668
  }
695
669
  }
696
670
  });
697
671
  await Promise.all(
698
- r?.map(async (i) => {
699
- const c = i.id, l = i.slug || c, m = {}, T = e === "production" && i?.productionState ? i.productionState : await C.getStateByProjectId(i.id, e), O = mt(
700
- I.env.languages?.map((d) => d.code) || [],
701
- T.supportedLocales?.map((d) => d.locale) || []
702
- ), b = (d, p) => {
703
- l && (m[Y("/", l, d)] = {
704
- ...p,
672
+ r?.map(async (c) => {
673
+ const l = c.id, p = c.slug || l, y = {}, w = e === "production" && c?.productionState ? c.productionState : await O.getStateByProjectId(c.id, e), j = gt(
674
+ b.env.languages?.map((u) => u.code) || [],
675
+ w.supportedLocales?.map((u) => u.locale) || []
676
+ ), I = (u, i) => {
677
+ p && (y[H("/", p, u)] = {
678
+ ...i,
705
679
  shouldRedirect: !0,
706
680
  mainPage: !0
707
- }), m[Y("/", c, d)] = {
708
- ...p,
681
+ }), y[H("/", l, u)] = {
682
+ ...i,
709
683
  shouldRedirect: !0,
710
684
  mainPage: !0
711
685
  };
712
- for (const g of O) {
713
- const P = { ...p, locale: g };
714
- m[Y("/", g, c, d)] = P, l && (m[Y("/", g, l, d)] = P);
686
+ for (const g of j) {
687
+ const C = { ...i, locale: g };
688
+ y[H("/", g, l, u)] = C, p && (y[H("/", g, p, u)] = C);
715
689
  }
716
690
  };
717
691
  if (e === "draft")
718
- for (const d of T.routeIds || []) {
719
- const p = T?.routes?.[d];
720
- if (!p) continue;
721
- if (p.params && p.params.length > 0) {
722
- const h = Se({
723
- basePath: p.path,
724
- params: p.params,
725
- routeId: p.id,
726
- paramsOptions: p.paramsOptions,
692
+ for (const u of w.routeIds || []) {
693
+ const i = w?.routes?.[u];
694
+ if (!i) continue;
695
+ if (i.params && i.params.length > 0) {
696
+ const m = Se({
697
+ basePath: i.path,
698
+ params: i.params,
699
+ routeId: i.id,
700
+ paramsOptions: i.paramsOptions,
727
701
  currentIndex: 0,
728
702
  currentParams: [],
729
703
  currentOptionIds: [],
730
704
  result: []
731
705
  });
732
- for (const u of h) {
733
- const y = u.path, w = {
734
- projectId: c,
735
- projectSlug: l,
736
- pageSlug: y,
737
- pageId: p.displayTemplateId || "",
738
- routeId: d,
706
+ for (const d of m) {
707
+ const h = d.path, A = {
708
+ projectId: l,
709
+ projectSlug: p,
710
+ pageSlug: h,
711
+ pageId: i.displayTemplateId || "",
712
+ routeId: u,
739
713
  // default locale
740
- defaultLocale: O?.[0],
741
- locales: O,
742
- publishedAt: T.config.publishedAt,
743
- isPublic: p.isPublic && u?.routeMetaData?.isPublic
714
+ defaultLocale: j?.[0],
715
+ locales: j,
716
+ publishedAt: w.config.publishedAt,
717
+ isPublic: i.isPublic && d?.routeMetaData?.isPublic
744
718
  };
745
- b(y, w);
719
+ I(h, A);
746
720
  }
747
721
  }
748
- const g = p.path, P = {
749
- projectId: c,
750
- projectSlug: l,
722
+ const g = i.path, C = {
723
+ projectId: l,
724
+ projectSlug: p,
751
725
  pageSlug: g,
752
- pageId: p.displayTemplateId || "",
753
- routeId: d,
726
+ pageId: i.displayTemplateId || "",
727
+ routeId: u,
754
728
  // default locale
755
- defaultLocale: O?.[0],
756
- locales: O,
757
- publishedAt: T.config.publishedAt,
758
- isPublic: p.isPublic
729
+ defaultLocale: j?.[0],
730
+ locales: j,
731
+ publishedAt: w.config.publishedAt,
732
+ isPublic: i.isPublic
759
733
  };
760
- b(g, P);
734
+ I(g, C);
761
735
  }
762
- for (const d of T.pageIds) {
763
- const p = T.pages[d];
764
- if (!p || e === "production" && !p.isPublic)
736
+ for (const u of w.pageIds) {
737
+ const i = w.pages[u];
738
+ if (!i || e === "production" && !i.isPublic)
765
739
  continue;
766
- const g = p.slug, P = i.slug || c, h = {
767
- projectId: c,
768
- projectSlug: P,
740
+ const g = i.slug, C = c.slug || l, m = {
741
+ projectId: l,
742
+ projectSlug: C,
769
743
  pageSlug: g,
770
- pageId: d,
744
+ pageId: u,
771
745
  // default locale
772
- defaultLocale: O?.[0],
773
- locales: O,
774
- publishedAt: T.config.publishedAt,
775
- isPublic: p.isPublic,
776
- templateConfig: p.templateConfig
746
+ defaultLocale: j?.[0],
747
+ locales: j,
748
+ publishedAt: w.config.publishedAt,
749
+ isPublic: i.isPublic,
750
+ templateConfig: i.templateConfig
777
751
  };
778
- b(g, h);
752
+ I(g, m);
779
753
  }
780
- e === "production" && C.pageUrlMapCache.set(c, m), o = { ...o, ...m };
754
+ e === "production" && O.pageUrlMapCache.set(l, y), o = { ...o, ...y };
781
755
  })
782
756
  );
783
757
  }
@@ -788,7 +762,7 @@ class C extends N.Doc {
788
762
  }
789
763
  static getInstancesSizeInfo() {
790
764
  const e = [];
791
- for (const [s, a] of Object.entries(C.sharedInstances)) {
765
+ for (const [s, a] of Object.entries(O.sharedInstances)) {
792
766
  const o = a.getDocumentSize();
793
767
  e.push({
794
768
  projectId: s,
@@ -813,8 +787,8 @@ class C extends N.Doc {
813
787
  }
814
788
  // 执行定期检查
815
789
  static performPeriodicCheck() {
816
- const e = Object.keys(C.sharedInstances).length, s = [], a = [];
817
- for (const [o, r] of Object.entries(C.sharedInstances))
790
+ const e = Object.keys(O.sharedInstances).length, s = [], a = [];
791
+ for (const [o, r] of Object.entries(O.sharedInstances))
818
792
  r.conns.size === 0 ? s.push({ projectId: o, instance: r }) : a.push({ projectId: o, connections: r.conns.size });
819
793
  if (f.info(
820
794
  `[SiteState] periodic check summary: total instances: ${e}, with connections: ${a.length}, without connections: ${s.length}`
@@ -824,11 +798,11 @@ class C extends N.Doc {
824
798
  s.map((r) => r.projectId)
825
799
  );
826
800
  let o = 0;
827
- for (const { projectId: r, instance: i } of s)
801
+ for (const { projectId: r, instance: c } of s)
828
802
  try {
829
- f.info(`[SiteState] releasing instance due to periodic check: ${r}`), i.destroy(), o++;
830
- } catch (c) {
831
- f.error(`[SiteState] failed to release instance ${r} during periodic check:`, c);
803
+ f.info(`[SiteState] releasing instance due to periodic check: ${r}`), c.destroy(), o++;
804
+ } catch (l) {
805
+ f.error(`[SiteState] failed to release instance ${r} during periodic check:`, l);
832
806
  }
833
807
  f.info(
834
808
  `[SiteState] periodic check completed: ${o}/${s.length} instances released successfully`
@@ -852,45 +826,45 @@ async function Vt(t, e, s) {
852
826
  })(), s[t] = a), a;
853
827
  }
854
828
  const zt = async (t, e) => {
855
- const s = j(t), a = await dt({
856
- name: Fe,
857
- path: Y("/uploads", s),
829
+ const s = R(t), a = await dt({
830
+ name: _e,
831
+ path: H("/uploads", s),
858
832
  responseType: "stream",
859
833
  method: "GET"
860
834
  });
861
835
  if (a.status >= 200 && a.status < 400) {
862
- const o = nt(e);
863
- await yt(a.data, o);
836
+ const o = it(e);
837
+ await St(a.data, o);
864
838
  } else
865
839
  throw new Error(`download asset failed ${a.status}`);
866
840
  }, Jt = async (t, e) => {
867
841
  await Promise.all(
868
842
  t.map(async (s) => {
869
843
  try {
870
- await zt(s, E(e, j(s)));
844
+ await zt(s, E(e, R(s)));
871
845
  } catch (a) {
872
846
  f.error(`Failed to export assets: ${s}, ${a}`);
873
847
  }
874
848
  })
875
849
  );
876
850
  };
877
- function xe(t) {
878
- return Ae.test(t) ? [t] : W.test(t) ? (De.lastIndex = 0, Array.from(t.matchAll(De)).map((s) => s[1]).filter((s) => !!s)) : [];
851
+ function Be(t) {
852
+ return Ae.test(t) ? [t] : W.test(t) ? (Te.lastIndex = 0, Array.from(t.matchAll(Te)).map((s) => s[1]).filter((s) => !!s)) : [];
879
853
  }
880
854
  async function Z(t, e, s) {
881
855
  const { getFilename: a, exportAssets: o } = s, r = E(e, a(t));
882
856
  if (_(L(r), { recursive: !0 }), ee(r, G.stringify(t)), o) {
883
- const c = ae(
857
+ const l = ae(
884
858
  t,
885
- (l) => typeof l == "string" && (Ae.test(l) || W.test(l))
886
- ).map((l) => {
887
- const m = Ie(t, l);
888
- return xe(m);
859
+ (p) => typeof p == "string" && (Ae.test(p) || W.test(p))
860
+ ).map((p) => {
861
+ const y = Ie(t, p);
862
+ return Be(y);
889
863
  }).flat().filter(Boolean);
890
- await Jt(c, L(r));
864
+ await Jt(l, L(r));
891
865
  }
892
866
  }
893
- const ye = new be({
867
+ const ye = new Ee({
894
868
  max: 100,
895
869
  ttl: 1 * 60 * 1e3
896
870
  // 1 minute
@@ -898,26 +872,26 @@ const ye = new be({
898
872
  async function Re(t, e, s) {
899
873
  const a = ae(
900
874
  t,
901
- (c) => typeof c == "string" && (Ae.test(c) || W.test(c))
875
+ (l) => typeof l == "string" && (Ae.test(l) || W.test(l))
902
876
  ), o = ht(2), r = a.map(
903
- (c) => o(async () => {
877
+ (l) => o(async () => {
904
878
  try {
905
- const l = Ie(t, c), m = xe(l);
906
- for (const T of m) {
907
- const O = j(T), b = s.getFilePath(T, c), d = b ? `${b}:${O}` : O, p = ye.get(d);
908
- if (p) {
909
- W.test(l) || ve(t, c, p);
879
+ const p = Ie(t, l), y = Be(p);
880
+ for (const w of y) {
881
+ const j = R(w), I = s.getFilePath(w, l), u = I ? `${I}:${j}` : j, i = ye.get(u);
882
+ if (i) {
883
+ W.test(p) || ve(t, l, i);
910
884
  return;
911
885
  }
912
- const g = await Vt(b, O, e);
913
- g && (W.test(l) || ve(t, c, g), ye.set(d, g));
886
+ const g = await Vt(I, j, e);
887
+ g && (W.test(p) || ve(t, l, g), ye.set(u, g));
914
888
  }
915
- } catch (l) {
916
- f.error(`Failed to process upload for path ${c.join(".")}:`, l.message || l.reason);
889
+ } catch (p) {
890
+ f.error(`Failed to process upload for path ${l.join(".")}:`, p.message || p.reason);
917
891
  }
918
892
  })
919
- ), i = await Promise.allSettled(r);
920
- s.onFinish?.(i);
893
+ ), c = await Promise.allSettled(r);
894
+ s.onFinish?.(c);
921
895
  }
922
896
  async function Kt(t, {
923
897
  exportAssets: e,
@@ -925,13 +899,13 @@ async function Kt(t, {
925
899
  componentIds: a = "all",
926
900
  rawConfig: o,
927
901
  includeResources: r = !1,
928
- routeIds: i = "all"
902
+ routeIds: c = "all"
929
903
  } = {}) {
930
- const c = s === "all" ? t.pageIds : s, l = ct({
904
+ const l = s === "all" ? t.pageIds : s, p = pt({
931
905
  state: t,
932
- pageIds: c,
906
+ pageIds: l,
933
907
  componentIds: a === "all" ? Object.keys(t.components) : a
934
- }), m = i === "all" ? t.routeIds : i, T = (n) => ({
908
+ }), y = c === "all" ? t.routeIds : c, w = (n) => ({
935
909
  id: n.id,
936
910
  name: n.name,
937
911
  isTemplateSection: n.isTemplateSection ?? !1,
@@ -940,15 +914,15 @@ async function Kt(t, {
940
914
  component: n.component,
941
915
  config: n.config,
942
916
  visibility: n.visibility,
943
- sections: n?.sectionIds ? R(
917
+ sections: n?.sectionIds ? T(
944
918
  n?.sectionIds?.map((S) => {
945
919
  const v = n.sections?.[S];
946
- return v && T(v);
920
+ return v && w(v);
947
921
  })
948
922
  ) : void 0
949
923
  // 已经废弃,数据在 page.dataSource 中管理
950
924
  // properties: section.locales?.[locale] ?? {},
951
- }), O = (n, S) => ({
925
+ }), j = (n, S) => ({
952
926
  id: n.id,
953
927
  createdAt: n.createdAt,
954
928
  updatedAt: n.updatedAt,
@@ -956,17 +930,17 @@ async function Kt(t, {
956
930
  isPublic: n.isPublic ?? !0,
957
931
  templateConfig: n.templateConfig,
958
932
  meta: n.locales?.[S] ?? {},
959
- sections: R(
933
+ sections: T(
960
934
  n.sectionIds.map((v) => {
961
935
  const x = n.sections[v];
962
- return x && T(x);
936
+ return x && w(x);
963
937
  })
964
938
  ),
965
939
  // 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
966
940
  dataSource: Object.fromEntries(
967
941
  Object.entries(n.dataSource || {}).map(([v, x]) => [v, x?.[S] ?? {}])
968
942
  )
969
- }), b = (n) => ({
943
+ }), I = (n) => ({
970
944
  id: n.id,
971
945
  createdAt: n.createdAt,
972
946
  updatedAt: n.updatedAt,
@@ -978,63 +952,63 @@ async function Kt(t, {
978
952
  enabledGenerate: n.enabledGenerate ?? !1,
979
953
  displayTemplateId: n.displayTemplateId,
980
954
  dataSource: n.dataSource
981
- }), d = R(
982
- m.map((n) => {
955
+ }), u = T(
956
+ y.map((n) => {
983
957
  const S = t.routes[n];
984
- return S && b(S);
958
+ return S && I(S);
985
959
  })
986
- ), p = R(
960
+ ), i = T(
987
961
  t.supportedLocales.map((n) => n.locale).flatMap(
988
- (n) => c.map((S) => {
962
+ (n) => l.map((S) => {
989
963
  const v = t.pages[S];
990
964
  return v && {
991
965
  locale: n,
992
966
  slug: v.slug,
993
- page: O(v, n)
967
+ page: j(v, n)
994
968
  };
995
969
  })
996
970
  )
997
- ), g = _e(), P = E(g, "pages");
998
- _(P, { recursive: !0 });
999
- const h = E(g, "components");
1000
- _(h, { recursive: !0 });
1001
- const u = E(g, "routes");
1002
- _(u, { recursive: !0 });
1003
- for (const { locale: n, slug: S, page: v } of p)
1004
- await Z(v, P, {
971
+ ), g = xe(), C = E(g, "pages");
972
+ _(C, { recursive: !0 });
973
+ const m = E(g, "components");
974
+ _(m, { recursive: !0 });
975
+ const d = E(g, "routes");
976
+ _(d, { recursive: !0 });
977
+ for (const { locale: n, slug: S, page: v } of i)
978
+ await Z(v, C, {
1005
979
  getFilename: () => `${oe(S) || "index"}.${n}.yml`,
1006
980
  exportAssets: e
1007
981
  });
1008
- for (const n of d)
1009
- await Z(n, u, {
982
+ for (const n of u)
983
+ await Z(n, d, {
1010
984
  // getFilename: () => `${sanitizeSlug(route.path)}.yml`,
1011
985
  getFilename: () => `${oe(n.path) || "index"}.yml`,
1012
986
  exportAssets: e
1013
987
  });
1014
- for (const n of l) {
988
+ for (const n of p) {
1015
989
  const S = t.components[n]?.data;
1016
- S && await Z(S, h, {
990
+ S && await Z(S, m, {
1017
991
  getFilename: (v) => `${v.name || "unnamed"}.${v.id}.yml`,
1018
992
  exportAssets: e
1019
993
  });
1020
994
  }
1021
- const y = E(g, ".blocklet/pages/pages.config.yml");
1022
- _(L(y), { recursive: !0 });
1023
- const w = {
1024
- pages: R(
1025
- c.map((n) => {
995
+ const h = E(g, ".blocklet/pages/pages.config.yml");
996
+ _(L(h), { recursive: !0 });
997
+ const A = {
998
+ pages: T(
999
+ l.map((n) => {
1026
1000
  const S = t.pages[n];
1027
1001
  return S && { id: n, slug: S.slug };
1028
1002
  })
1029
1003
  ),
1030
- routes: R(
1031
- m.map((n) => {
1004
+ routes: T(
1005
+ y.map((n) => {
1032
1006
  const S = t.routes[n];
1033
1007
  return S && { id: n, path: S.path };
1034
1008
  })
1035
1009
  ),
1036
- components: R(
1037
- l.map((n) => {
1010
+ components: T(
1011
+ p.map((n) => {
1038
1012
  const S = t.components[n]?.data;
1039
1013
  return S && {
1040
1014
  id: n,
@@ -1044,8 +1018,8 @@ async function Kt(t, {
1044
1018
  ),
1045
1019
  ...r ? {
1046
1020
  resources: {
1047
- components: R(
1048
- Object.keys(t.resources?.components || {}).filter((n) => l.includes(n)).map((n) => ({
1021
+ components: T(
1022
+ Object.keys(t.resources?.components || {}).filter((n) => p.includes(n)).map((n) => ({
1049
1023
  id: n,
1050
1024
  name: t.resources?.components?.[n]?.component?.name
1051
1025
  }))
@@ -1055,36 +1029,36 @@ async function Kt(t, {
1055
1029
  supportedLocales: t.supportedLocales,
1056
1030
  config: t.config
1057
1031
  };
1058
- ee(y, G.stringify(w));
1059
- const A = E(g, "config.source.json");
1060
- if (o && ee(A, JSON.stringify(o)), r) {
1032
+ ee(h, G.stringify(A));
1033
+ const P = E(g, "config.source.json");
1034
+ if (o && ee(P, JSON.stringify(o)), r) {
1061
1035
  const n = E(g, "resources"), S = E(n, "components");
1062
1036
  _(S, { recursive: !0 });
1063
- for (const J of Object.keys(t?.resources?.components ?? {}).filter(
1064
- ($) => l.includes($)
1037
+ for (const z of Object.keys(t?.resources?.components ?? {}).filter(
1038
+ ($) => p.includes($)
1065
1039
  )) {
1066
- const $ = t.resources?.components?.[J]?.component;
1040
+ const $ = t.resources?.components?.[z]?.component;
1067
1041
  $ && await Z($, S, {
1068
- getFilename: (K) => `${K.name || "unnamed"}.${K.id}.yml`,
1042
+ getFilename: (J) => `${J.name || "unnamed"}.${J.id}.yml`,
1069
1043
  exportAssets: e
1070
1044
  });
1071
1045
  }
1072
1046
  const v = E(g, "chunks");
1073
1047
  _(v, { recursive: !0 });
1074
1048
  const x = qt();
1075
- for (const J of Object.keys(t?.resources?.components ?? {}).filter(
1076
- ($) => l.includes($)
1049
+ for (const z of Object.keys(t?.resources?.components ?? {}).filter(
1050
+ ($) => p.includes($)
1077
1051
  )) {
1078
- const $ = t.resources?.components?.[J]?.component;
1052
+ const $ = t.resources?.components?.[z]?.component;
1079
1053
  if ($ && $.renderer?.type === "react-component") {
1080
- const K = $.renderer?.chunks ?? [];
1081
- if (K?.length > 0)
1082
- for (const pe of K) {
1054
+ const J = $.renderer?.chunks ?? [];
1055
+ if (J?.length > 0)
1056
+ for (const pe of J) {
1083
1057
  const Pe = E(v, pe), le = x?.[pe];
1084
1058
  try {
1085
- le && U(le) && !U(Pe) && ot(le, Pe);
1086
- } catch (He) {
1087
- f.error(`copy chunk ${pe} error`, He.message);
1059
+ le && U(le) && !U(Pe) && rt(le, Pe);
1060
+ } catch (Ye) {
1061
+ f.error(`copy chunk ${pe} error`, Ye.message);
1088
1062
  }
1089
1063
  }
1090
1064
  }
@@ -1092,75 +1066,75 @@ async function Kt(t, {
1092
1066
  }
1093
1067
  return g;
1094
1068
  }
1095
- async function Be(t, { importAssets: e, includeResources: s } = {}) {
1069
+ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1096
1070
  if (!U(t))
1097
1071
  return null;
1098
1072
  let a, o = !1;
1099
1073
  try {
1100
- B(t).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a = _e(), await St({ file: t, C: a }));
1101
- const r = te("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }).at(0), i = r && E(L(r), "../../pages"), c = r && E(L(r), "../../components"), l = r && E(L(r), "../../routes");
1074
+ B(t).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a = xe(), await It({ file: t, C: a }));
1075
+ const r = te("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }).at(0), c = r && E(L(r), "../../pages"), l = r && E(L(r), "../../components"), p = r && E(L(r), "../../routes");
1102
1076
  if (!r)
1103
1077
  return null;
1104
- const m = G.parse(H(r).toString()), T = (h, u, y) => {
1105
- let w = E(h, `${u}${y ? `.${y}` : ""}.yml`);
1106
- return (!U(w) || !B(w).isFile()) && (w = E(h, u, `index${y ? `.${y}` : ""}.yml`), !U(w) || !B(w)) ? null : G.parse(H(w).toString());
1107
- }, O = (h, u) => {
1078
+ const y = G.parse(q(r).toString()), w = (m, d, h) => {
1079
+ let A = E(m, `${d}${h ? `.${h}` : ""}.yml`);
1080
+ return (!U(A) || !B(A).isFile()) && (A = E(m, d, `index${h ? `.${h}` : ""}.yml`), !U(A) || !B(A)) ? null : G.parse(q(A).toString());
1081
+ }, j = (m, d) => {
1108
1082
  try {
1109
- const y = te(`*.${u}.yml`, { cwd: h, absolute: !0 })[0];
1110
- return y ? G.parse(H(y).toString()) : null;
1111
- } catch (y) {
1112
- f.error("parse component error", y);
1083
+ const h = te(`*.${d}.yml`, { cwd: m, absolute: !0 })[0];
1084
+ return h ? G.parse(q(h).toString()) : null;
1085
+ } catch (h) {
1086
+ f.error("parse component error", h);
1113
1087
  }
1114
1088
  return null;
1115
- }, b = (h, u) => {
1116
- let y = E(h, `${u}.yml`);
1117
- return (!U(y) || !B(y).isFile()) && (y = E(h, u, "index.yml"), !U(y) || !B(y)) ? null : G.parse(H(y).toString());
1118
- }, d = R(
1119
- m.pages.map(({ slug: h }) => {
1120
- const u = R(
1121
- m.supportedLocales.map(({ locale: A }) => {
1122
- const n = i ? T(i, oe(h), A) : void 0;
1089
+ }, I = (m, d) => {
1090
+ let h = E(m, `${d}.yml`);
1091
+ return (!U(h) || !B(h).isFile()) && (h = E(m, d, "index.yml"), !U(h) || !B(h)) ? null : G.parse(q(h).toString());
1092
+ }, u = T(
1093
+ y.pages.map(({ slug: m }) => {
1094
+ const d = T(
1095
+ y.supportedLocales.map(({ locale: P }) => {
1096
+ const n = c ? w(c, oe(m), P) : void 0;
1123
1097
  if (n)
1124
- return { locale: A, page: n };
1125
- const S = i ? T(i, h, A) : void 0;
1126
- return S && { locale: A, page: S };
1098
+ return { locale: P, page: n };
1099
+ const S = c ? w(c, m, P) : void 0;
1100
+ return S && { locale: P, page: S };
1127
1101
  })
1128
- ), y = u[0]?.page;
1129
- if (!y)
1102
+ ), h = d[0]?.page;
1103
+ if (!h)
1130
1104
  return null;
1131
- const w = y.sections.map(it);
1105
+ const A = h.sections.map(ct);
1132
1106
  return {
1133
- id: y.id || Oe(),
1134
- createdAt: y.createdAt,
1135
- updatedAt: y.updatedAt,
1136
- publishedAt: y.publishedAt,
1137
- isPublic: y.isPublic ?? !0,
1138
- templateConfig: y.templateConfig,
1139
- slug: h,
1140
- sections: Object.fromEntries(w.map((A) => [A.id, A])),
1141
- sectionIds: w.map((A) => A.id),
1142
- locales: Object.fromEntries(u.map(({ locale: A, page: n }) => [A, n.meta])),
1143
- dataSource: y.dataSource ? Object.fromEntries(
1107
+ id: h.id || Oe(),
1108
+ createdAt: h.createdAt,
1109
+ updatedAt: h.updatedAt,
1110
+ publishedAt: h.publishedAt,
1111
+ isPublic: h.isPublic ?? !0,
1112
+ templateConfig: h.templateConfig,
1113
+ slug: m,
1114
+ sections: Object.fromEntries(A.map((P) => [P.id, P])),
1115
+ sectionIds: A.map((P) => P.id),
1116
+ locales: Object.fromEntries(d.map(({ locale: P, page: n }) => [P, n.meta])),
1117
+ dataSource: h.dataSource ? Object.fromEntries(
1144
1118
  // 获取 dataSource 中所有 section ID
1145
- [...new Set(u.flatMap(({ page: A }) => Object.keys(A.dataSource ?? {})))].map((A) => [
1146
- A,
1119
+ [...new Set(d.flatMap(({ page: P }) => Object.keys(P.dataSource ?? {})))].map((P) => [
1120
+ P,
1147
1121
  Object.fromEntries(
1148
- u.map(({ locale: n, page: S }) => {
1149
- const v = S.dataSource?.[A];
1122
+ d.map(({ locale: n, page: S }) => {
1123
+ const v = S.dataSource?.[P];
1150
1124
  return [n, v || {}];
1151
1125
  })
1152
1126
  )
1153
1127
  ])
1154
1128
  ) : Object.fromEntries(
1155
1129
  // 获取所有 section ID
1156
- [...new Set(u.flatMap(({ page: A }) => A.sections.map((n) => n.id)))].map((A) => [
1157
- A,
1130
+ [...new Set(d.flatMap(({ page: P }) => P.sections.map((n) => n.id)))].map((P) => [
1131
+ P,
1158
1132
  Object.fromEntries(
1159
- u.map(({ locale: n, page: S }) => {
1160
- const v = S.dataSource?.[A];
1133
+ d.map(({ locale: n, page: S }) => {
1134
+ const v = S.dataSource?.[P];
1161
1135
  if (v)
1162
1136
  return [n, v];
1163
- const x = S.sections.find((J) => J.id === A);
1137
+ const x = S.sections.find((z) => z.id === P);
1164
1138
  return [n, x?.properties || {}];
1165
1139
  })
1166
1140
  )
@@ -1168,99 +1142,99 @@ async function Be(t, { importAssets: e, includeResources: s } = {}) {
1168
1142
  )
1169
1143
  };
1170
1144
  })
1171
- ), p = R(
1172
- m?.routes?.map(({ path: h }) => {
1173
- const u = l ? b(l, oe(h)) : void 0;
1145
+ ), i = T(
1146
+ y?.routes?.map(({ path: m }) => {
1147
+ const d = p ? I(p, oe(m)) : void 0;
1174
1148
  return {
1175
- ...u,
1176
- id: u?.id || Oe(),
1177
- createdAt: u?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1178
- updatedAt: u?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1149
+ ...d,
1150
+ id: d?.id || Oe(),
1151
+ createdAt: d?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1152
+ updatedAt: d?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1179
1153
  publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
1180
- path: u?.path ?? `/${u?.id}`,
1181
- params: u?.params,
1182
- handler: u?.handler ?? "Pages Kit",
1183
- isPublic: u?.isPublic ?? !0,
1184
- enabledGenerate: u?.enabledGenerate ?? !1,
1185
- displayTemplateId: u?.displayTemplateId ?? void 0,
1186
- dataSource: u?.dataSource ?? {}
1154
+ path: d?.path ?? `/${d?.id}`,
1155
+ params: d?.params,
1156
+ handler: d?.handler ?? "Pages Kit",
1157
+ isPublic: d?.isPublic ?? !0,
1158
+ enabledGenerate: d?.enabledGenerate ?? !1,
1159
+ displayTemplateId: d?.displayTemplateId ?? void 0,
1160
+ dataSource: d?.dataSource ?? {}
1187
1161
  };
1188
1162
  }) ?? []
1189
- ), g = c ? R(m.components?.map(({ id: h }) => O(c, h)) ?? []) : [];
1163
+ ), g = l ? T(y.components?.map(({ id: m }) => j(l, m)) ?? []) : [];
1190
1164
  if (e) {
1191
- const h = (...u) => {
1192
- f.info(`[${o ? j(t) : j(E(t, "../../../../"))}] importAssets:`, ...u);
1165
+ const m = (...d) => {
1166
+ f.info(`[${o ? R(t) : R(E(t, "../../../../"))}] importAssets:`, ...d);
1193
1167
  };
1194
1168
  try {
1195
- h("wait image-bin api ready"), await It({
1196
- resources: [`${pt(Ye)}/api/sdk/uploads`],
1197
- validateStatus: (w) => w >= 200 && w <= 500
1198
- }), h("image-bin api is ready");
1199
- const u = {}, y = {};
1200
- h("start to upload assets"), await Promise.allSettled([
1201
- Re(g, u, {
1202
- getFilePath: (w) => c && E(c, w),
1203
- onFinish: (w) => {
1204
- h(`upload ${w.length} component assets`);
1169
+ m("wait image-bin api ready"), await bt({
1170
+ resources: [`${lt(We)}/api/sdk/uploads`],
1171
+ validateStatus: (A) => A >= 200 && A <= 500
1172
+ }), m("image-bin api is ready");
1173
+ const d = {}, h = {};
1174
+ m("start to upload assets"), await Promise.allSettled([
1175
+ Re(g, d, {
1176
+ getFilePath: (A) => l && E(l, A),
1177
+ onFinish: (A) => {
1178
+ m(`upload ${A.length} component assets`);
1205
1179
  }
1206
1180
  }),
1207
- Re(d, y, {
1208
- getFilePath: (w, A) => {
1209
- const n = Ie(d, A.slice(0, 1));
1210
- return i && E(i, L(n.slug), w);
1181
+ Re(u, h, {
1182
+ getFilePath: (A, P) => {
1183
+ const n = Ie(u, P.slice(0, 1));
1184
+ return c && E(c, L(n.slug), A);
1211
1185
  },
1212
- onFinish: (w) => {
1213
- h(`upload ${w.length} page assets`);
1186
+ onFinish: (A) => {
1187
+ m(`upload ${A.length} page assets`);
1214
1188
  }
1215
1189
  })
1216
- ]), h("upload assets done"), ye.clear(), global.gc && global.gc();
1217
- } catch (u) {
1218
- h("Error during asset import:", u);
1190
+ ]), m("upload assets done"), ye.clear(), global.gc && global.gc();
1191
+ } catch (d) {
1192
+ m("Error during asset import:", d);
1219
1193
  }
1220
1194
  }
1221
- const P = {};
1195
+ const C = {};
1222
1196
  if (s) {
1223
- const h = r && E(L(r), "../../resources/components"), u = R(
1224
- m.resources?.components?.map(({ id: y }) => O(h, y)) ?? []
1197
+ const m = r && E(L(r), "../../resources/components"), d = T(
1198
+ y.resources?.components?.map(({ id: h }) => j(m, h)) ?? []
1225
1199
  );
1226
- u.length > 0 && (P.components = Object.fromEntries(
1227
- u.map((y, w) => [y.id, { index: w, component: y }])
1200
+ d.length > 0 && (C.components = Object.fromEntries(
1201
+ d.map((h, A) => [h.id, { index: A, component: h }])
1228
1202
  ));
1229
1203
  }
1230
1204
  return {
1231
- supportedLocales: m.supportedLocales,
1232
- pageIds: d.map((h) => h.id),
1233
- components: Object.fromEntries(g.map((h, u) => [h.id, { index: u, data: h }])),
1234
- pages: Object.fromEntries(d.map((h) => [h.id, h])),
1235
- config: m.config || {},
1236
- resources: P,
1237
- routeIds: p.map((h) => h.id),
1238
- routes: Object.fromEntries(p.map((h) => [h.id, h])),
1205
+ supportedLocales: y.supportedLocales,
1206
+ pageIds: u.map((m) => m.id),
1207
+ components: Object.fromEntries(g.map((m, d) => [m.id, { index: d, data: m }])),
1208
+ pages: Object.fromEntries(u.map((m) => [m.id, m])),
1209
+ config: y.config || {},
1210
+ resources: C,
1211
+ routeIds: i.map((m) => m.id),
1212
+ routes: Object.fromEntries(i.map((m) => [m.id, m])),
1239
1213
  dataSourceIds: [],
1240
1214
  dataSources: {}
1241
1215
  };
1242
1216
  } finally {
1243
- o && a && $e(a, { force: !0, recursive: !0 });
1217
+ o && a && Ue(a, { force: !0, recursive: !0 });
1244
1218
  }
1245
1219
  }
1246
- async function je(t, e, {
1220
+ async function Le(t, e, {
1247
1221
  routes: s,
1248
1222
  mergeMode: a = "byUpdateTime",
1249
1223
  deleteRoutes: o = !1,
1250
1224
  publishMode: r = void 0
1251
1225
  } = {}) {
1252
1226
  try {
1253
- r && We(r);
1254
- } catch (b) {
1255
- f.error("clear preload page cache error", { error: b });
1227
+ r && Qe(r);
1228
+ } catch (I) {
1229
+ f.error("clear preload page cache error", { error: I });
1256
1230
  }
1257
- const { pages: i, pageIds: c, routeIds: l, routes: m, supportedLocales: T } = t;
1231
+ const { pages: c, pageIds: l, routeIds: p, routes: y, supportedLocales: w } = t;
1258
1232
  if (r === "production") {
1259
- let b = s ?? [], d = null;
1260
- for (const p of l ?? []) {
1261
- const g = m?.[p];
1233
+ let I = s ?? [], u = null;
1234
+ for (const i of p ?? []) {
1235
+ const g = y?.[i];
1262
1236
  if (g?.params && g?.params.length > 0 && g?.paramsOptions && g?.paramsOptions.length > 0) {
1263
- const P = Se({
1237
+ const C = Se({
1264
1238
  basePath: g.path,
1265
1239
  params: g.params,
1266
1240
  routeId: g.id,
@@ -1269,127 +1243,127 @@ async function je(t, e, {
1269
1243
  currentParams: [],
1270
1244
  currentOptionIds: [],
1271
1245
  result: []
1272
- }), h = Object.fromEntries(P.map((u) => [`${p}-${u.paramOptionIds.join("-")}`, u]));
1273
- d = { ...d || {}, ...h }, s || (b = [...b, ...P.map((u) => `${p}-${u.paramOptionIds.join("-")}`)]);
1274
- } else s || b.push(p);
1246
+ }), m = Object.fromEntries(C.map((d) => [`${i}-${d.paramOptionIds.join("-")}`, d]));
1247
+ u = { ...u || {}, ...m }, s || (I = [...I, ...C.map((d) => `${i}-${d.paramOptionIds.join("-")}`)]);
1248
+ } else s || I.push(i);
1275
1249
  }
1276
- f.info("routeIds to be published: ", b);
1277
- for (const p of b) {
1278
- let g = p;
1250
+ f.info("routeIds to be published: ", I);
1251
+ for (const i of I) {
1252
+ let g = i;
1279
1253
  if (g.includes("-")) {
1280
- const [u] = g.split("-");
1281
- g = u;
1254
+ const [d] = g.split("-");
1255
+ g = d;
1282
1256
  }
1283
- const P = m?.[g];
1284
- if (!P) {
1285
- const u = e.pageIds.indexOf(g);
1286
- u !== -1 && o && (e.pageIds.splice(u, 1), delete e.pages[g]);
1287
- for (const y of e.pageIds)
1288
- y.includes(`${g}-`) && (e.pageIds.splice(e.pageIds.indexOf(y), 1), delete e.pages[y]);
1257
+ const C = y?.[g];
1258
+ if (!C) {
1259
+ const d = e.pageIds.indexOf(g);
1260
+ d !== -1 && o && (e.pageIds.splice(d, 1), delete e.pages[g]);
1261
+ for (const h of e.pageIds)
1262
+ h.includes(`${g}-`) && (e.pageIds.splice(e.pageIds.indexOf(h), 1), delete e.pages[h]);
1289
1263
  f.info("delete main route page", g);
1290
1264
  continue;
1291
1265
  }
1292
- if (p.includes("-") && !d?.[p]) {
1293
- const u = e.pageIds.indexOf(p);
1294
- u !== -1 && o && (e.pageIds.splice(u, 1), delete e.pages[p]), f.info("delete page", p);
1266
+ if (i.includes("-") && !u?.[i]) {
1267
+ const d = e.pageIds.indexOf(i);
1268
+ d !== -1 && o && (e.pageIds.splice(d, 1), delete e.pages[i]), f.info("delete page", i);
1295
1269
  continue;
1296
1270
  }
1297
- if (!P.displayTemplateId) {
1298
- f.info("no display template", p);
1271
+ if (!C.displayTemplateId) {
1272
+ f.info("no display template", i);
1299
1273
  continue;
1300
1274
  }
1301
- const h = i[P.displayTemplateId];
1302
- if (!h) {
1303
- f.info("no template page", p);
1275
+ const m = c[C.displayTemplateId];
1276
+ if (!m) {
1277
+ f.info("no template page", i);
1304
1278
  continue;
1305
1279
  }
1306
- if (e.pageIds.includes(p)) {
1307
- if (f.info("has need update page", p), a === "replace")
1308
- e.pages[p] = ue({
1309
- page: h,
1310
- route: P,
1280
+ if (e.pageIds.includes(i)) {
1281
+ if (f.info("has need update page", i), a === "replace")
1282
+ e.pages[i] = de({
1283
+ page: m,
1284
+ route: C,
1311
1285
  state: t,
1312
- routeId: p,
1313
- routePathInfo: d?.[p]
1314
- }), f.info("replace page", p);
1286
+ routeId: i,
1287
+ routePathInfo: u?.[i]
1288
+ }), f.info("replace page", i);
1315
1289
  else if (a === "byUpdateTime") {
1316
- const u = e.pages[P.id];
1317
- (!u || P.updatedAt && P.updatedAt > u.updatedAt) && (e.pages[p] = ue({
1318
- page: h,
1319
- route: P,
1290
+ const d = e.pages[C.id];
1291
+ (!d || C.updatedAt && C.updatedAt > d.updatedAt) && (e.pages[i] = de({
1292
+ page: m,
1293
+ route: C,
1320
1294
  state: t,
1321
- routeId: p,
1322
- routePathInfo: d?.[p]
1323
- }), f.info("replace page by update time", p));
1295
+ routeId: i,
1296
+ routePathInfo: u?.[i]
1297
+ }), f.info("replace page by update time", i));
1324
1298
  }
1325
1299
  } else
1326
- e.pageIds.push(p), e.pages[p] = ue({
1327
- page: h,
1328
- route: P,
1300
+ e.pageIds.push(i), e.pages[i] = de({
1301
+ page: m,
1302
+ route: C,
1329
1303
  state: t,
1330
- routeId: p,
1331
- routePathInfo: d?.[p]
1332
- }), f.info("add page", p);
1304
+ routeId: i,
1305
+ routePathInfo: u?.[i]
1306
+ }), f.info("add page", i);
1333
1307
  }
1334
1308
  if (o && !s)
1335
- for (const p of e.pageIds)
1336
- b?.includes(p) || (delete e.pages[p], f.info("delete page", p)), e.pageIds = [...e.pageIds].filter((g) => b?.includes(g));
1309
+ for (const i of e.pageIds)
1310
+ I?.includes(i) || (delete e.pages[i], f.info("delete page", i)), e.pageIds = [...e.pageIds].filter((g) => I?.includes(g));
1337
1311
  } else {
1338
- for (const b of c) {
1339
- const d = i[b];
1340
- if (d)
1341
- if (e.pageIds.includes(d.id)) {
1312
+ for (const I of l) {
1313
+ const u = c[I];
1314
+ if (u)
1315
+ if (e.pageIds.includes(u.id)) {
1342
1316
  if (a === "replace")
1343
- e.pages[d.id] = d;
1317
+ e.pages[u.id] = u;
1344
1318
  else if (a === "byUpdateTime") {
1345
- const p = e.pages[d.id];
1346
- (!p || d.updatedAt && d.updatedAt > p.updatedAt) && (e.pages[d.id] = d);
1319
+ const i = e.pages[u.id];
1320
+ (!i || u.updatedAt && u.updatedAt > i.updatedAt) && (e.pages[u.id] = u);
1347
1321
  }
1348
1322
  } else
1349
- e.pageIds.push(d.id), e.pages[d.id] = d;
1323
+ e.pageIds.push(u.id), e.pages[u.id] = u;
1350
1324
  }
1351
- for (const b of l) {
1352
- const d = m[b];
1353
- if (d)
1354
- if (e.routeIds.includes(d.id)) {
1325
+ for (const I of p) {
1326
+ const u = y[I];
1327
+ if (u)
1328
+ if (e.routeIds.includes(u.id)) {
1355
1329
  if (a === "replace")
1356
- e.routes[d.id] = d;
1330
+ e.routes[u.id] = u;
1357
1331
  else if (a === "byUpdateTime") {
1358
- const p = e.routes[d.id];
1359
- (!p || d.updatedAt && d.updatedAt > p.updatedAt) && (e.routes[d.id] = d);
1332
+ const i = e.routes[u.id];
1333
+ (!i || u.updatedAt && u.updatedAt > i.updatedAt) && (e.routes[u.id] = u);
1360
1334
  }
1361
1335
  } else
1362
- e.routeIds.push(d.id), e.routes[d.id] = d;
1336
+ e.routeIds.push(u.id), e.routes[u.id] = u;
1363
1337
  }
1364
1338
  }
1365
- if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...ft(T)), o)
1366
- for (const b of Object.keys(e.components))
1367
- delete e.components[b];
1368
- let O = JSON.parse(JSON.stringify(t.components));
1369
- O = Object.fromEntries(
1339
+ if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...mt(w)), o)
1340
+ for (const I of Object.keys(e.components))
1341
+ delete e.components[I];
1342
+ let j = JSON.parse(JSON.stringify(t.components));
1343
+ j = Object.fromEntries(
1370
1344
  await Promise.all(
1371
- Object.entries(O).map(async ([b, d]) => {
1372
- const p = await Ge(d?.data);
1345
+ Object.entries(j).map(async ([I, u]) => {
1346
+ const i = await Ve(u?.data);
1373
1347
  return [
1374
- b,
1348
+ I,
1375
1349
  {
1376
- ...d,
1377
- data: p
1350
+ ...u,
1351
+ data: i
1378
1352
  }
1379
1353
  ];
1380
1354
  })
1381
1355
  )
1382
- ), Object.assign(e.components, O), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ee(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1356
+ ), Object.assign(e.components, j), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), be(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1383
1357
  }
1384
- const Ge = Qe(
1358
+ const Ve = Xe(
1385
1359
  async (t) => {
1386
- if (!Ee(t?.properties))
1360
+ if (!be(t?.properties))
1387
1361
  return t;
1388
1362
  if (t?.renderer?.type === "react-component") {
1389
1363
  const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
1390
1364
  if (s || e && e.includes("PROPERTIES_SCHEMA"))
1391
1365
  try {
1392
- const a = await Xe(
1366
+ const a = await Ze(
1393
1367
  e ?? "",
1394
1368
  "PROPERTIES_SCHEMA",
1395
1369
  t.id,
@@ -1412,28 +1386,28 @@ const Ge = Qe(
1412
1386
  }
1413
1387
  );
1414
1388
  let re, Q, ne, ie;
1415
- const Ve = () => lt({
1389
+ const ze = () => ut({
1416
1390
  types: [
1417
- { did: Fe, type: Te },
1418
- { did: Tt, type: Te }
1391
+ { did: _e, type: De },
1392
+ { did: Dt, type: De }
1419
1393
  ]
1420
1394
  }), qt = () => {
1421
- const t = Ve(), e = {};
1395
+ const t = ze(), e = {};
1422
1396
  return t.forEach((s) => {
1423
1397
  const a = te("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), o = a && E(L(a), "../../chunks");
1424
1398
  if (o && U(o)) {
1425
- const r = rt(o);
1426
- for (const i of r)
1427
- e[i] = E(o, i);
1399
+ const r = nt(o);
1400
+ for (const c of r)
1401
+ e[c] = E(o, c);
1428
1402
  }
1429
1403
  }), e;
1430
1404
  };
1431
- function ze() {
1405
+ function Je() {
1432
1406
  return re = (async () => {
1433
- const t = Ve();
1407
+ const t = ze();
1434
1408
  Q = (await Promise.all(
1435
1409
  t.map(async (s) => {
1436
- const a = s.path ? await Be(s.path, { importAssets: !1 }) : void 0;
1410
+ const a = s.path ? await Ge(s.path, { importAssets: !1 }) : void 0;
1437
1411
  return a ? { blockletId: s.did, state: a, blockletTitle: s.title } : void 0;
1438
1412
  })
1439
1413
  )).filter((s) => !!s), ne = Q.reduce(
@@ -1457,7 +1431,7 @@ function ze() {
1457
1431
  ie = Object.fromEntries(
1458
1432
  await Promise.all(
1459
1433
  Object.entries(e).map(async ([s, a]) => {
1460
- const o = await Ge(a.component);
1434
+ const o = await Ve(a.component);
1461
1435
  return [
1462
1436
  s,
1463
1437
  {
@@ -1471,9 +1445,9 @@ function ze() {
1471
1445
  })(), re;
1472
1446
  }
1473
1447
  function Ht(t) {
1474
- const e = Ue(
1448
+ const e = Me(
1475
1449
  async () => {
1476
- await ze().catch((s) => {
1450
+ await Je().catch((s) => {
1477
1451
  f.error("load resource states error", { error: s });
1478
1452
  }), await t?.({
1479
1453
  states: Q,
@@ -1485,14 +1459,14 @@ function Ht(t) {
1485
1459
  // 3s
1486
1460
  { leading: !1, trailing: !0 }
1487
1461
  );
1488
- return e(), I.events.on(I.Events.componentAdded, e), I.events.on(I.Events.componentRemoved, e), I.events.on(I.Events.componentStarted, e), I.events.on(I.Events.componentStopped, e), I.events.on(I.Events.componentUpdated, e), I.events.on(he, e), () => {
1489
- I.events.off(I.Events.componentAdded, e), I.events.off(I.Events.componentRemoved, e), I.events.off(I.Events.componentStarted, e), I.events.off(I.Events.componentStopped, e), I.events.off(I.Events.componentUpdated, e), I.events.off(he, e);
1462
+ return e(), b.events.on(b.Events.componentAdded, e), b.events.on(b.Events.componentRemoved, e), b.events.on(b.Events.componentStarted, e), b.events.on(b.Events.componentStopped, e), b.events.on(b.Events.componentUpdated, e), b.events.on(ge, e), () => {
1463
+ b.events.off(b.Events.componentAdded, e), b.events.off(b.Events.componentRemoved, e), b.events.off(b.Events.componentStarted, e), b.events.off(b.Events.componentStopped, e), b.events.off(b.Events.componentUpdated, e), b.events.off(ge, e);
1490
1464
  };
1491
1465
  }
1492
- const Je = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), Ke = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), ce = globalThis;
1493
- ce[Je]?.();
1494
- ce[Je] = Ht(async ({ pages: t, components: e }) => {
1495
- const s = await C.getProjectIds();
1466
+ const Ke = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), qe = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), ce = globalThis;
1467
+ ce[Ke]?.();
1468
+ ce[Ke] = Ht(async ({ pages: t, components: e }) => {
1469
+ const s = await O.getProjectIds();
1496
1470
  f.info(`start update resource states projects(${s.length})`, s), await Promise.race([
1497
1471
  new Promise((a) => {
1498
1472
  setTimeout(() => {
@@ -1501,7 +1475,7 @@ ce[Je] = Ht(async ({ pages: t, components: e }) => {
1501
1475
  }),
1502
1476
  Promise.all(
1503
1477
  s.map(async (a) => {
1504
- qe({
1478
+ He({
1505
1479
  projectId: a,
1506
1480
  pages: t,
1507
1481
  components: e
@@ -1512,31 +1486,31 @@ ce[Je] = Ht(async ({ pages: t, components: e }) => {
1512
1486
  f.error("update resource states failed:", a);
1513
1487
  });
1514
1488
  });
1515
- ce[Ke]?.();
1516
- ce[Ke] = () => {
1489
+ ce[qe]?.();
1490
+ ce[qe] = () => {
1517
1491
  const t = () => {
1518
- C.pageUrlMapCache.clear(), f.info("[Cache CLEAR ALL] clear all page url map cache by env update");
1492
+ O.pageUrlMapCache.clear(), f.info("[Cache CLEAR ALL] clear all page url map cache by env update");
1519
1493
  };
1520
- return I.events.on(I.Events.envUpdate, t), () => {
1521
- I.events.off(I.Events.envUpdate, t);
1494
+ return b.events.on(b.Events.envUpdate, t), () => {
1495
+ b.events.off(b.Events.envUpdate, t);
1522
1496
  };
1523
1497
  };
1524
- C.startPeriodicCheck();
1498
+ O.startPeriodicCheck();
1525
1499
  process.on("beforeExit", () => {
1526
- C.stopPeriodicCheck();
1500
+ O.stopPeriodicCheck();
1527
1501
  });
1528
1502
  process.on("SIGINT", () => {
1529
- C.stopPeriodicCheck(), process.exit(0);
1503
+ O.stopPeriodicCheck(), process.exit(0);
1530
1504
  });
1531
1505
  process.on("SIGTERM", () => {
1532
- C.stopPeriodicCheck(), process.exit(0);
1506
+ O.stopPeriodicCheck(), process.exit(0);
1533
1507
  });
1534
- async function qe({
1508
+ async function He({
1535
1509
  projectId: t,
1536
1510
  pages: e,
1537
1511
  components: s
1538
1512
  }) {
1539
- const a = C.sharedInstances[t];
1513
+ const a = O.sharedInstances[t];
1540
1514
  if (!a) {
1541
1515
  f.info(`projectId: ${t} not found in sharedInstances`);
1542
1516
  return;
@@ -1544,10 +1518,10 @@ async function qe({
1544
1518
  if (a.syncedStore.resources.pages = e, (await M.findByPk(t))?.useAllResources)
1545
1519
  a.syncedStore.resources.components = s;
1546
1520
  else {
1547
- const i = (await we.findAll({ where: { projectId: t } })).map((l) => l.componentId), c = Object.fromEntries(
1548
- Object.entries(s || {}).filter(([l]) => i.includes(l))
1521
+ const c = (await we.findAll({ where: { projectId: t } })).map((p) => p.componentId), l = Object.fromEntries(
1522
+ Object.entries(s || {}).filter(([p]) => c.includes(p))
1549
1523
  );
1550
- a.syncedStore.resources.components = c;
1524
+ a.syncedStore.resources.components = l;
1551
1525
  }
1552
1526
  f.info(`update [${t}] resource states:`, {
1553
1527
  pages: Object.keys(a.syncedStore.resources.pages || {}).length,
@@ -1555,36 +1529,36 @@ async function qe({
1555
1529
  });
1556
1530
  }
1557
1531
  async function ks(t) {
1558
- return qe({
1532
+ return He({
1559
1533
  projectId: t,
1560
1534
  pages: ne,
1561
1535
  components: ie
1562
1536
  });
1563
1537
  }
1564
- async function Ts() {
1565
- f.info("trigger reload all project resource"), I.events.emit(he);
1538
+ async function Ds() {
1539
+ f.info("trigger reload all project resource"), b.events.emit(ge);
1566
1540
  }
1567
- async function Ds({
1541
+ async function Ts({
1568
1542
  ensureLoaded: t = !0
1569
1543
  } = {}) {
1570
- return t && (re ??= ze(), await re), { states: Q, pages: ne, components: ie };
1544
+ return t && (re ??= Je(), await re), { states: Q, pages: ne, components: ie };
1571
1545
  }
1572
1546
  export {
1573
- Fe as C,
1547
+ _e as C,
1574
1548
  M as P,
1575
- Te as R,
1576
- C as S,
1577
- q as a,
1578
- Os as b,
1579
- vs as c,
1549
+ De as R,
1550
+ O as S,
1551
+ K as a,
1552
+ vs as b,
1553
+ js as c,
1580
1554
  Gt as d,
1581
1555
  zt as e,
1582
1556
  Jt as f,
1583
- Ds as g,
1584
- Be as h,
1557
+ Ts as g,
1558
+ Ge as h,
1585
1559
  Ht as i,
1586
- Ts as j,
1587
- je as m,
1560
+ Ds as j,
1561
+ Le as m,
1588
1562
  Kt as t,
1589
1563
  ks as u
1590
1564
  };