@blocklet/pages-kit-inner-components 0.4.82 → 0.4.83
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/setting.js +4 -4
- package/lib/es/setting.js +546 -524
- package/package.json +3 -3
package/lib/cjs/setting.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Ve=Object.create;var ye=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ne=Object.getPrototypeOf,Ee=Object.prototype.hasOwnProperty;var Ue=(t,s,l,o)=>{if(s&&typeof s=="object"||typeof s=="function")for(let d of qe(s))!Ee.call(t,d)&&d!==l&&ye(t,d,{get:()=>s[d],enumerable:!(o=Fe(s,d))||o.enumerable});return t};var We=(t,s,l)=>(l=t!=null?Ve(Ne(t)):{},Ue(s||!t||!t.__esModule?ye(l,"default",{value:t,enumerable:!0}):l,t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),T=require("./_chunks/state-BjeG4kYg.js"),Ke=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),ne=require("@blocklet/code-editor"),Me=require("@mui/icons-material/AddRounded"),Le=require("@mui/icons-material/ArrowDownward"),He=require("@mui/icons-material/ArrowUpward"),Je=require("@mui/icons-material/DeleteOutline"),r=require("@mui/material"),Ye=require("lodash/sortBy"),I=require("react"),ie=require("react-use"),$e=require("@arcblock/ux/lib/Theme"),Ge=require("@emotion/css"),re=require("ahooks"),Qe=require("gradient-parser");require("lodash/without");const Xe=require("tinycolor2"),D=require("@mui/material/colors"),A=require("./uploader.js"),Ze=require("@iconify-icon/react"),et=require("lodash/isEmpty"),tt=require("lodash/set"),rt=require("yaml"),st=require("lodash"),ot=require("@arcblock/ux/lib/Toast"),Z=require("@blocklet/pages-kit/components"),Pe=require("@mui/base"),z=require("@mui/icons-material"),ge=require("@mui/material/styles"),M=require("@syncedstore/core"),lt=require("lodash/assign"),nt=require("lodash/has"),it=require("lodash/isNil"),ct=require("lodash/isObject"),at=require("lodash/keyBy"),ut=require("lodash/omit"),dt=require("lodash/pick"),pt=require("lodash/reduce"),q=require("material-ui-popup-state/hooks"),xt=require("react-error-boundary"),se=require("react-dnd"),R=t=>t&&t.__esModule?t:{default:t};function mt(t){if(t&&t.__esModule)return t;const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const l in t)if(l!=="default"){const o=Object.getOwnPropertyDescriptor(t,l);Object.defineProperty(s,l,o.get?o:{enumerable:!0,get:()=>t[l]})}}return s.default=t,Object.freeze(s)}const G=R(Ke),ft=R(Me),ht=R(Le),jt=R(He),bt=R(Je),V=R(Ye),ve=R(Qe),yt=R(Xe),Ie=R(et),Ce=R(tt),oe=mt(rt),ke=R(ot),gt=R(lt),vt=R(nt),ee=R(it),kt=R(ct),St=R(at),wt=R(ut),Pt=R(dt),It=R(pt);function Ct({onClick:t,disabled:s,sx:l,...o}){return e.jsx(r.IconButton,{size:"small",color:"warning",variant:"outlined",disabled:s,onClick:t,...o,children:e.jsx(bt.default,{fontSize:"small"})})}function Bt({onClick:t,disabled:s,sx:l,...o}){return e.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:t,...o,children:e.jsx(jt.default,{fontSize:"small"})})}function Tt({onClick:t,disabled:s,sx:l,...o}){return e.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:t,...o,children:e.jsx(ht.default,{fontSize:"small"})})}function Ot({label:t,value:s,onChange:l,disabled:o=!1,itemLabel:d="",emptyHeight:m=40,property:a,renderItem:x,...k}){const{t:b,locale:g}=_.useLocaleContext(),f=ie.useUpdate(),n=I.useCallback(y=>{l(T.transformValue(y,a.type))},[l,a.type]),c=I.useMemo(()=>Array.isArray(s)?s:[],[s]),i=I.useCallback(()=>{const y=[...c,""];n(y),f()},[c,n,f]),p=I.useCallback(()=>{if(!a||!a.subProperties)return i();const y={};V.default(Object.values(a.subProperties),"index").forEach(({data:O})=>{var N,E;if(!O.key)return;const F=((E=(N=O.locales)==null?void 0:N[g])==null?void 0:E.defaultValue)??"";y[O.key]=F});const B=[...c,y];n(B),f()},[c,n,f,a,g,i]),h=I.useCallback(y=>{try{const P=JSON.parse(y);Array.isArray(P)?n(P):console.error("JSON解析结果不是数组")}catch(P){console.error("JSON解析错误:",P)}},[n]),S=I.useCallback(y=>{const P=c.filter((B,O)=>O!==y);n(P),f()},[c,n,f]),u=I.useCallback(y=>{if(y<=0)return;const P=[...c],B=P[y];P[y]=P[y-1],P[y-1]=B,n(P),f()},[c,n,f]),v=I.useCallback(y=>{if(y>=c.length-1)return;const P=[...c],B=P[y];P[y]=P[y+1],P[y+1]=B,n(P),f()},[c,n,f]),j=I.useCallback((y,P)=>{const B=[...c];B[y]=P,n(B)},[c,n]),w=a&&a.subProperties&&Object.keys(a.subProperties).length>0,C=I.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:y})=>e.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:y+1})},{field:"content",headerName:"",renderCell:({row:y,index:P})=>x&&w?x({item:y,index:P,property:a,onChange:B=>j(P,B)}):e.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:o,value:y,placeholder:d||`${b("item")} ${P+1}`,onChange:B=>j(P,B.target.value),...k})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:y})=>e.jsxs(r.Stack,{direction:"column",spacing:.25,children:[e.jsx(Bt,{disabled:o||y===0,onClick:()=>u(y)}),e.jsx(Tt,{disabled:o||y===c.length-1,onClick:()=>v(y)}),e.jsx(Ct,{disabled:o,onClick:()=>S(y)})]})}],[x,w,a,j,d,b,o,k,S,u,v,c.length]);return w?e.jsxs(r.Stack,{width:"100%",gap:1,children:[t&&e.jsx(r.FormLabel,{children:t}),c.length>0?e.jsx(r.TableContainer,{component:r.Paper,variant:"outlined",sx:{borderRadius:1,mb:1},children:e.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:[e.jsx(r.TableHead,{sx:{display:"none"},children:e.jsx(r.TableRow,{children:C.map(y=>e.jsx(r.TableCell,{width:y.width,align:y.align||"left",sx:{fontWeight:"bold"},children:y.renderHeader?y.renderHeader():y.headerName},y.field))})}),e.jsx(r.TableBody,{children:c.map((y,P,B)=>e.jsx(r.TableRow,{sx:{borderBottom:P<B.length-1?"1px solid":"none",borderColor:"divider","&:hover":{backgroundColor:"action.hover"}},children:C.map(O=>e.jsx(r.TableCell,{width:O.width,align:O.align||"left",sx:{borderBottom:"none"},children:O.renderCell({row:y,index:P,onChange:F=>j(P,F)})},`${P}-${O.field}`))},P))})]})}):e.jsx(G.default,{style:{fontSize:12,height:m},children:b("maker.properties.arrayEmpty")}),e.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:o,startIcon:e.jsx(ft.default,{}),onClick:p,children:b("maker.properties.addArrayItem")})]}):e.jsxs(r.Stack,{width:"100%",gap:1,children:[t&&e.jsx(r.FormLabel,{children:t}),e.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,minHeight:150},children:e.jsx(ne.CodeEditor,{keyId:a.id,locale:g,language:"json",value:JSON.stringify(c,null,2),onChange:y=>h(y||"")},a.id)})]})}D.red[300],D.pink[300],D.purple[300],D.indigo[300],D.blue[300],D.cyan[300],D.teal[300],D.green[300],D.lime[300],D.yellow[300],D.amber[300],D.orange[300],D.brown[300],D.grey[300],D.blueGrey[300];const Rt=I.forwardRef(function({showMarkdown:s,markdown:l,onMarkdownChange:o,showUploader:d,value:m,meta:a,onChange:x,...k},b){const[g,f]=I.useState("");I.useEffect(()=>{f(m||"")},[m,f]);const n=async()=>{if(g!==m){const i=T.getImageAbsoluteUrl(g);if(!i){x(g,void 0);return}const p=await A.getImageSize(i).catch(()=>A.getVideoSize(i)).catch(()=>{});x(g,{...p,filename:g})}};ie.useDebounce(()=>{g!==m&&x(g)},300,[g]),I.useImperativeHandle(b,()=>({submit:n}));const c={};return d&&(c.InputProps={sx:{pr:0},endAdornment:e.jsx(r.InputAdornment,{position:"end",sx:{mx:.5},children:e.jsx(A.UploaderButton,{onChange:async({response:i})=>{var u;const p=(u=i==null?void 0:i.data)==null?void 0:u.filename,h=T.getImageAbsoluteUrl(p)||"";let S={};h&&(S=await A.getImageSize(h).catch(()=>A.getVideoSize(h)).catch(()=>{})),x(p,{...S,filename:p})}})})}),e.jsx(r.TextField,{size:"small",fullWidth:!0,...k,label:e.jsxs(r.Stack,{direction:"row",spacing:1,alignItems:"center",children:[k.label,s&&e.jsxs(e.Fragment,{children:[" (",e.jsx(r.FormControlLabel,{checked:l,label:e.jsx(r.Box,{component:Ze.Icon,icon:"tabler:markdown",sx:{verticalAlign:"middle"}}),labelPlacement:"start",control:e.jsx(r.Switch,{size:"small"}),sx:{ml:.25,pr:1},onChange:(i,p)=>o==null?void 0:o(p)}),")"]})]}),InputLabelProps:{shrink:!0,...k.InputLabelProps},value:g,onChange:i=>f(i.target.value),...c,onKeyDown:i=>{i.keyCode!==229&&i.key==="Enter"&&n()}})}),_t=I.lazy(()=>import("react-best-gradient-color-picker"));function Dt(t){try{const l=ve.default.parse(t).map(d=>{const m=d.colorStops.map(a=>{if(a.type!=="rgba"){const x=yt.default(a.value).toRgb();return{...a,value:[x.r,x.g,x.b,x.a],type:"rgba"}}return a});return{...d,colorStops:m}});return ve.default.stringify(l)}catch{return T.isColorString(t)?t:""}}function At({color:t,sx:s={},...l}){T.isColorString(t);const o={};return T.isGradient(t)?o.backgroundImage=t:o.backgroundColor=t,e.jsx(r.Box,{sx:{...s,width:"100%",paddingBottom:"100%",cursor:"pointer",transition:"opacity 0.2s",border:"1px solid #ccc",borderRadius:.5,"&:hover":{opacity:.75},...o},...l})}const zt=I.forwardRef(function({onSave:s},l){const o=re.useReactive({value:""}),{t:d}=_.useLocaleContext(),m={};o.value?T.isGradient(o.value)?m.backgroundImage=o.value:m.backgroundColor=o.value:m.border="1px solid #ccc";const[a,{setFalse:x,setTrue:k}]=re.useBoolean(!1),b=I.useCallback(()=>{x()},[x]),g=()=>{s({value:o.value},b)};return I.useImperativeHandle(l,()=>({open({value:f}={value:""}){o.value=f,k()},close(){b()}})),e.jsxs(r.Dialog,{open:a,onClose:b,hideBackdrop:!0,children:[e.jsx(r.DialogTitle,{children:d("maker.configBackground")}),e.jsx(r.DialogContent,{sx:{width:600},children:e.jsxs(r.Box,{width:"100%",display:"flex",children:[e.jsx(r.Box,{flex:1,mr:1,sx:m,children:!o.value&&e.jsx(G.default,{children:d("error.notConfig")})}),e.jsx(I.Suspense,{children:e.jsx(_t,{width:200,height:200,value:Dt(o.value),onChange:f=>{o.value=f},hidePresets:!0,hideAdvancedSliders:!0,hideColorGuide:!0,hideInputType:!0})})]})}),e.jsxs(r.DialogActions,{children:[e.jsx(r.Button,{variant:"outlined",size:"small",onClick:b,children:d("common.cancel")}),e.jsx(r.Button,{variant:"contained",size:"small",onClick:g,children:d("maker.save")})]})]})});$e.styled(r.Box)`
|
|
1
|
+
"use strict";var Ve=Object.create;var ye=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ne=Object.getPrototypeOf,Ee=Object.prototype.hasOwnProperty;var Ue=(e,s,o,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let d of Fe(s))!Ee.call(e,d)&&d!==o&&ye(e,d,{get:()=>s[d],enumerable:!(n=qe(s,d))||n.enumerable});return e};var We=(e,s,o)=>(o=e!=null?Ve(Ne(e)):{},Ue(s||!e||!e.__esModule?ye(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),T=require("./_chunks/state-BjeG4kYg.js"),Ke=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),le=require("@blocklet/code-editor"),Me=require("@mui/icons-material/AddRounded"),Le=require("@mui/icons-material/ArrowDownward"),He=require("@mui/icons-material/ArrowUpward"),Je=require("@mui/icons-material/DeleteOutline"),r=require("@mui/material"),Ye=require("lodash/sortBy"),I=require("react"),ie=require("react-use"),$e=require("@arcblock/ux/lib/Theme"),Ge=require("@emotion/css"),re=require("ahooks"),Qe=require("gradient-parser");require("lodash/without");const Xe=require("tinycolor2"),D=require("@mui/material/colors"),z=require("./uploader.js"),Ze=require("@iconify-icon/react"),et=require("lodash/isEmpty"),tt=require("lodash/set"),rt=require("yaml"),st=require("lodash"),ot=require("@arcblock/ux/lib/Toast"),Z=require("@blocklet/pages-kit/components"),Pe=require("@mui/base"),A=require("@mui/icons-material"),ge=require("@mui/material/styles"),M=require("@syncedstore/core"),nt=require("lodash/assign"),lt=require("lodash/has"),it=require("lodash/isNil"),ct=require("lodash/isObject"),at=require("lodash/keyBy"),ut=require("lodash/omit"),dt=require("lodash/pick"),pt=require("lodash/reduce"),F=require("material-ui-popup-state/hooks"),xt=require("react-error-boundary"),se=require("react-dnd"),R=e=>e&&e.__esModule?e:{default:e};function mt(e){if(e&&e.__esModule)return e;const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(s,o,n.get?n:{enumerable:!0,get:()=>e[o]})}}return s.default=e,Object.freeze(s)}const G=R(Ke),ft=R(Me),ht=R(Le),bt=R(He),jt=R(Je),V=R(Ye),ve=R(Qe),yt=R(Xe),Ie=R(et),Ce=R(tt),oe=mt(rt),ke=R(ot),gt=R(nt),vt=R(lt),ee=R(it),kt=R(ct),St=R(at),wt=R(ut),Pt=R(dt),It=R(pt);function Ct({onClick:e,disabled:s,sx:o,...n}){return t.jsx(r.IconButton,{size:"small",color:"warning",variant:"outlined",disabled:s,onClick:e,...n,children:t.jsx(jt.default,{fontSize:"small"})})}function Bt({onClick:e,disabled:s,sx:o,...n}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...n,children:t.jsx(bt.default,{fontSize:"small"})})}function Tt({onClick:e,disabled:s,sx:o,...n}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...n,children:t.jsx(ht.default,{fontSize:"small"})})}function Ot({label:e,value:s,onChange:o,disabled:n=!1,itemLabel:d="",emptyHeight:x=40,property:u,renderItem:m,...k}){const{t:j,locale:g}=_.useLocaleContext(),f=ie.useUpdate(),l=I.useCallback(y=>{o(T.transformValue(y,u.type))},[o,u.type]),c=I.useMemo(()=>Array.isArray(s)?s:[],[s]),i=I.useCallback(()=>{const y=[...c,""];l(y),f()},[c,l,f]),p=I.useCallback(()=>{if(!u||!u.subProperties)return i();const y={};V.default(Object.values(u.subProperties),"index").forEach(({data:O})=>{var N,E;if(!O.key)return;const q=((E=(N=O.locales)==null?void 0:N[g])==null?void 0:E.defaultValue)??"";y[O.key]=q});const B=[...c,y];l(B),f()},[c,l,f,u,g,i]),h=I.useCallback(y=>{try{const P=JSON.parse(y);Array.isArray(P)?l(P):console.error("JSON解析结果不是数组")}catch(P){console.error("JSON解析错误:",P)}},[l]),S=I.useCallback(y=>{const P=c.filter((B,O)=>O!==y);l(P),f()},[c,l,f]),a=I.useCallback(y=>{if(y<=0)return;const P=[...c],B=P[y];P[y]=P[y-1],P[y-1]=B,l(P),f()},[c,l,f]),v=I.useCallback(y=>{if(y>=c.length-1)return;const P=[...c],B=P[y];P[y]=P[y+1],P[y+1]=B,l(P),f()},[c,l,f]),b=I.useCallback((y,P)=>{const B=[...c];B[y]=P,l(B)},[c,l]),w=u&&u.subProperties&&Object.keys(u.subProperties).length>0,C=I.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:y})=>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:y+1})},{field:"content",headerName:"",renderCell:({row:y,index:P})=>m&&w?m({item:y,index:P,property:u,onChange:B=>b(P,B)}):t.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:n,value:y,placeholder:d||`${j("item")} ${P+1}`,onChange:B=>b(P,B.target.value),...k})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:y})=>t.jsxs(r.Stack,{direction:"column",spacing:.25,children:[t.jsx(Bt,{disabled:n||y===0,onClick:()=>a(y)}),t.jsx(Tt,{disabled:n||y===c.length-1,onClick:()=>v(y)}),t.jsx(Ct,{disabled:n,onClick:()=>S(y)})]})}],[m,w,u,b,d,j,n,k,S,a,v,c.length]);return w?t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),c.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:C.map(y=>t.jsx(r.TableCell,{width:y.width,align:y.align||"left",sx:{fontWeight:"bold"},children:y.renderHeader?y.renderHeader():y.headerName},y.field))})}),t.jsx(r.TableBody,{children:c.map((y,P,B)=>t.jsx(r.TableRow,{sx:{borderBottom:P<B.length-1?"1px solid":"none",borderColor:"divider","&:hover":{backgroundColor:"action.hover"}},children:C.map(O=>t.jsx(r.TableCell,{width:O.width,align:O.align||"left",sx:{borderBottom:"none"},children:O.renderCell({row:y,index:P,onChange:q=>b(P,q)})},`${P}-${O.field}`))},P))})]})}):t.jsx(G.default,{style:{fontSize:12,height:x},children:j("maker.properties.arrayEmpty")}),t.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:n,startIcon:t.jsx(ft.default,{}),onClick:p,children:j("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(le.CodeEditor,{keyId:u.id,locale:g,language:"json",value:JSON.stringify(c,null,2),onChange:y=>h(y||"")},u.id)})]})}D.red[300],D.pink[300],D.purple[300],D.indigo[300],D.blue[300],D.cyan[300],D.teal[300],D.green[300],D.lime[300],D.yellow[300],D.amber[300],D.orange[300],D.brown[300],D.grey[300],D.blueGrey[300];const Rt=I.forwardRef(function({showMarkdown:s,markdown:o,onMarkdownChange:n,showUploader:d,value:x,meta:u,onChange:m,...k},j){const[g,f]=I.useState("");I.useEffect(()=>{f(x||"")},[x,f]);const l=async()=>{if(g!==x){const i=T.getImageAbsoluteUrl(g);if(!i){m(g,void 0);return}const p=await z.getImageSize(i).catch(()=>z.getVideoSize(i)).catch(()=>{});m(g,{...p,filename:g})}};ie.useDebounce(()=>{g!==x&&m(g)},300,[g]),I.useImperativeHandle(j,()=>({submit:l}));const c={};return d&&(c.InputProps={sx:{pr:0},endAdornment:t.jsx(r.InputAdornment,{position:"end",sx:{mx:.5},children:t.jsx(z.UploaderButton,{onChange:async({response:i})=>{var a;const p=(a=i==null?void 0:i.data)==null?void 0:a.filename,h=T.getImageAbsoluteUrl(p)||"";let S={};h&&(S=await z.getImageSize(h).catch(()=>z.getVideoSize(h)).catch(()=>{})),m(p,{...S,filename:p})}})})}),t.jsx(r.TextField,{size:"small",fullWidth:!0,...k,label:t.jsxs(r.Stack,{direction:"row",spacing:1,alignItems:"center",children:[k.label,s&&t.jsxs(t.Fragment,{children:[" (",t.jsx(r.FormControlLabel,{checked:o,label:t.jsx(r.Box,{component:Ze.Icon,icon:"tabler:markdown",sx:{verticalAlign:"middle"}}),labelPlacement:"start",control:t.jsx(r.Switch,{size:"small"}),sx:{ml:.25,pr:1},onChange:(i,p)=>n==null?void 0:n(p)}),")"]})]}),InputLabelProps:{shrink:!0,...k.InputLabelProps},value:g,onChange:i=>f(i.target.value),...c,onKeyDown:i=>{i.keyCode!==229&&i.key==="Enter"&&l()}})}),_t=I.lazy(()=>import("react-best-gradient-color-picker"));function Dt(e){try{const o=ve.default.parse(e).map(d=>{const x=d.colorStops.map(u=>{if(u.type!=="rgba"){const m=yt.default(u.value).toRgb();return{...u,value:[m.r,m.g,m.b,m.a],type:"rgba"}}return u});return{...d,colorStops:x}});return ve.default.stringify(o)}catch{return T.isColorString(e)?e:""}}function zt({color:e,sx:s={},...o}){T.isColorString(e);const n={};return T.isGradient(e)?n.backgroundImage=e:n.backgroundColor=e,t.jsx(r.Box,{sx:{...s,width:"100%",paddingBottom:"100%",cursor:"pointer",transition:"opacity 0.2s",border:"1px solid #ccc",borderRadius:.5,"&:hover":{opacity:.75},...n},...o})}const At=I.forwardRef(function({onSave:s},o){const n=re.useReactive({value:""}),{t:d}=_.useLocaleContext(),x={};n.value?T.isGradient(n.value)?x.backgroundImage=n.value:x.backgroundColor=n.value:x.border="1px solid #ccc";const[u,{setFalse:m,setTrue:k}]=re.useBoolean(!1),j=I.useCallback(()=>{m()},[m]),g=()=>{s({value:n.value},j)};return I.useImperativeHandle(o,()=>({open({value:f}={value:""}){n.value=f,k()},close(){j()}})),t.jsxs(r.Dialog,{open:u,onClose:j,hideBackdrop:!0,children:[t.jsx(r.DialogTitle,{children:d("maker.configBackground")}),t.jsx(r.DialogContent,{sx:{width:600},children:t.jsxs(r.Box,{width:"100%",display:"flex",children:[t.jsx(r.Box,{flex:1,mr:1,sx:x,children:!n.value&&t.jsx(G.default,{children:d("error.notConfig")})}),t.jsx(I.Suspense,{children:t.jsx(_t,{width:200,height:200,value:Dt(n.value),onChange:f=>{n.value=f},hidePresets:!0,hideAdvancedSliders:!0,hideColorGuide:!0,hideInputType:!0})})]})}),t.jsxs(r.DialogActions,{children:[t.jsx(r.Button,{variant:"outlined",size:"small",onClick:j,children:d("common.cancel")}),t.jsx(r.Button,{variant:"contained",size:"small",onClick:g,children:d("maker.save")})]})]})});$e.styled(r.Box)`
|
|
2
2
|
.color-item {
|
|
3
3
|
position: relative;
|
|
4
4
|
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
top: 0;
|
|
19
19
|
right: 0;
|
|
20
20
|
}
|
|
21
|
-
`;function Vt({value:t,onChange:s,...l}){const o=I.useRef(null);return e.jsxs(e.Fragment,{children:[e.jsx(Rt,{...l,value:t,onChange:s,InputProps:{endAdornment:e.jsx(r.InputAdornment,{position:"end",children:e.jsx(At,{color:t??"",style:{width:"1.5rem",height:"1.5rem",padding:0},onClick:()=>{var d;(d=o.current)==null||d.open({value:t??""})}})})}}),e.jsx(zt,{ref:o,onSave:({value:d},m)=>{s(d),m()}})]})}function Ft({label:t,value:s,onChange:l,property:o,component:d,defaultLocale:m,allComponents:a,PropertyValueField:x,onUpload:k}){const{locale:b}=_.useLocaleContext(),g=I.useRef(null);if(!Ie.default(o.subProperties)){const n=V.default(Object.values(o.subProperties||{}),"index").filter(c=>c.data.visible!==!1&&c.data.key);return e.jsxs(r.Stack,{width:"100%",children:[e.jsx(r.FormLabel,{sx:{px:.25,py:.5},children:t}),e.jsx(r.Box,{children:e.jsx(r.Box,{sx:{position:"relative"},children:n.map((c,i)=>{const{data:p}=c,h=p.key??p.id,S=i===n.length-1;let u=null;try{s&&typeof s=="object"?u=s[h]:typeof s=="string"&&(u=(o.type==="yaml"?oe.parse(s||""):JSON.parse(s||"{}"))[h])}catch{}u==null&&(p.locales&&b&&p.locales[b]?u=p.locales[b].defaultValue:p.locales&&m&&p.locales[m]&&(u=p.locales[m].defaultValue));const v=w=>{try{let C={};if(typeof s=="string")try{C=o.type==="yaml"?oe.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(C={...s});Ce.default(C,h,w);const y=T.transformValue(C,o.type);l==null||l(y)}catch(C){console.error("Error updating property:",C)}},j=8;return e.jsxs(r.Box,{sx:{mb:S?0:1,display:"flex",flexDirection:"row"},children:[e.jsxs(r.Box,{sx:{position:"relative",width:24,flexShrink:0},children:[e.jsx(r.Box,{sx:{position:"absolute",left:j,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),e.jsx(r.Box,{sx:{position:"absolute",left:j,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!S&&e.jsx(r.Box,{sx:{position:"absolute",left:j,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),e.jsx(r.Box,{sx:{flexGrow:1},children:e.jsx(x,{component:d,property:p,value:u,onChange:v,size:"small",fullWidth:!0,defaultLocale:m,allComponents:a})})]},p.id)})})})]})}return e.jsx(r.Stack,{width:"100%",gap:2,children:e.jsxs(r.Stack,{sx:{width:"100%",position:"relative",pt:1,pb:"6px",px:"1px",minHeight:50,".monaco-editor,.overflow-guard":{borderRadius:1}},children:[e.jsx(r.FormLabel,{sx:{position:"absolute",left:0,top:0,transform:"translate(0px, -7px) scale(0.75)"},children:t}),e.jsx(ne.CodeEditor,{keyId:o.id,locale:b,language:o.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:n=>{l==null||l(n)},onUpload:n=>{g.current=n,k&&k(n)}},o.id),e.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:e.jsx(r.Box,{component:"legend",sx:{fontSize:"0.75em"},children:e.jsx(r.Box,{component:"span",sx:{opacity:0},children:t})})})]})})}const Se=["string","multiline","json","yaml","component","custom","url"];function Be({disabled:t,list:s,renderItem:l,...o}){const d=I.useRef(null),m=I.useId(),a=re.useUpdate(),x=V.default(Object.entries(s),c=>c[1].index).map(c=>c[0]),k=I.useRef(x),b=I.useCallback(c=>{k.current=c,a()},[a]),g=I.useCallback(({index:c},{index:i})=>{const p=[...k.current];p.splice(i,0,...p.splice(c,1)),b(p)},[b]);I.useEffect(()=>{b(x)},[x.join("-")]);const[{isOver:f},n]=se.useDrop({accept:m,collect:c=>({isOver:c.isOver()}),canDrop:()=>!t,drop:()=>{var p;const c=()=>{k.current.forEach((h,S)=>{const u=s[h];u&&(u.index=S)})},i=(p=M.getYjsValue(s))==null?void 0:p.doc;i?i.transact(()=>{c()}):c()}});return I.useEffect(()=>{f||b(x)},[f]),n(d),e.jsx(r.Box,{...o,ref:d,className:Ge.cx(f&&"isDragging"),children:k.current.map((c,i)=>e.jsx(qt,{type:m,disabled:t,id:c,index:i,itemIndex:p=>k.current.indexOf(p),move:g,children:p=>{const h=s[c];return h?l(h.data,i,p):null}},c))})}function qt({disabled:t,id:s,index:l,type:o,children:d,itemIndex:m,move:a}){const x=I.useRef(),[{isDragging:k},b,g]=se.useDrag({type:o,item:()=>({id:s}),canDrag:()=>!t,collect:n=>({isDragging:n.isDragging()})}),[,f]=se.useDrop({accept:o,canDrop:()=>!t,hover(n,c){var j;if(!x.current)return;const i=m(n.id),p=l;if(i===p)return;const h=(j=x.current)==null?void 0:j.getBoundingClientRect(),S=(h.bottom-h.top)/2,v=c.getClientOffset().y-h.top;i<p&&v<S||i>p&&v>S||a({id:n.id,index:i},{id:s,index:l})}});return typeof d=="function"?d({isDragging:k,drag:b,drop:n=>(x.current=n,f(n)),preview:g}):(b(f(g(x))),e.jsx(r.Box,{ref:x,children:d}))}function Nt({drop:t,preview:s,drag:l,disabled:o,isDragging:d,children:m,onDelete:a,onVisibilityChange:x,visible:k=!0,actions:b,alwaysShowActions:g=!1}){const{t:f}=_.useLocaleContext();return e.jsx(r.Box,{ref:t,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:k?1:.5},children:e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsx(r.Box,{ref:s,sx:{flex:1,borderRadius:.5,bgcolor:d?"action.hover":"background.paper",opacity:.9999},children:m}),!o&&e.jsx(r.Box,{className:g?"":"hover-visible",sx:{maxWidth:g?"100%":0,overflow:"hidden",position:"absolute",right:2,top:2,transition:"max-width 0.3s ease-in-out"},children:e.jsxs(r.Stack,{direction:"row",sx:{bgcolor:n=>r.alpha(n.palette.grey[200],.9),borderRadius:1,p:.5,[`.${r.buttonClasses.root}`]:{minWidth:24,width:24,height:24,p:0}},children:[b,x&&e.jsx(r.Tooltip,{title:f(k?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{onClick:()=>x(!k),children:k?e.jsx(z.VisibilityOffRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}}):e.jsx(z.VisibilityRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),a&&e.jsx(r.Tooltip,{title:f("delete"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{onClick:a,children:e.jsx(z.DeleteOutlineRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),e.jsx(r.Tooltip,{title:f("dragSort"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{ref:l,children:e.jsx(z.DragIndicatorRounded,{sx:{color:"grey.500"}})})})]})})]})})}function Et({label:t,value:s,onChange:l}){const[o,d]=I.useState(!1);return e.jsxs(r.Stack,{gap:1,children:[e.jsx(r.TextField,{label:t,size:"small",value:s,onChange:m=>l==null?void 0:l(m.target.value),InputProps:{endAdornment:e.jsx(A.UploaderButton,{onChange:({response:m})=>{var x;const a=(x=m==null?void 0:m.data)==null?void 0:x.filename;a&&(l==null||l(a))}})}}),s&&e.jsx(r.Box,{component:"img",sx:{objectFit:"contain",borderRadius:1,cursor:"pointer"},src:T.getImageAbsoluteUrl(s),alt:t,maxWidth:100,maxHeight:100,width:"100%",onClick:()=>d(!0)}),e.jsx(r.Dialog,{open:o,onClose:()=>d(!1),children:e.jsx(r.Box,{component:"img",sx:{objectFit:"contain"},src:T.getImageAbsoluteUrl(s),alt:t})})]})}function le(t,s=""){return It.default(t,(l,o,d)=>{const m=s?`${s}.${d}`:d;return kt.default(o)?gt.default(l,le(o,m)):l[m]=o,l},{})}const Ut=[{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 X(t,s,l){return!t||!l?!1:Object.values(t).some(({data:o})=>o.id!==s&&o.key===l)}function Te(t,s){var l;return!t||!s?!1:((l=t[s])==null?void 0:l.data.visible)??!0}function Wt({componentId:t}){const{state:{components:s}}=T.useStore(),l=s[t],o=l==null?void 0:l.data;return o?e.jsx(r.Stack,{maxHeight:"100%",overflow:"auto",children:e.jsx(r.Box,{p:2,children:e.jsx(xt.ErrorBoundary,{FallbackComponent:T.ErrorView,resetKeys:[t],children:e.jsx(Kt,{value:o})})})}):null}function Kt({value:t}){var k,b,g;const{t:s}=_.useLocaleContext(),{localState:{currentLocale:l,componentDebugProps:o},state:{config:{defaultLocale:d}},localActions:{setComponentDebugProps:m}}=T.useStore(),a=M.getYjsValue(t).doc,x=T.useAllComponents();return e.jsx(r.Stack,{height:"100%",children:e.jsxs(r.Stack,{gap:2,children:[e.jsx(Oe,{config:t}),e.jsx(_e,{config:t,currentLocale:l,defaultLocale:d,allComponents:x,onUpdateConfig:f=>{a.transact(()=>{f(t)})}}),e.jsxs(r.Stack,{gap:2,direction:"row",justifyContent:"space-between",alignItems:"center",children:[e.jsx(r.Typography,{variant:"subtitle1",children:s("renderer")}),e.jsxs(r.TextField,{hiddenLabel:!0,size:"small",select:!0,SelectProps:{autoWidth:!0},value:((k=t.renderer)==null?void 0:k.type)||"react-component",onChange:f=>{a.transact(()=>{const n=f.target.value;t.renderer??(t.renderer={type:n}),t.renderer.type=n})},children:[e.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),e.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),((b=t.renderer)==null?void 0:b.type)==="component"?e.jsx(Gt,{value:t}):((g=t.renderer)==null?void 0:g.type)==="react-component"?e.jsx($t,{value:t}):null,e.jsx(ce,{config:t,currentLocale:l,defaultLocale:d,allComponents:x,onChange:({key:f,value:n})=>{m({[f]:n.value})},props:{...o}})]})})}function Oe({config:t}){const{t:s}=_.useLocaleContext();return e.jsx(A.UploaderProvider,{children:e.jsxs(r.Stack,{gap:2,children:[e.jsx(r.Typography,{variant:"subtitle1",children:s("basicInfo")}),e.jsx(r.TextField,{label:s("name"),size:"small",value:t.name||"",onChange:l=>t.name=l.target.value}),e.jsx(r.TextField,{label:s("description"),size:"small",multiline:!0,minRows:2,maxRows:10,inputProps:{maxLength:200},value:t.description||"",onChange:l=>t.description=l.target.value}),e.jsx(r.Autocomplete,{size:"small",options:[],multiple:!0,freeSolo:!0,value:t.tags??[],onChange:(l,o)=>t.tags=o,renderInput:l=>e.jsx(r.TextField,{label:s("tags"),...l})}),e.jsx(Et,{label:s("previewImage"),value:t.previewImage||"",onChange:l=>t.previewImage=l})]})})}function Re({data:t,params:s,visible:l,config:o,currentLocale:d,defaultLocale:m,allComponents:a,onUpdateConfig:x}){var g,f,n,c,i,p;const{t:k}=_.useLocaleContext(),b=I.useMemo(()=>t.type==="json"||t.type==="yaml"||t.type==="array"?Jt:W,[t.type]);return e.jsx(Nt,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{x(h=>{if(h.properties){const u=Object.entries(h.properties).sort(([,j],[,w])=>j.index-w.index);delete h.properties[t.id],u.filter(([j])=>j!==t.id).forEach(([,j],w)=>{j.index=w})}})},visible:l,onVisibilityChange:h=>{x(S=>{const u=S.properties[t.id].data;u.visible=h})},alwaysShowActions:!0,children:e.jsxs(r.Stack,{direction:"column",gap:2,children:[e.jsx(r.TextField,{label:k("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:t.key?X(o.properties,t.id,t.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:t.key?X(o.properties,t.id,t.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:t.key?X(o.properties,t.id,t.key)?"warning.main":"primary.main":"error.main"}},value:t.key||"",onChange:h=>{x(S=>{const u=S.properties[t.id].data;u.key=h.target.value.trim()})},InputProps:{endAdornment:!t.key||t.key&&X(o.properties,t.id,t.key)?e.jsx(r.InputAdornment,{position:"end",sx:{width:16,ml:0},children:e.jsx(r.Tooltip,{title:t.key?k("duplicateKey"):k("requiredKey"),children:e.jsx(z.InfoRounded,{sx:{color:t.key?"warning.main":"error.main",fontSize:16}})})}):null}}),e.jsxs(r.Stack,{direction:"row",gap:1,children:[e.jsx(r.TextField,{label:k("label"),size:"small",sx:{flex:1},value:(((f=(g=t.locales)==null?void 0:g[d])==null?void 0:f.name)??((c=(n=t.locales)==null?void 0:n[m])==null?void 0:c.name))||"",onChange:h=>{x(S=>{var v;const u=S.properties[t.id].data;u.locales??(u.locales={}),(v=u.locales)[d]??(v[d]={}),u.locales[d].name=h.target.value})}}),e.jsx(r.TextField,{label:k("type"),size:"small",select:!0,sx:{flex:1},value:t.type==="string"&&t.multiline?"multiline":t.type||"string",onChange:h=>{x(S=>{const u=S.properties[t.id].data;if(u.locales)for(const j of Object.keys(u.locales))u.locales[j].defaultValue=void 0;const v=h.target.value;v==="multiline"?(u.type="string",u.multiline=!0):(typeof u.multiline<"u"&&delete u.multiline,u.type=v)})},children:Ut.map(h=>e.jsx(r.MenuItem,{value:h.value,children:h.label},h.value))})]}),e.jsxs(r.Stack,{direction:"row",gap:1,children:[e.jsx(b,{allComponents:a,defaultLocale:m,component:o,property:t,label:k("defaultValue"),size:"small",fullWidth:!0,value:(p=(i=t.locales)==null?void 0:i[d])==null?void 0:p.defaultValue,onChange:(h,S)=>{x(u=>{var j;const v=u.properties[t.id].data;if(S!=null&&S.forceUpdateProperty){const w=le(v),C=le(h);Object.keys(C).forEach(y=>{w[y]||Ce.default(v,y,C[y])})}else v.locales??(v.locales={}),(j=v.locales)[d]??(j[d]={}),v.locales[d].defaultValue=h})}}),t.type==="custom"?e.jsx(r.Box,{children:e.jsx(Lt,{property:t,allComponents:a})}):null]})]})})}function Mt(t,s){const[l,o]=I.useState(0);return I.useEffect(()=>{const m=setTimeout(()=>{if(t.current){let a=t.current.parentElement,x=0;for(;a;)a.classList.contains("property-container")&&x++,a=a.parentElement;o(x)}},100);return()=>clearTimeout(m)},[t,s]),l}function _e({config:t,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:d,useI18nEditor:m=!0}){const{t:a}=_.useLocaleContext(),x=q.usePopupState({variant:"dialog"}),k=t.properties&&V.default(Object.values(t.properties),"index");return e.jsx(A.UploaderProvider,{children:e.jsxs(r.Stack,{gap:2,children:[e.jsxs(r.Stack,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between",children:[e.jsx(r.Typography,{variant:"subtitle1",children:a("properties")}),e.jsx(r.Box,{flex:1}),m&&e.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...q.bindTrigger(x),children:e.jsx(z.TranslateRounded,{fontSize:"small"})})]}),t.properties&&Object.keys(t.properties).length>0?e.jsx(Be,{component:r.Stack,gap:2,list:t.properties,renderItem:(b,g,f)=>{const n=Te(t.properties,b.id);return e.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:n?"1px solid":"1px dashed",borderColor:"divider"},children:e.jsx(r.Stack,{gap:2,children:e.jsx(Re,{data:b,params:f,visible:n,config:t,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:d})})},b.id)}}):e.jsx(G.default,{style:{fontSize:12},children:a("maker.properties.noProperties")}),e.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",onClick:()=>{d(b=>{var f;const g=T.nextId();b.properties??(b.properties={}),(f=b.properties)[g]??(f[g]={index:(k==null?void 0:k.length)||0,data:{id:g}})})},startIcon:e.jsx(z.AddRounded,{}),children:a("addObject",{object:a("property")})}),m&&e.jsx(De,{...q.bindDialog(x),component:t})]})})}function Lt({property:t,allComponents:s}){const l=q.usePopupState({variant:"popper"});return e.jsxs(e.Fragment,{children:[e.jsx(r.Button,{sx:{minWidth:0},...q.bindTrigger(l),children:e.jsx(z.SettingsRounded,{fontSize:"small"})}),e.jsx(r.Popper,{...q.bindPopper(l),children:e.jsx(Pe.ClickAwayListener,{onClickAway:l.close,children:e.jsx(r.Paper,{children:e.jsx(r.Box,{width:500,p:2,children:e.jsx(te,{value:t.componentId,onChange:(o,d)=>t.componentId=d,allComponents:s})})})})})]})}function Ht({value:t,valueImmutable:s,onChange:l,defaultLocale:o,allComponents:d}){var g;const[m,a]=I.useState(!1),{t:x,locale:k}=_.useLocaleContext(),b=typeof(t==null?void 0:t.componentId)=="string"?(g=d[t.componentId])==null?void 0:g.data:void 0;return b?e.jsxs(e.Fragment,{children:[e.jsx(r.Button,{sx:{minWidth:0},disabled:!b,onClick:()=>a(!0),children:e.jsx(z.SettingsRounded,{fontSize:"small"})}),e.jsxs(r.Dialog,{open:m,onClose:()=>a(!1),maxWidth:"md",fullWidth:!0,children:[e.jsx(r.DialogTitle,{children:x("maker.properties.parameters")}),e.jsx(r.DialogContent,{children:e.jsx(r.Box,{width:"100%",p:2,children:e.jsx(ce,{config:b,currentLocale:k,defaultLocale:o,allComponents:d,propertiesValue:t==null?void 0:t.properties,onChange:({id:f,value:n})=>{const c=st.cloneDeep(n.value);if(s){const i=JSON.parse(JSON.stringify(t));l==null||l({...i,properties:{...i.properties,[f]:{value:c}}})}else M.getYjsValue(b).doc.transact(()=>{t.properties??(t.properties={}),t.properties[f]={value:c}})}})})}),e.jsx(r.DialogActions,{children:e.jsx(r.Button,{onClick:()=>a(!1),children:x("close")})})]})]}):null}function De({type:t="properties",component:s,...l}){var f,n,c;const{t:o}=_.useLocaleContext(),{state:{components:d,supportedLocales:m,config:{defaultLocale:a}}}=T.useStore(),x=T.useAllComponents(),k=M.getYjsValue(s).doc,b=t==="properties"?s.properties:t==="parameters"&&((f=s.renderer)==null?void 0:f.type)==="component"?(n=d[s.renderer.componentId])==null?void 0:n.data.properties:void 0,g=((c=s.renderer)==null?void 0:c.type)==="component"?s:void 0;return e.jsxs(r.Dialog,{...l,fullWidth:!0,maxWidth:"lg",children:[e.jsx(r.DialogTitle,{children:o("i18nEditorTitle")}),e.jsx(r.DialogContent,{children:b&&e.jsx(r.Stack,{children:e.jsxs(r.Table,{stickyHeader:!0,sx:{td:{verticalAlign:"top"}},children:[e.jsx(r.TableHead,{children:e.jsx(r.TableRow,{children:m.map(({locale:i,name:p})=>e.jsxs(r.TableCell,{children:[p,a===i&&e.jsx(z.StarRounded,{sx:{fontSize:12,color:"text.secondary"}})]},i))})}),e.jsx(r.TableBody,{children:V.default(Object.values(b),"index").map(({data:i})=>e.jsx(r.TableRow,{children:m.map(({locale:p})=>{var h,S,u,v,j,w,C,y,P,B,O,F,N,E,Q,L,H,J,Y,$,ae,ue,de,pe,xe,me;return e.jsx(r.TableCell,{children:e.jsx(r.Stack,{gap:1,children:t==="properties"?e.jsxs(e.Fragment,{children:[e.jsx(r.TextField,{size:"small",label:"Key",value:i.key||"",onChange:K=>{k.transact(()=>{i.key=K.target.value.trim()})}}),e.jsx(r.TextField,{size:"small",label:o("label"),value:(((S=(h=i.locales)==null?void 0:h[p])==null?void 0:S.name)??((v=(u=i.locales)==null?void 0:u[a])==null?void 0:v.name))||"",onChange:K=>{k.transact(()=>{var U;i.locales??(i.locales={}),(U=i.locales)[p]??(U[p]={}),i.locales[p].name=K.target.value})}}),e.jsx(r.Box,{children:e.jsx(W,{allComponents:x,defaultLocale:a,component:s,property:i,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:ee.default((w=(j=i.locales)==null?void 0:j[p])==null?void 0:w.defaultValue),value:((y=(C=i.locales)==null?void 0:C[p])==null?void 0:y.defaultValue)??((B=(P=i.locales)==null?void 0:P[a])==null?void 0:B.defaultValue),onChange:K=>{k.transact(()=>{var U;i.locales??(i.locales={}),(U=i.locales)[p]??(U[p]={}),i.locales[p].defaultValue=K})}})})]}):t==="parameters"&&g?e.jsx(r.Box,{children:e.jsx(W,{allComponents:x,defaultLocale:a,component:s,property:i,size:"small",fullWidth:!0,valueImmutable:ee.default((E=(N=(F=(O=g.renderer.properties)==null?void 0:O[i.id])==null?void 0:F.locales)==null?void 0:N[p])==null?void 0:E.value),value:((J=(H=(L=(Q=g.renderer.properties)==null?void 0:Q[i.id])==null?void 0:L.locales)==null?void 0:H[p])==null?void 0:J.value)??((ue=(ae=($=(Y=g.renderer.properties)==null?void 0:Y[i.id])==null?void 0:$.locales)==null?void 0:ae[a])==null?void 0:ue.value)??((pe=(de=i.locales)==null?void 0:de[p])==null?void 0:pe.defaultValue)??((me=(xe=i.locales)==null?void 0:xe[a])==null?void 0:me.defaultValue),onChange:K=>{k.transact(()=>{var U,fe,he,je,be;(U=g.renderer).properties??(U.properties={}),(fe=g.renderer.properties)[he=i.id]??(fe[he]={}),(je=g.renderer.properties[i.id]).locales??(je.locales={}),(be=g.renderer.properties[i.id].locales)[p]??(be[p]={}),g.renderer.properties[i.id].locales[p].value=K})}})}):null},i.id)},p)})},i.id))})]})})}),e.jsx(r.DialogActions,{children:e.jsx(r.Button,{onClick:i=>{var p;return(p=l.onClose)==null?void 0:p.call(l,i,"escapeKeyDown")},children:o("close")})})]})}const we=(t,s)=>l=>{const o=[l.palette.info.main,l.palette.primary.main,l.palette.secondary.main,l.palette.success.main,l.palette.warning.main],d=Math.min(o.length-1,t),m=o[d],a=ge.alpha(m,.5),x=ge.alpha(m,1);return{borderColor:`${a} !important`,borderLeft:"3px solid !important",borderLeftColor:a,color:x,...s}};function Jt({property:t,onChange:s,defaultLocale:l,allComponents:o}){const{t:d,locale:m}=_.useLocaleContext(),a=I.useRef(null),x=Mt(a,t),k=I.useCallback(()=>{if(!(t.type!=="json"&&t.type!=="yaml"&&t.type!=="array")&&t.subProperties)try{const b={};V.default(Object.values(t.subProperties),"index").filter(n=>n.data.visible!==!1&&n.data.key).forEach(({data:n})=>{var i,p,h,S;if(!n.key)return;let c=((p=(i=n.locales)==null?void 0:i[m])==null?void 0:p.defaultValue)??((S=(h=n.locales)==null?void 0:h[l])==null?void 0:S.defaultValue);if(n.type==="number")c=Number(c);else if(n.type==="boolean")c=c===!0||c==="true";else if((n.type==="json"||n.type==="yaml")&&typeof c=="string")try{n.type==="json"?c=JSON.parse(c):c=oe.parse(c)}catch(u){console.error("Error parsing nested value",c,u),c={}}b[n.key]=c});const f=T.transformValue(b,t.type);s==null||s(f)}catch(b){console.error("Error converting structure to text:",b)}},[t,m,l,s]);return t.type!=="json"&&t.type!=="yaml"&&t.type!=="array"?null:e.jsxs(r.Stack,{direction:"column",gap:1.5,sx:{width:"100%"},ref:a,children:[e.jsx(r.Divider,{sx:{mt:-1},children:e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:d("maker.properties.subProperties")})}),t.subProperties&&Object.keys(t.subProperties).length>0?e.jsx(Be,{component:r.Stack,gap:2,list:t.subProperties,renderItem:(b,g,f)=>{const n=b.visible!==!1;return e.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:n?"1px solid":"1px dashed","&":we(x)},children:e.jsx(r.Stack,{gap:2,children:e.jsx(Re,{data:b,params:f,visible:n,config:{properties:t.subProperties},currentLocale:m,defaultLocale:l,allComponents:o,onUpdateConfig:c=>{try{const i={properties:t.subProperties||{}};c(i);const p={...t,subProperties:i.properties};s==null||s(p,{forceUpdateProperty:!0}),k()}catch(i){console.error("Error updating property:",i)}}})})},b.id)}}):e.jsx(G.default,{style:{fontSize:12,height:100},children:d("maker.properties.noSubProperties")}),e.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",size:"small",startIcon:e.jsx(z.AddRounded,{}),onClick:()=>{try{const b=t.subProperties||{},g=T.nextId(),n={index:Object.values(b).length,data:{id:g,key:"",type:"string",visible:!0,locales:{[m]:{name:"",defaultValue:""}},subProperties:{}}},c={...t,subProperties:{...b,[g]:n}};s==null||s(c,{forceUpdateProperty:!0}),k()}catch(b){console.error("Error adding property:",b)}},sx:{"&":we(x,{})},children:d("maker.properties.addSubProperty")})]})}function W({component:t,property:s,value:l,onChange:o,valueImmutable:d,defaultLocale:m,allComponents:a,...x}){var c,i,p,h,S;const{locale:k}=_.useLocaleContext(),b=A.useUploader(),g=I.useRef(null),f=()=>{var v;const u=(v=b==null?void 0:b.current)==null?void 0:v.getUploader();u==null||u.open(),g.current&&u.onceUploadSuccess(({response:j})=>{var C,y;let w=((C=j==null?void 0:j.data)==null?void 0:C.filename)||"";w&&(w=`mediakit://${w}`,l&&!l.includes("mediakit://")&&(w+=" # please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address")),(y=g.current)==null||y.call(g,w)})},n=x.label||((i=(c=s.locales)==null?void 0:c[k])==null?void 0:i.name)||((h=(p=s.locales)==null?void 0:p[m])==null?void 0:h.name)||s.key||s.id;if(s.type==="number")return e.jsx(Yt,{...x,label:n,NumberProps:{value:["number","string"].includes(typeof l)?l:null,onChange:(u,v)=>o==null?void 0:o(v)}});if(s.type==="decimal")return e.jsx(r.TextField,{...x,label:n,type:"text",value:l??"",onChange:u=>{const v=u.target.value;if(v===""||v==="-"){o==null||o(v);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(v)){let w=v;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(w)&&(w=Number(w)),o==null||o(w)}}});if(s.type==="boolean")return e.jsx(r.FormControlLabel,{label:n,labelPlacement:"start",control:e.jsx(r.Switch,{checked:l===!0,onChange:(u,v)=>o==null?void 0:o(v)})});if(s.type==="color")return e.jsx(Vt,{label:n,value:l,onChange:u=>{o==null||o(u)}});if(s.type==="json"||s.type==="yaml")return e.jsx(Ft,{label:n,value:l,onChange:u=>{o==null||o(u)},property:s,component:t,defaultLocale:m,allComponents:a,PropertyValueField:W,onUpload:u=>{g.current=u,f()}});if(s.type==="custom"){const u=(S=a[s.componentId])==null?void 0:S.data;return u?e.jsx(r.Box,{width:"100%",children:e.jsx(Z.CustomComponentRenderer,{componentId:u.id,props:{label:n,value:l,onChange:o},locale:k,dev:{mode:"draft",components:a,defaultLocale:m}})}):e.jsx(r.TextField,{...x,label:n,disabled:!0,placeholder:"Click right button select a component"})}if(s.type==="component")return e.jsxs(r.Stack,{width:"100%",direction:"row",gap:1,children:[e.jsx(r.Box,{flex:1,children:e.jsx(te,{allComponents:a,label:n,value:l==null?void 0:l.componentId,onChange:(u,v)=>{d||!l?o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:v}):typeof l=="object"&&(l.componentId=v)}})}),e.jsx(r.Box,{children:e.jsx(Ht,{value:l,valueImmutable:d,onChange:o,defaultLocale:m,allComponents:a})})]});if(!s.type||["string","url"].includes(s.type)){const u=s.type==="string"?s.multiline:void 0,v=s.type==="url"?l==null?void 0:l.url:l;return e.jsx(r.TextField,{...x,label:n,value:typeof v=="string"?v:"",multiline:u,minRows:u?2:void 0,maxRows:u?10:void 0,onChange:j=>o==null?void 0:o(s.type==="url"?{...l,url:j.target.value,mediaKitUrl:j.target.value}:j.target.value),InputProps:s.type==="url"?{sx:{pr:0},endAdornment:e.jsxs(r.InputAdornment,{position:"end",children:[e.jsx(A.UploaderButton,{onChange:async({response:j})=>{var P,B,O;const w=((P=j==null?void 0:j.data)==null?void 0:P.url)||((B=j==null?void 0:j.data)==null?void 0:B.fileUrl);let C;w&&(C=await A.getImageSize(w).catch(()=>A.getVideoSize(w)).catch(()=>{}));let y=((O=j==null?void 0:j.data)==null?void 0:O.filename)||"";y&&(y=`mediakit://${y}`),o==null||o({url:w,mediaKitUrl:y,width:C==null?void 0:C.naturalWidth,height:C==null?void 0:C.naturalHeight})}}),e.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:e.jsx(z.InfoRounded,{sx:{cursor:"default"},fontSize:"small"})})]})}:void 0})}return s.type==="array"?e.jsx(Ot,{label:n,value:Array.isArray(l)?l:[],onChange:u=>o==null?void 0:o(u),property:s,renderItem:({item:u,index:v,onChange:j})=>s.subProperties&&Object.keys(s.subProperties).length>0?e.jsx(r.Stack,{gap:1,width:"100%",children:V.default(Object.values(s.subProperties),"index").filter(w=>w.data.visible!==!1).map(({data:w})=>w.key?e.jsx(W,{component:t,property:w,value:u[w.key],onChange:C=>{const y={...u,[w.key]:C};j(y)},size:"small",fullWidth:!0,defaultLocale:m,allComponents:a},w.id):null)},v):e.jsx(r.TextField,{size:x.size,fullWidth:!0,value:u,onChange:w=>j(w.target.value)})}):(console.error("Unsupported property type",s.type),null)}function Yt({NumberProps:t,...s}){const{getInputProps:l}=Pe.unstable_useNumberInput(t),o=l();return e.jsx(r.TextField,{...s,inputProps:o})}const Ae=`import React from '@blocklet/pages-kit/builtin/react'
|
|
21
|
+
`;function Vt({value:e,onChange:s,...o}){const n=I.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsx(Rt,{...o,value:e,onChange:s,InputProps:{endAdornment:t.jsx(r.InputAdornment,{position:"end",children:t.jsx(zt,{color:e??"",style:{width:"1.5rem",height:"1.5rem",padding:0},onClick:()=>{var d;(d=n.current)==null||d.open({value:e??""})}})})}}),t.jsx(At,{ref:n,onSave:({value:d},x)=>{s(d),x()}})]})}function qt({label:e,value:s,onChange:o,property:n,component:d,defaultLocale:x,allComponents:u,PropertyValueField:m,onUpload:k}){const{locale:j}=_.useLocaleContext(),g=I.useRef(null);if(!Ie.default(n.subProperties)){const l=V.default(Object.values(n.subProperties||{}),"index").filter(c=>c.data.visible!==!1&&c.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:l.map((c,i)=>{const{data:p}=c,h=p.key??p.id,S=i===l.length-1;let a=null;try{s&&typeof s=="object"?a=s[h]:typeof s=="string"&&(a=(n.type==="yaml"?oe.parse(s||""):JSON.parse(s||"{}"))[h])}catch{}a==null&&(p.locales&&j&&p.locales[j]?a=p.locales[j].defaultValue:p.locales&&x&&p.locales[x]&&(a=p.locales[x].defaultValue));const v=w=>{try{let C={};if(typeof s=="string")try{C=n.type==="yaml"?oe.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(C={...s});Ce.default(C,h,w);const y=T.transformValue(C,n.type);o==null||o(y)}catch(C){console.error("Error updating property:",C)}},b=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:b,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),t.jsx(r.Box,{sx:{position:"absolute",left:b,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!S&&t.jsx(r.Box,{sx:{position:"absolute",left:b,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),t.jsx(r.Box,{sx:{flexGrow:1},children:t.jsx(m,{component:d,property:p,value:a,onChange:v,size:"small",fullWidth:!0,defaultLocale:x,allComponents:u})})]},p.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(le.CodeEditor,{keyId:n.id,locale:j,language:n.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:l=>{o==null||o(l)},onUpload:l=>{g.current=l,k&&k(l)}},n.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 Se=["string","multiline","json","yaml","component","custom","url"];function Be({disabled:e,list:s,renderItem:o,...n}){const d=I.useRef(null),x=I.useId(),u=re.useUpdate(),m=V.default(Object.entries(s),c=>c[1].index).map(c=>c[0]),k=I.useRef(m),j=I.useCallback(c=>{k.current=c,u()},[u]),g=I.useCallback(({index:c},{index:i})=>{const p=[...k.current];p.splice(i,0,...p.splice(c,1)),j(p)},[j]);I.useEffect(()=>{j(m)},[m.join("-")]);const[{isOver:f},l]=se.useDrop({accept:x,collect:c=>({isOver:c.isOver()}),canDrop:()=>!e,drop:()=>{var p;const c=()=>{k.current.forEach((h,S)=>{const a=s[h];a&&(a.index=S)})},i=(p=M.getYjsValue(s))==null?void 0:p.doc;i?i.transact(()=>{c()}):c()}});return I.useEffect(()=>{f||j(m)},[f]),l(d),t.jsx(r.Box,{...n,ref:d,className:Ge.cx(f&&"isDragging"),children:k.current.map((c,i)=>t.jsx(Ft,{type:x,disabled:e,id:c,index:i,itemIndex:p=>k.current.indexOf(p),move:g,children:p=>{const h=s[c];return h?o(h.data,i,p):null}},c))})}function Ft({disabled:e,id:s,index:o,type:n,children:d,itemIndex:x,move:u}){const m=I.useRef(),[{isDragging:k},j,g]=se.useDrag({type:n,item:()=>({id:s}),canDrag:()=>!e,collect:l=>({isDragging:l.isDragging()})}),[,f]=se.useDrop({accept:n,canDrop:()=>!e,hover(l,c){var b;if(!m.current)return;const i=x(l.id),p=o;if(i===p)return;const h=(b=m.current)==null?void 0:b.getBoundingClientRect(),S=(h.bottom-h.top)/2,v=c.getClientOffset().y-h.top;i<p&&v<S||i>p&&v>S||u({id:l.id,index:i},{id:s,index:o})}});return typeof d=="function"?d({isDragging:k,drag:j,drop:l=>(m.current=l,f(l)),preview:g}):(j(f(g(m))),t.jsx(r.Box,{ref:m,children:d}))}function Nt({drop:e,preview:s,drag:o,disabled:n,isDragging:d,children:x,onDelete:u,onVisibilityChange:m,visible:k=!0,actions:j,alwaysShowActions:g=!1}){const{t:f}=_.useLocaleContext();return t.jsx(r.Box,{ref:e,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:k?1:.5},children:t.jsxs(r.Box,{sx:{position:"relative"},children:[t.jsx(r.Box,{ref:s,sx:{flex:1,borderRadius:.5,bgcolor:d?"action.hover":"background.paper",opacity:.9999},children:x}),!n&&t.jsx(r.Box,{className:g?"":"hover-visible",sx:{maxWidth:g?"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:l=>r.alpha(l.palette.grey[200],.9),borderRadius:1,p:.5,[`.${r.buttonClasses.root}`]:{minWidth:24,width:24,height:24,p:0}},children:[j,m&&t.jsx(r.Tooltip,{title:f(k?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:()=>m(!k),children:k?t.jsx(A.VisibilityOffRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}}):t.jsx(A.VisibilityRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),u&&t.jsx(r.Tooltip,{title:f("delete"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:u,children:t.jsx(A.DeleteOutlineRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),t.jsx(r.Tooltip,{title:f("dragSort"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{ref:o,children:t.jsx(A.DragIndicatorRounded,{sx:{color:"grey.500"}})})})]})})]})})}function Et({label:e,value:s,onChange:o}){const[n,d]=I.useState(!1);return t.jsxs(r.Stack,{gap:1,children:[t.jsx(r.TextField,{label:e,size:"small",value:s,onChange:x=>o==null?void 0:o(x.target.value),InputProps:{endAdornment:t.jsx(z.UploaderButton,{onChange:({response:x})=>{var m;const u=(m=x==null?void 0:x.data)==null?void 0:m.filename;u&&(o==null||o(u))}})}}),s&&t.jsx(r.Box,{component:"img",sx:{objectFit:"contain",borderRadius:1,cursor:"pointer"},src:T.getImageAbsoluteUrl(s),alt:e,maxWidth:100,maxHeight:100,width:"100%",onClick:()=>d(!0)}),t.jsx(r.Dialog,{open:n,onClose:()=>d(!1),children:t.jsx(r.Box,{component:"img",sx:{objectFit:"contain"},src:T.getImageAbsoluteUrl(s),alt:e})})]})}function ne(e,s=""){return It.default(e,(o,n,d)=>{const x=s?`${s}.${d}`:d;return kt.default(n)?gt.default(o,ne(n,x)):o[x]=n,o},{})}const Ut=[{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 X(e,s,o){return!e||!o?!1:Object.values(e).some(({data:n})=>n.id!==s&&n.key===o)}function Te(e,s){var o;return!e||!s?!1:((o=e[s])==null?void 0:o.data.visible)??!0}function Wt({componentId:e}){const{state:{components:s}}=T.useStore(),o=s[e],n=o==null?void 0:o.data;return n?t.jsx(r.Stack,{maxHeight:"100%",overflow:"auto",children:t.jsx(r.Box,{p:2,children:t.jsx(xt.ErrorBoundary,{FallbackComponent:T.ErrorView,resetKeys:[e],children:t.jsx(Kt,{value:n})})})}):null}function Kt({value:e}){var k,j,g;const{t:s}=_.useLocaleContext(),{localState:{currentLocale:o,componentDebugProps:n},state:{config:{defaultLocale:d}},localActions:{setComponentDebugProps:x}}=T.useStore(),u=M.getYjsValue(e).doc,m=T.useAllComponents();return t.jsx(r.Stack,{height:"100%",children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(Oe,{config:e}),t.jsx(_e,{config:e,currentLocale:o,defaultLocale:d,allComponents:m,onUpdateConfig:f=>{u.transact(()=>{f(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:((k=e.renderer)==null?void 0:k.type)||"react-component",onChange:f=>{u.transact(()=>{const l=f.target.value;e.renderer??(e.renderer={type:l}),e.renderer.type=l})},children:[t.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),t.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),((j=e.renderer)==null?void 0:j.type)==="component"?t.jsx(Gt,{value:e}):((g=e.renderer)==null?void 0:g.type)==="react-component"?t.jsx($t,{value:e}):null,t.jsx(ce,{config:e,currentLocale:o,defaultLocale:d,allComponents:m,onChange:({key:f,value:l})=>{x({[f]:l.value})},props:{...n}})]})})}function Oe({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:o=>e.name=o.target.value}),t.jsx(r.TextField,{label:s("description"),size:"small",multiline:!0,minRows:2,maxRows:10,inputProps:{maxLength:200},value:e.description||"",onChange:o=>e.description=o.target.value}),t.jsx(r.Autocomplete,{size:"small",options:[],multiple:!0,freeSolo:!0,value:e.tags??[],onChange:(o,n)=>e.tags=n,renderInput:o=>t.jsx(r.TextField,{label:s("tags"),...o})}),t.jsx(Et,{label:s("previewImage"),value:e.previewImage||"",onChange:o=>e.previewImage=o})]})})}function Re({data:e,params:s,visible:o,config:n,currentLocale:d,defaultLocale:x,allComponents:u,onUpdateConfig:m}){var g,f,l,c,i,p;const{t:k}=_.useLocaleContext(),j=I.useMemo(()=>e.type==="json"||e.type==="yaml"||e.type==="array"?Jt:W,[e.type]);return t.jsx(Nt,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{m(h=>{if(h.properties){const a=Object.entries(h.properties).sort(([,b],[,w])=>b.index-w.index);delete h.properties[e.id],a.filter(([b])=>b!==e.id).forEach(([,b],w)=>{b.index=w})}})},visible:o,onVisibilityChange:h=>{m(S=>{const a=S.properties[e.id].data;a.visible=h})},alwaysShowActions:!0,children:t.jsxs(r.Stack,{direction:"column",gap:2,children:[t.jsx(r.TextField,{label:k("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:e.key?X(n.properties,e.id,e.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:e.key?X(n.properties,e.id,e.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:e.key?X(n.properties,e.id,e.key)?"warning.main":"primary.main":"error.main"}},value:e.key||"",onChange:h=>{m(S=>{const a=S.properties[e.id].data;a.key=h.target.value.trim()})},InputProps:{endAdornment:!e.key||e.key&&X(n.properties,e.id,e.key)?t.jsx(r.InputAdornment,{position:"end",sx:{width:16,ml:0},children:t.jsx(r.Tooltip,{title:e.key?k("duplicateKey"):k("requiredKey"),children:t.jsx(A.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:k("label"),size:"small",sx:{flex:1},value:(((f=(g=e.locales)==null?void 0:g[d])==null?void 0:f.name)??((c=(l=e.locales)==null?void 0:l[x])==null?void 0:c.name))||"",onChange:h=>{m(S=>{var v;const a=S.properties[e.id].data;a.locales??(a.locales={}),(v=a.locales)[d]??(v[d]={}),a.locales[d].name=h.target.value})}}),t.jsx(r.TextField,{label:k("type"),size:"small",select:!0,sx:{flex:1},value:e.type==="string"&&e.multiline?"multiline":e.type||"string",onChange:h=>{m(S=>{const a=S.properties[e.id].data;if(a.locales)for(const b of Object.keys(a.locales))a.locales[b].defaultValue=void 0;const v=h.target.value;v==="multiline"?(a.type="string",a.multiline=!0):(typeof a.multiline<"u"&&delete a.multiline,a.type=v)})},children:Ut.map(h=>t.jsx(r.MenuItem,{value:h.value,children:h.label},h.value))})]}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(j,{allComponents:u,defaultLocale:x,component:n,property:e,label:k("defaultValue"),size:"small",fullWidth:!0,value:(p=(i=e.locales)==null?void 0:i[d])==null?void 0:p.defaultValue,onChange:(h,S)=>{m(a=>{var b;const v=a.properties[e.id].data;if(S!=null&&S.forceUpdateProperty){const w=ne(v),C=ne(h);Object.keys(C).forEach(y=>{w[y]||Ce.default(v,y,C[y])})}else v.locales??(v.locales={}),(b=v.locales)[d]??(b[d]={}),v.locales[d].defaultValue=h})}}),e.type==="custom"?t.jsx(r.Box,{children:t.jsx(Lt,{property:e,allComponents:u})}):null]})]})})}function Mt(e,s){const[o,n]=I.useState(0);return I.useEffect(()=>{const x=setTimeout(()=>{if(e.current){let u=e.current.parentElement,m=0;for(;u;)u.classList.contains("property-container")&&m++,u=u.parentElement;n(m)}},100);return()=>clearTimeout(x)},[e,s]),o}function _e({config:e,currentLocale:s,defaultLocale:o,allComponents:n,onUpdateConfig:d,useI18nEditor:x=!0}){const{t:u}=_.useLocaleContext(),m=F.usePopupState({variant:"dialog"}),k=e.properties&&V.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:u("properties")}),t.jsx(r.Box,{flex:1}),x&&t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...F.bindTrigger(m),children:t.jsx(A.TranslateRounded,{fontSize:"small"})})]}),e.properties&&Object.keys(e.properties).length>0?t.jsx(Be,{component:r.Stack,gap:2,list:e.properties,renderItem:(j,g,f)=>{const l=Te(e.properties,j.id);return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:l?"1px solid":"1px dashed",borderColor:"divider"},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Re,{data:j,params:f,visible:l,config:e,currentLocale:s,defaultLocale:o,allComponents:n,onUpdateConfig:d})})},j.id)}}):t.jsx(G.default,{style:{fontSize:12},children:u("maker.properties.noProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",onClick:()=>{d(j=>{var f;const g=T.nextId();j.properties??(j.properties={}),(f=j.properties)[g]??(f[g]={index:(k==null?void 0:k.length)||0,data:{id:g}})})},startIcon:t.jsx(A.AddRounded,{}),children:u("addObject",{object:u("property")})}),x&&t.jsx(De,{...F.bindDialog(m),component:e})]})})}function Lt({property:e,allComponents:s}){const o=F.usePopupState({variant:"popper"});return t.jsxs(t.Fragment,{children:[t.jsx(r.Button,{sx:{minWidth:0},...F.bindTrigger(o),children:t.jsx(A.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Popper,{...F.bindPopper(o),children:t.jsx(Pe.ClickAwayListener,{onClickAway:o.close,children:t.jsx(r.Paper,{children:t.jsx(r.Box,{width:500,p:2,children:t.jsx(te,{value:e.componentId,onChange:(n,d)=>e.componentId=d,allComponents:s})})})})})]})}function Ht({value:e,valueImmutable:s,onChange:o,defaultLocale:n,allComponents:d}){var g;const[x,u]=I.useState(!1),{t:m,locale:k}=_.useLocaleContext(),j=typeof(e==null?void 0:e.componentId)=="string"?(g=d[e.componentId])==null?void 0:g.data:void 0;return j?t.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[t.jsx(r.Button,{sx:{minWidth:0},disabled:!j,onClick:()=>u(!x),color:x?"primary":"inherit",children:t.jsx(A.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Collapse,{in:x,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:j,currentLocale:k,defaultLocale:n,allComponents:d,propertiesValue:e==null?void 0:e.properties,onChange:({id:f,value:l})=>{const c=st.cloneDeep(l.value);if(s){const i=JSON.parse(JSON.stringify(e));o==null||o({...i,properties:{...i.properties,[f]:{value:c}}})}else M.getYjsValue(j).doc.transact(()=>{e.properties??(e.properties={}),e.properties[f]={value:c}})}})}),t.jsx(r.Button,{size:"small",onClick:()=>u(!1),sx:{mt:1},children:m("close")})]})})]}):null}function De({type:e="properties",component:s,...o}){var f,l,c;const{t:n}=_.useLocaleContext(),{state:{components:d,supportedLocales:x,config:{defaultLocale:u}}}=T.useStore(),m=T.useAllComponents(),k=M.getYjsValue(s).doc,j=e==="properties"?s.properties:e==="parameters"&&((f=s.renderer)==null?void 0:f.type)==="component"?(l=d[s.renderer.componentId])==null?void 0:l.data.properties:void 0,g=((c=s.renderer)==null?void 0:c.type)==="component"?s:void 0;return t.jsxs(r.Dialog,{...o,fullWidth:!0,maxWidth:"lg",children:[t.jsx(r.DialogTitle,{children:n("i18nEditorTitle")}),t.jsx(r.DialogContent,{children:j&&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:x.map(({locale:i,name:p})=>t.jsxs(r.TableCell,{children:[p,u===i&&t.jsx(A.StarRounded,{sx:{fontSize:12,color:"text.secondary"}})]},i))})}),t.jsx(r.TableBody,{children:V.default(Object.values(j),"index").map(({data:i})=>t.jsx(r.TableRow,{children:x.map(({locale:p})=>{var h,S,a,v,b,w,C,y,P,B,O,q,N,E,Q,L,H,J,Y,$,ae,ue,de,pe,xe,me;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:i.key||"",onChange:K=>{k.transact(()=>{i.key=K.target.value.trim()})}}),t.jsx(r.TextField,{size:"small",label:n("label"),value:(((S=(h=i.locales)==null?void 0:h[p])==null?void 0:S.name)??((v=(a=i.locales)==null?void 0:a[u])==null?void 0:v.name))||"",onChange:K=>{k.transact(()=>{var U;i.locales??(i.locales={}),(U=i.locales)[p]??(U[p]={}),i.locales[p].name=K.target.value})}}),t.jsx(r.Box,{children:t.jsx(W,{allComponents:m,defaultLocale:u,component:s,property:i,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:ee.default((w=(b=i.locales)==null?void 0:b[p])==null?void 0:w.defaultValue),value:((y=(C=i.locales)==null?void 0:C[p])==null?void 0:y.defaultValue)??((B=(P=i.locales)==null?void 0:P[u])==null?void 0:B.defaultValue),onChange:K=>{k.transact(()=>{var U;i.locales??(i.locales={}),(U=i.locales)[p]??(U[p]={}),i.locales[p].defaultValue=K})}})})]}):e==="parameters"&&g?t.jsx(r.Box,{children:t.jsx(W,{allComponents:m,defaultLocale:u,component:s,property:i,size:"small",fullWidth:!0,valueImmutable:ee.default((E=(N=(q=(O=g.renderer.properties)==null?void 0:O[i.id])==null?void 0:q.locales)==null?void 0:N[p])==null?void 0:E.value),value:((J=(H=(L=(Q=g.renderer.properties)==null?void 0:Q[i.id])==null?void 0:L.locales)==null?void 0:H[p])==null?void 0:J.value)??((ue=(ae=($=(Y=g.renderer.properties)==null?void 0:Y[i.id])==null?void 0:$.locales)==null?void 0:ae[u])==null?void 0:ue.value)??((pe=(de=i.locales)==null?void 0:de[p])==null?void 0:pe.defaultValue)??((me=(xe=i.locales)==null?void 0:xe[u])==null?void 0:me.defaultValue),onChange:K=>{k.transact(()=>{var U,fe,he,be,je;(U=g.renderer).properties??(U.properties={}),(fe=g.renderer.properties)[he=i.id]??(fe[he]={}),(be=g.renderer.properties[i.id]).locales??(be.locales={}),(je=g.renderer.properties[i.id].locales)[p]??(je[p]={}),g.renderer.properties[i.id].locales[p].value=K})}})}):null},i.id)},p)})},i.id))})]})})}),t.jsx(r.DialogActions,{children:t.jsx(r.Button,{onClick:i=>{var p;return(p=o.onClose)==null?void 0:p.call(o,i,"escapeKeyDown")},children:n("close")})})]})}const we=(e,s)=>o=>{const n=[o.palette.info.main,o.palette.primary.main,o.palette.secondary.main,o.palette.success.main,o.palette.warning.main],d=Math.min(n.length-1,e),x=n[d],u=ge.alpha(x,.5),m=ge.alpha(x,1);return{borderColor:`${u} !important`,borderLeft:"3px solid !important",borderLeftColor:u,color:m,...s}};function Jt({property:e,onChange:s,defaultLocale:o,allComponents:n}){const{t:d,locale:x}=_.useLocaleContext(),u=I.useRef(null),m=Mt(u,e),k=I.useCallback(()=>{if(!(e.type!=="json"&&e.type!=="yaml"&&e.type!=="array")&&e.subProperties)try{const j={};V.default(Object.values(e.subProperties),"index").filter(l=>l.data.visible!==!1&&l.data.key).forEach(({data:l})=>{var i,p,h,S;if(!l.key)return;let c=((p=(i=l.locales)==null?void 0:i[x])==null?void 0:p.defaultValue)??((S=(h=l.locales)==null?void 0:h[o])==null?void 0:S.defaultValue);if(l.type==="number")c=Number(c);else if(l.type==="boolean")c=c===!0||c==="true";else if((l.type==="json"||l.type==="yaml")&&typeof c=="string")try{l.type==="json"?c=JSON.parse(c):c=oe.parse(c)}catch(a){console.error("Error parsing nested value",c,a),c={}}j[l.key]=c});const f=T.transformValue(j,e.type);s==null||s(f)}catch(j){console.error("Error converting structure to text:",j)}},[e,x,o,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:u,children:[t.jsx(r.Divider,{sx:{mt:-1},children:t.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:d("maker.properties.subProperties")})}),e.subProperties&&Object.keys(e.subProperties).length>0?t.jsx(Be,{component:r.Stack,gap:2,list:e.subProperties,renderItem:(j,g,f)=>{const l=j.visible!==!1;return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:l?"1px solid":"1px dashed","&":we(m)},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Re,{data:j,params:f,visible:l,config:{properties:e.subProperties},currentLocale:x,defaultLocale:o,allComponents:n,onUpdateConfig:c=>{try{const i={properties:e.subProperties||{}};c(i);const p={...e,subProperties:i.properties};s==null||s(p,{forceUpdateProperty:!0}),k()}catch(i){console.error("Error updating property:",i)}}})})},j.id)}}):t.jsx(G.default,{style:{fontSize:12,height:100},children:d("maker.properties.noSubProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",size:"small",startIcon:t.jsx(A.AddRounded,{}),onClick:()=>{try{const j=e.subProperties||{},g=T.nextId(),l={index:Object.values(j).length,data:{id:g,key:"",type:"string",visible:!0,locales:{[x]:{name:"",defaultValue:""}},subProperties:{}}},c={...e,subProperties:{...j,[g]:l}};s==null||s(c,{forceUpdateProperty:!0}),k()}catch(j){console.error("Error adding property:",j)}},sx:{"&":we(m,{})},children:d("maker.properties.addSubProperty")})]})}function W({component:e,property:s,value:o,onChange:n,valueImmutable:d,defaultLocale:x,allComponents:u,...m}){var c,i,p,h,S;const{locale:k}=_.useLocaleContext(),j=z.useUploader(),g=I.useRef(null),f=()=>{var v;const a=(v=j==null?void 0:j.current)==null?void 0:v.getUploader();a==null||a.open(),g.current&&a.onceUploadSuccess(({response:b})=>{var C,y;let w=((C=b==null?void 0:b.data)==null?void 0:C.filename)||"";w&&(w=`mediakit://${w}`,o&&!o.includes("mediakit://")&&(w+=" # please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address")),(y=g.current)==null||y.call(g,w)})},l=m.label||((i=(c=s.locales)==null?void 0:c[k])==null?void 0:i.name)||((h=(p=s.locales)==null?void 0:p[x])==null?void 0:h.name)||s.key||s.id;if(s.type==="number")return t.jsx(Yt,{...m,label:l,NumberProps:{value:["number","string"].includes(typeof o)?o:null,onChange:(a,v)=>n==null?void 0:n(v)}});if(s.type==="decimal")return t.jsx(r.TextField,{...m,label:l,type:"text",value:o??"",onChange:a=>{const v=a.target.value;if(v===""||v==="-"){n==null||n(v);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(v)){let w=v;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(w)&&(w=Number(w)),n==null||n(w)}}});if(s.type==="boolean")return t.jsx(r.FormControlLabel,{label:l,labelPlacement:"start",control:t.jsx(r.Switch,{checked:o===!0,onChange:(a,v)=>n==null?void 0:n(v)})});if(s.type==="color")return t.jsx(Vt,{label:l,value:o,onChange:a=>{n==null||n(a)}});if(s.type==="json"||s.type==="yaml")return t.jsx(qt,{label:l,value:o,onChange:a=>{n==null||n(a)},property:s,component:e,defaultLocale:x,allComponents:u,PropertyValueField:W,onUpload:a=>{g.current=a,f()}});if(s.type==="custom"){const a=(S=u[s.componentId])==null?void 0:S.data;return a?t.jsx(r.Box,{width:"100%",children:t.jsx(Z.CustomComponentRenderer,{componentId:a.id,props:{label:l,value:o,onChange:n},locale:k,dev:{mode:"draft",components:u,defaultLocale:x}})}):t.jsx(r.TextField,{...m,label:l,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(te,{allComponents:u,label:l,value:o==null?void 0:o.componentId,onChange:(a,v)=>{d||!o?n==null||n({...o&&JSON.parse(JSON.stringify(o)),componentId:v}):typeof o=="object"&&(o.componentId=v)}}),(o==null?void 0:o.componentId)&&t.jsx(Ht,{value:o,valueImmutable:d,onChange:n,defaultLocale:x,allComponents:u})]});if(!s.type||["string","url"].includes(s.type)){const a=s.type==="string"?s.multiline:void 0,v=s.type==="url"?o==null?void 0:o.url:o;return t.jsx(r.TextField,{...m,label:l,value:typeof v=="string"?v:"",multiline:a,minRows:a?2:void 0,maxRows:a?10:void 0,onChange:b=>n==null?void 0:n(s.type==="url"?{...o,url:b.target.value,mediaKitUrl:b.target.value}:b.target.value),InputProps:s.type==="url"?{sx:{pr:0},endAdornment:t.jsxs(r.InputAdornment,{position:"end",children:[t.jsx(z.UploaderButton,{onChange:async({response:b})=>{var P,B,O;const w=((P=b==null?void 0:b.data)==null?void 0:P.url)||((B=b==null?void 0:b.data)==null?void 0:B.fileUrl);let C;w&&(C=await z.getImageSize(w).catch(()=>z.getVideoSize(w)).catch(()=>{}));let y=((O=b==null?void 0:b.data)==null?void 0:O.filename)||"";y&&(y=`mediakit://${y}`),n==null||n({url:w,mediaKitUrl:y,width:C==null?void 0:C.naturalWidth,height:C==null?void 0:C.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(A.InfoRounded,{sx:{cursor:"default"},fontSize:"small"})})]})}:void 0})}return s.type==="array"?t.jsx(Ot,{label:l,value:Array.isArray(o)?o:[],onChange:a=>n==null?void 0:n(a),property:s,renderItem:({item:a,index:v,onChange:b})=>s.subProperties&&Object.keys(s.subProperties).length>0?t.jsx(r.Stack,{gap:1,width:"100%",children:V.default(Object.values(s.subProperties),"index").filter(w=>w.data.visible!==!1).map(({data:w})=>w.key?t.jsx(W,{component:e,property:w,value:a[w.key],onChange:C=>{const y={...a,[w.key]:C};b(y)},size:"small",fullWidth:!0,defaultLocale:x,allComponents:u},w.id):null)},v):t.jsx(r.TextField,{size:m.size,fullWidth:!0,value:a,onChange:w=>b(w.target.value)})}):(console.error("Unsupported property type",s.type),null)}function Yt({NumberProps:e,...s}){const{getInputProps:o}=Pe.unstable_useNumberInput(e),n=o();return t.jsx(r.TextField,{...s,inputProps:n})}const ze=`import React from '@blocklet/pages-kit/builtin/react'
|
|
22
22
|
import { Box } from '@blocklet/pages-kit/builtin/mui/material'
|
|
23
23
|
|
|
24
24
|
export default function () {
|
|
@@ -27,5 +27,5 @@ export default function () {
|
|
|
27
27
|
Hello World
|
|
28
28
|
</Box>
|
|
29
29
|
)
|
|
30
|
-
}`,
|
|
31
|
-
`;function $t({value:
|
|
30
|
+
}`,Ae=`console.log('hello')
|
|
31
|
+
`;function $t({value:e}){const{locale:s}=_.useLocaleContext(),o=ie.useUpdate(),n=M.getYjsValue(e).doc;return I.useEffect(()=>{var d;(d=e.renderer)!=null&&d.script||(n.transact(()=>{e.renderer.script=e.renderer.type==="react-component"?ze:Ae}),o())},[e]),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:t.jsx(le.CodeEditor,{keyId:e.id,locale:s,language:"typescript",value:e.renderer.script||"",onChange:d=>e.renderer.script=d,typeScriptNoValidation:!1},e.id)})}function Gt({value:e}){var g,f,l;const{t:s}=_.useLocaleContext(),o=M.getYjsValue(e).doc,{state:{components:n,config:{defaultLocale:d},resources:x},localState:{currentLocale:u}}=T.useStore(),m=T.useAllComponents(),k=((g=n[e.renderer.componentId])==null?void 0:g.data)??((l=(f=x.components)==null?void 0:f[e.renderer.componentId])==null?void 0:l.component),j=F.usePopupState({variant:"dialog"});return t.jsxs(r.Stack,{gap:1,children:[t.jsx(te,{allComponents:m,excludes:[e.id],value:e.renderer.componentId,onChange:(c,i)=>e.renderer.componentId=i}),k&&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},...F.bindTrigger(j),children:t.jsx(A.TranslateRounded,{fontSize:"small"})})]}),k.properties&&V.default(Object.values(k.properties),"index").map(({data:c})=>{var i,p,h,S,a,v,b,w,C,y,P,B,O,q,N,E;return t.jsx(r.Box,{children:t.jsx(W,{allComponents:m,defaultLocale:d,component:k,property:c,fullWidth:!0,size:"small",valueImmutable:ee.default((S=(h=(p=(i=e.renderer.properties)==null?void 0:i[c.id])==null?void 0:p.locales)==null?void 0:h[u])==null?void 0:S.value),value:((w=(b=(v=(a=e.renderer.properties)==null?void 0:a[c.id])==null?void 0:v.locales)==null?void 0:b[u])==null?void 0:w.value)??((B=(P=(y=(C=e.renderer.properties)==null?void 0:C[c.id])==null?void 0:y.locales)==null?void 0:P[d])==null?void 0:B.value)??((q=(O=c.locales)==null?void 0:O[u])==null?void 0:q.defaultValue)??((E=(N=c.locales)==null?void 0:N[d])==null?void 0:E.defaultValue),onChange:Q=>{o.transact(()=>{var L,H,J,Y,$;(L=e.renderer).properties??(L.properties={}),(H=e.renderer.properties)[J=c.id]??(H[J]={}),(Y=e.renderer.properties[c.id]).locales??(Y.locales={}),($=e.renderer.properties[c.id].locales)[u]??($[u]={}),e.renderer.properties[c.id].locales[u].value=Q})}})},c.id)}),t.jsx(De,{...F.bindDialog(j),component:e,type:"parameters"})]})]})}function te({label:e,options:s,excludes:o,value:n,onChange:d,allComponents:x,...u}){var g;const{t:m}=_.useLocaleContext(),k=s??V.default(Object.values(wt.default(x,...o??[])),"index").map(f=>f.data),j=(typeof n=="string"?(g=x[n])==null?void 0:g.data:void 0)??null;return t.jsx(r.Autocomplete,{...u,size:"small",options:k,autoHighlight:!0,isOptionEqualToValue:(f,l)=>f.id===l.id,getOptionKey:f=>f.id,getOptionLabel:f=>f.name||f.id,renderInput:f=>t.jsx(r.TextField,{label:e||m("component"),...f}),value:j,onChange:(f,l)=>{var i,p,h,S,a,v;let c={};l&&(c={blockletId:(i=x[l==null?void 0:l.id])==null?void 0:i.blockletId,blockletTitle:(p=x[l==null?void 0:l.id])==null?void 0:p.blockletTitle,componentName:((S=(h=x[l==null?void 0:l.id])==null?void 0:h.data)==null?void 0:S.name)||((v=(a=x[l==null?void 0:l.id])==null?void 0:a.data)==null?void 0:v.id)}),d==null||d(f,l==null?void 0:l.id,c)}})}function ce({config:e,allComponents:s,defaultLocale:o,propertiesValue:n,currentLocale:d,onChange:x,props:u}){const{t:m}=_.useLocaleContext(),[k,j]=I.useState(e==null?void 0:e.properties),[g,f]=I.useState(null);I.useEffect(()=>{(()=>{var S,a;((S=e==null?void 0:e.renderer)==null?void 0:S.type)==="react-component"&&Ie.default(e==null?void 0:e.properties)?Z.transpileAndLoadScript((a=e==null?void 0:e.renderer)==null?void 0:a.script).then(v=>{const b=Z.getPropertiesFromCode(v);j(b)}):j(e==null?void 0:e.properties)})()},[JSON.stringify(e)]);const l=I.useCallback(()=>!e||!k?{}:Object.values(k).reduce((h,{data:S})=>{var v,b,w,C,y;const a=S.key||S.id;return h[S.id]={key:a,value:(u==null?void 0:u[a])??((v=n==null?void 0:n[S.id])==null?void 0:v.value)??((w=(b=S.locales)==null?void 0:b[d])==null?void 0:w.defaultValue)??((y=(C=S.locales)==null?void 0:C[o])==null?void 0:y.defaultValue),id:S.id,type:S.type},h},{}),[JSON.stringify(k),e,n,d,o]),c=I.useMemo(()=>{if(!k)return{canUseProperties:[],visibleProperties:[],canUsePropertiesKeys:[]};const h=V.default(Object.values(k),"index"),S=h.filter(({data:b})=>b.key&&Te(k,b.id)),a=h.filter(({data:b})=>b.key&&b.type!=="component"),v=a.map(({data:b})=>b.key);return{canUseProperties:a,visibleProperties:S,canUsePropertiesKeys:v}},[JSON.stringify(k)]),i=l(),p=St.default(i,"key");return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(r.Typography,{variant:"subtitle1",children:m("maker.properties.parameters")}),!e||c.canUsePropertiesKeys.length===0?t.jsx(G.default,{style:{fontSize:12},children:m("maker.properties.noParameters")}):t.jsxs(t.Fragment,{children:[t.jsx(r.Stack,{gap:2,children:c.visibleProperties.map(({data:h})=>{var S,a;return t.jsx(r.Box,{children:t.jsx(W,{allComponents:s,defaultLocale:o,size:"small",fullWidth:!0,component:e,property:h,valueImmutable:ee.default((S=n==null?void 0:n[h.id])==null?void 0:S.value),value:(u==null?void 0:u[h.key||h.id])??((a=i[h.id])==null?void 0:a.value),onChange:v=>{x({path:["properties",h.id],id:h.id,value:{value:v},shouldSync:!(!h.type||Se.includes(h.type)),excludeKeys:[],key:h.key||h.id})}})},h.id)})}),t.jsx(r.Stack,{gap:2,sx:{width:"100%"},children:t.jsx(Z.CustomComponentRenderer,{componentId:(e==null?void 0:e.id)||"",renderType:"setting",locale:d,properties:i,dev:{mode:"draft",components:s,defaultLocale:o},props:{...Pt.default(u??{},c.canUsePropertiesKeys),onChange:h=>{const{canUsePropertiesKeys:S}=c;Object.keys(h).filter(v=>{var b;return h[v]!==((b=p==null?void 0:p[v])==null?void 0:b.value)}).filter(v=>{var b;return!(v==="locale"&&!vt.default(p[v],"locale")||((b=p[v])==null?void 0:b.type)==="component")}).reduce((v,b)=>v.then(()=>{const w=p[b],C=S.includes(b);if(w!=null&&w.id&&C)return x({path:["properties",w.id],id:w.id,value:{value:h[b]},shouldSync:!(!w.type||Se.includes(w.type)),excludeKeys:[],key:w.key||w.id}),Promise.resolve();const y=`propertyNotFound${b}`;if(g===y)return Promise.resolve();ke.default.close(g);const P=ke.default.warning(m("maker.properties.propertyNotFound",{key:b}),{key:y});return f(P),Promise.resolve()}),Promise.resolve())}}})})]})]})})}exports.BasicInfo=Oe;exports.CustomComponentAutocomplete=te;exports.CustomComponentSettings=Wt;exports.DefaultReactComponentScriptTemplate=ze;exports.DefaultWebComponentScriptTemplate=Ae;exports.ParametersConfig=ce;exports.PropertiesConfig=_e;exports.PropertyValueField=W;
|