@blocklet/pages-kit-inner-components 0.6.96 → 0.6.98

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,43 @@
1
- import { d as Ne, l as f, I as et, c as tt, m as st, b as ot } from "./components-DLwSTd_N.js";
2
- import { getYjsValue as V, syncedStore as at } from "@syncedstore/core";
3
- import * as _ from "yjs";
4
- import { setPageDataSource as nt } from "@blocklet/pages-kit/utils/data-source";
5
- import { getRouteMetaDataByOptionIds as rt, generateParamCombinations as Ie } from "@blocklet/pages-kit/utils/route";
1
+ import { d as Fe, l as f, I as tt, c as st, m as ot, b as at } from "./components-DLwSTd_N.js";
2
+ import { getYjsValue as V, syncedStore as nt } from "@syncedstore/core";
3
+ import * as N from "yjs";
4
+ import { setPageDataSource as rt } from "@blocklet/pages-kit/utils/data-source";
5
+ import { getRouteMetaDataByOptionIds as it, generateParamCombinations as Ie } from "@blocklet/pages-kit/utils/route";
6
6
  import Ee from "lodash/cloneDeep";
7
7
  import E from "@blocklet/sdk/lib/config";
8
- import { mkdtempSync as it, existsSync as M, readFileSync as J, renameSync as Re, mkdirSync as N, rmSync as Fe, writeFileSync as te, copyFileSync as ct, lstatSync as x, readdirSync as lt, createWriteStream as pt } from "fs";
8
+ import { mkdtempSync as ct, existsSync as $, readFileSync as J, renameSync as je, mkdirSync as _, rmSync as Ge, writeFileSync as te, copyFileSync as lt, lstatSync as x, readdirSync as pt, createWriteStream as ut } from "fs";
9
9
  import { join as b, basename as k, dirname as L } from "path";
10
- import { nextId as je } from "@blocklet/pages-kit/utils/common";
11
- import { unzipSection as ut } from "@blocklet/pages-kit/utils/page-model";
12
- import { getComponentDependencies as dt } from "@blocklet/pages-kit/utils/property";
13
- import { getComponentWebEndpoint as ft, getResources as mt, call as gt } from "@blocklet/sdk/lib/component";
14
- import { reactive as ht } from "@reactivedata/reactive";
10
+ import { nextId as De } from "@blocklet/pages-kit/utils/common";
11
+ import { unzipSection as dt } from "@blocklet/pages-kit/utils/page-model";
12
+ import { getComponentDependencies as ft } from "@blocklet/pages-kit/utils/property";
13
+ import { getComponentWebEndpoint as mt, getResources as gt, call as ht } from "@blocklet/sdk/lib/component";
14
+ import { reactive as yt } from "@reactivedata/reactive";
15
15
  import { globSync as se } from "glob";
16
16
  import * as de from "lib0/decoding";
17
17
  import * as D from "lib0/encoding";
18
- import Ge from "lodash/debounce";
18
+ import xe from "lodash/debounce";
19
19
  import be from "lodash/get";
20
20
  import Ae from "lodash/isEmpty";
21
- import De from "lodash/set";
22
- import yt from "lodash/union";
21
+ import Te from "lodash/set";
22
+ import St from "lodash/union";
23
23
  import { LRUCache as we } from "lru-cache";
24
- import St from "p-limit";
25
- import { DataTypes as R, Sequelize as It, Model as xe, Op as Pe } from "sequelize";
26
- import { pipeline as Et } from "stream/promises";
27
- import { x as bt } from "tar";
28
- import { withoutTrailingSlash as Be, withLeadingSlash as At, joinURL as Y } from "ufo";
24
+ import It from "p-limit";
25
+ import { DataTypes as R, Sequelize as Et, Model as Be, Op as Pe } from "sequelize";
26
+ import { pipeline as bt } from "stream/promises";
27
+ import { x as At } from "tar";
28
+ import { withoutTrailingSlash as Oe, withLeadingSlash as Ve, joinURL as Y } from "ufo";
29
29
  import wt from "wait-on";
30
- import { Awareness as Pt, encodeAwarenessUpdate as Te, removeAwarenessStates as Ot, applyAwarenessUpdate as Ct } from "y-protocols/awareness";
30
+ import { Awareness as Pt, encodeAwarenessUpdate as ke, removeAwarenessStates as Ot, applyAwarenessUpdate as Ct } from "y-protocols/awareness";
31
31
  import { writeUpdate as vt, writeSyncStep1 as Rt, readSyncMessage as jt } from "y-protocols/sync";
32
32
  import * as B from "yaml";
33
- import { m as ke } from "./html-DOgzvdOd.js";
33
+ import { m as Le } from "./html-DOgzvdOd.js";
34
34
  import "sqlite3";
35
35
  import "@blocklet/pages-kit/types/state";
36
36
  const Dt = R.sqlite.DATE.parse;
37
37
  R.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Dt(t, e);
38
- const F = new It({
38
+ const F = new Et({
39
39
  dialect: "sqlite",
40
- storage: Ne,
40
+ storage: Fe,
41
41
  benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
42
42
  retry: {
43
43
  match: [/SQLITE_BUSY/],
@@ -76,16 +76,16 @@ let ge = null;
76
76
  ge && clearInterval(ge);
77
77
  ge = setInterval(
78
78
  async () => {
79
- f.info("Start cleanupSqliteMemory"), await Tt(F, Ne), f.info("End cleanupSqliteMemory");
79
+ f.info("Start cleanupSqliteMemory"), await Tt(F, Fe), f.info("End cleanupSqliteMemory");
80
80
  },
81
81
  60 * 1e3 * 10
82
82
  // 10 minutes
83
83
  );
84
- const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Le = "page", he = "trigger-reload-project-resource", Ve = kt, Lt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", Ut = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
85
- class Oe extends xe {
84
+ const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Ue = "page", he = "trigger-reload-project-resource", ze = kt, Lt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", Ut = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
85
+ class Ce extends Be {
86
86
  // Foreign key to Component
87
87
  }
88
- Oe.init(
88
+ Ce.init(
89
89
  {
90
90
  id: {
91
91
  type: R.UUID,
@@ -104,22 +104,22 @@ Oe.init(
104
104
  },
105
105
  { sequelize: F, tableName: "ProjectComponents", timestamps: !1 }
106
106
  );
107
- const $t = "SLUG_INVALID", K = (t) => ({
107
+ const Mt = "SLUG_INVALID", K = (t) => ({
108
108
  error: "slugInvalid",
109
- code: $t,
109
+ code: Mt,
110
110
  field: "slug",
111
111
  message: t
112
- }), Mt = {
112
+ }), $t = {
113
113
  error: "slugRequired",
114
114
  code: "SLUG_REQUIRED",
115
115
  field: "slug",
116
116
  message: () => "Project slug is required"
117
- }, _t = {
117
+ }, Nt = {
118
118
  error: "slugAlreadyExists",
119
119
  code: "SLUG_EXISTS",
120
120
  field: "slug",
121
121
  message: (t) => `Project slug "${t}" already exists`
122
- }, Nt = [
122
+ }, _t = [
123
123
  /\.\./,
124
124
  // Directory traversal
125
125
  /<[^>]*>/,
@@ -135,13 +135,13 @@ const $t = "SLUG_INVALID", K = (t) => ({
135
135
  // Control characters
136
136
  /[^a-zA-Z0-9-_@/\\:]/
137
137
  // Only allow specific characters
138
- ], Ue = (t) => {
138
+ ], Me = (t) => {
139
139
  if (!t) return "";
140
140
  if (t === "/") return "/";
141
- const e = Be(t);
142
- return At(e) || "/";
141
+ const e = Oe(t);
142
+ return Ve(e) || "/";
143
143
  }, Ft = (t) => t.did === Ut;
144
- class U extends xe {
144
+ class U extends Be {
145
145
  static async getProjectByIdOrSlug(e, s) {
146
146
  return e ? U.findOne({
147
147
  where: {
@@ -159,20 +159,22 @@ class U extends xe {
159
159
  if (e == null)
160
160
  return null;
161
161
  if (e === "")
162
- return Mt;
163
- const o = Ue(e);
164
- if (e !== "/" && e.endsWith("/"))
162
+ return $t;
163
+ const o = e === "/" ? "/" : Oe(Ve(e)), a = Me(o);
164
+ if (o !== "/" && o.endsWith("/"))
165
165
  return K((r) => `Project slug "${r}" cannot end with /`);
166
- if (/\/{2,}/.test(e))
166
+ if (/\/{2,}/.test(o))
167
167
  return K((r) => `Project slug "${r}" cannot contain consecutive /`);
168
- if (/\s/.test(e))
168
+ if (/\s/.test(o))
169
169
  return K((r) => `Project slug "${r}" cannot contain whitespace`);
170
- if (Nt.some((r) => r.test(e)))
170
+ if (_t.some((r) => r.test(o)))
171
171
  return K((r) => `Project slug "${r}" contains invalid characters`);
172
- if (E.components?.filter((r) => r.mountPoint && !Ft(r)).some((r) => Ue(r.mountPoint) === o))
172
+ if (E.components?.filter((r) => r.mountPoint && !Ft(r)).some((r) => Me(r.mountPoint) === a))
173
173
  return K((r) => `Project slug "${r}" conflicts with existing blocklet`);
174
- const n = await U.findOne({ where: { slug: `${e}` } });
175
- return n && n?.id !== s ? _t : null;
174
+ const c = await U.findOne({
175
+ where: { slug: o }
176
+ });
177
+ return c && c?.id !== s ? Nt : null;
176
178
  }
177
179
  }
178
180
  U.init(
@@ -279,7 +281,7 @@ U.init(
279
281
  ]
280
282
  }
281
283
  );
282
- U.hasMany(Oe, {
284
+ U.hasMany(Ce, {
283
285
  foreignKey: "projectId",
284
286
  as: "components"
285
287
  });
@@ -288,8 +290,8 @@ function oe(t) {
288
290
  e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
289
291
  });
290
292
  }
291
- function ze() {
292
- return it(b(E.env.dataDir, "tmp-"));
293
+ function qe() {
294
+ return ct(b(E.env.dataDir, "tmp-"));
293
295
  }
294
296
  function ae(t, e, s = []) {
295
297
  return Array.isArray(t) ? t.flatMap((o, a) => ae(o, e, [...s, a])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([o, a]) => ae(a, e, [...s, o])) : e(t) ? [s] : [];
@@ -300,14 +302,14 @@ function T(t) {
300
302
  function Gt(t) {
301
303
  t.pages && Object.keys(t.pages).forEach((s) => {
302
304
  const o = V(t.pages[s]);
303
- o && o instanceof _.Map && oe(o);
305
+ o && o instanceof N.Map && oe(o);
304
306
  });
305
307
  const e = V(t.pages);
306
- e && e instanceof _.Map && e.observe((s) => {
308
+ e && e instanceof N.Map && e.observe((s) => {
307
309
  s.changes.keys.forEach((o, a) => {
308
310
  if (o.action === "add") {
309
311
  const n = V(t.pages[a]);
310
- n && n instanceof _.Map && oe(n);
312
+ n && n instanceof N.Map && oe(n);
311
313
  }
312
314
  });
313
315
  });
@@ -315,14 +317,14 @@ function Gt(t) {
315
317
  function xt(t) {
316
318
  t.routes && Object.keys(t.routes).forEach((s) => {
317
319
  const o = V(t.routes?.[s]);
318
- o && o instanceof _.Map && oe(o);
320
+ o && o instanceof N.Map && oe(o);
319
321
  });
320
322
  const e = V(t.routes);
321
- e && e instanceof _.Map && e.observe((s) => {
323
+ e && e instanceof N.Map && e.observe((s) => {
322
324
  s.changes.keys.forEach((o, a) => {
323
325
  if (o.action === "add") {
324
326
  const n = V(t.routes?.[a]);
325
- n && n instanceof _.Map && oe(n);
327
+ n && n instanceof N.Map && oe(n);
326
328
  }
327
329
  });
328
330
  });
@@ -331,8 +333,8 @@ function Bt(t, e) {
331
333
  for (const s of e || Object.keys(t.routes || {})) {
332
334
  let o = s, a = [];
333
335
  if (s.includes("-")) {
334
- const [n, ...r] = s.split("-");
335
- o = n, a = r || [];
336
+ const [n, ...c] = s.split("-");
337
+ o = n, a = c || [];
336
338
  }
337
339
  if (t.routes?.[o] !== void 0) {
338
340
  t.routes[o].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -340,11 +342,11 @@ function Bt(t, e) {
340
342
  if (!n || !n.params || n.params.length === 0)
341
343
  continue;
342
344
  if (s.includes("-") && a.length > 0) {
343
- const r = rt(a, n);
344
- r && (r.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
345
+ const c = it(a, n);
346
+ c && (c.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
345
347
  }
346
348
  if (!e) {
347
- const r = Ie({
349
+ const c = Ie({
348
350
  basePath: n.path,
349
351
  params: n.params,
350
352
  routeId: n.id,
@@ -354,8 +356,8 @@ function Bt(t, e) {
354
356
  currentOptionIds: [],
355
357
  result: []
356
358
  });
357
- for (const l of r)
358
- l.routeMetaData ??= {}, l.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
359
+ for (const r of c)
360
+ r.routeMetaData ??= {}, r.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
359
361
  }
360
362
  }
361
363
  }
@@ -379,14 +381,14 @@ function fe({
379
381
  publishedAt: a?.routeMetaData?.publishedAt ?? e.publishedAt,
380
382
  isPublic: (a?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
381
383
  };
382
- for (const r of s.supportedLocales) {
384
+ for (const c of s.supportedLocales) {
383
385
  if (e.dataSource) {
384
- let l = e.id;
385
- a && (l = a.paramOptionIds.join("-"));
386
- const p = e.dataSource.pathDataMappings?.[l]?.dataCache?.[r.locale] ?? e.dataSource.pathDataMappings?.[l]?.dataCache?.[s.config.defaultLocale || "en"];
386
+ let r = e.id;
387
+ a && (r = a.paramOptionIds.join("-"));
388
+ const p = e.dataSource.pathDataMappings?.[r]?.dataCache?.[c.locale] ?? e.dataSource.pathDataMappings?.[r]?.dataCache?.[s.config.defaultLocale || "en"];
387
389
  if (!p)
388
390
  continue;
389
- nt(n, s, r.locale, p);
391
+ rt(n, s, c.locale, p);
390
392
  }
391
393
  a && a.routeMetaData && (a.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
392
394
  }
@@ -402,15 +404,15 @@ const Vt = 60 * 60 * 1e3, W = new we({
402
404
  });
403
405
  function zt(t, e = []) {
404
406
  let s = 0;
405
- const o = Array.from(W.keys()), a = t.map((n) => Be(n));
407
+ const o = Array.from(W.keys()), a = t.map((n) => Oe(n));
406
408
  for (const n of o)
407
- for (const r of a) {
408
- if (ke(n, { currentPath: r })) {
409
+ for (const c of a) {
410
+ if (Le(n, { currentPath: c })) {
409
411
  W.delete(n), s++, f.info(`[Cache CLEAR] key: ${n}`);
410
412
  break;
411
413
  }
412
- for (const l of e)
413
- if (ke(n, { currentPath: `/${l}${r}` })) {
414
+ for (const r of e)
415
+ if (Le(n, { currentPath: `/${r}${c}` })) {
414
416
  W.delete(n), s++, f.info(`[Cache CLEAR] key: ${n}`);
415
417
  break;
416
418
  }
@@ -422,7 +424,7 @@ function qt() {
422
424
  return W.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
423
425
  }
424
426
  E.events.on(E.Events.envUpdate, qt);
425
- const { uploadToMediaKit: Kt } = require("@blocklet/uploader-server"), Ce = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, X = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, $e = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Ht = 1e4, Jt = 3e4, Z = 0, me = 1, Yt = 0, Wt = 1, ye = E, H = b(process.env.BLOCKLET_DATA_DIR, "site-state"), Ms = ["production", "draft"], _s = ["production"];
427
+ const { uploadToMediaKit: Kt } = require("@blocklet/uploader-server"), ve = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, X = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, $e = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Ht = 1e4, Jt = 3e4, Z = 0, me = 1, Yt = 0, Wt = 1, ye = E, H = b(process.env.BLOCKLET_DATA_DIR, "site-state"), $s = ["production", "draft"], Ns = ["production"];
426
428
  function ne(t) {
427
429
  return t?.replace(/\//g, "|") || "";
428
430
  }
@@ -441,10 +443,10 @@ function Xt() {
441
443
  resources: {}
442
444
  };
443
445
  }
444
- class O extends _.Doc {
446
+ class O extends N.Doc {
445
447
  constructor(e) {
446
- super(), this.options = e, M(this.draftYjsFilePath) && _.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore = ht(
447
- at(
448
+ super(), this.options = e, $(this.draftYjsFilePath) && N.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore = yt(
449
+ nt(
448
450
  {
449
451
  pages: {},
450
452
  pageIds: [],
@@ -480,7 +482,7 @@ class O extends _.Doc {
480
482
  throw new Error("Should provide project context");
481
483
  try {
482
484
  const s = b(H, e), o = b(H, `@del-${e}`);
483
- Re(s, o);
485
+ je(s, o);
484
486
  } catch (s) {
485
487
  f.error("Failed to safe delete project state dir:", s);
486
488
  }
@@ -514,10 +516,10 @@ class O extends _.Doc {
514
516
  attributes: ["productionState"]
515
517
  });
516
518
  if (Ae(s?.productionState)) {
517
- const o = b(H, e, "production"), a = await Ke(o, { includeResources: !0 }) ?? Xt();
519
+ const o = b(H, e, "production"), a = await He(o, { includeResources: !0 }) ?? Xt();
518
520
  if (!a?.config?.defaultLocale) {
519
521
  a.config ??= {};
520
- const n = ye.env.languages?.map((r) => ({ locale: r.code, name: r.name })) || [];
522
+ const n = ye.env.languages?.map((c) => ({ locale: c.code, name: c.name })) || [];
521
523
  a.config.defaultLocale = n[0]?.locale;
522
524
  }
523
525
  return a;
@@ -550,11 +552,11 @@ class O extends _.Doc {
550
552
  }
551
553
  async setState(e, s) {
552
554
  const o = await ts(s, { exportAssets: !1, includeResources: !0 }), a = this.getPublishDir(e);
553
- if (N(L(a), { recursive: !0 }), Fe(a, { force: !0, recursive: !0 }), Re(o, a), e === "production") {
555
+ if (_(L(a), { recursive: !0 }), Ge(a, { force: !0, recursive: !0 }), je(o, a), e === "production") {
554
556
  const n = k(this.options.path);
555
557
  O.pageUrlMapCache.delete(n);
556
- const r = Ee(s);
557
- await U.update({ productionState: r }, { where: { id: n } });
558
+ const c = Ee(s);
559
+ await U.update({ productionState: c }, { where: { id: n } });
558
560
  }
559
561
  }
560
562
  getPublishDir(e) {
@@ -575,10 +577,10 @@ class O extends _.Doc {
575
577
  p.delete(y);
576
578
  }));
577
579
  }
578
- const r = D.createEncoder();
579
- D.writeVarUint(r, me), D.writeVarUint8Array(r, Te(this.awareness, n));
580
- const l = D.toUint8Array(r);
581
- this.conns.forEach((p, y) => this.send(y, l));
580
+ const c = D.createEncoder();
581
+ D.writeVarUint(c, me), D.writeVarUint8Array(c, ke(this.awareness, n));
582
+ const r = D.toUint8Array(c);
583
+ this.conns.forEach((p, y) => this.send(y, r));
582
584
  };
583
585
  updateHandler = (e) => {
584
586
  const s = D.createEncoder();
@@ -587,30 +589,30 @@ class O extends _.Doc {
587
589
  this.conns.forEach((a, n) => this.send(n, o));
588
590
  };
589
591
  ensureDataStructure = () => {
590
- const { supportedLocales: e, pages: s, pageIds: o, config: a, routes: n, routeIds: r } = this.syncedStore;
592
+ const { supportedLocales: e, pages: s, pageIds: o, config: a, routes: n, routeIds: c } = this.syncedStore;
591
593
  {
592
- const l = new Set(Object.keys(s));
594
+ const r = new Set(Object.keys(s));
593
595
  let p = 0;
594
596
  for (; p < o.length; ) {
595
597
  const y = o[p];
596
- l.has(y) ? (l.delete(y), p++) : o.splice(p, 1);
598
+ r.has(y) ? (r.delete(y), p++) : o.splice(p, 1);
597
599
  }
598
600
  }
599
601
  {
600
- const l = new Set(Object.keys(n));
602
+ const r = new Set(Object.keys(n));
601
603
  let p = 0;
602
- for (; p < r.length; ) {
603
- const y = r[p];
604
- l.has(y) ? (l.delete(y), p++) : r.splice(p, 1);
604
+ for (; p < c.length; ) {
605
+ const y = c[p];
606
+ r.has(y) ? (r.delete(y), p++) : c.splice(p, 1);
605
607
  }
606
608
  }
607
- e.splice(0, e.length), e.push(...ye.env.languages.map((l) => ({ locale: l.code, name: l.name }))), a.defaultLocale = e[0]?.locale;
609
+ e.splice(0, e.length), e.push(...ye.env.languages.map((r) => ({ locale: r.code, name: r.name }))), a.defaultLocale = e[0]?.locale;
608
610
  {
609
- let l = 0;
611
+ let r = 0;
610
612
  const p = /* @__PURE__ */ new Set();
611
- for (; l < e.length; ) {
612
- const { locale: y } = e[l];
613
- p.has(y) ? e.splice(l, 1) : (l++, p.add(y));
613
+ for (; r < e.length; ) {
614
+ const { locale: y } = e[r];
615
+ p.has(y) ? e.splice(r, 1) : (r++, p.add(y));
614
616
  }
615
617
  }
616
618
  };
@@ -651,8 +653,8 @@ class O extends _.Doc {
651
653
  f.info(`[SiteState] cancelled scheduled release for project ${e}`);
652
654
  }
653
655
  }
654
- autoSave = Ge(() => {
655
- N(L(this.draftYjsFilePath), { recursive: !0 }), te(this.draftYjsFilePath, _.encodeStateAsUpdate(this));
656
+ autoSave = xe(() => {
657
+ _(L(this.draftYjsFilePath), { recursive: !0 }), te(this.draftYjsFilePath, N.encodeStateAsUpdate(this));
656
658
  }, Ht);
657
659
  save = ({ flush: e = !1 } = {}) => {
658
660
  this.autoSave(), e && this.autoSave.flush();
@@ -667,30 +669,30 @@ class O extends _.Doc {
667
669
  const o = JSON.parse(JSON.stringify(s));
668
670
  e.config.fontFamily ??= {};
669
671
  const a = o.config?.fontFamily, n = e.config?.fontFamily;
670
- e.config.fontFamily.title = a?.title || n?.title, e.config.fontFamily.description = a?.description || n?.description, await new Promise((r, l) => {
672
+ e.config.fontFamily.title = a?.title || n?.title, e.config.fontFamily.description = a?.description || n?.description, await new Promise((c, r) => {
671
673
  this.transact(async () => {
672
674
  try {
673
675
  const p = await _e(e, s);
674
- r(p);
676
+ c(p);
675
677
  } catch (p) {
676
- l(p);
678
+ r(p);
677
679
  }
678
680
  });
679
681
  });
680
682
  };
681
683
  clearPageCacheForRoutes = async (e, s) => {
682
684
  const o = k(this.options.path), n = (await U.findByPk(o))?.slug || o;
683
- let r = e;
684
- (!r || r.length === 0) && (r = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${o}, routes:`, r || []);
685
- const l = s.supportedLocales.map((A) => A.locale), p = [], y = r.filter((A) => s.pageIds?.includes(A));
685
+ let c = e;
686
+ (!c || c.length === 0) && (c = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${o}, routes:`, c || []);
687
+ const r = s.supportedLocales.map((A) => A.locale), p = [], y = c.filter((A) => s.pageIds?.includes(A));
686
688
  for (const A of y) {
687
689
  const I = s.pages[A].slug;
688
690
  n && n !== o && (n === "/" ? p.push(I) : p.push(`/${n}${I}`)), p.push(`/${o}${I}`);
689
691
  }
690
692
  if (p.length > 0)
691
693
  try {
692
- const A = zt(p, l);
693
- f.info(`[SiteState] cleared ${A} page cache entries for project ${o}, routes:`, r);
694
+ const A = zt(p, r);
695
+ f.info(`[SiteState] cleared ${A} page cache entries for project ${o}, routes:`, c);
694
696
  } catch {
695
697
  }
696
698
  O.pageUrlMapCache.delete(o);
@@ -722,8 +724,8 @@ class O extends _.Doc {
722
724
  D.writeVarUint(a, Z), Rt(a, this), this.send(e, D.toUint8Array(a));
723
725
  const n = this.awareness.getStates();
724
726
  if (n.size > 0) {
725
- const r = D.createEncoder();
726
- D.writeVarUint(r, me), D.writeVarUint8Array(r, Te(this.awareness, Array.from(n.keys()))), this.send(e, D.toUint8Array(r));
727
+ const c = D.createEncoder();
728
+ D.writeVarUint(c, me), D.writeVarUint8Array(c, ke(this.awareness, Array.from(n.keys()))), this.send(e, D.toUint8Array(c));
727
729
  }
728
730
  }
729
731
  };
@@ -752,10 +754,10 @@ class O extends _.Doc {
752
754
  s ? o = [s] : o = await this.getProjectIds();
753
755
  let a = {};
754
756
  if (e === "production" && o?.length) {
755
- const n = new Map(o?.map((r) => [r, !0]) || []);
756
- for (const r of o) {
757
- const l = O.pageUrlMapCache.get(r);
758
- l && (a = { ...a, ...l }, n.delete(r));
757
+ const n = new Map(o?.map((c) => [c, !0]) || []);
758
+ for (const c of o) {
759
+ const r = O.pageUrlMapCache.get(c);
760
+ r && (a = { ...a, ...r }, n.delete(c));
759
761
  }
760
762
  o = Array.from(n.keys());
761
763
  }
@@ -768,35 +770,35 @@ class O extends _.Doc {
768
770
  }
769
771
  });
770
772
  await Promise.all(
771
- n?.map(async (r) => {
772
- const l = r.id, p = r.slug || l, y = {}, A = e === "production" && r?.productionState ? r.productionState : await O.getStateByProjectId(r.id, e), j = yt(
773
+ n?.map(async (c) => {
774
+ const r = c.id, p = c.slug || r, y = {}, A = e === "production" && c?.productionState ? c.productionState : await O.getStateByProjectId(c.id, e), j = St(
773
775
  E.env.languages?.map((u) => u.code) || [],
774
776
  A.supportedLocales?.map((u) => u.locale) || []
775
- ), I = (u, c) => {
777
+ ), I = (u, l) => {
776
778
  p && (y[Y("/", p, u)] = {
777
- ...c,
779
+ ...l,
778
780
  shouldRedirect: !0,
779
781
  mainPage: !0
780
- }), y[Y("/", l, u)] = {
781
- ...c,
782
+ }), y[Y("/", r, u)] = {
783
+ ...l,
782
784
  shouldRedirect: !0,
783
785
  mainPage: !0
784
786
  };
785
787
  for (const g of j) {
786
- const C = { ...c, locale: g };
787
- y[Y("/", g, l, u)] = C, p && (y[Y("/", g, p, u)] = C);
788
+ const C = { ...l, locale: g };
789
+ y[Y("/", g, r, u)] = C, p && (y[Y("/", g, p, u)] = C);
788
790
  }
789
791
  };
790
792
  if (e === "draft")
791
793
  for (const u of A.routeIds || []) {
792
- const c = A?.routes?.[u];
793
- if (!c) continue;
794
- if (c.params && c.params.length > 0) {
794
+ const l = A?.routes?.[u];
795
+ if (!l) continue;
796
+ if (l.params && l.params.length > 0) {
795
797
  const m = Ie({
796
- basePath: c.path,
797
- params: c.params,
798
- routeId: c.id,
799
- paramsOptions: c.paramsOptions,
798
+ basePath: l.path,
799
+ params: l.params,
800
+ routeId: l.id,
801
+ paramsOptions: l.paramsOptions,
800
802
  currentIndex: 0,
801
803
  currentParams: [],
802
804
  currentOptionIds: [],
@@ -804,40 +806,40 @@ class O extends _.Doc {
804
806
  });
805
807
  for (const d of m) {
806
808
  const h = d.path, w = {
807
- projectId: l,
809
+ projectId: r,
808
810
  projectSlug: p,
809
811
  pageSlug: h,
810
- pageId: c.displayTemplateId || "",
812
+ pageId: l.displayTemplateId || "",
811
813
  routeId: u,
812
814
  // default locale
813
815
  defaultLocale: j?.[0],
814
816
  locales: j,
815
817
  publishedAt: A.config.publishedAt,
816
- isPublic: c.isPublic && d?.routeMetaData?.isPublic
818
+ isPublic: l.isPublic && d?.routeMetaData?.isPublic
817
819
  };
818
820
  I(h, w);
819
821
  }
820
822
  }
821
- const g = c.path, C = {
822
- projectId: l,
823
+ const g = l.path, C = {
824
+ projectId: r,
823
825
  projectSlug: p,
824
826
  pageSlug: g,
825
- pageId: c.displayTemplateId || "",
827
+ pageId: l.displayTemplateId || "",
826
828
  routeId: u,
827
829
  // default locale
828
830
  defaultLocale: j?.[0],
829
831
  locales: j,
830
832
  publishedAt: A.config.publishedAt,
831
- isPublic: c.isPublic
833
+ isPublic: l.isPublic
832
834
  };
833
835
  I(g, C);
834
836
  }
835
837
  for (const u of A.pageIds || []) {
836
- const c = A.pages[u];
837
- if (!c || e === "production" && !c.isPublic)
838
+ const l = A.pages[u];
839
+ if (!l || e === "production" && !l.isPublic)
838
840
  continue;
839
- const g = c.slug, C = r.slug || l, m = {
840
- projectId: l,
841
+ const g = l.slug, C = c.slug || r, m = {
842
+ projectId: r,
841
843
  projectSlug: C,
842
844
  pageSlug: g,
843
845
  pageId: u,
@@ -845,19 +847,19 @@ class O extends _.Doc {
845
847
  defaultLocale: j?.[0],
846
848
  locales: j,
847
849
  publishedAt: A.config.publishedAt,
848
- isPublic: c.isPublic,
849
- templateConfig: c.templateConfig
850
+ isPublic: l.isPublic,
851
+ templateConfig: l.templateConfig
850
852
  };
851
853
  I(g, m);
852
854
  }
853
- e === "production" && O.pageUrlMapCache.set(l, y), a = { ...a, ...y };
855
+ e === "production" && O.pageUrlMapCache.set(r, y), a = { ...a, ...y };
854
856
  })
855
857
  );
856
858
  }
857
859
  return a;
858
860
  }
859
861
  getDocumentSize() {
860
- return _.encodeStateAsUpdate(this).byteLength;
862
+ return N.encodeStateAsUpdate(this).byteLength;
861
863
  }
862
864
  static getInstancesSizeInfo() {
863
865
  const e = [];
@@ -897,11 +899,11 @@ class O extends _.Doc {
897
899
  s.map((n) => n.projectId)
898
900
  );
899
901
  let a = 0;
900
- for (const { projectId: n, instance: r } of s)
902
+ for (const { projectId: n, instance: c } of s)
901
903
  try {
902
- f.info(`[SiteState] releasing instance due to periodic check: ${n}`), r.destroy(), a++;
903
- } catch (l) {
904
- f.error(`[SiteState] failed to release instance ${n} during periodic check:`, l);
904
+ f.info(`[SiteState] releasing instance due to periodic check: ${n}`), c.destroy(), a++;
905
+ } catch (r) {
906
+ f.error(`[SiteState] failed to release instance ${n} during periodic check:`, r);
905
907
  }
906
908
  f.info(
907
909
  `[SiteState] periodic check completed: ${a}/${s.length} instances released successfully`
@@ -910,7 +912,7 @@ class O extends _.Doc {
910
912
  }
911
913
  }
912
914
  async function Qt(t, e, s) {
913
- if (!t || !M(t) || !x(t).isFile())
915
+ if (!t || !$(t) || !x(t).isFile())
914
916
  return null;
915
917
  let o = s[t];
916
918
  return o || (o = (async () => {
@@ -925,15 +927,15 @@ async function Qt(t, e, s) {
925
927
  })(), s[t] = o), o;
926
928
  }
927
929
  const Zt = async (t, e) => {
928
- const s = k(t), o = await gt({
929
- name: Ve,
930
+ const s = k(t), o = await ht({
931
+ name: ze,
930
932
  path: Y("/uploads", s),
931
933
  responseType: "stream",
932
934
  method: "GET"
933
935
  });
934
936
  if (o.status >= 200 && o.status < 400) {
935
- const a = pt(e);
936
- await Et(o.data, a);
937
+ const a = ut(e);
938
+ await bt(o.data, a);
937
939
  } else
938
940
  throw new Error(`download asset failed ${o.status}`);
939
941
  }, es = async (t, e) => {
@@ -947,20 +949,20 @@ const Zt = async (t, e) => {
947
949
  })
948
950
  );
949
951
  };
950
- function qe(t) {
951
- return Ce.test(t) ? [t] : X.test(t) ? ($e.lastIndex = 0, Array.from(t.matchAll($e)).map((s) => s[1]).filter((s) => !!s)) : [];
952
+ function Ke(t) {
953
+ return ve.test(t) ? [t] : X.test(t) ? ($e.lastIndex = 0, Array.from(t.matchAll($e)).map((s) => s[1]).filter((s) => !!s)) : [];
952
954
  }
953
955
  async function ee(t, e, s) {
954
956
  const { getFilename: o, exportAssets: a } = s, n = b(e, o(t));
955
- if (N(L(n), { recursive: !0 }), te(n, B.stringify(t)), a) {
956
- const l = ae(
957
+ if (_(L(n), { recursive: !0 }), te(n, B.stringify(t)), a) {
958
+ const r = ae(
957
959
  t,
958
- (p) => typeof p == "string" && (Ce.test(p) || X.test(p))
960
+ (p) => typeof p == "string" && (ve.test(p) || X.test(p))
959
961
  ).map((p) => {
960
962
  const y = be(t, p);
961
- return qe(y);
963
+ return Ke(y);
962
964
  }).flat().filter(Boolean);
963
- await es(l, L(n));
965
+ await es(r, L(n));
964
966
  }
965
967
  }
966
968
  const Se = new we({
@@ -968,29 +970,29 @@ const Se = new we({
968
970
  ttl: 1 * 60 * 1e3
969
971
  // 1 minute
970
972
  });
971
- async function Me(t, e, s) {
973
+ async function Ne(t, e, s) {
972
974
  const o = ae(
973
975
  t,
974
- (l) => typeof l == "string" && (Ce.test(l) || X.test(l))
975
- ), a = St(2), n = o.map(
976
- (l) => a(async () => {
976
+ (r) => typeof r == "string" && (ve.test(r) || X.test(r))
977
+ ), a = It(2), n = o.map(
978
+ (r) => a(async () => {
977
979
  try {
978
- const p = be(t, l), y = qe(p);
980
+ const p = be(t, r), y = Ke(p);
979
981
  for (const A of y) {
980
- const j = k(A), I = s.getFilePath(A, l), u = I ? `${I}:${j}` : j, c = Se.get(u);
981
- if (c) {
982
- X.test(p) || De(t, l, c);
982
+ const j = k(A), I = s.getFilePath(A, r), u = I ? `${I}:${j}` : j, l = Se.get(u);
983
+ if (l) {
984
+ X.test(p) || Te(t, r, l);
983
985
  return;
984
986
  }
985
987
  const g = await Qt(I, j, e);
986
- g && (X.test(p) || De(t, l, g), Se.set(u, g));
988
+ g && (X.test(p) || Te(t, r, g), Se.set(u, g));
987
989
  }
988
990
  } catch (p) {
989
- f.error(`Failed to process upload for path ${l.join(".")}:`, p.message || p.reason);
991
+ f.error(`Failed to process upload for path ${r.join(".")}:`, p.message || p.reason);
990
992
  }
991
993
  })
992
- ), r = await Promise.allSettled(n);
993
- s.onFinish?.(r);
994
+ ), c = await Promise.allSettled(n);
995
+ s.onFinish?.(c);
994
996
  }
995
997
  async function ts(t, {
996
998
  exportAssets: e,
@@ -998,17 +1000,17 @@ async function ts(t, {
998
1000
  componentIds: o = "all",
999
1001
  rawConfig: a,
1000
1002
  includeResources: n = !1,
1001
- routeIds: r = "all"
1003
+ routeIds: c = "all"
1002
1004
  } = {}) {
1003
- const l = s === "all" ? t.pageIds : s, p = dt({
1005
+ const r = s === "all" ? t.pageIds : s, p = ft({
1004
1006
  state: t,
1005
- pageIds: l,
1007
+ pageIds: r,
1006
1008
  componentIds: o === "all" ? Object.keys(t.components) : o
1007
1009
  });
1008
1010
  Object.entries(t.components).forEach(([i, S]) => {
1009
1011
  S.data?.renderer?.type === "component-template" && p.push(i);
1010
1012
  });
1011
- const y = r === "all" ? t.routeIds : r, A = (i) => ({
1013
+ const y = c === "all" ? t.routeIds : c, A = (i) => ({
1012
1014
  id: i.id,
1013
1015
  name: i.name,
1014
1016
  isTemplateSection: i.isTemplateSection ?? !1,
@@ -1061,9 +1063,9 @@ async function ts(t, {
1061
1063
  const S = t.routes[i];
1062
1064
  return S && I(S);
1063
1065
  })
1064
- ), c = T(
1066
+ ), l = T(
1065
1067
  t.supportedLocales.map((i) => i.locale).flatMap(
1066
- (i) => l.map((S) => {
1068
+ (i) => r.map((S) => {
1067
1069
  const v = t.pages[S];
1068
1070
  return v && {
1069
1071
  locale: i,
@@ -1072,13 +1074,13 @@ async function ts(t, {
1072
1074
  };
1073
1075
  })
1074
1076
  )
1075
- ), g = ze(), C = b(g, "pages");
1076
- N(C, { recursive: !0 });
1077
+ ), g = qe(), C = b(g, "pages");
1078
+ _(C, { recursive: !0 });
1077
1079
  const m = b(g, "components");
1078
- N(m, { recursive: !0 });
1080
+ _(m, { recursive: !0 });
1079
1081
  const d = b(g, "routes");
1080
- N(d, { recursive: !0 });
1081
- for (const { locale: i, slug: S, page: v } of c)
1082
+ _(d, { recursive: !0 });
1083
+ for (const { locale: i, slug: S, page: v } of l)
1082
1084
  await ee(v, C, {
1083
1085
  getFilename: () => `${ne(S) || "index"}.${i}.yml`,
1084
1086
  exportAssets: e
@@ -1097,10 +1099,10 @@ async function ts(t, {
1097
1099
  });
1098
1100
  }
1099
1101
  const h = b(g, ".blocklet/pages/pages.config.yml");
1100
- N(L(h), { recursive: !0 });
1102
+ _(L(h), { recursive: !0 });
1101
1103
  const w = {
1102
1104
  pages: T(
1103
- l.map((i) => {
1105
+ r.map((i) => {
1104
1106
  const S = t.pages[i];
1105
1107
  return S && { id: i, slug: S.slug };
1106
1108
  })
@@ -1137,32 +1139,32 @@ async function ts(t, {
1137
1139
  const P = b(g, "config.source.json");
1138
1140
  if (a && te(P, JSON.stringify(a)), n) {
1139
1141
  const i = b(g, "resources"), S = b(i, "components");
1140
- N(S, { recursive: !0 });
1142
+ _(S, { recursive: !0 });
1141
1143
  for (const z of Object.keys(t?.resources?.components ?? {}).filter(
1142
- ($) => p.includes($)
1144
+ (M) => p.includes(M)
1143
1145
  )) {
1144
- const $ = t.resources?.components?.[z]?.component;
1145
- $ && await ee($, S, {
1146
+ const M = t.resources?.components?.[z]?.component;
1147
+ M && await ee(M, S, {
1146
1148
  getFilename: (q) => `${q.name || "unnamed"}.${q.id}.yml`,
1147
1149
  exportAssets: e
1148
1150
  });
1149
1151
  }
1150
1152
  const v = b(g, "chunks");
1151
- N(v, { recursive: !0 });
1153
+ _(v, { recursive: !0 });
1152
1154
  const G = ss();
1153
1155
  for (const z of Object.keys(t?.resources?.components ?? {}).filter(
1154
- ($) => p.includes($)
1156
+ (M) => p.includes(M)
1155
1157
  )) {
1156
- const $ = t.resources?.components?.[z]?.component;
1157
- if ($ && $.renderer?.type === "react-component") {
1158
- const q = $.renderer?.chunks ?? [];
1158
+ const M = t.resources?.components?.[z]?.component;
1159
+ if (M && M.renderer?.type === "react-component") {
1160
+ const q = M.renderer?.chunks ?? [];
1159
1161
  if (q?.length > 0)
1160
1162
  for (const pe of q) {
1161
- const ve = b(v, pe), ue = G?.[pe];
1163
+ const Re = b(v, pe), ue = G?.[pe];
1162
1164
  try {
1163
- ue && M(ue) && !M(ve) && ct(ue, ve);
1164
- } catch (Ze) {
1165
- f.error(`copy chunk ${pe} error`, Ze.message);
1165
+ ue && $(ue) && !$(Re) && lt(ue, Re);
1166
+ } catch (et) {
1167
+ f.error(`copy chunk ${pe} error`, et.message);
1166
1168
  }
1167
1169
  }
1168
1170
  }
@@ -1170,18 +1172,18 @@ async function ts(t, {
1170
1172
  }
1171
1173
  return g;
1172
1174
  }
1173
- async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1174
- if (!M(t))
1175
+ async function He(t, { importAssets: e, includeResources: s } = {}) {
1176
+ if (!$(t))
1175
1177
  return null;
1176
1178
  let o, a = !1;
1177
1179
  try {
1178
- x(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o = ze(), await bt({ file: t, C: o }));
1179
- const n = se("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), r = n && b(L(n), "../../pages"), l = n && b(L(n), "../../components"), p = n && b(L(n), "../../routes");
1180
+ x(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o = qe(), await At({ file: t, C: o }));
1181
+ const n = se("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), c = n && b(L(n), "../../pages"), r = n && b(L(n), "../../components"), p = n && b(L(n), "../../routes");
1180
1182
  if (!n)
1181
1183
  return null;
1182
1184
  const y = B.parse(J(n).toString()), A = (m, d, h) => {
1183
1185
  let w = b(m, `${d}${h ? `.${h}` : ""}.yml`);
1184
- return (!M(w) || !x(w).isFile()) && (w = b(m, d, `index${h ? `.${h}` : ""}.yml`), !M(w) || !x(w)) ? null : B.parse(J(w).toString());
1186
+ return (!$(w) || !x(w).isFile()) && (w = b(m, d, `index${h ? `.${h}` : ""}.yml`), !$(w) || !x(w)) ? null : B.parse(J(w).toString());
1185
1187
  }, j = (m, d) => {
1186
1188
  try {
1187
1189
  const h = se(`*.${d}.yml`, { cwd: m, absolute: !0 })[0];
@@ -1192,23 +1194,23 @@ async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1192
1194
  return null;
1193
1195
  }, I = (m, d) => {
1194
1196
  let h = b(m, `${d}.yml`);
1195
- return (!M(h) || !x(h).isFile()) && (h = b(m, d, "index.yml"), !M(h) || !x(h)) ? null : B.parse(J(h).toString());
1197
+ return (!$(h) || !x(h).isFile()) && (h = b(m, d, "index.yml"), !$(h) || !x(h)) ? null : B.parse(J(h).toString());
1196
1198
  }, u = T(
1197
1199
  y.pages.map(({ slug: m }) => {
1198
1200
  const d = T(
1199
1201
  y.supportedLocales.map(({ locale: P }) => {
1200
- const i = r ? A(r, ne(m), P) : void 0;
1202
+ const i = c ? A(c, ne(m), P) : void 0;
1201
1203
  if (i)
1202
1204
  return { locale: P, page: i };
1203
- const S = r ? A(r, m, P) : void 0;
1205
+ const S = c ? A(c, m, P) : void 0;
1204
1206
  return S && { locale: P, page: S };
1205
1207
  })
1206
1208
  ), h = d[0]?.page;
1207
1209
  if (!h)
1208
1210
  return null;
1209
- const w = h.sections.map(ut);
1211
+ const w = h.sections.map(dt);
1210
1212
  return {
1211
- id: h.id || je(),
1213
+ id: h.id || De(),
1212
1214
  createdAt: h.createdAt,
1213
1215
  updatedAt: h.updatedAt,
1214
1216
  publishedAt: h.publishedAt,
@@ -1246,12 +1248,12 @@ async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1246
1248
  )
1247
1249
  };
1248
1250
  })
1249
- ), c = T(
1251
+ ), l = T(
1250
1252
  y?.routes?.map(({ path: m }) => {
1251
1253
  const d = p ? I(p, ne(m)) : void 0;
1252
1254
  return {
1253
1255
  ...d,
1254
- id: d?.id || je(),
1256
+ id: d?.id || De(),
1255
1257
  createdAt: d?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1256
1258
  updatedAt: d?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1257
1259
  publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
@@ -1264,28 +1266,28 @@ async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1264
1266
  dataSource: d?.dataSource ?? {}
1265
1267
  };
1266
1268
  }) ?? []
1267
- ), g = l ? T(y.components?.map(({ id: m }) => j(l, m)) ?? []) : [];
1269
+ ), g = r ? T(y.components?.map(({ id: m }) => j(r, m)) ?? []) : [];
1268
1270
  if (e) {
1269
1271
  const m = (...d) => {
1270
1272
  f.info(`[${a ? k(t) : k(b(t, "../../../../"))}] importAssets:`, ...d);
1271
1273
  };
1272
1274
  try {
1273
1275
  m("wait image-bin api ready"), await wt({
1274
- resources: [`${ft(et)}/api/sdk/uploads`],
1276
+ resources: [`${mt(tt)}/api/sdk/uploads`],
1275
1277
  validateStatus: (w) => w >= 200 && w <= 500
1276
1278
  }), m("image-bin api is ready");
1277
1279
  const d = {}, h = {};
1278
1280
  m("start to upload assets"), await Promise.allSettled([
1279
- Me(g, d, {
1280
- getFilePath: (w) => l && b(l, w),
1281
+ Ne(g, d, {
1282
+ getFilePath: (w) => r && b(r, w),
1281
1283
  onFinish: (w) => {
1282
1284
  m(`upload ${w.length} component assets`);
1283
1285
  }
1284
1286
  }),
1285
- Me(u, h, {
1287
+ Ne(u, h, {
1286
1288
  getFilePath: (w, P) => {
1287
1289
  const i = be(u, P.slice(0, 1));
1288
- return r && b(r, L(i.slug), w);
1290
+ return c && b(c, L(i.slug), w);
1289
1291
  },
1290
1292
  onFinish: (w) => {
1291
1293
  m(`upload ${w.length} page assets`);
@@ -1312,13 +1314,13 @@ async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1312
1314
  pages: Object.fromEntries(u.map((m) => [m.id, m])),
1313
1315
  config: y.config || {},
1314
1316
  resources: C,
1315
- routeIds: c.map((m) => m.id),
1316
- routes: Object.fromEntries(c.map((m) => [m.id, m])),
1317
+ routeIds: l.map((m) => m.id),
1318
+ routes: Object.fromEntries(l.map((m) => [m.id, m])),
1317
1319
  dataSourceIds: [],
1318
1320
  dataSources: {}
1319
1321
  };
1320
1322
  } finally {
1321
- a && o && Fe(o, { force: !0, recursive: !0 });
1323
+ a && o && Ge(o, { force: !0, recursive: !0 });
1322
1324
  }
1323
1325
  }
1324
1326
  async function _e(t, e, {
@@ -1328,15 +1330,15 @@ async function _e(t, e, {
1328
1330
  publishMode: n = void 0
1329
1331
  } = {}) {
1330
1332
  try {
1331
- n && tt(n);
1333
+ n && st(n);
1332
1334
  } catch (I) {
1333
1335
  f.error("clear preload page cache error", { error: I });
1334
1336
  }
1335
- const { pages: r, pageIds: l, routeIds: p, routes: y, supportedLocales: A } = t;
1337
+ const { pages: c, pageIds: r, routeIds: p, routes: y, supportedLocales: A } = t;
1336
1338
  if (n === "production") {
1337
1339
  let I = s ?? [], u = null;
1338
- for (const c of p ?? []) {
1339
- const g = y?.[c];
1340
+ for (const l of p ?? []) {
1341
+ const g = y?.[l];
1340
1342
  if (g?.params && g?.params.length > 0 && g?.paramsOptions && g?.paramsOptions.length > 0) {
1341
1343
  const C = Ie({
1342
1344
  basePath: g.path,
@@ -1347,13 +1349,13 @@ async function _e(t, e, {
1347
1349
  currentParams: [],
1348
1350
  currentOptionIds: [],
1349
1351
  result: []
1350
- }), m = Object.fromEntries(C.map((d) => [`${c}-${d.paramOptionIds.join("-")}`, d]));
1351
- u = { ...u || {}, ...m }, s || (I = [...I, ...C.map((d) => `${c}-${d.paramOptionIds.join("-")}`)]);
1352
- } else s || I.push(c);
1352
+ }), m = Object.fromEntries(C.map((d) => [`${l}-${d.paramOptionIds.join("-")}`, d]));
1353
+ u = { ...u || {}, ...m }, s || (I = [...I, ...C.map((d) => `${l}-${d.paramOptionIds.join("-")}`)]);
1354
+ } else s || I.push(l);
1353
1355
  }
1354
1356
  f.info("routeIds to be published: ", I);
1355
- for (const c of I) {
1356
- let g = c;
1357
+ for (const l of I) {
1358
+ let g = l;
1357
1359
  if (g.includes("-")) {
1358
1360
  const [d] = g.split("-");
1359
1361
  g = d;
@@ -1367,61 +1369,61 @@ async function _e(t, e, {
1367
1369
  f.info("delete main route page", g);
1368
1370
  continue;
1369
1371
  }
1370
- if (c.includes("-") && !u?.[c]) {
1371
- const d = e.pageIds.indexOf(c);
1372
- d !== -1 && a && (e.pageIds.splice(d, 1), delete e.pages[c]), f.info("delete page", c);
1372
+ if (l.includes("-") && !u?.[l]) {
1373
+ const d = e.pageIds.indexOf(l);
1374
+ d !== -1 && a && (e.pageIds.splice(d, 1), delete e.pages[l]), f.info("delete page", l);
1373
1375
  continue;
1374
1376
  }
1375
1377
  if (!C.displayTemplateId) {
1376
- f.info("no display template", c);
1378
+ f.info("no display template", l);
1377
1379
  continue;
1378
1380
  }
1379
- const m = r[C.displayTemplateId];
1381
+ const m = c[C.displayTemplateId];
1380
1382
  if (!m) {
1381
- f.info("no template page", c);
1383
+ f.info("no template page", l);
1382
1384
  continue;
1383
1385
  }
1384
- if (e.pageIds.includes(c)) {
1385
- if (f.info("has need update page", c), o === "replace")
1386
- e.pages[c] = fe({
1386
+ if (e.pageIds.includes(l)) {
1387
+ if (f.info("has need update page", l), o === "replace")
1388
+ e.pages[l] = fe({
1387
1389
  page: m,
1388
1390
  route: C,
1389
1391
  state: t,
1390
- routeId: c,
1391
- routePathInfo: u?.[c]
1392
- }), f.info("replace page", c);
1392
+ routeId: l,
1393
+ routePathInfo: u?.[l]
1394
+ }), f.info("replace page", l);
1393
1395
  else if (o === "byUpdateTime") {
1394
1396
  const d = e.pages[C.id];
1395
- (!d || C.updatedAt && C.updatedAt > d.updatedAt) && (e.pages[c] = fe({
1397
+ (!d || C.updatedAt && C.updatedAt > d.updatedAt) && (e.pages[l] = fe({
1396
1398
  page: m,
1397
1399
  route: C,
1398
1400
  state: t,
1399
- routeId: c,
1400
- routePathInfo: u?.[c]
1401
- }), f.info("replace page by update time", c));
1401
+ routeId: l,
1402
+ routePathInfo: u?.[l]
1403
+ }), f.info("replace page by update time", l));
1402
1404
  }
1403
1405
  } else
1404
- e.pageIds.push(c), e.pages[c] = fe({
1406
+ e.pageIds.push(l), e.pages[l] = fe({
1405
1407
  page: m,
1406
1408
  route: C,
1407
1409
  state: t,
1408
- routeId: c,
1409
- routePathInfo: u?.[c]
1410
- }), f.info("add page", c);
1410
+ routeId: l,
1411
+ routePathInfo: u?.[l]
1412
+ }), f.info("add page", l);
1411
1413
  }
1412
1414
  if (a && !s)
1413
- for (const c of e.pageIds)
1414
- I?.includes(c) || (delete e.pages[c], f.info("delete page", c)), e.pageIds = [...e.pageIds].filter((g) => I?.includes(g));
1415
+ for (const l of e.pageIds)
1416
+ I?.includes(l) || (delete e.pages[l], f.info("delete page", l)), e.pageIds = [...e.pageIds].filter((g) => I?.includes(g));
1415
1417
  } else {
1416
- for (const I of l) {
1417
- const u = r[I];
1418
+ for (const I of r) {
1419
+ const u = c[I];
1418
1420
  if (u)
1419
1421
  if (e.pageIds.includes(u.id)) {
1420
1422
  if (o === "replace")
1421
1423
  e.pages[u.id] = u;
1422
1424
  else if (o === "byUpdateTime") {
1423
- const c = e.pages[u.id];
1424
- (!c || u.updatedAt && u.updatedAt > c.updatedAt) && (e.pages[u.id] = u);
1425
+ const l = e.pages[u.id];
1426
+ (!l || u.updatedAt && u.updatedAt > l.updatedAt) && (e.pages[u.id] = u);
1425
1427
  }
1426
1428
  } else
1427
1429
  e.pageIds.push(u.id), e.pages[u.id] = u;
@@ -1433,8 +1435,8 @@ async function _e(t, e, {
1433
1435
  if (o === "replace")
1434
1436
  e.routes[u.id] = u;
1435
1437
  else if (o === "byUpdateTime") {
1436
- const c = e.routes[u.id];
1437
- (!c || u.updatedAt && u.updatedAt > c.updatedAt) && (e.routes[u.id] = u);
1438
+ const l = e.routes[u.id];
1439
+ (!l || u.updatedAt && u.updatedAt > l.updatedAt) && (e.routes[u.id] = u);
1438
1440
  }
1439
1441
  } else
1440
1442
  e.routeIds.push(u.id), e.routes[u.id] = u;
@@ -1447,19 +1449,19 @@ async function _e(t, e, {
1447
1449
  j = Object.fromEntries(
1448
1450
  await Promise.all(
1449
1451
  Object.entries(j).map(async ([I, u]) => {
1450
- const c = await He(u?.data);
1452
+ const l = await Je(u?.data);
1451
1453
  return [
1452
1454
  I,
1453
1455
  {
1454
1456
  ...u,
1455
- data: c
1457
+ data: l
1456
1458
  }
1457
1459
  ];
1458
1460
  })
1459
1461
  )
1460
1462
  ), Object.assign(e.components, j), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ae(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1461
1463
  }
1462
- const He = st(
1464
+ const Je = ot(
1463
1465
  async (t) => {
1464
1466
  if (!Ae(t?.properties))
1465
1467
  return t;
@@ -1467,7 +1469,7 @@ const He = st(
1467
1469
  const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
1468
1470
  if (s || e && e.includes("PROPERTIES_SCHEMA"))
1469
1471
  try {
1470
- const o = await ot(
1472
+ const o = await at(
1471
1473
  e ?? "",
1472
1474
  "PROPERTIES_SCHEMA",
1473
1475
  t.id,
@@ -1490,28 +1492,28 @@ const He = st(
1490
1492
  }
1491
1493
  );
1492
1494
  let re, Q, ie, ce;
1493
- const Je = () => mt({
1495
+ const Ye = () => gt({
1494
1496
  types: [
1495
- { did: Ve, type: Le },
1496
- { did: Lt, type: Le }
1497
+ { did: ze, type: Ue },
1498
+ { did: Lt, type: Ue }
1497
1499
  ]
1498
1500
  }), ss = () => {
1499
- const t = Je(), e = {};
1501
+ const t = Ye(), e = {};
1500
1502
  return t.forEach((s) => {
1501
1503
  const o = se("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), a = o && b(L(o), "../../chunks");
1502
- if (a && M(a)) {
1503
- const n = lt(a);
1504
- for (const r of n)
1505
- e[r] = b(a, r);
1504
+ if (a && $(a)) {
1505
+ const n = pt(a);
1506
+ for (const c of n)
1507
+ e[c] = b(a, c);
1506
1508
  }
1507
1509
  }), e;
1508
1510
  };
1509
- function Ye() {
1511
+ function We() {
1510
1512
  return re = (async () => {
1511
- const t = Je();
1513
+ const t = Ye();
1512
1514
  Q = (await Promise.all(
1513
1515
  t.map(async (s) => {
1514
- const o = s.path ? await Ke(s.path, { importAssets: !1 }) : void 0;
1516
+ const o = s.path ? await He(s.path, { importAssets: !1 }) : void 0;
1515
1517
  return o ? { blockletId: s.did, state: o, blockletTitle: s.title } : void 0;
1516
1518
  })
1517
1519
  )).filter((s) => !!s), ie = Q.reduce(
@@ -1535,7 +1537,7 @@ function Ye() {
1535
1537
  ce = Object.fromEntries(
1536
1538
  await Promise.all(
1537
1539
  Object.entries(e).map(async ([s, o]) => {
1538
- const a = await He(o.component);
1540
+ const a = await Je(o.component);
1539
1541
  return [
1540
1542
  s,
1541
1543
  {
@@ -1549,9 +1551,9 @@ function Ye() {
1549
1551
  })(), re;
1550
1552
  }
1551
1553
  function os(t) {
1552
- const e = Ge(
1554
+ const e = xe(
1553
1555
  async () => {
1554
- await Ye().catch((s) => {
1556
+ await We().catch((s) => {
1555
1557
  f.error("load resource states error", { error: s });
1556
1558
  }), await t?.({
1557
1559
  states: Q,
@@ -1567,9 +1569,9 @@ function os(t) {
1567
1569
  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(he, e);
1568
1570
  };
1569
1571
  }
1570
- const We = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), Xe = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), le = globalThis;
1571
- le[We]?.();
1572
- le[We] = os(async ({ pages: t, components: e }) => {
1572
+ const Xe = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), Qe = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), le = globalThis;
1573
+ le[Xe]?.();
1574
+ le[Xe] = os(async ({ pages: t, components: e }) => {
1573
1575
  const s = await O.getProjectIds();
1574
1576
  f.info(`start update resource states projects(${s.length})`, s), await Promise.race([
1575
1577
  new Promise((o) => {
@@ -1579,7 +1581,7 @@ le[We] = os(async ({ pages: t, components: e }) => {
1579
1581
  }),
1580
1582
  Promise.all(
1581
1583
  s.map(async (o) => {
1582
- Qe({
1584
+ Ze({
1583
1585
  projectId: o,
1584
1586
  pages: t,
1585
1587
  components: e
@@ -1590,8 +1592,8 @@ le[We] = os(async ({ pages: t, components: e }) => {
1590
1592
  f.error("update resource states failed:", o);
1591
1593
  });
1592
1594
  });
1593
- le[Xe]?.();
1594
- le[Xe] = () => {
1595
+ le[Qe]?.();
1596
+ le[Qe] = () => {
1595
1597
  const t = () => {
1596
1598
  O.pageUrlMapCache.clear(), f.info("[Cache CLEAR ALL] clear all page url map cache by env update");
1597
1599
  };
@@ -1609,7 +1611,7 @@ process.on("SIGINT", () => {
1609
1611
  process.on("SIGTERM", () => {
1610
1612
  O.stopPeriodicCheck(), process.exit(0);
1611
1613
  });
1612
- async function Qe({
1614
+ async function Ze({
1613
1615
  projectId: t,
1614
1616
  pages: e,
1615
1617
  components: s
@@ -1622,10 +1624,10 @@ async function Qe({
1622
1624
  if (o.syncedStore.resources.pages = e, (await U.findByPk(t))?.useAllResources)
1623
1625
  o.syncedStore.resources.components = s;
1624
1626
  else {
1625
- const r = (await Oe.findAll({ where: { projectId: t } })).map((p) => p.componentId), l = Object.fromEntries(
1626
- Object.entries(s || {}).filter(([p]) => r.includes(p))
1627
+ const c = (await Ce.findAll({ where: { projectId: t } })).map((p) => p.componentId), r = Object.fromEntries(
1628
+ Object.entries(s || {}).filter(([p]) => c.includes(p))
1627
1629
  );
1628
- o.syncedStore.resources.components = l;
1630
+ o.syncedStore.resources.components = r;
1629
1631
  }
1630
1632
  f.info(`update [${t}] resource states:`, {
1631
1633
  pages: Object.keys(o.syncedStore.resources.pages || {}).length,
@@ -1633,35 +1635,35 @@ async function Qe({
1633
1635
  });
1634
1636
  }
1635
1637
  async function as(t) {
1636
- return Qe({
1638
+ return Ze({
1637
1639
  projectId: t,
1638
1640
  pages: ie,
1639
1641
  components: ce
1640
1642
  });
1641
1643
  }
1642
- async function Ns() {
1644
+ async function _s() {
1643
1645
  f.info("trigger reload all project resource"), E.events.emit(he);
1644
1646
  }
1645
1647
  async function Fs({
1646
1648
  ensureLoaded: t = !0
1647
1649
  } = {}) {
1648
- return t && (re ??= Ye(), await re), { states: Q, pages: ie, components: ce };
1650
+ return t && (re ??= We(), await re), { states: Q, pages: ie, components: ce };
1649
1651
  }
1650
1652
  export {
1651
- Ve as C,
1653
+ ze as C,
1652
1654
  U as P,
1653
- Le as R,
1655
+ Ue as R,
1654
1656
  O as S,
1655
1657
  H as a,
1656
- Ms as b,
1657
- _s as c,
1658
+ $s as b,
1659
+ Ns as c,
1658
1660
  Xt as d,
1659
1661
  Zt as e,
1660
1662
  es as f,
1661
1663
  Fs as g,
1662
- Ke as h,
1664
+ He as h,
1663
1665
  os as i,
1664
- Ns as j,
1666
+ _s as j,
1665
1667
  _e as m,
1666
1668
  ts as t,
1667
1669
  as as u