@blocklet/pages-kit-inner-components 0.4.130 → 0.4.131
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-3OBY1z8c.js → array-D-LDfLBW.js} +1 -1
- package/lib/cjs/chunks/{config-string-BOqUdy2S.js → config-string-BMi-8GXv.js} +1 -1
- package/lib/cjs/chunks/{draft-data-C4FzOyR5.js → draft-data-C-aBMmuZ.js} +1 -1
- package/lib/cjs/chunks/home-BWklFLCu.js +38 -0
- package/lib/cjs/chunks/publish-button-kozBI0aZ.js +1 -0
- package/lib/cjs/chunks/site-state-C8qhC6pw.js +57 -0
- package/lib/cjs/chunks/state-DPSTH2vo.js +1 -0
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/locales.js +1 -1
- package/lib/cjs/project-html.js +1 -1
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/add-component.js +3 -3
- package/lib/es/chunks/{array-CWudJ_mc.js → array-BfSgATE1.js} +1 -1
- package/lib/es/chunks/{config-string-CcDa1MHl.js → config-string-BObBTkZS.js} +1 -1
- package/lib/es/chunks/{draft-data-DoNjnkxB.js → draft-data-PScFOAJJ.js} +1 -1
- package/lib/es/chunks/home-qQe9H8C9.js +527 -0
- package/lib/es/chunks/publish-button-DMQRXAVS.js +455 -0
- package/lib/es/chunks/site-state-qF6lXjrQ.js +1833 -0
- package/lib/es/chunks/{state-DNndJ33Y.js → state-DGyH1TW3.js} +97 -97
- package/lib/es/components.js +1 -1
- package/lib/es/home.js +11 -10
- package/lib/es/locales.js +39 -9
- package/lib/es/project-html.js +1 -1
- package/lib/es/resources.js +1 -1
- package/lib/es/setting.js +2 -2
- package/lib/es/site-state.js +13 -12
- package/package.json +3 -3
- package/lib/cjs/chunks/home-B6yRf7rx.js +0 -38
- package/lib/cjs/chunks/publish-button-BcyFHcAL.js +0 -1
- package/lib/cjs/chunks/site-state-C5t-5c6U.js +0 -57
- package/lib/cjs/chunks/state-5jwYHuoB.js +0 -1
- package/lib/es/chunks/home-Crb2pbrM.js +0 -489
- package/lib/es/chunks/publish-button-CAJErJjj.js +0 -295
- package/lib/es/chunks/site-state-BLNi12iP.js +0 -1717
|
@@ -0,0 +1,1833 @@
|
|
|
1
|
+
var St = Object.defineProperty;
|
|
2
|
+
var wt = (t, s, e) => s in t ? St(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
|
|
3
|
+
var j = (t, s, e) => wt(t, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
import { getComponentMountPoint as bt } from "@blocklet/pages-kit/builtin/utils";
|
|
5
|
+
import { PreloadComponentScriptModule as fe } from "@blocklet/pages-kit/types";
|
|
6
|
+
import { componentUMDName as It, RenderNestedComponent as Je, mergeComponent as Et, getComponentDependencies as At } from "@blocklet/pages-kit/utils/property";
|
|
7
|
+
import { memoize as Ee, Sandbox as nt, BuiltinModules as Ot } from "@blocklet/quickjs";
|
|
8
|
+
import I from "@blocklet/sdk/lib/config";
|
|
9
|
+
import { LRUCache as Re } from "lru-cache";
|
|
10
|
+
import Tt, { Headers as vt } from "node-fetch";
|
|
11
|
+
import { joinURL as K, getQuery as Pt, withQuery as Ct, parseURL as Ve, withHttps as Dt } from "ufo";
|
|
12
|
+
import { createHash as Ae } from "crypto";
|
|
13
|
+
import xt from "@blocklet/logger";
|
|
14
|
+
import { BuiltinModules as jt } from "@blocklet/pages-kit/utils/builtin";
|
|
15
|
+
import { createBuiltinModuleTransformer as kt, isRelativeModule as Nt } from "@blocklet/pages-kit/utils/typescript/builtin-module-transformer";
|
|
16
|
+
import { getResources as Lt, getComponentWebEndpoint as Rt, call as _t } from "@blocklet/sdk/lib/component";
|
|
17
|
+
import Mt from "autoprefixer";
|
|
18
|
+
import * as Ut from "esbuild";
|
|
19
|
+
import { readFileSync as Z, existsSync as F, lstatSync as X, readdirSync as $t, rmSync as ot, mkdtempSync as Ft, renameSync as He, mkdirSync as G, writeFileSync as he, copyFileSync as Bt, createWriteStream as Gt } from "fs";
|
|
20
|
+
import Jt from "postcss";
|
|
21
|
+
import Vt from "tailwindcss";
|
|
22
|
+
import N from "typescript";
|
|
23
|
+
import { setPageDataSource as Ht } from "@blocklet/pages-kit/utils/data-source";
|
|
24
|
+
import { getRouteMetaDataByOptionIds as Kt, generateParamCombinations as je } from "@blocklet/pages-kit/utils/route";
|
|
25
|
+
import { reactive as zt } from "@reactivedata/reactive";
|
|
26
|
+
import { syncedStore as Yt, getYjsValue as Q } from "@syncedstore/core";
|
|
27
|
+
import { globSync as ke } from "glob";
|
|
28
|
+
import * as Pe from "lib0/decoding";
|
|
29
|
+
import * as k from "lib0/encoding";
|
|
30
|
+
import rt from "lodash/cloneDeep";
|
|
31
|
+
import at from "lodash/debounce";
|
|
32
|
+
import _e from "lodash/get";
|
|
33
|
+
import Wt from "lodash/isEmpty";
|
|
34
|
+
import qt from "lodash/pick";
|
|
35
|
+
import Ke from "lodash/set";
|
|
36
|
+
import Qt from "lodash/union";
|
|
37
|
+
import { customAlphabet as Xt } from "nanoid";
|
|
38
|
+
import Zt from "p-limit";
|
|
39
|
+
import es, { join as O, dirname as R, basename as se } from "path";
|
|
40
|
+
import { pipeline as ts } from "stream/promises";
|
|
41
|
+
import { x as ss } from "tar";
|
|
42
|
+
import ns from "wait-on";
|
|
43
|
+
import { Awareness as os, encodeAwarenessUpdate as ze, removeAwarenessStates as rs, applyAwarenessUpdate as as } from "y-protocols/awareness";
|
|
44
|
+
import { writeUpdate as is, writeSyncStep1 as cs, readSyncMessage as ps } from "y-protocols/sync";
|
|
45
|
+
import * as ee from "yaml";
|
|
46
|
+
import * as $ from "yjs";
|
|
47
|
+
import ls from "lodash/isNil";
|
|
48
|
+
import { DataTypes as x, Sequelize as ds, Model as it, Op as us } from "sequelize";
|
|
49
|
+
import "sqlite3";
|
|
50
|
+
import "@blocklet/pages-kit/types/state";
|
|
51
|
+
I.env.mode;
|
|
52
|
+
I.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY;
|
|
53
|
+
I.env.OPENAI_BASE_URL || process.env.OPENAI_BASE_URL;
|
|
54
|
+
I.env.TRANSLATE_ADDITIONAL_PROMPT || process.env.TRANSLATE_ADDITIONAL_PROMPT;
|
|
55
|
+
I.env.PAGE_CONTENT_ADDITIONAL_PROMPT || process.env.PAGE_CONTENT_ADDITIONAL_PROMPT;
|
|
56
|
+
const ms = "image-bin";
|
|
57
|
+
I.env.INIT_TEMPLATE_PATH;
|
|
58
|
+
const fs = process.env.DATABASE_URL || es.join(I.env.dataDir, "db/pages-kit.db"), Ye = I, kn = () => I.env.tenantMode === "multiple", Nn = () => {
|
|
59
|
+
var t;
|
|
60
|
+
return (ls(Ye.env.preferences.multiTenantAllProjectAccessPassports) ? [] : (t = Ye.env.preferences.multiTenantAllProjectAccessPassports) == null ? void 0 : t.split(",")) || [];
|
|
61
|
+
}, b = xt("pages-kit"), gs = x.sqlite.DATE.parse;
|
|
62
|
+
x.sqlite.DATE.parse = (t, s) => typeof t == "number" ? new Date(t) : gs(t, s);
|
|
63
|
+
const ie = new ds({
|
|
64
|
+
dialect: "sqlite",
|
|
65
|
+
storage: fs,
|
|
66
|
+
benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
|
|
67
|
+
retry: {
|
|
68
|
+
match: [/SQLITE_BUSY/],
|
|
69
|
+
name: "query",
|
|
70
|
+
max: 10
|
|
71
|
+
},
|
|
72
|
+
// eslint-disable-next-line no-console
|
|
73
|
+
logging: process.env.ENABLE_SEQUELIZE_LOGGING === "true" ? console.log : !1
|
|
74
|
+
// logQueryParameters: true,
|
|
75
|
+
});
|
|
76
|
+
ie.query("pragma journal_mode = WAL;");
|
|
77
|
+
ie.query("pragma synchronous = normal;");
|
|
78
|
+
ie.query("pragma journal_size_limit = 67108864;");
|
|
79
|
+
class Oe extends it {
|
|
80
|
+
// Foreign key to Component
|
|
81
|
+
}
|
|
82
|
+
Oe.init(
|
|
83
|
+
{
|
|
84
|
+
id: {
|
|
85
|
+
type: x.UUID,
|
|
86
|
+
allowNull: !1,
|
|
87
|
+
primaryKey: !0,
|
|
88
|
+
defaultValue: x.UUIDV4
|
|
89
|
+
},
|
|
90
|
+
projectId: {
|
|
91
|
+
type: x.UUID,
|
|
92
|
+
allowNull: !1
|
|
93
|
+
},
|
|
94
|
+
componentId: {
|
|
95
|
+
type: x.STRING,
|
|
96
|
+
allowNull: !1
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{ sequelize: ie, tableName: "ProjectComponents", timestamps: !1 }
|
|
100
|
+
);
|
|
101
|
+
class q extends it {
|
|
102
|
+
static async getProjectByIdOrSlug(s) {
|
|
103
|
+
return q.findOne({
|
|
104
|
+
where: {
|
|
105
|
+
[us.or]: [{ id: s }, { slug: s }]
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
q.init(
|
|
111
|
+
{
|
|
112
|
+
id: {
|
|
113
|
+
type: x.UUID,
|
|
114
|
+
defaultValue: x.UUIDV4,
|
|
115
|
+
primaryKey: !0
|
|
116
|
+
},
|
|
117
|
+
name: {
|
|
118
|
+
type: x.STRING,
|
|
119
|
+
allowNull: !1
|
|
120
|
+
},
|
|
121
|
+
description: x.TEXT,
|
|
122
|
+
createdAt: x.DATE,
|
|
123
|
+
updatedAt: x.DATE,
|
|
124
|
+
createdBy: {
|
|
125
|
+
type: x.STRING,
|
|
126
|
+
allowNull: !1
|
|
127
|
+
},
|
|
128
|
+
updatedBy: {
|
|
129
|
+
type: x.STRING,
|
|
130
|
+
allowNull: !1
|
|
131
|
+
},
|
|
132
|
+
slug: x.STRING,
|
|
133
|
+
icon: x.STRING,
|
|
134
|
+
pinnedAt: x.DATE,
|
|
135
|
+
useAllResources: x.BOOLEAN,
|
|
136
|
+
npmSecret: x.STRING,
|
|
137
|
+
relatedBlocklets: {
|
|
138
|
+
type: x.JSON,
|
|
139
|
+
allowNull: !1,
|
|
140
|
+
defaultValue: {},
|
|
141
|
+
get() {
|
|
142
|
+
return this.getDataValue("relatedBlocklets") || {};
|
|
143
|
+
},
|
|
144
|
+
set(t) {
|
|
145
|
+
this.setDataValue("relatedBlocklets", JSON.stringify(t || {}));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{ sequelize: ie, paranoid: !0 }
|
|
150
|
+
);
|
|
151
|
+
q.hasMany(Oe, {
|
|
152
|
+
foreignKey: "projectId",
|
|
153
|
+
as: "components"
|
|
154
|
+
});
|
|
155
|
+
const hs = async (t, { componentId: s }) => {
|
|
156
|
+
const e = `@tailwind components;
|
|
157
|
+
@tailwind utilities;
|
|
158
|
+
`, n = `.CustomComponent_${s}`;
|
|
159
|
+
return (await Jt([
|
|
160
|
+
Vt({ content: [{ raw: t, extension: "tsx" }] }),
|
|
161
|
+
Mt({
|
|
162
|
+
overrideBrowserslist: ["> 1%", "last 2 versions"],
|
|
163
|
+
stats: {}
|
|
164
|
+
}),
|
|
165
|
+
(r) => {
|
|
166
|
+
r.walkRules((l) => {
|
|
167
|
+
l.selectors = l.selectors.map((i) => i.replace(/\.(.+)/g, `${n}.$1,${n} .$1`));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// FIXME: cssnano use browserslist, it is not working with the fs isolation
|
|
171
|
+
// cssnano({ preset: 'default' }),
|
|
172
|
+
]).process(e)).css;
|
|
173
|
+
}, ys = async (t, { componentId: s }) => {
|
|
174
|
+
const e = await hs(t, { componentId: s });
|
|
175
|
+
return `export const __PagesKit_CSS__ = ${JSON.stringify(e)};
|
|
176
|
+
|
|
177
|
+
${t}
|
|
178
|
+
`;
|
|
179
|
+
}, We = Ee(
|
|
180
|
+
async (t, s) => {
|
|
181
|
+
let e = N.transpileModule(t, {
|
|
182
|
+
compilerOptions: {
|
|
183
|
+
jsx: N.JsxEmit.React,
|
|
184
|
+
target: N.ScriptTarget.ES2016,
|
|
185
|
+
module: N.ModuleKind.ESNext
|
|
186
|
+
},
|
|
187
|
+
transformers: {
|
|
188
|
+
before: [kt(N)]
|
|
189
|
+
}
|
|
190
|
+
}).outputText;
|
|
191
|
+
if (s.tailwind && (e = await ys(e, { componentId: s.componentId })), s.module === fe.ESM) return e;
|
|
192
|
+
const n = N.transpileModule(e, {
|
|
193
|
+
compilerOptions: {
|
|
194
|
+
jsx: N.JsxEmit.React,
|
|
195
|
+
target: N.ScriptTarget.ES2016,
|
|
196
|
+
module: N.ModuleKind.CommonJS,
|
|
197
|
+
moduleResolution: N.ModuleResolutionKind.Node16
|
|
198
|
+
}
|
|
199
|
+
}).outputText;
|
|
200
|
+
return s.module === fe.CJS ? n : ws(s.moduleName, n);
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
keyGenerator: (t, s) => {
|
|
204
|
+
const e = Ae("md5").update(t).digest("hex"), n = {
|
|
205
|
+
...s,
|
|
206
|
+
componentId: s.componentId,
|
|
207
|
+
module: s.module,
|
|
208
|
+
...s.module !== fe.ESM ? { moduleName: s.moduleName } : {},
|
|
209
|
+
tailwind: s.tailwind
|
|
210
|
+
};
|
|
211
|
+
return JSON.stringify(["transpileModule", e, n]);
|
|
212
|
+
},
|
|
213
|
+
lruOptions: {
|
|
214
|
+
max: 100,
|
|
215
|
+
// 限制缓存项数量为100
|
|
216
|
+
ttl: 1e3 * 60 * 60
|
|
217
|
+
// 1小时过期时间
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
), Ss = async (t, s) => {
|
|
221
|
+
var l, i;
|
|
222
|
+
const n = (i = (l = (await Ut.build({
|
|
223
|
+
entryPoints: ["index.tsx"],
|
|
224
|
+
external: Object.keys(jt),
|
|
225
|
+
format: "esm",
|
|
226
|
+
target: "esnext",
|
|
227
|
+
bundle: !0,
|
|
228
|
+
write: !1,
|
|
229
|
+
plugins: [
|
|
230
|
+
{
|
|
231
|
+
name: "vfs",
|
|
232
|
+
setup(d) {
|
|
233
|
+
let p = null;
|
|
234
|
+
d.onResolve({ filter: /.*/ }, (u) => u.path === "index.tsx" ? { path: "index.tsx", namespace: "vfs" } : u.path === "./component" ? { path: "component.tsx", namespace: "vfs" } : null), d.onLoad({ filter: /.*/, namespace: "vfs" }, async (u) => {
|
|
235
|
+
var y;
|
|
236
|
+
if (u.path === "index.tsx")
|
|
237
|
+
return { contents: `export { ${s} } from './component'`, loader: "tsx" };
|
|
238
|
+
if (u.path === "component.tsx")
|
|
239
|
+
return { contents: t, loader: "tsx" };
|
|
240
|
+
if (Nt(u.path)) {
|
|
241
|
+
const g = u.path.split("/").pop();
|
|
242
|
+
if (p || (p = await Be({ ensureLoaded: !1 })), (y = p == null ? void 0 : p.chunks) != null && y[g])
|
|
243
|
+
try {
|
|
244
|
+
const c = Z(p.chunks[g], "utf-8");
|
|
245
|
+
return b.info("get chunk from local file system", g), { contents: c, loader: "tsx" };
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
})).outputFiles) == null ? void 0 : l[0]) == null ? void 0 : i.contents;
|
|
255
|
+
if (!n) throw new Error("Failed to build server code");
|
|
256
|
+
const o = Buffer.from(n).toString();
|
|
257
|
+
return N.transpileModule(o, {
|
|
258
|
+
compilerOptions: { module: N.ModuleKind.ESNext, target: N.ScriptTarget.ES2020 }
|
|
259
|
+
}).outputText;
|
|
260
|
+
}, ct = Ee(
|
|
261
|
+
async (t, s) => {
|
|
262
|
+
const e = await Ss(t, s);
|
|
263
|
+
return new RegExp(`export\\s+\\{\\s+${s}\\s+\\}`, "m").test(e) ? e : void 0;
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
keyGenerator: (t, s) => {
|
|
267
|
+
const e = Ae("md5").update(t).digest("hex");
|
|
268
|
+
return JSON.stringify(["extractExportValueSchema", e, s]);
|
|
269
|
+
},
|
|
270
|
+
lruOptions: {
|
|
271
|
+
max: 100,
|
|
272
|
+
ttl: 1e3 * 60 * 60
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
), ws = (t, s) => `// GENERATED FILE. DO NOT EDIT.
|
|
276
|
+
var ${t} = function () {
|
|
277
|
+
|
|
278
|
+
const exports = {};
|
|
279
|
+
let moduleExports = null;
|
|
280
|
+
|
|
281
|
+
// add commonjs module compatibility layer
|
|
282
|
+
const module = { exports: moduleExports };
|
|
283
|
+
|
|
284
|
+
// execute component code
|
|
285
|
+
${s}
|
|
286
|
+
|
|
287
|
+
// handle possible module.exports
|
|
288
|
+
if (module.exports && module.exports !== moduleExports) {
|
|
289
|
+
// if module.exports is used, use it first
|
|
290
|
+
return typeof module.exports === 'object' ? module.exports : { default: module.exports };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ensure a default export
|
|
294
|
+
if (!('default' in exports) && Object.keys(exports).length === 0) {
|
|
295
|
+
// module has no exports, return null to indicate invalid
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return exports;
|
|
300
|
+
};
|
|
301
|
+
`, re = new Re({
|
|
302
|
+
max: 100
|
|
303
|
+
}), bs = 60 * 60, qe = 60;
|
|
304
|
+
function Is(t) {
|
|
305
|
+
b.info("clear preload components cache", { cacheKey: t }), re.delete(t);
|
|
306
|
+
}
|
|
307
|
+
function Es(t) {
|
|
308
|
+
for (const s of re.keys())
|
|
309
|
+
s.includes(t) && (b.info("clear preload components cache", { cacheKey: s }), Is(s));
|
|
310
|
+
}
|
|
311
|
+
function As({
|
|
312
|
+
mode: t,
|
|
313
|
+
instanceId: s,
|
|
314
|
+
componentId: e,
|
|
315
|
+
locale: n
|
|
316
|
+
}) {
|
|
317
|
+
return ["getPreloadComponents", t, s, e, n].join("-");
|
|
318
|
+
}
|
|
319
|
+
async function Ln({
|
|
320
|
+
mode: t,
|
|
321
|
+
req: s,
|
|
322
|
+
state: e,
|
|
323
|
+
locale: n,
|
|
324
|
+
instances: o,
|
|
325
|
+
module: r
|
|
326
|
+
}) {
|
|
327
|
+
const {
|
|
328
|
+
supportedLocales: l,
|
|
329
|
+
config: { defaultLocale: i }
|
|
330
|
+
} = e;
|
|
331
|
+
if (!i) return null;
|
|
332
|
+
const d = (await Promise.all(
|
|
333
|
+
o.map(async (c) => {
|
|
334
|
+
try {
|
|
335
|
+
const a = As({
|
|
336
|
+
mode: t,
|
|
337
|
+
instanceId: c.id,
|
|
338
|
+
componentId: c.componentId,
|
|
339
|
+
locale: n
|
|
340
|
+
});
|
|
341
|
+
if (t !== "draft" && c.useCache && re.has(a))
|
|
342
|
+
return b.info(`get preload component from cache: ${a}`), re.get(a);
|
|
343
|
+
const m = ye({ state: e, componentId: c.componentId });
|
|
344
|
+
if (!m) return null;
|
|
345
|
+
const S = await Os({
|
|
346
|
+
req: s,
|
|
347
|
+
state: e,
|
|
348
|
+
componentId: m.id,
|
|
349
|
+
locale: n,
|
|
350
|
+
defaultLocale: i,
|
|
351
|
+
properties: c.properties
|
|
352
|
+
});
|
|
353
|
+
if (!S) return null;
|
|
354
|
+
const C = { instanceId: c.id, preload: S };
|
|
355
|
+
if (t !== "draft" && c.useCache) {
|
|
356
|
+
let A = bs;
|
|
357
|
+
c.cacheDuration && (A = c.cacheDuration), b.info(`set preload component to cache(${A}s): ${a}`), re.set(a, C, {
|
|
358
|
+
ttl: A * 1e3
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return C;
|
|
362
|
+
} catch (a) {
|
|
363
|
+
return b.error("get preload component error", { instanceId: c.id, componentId: c.componentId }, { error: a }), null;
|
|
364
|
+
}
|
|
365
|
+
})
|
|
366
|
+
)).filter((c) => !!c), p = Object.values(
|
|
367
|
+
d.reduce((c, a) => ({ ...c, ...a.preload.components }), {})
|
|
368
|
+
);
|
|
369
|
+
async function u() {
|
|
370
|
+
const c = await Promise.all(
|
|
371
|
+
p.map(async (a) => {
|
|
372
|
+
const m = It({ componentId: a.component.id }), S = r === fe.ESM ? {
|
|
373
|
+
module: r,
|
|
374
|
+
script: await We(a.script, {
|
|
375
|
+
componentId: a.component.id,
|
|
376
|
+
module: r,
|
|
377
|
+
tailwind: t !== "draft"
|
|
378
|
+
})
|
|
379
|
+
} : {
|
|
380
|
+
module: r,
|
|
381
|
+
script: await We(a.script, {
|
|
382
|
+
componentId: a.component.id,
|
|
383
|
+
module: r,
|
|
384
|
+
moduleName: m,
|
|
385
|
+
tailwind: t !== "draft"
|
|
386
|
+
}),
|
|
387
|
+
moduleName: m
|
|
388
|
+
};
|
|
389
|
+
return [a.component.id, { component: a.component, script: S }];
|
|
390
|
+
})
|
|
391
|
+
);
|
|
392
|
+
return Object.fromEntries(c);
|
|
393
|
+
}
|
|
394
|
+
const y = await u();
|
|
395
|
+
return {
|
|
396
|
+
config: { defaultLocale: i, supportedLocales: l },
|
|
397
|
+
components: y,
|
|
398
|
+
instances: d.map((c) => ({
|
|
399
|
+
id: c.instanceId,
|
|
400
|
+
componentId: c.preload.component.id,
|
|
401
|
+
locales: { [c.preload.locale]: { props: c.preload.props } }
|
|
402
|
+
}))
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
async function Os({
|
|
406
|
+
req: t,
|
|
407
|
+
state: s,
|
|
408
|
+
componentId: e,
|
|
409
|
+
locale: n,
|
|
410
|
+
defaultLocale: o,
|
|
411
|
+
properties: r
|
|
412
|
+
}) {
|
|
413
|
+
const { supportedLocales: l } = s, i = ye({ state: s, componentId: e });
|
|
414
|
+
if (!i) return null;
|
|
415
|
+
const d = l.some((u) => u.locale === n) ? n : o;
|
|
416
|
+
if (!d) return null;
|
|
417
|
+
const p = await pt({ req: t, state: s, componentId: e, locale: d, defaultLocale: o, properties: r });
|
|
418
|
+
return p ? {
|
|
419
|
+
component: i,
|
|
420
|
+
...p
|
|
421
|
+
} : null;
|
|
422
|
+
}
|
|
423
|
+
const Ts = 20;
|
|
424
|
+
async function pt({
|
|
425
|
+
req: t,
|
|
426
|
+
depth: s = 0,
|
|
427
|
+
state: e,
|
|
428
|
+
componentId: n,
|
|
429
|
+
locale: o,
|
|
430
|
+
defaultLocale: r,
|
|
431
|
+
properties: l
|
|
432
|
+
}) {
|
|
433
|
+
if (s > Ts) throw new RangeError("max component depth exceeded");
|
|
434
|
+
const i = vs({ state: e, componentId: n, properties: l, locale: o });
|
|
435
|
+
if (!i) return null;
|
|
436
|
+
const { props: d } = i, p = {
|
|
437
|
+
locale: o || r,
|
|
438
|
+
components: { [i.component.id]: { component: i.component, script: i.script } },
|
|
439
|
+
props: { ...d }
|
|
440
|
+
};
|
|
441
|
+
try {
|
|
442
|
+
const u = await Ps({ ...i, req: t });
|
|
443
|
+
u != null && u.props && Object.assign(p.props, u.props);
|
|
444
|
+
} catch (u) {
|
|
445
|
+
b.error("preload data at server side error", { componentId: n, name: i.component.name }, { error: u });
|
|
446
|
+
}
|
|
447
|
+
return await Promise.all(
|
|
448
|
+
Object.entries(d).map(async ([u, y]) => {
|
|
449
|
+
if ((y == null ? void 0 : y.type) === Je) {
|
|
450
|
+
const g = await pt({
|
|
451
|
+
req: t,
|
|
452
|
+
depth: s + 1,
|
|
453
|
+
state: e,
|
|
454
|
+
componentId: y.componentId,
|
|
455
|
+
locale: o,
|
|
456
|
+
defaultLocale: r,
|
|
457
|
+
properties: y.properties
|
|
458
|
+
});
|
|
459
|
+
g && (Object.assign(p.components, g.components), Object.assign(p.props, {
|
|
460
|
+
[u]: {
|
|
461
|
+
type: Je,
|
|
462
|
+
componentId: y.componentId,
|
|
463
|
+
props: g.props
|
|
464
|
+
}
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
467
|
+
})
|
|
468
|
+
), p;
|
|
469
|
+
}
|
|
470
|
+
function vs({
|
|
471
|
+
state: t,
|
|
472
|
+
componentId: s,
|
|
473
|
+
locale: e,
|
|
474
|
+
properties: n
|
|
475
|
+
}) {
|
|
476
|
+
const o = ye({ state: t, componentId: s });
|
|
477
|
+
if (!o) return null;
|
|
478
|
+
const r = Et({
|
|
479
|
+
componentId: s,
|
|
480
|
+
getComponent: (l) => ye({ state: t, componentId: l }),
|
|
481
|
+
locale: e,
|
|
482
|
+
defaultLocale: t.config.defaultLocale,
|
|
483
|
+
properties: n
|
|
484
|
+
});
|
|
485
|
+
return r ? { component: o, script: r.script, props: { locale: e, ...r.props } } : null;
|
|
486
|
+
}
|
|
487
|
+
function ye({ state: t, componentId: s }) {
|
|
488
|
+
var e, n, o;
|
|
489
|
+
return ((e = t.components[s]) == null ? void 0 : e.data) ?? ((o = (n = t.resources.components) == null ? void 0 : n[s]) == null ? void 0 : o.component);
|
|
490
|
+
}
|
|
491
|
+
function Rn({ state: t, name: s }) {
|
|
492
|
+
var n, o;
|
|
493
|
+
const e = s.toLowerCase();
|
|
494
|
+
return ((n = Object.values(t.components).find((r) => {
|
|
495
|
+
var l;
|
|
496
|
+
return ((l = r.data.name) == null ? void 0 : l.toLowerCase()) === e;
|
|
497
|
+
})) == null ? void 0 : n.data) ?? ((o = t.resources.components && Object.values(t.resources.components).find((r) => {
|
|
498
|
+
var l;
|
|
499
|
+
return ((l = r.component.name) == null ? void 0 : l.toLowerCase()) === e;
|
|
500
|
+
})) == null ? void 0 : o.component);
|
|
501
|
+
}
|
|
502
|
+
async function Ps({
|
|
503
|
+
component: t,
|
|
504
|
+
script: s,
|
|
505
|
+
props: e,
|
|
506
|
+
req: n
|
|
507
|
+
}) {
|
|
508
|
+
if (!(s != null && s.includes("getServerSideProps")))
|
|
509
|
+
return null;
|
|
510
|
+
const o = await ct(s, "getServerSideProps");
|
|
511
|
+
if (!o) return null;
|
|
512
|
+
const r = new Promise((i) => {
|
|
513
|
+
setTimeout(() => {
|
|
514
|
+
i({});
|
|
515
|
+
}, qe * 1e3);
|
|
516
|
+
});
|
|
517
|
+
return await Promise.race([
|
|
518
|
+
r,
|
|
519
|
+
nt.callFunction({
|
|
520
|
+
code: `${o}
|
|
521
|
+
|
|
522
|
+
export async function getServerSidePropsWrapper(props) {
|
|
523
|
+
const { location, fetch, props: componentProps } = props;
|
|
524
|
+
// 使用局部变量而不是全局变量
|
|
525
|
+
const originalLocation = typeof window !== 'undefined' ? window.location : undefined;
|
|
526
|
+
const originalFetch = globalThis.fetch;
|
|
527
|
+
|
|
528
|
+
try {
|
|
529
|
+
globalThis.location = location;
|
|
530
|
+
globalThis.fetch = fetch;
|
|
531
|
+
return await getServerSideProps(componentProps);
|
|
532
|
+
} finally {
|
|
533
|
+
// 清理全局状态
|
|
534
|
+
if (originalLocation) globalThis.location = originalLocation;
|
|
535
|
+
if (originalFetch) globalThis.fetch = originalFetch;
|
|
536
|
+
}
|
|
537
|
+
}`,
|
|
538
|
+
filename: `${t.name || t.id}.js`,
|
|
539
|
+
moduleLoader: (i) => {
|
|
540
|
+
if (i === "@blocklet/pages-kit/builtin/utils")
|
|
541
|
+
return `const { joinURL, withQuery, getQuery, getComponentMountPoint } = globalThis
|
|
542
|
+
export { joinURL, withQuery, getQuery, getComponentMountPoint }
|
|
543
|
+
`;
|
|
544
|
+
if (i === "@blocklet/pages-kit/builtin/dayjs")
|
|
545
|
+
return Ot.dayjs;
|
|
546
|
+
},
|
|
547
|
+
global: {
|
|
548
|
+
console: {
|
|
549
|
+
// NOTE: do not return logger.xxx result, it will cause memory leak
|
|
550
|
+
// eslint-disable-next-line prettier/prettier
|
|
551
|
+
log: (...i) => {
|
|
552
|
+
b.info(...i);
|
|
553
|
+
},
|
|
554
|
+
warn: (...i) => {
|
|
555
|
+
b.warn(...i);
|
|
556
|
+
},
|
|
557
|
+
error: (...i) => {
|
|
558
|
+
b.error(...i);
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
getComponentMountPoint: bt,
|
|
562
|
+
joinURL: K,
|
|
563
|
+
withQuery: Ct,
|
|
564
|
+
getQuery: Pt
|
|
565
|
+
},
|
|
566
|
+
functionName: "getServerSidePropsWrapper",
|
|
567
|
+
args: [
|
|
568
|
+
{
|
|
569
|
+
// NOTE: IMPORTANT! place location and fetch (has side effect) at the args not global
|
|
570
|
+
// because the global is shared between all runtime and just init once
|
|
571
|
+
location: { href: K(Dt(n.hostname), n.originalUrl) },
|
|
572
|
+
fetch: (i, { ...d } = {}) => {
|
|
573
|
+
const p = typeof i == "string" && i.startsWith("/") ? K(I.env.appUrl, i) : i;
|
|
574
|
+
if (typeof p == "string" && Ve(p).host === Ve(I.env.appUrl).host) {
|
|
575
|
+
const u = n.get("cookie");
|
|
576
|
+
if (u) {
|
|
577
|
+
const y = new vt(d.headers);
|
|
578
|
+
y.set("cookie", u), d.headers = y;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return Tt(p, {
|
|
582
|
+
...d,
|
|
583
|
+
timeout: qe * 1e3
|
|
584
|
+
}).then((u) => ({
|
|
585
|
+
ok: u.ok,
|
|
586
|
+
status: u.status,
|
|
587
|
+
statusText: u.statusText,
|
|
588
|
+
headers: Object.fromEntries(u.headers.entries()),
|
|
589
|
+
json: () => u.json()
|
|
590
|
+
}));
|
|
591
|
+
},
|
|
592
|
+
props: e
|
|
593
|
+
}
|
|
594
|
+
]
|
|
595
|
+
})
|
|
596
|
+
]);
|
|
597
|
+
}
|
|
598
|
+
const Cs = Ee(
|
|
599
|
+
async (t, s, e) => {
|
|
600
|
+
if (!(t != null && t.includes(s)))
|
|
601
|
+
return null;
|
|
602
|
+
const n = await ct(t, s);
|
|
603
|
+
if (n)
|
|
604
|
+
try {
|
|
605
|
+
return await nt.callFunction({
|
|
606
|
+
code: `
|
|
607
|
+
${n}
|
|
608
|
+
|
|
609
|
+
export function get${s}SchemaWrapper() {
|
|
610
|
+
return ${s};
|
|
611
|
+
}
|
|
612
|
+
`,
|
|
613
|
+
filename: `${e}.js`,
|
|
614
|
+
functionName: `get${s}SchemaWrapper`
|
|
615
|
+
});
|
|
616
|
+
} catch (o) {
|
|
617
|
+
return b.error(`获取 ${s} 失败`, { componentId: e, error: o }), null;
|
|
618
|
+
}
|
|
619
|
+
return null;
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
keyGenerator: (t, s, e) => {
|
|
623
|
+
const n = Ae("md5").update(t).digest("hex");
|
|
624
|
+
return JSON.stringify(["getExportSchemaValueFromCode", n, s, e]);
|
|
625
|
+
},
|
|
626
|
+
lruOptions: {
|
|
627
|
+
max: 100,
|
|
628
|
+
ttl: 1e3 * 60 * 60
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
), Ds = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Qe = "page", Ne = "trigger-reload-project-resource", lt = Ds, xs = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", { uploadToMediaKit: js } = require("@blocklet/uploader-server"), Ce = Xt("abcdefghijklmnopqrstuvwxyz0123456789", 16), Me = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, ae = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, Xe = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, ks = 1e4, Ns = 3e4, de = 0, De = 1, Ls = 0, Rs = 1, Le = I, ue = O(process.env.BLOCKLET_DATA_DIR, "site-state"), _n = ["production", "draft"], Mn = ["production"];
|
|
632
|
+
function Se(t) {
|
|
633
|
+
return (t == null ? void 0 : t.replace(/\//g, "|")) || "";
|
|
634
|
+
}
|
|
635
|
+
function _s() {
|
|
636
|
+
var e;
|
|
637
|
+
const t = Le.env.languages.map((n) => ({ locale: n.code, name: n.name })), s = (e = t[0]) == null ? void 0 : e.locale;
|
|
638
|
+
return {
|
|
639
|
+
pageIds: [],
|
|
640
|
+
pages: {},
|
|
641
|
+
routeIds: [],
|
|
642
|
+
routes: {},
|
|
643
|
+
components: {},
|
|
644
|
+
supportedLocales: t,
|
|
645
|
+
config: { defaultLocale: s },
|
|
646
|
+
resources: {}
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
const H = class H extends $.Doc {
|
|
650
|
+
constructor(e) {
|
|
651
|
+
super();
|
|
652
|
+
j(this, "states", {});
|
|
653
|
+
j(this, "syncedStore");
|
|
654
|
+
j(this, "conns", /* @__PURE__ */ new Map());
|
|
655
|
+
j(this, "awareness");
|
|
656
|
+
j(this, "awarenessChangeHandler", ({ added: e, updated: n, removed: o }, r) => {
|
|
657
|
+
const l = e.concat(n, o);
|
|
658
|
+
if (r !== null) {
|
|
659
|
+
const p = this.conns.get(r);
|
|
660
|
+
p && (e.forEach((u) => {
|
|
661
|
+
p.add(u);
|
|
662
|
+
}), o.forEach((u) => {
|
|
663
|
+
p.delete(u);
|
|
664
|
+
}));
|
|
665
|
+
}
|
|
666
|
+
const i = k.createEncoder();
|
|
667
|
+
k.writeVarUint(i, De), k.writeVarUint8Array(i, ze(this.awareness, l));
|
|
668
|
+
const d = k.toUint8Array(i);
|
|
669
|
+
this.conns.forEach((p, u) => this.send(u, d));
|
|
670
|
+
});
|
|
671
|
+
j(this, "updateHandler", (e) => {
|
|
672
|
+
const n = k.createEncoder();
|
|
673
|
+
k.writeVarUint(n, de), is(n, e);
|
|
674
|
+
const o = k.toUint8Array(n);
|
|
675
|
+
this.conns.forEach((r, l) => this.send(l, o));
|
|
676
|
+
});
|
|
677
|
+
j(this, "ensureDataStructure", () => {
|
|
678
|
+
var l;
|
|
679
|
+
const { supportedLocales: e, pages: n, pageIds: o, config: r } = this.syncedStore;
|
|
680
|
+
{
|
|
681
|
+
const i = new Set(Object.keys(n));
|
|
682
|
+
let d = 0;
|
|
683
|
+
for (; d < o.length; ) {
|
|
684
|
+
const p = o[d];
|
|
685
|
+
i.has(p) ? (i.delete(p), d++) : o.splice(d, 1);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
e.splice(0, e.length), e.push(...Le.env.languages.map((i) => ({ locale: i.code, name: i.name }))), r.defaultLocale = (l = e[0]) == null ? void 0 : l.locale;
|
|
689
|
+
{
|
|
690
|
+
let i = 0;
|
|
691
|
+
const d = /* @__PURE__ */ new Set();
|
|
692
|
+
for (; i < e.length; ) {
|
|
693
|
+
const { locale: p } = e[i];
|
|
694
|
+
d.has(p) ? e.splice(i, 1) : (i++, d.add(p));
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
j(this, "send", (e, n) => {
|
|
699
|
+
e.readyState !== Ls && e.readyState !== Rs && this.closeConn(e);
|
|
700
|
+
try {
|
|
701
|
+
e.send(n, (o) => {
|
|
702
|
+
o && this.closeConn(e);
|
|
703
|
+
});
|
|
704
|
+
} catch {
|
|
705
|
+
this.closeConn(e);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
j(this, "closeConn", (e) => {
|
|
709
|
+
if (e.removeAllListeners(), this.conns.has(e)) {
|
|
710
|
+
const n = this.conns.get(e);
|
|
711
|
+
this.conns.delete(e), n && rs(this.awareness, Array.from(n), null);
|
|
712
|
+
}
|
|
713
|
+
e.close();
|
|
714
|
+
});
|
|
715
|
+
j(this, "autoSave", at(() => {
|
|
716
|
+
G(R(this.draftYjsFilePath), { recursive: !0 }), he(this.draftYjsFilePath, $.encodeStateAsUpdate(this));
|
|
717
|
+
}, ks));
|
|
718
|
+
j(this, "save", ({ flush: e = !1 } = {}) => {
|
|
719
|
+
this.autoSave(), e && this.autoSave.flush();
|
|
720
|
+
});
|
|
721
|
+
j(this, "publish", async ({ mode: e, routes: n }) => {
|
|
722
|
+
var l;
|
|
723
|
+
const o = await this.getState("draft"), r = await this.getState("production");
|
|
724
|
+
await tt(o, r, { routes: n, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), r.config.publishedAt = (/* @__PURE__ */ new Date()).getTime();
|
|
725
|
+
for (const i of n || Object.keys(this.syncedStore.routes || {})) {
|
|
726
|
+
let d = i, p = [];
|
|
727
|
+
if (i.includes("-")) {
|
|
728
|
+
const [u, ...y] = i.split("-");
|
|
729
|
+
d = u, p = y || [];
|
|
730
|
+
}
|
|
731
|
+
if (((l = this.syncedStore.routes) == null ? void 0 : l[d]) !== void 0) {
|
|
732
|
+
this.syncedStore.routes[d].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
733
|
+
const u = this.syncedStore.routes[d];
|
|
734
|
+
if (!u || !u.params || u.params.length === 0)
|
|
735
|
+
continue;
|
|
736
|
+
if (i.includes("-") && p.length > 0) {
|
|
737
|
+
const y = Kt(p, u);
|
|
738
|
+
y && (y.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
739
|
+
}
|
|
740
|
+
if (!n) {
|
|
741
|
+
const y = je({
|
|
742
|
+
basePath: u.path,
|
|
743
|
+
params: u.params,
|
|
744
|
+
routeId: u.id,
|
|
745
|
+
paramsOptions: u.paramsOptions,
|
|
746
|
+
currentIndex: 0,
|
|
747
|
+
currentParams: [],
|
|
748
|
+
currentOptionIds: [],
|
|
749
|
+
result: []
|
|
750
|
+
});
|
|
751
|
+
for (const g of y)
|
|
752
|
+
g.routeMetaData ?? (g.routeMetaData = {}), g.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
await this.setState(e, r);
|
|
757
|
+
});
|
|
758
|
+
j(this, "mergeState", async (e, n) => {
|
|
759
|
+
var i, d, p;
|
|
760
|
+
const o = JSON.parse(JSON.stringify(n));
|
|
761
|
+
(i = e.config).fontFamily ?? (i.fontFamily = {});
|
|
762
|
+
const r = (d = o.config) == null ? void 0 : d.fontFamily, l = (p = e.config) == null ? void 0 : p.fontFamily;
|
|
763
|
+
e.config.fontFamily.title = (r == null ? void 0 : r.title) || (l == null ? void 0 : l.title), e.config.fontFamily.description = (r == null ? void 0 : r.description) || (l == null ? void 0 : l.description), await new Promise((u, y) => {
|
|
764
|
+
this.transact(async () => {
|
|
765
|
+
try {
|
|
766
|
+
const g = await tt(e, n);
|
|
767
|
+
u(g);
|
|
768
|
+
} catch (g) {
|
|
769
|
+
y(g);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
j(this, "addConnection", (e) => {
|
|
775
|
+
if (this.conns.has(e))
|
|
776
|
+
return;
|
|
777
|
+
e.binaryType = "arraybuffer", this.conns.set(e, /* @__PURE__ */ new Set()), e.on("message", (r) => this.messageListener(e, new Uint8Array(r)));
|
|
778
|
+
let n = !0;
|
|
779
|
+
const o = setInterval(() => {
|
|
780
|
+
if (!n)
|
|
781
|
+
this.conns.has(e) && this.closeConn(e), clearInterval(o);
|
|
782
|
+
else if (this.conns.has(e)) {
|
|
783
|
+
n = !1;
|
|
784
|
+
try {
|
|
785
|
+
e.ping();
|
|
786
|
+
} catch {
|
|
787
|
+
this.closeConn(e), clearInterval(o);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}, Ns);
|
|
791
|
+
e.on("close", () => {
|
|
792
|
+
this.closeConn(e), clearInterval(o);
|
|
793
|
+
}), e.on("pong", () => {
|
|
794
|
+
n = !0;
|
|
795
|
+
});
|
|
796
|
+
{
|
|
797
|
+
const r = k.createEncoder();
|
|
798
|
+
k.writeVarUint(r, de), cs(r, this), this.send(e, k.toUint8Array(r));
|
|
799
|
+
const l = this.awareness.getStates();
|
|
800
|
+
if (l.size > 0) {
|
|
801
|
+
const i = k.createEncoder();
|
|
802
|
+
k.writeVarUint(i, De), k.writeVarUint8Array(i, ze(this.awareness, Array.from(l.keys()))), this.send(e, k.toUint8Array(i));
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
j(this, "messageListener", (e, n) => {
|
|
807
|
+
try {
|
|
808
|
+
const o = k.createEncoder(), r = Pe.createDecoder(n), l = Pe.readVarUint(r);
|
|
809
|
+
switch (l) {
|
|
810
|
+
case de:
|
|
811
|
+
k.writeVarUint(o, de), ps(r, o, this, null), k.length(o) > 1 && (this.ensureDataStructure(), this.send(e, k.toUint8Array(o)));
|
|
812
|
+
break;
|
|
813
|
+
case De: {
|
|
814
|
+
as(this.awareness, Pe.readVarUint8Array(r), e);
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
default:
|
|
818
|
+
b.warn(`Unsupported messageType ${l}`);
|
|
819
|
+
}
|
|
820
|
+
} catch (o) {
|
|
821
|
+
b.error(o);
|
|
822
|
+
}
|
|
823
|
+
this.save();
|
|
824
|
+
});
|
|
825
|
+
this.options = e, F(this.draftYjsFilePath) && $.applyUpdate(this, Z(this.draftYjsFilePath)), this.syncedStore = zt(
|
|
826
|
+
Yt(
|
|
827
|
+
{
|
|
828
|
+
pages: {},
|
|
829
|
+
pageIds: [],
|
|
830
|
+
components: {},
|
|
831
|
+
supportedLocales: [],
|
|
832
|
+
config: {},
|
|
833
|
+
resources: {},
|
|
834
|
+
routeIds: [],
|
|
835
|
+
routes: {}
|
|
836
|
+
},
|
|
837
|
+
this
|
|
838
|
+
)
|
|
839
|
+
), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new os(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
|
|
840
|
+
}
|
|
841
|
+
// safe delete project state dir
|
|
842
|
+
static safeDeleteProjectStateDir(e) {
|
|
843
|
+
if (!e)
|
|
844
|
+
throw new Error("Should provide project context");
|
|
845
|
+
try {
|
|
846
|
+
const n = O(ue, e), o = O(ue, `@del-${e}`);
|
|
847
|
+
He(n, o);
|
|
848
|
+
} catch (n) {
|
|
849
|
+
b.error("Failed to safe delete project state dir:", n);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
static get projectIds() {
|
|
853
|
+
return ke("*/", {
|
|
854
|
+
cwd: ue,
|
|
855
|
+
ignore: ["@del-*", "@tmp-*", ".*", "staging", "production", "@backup-*"]
|
|
856
|
+
// Ignore temp directories and hidden files
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
static get allShared() {
|
|
860
|
+
return this.projectIds.map((e) => H.shared(e));
|
|
861
|
+
}
|
|
862
|
+
static shared(e) {
|
|
863
|
+
if (!e)
|
|
864
|
+
throw new Error("Should provide project context");
|
|
865
|
+
let n = this.sharedInstances.get(e);
|
|
866
|
+
return n || (n = new H({
|
|
867
|
+
path: O(ue, e)
|
|
868
|
+
}), this.sharedInstances.set(e, n), n);
|
|
869
|
+
}
|
|
870
|
+
destroy() {
|
|
871
|
+
this.conns.forEach((e, n) => this.closeConn(n)), this.awareness.destroy(), super.destroy();
|
|
872
|
+
}
|
|
873
|
+
initObserver() {
|
|
874
|
+
const e = (r) => {
|
|
875
|
+
r.observeDeep((l) => {
|
|
876
|
+
l.some((i) => i.changes.keys.has("updatedAt") || i.changes.keys.has("publishedAt")) || r.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
|
|
877
|
+
});
|
|
878
|
+
};
|
|
879
|
+
this.syncedStore.pages && Object.keys(this.syncedStore.pages).forEach((r) => {
|
|
880
|
+
const l = Q(this.syncedStore.pages[r]);
|
|
881
|
+
l && l instanceof $.Map && e(l);
|
|
882
|
+
});
|
|
883
|
+
const n = Q(this.syncedStore.pages);
|
|
884
|
+
n && n instanceof $.Map && n.observe((r) => {
|
|
885
|
+
r.changes.keys.forEach((l, i) => {
|
|
886
|
+
if (l.action === "add") {
|
|
887
|
+
const d = Q(this.syncedStore.pages[i]);
|
|
888
|
+
d && d instanceof $.Map && e(d);
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
}), this.syncedStore.routes && Object.keys(this.syncedStore.routes).forEach((r) => {
|
|
892
|
+
var i;
|
|
893
|
+
const l = Q((i = this.syncedStore.routes) == null ? void 0 : i[r]);
|
|
894
|
+
l && l instanceof $.Map && e(l);
|
|
895
|
+
});
|
|
896
|
+
const o = Q(this.syncedStore.routes);
|
|
897
|
+
o && o instanceof $.Map && o.observe((r) => {
|
|
898
|
+
r.changes.keys.forEach((l, i) => {
|
|
899
|
+
var d;
|
|
900
|
+
if (l.action === "add") {
|
|
901
|
+
const p = Q((d = this.syncedStore.routes) == null ? void 0 : d[i]);
|
|
902
|
+
p && p instanceof $.Map && e(p);
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
get draftYjsFilePath() {
|
|
908
|
+
return O(this.options.path, "draft.yjs");
|
|
909
|
+
}
|
|
910
|
+
async getState(e) {
|
|
911
|
+
var n, o, r, l;
|
|
912
|
+
if (e === "draft")
|
|
913
|
+
return JSON.parse(JSON.stringify(this.syncedStore));
|
|
914
|
+
if (!this.states[e] && (this.states[e] = await mt(this.getPublishDir(e), { includeResources: !0 }) ?? _s(), !((o = (n = this.states[e]) == null ? void 0 : n.config) != null && o.defaultLocale))) {
|
|
915
|
+
(r = this.states[e]).config ?? (r.config = {});
|
|
916
|
+
const i = Le.env.languages.map((d) => ({ locale: d.code, name: d.name }));
|
|
917
|
+
this.states[e].config.defaultLocale = (l = i[0]) == null ? void 0 : l.locale;
|
|
918
|
+
}
|
|
919
|
+
return {
|
|
920
|
+
...this.states[e],
|
|
921
|
+
resources: await Be().then(async (i) => {
|
|
922
|
+
var c, a, m, S;
|
|
923
|
+
const { pages: d, components: p } = qt(i, "pages", "components");
|
|
924
|
+
let u = p;
|
|
925
|
+
const y = se(this.options.path), g = await q.findByPk(y);
|
|
926
|
+
if (g != null && g.useAllResources)
|
|
927
|
+
u = p;
|
|
928
|
+
else {
|
|
929
|
+
const A = (await Oe.findAll({ where: { projectId: y } })).map((J) => J.componentId);
|
|
930
|
+
u = Object.fromEntries(
|
|
931
|
+
Object.entries(p || {}).filter(([J]) => A.includes(J))
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
return Object.keys(((a = (c = this.states[e]) == null ? void 0 : c.resources) == null ? void 0 : a.components) || {}).length > 0 && (u = {
|
|
935
|
+
...u,
|
|
936
|
+
...(S = (m = this.states[e]) == null ? void 0 : m.resources) == null ? void 0 : S.components
|
|
937
|
+
}), { pages: d, components: u };
|
|
938
|
+
}).catch(() => ({}))
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
async setState(e, n) {
|
|
942
|
+
const o = await Fs(n, { exportAssets: !1, includeResources: !0 }), r = this.getPublishDir(e);
|
|
943
|
+
G(R(r), { recursive: !0 }), ot(r, { force: !0, recursive: !0 }), He(o, r), this.states[e] = n;
|
|
944
|
+
}
|
|
945
|
+
getPublishDir(e) {
|
|
946
|
+
return O(this.options.path, e);
|
|
947
|
+
}
|
|
948
|
+
static async pageUrlMap(e) {
|
|
949
|
+
var r, l;
|
|
950
|
+
const { projectIds: n } = this, o = {};
|
|
951
|
+
for (const i of n) {
|
|
952
|
+
const d = await q.findByPk(i);
|
|
953
|
+
if (!d) continue;
|
|
954
|
+
const p = await H.shared(i).getState(e), u = d.slug || i, y = Qt(
|
|
955
|
+
I.env.languages.map((c) => c.code),
|
|
956
|
+
p.supportedLocales.map((c) => c.locale)
|
|
957
|
+
), g = (c, a) => {
|
|
958
|
+
u && (o[K("/", u, c)] = {
|
|
959
|
+
...a,
|
|
960
|
+
shouldRedirect: !0,
|
|
961
|
+
mainPage: !0
|
|
962
|
+
}), o[K("/", i, c)] = {
|
|
963
|
+
...a,
|
|
964
|
+
shouldRedirect: !0,
|
|
965
|
+
mainPage: !0
|
|
966
|
+
};
|
|
967
|
+
for (const m of y) {
|
|
968
|
+
const S = { ...a, locale: m };
|
|
969
|
+
o[K("/", m, i, c)] = S, u && (o[K("/", m, u, c)] = S);
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
if (e === "draft")
|
|
973
|
+
for (const c of p.routeIds || []) {
|
|
974
|
+
const a = (r = p == null ? void 0 : p.routes) == null ? void 0 : r[c];
|
|
975
|
+
if (a)
|
|
976
|
+
if (a.params && a.params.length > 0) {
|
|
977
|
+
const m = je({
|
|
978
|
+
basePath: a.path,
|
|
979
|
+
params: a.params,
|
|
980
|
+
routeId: a.id,
|
|
981
|
+
paramsOptions: a.paramsOptions,
|
|
982
|
+
currentIndex: 0,
|
|
983
|
+
currentParams: [],
|
|
984
|
+
currentOptionIds: [],
|
|
985
|
+
result: []
|
|
986
|
+
});
|
|
987
|
+
for (const S of m) {
|
|
988
|
+
const C = S.path, A = {
|
|
989
|
+
projectId: i,
|
|
990
|
+
projectSlug: u,
|
|
991
|
+
pageSlug: C,
|
|
992
|
+
pageId: a.displayTemplateId || "",
|
|
993
|
+
routeId: c,
|
|
994
|
+
// default locale
|
|
995
|
+
defaultLocale: y == null ? void 0 : y[0],
|
|
996
|
+
locales: y,
|
|
997
|
+
publishedAt: p.config.publishedAt,
|
|
998
|
+
isPublic: a.isPublic && ((l = S == null ? void 0 : S.routeMetaData) == null ? void 0 : l.isPublic)
|
|
999
|
+
};
|
|
1000
|
+
g(C, A);
|
|
1001
|
+
}
|
|
1002
|
+
} else {
|
|
1003
|
+
const m = a.path, S = {
|
|
1004
|
+
projectId: i,
|
|
1005
|
+
projectSlug: u,
|
|
1006
|
+
pageSlug: m,
|
|
1007
|
+
pageId: a.displayTemplateId || "",
|
|
1008
|
+
routeId: c,
|
|
1009
|
+
// default locale
|
|
1010
|
+
defaultLocale: y == null ? void 0 : y[0],
|
|
1011
|
+
locales: y,
|
|
1012
|
+
publishedAt: p.config.publishedAt,
|
|
1013
|
+
isPublic: a.isPublic
|
|
1014
|
+
};
|
|
1015
|
+
g(m, S);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
for (const c of p.pageIds) {
|
|
1019
|
+
const a = p.pages[c];
|
|
1020
|
+
if (!a || e === "production" && !a.isPublic)
|
|
1021
|
+
continue;
|
|
1022
|
+
const m = a.slug, S = d.slug || i, C = {
|
|
1023
|
+
projectId: i,
|
|
1024
|
+
projectSlug: S,
|
|
1025
|
+
pageSlug: m,
|
|
1026
|
+
pageId: c,
|
|
1027
|
+
// default locale
|
|
1028
|
+
defaultLocale: y == null ? void 0 : y[0],
|
|
1029
|
+
locales: y,
|
|
1030
|
+
publishedAt: p.config.publishedAt,
|
|
1031
|
+
isPublic: a.isPublic,
|
|
1032
|
+
templateConfig: a.templateConfig
|
|
1033
|
+
};
|
|
1034
|
+
g(m, C);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return o;
|
|
1038
|
+
}
|
|
1039
|
+
getDocumentSize() {
|
|
1040
|
+
return $.encodeStateAsUpdate(this).byteLength;
|
|
1041
|
+
}
|
|
1042
|
+
static getInstancesSizeInfo() {
|
|
1043
|
+
const e = [];
|
|
1044
|
+
for (const [n, o] of this.sharedInstances.entries()) {
|
|
1045
|
+
const r = o.getDocumentSize();
|
|
1046
|
+
e.push({
|
|
1047
|
+
projectId: n,
|
|
1048
|
+
sizeInBytes: r,
|
|
1049
|
+
sizeInMB: `${(r / (1024 * 1024)).toFixed(2)} MB`,
|
|
1050
|
+
activeConnections: o.conns.size
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
return e;
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
j(H, "INSTANCE_TTL", 30 * 60 * 1e3), // 30 minutes
|
|
1057
|
+
j(H, "sharedInstances", new Re({
|
|
1058
|
+
max: 100,
|
|
1059
|
+
// Maximum number of instances to store
|
|
1060
|
+
ttl: H.INSTANCE_TTL,
|
|
1061
|
+
dispose: (e) => {
|
|
1062
|
+
e.destroy();
|
|
1063
|
+
}
|
|
1064
|
+
}));
|
|
1065
|
+
let we = H;
|
|
1066
|
+
function dt() {
|
|
1067
|
+
return Ft(O(I.env.dataDir, "tmp-"));
|
|
1068
|
+
}
|
|
1069
|
+
function be(t, s, e = []) {
|
|
1070
|
+
return Array.isArray(t) ? t.flatMap((n, o) => be(n, s, [...e, o])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([n, o]) => be(o, s, [...e, n])) : s(t) ? [e] : [];
|
|
1071
|
+
}
|
|
1072
|
+
function L(t) {
|
|
1073
|
+
return t.filter((s) => s != null);
|
|
1074
|
+
}
|
|
1075
|
+
async function Ms(t, s, e) {
|
|
1076
|
+
if (!t || !F(t) || !X(t).isFile())
|
|
1077
|
+
return null;
|
|
1078
|
+
let n = e[t];
|
|
1079
|
+
return n || (n = (async () => {
|
|
1080
|
+
var o;
|
|
1081
|
+
try {
|
|
1082
|
+
const r = (o = await js({
|
|
1083
|
+
filePath: t,
|
|
1084
|
+
fileName: s
|
|
1085
|
+
})) == null ? void 0 : o.data;
|
|
1086
|
+
return r == null ? void 0 : r.filename;
|
|
1087
|
+
} catch (r) {
|
|
1088
|
+
return b.error(`Failed to upload asset ${t}:`, r), null;
|
|
1089
|
+
}
|
|
1090
|
+
})(), e[t] = n), n;
|
|
1091
|
+
}
|
|
1092
|
+
const Us = async (t, s) => {
|
|
1093
|
+
const e = se(t), n = await _t({
|
|
1094
|
+
name: lt,
|
|
1095
|
+
path: K("/uploads", e),
|
|
1096
|
+
responseType: "stream",
|
|
1097
|
+
method: "GET"
|
|
1098
|
+
});
|
|
1099
|
+
if (n.status >= 200 && n.status < 400) {
|
|
1100
|
+
const o = Gt(s);
|
|
1101
|
+
await ts(n.data, o);
|
|
1102
|
+
} else
|
|
1103
|
+
throw new Error(`download asset failed ${n.status}`);
|
|
1104
|
+
}, $s = async (t, s) => {
|
|
1105
|
+
await Promise.all(
|
|
1106
|
+
t.map(async (e) => {
|
|
1107
|
+
try {
|
|
1108
|
+
await Us(e, O(s, se(e)));
|
|
1109
|
+
} catch (n) {
|
|
1110
|
+
b.error(`Failed to export assets: ${e}, ${n}`);
|
|
1111
|
+
}
|
|
1112
|
+
})
|
|
1113
|
+
);
|
|
1114
|
+
};
|
|
1115
|
+
function ut(t) {
|
|
1116
|
+
return Me.test(t) ? [t] : ae.test(t) ? (Xe.lastIndex = 0, Array.from(t.matchAll(Xe)).map((e) => e[1]).filter((e) => !!e)) : [];
|
|
1117
|
+
}
|
|
1118
|
+
async function me(t, s, e) {
|
|
1119
|
+
const { getFilename: n, exportAssets: o } = e, r = O(s, n(t));
|
|
1120
|
+
if (G(R(r), { recursive: !0 }), he(r, ee.stringify(t)), o) {
|
|
1121
|
+
const i = be(
|
|
1122
|
+
t,
|
|
1123
|
+
(d) => typeof d == "string" && (Me.test(d) || ae.test(d))
|
|
1124
|
+
).map((d) => {
|
|
1125
|
+
const p = _e(t, d);
|
|
1126
|
+
return ut(p);
|
|
1127
|
+
}).flat().filter(Boolean);
|
|
1128
|
+
await $s(i, R(r));
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
const Ze = new Re({
|
|
1132
|
+
max: 1e3,
|
|
1133
|
+
ttl: 30 * 24 * 60 * 60 * 1e3
|
|
1134
|
+
});
|
|
1135
|
+
async function et(t, s, e) {
|
|
1136
|
+
var i;
|
|
1137
|
+
const n = be(
|
|
1138
|
+
t,
|
|
1139
|
+
(d) => typeof d == "string" && (Me.test(d) || ae.test(d))
|
|
1140
|
+
), o = Zt(2), r = n.map(
|
|
1141
|
+
(d) => o(async () => {
|
|
1142
|
+
try {
|
|
1143
|
+
const p = _e(t, d), u = ut(p);
|
|
1144
|
+
for (const y of u) {
|
|
1145
|
+
const g = se(y), c = e.getFilePath(y, d), a = c ? `${c}:${g}` : g, m = Ze.get(a);
|
|
1146
|
+
if (m) {
|
|
1147
|
+
ae.test(p) || Ke(t, d, m);
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
const S = await Ms(c, g, s);
|
|
1151
|
+
S && (ae.test(p) || Ke(t, d, S), Ze.set(a, S));
|
|
1152
|
+
}
|
|
1153
|
+
} catch (p) {
|
|
1154
|
+
b.error(`Failed to process upload for path ${d.join(".")}:`, p.message || p.reason);
|
|
1155
|
+
}
|
|
1156
|
+
})
|
|
1157
|
+
), l = await Promise.allSettled(r);
|
|
1158
|
+
(i = e.onFinish) == null || i.call(e, l);
|
|
1159
|
+
}
|
|
1160
|
+
async function Fs(t, {
|
|
1161
|
+
exportAssets: s,
|
|
1162
|
+
pageIds: e = "all",
|
|
1163
|
+
componentIds: n = "all",
|
|
1164
|
+
rawConfig: o,
|
|
1165
|
+
includeResources: r = !1,
|
|
1166
|
+
routeIds: l = "all"
|
|
1167
|
+
} = {}) {
|
|
1168
|
+
var ne, w, f, E, v, z, P, M, Y, pe, oe, le;
|
|
1169
|
+
const i = e === "all" ? t.pageIds : e, d = At({
|
|
1170
|
+
state: t,
|
|
1171
|
+
pageIds: i,
|
|
1172
|
+
componentIds: n === "all" ? Object.keys(t.components) : n
|
|
1173
|
+
}), p = l === "all" ? t.routeIds : l, u = (h, T) => {
|
|
1174
|
+
var D;
|
|
1175
|
+
return {
|
|
1176
|
+
id: h.id,
|
|
1177
|
+
name: h.name,
|
|
1178
|
+
isTemplateSection: h.isTemplateSection ?? !1,
|
|
1179
|
+
templateDescription: h.templateDescription,
|
|
1180
|
+
llmConfig: h.llmConfig,
|
|
1181
|
+
component: h.component,
|
|
1182
|
+
config: h.config,
|
|
1183
|
+
visibility: h.visibility,
|
|
1184
|
+
properties: ((D = h.locales) == null ? void 0 : D[T]) ?? {}
|
|
1185
|
+
};
|
|
1186
|
+
}, y = (h, T) => {
|
|
1187
|
+
var D;
|
|
1188
|
+
return {
|
|
1189
|
+
id: h.id,
|
|
1190
|
+
createdAt: h.createdAt,
|
|
1191
|
+
updatedAt: h.updatedAt,
|
|
1192
|
+
publishedAt: h.publishedAt,
|
|
1193
|
+
isPublic: h.isPublic ?? !0,
|
|
1194
|
+
templateConfig: h.templateConfig,
|
|
1195
|
+
meta: ((D = h.locales) == null ? void 0 : D[T]) ?? {},
|
|
1196
|
+
sections: L(
|
|
1197
|
+
h.sectionIds.map((V) => {
|
|
1198
|
+
const B = h.sections[V];
|
|
1199
|
+
return B && u(B, T);
|
|
1200
|
+
})
|
|
1201
|
+
)
|
|
1202
|
+
};
|
|
1203
|
+
}, g = (h) => ({
|
|
1204
|
+
id: h.id,
|
|
1205
|
+
createdAt: h.createdAt,
|
|
1206
|
+
updatedAt: h.updatedAt,
|
|
1207
|
+
publishedAt: h.publishedAt,
|
|
1208
|
+
path: h.path,
|
|
1209
|
+
handler: h.handler,
|
|
1210
|
+
isPublic: h.isPublic ?? !0,
|
|
1211
|
+
params: h.params ?? [],
|
|
1212
|
+
enabledGenerate: h.enabledGenerate ?? !1,
|
|
1213
|
+
displayTemplateId: h.displayTemplateId,
|
|
1214
|
+
dataSource: h.dataSource
|
|
1215
|
+
}), c = L(
|
|
1216
|
+
p.map((h) => {
|
|
1217
|
+
const T = t.routes[h];
|
|
1218
|
+
return T && g(T);
|
|
1219
|
+
})
|
|
1220
|
+
), a = L(
|
|
1221
|
+
t.supportedLocales.map((h) => h.locale).flatMap(
|
|
1222
|
+
(h) => i.map((T) => {
|
|
1223
|
+
const D = t.pages[T];
|
|
1224
|
+
return D && {
|
|
1225
|
+
locale: h,
|
|
1226
|
+
slug: D.slug,
|
|
1227
|
+
page: y(D, h)
|
|
1228
|
+
};
|
|
1229
|
+
})
|
|
1230
|
+
)
|
|
1231
|
+
), m = dt(), S = O(m, "pages");
|
|
1232
|
+
G(S, { recursive: !0 });
|
|
1233
|
+
const C = O(m, "components");
|
|
1234
|
+
G(C, { recursive: !0 });
|
|
1235
|
+
const A = O(m, "routes");
|
|
1236
|
+
G(A, { recursive: !0 });
|
|
1237
|
+
for (const { locale: h, slug: T, page: D } of a)
|
|
1238
|
+
await me(D, S, {
|
|
1239
|
+
getFilename: () => `${Se(T) || "index"}.${h}.yml`,
|
|
1240
|
+
exportAssets: s
|
|
1241
|
+
});
|
|
1242
|
+
for (const h of c)
|
|
1243
|
+
await me(h, A, {
|
|
1244
|
+
// getFilename: () => `${sanitizeSlug(route.path)}.yml`,
|
|
1245
|
+
getFilename: () => `${Se(h.path) || "index"}.yml`,
|
|
1246
|
+
exportAssets: s
|
|
1247
|
+
});
|
|
1248
|
+
for (const h of d) {
|
|
1249
|
+
const T = (ne = t.components[h]) == null ? void 0 : ne.data;
|
|
1250
|
+
T && await me(T, C, {
|
|
1251
|
+
getFilename: (D) => `${D.name || "unnamed"}.${D.id}.yml`,
|
|
1252
|
+
exportAssets: s
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
const _ = O(m, ".blocklet/pages/pages.config.yml");
|
|
1256
|
+
G(R(_), { recursive: !0 });
|
|
1257
|
+
const J = {
|
|
1258
|
+
pages: L(
|
|
1259
|
+
i.map((h) => {
|
|
1260
|
+
const T = t.pages[h];
|
|
1261
|
+
return T && { id: h, slug: T.slug };
|
|
1262
|
+
})
|
|
1263
|
+
),
|
|
1264
|
+
routes: L(
|
|
1265
|
+
p.map((h) => {
|
|
1266
|
+
const T = t.routes[h];
|
|
1267
|
+
return T && { id: h, path: T.path };
|
|
1268
|
+
})
|
|
1269
|
+
),
|
|
1270
|
+
components: L(
|
|
1271
|
+
d.map((h) => {
|
|
1272
|
+
var D;
|
|
1273
|
+
const T = (D = t.components[h]) == null ? void 0 : D.data;
|
|
1274
|
+
return T && {
|
|
1275
|
+
id: h,
|
|
1276
|
+
name: T.name
|
|
1277
|
+
};
|
|
1278
|
+
})
|
|
1279
|
+
),
|
|
1280
|
+
...r ? {
|
|
1281
|
+
resources: {
|
|
1282
|
+
components: L(
|
|
1283
|
+
Object.keys(((w = t.resources) == null ? void 0 : w.components) || {}).filter((h) => d.includes(h)).map((h) => {
|
|
1284
|
+
var T, D, V, B;
|
|
1285
|
+
return {
|
|
1286
|
+
id: h,
|
|
1287
|
+
name: (B = (V = (D = (T = t.resources) == null ? void 0 : T.components) == null ? void 0 : D[h]) == null ? void 0 : V.component) == null ? void 0 : B.name
|
|
1288
|
+
};
|
|
1289
|
+
})
|
|
1290
|
+
)
|
|
1291
|
+
}
|
|
1292
|
+
} : {},
|
|
1293
|
+
supportedLocales: t.supportedLocales,
|
|
1294
|
+
config: t.config
|
|
1295
|
+
};
|
|
1296
|
+
he(_, ee.stringify(J));
|
|
1297
|
+
const ce = O(m, "config.source.json");
|
|
1298
|
+
if (o && he(ce, JSON.stringify(o)), r) {
|
|
1299
|
+
const h = O(m, "resources"), T = O(h, "components");
|
|
1300
|
+
G(T, { recursive: !0 });
|
|
1301
|
+
for (const B of Object.keys(((f = t == null ? void 0 : t.resources) == null ? void 0 : f.components) ?? {}).filter(
|
|
1302
|
+
(U) => d.includes(U)
|
|
1303
|
+
)) {
|
|
1304
|
+
const U = (z = (v = (E = t.resources) == null ? void 0 : E.components) == null ? void 0 : v[B]) == null ? void 0 : z.component;
|
|
1305
|
+
U && await me(U, T, {
|
|
1306
|
+
getFilename: (W) => `${W.name || "unnamed"}.${W.id}.yml`,
|
|
1307
|
+
exportAssets: s
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
const D = O(m, "chunks");
|
|
1311
|
+
G(D, { recursive: !0 });
|
|
1312
|
+
const { chunks: V } = await Be();
|
|
1313
|
+
for (const B of Object.keys(((P = t == null ? void 0 : t.resources) == null ? void 0 : P.components) ?? {}).filter(
|
|
1314
|
+
(U) => d.includes(U)
|
|
1315
|
+
)) {
|
|
1316
|
+
const U = (pe = (Y = (M = t.resources) == null ? void 0 : M.components) == null ? void 0 : Y[B]) == null ? void 0 : pe.component;
|
|
1317
|
+
if (U && ((oe = U.renderer) == null ? void 0 : oe.type) === "react-component") {
|
|
1318
|
+
const W = ((le = U.renderer) == null ? void 0 : le.chunks) ?? [];
|
|
1319
|
+
if ((W == null ? void 0 : W.length) > 0)
|
|
1320
|
+
for (const Te of W) {
|
|
1321
|
+
const Ge = O(D, Te), ve = V == null ? void 0 : V[Te];
|
|
1322
|
+
try {
|
|
1323
|
+
ve && F(ve) && !F(Ge) && Bt(ve, Ge);
|
|
1324
|
+
} catch (yt) {
|
|
1325
|
+
b.error(`copy chunk ${Te} error`, yt.message);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
return m;
|
|
1332
|
+
}
|
|
1333
|
+
async function mt(t, { importAssets: s, includeResources: e } = {}) {
|
|
1334
|
+
var r, l, i, d;
|
|
1335
|
+
if (!F(t))
|
|
1336
|
+
return null;
|
|
1337
|
+
let n, o = !1;
|
|
1338
|
+
try {
|
|
1339
|
+
X(t).isDirectory() ? n = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, n = dt(), await ss({ file: t, C: n }));
|
|
1340
|
+
const p = ke("**/.blocklet/pages/pages.config.yml", { cwd: n, absolute: !0 }).at(0), u = p && O(R(p), "../../pages"), y = p && O(R(p), "../../components"), g = p && O(R(p), "../../chunks"), c = p && O(R(p), "../../routes");
|
|
1341
|
+
if (!p)
|
|
1342
|
+
return null;
|
|
1343
|
+
const a = ee.parse(Z(p).toString()), m = (w, f, E) => {
|
|
1344
|
+
let v = O(w, `${f}${E ? `.${E}` : ""}.yml`);
|
|
1345
|
+
return (!F(v) || !X(v).isFile()) && (v = O(w, f, `index${E ? `.${E}` : ""}.yml`), !F(v) || !X(v)) ? null : ee.parse(Z(v).toString());
|
|
1346
|
+
}, S = (w, f) => {
|
|
1347
|
+
try {
|
|
1348
|
+
const E = ke(`*.${f}.yml`, { cwd: w, absolute: !0 })[0];
|
|
1349
|
+
return E ? ee.parse(Z(E).toString()) : null;
|
|
1350
|
+
} catch (E) {
|
|
1351
|
+
b.error("parse component error", E);
|
|
1352
|
+
}
|
|
1353
|
+
return null;
|
|
1354
|
+
}, C = (w, f) => {
|
|
1355
|
+
let E = O(w, `${f}.yml`);
|
|
1356
|
+
return (!F(E) || !X(E).isFile()) && (E = O(w, f, "index.yml"), !F(E) || !X(E)) ? null : ee.parse(Z(E).toString());
|
|
1357
|
+
}, A = L(
|
|
1358
|
+
a.pages.map(({ slug: w }) => {
|
|
1359
|
+
var z;
|
|
1360
|
+
const f = L(
|
|
1361
|
+
a.supportedLocales.map(({ locale: P }) => {
|
|
1362
|
+
const M = u ? m(u, Se(w), P) : void 0;
|
|
1363
|
+
if (M)
|
|
1364
|
+
return { locale: P, page: M };
|
|
1365
|
+
const Y = u ? m(u, w, P) : void 0;
|
|
1366
|
+
return Y && { locale: P, page: Y };
|
|
1367
|
+
})
|
|
1368
|
+
), E = (z = f[0]) == null ? void 0 : z.page;
|
|
1369
|
+
if (!E)
|
|
1370
|
+
return null;
|
|
1371
|
+
const v = E.sections.map((P) => {
|
|
1372
|
+
const M = P.id || Ce();
|
|
1373
|
+
return {
|
|
1374
|
+
id: M,
|
|
1375
|
+
component: P.component,
|
|
1376
|
+
config: P.config,
|
|
1377
|
+
name: P.name,
|
|
1378
|
+
isTemplateSection: P.isTemplateSection ?? !1,
|
|
1379
|
+
templateDescription: P.templateDescription,
|
|
1380
|
+
llmConfig: P.llmConfig,
|
|
1381
|
+
visibility: P.visibility,
|
|
1382
|
+
locales: Object.fromEntries(
|
|
1383
|
+
L(
|
|
1384
|
+
f.map(({ locale: Y, page: pe }) => {
|
|
1385
|
+
const oe = pe.sections.find((le) => le.id === M);
|
|
1386
|
+
return oe && [Y, oe.properties];
|
|
1387
|
+
})
|
|
1388
|
+
)
|
|
1389
|
+
)
|
|
1390
|
+
};
|
|
1391
|
+
});
|
|
1392
|
+
return {
|
|
1393
|
+
id: E.id || Ce(),
|
|
1394
|
+
createdAt: E.createdAt,
|
|
1395
|
+
updatedAt: E.updatedAt,
|
|
1396
|
+
publishedAt: E.publishedAt,
|
|
1397
|
+
isPublic: E.isPublic ?? !0,
|
|
1398
|
+
templateConfig: E.templateConfig,
|
|
1399
|
+
slug: w,
|
|
1400
|
+
sections: Object.fromEntries(v.map((P) => [P.id, P])),
|
|
1401
|
+
sectionIds: v.map((P) => P.id),
|
|
1402
|
+
locales: Object.fromEntries(f.map(({ locale: P, page: M }) => [P, M.meta]))
|
|
1403
|
+
};
|
|
1404
|
+
})
|
|
1405
|
+
), _ = L(
|
|
1406
|
+
((r = a == null ? void 0 : a.routes) == null ? void 0 : r.map(({ path: w }) => {
|
|
1407
|
+
const f = c ? C(c, Se(w)) : void 0;
|
|
1408
|
+
return {
|
|
1409
|
+
...f,
|
|
1410
|
+
id: (f == null ? void 0 : f.id) || Ce(),
|
|
1411
|
+
createdAt: (f == null ? void 0 : f.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1412
|
+
updatedAt: (f == null ? void 0 : f.updatedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1413
|
+
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1414
|
+
path: (f == null ? void 0 : f.path) ?? `/${f == null ? void 0 : f.id}`,
|
|
1415
|
+
params: f == null ? void 0 : f.params,
|
|
1416
|
+
handler: (f == null ? void 0 : f.handler) ?? "Pages Kit",
|
|
1417
|
+
isPublic: (f == null ? void 0 : f.isPublic) ?? !0,
|
|
1418
|
+
enabledGenerate: (f == null ? void 0 : f.enabledGenerate) ?? !1,
|
|
1419
|
+
displayTemplateId: (f == null ? void 0 : f.displayTemplateId) ?? void 0,
|
|
1420
|
+
dataSource: (f == null ? void 0 : f.dataSource) ?? {}
|
|
1421
|
+
};
|
|
1422
|
+
})) ?? []
|
|
1423
|
+
), J = y ? L(((l = a.components) == null ? void 0 : l.map(({ id: w }) => S(y, w))) ?? []) : [];
|
|
1424
|
+
if (s) {
|
|
1425
|
+
const w = (...f) => {
|
|
1426
|
+
b.info(`[${o ? se(t) : se(O(t, "../../../../"))}] importAssets:`, ...f);
|
|
1427
|
+
};
|
|
1428
|
+
try {
|
|
1429
|
+
w("wait image-bin api ready"), await ns({
|
|
1430
|
+
resources: [`${Rt(ms)}/api/sdk/uploads`],
|
|
1431
|
+
validateStatus: (v) => v >= 200 && v <= 500
|
|
1432
|
+
}), w("image-bin api is ready");
|
|
1433
|
+
const f = {}, E = {};
|
|
1434
|
+
w("start to upload assets"), await Promise.allSettled([
|
|
1435
|
+
et(J, f, {
|
|
1436
|
+
getFilePath: (v) => y && O(y, v),
|
|
1437
|
+
onFinish: (v) => {
|
|
1438
|
+
w(`upload ${v.length} component assets`);
|
|
1439
|
+
}
|
|
1440
|
+
}),
|
|
1441
|
+
et(A, E, {
|
|
1442
|
+
getFilePath: (v, z) => {
|
|
1443
|
+
const P = _e(A, z.slice(0, 1));
|
|
1444
|
+
return u && O(u, R(P.slug), v);
|
|
1445
|
+
},
|
|
1446
|
+
onFinish: (v) => {
|
|
1447
|
+
w(`upload ${v.length} page assets`);
|
|
1448
|
+
}
|
|
1449
|
+
})
|
|
1450
|
+
]), w("upload assets done"), global.gc && global.gc();
|
|
1451
|
+
} catch (f) {
|
|
1452
|
+
w("Error during asset import:", f);
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
const ce = {};
|
|
1456
|
+
if (e) {
|
|
1457
|
+
const w = p && O(R(p), "../../resources/components"), f = L(
|
|
1458
|
+
((d = (i = a.resources) == null ? void 0 : i.components) == null ? void 0 : d.map(({ id: E }) => S(w, E))) ?? []
|
|
1459
|
+
);
|
|
1460
|
+
f.length > 0 && (ce.components = Object.fromEntries(
|
|
1461
|
+
f.map((E, v) => [E.id, { index: v, component: E }])
|
|
1462
|
+
));
|
|
1463
|
+
}
|
|
1464
|
+
const ne = {};
|
|
1465
|
+
if (g && F(g)) {
|
|
1466
|
+
const w = $t(g);
|
|
1467
|
+
for (const f of w)
|
|
1468
|
+
ne[f] = O(g, f);
|
|
1469
|
+
}
|
|
1470
|
+
return {
|
|
1471
|
+
supportedLocales: a.supportedLocales,
|
|
1472
|
+
pageIds: A.map((w) => w.id),
|
|
1473
|
+
components: Object.fromEntries(J.map((w, f) => [w.id, { index: f, data: w }])),
|
|
1474
|
+
pages: Object.fromEntries(A.map((w) => [w.id, w])),
|
|
1475
|
+
config: a.config || {},
|
|
1476
|
+
resources: ce,
|
|
1477
|
+
chunks: ne,
|
|
1478
|
+
routeIds: _.map((w) => w.id),
|
|
1479
|
+
routes: Object.fromEntries(_.map((w) => [w.id, w]))
|
|
1480
|
+
};
|
|
1481
|
+
} finally {
|
|
1482
|
+
o && n && ot(n, { force: !0, recursive: !0 });
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
function xe({
|
|
1486
|
+
page: t,
|
|
1487
|
+
route: s,
|
|
1488
|
+
state: e,
|
|
1489
|
+
routeId: n,
|
|
1490
|
+
routePathInfo: o
|
|
1491
|
+
}) {
|
|
1492
|
+
var l, i, d, p, u, y, g, c, a;
|
|
1493
|
+
b.info(
|
|
1494
|
+
`Executing datasource data assembly, routeId: ${n}, routePathInfo: ${JSON.stringify(o)}`
|
|
1495
|
+
);
|
|
1496
|
+
const r = {
|
|
1497
|
+
...rt(t),
|
|
1498
|
+
id: n,
|
|
1499
|
+
slug: (o == null ? void 0 : o.path) ?? s.path,
|
|
1500
|
+
createdAt: s.createdAt,
|
|
1501
|
+
updatedAt: ((l = o == null ? void 0 : o.routeMetaData) == null ? void 0 : l.updatedAt) ?? s.updatedAt,
|
|
1502
|
+
publishedAt: ((i = o == null ? void 0 : o.routeMetaData) == null ? void 0 : i.publishedAt) ?? s.publishedAt,
|
|
1503
|
+
isPublic: (((d = o == null ? void 0 : o.routeMetaData) == null ? void 0 : d.isPublic) ?? s.isPublic) && s.isPublic
|
|
1504
|
+
};
|
|
1505
|
+
for (const m of e.supportedLocales) {
|
|
1506
|
+
if (s.dataSource) {
|
|
1507
|
+
let S = s.id;
|
|
1508
|
+
o && (S = o.paramOptionIds.join("-"));
|
|
1509
|
+
const C = ((y = (u = (p = s.dataSource.pathDataMappings) == null ? void 0 : p[S]) == null ? void 0 : u.dataCache) == null ? void 0 : y[m.locale]) ?? ((a = (c = (g = s.dataSource.pathDataMappings) == null ? void 0 : g[S]) == null ? void 0 : c.dataCache) == null ? void 0 : a[e.config.defaultLocale || "en"]);
|
|
1510
|
+
if (!C)
|
|
1511
|
+
continue;
|
|
1512
|
+
Ht(r, e, m.locale, C);
|
|
1513
|
+
}
|
|
1514
|
+
o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
1515
|
+
}
|
|
1516
|
+
return r;
|
|
1517
|
+
}
|
|
1518
|
+
async function tt(t, s, {
|
|
1519
|
+
routes: e,
|
|
1520
|
+
mergeMode: n = "byUpdateTime",
|
|
1521
|
+
deleteRoutes: o = !1,
|
|
1522
|
+
publishMode: r = void 0
|
|
1523
|
+
} = {}) {
|
|
1524
|
+
try {
|
|
1525
|
+
r && Es(r);
|
|
1526
|
+
} catch (g) {
|
|
1527
|
+
b.error("clear preload page cache error", { error: g });
|
|
1528
|
+
}
|
|
1529
|
+
const { pages: l, pageIds: i, routeIds: d, routes: p, supportedLocales: u } = t;
|
|
1530
|
+
if (r === "production") {
|
|
1531
|
+
let g = e ?? [], c = null;
|
|
1532
|
+
for (const a of d ?? []) {
|
|
1533
|
+
const m = p == null ? void 0 : p[a];
|
|
1534
|
+
if (m != null && m.params && (m == null ? void 0 : m.params.length) > 0 && (m != null && m.paramsOptions) && (m == null ? void 0 : m.paramsOptions.length) > 0) {
|
|
1535
|
+
const S = je({
|
|
1536
|
+
basePath: m.path,
|
|
1537
|
+
params: m.params,
|
|
1538
|
+
routeId: m.id,
|
|
1539
|
+
paramsOptions: m.paramsOptions,
|
|
1540
|
+
currentIndex: 0,
|
|
1541
|
+
currentParams: [],
|
|
1542
|
+
currentOptionIds: [],
|
|
1543
|
+
result: []
|
|
1544
|
+
}), C = Object.fromEntries(S.map((A) => [`${a}-${A.paramOptionIds.join("-")}`, A]));
|
|
1545
|
+
c = { ...c || {}, ...C }, e || (g = [...g, ...S.map((A) => `${a}-${A.paramOptionIds.join("-")}`)]);
|
|
1546
|
+
} else e || g.push(a);
|
|
1547
|
+
}
|
|
1548
|
+
b.info("routeIds to be published: ", g);
|
|
1549
|
+
for (const a of g) {
|
|
1550
|
+
let m = a;
|
|
1551
|
+
if (m.includes("-")) {
|
|
1552
|
+
const [A] = m.split("-");
|
|
1553
|
+
m = A;
|
|
1554
|
+
}
|
|
1555
|
+
const S = p == null ? void 0 : p[m];
|
|
1556
|
+
if (!S) {
|
|
1557
|
+
const A = s.pageIds.indexOf(m);
|
|
1558
|
+
A !== -1 && o && (s.pageIds.splice(A, 1), delete s.pages[m]);
|
|
1559
|
+
for (const _ of s.pageIds)
|
|
1560
|
+
_.includes(`${m}-`) && (s.pageIds.splice(s.pageIds.indexOf(_), 1), delete s.pages[_]);
|
|
1561
|
+
b.info("delete main route page", m);
|
|
1562
|
+
continue;
|
|
1563
|
+
}
|
|
1564
|
+
if (a.includes("-") && !(c != null && c[a])) {
|
|
1565
|
+
const A = s.pageIds.indexOf(a);
|
|
1566
|
+
A !== -1 && o && (s.pageIds.splice(A, 1), delete s.pages[a]), b.info("delete page", a);
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
if (!a.includes("-") && S.params && S.params.length > 0 && s.pageIds.includes(a) && o) {
|
|
1570
|
+
const A = s.pageIds.indexOf(a);
|
|
1571
|
+
A !== -1 && (s.pageIds.splice(A, 1), delete s.pages[a]), b.info("delete main route page", a);
|
|
1572
|
+
continue;
|
|
1573
|
+
}
|
|
1574
|
+
if (!S.displayTemplateId) {
|
|
1575
|
+
b.info("no display template", a);
|
|
1576
|
+
continue;
|
|
1577
|
+
}
|
|
1578
|
+
const C = l[S.displayTemplateId];
|
|
1579
|
+
if (!C) {
|
|
1580
|
+
b.info("no template page", a);
|
|
1581
|
+
continue;
|
|
1582
|
+
}
|
|
1583
|
+
if (s.pageIds.includes(a)) {
|
|
1584
|
+
if (b.info("has need update page", a), n === "replace")
|
|
1585
|
+
s.pages[a] = xe({
|
|
1586
|
+
page: C,
|
|
1587
|
+
route: S,
|
|
1588
|
+
state: t,
|
|
1589
|
+
routeId: a,
|
|
1590
|
+
routePathInfo: c == null ? void 0 : c[a]
|
|
1591
|
+
}), b.info("replace page", a);
|
|
1592
|
+
else if (n === "byUpdateTime") {
|
|
1593
|
+
const A = s.pages[S.id];
|
|
1594
|
+
(!A || S.updatedAt && S.updatedAt > A.updatedAt) && (s.pages[a] = xe({
|
|
1595
|
+
page: C,
|
|
1596
|
+
route: S,
|
|
1597
|
+
state: t,
|
|
1598
|
+
routeId: a,
|
|
1599
|
+
routePathInfo: c == null ? void 0 : c[a]
|
|
1600
|
+
}), b.info("replace page by update time", a));
|
|
1601
|
+
}
|
|
1602
|
+
} else
|
|
1603
|
+
(!S.params || S.params.length === 0 || a.includes("-")) && (s.pageIds.push(a), s.pages[a] = xe({
|
|
1604
|
+
page: C,
|
|
1605
|
+
route: S,
|
|
1606
|
+
state: t,
|
|
1607
|
+
routeId: a,
|
|
1608
|
+
routePathInfo: c == null ? void 0 : c[a]
|
|
1609
|
+
}), b.info("add page", a));
|
|
1610
|
+
}
|
|
1611
|
+
if (o && !e)
|
|
1612
|
+
for (const a of s.pageIds)
|
|
1613
|
+
g != null && g.includes(a) || (delete s.pages[a], b.info("delete page", a)), s.pageIds = [...s.pageIds].filter((m) => g == null ? void 0 : g.includes(m));
|
|
1614
|
+
} else {
|
|
1615
|
+
for (const g of i) {
|
|
1616
|
+
const c = l[g];
|
|
1617
|
+
if (c)
|
|
1618
|
+
if (s.pageIds.includes(c.id)) {
|
|
1619
|
+
if (n === "replace")
|
|
1620
|
+
s.pages[c.id] = c;
|
|
1621
|
+
else if (n === "byUpdateTime") {
|
|
1622
|
+
const a = s.pages[c.id];
|
|
1623
|
+
(!a || c.updatedAt && c.updatedAt > a.updatedAt) && (s.pages[c.id] = c);
|
|
1624
|
+
}
|
|
1625
|
+
} else
|
|
1626
|
+
s.pageIds.push(c.id), s.pages[c.id] = c;
|
|
1627
|
+
}
|
|
1628
|
+
for (const g of d) {
|
|
1629
|
+
const c = p[g];
|
|
1630
|
+
if (c)
|
|
1631
|
+
if (s.pageIds.includes(c.id)) {
|
|
1632
|
+
if (n === "replace")
|
|
1633
|
+
s.routes[c.id] = c;
|
|
1634
|
+
else if (n === "byUpdateTime") {
|
|
1635
|
+
const a = s.routes[c.id];
|
|
1636
|
+
(!a || c.updatedAt && c.updatedAt > a.updatedAt) && (s.routes[c.id] = c);
|
|
1637
|
+
}
|
|
1638
|
+
} else
|
|
1639
|
+
s.routeIds.push(c.id), s.routes[c.id] = c;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
if (s.supportedLocales.splice(0, s.supportedLocales.length), s.supportedLocales.push(...rt(u)), o)
|
|
1643
|
+
for (const g of Object.keys(s.components))
|
|
1644
|
+
delete s.components[g];
|
|
1645
|
+
let y = JSON.parse(JSON.stringify(t.components));
|
|
1646
|
+
y = Object.fromEntries(
|
|
1647
|
+
await Promise.all(
|
|
1648
|
+
Object.entries(y).map(async ([g, c]) => {
|
|
1649
|
+
const a = await ft(c == null ? void 0 : c.data);
|
|
1650
|
+
return [
|
|
1651
|
+
g,
|
|
1652
|
+
{
|
|
1653
|
+
...c,
|
|
1654
|
+
data: a
|
|
1655
|
+
}
|
|
1656
|
+
];
|
|
1657
|
+
})
|
|
1658
|
+
)
|
|
1659
|
+
), Object.assign(s.components, y), Object.assign(s.config, JSON.parse(JSON.stringify(t.config))), s.resources.components = JSON.parse(JSON.stringify(t.resources.components || {}));
|
|
1660
|
+
}
|
|
1661
|
+
const ft = Ee(
|
|
1662
|
+
async (t) => {
|
|
1663
|
+
var s;
|
|
1664
|
+
if (!Wt(t == null ? void 0 : t.properties))
|
|
1665
|
+
return t;
|
|
1666
|
+
if (((s = t == null ? void 0 : t.renderer) == null ? void 0 : s.type) === "react-component") {
|
|
1667
|
+
const { script: e } = (t == null ? void 0 : t.renderer) || {};
|
|
1668
|
+
if (e && e.includes("PROPERTIES_SCHEMA"))
|
|
1669
|
+
try {
|
|
1670
|
+
const n = await Cs(e, "PROPERTIES_SCHEMA", t.id);
|
|
1671
|
+
n && n.length > 0 && t && (t.properties = {}, n.forEach((o, r) => {
|
|
1672
|
+
t != null && t.properties && (t.properties[o.id] = {
|
|
1673
|
+
index: r,
|
|
1674
|
+
data: o
|
|
1675
|
+
});
|
|
1676
|
+
}));
|
|
1677
|
+
} catch (n) {
|
|
1678
|
+
b.error("checkPropertiesFromCode error", { componentId: t.id, name: t.name }, { error: n });
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
return t;
|
|
1682
|
+
},
|
|
1683
|
+
{
|
|
1684
|
+
keyGenerator: (t) => {
|
|
1685
|
+
var l;
|
|
1686
|
+
const s = (t == null ? void 0 : t.id) || "", e = (t == null ? void 0 : t.name) || "", n = ((l = t == null ? void 0 : t.renderer) == null ? void 0 : l.type) || "", o = (t == null ? void 0 : t.properties) || {}, r = Ae("md5").update(JSON.stringify(o)).digest("hex");
|
|
1687
|
+
return JSON.stringify(["checkPropertiesFromCode", s, e, n, r]);
|
|
1688
|
+
},
|
|
1689
|
+
lruOptions: {
|
|
1690
|
+
max: 100,
|
|
1691
|
+
ttl: 1e3 * 60 * 60
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
);
|
|
1695
|
+
let Ie, te, Ue, $e, Fe;
|
|
1696
|
+
function gt() {
|
|
1697
|
+
return Ie = (async () => {
|
|
1698
|
+
const t = Lt({
|
|
1699
|
+
types: [
|
|
1700
|
+
{ did: lt, type: Qe },
|
|
1701
|
+
{ did: xs, type: Qe }
|
|
1702
|
+
]
|
|
1703
|
+
});
|
|
1704
|
+
te = (await Promise.all(
|
|
1705
|
+
t.map(async (e) => {
|
|
1706
|
+
const n = e.path ? await mt(e.path, { importAssets: !1 }) : void 0;
|
|
1707
|
+
return n ? { blockletId: e.did, state: n, blockletTitle: e.title } : void 0;
|
|
1708
|
+
})
|
|
1709
|
+
)).filter((e) => !!e), Ue = te.reduce(
|
|
1710
|
+
(e, n) => Object.assign(
|
|
1711
|
+
e,
|
|
1712
|
+
Object.fromEntries(
|
|
1713
|
+
Object.values(n.state.pages).map((o) => o ? [o == null ? void 0 : o.id, { page: o, blockletId: n.blockletId }] : [])
|
|
1714
|
+
)
|
|
1715
|
+
),
|
|
1716
|
+
{}
|
|
1717
|
+
);
|
|
1718
|
+
const s = te.reduce(
|
|
1719
|
+
(e, n) => Object.assign(
|
|
1720
|
+
e,
|
|
1721
|
+
Object.fromEntries(
|
|
1722
|
+
Object.values(n.state.components).map((o) => [o.data.id, { blockletId: n.blockletId, component: o.data }])
|
|
1723
|
+
)
|
|
1724
|
+
),
|
|
1725
|
+
{}
|
|
1726
|
+
);
|
|
1727
|
+
$e = Object.fromEntries(
|
|
1728
|
+
await Promise.all(
|
|
1729
|
+
Object.entries(s).map(async ([e, n]) => {
|
|
1730
|
+
const o = await ft(n.component);
|
|
1731
|
+
return [
|
|
1732
|
+
e,
|
|
1733
|
+
{
|
|
1734
|
+
...n,
|
|
1735
|
+
component: o
|
|
1736
|
+
}
|
|
1737
|
+
];
|
|
1738
|
+
})
|
|
1739
|
+
)
|
|
1740
|
+
), Fe = te.reduce((e, n) => Object.assign(e, n.state.chunks), {});
|
|
1741
|
+
})(), Ie;
|
|
1742
|
+
}
|
|
1743
|
+
function Bs(t) {
|
|
1744
|
+
const s = at(
|
|
1745
|
+
async () => {
|
|
1746
|
+
await gt().catch((e) => {
|
|
1747
|
+
b.error("load resource states error", { error: e });
|
|
1748
|
+
}), await (t == null ? void 0 : t({
|
|
1749
|
+
states: te,
|
|
1750
|
+
pages: Ue,
|
|
1751
|
+
components: $e,
|
|
1752
|
+
chunks: Fe
|
|
1753
|
+
}));
|
|
1754
|
+
},
|
|
1755
|
+
3e3,
|
|
1756
|
+
// 3s
|
|
1757
|
+
{ leading: !1, trailing: !0 }
|
|
1758
|
+
);
|
|
1759
|
+
return s(), I.events.on(I.Events.componentAdded, s), I.events.on(I.Events.componentRemoved, s), I.events.on(I.Events.componentStarted, s), I.events.on(I.Events.componentStopped, s), I.events.on(I.Events.componentUpdated, s), I.events.on(Ne, s), () => {
|
|
1760
|
+
I.events.off(I.Events.componentAdded, s), I.events.off(I.Events.componentRemoved, s), I.events.off(I.Events.componentStarted, s), I.events.off(I.Events.componentStopped, s), I.events.off(I.Events.componentUpdated, s), I.events.off(Ne, s);
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
const ht = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), ge = globalThis;
|
|
1764
|
+
var st;
|
|
1765
|
+
(st = ge[ht]) == null || st.call(ge);
|
|
1766
|
+
ge[ht] = Bs(async ({ pages: t, components: s }) => {
|
|
1767
|
+
const { projectIds: e } = we;
|
|
1768
|
+
b.info(`start update resource states projects(${e.length})`, e), await Promise.race([
|
|
1769
|
+
new Promise((n) => {
|
|
1770
|
+
setTimeout(() => {
|
|
1771
|
+
n({});
|
|
1772
|
+
}, 30 * 1e3);
|
|
1773
|
+
}),
|
|
1774
|
+
Promise.all(
|
|
1775
|
+
e.map(async (n) => {
|
|
1776
|
+
const o = we.shared(n);
|
|
1777
|
+
o.syncedStore.resources.pages = t;
|
|
1778
|
+
const r = await q.findByPk(n);
|
|
1779
|
+
if (r != null && r.useAllResources)
|
|
1780
|
+
o.syncedStore.resources.components = s;
|
|
1781
|
+
else {
|
|
1782
|
+
const i = (await Oe.findAll({ where: { projectId: n } })).map((p) => p.componentId), d = Object.fromEntries(
|
|
1783
|
+
Object.entries(s || {}).filter(([p]) => i.includes(p))
|
|
1784
|
+
);
|
|
1785
|
+
o.syncedStore.resources.components = d;
|
|
1786
|
+
}
|
|
1787
|
+
b.info(`update [${n}] resource states:`, {
|
|
1788
|
+
pages: Object.keys(o.syncedStore.resources.pages || {}).length,
|
|
1789
|
+
components: Object.keys(o.syncedStore.resources.components || {}).length
|
|
1790
|
+
});
|
|
1791
|
+
})
|
|
1792
|
+
)
|
|
1793
|
+
]).catch((n) => {
|
|
1794
|
+
b.error("update resource states failed:", n);
|
|
1795
|
+
});
|
|
1796
|
+
});
|
|
1797
|
+
async function Un() {
|
|
1798
|
+
b.info("trigger reload all project resource"), I.events.emit(Ne);
|
|
1799
|
+
}
|
|
1800
|
+
async function Be({
|
|
1801
|
+
ensureLoaded: t = !0
|
|
1802
|
+
} = {}) {
|
|
1803
|
+
return t && (Ie ?? (Ie = gt()), await Ie), { states: te, pages: Ue, components: $e, chunks: Fe };
|
|
1804
|
+
}
|
|
1805
|
+
export {
|
|
1806
|
+
lt as C,
|
|
1807
|
+
qe as G,
|
|
1808
|
+
q as P,
|
|
1809
|
+
Qe as R,
|
|
1810
|
+
we as S,
|
|
1811
|
+
Nn as a,
|
|
1812
|
+
Be as b,
|
|
1813
|
+
bs as c,
|
|
1814
|
+
Is as d,
|
|
1815
|
+
Es as e,
|
|
1816
|
+
As as f,
|
|
1817
|
+
Ln as g,
|
|
1818
|
+
Os as h,
|
|
1819
|
+
kn as i,
|
|
1820
|
+
ye as j,
|
|
1821
|
+
Rn as k,
|
|
1822
|
+
b as l,
|
|
1823
|
+
Cs as m,
|
|
1824
|
+
Ce as n,
|
|
1825
|
+
ue as o,
|
|
1826
|
+
_n as p,
|
|
1827
|
+
Mn as q,
|
|
1828
|
+
mt as r,
|
|
1829
|
+
tt as s,
|
|
1830
|
+
Fs as t,
|
|
1831
|
+
Bs as u,
|
|
1832
|
+
Un as v
|
|
1833
|
+
};
|