@blocklet/pages-kit-inner-components 0.6.20 → 0.6.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),r=require("@mui/material"),_=require("./chunks/state-tEydRMV8.js"),ge=require("@arcblock/ux/lib/Empty"),O=require("@arcblock/ux/lib/Locale/context"),ee=require("@blocklet/code-editor"),ye=require("@mui/icons-material/AddRounded"),Ce=require("@mui/icons-material/ArrowDownward"),ve=require("@mui/icons-material/ArrowUpward"),ke=require("@mui/icons-material/DeleteOutline"),Pe=require("lodash/sortBy"),v=require("react"),te=require("react-use"),se=require("@blocklet/pages-kit/builtin/color-picker"),N=require("@blocklet/pages-kit/builtin/uploader"),Se=require("@iconify-icon/react"),we=require("lodash/isEmpty"),Ie=require("lodash/set"),Te=require("yaml"),Be=require("lodash/cloneDeep"),Oe=require("@arcblock/ux/lib/Toast"),K=require("@blocklet/pages-kit/components"),Re=require("@blocklet/pages-kit/utils/property"),ie=require("@mui/base"),V=require("@mui/icons-material"),L=require("@syncedstore/core"),le=require("ahooks"),Ne=require("lodash/assign"),Ve=require("lodash/get"),_e=require("lodash/has"),ze=require("lodash/isEqual"),Ee=require("lodash/isNil"),Ae=require("lodash/isObject"),De=require("lodash/keyBy"),Fe=require("lodash/omit"),qe=require("lodash/pick"),Le=require("lodash/reduce"),A=require("material-ui-popup-state/hooks"),Ue=require("react-error-boundary"),Me=require("@emotion/css"),$=require("react-dnd"),ae=require("@blocklet/pages-kit/utils/common"),T=t=>t&&t.__esModule?t:{default:t};function We(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 U=T(ge),Ke=T(ye),Je=T(Ce),He=T(ve),Ye=T(ke),z=T(Pe),D=T(we),ce=T(Ie),G=We(Te),$e=T(Be),Q=T(Oe),Ge=T(Ne),Qe=T(Ve),Xe=T(_e),Ze=T(ze),J=T(Ee),et=T(Ae),tt=T(De),rt=T(Fe),st=T(qe),nt=T(Le);function ot({error:t}){return e.jsx(r.Box,{children:e.jsx(r.Alert,{severity:"error",children:t.message})})}function it({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(Ye.default,{fontSize:"small"})})}function lt({onClick:t,disabled:s,sx:i,...l}){return e.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:t,...l,children:e.jsx(He.default,{fontSize:"small"})})}function at({onClick:t,disabled:s,sx:i,...l}){return e.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:t,...l,children:e.jsx(Je.default,{fontSize:"small"})})}function ct({label:t,value:s,onChange:i,disabled:l=!1,itemLabel:f="",emptyHeight:x=40,property:d,renderItem:b,...m}){const{t:u,locale:a}=O.useLocaleContext(),c=te.useUpdate(),o=v.useCallback(g=>{i(_.transformValue(g,d.type))},[i,d.type]),n=v.useMemo(()=>Array.isArray(s)?s:[],[s]),h=v.useCallback(()=>{const g=[...n,""];o(g),c()},[n,o,c]),j=v.useCallback(()=>{if(!d||!d.subProperties)return h();const g={};z.default(Object.values(d.subProperties),"index").forEach(({data:R})=>{if(!R.key)return;const E=R.locales?.[a]?.defaultValue??"";g[R.key]=E});const w=[...n,g];o(w),c()},[n,o,c,d,a,h]),p=v.useCallback(g=>{try{const C=JSON.parse(g);Array.isArray(C)?o(C):console.error("JSON解析结果不是数组")}catch(C){console.error("JSON解析错误:",C)}},[o]),y=v.useCallback(g=>{const C=n.filter((w,R)=>R!==g);o(C),c()},[n,o,c]),P=v.useCallback(g=>{if(g<=0)return;const C=[...n],w=C[g];C[g]=C[g-1],C[g-1]=w,o(C),c()},[n,o,c]),I=v.useCallback(g=>{if(g>=n.length-1)return;const C=[...n],w=C[g];C[g]=C[g+1],C[g+1]=w,o(C),c()},[n,o,c]),S=v.useCallback((g,C)=>{const w=[...n];w[g]=C,o(w)},[n,o]),k=d&&d.subProperties&&Object.keys(d.subProperties).length>0,B=v.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:g})=>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:g+1})},{field:"content",headerName:"",renderCell:({row:g,index:C})=>b&&k?b({item:g,index:C,property:d,onChange:w=>S(C,w)}):e.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:l,value:g,placeholder:f||`${u("item")} ${C+1}`,onChange:w=>S(C,w.target.value),...m})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:g})=>e.jsxs(r.Stack,{direction:"column",spacing:.25,children:[e.jsx(lt,{disabled:l||g===0,onClick:()=>P(g)}),e.jsx(at,{disabled:l||g===n.length-1,onClick:()=>I(g)}),e.jsx(it,{disabled:l,onClick:()=>y(g)})]})}],[b,k,d,S,f,u,l,m,y,P,I,n.length]);return k?e.jsxs(r.Stack,{sx:{width:"100%",gap:1},children:[t&&e.jsx(r.FormLabel,{children:t}),n.length>0?e.jsx(r.TableContainer,{component:r.Paper,variant:"outlined",sx:{borderRadius:1,mb:1},children:e.jsxs(r.Table,{size:"small",sx:{"& .MuiTableCell-root":{py:.25,px:1,whiteSpace:"nowrap"},"& .MuiTableCell-head":{backgroundColor:"action.hover",py:.25,px:1},borderCollapse:"collapse"},children:[e.jsx(r.TableHead,{sx:{display:"none"},children:e.jsx(r.TableRow,{children:B.map(g=>e.jsx(r.TableCell,{width:g.width,align:g.align||"left",sx:{fontWeight:"bold"},children:g.renderHeader?g.renderHeader():g.headerName},g.field))})}),e.jsx(r.TableBody,{children:n.map((g,C,w)=>e.jsx(r.TableRow,{sx:{borderBottom:C<w.length-1?"1px solid":"none",borderColor:"divider","&:hover":{backgroundColor:"action.hover"}},children:B.map(R=>e.jsx(r.TableCell,{width:R.width,align:R.align||"left",sx:{borderBottom:"none"},children:R.renderCell({row:g,index:C,onChange:E=>S(C,E)})},`${C}-${R.field}`))},C))})]})}):e.jsx(U.default,{style:{fontSize:12,height:x},children:u("maker.properties.arrayEmpty")}),e.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:l,startIcon:e.jsx(Ke.default,{}),onClick:j,children:u("maker.properties.addArrayItem")})]}):e.jsxs(r.Stack,{sx:{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(ee.CodeEditor,{keyId:d.id,locale:a,language:"json",value:JSON.stringify(n,null,2),onChange:g=>p(g||""),fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},d.id)})]})}function ut({ref:t,showMarkdown:s,markdown:i,onMarkdownChange:l,showUploader:f,value:x,meta:d,onChange:b,...m}){const[u,a]=v.useState("");v.useEffect(()=>{a(x||"")},[x,a]);const c=async()=>{if(u!==x){const n=_.getImageAbsoluteUrl(u);if(!n){b(u,void 0);return}const h=await N.getImageSize(n).catch(()=>N.getVideoSize(n)).catch(()=>{});b(u,{...h,filename:u})}};te.useDebounce(()=>{u!==x&&b(u)},300,[u]),v.useImperativeHandle(t,()=>({submit:c}));const o={};return f&&(o.InputProps={sx:{pr:0},endAdornment:e.jsx(r.InputAdornment,{position:"end",sx:{mx:.5},children:e.jsx(N.UploaderButton,{onChange:async({response:n})=>{const h=n?.data?.filename,j=_.getImageAbsoluteUrl(h)||"";let p={};j&&(p=await N.getImageSize(j).catch(()=>N.getVideoSize(j)).catch(()=>{})),b(h,{...p,filename:h})}})})}),e.jsx(r.TextField,{size:"small",fullWidth:!0,...m,label:e.jsxs(r.Stack,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[m.label,s&&e.jsxs(e.Fragment,{children:[" (",e.jsx(r.FormControlLabel,{checked:i,label:e.jsx(r.Box,{component:Se.Icon,icon:"tabler:markdown",sx:{verticalAlign:"middle"}}),labelPlacement:"start",control:e.jsx(r.Switch,{size:"small"}),sx:{ml:.25,pr:1},onChange:(n,h)=>l?.(h)}),")"]})]}),value:u,onChange:n=>a(n.target.value),...o,onKeyDown:n=>{n.keyCode!==229&&n.key==="Enter"&&c()},slotProps:{inputLabel:{shrink:!0,...m.InputLabelProps}}})}function dt({value:t,onChange:s,...i}){const l=v.useRef(null);return e.jsxs(e.Fragment,{children:[e.jsx(ut,{...i,value:t,onChange:s,InputProps:{endAdornment:e.jsx(r.InputAdornment,{position:"end",children:e.jsx(se.ColorItem,{color:t??"",style:{width:"1.5rem",height:"1.5rem",padding:0},onClick:()=>{l.current?.open({value:t??""})}})})}}),e.jsx(se.ConfigColorDialog,{ref:l,onSave:({value:f},x)=>{s(f),x()}})]})}function pt({label:t,value:s,onChange:i,property:l,component:f,defaultLocale:x,allComponents:d,PropertyValueField:b,onUpload:m}){const{locale:u}=O.useLocaleContext(),a=v.useRef(null);if(!D.default(l.subProperties)){const o=z.default(Object.values(l.subProperties||{}),"index").filter(n=>n.data.visible!==!1&&n.data.key);return e.jsxs(r.Stack,{sx:{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((n,h)=>{const{data:j}=n,p=j.key??j.id,y=h===o.length-1;let P=null;try{s&&typeof s=="object"?P=s[p]:typeof s=="string"&&(P=(l.type==="yaml"?G.parse(s||""):JSON.parse(s||"{}"))[p])}catch{}P==null&&(j.locales&&u&&j.locales[u]?P=j.locales[u].defaultValue:j.locales&&x&&j.locales[x]&&(P=j.locales[x].defaultValue));const I=k=>{try{let B={};if(typeof s=="string")try{B=l.type==="yaml"?G.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(B={...s});ce.default(B,p,k);const g=_.transformValue(B,l.type);i?.(g)}catch(B){console.error("Error updating property:",B)}},S=8;return e.jsxs(r.Box,{sx:{mb:y?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:S,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),e.jsx(r.Box,{sx:{position:"absolute",left:S,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!y&&e.jsx(r.Box,{sx:{position:"absolute",left:S,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),e.jsx(r.Box,{sx:{flexGrow:1},children:e.jsx(b,{component:f,property:j,value:P,onChange:I,size:"small",fullWidth:!0,defaultLocale:x,allComponents:d})})]},j.id)})})})]})}return e.jsx(r.Stack,{sx:{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(ee.CodeEditor,{keyId:l.id,locale:u,language:l.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:o=>{i?.(o)},onUpload:o=>{a.current=o,m&&m(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 xt=["string","multiline","json","yaml","url","component","custom","array"];function ne(t){return t.type?!xt.includes(t.type):!1}function ue({disabled:t,list:s,renderItem:i,...l}){const f=v.useRef(null),x=v.useId(),d=le.useUpdate(),b=z.default(Object.entries(s),n=>n[1].index).map(n=>n[0]),m=v.useRef(b),u=v.useCallback(n=>{m.current=n,d()},[d]),a=v.useCallback(({index:n},{index:h})=>{const j=[...m.current];j.splice(h,0,...j.splice(n,1)),u(j)},[u]);v.useEffect(()=>{u(b)},[b.join("-")]);const[{isOver:c},o]=$.useDrop({accept:x,collect:n=>({isOver:n.isOver()}),canDrop:()=>!t,drop:()=>{const n=()=>{m.current.forEach((j,p)=>{const y=s[j];y&&(y.index=p)})},h=L.getYjsValue(s)?.doc;h?h.transact(()=>{n()}):n()}});return v.useEffect(()=>{c||u(b)},[c]),o(f),e.jsx(r.Box,{...l,ref:f,className:Me.cx(c&&"isDragging"),children:m.current.map((n,h)=>e.jsx(mt,{type:x,disabled:t,id:n,index:h,itemIndex:j=>m.current.indexOf(j),move:a,children:j=>{const p=s[n];return p?i(p.data,h,j):null}},n))})}function mt({disabled:t,id:s,index:i,type:l,children:f,itemIndex:x,move:d}){const b=v.useRef(void 0),[{isDragging:m},u,a]=$.useDrag({type:l,item:()=>({id:s}),canDrag:()=>!t,collect:o=>({isDragging:o.isDragging()})}),[,c]=$.useDrop({accept:l,canDrop:()=>!t,hover(o,n){if(!b.current)return;const h=x(o.id),j=i;if(h===j)return;const p=b.current?.getBoundingClientRect(),y=(p.bottom-p.top)/2,I=n.getClientOffset().y-p.top;h<j&&I<y||h>j&&I>y||d({id:o.id,index:h},{id:s,index:i})}});return typeof f=="function"?f({isDragging:m,drag:u,drop:o=>(b.current=o,c(o)),preview:a}):(u(c(a(b))),e.jsx(r.Box,{ref:b,children:f}))}function ft({drop:t,preview:s,drag:i,disabled:l,isDragging:f,children:x,onDelete:d,onVisibilityChange:b,visible:m=!0,actions:u,alwaysShowActions:a=!1}){const{t:c}=O.useLocaleContext();return e.jsx(r.Box,{ref:t,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:m?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:x}),!l&&e.jsx(r.Box,{className:a?"":"hover-visible",sx:{maxWidth:a?"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:[u,b&&e.jsx(r.Tooltip,{title:c(m?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{onClick:()=>b(!m),children:m?e.jsx(V.VisibilityOffRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}}):e.jsx(V.VisibilityRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),d&&e.jsx(r.Tooltip,{title:c("delete"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{onClick:d,children:e.jsx(V.DeleteOutlineRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),e.jsx(r.Tooltip,{title:c("dragSort"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{ref:i,children:e.jsx(V.DragIndicatorRounded,{sx:{color:"grey.500"}})})})]})})]})})}function ht(t){const s=["string","json","array","url","multiline"],i=["style","fontSize","color","content","type"];return!!(s.includes(t.type||"")&&!i.includes(t.key||""))}function bt(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 de=(t,s,i,l)=>{const f={};return z.default(Object.entries(t),([,d])=>d.index).forEach(([d,b])=>{const m=b.data;if(!m)return;const u=m.key||m.id,a=i?bt(m,i,l||""):u,c=s?.[m.id],o={key:u,isNeedGenerate:c?.isNeedGenerate??ht(m),describe:c?.describe??"",displayName:a};m.subProperties&&!D.default(m.subProperties)&&(o.subProperties=de(m.subProperties,c?.subProperties,i,l)),f[m.id]=o}),f};function jt({open:t,onClose:s,onConfirm:i,component:l,initialConfig:f,locale:x,defaultLocale:d,title:b,loading:m=!1}){const{t:u}=O.useLocaleContext(),[a,c]=v.useState(null);v.useEffect(()=>{if(t&&l){const p={properties:{}};if(l.properties){const y=f?.properties;p.properties=de(l.properties,y,x,d)}c(p)}},[t,l,f,x,d]);const o=()=>{s()},n=()=>{a&&(i(a),s())},h=(p,y,P)=>{if(!a||!p.length)return;const I=JSON.parse(JSON.stringify(a));let S=I.properties,k=null;for(let g=0;g<p.length-1;g++){const C=p[g];if(!C||!S[C])return;k=S;const w=S[C];w.subProperties||(w.subProperties={}),S=w.subProperties}const B=p[p.length-1];if(B){if("isNeedGenerate"in P){const g=P.isNeedGenerate,C={...y,...P};if(y.subProperties&&!D.default(y.subProperties)){const w=(R,E)=>{const q={};return Object.entries(R).forEach(([je,M])=>{const Y={...M};E!==null&&(Y.isNeedGenerate=E),M.subProperties&&!D.default(M.subProperties)&&(Y.subProperties=w(M.subProperties,E!==null?E:null)),q[je]=Y}),q};C.subProperties=w(y.subProperties,g===!1?!1:null)}if(p.length===1)I.properties[B]=C;else if(k&&p.length>=2){const w=p[p.length-2];w&&k[w]&&(k[w].subProperties||(k[w].subProperties={}),k[w].subProperties[B]=C)}}else if(p.length===1)I.properties[B]={...y,...P};else if(k&&p.length>=2){const g=p[p.length-2];g&&k[g]&&k[g].subProperties&&(k[g].subProperties[B]={...y,...P})}c(I)}},j=(p,y=[],P=!0)=>{if(!p||D.default(p))return e.jsx(U.default,{children:u("maker.properties.noProperties")});const I=z.default(Object.entries(p),([,S])=>S.displayName);return e.jsx(r.Stack,{spacing:1.5,children:I.map(([S,k],B)=>{const g=[...y,S],C=B===I.length-1,w=k.subProperties&&!D.default(k.subProperties),R=k.displayName||S,E=!P;return e.jsx(r.Box,{sx:{position:"relative"},children:e.jsxs(r.Stack,{direction:"row",children:[y.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"}}),!C&&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"},spacing:1.5,sx:{alignItems:{xs:"flex-start",md:"center"},width:"100%"},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:k.isNeedGenerate,disabled:E,onChange:q=>{h(g,k,{isNeedGenerate:q.target.checked})}}),label:R,sx:{minWidth:"180px",maxWidth:"280px",mr:2,"& .MuiFormControlLabel-label":{wordBreak:"break-word"}}}),e.jsx(r.TextField,{size:"small",fullWidth:!0,label:u("maker.properties.llmPropertyDescribe"),value:k.describe,onChange:q=>{h(g,k,{describe:q.target.value})},disabled:!k.isNeedGenerate})]}),w&&e.jsx(r.Box,{sx:{ml:3},children:j(k.subProperties,g,k.isNeedGenerate&&P)})]})]})},S)})})};return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"lg",fullWidth:!0,children:[e.jsx(r.DialogTitle,{children:b||u("maker.properties.llmConfigTitle")}),e.jsx(r.DialogContent,{children:e.jsx(r.Box,{sx:{my:3},children:m?e.jsx(r.Typography,{children:u("maker.properties.loading")}):l?a?e.jsxs(r.Stack,{spacing:3,children:[e.jsx(r.Typography,{variant:"subtitle2",children:u("maker.properties.llmConfigInstructions")}),j(a.properties)]}):e.jsx(r.Typography,{children:u("maker.properties.loading")}):e.jsx(r.Typography,{color:"error",children:u("maker.properties.componentNotFound")})})}),e.jsxs(r.DialogActions,{children:[e.jsx(r.Button,{onClick:o,children:u("common.cancel")}),e.jsx(r.Button,{variant:"contained",onClick:n,disabled:!a||m,children:u("common.confirm")})]})]})}function gt({label:t,value:s,onChange:i}){const[l,f]=v.useState(!1);return e.jsxs(r.Stack,{sx:{gap:1},children:[e.jsx(r.TextField,{label:t,size:"small",value:s,onChange:x=>i?.(x.target.value),slotProps:{input:{sx:{pr:0},endAdornment:e.jsx(r.InputAdornment,{position:"end",children:e.jsx(N.UploaderButton,{onChange:({response:x})=>{const d=x?.data?.filename;d&&i?.(d)}})})}}}),s&&e.jsx(r.Box,{component:"img",src:_.getImageAbsoluteUrl(s),alt:t,onClick:()=>f(!0),sx:{maxWidth:100,maxHeight:100,width:"100%",objectFit:"contain",borderRadius:1,cursor:"pointer"}}),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 X(t,s=""){return nt.default(t,(i,l,f)=>{const x=s?`${s}.${f}`:f;return et.default(l)?Ge.default(i,X(l,x)):i[x]=l,i},{})}const yt=[{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 W(t,s,i){return!t||!i?!1:Object.values(t).some(({data:l})=>l.id!==s&&l.key===i)}function Z(t,s){return!t||!s?!1:t[s]?.data.visible??!0}function Ct({componentId:t}){const{state:{components:s}}=_.useStore(),l=s[t]?.data;return l?e.jsx(r.Stack,{sx:{maxHeight:"100%",overflow:"auto"},children:e.jsx(r.Box,{sx:{p:2},children:e.jsx(Ue.ErrorBoundary,{FallbackComponent:ot,resetKeys:[t],children:e.jsx(vt,{value:l,componentId:t})})})}):null}function vt({value:t,componentId:s}){const{t:i}=O.useLocaleContext(),{localState:{currentLocale:l,customComponentPreviewerProperties:f},state:{config:{defaultLocale:x}},localActions:{setCustomComponentPreviewerProperties:d}}=_.useStore(),b=L.getYjsValue(t).doc,m=_.useAllComponents(),u=v.useMemo(()=>f?.[s]??{},[s,f]),a=le.useReactive({componentId:s,propertiesValue:{...u}});return v.useEffect(()=>{a.componentId!==s&&(a.componentId=s,a.propertiesValue={...u})},[s,u,a]),v.useEffect(()=>{if(a.componentId!==s)return;const c=Object.fromEntries(Object.values(t.properties??{}).map(({data:o})=>[o.id,{value:a.propertiesValue[o.id]?.value??Re.parsePropertyValue(o,o.locales?.[l]?.defaultValue??o.locales?.[x]?.defaultValue,{locale:l,defaultLocale:x})}]));d(s,c)},[JSON.stringify(a.propertiesValue),s,a.componentId]),e.jsx(r.Stack,{sx:{height:"100%"},children:e.jsxs(r.Stack,{sx:{gap:2},children:[e.jsx(pe,{config:t}),e.jsx(me,{config:t,currentLocale:l,defaultLocale:x,allComponents:m,onUpdateConfig:c=>{b.transact(()=>{c(t)})}}),e.jsxs(r.Stack,{direction:"row",sx:{gap:2,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,value:t.renderer?.type||"react-component",onChange:c=>{b.transact(()=>{const o=c.target.value;t.renderer??={type:o},t.renderer.type=o})},slotProps:{select:{autoWidth:!0}},children:[e.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),e.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),t.renderer?.type==="component"&&e.jsx(Bt,{value:t}),t.renderer?.type==="react-component"&&e.jsx(Tt,{value:t}),e.jsx(re,{config:t,currentLocale:l,defaultLocale:x,allComponents:m,propertiesValue:a.propertiesValue,onChange:({value:c,id:o,path:n})=>{const h=[...n,"data"];if(!Qe.default(t,h)){Q.default.warning(i("cannotFindPropertyKey",{key:h.join(".")}));return}a.propertiesValue[o]={value:c.value}}})]})})}function pe({config:t}){const{t:s}=O.useLocaleContext();return e.jsx(N.UploaderProvider,{children:e.jsxs(r.Stack,{sx:{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,value:t.description||"",onChange:i=>t.description=i.target.value,slotProps:{input:{endAdornment:e.jsx(r.InputAdornment,{position:"end",sx:{mt:-1.5},children:e.jsx(Ot,{config:t})})},htmlInput:{maxLength:200}}}),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(gt,{label:s("previewImage"),value:t.previewImage||"",onChange:i=>t.previewImage=i})]})})}function xe({data:t,params:s,visible:i,config:l,currentLocale:f,defaultLocale:x,allComponents:d,onUpdateConfig:b}){const{t:m}=O.useLocaleContext(),u=v.useMemo(()=>t.type==="json"||t.type==="yaml"||t.type==="array"?wt:F,[t.type]);return e.jsx(ft,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{b(a=>{if(a.properties){const o=Object.entries(a.properties).sort(([,h],[,j])=>h.index-j.index);delete a.properties[t.id],o.filter(([h])=>h!==t.id).forEach(([,h],j)=>{h.index=j})}})},visible:i,onVisibilityChange:a=>{b(c=>{const o=c.properties[t.id].data;o.visible=a})},alwaysShowActions:!0,children:e.jsxs(r.Stack,{direction:"column",sx:{gap:2},children:[e.jsx(r.TextField,{label:m("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:t.key?W(l.properties,t.id,t.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:t.key?W(l.properties,t.id,t.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:t.key?W(l.properties,t.id,t.key)?"warning.main":"primary.main":"error.main"}},value:t.key||"",onChange:a=>{b(c=>{const o=c.properties[t.id].data;o.key=a.target.value.trim()})},slotProps:{input:{endAdornment:!t.key||t.key&&W(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?m("duplicateKey"):m("requiredKey"),children:e.jsx(V.InfoRounded,{sx:{color:t.key?"warning.main":"error.main",fontSize:16}})})}):null}}}),e.jsxs(r.Stack,{direction:"row",sx:{gap:1},children:[e.jsx(r.TextField,{label:m("label"),size:"small",sx:{flex:1},value:(t.locales?.[f]?.name??t.locales?.[x]?.name)||"",onChange:a=>{b(c=>{const o=c.properties[t.id].data;o.locales??={},o.locales[f]??={},o.locales[f].name=a.target.value})}}),e.jsx(r.TextField,{label:m("type"),size:"small",select:!0,sx:{flex:1},value:t.type==="string"&&t.multiline?"multiline":t.type||"string",onChange:a=>{b(c=>{const o=c.properties[t.id].data;if(o.locales)for(const h of Object.keys(o.locales))o.locales[h].defaultValue=void 0;const n=a.target.value;n==="multiline"?(o.type="string",o.multiline=!0):(typeof o.multiline<"u"&&delete o.multiline,o.type=n)})},children:yt.map(a=>e.jsx(r.MenuItem,{value:a.value,children:a.label},a.value))})]}),e.jsxs(r.Stack,{direction:"row",sx:{gap:1},children:[e.jsx(u,{allComponents:d,defaultLocale:x,component:l,property:t,label:m("defaultValue"),size:"small",fullWidth:!0,value:t.locales?.[f]?.defaultValue,onChange:(a,c)=>{b(o=>{const n=o.properties[t.id].data;if(c?.forceUpdateProperty){const h=X(n),j=X(a);Object.keys(j).forEach(p=>{h[p]||ce.default(n,p,j[p])})}else n.locales??={},n.locales[f]??={},n.locales[f].defaultValue=a})}}),t.type==="custom"?e.jsx(r.Box,{children:e.jsx(Pt,{property:t,allComponents:d})}):null]})]})})}function kt(t,s){const[i,l]=v.useState(0);return v.useEffect(()=>{const x=setTimeout(()=>{if(t.current){let d=t.current.parentElement,b=0;for(;d;)d.classList.contains("property-container")&&b++,d=d.parentElement;l(b)}},100);return()=>clearTimeout(x)},[t,s]),i}function me({config:t,currentLocale:s,defaultLocale:i,allComponents:l,onUpdateConfig:f,useI18nEditor:x=!0}){const{t:d}=O.useLocaleContext(),b=A.usePopupState({variant:"dialog"}),m=t.properties&&z.default(Object.values(t.properties),"index");return e.jsx(N.UploaderProvider,{children:e.jsxs(r.Stack,{sx:{gap:2},children:[e.jsxs(r.Stack,{direction:"row",sx:{gap:1,alignItems:"center",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"subtitle1",children:d("properties")}),e.jsx(r.Box,{sx:{flex:1}}),x&&e.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...A.bindTrigger(b),children:e.jsx(V.TranslateRounded,{fontSize:"small"})})]}),t.properties&&Object.keys(t.properties).length>0?e.jsx(ue,{component:r.Stack,gap:2,list:t.properties,renderItem:(u,a,c)=>{const o=Z(t.properties,u.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,{sx:{gap:2},children:e.jsx(xe,{data:u,params:c,visible:o,config:t,currentLocale:s,defaultLocale:i,allComponents:l,onUpdateConfig:f})})},u.id)}}):e.jsx(U.default,{style:{fontSize:12},children:d("maker.properties.noProperties")}),e.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",onClick:()=>{f(u=>{const a=ae.nextId();u.properties??={},u.properties[a]??={index:m?.length||0,data:{id:a}}})},startIcon:e.jsx(V.AddRounded,{}),children:d("addObject",{object:d("property")})}),x&&e.jsx(fe,{...A.bindDialog(b),component:t})]})})}function Pt({property:t,allComponents:s}){const i=A.usePopupState({variant:"popper"});return e.jsxs(e.Fragment,{children:[e.jsx(r.Button,{sx:{minWidth:0},...A.bindTrigger(i),children:e.jsx(V.SettingsRounded,{fontSize:"small"})}),e.jsx(r.Popper,{...A.bindPopper(i),children:e.jsx(ie.ClickAwayListener,{onClickAway:i.close,children:e.jsx(r.Paper,{children:e.jsx(r.Box,{sx:{width:500,p:2},children:e.jsx(H,{value:t.componentId,onChange:(l,f)=>t.componentId=f,allComponents:s})})})})})]})}function St({value:t,valueImmutable:s,onChange:i,defaultLocale:l,allComponents:f}){const[x,d]=v.useState(!1),{t:b,locale:m}=O.useLocaleContext(),u=typeof t?.componentId=="string"?f[t.componentId]?.data:void 0;return u?e.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[e.jsx(r.IconButton,{sx:{minWidth:0},disabled:!u,size:"small",onClick:()=>d(!x),color:x?"primary":"default",children:e.jsx(V.SettingsRounded,{fontSize:"small"})}),x&&e.jsx(r.Collapse,{in:x,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,{sx:{width:"100%",mb:2},children:e.jsx(re,{config:u,currentLocale:m,defaultLocale:l,allComponents:f,propertiesValue:t?.properties,onChange:({id:a,value:c})=>{const o=$e.default(c.value),n=JSON.parse(JSON.stringify(t));n?.componentId&&(s?i?.({...n,properties:{...n.properties,[a]:{value:o}}}):(n.properties=n.properties??{},n.properties[a]={value:o},i?.(n)))}})}),e.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:b("close")})]})})]}):null}function fe({type:t="properties",component:s,...i}){const{t:l}=O.useLocaleContext(),{state:{components:f,supportedLocales:x,config:{defaultLocale:d}}}=_.useStore(),b=_.useAllComponents(),m=L.getYjsValue(s).doc,u=t==="properties"?s.properties:t==="parameters"&&s.renderer?.type==="component"?f[s.renderer.componentId]?.data.properties:void 0,a=s.renderer?.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:u&&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:x.map(({locale:c,name:o})=>e.jsx(r.TableCell,{children:e.jsxs(r.Typography,{sx:{color:"text.primary"},children:[o,d===c&&e.jsx(V.StarRounded,{sx:{fontSize:12}})]})},c))})}),e.jsx(r.TableBody,{children:z.default(Object.values(u),"index").map(({data:c})=>e.jsx(r.TableRow,{children:x.map(({locale:o})=>e.jsx(r.TableCell,{children:e.jsx(r.Stack,{sx:{gap:1},children:t==="properties"?e.jsxs(e.Fragment,{children:[e.jsx(r.TextField,{size:"small",label:"Key",value:c.key||"",onChange:n=>{m.transact(()=>{c.key=n.target.value.trim()})}}),e.jsx(r.TextField,{size:"small",label:l("label"),value:(c.locales?.[o]?.name??c.locales?.[d]?.name)||"",onChange:n=>{m.transact(()=>{c.locales??={},c.locales[o]??={},c.locales[o].name=n.target.value})}}),e.jsx(r.Box,{children:e.jsx(F,{allComponents:b,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:J.default(c.locales?.[o]?.defaultValue),value:c.locales?.[o]?.defaultValue??c.locales?.[d]?.defaultValue,onChange:n=>{m.transact(()=>{c.locales??={},c.locales[o]??={},c.locales[o].defaultValue=n})}})})]}):t==="parameters"&&a?e.jsx(r.Box,{children:e.jsx(F,{allComponents:b,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,valueImmutable:J.default(a.renderer.properties?.[c.id]?.locales?.[o]?.value),value:a.renderer.properties?.[c.id]?.locales?.[o]?.value??a.renderer.properties?.[c.id]?.locales?.[d]?.value??c.locales?.[o]?.defaultValue??c.locales?.[d]?.defaultValue,onChange:n=>{m.transact(()=>{a.renderer.properties??={},a.renderer.properties[c.id]??={},a.renderer.properties[c.id].locales??={},a.renderer.properties[c.id].locales[o]??={},a.renderer.properties[c.id].locales[o].value=n})}})}):null},c.id)},o))},c.id))})]})})}),e.jsx(r.DialogActions,{children:e.jsx(r.Button,{onClick:c=>i.onClose?.(c,"escapeKeyDown"),children:l("close")})})]})}const oe=(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),x=l[f],d=r.alpha(x,.5),b=r.alpha(x,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:b,...s}};function wt({property:t,onChange:s,defaultLocale:i,allComponents:l}){const{t:f,locale:x}=O.useLocaleContext(),d=v.useRef(null),b=kt(d,t),m=v.useCallback(()=>{if(!(t.type!=="json"&&t.type!=="yaml"&&t.type!=="array")&&t.subProperties)try{let u={};z.default(Object.values(t.subProperties),"index").filter(o=>o.data.visible!==!1&&o.data.key).forEach(({data:o})=>{if(!o.key)return;let n=o.locales?.[x]?.defaultValue??o.locales?.[i]?.defaultValue;if(o.type==="number")n=Number(n);else if(o.type==="boolean")n=n===!0||n==="true";else if((o.type==="json"||o.type==="yaml")&&typeof n=="string")try{o.type==="json"?n=JSON.parse(n):n=G.parse(n)}catch(h){console.error("Error parsing nested value",n,h),n={}}u[o.key]=n}),t.type==="array"&&!Array.isArray(u)&&(u=D.default(u)?[]:[u]);const c=_.transformValue(u,t.type);s?.(c)}catch(u){console.error("Error converting structure to text:",u)}},[t,x,i,s]);return t.type!=="json"&&t.type!=="yaml"&&t.type!=="array"?null:e.jsxs(r.Stack,{direction:"column",ref:d,sx:{gap:1.5,width:"100%"},children:[e.jsx(r.Divider,{sx:{mt:-1},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:f("maker.properties.subProperties")})}),t.subProperties&&Object.keys(t.subProperties).length>0?e.jsx(ue,{component:r.Stack,gap:2,list:t.subProperties,renderItem:(u,a,c)=>{const o=u.visible!==!1;return e.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:o?"1px solid":"1px dashed","&":oe(b)},children:e.jsx(r.Stack,{sx:{gap:2},children:e.jsx(xe,{data:u,params:c,visible:o,config:{properties:t.subProperties},currentLocale:x,defaultLocale:i,allComponents:l,onUpdateConfig:n=>{try{const h={properties:t.subProperties||{}};n(h);const j={...t,subProperties:h.properties};s?.(j,{forceUpdateProperty:!0}),m()}catch(h){console.error("Error updating property:",h)}}})})},u.id)}}):e.jsx(U.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(V.AddRounded,{}),onClick:()=>{try{const u=t.subProperties||{},a=ae.nextId(),o={index:Object.values(u).length,data:{id:a,key:"",type:"string",visible:!0,locales:{[x]:{name:"",defaultValue:""}},subProperties:{}}},n={...t,subProperties:{...u,[a]:o}};s?.(n,{forceUpdateProperty:!0}),m()}catch(u){console.error("Error adding property:",u)}},sx:{"&":oe(b,{})},children:f("maker.properties.addSubProperty")})]})}function F({component:t,property:s,value:i,onChange:l,valueImmutable:f,defaultLocale:x,allComponents:d,...b}){const{locale:m}=O.useLocaleContext(),u=N.useUploader(),a=v.useRef(null),c=()=>{const n=u?.current?.getUploader();n?.open(),a.current&&n.onceUploadSuccess(({response:h})=>{let j=h?.data?.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")),a.current?.(j)})},o=b.label??(s.locales?.[m]?.name||s.locales?.[x]?.name||s.key||s.id);if(s.type==="number")return e.jsx(It,{...b,label:o,NumberProps:{value:["number","string"].includes(typeof i)?i:null,onChange:(n,h)=>l?.(h)}});if(s.type==="decimal")return e.jsx(r.TextField,{...b,label:o,type:"text",value:i??"",onChange:n=>{const h=n.target.value;if(h===""||h==="-"){l?.(h);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(h)){let p=h;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(p)&&(p=Number(p)),l?.(p)}}});if(s.type==="boolean")return e.jsx(r.FormControlLabel,{label:o,labelPlacement:"start",control:e.jsx(r.Switch,{checked:i===!0,onChange:(n,h)=>l?.(h)})});if(s.type==="color")return e.jsx(dt,{label:o,value:i,onChange:n=>{l?.(n)}});if(s.type==="json"||s.type==="yaml")return e.jsx(pt,{label:o,value:i,onChange:n=>{l?.(n)},property:s,component:t,defaultLocale:x,allComponents:d,PropertyValueField:F,onUpload:n=>{a.current=n,c()}});if(s.type==="custom"){const n=d[s.componentId]?.data;return n?e.jsx(r.Box,{sx:{width:"100%"},children:e.jsx(K.CustomComponentRenderer,{componentId:n.id,props:{label:o,value:i,onChange:l},locale:m,dev:{mode:"draft",components:d,defaultLocale:x}})}):e.jsx(r.TextField,{...b,label:o,disabled:!0,placeholder:"Click right button select a component"})}if(s.type==="component")return e.jsxs(r.Stack,{direction:"column",sx:{width:"100%",gap:1},children:[e.jsx(H,{allComponents:d,label:o,value:i?.componentId,onChange:(n,h)=>{f||!i?l?.({...i&&JSON.parse(JSON.stringify(i)),componentId:h}):typeof i=="object"&&(i.componentId=h,l?.({...i&&JSON.parse(JSON.stringify(i)),componentId:h}))}}),i?.componentId&&e.jsx(St,{value:i,valueImmutable:f,onChange:l,defaultLocale:x,allComponents:d})]});if(!s.type||["string","url","multiline"].includes(s.type)){let n=s.type==="string"?s.multiline:void 0;s.type==="multiline"&&(n=!0);const h=s.type==="url"?i?.url:i;return e.jsx(r.TextField,{...b,label:o,value:typeof h=="string"?h:"",multiline:n,minRows:n?2:void 0,maxRows:n?10:void 0,onChange:j=>l?.(s.type==="url"?{...i,url:j.target.value,mediaKitUrl:j.target.value}:j.target.value),slotProps:{input:s.type==="url"?{sx:{pr:0},endAdornment:e.jsxs(r.InputAdornment,{position:"end",sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(N.UploaderButton,{onChange:async({response:j})=>{const p=j?.data?.url||j?.data?.fileUrl;let y;p&&(y=await N.getImageSize(p).catch(()=>N.getVideoSize(p)).catch(()=>{}));let P=j?.data?.filename||"";P&&(P=`mediakit://${P}`),l?.({url:p,mediaKitUrl:P,width:y?.naturalWidth,height:y?.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(V.InfoRounded,{sx:{cursor:"default",mr:1},fontSize:"small"})})]})}:void 0}})}return s.type==="array"?e.jsx(ct,{label:o,value:Array.isArray(i)?i:[],onChange:n=>l?.(n),property:s,renderItem:({item:n,index:h,onChange:j})=>s.subProperties&&Object.keys(s.subProperties).length>0?e.jsx(r.Stack,{sx:{gap:1,width:"100%"},children:z.default(Object.values(s.subProperties),"index").filter(p=>p.data.visible!==!1).map(({data:p})=>p.key?e.jsx(F,{component:t,property:p,value:n[p.key],onChange:y=>{const P={...n,[p.key]:y};j(P)},size:"small",fullWidth:!0,defaultLocale:x,allComponents:d},p.id):null)},h):e.jsx(r.TextField,{size:b.size,fullWidth:!0,value:n,onChange:p=>j(p.target.value)})}):(console.error("Unsupported property type",s.type),null)}function It({NumberProps:t,...s}){const{getInputProps:i}=ie.unstable_useNumberInput(t),l=i();return e.jsx(r.TextField,{...s,slotProps:{htmlInput:l}})}const he=`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"),r=require("@mui/material"),_=require("./chunks/state-tEydRMV8.js"),ye=require("@arcblock/ux/lib/Empty"),O=require("@arcblock/ux/lib/Locale/context"),te=require("@blocklet/code-editor"),Ce=require("@mui/icons-material/AddRounded"),ve=require("@mui/icons-material/ArrowDownward"),ke=require("@mui/icons-material/ArrowUpward"),Pe=require("@mui/icons-material/DeleteOutline"),Se=require("lodash/sortBy"),v=require("react"),re=require("react-use"),ne=require("@blocklet/pages-kit/builtin/color-picker"),N=require("@blocklet/pages-kit/builtin/uploader"),we=require("@iconify-icon/react"),Ie=require("lodash/isEmpty"),Te=require("lodash/set"),Be=require("yaml"),Oe=require("lodash/cloneDeep"),Re=require("@arcblock/ux/lib/Toast"),K=require("@blocklet/pages-kit/components"),Ne=require("@blocklet/pages-kit/utils/property"),le=require("@mui/base"),V=require("@mui/icons-material"),L=require("@syncedstore/core"),ae=require("ahooks"),Ve=require("lodash/assign"),_e=require("lodash/get"),ze=require("lodash/has"),Ee=require("lodash/isEqual"),Ae=require("lodash/isNil"),De=require("lodash/isObject"),Fe=require("lodash/keyBy"),qe=require("lodash/omit"),Le=require("lodash/pick"),Ue=require("lodash/reduce"),A=require("material-ui-popup-state/hooks"),Me=require("react-error-boundary"),We=require("@emotion/css"),$=require("react-dnd"),ce=require("@blocklet/pages-kit/utils/common"),T=t=>t&&t.__esModule?t:{default:t};function Ke(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 U=T(ye),Je=T(Ce),He=T(ve),Ye=T(ke),$e=T(Pe),z=T(Se),D=T(Ie),ue=T(Te),G=Ke(Be),Q=T(Oe),X=T(Re),Ge=T(Ve),Qe=T(_e),Xe=T(ze),Ze=T(Ee),J=T(Ae),et=T(De),tt=T(Fe),rt=T(qe),st=T(Le),nt=T(Ue);function ot({error:t}){return e.jsx(r.Box,{children:e.jsx(r.Alert,{severity:"error",children:t.message})})}function it({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($e.default,{fontSize:"small"})})}function lt({onClick:t,disabled:s,sx:i,...l}){return e.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:t,...l,children:e.jsx(Ye.default,{fontSize:"small"})})}function at({onClick:t,disabled:s,sx:i,...l}){return e.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:t,...l,children:e.jsx(He.default,{fontSize:"small"})})}function ct({label:t,value:s,onChange:i,disabled:l=!1,itemLabel:f="",emptyHeight:x=40,property:d,renderItem:b,...m}){const{t:u,locale:a}=O.useLocaleContext(),c=re.useUpdate(),o=v.useCallback(g=>{i(_.transformValue(g,d.type))},[i,d.type]),n=v.useMemo(()=>Array.isArray(s)?s:[],[s]),h=v.useCallback(()=>{const g=[...n,""];o(g),c()},[n,o,c]),j=v.useCallback(()=>{if(!d||!d.subProperties)return h();const g={};z.default(Object.values(d.subProperties),"index").forEach(({data:R})=>{if(!R.key)return;const E=R.locales?.[a]?.defaultValue??"";g[R.key]=E});const w=[...n,g];o(w),c()},[n,o,c,d,a,h]),p=v.useCallback(g=>{try{const C=JSON.parse(g);Array.isArray(C)?o(C):console.error("JSON解析结果不是数组")}catch(C){console.error("JSON解析错误:",C)}},[o]),y=v.useCallback(g=>{const C=n.filter((w,R)=>R!==g);o(C),c()},[n,o,c]),P=v.useCallback(g=>{if(g<=0)return;const C=[...n],w=C[g];C[g]=C[g-1],C[g-1]=w,o(C),c()},[n,o,c]),I=v.useCallback(g=>{if(g>=n.length-1)return;const C=[...n],w=C[g];C[g]=C[g+1],C[g+1]=w,o(C),c()},[n,o,c]),S=v.useCallback((g,C)=>{const w=[...n];w[g]=C,o(w)},[n,o]),k=d&&d.subProperties&&Object.keys(d.subProperties).length>0,B=v.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:g})=>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:g+1})},{field:"content",headerName:"",renderCell:({row:g,index:C})=>b&&k?b({item:g,index:C,property:d,onChange:w=>S(C,w)}):e.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:l,value:g,placeholder:f||`${u("item")} ${C+1}`,onChange:w=>S(C,w.target.value),...m})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:g})=>e.jsxs(r.Stack,{direction:"column",spacing:.25,children:[e.jsx(lt,{disabled:l||g===0,onClick:()=>P(g)}),e.jsx(at,{disabled:l||g===n.length-1,onClick:()=>I(g)}),e.jsx(it,{disabled:l,onClick:()=>y(g)})]})}],[b,k,d,S,f,u,l,m,y,P,I,n.length]);return k?e.jsxs(r.Stack,{sx:{width:"100%",gap:1},children:[t&&e.jsx(r.FormLabel,{children:t}),n.length>0?e.jsx(r.TableContainer,{component:r.Paper,variant:"outlined",sx:{borderRadius:1,mb:1},children:e.jsxs(r.Table,{size:"small",sx:{"& .MuiTableCell-root":{py:.25,px:1,whiteSpace:"nowrap"},"& .MuiTableCell-head":{backgroundColor:"action.hover",py:.25,px:1},borderCollapse:"collapse"},children:[e.jsx(r.TableHead,{sx:{display:"none"},children:e.jsx(r.TableRow,{children:B.map(g=>e.jsx(r.TableCell,{width:g.width,align:g.align||"left",sx:{fontWeight:"bold"},children:g.renderHeader?g.renderHeader():g.headerName},g.field))})}),e.jsx(r.TableBody,{children:n.map((g,C,w)=>e.jsx(r.TableRow,{sx:{borderBottom:C<w.length-1?"1px solid":"none",borderColor:"divider","&:hover":{backgroundColor:"action.hover"}},children:B.map(R=>e.jsx(r.TableCell,{width:R.width,align:R.align||"left",sx:{borderBottom:"none"},children:R.renderCell({row:g,index:C,onChange:E=>S(C,E)})},`${C}-${R.field}`))},C))})]})}):e.jsx(U.default,{style:{fontSize:12,height:x},children:u("maker.properties.arrayEmpty")}),e.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:l,startIcon:e.jsx(Je.default,{}),onClick:j,children:u("maker.properties.addArrayItem")})]}):e.jsxs(r.Stack,{sx:{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(te.CodeEditor,{keyId:d.id,locale:a,language:"json",value:JSON.stringify(n,null,2),onChange:g=>p(g||""),fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},d.id)})]})}function ut({ref:t,showMarkdown:s,markdown:i,onMarkdownChange:l,showUploader:f,value:x,meta:d,onChange:b,...m}){const[u,a]=v.useState("");v.useEffect(()=>{a(x||"")},[x,a]);const c=async()=>{if(u!==x){const n=_.getImageAbsoluteUrl(u);if(!n){b(u,void 0);return}const h=await N.getImageSize(n).catch(()=>N.getVideoSize(n)).catch(()=>{});b(u,{...h,filename:u})}};re.useDebounce(()=>{u!==x&&b(u)},300,[u]),v.useImperativeHandle(t,()=>({submit:c}));const o={};return f&&(o.InputProps={sx:{pr:0},endAdornment:e.jsx(r.InputAdornment,{position:"end",sx:{mx:.5},children:e.jsx(N.UploaderButton,{onChange:async({response:n})=>{const h=n?.data?.filename,j=_.getImageAbsoluteUrl(h)||"";let p={};j&&(p=await N.getImageSize(j).catch(()=>N.getVideoSize(j)).catch(()=>{})),b(h,{...p,filename:h})}})})}),e.jsx(r.TextField,{size:"small",fullWidth:!0,...m,label:e.jsxs(r.Stack,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[m.label,s&&e.jsxs(e.Fragment,{children:[" (",e.jsx(r.FormControlLabel,{checked:i,label:e.jsx(r.Box,{component:we.Icon,icon:"tabler:markdown",sx:{verticalAlign:"middle"}}),labelPlacement:"start",control:e.jsx(r.Switch,{size:"small"}),sx:{ml:.25,pr:1},onChange:(n,h)=>l?.(h)}),")"]})]}),value:u,onChange:n=>a(n.target.value),...o,onKeyDown:n=>{n.keyCode!==229&&n.key==="Enter"&&c()},slotProps:{inputLabel:{shrink:!0,...m.InputLabelProps}}})}function dt({value:t,onChange:s,disableGradient:i=!1,...l}){const f=v.useRef(null);return e.jsxs(e.Fragment,{children:[e.jsx(ut,{...l,value:t,onChange:s,InputProps:{endAdornment:e.jsx(r.InputAdornment,{position:"end",children:e.jsx(ne.ColorItem,{color:t??"",style:{width:"1.5rem",height:"1.5rem",padding:0},onClick:()=>{f.current?.open({value:t??""})}})})}}),e.jsx(ne.ConfigColorDialog,{ref:f,onSave:({value:x},d)=>{s(x),d()},disableGradient:i})]})}function pt({label:t,value:s,onChange:i,property:l,component:f,defaultLocale:x,allComponents:d,PropertyValueField:b,onUpload:m}){const{locale:u}=O.useLocaleContext(),a=v.useRef(null);if(!D.default(l.subProperties)){const o=z.default(Object.values(l.subProperties||{}),"index").filter(n=>n.data.visible!==!1&&n.data.key);return e.jsxs(r.Stack,{sx:{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((n,h)=>{const{data:j}=n,p=j.key??j.id,y=h===o.length-1;let P=null;try{s&&typeof s=="object"?P=s[p]:typeof s=="string"&&(P=(l.type==="yaml"?G.parse(s||""):JSON.parse(s||"{}"))[p])}catch{}P==null&&(j.locales&&u&&j.locales[u]?P=j.locales[u].defaultValue:j.locales&&x&&j.locales[x]&&(P=j.locales[x].defaultValue));const I=k=>{try{let B={};if(typeof s=="string")try{B=l.type==="yaml"?G.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(B={...s});ue.default(B,p,k);const g=_.transformValue(B,l.type);i?.(g)}catch(B){console.error("Error updating property:",B)}},S=8;return e.jsxs(r.Box,{sx:{mb:y?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:S,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),e.jsx(r.Box,{sx:{position:"absolute",left:S,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!y&&e.jsx(r.Box,{sx:{position:"absolute",left:S,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),e.jsx(r.Box,{sx:{flexGrow:1},children:e.jsx(b,{component:f,property:j,value:P,onChange:I,size:"small",fullWidth:!0,defaultLocale:x,allComponents:d})})]},j.id)})})})]})}return e.jsx(r.Stack,{sx:{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(te.CodeEditor,{keyId:l.id,locale:u,language:l.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:o=>{i?.(o)},onUpload:o=>{a.current=o,m&&m(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 xt=["string","multiline","json","yaml","url","component","custom","array"];function oe(t){return t.type?!xt.includes(t.type):!1}function de({disabled:t,list:s,renderItem:i,...l}){const f=v.useRef(null),x=v.useId(),d=ae.useUpdate(),b=z.default(Object.entries(s),n=>n[1].index).map(n=>n[0]),m=v.useRef(b),u=v.useCallback(n=>{m.current=n,d()},[d]),a=v.useCallback(({index:n},{index:h})=>{const j=[...m.current];j.splice(h,0,...j.splice(n,1)),u(j)},[u]);v.useEffect(()=>{u(b)},[b.join("-")]);const[{isOver:c},o]=$.useDrop({accept:x,collect:n=>({isOver:n.isOver()}),canDrop:()=>!t,drop:()=>{const n=()=>{m.current.forEach((j,p)=>{const y=s[j];y&&(y.index=p)})},h=L.getYjsValue(s)?.doc;h?h.transact(()=>{n()}):n()}});return v.useEffect(()=>{c||u(b)},[c]),o(f),e.jsx(r.Box,{...l,ref:f,className:We.cx(c&&"isDragging"),children:m.current.map((n,h)=>e.jsx(mt,{type:x,disabled:t,id:n,index:h,itemIndex:j=>m.current.indexOf(j),move:a,children:j=>{const p=s[n];return p?i(p.data,h,j):null}},n))})}function mt({disabled:t,id:s,index:i,type:l,children:f,itemIndex:x,move:d}){const b=v.useRef(void 0),[{isDragging:m},u,a]=$.useDrag({type:l,item:()=>({id:s}),canDrag:()=>!t,collect:o=>({isDragging:o.isDragging()})}),[,c]=$.useDrop({accept:l,canDrop:()=>!t,hover(o,n){if(!b.current)return;const h=x(o.id),j=i;if(h===j)return;const p=b.current?.getBoundingClientRect(),y=(p.bottom-p.top)/2,I=n.getClientOffset().y-p.top;h<j&&I<y||h>j&&I>y||d({id:o.id,index:h},{id:s,index:i})}});return typeof f=="function"?f({isDragging:m,drag:u,drop:o=>(b.current=o,c(o)),preview:a}):(u(c(a(b))),e.jsx(r.Box,{ref:b,children:f}))}function ft({drop:t,preview:s,drag:i,disabled:l,isDragging:f,children:x,onDelete:d,onVisibilityChange:b,visible:m=!0,actions:u,alwaysShowActions:a=!1}){const{t:c}=O.useLocaleContext();return e.jsx(r.Box,{ref:t,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:m?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:x}),!l&&e.jsx(r.Box,{className:a?"":"hover-visible",sx:{maxWidth:a?"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:[u,b&&e.jsx(r.Tooltip,{title:c(m?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{onClick:()=>b(!m),children:m?e.jsx(V.VisibilityOffRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}}):e.jsx(V.VisibilityRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),d&&e.jsx(r.Tooltip,{title:c("delete"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{onClick:d,children:e.jsx(V.DeleteOutlineRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),e.jsx(r.Tooltip,{title:c("dragSort"),disableInteractive:!0,placement:"top",children:e.jsx(r.Button,{ref:i,children:e.jsx(V.DragIndicatorRounded,{sx:{color:"grey.500"}})})})]})})]})})}function ht(t){const s=["string","json","array","url","multiline"],i=["style","fontSize","color","content","type"];return!!(s.includes(t.type||"")&&!i.includes(t.key||""))}function bt(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 pe=(t,s,i,l)=>{const f={};return z.default(Object.entries(t),([,d])=>d.index).forEach(([d,b])=>{const m=b.data;if(!m)return;const u=m.key||m.id,a=i?bt(m,i,l||""):u,c=s?.[m.id],o={key:u,isNeedGenerate:c?.isNeedGenerate??ht(m),describe:c?.describe??"",displayName:a};m.subProperties&&!D.default(m.subProperties)&&(o.subProperties=pe(m.subProperties,c?.subProperties,i,l)),f[m.id]=o}),f};function jt({open:t,onClose:s,onConfirm:i,component:l,initialConfig:f,locale:x,defaultLocale:d,title:b,loading:m=!1}){const{t:u}=O.useLocaleContext(),[a,c]=v.useState(null);v.useEffect(()=>{if(t&&l){const p={properties:{}};if(l.properties){const y=f?.properties;p.properties=pe(l.properties,y,x,d)}c(p)}},[t,l,f,x,d]);const o=()=>{s()},n=()=>{a&&(i(a),s())},h=(p,y,P)=>{if(!a||!p.length)return;const I=JSON.parse(JSON.stringify(a));let S=I.properties,k=null;for(let g=0;g<p.length-1;g++){const C=p[g];if(!C||!S[C])return;k=S;const w=S[C];w.subProperties||(w.subProperties={}),S=w.subProperties}const B=p[p.length-1];if(B){if("isNeedGenerate"in P){const g=P.isNeedGenerate,C={...y,...P};if(y.subProperties&&!D.default(y.subProperties)){const w=(R,E)=>{const q={};return Object.entries(R).forEach(([ge,M])=>{const Y={...M};E!==null&&(Y.isNeedGenerate=E),M.subProperties&&!D.default(M.subProperties)&&(Y.subProperties=w(M.subProperties,E!==null?E:null)),q[ge]=Y}),q};C.subProperties=w(y.subProperties,g===!1?!1:null)}if(p.length===1)I.properties[B]=C;else if(k&&p.length>=2){const w=p[p.length-2];w&&k[w]&&(k[w].subProperties||(k[w].subProperties={}),k[w].subProperties[B]=C)}}else if(p.length===1)I.properties[B]={...y,...P};else if(k&&p.length>=2){const g=p[p.length-2];g&&k[g]&&k[g].subProperties&&(k[g].subProperties[B]={...y,...P})}c(I)}},j=(p,y=[],P=!0)=>{if(!p||D.default(p))return e.jsx(U.default,{children:u("maker.properties.noProperties")});const I=z.default(Object.entries(p),([,S])=>S.displayName);return e.jsx(r.Stack,{spacing:1.5,children:I.map(([S,k],B)=>{const g=[...y,S],C=B===I.length-1,w=k.subProperties&&!D.default(k.subProperties),R=k.displayName||S,E=!P;return e.jsx(r.Box,{sx:{position:"relative"},children:e.jsxs(r.Stack,{direction:"row",children:[y.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"}}),!C&&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"},spacing:1.5,sx:{alignItems:{xs:"flex-start",md:"center"},width:"100%"},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:k.isNeedGenerate,disabled:E,onChange:q=>{h(g,k,{isNeedGenerate:q.target.checked})}}),label:R,sx:{minWidth:"180px",maxWidth:"280px",mr:2,"& .MuiFormControlLabel-label":{wordBreak:"break-word"}}}),e.jsx(r.TextField,{size:"small",fullWidth:!0,label:u("maker.properties.llmPropertyDescribe"),value:k.describe,onChange:q=>{h(g,k,{describe:q.target.value})},disabled:!k.isNeedGenerate})]}),w&&e.jsx(r.Box,{sx:{ml:3},children:j(k.subProperties,g,k.isNeedGenerate&&P)})]})]})},S)})})};return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"lg",fullWidth:!0,children:[e.jsx(r.DialogTitle,{children:b||u("maker.properties.llmConfigTitle")}),e.jsx(r.DialogContent,{children:e.jsx(r.Box,{sx:{my:3},children:m?e.jsx(r.Typography,{children:u("maker.properties.loading")}):l?a?e.jsxs(r.Stack,{spacing:3,children:[e.jsx(r.Typography,{variant:"subtitle2",children:u("maker.properties.llmConfigInstructions")}),j(a.properties)]}):e.jsx(r.Typography,{children:u("maker.properties.loading")}):e.jsx(r.Typography,{color:"error",children:u("maker.properties.componentNotFound")})})}),e.jsxs(r.DialogActions,{children:[e.jsx(r.Button,{onClick:o,children:u("common.cancel")}),e.jsx(r.Button,{variant:"contained",onClick:n,disabled:!a||m,children:u("common.confirm")})]})]})}function gt({label:t,value:s,onChange:i}){const[l,f]=v.useState(!1);return e.jsxs(r.Stack,{sx:{gap:1},children:[e.jsx(r.TextField,{label:t,size:"small",value:s,onChange:x=>i?.(x.target.value),slotProps:{input:{sx:{pr:0},endAdornment:e.jsx(r.InputAdornment,{position:"end",children:e.jsx(N.UploaderButton,{onChange:({response:x})=>{const d=x?.data?.filename;d&&i?.(d)}})})}}}),s&&e.jsx(r.Box,{component:"img",src:_.getImageAbsoluteUrl(s),alt:t,onClick:()=>f(!0),sx:{maxWidth:100,maxHeight:100,width:"100%",objectFit:"contain",borderRadius:1,cursor:"pointer"}}),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 Z(t,s=""){return nt.default(t,(i,l,f)=>{const x=s?`${s}.${f}`:f;return et.default(l)?Ge.default(i,Z(l,x)):i[x]=l,i},{})}const yt=[{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 W(t,s,i){return!t||!i?!1:Object.values(t).some(({data:l})=>l.id!==s&&l.key===i)}function ee(t,s){return!t||!s?!1:t[s]?.data.visible??!0}function Ct({componentId:t}){const{state:{components:s}}=_.useStore(),l=s[t]?.data;return l?e.jsx(r.Stack,{sx:{maxHeight:"100%",overflow:"auto"},children:e.jsx(r.Box,{sx:{p:2},children:e.jsx(Me.ErrorBoundary,{FallbackComponent:ot,resetKeys:[t],children:e.jsx(vt,{value:l,componentId:t})})})}):null}function vt({value:t,componentId:s}){const{t:i}=O.useLocaleContext(),{localState:{currentLocale:l,customComponentPreviewerProperties:f},state:{config:{defaultLocale:x}},localActions:{setCustomComponentPreviewerProperties:d}}=_.useStore(),b=L.getYjsValue(t).doc,m=_.useAllComponents(),u=v.useMemo(()=>f?.[s]??{},[s,f]),a=ae.useReactive({componentId:s,propertiesValue:{...u}});return v.useEffect(()=>{a.componentId!==s&&(a.componentId=s,a.propertiesValue={...u})},[s,u,a]),v.useEffect(()=>{if(a.componentId!==s)return;const c=Object.fromEntries(Object.values(t.properties??{}).map(({data:o})=>[o.id,{value:a.propertiesValue[o.id]?.value??Ne.parsePropertyValue(o,o.locales?.[l]?.defaultValue??o.locales?.[x]?.defaultValue,{locale:l,defaultLocale:x})}]));d(s,c)},[JSON.stringify(a.propertiesValue),s,a.componentId]),e.jsx(r.Stack,{sx:{height:"100%"},children:e.jsxs(r.Stack,{sx:{gap:2},children:[e.jsx(xe,{config:t}),e.jsx(fe,{config:t,currentLocale:l,defaultLocale:x,allComponents:m,onUpdateConfig:c=>{b.transact(()=>{c(t)})}}),e.jsxs(r.Stack,{direction:"row",sx:{gap:2,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,value:t.renderer?.type||"react-component",onChange:c=>{b.transact(()=>{const o=c.target.value;t.renderer??={type:o},t.renderer.type=o})},slotProps:{select:{autoWidth:!0}},children:[e.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),e.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),t.renderer?.type==="component"&&e.jsx(Bt,{value:t}),t.renderer?.type==="react-component"&&e.jsx(Tt,{value:t}),e.jsx(se,{config:t,currentLocale:l,defaultLocale:x,allComponents:m,propertiesValue:a.propertiesValue,onChange:({value:c,id:o,path:n})=>{const h=[...n,"data"];if(!Qe.default(t,h)){X.default.warning(i("cannotFindPropertyKey",{key:h.join(".")}));return}a.propertiesValue[o]={value:c.value}}})]})})}function xe({config:t}){const{t:s}=O.useLocaleContext();return e.jsx(N.UploaderProvider,{children:e.jsxs(r.Stack,{sx:{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,value:t.description||"",onChange:i=>t.description=i.target.value,slotProps:{input:{endAdornment:e.jsx(r.InputAdornment,{position:"end",sx:{mt:-1.5},children:e.jsx(Ot,{config:t})})},htmlInput:{maxLength:200}}}),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(gt,{label:s("previewImage"),value:t.previewImage||"",onChange:i=>t.previewImage=i})]})})}function me({data:t,params:s,visible:i,config:l,currentLocale:f,defaultLocale:x,allComponents:d,onUpdateConfig:b}){const{t:m}=O.useLocaleContext(),u=v.useMemo(()=>t.type==="json"||t.type==="yaml"||t.type==="array"?wt:F,[t.type]);return e.jsx(ft,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{b(a=>{if(a.properties){const o=Object.entries(a.properties).sort(([,h],[,j])=>h.index-j.index);delete a.properties[t.id],o.filter(([h])=>h!==t.id).forEach(([,h],j)=>{h.index=j})}})},visible:i,onVisibilityChange:a=>{b(c=>{const o=c.properties[t.id].data;o.visible=a})},alwaysShowActions:!0,children:e.jsxs(r.Stack,{direction:"column",sx:{gap:2},children:[e.jsx(r.TextField,{label:m("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:t.key?W(l.properties,t.id,t.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:t.key?W(l.properties,t.id,t.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:t.key?W(l.properties,t.id,t.key)?"warning.main":"primary.main":"error.main"}},value:t.key||"",onChange:a=>{b(c=>{const o=c.properties[t.id].data;o.key=a.target.value.trim()})},slotProps:{input:{endAdornment:!t.key||t.key&&W(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?m("duplicateKey"):m("requiredKey"),children:e.jsx(V.InfoRounded,{sx:{color:t.key?"warning.main":"error.main",fontSize:16}})})}):null}}}),e.jsxs(r.Stack,{direction:"row",sx:{gap:1},children:[e.jsx(r.TextField,{label:m("label"),size:"small",sx:{flex:1},value:(t.locales?.[f]?.name??t.locales?.[x]?.name)||"",onChange:a=>{b(c=>{const o=c.properties[t.id].data;o.locales??={},o.locales[f]??={},o.locales[f].name=a.target.value})}}),e.jsx(r.TextField,{label:m("type"),size:"small",select:!0,sx:{flex:1},value:t.type==="string"&&t.multiline?"multiline":t.type||"string",onChange:a=>{b(c=>{const o=c.properties[t.id].data;if(o.locales)for(const h of Object.keys(o.locales))o.locales[h].defaultValue=void 0;const n=a.target.value;n==="multiline"?(o.type="string",o.multiline=!0):(typeof o.multiline<"u"&&delete o.multiline,o.type=n)})},children:yt.map(a=>e.jsx(r.MenuItem,{value:a.value,children:a.label},a.value))})]}),e.jsxs(r.Stack,{direction:"row",sx:{gap:1},children:[e.jsx(u,{allComponents:d,defaultLocale:x,component:l,property:t,label:m("defaultValue"),size:"small",fullWidth:!0,value:t.locales?.[f]?.defaultValue,onChange:(a,c)=>{b(o=>{const n=o.properties[t.id].data;if(c?.forceUpdateProperty){const h=Z(n),j=Z(a);Object.keys(j).forEach(p=>{h[p]||ue.default(n,p,j[p])})}else n.locales??={},n.locales[f]??={},n.locales[f].defaultValue=a})}}),t.type==="custom"?e.jsx(r.Box,{children:e.jsx(Pt,{property:t,allComponents:d})}):null]})]})})}function kt(t,s){const[i,l]=v.useState(0);return v.useEffect(()=>{const x=setTimeout(()=>{if(t.current){let d=t.current.parentElement,b=0;for(;d;)d.classList.contains("property-container")&&b++,d=d.parentElement;l(b)}},100);return()=>clearTimeout(x)},[t,s]),i}function fe({config:t,currentLocale:s,defaultLocale:i,allComponents:l,onUpdateConfig:f,useI18nEditor:x=!0}){const{t:d}=O.useLocaleContext(),b=A.usePopupState({variant:"dialog"}),m=t.properties&&z.default(Object.values(t.properties),"index");return e.jsx(N.UploaderProvider,{children:e.jsxs(r.Stack,{sx:{gap:2},children:[e.jsxs(r.Stack,{direction:"row",sx:{gap:1,alignItems:"center",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"subtitle1",children:d("properties")}),e.jsx(r.Box,{sx:{flex:1}}),x&&e.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...A.bindTrigger(b),children:e.jsx(V.TranslateRounded,{fontSize:"small"})})]}),t.properties&&Object.keys(t.properties).length>0?e.jsx(de,{component:r.Stack,gap:2,list:t.properties,renderItem:(u,a,c)=>{const o=ee(t.properties,u.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,{sx:{gap:2},children:e.jsx(me,{data:u,params:c,visible:o,config:t,currentLocale:s,defaultLocale:i,allComponents:l,onUpdateConfig:f})})},u.id)}}):e.jsx(U.default,{style:{fontSize:12},children:d("maker.properties.noProperties")}),e.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",onClick:()=>{f(u=>{const a=ce.nextId();u.properties??={},u.properties[a]??={index:m?.length||0,data:{id:a}}})},startIcon:e.jsx(V.AddRounded,{}),children:d("addObject",{object:d("property")})}),x&&e.jsx(he,{...A.bindDialog(b),component:t})]})})}function Pt({property:t,allComponents:s}){const i=A.usePopupState({variant:"popper"});return e.jsxs(e.Fragment,{children:[e.jsx(r.Button,{sx:{minWidth:0},...A.bindTrigger(i),children:e.jsx(V.SettingsRounded,{fontSize:"small"})}),e.jsx(r.Popper,{...A.bindPopper(i),children:e.jsx(le.ClickAwayListener,{onClickAway:i.close,children:e.jsx(r.Paper,{children:e.jsx(r.Box,{sx:{width:500,p:2},children:e.jsx(H,{value:t.componentId,onChange:(l,f)=>t.componentId=f,allComponents:s})})})})})]})}function St({value:t,valueImmutable:s,onChange:i,defaultLocale:l,allComponents:f}){const[x,d]=v.useState(!1),{t:b,locale:m}=O.useLocaleContext(),u=typeof t?.componentId=="string"?f[t.componentId]?.data:void 0;return u?e.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[e.jsx(r.IconButton,{sx:{minWidth:0},disabled:!u,size:"small",onClick:()=>d(!x),color:x?"primary":"default",children:e.jsx(V.SettingsRounded,{fontSize:"small"})}),x&&e.jsx(r.Collapse,{in:x,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,{sx:{width:"100%",mb:2},children:e.jsx(se,{config:u,currentLocale:m,defaultLocale:l,allComponents:f,propertiesValue:t?.properties,onChange:({id:a,value:c})=>{const o=Q.default(c.value),n=JSON.parse(JSON.stringify(t));n?.componentId&&(s?i?.({...n,properties:{...n.properties,[a]:{value:o}}}):(n.properties=n.properties??{},n.properties[a]={value:o},i?.(n)))}})}),e.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:b("close")})]})})]}):null}function he({type:t="properties",component:s,...i}){const{t:l}=O.useLocaleContext(),{state:{components:f,supportedLocales:x,config:{defaultLocale:d}}}=_.useStore(),b=_.useAllComponents(),m=L.getYjsValue(s).doc,u=t==="properties"?s.properties:t==="parameters"&&s.renderer?.type==="component"?f[s.renderer.componentId]?.data.properties:void 0,a=s.renderer?.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:u&&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:x.map(({locale:c,name:o})=>e.jsx(r.TableCell,{children:e.jsxs(r.Typography,{sx:{color:"text.primary"},children:[o,d===c&&e.jsx(V.StarRounded,{sx:{fontSize:12}})]})},c))})}),e.jsx(r.TableBody,{children:z.default(Object.values(u),"index").map(({data:c})=>e.jsx(r.TableRow,{children:x.map(({locale:o})=>e.jsx(r.TableCell,{children:e.jsx(r.Stack,{sx:{gap:1},children:t==="properties"?e.jsxs(e.Fragment,{children:[e.jsx(r.TextField,{size:"small",label:"Key",value:c.key||"",onChange:n=>{m.transact(()=>{c.key=n.target.value.trim()})}}),e.jsx(r.TextField,{size:"small",label:l("label"),value:(c.locales?.[o]?.name??c.locales?.[d]?.name)||"",onChange:n=>{m.transact(()=>{c.locales??={},c.locales[o]??={},c.locales[o].name=n.target.value})}}),e.jsx(r.Box,{children:e.jsx(F,{allComponents:b,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:J.default(c.locales?.[o]?.defaultValue),value:c.locales?.[o]?.defaultValue??c.locales?.[d]?.defaultValue,onChange:n=>{m.transact(()=>{c.locales??={},c.locales[o]??={},c.locales[o].defaultValue=n})}})})]}):t==="parameters"&&a?e.jsx(r.Box,{children:e.jsx(F,{allComponents:b,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,valueImmutable:J.default(a.renderer.properties?.[c.id]?.locales?.[o]?.value),value:a.renderer.properties?.[c.id]?.locales?.[o]?.value??a.renderer.properties?.[c.id]?.locales?.[d]?.value??c.locales?.[o]?.defaultValue??c.locales?.[d]?.defaultValue,onChange:n=>{m.transact(()=>{a.renderer.properties??={},a.renderer.properties[c.id]??={},a.renderer.properties[c.id].locales??={},a.renderer.properties[c.id].locales[o]??={},a.renderer.properties[c.id].locales[o].value=n})}})}):null},c.id)},o))},c.id))})]})})}),e.jsx(r.DialogActions,{children:e.jsx(r.Button,{onClick:c=>i.onClose?.(c,"escapeKeyDown"),children:l("close")})})]})}const ie=(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),x=l[f],d=r.alpha(x,.5),b=r.alpha(x,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:b,...s}};function wt({property:t,onChange:s,defaultLocale:i,allComponents:l}){const{t:f,locale:x}=O.useLocaleContext(),d=v.useRef(null),b=kt(d,t),m=v.useCallback(()=>{if(!(t.type!=="json"&&t.type!=="yaml"&&t.type!=="array")&&t.subProperties)try{let u={};z.default(Object.values(t.subProperties),"index").filter(o=>o.data.visible!==!1&&o.data.key).forEach(({data:o})=>{if(!o.key)return;let n=o.locales?.[x]?.defaultValue??o.locales?.[i]?.defaultValue;if(o.type==="number")n=Number(n);else if(o.type==="boolean")n=n===!0||n==="true";else if((o.type==="json"||o.type==="yaml")&&typeof n=="string")try{o.type==="json"?n=JSON.parse(n):n=G.parse(n)}catch(h){console.error("Error parsing nested value",n,h),n={}}u[o.key]=n}),t.type==="array"&&!Array.isArray(u)&&(u=D.default(u)?[]:[u]);const c=_.transformValue(u,t.type);s?.(c)}catch(u){console.error("Error converting structure to text:",u)}},[t,x,i,s]);return t.type!=="json"&&t.type!=="yaml"&&t.type!=="array"?null:e.jsxs(r.Stack,{direction:"column",ref:d,sx:{gap:1.5,width:"100%"},children:[e.jsx(r.Divider,{sx:{mt:-1},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:f("maker.properties.subProperties")})}),t.subProperties&&Object.keys(t.subProperties).length>0?e.jsx(de,{component:r.Stack,gap:2,list:t.subProperties,renderItem:(u,a,c)=>{const o=u.visible!==!1;return e.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:o?"1px solid":"1px dashed","&":ie(b)},children:e.jsx(r.Stack,{sx:{gap:2},children:e.jsx(me,{data:u,params:c,visible:o,config:{properties:t.subProperties},currentLocale:x,defaultLocale:i,allComponents:l,onUpdateConfig:n=>{try{const h={properties:t.subProperties||{}};n(h);const j={...t,subProperties:h.properties};s?.(j,{forceUpdateProperty:!0}),m()}catch(h){console.error("Error updating property:",h)}}})})},u.id)}}):e.jsx(U.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(V.AddRounded,{}),onClick:()=>{try{const u=t.subProperties||{},a=ce.nextId(),o={index:Object.values(u).length,data:{id:a,key:"",type:"string",visible:!0,locales:{[x]:{name:"",defaultValue:""}},subProperties:{}}},n={...t,subProperties:{...u,[a]:o}};s?.(n,{forceUpdateProperty:!0}),m()}catch(u){console.error("Error adding property:",u)}},sx:{"&":ie(b,{})},children:f("maker.properties.addSubProperty")})]})}function F({component:t,property:s,value:i,onChange:l,valueImmutable:f,defaultLocale:x,allComponents:d,...b}){const{locale:m}=O.useLocaleContext(),u=N.useUploader(),a=v.useRef(null),c=()=>{const n=u?.current?.getUploader();n?.open(),a.current&&n.onceUploadSuccess(({response:h})=>{let j=h?.data?.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")),a.current?.(j)})},o=b.label??(s.locales?.[m]?.name||s.locales?.[x]?.name||s.key||s.id);if(s.type==="number")return e.jsx(It,{...b,label:o,NumberProps:{value:["number","string"].includes(typeof i)?i:null,onChange:(n,h)=>l?.(h)}});if(s.type==="decimal")return e.jsx(r.TextField,{...b,label:o,type:"text",value:i??"",onChange:n=>{const h=n.target.value;if(h===""||h==="-"){l?.(h);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(h)){let p=h;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(p)&&(p=Number(p)),l?.(p)}}});if(s.type==="boolean")return e.jsx(r.FormControlLabel,{label:o,labelPlacement:"start",control:e.jsx(r.Switch,{checked:i===!0,onChange:(n,h)=>l?.(h)})});if(s.type==="color")return e.jsx(dt,{label:o,value:i,onChange:n=>{l?.(n)}});if(s.type==="json"||s.type==="yaml")return e.jsx(pt,{label:o,value:i,onChange:n=>{l?.(n)},property:s,component:t,defaultLocale:x,allComponents:d,PropertyValueField:F,onUpload:n=>{a.current=n,c()}});if(s.type==="custom"){const n=d[s.componentId]?.data;return n?e.jsx(r.Box,{sx:{width:"100%"},children:e.jsx(K.CustomComponentRenderer,{componentId:n.id,props:{label:o,value:i,onChange:l},locale:m,dev:{mode:"draft",components:d,defaultLocale:x}})}):e.jsx(r.TextField,{...b,label:o,disabled:!0,placeholder:"Click right button select a component"})}if(s.type==="component")return e.jsxs(r.Stack,{direction:"column",sx:{width:"100%",gap:1},children:[e.jsx(H,{allComponents:d,label:o,value:i?.componentId,onChange:(n,h)=>{f||!i?l?.({...i&&JSON.parse(JSON.stringify(i)),componentId:h}):typeof i=="object"&&(i.componentId=h,l?.({...i&&JSON.parse(JSON.stringify(i)),componentId:h}))}}),i?.componentId&&e.jsx(St,{value:i,valueImmutable:f,onChange:l,defaultLocale:x,allComponents:d})]});if(!s.type||["string","url","multiline"].includes(s.type)){let n=s.type==="string"?s.multiline:void 0;s.type==="multiline"&&(n=!0);const h=s.type==="url"?i?.url:i;return e.jsx(r.TextField,{...b,label:o,value:typeof h=="string"?h:"",multiline:n,minRows:n?2:void 0,maxRows:n?10:void 0,onChange:j=>l?.(s.type==="url"?{...i,url:j.target.value,mediaKitUrl:j.target.value}:j.target.value),slotProps:{input:s.type==="url"?{sx:{pr:0},endAdornment:e.jsxs(r.InputAdornment,{position:"end",sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(N.UploaderButton,{onChange:async({response:j})=>{const p=j?.data?.url||j?.data?.fileUrl;let y;p&&(y=await N.getImageSize(p).catch(()=>N.getVideoSize(p)).catch(()=>{}));let P=j?.data?.filename||"";P&&(P=`mediakit://${P}`),l?.({url:p,mediaKitUrl:P,width:y?.naturalWidth,height:y?.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(V.InfoRounded,{sx:{cursor:"default",mr:1},fontSize:"small"})})]})}:void 0}})}return s.type==="array"?e.jsx(ct,{label:o,value:Array.isArray(i)?i:[],onChange:n=>l?.(n),property:s,renderItem:({item:n,index:h,onChange:j})=>s.subProperties&&Object.keys(s.subProperties).length>0?e.jsx(r.Stack,{sx:{gap:1,width:"100%"},children:z.default(Object.values(s.subProperties),"index").filter(p=>p.data.visible!==!1).map(({data:p})=>p.key?e.jsx(F,{component:t,property:p,value:n[p.key],onChange:y=>{const P={...n,[p.key]:y};j(P)},size:"small",fullWidth:!0,defaultLocale:x,allComponents:d},p.id):null)},h):e.jsx(r.TextField,{size:b.size,fullWidth:!0,value:n,onChange:p=>j(p.target.value)})}):(console.error("Unsupported property type",s.type),null)}function It({NumberProps:t,...s}){const{getInputProps:i}=le.unstable_useNumberInput(t),l=i();return e.jsx(r.TextField,{...s,slotProps:{htmlInput:l}})}const be=`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 () {
@@ -7,5 +7,5 @@ export default function () {
7
7
  Hello World
8
8
  </Box>
9
9
  )
10
- }`,be=`console.log('hello')
11
- `;function Tt({value:t}){const{locale:s}=O.useLocaleContext(),i=te.useUpdate(),l=L.getYjsValue(t).doc;return v.useEffect(()=>{t.renderer?.script||(l.transact(()=>{t.renderer.script=t.renderer.type==="react-component"?he:be}),i())},[t]),e.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:e.jsx(ee.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 Bt({value:t}){const{t:s}=O.useLocaleContext(),i=L.getYjsValue(t).doc,{state:{components:l,config:{defaultLocale:f},resources:x},localState:{currentLocale:d}}=_.useStore(),b=_.useAllComponents(),m=l[t.renderer.componentId]?.data??x.components?.[t.renderer.componentId]?.component,u=A.usePopupState({variant:"dialog"});return e.jsx(N.UploaderProvider,{children:e.jsxs(r.Stack,{sx:{gap:1},children:[e.jsx(H,{allComponents:b,excludes:[t.id],value:t.renderer.componentId,onChange:(a,c)=>t.renderer.componentId=c}),m&&e.jsxs(e.Fragment,{children:[e.jsxs(r.Stack,{direction:"row",sx:{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},...A.bindTrigger(u),children:e.jsx(V.TranslateRounded,{fontSize:"small"})})]}),m.properties&&z.default(Object.values(m.properties),"index").map(({data:a})=>e.jsx(r.Box,{children:e.jsx(F,{allComponents:b,defaultLocale:f,component:m,property:a,fullWidth:!0,size:"small",valueImmutable:J.default(t.renderer.properties?.[a.id]?.locales?.[d]?.value),value:t.renderer.properties?.[a.id]?.locales?.[d]?.value??t.renderer.properties?.[a.id]?.locales?.[f]?.value??a.locales?.[d]?.defaultValue??a.locales?.[f]?.defaultValue,onChange:c=>{i.transact(()=>{t.renderer.properties??={},t.renderer.properties[a.id]??={},t.renderer.properties[a.id].locales??={},t.renderer.properties[a.id].locales[d]??={},t.renderer.properties[a.id].locales[d].value=c})}})},a.id)),e.jsx(fe,{...A.bindDialog(u),component:t,type:"parameters"})]})]})})}function H({label:t,options:s,excludes:i,value:l,onChange:f,allComponents:x,...d}){const{t:b}=O.useLocaleContext(),m=s??z.default(Object.values(rt.default(x,...i??[])),"index").map(a=>a.data),u=(typeof l=="string"?x[l]?.data:void 0)??null;return e.jsx(r.Autocomplete,{...d,size:"small",options:m,autoHighlight:!0,isOptionEqualToValue:(a,c)=>a.id===c.id,getOptionKey:a=>a.id,getOptionLabel:a=>a.name||a.id,renderInput:a=>e.jsx(r.TextField,{label:t||b("component"),...a}),value:u,onChange:(a,c)=>{let o={};c&&(o={blockletId:x[c?.id]?.blockletId,blockletTitle:x[c?.id]?.blockletTitle,componentName:x[c?.id]?.data?.name||x[c?.id]?.data?.id}),f?.(a,c?.id,o)}})}function re({config:t,allComponents:s,defaultLocale:i,propertiesValue:l,currentLocale:f,onChange:x,props:d}){const{t:b}=O.useLocaleContext(),[m,u]=v.useState(t?.properties),[a,c]=v.useState(null);v.useEffect(()=>{(()=>{t?.renderer?.type==="react-component"&&D.default(t?.properties)?K.transpileAndLoadScript(t?.renderer?.script).then(y=>{const P=K.getPropertiesFromCode(y);u(P)}):u(t?.properties)})()},[JSON.stringify(t)]);const o=v.useCallback(()=>!t||!m?{}:Object.values(m).reduce((p,{data:y})=>{const P=y.key||y.id;return p[y.id]={key:P,value:d?.[P]??l?.[y.id]?.value??y.locales?.[f]?.defaultValue??y.locales?.[i]?.defaultValue,id:y.id,type:y.type},p},{}),[JSON.stringify(m),t,l,f,i]),n=v.useMemo(()=>{if(!m)return{canUseProperties:[],visibleProperties:[],canUsePropertiesKeys:[]};const p=z.default(Object.values(m),"index"),y=p.filter(({data:S})=>S.key&&Z(m,S.id)),P=p.filter(({data:S})=>S.key&&S.type!=="component"),I=P.map(({data:S})=>S.key);return{canUseProperties:P,visibleProperties:y,canUsePropertiesKeys:I}},[JSON.stringify(m)]),h=o(),j=tt.default(h,"key");return e.jsx(N.UploaderProvider,{children:e.jsxs(r.Stack,{sx:{gap:2},children:[e.jsx(r.Typography,{variant:"subtitle1",children:b("maker.properties.parameters")}),!t||n.canUsePropertiesKeys.length===0?e.jsx(U.default,{style:{fontSize:12},children:b("maker.properties.noParameters")}):e.jsxs(e.Fragment,{children:[e.jsx(r.Stack,{sx:{gap:2},children:n.visibleProperties.map(({data:p})=>e.jsx(r.Box,{children:e.jsx(F,{allComponents:s,defaultLocale:i,size:"small",fullWidth:!0,component:t,property:p,valueImmutable:J.default(l?.[p.id]?.value),value:d?.[p.key||p.id]??h[p.id]?.value,onChange:y=>{x({path:["properties",p.id],id:p.id,value:{value:y},shouldSync:ne(p),excludeKeys:[],key:p.key||p.id})}})},p.id))}),e.jsx(r.Stack,{sx:{gap:2,width:"100%"},children:e.jsx(K.CustomComponentRenderer,{componentId:t?.id||"",renderType:"setting",locale:f,properties:h,dev:{mode:"draft",components:s,defaultLocale:i},props:{...st.default(d??{},n.canUsePropertiesKeys),onChange:p=>{const{canUsePropertiesKeys:y}=n;Object.keys(p).filter(I=>!Ze.default(p[I],j?.[I]?.value)).filter(I=>!(I==="locale"&&!Xe.default(j[I],"locale")||j[I]?.type==="component"||(j[I]?.type==="yaml"||j[I]?.type==="json")&&Z(m,j[I]?.id))).reduce((I,S)=>I.then(()=>{const k=j[S],B=y.includes(S);if(k?.id&&B)return x({path:["properties",k.id],id:k.id,value:{value:p[S]},shouldSync:ne(k),excludeKeys:[],key:k.key||k.id}),Promise.resolve();const g=`propertyNotFound${S}`;if(a===g)return Promise.resolve();Q.default.close(a);const C=Q.default.warning(b("maker.properties.propertyNotFound",{key:S}),{key:g});return c(C),Promise.resolve()}),Promise.resolve())}}})})]})]})})}function Ot({config:t}){const{t:s,locale:i}=O.useLocaleContext(),[l,f]=v.useState(!1),x=d=>{t.llmConfig=d};return e.jsxs(e.Fragment,{children:[e.jsx(r.Tooltip,{title:s("maker.properties.configLLMDescription"),children:e.jsx(r.IconButton,{color:"primary",onClick:()=>f(!0),size:"small",children:e.jsx(V.PsychologyAlt,{})})}),l&&e.jsx(jt,{open:l,onClose:()=>f(!1),onConfirm:x,component:t,initialConfig:t.llmConfig,locale:i,defaultLocale:"en",title:s("maker.properties.llmConfigTitle")})]})}exports.BasicInfo=pe;exports.CustomComponentAutocomplete=H;exports.CustomComponentSettings=Ct;exports.DefaultReactComponentScriptTemplate=he;exports.DefaultWebComponentScriptTemplate=be;exports.ParametersConfig=re;exports.PropertiesConfig=me;exports.PropertyValueField=F;
10
+ }`,je=`console.log('hello')
11
+ `;function Tt({value:t}){const{locale:s}=O.useLocaleContext(),i=re.useUpdate(),l=L.getYjsValue(t).doc;return v.useEffect(()=>{t.renderer?.script||(l.transact(()=>{t.renderer.script=t.renderer.type==="react-component"?be:je}),i())},[t]),e.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:e.jsx(te.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 Bt({value:t}){const{t:s}=O.useLocaleContext(),i=L.getYjsValue(t).doc,{state:{components:l,config:{defaultLocale:f},resources:x},localState:{currentLocale:d}}=_.useStore(),b=_.useAllComponents(),m=l[t.renderer.componentId]?.data??x.components?.[t.renderer.componentId]?.component,u=A.usePopupState({variant:"dialog"});return e.jsx(N.UploaderProvider,{children:e.jsxs(r.Stack,{sx:{gap:1},children:[e.jsx(H,{allComponents:b,excludes:[t.id],value:t.renderer.componentId,onChange:(a,c)=>t.renderer.componentId=c}),m&&e.jsxs(e.Fragment,{children:[e.jsxs(r.Stack,{direction:"row",sx:{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},...A.bindTrigger(u),children:e.jsx(V.TranslateRounded,{fontSize:"small"})})]}),m.properties&&z.default(Object.values(m.properties),"index").map(({data:a})=>e.jsx(r.Box,{children:e.jsx(F,{allComponents:b,defaultLocale:f,component:m,property:a,fullWidth:!0,size:"small",valueImmutable:J.default(t.renderer.properties?.[a.id]?.locales?.[d]?.value),value:t.renderer.properties?.[a.id]?.locales?.[d]?.value??t.renderer.properties?.[a.id]?.locales?.[f]?.value??a.locales?.[d]?.defaultValue??a.locales?.[f]?.defaultValue,onChange:c=>{i.transact(()=>{t.renderer.properties??={},t.renderer.properties[a.id]??={},t.renderer.properties[a.id].locales??={},t.renderer.properties[a.id].locales[d]??={},t.renderer.properties[a.id].locales[d].value=c})}})},a.id)),e.jsx(he,{...A.bindDialog(u),component:t,type:"parameters"})]})]})})}function H({label:t,options:s,excludes:i,value:l,onChange:f,allComponents:x,...d}){const{t:b}=O.useLocaleContext(),m=s??z.default(Object.values(rt.default(x,...i??[])),"index").map(a=>a.data),u=(typeof l=="string"?x[l]?.data:void 0)??null;return e.jsx(r.Autocomplete,{...d,size:"small",options:m,autoHighlight:!0,isOptionEqualToValue:(a,c)=>a.id===c.id,getOptionKey:a=>a.id,getOptionLabel:a=>a.name||a.id,renderInput:a=>e.jsx(r.TextField,{label:t||b("component"),...a}),value:u,onChange:(a,c)=>{let o={};c&&(o={blockletId:x[c?.id]?.blockletId,blockletTitle:x[c?.id]?.blockletTitle,componentName:x[c?.id]?.data?.name||x[c?.id]?.data?.id}),f?.(a,c?.id,o)}})}function se({config:t,allComponents:s,defaultLocale:i,propertiesValue:l,currentLocale:f,onChange:x,props:d}){const{t:b}=O.useLocaleContext(),[m,u]=v.useState(Q.default(t?.properties)),[a,c]=v.useState(null);v.useEffect(()=>{(()=>{t?.renderer?.type==="react-component"&&D.default(t?.properties)?K.transpileAndLoadScript(t?.renderer?.script).then(y=>{const P=K.getPropertiesFromCode(y);u(P)}):u(Q.default(t?.properties))})()},[JSON.stringify(t)]);const o=v.useCallback(()=>!t||!m?{}:Object.values(m).reduce((p,{data:y})=>{const P=y.key||y.id;return p[y.id]={key:P,value:d?.[P]??l?.[y.id]?.value??y.locales?.[f]?.defaultValue??y.locales?.[i]?.defaultValue,id:y.id,type:y.type},p},{}),[JSON.stringify(m),t,l,f,i]),n=v.useMemo(()=>{if(!m)return{canUseProperties:[],visibleProperties:[],canUsePropertiesKeys:[]};const p=z.default(Object.values(m),"index"),y=p.filter(({data:S})=>S.key&&ee(m,S.id)),P=p.filter(({data:S})=>S.key&&S.type!=="component"),I=P.map(({data:S})=>S.key);return{canUseProperties:P,visibleProperties:y,canUsePropertiesKeys:I}},[JSON.stringify(m)]),h=o(),j=tt.default(h,"key");return e.jsx(N.UploaderProvider,{children:e.jsxs(r.Stack,{sx:{gap:2},children:[e.jsx(r.Typography,{variant:"subtitle1",children:b("maker.properties.parameters")}),!t||n.canUsePropertiesKeys.length===0?e.jsx(U.default,{style:{fontSize:12},children:b("maker.properties.noParameters")}):e.jsxs(e.Fragment,{children:[e.jsx(r.Stack,{sx:{gap:2},children:n.visibleProperties.map(({data:p})=>e.jsx(r.Box,{children:e.jsx(F,{allComponents:s,defaultLocale:i,size:"small",fullWidth:!0,component:t,property:p,valueImmutable:J.default(l?.[p.id]?.value),value:d?.[p.key||p.id]??h[p.id]?.value,onChange:y=>{x({path:["properties",p.id],id:p.id,value:{value:y},shouldSync:oe(p),excludeKeys:[],key:p.key||p.id})}})},p.id))}),e.jsx(r.Stack,{sx:{gap:2,width:"100%"},children:e.jsx(K.CustomComponentRenderer,{componentId:t?.id||"",renderType:"setting",locale:f,properties:h,dev:{mode:"draft",components:s,defaultLocale:i},props:{...st.default(d??{},n.canUsePropertiesKeys),onChange:p=>{const{canUsePropertiesKeys:y}=n;Object.keys(p).filter(I=>!Ze.default(p[I],j?.[I]?.value)).filter(I=>!(I==="locale"&&!Xe.default(j[I],"locale")||j[I]?.type==="component"||(j[I]?.type==="yaml"||j[I]?.type==="json")&&ee(m,j[I]?.id))).reduce((I,S)=>I.then(()=>{const k=j[S],B=y.includes(S);if(k?.id&&B)return x({path:["properties",k.id],id:k.id,value:{value:p[S]},shouldSync:oe(k),excludeKeys:[],key:k.key||k.id}),Promise.resolve();const g=`propertyNotFound${S}`;if(a===g)return Promise.resolve();X.default.close(a);const C=X.default.warning(b("maker.properties.propertyNotFound",{key:S}),{key:g});return c(C),Promise.resolve()}),Promise.resolve())}}})})]})]})})}function Ot({config:t}){const{t:s,locale:i}=O.useLocaleContext(),[l,f]=v.useState(!1),x=d=>{t.llmConfig=d};return e.jsxs(e.Fragment,{children:[e.jsx(r.Tooltip,{title:s("maker.properties.configLLMDescription"),children:e.jsx(r.IconButton,{color:"primary",onClick:()=>f(!0),size:"small",children:e.jsx(V.PsychologyAlt,{})})}),l&&e.jsx(jt,{open:l,onClose:()=>f(!1),onConfirm:x,component:t,initialConfig:t.llmConfig,locale:i,defaultLocale:"en",title:s("maker.properties.llmConfigTitle")})]})}exports.BasicInfo=xe;exports.CustomComponentAutocomplete=H;exports.CustomComponentSettings=Ct;exports.DefaultReactComponentScriptTemplate=be;exports.DefaultWebComponentScriptTemplate=je;exports.ParametersConfig=se;exports.PropertiesConfig=fe;exports.PropertyValueField=F;
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("./chunks/components-CacZMc0_.js");const e=require("./chunks/site-state-Vc48a38-.js"),u=require("@blocklet/pages-kit/utils/common");require("@blocklet/pages-kit/utils/page-model");require("@blocklet/pages-kit/utils/property");require("@blocklet/pages-kit/utils/route");require("@blocklet/sdk/lib/component");require("@blocklet/sdk/lib/config");require("@reactivedata/reactive");require("@syncedstore/core");require("fs");require("glob");require("lib0/decoding");require("lib0/encoding");require("lodash/cloneDeep");require("lodash/debounce");require("lodash/get");require("lodash/isEmpty");require("lodash/set");require("lodash/union");require("lru-cache");require("p-limit");require("path");require("sequelize");require("stream/promises");require("tar");require("ufo");require("wait-on");require("y-protocols/awareness");require("y-protocols/sync");require("yaml");require("yjs");const t=require("@blocklet/pages-kit/types/state");exports.PUBLISH_MODES=e.PUBLISH_MODES;exports.SITE_STATE_PATH=e.SITE_STATE_PATH;exports.STATE_MODES=e.STATE_MODES;exports.default=e.SiteState;exports.downloadAsset=e.downloadAsset;exports.downloadAssets=e.downloadAssets;exports.fromPackage=e.fromPackage;exports.getDefaultState=e.getDefaultState;exports.getResourceStates=e.getResourceStates;exports.initPackResourceStates=e.initPackResourceStates;exports.mergeState=e.mergeState;exports.toPackage=e.toPackage;exports.triggerReloadAllProjectResource=e.triggerReloadAllProjectResource;exports.updateResourceStatesByProjectId=e.updateResourceStatesByProjectId;Object.defineProperty(exports,"nextId",{enumerable:!0,get:()=>u.nextId});Object.keys(t).forEach(r=>{r!=="default"&&!Object.prototype.hasOwnProperty.call(exports,r)&&Object.defineProperty(exports,r,{enumerable:!0,get:()=>t[r]})});
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("./chunks/components-CacZMc0_.js");const e=require("./chunks/site-state-CkqENAbR.js"),u=require("@blocklet/pages-kit/utils/common");require("@blocklet/pages-kit/utils/page-model");require("@blocklet/pages-kit/utils/property");require("@blocklet/pages-kit/utils/route");require("@blocklet/sdk/lib/component");require("@blocklet/sdk/lib/config");require("@reactivedata/reactive");require("@syncedstore/core");require("fs");require("glob");require("lib0/decoding");require("lib0/encoding");require("lodash/cloneDeep");require("lodash/debounce");require("lodash/get");require("lodash/isEmpty");require("lodash/set");require("lodash/union");require("lru-cache");require("p-limit");require("path");require("sequelize");require("stream/promises");require("tar");require("ufo");require("wait-on");require("y-protocols/awareness");require("y-protocols/sync");require("yaml");require("yjs");const t=require("@blocklet/pages-kit/types/state");exports.PUBLISH_MODES=e.PUBLISH_MODES;exports.SITE_STATE_PATH=e.SITE_STATE_PATH;exports.STATE_MODES=e.STATE_MODES;exports.default=e.SiteState;exports.downloadAsset=e.downloadAsset;exports.downloadAssets=e.downloadAssets;exports.fromPackage=e.fromPackage;exports.getDefaultState=e.getDefaultState;exports.getResourceStates=e.getResourceStates;exports.initPackResourceStates=e.initPackResourceStates;exports.mergeState=e.mergeState;exports.toPackage=e.toPackage;exports.triggerReloadAllProjectResource=e.triggerReloadAllProjectResource;exports.updateResourceStatesByProjectId=e.updateResourceStatesByProjectId;Object.defineProperty(exports,"nextId",{enumerable:!0,get:()=>u.nextId});Object.keys(t).forEach(r=>{r!=="default"&&!Object.prototype.hasOwnProperty.call(exports,r)&&Object.defineProperty(exports,r,{enumerable:!0,get:()=>t[r]})});
@@ -7,7 +7,7 @@ import te from "@mui/icons-material/Check";
7
7
  import { Box as n, styled as H, Dialog as re, DialogTitle as ie, TextField as ne, IconButton as ae, DialogContent as se, Tabs as le, Tab as pe, Grid as N, Card as de, CardMedia as ce, CardContent as me, Typography as V, DialogActions as ue, Button as $, Skeleton as fe } from "@mui/material";
8
8
  import { useReactive as Q } from "ahooks";
9
9
  import { createContext as L, useMemo as M, useEffect as A, useRef as S } from "react";
10
- import { b as be, T as he, I as ge, B as xe } from "./chunks/index-aeMNll_R.js";
10
+ import { b as be, T as he, I as ge, B as xe } from "./chunks/index-BHQcp5eX.js";
11
11
  import { styled as m } from "@arcblock/ux/lib/Theme";
12
12
  import "@blocklet/pages-kit/builtin/color-picker";
13
13
  import "@blocklet/pages-kit/utils/style";
@@ -42,7 +42,7 @@ import "lodash/isEmpty";
42
42
  import "yaml";
43
43
  import "@mui/material/Typography";
44
44
  import "joi";
45
- import { createStatusApi as U, createTextCompletionApi as Ne } from "@blocklet/ai-kit/api";
45
+ import { createStatusApi as U, createTextCompletionApi as Ne } from "@blocklet/aigne-hub/api";
46
46
  import { createFetch as $e } from "@blocklet/js-sdk";
47
47
  import "@mui/x-date-pickers";
48
48
  import "@mui/x-date-pickers/AdapterDayjs";
@@ -21,7 +21,7 @@ import { Helmet as ke } from "react-helmet";
21
21
  import { useSearchParams as ee, Routes as Se, Route as S, Navigate as Ce, ScrollRestoration as Ie } from "react-router-dom";
22
22
  import { useAsync as te } from "react-use";
23
23
  import { joinURL as w } from "ufo";
24
- import { S as Te, P as je, a as Re, B as Oe, g as Ee } from "./index-aeMNll_R.js";
24
+ import { S as Te, P as je, a as Re, B as Oe, g as Ee } from "./index-BHQcp5eX.js";
25
25
  import Me from "@blocklet/ui-react/lib/Footer";
26
26
  import "webfontloader";
27
27
  import { u as Ae, a as Be } from "./session-C72Dq8zg.js";
@@ -114,7 +114,7 @@ function ze({ mode: t }) {
114
114
  }
115
115
  return /* @__PURE__ */ e(Ve, { children: ({ state: o }) => /* @__PURE__ */ e(F, { mode: t, state: o }) });
116
116
  }
117
- const Ue = X(() => import("./publish-button-BPtL08Ue.js")), Ve = X(() => import("./draft-data-CpCuyq4R.js"));
117
+ const Ue = X(() => import("./publish-button-CIVPDQb7.js")), Ve = X(() => import("./draft-data-CpCuyq4R.js"));
118
118
  function Ge({
119
119
  mode: t,
120
120
  children: o
@@ -0,0 +1,49 @@
1
+ import { createHash as a } from "crypto";
2
+ const s = async () => await import("cheerio"), o = {};
3
+ function u(t, e) {
4
+ const n = JSON.stringify([t, e]);
5
+ return a("md5").update(n).digest("hex");
6
+ }
7
+ async function l(t, e) {
8
+ {
9
+ let n = await s();
10
+ try {
11
+ const r = n.load(t);
12
+ return e.forEach((c) => {
13
+ r(c.selector.cheerio).replaceWith(c.value);
14
+ }), r.html();
15
+ } catch {
16
+ } finally {
17
+ n = null;
18
+ }
19
+ }
20
+ return i(t, e);
21
+ }
22
+ function i(t, e) {
23
+ let n = t;
24
+ return e.forEach((r) => {
25
+ const c = typeof r.selector.pattern == "string" ? new RegExp(r.selector.pattern, "gis") : r.selector.pattern;
26
+ n = n.replace(c, r.value);
27
+ }), n;
28
+ }
29
+ async function y(t, e) {
30
+ if (!e || e.length === 0)
31
+ return t;
32
+ const n = u(t, e);
33
+ return o[n] ??= l(t, e).finally(() => {
34
+ setTimeout(() => {
35
+ delete o[n];
36
+ }, 10 * 1e3);
37
+ }), o[n];
38
+ }
39
+ function f(t) {
40
+ return t.match(/<body[^>]*>(.*?)<\/body>/s)?.[1] || "";
41
+ }
42
+ function p(t, e) {
43
+ return !e || Object.keys(e).length === 0 ? !0 : Object.entries(e).every(([n, r]) => t.includes(`${n}=${r}`));
44
+ }
45
+ export {
46
+ f as e,
47
+ y as i,
48
+ p as m
49
+ };