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