@blocklet/pages-kit-inner-components 0.4.43 → 0.4.44
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/_chunks/{draft-data-kZlleQ4E.js → draft-data-CMqq2YH1.js} +1 -1
- package/lib/cjs/_chunks/{home-Ce3-4w2I.js → home-BFxAZSGy.js} +3 -3
- package/lib/cjs/_chunks/{publish-button-NBzp4nrV.js → publish-button-DFR8IHQq.js} +1 -1
- package/lib/cjs/_chunks/state-BjeG4kYg.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/setting.js +3 -3
- package/lib/es/_chunks/{draft-data-CkmH99IX.js → draft-data-vlK5oTGT.js} +1 -1
- package/lib/es/_chunks/{home-DDJ3wLld.js → home-BTLUdaL7.js} +3 -3
- package/lib/es/_chunks/{publish-button-Ca4oEKdb.js → publish-button-BWD3lOEM.js} +2 -2
- package/lib/es/_chunks/{state-kKXkQecK.js → state-DqChB5ys.js} +90 -89
- package/lib/es/home.js +2 -2
- package/lib/es/setting.js +525 -523
- package/package.json +3 -3
- package/lib/cjs/_chunks/state-B6B5oPws.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit-inner-components",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.44",
|
|
4
4
|
"description": "Pages Kit inner components library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -202,8 +202,8 @@
|
|
|
202
202
|
"yaml": "^2.5.0",
|
|
203
203
|
"yjs": "^13.6.18",
|
|
204
204
|
"zustand": "^4.5.5",
|
|
205
|
-
"@blocklet/pages-kit": "^0.4.
|
|
206
|
-
"@blocklet/pages-kit-block-studio": "^0.4.
|
|
205
|
+
"@blocklet/pages-kit": "^0.4.44",
|
|
206
|
+
"@blocklet/pages-kit-block-studio": "^0.4.44"
|
|
207
207
|
},
|
|
208
208
|
"devDependencies": {
|
|
209
209
|
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const P=require("react/jsx-runtime"),I=require("@mui/material"),Q=require("gradient-parser"),X=require("tinycolor2"),j=require("ufo"),Y=require("@blocklet/js-sdk"),Z=require("yaml"),W=require("@syncedstore/core"),H=require("@syncedstore/react"),ee=require("ahooks"),E=require("immer"),te=require("js-cookie"),ne=require("lodash/debounce"),oe=require("nanoid"),d=require("react"),N=require("react-router-dom"),re=require("y-indexeddb"),se=require("y-websocket"),ce=require("yjs"),x=e=>e&&e.__esModule?e:{default:e};function ie(e){if(e&&e.__esModule)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const i in e)if(i!=="default"){const u=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(n,i,u.get?u:{enumerable:!0,get:()=>e[i]})}}return n.default=e,Object.freeze(n)}const ae=x(Q),ue=x(X),de=ie(Z),le=x(W),fe=x(te),F=x(ne);function V(){const{pathname:e}=window.location,n=e.match(/\/admin\/(maker|previewer)\/([^/]+)/),i=n==null?void 0:n[2],u=window.__PROJECT_ID__;if(!i&&!u)throw new Error("Unable to get projectId from pathname");return i||u}function me(e){return`${e}:pages:version`}function pe(e,n){return n==="yaml"?de.stringify(e,{indent:2}):n==="json"?JSON.parse(JSON.stringify(e||"{}")):n==="array"?JSON.parse(JSON.stringify(e||"[]")):e}function ge({error:e}){return P.jsx(I.Box,{children:P.jsx(I.Alert,{severity:"error",children:e.message})})}var T;const v=((T=window.blocklet)==null?void 0:T.prefix)||"/",O=Y.createAxios({timeout:200*1e3}),Se=window.location.protocol==="https:"?"wss":"ws",we=e=>j.joinURL(`${Se}://${window.location.hostname}`,v,`api/${e}/ws/pages`),he="z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";var $;($=blocklet==null?void 0:blocklet.componentMountPoints.find(e=>e.did===he))!=null&&$.mountPoint||j.joinURL(v,"/image-bin");function Pe(e){return e&&!/^(https?:\/\/|\/)/.test(e)?window.location.origin+j.joinURL(v,"uploads",e):e}const je=window.innerWidth<=750;function ye(e,n,i){if(!e||/\.gif/.test(e))return e;const u=(je?n/1.5:n)*(i==="quality"?1.5:1);return ke(e,{imageFilter:"resize",w:u,f:"webp"})}function ke(e,n){return!e||!n?e:j.withQuery(e,n)}function z(e){if(e!=null&&e.trim())try{return ae.default.parse(e),!0}catch{return!1}return!1}function be(e){return typeof e!="string"?!1:!!(z(e)||ue.default(e).isValid())}async function Ie(e){return O.get(`/api/projects/${e}`).then(n=>n.data)}async function xe(e){return O.post(`/api/projects/${e.id}/update`,e).then(n=>n.data)}const Ce=500,_=oe.customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789",16),B=d.createContext(null);function Ee({url:e,name:n,children:i,waitingSynced:u}){const[f,l]=d.useState(!1),S=L(),y=`${S}:MakerLocalState`,t=`${S}:${n}`,[r,o]=ee.useLocalStorageState(y,{defaultValue:{},listenStorageChange:!0}),s=d.useRef(r);s.current=r;const a=d.useMemo(()=>le.default({pages:{},pageIds:[],components:{},supportedLocales:[],config:{},resources:{}}),[]),c=d.useMemo(()=>W.getYjsDoc(a),[a]);d.useMemo(()=>new re.IndexeddbPersistence(t,c),[t,c]);const w=d.useMemo(()=>new se.WebsocketProvider(e,t,c,{params:{token:fe.default.get("login_token")}}),[e,t,c]),k=d.useMemo(()=>new ce.UndoManager([c.getArray("pageIds"),c.getMap("pages"),c.getArray("supportedLocales"),c.getMap("config")],{doc:c}),[c]),[b,C]=d.useState(null),[A,q]=d.useState(!1),[M,R]=d.useState(void 0),D=d.useCallback(async()=>{if(S){q(!0);try{const m=await Ie(S);C(m)}catch(m){console.error("Failed to fetch project:",m)}finally{q(!1)}}},[S]),U=d.useCallback(async(m,p)=>{var h;if(R(void 0),!!S){p!=null&&p.optimisticUpdate&&b&&C(g=>({...g,...m}));try{const g=await xe({...m});C(g)}catch(g){console.error("Failed to update project:",g),p!=null&&p.optimisticUpdate&&C(b),R((h=g==null?void 0:g.response)==null?void 0:h.data)}}},[S,b]);d.useEffect(()=>{S&&D()},[S,D]);const K=d.useMemo(()=>({doc:c,state:a,localState:r,setLocalState:m=>o(typeof m=="function"?p=>m(p??{}):m),undoManager:k,projectState:{project:b,isLoadingProject:A,error:M},updateProject:U}),[c,a,JSON.stringify(r),o,k,b,A,U,M]);return d.useEffect(()=>{k.on("stack-item-added",({stackItem:m})=>{const{currentPageId:p,currentLocale:h,pages:g}=s.current;m.meta.set("localState",{currentPageId:p,currentLocale:h,pages:g})}),k.on("stack-item-popped",({stackItem:m})=>{const p=m.meta.get("localState");p&&o(h=>({...h,...p}))})},[k,o]),d.useEffect(()=>{w.awareness.setLocalState(r)},[w,r]),d.useEffect(()=>{w.once("synced",()=>l(!0));const m=()=>{o(g=>({...g,networkStatus:void 0}))},p=()=>{o(g=>({...g,networkStatus:"offline"}))},h=F.default(({status:g})=>{g==="connected"?m():g==="disconnected"&&p()},Ce);return w.on("status",h),window.addEventListener("online",m),window.addEventListener("offline",p),()=>{w.off("status",h),window.removeEventListener("online",m),window.removeEventListener("offline",p)}},[w,o]),u&&!f?null:P.jsx(B.Provider,{value:K,children:i})}const G=()=>{const e=d.useContext(B);if(!e)throw new Error("Context is null");const n=H.useSyncedStore(e.state),{setLocalState:i,localState:u}=e,f=N.useNavigate(),l=L(),S=d.useMemo(()=>({setCurrentSectionId:(t,r)=>{var o,s;t===u.currentPageId&&r===((s=(o=u.pages)==null?void 0:o[t])==null?void 0:s.currentSectionId)||(f(j.joinURL("/admin/maker",l??"","pages",t)),i(a=>E.produce(a,c=>{var w;c.currentPageId=t,c.currentComponentId=void 0,c.componentDebugProps={},r!==void 0&&(c.pages??(c.pages={}),(w=c.pages)[t]??(w[t]={}),c.pages[t].currentSectionId=r??void 0),r?window.sessionStorage.setItem("iframe_show_id",`"${r}"`):window.sessionStorage.removeItem("iframe_show_id")})))},setCurrentComponentId:t=>{t!==u.currentComponentId&&(f(j.joinURL("/admin/maker",l??"","components",t)),i(r=>E.produce(r,o=>{o.currentComponentId=t,o.componentDebugProps={}})))},setComponentDebugProps:(()=>{const t={},r=F.default(()=>{i(o=>E.produce(o,s=>{s.componentDebugProps={...s==null?void 0:s.componentDebugProps,...t},Object.keys(t).forEach(a=>delete t[a])}))},5);return o=>{Object.assign(t,o),r()}})()}),[i,f,l]),y=d.useMemo(()=>({addPage:(t,r)=>{const o=(t==null?void 0:t.id)??_(),s={...t,id:o,createdAt:(t==null?void 0:t.createdAt)??new Date().toISOString(),updatedAt:(t==null?void 0:t.updatedAt)??new Date().toISOString(),publishedAt:new Date(0).toISOString(),slug:(t==null?void 0:t.slug)??`/${o}`,sections:(t==null?void 0:t.sections)??{},sectionIds:(t==null?void 0:t.sectionIds)??[],isPublic:(t==null?void 0:t.isPublic)??!0,isTemplate:(t==null?void 0:t.isTemplate)??!1};return e.doc.transact(()=>{n.pages[s.id]=s,n.pageIds.splice(r??n.pageIds.length,0,s.id)}),s},deletePage:t=>{const r=n.pageIds.indexOf(t);r!==-1&&e.doc.transact(()=>{n.pageIds.splice(r,1),delete n.pages[t]})},movePage:(t,r)=>{const{pageIds:o}=n,s=o.indexOf(t);s>=0&&o.splice(r,0,...o.splice(s,1))},addSection:(t,r,o)=>{const s=n.pages[t];if(!s)throw new Error(`Page ${t} is not exists`);const a={...r,id:r.id??_(),isTemplateSection:r.isTemplateSection??!1};return e.doc.transact(()=>{s.sections[a.id]=a,s.sectionIds.splice(o??s.sectionIds.length,0,a.id)}),a},deleteSection:(t,r)=>{const o=n.pages[t];if(!o)throw new Error(`Page ${t} is not exists`);const s=o.sectionIds.indexOf(r);s!==-1&&e.doc.transact(()=>{o.sectionIds.splice(s,1),delete o.sections[r]})},toggleSectionVisibility:(t,r,o)=>{const s=n.pages[t];if(!s)throw new Error(`Page ${t} is not exists`);const a=s.sections[r];a&&(a.visibility=o)},moveSection:(t,r,o)=>{const s=n.pages[t];if(!s)throw new Error(`Page ${t} is not exists`);const{sectionIds:a}=s,c=a.indexOf(r);c>=0&&a.splice(o,0,...a.splice(c,1))}}),[n,e.doc]);return{...e,state:n,actions:y,localActions:S,get currentPage(){const{localState:{currentPageId:t}}=e;return t?n.pages[t]:void 0},get currentSection(){var s,a,c;const{localState:{currentPageId:t,...r}}=e;if(!t)return;const o=(a=(s=r.pages)==null?void 0:s[t])==null?void 0:a.currentSectionId;if(o)return(c=n.pages[t])==null?void 0:c.sections[o]}}},L=()=>{const{projectId:e}=N.useParams();return e??V()};function _e(e){var u,f;const{resources:n}=e;if(!n.components)return{};const i={};return(f=(u=window==null?void 0:window.blocklet)==null?void 0:u.componentMountPoints)==null||f.forEach(l=>{i[l.did]=l}),Object.fromEntries(Object.entries(n.components).map(([l,{blockletId:S,component:y}])=>{var t;return[l,{data:y,blockletId:S,blockletTitle:((t=i[S])==null?void 0:t.title)||S}]}))}function ve(e){const{components:n}=e;return n||{}}function J(e){return{..._e(e),...ve(e)}}const Oe=()=>J(G().state),Le=[/\.\./,/<[^>]*>/,/%[0-9a-f]{2}/i,/[<>'"%;{}()\\]/,/\x00/,/\n|\r|\t|\v|\f/,/[^a-zA-Z0-9-_@/]/];function Ae(e,n,i){const u=[];{let f;n.slug?n.slug.startsWith("/")?n.slug!=="/"&&n.slug.endsWith("/")?f=e("maker.properties.pathCheckEndWithoutSlash"):/\/{2,}/.test(n.slug)?f=e("maker.properties.pathCheckConsecutiveSlash"):/\s/.test(n.slug)?f=e("maker.properties.pathCheckWhitespace"):Le.some(l=>l.test(n.slug))?f=e("maker.properties.pathCheckInvalid"):Object.values(i.pages).some(l=>(l==null?void 0:l.id)!==n.id&&(l==null?void 0:l.slug)===n.slug)&&(f=e("maker.properties.pathCheckAlreadyExist")):f=e("maker.properties.pathCheckStartWithSlash"):f=e("maker.properties.pathCheckRequired"),f&&u.push({path:["path"],message:f})}return u.length>0?u:null}function qe({errors:e,...n}){return e!=null&&e.length?P.jsx(I.Tooltip,{...n,title:P.jsx(I.Box,{children:e.map((i,u)=>P.jsx(I.Box,{children:i.message},u))})}):null}exports.ErrorView=ge;exports.PageErrorTip=qe;exports.StoreProvider=Ee;exports.api=O;exports.autoResizeImage=ye;exports.checkPage=Ae;exports.getAllComponents=J;exports.getImageAbsoluteUrl=Pe;exports.getProjectIdFromPathnameOrWindow=V;exports.getProjectPageVersionKey=me;exports.getWssURL=we;exports.isColorString=be;exports.isGradient=z;exports.nextId=_;exports.transformValue=pe;exports.useAllComponents=Oe;exports.useProjectId=L;exports.useStore=G;
|