@blocklet/pages-kit-inner-components 0.6.38 → 0.6.39

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