@blocklet/pages-kit-inner-components 0.5.40 → 0.5.42
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/{array-Cr5KF-hM.js → array-Cip5uTnI.js} +1 -1
- package/lib/cjs/chunks/{config-string-BYZ5HfyY.js → config-string-CEipCOnU.js} +1 -1
- package/lib/cjs/chunks/{draft-data-6zW9mu28.js → draft-data-F0V4PcIs.js} +1 -1
- package/lib/cjs/chunks/home-BCFoaIEZ.js +38 -0
- package/lib/cjs/chunks/{publish-button-B-H_3RtT.js → publish-button-Bbd4z1_d.js} +1 -1
- package/lib/cjs/chunks/site-state-CeQEnrvX.js +57 -0
- package/lib/cjs/chunks/state-UwRWAZRe.js +1 -0
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +3 -3
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +2 -2
- package/lib/cjs/site-state.js +1 -1
- package/lib/cjs/theme.js +1 -1
- package/lib/es/add-component.js +3 -3
- package/lib/es/chunks/{array-D34Qpnhk.js → array-DM0x2Sjw.js} +1 -1
- package/lib/es/chunks/{config-string-DgK7ETCs.js → config-string-Dw6sJMn_.js} +1 -1
- package/lib/es/chunks/{draft-data-B5kzDvTI.js → draft-data-sTSk4UTm.js} +1 -1
- package/lib/es/chunks/home-ClxOpmCx.js +569 -0
- package/lib/es/chunks/{publish-button-CvQPEUZl.js → publish-button-CKXdANG9.js} +3 -3
- package/lib/es/chunks/{site-state-DI5PAxyt.js → site-state-BeEHvakk.js} +410 -399
- package/lib/es/chunks/{state-BzwEX9VC.js → state-COB6reM7.js} +98 -103
- package/lib/es/components.js +1 -1
- package/lib/es/home.js +3 -3
- package/lib/es/project-html.js +70 -70
- package/lib/es/resources.js +1 -1
- package/lib/es/setting.js +1152 -888
- package/lib/es/site-state.js +1 -1
- package/lib/es/theme.js +14 -11
- package/package.json +11 -11
- package/lib/cjs/chunks/home-DJPbdJux.js +0 -38
- package/lib/cjs/chunks/site-state-6tgRGL_9.js +0 -57
- package/lib/cjs/chunks/state-BWuBNdK8.js +0 -1
- package/lib/es/chunks/home-DpmpXDlo.js +0 -532
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var Pt = Object.defineProperty;
|
|
2
2
|
var Tt = (e, n, t) => n in e ? Pt(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
|
|
3
|
-
var
|
|
3
|
+
var x = (e, n, t) => Tt(e, typeof n != "symbol" ? n + "" : n, t);
|
|
4
4
|
import { getComponentMountPoint as vt } from "@blocklet/pages-kit/builtin/utils";
|
|
5
5
|
import { PreloadComponentScriptModule as ye } from "@blocklet/pages-kit/types";
|
|
6
6
|
import { componentUMDName as kt, RenderNestedComponent as ze, mergeComponent as Dt, getComponentDependencies as xt } from "@blocklet/pages-kit/utils/property";
|
|
@@ -8,11 +8,11 @@ import { memoize as it, Sandbox as ct, BuiltinModules as Rt } from "@blocklet/qu
|
|
|
8
8
|
import I from "@blocklet/sdk/lib/config";
|
|
9
9
|
import { LRUCache as Pe } from "lru-cache";
|
|
10
10
|
import jt, { Headers as $t } from "node-fetch";
|
|
11
|
-
import { joinURL as
|
|
12
|
-
import { createHash as
|
|
11
|
+
import { joinURL as Q, getQuery as Lt, withQuery as Nt, parseURL as We, withHttps as _t } from "ufo";
|
|
12
|
+
import { createHash as ne } from "crypto";
|
|
13
13
|
import Mt from "@blocklet/logger";
|
|
14
|
-
import { promises as
|
|
15
|
-
import pt, { join as O, dirname as
|
|
14
|
+
import { promises as z, readFileSync as ae, mkdtempSync as Ut, existsSync as K, lstatSync as re, readdirSync as Ft, rmSync as lt, renameSync as Ye, mkdirSync as Y, writeFileSync as we, copyFileSync as Bt, createWriteStream as Gt } from "fs";
|
|
15
|
+
import pt, { join as O, dirname as H, basename as J } from "path";
|
|
16
16
|
import Ht from "lodash/isNil";
|
|
17
17
|
import { BuiltinModules as Jt } from "@blocklet/pages-kit/utils/builtin";
|
|
18
18
|
import { isRelativeModule as Vt, createBuiltinModuleTransformer as Kt } from "@blocklet/pages-kit/utils/typescript/builtin-module-transformer";
|
|
@@ -21,9 +21,9 @@ import qt from "autoprefixer";
|
|
|
21
21
|
import * as Qt from "esbuild";
|
|
22
22
|
import Xt from "postcss";
|
|
23
23
|
import Zt from "tailwindcss";
|
|
24
|
-
import
|
|
25
|
-
import { getYjsValue as
|
|
26
|
-
import * as
|
|
24
|
+
import U from "typescript";
|
|
25
|
+
import { getYjsValue as le, syncedStore as es } from "@syncedstore/core";
|
|
26
|
+
import * as W from "yjs";
|
|
27
27
|
import { setPageDataSource as ts } from "@blocklet/pages-kit/utils/data-source";
|
|
28
28
|
import { getRouteMetaDataByOptionIds as ss, generateParamCombinations as Fe } from "@blocklet/pages-kit/utils/route";
|
|
29
29
|
import { cloneDeep as ns } from "lodash";
|
|
@@ -45,7 +45,7 @@ import { x as ds } from "tar";
|
|
|
45
45
|
import us from "wait-on";
|
|
46
46
|
import { Awareness as fs, encodeAwarenessUpdate as Qe, removeAwarenessStates as ms, applyAwarenessUpdate as hs } from "y-protocols/awareness";
|
|
47
47
|
import { writeUpdate as gs, writeSyncStep1 as ys, readSyncMessage as Ss } from "y-protocols/sync";
|
|
48
|
-
import * as
|
|
48
|
+
import * as ie from "yaml";
|
|
49
49
|
import { DataTypes as R, Sequelize as ws, Model as ft, Op as Es } from "sequelize";
|
|
50
50
|
import "sqlite3";
|
|
51
51
|
import "@blocklet/pages-kit/types/state";
|
|
@@ -54,16 +54,16 @@ I.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY;
|
|
|
54
54
|
I.env.OPENAI_BASE_URL || process.env.OPENAI_BASE_URL;
|
|
55
55
|
I.env.TRANSLATE_ADDITIONAL_PROMPT || process.env.TRANSLATE_ADDITIONAL_PROMPT;
|
|
56
56
|
I.env.PAGE_CONTENT_ADDITIONAL_PROMPT || process.env.PAGE_CONTENT_ADDITIONAL_PROMPT;
|
|
57
|
-
const
|
|
57
|
+
const bs = "image-bin";
|
|
58
58
|
I.env.INIT_TEMPLATE_PATH;
|
|
59
|
-
const
|
|
59
|
+
const Is = process.env.DATABASE_URL || pt.join(I.env.dataDir, "db/pages-kit.db"), Xe = I, eo = () => I.env.tenantMode === "multiple", to = () => {
|
|
60
60
|
var e;
|
|
61
61
|
return (Ht(Xe.env.preferences.multiTenantAllProjectAccessPassports) ? [] : (e = Xe.env.preferences.multiTenantAllProjectAccessPassports) == null ? void 0 : e.split(",")) || [];
|
|
62
62
|
}, As = pt.join(I.env.dataDir, "fs-memoize-cache"), Os = I.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", y = Mt("pages-kit"), Cs = R.sqlite.DATE.parse;
|
|
63
63
|
R.sqlite.DATE.parse = (e, n) => typeof e == "number" ? new Date(e) : Cs(e, n);
|
|
64
64
|
const me = new ws({
|
|
65
65
|
dialect: "sqlite",
|
|
66
|
-
storage:
|
|
66
|
+
storage: Is,
|
|
67
67
|
benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
|
|
68
68
|
retry: {
|
|
69
69
|
match: [/SQLITE_BUSY/],
|
|
@@ -99,16 +99,16 @@ Te.init(
|
|
|
99
99
|
},
|
|
100
100
|
{ sequelize: me, tableName: "ProjectComponents", timestamps: !1 }
|
|
101
101
|
);
|
|
102
|
-
class
|
|
102
|
+
class X extends ft {
|
|
103
103
|
static async getProjectByIdOrSlug(n) {
|
|
104
|
-
return
|
|
104
|
+
return X.findOne({
|
|
105
105
|
where: {
|
|
106
106
|
[Es.or]: [{ id: n }, { slug: n }]
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
X.init(
|
|
112
112
|
{
|
|
113
113
|
id: {
|
|
114
114
|
type: R.UUID,
|
|
@@ -149,36 +149,36 @@ q.init(
|
|
|
149
149
|
},
|
|
150
150
|
{ sequelize: me, paranoid: !0 }
|
|
151
151
|
);
|
|
152
|
-
|
|
152
|
+
X.hasMany(Te, {
|
|
153
153
|
foreignKey: "projectId",
|
|
154
154
|
as: "components"
|
|
155
155
|
});
|
|
156
156
|
const Ps = As, Ts = Os, _e = 7 * 24 * 60 * 60 * 1e3, vs = 24 * 60 * 60 * 1e3, mt = async (e = "") => {
|
|
157
157
|
const n = O(Ps, e);
|
|
158
158
|
try {
|
|
159
|
-
if (!(await
|
|
159
|
+
if (!(await z.stat(n)).isDirectory())
|
|
160
160
|
throw new Error(`${n} is not a directory`);
|
|
161
161
|
} catch {
|
|
162
|
-
await
|
|
162
|
+
await z.mkdir(n, { recursive: !0 });
|
|
163
163
|
}
|
|
164
164
|
return n;
|
|
165
165
|
}, ks = (e, n) => {
|
|
166
|
-
const t =
|
|
166
|
+
const t = ne("md5").update(n).digest("hex");
|
|
167
167
|
return O(e, `${Ts}-${t}.json`);
|
|
168
168
|
}, Ds = async (e = "") => {
|
|
169
169
|
const n = await mt(e), t = Date.now();
|
|
170
170
|
try {
|
|
171
|
-
const s = await
|
|
171
|
+
const s = await z.readdir(n);
|
|
172
172
|
await Promise.all(
|
|
173
173
|
s.filter((o) => o.endsWith(".json")).map(async (o) => {
|
|
174
174
|
const r = O(n, o);
|
|
175
175
|
try {
|
|
176
|
-
const a = await
|
|
177
|
-
u.createdAt && t - u.createdAt > _e && await
|
|
176
|
+
const a = await z.readFile(r, "utf-8"), u = JSON.parse(a);
|
|
177
|
+
u.createdAt && t - u.createdAt > _e && await z.unlink(r);
|
|
178
178
|
} catch {
|
|
179
179
|
try {
|
|
180
|
-
const u = await
|
|
181
|
-
t - u.mtimeMs > _e && await
|
|
180
|
+
const u = await z.stat(r);
|
|
181
|
+
t - u.mtimeMs > _e && await z.unlink(r);
|
|
182
182
|
} catch {
|
|
183
183
|
}
|
|
184
184
|
}
|
|
@@ -200,14 +200,14 @@ function Ge(e, n) {
|
|
|
200
200
|
async (...s) => {
|
|
201
201
|
const o = await mt(n.subdir || ""), r = n.keyGenerator ? n.keyGenerator(...s) : JSON.stringify(s), a = ks(o, r);
|
|
202
202
|
try {
|
|
203
|
-
const u = await
|
|
203
|
+
const u = await z.readFile(a, "utf-8"), { value: c, createdAt: i } = JSON.parse(u);
|
|
204
204
|
if (i && Date.now() - i > _e)
|
|
205
|
-
throw await
|
|
205
|
+
throw await z.unlink(a).catch(() => {
|
|
206
206
|
}), new Error("Cache expired");
|
|
207
207
|
return c;
|
|
208
208
|
} catch {
|
|
209
209
|
const c = await e(...s), i = JSON.stringify({ value: c, createdAt: Date.now() });
|
|
210
|
-
return
|
|
210
|
+
return z.writeFile(a, i, "utf-8").catch((p) => {
|
|
211
211
|
console.error("Failed to write fs cache:", p);
|
|
212
212
|
}), c;
|
|
213
213
|
}
|
|
@@ -244,30 +244,30 @@ ${e}
|
|
|
244
244
|
`;
|
|
245
245
|
}, Ze = Ge(
|
|
246
246
|
async (e, n) => {
|
|
247
|
-
let t =
|
|
247
|
+
let t = U.transpileModule(e, {
|
|
248
248
|
compilerOptions: {
|
|
249
|
-
jsx:
|
|
250
|
-
target:
|
|
251
|
-
module:
|
|
249
|
+
jsx: U.JsxEmit.React,
|
|
250
|
+
target: U.ScriptTarget.ES2016,
|
|
251
|
+
module: U.ModuleKind.ESNext
|
|
252
252
|
},
|
|
253
253
|
transformers: {
|
|
254
|
-
before: [Kt(
|
|
254
|
+
before: [Kt(U)]
|
|
255
255
|
}
|
|
256
256
|
}).outputText;
|
|
257
257
|
if (n.tailwind && (t = await js(t, { componentId: n.componentId })), n.module === ye.ESM) return t;
|
|
258
|
-
const s =
|
|
258
|
+
const s = U.transpileModule(t, {
|
|
259
259
|
compilerOptions: {
|
|
260
|
-
jsx:
|
|
261
|
-
target:
|
|
262
|
-
module:
|
|
263
|
-
moduleResolution:
|
|
260
|
+
jsx: U.JsxEmit.React,
|
|
261
|
+
target: U.ScriptTarget.ES2016,
|
|
262
|
+
module: U.ModuleKind.CommonJS,
|
|
263
|
+
moduleResolution: U.ModuleResolutionKind.Node16
|
|
264
264
|
}
|
|
265
265
|
}).outputText;
|
|
266
266
|
return n.module === ye.CJS ? s : Ls(n.moduleName, s);
|
|
267
267
|
},
|
|
268
268
|
{
|
|
269
269
|
keyGenerator: (e, n) => {
|
|
270
|
-
const t =
|
|
270
|
+
const t = ne("md5").update(e).digest("hex"), s = {
|
|
271
271
|
...n,
|
|
272
272
|
componentId: n.componentId,
|
|
273
273
|
module: n.module,
|
|
@@ -308,7 +308,7 @@ ${e}
|
|
|
308
308
|
const f = p.path.split("/").pop();
|
|
309
309
|
if (i || (i = await Ve({ ensureLoaded: !1 })), (S = i == null ? void 0 : i.chunks) != null && S[f])
|
|
310
310
|
try {
|
|
311
|
-
const d =
|
|
311
|
+
const d = ae(i.chunks[f], "utf-8");
|
|
312
312
|
return y.info("get chunk from local file system", f), { contents: d, loader: "tsx" };
|
|
313
313
|
} catch {
|
|
314
314
|
}
|
|
@@ -321,8 +321,8 @@ ${e}
|
|
|
321
321
|
})).outputFiles) == null ? void 0 : a[0]) == null ? void 0 : u.contents;
|
|
322
322
|
if (!s) throw new Error("Failed to build server code");
|
|
323
323
|
const o = Buffer.from(s).toString();
|
|
324
|
-
return
|
|
325
|
-
compilerOptions: { module:
|
|
324
|
+
return U.transpileModule(o, {
|
|
325
|
+
compilerOptions: { module: U.ModuleKind.ESNext, target: U.ScriptTarget.ES2020 }
|
|
326
326
|
}).outputText;
|
|
327
327
|
}, ht = Ge(
|
|
328
328
|
async (e, n) => {
|
|
@@ -334,7 +334,7 @@ ${e}
|
|
|
334
334
|
},
|
|
335
335
|
{
|
|
336
336
|
keyGenerator: (e, n) => {
|
|
337
|
-
const t =
|
|
337
|
+
const t = ne("md5").update(e).digest("hex");
|
|
338
338
|
return JSON.stringify(["extractExportValueSchema", t, n]);
|
|
339
339
|
},
|
|
340
340
|
lruOptions: {
|
|
@@ -423,14 +423,14 @@ async function so({
|
|
|
423
423
|
properties: d.properties
|
|
424
424
|
});
|
|
425
425
|
if (!w) return null;
|
|
426
|
-
const
|
|
426
|
+
const D = { instanceId: d.id, preload: w };
|
|
427
427
|
if (e !== "draft" && d.useCache) {
|
|
428
|
-
let
|
|
429
|
-
d.cacheDuration && (
|
|
430
|
-
ttl:
|
|
428
|
+
let P = Ns;
|
|
429
|
+
d.cacheDuration && (P = d.cacheDuration), y.info(`set preload component to cache(${P}s): ${l}`), ue.set(l, D, {
|
|
430
|
+
ttl: P * 1e3
|
|
431
431
|
});
|
|
432
432
|
}
|
|
433
|
-
return
|
|
433
|
+
return D;
|
|
434
434
|
} catch (l) {
|
|
435
435
|
return y.error("get preload component error", { instanceId: d.id, componentId: d.componentId }, { error: l }), null;
|
|
436
436
|
}
|
|
@@ -631,7 +631,7 @@ export { joinURL, withQuery, getQuery, getComponentMountPoint }
|
|
|
631
631
|
}
|
|
632
632
|
},
|
|
633
633
|
getComponentMountPoint: vt,
|
|
634
|
-
joinURL:
|
|
634
|
+
joinURL: Q,
|
|
635
635
|
withQuery: Nt,
|
|
636
636
|
getQuery: Lt
|
|
637
637
|
},
|
|
@@ -640,9 +640,9 @@ export { joinURL, withQuery, getQuery, getComponentMountPoint }
|
|
|
640
640
|
{
|
|
641
641
|
// NOTE: IMPORTANT! place location and fetch (has side effect) at the args not global
|
|
642
642
|
// because the global is shared between all runtime and just init once
|
|
643
|
-
location: { href:
|
|
643
|
+
location: { href: Q(_t(s.hostname), s.originalUrl) },
|
|
644
644
|
fetch: (i, { ...p } = {}) => {
|
|
645
|
-
const S = typeof i == "string" && i.startsWith("/") ?
|
|
645
|
+
const S = typeof i == "string" && i.startsWith("/") ? Q(I.env.appUrl, i) : i;
|
|
646
646
|
if (typeof S == "string" && We(S).host === We(I.env.appUrl).host) {
|
|
647
647
|
const f = s.get("cookie");
|
|
648
648
|
if (f) {
|
|
@@ -692,7 +692,7 @@ const Js = it(
|
|
|
692
692
|
},
|
|
693
693
|
{
|
|
694
694
|
keyGenerator: (e, n, t) => {
|
|
695
|
-
const s =
|
|
695
|
+
const s = ne("md5").update(e).digest("hex");
|
|
696
696
|
return JSON.stringify(["getExportSchemaValueFromCode", s, n, t]);
|
|
697
697
|
},
|
|
698
698
|
lruOptions: {
|
|
@@ -701,7 +701,7 @@ const Js = it(
|
|
|
701
701
|
}
|
|
702
702
|
}
|
|
703
703
|
), Vs = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", tt = "page", Me = "trigger-reload-project-resource", yt = Vs, Ks = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM";
|
|
704
|
-
function
|
|
704
|
+
function be(e) {
|
|
705
705
|
e.observeDeep((n) => {
|
|
706
706
|
n.some((t) => t.changes.keys.has("updatedAt") || t.changes.keys.has("publishedAt")) || e.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
|
|
707
707
|
});
|
|
@@ -709,23 +709,23 @@ function Ie(e) {
|
|
|
709
709
|
function St() {
|
|
710
710
|
return Ut(O(I.env.dataDir, "tmp-"));
|
|
711
711
|
}
|
|
712
|
-
function
|
|
713
|
-
return Array.isArray(e) ? e.flatMap((s, o) =>
|
|
712
|
+
function Ie(e, n, t = []) {
|
|
713
|
+
return Array.isArray(e) ? e.flatMap((s, o) => Ie(s, n, [...t, o])) : typeof e == "object" ? e === null ? [] : Object.entries(e).flatMap(([s, o]) => Ie(o, n, [...t, s])) : n(e) ? [t] : [];
|
|
714
714
|
}
|
|
715
|
-
function
|
|
715
|
+
function F(e) {
|
|
716
716
|
return e.filter((n) => n != null);
|
|
717
717
|
}
|
|
718
718
|
function zs(e) {
|
|
719
719
|
e.pages && Object.keys(e.pages).forEach((t) => {
|
|
720
|
-
const s =
|
|
721
|
-
s && s instanceof
|
|
720
|
+
const s = le(e.pages[t]);
|
|
721
|
+
s && s instanceof W.Map && be(s);
|
|
722
722
|
});
|
|
723
|
-
const n =
|
|
724
|
-
n && n instanceof
|
|
723
|
+
const n = le(e.pages);
|
|
724
|
+
n && n instanceof W.Map && n.observe((t) => {
|
|
725
725
|
t.changes.keys.forEach((s, o) => {
|
|
726
726
|
if (s.action === "add") {
|
|
727
|
-
const r =
|
|
728
|
-
r && r instanceof
|
|
727
|
+
const r = le(e.pages[o]);
|
|
728
|
+
r && r instanceof W.Map && be(r);
|
|
729
729
|
}
|
|
730
730
|
});
|
|
731
731
|
});
|
|
@@ -733,16 +733,16 @@ function zs(e) {
|
|
|
733
733
|
function Ws(e) {
|
|
734
734
|
e.routes && Object.keys(e.routes).forEach((t) => {
|
|
735
735
|
var o;
|
|
736
|
-
const s =
|
|
737
|
-
s && s instanceof
|
|
736
|
+
const s = le((o = e.routes) == null ? void 0 : o[t]);
|
|
737
|
+
s && s instanceof W.Map && be(s);
|
|
738
738
|
});
|
|
739
|
-
const n =
|
|
740
|
-
n && n instanceof
|
|
739
|
+
const n = le(e.routes);
|
|
740
|
+
n && n instanceof W.Map && n.observe((t) => {
|
|
741
741
|
t.changes.keys.forEach((s, o) => {
|
|
742
742
|
var r;
|
|
743
743
|
if (s.action === "add") {
|
|
744
|
-
const a =
|
|
745
|
-
a && a instanceof
|
|
744
|
+
const a = le((r = e.routes) == null ? void 0 : r[o]);
|
|
745
|
+
a && a instanceof W.Map && be(a);
|
|
746
746
|
}
|
|
747
747
|
});
|
|
748
748
|
});
|
|
@@ -805,10 +805,10 @@ function je({
|
|
|
805
805
|
if (n.dataSource) {
|
|
806
806
|
let w = n.id;
|
|
807
807
|
o && (w = o.paramOptionIds.join("-"));
|
|
808
|
-
const
|
|
809
|
-
if (!
|
|
808
|
+
const D = ((S = (p = (i = n.dataSource.pathDataMappings) == null ? void 0 : i[w]) == null ? void 0 : p.dataCache) == null ? void 0 : S[m.locale]) ?? ((l = (d = (f = n.dataSource.pathDataMappings) == null ? void 0 : f[w]) == null ? void 0 : d.dataCache) == null ? void 0 : l[t.config.defaultLocale || "en"]);
|
|
809
|
+
if (!D)
|
|
810
810
|
continue;
|
|
811
|
-
ts(r, t, m.locale,
|
|
811
|
+
ts(r, t, m.locale, D);
|
|
812
812
|
}
|
|
813
813
|
o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
814
814
|
}
|
|
@@ -846,9 +846,9 @@ function Qs({
|
|
|
846
846
|
}) {
|
|
847
847
|
let s = 0;
|
|
848
848
|
const o = Array.from(Ae.keys()), r = [];
|
|
849
|
-
r.push(`page-html:prod:/${e}
|
|
849
|
+
r.push(`page-html:prod:/${e}`), n && n !== e && r.push(`page-html:prod:/${n}`);
|
|
850
850
|
for (const a of t)
|
|
851
|
-
r.push(`page-html:prod:/${a}/${e}
|
|
851
|
+
r.push(`page-html:prod:/${a}/${e}`), n && n !== e && (n !== "/" ? r.push(`page-html:prod:/${a}/${n}`) : r.push(`page-html:prod:/${a}`));
|
|
852
852
|
for (const a of o)
|
|
853
853
|
for (const u of r)
|
|
854
854
|
if (a.startsWith(u)) {
|
|
@@ -879,15 +879,15 @@ function nn() {
|
|
|
879
879
|
resources: {}
|
|
880
880
|
};
|
|
881
881
|
}
|
|
882
|
-
const
|
|
882
|
+
const v = class v extends W.Doc {
|
|
883
883
|
constructor(t) {
|
|
884
884
|
super();
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
885
|
+
x(this, "syncedStore");
|
|
886
|
+
x(this, "conns", /* @__PURE__ */ new Map());
|
|
887
|
+
x(this, "awareness");
|
|
888
888
|
// 延迟释放定时器
|
|
889
|
-
|
|
890
|
-
|
|
889
|
+
x(this, "releaseTimer");
|
|
890
|
+
x(this, "awarenessChangeHandler", ({ added: t, updated: s, removed: o }, r) => {
|
|
891
891
|
const a = t.concat(s, o);
|
|
892
892
|
if (r !== null) {
|
|
893
893
|
const i = this.conns.get(r);
|
|
@@ -902,13 +902,13 @@ const T = class T extends K.Doc {
|
|
|
902
902
|
const c = j.toUint8Array(u);
|
|
903
903
|
this.conns.forEach((i, p) => this.send(p, c));
|
|
904
904
|
});
|
|
905
|
-
|
|
905
|
+
x(this, "updateHandler", (t) => {
|
|
906
906
|
const s = j.createEncoder();
|
|
907
907
|
j.writeVarUint(s, he), gs(s, t);
|
|
908
908
|
const o = j.toUint8Array(s);
|
|
909
909
|
this.conns.forEach((r, a) => this.send(a, o));
|
|
910
910
|
});
|
|
911
|
-
|
|
911
|
+
x(this, "ensureDataStructure", () => {
|
|
912
912
|
var c;
|
|
913
913
|
const { supportedLocales: t, pages: s, pageIds: o, config: r, routes: a, routeIds: u } = this.syncedStore;
|
|
914
914
|
{
|
|
@@ -937,7 +937,7 @@ const T = class T extends K.Doc {
|
|
|
937
937
|
}
|
|
938
938
|
}
|
|
939
939
|
});
|
|
940
|
-
|
|
940
|
+
x(this, "send", (t, s) => {
|
|
941
941
|
t.readyState !== tn && t.readyState !== sn && this.closeConn(t);
|
|
942
942
|
try {
|
|
943
943
|
t.send(s, (o) => {
|
|
@@ -947,24 +947,24 @@ const T = class T extends K.Doc {
|
|
|
947
947
|
this.closeConn(t);
|
|
948
948
|
}
|
|
949
949
|
});
|
|
950
|
-
|
|
950
|
+
x(this, "closeConn", (t) => {
|
|
951
951
|
if (t.removeAllListeners(), this.conns.has(t)) {
|
|
952
952
|
const s = this.conns.get(t);
|
|
953
953
|
this.conns.delete(t), s && ms(this.awareness, Array.from(s), null);
|
|
954
954
|
}
|
|
955
955
|
t.close(), this.checkAndScheduleRelease();
|
|
956
956
|
});
|
|
957
|
-
|
|
958
|
-
|
|
957
|
+
x(this, "autoSave", dt(() => {
|
|
958
|
+
Y(H(this.draftYjsFilePath), { recursive: !0 }), we(this.draftYjsFilePath, W.encodeStateAsUpdate(this));
|
|
959
959
|
}, Zs));
|
|
960
|
-
|
|
960
|
+
x(this, "save", ({ flush: t = !1 } = {}) => {
|
|
961
961
|
this.autoSave(), t && this.autoSave.flush();
|
|
962
962
|
});
|
|
963
|
-
|
|
963
|
+
x(this, "publish", async ({ mode: t, routes: s }) => {
|
|
964
964
|
const o = await this.getState("draft"), r = await this.getState("production");
|
|
965
965
|
await rt(o, r, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: t }), r.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Ys(this.syncedStore, s), await this.setState(t, r), await this.clearPageCacheForRoutes(s, r);
|
|
966
966
|
});
|
|
967
|
-
|
|
967
|
+
x(this, "mergeState", async (t, s) => {
|
|
968
968
|
var u, c, i;
|
|
969
969
|
const o = JSON.parse(JSON.stringify(s));
|
|
970
970
|
(u = t.config).fontFamily ?? (u.fontFamily = {});
|
|
@@ -980,8 +980,8 @@ const T = class T extends K.Doc {
|
|
|
980
980
|
});
|
|
981
981
|
});
|
|
982
982
|
});
|
|
983
|
-
|
|
984
|
-
const o =
|
|
983
|
+
x(this, "clearPageCacheForRoutes", async (t, s) => {
|
|
984
|
+
const o = J(this.options.path), r = await X.findByPk(o), a = (r == null ? void 0 : r.slug) || o;
|
|
985
985
|
if (y.info(`[SiteState] clearing page cache for project ${o}, routes:`, t || []), !t || t.length === 0) {
|
|
986
986
|
Qs({ projectId: o, projectSlug: a, supportedLocales: s.supportedLocales.map((p) => p.locale) });
|
|
987
987
|
return;
|
|
@@ -996,7 +996,7 @@ const T = class T extends K.Doc {
|
|
|
996
996
|
y.info(`[SiteState] cleared ${p} page cache entries for project ${o}, routes:`, t);
|
|
997
997
|
}
|
|
998
998
|
});
|
|
999
|
-
|
|
999
|
+
x(this, "addConnection", (t) => {
|
|
1000
1000
|
if (this.conns.has(t))
|
|
1001
1001
|
return;
|
|
1002
1002
|
this.cancelRelease(), t.binaryType = "arraybuffer", this.conns.set(t, /* @__PURE__ */ new Set()), t.on("message", (r) => this.messageListener(t, new Uint8Array(r)));
|
|
@@ -1028,7 +1028,7 @@ const T = class T extends K.Doc {
|
|
|
1028
1028
|
}
|
|
1029
1029
|
}
|
|
1030
1030
|
});
|
|
1031
|
-
|
|
1031
|
+
x(this, "messageListener", (t, s) => {
|
|
1032
1032
|
try {
|
|
1033
1033
|
const o = j.createEncoder(), r = Re.createDecoder(s), a = Re.readVarUint(r);
|
|
1034
1034
|
switch (a) {
|
|
@@ -1047,7 +1047,7 @@ const T = class T extends K.Doc {
|
|
|
1047
1047
|
}
|
|
1048
1048
|
this.save();
|
|
1049
1049
|
});
|
|
1050
|
-
this.options = t,
|
|
1050
|
+
this.options = t, K(this.draftYjsFilePath) && W.applyUpdate(this, ae(this.draftYjsFilePath)), this.syncedStore = os(
|
|
1051
1051
|
es(
|
|
1052
1052
|
{
|
|
1053
1053
|
pages: {},
|
|
@@ -1084,15 +1084,15 @@ const T = class T extends K.Doc {
|
|
|
1084
1084
|
});
|
|
1085
1085
|
}
|
|
1086
1086
|
static get allShared() {
|
|
1087
|
-
return this.projectIds.map((t) =>
|
|
1087
|
+
return this.projectIds.map((t) => v.shared(t));
|
|
1088
1088
|
}
|
|
1089
1089
|
static shared(t) {
|
|
1090
1090
|
if (!t)
|
|
1091
1091
|
throw new Error("Should provide project context");
|
|
1092
|
-
let s =
|
|
1093
|
-
return s || (s = new
|
|
1092
|
+
let s = v.sharedInstances[t];
|
|
1093
|
+
return s || (s = new v({
|
|
1094
1094
|
path: O(de, t)
|
|
1095
|
-
}),
|
|
1095
|
+
}), v.sharedInstances[t] = s, Ot({
|
|
1096
1096
|
projectId: t,
|
|
1097
1097
|
pages: ve,
|
|
1098
1098
|
components: ke
|
|
@@ -1101,7 +1101,7 @@ const T = class T extends K.Doc {
|
|
|
1101
1101
|
// 轻量级 production 状态获取,不加载 draft 数据
|
|
1102
1102
|
static async getProductionState(t) {
|
|
1103
1103
|
var o, r;
|
|
1104
|
-
let s =
|
|
1104
|
+
let s = v.productionStates.get(t);
|
|
1105
1105
|
if (!s) {
|
|
1106
1106
|
const a = O(de, t, "production");
|
|
1107
1107
|
if (s = await Et(a, { includeResources: !0 }) ?? nn(), !((o = s == null ? void 0 : s.config) != null && o.defaultLocale)) {
|
|
@@ -1109,7 +1109,7 @@ const T = class T extends K.Doc {
|
|
|
1109
1109
|
const u = Ue.env.languages.map((c) => ({ locale: c.code, name: c.name }));
|
|
1110
1110
|
s.config.defaultLocale = (r = u[0]) == null ? void 0 : r.locale;
|
|
1111
1111
|
}
|
|
1112
|
-
|
|
1112
|
+
v.productionStates.set(t, s);
|
|
1113
1113
|
}
|
|
1114
1114
|
return {
|
|
1115
1115
|
...s,
|
|
@@ -1117,7 +1117,7 @@ const T = class T extends K.Doc {
|
|
|
1117
1117
|
var S, f;
|
|
1118
1118
|
const { pages: u, components: c } = as(a, "pages", "components");
|
|
1119
1119
|
let i = c;
|
|
1120
|
-
const p = await
|
|
1120
|
+
const p = await X.findByPk(t);
|
|
1121
1121
|
if (p != null && p.useAllResources)
|
|
1122
1122
|
i = c;
|
|
1123
1123
|
else {
|
|
@@ -1135,8 +1135,8 @@ const T = class T extends K.Doc {
|
|
|
1135
1135
|
}
|
|
1136
1136
|
destroy() {
|
|
1137
1137
|
this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, o) => this.closeConn(o)), this.awareness.destroy();
|
|
1138
|
-
const t =
|
|
1139
|
-
delete
|
|
1138
|
+
const t = J(this.options.path);
|
|
1139
|
+
delete v.sharedInstances[t], super.destroy();
|
|
1140
1140
|
}
|
|
1141
1141
|
initObserver() {
|
|
1142
1142
|
zs(this.syncedStore), Ws(this.syncedStore);
|
|
@@ -1146,22 +1146,22 @@ const T = class T extends K.Doc {
|
|
|
1146
1146
|
}
|
|
1147
1147
|
static async getStateByProjectId(t, s) {
|
|
1148
1148
|
if (s === "draft") {
|
|
1149
|
-
const o =
|
|
1149
|
+
const o = v.shared(t);
|
|
1150
1150
|
return JSON.parse(JSON.stringify(o.syncedStore));
|
|
1151
1151
|
}
|
|
1152
|
-
return
|
|
1152
|
+
return v.getProductionState(t);
|
|
1153
1153
|
}
|
|
1154
1154
|
async getState(t) {
|
|
1155
1155
|
if (t === "draft")
|
|
1156
1156
|
return JSON.parse(JSON.stringify(this.syncedStore));
|
|
1157
|
-
const s =
|
|
1158
|
-
return
|
|
1157
|
+
const s = J(this.options.path);
|
|
1158
|
+
return v.getProductionState(s);
|
|
1159
1159
|
}
|
|
1160
1160
|
async setState(t, s) {
|
|
1161
1161
|
const o = await cn(s, { exportAssets: !1, includeResources: !0 }), r = this.getPublishDir(t);
|
|
1162
|
-
if (
|
|
1163
|
-
const a =
|
|
1164
|
-
|
|
1162
|
+
if (Y(H(r), { recursive: !0 }), lt(r, { force: !0, recursive: !0 }), Ye(o, r), t === "production") {
|
|
1163
|
+
const a = J(this.options.path);
|
|
1164
|
+
v.productionStates.set(a, s);
|
|
1165
1165
|
}
|
|
1166
1166
|
}
|
|
1167
1167
|
getPublishDir(t) {
|
|
@@ -1174,16 +1174,16 @@ const T = class T extends K.Doc {
|
|
|
1174
1174
|
// 调度延迟释放
|
|
1175
1175
|
scheduleRelease() {
|
|
1176
1176
|
this.cancelRelease();
|
|
1177
|
-
const t =
|
|
1177
|
+
const t = J(this.options.path);
|
|
1178
1178
|
this.releaseTimer = setTimeout(() => {
|
|
1179
1179
|
y.info(`[SiteState] releasing instance due to no active connections: ${t}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
|
|
1180
|
-
},
|
|
1180
|
+
}, v.RELEASE_DELAY), y.info(`[SiteState] scheduled release for project ${t} in ${v.RELEASE_DELAY / 1e3}s`);
|
|
1181
1181
|
}
|
|
1182
1182
|
// 取消延迟释放
|
|
1183
1183
|
cancelRelease() {
|
|
1184
1184
|
if (this.releaseTimer) {
|
|
1185
1185
|
clearTimeout(this.releaseTimer), this.releaseTimer = void 0;
|
|
1186
|
-
const t =
|
|
1186
|
+
const t = J(this.options.path);
|
|
1187
1187
|
y.info(`[SiteState] cancelled scheduled release for project ${t}`);
|
|
1188
1188
|
}
|
|
1189
1189
|
}
|
|
@@ -1193,24 +1193,24 @@ const T = class T extends K.Doc {
|
|
|
1193
1193
|
s && (o = [s]);
|
|
1194
1194
|
const r = {};
|
|
1195
1195
|
for (const c of o) {
|
|
1196
|
-
const i = await
|
|
1196
|
+
const i = await X.findByPk(c);
|
|
1197
1197
|
if (!i) continue;
|
|
1198
|
-
const p = await
|
|
1198
|
+
const p = await v.getStateByProjectId(c, t), S = i.slug || c, f = is(
|
|
1199
1199
|
I.env.languages.map((l) => l.code),
|
|
1200
1200
|
p.supportedLocales.map((l) => l.locale)
|
|
1201
1201
|
), d = (l, m) => {
|
|
1202
|
-
S && (r[
|
|
1202
|
+
S && (r[Q("/", S, l)] = {
|
|
1203
1203
|
...m,
|
|
1204
1204
|
shouldRedirect: !0,
|
|
1205
1205
|
mainPage: !0
|
|
1206
|
-
}), r[
|
|
1206
|
+
}), r[Q("/", c, l)] = {
|
|
1207
1207
|
...m,
|
|
1208
1208
|
shouldRedirect: !0,
|
|
1209
1209
|
mainPage: !0
|
|
1210
1210
|
};
|
|
1211
1211
|
for (const w of f) {
|
|
1212
|
-
const
|
|
1213
|
-
r[
|
|
1212
|
+
const D = { ...m, locale: w };
|
|
1213
|
+
r[Q("/", w, c, l)] = D, S && (r[Q("/", w, S, l)] = D);
|
|
1214
1214
|
}
|
|
1215
1215
|
};
|
|
1216
1216
|
if (t === "draft")
|
|
@@ -1218,7 +1218,7 @@ const T = class T extends K.Doc {
|
|
|
1218
1218
|
const m = (a = p == null ? void 0 : p.routes) == null ? void 0 : a[l];
|
|
1219
1219
|
if (!m) continue;
|
|
1220
1220
|
if (m.params && m.params.length > 0) {
|
|
1221
|
-
const
|
|
1221
|
+
const P = Fe({
|
|
1222
1222
|
basePath: m.path,
|
|
1223
1223
|
params: m.params,
|
|
1224
1224
|
routeId: m.id,
|
|
@@ -1228,23 +1228,23 @@ const T = class T extends K.Doc {
|
|
|
1228
1228
|
currentOptionIds: [],
|
|
1229
1229
|
result: []
|
|
1230
1230
|
});
|
|
1231
|
-
for (const
|
|
1232
|
-
const
|
|
1231
|
+
for (const N of P) {
|
|
1232
|
+
const ee = N.path, oe = {
|
|
1233
1233
|
projectId: c,
|
|
1234
1234
|
projectSlug: S,
|
|
1235
|
-
pageSlug:
|
|
1235
|
+
pageSlug: ee,
|
|
1236
1236
|
pageId: m.displayTemplateId || "",
|
|
1237
1237
|
routeId: l,
|
|
1238
1238
|
// default locale
|
|
1239
1239
|
defaultLocale: f == null ? void 0 : f[0],
|
|
1240
1240
|
locales: f,
|
|
1241
1241
|
publishedAt: p.config.publishedAt,
|
|
1242
|
-
isPublic: m.isPublic && ((u =
|
|
1242
|
+
isPublic: m.isPublic && ((u = N == null ? void 0 : N.routeMetaData) == null ? void 0 : u.isPublic)
|
|
1243
1243
|
};
|
|
1244
|
-
d(
|
|
1244
|
+
d(ee, oe);
|
|
1245
1245
|
}
|
|
1246
1246
|
}
|
|
1247
|
-
const w = m.path,
|
|
1247
|
+
const w = m.path, D = {
|
|
1248
1248
|
projectId: c,
|
|
1249
1249
|
projectSlug: S,
|
|
1250
1250
|
pageSlug: w,
|
|
@@ -1256,15 +1256,15 @@ const T = class T extends K.Doc {
|
|
|
1256
1256
|
publishedAt: p.config.publishedAt,
|
|
1257
1257
|
isPublic: m.isPublic
|
|
1258
1258
|
};
|
|
1259
|
-
d(w,
|
|
1259
|
+
d(w, D);
|
|
1260
1260
|
}
|
|
1261
1261
|
for (const l of p.pageIds) {
|
|
1262
1262
|
const m = p.pages[l];
|
|
1263
1263
|
if (!m || t === "production" && !m.isPublic)
|
|
1264
1264
|
continue;
|
|
1265
|
-
const w = m.slug,
|
|
1265
|
+
const w = m.slug, D = i.slug || c, P = {
|
|
1266
1266
|
projectId: c,
|
|
1267
|
-
projectSlug:
|
|
1267
|
+
projectSlug: D,
|
|
1268
1268
|
pageSlug: w,
|
|
1269
1269
|
pageId: l,
|
|
1270
1270
|
// default locale
|
|
@@ -1274,17 +1274,17 @@ const T = class T extends K.Doc {
|
|
|
1274
1274
|
isPublic: m.isPublic,
|
|
1275
1275
|
templateConfig: m.templateConfig
|
|
1276
1276
|
};
|
|
1277
|
-
d(w,
|
|
1277
|
+
d(w, P);
|
|
1278
1278
|
}
|
|
1279
1279
|
}
|
|
1280
1280
|
return r;
|
|
1281
1281
|
}
|
|
1282
1282
|
getDocumentSize() {
|
|
1283
|
-
return
|
|
1283
|
+
return W.encodeStateAsUpdate(this).byteLength;
|
|
1284
1284
|
}
|
|
1285
1285
|
static getInstancesSizeInfo() {
|
|
1286
1286
|
const t = [];
|
|
1287
|
-
for (const [s, o] of Object.entries(
|
|
1287
|
+
for (const [s, o] of Object.entries(v.sharedInstances)) {
|
|
1288
1288
|
const r = o.getDocumentSize();
|
|
1289
1289
|
t.push({
|
|
1290
1290
|
projectId: s,
|
|
@@ -1309,8 +1309,8 @@ const T = class T extends K.Doc {
|
|
|
1309
1309
|
}
|
|
1310
1310
|
// 执行定期检查
|
|
1311
1311
|
static performPeriodicCheck() {
|
|
1312
|
-
const t = Object.keys(
|
|
1313
|
-
for (const [r, a] of Object.entries(
|
|
1312
|
+
const t = Object.keys(v.sharedInstances).length, s = [], o = [];
|
|
1313
|
+
for (const [r, a] of Object.entries(v.sharedInstances))
|
|
1314
1314
|
a.conns.size === 0 ? s.push({ projectId: r, instance: a }) : o.push({ projectId: r, connections: a.conns.size });
|
|
1315
1315
|
if (y.info(
|
|
1316
1316
|
`[SiteState] periodic check summary: total instances: ${t}, with connections: ${o.length}, without connections: ${s.length}`
|
|
@@ -1332,18 +1332,18 @@ const T = class T extends K.Doc {
|
|
|
1332
1332
|
} else t > 0 ? y.debug("[SiteState] periodic check: all instances have active connections") : y.debug("[SiteState] periodic check: no instances exist");
|
|
1333
1333
|
}
|
|
1334
1334
|
};
|
|
1335
|
-
|
|
1335
|
+
x(v, "PRODUCTION_CACHE_TTL", 7 * 24 * 60 * 60 * 1e3), // 7 days
|
|
1336
1336
|
// 延迟释放时间:5分钟
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1337
|
+
x(v, "RELEASE_DELAY", 5 * 60 * 1e3), // 定期检查间隔:2 小时
|
|
1338
|
+
x(v, "PERIODIC_CHECK_INTERVAL", 2 * 60 * 60 * 1e3), // 2 hours
|
|
1339
|
+
x(v, "sharedInstances", {}), x(v, "productionStates", new Pe({
|
|
1340
1340
|
max: 100,
|
|
1341
|
-
ttl:
|
|
1341
|
+
ttl: v.PRODUCTION_CACHE_TTL
|
|
1342
1342
|
})), // 定期检查定时器
|
|
1343
|
-
|
|
1344
|
-
let
|
|
1343
|
+
x(v, "periodicCheckTimer");
|
|
1344
|
+
let Z = v;
|
|
1345
1345
|
async function on(e, n, t) {
|
|
1346
|
-
if (!e || !
|
|
1346
|
+
if (!e || !K(e) || !re(e).isFile())
|
|
1347
1347
|
return null;
|
|
1348
1348
|
let s = t[e];
|
|
1349
1349
|
return s || (s = (async () => {
|
|
@@ -1360,9 +1360,9 @@ async function on(e, n, t) {
|
|
|
1360
1360
|
})(), t[e] = s), s;
|
|
1361
1361
|
}
|
|
1362
1362
|
const rn = async (e, n) => {
|
|
1363
|
-
const t =
|
|
1363
|
+
const t = J(e), s = await Yt({
|
|
1364
1364
|
name: yt,
|
|
1365
|
-
path:
|
|
1365
|
+
path: Q("/uploads", t),
|
|
1366
1366
|
responseType: "stream",
|
|
1367
1367
|
method: "GET"
|
|
1368
1368
|
});
|
|
@@ -1375,7 +1375,7 @@ const rn = async (e, n) => {
|
|
|
1375
1375
|
await Promise.all(
|
|
1376
1376
|
e.map(async (t) => {
|
|
1377
1377
|
try {
|
|
1378
|
-
await rn(t, O(n,
|
|
1378
|
+
await rn(t, O(n, J(t)));
|
|
1379
1379
|
} catch (s) {
|
|
1380
1380
|
y.error(`Failed to export assets: ${t}, ${s}`);
|
|
1381
1381
|
}
|
|
@@ -1387,15 +1387,15 @@ function wt(e) {
|
|
|
1387
1387
|
}
|
|
1388
1388
|
async function ge(e, n, t) {
|
|
1389
1389
|
const { getFilename: s, exportAssets: o } = t, r = O(n, s(e));
|
|
1390
|
-
if (
|
|
1391
|
-
const u =
|
|
1390
|
+
if (Y(H(r), { recursive: !0 }), we(r, ie.stringify(e)), o) {
|
|
1391
|
+
const u = Ie(
|
|
1392
1392
|
e,
|
|
1393
1393
|
(c) => typeof c == "string" && (He.test(c) || fe.test(c))
|
|
1394
1394
|
).map((c) => {
|
|
1395
1395
|
const i = Be(e, c);
|
|
1396
1396
|
return wt(i);
|
|
1397
1397
|
}).flat().filter(Boolean);
|
|
1398
|
-
await an(u,
|
|
1398
|
+
await an(u, H(r));
|
|
1399
1399
|
}
|
|
1400
1400
|
}
|
|
1401
1401
|
const nt = new Pe({
|
|
@@ -1404,7 +1404,7 @@ const nt = new Pe({
|
|
|
1404
1404
|
});
|
|
1405
1405
|
async function ot(e, n, t) {
|
|
1406
1406
|
var u;
|
|
1407
|
-
const s =
|
|
1407
|
+
const s = Ie(
|
|
1408
1408
|
e,
|
|
1409
1409
|
(c) => typeof c == "string" && (He.test(c) || fe.test(c))
|
|
1410
1410
|
), o = ls(2), r = s.map(
|
|
@@ -1412,7 +1412,7 @@ async function ot(e, n, t) {
|
|
|
1412
1412
|
try {
|
|
1413
1413
|
const i = Be(e, c), p = wt(i);
|
|
1414
1414
|
for (const S of p) {
|
|
1415
|
-
const f =
|
|
1415
|
+
const f = J(S), d = t.getFilePath(S, c), l = d ? `${d}:${f}` : f, m = nt.get(l);
|
|
1416
1416
|
if (m) {
|
|
1417
1417
|
fe.test(i) || qe(e, c, m);
|
|
1418
1418
|
return;
|
|
@@ -1435,130 +1435,138 @@ async function cn(e, {
|
|
|
1435
1435
|
includeResources: r = !1,
|
|
1436
1436
|
routeIds: a = "all"
|
|
1437
1437
|
} = {}) {
|
|
1438
|
-
var
|
|
1438
|
+
var pe, E, g, A, k, te, b, $, B, G, _, q;
|
|
1439
1439
|
const u = t === "all" ? e.pageIds : t, c = xt({
|
|
1440
1440
|
state: e,
|
|
1441
1441
|
pageIds: u,
|
|
1442
1442
|
componentIds: s === "all" ? Object.keys(e.components) : s
|
|
1443
|
-
}), i = a === "all" ? e.routeIds : a, p = (
|
|
1444
|
-
|
|
1445
|
-
name: g.name,
|
|
1446
|
-
isTemplateSection: g.isTemplateSection ?? !1,
|
|
1447
|
-
templateDescription: g.templateDescription,
|
|
1448
|
-
llmConfig: g.llmConfig,
|
|
1449
|
-
component: g.component,
|
|
1450
|
-
config: g.config,
|
|
1451
|
-
visibility: g.visibility,
|
|
1452
|
-
sections: g.sections,
|
|
1453
|
-
sectionIds: g.sectionIds
|
|
1454
|
-
// 已经废弃,数据在 page.dataSource 中管理
|
|
1455
|
-
// properties: section.locales?.[locale] ?? {},
|
|
1456
|
-
}), S = (g, P) => {
|
|
1457
|
-
var x;
|
|
1443
|
+
}), i = a === "all" ? e.routeIds : a, p = (h) => {
|
|
1444
|
+
var C;
|
|
1458
1445
|
return {
|
|
1459
|
-
id:
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1446
|
+
id: h.id,
|
|
1447
|
+
name: h.name,
|
|
1448
|
+
isTemplateSection: h.isTemplateSection ?? !1,
|
|
1449
|
+
templateDescription: h.templateDescription,
|
|
1450
|
+
llmConfig: h.llmConfig,
|
|
1451
|
+
component: h.component,
|
|
1452
|
+
config: h.config,
|
|
1453
|
+
visibility: h.visibility,
|
|
1454
|
+
sections: h != null && h.sectionIds ? F(
|
|
1455
|
+
(C = h == null ? void 0 : h.sectionIds) == null ? void 0 : C.map((T) => {
|
|
1456
|
+
var L;
|
|
1457
|
+
const M = (L = h.sections) == null ? void 0 : L[T];
|
|
1458
|
+
return M && p(M);
|
|
1459
|
+
})
|
|
1460
|
+
) : void 0
|
|
1461
|
+
// 已经废弃,数据在 page.dataSource 中管理
|
|
1462
|
+
// properties: section.locales?.[locale] ?? {},
|
|
1463
|
+
};
|
|
1464
|
+
}, S = (h, C) => {
|
|
1465
|
+
var T;
|
|
1466
|
+
return {
|
|
1467
|
+
id: h.id,
|
|
1468
|
+
createdAt: h.createdAt,
|
|
1469
|
+
updatedAt: h.updatedAt,
|
|
1470
|
+
publishedAt: h.publishedAt,
|
|
1471
|
+
isPublic: h.isPublic ?? !0,
|
|
1472
|
+
templateConfig: h.templateConfig,
|
|
1473
|
+
meta: ((T = h.locales) == null ? void 0 : T[C]) ?? {},
|
|
1474
|
+
sections: F(
|
|
1475
|
+
h.sectionIds.map((M) => {
|
|
1476
|
+
const L = h.sections[M];
|
|
1477
|
+
return L && p(L);
|
|
1470
1478
|
})
|
|
1471
1479
|
),
|
|
1472
1480
|
// 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
|
|
1473
1481
|
dataSource: Object.fromEntries(
|
|
1474
|
-
Object.entries(
|
|
1482
|
+
Object.entries(h.dataSource || {}).map(([M, L]) => [M, (L == null ? void 0 : L[C]) ?? {}])
|
|
1475
1483
|
)
|
|
1476
1484
|
};
|
|
1477
|
-
}, f = (
|
|
1478
|
-
id:
|
|
1479
|
-
createdAt:
|
|
1480
|
-
updatedAt:
|
|
1481
|
-
publishedAt:
|
|
1482
|
-
path:
|
|
1483
|
-
handler:
|
|
1484
|
-
isPublic:
|
|
1485
|
-
params:
|
|
1486
|
-
enabledGenerate:
|
|
1487
|
-
displayTemplateId:
|
|
1488
|
-
dataSource:
|
|
1489
|
-
}), d =
|
|
1490
|
-
i.map((
|
|
1491
|
-
const
|
|
1492
|
-
return
|
|
1485
|
+
}, f = (h) => ({
|
|
1486
|
+
id: h.id,
|
|
1487
|
+
createdAt: h.createdAt,
|
|
1488
|
+
updatedAt: h.updatedAt,
|
|
1489
|
+
publishedAt: h.publishedAt,
|
|
1490
|
+
path: h.path,
|
|
1491
|
+
handler: h.handler,
|
|
1492
|
+
isPublic: h.isPublic ?? !0,
|
|
1493
|
+
params: h.params ?? [],
|
|
1494
|
+
enabledGenerate: h.enabledGenerate ?? !1,
|
|
1495
|
+
displayTemplateId: h.displayTemplateId,
|
|
1496
|
+
dataSource: h.dataSource
|
|
1497
|
+
}), d = F(
|
|
1498
|
+
i.map((h) => {
|
|
1499
|
+
const C = e.routes[h];
|
|
1500
|
+
return C && f(C);
|
|
1493
1501
|
})
|
|
1494
|
-
), l =
|
|
1495
|
-
e.supportedLocales.map((
|
|
1496
|
-
(
|
|
1497
|
-
const
|
|
1498
|
-
return
|
|
1499
|
-
locale:
|
|
1500
|
-
slug:
|
|
1501
|
-
page: S(
|
|
1502
|
+
), l = F(
|
|
1503
|
+
e.supportedLocales.map((h) => h.locale).flatMap(
|
|
1504
|
+
(h) => u.map((C) => {
|
|
1505
|
+
const T = e.pages[C];
|
|
1506
|
+
return T && {
|
|
1507
|
+
locale: h,
|
|
1508
|
+
slug: T.slug,
|
|
1509
|
+
page: S(T, h)
|
|
1502
1510
|
};
|
|
1503
1511
|
})
|
|
1504
1512
|
)
|
|
1505
1513
|
), m = St(), w = O(m, "pages");
|
|
1506
|
-
|
|
1507
|
-
const
|
|
1508
|
-
|
|
1509
|
-
const
|
|
1510
|
-
|
|
1511
|
-
for (const { locale:
|
|
1512
|
-
await ge(
|
|
1513
|
-
getFilename: () => `${Oe(
|
|
1514
|
+
Y(w, { recursive: !0 });
|
|
1515
|
+
const D = O(m, "components");
|
|
1516
|
+
Y(D, { recursive: !0 });
|
|
1517
|
+
const P = O(m, "routes");
|
|
1518
|
+
Y(P, { recursive: !0 });
|
|
1519
|
+
for (const { locale: h, slug: C, page: T } of l)
|
|
1520
|
+
await ge(T, w, {
|
|
1521
|
+
getFilename: () => `${Oe(C) || "index"}.${h}.yml`,
|
|
1514
1522
|
exportAssets: n
|
|
1515
1523
|
});
|
|
1516
|
-
for (const
|
|
1517
|
-
await ge(
|
|
1524
|
+
for (const h of d)
|
|
1525
|
+
await ge(h, P, {
|
|
1518
1526
|
// getFilename: () => `${sanitizeSlug(route.path)}.yml`,
|
|
1519
|
-
getFilename: () => `${Oe(
|
|
1527
|
+
getFilename: () => `${Oe(h.path) || "index"}.yml`,
|
|
1520
1528
|
exportAssets: n
|
|
1521
1529
|
});
|
|
1522
|
-
for (const
|
|
1523
|
-
const
|
|
1524
|
-
|
|
1525
|
-
getFilename: (
|
|
1530
|
+
for (const h of c) {
|
|
1531
|
+
const C = (pe = e.components[h]) == null ? void 0 : pe.data;
|
|
1532
|
+
C && await ge(C, D, {
|
|
1533
|
+
getFilename: (T) => `${T.name || "unnamed"}.${T.id}.yml`,
|
|
1526
1534
|
exportAssets: n
|
|
1527
1535
|
});
|
|
1528
1536
|
}
|
|
1529
|
-
const
|
|
1530
|
-
|
|
1531
|
-
const
|
|
1532
|
-
pages:
|
|
1533
|
-
u.map((
|
|
1534
|
-
const
|
|
1535
|
-
return
|
|
1537
|
+
const N = O(m, ".blocklet/pages/pages.config.yml");
|
|
1538
|
+
Y(H(N), { recursive: !0 });
|
|
1539
|
+
const ee = {
|
|
1540
|
+
pages: F(
|
|
1541
|
+
u.map((h) => {
|
|
1542
|
+
const C = e.pages[h];
|
|
1543
|
+
return C && { id: h, slug: C.slug };
|
|
1536
1544
|
})
|
|
1537
1545
|
),
|
|
1538
|
-
routes:
|
|
1539
|
-
i.map((
|
|
1540
|
-
const
|
|
1541
|
-
return
|
|
1546
|
+
routes: F(
|
|
1547
|
+
i.map((h) => {
|
|
1548
|
+
const C = e.routes[h];
|
|
1549
|
+
return C && { id: h, path: C.path };
|
|
1542
1550
|
})
|
|
1543
1551
|
),
|
|
1544
|
-
components:
|
|
1545
|
-
c.map((
|
|
1546
|
-
var
|
|
1547
|
-
const
|
|
1548
|
-
return
|
|
1549
|
-
id:
|
|
1550
|
-
name:
|
|
1552
|
+
components: F(
|
|
1553
|
+
c.map((h) => {
|
|
1554
|
+
var T;
|
|
1555
|
+
const C = (T = e.components[h]) == null ? void 0 : T.data;
|
|
1556
|
+
return C && {
|
|
1557
|
+
id: h,
|
|
1558
|
+
name: C.name
|
|
1551
1559
|
};
|
|
1552
1560
|
})
|
|
1553
1561
|
),
|
|
1554
1562
|
...r ? {
|
|
1555
1563
|
resources: {
|
|
1556
|
-
components:
|
|
1557
|
-
Object.keys(((E = e.resources) == null ? void 0 : E.components) || {}).filter((
|
|
1558
|
-
var
|
|
1564
|
+
components: F(
|
|
1565
|
+
Object.keys(((E = e.resources) == null ? void 0 : E.components) || {}).filter((h) => c.includes(h)).map((h) => {
|
|
1566
|
+
var C, T, M, L;
|
|
1559
1567
|
return {
|
|
1560
|
-
id:
|
|
1561
|
-
name: (
|
|
1568
|
+
id: h,
|
|
1569
|
+
name: (L = (M = (T = (C = e.resources) == null ? void 0 : C.components) == null ? void 0 : T[h]) == null ? void 0 : M.component) == null ? void 0 : L.name
|
|
1562
1570
|
};
|
|
1563
1571
|
})
|
|
1564
1572
|
)
|
|
@@ -1567,34 +1575,34 @@ async function cn(e, {
|
|
|
1567
1575
|
supportedLocales: e.supportedLocales,
|
|
1568
1576
|
config: e.config
|
|
1569
1577
|
};
|
|
1570
|
-
we(
|
|
1571
|
-
const
|
|
1572
|
-
if (o && we(
|
|
1573
|
-
const
|
|
1574
|
-
|
|
1575
|
-
for (const
|
|
1576
|
-
(
|
|
1578
|
+
we(N, ie.stringify(ee));
|
|
1579
|
+
const oe = O(m, "config.source.json");
|
|
1580
|
+
if (o && we(oe, JSON.stringify(o)), r) {
|
|
1581
|
+
const h = O(m, "resources"), C = O(h, "components");
|
|
1582
|
+
Y(C, { recursive: !0 });
|
|
1583
|
+
for (const L of Object.keys(((g = e == null ? void 0 : e.resources) == null ? void 0 : g.components) ?? {}).filter(
|
|
1584
|
+
(V) => c.includes(V)
|
|
1577
1585
|
)) {
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1580
|
-
getFilename: (
|
|
1586
|
+
const V = (te = (k = (A = e.resources) == null ? void 0 : A.components) == null ? void 0 : k[L]) == null ? void 0 : te.component;
|
|
1587
|
+
V && await ge(V, C, {
|
|
1588
|
+
getFilename: (se) => `${se.name || "unnamed"}.${se.id}.yml`,
|
|
1581
1589
|
exportAssets: n
|
|
1582
1590
|
});
|
|
1583
1591
|
}
|
|
1584
|
-
const
|
|
1585
|
-
|
|
1586
|
-
const { chunks:
|
|
1587
|
-
for (const
|
|
1588
|
-
(
|
|
1592
|
+
const T = O(m, "chunks");
|
|
1593
|
+
Y(T, { recursive: !0 });
|
|
1594
|
+
const { chunks: M } = await Ve();
|
|
1595
|
+
for (const L of Object.keys(((b = e == null ? void 0 : e.resources) == null ? void 0 : b.components) ?? {}).filter(
|
|
1596
|
+
(V) => c.includes(V)
|
|
1589
1597
|
)) {
|
|
1590
|
-
const
|
|
1591
|
-
if (
|
|
1592
|
-
const
|
|
1593
|
-
if ((
|
|
1594
|
-
for (const De of
|
|
1595
|
-
const Ke = O(
|
|
1598
|
+
const V = (G = (B = ($ = e.resources) == null ? void 0 : $.components) == null ? void 0 : B[L]) == null ? void 0 : G.component;
|
|
1599
|
+
if (V && ((_ = V.renderer) == null ? void 0 : _.type) === "react-component") {
|
|
1600
|
+
const se = ((q = V.renderer) == null ? void 0 : q.chunks) ?? [];
|
|
1601
|
+
if ((se == null ? void 0 : se.length) > 0)
|
|
1602
|
+
for (const De of se) {
|
|
1603
|
+
const Ke = O(T, De), xe = M == null ? void 0 : M[De];
|
|
1596
1604
|
try {
|
|
1597
|
-
xe &&
|
|
1605
|
+
xe && K(xe) && !K(Ke) && Bt(xe, Ke);
|
|
1598
1606
|
} catch (Ct) {
|
|
1599
1607
|
y.error(`copy chunk ${De} error`, Ct.message);
|
|
1600
1608
|
}
|
|
@@ -1606,32 +1614,32 @@ async function cn(e, {
|
|
|
1606
1614
|
}
|
|
1607
1615
|
async function Et(e, { importAssets: n, includeResources: t } = {}) {
|
|
1608
1616
|
var r, a, u, c;
|
|
1609
|
-
if (!
|
|
1617
|
+
if (!K(e))
|
|
1610
1618
|
return null;
|
|
1611
1619
|
let s, o = !1;
|
|
1612
1620
|
try {
|
|
1613
|
-
|
|
1614
|
-
const i = Ne("**/.blocklet/pages/pages.config.yml", { cwd: s, absolute: !0 }).at(0), p = i && O(
|
|
1621
|
+
re(e).isDirectory() ? s = e : /\.(tgz|gz|tar)$/.test(e) && (o = !0, s = St(), await ds({ file: e, C: s }));
|
|
1622
|
+
const i = Ne("**/.blocklet/pages/pages.config.yml", { cwd: s, absolute: !0 }).at(0), p = i && O(H(i), "../../pages"), S = i && O(H(i), "../../components"), f = i && O(H(i), "../../chunks"), d = i && O(H(i), "../../routes");
|
|
1615
1623
|
if (!i)
|
|
1616
1624
|
return null;
|
|
1617
|
-
const l =
|
|
1618
|
-
let
|
|
1619
|
-
return (!
|
|
1620
|
-
}, w = (E,
|
|
1625
|
+
const l = ie.parse(ae(i).toString()), m = (E, g, A) => {
|
|
1626
|
+
let k = O(E, `${g}${A ? `.${A}` : ""}.yml`);
|
|
1627
|
+
return (!K(k) || !re(k).isFile()) && (k = O(E, g, `index${A ? `.${A}` : ""}.yml`), !K(k) || !re(k)) ? null : ie.parse(ae(k).toString());
|
|
1628
|
+
}, w = (E, g) => {
|
|
1621
1629
|
try {
|
|
1622
|
-
const A = Ne(`*.${
|
|
1623
|
-
return A ?
|
|
1630
|
+
const A = Ne(`*.${g}.yml`, { cwd: E, absolute: !0 })[0];
|
|
1631
|
+
return A ? ie.parse(ae(A).toString()) : null;
|
|
1624
1632
|
} catch (A) {
|
|
1625
1633
|
y.error("parse component error", A);
|
|
1626
1634
|
}
|
|
1627
1635
|
return null;
|
|
1628
|
-
},
|
|
1629
|
-
let A = O(E, `${
|
|
1630
|
-
return (!
|
|
1631
|
-
},
|
|
1636
|
+
}, D = (E, g) => {
|
|
1637
|
+
let A = O(E, `${g}.yml`);
|
|
1638
|
+
return (!K(A) || !re(A).isFile()) && (A = O(E, g, "index.yml"), !K(A) || !re(A)) ? null : ie.parse(ae(A).toString());
|
|
1639
|
+
}, P = F(
|
|
1632
1640
|
l.pages.map(({ slug: E }) => {
|
|
1633
|
-
var
|
|
1634
|
-
const
|
|
1641
|
+
var te;
|
|
1642
|
+
const g = F(
|
|
1635
1643
|
l.supportedLocales.map(({ locale: b }) => {
|
|
1636
1644
|
const $ = p ? m(p, Oe(E), b) : void 0;
|
|
1637
1645
|
if ($)
|
|
@@ -1639,30 +1647,33 @@ async function Et(e, { importAssets: n, includeResources: t } = {}) {
|
|
|
1639
1647
|
const B = p ? m(p, E, b) : void 0;
|
|
1640
1648
|
return B && { locale: b, page: B };
|
|
1641
1649
|
})
|
|
1642
|
-
), A = (
|
|
1650
|
+
), A = (te = g[0]) == null ? void 0 : te.page;
|
|
1643
1651
|
if (!A)
|
|
1644
1652
|
return null;
|
|
1645
|
-
const
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1653
|
+
const k = A.sections.map((b) => {
|
|
1654
|
+
var _, q, h, C;
|
|
1655
|
+
const $ = b.id || $e(), B = b.sections && Object.keys(b.sections).length > 0, G = {};
|
|
1656
|
+
return B && (G.sections = Object.fromEntries(((q = (_ = b.sections) == null ? void 0 : _.map) == null ? void 0 : q.call(_, (T) => [T.id, T])) ?? []) || {}, G.sectionIds = ((C = (h = b.sections) == null ? void 0 : h.map) == null ? void 0 : C.call(h, (T) => T.id)) ?? []), {
|
|
1657
|
+
id: $,
|
|
1658
|
+
component: b.component,
|
|
1659
|
+
config: b.config,
|
|
1660
|
+
name: b.name,
|
|
1661
|
+
isTemplateSection: b.isTemplateSection ?? !1,
|
|
1662
|
+
templateDescription: b.templateDescription,
|
|
1663
|
+
llmConfig: b.llmConfig,
|
|
1664
|
+
visibility: b.visibility,
|
|
1665
|
+
...G
|
|
1666
|
+
// 不再需要 locales, 数据在 page.dataSource 中管理
|
|
1667
|
+
// locales: Object.fromEntries(
|
|
1668
|
+
// filterNone(
|
|
1669
|
+
// locales.map(({ locale, page }) => {
|
|
1670
|
+
// const section = page.sections.find((s) => s.id === sectionId);
|
|
1671
|
+
// return section && [locale, section.properties];
|
|
1672
|
+
// })
|
|
1673
|
+
// )
|
|
1674
|
+
// ),
|
|
1675
|
+
};
|
|
1676
|
+
});
|
|
1666
1677
|
return {
|
|
1667
1678
|
id: A.id || $e(),
|
|
1668
1679
|
createdAt: A.createdAt,
|
|
@@ -1671,114 +1682,114 @@ async function Et(e, { importAssets: n, includeResources: t } = {}) {
|
|
|
1671
1682
|
isPublic: A.isPublic ?? !0,
|
|
1672
1683
|
templateConfig: A.templateConfig,
|
|
1673
1684
|
slug: E,
|
|
1674
|
-
sections: Object.fromEntries(
|
|
1675
|
-
sectionIds:
|
|
1676
|
-
locales: Object.fromEntries(
|
|
1685
|
+
sections: Object.fromEntries(k.map((b) => [b.id, b])),
|
|
1686
|
+
sectionIds: k.map((b) => b.id),
|
|
1687
|
+
locales: Object.fromEntries(g.map(({ locale: b, page: $ }) => [b, $.meta])),
|
|
1677
1688
|
dataSource: A.dataSource ? Object.fromEntries(
|
|
1678
1689
|
// 获取 dataSource 中所有 section ID
|
|
1679
|
-
[...new Set(
|
|
1690
|
+
[...new Set(g.flatMap(({ page: b }) => Object.keys(b.dataSource ?? {})))].map((b) => [
|
|
1680
1691
|
b,
|
|
1681
1692
|
Object.fromEntries(
|
|
1682
|
-
|
|
1683
|
-
var
|
|
1684
|
-
const
|
|
1685
|
-
return [$,
|
|
1693
|
+
g.map(({ locale: $, page: B }) => {
|
|
1694
|
+
var _;
|
|
1695
|
+
const G = (_ = B.dataSource) == null ? void 0 : _[b];
|
|
1696
|
+
return [$, G || {}];
|
|
1686
1697
|
})
|
|
1687
1698
|
)
|
|
1688
1699
|
])
|
|
1689
1700
|
) : Object.fromEntries(
|
|
1690
1701
|
// 获取所有 section ID
|
|
1691
|
-
[...new Set(
|
|
1702
|
+
[...new Set(g.flatMap(({ page: b }) => b.sections.map(($) => $.id)))].map((b) => [
|
|
1692
1703
|
b,
|
|
1693
1704
|
Object.fromEntries(
|
|
1694
|
-
|
|
1695
|
-
var
|
|
1696
|
-
const
|
|
1697
|
-
if (
|
|
1698
|
-
return [$,
|
|
1699
|
-
const
|
|
1700
|
-
return [$, (
|
|
1705
|
+
g.map(({ locale: $, page: B }) => {
|
|
1706
|
+
var q;
|
|
1707
|
+
const G = (q = B.dataSource) == null ? void 0 : q[b];
|
|
1708
|
+
if (G)
|
|
1709
|
+
return [$, G];
|
|
1710
|
+
const _ = B.sections.find((h) => h.id === b);
|
|
1711
|
+
return [$, (_ == null ? void 0 : _.properties) || {}];
|
|
1701
1712
|
})
|
|
1702
1713
|
)
|
|
1703
1714
|
])
|
|
1704
1715
|
)
|
|
1705
1716
|
};
|
|
1706
1717
|
})
|
|
1707
|
-
),
|
|
1718
|
+
), N = F(
|
|
1708
1719
|
((r = l == null ? void 0 : l.routes) == null ? void 0 : r.map(({ path: E }) => {
|
|
1709
|
-
const
|
|
1720
|
+
const g = d ? D(d, Oe(E)) : void 0;
|
|
1710
1721
|
return {
|
|
1711
|
-
...
|
|
1712
|
-
id: (
|
|
1713
|
-
createdAt: (
|
|
1714
|
-
updatedAt: (
|
|
1722
|
+
...g,
|
|
1723
|
+
id: (g == null ? void 0 : g.id) || $e(),
|
|
1724
|
+
createdAt: (g == null ? void 0 : g.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1725
|
+
updatedAt: (g == null ? void 0 : g.updatedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1715
1726
|
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1716
|
-
path: (
|
|
1717
|
-
params:
|
|
1718
|
-
handler: (
|
|
1719
|
-
isPublic: (
|
|
1720
|
-
enabledGenerate: (
|
|
1721
|
-
displayTemplateId: (
|
|
1722
|
-
dataSource: (
|
|
1727
|
+
path: (g == null ? void 0 : g.path) ?? `/${g == null ? void 0 : g.id}`,
|
|
1728
|
+
params: g == null ? void 0 : g.params,
|
|
1729
|
+
handler: (g == null ? void 0 : g.handler) ?? "Pages Kit",
|
|
1730
|
+
isPublic: (g == null ? void 0 : g.isPublic) ?? !0,
|
|
1731
|
+
enabledGenerate: (g == null ? void 0 : g.enabledGenerate) ?? !1,
|
|
1732
|
+
displayTemplateId: (g == null ? void 0 : g.displayTemplateId) ?? void 0,
|
|
1733
|
+
dataSource: (g == null ? void 0 : g.dataSource) ?? {}
|
|
1723
1734
|
};
|
|
1724
1735
|
})) ?? []
|
|
1725
|
-
),
|
|
1736
|
+
), ee = S ? F(((a = l.components) == null ? void 0 : a.map(({ id: E }) => w(S, E))) ?? []) : [];
|
|
1726
1737
|
if (n) {
|
|
1727
|
-
const E = (...
|
|
1728
|
-
y.info(`[${o ?
|
|
1738
|
+
const E = (...g) => {
|
|
1739
|
+
y.info(`[${o ? J(e) : J(O(e, "../../../../"))}] importAssets:`, ...g);
|
|
1729
1740
|
};
|
|
1730
1741
|
try {
|
|
1731
1742
|
E("wait image-bin api ready"), await us({
|
|
1732
|
-
resources: [`${Wt(
|
|
1733
|
-
validateStatus: (
|
|
1743
|
+
resources: [`${Wt(bs)}/api/sdk/uploads`],
|
|
1744
|
+
validateStatus: (k) => k >= 200 && k <= 500
|
|
1734
1745
|
}), E("image-bin api is ready");
|
|
1735
|
-
const
|
|
1746
|
+
const g = {}, A = {};
|
|
1736
1747
|
E("start to upload assets"), await Promise.allSettled([
|
|
1737
|
-
ot(
|
|
1738
|
-
getFilePath: (
|
|
1739
|
-
onFinish: (
|
|
1740
|
-
E(`upload ${
|
|
1748
|
+
ot(ee, g, {
|
|
1749
|
+
getFilePath: (k) => S && O(S, k),
|
|
1750
|
+
onFinish: (k) => {
|
|
1751
|
+
E(`upload ${k.length} component assets`);
|
|
1741
1752
|
}
|
|
1742
1753
|
}),
|
|
1743
|
-
ot(
|
|
1744
|
-
getFilePath: (
|
|
1745
|
-
const b = Be(
|
|
1746
|
-
return p && O(p,
|
|
1754
|
+
ot(P, A, {
|
|
1755
|
+
getFilePath: (k, te) => {
|
|
1756
|
+
const b = Be(P, te.slice(0, 1));
|
|
1757
|
+
return p && O(p, H(b.slug), k);
|
|
1747
1758
|
},
|
|
1748
|
-
onFinish: (
|
|
1749
|
-
E(`upload ${
|
|
1759
|
+
onFinish: (k) => {
|
|
1760
|
+
E(`upload ${k.length} page assets`);
|
|
1750
1761
|
}
|
|
1751
1762
|
})
|
|
1752
1763
|
]), E("upload assets done"), global.gc && global.gc();
|
|
1753
|
-
} catch (
|
|
1754
|
-
E("Error during asset import:",
|
|
1764
|
+
} catch (g) {
|
|
1765
|
+
E("Error during asset import:", g);
|
|
1755
1766
|
}
|
|
1756
1767
|
}
|
|
1757
|
-
const
|
|
1768
|
+
const oe = {};
|
|
1758
1769
|
if (t) {
|
|
1759
|
-
const E = i && O(
|
|
1770
|
+
const E = i && O(H(i), "../../resources/components"), g = F(
|
|
1760
1771
|
((c = (u = l.resources) == null ? void 0 : u.components) == null ? void 0 : c.map(({ id: A }) => w(E, A))) ?? []
|
|
1761
1772
|
);
|
|
1762
|
-
|
|
1763
|
-
|
|
1773
|
+
g.length > 0 && (oe.components = Object.fromEntries(
|
|
1774
|
+
g.map((A, k) => [A.id, { index: k, component: A }])
|
|
1764
1775
|
));
|
|
1765
1776
|
}
|
|
1766
|
-
const
|
|
1767
|
-
if (f &&
|
|
1777
|
+
const pe = {};
|
|
1778
|
+
if (f && K(f)) {
|
|
1768
1779
|
const E = Ft(f);
|
|
1769
|
-
for (const
|
|
1770
|
-
|
|
1780
|
+
for (const g of E)
|
|
1781
|
+
pe[g] = O(f, g);
|
|
1771
1782
|
}
|
|
1772
1783
|
return {
|
|
1773
1784
|
supportedLocales: l.supportedLocales,
|
|
1774
|
-
pageIds:
|
|
1775
|
-
components: Object.fromEntries(
|
|
1776
|
-
pages: Object.fromEntries(
|
|
1785
|
+
pageIds: P.map((E) => E.id),
|
|
1786
|
+
components: Object.fromEntries(ee.map((E, g) => [E.id, { index: g, data: E }])),
|
|
1787
|
+
pages: Object.fromEntries(P.map((E) => [E.id, E])),
|
|
1777
1788
|
config: l.config || {},
|
|
1778
|
-
resources:
|
|
1779
|
-
chunks:
|
|
1780
|
-
routeIds:
|
|
1781
|
-
routes: Object.fromEntries(
|
|
1789
|
+
resources: oe,
|
|
1790
|
+
chunks: pe,
|
|
1791
|
+
routeIds: N.map((E) => E.id),
|
|
1792
|
+
routes: Object.fromEntries(N.map((E) => [E.id, E])),
|
|
1782
1793
|
dataSourceIds: [],
|
|
1783
1794
|
dataSources: {}
|
|
1784
1795
|
};
|
|
@@ -1812,53 +1823,53 @@ async function rt(e, n, {
|
|
|
1812
1823
|
currentParams: [],
|
|
1813
1824
|
currentOptionIds: [],
|
|
1814
1825
|
result: []
|
|
1815
|
-
}),
|
|
1816
|
-
d = { ...d || {}, ...
|
|
1826
|
+
}), D = Object.fromEntries(w.map((P) => [`${l}-${P.paramOptionIds.join("-")}`, P]));
|
|
1827
|
+
d = { ...d || {}, ...D }, t || (f = [...f, ...w.map((P) => `${l}-${P.paramOptionIds.join("-")}`)]);
|
|
1817
1828
|
} else t || f.push(l);
|
|
1818
1829
|
}
|
|
1819
1830
|
y.info("routeIds to be published: ", f);
|
|
1820
1831
|
for (const l of f) {
|
|
1821
1832
|
let m = l;
|
|
1822
1833
|
if (m.includes("-")) {
|
|
1823
|
-
const [
|
|
1824
|
-
m =
|
|
1834
|
+
const [P] = m.split("-");
|
|
1835
|
+
m = P;
|
|
1825
1836
|
}
|
|
1826
1837
|
const w = i == null ? void 0 : i[m];
|
|
1827
1838
|
if (!w) {
|
|
1828
|
-
const
|
|
1829
|
-
|
|
1830
|
-
for (const
|
|
1831
|
-
|
|
1839
|
+
const P = n.pageIds.indexOf(m);
|
|
1840
|
+
P !== -1 && o && (n.pageIds.splice(P, 1), delete n.pages[m]);
|
|
1841
|
+
for (const N of n.pageIds)
|
|
1842
|
+
N.includes(`${m}-`) && (n.pageIds.splice(n.pageIds.indexOf(N), 1), delete n.pages[N]);
|
|
1832
1843
|
y.info("delete main route page", m);
|
|
1833
1844
|
continue;
|
|
1834
1845
|
}
|
|
1835
1846
|
if (l.includes("-") && !(d != null && d[l])) {
|
|
1836
|
-
const
|
|
1837
|
-
|
|
1847
|
+
const P = n.pageIds.indexOf(l);
|
|
1848
|
+
P !== -1 && o && (n.pageIds.splice(P, 1), delete n.pages[l]), y.info("delete page", l);
|
|
1838
1849
|
continue;
|
|
1839
1850
|
}
|
|
1840
1851
|
if (!w.displayTemplateId) {
|
|
1841
1852
|
y.info("no display template", l);
|
|
1842
1853
|
continue;
|
|
1843
1854
|
}
|
|
1844
|
-
const
|
|
1845
|
-
if (!
|
|
1855
|
+
const D = a[w.displayTemplateId];
|
|
1856
|
+
if (!D) {
|
|
1846
1857
|
y.info("no template page", l);
|
|
1847
1858
|
continue;
|
|
1848
1859
|
}
|
|
1849
1860
|
if (n.pageIds.includes(l)) {
|
|
1850
1861
|
if (y.info("has need update page", l), s === "replace")
|
|
1851
1862
|
n.pages[l] = je({
|
|
1852
|
-
page:
|
|
1863
|
+
page: D,
|
|
1853
1864
|
route: w,
|
|
1854
1865
|
state: e,
|
|
1855
1866
|
routeId: l,
|
|
1856
1867
|
routePathInfo: d == null ? void 0 : d[l]
|
|
1857
1868
|
}), y.info("replace page", l);
|
|
1858
1869
|
else if (s === "byUpdateTime") {
|
|
1859
|
-
const
|
|
1860
|
-
(!
|
|
1861
|
-
page:
|
|
1870
|
+
const P = n.pages[w.id];
|
|
1871
|
+
(!P || w.updatedAt && w.updatedAt > P.updatedAt) && (n.pages[l] = je({
|
|
1872
|
+
page: D,
|
|
1862
1873
|
route: w,
|
|
1863
1874
|
state: e,
|
|
1864
1875
|
routeId: l,
|
|
@@ -1867,7 +1878,7 @@ async function rt(e, n, {
|
|
|
1867
1878
|
}
|
|
1868
1879
|
} else
|
|
1869
1880
|
n.pageIds.push(l), n.pages[l] = je({
|
|
1870
|
-
page:
|
|
1881
|
+
page: D,
|
|
1871
1882
|
route: w,
|
|
1872
1883
|
state: e,
|
|
1873
1884
|
routeId: l,
|
|
@@ -1912,7 +1923,7 @@ async function rt(e, n, {
|
|
|
1912
1923
|
S = Object.fromEntries(
|
|
1913
1924
|
await Promise.all(
|
|
1914
1925
|
Object.entries(S).map(async ([f, d]) => {
|
|
1915
|
-
const l = await
|
|
1926
|
+
const l = await bt(d == null ? void 0 : d.data);
|
|
1916
1927
|
return [
|
|
1917
1928
|
f,
|
|
1918
1929
|
{
|
|
@@ -1924,7 +1935,7 @@ async function rt(e, n, {
|
|
|
1924
1935
|
)
|
|
1925
1936
|
), Object.assign(n.components, S), Object.assign(n.config, JSON.parse(JSON.stringify(e.config))), ut(e.resources.components) || (n.resources.components = JSON.parse(JSON.stringify(e.resources.components || {})));
|
|
1926
1937
|
}
|
|
1927
|
-
const
|
|
1938
|
+
const bt = Ge(
|
|
1928
1939
|
async (e) => {
|
|
1929
1940
|
var n;
|
|
1930
1941
|
if (!ut(e == null ? void 0 : e.properties))
|
|
@@ -1949,9 +1960,9 @@ const It = Ge(
|
|
|
1949
1960
|
{
|
|
1950
1961
|
keyGenerator: (e) => {
|
|
1951
1962
|
var i, p, S, f;
|
|
1952
|
-
const n = (e == null ? void 0 : e.id) || "", t = (e == null ? void 0 : e.name) || "", s = ((i = e == null ? void 0 : e.renderer) == null ? void 0 : i.type) || "", o = (e == null ? void 0 : e.properties) || {}, r = (e == null ? void 0 : e.updatedAt) || "", a =
|
|
1963
|
+
const n = (e == null ? void 0 : e.id) || "", t = (e == null ? void 0 : e.name) || "", s = ((i = e == null ? void 0 : e.renderer) == null ? void 0 : i.type) || "", o = (e == null ? void 0 : e.properties) || {}, r = (e == null ? void 0 : e.updatedAt) || "", a = ne("md5").update(JSON.stringify(o)).digest("hex");
|
|
1953
1964
|
let u = "", c = "";
|
|
1954
|
-
return ((p = e == null ? void 0 : e.renderer) == null ? void 0 : p.type) === "react-component" && (u =
|
|
1965
|
+
return ((p = e == null ? void 0 : e.renderer) == null ? void 0 : p.type) === "react-component" && (u = ne("md5").update(((S = e == null ? void 0 : e.renderer) == null ? void 0 : S.script) || "").digest("hex"), c = ne("md5").update(((f = e == null ? void 0 : e.renderer) == null ? void 0 : f.editComponent) || "").digest("hex")), JSON.stringify([
|
|
1955
1966
|
"checkPropertiesFromCode",
|
|
1956
1967
|
n,
|
|
1957
1968
|
t,
|
|
@@ -1969,8 +1980,8 @@ const It = Ge(
|
|
|
1969
1980
|
subdir: "checkPropertiesFromCode"
|
|
1970
1981
|
}
|
|
1971
1982
|
);
|
|
1972
|
-
let Ce,
|
|
1973
|
-
function
|
|
1983
|
+
let Ce, ce, ve, ke, Je;
|
|
1984
|
+
function It() {
|
|
1974
1985
|
return Ce = (async () => {
|
|
1975
1986
|
const e = zt({
|
|
1976
1987
|
types: [
|
|
@@ -1978,12 +1989,12 @@ function bt() {
|
|
|
1978
1989
|
{ did: Ks, type: tt }
|
|
1979
1990
|
]
|
|
1980
1991
|
});
|
|
1981
|
-
|
|
1992
|
+
ce = (await Promise.all(
|
|
1982
1993
|
e.map(async (t) => {
|
|
1983
1994
|
const s = t.path ? await Et(t.path, { importAssets: !1 }) : void 0;
|
|
1984
1995
|
return s ? { blockletId: t.did, state: s, blockletTitle: t.title } : void 0;
|
|
1985
1996
|
})
|
|
1986
|
-
)).filter((t) => !!t), ve =
|
|
1997
|
+
)).filter((t) => !!t), ve = ce.reduce(
|
|
1987
1998
|
(t, s) => Object.assign(
|
|
1988
1999
|
t,
|
|
1989
2000
|
Object.fromEntries(
|
|
@@ -1992,7 +2003,7 @@ function bt() {
|
|
|
1992
2003
|
),
|
|
1993
2004
|
{}
|
|
1994
2005
|
);
|
|
1995
|
-
const n =
|
|
2006
|
+
const n = ce.reduce(
|
|
1996
2007
|
(t, s) => Object.assign(
|
|
1997
2008
|
t,
|
|
1998
2009
|
Object.fromEntries(
|
|
@@ -2004,7 +2015,7 @@ function bt() {
|
|
|
2004
2015
|
ke = Object.fromEntries(
|
|
2005
2016
|
await Promise.all(
|
|
2006
2017
|
Object.entries(n).map(async ([t, s]) => {
|
|
2007
|
-
const o = await
|
|
2018
|
+
const o = await bt(s.component);
|
|
2008
2019
|
return [
|
|
2009
2020
|
t,
|
|
2010
2021
|
{
|
|
@@ -2014,16 +2025,16 @@ function bt() {
|
|
|
2014
2025
|
];
|
|
2015
2026
|
})
|
|
2016
2027
|
)
|
|
2017
|
-
), Je =
|
|
2028
|
+
), Je = ce.reduce((t, s) => Object.assign(t, s.state.chunks), {});
|
|
2018
2029
|
})(), Ce;
|
|
2019
2030
|
}
|
|
2020
2031
|
function ln(e) {
|
|
2021
2032
|
const n = dt(
|
|
2022
2033
|
async () => {
|
|
2023
|
-
await
|
|
2034
|
+
await It().catch((t) => {
|
|
2024
2035
|
y.error("load resource states error", { error: t });
|
|
2025
2036
|
}), await (e == null ? void 0 : e({
|
|
2026
|
-
states:
|
|
2037
|
+
states: ce,
|
|
2027
2038
|
pages: ve,
|
|
2028
2039
|
components: ke,
|
|
2029
2040
|
chunks: Je
|
|
@@ -2041,7 +2052,7 @@ const At = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), Se = globalThis;
|
|
|
2041
2052
|
var at;
|
|
2042
2053
|
(at = Se[At]) == null || at.call(Se);
|
|
2043
2054
|
Se[At] = ln(async ({ pages: e, components: n }) => {
|
|
2044
|
-
const { projectIds: t } =
|
|
2055
|
+
const { projectIds: t } = Z;
|
|
2045
2056
|
y.info(`start update resource states projects(${t.length})`, t), await Promise.race([
|
|
2046
2057
|
new Promise((s) => {
|
|
2047
2058
|
setTimeout(() => {
|
|
@@ -2061,28 +2072,28 @@ Se[At] = ln(async ({ pages: e, components: n }) => {
|
|
|
2061
2072
|
y.error("update resource states failed:", s);
|
|
2062
2073
|
});
|
|
2063
2074
|
});
|
|
2064
|
-
|
|
2075
|
+
Z.startPeriodicCheck();
|
|
2065
2076
|
process.on("beforeExit", () => {
|
|
2066
|
-
|
|
2077
|
+
Z.stopPeriodicCheck();
|
|
2067
2078
|
});
|
|
2068
2079
|
process.on("SIGINT", () => {
|
|
2069
|
-
|
|
2080
|
+
Z.stopPeriodicCheck(), process.exit(0);
|
|
2070
2081
|
});
|
|
2071
2082
|
process.on("SIGTERM", () => {
|
|
2072
|
-
|
|
2083
|
+
Z.stopPeriodicCheck(), process.exit(0);
|
|
2073
2084
|
});
|
|
2074
2085
|
async function Ot({
|
|
2075
2086
|
projectId: e,
|
|
2076
2087
|
pages: n,
|
|
2077
2088
|
components: t
|
|
2078
2089
|
}) {
|
|
2079
|
-
const s =
|
|
2090
|
+
const s = Z.sharedInstances[e];
|
|
2080
2091
|
if (!s) {
|
|
2081
2092
|
y.info(`projectId: ${e} not found in sharedInstances`);
|
|
2082
2093
|
return;
|
|
2083
2094
|
}
|
|
2084
2095
|
s.syncedStore.resources.pages = n;
|
|
2085
|
-
const o = await
|
|
2096
|
+
const o = await X.findByPk(e);
|
|
2086
2097
|
if (o != null && o.useAllResources)
|
|
2087
2098
|
s.syncedStore.resources.components = t;
|
|
2088
2099
|
else {
|
|
@@ -2102,14 +2113,14 @@ async function ao() {
|
|
|
2102
2113
|
async function Ve({
|
|
2103
2114
|
ensureLoaded: e = !0
|
|
2104
2115
|
} = {}) {
|
|
2105
|
-
return e && (Ce ?? (Ce =
|
|
2116
|
+
return e && (Ce ?? (Ce = It()), await Ce), { states: ce, pages: ve, components: ke, chunks: Je };
|
|
2106
2117
|
}
|
|
2107
2118
|
export {
|
|
2108
2119
|
yt as C,
|
|
2109
2120
|
et as G,
|
|
2110
|
-
|
|
2121
|
+
X as P,
|
|
2111
2122
|
tt as R,
|
|
2112
|
-
|
|
2123
|
+
Z as S,
|
|
2113
2124
|
to as a,
|
|
2114
2125
|
Ve as b,
|
|
2115
2126
|
Ns as c,
|