@blocklet/pages-kit-inner-components 0.4.126 → 0.4.127

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit-inner-components",
3
- "version": "0.4.126",
3
+ "version": "0.4.127",
4
4
  "description": "Pages Kit inner components library",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -205,8 +205,8 @@
205
205
  "yaml": "^2.5.0",
206
206
  "yjs": "^13.6.18",
207
207
  "zustand": "^4.5.5",
208
- "@blocklet/pages-kit": "^0.4.126",
209
- "@blocklet/pages-kit-block-studio": "^0.4.126"
208
+ "@blocklet/pages-kit-block-studio": "^0.4.127",
209
+ "@blocklet/pages-kit": "^0.4.127"
210
210
  },
211
211
  "devDependencies": {
212
212
  "@trivago/prettier-plugin-sort-imports": "^5.2.1",
@@ -1 +0,0 @@
1
- "use strict";const _=require("react/jsx-runtime"),D=require("@mui/material"),C=require("ufo"),Z=require("@blocklet/js-sdk"),H=require("lodash/isEmpty"),ee=require("yaml"),te=require("@arcblock/ux/lib/Locale/context"),V=require("@syncedstore/core"),ne=require("@syncedstore/react"),oe=require("ahooks"),x=require("immer"),re=require("js-cookie"),se=require("lodash/debounce"),ce=require("nanoid"),d=require("react"),W=require("react-router-dom"),ie=require("y-indexeddb"),ae=require("y-websocket"),de=require("yjs");require("@blocklet/pages-kit/types");const O=t=>t&&t.__esModule?t:{default:t};function le(t){if(t&&t.__esModule)return t;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const i in t)if(i!=="default"){const S=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(n,i,S.get?S:{enumerable:!0,get:()=>t[i]})}}return n.default=t,Object.freeze(n)}const ue=O(H),fe=le(ee),me=O(V),Se=O(re),G=O(se),we=t=>{const n=blocklet==null?void 0:blocklet.componentMountPoints.find(i=>i.name===t);return n?n.mountPoint:"/"};function z(){const{pathname:t}=window.location,n=t.match(/\/admin\/(maker|previewer)\/([^/]+)/),i=n==null?void 0:n[2],S=window.__PROJECT_ID__;if(!i&&!S)throw new Error("Unable to get projectId from pathname");return i||S}function pe(t){return`${t}:pages:version`}function Pe(t,n){return n==="yaml"?ue.default(t)?"":fe.stringify(t,{indent:2}):n==="json"?JSON.parse(JSON.stringify(t||{})):n==="array"?JSON.parse(JSON.stringify(t||[])):t}function Ie({error:t}){return _.jsx(D.Box,{children:_.jsx(D.Alert,{severity:"error",children:t.message})})}var F;const k=((F=window.blocklet)==null?void 0:F.prefix)||"/",L=Z.createAxios({timeout:200*1e3}),ge=window.location.protocol==="https:"?"wss":"ws",je=t=>C.joinURL(`${ge}://${window.location.hostname}`,k,`api/${t}/ws/pages`),ye="z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";var N;(N=blocklet==null?void 0:blocklet.componentMountPoints.find(t=>t.did===ye))!=null&&N.mountPoint||C.joinURL(k,"/image-bin");function Ce(t){return t&&!/^(https?:\/\/|\/)/.test(t)?window.location.origin+C.joinURL(k,"uploads",t):t}const be=window.innerWidth<=750;function he(t,n,i){if(!t||/\.gif/.test(t))return t;const S=(be?n/1.5:n)*(i==="quality"?1.5:1);return ve(t,{imageFilter:"resize",w:S,f:"webp"})}function ve(t,n){return!t||!n?t:C.withQuery(t,n)}async function xe(t){return L.get(`/api/projects/${t}`).then(n=>n.data)}async function Ee(t){return L.post(`/api/projects/${t.id}/update`,t).then(n=>n.data)}const Oe=500,E=ce.customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789",16),J=d.createContext(null);function _e({url:t,name:n,children:i,waitingSynced:S}){const[g,P]=d.useState(!1),{locale:j}=te.useLocaleContext(),w=A(),e=`${w}:MakerLocalState`,r=`${w}:${n}`,[s,o]=oe.useLocalStorageState(e,{defaultValue:{},listenStorageChange:!0}),c=d.useRef(s);c.current=s;const a=d.useMemo(()=>me.default({pages:{},pageIds:[],routes:{},routeIds:[],components:{},supportedLocales:[],config:{},resources:{}}),[]),l=d.useMemo(()=>V.getYjsDoc(a),[a]);d.useMemo(()=>new ie.IndexeddbPersistence(r,l),[r,l]);const p=d.useMemo(()=>new ae.WebsocketProvider(t,r,l,{params:{token:Se.default.get("login_token")},resyncInterval:5*60*1e3}),[t,r,l]),b=d.useCallback(()=>{p&&(p.disconnect(),p.connect())},[p]),y=d.useMemo(()=>new de.UndoManager([l.getArray("pageIds"),l.getMap("pages"),l.getArray("supportedLocales"),l.getMap("config")],{doc:l}),[l]),[h,v]=d.useState(null),[R,M]=d.useState(!1),[q,U]=d.useState(void 0),$=d.useCallback(async()=>{if(w){M(!0);try{const u=await xe(w);v(u)}catch(u){console.error("Failed to fetch project:",u)}finally{M(!1)}}},[w]),T=d.useCallback(async(u,f)=>{var I;if(U(void 0),!!w){f!=null&&f.optimisticUpdate&&h&&v(m=>({...m,...u}));try{const m=await Ee({...u});v(m)}catch(m){console.error("Failed to update project:",m),f!=null&&f.optimisticUpdate&&v(h),U((I=m==null?void 0:m.response)==null?void 0:I.data)}}},[w,h]);d.useEffect(()=>{w&&$()},[w,$]);const Y=d.useMemo(()=>({doc:l,state:a,localState:{...s,currentLocale:j},setLocalState:u=>o(typeof u=="function"?f=>u(f??{}):u),undoManager:y,projectState:{project:h,isLoadingProject:R,error:q},updateProject:T,forceSync:b}),[l,a,JSON.stringify(s),o,y,h,R,T,q,j,b]);return d.useEffect(()=>{y.on("stack-item-added",({stackItem:u})=>{const{currentPageId:f,currentLocale:I,pages:m}=c.current;u.meta.set("localState",{currentPageId:f,currentLocale:I,pages:m})}),y.on("stack-item-popped",({stackItem:u})=>{const f=u.meta.get("localState");f&&o(I=>({...I,...f}))})},[y,o]),d.useEffect(()=>{p.awareness.setLocalState(s)},[p,s]),d.useEffect(()=>{p.once("synced",()=>P(!0));const u=()=>{o(m=>({...m,networkStatus:void 0}))},f=()=>{o(m=>({...m,networkStatus:"offline"}))},I=G.default(({status:m})=>{m==="connected"?u():m==="disconnected"&&f()},Oe);return p.on("status",I),window.addEventListener("online",u),window.addEventListener("offline",f),()=>{p.off("status",I),window.removeEventListener("online",u),window.removeEventListener("offline",f)}},[p,o]),S&&!g?null:_.jsx(J.Provider,{value:Y,children:i})}const B=()=>{const t=d.useContext(J);if(!t)throw new Error("Context is null");const n=ne.useSyncedStore(t.state),{setLocalState:i,localState:S}=t,g=W.useNavigate(),P=A(),j=d.useMemo(()=>({setCurrentSectionId:(e,r)=>{var s,o;e===S.currentPageId&&r===((o=(s=S.pages)==null?void 0:s[e])==null?void 0:o.currentSectionId)||(g(C.joinURL("/admin/maker",P??"","pages",e)),i(c=>x.produce(c,a=>{var l;a.currentPageId=e,a.currentComponentId=void 0,a.customComponentPreviewerProperties={},r!==void 0&&(a.pages??(a.pages={}),(l=a.pages)[e]??(l[e]={}),a.pages[e].currentSectionId=r??void 0),r?window.sessionStorage.setItem("iframe_show_id",`"${r}"`):window.sessionStorage.removeItem("iframe_show_id")})))},setCurrentComponentId:e=>{e!==S.currentComponentId&&(g(C.joinURL("/admin/maker",P??"","components",e)),i(r=>x.produce(r,s=>{s.currentComponentId=e,s.customComponentPreviewerProperties={}})))},setCurrentRouteId:e=>{i(r=>x.produce(r,s=>{s.currentRouteId=e}))},setCustomComponentPreviewerProperties:(()=>{const e={},r=G.default(()=>{i(s=>x.produce(s,o=>{o.customComponentPreviewerProperties={...o==null?void 0:o.customComponentPreviewerProperties,...e},Object.keys(e).forEach(c=>delete e[c])}))},5);return s=>{Object.assign(e,s),r()}})()}),[i,g,P]),w=d.useMemo(()=>({addPage:(e,r)=>{var c,a,l,p,b,y;const s=(e==null?void 0:e.id)??E(),o={...e,id:s,createdAt:(e==null?void 0:e.createdAt)??new Date().toISOString(),updatedAt:(e==null?void 0:e.updatedAt)??new Date().toISOString(),publishedAt:new Date(0).toISOString(),slug:(e==null?void 0:e.slug)??`/${s}`,sections:(e==null?void 0:e.sections)??{},sectionIds:(e==null?void 0:e.sectionIds)??[],isPublic:(e==null?void 0:e.isPublic)??!0,templateConfig:(e==null?void 0:e.templateConfig)??{isTemplate:((c=e==null?void 0:e.templateConfig)==null?void 0:c.isTemplate)??!0,displayTemplateId:((a=e==null?void 0:e.templateConfig)==null?void 0:a.displayTemplateId)??void 0,dataSourceIds:((l=e==null?void 0:e.templateConfig)==null?void 0:l.dataSourceIds)??void 0,dataSourceParameters:((p=e==null?void 0:e.templateConfig)==null?void 0:p.dataSourceParameters)??{},enabledGenerate:((b=e==null?void 0:e.templateConfig)==null?void 0:b.enabledGenerate)??!1,agentId:((y=e==null?void 0:e.templateConfig)==null?void 0:y.agentId)??void 0}};return t.doc.transact(()=>{n.pages[o.id]=o,n.pageIds.splice(r??n.pageIds.length,0,o.id)}),o},addRoute:(e,r)=>{const s=(e==null?void 0:e.id)??E(),o={...e,id:s,createdAt:(e==null?void 0:e.createdAt)??new Date().toISOString(),updatedAt:(e==null?void 0:e.updatedAt)??new Date().toISOString(),publishedAt:new Date(0).toISOString(),path:(e==null?void 0:e.path)??`/${s}`,handler:(e==null?void 0:e.handler)??"Pages Kit",isPublic:(e==null?void 0:e.isPublic)??!0,params:(e==null?void 0:e.params)??[],enabledGenerate:(e==null?void 0:e.enabledGenerate)??!1,displayTemplateId:(e==null?void 0:e.displayTemplateId)??void 0,dataSource:(e==null?void 0:e.dataSource)??{}};return t.doc.transact(()=>{n.routes??(n.routes={}),n.routeIds??(n.routeIds=[]),n.routes[o.id]=o,n.routeIds.splice(r??n.routeIds.length,0,o.id)}),o},deleteRoute:e=>{var s;if(!e)return;const r=(s=n.routeIds)==null?void 0:s.indexOf(e);r!==void 0&&r!==-1&&t.doc.transact(()=>{var o,c;(o=n.routeIds)==null||o.splice(r,1),(c=n.routes)==null||delete c[e]})},deletePage:e=>{const r=n.pageIds.indexOf(e);r!==-1&&t.doc.transact(()=>{n.pageIds.splice(r,1),delete n.pages[e]})},movePage:(e,r)=>{const{pageIds:s}=n,o=s.indexOf(e);o>=0&&s.splice(r,0,...s.splice(o,1))},addSection:(e,r,s)=>{const o=n.pages[e];if(!o)throw new Error(`Page ${e} is not exists`);const c={...r,id:r.id??E(),isTemplateSection:r.isTemplateSection??!0,llmConfig:r.llmConfig??{}};return t.doc.transact(()=>{o.sections[c.id]=c,o.sectionIds.splice(s??o.sectionIds.length,0,c.id)}),c},deleteSection:(e,r)=>{const s=n.pages[e];if(!s)throw new Error(`Page ${e} is not exists`);const o=s.sectionIds.indexOf(r);o!==-1&&t.doc.transact(()=>{s.sectionIds.splice(o,1),delete s.sections[r]})},toggleSectionVisibility:(e,r,s)=>{const o=n.pages[e];if(!o)throw new Error(`Page ${e} is not exists`);const c=o.sections[r];c&&(c.visibility=s)},moveSection:(e,r,s)=>{const o=n.pages[e];if(!o)throw new Error(`Page ${e} is not exists`);const{sectionIds:c}=o,a=c.indexOf(r);a>=0&&c.splice(s,0,...c.splice(a,1))}}),[n,t.doc]);return{...t,state:n,actions:w,localActions:j,get currentPage(){const{localState:{currentPageId:e}}=t;return e?n.pages[e]:void 0},get currentSection(){var o,c,a;const{localState:{currentPageId:e,...r}}=t;if(!e)return;const s=(c=(o=r.pages)==null?void 0:o[e])==null?void 0:c.currentSectionId;if(s)return(a=n.pages[e])==null?void 0:a.sections[s]},get currentRoute(){var r;const{localState:{currentRouteId:e}}=t;return e?(r=n.routes)==null?void 0:r[e]:void 0}}},A=()=>{const{projectId:t}=W.useParams();return t??z()??""};function K(t){var S,g;const{resources:n}=t;if(!n.components)return{};const i={};return(g=(S=window==null?void 0:window.blocklet)==null?void 0:S.componentMountPoints)==null||g.forEach(P=>{i[P.did]=P}),Object.fromEntries(Object.entries(n.components).map(([P,{blockletId:j,component:w}])=>{var e;return[P,{data:w,blockletId:j,blockletTitle:((e=i[j])==null?void 0:e.title)||j}]}))}function Q(t){const{components:n}=t;return n||{}}function X(t){return{...K(t),...Q(t)}}const ke=()=>X(B().state);exports.ErrorView=Ie;exports.StoreProvider=_e;exports.api=L;exports.autoResizeImage=he;exports.getAllComponents=X;exports.getCustomComponents=Q;exports.getImageAbsoluteUrl=Ce;exports.getMountPoint=we;exports.getProjectIdFromPathnameOrWindow=z;exports.getProjectPageVersionKey=pe;exports.getResourceComponents=K;exports.getWssURL=je;exports.nextId=E;exports.transformValue=Pe;exports.useAllComponents=ke;exports.useProjectId=A;exports.useStore=B;
@@ -1,437 +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 j, 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 tt } from "@syncedstore/core";
9
- import { useSyncedStore as et } from "@syncedstore/react";
10
- import { useLocalStorageState as nt } from "ahooks";
11
- import { produce as x } from "immer";
12
- import ot from "js-cookie";
13
- import G from "lodash/debounce";
14
- import { customAlphabet as rt } from "nanoid";
15
- import { createContext as st, useState as E, useRef as it, useMemo as v, useCallback as k, useEffect as O, useContext as ct } from "react";
16
- import { useParams as at, useNavigate as dt } from "react-router-dom";
17
- import { IndexeddbPersistence as lt } from "y-indexeddb";
18
- import { WebsocketProvider as mt } from "y-websocket";
19
- import { UndoManager as ft } from "yjs";
20
- import "@blocklet/pages-kit/types";
21
- const Vt = (e) => {
22
- const n = blocklet == null ? void 0 : blocklet.componentMountPoints.find((l) => l.name === e);
23
- return n ? n.mountPoint : "/";
24
- };
25
- function ut() {
26
- const { pathname: e } = window.location, n = e.match(/\/admin\/(maker|previewer)\/([^/]+)/), l = n == null ? void 0 : n[2], u = window.__PROJECT_ID__;
27
- if (!l && !u)
28
- throw new Error("Unable to get projectId from pathname");
29
- return l || u;
30
- }
31
- function Wt(e) {
32
- return `${e}:pages:version`;
33
- }
34
- function zt(e, n) {
35
- return n === "yaml" ? X(e) ? "" : Y.stringify(e, { indent: 2 }) : n === "json" ? JSON.parse(JSON.stringify(e || {})) : n === "array" ? JSON.parse(JSON.stringify(e || [])) : e;
36
- }
37
- function Kt({ error: e }) {
38
- return /* @__PURE__ */ L(z, { children: /* @__PURE__ */ L(K, { severity: "error", children: e.message }) });
39
- }
40
- var F;
41
- const $ = ((F = window.blocklet) == null ? void 0 : F.prefix) || "/", J = Q({
42
- timeout: 200 * 1e3
43
- }), pt = window.location.protocol === "https:" ? "wss" : "ws", qt = (e) => j(`${pt}://${window.location.hostname}`, $, `api/${e}/ws/pages`), wt = "z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";
44
- var N;
45
- (N = blocklet == null ? void 0 : blocklet.componentMountPoints.find((e) => e.did === wt)) != null && N.mountPoint || j($, "/image-bin");
46
- function Qt(e) {
47
- return e && !/^(https?:\/\/|\/)/.test(e) ? window.location.origin + j($, "uploads", e) : e;
48
- }
49
- const St = window.innerWidth <= 750;
50
- function Xt(e, n, l) {
51
- if (!e || /\.gif/.test(e)) return e;
52
- const u = (St ? n / 1.5 : n) * (l === "quality" ? 1.5 : 1);
53
- return Pt(e, { imageFilter: "resize", w: u, f: "webp" });
54
- }
55
- function Pt(e, n) {
56
- return !e || !n ? e : q(e, n);
57
- }
58
- async function It(e) {
59
- return J.get(`/api/projects/${e}`).then((n) => n.data);
60
- }
61
- async function ht(e) {
62
- return J.post(`/api/projects/${e.id}/update`, e).then((n) => n.data);
63
- }
64
- const yt = 500, A = rt("abcdefghijklmnopqrstuvwxyz0123456789", 16), B = st(null);
65
- function Yt({
66
- url: e,
67
- name: n,
68
- children: l,
69
- waitingSynced: u
70
- }) {
71
- const [I, S] = E(!1), { locale: h } = Z(), p = V(), t = `${p}:MakerLocalState`, r = `${p}:${n}`, [s, o] = nt(t, {
72
- defaultValue: {},
73
- listenStorageChange: !0
74
- }), i = it(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
- ), a = v(() => tt(c), [c]);
89
- v(() => new lt(r, a), [r, a]);
90
- const w = v(
91
- () => new mt(e, r, a, {
92
- params: { token: ot.get("login_token") },
93
- resyncInterval: 5 * 60 * 1e3
94
- }),
95
- [e, r, a]
96
- ), C = k(() => {
97
- w && (w.disconnect(), w.connect());
98
- }, [w]), y = v(
99
- () => new ft(
100
- [a.getArray("pageIds"), a.getMap("pages"), a.getArray("supportedLocales"), a.getMap("config")],
101
- { doc: a }
102
- ),
103
- [a]
104
- ), [g, b] = E(null), [R, T] = E(!1), [_, D] = E(void 0), M = k(async () => {
105
- if (p) {
106
- T(!0);
107
- try {
108
- const d = await It(p);
109
- b(d);
110
- } catch (d) {
111
- console.error("Failed to fetch project:", d);
112
- } finally {
113
- T(!1);
114
- }
115
- }
116
- }, [p]), U = k(
117
- async (d, m) => {
118
- var P;
119
- if (D(void 0), !!p) {
120
- m != null && m.optimisticUpdate && g && b((f) => ({
121
- ...f,
122
- ...d
123
- }));
124
- try {
125
- const f = await ht({
126
- ...d
127
- });
128
- b(f);
129
- } catch (f) {
130
- console.error("Failed to update project:", f), m != null && m.optimisticUpdate && b(g), D((P = f == null ? void 0 : f.response) == null ? void 0 : P.data);
131
- }
132
- }
133
- },
134
- [p, g]
135
- );
136
- O(() => {
137
- p && M();
138
- }, [p, M]);
139
- const W = v(
140
- () => ({
141
- doc: a,
142
- state: c,
143
- localState: {
144
- ...s,
145
- // always use the locale from the context
146
- currentLocale: h
147
- },
148
- setLocalState: (d) => o(typeof d == "function" ? (m) => d(m ?? {}) : d),
149
- undoManager: y,
150
- projectState: {
151
- project: g,
152
- isLoadingProject: R,
153
- error: _
154
- },
155
- updateProject: U,
156
- forceSync: C
157
- }),
158
- // eslint-disable-next-line react-hooks/exhaustive-deps
159
- [
160
- a,
161
- c,
162
- JSON.stringify(s),
163
- // resolve the problem of react warning
164
- o,
165
- y,
166
- g,
167
- R,
168
- U,
169
- _,
170
- h,
171
- C
172
- ]
173
- );
174
- return O(() => {
175
- y.on("stack-item-added", ({ stackItem: d }) => {
176
- const { currentPageId: m, currentLocale: P, pages: f } = i.current;
177
- d.meta.set("localState", { currentPageId: m, currentLocale: P, pages: f });
178
- }), y.on("stack-item-popped", ({ stackItem: d }) => {
179
- const m = d.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 d = () => {
187
- o((f) => ({
188
- ...f,
189
- networkStatus: void 0
190
- }));
191
- }, m = () => {
192
- o((f) => ({
193
- ...f,
194
- networkStatus: "offline"
195
- }));
196
- }, P = G(({ status: f }) => {
197
- f === "connected" ? d() : f === "disconnected" && m();
198
- }, yt);
199
- return w.on("status", P), window.addEventListener("online", d), window.addEventListener("offline", m), () => {
200
- w.off("status", P), window.removeEventListener("online", d), window.removeEventListener("offline", m);
201
- };
202
- }, [w, o]), u && !I ? null : /* @__PURE__ */ L(B.Provider, { value: W, children: l });
203
- }
204
- const vt = () => {
205
- const e = ct(B);
206
- if (!e)
207
- throw new Error("Context is null");
208
- const n = et(e.state), { setLocalState: l, localState: u } = e, I = dt(), S = V(), h = v(
209
- () => ({
210
- setCurrentSectionId: (t, r) => {
211
- var s, o;
212
- t === u.currentPageId && r === ((o = (s = u.pages) == null ? void 0 : s[t]) == null ? void 0 : o.currentSectionId) || (I(j("/admin/maker", S ?? "", "pages", t)), l(
213
- (i) => x(i, (c) => {
214
- var a;
215
- c.currentPageId = t, c.currentComponentId = void 0, c.customComponentPreviewerProperties = {}, r !== void 0 && (c.pages ?? (c.pages = {}), (a = c.pages)[t] ?? (a[t] = {}), c.pages[t].currentSectionId = r ?? void 0), r ? window.sessionStorage.setItem("iframe_show_id", `"${r}"`) : window.sessionStorage.removeItem("iframe_show_id");
216
- })
217
- ));
218
- },
219
- setCurrentComponentId: (t) => {
220
- t !== u.currentComponentId && (I(j("/admin/maker", S ?? "", "components", t)), l(
221
- (r) => x(r, (s) => {
222
- s.currentComponentId = t, s.customComponentPreviewerProperties = {};
223
- })
224
- ));
225
- },
226
- setCurrentRouteId: (t) => {
227
- l(
228
- (r) => x(r, (s) => {
229
- s.currentRouteId = t;
230
- })
231
- );
232
- },
233
- setCustomComponentPreviewerProperties: (() => {
234
- const t = {}, r = G(() => {
235
- l(
236
- (s) => x(s, (o) => {
237
- o.customComponentPreviewerProperties = {
238
- ...o == null ? void 0 : o.customComponentPreviewerProperties,
239
- ...t
240
- }, Object.keys(t).forEach((i) => delete t[i]);
241
- })
242
- );
243
- }, 5);
244
- return (s) => {
245
- Object.assign(t, s), r();
246
- };
247
- })()
248
- }),
249
- [l, I, S]
250
- ), p = v(
251
- () => ({
252
- addPage: (t, r) => {
253
- var i, c, a, w, C, y;
254
- const s = (t == null ? void 0 : t.id) ?? A(), o = {
255
- ...t,
256
- id: s,
257
- createdAt: (t == null ? void 0 : t.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
258
- updatedAt: (t == null ? void 0 : t.updatedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
259
- publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
260
- slug: (t == null ? void 0 : t.slug) ?? `/${s}`,
261
- sections: (t == null ? void 0 : t.sections) ?? {},
262
- sectionIds: (t == null ? void 0 : t.sectionIds) ?? [],
263
- isPublic: (t == null ? void 0 : t.isPublic) ?? !0,
264
- templateConfig: (t == null ? void 0 : t.templateConfig) ?? {
265
- isTemplate: ((i = t == null ? void 0 : t.templateConfig) == null ? void 0 : i.isTemplate) ?? !0,
266
- displayTemplateId: ((c = t == null ? void 0 : t.templateConfig) == null ? void 0 : c.displayTemplateId) ?? void 0,
267
- dataSourceIds: ((a = t == null ? void 0 : t.templateConfig) == null ? void 0 : a.dataSourceIds) ?? void 0,
268
- dataSourceParameters: ((w = t == null ? void 0 : t.templateConfig) == null ? void 0 : w.dataSourceParameters) ?? {},
269
- enabledGenerate: ((C = t == null ? void 0 : t.templateConfig) == null ? void 0 : C.enabledGenerate) ?? !1,
270
- agentId: ((y = t == null ? void 0 : t.templateConfig) == null ? void 0 : y.agentId) ?? void 0
271
- }
272
- };
273
- return e.doc.transact(() => {
274
- n.pages[o.id] = o, n.pageIds.splice(r ?? n.pageIds.length, 0, o.id);
275
- }), o;
276
- },
277
- addRoute: (t, r) => {
278
- const s = (t == null ? void 0 : t.id) ?? A(), o = {
279
- ...t,
280
- id: s,
281
- createdAt: (t == null ? void 0 : t.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
282
- updatedAt: (t == null ? void 0 : t.updatedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
283
- publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
284
- path: (t == null ? void 0 : t.path) ?? `/${s}`,
285
- handler: (t == null ? void 0 : t.handler) ?? "Pages Kit",
286
- isPublic: (t == null ? void 0 : t.isPublic) ?? !0,
287
- params: (t == null ? void 0 : t.params) ?? [],
288
- enabledGenerate: (t == null ? void 0 : t.enabledGenerate) ?? !1,
289
- displayTemplateId: (t == null ? void 0 : t.displayTemplateId) ?? void 0,
290
- dataSource: (t == null ? void 0 : t.dataSource) ?? {}
291
- };
292
- return e.doc.transact(() => {
293
- n.routes ?? (n.routes = {}), n.routeIds ?? (n.routeIds = []), n.routes[o.id] = o, n.routeIds.splice(r ?? n.routeIds.length, 0, o.id);
294
- }), o;
295
- },
296
- deleteRoute: (t) => {
297
- var s;
298
- if (!t)
299
- return;
300
- const r = (s = n.routeIds) == null ? void 0 : s.indexOf(t);
301
- r !== void 0 && r !== -1 && e.doc.transact(() => {
302
- var o, i;
303
- (o = n.routeIds) == null || o.splice(r, 1), (i = n.routes) == null || delete i[t];
304
- });
305
- },
306
- deletePage: (t) => {
307
- const r = n.pageIds.indexOf(t);
308
- r !== -1 && e.doc.transact(() => {
309
- n.pageIds.splice(r, 1), delete n.pages[t];
310
- });
311
- },
312
- movePage: (t, r) => {
313
- const { pageIds: s } = n, o = s.indexOf(t);
314
- o >= 0 && s.splice(r, 0, ...s.splice(o, 1));
315
- },
316
- addSection: (t, r, s) => {
317
- const o = n.pages[t];
318
- if (!o)
319
- throw new Error(`Page ${t} is not exists`);
320
- const i = {
321
- ...r,
322
- id: r.id ?? A(),
323
- isTemplateSection: r.isTemplateSection ?? !0,
324
- llmConfig: r.llmConfig ?? {}
325
- };
326
- return e.doc.transact(() => {
327
- o.sections[i.id] = i, o.sectionIds.splice(s ?? o.sectionIds.length, 0, i.id);
328
- }), i;
329
- },
330
- deleteSection: (t, r) => {
331
- const s = n.pages[t];
332
- if (!s)
333
- throw new Error(`Page ${t} is not exists`);
334
- const o = s.sectionIds.indexOf(r);
335
- o !== -1 && e.doc.transact(() => {
336
- s.sectionIds.splice(o, 1), delete s.sections[r];
337
- });
338
- },
339
- toggleSectionVisibility: (t, r, s) => {
340
- const o = n.pages[t];
341
- if (!o)
342
- throw new Error(`Page ${t} is not exists`);
343
- const i = o.sections[r];
344
- i && (i.visibility = s);
345
- },
346
- moveSection: (t, r, s) => {
347
- const o = n.pages[t];
348
- if (!o)
349
- throw new Error(`Page ${t} is not exists`);
350
- const { sectionIds: i } = o, c = i.indexOf(r);
351
- c >= 0 && i.splice(s, 0, ...i.splice(c, 1));
352
- }
353
- }),
354
- [n, e.doc]
355
- );
356
- return {
357
- ...e,
358
- state: n,
359
- actions: p,
360
- localActions: h,
361
- get currentPage() {
362
- const {
363
- localState: { currentPageId: t }
364
- } = e;
365
- return t ? n.pages[t] : void 0;
366
- },
367
- get currentSection() {
368
- var o, i, c;
369
- const {
370
- localState: { currentPageId: t, ...r }
371
- } = e;
372
- if (!t)
373
- return;
374
- const s = (i = (o = r.pages) == null ? void 0 : o[t]) == null ? void 0 : i.currentSectionId;
375
- if (s)
376
- return (c = n.pages[t]) == null ? void 0 : c.sections[s];
377
- },
378
- get currentRoute() {
379
- var r;
380
- const {
381
- localState: { currentRouteId: t }
382
- } = e;
383
- return t ? (r = n.routes) == null ? void 0 : r[t] : void 0;
384
- }
385
- };
386
- }, V = () => {
387
- const { projectId: e } = at();
388
- return e ?? ut() ?? "";
389
- };
390
- function Ct(e) {
391
- var u, I;
392
- const { resources: n } = e;
393
- if (!n.components)
394
- return {};
395
- const l = {};
396
- return (I = (u = window == null ? void 0 : window.blocklet) == null ? void 0 : u.componentMountPoints) == null || I.forEach((S) => {
397
- l[S.did] = S;
398
- }), Object.fromEntries(
399
- Object.entries(n.components).map(([S, { blockletId: h, component: p }]) => {
400
- var t;
401
- return [
402
- S,
403
- { data: p, blockletId: h, blockletTitle: ((t = l[h]) == null ? void 0 : t.title) || h }
404
- ];
405
- })
406
- );
407
- }
408
- function gt(e) {
409
- const { components: n } = e;
410
- return n || {};
411
- }
412
- function jt(e) {
413
- return {
414
- ...Ct(e),
415
- ...gt(e)
416
- };
417
- }
418
- const Zt = () => jt(vt().state);
419
- export {
420
- Kt as E,
421
- Yt as S,
422
- qt as a,
423
- vt as b,
424
- Wt as c,
425
- jt as d,
426
- Xt as e,
427
- Zt as f,
428
- Qt as g,
429
- J as h,
430
- Vt as i,
431
- gt as j,
432
- Ct as k,
433
- ut as l,
434
- A as n,
435
- zt as t,
436
- V as u
437
- };