@blocklet/pages-kit-inner-components 0.6.38 → 0.6.40

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,12 +1,12 @@
1
- import { d as $e, l as f, I as We, c as Qe, m as Xe, b as Ze } from "./components-BWQM8y6L.js";
1
+ import { d as $e, l as f, I as We, c as Qe, m as Xe, b as Ze } from "./components-6zI6vrkL.js";
2
2
  import { getYjsValue as V, syncedStore as et } from "@syncedstore/core";
3
3
  import * as N from "yjs";
4
4
  import { setPageDataSource as tt } from "@blocklet/pages-kit/utils/data-source";
5
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";
6
+ import { cloneDeep as ot } from "lodash";
7
+ import E from "@blocklet/sdk/lib/config";
8
+ import { mkdtempSync as at, 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 b, basename as R, dirname as L } from "path";
10
10
  import { nextId as Oe } from "@blocklet/pages-kit/utils/common";
11
11
  import { unzipSection as ct } from "@blocklet/pages-kit/utils/page-model";
12
12
  import { getComponentDependencies as pt } from "@blocklet/pages-kit/utils/property";
@@ -18,17 +18,17 @@ import * as D from "lib0/encoding";
18
18
  import mt from "lodash/cloneDeep";
19
19
  import Me from "lodash/debounce";
20
20
  import Ie from "lodash/get";
21
- import be from "lodash/isEmpty";
21
+ import Ee from "lodash/isEmpty";
22
22
  import ve from "lodash/set";
23
23
  import gt from "lodash/union";
24
- import { LRUCache as Ee } from "lru-cache";
24
+ import { LRUCache as be } from "lru-cache";
25
25
  import ht from "p-limit";
26
26
  import { DataTypes as k, Sequelize as yt, Model as Ne, Op as Fe } from "sequelize";
27
27
  import { pipeline as St } from "stream/promises";
28
28
  import { x as It } from "tar";
29
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";
30
+ import Et from "wait-on";
31
+ import { Awareness as bt, encodeAwarenessUpdate as je, removeAwarenessStates as wt, applyAwarenessUpdate as At } from "y-protocols/awareness";
32
32
  import { writeUpdate as Pt, writeSyncStep1 as Ct, readSyncMessage as Ot } from "y-protocols/sync";
33
33
  import * as G from "yaml";
34
34
  import { m as ke } from "./html-DfzaaIYa.js";
@@ -199,24 +199,24 @@ function se(t) {
199
199
  });
200
200
  }
201
201
  function xe() {
202
- return ot(E(b.env.dataDir, "tmp-"));
202
+ return at(b(E.env.dataDir, "tmp-"));
203
203
  }
204
- function ae(t, e, s = []) {
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] : [];
204
+ function oe(t, e, s = []) {
205
+ return Array.isArray(t) ? t.flatMap((o, a) => oe(o, e, [...s, a])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([o, a]) => oe(a, e, [...s, o])) : e(t) ? [s] : [];
206
206
  }
207
207
  function T(t) {
208
208
  return t.filter((e) => e != null);
209
209
  }
210
210
  function Tt(t) {
211
211
  t.pages && Object.keys(t.pages).forEach((s) => {
212
- const a = V(t.pages[s]);
213
- a && a instanceof N.Map && se(a);
212
+ const o = V(t.pages[s]);
213
+ o && o instanceof N.Map && se(o);
214
214
  });
215
215
  const e = V(t.pages);
216
216
  e && e instanceof N.Map && e.observe((s) => {
217
- s.changes.keys.forEach((a, o) => {
218
- if (a.action === "add") {
219
- const r = V(t.pages[o]);
217
+ s.changes.keys.forEach((o, a) => {
218
+ if (o.action === "add") {
219
+ const r = V(t.pages[a]);
220
220
  r && r instanceof N.Map && se(r);
221
221
  }
222
222
  });
@@ -224,14 +224,14 @@ function Tt(t) {
224
224
  }
225
225
  function Rt(t) {
226
226
  t.routes && Object.keys(t.routes).forEach((s) => {
227
- const a = V(t.routes?.[s]);
228
- a && a instanceof N.Map && se(a);
227
+ const o = V(t.routes?.[s]);
228
+ o && o instanceof N.Map && se(o);
229
229
  });
230
230
  const e = V(t.routes);
231
231
  e && e instanceof N.Map && e.observe((s) => {
232
- s.changes.keys.forEach((a, o) => {
233
- if (a.action === "add") {
234
- const r = V(t.routes?.[o]);
232
+ s.changes.keys.forEach((o, a) => {
233
+ if (o.action === "add") {
234
+ const r = V(t.routes?.[a]);
235
235
  r && r instanceof N.Map && se(r);
236
236
  }
237
237
  });
@@ -239,18 +239,18 @@ function Rt(t) {
239
239
  }
240
240
  function Lt(t, e) {
241
241
  for (const s of e || Object.keys(t.routes || {})) {
242
- let a = s, o = [];
242
+ let o = s, a = [];
243
243
  if (s.includes("-")) {
244
244
  const [r, ...c] = s.split("-");
245
- a = r, o = c || [];
245
+ o = r, a = c || [];
246
246
  }
247
- if (t.routes?.[a] !== void 0) {
248
- t.routes[a].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
249
- const r = t.routes[a];
247
+ if (t.routes?.[o] !== void 0) {
248
+ t.routes[o].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
249
+ const r = t.routes[o];
250
250
  if (!r || !r.params || r.params.length === 0)
251
251
  continue;
252
- if (s.includes("-") && o.length > 0) {
253
- const c = st(o, r);
252
+ if (s.includes("-") && a.length > 0) {
253
+ const c = st(a, r);
254
254
  c && (c.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
255
255
  }
256
256
  if (!e) {
@@ -274,50 +274,54 @@ function de({
274
274
  page: t,
275
275
  route: e,
276
276
  state: s,
277
- routeId: a,
278
- routePathInfo: o
277
+ routeId: o,
278
+ routePathInfo: a
279
279
  }) {
280
280
  f.info(
281
- `Executing datasource data assembly, routeId: ${a}, routePathInfo: ${JSON.stringify(o)}`
281
+ `Executing datasource data assembly, routeId: ${o}, routePathInfo: ${JSON.stringify(a)}`
282
282
  );
283
283
  const r = {
284
- ...at(t),
285
- id: a,
286
- slug: o?.path ?? e.path,
284
+ ...ot(t),
285
+ id: o,
286
+ slug: a?.path ?? e.path,
287
287
  createdAt: e.createdAt,
288
- updatedAt: o?.routeMetaData?.updatedAt ?? e.updatedAt,
289
- publishedAt: o?.routeMetaData?.publishedAt ?? e.publishedAt,
290
- isPublic: (o?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
288
+ updatedAt: a?.routeMetaData?.updatedAt ?? e.updatedAt,
289
+ publishedAt: a?.routeMetaData?.publishedAt ?? e.publishedAt,
290
+ isPublic: (a?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
291
291
  };
292
292
  for (const c of s.supportedLocales) {
293
293
  if (e.dataSource) {
294
294
  let l = e.id;
295
- o && (l = o.paramOptionIds.join("-"));
295
+ a && (l = a.paramOptionIds.join("-"));
296
296
  const p = e.dataSource.pathDataMappings?.[l]?.dataCache?.[c.locale] ?? e.dataSource.pathDataMappings?.[l]?.dataCache?.[s.config.defaultLocale || "en"];
297
297
  if (!p)
298
298
  continue;
299
299
  tt(r, s, c.locale, p);
300
300
  }
301
- o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
301
+ a && a.routeMetaData && (a.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
302
302
  }
303
303
  return r;
304
304
  }
305
- const $t = 30 * 60 * 1e3, Y = new Ee({
305
+ ["true", "1", "yes", "y"].includes(process.env.USE_FS_CACHE_HTML ?? "");
306
+ const $t = 60 * 60 * 1e3, Y = new be({
306
307
  max: 100,
307
- ttl: $t
308
+ ttl: $t,
309
+ ttlResolution: 10 * 1e3,
310
+ // 10 seconds
311
+ allowStale: !0
308
312
  });
309
313
  function Ut(t, e = []) {
310
314
  let s = 0;
311
- const a = Array.from(Y.keys());
312
- for (const o of a)
315
+ const o = Array.from(Y.keys());
316
+ for (const a of o)
313
317
  for (const r of t) {
314
- if (ke(o, { currentPath: r })) {
315
- Y.delete(o), s++, f.info(`[Cache CLEAR] key: ${o}`);
318
+ if (ke(a, { currentPath: r })) {
319
+ Y.delete(a), s++, f.info(`[Cache CLEAR] key: ${a}`);
316
320
  break;
317
321
  }
318
322
  for (const c of e)
319
- if (ke(o, { currentPath: `/${c}${r}` })) {
320
- Y.delete(o), s++, f.info(`[Cache CLEAR] key: ${o}`);
323
+ if (ke(a, { currentPath: `/${c}${r}` })) {
324
+ Y.delete(a), s++, f.info(`[Cache CLEAR] key: ${a}`);
321
325
  break;
322
326
  }
323
327
  }
@@ -327,9 +331,9 @@ function Mt() {
327
331
  const t = Y.size;
328
332
  return Y.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
329
333
  }
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"];
332
- function oe(t) {
334
+ E.events.on(E.Events.envUpdate, Mt);
335
+ 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 = E, K = b(process.env.BLOCKLET_DATA_DIR, "site-state"), vs = ["production", "draft"], js = ["production"];
336
+ function ae(t) {
333
337
  return t?.replace(/\//g, "|") || "";
334
338
  }
335
339
  function Gt() {
@@ -365,7 +369,7 @@ class O extends N.Doc {
365
369
  },
366
370
  this
367
371
  )
368
- ), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new Et(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
372
+ ), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new bt(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
369
373
  }
370
374
  // 延迟释放时间:5 分钟
371
375
  static RELEASE_DELAY = 5 * 60 * 1e3;
@@ -373,7 +377,7 @@ class O extends N.Doc {
373
377
  static PERIODIC_CHECK_INTERVAL = 2 * 60 * 60 * 1e3;
374
378
  // 2 hours
375
379
  static sharedInstances = {};
376
- static pageUrlMapCache = new Ee({
380
+ static pageUrlMapCache = new be({
377
381
  max: 100,
378
382
  ttl: 1e3 * 60 * 60 * 24
379
383
  // 1 day
@@ -385,8 +389,8 @@ class O extends N.Doc {
385
389
  if (!e)
386
390
  throw new Error("Should provide project context");
387
391
  try {
388
- const s = E(K, e), a = E(K, `@del-${e}`);
389
- Ce(s, a);
392
+ const s = b(K, e), o = b(K, `@del-${e}`);
393
+ Ce(s, o);
390
394
  } catch (s) {
391
395
  f.error("Failed to safe delete project state dir:", s);
392
396
  }
@@ -411,7 +415,7 @@ class O extends N.Doc {
411
415
  throw new Error("Should provide project context");
412
416
  let s = O.sharedInstances[e];
413
417
  return s || (s = new O({
414
- path: E(K, e)
418
+ path: b(K, e)
415
419
  }), O.sharedInstances[e] = s, s);
416
420
  }
417
421
  // 轻量级 production 状态获取,不加载 draft 数据
@@ -419,19 +423,19 @@ class O extends N.Doc {
419
423
  const s = await M.findByPk(e, {
420
424
  attributes: ["productionState"]
421
425
  });
422
- if (be(s?.productionState)) {
423
- const a = E(K, e, "production"), o = await Ge(a, { includeResources: !0 }) ?? Gt();
424
- if (!o?.config?.defaultLocale) {
425
- o.config ??= {};
426
+ if (Ee(s?.productionState)) {
427
+ const o = b(K, e, "production"), a = await Ge(o, { includeResources: !0 }) ?? Gt();
428
+ if (!a?.config?.defaultLocale) {
429
+ a.config ??= {};
426
430
  const r = he.env.languages?.map((c) => ({ locale: c.code, name: c.name })) || [];
427
- o.config.defaultLocale = r[0]?.locale;
431
+ a.config.defaultLocale = r[0]?.locale;
428
432
  }
429
- return o;
433
+ return a;
430
434
  }
431
435
  return s?.productionState;
432
436
  }
433
437
  destroy() {
434
- this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, a) => this.closeConn(a)), this.awareness.destroy();
438
+ this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, o) => this.closeConn(o)), this.awareness.destroy();
435
439
  const e = R(this.options.path);
436
440
  delete O.sharedInstances[e], super.destroy();
437
441
  }
@@ -439,12 +443,12 @@ class O extends N.Doc {
439
443
  Tt(this.syncedStore), Rt(this.syncedStore);
440
444
  }
441
445
  get draftYjsFilePath() {
442
- return E(this.options.path, "draft.yjs");
446
+ return b(this.options.path, "draft.yjs");
443
447
  }
444
448
  static async getStateByProjectId(e, s) {
445
449
  if (s === "draft") {
446
- const a = O.shared(e);
447
- return JSON.parse(JSON.stringify(a.syncedStore));
450
+ const o = O.shared(e);
451
+ return JSON.parse(JSON.stringify(o.syncedStore));
448
452
  }
449
453
  return O.getProductionState(e);
450
454
  }
@@ -455,27 +459,27 @@ class O extends N.Doc {
455
459
  return O.getProductionState(s);
456
460
  }
457
461
  async setState(e, s) {
458
- const a = await Kt(s, { exportAssets: !1, includeResources: !0 }), o = this.getPublishDir(e);
459
- if (_(L(o), { recursive: !0 }), Ue(o, { force: !0, recursive: !0 }), Ce(a, o), e === "production") {
462
+ const o = await Kt(s, { exportAssets: !1, includeResources: !0 }), a = this.getPublishDir(e);
463
+ if (_(L(a), { recursive: !0 }), Ue(a, { force: !0, recursive: !0 }), Ce(o, a), e === "production") {
460
464
  const r = R(this.options.path);
461
465
  O.pageUrlMapCache.delete(r), await M.update({ productionState: { ...s } }, { where: { id: r } });
462
466
  }
463
467
  }
464
468
  getPublishDir(e) {
465
- return E(this.options.path, e);
469
+ return b(this.options.path, e);
466
470
  }
467
471
  syncedStore;
468
472
  conns = /* @__PURE__ */ new Map();
469
473
  awareness;
470
474
  // 延迟释放定时器
471
475
  releaseTimer;
472
- awarenessChangeHandler = ({ added: e, updated: s, removed: a }, o) => {
473
- const r = e.concat(s, a);
474
- if (o !== null) {
475
- const p = this.conns.get(o);
476
+ awarenessChangeHandler = ({ added: e, updated: s, removed: o }, a) => {
477
+ const r = e.concat(s, o);
478
+ if (a !== null) {
479
+ const p = this.conns.get(a);
476
480
  p && (e.forEach((y) => {
477
481
  p.add(y);
478
- }), a.forEach((y) => {
482
+ }), o.forEach((y) => {
479
483
  p.delete(y);
480
484
  }));
481
485
  }
@@ -487,17 +491,17 @@ class O extends N.Doc {
487
491
  updateHandler = (e) => {
488
492
  const s = D.createEncoder();
489
493
  D.writeVarUint(s, X), Pt(s, e);
490
- const a = D.toUint8Array(s);
491
- this.conns.forEach((o, r) => this.send(r, a));
494
+ const o = D.toUint8Array(s);
495
+ this.conns.forEach((a, r) => this.send(r, o));
492
496
  };
493
497
  ensureDataStructure = () => {
494
- const { supportedLocales: e, pages: s, pageIds: a, config: o, routes: r, routeIds: c } = this.syncedStore;
498
+ const { supportedLocales: e, pages: s, pageIds: o, config: a, routes: r, routeIds: c } = this.syncedStore;
495
499
  {
496
500
  const l = new Set(Object.keys(s));
497
501
  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);
502
+ for (; p < o.length; ) {
503
+ const y = o[p];
504
+ l.has(y) ? (l.delete(y), p++) : o.splice(p, 1);
501
505
  }
502
506
  }
503
507
  {
@@ -508,7 +512,7 @@ class O extends N.Doc {
508
512
  l.has(y) ? (l.delete(y), p++) : c.splice(p, 1);
509
513
  }
510
514
  }
511
- e.splice(0, e.length), e.push(...he.env.languages.map((l) => ({ locale: l.code, name: l.name }))), o.defaultLocale = e[0]?.locale;
515
+ e.splice(0, e.length), e.push(...he.env.languages.map((l) => ({ locale: l.code, name: l.name }))), a.defaultLocale = e[0]?.locale;
512
516
  {
513
517
  let l = 0;
514
518
  const p = /* @__PURE__ */ new Set();
@@ -521,8 +525,8 @@ class O extends N.Doc {
521
525
  send = (e, s) => {
522
526
  e.readyState !== xt && e.readyState !== Bt && this.closeConn(e);
523
527
  try {
524
- e.send(s, (a) => {
525
- a && this.closeConn(e);
528
+ e.send(s, (o) => {
529
+ o && this.closeConn(e);
526
530
  });
527
531
  } catch {
528
532
  this.closeConn(e);
@@ -562,14 +566,14 @@ class O extends N.Doc {
562
566
  this.autoSave(), e && this.autoSave.flush();
563
567
  };
564
568
  publish = async ({ mode: e, routes: s }) => {
565
- const a = await this.getState("draft"), o = await this.getState("production");
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);
569
+ const o = await this.getState("draft"), a = await this.getState("production");
570
+ await Le(o, a, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), a.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Lt(this.syncedStore, s), await this.setState(e, a), await this.clearPageCacheForRoutes(s, a);
567
571
  };
568
572
  mergeState = async (e, s) => {
569
- const a = JSON.parse(JSON.stringify(s));
573
+ const o = JSON.parse(JSON.stringify(s));
570
574
  e.config.fontFamily ??= {};
571
- const o = a.config?.fontFamily, r = e.config?.fontFamily;
572
- e.config.fontFamily.title = o?.title || r?.title, e.config.fontFamily.description = o?.description || r?.description, await new Promise((c, l) => {
575
+ const a = o.config?.fontFamily, r = e.config?.fontFamily;
576
+ e.config.fontFamily.title = a?.title || r?.title, e.config.fontFamily.description = a?.description || r?.description, await new Promise((c, l) => {
573
577
  this.transact(async () => {
574
578
  try {
575
579
  const p = await Le(e, s);
@@ -581,46 +585,46 @@ class O extends N.Doc {
581
585
  });
582
586
  };
583
587
  clearPageCacheForRoutes = async (e, s) => {
584
- const a = R(this.options.path), r = (await M.findByPk(a))?.slug || a;
588
+ const o = R(this.options.path), r = (await M.findByPk(o))?.slug || o;
585
589
  let c = e;
586
- (!c || c.length === 0) && (c = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${a}, routes:`, c || []);
590
+ (!c || c.length === 0) && (c = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${o}, routes:`, c || []);
587
591
  const l = s.supportedLocales.map((w) => w.locale), p = [], y = c.filter((w) => s.pageIds?.includes(w));
588
592
  for (const w of y) {
589
593
  const I = s.pages[w].slug;
590
- r && r !== a && (r === "/" ? p.push(I) : p.push(`/${r}${I}`)), p.push(`/${a}${I}`);
594
+ r && r !== o && (r === "/" ? p.push(I) : p.push(`/${r}${I}`)), p.push(`/${o}${I}`);
591
595
  }
592
- if (f.info(`[SiteState] clearing page cache for project ${a}, pathPatterns:`, p), p.length > 0)
596
+ if (f.info(`[SiteState] clearing page cache for project ${o}, pathPatterns:`, p), p.length > 0)
593
597
  try {
594
598
  const w = Ut(p, l);
595
- f.info(`[SiteState] cleared ${w} page cache entries for project ${a}, routes:`, c);
599
+ f.info(`[SiteState] cleared ${w} page cache entries for project ${o}, routes:`, c);
596
600
  } catch {
597
601
  }
598
602
  };
599
603
  addConnection = (e) => {
600
604
  if (this.conns.has(e))
601
605
  return;
602
- this.cancelRelease(), e.binaryType = "arraybuffer", this.conns.set(e, /* @__PURE__ */ new Set()), e.on("message", (o) => this.messageListener(e, new Uint8Array(o)));
606
+ this.cancelRelease(), e.binaryType = "arraybuffer", this.conns.set(e, /* @__PURE__ */ new Set()), e.on("message", (a) => this.messageListener(e, new Uint8Array(a)));
603
607
  let s = !0;
604
- const a = setInterval(() => {
608
+ const o = setInterval(() => {
605
609
  if (!s)
606
- this.conns.has(e) && this.closeConn(e), clearInterval(a);
610
+ this.conns.has(e) && this.closeConn(e), clearInterval(o);
607
611
  else if (this.conns.has(e)) {
608
612
  s = !1;
609
613
  try {
610
614
  e.ping();
611
615
  } catch {
612
- this.closeConn(e), clearInterval(a);
616
+ this.closeConn(e), clearInterval(o);
613
617
  }
614
618
  }
615
619
  }, _t);
616
620
  e.on("close", () => {
617
- this.closeConn(e), clearInterval(a);
621
+ this.closeConn(e), clearInterval(o);
618
622
  }), e.on("pong", () => {
619
623
  s = !0;
620
624
  });
621
625
  {
622
- const o = D.createEncoder();
623
- D.writeVarUint(o, X), Ct(o, this), this.send(e, D.toUint8Array(o));
626
+ const a = D.createEncoder();
627
+ D.writeVarUint(a, X), Ct(a, this), this.send(e, D.toUint8Array(a));
624
628
  const r = this.awareness.getStates();
625
629
  if (r.size > 0) {
626
630
  const c = D.createEncoder();
@@ -630,48 +634,48 @@ class O extends N.Doc {
630
634
  };
631
635
  messageListener = (e, s) => {
632
636
  try {
633
- const a = D.createEncoder(), o = ue.createDecoder(s), r = ue.readVarUint(o);
637
+ const o = D.createEncoder(), a = ue.createDecoder(s), r = ue.readVarUint(a);
634
638
  switch (r) {
635
639
  case X:
636
- D.writeVarUint(a, X), Ot(o, a, this, null), D.length(a) > 1 && (this.ensureDataStructure(), this.send(e, D.toUint8Array(a)));
640
+ D.writeVarUint(o, X), Ot(a, o, this, null), D.length(o) > 1 && (this.ensureDataStructure(), this.send(e, D.toUint8Array(o)));
637
641
  break;
638
642
  case fe: {
639
- At(this.awareness, ue.readVarUint8Array(o), e);
643
+ At(this.awareness, ue.readVarUint8Array(a), e);
640
644
  break;
641
645
  }
642
646
  default:
643
647
  f.warn(`Unsupported messageType ${r}`);
644
648
  }
645
- } catch (a) {
646
- f.error(a);
649
+ } catch (o) {
650
+ f.error(o);
647
651
  }
648
652
  this.save();
649
653
  };
650
654
  // 这个方法还是需要动态的,因为可能会动态修改 projectSlug、语言之类的
651
655
  static async pageUrlMap(e, s) {
652
- let a = [];
653
- s ? a = [s] : a = await this.getProjectIds();
654
- let o = {};
655
- if (e === "production" && a?.length) {
656
- const r = new Map(a?.map((c) => [c, !0]) || []);
657
- for (const c of a) {
656
+ let o = [];
657
+ s ? o = [s] : o = await this.getProjectIds();
658
+ let a = {};
659
+ if (e === "production" && o?.length) {
660
+ const r = new Map(o?.map((c) => [c, !0]) || []);
661
+ for (const c of o) {
658
662
  const l = O.pageUrlMapCache.get(c);
659
- l && (o = { ...o, ...l }, r.delete(c));
663
+ l && (a = { ...a, ...l }, r.delete(c));
660
664
  }
661
- a = Array.from(r.keys());
665
+ o = Array.from(r.keys());
662
666
  }
663
- if (a?.length) {
667
+ if (o?.length) {
664
668
  const r = await M.findAll({
665
669
  where: {
666
670
  id: {
667
- [Fe.in]: a
671
+ [Fe.in]: o
668
672
  }
669
673
  }
670
674
  });
671
675
  await Promise.all(
672
676
  r?.map(async (c) => {
673
677
  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) || [],
678
+ E.env.languages?.map((u) => u.code) || [],
675
679
  w.supportedLocales?.map((u) => u.locale) || []
676
680
  ), I = (u, i) => {
677
681
  p && (y[H("/", p, u)] = {
@@ -751,24 +755,24 @@ class O extends N.Doc {
751
755
  };
752
756
  I(g, m);
753
757
  }
754
- e === "production" && O.pageUrlMapCache.set(l, y), o = { ...o, ...y };
758
+ e === "production" && O.pageUrlMapCache.set(l, y), a = { ...a, ...y };
755
759
  })
756
760
  );
757
761
  }
758
- return o;
762
+ return a;
759
763
  }
760
764
  getDocumentSize() {
761
765
  return N.encodeStateAsUpdate(this).byteLength;
762
766
  }
763
767
  static getInstancesSizeInfo() {
764
768
  const e = [];
765
- for (const [s, a] of Object.entries(O.sharedInstances)) {
766
- const o = a.getDocumentSize();
769
+ for (const [s, o] of Object.entries(O.sharedInstances)) {
770
+ const a = o.getDocumentSize();
767
771
  e.push({
768
772
  projectId: s,
769
- sizeInBytes: o,
770
- sizeInMB: `${(o / (1024 * 1024)).toFixed(2)} MB`,
771
- activeConnections: a.conns.size
773
+ sizeInBytes: a,
774
+ sizeInMB: `${(a / (1024 * 1024)).toFixed(2)} MB`,
775
+ activeConnections: o.conns.size
772
776
  });
773
777
  }
774
778
  return e;
@@ -787,25 +791,25 @@ class O extends N.Doc {
787
791
  }
788
792
  // 执行定期检查
789
793
  static performPeriodicCheck() {
790
- const e = Object.keys(O.sharedInstances).length, s = [], a = [];
791
- for (const [o, r] of Object.entries(O.sharedInstances))
792
- r.conns.size === 0 ? s.push({ projectId: o, instance: r }) : a.push({ projectId: o, connections: r.conns.size });
794
+ const e = Object.keys(O.sharedInstances).length, s = [], o = [];
795
+ for (const [a, r] of Object.entries(O.sharedInstances))
796
+ r.conns.size === 0 ? s.push({ projectId: a, instance: r }) : o.push({ projectId: a, connections: r.conns.size });
793
797
  if (f.info(
794
- `[SiteState] periodic check summary: total instances: ${e}, with connections: ${a.length}, without connections: ${s.length}`
798
+ `[SiteState] periodic check summary: total instances: ${e}, with connections: ${o.length}, without connections: ${s.length}`
795
799
  ), s.length > 0) {
796
800
  f.info(
797
801
  `[SiteState] releasing ${s.length} instances without connections:`,
798
802
  s.map((r) => r.projectId)
799
803
  );
800
- let o = 0;
804
+ let a = 0;
801
805
  for (const { projectId: r, instance: c } of s)
802
806
  try {
803
- f.info(`[SiteState] releasing instance due to periodic check: ${r}`), c.destroy(), o++;
807
+ f.info(`[SiteState] releasing instance due to periodic check: ${r}`), c.destroy(), a++;
804
808
  } catch (l) {
805
809
  f.error(`[SiteState] failed to release instance ${r} during periodic check:`, l);
806
810
  }
807
811
  f.info(
808
- `[SiteState] periodic check completed: ${o}/${s.length} instances released successfully`
812
+ `[SiteState] periodic check completed: ${a}/${s.length} instances released successfully`
809
813
  );
810
814
  } else e > 0 ? f.debug("[SiteState] periodic check: all instances have active connections") : f.debug("[SiteState] periodic check: no instances exist");
811
815
  }
@@ -813,37 +817,37 @@ class O extends N.Doc {
813
817
  async function Vt(t, e, s) {
814
818
  if (!t || !U(t) || !B(t).isFile())
815
819
  return null;
816
- let a = s[t];
817
- return a || (a = (async () => {
820
+ let o = s[t];
821
+ return o || (o = (async () => {
818
822
  try {
819
823
  return (await Nt({
820
824
  filePath: t,
821
825
  fileName: e
822
826
  }))?.data?.filename;
823
- } catch (o) {
824
- return f.error(`Failed to upload asset ${t}:`, o), null;
827
+ } catch (a) {
828
+ return f.error(`Failed to upload asset ${t}:`, a), null;
825
829
  }
826
- })(), s[t] = a), a;
830
+ })(), s[t] = o), o;
827
831
  }
828
832
  const zt = async (t, e) => {
829
- const s = R(t), a = await dt({
833
+ const s = R(t), o = await dt({
830
834
  name: _e,
831
835
  path: H("/uploads", s),
832
836
  responseType: "stream",
833
837
  method: "GET"
834
838
  });
835
- if (a.status >= 200 && a.status < 400) {
836
- const o = it(e);
837
- await St(a.data, o);
839
+ if (o.status >= 200 && o.status < 400) {
840
+ const a = it(e);
841
+ await St(o.data, a);
838
842
  } else
839
- throw new Error(`download asset failed ${a.status}`);
843
+ throw new Error(`download asset failed ${o.status}`);
840
844
  }, Jt = async (t, e) => {
841
845
  await Promise.all(
842
846
  t.map(async (s) => {
843
847
  try {
844
- await zt(s, E(e, R(s)));
845
- } catch (a) {
846
- f.error(`Failed to export assets: ${s}, ${a}`);
848
+ await zt(s, b(e, R(s)));
849
+ } catch (o) {
850
+ f.error(`Failed to export assets: ${s}, ${o}`);
847
851
  }
848
852
  })
849
853
  );
@@ -852,9 +856,9 @@ function Be(t) {
852
856
  return Ae.test(t) ? [t] : W.test(t) ? (Te.lastIndex = 0, Array.from(t.matchAll(Te)).map((s) => s[1]).filter((s) => !!s)) : [];
853
857
  }
854
858
  async function Z(t, e, s) {
855
- const { getFilename: a, exportAssets: o } = s, r = E(e, a(t));
856
- if (_(L(r), { recursive: !0 }), ee(r, G.stringify(t)), o) {
857
- const l = ae(
859
+ const { getFilename: o, exportAssets: a } = s, r = b(e, o(t));
860
+ if (_(L(r), { recursive: !0 }), ee(r, G.stringify(t)), a) {
861
+ const l = oe(
858
862
  t,
859
863
  (p) => typeof p == "string" && (Ae.test(p) || W.test(p))
860
864
  ).map((p) => {
@@ -864,17 +868,17 @@ async function Z(t, e, s) {
864
868
  await Jt(l, L(r));
865
869
  }
866
870
  }
867
- const ye = new Ee({
871
+ const ye = new be({
868
872
  max: 100,
869
873
  ttl: 1 * 60 * 1e3
870
874
  // 1 minute
871
875
  });
872
876
  async function Re(t, e, s) {
873
- const a = ae(
877
+ const o = oe(
874
878
  t,
875
879
  (l) => typeof l == "string" && (Ae.test(l) || W.test(l))
876
- ), o = ht(2), r = a.map(
877
- (l) => o(async () => {
880
+ ), a = ht(2), r = o.map(
881
+ (l) => a(async () => {
878
882
  try {
879
883
  const p = Ie(t, l), y = Be(p);
880
884
  for (const w of y) {
@@ -896,15 +900,15 @@ async function Re(t, e, s) {
896
900
  async function Kt(t, {
897
901
  exportAssets: e,
898
902
  pageIds: s = "all",
899
- componentIds: a = "all",
900
- rawConfig: o,
903
+ componentIds: o = "all",
904
+ rawConfig: a,
901
905
  includeResources: r = !1,
902
906
  routeIds: c = "all"
903
907
  } = {}) {
904
908
  const l = s === "all" ? t.pageIds : s, p = pt({
905
909
  state: t,
906
910
  pageIds: l,
907
- componentIds: a === "all" ? Object.keys(t.components) : a
911
+ componentIds: o === "all" ? Object.keys(t.components) : o
908
912
  }), y = c === "all" ? t.routeIds : c, w = (n) => ({
909
913
  id: n.id,
910
914
  name: n.name,
@@ -968,21 +972,21 @@ async function Kt(t, {
968
972
  };
969
973
  })
970
974
  )
971
- ), g = xe(), C = E(g, "pages");
975
+ ), g = xe(), C = b(g, "pages");
972
976
  _(C, { recursive: !0 });
973
- const m = E(g, "components");
977
+ const m = b(g, "components");
974
978
  _(m, { recursive: !0 });
975
- const d = E(g, "routes");
979
+ const d = b(g, "routes");
976
980
  _(d, { recursive: !0 });
977
981
  for (const { locale: n, slug: S, page: v } of i)
978
982
  await Z(v, C, {
979
- getFilename: () => `${oe(S) || "index"}.${n}.yml`,
983
+ getFilename: () => `${ae(S) || "index"}.${n}.yml`,
980
984
  exportAssets: e
981
985
  });
982
986
  for (const n of u)
983
987
  await Z(n, d, {
984
988
  // getFilename: () => `${sanitizeSlug(route.path)}.yml`,
985
- getFilename: () => `${oe(n.path) || "index"}.yml`,
989
+ getFilename: () => `${ae(n.path) || "index"}.yml`,
986
990
  exportAssets: e
987
991
  });
988
992
  for (const n of p) {
@@ -992,7 +996,7 @@ async function Kt(t, {
992
996
  exportAssets: e
993
997
  });
994
998
  }
995
- const h = E(g, ".blocklet/pages/pages.config.yml");
999
+ const h = b(g, ".blocklet/pages/pages.config.yml");
996
1000
  _(L(h), { recursive: !0 });
997
1001
  const A = {
998
1002
  pages: T(
@@ -1030,9 +1034,9 @@ async function Kt(t, {
1030
1034
  config: t.config
1031
1035
  };
1032
1036
  ee(h, G.stringify(A));
1033
- const P = E(g, "config.source.json");
1034
- if (o && ee(P, JSON.stringify(o)), r) {
1035
- const n = E(g, "resources"), S = E(n, "components");
1037
+ const P = b(g, "config.source.json");
1038
+ if (a && ee(P, JSON.stringify(a)), r) {
1039
+ const n = b(g, "resources"), S = b(n, "components");
1036
1040
  _(S, { recursive: !0 });
1037
1041
  for (const z of Object.keys(t?.resources?.components ?? {}).filter(
1038
1042
  ($) => p.includes($)
@@ -1043,7 +1047,7 @@ async function Kt(t, {
1043
1047
  exportAssets: e
1044
1048
  });
1045
1049
  }
1046
- const v = E(g, "chunks");
1050
+ const v = b(g, "chunks");
1047
1051
  _(v, { recursive: !0 });
1048
1052
  const x = qt();
1049
1053
  for (const z of Object.keys(t?.resources?.components ?? {}).filter(
@@ -1054,7 +1058,7 @@ async function Kt(t, {
1054
1058
  const J = $.renderer?.chunks ?? [];
1055
1059
  if (J?.length > 0)
1056
1060
  for (const pe of J) {
1057
- const Pe = E(v, pe), le = x?.[pe];
1061
+ const Pe = b(v, pe), le = x?.[pe];
1058
1062
  try {
1059
1063
  le && U(le) && !U(Pe) && rt(le, Pe);
1060
1064
  } catch (Ye) {
@@ -1069,15 +1073,15 @@ async function Kt(t, {
1069
1073
  async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1070
1074
  if (!U(t))
1071
1075
  return null;
1072
- let a, o = !1;
1076
+ let o, a = !1;
1073
1077
  try {
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");
1078
+ B(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o = xe(), await It({ file: t, C: o }));
1079
+ const r = te("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), c = r && b(L(r), "../../pages"), l = r && b(L(r), "../../components"), p = r && b(L(r), "../../routes");
1076
1080
  if (!r)
1077
1081
  return null;
1078
1082
  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());
1083
+ let A = b(m, `${d}${h ? `.${h}` : ""}.yml`);
1084
+ return (!U(A) || !B(A).isFile()) && (A = b(m, d, `index${h ? `.${h}` : ""}.yml`), !U(A) || !B(A)) ? null : G.parse(q(A).toString());
1081
1085
  }, j = (m, d) => {
1082
1086
  try {
1083
1087
  const h = te(`*.${d}.yml`, { cwd: m, absolute: !0 })[0];
@@ -1087,13 +1091,13 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1087
1091
  }
1088
1092
  return null;
1089
1093
  }, 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());
1094
+ let h = b(m, `${d}.yml`);
1095
+ return (!U(h) || !B(h).isFile()) && (h = b(m, d, "index.yml"), !U(h) || !B(h)) ? null : G.parse(q(h).toString());
1092
1096
  }, u = T(
1093
1097
  y.pages.map(({ slug: m }) => {
1094
1098
  const d = T(
1095
1099
  y.supportedLocales.map(({ locale: P }) => {
1096
- const n = c ? w(c, oe(m), P) : void 0;
1100
+ const n = c ? w(c, ae(m), P) : void 0;
1097
1101
  if (n)
1098
1102
  return { locale: P, page: n };
1099
1103
  const S = c ? w(c, m, P) : void 0;
@@ -1144,7 +1148,7 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1144
1148
  })
1145
1149
  ), i = T(
1146
1150
  y?.routes?.map(({ path: m }) => {
1147
- const d = p ? I(p, oe(m)) : void 0;
1151
+ const d = p ? I(p, ae(m)) : void 0;
1148
1152
  return {
1149
1153
  ...d,
1150
1154
  id: d?.id || Oe(),
@@ -1163,17 +1167,17 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1163
1167
  ), g = l ? T(y.components?.map(({ id: m }) => j(l, m)) ?? []) : [];
1164
1168
  if (e) {
1165
1169
  const m = (...d) => {
1166
- f.info(`[${o ? R(t) : R(E(t, "../../../../"))}] importAssets:`, ...d);
1170
+ f.info(`[${a ? R(t) : R(b(t, "../../../../"))}] importAssets:`, ...d);
1167
1171
  };
1168
1172
  try {
1169
- m("wait image-bin api ready"), await bt({
1173
+ m("wait image-bin api ready"), await Et({
1170
1174
  resources: [`${lt(We)}/api/sdk/uploads`],
1171
1175
  validateStatus: (A) => A >= 200 && A <= 500
1172
1176
  }), m("image-bin api is ready");
1173
1177
  const d = {}, h = {};
1174
1178
  m("start to upload assets"), await Promise.allSettled([
1175
1179
  Re(g, d, {
1176
- getFilePath: (A) => l && E(l, A),
1180
+ getFilePath: (A) => l && b(l, A),
1177
1181
  onFinish: (A) => {
1178
1182
  m(`upload ${A.length} component assets`);
1179
1183
  }
@@ -1181,7 +1185,7 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1181
1185
  Re(u, h, {
1182
1186
  getFilePath: (A, P) => {
1183
1187
  const n = Ie(u, P.slice(0, 1));
1184
- return c && E(c, L(n.slug), A);
1188
+ return c && b(c, L(n.slug), A);
1185
1189
  },
1186
1190
  onFinish: (A) => {
1187
1191
  m(`upload ${A.length} page assets`);
@@ -1194,7 +1198,7 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1194
1198
  }
1195
1199
  const C = {};
1196
1200
  if (s) {
1197
- const m = r && E(L(r), "../../resources/components"), d = T(
1201
+ const m = r && b(L(r), "../../resources/components"), d = T(
1198
1202
  y.resources?.components?.map(({ id: h }) => j(m, h)) ?? []
1199
1203
  );
1200
1204
  d.length > 0 && (C.components = Object.fromEntries(
@@ -1214,13 +1218,13 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1214
1218
  dataSources: {}
1215
1219
  };
1216
1220
  } finally {
1217
- o && a && Ue(a, { force: !0, recursive: !0 });
1221
+ a && o && Ue(o, { force: !0, recursive: !0 });
1218
1222
  }
1219
1223
  }
1220
1224
  async function Le(t, e, {
1221
1225
  routes: s,
1222
- mergeMode: a = "byUpdateTime",
1223
- deleteRoutes: o = !1,
1226
+ mergeMode: o = "byUpdateTime",
1227
+ deleteRoutes: a = !1,
1224
1228
  publishMode: r = void 0
1225
1229
  } = {}) {
1226
1230
  try {
@@ -1257,7 +1261,7 @@ async function Le(t, e, {
1257
1261
  const C = y?.[g];
1258
1262
  if (!C) {
1259
1263
  const d = e.pageIds.indexOf(g);
1260
- d !== -1 && o && (e.pageIds.splice(d, 1), delete e.pages[g]);
1264
+ d !== -1 && a && (e.pageIds.splice(d, 1), delete e.pages[g]);
1261
1265
  for (const h of e.pageIds)
1262
1266
  h.includes(`${g}-`) && (e.pageIds.splice(e.pageIds.indexOf(h), 1), delete e.pages[h]);
1263
1267
  f.info("delete main route page", g);
@@ -1265,7 +1269,7 @@ async function Le(t, e, {
1265
1269
  }
1266
1270
  if (i.includes("-") && !u?.[i]) {
1267
1271
  const d = e.pageIds.indexOf(i);
1268
- d !== -1 && o && (e.pageIds.splice(d, 1), delete e.pages[i]), f.info("delete page", i);
1272
+ d !== -1 && a && (e.pageIds.splice(d, 1), delete e.pages[i]), f.info("delete page", i);
1269
1273
  continue;
1270
1274
  }
1271
1275
  if (!C.displayTemplateId) {
@@ -1278,7 +1282,7 @@ async function Le(t, e, {
1278
1282
  continue;
1279
1283
  }
1280
1284
  if (e.pageIds.includes(i)) {
1281
- if (f.info("has need update page", i), a === "replace")
1285
+ if (f.info("has need update page", i), o === "replace")
1282
1286
  e.pages[i] = de({
1283
1287
  page: m,
1284
1288
  route: C,
@@ -1286,7 +1290,7 @@ async function Le(t, e, {
1286
1290
  routeId: i,
1287
1291
  routePathInfo: u?.[i]
1288
1292
  }), f.info("replace page", i);
1289
- else if (a === "byUpdateTime") {
1293
+ else if (o === "byUpdateTime") {
1290
1294
  const d = e.pages[C.id];
1291
1295
  (!d || C.updatedAt && C.updatedAt > d.updatedAt) && (e.pages[i] = de({
1292
1296
  page: m,
@@ -1305,7 +1309,7 @@ async function Le(t, e, {
1305
1309
  routePathInfo: u?.[i]
1306
1310
  }), f.info("add page", i);
1307
1311
  }
1308
- if (o && !s)
1312
+ if (a && !s)
1309
1313
  for (const i of e.pageIds)
1310
1314
  I?.includes(i) || (delete e.pages[i], f.info("delete page", i)), e.pageIds = [...e.pageIds].filter((g) => I?.includes(g));
1311
1315
  } else {
@@ -1313,9 +1317,9 @@ async function Le(t, e, {
1313
1317
  const u = c[I];
1314
1318
  if (u)
1315
1319
  if (e.pageIds.includes(u.id)) {
1316
- if (a === "replace")
1320
+ if (o === "replace")
1317
1321
  e.pages[u.id] = u;
1318
- else if (a === "byUpdateTime") {
1322
+ else if (o === "byUpdateTime") {
1319
1323
  const i = e.pages[u.id];
1320
1324
  (!i || u.updatedAt && u.updatedAt > i.updatedAt) && (e.pages[u.id] = u);
1321
1325
  }
@@ -1326,9 +1330,9 @@ async function Le(t, e, {
1326
1330
  const u = y[I];
1327
1331
  if (u)
1328
1332
  if (e.routeIds.includes(u.id)) {
1329
- if (a === "replace")
1333
+ if (o === "replace")
1330
1334
  e.routes[u.id] = u;
1331
- else if (a === "byUpdateTime") {
1335
+ else if (o === "byUpdateTime") {
1332
1336
  const i = e.routes[u.id];
1333
1337
  (!i || u.updatedAt && u.updatedAt > i.updatedAt) && (e.routes[u.id] = u);
1334
1338
  }
@@ -1336,7 +1340,7 @@ async function Le(t, e, {
1336
1340
  e.routeIds.push(u.id), e.routes[u.id] = u;
1337
1341
  }
1338
1342
  }
1339
- if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...mt(w)), o)
1343
+ if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...mt(w)), a)
1340
1344
  for (const I of Object.keys(e.components))
1341
1345
  delete e.components[I];
1342
1346
  let j = JSON.parse(JSON.stringify(t.components));
@@ -1353,30 +1357,30 @@ async function Le(t, e, {
1353
1357
  ];
1354
1358
  })
1355
1359
  )
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 || {})));
1360
+ ), Object.assign(e.components, j), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ee(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1357
1361
  }
1358
1362
  const Ve = Xe(
1359
1363
  async (t) => {
1360
- if (!be(t?.properties))
1364
+ if (!Ee(t?.properties))
1361
1365
  return t;
1362
1366
  if (t?.renderer?.type === "react-component") {
1363
1367
  const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
1364
1368
  if (s || e && e.includes("PROPERTIES_SCHEMA"))
1365
1369
  try {
1366
- const a = await Ze(
1370
+ const o = await Ze(
1367
1371
  e ?? "",
1368
1372
  "PROPERTIES_SCHEMA",
1369
1373
  t.id,
1370
1374
  s
1371
1375
  );
1372
- a && a.length > 0 && t && (t.properties = {}, a.forEach((o, r) => {
1373
- t?.properties && (t.properties[o.id] = {
1376
+ o && o.length > 0 && t && (t.properties = {}, o.forEach((a, r) => {
1377
+ t?.properties && (t.properties[a.id] = {
1374
1378
  index: r,
1375
- data: o
1379
+ data: a
1376
1380
  });
1377
1381
  }));
1378
- } catch (a) {
1379
- f.error("getPropertiesFromCode error", { componentId: t.id, name: t.name }, { error: a });
1382
+ } catch (o) {
1383
+ f.error("getPropertiesFromCode error", { componentId: t.id, name: t.name }, { error: o });
1380
1384
  }
1381
1385
  }
1382
1386
  return t;
@@ -1394,11 +1398,11 @@ const ze = () => ut({
1394
1398
  }), qt = () => {
1395
1399
  const t = ze(), e = {};
1396
1400
  return t.forEach((s) => {
1397
- const a = te("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), o = a && E(L(a), "../../chunks");
1398
- if (o && U(o)) {
1399
- const r = nt(o);
1401
+ const o = te("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), a = o && b(L(o), "../../chunks");
1402
+ if (a && U(a)) {
1403
+ const r = nt(a);
1400
1404
  for (const c of r)
1401
- e[c] = E(o, c);
1405
+ e[c] = b(a, c);
1402
1406
  }
1403
1407
  }), e;
1404
1408
  };
@@ -1407,36 +1411,36 @@ function Je() {
1407
1411
  const t = ze();
1408
1412
  Q = (await Promise.all(
1409
1413
  t.map(async (s) => {
1410
- const a = s.path ? await Ge(s.path, { importAssets: !1 }) : void 0;
1411
- return a ? { blockletId: s.did, state: a, blockletTitle: s.title } : void 0;
1414
+ const o = s.path ? await Ge(s.path, { importAssets: !1 }) : void 0;
1415
+ return o ? { blockletId: s.did, state: o, blockletTitle: s.title } : void 0;
1412
1416
  })
1413
1417
  )).filter((s) => !!s), ne = Q.reduce(
1414
- (s, a) => Object.assign(
1418
+ (s, o) => Object.assign(
1415
1419
  s,
1416
1420
  Object.fromEntries(
1417
- Object.values(a.state.pages).map((o) => o ? [o?.id, { page: o, blockletId: a.blockletId }] : [])
1421
+ Object.values(o.state.pages).map((a) => a ? [a?.id, { page: a, blockletId: o.blockletId }] : [])
1418
1422
  )
1419
1423
  ),
1420
1424
  {}
1421
1425
  );
1422
1426
  const e = Q.reduce(
1423
- (s, a) => Object.assign(
1427
+ (s, o) => Object.assign(
1424
1428
  s,
1425
1429
  Object.fromEntries(
1426
- Object.values(a.state.components).map((o) => [o.data.id, { blockletId: a.blockletId, component: o.data }])
1430
+ Object.values(o.state.components).map((a) => [a.data.id, { blockletId: o.blockletId, component: a.data }])
1427
1431
  )
1428
1432
  ),
1429
1433
  {}
1430
1434
  );
1431
1435
  ie = Object.fromEntries(
1432
1436
  await Promise.all(
1433
- Object.entries(e).map(async ([s, a]) => {
1434
- const o = await Ve(a.component);
1437
+ Object.entries(e).map(async ([s, o]) => {
1438
+ const a = await Ve(o.component);
1435
1439
  return [
1436
1440
  s,
1437
1441
  {
1438
- ...a,
1439
- component: o
1442
+ ...o,
1443
+ component: a
1440
1444
  }
1441
1445
  ];
1442
1446
  })
@@ -1459,8 +1463,8 @@ function Ht(t) {
1459
1463
  // 3s
1460
1464
  { leading: !1, trailing: !0 }
1461
1465
  );
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);
1466
+ return e(), E.events.on(E.Events.componentAdded, e), E.events.on(E.Events.componentRemoved, e), E.events.on(E.Events.componentStarted, e), E.events.on(E.Events.componentStopped, e), E.events.on(E.Events.componentUpdated, e), E.events.on(ge, e), () => {
1467
+ E.events.off(E.Events.componentAdded, e), E.events.off(E.Events.componentRemoved, e), E.events.off(E.Events.componentStarted, e), E.events.off(E.Events.componentStopped, e), E.events.off(E.Events.componentUpdated, e), E.events.off(ge, e);
1464
1468
  };
1465
1469
  }
1466
1470
  const Ke = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), qe = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), ce = globalThis;
@@ -1468,22 +1472,22 @@ ce[Ke]?.();
1468
1472
  ce[Ke] = Ht(async ({ pages: t, components: e }) => {
1469
1473
  const s = await O.getProjectIds();
1470
1474
  f.info(`start update resource states projects(${s.length})`, s), await Promise.race([
1471
- new Promise((a) => {
1475
+ new Promise((o) => {
1472
1476
  setTimeout(() => {
1473
- a({});
1477
+ o({});
1474
1478
  }, 30 * 1e3);
1475
1479
  }),
1476
1480
  Promise.all(
1477
- s.map(async (a) => {
1481
+ s.map(async (o) => {
1478
1482
  He({
1479
- projectId: a,
1483
+ projectId: o,
1480
1484
  pages: t,
1481
1485
  components: e
1482
1486
  });
1483
1487
  })
1484
1488
  )
1485
- ]).catch((a) => {
1486
- f.error("update resource states failed:", a);
1489
+ ]).catch((o) => {
1490
+ f.error("update resource states failed:", o);
1487
1491
  });
1488
1492
  });
1489
1493
  ce[qe]?.();
@@ -1491,8 +1495,8 @@ ce[qe] = () => {
1491
1495
  const t = () => {
1492
1496
  O.pageUrlMapCache.clear(), f.info("[Cache CLEAR ALL] clear all page url map cache by env update");
1493
1497
  };
1494
- return b.events.on(b.Events.envUpdate, t), () => {
1495
- b.events.off(b.Events.envUpdate, t);
1498
+ return E.events.on(E.Events.envUpdate, t), () => {
1499
+ E.events.off(E.Events.envUpdate, t);
1496
1500
  };
1497
1501
  };
1498
1502
  O.startPeriodicCheck();
@@ -1510,22 +1514,22 @@ async function He({
1510
1514
  pages: e,
1511
1515
  components: s
1512
1516
  }) {
1513
- const a = O.sharedInstances[t];
1514
- if (!a) {
1517
+ const o = O.sharedInstances[t];
1518
+ if (!o) {
1515
1519
  f.info(`projectId: ${t} not found in sharedInstances`);
1516
1520
  return;
1517
1521
  }
1518
- if (a.syncedStore.resources.pages = e, (await M.findByPk(t))?.useAllResources)
1519
- a.syncedStore.resources.components = s;
1522
+ if (o.syncedStore.resources.pages = e, (await M.findByPk(t))?.useAllResources)
1523
+ o.syncedStore.resources.components = s;
1520
1524
  else {
1521
1525
  const c = (await we.findAll({ where: { projectId: t } })).map((p) => p.componentId), l = Object.fromEntries(
1522
1526
  Object.entries(s || {}).filter(([p]) => c.includes(p))
1523
1527
  );
1524
- a.syncedStore.resources.components = l;
1528
+ o.syncedStore.resources.components = l;
1525
1529
  }
1526
1530
  f.info(`update [${t}] resource states:`, {
1527
- pages: Object.keys(a.syncedStore.resources.pages || {}).length,
1528
- components: Object.keys(a.syncedStore.resources.components || {}).length
1531
+ pages: Object.keys(o.syncedStore.resources.pages || {}).length,
1532
+ components: Object.keys(o.syncedStore.resources.components || {}).length
1529
1533
  });
1530
1534
  }
1531
1535
  async function ks(t) {
@@ -1536,7 +1540,7 @@ async function ks(t) {
1536
1540
  });
1537
1541
  }
1538
1542
  async function Ds() {
1539
- f.info("trigger reload all project resource"), b.events.emit(ge);
1543
+ f.info("trigger reload all project resource"), E.events.emit(ge);
1540
1544
  }
1541
1545
  async function Ts({
1542
1546
  ensureLoaded: t = !0