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