@blocklet/pages-kit-inner-components 0.5.56 → 0.6.0

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.
Files changed (45) hide show
  1. package/lib/cjs/add-component.js +21 -23
  2. package/lib/cjs/chunks/{draft-data-CuZfaQ4s.js → draft-data-D44_IEV2.js} +1 -1
  3. package/lib/cjs/chunks/home-BYk01EUy.js +39 -0
  4. package/lib/cjs/chunks/index-BRgYwvuv.js +475 -0
  5. package/lib/cjs/chunks/publish-button-C8XPA4g_.js +1 -0
  6. package/lib/cjs/chunks/session-BRtsDvA-.js +1 -0
  7. package/lib/cjs/chunks/site-state-gSkcvhcV.js +57 -0
  8. package/lib/cjs/chunks/state-B6BF5wJ-.js +1 -0
  9. package/lib/cjs/components.js +1 -1
  10. package/lib/cjs/home.js +1 -1
  11. package/lib/cjs/project-html.js +7 -7
  12. package/lib/cjs/resources.js +1 -1
  13. package/lib/cjs/setting.js +3 -3
  14. package/lib/cjs/site-state.js +1 -1
  15. package/lib/cjs/theme.js +1 -1
  16. package/lib/es/add-component.js +385 -2356
  17. package/lib/es/chunks/{draft-data-CWM--ooz.js → draft-data-CafrGKeh.js} +1 -1
  18. package/lib/es/chunks/home-DW8SdyfO.js +594 -0
  19. package/lib/es/chunks/index-D5gXPe_7.js +2326 -0
  20. package/lib/es/chunks/publish-button-XSZrDaTQ.js +498 -0
  21. package/lib/es/chunks/session-C72Dq8zg.js +19 -0
  22. package/lib/es/chunks/site-state-W2H7XCSQ.js +2077 -0
  23. package/lib/es/chunks/state-0gvZF3k2.js +573 -0
  24. package/lib/es/components.js +1 -1
  25. package/lib/es/home.js +5 -5
  26. package/lib/es/project-html.js +131 -141
  27. package/lib/es/resources.js +106 -107
  28. package/lib/es/setting.js +1772 -1489
  29. package/lib/es/site-state.js +1 -1
  30. package/lib/es/theme.js +50 -51
  31. package/package.json +46 -47
  32. package/lib/cjs/chunks/array-BqHuYyfx.js +0 -475
  33. package/lib/cjs/chunks/config-string-4bVR9Vc8.js +0 -1
  34. package/lib/cjs/chunks/home-BMjMYgq3.js +0 -38
  35. package/lib/cjs/chunks/publish-button-CGfGqrov.js +0 -1
  36. package/lib/cjs/chunks/session-BA7Qrcia.js +0 -1
  37. package/lib/cjs/chunks/site-state-BtZ8o3J2.js +0 -57
  38. package/lib/cjs/chunks/state-BVdbNJCA.js +0 -1
  39. package/lib/es/chunks/array-c6HYTLze.js +0 -2224
  40. package/lib/es/chunks/config-string-WMpFf-7V.js +0 -88
  41. package/lib/es/chunks/home-PDsc59QG.js +0 -566
  42. package/lib/es/chunks/publish-button-Ds7OBvxV.js +0 -462
  43. package/lib/es/chunks/session-CVblGhSp.js +0 -21
  44. package/lib/es/chunks/site-state-D-moj9fA.js +0 -2125
  45. package/lib/es/chunks/state-l--dTdHq.js +0 -603
@@ -0,0 +1,573 @@
1
+ import { jsx as k } from "react/jsx-runtime";
2
+ import { Box as V, Alert as K } from "@mui/material";
3
+ import { joinURL as b, withQuery as z } from "ufo";
4
+ import { createAxios as Q } from "@blocklet/js-sdk";
5
+ import X from "lodash/isEmpty";
6
+ import * as q from "yaml";
7
+ import { useLocaleContext as Y } from "@arcblock/ux/lib/Locale/context";
8
+ import { nextId as O } from "@blocklet/pages-kit/utils/common";
9
+ import { getPageTemplateModel as Z } from "@blocklet/pages-kit/utils/page-model";
10
+ import H, { getYjsDoc as ee } from "@syncedstore/core";
11
+ import { useSyncedStore as te } from "@syncedstore/react";
12
+ import { useLocalStorageState as oe } from "ahooks";
13
+ import { produce as v } from "immer";
14
+ import J from "lodash/cloneDeep";
15
+ import G from "lodash/debounce";
16
+ import { createContext as ne, useState as x, useRef as re, useMemo as I, useCallback as M, useEffect as L, useContext as se } from "react";
17
+ import { useParams as ce, useNavigate as ae } from "react-router-dom";
18
+ import { IndexeddbPersistence as ie } from "y-indexeddb";
19
+ import { WebsocketProvider as de } from "y-websocket";
20
+ import { UndoManager as le } from "yjs";
21
+ import "@blocklet/pages-kit/types";
22
+ function ue() {
23
+ const { pathname: o } = window.location, l = o.match(/\/admin\/(maker|previewer)\/([^/]+)/)?.[2], p = window.__PROJECT_ID__;
24
+ if (!l && !p)
25
+ throw new Error("Unable to get projectId from pathname");
26
+ return l || p;
27
+ }
28
+ function We(o) {
29
+ return `${o}:pages:version`;
30
+ }
31
+ function Ve(o, r) {
32
+ return r === "yaml" ? X(o) ? "" : q.stringify(o, { indent: 2 }) : r === "json" ? JSON.parse(JSON.stringify(o || {})) : r === "array" ? JSON.parse(JSON.stringify(o || [])) : o;
33
+ }
34
+ function Ke({ error: o }) {
35
+ return /* @__PURE__ */ k(V, { children: /* @__PURE__ */ k(K, { severity: "error", children: o.message }) });
36
+ }
37
+ const N = window.blocklet?.prefix || "/", B = Q({
38
+ timeout: 200 * 1e3
39
+ }), pe = window.location.protocol === "https:" ? "wss" : "ws", ze = (o) => b(`${pe}://${window.location.hostname}`, N, `api/${o}/ws/pages`), me = "z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";
40
+ blocklet?.componentMountPoints.find((o) => o.did === me)?.mountPoint || b(N, "/image-bin");
41
+ function Qe(o) {
42
+ return o && !/^(https?:\/\/|\/)/.test(o) ? window.location.origin + b(N, "uploads", o) : o;
43
+ }
44
+ const fe = window.innerWidth <= 750;
45
+ function Xe(o, r, l) {
46
+ if (!o || /\.gif/.test(o)) return o;
47
+ const p = (fe ? r / 1.5 : r) * (l === "quality" ? 1.5 : 1);
48
+ return ge(o, { imageFilter: "resize", w: p, f: "webp" });
49
+ }
50
+ function ge(o, r) {
51
+ return !o || !r ? o : z(o, r);
52
+ }
53
+ async function Se(o) {
54
+ return B.get(`/api/projects/${o}`).then((r) => r.data);
55
+ }
56
+ async function Pe(o) {
57
+ return B.post(`/api/projects/${o.id}/update`, o).then((r) => r.data);
58
+ }
59
+ const we = 500, U = ne(null);
60
+ function qe({
61
+ url: o,
62
+ name: r,
63
+ children: l,
64
+ waitingSynced: p
65
+ }) {
66
+ const [w, y] = x(!1), { locale: m } = Y(), P = F(), E = `${P}:MakerLocalState`, e = `${P}:${r}`, [t, s] = oe(E, {
67
+ defaultValue: {},
68
+ listenStorageChange: !0
69
+ }), n = re(t);
70
+ n.current = t;
71
+ const i = I(
72
+ () => H({
73
+ dataSourceIds: [],
74
+ dataSources: {},
75
+ pages: {},
76
+ pageIds: [],
77
+ routes: {},
78
+ routeIds: [],
79
+ components: {},
80
+ supportedLocales: [],
81
+ config: {},
82
+ resources: {}
83
+ }),
84
+ []
85
+ ), c = I(() => ee(i), [i]);
86
+ I(() => new ie(e, c), [e, c]);
87
+ const a = I(
88
+ () => new de(o, e, c, {
89
+ params: {},
90
+ resyncInterval: 5 * 60 * 1e3
91
+ }),
92
+ [o, e, c]
93
+ ), d = M(() => {
94
+ a && (a.disconnect(), a.connect());
95
+ }, [a]), f = I(
96
+ () => new le(
97
+ [
98
+ c.getArray("pageIds"),
99
+ c.getMap("pages"),
100
+ c.getArray("supportedLocales"),
101
+ c.getMap("config"),
102
+ c.getMap("dataSources"),
103
+ c.getArray("dataSourceIds"),
104
+ c.getArray("routeIds"),
105
+ c.getMap("routes")
106
+ ],
107
+ { doc: c }
108
+ ),
109
+ [c]
110
+ ), [C, j] = x(null), [A, R] = x(!1), [_, $] = x(void 0), D = M(async () => {
111
+ if (P) {
112
+ R(!0);
113
+ try {
114
+ const u = await Se(P);
115
+ j(u);
116
+ } catch (u) {
117
+ console.error("Failed to fetch project:", u);
118
+ } finally {
119
+ R(!1);
120
+ }
121
+ }
122
+ }, [P]), T = M(
123
+ async (u, g) => {
124
+ if ($(void 0), !!P) {
125
+ g?.optimisticUpdate && C && j((S) => ({
126
+ ...S,
127
+ ...u
128
+ }));
129
+ try {
130
+ const S = await Pe({
131
+ ...u
132
+ });
133
+ j(S);
134
+ } catch (S) {
135
+ console.error("Failed to update project:", S), g?.optimisticUpdate && j(C), $(S?.response?.data);
136
+ }
137
+ }
138
+ },
139
+ [P, C]
140
+ );
141
+ L(() => {
142
+ P && D();
143
+ }, [P, D]);
144
+ const W = I(
145
+ () => ({
146
+ doc: c,
147
+ state: i,
148
+ localState: {
149
+ ...t,
150
+ // always use the locale from the context
151
+ currentLocale: m
152
+ },
153
+ setLocalState: (u) => s(typeof u == "function" ? (g) => u(g ?? {}) : u),
154
+ undoManager: f,
155
+ projectState: {
156
+ project: C,
157
+ isLoadingProject: A,
158
+ error: _
159
+ },
160
+ updateProject: T,
161
+ forceSync: d
162
+ }),
163
+ // eslint-disable-next-line react-hooks/exhaustive-deps
164
+ [
165
+ c,
166
+ i,
167
+ JSON.stringify(t),
168
+ // resolve the problem of react warning
169
+ s,
170
+ f,
171
+ C,
172
+ A,
173
+ T,
174
+ _,
175
+ m,
176
+ d
177
+ ]
178
+ );
179
+ return L(() => {
180
+ f.on("stack-item-added", ({ stackItem: u }) => {
181
+ const { currentPageId: g, currentLocale: S, pages: h } = n.current;
182
+ u.meta.set("localState", { currentPageId: g, currentLocale: S, pages: h });
183
+ }), f.on("stack-item-popped", ({ stackItem: u }) => {
184
+ const g = u.meta.get("localState");
185
+ g && s((S) => ({ ...S, ...g }));
186
+ });
187
+ }, [f, s]), L(() => {
188
+ a.awareness.setLocalState(t);
189
+ }, [a, t]), L(() => {
190
+ a.once("synced", () => y(!0));
191
+ const u = () => {
192
+ s((h) => ({
193
+ ...h,
194
+ networkStatus: void 0
195
+ }));
196
+ }, g = () => {
197
+ s((h) => ({
198
+ ...h,
199
+ networkStatus: "offline"
200
+ }));
201
+ }, S = G(({ status: h }) => {
202
+ h === "connected" ? u() : h === "disconnected" && g();
203
+ }, we);
204
+ return a.on("status", S), window.addEventListener("online", u), window.addEventListener("offline", g), () => {
205
+ a.off("status", S), window.removeEventListener("online", u), window.removeEventListener("offline", g);
206
+ };
207
+ }, [a, s]), p && !w ? null : /* @__PURE__ */ k(U.Provider, { value: W, children: l });
208
+ }
209
+ const Ie = () => {
210
+ const o = se(U);
211
+ if (!o)
212
+ throw new Error("Context is null");
213
+ const r = te(o.state), { setLocalState: l, localState: p } = o, w = ae(), y = F(), m = I(
214
+ () => ({
215
+ get currentPage() {
216
+ const {
217
+ localState: { currentPageId: e }
218
+ } = o;
219
+ return e ? r.pages[e] : void 0;
220
+ },
221
+ get currentSection() {
222
+ const {
223
+ localState: { currentPageId: e, ...t }
224
+ } = o;
225
+ if (!e)
226
+ return;
227
+ const s = t.pages?.[e]?.currentSectionId;
228
+ if (s)
229
+ return r.pages[e]?.sections[s] ?? this.currentPageModel?.getComponentById(s)?.model;
230
+ },
231
+ get currentSectionProperties() {
232
+ const {
233
+ localState: { currentPageId: e, ...t }
234
+ } = o;
235
+ if (!e)
236
+ return;
237
+ const s = t.pages?.[e]?.currentSectionId;
238
+ if (!s)
239
+ return;
240
+ const n = r.pages[e]?.dataSource?.[s];
241
+ if (!n)
242
+ return;
243
+ const { currentLocale: i } = this.currentLocaleMap;
244
+ return i ? n[i] : void 0;
245
+ },
246
+ get currentSectionPropertiesWithFallback() {
247
+ const {
248
+ localState: { currentPageId: e, ...t }
249
+ } = o;
250
+ if (!e)
251
+ return;
252
+ const s = t.pages?.[e]?.currentSectionId;
253
+ if (!s)
254
+ return;
255
+ const n = r.pages[e]?.dataSource?.[s];
256
+ if (!n)
257
+ return;
258
+ const { currentLocale: i, defaultLocale: c, fallbackLocale: a } = this.currentLocaleMap;
259
+ if (i && n[i])
260
+ return n[i];
261
+ if (c && n[c])
262
+ return n[c];
263
+ if (a && n[a])
264
+ return n[a];
265
+ },
266
+ get currentLocaleMap() {
267
+ const {
268
+ localState: { currentLocale: e },
269
+ state: {
270
+ supportedLocales: t,
271
+ config: { defaultLocale: s }
272
+ }
273
+ } = o;
274
+ return {
275
+ currentLocale: e,
276
+ defaultLocale: s,
277
+ fallbackLocale: t?.[0]?.locale ?? "en"
278
+ };
279
+ },
280
+ get currentRoute() {
281
+ const {
282
+ localState: { currentRouteId: e }
283
+ } = o;
284
+ return e ? r.routes?.[e] : void 0;
285
+ },
286
+ get currentPageModel() {
287
+ const e = this.currentPage ?? null;
288
+ if (e)
289
+ return Z(e, !1);
290
+ }
291
+ }),
292
+ [JSON.stringify(p), r]
293
+ ), P = I(
294
+ () => ({
295
+ setCurrentSectionId: (e, t) => {
296
+ e === p.currentPageId && t === p.pages?.[e]?.currentSectionId || (w(b("/admin/maker", y ?? "", "pages", e)), l(
297
+ (s) => v(s, (n) => {
298
+ n.currentPageId = e, n.currentComponentId = void 0, t !== void 0 && (n.pages ??= {}, n.pages[e] ??= {}, n.pages[e].currentSectionId = t ?? void 0), t ? window.sessionStorage.setItem("iframe_show_id", `"${t}"`) : window.sessionStorage.removeItem("iframe_show_id");
299
+ })
300
+ ));
301
+ },
302
+ setCurrentComponentId: (e) => {
303
+ e !== p.currentComponentId && (w(b("/admin/maker", y ?? "", "components", e)), l(
304
+ (t) => v(t, (s) => {
305
+ s.currentComponentId = e;
306
+ })
307
+ ));
308
+ },
309
+ setCurrentRouteId: ({ routeId: e, dynamicParams: t }) => {
310
+ l(
311
+ (s) => v(s, (n) => {
312
+ n.currentRouteId = e, n.currentDynamicParams = t;
313
+ })
314
+ );
315
+ },
316
+ // 本地缓存组件调试参数,避免用户切换组件后,需要重新输入
317
+ setCustomComponentPreviewerProperties: (() => {
318
+ const e = {};
319
+ let t = "";
320
+ const s = G(() => {
321
+ l(
322
+ (n) => v(n, (i) => {
323
+ i.customComponentPreviewerProperties ??= {}, i.customComponentPreviewerProperties[t] = {
324
+ ...i.customComponentPreviewerProperties[t],
325
+ ...J(e[t])
326
+ }, delete e[t];
327
+ })
328
+ );
329
+ }, 5);
330
+ return (n, i) => {
331
+ const c = e[n] ?? {};
332
+ Object.assign(c, i), e[n] = c, t = n, s();
333
+ };
334
+ })(),
335
+ setRouteGenerateProcess: (e) => {
336
+ l(
337
+ (t) => v(t, (s) => {
338
+ e ? s.routeGenerateProcess = {
339
+ ...s.routeGenerateProcess,
340
+ ...e
341
+ } : s.routeGenerateProcess = {};
342
+ })
343
+ );
344
+ },
345
+ resetRouteGenerateProcess: () => {
346
+ l(
347
+ (e) => v(e, (t) => {
348
+ t.routeGenerateProcess = {
349
+ progress: "complete"
350
+ };
351
+ })
352
+ );
353
+ }
354
+ }),
355
+ [l, w, y, m]
356
+ ), E = I(
357
+ () => ({
358
+ addPage: (e, t) => {
359
+ const s = e?.id ?? O(), n = {
360
+ ...e,
361
+ id: s,
362
+ createdAt: e?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
363
+ updatedAt: e?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
364
+ publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
365
+ slug: e?.slug ?? `/${s}`,
366
+ sections: e?.sections ?? {},
367
+ sectionIds: e?.sectionIds ?? [],
368
+ isPublic: e?.isPublic ?? !0,
369
+ templateConfig: e?.templateConfig ?? {
370
+ isTemplate: e?.templateConfig?.isTemplate ?? !0,
371
+ displayTemplateId: e?.templateConfig?.displayTemplateId ?? void 0,
372
+ dataSourceIds: e?.templateConfig?.dataSourceIds ?? void 0,
373
+ dataSourceParameters: e?.templateConfig?.dataSourceParameters ?? {},
374
+ enabledGenerate: e?.templateConfig?.enabledGenerate ?? !1,
375
+ agentId: e?.templateConfig?.agentId ?? void 0
376
+ }
377
+ };
378
+ return o.doc.transact(() => {
379
+ r.pages[n.id] = n, r.pageIds.splice(t ?? r.pageIds.length, 0, n.id);
380
+ }), n;
381
+ },
382
+ addRoute: (e, t) => {
383
+ const s = e?.id ?? O(), n = {
384
+ ...e,
385
+ id: s,
386
+ createdAt: e?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
387
+ updatedAt: e?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
388
+ publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
389
+ path: e?.path ?? `/${s}`,
390
+ handler: e?.handler ?? "Pages Kit",
391
+ isPublic: e?.isPublic ?? !0,
392
+ params: e?.params ?? [],
393
+ enabledGenerate: e?.enabledGenerate ?? !1,
394
+ displayTemplateId: e?.displayTemplateId ?? void 0,
395
+ dataSource: e?.dataSource ?? {}
396
+ };
397
+ return o.doc.transact(() => {
398
+ r.routes ??= {}, r.routeIds ??= [], r.routes[n.id] = n, r.routeIds.splice(t ?? r.routeIds.length, 0, n.id);
399
+ }), n;
400
+ },
401
+ deleteRoute: (e) => {
402
+ if (!e)
403
+ return;
404
+ const t = r.routeIds?.indexOf(e);
405
+ t !== void 0 && t !== -1 && o.doc.transact(() => {
406
+ r.routeIds?.splice(t, 1), delete r.routes?.[e];
407
+ });
408
+ },
409
+ deletePage: (e) => {
410
+ const t = r.pageIds.indexOf(e);
411
+ t !== -1 && o.doc.transact(() => {
412
+ r.pageIds.splice(t, 1), delete r.pages[e];
413
+ });
414
+ },
415
+ movePage: (e, t) => {
416
+ const { pageIds: s } = r, n = s.indexOf(e);
417
+ n >= 0 && s.splice(t, 0, ...s.splice(n, 1));
418
+ },
419
+ addSection: (e, t, s, n) => {
420
+ const i = r.pages[e];
421
+ if (!i)
422
+ throw new Error(`Page ${e} is not exists`);
423
+ const c = {
424
+ ...t,
425
+ id: t.id ?? O(),
426
+ isTemplateSection: t.isTemplateSection ?? !0,
427
+ llmConfig: t.llmConfig ?? {}
428
+ }, a = J(c.locales);
429
+ return delete c.locales, o.doc.transact(() => {
430
+ if (n && n.component === "layout-block") {
431
+ const d = m.currentPageModel?.getComponentById(n.id);
432
+ d && (d.model.sections ??= {}, d.model.sections[c.id] = c, d.model.sectionIds ??= [], d.model.sectionIds.push(c.id));
433
+ } else
434
+ i.sections[c.id] = c, i.sectionIds.splice(s ?? i.sectionIds.length, 0, c.id);
435
+ a && (i.dataSource ??= {}, i.dataSource[c.id] = a);
436
+ }), c;
437
+ },
438
+ deleteSection: (e, t) => {
439
+ const s = r.pages[e];
440
+ if (!s)
441
+ throw new Error(`Page ${e} is not exists`);
442
+ o.doc.transact(() => {
443
+ const n = [], i = m.currentPageModel?.getComponentById(t), c = i?.parent;
444
+ if (i && (n.push(i.model.id, ...i.all().map((a) => a.model.id)), c?.model.component === "layout-block")) {
445
+ const a = c.model.sectionIds?.indexOf(t);
446
+ a !== void 0 && a !== -1 && (c.model.sectionIds?.splice(a, 1), delete c.model.sections?.[t]), c.model.config?.gridSettings && Object.keys(c.model.config.gridSettings).forEach((d) => {
447
+ try {
448
+ delete c.model.config.gridSettings[d]?.[t];
449
+ } catch {
450
+ }
451
+ }), c.model.config?.backgroundSectionId === t && (c.model.config.backgroundSectionId = void 0);
452
+ }
453
+ n.forEach((a) => {
454
+ const d = s.sectionIds.indexOf(a);
455
+ d !== -1 && s.sectionIds.splice(d, 1), s.sections[a] && delete s.sections[a], s.dataSource?.[a] && delete s.dataSource?.[a];
456
+ });
457
+ });
458
+ },
459
+ lockSection: (e, t) => {
460
+ if (!r.pages[e])
461
+ throw new Error(`Page ${e} is not exists`);
462
+ const n = m.currentPageModel?.getComponentById(t)?.model;
463
+ n && (n.locked = !n.locked);
464
+ },
465
+ toggleSectionVisibility: (e, t, s) => {
466
+ if (!r.pages[e])
467
+ throw new Error(`Page ${e} is not exists`);
468
+ const i = m.currentPageModel?.getComponentById(t)?.model;
469
+ i && (i.visibility = s);
470
+ },
471
+ moveSection: (e, t, s, n) => {
472
+ if (!r.pages[e])
473
+ throw new Error(`Page ${e} is not exists`);
474
+ if (n && n !== t) {
475
+ const c = m.currentPageModel?.getComponentById(t), a = m.currentPageModel?.getComponentById(n), d = c?.parent, f = a?.parent;
476
+ f && d && f?.model?.id === d?.model?.id ? o.doc.transact(() => {
477
+ d.model.sectionIds.splice(c.getIndex(), 1), d.model.sectionIds.splice(a.getIndex(), 0, t);
478
+ }) : f && d && f?.model?.id !== d?.model?.id && t !== n && !c?.model?.sectionIds?.includes(n) && o.doc.transact(() => {
479
+ f.model.sections[t] = JSON.parse(JSON.stringify(c.model)), f.model.sectionIds.splice(a.getIndex(), 0, t), d.model.sectionIds.splice(c.getIndex(), 1), delete d.model.sections[t];
480
+ });
481
+ }
482
+ },
483
+ copySection: (e, t) => {
484
+ if (!r.pages[e])
485
+ throw new Error(`Page ${e} is not exists`);
486
+ const n = m.currentPageModel?.getComponentById(t);
487
+ if (!n?.model)
488
+ throw new Error(`Section ${t} is not exists`);
489
+ const i = JSON.parse(JSON.stringify(n.model)), c = Ce(i), a = c.id, d = n?.parent;
490
+ return d && (d.model.sections[a] = c, d.model.sectionIds.push(a), P.setCurrentSectionId(e, a), m.currentPage?.dataSource?.[t] && (m.currentPage.dataSource[a] = JSON.parse(
491
+ JSON.stringify(m.currentPage.dataSource[t])
492
+ ))), c;
493
+ },
494
+ addDataSource: (e) => {
495
+ const t = e.id ?? O(), s = {
496
+ ...e ?? {},
497
+ id: t,
498
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
499
+ };
500
+ return o.doc.transact(() => {
501
+ r.dataSourceIds ??= [], r.dataSources ??= {}, r.dataSourceIds.push(t), r.dataSources[t] = s;
502
+ }), r.dataSources[t];
503
+ },
504
+ deleteDataSource: (e) => {
505
+ const t = r.dataSourceIds.indexOf(e);
506
+ t !== -1 && o.doc.transact(() => {
507
+ r.dataSourceIds.splice(t, 1), delete r.dataSources[e];
508
+ });
509
+ }
510
+ }),
511
+ [r, o.doc, m]
512
+ );
513
+ return {
514
+ ...o,
515
+ state: r,
516
+ actions: E,
517
+ localActions: P,
518
+ ...m
519
+ };
520
+ }, F = () => {
521
+ const { projectId: o } = ce();
522
+ return o ?? ue() ?? "";
523
+ }, Ye = () => window.__PROJECT_SLUG__ ?? "";
524
+ function he(o) {
525
+ const { resources: r } = o;
526
+ if (!r.components)
527
+ return {};
528
+ const l = {};
529
+ return window?.blocklet?.componentMountPoints?.forEach((p) => {
530
+ l[p.did] = p;
531
+ }), Object.fromEntries(
532
+ Object.entries(r.components).map(([p, { blockletId: w, component: y }]) => [
533
+ p,
534
+ { data: y, blockletId: w, blockletTitle: l[w]?.title || w }
535
+ ])
536
+ );
537
+ }
538
+ function ye(o) {
539
+ const { components: r } = o;
540
+ return r || {};
541
+ }
542
+ function ve(o) {
543
+ return {
544
+ ...he(o),
545
+ ...ye(o)
546
+ };
547
+ }
548
+ const Ze = () => ve(Ie().state);
549
+ function Ce(o) {
550
+ const r = JSON.parse(JSON.stringify(o)), l = O();
551
+ return {
552
+ ...r,
553
+ id: l
554
+ };
555
+ }
556
+ export {
557
+ Ke as E,
558
+ qe as S,
559
+ Ie as a,
560
+ We as b,
561
+ ve as c,
562
+ Ye as d,
563
+ Xe as e,
564
+ Qe as f,
565
+ ze as g,
566
+ Ze as h,
567
+ B as i,
568
+ ye as j,
569
+ he as k,
570
+ ue as l,
571
+ Ve as t,
572
+ F as u
573
+ };
@@ -7,7 +7,7 @@ import "lru-cache";
7
7
  import "node-fetch";
8
8
  import "ufo";
9
9
  import "crypto";
10
- import { c as _, G as E, d as i, e as d, j as l, k as N, m as O, h as P, g as c, f as g } from "./chunks/site-state-D-moj9fA.js";
10
+ import { c as _, G as E, d as i, e as d, j as l, k as N, m as O, h as P, g as c, f as g } from "./chunks/site-state-W2H7XCSQ.js";
11
11
  export {
12
12
  _ as CUSTOM_COMPONENT_CACHE_DURATION_IN_SECONDS,
13
13
  E as GET_SERVER_SIDE_PROPS_TIMEOUT_IN_SECONDS,
package/lib/es/home.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import "react/jsx-runtime";
2
- import "./chunks/state-l--dTdHq.js";
2
+ import "./chunks/state-0gvZF3k2.js";
3
3
  import "@arcblock/ux/lib/Locale/context";
4
4
  import "@arcblock/ux/lib/Result";
5
+ import "@arcblock/ux/lib/Theme";
5
6
  import "@blocklet/pages-kit/builtin/page/header";
6
7
  import "@blocklet/pages-kit/contexts/color";
7
8
  import "@blocklet/pages-kit/utils/data-source";
@@ -9,7 +10,6 @@ import "@blocklet/pages-kit/utils/route";
9
10
  import "@blocklet/ui-react/lib/Header";
10
11
  import "@emotion/css";
11
12
  import "@emotion/react";
12
- import "@emotion/styled";
13
13
  import "@mui/material";
14
14
  import "ahooks";
15
15
  import "isomorphic-dompurify";
@@ -21,9 +21,9 @@ import "react-helmet";
21
21
  import "react-router-dom";
22
22
  import "react-use";
23
23
  import "ufo";
24
- import "./chunks/array-c6HYTLze.js";
25
- import { a as R, P as S, d as W, c as j, b as k, T as q, H as v } from "./chunks/home-PDsc59QG.js";
26
- import "./chunks/session-CVblGhSp.js";
24
+ import "./chunks/index-D5gXPe_7.js";
25
+ import { a as R, P as S, d as W, c as j, b as k, T as q, H as v } from "./chunks/home-DW8SdyfO.js";
26
+ import "./chunks/session-C72Dq8zg.js";
27
27
  export {
28
28
  R as HomeView,
29
29
  S as PageRoutes,