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