@blocklet/pages-kit-inner-components 0.0.18 → 0.1.0

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