@blocklet/pages-kit-inner-components 0.6.1 → 0.6.3
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 -420
- package/lib/cjs/chunks/draft-data-CfIMszE7.js +1 -0
- package/lib/cjs/chunks/home-DUjl5PbP.js +6 -0
- package/lib/cjs/chunks/publish-button-C522nNv6.js +1 -0
- package/lib/cjs/chunks/site-state-BG2d2tBl.js +57 -0
- package/lib/cjs/chunks/state-CtNs8GrN.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +11 -4
- package/lib/cjs/resources.js +1 -1
- package/lib/es/add-component.js +2 -1089
- package/lib/es/chunks/{draft-data-CafrGKeh.js → draft-data-bRUHvvzp.js} +5 -4
- package/lib/es/chunks/home-VWWdvIPQ.js +69 -0
- package/lib/es/chunks/{publish-button-XSZrDaTQ.js → publish-button-Ceet-m88.js} +158 -140
- package/lib/es/chunks/site-state-BoVWlYLn.js +2096 -0
- package/lib/es/chunks/state-BdNIIXJP.js +502 -0
- package/lib/es/home.js +3 -28
- package/lib/es/project-html.js +114 -130
- package/lib/es/resources.js +93 -137
- package/package.json +11 -11
- package/lib/cjs/chunks/draft-data-D44_IEV2.js +0 -1
- package/lib/cjs/chunks/home-BYk01EUy.js +0 -39
- package/lib/cjs/chunks/index-BRgYwvuv.js +0 -475
- package/lib/cjs/chunks/publish-button-C8XPA4g_.js +0 -1
- package/lib/cjs/chunks/session-BRtsDvA-.js +0 -1
- package/lib/cjs/chunks/site-state-gSkcvhcV.js +0 -57
- package/lib/cjs/chunks/state-B6BF5wJ-.js +0 -1
- package/lib/cjs/chunks-map.json +0 -1
- package/lib/cjs/components.js +0 -1
- package/lib/cjs/locales.js +0 -3
- package/lib/cjs/setting.js +0 -11
- package/lib/cjs/site-state.js +0 -1
- package/lib/cjs/theme.js +0 -1
- package/lib/cjs/uploader.js +0 -1
- package/lib/es/chunks/home-DW8SdyfO.js +0 -594
- package/lib/es/chunks/index-D5gXPe_7.js +0 -2326
- package/lib/es/chunks/session-C72Dq8zg.js +0 -19
- package/lib/es/chunks/site-state-W2H7XCSQ.js +0 -2077
- package/lib/es/chunks/state-0gvZF3k2.js +0 -573
- package/lib/es/chunks-map.json +0 -1
- package/lib/es/components.js +0 -22
- package/lib/es/locales.js +0 -1032
- package/lib/es/setting.js +0 -2294
- package/lib/es/site-state.js +0 -48
- package/lib/es/theme.js +0 -484
- package/lib/es/uploader.js +0 -8
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { jsx as W } from "react/jsx-runtime";
|
|
2
|
+
import { joinURL as R } from "ufo";
|
|
3
|
+
import { c as B, d as F } from "./home-VWWdvIPQ.js";
|
|
4
|
+
import { useLocaleContext as K } from "@arcblock/ux/lib/Locale/context";
|
|
5
|
+
import { nextId as x } from "@blocklet/pages-kit/utils/common";
|
|
6
|
+
import { getPageTemplateModel as V } from "@blocklet/pages-kit/utils/page-model";
|
|
7
|
+
import "@mui/material";
|
|
8
|
+
import Y, { getYjsDoc as q } from "@syncedstore/core";
|
|
9
|
+
import { useSyncedStore as z } from "@syncedstore/react";
|
|
10
|
+
import { useLocalStorageState as H } from "ahooks";
|
|
11
|
+
import { produce as v } from "immer";
|
|
12
|
+
import T from "lodash/cloneDeep";
|
|
13
|
+
import G from "lodash/debounce";
|
|
14
|
+
import { useState as O, useRef as Q, useMemo as P, useCallback as M, useEffect as j, createContext as X, useContext as Z } from "react";
|
|
15
|
+
import { useParams as ee, useNavigate as te } from "react-router-dom";
|
|
16
|
+
import { IndexeddbPersistence as oe } from "y-indexeddb";
|
|
17
|
+
import { WebsocketProvider as re } from "y-websocket";
|
|
18
|
+
import { UndoManager as ne } from "yjs";
|
|
19
|
+
import "@blocklet/pages-kit/types";
|
|
20
|
+
async function ce(i) {
|
|
21
|
+
return B.get(`/api/projects/${i}`).then((c) => c.data);
|
|
22
|
+
}
|
|
23
|
+
async function se(i) {
|
|
24
|
+
return B.post(`/api/projects/${i.id}/update`, i).then((c) => c.data);
|
|
25
|
+
}
|
|
26
|
+
const ae = 500, J = X(null);
|
|
27
|
+
function be({
|
|
28
|
+
url: i,
|
|
29
|
+
name: c,
|
|
30
|
+
children: S,
|
|
31
|
+
waitingSynced: w
|
|
32
|
+
}) {
|
|
33
|
+
const [y, h] = O(!1), { locale: u } = K(), f = _(), b = `${f}:MakerLocalState`, e = `${f}:${c}`, [t, r] = H(b, {
|
|
34
|
+
defaultValue: {},
|
|
35
|
+
listenStorageChange: !0
|
|
36
|
+
}), o = Q(t);
|
|
37
|
+
o.current = t;
|
|
38
|
+
const a = P(
|
|
39
|
+
() => Y({
|
|
40
|
+
dataSourceIds: [],
|
|
41
|
+
dataSources: {},
|
|
42
|
+
pages: {},
|
|
43
|
+
pageIds: [],
|
|
44
|
+
routes: {},
|
|
45
|
+
routeIds: [],
|
|
46
|
+
components: {},
|
|
47
|
+
supportedLocales: [],
|
|
48
|
+
config: {},
|
|
49
|
+
resources: {}
|
|
50
|
+
}),
|
|
51
|
+
[]
|
|
52
|
+
), n = P(() => q(a), [a]);
|
|
53
|
+
P(() => new oe(e, n), [e, n]);
|
|
54
|
+
const s = P(
|
|
55
|
+
() => new re(i, e, n, {
|
|
56
|
+
params: {},
|
|
57
|
+
resyncInterval: 5 * 60 * 1e3
|
|
58
|
+
}),
|
|
59
|
+
[i, e, n]
|
|
60
|
+
), d = M(() => {
|
|
61
|
+
s && (s.disconnect(), s.connect());
|
|
62
|
+
}, [s]), p = P(
|
|
63
|
+
() => new ne(
|
|
64
|
+
[
|
|
65
|
+
n.getArray("pageIds"),
|
|
66
|
+
n.getMap("pages"),
|
|
67
|
+
n.getArray("supportedLocales"),
|
|
68
|
+
n.getMap("config"),
|
|
69
|
+
n.getMap("dataSources"),
|
|
70
|
+
n.getArray("dataSourceIds"),
|
|
71
|
+
n.getArray("routeIds"),
|
|
72
|
+
n.getMap("routes")
|
|
73
|
+
],
|
|
74
|
+
{ doc: n }
|
|
75
|
+
),
|
|
76
|
+
[n]
|
|
77
|
+
), [C, L] = O(null), [E, N] = O(!1), [k, A] = O(void 0), $ = M(async () => {
|
|
78
|
+
if (f) {
|
|
79
|
+
N(!0);
|
|
80
|
+
try {
|
|
81
|
+
const l = await ce(f);
|
|
82
|
+
L(l);
|
|
83
|
+
} catch (l) {
|
|
84
|
+
console.error("Failed to fetch project:", l);
|
|
85
|
+
} finally {
|
|
86
|
+
N(!1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, [f]), D = M(
|
|
90
|
+
async (l, g) => {
|
|
91
|
+
if (A(void 0), !!f) {
|
|
92
|
+
g?.optimisticUpdate && C && L((m) => ({
|
|
93
|
+
...m,
|
|
94
|
+
...l
|
|
95
|
+
}));
|
|
96
|
+
try {
|
|
97
|
+
const m = await se({
|
|
98
|
+
...l
|
|
99
|
+
});
|
|
100
|
+
L(m);
|
|
101
|
+
} catch (m) {
|
|
102
|
+
console.error("Failed to update project:", m), g?.optimisticUpdate && L(C), A(m?.response?.data);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
[f, C]
|
|
107
|
+
);
|
|
108
|
+
j(() => {
|
|
109
|
+
f && $();
|
|
110
|
+
}, [f, $]);
|
|
111
|
+
const U = P(
|
|
112
|
+
() => ({
|
|
113
|
+
doc: n,
|
|
114
|
+
state: a,
|
|
115
|
+
localState: {
|
|
116
|
+
...t,
|
|
117
|
+
// always use the locale from the context
|
|
118
|
+
currentLocale: u
|
|
119
|
+
},
|
|
120
|
+
setLocalState: (l) => r(typeof l == "function" ? (g) => l(g ?? {}) : l),
|
|
121
|
+
undoManager: p,
|
|
122
|
+
projectState: {
|
|
123
|
+
project: C,
|
|
124
|
+
isLoadingProject: E,
|
|
125
|
+
error: k
|
|
126
|
+
},
|
|
127
|
+
updateProject: D,
|
|
128
|
+
forceSync: d
|
|
129
|
+
}),
|
|
130
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
131
|
+
[
|
|
132
|
+
n,
|
|
133
|
+
a,
|
|
134
|
+
JSON.stringify(t),
|
|
135
|
+
// resolve the problem of react warning
|
|
136
|
+
r,
|
|
137
|
+
p,
|
|
138
|
+
C,
|
|
139
|
+
E,
|
|
140
|
+
D,
|
|
141
|
+
k,
|
|
142
|
+
u,
|
|
143
|
+
d
|
|
144
|
+
]
|
|
145
|
+
);
|
|
146
|
+
return j(() => {
|
|
147
|
+
p.on("stack-item-added", ({ stackItem: l }) => {
|
|
148
|
+
const { currentPageId: g, currentLocale: m, pages: I } = o.current;
|
|
149
|
+
l.meta.set("localState", { currentPageId: g, currentLocale: m, pages: I });
|
|
150
|
+
}), p.on("stack-item-popped", ({ stackItem: l }) => {
|
|
151
|
+
const g = l.meta.get("localState");
|
|
152
|
+
g && r((m) => ({ ...m, ...g }));
|
|
153
|
+
});
|
|
154
|
+
}, [p, r]), j(() => {
|
|
155
|
+
s.awareness.setLocalState(t);
|
|
156
|
+
}, [s, t]), j(() => {
|
|
157
|
+
s.once("synced", () => h(!0));
|
|
158
|
+
const l = () => {
|
|
159
|
+
r((I) => ({
|
|
160
|
+
...I,
|
|
161
|
+
networkStatus: void 0
|
|
162
|
+
}));
|
|
163
|
+
}, g = () => {
|
|
164
|
+
r((I) => ({
|
|
165
|
+
...I,
|
|
166
|
+
networkStatus: "offline"
|
|
167
|
+
}));
|
|
168
|
+
}, m = G(({ status: I }) => {
|
|
169
|
+
I === "connected" ? l() : I === "disconnected" && g();
|
|
170
|
+
}, ae);
|
|
171
|
+
return s.on("status", m), window.addEventListener("online", l), window.addEventListener("offline", g), () => {
|
|
172
|
+
s.off("status", m), window.removeEventListener("online", l), window.removeEventListener("offline", g);
|
|
173
|
+
};
|
|
174
|
+
}, [s, r]), w && !y ? null : /* @__PURE__ */ W(J.Provider, { value: U, children: S });
|
|
175
|
+
}
|
|
176
|
+
const Me = () => {
|
|
177
|
+
const i = Z(J);
|
|
178
|
+
if (!i)
|
|
179
|
+
throw new Error("Context is null");
|
|
180
|
+
const c = z(i.state), { setLocalState: S, localState: w } = i, y = te(), h = _(), u = P(
|
|
181
|
+
() => ({
|
|
182
|
+
get currentPage() {
|
|
183
|
+
const {
|
|
184
|
+
localState: { currentPageId: e }
|
|
185
|
+
} = i;
|
|
186
|
+
return e ? c.pages[e] : void 0;
|
|
187
|
+
},
|
|
188
|
+
get currentSection() {
|
|
189
|
+
const {
|
|
190
|
+
localState: { currentPageId: e, ...t }
|
|
191
|
+
} = i;
|
|
192
|
+
if (!e)
|
|
193
|
+
return;
|
|
194
|
+
const r = t.pages?.[e]?.currentSectionId;
|
|
195
|
+
if (r)
|
|
196
|
+
return c.pages[e]?.sections[r] ?? this.currentPageModel?.getComponentById(r)?.model;
|
|
197
|
+
},
|
|
198
|
+
get currentSectionProperties() {
|
|
199
|
+
const {
|
|
200
|
+
localState: { currentPageId: e, ...t }
|
|
201
|
+
} = i;
|
|
202
|
+
if (!e)
|
|
203
|
+
return;
|
|
204
|
+
const r = t.pages?.[e]?.currentSectionId;
|
|
205
|
+
if (!r)
|
|
206
|
+
return;
|
|
207
|
+
const o = c.pages[e]?.dataSource?.[r];
|
|
208
|
+
if (!o)
|
|
209
|
+
return;
|
|
210
|
+
const { currentLocale: a } = this.currentLocaleMap;
|
|
211
|
+
return a ? o[a] : void 0;
|
|
212
|
+
},
|
|
213
|
+
get currentSectionPropertiesWithFallback() {
|
|
214
|
+
const {
|
|
215
|
+
localState: { currentPageId: e, ...t }
|
|
216
|
+
} = i;
|
|
217
|
+
if (!e)
|
|
218
|
+
return;
|
|
219
|
+
const r = t.pages?.[e]?.currentSectionId;
|
|
220
|
+
if (!r)
|
|
221
|
+
return;
|
|
222
|
+
const o = c.pages[e]?.dataSource?.[r];
|
|
223
|
+
if (!o)
|
|
224
|
+
return;
|
|
225
|
+
const { currentLocale: a, defaultLocale: n, fallbackLocale: s } = this.currentLocaleMap;
|
|
226
|
+
if (a && o[a])
|
|
227
|
+
return o[a];
|
|
228
|
+
if (n && o[n])
|
|
229
|
+
return o[n];
|
|
230
|
+
if (s && o[s])
|
|
231
|
+
return o[s];
|
|
232
|
+
},
|
|
233
|
+
get currentLocaleMap() {
|
|
234
|
+
const {
|
|
235
|
+
localState: { currentLocale: e },
|
|
236
|
+
state: {
|
|
237
|
+
supportedLocales: t,
|
|
238
|
+
config: { defaultLocale: r }
|
|
239
|
+
}
|
|
240
|
+
} = i;
|
|
241
|
+
return {
|
|
242
|
+
currentLocale: e,
|
|
243
|
+
defaultLocale: r,
|
|
244
|
+
fallbackLocale: t?.[0]?.locale ?? "en"
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
get currentRoute() {
|
|
248
|
+
const {
|
|
249
|
+
localState: { currentRouteId: e }
|
|
250
|
+
} = i;
|
|
251
|
+
return e ? c.routes?.[e] : void 0;
|
|
252
|
+
},
|
|
253
|
+
get currentPageModel() {
|
|
254
|
+
const e = this.currentPage ?? null;
|
|
255
|
+
if (e)
|
|
256
|
+
return V(e, !1);
|
|
257
|
+
}
|
|
258
|
+
}),
|
|
259
|
+
[JSON.stringify(w), c]
|
|
260
|
+
), f = P(
|
|
261
|
+
() => ({
|
|
262
|
+
setCurrentSectionId: (e, t) => {
|
|
263
|
+
e === w.currentPageId && t === w.pages?.[e]?.currentSectionId || (y(R("/admin/maker", h ?? "", "pages", e)), S(
|
|
264
|
+
(r) => v(r, (o) => {
|
|
265
|
+
o.currentPageId = e, o.currentComponentId = void 0, t !== void 0 && (o.pages ??= {}, o.pages[e] ??= {}, o.pages[e].currentSectionId = t ?? void 0), t ? window.sessionStorage.setItem("iframe_show_id", `"${t}"`) : window.sessionStorage.removeItem("iframe_show_id");
|
|
266
|
+
})
|
|
267
|
+
));
|
|
268
|
+
},
|
|
269
|
+
setCurrentComponentId: (e) => {
|
|
270
|
+
e !== w.currentComponentId && (y(R("/admin/maker", h ?? "", "components", e)), S(
|
|
271
|
+
(t) => v(t, (r) => {
|
|
272
|
+
r.currentComponentId = e;
|
|
273
|
+
})
|
|
274
|
+
));
|
|
275
|
+
},
|
|
276
|
+
setCurrentRouteId: ({ routeId: e, dynamicParams: t }) => {
|
|
277
|
+
S(
|
|
278
|
+
(r) => v(r, (o) => {
|
|
279
|
+
o.currentRouteId = e, o.currentDynamicParams = t;
|
|
280
|
+
})
|
|
281
|
+
);
|
|
282
|
+
},
|
|
283
|
+
// 本地缓存组件调试参数,避免用户切换组件后,需要重新输入
|
|
284
|
+
setCustomComponentPreviewerProperties: (() => {
|
|
285
|
+
const e = {};
|
|
286
|
+
let t = "";
|
|
287
|
+
const r = G(() => {
|
|
288
|
+
S(
|
|
289
|
+
(o) => v(o, (a) => {
|
|
290
|
+
a.customComponentPreviewerProperties ??= {}, a.customComponentPreviewerProperties[t] = {
|
|
291
|
+
...a.customComponentPreviewerProperties[t],
|
|
292
|
+
...T(e[t])
|
|
293
|
+
}, delete e[t];
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
}, 5);
|
|
297
|
+
return (o, a) => {
|
|
298
|
+
const n = e[o] ?? {};
|
|
299
|
+
Object.assign(n, a), e[o] = n, t = o, r();
|
|
300
|
+
};
|
|
301
|
+
})(),
|
|
302
|
+
setRouteGenerateProcess: (e) => {
|
|
303
|
+
S(
|
|
304
|
+
(t) => v(t, (r) => {
|
|
305
|
+
e ? r.routeGenerateProcess = {
|
|
306
|
+
...r.routeGenerateProcess,
|
|
307
|
+
...e
|
|
308
|
+
} : r.routeGenerateProcess = {};
|
|
309
|
+
})
|
|
310
|
+
);
|
|
311
|
+
},
|
|
312
|
+
resetRouteGenerateProcess: () => {
|
|
313
|
+
S(
|
|
314
|
+
(e) => v(e, (t) => {
|
|
315
|
+
t.routeGenerateProcess = {
|
|
316
|
+
progress: "complete"
|
|
317
|
+
};
|
|
318
|
+
})
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
}),
|
|
322
|
+
[S, y, h, u]
|
|
323
|
+
), b = P(
|
|
324
|
+
() => ({
|
|
325
|
+
addPage: (e, t) => {
|
|
326
|
+
const r = e?.id ?? x(), o = {
|
|
327
|
+
...e,
|
|
328
|
+
id: r,
|
|
329
|
+
createdAt: e?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
330
|
+
updatedAt: e?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
331
|
+
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
332
|
+
slug: e?.slug ?? `/${r}`,
|
|
333
|
+
sections: e?.sections ?? {},
|
|
334
|
+
sectionIds: e?.sectionIds ?? [],
|
|
335
|
+
isPublic: e?.isPublic ?? !0,
|
|
336
|
+
templateConfig: e?.templateConfig ?? {
|
|
337
|
+
isTemplate: e?.templateConfig?.isTemplate ?? !0,
|
|
338
|
+
displayTemplateId: e?.templateConfig?.displayTemplateId ?? void 0,
|
|
339
|
+
dataSourceIds: e?.templateConfig?.dataSourceIds ?? void 0,
|
|
340
|
+
dataSourceParameters: e?.templateConfig?.dataSourceParameters ?? {},
|
|
341
|
+
enabledGenerate: e?.templateConfig?.enabledGenerate ?? !1,
|
|
342
|
+
agentId: e?.templateConfig?.agentId ?? void 0
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
return i.doc.transact(() => {
|
|
346
|
+
c.pages[o.id] = o, c.pageIds.splice(t ?? c.pageIds.length, 0, o.id);
|
|
347
|
+
}), o;
|
|
348
|
+
},
|
|
349
|
+
addRoute: (e, t) => {
|
|
350
|
+
const r = e?.id ?? x(), o = {
|
|
351
|
+
...e,
|
|
352
|
+
id: r,
|
|
353
|
+
createdAt: e?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
354
|
+
updatedAt: e?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
355
|
+
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
356
|
+
path: e?.path ?? `/${r}`,
|
|
357
|
+
handler: e?.handler ?? "Pages Kit",
|
|
358
|
+
isPublic: e?.isPublic ?? !0,
|
|
359
|
+
params: e?.params ?? [],
|
|
360
|
+
enabledGenerate: e?.enabledGenerate ?? !1,
|
|
361
|
+
displayTemplateId: e?.displayTemplateId ?? void 0,
|
|
362
|
+
dataSource: e?.dataSource ?? {}
|
|
363
|
+
};
|
|
364
|
+
return i.doc.transact(() => {
|
|
365
|
+
c.routes ??= {}, c.routeIds ??= [], c.routes[o.id] = o, c.routeIds.splice(t ?? c.routeIds.length, 0, o.id);
|
|
366
|
+
}), o;
|
|
367
|
+
},
|
|
368
|
+
deleteRoute: (e) => {
|
|
369
|
+
if (!e)
|
|
370
|
+
return;
|
|
371
|
+
const t = c.routeIds?.indexOf(e);
|
|
372
|
+
t !== void 0 && t !== -1 && i.doc.transact(() => {
|
|
373
|
+
c.routeIds?.splice(t, 1), delete c.routes?.[e];
|
|
374
|
+
});
|
|
375
|
+
},
|
|
376
|
+
deletePage: (e) => {
|
|
377
|
+
const t = c.pageIds.indexOf(e);
|
|
378
|
+
t !== -1 && i.doc.transact(() => {
|
|
379
|
+
c.pageIds.splice(t, 1), delete c.pages[e];
|
|
380
|
+
});
|
|
381
|
+
},
|
|
382
|
+
movePage: (e, t) => {
|
|
383
|
+
const { pageIds: r } = c, o = r.indexOf(e);
|
|
384
|
+
o >= 0 && r.splice(t, 0, ...r.splice(o, 1));
|
|
385
|
+
},
|
|
386
|
+
addSection: (e, t, r, o) => {
|
|
387
|
+
const a = c.pages[e];
|
|
388
|
+
if (!a)
|
|
389
|
+
throw new Error(`Page ${e} is not exists`);
|
|
390
|
+
const n = {
|
|
391
|
+
...t,
|
|
392
|
+
id: t.id ?? x(),
|
|
393
|
+
isTemplateSection: t.isTemplateSection ?? !0,
|
|
394
|
+
llmConfig: t.llmConfig ?? {}
|
|
395
|
+
}, s = T(n.locales);
|
|
396
|
+
return delete n.locales, i.doc.transact(() => {
|
|
397
|
+
if (o && o.component === "layout-block") {
|
|
398
|
+
const d = u.currentPageModel?.getComponentById(o.id);
|
|
399
|
+
d && (d.model.sections ??= {}, d.model.sections[n.id] = n, d.model.sectionIds ??= [], d.model.sectionIds.push(n.id));
|
|
400
|
+
} else
|
|
401
|
+
a.sections[n.id] = n, a.sectionIds.splice(r ?? a.sectionIds.length, 0, n.id);
|
|
402
|
+
s && (a.dataSource ??= {}, a.dataSource[n.id] = s);
|
|
403
|
+
}), n;
|
|
404
|
+
},
|
|
405
|
+
deleteSection: (e, t) => {
|
|
406
|
+
const r = c.pages[e];
|
|
407
|
+
if (!r)
|
|
408
|
+
throw new Error(`Page ${e} is not exists`);
|
|
409
|
+
i.doc.transact(() => {
|
|
410
|
+
const o = [], a = u.currentPageModel?.getComponentById(t), n = a?.parent;
|
|
411
|
+
if (a && (o.push(a.model.id, ...a.all().map((s) => s.model.id)), n?.model.component === "layout-block")) {
|
|
412
|
+
const s = n.model.sectionIds?.indexOf(t);
|
|
413
|
+
s !== void 0 && s !== -1 && (n.model.sectionIds?.splice(s, 1), delete n.model.sections?.[t]), n.model.config?.gridSettings && Object.keys(n.model.config.gridSettings).forEach((d) => {
|
|
414
|
+
try {
|
|
415
|
+
delete n.model.config.gridSettings[d]?.[t];
|
|
416
|
+
} catch {
|
|
417
|
+
}
|
|
418
|
+
}), n.model.config?.backgroundSectionId === t && (n.model.config.backgroundSectionId = void 0);
|
|
419
|
+
}
|
|
420
|
+
o.forEach((s) => {
|
|
421
|
+
const d = r.sectionIds.indexOf(s);
|
|
422
|
+
d !== -1 && r.sectionIds.splice(d, 1), r.sections[s] && delete r.sections[s], r.dataSource?.[s] && delete r.dataSource?.[s];
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
},
|
|
426
|
+
lockSection: (e, t) => {
|
|
427
|
+
if (!c.pages[e])
|
|
428
|
+
throw new Error(`Page ${e} is not exists`);
|
|
429
|
+
const o = u.currentPageModel?.getComponentById(t)?.model;
|
|
430
|
+
o && (o.locked = !o.locked);
|
|
431
|
+
},
|
|
432
|
+
toggleSectionVisibility: (e, t, r) => {
|
|
433
|
+
if (!c.pages[e])
|
|
434
|
+
throw new Error(`Page ${e} is not exists`);
|
|
435
|
+
const a = u.currentPageModel?.getComponentById(t)?.model;
|
|
436
|
+
a && (a.visibility = r);
|
|
437
|
+
},
|
|
438
|
+
moveSection: (e, t, r, o) => {
|
|
439
|
+
if (!c.pages[e])
|
|
440
|
+
throw new Error(`Page ${e} is not exists`);
|
|
441
|
+
if (o && o !== t) {
|
|
442
|
+
const n = u.currentPageModel?.getComponentById(t), s = u.currentPageModel?.getComponentById(o), d = n?.parent, p = s?.parent;
|
|
443
|
+
p && d && p?.model?.id === d?.model?.id ? i.doc.transact(() => {
|
|
444
|
+
d.model.sectionIds.splice(n.getIndex(), 1), d.model.sectionIds.splice(s.getIndex(), 0, t);
|
|
445
|
+
}) : p && d && p?.model?.id !== d?.model?.id && t !== o && !n?.model?.sectionIds?.includes(o) && i.doc.transact(() => {
|
|
446
|
+
p.model.sections[t] = JSON.parse(JSON.stringify(n.model)), p.model.sectionIds.splice(s.getIndex(), 0, t), d.model.sectionIds.splice(n.getIndex(), 1), delete d.model.sections[t];
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
copySection: (e, t) => {
|
|
451
|
+
if (!c.pages[e])
|
|
452
|
+
throw new Error(`Page ${e} is not exists`);
|
|
453
|
+
const o = u.currentPageModel?.getComponentById(t);
|
|
454
|
+
if (!o?.model)
|
|
455
|
+
throw new Error(`Section ${t} is not exists`);
|
|
456
|
+
const a = JSON.parse(JSON.stringify(o.model)), n = ie(a), s = n.id, d = o?.parent;
|
|
457
|
+
return d && (d.model.sections[s] = n, d.model.sectionIds.push(s), f.setCurrentSectionId(e, s), u.currentPage?.dataSource?.[t] && (u.currentPage.dataSource[s] = JSON.parse(
|
|
458
|
+
JSON.stringify(u.currentPage.dataSource[t])
|
|
459
|
+
))), n;
|
|
460
|
+
},
|
|
461
|
+
addDataSource: (e) => {
|
|
462
|
+
const t = e.id ?? x(), r = {
|
|
463
|
+
...e ?? {},
|
|
464
|
+
id: t,
|
|
465
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
466
|
+
};
|
|
467
|
+
return i.doc.transact(() => {
|
|
468
|
+
c.dataSourceIds ??= [], c.dataSources ??= {}, c.dataSourceIds.push(t), c.dataSources[t] = r;
|
|
469
|
+
}), c.dataSources[t];
|
|
470
|
+
},
|
|
471
|
+
deleteDataSource: (e) => {
|
|
472
|
+
const t = c.dataSourceIds.indexOf(e);
|
|
473
|
+
t !== -1 && i.doc.transact(() => {
|
|
474
|
+
c.dataSourceIds.splice(t, 1), delete c.dataSources[e];
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}),
|
|
478
|
+
[c, i.doc, u]
|
|
479
|
+
);
|
|
480
|
+
return {
|
|
481
|
+
...i,
|
|
482
|
+
state: c,
|
|
483
|
+
actions: b,
|
|
484
|
+
localActions: f,
|
|
485
|
+
...u
|
|
486
|
+
};
|
|
487
|
+
}, _ = () => {
|
|
488
|
+
const { projectId: i } = ee();
|
|
489
|
+
return i ?? F() ?? "";
|
|
490
|
+
};
|
|
491
|
+
function ie(i) {
|
|
492
|
+
const c = JSON.parse(JSON.stringify(i)), S = x();
|
|
493
|
+
return {
|
|
494
|
+
...c,
|
|
495
|
+
id: S
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
export {
|
|
499
|
+
be as S,
|
|
500
|
+
Me as a,
|
|
501
|
+
_ as u
|
|
502
|
+
};
|
package/lib/es/home.js
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
1
|
-
import "react/jsx-runtime";
|
|
2
|
-
import "./chunks/state-0gvZF3k2.js";
|
|
3
|
-
import "@arcblock/ux/lib/Locale/context";
|
|
4
|
-
import "@arcblock/ux/lib/Result";
|
|
5
1
|
import "@arcblock/ux/lib/Theme";
|
|
6
|
-
import "@blocklet/pages-kit/builtin/page/header";
|
|
7
|
-
import "@blocklet/pages-kit/contexts/color";
|
|
8
|
-
import "@blocklet/pages-kit/utils/data-source";
|
|
9
|
-
import "@blocklet/pages-kit/utils/route";
|
|
10
2
|
import "@blocklet/ui-react/lib/Header";
|
|
11
|
-
import "@emotion/css";
|
|
12
|
-
import "@emotion/react";
|
|
13
3
|
import "@mui/material";
|
|
14
|
-
import "ahooks";
|
|
15
|
-
import "isomorphic-dompurify";
|
|
16
|
-
import "lodash/cloneDeep";
|
|
17
|
-
import "lodash/isEmpty";
|
|
18
|
-
import "lodash/isEqual";
|
|
19
4
|
import "react";
|
|
20
|
-
import "react-helmet";
|
|
21
5
|
import "react-router-dom";
|
|
22
|
-
import "
|
|
23
|
-
import "
|
|
24
|
-
import "./chunks/index-D5gXPe_7.js";
|
|
25
|
-
import { a as R, P as S, d as W, c as j, b as k, T as q, H as v } from "./chunks/home-DW8SdyfO.js";
|
|
26
|
-
import "./chunks/session-C72Dq8zg.js";
|
|
6
|
+
import { e as f } from "./chunks/home-VWWdvIPQ.js";
|
|
7
|
+
import "react/jsx-runtime";
|
|
27
8
|
export {
|
|
28
|
-
|
|
29
|
-
S as PageRoutes,
|
|
30
|
-
W as PageView,
|
|
31
|
-
j as PageViewByPath,
|
|
32
|
-
k as PageViewWithDataSource,
|
|
33
|
-
q as TranslucentHeader,
|
|
34
|
-
v as default
|
|
9
|
+
f as default
|
|
35
10
|
};
|