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