@blocklet/pages-kit-inner-components 0.5.21 → 0.5.22
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 +9 -9
- package/lib/cjs/chunks/home-5a40bAJ6.js +38 -0
- package/lib/cjs/chunks/{publish-button-Cw_MfRfv.js → publish-button-DUYSuenR.js} +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/setting.js +2 -2
- package/lib/es/add-component.js +4 -4
- package/lib/es/chunks/{home-BjT8iYTg.js → home-BB778Odl.js} +174 -171
- package/lib/es/chunks/{publish-button-eIyM_BsP.js → publish-button-BJSEYd0m.js} +1 -1
- package/lib/es/home.js +1 -1
- package/lib/es/setting.js +46 -46
- package/package.json +3 -3
- package/lib/cjs/chunks/home-DH9Z8Tuv.js +0 -38
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),I=require("./state-CA6q2h83.js"),Y=require("@arcblock/ux/lib/Locale/context"),ce=require("@arcblock/ux/lib/Result"),ue=require("@blocklet/pages-kit/builtin/page/header"),de=require("@blocklet/pages-kit/contexts/color"),J=require("@blocklet/pages-kit/utils/data-source"),pe=require("@blocklet/pages-kit/utils/route"),ge=require("@blocklet/ui-react/lib/Header"),Z=require("@emotion/css"),N=require("@emotion/react"),me=require("@emotion/styled"),b=require("@mui/material"),G=require("ahooks"),fe=require("isomorphic-dompurify"),he=require("lodash/cloneDeep"),xe=require("lodash/isEmpty"),je=require("lodash/isEqual"),f=require("react"),ye=require("react-helmet"),P=require("react-router-dom"),ee=require("react-use"),_=require("ufo"),C=require("./array-C0IVbCmb.js"),W=require("@arcblock/ux/lib/Theme"),be=require("@blocklet/ui-react/lib/Footer");require("webfontloader");const X=require("./session-BA7Qrcia.js"),S=t=>t&&t.__esModule?t:{default:t},te=S(ce),ve=S(ge),ne=S(me),we=S(fe),V=S(he),Pe=S(xe),oe=S(je),Re=S(be),ke=W.styled(Re.default,{shouldForwardProp:t=>!!t})`
|
|
2
|
+
& > div > .MuiContainer-root {
|
|
3
|
+
max-width: unset;
|
|
4
|
+
}
|
|
5
|
+
`;function Se({meta:t,...o}){const a=W.useTheme();return e.jsx(ke,{...o,meta:t,theme:a||{}})}function re(t){return e.jsx(b.Box,{display:"flex",flex:1,height:"100%",alignItems:"center",justifyContent:"center",...t,children:e.jsx(b.CircularProgress,{size:30})})}function qe(t){return e.jsx(_e,{...t})}const _e=W.styled(b.Box)`
|
|
6
|
+
position: fixed;
|
|
7
|
+
left: 0;
|
|
8
|
+
top: 0;
|
|
9
|
+
z-index: 999999999999;
|
|
10
|
+
width: 80px;
|
|
11
|
+
font-size: 12px;
|
|
12
|
+
text-align: center;
|
|
13
|
+
opacity: 0.7;
|
|
14
|
+
transform: translateX(-23%) translateY(70%) rotate(-45deg);
|
|
15
|
+
pointer-events: none;
|
|
16
|
+
`,Ce=`Avenir, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
|
|
17
|
+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'`;function Ee({titleFontFamily:t,descriptionFontFamily:o}){var n;const a=b.useTheme(),s=(n=a==null?void 0:a.typography)==null?void 0:n.fontFamily;f.useEffect(()=>{},[t,o]);const l=`${s}, ${Ce}`;return e.jsx(N.Global,{styles:N.css`
|
|
18
|
+
#app {
|
|
19
|
+
font-family: ${l};
|
|
20
|
+
|
|
21
|
+
.page-kit-section__title {
|
|
22
|
+
font-family: ${l};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.page-kit-section__description {
|
|
26
|
+
font-family: ${l};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`})}function Me(){const[t]=P.useSearchParams(),{session:o}=X.useSessionContext(),a=X.useIsRoleOrMultiTenant("owner","admin","pagesEditor","member"),s=f.useMemo(()=>{const n=t.get("mode");return C.STATE_MODES.includes(n)?n:"production"},[t]),l=s==="production"?s:o.user?a?s:"production":null;return l?e.jsx(se,{mode:l}):null}function se({mode:t}){if(t!=="draft"){const o=window.__PAGE_STATE__;return o?e.jsx(A,{mode:t,state:o}):e.jsx(Be,{mode:t,children:({state:a})=>e.jsx(A,{mode:t,state:a})})}return e.jsx(Ie,{children:({state:o})=>e.jsx(A,{mode:t,state:o})})}const Ie=f.lazy(()=>Promise.resolve().then(()=>require("./draft-data-BLL0M7MI.js")));function Be({mode:t,children:o}){const a=document.querySelector('meta[property="pages:version"]'),s=a==null?void 0:a.content,l=I.useProjectId(),n=f.useMemo(()=>{if(s==="{{pagesPublishedAt}}"){const c=localStorage.getItem(I.getProjectPageVersionKey(l??""));return Number(c)?Number(c):new Date().getTime()}return Number(s)},[s]),{loading:g,value:i}=ee.useAsync(()=>C.getPages({mode:t,version:n}),[t,n]);return g?e.jsx(re,{}):i?o({state:i}):null}function A({mode:t,state:o}){const{t:a,locale:s}=Y.useLocaleContext(),[l]=P.useSearchParams(),n=l.get("hiddenBadge")==="true",g=l.get("showPublish")==="true",{pageIds:i,pages:c,routeIds:m,routes:d,supportedLocales:p,config:{defaultLocale:h},resources:v}=o,w=I.getAllComponents(o),x=f.useMemo(()=>p!=null&&p.some(u=>u.locale===s)?s:void 0,[s,p]),B=Object.values(d||{}).find(u=>(u==null?void 0:u.path)==="/")||Object.values(c).find(u=>(u==null?void 0:u.slug)==="/")?void 0:Object.values(c)[0],U=f.useMemo(()=>t==="production"?i.map(u=>{const r=c[u];return r&&{id:r.id,path:_.joinURL("/",x||"",r.slug)}}).filter(C.nonNullable):m.map(u=>{const r=d[u];return r?{id:r.id,path:_.joinURL("/",x||"",r.path,`?mode=${t}`)}:null}).filter(C.nonNullable),[i,c,x,t,d,m]),q=([...u])=>(t!=="production"&&g&&u.unshift(e.jsx(f.Suspense,{fallback:e.jsx("div",{}),children:e.jsx(Te,{mode:"production",state:o})})),u);return e.jsxs(C.Provider,{value:{pages:U},children:[e.jsxs(P.Routes,{children:[B&&e.jsx(P.Route,{index:!0,element:e.jsx(P.Navigate,{to:_.joinURL("/",x||"",B.slug)})}),m==null?void 0:m.map(u=>{var L,T,R,j;const r=d==null?void 0:d[u];if(!r||!r.displayTemplateId)return null;const E=c[r.displayTemplateId];if(!E)return null;let M=[];if(r.params&&r.params.length>0){const k=pe.generateParamCombinations({basePath:r.path,params:r.params,routeId:r.id,paramsOptions:r.paramsOptions,currentIndex:0,currentParams:[],currentOptionIds:[],result:[]});M=k==null?void 0:k.map(H=>{var O,$,K,Q;const D=H.paramOptionIds.join("-");return e.jsx(P.Route,{path:_.joinURL(":projectIdOrSlug?",H.path),element:e.jsx(z,{mode:t,components:w,page:E,locale:x,defaultLocale:h,headerAddons:q,state:o,pageData:(Q=(K=($=(O=r.dataSource)==null?void 0:O.pathDataMappings)==null?void 0:$[D])==null?void 0:K.dataCache)==null?void 0:Q[x||h||"en"]})},D)})}return M.push(e.jsx(P.Route,{path:_.joinURL(":projectIdOrSlug?",r.path),element:e.jsx(z,{mode:t,components:w,page:E,locale:x,defaultLocale:h,headerAddons:q,state:o,pageData:(j=(R=(T=(L=r.dataSource)==null?void 0:L.pathDataMappings)==null?void 0:T[r.id])==null?void 0:R.dataCache)==null?void 0:j[x||h||"en"]})},r.id)),M}),i.map(u=>{const r=c[u];return r?e.jsx(P.Route,{path:_.joinURL(":projectIdOrSlug?",r.slug),element:e.jsx(F,{mode:t,components:w,page:r,locale:x,defaultLocale:h,headerAddons:q})},r.id):null}),v.pages&&Object.values(v.pages).map(({blockletId:u,page:r})=>e.jsx(P.Route,{path:_.joinURL("/",`@${u}`,r.slug),element:e.jsx(F,{mode:t,components:w,page:r,locale:x,defaultLocale:h,headerAddons:q})},r.id)),e.jsx(P.Route,{path:"*",element:e.jsx(b.Box,{width:"100vw",height:"100vh",display:"flex",justifyContent:"center",alignItems:"center",children:e.jsx(te.default,{status:404,extra:e.jsx(le,{href:"/",children:a("common.back")})})})})]}),t!=="production"&&!n&&e.jsx(qe,{sx:{bgcolor:"info.light"},children:t}),e.jsx(Ee,{})]})}function z({mode:t,pageData:o,components:a,page:s,locale:l,defaultLocale:n,headerAddons:g,state:i}){const c=G.useReactive({page:null});f.useEffect(()=>{const d=s||null;d?c.page=V.default(d):c.page=null},[s,c]);const m=f.useRef();return f.useEffect(()=>{oe.default(o,m.current)||o&&c.page&&(J.setPageDataSource(c.page,i,l,o),m.current=V.default(o))},[c.page,o,l,i]),c.page?e.jsx(F,{mode:t,components:a,page:c.page,locale:l,defaultLocale:n,headerAddons:g}):null}function Le({mode:t,state:o,path:a,pageData:s}){const{t:l,locale:n}=Y.useLocaleContext(),{pages:g,supportedLocales:i,config:{defaultLocale:c},resources:m}=o,d=Object.values(g).find(y=>(y==null?void 0:y.slug)===a),p=Object.values(m.pages||{}).find(y=>y.page.slug===a),h=f.useMemo(()=>i!=null&&i.some(y=>y.locale===n)?n:void 0,[n,i]),v=G.useReactive({page:null});f.useEffect(()=>{const y=d||(p==null?void 0:p.page)||null;y?v.page=V.default(y):v.page=null},[d,p]);const w=f.useRef();if(f.useEffect(()=>{oe.default(s,w.current)||s&&v.page&&(J.setPageDataSource(v.page,o,h,s),w.current=V.default(s))},[{}]),!d&&!(p!=null&&p.page))return e.jsx(b.Box,{width:"100vw",height:"100vh",display:"flex",justifyContent:"center",alignItems:"center",children:e.jsx(te.default,{style:{background:"inherit"},status:404,extra:e.jsx(le,{href:"/",children:l("common.back")})})});const x=I.getAllComponents(o);return v.page?e.jsx(F,{mode:t,components:x,page:v.page,locale:h,defaultLocale:c}):null}function F({mode:t,components:o,page:a,locale:s,defaultLocale:l,headerAddons:n}){var B,U,q,u,r,E,M,L,T;const g=de.useColorConvert(),i=((B=a.locales)==null?void 0:B[s])??((U=a.locales)==null?void 0:U[l])??{},c=i.title||((q=window.blocklet)==null?void 0:q.appName),m=i.description||((u=window.blocklet)==null?void 0:u.appDescription),d=I.autoResizeImage(I.getImageAbsoluteUrl(i.image),540),{logo:p,brand:h,description:v,...w}=ue.useHeaderState(),x=f.useMemo(()=>R=>{var k;let j=(n==null?void 0:n(R))??R;return j=((k=w.addons)==null?void 0:k.call(w,j))??j,j},[w.addons,n]),y=(r=i.header)!=null&&r.translucent?ie:ae;return e.jsxs(C.PageProvider,{page:a,defaultLocale:l,currentLocale:s,children:[e.jsx(N.Global,{styles:N.css`
|
|
30
|
+
body {
|
|
31
|
+
background-color: ${g(!i.backgroundColor||i.backgroundColor==="transparent"?"background.default":i.backgroundColor)} !important;
|
|
32
|
+
}
|
|
33
|
+
`}),e.jsx(y,{hideNavMenu:!!((E=i.header)!=null&&E.hideNavMenus),translucentTextColor:(M=i.header)==null?void 0:M.translucentTextColor,...p?{logo:p}:{},...h?{brand:h}:{},...v?{description:v}:{},className:Z.cx(((L=i.header)==null?void 0:L.sticky)&&"sticky","page-header"),maxWidth:!1,addons:x}),e.jsx(P.ScrollRestoration,{}),e.jsxs(ye.Helmet,{children:[e.jsx("title",{children:c}),e.jsx("meta",{name:"og:title",content:c}),e.jsx("meta",{name:"og:description",content:m}),e.jsx("meta",{name:"og:image",content:d}),e.jsx("meta",{name:"twitter:image:src",content:d}),e.jsx("meta",{name:"twitter:image",content:d}),e.jsx("meta",{property:"twitter:description",content:m}),e.jsx("meta",{property:"twitter:title",content:c}),e.jsx("meta",{name:"description",content:m})]}),e.jsx(b.Stack,{flexGrow:1,className:"PageView-root",sx:{"& .BlockBase-root:first-child":{pt:"0 !important"}},children:a.sectionIds.map(R=>{var D,O;const j=a.sections[R];if(!j||j.visibility==="hidden")return null;const k=(D=j.locales)==null?void 0:D[s],H=((O=j.locales)==null?void 0:O[l])??{};return e.jsx(C.BlockRenderer,{id:R,type:j.component,mode:t,section:j,config:{...Pe.default(k)?H:k,locale:s,dev:t==="draft"?{mode:t,components:o,defaultLocale:l}:{mode:t}}},R)})}),!((T=i.footer)!=null&&T.hidden)&&e.jsx(Se,{})]})}const Te=f.lazy(()=>Promise.resolve().then(()=>require("./publish-button-DUYSuenR.js"))),ae=ne.default(ve.default)`
|
|
34
|
+
&.sticky {
|
|
35
|
+
position: sticky;
|
|
36
|
+
top: 0;
|
|
37
|
+
}
|
|
38
|
+
`;function De({logo:t}){const[o,a]=f.useState(),s=b.useMediaQuery(n=>n.breakpoints.down("sm")),{value:l}=ee.useAsync(()=>{var i,c;const n=new URL(s?((i=window==null?void 0:window.blocklet)==null?void 0:i.appLogo)||"/.well-known/service/blocklet/logo":((c=window==null?void 0:window.blocklet)==null?void 0:c.appLogoRect)||"/.well-known/service/blocklet/logo-rect",window.location.origin);n.searchParams.delete("imageFilter"),n.searchParams.delete("f");const g=n.toString();return new Promise(m=>{fetch(g).then(d=>{const p=d.headers.get("content-type");p!=null&&p.includes("svg")&&d.text().then(h=>{a(h),m(null)}),m(d.url)})})},[s]);if(t)return t;if(o)return e.jsx(b.Box,{sx:{filter:"initial !important"},dangerouslySetInnerHTML:{__html:we.default.sanitize(o)}});if(l){const n=new URL(l);n.searchParams.set("imageFilter","convert"),n.searchParams.set("f","png"),n.searchParams.set("h","80");const g=n.toString();return e.jsx("img",{src:g,alt:"logo"})}return null}function ie({logo:t,translucentTextColor:o,...a}){const{top:s=0}=G.useScroll(()=>document.getElementById("app"))||{},l=b.useTheme();let n=Math.min(s/800,1),g="";return n>.1?(n=Math.max(n,.6),g=b.alpha(l.palette.text.primary,n)):g=o||"#EEEEEE",e.jsx(ae,{logo:e.jsx(De,{logo:t}),...a,className:Z.cx(n<=.7&&"reverse-color"),style:{backgroundColor:b.alpha(l.palette.background.default,n),"--logo-invert":n<=.7?1-n/6:1-n},sx:{backdropFilter:n>=.6?"blur(10px)":"blur(0px)",transition:"all 0.3s ease",position:"fixed !important",left:0,top:0,right:0,bgcolor:"transparent","&.reverse-color":{".navmenu-root>.navmenu-sub>span,\n .navmenu-root>.navmenu-item,\n .header-addons>button,\n .header-addons>a,\n .header-addons>div>button":{color:`${g} !important`}},"& .navmenu--horizontal":{bgcolor:"transparent !important"},".header-logo > div":{filter:"invert(var(--logo-invert))"},".header-logo":{color:g}}})}const le=ne.default(b.Button)``;exports.Home=Me;exports.HomeView=se;exports.Loading=re;exports.PageRoutes=A;exports.PageView=F;exports.PageViewByPath=Le;exports.PageViewWithDataSource=z;exports.TranslucentHeader=ie;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),F=require("./state-CA6q2h83.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-DH9Z8Tuv.js"),U=require("./array-C0IVbCmb.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
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),F=require("./state-CA6q2h83.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-5a40bAJ6.js"),U=require("./array-C0IVbCmb.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;
|
package/lib/cjs/home.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("react/jsx-runtime");require("./chunks/state-CA6q2h83.js");require("@arcblock/ux/lib/Locale/context");require("@arcblock/ux/lib/Result");require("@blocklet/pages-kit/builtin/page/header");require("@blocklet/pages-kit/contexts/color");require("@blocklet/pages-kit/utils/data-source");require("@blocklet/pages-kit/utils/route");require("@blocklet/ui-react/lib/Header");require("@emotion/css");require("@emotion/react");require("@emotion/styled");require("@mui/material");require("ahooks");require("isomorphic-dompurify");require("lodash/cloneDeep");require("lodash/isEmpty");require("lodash/isEqual");require("react");require("react-helmet");require("react-router-dom");require("react-use");require("ufo");require("./chunks/array-C0IVbCmb.js");const e=require("./chunks/home-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("react/jsx-runtime");require("./chunks/state-CA6q2h83.js");require("@arcblock/ux/lib/Locale/context");require("@arcblock/ux/lib/Result");require("@blocklet/pages-kit/builtin/page/header");require("@blocklet/pages-kit/contexts/color");require("@blocklet/pages-kit/utils/data-source");require("@blocklet/pages-kit/utils/route");require("@blocklet/ui-react/lib/Header");require("@emotion/css");require("@emotion/react");require("@emotion/styled");require("@mui/material");require("ahooks");require("isomorphic-dompurify");require("lodash/cloneDeep");require("lodash/isEmpty");require("lodash/isEqual");require("react");require("react-helmet");require("react-router-dom");require("react-use");require("ufo");require("./chunks/array-C0IVbCmb.js");const e=require("./chunks/home-5a40bAJ6.js");require("./chunks/session-BA7Qrcia.js");exports.HomeView=e.HomeView;exports.PageRoutes=e.PageRoutes;exports.PageView=e.PageView;exports.PageViewByPath=e.PageViewByPath;exports.PageViewWithDataSource=e.PageViewWithDataSource;exports.TranslucentHeader=e.TranslucentHeader;exports.default=e.Home;
|
package/lib/cjs/setting.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),R=require("./chunks/state-CA6q2h83.js"),De=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),ie=require("@blocklet/code-editor"),Ee=require("@mui/icons-material/AddRounded"),Ve=require("@mui/icons-material/ArrowDownward"),ze=require("@mui/icons-material/ArrowUpward"),Ae=require("@mui/icons-material/DeleteOutline"),r=require("@mui/material"),Ne=require("lodash/sortBy"),C=require("react"),ke=require("react-use"),ye=require("@blocklet/pages-kit/builtin/color-picker"),qe=require("./chunks/config-string-CqKhhXBA.js"),Fe=require("lodash/isEmpty"),Ue=require("lodash/set"),Me=require("yaml"),F=require("@blocklet/pages-kit/builtin/uploader"),We=require("lodash/cloneDeep"),Ke=require("@arcblock/ux/lib/Toast"),Q=require("@blocklet/pages-kit/components"),Le=require("@blocklet/pages-kit/utils/property"),Se=require("@mui/base"),D=require("@mui/icons-material"),Y=require("@syncedstore/core"),Pe=require("ahooks"),Je=require("lodash/assign"),He=require("lodash/get"),Ye=require("lodash/has"),$e=require("lodash/isEqual"),Ge=require("lodash/isNil"),Qe=require("lodash/isObject"),Xe=require("lodash/keyBy"),Ze=require("lodash/omit"),et=require("lodash/pick"),tt=require("lodash/reduce"),z=require("material-ui-popup-state/hooks"),rt=require("react-error-boundary"),st=require("@emotion/css"),te=require("react-dnd"),T=e=>e&&e.__esModule?e:{default:e};function lt(e){if(e&&e.__esModule)return e;const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const o=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(s,l,o.get?o:{enumerable:!0,get:()=>e[l]})}}return s.default=e,Object.freeze(s)}const Z=T(De),ot=T(Ee),it=T(Ve),nt=T(ze),ct=T(Ae),E=T(Ne),ne=T(Fe),we=T(Ue),re=lt(Me),at=T(We),se=T(Ke),ut=T(Je),dt=T(He),pt=T(Ye),mt=T($e),X=T(Ge),xt=T(Qe),ft=T(Xe),jt=T(Ze),bt=T(et),ht=T(tt);function yt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"warning",variant:"outlined",disabled:s,onClick:e,...o,children:t.jsx(ct.default,{fontSize:"small"})})}function gt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(nt.default,{fontSize:"small"})})}function vt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(it.default,{fontSize:"small"})})}function kt({label:e,value:s,onChange:l,disabled:o=!1,itemLabel:p="",emptyHeight:h=40,property:d,renderItem:g,...v}){const{t:b,locale:P}=_.useLocaleContext(),y=ke.useUpdate(),i=C.useCallback(m=>{l(R.transformValue(m,d.type))},[l,d.type]),n=C.useMemo(()=>Array.isArray(s)?s:[],[s]),c=C.useCallback(()=>{const m=[...n,""];i(m),y()},[n,i,y]),u=C.useCallback(()=>{if(!d||!d.subProperties)return c();const m={};E.default(Object.values(d.subProperties),"index").forEach(({data:B})=>{var A,N;if(!B.key)return;const V=((N=(A=B.locales)==null?void 0:A[P])==null?void 0:N.defaultValue)??"";m[B.key]=V});const O=[...n,m];i(O),y()},[n,i,y,d,P,c]),x=C.useCallback(m=>{try{const w=JSON.parse(m);Array.isArray(w)?i(w):console.error("JSON解析结果不是数组")}catch(w){console.error("JSON解析错误:",w)}},[i]),S=C.useCallback(m=>{const w=n.filter((O,B)=>B!==m);i(w),y()},[n,i,y]),a=C.useCallback(m=>{if(m<=0)return;const w=[...n],O=w[m];w[m]=w[m-1],w[m-1]=O,i(w),y()},[n,i,y]),j=C.useCallback(m=>{if(m>=n.length-1)return;const w=[...n],O=w[m];w[m]=w[m+1],w[m+1]=O,i(w),y()},[n,i,y]),f=C.useCallback((m,w)=>{const O=[...n];O[m]=w,i(O)},[n,i]),k=d&&d.subProperties&&Object.keys(d.subProperties).length>0,I=C.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:m})=>t.jsx(r.Typography,{variant:"body1",sx:{bgcolor:"action.hover",borderRadius:"50%",width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:m+1})},{field:"content",headerName:"",renderCell:({row:m,index:w})=>g&&k?g({item:m,index:w,property:d,onChange:O=>f(w,O)}):t.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:o,value:m,placeholder:p||`${b("item")} ${w+1}`,onChange:O=>f(w,O.target.value),...v})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:m})=>t.jsxs(r.Stack,{direction:"column",spacing:.25,children:[t.jsx(gt,{disabled:o||m===0,onClick:()=>a(m)}),t.jsx(vt,{disabled:o||m===n.length-1,onClick:()=>j(m)}),t.jsx(yt,{disabled:o,onClick:()=>S(m)})]})}],[g,k,d,f,p,b,o,v,S,a,j,n.length]);return k?t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),n.length>0?t.jsx(r.TableContainer,{component:r.Paper,variant:"outlined",sx:{borderRadius:1,mb:1},children:t.jsxs(r.Table,{size:"small",sx:{"& .MuiTableCell-root":{py:.25,px:1,whiteSpace:"nowrap"},"& .MuiTableCell-head":{backgroundColor:"action.hover",py:.25,px:1},borderCollapse:"collapse"},children:[t.jsx(r.TableHead,{sx:{display:"none"},children:t.jsx(r.TableRow,{children:I.map(m=>t.jsx(r.TableCell,{width:m.width,align:m.align||"left",sx:{fontWeight:"bold"},children:m.renderHeader?m.renderHeader():m.headerName},m.field))})}),t.jsx(r.TableBody,{children:n.map((m,w,O)=>t.jsx(r.TableRow,{sx:{borderBottom:w<O.length-1?"1px solid":"none",borderColor:"divider","&:hover":{backgroundColor:"action.hover"}},children:I.map(B=>t.jsx(r.TableCell,{width:B.width,align:B.align||"left",sx:{borderBottom:"none"},children:B.renderCell({row:m,index:w,onChange:V=>f(w,V)})},`${w}-${B.field}`))},w))})]})}):t.jsx(Z.default,{style:{fontSize:12,height:h},children:b("maker.properties.arrayEmpty")}),t.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:o,startIcon:t.jsx(ot.default,{}),onClick:u,children:b("maker.properties.addArrayItem")})]}):t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,minHeight:150},children:t.jsx(ie.CodeEditor,{keyId:d.id,locale:P,language:"json",value:JSON.stringify(n,null,2),onChange:m=>x(m||""),fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},d.id)})]})}function St({value:e,onChange:s,...l}){const o=C.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsx(qe.ConfigString,{...l,value:e,onChange:s,InputProps:{endAdornment:t.jsx(r.InputAdornment,{position:"end",children:t.jsx(ye.ColorItem,{color:e??"",style:{width:"1.5rem",height:"1.5rem",padding:0},onClick:()=>{var p;(p=o.current)==null||p.open({value:e??""})}})})}}),t.jsx(ye.ConfigColorDialog,{ref:o,onSave:({value:p},h)=>{s(p),h()}})]})}function Pt({label:e,value:s,onChange:l,property:o,component:p,defaultLocale:h,allComponents:d,PropertyValueField:g,onUpload:v}){const{locale:b}=_.useLocaleContext(),P=C.useRef(null);if(!ne.default(o.subProperties)){const i=E.default(Object.values(o.subProperties||{}),"index").filter(n=>n.data.visible!==!1&&n.data.key);return t.jsxs(r.Stack,{width:"100%",children:[t.jsx(r.FormLabel,{sx:{px:.25,py:.5},children:e}),t.jsx(r.Box,{children:t.jsx(r.Box,{sx:{position:"relative"},children:i.map((n,c)=>{const{data:u}=n,x=u.key??u.id,S=c===i.length-1;let a=null;try{s&&typeof s=="object"?a=s[x]:typeof s=="string"&&(a=(o.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}"))[x])}catch{}a==null&&(u.locales&&b&&u.locales[b]?a=u.locales[b].defaultValue:u.locales&&h&&u.locales[h]&&(a=u.locales[h].defaultValue));const j=k=>{try{let I={};if(typeof s=="string")try{I=o.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(I={...s});we.default(I,x,k);const m=R.transformValue(I,o.type);l==null||l(m)}catch(I){console.error("Error updating property:",I)}},f=8;return t.jsxs(r.Box,{sx:{mb:S?0:1,display:"flex",flexDirection:"row"},children:[t.jsxs(r.Box,{sx:{position:"relative",width:24,flexShrink:0},children:[t.jsx(r.Box,{sx:{position:"absolute",left:f,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),t.jsx(r.Box,{sx:{position:"absolute",left:f,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!S&&t.jsx(r.Box,{sx:{position:"absolute",left:f,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),t.jsx(r.Box,{sx:{flexGrow:1},children:t.jsx(g,{component:p,property:u,value:a,onChange:j,size:"small",fullWidth:!0,defaultLocale:h,allComponents:d})})]},u.id)})})})]})}return t.jsx(r.Stack,{width:"100%",gap:2,children:t.jsxs(r.Stack,{sx:{width:"100%",position:"relative",pt:1,pb:"6px",px:"1px",minHeight:50,".monaco-editor,.overflow-guard":{borderRadius:1}},children:[t.jsx(r.FormLabel,{sx:{position:"absolute",left:0,top:0,transform:"translate(0px, -7px) scale(0.75)"},children:e}),t.jsx(ie.CodeEditor,{keyId:o.id,locale:b,language:o.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:i=>{l==null||l(i)},onUpload:i=>{P.current=i,v&&v(i)},fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},o.id),t.jsx(r.Box,{component:"fieldset",sx:{pointerEvents:"none",position:"absolute",left:0,top:-5,width:"100%",height:"100%",border:1,borderColor:"rgba(0, 0, 0, 0.23)",borderRadius:1,px:1,py:0},children:t.jsx(r.Box,{component:"legend",sx:{fontSize:"0.75em"},children:t.jsx(r.Box,{component:"span",sx:{opacity:0},children:e})})})]})})}const wt=["string","multiline","json","yaml","url","component","custom"];function ge(e){return e.type?!wt.includes(e.type):!1}function Ie({disabled:e,list:s,renderItem:l,...o}){const p=C.useRef(null),h=C.useId(),d=Pe.useUpdate(),g=E.default(Object.entries(s),n=>n[1].index).map(n=>n[0]),v=C.useRef(g),b=C.useCallback(n=>{v.current=n,d()},[d]),P=C.useCallback(({index:n},{index:c})=>{const u=[...v.current];u.splice(c,0,...u.splice(n,1)),b(u)},[b]);C.useEffect(()=>{b(g)},[g.join("-")]);const[{isOver:y},i]=te.useDrop({accept:h,collect:n=>({isOver:n.isOver()}),canDrop:()=>!e,drop:()=>{var u;const n=()=>{v.current.forEach((x,S)=>{const a=s[x];a&&(a.index=S)})},c=(u=Y.getYjsValue(s))==null?void 0:u.doc;c?c.transact(()=>{n()}):n()}});return C.useEffect(()=>{y||b(g)},[y]),i(p),t.jsx(r.Box,{...o,ref:p,className:st.cx(y&&"isDragging"),children:v.current.map((n,c)=>t.jsx(It,{type:h,disabled:e,id:n,index:c,itemIndex:u=>v.current.indexOf(u),move:P,children:u=>{const x=s[n];return x?l(x.data,c,u):null}},n))})}function It({disabled:e,id:s,index:l,type:o,children:p,itemIndex:h,move:d}){const g=C.useRef(),[{isDragging:v},b,P]=te.useDrag({type:o,item:()=>({id:s}),canDrag:()=>!e,collect:i=>({isDragging:i.isDragging()})}),[,y]=te.useDrop({accept:o,canDrop:()=>!e,hover(i,n){var f;if(!g.current)return;const c=h(i.id),u=l;if(c===u)return;const x=(f=g.current)==null?void 0:f.getBoundingClientRect(),S=(x.bottom-x.top)/2,j=n.getClientOffset().y-x.top;c<u&&j<S||c>u&&j>S||d({id:i.id,index:c},{id:s,index:l})}});return typeof p=="function"?p({isDragging:v,drag:b,drop:i=>(g.current=i,y(i)),preview:P}):(b(y(P(g))),t.jsx(r.Box,{ref:g,children:p}))}function Ct({drop:e,preview:s,drag:l,disabled:o,isDragging:p,children:h,onDelete:d,onVisibilityChange:g,visible:v=!0,actions:b,alwaysShowActions:P=!1}){const{t:y}=_.useLocaleContext();return t.jsx(r.Box,{ref:e,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:v?1:.5},children:t.jsxs(r.Box,{sx:{position:"relative"},children:[t.jsx(r.Box,{ref:s,sx:{flex:1,borderRadius:.5,bgcolor:p?"action.hover":"background.paper",opacity:.9999},children:h}),!o&&t.jsx(r.Box,{className:P?"":"hover-visible",sx:{maxWidth:P?"100%":0,overflow:"hidden",position:"absolute",right:2,top:2,transition:"max-width 0.3s ease-in-out"},children:t.jsxs(r.Stack,{direction:"row",sx:{bgcolor:i=>r.alpha(i.palette.grey[200],.9),borderRadius:1,p:.5,[`.${r.buttonClasses.root}`]:{minWidth:24,width:24,height:24,p:0}},children:[b,g&&t.jsx(r.Tooltip,{title:y(v?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:()=>g(!v),children:v?t.jsx(D.VisibilityOffRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}}):t.jsx(D.VisibilityRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),d&&t.jsx(r.Tooltip,{title:y("delete"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:d,children:t.jsx(D.DeleteOutlineRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),t.jsx(r.Tooltip,{title:y("dragSort"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{ref:l,children:t.jsx(D.DragIndicatorRounded,{sx:{color:"grey.500"}})})})]})})]})})}function Ot({label:e,value:s,onChange:l}){const[o,p]=C.useState(!1);return t.jsxs(r.Stack,{gap:1,children:[t.jsx(r.TextField,{label:e,size:"small",value:s,onChange:h=>l==null?void 0:l(h.target.value),InputProps:{endAdornment:t.jsx(F.UploaderButton,{onChange:({response:h})=>{var g;const d=(g=h==null?void 0:h.data)==null?void 0:g.filename;d&&(l==null||l(d))}})}}),s&&t.jsx(r.Box,{component:"img",sx:{objectFit:"contain",borderRadius:1,cursor:"pointer"},src:R.getImageAbsoluteUrl(s),alt:e,maxWidth:100,maxHeight:100,width:"100%",onClick:()=>p(!0)}),t.jsx(r.Dialog,{open:o,onClose:()=>p(!1),children:t.jsx(r.Box,{component:"img",sx:{objectFit:"contain"},src:R.getImageAbsoluteUrl(s),alt:e})})]})}function le(e,s=""){return ht.default(e,(l,o,p)=>{const h=s?`${s}.${p}`:p;return xt.default(o)?ut.default(l,le(o,h)):l[h]=o,l},{})}const Tt=[{value:"string",label:"Text"},{value:"multiline",label:"Text (Multiline)"},{value:"number",label:"Number"},{value:"decimal",label:"Decimal"},{value:"boolean",label:"Boolean"},{value:"color",label:"Color"},{value:"url",label:"URL (Upload)"},{value:"json",label:"JSON"},{value:"yaml",label:"YAML"},{value:"array",label:"Array"},{value:"component",label:"Component"},{value:"custom",label:"Custom (Render by a Component)"}];function G(e,s,l){return!e||!l?!1:Object.values(e).some(({data:o})=>o.id!==s&&o.key===l)}function oe(e,s){var l;return!e||!s?!1:((l=e[s])==null?void 0:l.data.visible)??!0}function Bt({componentId:e}){const{state:{components:s}}=R.useStore(),l=s[e],o=l==null?void 0:l.data;return o?t.jsx(r.Stack,{maxHeight:"100%",overflow:"auto",children:t.jsx(r.Box,{p:2,children:t.jsx(rt.ErrorBoundary,{FallbackComponent:R.ErrorView,resetKeys:[e],children:t.jsx(Rt,{value:o})})})}):null}function Rt({value:e}){var b,P,y;const{t:s}=_.useLocaleContext(),{localState:{currentLocale:l,customComponentPreviewerProperties:o},state:{config:{defaultLocale:p}},localActions:{setCustomComponentPreviewerProperties:h}}=R.useStore(),d=Y.getYjsValue(e).doc,g=R.useAllComponents(),v=Pe.useReactive({propertiesValue:{...h}});return C.useEffect(()=>{const i=Object.fromEntries(Object.values(e.properties??{}).map(({data:n})=>{var c,u,x,S,a;return[n.id,{value:((c=v.propertiesValue[n.id])==null?void 0:c.value)??Le.parsePropertyValue(n,((x=(u=n.locales)==null?void 0:u[l])==null?void 0:x.defaultValue)??((a=(S=n.locales)==null?void 0:S[p])==null?void 0:a.defaultValue),{locale:l,defaultLocale:p})}]}));h(i)},[JSON.stringify(v.propertiesValue)]),t.jsx(r.Stack,{height:"100%",children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(Ce,{config:e}),t.jsx(Te,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,onUpdateConfig:i=>{d.transact(()=>{i(e)})}}),t.jsxs(r.Stack,{gap:2,direction:"row",justifyContent:"space-between",alignItems:"center",children:[t.jsx(r.Typography,{variant:"subtitle1",children:s("renderer")}),t.jsxs(r.TextField,{hiddenLabel:!0,size:"small",select:!0,SelectProps:{autoWidth:!0},value:((b=e.renderer)==null?void 0:b.type)||"react-component",onChange:i=>{d.transact(()=>{const n=i.target.value;e.renderer??(e.renderer={type:n}),e.renderer.type=n})},children:[t.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),t.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),((P=e.renderer)==null?void 0:P.type)==="component"&&t.jsx(Nt,{value:e}),((y=e.renderer)==null?void 0:y.type)==="react-component"&&t.jsx(At,{value:e}),t.jsx(ce,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,propertiesValue:o,onChange:({value:i,id:n,path:c})=>{const u=[...c,"data"];if(!dt.default(e,u)){se.default.warning(s("cannotFindPropertyKey",{key:u.join(".")}));return}v.propertiesValue[n]={value:i.value}}})]})})}function Ce({config:e}){const{t:s}=_.useLocaleContext();return t.jsx(F.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(r.Typography,{variant:"subtitle1",children:s("basicInfo")}),t.jsx(r.TextField,{label:s("name"),size:"small",value:e.name||"",onChange:l=>e.name=l.target.value}),t.jsx(r.TextField,{label:s("description"),size:"small",multiline:!0,minRows:2,maxRows:10,inputProps:{maxLength:200},value:e.description||"",onChange:l=>e.description=l.target.value}),t.jsx(r.Autocomplete,{size:"small",options:[],multiple:!0,freeSolo:!0,value:e.tags??[],onChange:(l,o)=>e.tags=o,renderInput:l=>t.jsx(r.TextField,{label:s("tags"),...l})}),t.jsx(Ot,{label:s("previewImage"),value:e.previewImage||"",onChange:l=>e.previewImage=l})]})})}function Oe({data:e,params:s,visible:l,config:o,currentLocale:p,defaultLocale:h,allComponents:d,onUpdateConfig:g}){var P,y,i,n,c,u;const{t:v}=_.useLocaleContext(),b=C.useMemo(()=>e.type==="json"||e.type==="yaml"||e.type==="array"?Vt:U,[e.type]);return t.jsx(Ct,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{g(x=>{if(x.properties){const a=Object.entries(x.properties).sort(([,f],[,k])=>f.index-k.index);delete x.properties[e.id],a.filter(([f])=>f!==e.id).forEach(([,f],k)=>{f.index=k})}})},visible:l,onVisibilityChange:x=>{g(S=>{const a=S.properties[e.id].data;a.visible=x})},alwaysShowActions:!0,children:t.jsxs(r.Stack,{direction:"column",gap:2,children:[t.jsx(r.TextField,{label:v("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:e.key?G(o.properties,e.id,e.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:e.key?G(o.properties,e.id,e.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:e.key?G(o.properties,e.id,e.key)?"warning.main":"primary.main":"error.main"}},value:e.key||"",onChange:x=>{g(S=>{const a=S.properties[e.id].data;a.key=x.target.value.trim()})},InputProps:{endAdornment:!e.key||e.key&&G(o.properties,e.id,e.key)?t.jsx(r.InputAdornment,{position:"end",sx:{width:16,ml:0},children:t.jsx(r.Tooltip,{title:e.key?v("duplicateKey"):v("requiredKey"),children:t.jsx(D.InfoRounded,{sx:{color:e.key?"warning.main":"error.main",fontSize:16}})})}):null}}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(r.TextField,{label:v("label"),size:"small",sx:{flex:1},value:(((y=(P=e.locales)==null?void 0:P[p])==null?void 0:y.name)??((n=(i=e.locales)==null?void 0:i[h])==null?void 0:n.name))||"",onChange:x=>{g(S=>{var j;const a=S.properties[e.id].data;a.locales??(a.locales={}),(j=a.locales)[p]??(j[p]={}),a.locales[p].name=x.target.value})}}),t.jsx(r.TextField,{label:v("type"),size:"small",select:!0,sx:{flex:1},value:e.type==="string"&&e.multiline?"multiline":e.type||"string",onChange:x=>{g(S=>{const a=S.properties[e.id].data;if(a.locales)for(const f of Object.keys(a.locales))a.locales[f].defaultValue=void 0;const j=x.target.value;j==="multiline"?(a.type="string",a.multiline=!0):(typeof a.multiline<"u"&&delete a.multiline,a.type=j)})},children:Tt.map(x=>t.jsx(r.MenuItem,{value:x.value,children:x.label},x.value))})]}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(b,{allComponents:d,defaultLocale:h,component:o,property:e,label:v("defaultValue"),size:"small",fullWidth:!0,value:(u=(c=e.locales)==null?void 0:c[p])==null?void 0:u.defaultValue,onChange:(x,S)=>{g(a=>{var f;const j=a.properties[e.id].data;if(S!=null&&S.forceUpdateProperty){const k=le(j),I=le(x);Object.keys(I).forEach(m=>{k[m]||we.default(j,m,I[m])})}else j.locales??(j.locales={}),(f=j.locales)[p]??(f[p]={}),j.locales[p].defaultValue=x})}}),e.type==="custom"?t.jsx(r.Box,{children:t.jsx(Dt,{property:e,allComponents:d})}):null]})]})})}function _t(e,s){const[l,o]=C.useState(0);return C.useEffect(()=>{const h=setTimeout(()=>{if(e.current){let d=e.current.parentElement,g=0;for(;d;)d.classList.contains("property-container")&&g++,d=d.parentElement;o(g)}},100);return()=>clearTimeout(h)},[e,s]),l}function Te({config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p,useI18nEditor:h=!0}){const{t:d}=_.useLocaleContext(),g=z.usePopupState({variant:"dialog"}),v=e.properties&&E.default(Object.values(e.properties),"index");return t.jsx(F.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsxs(r.Stack,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between",children:[t.jsx(r.Typography,{variant:"subtitle1",children:d("properties")}),t.jsx(r.Box,{flex:1}),h&&t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...z.bindTrigger(g),children:t.jsx(D.TranslateRounded,{fontSize:"small"})})]}),e.properties&&Object.keys(e.properties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.properties,renderItem:(b,P,y)=>{const i=oe(e.properties,b.id);return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:i?"1px solid":"1px dashed",borderColor:"divider"},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:y,visible:i,config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12},children:d("maker.properties.noProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",onClick:()=>{p(b=>{var y;const P=R.nextId();b.properties??(b.properties={}),(y=b.properties)[P]??(y[P]={index:(v==null?void 0:v.length)||0,data:{id:P}})})},startIcon:t.jsx(D.AddRounded,{}),children:d("addObject",{object:d("property")})}),h&&t.jsx(Be,{...z.bindDialog(g),component:e})]})})}function Dt({property:e,allComponents:s}){const l=z.usePopupState({variant:"popper"});return t.jsxs(t.Fragment,{children:[t.jsx(r.Button,{sx:{minWidth:0},...z.bindTrigger(l),children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Popper,{...z.bindPopper(l),children:t.jsx(Se.ClickAwayListener,{onClickAway:l.close,children:t.jsx(r.Paper,{children:t.jsx(r.Box,{width:500,p:2,children:t.jsx(ee,{value:e.componentId,onChange:(o,p)=>e.componentId=p,allComponents:s})})})})})]})}function Et({value:e,valueImmutable:s,onChange:l,defaultLocale:o,allComponents:p}){var P;const[h,d]=C.useState(!1),{t:g,locale:v}=_.useLocaleContext(),b=typeof(e==null?void 0:e.componentId)=="string"?(P=p[e.componentId])==null?void 0:P.data:void 0;return b?t.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[t.jsx(r.IconButton,{sx:{minWidth:0},disabled:!b,size:"small",onClick:()=>d(!h),color:h?"primary":"default",children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),h&&t.jsx(r.Collapse,{in:h,timeout:"auto",unmountOnExit:!0,sx:{width:"100%",zIndex:10},children:t.jsxs(r.Paper,{elevation:1,sx:{mt:1,p:2,borderRadius:1,border:"1px solid",borderColor:"divider",width:"100%"},children:[t.jsx(r.Box,{width:"100%",mb:2,children:t.jsx(ce,{config:b,currentLocale:v,defaultLocale:o,allComponents:p,propertiesValue:e==null?void 0:e.properties,onChange:({id:y,value:i})=>{const n=at.default(i.value),c=JSON.parse(JSON.stringify(e));c!=null&&c.componentId&&(s?l==null||l({...c,properties:{...c.properties,[y]:{value:n}}}):(c.properties=c.properties??{},c.properties[y]={value:n},l==null||l(c)))}})}),t.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:g("close")})]})})]}):null}function Be({type:e="properties",component:s,...l}){var y,i,n;const{t:o}=_.useLocaleContext(),{state:{components:p,supportedLocales:h,config:{defaultLocale:d}}}=R.useStore(),g=R.useAllComponents(),v=Y.getYjsValue(s).doc,b=e==="properties"?s.properties:e==="parameters"&&((y=s.renderer)==null?void 0:y.type)==="component"?(i=p[s.renderer.componentId])==null?void 0:i.data.properties:void 0,P=((n=s.renderer)==null?void 0:n.type)==="component"?s:void 0;return t.jsxs(r.Dialog,{...l,fullWidth:!0,maxWidth:"lg",children:[t.jsx(r.DialogTitle,{children:o("i18nEditorTitle")}),t.jsx(r.DialogContent,{children:b&&t.jsx(r.Stack,{children:t.jsxs(r.Table,{stickyHeader:!0,sx:{td:{verticalAlign:"top"}},children:[t.jsx(r.TableHead,{children:t.jsx(r.TableRow,{children:h.map(({locale:c,name:u})=>t.jsx(r.TableCell,{children:t.jsxs(r.Typography,{color:"text.primary",children:[u,d===c&&t.jsx(D.StarRounded,{sx:{fontSize:12}})]})},c))})}),t.jsx(r.TableBody,{children:E.default(Object.values(b),"index").map(({data:c})=>t.jsx(r.TableRow,{children:h.map(({locale:u})=>{var x,S,a,j,f,k,I,m,w,O,B,V,A,N,$,W,K,L,J,H,ae,ue,de,pe,me,xe;return t.jsx(r.TableCell,{children:t.jsx(r.Stack,{gap:1,children:e==="properties"?t.jsxs(t.Fragment,{children:[t.jsx(r.TextField,{size:"small",label:"Key",value:c.key||"",onChange:M=>{v.transact(()=>{c.key=M.target.value.trim()})}}),t.jsx(r.TextField,{size:"small",label:o("label"),value:(((S=(x=c.locales)==null?void 0:x[u])==null?void 0:S.name)??((j=(a=c.locales)==null?void 0:a[d])==null?void 0:j.name))||"",onChange:M=>{v.transact(()=>{var q;c.locales??(c.locales={}),(q=c.locales)[u]??(q[u]={}),c.locales[u].name=M.target.value})}}),t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:X.default((k=(f=c.locales)==null?void 0:f[u])==null?void 0:k.defaultValue),value:((m=(I=c.locales)==null?void 0:I[u])==null?void 0:m.defaultValue)??((O=(w=c.locales)==null?void 0:w[d])==null?void 0:O.defaultValue),onChange:M=>{v.transact(()=>{var q;c.locales??(c.locales={}),(q=c.locales)[u]??(q[u]={}),c.locales[u].defaultValue=M})}})})]}):e==="parameters"&&P?t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,valueImmutable:X.default((N=(A=(V=(B=P.renderer.properties)==null?void 0:B[c.id])==null?void 0:V.locales)==null?void 0:A[u])==null?void 0:N.value),value:((L=(K=(W=($=P.renderer.properties)==null?void 0:$[c.id])==null?void 0:W.locales)==null?void 0:K[u])==null?void 0:L.value)??((ue=(ae=(H=(J=P.renderer.properties)==null?void 0:J[c.id])==null?void 0:H.locales)==null?void 0:ae[d])==null?void 0:ue.value)??((pe=(de=c.locales)==null?void 0:de[u])==null?void 0:pe.defaultValue)??((xe=(me=c.locales)==null?void 0:me[d])==null?void 0:xe.defaultValue),onChange:M=>{v.transact(()=>{var q,fe,je,be,he;(q=P.renderer).properties??(q.properties={}),(fe=P.renderer.properties)[je=c.id]??(fe[je]={}),(be=P.renderer.properties[c.id]).locales??(be.locales={}),(he=P.renderer.properties[c.id].locales)[u]??(he[u]={}),P.renderer.properties[c.id].locales[u].value=M})}})}):null},c.id)},u)})},c.id))})]})})}),t.jsx(r.DialogActions,{children:t.jsx(r.Button,{onClick:c=>{var u;return(u=l.onClose)==null?void 0:u.call(l,c,"escapeKeyDown")},children:o("close")})})]})}const ve=(e,s)=>l=>{const o=[l.palette.info.main,l.palette.primary.main,l.palette.secondary.main,l.palette.success.main,l.palette.warning.main],p=Math.min(o.length-1,e),h=o[p],d=r.alpha(h,.5),g=r.alpha(h,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:g,...s}};function Vt({property:e,onChange:s,defaultLocale:l,allComponents:o}){const{t:p,locale:h}=_.useLocaleContext(),d=C.useRef(null),g=_t(d,e),v=C.useCallback(()=>{if(!(e.type!=="json"&&e.type!=="yaml"&&e.type!=="array")&&e.subProperties)try{let b={};E.default(Object.values(e.subProperties),"index").filter(i=>i.data.visible!==!1&&i.data.key).forEach(({data:i})=>{var c,u,x,S;if(!i.key)return;let n=((u=(c=i.locales)==null?void 0:c[h])==null?void 0:u.defaultValue)??((S=(x=i.locales)==null?void 0:x[l])==null?void 0:S.defaultValue);if(i.type==="number")n=Number(n);else if(i.type==="boolean")n=n===!0||n==="true";else if((i.type==="json"||i.type==="yaml")&&typeof n=="string")try{i.type==="json"?n=JSON.parse(n):n=re.parse(n)}catch(a){console.error("Error parsing nested value",n,a),n={}}b[i.key]=n}),e.type==="array"&&!Array.isArray(b)&&(b=ne.default(b)?[]:[b]);const y=R.transformValue(b,e.type);s==null||s(y)}catch(b){console.error("Error converting structure to text:",b)}},[e,h,l,s]);return e.type!=="json"&&e.type!=="yaml"&&e.type!=="array"?null:t.jsxs(r.Stack,{direction:"column",gap:1.5,sx:{width:"100%"},ref:d,children:[t.jsx(r.Divider,{sx:{mt:-1},children:t.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:p("maker.properties.subProperties")})}),e.subProperties&&Object.keys(e.subProperties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.subProperties,renderItem:(b,P,y)=>{const i=b.visible!==!1;return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:i?"1px solid":"1px dashed","&":ve(g)},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:y,visible:i,config:{properties:e.subProperties},currentLocale:h,defaultLocale:l,allComponents:o,onUpdateConfig:n=>{try{const c={properties:e.subProperties||{}};n(c);const u={...e,subProperties:c.properties};s==null||s(u,{forceUpdateProperty:!0}),v()}catch(c){console.error("Error updating property:",c)}}})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12,height:100},children:p("maker.properties.noSubProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",size:"small",startIcon:t.jsx(D.AddRounded,{}),onClick:()=>{try{const b=e.subProperties||{},P=R.nextId(),i={index:Object.values(b).length,data:{id:P,key:"",type:"string",visible:!0,locales:{[h]:{name:"",defaultValue:""}},subProperties:{}}},n={...e,subProperties:{...b,[P]:i}};s==null||s(n,{forceUpdateProperty:!0}),v()}catch(b){console.error("Error adding property:",b)}},sx:{"&":ve(g,{})},children:p("maker.properties.addSubProperty")})]})}function U({component:e,property:s,value:l,onChange:o,valueImmutable:p,defaultLocale:h,allComponents:d,...g}){var n,c,u,x,S;const{locale:v}=_.useLocaleContext(),b=F.useUploader(),P=C.useRef(null),y=()=>{var j;const a=(j=b==null?void 0:b.current)==null?void 0:j.getUploader();a==null||a.open(),P.current&&a.onceUploadSuccess(({response:f})=>{var I,m;let k=((I=f==null?void 0:f.data)==null?void 0:I.filename)||"";k&&(k=`mediakit://${k}`,l&&!l.includes("mediakit://")&&(k+=" # please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address")),(m=P.current)==null||m.call(P,k)})},i=g.label??(((c=(n=s.locales)==null?void 0:n[v])==null?void 0:c.name)||((x=(u=s.locales)==null?void 0:u[h])==null?void 0:x.name)||s.key||s.id);if(s.type==="number")return t.jsx(zt,{...g,label:i,NumberProps:{value:["number","string"].includes(typeof l)?l:null,onChange:(a,j)=>o==null?void 0:o(j)}});if(s.type==="decimal")return t.jsx(r.TextField,{...g,label:i,type:"text",value:l??"",onChange:a=>{const j=a.target.value;if(j===""||j==="-"){o==null||o(j);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(j)){let k=j;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(k)&&(k=Number(k)),o==null||o(k)}}});if(s.type==="boolean")return t.jsx(r.FormControlLabel,{label:i,labelPlacement:"start",control:t.jsx(r.Switch,{checked:l===!0,onChange:(a,j)=>o==null?void 0:o(j)})});if(s.type==="color")return t.jsx(St,{label:i,value:l,onChange:a=>{o==null||o(a)}});if(s.type==="json"||s.type==="yaml")return t.jsx(Pt,{label:i,value:l,onChange:a=>{o==null||o(a)},property:s,component:e,defaultLocale:h,allComponents:d,PropertyValueField:U,onUpload:a=>{P.current=a,y()}});if(s.type==="custom"){const a=(S=d[s.componentId])==null?void 0:S.data;return a?t.jsx(r.Box,{width:"100%",children:t.jsx(Q.CustomComponentRenderer,{componentId:a.id,props:{label:i,value:l,onChange:o},locale:v,dev:{mode:"draft",components:d,defaultLocale:h}})}):t.jsx(r.TextField,{...g,label:i,disabled:!0,placeholder:"Click right button select a component"})}if(s.type==="component")return t.jsxs(r.Stack,{width:"100%",direction:"column",gap:1,children:[t.jsx(ee,{allComponents:d,label:i,value:l==null?void 0:l.componentId,onChange:(a,j)=>{p||!l?o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:j}):typeof l=="object"&&(l.componentId=j,o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:j}))}}),(l==null?void 0:l.componentId)&&t.jsx(Et,{value:l,valueImmutable:p,onChange:o,defaultLocale:h,allComponents:d})]});if(!s.type||["string","url","multiline"].includes(s.type)){let a=s.type==="string"?s.multiline:void 0;s.type==="multiline"&&(a=!0);const j=s.type==="url"?l==null?void 0:l.url:l;return t.jsx(r.TextField,{...g,label:i,value:typeof j=="string"?j:"",multiline:a,minRows:a?2:void 0,maxRows:a?10:void 0,onChange:f=>o==null?void 0:o(s.type==="url"?{...l,url:f.target.value,mediaKitUrl:f.target.value}:f.target.value),InputProps:s.type==="url"?{sx:{pr:0},endAdornment:t.jsxs(r.InputAdornment,{position:"end",children:[t.jsx(F.UploaderButton,{onChange:async({response:f})=>{var w,O,B;const k=((w=f==null?void 0:f.data)==null?void 0:w.url)||((O=f==null?void 0:f.data)==null?void 0:O.fileUrl);let I;k&&(I=await F.getImageSize(k).catch(()=>F.getVideoSize(k)).catch(()=>{}));let m=((B=f==null?void 0:f.data)==null?void 0:B.filename)||"";m&&(m=`mediakit://${m}`),o==null||o({url:k,mediaKitUrl:m,width:I==null?void 0:I.naturalWidth,height:I==null?void 0:I.naturalHeight})}}),t.jsx(r.Tooltip,{title:"If you are using the 'mediaKitUrl' property, please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address.",children:t.jsx(D.InfoRounded,{sx:{cursor:"default",mr:1},fontSize:"small"})})]})}:void 0})}return s.type==="array"?t.jsx(kt,{label:i,value:Array.isArray(l)?l:[],onChange:a=>o==null?void 0:o(a),property:s,renderItem:({item:a,index:j,onChange:f})=>s.subProperties&&Object.keys(s.subProperties).length>0?t.jsx(r.Stack,{gap:1,width:"100%",children:E.default(Object.values(s.subProperties),"index").filter(k=>k.data.visible!==!1).map(({data:k})=>k.key?t.jsx(U,{component:e,property:k,value:a[k.key],onChange:I=>{const m={...a,[k.key]:I};f(m)},size:"small",fullWidth:!0,defaultLocale:h,allComponents:d},k.id):null)},j):t.jsx(r.TextField,{size:g.size,fullWidth:!0,value:a,onChange:k=>f(k.target.value)})}):(console.error("Unsupported property type",s.type),null)}function zt({NumberProps:e,...s}){const{getInputProps:l}=Se.unstable_useNumberInput(e),o=l();return t.jsx(r.TextField,{...s,inputProps:o})}const Re=`import React from '@blocklet/pages-kit/builtin/react'
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),R=require("./chunks/state-CA6q2h83.js"),De=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),ie=require("@blocklet/code-editor"),Ee=require("@mui/icons-material/AddRounded"),Ve=require("@mui/icons-material/ArrowDownward"),ze=require("@mui/icons-material/ArrowUpward"),Ae=require("@mui/icons-material/DeleteOutline"),r=require("@mui/material"),Ne=require("lodash/sortBy"),C=require("react"),ke=require("react-use"),ye=require("@blocklet/pages-kit/builtin/color-picker"),qe=require("./chunks/config-string-CqKhhXBA.js"),Fe=require("lodash/isEmpty"),Ue=require("lodash/set"),Me=require("yaml"),z=require("@blocklet/pages-kit/builtin/uploader"),We=require("lodash/cloneDeep"),Ke=require("@arcblock/ux/lib/Toast"),Q=require("@blocklet/pages-kit/components"),Le=require("@blocklet/pages-kit/utils/property"),Se=require("@mui/base"),D=require("@mui/icons-material"),Y=require("@syncedstore/core"),Pe=require("ahooks"),Je=require("lodash/assign"),He=require("lodash/get"),Ye=require("lodash/has"),$e=require("lodash/isEqual"),Ge=require("lodash/isNil"),Qe=require("lodash/isObject"),Xe=require("lodash/keyBy"),Ze=require("lodash/omit"),et=require("lodash/pick"),tt=require("lodash/reduce"),A=require("material-ui-popup-state/hooks"),rt=require("react-error-boundary"),st=require("@emotion/css"),te=require("react-dnd"),T=e=>e&&e.__esModule?e:{default:e};function lt(e){if(e&&e.__esModule)return e;const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const o=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(s,l,o.get?o:{enumerable:!0,get:()=>e[l]})}}return s.default=e,Object.freeze(s)}const Z=T(De),ot=T(Ee),it=T(Ve),nt=T(ze),ct=T(Ae),E=T(Ne),ne=T(Fe),we=T(Ue),re=lt(Me),at=T(We),se=T(Ke),ut=T(Je),dt=T(He),pt=T(Ye),mt=T($e),X=T(Ge),xt=T(Qe),ft=T(Xe),jt=T(Ze),bt=T(et),ht=T(tt);function yt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"warning",variant:"outlined",disabled:s,onClick:e,...o,children:t.jsx(ct.default,{fontSize:"small"})})}function gt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(nt.default,{fontSize:"small"})})}function vt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(it.default,{fontSize:"small"})})}function kt({label:e,value:s,onChange:l,disabled:o=!1,itemLabel:p="",emptyHeight:h=40,property:d,renderItem:g,...v}){const{t:b,locale:P}=_.useLocaleContext(),y=ke.useUpdate(),i=C.useCallback(m=>{l(R.transformValue(m,d.type))},[l,d.type]),n=C.useMemo(()=>Array.isArray(s)?s:[],[s]),c=C.useCallback(()=>{const m=[...n,""];i(m),y()},[n,i,y]),u=C.useCallback(()=>{if(!d||!d.subProperties)return c();const m={};E.default(Object.values(d.subProperties),"index").forEach(({data:B})=>{var N,q;if(!B.key)return;const V=((q=(N=B.locales)==null?void 0:N[P])==null?void 0:q.defaultValue)??"";m[B.key]=V});const O=[...n,m];i(O),y()},[n,i,y,d,P,c]),x=C.useCallback(m=>{try{const w=JSON.parse(m);Array.isArray(w)?i(w):console.error("JSON解析结果不是数组")}catch(w){console.error("JSON解析错误:",w)}},[i]),S=C.useCallback(m=>{const w=n.filter((O,B)=>B!==m);i(w),y()},[n,i,y]),a=C.useCallback(m=>{if(m<=0)return;const w=[...n],O=w[m];w[m]=w[m-1],w[m-1]=O,i(w),y()},[n,i,y]),j=C.useCallback(m=>{if(m>=n.length-1)return;const w=[...n],O=w[m];w[m]=w[m+1],w[m+1]=O,i(w),y()},[n,i,y]),f=C.useCallback((m,w)=>{const O=[...n];O[m]=w,i(O)},[n,i]),k=d&&d.subProperties&&Object.keys(d.subProperties).length>0,I=C.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:m})=>t.jsx(r.Typography,{variant:"body1",sx:{bgcolor:"action.hover",borderRadius:"50%",width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:m+1})},{field:"content",headerName:"",renderCell:({row:m,index:w})=>g&&k?g({item:m,index:w,property:d,onChange:O=>f(w,O)}):t.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:o,value:m,placeholder:p||`${b("item")} ${w+1}`,onChange:O=>f(w,O.target.value),...v})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:m})=>t.jsxs(r.Stack,{direction:"column",spacing:.25,children:[t.jsx(gt,{disabled:o||m===0,onClick:()=>a(m)}),t.jsx(vt,{disabled:o||m===n.length-1,onClick:()=>j(m)}),t.jsx(yt,{disabled:o,onClick:()=>S(m)})]})}],[g,k,d,f,p,b,o,v,S,a,j,n.length]);return k?t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),n.length>0?t.jsx(r.TableContainer,{component:r.Paper,variant:"outlined",sx:{borderRadius:1,mb:1},children:t.jsxs(r.Table,{size:"small",sx:{"& .MuiTableCell-root":{py:.25,px:1,whiteSpace:"nowrap"},"& .MuiTableCell-head":{backgroundColor:"action.hover",py:.25,px:1},borderCollapse:"collapse"},children:[t.jsx(r.TableHead,{sx:{display:"none"},children:t.jsx(r.TableRow,{children:I.map(m=>t.jsx(r.TableCell,{width:m.width,align:m.align||"left",sx:{fontWeight:"bold"},children:m.renderHeader?m.renderHeader():m.headerName},m.field))})}),t.jsx(r.TableBody,{children:n.map((m,w,O)=>t.jsx(r.TableRow,{sx:{borderBottom:w<O.length-1?"1px solid":"none",borderColor:"divider","&:hover":{backgroundColor:"action.hover"}},children:I.map(B=>t.jsx(r.TableCell,{width:B.width,align:B.align||"left",sx:{borderBottom:"none"},children:B.renderCell({row:m,index:w,onChange:V=>f(w,V)})},`${w}-${B.field}`))},w))})]})}):t.jsx(Z.default,{style:{fontSize:12,height:h},children:b("maker.properties.arrayEmpty")}),t.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:o,startIcon:t.jsx(ot.default,{}),onClick:u,children:b("maker.properties.addArrayItem")})]}):t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,minHeight:150},children:t.jsx(ie.CodeEditor,{keyId:d.id,locale:P,language:"json",value:JSON.stringify(n,null,2),onChange:m=>x(m||""),fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},d.id)})]})}function St({value:e,onChange:s,...l}){const o=C.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsx(qe.ConfigString,{...l,value:e,onChange:s,InputProps:{endAdornment:t.jsx(r.InputAdornment,{position:"end",children:t.jsx(ye.ColorItem,{color:e??"",style:{width:"1.5rem",height:"1.5rem",padding:0},onClick:()=>{var p;(p=o.current)==null||p.open({value:e??""})}})})}}),t.jsx(ye.ConfigColorDialog,{ref:o,onSave:({value:p},h)=>{s(p),h()}})]})}function Pt({label:e,value:s,onChange:l,property:o,component:p,defaultLocale:h,allComponents:d,PropertyValueField:g,onUpload:v}){const{locale:b}=_.useLocaleContext(),P=C.useRef(null);if(!ne.default(o.subProperties)){const i=E.default(Object.values(o.subProperties||{}),"index").filter(n=>n.data.visible!==!1&&n.data.key);return t.jsxs(r.Stack,{width:"100%",children:[t.jsx(r.FormLabel,{sx:{px:.25,py:.5},children:e}),t.jsx(r.Box,{children:t.jsx(r.Box,{sx:{position:"relative"},children:i.map((n,c)=>{const{data:u}=n,x=u.key??u.id,S=c===i.length-1;let a=null;try{s&&typeof s=="object"?a=s[x]:typeof s=="string"&&(a=(o.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}"))[x])}catch{}a==null&&(u.locales&&b&&u.locales[b]?a=u.locales[b].defaultValue:u.locales&&h&&u.locales[h]&&(a=u.locales[h].defaultValue));const j=k=>{try{let I={};if(typeof s=="string")try{I=o.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(I={...s});we.default(I,x,k);const m=R.transformValue(I,o.type);l==null||l(m)}catch(I){console.error("Error updating property:",I)}},f=8;return t.jsxs(r.Box,{sx:{mb:S?0:1,display:"flex",flexDirection:"row"},children:[t.jsxs(r.Box,{sx:{position:"relative",width:24,flexShrink:0},children:[t.jsx(r.Box,{sx:{position:"absolute",left:f,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),t.jsx(r.Box,{sx:{position:"absolute",left:f,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!S&&t.jsx(r.Box,{sx:{position:"absolute",left:f,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),t.jsx(r.Box,{sx:{flexGrow:1},children:t.jsx(g,{component:p,property:u,value:a,onChange:j,size:"small",fullWidth:!0,defaultLocale:h,allComponents:d})})]},u.id)})})})]})}return t.jsx(r.Stack,{width:"100%",gap:2,children:t.jsxs(r.Stack,{sx:{width:"100%",position:"relative",pt:1,pb:"6px",px:"1px",minHeight:50,".monaco-editor,.overflow-guard":{borderRadius:1}},children:[t.jsx(r.FormLabel,{sx:{position:"absolute",left:0,top:0,transform:"translate(0px, -7px) scale(0.75)"},children:e}),t.jsx(ie.CodeEditor,{keyId:o.id,locale:b,language:o.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:i=>{l==null||l(i)},onUpload:i=>{P.current=i,v&&v(i)},fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},o.id),t.jsx(r.Box,{component:"fieldset",sx:{pointerEvents:"none",position:"absolute",left:0,top:-5,width:"100%",height:"100%",border:1,borderColor:"rgba(0, 0, 0, 0.23)",borderRadius:1,px:1,py:0},children:t.jsx(r.Box,{component:"legend",sx:{fontSize:"0.75em"},children:t.jsx(r.Box,{component:"span",sx:{opacity:0},children:e})})})]})})}const wt=["string","multiline","json","yaml","url","component","custom","array"];function ge(e){return e.type?!wt.includes(e.type):!1}function Ie({disabled:e,list:s,renderItem:l,...o}){const p=C.useRef(null),h=C.useId(),d=Pe.useUpdate(),g=E.default(Object.entries(s),n=>n[1].index).map(n=>n[0]),v=C.useRef(g),b=C.useCallback(n=>{v.current=n,d()},[d]),P=C.useCallback(({index:n},{index:c})=>{const u=[...v.current];u.splice(c,0,...u.splice(n,1)),b(u)},[b]);C.useEffect(()=>{b(g)},[g.join("-")]);const[{isOver:y},i]=te.useDrop({accept:h,collect:n=>({isOver:n.isOver()}),canDrop:()=>!e,drop:()=>{var u;const n=()=>{v.current.forEach((x,S)=>{const a=s[x];a&&(a.index=S)})},c=(u=Y.getYjsValue(s))==null?void 0:u.doc;c?c.transact(()=>{n()}):n()}});return C.useEffect(()=>{y||b(g)},[y]),i(p),t.jsx(r.Box,{...o,ref:p,className:st.cx(y&&"isDragging"),children:v.current.map((n,c)=>t.jsx(It,{type:h,disabled:e,id:n,index:c,itemIndex:u=>v.current.indexOf(u),move:P,children:u=>{const x=s[n];return x?l(x.data,c,u):null}},n))})}function It({disabled:e,id:s,index:l,type:o,children:p,itemIndex:h,move:d}){const g=C.useRef(),[{isDragging:v},b,P]=te.useDrag({type:o,item:()=>({id:s}),canDrag:()=>!e,collect:i=>({isDragging:i.isDragging()})}),[,y]=te.useDrop({accept:o,canDrop:()=>!e,hover(i,n){var f;if(!g.current)return;const c=h(i.id),u=l;if(c===u)return;const x=(f=g.current)==null?void 0:f.getBoundingClientRect(),S=(x.bottom-x.top)/2,j=n.getClientOffset().y-x.top;c<u&&j<S||c>u&&j>S||d({id:i.id,index:c},{id:s,index:l})}});return typeof p=="function"?p({isDragging:v,drag:b,drop:i=>(g.current=i,y(i)),preview:P}):(b(y(P(g))),t.jsx(r.Box,{ref:g,children:p}))}function Ct({drop:e,preview:s,drag:l,disabled:o,isDragging:p,children:h,onDelete:d,onVisibilityChange:g,visible:v=!0,actions:b,alwaysShowActions:P=!1}){const{t:y}=_.useLocaleContext();return t.jsx(r.Box,{ref:e,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:v?1:.5},children:t.jsxs(r.Box,{sx:{position:"relative"},children:[t.jsx(r.Box,{ref:s,sx:{flex:1,borderRadius:.5,bgcolor:p?"action.hover":"background.paper",opacity:.9999},children:h}),!o&&t.jsx(r.Box,{className:P?"":"hover-visible",sx:{maxWidth:P?"100%":0,overflow:"hidden",position:"absolute",right:2,top:2,transition:"max-width 0.3s ease-in-out"},children:t.jsxs(r.Stack,{direction:"row",sx:{bgcolor:i=>r.alpha(i.palette.grey[200],.9),borderRadius:1,p:.5,[`.${r.buttonClasses.root}`]:{minWidth:24,width:24,height:24,p:0}},children:[b,g&&t.jsx(r.Tooltip,{title:y(v?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:()=>g(!v),children:v?t.jsx(D.VisibilityOffRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}}):t.jsx(D.VisibilityRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),d&&t.jsx(r.Tooltip,{title:y("delete"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:d,children:t.jsx(D.DeleteOutlineRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),t.jsx(r.Tooltip,{title:y("dragSort"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{ref:l,children:t.jsx(D.DragIndicatorRounded,{sx:{color:"grey.500"}})})})]})})]})})}function Ot({label:e,value:s,onChange:l}){const[o,p]=C.useState(!1);return t.jsxs(r.Stack,{gap:1,children:[t.jsx(r.TextField,{label:e,size:"small",value:s,onChange:h=>l==null?void 0:l(h.target.value),InputProps:{endAdornment:t.jsx(z.UploaderButton,{onChange:({response:h})=>{var g;const d=(g=h==null?void 0:h.data)==null?void 0:g.filename;d&&(l==null||l(d))}})}}),s&&t.jsx(r.Box,{component:"img",sx:{objectFit:"contain",borderRadius:1,cursor:"pointer"},src:R.getImageAbsoluteUrl(s),alt:e,maxWidth:100,maxHeight:100,width:"100%",onClick:()=>p(!0)}),t.jsx(r.Dialog,{open:o,onClose:()=>p(!1),children:t.jsx(r.Box,{component:"img",sx:{objectFit:"contain"},src:R.getImageAbsoluteUrl(s),alt:e})})]})}function le(e,s=""){return ht.default(e,(l,o,p)=>{const h=s?`${s}.${p}`:p;return xt.default(o)?ut.default(l,le(o,h)):l[h]=o,l},{})}const Tt=[{value:"string",label:"Text"},{value:"multiline",label:"Text (Multiline)"},{value:"number",label:"Number"},{value:"decimal",label:"Decimal"},{value:"boolean",label:"Boolean"},{value:"color",label:"Color"},{value:"url",label:"URL (Upload)"},{value:"json",label:"JSON"},{value:"yaml",label:"YAML"},{value:"array",label:"Array"},{value:"component",label:"Component"},{value:"custom",label:"Custom (Render by a Component)"}];function G(e,s,l){return!e||!l?!1:Object.values(e).some(({data:o})=>o.id!==s&&o.key===l)}function oe(e,s){var l;return!e||!s?!1:((l=e[s])==null?void 0:l.data.visible)??!0}function Bt({componentId:e}){const{state:{components:s}}=R.useStore(),l=s[e],o=l==null?void 0:l.data;return o?t.jsx(r.Stack,{maxHeight:"100%",overflow:"auto",children:t.jsx(r.Box,{p:2,children:t.jsx(rt.ErrorBoundary,{FallbackComponent:R.ErrorView,resetKeys:[e],children:t.jsx(Rt,{value:o})})})}):null}function Rt({value:e}){var b,P,y;const{t:s}=_.useLocaleContext(),{localState:{currentLocale:l,customComponentPreviewerProperties:o},state:{config:{defaultLocale:p}},localActions:{setCustomComponentPreviewerProperties:h}}=R.useStore(),d=Y.getYjsValue(e).doc,g=R.useAllComponents(),v=Pe.useReactive({propertiesValue:{...h}});return C.useEffect(()=>{const i=Object.fromEntries(Object.values(e.properties??{}).map(({data:n})=>{var c,u,x,S,a;return[n.id,{value:((c=v.propertiesValue[n.id])==null?void 0:c.value)??Le.parsePropertyValue(n,((x=(u=n.locales)==null?void 0:u[l])==null?void 0:x.defaultValue)??((a=(S=n.locales)==null?void 0:S[p])==null?void 0:a.defaultValue),{locale:l,defaultLocale:p})}]}));h(i)},[JSON.stringify(v.propertiesValue)]),t.jsx(r.Stack,{height:"100%",children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(Ce,{config:e}),t.jsx(Te,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,onUpdateConfig:i=>{d.transact(()=>{i(e)})}}),t.jsxs(r.Stack,{gap:2,direction:"row",justifyContent:"space-between",alignItems:"center",children:[t.jsx(r.Typography,{variant:"subtitle1",children:s("renderer")}),t.jsxs(r.TextField,{hiddenLabel:!0,size:"small",select:!0,SelectProps:{autoWidth:!0},value:((b=e.renderer)==null?void 0:b.type)||"react-component",onChange:i=>{d.transact(()=>{const n=i.target.value;e.renderer??(e.renderer={type:n}),e.renderer.type=n})},children:[t.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),t.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),((P=e.renderer)==null?void 0:P.type)==="component"&&t.jsx(Nt,{value:e}),((y=e.renderer)==null?void 0:y.type)==="react-component"&&t.jsx(At,{value:e}),t.jsx(ce,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,propertiesValue:o,onChange:({value:i,id:n,path:c})=>{const u=[...c,"data"];if(!dt.default(e,u)){se.default.warning(s("cannotFindPropertyKey",{key:u.join(".")}));return}v.propertiesValue[n]={value:i.value}}})]})})}function Ce({config:e}){const{t:s}=_.useLocaleContext();return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(r.Typography,{variant:"subtitle1",children:s("basicInfo")}),t.jsx(r.TextField,{label:s("name"),size:"small",value:e.name||"",onChange:l=>e.name=l.target.value}),t.jsx(r.TextField,{label:s("description"),size:"small",multiline:!0,minRows:2,maxRows:10,inputProps:{maxLength:200},value:e.description||"",onChange:l=>e.description=l.target.value}),t.jsx(r.Autocomplete,{size:"small",options:[],multiple:!0,freeSolo:!0,value:e.tags??[],onChange:(l,o)=>e.tags=o,renderInput:l=>t.jsx(r.TextField,{label:s("tags"),...l})}),t.jsx(Ot,{label:s("previewImage"),value:e.previewImage||"",onChange:l=>e.previewImage=l})]})})}function Oe({data:e,params:s,visible:l,config:o,currentLocale:p,defaultLocale:h,allComponents:d,onUpdateConfig:g}){var P,y,i,n,c,u;const{t:v}=_.useLocaleContext(),b=C.useMemo(()=>e.type==="json"||e.type==="yaml"||e.type==="array"?Vt:U,[e.type]);return t.jsx(Ct,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{g(x=>{if(x.properties){const a=Object.entries(x.properties).sort(([,f],[,k])=>f.index-k.index);delete x.properties[e.id],a.filter(([f])=>f!==e.id).forEach(([,f],k)=>{f.index=k})}})},visible:l,onVisibilityChange:x=>{g(S=>{const a=S.properties[e.id].data;a.visible=x})},alwaysShowActions:!0,children:t.jsxs(r.Stack,{direction:"column",gap:2,children:[t.jsx(r.TextField,{label:v("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:e.key?G(o.properties,e.id,e.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:e.key?G(o.properties,e.id,e.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:e.key?G(o.properties,e.id,e.key)?"warning.main":"primary.main":"error.main"}},value:e.key||"",onChange:x=>{g(S=>{const a=S.properties[e.id].data;a.key=x.target.value.trim()})},InputProps:{endAdornment:!e.key||e.key&&G(o.properties,e.id,e.key)?t.jsx(r.InputAdornment,{position:"end",sx:{width:16,ml:0},children:t.jsx(r.Tooltip,{title:e.key?v("duplicateKey"):v("requiredKey"),children:t.jsx(D.InfoRounded,{sx:{color:e.key?"warning.main":"error.main",fontSize:16}})})}):null}}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(r.TextField,{label:v("label"),size:"small",sx:{flex:1},value:(((y=(P=e.locales)==null?void 0:P[p])==null?void 0:y.name)??((n=(i=e.locales)==null?void 0:i[h])==null?void 0:n.name))||"",onChange:x=>{g(S=>{var j;const a=S.properties[e.id].data;a.locales??(a.locales={}),(j=a.locales)[p]??(j[p]={}),a.locales[p].name=x.target.value})}}),t.jsx(r.TextField,{label:v("type"),size:"small",select:!0,sx:{flex:1},value:e.type==="string"&&e.multiline?"multiline":e.type||"string",onChange:x=>{g(S=>{const a=S.properties[e.id].data;if(a.locales)for(const f of Object.keys(a.locales))a.locales[f].defaultValue=void 0;const j=x.target.value;j==="multiline"?(a.type="string",a.multiline=!0):(typeof a.multiline<"u"&&delete a.multiline,a.type=j)})},children:Tt.map(x=>t.jsx(r.MenuItem,{value:x.value,children:x.label},x.value))})]}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(b,{allComponents:d,defaultLocale:h,component:o,property:e,label:v("defaultValue"),size:"small",fullWidth:!0,value:(u=(c=e.locales)==null?void 0:c[p])==null?void 0:u.defaultValue,onChange:(x,S)=>{g(a=>{var f;const j=a.properties[e.id].data;if(S!=null&&S.forceUpdateProperty){const k=le(j),I=le(x);Object.keys(I).forEach(m=>{k[m]||we.default(j,m,I[m])})}else j.locales??(j.locales={}),(f=j.locales)[p]??(f[p]={}),j.locales[p].defaultValue=x})}}),e.type==="custom"?t.jsx(r.Box,{children:t.jsx(Dt,{property:e,allComponents:d})}):null]})]})})}function _t(e,s){const[l,o]=C.useState(0);return C.useEffect(()=>{const h=setTimeout(()=>{if(e.current){let d=e.current.parentElement,g=0;for(;d;)d.classList.contains("property-container")&&g++,d=d.parentElement;o(g)}},100);return()=>clearTimeout(h)},[e,s]),l}function Te({config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p,useI18nEditor:h=!0}){const{t:d}=_.useLocaleContext(),g=A.usePopupState({variant:"dialog"}),v=e.properties&&E.default(Object.values(e.properties),"index");return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsxs(r.Stack,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between",children:[t.jsx(r.Typography,{variant:"subtitle1",children:d("properties")}),t.jsx(r.Box,{flex:1}),h&&t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...A.bindTrigger(g),children:t.jsx(D.TranslateRounded,{fontSize:"small"})})]}),e.properties&&Object.keys(e.properties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.properties,renderItem:(b,P,y)=>{const i=oe(e.properties,b.id);return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:i?"1px solid":"1px dashed",borderColor:"divider"},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:y,visible:i,config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12},children:d("maker.properties.noProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",onClick:()=>{p(b=>{var y;const P=R.nextId();b.properties??(b.properties={}),(y=b.properties)[P]??(y[P]={index:(v==null?void 0:v.length)||0,data:{id:P}})})},startIcon:t.jsx(D.AddRounded,{}),children:d("addObject",{object:d("property")})}),h&&t.jsx(Be,{...A.bindDialog(g),component:e})]})})}function Dt({property:e,allComponents:s}){const l=A.usePopupState({variant:"popper"});return t.jsxs(t.Fragment,{children:[t.jsx(r.Button,{sx:{minWidth:0},...A.bindTrigger(l),children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Popper,{...A.bindPopper(l),children:t.jsx(Se.ClickAwayListener,{onClickAway:l.close,children:t.jsx(r.Paper,{children:t.jsx(r.Box,{width:500,p:2,children:t.jsx(ee,{value:e.componentId,onChange:(o,p)=>e.componentId=p,allComponents:s})})})})})]})}function Et({value:e,valueImmutable:s,onChange:l,defaultLocale:o,allComponents:p}){var P;const[h,d]=C.useState(!1),{t:g,locale:v}=_.useLocaleContext(),b=typeof(e==null?void 0:e.componentId)=="string"?(P=p[e.componentId])==null?void 0:P.data:void 0;return b?t.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[t.jsx(r.IconButton,{sx:{minWidth:0},disabled:!b,size:"small",onClick:()=>d(!h),color:h?"primary":"default",children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),h&&t.jsx(r.Collapse,{in:h,timeout:"auto",unmountOnExit:!0,sx:{width:"100%",zIndex:10},children:t.jsxs(r.Paper,{elevation:1,sx:{mt:1,p:2,borderRadius:1,border:"1px solid",borderColor:"divider",width:"100%"},children:[t.jsx(r.Box,{width:"100%",mb:2,children:t.jsx(ce,{config:b,currentLocale:v,defaultLocale:o,allComponents:p,propertiesValue:e==null?void 0:e.properties,onChange:({id:y,value:i})=>{const n=at.default(i.value),c=JSON.parse(JSON.stringify(e));c!=null&&c.componentId&&(s?l==null||l({...c,properties:{...c.properties,[y]:{value:n}}}):(c.properties=c.properties??{},c.properties[y]={value:n},l==null||l(c)))}})}),t.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:g("close")})]})})]}):null}function Be({type:e="properties",component:s,...l}){var y,i,n;const{t:o}=_.useLocaleContext(),{state:{components:p,supportedLocales:h,config:{defaultLocale:d}}}=R.useStore(),g=R.useAllComponents(),v=Y.getYjsValue(s).doc,b=e==="properties"?s.properties:e==="parameters"&&((y=s.renderer)==null?void 0:y.type)==="component"?(i=p[s.renderer.componentId])==null?void 0:i.data.properties:void 0,P=((n=s.renderer)==null?void 0:n.type)==="component"?s:void 0;return t.jsxs(r.Dialog,{...l,fullWidth:!0,maxWidth:"lg",children:[t.jsx(r.DialogTitle,{children:o("i18nEditorTitle")}),t.jsx(r.DialogContent,{children:b&&t.jsx(r.Stack,{children:t.jsxs(r.Table,{stickyHeader:!0,sx:{td:{verticalAlign:"top"}},children:[t.jsx(r.TableHead,{children:t.jsx(r.TableRow,{children:h.map(({locale:c,name:u})=>t.jsx(r.TableCell,{children:t.jsxs(r.Typography,{color:"text.primary",children:[u,d===c&&t.jsx(D.StarRounded,{sx:{fontSize:12}})]})},c))})}),t.jsx(r.TableBody,{children:E.default(Object.values(b),"index").map(({data:c})=>t.jsx(r.TableRow,{children:h.map(({locale:u})=>{var x,S,a,j,f,k,I,m,w,O,B,V,N,q,$,W,K,L,J,H,ae,ue,de,pe,me,xe;return t.jsx(r.TableCell,{children:t.jsx(r.Stack,{gap:1,children:e==="properties"?t.jsxs(t.Fragment,{children:[t.jsx(r.TextField,{size:"small",label:"Key",value:c.key||"",onChange:M=>{v.transact(()=>{c.key=M.target.value.trim()})}}),t.jsx(r.TextField,{size:"small",label:o("label"),value:(((S=(x=c.locales)==null?void 0:x[u])==null?void 0:S.name)??((j=(a=c.locales)==null?void 0:a[d])==null?void 0:j.name))||"",onChange:M=>{v.transact(()=>{var F;c.locales??(c.locales={}),(F=c.locales)[u]??(F[u]={}),c.locales[u].name=M.target.value})}}),t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:X.default((k=(f=c.locales)==null?void 0:f[u])==null?void 0:k.defaultValue),value:((m=(I=c.locales)==null?void 0:I[u])==null?void 0:m.defaultValue)??((O=(w=c.locales)==null?void 0:w[d])==null?void 0:O.defaultValue),onChange:M=>{v.transact(()=>{var F;c.locales??(c.locales={}),(F=c.locales)[u]??(F[u]={}),c.locales[u].defaultValue=M})}})})]}):e==="parameters"&&P?t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,valueImmutable:X.default((q=(N=(V=(B=P.renderer.properties)==null?void 0:B[c.id])==null?void 0:V.locales)==null?void 0:N[u])==null?void 0:q.value),value:((L=(K=(W=($=P.renderer.properties)==null?void 0:$[c.id])==null?void 0:W.locales)==null?void 0:K[u])==null?void 0:L.value)??((ue=(ae=(H=(J=P.renderer.properties)==null?void 0:J[c.id])==null?void 0:H.locales)==null?void 0:ae[d])==null?void 0:ue.value)??((pe=(de=c.locales)==null?void 0:de[u])==null?void 0:pe.defaultValue)??((xe=(me=c.locales)==null?void 0:me[d])==null?void 0:xe.defaultValue),onChange:M=>{v.transact(()=>{var F,fe,je,be,he;(F=P.renderer).properties??(F.properties={}),(fe=P.renderer.properties)[je=c.id]??(fe[je]={}),(be=P.renderer.properties[c.id]).locales??(be.locales={}),(he=P.renderer.properties[c.id].locales)[u]??(he[u]={}),P.renderer.properties[c.id].locales[u].value=M})}})}):null},c.id)},u)})},c.id))})]})})}),t.jsx(r.DialogActions,{children:t.jsx(r.Button,{onClick:c=>{var u;return(u=l.onClose)==null?void 0:u.call(l,c,"escapeKeyDown")},children:o("close")})})]})}const ve=(e,s)=>l=>{const o=[l.palette.info.main,l.palette.primary.main,l.palette.secondary.main,l.palette.success.main,l.palette.warning.main],p=Math.min(o.length-1,e),h=o[p],d=r.alpha(h,.5),g=r.alpha(h,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:g,...s}};function Vt({property:e,onChange:s,defaultLocale:l,allComponents:o}){const{t:p,locale:h}=_.useLocaleContext(),d=C.useRef(null),g=_t(d,e),v=C.useCallback(()=>{if(!(e.type!=="json"&&e.type!=="yaml"&&e.type!=="array")&&e.subProperties)try{let b={};E.default(Object.values(e.subProperties),"index").filter(i=>i.data.visible!==!1&&i.data.key).forEach(({data:i})=>{var c,u,x,S;if(!i.key)return;let n=((u=(c=i.locales)==null?void 0:c[h])==null?void 0:u.defaultValue)??((S=(x=i.locales)==null?void 0:x[l])==null?void 0:S.defaultValue);if(i.type==="number")n=Number(n);else if(i.type==="boolean")n=n===!0||n==="true";else if((i.type==="json"||i.type==="yaml")&&typeof n=="string")try{i.type==="json"?n=JSON.parse(n):n=re.parse(n)}catch(a){console.error("Error parsing nested value",n,a),n={}}b[i.key]=n}),e.type==="array"&&!Array.isArray(b)&&(b=ne.default(b)?[]:[b]);const y=R.transformValue(b,e.type);s==null||s(y)}catch(b){console.error("Error converting structure to text:",b)}},[e,h,l,s]);return e.type!=="json"&&e.type!=="yaml"&&e.type!=="array"?null:t.jsxs(r.Stack,{direction:"column",gap:1.5,sx:{width:"100%"},ref:d,children:[t.jsx(r.Divider,{sx:{mt:-1},children:t.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:p("maker.properties.subProperties")})}),e.subProperties&&Object.keys(e.subProperties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.subProperties,renderItem:(b,P,y)=>{const i=b.visible!==!1;return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:i?"1px solid":"1px dashed","&":ve(g)},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:y,visible:i,config:{properties:e.subProperties},currentLocale:h,defaultLocale:l,allComponents:o,onUpdateConfig:n=>{try{const c={properties:e.subProperties||{}};n(c);const u={...e,subProperties:c.properties};s==null||s(u,{forceUpdateProperty:!0}),v()}catch(c){console.error("Error updating property:",c)}}})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12,height:100},children:p("maker.properties.noSubProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",size:"small",startIcon:t.jsx(D.AddRounded,{}),onClick:()=>{try{const b=e.subProperties||{},P=R.nextId(),i={index:Object.values(b).length,data:{id:P,key:"",type:"string",visible:!0,locales:{[h]:{name:"",defaultValue:""}},subProperties:{}}},n={...e,subProperties:{...b,[P]:i}};s==null||s(n,{forceUpdateProperty:!0}),v()}catch(b){console.error("Error adding property:",b)}},sx:{"&":ve(g,{})},children:p("maker.properties.addSubProperty")})]})}function U({component:e,property:s,value:l,onChange:o,valueImmutable:p,defaultLocale:h,allComponents:d,...g}){var n,c,u,x,S;const{locale:v}=_.useLocaleContext(),b=z.useUploader(),P=C.useRef(null),y=()=>{var j;const a=(j=b==null?void 0:b.current)==null?void 0:j.getUploader();a==null||a.open(),P.current&&a.onceUploadSuccess(({response:f})=>{var I,m;let k=((I=f==null?void 0:f.data)==null?void 0:I.filename)||"";k&&(k=`mediakit://${k}`,l&&!l.includes("mediakit://")&&(k+=" # please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address")),(m=P.current)==null||m.call(P,k)})},i=g.label??(((c=(n=s.locales)==null?void 0:n[v])==null?void 0:c.name)||((x=(u=s.locales)==null?void 0:u[h])==null?void 0:x.name)||s.key||s.id);if(s.type==="number")return t.jsx(zt,{...g,label:i,NumberProps:{value:["number","string"].includes(typeof l)?l:null,onChange:(a,j)=>o==null?void 0:o(j)}});if(s.type==="decimal")return t.jsx(r.TextField,{...g,label:i,type:"text",value:l??"",onChange:a=>{const j=a.target.value;if(j===""||j==="-"){o==null||o(j);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(j)){let k=j;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(k)&&(k=Number(k)),o==null||o(k)}}});if(s.type==="boolean")return t.jsx(r.FormControlLabel,{label:i,labelPlacement:"start",control:t.jsx(r.Switch,{checked:l===!0,onChange:(a,j)=>o==null?void 0:o(j)})});if(s.type==="color")return t.jsx(St,{label:i,value:l,onChange:a=>{o==null||o(a)}});if(s.type==="json"||s.type==="yaml")return t.jsx(Pt,{label:i,value:l,onChange:a=>{o==null||o(a)},property:s,component:e,defaultLocale:h,allComponents:d,PropertyValueField:U,onUpload:a=>{P.current=a,y()}});if(s.type==="custom"){const a=(S=d[s.componentId])==null?void 0:S.data;return a?t.jsx(r.Box,{width:"100%",children:t.jsx(Q.CustomComponentRenderer,{componentId:a.id,props:{label:i,value:l,onChange:o},locale:v,dev:{mode:"draft",components:d,defaultLocale:h}})}):t.jsx(r.TextField,{...g,label:i,disabled:!0,placeholder:"Click right button select a component"})}if(s.type==="component")return t.jsxs(r.Stack,{width:"100%",direction:"column",gap:1,children:[t.jsx(ee,{allComponents:d,label:i,value:l==null?void 0:l.componentId,onChange:(a,j)=>{p||!l?o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:j}):typeof l=="object"&&(l.componentId=j,o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:j}))}}),(l==null?void 0:l.componentId)&&t.jsx(Et,{value:l,valueImmutable:p,onChange:o,defaultLocale:h,allComponents:d})]});if(!s.type||["string","url","multiline"].includes(s.type)){let a=s.type==="string"?s.multiline:void 0;s.type==="multiline"&&(a=!0);const j=s.type==="url"?l==null?void 0:l.url:l;return t.jsx(r.TextField,{...g,label:i,value:typeof j=="string"?j:"",multiline:a,minRows:a?2:void 0,maxRows:a?10:void 0,onChange:f=>o==null?void 0:o(s.type==="url"?{...l,url:f.target.value,mediaKitUrl:f.target.value}:f.target.value),InputProps:s.type==="url"?{sx:{pr:0},endAdornment:t.jsxs(r.InputAdornment,{position:"end",children:[t.jsx(z.UploaderButton,{onChange:async({response:f})=>{var w,O,B;const k=((w=f==null?void 0:f.data)==null?void 0:w.url)||((O=f==null?void 0:f.data)==null?void 0:O.fileUrl);let I;k&&(I=await z.getImageSize(k).catch(()=>z.getVideoSize(k)).catch(()=>{}));let m=((B=f==null?void 0:f.data)==null?void 0:B.filename)||"";m&&(m=`mediakit://${m}`),o==null||o({url:k,mediaKitUrl:m,width:I==null?void 0:I.naturalWidth,height:I==null?void 0:I.naturalHeight})}}),t.jsx(r.Tooltip,{title:"If you are using the 'mediaKitUrl' property, please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address.",children:t.jsx(D.InfoRounded,{sx:{cursor:"default",mr:1},fontSize:"small"})})]})}:void 0})}return s.type==="array"?t.jsx(kt,{label:i,value:Array.isArray(l)?l:[],onChange:a=>o==null?void 0:o(a),property:s,renderItem:({item:a,index:j,onChange:f})=>s.subProperties&&Object.keys(s.subProperties).length>0?t.jsx(r.Stack,{gap:1,width:"100%",children:E.default(Object.values(s.subProperties),"index").filter(k=>k.data.visible!==!1).map(({data:k})=>k.key?t.jsx(U,{component:e,property:k,value:a[k.key],onChange:I=>{const m={...a,[k.key]:I};f(m)},size:"small",fullWidth:!0,defaultLocale:h,allComponents:d},k.id):null)},j):t.jsx(r.TextField,{size:g.size,fullWidth:!0,value:a,onChange:k=>f(k.target.value)})}):(console.error("Unsupported property type",s.type),null)}function zt({NumberProps:e,...s}){const{getInputProps:l}=Se.unstable_useNumberInput(e),o=l();return t.jsx(r.TextField,{...s,inputProps:o})}const Re=`import React from '@blocklet/pages-kit/builtin/react'
|
|
2
2
|
import { Box } from '@blocklet/pages-kit/builtin/mui/material'
|
|
3
3
|
|
|
4
4
|
export default function () {
|
|
@@ -8,4 +8,4 @@ export default function () {
|
|
|
8
8
|
</Box>
|
|
9
9
|
)
|
|
10
10
|
}`,_e=`console.log('hello')
|
|
11
|
-
`;function At({value:e}){const{locale:s}=_.useLocaleContext(),l=ke.useUpdate(),o=Y.getYjsValue(e).doc;return C.useEffect(()=>{var p;(p=e.renderer)!=null&&p.script||(o.transact(()=>{e.renderer.script=e.renderer.type==="react-component"?Re:_e}),l())},[e]),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:t.jsx(ie.CodeEditor,{keyId:e.id,locale:s,language:"typescript",value:e.renderer.script||"",onChange:p=>e.renderer.script=p,typeScriptNoValidation:!1,fullScreenOptions:{enableEscExit:!0}},e.id)})}function Nt({value:e}){var P,y,i;const{t:s}=_.useLocaleContext(),l=Y.getYjsValue(e).doc,{state:{components:o,config:{defaultLocale:p},resources:h},localState:{currentLocale:d}}=R.useStore(),g=R.useAllComponents(),v=((P=o[e.renderer.componentId])==null?void 0:P.data)??((i=(y=h.components)==null?void 0:y[e.renderer.componentId])==null?void 0:i.component),b=
|
|
11
|
+
`;function At({value:e}){const{locale:s}=_.useLocaleContext(),l=ke.useUpdate(),o=Y.getYjsValue(e).doc;return C.useEffect(()=>{var p;(p=e.renderer)!=null&&p.script||(o.transact(()=>{e.renderer.script=e.renderer.type==="react-component"?Re:_e}),l())},[e]),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:t.jsx(ie.CodeEditor,{keyId:e.id,locale:s,language:"typescript",value:e.renderer.script||"",onChange:p=>e.renderer.script=p,typeScriptNoValidation:!1,fullScreenOptions:{enableEscExit:!0}},e.id)})}function Nt({value:e}){var P,y,i;const{t:s}=_.useLocaleContext(),l=Y.getYjsValue(e).doc,{state:{components:o,config:{defaultLocale:p},resources:h},localState:{currentLocale:d}}=R.useStore(),g=R.useAllComponents(),v=((P=o[e.renderer.componentId])==null?void 0:P.data)??((i=(y=h.components)==null?void 0:y[e.renderer.componentId])==null?void 0:i.component),b=A.usePopupState({variant:"dialog"});return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:1,children:[t.jsx(ee,{allComponents:g,excludes:[e.id],value:e.renderer.componentId,onChange:(n,c)=>e.renderer.componentId=c}),v&&t.jsxs(t.Fragment,{children:[t.jsxs(r.Stack,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[t.jsx(r.Typography,{variant:"subtitle2",children:s("parameters")}),t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...A.bindTrigger(b),children:t.jsx(D.TranslateRounded,{fontSize:"small"})})]}),v.properties&&E.default(Object.values(v.properties),"index").map(({data:n})=>{var c,u,x,S,a,j,f,k,I,m,w,O,B,V,N,q;return t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:p,component:v,property:n,fullWidth:!0,size:"small",valueImmutable:X.default((S=(x=(u=(c=e.renderer.properties)==null?void 0:c[n.id])==null?void 0:u.locales)==null?void 0:x[d])==null?void 0:S.value),value:((k=(f=(j=(a=e.renderer.properties)==null?void 0:a[n.id])==null?void 0:j.locales)==null?void 0:f[d])==null?void 0:k.value)??((O=(w=(m=(I=e.renderer.properties)==null?void 0:I[n.id])==null?void 0:m.locales)==null?void 0:w[p])==null?void 0:O.value)??((V=(B=n.locales)==null?void 0:B[d])==null?void 0:V.defaultValue)??((q=(N=n.locales)==null?void 0:N[p])==null?void 0:q.defaultValue),onChange:$=>{l.transact(()=>{var W,K,L,J,H;(W=e.renderer).properties??(W.properties={}),(K=e.renderer.properties)[L=n.id]??(K[L]={}),(J=e.renderer.properties[n.id]).locales??(J.locales={}),(H=e.renderer.properties[n.id].locales)[d]??(H[d]={}),e.renderer.properties[n.id].locales[d].value=$})}})},n.id)}),t.jsx(Be,{...A.bindDialog(b),component:e,type:"parameters"})]})]})})}function ee({label:e,options:s,excludes:l,value:o,onChange:p,allComponents:h,...d}){var P;const{t:g}=_.useLocaleContext(),v=s??E.default(Object.values(jt.default(h,...l??[])),"index").map(y=>y.data),b=(typeof o=="string"?(P=h[o])==null?void 0:P.data:void 0)??null;return t.jsx(r.Autocomplete,{...d,size:"small",options:v,autoHighlight:!0,isOptionEqualToValue:(y,i)=>y.id===i.id,getOptionKey:y=>y.id,getOptionLabel:y=>y.name||y.id,renderInput:y=>t.jsx(r.TextField,{label:e||g("component"),...y}),value:b,onChange:(y,i)=>{var c,u,x,S,a,j;let n={};i&&(n={blockletId:(c=h[i==null?void 0:i.id])==null?void 0:c.blockletId,blockletTitle:(u=h[i==null?void 0:i.id])==null?void 0:u.blockletTitle,componentName:((S=(x=h[i==null?void 0:i.id])==null?void 0:x.data)==null?void 0:S.name)||((j=(a=h[i==null?void 0:i.id])==null?void 0:a.data)==null?void 0:j.id)}),p==null||p(y,i==null?void 0:i.id,n)}})}function ce({config:e,allComponents:s,defaultLocale:l,propertiesValue:o,currentLocale:p,onChange:h,props:d}){const{t:g}=_.useLocaleContext(),[v,b]=C.useState(e==null?void 0:e.properties),[P,y]=C.useState(null);C.useEffect(()=>{(()=>{var S,a;((S=e==null?void 0:e.renderer)==null?void 0:S.type)==="react-component"&&ne.default(e==null?void 0:e.properties)?Q.transpileAndLoadScript((a=e==null?void 0:e.renderer)==null?void 0:a.script).then(j=>{const f=Q.getPropertiesFromCode(j);b(f)}):b(e==null?void 0:e.properties)})()},[JSON.stringify(e)]);const i=C.useCallback(()=>!e||!v?{}:Object.values(v).reduce((x,{data:S})=>{var j,f,k,I,m;const a=S.key||S.id;return x[S.id]={key:a,value:(d==null?void 0:d[a])??((j=o==null?void 0:o[S.id])==null?void 0:j.value)??((k=(f=S.locales)==null?void 0:f[p])==null?void 0:k.defaultValue)??((m=(I=S.locales)==null?void 0:I[l])==null?void 0:m.defaultValue),id:S.id,type:S.type},x},{}),[JSON.stringify(v),e,o,p,l]),n=C.useMemo(()=>{if(!v)return{canUseProperties:[],visibleProperties:[],canUsePropertiesKeys:[]};const x=E.default(Object.values(v),"index"),S=x.filter(({data:f})=>f.key&&oe(v,f.id)),a=x.filter(({data:f})=>f.key&&f.type!=="component"),j=a.map(({data:f})=>f.key);return{canUseProperties:a,visibleProperties:S,canUsePropertiesKeys:j}},[JSON.stringify(v)]),c=i(),u=ft.default(c,"key");return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(r.Typography,{variant:"subtitle1",children:g("maker.properties.parameters")}),!e||n.canUsePropertiesKeys.length===0?t.jsx(Z.default,{style:{fontSize:12},children:g("maker.properties.noParameters")}):t.jsxs(t.Fragment,{children:[t.jsx(r.Stack,{gap:2,children:n.visibleProperties.map(({data:x})=>{var S,a;return t.jsx(r.Box,{children:t.jsx(U,{allComponents:s,defaultLocale:l,size:"small",fullWidth:!0,component:e,property:x,valueImmutable:X.default((S=o==null?void 0:o[x.id])==null?void 0:S.value),value:(d==null?void 0:d[x.key||x.id])??((a=c[x.id])==null?void 0:a.value),onChange:j=>{h({path:["properties",x.id],id:x.id,value:{value:j},shouldSync:ge(x),excludeKeys:[],key:x.key||x.id})}})},x.id)})}),t.jsx(r.Stack,{gap:2,sx:{width:"100%"},children:t.jsx(Q.CustomComponentRenderer,{componentId:(e==null?void 0:e.id)||"",renderType:"setting",locale:p,properties:c,dev:{mode:"draft",components:s,defaultLocale:l},props:{...bt.default(d??{},n.canUsePropertiesKeys),onChange:x=>{const{canUsePropertiesKeys:S}=n;Object.keys(x).filter(j=>{var f;return!mt.default(x[j],(f=u==null?void 0:u[j])==null?void 0:f.value)}).filter(j=>{var f,k,I,m;return!(j==="locale"&&!pt.default(u[j],"locale")||((f=u[j])==null?void 0:f.type)==="component"||(((k=u[j])==null?void 0:k.type)==="yaml"||((I=u[j])==null?void 0:I.type)==="json")&&oe(v,(m=u[j])==null?void 0:m.id))}).reduce((j,f)=>j.then(()=>{const k=u[f],I=S.includes(f);if(k!=null&&k.id&&I)return h({path:["properties",k.id],id:k.id,value:{value:x[f]},shouldSync:ge(k),excludeKeys:[],key:k.key||k.id}),Promise.resolve();const m=`propertyNotFound${f}`;if(P===m)return Promise.resolve();se.default.close(P);const w=se.default.warning(g("maker.properties.propertyNotFound",{key:f}),{key:m});return y(w),Promise.resolve()}),Promise.resolve())}}})})]})]})})}exports.BasicInfo=Ce;exports.CustomComponentAutocomplete=ee;exports.CustomComponentSettings=Bt;exports.DefaultReactComponentScriptTemplate=Re;exports.DefaultWebComponentScriptTemplate=_e;exports.ParametersConfig=ce;exports.PropertiesConfig=Te;exports.PropertyValueField=U;
|
package/lib/es/add-component.js
CHANGED
|
@@ -270,10 +270,10 @@ function pI({
|
|
|
270
270
|
...w
|
|
271
271
|
}) {
|
|
272
272
|
const {
|
|
273
|
-
state: {
|
|
274
|
-
} = oI(), g = E(() => o.map((L) => A[L].
|
|
273
|
+
state: { routes: A, routeIds: o }
|
|
274
|
+
} = oI(), g = E(() => o.map((L) => A[L].path), [A, o]), [s] = c(() => {
|
|
275
275
|
var L;
|
|
276
|
-
return ((L = A[C]) == null ? void 0 : L.
|
|
276
|
+
return ((L = A[C]) == null ? void 0 : L.path) || C;
|
|
277
277
|
});
|
|
278
278
|
return /* @__PURE__ */ I(
|
|
279
279
|
tI,
|
|
@@ -287,7 +287,7 @@ function pI({
|
|
|
287
287
|
openOnFocus: !0,
|
|
288
288
|
onChange: (L, J) => {
|
|
289
289
|
var M;
|
|
290
|
-
return i(((M = Object.values(A).find((y) => (y == null ? void 0 : y.
|
|
290
|
+
return i(((M = Object.values(A).find((y) => (y == null ? void 0 : y.path) === J)) == null ? void 0 : M.id) || J || "");
|
|
291
291
|
},
|
|
292
292
|
renderInput: (L) => /* @__PURE__ */ I(h, { ...L, ...w })
|
|
293
293
|
}
|