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