@blocklet/pages-kit-inner-components 0.4.25 → 0.4.27

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