@blocklet/pages-kit-inner-components 0.5.30 → 0.5.32
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.
- package/lib/cjs/add-component.js +47 -23
- package/lib/cjs/chunks/array-DxhrK2d5.js +475 -0
- package/lib/cjs/chunks/{config-string-C4Q0hgG0.js → config-string-DqWgB7yO.js} +1 -1
- package/lib/cjs/chunks/{draft-data-Cu9gua-P.js → draft-data-DzN2u_NT.js} +1 -1
- package/lib/cjs/chunks/home-0fezWT4S.js +38 -0
- package/lib/cjs/chunks/{publish-button-DvwoFH1F.js → publish-button-D2jaaXXn.js} +1 -1
- package/lib/cjs/chunks/site-state-D5jk8eJT.js +57 -0
- package/lib/cjs/chunks/state-DoGBMTzI.js +1 -0
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/locales.js +3 -1
- package/lib/cjs/project-html.js +2 -2
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/add-component.js +795 -749
- package/lib/es/chunks/array-D6qyZucY.js +2224 -0
- package/lib/es/chunks/{config-string-CNLg1EYu.js → config-string-Btybe5Rd.js} +1 -1
- package/lib/es/chunks/{draft-data-hSHLdxKp.js → draft-data-DQ7_JyJX.js} +1 -1
- package/lib/es/chunks/{home-CNk6U8FU.js → home-Dox9JwvF.js} +112 -96
- package/lib/es/chunks/{publish-button-BftBlabj.js → publish-button-T2YJBoty.js} +3 -3
- package/lib/es/chunks/{site-state-DJ3JcBMm.js → site-state-DEduMTrY.js} +505 -473
- package/lib/es/chunks/state-NhsHvaKm.js +605 -0
- package/lib/es/components.js +1 -1
- package/lib/es/home.js +3 -3
- package/lib/es/locales.js +46 -6
- package/lib/es/project-html.js +43 -42
- package/lib/es/resources.js +1 -1
- package/lib/es/setting.js +2 -2
- package/lib/es/site-state.js +1 -1
- package/package.json +10 -10
- package/lib/cjs/chunks/array-CJC7ex3i.js +0 -467
- package/lib/cjs/chunks/home-CimGvyT9.js +0 -38
- package/lib/cjs/chunks/site-state-DvIWP0pO.js +0 -57
- package/lib/cjs/chunks/state-jCG5gSUJ.js +0 -1
- package/lib/es/chunks/array-9j8tOSbO.js +0 -1993
- package/lib/es/chunks/state-D5BnGunt.js +0 -483
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
import { jsx as k } from "react/jsx-runtime";
|
|
2
|
-
import { Box as z, Alert as K } from "@mui/material";
|
|
3
|
-
import { joinURL as b, withQuery as q } from "ufo";
|
|
4
|
-
import { createAxios as Q } from "@blocklet/js-sdk";
|
|
5
|
-
import X from "lodash/isEmpty";
|
|
6
|
-
import * as Y from "yaml";
|
|
7
|
-
import { useLocaleContext as Z } from "@arcblock/ux/lib/Locale/context";
|
|
8
|
-
import H, { getYjsDoc as ee } from "@syncedstore/core";
|
|
9
|
-
import { useSyncedStore as te } from "@syncedstore/react";
|
|
10
|
-
import { useLocalStorageState as ne } from "ahooks";
|
|
11
|
-
import { produce as v } from "immer";
|
|
12
|
-
import N from "lodash/debounce";
|
|
13
|
-
import { customAlphabet as oe } from "nanoid";
|
|
14
|
-
import { createContext as re, useState as E, useRef as se, useMemo as g, useCallback as L, useEffect as O, useContext as ce } from "react";
|
|
15
|
-
import { useParams as ie, useNavigate as ae } from "react-router-dom";
|
|
16
|
-
import { IndexeddbPersistence as de } from "y-indexeddb";
|
|
17
|
-
import { WebsocketProvider as le } from "y-websocket";
|
|
18
|
-
import { UndoManager as ue } from "yjs";
|
|
19
|
-
import "@blocklet/pages-kit/types";
|
|
20
|
-
const Je = (n) => {
|
|
21
|
-
const t = blocklet == null ? void 0 : blocklet.componentMountPoints.find((d) => d.name === n);
|
|
22
|
-
return t ? t.mountPoint : "/";
|
|
23
|
-
};
|
|
24
|
-
function me() {
|
|
25
|
-
const { pathname: n } = window.location, t = n.match(/\/admin\/(maker|previewer)\/([^/]+)/), d = t == null ? void 0 : t[2], f = window.__PROJECT_ID__;
|
|
26
|
-
if (!d && !f)
|
|
27
|
-
throw new Error("Unable to get projectId from pathname");
|
|
28
|
-
return d || f;
|
|
29
|
-
}
|
|
30
|
-
function Be(n) {
|
|
31
|
-
return `${n}:pages:version`;
|
|
32
|
-
}
|
|
33
|
-
function Ve(n, t) {
|
|
34
|
-
return t === "yaml" ? X(n) ? "" : Y.stringify(n, { indent: 2 }) : t === "json" ? JSON.parse(JSON.stringify(n || {})) : t === "array" ? JSON.parse(JSON.stringify(n || [])) : n;
|
|
35
|
-
}
|
|
36
|
-
function We({ error: n }) {
|
|
37
|
-
return /* @__PURE__ */ k(z, { children: /* @__PURE__ */ k(K, { severity: "error", children: n.message }) });
|
|
38
|
-
}
|
|
39
|
-
var U;
|
|
40
|
-
const _ = ((U = window.blocklet) == null ? void 0 : U.prefix) || "/", J = Q({
|
|
41
|
-
timeout: 200 * 1e3
|
|
42
|
-
}), fe = window.location.protocol === "https:" ? "wss" : "ws", ze = (n) => b(`${fe}://${window.location.hostname}`, _, `api/${n}/ws/pages`), Se = "z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";
|
|
43
|
-
var F;
|
|
44
|
-
(F = blocklet == null ? void 0 : blocklet.componentMountPoints.find((n) => n.did === Se)) != null && F.mountPoint || b(_, "/image-bin");
|
|
45
|
-
function Ke(n) {
|
|
46
|
-
return n && !/^(https?:\/\/|\/)/.test(n) ? window.location.origin + b(_, "uploads", n) : n;
|
|
47
|
-
}
|
|
48
|
-
const pe = window.innerWidth <= 750;
|
|
49
|
-
function qe(n, t, d) {
|
|
50
|
-
if (!n || /\.gif/.test(n)) return n;
|
|
51
|
-
const f = (pe ? t / 1.5 : t) * (d === "quality" ? 1.5 : 1);
|
|
52
|
-
return we(n, { imageFilter: "resize", w: f, f: "webp" });
|
|
53
|
-
}
|
|
54
|
-
function we(n, t) {
|
|
55
|
-
return !n || !t ? n : q(n, t);
|
|
56
|
-
}
|
|
57
|
-
async function Pe(n) {
|
|
58
|
-
return J.get(`/api/projects/${n}`).then((t) => t.data);
|
|
59
|
-
}
|
|
60
|
-
async function Ie(n) {
|
|
61
|
-
return J.post(`/api/projects/${n.id}/update`, n).then((t) => t.data);
|
|
62
|
-
}
|
|
63
|
-
const ye = 500, A = oe("abcdefghijklmnopqrstuvwxyz0123456789", 16), B = re(null);
|
|
64
|
-
function Qe({
|
|
65
|
-
url: n,
|
|
66
|
-
name: t,
|
|
67
|
-
children: d,
|
|
68
|
-
waitingSynced: f
|
|
69
|
-
}) {
|
|
70
|
-
const [I, w] = E(!1), { locale: y } = Z(), S = V(), e = `${S}:MakerLocalState`, o = `${S}:${t}`, [s, r] = ne(e, {
|
|
71
|
-
defaultValue: {},
|
|
72
|
-
listenStorageChange: !0
|
|
73
|
-
}), c = se(s);
|
|
74
|
-
c.current = s;
|
|
75
|
-
const i = g(
|
|
76
|
-
() => H({
|
|
77
|
-
dataSourceIds: [],
|
|
78
|
-
dataSources: {},
|
|
79
|
-
pages: {},
|
|
80
|
-
pageIds: [],
|
|
81
|
-
routes: {},
|
|
82
|
-
routeIds: [],
|
|
83
|
-
components: {},
|
|
84
|
-
supportedLocales: [],
|
|
85
|
-
config: {},
|
|
86
|
-
resources: {}
|
|
87
|
-
}),
|
|
88
|
-
[]
|
|
89
|
-
), a = g(() => ee(i), [i]);
|
|
90
|
-
g(() => new de(o, a), [o, a]);
|
|
91
|
-
const p = g(
|
|
92
|
-
() => new le(n, o, a, {
|
|
93
|
-
params: {},
|
|
94
|
-
resyncInterval: 5 * 60 * 1e3
|
|
95
|
-
}),
|
|
96
|
-
[n, o, a]
|
|
97
|
-
), C = L(() => {
|
|
98
|
-
p && (p.disconnect(), p.connect());
|
|
99
|
-
}, [p]), h = g(
|
|
100
|
-
() => new ue(
|
|
101
|
-
[
|
|
102
|
-
a.getArray("pageIds"),
|
|
103
|
-
a.getMap("pages"),
|
|
104
|
-
a.getArray("supportedLocales"),
|
|
105
|
-
a.getMap("config"),
|
|
106
|
-
a.getMap("dataSources"),
|
|
107
|
-
a.getArray("dataSourceIds"),
|
|
108
|
-
a.getArray("routeIds"),
|
|
109
|
-
a.getMap("routes")
|
|
110
|
-
],
|
|
111
|
-
{ doc: a }
|
|
112
|
-
),
|
|
113
|
-
[a]
|
|
114
|
-
), [j, x] = E(null), [R, D] = E(!1), [$, T] = E(void 0), G = L(async () => {
|
|
115
|
-
if (S) {
|
|
116
|
-
D(!0);
|
|
117
|
-
try {
|
|
118
|
-
const l = await Pe(S);
|
|
119
|
-
x(l);
|
|
120
|
-
} catch (l) {
|
|
121
|
-
console.error("Failed to fetch project:", l);
|
|
122
|
-
} finally {
|
|
123
|
-
D(!1);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}, [S]), M = L(
|
|
127
|
-
async (l, u) => {
|
|
128
|
-
var P;
|
|
129
|
-
if (T(void 0), !!S) {
|
|
130
|
-
u != null && u.optimisticUpdate && j && x((m) => ({
|
|
131
|
-
...m,
|
|
132
|
-
...l
|
|
133
|
-
}));
|
|
134
|
-
try {
|
|
135
|
-
const m = await Ie({
|
|
136
|
-
...l
|
|
137
|
-
});
|
|
138
|
-
x(m);
|
|
139
|
-
} catch (m) {
|
|
140
|
-
console.error("Failed to update project:", m), u != null && u.optimisticUpdate && x(j), T((P = m == null ? void 0 : m.response) == null ? void 0 : P.data);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
[S, j]
|
|
145
|
-
);
|
|
146
|
-
O(() => {
|
|
147
|
-
S && G();
|
|
148
|
-
}, [S, G]);
|
|
149
|
-
const W = g(
|
|
150
|
-
() => ({
|
|
151
|
-
doc: a,
|
|
152
|
-
state: i,
|
|
153
|
-
localState: {
|
|
154
|
-
...s,
|
|
155
|
-
// always use the locale from the context
|
|
156
|
-
currentLocale: y
|
|
157
|
-
},
|
|
158
|
-
setLocalState: (l) => r(typeof l == "function" ? (u) => l(u ?? {}) : l),
|
|
159
|
-
undoManager: h,
|
|
160
|
-
projectState: {
|
|
161
|
-
project: j,
|
|
162
|
-
isLoadingProject: R,
|
|
163
|
-
error: $
|
|
164
|
-
},
|
|
165
|
-
updateProject: M,
|
|
166
|
-
forceSync: C
|
|
167
|
-
}),
|
|
168
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
169
|
-
[
|
|
170
|
-
a,
|
|
171
|
-
i,
|
|
172
|
-
JSON.stringify(s),
|
|
173
|
-
// resolve the problem of react warning
|
|
174
|
-
r,
|
|
175
|
-
h,
|
|
176
|
-
j,
|
|
177
|
-
R,
|
|
178
|
-
M,
|
|
179
|
-
$,
|
|
180
|
-
y,
|
|
181
|
-
C
|
|
182
|
-
]
|
|
183
|
-
);
|
|
184
|
-
return O(() => {
|
|
185
|
-
h.on("stack-item-added", ({ stackItem: l }) => {
|
|
186
|
-
const { currentPageId: u, currentLocale: P, pages: m } = c.current;
|
|
187
|
-
l.meta.set("localState", { currentPageId: u, currentLocale: P, pages: m });
|
|
188
|
-
}), h.on("stack-item-popped", ({ stackItem: l }) => {
|
|
189
|
-
const u = l.meta.get("localState");
|
|
190
|
-
u && r((P) => ({ ...P, ...u }));
|
|
191
|
-
});
|
|
192
|
-
}, [h, r]), O(() => {
|
|
193
|
-
p.awareness.setLocalState(s);
|
|
194
|
-
}, [p, s]), O(() => {
|
|
195
|
-
p.once("synced", () => w(!0));
|
|
196
|
-
const l = () => {
|
|
197
|
-
r((m) => ({
|
|
198
|
-
...m,
|
|
199
|
-
networkStatus: void 0
|
|
200
|
-
}));
|
|
201
|
-
}, u = () => {
|
|
202
|
-
r((m) => ({
|
|
203
|
-
...m,
|
|
204
|
-
networkStatus: "offline"
|
|
205
|
-
}));
|
|
206
|
-
}, P = N(({ status: m }) => {
|
|
207
|
-
m === "connected" ? l() : m === "disconnected" && u();
|
|
208
|
-
}, ye);
|
|
209
|
-
return p.on("status", P), window.addEventListener("online", l), window.addEventListener("offline", u), () => {
|
|
210
|
-
p.off("status", P), window.removeEventListener("online", l), window.removeEventListener("offline", u);
|
|
211
|
-
};
|
|
212
|
-
}, [p, r]), f && !I ? null : /* @__PURE__ */ k(B.Provider, { value: W, children: d });
|
|
213
|
-
}
|
|
214
|
-
const he = () => {
|
|
215
|
-
const n = ce(B);
|
|
216
|
-
if (!n)
|
|
217
|
-
throw new Error("Context is null");
|
|
218
|
-
const t = te(n.state), { setLocalState: d, localState: f } = n, I = ae(), w = V(), y = g(
|
|
219
|
-
() => ({
|
|
220
|
-
setCurrentSectionId: (e, o) => {
|
|
221
|
-
var s, r;
|
|
222
|
-
e === f.currentPageId && o === ((r = (s = f.pages) == null ? void 0 : s[e]) == null ? void 0 : r.currentSectionId) || (I(b("/admin/maker", w ?? "", "pages", e)), d(
|
|
223
|
-
(c) => v(c, (i) => {
|
|
224
|
-
var a;
|
|
225
|
-
i.currentPageId = e, i.currentComponentId = void 0, i.customComponentPreviewerProperties = {}, o !== void 0 && (i.pages ?? (i.pages = {}), (a = i.pages)[e] ?? (a[e] = {}), i.pages[e].currentSectionId = o ?? void 0), o ? window.sessionStorage.setItem("iframe_show_id", `"${o}"`) : window.sessionStorage.removeItem("iframe_show_id");
|
|
226
|
-
})
|
|
227
|
-
));
|
|
228
|
-
},
|
|
229
|
-
setCurrentComponentId: (e) => {
|
|
230
|
-
e !== f.currentComponentId && (I(b("/admin/maker", w ?? "", "components", e)), d(
|
|
231
|
-
(o) => v(o, (s) => {
|
|
232
|
-
s.currentComponentId = e, s.customComponentPreviewerProperties = {};
|
|
233
|
-
})
|
|
234
|
-
));
|
|
235
|
-
},
|
|
236
|
-
setCurrentRouteId: ({ routeId: e, dynamicParams: o }) => {
|
|
237
|
-
d(
|
|
238
|
-
(s) => v(s, (r) => {
|
|
239
|
-
r.currentRouteId = e, r.currentDynamicParams = o;
|
|
240
|
-
})
|
|
241
|
-
);
|
|
242
|
-
},
|
|
243
|
-
setCustomComponentPreviewerProperties: (() => {
|
|
244
|
-
const e = {}, o = N(() => {
|
|
245
|
-
d(
|
|
246
|
-
(s) => v(s, (r) => {
|
|
247
|
-
r.customComponentPreviewerProperties = {
|
|
248
|
-
...r == null ? void 0 : r.customComponentPreviewerProperties,
|
|
249
|
-
...e
|
|
250
|
-
}, Object.keys(e).forEach((c) => delete e[c]);
|
|
251
|
-
})
|
|
252
|
-
);
|
|
253
|
-
}, 5);
|
|
254
|
-
return (s) => {
|
|
255
|
-
Object.assign(e, s), o();
|
|
256
|
-
};
|
|
257
|
-
})(),
|
|
258
|
-
setRouteGenerateProcess: (e) => {
|
|
259
|
-
d(
|
|
260
|
-
(o) => v(o, (s) => {
|
|
261
|
-
e ? s.routeGenerateProcess = {
|
|
262
|
-
...s.routeGenerateProcess,
|
|
263
|
-
...e
|
|
264
|
-
} : s.routeGenerateProcess = {};
|
|
265
|
-
})
|
|
266
|
-
);
|
|
267
|
-
},
|
|
268
|
-
resetRouteGenerateProcess: () => {
|
|
269
|
-
d(
|
|
270
|
-
(e) => v(e, (o) => {
|
|
271
|
-
o.routeGenerateProcess = {
|
|
272
|
-
progress: "complete"
|
|
273
|
-
};
|
|
274
|
-
})
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
}),
|
|
278
|
-
[d, I, w]
|
|
279
|
-
), S = g(
|
|
280
|
-
() => ({
|
|
281
|
-
addPage: (e, o) => {
|
|
282
|
-
var c, i, a, p, C, h;
|
|
283
|
-
const s = (e == null ? void 0 : e.id) ?? A(), r = {
|
|
284
|
-
...e,
|
|
285
|
-
id: s,
|
|
286
|
-
createdAt: (e == null ? void 0 : e.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
287
|
-
updatedAt: (e == null ? void 0 : e.updatedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
288
|
-
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
289
|
-
slug: (e == null ? void 0 : e.slug) ?? `/${s}`,
|
|
290
|
-
sections: (e == null ? void 0 : e.sections) ?? {},
|
|
291
|
-
sectionIds: (e == null ? void 0 : e.sectionIds) ?? [],
|
|
292
|
-
isPublic: (e == null ? void 0 : e.isPublic) ?? !0,
|
|
293
|
-
templateConfig: (e == null ? void 0 : e.templateConfig) ?? {
|
|
294
|
-
isTemplate: ((c = e == null ? void 0 : e.templateConfig) == null ? void 0 : c.isTemplate) ?? !0,
|
|
295
|
-
displayTemplateId: ((i = e == null ? void 0 : e.templateConfig) == null ? void 0 : i.displayTemplateId) ?? void 0,
|
|
296
|
-
dataSourceIds: ((a = e == null ? void 0 : e.templateConfig) == null ? void 0 : a.dataSourceIds) ?? void 0,
|
|
297
|
-
dataSourceParameters: ((p = e == null ? void 0 : e.templateConfig) == null ? void 0 : p.dataSourceParameters) ?? {},
|
|
298
|
-
enabledGenerate: ((C = e == null ? void 0 : e.templateConfig) == null ? void 0 : C.enabledGenerate) ?? !1,
|
|
299
|
-
agentId: ((h = e == null ? void 0 : e.templateConfig) == null ? void 0 : h.agentId) ?? void 0
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
return n.doc.transact(() => {
|
|
303
|
-
t.pages[r.id] = r, t.pageIds.splice(o ?? t.pageIds.length, 0, r.id);
|
|
304
|
-
}), r;
|
|
305
|
-
},
|
|
306
|
-
addRoute: (e, o) => {
|
|
307
|
-
const s = (e == null ? void 0 : e.id) ?? A(), r = {
|
|
308
|
-
...e,
|
|
309
|
-
id: s,
|
|
310
|
-
createdAt: (e == null ? void 0 : e.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
311
|
-
updatedAt: (e == null ? void 0 : e.updatedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
312
|
-
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
313
|
-
path: (e == null ? void 0 : e.path) ?? `/${s}`,
|
|
314
|
-
handler: (e == null ? void 0 : e.handler) ?? "Pages Kit",
|
|
315
|
-
isPublic: (e == null ? void 0 : e.isPublic) ?? !0,
|
|
316
|
-
params: (e == null ? void 0 : e.params) ?? [],
|
|
317
|
-
enabledGenerate: (e == null ? void 0 : e.enabledGenerate) ?? !1,
|
|
318
|
-
displayTemplateId: (e == null ? void 0 : e.displayTemplateId) ?? void 0,
|
|
319
|
-
dataSource: (e == null ? void 0 : e.dataSource) ?? {}
|
|
320
|
-
};
|
|
321
|
-
return n.doc.transact(() => {
|
|
322
|
-
t.routes ?? (t.routes = {}), t.routeIds ?? (t.routeIds = []), t.routes[r.id] = r, t.routeIds.splice(o ?? t.routeIds.length, 0, r.id);
|
|
323
|
-
}), r;
|
|
324
|
-
},
|
|
325
|
-
deleteRoute: (e) => {
|
|
326
|
-
var s;
|
|
327
|
-
if (!e)
|
|
328
|
-
return;
|
|
329
|
-
const o = (s = t.routeIds) == null ? void 0 : s.indexOf(e);
|
|
330
|
-
o !== void 0 && o !== -1 && n.doc.transact(() => {
|
|
331
|
-
var r, c;
|
|
332
|
-
(r = t.routeIds) == null || r.splice(o, 1), (c = t.routes) == null || delete c[e];
|
|
333
|
-
});
|
|
334
|
-
},
|
|
335
|
-
deletePage: (e) => {
|
|
336
|
-
const o = t.pageIds.indexOf(e);
|
|
337
|
-
o !== -1 && n.doc.transact(() => {
|
|
338
|
-
t.pageIds.splice(o, 1), delete t.pages[e];
|
|
339
|
-
});
|
|
340
|
-
},
|
|
341
|
-
movePage: (e, o) => {
|
|
342
|
-
const { pageIds: s } = t, r = s.indexOf(e);
|
|
343
|
-
r >= 0 && s.splice(o, 0, ...s.splice(r, 1));
|
|
344
|
-
},
|
|
345
|
-
addSection: (e, o, s) => {
|
|
346
|
-
const r = t.pages[e];
|
|
347
|
-
if (!r)
|
|
348
|
-
throw new Error(`Page ${e} is not exists`);
|
|
349
|
-
const c = {
|
|
350
|
-
...o,
|
|
351
|
-
id: o.id ?? A(),
|
|
352
|
-
isTemplateSection: o.isTemplateSection ?? !0,
|
|
353
|
-
llmConfig: o.llmConfig ?? {}
|
|
354
|
-
};
|
|
355
|
-
return n.doc.transact(() => {
|
|
356
|
-
r.sections[c.id] = c, r.sectionIds.splice(s ?? r.sectionIds.length, 0, c.id);
|
|
357
|
-
}), c;
|
|
358
|
-
},
|
|
359
|
-
deleteSection: (e, o) => {
|
|
360
|
-
const s = t.pages[e];
|
|
361
|
-
if (!s)
|
|
362
|
-
throw new Error(`Page ${e} is not exists`);
|
|
363
|
-
const r = s.sectionIds.indexOf(o);
|
|
364
|
-
r !== -1 && n.doc.transact(() => {
|
|
365
|
-
s.sectionIds.splice(r, 1), delete s.sections[o];
|
|
366
|
-
});
|
|
367
|
-
},
|
|
368
|
-
toggleSectionVisibility: (e, o, s) => {
|
|
369
|
-
const r = t.pages[e];
|
|
370
|
-
if (!r)
|
|
371
|
-
throw new Error(`Page ${e} is not exists`);
|
|
372
|
-
const c = r.sections[o];
|
|
373
|
-
c && (c.visibility = s);
|
|
374
|
-
},
|
|
375
|
-
moveSection: (e, o, s) => {
|
|
376
|
-
const r = t.pages[e];
|
|
377
|
-
if (!r)
|
|
378
|
-
throw new Error(`Page ${e} is not exists`);
|
|
379
|
-
const { sectionIds: c } = r, i = c.indexOf(o);
|
|
380
|
-
i >= 0 && c.splice(s, 0, ...c.splice(i, 1));
|
|
381
|
-
},
|
|
382
|
-
addDataSource: (e) => {
|
|
383
|
-
const o = e.id ?? A(), s = {
|
|
384
|
-
...e ?? {},
|
|
385
|
-
id: o,
|
|
386
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
387
|
-
};
|
|
388
|
-
return n.doc.transact(() => {
|
|
389
|
-
t.dataSourceIds ?? (t.dataSourceIds = []), t.dataSources ?? (t.dataSources = {}), t.dataSourceIds.push(o), t.dataSources[o] = s;
|
|
390
|
-
}), t.dataSources[o];
|
|
391
|
-
},
|
|
392
|
-
deleteDataSource: (e) => {
|
|
393
|
-
const o = t.dataSourceIds.indexOf(e);
|
|
394
|
-
o !== -1 && n.doc.transact(() => {
|
|
395
|
-
t.dataSourceIds.splice(o, 1), delete t.dataSources[e];
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
}),
|
|
399
|
-
[t, n.doc]
|
|
400
|
-
);
|
|
401
|
-
return {
|
|
402
|
-
...n,
|
|
403
|
-
state: t,
|
|
404
|
-
actions: S,
|
|
405
|
-
localActions: y,
|
|
406
|
-
get currentPage() {
|
|
407
|
-
const {
|
|
408
|
-
localState: { currentPageId: e }
|
|
409
|
-
} = n;
|
|
410
|
-
return e ? t.pages[e] : void 0;
|
|
411
|
-
},
|
|
412
|
-
get currentSection() {
|
|
413
|
-
var r, c, i;
|
|
414
|
-
const {
|
|
415
|
-
localState: { currentPageId: e, ...o }
|
|
416
|
-
} = n;
|
|
417
|
-
if (!e)
|
|
418
|
-
return;
|
|
419
|
-
const s = (c = (r = o.pages) == null ? void 0 : r[e]) == null ? void 0 : c.currentSectionId;
|
|
420
|
-
if (s)
|
|
421
|
-
return (i = t.pages[e]) == null ? void 0 : i.sections[s];
|
|
422
|
-
},
|
|
423
|
-
get currentRoute() {
|
|
424
|
-
var o;
|
|
425
|
-
const {
|
|
426
|
-
localState: { currentRouteId: e }
|
|
427
|
-
} = n;
|
|
428
|
-
return e ? (o = t.routes) == null ? void 0 : o[e] : void 0;
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
}, V = () => {
|
|
432
|
-
const { projectId: n } = ie();
|
|
433
|
-
return n ?? me() ?? "";
|
|
434
|
-
}, Xe = () => window.__PROJECT_SLUG__ ?? "";
|
|
435
|
-
function ge(n) {
|
|
436
|
-
var f, I;
|
|
437
|
-
const { resources: t } = n;
|
|
438
|
-
if (!t.components)
|
|
439
|
-
return {};
|
|
440
|
-
const d = {};
|
|
441
|
-
return (I = (f = window == null ? void 0 : window.blocklet) == null ? void 0 : f.componentMountPoints) == null || I.forEach((w) => {
|
|
442
|
-
d[w.did] = w;
|
|
443
|
-
}), Object.fromEntries(
|
|
444
|
-
Object.entries(t.components).map(([w, { blockletId: y, component: S }]) => {
|
|
445
|
-
var e;
|
|
446
|
-
return [
|
|
447
|
-
w,
|
|
448
|
-
{ data: S, blockletId: y, blockletTitle: ((e = d[y]) == null ? void 0 : e.title) || y }
|
|
449
|
-
];
|
|
450
|
-
})
|
|
451
|
-
);
|
|
452
|
-
}
|
|
453
|
-
function ve(n) {
|
|
454
|
-
const { components: t } = n;
|
|
455
|
-
return t || {};
|
|
456
|
-
}
|
|
457
|
-
function Ce(n) {
|
|
458
|
-
return {
|
|
459
|
-
...ge(n),
|
|
460
|
-
...ve(n)
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
const Ye = () => Ce(he().state);
|
|
464
|
-
export {
|
|
465
|
-
We as E,
|
|
466
|
-
Qe as S,
|
|
467
|
-
ze as a,
|
|
468
|
-
he as b,
|
|
469
|
-
Be as c,
|
|
470
|
-
Ce as d,
|
|
471
|
-
Xe as e,
|
|
472
|
-
qe as f,
|
|
473
|
-
Ke as g,
|
|
474
|
-
Ye as h,
|
|
475
|
-
J as i,
|
|
476
|
-
Je as j,
|
|
477
|
-
ve as k,
|
|
478
|
-
ge as l,
|
|
479
|
-
me as m,
|
|
480
|
-
A as n,
|
|
481
|
-
Ve as t,
|
|
482
|
-
V as u
|
|
483
|
-
};
|