@blocklet/pages-kit-inner-components 0.5.36 → 0.5.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/add-component.js +1 -1
- package/lib/cjs/chunks/{array-Ck0L_JhL.js → array-Cr5KF-hM.js} +1 -1
- package/lib/cjs/chunks/{config-string-CaLe_baf.js → config-string-BYZ5HfyY.js} +1 -1
- package/lib/cjs/chunks/{draft-data-CY1N7Ozn.js → draft-data-6zW9mu28.js} +1 -1
- package/lib/cjs/chunks/{home-CjWVwLEf.js → home-C0ZSLVcc.js} +3 -3
- package/lib/cjs/chunks/{publish-button-BDrUGRX4.js → publish-button-CPmErdXB.js} +1 -1
- package/lib/cjs/chunks/state-BWuBNdK8.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +5 -5
- package/lib/cjs/setting.js +2 -2
- package/lib/es/add-component.js +3 -3
- package/lib/es/chunks/{array-HCA75FfO.js → array-D34Qpnhk.js} +1 -1
- package/lib/es/chunks/{config-string-17RNX8vu.js → config-string-DgK7ETCs.js} +1 -1
- package/lib/es/chunks/{draft-data-CyeVe0kA.js → draft-data-B5kzDvTI.js} +1 -1
- package/lib/es/chunks/{home-COrN_x32.js → home-B1ALs6m4.js} +4 -4
- package/lib/es/chunks/{publish-button-WmGjhj6q.js → publish-button-9J9uRZtS.js} +3 -3
- package/lib/es/chunks/{state-Br2xp7Mf.js → state-BzwEX9VC.js} +38 -38
- package/lib/es/home.js +3 -3
- package/lib/es/project-html.js +15 -15
- package/lib/es/setting.js +154 -154
- package/package.json +3 -3
- package/lib/cjs/chunks/state-D4QeRw7n.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit-inner-components",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.37",
|
|
4
4
|
"description": "Pages Kit inner components library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -204,8 +204,8 @@
|
|
|
204
204
|
"yaml": "^2.5.0",
|
|
205
205
|
"yjs": "^13.6.18",
|
|
206
206
|
"zustand": "^4.5.5",
|
|
207
|
-
"@blocklet/pages-kit": "^0.5.
|
|
208
|
-
"@blocklet/pages-kit-block-studio": "^0.5.
|
|
207
|
+
"@blocklet/pages-kit": "^0.5.37",
|
|
208
|
+
"@blocklet/pages-kit-block-studio": "^0.5.37"
|
|
209
209
|
},
|
|
210
210
|
"devDependencies": {
|
|
211
211
|
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const D=require("react/jsx-runtime"),U=require("@mui/material"),R=require("ufo"),Z=require("@blocklet/js-sdk"),ee=require("lodash/isEmpty"),te=require("yaml"),oe=require("@arcblock/ux/lib/Locale/context"),J=require("@blocklet/pages-kit-core"),F=require("@syncedstore/core"),ne=require("@syncedstore/react"),re=require("ahooks"),x=require("immer"),ce=require("lodash/cloneDeep"),se=require("lodash/debounce"),ie=require("nanoid"),m=require("react"),W=require("react-router-dom"),ae=require("y-indexeddb"),de=require("y-websocket"),le=require("yjs");require("@blocklet/pages-kit/types");const A=o=>o&&o.__esModule?o:{default:o};function ue(o){if(o&&o.__esModule)return o;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const l in o)if(l!=="default"){const P=Object.getOwnPropertyDescriptor(o,l);Object.defineProperty(n,l,P.get?P:{enumerable:!0,get:()=>o[l]})}}return n.default=o,Object.freeze(n)}const fe=A(ee),me=ue(te),Se=A(F),pe=A(ce),V=A(se),ge=o=>{const n=blocklet==null?void 0:blocklet.componentMountPoints.find(l=>l.name===o);return n?n.mountPoint:"/"};function K(){const{pathname:o}=window.location,n=o.match(/\/admin\/(maker|previewer)\/([^/]+)/),l=n==null?void 0:n[2],P=window.__PROJECT_ID__;if(!l&&!P)throw new Error("Unable to get projectId from pathname");return l||P}function Pe(o){return`${o}:pages:version`}function we(o,n){return n==="yaml"?fe.default(o)?"":me.stringify(o,{indent:2}):n==="json"?JSON.parse(JSON.stringify(o||{})):n==="array"?JSON.parse(JSON.stringify(o||[])):o}function Ie({error:o}){return D.jsx(U.Box,{children:D.jsx(U.Alert,{severity:"error",children:o.message})})}var G;const q=((G=window.blocklet)==null?void 0:G.prefix)||"/",T=Z.createAxios({timeout:200*1e3}),ye=window.location.protocol==="https:"?"wss":"ws",he=o=>R.joinURL(`${ye}://${window.location.hostname}`,q,`api/${o}/ws/pages`),Ce="z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";var B;(B=blocklet==null?void 0:blocklet.componentMountPoints.find(o=>o.did===Ce))!=null&&B.mountPoint||R.joinURL(q,"/image-bin");function je(o){return o&&!/^(https?:\/\/|\/)/.test(o)?window.location.origin+R.joinURL(q,"uploads",o):o}const ve=window.innerWidth<=750;function be(o,n,l){if(!o||/\.gif/.test(o))return o;const P=(ve?n/1.5:n)*(l==="quality"?1.5:1);return Oe(o,{imageFilter:"resize",w:P,f:"webp"})}function Oe(o,n){return!o||!n?o:R.withQuery(o,n)}async function Ee(o){return T.get(`/api/projects/${o}`).then(n=>n.data)}async function Le(o){return T.post(`/api/projects/${o.id}/update`,o).then(n=>n.data)}const Me=500,k=ie.customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789",16),N=m.createContext(null);function _e({url:o,name:n,children:l,waitingSynced:P}){const[L,O]=m.useState(!1),{locale:p}=oe.useLocaleContext(),j=$(),_=`${j}:MakerLocalState`,e=`${j}:${n}`,[t,s]=re.useLocalStorageState(_,{defaultValue:{},listenStorageChange:!0}),c=m.useRef(t);c.current=t;const i=m.useMemo(()=>Se.default({dataSourceIds:[],dataSources:{},pages:{},pageIds:[],routes:{},routeIds:[],components:{},supportedLocales:[],config:{},resources:{}}),[]),r=m.useMemo(()=>F.getYjsDoc(i),[i]);m.useMemo(()=>new ae.IndexeddbPersistence(e,r),[e,r]);const a=m.useMemo(()=>new de.WebsocketProvider(o,e,r,{params:{},resyncInterval:5*60*1e3}),[o,e,r]),d=m.useCallback(()=>{a&&(a.disconnect(),a.connect())},[a]),u=m.useMemo(()=>new le.UndoManager([r.getArray("pageIds"),r.getMap("pages"),r.getArray("supportedLocales"),r.getMap("config"),r.getMap("dataSources"),r.getArray("dataSourceIds"),r.getArray("routeIds"),r.getMap("routes")],{doc:r}),[r]),[f,S]=m.useState(null),[M,I]=m.useState(!1),[y,v]=m.useState(void 0),g=m.useCallback(async()=>{if(j){I(!0);try{const w=await Ee(j);S(w)}catch(w){console.error("Failed to fetch project:",w)}finally{I(!1)}}},[j]),b=m.useCallback(async(w,h)=>{var E;if(v(void 0),!!j){h!=null&&h.optimisticUpdate&&f&&S(C=>({...C,...w}));try{const C=await Le({...w});S(C)}catch(C){console.error("Failed to update project:",C),h!=null&&h.optimisticUpdate&&S(f),v((E=C==null?void 0:C.response)==null?void 0:E.data)}}},[j,f]);m.useEffect(()=>{j&&g()},[j,g]);const H=m.useMemo(()=>({doc:r,state:i,localState:{...t,currentLocale:p},setLocalState:w=>s(typeof w=="function"?h=>w(h??{}):w),undoManager:u,projectState:{project:f,isLoadingProject:M,error:y},updateProject:b,forceSync:d}),[r,i,JSON.stringify(t),s,u,f,M,b,y,p,d]);return m.useEffect(()=>{u.on("stack-item-added",({stackItem:w})=>{const{currentPageId:h,currentLocale:E,pages:C}=c.current;w.meta.set("localState",{currentPageId:h,currentLocale:E,pages:C})}),u.on("stack-item-popped",({stackItem:w})=>{const h=w.meta.get("localState");h&&s(E=>({...E,...h}))})},[u,s]),m.useEffect(()=>{a.awareness.setLocalState(t)},[a,t]),m.useEffect(()=>{a.once("synced",()=>O(!0));const w=()=>{s(C=>({...C,networkStatus:void 0}))},h=()=>{s(C=>({...C,networkStatus:"offline"}))},E=V.default(({status:C})=>{C==="connected"?w():C==="disconnected"&&h()},Me);return a.on("status",E),window.addEventListener("online",w),window.addEventListener("offline",h),()=>{a.off("status",E),window.removeEventListener("online",w),window.removeEventListener("offline",h)}},[a,s]),P&&!L?null:D.jsx(N.Provider,{value:H,children:l})}const z=()=>{const o=m.useContext(N);if(!o)throw new Error("Context is null");const n=ne.useSyncedStore(o.state),{setLocalState:l,localState:P}=o,L=W.useNavigate(),O=$(),p=m.useMemo(()=>({get currentPage(){const{localState:{currentPageId:e}}=o;return e?n.pages[e]:void 0},get currentSection(){var c,i,r,a,d;const{localState:{currentPageId:e,...t}}=o;if(!e)return;const s=(i=(c=t.pages)==null?void 0:c[e])==null?void 0:i.currentSectionId;if(s)return((r=n.pages[e])==null?void 0:r.sections[s])??((d=(a=this.currentPageModel)==null?void 0:a.getComponentById(s))==null?void 0:d.model)},get currentSectionProperties(){var r,a,d,u;const{localState:{currentPageId:e,...t}}=o;if(!e)return;const s=(a=(r=t.pages)==null?void 0:r[e])==null?void 0:a.currentSectionId;if(!s)return;const c=(u=(d=n.pages[e])==null?void 0:d.dataSource)==null?void 0:u[s];if(!c)return;const{currentLocale:i}=this.currentLocaleMap;return i?c[i]:void 0},get currentSectionPropertiesWithFallback(){var d,u,f,S;const{localState:{currentPageId:e,...t}}=o;if(!e)return;const s=(u=(d=t.pages)==null?void 0:d[e])==null?void 0:u.currentSectionId;if(!s)return;const c=(S=(f=n.pages[e])==null?void 0:f.dataSource)==null?void 0:S[s];if(!c)return;const{currentLocale:i,defaultLocale:r,fallbackLocale:a}=this.currentLocaleMap;if(i&&c[i])return c[i];if(r&&c[r])return c[r];if(a&&c[a])return c[a]},get currentLocaleMap(){var c;const{localState:{currentLocale:e},state:{supportedLocales:t,config:{defaultLocale:s}}}=o;return{currentLocale:e,defaultLocale:s,fallbackLocale:((c=t==null?void 0:t[0])==null?void 0:c.locale)??"en"}},get currentRoute(){var t;const{localState:{currentRouteId:e}}=o;return e?(t=n.routes)==null?void 0:t[e]:void 0},get currentPageModel(){const e=this.currentPage??null;if(e){const t=new J.TemplateModel({childrenProperties:J.PAGES_KIT_CHILDREN_PROPERTIES,locale:P.currentLocale});return t.parse(e),t}}}),[JSON.stringify(P),n]),j=m.useMemo(()=>({setCurrentSectionId:(e,t)=>{var s,c;e===P.currentPageId&&t===((c=(s=P.pages)==null?void 0:s[e])==null?void 0:c.currentSectionId)||(L(R.joinURL("/admin/maker",O??"","pages",e)),l(i=>x.produce(i,r=>{var a;r.currentPageId=e,r.currentComponentId=void 0,t!==void 0&&(r.pages??(r.pages={}),(a=r.pages)[e]??(a[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!==P.currentComponentId&&(L(R.joinURL("/admin/maker",O??"","components",e)),l(t=>x.produce(t,s=>{s.currentComponentId=e})))},setCurrentRouteId:({routeId:e,dynamicParams:t})=>{l(s=>x.produce(s,c=>{c.currentRouteId=e,c.currentDynamicParams=t}))},setCustomComponentPreviewerProperties:(()=>{const e={};let t="";const s=V.default(()=>{l(c=>x.produce(c,i=>{i.customComponentPreviewerProperties??(i.customComponentPreviewerProperties={}),i.customComponentPreviewerProperties[t]={...i.customComponentPreviewerProperties[t],...e[t]},delete e[t]}))},5);return(c,i)=>{const r=e[c]??{};Object.assign(r,i),e[c]=r,t=c,s()}})(),setRouteGenerateProcess:e=>{l(t=>x.produce(t,s=>{e?s.routeGenerateProcess={...s.routeGenerateProcess,...e}:s.routeGenerateProcess={}}))},resetRouteGenerateProcess:()=>{l(e=>x.produce(e,t=>{t.routeGenerateProcess={progress:"complete"}}))}}),[l,L,O,p]),_=m.useMemo(()=>({addPage:(e,t)=>{var i,r,a,d,u,f;const s=(e==null?void 0:e.id)??k(),c={...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:((i=e==null?void 0:e.templateConfig)==null?void 0:i.isTemplate)??!0,displayTemplateId:((r=e==null?void 0:e.templateConfig)==null?void 0:r.displayTemplateId)??void 0,dataSourceIds:((a=e==null?void 0:e.templateConfig)==null?void 0:a.dataSourceIds)??void 0,dataSourceParameters:((d=e==null?void 0:e.templateConfig)==null?void 0:d.dataSourceParameters)??{},enabledGenerate:((u=e==null?void 0:e.templateConfig)==null?void 0:u.enabledGenerate)??!1,agentId:((f=e==null?void 0:e.templateConfig)==null?void 0:f.agentId)??void 0}};return o.doc.transact(()=>{n.pages[c.id]=c,n.pageIds.splice(t??n.pageIds.length,0,c.id)}),c},addRoute:(e,t)=>{const s=(e==null?void 0:e.id)??k(),c={...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 o.doc.transact(()=>{n.routes??(n.routes={}),n.routeIds??(n.routeIds=[]),n.routes[c.id]=c,n.routeIds.splice(t??n.routeIds.length,0,c.id)}),c},deleteRoute:e=>{var s;if(!e)return;const t=(s=n.routeIds)==null?void 0:s.indexOf(e);t!==void 0&&t!==-1&&o.doc.transact(()=>{var c,i;(c=n.routeIds)==null||c.splice(t,1),(i=n.routes)==null||delete i[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,c=s.indexOf(e);c>=0&&s.splice(t,0,...s.splice(c,1))},addSection:(e,t,s,c)=>{const i=n.pages[e];if(!i)throw new Error(`Page ${e} is not exists`);const r={...t,id:t.id??k(),isTemplateSection:t.isTemplateSection??!0,llmConfig:t.llmConfig??{}},a=pe.default(r.locales);return delete r.locales,o.doc.transact(()=>{var d,u,f;if(c&&c.component==="layout-block"){const S=(d=p.currentPageModel)==null?void 0:d.getComponentById(c.id);S&&((u=S.model).sections??(u.sections={}),S.model.sections[r.id]=r,(f=S.model).sectionIds??(f.sectionIds=[]),S.model.sectionIds.push(r.id))}else i.sections[r.id]=r,i.sectionIds.splice(s??i.sectionIds.length,0,r.id);a&&(i.dataSource??(i.dataSource={}),i.dataSource[r.id]=a)}),r},deleteSection:(e,t)=>{const s=n.pages[e];if(!s)throw new Error(`Page ${e} is not exists`);o.doc.transact(()=>{var a,d,u,f,S,M;const c=[],i=(a=p.currentPageModel)==null?void 0:a.getComponentById(t),r=i==null?void 0:i.parent;if(i&&(c.push(i.model.id,...i.all().map(I=>I.model.id)),(r==null?void 0:r.model.component)==="layout-block")){const I=(d=r.model.sectionIds)==null?void 0:d.indexOf(t);I!==void 0&&I!==-1&&((u=r.model.sectionIds)==null||u.splice(I,1),(f=r.model.sections)==null||delete f[t]),(S=r.model.config)!=null&&S.gridSettings&&Object.keys(r.model.config.gridSettings).forEach(y=>{var v;try{(v=r.model.config.gridSettings[y])==null||delete v[t]}catch{}}),((M=r.model.config)==null?void 0:M.backgroundSectionId)===t&&(r.model.config.backgroundSectionId=void 0)}c.forEach(I=>{var v,g;const y=s.sectionIds.indexOf(I);y!==-1&&s.sectionIds.splice(y,1),s.sections[I]&&delete s.sections[I],(v=s.dataSource)!=null&&v[I]&&((g=s.dataSource)==null||delete g[I])})})},lockSection:(e,t)=>{var i,r;if(!n.pages[e])throw new Error(`Page ${e} is not exists`);const c=(r=(i=p.currentPageModel)==null?void 0:i.getComponentById(t))==null?void 0:r.model;c&&(c.locked=!c.locked)},toggleSectionVisibility:(e,t,s)=>{var r,a;if(!n.pages[e])throw new Error(`Page ${e} is not exists`);const i=(a=(r=p.currentPageModel)==null?void 0:r.getComponentById(t))==null?void 0:a.model;i&&(i.visibility=s)},moveSection:(e,t,s,c)=>{var r,a,d,u,f,S,M,I;if(!n.pages[e])throw new Error(`Page ${e} is not exists`);if(c&&c!==t){const y=(r=p.currentPageModel)==null?void 0:r.getComponentById(t),v=(a=p.currentPageModel)==null?void 0:a.getComponentById(c),g=y==null?void 0:y.parent,b=v==null?void 0:v.parent;b&&g&&((d=b==null?void 0:b.model)==null?void 0:d.id)===((u=g==null?void 0:g.model)==null?void 0:u.id)?o.doc.transact(()=>{g.model.sectionIds.splice(y.getIndex(),1),g.model.sectionIds.splice(v.getIndex(),0,t)}):b&&g&&((f=b==null?void 0:b.model)==null?void 0:f.id)!==((S=g==null?void 0:g.model)==null?void 0:S.id)&&t!==c&&!((I=(M=y==null?void 0:y.model)==null?void 0:M.sectionIds)!=null&&I.includes(c))&&o.doc.transact(()=>{b.model.sections[t]=JSON.parse(JSON.stringify(y.model)),b.model.sectionIds.splice(v.getIndex(),0,t),g.model.sectionIds.splice(y.getIndex(),1),delete g.model.sections[t]})}},copySection:(e,t)=>{var u,f,S;if(!n.pages[e])throw new Error(`Page ${e} is not exists`);const c=(u=p.currentPageModel)==null?void 0:u.getComponentById(t);if(!(c!=null&&c.model))throw new Error(`Section ${t} is not exists`);const i=JSON.parse(JSON.stringify(c.model)),r=Re(i),a=r.id,d=c==null?void 0:c.parent;return d&&(d.model.sections[a]=r,d.model.sectionIds.push(a),j.setCurrentSectionId(e,a),(S=(f=p.currentPage)==null?void 0:f.dataSource)!=null&&S[t]&&(p.currentPage.dataSource[a]=JSON.parse(JSON.stringify(p.currentPage.dataSource[t])))),r},addDataSource:e=>{const t=e.id??k(),s={...e??{},id:t,createdAt:new Date().toISOString()};return o.doc.transact(()=>{n.dataSourceIds??(n.dataSourceIds=[]),n.dataSources??(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,p]);return{...o,state:n,actions:_,localActions:j,...p}},$=()=>{const{projectId:o}=W.useParams();return o??K()??""},xe=()=>window.__PROJECT_SLUG__??"";function Q(o){var P,L;const{resources:n}=o;if(!n.components)return{};const l={};return(L=(P=window==null?void 0:window.blocklet)==null?void 0:P.componentMountPoints)==null||L.forEach(O=>{l[O.did]=O}),Object.fromEntries(Object.entries(n.components).map(([O,{blockletId:p,component:j}])=>{var _;return[O,{data:j,blockletId:p,blockletTitle:((_=l[p])==null?void 0:_.title)||p}]}))}function X(o){const{components:n}=o;return n||{}}function Y(o){return{...Q(o),...X(o)}}const ke=()=>Y(z().state);function Re(o){const n=JSON.parse(JSON.stringify(o)),l=k();return{...n,id:l}}exports.ErrorView=Ie;exports.StoreProvider=_e;exports.api=T;exports.autoResizeImage=be;exports.getAllComponents=Y;exports.getCustomComponents=X;exports.getImageAbsoluteUrl=je;exports.getMountPoint=ge;exports.getProjectIdFromPathnameOrWindow=K;exports.getProjectPageVersionKey=Pe;exports.getResourceComponents=Q;exports.getWssURL=he;exports.nextId=k;exports.transformValue=we;exports.useAllComponents=ke;exports.useProjectId=$;exports.useProjectSlug=xe;exports.useStore=z;
|