@blocklet/pages-kit-inner-components 0.4.127 → 0.4.129

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