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