@blocklet/pages-kit-inner-components 0.6.76 → 0.6.78
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 +1 -1
- package/lib/cjs/chunks/{draft-data-1hI-ev3X.js → draft-data-CkVvOh60.js} +1 -1
- package/lib/cjs/chunks/{home-BEBAcHLJ.js → home-CjhOAEa7.js} +2 -2
- package/lib/cjs/chunks/html-xfTPTsl5.js +1 -0
- package/lib/cjs/chunks/{index-DC4XWhpO.js → index-CiYwdeK9.js} +1 -1
- package/lib/cjs/chunks/{publish-button-Brxy74Ql.js → publish-button-DV23sfgB.js} +1 -1
- package/lib/cjs/chunks/site-state-CtiXHtSX.js +1 -0
- package/lib/cjs/chunks/state-BdtFHk36.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/locales.js +2 -2
- package/lib/cjs/project-html.js +1 -1
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +2 -2
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/add-component.js +2 -2
- package/lib/es/chunks/{draft-data--WtLtXxy.js → draft-data-BOoVhbon.js} +1 -1
- package/lib/es/chunks/{home-iBLOByRu.js → home-BZB9zOlO.js} +3 -3
- package/lib/es/chunks/{html-DfzaaIYa.js → html-DOgzvdOd.js} +11 -10
- package/lib/es/chunks/{index-BlZcgfTW.js → index-Bggolyu_.js} +2 -2
- package/lib/es/chunks/{publish-button-CHmiGlT7.js → publish-button-Dm2Nce-b.js} +3 -3
- package/lib/es/chunks/{site-state-BXM-5tZw.js → site-state-D4wvb7PN.js} +300 -300
- package/lib/es/chunks/{state-DS2djQbR.js → state-DNdwHwty.js} +173 -165
- package/lib/es/home.js +3 -3
- package/lib/es/locales.js +2 -0
- package/lib/es/project-html.js +1 -1
- package/lib/es/resources.js +1 -1
- package/lib/es/setting.js +680 -670
- package/lib/es/site-state.js +1 -1
- package/package.json +3 -3
- package/lib/cjs/chunks/html-JOhPskS4.js +0 -1
- package/lib/cjs/chunks/site-state-CcYU6tKv.js +0 -1
- package/lib/cjs/chunks/state-BAjDjwwp.js +0 -1
|
@@ -10,8 +10,8 @@ import "@mui/material";
|
|
|
10
10
|
import Se, { getYjsDoc as Ie } from "@syncedstore/core";
|
|
11
11
|
import { useSyncedStore as Pe } from "@syncedstore/react";
|
|
12
12
|
import { useLocalStorageState as ye } from "ahooks";
|
|
13
|
-
import { produce as
|
|
14
|
-
import
|
|
13
|
+
import { produce as _ } from "immer";
|
|
14
|
+
import R from "lodash/cloneDeep";
|
|
15
15
|
import ee from "lodash/debounce";
|
|
16
16
|
import { createContext as we, useState as W, useRef as te, useMemo as j, useCallback as M, useEffect as V, useContext as Ce } from "react";
|
|
17
17
|
import { useParams as he, useNavigate as ve } from "react-router-dom";
|
|
@@ -20,10 +20,10 @@ import { WebsocketProvider as be } from "y-websocket";
|
|
|
20
20
|
import { UndoManager as xe } from "yjs";
|
|
21
21
|
import "@blocklet/pages-kit/types";
|
|
22
22
|
function Ee() {
|
|
23
|
-
const { pathname: o } = window.location,
|
|
24
|
-
if (!
|
|
23
|
+
const { pathname: o } = window.location, I = o.match(/\/admin\/(maker|previewer)\/([^/]+)/)?.[2], f = window.__PROJECT_ID__;
|
|
24
|
+
if (!I && !f)
|
|
25
25
|
throw new Error("Unable to get projectId from pathname");
|
|
26
|
-
return
|
|
26
|
+
return I || f;
|
|
27
27
|
}
|
|
28
28
|
function st(o) {
|
|
29
29
|
return `${o}:pages:version`;
|
|
@@ -39,9 +39,9 @@ function dt(o) {
|
|
|
39
39
|
return o && !/^(https?:\/\/|\/)/.test(o) ? window.location.origin + F(Q, "uploads", o) : o;
|
|
40
40
|
}
|
|
41
41
|
const Ne = window.innerWidth <= 750;
|
|
42
|
-
function ut(o, n,
|
|
42
|
+
function ut(o, n, I) {
|
|
43
43
|
if (!o || /\.gif/.test(o)) return o;
|
|
44
|
-
const f = (Ne ? n / 1.5 : n) * (
|
|
44
|
+
const f = (Ne ? n / 1.5 : n) * (I === "quality" ? 1.5 : 1);
|
|
45
45
|
return Le(o, { imageFilter: "resize", w: f, f: "webp" });
|
|
46
46
|
}
|
|
47
47
|
function Le(o, n) {
|
|
@@ -55,17 +55,17 @@ async function Me(o) {
|
|
|
55
55
|
}
|
|
56
56
|
const q = "@COMPONENT-TEMPLATE-", X = (o) => `${q}${o}`, K = (o) => o.startsWith(q), Z = (o) => K(o) ? o.slice(q.length) : null;
|
|
57
57
|
function ne(o, n = {}) {
|
|
58
|
-
return n[o.id] = o, o.sectionIds && o.sections && o.sectionIds.forEach((
|
|
59
|
-
const f = o.sections?.[
|
|
58
|
+
return n[o.id] = o, o.sectionIds && o.sections && o.sectionIds.forEach((I) => {
|
|
59
|
+
const f = o.sections?.[I];
|
|
60
60
|
f && ne(f, n);
|
|
61
61
|
}), n;
|
|
62
62
|
}
|
|
63
63
|
function Ae(o, n) {
|
|
64
|
-
const
|
|
64
|
+
const I = X(o.id), f = n.section, O = ne(f);
|
|
65
65
|
n.dataSource ??= {};
|
|
66
66
|
const w = n.dataSource;
|
|
67
67
|
return {
|
|
68
|
-
id:
|
|
68
|
+
id: I,
|
|
69
69
|
createdAt: o.createdAt,
|
|
70
70
|
updatedAt: o.updatedAt,
|
|
71
71
|
publishedAt: o.updatedAt,
|
|
@@ -78,19 +78,19 @@ function Ae(o, n) {
|
|
|
78
78
|
dataSource: w
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
const De = 500,
|
|
81
|
+
const De = 500, re = we(null);
|
|
82
82
|
function lt({
|
|
83
83
|
url: o,
|
|
84
84
|
name: n,
|
|
85
|
-
children:
|
|
85
|
+
children: I,
|
|
86
86
|
waitingSynced: f
|
|
87
87
|
}) {
|
|
88
|
-
const [O, w] = W(!1), { locale: A } = fe(), h =
|
|
88
|
+
const [O, w] = W(!1), { locale: A } = fe(), h = ce(), k = `${h}:MakerLocalState`, b = `${h}:${n}`, [v, S] = ye(k, {
|
|
89
89
|
defaultValue: {},
|
|
90
90
|
listenStorageChange: !0
|
|
91
|
-
}),
|
|
92
|
-
|
|
93
|
-
const
|
|
91
|
+
}), J = te(v);
|
|
92
|
+
J.current = v;
|
|
93
|
+
const $ = j(
|
|
94
94
|
() => Se({
|
|
95
95
|
dataSourceIds: [],
|
|
96
96
|
dataSources: {},
|
|
@@ -104,7 +104,7 @@ function lt({
|
|
|
104
104
|
resources: {}
|
|
105
105
|
}),
|
|
106
106
|
[]
|
|
107
|
-
), y = j(() => Ie(
|
|
107
|
+
), y = j(() => Ie($), [$]);
|
|
108
108
|
j(() => new Oe(b, y), [b, y]);
|
|
109
109
|
const C = j(
|
|
110
110
|
() => new be(o, b, y, {
|
|
@@ -129,12 +129,12 @@ function lt({
|
|
|
129
129
|
{ doc: y }
|
|
130
130
|
),
|
|
131
131
|
[y]
|
|
132
|
-
), [t,
|
|
132
|
+
), [t, r] = W(null), [c, d] = W(!1), [i, l] = W(void 0), m = M(async () => {
|
|
133
133
|
if (h) {
|
|
134
134
|
d(!0);
|
|
135
135
|
try {
|
|
136
136
|
const s = await je(h);
|
|
137
|
-
|
|
137
|
+
r(s);
|
|
138
138
|
} catch (s) {
|
|
139
139
|
console.error("Failed to fetch project:", s);
|
|
140
140
|
} finally {
|
|
@@ -144,7 +144,7 @@ function lt({
|
|
|
144
144
|
}, [h]), u = M(
|
|
145
145
|
async (s, a) => {
|
|
146
146
|
if (l(void 0), !!h) {
|
|
147
|
-
a?.optimisticUpdate && t &&
|
|
147
|
+
a?.optimisticUpdate && t && r((g) => ({
|
|
148
148
|
...g,
|
|
149
149
|
...s
|
|
150
150
|
}));
|
|
@@ -152,9 +152,9 @@ function lt({
|
|
|
152
152
|
const g = await Me({
|
|
153
153
|
...s
|
|
154
154
|
});
|
|
155
|
-
|
|
155
|
+
r(g);
|
|
156
156
|
} catch (g) {
|
|
157
|
-
console.error("Failed to update project:", g), a?.optimisticUpdate &&
|
|
157
|
+
console.error("Failed to update project:", g), a?.optimisticUpdate && r(t), l(g?.response?.data);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
},
|
|
@@ -166,7 +166,7 @@ function lt({
|
|
|
166
166
|
const p = j(
|
|
167
167
|
() => ({
|
|
168
168
|
doc: y,
|
|
169
|
-
state:
|
|
169
|
+
state: $,
|
|
170
170
|
localState: {
|
|
171
171
|
...v,
|
|
172
172
|
// always use the locale from the context
|
|
@@ -176,7 +176,7 @@ function lt({
|
|
|
176
176
|
undoManager: e,
|
|
177
177
|
projectState: {
|
|
178
178
|
project: t,
|
|
179
|
-
isLoadingProject:
|
|
179
|
+
isLoadingProject: c,
|
|
180
180
|
error: i
|
|
181
181
|
},
|
|
182
182
|
updateProject: u,
|
|
@@ -185,13 +185,13 @@ function lt({
|
|
|
185
185
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
186
186
|
[
|
|
187
187
|
y,
|
|
188
|
-
|
|
188
|
+
$,
|
|
189
189
|
JSON.stringify(v),
|
|
190
190
|
// resolve the problem of react warning
|
|
191
191
|
S,
|
|
192
192
|
e,
|
|
193
193
|
t,
|
|
194
|
-
|
|
194
|
+
c,
|
|
195
195
|
u,
|
|
196
196
|
i,
|
|
197
197
|
A,
|
|
@@ -200,8 +200,8 @@ function lt({
|
|
|
200
200
|
);
|
|
201
201
|
return V(() => {
|
|
202
202
|
e.on("stack-item-added", ({ stackItem: s }) => {
|
|
203
|
-
const { currentPageId: a, currentLocale: g, pages:
|
|
204
|
-
s.meta.set("localState", { currentPageId: a, currentLocale: g, pages:
|
|
203
|
+
const { currentPageId: a, currentLocale: g, pages: P } = J.current;
|
|
204
|
+
s.meta.set("localState", { currentPageId: a, currentLocale: g, pages: P });
|
|
205
205
|
}), e.on("stack-item-popped", ({ stackItem: s }) => {
|
|
206
206
|
const a = s.meta.get("localState");
|
|
207
207
|
a && S((g) => ({ ...g, ...a }));
|
|
@@ -213,7 +213,7 @@ function lt({
|
|
|
213
213
|
w(!0);
|
|
214
214
|
});
|
|
215
215
|
let s = 0, a = null;
|
|
216
|
-
const g = 3,
|
|
216
|
+
const g = 3, P = 5e3, N = 15e3, x = () => {
|
|
217
217
|
s = 0, S((T) => ({
|
|
218
218
|
...T,
|
|
219
219
|
networkStatus: void 0
|
|
@@ -230,7 +230,7 @@ function lt({
|
|
|
230
230
|
if (s++, !a) {
|
|
231
231
|
const se = Date.now();
|
|
232
232
|
let H = 0;
|
|
233
|
-
const ie = Math.ceil(N /
|
|
233
|
+
const ie = Math.ceil(N / P), Y = () => {
|
|
234
234
|
H++;
|
|
235
235
|
const ae = Date.now() - se;
|
|
236
236
|
if (C.wsconnected) {
|
|
@@ -241,9 +241,9 @@ function lt({
|
|
|
241
241
|
E();
|
|
242
242
|
return;
|
|
243
243
|
}
|
|
244
|
-
a = setTimeout(Y,
|
|
244
|
+
a = setTimeout(Y, P);
|
|
245
245
|
};
|
|
246
|
-
a = setTimeout(Y,
|
|
246
|
+
a = setTimeout(Y, P);
|
|
247
247
|
}
|
|
248
248
|
s >= g && E();
|
|
249
249
|
}
|
|
@@ -255,13 +255,13 @@ function lt({
|
|
|
255
255
|
return C.on("status", L), window.addEventListener("online", D), window.addEventListener("offline", G), C.wsconnected && x(), () => {
|
|
256
256
|
a && clearTimeout(a), C.off("status", L), window.removeEventListener("online", D), window.removeEventListener("offline", G);
|
|
257
257
|
};
|
|
258
|
-
}, [C, S]), f && !O ? null : /* @__PURE__ */ de(
|
|
258
|
+
}, [C, S]), f && !O ? null : /* @__PURE__ */ de(re.Provider, { value: p, children: I });
|
|
259
259
|
}
|
|
260
260
|
const _e = () => {
|
|
261
|
-
const o = Ce(
|
|
261
|
+
const o = Ce(re);
|
|
262
262
|
if (!o)
|
|
263
263
|
throw new Error("Context is null");
|
|
264
|
-
const n = Pe(o.state), { setLocalState:
|
|
264
|
+
const n = Pe(o.state), { setLocalState: I, localState: f } = o, O = ve(), w = ce(), A = te({}), h = M(
|
|
265
265
|
(e) => {
|
|
266
266
|
const t = n.components[e]?.data;
|
|
267
267
|
return !t || t.renderer?.type !== "component-template" ? void 0 : (A.current[e] || (A.current[e] = {
|
|
@@ -274,13 +274,13 @@ const _e = () => {
|
|
|
274
274
|
const t = n.components[e]?.data;
|
|
275
275
|
if (!t || t.renderer?.type !== "component-template")
|
|
276
276
|
return;
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
277
|
+
const r = h(e);
|
|
278
|
+
if (r)
|
|
279
279
|
return {
|
|
280
280
|
componentId: e,
|
|
281
281
|
component: t,
|
|
282
282
|
renderer: t.renderer,
|
|
283
|
-
page:
|
|
283
|
+
page: r
|
|
284
284
|
};
|
|
285
285
|
},
|
|
286
286
|
[h, n.components]
|
|
@@ -291,18 +291,18 @@ const _e = () => {
|
|
|
291
291
|
return { kind: "page", pageId: e, page: t };
|
|
292
292
|
if (!K(e))
|
|
293
293
|
return;
|
|
294
|
-
const
|
|
295
|
-
if (!
|
|
294
|
+
const r = Z(e);
|
|
295
|
+
if (!r)
|
|
296
296
|
return;
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
297
|
+
const c = k(r);
|
|
298
|
+
if (c)
|
|
299
299
|
return {
|
|
300
300
|
kind: "component-template",
|
|
301
301
|
pageId: e,
|
|
302
|
-
page:
|
|
303
|
-
componentId:
|
|
304
|
-
component:
|
|
305
|
-
renderer:
|
|
302
|
+
page: c.page,
|
|
303
|
+
componentId: c.componentId,
|
|
304
|
+
component: c.component,
|
|
305
|
+
renderer: c.renderer
|
|
306
306
|
};
|
|
307
307
|
},
|
|
308
308
|
[k, n.pages]
|
|
@@ -321,36 +321,36 @@ const _e = () => {
|
|
|
321
321
|
localState: { currentPageId: e, currentComponentId: t }
|
|
322
322
|
} = o;
|
|
323
323
|
if (e) {
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
326
|
-
return
|
|
324
|
+
const r = b(e);
|
|
325
|
+
if (r)
|
|
326
|
+
return r.page;
|
|
327
327
|
}
|
|
328
328
|
if (t) {
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
return
|
|
329
|
+
const r = k(t);
|
|
330
|
+
if (r)
|
|
331
|
+
return r.page;
|
|
332
332
|
}
|
|
333
333
|
},
|
|
334
334
|
get currentSection() {
|
|
335
335
|
const {
|
|
336
336
|
localState: { currentPageId: e, ...t }
|
|
337
|
-
} = o, { currentPage:
|
|
338
|
-
if (!
|
|
337
|
+
} = o, { currentPage: r } = this;
|
|
338
|
+
if (!r || !e)
|
|
339
339
|
return;
|
|
340
|
-
const
|
|
341
|
-
if (
|
|
342
|
-
return
|
|
340
|
+
const c = t.pages?.[e]?.currentSectionId;
|
|
341
|
+
if (c)
|
|
342
|
+
return r.sections?.[c] ?? this.currentPageModel?.getComponentById(c)?.model;
|
|
343
343
|
},
|
|
344
344
|
get currentSectionProperties() {
|
|
345
345
|
const {
|
|
346
346
|
localState: { currentPageId: e, ...t }
|
|
347
|
-
} = o, { currentPage:
|
|
348
|
-
if (!
|
|
347
|
+
} = o, { currentPage: r } = this;
|
|
348
|
+
if (!r || !e)
|
|
349
349
|
return;
|
|
350
|
-
const
|
|
351
|
-
if (!
|
|
350
|
+
const c = t.pages?.[e]?.currentSectionId;
|
|
351
|
+
if (!c)
|
|
352
352
|
return;
|
|
353
|
-
const d =
|
|
353
|
+
const d = r.dataSource?.[c];
|
|
354
354
|
if (!d)
|
|
355
355
|
return;
|
|
356
356
|
const { currentLocale: i } = this.currentLocaleMap;
|
|
@@ -359,13 +359,13 @@ const _e = () => {
|
|
|
359
359
|
get currentSectionPropertiesWithFallback() {
|
|
360
360
|
const {
|
|
361
361
|
localState: { currentPageId: e, ...t }
|
|
362
|
-
} = o, { currentPage:
|
|
363
|
-
if (!
|
|
362
|
+
} = o, { currentPage: r } = this;
|
|
363
|
+
if (!r || !e)
|
|
364
364
|
return;
|
|
365
|
-
const
|
|
366
|
-
if (!
|
|
365
|
+
const c = t.pages?.[e]?.currentSectionId;
|
|
366
|
+
if (!c)
|
|
367
367
|
return;
|
|
368
|
-
const d =
|
|
368
|
+
const d = r.dataSource?.[c];
|
|
369
369
|
if (!d)
|
|
370
370
|
return;
|
|
371
371
|
const { currentLocale: i, defaultLocale: l, fallbackLocale: m } = this.currentLocaleMap;
|
|
@@ -381,12 +381,12 @@ const _e = () => {
|
|
|
381
381
|
localState: { currentLocale: e },
|
|
382
382
|
state: {
|
|
383
383
|
supportedLocales: t,
|
|
384
|
-
config: { defaultLocale:
|
|
384
|
+
config: { defaultLocale: r }
|
|
385
385
|
}
|
|
386
386
|
} = o;
|
|
387
387
|
return {
|
|
388
388
|
currentLocale: e,
|
|
389
|
-
defaultLocale:
|
|
389
|
+
defaultLocale: r,
|
|
390
390
|
fallbackLocale: t?.[0]?.locale ?? "en"
|
|
391
391
|
};
|
|
392
392
|
},
|
|
@@ -403,7 +403,7 @@ const _e = () => {
|
|
|
403
403
|
}
|
|
404
404
|
}),
|
|
405
405
|
[JSON.stringify(f), n]
|
|
406
|
-
),
|
|
406
|
+
), J = j(() => {
|
|
407
407
|
if (f.currentPageId) {
|
|
408
408
|
const e = b(f.currentPageId);
|
|
409
409
|
if (e?.kind === "component-template")
|
|
@@ -421,31 +421,39 @@ const _e = () => {
|
|
|
421
421
|
renderer: e.renderer
|
|
422
422
|
};
|
|
423
423
|
}
|
|
424
|
-
}, [f.currentPageId, f.currentComponentId, b, k]),
|
|
425
|
-
() =>
|
|
426
|
-
[
|
|
424
|
+
}, [f.currentPageId, f.currentComponentId, b, k]), $ = M(
|
|
425
|
+
() => J?.kind === "component-template" ? J : void 0,
|
|
426
|
+
[J]
|
|
427
427
|
), y = j(
|
|
428
428
|
() => ({
|
|
429
429
|
setCurrentSectionId: (e, t) => {
|
|
430
|
-
const
|
|
431
|
-
e === f.currentPageId && t === f.pages?.[e]?.currentSectionId && (!
|
|
432
|
-
(d) =>
|
|
433
|
-
i.currentPageId = e,
|
|
430
|
+
const r = K(e), c = r ? Z(e) : null;
|
|
431
|
+
e === f.currentPageId && t === f.pages?.[e]?.currentSectionId && (!r || c === f.currentComponentId) || (O(r && c ? F("/admin/maker", w ?? "", "components", c) : F("/admin/maker", w ?? "", "pages", e)), I(
|
|
432
|
+
(d) => _(d, (i) => {
|
|
433
|
+
i.currentPageId = e, r ? c && (i.currentComponentId = c) : i.currentComponentId = void 0, i.pages ??= {}, i.pages[e] ??= {}, i.pages[e].currentSectionId = t ?? void 0, t ? window.sessionStorage.setItem("iframe_show_id", `"${t}"`) : window.sessionStorage.removeItem("iframe_show_id");
|
|
434
434
|
})
|
|
435
435
|
));
|
|
436
436
|
},
|
|
437
437
|
setCurrentComponentId: (e) => {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
438
|
+
if (!e) {
|
|
439
|
+
I(
|
|
440
|
+
(d) => _(d, (i) => {
|
|
441
|
+
i.currentComponentId = void 0;
|
|
442
|
+
})
|
|
443
|
+
);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const r = n.components[e]?.data?.renderer?.type === "component-template", c = r ? X(e) : void 0;
|
|
447
|
+
e === f.currentComponentId && (!r || f.currentPageId === c) || (O(F("/admin/maker", w ?? "", "components", e)), I(
|
|
448
|
+
(d) => _(d, (i) => {
|
|
449
|
+
i.currentComponentId = e, r && c ? (i.currentPageId = c, i.pages ??= {}, i.pages[c] ??= {}) : i.currentPageId && K(i.currentPageId) && (i.currentPageId = void 0);
|
|
442
450
|
})
|
|
443
451
|
));
|
|
444
452
|
},
|
|
445
453
|
setCurrentRouteId: ({ routeId: e, dynamicParams: t }) => {
|
|
446
|
-
|
|
447
|
-
(
|
|
448
|
-
|
|
454
|
+
I(
|
|
455
|
+
(r) => _(r, (c) => {
|
|
456
|
+
c.currentRouteId = e, c.currentDynamicParams = t;
|
|
449
457
|
})
|
|
450
458
|
);
|
|
451
459
|
},
|
|
@@ -453,34 +461,34 @@ const _e = () => {
|
|
|
453
461
|
setCustomComponentPreviewerProperties: (() => {
|
|
454
462
|
const e = {};
|
|
455
463
|
let t = "";
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
(
|
|
464
|
+
const r = ee(() => {
|
|
465
|
+
I(
|
|
466
|
+
(c) => _(c, (d) => {
|
|
459
467
|
d.customComponentPreviewerProperties ??= {}, d.customComponentPreviewerProperties[t] = {
|
|
460
468
|
...d.customComponentPreviewerProperties[t],
|
|
461
|
-
...
|
|
469
|
+
...R(e[t])
|
|
462
470
|
}, delete e[t];
|
|
463
471
|
})
|
|
464
472
|
);
|
|
465
473
|
}, 5);
|
|
466
|
-
return (
|
|
467
|
-
const i = e[
|
|
468
|
-
Object.assign(i, d), e[
|
|
474
|
+
return (c, d) => {
|
|
475
|
+
const i = e[c] ?? {};
|
|
476
|
+
Object.assign(i, d), e[c] = i, t = c, r();
|
|
469
477
|
};
|
|
470
478
|
})(),
|
|
471
479
|
setRouteGenerateProcess: (e) => {
|
|
472
|
-
|
|
473
|
-
(t) =>
|
|
474
|
-
e ?
|
|
475
|
-
...
|
|
480
|
+
I(
|
|
481
|
+
(t) => _(t, (r) => {
|
|
482
|
+
e ? r.routeGenerateProcess = {
|
|
483
|
+
...r.routeGenerateProcess,
|
|
476
484
|
...e
|
|
477
|
-
} :
|
|
485
|
+
} : r.routeGenerateProcess = {};
|
|
478
486
|
})
|
|
479
487
|
);
|
|
480
488
|
},
|
|
481
489
|
resetRouteGenerateProcess: () => {
|
|
482
|
-
|
|
483
|
-
(e) =>
|
|
490
|
+
I(
|
|
491
|
+
(e) => _(e, (t) => {
|
|
484
492
|
t.routeGenerateProcess = {
|
|
485
493
|
progress: "complete"
|
|
486
494
|
};
|
|
@@ -488,10 +496,10 @@ const _e = () => {
|
|
|
488
496
|
);
|
|
489
497
|
}
|
|
490
498
|
}),
|
|
491
|
-
[
|
|
499
|
+
[I, O, w, S]
|
|
492
500
|
), C = M(
|
|
493
|
-
(e, t,
|
|
494
|
-
const i = v(e), { page: l } = i, m =
|
|
501
|
+
(e, t, r, c, d) => {
|
|
502
|
+
const i = v(e), { page: l } = i, m = R(t), u = r ? R(r) : void 0, p = z(m);
|
|
495
503
|
return o.doc.transact(() => {
|
|
496
504
|
if (d && d.component === "layout-block") {
|
|
497
505
|
const s = S.currentPageModel?.getComponentById(d.id);
|
|
@@ -500,12 +508,12 @@ const _e = () => {
|
|
|
500
508
|
const s = i.renderer.section;
|
|
501
509
|
s.sections ??= {}, s.sections[p.id] = p, s.sectionIds ??= [], s.sectionIds.push(p.id);
|
|
502
510
|
} else
|
|
503
|
-
l.sections[p.id] = p, l.sectionIds.splice(
|
|
511
|
+
l.sections[p.id] = p, l.sectionIds.splice(c ?? l.sectionIds.length, 0, p.id);
|
|
504
512
|
if (u) {
|
|
505
513
|
l.dataSource ??= {};
|
|
506
514
|
const s = (a, g) => {
|
|
507
|
-
const
|
|
508
|
-
|
|
515
|
+
const P = u[a.id];
|
|
516
|
+
P && (l.dataSource[g.id] = R(P)), a.component === "layout-block" && a.sectionIds?.length && a.sectionIds.forEach((N, x) => {
|
|
509
517
|
const E = a.sections?.[N], L = g.sectionIds?.[x], D = L ? g.sections?.[L] : void 0;
|
|
510
518
|
E && D && s(E, D);
|
|
511
519
|
});
|
|
@@ -518,13 +526,13 @@ const _e = () => {
|
|
|
518
526
|
), U = j(
|
|
519
527
|
() => ({
|
|
520
528
|
addPage: (e, t) => {
|
|
521
|
-
const
|
|
529
|
+
const r = e?.id ?? B(), c = {
|
|
522
530
|
...e,
|
|
523
|
-
id:
|
|
531
|
+
id: r,
|
|
524
532
|
createdAt: e?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
525
533
|
updatedAt: e?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
526
534
|
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
527
|
-
slug: e?.slug ?? `/${
|
|
535
|
+
slug: e?.slug ?? `/${r}`,
|
|
528
536
|
sections: e?.sections ?? {},
|
|
529
537
|
sectionIds: e?.sectionIds ?? [],
|
|
530
538
|
isPublic: e?.isPublic ?? !0,
|
|
@@ -538,17 +546,17 @@ const _e = () => {
|
|
|
538
546
|
}
|
|
539
547
|
};
|
|
540
548
|
return o.doc.transact(() => {
|
|
541
|
-
n.pages[
|
|
542
|
-
}),
|
|
549
|
+
n.pages[c.id] = c, n.pageIds.splice(t ?? n.pageIds.length, 0, c.id);
|
|
550
|
+
}), c;
|
|
543
551
|
},
|
|
544
552
|
addRoute: (e, t) => {
|
|
545
|
-
const
|
|
553
|
+
const r = e?.id ?? B(), c = {
|
|
546
554
|
...e,
|
|
547
|
-
id:
|
|
555
|
+
id: r,
|
|
548
556
|
createdAt: e?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
549
557
|
updatedAt: e?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
550
558
|
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
551
|
-
path: e?.path ?? `/${
|
|
559
|
+
path: e?.path ?? `/${r}`,
|
|
552
560
|
handler: e?.handler ?? "Pages Kit",
|
|
553
561
|
isPublic: e?.isPublic ?? !0,
|
|
554
562
|
params: e?.params ?? [],
|
|
@@ -557,8 +565,8 @@ const _e = () => {
|
|
|
557
565
|
dataSource: e?.dataSource ?? {}
|
|
558
566
|
};
|
|
559
567
|
return o.doc.transact(() => {
|
|
560
|
-
n.routes ??= {}, n.routeIds ??= [], n.routes[
|
|
561
|
-
}),
|
|
568
|
+
n.routes ??= {}, n.routeIds ??= [], n.routes[c.id] = c, n.routeIds.splice(t ?? n.routeIds.length, 0, c.id);
|
|
569
|
+
}), c;
|
|
562
570
|
},
|
|
563
571
|
deleteRoute: (e) => {
|
|
564
572
|
if (!e)
|
|
@@ -575,15 +583,15 @@ const _e = () => {
|
|
|
575
583
|
});
|
|
576
584
|
},
|
|
577
585
|
movePage: (e, t) => {
|
|
578
|
-
const { pageIds:
|
|
579
|
-
|
|
586
|
+
const { pageIds: r } = n, c = r.indexOf(e);
|
|
587
|
+
c >= 0 && r.splice(t, 0, ...r.splice(c, 1));
|
|
580
588
|
},
|
|
581
|
-
addSection: (e, t,
|
|
589
|
+
addSection: (e, t, r, c) => {
|
|
582
590
|
const d = v(e), { page: i } = d, l = t?.config, m = typeof l?.componentId == "string" ? l.componentId : void 0;
|
|
583
591
|
if (t.component === "custom-component" && m) {
|
|
584
592
|
const a = (n.components[m]?.data ?? n.resources?.components?.[m]?.component)?.renderer;
|
|
585
593
|
if (a?.type === "component-template")
|
|
586
|
-
return C(e, a.section, a.dataSource,
|
|
594
|
+
return C(e, a.section, a.dataSource, r, c);
|
|
587
595
|
}
|
|
588
596
|
const u = {
|
|
589
597
|
...t,
|
|
@@ -591,21 +599,21 @@ const _e = () => {
|
|
|
591
599
|
isTemplateSection: t.isTemplateSection ?? !0
|
|
592
600
|
/** @deprecated 已经废弃,llmConfig 从 component / resources.component 中获取 */
|
|
593
601
|
// llmConfig: section.llmConfig ?? {},
|
|
594
|
-
}, p =
|
|
602
|
+
}, p = R(u.locales);
|
|
595
603
|
return delete u.locales, o.doc.transact(() => {
|
|
596
|
-
if (
|
|
597
|
-
const s = S.currentPageModel?.getComponentById(
|
|
604
|
+
if (c && c.component === "layout-block") {
|
|
605
|
+
const s = S.currentPageModel?.getComponentById(c.id);
|
|
598
606
|
s && (s.model.sections ??= {}, s.model.sections[u.id] = u, s.model.sectionIds ??= [], s.model.sectionIds.push(u.id));
|
|
599
607
|
} else if (d.kind === "component-template") {
|
|
600
608
|
const s = d.renderer.section;
|
|
601
609
|
s.sections ??= {}, s.sections[u.id] = u, s.sectionIds ??= [], s.sectionIds.push(u.id);
|
|
602
610
|
} else
|
|
603
|
-
i.sections[u.id] = u, i.sectionIds.splice(
|
|
611
|
+
i.sections[u.id] = u, i.sectionIds.splice(r ?? i.sectionIds.length, 0, u.id);
|
|
604
612
|
p && (i.dataSource ??= {}, i.dataSource[u.id] = p);
|
|
605
613
|
}), u;
|
|
606
614
|
},
|
|
607
615
|
deleteSection: (e, t) => {
|
|
608
|
-
const
|
|
616
|
+
const r = v(e), { page: c } = r;
|
|
609
617
|
o.doc.transact(() => {
|
|
610
618
|
const d = [], i = S.currentPageModel?.getComponentById(t), l = i?.parent;
|
|
611
619
|
if (i && (d.push(i.model.id, ...i.all().map((m) => m.model.id)), l?.model.component === "layout-block")) {
|
|
@@ -618,22 +626,22 @@ const _e = () => {
|
|
|
618
626
|
}), l.model.config?.backgroundSectionId === t && (l.model.config.backgroundSectionId = void 0);
|
|
619
627
|
}
|
|
620
628
|
d.forEach((m) => {
|
|
621
|
-
const u =
|
|
622
|
-
u !== -1 &&
|
|
629
|
+
const u = c.sectionIds.indexOf(m);
|
|
630
|
+
u !== -1 && c.sectionIds.splice(u, 1), c.sections[m] && delete c.sections[m], c.dataSource?.[m] && delete c.dataSource?.[m];
|
|
623
631
|
});
|
|
624
632
|
});
|
|
625
633
|
},
|
|
626
634
|
lockSection: (e, t) => {
|
|
627
635
|
v(e);
|
|
628
|
-
const
|
|
629
|
-
|
|
636
|
+
const r = S.currentPageModel?.getComponentById(t)?.model;
|
|
637
|
+
r && (r.locked = !r.locked);
|
|
630
638
|
},
|
|
631
|
-
toggleSectionVisibility: (e, t,
|
|
639
|
+
toggleSectionVisibility: (e, t, r) => {
|
|
632
640
|
v(e);
|
|
633
|
-
const
|
|
634
|
-
|
|
641
|
+
const c = S.currentPageModel?.getComponentById(t)?.model;
|
|
642
|
+
c && (c.visibility = r);
|
|
635
643
|
},
|
|
636
|
-
moveSection: (e, t,
|
|
644
|
+
moveSection: (e, t, r, c) => {
|
|
637
645
|
const d = v(e), { page: i } = d, l = S.currentPageModel;
|
|
638
646
|
if (!l)
|
|
639
647
|
throw new Error(`Page model for ${e} is not available`);
|
|
@@ -648,20 +656,20 @@ const _e = () => {
|
|
|
648
656
|
containerType: "root",
|
|
649
657
|
index: i.sectionIds.indexOf(p)
|
|
650
658
|
};
|
|
651
|
-
const
|
|
659
|
+
const P = g.model;
|
|
652
660
|
return {
|
|
653
661
|
section: a,
|
|
654
|
-
container:
|
|
662
|
+
container: P,
|
|
655
663
|
containerType: "layout-block",
|
|
656
|
-
index:
|
|
664
|
+
index: P.sectionIds.indexOf(p)
|
|
657
665
|
};
|
|
658
666
|
}, u = m(t);
|
|
659
667
|
if (!u)
|
|
660
668
|
throw new Error(`Section ${t} not found`);
|
|
661
669
|
o.doc.transact(() => {
|
|
662
|
-
if (
|
|
663
|
-
const a =
|
|
664
|
-
if (!
|
|
670
|
+
if (r.startsWith("layout-")) {
|
|
671
|
+
const a = r.replace("layout-", ""), P = l.getComponentById(a)?.model;
|
|
672
|
+
if (!P || P.component !== "layout-block")
|
|
665
673
|
throw new Error(`Layout block ${a} not found`);
|
|
666
674
|
if (a === t || ((E, L) => {
|
|
667
675
|
const D = l.getComponentById(E), G = l.getComponentById(L);
|
|
@@ -677,14 +685,14 @@ const _e = () => {
|
|
|
677
685
|
})(t, a))
|
|
678
686
|
return;
|
|
679
687
|
const x = JSON.parse(JSON.stringify(u.section));
|
|
680
|
-
|
|
688
|
+
P.sections || (P.sections = {}), P.sectionIds || (P.sectionIds = []), P.sections[t] = x, P.sectionIds.push(t), u.container.sectionIds.splice(u.index, 1), u.containerType === "layout-block" && delete u.container.sections[t];
|
|
681
689
|
return;
|
|
682
690
|
}
|
|
683
|
-
const p = m(
|
|
691
|
+
const p = m(r);
|
|
684
692
|
if (!p)
|
|
685
|
-
throw new Error(`Target section ${
|
|
693
|
+
throw new Error(`Target section ${r} not found`);
|
|
686
694
|
let s = p.index;
|
|
687
|
-
if (
|
|
695
|
+
if (c === "bottom" && (s = p.index + 1), u.container === p.container) {
|
|
688
696
|
const { sectionIds: a } = u.container;
|
|
689
697
|
a.splice(u.index, 1), u.index < s && (s -= 1), a.splice(s, 0, t);
|
|
690
698
|
} else {
|
|
@@ -695,18 +703,18 @@ const _e = () => {
|
|
|
695
703
|
},
|
|
696
704
|
copySection: (e, t) => {
|
|
697
705
|
v(e);
|
|
698
|
-
const
|
|
699
|
-
if (!
|
|
706
|
+
const r = S.currentPageModel?.getComponentById(t);
|
|
707
|
+
if (!r?.model)
|
|
700
708
|
throw new Error(`Section ${t} is not exists`);
|
|
701
|
-
const
|
|
709
|
+
const c = JSON.parse(JSON.stringify(r.model)), d = z(c), i = d.id, l = r?.parent;
|
|
702
710
|
if (l) {
|
|
703
711
|
if (l.model.sections[i] = d, l.model.sectionIds.push(i), S.currentPage?.dataSource?.[t] && (S.currentPage.dataSource[i] = JSON.parse(
|
|
704
712
|
JSON.stringify(S.currentPage.dataSource[t])
|
|
705
713
|
), d.component === "layout-block")) {
|
|
706
714
|
const m = (u, p) => {
|
|
707
715
|
const s = u.sectionIds, a = p.sectionIds;
|
|
708
|
-
s?.forEach((g,
|
|
709
|
-
const N = a?.[
|
|
716
|
+
s?.forEach((g, P) => {
|
|
717
|
+
const N = a?.[P];
|
|
710
718
|
if (N) {
|
|
711
719
|
if (N && S.currentPage?.dataSource) {
|
|
712
720
|
const L = S.currentPage.dataSource[N];
|
|
@@ -717,14 +725,14 @@ const _e = () => {
|
|
|
717
725
|
}
|
|
718
726
|
});
|
|
719
727
|
};
|
|
720
|
-
d.sectionIds &&
|
|
728
|
+
d.sectionIds && c.sectionIds && m(d, c);
|
|
721
729
|
}
|
|
722
730
|
y.setCurrentSectionId(e, i);
|
|
723
731
|
}
|
|
724
732
|
return d;
|
|
725
733
|
},
|
|
726
734
|
extractSectionToComponentTemplate: (e, t) => {
|
|
727
|
-
const
|
|
735
|
+
const r = v(e), { page: c } = r, i = S.currentPageModel?.getComponentById(t)?.model;
|
|
728
736
|
if (!i) {
|
|
729
737
|
console.warn(`Section ${t} is not exists`);
|
|
730
738
|
return;
|
|
@@ -735,11 +743,11 @@ const _e = () => {
|
|
|
735
743
|
return;
|
|
736
744
|
}
|
|
737
745
|
const m = (s, a = []) => (s && (a.push(s.id), s.sectionIds?.forEach((g) => {
|
|
738
|
-
const
|
|
739
|
-
m(
|
|
746
|
+
const P = s.sections?.[g];
|
|
747
|
+
m(P, a);
|
|
740
748
|
})), a), p = m(i).reduce(
|
|
741
749
|
(s, a) => {
|
|
742
|
-
const g =
|
|
750
|
+
const g = c.dataSource?.[a];
|
|
743
751
|
return g && (s[a] = JSON.parse(JSON.stringify(g))), s;
|
|
744
752
|
},
|
|
745
753
|
{}
|
|
@@ -752,10 +760,10 @@ const _e = () => {
|
|
|
752
760
|
addComponentTemplate: ({
|
|
753
761
|
name: e,
|
|
754
762
|
description: t,
|
|
755
|
-
section:
|
|
756
|
-
dataSource:
|
|
763
|
+
section: r,
|
|
764
|
+
dataSource: c
|
|
757
765
|
}) => {
|
|
758
|
-
const d = B(), i = (/* @__PURE__ */ new Date()).toISOString(), l =
|
|
766
|
+
const d = B(), i = (/* @__PURE__ */ new Date()).toISOString(), l = R(r), m = c ? R(c) : void 0;
|
|
759
767
|
return o.doc.transact(() => {
|
|
760
768
|
const u = Object.values(n.components).length;
|
|
761
769
|
n.components[d] = {
|
|
@@ -776,13 +784,13 @@ const _e = () => {
|
|
|
776
784
|
}), n.components[d];
|
|
777
785
|
},
|
|
778
786
|
addDataSource: (e) => {
|
|
779
|
-
const t = e.id ?? B(),
|
|
787
|
+
const t = e.id ?? B(), r = {
|
|
780
788
|
...e ?? {},
|
|
781
789
|
id: t,
|
|
782
790
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
783
791
|
};
|
|
784
792
|
return o.doc.transact(() => {
|
|
785
|
-
n.dataSourceIds ??= [], n.dataSources ??= {}, n.dataSourceIds.push(t), n.dataSources[t] =
|
|
793
|
+
n.dataSourceIds ??= [], n.dataSources ??= {}, n.dataSourceIds.push(t), n.dataSources[t] = r;
|
|
786
794
|
}), n.dataSources[t];
|
|
787
795
|
},
|
|
788
796
|
deleteDataSource: (e) => {
|
|
@@ -800,9 +808,9 @@ const _e = () => {
|
|
|
800
808
|
actions: U,
|
|
801
809
|
localActions: y,
|
|
802
810
|
...S,
|
|
803
|
-
getComponentTemplateContext:
|
|
811
|
+
getComponentTemplateContext: $
|
|
804
812
|
};
|
|
805
|
-
},
|
|
813
|
+
}, ce = () => {
|
|
806
814
|
const { projectId: o } = he();
|
|
807
815
|
return o ?? Ee() ?? "";
|
|
808
816
|
}, pt = () => window.__PROJECT_SLUG__ ?? "";
|
|
@@ -810,13 +818,13 @@ function Re(o) {
|
|
|
810
818
|
const { resources: n } = o;
|
|
811
819
|
if (!n.components)
|
|
812
820
|
return {};
|
|
813
|
-
const
|
|
821
|
+
const I = {};
|
|
814
822
|
return window?.blocklet?.componentMountPoints?.forEach((f) => {
|
|
815
|
-
|
|
823
|
+
I[f.did] = f;
|
|
816
824
|
}), Object.fromEntries(
|
|
817
825
|
Object.entries(n.components).map(([f, { blockletId: O, component: w }]) => [
|
|
818
826
|
f,
|
|
819
|
-
{ data: w, blockletId: O, blockletTitle:
|
|
827
|
+
{ data: w, blockletId: O, blockletTitle: I[O]?.title || O }
|
|
820
828
|
])
|
|
821
829
|
);
|
|
822
830
|
}
|
|
@@ -832,7 +840,7 @@ function $e(o) {
|
|
|
832
840
|
}
|
|
833
841
|
const mt = () => $e(_e().state);
|
|
834
842
|
function z(o) {
|
|
835
|
-
const n = JSON.parse(JSON.stringify(o)),
|
|
843
|
+
const n = JSON.parse(JSON.stringify(o)), I = B();
|
|
836
844
|
if (n.component === "layout-block") {
|
|
837
845
|
const f = { ...n.config ?? {} }, O = n.sectionIds?.map((w) => {
|
|
838
846
|
const A = n.sections?.[w], h = z(n.sections?.[w]), k = h.id;
|
|
@@ -850,7 +858,7 @@ function z(o) {
|
|
|
850
858
|
}
|
|
851
859
|
return {
|
|
852
860
|
...n,
|
|
853
|
-
id:
|
|
861
|
+
id: I
|
|
854
862
|
};
|
|
855
863
|
}
|
|
856
864
|
export {
|
|
@@ -869,5 +877,5 @@ export {
|
|
|
869
877
|
Je as l,
|
|
870
878
|
Re as m,
|
|
871
879
|
it as t,
|
|
872
|
-
|
|
880
|
+
ce as u
|
|
873
881
|
};
|