@blocklet/pages-kit-inner-components 0.1.5 → 0.1.7
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/_chunks/components-Bu9hOpQX.js +48 -0
- package/lib/cjs/_chunks/{site-state-BjTlKyaF.js → site-state-Bnmllv1a.js} +1 -1
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/project-html.js +23 -0
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/_chunks/components-BVBbxiyS.js +453 -0
- package/lib/es/_chunks/{site-state-CD7ipvhF.js → site-state-DH2gSYZG.js} +1 -1
- package/lib/es/components.js +1 -1
- package/lib/es/project-html.js +148 -0
- package/lib/es/resources.js +2 -2
- package/lib/es/site-state.js +2 -2
- package/package.json +22 -18
- package/lib/cjs/_chunks/components-CGE2womb.js +0 -29
- package/lib/es/_chunks/components-k4kCJg_V.js +0 -412
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { getComponentMountPoint as v } from "@blocklet/pages-kit/builtin/utils";
|
|
2
|
+
import { PreloadComponentScriptModule as N } from "@blocklet/pages-kit/types";
|
|
3
|
+
import { componentUMDName as L, RenderNestedComponent as P, mergeComponent as U } from "@blocklet/pages-kit/utils/property";
|
|
4
|
+
import { memoize as b, Sandbox as _, BuiltinModules as D } from "@blocklet/quickjs";
|
|
5
|
+
import M from "@blocklet/sdk/lib/config";
|
|
6
|
+
import { LRUCache as F } from "lru-cache";
|
|
7
|
+
import B, { Headers as G } from "node-fetch";
|
|
8
|
+
import { joinURL as S, getQuery as J, withQuery as K, parseURL as T, withHttps as Q } from "ufo";
|
|
9
|
+
import W from "@blocklet/logger";
|
|
10
|
+
import { BuiltinModules as A } from "@blocklet/pages-kit/utils/builtin";
|
|
11
|
+
import { createBuiltinModuleTransformer as V, isRelativeModule as j } from "@blocklet/pages-kit/utils/typescript/builtin-module-transformer";
|
|
12
|
+
import { call as H } from "@blocklet/sdk/lib/component";
|
|
13
|
+
import z from "autoprefixer";
|
|
14
|
+
import * as X from "esbuild";
|
|
15
|
+
import Y from "postcss";
|
|
16
|
+
import Z from "tailwindcss";
|
|
17
|
+
import d from "typescript";
|
|
18
|
+
const h = W("pages-kit"), q = async (e, { componentId: t }) => {
|
|
19
|
+
const o = `@tailwind components;
|
|
20
|
+
@tailwind utilities;
|
|
21
|
+
`, r = `.CustomComponent_${t}`;
|
|
22
|
+
return (await Y([
|
|
23
|
+
Z({ content: [{ raw: e, extension: "tsx" }] }),
|
|
24
|
+
z({
|
|
25
|
+
overrideBrowserslist: ["> 1%", "last 2 versions"],
|
|
26
|
+
stats: {}
|
|
27
|
+
}),
|
|
28
|
+
(i) => {
|
|
29
|
+
i.walkRules((n) => {
|
|
30
|
+
n.selectors = n.selectors.map((c) => c.replace(/\.(.+)/g, `${r}.$1,${r} .$1`));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// FIXME: cssnano use browserslist, it is not working with the fs isolation
|
|
34
|
+
// cssnano({ preset: 'default' }),
|
|
35
|
+
]).process(o)).css;
|
|
36
|
+
}, ee = async (e, { componentId: t }) => {
|
|
37
|
+
const o = await q(e, { componentId: t });
|
|
38
|
+
return `export const __PagesKit_CSS__ = ${JSON.stringify(o)};
|
|
39
|
+
|
|
40
|
+
${e}
|
|
41
|
+
`;
|
|
42
|
+
}, I = b(
|
|
43
|
+
async (e, t) => {
|
|
44
|
+
let o = d.transpileModule(e, {
|
|
45
|
+
compilerOptions: {
|
|
46
|
+
jsx: d.JsxEmit.React,
|
|
47
|
+
target: d.ScriptTarget.ES2016,
|
|
48
|
+
module: d.ModuleKind.ESNext
|
|
49
|
+
},
|
|
50
|
+
transformers: {
|
|
51
|
+
before: [V(d)]
|
|
52
|
+
}
|
|
53
|
+
}).outputText;
|
|
54
|
+
if (t.tailwind && (o = await ee(o, { componentId: t.componentId })), t.module === N.ESM) return o;
|
|
55
|
+
const r = d.transpileModule(o, {
|
|
56
|
+
compilerOptions: {
|
|
57
|
+
jsx: d.JsxEmit.React,
|
|
58
|
+
target: d.ScriptTarget.ES2016,
|
|
59
|
+
module: d.ModuleKind.CommonJS,
|
|
60
|
+
moduleResolution: d.ModuleResolutionKind.Node16
|
|
61
|
+
}
|
|
62
|
+
}).outputText;
|
|
63
|
+
return oe(t.moduleName, r);
|
|
64
|
+
},
|
|
65
|
+
{ keyGenerator: (e, t) => JSON.stringify(["transpileModule", e, t]) }
|
|
66
|
+
), te = async (e, t) => {
|
|
67
|
+
var n, c;
|
|
68
|
+
const r = (c = (n = (await X.build({
|
|
69
|
+
entryPoints: ["index.tsx"],
|
|
70
|
+
external: Object.keys(A),
|
|
71
|
+
format: "esm",
|
|
72
|
+
target: "es2020",
|
|
73
|
+
bundle: !0,
|
|
74
|
+
write: !1,
|
|
75
|
+
plugins: [
|
|
76
|
+
{
|
|
77
|
+
name: "vfs",
|
|
78
|
+
setup(m) {
|
|
79
|
+
m.onResolve({ filter: /.*/ }, (s) => s.path === "index.tsx" ? { path: "index.tsx", namespace: "vfs" } : s.path === "./component" ? { path: "component.tsx", namespace: "vfs" } : j(s.path) ? { path: s.path, namespace: "vfs" } : null), m.onLoad({ filter: /.*/, namespace: "vfs" }, async (s) => {
|
|
80
|
+
if (s.path === "index.tsx")
|
|
81
|
+
return { contents: `export { ${t} } from './component'`, loader: "tsx" };
|
|
82
|
+
if (s.path === "component.tsx")
|
|
83
|
+
return { contents: e, loader: "tsx" };
|
|
84
|
+
if (j(s.path)) {
|
|
85
|
+
const l = s.path.split("/").pop(), f = S("chunks", l), { data: g } = await H({
|
|
86
|
+
name: "pages-kit",
|
|
87
|
+
method: "GET",
|
|
88
|
+
path: f
|
|
89
|
+
});
|
|
90
|
+
return { contents: g, loader: "js" };
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
})).outputFiles) == null ? void 0 : n[0]) == null ? void 0 : c.contents;
|
|
98
|
+
if (!r) throw new Error("Failed to build server code");
|
|
99
|
+
const a = Buffer.from(r).toString();
|
|
100
|
+
return d.transpileModule(a, {
|
|
101
|
+
compilerOptions: { module: d.ModuleKind.ESNext, target: d.ScriptTarget.ES2020 }
|
|
102
|
+
}).outputText;
|
|
103
|
+
}, k = b(
|
|
104
|
+
async (e, t) => {
|
|
105
|
+
const o = await te(e, t);
|
|
106
|
+
return new RegExp(`export\\s+\\{\\s+${t}\\s+\\}`, "m").test(o) ? o : void 0;
|
|
107
|
+
},
|
|
108
|
+
{ keyGenerator: (e, t) => JSON.stringify(["extractExportValueSchema", e, t]) }
|
|
109
|
+
), oe = (e, t) => {
|
|
110
|
+
const o = /\bawait\b/.test(t);
|
|
111
|
+
return `// GENERATED FILE. DO NOT EDIT.
|
|
112
|
+
var ${e} = ${o ? "async" : ""} function () {
|
|
113
|
+
|
|
114
|
+
const exports = {};
|
|
115
|
+
let moduleExports = null;
|
|
116
|
+
|
|
117
|
+
// add commonjs module compatibility layer
|
|
118
|
+
const module = { exports: moduleExports };
|
|
119
|
+
|
|
120
|
+
// execute component code
|
|
121
|
+
${t}
|
|
122
|
+
|
|
123
|
+
// handle possible module.exports
|
|
124
|
+
if (module.exports && module.exports !== moduleExports) {
|
|
125
|
+
// if module.exports is used, use it first
|
|
126
|
+
return typeof module.exports === 'object' ? module.exports : { default: module.exports };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ensure a default export
|
|
130
|
+
if (!('default' in exports) && Object.keys(exports).length === 0) {
|
|
131
|
+
// module has no exports, return null to indicate invalid
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return exports;
|
|
136
|
+
};
|
|
137
|
+
`;
|
|
138
|
+
}, w = new F({
|
|
139
|
+
max: 100
|
|
140
|
+
}), ne = 60 * 60, $ = 60;
|
|
141
|
+
function re(e) {
|
|
142
|
+
h.info("clear preload components cache", { cacheKey: e }), w.delete(e);
|
|
143
|
+
}
|
|
144
|
+
function Me(e) {
|
|
145
|
+
for (const t of w.keys())
|
|
146
|
+
t.includes(e) && (h.info("clear preload components cache", { cacheKey: t }), re(t));
|
|
147
|
+
}
|
|
148
|
+
function se({
|
|
149
|
+
mode: e,
|
|
150
|
+
instanceId: t,
|
|
151
|
+
componentId: o,
|
|
152
|
+
locale: r
|
|
153
|
+
}) {
|
|
154
|
+
return ["getPreloadComponents", e, t, o, r].join("-");
|
|
155
|
+
}
|
|
156
|
+
async function Te({
|
|
157
|
+
mode: e,
|
|
158
|
+
req: t,
|
|
159
|
+
state: o,
|
|
160
|
+
locale: r,
|
|
161
|
+
instances: a,
|
|
162
|
+
module: i
|
|
163
|
+
}) {
|
|
164
|
+
const {
|
|
165
|
+
supportedLocales: n,
|
|
166
|
+
config: { defaultLocale: c }
|
|
167
|
+
} = o;
|
|
168
|
+
if (!c) return null;
|
|
169
|
+
const m = (await Promise.all(
|
|
170
|
+
a.map(async (p) => {
|
|
171
|
+
try {
|
|
172
|
+
const u = se({
|
|
173
|
+
mode: e,
|
|
174
|
+
instanceId: p.id,
|
|
175
|
+
componentId: p.componentId,
|
|
176
|
+
locale: r
|
|
177
|
+
});
|
|
178
|
+
if (e !== "draft" && p.useCache && w.has(u))
|
|
179
|
+
return h.info(`get preload component from cache: ${u}`), w.get(u);
|
|
180
|
+
const x = C({ state: o, componentId: p.componentId });
|
|
181
|
+
if (!x) return null;
|
|
182
|
+
const y = await ce({
|
|
183
|
+
req: t,
|
|
184
|
+
state: o,
|
|
185
|
+
componentId: x.id,
|
|
186
|
+
locale: r,
|
|
187
|
+
defaultLocale: c,
|
|
188
|
+
properties: p.properties
|
|
189
|
+
});
|
|
190
|
+
if (!y) return null;
|
|
191
|
+
const O = { instanceId: p.id, preload: y };
|
|
192
|
+
if (e !== "draft" && p.useCache) {
|
|
193
|
+
let E = ne;
|
|
194
|
+
p.cacheDuration && (E = p.cacheDuration), h.info(`set preload component to cache(${E}s): ${u}`), w.set(u, O, {
|
|
195
|
+
ttl: E * 1e3
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return O;
|
|
199
|
+
} catch (u) {
|
|
200
|
+
return h.error("get preload component error", { instanceId: p.id, componentId: p.componentId }, { error: u }), null;
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
)).filter((p) => !!p), s = Object.values(
|
|
204
|
+
m.reduce((p, u) => ({ ...p, ...u.preload.components }), {})
|
|
205
|
+
);
|
|
206
|
+
async function l() {
|
|
207
|
+
const p = await Promise.all(
|
|
208
|
+
s.map(async (u) => {
|
|
209
|
+
const x = L({ componentId: u.component.id }), y = i === N.ESM ? {
|
|
210
|
+
module: i,
|
|
211
|
+
script: await I(u.script, {
|
|
212
|
+
componentId: u.component.id,
|
|
213
|
+
module: i,
|
|
214
|
+
tailwind: e !== "draft"
|
|
215
|
+
})
|
|
216
|
+
} : {
|
|
217
|
+
module: i,
|
|
218
|
+
script: await I(u.script, {
|
|
219
|
+
componentId: u.component.id,
|
|
220
|
+
module: i,
|
|
221
|
+
moduleName: x,
|
|
222
|
+
tailwind: e !== "draft"
|
|
223
|
+
}),
|
|
224
|
+
moduleName: x
|
|
225
|
+
};
|
|
226
|
+
return [u.component.id, { component: u.component, script: y }];
|
|
227
|
+
})
|
|
228
|
+
);
|
|
229
|
+
return Object.fromEntries(p);
|
|
230
|
+
}
|
|
231
|
+
const f = await l();
|
|
232
|
+
return {
|
|
233
|
+
config: { defaultLocale: c, supportedLocales: n },
|
|
234
|
+
components: f,
|
|
235
|
+
instances: m.map((p) => ({
|
|
236
|
+
id: p.instanceId,
|
|
237
|
+
componentId: p.preload.component.id,
|
|
238
|
+
locales: { [p.preload.locale]: { props: p.preload.props } }
|
|
239
|
+
}))
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
async function ce({
|
|
243
|
+
req: e,
|
|
244
|
+
state: t,
|
|
245
|
+
componentId: o,
|
|
246
|
+
locale: r,
|
|
247
|
+
defaultLocale: a,
|
|
248
|
+
properties: i
|
|
249
|
+
}) {
|
|
250
|
+
const { supportedLocales: n } = t, c = C({ state: t, componentId: o });
|
|
251
|
+
if (!c) return null;
|
|
252
|
+
const m = n.some((l) => l.locale === r) ? r : a;
|
|
253
|
+
if (!m) return null;
|
|
254
|
+
const s = await R({ req: e, state: t, componentId: o, locale: m, defaultLocale: a, properties: i });
|
|
255
|
+
return s ? {
|
|
256
|
+
component: c,
|
|
257
|
+
...s
|
|
258
|
+
} : null;
|
|
259
|
+
}
|
|
260
|
+
const ae = 20;
|
|
261
|
+
async function R({
|
|
262
|
+
req: e,
|
|
263
|
+
depth: t = 0,
|
|
264
|
+
state: o,
|
|
265
|
+
componentId: r,
|
|
266
|
+
locale: a,
|
|
267
|
+
defaultLocale: i,
|
|
268
|
+
properties: n
|
|
269
|
+
}) {
|
|
270
|
+
if (t > ae) throw new RangeError("max component depth exceeded");
|
|
271
|
+
const c = ie({ state: o, componentId: r, properties: n, locale: a });
|
|
272
|
+
if (!c) return null;
|
|
273
|
+
const { props: m } = c, s = {
|
|
274
|
+
locale: a || i,
|
|
275
|
+
components: { [c.component.id]: { component: c.component, script: c.script } },
|
|
276
|
+
props: { ...m }
|
|
277
|
+
};
|
|
278
|
+
try {
|
|
279
|
+
const l = await pe({ ...c, req: e });
|
|
280
|
+
l != null && l.props && Object.assign(s.props, l.props);
|
|
281
|
+
} catch (l) {
|
|
282
|
+
h.error("preload data at server side error", { componentId: r, name: c.component.name }, { error: l });
|
|
283
|
+
}
|
|
284
|
+
return await Promise.all(
|
|
285
|
+
Object.entries(m).map(async ([l, f]) => {
|
|
286
|
+
if ((f == null ? void 0 : f.type) === P) {
|
|
287
|
+
const g = await R({
|
|
288
|
+
req: e,
|
|
289
|
+
depth: t + 1,
|
|
290
|
+
state: o,
|
|
291
|
+
componentId: f.componentId,
|
|
292
|
+
locale: a,
|
|
293
|
+
defaultLocale: i,
|
|
294
|
+
properties: f.properties
|
|
295
|
+
});
|
|
296
|
+
g && (Object.assign(s.components, g.components), Object.assign(s.props, {
|
|
297
|
+
[l]: {
|
|
298
|
+
type: P,
|
|
299
|
+
componentId: f.componentId,
|
|
300
|
+
props: g.props
|
|
301
|
+
}
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
), s;
|
|
306
|
+
}
|
|
307
|
+
function ie({
|
|
308
|
+
state: e,
|
|
309
|
+
componentId: t,
|
|
310
|
+
locale: o,
|
|
311
|
+
properties: r
|
|
312
|
+
}) {
|
|
313
|
+
const a = C({ state: e, componentId: t });
|
|
314
|
+
if (!a) return null;
|
|
315
|
+
const i = U({
|
|
316
|
+
componentId: t,
|
|
317
|
+
getComponent: (n) => C({ state: e, componentId: n }),
|
|
318
|
+
locale: o,
|
|
319
|
+
defaultLocale: e.config.defaultLocale,
|
|
320
|
+
properties: r
|
|
321
|
+
});
|
|
322
|
+
return i ? { component: a, script: i.script, props: { locale: o, ...i.properties } } : null;
|
|
323
|
+
}
|
|
324
|
+
function C({ state: e, componentId: t }) {
|
|
325
|
+
var o, r, a;
|
|
326
|
+
return ((o = e.components[t]) == null ? void 0 : o.data) ?? ((a = (r = e.resources.components) == null ? void 0 : r[t]) == null ? void 0 : a.component);
|
|
327
|
+
}
|
|
328
|
+
function je({ state: e, name: t }) {
|
|
329
|
+
var r, a;
|
|
330
|
+
const o = t.toLowerCase();
|
|
331
|
+
return ((r = Object.values(e.components).find((i) => {
|
|
332
|
+
var n;
|
|
333
|
+
return ((n = i.data.name) == null ? void 0 : n.toLowerCase()) === o;
|
|
334
|
+
})) == null ? void 0 : r.data) ?? ((a = e.resources.components && Object.values(e.resources.components).find((i) => {
|
|
335
|
+
var n;
|
|
336
|
+
return ((n = i.component.name) == null ? void 0 : n.toLowerCase()) === o;
|
|
337
|
+
})) == null ? void 0 : a.component);
|
|
338
|
+
}
|
|
339
|
+
async function pe({
|
|
340
|
+
component: e,
|
|
341
|
+
script: t,
|
|
342
|
+
props: o,
|
|
343
|
+
req: r
|
|
344
|
+
}) {
|
|
345
|
+
const a = await k(t, "getServerSideProps");
|
|
346
|
+
if (!a) return null;
|
|
347
|
+
const i = new Promise((n, c) => {
|
|
348
|
+
setTimeout(() => c(new Error("getServerSideProps timeout in promise race")), $ * 1e3);
|
|
349
|
+
});
|
|
350
|
+
return Promise.race([
|
|
351
|
+
i,
|
|
352
|
+
_.callFunction({
|
|
353
|
+
code: `${a}
|
|
354
|
+
|
|
355
|
+
export async function getServerSidePropsWrapper({ location, fetch, props}) {
|
|
356
|
+
globalThis.location = location
|
|
357
|
+
globalThis.fetch = fetch
|
|
358
|
+
|
|
359
|
+
return getServerSideProps(props);
|
|
360
|
+
}
|
|
361
|
+
`,
|
|
362
|
+
filename: `${e.name || e.id}.js`,
|
|
363
|
+
moduleLoader: (n) => {
|
|
364
|
+
if (n === "@blocklet/pages-kit/builtin/utils")
|
|
365
|
+
return `const { joinURL, withQuery, getQuery, getComponentMountPoint } = globalThis
|
|
366
|
+
export { joinURL, withQuery, getQuery, getComponentMountPoint }
|
|
367
|
+
`;
|
|
368
|
+
if (n === "@blocklet/pages-kit/builtin/dayjs")
|
|
369
|
+
return D.dayjs;
|
|
370
|
+
},
|
|
371
|
+
global: {
|
|
372
|
+
console: {
|
|
373
|
+
// NOTE: do not return logger.xxx result, it will cause memory leak
|
|
374
|
+
// eslint-disable-next-line prettier/prettier
|
|
375
|
+
log: (...n) => {
|
|
376
|
+
h.info(...n);
|
|
377
|
+
},
|
|
378
|
+
warn: (...n) => {
|
|
379
|
+
h.warn(...n);
|
|
380
|
+
},
|
|
381
|
+
error: (...n) => {
|
|
382
|
+
h.error(...n);
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
getComponentMountPoint: v,
|
|
386
|
+
joinURL: S,
|
|
387
|
+
withQuery: K,
|
|
388
|
+
getQuery: J
|
|
389
|
+
},
|
|
390
|
+
functionName: "getServerSidePropsWrapper",
|
|
391
|
+
args: [
|
|
392
|
+
{
|
|
393
|
+
// NOTE: IMPORTANT! place location and fetch (has side effect) at the args not global
|
|
394
|
+
// because the global is shared between all runtime and just init once
|
|
395
|
+
location: { href: S(Q(r.hostname), r.originalUrl) },
|
|
396
|
+
fetch: (n, { ...c } = {}) => {
|
|
397
|
+
const m = typeof n == "string" && n.startsWith("/") ? S(M.env.appUrl, n) : n;
|
|
398
|
+
if (typeof m == "string" && T(m).host === T(M.env.appUrl).host) {
|
|
399
|
+
const s = r.get("cookie");
|
|
400
|
+
if (s) {
|
|
401
|
+
const l = new G(c.headers);
|
|
402
|
+
l.set("cookie", s), c.headers = l;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return B(m, {
|
|
406
|
+
...c,
|
|
407
|
+
timeout: $ * 1e3
|
|
408
|
+
}).then((s) => ({
|
|
409
|
+
ok: s.ok,
|
|
410
|
+
status: s.status,
|
|
411
|
+
statusText: s.statusText,
|
|
412
|
+
headers: Object.fromEntries(s.headers.entries()),
|
|
413
|
+
json: () => s.json()
|
|
414
|
+
}));
|
|
415
|
+
},
|
|
416
|
+
props: o
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
})
|
|
420
|
+
]);
|
|
421
|
+
}
|
|
422
|
+
const Ie = b(
|
|
423
|
+
async (e, t, o) => {
|
|
424
|
+
const r = await k(e, t);
|
|
425
|
+
return r ? await _.callFunction({
|
|
426
|
+
code: `
|
|
427
|
+
${r}
|
|
428
|
+
|
|
429
|
+
export function get${t}SchemaWrapper() {
|
|
430
|
+
return ${t};
|
|
431
|
+
}
|
|
432
|
+
`,
|
|
433
|
+
filename: `${o}.js`,
|
|
434
|
+
functionName: `get${t}SchemaWrapper`
|
|
435
|
+
}) : null;
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
keyGenerator: (e, t, o) => JSON.stringify(["getExportSchemaValueFromCode", e, t, o])
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
export {
|
|
442
|
+
ne as C,
|
|
443
|
+
$ as G,
|
|
444
|
+
Te as a,
|
|
445
|
+
re as b,
|
|
446
|
+
Me as c,
|
|
447
|
+
se as d,
|
|
448
|
+
ce as e,
|
|
449
|
+
C as f,
|
|
450
|
+
Ie as g,
|
|
451
|
+
je as h,
|
|
452
|
+
h as l
|
|
453
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as D, c as Me, g as $e } from "./components-
|
|
1
|
+
import { l as D, c as Me, g as $e } from "./components-BVBbxiyS.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";
|
package/lib/es/components.js
CHANGED
|
@@ -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 _,
|
|
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-BVBbxiyS.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 y } from "./_chunks/components-BVBbxiyS.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: E,
|
|
25
|
+
projectId: R,
|
|
26
|
+
state: t
|
|
27
|
+
}) {
|
|
28
|
+
let g;
|
|
29
|
+
if (E) {
|
|
30
|
+
const o = j(D(process.cwd(), "./index.html"), "utf-8");
|
|
31
|
+
p.use(async (_, T, k) => {
|
|
32
|
+
const P = _.originalUrl;
|
|
33
|
+
g = await E.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, _, T) => {
|
|
44
|
+
var S, b, I;
|
|
45
|
+
if (F.some((n) => o.path.startsWith(n))) {
|
|
46
|
+
T();
|
|
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 || !((S = t.supportedLocales) != null && S.find((a) => a.locale === s))) && (s = ((I = (b = t.supportedLocales) == null ? void 0 : b[0]) == null ? void 0 : I.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, L;
|
|
64
|
+
return {
|
|
65
|
+
id: c.id,
|
|
66
|
+
componentId: c.config.componentId,
|
|
67
|
+
useCache: c.config.useCache,
|
|
68
|
+
cacheDuration: c.config.cacheDuration,
|
|
69
|
+
properties: (L = (f = c.locales) == null ? void 0 : f[s]) == null ? void 0 : L.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 (i) {
|
|
94
|
+
y.warn("getPreloadComponents timeout in promise race, skip inject html elements"), y.warn(i);
|
|
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 $ = z();
|
|
136
|
+
if ($ && d('script[src="__blocklet__.js"]').replaceWith(`<script>${$}<\/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), y.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
|
+
};
|
package/lib/es/resources.js
CHANGED
|
@@ -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-
|
|
2
|
-
import { l as N } from "./_chunks/components-
|
|
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-DH2gSYZG.js";
|
|
2
|
+
import { l as N } from "./_chunks/components-BVBbxiyS.js";
|
|
3
3
|
import { AsyncLocalStorage as K } from "async_hooks";
|
|
4
4
|
import { Router as Y } from "express";
|
|
5
5
|
import d from "fs";
|
package/lib/es/site-state.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./_chunks/components-
|
|
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-
|
|
1
|
+
import "./_chunks/components-BVBbxiyS.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-DH2gSYZG.js";
|
|
3
3
|
import "@blocklet/quickjs";
|
|
4
4
|
import "@blocklet/sdk/lib/component";
|
|
5
5
|
import "@blocklet/sdk/lib/config";
|