@blocklet/pages-kit-inner-components 0.6.1 → 0.6.3
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 -420
- package/lib/cjs/chunks/draft-data-CfIMszE7.js +1 -0
- package/lib/cjs/chunks/home-DUjl5PbP.js +6 -0
- package/lib/cjs/chunks/publish-button-C522nNv6.js +1 -0
- package/lib/cjs/chunks/site-state-BG2d2tBl.js +57 -0
- package/lib/cjs/chunks/state-CtNs8GrN.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +11 -4
- package/lib/cjs/resources.js +1 -1
- package/lib/es/add-component.js +2 -1089
- package/lib/es/chunks/{draft-data-CafrGKeh.js → draft-data-bRUHvvzp.js} +5 -4
- package/lib/es/chunks/home-VWWdvIPQ.js +69 -0
- package/lib/es/chunks/{publish-button-XSZrDaTQ.js → publish-button-Ceet-m88.js} +158 -140
- package/lib/es/chunks/site-state-BoVWlYLn.js +2096 -0
- package/lib/es/chunks/state-BdNIIXJP.js +502 -0
- package/lib/es/home.js +3 -28
- package/lib/es/project-html.js +114 -130
- package/lib/es/resources.js +93 -137
- package/package.json +11 -11
- package/lib/cjs/chunks/draft-data-D44_IEV2.js +0 -1
- package/lib/cjs/chunks/home-BYk01EUy.js +0 -39
- package/lib/cjs/chunks/index-BRgYwvuv.js +0 -475
- package/lib/cjs/chunks/publish-button-C8XPA4g_.js +0 -1
- package/lib/cjs/chunks/session-BRtsDvA-.js +0 -1
- package/lib/cjs/chunks/site-state-gSkcvhcV.js +0 -57
- package/lib/cjs/chunks/state-B6BF5wJ-.js +0 -1
- package/lib/cjs/chunks-map.json +0 -1
- package/lib/cjs/components.js +0 -1
- package/lib/cjs/locales.js +0 -3
- package/lib/cjs/setting.js +0 -11
- package/lib/cjs/site-state.js +0 -1
- package/lib/cjs/theme.js +0 -1
- package/lib/cjs/uploader.js +0 -1
- package/lib/es/chunks/home-DW8SdyfO.js +0 -594
- package/lib/es/chunks/index-D5gXPe_7.js +0 -2326
- package/lib/es/chunks/session-C72Dq8zg.js +0 -19
- package/lib/es/chunks/site-state-W2H7XCSQ.js +0 -2077
- package/lib/es/chunks/state-0gvZF3k2.js +0 -573
- package/lib/es/chunks-map.json +0 -1
- package/lib/es/components.js +0 -22
- package/lib/es/locales.js +0 -1032
- package/lib/es/setting.js +0 -2294
- package/lib/es/site-state.js +0 -48
- package/lib/es/theme.js +0 -484
- package/lib/es/uploader.js +0 -8
package/lib/es/project-html.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { l as
|
|
9
|
-
import {
|
|
1
|
+
import K from "@arcblock/did-auth-storage-nedb";
|
|
2
|
+
import r, { getBlockletJs as W } from "@blocklet/sdk/lib/config";
|
|
3
|
+
import H from "@blocklet/sdk/lib/service/auth";
|
|
4
|
+
import B from "@blocklet/sdk/lib/wallet";
|
|
5
|
+
import N from "@blocklet/sdk/lib/wallet-authenticator";
|
|
6
|
+
import q from "@blocklet/sdk/lib/wallet-handler";
|
|
7
|
+
import O, { resolve as T } from "path";
|
|
8
|
+
import { l as _, b as U } from "./chunks/site-state-BoVWlYLn.js";
|
|
9
|
+
import { createHash as L } from "crypto";
|
|
10
|
+
import { createSnapshotMiddleware as z } from "@arcblock/crawler-middleware";
|
|
10
11
|
import { PreloadComponentScriptModule as F } from "@blocklet/pages-kit/types";
|
|
11
12
|
import { isMuiColorKey as J } from "@blocklet/pages-kit/utils/common";
|
|
12
|
-
import { injectPreloadComponents as
|
|
13
|
-
import { getComponentMountPoint as
|
|
14
|
-
import * as E from "cheerio/slim";
|
|
13
|
+
import { injectPreloadComponents as R, safeJSONStringify as Y } from "@blocklet/pages-kit/utils/preload";
|
|
14
|
+
import { getComponentMountPoint as G } from "@blocklet/sdk/lib/component";
|
|
15
15
|
import { Router as Q } from "express";
|
|
16
|
-
import { readFileSync as
|
|
16
|
+
import { readFileSync as $ } from "fs";
|
|
17
17
|
import V from "lodash/get";
|
|
18
18
|
import X from "mustache";
|
|
19
|
-
import { withQuery as Z, joinURL as
|
|
20
|
-
const
|
|
19
|
+
import { withQuery as Z, joinURL as P } from "ufo";
|
|
20
|
+
const ee = (o = {}) => {
|
|
21
21
|
const e = {
|
|
22
22
|
data: /* @__PURE__ */ new Map(),
|
|
23
23
|
timers: /* @__PURE__ */ new Map(),
|
|
24
|
-
set: (t,
|
|
24
|
+
set: (t, i, s = o.ttl || 36e5) => {
|
|
25
25
|
o.max && e.data.size >= o.max && e.delete(e.data.keys().next().value), e.timers.has(t) && clearTimeout(e.timers.get(t)), e.timers.set(
|
|
26
26
|
t,
|
|
27
|
-
setTimeout(() => e.delete(t),
|
|
28
|
-
), e.data.set(t,
|
|
27
|
+
setTimeout(() => e.delete(t), s)
|
|
28
|
+
), e.data.set(t, i);
|
|
29
29
|
},
|
|
30
30
|
get: (t) => e.data.get(t),
|
|
31
31
|
has: (t) => e.data.has(t),
|
|
@@ -38,166 +38,150 @@ const q = (o = {}) => {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
return e;
|
|
41
|
-
},
|
|
41
|
+
}, E = ee({
|
|
42
42
|
max: 1,
|
|
43
43
|
ttl: 1e3 * 30
|
|
44
44
|
// 30 seconds
|
|
45
45
|
});
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
new
|
|
49
|
-
authenticator:
|
|
50
|
-
tokenStorage: new
|
|
51
|
-
dbPath:
|
|
46
|
+
B();
|
|
47
|
+
const te = new N();
|
|
48
|
+
new q({
|
|
49
|
+
authenticator: te,
|
|
50
|
+
tokenStorage: new K({
|
|
51
|
+
dbPath: O.join(r.env.dataDir, "auth.db")
|
|
52
52
|
})
|
|
53
53
|
});
|
|
54
|
-
const
|
|
54
|
+
const oe = new H(), ne = async () => {
|
|
55
55
|
try {
|
|
56
|
-
const o =
|
|
56
|
+
const o = E.get("blockletInfo");
|
|
57
57
|
if (o)
|
|
58
58
|
return o;
|
|
59
|
-
const { blocklet: e } = await
|
|
60
|
-
return
|
|
59
|
+
const { blocklet: e } = await oe.getBlocklet();
|
|
60
|
+
return E.set("blockletInfo", e), e;
|
|
61
61
|
} catch {
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
|
-
},
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
}, re = async () => await import("cheerio"), C = {};
|
|
65
|
+
function ae(o, e) {
|
|
66
|
+
const t = JSON.stringify([o, e]);
|
|
67
|
+
return L("md5").update(t).digest("hex");
|
|
68
|
+
}
|
|
69
|
+
async function ie(o, e) {
|
|
70
|
+
{
|
|
71
|
+
const i = (await re()).load(o);
|
|
72
|
+
return e.forEach((s) => {
|
|
73
|
+
i(s.selector.cheerio).replaceWith(s.value);
|
|
74
|
+
}), i.html();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function se(o, e) {
|
|
78
|
+
if (!e || e.length === 0)
|
|
79
|
+
return o;
|
|
80
|
+
const t = ae(o, e);
|
|
81
|
+
return C[t] ??= ie(o, e).finally(() => {
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
delete C[t];
|
|
84
|
+
}, 2 * 1e3);
|
|
85
|
+
}), C[t];
|
|
86
|
+
}
|
|
87
|
+
function ce(o) {
|
|
88
|
+
return o.match(/<body[^>]*>(.*?)<\/body>/s)?.[1] || "";
|
|
89
|
+
}
|
|
90
|
+
const le = ["/assets/"];
|
|
91
|
+
function je({ app: o, viteDevServer: e, state: t }) {
|
|
92
|
+
let i;
|
|
72
93
|
if (e) {
|
|
73
|
-
const n =
|
|
74
|
-
o.use(async (u,
|
|
75
|
-
const
|
|
76
|
-
|
|
94
|
+
const n = $(T(process.cwd(), "./index.html"), "utf-8");
|
|
95
|
+
o.use(async (u, v, k) => {
|
|
96
|
+
const S = u.originalUrl;
|
|
97
|
+
i = await e.transformIndexHtml(S, n), k();
|
|
77
98
|
});
|
|
78
|
-
} else
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
m.use((n, u, S) => {
|
|
99
|
+
} else i = $(T(process.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
|
|
100
|
+
const s = Q();
|
|
101
|
+
s.use((n, u, v) => {
|
|
82
102
|
if (n.headers["x-unique-record"] === "dial_http") {
|
|
83
|
-
|
|
103
|
+
_.info("[html] dial http request, return 200 status code"), u.status(200).send("ok");
|
|
84
104
|
return;
|
|
85
105
|
}
|
|
86
|
-
|
|
87
|
-
}),
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
accessKey: i.env.SNAP_KIT_ACCESS_KEY,
|
|
91
|
-
cacheMax: i.env.preferences.snapkitCacheSize || 100
|
|
92
|
-
})
|
|
93
|
-
), m.get("/:path(*)?", async (n, u, S) => {
|
|
94
|
-
if (ne.some((a) => n.path?.startsWith(a))) {
|
|
95
|
-
S();
|
|
106
|
+
v();
|
|
107
|
+
}), r.env.preferences.snapkitEnabled && r.env.preferences.snapkitEndpoint && r.env.SNAP_KIT_ACCESS_KEY && s.use(z({ endpoint: r.env.preferences.snapkitEndpoint, accessKey: r.env.SNAP_KIT_ACCESS_KEY, cacheMax: r.env.preferences.snapkitCacheSize || 100 })), s.get("/:path(*)?", async (n, u, v) => {
|
|
108
|
+
if (le.some((a) => n.path?.startsWith(a))) {
|
|
109
|
+
v();
|
|
96
110
|
return;
|
|
97
111
|
}
|
|
98
|
-
const
|
|
99
|
-
let
|
|
112
|
+
const k = performance.now(), S = () => Math.round(performance.now() - k), j = "production";
|
|
113
|
+
let f, b, g = i;
|
|
100
114
|
if (n.path.startsWith("/pages")) {
|
|
101
|
-
const a = n.params.lang, y = n.cookies.nf_lang,
|
|
102
|
-
let
|
|
103
|
-
if ((!
|
|
104
|
-
const
|
|
105
|
-
Object.values(t.pages).forEach((
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
).map((c) => ({
|
|
109
|
-
id: c.id,
|
|
110
|
-
componentId: c.config.componentId,
|
|
111
|
-
useCache: c.config.useCache,
|
|
112
|
-
cacheDuration: c.config.cacheDuration,
|
|
113
|
-
properties: r?.dataSource?.[c.id]?.[h]
|
|
114
|
-
// ?? i.locales?.[respectLocale!]?.properties,
|
|
115
|
-
}));
|
|
116
|
-
f.push(...L);
|
|
115
|
+
const a = n.params.lang, y = n.cookies.nf_lang, w = /* @__PURE__ */ new Set([...r.env.languages.map((h) => h.code)]);
|
|
116
|
+
let d = (a && w.has(a) ? a : void 0) || (w.has(y) ? y : void 0) || [...w][0];
|
|
117
|
+
if ((!d || !t.supportedLocales?.find((h) => h.locale === d)) && (d = t.supportedLocales?.[0]?.locale || ""), d) {
|
|
118
|
+
const h = [];
|
|
119
|
+
Object.values(t.pages).forEach((c) => {
|
|
120
|
+
const D = Object.values(c?.sections ?? {}).filter((p) => p.component === "custom-component" && p.config?.componentId).map((p) => ({ id: p.id, componentId: p.config.componentId, useCache: p.config.useCache, cacheDuration: p.config.cacheDuration, properties: c?.dataSource?.[p.id]?.[d] }));
|
|
121
|
+
h.push(...D);
|
|
117
122
|
});
|
|
118
|
-
const M = new Promise((
|
|
123
|
+
const M = new Promise((c) => {
|
|
119
124
|
setTimeout(() => {
|
|
120
|
-
|
|
121
|
-
},
|
|
125
|
+
c({});
|
|
126
|
+
}, 30 * 1e3);
|
|
122
127
|
});
|
|
123
128
|
try {
|
|
124
|
-
await Promise.race([
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
state: t,
|
|
130
|
-
locale: h,
|
|
131
|
-
instances: f,
|
|
132
|
-
module: F.UMD_FN
|
|
133
|
-
}).then((r) => {
|
|
134
|
-
r && (b = z(r));
|
|
135
|
-
})
|
|
136
|
-
]);
|
|
137
|
-
} catch (r) {
|
|
138
|
-
C.warn("getPreloadComponents timeout in promise race, skip inject html elements", r);
|
|
129
|
+
await Promise.race([M, U({ mode: j, req: n, state: t, locale: d, instances: h, module: F.UMD_FN }).then((c) => {
|
|
130
|
+
c && (b = R(c));
|
|
131
|
+
})]);
|
|
132
|
+
} catch (c) {
|
|
133
|
+
_.warn("getPreloadComponents timeout in promise race, skip inject html elements", c);
|
|
139
134
|
}
|
|
140
135
|
}
|
|
141
136
|
}
|
|
142
137
|
try {
|
|
143
|
-
const a =
|
|
144
|
-
|
|
145
|
-
description: y
|
|
146
|
-
});
|
|
147
|
-
w = X.render(l, {
|
|
148
|
-
ogTitle: a,
|
|
149
|
-
ogDescription: y,
|
|
150
|
-
ogImage: ae(g?.image) || k,
|
|
151
|
-
pagesPublishedAt: t?.config.publishedAt || (/* @__PURE__ */ new Date()).getTime()
|
|
152
|
-
});
|
|
138
|
+
const a = f?.title || r.env.appName, y = f?.description || r.env.appDescription, w = Z(P(r.env.appUrl, "/.well-known/service/blocklet/og.png"), { title: a, description: y });
|
|
139
|
+
g = X.render(i, { ogTitle: a, ogDescription: y, ogImage: pe(f?.image) || w, pagesPublishedAt: t?.config.publishedAt || (/* @__PURE__ */ new Date()).getTime() });
|
|
153
140
|
} catch {
|
|
154
141
|
}
|
|
155
|
-
const
|
|
156
|
-
let
|
|
157
|
-
if (
|
|
158
|
-
const a = await
|
|
159
|
-
|
|
160
|
-
a,
|
|
161
|
-
// 目前 dark 和 light 还是前端行为,后端通过 从 light 中获取
|
|
162
|
-
`settings.theme.light.palette.${s}`,
|
|
163
|
-
s
|
|
164
|
-
);
|
|
142
|
+
const m = t?.config.fontFamily, A = n.query.mode === "draft" || n.url.includes("preview") || n.path?.startsWith("/admin");
|
|
143
|
+
let l = f?.backgroundColor;
|
|
144
|
+
if (l && J(l)) {
|
|
145
|
+
const a = await ne();
|
|
146
|
+
l = V(a, `settings.theme.light.palette.${l}`, l);
|
|
165
147
|
}
|
|
166
|
-
|
|
167
|
-
${
|
|
168
|
-
${
|
|
169
|
-
${
|
|
148
|
+
const I = W(), x = [{ selector: { cheerio: "#injected-head-elements", pattern: /<script[^>]*id=["']injected-head-elements["'][^>]*><\/script>/gis }, value: `
|
|
149
|
+
${l ? `<meta name="theme-color" content="${l}" /><style>html,body,#app {background-color: ${l};}</style>` : ""}
|
|
150
|
+
${m?.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${m.title}&display=swap">` : ""}
|
|
151
|
+
${m?.description && m?.description !== m?.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${m.description}&display=swap">` : ""}
|
|
152
|
+
|
|
153
|
+
|
|
170
154
|
<script>
|
|
171
155
|
|
|
172
|
-
window.__PAGE_STATE__ = ${
|
|
156
|
+
window.__PAGE_STATE__ = ${Y(t || null)};
|
|
157
|
+
|
|
158
|
+
<\/script>
|
|
159
|
+
|
|
173
160
|
|
|
161
|
+
<script>
|
|
174
162
|
document.querySelectorAll('link[rel="preload"][as="style"]').forEach(function (link) {
|
|
175
163
|
const l = document.createElement('link');
|
|
176
164
|
l.rel = 'stylesheet';
|
|
177
165
|
l.href = link.href;
|
|
178
166
|
document.head.appendChild(l);
|
|
179
167
|
});
|
|
168
|
+
|
|
180
169
|
<\/script>
|
|
181
170
|
|
|
182
|
-
${
|
|
171
|
+
${A ? `<script src="https://cdn.tailwindcss.com"><\/script>
|
|
183
172
|
<script>
|
|
184
173
|
window.tailwind.config = {
|
|
185
174
|
darkMode: "class",
|
|
186
175
|
};
|
|
187
176
|
<\/script>` : ""}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const a = E.load(n.cachedHtml);
|
|
192
|
-
d("body").html(a("body").html() || "");
|
|
193
|
-
}
|
|
194
|
-
w = d.html(), u.send(w), C.info(`[html] render: ${n.path}, ${_()}ms`), d.root().children().remove(), w = null, g = null, b = null;
|
|
195
|
-
}), o.use(m);
|
|
177
|
+
` }, I && { selector: { cheerio: 'script[src="__blocklet__.js"]', pattern: /<script[^>]*src=["']__blocklet__\.js["'][^>]*><\/script>/gis }, value: `<script>${I}<\/script>` }, b?.html && { selector: { cheerio: "#injected-html-elements", pattern: /<script[^>]*id=["']injected-html-elements["'][^>]*><\/script>/gis }, value: b.html }, n.cachedHtml && { selector: { cheerio: "body", pattern: /(<body[^>]*>).*?(<\/body>)/gis }, value: `<body>${ce(n.cachedHtml)}</body>` }].filter(Boolean);
|
|
178
|
+
g = await se(g, x), u.send(g), _.info(`[html] render: ${n.path}, ${S()}ms`), g = null, f = null, b = null;
|
|
179
|
+
}), o.use(s);
|
|
196
180
|
}
|
|
197
|
-
function
|
|
198
|
-
const e =
|
|
199
|
-
return e && o && !/^(https?:\/\/|\/)/.test(o) ?
|
|
181
|
+
function pe(o) {
|
|
182
|
+
const e = G("image-bin");
|
|
183
|
+
return e && o && !/^(https?:\/\/|\/)/.test(o) ? r.env.appUrl + P(e, "uploads", o) : o;
|
|
200
184
|
}
|
|
201
185
|
export {
|
|
202
|
-
|
|
186
|
+
je as default
|
|
203
187
|
};
|
package/lib/es/resources.js
CHANGED
|
@@ -1,167 +1,123 @@
|
|
|
1
|
-
import { P as
|
|
2
|
-
import { AsyncLocalStorage as
|
|
3
|
-
import { Router as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { getResourceExportDir as
|
|
11
|
-
new
|
|
12
|
-
const Q = async (
|
|
1
|
+
import { P as S, i as B, g as F, l as N, C as W, R as $, S as T, t as z, a as G } from "./chunks/site-state-BoVWlYLn.js";
|
|
2
|
+
import { AsyncLocalStorage as H } from "async_hooks";
|
|
3
|
+
import { Router as J } from "express";
|
|
4
|
+
import i from "fs";
|
|
5
|
+
import u from "joi";
|
|
6
|
+
import O from "lodash/groupBy";
|
|
7
|
+
import K from "lodash/sortBy";
|
|
8
|
+
import b, { join as Y } from "path";
|
|
9
|
+
import v from "@blocklet/sdk/lib/middlewares/auth";
|
|
10
|
+
import { getResourceExportDir as q } from "@blocklet/sdk/lib/component";
|
|
11
|
+
new H();
|
|
12
|
+
const Q = async (t, e, r) => {
|
|
13
13
|
try {
|
|
14
|
-
const { projectId:
|
|
15
|
-
if (!s)
|
|
16
|
-
return o();
|
|
17
|
-
const n = await w.findByPk(s);
|
|
14
|
+
const { projectId: n } = t.params;
|
|
18
15
|
if (!n)
|
|
19
|
-
return
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
return r();
|
|
17
|
+
const s = await S.findByPk(n);
|
|
18
|
+
if (!s)
|
|
19
|
+
return e?.status(404).json({ error: "Project not found" });
|
|
20
|
+
const o = t.user?.did, c = t.user?.role || "UNKNOWN_ROLE";
|
|
21
|
+
if (!o)
|
|
22
|
+
return e?.status(401).json({ error: "Authentication required" });
|
|
23
|
+
if (B()) {
|
|
24
|
+
const f = s.createdBy === o, I = F()?.includes?.(c);
|
|
25
|
+
if (!f && !I)
|
|
26
|
+
return e?.status(403).json({ error: "No permission to access this project in multi-tenant mode" });
|
|
27
27
|
} else if (!["owner", "admin", "pagesEditor"].includes(c))
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
} catch (
|
|
31
|
-
|
|
28
|
+
return e?.status(403).json({ error: "No permission to access this project in single-tenant mode" });
|
|
29
|
+
t.project = s, t.projectId = n, r();
|
|
30
|
+
} catch (n) {
|
|
31
|
+
N.error("Project middleware error:", n), e?.status(400).json({ error: "Internal server error" });
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
function
|
|
35
|
-
return new Promise((
|
|
36
|
-
const
|
|
37
|
-
|
|
34
|
+
function x(t, e) {
|
|
35
|
+
return new Promise((r, n) => {
|
|
36
|
+
const s = i.createReadStream(t), o = i.createWriteStream(e);
|
|
37
|
+
s.on("error", n), o.on("error", n), o.on("finish", r), s.pipe(o);
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
async function
|
|
41
|
-
await
|
|
42
|
-
const
|
|
43
|
-
for (const
|
|
44
|
-
const
|
|
45
|
-
|
|
40
|
+
async function C(t, e) {
|
|
41
|
+
await i.promises.mkdir(e, { recursive: !0 });
|
|
42
|
+
const r = await i.promises.readdir(t, { withFileTypes: !0 });
|
|
43
|
+
for (const n of r) {
|
|
44
|
+
const s = b.join(t, n.name), o = b.join(e, n.name);
|
|
45
|
+
n.isDirectory() ? await C(s, o) : await x(s, o);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
async function V(
|
|
49
|
-
(await
|
|
48
|
+
async function V(t, e) {
|
|
49
|
+
(await i.promises.stat(t)).isDirectory() ? await C(t, e) : await x(t, e);
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
return
|
|
54
|
-
},
|
|
55
|
-
const [
|
|
56
|
-
if (
|
|
57
|
-
},
|
|
58
|
-
const [
|
|
59
|
-
if (
|
|
60
|
-
},
|
|
61
|
-
const [
|
|
62
|
-
if (
|
|
63
|
-
},
|
|
51
|
+
const k = (t, e, r) => B() ? v()(t, e, r) : v({ roles: ["owner", "admin", "pagesEditor"] })(t, e, r), X = (t, e) => {
|
|
52
|
+
const r = q({ projectId: t, releaseId: e });
|
|
53
|
+
return Y(r, W, $);
|
|
54
|
+
}, w = J(), L = "@page", M = "@component", l = ":", y = "ALL", U = "@project", A = ({ pageId: t, projectId: e }) => [L, e, t].join(l), Z = (t) => {
|
|
55
|
+
const [e, r, n] = t.split(l);
|
|
56
|
+
if (e === L) return { pageId: n, projectId: r };
|
|
57
|
+
}, D = ({ componentId: t, projectId: e }) => [M, e, t].join(l), tt = (t) => {
|
|
58
|
+
const [e, r, n] = t.split(l);
|
|
59
|
+
if (e === M) return { componentId: n, projectId: r };
|
|
60
|
+
}, et = (t) => [U, t].join(l), rt = (t) => {
|
|
61
|
+
const [e, r] = t.split(l);
|
|
62
|
+
if (e === U) return r;
|
|
63
|
+
}, ot = (t) => {
|
|
64
64
|
try {
|
|
65
|
-
return JSON.parse(
|
|
65
|
+
return JSON.parse(t);
|
|
66
66
|
} catch {
|
|
67
67
|
}
|
|
68
68
|
return {};
|
|
69
69
|
};
|
|
70
|
-
async function
|
|
71
|
-
const
|
|
72
|
-
const c =
|
|
73
|
-
if (c)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
id: k({ componentId: r.id, projectId: e }),
|
|
77
|
-
name: r.name || r.id
|
|
78
|
-
}));
|
|
79
|
-
return {
|
|
80
|
-
id: te(e),
|
|
81
|
-
name: o?.name || "Unnamed Project",
|
|
82
|
-
children: [
|
|
83
|
-
{ id: D({ pageId: P, projectId: e }), name: "Pages", children: s },
|
|
84
|
-
{
|
|
85
|
-
id: k({ componentId: P, projectId: e }),
|
|
86
|
-
name: "Components",
|
|
87
|
-
children: n
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
};
|
|
70
|
+
async function R(t) {
|
|
71
|
+
const e = await T.getStateByProjectId(t, "production"), r = await S.findByPk(t), n = e.pageIds.map((o) => {
|
|
72
|
+
const c = e.pages[o];
|
|
73
|
+
if (c) return { id: A({ pageId: o, projectId: t }), name: c.slug };
|
|
74
|
+
}).filter(Boolean), s = K(Object.values(e.components), (o) => o.index).map(({ data: o }) => ({ id: D({ componentId: o.id, projectId: t }), name: o.name || o.id }));
|
|
75
|
+
return { id: et(t), name: r?.name || "Unnamed Project", children: [{ id: A({ pageId: y, projectId: t }), name: "Pages", children: n }, { id: D({ componentId: y, projectId: t }), name: "Components", children: s }] };
|
|
91
76
|
}
|
|
92
|
-
|
|
93
|
-
const { projectId:
|
|
94
|
-
if (
|
|
95
|
-
|
|
77
|
+
w.get("/resources", k, async (t, e) => {
|
|
78
|
+
const { projectId: r } = ot(t.query.resourcesParams);
|
|
79
|
+
if (r) {
|
|
80
|
+
t.params = { ...t.params, projectId: r }, await Q(t, e, () => {
|
|
96
81
|
});
|
|
97
|
-
const
|
|
98
|
-
|
|
82
|
+
const o = await R(r);
|
|
83
|
+
e.json({ resources: [o] });
|
|
99
84
|
return;
|
|
100
85
|
}
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
// Add your permission check conditions here
|
|
104
|
-
// For example: userId: req.user.id
|
|
105
|
-
}
|
|
106
|
-
}), n = await Promise.all(s.map((r) => v(r.id)));
|
|
107
|
-
t.json({ resources: n });
|
|
86
|
+
const n = await S.findAll({ where: {} }), s = await Promise.all(n.map((o) => R(o.id)));
|
|
87
|
+
e.json({ resources: s });
|
|
108
88
|
});
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
releaseId:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const { resources: o, projectId: s, releaseId: n } = await se.validateAsync(e.body), r = "production", c = [], j = [];
|
|
117
|
-
for (const i of o) {
|
|
118
|
-
if (oe(i))
|
|
119
|
-
continue;
|
|
120
|
-
const { pageId: p, projectId: g } = q(i) || {};
|
|
121
|
-
if (p)
|
|
122
|
-
p === P || p && g && c.push({
|
|
123
|
-
pageId: p,
|
|
124
|
-
projectId: g
|
|
125
|
-
});
|
|
89
|
+
const nt = u.object({ projectId: u.string().required().min(1), releaseId: u.string().allow(""), resources: u.array().items(u.string()).required(), locale: u.string().allow("") });
|
|
90
|
+
w.post("/resources", k, async (t, e) => {
|
|
91
|
+
const { resources: r, projectId: n, releaseId: s } = await nt.validateAsync(t.body), o = "production", c = [], f = [];
|
|
92
|
+
for (const a of r) {
|
|
93
|
+
if (rt(a)) continue;
|
|
94
|
+
const { pageId: p, projectId: g } = Z(a) || {};
|
|
95
|
+
if (p) p === y || p && g && c.push({ pageId: p, projectId: g });
|
|
126
96
|
else {
|
|
127
|
-
const { componentId:
|
|
128
|
-
|
|
129
|
-
componentId: f,
|
|
130
|
-
projectId: d
|
|
131
|
-
});
|
|
97
|
+
const { componentId: j, projectId: d } = tt(a) || {};
|
|
98
|
+
j === y || j && d && f.push({ componentId: j, projectId: d });
|
|
132
99
|
}
|
|
133
100
|
}
|
|
134
|
-
const I =
|
|
135
|
-
|
|
136
|
-
for (const
|
|
137
|
-
const p = await
|
|
138
|
-
if (d?.length ||
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
pageIds: d,
|
|
142
|
-
componentIds: R
|
|
143
|
-
});
|
|
144
|
-
await V(u, y), a.rmSync(u, { recursive: !0, force: !0 });
|
|
101
|
+
const I = O(c, "projectId"), E = O(f, "projectId"), _ = /* @__PURE__ */ new Set([...Object.keys(I), ...Object.keys(E)]), P = X(n, s);
|
|
102
|
+
i.rmSync(P, { recursive: !0, force: !0 }), i.mkdirSync(P, { recursive: !0 });
|
|
103
|
+
for (const a of _) {
|
|
104
|
+
const p = await T.getStateByProjectId(a, o), g = I[a], j = E[a], d = g?.map((m) => m.pageId), h = j?.map((m) => m.componentId);
|
|
105
|
+
if (d?.length || h?.length) {
|
|
106
|
+
const m = await z(p, { exportAssets: !0, pageIds: d, componentIds: h });
|
|
107
|
+
await V(m, P), i.rmSync(m, { recursive: !0, force: !0 });
|
|
145
108
|
}
|
|
146
|
-
|
|
147
|
-
pageIds: d,
|
|
148
|
-
componentIds: R
|
|
149
|
-
});
|
|
109
|
+
N.info(`Exported resources for project ${a}`, { pageIds: d, componentIds: h });
|
|
150
110
|
}
|
|
151
|
-
|
|
111
|
+
e.json({});
|
|
152
112
|
});
|
|
153
|
-
|
|
154
|
-
const { states:
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
blockletTitle: n.blockletTitle,
|
|
158
|
-
components: {}
|
|
159
|
-
};
|
|
160
|
-
if (n.state.components && (r.components = n.state.components), Object.keys(r.components).length !== 0)
|
|
161
|
-
return r;
|
|
113
|
+
w.get("/all-resources", k, async (t, e) => {
|
|
114
|
+
const { states: r } = await G(), n = r?.map((s) => {
|
|
115
|
+
const o = { blockletId: s.blockletId, blockletTitle: s.blockletTitle, components: {} };
|
|
116
|
+
if (s.state.components && (o.components = s.state.components), Object.keys(o.components).length !== 0) return o;
|
|
162
117
|
}).filter(Boolean);
|
|
163
|
-
|
|
118
|
+
e.json(n);
|
|
164
119
|
});
|
|
120
|
+
var ft = w;
|
|
165
121
|
export {
|
|
166
|
-
|
|
122
|
+
ft as default
|
|
167
123
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit-inner-components",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Pages Kit inner components library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -71,21 +71,21 @@
|
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@arcblock/did-auth": "^1.20.15",
|
|
73
73
|
"@arcblock/did-auth-storage-nedb": "^1.7.1",
|
|
74
|
-
"@arcblock/did-connect": "^3.0.
|
|
75
|
-
"@arcblock/react-hooks": "^3.0.
|
|
76
|
-
"@arcblock/ux": "^3.0.
|
|
74
|
+
"@arcblock/did-connect": "^3.0.14",
|
|
75
|
+
"@arcblock/react-hooks": "^3.0.14",
|
|
76
|
+
"@arcblock/ux": "^3.0.14",
|
|
77
77
|
"@blocklet/ai-kit": "^0.1.79",
|
|
78
78
|
"@blocklet/ai-runtime": "^0.4.275",
|
|
79
79
|
"@blocklet/code-editor": "^0.4.275",
|
|
80
80
|
"@blocklet/embed": "^0.2.5",
|
|
81
|
-
"@blocklet/js-sdk": "^1.16.
|
|
81
|
+
"@blocklet/js-sdk": "^1.16.45",
|
|
82
82
|
"@blocklet/logger": "1.16.44",
|
|
83
83
|
"@blocklet/quickjs": "^0.4.275",
|
|
84
|
-
"@blocklet/sdk": "^1.16.
|
|
84
|
+
"@blocklet/sdk": "^1.16.45",
|
|
85
85
|
"@blocklet/studio-ui": "^0.4.275",
|
|
86
|
-
"@blocklet/tracker": "^1.16.
|
|
87
|
-
"@blocklet/ui-react": "^3.0.
|
|
88
|
-
"@blocklet/uploader": "^0.2.
|
|
86
|
+
"@blocklet/tracker": "^1.16.45",
|
|
87
|
+
"@blocklet/ui-react": "^3.0.14",
|
|
88
|
+
"@blocklet/uploader": "^0.2.2",
|
|
89
89
|
"@blocklet/uploader-server": "^0.2.0",
|
|
90
90
|
"@emotion/cache": "^11.14.0",
|
|
91
91
|
"@emotion/css": "^11.13.5",
|
|
@@ -203,8 +203,8 @@
|
|
|
203
203
|
"yaml": "^2.5.0",
|
|
204
204
|
"yjs": "^13.6.18",
|
|
205
205
|
"zustand": "^4.5.5",
|
|
206
|
-
"@blocklet/pages-kit": "^0.6.
|
|
207
|
-
"@blocklet/pages-kit-block-studio": "^0.6.
|
|
206
|
+
"@blocklet/pages-kit": "^0.6.3",
|
|
207
|
+
"@blocklet/pages-kit-block-studio": "^0.6.3"
|
|
208
208
|
},
|
|
209
209
|
"devDependencies": {
|
|
210
210
|
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),t=require("./state-B6BF5wJ-.js");function n({children:e}){const r=t.useProjectId();return s.jsx(t.StoreProvider,{url:t.getWssURL(r??""),name:"root",waitingSynced:!0,children:s.jsx(o,{children:e})})}function o({children:e}){const{state:r}=t.useStore();return e({state:r})}exports.default=n;
|