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