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