@blocklet/pages-kit-inner-components 0.5.37 → 0.5.38
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/project-html.js +5 -5
- package/lib/es/project-html.js +38 -38
- package/package.json +3 -3
package/lib/cjs/project-html.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";const
|
|
2
|
-
${
|
|
1
|
+
"use strict";const H=require("@arcblock/did-auth-storage-nedb"),D=require("@blocklet/sdk/lib/config"),R=require("@blocklet/sdk/lib/service/auth"),z=require("@blocklet/sdk/lib/wallet"),J=require("@blocklet/sdk/lib/wallet-authenticator"),G=require("@blocklet/sdk/lib/wallet-handler"),P=require("path"),C=require("./chunks/site-state-CIPfhJn5.js"),Y=require("@arcblock/crawler-middleware"),Q=require("@blocklet/pages-kit/types"),V=require("@blocklet/pages-kit/utils/common"),x=require("@blocklet/pages-kit/utils/preload"),X=require("@blocklet/sdk/lib/component"),Z=require("cheerio/slim"),F=require("express"),W=require("fs"),ee=require("lodash/get"),te=require("mustache"),I=require("ufo"),d=n=>n&&n.__esModule?n:{default:n};function ne(n){if(n&&n.__esModule)return n;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const oe=d(H),a=d(D),ce=d(R),re=d(z),le=d(J),se=d(G),ae=d(P),L=ne(Z),ie=d(ee),de=d(te),ue=(n={})=>{const t={data:new Map,timers:new Map,set:(e,i,h=n.ttl||36e5)=>{n.max&&t.data.size>=n.max&&t.delete(t.data.keys().next().value),t.timers.has(e)&&clearTimeout(t.timers.get(e)),t.timers.set(e,setTimeout(()=>t.delete(e),h)),t.data.set(e,i)},get:e=>t.data.get(e),has:e=>t.data.has(e),delete:e=>(t.timers.has(e)&&clearTimeout(t.timers.get(e)),t.timers.delete(e),t.data.delete(e)),clear:()=>{t.data.clear();for(const e of t.timers.values())clearTimeout(e);t.timers.clear()}};return t},O=ue({max:1,ttl:1e3*30});re.default();const pe=new le.default;new se.default({authenticator:pe,tokenStorage:new oe.default({dbPath:ae.default.join(a.default.env.dataDir,"auth.db")})});const fe=new ce.default,he=async()=>{try{const n=O.get("blockletInfo");if(n)return n;const{blocklet:t}=await fe.getBlocklet();return O.set("blockletInfo",t),t}catch{return null}},me=["/assets/"];function ge({app:n,viteDevServer:t,state:e}){let i;if(t){const o=W.readFileSync(P.resolve(process.cwd(),"./index.html"),"utf-8");n.use(async(S,v,T)=>{const A=S.originalUrl;i=await t.transformIndexHtml(A,o),T()})}else i=W.readFileSync(P.resolve(process.env.BLOCKLET_APP_DIR,"dist/index.html"),"utf-8");const h=F.Router();h.use((o,S,v)=>{if(o.headers["x-unique-record"]==="dial_http"){C.logger.info("[html] dial http request, return 200 status code"),S.status(200).send("ok");return}v()}),a.default.env.preferences.snapkitEnabled&&a.default.env.preferences.snapkitEndpoint&&a.default.env.SNAP_KIT_ACCESS_KEY&&h.use(Y.createSnapshotMiddleware({endpoint:a.default.env.preferences.snapkitEndpoint,accessKey:a.default.env.SNAP_KIT_ACCESS_KEY,cacheMax:a.default.env.preferences.snapkitCacheSize||100})),h.get("/:path(*)?",async(o,S,v)=>{var E,M,j;if(me.some(s=>{var p;return(p=o.path)==null?void 0:p.startsWith(s)})){v();return}const T=performance.now(),A=()=>Math.round(performance.now()-T),U="production";let r,m,b=i;if(o.path.startsWith("/pages")){const s=o.params.lang,p=o.cookies.nf_lang,k=new Set([...a.default.env.languages.map(w=>w.code)]);let _=(s&&k.has(s)?s:void 0)||(k.has(p)?p:void 0)||[...k][0];if((!_||!((E=e.supportedLocales)!=null&&E.find(w=>w.locale===_)))&&(_=((j=(M=e.supportedLocales)==null?void 0:M[0])==null?void 0:j.locale)||""),_){const w=[];Object.values(e.pages).forEach(l=>{const B=Object.values((l==null?void 0:l.sections)??{}).filter(f=>{var y;return f.component==="custom-component"&&((y=f.config)==null?void 0:y.componentId)}).map(f=>{var y,$;return{id:f.id,componentId:f.config.componentId,useCache:f.config.useCache,cacheDuration:f.config.cacheDuration,properties:($=(y=l==null?void 0:l.dataSource)==null?void 0:y[f.id])==null?void 0:$[_]}});w.push(...B)});const N=new Promise(l=>{setTimeout(()=>{l({})},90*1e3)});try{await Promise.race([N,C.getPreloadComponents({mode:U,req:o,state:e,locale:_,instances:w,module:Q.PreloadComponentScriptModule.UMD_FN}).then(l=>{l&&(m=x.injectPreloadComponents(l))})])}catch(l){C.logger.warn("getPreloadComponents timeout in promise race, skip inject html elements",l)}}}try{const s=(r==null?void 0:r.title)||a.default.env.appName,p=(r==null?void 0:r.description)||a.default.env.appDescription,k=I.withQuery(I.joinURL(a.default.env.appUrl,"/.well-known/service/blocklet/og.png"),{title:s,description:p});b=de.default.render(i,{ogTitle:s,ogDescription:p,ogImage:_e(r==null?void 0:r.image)||k,pagesPublishedAt:(e==null?void 0:e.config.publishedAt)||new Date().getTime()})}catch{}const c=e==null?void 0:e.config.fontFamily,K=o.query.mode==="draft"||o.url.includes("preview"),g=L.load(b);let u=r==null?void 0:r.backgroundColor;if(u&&V.isMuiColorKey(u)){const s=await he();u=ie.default(s,`settings.theme.light.palette.${u}`,u)}g("head").find("#injected-head-elements").replaceWith(`
|
|
2
|
+
${u?`<meta name="theme-color" content="${u}" /><style>html,body,#app {background-color: ${u};}</style>`:""}
|
|
3
3
|
${c!=null&&c.title?`<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${c.title}&display=swap">`:""}
|
|
4
4
|
${c!=null&&c.description&&(c==null?void 0:c.description)!==(c==null?void 0:c.title)?`<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${c.description}&display=swap">`:""}
|
|
5
5
|
<script>
|
|
6
6
|
|
|
7
|
-
window.__PAGE_STATE__ =
|
|
7
|
+
window.__PAGE_STATE__ = ${x.safeJSONStringify(e||null)};
|
|
8
8
|
|
|
9
9
|
document.querySelectorAll('link[rel="preload"][as="style"]').forEach(function (link) {
|
|
10
10
|
const l = document.createElement('link');
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
});
|
|
15
15
|
<\/script>
|
|
16
16
|
|
|
17
|
-
${
|
|
17
|
+
${K?`<script src="https://cdn.tailwindcss.com"><\/script>
|
|
18
18
|
<script>
|
|
19
19
|
window.tailwind.config = {
|
|
20
20
|
darkMode: "class",
|
|
21
21
|
};
|
|
22
22
|
<\/script>`:""}
|
|
23
|
-
`);const q=
|
|
23
|
+
`);const q=D.getBlockletJs();if(q&&g('script[src="__blocklet__.js"]').replaceWith(`<script>${q}<\/script>`),m!=null&&m.html&&g("head").find("#injected-html-elements").replaceWith(m.html),o.cachedHtml){const s=L.load(o.cachedHtml);g("body").html(s("body").html()||"")}b=g.html(),S.send(b),C.logger.info(`[html] render: ${o.path}, ${A()}ms`),g.root().children().remove(),b=null,r=null,m=null}),n.use(h)}function _e(n){const t=X.getComponentMountPoint("image-bin");return t&&n&&!/^(https?:\/\/|\/)/.test(n)?a.default.env.appUrl+I.joinURL(t,"uploads",n):n}module.exports=ge;
|
package/lib/es/project-html.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import l, { getBlockletJs as
|
|
3
|
-
import
|
|
1
|
+
import N from "@arcblock/did-auth-storage-nedb";
|
|
2
|
+
import l, { getBlockletJs as H } from "@blocklet/sdk/lib/config";
|
|
3
|
+
import O from "@blocklet/sdk/lib/service/auth";
|
|
4
4
|
import R from "@blocklet/sdk/lib/wallet";
|
|
5
5
|
import J from "@blocklet/sdk/lib/wallet-authenticator";
|
|
6
6
|
import z from "@blocklet/sdk/lib/wallet-handler";
|
|
@@ -9,15 +9,15 @@ import { l as T, g as Y } from "./chunks/site-state-CfrteYXm.js";
|
|
|
9
9
|
import { createSnapshotMiddleware as Q } from "@arcblock/crawler-middleware";
|
|
10
10
|
import { PreloadComponentScriptModule as V } from "@blocklet/pages-kit/types";
|
|
11
11
|
import { isMuiColorKey as X } from "@blocklet/pages-kit/utils/common";
|
|
12
|
-
import { injectPreloadComponents as Z } from "@blocklet/pages-kit/utils/preload";
|
|
13
|
-
import { getComponentMountPoint as
|
|
12
|
+
import { injectPreloadComponents as Z, safeJSONStringify as q } from "@blocklet/pages-kit/utils/preload";
|
|
13
|
+
import { getComponentMountPoint as F } from "@blocklet/sdk/lib/component";
|
|
14
14
|
import * as M from "cheerio/slim";
|
|
15
|
-
import { Router as
|
|
15
|
+
import { Router as ee } from "express";
|
|
16
16
|
import { readFileSync as L } from "fs";
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import { withQuery as
|
|
20
|
-
const
|
|
17
|
+
import te from "lodash/get";
|
|
18
|
+
import oe from "mustache";
|
|
19
|
+
import { withQuery as ne, joinURL as W } from "ufo";
|
|
20
|
+
const re = (o = {}) => {
|
|
21
21
|
const t = {
|
|
22
22
|
data: /* @__PURE__ */ new Map(),
|
|
23
23
|
timers: /* @__PURE__ */ new Map(),
|
|
@@ -38,31 +38,31 @@ const ne = (o = {}) => {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
return t;
|
|
41
|
-
}, j =
|
|
41
|
+
}, j = re({
|
|
42
42
|
max: 1,
|
|
43
43
|
ttl: 1e3 * 30
|
|
44
44
|
// 30 seconds
|
|
45
45
|
});
|
|
46
46
|
R();
|
|
47
|
-
const
|
|
47
|
+
const ce = new J();
|
|
48
48
|
new z({
|
|
49
|
-
authenticator:
|
|
50
|
-
tokenStorage: new
|
|
49
|
+
authenticator: ce,
|
|
50
|
+
tokenStorage: new N({
|
|
51
51
|
dbPath: G.join(l.env.dataDir, "auth.db")
|
|
52
52
|
})
|
|
53
53
|
});
|
|
54
|
-
const
|
|
54
|
+
const ie = new O(), se = async () => {
|
|
55
55
|
try {
|
|
56
56
|
const o = j.get("blockletInfo");
|
|
57
57
|
if (o)
|
|
58
58
|
return o;
|
|
59
|
-
const { blocklet: t } = await
|
|
59
|
+
const { blocklet: t } = await ie.getBlocklet();
|
|
60
60
|
return j.set("blockletInfo", t), t;
|
|
61
61
|
} catch {
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
|
-
},
|
|
65
|
-
function
|
|
64
|
+
}, le = ["/assets/"];
|
|
65
|
+
function Ae({
|
|
66
66
|
app: o,
|
|
67
67
|
viteDevServer: t,
|
|
68
68
|
// projectId,
|
|
@@ -77,7 +77,7 @@ function Pe({
|
|
|
77
77
|
});
|
|
78
78
|
} else
|
|
79
79
|
d = L(x(process.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
|
|
80
|
-
const h =
|
|
80
|
+
const h = ee();
|
|
81
81
|
h.use((n, k, _) => {
|
|
82
82
|
if (n.headers["x-unique-record"] === "dial_http") {
|
|
83
83
|
T.info("[html] dial http request, return 200 status code"), k.status(200).send("ok");
|
|
@@ -92,14 +92,14 @@ function Pe({
|
|
|
92
92
|
})
|
|
93
93
|
), h.get("/:path(*)?", async (n, k, _) => {
|
|
94
94
|
var E, P, A;
|
|
95
|
-
if (
|
|
95
|
+
if (le.some((s) => {
|
|
96
96
|
var m;
|
|
97
97
|
return (m = n.path) == null ? void 0 : m.startsWith(s);
|
|
98
98
|
})) {
|
|
99
99
|
_();
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
|
-
const y = performance.now(), C = () => Math.round(performance.now() - y),
|
|
102
|
+
const y = performance.now(), C = () => Math.round(performance.now() - y), D = "production";
|
|
103
103
|
let c, u, S = d;
|
|
104
104
|
if (n.path.startsWith("/pages")) {
|
|
105
105
|
const s = n.params.lang, m = n.cookies.nf_lang, b = /* @__PURE__ */ new Set([...l.env.languages.map((w) => w.code)]);
|
|
@@ -107,7 +107,7 @@ function Pe({
|
|
|
107
107
|
if ((!g || !((E = e.supportedLocales) != null && E.find((w) => w.locale === g))) && (g = ((A = (P = e.supportedLocales) == null ? void 0 : P[0]) == null ? void 0 : A.locale) || ""), g) {
|
|
108
108
|
const w = [];
|
|
109
109
|
Object.values(e.pages).forEach((i) => {
|
|
110
|
-
const
|
|
110
|
+
const B = Object.values((i == null ? void 0 : i.sections) ?? {}).filter(
|
|
111
111
|
(p) => {
|
|
112
112
|
var v;
|
|
113
113
|
return p.component === "custom-component" && ((v = p.config) == null ? void 0 : v.componentId);
|
|
@@ -123,18 +123,18 @@ function Pe({
|
|
|
123
123
|
// ?? i.locales?.[respectLocale!]?.properties,
|
|
124
124
|
};
|
|
125
125
|
});
|
|
126
|
-
w.push(...
|
|
126
|
+
w.push(...B);
|
|
127
127
|
});
|
|
128
|
-
const
|
|
128
|
+
const U = new Promise((i) => {
|
|
129
129
|
setTimeout(() => {
|
|
130
130
|
i({});
|
|
131
131
|
}, 90 * 1e3);
|
|
132
132
|
});
|
|
133
133
|
try {
|
|
134
134
|
await Promise.race([
|
|
135
|
-
|
|
135
|
+
U,
|
|
136
136
|
Y({
|
|
137
|
-
mode:
|
|
137
|
+
mode: D,
|
|
138
138
|
req: n,
|
|
139
139
|
state: e,
|
|
140
140
|
locale: g,
|
|
@@ -150,23 +150,23 @@ function Pe({
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
try {
|
|
153
|
-
const s = (c == null ? void 0 : c.title) || l.env.appName, m = (c == null ? void 0 : c.description) || l.env.appDescription, b =
|
|
153
|
+
const s = (c == null ? void 0 : c.title) || l.env.appName, m = (c == null ? void 0 : c.description) || l.env.appDescription, b = ne(W(l.env.appUrl, "/.well-known/service/blocklet/og.png"), {
|
|
154
154
|
title: s,
|
|
155
155
|
description: m
|
|
156
156
|
});
|
|
157
|
-
S =
|
|
157
|
+
S = oe.render(d, {
|
|
158
158
|
ogTitle: s,
|
|
159
159
|
ogDescription: m,
|
|
160
|
-
ogImage:
|
|
160
|
+
ogImage: ae(c == null ? void 0 : c.image) || b,
|
|
161
161
|
pagesPublishedAt: (e == null ? void 0 : e.config.publishedAt) || (/* @__PURE__ */ new Date()).getTime()
|
|
162
162
|
});
|
|
163
163
|
} catch {
|
|
164
164
|
}
|
|
165
|
-
const r = e == null ? void 0 : e.config.fontFamily,
|
|
165
|
+
const r = e == null ? void 0 : e.config.fontFamily, K = n.query.mode === "draft" || n.url.includes("preview"), f = M.load(S);
|
|
166
166
|
let a = c == null ? void 0 : c.backgroundColor;
|
|
167
167
|
if (a && X(a)) {
|
|
168
|
-
const s = await
|
|
169
|
-
a =
|
|
168
|
+
const s = await se();
|
|
169
|
+
a = te(
|
|
170
170
|
s,
|
|
171
171
|
// 目前 dark 和 light 还是前端行为,后端通过 从 light 中获取
|
|
172
172
|
`settings.theme.light.palette.${a}`,
|
|
@@ -179,7 +179,7 @@ function Pe({
|
|
|
179
179
|
${r != null && r.description && (r == null ? void 0 : r.description) !== (r == null ? void 0 : r.title) ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${r.description}&display=swap">` : ""}
|
|
180
180
|
<script>
|
|
181
181
|
|
|
182
|
-
window.__PAGE_STATE__ =
|
|
182
|
+
window.__PAGE_STATE__ = ${q(e || null)};
|
|
183
183
|
|
|
184
184
|
document.querySelectorAll('link[rel="preload"][as="style"]').forEach(function (link) {
|
|
185
185
|
const l = document.createElement('link');
|
|
@@ -189,14 +189,14 @@ function Pe({
|
|
|
189
189
|
});
|
|
190
190
|
<\/script>
|
|
191
191
|
|
|
192
|
-
${
|
|
192
|
+
${K ? `<script src="https://cdn.tailwindcss.com"><\/script>
|
|
193
193
|
<script>
|
|
194
194
|
window.tailwind.config = {
|
|
195
195
|
darkMode: "class",
|
|
196
196
|
};
|
|
197
197
|
<\/script>` : ""}
|
|
198
198
|
`);
|
|
199
|
-
const I =
|
|
199
|
+
const I = H();
|
|
200
200
|
if (I && f('script[src="__blocklet__.js"]').replaceWith(`<script>${I}<\/script>`), u != null && u.html && f("head").find("#injected-html-elements").replaceWith(u.html), n.cachedHtml) {
|
|
201
201
|
const s = M.load(n.cachedHtml);
|
|
202
202
|
f("body").html(s("body").html() || "");
|
|
@@ -204,10 +204,10 @@ function Pe({
|
|
|
204
204
|
S = f.html(), k.send(S), T.info(`[html] render: ${n.path}, ${C()}ms`), f.root().children().remove(), S = null, c = null, u = null;
|
|
205
205
|
}), o.use(h);
|
|
206
206
|
}
|
|
207
|
-
function
|
|
208
|
-
const t =
|
|
207
|
+
function ae(o) {
|
|
208
|
+
const t = F("image-bin");
|
|
209
209
|
return t && o && !/^(https?:\/\/|\/)/.test(o) ? l.env.appUrl + W(t, "uploads", o) : o;
|
|
210
210
|
}
|
|
211
211
|
export {
|
|
212
|
-
|
|
212
|
+
Ae as default
|
|
213
213
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit-inner-components",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.38",
|
|
4
4
|
"description": "Pages Kit inner components library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -204,8 +204,8 @@
|
|
|
204
204
|
"yaml": "^2.5.0",
|
|
205
205
|
"yjs": "^13.6.18",
|
|
206
206
|
"zustand": "^4.5.5",
|
|
207
|
-
"@blocklet/pages-kit": "^0.5.
|
|
208
|
-
"@blocklet/pages-kit-block-studio": "^0.5.
|
|
207
|
+
"@blocklet/pages-kit": "^0.5.38",
|
|
208
|
+
"@blocklet/pages-kit-block-studio": "^0.5.38"
|
|
209
209
|
},
|
|
210
210
|
"devDependencies": {
|
|
211
211
|
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
|