@blocklet/pages-kit-inner-components 0.4.98 → 0.4.100

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.
@@ -0,0 +1,425 @@
1
+ import { jsx as I } from "react/jsx-runtime";
2
+ import { Box as L, Alert as q, Tooltip as K } from "@mui/material";
3
+ import { joinURL as k, withQuery as Q } from "ufo";
4
+ import { createAxios as X } from "@blocklet/js-sdk";
5
+ import Z from "lodash/isEmpty";
6
+ import * as Y from "yaml";
7
+ import { useLocaleContext as H } from "@arcblock/ux/lib/Locale/context";
8
+ import tt, { getYjsDoc as et } from "@syncedstore/core";
9
+ import { useSyncedStore as ot } from "@syncedstore/react";
10
+ import { useLocalStorageState as nt } from "ahooks";
11
+ import { produce as b } from "immer";
12
+ import rt from "js-cookie";
13
+ import J from "lodash/debounce";
14
+ import { customAlphabet as st } from "nanoid";
15
+ import { createContext as it, useState as E, useRef as ct, useMemo as C, useCallback as O, useEffect as x, useContext as at } from "react";
16
+ import { useParams as lt, useNavigate as dt } from "react-router-dom";
17
+ import { IndexeddbPersistence as ut } from "y-indexeddb";
18
+ import { WebsocketProvider as mt } from "y-websocket";
19
+ import { UndoManager as ft } from "yjs";
20
+ import "@blocklet/pages-kit/types";
21
+ const Gt = (e) => {
22
+ const o = blocklet == null ? void 0 : blocklet.componentMountPoints.find((a) => a.name === e);
23
+ return o ? o.mountPoint : "/";
24
+ };
25
+ function pt() {
26
+ const { pathname: e } = window.location, o = e.match(/\/admin\/(maker|previewer)\/([^/]+)/), a = o == null ? void 0 : o[2], l = window.__PROJECT_ID__;
27
+ if (!a && !l)
28
+ throw new Error("Unable to get projectId from pathname");
29
+ return a || l;
30
+ }
31
+ function qt(e) {
32
+ return `${e}:pages:version`;
33
+ }
34
+ function Kt(e, o) {
35
+ return o === "yaml" ? Z(e) ? "" : Y.stringify(e, { indent: 2 }) : o === "json" ? JSON.parse(JSON.stringify(e || "{}")) : o === "array" ? JSON.parse(JSON.stringify(e || "[]")) : e;
36
+ }
37
+ function Qt({ error: e }) {
38
+ return /* @__PURE__ */ I(L, { children: /* @__PURE__ */ I(q, { severity: "error", children: e.message }) });
39
+ }
40
+ var W;
41
+ const A = ((W = window.blocklet) == null ? void 0 : W.prefix) || "/", z = X({
42
+ timeout: 200 * 1e3
43
+ }), wt = window.location.protocol === "https:" ? "wss" : "ws", Xt = (e) => k(`${wt}://${window.location.hostname}`, A, `api/${e}/ws/pages`), St = "z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";
44
+ var F;
45
+ (F = blocklet == null ? void 0 : blocklet.componentMountPoints.find((e) => e.did === St)) != null && F.mountPoint || k(A, "/image-bin");
46
+ function Zt(e) {
47
+ return e && !/^(https?:\/\/|\/)/.test(e) ? window.location.origin + k(A, "uploads", e) : e;
48
+ }
49
+ const ht = window.innerWidth <= 750;
50
+ function Yt(e, o, a) {
51
+ if (!e || /\.gif/.test(e)) return e;
52
+ const l = (ht ? o / 1.5 : o) * (a === "quality" ? 1.5 : 1);
53
+ return Pt(e, { imageFilter: "resize", w: l, f: "webp" });
54
+ }
55
+ function Pt(e, o) {
56
+ return !e || !o ? e : Q(e, o);
57
+ }
58
+ async function gt(e) {
59
+ return z.get(`/api/projects/${e}`).then((o) => o.data);
60
+ }
61
+ async function Ct(e) {
62
+ return z.post(`/api/projects/${e.id}/update`, e).then((o) => o.data);
63
+ }
64
+ const It = 500, D = st("abcdefghijklmnopqrstuvwxyz0123456789", 16), B = it(null);
65
+ function Ht({
66
+ url: e,
67
+ name: o,
68
+ children: a,
69
+ waitingSynced: l
70
+ }) {
71
+ const [u, d] = E(!1), { locale: g } = H(), S = V(), t = `${S}:MakerLocalState`, s = `${S}:${o}`, [r, n] = nt(t, {
72
+ defaultValue: {},
73
+ listenStorageChange: !0
74
+ }), i = ct(r);
75
+ i.current = r;
76
+ const c = C(
77
+ () => tt({
78
+ pages: {},
79
+ pageIds: [],
80
+ components: {},
81
+ supportedLocales: [],
82
+ config: {},
83
+ resources: {}
84
+ }),
85
+ []
86
+ ), m = C(() => et(c), [c]);
87
+ C(() => new ut(s, m), [s, m]);
88
+ const h = C(
89
+ () => new mt(e, s, m, {
90
+ params: { token: rt.get("login_token") },
91
+ resyncInterval: 5 * 60 * 1e3
92
+ }),
93
+ [e, s, m]
94
+ ), T = O(() => {
95
+ h && (h.disconnect(), h.connect());
96
+ }, [h]), v = C(
97
+ () => new ft(
98
+ [m.getArray("pageIds"), m.getMap("pages"), m.getArray("supportedLocales"), m.getMap("config")],
99
+ { doc: m }
100
+ ),
101
+ [m]
102
+ ), [y, j] = E(null), [_, $] = E(!1), [M, U] = E(void 0), N = O(async () => {
103
+ if (S) {
104
+ $(!0);
105
+ try {
106
+ const f = await gt(S);
107
+ j(f);
108
+ } catch (f) {
109
+ console.error("Failed to fetch project:", f);
110
+ } finally {
111
+ $(!1);
112
+ }
113
+ }
114
+ }, [S]), R = O(
115
+ async (f, p) => {
116
+ var P;
117
+ if (U(void 0), !!S) {
118
+ p != null && p.optimisticUpdate && y && j((w) => ({
119
+ ...w,
120
+ ...f
121
+ }));
122
+ try {
123
+ const w = await Ct({
124
+ ...f
125
+ });
126
+ j(w);
127
+ } catch (w) {
128
+ console.error("Failed to update project:", w), p != null && p.optimisticUpdate && j(y), U((P = w == null ? void 0 : w.response) == null ? void 0 : P.data);
129
+ }
130
+ }
131
+ },
132
+ [S, y]
133
+ );
134
+ x(() => {
135
+ S && N();
136
+ }, [S, N]);
137
+ const G = C(
138
+ () => ({
139
+ doc: m,
140
+ state: c,
141
+ localState: {
142
+ ...r,
143
+ // always use the locale from the context
144
+ currentLocale: g
145
+ },
146
+ setLocalState: (f) => n(typeof f == "function" ? (p) => f(p ?? {}) : f),
147
+ undoManager: v,
148
+ projectState: {
149
+ project: y,
150
+ isLoadingProject: _,
151
+ error: M
152
+ },
153
+ updateProject: R,
154
+ forceSync: T
155
+ }),
156
+ // eslint-disable-next-line react-hooks/exhaustive-deps
157
+ [
158
+ m,
159
+ c,
160
+ JSON.stringify(r),
161
+ // resolve the problem of react warning
162
+ n,
163
+ v,
164
+ y,
165
+ _,
166
+ R,
167
+ M,
168
+ g,
169
+ T
170
+ ]
171
+ );
172
+ return x(() => {
173
+ v.on("stack-item-added", ({ stackItem: f }) => {
174
+ const { currentPageId: p, currentLocale: P, pages: w } = i.current;
175
+ f.meta.set("localState", { currentPageId: p, currentLocale: P, pages: w });
176
+ }), v.on("stack-item-popped", ({ stackItem: f }) => {
177
+ const p = f.meta.get("localState");
178
+ p && n((P) => ({ ...P, ...p }));
179
+ });
180
+ }, [v, n]), x(() => {
181
+ h.awareness.setLocalState(r);
182
+ }, [h, r]), x(() => {
183
+ h.once("synced", () => d(!0));
184
+ const f = () => {
185
+ n((w) => ({
186
+ ...w,
187
+ networkStatus: void 0
188
+ }));
189
+ }, p = () => {
190
+ n((w) => ({
191
+ ...w,
192
+ networkStatus: "offline"
193
+ }));
194
+ }, P = J(({ status: w }) => {
195
+ w === "connected" ? f() : w === "disconnected" && p();
196
+ }, It);
197
+ return h.on("status", P), window.addEventListener("online", f), window.addEventListener("offline", p), () => {
198
+ h.off("status", P), window.removeEventListener("online", f), window.removeEventListener("offline", p);
199
+ };
200
+ }, [h, n]), l && !u ? null : /* @__PURE__ */ I(B.Provider, { value: G, children: a });
201
+ }
202
+ const vt = () => {
203
+ const e = at(B);
204
+ if (!e)
205
+ throw new Error("Context is null");
206
+ const o = ot(e.state), { setLocalState: a, localState: l } = e, u = dt(), d = V(), g = C(
207
+ () => ({
208
+ setCurrentSectionId: (t, s) => {
209
+ var r, n;
210
+ t === l.currentPageId && s === ((n = (r = l.pages) == null ? void 0 : r[t]) == null ? void 0 : n.currentSectionId) || (u(k("/admin/maker", d ?? "", "pages", t)), a(
211
+ (i) => b(i, (c) => {
212
+ var m;
213
+ c.currentPageId = t, c.currentComponentId = void 0, c.customComponentPreviewerProperties = {}, s !== void 0 && (c.pages ?? (c.pages = {}), (m = c.pages)[t] ?? (m[t] = {}), c.pages[t].currentSectionId = s ?? void 0), s ? window.sessionStorage.setItem("iframe_show_id", `"${s}"`) : window.sessionStorage.removeItem("iframe_show_id");
214
+ })
215
+ ));
216
+ },
217
+ setCurrentComponentId: (t) => {
218
+ t !== l.currentComponentId && (u(k("/admin/maker", d ?? "", "components", t)), a(
219
+ (s) => b(s, (r) => {
220
+ r.currentComponentId = t, r.customComponentPreviewerProperties = {};
221
+ })
222
+ ));
223
+ },
224
+ setCustomComponentPreviewerProperties: (() => {
225
+ const t = {}, s = J(() => {
226
+ a(
227
+ (r) => b(r, (n) => {
228
+ n.customComponentPreviewerProperties = {
229
+ ...n == null ? void 0 : n.customComponentPreviewerProperties,
230
+ ...t
231
+ }, Object.keys(t).forEach((i) => delete t[i]);
232
+ })
233
+ );
234
+ }, 5);
235
+ return (r) => {
236
+ Object.assign(t, r), s();
237
+ };
238
+ })()
239
+ }),
240
+ [a, u, d]
241
+ ), S = C(
242
+ () => ({
243
+ addPage: (t, s) => {
244
+ var i, c, m, h;
245
+ const r = (t == null ? void 0 : t.id) ?? D(), n = {
246
+ ...t,
247
+ id: r,
248
+ createdAt: (t == null ? void 0 : t.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
249
+ updatedAt: (t == null ? void 0 : t.updatedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
250
+ publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
251
+ slug: (t == null ? void 0 : t.slug) ?? `/${r}`,
252
+ sections: (t == null ? void 0 : t.sections) ?? {},
253
+ sectionIds: (t == null ? void 0 : t.sectionIds) ?? [],
254
+ isPublic: (t == null ? void 0 : t.isPublic) ?? !0,
255
+ templateConfig: (t == null ? void 0 : t.templateConfig) ?? {
256
+ isTemplate: ((i = t == null ? void 0 : t.templateConfig) == null ? void 0 : i.isTemplate) ?? !0,
257
+ displayTemplateId: ((c = t == null ? void 0 : t.templateConfig) == null ? void 0 : c.displayTemplateId) ?? void 0,
258
+ dataSourceId: ((m = t == null ? void 0 : t.templateConfig) == null ? void 0 : m.dataSourceId) ?? void 0,
259
+ dataSourceParameters: ((h = t == null ? void 0 : t.templateConfig) == null ? void 0 : h.dataSourceParameters) ?? {}
260
+ }
261
+ };
262
+ return e.doc.transact(() => {
263
+ o.pages[n.id] = n, o.pageIds.splice(s ?? o.pageIds.length, 0, n.id);
264
+ }), n;
265
+ },
266
+ deletePage: (t) => {
267
+ const s = o.pageIds.indexOf(t);
268
+ s !== -1 && e.doc.transact(() => {
269
+ o.pageIds.splice(s, 1), delete o.pages[t];
270
+ });
271
+ },
272
+ movePage: (t, s) => {
273
+ const { pageIds: r } = o, n = r.indexOf(t);
274
+ n >= 0 && r.splice(s, 0, ...r.splice(n, 1));
275
+ },
276
+ addSection: (t, s, r) => {
277
+ const n = o.pages[t];
278
+ if (!n)
279
+ throw new Error(`Page ${t} is not exists`);
280
+ const i = {
281
+ ...s,
282
+ id: s.id ?? D(),
283
+ isTemplateSection: s.isTemplateSection ?? !0,
284
+ llmConfig: s.llmConfig ?? {}
285
+ };
286
+ return e.doc.transact(() => {
287
+ n.sections[i.id] = i, n.sectionIds.splice(r ?? n.sectionIds.length, 0, i.id);
288
+ }), i;
289
+ },
290
+ deleteSection: (t, s) => {
291
+ const r = o.pages[t];
292
+ if (!r)
293
+ throw new Error(`Page ${t} is not exists`);
294
+ const n = r.sectionIds.indexOf(s);
295
+ n !== -1 && e.doc.transact(() => {
296
+ r.sectionIds.splice(n, 1), delete r.sections[s];
297
+ });
298
+ },
299
+ toggleSectionVisibility: (t, s, r) => {
300
+ const n = o.pages[t];
301
+ if (!n)
302
+ throw new Error(`Page ${t} is not exists`);
303
+ const i = n.sections[s];
304
+ i && (i.visibility = r);
305
+ },
306
+ moveSection: (t, s, r) => {
307
+ const n = o.pages[t];
308
+ if (!n)
309
+ throw new Error(`Page ${t} is not exists`);
310
+ const { sectionIds: i } = n, c = i.indexOf(s);
311
+ c >= 0 && i.splice(r, 0, ...i.splice(c, 1));
312
+ }
313
+ }),
314
+ [o, e.doc]
315
+ );
316
+ return {
317
+ ...e,
318
+ state: o,
319
+ actions: S,
320
+ localActions: g,
321
+ get currentPage() {
322
+ const {
323
+ localState: { currentPageId: t }
324
+ } = e;
325
+ return t ? o.pages[t] : void 0;
326
+ },
327
+ get currentSection() {
328
+ var n, i, c;
329
+ const {
330
+ localState: { currentPageId: t, ...s }
331
+ } = e;
332
+ if (!t)
333
+ return;
334
+ const r = (i = (n = s.pages) == null ? void 0 : n[t]) == null ? void 0 : i.currentSectionId;
335
+ if (r)
336
+ return (c = o.pages[t]) == null ? void 0 : c.sections[r];
337
+ }
338
+ };
339
+ }, V = () => {
340
+ const { projectId: e } = lt();
341
+ return e ?? pt() ?? "";
342
+ };
343
+ function yt(e) {
344
+ var l, u;
345
+ const { resources: o } = e;
346
+ if (!o.components)
347
+ return {};
348
+ const a = {};
349
+ return (u = (l = window == null ? void 0 : window.blocklet) == null ? void 0 : l.componentMountPoints) == null || u.forEach((d) => {
350
+ a[d.did] = d;
351
+ }), Object.fromEntries(
352
+ Object.entries(o.components).map(([d, { blockletId: g, component: S }]) => {
353
+ var t;
354
+ return [
355
+ d,
356
+ { data: S, blockletId: g, blockletTitle: ((t = a[g]) == null ? void 0 : t.title) || g }
357
+ ];
358
+ })
359
+ );
360
+ }
361
+ function kt(e) {
362
+ const { components: o } = e;
363
+ return o || {};
364
+ }
365
+ function jt(e) {
366
+ return {
367
+ ...yt(e),
368
+ ...kt(e)
369
+ };
370
+ }
371
+ const te = () => jt(vt().state), Et = [
372
+ /\.\./,
373
+ // Directory traversal
374
+ /<[^>]*>/,
375
+ // HTML/XML tags
376
+ /%[0-9a-f]{2}/i,
377
+ // Percent encoding
378
+ /[<>'"%;{}()\\]/,
379
+ // Special characters
380
+ // eslint-disable-next-line no-control-regex
381
+ /\x00/,
382
+ // Null byte
383
+ /\n|\r|\t|\v|\f/,
384
+ // Control characters
385
+ /[^a-zA-Z0-9-_@/]/
386
+ // Disallow any characters except alphanumeric, dash, underscore and forward slash
387
+ ];
388
+ function ee(e, o, a) {
389
+ const l = [];
390
+ {
391
+ let u;
392
+ o.slug ? o.slug.startsWith("/") ? o.slug !== "/" && o.slug.endsWith("/") ? u = e("maker.properties.pathCheckEndWithoutSlash") : /\/{2,}/.test(o.slug) ? u = e("maker.properties.pathCheckConsecutiveSlash") : /\s/.test(o.slug) ? u = e("maker.properties.pathCheckWhitespace") : Et.some((d) => d.test(o.slug)) ? u = e("maker.properties.pathCheckInvalid") : Object.values(a.pages).some((d) => (d == null ? void 0 : d.id) !== o.id && (d == null ? void 0 : d.slug) === o.slug) && (u = e("maker.properties.pathCheckAlreadyExist")) : u = e("maker.properties.pathCheckStartWithSlash") : u = e("maker.properties.pathCheckRequired"), u && l.push({ path: ["path"], message: u });
393
+ }
394
+ return l.length > 0 ? l : null;
395
+ }
396
+ function oe({ errors: e, ...o }) {
397
+ return e != null && e.length ? /* @__PURE__ */ I(
398
+ K,
399
+ {
400
+ ...o,
401
+ title: /* @__PURE__ */ I(L, { children: e.map((a, l) => /* @__PURE__ */ I(L, { children: a.message }, l)) })
402
+ }
403
+ ) : null;
404
+ }
405
+ export {
406
+ Qt as E,
407
+ oe as P,
408
+ Ht as S,
409
+ Yt as a,
410
+ Zt as b,
411
+ qt as c,
412
+ vt as d,
413
+ te as e,
414
+ z as f,
415
+ jt as g,
416
+ Gt as h,
417
+ kt as i,
418
+ yt as j,
419
+ pt as k,
420
+ Xt as l,
421
+ ee as m,
422
+ D as n,
423
+ Kt as t,
424
+ V as u
425
+ };
package/lib/es/home.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import "react/jsx-runtime";
2
- import "./chunks/state-JDvNqLu1.js";
3
- import { a as h, P as x, c as y, b as B, T as R, H as j } from "./chunks/home-DQvcjT5p.js";
2
+ import "./chunks/state-DsXKwImw.js";
3
+ import { a as y, P as B, c as R, b as j, T as k, H as q } from "./chunks/home-BBfstt15.js";
4
4
  import "@arcblock/ux/lib/Locale/context";
5
5
  import "@arcblock/ux/lib/Result";
6
6
  import "@blocklet/pages-kit/builtin/page/header";
7
+ import "@blocklet/pages-kit/contexts/color";
7
8
  import "@blocklet/ui-react/lib/Header";
8
9
  import "@emotion/css";
9
10
  import "@emotion/react";
@@ -19,11 +20,12 @@ import "react-helmet";
19
20
  import "react-router-dom";
20
21
  import "react-use";
21
22
  import "ufo";
23
+ import "./chunks/array-C85JziT_.js";
22
24
  export {
23
- h as HomeView,
24
- x as PageRoutes,
25
- y as PageView,
26
- B as PageViewByPath,
27
- R as TranslucentHeader,
28
- j as default
25
+ y as HomeView,
26
+ B as PageRoutes,
27
+ R as PageView,
28
+ j as PageViewByPath,
29
+ k as TranslucentHeader,
30
+ q as default
29
31
  };