@blocklet/pages-kit-inner-components 0.4.132 → 0.4.134

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