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