@blocklet/pages-kit-inner-components 0.6.2 → 0.6.4

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.
Files changed (42) hide show
  1. package/lib/cjs/add-component.js +420 -1
  2. package/lib/cjs/chunks/draft-data-D44_IEV2.js +1 -0
  3. package/lib/cjs/chunks/home-BYk01EUy.js +39 -0
  4. package/lib/cjs/chunks/index-BRgYwvuv.js +475 -0
  5. package/lib/cjs/chunks/publish-button-C8XPA4g_.js +1 -0
  6. package/lib/cjs/chunks/session-BRtsDvA-.js +1 -0
  7. package/lib/cjs/chunks/site-state-BlQzwACl.js +57 -0
  8. package/lib/cjs/chunks/state-B6BF5wJ-.js +1 -0
  9. package/lib/cjs/components.js +1 -0
  10. package/lib/cjs/home.js +1 -1
  11. package/lib/cjs/locales.js +3 -0
  12. package/lib/cjs/project-html.js +4 -4
  13. package/lib/cjs/resources.js +1 -1
  14. package/lib/cjs/setting.js +11 -0
  15. package/lib/cjs/site-state.js +1 -0
  16. package/lib/cjs/theme.js +1 -0
  17. package/lib/cjs/uploader.js +1 -0
  18. package/lib/es/add-component.js +1089 -2
  19. package/lib/es/chunks/{draft-data-bRUHvvzp.js → draft-data-CafrGKeh.js} +4 -5
  20. package/lib/es/chunks/home-DW8SdyfO.js +594 -0
  21. package/lib/es/chunks/index-D5gXPe_7.js +2326 -0
  22. package/lib/es/chunks/{publish-button-Ceet-m88.js → publish-button-XSZrDaTQ.js} +140 -158
  23. package/lib/es/chunks/session-C72Dq8zg.js +19 -0
  24. package/lib/es/chunks/{site-state-Bh8guIeX.js → site-state-BdLTu3Od.js} +201 -170
  25. package/lib/es/chunks/state-0gvZF3k2.js +573 -0
  26. package/lib/es/components.js +24 -0
  27. package/lib/es/home.js +28 -3
  28. package/lib/es/locales.js +1032 -0
  29. package/lib/es/project-html.js +155 -79
  30. package/lib/es/resources.js +137 -93
  31. package/lib/es/setting.js +2294 -0
  32. package/lib/es/site-state.js +48 -0
  33. package/lib/es/theme.js +484 -0
  34. package/lib/es/uploader.js +8 -0
  35. package/package.json +3 -3
  36. package/lib/cjs/chunks/draft-data-CfIMszE7.js +0 -1
  37. package/lib/cjs/chunks/home-DUjl5PbP.js +0 -6
  38. package/lib/cjs/chunks/publish-button-C522nNv6.js +0 -1
  39. package/lib/cjs/chunks/site-state-DDXqWF74.js +0 -57
  40. package/lib/cjs/chunks/state-CtNs8GrN.js +0 -1
  41. package/lib/es/chunks/home-VWWdvIPQ.js +0 -69
  42. package/lib/es/chunks/state-BdNIIXJP.js +0 -502
@@ -1,24 +1,24 @@
1
1
  import { getComponentMountPoint as dt } from "@blocklet/pages-kit/builtin/utils";
2
2
  import { PreloadComponentScriptModule as Ie } from "@blocklet/pages-kit/types";
3
- import { componentUMDName as ft, RenderNestedComponent as ke, mergeComponent as mt, getComponentDependencies as ht } from "@blocklet/pages-kit/utils/property";
3
+ import { componentUMDName as ft, RenderNestedComponent as De, mergeComponent as mt, getComponentDependencies as ht } from "@blocklet/pages-kit/utils/property";
4
4
  import { memoize as gt, BuiltinModules as ge } from "@blocklet/quickjs";
5
5
  import { BuiltinModules as Ee } from "@blocklet/pages-kit/utils/builtin";
6
- import E from "@blocklet/sdk/lib/config";
6
+ import I from "@blocklet/sdk/lib/config";
7
7
  import { LRUCache as le } from "lru-cache";
8
8
  import yt, { Headers as St } from "node-fetch";
9
- import { joinURL as V, getQuery as wt, withQuery as It, parseURL as De, withHttps as Et } from "ufo";
10
- import Pe from "lodash/isEmpty";
9
+ import { joinURL as G, getQuery as wt, withQuery as It, parseURL as Re, withHttps as Et } from "ufo";
10
+ import Ae from "lodash/isEmpty";
11
11
  import { createHash as bt } from "crypto";
12
- import { promises as M, readFileSync as J, mkdtempSync as Pt, existsSync as L, lstatSync as G, rmSync as Je, renameSync as Re, mkdirSync as F, writeFileSync as oe, copyFileSync as At, readdirSync as Ct, createWriteStream as Ot } from "fs";
13
- import Ke, { join as P, dirname as j, basename as x } from "path";
12
+ import { promises as $, readFileSync as J, mkdtempSync as Pt, existsSync as L, lstatSync as V, rmSync as Je, renameSync as je, mkdirSync as F, writeFileSync as oe, copyFileSync as At, readdirSync as Ct, createWriteStream as Ot } from "fs";
13
+ import Ke, { join as P, dirname as x, basename as j } from "path";
14
14
  import vt from "lodash/isNil";
15
15
  import Tt from "@blocklet/logger";
16
16
  import { isRelativeModule as kt, createBuiltinModuleTransformer as Dt } from "@blocklet/pages-kit/utils/typescript/builtin-module-transformer";
17
- import { getResources as Rt, getComponentWebEndpoint as xt, call as jt } from "@blocklet/sdk/lib/component";
18
- import { getYjsValue as z, syncedStore as $t } from "@syncedstore/core";
17
+ import { getResources as Rt, getComponentWebEndpoint as jt, call as xt } from "@blocklet/sdk/lib/component";
18
+ import { getYjsValue as z, syncedStore as Mt } from "@syncedstore/core";
19
19
  import * as _ from "yjs";
20
- import { setPageDataSource as Mt } from "@blocklet/pages-kit/utils/data-source";
21
- import { getRouteMetaDataByOptionIds as Lt, generateParamCombinations as Ae } from "@blocklet/pages-kit/utils/route";
20
+ import { setPageDataSource as $t } from "@blocklet/pages-kit/utils/data-source";
21
+ import { getRouteMetaDataByOptionIds as Lt, generateParamCombinations as Ce } from "@blocklet/pages-kit/utils/route";
22
22
  import { cloneDeep as Nt } from "lodash";
23
23
  import { nextId as xe } from "@blocklet/pages-kit/utils/common";
24
24
  import { unzipSection as _t } from "@blocklet/pages-kit/utils/page-model";
@@ -28,11 +28,11 @@ import * as ye from "lib0/decoding";
28
28
  import * as D from "lib0/encoding";
29
29
  import Ft from "lodash/cloneDeep";
30
30
  import ze from "lodash/debounce";
31
- import Ce from "lodash/get";
32
- import je from "lodash/set";
31
+ import Oe from "lodash/get";
32
+ import Me from "lodash/set";
33
33
  import Bt from "lodash/union";
34
- import Vt from "p-limit";
35
- import { DataTypes as k, Sequelize as Gt, Model as He, Op as We } from "sequelize";
34
+ import Gt from "p-limit";
35
+ import { DataTypes as k, Sequelize as Vt, Model as He, Op as We } from "sequelize";
36
36
  import { pipeline as Jt } from "stream/promises";
37
37
  import { x as Kt } from "tar";
38
38
  import zt from "wait-on";
@@ -41,16 +41,16 @@ import { writeUpdate as qt, writeSyncStep1 as Qt, readSyncMessage as Xt } from "
41
41
  import * as K from "yaml";
42
42
  import "sqlite3";
43
43
  import "@blocklet/pages-kit/types/state";
44
- E.env.mode;
45
- E.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY;
46
- E.env.OPENAI_BASE_URL || process.env.OPENAI_BASE_URL;
47
- E.env.TRANSLATE_ADDITIONAL_PROMPT || process.env.TRANSLATE_ADDITIONAL_PROMPT;
48
- E.env.PAGE_CONTENT_ADDITIONAL_PROMPT || process.env.PAGE_CONTENT_ADDITIONAL_PROMPT;
44
+ I.env.mode;
45
+ I.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY;
46
+ I.env.OPENAI_BASE_URL || process.env.OPENAI_BASE_URL;
47
+ I.env.TRANSLATE_ADDITIONAL_PROMPT || process.env.TRANSLATE_ADDITIONAL_PROMPT;
48
+ I.env.PAGE_CONTENT_ADDITIONAL_PROMPT || process.env.PAGE_CONTENT_ADDITIONAL_PROMPT;
49
49
  const Zt = "image-bin";
50
- E.env.INIT_TEMPLATE_PATH;
51
- const Ye = process.env.DATABASE_URL || Ke.join(E.env.dataDir, "db/pages-kit.db"), Me = E, Ns = () => E.env.tenantMode === "multiple", _s = () => (vt(Me.env.preferences.multiTenantAllProjectAccessPassports) ? [] : Me.env.preferences.multiTenantAllProjectAccessPassports?.split(",")) || [], eo = Ke.join(E.env.dataDir, "fs-memoize-cache"), to = E.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", f = Tt("pages-kit"), oo = k.sqlite.DATE.parse;
50
+ I.env.INIT_TEMPLATE_PATH;
51
+ const Ye = process.env.DATABASE_URL || Ke.join(I.env.dataDir, "db/pages-kit.db"), Le = I, Ns = () => I.env.tenantMode === "multiple", _s = () => (vt(Le.env.preferences.multiTenantAllProjectAccessPassports) ? [] : Le.env.preferences.multiTenantAllProjectAccessPassports?.split(",")) || [], eo = Ke.join(I.env.dataDir, "fs-memoize-cache"), to = I.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", f = Tt("pages-kit"), oo = k.sqlite.DATE.parse;
52
52
  k.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : oo(t, e);
53
- const U = new Gt({
53
+ const U = new Vt({
54
54
  dialect: "sqlite",
55
55
  storage: Ye,
56
56
  benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
@@ -95,10 +95,10 @@ setInterval(
95
95
  60 * 1e3 * 10
96
96
  // 10 minutes
97
97
  );
98
- class Oe extends He {
98
+ class ve extends He {
99
99
  // Foreign key to Component
100
100
  }
101
- Oe.init(
101
+ ve.init(
102
102
  {
103
103
  id: {
104
104
  type: k.UUID,
@@ -159,6 +159,8 @@ N.init(
159
159
  defaultValue: {},
160
160
  get() {
161
161
  const t = this.getDataValue("relatedBlocklets");
162
+ if (typeof t == "object")
163
+ return t ?? {};
162
164
  try {
163
165
  return t ? JSON.parse(t) : {};
164
166
  } catch (e) {
@@ -179,6 +181,8 @@ N.init(
179
181
  defaultValue: {},
180
182
  get() {
181
183
  const t = this.getDataValue("productionState");
184
+ if (typeof t == "object")
185
+ return t ?? {};
182
186
  try {
183
187
  return t ? JSON.parse(t) : {};
184
188
  } catch (e) {
@@ -196,36 +200,36 @@ N.init(
196
200
  },
197
201
  { sequelize: U, paranoid: !0 }
198
202
  );
199
- N.hasMany(Oe, {
203
+ N.hasMany(ve, {
200
204
  foreignKey: "projectId",
201
205
  as: "components"
202
206
  });
203
207
  const no = eo, ro = to, ne = 30 * 24 * 60 * 60 * 1e3, ao = 24 * 60 * 60 * 1e3, qe = async (t = "") => {
204
208
  const e = P(no, t);
205
209
  try {
206
- if (!(await M.stat(e)).isDirectory())
210
+ if (!(await $.stat(e)).isDirectory())
207
211
  throw new Error(`${e} is not a directory`);
208
212
  } catch {
209
- await M.mkdir(e, { recursive: !0 });
213
+ await $.mkdir(e, { recursive: !0 });
210
214
  }
211
215
  return e;
212
- }, Le = (t, ...e) => t.keyGenerator ? t.keyGenerator(...e) : JSON.stringify([t.subdir || "", ...e]), io = (t, e) => {
216
+ }, Ne = (t, ...e) => t.keyGenerator ? t.keyGenerator(...e) : JSON.stringify([t.subdir || "", ...e]), io = (t, e) => {
213
217
  const o = bt("md5").update(e).digest("hex");
214
218
  return P(t, `${ro}-${o}.json`);
215
219
  }, co = async (t = "") => {
216
220
  const e = await qe(t), o = Date.now();
217
221
  try {
218
- const s = await M.readdir(e);
222
+ const s = await $.readdir(e);
219
223
  await Promise.all(
220
224
  s.filter((n) => n.endsWith(".json")).map(async (n) => {
221
225
  const r = P(e, n);
222
226
  try {
223
- const c = await M.readFile(r, "utf-8"), a = JSON.parse(c);
224
- a.createdAt && o - a.createdAt > ne && await M.unlink(r);
227
+ const c = await $.readFile(r, "utf-8"), a = JSON.parse(c);
228
+ a.createdAt && o - a.createdAt > ne && await $.unlink(r);
225
229
  } catch {
226
230
  try {
227
- const a = await M.stat(r);
228
- o - a.mtimeMs > ne && await M.unlink(r);
231
+ const a = await $.stat(r);
232
+ o - a.mtimeMs > ne && await $.unlink(r);
229
233
  } catch {
230
234
  }
231
235
  }
@@ -245,22 +249,22 @@ const no = eo, ro = to, ne = 30 * 24 * 60 * 60 * 1e3, ao = 24 * 60 * 60 * 1e3, q
245
249
  function ue(t, e) {
246
250
  return e.subdir && po(e.subdir), gt(
247
251
  async (...s) => {
248
- const n = await qe(e.subdir || ""), r = Le(e, ...s), c = io(n, r);
252
+ const n = await qe(e.subdir || ""), r = Ne(e, ...s), c = io(n, r);
249
253
  try {
250
- const a = await M.readFile(c, "utf-8"), { value: l, createdAt: d } = JSON.parse(a);
254
+ const a = await $.readFile(c, "utf-8"), { value: l, createdAt: d } = JSON.parse(a);
251
255
  if (d && Date.now() - d > ne)
252
- throw await M.unlink(c).catch(() => {
256
+ throw await $.unlink(c).catch(() => {
253
257
  }), new Error("Cache expired");
254
258
  return l;
255
259
  } catch {
256
260
  const l = await t(...s), d = JSON.stringify({ value: l, createdAt: Date.now() });
257
- return M.writeFile(c, d, "utf-8").catch((I) => {
258
- console.error("Failed to write fs cache:", I);
261
+ return $.writeFile(c, d, "utf-8").catch((E) => {
262
+ console.error("Failed to write fs cache:", E);
259
263
  }), l;
260
264
  }
261
265
  },
262
266
  {
263
- keyGenerator: (...s) => Le(e, ...s),
267
+ keyGenerator: (...s) => Ne(e, ...s),
264
268
  lruOptions: e.lruOptions || {
265
269
  max: 100,
266
270
  ttl: ne
@@ -280,7 +284,7 @@ const Qe = async () => await import("typescript"), lo = async () => await import
280
284
  }),
281
285
  (l) => {
282
286
  l.walkRules((d) => {
283
- d.selectors = d.selectors.map((I) => I.replace(/\.(.+)/g, `${s}.$1,${s} .$1`));
287
+ d.selectors = d.selectors.map((E) => E.replace(/\.(.+)/g, `${s}.$1,${s} .$1`));
284
288
  });
285
289
  }
286
290
  // FIXME: cssnano use browserslist, it is not working with the fs isolation
@@ -292,7 +296,7 @@ const Qe = async () => await import("typescript"), lo = async () => await import
292
296
 
293
297
  ${t}
294
298
  `;
295
- }, Ne = ue(
299
+ }, _e = ue(
296
300
  async (t, e) => {
297
301
  const o = await Qe();
298
302
  let s = o.transpileModule(t, {
@@ -332,13 +336,13 @@ ${t}
332
336
  name: "vfs",
333
337
  setup(l) {
334
338
  let d = null;
335
- l.onResolve({ filter: /.*/ }, (I) => I.path === "index.tsx" ? { path: "index.tsx", namespace: "vfs" } : I.path === "./component" ? { path: "component.tsx", namespace: "vfs" } : null), l.onLoad({ filter: /.*/, namespace: "vfs" }, async (I) => {
336
- if (I.path === "index.tsx")
339
+ l.onResolve({ filter: /.*/ }, (E) => E.path === "index.tsx" ? { path: "index.tsx", namespace: "vfs" } : E.path === "./component" ? { path: "component.tsx", namespace: "vfs" } : null), l.onLoad({ filter: /.*/, namespace: "vfs" }, async (E) => {
340
+ if (E.path === "index.tsx")
337
341
  return { contents: `export { ${e} } from './component'`, loader: "tsx" };
338
- if (I.path === "component.tsx")
342
+ if (E.path === "component.tsx")
339
343
  return { contents: t, loader: "tsx" };
340
- if (kt(I.path)) {
341
- const h = I.path.split("/").pop();
344
+ if (kt(E.path)) {
345
+ const h = E.path.split("/").pop();
342
346
  if (d || (d = await Qo({ ensureLoaded: !1 })), d?.chunks?.[h])
343
347
  try {
344
348
  const S = J(d.chunks[h], "utf-8");
@@ -405,7 +409,7 @@ const q = new le({
405
409
  max: 100,
406
410
  ttl: 1e3 * 60 * 60 * 24
407
411
  // 24 hours
408
- }), Eo = 60 * 60, _e = 10;
412
+ }), Eo = 60 * 60, Ue = 10;
409
413
  function bo(t) {
410
414
  f.info("clear preload components cache", { cacheKey: t }), q.delete(t);
411
415
  }
@@ -471,19 +475,19 @@ async function Us({
471
475
  )).filter((p) => !!p), d = Object.values(
472
476
  l.reduce((p, i) => ({ ...p, ...i.preload.components }), {})
473
477
  );
474
- async function I() {
478
+ async function E() {
475
479
  const p = await Promise.all(
476
480
  d.map(async (i) => {
477
481
  const y = ft({ componentId: i.component.id }), A = r === Ie.ESM ? {
478
482
  module: r,
479
- script: await Ne(i.script, {
483
+ script: await _e(i.script, {
480
484
  componentId: i.component.id,
481
485
  module: r,
482
486
  tailwind: t !== "draft"
483
487
  })
484
488
  } : {
485
489
  module: r,
486
- script: await Ne(i.script, {
490
+ script: await _e(i.script, {
487
491
  componentId: i.component.id,
488
492
  module: r,
489
493
  moduleName: y,
@@ -496,7 +500,7 @@ async function Us({
496
500
  );
497
501
  return Object.fromEntries(p);
498
502
  }
499
- const h = await I();
503
+ const h = await E();
500
504
  return {
501
505
  config: { defaultLocale: a, supportedLocales: c },
502
506
  components: h,
@@ -517,7 +521,7 @@ async function Co({
517
521
  }) {
518
522
  const { supportedLocales: c } = e, a = re({ state: e, componentId: o });
519
523
  if (!a) return null;
520
- const l = c.some((I) => I.locale === s) ? s : n;
524
+ const l = c.some((E) => E.locale === s) ? s : n;
521
525
  if (!l) return null;
522
526
  const d = await et({ req: t, state: e, componentId: o, locale: l, defaultLocale: n, properties: r });
523
527
  return d ? {
@@ -538,20 +542,20 @@ async function et({
538
542
  if (e > Oo) throw new RangeError("max component depth exceeded");
539
543
  const a = vo({ state: o, componentId: s, properties: c, locale: n });
540
544
  if (!a) return null;
541
- const { props: l, component: d } = a, I = {
545
+ const { props: l, component: d } = a, E = {
542
546
  locale: n || r,
543
547
  components: { [a.component.id]: { component: a.component, script: a.script } },
544
548
  props: { ...l }
545
549
  };
546
550
  try {
547
551
  const h = Io(d.renderer) ? d.renderer.getServerSideProps : void 0, S = await To({ ...a, req: t, serverSideProps: h });
548
- S?.props && Object.assign(I.props, S.props);
552
+ S?.props && Object.assign(E.props, S.props);
549
553
  } catch (h) {
550
554
  f.error("preload data at server side error", { componentId: s, name: a.component.name }, { error: h });
551
555
  }
552
556
  return await Promise.all(
553
557
  Object.entries(l).map(async ([h, S]) => {
554
- if (S?.type === ke) {
558
+ if (S?.type === De) {
555
559
  const p = await et({
556
560
  req: t,
557
561
  depth: e + 1,
@@ -561,16 +565,16 @@ async function et({
561
565
  defaultLocale: r,
562
566
  properties: S.properties
563
567
  });
564
- p && (Object.assign(I.components, p.components), Object.assign(I.props, {
568
+ p && (Object.assign(E.components, p.components), Object.assign(E.props, {
565
569
  [h]: {
566
- type: ke,
570
+ type: De,
567
571
  componentId: S.componentId,
568
572
  props: p.props
569
573
  }
570
574
  }));
571
575
  }
572
576
  })
573
- ), I;
577
+ ), E;
574
578
  }
575
579
  function vo({
576
580
  state: t,
@@ -592,6 +596,10 @@ function vo({
592
596
  function re({ state: t, componentId: e }) {
593
597
  return t.components[e]?.data ?? t.resources.components?.[e]?.component;
594
598
  }
599
+ function Fs({ state: t, name: e }) {
600
+ const o = e.toLowerCase();
601
+ return Object.values(t.components).find((s) => s.data.name?.toLowerCase() === o)?.data ?? (t.resources.components && Object.values(t.resources.components).find((s) => s.component.name?.toLowerCase() === o))?.component;
602
+ }
595
603
  async function To({
596
604
  component: t,
597
605
  script: e,
@@ -606,7 +614,7 @@ async function To({
606
614
  const a = (r.match(/export\s*{\s*(\w+)\s+as\s+getServerSideProps\s*}/) || r.match(/export\s*{\s*getServerSideProps\s*}/))?.[1] || "getServerSideProps", l = new Promise((h) => {
607
615
  setTimeout(() => {
608
616
  h({});
609
- }, _e * 1e3);
617
+ }, Ue * 1e3);
610
618
  }), d = await Ze();
611
619
  return await Promise.race([
612
620
  l,
@@ -641,7 +649,7 @@ export async function getServerSidePropsWrapper(props) {
641
649
  return ge[h];
642
650
  if (h in Ee) {
643
651
  const S = Ee[h];
644
- return Pe(S) ? void 0 : S;
652
+ return Ae(S) ? void 0 : S;
645
653
  }
646
654
  },
647
655
  global: {
@@ -659,7 +667,7 @@ export async function getServerSidePropsWrapper(props) {
659
667
  }
660
668
  },
661
669
  getComponentMountPoint: dt,
662
- joinURL: V,
670
+ joinURL: G,
663
671
  withQuery: It,
664
672
  getQuery: wt
665
673
  },
@@ -668,10 +676,10 @@ export async function getServerSidePropsWrapper(props) {
668
676
  {
669
677
  // NOTE: IMPORTANT! place location and fetch (has side effect) at the args not global
670
678
  // because the global is shared between all runtime and just init once
671
- location: { href: V(Et(s.hostname), s.originalUrl) },
679
+ location: { href: G(Et(s.hostname), s.originalUrl) },
672
680
  fetch: (h, { ...S } = {}) => {
673
- const p = typeof h == "string" && h.startsWith("/") ? V(E.env.appUrl, h) : h;
674
- if (typeof p == "string" && De(p).host === De(E.env.appUrl).host) {
681
+ const p = typeof h == "string" && h.startsWith("/") ? G(I.env.appUrl, h) : h;
682
+ if (typeof p == "string" && Re(p).host === Re(I.env.appUrl).host) {
675
683
  const i = s.get("cookie");
676
684
  if (i) {
677
685
  const y = new St(S.headers);
@@ -680,7 +688,7 @@ export async function getServerSidePropsWrapper(props) {
680
688
  }
681
689
  return yt(p, {
682
690
  ...S,
683
- timeout: _e * 1e3
691
+ timeout: Ue * 1e3
684
692
  }).then((i) => ({
685
693
  ok: i.ok,
686
694
  status: i.status,
@@ -721,14 +729,14 @@ const ko = ue(
721
729
  {
722
730
  subdir: "getExportSchemaValueFromCode"
723
731
  }
724
- ), Do = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Ue = "page", Fe = "trigger-reload-project-resource", tt = Do, Ro = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM";
732
+ ), Bs = (t) => !!(t.version && t.version >= 2), Do = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Fe = "page", be = "trigger-reload-project-resource", tt = Do, Ro = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM";
725
733
  function ae(t) {
726
734
  t.observeDeep((e) => {
727
735
  e.some((o) => o.changes.keys.has("updatedAt") || o.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
728
736
  });
729
737
  }
730
738
  function ot() {
731
- return Pt(P(E.env.dataDir, "tmp-"));
739
+ return Pt(P(I.env.dataDir, "tmp-"));
732
740
  }
733
741
  function ie(t, e, o = []) {
734
742
  return Array.isArray(t) ? t.flatMap((s, n) => ie(s, e, [...o, n])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([s, n]) => ie(n, e, [...o, s])) : e(t) ? [o] : [];
@@ -736,7 +744,7 @@ function ie(t, e, o = []) {
736
744
  function R(t) {
737
745
  return t.filter((e) => e != null);
738
746
  }
739
- function xo(t) {
747
+ function jo(t) {
740
748
  t.pages && Object.keys(t.pages).forEach((o) => {
741
749
  const s = z(t.pages[o]);
742
750
  s && s instanceof _.Map && ae(s);
@@ -751,7 +759,7 @@ function xo(t) {
751
759
  });
752
760
  });
753
761
  }
754
- function jo(t) {
762
+ function xo(t) {
755
763
  t.routes && Object.keys(t.routes).forEach((o) => {
756
764
  const s = z(t.routes?.[o]);
757
765
  s && s instanceof _.Map && ae(s);
@@ -766,7 +774,7 @@ function jo(t) {
766
774
  });
767
775
  });
768
776
  }
769
- function $o(t, e) {
777
+ function Mo(t, e) {
770
778
  for (const o of e || Object.keys(t.routes || {})) {
771
779
  let s = o, n = [];
772
780
  if (o.includes("-")) {
@@ -783,7 +791,7 @@ function $o(t, e) {
783
791
  c && (c.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
784
792
  }
785
793
  if (!e) {
786
- const c = Ae({
794
+ const c = Ce({
787
795
  basePath: r.path,
788
796
  params: r.params,
789
797
  routeId: r.id,
@@ -825,7 +833,7 @@ function Se({
825
833
  const l = e.dataSource.pathDataMappings?.[a]?.dataCache?.[c.locale] ?? e.dataSource.pathDataMappings?.[a]?.dataCache?.[o.config.defaultLocale || "en"];
826
834
  if (!l)
827
835
  continue;
828
- Mt(r, o, c.locale, l);
836
+ $t(r, o, c.locale, l);
829
837
  }
830
838
  n && n.routeMetaData && (n.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
831
839
  }
@@ -836,7 +844,7 @@ const H = new le({
836
844
  ttl: 10 * 60 * 1e3
837
845
  // 10 minutes
838
846
  });
839
- function Mo(t, e = []) {
847
+ function $o(t, e = []) {
840
848
  let o = 0;
841
849
  const s = Array.from(H.keys()), n = [];
842
850
  for (const r of t) {
@@ -880,12 +888,12 @@ function No() {
880
888
  const t = H.size;
881
889
  return H.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
882
890
  }
883
- E.events.on(E.Events.envUpdate, No);
884
- const { uploadToMediaKit: _o } = require("@blocklet/uploader-server"), ve = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, Q = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, Be = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Uo = 1e4, Fo = 3e4, Z = 0, we = 1, Bo = 0, Vo = 1, st = E, ee = P(process.env.BLOCKLET_DATA_DIR, "site-state");
891
+ I.events.on(I.Events.envUpdate, No);
892
+ const { uploadToMediaKit: _o } = require("@blocklet/uploader-server"), Te = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, Q = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, Be = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Uo = 1e4, Fo = 3e4, Z = 0, we = 1, Bo = 0, Go = 1, st = I, ee = P(process.env.BLOCKLET_DATA_DIR, "site-state"), Gs = ["production", "draft"], Vs = ["production"];
885
893
  function ce(t) {
886
894
  return t?.replace(/\//g, "|") || "";
887
895
  }
888
- function Go() {
896
+ function Vo() {
889
897
  const t = st.env.languages.map((o) => ({ locale: o.code, name: o.name })), e = t[0]?.locale;
890
898
  return {
891
899
  pageIds: [],
@@ -903,7 +911,7 @@ function Go() {
903
911
  class v extends _.Doc {
904
912
  constructor(e) {
905
913
  super(), this.options = e, L(this.draftYjsFilePath) && _.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore = Ut(
906
- $t(
914
+ Mt(
907
915
  {
908
916
  pages: {},
909
917
  pageIds: [],
@@ -939,7 +947,7 @@ class v extends _.Doc {
939
947
  throw new Error("Should provide project context");
940
948
  try {
941
949
  const o = P(ee, e), s = P(ee, `@del-${e}`);
942
- Re(o, s);
950
+ je(o, s);
943
951
  } catch (o) {
944
952
  f.error("Failed to safe delete project state dir:", o);
945
953
  }
@@ -975,15 +983,15 @@ class v extends _.Doc {
975
983
  static async getProductionState(e) {
976
984
  return (await N.findByPk(e, {
977
985
  attributes: ["productionState"]
978
- }))?.productionState ?? Go();
986
+ }))?.productionState ?? Vo();
979
987
  }
980
988
  destroy() {
981
989
  this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((o, s) => this.closeConn(s)), this.awareness.destroy();
982
- const e = x(this.options.path);
990
+ const e = j(this.options.path);
983
991
  delete v.sharedInstances[e], super.destroy();
984
992
  }
985
993
  initObserver() {
986
- xo(this.syncedStore), jo(this.syncedStore);
994
+ jo(this.syncedStore), xo(this.syncedStore);
987
995
  }
988
996
  get draftYjsFilePath() {
989
997
  return P(this.options.path, "draft.yjs");
@@ -998,13 +1006,13 @@ class v extends _.Doc {
998
1006
  async getState(e) {
999
1007
  if (e === "draft")
1000
1008
  return JSON.parse(JSON.stringify(this.syncedStore));
1001
- const o = x(this.options.path);
1009
+ const o = j(this.options.path);
1002
1010
  return v.getProductionState(o);
1003
1011
  }
1004
1012
  async setState(e, o) {
1005
1013
  const s = await Ho(o, { exportAssets: !1, includeResources: !0 }), n = this.getPublishDir(e);
1006
- if (F(j(n), { recursive: !0 }), Je(n, { force: !0, recursive: !0 }), Re(s, n), e === "production") {
1007
- const r = x(this.options.path);
1014
+ if (F(x(n), { recursive: !0 }), Je(n, { force: !0, recursive: !0 }), je(s, n), e === "production") {
1015
+ const r = j(this.options.path);
1008
1016
  v.pageUrlMapCache.delete(r), await N.update({ productionState: o }, { where: { id: r } });
1009
1017
  }
1010
1018
  }
@@ -1066,7 +1074,7 @@ class v extends _.Doc {
1066
1074
  }
1067
1075
  };
1068
1076
  send = (e, o) => {
1069
- e.readyState !== Bo && e.readyState !== Vo && this.closeConn(e);
1077
+ e.readyState !== Bo && e.readyState !== Go && this.closeConn(e);
1070
1078
  try {
1071
1079
  e.send(o, (s) => {
1072
1080
  s && this.closeConn(e);
@@ -1089,7 +1097,7 @@ class v extends _.Doc {
1089
1097
  // 调度延迟释放
1090
1098
  scheduleRelease() {
1091
1099
  this.cancelRelease();
1092
- const e = x(this.options.path);
1100
+ const e = j(this.options.path);
1093
1101
  this.releaseTimer = setTimeout(() => {
1094
1102
  f.info(`[SiteState] releasing instance due to no active connections: ${e}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
1095
1103
  }, v.RELEASE_DELAY), f.info(`[SiteState] scheduled release for project ${e} in ${v.RELEASE_DELAY / 1e3}s`);
@@ -1098,19 +1106,19 @@ class v extends _.Doc {
1098
1106
  cancelRelease() {
1099
1107
  if (this.releaseTimer) {
1100
1108
  clearTimeout(this.releaseTimer), this.releaseTimer = void 0;
1101
- const e = x(this.options.path);
1109
+ const e = j(this.options.path);
1102
1110
  f.info(`[SiteState] cancelled scheduled release for project ${e}`);
1103
1111
  }
1104
1112
  }
1105
1113
  autoSave = ze(() => {
1106
- F(j(this.draftYjsFilePath), { recursive: !0 }), oe(this.draftYjsFilePath, _.encodeStateAsUpdate(this));
1114
+ F(x(this.draftYjsFilePath), { recursive: !0 }), oe(this.draftYjsFilePath, _.encodeStateAsUpdate(this));
1107
1115
  }, Uo);
1108
1116
  save = ({ flush: e = !1 } = {}) => {
1109
1117
  this.autoSave(), e && this.autoSave.flush();
1110
1118
  };
1111
1119
  publish = async ({ mode: e, routes: o }) => {
1112
1120
  const s = await this.getState("draft"), n = await this.getState("production");
1113
- await Ge(s, n, { routes: o, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), n.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), $o(this.syncedStore, o), await this.setState(e, n), await this.clearPageCacheForRoutes(o, n);
1121
+ await Ve(s, n, { routes: o, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), n.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Mo(this.syncedStore, o), await this.setState(e, n), await this.clearPageCacheForRoutes(o, n);
1114
1122
  };
1115
1123
  mergeState = async (e, o) => {
1116
1124
  const s = JSON.parse(JSON.stringify(o));
@@ -1119,7 +1127,7 @@ class v extends _.Doc {
1119
1127
  e.config.fontFamily.title = n?.title || r?.title, e.config.fontFamily.description = n?.description || r?.description, await new Promise((c, a) => {
1120
1128
  this.transact(async () => {
1121
1129
  try {
1122
- const l = await Ge(e, o);
1130
+ const l = await Ve(e, o);
1123
1131
  c(l);
1124
1132
  } catch (l) {
1125
1133
  a(l);
@@ -1128,7 +1136,7 @@ class v extends _.Doc {
1128
1136
  });
1129
1137
  };
1130
1138
  clearPageCacheForRoutes = async (e, o) => {
1131
- const s = x(this.options.path), r = (await N.findByPk(s))?.slug || s;
1139
+ const s = j(this.options.path), r = (await N.findByPk(s))?.slug || s;
1132
1140
  if (f.info(`[SiteState] clearing page cache for project ${s}, routes:`, e || []), !e || e.length === 0) {
1133
1141
  Lo({
1134
1142
  projectId: s,
@@ -1143,7 +1151,7 @@ class v extends _.Doc {
1143
1151
  r && r !== s && (r === "/" ? a.push(h) : a.push(`/${r}${h}`)), a.push(`/${s}${h}`);
1144
1152
  }
1145
1153
  if (f.info(`[SiteState] clearing page cache for project ${s}, pathPatterns:`, a), a.length > 0) {
1146
- const d = Mo(a, c);
1154
+ const d = $o(a, c);
1147
1155
  f.info(`[SiteState] cleared ${d} page cache entries for project ${s}, routes:`, e);
1148
1156
  }
1149
1157
  };
@@ -1221,30 +1229,30 @@ class v extends _.Doc {
1221
1229
  });
1222
1230
  await Promise.all(
1223
1231
  r.map(async (c) => {
1224
- const a = c.id, l = c.slug || a, d = {}, I = e === "production" && c?.productionState ? c.productionState : await v.getStateByProjectId(c.id, e), h = Bt(
1225
- E.env.languages.map((p) => p.code),
1226
- I.supportedLocales.map((p) => p.locale)
1232
+ const a = c.id, l = c.slug || a, d = {}, E = e === "production" && c?.productionState ? c.productionState : await v.getStateByProjectId(c.id, e), h = Bt(
1233
+ I.env.languages.map((p) => p.code),
1234
+ E.supportedLocales.map((p) => p.locale)
1227
1235
  ), S = (p, i) => {
1228
- l && (d[V("/", l, p)] = {
1236
+ l && (d[G("/", l, p)] = {
1229
1237
  ...i,
1230
1238
  shouldRedirect: !0,
1231
1239
  mainPage: !0
1232
- }), d[V("/", a, p)] = {
1240
+ }), d[G("/", a, p)] = {
1233
1241
  ...i,
1234
1242
  shouldRedirect: !0,
1235
1243
  mainPage: !0
1236
1244
  };
1237
1245
  for (const y of h) {
1238
1246
  const A = { ...i, locale: y };
1239
- d[V("/", y, a, p)] = A, l && (d[V("/", y, l, p)] = A);
1247
+ d[G("/", y, a, p)] = A, l && (d[G("/", y, l, p)] = A);
1240
1248
  }
1241
1249
  };
1242
1250
  if (e === "draft")
1243
- for (const p of I.routeIds || []) {
1244
- const i = I?.routes?.[p];
1251
+ for (const p of E.routeIds || []) {
1252
+ const i = E?.routes?.[p];
1245
1253
  if (!i) continue;
1246
1254
  if (i.params && i.params.length > 0) {
1247
- const g = Ae({
1255
+ const g = Ce({
1248
1256
  basePath: i.path,
1249
1257
  params: i.params,
1250
1258
  routeId: i.id,
@@ -1264,7 +1272,7 @@ class v extends _.Doc {
1264
1272
  // default locale
1265
1273
  defaultLocale: h?.[0],
1266
1274
  locales: h,
1267
- publishedAt: I.config.publishedAt,
1275
+ publishedAt: E.config.publishedAt,
1268
1276
  isPublic: i.isPublic && m?.routeMetaData?.isPublic
1269
1277
  };
1270
1278
  S(w, C);
@@ -1279,13 +1287,13 @@ class v extends _.Doc {
1279
1287
  // default locale
1280
1288
  defaultLocale: h?.[0],
1281
1289
  locales: h,
1282
- publishedAt: I.config.publishedAt,
1290
+ publishedAt: E.config.publishedAt,
1283
1291
  isPublic: i.isPublic
1284
1292
  };
1285
1293
  S(y, A);
1286
1294
  }
1287
- for (const p of I.pageIds) {
1288
- const i = I.pages[p];
1295
+ for (const p of E.pageIds) {
1296
+ const i = E.pages[p];
1289
1297
  if (!i || e === "production" && !i.isPublic)
1290
1298
  continue;
1291
1299
  const y = i.slug, A = c.slug || a, g = {
@@ -1296,7 +1304,7 @@ class v extends _.Doc {
1296
1304
  // default locale
1297
1305
  defaultLocale: h?.[0],
1298
1306
  locales: h,
1299
- publishedAt: I.config.publishedAt,
1307
+ publishedAt: E.config.publishedAt,
1300
1308
  isPublic: i.isPublic,
1301
1309
  templateConfig: i.templateConfig
1302
1310
  };
@@ -1362,7 +1370,7 @@ class v extends _.Doc {
1362
1370
  }
1363
1371
  }
1364
1372
  async function Jo(t, e, o) {
1365
- if (!t || !L(t) || !G(t).isFile())
1373
+ if (!t || !L(t) || !V(t).isFile())
1366
1374
  return null;
1367
1375
  let s = o[t];
1368
1376
  return s || (s = (async () => {
@@ -1377,9 +1385,9 @@ async function Jo(t, e, o) {
1377
1385
  })(), o[t] = s), s;
1378
1386
  }
1379
1387
  const Ko = async (t, e) => {
1380
- const o = x(t), s = await jt({
1388
+ const o = j(t), s = await xt({
1381
1389
  name: tt,
1382
- path: V("/uploads", o),
1390
+ path: G("/uploads", o),
1383
1391
  responseType: "stream",
1384
1392
  method: "GET"
1385
1393
  });
@@ -1392,7 +1400,7 @@ const Ko = async (t, e) => {
1392
1400
  await Promise.all(
1393
1401
  t.map(async (o) => {
1394
1402
  try {
1395
- await Ko(o, P(e, x(o)));
1403
+ await Ko(o, P(e, j(o)));
1396
1404
  } catch (s) {
1397
1405
  f.error(`Failed to export assets: ${o}, ${s}`);
1398
1406
  }
@@ -1400,42 +1408,42 @@ const Ko = async (t, e) => {
1400
1408
  );
1401
1409
  };
1402
1410
  function nt(t) {
1403
- return ve.test(t) ? [t] : Q.test(t) ? (Be.lastIndex = 0, Array.from(t.matchAll(Be)).map((o) => o[1]).filter((o) => !!o)) : [];
1411
+ return Te.test(t) ? [t] : Q.test(t) ? (Be.lastIndex = 0, Array.from(t.matchAll(Be)).map((o) => o[1]).filter((o) => !!o)) : [];
1404
1412
  }
1405
1413
  async function te(t, e, o) {
1406
1414
  const { getFilename: s, exportAssets: n } = o, r = P(e, s(t));
1407
- if (F(j(r), { recursive: !0 }), oe(r, K.stringify(t)), n) {
1415
+ if (F(x(r), { recursive: !0 }), oe(r, K.stringify(t)), n) {
1408
1416
  const a = ie(
1409
1417
  t,
1410
- (l) => typeof l == "string" && (ve.test(l) || Q.test(l))
1418
+ (l) => typeof l == "string" && (Te.test(l) || Q.test(l))
1411
1419
  ).map((l) => {
1412
- const d = Ce(t, l);
1420
+ const d = Oe(t, l);
1413
1421
  return nt(d);
1414
1422
  }).flat().filter(Boolean);
1415
- await zo(a, j(r));
1423
+ await zo(a, x(r));
1416
1424
  }
1417
1425
  }
1418
- const be = new le({
1426
+ const Pe = new le({
1419
1427
  max: 100,
1420
1428
  ttl: 1 * 60 * 1e3
1421
1429
  // 1 minute
1422
1430
  });
1423
- async function Ve(t, e, o) {
1431
+ async function Ge(t, e, o) {
1424
1432
  const s = ie(
1425
1433
  t,
1426
- (a) => typeof a == "string" && (ve.test(a) || Q.test(a))
1427
- ), n = Vt(2), r = s.map(
1434
+ (a) => typeof a == "string" && (Te.test(a) || Q.test(a))
1435
+ ), n = Gt(2), r = s.map(
1428
1436
  (a) => n(async () => {
1429
1437
  try {
1430
- const l = Ce(t, a), d = nt(l);
1431
- for (const I of d) {
1432
- const h = x(I), S = o.getFilePath(I, a), p = S ? `${S}:${h}` : h, i = be.get(p);
1438
+ const l = Oe(t, a), d = nt(l);
1439
+ for (const E of d) {
1440
+ const h = j(E), S = o.getFilePath(E, a), p = S ? `${S}:${h}` : h, i = Pe.get(p);
1433
1441
  if (i) {
1434
- Q.test(l) || je(t, a, i);
1442
+ Q.test(l) || Me(t, a, i);
1435
1443
  return;
1436
1444
  }
1437
1445
  const y = await Jo(S, h, e);
1438
- y && (Q.test(l) || je(t, a, y), be.set(p, y));
1446
+ y && (Q.test(l) || Me(t, a, y), Pe.set(p, y));
1439
1447
  }
1440
1448
  } catch (l) {
1441
1449
  f.error(`Failed to process upload for path ${a.join(".")}:`, l.message || l.reason);
@@ -1456,7 +1464,7 @@ async function Ho(t, {
1456
1464
  state: t,
1457
1465
  pageIds: a,
1458
1466
  componentIds: s === "all" ? Object.keys(t.components) : s
1459
- }), d = c === "all" ? t.routeIds : c, I = (u) => ({
1467
+ }), d = c === "all" ? t.routeIds : c, E = (u) => ({
1460
1468
  id: u.id,
1461
1469
  name: u.name,
1462
1470
  isTemplateSection: u.isTemplateSection ?? !1,
@@ -1468,7 +1476,7 @@ async function Ho(t, {
1468
1476
  sections: u?.sectionIds ? R(
1469
1477
  u?.sectionIds?.map((b) => {
1470
1478
  const T = u.sections?.[b];
1471
- return T && I(T);
1479
+ return T && E(T);
1472
1480
  })
1473
1481
  ) : void 0
1474
1482
  // 已经废弃,数据在 page.dataSource 中管理
@@ -1484,7 +1492,7 @@ async function Ho(t, {
1484
1492
  sections: R(
1485
1493
  u.sectionIds.map((T) => {
1486
1494
  const B = u.sections[T];
1487
- return B && I(B);
1495
+ return B && E(B);
1488
1496
  })
1489
1497
  ),
1490
1498
  // 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
@@ -1544,7 +1552,7 @@ async function Ho(t, {
1544
1552
  });
1545
1553
  }
1546
1554
  const w = P(y, ".blocklet/pages/pages.config.yml");
1547
- F(j(w), { recursive: !0 });
1555
+ F(x(w), { recursive: !0 });
1548
1556
  const C = {
1549
1557
  pages: R(
1550
1558
  a.map((u) => {
@@ -1586,10 +1594,10 @@ async function Ho(t, {
1586
1594
  const u = P(y, "resources"), b = P(u, "components");
1587
1595
  F(b, { recursive: !0 });
1588
1596
  for (const W of Object.keys(t?.resources?.components ?? {}).filter(
1589
- ($) => l.includes($)
1597
+ (M) => l.includes(M)
1590
1598
  )) {
1591
- const $ = t.resources?.components?.[W]?.component;
1592
- $ && await te($, b, {
1599
+ const M = t.resources?.components?.[W]?.component;
1600
+ M && await te(M, b, {
1593
1601
  getFilename: (Y) => `${Y.name || "unnamed"}.${Y.id}.yml`,
1594
1602
  exportAssets: e
1595
1603
  });
@@ -1598,16 +1606,16 @@ async function Ho(t, {
1598
1606
  F(T, { recursive: !0 });
1599
1607
  const B = Yo();
1600
1608
  for (const W of Object.keys(t?.resources?.components ?? {}).filter(
1601
- ($) => l.includes($)
1609
+ (M) => l.includes(M)
1602
1610
  )) {
1603
- const $ = t.resources?.components?.[W]?.component;
1604
- if ($ && $.renderer?.type === "react-component") {
1605
- const Y = $.renderer?.chunks ?? [];
1611
+ const M = t.resources?.components?.[W]?.component;
1612
+ if (M && M.renderer?.type === "react-component") {
1613
+ const Y = M.renderer?.chunks ?? [];
1606
1614
  if (Y?.length > 0)
1607
1615
  for (const me of Y) {
1608
- const Te = P(T, me), he = B?.[me];
1616
+ const ke = P(T, me), he = B?.[me];
1609
1617
  try {
1610
- he && L(he) && !L(Te) && At(he, Te);
1618
+ he && L(he) && !L(ke) && At(he, ke);
1611
1619
  } catch (ut) {
1612
1620
  f.error(`copy chunk ${me} error`, ut.message);
1613
1621
  }
@@ -1622,13 +1630,13 @@ async function Wo(t, { importAssets: e, includeResources: o } = {}) {
1622
1630
  return null;
1623
1631
  let s, n = !1;
1624
1632
  try {
1625
- G(t).isDirectory() ? s = t : /\.(tgz|gz|tar)$/.test(t) && (n = !0, s = ot(), await Kt({ file: t, C: s }));
1626
- const r = se("**/.blocklet/pages/pages.config.yml", { cwd: s, absolute: !0 }).at(0), c = r && P(j(r), "../../pages"), a = r && P(j(r), "../../components"), l = r && P(j(r), "../../routes");
1633
+ V(t).isDirectory() ? s = t : /\.(tgz|gz|tar)$/.test(t) && (n = !0, s = ot(), await Kt({ file: t, C: s }));
1634
+ const r = se("**/.blocklet/pages/pages.config.yml", { cwd: s, absolute: !0 }).at(0), c = r && P(x(r), "../../pages"), a = r && P(x(r), "../../components"), l = r && P(x(r), "../../routes");
1627
1635
  if (!r)
1628
1636
  return null;
1629
- const d = K.parse(J(r).toString()), I = (g, m, w) => {
1637
+ const d = K.parse(J(r).toString()), E = (g, m, w) => {
1630
1638
  let C = P(g, `${m}${w ? `.${w}` : ""}.yml`);
1631
- return (!L(C) || !G(C).isFile()) && (C = P(g, m, `index${w ? `.${w}` : ""}.yml`), !L(C) || !G(C)) ? null : K.parse(J(C).toString());
1639
+ return (!L(C) || !V(C).isFile()) && (C = P(g, m, `index${w ? `.${w}` : ""}.yml`), !L(C) || !V(C)) ? null : K.parse(J(C).toString());
1632
1640
  }, h = (g, m) => {
1633
1641
  try {
1634
1642
  const w = se(`*.${m}.yml`, { cwd: g, absolute: !0 })[0];
@@ -1639,15 +1647,15 @@ async function Wo(t, { importAssets: e, includeResources: o } = {}) {
1639
1647
  return null;
1640
1648
  }, S = (g, m) => {
1641
1649
  let w = P(g, `${m}.yml`);
1642
- return (!L(w) || !G(w).isFile()) && (w = P(g, m, "index.yml"), !L(w) || !G(w)) ? null : K.parse(J(w).toString());
1650
+ return (!L(w) || !V(w).isFile()) && (w = P(g, m, "index.yml"), !L(w) || !V(w)) ? null : K.parse(J(w).toString());
1643
1651
  }, p = R(
1644
1652
  d.pages.map(({ slug: g }) => {
1645
1653
  const m = R(
1646
1654
  d.supportedLocales.map(({ locale: O }) => {
1647
- const u = c ? I(c, ce(g), O) : void 0;
1655
+ const u = c ? E(c, ce(g), O) : void 0;
1648
1656
  if (u)
1649
1657
  return { locale: O, page: u };
1650
- const b = c ? I(c, g, O) : void 0;
1658
+ const b = c ? E(c, g, O) : void 0;
1651
1659
  return b && { locale: O, page: b };
1652
1660
  })
1653
1661
  ), w = m[0]?.page;
@@ -1714,38 +1722,38 @@ async function Wo(t, { importAssets: e, includeResources: o } = {}) {
1714
1722
  ), y = a ? R(d.components?.map(({ id: g }) => h(a, g)) ?? []) : [];
1715
1723
  if (e) {
1716
1724
  const g = (...m) => {
1717
- f.info(`[${n ? x(t) : x(P(t, "../../../../"))}] importAssets:`, ...m);
1725
+ f.info(`[${n ? j(t) : j(P(t, "../../../../"))}] importAssets:`, ...m);
1718
1726
  };
1719
1727
  try {
1720
1728
  g("wait image-bin api ready"), await zt({
1721
- resources: [`${xt(Zt)}/api/sdk/uploads`],
1729
+ resources: [`${jt(Zt)}/api/sdk/uploads`],
1722
1730
  validateStatus: (C) => C >= 200 && C <= 500
1723
1731
  }), g("image-bin api is ready");
1724
1732
  const m = {}, w = {};
1725
1733
  g("start to upload assets"), await Promise.allSettled([
1726
- Ve(y, m, {
1734
+ Ge(y, m, {
1727
1735
  getFilePath: (C) => a && P(a, C),
1728
1736
  onFinish: (C) => {
1729
1737
  g(`upload ${C.length} component assets`);
1730
1738
  }
1731
1739
  }),
1732
- Ve(p, w, {
1740
+ Ge(p, w, {
1733
1741
  getFilePath: (C, O) => {
1734
- const u = Ce(p, O.slice(0, 1));
1735
- return c && P(c, j(u.slug), C);
1742
+ const u = Oe(p, O.slice(0, 1));
1743
+ return c && P(c, x(u.slug), C);
1736
1744
  },
1737
1745
  onFinish: (C) => {
1738
1746
  g(`upload ${C.length} page assets`);
1739
1747
  }
1740
1748
  })
1741
- ]), g("upload assets done"), be.clear(), global.gc && global.gc();
1749
+ ]), g("upload assets done"), Pe.clear(), global.gc && global.gc();
1742
1750
  } catch (m) {
1743
1751
  g("Error during asset import:", m);
1744
1752
  }
1745
1753
  }
1746
1754
  const A = {};
1747
1755
  if (o) {
1748
- const g = r && P(j(r), "../../resources/components"), m = R(
1756
+ const g = r && P(x(r), "../../resources/components"), m = R(
1749
1757
  d.resources?.components?.map(({ id: w }) => h(g, w)) ?? []
1750
1758
  );
1751
1759
  m.length > 0 && (A.components = Object.fromEntries(
@@ -1768,7 +1776,7 @@ async function Wo(t, { importAssets: e, includeResources: o } = {}) {
1768
1776
  n && s && Je(s, { force: !0, recursive: !0 });
1769
1777
  }
1770
1778
  }
1771
- async function Ge(t, e, {
1779
+ async function Ve(t, e, {
1772
1780
  routes: o,
1773
1781
  mergeMode: s = "byUpdateTime",
1774
1782
  deleteRoutes: n = !1,
@@ -1779,13 +1787,13 @@ async function Ge(t, e, {
1779
1787
  } catch (S) {
1780
1788
  f.error("clear preload page cache error", { error: S });
1781
1789
  }
1782
- const { pages: c, pageIds: a, routeIds: l, routes: d, supportedLocales: I } = t;
1790
+ const { pages: c, pageIds: a, routeIds: l, routes: d, supportedLocales: E } = t;
1783
1791
  if (r === "production") {
1784
1792
  let S = o ?? [], p = null;
1785
1793
  for (const i of l ?? []) {
1786
1794
  const y = d?.[i];
1787
1795
  if (y?.params && y?.params.length > 0 && y?.paramsOptions && y?.paramsOptions.length > 0) {
1788
- const A = Ae({
1796
+ const A = Ce({
1789
1797
  basePath: y.path,
1790
1798
  params: y.params,
1791
1799
  routeId: y.id,
@@ -1887,7 +1895,7 @@ async function Ge(t, e, {
1887
1895
  e.routeIds.push(p.id), e.routes[p.id] = p;
1888
1896
  }
1889
1897
  }
1890
- if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ft(I)), n)
1898
+ if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ft(E)), n)
1891
1899
  for (const S of Object.keys(e.components))
1892
1900
  delete e.components[S];
1893
1901
  let h = JSON.parse(JSON.stringify(t.components));
@@ -1904,11 +1912,11 @@ async function Ge(t, e, {
1904
1912
  ];
1905
1913
  })
1906
1914
  )
1907
- ), Object.assign(e.components, h), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Pe(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1915
+ ), Object.assign(e.components, h), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ae(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1908
1916
  }
1909
1917
  const rt = ue(
1910
1918
  async (t) => {
1911
- if (!Pe(t?.properties))
1919
+ if (!Ae(t?.properties))
1912
1920
  return t;
1913
1921
  if (t?.renderer?.type === "react-component") {
1914
1922
  const { script: e, PROPERTIES_SCHEMA: o } = t?.renderer || {};
@@ -1939,13 +1947,13 @@ const rt = ue(
1939
1947
  let pe, X, de, fe;
1940
1948
  const at = () => Rt({
1941
1949
  types: [
1942
- { did: tt, type: Ue },
1943
- { did: Ro, type: Ue }
1950
+ { did: tt, type: Fe },
1951
+ { did: Ro, type: Fe }
1944
1952
  ]
1945
1953
  }), Yo = () => {
1946
1954
  const t = at(), e = {};
1947
1955
  return t.forEach((o) => {
1948
- const s = se("**/.blocklet/pages/pages.config.yml", { cwd: o.path, absolute: !0 }).at(0), n = s && P(j(s), "../../chunks");
1956
+ const s = se("**/.blocklet/pages/pages.config.yml", { cwd: o.path, absolute: !0 }).at(0), n = s && P(x(s), "../../chunks");
1949
1957
  if (n && L(n)) {
1950
1958
  const r = Ct(n);
1951
1959
  for (const c of r)
@@ -2010,8 +2018,8 @@ function qo(t) {
2010
2018
  // 3s
2011
2019
  { leading: !1, trailing: !0 }
2012
2020
  );
2013
- 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(Fe, e), () => {
2014
- 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(Fe, e);
2021
+ return e(), I.events.on(I.Events.componentAdded, e), I.events.on(I.Events.componentRemoved, e), I.events.on(I.Events.componentStarted, e), I.events.on(I.Events.componentStopped, e), I.events.on(I.Events.componentUpdated, e), I.events.on(be, e), () => {
2022
+ I.events.off(I.Events.componentAdded, e), I.events.off(I.Events.componentRemoved, e), I.events.off(I.Events.componentStarted, e), I.events.off(I.Events.componentStopped, e), I.events.off(I.Events.componentUpdated, e), I.events.off(be, e);
2015
2023
  };
2016
2024
  }
2017
2025
  const ct = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), pt = globalThis;
@@ -2060,7 +2068,7 @@ async function lt({
2060
2068
  if (s.syncedStore.resources.pages = e, (await N.findByPk(t))?.useAllResources)
2061
2069
  s.syncedStore.resources.components = o;
2062
2070
  else {
2063
- const c = (await Oe.findAll({ where: { projectId: t } })).map((l) => l.componentId), a = Object.fromEntries(
2071
+ const c = (await ve.findAll({ where: { projectId: t } })).map((l) => l.componentId), a = Object.fromEntries(
2064
2072
  Object.entries(o || {}).filter(([l]) => c.includes(l))
2065
2073
  );
2066
2074
  s.syncedStore.resources.components = a;
@@ -2070,23 +2078,46 @@ async function lt({
2070
2078
  components: Object.keys(s.syncedStore.resources.components || {}).length
2071
2079
  });
2072
2080
  }
2081
+ async function Js() {
2082
+ f.info("trigger reload all project resource"), I.events.emit(be);
2083
+ }
2073
2084
  async function Qo({
2074
2085
  ensureLoaded: t = !0
2075
2086
  } = {}) {
2076
2087
  return t && (pe ??= it(), await pe), { states: X, pages: de, components: fe };
2077
2088
  }
2078
- E.events.on(E.Events.envUpdate, () => {
2089
+ I.events.on(I.Events.envUpdate, () => {
2079
2090
  v.pageUrlMapCache.clear(), f.info("clear all page url map cache");
2080
2091
  });
2081
2092
  export {
2082
2093
  tt as C,
2094
+ Ue as G,
2083
2095
  N as P,
2084
- Ue as R,
2096
+ Fe as R,
2085
2097
  v as S,
2086
- Qo as a,
2087
- Us as b,
2088
- _s as g,
2098
+ _s as a,
2099
+ Qo as b,
2100
+ Eo as c,
2101
+ bo as d,
2102
+ Po as e,
2103
+ Ao as f,
2104
+ Us as g,
2105
+ Co as h,
2089
2106
  Ns as i,
2107
+ re as j,
2108
+ Fs as k,
2090
2109
  f as l,
2091
- Ho as t
2110
+ ko as m,
2111
+ ee as n,
2112
+ Gs as o,
2113
+ Vs as p,
2114
+ Vo as q,
2115
+ Ko as r,
2116
+ Bs as s,
2117
+ Ho as t,
2118
+ zo as u,
2119
+ Wo as v,
2120
+ Ve as w,
2121
+ qo as x,
2122
+ Js as y
2092
2123
  };