@blocklet/pages-kit-inner-components 0.1.5 → 0.1.6

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.
@@ -0,0 +1,23 @@
1
+ "use strict";const S=require("./_chunks/components-CGE2womb.js"),T=require("@blocklet/crawler/middlewares"),J=require("@blocklet/pages-kit/types"),G=require("@blocklet/pages-kit/utils/preload"),z=require("@blocklet/sdk/lib/component"),R=require("@blocklet/sdk/lib/config"),K=require("cheerio"),Q=require("express"),L=require("fs"),V=require("mustache"),A=require("path"),D=require("ufo"),U=e=>e&&e.__esModule?e:{default:e};function X(e){if(e&&e.__esModule)return e;const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const d in e)if(d!=="default"){const t=Object.getOwnPropertyDescriptor(e,d);Object.defineProperty(a,d,t.get?t:{enumerable:!0,get:()=>e[d]})}}return a.default=e,Object.freeze(a)}const i=U(R),q=X(K),Y=U(V),Z=["/assets/"],x=()=>[!0,"true"].includes(i.default.env.preferences.allowCrawler);function H(){x()?T.initCronCrawlBlocklet({time:"30 30 */12 * * *",options:{}}):T.cancelCronCrawlBlocklet()}H();i.default.events.on(i.default.Events.envUpdate,H);function F({app:e,viteDevServer:a,projectId:d,state:t}){let _;if(a){const n=L.readFileSync(A.resolve(process.cwd(),"./index.html"),"utf-8");e.use(async(y,E,P)=>{const b=y.originalUrl;_=await a.transformIndexHtml(b,n),P()})}else _=L.readFileSync(A.resolve(process.env.BLOCKLET_APP_DIR,"dist/index.html"),"utf-8");const k=Q.Router();k.use(T.initSEOMiddleware({autoReturnHtml:!1,allowCrawler:x})),k.get("/:path(*)?",async(n,y,E)=>{var O,$,M;if(Z.some(c=>n.path.startsWith(c))){E();return}const P=performance.now(),b=()=>Math.round(performance.now()-P),N="production";let r,m,C=_;if(n.path.startsWith("/pages")){const c=n.params.lang,h=n.cookies.nf_lang,g=new Set([...i.default.env.languages.map(u=>u.code)]);let p=(c&&g.has(c)?c:void 0)||(g.has(h)?h:void 0)||[...g][0];if((!p||!((O=t.supportedLocales)!=null&&O.find(u=>u.locale===p)))&&(p=((M=($=t.supportedLocales)==null?void 0:$[0])==null?void 0:M.locale)||""),p){const u=[];Object.values(t.pages).forEach(s=>{const v=Object.values((s==null?void 0:s.sections)??{}).filter(l=>{var w;return l.component==="custom-component"&&((w=l.config)==null?void 0:w.componentId)}).map(l=>{var w,I;return{id:l.id,componentId:l.config.componentId,useCache:l.config.useCache,cacheDuration:l.config.cacheDuration,properties:(I=(w=l.locales)==null?void 0:w[p])==null?void 0:I.properties}});u.push(...v)});const B=new Promise((s,v)=>{setTimeout(()=>{v(new Error("getPreloadComponents timeout in promise race, skip it"))},90*1e3)});try{await Promise.race([B,S.getPreloadComponents({mode:N,req:n,state:t,locale:p,instances:u,module:J.PreloadComponentScriptModule.UMD_FN}).then(s=>{s&&(m=G.injectPreloadComponents(s))})])}catch{S.logger.warn("getPreloadComponents timeout in promise race, skip inject html elements")}}}try{const c=(r==null?void 0:r.title)||i.default.env.appName,h=(r==null?void 0:r.description)||i.default.env.appDescription,g=D.withQuery(D.joinURL(i.default.env.appUrl,"/.well-known/service/blocklet/og.png"),{title:c,description:h});C=Y.default.render(_,{ogTitle:c,ogDescription:h,ogImage:ee(r==null?void 0:r.image)||g,pagesPublishedAt:(t==null?void 0:t.config.publishedAt)||new Date().getTime()})}catch{}const o=t==null?void 0:t.config.fontFamily,W=n.query.mode==="draft"||n.url.includes("preview"),f=q.load(C);f("head").find("#injected-head-elements").replaceWith(`
2
+
3
+ ${o!=null&&o.title?`<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${o.title}&display=swap">`:""}
4
+ ${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">`:""}
5
+ <script>
6
+ window.__PROJECT_ID__ = "${d}"
7
+ window.__PAGE_STATE__ = ${JSON.stringify(t)}
8
+
9
+ document.querySelectorAll('link[rel="preload"][as="style"]').forEach(function (link) {
10
+ const l = document.createElement('link');
11
+ l.rel = 'stylesheet';
12
+ l.href = link.href;
13
+ document.head.appendChild(l);
14
+ });
15
+ <\/script>
16
+
17
+ ${W?`<script src="https://cdn.tailwindcss.com"><\/script>
18
+ <script>
19
+ window.tailwind.config = {
20
+ darkMode: "class",
21
+ };
22
+ <\/script>`:""}
23
+ `);const j=R.getBlockletJs();if(j&&f('script[src="__blocklet__.js"]').replaceWith(`<script>${j}<\/script>`),m!=null&&m.html&&f("head").find("#injected-html-elements").replaceWith(m.html),n.cachedHtml){const c=q.load(n.cachedHtml);f("body").html(c("body").html()||"")}C=f.html(),y.send(C),S.logger.info(`[html] render: ${n.path}, ${b()}ms`)}),e.use(k)}function ee(e){return z.getComponentMountPoint("image-bin"),e}module.exports=F;
@@ -400,10 +400,10 @@ const Te = O(
400
400
  export {
401
401
  te as C,
402
402
  j as G,
403
- oe as a,
404
- ne as b,
403
+ Pe as a,
404
+ oe as b,
405
405
  Oe as c,
406
- Pe as d,
406
+ ne as d,
407
407
  re as e,
408
408
  C as f,
409
409
  Te as g,
@@ -1,4 +1,4 @@
1
- import { l as D, c as Me, g as $e } from "./components-k4kCJg_V.js";
1
+ import { l as D, c as Me, g as $e } from "./components-2nieeR3G.js";
2
2
  import { memoize as Be } from "@blocklet/quickjs";
3
3
  import { getComponentWebEndpoint as xe, getResources as Ve, call as Ge } from "@blocklet/sdk/lib/component";
4
4
  import h from "@blocklet/sdk/lib/config";
@@ -6,7 +6,7 @@ import "@blocklet/sdk/lib/config";
6
6
  import "lru-cache";
7
7
  import "node-fetch";
8
8
  import "ufo";
9
- import { C as S, G as _, a as E, c as d, f as i, h as l, g as N, e as O, d as P, b as c } from "./_chunks/components-k4kCJg_V.js";
9
+ import { C as S, G as _, b as E, c as d, f as i, h as l, g as N, e as O, a as P, d as c } from "./_chunks/components-2nieeR3G.js";
10
10
  export {
11
11
  S as CUSTOM_COMPONENT_CACHE_DURATION_IN_SECONDS,
12
12
  _ as GET_SERVER_SIDE_PROPS_TIMEOUT_IN_SECONDS,
@@ -0,0 +1,148 @@
1
+ import { a as W, l as L } from "./_chunks/components-2nieeR3G.js";
2
+ import { initCronCrawlBlocklet as B, cancelCronCrawlBlocklet as J, initSEOMiddleware as N } from "@blocklet/crawler/middlewares";
3
+ import { PreloadComponentScriptModule as G } from "@blocklet/pages-kit/types";
4
+ import { injectPreloadComponents as K } from "@blocklet/pages-kit/utils/preload";
5
+ import { getComponentMountPoint as Q } from "@blocklet/sdk/lib/component";
6
+ import l, { getBlockletJs as z } from "@blocklet/sdk/lib/config";
7
+ import * as A from "cheerio";
8
+ import { Router as V } from "express";
9
+ import { readFileSync as j } from "fs";
10
+ import X from "mustache";
11
+ import { resolve as D } from "path";
12
+ import { withQuery as Y, joinURL as Z } from "ufo";
13
+ const F = ["/assets/"], M = () => [!0, "true"].includes(l.env.preferences.allowCrawler);
14
+ function O() {
15
+ M() ? B({
16
+ time: "30 30 */12 * * *",
17
+ options: {}
18
+ }) : J();
19
+ }
20
+ O();
21
+ l.events.on(l.Events.envUpdate, O);
22
+ function de({
23
+ app: p,
24
+ viteDevServer: y,
25
+ projectId: R,
26
+ state: t
27
+ }) {
28
+ let g;
29
+ if (y) {
30
+ const o = j(D(process.cwd(), "./index.html"), "utf-8");
31
+ p.use(async (_, E, k) => {
32
+ const P = _.originalUrl;
33
+ g = await y.transformIndexHtml(P, o), k();
34
+ });
35
+ } else
36
+ g = j(D(process.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
37
+ const C = V();
38
+ C.use(
39
+ N({
40
+ autoReturnHtml: !1,
41
+ allowCrawler: M
42
+ })
43
+ ), C.get("/:path(*)?", async (o, _, E) => {
44
+ var $, S, b;
45
+ if (F.some((n) => o.path.startsWith(n))) {
46
+ E();
47
+ return;
48
+ }
49
+ const k = performance.now(), P = () => Math.round(performance.now() - k), U = "production";
50
+ let r, m, w = g;
51
+ if (o.path.startsWith("/pages")) {
52
+ const n = o.params.lang, h = o.cookies.nf_lang, u = /* @__PURE__ */ new Set([...l.env.languages.map((a) => a.code)]);
53
+ let s = (n && u.has(n) ? n : void 0) || (u.has(h) ? h : void 0) || [...u][0];
54
+ if ((!s || !(($ = t.supportedLocales) != null && $.find((a) => a.locale === s))) && (s = ((b = (S = t.supportedLocales) == null ? void 0 : S[0]) == null ? void 0 : b.locale) || ""), s) {
55
+ const a = [];
56
+ Object.values(t.pages).forEach((i) => {
57
+ const v = Object.values((i == null ? void 0 : i.sections) ?? {}).filter(
58
+ (c) => {
59
+ var f;
60
+ return c.component === "custom-component" && ((f = c.config) == null ? void 0 : f.componentId);
61
+ }
62
+ ).map((c) => {
63
+ var f, I;
64
+ return {
65
+ id: c.id,
66
+ componentId: c.config.componentId,
67
+ useCache: c.config.useCache,
68
+ cacheDuration: c.config.cacheDuration,
69
+ properties: (I = (f = c.locales) == null ? void 0 : f[s]) == null ? void 0 : I.properties
70
+ };
71
+ });
72
+ a.push(...v);
73
+ });
74
+ const H = new Promise((i, v) => {
75
+ setTimeout(() => {
76
+ v(new Error("getPreloadComponents timeout in promise race, skip it"));
77
+ }, 90 * 1e3);
78
+ });
79
+ try {
80
+ await Promise.race([
81
+ H,
82
+ W({
83
+ mode: U,
84
+ req: o,
85
+ state: t,
86
+ locale: s,
87
+ instances: a,
88
+ module: G.UMD_FN
89
+ }).then((i) => {
90
+ i && (m = K(i));
91
+ })
92
+ ]);
93
+ } catch {
94
+ L.warn("getPreloadComponents timeout in promise race, skip inject html elements");
95
+ }
96
+ }
97
+ }
98
+ try {
99
+ const n = (r == null ? void 0 : r.title) || l.env.appName, h = (r == null ? void 0 : r.description) || l.env.appDescription, u = Y(Z(l.env.appUrl, "/.well-known/service/blocklet/og.png"), {
100
+ title: n,
101
+ description: h
102
+ });
103
+ w = X.render(g, {
104
+ ogTitle: n,
105
+ ogDescription: h,
106
+ ogImage: q(r == null ? void 0 : r.image) || u,
107
+ pagesPublishedAt: (t == null ? void 0 : t.config.publishedAt) || (/* @__PURE__ */ new Date()).getTime()
108
+ });
109
+ } catch {
110
+ }
111
+ const e = t == null ? void 0 : t.config.fontFamily, x = o.query.mode === "draft" || o.url.includes("preview"), d = A.load(w);
112
+ d("head").find("#injected-head-elements").replaceWith(`
113
+
114
+ ${e != null && e.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${e.title}&display=swap">` : ""}
115
+ ${e != null && e.description && (e == null ? void 0 : e.description) !== (e == null ? void 0 : e.title) ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${e.description}&display=swap">` : ""}
116
+ <script>
117
+ window.__PROJECT_ID__ = "${R}"
118
+ window.__PAGE_STATE__ = ${JSON.stringify(t)}
119
+
120
+ document.querySelectorAll('link[rel="preload"][as="style"]').forEach(function (link) {
121
+ const l = document.createElement('link');
122
+ l.rel = 'stylesheet';
123
+ l.href = link.href;
124
+ document.head.appendChild(l);
125
+ });
126
+ <\/script>
127
+
128
+ ${x ? `<script src="https://cdn.tailwindcss.com"><\/script>
129
+ <script>
130
+ window.tailwind.config = {
131
+ darkMode: "class",
132
+ };
133
+ <\/script>` : ""}
134
+ `);
135
+ const T = z();
136
+ if (T && d('script[src="__blocklet__.js"]').replaceWith(`<script>${T}<\/script>`), m != null && m.html && d("head").find("#injected-html-elements").replaceWith(m.html), o.cachedHtml) {
137
+ const n = A.load(o.cachedHtml);
138
+ d("body").html(n("body").html() || "");
139
+ }
140
+ w = d.html(), _.send(w), L.info(`[html] render: ${o.path}, ${P()}ms`);
141
+ }), p.use(C);
142
+ }
143
+ function q(p) {
144
+ return Q("image-bin"), p;
145
+ }
146
+ export {
147
+ de as default
148
+ };
@@ -1,5 +1,5 @@
1
- import { P as S, i as b, g as M, C as J, R as X, S as x, t as W, a as G } from "./_chunks/site-state-CD7ipvhF.js";
2
- import { l as N } from "./_chunks/components-k4kCJg_V.js";
1
+ import { P as S, i as b, g as M, C as J, R as X, S as x, t as W, a as G } from "./_chunks/site-state-BxPgS4Do.js";
2
+ import { l as N } from "./_chunks/components-2nieeR3G.js";
3
3
  import { AsyncLocalStorage as K } from "async_hooks";
4
4
  import { Router as Y } from "express";
5
5
  import d from "fs";
@@ -1,5 +1,5 @@
1
- import "./_chunks/components-k4kCJg_V.js";
2
- import { d as x, b as D, c as H, S as M, f as O, a as b, e as h, m as j, n as B, t as L, h as U } from "./_chunks/site-state-CD7ipvhF.js";
1
+ import "./_chunks/components-2nieeR3G.js";
2
+ import { d as x, b as D, c as H, S as M, f as O, a as b, e as h, m as j, n as B, t as L, h as U } from "./_chunks/site-state-BxPgS4Do.js";
3
3
  import "@blocklet/quickjs";
4
4
  import "@blocklet/sdk/lib/component";
5
5
  import "@blocklet/sdk/lib/config";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit-inner-components",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Pages Kit inner components library",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -47,6 +47,10 @@
47
47
  "./theme": {
48
48
  "import": "./lib/es/theme.js",
49
49
  "require": "./lib/cjs/theme.js"
50
+ },
51
+ "./project-html": {
52
+ "import": "./lib/es/project-html.js",
53
+ "require": "./lib/cjs/project-html.js"
50
54
  }
51
55
  },
52
56
  "files": [
@@ -199,7 +203,7 @@
199
203
  "yjs": "^13.6.18",
200
204
  "zustand": "^4.5.5",
201
205
  "@blocklet/pages-kit": "^0.4.16-beta.20250305-2",
202
- "@blocklet/pages-kit-block-studio": "^0.1.31"
206
+ "@blocklet/pages-kit-block-studio": "^0.1.32"
203
207
  },
204
208
  "devDependencies": {
205
209
  "@trivago/prettier-plugin-sort-imports": "^5.2.1",