@blocklet/pages-kit-inner-components 0.6.3 → 0.6.5
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 +420 -1
- package/lib/cjs/chunks/draft-data-D44_IEV2.js +1 -0
- package/lib/cjs/chunks/home-BYk01EUy.js +39 -0
- package/lib/cjs/chunks/index-BRgYwvuv.js +475 -0
- package/lib/cjs/chunks/publish-button-C8XPA4g_.js +1 -0
- package/lib/cjs/chunks/session-BRtsDvA-.js +1 -0
- package/lib/cjs/chunks/site-state-BlQzwACl.js +57 -0
- package/lib/cjs/chunks/state-B6BF5wJ-.js +1 -0
- package/lib/cjs/components.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/locales.js +3 -0
- package/lib/cjs/project-html.js +4 -4
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +11 -0
- package/lib/cjs/site-state.js +1 -0
- package/lib/cjs/theme.js +1 -0
- package/lib/cjs/uploader.js +1 -0
- package/lib/es/add-component.js +1089 -2
- package/lib/es/chunks/{draft-data-bRUHvvzp.js → draft-data-CafrGKeh.js} +4 -5
- package/lib/es/chunks/home-DW8SdyfO.js +594 -0
- package/lib/es/chunks/index-D5gXPe_7.js +2326 -0
- package/lib/es/chunks/{publish-button-Ceet-m88.js → publish-button-XSZrDaTQ.js} +140 -158
- package/lib/es/chunks/session-C72Dq8zg.js +19 -0
- package/lib/es/chunks/{site-state-BoVWlYLn.js → site-state-BdLTu3Od.js} +197 -170
- package/lib/es/chunks/state-0gvZF3k2.js +573 -0
- package/lib/es/components.js +24 -0
- package/lib/es/home.js +28 -3
- package/lib/es/locales.js +1032 -0
- package/lib/es/project-html.js +155 -79
- package/lib/es/resources.js +137 -93
- package/lib/es/setting.js +2294 -0
- package/lib/es/site-state.js +48 -0
- package/lib/es/theme.js +484 -0
- package/lib/es/uploader.js +8 -0
- package/package.json +3 -3
- package/lib/cjs/chunks/draft-data-CfIMszE7.js +0 -1
- package/lib/cjs/chunks/home-DUjl5PbP.js +0 -6
- package/lib/cjs/chunks/publish-button-C522nNv6.js +0 -1
- package/lib/cjs/chunks/site-state-BG2d2tBl.js +0 -57
- package/lib/cjs/chunks/state-CtNs8GrN.js +0 -1
- package/lib/es/chunks/home-VWWdvIPQ.js +0 -69
- package/lib/es/chunks/state-BdNIIXJP.js +0 -502
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { getComponentMountPoint as dt } from "@blocklet/pages-kit/builtin/utils";
|
|
2
2
|
import { PreloadComponentScriptModule as Ie } from "@blocklet/pages-kit/types";
|
|
3
|
-
import { componentUMDName as ft, RenderNestedComponent as
|
|
3
|
+
import { componentUMDName as ft, RenderNestedComponent as De, mergeComponent as mt, getComponentDependencies as ht } from "@blocklet/pages-kit/utils/property";
|
|
4
4
|
import { memoize as gt, BuiltinModules as ge } from "@blocklet/quickjs";
|
|
5
5
|
import { BuiltinModules as Ee } from "@blocklet/pages-kit/utils/builtin";
|
|
6
|
-
import
|
|
6
|
+
import I from "@blocklet/sdk/lib/config";
|
|
7
7
|
import { LRUCache as le } from "lru-cache";
|
|
8
8
|
import yt, { Headers as St } from "node-fetch";
|
|
9
|
-
import { joinURL as
|
|
10
|
-
import
|
|
9
|
+
import { joinURL as G, getQuery as wt, withQuery as It, parseURL as Re, withHttps as Et } from "ufo";
|
|
10
|
+
import Ae from "lodash/isEmpty";
|
|
11
11
|
import { createHash as bt } from "crypto";
|
|
12
|
-
import { promises as
|
|
13
|
-
import Ke, { join as P, dirname as
|
|
12
|
+
import { promises as $, readFileSync as J, mkdtempSync as Pt, existsSync as L, lstatSync as V, rmSync as Je, renameSync as je, mkdirSync as F, writeFileSync as oe, copyFileSync as At, readdirSync as Ct, createWriteStream as Ot } from "fs";
|
|
13
|
+
import Ke, { join as P, dirname as x, basename as j } from "path";
|
|
14
14
|
import vt from "lodash/isNil";
|
|
15
15
|
import Tt from "@blocklet/logger";
|
|
16
16
|
import { isRelativeModule as kt, createBuiltinModuleTransformer as Dt } from "@blocklet/pages-kit/utils/typescript/builtin-module-transformer";
|
|
17
|
-
import { getResources as Rt, getComponentWebEndpoint as
|
|
18
|
-
import { getYjsValue as z, syncedStore as
|
|
17
|
+
import { getResources as Rt, getComponentWebEndpoint as jt, call as xt } from "@blocklet/sdk/lib/component";
|
|
18
|
+
import { getYjsValue as z, syncedStore as Mt } from "@syncedstore/core";
|
|
19
19
|
import * as _ from "yjs";
|
|
20
|
-
import { setPageDataSource as
|
|
21
|
-
import { getRouteMetaDataByOptionIds as Lt, generateParamCombinations as
|
|
20
|
+
import { setPageDataSource as $t } from "@blocklet/pages-kit/utils/data-source";
|
|
21
|
+
import { getRouteMetaDataByOptionIds as Lt, generateParamCombinations as Ce } from "@blocklet/pages-kit/utils/route";
|
|
22
22
|
import { cloneDeep as Nt } from "lodash";
|
|
23
23
|
import { nextId as xe } from "@blocklet/pages-kit/utils/common";
|
|
24
24
|
import { unzipSection as _t } from "@blocklet/pages-kit/utils/page-model";
|
|
@@ -28,11 +28,11 @@ import * as ye from "lib0/decoding";
|
|
|
28
28
|
import * as D from "lib0/encoding";
|
|
29
29
|
import Ft from "lodash/cloneDeep";
|
|
30
30
|
import ze from "lodash/debounce";
|
|
31
|
-
import
|
|
32
|
-
import
|
|
31
|
+
import Oe from "lodash/get";
|
|
32
|
+
import Me from "lodash/set";
|
|
33
33
|
import Bt from "lodash/union";
|
|
34
|
-
import
|
|
35
|
-
import { DataTypes as k, Sequelize as
|
|
34
|
+
import Gt from "p-limit";
|
|
35
|
+
import { DataTypes as k, Sequelize as Vt, Model as He, Op as We } from "sequelize";
|
|
36
36
|
import { pipeline as Jt } from "stream/promises";
|
|
37
37
|
import { x as Kt } from "tar";
|
|
38
38
|
import zt from "wait-on";
|
|
@@ -41,16 +41,16 @@ import { writeUpdate as qt, writeSyncStep1 as Qt, readSyncMessage as Xt } from "
|
|
|
41
41
|
import * as K from "yaml";
|
|
42
42
|
import "sqlite3";
|
|
43
43
|
import "@blocklet/pages-kit/types/state";
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
I.env.mode;
|
|
45
|
+
I.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY;
|
|
46
|
+
I.env.OPENAI_BASE_URL || process.env.OPENAI_BASE_URL;
|
|
47
|
+
I.env.TRANSLATE_ADDITIONAL_PROMPT || process.env.TRANSLATE_ADDITIONAL_PROMPT;
|
|
48
|
+
I.env.PAGE_CONTENT_ADDITIONAL_PROMPT || process.env.PAGE_CONTENT_ADDITIONAL_PROMPT;
|
|
49
49
|
const Zt = "image-bin";
|
|
50
|
-
|
|
51
|
-
const Ye = process.env.DATABASE_URL || Ke.join(
|
|
50
|
+
I.env.INIT_TEMPLATE_PATH;
|
|
51
|
+
const Ye = process.env.DATABASE_URL || Ke.join(I.env.dataDir, "db/pages-kit.db"), Le = I, Ns = () => I.env.tenantMode === "multiple", _s = () => (vt(Le.env.preferences.multiTenantAllProjectAccessPassports) ? [] : Le.env.preferences.multiTenantAllProjectAccessPassports?.split(",")) || [], eo = Ke.join(I.env.dataDir, "fs-memoize-cache"), to = I.env.FS_MEMOIZE_CACHE_VERSION || "v1.0.0", f = Tt("pages-kit"), oo = k.sqlite.DATE.parse;
|
|
52
52
|
k.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : oo(t, e);
|
|
53
|
-
const U = new
|
|
53
|
+
const U = new Vt({
|
|
54
54
|
dialect: "sqlite",
|
|
55
55
|
storage: Ye,
|
|
56
56
|
benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
|
|
@@ -95,10 +95,10 @@ setInterval(
|
|
|
95
95
|
60 * 1e3 * 10
|
|
96
96
|
// 10 minutes
|
|
97
97
|
);
|
|
98
|
-
class
|
|
98
|
+
class ve extends He {
|
|
99
99
|
// Foreign key to Component
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
ve.init(
|
|
102
102
|
{
|
|
103
103
|
id: {
|
|
104
104
|
type: k.UUID,
|
|
@@ -200,36 +200,36 @@ N.init(
|
|
|
200
200
|
},
|
|
201
201
|
{ sequelize: U, paranoid: !0 }
|
|
202
202
|
);
|
|
203
|
-
N.hasMany(
|
|
203
|
+
N.hasMany(ve, {
|
|
204
204
|
foreignKey: "projectId",
|
|
205
205
|
as: "components"
|
|
206
206
|
});
|
|
207
207
|
const no = eo, ro = to, ne = 30 * 24 * 60 * 60 * 1e3, ao = 24 * 60 * 60 * 1e3, qe = async (t = "") => {
|
|
208
208
|
const e = P(no, t);
|
|
209
209
|
try {
|
|
210
|
-
if (!(await
|
|
210
|
+
if (!(await $.stat(e)).isDirectory())
|
|
211
211
|
throw new Error(`${e} is not a directory`);
|
|
212
212
|
} catch {
|
|
213
|
-
await
|
|
213
|
+
await $.mkdir(e, { recursive: !0 });
|
|
214
214
|
}
|
|
215
215
|
return e;
|
|
216
|
-
},
|
|
216
|
+
}, Ne = (t, ...e) => t.keyGenerator ? t.keyGenerator(...e) : JSON.stringify([t.subdir || "", ...e]), io = (t, e) => {
|
|
217
217
|
const o = bt("md5").update(e).digest("hex");
|
|
218
218
|
return P(t, `${ro}-${o}.json`);
|
|
219
219
|
}, co = async (t = "") => {
|
|
220
220
|
const e = await qe(t), o = Date.now();
|
|
221
221
|
try {
|
|
222
|
-
const s = await
|
|
222
|
+
const s = await $.readdir(e);
|
|
223
223
|
await Promise.all(
|
|
224
224
|
s.filter((n) => n.endsWith(".json")).map(async (n) => {
|
|
225
225
|
const r = P(e, n);
|
|
226
226
|
try {
|
|
227
|
-
const c = await
|
|
228
|
-
a.createdAt && o - a.createdAt > ne && await
|
|
227
|
+
const c = await $.readFile(r, "utf-8"), a = JSON.parse(c);
|
|
228
|
+
a.createdAt && o - a.createdAt > ne && await $.unlink(r);
|
|
229
229
|
} catch {
|
|
230
230
|
try {
|
|
231
|
-
const a = await
|
|
232
|
-
o - a.mtimeMs > ne && await
|
|
231
|
+
const a = await $.stat(r);
|
|
232
|
+
o - a.mtimeMs > ne && await $.unlink(r);
|
|
233
233
|
} catch {
|
|
234
234
|
}
|
|
235
235
|
}
|
|
@@ -249,22 +249,22 @@ const no = eo, ro = to, ne = 30 * 24 * 60 * 60 * 1e3, ao = 24 * 60 * 60 * 1e3, q
|
|
|
249
249
|
function ue(t, e) {
|
|
250
250
|
return e.subdir && po(e.subdir), gt(
|
|
251
251
|
async (...s) => {
|
|
252
|
-
const n = await qe(e.subdir || ""), r =
|
|
252
|
+
const n = await qe(e.subdir || ""), r = Ne(e, ...s), c = io(n, r);
|
|
253
253
|
try {
|
|
254
|
-
const a = await
|
|
254
|
+
const a = await $.readFile(c, "utf-8"), { value: l, createdAt: d } = JSON.parse(a);
|
|
255
255
|
if (d && Date.now() - d > ne)
|
|
256
|
-
throw await
|
|
256
|
+
throw await $.unlink(c).catch(() => {
|
|
257
257
|
}), new Error("Cache expired");
|
|
258
258
|
return l;
|
|
259
259
|
} catch {
|
|
260
260
|
const l = await t(...s), d = JSON.stringify({ value: l, createdAt: Date.now() });
|
|
261
|
-
return
|
|
262
|
-
console.error("Failed to write fs cache:",
|
|
261
|
+
return $.writeFile(c, d, "utf-8").catch((E) => {
|
|
262
|
+
console.error("Failed to write fs cache:", E);
|
|
263
263
|
}), l;
|
|
264
264
|
}
|
|
265
265
|
},
|
|
266
266
|
{
|
|
267
|
-
keyGenerator: (...s) =>
|
|
267
|
+
keyGenerator: (...s) => Ne(e, ...s),
|
|
268
268
|
lruOptions: e.lruOptions || {
|
|
269
269
|
max: 100,
|
|
270
270
|
ttl: ne
|
|
@@ -284,7 +284,7 @@ const Qe = async () => await import("typescript"), lo = async () => await import
|
|
|
284
284
|
}),
|
|
285
285
|
(l) => {
|
|
286
286
|
l.walkRules((d) => {
|
|
287
|
-
d.selectors = d.selectors.map((
|
|
287
|
+
d.selectors = d.selectors.map((E) => E.replace(/\.(.+)/g, `${s}.$1,${s} .$1`));
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
// FIXME: cssnano use browserslist, it is not working with the fs isolation
|
|
@@ -296,7 +296,7 @@ const Qe = async () => await import("typescript"), lo = async () => await import
|
|
|
296
296
|
|
|
297
297
|
${t}
|
|
298
298
|
`;
|
|
299
|
-
},
|
|
299
|
+
}, _e = ue(
|
|
300
300
|
async (t, e) => {
|
|
301
301
|
const o = await Qe();
|
|
302
302
|
let s = o.transpileModule(t, {
|
|
@@ -336,13 +336,13 @@ ${t}
|
|
|
336
336
|
name: "vfs",
|
|
337
337
|
setup(l) {
|
|
338
338
|
let d = null;
|
|
339
|
-
l.onResolve({ filter: /.*/ }, (
|
|
340
|
-
if (
|
|
339
|
+
l.onResolve({ filter: /.*/ }, (E) => E.path === "index.tsx" ? { path: "index.tsx", namespace: "vfs" } : E.path === "./component" ? { path: "component.tsx", namespace: "vfs" } : null), l.onLoad({ filter: /.*/, namespace: "vfs" }, async (E) => {
|
|
340
|
+
if (E.path === "index.tsx")
|
|
341
341
|
return { contents: `export { ${e} } from './component'`, loader: "tsx" };
|
|
342
|
-
if (
|
|
342
|
+
if (E.path === "component.tsx")
|
|
343
343
|
return { contents: t, loader: "tsx" };
|
|
344
|
-
if (kt(
|
|
345
|
-
const h =
|
|
344
|
+
if (kt(E.path)) {
|
|
345
|
+
const h = E.path.split("/").pop();
|
|
346
346
|
if (d || (d = await Qo({ ensureLoaded: !1 })), d?.chunks?.[h])
|
|
347
347
|
try {
|
|
348
348
|
const S = J(d.chunks[h], "utf-8");
|
|
@@ -409,7 +409,7 @@ const q = new le({
|
|
|
409
409
|
max: 100,
|
|
410
410
|
ttl: 1e3 * 60 * 60 * 24
|
|
411
411
|
// 24 hours
|
|
412
|
-
}), Eo = 60 * 60,
|
|
412
|
+
}), Eo = 60 * 60, Ue = 10;
|
|
413
413
|
function bo(t) {
|
|
414
414
|
f.info("clear preload components cache", { cacheKey: t }), q.delete(t);
|
|
415
415
|
}
|
|
@@ -475,19 +475,19 @@ async function Us({
|
|
|
475
475
|
)).filter((p) => !!p), d = Object.values(
|
|
476
476
|
l.reduce((p, i) => ({ ...p, ...i.preload.components }), {})
|
|
477
477
|
);
|
|
478
|
-
async function
|
|
478
|
+
async function E() {
|
|
479
479
|
const p = await Promise.all(
|
|
480
480
|
d.map(async (i) => {
|
|
481
481
|
const y = ft({ componentId: i.component.id }), A = r === Ie.ESM ? {
|
|
482
482
|
module: r,
|
|
483
|
-
script: await
|
|
483
|
+
script: await _e(i.script, {
|
|
484
484
|
componentId: i.component.id,
|
|
485
485
|
module: r,
|
|
486
486
|
tailwind: t !== "draft"
|
|
487
487
|
})
|
|
488
488
|
} : {
|
|
489
489
|
module: r,
|
|
490
|
-
script: await
|
|
490
|
+
script: await _e(i.script, {
|
|
491
491
|
componentId: i.component.id,
|
|
492
492
|
module: r,
|
|
493
493
|
moduleName: y,
|
|
@@ -500,7 +500,7 @@ async function Us({
|
|
|
500
500
|
);
|
|
501
501
|
return Object.fromEntries(p);
|
|
502
502
|
}
|
|
503
|
-
const h = await
|
|
503
|
+
const h = await E();
|
|
504
504
|
return {
|
|
505
505
|
config: { defaultLocale: a, supportedLocales: c },
|
|
506
506
|
components: h,
|
|
@@ -521,7 +521,7 @@ async function Co({
|
|
|
521
521
|
}) {
|
|
522
522
|
const { supportedLocales: c } = e, a = re({ state: e, componentId: o });
|
|
523
523
|
if (!a) return null;
|
|
524
|
-
const l = c.some((
|
|
524
|
+
const l = c.some((E) => E.locale === s) ? s : n;
|
|
525
525
|
if (!l) return null;
|
|
526
526
|
const d = await et({ req: t, state: e, componentId: o, locale: l, defaultLocale: n, properties: r });
|
|
527
527
|
return d ? {
|
|
@@ -542,20 +542,20 @@ async function et({
|
|
|
542
542
|
if (e > Oo) throw new RangeError("max component depth exceeded");
|
|
543
543
|
const a = vo({ state: o, componentId: s, properties: c, locale: n });
|
|
544
544
|
if (!a) return null;
|
|
545
|
-
const { props: l, component: d } = a,
|
|
545
|
+
const { props: l, component: d } = a, E = {
|
|
546
546
|
locale: n || r,
|
|
547
547
|
components: { [a.component.id]: { component: a.component, script: a.script } },
|
|
548
548
|
props: { ...l }
|
|
549
549
|
};
|
|
550
550
|
try {
|
|
551
551
|
const h = Io(d.renderer) ? d.renderer.getServerSideProps : void 0, S = await To({ ...a, req: t, serverSideProps: h });
|
|
552
|
-
S?.props && Object.assign(
|
|
552
|
+
S?.props && Object.assign(E.props, S.props);
|
|
553
553
|
} catch (h) {
|
|
554
554
|
f.error("preload data at server side error", { componentId: s, name: a.component.name }, { error: h });
|
|
555
555
|
}
|
|
556
556
|
return await Promise.all(
|
|
557
557
|
Object.entries(l).map(async ([h, S]) => {
|
|
558
|
-
if (S?.type ===
|
|
558
|
+
if (S?.type === De) {
|
|
559
559
|
const p = await et({
|
|
560
560
|
req: t,
|
|
561
561
|
depth: e + 1,
|
|
@@ -565,16 +565,16 @@ async function et({
|
|
|
565
565
|
defaultLocale: r,
|
|
566
566
|
properties: S.properties
|
|
567
567
|
});
|
|
568
|
-
p && (Object.assign(
|
|
568
|
+
p && (Object.assign(E.components, p.components), Object.assign(E.props, {
|
|
569
569
|
[h]: {
|
|
570
|
-
type:
|
|
570
|
+
type: De,
|
|
571
571
|
componentId: S.componentId,
|
|
572
572
|
props: p.props
|
|
573
573
|
}
|
|
574
574
|
}));
|
|
575
575
|
}
|
|
576
576
|
})
|
|
577
|
-
),
|
|
577
|
+
), E;
|
|
578
578
|
}
|
|
579
579
|
function vo({
|
|
580
580
|
state: t,
|
|
@@ -596,6 +596,10 @@ function vo({
|
|
|
596
596
|
function re({ state: t, componentId: e }) {
|
|
597
597
|
return t.components[e]?.data ?? t.resources.components?.[e]?.component;
|
|
598
598
|
}
|
|
599
|
+
function Fs({ state: t, name: e }) {
|
|
600
|
+
const o = e.toLowerCase();
|
|
601
|
+
return Object.values(t.components).find((s) => s.data.name?.toLowerCase() === o)?.data ?? (t.resources.components && Object.values(t.resources.components).find((s) => s.component.name?.toLowerCase() === o))?.component;
|
|
602
|
+
}
|
|
599
603
|
async function To({
|
|
600
604
|
component: t,
|
|
601
605
|
script: e,
|
|
@@ -610,7 +614,7 @@ async function To({
|
|
|
610
614
|
const a = (r.match(/export\s*{\s*(\w+)\s+as\s+getServerSideProps\s*}/) || r.match(/export\s*{\s*getServerSideProps\s*}/))?.[1] || "getServerSideProps", l = new Promise((h) => {
|
|
611
615
|
setTimeout(() => {
|
|
612
616
|
h({});
|
|
613
|
-
},
|
|
617
|
+
}, Ue * 1e3);
|
|
614
618
|
}), d = await Ze();
|
|
615
619
|
return await Promise.race([
|
|
616
620
|
l,
|
|
@@ -645,7 +649,7 @@ export async function getServerSidePropsWrapper(props) {
|
|
|
645
649
|
return ge[h];
|
|
646
650
|
if (h in Ee) {
|
|
647
651
|
const S = Ee[h];
|
|
648
|
-
return
|
|
652
|
+
return Ae(S) ? void 0 : S;
|
|
649
653
|
}
|
|
650
654
|
},
|
|
651
655
|
global: {
|
|
@@ -663,7 +667,7 @@ export async function getServerSidePropsWrapper(props) {
|
|
|
663
667
|
}
|
|
664
668
|
},
|
|
665
669
|
getComponentMountPoint: dt,
|
|
666
|
-
joinURL:
|
|
670
|
+
joinURL: G,
|
|
667
671
|
withQuery: It,
|
|
668
672
|
getQuery: wt
|
|
669
673
|
},
|
|
@@ -672,10 +676,10 @@ export async function getServerSidePropsWrapper(props) {
|
|
|
672
676
|
{
|
|
673
677
|
// NOTE: IMPORTANT! place location and fetch (has side effect) at the args not global
|
|
674
678
|
// because the global is shared between all runtime and just init once
|
|
675
|
-
location: { href:
|
|
679
|
+
location: { href: G(Et(s.hostname), s.originalUrl) },
|
|
676
680
|
fetch: (h, { ...S } = {}) => {
|
|
677
|
-
const p = typeof h == "string" && h.startsWith("/") ?
|
|
678
|
-
if (typeof p == "string" &&
|
|
681
|
+
const p = typeof h == "string" && h.startsWith("/") ? G(I.env.appUrl, h) : h;
|
|
682
|
+
if (typeof p == "string" && Re(p).host === Re(I.env.appUrl).host) {
|
|
679
683
|
const i = s.get("cookie");
|
|
680
684
|
if (i) {
|
|
681
685
|
const y = new St(S.headers);
|
|
@@ -684,7 +688,7 @@ export async function getServerSidePropsWrapper(props) {
|
|
|
684
688
|
}
|
|
685
689
|
return yt(p, {
|
|
686
690
|
...S,
|
|
687
|
-
timeout:
|
|
691
|
+
timeout: Ue * 1e3
|
|
688
692
|
}).then((i) => ({
|
|
689
693
|
ok: i.ok,
|
|
690
694
|
status: i.status,
|
|
@@ -725,14 +729,14 @@ const ko = ue(
|
|
|
725
729
|
{
|
|
726
730
|
subdir: "getExportSchemaValueFromCode"
|
|
727
731
|
}
|
|
728
|
-
), Do = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o",
|
|
732
|
+
), Bs = (t) => !!(t.version && t.version >= 2), Do = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Fe = "page", be = "trigger-reload-project-resource", tt = Do, Ro = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM";
|
|
729
733
|
function ae(t) {
|
|
730
734
|
t.observeDeep((e) => {
|
|
731
735
|
e.some((o) => o.changes.keys.has("updatedAt") || o.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
|
|
732
736
|
});
|
|
733
737
|
}
|
|
734
738
|
function ot() {
|
|
735
|
-
return Pt(P(
|
|
739
|
+
return Pt(P(I.env.dataDir, "tmp-"));
|
|
736
740
|
}
|
|
737
741
|
function ie(t, e, o = []) {
|
|
738
742
|
return Array.isArray(t) ? t.flatMap((s, n) => ie(s, e, [...o, n])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([s, n]) => ie(n, e, [...o, s])) : e(t) ? [o] : [];
|
|
@@ -740,7 +744,7 @@ function ie(t, e, o = []) {
|
|
|
740
744
|
function R(t) {
|
|
741
745
|
return t.filter((e) => e != null);
|
|
742
746
|
}
|
|
743
|
-
function
|
|
747
|
+
function jo(t) {
|
|
744
748
|
t.pages && Object.keys(t.pages).forEach((o) => {
|
|
745
749
|
const s = z(t.pages[o]);
|
|
746
750
|
s && s instanceof _.Map && ae(s);
|
|
@@ -755,7 +759,7 @@ function xo(t) {
|
|
|
755
759
|
});
|
|
756
760
|
});
|
|
757
761
|
}
|
|
758
|
-
function
|
|
762
|
+
function xo(t) {
|
|
759
763
|
t.routes && Object.keys(t.routes).forEach((o) => {
|
|
760
764
|
const s = z(t.routes?.[o]);
|
|
761
765
|
s && s instanceof _.Map && ae(s);
|
|
@@ -770,7 +774,7 @@ function jo(t) {
|
|
|
770
774
|
});
|
|
771
775
|
});
|
|
772
776
|
}
|
|
773
|
-
function
|
|
777
|
+
function Mo(t, e) {
|
|
774
778
|
for (const o of e || Object.keys(t.routes || {})) {
|
|
775
779
|
let s = o, n = [];
|
|
776
780
|
if (o.includes("-")) {
|
|
@@ -787,7 +791,7 @@ function $o(t, e) {
|
|
|
787
791
|
c && (c.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
788
792
|
}
|
|
789
793
|
if (!e) {
|
|
790
|
-
const c =
|
|
794
|
+
const c = Ce({
|
|
791
795
|
basePath: r.path,
|
|
792
796
|
params: r.params,
|
|
793
797
|
routeId: r.id,
|
|
@@ -829,7 +833,7 @@ function Se({
|
|
|
829
833
|
const l = e.dataSource.pathDataMappings?.[a]?.dataCache?.[c.locale] ?? e.dataSource.pathDataMappings?.[a]?.dataCache?.[o.config.defaultLocale || "en"];
|
|
830
834
|
if (!l)
|
|
831
835
|
continue;
|
|
832
|
-
|
|
836
|
+
$t(r, o, c.locale, l);
|
|
833
837
|
}
|
|
834
838
|
n && n.routeMetaData && (n.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
835
839
|
}
|
|
@@ -840,7 +844,7 @@ const H = new le({
|
|
|
840
844
|
ttl: 10 * 60 * 1e3
|
|
841
845
|
// 10 minutes
|
|
842
846
|
});
|
|
843
|
-
function
|
|
847
|
+
function $o(t, e = []) {
|
|
844
848
|
let o = 0;
|
|
845
849
|
const s = Array.from(H.keys()), n = [];
|
|
846
850
|
for (const r of t) {
|
|
@@ -884,12 +888,12 @@ function No() {
|
|
|
884
888
|
const t = H.size;
|
|
885
889
|
return H.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
|
|
886
890
|
}
|
|
887
|
-
|
|
888
|
-
const { uploadToMediaKit: _o } = require("@blocklet/uploader-server"),
|
|
891
|
+
I.events.on(I.Events.envUpdate, No);
|
|
892
|
+
const { uploadToMediaKit: _o } = require("@blocklet/uploader-server"), Te = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, Q = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, Be = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Uo = 1e4, Fo = 3e4, Z = 0, we = 1, Bo = 0, Go = 1, st = I, ee = P(process.env.BLOCKLET_DATA_DIR, "site-state"), Gs = ["production", "draft"], Vs = ["production"];
|
|
889
893
|
function ce(t) {
|
|
890
894
|
return t?.replace(/\//g, "|") || "";
|
|
891
895
|
}
|
|
892
|
-
function
|
|
896
|
+
function Vo() {
|
|
893
897
|
const t = st.env.languages.map((o) => ({ locale: o.code, name: o.name })), e = t[0]?.locale;
|
|
894
898
|
return {
|
|
895
899
|
pageIds: [],
|
|
@@ -907,7 +911,7 @@ function Go() {
|
|
|
907
911
|
class v extends _.Doc {
|
|
908
912
|
constructor(e) {
|
|
909
913
|
super(), this.options = e, L(this.draftYjsFilePath) && _.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore = Ut(
|
|
910
|
-
|
|
914
|
+
Mt(
|
|
911
915
|
{
|
|
912
916
|
pages: {},
|
|
913
917
|
pageIds: [],
|
|
@@ -943,7 +947,7 @@ class v extends _.Doc {
|
|
|
943
947
|
throw new Error("Should provide project context");
|
|
944
948
|
try {
|
|
945
949
|
const o = P(ee, e), s = P(ee, `@del-${e}`);
|
|
946
|
-
|
|
950
|
+
je(o, s);
|
|
947
951
|
} catch (o) {
|
|
948
952
|
f.error("Failed to safe delete project state dir:", o);
|
|
949
953
|
}
|
|
@@ -979,15 +983,15 @@ class v extends _.Doc {
|
|
|
979
983
|
static async getProductionState(e) {
|
|
980
984
|
return (await N.findByPk(e, {
|
|
981
985
|
attributes: ["productionState"]
|
|
982
|
-
}))?.productionState ??
|
|
986
|
+
}))?.productionState ?? Vo();
|
|
983
987
|
}
|
|
984
988
|
destroy() {
|
|
985
989
|
this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((o, s) => this.closeConn(s)), this.awareness.destroy();
|
|
986
|
-
const e =
|
|
990
|
+
const e = j(this.options.path);
|
|
987
991
|
delete v.sharedInstances[e], super.destroy();
|
|
988
992
|
}
|
|
989
993
|
initObserver() {
|
|
990
|
-
|
|
994
|
+
jo(this.syncedStore), xo(this.syncedStore);
|
|
991
995
|
}
|
|
992
996
|
get draftYjsFilePath() {
|
|
993
997
|
return P(this.options.path, "draft.yjs");
|
|
@@ -1002,13 +1006,13 @@ class v extends _.Doc {
|
|
|
1002
1006
|
async getState(e) {
|
|
1003
1007
|
if (e === "draft")
|
|
1004
1008
|
return JSON.parse(JSON.stringify(this.syncedStore));
|
|
1005
|
-
const o =
|
|
1009
|
+
const o = j(this.options.path);
|
|
1006
1010
|
return v.getProductionState(o);
|
|
1007
1011
|
}
|
|
1008
1012
|
async setState(e, o) {
|
|
1009
1013
|
const s = await Ho(o, { exportAssets: !1, includeResources: !0 }), n = this.getPublishDir(e);
|
|
1010
|
-
if (F(
|
|
1011
|
-
const r =
|
|
1014
|
+
if (F(x(n), { recursive: !0 }), Je(n, { force: !0, recursive: !0 }), je(s, n), e === "production") {
|
|
1015
|
+
const r = j(this.options.path);
|
|
1012
1016
|
v.pageUrlMapCache.delete(r), await N.update({ productionState: o }, { where: { id: r } });
|
|
1013
1017
|
}
|
|
1014
1018
|
}
|
|
@@ -1070,7 +1074,7 @@ class v extends _.Doc {
|
|
|
1070
1074
|
}
|
|
1071
1075
|
};
|
|
1072
1076
|
send = (e, o) => {
|
|
1073
|
-
e.readyState !== Bo && e.readyState !==
|
|
1077
|
+
e.readyState !== Bo && e.readyState !== Go && this.closeConn(e);
|
|
1074
1078
|
try {
|
|
1075
1079
|
e.send(o, (s) => {
|
|
1076
1080
|
s && this.closeConn(e);
|
|
@@ -1093,7 +1097,7 @@ class v extends _.Doc {
|
|
|
1093
1097
|
// 调度延迟释放
|
|
1094
1098
|
scheduleRelease() {
|
|
1095
1099
|
this.cancelRelease();
|
|
1096
|
-
const e =
|
|
1100
|
+
const e = j(this.options.path);
|
|
1097
1101
|
this.releaseTimer = setTimeout(() => {
|
|
1098
1102
|
f.info(`[SiteState] releasing instance due to no active connections: ${e}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
|
|
1099
1103
|
}, v.RELEASE_DELAY), f.info(`[SiteState] scheduled release for project ${e} in ${v.RELEASE_DELAY / 1e3}s`);
|
|
@@ -1102,19 +1106,19 @@ class v extends _.Doc {
|
|
|
1102
1106
|
cancelRelease() {
|
|
1103
1107
|
if (this.releaseTimer) {
|
|
1104
1108
|
clearTimeout(this.releaseTimer), this.releaseTimer = void 0;
|
|
1105
|
-
const e =
|
|
1109
|
+
const e = j(this.options.path);
|
|
1106
1110
|
f.info(`[SiteState] cancelled scheduled release for project ${e}`);
|
|
1107
1111
|
}
|
|
1108
1112
|
}
|
|
1109
1113
|
autoSave = ze(() => {
|
|
1110
|
-
F(
|
|
1114
|
+
F(x(this.draftYjsFilePath), { recursive: !0 }), oe(this.draftYjsFilePath, _.encodeStateAsUpdate(this));
|
|
1111
1115
|
}, Uo);
|
|
1112
1116
|
save = ({ flush: e = !1 } = {}) => {
|
|
1113
1117
|
this.autoSave(), e && this.autoSave.flush();
|
|
1114
1118
|
};
|
|
1115
1119
|
publish = async ({ mode: e, routes: o }) => {
|
|
1116
1120
|
const s = await this.getState("draft"), n = await this.getState("production");
|
|
1117
|
-
await
|
|
1121
|
+
await Ve(s, n, { routes: o, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), n.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Mo(this.syncedStore, o), await this.setState(e, n), await this.clearPageCacheForRoutes(o, n);
|
|
1118
1122
|
};
|
|
1119
1123
|
mergeState = async (e, o) => {
|
|
1120
1124
|
const s = JSON.parse(JSON.stringify(o));
|
|
@@ -1123,7 +1127,7 @@ class v extends _.Doc {
|
|
|
1123
1127
|
e.config.fontFamily.title = n?.title || r?.title, e.config.fontFamily.description = n?.description || r?.description, await new Promise((c, a) => {
|
|
1124
1128
|
this.transact(async () => {
|
|
1125
1129
|
try {
|
|
1126
|
-
const l = await
|
|
1130
|
+
const l = await Ve(e, o);
|
|
1127
1131
|
c(l);
|
|
1128
1132
|
} catch (l) {
|
|
1129
1133
|
a(l);
|
|
@@ -1132,7 +1136,7 @@ class v extends _.Doc {
|
|
|
1132
1136
|
});
|
|
1133
1137
|
};
|
|
1134
1138
|
clearPageCacheForRoutes = async (e, o) => {
|
|
1135
|
-
const s =
|
|
1139
|
+
const s = j(this.options.path), r = (await N.findByPk(s))?.slug || s;
|
|
1136
1140
|
if (f.info(`[SiteState] clearing page cache for project ${s}, routes:`, e || []), !e || e.length === 0) {
|
|
1137
1141
|
Lo({
|
|
1138
1142
|
projectId: s,
|
|
@@ -1147,7 +1151,7 @@ class v extends _.Doc {
|
|
|
1147
1151
|
r && r !== s && (r === "/" ? a.push(h) : a.push(`/${r}${h}`)), a.push(`/${s}${h}`);
|
|
1148
1152
|
}
|
|
1149
1153
|
if (f.info(`[SiteState] clearing page cache for project ${s}, pathPatterns:`, a), a.length > 0) {
|
|
1150
|
-
const d =
|
|
1154
|
+
const d = $o(a, c);
|
|
1151
1155
|
f.info(`[SiteState] cleared ${d} page cache entries for project ${s}, routes:`, e);
|
|
1152
1156
|
}
|
|
1153
1157
|
};
|
|
@@ -1225,30 +1229,30 @@ class v extends _.Doc {
|
|
|
1225
1229
|
});
|
|
1226
1230
|
await Promise.all(
|
|
1227
1231
|
r.map(async (c) => {
|
|
1228
|
-
const a = c.id, l = c.slug || a, d = {},
|
|
1229
|
-
|
|
1230
|
-
|
|
1232
|
+
const a = c.id, l = c.slug || a, d = {}, E = e === "production" && c?.productionState ? c.productionState : await v.getStateByProjectId(c.id, e), h = Bt(
|
|
1233
|
+
I.env.languages.map((p) => p.code),
|
|
1234
|
+
E.supportedLocales.map((p) => p.locale)
|
|
1231
1235
|
), S = (p, i) => {
|
|
1232
|
-
l && (d[
|
|
1236
|
+
l && (d[G("/", l, p)] = {
|
|
1233
1237
|
...i,
|
|
1234
1238
|
shouldRedirect: !0,
|
|
1235
1239
|
mainPage: !0
|
|
1236
|
-
}), d[
|
|
1240
|
+
}), d[G("/", a, p)] = {
|
|
1237
1241
|
...i,
|
|
1238
1242
|
shouldRedirect: !0,
|
|
1239
1243
|
mainPage: !0
|
|
1240
1244
|
};
|
|
1241
1245
|
for (const y of h) {
|
|
1242
1246
|
const A = { ...i, locale: y };
|
|
1243
|
-
d[
|
|
1247
|
+
d[G("/", y, a, p)] = A, l && (d[G("/", y, l, p)] = A);
|
|
1244
1248
|
}
|
|
1245
1249
|
};
|
|
1246
1250
|
if (e === "draft")
|
|
1247
|
-
for (const p of
|
|
1248
|
-
const i =
|
|
1251
|
+
for (const p of E.routeIds || []) {
|
|
1252
|
+
const i = E?.routes?.[p];
|
|
1249
1253
|
if (!i) continue;
|
|
1250
1254
|
if (i.params && i.params.length > 0) {
|
|
1251
|
-
const g =
|
|
1255
|
+
const g = Ce({
|
|
1252
1256
|
basePath: i.path,
|
|
1253
1257
|
params: i.params,
|
|
1254
1258
|
routeId: i.id,
|
|
@@ -1268,7 +1272,7 @@ class v extends _.Doc {
|
|
|
1268
1272
|
// default locale
|
|
1269
1273
|
defaultLocale: h?.[0],
|
|
1270
1274
|
locales: h,
|
|
1271
|
-
publishedAt:
|
|
1275
|
+
publishedAt: E.config.publishedAt,
|
|
1272
1276
|
isPublic: i.isPublic && m?.routeMetaData?.isPublic
|
|
1273
1277
|
};
|
|
1274
1278
|
S(w, C);
|
|
@@ -1283,13 +1287,13 @@ class v extends _.Doc {
|
|
|
1283
1287
|
// default locale
|
|
1284
1288
|
defaultLocale: h?.[0],
|
|
1285
1289
|
locales: h,
|
|
1286
|
-
publishedAt:
|
|
1290
|
+
publishedAt: E.config.publishedAt,
|
|
1287
1291
|
isPublic: i.isPublic
|
|
1288
1292
|
};
|
|
1289
1293
|
S(y, A);
|
|
1290
1294
|
}
|
|
1291
|
-
for (const p of
|
|
1292
|
-
const i =
|
|
1295
|
+
for (const p of E.pageIds) {
|
|
1296
|
+
const i = E.pages[p];
|
|
1293
1297
|
if (!i || e === "production" && !i.isPublic)
|
|
1294
1298
|
continue;
|
|
1295
1299
|
const y = i.slug, A = c.slug || a, g = {
|
|
@@ -1300,7 +1304,7 @@ class v extends _.Doc {
|
|
|
1300
1304
|
// default locale
|
|
1301
1305
|
defaultLocale: h?.[0],
|
|
1302
1306
|
locales: h,
|
|
1303
|
-
publishedAt:
|
|
1307
|
+
publishedAt: E.config.publishedAt,
|
|
1304
1308
|
isPublic: i.isPublic,
|
|
1305
1309
|
templateConfig: i.templateConfig
|
|
1306
1310
|
};
|
|
@@ -1366,7 +1370,7 @@ class v extends _.Doc {
|
|
|
1366
1370
|
}
|
|
1367
1371
|
}
|
|
1368
1372
|
async function Jo(t, e, o) {
|
|
1369
|
-
if (!t || !L(t) || !
|
|
1373
|
+
if (!t || !L(t) || !V(t).isFile())
|
|
1370
1374
|
return null;
|
|
1371
1375
|
let s = o[t];
|
|
1372
1376
|
return s || (s = (async () => {
|
|
@@ -1381,9 +1385,9 @@ async function Jo(t, e, o) {
|
|
|
1381
1385
|
})(), o[t] = s), s;
|
|
1382
1386
|
}
|
|
1383
1387
|
const Ko = async (t, e) => {
|
|
1384
|
-
const o =
|
|
1388
|
+
const o = j(t), s = await xt({
|
|
1385
1389
|
name: tt,
|
|
1386
|
-
path:
|
|
1390
|
+
path: G("/uploads", o),
|
|
1387
1391
|
responseType: "stream",
|
|
1388
1392
|
method: "GET"
|
|
1389
1393
|
});
|
|
@@ -1396,7 +1400,7 @@ const Ko = async (t, e) => {
|
|
|
1396
1400
|
await Promise.all(
|
|
1397
1401
|
t.map(async (o) => {
|
|
1398
1402
|
try {
|
|
1399
|
-
await Ko(o, P(e,
|
|
1403
|
+
await Ko(o, P(e, j(o)));
|
|
1400
1404
|
} catch (s) {
|
|
1401
1405
|
f.error(`Failed to export assets: ${o}, ${s}`);
|
|
1402
1406
|
}
|
|
@@ -1404,42 +1408,42 @@ const Ko = async (t, e) => {
|
|
|
1404
1408
|
);
|
|
1405
1409
|
};
|
|
1406
1410
|
function nt(t) {
|
|
1407
|
-
return
|
|
1411
|
+
return Te.test(t) ? [t] : Q.test(t) ? (Be.lastIndex = 0, Array.from(t.matchAll(Be)).map((o) => o[1]).filter((o) => !!o)) : [];
|
|
1408
1412
|
}
|
|
1409
1413
|
async function te(t, e, o) {
|
|
1410
1414
|
const { getFilename: s, exportAssets: n } = o, r = P(e, s(t));
|
|
1411
|
-
if (F(
|
|
1415
|
+
if (F(x(r), { recursive: !0 }), oe(r, K.stringify(t)), n) {
|
|
1412
1416
|
const a = ie(
|
|
1413
1417
|
t,
|
|
1414
|
-
(l) => typeof l == "string" && (
|
|
1418
|
+
(l) => typeof l == "string" && (Te.test(l) || Q.test(l))
|
|
1415
1419
|
).map((l) => {
|
|
1416
|
-
const d =
|
|
1420
|
+
const d = Oe(t, l);
|
|
1417
1421
|
return nt(d);
|
|
1418
1422
|
}).flat().filter(Boolean);
|
|
1419
|
-
await zo(a,
|
|
1423
|
+
await zo(a, x(r));
|
|
1420
1424
|
}
|
|
1421
1425
|
}
|
|
1422
|
-
const
|
|
1426
|
+
const Pe = new le({
|
|
1423
1427
|
max: 100,
|
|
1424
1428
|
ttl: 1 * 60 * 1e3
|
|
1425
1429
|
// 1 minute
|
|
1426
1430
|
});
|
|
1427
|
-
async function
|
|
1431
|
+
async function Ge(t, e, o) {
|
|
1428
1432
|
const s = ie(
|
|
1429
1433
|
t,
|
|
1430
|
-
(a) => typeof a == "string" && (
|
|
1431
|
-
), n =
|
|
1434
|
+
(a) => typeof a == "string" && (Te.test(a) || Q.test(a))
|
|
1435
|
+
), n = Gt(2), r = s.map(
|
|
1432
1436
|
(a) => n(async () => {
|
|
1433
1437
|
try {
|
|
1434
|
-
const l =
|
|
1435
|
-
for (const
|
|
1436
|
-
const h =
|
|
1438
|
+
const l = Oe(t, a), d = nt(l);
|
|
1439
|
+
for (const E of d) {
|
|
1440
|
+
const h = j(E), S = o.getFilePath(E, a), p = S ? `${S}:${h}` : h, i = Pe.get(p);
|
|
1437
1441
|
if (i) {
|
|
1438
|
-
Q.test(l) ||
|
|
1442
|
+
Q.test(l) || Me(t, a, i);
|
|
1439
1443
|
return;
|
|
1440
1444
|
}
|
|
1441
1445
|
const y = await Jo(S, h, e);
|
|
1442
|
-
y && (Q.test(l) ||
|
|
1446
|
+
y && (Q.test(l) || Me(t, a, y), Pe.set(p, y));
|
|
1443
1447
|
}
|
|
1444
1448
|
} catch (l) {
|
|
1445
1449
|
f.error(`Failed to process upload for path ${a.join(".")}:`, l.message || l.reason);
|
|
@@ -1460,7 +1464,7 @@ async function Ho(t, {
|
|
|
1460
1464
|
state: t,
|
|
1461
1465
|
pageIds: a,
|
|
1462
1466
|
componentIds: s === "all" ? Object.keys(t.components) : s
|
|
1463
|
-
}), d = c === "all" ? t.routeIds : c,
|
|
1467
|
+
}), d = c === "all" ? t.routeIds : c, E = (u) => ({
|
|
1464
1468
|
id: u.id,
|
|
1465
1469
|
name: u.name,
|
|
1466
1470
|
isTemplateSection: u.isTemplateSection ?? !1,
|
|
@@ -1472,7 +1476,7 @@ async function Ho(t, {
|
|
|
1472
1476
|
sections: u?.sectionIds ? R(
|
|
1473
1477
|
u?.sectionIds?.map((b) => {
|
|
1474
1478
|
const T = u.sections?.[b];
|
|
1475
|
-
return T &&
|
|
1479
|
+
return T && E(T);
|
|
1476
1480
|
})
|
|
1477
1481
|
) : void 0
|
|
1478
1482
|
// 已经废弃,数据在 page.dataSource 中管理
|
|
@@ -1488,7 +1492,7 @@ async function Ho(t, {
|
|
|
1488
1492
|
sections: R(
|
|
1489
1493
|
u.sectionIds.map((T) => {
|
|
1490
1494
|
const B = u.sections[T];
|
|
1491
|
-
return B &&
|
|
1495
|
+
return B && E(B);
|
|
1492
1496
|
})
|
|
1493
1497
|
),
|
|
1494
1498
|
// 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
|
|
@@ -1548,7 +1552,7 @@ async function Ho(t, {
|
|
|
1548
1552
|
});
|
|
1549
1553
|
}
|
|
1550
1554
|
const w = P(y, ".blocklet/pages/pages.config.yml");
|
|
1551
|
-
F(
|
|
1555
|
+
F(x(w), { recursive: !0 });
|
|
1552
1556
|
const C = {
|
|
1553
1557
|
pages: R(
|
|
1554
1558
|
a.map((u) => {
|
|
@@ -1590,10 +1594,10 @@ async function Ho(t, {
|
|
|
1590
1594
|
const u = P(y, "resources"), b = P(u, "components");
|
|
1591
1595
|
F(b, { recursive: !0 });
|
|
1592
1596
|
for (const W of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1593
|
-
(
|
|
1597
|
+
(M) => l.includes(M)
|
|
1594
1598
|
)) {
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1599
|
+
const M = t.resources?.components?.[W]?.component;
|
|
1600
|
+
M && await te(M, b, {
|
|
1597
1601
|
getFilename: (Y) => `${Y.name || "unnamed"}.${Y.id}.yml`,
|
|
1598
1602
|
exportAssets: e
|
|
1599
1603
|
});
|
|
@@ -1602,16 +1606,16 @@ async function Ho(t, {
|
|
|
1602
1606
|
F(T, { recursive: !0 });
|
|
1603
1607
|
const B = Yo();
|
|
1604
1608
|
for (const W of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1605
|
-
(
|
|
1609
|
+
(M) => l.includes(M)
|
|
1606
1610
|
)) {
|
|
1607
|
-
const
|
|
1608
|
-
if (
|
|
1609
|
-
const Y =
|
|
1611
|
+
const M = t.resources?.components?.[W]?.component;
|
|
1612
|
+
if (M && M.renderer?.type === "react-component") {
|
|
1613
|
+
const Y = M.renderer?.chunks ?? [];
|
|
1610
1614
|
if (Y?.length > 0)
|
|
1611
1615
|
for (const me of Y) {
|
|
1612
|
-
const
|
|
1616
|
+
const ke = P(T, me), he = B?.[me];
|
|
1613
1617
|
try {
|
|
1614
|
-
he && L(he) && !L(
|
|
1618
|
+
he && L(he) && !L(ke) && At(he, ke);
|
|
1615
1619
|
} catch (ut) {
|
|
1616
1620
|
f.error(`copy chunk ${me} error`, ut.message);
|
|
1617
1621
|
}
|
|
@@ -1626,13 +1630,13 @@ async function Wo(t, { importAssets: e, includeResources: o } = {}) {
|
|
|
1626
1630
|
return null;
|
|
1627
1631
|
let s, n = !1;
|
|
1628
1632
|
try {
|
|
1629
|
-
|
|
1630
|
-
const r = se("**/.blocklet/pages/pages.config.yml", { cwd: s, absolute: !0 }).at(0), c = r && P(
|
|
1633
|
+
V(t).isDirectory() ? s = t : /\.(tgz|gz|tar)$/.test(t) && (n = !0, s = ot(), await Kt({ file: t, C: s }));
|
|
1634
|
+
const r = se("**/.blocklet/pages/pages.config.yml", { cwd: s, absolute: !0 }).at(0), c = r && P(x(r), "../../pages"), a = r && P(x(r), "../../components"), l = r && P(x(r), "../../routes");
|
|
1631
1635
|
if (!r)
|
|
1632
1636
|
return null;
|
|
1633
|
-
const d = K.parse(J(r).toString()),
|
|
1637
|
+
const d = K.parse(J(r).toString()), E = (g, m, w) => {
|
|
1634
1638
|
let C = P(g, `${m}${w ? `.${w}` : ""}.yml`);
|
|
1635
|
-
return (!L(C) || !
|
|
1639
|
+
return (!L(C) || !V(C).isFile()) && (C = P(g, m, `index${w ? `.${w}` : ""}.yml`), !L(C) || !V(C)) ? null : K.parse(J(C).toString());
|
|
1636
1640
|
}, h = (g, m) => {
|
|
1637
1641
|
try {
|
|
1638
1642
|
const w = se(`*.${m}.yml`, { cwd: g, absolute: !0 })[0];
|
|
@@ -1643,15 +1647,15 @@ async function Wo(t, { importAssets: e, includeResources: o } = {}) {
|
|
|
1643
1647
|
return null;
|
|
1644
1648
|
}, S = (g, m) => {
|
|
1645
1649
|
let w = P(g, `${m}.yml`);
|
|
1646
|
-
return (!L(w) || !
|
|
1650
|
+
return (!L(w) || !V(w).isFile()) && (w = P(g, m, "index.yml"), !L(w) || !V(w)) ? null : K.parse(J(w).toString());
|
|
1647
1651
|
}, p = R(
|
|
1648
1652
|
d.pages.map(({ slug: g }) => {
|
|
1649
1653
|
const m = R(
|
|
1650
1654
|
d.supportedLocales.map(({ locale: O }) => {
|
|
1651
|
-
const u = c ?
|
|
1655
|
+
const u = c ? E(c, ce(g), O) : void 0;
|
|
1652
1656
|
if (u)
|
|
1653
1657
|
return { locale: O, page: u };
|
|
1654
|
-
const b = c ?
|
|
1658
|
+
const b = c ? E(c, g, O) : void 0;
|
|
1655
1659
|
return b && { locale: O, page: b };
|
|
1656
1660
|
})
|
|
1657
1661
|
), w = m[0]?.page;
|
|
@@ -1718,38 +1722,38 @@ async function Wo(t, { importAssets: e, includeResources: o } = {}) {
|
|
|
1718
1722
|
), y = a ? R(d.components?.map(({ id: g }) => h(a, g)) ?? []) : [];
|
|
1719
1723
|
if (e) {
|
|
1720
1724
|
const g = (...m) => {
|
|
1721
|
-
f.info(`[${n ?
|
|
1725
|
+
f.info(`[${n ? j(t) : j(P(t, "../../../../"))}] importAssets:`, ...m);
|
|
1722
1726
|
};
|
|
1723
1727
|
try {
|
|
1724
1728
|
g("wait image-bin api ready"), await zt({
|
|
1725
|
-
resources: [`${
|
|
1729
|
+
resources: [`${jt(Zt)}/api/sdk/uploads`],
|
|
1726
1730
|
validateStatus: (C) => C >= 200 && C <= 500
|
|
1727
1731
|
}), g("image-bin api is ready");
|
|
1728
1732
|
const m = {}, w = {};
|
|
1729
1733
|
g("start to upload assets"), await Promise.allSettled([
|
|
1730
|
-
|
|
1734
|
+
Ge(y, m, {
|
|
1731
1735
|
getFilePath: (C) => a && P(a, C),
|
|
1732
1736
|
onFinish: (C) => {
|
|
1733
1737
|
g(`upload ${C.length} component assets`);
|
|
1734
1738
|
}
|
|
1735
1739
|
}),
|
|
1736
|
-
|
|
1740
|
+
Ge(p, w, {
|
|
1737
1741
|
getFilePath: (C, O) => {
|
|
1738
|
-
const u =
|
|
1739
|
-
return c && P(c,
|
|
1742
|
+
const u = Oe(p, O.slice(0, 1));
|
|
1743
|
+
return c && P(c, x(u.slug), C);
|
|
1740
1744
|
},
|
|
1741
1745
|
onFinish: (C) => {
|
|
1742
1746
|
g(`upload ${C.length} page assets`);
|
|
1743
1747
|
}
|
|
1744
1748
|
})
|
|
1745
|
-
]), g("upload assets done"),
|
|
1749
|
+
]), g("upload assets done"), Pe.clear(), global.gc && global.gc();
|
|
1746
1750
|
} catch (m) {
|
|
1747
1751
|
g("Error during asset import:", m);
|
|
1748
1752
|
}
|
|
1749
1753
|
}
|
|
1750
1754
|
const A = {};
|
|
1751
1755
|
if (o) {
|
|
1752
|
-
const g = r && P(
|
|
1756
|
+
const g = r && P(x(r), "../../resources/components"), m = R(
|
|
1753
1757
|
d.resources?.components?.map(({ id: w }) => h(g, w)) ?? []
|
|
1754
1758
|
);
|
|
1755
1759
|
m.length > 0 && (A.components = Object.fromEntries(
|
|
@@ -1772,7 +1776,7 @@ async function Wo(t, { importAssets: e, includeResources: o } = {}) {
|
|
|
1772
1776
|
n && s && Je(s, { force: !0, recursive: !0 });
|
|
1773
1777
|
}
|
|
1774
1778
|
}
|
|
1775
|
-
async function
|
|
1779
|
+
async function Ve(t, e, {
|
|
1776
1780
|
routes: o,
|
|
1777
1781
|
mergeMode: s = "byUpdateTime",
|
|
1778
1782
|
deleteRoutes: n = !1,
|
|
@@ -1783,13 +1787,13 @@ async function Ge(t, e, {
|
|
|
1783
1787
|
} catch (S) {
|
|
1784
1788
|
f.error("clear preload page cache error", { error: S });
|
|
1785
1789
|
}
|
|
1786
|
-
const { pages: c, pageIds: a, routeIds: l, routes: d, supportedLocales:
|
|
1790
|
+
const { pages: c, pageIds: a, routeIds: l, routes: d, supportedLocales: E } = t;
|
|
1787
1791
|
if (r === "production") {
|
|
1788
1792
|
let S = o ?? [], p = null;
|
|
1789
1793
|
for (const i of l ?? []) {
|
|
1790
1794
|
const y = d?.[i];
|
|
1791
1795
|
if (y?.params && y?.params.length > 0 && y?.paramsOptions && y?.paramsOptions.length > 0) {
|
|
1792
|
-
const A =
|
|
1796
|
+
const A = Ce({
|
|
1793
1797
|
basePath: y.path,
|
|
1794
1798
|
params: y.params,
|
|
1795
1799
|
routeId: y.id,
|
|
@@ -1891,7 +1895,7 @@ async function Ge(t, e, {
|
|
|
1891
1895
|
e.routeIds.push(p.id), e.routes[p.id] = p;
|
|
1892
1896
|
}
|
|
1893
1897
|
}
|
|
1894
|
-
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ft(
|
|
1898
|
+
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ft(E)), n)
|
|
1895
1899
|
for (const S of Object.keys(e.components))
|
|
1896
1900
|
delete e.components[S];
|
|
1897
1901
|
let h = JSON.parse(JSON.stringify(t.components));
|
|
@@ -1908,11 +1912,11 @@ async function Ge(t, e, {
|
|
|
1908
1912
|
];
|
|
1909
1913
|
})
|
|
1910
1914
|
)
|
|
1911
|
-
), Object.assign(e.components, h), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))),
|
|
1915
|
+
), Object.assign(e.components, h), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ae(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
|
|
1912
1916
|
}
|
|
1913
1917
|
const rt = ue(
|
|
1914
1918
|
async (t) => {
|
|
1915
|
-
if (!
|
|
1919
|
+
if (!Ae(t?.properties))
|
|
1916
1920
|
return t;
|
|
1917
1921
|
if (t?.renderer?.type === "react-component") {
|
|
1918
1922
|
const { script: e, PROPERTIES_SCHEMA: o } = t?.renderer || {};
|
|
@@ -1943,13 +1947,13 @@ const rt = ue(
|
|
|
1943
1947
|
let pe, X, de, fe;
|
|
1944
1948
|
const at = () => Rt({
|
|
1945
1949
|
types: [
|
|
1946
|
-
{ did: tt, type:
|
|
1947
|
-
{ did: Ro, type:
|
|
1950
|
+
{ did: tt, type: Fe },
|
|
1951
|
+
{ did: Ro, type: Fe }
|
|
1948
1952
|
]
|
|
1949
1953
|
}), Yo = () => {
|
|
1950
1954
|
const t = at(), e = {};
|
|
1951
1955
|
return t.forEach((o) => {
|
|
1952
|
-
const s = se("**/.blocklet/pages/pages.config.yml", { cwd: o.path, absolute: !0 }).at(0), n = s && P(
|
|
1956
|
+
const s = se("**/.blocklet/pages/pages.config.yml", { cwd: o.path, absolute: !0 }).at(0), n = s && P(x(s), "../../chunks");
|
|
1953
1957
|
if (n && L(n)) {
|
|
1954
1958
|
const r = Ct(n);
|
|
1955
1959
|
for (const c of r)
|
|
@@ -2014,8 +2018,8 @@ function qo(t) {
|
|
|
2014
2018
|
// 3s
|
|
2015
2019
|
{ leading: !1, trailing: !0 }
|
|
2016
2020
|
);
|
|
2017
|
-
return e(),
|
|
2018
|
-
|
|
2021
|
+
return e(), I.events.on(I.Events.componentAdded, e), I.events.on(I.Events.componentRemoved, e), I.events.on(I.Events.componentStarted, e), I.events.on(I.Events.componentStopped, e), I.events.on(I.Events.componentUpdated, e), I.events.on(be, e), () => {
|
|
2022
|
+
I.events.off(I.Events.componentAdded, e), I.events.off(I.Events.componentRemoved, e), I.events.off(I.Events.componentStarted, e), I.events.off(I.Events.componentStopped, e), I.events.off(I.Events.componentUpdated, e), I.events.off(be, e);
|
|
2019
2023
|
};
|
|
2020
2024
|
}
|
|
2021
2025
|
const ct = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), pt = globalThis;
|
|
@@ -2064,7 +2068,7 @@ async function lt({
|
|
|
2064
2068
|
if (s.syncedStore.resources.pages = e, (await N.findByPk(t))?.useAllResources)
|
|
2065
2069
|
s.syncedStore.resources.components = o;
|
|
2066
2070
|
else {
|
|
2067
|
-
const c = (await
|
|
2071
|
+
const c = (await ve.findAll({ where: { projectId: t } })).map((l) => l.componentId), a = Object.fromEntries(
|
|
2068
2072
|
Object.entries(o || {}).filter(([l]) => c.includes(l))
|
|
2069
2073
|
);
|
|
2070
2074
|
s.syncedStore.resources.components = a;
|
|
@@ -2074,23 +2078,46 @@ async function lt({
|
|
|
2074
2078
|
components: Object.keys(s.syncedStore.resources.components || {}).length
|
|
2075
2079
|
});
|
|
2076
2080
|
}
|
|
2081
|
+
async function Js() {
|
|
2082
|
+
f.info("trigger reload all project resource"), I.events.emit(be);
|
|
2083
|
+
}
|
|
2077
2084
|
async function Qo({
|
|
2078
2085
|
ensureLoaded: t = !0
|
|
2079
2086
|
} = {}) {
|
|
2080
2087
|
return t && (pe ??= it(), await pe), { states: X, pages: de, components: fe };
|
|
2081
2088
|
}
|
|
2082
|
-
|
|
2089
|
+
I.events.on(I.Events.envUpdate, () => {
|
|
2083
2090
|
v.pageUrlMapCache.clear(), f.info("clear all page url map cache");
|
|
2084
2091
|
});
|
|
2085
2092
|
export {
|
|
2086
2093
|
tt as C,
|
|
2094
|
+
Ue as G,
|
|
2087
2095
|
N as P,
|
|
2088
|
-
|
|
2096
|
+
Fe as R,
|
|
2089
2097
|
v as S,
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2098
|
+
_s as a,
|
|
2099
|
+
Qo as b,
|
|
2100
|
+
Eo as c,
|
|
2101
|
+
bo as d,
|
|
2102
|
+
Po as e,
|
|
2103
|
+
Ao as f,
|
|
2104
|
+
Us as g,
|
|
2105
|
+
Co as h,
|
|
2093
2106
|
Ns as i,
|
|
2107
|
+
re as j,
|
|
2108
|
+
Fs as k,
|
|
2094
2109
|
f as l,
|
|
2095
|
-
|
|
2110
|
+
ko as m,
|
|
2111
|
+
ee as n,
|
|
2112
|
+
Gs as o,
|
|
2113
|
+
Vs as p,
|
|
2114
|
+
Vo as q,
|
|
2115
|
+
Ko as r,
|
|
2116
|
+
Bs as s,
|
|
2117
|
+
Ho as t,
|
|
2118
|
+
zo as u,
|
|
2119
|
+
Wo as v,
|
|
2120
|
+
Ve as w,
|
|
2121
|
+
qo as x,
|
|
2122
|
+
Js as y
|
|
2096
2123
|
};
|