@blocklet/pages-kit-inner-components 0.5.53 → 0.5.55

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,569 +0,0 @@
1
- import { jsx as t, jsxs as D } from "react/jsx-runtime";
2
- import { u as J, d as Q, e as ft, f as ht, g as bt, c as vt } from "./state-l--dTdHq.js";
3
- import { useLocaleContext as X } from "@arcblock/ux/lib/Locale/context";
4
- import Z from "@arcblock/ux/lib/Result";
5
- import { useHeaderState as yt } from "@blocklet/pages-kit/builtin/page/header";
6
- import { useColorConvert as wt } from "@blocklet/pages-kit/contexts/color";
7
- import { setPageDataSource as tt } from "@blocklet/pages-kit/utils/data-source";
8
- import { generateParamCombinations as xt } from "@blocklet/pages-kit/utils/route";
9
- import kt from "@blocklet/ui-react/lib/Header";
10
- import { cx as Pt } from "@emotion/css";
11
- import { Global as et, css as ot } from "@emotion/react";
12
- import nt from "@emotion/styled";
13
- import { Box as $, CircularProgress as St, useTheme as rt, Button as Ct, Stack as It, alpha as q, useMediaQuery as jt } from "@mui/material";
14
- import { useReactive as at } from "ahooks";
15
- import Rt from "isomorphic-dompurify";
16
- import H from "lodash/cloneDeep";
17
- import Tt from "lodash/isEmpty";
18
- import st from "lodash/isEqual";
19
- import { useEffect as E, lazy as it, useMemo as O, useRef as lt, useState as ct, Suspense as Et } from "react";
20
- import { Helmet as Ot } from "react-helmet";
21
- import { useSearchParams as ut, Routes as Bt, Route as T, Navigate as Mt, ScrollRestoration as Ft } from "react-router-dom";
22
- import { useAsync as pt } from "react-use";
23
- import { joinURL as S } from "ufo";
24
- import { S as Lt, n as Y, P as $t, a as _t, B as At, g as Dt } from "./array-c6HYTLze.js";
25
- import { styled as mt, useTheme as Ht } from "@arcblock/ux/lib/Theme";
26
- import Nt from "@blocklet/ui-react/lib/Footer";
27
- import "webfontloader";
28
- import { u as zt, a as Ut } from "./session-CVblGhSp.js";
29
- const Vt = mt(Nt, { shouldForwardProp: (e) => !!e })`
30
- & > div > .MuiContainer-root {
31
- max-width: unset;
32
- }
33
- `;
34
- function Gt({ meta: e, ...n }) {
35
- const s = Ht();
36
- return /* @__PURE__ */ t(Vt, { ...n, meta: e, theme: s || {} });
37
- }
38
- function Wt(e) {
39
- return /* @__PURE__ */ t($, { display: "flex", flex: 1, height: "100%", alignItems: "center", justifyContent: "center", ...e, children: /* @__PURE__ */ t(St, { size: 30 }) });
40
- }
41
- function qt(e) {
42
- return /* @__PURE__ */ t(Yt, { ...e });
43
- }
44
- const Yt = mt($)`
45
- position: fixed;
46
- left: 0;
47
- top: 0;
48
- z-index: 999999999999;
49
- width: 80px;
50
- font-size: 12px;
51
- text-align: center;
52
- opacity: 0.7;
53
- transform: translateX(-23%) translateY(70%) rotate(-45deg);
54
- pointer-events: none;
55
- `, Kt = `Avenir, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
56
- sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'`;
57
- function Jt({
58
- titleFontFamily: e,
59
- descriptionFontFamily: n
60
- }) {
61
- var o;
62
- const s = rt(), i = (o = s == null ? void 0 : s.typography) == null ? void 0 : o.fontFamily;
63
- E(() => {
64
- }, [e, n]);
65
- const l = `${i}, ${Kt}`;
66
- return /* @__PURE__ */ t(
67
- et,
68
- {
69
- styles: ot`
70
- #app {
71
- font-family: ${l};
72
-
73
- .page-kit-section__title {
74
- font-family: ${l};
75
- }
76
-
77
- .page-kit-section__description {
78
- font-family: ${l};
79
- }
80
- }
81
- `
82
- }
83
- );
84
- }
85
- function Oe() {
86
- const [e] = ut(), { session: n } = zt(), s = Ut("owner", "admin", "pagesEditor", "member"), i = O(() => {
87
- const o = e.get("mode");
88
- return Lt.includes(o) ? o : "production";
89
- }, [e]), l = i === "production" ? i : n.user ? s ? i : "production" : null;
90
- return l ? /* @__PURE__ */ t(Qt, { mode: l }) : null;
91
- }
92
- function Qt({ mode: e }) {
93
- if (e !== "draft") {
94
- const n = window.__PAGE_STATE__;
95
- return n ? /* @__PURE__ */ t(U, { mode: e, state: n }) : /* @__PURE__ */ t(Zt, { mode: e, children: ({ state: s }) => /* @__PURE__ */ t(U, { mode: e, state: s }) });
96
- }
97
- return /* @__PURE__ */ t(Xt, { children: ({ state: n }) => /* @__PURE__ */ t(U, { mode: e, state: n }) });
98
- }
99
- const Xt = it(() => import("./draft-data-CWM--ooz.js"));
100
- function Zt({
101
- mode: e,
102
- children: n
103
- }) {
104
- const s = document.querySelector('meta[property="pages:version"]'), i = s == null ? void 0 : s.content, l = J(), o = O(() => {
105
- if (i === "{{pagesPublishedAt}}") {
106
- const u = localStorage.getItem(vt(l ?? ""));
107
- return Number(u) ? Number(u) : (/* @__PURE__ */ new Date()).getTime();
108
- }
109
- return Number(i);
110
- }, [i]), { loading: d, value: r } = pt(() => Dt({ mode: e, version: o }), [e, o]);
111
- return d ? /* @__PURE__ */ t(Wt, {}) : r ? n({ state: r }) : null;
112
- }
113
- function U({ mode: e, state: n }) {
114
- const { t: s, locale: i } = X(), [l] = ut(), o = J(), d = ft(), r = l.get("hiddenBadge") === "true", u = l.get("showPublish") === "true", {
115
- pageIds: g,
116
- pages: c,
117
- routeIds: m,
118
- routes: f,
119
- supportedLocales: b,
120
- config: { defaultLocale: v },
121
- resources: C
122
- } = n, h = Q(n), x = O(
123
- () => b != null && b.some((p) => p.locale === i) ? i : void 0,
124
- [i, b]
125
- ), B = Object.values(f || {}).find((p) => (p == null ? void 0 : p.path) === "/") || Object.values(c).find((p) => (p == null ? void 0 : p.slug) === "/") ? void 0 : Object.values(c)[0], _ = O(() => e === "production" ? g.map((p) => {
126
- const a = c[p];
127
- return a && {
128
- id: a.id,
129
- path: S("/", d || o || "", a.slug)
130
- };
131
- }).filter(Y) : m.map((p) => {
132
- const a = f[p];
133
- return a ? {
134
- id: a.id,
135
- path: S("/", d || o || "", a.path, `?mode=${e}&showPublish=true`)
136
- } : null;
137
- }).filter(Y), [g, c, e, f, m, o, d]), P = ([...p]) => (e !== "production" && u && p.unshift(
138
- /* @__PURE__ */ t(Et, { fallback: /* @__PURE__ */ t("div", {}), children: /* @__PURE__ */ t(te, { mode: "production", state: n }) })
139
- ), p);
140
- return /* @__PURE__ */ D($t, { value: { pages: _ }, children: [
141
- /* @__PURE__ */ D(Bt, { children: [
142
- B && /* @__PURE__ */ t(T, { index: !0, element: /* @__PURE__ */ t(Mt, { to: S("/", x || "", B.slug) }) }),
143
- m == null ? void 0 : m.map((p) => {
144
- var w, y, k, A;
145
- const a = f == null ? void 0 : f[p];
146
- if (!a || !a.displayTemplateId) return null;
147
- const I = c[a.displayTemplateId];
148
- if (!I) return null;
149
- let j = [];
150
- if (a.params && a.params.length > 0) {
151
- const R = xt({
152
- basePath: a.path,
153
- params: a.params,
154
- routeId: a.id,
155
- paramsOptions: a.paramsOptions,
156
- currentIndex: 0,
157
- currentParams: [],
158
- currentOptionIds: [],
159
- result: []
160
- });
161
- j = R == null ? void 0 : R.map((M) => {
162
- var L, V, G, W;
163
- const F = M.paramOptionIds.join("-");
164
- return /* @__PURE__ */ t(
165
- T,
166
- {
167
- path: S(":projectIdOrSlug?", M.path),
168
- element: /* @__PURE__ */ t(
169
- K,
170
- {
171
- mode: e,
172
- components: h,
173
- page: I,
174
- locale: x,
175
- defaultLocale: v,
176
- headerAddons: P,
177
- state: n,
178
- pageData: (W = (G = (V = (L = a.dataSource) == null ? void 0 : L.pathDataMappings) == null ? void 0 : V[F]) == null ? void 0 : G.dataCache) == null ? void 0 : W[x || v || "en"]
179
- }
180
- )
181
- },
182
- F
183
- );
184
- });
185
- }
186
- return j.push(
187
- /* @__PURE__ */ t(
188
- T,
189
- {
190
- path: S(":projectIdOrSlug?", a.path),
191
- element: /* @__PURE__ */ t(
192
- K,
193
- {
194
- mode: e,
195
- components: h,
196
- page: I,
197
- locale: x,
198
- defaultLocale: v,
199
- headerAddons: P,
200
- state: n,
201
- pageData: (A = (k = (y = (w = a.dataSource) == null ? void 0 : w.pathDataMappings) == null ? void 0 : y[a.id]) == null ? void 0 : k.dataCache) == null ? void 0 : A[x || v || "en"]
202
- }
203
- )
204
- },
205
- a.id
206
- )
207
- ), j;
208
- }),
209
- g.map((p) => {
210
- const a = c[p];
211
- return a ? /* @__PURE__ */ t(
212
- T,
213
- {
214
- path: S(":projectIdOrSlug?", a.slug),
215
- element: /* @__PURE__ */ t(
216
- N,
217
- {
218
- mode: e,
219
- components: h,
220
- page: a,
221
- locale: x,
222
- defaultLocale: v,
223
- headerAddons: P
224
- }
225
- )
226
- },
227
- a.id
228
- ) : null;
229
- }),
230
- C.pages && Object.values(C.pages).map(({ blockletId: p, page: a }) => /* @__PURE__ */ t(
231
- T,
232
- {
233
- path: S("/", `@${p}`, a.slug),
234
- element: /* @__PURE__ */ t(
235
- N,
236
- {
237
- mode: e,
238
- components: h,
239
- page: a,
240
- locale: x,
241
- defaultLocale: v,
242
- headerAddons: P
243
- }
244
- )
245
- },
246
- a.id
247
- )),
248
- /* @__PURE__ */ t(
249
- T,
250
- {
251
- path: "*",
252
- element: /* @__PURE__ */ t($, { width: "100vw", height: "100vh", display: "flex", justifyContent: "center", alignItems: "center", children: /* @__PURE__ */ t(
253
- Z,
254
- {
255
- status: 404,
256
- extra: /* @__PURE__ */ t(gt, { href: "/", children: s("common.back") }),
257
- sx: {
258
- bgcolor: "transparent",
259
- width: "100%",
260
- height: "100%"
261
- }
262
- }
263
- ) })
264
- }
265
- )
266
- ] }),
267
- e !== "production" && !r && /* @__PURE__ */ t(qt, { sx: { bgcolor: "info.light" }, children: e }),
268
- /* @__PURE__ */ t(Jt, {})
269
- ] });
270
- }
271
- function K({
272
- mode: e,
273
- pageData: n,
274
- components: s,
275
- page: i,
276
- locale: l,
277
- defaultLocale: o,
278
- headerAddons: d,
279
- state: r
280
- }) {
281
- const u = at({
282
- page: null
283
- });
284
- E(() => {
285
- const c = i || null;
286
- c ? u.page = H(c) : u.page = null;
287
- }, [i, JSON.stringify(i), u]);
288
- const g = lt();
289
- return E(() => {
290
- st(n, g.current) || n && u.page && (tt(u.page, r, l, n), g.current = H(n));
291
- }, [u.page, n, l, r]), u.page ? /* @__PURE__ */ t(
292
- N,
293
- {
294
- mode: e,
295
- components: s,
296
- page: u.page,
297
- locale: l,
298
- defaultLocale: o,
299
- headerAddons: d
300
- }
301
- ) : null;
302
- }
303
- function Be({
304
- mode: e,
305
- state: n,
306
- path: s,
307
- pageData: i
308
- }) {
309
- const { t: l, locale: o } = X(), {
310
- pages: d,
311
- supportedLocales: r,
312
- config: { defaultLocale: u },
313
- resources: g
314
- } = n, c = Object.values(d).find((h) => (h == null ? void 0 : h.slug) === s), m = Object.values(g.pages || {}).find((h) => h.page.slug === s), f = O(
315
- () => r != null && r.some((h) => h.locale === o) ? o : void 0,
316
- [o, r]
317
- ), b = at({
318
- page: null
319
- });
320
- E(() => {
321
- const h = c || (m == null ? void 0 : m.page) || null;
322
- h ? b.page = H(h) : b.page = null;
323
- }, [c, m]);
324
- const v = lt();
325
- if (E(() => {
326
- st(i, v.current) || i && b.page && (tt(b.page, n, f, i), v.current = H(i));
327
- }, [{}]), !c && !(m != null && m.page))
328
- return /* @__PURE__ */ t($, { width: "100vw", height: "100vh", display: "flex", justifyContent: "center", alignItems: "center", children: /* @__PURE__ */ t(Z, { style: { background: "inherit" }, status: 404, extra: /* @__PURE__ */ t(gt, { href: "/", children: l("common.back") }) }) });
329
- const C = Q(n);
330
- return b.page ? /* @__PURE__ */ t(
331
- N,
332
- {
333
- mode: e,
334
- components: C,
335
- page: b.page,
336
- locale: f,
337
- defaultLocale: u
338
- }
339
- ) : null;
340
- }
341
- function N({
342
- mode: e,
343
- components: n,
344
- page: s,
345
- locale: i,
346
- defaultLocale: l,
347
- headerAddons: o
348
- }) {
349
- var x, z, B, _, P, p, a, I, j;
350
- const d = wt(), r = ((x = s.locales) == null ? void 0 : x[i]) ?? ((z = s.locales) == null ? void 0 : z[l]) ?? {}, u = r.title || ((B = window.blocklet) == null ? void 0 : B.appName), g = r.description || ((_ = window.blocklet) == null ? void 0 : _.appDescription), c = ht(bt(r.image), 540), { logo: m, brand: f, description: b, ...v } = yt(), C = O(
351
- () => (w) => {
352
- var k;
353
- let y = (o == null ? void 0 : o(w)) ?? w;
354
- return y = ((k = v.addons) == null ? void 0 : k.call(v, y)) ?? y, y;
355
- },
356
- [v.addons, o]
357
- ), h = (P = r.header) != null && P.translucent ? oe : dt;
358
- return /* @__PURE__ */ D(_t, { page: s, defaultLocale: l, currentLocale: i, children: [
359
- /* @__PURE__ */ t(
360
- et,
361
- {
362
- styles: ot`
363
- body {
364
- background-color: ${d(
365
- !r.backgroundColor || r.backgroundColor === "transparent" ? "background.default" : r.backgroundColor
366
- )} !important;
367
- }
368
- `
369
- }
370
- ),
371
- /* @__PURE__ */ t(
372
- h,
373
- {
374
- hideNavMenu: !!((p = r.header) != null && p.hideNavMenus),
375
- translucentTextColor: (a = r.header) == null ? void 0 : a.translucentTextColor,
376
- ...m ? { logo: m } : {},
377
- ...f ? { brand: f } : {},
378
- ...b ? { description: b } : {},
379
- className: Pt(((I = r.header) == null ? void 0 : I.sticky) && "sticky", "page-header"),
380
- maxWidth: !1,
381
- addons: C
382
- }
383
- ),
384
- /* @__PURE__ */ t(Ft, {}),
385
- /* @__PURE__ */ D(Ot, { children: [
386
- /* @__PURE__ */ t("title", { children: u }),
387
- /* @__PURE__ */ t("meta", { name: "og:title", content: u }),
388
- /* @__PURE__ */ t("meta", { name: "og:description", content: g }),
389
- /* @__PURE__ */ t("meta", { name: "og:image", content: c }),
390
- /* @__PURE__ */ t("meta", { name: "twitter:image:src", content: c }),
391
- /* @__PURE__ */ t("meta", { name: "twitter:image", content: c }),
392
- /* @__PURE__ */ t("meta", { property: "twitter:description", content: g }),
393
- /* @__PURE__ */ t("meta", { property: "twitter:title", content: u }),
394
- /* @__PURE__ */ t("meta", { name: "description", content: g })
395
- ] }),
396
- /* @__PURE__ */ t(
397
- It,
398
- {
399
- flexGrow: 1,
400
- className: "PageView-root",
401
- sx: {
402
- // 第一个 .BlockBase-root 的 pt 为 0
403
- "& .BlockBase-root:first-child": {
404
- pt: "0 !important"
405
- }
406
- },
407
- children: s.sectionIds.map((w) => {
408
- var R, M, F, L;
409
- const y = s.sections[w];
410
- if (!y || y.visibility === "hidden") return null;
411
- const k = (M = (R = s.dataSource) == null ? void 0 : R[w]) == null ? void 0 : M[i], A = ((L = (F = s.dataSource) == null ? void 0 : F[w]) == null ? void 0 : L[l]) ?? {};
412
- return /* @__PURE__ */ t(
413
- At,
414
- {
415
- id: w,
416
- type: y.component,
417
- mode: e,
418
- section: y,
419
- config: {
420
- ...Tt(k) ? A : k,
421
- locale: i,
422
- dev: e === "draft" ? {
423
- mode: e,
424
- components: n,
425
- defaultLocale: l
426
- } : {
427
- mode: e,
428
- defaultLocale: l
429
- // 用于 fallback 的 locale
430
- }
431
- },
432
- page: s
433
- },
434
- w
435
- );
436
- })
437
- }
438
- ),
439
- !((j = r.footer) != null && j.hidden) && /* @__PURE__ */ t(Gt, {})
440
- ] });
441
- }
442
- const te = it(() => import("./publish-button-wYeS7m-g.js")), dt = nt(kt)`
443
- &.sticky {
444
- position: sticky;
445
- top: 0;
446
- }
447
- `;
448
- function ee({ logo: e }) {
449
- const [n, s] = ct(), i = jt((o) => o.breakpoints.down("sm")), { value: l } = pt(() => {
450
- var r, u;
451
- const o = new URL(
452
- i ? ((r = window == null ? void 0 : window.blocklet) == null ? void 0 : r.appLogo) || "/.well-known/service/blocklet/logo" : ((u = window == null ? void 0 : window.blocklet) == null ? void 0 : u.appLogoRect) || "/.well-known/service/blocklet/logo-rect",
453
- window.location.origin
454
- );
455
- o.searchParams.delete("imageFilter"), o.searchParams.delete("f");
456
- const d = o.toString();
457
- return new Promise((g) => {
458
- fetch(d).then((c) => {
459
- const m = c.headers.get("content-type");
460
- m != null && m.includes("svg") && c.text().then((f) => {
461
- s(f), g(null);
462
- }), g(c.url);
463
- });
464
- });
465
- }, [i]);
466
- if (e)
467
- return e;
468
- if (n)
469
- return /* @__PURE__ */ t($, { sx: { filter: "initial !important" }, dangerouslySetInnerHTML: { __html: Rt.sanitize(n) } });
470
- if (l) {
471
- const o = new URL(l);
472
- o.searchParams.set("imageFilter", "convert"), o.searchParams.set("f", "png"), o.searchParams.set("h", "80");
473
- const d = o.toString();
474
- return /* @__PURE__ */ t("img", { src: d, alt: "logo" });
475
- }
476
- return null;
477
- }
478
- function oe({
479
- logo: e,
480
- translucentTextColor: n,
481
- ...s
482
- }) {
483
- const [i, l] = ct(0), o = rt(), d = 800;
484
- E(() => {
485
- const c = document.getElementById("app");
486
- if (!c) return;
487
- let m = !1;
488
- const f = () => {
489
- m || (requestAnimationFrame(() => {
490
- l(c.scrollTop), m = !1;
491
- }), m = !0);
492
- };
493
- return c.addEventListener("scroll", f, { passive: !0 }), l(c.scrollTop), () => {
494
- c.removeEventListener("scroll", f);
495
- };
496
- }, []);
497
- let r = Math.min(i / d, 1), u = "";
498
- r > 0.1 ? (r = Math.max(r, 0.6), u = q(o.palette.text.primary, r)) : u = n || "#EEEEEE";
499
- const g = r < 0.7;
500
- return /* @__PURE__ */ t(
501
- dt,
502
- {
503
- logo: /* @__PURE__ */ t(ee, { logo: e }),
504
- ...s,
505
- sx: {
506
- // 基础布局和定位
507
- position: "fixed !important",
508
- top: 0,
509
- left: 0,
510
- right: 0,
511
- zIndex: o.zIndex.appBar,
512
- // 确保在顶层
513
- backgroundColor: "transparent !important",
514
- // 主元素始终透明
515
- // 使用伪元素作为背景层
516
- "&::before": {
517
- content: '""',
518
- position: "absolute",
519
- top: 0,
520
- left: 0,
521
- right: 0,
522
- bottom: 0,
523
- zIndex: -1,
524
- // 置于内容下方
525
- // 背景样式(颜色和模糊)是固定的
526
- backgroundColor: q(o.palette.background.default, r),
527
- backdropFilter: r >= 0.6 ? "blur(10px)" : "blur(0px)",
528
- // **性能关键**: 只对 opacity 进行动画
529
- // opacity: backgroundOpacity,
530
- // 让 CSS 平滑地处理透明度变化
531
- transition: "backgroundColor 0.3s ease-in-out"
532
- },
533
- // --- 文字和图标颜色过渡 ---
534
- // 直接为 Header 内所有相关元素设置颜色和过渡
535
- // color: textColor,
536
- transition: "color 0.3s ease-in-out",
537
- // 覆盖子组件的颜色,使其继承父级的 `color`
538
- ".navmenu-root>.navmenu-sub>span,\n .navmenu-root>.navmenu-item,\n .header-addons>button,\n .header-addons>a,\n .header-addons>div>button": {
539
- color: `${u} !important`
540
- // 使用 inherit 来同步颜色
541
- },
542
- ".header-logo": {
543
- color: `${u} !important`
544
- },
545
- "& .navmenu--horizontal": {
546
- bgcolor: "transparent !important"
547
- },
548
- // --- Logo 反色效果 ---
549
- // filter 也是一个较昂贵的属性,但其影响远小于背景色的重绘
550
- // 这里的逻辑保持不变,但可以考虑是否有更优的方案(如提供两个颜色的 Logo)
551
- ".header-logo > div": {
552
- filter: `invert(${g ? 1 : 0})`,
553
- transition: "filter 0.3s ease-in-out"
554
- }
555
- }
556
- }
557
- );
558
- }
559
- const gt = nt(Ct)``;
560
- export {
561
- Oe as H,
562
- Wt as L,
563
- U as P,
564
- oe as T,
565
- Qt as a,
566
- K as b,
567
- Be as c,
568
- N as d
569
- };