@blocklet/pages-kit-inner-components 0.6.50 → 0.6.52

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.6.50",
3
+ "version": "0.6.52",
4
4
  "description": "Pages Kit inner components library",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -69,11 +69,11 @@
69
69
  "url": "git+https://github.com/blocklet/pages-kit.git"
70
70
  },
71
71
  "dependencies": {
72
- "@arcblock/did-connect-react": "^3.1.18",
72
+ "@arcblock/did-connect-react": "^3.1.21",
73
73
  "@arcblock/did-connect-storage-nedb": "^1.8.0",
74
- "@arcblock/react-hooks": "^3.1.18",
75
- "@arcblock/ux": "^3.1.18",
76
- "@blocklet/aigne-hub": "^0.3.12",
74
+ "@arcblock/react-hooks": "^3.1.21",
75
+ "@arcblock/ux": "^3.1.21",
76
+ "@blocklet/aigne-hub": "^0.3.13",
77
77
  "@blocklet/code-editor": "^0.5.6",
78
78
  "@blocklet/embed": "^0.2.5",
79
79
  "@blocklet/js-sdk": "^1.16.48",
@@ -82,9 +82,9 @@
82
82
  "@blocklet/sdk": "^1.16.48",
83
83
  "@blocklet/studio-ui": "^0.5.6",
84
84
  "@blocklet/tracker": "^1.16.48",
85
- "@blocklet/ui-react": "^3.1.18",
85
+ "@blocklet/ui-react": "^3.1.21",
86
86
  "@blocklet/uploader": "^0.2.7",
87
- "@blocklet/uploader-server": "^0.2.5",
87
+ "@blocklet/uploader-server": "^0.2.7",
88
88
  "@emotion/cache": "^11.14.0",
89
89
  "@emotion/css": "^11.13.5",
90
90
  "@emotion/react": "^11.14.0",
@@ -160,8 +160,6 @@
160
160
  "prettier": "^3.3.3",
161
161
  "react": "^19.1.0",
162
162
  "react-best-gradient-color-picker": "^3.0.14",
163
- "react-dnd": "^16.0.1",
164
- "react-dnd-html5-backend": "^16.0.1",
165
163
  "react-dom": "^19.1.0",
166
164
  "react-error-boundary": "^4.0.13",
167
165
  "react-frame-component": "^5.2.7",
@@ -201,8 +199,8 @@
201
199
  "yaml": "^2.5.0",
202
200
  "yjs": "^13.6.18",
203
201
  "zustand": "^4.5.5",
204
- "@blocklet/pages-kit": "^0.6.50",
205
- "@blocklet/pages-kit-block-studio": "^0.6.50"
202
+ "@blocklet/pages-kit": "^0.6.52",
203
+ "@blocklet/pages-kit-block-studio": "^0.6.52"
206
204
  },
207
205
  "devDependencies": {
208
206
  "@trivago/prettier-plugin-sort-imports": "^5.2.1",
@@ -1 +0,0 @@
1
- "use strict";const X=require("react/jsx-runtime"),x=require("ufo"),Y=require("@blocklet/js-sdk"),Z=require("lodash/isEmpty"),H=require("yaml"),ee=require("@arcblock/ux/lib/Locale/context"),E=require("@blocklet/pages-kit/utils/common"),te=require("@blocklet/pages-kit/utils/page-model");require("@mui/material");const T=require("@syncedstore/core"),oe=require("@syncedstore/react"),ne=require("ahooks"),M=require("immer"),re=require("lodash/cloneDeep"),se=require("lodash/debounce"),f=require("react"),U=require("react-router-dom"),ce=require("y-indexeddb"),ie=require("y-websocket"),ae=require("yjs");require("@blocklet/pages-kit/types");const A=o=>o&&o.__esModule?o:{default:o};function de(o){if(o&&o.__esModule)return o;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const u in o)if(u!=="default"){const l=Object.getOwnPropertyDescriptor(o,u);Object.defineProperty(n,u,l.get?l:{enumerable:!0,get:()=>o[u]})}}return n.default=o,Object.freeze(n)}const ue=A(Z),le=de(H),fe=A(T),J=A(re),G=A(se);function B(){const{pathname:o}=window.location,u=o.match(/\/admin\/(maker|previewer)\/([^/]+)/)?.[2],l=window.__PROJECT_ID__;if(!u&&!l)throw new Error("Unable to get projectId from pathname");return u||l}function ge(o){return`${o}:pages:version`}function pe(o,n){return n==="yaml"?ue.default(o)?"":le.stringify(o,{indent:2}):n==="json"?JSON.parse(JSON.stringify(o||{})):n==="array"?JSON.parse(JSON.stringify(o||[])):o}const D=window.blocklet?.prefix||"/",q=Y.createAxios({timeout:200*1e3}),me=window.location.protocol==="https:"?"wss":"ws",Se=o=>x.joinURL(`${me}://${window.location.hostname}`,D,`api/${o}/ws/pages`),Pe="z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";blocklet?.componentMountPoints.find(o=>o.did===Pe)?.mountPoint||x.joinURL(D,"/image-bin");function Ie(o){return o&&!/^(https?:\/\/|\/)/.test(o)?window.location.origin+x.joinURL(D,"uploads",o):o}const we=window.innerWidth<=750;function ye(o,n,u){if(!o||/\.gif/.test(o))return o;const l=(we?n/1.5:n)*(u==="quality"?1.5:1);return he(o,{imageFilter:"resize",w:l,f:"webp"})}function he(o,n){return!o||!n?o:x.withQuery(o,n)}async function Ce(o){return q.get(`/api/projects/${o}`).then(n=>n.data)}async function be(o){return q.post(`/api/projects/${o.id}/update`,o).then(n=>n.data)}const je=500,F=f.createContext(null);function ve({url:o,name:n,children:u,waitingSynced:l}){const[y,m]=f.useState(!1),{locale:g}=ee.useLocaleContext(),S=$(),v=`${S}:MakerLocalState`,e=`${S}:${n}`,[t,s]=ne.useLocalStorageState(v,{defaultValue:{},listenStorageChange:!0}),r=f.useRef(t);r.current=t;const a=f.useMemo(()=>fe.default({dataSourceIds:[],dataSources:{},pages:{},pageIds:[],routes:{},routeIds:[],components:{},supportedLocales:[],config:{},resources:{}}),[]),c=f.useMemo(()=>T.getYjsDoc(a),[a]);f.useMemo(()=>new ce.IndexeddbPersistence(e,c),[e,c]);const i=f.useMemo(()=>new ie.WebsocketProvider(o,e,c,{params:{},resyncInterval:5*60*1e3}),[o,e,c]),d=f.useCallback(()=>{i&&(i.disconnect(),i.connect())},[i]),P=f.useMemo(()=>new ae.UndoManager([c.getArray("pageIds"),c.getMap("pages"),c.getArray("supportedLocales"),c.getMap("config"),c.getMap("dataSources"),c.getArray("dataSourceIds"),c.getArray("routeIds"),c.getMap("routes")],{doc:c}),[c]),[h,b]=f.useState(null),[_,k]=f.useState(!1),[L,R]=f.useState(void 0),j=f.useCallback(async()=>{if(S){k(!0);try{const p=await Ce(S);b(p)}catch(p){console.error("Failed to fetch project:",p)}finally{k(!1)}}},[S]),O=f.useCallback(async(p,I)=>{if(R(void 0),!!S){I?.optimisticUpdate&&h&&b(w=>({...w,...p}));try{const w=await be({...p});b(w)}catch(w){console.error("Failed to update project:",w),I?.optimisticUpdate&&b(h),R(w?.response?.data)}}},[S,h]);f.useEffect(()=>{S&&j()},[S,j]);const N=f.useMemo(()=>({doc:c,state:a,localState:{...t,currentLocale:g},setLocalState:p=>s(typeof p=="function"?I=>p(I??{}):p),undoManager:P,projectState:{project:h,isLoadingProject:_,error:L},updateProject:O,forceSync:d}),[c,a,JSON.stringify(t),s,P,h,_,O,L,g,d]);return f.useEffect(()=>{P.on("stack-item-added",({stackItem:p})=>{const{currentPageId:I,currentLocale:w,pages:C}=r.current;p.meta.set("localState",{currentPageId:I,currentLocale:w,pages:C})}),P.on("stack-item-popped",({stackItem:p})=>{const I=p.meta.get("localState");I&&s(w=>({...w,...I}))})},[P,s]),f.useEffect(()=>{i.awareness.setLocalState(t)},[i,t]),f.useEffect(()=>{i.once("synced",()=>m(!0));const p=()=>{s(C=>({...C,networkStatus:void 0}))},I=()=>{s(C=>({...C,networkStatus:"offline"}))},w=G.default(({status:C})=>{C==="connected"?p():C==="disconnected"&&I()},je);return i.on("status",w),window.addEventListener("online",p),window.addEventListener("offline",I),()=>{i.off("status",w),window.removeEventListener("online",p),window.removeEventListener("offline",I)}},[i,s]),l&&!y?null:X.jsx(F.Provider,{value:N,children:u})}const W=()=>{const o=f.useContext(F);if(!o)throw new Error("Context is null");const n=oe.useSyncedStore(o.state),{setLocalState:u,localState:l}=o,y=U.useNavigate(),m=$(),g=f.useMemo(()=>({get currentPage(){const{localState:{currentPageId:e}}=o;return e?n.pages[e]:void 0},get currentSection(){const{localState:{currentPageId:e,...t}}=o;if(!e)return;const s=t.pages?.[e]?.currentSectionId;if(s)return n.pages[e]?.sections[s]??this.currentPageModel?.getComponentById(s)?.model},get currentSectionProperties(){const{localState:{currentPageId:e,...t}}=o;if(!e)return;const s=t.pages?.[e]?.currentSectionId;if(!s)return;const r=n.pages[e]?.dataSource?.[s];if(!r)return;const{currentLocale:a}=this.currentLocaleMap;return a?r[a]:void 0},get currentSectionPropertiesWithFallback(){const{localState:{currentPageId:e,...t}}=o;if(!e)return;const s=t.pages?.[e]?.currentSectionId;if(!s)return;const r=n.pages[e]?.dataSource?.[s];if(!r)return;const{currentLocale:a,defaultLocale:c,fallbackLocale:i}=this.currentLocaleMap;if(a&&r[a])return r[a];if(c&&r[c])return r[c];if(i&&r[i])return r[i]},get currentLocaleMap(){const{localState:{currentLocale:e},state:{supportedLocales:t,config:{defaultLocale:s}}}=o;return{currentLocale:e,defaultLocale:s,fallbackLocale:t?.[0]?.locale??"en"}},get currentRoute(){const{localState:{currentRouteId:e}}=o;return e?n.routes?.[e]:void 0},get currentPageModel(){const e=this.currentPage??null;if(e)return te.getPageTemplateModel(e,!1)}}),[JSON.stringify(l),n]),S=f.useMemo(()=>({setCurrentSectionId:(e,t)=>{e===l.currentPageId&&t===l.pages?.[e]?.currentSectionId||(y(x.joinURL("/admin/maker",m??"","pages",e)),u(s=>M.produce(s,r=>{r.currentPageId=e,r.currentComponentId=void 0,t!==void 0&&(r.pages??={},r.pages[e]??={},r.pages[e].currentSectionId=t??void 0),t?window.sessionStorage.setItem("iframe_show_id",`"${t}"`):window.sessionStorage.removeItem("iframe_show_id")})))},setCurrentComponentId:e=>{e!==l.currentComponentId&&(y(x.joinURL("/admin/maker",m??"","components",e)),u(t=>M.produce(t,s=>{s.currentComponentId=e})))},setCurrentRouteId:({routeId:e,dynamicParams:t})=>{u(s=>M.produce(s,r=>{r.currentRouteId=e,r.currentDynamicParams=t}))},setCustomComponentPreviewerProperties:(()=>{const e={};let t="";const s=G.default(()=>{u(r=>M.produce(r,a=>{a.customComponentPreviewerProperties??={},a.customComponentPreviewerProperties[t]={...a.customComponentPreviewerProperties[t],...J.default(e[t])},delete e[t]}))},5);return(r,a)=>{const c=e[r]??{};Object.assign(c,a),e[r]=c,t=r,s()}})(),setRouteGenerateProcess:e=>{u(t=>M.produce(t,s=>{e?s.routeGenerateProcess={...s.routeGenerateProcess,...e}:s.routeGenerateProcess={}}))},resetRouteGenerateProcess:()=>{u(e=>M.produce(e,t=>{t.routeGenerateProcess={progress:"complete"}}))}}),[u,y,m,g]),v=f.useMemo(()=>({addPage:(e,t)=>{const s=e?.id??E.nextId(),r={...e,id:s,createdAt:e?.createdAt??new Date().toISOString(),updatedAt:e?.updatedAt??new Date().toISOString(),publishedAt:new Date(0).toISOString(),slug:e?.slug??`/${s}`,sections:e?.sections??{},sectionIds:e?.sectionIds??[],isPublic:e?.isPublic??!0,templateConfig:e?.templateConfig??{isTemplate:e?.templateConfig?.isTemplate??!0,displayTemplateId:e?.templateConfig?.displayTemplateId??void 0,dataSourceIds:e?.templateConfig?.dataSourceIds??void 0,dataSourceParameters:e?.templateConfig?.dataSourceParameters??{},enabledGenerate:e?.templateConfig?.enabledGenerate??!1,agentId:e?.templateConfig?.agentId??void 0}};return o.doc.transact(()=>{n.pages[r.id]=r,n.pageIds.splice(t??n.pageIds.length,0,r.id)}),r},addRoute:(e,t)=>{const s=e?.id??E.nextId(),r={...e,id:s,createdAt:e?.createdAt??new Date().toISOString(),updatedAt:e?.updatedAt??new Date().toISOString(),publishedAt:new Date(0).toISOString(),path:e?.path??`/${s}`,handler:e?.handler??"Pages Kit",isPublic:e?.isPublic??!0,params:e?.params??[],enabledGenerate:e?.enabledGenerate??!1,displayTemplateId:e?.displayTemplateId??void 0,dataSource:e?.dataSource??{}};return o.doc.transact(()=>{n.routes??={},n.routeIds??=[],n.routes[r.id]=r,n.routeIds.splice(t??n.routeIds.length,0,r.id)}),r},deleteRoute:e=>{if(!e)return;const t=n.routeIds?.indexOf(e);t!==void 0&&t!==-1&&o.doc.transact(()=>{n.routeIds?.splice(t,1),delete n.routes?.[e]})},deletePage:e=>{const t=n.pageIds.indexOf(e);t!==-1&&o.doc.transact(()=>{n.pageIds.splice(t,1),delete n.pages[e]})},movePage:(e,t)=>{const{pageIds:s}=n,r=s.indexOf(e);r>=0&&s.splice(t,0,...s.splice(r,1))},addSection:(e,t,s,r)=>{const a=n.pages[e];if(!a)throw new Error(`Page ${e} is not exists`);const c={...t,id:t.id??E.nextId(),isTemplateSection:t.isTemplateSection??!0,llmConfig:t.llmConfig??{}},i=J.default(c.locales);return delete c.locales,o.doc.transact(()=>{if(r&&r.component==="layout-block"){const d=g.currentPageModel?.getComponentById(r.id);d&&(d.model.sections??={},d.model.sections[c.id]=c,d.model.sectionIds??=[],d.model.sectionIds.push(c.id))}else a.sections[c.id]=c,a.sectionIds.splice(s??a.sectionIds.length,0,c.id);i&&(a.dataSource??={},a.dataSource[c.id]=i)}),c},deleteSection:(e,t)=>{const s=n.pages[e];if(!s)throw new Error(`Page ${e} is not exists`);o.doc.transact(()=>{const r=[],a=g.currentPageModel?.getComponentById(t),c=a?.parent;if(a&&(r.push(a.model.id,...a.all().map(i=>i.model.id)),c?.model.component==="layout-block")){const i=c.model.sectionIds?.indexOf(t);i!==void 0&&i!==-1&&(c.model.sectionIds?.splice(i,1),delete c.model.sections?.[t]),c.model.config?.gridSettings&&Object.keys(c.model.config.gridSettings).forEach(d=>{try{delete c.model.config.gridSettings[d]?.[t]}catch{}}),c.model.config?.backgroundSectionId===t&&(c.model.config.backgroundSectionId=void 0)}r.forEach(i=>{const d=s.sectionIds.indexOf(i);d!==-1&&s.sectionIds.splice(d,1),s.sections[i]&&delete s.sections[i],s.dataSource?.[i]&&delete s.dataSource?.[i]})})},lockSection:(e,t)=>{if(!n.pages[e])throw new Error(`Page ${e} is not exists`);const r=g.currentPageModel?.getComponentById(t)?.model;r&&(r.locked=!r.locked)},toggleSectionVisibility:(e,t,s)=>{if(!n.pages[e])throw new Error(`Page ${e} is not exists`);const a=g.currentPageModel?.getComponentById(t)?.model;a&&(a.visibility=s)},moveSection:(e,t,s,r)=>{if(!n.pages[e])throw new Error(`Page ${e} is not exists`);if(r&&r!==t){const c=g.currentPageModel?.getComponentById(t),i=g.currentPageModel?.getComponentById(r),d=c?.parent,P=i?.parent;P&&d&&P?.model?.id===d?.model?.id?o.doc.transact(()=>{d.model.sectionIds.splice(c.getIndex(),1),d.model.sectionIds.splice(i.getIndex(),0,t)}):P&&d&&P?.model?.id!==d?.model?.id&&t!==r&&!c?.model?.sectionIds?.includes(r)&&o.doc.transact(()=>{P.model.sections[t]=JSON.parse(JSON.stringify(c.model)),P.model.sectionIds.splice(i.getIndex(),0,t),d.model.sectionIds.splice(c.getIndex(),1),delete d.model.sections[t]})}},copySection:(e,t)=>{if(!n.pages[e])throw new Error(`Page ${e} is not exists`);const r=g.currentPageModel?.getComponentById(t);if(!r?.model)throw new Error(`Section ${t} is not exists`);const a=JSON.parse(JSON.stringify(r.model)),c=Q(a),i=c.id,d=r?.parent;if(d){if(d.model.sections[i]=c,d.model.sectionIds.push(i),g.currentPage?.dataSource?.[t]&&(g.currentPage.dataSource[i]=JSON.parse(JSON.stringify(g.currentPage.dataSource[t])),c.component==="layout-block")){const P=(h,b)=>{const _=h.sectionIds,k=b.sectionIds;_?.forEach((L,R)=>{const j=k?.[R];if(j){if(j&&g.currentPage?.dataSource){const p=g.currentPage.dataSource[j];p&&(g.currentPage.dataSource[L]=JSON.parse(JSON.stringify(p)))}const O=h.sections?.[L],N=b?.sections?.[j];O?.component==="layout-block"&&O.sectionIds&&N?.sectionIds&&P(O,N)}})};c.sectionIds&&a.sectionIds&&P(c,a)}S.setCurrentSectionId(e,i)}return c},addDataSource:e=>{const t=e.id??E.nextId(),s={...e??{},id:t,createdAt:new Date().toISOString()};return o.doc.transact(()=>{n.dataSourceIds??=[],n.dataSources??={},n.dataSourceIds.push(t),n.dataSources[t]=s}),n.dataSources[t]},deleteDataSource:e=>{const t=n.dataSourceIds.indexOf(e);t!==-1&&o.doc.transact(()=>{n.dataSourceIds.splice(t,1),delete n.dataSources[e]})}}),[n,o.doc,g]);return{...o,state:n,actions:v,localActions:S,...g}},$=()=>{const{projectId:o}=U.useParams();return o??B()??""},Oe=()=>window.__PROJECT_SLUG__??"";function V(o){const{resources:n}=o;if(!n.components)return{};const u={};return window?.blocklet?.componentMountPoints?.forEach(l=>{u[l.did]=l}),Object.fromEntries(Object.entries(n.components).map(([l,{blockletId:y,component:m}])=>[l,{data:m,blockletId:y,blockletTitle:u[y]?.title||y}]))}function z(o){const{components:n}=o;return n||{}}function K(o){return{...V(o),...z(o)}}const Me=()=>K(W().state);function Q(o){const n=JSON.parse(JSON.stringify(o)),u=E.nextId();if(n.component==="layout-block"){const l={...n.config??{}},y=n.sectionIds?.map(m=>{const g=n.sections?.[m],S=Q(n.sections?.[m]),v=S.id;return g?.id===n.config?.backgroundSectionId&&(l.backgroundSectionId=S.id),n.config?.gridSettings&&Object.keys(n.config.gridSettings).forEach(e=>{l.gridSettings[e]={...l.gridSettings[e]??{},[v]:{...n.config?.gridSettings?.[e]?.[m],id:v}},delete n.config?.gridSettings?.[e]?.[m]}),S});n.sections=Object.fromEntries(y?.map(m=>[m.id,m])??[]),n.sectionIds=y?.map(m=>m.id)??[],n.config=l}return{...n,id:u}}exports.StoreProvider=ve;exports.api=q;exports.autoResizeImage=ye;exports.getAllComponents=K;exports.getCustomComponents=z;exports.getImageAbsoluteUrl=Ie;exports.getProjectIdFromPathnameOrWindow=B;exports.getProjectPageVersionKey=ge;exports.getResourceComponents=V;exports.getWssURL=Se;exports.transformValue=pe;exports.useAllComponents=Me;exports.useProjectId=$;exports.useProjectSlug=Oe;exports.useStore=W;
@@ -1,604 +0,0 @@
1
- import { jsx as K } from "react/jsx-runtime";
2
- import { joinURL as k, withQuery as V } from "ufo";
3
- import { createAxios as z } from "@blocklet/js-sdk";
4
- import Q from "lodash/isEmpty";
5
- import * as X from "yaml";
6
- import { useLocaleContext as q } from "@arcblock/ux/lib/Locale/context";
7
- import { nextId as E } from "@blocklet/pages-kit/utils/common";
8
- import { getPageTemplateModel as Y } from "@blocklet/pages-kit/utils/page-model";
9
- import "@mui/material";
10
- import Z, { getYjsDoc as H } from "@syncedstore/core";
11
- import { useSyncedStore as ee } from "@syncedstore/react";
12
- import { useLocalStorageState as te } from "ahooks";
13
- import { produce as L } from "immer";
14
- import T from "lodash/cloneDeep";
15
- import G from "lodash/debounce";
16
- import { createContext as oe, useState as D, useRef as ne, useMemo as y, useCallback as $, useEffect as _, useContext as re } from "react";
17
- import { useParams as se, useNavigate as ce } from "react-router-dom";
18
- import { IndexeddbPersistence as ie } from "y-indexeddb";
19
- import { WebsocketProvider as ae } from "y-websocket";
20
- import { UndoManager as de } from "yjs";
21
- import "@blocklet/pages-kit/types";
22
- function le() {
23
- const { pathname: n } = window.location, f = n.match(/\/admin\/(maker|previewer)\/([^/]+)/)?.[2], l = window.__PROJECT_ID__;
24
- if (!f && !l)
25
- throw new Error("Unable to get projectId from pathname");
26
- return f || l;
27
- }
28
- function Ue(n) {
29
- return `${n}:pages:version`;
30
- }
31
- function Fe(n, o) {
32
- return o === "yaml" ? Q(n) ? "" : X.stringify(n, { indent: 2 }) : o === "json" ? JSON.parse(JSON.stringify(n || {})) : o === "array" ? JSON.parse(JSON.stringify(n || [])) : n;
33
- }
34
- const J = window.blocklet?.prefix || "/", B = z({
35
- timeout: 200 * 1e3
36
- }), ue = window.location.protocol === "https:" ? "wss" : "ws", We = (n) => k(`${ue}://${window.location.hostname}`, J, `api/${n}/ws/pages`), pe = "z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";
37
- blocklet?.componentMountPoints.find((n) => n.did === pe)?.mountPoint || k(J, "/image-bin");
38
- function Ke(n) {
39
- return n && !/^(https?:\/\/|\/)/.test(n) ? window.location.origin + k(J, "uploads", n) : n;
40
- }
41
- const fe = window.innerWidth <= 750;
42
- function Ve(n, o, f) {
43
- if (!n || /\.gif/.test(n)) return n;
44
- const l = (fe ? o / 1.5 : o) * (f === "quality" ? 1.5 : 1);
45
- return ge(n, { imageFilter: "resize", w: l, f: "webp" });
46
- }
47
- function ge(n, o) {
48
- return !n || !o ? n : V(n, o);
49
- }
50
- async function me(n) {
51
- return B.get(`/api/projects/${n}`).then((o) => o.data);
52
- }
53
- async function Se(n) {
54
- return B.post(`/api/projects/${n.id}/update`, n).then((o) => o.data);
55
- }
56
- const Pe = 500, U = oe(null);
57
- function ze({
58
- url: n,
59
- name: o,
60
- children: f,
61
- waitingSynced: l
62
- }) {
63
- const [w, g] = D(!1), { locale: u } = q(), m = F(), O = `${m}:MakerLocalState`, e = `${m}:${o}`, [t, s] = te(O, {
64
- defaultValue: {},
65
- listenStorageChange: !0
66
- }), r = ne(t);
67
- r.current = t;
68
- const a = y(
69
- () => Z({
70
- dataSourceIds: [],
71
- dataSources: {},
72
- pages: {},
73
- pageIds: [],
74
- routes: {},
75
- routeIds: [],
76
- components: {},
77
- supportedLocales: [],
78
- config: {},
79
- resources: {}
80
- }),
81
- []
82
- ), c = y(() => H(a), [a]);
83
- y(() => new ie(e, c), [e, c]);
84
- const i = y(
85
- () => new ae(n, e, c, {
86
- params: {},
87
- resyncInterval: 5 * 60 * 1e3
88
- }),
89
- [n, e, c]
90
- ), d = $(() => {
91
- i && (i.disconnect(), i.connect());
92
- }, [i]), S = y(
93
- () => new de(
94
- [
95
- c.getArray("pageIds"),
96
- c.getMap("pages"),
97
- c.getArray("supportedLocales"),
98
- c.getMap("config"),
99
- c.getMap("dataSources"),
100
- c.getArray("dataSourceIds"),
101
- c.getArray("routeIds"),
102
- c.getMap("routes")
103
- ],
104
- { doc: c }
105
- ),
106
- [c]
107
- ), [h, C] = D(null), [M, N] = D(!1), [x, A] = D(void 0), b = $(async () => {
108
- if (m) {
109
- N(!0);
110
- try {
111
- const p = await me(m);
112
- C(p);
113
- } catch (p) {
114
- console.error("Failed to fetch project:", p);
115
- } finally {
116
- N(!1);
117
- }
118
- }
119
- }, [m]), j = $(
120
- async (p, P) => {
121
- if (A(void 0), !!m) {
122
- P?.optimisticUpdate && h && C((I) => ({
123
- ...I,
124
- ...p
125
- }));
126
- try {
127
- const I = await Se({
128
- ...p
129
- });
130
- C(I);
131
- } catch (I) {
132
- console.error("Failed to update project:", I), P?.optimisticUpdate && C(h), A(I?.response?.data);
133
- }
134
- }
135
- },
136
- [m, h]
137
- );
138
- _(() => {
139
- m && b();
140
- }, [m, b]);
141
- const R = y(
142
- () => ({
143
- doc: c,
144
- state: a,
145
- localState: {
146
- ...t,
147
- // always use the locale from the context
148
- currentLocale: u
149
- },
150
- setLocalState: (p) => s(typeof p == "function" ? (P) => p(P ?? {}) : p),
151
- undoManager: S,
152
- projectState: {
153
- project: h,
154
- isLoadingProject: M,
155
- error: x
156
- },
157
- updateProject: j,
158
- forceSync: d
159
- }),
160
- // eslint-disable-next-line react-hooks/exhaustive-deps
161
- [
162
- c,
163
- a,
164
- JSON.stringify(t),
165
- // resolve the problem of react warning
166
- s,
167
- S,
168
- h,
169
- M,
170
- j,
171
- x,
172
- u,
173
- d
174
- ]
175
- );
176
- return _(() => {
177
- S.on("stack-item-added", ({ stackItem: p }) => {
178
- const { currentPageId: P, currentLocale: I, pages: v } = r.current;
179
- p.meta.set("localState", { currentPageId: P, currentLocale: I, pages: v });
180
- }), S.on("stack-item-popped", ({ stackItem: p }) => {
181
- const P = p.meta.get("localState");
182
- P && s((I) => ({ ...I, ...P }));
183
- });
184
- }, [S, s]), _(() => {
185
- i.awareness.setLocalState(t);
186
- }, [i, t]), _(() => {
187
- i.once("synced", () => g(!0));
188
- const p = () => {
189
- s((v) => ({
190
- ...v,
191
- networkStatus: void 0
192
- }));
193
- }, P = () => {
194
- s((v) => ({
195
- ...v,
196
- networkStatus: "offline"
197
- }));
198
- }, I = G(({ status: v }) => {
199
- v === "connected" ? p() : v === "disconnected" && P();
200
- }, Pe);
201
- return i.on("status", I), window.addEventListener("online", p), window.addEventListener("offline", P), () => {
202
- i.off("status", I), window.removeEventListener("online", p), window.removeEventListener("offline", P);
203
- };
204
- }, [i, s]), l && !w ? null : /* @__PURE__ */ K(U.Provider, { value: R, children: f });
205
- }
206
- const Ie = () => {
207
- const n = re(U);
208
- if (!n)
209
- throw new Error("Context is null");
210
- const o = ee(n.state), { setLocalState: f, localState: l } = n, w = ce(), g = F(), u = y(
211
- () => ({
212
- get currentPage() {
213
- const {
214
- localState: { currentPageId: e }
215
- } = n;
216
- return e ? o.pages[e] : void 0;
217
- },
218
- get currentSection() {
219
- const {
220
- localState: { currentPageId: e, ...t }
221
- } = n;
222
- if (!e)
223
- return;
224
- const s = t.pages?.[e]?.currentSectionId;
225
- if (s)
226
- return o.pages[e]?.sections[s] ?? this.currentPageModel?.getComponentById(s)?.model;
227
- },
228
- get currentSectionProperties() {
229
- const {
230
- localState: { currentPageId: e, ...t }
231
- } = n;
232
- if (!e)
233
- return;
234
- const s = t.pages?.[e]?.currentSectionId;
235
- if (!s)
236
- return;
237
- const r = o.pages[e]?.dataSource?.[s];
238
- if (!r)
239
- return;
240
- const { currentLocale: a } = this.currentLocaleMap;
241
- return a ? r[a] : void 0;
242
- },
243
- get currentSectionPropertiesWithFallback() {
244
- const {
245
- localState: { currentPageId: e, ...t }
246
- } = n;
247
- if (!e)
248
- return;
249
- const s = t.pages?.[e]?.currentSectionId;
250
- if (!s)
251
- return;
252
- const r = o.pages[e]?.dataSource?.[s];
253
- if (!r)
254
- return;
255
- const { currentLocale: a, defaultLocale: c, fallbackLocale: i } = this.currentLocaleMap;
256
- if (a && r[a])
257
- return r[a];
258
- if (c && r[c])
259
- return r[c];
260
- if (i && r[i])
261
- return r[i];
262
- },
263
- get currentLocaleMap() {
264
- const {
265
- localState: { currentLocale: e },
266
- state: {
267
- supportedLocales: t,
268
- config: { defaultLocale: s }
269
- }
270
- } = n;
271
- return {
272
- currentLocale: e,
273
- defaultLocale: s,
274
- fallbackLocale: t?.[0]?.locale ?? "en"
275
- };
276
- },
277
- get currentRoute() {
278
- const {
279
- localState: { currentRouteId: e }
280
- } = n;
281
- return e ? o.routes?.[e] : void 0;
282
- },
283
- get currentPageModel() {
284
- const e = this.currentPage ?? null;
285
- if (e)
286
- return Y(e, !1);
287
- }
288
- }),
289
- [JSON.stringify(l), o]
290
- ), m = y(
291
- () => ({
292
- setCurrentSectionId: (e, t) => {
293
- e === l.currentPageId && t === l.pages?.[e]?.currentSectionId || (w(k("/admin/maker", g ?? "", "pages", e)), f(
294
- (s) => L(s, (r) => {
295
- r.currentPageId = e, r.currentComponentId = void 0, t !== void 0 && (r.pages ??= {}, r.pages[e] ??= {}, r.pages[e].currentSectionId = t ?? void 0), t ? window.sessionStorage.setItem("iframe_show_id", `"${t}"`) : window.sessionStorage.removeItem("iframe_show_id");
296
- })
297
- ));
298
- },
299
- setCurrentComponentId: (e) => {
300
- e !== l.currentComponentId && (w(k("/admin/maker", g ?? "", "components", e)), f(
301
- (t) => L(t, (s) => {
302
- s.currentComponentId = e;
303
- })
304
- ));
305
- },
306
- setCurrentRouteId: ({ routeId: e, dynamicParams: t }) => {
307
- f(
308
- (s) => L(s, (r) => {
309
- r.currentRouteId = e, r.currentDynamicParams = t;
310
- })
311
- );
312
- },
313
- // 本地缓存组件调试参数,避免用户切换组件后,需要重新输入
314
- setCustomComponentPreviewerProperties: (() => {
315
- const e = {};
316
- let t = "";
317
- const s = G(() => {
318
- f(
319
- (r) => L(r, (a) => {
320
- a.customComponentPreviewerProperties ??= {}, a.customComponentPreviewerProperties[t] = {
321
- ...a.customComponentPreviewerProperties[t],
322
- ...T(e[t])
323
- }, delete e[t];
324
- })
325
- );
326
- }, 5);
327
- return (r, a) => {
328
- const c = e[r] ?? {};
329
- Object.assign(c, a), e[r] = c, t = r, s();
330
- };
331
- })(),
332
- setRouteGenerateProcess: (e) => {
333
- f(
334
- (t) => L(t, (s) => {
335
- e ? s.routeGenerateProcess = {
336
- ...s.routeGenerateProcess,
337
- ...e
338
- } : s.routeGenerateProcess = {};
339
- })
340
- );
341
- },
342
- resetRouteGenerateProcess: () => {
343
- f(
344
- (e) => L(e, (t) => {
345
- t.routeGenerateProcess = {
346
- progress: "complete"
347
- };
348
- })
349
- );
350
- }
351
- }),
352
- [f, w, g, u]
353
- ), O = y(
354
- () => ({
355
- addPage: (e, t) => {
356
- const s = e?.id ?? E(), r = {
357
- ...e,
358
- id: s,
359
- createdAt: e?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
360
- updatedAt: e?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
361
- publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
362
- slug: e?.slug ?? `/${s}`,
363
- sections: e?.sections ?? {},
364
- sectionIds: e?.sectionIds ?? [],
365
- isPublic: e?.isPublic ?? !0,
366
- templateConfig: e?.templateConfig ?? {
367
- isTemplate: e?.templateConfig?.isTemplate ?? !0,
368
- displayTemplateId: e?.templateConfig?.displayTemplateId ?? void 0,
369
- dataSourceIds: e?.templateConfig?.dataSourceIds ?? void 0,
370
- dataSourceParameters: e?.templateConfig?.dataSourceParameters ?? {},
371
- enabledGenerate: e?.templateConfig?.enabledGenerate ?? !1,
372
- agentId: e?.templateConfig?.agentId ?? void 0
373
- }
374
- };
375
- return n.doc.transact(() => {
376
- o.pages[r.id] = r, o.pageIds.splice(t ?? o.pageIds.length, 0, r.id);
377
- }), r;
378
- },
379
- addRoute: (e, t) => {
380
- const s = e?.id ?? E(), r = {
381
- ...e,
382
- id: s,
383
- createdAt: e?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
384
- updatedAt: e?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
385
- publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
386
- path: e?.path ?? `/${s}`,
387
- handler: e?.handler ?? "Pages Kit",
388
- isPublic: e?.isPublic ?? !0,
389
- params: e?.params ?? [],
390
- enabledGenerate: e?.enabledGenerate ?? !1,
391
- displayTemplateId: e?.displayTemplateId ?? void 0,
392
- dataSource: e?.dataSource ?? {}
393
- };
394
- return n.doc.transact(() => {
395
- o.routes ??= {}, o.routeIds ??= [], o.routes[r.id] = r, o.routeIds.splice(t ?? o.routeIds.length, 0, r.id);
396
- }), r;
397
- },
398
- deleteRoute: (e) => {
399
- if (!e)
400
- return;
401
- const t = o.routeIds?.indexOf(e);
402
- t !== void 0 && t !== -1 && n.doc.transact(() => {
403
- o.routeIds?.splice(t, 1), delete o.routes?.[e];
404
- });
405
- },
406
- deletePage: (e) => {
407
- const t = o.pageIds.indexOf(e);
408
- t !== -1 && n.doc.transact(() => {
409
- o.pageIds.splice(t, 1), delete o.pages[e];
410
- });
411
- },
412
- movePage: (e, t) => {
413
- const { pageIds: s } = o, r = s.indexOf(e);
414
- r >= 0 && s.splice(t, 0, ...s.splice(r, 1));
415
- },
416
- addSection: (e, t, s, r) => {
417
- const a = o.pages[e];
418
- if (!a)
419
- throw new Error(`Page ${e} is not exists`);
420
- const c = {
421
- ...t,
422
- id: t.id ?? E(),
423
- isTemplateSection: t.isTemplateSection ?? !0,
424
- llmConfig: t.llmConfig ?? {}
425
- }, i = T(c.locales);
426
- return delete c.locales, n.doc.transact(() => {
427
- if (r && r.component === "layout-block") {
428
- const d = u.currentPageModel?.getComponentById(r.id);
429
- d && (d.model.sections ??= {}, d.model.sections[c.id] = c, d.model.sectionIds ??= [], d.model.sectionIds.push(c.id));
430
- } else
431
- a.sections[c.id] = c, a.sectionIds.splice(s ?? a.sectionIds.length, 0, c.id);
432
- i && (a.dataSource ??= {}, a.dataSource[c.id] = i);
433
- }), c;
434
- },
435
- deleteSection: (e, t) => {
436
- const s = o.pages[e];
437
- if (!s)
438
- throw new Error(`Page ${e} is not exists`);
439
- n.doc.transact(() => {
440
- const r = [], a = u.currentPageModel?.getComponentById(t), c = a?.parent;
441
- if (a && (r.push(a.model.id, ...a.all().map((i) => i.model.id)), c?.model.component === "layout-block")) {
442
- const i = c.model.sectionIds?.indexOf(t);
443
- i !== void 0 && i !== -1 && (c.model.sectionIds?.splice(i, 1), delete c.model.sections?.[t]), c.model.config?.gridSettings && Object.keys(c.model.config.gridSettings).forEach((d) => {
444
- try {
445
- delete c.model.config.gridSettings[d]?.[t];
446
- } catch {
447
- }
448
- }), c.model.config?.backgroundSectionId === t && (c.model.config.backgroundSectionId = void 0);
449
- }
450
- r.forEach((i) => {
451
- const d = s.sectionIds.indexOf(i);
452
- d !== -1 && s.sectionIds.splice(d, 1), s.sections[i] && delete s.sections[i], s.dataSource?.[i] && delete s.dataSource?.[i];
453
- });
454
- });
455
- },
456
- lockSection: (e, t) => {
457
- if (!o.pages[e])
458
- throw new Error(`Page ${e} is not exists`);
459
- const r = u.currentPageModel?.getComponentById(t)?.model;
460
- r && (r.locked = !r.locked);
461
- },
462
- toggleSectionVisibility: (e, t, s) => {
463
- if (!o.pages[e])
464
- throw new Error(`Page ${e} is not exists`);
465
- const a = u.currentPageModel?.getComponentById(t)?.model;
466
- a && (a.visibility = s);
467
- },
468
- moveSection: (e, t, s, r) => {
469
- if (!o.pages[e])
470
- throw new Error(`Page ${e} is not exists`);
471
- if (r && r !== t) {
472
- const c = u.currentPageModel?.getComponentById(t), i = u.currentPageModel?.getComponentById(r), d = c?.parent, S = i?.parent;
473
- S && d && S?.model?.id === d?.model?.id ? n.doc.transact(() => {
474
- d.model.sectionIds.splice(c.getIndex(), 1), d.model.sectionIds.splice(i.getIndex(), 0, t);
475
- }) : S && d && S?.model?.id !== d?.model?.id && t !== r && !c?.model?.sectionIds?.includes(r) && n.doc.transact(() => {
476
- S.model.sections[t] = JSON.parse(JSON.stringify(c.model)), S.model.sectionIds.splice(i.getIndex(), 0, t), d.model.sectionIds.splice(c.getIndex(), 1), delete d.model.sections[t];
477
- });
478
- }
479
- },
480
- copySection: (e, t) => {
481
- if (!o.pages[e])
482
- throw new Error(`Page ${e} is not exists`);
483
- const r = u.currentPageModel?.getComponentById(t);
484
- if (!r?.model)
485
- throw new Error(`Section ${t} is not exists`);
486
- const a = JSON.parse(JSON.stringify(r.model)), c = W(a), i = c.id, d = r?.parent;
487
- if (d) {
488
- if (d.model.sections[i] = c, d.model.sectionIds.push(i), u.currentPage?.dataSource?.[t] && (u.currentPage.dataSource[i] = JSON.parse(
489
- JSON.stringify(u.currentPage.dataSource[t])
490
- ), c.component === "layout-block")) {
491
- const S = (h, C) => {
492
- const M = h.sectionIds, N = C.sectionIds;
493
- M?.forEach((x, A) => {
494
- const b = N?.[A];
495
- if (b) {
496
- if (b && u.currentPage?.dataSource) {
497
- const p = u.currentPage.dataSource[b];
498
- p && (u.currentPage.dataSource[x] = JSON.parse(JSON.stringify(p)));
499
- }
500
- const j = h.sections?.[x], R = C?.sections?.[b];
501
- j?.component === "layout-block" && j.sectionIds && R?.sectionIds && S(j, R);
502
- }
503
- });
504
- };
505
- c.sectionIds && a.sectionIds && S(c, a);
506
- }
507
- m.setCurrentSectionId(e, i);
508
- }
509
- return c;
510
- },
511
- addDataSource: (e) => {
512
- const t = e.id ?? E(), s = {
513
- ...e ?? {},
514
- id: t,
515
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
516
- };
517
- return n.doc.transact(() => {
518
- o.dataSourceIds ??= [], o.dataSources ??= {}, o.dataSourceIds.push(t), o.dataSources[t] = s;
519
- }), o.dataSources[t];
520
- },
521
- deleteDataSource: (e) => {
522
- const t = o.dataSourceIds.indexOf(e);
523
- t !== -1 && n.doc.transact(() => {
524
- o.dataSourceIds.splice(t, 1), delete o.dataSources[e];
525
- });
526
- }
527
- }),
528
- [o, n.doc, u]
529
- );
530
- return {
531
- ...n,
532
- state: o,
533
- actions: O,
534
- localActions: m,
535
- ...u
536
- };
537
- }, F = () => {
538
- const { projectId: n } = se();
539
- return n ?? le() ?? "";
540
- }, Qe = () => window.__PROJECT_SLUG__ ?? "";
541
- function we(n) {
542
- const { resources: o } = n;
543
- if (!o.components)
544
- return {};
545
- const f = {};
546
- return window?.blocklet?.componentMountPoints?.forEach((l) => {
547
- f[l.did] = l;
548
- }), Object.fromEntries(
549
- Object.entries(o.components).map(([l, { blockletId: w, component: g }]) => [
550
- l,
551
- { data: g, blockletId: w, blockletTitle: f[w]?.title || w }
552
- ])
553
- );
554
- }
555
- function ye(n) {
556
- const { components: o } = n;
557
- return o || {};
558
- }
559
- function he(n) {
560
- return {
561
- ...we(n),
562
- ...ye(n)
563
- };
564
- }
565
- const Xe = () => he(Ie().state);
566
- function W(n) {
567
- const o = JSON.parse(JSON.stringify(n)), f = E();
568
- if (o.component === "layout-block") {
569
- const l = { ...o.config ?? {} }, w = o.sectionIds?.map((g) => {
570
- const u = o.sections?.[g], m = W(o.sections?.[g]), O = m.id;
571
- return u?.id === o.config?.backgroundSectionId && (l.backgroundSectionId = m.id), o.config?.gridSettings && Object.keys(o.config.gridSettings).forEach((e) => {
572
- l.gridSettings[e] = {
573
- ...l.gridSettings[e] ?? {},
574
- [O]: {
575
- ...o.config?.gridSettings?.[e]?.[g],
576
- id: O
577
- }
578
- }, delete o.config?.gridSettings?.[e]?.[g];
579
- }), m;
580
- });
581
- o.sections = Object.fromEntries(w?.map((g) => [g.id, g]) ?? []), o.sectionIds = w?.map((g) => g.id) ?? [], o.config = l;
582
- }
583
- return {
584
- ...o,
585
- id: f
586
- };
587
- }
588
- export {
589
- ze as S,
590
- Ie as a,
591
- Ue as b,
592
- he as c,
593
- Qe as d,
594
- Ve as e,
595
- Ke as f,
596
- We as g,
597
- Xe as h,
598
- B as i,
599
- ye as j,
600
- we as k,
601
- le as l,
602
- Fe as t,
603
- F as u
604
- };