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