@blocklet/pages-kit-inner-components 0.4.40 → 0.4.41

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.
@@ -1,4 +1,4 @@
1
- "use strict";const k=require("./_chunks/site-state-DtuL49Z6.js"),S=require("@blocklet/crawler/middlewares"),W=require("@blocklet/pages-kit/types"),J=require("@blocklet/pages-kit/utils/preload"),G=require("@blocklet/sdk/lib/component"),D=require("@blocklet/sdk/lib/config"),z=require("cheerio"),K=require("express"),A=require("fs"),Q=require("mustache"),I=require("path"),j=require("ufo"),q=e=>e&&e.__esModule?e:{default:e};function V(e){if(e&&e.__esModule)return e;const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const d=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(l,t,d.get?d:{enumerable:!0,get:()=>e[t]})}}return l.default=e,Object.freeze(l)}const a=q(D),U=V(z),X=q(Q),Y=["/assets/"],R=()=>[!0,"true"].includes(a.default.env.preferences.allowCrawler);function x(){R()?S.initCronCrawlBlocklet({time:"30 30 */12 * * *",options:{}}):S.cancelCronCrawlBlocklet()}x();a.default.events.on(a.default.Events.envUpdate,x);function Z({app:e,viteDevServer:l,state:t}){let d;if(l){const r=A.readFileSync(I.resolve(process.cwd(),"./index.html"),"utf-8");e.use(async(b,T,y)=>{const v=b.originalUrl;d=await l.transformIndexHtml(v,r),y()})}else d=A.readFileSync(I.resolve(process.env.BLOCKLET_APP_DIR,"dist/index.html"),"utf-8");const C=K.Router();C.use(S.initSEOMiddleware({autoReturnHtml:!1,allowCrawler:R})),C.get("/:path(*)?",async(r,b,T)=>{var E,L,M;if(Y.some(c=>r.path.startsWith(c))){T();return}const y=performance.now(),v=()=>Math.round(performance.now()-y),B="production";let o,p,h=d;if(r.path.startsWith("/pages")){const c=r.params.lang,g=r.cookies.nf_lang,w=new Set([...a.default.env.languages.map(f=>f.code)]);let m=(c&&w.has(c)?c:void 0)||(w.has(g)?g:void 0)||[...w][0];if((!m||!((E=t.supportedLocales)!=null&&E.find(f=>f.locale===m)))&&(m=((M=(L=t.supportedLocales)==null?void 0:L[0])==null?void 0:M.locale)||""),m){const f=[];Object.values(t.pages).forEach(s=>{const P=Object.values((s==null?void 0:s.sections)??{}).filter(i=>{var _;return i.component==="custom-component"&&((_=i.config)==null?void 0:_.componentId)}).map(i=>{var _,O;return{id:i.id,componentId:i.config.componentId,useCache:i.config.useCache,cacheDuration:i.config.cacheDuration,properties:(O=(_=i.locales)==null?void 0:_[m])==null?void 0:O.properties}});f.push(...P)});const N=new Promise((s,P)=>{setTimeout(()=>{P(new Error("getPreloadComponents timeout in promise race, skip it"))},90*1e3)});try{await Promise.race([N,k.getPreloadComponents({mode:B,req:r,state:t,locale:m,instances:f,module:W.PreloadComponentScriptModule.UMD_FN}).then(s=>{s&&(p=J.injectPreloadComponents(s))})])}catch(s){k.logger.warn("getPreloadComponents timeout in promise race, skip inject html elements"),k.logger.warn(s)}}}try{const c=(o==null?void 0:o.title)||a.default.env.appName,g=(o==null?void 0:o.description)||a.default.env.appDescription,w=j.withQuery(j.joinURL(a.default.env.appUrl,"/.well-known/service/blocklet/og.png"),{title:c,description:g});h=X.default.render(d,{ogTitle:c,ogDescription:g,ogImage:F(o==null?void 0:o.image)||w,pagesPublishedAt:(t==null?void 0:t.config.publishedAt)||new Date().getTime()})}catch{}const n=t==null?void 0:t.config.fontFamily,H=r.query.mode==="draft"||r.url.includes("preview"),u=U.load(h);u("head").find("#injected-head-elements").replaceWith(`
1
+ "use strict";const k=require("./_chunks/site-state-DtuL49Z6.js"),S=require("@blocklet/crawler/middlewares"),W=require("@blocklet/pages-kit/types"),J=require("@blocklet/pages-kit/utils/preload"),G=require("@blocklet/sdk/lib/component"),D=require("@blocklet/sdk/lib/config"),z=require("cheerio"),K=require("express"),A=require("fs"),Q=require("mustache"),I=require("path"),j=require("ufo"),q=e=>e&&e.__esModule?e:{default:e};function V(e){if(e&&e.__esModule)return e;const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const p=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(l,t,p.get?p:{enumerable:!0,get:()=>e[t]})}}return l.default=e,Object.freeze(l)}const d=q(D),U=V(z),X=q(Q),Y=["/assets/"],R=()=>[!0,"true"].includes(d.default.env.preferences.allowCrawler);function x(){R()?S.initCronCrawlBlocklet({time:"30 30 */12 * * *",options:{}}):S.cancelCronCrawlBlocklet()}x();d.default.events.on(d.default.Events.envUpdate,x);function Z({app:e,viteDevServer:l,state:t}){let p;if(l){const r=A.readFileSync(I.resolve(process.cwd(),"./index.html"),"utf-8");e.use(async(b,T,y)=>{const v=b.originalUrl;p=await l.transformIndexHtml(v,r),y()})}else p=A.readFileSync(I.resolve(process.env.BLOCKLET_APP_DIR,"dist/index.html"),"utf-8");const C=K.Router();C.use(S.initSEOMiddleware({autoReturnHtml:!1,allowCrawler:R})),C.get("/:path(*)?",async(r,b,T)=>{var E,L,M;if(Y.some(c=>{var i;return(i=r.path)==null?void 0:i.startsWith(c)})){T();return}const y=performance.now(),v=()=>Math.round(performance.now()-y),B="production";let o,u,g=p;if(r.path.startsWith("/pages")){const c=r.params.lang,i=r.cookies.nf_lang,w=new Set([...d.default.env.languages.map(h=>h.code)]);let f=(c&&w.has(c)?c:void 0)||(w.has(i)?i:void 0)||[...w][0];if((!f||!((E=t.supportedLocales)!=null&&E.find(h=>h.locale===f)))&&(f=((M=(L=t.supportedLocales)==null?void 0:L[0])==null?void 0:M.locale)||""),f){const h=[];Object.values(t.pages).forEach(s=>{const P=Object.values((s==null?void 0:s.sections)??{}).filter(a=>{var _;return a.component==="custom-component"&&((_=a.config)==null?void 0:_.componentId)}).map(a=>{var _,O;return{id:a.id,componentId:a.config.componentId,useCache:a.config.useCache,cacheDuration:a.config.cacheDuration,properties:(O=(_=a.locales)==null?void 0:_[f])==null?void 0:O.properties}});h.push(...P)});const N=new Promise((s,P)=>{setTimeout(()=>{P(new Error("getPreloadComponents timeout in promise race, skip it"))},90*1e3)});try{await Promise.race([N,k.getPreloadComponents({mode:B,req:r,state:t,locale:f,instances:h,module:W.PreloadComponentScriptModule.UMD_FN}).then(s=>{s&&(u=J.injectPreloadComponents(s))})])}catch(s){k.logger.warn("getPreloadComponents timeout in promise race, skip inject html elements"),k.logger.warn(s)}}}try{const c=(o==null?void 0:o.title)||d.default.env.appName,i=(o==null?void 0:o.description)||d.default.env.appDescription,w=j.withQuery(j.joinURL(d.default.env.appUrl,"/.well-known/service/blocklet/og.png"),{title:c,description:i});g=X.default.render(p,{ogTitle:c,ogDescription:i,ogImage:F(o==null?void 0:o.image)||w,pagesPublishedAt:(t==null?void 0:t.config.publishedAt)||new Date().getTime()})}catch{}const n=t==null?void 0:t.config.fontFamily,H=r.query.mode==="draft"||r.url.includes("preview"),m=U.load(g);m("head").find("#injected-head-elements").replaceWith(`
2
2
  ${o!=null&&o.backgroundColor?`<meta name="theme-color" content="${o.backgroundColor}" /><style>html,body,#app {background-color: ${o.backgroundColor} !important;}</style>`:""}
3
3
  ${n!=null&&n.title?`<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${n.title}&display=swap">`:""}
4
4
  ${n!=null&&n.description&&(n==null?void 0:n.description)!==(n==null?void 0:n.title)?`<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${n.description}&display=swap">`:""}
@@ -20,4 +20,4 @@
20
20
  darkMode: "class",
21
21
  };
22
22
  <\/script>`:""}
23
- `);const $=D.getBlockletJs();if($&&u('script[src="__blocklet__.js"]').replaceWith(`<script>${$}<\/script>`),p!=null&&p.html&&u("head").find("#injected-html-elements").replaceWith(p.html),r.cachedHtml){const c=U.load(r.cachedHtml);u("body").html(c("body").html()||"")}h=u.html(),b.send(h),k.logger.info(`[html] render: ${r.path}, ${v()}ms`),u.root().children().remove(),h=null,o=null,p=null}),e.use(C)}function F(e){const l=G.getComponentMountPoint("image-bin");return l&&e&&!/^(https?:\/\/|\/)/.test(e)?a.default.env.appUrl+j.joinURL(l,"uploads",e):e}module.exports=Z;
23
+ `);const $=D.getBlockletJs();if($&&m('script[src="__blocklet__.js"]').replaceWith(`<script>${$}<\/script>`),u!=null&&u.html&&m("head").find("#injected-html-elements").replaceWith(u.html),r.cachedHtml){const c=U.load(r.cachedHtml);m("body").html(c("body").html()||"")}g=m.html(),b.send(g),k.logger.info(`[html] render: ${r.path}, ${v()}ms`),m.root().children().remove(),g=null,o=null,u=null}),e.use(C)}function F(e){const l=G.getComponentMountPoint("image-bin");return l&&e&&!/^(https?:\/\/|\/)/.test(e)?d.default.env.appUrl+j.joinURL(l,"uploads",e):e}module.exports=Z;
@@ -3,14 +3,14 @@ import { initCronCrawlBlocklet as W, cancelCronCrawlBlocklet as N, initSEOMiddle
3
3
  import { PreloadComponentScriptModule as G } from "@blocklet/pages-kit/types";
4
4
  import { injectPreloadComponents as K } from "@blocklet/pages-kit/utils/preload";
5
5
  import { getComponentMountPoint as Q } from "@blocklet/sdk/lib/component";
6
- import s, { getBlockletJs as z } from "@blocklet/sdk/lib/config";
6
+ import a, { getBlockletJs as z } from "@blocklet/sdk/lib/config";
7
7
  import * as I from "cheerio";
8
8
  import { Router as V } from "express";
9
9
  import { readFileSync as j } from "fs";
10
10
  import X from "mustache";
11
11
  import { resolve as U } from "path";
12
12
  import { withQuery as Y, joinURL as M } from "ufo";
13
- const Z = ["/assets/"], D = () => [!0, "true"].includes(s.env.preferences.allowCrawler);
13
+ const Z = ["/assets/"], D = () => [!0, "true"].includes(a.env.preferences.allowCrawler);
14
14
  function O() {
15
15
  D() ? W({
16
16
  time: "30 30 */12 * * *",
@@ -18,19 +18,19 @@ function O() {
18
18
  }) : N();
19
19
  }
20
20
  O();
21
- s.events.on(s.Events.envUpdate, O);
21
+ a.events.on(a.Events.envUpdate, O);
22
22
  function me({
23
23
  app: c,
24
- viteDevServer: u,
24
+ viteDevServer: h,
25
25
  // projectId,
26
26
  state: n
27
27
  }) {
28
28
  let C;
29
- if (u) {
29
+ if (h) {
30
30
  const t = j(U(process.cwd(), "./index.html"), "utf-8");
31
31
  c.use(async (b, $, y) => {
32
32
  const _ = b.originalUrl;
33
- C = await u.transformIndexHtml(_, t), y();
33
+ C = await h.transformIndexHtml(_, t), y();
34
34
  });
35
35
  } else
36
36
  C = j(U(process.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
@@ -42,34 +42,37 @@ function me({
42
42
  })
43
43
  ), k.get("/:path(*)?", async (t, b, $) => {
44
44
  var T, S, L;
45
- if (Z.some((r) => t.path.startsWith(r))) {
45
+ if (Z.some((r) => {
46
+ var i;
47
+ return (i = t.path) == null ? void 0 : i.startsWith(r);
48
+ })) {
46
49
  $();
47
50
  return;
48
51
  }
49
52
  const y = performance.now(), _ = () => Math.round(performance.now() - y), R = "production";
50
- let e, a, h = C;
53
+ let e, p, f = C;
51
54
  if (t.path.startsWith("/pages")) {
52
- const r = t.params.lang, f = t.cookies.nf_lang, g = /* @__PURE__ */ new Set([...s.env.languages.map((d) => d.code)]);
53
- let m = (r && g.has(r) ? r : void 0) || (g.has(f) ? f : void 0) || [...g][0];
54
- if ((!m || !((T = n.supportedLocales) != null && T.find((d) => d.locale === m))) && (m = ((L = (S = n.supportedLocales) == null ? void 0 : S[0]) == null ? void 0 : L.locale) || ""), m) {
55
- const d = [];
55
+ const r = t.params.lang, i = t.cookies.nf_lang, g = /* @__PURE__ */ new Set([...a.env.languages.map((u) => u.code)]);
56
+ let d = (r && g.has(r) ? r : void 0) || (g.has(i) ? i : void 0) || [...g][0];
57
+ if ((!d || !((T = n.supportedLocales) != null && T.find((u) => u.locale === d))) && (d = ((L = (S = n.supportedLocales) == null ? void 0 : S[0]) == null ? void 0 : L.locale) || ""), d) {
58
+ const u = [];
56
59
  Object.values(n.pages).forEach((l) => {
57
60
  const v = Object.values((l == null ? void 0 : l.sections) ?? {}).filter(
58
- (i) => {
61
+ (s) => {
59
62
  var w;
60
- return i.component === "custom-component" && ((w = i.config) == null ? void 0 : w.componentId);
63
+ return s.component === "custom-component" && ((w = s.config) == null ? void 0 : w.componentId);
61
64
  }
62
- ).map((i) => {
65
+ ).map((s) => {
63
66
  var w, A;
64
67
  return {
65
- id: i.id,
66
- componentId: i.config.componentId,
67
- useCache: i.config.useCache,
68
- cacheDuration: i.config.cacheDuration,
69
- properties: (A = (w = i.locales) == null ? void 0 : w[m]) == null ? void 0 : A.properties
68
+ id: s.id,
69
+ componentId: s.config.componentId,
70
+ useCache: s.config.useCache,
71
+ cacheDuration: s.config.cacheDuration,
72
+ properties: (A = (w = s.locales) == null ? void 0 : w[d]) == null ? void 0 : A.properties
70
73
  };
71
74
  });
72
- d.push(...v);
75
+ u.push(...v);
73
76
  });
74
77
  const B = new Promise((l, v) => {
75
78
  setTimeout(() => {
@@ -83,11 +86,11 @@ function me({
83
86
  mode: R,
84
87
  req: t,
85
88
  state: n,
86
- locale: m,
87
- instances: d,
89
+ locale: d,
90
+ instances: u,
88
91
  module: G.UMD_FN
89
92
  }).then((l) => {
90
- l && (a = K(l));
93
+ l && (p = K(l));
91
94
  })
92
95
  ]);
93
96
  } catch (l) {
@@ -96,20 +99,20 @@ function me({
96
99
  }
97
100
  }
98
101
  try {
99
- const r = (e == null ? void 0 : e.title) || s.env.appName, f = (e == null ? void 0 : e.description) || s.env.appDescription, g = Y(M(s.env.appUrl, "/.well-known/service/blocklet/og.png"), {
102
+ const r = (e == null ? void 0 : e.title) || a.env.appName, i = (e == null ? void 0 : e.description) || a.env.appDescription, g = Y(M(a.env.appUrl, "/.well-known/service/blocklet/og.png"), {
100
103
  title: r,
101
- description: f
104
+ description: i
102
105
  });
103
- h = X.render(C, {
106
+ f = X.render(C, {
104
107
  ogTitle: r,
105
- ogDescription: f,
108
+ ogDescription: i,
106
109
  ogImage: F(e == null ? void 0 : e.image) || g,
107
110
  pagesPublishedAt: (n == null ? void 0 : n.config.publishedAt) || (/* @__PURE__ */ new Date()).getTime()
108
111
  });
109
112
  } catch {
110
113
  }
111
- const o = n == null ? void 0 : n.config.fontFamily, x = t.query.mode === "draft" || t.url.includes("preview"), p = I.load(h);
112
- p("head").find("#injected-head-elements").replaceWith(`
114
+ const o = n == null ? void 0 : n.config.fontFamily, x = t.query.mode === "draft" || t.url.includes("preview"), m = I.load(f);
115
+ m("head").find("#injected-head-elements").replaceWith(`
113
116
  ${e != null && e.backgroundColor ? `<meta name="theme-color" content="${e.backgroundColor}" /><style>html,body,#app {background-color: ${e.backgroundColor} !important;}</style>` : ""}
114
117
  ${o != null && o.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${o.title}&display=swap">` : ""}
115
118
  ${o != null && o.description && (o == null ? void 0 : o.description) !== (o == null ? void 0 : o.title) ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${o.description}&display=swap">` : ""}
@@ -133,16 +136,16 @@ function me({
133
136
  <\/script>` : ""}
134
137
  `);
135
138
  const E = z();
136
- if (E && p('script[src="__blocklet__.js"]').replaceWith(`<script>${E}<\/script>`), a != null && a.html && p("head").find("#injected-html-elements").replaceWith(a.html), t.cachedHtml) {
139
+ if (E && m('script[src="__blocklet__.js"]').replaceWith(`<script>${E}<\/script>`), p != null && p.html && m("head").find("#injected-html-elements").replaceWith(p.html), t.cachedHtml) {
137
140
  const r = I.load(t.cachedHtml);
138
- p("body").html(r("body").html() || "");
141
+ m("body").html(r("body").html() || "");
139
142
  }
140
- h = p.html(), b.send(h), P.info(`[html] render: ${t.path}, ${_()}ms`), p.root().children().remove(), h = null, e = null, a = null;
143
+ f = m.html(), b.send(f), P.info(`[html] render: ${t.path}, ${_()}ms`), m.root().children().remove(), f = null, e = null, p = null;
141
144
  }), c.use(k);
142
145
  }
143
146
  function F(c) {
144
- const u = Q("image-bin");
145
- return u && c && !/^(https?:\/\/|\/)/.test(c) ? s.env.appUrl + M(u, "uploads", c) : c;
147
+ const h = Q("image-bin");
148
+ return h && c && !/^(https?:\/\/|\/)/.test(c) ? a.env.appUrl + M(h, "uploads", c) : c;
146
149
  }
147
150
  export {
148
151
  me as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit-inner-components",
3
- "version": "0.4.40",
3
+ "version": "0.4.41",
4
4
  "description": "Pages Kit inner components library",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -202,8 +202,8 @@
202
202
  "yaml": "^2.5.0",
203
203
  "yjs": "^13.6.18",
204
204
  "zustand": "^4.5.5",
205
- "@blocklet/pages-kit": "^0.4.40",
206
- "@blocklet/pages-kit-block-studio": "^0.4.40"
205
+ "@blocklet/pages-kit": "^0.4.41",
206
+ "@blocklet/pages-kit-block-studio": "^0.4.41"
207
207
  },
208
208
  "devDependencies": {
209
209
  "@trivago/prettier-plugin-sort-imports": "^5.2.1",