@blocklet/pages-kit-inner-components 0.6.72 → 0.6.74
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 +12 -12
- package/lib/cjs/chunks/{draft-data-DfZ81oCU.js → draft-data-1hI-ev3X.js} +1 -1
- package/lib/cjs/chunks/{home-CP3WKJ_e.js → home-ymdnbwRQ.js} +2 -2
- package/lib/cjs/chunks/{index-BqynZDZ3.js → index-BAiZumV7.js} +1 -1
- package/lib/cjs/chunks/{publish-button-t3lAZwFy.js → publish-button-45a3egG-.js} +1 -1
- package/lib/cjs/chunks/{site-state-BRYYpS9Q.js → site-state-CcYU6tKv.js} +1 -1
- package/lib/cjs/chunks/state-BAjDjwwp.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/locales.js +2 -2
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +3 -3
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/add-component.js +274 -242
- package/lib/es/chunks/{draft-data-BtzZ0_tq.js → draft-data--WtLtXxy.js} +1 -1
- package/lib/es/chunks/{home-DBOWtpCK.js → home-BIH-BNIG.js} +3 -3
- package/lib/es/chunks/{index-CjNVgrdz.js → index-Cj977HLf.js} +1 -1
- package/lib/es/chunks/{publish-button-CFzWcpJ3.js → publish-button-Dn3ikSo5.js} +3 -3
- package/lib/es/chunks/{site-state-DYm1fKT3.js → site-state-BXM-5tZw.js} +5 -1
- package/lib/es/chunks/state-DS2djQbR.js +873 -0
- package/lib/es/home.js +3 -3
- package/lib/es/locales.js +20 -4
- package/lib/es/resources.js +1 -1
- package/lib/es/setting.js +829 -799
- package/lib/es/site-state.js +1 -1
- package/package.json +3 -3
- package/lib/cjs/chunks/state-BP5DoD6I.js +0 -1
- package/lib/es/chunks/state-Biqa_a5U.js +0 -685
|
@@ -1,685 +0,0 @@
|
|
|
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
|
-
/** @deprecated 已经废弃,llmConfig 从 component / resources.component 中获取 */
|
|
454
|
-
// llmConfig: section.llmConfig ?? {},
|
|
455
|
-
}, i = X(s.locales);
|
|
456
|
-
return delete s.locales, n.doc.transact(() => {
|
|
457
|
-
if (c && c.component === "layout-block") {
|
|
458
|
-
const d = m.currentPageModel?.getComponentById(c.id);
|
|
459
|
-
d && (d.model.sections ??= {}, d.model.sections[s.id] = s, d.model.sectionIds ??= [], d.model.sectionIds.push(s.id));
|
|
460
|
-
} else
|
|
461
|
-
a.sections[s.id] = s, a.sectionIds.splice(r ?? a.sectionIds.length, 0, s.id);
|
|
462
|
-
i && (a.dataSource ??= {}, a.dataSource[s.id] = i);
|
|
463
|
-
}), s;
|
|
464
|
-
},
|
|
465
|
-
deleteSection: (e, t) => {
|
|
466
|
-
const r = o.pages[e];
|
|
467
|
-
if (!r)
|
|
468
|
-
throw new Error(`Page ${e} is not exists`);
|
|
469
|
-
n.doc.transact(() => {
|
|
470
|
-
const c = [], a = m.currentPageModel?.getComponentById(t), s = a?.parent;
|
|
471
|
-
if (a && (c.push(a.model.id, ...a.all().map((i) => i.model.id)), s?.model.component === "layout-block")) {
|
|
472
|
-
const i = s.model.sectionIds?.indexOf(t);
|
|
473
|
-
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) => {
|
|
474
|
-
try {
|
|
475
|
-
delete s.model.config.gridSettings[d]?.[t];
|
|
476
|
-
} catch {
|
|
477
|
-
}
|
|
478
|
-
}), s.model.config?.backgroundSectionId === t && (s.model.config.backgroundSectionId = void 0);
|
|
479
|
-
}
|
|
480
|
-
c.forEach((i) => {
|
|
481
|
-
const d = r.sectionIds.indexOf(i);
|
|
482
|
-
d !== -1 && r.sectionIds.splice(d, 1), r.sections[i] && delete r.sections[i], r.dataSource?.[i] && delete r.dataSource?.[i];
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
},
|
|
486
|
-
lockSection: (e, t) => {
|
|
487
|
-
if (!o.pages[e])
|
|
488
|
-
throw new Error(`Page ${e} is not exists`);
|
|
489
|
-
const c = m.currentPageModel?.getComponentById(t)?.model;
|
|
490
|
-
c && (c.locked = !c.locked);
|
|
491
|
-
},
|
|
492
|
-
toggleSectionVisibility: (e, t, r) => {
|
|
493
|
-
if (!o.pages[e])
|
|
494
|
-
throw new Error(`Page ${e} is not exists`);
|
|
495
|
-
const a = m.currentPageModel?.getComponentById(t)?.model;
|
|
496
|
-
a && (a.visibility = r);
|
|
497
|
-
},
|
|
498
|
-
moveSection: (e, t, r, c) => {
|
|
499
|
-
const a = o.pages[e];
|
|
500
|
-
if (!a)
|
|
501
|
-
throw new Error(`Page ${e} is not exists`);
|
|
502
|
-
const s = m.currentPageModel;
|
|
503
|
-
if (!s)
|
|
504
|
-
throw new Error(`Page model for ${e} is not available`);
|
|
505
|
-
const i = (l) => {
|
|
506
|
-
const w = s.getComponentById(l);
|
|
507
|
-
if (!w) return null;
|
|
508
|
-
const g = w.model, v = w.parent;
|
|
509
|
-
if (!v)
|
|
510
|
-
return {
|
|
511
|
-
section: g,
|
|
512
|
-
container: a,
|
|
513
|
-
containerType: "root",
|
|
514
|
-
index: a.sectionIds.indexOf(l)
|
|
515
|
-
};
|
|
516
|
-
const y = v.model;
|
|
517
|
-
return {
|
|
518
|
-
section: g,
|
|
519
|
-
container: y,
|
|
520
|
-
containerType: "layout-block",
|
|
521
|
-
index: y.sectionIds.indexOf(l)
|
|
522
|
-
};
|
|
523
|
-
}, d = i(t);
|
|
524
|
-
if (!d)
|
|
525
|
-
throw new Error(`Section ${t} not found`);
|
|
526
|
-
n.doc.transact(() => {
|
|
527
|
-
if (r.startsWith("layout-")) {
|
|
528
|
-
const g = r.replace("layout-", ""), y = s.getComponentById(g)?.model;
|
|
529
|
-
if (!y || y.component !== "layout-block")
|
|
530
|
-
throw new Error(`Layout block ${g} not found`);
|
|
531
|
-
if (g === t || ((O, E) => {
|
|
532
|
-
const x = s.getComponentById(O), u = s.getComponentById(E);
|
|
533
|
-
if (!x || !u || x.model.component !== "layout-block")
|
|
534
|
-
return !1;
|
|
535
|
-
let f = u.parent;
|
|
536
|
-
for (; f; ) {
|
|
537
|
-
if (f.model.id === O)
|
|
538
|
-
return !0;
|
|
539
|
-
f = f.parent;
|
|
540
|
-
}
|
|
541
|
-
return !1;
|
|
542
|
-
})(t, g))
|
|
543
|
-
return;
|
|
544
|
-
const L = JSON.parse(JSON.stringify(d.section));
|
|
545
|
-
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];
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
const l = i(r);
|
|
549
|
-
if (!l)
|
|
550
|
-
throw new Error(`Target section ${r} not found`);
|
|
551
|
-
let w = l.index;
|
|
552
|
-
if (c === "bottom" && (w = l.index + 1), d.container === l.container) {
|
|
553
|
-
const { sectionIds: g } = d.container;
|
|
554
|
-
g.splice(d.index, 1), d.index < w && (w -= 1), g.splice(w, 0, t);
|
|
555
|
-
} else {
|
|
556
|
-
const g = JSON.parse(JSON.stringify(d.section));
|
|
557
|
-
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];
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
},
|
|
561
|
-
copySection: (e, t) => {
|
|
562
|
-
if (!o.pages[e])
|
|
563
|
-
throw new Error(`Page ${e} is not exists`);
|
|
564
|
-
const c = m.currentPageModel?.getComponentById(t);
|
|
565
|
-
if (!c?.model)
|
|
566
|
-
throw new Error(`Section ${t} is not exists`);
|
|
567
|
-
const a = JSON.parse(JSON.stringify(c.model)), s = Z(a), i = s.id, d = c?.parent;
|
|
568
|
-
if (d) {
|
|
569
|
-
if (d.model.sections[i] = s, d.model.sectionIds.push(i), m.currentPage?.dataSource?.[t] && (m.currentPage.dataSource[i] = JSON.parse(
|
|
570
|
-
JSON.stringify(m.currentPage.dataSource[t])
|
|
571
|
-
), s.component === "layout-block")) {
|
|
572
|
-
const l = (w, g) => {
|
|
573
|
-
const v = w.sectionIds, y = g.sectionIds;
|
|
574
|
-
v?.forEach((k, L) => {
|
|
575
|
-
const O = y?.[L];
|
|
576
|
-
if (O) {
|
|
577
|
-
if (O && m.currentPage?.dataSource) {
|
|
578
|
-
const u = m.currentPage.dataSource[O];
|
|
579
|
-
u && (m.currentPage.dataSource[k] = JSON.parse(JSON.stringify(u)));
|
|
580
|
-
}
|
|
581
|
-
const E = w.sections?.[k], x = g?.sections?.[O];
|
|
582
|
-
E?.component === "layout-block" && E.sectionIds && x?.sectionIds && l(E, x);
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
|
-
};
|
|
586
|
-
s.sectionIds && a.sectionIds && l(s, a);
|
|
587
|
-
}
|
|
588
|
-
P.setCurrentSectionId(e, i);
|
|
589
|
-
}
|
|
590
|
-
return s;
|
|
591
|
-
},
|
|
592
|
-
addDataSource: (e) => {
|
|
593
|
-
const t = e.id ?? A(), r = {
|
|
594
|
-
...e ?? {},
|
|
595
|
-
id: t,
|
|
596
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
597
|
-
};
|
|
598
|
-
return n.doc.transact(() => {
|
|
599
|
-
o.dataSourceIds ??= [], o.dataSources ??= {}, o.dataSourceIds.push(t), o.dataSources[t] = r;
|
|
600
|
-
}), o.dataSources[t];
|
|
601
|
-
},
|
|
602
|
-
deleteDataSource: (e) => {
|
|
603
|
-
const t = o.dataSourceIds.indexOf(e);
|
|
604
|
-
t !== -1 && n.doc.transact(() => {
|
|
605
|
-
o.dataSourceIds.splice(t, 1), delete o.dataSources[e];
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
}),
|
|
609
|
-
[o, n.doc, m]
|
|
610
|
-
);
|
|
611
|
-
return {
|
|
612
|
-
...n,
|
|
613
|
-
state: o,
|
|
614
|
-
actions: N,
|
|
615
|
-
localActions: P,
|
|
616
|
-
...m
|
|
617
|
-
};
|
|
618
|
-
}, Y = () => {
|
|
619
|
-
const { projectId: n } = we();
|
|
620
|
-
return n ?? Ce() ?? "";
|
|
621
|
-
}, st = () => window.__PROJECT_SLUG__ ?? "";
|
|
622
|
-
function je(n) {
|
|
623
|
-
const { resources: o } = n;
|
|
624
|
-
if (!o.components)
|
|
625
|
-
return {};
|
|
626
|
-
const S = {};
|
|
627
|
-
return window?.blocklet?.componentMountPoints?.forEach((p) => {
|
|
628
|
-
S[p.did] = p;
|
|
629
|
-
}), Object.fromEntries(
|
|
630
|
-
Object.entries(o.components).map(([p, { blockletId: h, component: I }]) => [
|
|
631
|
-
p,
|
|
632
|
-
{ data: I, blockletId: h, blockletTitle: S[h]?.title || h }
|
|
633
|
-
])
|
|
634
|
-
);
|
|
635
|
-
}
|
|
636
|
-
function Te(n) {
|
|
637
|
-
const { components: o } = n;
|
|
638
|
-
return o || {};
|
|
639
|
-
}
|
|
640
|
-
function Me(n) {
|
|
641
|
-
return {
|
|
642
|
-
...je(n),
|
|
643
|
-
...Te(n)
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
const it = () => Me(Le().state);
|
|
647
|
-
function Z(n) {
|
|
648
|
-
const o = JSON.parse(JSON.stringify(n)), S = A();
|
|
649
|
-
if (o.component === "layout-block") {
|
|
650
|
-
const p = { ...o.config ?? {} }, h = o.sectionIds?.map((I) => {
|
|
651
|
-
const m = o.sections?.[I], P = Z(o.sections?.[I]), N = P.id;
|
|
652
|
-
return m?.id === o.config?.backgroundSectionId && (p.backgroundSectionId = P.id), o.config?.gridSettings && Object.keys(o.config.gridSettings).forEach((e) => {
|
|
653
|
-
p.gridSettings[e] = {
|
|
654
|
-
...p.gridSettings[e] ?? {},
|
|
655
|
-
[N]: {
|
|
656
|
-
...o.config?.gridSettings?.[e]?.[I],
|
|
657
|
-
id: N
|
|
658
|
-
}
|
|
659
|
-
}, delete o.config?.gridSettings?.[e]?.[I];
|
|
660
|
-
}), P;
|
|
661
|
-
});
|
|
662
|
-
o.sections = Object.fromEntries(h?.map((I) => [I.id, I]) ?? []), o.sectionIds = h?.map((I) => I.id) ?? [], o.config = p;
|
|
663
|
-
}
|
|
664
|
-
return {
|
|
665
|
-
...o,
|
|
666
|
-
id: S
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
export {
|
|
670
|
-
ct as S,
|
|
671
|
-
Le as a,
|
|
672
|
-
et as b,
|
|
673
|
-
Me as c,
|
|
674
|
-
st as d,
|
|
675
|
-
rt as e,
|
|
676
|
-
nt as f,
|
|
677
|
-
ot as g,
|
|
678
|
-
it as h,
|
|
679
|
-
q as i,
|
|
680
|
-
Te as j,
|
|
681
|
-
je as k,
|
|
682
|
-
Ce as l,
|
|
683
|
-
tt as t,
|
|
684
|
-
Y as u
|
|
685
|
-
};
|