@blocklet/pages-kit-inner-components 0.5.25 → 0.5.27
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-BEJTeOmf.js → array-CJC7ex3i.js} +1 -1
- package/lib/cjs/chunks/{config-string-DOydtRKn.js → config-string-C4Q0hgG0.js} +1 -1
- package/lib/cjs/chunks/{draft-data-B19cThO_.js → draft-data-Cu9gua-P.js} +1 -1
- package/lib/cjs/chunks/{home-DQhlP6NG.js → home-CimGvyT9.js} +3 -3
- package/lib/cjs/chunks/publish-button-DvwoFH1F.js +1 -0
- package/lib/cjs/chunks/state-jCG5gSUJ.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/locales.js +1 -1
- package/lib/cjs/setting.js +1 -1
- package/lib/es/add-component.js +3 -3
- package/lib/es/chunks/{array-uzhVAv0S.js → array-9j8tOSbO.js} +1 -1
- package/lib/es/chunks/{config-string-BloDH_C5.js → config-string-CNLg1EYu.js} +1 -1
- package/lib/es/chunks/{draft-data-hZqezCbE.js → draft-data-hSHLdxKp.js} +1 -1
- package/lib/es/chunks/{home-BG1ZwC5Y.js → home-CNk6U8FU.js} +4 -4
- package/lib/es/chunks/{publish-button-CyxGsQeI.js → publish-button-BftBlabj.js} +41 -41
- package/lib/es/chunks/{state-TRx4qpp_.js → state-D5BnGunt.js} +82 -73
- package/lib/es/home.js +3 -3
- package/lib/es/locales.js +12 -4
- package/lib/es/setting.js +2 -2
- package/package.json +3 -3
- package/lib/cjs/chunks/publish-button-CK7LTkaC.js +0 -1
- package/lib/cjs/chunks/state-B4V60dHq.js +0 -1
package/lib/es/home.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
|
-
import "./chunks/state-
|
|
2
|
+
import "./chunks/state-D5BnGunt.js";
|
|
3
3
|
import "@arcblock/ux/lib/Locale/context";
|
|
4
4
|
import "@arcblock/ux/lib/Result";
|
|
5
5
|
import "@blocklet/pages-kit/builtin/page/header";
|
|
@@ -21,8 +21,8 @@ import "react-helmet";
|
|
|
21
21
|
import "react-router-dom";
|
|
22
22
|
import "react-use";
|
|
23
23
|
import "ufo";
|
|
24
|
-
import "./chunks/array-
|
|
25
|
-
import { a as R, P as S, d as W, c as j, b as k, T as q, H as v } from "./chunks/home-
|
|
24
|
+
import "./chunks/array-9j8tOSbO.js";
|
|
25
|
+
import { a as R, P as S, d as W, c as j, b as k, T as q, H as v } from "./chunks/home-CNk6U8FU.js";
|
|
26
26
|
import "./chunks/session-CVblGhSp.js";
|
|
27
27
|
export {
|
|
28
28
|
R as HomeView,
|
package/lib/es/locales.js
CHANGED
|
@@ -39,7 +39,7 @@ const t = e({
|
|
|
39
39
|
topToggle: {
|
|
40
40
|
sitemap: "Sitemap",
|
|
41
41
|
data: "Data Source",
|
|
42
|
-
page: "Page"
|
|
42
|
+
page: "Page Templates"
|
|
43
43
|
},
|
|
44
44
|
dataSourceEmpty: 'No data sources yet, click "Add" button to create',
|
|
45
45
|
selectDataSource: "Please select a data source from the list",
|
|
@@ -89,7 +89,7 @@ const t = e({
|
|
|
89
89
|
pageTitle: "Pages Editor",
|
|
90
90
|
save: "Save",
|
|
91
91
|
publish: "Publish",
|
|
92
|
-
publishToProduction: "Publish",
|
|
92
|
+
publishToProduction: "Publish to production",
|
|
93
93
|
publishToProductionTip: "Anyone can see production version",
|
|
94
94
|
publishConfirmContent: "Publish to",
|
|
95
95
|
publishSelectPagesMessage: "Please select the pages to publish",
|
|
@@ -125,6 +125,10 @@ const t = e({
|
|
|
125
125
|
},
|
|
126
126
|
export: "Export",
|
|
127
127
|
noPreviewAvailable: "No preview available",
|
|
128
|
+
networkStatus: {
|
|
129
|
+
online: "Network connected - Your changes will sync to server in real-time",
|
|
130
|
+
offline: "Network disconnected - Your changes will sync automatically when connection is restored"
|
|
131
|
+
},
|
|
128
132
|
routePreview: {
|
|
129
133
|
loading: "Loading...",
|
|
130
134
|
generatingPageStructure: "Generating page content structure...",
|
|
@@ -524,7 +528,7 @@ const t = e({
|
|
|
524
528
|
topToggle: {
|
|
525
529
|
sitemap: "站点地图",
|
|
526
530
|
data: "数据源",
|
|
527
|
-
page: "
|
|
531
|
+
page: "页面模板"
|
|
528
532
|
},
|
|
529
533
|
dataSourceEmpty: '暂无数据源,点击"添加"按钮创建',
|
|
530
534
|
selectDataSource: "请选择左侧的数据源进行操作",
|
|
@@ -574,7 +578,7 @@ const t = e({
|
|
|
574
578
|
pageTitle: "页面编辑器",
|
|
575
579
|
save: "保存",
|
|
576
580
|
publish: "发布",
|
|
577
|
-
publishToProduction: "
|
|
581
|
+
publishToProduction: "发布到正式版",
|
|
578
582
|
publishToProductionTip: "任何人都可以看到正式版",
|
|
579
583
|
publishConfirmContent: "发布到",
|
|
580
584
|
publishSelectPagesMessage: "请选择要发布的页面",
|
|
@@ -610,6 +614,10 @@ const t = e({
|
|
|
610
614
|
},
|
|
611
615
|
export: "导出",
|
|
612
616
|
noPreviewAvailable: "无可用预览",
|
|
617
|
+
networkStatus: {
|
|
618
|
+
online: "网络连接正常 - 您的修改将实时同步到服务器",
|
|
619
|
+
offline: "网络连接中断 - 您的修改将在网络恢复后自动同步"
|
|
620
|
+
},
|
|
613
621
|
routePreview: {
|
|
614
622
|
loading: "加载中...",
|
|
615
623
|
generatingPageStructure: "正在生成页面内容结构...",
|
package/lib/es/setting.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as t, jsxs as O, Fragment as X } from "react/jsx-runtime";
|
|
2
|
-
import { t as ve, g as Te, b as ce, E as ot, n as Ke, h as xe } from "./chunks/state-
|
|
2
|
+
import { t as ve, g as Te, b as ce, E as ot, n as Ke, h as xe } from "./chunks/state-D5BnGunt.js";
|
|
3
3
|
import de from "@arcblock/ux/lib/Empty";
|
|
4
4
|
import { useLocaleContext as C } from "@arcblock/ux/lib/Locale/context";
|
|
5
5
|
import { CodeEditor as ge } from "@blocklet/code-editor";
|
|
@@ -12,7 +12,7 @@ import A from "lodash/sortBy";
|
|
|
12
12
|
import { useCallback as D, useMemo as ne, useRef as J, useId as gt, useEffect as $, useState as Q } from "react";
|
|
13
13
|
import { useUpdate as _e } from "react-use";
|
|
14
14
|
import { ColorItem as Pt, ConfigColorDialog as wt } from "@blocklet/pages-kit/builtin/color-picker";
|
|
15
|
-
import { C as kt } from "./chunks/config-string-
|
|
15
|
+
import { C as kt } from "./chunks/config-string-CNLg1EYu.js";
|
|
16
16
|
import we from "lodash/isEmpty";
|
|
17
17
|
import He from "lodash/set";
|
|
18
18
|
import * as fe from "yaml";
|
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.27",
|
|
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.5.
|
|
209
|
-
"@blocklet/pages-kit-block-studio": "^0.5.
|
|
208
|
+
"@blocklet/pages-kit": "^0.5.27",
|
|
209
|
+
"@blocklet/pages-kit-block-studio": "^0.5.27"
|
|
210
210
|
},
|
|
211
211
|
"devDependencies": {
|
|
212
212
|
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),F=require("./state-B4V60dHq.js"),W=require("@arcblock/ux/lib/Locale/context"),ee=require("@arcblock/ux/lib/Toast"),te=require("@blocklet/pages-kit/utils/route"),P=require("@mui/icons-material"),J=require("@mui/lab"),s=require("@mui/material"),se=require("immer"),ne=require("lodash/difference"),l=require("react"),ie=require("react-use"),re=require("./home-DQhlP6NG.js"),U=require("./array-BEJTeOmf.js"),G=r=>r&&r.__esModule?r:{default:r},$=G(ee),H=G(ne);function oe(r){const[j,k]=l.useState(!1);return e.jsx(J.LoadingButton,{...r,loading:r.loading||j,onClick:u=>{var b;const p=(b=r.onClick)==null?void 0:b.call(r,u);p instanceof Promise&&(k(!0),p.finally(()=>{k(!1)}))}})}const ae=s.createSvgIcon(e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M7.75732 16.2426L16.2426 7.75736",stroke:"#4B5563",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M16.2426 16.2426L7.75732 7.75735",stroke:"#4B5563",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),"Close");function le(){const[r,j]=l.useState(),k=l.useMemo(()=>r?e.jsx(s.Dialog,{...r}):null,[r]),u=l.useCallback(()=>{j(void 0)},[]),p=l.useCallback(({title:b,content:d,cancelText:S="Cancel",okText:f="Ok",onOk:g,onClose:c,okIcon:O,okColor:w="primary",cancelColor:y="primary",DialogContentProps:A,form:E,...z})=>{j({...z,open:!0,children:e.jsxs("form",{onSubmit:v=>v.preventDefault(),children:[b&&e.jsxs(s.DialogTitle,{className:"between",zIndex:"appBar",bgcolor:"background.paper",sx:{borderBottom:v=>`1px solid ${v.palette.divider}`},children:[e.jsx(s.Box,{children:b}),e.jsx(s.IconButton,{size:"small",onClick:async()=>{u(),c==null||c()},children:e.jsx(ae,{})})]}),d&&e.jsx(s.DialogContent,{...A,sx:{mt:-3,...A==null?void 0:A.sx},children:e.jsx(s.Box,{pt:3,children:d})}),e.jsxs(s.DialogActions,{children:[e.jsx(s.Button,{variant:"outlined",color:y||"primary",onClick:c??u,children:S}),e.jsx(oe,{variant:"contained",color:w||"primary",startIcon:O,loadingPosition:O?"start":"center",onClick:async()=>{await(g==null?void 0:g()),u()},type:"submit",children:f})]})]}),onClose:c??u})},[u]);return{dialog:k,showDialog:p,closeDialog:u}}const ce=l.forwardRef(({mode:r,state:j},k)=>{const{t:u}=W.useLocaleContext(),[p,b]=l.useState(!1),{dialog:d,showDialog:S}=le(),f=F.useProjectId(),g=l.useCallback(O=>{let w=[];S({title:u("maker.publishToProduction"),content:e.jsxs(s.Box,{sx:{minWidth:300},children:[e.jsx(s.Alert,{color:"warning",icon:e.jsx(P.Warning,{}),children:u("maker.publishToProductionTip")}),e.jsx(s.Box,{maxHeight:"50vh",overflow:"auto",mt:2,children:e.jsx(de,{state:j,toMode:r,onChange:y=>w=y,defaultRouteIds:O})})]}),okText:u("maker.publish"),cancelText:u("common.cancel"),onOk:async()=>{if((w==null?void 0:w.length)===0){const y=u("maker.publishSelectPagesMessage");throw $.default.error(y),new Error(y)}localStorage.setItem(F.getProjectPageVersionKey(f??""),String(new Date().getTime())),b(!0);try{await U.publishPages({mode:r,routes:w}),$.default.success(u("maker.publishSuccessMessage"))}catch(y){throw $.default.error(y.message),y}finally{b(!1)}}})},[r,j,u,f,S]);l.useImperativeHandle(k,()=>({openPublishDialog:g}));const c=l.useCallback(()=>{g()},[g]);return e.jsxs(e.Fragment,{children:[e.jsx(J.LoadingButton,{color:"primary",variant:"contained",size:"small",sx:{mr:1},onClick:c,loading:p,disabled:p,children:u("maker.publishToProduction")}),d]})});function ue({routePathInfo:r,checked:j,onClick:k,route:u}){var d,S,f,g,c;const{t:p}=W.useLocaleContext(),b=!((d=r.routeMetaData)!=null&&d.publishedAt)||((S=r.routeMetaData)==null?void 0:S.updatedAt)&&new Date((f=r.routeMetaData)==null?void 0:f.updatedAt)>new Date((g=r.routeMetaData)==null?void 0:g.publishedAt);return e.jsx(s.ListItem,{sx:{pl:4,pr:3},disablePadding:!0,secondaryAction:e.jsxs(s.Box,{display:"flex",alignItems:"center",sx:{minWidth:"auto"},children:[b&&e.jsx(s.Box,{mr:.35,className:"visible",color:"warning.main",sx:{display:"flex",alignItems:"center"},title:p("maker.pages.needPublish"),children:e.jsx(s.Tooltip,{title:p("maker.pages.needPublish"),children:e.jsx(P.Sync,{fontSize:"small",sx:{fontSize:"16px"}})})}),(!((c=r.routeMetaData)!=null&&c.isPublic)||!u.isPublic)&&e.jsx(s.Box,{className:"visible",color:"warning.main",children:e.jsx(s.Tooltip,{title:p("maker.pages.notPublic"),children:e.jsx(P.VisibilityOff,{fontSize:"small",sx:{fontSize:"16px"}})})})]}),children:e.jsxs(s.ListItemButton,{onClick:k,dense:!0,children:[e.jsx(s.ListItemIcon,{children:e.jsx(s.Checkbox,{edge:"start",checked:j,tabIndex:-1})}),e.jsx(s.ListItemText,{primary:r.path,primaryTypographyProps:{fontSize:"0.8rem",fontStyle:"italic",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",pr:1}})]})})}function de({state:r,toMode:j,onChange:k,defaultRouteIds:u}){const{t:p,locale:b}=W.useLocaleContext(),[d,S]=l.useState(!1),[f,g]=l.useState(()=>u?Object.fromEntries(u.filter(t=>!t.includes("-")).map(t=>[t,!0])):{}),[c,O]=l.useState({}),[w,y]=l.useState(()=>u?Object.fromEntries(u.filter(t=>t.includes("-")).map(t=>[t,!0])):{}),[A,E]=l.useState({}),{loading:z,error:v,value:x}=ie.useAsync(()=>U.getPages({mode:j}),[j]);if(v)throw v;const T=l.useMemo(()=>r.routeIds||[],[r]),I=l.useMemo(()=>(x==null?void 0:x.pageIds)||[],[x]),L=l.useMemo(()=>!T||!r.routes?[]:JSON.parse(JSON.stringify(T)).sort((o,i)=>{var h,m;const n=(h=r.routes)==null?void 0:h[o],a=(m=r.routes)==null?void 0:m[i];return n!=null&&n.publishedAt&&new Date(n.publishedAt).getTime()<new Date(n.updatedAt).getTime()?-1:a!=null&&a.publishedAt&&new Date(a.publishedAt).getTime()<new Date(a.updatedAt).getTime()?1:new Date((n==null?void 0:n.updatedAt)??"").getTime()-new Date((a==null?void 0:a.updatedAt)??"").getTime()}),[r,T]),q=l.useMemo(()=>{if(!L)return[];if(!c)return L;const t=[...L].filter(o=>!c[o]);return Object.values(c).forEach(o=>{o.forEach(i=>{t.push(`${i.originalRouteId}-${i.paramOptionIds.join("-")}`)})}),t},[L,c]),B=l.useMemo(()=>!x||!I||!q?[]:H.default(I,q),[q,x,I]),C=l.useMemo(()=>T?[...T].concat(B):B,[T,B]),_=l.useCallback(()=>{const t={};L==null||L.forEach(o=>{var n;const i=(n=r.routes)==null?void 0:n[o];if(i&&i.params&&i.params.length>0&&i.paramsOptions&&i.paramsOptions.length>0){const a=te.generateParamCombinations({basePath:i.path,params:i.params,routeId:i.id,paramsOptions:i.paramsOptions,currentIndex:0,currentParams:[],currentOptionIds:[],result:[]});a.length>0&&(t[i.id]=a)}}),O(t)},[L,r.routes]);l.useEffect(()=>{_()},[_]),l.useEffect(()=>{E(t=>{const o={...t};return Object.keys(c).forEach(i=>{var n;c[i]&&((n=c[i])==null?void 0:n.length)>0&&o[i]===void 0&&(o[i]=!0)}),o})},[c]);const K=l.useRef(!0);l.useEffect(()=>{y(t=>{const o={...t};return Object.keys(c).length===0||(Object.keys(c).forEach(i=>{const n=c[i]||[],a=d||!!f[i];n.forEach(h=>{const m=`${i}-${h.paramOptionIds.join("-")}`;K.current?o[m]=a||t[m]||!1:o[m]=a})}),K.current=!1),o})},[f,c,d]);const Q=(t,o)=>{o.stopPropagation(),E(i=>{const n={...i};return n[t]=!n[t],n})},N=l.useCallback(t=>{g(o=>{const i=se.produce(o,n=>{d?(Object.assign(n,Object.fromEntries(C.map(a=>[a,!0]))),delete n[t]):n[t]?(delete n[t],B.includes(t)&&(T||[]).filter(a=>{var h,m;return((h=r.pages[a])==null?void 0:h.slug)===((m=x==null?void 0:x.pages[t])==null?void 0:m.slug)}).forEach(a=>{delete n[a]})):(n[t]=!0,T&&T.includes(t)&&B.filter(a=>{var h,m;return((h=x==null?void 0:x.pages[a])==null?void 0:h.slug)===((m=r.pages[t])==null?void 0:m.slug)}).forEach(a=>{n[a]=!0}))});return S(H.default(C,Object.keys(i)).length===0),i})},[d,C,B,r,x,T]),X=l.useCallback((t,o)=>{const i=`${t}-${o.paramOptionIds.join("-")}`;y(n=>{var m;const a={...n};a[i]=!a[i];const h=((m=c[t])==null?void 0:m.every(D=>a[`${t}-${D.paramOptionIds.join("-")}`]))??!1;return g(D=>{if(h&&!D[t])return{...D,[t]:!0};if(!h&&D[t]){const R={...D};return delete R[t],R}return D}),a})},[c]),Y=l.useCallback(()=>{S(t=>(t&&g({}),!t))},[]);return l.useEffect(()=>{const t=d?C:Object.keys(f),o=Object.entries(w).filter(([,n])=>n).map(([n])=>n).filter(n=>n!==void 0),i=Array.from(new Set([...t,...o]));k(d?null:i)},[d,f,w,C,k]),z?e.jsx(re.Loading,{sx:{my:4}}):e.jsxs(s.List,{disablePadding:!0,sx:{maxWidth:700},children:[e.jsx(s.ListItem,{sx:{position:"sticky",top:0,bgcolor:"background.paper",zIndex:1},disablePadding:!0,children:e.jsxs(s.ListItemButton,{onClick:Y,dense:!0,children:[e.jsx(s.ListItemIcon,{children:e.jsx(s.Checkbox,{edge:"start",checked:d,tabIndex:-1})}),e.jsx(s.ListItemText,{primary:p("common.all")})]})}),L.map(t=>{var D,R;const o=(D=r.routes)==null?void 0:D[t];if(!o)return null;const i=!1,n=c&&c[t]&&((R=c[t])==null?void 0:R.length)>0,a=A[t]!==!1,h=c[t]||[],m=!o.publishedAt||o.updatedAt&&new Date(o.updatedAt).getTime()>new Date(o.publishedAt).getTime();return e.jsxs(s.Box,{children:[e.jsx(s.ListItem,{sx:{pr:4},disablePadding:!0,secondaryAction:e.jsxs(s.Box,{sx:{display:"flex",alignItems:"center"},children:[m&&e.jsx(s.Tooltip,{title:p("maker.pages.needPublish"),children:e.jsx(P.Sync,{fontSize:"small",sx:{color:"warning.main",fontSize:16,mr:.35}})}),!o.isPublic&&e.jsx(s.Tooltip,{title:p("maker.pages.notPublic"),children:e.jsx(P.VisibilityOff,{fontSize:"small",sx:{color:"warning.main",fontSize:16,mr:.35}})}),i,n&&e.jsx(s.Box,{onClick:M=>Q(t,M),sx:{display:"inline-flex",alignItems:"center",mr:.35,cursor:"pointer",color:"info.main"},children:a?e.jsx(P.KeyboardArrowDown,{fontSize:"small",sx:{fontSize:"18px"}}):e.jsx(P.KeyboardArrowRight,{fontSize:"small",sx:{fontSize:"18px"}})})]}),children:e.jsxs(s.ListItemButton,{onClick:()=>N(t),dense:!0,children:[e.jsx(s.ListItemIcon,{children:e.jsx(s.Checkbox,{edge:"start",checked:d||!!f[t],tabIndex:-1})}),e.jsx(s.ListItemText,{primary:o.path,primaryTypographyProps:{noWrap:!0,textOverflow:"ellipsis"},secondaryTypographyProps:{noWrap:!0,textOverflow:"ellipsis"}})]})}),n&&e.jsx(s.Collapse,{in:a,children:e.jsx(s.Box,{children:h.map(M=>{const V=`${t}-${M.paramOptionIds.join("-")}`,Z=w[V]||!1;return e.jsx(ue,{routePathInfo:M,checked:d||Z,onClick:()=>X(t,M),route:o},V)})})})]},t)}),B.map(t=>{var i,n;const o=x==null?void 0:x.pages[t];return o?e.jsx(s.ListItem,{disablePadding:!0,secondaryAction:e.jsx(s.Chip,{color:"warning",label:"deleted",size:"small"}),children:e.jsxs(s.ListItemButton,{onClick:()=>N(t),dense:!0,children:[e.jsx(s.ListItemIcon,{children:e.jsx(s.Checkbox,{edge:"start",checked:d||!!f[t],tabIndex:-1})}),e.jsx(s.ListItemText,{primary:o.slug,secondary:(n=(i=o.locales)==null?void 0:i[b])==null?void 0:n.title,primaryTypographyProps:{noWrap:!0,textOverflow:"ellipsis"},secondaryTypographyProps:{noWrap:!0,textOverflow:"ellipsis"}})]})},t):null})]})}exports.default=ce;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const E=require("react/jsx-runtime"),$=require("@mui/material"),b=require("ufo"),Z=require("@blocklet/js-sdk"),H=require("lodash/isEmpty"),ee=require("yaml"),te=require("@arcblock/ux/lib/Locale/context"),N=require("@syncedstore/core"),ne=require("@syncedstore/react"),oe=require("ahooks"),C=require("immer"),re=require("lodash/debounce"),se=require("nanoid"),d=require("react"),V=require("react-router-dom"),ce=require("y-indexeddb"),ie=require("y-websocket"),ae=require("yjs");require("@blocklet/pages-kit/types");const _=t=>t&&t.__esModule?t:{default:t};function de(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=_(H),le=de(ee),fe=_(N),W=_(re),me=t=>{const n=blocklet==null?void 0:blocklet.componentMountPoints.find(i=>i.name===t);return n?n.mountPoint:"/"};function J(){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 Se(t){return`${t}:pages:version`}function we(t,n){return n==="yaml"?ue.default(t)?"":le.stringify(t,{indent:2}):n==="json"?JSON.parse(JSON.stringify(t||{})):n==="array"?JSON.parse(JSON.stringify(t||[])):t}function Pe({error:t}){return E.jsx($.Box,{children:E.jsx($.Alert,{severity:"error",children:t.message})})}var G;const L=((G=window.blocklet)==null?void 0:G.prefix)||"/",R=Z.createAxios({timeout:200*1e3}),pe=window.location.protocol==="https:"?"wss":"ws",Ie=t=>b.joinURL(`${pe}://${window.location.hostname}`,L,`api/${t}/ws/pages`),ge="z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";var F;(F=blocklet==null?void 0:blocklet.componentMountPoints.find(t=>t.did===ge))!=null&&F.mountPoint||b.joinURL(L,"/image-bin");function je(t){return t&&!/^(https?:\/\/|\/)/.test(t)?window.location.origin+b.joinURL(L,"uploads",t):t}const ye=window.innerWidth<=750;function Ce(t,n,i){if(!t||/\.gif/.test(t))return t;const S=(ye?n/1.5:n)*(i==="quality"?1.5:1);return be(t,{imageFilter:"resize",w:S,f:"webp"})}function be(t,n){return!t||!n?t:b.withQuery(t,n)}async function he(t){return R.get(`/api/projects/${t}`).then(n=>n.data)}async function ve(t){return R.post(`/api/projects/${t.id}/update`,t).then(n=>n.data)}const xe=500,x=se.customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789",16),z=d.createContext(null);function Oe({url:t,name:n,children:i,waitingSynced:S}){const[g,p]=d.useState(!1),{locale:j}=te.useLocaleContext(),w=A(),e=`${w}:MakerLocalState`,o=`${w}:${n}`,[s,r]=oe.useLocalStorageState(e,{defaultValue:{},listenStorageChange:!0}),c=d.useRef(s);c.current=s;const a=d.useMemo(()=>fe.default({dataSourceIds:[],dataSources:{},pages:{},pageIds:[],routes:{},routeIds:[],components:{},supportedLocales:[],config:{},resources:{}}),[]),u=d.useMemo(()=>N.getYjsDoc(a),[a]);d.useMemo(()=>new ce.IndexeddbPersistence(o,u),[o,u]);const P=d.useMemo(()=>new ie.WebsocketProvider(t,o,u,{params:{},resyncInterval:5*60*1e3}),[t,o,u]),h=d.useCallback(()=>{P&&(P.disconnect(),P.connect())},[P]),y=d.useMemo(()=>new ae.UndoManager([u.getArray("pageIds"),u.getMap("pages"),u.getArray("supportedLocales"),u.getMap("config")],{doc:u}),[u]),[v,O]=d.useState(null),[k,M]=d.useState(!1),[q,D]=d.useState(void 0),U=d.useCallback(async()=>{if(w){M(!0);try{const l=await he(w);O(l)}catch(l){console.error("Failed to fetch project:",l)}finally{M(!1)}}},[w]),T=d.useCallback(async(l,f)=>{var I;if(D(void 0),!!w){f!=null&&f.optimisticUpdate&&v&&O(m=>({...m,...l}));try{const m=await ve({...l});O(m)}catch(m){console.error("Failed to update project:",m),f!=null&&f.optimisticUpdate&&O(v),D((I=m==null?void 0:m.response)==null?void 0:I.data)}}},[w,v]);d.useEffect(()=>{w&&U()},[w,U]);const Y=d.useMemo(()=>({doc:u,state:a,localState:{...s,currentLocale:j},setLocalState:l=>r(typeof l=="function"?f=>l(f??{}):l),undoManager:y,projectState:{project:v,isLoadingProject:k,error:q},updateProject:T,forceSync:h}),[u,a,JSON.stringify(s),r,y,v,k,T,q,j,h]);return d.useEffect(()=>{y.on("stack-item-added",({stackItem:l})=>{const{currentPageId:f,currentLocale:I,pages:m}=c.current;l.meta.set("localState",{currentPageId:f,currentLocale:I,pages:m})}),y.on("stack-item-popped",({stackItem:l})=>{const f=l.meta.get("localState");f&&r(I=>({...I,...f}))})},[y,r]),d.useEffect(()=>{P.awareness.setLocalState(s)},[P,s]),d.useEffect(()=>{P.once("synced",()=>p(!0));const l=()=>{r(m=>({...m,networkStatus:void 0}))},f=()=>{r(m=>({...m,networkStatus:"offline"}))},I=W.default(({status:m})=>{m==="connected"?l():m==="disconnected"&&f()},xe);return P.on("status",I),window.addEventListener("online",l),window.addEventListener("offline",f),()=>{P.off("status",I),window.removeEventListener("online",l),window.removeEventListener("offline",f)}},[P,r]),S&&!g?null:E.jsx(z.Provider,{value:Y,children:i})}const B=()=>{const t=d.useContext(z);if(!t)throw new Error("Context is null");const n=ne.useSyncedStore(t.state),{setLocalState:i,localState:S}=t,g=V.useNavigate(),p=A(),j=d.useMemo(()=>({setCurrentSectionId:(e,o)=>{var s,r;e===S.currentPageId&&o===((r=(s=S.pages)==null?void 0:s[e])==null?void 0:r.currentSectionId)||(g(b.joinURL("/admin/maker",p??"","pages",e)),i(c=>C.produce(c,a=>{var u;a.currentPageId=e,a.currentComponentId=void 0,a.customComponentPreviewerProperties={},o!==void 0&&(a.pages??(a.pages={}),(u=a.pages)[e]??(u[e]={}),a.pages[e].currentSectionId=o??void 0),o?window.sessionStorage.setItem("iframe_show_id",`"${o}"`):window.sessionStorage.removeItem("iframe_show_id")})))},setCurrentComponentId:e=>{e!==S.currentComponentId&&(g(b.joinURL("/admin/maker",p??"","components",e)),i(o=>C.produce(o,s=>{s.currentComponentId=e,s.customComponentPreviewerProperties={}})))},setCurrentRouteId:({routeId:e,dynamicParams:o})=>{i(s=>C.produce(s,r=>{r.currentRouteId=e,r.currentDynamicParams=o}))},setCustomComponentPreviewerProperties:(()=>{const e={},o=W.default(()=>{i(s=>C.produce(s,r=>{r.customComponentPreviewerProperties={...r==null?void 0:r.customComponentPreviewerProperties,...e},Object.keys(e).forEach(c=>delete e[c])}))},5);return s=>{Object.assign(e,s),o()}})(),setRouteGenerateProcess:e=>{i(o=>C.produce(o,s=>{e?s.routeGenerateProcess={...s.routeGenerateProcess,...e}:s.routeGenerateProcess={}}))},resetRouteGenerateProcess:()=>{i(e=>C.produce(e,o=>{o.routeGenerateProcess={progress:"complete"}}))}}),[i,g,p]),w=d.useMemo(()=>({addPage:(e,o)=>{var c,a,u,P,h,y;const s=(e==null?void 0:e.id)??x(),r={...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:((u=e==null?void 0:e.templateConfig)==null?void 0:u.dataSourceIds)??void 0,dataSourceParameters:((P=e==null?void 0:e.templateConfig)==null?void 0:P.dataSourceParameters)??{},enabledGenerate:((h=e==null?void 0:e.templateConfig)==null?void 0:h.enabledGenerate)??!1,agentId:((y=e==null?void 0:e.templateConfig)==null?void 0:y.agentId)??void 0}};return t.doc.transact(()=>{n.pages[r.id]=r,n.pageIds.splice(o??n.pageIds.length,0,r.id)}),r},addRoute:(e,o)=>{const s=(e==null?void 0:e.id)??x(),r={...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[r.id]=r,n.routeIds.splice(o??n.routeIds.length,0,r.id)}),r},deleteRoute:e=>{var s;if(!e)return;const o=(s=n.routeIds)==null?void 0:s.indexOf(e);o!==void 0&&o!==-1&&t.doc.transact(()=>{var r,c;(r=n.routeIds)==null||r.splice(o,1),(c=n.routes)==null||delete c[e]})},deletePage:e=>{const o=n.pageIds.indexOf(e);o!==-1&&t.doc.transact(()=>{n.pageIds.splice(o,1),delete n.pages[e]})},movePage:(e,o)=>{const{pageIds:s}=n,r=s.indexOf(e);r>=0&&s.splice(o,0,...s.splice(r,1))},addSection:(e,o,s)=>{const r=n.pages[e];if(!r)throw new Error(`Page ${e} is not exists`);const c={...o,id:o.id??x(),isTemplateSection:o.isTemplateSection??!0,llmConfig:o.llmConfig??{}};return t.doc.transact(()=>{r.sections[c.id]=c,r.sectionIds.splice(s??r.sectionIds.length,0,c.id)}),c},deleteSection:(e,o)=>{const s=n.pages[e];if(!s)throw new Error(`Page ${e} is not exists`);const r=s.sectionIds.indexOf(o);r!==-1&&t.doc.transact(()=>{s.sectionIds.splice(r,1),delete s.sections[o]})},toggleSectionVisibility:(e,o,s)=>{const r=n.pages[e];if(!r)throw new Error(`Page ${e} is not exists`);const c=r.sections[o];c&&(c.visibility=s)},moveSection:(e,o,s)=>{const r=n.pages[e];if(!r)throw new Error(`Page ${e} is not exists`);const{sectionIds:c}=r,a=c.indexOf(o);a>=0&&c.splice(s,0,...c.splice(a,1))},addDataSource:e=>{const o=e.id??x(),s={...e??{},id:o,createdAt:new Date().toISOString()};return t.doc.transact(()=>{n.dataSourceIds??(n.dataSourceIds=[]),n.dataSources??(n.dataSources={}),n.dataSourceIds.push(o),n.dataSources[o]=s}),n.dataSources[o]},deleteDataSource:e=>{const o=n.dataSourceIds.indexOf(e);o!==-1&&t.doc.transact(()=>{n.dataSourceIds.splice(o,1),delete n.dataSources[e]})}}),[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 r,c,a;const{localState:{currentPageId:e,...o}}=t;if(!e)return;const s=(c=(r=o.pages)==null?void 0:r[e])==null?void 0:c.currentSectionId;if(s)return(a=n.pages[e])==null?void 0:a.sections[s]},get currentRoute(){var o;const{localState:{currentRouteId:e}}=t;return e?(o=n.routes)==null?void 0:o[e]:void 0}}},A=()=>{const{projectId:t}=V.useParams();return t??J()??""},Ee=()=>window.__PROJECT_SLUG__??"";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 _e=()=>X(B().state);exports.ErrorView=Pe;exports.StoreProvider=Oe;exports.api=R;exports.autoResizeImage=Ce;exports.getAllComponents=X;exports.getCustomComponents=Q;exports.getImageAbsoluteUrl=je;exports.getMountPoint=me;exports.getProjectIdFromPathnameOrWindow=J;exports.getProjectPageVersionKey=Se;exports.getResourceComponents=K;exports.getWssURL=Ie;exports.nextId=x;exports.transformValue=we;exports.useAllComponents=_e;exports.useProjectId=A;exports.useProjectSlug=Ee;exports.useStore=B;
|