@blocklet/pages-kit-inner-components 0.4.157 → 0.4.159

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,533 +0,0 @@
1
- import { jsx as e, jsxs as A } from "react/jsx-runtime";
2
- import { d as W, e as ce, g as ue, u as pe, c as me } from "./state-BcZbsEn6.js";
3
- import { useLocaleContext as q } from "@arcblock/ux/lib/Locale/context";
4
- import K from "@arcblock/ux/lib/Result";
5
- import { useHeaderState as de } from "@blocklet/pages-kit/builtin/page/header";
6
- import { useColorConvert as ge } from "@blocklet/pages-kit/contexts/color";
7
- import { setPageDataSource as Q } from "@blocklet/pages-kit/utils/data-source";
8
- import { generateParamCombinations as fe } from "@blocklet/pages-kit/utils/route";
9
- import he from "@blocklet/ui-react/lib/Header";
10
- import { cx as X } from "@emotion/css";
11
- import { Global as Y, css as J } from "@emotion/react";
12
- import Z from "@emotion/styled";
13
- import { Box as O, CircularProgress as be, useTheme as ve, Button as ye, Stack as we, useMediaQuery as Se } from "@mui/material";
14
- import { useReactive as ee, useScroll as xe } from "ahooks";
15
- import Pe from "isomorphic-dompurify";
16
- import D from "lodash/cloneDeep";
17
- import ke from "lodash/isEmpty";
18
- import te from "lodash/isEqual";
19
- import { useEffect as F, useContext as Ce, lazy as oe, useMemo as M, useRef as ne, Suspense as Ie, useState as Re } from "react";
20
- import { Helmet as Me } from "react-helmet";
21
- import { useSearchParams as re, Routes as je, Route as I, Navigate as Ee, ScrollRestoration as Te } from "react-router-dom";
22
- import { useAsync as se } from "react-use";
23
- import { joinURL as R } from "ufo";
24
- import { S as Be, n as $e, P as Fe, a as Oe, B as Le, g as _e } from "./array-DudMqbtU.js";
25
- import { styled as ae, useTheme as Ae } from "@arcblock/ux/lib/Theme";
26
- import De from "@blocklet/ui-react/lib/Footer";
27
- import "webfontloader";
28
- import { createAuthServiceSessionContext as Ne } from "@arcblock/did-connect/lib/Session";
29
- const He = ae(De, { shouldForwardProp: (t) => !!t })`
30
- & > div > .MuiContainer-root {
31
- max-width: unset;
32
- }
33
- `;
34
- function Ue({ meta: t, ...o }) {
35
- const s = Ae();
36
- return /* @__PURE__ */ e(He, { ...o, meta: t, theme: s || {} });
37
- }
38
- function ze(t) {
39
- return /* @__PURE__ */ e(O, { display: "flex", flex: 1, height: "100%", alignItems: "center", justifyContent: "center", ...t, children: /* @__PURE__ */ e(be, { size: 30 }) });
40
- }
41
- function Ve(t) {
42
- return /* @__PURE__ */ e(Ge, { ...t });
43
- }
44
- const Ge = ae(O)`
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
- `, We = `Avenir, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
56
- sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'`;
57
- function qe({
58
- titleFontFamily: t,
59
- descriptionFontFamily: o
60
- }) {
61
- var n;
62
- const s = ve(), a = (n = s == null ? void 0 : s.typography) == null ? void 0 : n.fontFamily;
63
- F(() => {
64
- }, [t, o]);
65
- const r = `${a}, ${We}`;
66
- return /* @__PURE__ */ e(
67
- Y,
68
- {
69
- styles: J`
70
- #app {
71
- font-family: ${r};
72
-
73
- .page-kit-section__title {
74
- font-family: ${r};
75
- }
76
-
77
- .page-kit-section__description {
78
- font-family: ${r};
79
- }
80
- }
81
- `
82
- }
83
- );
84
- }
85
- const { SessionProvider: Tt, SessionContext: Ke, SessionConsumer: Bt, withSession: $t } = Ne();
86
- function U() {
87
- return Ce(Ke);
88
- }
89
- function Qe(...t) {
90
- var s;
91
- const { session: o } = U();
92
- return t.includes((s = o.user) == null ? void 0 : s.role);
93
- }
94
- function Xe(...t) {
95
- var a;
96
- const { session: o } = U(), s = Qe(...t);
97
- return ((a = window.blocklet) == null ? void 0 : a.tenantMode) === "multiple" ? !!o.user : s;
98
- }
99
- function Ft() {
100
- const [t] = re(), { session: o } = U(), s = Xe("owner", "admin", "pagesEditor", "member"), a = M(() => {
101
- const n = t.get("mode");
102
- return Be.includes(n) ? n : "production";
103
- }, [t]), r = a === "production" ? a : o.user ? s ? a : "production" : null;
104
- return r ? /* @__PURE__ */ e(Ye, { mode: r }) : null;
105
- }
106
- function Ye({ mode: t }) {
107
- if (t !== "draft") {
108
- const o = window.__PAGE_STATE__;
109
- return o ? /* @__PURE__ */ e(H, { mode: t, state: o }) : /* @__PURE__ */ e(Ze, { mode: t, children: ({ state: s }) => /* @__PURE__ */ e(H, { mode: t, state: s }) });
110
- }
111
- return /* @__PURE__ */ e(Je, { children: ({ state: o }) => /* @__PURE__ */ e(H, { mode: t, state: o }) });
112
- }
113
- const Je = oe(() => import("./draft-data-DB1pDB18.js"));
114
- function Ze({
115
- mode: t,
116
- children: o
117
- }) {
118
- const s = document.querySelector('meta[property="pages:version"]'), a = s == null ? void 0 : s.content, r = pe(), n = M(() => {
119
- if (a === "{{pagesPublishedAt}}") {
120
- const c = localStorage.getItem(me(r ?? ""));
121
- return Number(c) ? Number(c) : (/* @__PURE__ */ new Date()).getTime();
122
- }
123
- return Number(a);
124
- }, [a]), { loading: d, value: l } = se(() => _e({ mode: t, version: n }), [t, n]);
125
- return d ? /* @__PURE__ */ e(ze, {}) : l ? o({ state: l }) : null;
126
- }
127
- function H({ mode: t, state: o }) {
128
- const { t: s, locale: a } = q(), [r] = re(), n = r.get("hiddenBadge") === "true", d = r.get("showPublish") === "true", {
129
- pageIds: l,
130
- pages: c,
131
- routeIds: g,
132
- routes: m,
133
- supportedLocales: u,
134
- config: { defaultLocale: b },
135
- resources: y
136
- } = o, w = W(o), v = M(
137
- () => u != null && u.some((p) => p.locale === a) ? a : void 0,
138
- [a, u]
139
- ), f = Object.values(c).find((p) => (p == null ? void 0 : p.slug) === "/") ? void 0 : Object.values(c)[0], L = M(
140
- () => l.map((p) => {
141
- const i = c[p];
142
- return i && {
143
- id: i.id,
144
- path: R("/", v || "", i.slug, t !== "production" ? `?mode=${t}` : "")
145
- };
146
- }).filter($e),
147
- [l, c, v, t]
148
- ), P = ([...p]) => (t !== "production" && d && p.unshift(
149
- /* @__PURE__ */ e(Ie, { fallback: /* @__PURE__ */ e("div", {}), children: /* @__PURE__ */ e(et, { mode: "production", state: o }) })
150
- ), p);
151
- return /* @__PURE__ */ A(Fe, { value: { pages: L }, children: [
152
- /* @__PURE__ */ A(je, { children: [
153
- f && /* @__PURE__ */ e(I, { index: !0, element: /* @__PURE__ */ e(Ee, { to: R("/", v || "", f.slug) }) }),
154
- g == null ? void 0 : g.map((p) => {
155
- var j, E, T, S;
156
- const i = m == null ? void 0 : m[p];
157
- if (!i || !i.displayTemplateId) return null;
158
- const k = c[i.displayTemplateId];
159
- if (!k) return null;
160
- let C = [];
161
- if (i.params && i.params.length > 0) {
162
- const h = fe({
163
- basePath: i.path,
164
- params: i.params,
165
- routeId: i.id,
166
- paramsOptions: i.paramsOptions,
167
- currentIndex: 0,
168
- currentParams: [],
169
- currentOptionIds: [],
170
- result: []
171
- });
172
- C = h == null ? void 0 : h.map((x) => {
173
- var B, $, z, V;
174
- const _ = x.paramOptionIds.join("-");
175
- return /* @__PURE__ */ e(
176
- I,
177
- {
178
- path: R(":projectIdOrSlug?", x.path),
179
- element: /* @__PURE__ */ e(
180
- G,
181
- {
182
- mode: t,
183
- components: w,
184
- page: k,
185
- locale: v,
186
- defaultLocale: b,
187
- headerAddons: P,
188
- state: o,
189
- pageData: (V = (z = ($ = (B = i.dataSource) == null ? void 0 : B.pathDataMappings) == null ? void 0 : $[_]) == null ? void 0 : z.dataCache) == null ? void 0 : V[v || b || "en"]
190
- }
191
- )
192
- },
193
- _
194
- );
195
- });
196
- }
197
- return C.push(
198
- /* @__PURE__ */ e(
199
- I,
200
- {
201
- path: R(":projectIdOrSlug?", i.path),
202
- element: /* @__PURE__ */ e(
203
- G,
204
- {
205
- mode: t,
206
- components: w,
207
- page: k,
208
- locale: v,
209
- defaultLocale: b,
210
- headerAddons: P,
211
- state: o,
212
- pageData: (S = (T = (E = (j = i.dataSource) == null ? void 0 : j.pathDataMappings) == null ? void 0 : E[i.id]) == null ? void 0 : T.dataCache) == null ? void 0 : S[v || b || "en"]
213
- }
214
- )
215
- },
216
- i.id
217
- )
218
- ), C;
219
- }),
220
- l.map((p) => {
221
- const i = c[p];
222
- return i ? /* @__PURE__ */ e(
223
- I,
224
- {
225
- path: R(":projectIdOrSlug?", i.slug),
226
- element: /* @__PURE__ */ e(
227
- N,
228
- {
229
- mode: t,
230
- components: w,
231
- page: i,
232
- locale: v,
233
- defaultLocale: b,
234
- headerAddons: P
235
- }
236
- )
237
- },
238
- i.id
239
- ) : null;
240
- }),
241
- y.pages && Object.values(y.pages).map(({ blockletId: p, page: i }) => /* @__PURE__ */ e(
242
- I,
243
- {
244
- path: R("/", `@${p}`, i.slug),
245
- element: /* @__PURE__ */ e(
246
- N,
247
- {
248
- mode: t,
249
- components: w,
250
- page: i,
251
- locale: v,
252
- defaultLocale: b,
253
- headerAddons: P
254
- }
255
- )
256
- },
257
- i.id
258
- )),
259
- /* @__PURE__ */ e(
260
- I,
261
- {
262
- path: "*",
263
- element: /* @__PURE__ */ e(O, { width: "100vw", height: "100vh", display: "flex", justifyContent: "center", alignItems: "center", children: /* @__PURE__ */ e(K, { status: 404, extra: /* @__PURE__ */ e(le, { href: "/", children: s("common.back") }) }) })
264
- }
265
- )
266
- ] }),
267
- t !== "production" && !n && /* @__PURE__ */ e(Ve, { sx: { bgcolor: "info.light" }, children: t }),
268
- /* @__PURE__ */ e(qe, {})
269
- ] });
270
- }
271
- function G({
272
- mode: t,
273
- pageData: o,
274
- components: s,
275
- page: a,
276
- locale: r,
277
- defaultLocale: n,
278
- headerAddons: d,
279
- state: l
280
- }) {
281
- const c = ee({
282
- page: null
283
- });
284
- F(() => {
285
- const m = a || null;
286
- m ? c.page = D(m) : c.page = null;
287
- }, [a, c]);
288
- const g = ne();
289
- return F(() => {
290
- te(o, g.current) || o && c.page && (Q(c.page, l, r, o), g.current = D(o));
291
- }, [c.page, o, r, l]), c.page ? /* @__PURE__ */ e(
292
- N,
293
- {
294
- mode: t,
295
- components: s,
296
- page: c.page,
297
- locale: r,
298
- defaultLocale: n,
299
- headerAddons: d
300
- }
301
- ) : null;
302
- }
303
- function Ot({
304
- mode: t,
305
- state: o,
306
- path: s,
307
- pageData: a
308
- }) {
309
- const { t: r, locale: n } = q(), {
310
- pages: d,
311
- supportedLocales: l,
312
- config: { defaultLocale: c },
313
- resources: g
314
- } = o, m = Object.values(d).find((f) => (f == null ? void 0 : f.slug) === s), u = Object.values(g.pages || {}).find((f) => f.page.slug === s), b = M(
315
- () => l != null && l.some((f) => f.locale === n) ? n : void 0,
316
- [n, l]
317
- ), y = ee({
318
- page: null
319
- });
320
- F(() => {
321
- const f = m || (u == null ? void 0 : u.page) || null;
322
- f ? y.page = D(f) : y.page = null;
323
- }, [m, u]);
324
- const w = ne();
325
- if (F(() => {
326
- te(a, w.current) || a && y.page && (Q(y.page, o, b, a), w.current = D(a));
327
- }, [{}]), !m && !(u != null && u.page))
328
- return /* @__PURE__ */ e(O, { width: "100vw", height: "100vh", display: "flex", justifyContent: "center", alignItems: "center", children: /* @__PURE__ */ e(K, { style: { background: "inherit" }, status: 404, extra: /* @__PURE__ */ e(le, { href: "/", children: r("common.back") }) }) });
329
- const v = W(o);
330
- return y.page ? /* @__PURE__ */ e(
331
- N,
332
- {
333
- mode: t,
334
- components: v,
335
- page: y.page,
336
- locale: b,
337
- defaultLocale: c
338
- }
339
- ) : null;
340
- }
341
- function N({
342
- mode: t,
343
- components: o,
344
- page: s,
345
- locale: a,
346
- defaultLocale: r,
347
- headerAddons: n
348
- }) {
349
- var L, P, p, i, k, C, j, E, T;
350
- const d = ge(), l = ((L = s.locales) == null ? void 0 : L[a]) ?? ((P = s.locales) == null ? void 0 : P[r]) ?? {}, c = l.title || ((p = window.blocklet) == null ? void 0 : p.appName), g = l.description || ((i = window.blocklet) == null ? void 0 : i.appDescription), m = ce(ue(l.image), 540), { logo: u, brand: b, description: y, ...w } = de(), v = M(
351
- () => (S) => {
352
- var x;
353
- let h = (n == null ? void 0 : n(S)) ?? S;
354
- return h = ((x = w.addons) == null ? void 0 : x.call(w, h)) ?? h, h;
355
- },
356
- [w.addons, n]
357
- ), f = (k = l.header) != null && k.translucent ? ot : ie;
358
- return /* @__PURE__ */ A(Oe, { page: s, defaultLocale: r, currentLocale: a, children: [
359
- /* @__PURE__ */ e(
360
- Y,
361
- {
362
- styles: J`
363
- body {
364
- background-color: ${d(
365
- !l.backgroundColor || l.backgroundColor === "transparent" ? "background.default" : l.backgroundColor
366
- )} !important;
367
- }
368
- `
369
- }
370
- ),
371
- /* @__PURE__ */ e(
372
- f,
373
- {
374
- hideNavMenu: !!((C = l.header) != null && C.hideNavMenus),
375
- translucentTextColor: (j = l.header) == null ? void 0 : j.translucentTextColor,
376
- ...u ? { logo: u } : {},
377
- ...b ? { brand: b } : {},
378
- ...y ? { description: y } : {},
379
- className: X(((E = l.header) == null ? void 0 : E.sticky) && "sticky", "page-header"),
380
- maxWidth: !1,
381
- addons: v
382
- }
383
- ),
384
- /* @__PURE__ */ e(Te, {}),
385
- /* @__PURE__ */ A(Me, { children: [
386
- /* @__PURE__ */ e("title", { children: c }),
387
- /* @__PURE__ */ e("meta", { name: "og:title", content: c }),
388
- /* @__PURE__ */ e("meta", { name: "og:description", content: g }),
389
- /* @__PURE__ */ e("meta", { name: "og:image", content: m }),
390
- /* @__PURE__ */ e("meta", { name: "twitter:image:src", content: m }),
391
- /* @__PURE__ */ e("meta", { name: "twitter:image", content: m }),
392
- /* @__PURE__ */ e("meta", { property: "twitter:description", content: g }),
393
- /* @__PURE__ */ e("meta", { property: "twitter:title", content: c }),
394
- /* @__PURE__ */ e("meta", { name: "description", content: g })
395
- ] }),
396
- /* @__PURE__ */ e(
397
- we,
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((S) => {
408
- var B, $;
409
- const h = s.sections[S];
410
- if (!h || h.visibility === "hidden") return null;
411
- const x = (B = h.locales) == null ? void 0 : B[a], _ = (($ = h.locales) == null ? void 0 : $[r]) ?? {};
412
- return /* @__PURE__ */ e(
413
- Le,
414
- {
415
- id: S,
416
- type: h.component,
417
- mode: t,
418
- section: h,
419
- config: {
420
- ...ke(x) ? _ : x,
421
- locale: a,
422
- dev: t === "draft" ? {
423
- mode: t,
424
- components: o,
425
- defaultLocale: r
426
- } : { mode: t }
427
- }
428
- },
429
- S
430
- );
431
- })
432
- }
433
- ),
434
- !((T = l.footer) != null && T.hidden) && /* @__PURE__ */ e(Ue, {})
435
- ] });
436
- }
437
- const et = oe(() => import("./publish-button-BauXdoix.js")), ie = Z(he)`
438
- &.sticky {
439
- position: sticky;
440
- top: 0;
441
- }
442
- `;
443
- function tt({ logo: t }) {
444
- const [o, s] = Re(), a = Se((n) => n.breakpoints.down("sm")), { value: r } = se(() => {
445
- var l, c;
446
- const n = new URL(
447
- a ? ((l = window == null ? void 0 : window.blocklet) == null ? void 0 : l.appLogo) || "/.well-known/service/blocklet/logo" : ((c = window == null ? void 0 : window.blocklet) == null ? void 0 : c.appLogoRect) || "/.well-known/service/blocklet/logo-rect",
448
- window.location.origin
449
- );
450
- n.searchParams.delete("imageFilter"), n.searchParams.delete("f");
451
- const d = n.toString();
452
- return new Promise((g) => {
453
- fetch(d).then((m) => {
454
- const u = m.headers.get("content-type");
455
- u != null && u.includes("svg") && m.text().then((b) => {
456
- s(b), g(null);
457
- }), g(m.url);
458
- });
459
- });
460
- }, [a]);
461
- if (t)
462
- return t;
463
- if (o)
464
- return /* @__PURE__ */ e(O, { sx: { filter: "initial !important" }, dangerouslySetInnerHTML: { __html: Pe.sanitize(o) } });
465
- if (r) {
466
- const n = new URL(r);
467
- n.searchParams.set("imageFilter", "convert"), n.searchParams.set("f", "png"), n.searchParams.set("h", "80");
468
- const d = n.toString();
469
- return /* @__PURE__ */ e("img", { src: d, alt: "logo" });
470
- }
471
- return null;
472
- }
473
- function ot({
474
- logo: t,
475
- translucentTextColor: o,
476
- ...s
477
- }) {
478
- const { top: a = 0 } = xe(() => document.getElementById("app")) || {};
479
- let r = Math.min(a / 800, 1), n = "";
480
- if (r > 0.1) {
481
- r = Math.max(r, 0.6);
482
- const d = Math.round(255 * Math.min(1 - r, 0.2));
483
- n = `rgb(${d}, ${d}, ${d})`;
484
- } else
485
- n = o || "#EEEEEE";
486
- return /* @__PURE__ */ e(
487
- ie,
488
- {
489
- logo: /* @__PURE__ */ e(tt, { logo: t }),
490
- ...s,
491
- className: X(r <= 0.7 && "reverse-color"),
492
- style: {
493
- backgroundColor: `rgba(255,255,255,${r})`,
494
- // @ts-ignore
495
- "--logo-invert": r <= 0.7 ? 1 - r / 6 : 1 - r
496
- },
497
- sx: {
498
- backdropFilter: r >= 0.6 ? "blur(10px)" : "blur(0px)",
499
- transition: "all 0.3s ease",
500
- position: "fixed !important",
501
- left: 0,
502
- top: 0,
503
- right: 0,
504
- bgcolor: "transparent",
505
- "&.reverse-color": {
506
- ".navmenu-root>.navmenu-sub>span,\n .navmenu-root>.navmenu-item,\n .header-addons>button,\n .header-addons>a,\n .header-addons>div>button": {
507
- color: `${n} !important`
508
- }
509
- },
510
- "& .navmenu--horizontal": {
511
- bgcolor: "transparent !important"
512
- },
513
- ".header-logo > div": {
514
- filter: "invert(var(--logo-invert))"
515
- },
516
- ".header-logo": {
517
- color: n
518
- }
519
- }
520
- }
521
- );
522
- }
523
- const le = Z(ye)``;
524
- export {
525
- Ft as H,
526
- ze as L,
527
- H as P,
528
- ot as T,
529
- Ye as a,
530
- G as b,
531
- Ot as c,
532
- N as d
533
- };