@blocklet/pages-kit-inner-components 0.1.1 → 0.1.2

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,40 +1,40 @@
1
- import { l as P, c as Ne, g as Fe } from "./components-Bo3_pN-Y.mjs";
2
- import { memoize as _e } from "@blocklet/quickjs";
3
- import { getComponentWebEndpoint as Me, getResources as $e, call as Be } from "@blocklet/sdk/lib/component";
4
- import m from "@blocklet/sdk/lib/config";
5
- import { reactive as xe } from "@reactivedata/reactive";
6
- import { syncedStore as Ve, getYjsValue as se } from "@syncedstore/core";
7
- import { mkdirSync as F, writeFileSync as X, existsSync as x, readFileSync as H, renameSync as ue, rmSync as ve, lstatSync as Y, mkdtempSync as Ge, createWriteStream as Je } from "fs";
1
+ import { l as P, c as Fe, g as _e } from "./components-Bo3_pN-Y.mjs";
2
+ import { memoize as Me } from "@blocklet/quickjs";
3
+ import { getComponentWebEndpoint as $e, getResources as Be, call as xe } from "@blocklet/sdk/lib/component";
4
+ import g from "@blocklet/sdk/lib/config";
5
+ import { reactive as Ve } from "@reactivedata/reactive";
6
+ import { syncedStore as Ge, getYjsValue as se } from "@syncedstore/core";
7
+ import { mkdirSync as F, writeFileSync as X, existsSync as x, readFileSync as H, renameSync as fe, rmSync as Ie, lstatSync as Y, mkdtempSync as Je, createWriteStream as qe } from "fs";
8
8
  import { globSync as ae } from "glob";
9
9
  import * as ne from "lib0/decoding";
10
10
  import * as I from "lib0/encoding";
11
- import { debounce as Ie, pick as qe, union as ze, get as ce, cloneDeep as Ke, isEmpty as He, set as fe } from "lodash";
12
- import { LRUCache as Te } from "lru-cache";
13
- import { customAlphabet as Ye } from "nanoid";
14
- import We from "p-limit";
15
- import Xe, { join as A, dirname as U, basename as $ } from "path";
16
- import { pipeline as Qe } from "stream/promises";
17
- import { x as Ze } from "tar";
11
+ import { debounce as Te, pick as ze, union as Ke, get as le, cloneDeep as He, isEmpty as Ye, set as me } from "lodash";
12
+ import { LRUCache as Oe } from "lru-cache";
13
+ import { customAlphabet as We } from "nanoid";
14
+ import Xe from "p-limit";
15
+ import Qe, { join as b, dirname as k, basename as $ } from "path";
16
+ import { pipeline as Ze } from "stream/promises";
17
+ import { x as et } from "tar";
18
18
  import { joinURL as B } from "ufo";
19
- import et from "wait-on";
20
- import { encodeAwarenessUpdate as me, removeAwarenessStates as tt, applyAwarenessUpdate as st, Awareness as nt } from "y-protocols/awareness";
21
- import { writeUpdate as rt, writeSyncStep1 as ot, readSyncMessage as at } from "y-protocols/sync";
19
+ import tt from "wait-on";
20
+ import { encodeAwarenessUpdate as ge, removeAwarenessStates as st, applyAwarenessUpdate as nt, Awareness as rt } from "y-protocols/awareness";
21
+ import { writeUpdate as ot, writeSyncStep1 as at, readSyncMessage as it } from "y-protocols/sync";
22
22
  import * as V from "yaml";
23
23
  import * as M from "yjs";
24
- import it from "lodash/isNil";
25
- import { DataTypes as v, Sequelize as ct, Model as Oe, Op as lt } from "sequelize";
24
+ import ct from "lodash/isNil";
25
+ import { DataTypes as v, Sequelize as lt, Model as Pe, Op as pt } from "sequelize";
26
26
  import "sqlite3";
27
- m.env.mode;
28
- const pt = "image-bin";
29
- m.env.INIT_TEMPLATE_PATH;
30
- const dt = process.env.DATABASE_URL || Xe.join(m.env.dataDir, "db/pages-kit.db"), ge = m, Xt = () => m.env.tenantMode === "multiple", Qt = () => {
27
+ g.env.mode;
28
+ const dt = "image-bin";
29
+ g.env.INIT_TEMPLATE_PATH;
30
+ const ut = process.env.DATABASE_URL || Qe.join(g.env.dataDir, "db/pages-kit.db"), he = g, Xt = () => g.env.tenantMode === "multiple", Qt = () => {
31
31
  var t;
32
- return (it(ge.env.preferences.multiTenantAllProjectAccessPassports) ? [] : (t = ge.env.preferences.multiTenantAllProjectAccessPassports) == null ? void 0 : t.split(",")) || [];
33
- }, ut = v.sqlite.DATE.parse;
34
- v.sqlite.DATE.parse = (t, s) => typeof t == "number" ? new Date(t) : ut(t, s);
35
- const q = new ct({
32
+ return (ct(he.env.preferences.multiTenantAllProjectAccessPassports) ? [] : (t = he.env.preferences.multiTenantAllProjectAccessPassports) == null ? void 0 : t.split(",")) || [];
33
+ }, ft = v.sqlite.DATE.parse;
34
+ v.sqlite.DATE.parse = (t, s) => typeof t == "number" ? new Date(t) : ft(t, s);
35
+ const q = new lt({
36
36
  dialect: "sqlite",
37
- storage: dt,
37
+ storage: ut,
38
38
  benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
39
39
  retry: {
40
40
  match: [/SQLITE_BUSY/],
@@ -48,7 +48,7 @@ const q = new ct({
48
48
  q.query("pragma journal_mode = WAL;");
49
49
  q.query("pragma synchronous = normal;");
50
50
  q.query("pragma journal_size_limit = 67108864;");
51
- class te extends Oe {
51
+ class te extends Pe {
52
52
  // Foreign key to Component
53
53
  }
54
54
  te.init(
@@ -70,11 +70,11 @@ te.init(
70
70
  },
71
71
  { sequelize: q, tableName: "ProjectComponents", timestamps: !1 }
72
72
  );
73
- class _ extends Oe {
73
+ class _ extends Pe {
74
74
  static async getProjectByIdOrSlug(s) {
75
75
  return _.findOne({
76
76
  where: {
77
- [lt.or]: [{ id: s }, { slug: s }]
77
+ [pt.or]: [{ id: s }, { slug: s }]
78
78
  }
79
79
  });
80
80
  }
@@ -123,26 +123,28 @@ _.hasMany(te, {
123
123
  foreignKey: "projectId",
124
124
  as: "components"
125
125
  });
126
- const ft = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", he = "page", ie = "trigger-reload-project-resource", Pe = ft, mt = "z2qa7rr3eUyVnWp2PCxEVARuUfLFh6cE5V2xV", { uploadToMediaKit: gt } = require("@blocklet/uploader-server"), ye = Ye("abcdefghijklmnopqrstuvwxyz0123456789", 16), le = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, G = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, Se = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, ht = 1e4, yt = 3e4, z = 0, re = 1, St = 0, wt = 1, Et = m, K = A(process.env.BLOCKLET_DATA_DIR, "site-state"), Zt = ["production", "draft"], es = ["production"];
127
- function De(t) {
126
+ const mt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", ye = "page", ie = "trigger-reload-project-resource", De = mt, gt = "z2qa7rr3eUyVnWp2PCxEVARuUfLFh6cE5V2xV", { uploadToMediaKit: ht } = require("@blocklet/uploader-server"), Se = We("abcdefghijklmnopqrstuvwxyz0123456789", 16), pe = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, G = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, we = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, yt = 1e4, St = 3e4, z = 0, re = 1, wt = 0, Et = 1, ce = g, K = b(process.env.BLOCKLET_DATA_DIR, "site-state"), Zt = ["production", "draft"], es = ["production"];
127
+ function je(t) {
128
128
  return (t == null ? void 0 : t.replace(/\//g, "|")) || "";
129
129
  }
130
130
  function At() {
131
+ var e;
132
+ const t = ce.env.languages.map((n) => ({ locale: n.code, name: n.name })), s = (e = t[0]) == null ? void 0 : e.locale;
131
133
  return {
132
134
  pageIds: [],
133
135
  pages: {},
134
136
  components: {},
135
- supportedLocales: [],
136
- config: {},
137
+ supportedLocales: t,
138
+ config: { defaultLocale: s },
137
139
  resources: {}
138
140
  };
139
141
  }
140
142
  const R = class R extends M.Doc {
141
143
  constructor(s) {
142
- super(), this.options = s, this.states = {}, this.conns = /* @__PURE__ */ new Map(), this.awarenessChangeHandler = ({ added: e, updated: n, removed: r }, o) => {
144
+ super(), this.options = s, this.states = {}, this.conns = /* @__PURE__ */ new Map(), this.awarenessChangeHandler = ({ added: e, updated: n, removed: r }, a) => {
143
145
  const l = e.concat(n, r);
144
- if (o !== null) {
145
- const c = this.conns.get(o);
146
+ if (a !== null) {
147
+ const c = this.conns.get(a);
146
148
  c && (e.forEach((u) => {
147
149
  c.add(u);
148
150
  }), r.forEach((u) => {
@@ -150,36 +152,36 @@ const R = class R extends M.Doc {
150
152
  }));
151
153
  }
152
154
  const i = I.createEncoder();
153
- I.writeVarUint(i, re), I.writeVarUint8Array(i, me(this.awareness, l));
154
- const a = I.toUint8Array(i);
155
- this.conns.forEach((c, u) => this.send(u, a));
155
+ I.writeVarUint(i, re), I.writeVarUint8Array(i, ge(this.awareness, l));
156
+ const o = I.toUint8Array(i);
157
+ this.conns.forEach((c, u) => this.send(u, o));
156
158
  }, this.updateHandler = (e) => {
157
159
  const n = I.createEncoder();
158
- I.writeVarUint(n, z), rt(n, e);
160
+ I.writeVarUint(n, z), ot(n, e);
159
161
  const r = I.toUint8Array(n);
160
- this.conns.forEach((o, l) => this.send(l, r));
162
+ this.conns.forEach((a, l) => this.send(l, r));
161
163
  }, this.ensureDataStructure = () => {
162
164
  var l;
163
- const { supportedLocales: e, pages: n, pageIds: r, config: o } = this.syncedStore;
165
+ const { supportedLocales: e, pages: n, pageIds: r, config: a } = this.syncedStore;
164
166
  {
165
167
  const i = new Set(Object.keys(n));
166
- let a = 0;
167
- for (; a < r.length; ) {
168
- const c = r[a];
169
- i.has(c) ? (i.delete(c), a++) : r.splice(a, 1);
168
+ let o = 0;
169
+ for (; o < r.length; ) {
170
+ const c = r[o];
171
+ i.has(c) ? (i.delete(c), o++) : r.splice(o, 1);
170
172
  }
171
173
  }
172
- e.splice(0, e.length), e.push(...Et.env.languages.map((i) => ({ locale: i.code, name: i.name }))), o.defaultLocale = (l = e[0]) == null ? void 0 : l.locale;
174
+ e.splice(0, e.length), e.push(...ce.env.languages.map((i) => ({ locale: i.code, name: i.name }))), a.defaultLocale = (l = e[0]) == null ? void 0 : l.locale;
173
175
  {
174
176
  let i = 0;
175
- const a = /* @__PURE__ */ new Set();
177
+ const o = /* @__PURE__ */ new Set();
176
178
  for (; i < e.length; ) {
177
179
  const { locale: c } = e[i];
178
- a.has(c) ? e.splice(i, 1) : (i++, a.add(c));
180
+ o.has(c) ? e.splice(i, 1) : (i++, o.add(c));
179
181
  }
180
182
  }
181
183
  }, this.send = (e, n) => {
182
- e.readyState !== St && e.readyState !== wt && this.closeConn(e);
184
+ e.readyState !== wt && e.readyState !== Et && this.closeConn(e);
183
185
  try {
184
186
  e.send(n, (r) => {
185
187
  r && this.closeConn(e);
@@ -190,38 +192,38 @@ const R = class R extends M.Doc {
190
192
  }, this.closeConn = (e) => {
191
193
  if (e.removeAllListeners(), this.conns.has(e)) {
192
194
  const n = this.conns.get(e);
193
- this.conns.delete(e), n && tt(this.awareness, Array.from(n), null);
195
+ this.conns.delete(e), n && st(this.awareness, Array.from(n), null);
194
196
  }
195
197
  e.close();
196
- }, this.autoSave = Ie(() => {
197
- F(U(this.draftYjsFilePath), { recursive: !0 }), X(this.draftYjsFilePath, M.encodeStateAsUpdate(this));
198
- }, ht), this.save = ({ flush: e = !1 } = {}) => {
198
+ }, this.autoSave = Te(() => {
199
+ F(k(this.draftYjsFilePath), { recursive: !0 }), X(this.draftYjsFilePath, M.encodeStateAsUpdate(this));
200
+ }, yt), this.save = ({ flush: e = !1 } = {}) => {
199
201
  this.autoSave(), e && this.autoSave.flush();
200
202
  }, this.publish = async ({ mode: e, pages: n }) => {
201
- const r = await this.getState("draft"), o = await this.getState("production");
202
- await Ae(r, o, { pages: n, pageMergeMode: "replace", deletePages: !0, publishMode: e }), o.config.publishedAt = (/* @__PURE__ */ new Date()).getTime();
203
+ const r = await this.getState("draft"), a = await this.getState("production");
204
+ await be(r, a, { pages: n, pageMergeMode: "replace", deletePages: !0, publishMode: e }), a.config.publishedAt = (/* @__PURE__ */ new Date()).getTime();
203
205
  for (const l of n || Object.keys(this.syncedStore.pages))
204
206
  this.syncedStore.pages[l] && (this.syncedStore.pages[l].publishedAt = (/* @__PURE__ */ new Date()).toISOString());
205
- await this.setState(e, o);
207
+ await this.setState(e, a);
206
208
  }, this.mergeState = async (e, n) => {
207
- var i, a, c;
209
+ var i, o, c;
208
210
  const r = JSON.parse(JSON.stringify(n));
209
211
  (i = e.config).fontFamily ?? (i.fontFamily = {});
210
- const o = (a = r.config) == null ? void 0 : a.fontFamily, l = (c = e.config) == null ? void 0 : c.fontFamily;
211
- e.config.fontFamily.title = (o == null ? void 0 : o.title) || (l == null ? void 0 : l.title), e.config.fontFamily.description = (o == null ? void 0 : o.description) || (l == null ? void 0 : l.description), await new Promise((u, p) => {
212
+ const a = (o = r.config) == null ? void 0 : o.fontFamily, l = (c = e.config) == null ? void 0 : c.fontFamily;
213
+ e.config.fontFamily.title = (a == null ? void 0 : a.title) || (l == null ? void 0 : l.title), e.config.fontFamily.description = (a == null ? void 0 : a.description) || (l == null ? void 0 : l.description), await new Promise((u, p) => {
212
214
  this.transact(async () => {
213
215
  try {
214
- const y = await Ae(e, n);
215
- u(y);
216
- } catch (y) {
217
- p(y);
216
+ const h = await be(e, n);
217
+ u(h);
218
+ } catch (h) {
219
+ p(h);
218
220
  }
219
221
  });
220
222
  });
221
223
  }, this.addConnection = (e) => {
222
224
  if (this.conns.has(e))
223
225
  return;
224
- e.binaryType = "arraybuffer", this.conns.set(e, /* @__PURE__ */ new Set()), e.on("message", (o) => this.messageListener(e, new Uint8Array(o)));
226
+ e.binaryType = "arraybuffer", this.conns.set(e, /* @__PURE__ */ new Set()), e.on("message", (a) => this.messageListener(e, new Uint8Array(a)));
225
227
  let n = !0;
226
228
  const r = setInterval(() => {
227
229
  if (!n)
@@ -234,30 +236,30 @@ const R = class R extends M.Doc {
234
236
  this.closeConn(e), clearInterval(r);
235
237
  }
236
238
  }
237
- }, yt);
239
+ }, St);
238
240
  e.on("close", () => {
239
241
  this.closeConn(e), clearInterval(r);
240
242
  }), e.on("pong", () => {
241
243
  n = !0;
242
244
  });
243
245
  {
244
- const o = I.createEncoder();
245
- I.writeVarUint(o, z), ot(o, this), this.send(e, I.toUint8Array(o));
246
+ const a = I.createEncoder();
247
+ I.writeVarUint(a, z), at(a, this), this.send(e, I.toUint8Array(a));
246
248
  const l = this.awareness.getStates();
247
249
  if (l.size > 0) {
248
250
  const i = I.createEncoder();
249
- I.writeVarUint(i, re), I.writeVarUint8Array(i, me(this.awareness, Array.from(l.keys()))), this.send(e, I.toUint8Array(i));
251
+ I.writeVarUint(i, re), I.writeVarUint8Array(i, ge(this.awareness, Array.from(l.keys()))), this.send(e, I.toUint8Array(i));
250
252
  }
251
253
  }
252
254
  }, this.messageListener = (e, n) => {
253
255
  try {
254
- const r = I.createEncoder(), o = ne.createDecoder(n), l = ne.readVarUint(o);
256
+ const r = I.createEncoder(), a = ne.createDecoder(n), l = ne.readVarUint(a);
255
257
  switch (l) {
256
258
  case z:
257
- I.writeVarUint(r, z), at(o, r, this, null), I.length(r) > 1 && (this.ensureDataStructure(), this.send(e, I.toUint8Array(r)));
259
+ I.writeVarUint(r, z), it(a, r, this, null), I.length(r) > 1 && (this.ensureDataStructure(), this.send(e, I.toUint8Array(r)));
258
260
  break;
259
261
  case re: {
260
- st(this.awareness, ne.readVarUint8Array(o), e);
262
+ nt(this.awareness, ne.readVarUint8Array(a), e);
261
263
  break;
262
264
  }
263
265
  default:
@@ -267,20 +269,20 @@ const R = class R extends M.Doc {
267
269
  P.error(r);
268
270
  }
269
271
  this.save();
270
- }, x(this.draftYjsFilePath) && M.applyUpdate(this, H(this.draftYjsFilePath)), this.syncedStore = xe(
271
- Ve(
272
+ }, x(this.draftYjsFilePath) && M.applyUpdate(this, H(this.draftYjsFilePath)), this.syncedStore = Ve(
273
+ Ge(
272
274
  { pages: {}, pageIds: [], components: {}, supportedLocales: [], config: {}, resources: {} },
273
275
  this
274
276
  )
275
- ), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new nt(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
277
+ ), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new rt(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
276
278
  }
277
279
  // safe delete project state dir
278
280
  static safeDeleteProjectStateDir(s) {
279
281
  if (!s)
280
282
  throw new Error("Should provide project context");
281
283
  try {
282
- const e = A(K, s), n = A(K, `@del-${s}`);
283
- ue(e, n);
284
+ const e = b(K, s), n = b(K, `@del-${s}`);
285
+ fe(e, n);
284
286
  } catch (e) {
285
287
  P.error("Failed to safe delete project state dir:", e);
286
288
  }
@@ -300,7 +302,7 @@ const R = class R extends M.Doc {
300
302
  throw new Error("Should provide project context");
301
303
  let e = this.sharedInstances.get(s);
302
304
  return e || (e = new R({
303
- path: A(K, s)
305
+ path: b(K, s)
304
306
  }), this.sharedInstances.set(s, e), e);
305
307
  }
306
308
  destroy() {
@@ -309,7 +311,7 @@ const R = class R extends M.Doc {
309
311
  initObserver() {
310
312
  const s = (n) => {
311
313
  n.observeDeep((r) => {
312
- r.some((o) => o.changes.keys.has("updatedAt") || o.changes.keys.has("publishedAt")) || n.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
314
+ r.some((a) => a.changes.keys.has("updatedAt") || a.changes.keys.has("publishedAt")) || n.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
313
315
  });
314
316
  };
315
317
  this.syncedStore.pages && Object.keys(this.syncedStore.pages).forEach((n) => {
@@ -318,68 +320,76 @@ const R = class R extends M.Doc {
318
320
  });
319
321
  const e = se(this.syncedStore.pages);
320
322
  e && e instanceof M.Map && e.observe((n) => {
321
- n.changes.keys.forEach((r, o) => {
323
+ n.changes.keys.forEach((r, a) => {
322
324
  if (r.action === "add") {
323
- const l = se(this.syncedStore.pages[o]);
325
+ const l = se(this.syncedStore.pages[a]);
324
326
  l && l instanceof M.Map && s(l);
325
327
  }
326
328
  });
327
329
  });
328
330
  }
329
331
  get draftYjsFilePath() {
330
- return A(this.options.path, "draft.yjs");
332
+ return b(this.options.path, "draft.yjs");
331
333
  }
332
334
  async getState(s) {
333
- return s === "draft" ? JSON.parse(JSON.stringify(this.syncedStore)) : (this.states[s] || (this.states[s] = await Le(this.getPublishDir(s), { includeResources: !0 }) ?? At()), {
335
+ var e, n, r, a;
336
+ if (s === "draft")
337
+ return JSON.parse(JSON.stringify(this.syncedStore));
338
+ if (!this.states[s] && (this.states[s] = await Ue(this.getPublishDir(s), { includeResources: !0 }) ?? At(), !((n = (e = this.states[s]) == null ? void 0 : e.config) != null && n.defaultLocale))) {
339
+ (r = this.states[s]).config ?? (r.config = {});
340
+ const l = ce.env.languages.map((i) => ({ locale: i.code, name: i.name }));
341
+ this.states[s].config.defaultLocale = (a = l[0]) == null ? void 0 : a.locale;
342
+ }
343
+ return {
334
344
  ...this.states[s],
335
- resources: await Dt().then(async (e) => {
336
- var l, i, a, c;
337
- const { pages: n, components: r } = qe(e, "pages", "components");
338
- let o = r;
339
- if ((i = (l = this.states[s]) == null ? void 0 : l.resources) != null && i.components)
340
- o = {
341
- ...(c = (a = this.states[s]) == null ? void 0 : a.resources) == null ? void 0 : c.components
345
+ resources: await Dt().then(async (l) => {
346
+ var u, p, h, T;
347
+ const { pages: i, components: o } = ze(l, "pages", "components");
348
+ let c = o;
349
+ if ((p = (u = this.states[s]) == null ? void 0 : u.resources) != null && p.components)
350
+ c = {
351
+ ...(T = (h = this.states[s]) == null ? void 0 : h.resources) == null ? void 0 : T.components
342
352
  };
343
353
  else {
344
- const u = $(this.options.path), p = await _.findByPk(u);
345
- if (p != null && p.useAllResources)
346
- o = r;
354
+ const O = $(this.options.path), D = await _.findByPk(O);
355
+ if (D != null && D.useAllResources)
356
+ c = o;
347
357
  else {
348
- const T = (await te.findAll({ where: { projectId: u } })).map((D) => D.componentId);
349
- o = Object.fromEntries(
350
- Object.entries(r || {}).filter(([D]) => T.includes(D))
358
+ const f = (await te.findAll({ where: { projectId: O } })).map((m) => m.componentId);
359
+ c = Object.fromEntries(
360
+ Object.entries(o || {}).filter(([m]) => f.includes(m))
351
361
  );
352
362
  }
353
363
  }
354
- return { pages: n, components: o };
364
+ return { pages: i, components: c };
355
365
  }).catch(() => ({}))
356
- });
366
+ };
357
367
  }
358
368
  async setState(s, e) {
359
369
  const n = await Tt(e, { exportAssets: !1, includeResources: !0 }), r = this.getPublishDir(s);
360
- F(U(r), { recursive: !0 }), ve(r, { force: !0, recursive: !0 }), ue(n, r), this.states[s] = e;
370
+ F(k(r), { recursive: !0 }), Ie(r, { force: !0, recursive: !0 }), fe(n, r), this.states[s] = e;
361
371
  }
362
372
  getPublishDir(s) {
363
- return A(this.options.path, s);
373
+ return b(this.options.path, s);
364
374
  }
365
375
  static async pageUrlMap(s) {
366
376
  const { projectIds: e } = this, n = {};
367
377
  for (const r of e) {
368
- const o = await _.findByPk(r);
369
- if (!o) continue;
370
- const l = await R.shared(r).getState(s), i = ze(
371
- m.env.languages.map((a) => a.code),
372
- l.supportedLocales.map((a) => a.locale)
378
+ const a = await _.findByPk(r);
379
+ if (!a) continue;
380
+ const l = await R.shared(r).getState(s), i = Ke(
381
+ g.env.languages.map((o) => o.code),
382
+ l.supportedLocales.map((o) => o.locale)
373
383
  );
374
- for (const a of l.pageIds) {
375
- const c = l.pages[a];
384
+ for (const o of l.pageIds) {
385
+ const c = l.pages[o];
376
386
  if (!c || s === "production" && !c.isPublic)
377
387
  continue;
378
- const u = c.slug, p = o.slug || r, y = {
388
+ const u = c.slug, p = a.slug || r, h = {
379
389
  projectId: r,
380
390
  projectSlug: p,
381
391
  pageSlug: u,
382
- pageId: a,
392
+ pageId: o,
383
393
  // default locale
384
394
  defaultLocale: i == null ? void 0 : i[0],
385
395
  locales: i,
@@ -388,16 +398,16 @@ const R = class R extends M.Doc {
388
398
  isTemplate: c.isTemplate
389
399
  };
390
400
  p && (n[B("/", p, u)] = {
391
- ...y,
401
+ ...h,
392
402
  shouldRedirect: !0,
393
403
  mainPage: !0
394
404
  }), n[B("/", r, u)] = {
395
- ...y,
405
+ ...h,
396
406
  shouldRedirect: !0,
397
407
  mainPage: !0
398
408
  };
399
409
  for (const T of i) {
400
- const O = { ...y, locale: T };
410
+ const O = { ...h, locale: T };
401
411
  n[B("/", T, r, u)] = O, p && (n[B("/", T, p, u)] = O);
402
412
  }
403
413
  }
@@ -405,7 +415,7 @@ const R = class R extends M.Doc {
405
415
  return n;
406
416
  }
407
417
  };
408
- R.INSTANCE_TTL = 30 * 60 * 1e3, R.sharedInstances = new Te({
418
+ R.INSTANCE_TTL = 30 * 60 * 1e3, R.sharedInstances = new Oe({
409
419
  max: 100,
410
420
  // Maximum number of instances to store
411
421
  ttl: R.INSTANCE_TTL,
@@ -414,8 +424,8 @@ R.INSTANCE_TTL = 30 * 60 * 1e3, R.sharedInstances = new Te({
414
424
  }
415
425
  });
416
426
  let Q = R;
417
- function je() {
418
- return Ge(A(m.env.dataDir, "tmp-"));
427
+ function Ce() {
428
+ return Je(b(g.env.dataDir, "tmp-"));
419
429
  }
420
430
  function Z(t, s, e = []) {
421
431
  return Array.isArray(t) ? t.flatMap((n, r) => Z(n, s, [...e, r])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([n, r]) => Z(r, s, [...e, n])) : s(t) ? [e] : [];
@@ -427,77 +437,77 @@ async function bt(t, s, e) {
427
437
  if (!t || !x(t) || !Y(t).isFile())
428
438
  return null;
429
439
  let n = e[t];
430
- return n || (n = (async () => (await gt({
440
+ return n || (n = (async () => (await ht({
431
441
  filePath: t,
432
442
  fileName: s
433
443
  })).data.filename)(), e[t] = n), n;
434
444
  }
435
445
  const vt = async (t, s) => {
436
- const e = $(t), n = await Be({
437
- name: Pe,
446
+ const e = $(t), n = await xe({
447
+ name: De,
438
448
  path: B("/uploads", e),
439
449
  responseType: "stream",
440
450
  method: "GET"
441
451
  });
442
452
  if (n.status >= 200 && n.status < 400) {
443
- const r = Je(s);
444
- await Qe(n.data, r);
453
+ const r = qe(s);
454
+ await Ze(n.data, r);
445
455
  } else
446
456
  throw new Error(`download asset failed ${n.status}`);
447
457
  }, It = async (t, s) => {
448
458
  await Promise.all(
449
459
  t.map(async (e) => {
450
460
  try {
451
- await vt(e, A(s, $(e)));
461
+ await vt(e, b(s, $(e)));
452
462
  } catch (n) {
453
463
  P.error(`Failed to export assets: ${e}, ${n}`);
454
464
  }
455
465
  })
456
466
  );
457
467
  };
458
- function Ce(t) {
459
- return le.test(t) ? [t] : G.test(t) ? (Se.lastIndex = 0, Array.from(t.matchAll(Se)).map((e) => e[1]).filter((e) => !!e)) : [];
468
+ function Le(t) {
469
+ return pe.test(t) ? [t] : G.test(t) ? (we.lastIndex = 0, Array.from(t.matchAll(we)).map((e) => e[1]).filter((e) => !!e)) : [];
460
470
  }
461
471
  async function oe(t, s, e) {
462
- const { getFilename: n, exportAssets: r } = e, o = A(s, n(t));
463
- if (F(U(o), { recursive: !0 }), X(o, V.stringify(t)), r) {
472
+ const { getFilename: n, exportAssets: r } = e, a = b(s, n(t));
473
+ if (F(k(a), { recursive: !0 }), X(a, V.stringify(t)), r) {
464
474
  const i = Z(
465
475
  t,
466
- (a) => typeof a == "string" && (le.test(a) || G.test(a))
467
- ).map((a) => {
468
- const c = ce(t, a);
469
- return Ce(c);
476
+ (o) => typeof o == "string" && (pe.test(o) || G.test(o))
477
+ ).map((o) => {
478
+ const c = le(t, o);
479
+ return Le(c);
470
480
  }).flat().filter(Boolean);
471
- await It(i, U(o));
481
+ await It(i, k(a));
472
482
  }
473
483
  }
474
- const we = new Te({
484
+ const Ee = new Oe({
475
485
  max: 1e3,
476
486
  ttl: 30 * 24 * 60 * 60 * 1e3
477
487
  });
478
- async function Ee(t, s, e) {
488
+ async function Ae(t, s, e) {
479
489
  var i;
480
490
  const n = Z(
481
491
  t,
482
- (a) => typeof a == "string" && (le.test(a) || G.test(a))
483
- ), r = We(2), o = n.map(
484
- (a) => r(async () => {
492
+ (o) => typeof o == "string" && (pe.test(o) || G.test(o))
493
+ ), r = Xe(2), a = n.map(
494
+ (o) => r(async () => {
485
495
  try {
486
- const c = ce(t, a), u = Ce(c);
496
+ const c = le(t, o), u = Le(c);
487
497
  for (const p of u) {
488
- const y = $(p), T = e.getFilePath(p, a), O = T ? `${T}:${y}` : y, D = we.get(O);
498
+ const h = $(p), T = e.getFilePath(p, o), O = T ? `${T}:${h}` : h, D = Ee.get(O);
489
499
  if (D) {
490
- G.test(c) || fe(t, a, D);
500
+ G.test(c) || me(t, o, D);
491
501
  return;
492
502
  }
493
- const k = await bt(T, y, s);
494
- k && (G.test(c) || fe(t, a, k), we.set(O, k));
503
+ const U = await bt(T, h, s);
504
+ U && (G.test(c) || me(t, o, U), Ee.set(O, U));
495
505
  }
496
506
  } catch (c) {
497
- P.error(`Failed to process upload for path ${a.join(".")}:`, c.message || c.reason);
507
+ P.error(`Failed to process upload for path ${o.join(".")}:`, c.message || c.reason);
498
508
  }
499
509
  })
500
- ), l = await Promise.allSettled(o);
510
+ ), l = await Promise.allSettled(a);
501
511
  (i = e.onFinish) == null || i.call(e, l);
502
512
  }
503
513
  async function Tt(t, {
@@ -505,14 +515,14 @@ async function Tt(t, {
505
515
  pageIds: e = "all",
506
516
  componentIds: n = "all",
507
517
  rawConfig: r,
508
- includeResources: o = !1
518
+ includeResources: a = !1
509
519
  } = {}) {
510
- var f, b, g, S, N, E;
520
+ var f, E, m, S, N, A;
511
521
  const l = e === "all" ? t.pageIds : e, i = Ot({
512
522
  state: t,
513
523
  pageIds: l,
514
524
  componentIds: n === "all" ? Object.keys(t.components) : n
515
- }), a = (d, h) => {
525
+ }), o = (d, y) => {
516
526
  var w;
517
527
  return {
518
528
  id: d.id,
@@ -521,9 +531,9 @@ async function Tt(t, {
521
531
  component: d.component,
522
532
  config: d.config,
523
533
  visibility: d.visibility,
524
- properties: ((w = d.locales) == null ? void 0 : w[h]) ?? {}
534
+ properties: ((w = d.locales) == null ? void 0 : w[y]) ?? {}
525
535
  };
526
- }, c = (d, h) => {
536
+ }, c = (d, y) => {
527
537
  var w;
528
538
  return {
529
539
  id: d.id,
@@ -532,18 +542,18 @@ async function Tt(t, {
532
542
  publishedAt: d.publishedAt,
533
543
  isPublic: d.isPublic ?? !0,
534
544
  isTemplate: d.isTemplate ?? !1,
535
- meta: ((w = d.locales) == null ? void 0 : w[h]) ?? {},
545
+ meta: ((w = d.locales) == null ? void 0 : w[y]) ?? {},
536
546
  sections: L(
537
547
  d.sectionIds.map((j) => {
538
548
  const C = d.sections[j];
539
- return C && a(C, h);
549
+ return C && o(C, y);
540
550
  })
541
551
  )
542
552
  };
543
553
  }, u = L(
544
554
  t.supportedLocales.map((d) => d.locale).flatMap(
545
- (d) => l.map((h) => {
546
- const w = t.pages[h];
555
+ (d) => l.map((y) => {
556
+ const w = t.pages[y];
547
557
  return w && {
548
558
  locale: d,
549
559
  slug: w.slug,
@@ -551,49 +561,49 @@ async function Tt(t, {
551
561
  };
552
562
  })
553
563
  )
554
- ), p = je(), y = A(p, "pages");
555
- F(y, { recursive: !0 });
556
- const T = A(p, "components");
564
+ ), p = Ce(), h = b(p, "pages");
565
+ F(h, { recursive: !0 });
566
+ const T = b(p, "components");
557
567
  F(T, { recursive: !0 });
558
- for (const { locale: d, slug: h, page: w } of u)
559
- await oe(w, y, {
560
- getFilename: () => `${De(h) || "index"}.${d}.yml`,
568
+ for (const { locale: d, slug: y, page: w } of u)
569
+ await oe(w, h, {
570
+ getFilename: () => `${je(y) || "index"}.${d}.yml`,
561
571
  exportAssets: s
562
572
  });
563
573
  for (const d of i) {
564
- const h = (f = t.components[d]) == null ? void 0 : f.data;
565
- h && await oe(h, T, {
574
+ const y = (f = t.components[d]) == null ? void 0 : f.data;
575
+ y && await oe(y, T, {
566
576
  getFilename: (w) => `${w.name || "unnamed"}.${w.id}.yml`,
567
577
  exportAssets: s
568
578
  });
569
579
  }
570
- const O = A(p, ".blocklet/pages/pages.config.yml");
571
- F(U(O), { recursive: !0 });
580
+ const O = b(p, ".blocklet/pages/pages.config.yml");
581
+ F(k(O), { recursive: !0 });
572
582
  const D = {
573
583
  pages: L(
574
584
  l.map((d) => {
575
- const h = t.pages[d];
576
- return h && { id: d, slug: h.slug };
585
+ const y = t.pages[d];
586
+ return y && { id: d, slug: y.slug };
577
587
  })
578
588
  ),
579
589
  components: L(
580
590
  i.map((d) => {
581
591
  var w;
582
- const h = (w = t.components[d]) == null ? void 0 : w.data;
583
- return h && {
592
+ const y = (w = t.components[d]) == null ? void 0 : w.data;
593
+ return y && {
584
594
  id: d,
585
- name: h.name
595
+ name: y.name
586
596
  };
587
597
  })
588
598
  ),
589
- ...o ? {
599
+ ...a ? {
590
600
  resources: {
591
601
  components: L(
592
- Object.keys(((b = t.resources) == null ? void 0 : b.components) || {}).map((d) => {
593
- var h, w, j, C;
602
+ Object.keys(((E = t.resources) == null ? void 0 : E.components) || {}).map((d) => {
603
+ var y, w, j, C;
594
604
  return {
595
605
  id: d,
596
- name: (C = (j = (w = (h = t.resources) == null ? void 0 : h.components) == null ? void 0 : w[d]) == null ? void 0 : j.component) == null ? void 0 : C.name
606
+ name: (C = (j = (w = (y = t.resources) == null ? void 0 : y.components) == null ? void 0 : w[d]) == null ? void 0 : j.component) == null ? void 0 : C.name
597
607
  };
598
608
  })
599
609
  )
@@ -603,13 +613,13 @@ async function Tt(t, {
603
613
  config: t.config
604
614
  };
605
615
  X(O, V.stringify(D));
606
- const k = A(p, "config.source.json");
607
- if (r && X(k, JSON.stringify(r)), o) {
608
- const d = A(p, "resources"), h = A(d, "components");
609
- F(h, { recursive: !0 });
610
- for (const w of Object.keys(((g = t == null ? void 0 : t.resources) == null ? void 0 : g.components) ?? {})) {
611
- const j = (E = (N = (S = t.resources) == null ? void 0 : S.components) == null ? void 0 : N[w]) == null ? void 0 : E.component;
612
- j && await oe(j, h, {
616
+ const U = b(p, "config.source.json");
617
+ if (r && X(U, JSON.stringify(r)), a) {
618
+ const d = b(p, "resources"), y = b(d, "components");
619
+ F(y, { recursive: !0 });
620
+ for (const w of Object.keys(((m = t == null ? void 0 : t.resources) == null ? void 0 : m.components) ?? {})) {
621
+ const j = (A = (N = (S = t.resources) == null ? void 0 : S.components) == null ? void 0 : N[w]) == null ? void 0 : A.component;
622
+ j && await oe(j, y, {
613
623
  getFilename: (C) => `${C.name || "unnamed"}.${C.id}.yml`,
614
624
  exportAssets: s
615
625
  });
@@ -617,151 +627,151 @@ async function Tt(t, {
617
627
  }
618
628
  return p;
619
629
  }
620
- async function Le(t, { importAssets: s, includeResources: e } = {}) {
621
- var o, l, i;
630
+ async function Ue(t, { importAssets: s, includeResources: e } = {}) {
631
+ var a, l, i;
622
632
  if (!x(t))
623
633
  return null;
624
634
  let n, r = !1;
625
635
  try {
626
- Y(t).isDirectory() ? n = t : /\.(tgz|gz|tar)$/.test(t) && (r = !0, n = je(), await Ze({ file: t, C: n }));
627
- const a = ae("**/.blocklet/pages/pages.config.yml", { cwd: n, absolute: !0 }).at(0), c = a && A(U(a), "../../pages"), u = a && A(U(a), "../../components");
628
- if (!a)
636
+ Y(t).isDirectory() ? n = t : /\.(tgz|gz|tar)$/.test(t) && (r = !0, n = Ce(), await et({ file: t, C: n }));
637
+ const o = ae("**/.blocklet/pages/pages.config.yml", { cwd: n, absolute: !0 }).at(0), c = o && b(k(o), "../../pages"), u = o && b(k(o), "../../components");
638
+ if (!o)
629
639
  return null;
630
- const p = V.parse(H(a).toString()), y = (f, b, g) => {
631
- let S = A(f, `${b}${g ? `.${g}` : ""}.yml`);
632
- return (!x(S) || !Y(S).isFile()) && (S = A(f, b, `index${g ? `.${g}` : ""}.yml`), !x(S) || !Y(S)) ? null : V.parse(H(S).toString());
633
- }, T = (f, b) => {
640
+ const p = V.parse(H(o).toString()), h = (f, E, m) => {
641
+ let S = b(f, `${E}${m ? `.${m}` : ""}.yml`);
642
+ return (!x(S) || !Y(S).isFile()) && (S = b(f, E, `index${m ? `.${m}` : ""}.yml`), !x(S) || !Y(S)) ? null : V.parse(H(S).toString());
643
+ }, T = (f, E) => {
634
644
  try {
635
- const g = ae(`*.${b}.yml`, { cwd: f, absolute: !0 })[0];
636
- return g ? V.parse(H(g).toString()) : null;
637
- } catch (g) {
638
- P.error("parse component error", g);
645
+ const m = ae(`*.${E}.yml`, { cwd: f, absolute: !0 })[0];
646
+ return m ? V.parse(H(m).toString()) : null;
647
+ } catch (m) {
648
+ P.error("parse component error", m);
639
649
  }
640
650
  return null;
641
651
  }, O = L(
642
652
  p.pages.map(({ slug: f }) => {
643
653
  var N;
644
- const b = L(
645
- p.supportedLocales.map(({ locale: E }) => {
646
- const d = c ? y(c, De(f), E) : void 0;
654
+ const E = L(
655
+ p.supportedLocales.map(({ locale: A }) => {
656
+ const d = c ? h(c, je(f), A) : void 0;
647
657
  if (d)
648
- return { locale: E, page: d };
649
- const h = c ? y(c, f, E) : void 0;
650
- return h && { locale: E, page: h };
658
+ return { locale: A, page: d };
659
+ const y = c ? h(c, f, A) : void 0;
660
+ return y && { locale: A, page: y };
651
661
  })
652
- ), g = (N = b[0]) == null ? void 0 : N.page;
653
- if (!g)
662
+ ), m = (N = E[0]) == null ? void 0 : N.page;
663
+ if (!m)
654
664
  return null;
655
- const S = g.sections.map((E) => {
656
- const d = E.id || ye();
665
+ const S = m.sections.map((A) => {
666
+ const d = A.id || Se();
657
667
  return {
658
668
  id: d,
659
- component: E.component,
660
- config: E.config,
661
- name: E.name,
662
- isTemplateSection: E.isTemplateSection ?? !1,
663
- visibility: E.visibility,
669
+ component: A.component,
670
+ config: A.config,
671
+ name: A.name,
672
+ isTemplateSection: A.isTemplateSection ?? !1,
673
+ visibility: A.visibility,
664
674
  locales: Object.fromEntries(
665
675
  L(
666
- b.map(({ locale: h, page: w }) => {
676
+ E.map(({ locale: y, page: w }) => {
667
677
  const j = w.sections.find((C) => C.id === d);
668
- return j && [h, j.properties];
678
+ return j && [y, j.properties];
669
679
  })
670
680
  )
671
681
  )
672
682
  };
673
683
  });
674
684
  return {
675
- id: g.id || ye(),
676
- createdAt: g.createdAt,
677
- updatedAt: g.updatedAt,
678
- publishedAt: g.publishedAt,
679
- isPublic: g.isPublic ?? !0,
680
- isTemplate: g.isTemplate ?? !1,
685
+ id: m.id || Se(),
686
+ createdAt: m.createdAt,
687
+ updatedAt: m.updatedAt,
688
+ publishedAt: m.publishedAt,
689
+ isPublic: m.isPublic ?? !0,
690
+ isTemplate: m.isTemplate ?? !1,
681
691
  slug: f,
682
- sections: Object.fromEntries(S.map((E) => [E.id, E])),
683
- sectionIds: S.map((E) => E.id),
684
- locales: Object.fromEntries(b.map(({ locale: E, page: d }) => [E, d.meta]))
692
+ sections: Object.fromEntries(S.map((A) => [A.id, A])),
693
+ sectionIds: S.map((A) => A.id),
694
+ locales: Object.fromEntries(E.map(({ locale: A, page: d }) => [A, d.meta]))
685
695
  };
686
696
  })
687
- ), D = u ? L(((o = p.components) == null ? void 0 : o.map(({ id: f }) => T(u, f))) ?? []) : [];
697
+ ), D = u ? L(((a = p.components) == null ? void 0 : a.map(({ id: f }) => T(u, f))) ?? []) : [];
688
698
  if (s) {
689
- const f = (...b) => {
690
- P.info(`[${r ? $(t) : $(A(t, "../../../../"))}] importAssets:`, ...b);
699
+ const f = (...E) => {
700
+ P.info(`[${r ? $(t) : $(b(t, "../../../../"))}] importAssets:`, ...E);
691
701
  };
692
702
  try {
693
- f("wait image-bin api ready"), await et({
694
- resources: [`${Me(pt)}/api/sdk/uploads`],
703
+ f("wait image-bin api ready"), await tt({
704
+ resources: [`${$e(dt)}/api/sdk/uploads`],
695
705
  validateStatus: (S) => S >= 200 && S <= 500
696
706
  }), f("image-bin api is ready");
697
- const b = {}, g = {};
707
+ const E = {}, m = {};
698
708
  f("start to upload assets"), await Promise.allSettled([
699
- Ee(D, b, {
700
- getFilePath: (S) => u && A(u, S),
709
+ Ae(D, E, {
710
+ getFilePath: (S) => u && b(u, S),
701
711
  onFinish: (S) => {
702
712
  f(`upload ${S.length} component assets`);
703
713
  }
704
714
  }),
705
- Ee(O, g, {
715
+ Ae(O, m, {
706
716
  getFilePath: (S, N) => {
707
- const E = ce(O, N.slice(0, 1));
708
- return c && A(c, U(E.slug), S);
717
+ const A = le(O, N.slice(0, 1));
718
+ return c && b(c, k(A.slug), S);
709
719
  },
710
720
  onFinish: (S) => {
711
721
  f(`upload ${S.length} page assets`);
712
722
  }
713
723
  })
714
724
  ]), f("upload assets done"), global.gc && global.gc();
715
- } catch (b) {
716
- f("Error during asset import:", b);
725
+ } catch (E) {
726
+ f("Error during asset import:", E);
717
727
  }
718
728
  }
719
- const k = {};
729
+ const U = {};
720
730
  if (e) {
721
- const f = a && A(U(a), "../../resources/components"), b = L(
722
- ((i = (l = p.resources) == null ? void 0 : l.components) == null ? void 0 : i.map(({ id: g }) => T(f, g))) ?? []
731
+ const f = o && b(k(o), "../../resources/components"), E = L(
732
+ ((i = (l = p.resources) == null ? void 0 : l.components) == null ? void 0 : i.map(({ id: m }) => T(f, m))) ?? []
723
733
  );
724
- b.length > 0 && (k.components = Object.fromEntries(
725
- b.map((g, S) => [g.id, { index: S, component: g }])
734
+ E.length > 0 && (U.components = Object.fromEntries(
735
+ E.map((m, S) => [m.id, { index: S, component: m }])
726
736
  ));
727
737
  }
728
738
  return {
729
739
  supportedLocales: p.supportedLocales,
730
740
  pageIds: O.map((f) => f.id),
731
- components: Object.fromEntries(D.map((f, b) => [f.id, { index: b, data: f }])),
741
+ components: Object.fromEntries(D.map((f, E) => [f.id, { index: E, data: f }])),
732
742
  pages: Object.fromEntries(O.map((f) => [f.id, f])),
733
743
  config: p.config || {},
734
- resources: k
744
+ resources: U
735
745
  };
736
746
  } finally {
737
- r && n && ve(n, { force: !0, recursive: !0 });
747
+ r && n && Ie(n, { force: !0, recursive: !0 });
738
748
  }
739
749
  }
740
- async function Ae(t, s, {
750
+ async function be(t, s, {
741
751
  pages: e,
742
752
  pageMergeMode: n = "byUpdateTime",
743
753
  deletePages: r = !1,
744
- publishMode: o = void 0
754
+ publishMode: a = void 0
745
755
  } = {}) {
746
756
  try {
747
- o && Ne(o);
757
+ a && Fe(a);
748
758
  } catch (u) {
749
759
  P.error("clear preload page cache error", { error: u });
750
760
  }
751
- const { pageIds: l, pages: i, supportedLocales: a } = t;
761
+ const { pageIds: l, pages: i, supportedLocales: o } = t;
752
762
  for (const u of e ?? l) {
753
763
  const p = i[u];
754
764
  if (!p) {
755
- const y = s.pageIds.indexOf(u);
756
- y !== -1 && r && (s.pageIds.splice(y, 1), delete s.pages[u]);
765
+ const h = s.pageIds.indexOf(u);
766
+ h !== -1 && r && (s.pageIds.splice(h, 1), delete s.pages[u]);
757
767
  continue;
758
768
  }
759
769
  if (s.pageIds.includes(p.id)) {
760
770
  if (n === "replace")
761
771
  s.pages[p.id] = p;
762
772
  else if (n === "byUpdateTime") {
763
- const y = s.pages[p.id];
764
- (!y || p.updatedAt && p.updatedAt > y.updatedAt) && (s.pages[p.id] = p);
773
+ const h = s.pages[p.id];
774
+ (!h || p.updatedAt && p.updatedAt > h.updatedAt) && (s.pages[p.id] = p);
765
775
  }
766
776
  } else
767
777
  s.pageIds.push(p.id), s.pages[p.id] = p;
@@ -769,38 +779,38 @@ async function Ae(t, s, {
769
779
  if (r && !e)
770
780
  for (const u of s.pageIds)
771
781
  t.pageIds.includes(u) || delete s.pages[u], s.pageIds = [...s.pageIds].filter((p) => t.pageIds.includes(p));
772
- if (s.supportedLocales.splice(0, s.supportedLocales.length), s.supportedLocales.push(...Ke(a)), r)
782
+ if (s.supportedLocales.splice(0, s.supportedLocales.length), s.supportedLocales.push(...He(o)), r)
773
783
  for (const u of Object.keys(s.components))
774
784
  delete s.components[u];
775
785
  let c = JSON.parse(JSON.stringify(t.components));
776
786
  c = Object.fromEntries(
777
787
  await Promise.all(
778
788
  Object.entries(c).map(async ([u, p]) => {
779
- const y = await Ue(p == null ? void 0 : p.data);
789
+ const h = await ke(p == null ? void 0 : p.data);
780
790
  return [
781
791
  u,
782
792
  {
783
793
  ...p,
784
- data: y
794
+ data: h
785
795
  }
786
796
  ];
787
797
  })
788
798
  )
789
799
  ), Object.assign(s.components, c), Object.assign(s.config, JSON.parse(JSON.stringify(t.config))), s.resources.components = JSON.parse(JSON.stringify(t.resources.components || {}));
790
800
  }
791
- const Ue = _e(
801
+ const ke = Me(
792
802
  async (t) => {
793
803
  var s;
794
- if (!He(t == null ? void 0 : t.properties))
804
+ if (!Ye(t == null ? void 0 : t.properties))
795
805
  return t;
796
806
  if (((s = t == null ? void 0 : t.renderer) == null ? void 0 : s.type) === "react-component") {
797
807
  const { script: e } = (t == null ? void 0 : t.renderer) || {};
798
808
  if (e)
799
809
  try {
800
- const n = await Fe(e, "PROPERTIES_SCHEMA", t.id);
801
- n && n.length > 0 && t && (t.properties = {}, n.forEach((r, o) => {
810
+ const n = await _e(e, "PROPERTIES_SCHEMA", t.id);
811
+ n && n.length > 0 && t && (t.properties = {}, n.forEach((r, a) => {
802
812
  t != null && t.properties && (t.properties[r.id] = {
803
- index: o,
813
+ index: a,
804
814
  data: r
805
815
  });
806
816
  }));
@@ -820,37 +830,37 @@ function Ot({
820
830
  componentIds: e = []
821
831
  }) {
822
832
  var l;
823
- const n = (i, a = /* @__PURE__ */ new Set()) => (Array.isArray(i) && i.forEach((c) => n(c, a)), i && typeof i == "object" && (typeof i.componentId == "string" && a.add(i.componentId), Object.values(i).forEach((c) => n(c, a))), a), r = new Set(e);
833
+ const n = (i, o = /* @__PURE__ */ new Set()) => (Array.isArray(i) && i.forEach((c) => n(c, o)), i && typeof i == "object" && (typeof i.componentId == "string" && o.add(i.componentId), Object.values(i).forEach((c) => n(c, o))), o), r = new Set(e);
824
834
  for (const i of s) {
825
- const a = t.pages[i];
826
- n(a, r);
835
+ const o = t.pages[i];
836
+ n(o, r);
827
837
  }
828
- const o = [...r];
829
- for (; o.length; ) {
830
- const i = o.shift();
838
+ const a = [...r];
839
+ for (; a.length; ) {
840
+ const i = a.shift();
831
841
  r.has(i) || r.add(i);
832
- const a = (l = t.components[i]) == null ? void 0 : l.data;
833
- if (a)
834
- for (const c of n(a))
835
- r.has(c) || o.push(c);
842
+ const o = (l = t.components[i]) == null ? void 0 : l.data;
843
+ if (o)
844
+ for (const c of n(o))
845
+ r.has(c) || a.push(c);
836
846
  }
837
847
  return [...r];
838
848
  }
839
- let ee, J, pe, de;
840
- function ke() {
849
+ let ee, J, de, ue;
850
+ function Re() {
841
851
  return ee = (async () => {
842
- const t = $e({
852
+ const t = Be({
843
853
  types: [
844
- { did: Pe, type: he },
845
- { did: mt, type: he }
854
+ { did: De, type: ye },
855
+ { did: gt, type: ye }
846
856
  ]
847
857
  });
848
858
  J = (await Promise.all(
849
859
  t.map(async (e) => {
850
- const n = e.path ? await Le(e.path, { importAssets: !1 }) : void 0;
860
+ const n = e.path ? await Ue(e.path, { importAssets: !1 }) : void 0;
851
861
  return n ? { blockletId: e.did, state: n, blockletTitle: e.title } : void 0;
852
862
  })
853
- )).filter((e) => !!e), pe = J.reduce(
863
+ )).filter((e) => !!e), de = J.reduce(
854
864
  (e, n) => Object.assign(
855
865
  e,
856
866
  Object.fromEntries(
@@ -868,10 +878,10 @@ function ke() {
868
878
  ),
869
879
  {}
870
880
  );
871
- de = Object.fromEntries(
881
+ ue = Object.fromEntries(
872
882
  await Promise.all(
873
883
  Object.entries(s).map(async ([e, n]) => {
874
- const r = await Ue(n.component);
884
+ const r = await ke(n.component);
875
885
  return [
876
886
  e,
877
887
  {
@@ -885,36 +895,36 @@ function ke() {
885
895
  })(), ee;
886
896
  }
887
897
  function Pt(t) {
888
- const s = Ie(
898
+ const s = Te(
889
899
  async () => {
890
- await ke().catch((e) => {
900
+ await Re().catch((e) => {
891
901
  P.error("load resource states error", { error: e });
892
- }), await (t == null ? void 0 : t({ states: J, pages: pe, components: de }));
902
+ }), await (t == null ? void 0 : t({ states: J, pages: de, components: ue }));
893
903
  },
894
904
  3e3,
895
905
  { leading: !1, trailing: !0 }
896
906
  );
897
- return s(), m.events.on(m.Events.componentAdded, s), m.events.on(m.Events.componentRemoved, s), m.events.on(m.Events.componentStarted, s), m.events.on(m.Events.componentStopped, s), m.events.on(m.Events.componentUpdated, s), m.events.on(ie, s), () => {
898
- m.events.off(m.Events.componentAdded, s), m.events.off(m.Events.componentRemoved, s), m.events.off(m.Events.componentStarted, s), m.events.off(m.Events.componentStopped, s), m.events.off(m.Events.componentUpdated, s), m.events.off(ie, s);
907
+ return s(), g.events.on(g.Events.componentAdded, s), g.events.on(g.Events.componentRemoved, s), g.events.on(g.Events.componentStarted, s), g.events.on(g.Events.componentStopped, s), g.events.on(g.Events.componentUpdated, s), g.events.on(ie, s), () => {
908
+ g.events.off(g.Events.componentAdded, s), g.events.off(g.Events.componentRemoved, s), g.events.off(g.Events.componentStarted, s), g.events.off(g.Events.componentStopped, s), g.events.off(g.Events.componentUpdated, s), g.events.off(ie, s);
899
909
  };
900
910
  }
901
- const Re = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), W = globalThis;
902
- var be;
903
- (be = W[Re]) == null || be.call(W);
904
- W[Re] = Pt(async ({ pages: t, components: s }) => {
911
+ const Ne = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), W = globalThis;
912
+ var ve;
913
+ (ve = W[Ne]) == null || ve.call(W);
914
+ W[Ne] = Pt(async ({ pages: t, components: s }) => {
905
915
  const { projectIds: e } = Q;
906
916
  await Promise.all(
907
917
  e.map(async (n) => {
908
918
  const r = Q.shared(n);
909
919
  r.syncedStore.resources.pages = t;
910
- const o = await _.findByPk(n);
911
- if (o != null && o.useAllResources)
920
+ const a = await _.findByPk(n);
921
+ if (a != null && a.useAllResources)
912
922
  r.syncedStore.resources.components = s;
913
923
  else {
914
- const i = (await te.findAll({ where: { projectId: n } })).map((c) => c.componentId), a = Object.fromEntries(
924
+ const i = (await te.findAll({ where: { projectId: n } })).map((c) => c.componentId), o = Object.fromEntries(
915
925
  Object.entries(s || {}).filter(([c]) => i.includes(c))
916
926
  );
917
- r.syncedStore.resources.components = a;
927
+ r.syncedStore.resources.components = o;
918
928
  }
919
929
  P.info(`update [${n}] resource states:`, {
920
930
  pages: Object.keys(r.syncedStore.resources.pages || {}).length,
@@ -924,26 +934,26 @@ W[Re] = Pt(async ({ pages: t, components: s }) => {
924
934
  );
925
935
  });
926
936
  async function ts() {
927
- P.info("trigger reload all project resource"), m.events.emit(ie);
937
+ P.info("trigger reload all project resource"), g.events.emit(ie);
928
938
  }
929
939
  async function Dt() {
930
- return ee ?? (ee = ke()), await ee, { states: J, pages: pe, components: de };
940
+ return ee ?? (ee = Re()), await ee, { states: J, pages: de, components: ue };
931
941
  }
932
942
  export {
933
- Pe as C,
943
+ De as C,
934
944
  _ as P,
935
- he as R,
945
+ ye as R,
936
946
  Q as S,
937
947
  Dt as a,
938
948
  K as b,
939
949
  Zt as c,
940
950
  es as d,
941
951
  Pt as e,
942
- Le as f,
952
+ Ue as f,
943
953
  Qt as g,
944
954
  ts as h,
945
955
  Xt as i,
946
- Ae as m,
947
- ye as n,
956
+ be as m,
957
+ Se as n,
948
958
  Tt as t
949
959
  };