@blocklet/pages-kit-inner-components 0.5.30 → 0.5.32

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.
Files changed (37) hide show
  1. package/lib/cjs/add-component.js +47 -23
  2. package/lib/cjs/chunks/array-DxhrK2d5.js +475 -0
  3. package/lib/cjs/chunks/{config-string-C4Q0hgG0.js → config-string-DqWgB7yO.js} +1 -1
  4. package/lib/cjs/chunks/{draft-data-Cu9gua-P.js → draft-data-DzN2u_NT.js} +1 -1
  5. package/lib/cjs/chunks/home-0fezWT4S.js +38 -0
  6. package/lib/cjs/chunks/{publish-button-DvwoFH1F.js → publish-button-D2jaaXXn.js} +1 -1
  7. package/lib/cjs/chunks/site-state-D5jk8eJT.js +57 -0
  8. package/lib/cjs/chunks/state-DoGBMTzI.js +1 -0
  9. package/lib/cjs/components.js +1 -1
  10. package/lib/cjs/home.js +1 -1
  11. package/lib/cjs/locales.js +3 -1
  12. package/lib/cjs/project-html.js +2 -2
  13. package/lib/cjs/resources.js +1 -1
  14. package/lib/cjs/setting.js +1 -1
  15. package/lib/cjs/site-state.js +1 -1
  16. package/lib/es/add-component.js +795 -749
  17. package/lib/es/chunks/array-D6qyZucY.js +2224 -0
  18. package/lib/es/chunks/{config-string-CNLg1EYu.js → config-string-Btybe5Rd.js} +1 -1
  19. package/lib/es/chunks/{draft-data-hSHLdxKp.js → draft-data-DQ7_JyJX.js} +1 -1
  20. package/lib/es/chunks/{home-CNk6U8FU.js → home-Dox9JwvF.js} +112 -96
  21. package/lib/es/chunks/{publish-button-BftBlabj.js → publish-button-T2YJBoty.js} +3 -3
  22. package/lib/es/chunks/{site-state-DJ3JcBMm.js → site-state-DEduMTrY.js} +505 -473
  23. package/lib/es/chunks/state-NhsHvaKm.js +605 -0
  24. package/lib/es/components.js +1 -1
  25. package/lib/es/home.js +3 -3
  26. package/lib/es/locales.js +46 -6
  27. package/lib/es/project-html.js +43 -42
  28. package/lib/es/resources.js +1 -1
  29. package/lib/es/setting.js +2 -2
  30. package/lib/es/site-state.js +1 -1
  31. package/package.json +10 -10
  32. package/lib/cjs/chunks/array-CJC7ex3i.js +0 -467
  33. package/lib/cjs/chunks/home-CimGvyT9.js +0 -38
  34. package/lib/cjs/chunks/site-state-DvIWP0pO.js +0 -57
  35. package/lib/cjs/chunks/state-jCG5gSUJ.js +0 -1
  36. package/lib/es/chunks/array-9j8tOSbO.js +0 -1993
  37. package/lib/es/chunks/state-D5BnGunt.js +0 -483
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),R=require("./chunks/state-jCG5gSUJ.js"),De=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),ie=require("@blocklet/code-editor"),Ee=require("@mui/icons-material/AddRounded"),Ve=require("@mui/icons-material/ArrowDownward"),ze=require("@mui/icons-material/ArrowUpward"),Ae=require("@mui/icons-material/DeleteOutline"),r=require("@mui/material"),Ne=require("lodash/sortBy"),C=require("react"),ke=require("react-use"),ye=require("@blocklet/pages-kit/builtin/color-picker"),qe=require("./chunks/config-string-C4Q0hgG0.js"),Fe=require("lodash/isEmpty"),Ue=require("lodash/set"),Me=require("yaml"),z=require("@blocklet/pages-kit/builtin/uploader"),We=require("lodash/cloneDeep"),Ke=require("@arcblock/ux/lib/Toast"),Q=require("@blocklet/pages-kit/components"),Le=require("@blocklet/pages-kit/utils/property"),Se=require("@mui/base"),D=require("@mui/icons-material"),Y=require("@syncedstore/core"),Pe=require("ahooks"),Je=require("lodash/assign"),He=require("lodash/get"),Ye=require("lodash/has"),$e=require("lodash/isEqual"),Ge=require("lodash/isNil"),Qe=require("lodash/isObject"),Xe=require("lodash/keyBy"),Ze=require("lodash/omit"),et=require("lodash/pick"),tt=require("lodash/reduce"),A=require("material-ui-popup-state/hooks"),rt=require("react-error-boundary"),st=require("@emotion/css"),te=require("react-dnd"),T=e=>e&&e.__esModule?e:{default:e};function lt(e){if(e&&e.__esModule)return e;const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const o=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(s,l,o.get?o:{enumerable:!0,get:()=>e[l]})}}return s.default=e,Object.freeze(s)}const Z=T(De),ot=T(Ee),it=T(Ve),nt=T(ze),ct=T(Ae),E=T(Ne),ne=T(Fe),we=T(Ue),re=lt(Me),at=T(We),se=T(Ke),ut=T(Je),dt=T(He),pt=T(Ye),mt=T($e),X=T(Ge),xt=T(Qe),ft=T(Xe),jt=T(Ze),bt=T(et),ht=T(tt);function yt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"warning",variant:"outlined",disabled:s,onClick:e,...o,children:t.jsx(ct.default,{fontSize:"small"})})}function gt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(nt.default,{fontSize:"small"})})}function vt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(it.default,{fontSize:"small"})})}function kt({label:e,value:s,onChange:l,disabled:o=!1,itemLabel:p="",emptyHeight:h=40,property:d,renderItem:g,...v}){const{t:b,locale:P}=_.useLocaleContext(),y=ke.useUpdate(),i=C.useCallback(m=>{l(R.transformValue(m,d.type))},[l,d.type]),n=C.useMemo(()=>Array.isArray(s)?s:[],[s]),c=C.useCallback(()=>{const m=[...n,""];i(m),y()},[n,i,y]),u=C.useCallback(()=>{if(!d||!d.subProperties)return c();const m={};E.default(Object.values(d.subProperties),"index").forEach(({data:B})=>{var N,q;if(!B.key)return;const V=((q=(N=B.locales)==null?void 0:N[P])==null?void 0:q.defaultValue)??"";m[B.key]=V});const O=[...n,m];i(O),y()},[n,i,y,d,P,c]),x=C.useCallback(m=>{try{const w=JSON.parse(m);Array.isArray(w)?i(w):console.error("JSON解析结果不是数组")}catch(w){console.error("JSON解析错误:",w)}},[i]),S=C.useCallback(m=>{const w=n.filter((O,B)=>B!==m);i(w),y()},[n,i,y]),a=C.useCallback(m=>{if(m<=0)return;const w=[...n],O=w[m];w[m]=w[m-1],w[m-1]=O,i(w),y()},[n,i,y]),j=C.useCallback(m=>{if(m>=n.length-1)return;const w=[...n],O=w[m];w[m]=w[m+1],w[m+1]=O,i(w),y()},[n,i,y]),f=C.useCallback((m,w)=>{const O=[...n];O[m]=w,i(O)},[n,i]),k=d&&d.subProperties&&Object.keys(d.subProperties).length>0,I=C.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:m})=>t.jsx(r.Typography,{variant:"body1",sx:{bgcolor:"action.hover",borderRadius:"50%",width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:m+1})},{field:"content",headerName:"",renderCell:({row:m,index:w})=>g&&k?g({item:m,index:w,property:d,onChange:O=>f(w,O)}):t.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:o,value:m,placeholder:p||`${b("item")} ${w+1}`,onChange:O=>f(w,O.target.value),...v})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:m})=>t.jsxs(r.Stack,{direction:"column",spacing:.25,children:[t.jsx(gt,{disabled:o||m===0,onClick:()=>a(m)}),t.jsx(vt,{disabled:o||m===n.length-1,onClick:()=>j(m)}),t.jsx(yt,{disabled:o,onClick:()=>S(m)})]})}],[g,k,d,f,p,b,o,v,S,a,j,n.length]);return k?t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),n.length>0?t.jsx(r.TableContainer,{component:r.Paper,variant:"outlined",sx:{borderRadius:1,mb:1},children:t.jsxs(r.Table,{size:"small",sx:{"& .MuiTableCell-root":{py:.25,px:1,whiteSpace:"nowrap"},"& .MuiTableCell-head":{backgroundColor:"action.hover",py:.25,px:1},borderCollapse:"collapse"},children:[t.jsx(r.TableHead,{sx:{display:"none"},children:t.jsx(r.TableRow,{children:I.map(m=>t.jsx(r.TableCell,{width:m.width,align:m.align||"left",sx:{fontWeight:"bold"},children:m.renderHeader?m.renderHeader():m.headerName},m.field))})}),t.jsx(r.TableBody,{children:n.map((m,w,O)=>t.jsx(r.TableRow,{sx:{borderBottom:w<O.length-1?"1px solid":"none",borderColor:"divider","&:hover":{backgroundColor:"action.hover"}},children:I.map(B=>t.jsx(r.TableCell,{width:B.width,align:B.align||"left",sx:{borderBottom:"none"},children:B.renderCell({row:m,index:w,onChange:V=>f(w,V)})},`${w}-${B.field}`))},w))})]})}):t.jsx(Z.default,{style:{fontSize:12,height:h},children:b("maker.properties.arrayEmpty")}),t.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:o,startIcon:t.jsx(ot.default,{}),onClick:u,children:b("maker.properties.addArrayItem")})]}):t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,minHeight:150},children:t.jsx(ie.CodeEditor,{keyId:d.id,locale:P,language:"json",value:JSON.stringify(n,null,2),onChange:m=>x(m||""),fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},d.id)})]})}function St({value:e,onChange:s,...l}){const o=C.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsx(qe.ConfigString,{...l,value:e,onChange:s,InputProps:{endAdornment:t.jsx(r.InputAdornment,{position:"end",children:t.jsx(ye.ColorItem,{color:e??"",style:{width:"1.5rem",height:"1.5rem",padding:0},onClick:()=>{var p;(p=o.current)==null||p.open({value:e??""})}})})}}),t.jsx(ye.ConfigColorDialog,{ref:o,onSave:({value:p},h)=>{s(p),h()}})]})}function Pt({label:e,value:s,onChange:l,property:o,component:p,defaultLocale:h,allComponents:d,PropertyValueField:g,onUpload:v}){const{locale:b}=_.useLocaleContext(),P=C.useRef(null);if(!ne.default(o.subProperties)){const i=E.default(Object.values(o.subProperties||{}),"index").filter(n=>n.data.visible!==!1&&n.data.key);return t.jsxs(r.Stack,{width:"100%",children:[t.jsx(r.FormLabel,{sx:{px:.25,py:.5},children:e}),t.jsx(r.Box,{children:t.jsx(r.Box,{sx:{position:"relative"},children:i.map((n,c)=>{const{data:u}=n,x=u.key??u.id,S=c===i.length-1;let a=null;try{s&&typeof s=="object"?a=s[x]:typeof s=="string"&&(a=(o.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}"))[x])}catch{}a==null&&(u.locales&&b&&u.locales[b]?a=u.locales[b].defaultValue:u.locales&&h&&u.locales[h]&&(a=u.locales[h].defaultValue));const j=k=>{try{let I={};if(typeof s=="string")try{I=o.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(I={...s});we.default(I,x,k);const m=R.transformValue(I,o.type);l==null||l(m)}catch(I){console.error("Error updating property:",I)}},f=8;return t.jsxs(r.Box,{sx:{mb:S?0:1,display:"flex",flexDirection:"row"},children:[t.jsxs(r.Box,{sx:{position:"relative",width:24,flexShrink:0},children:[t.jsx(r.Box,{sx:{position:"absolute",left:f,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),t.jsx(r.Box,{sx:{position:"absolute",left:f,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!S&&t.jsx(r.Box,{sx:{position:"absolute",left:f,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),t.jsx(r.Box,{sx:{flexGrow:1},children:t.jsx(g,{component:p,property:u,value:a,onChange:j,size:"small",fullWidth:!0,defaultLocale:h,allComponents:d})})]},u.id)})})})]})}return t.jsx(r.Stack,{width:"100%",gap:2,children:t.jsxs(r.Stack,{sx:{width:"100%",position:"relative",pt:1,pb:"6px",px:"1px",minHeight:50,".monaco-editor,.overflow-guard":{borderRadius:1}},children:[t.jsx(r.FormLabel,{sx:{position:"absolute",left:0,top:0,transform:"translate(0px, -7px) scale(0.75)"},children:e}),t.jsx(ie.CodeEditor,{keyId:o.id,locale:b,language:o.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:i=>{l==null||l(i)},onUpload:i=>{P.current=i,v&&v(i)},fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},o.id),t.jsx(r.Box,{component:"fieldset",sx:{pointerEvents:"none",position:"absolute",left:0,top:-5,width:"100%",height:"100%",border:1,borderColor:"rgba(0, 0, 0, 0.23)",borderRadius:1,px:1,py:0},children:t.jsx(r.Box,{component:"legend",sx:{fontSize:"0.75em"},children:t.jsx(r.Box,{component:"span",sx:{opacity:0},children:e})})})]})})}const wt=["string","multiline","json","yaml","url","component","custom","array"];function ge(e){return e.type?!wt.includes(e.type):!1}function Ie({disabled:e,list:s,renderItem:l,...o}){const p=C.useRef(null),h=C.useId(),d=Pe.useUpdate(),g=E.default(Object.entries(s),n=>n[1].index).map(n=>n[0]),v=C.useRef(g),b=C.useCallback(n=>{v.current=n,d()},[d]),P=C.useCallback(({index:n},{index:c})=>{const u=[...v.current];u.splice(c,0,...u.splice(n,1)),b(u)},[b]);C.useEffect(()=>{b(g)},[g.join("-")]);const[{isOver:y},i]=te.useDrop({accept:h,collect:n=>({isOver:n.isOver()}),canDrop:()=>!e,drop:()=>{var u;const n=()=>{v.current.forEach((x,S)=>{const a=s[x];a&&(a.index=S)})},c=(u=Y.getYjsValue(s))==null?void 0:u.doc;c?c.transact(()=>{n()}):n()}});return C.useEffect(()=>{y||b(g)},[y]),i(p),t.jsx(r.Box,{...o,ref:p,className:st.cx(y&&"isDragging"),children:v.current.map((n,c)=>t.jsx(It,{type:h,disabled:e,id:n,index:c,itemIndex:u=>v.current.indexOf(u),move:P,children:u=>{const x=s[n];return x?l(x.data,c,u):null}},n))})}function It({disabled:e,id:s,index:l,type:o,children:p,itemIndex:h,move:d}){const g=C.useRef(),[{isDragging:v},b,P]=te.useDrag({type:o,item:()=>({id:s}),canDrag:()=>!e,collect:i=>({isDragging:i.isDragging()})}),[,y]=te.useDrop({accept:o,canDrop:()=>!e,hover(i,n){var f;if(!g.current)return;const c=h(i.id),u=l;if(c===u)return;const x=(f=g.current)==null?void 0:f.getBoundingClientRect(),S=(x.bottom-x.top)/2,j=n.getClientOffset().y-x.top;c<u&&j<S||c>u&&j>S||d({id:i.id,index:c},{id:s,index:l})}});return typeof p=="function"?p({isDragging:v,drag:b,drop:i=>(g.current=i,y(i)),preview:P}):(b(y(P(g))),t.jsx(r.Box,{ref:g,children:p}))}function Ct({drop:e,preview:s,drag:l,disabled:o,isDragging:p,children:h,onDelete:d,onVisibilityChange:g,visible:v=!0,actions:b,alwaysShowActions:P=!1}){const{t:y}=_.useLocaleContext();return t.jsx(r.Box,{ref:e,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:v?1:.5},children:t.jsxs(r.Box,{sx:{position:"relative"},children:[t.jsx(r.Box,{ref:s,sx:{flex:1,borderRadius:.5,bgcolor:p?"action.hover":"background.paper",opacity:.9999},children:h}),!o&&t.jsx(r.Box,{className:P?"":"hover-visible",sx:{maxWidth:P?"100%":0,overflow:"hidden",position:"absolute",right:2,top:2,transition:"max-width 0.3s ease-in-out"},children:t.jsxs(r.Stack,{direction:"row",sx:{bgcolor:i=>r.alpha(i.palette.grey[200],.9),borderRadius:1,p:.5,[`.${r.buttonClasses.root}`]:{minWidth:24,width:24,height:24,p:0}},children:[b,g&&t.jsx(r.Tooltip,{title:y(v?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:()=>g(!v),children:v?t.jsx(D.VisibilityOffRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}}):t.jsx(D.VisibilityRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),d&&t.jsx(r.Tooltip,{title:y("delete"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:d,children:t.jsx(D.DeleteOutlineRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),t.jsx(r.Tooltip,{title:y("dragSort"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{ref:l,children:t.jsx(D.DragIndicatorRounded,{sx:{color:"grey.500"}})})})]})})]})})}function Ot({label:e,value:s,onChange:l}){const[o,p]=C.useState(!1);return t.jsxs(r.Stack,{gap:1,children:[t.jsx(r.TextField,{label:e,size:"small",value:s,onChange:h=>l==null?void 0:l(h.target.value),InputProps:{endAdornment:t.jsx(z.UploaderButton,{onChange:({response:h})=>{var g;const d=(g=h==null?void 0:h.data)==null?void 0:g.filename;d&&(l==null||l(d))}})}}),s&&t.jsx(r.Box,{component:"img",sx:{objectFit:"contain",borderRadius:1,cursor:"pointer"},src:R.getImageAbsoluteUrl(s),alt:e,maxWidth:100,maxHeight:100,width:"100%",onClick:()=>p(!0)}),t.jsx(r.Dialog,{open:o,onClose:()=>p(!1),children:t.jsx(r.Box,{component:"img",sx:{objectFit:"contain"},src:R.getImageAbsoluteUrl(s),alt:e})})]})}function le(e,s=""){return ht.default(e,(l,o,p)=>{const h=s?`${s}.${p}`:p;return xt.default(o)?ut.default(l,le(o,h)):l[h]=o,l},{})}const Tt=[{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 G(e,s,l){return!e||!l?!1:Object.values(e).some(({data:o})=>o.id!==s&&o.key===l)}function oe(e,s){var l;return!e||!s?!1:((l=e[s])==null?void 0:l.data.visible)??!0}function Bt({componentId:e}){const{state:{components:s}}=R.useStore(),l=s[e],o=l==null?void 0:l.data;return o?t.jsx(r.Stack,{maxHeight:"100%",overflow:"auto",children:t.jsx(r.Box,{p:2,children:t.jsx(rt.ErrorBoundary,{FallbackComponent:R.ErrorView,resetKeys:[e],children:t.jsx(Rt,{value:o})})})}):null}function Rt({value:e}){var b,P,y;const{t:s}=_.useLocaleContext(),{localState:{currentLocale:l,customComponentPreviewerProperties:o},state:{config:{defaultLocale:p}},localActions:{setCustomComponentPreviewerProperties:h}}=R.useStore(),d=Y.getYjsValue(e).doc,g=R.useAllComponents(),v=Pe.useReactive({propertiesValue:{...h}});return C.useEffect(()=>{const i=Object.fromEntries(Object.values(e.properties??{}).map(({data:n})=>{var c,u,x,S,a;return[n.id,{value:((c=v.propertiesValue[n.id])==null?void 0:c.value)??Le.parsePropertyValue(n,((x=(u=n.locales)==null?void 0:u[l])==null?void 0:x.defaultValue)??((a=(S=n.locales)==null?void 0:S[p])==null?void 0:a.defaultValue),{locale:l,defaultLocale:p})}]}));h(i)},[JSON.stringify(v.propertiesValue)]),t.jsx(r.Stack,{height:"100%",children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(Ce,{config:e}),t.jsx(Te,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,onUpdateConfig:i=>{d.transact(()=>{i(e)})}}),t.jsxs(r.Stack,{gap:2,direction:"row",justifyContent:"space-between",alignItems:"center",children:[t.jsx(r.Typography,{variant:"subtitle1",children:s("renderer")}),t.jsxs(r.TextField,{hiddenLabel:!0,size:"small",select:!0,SelectProps:{autoWidth:!0},value:((b=e.renderer)==null?void 0:b.type)||"react-component",onChange:i=>{d.transact(()=>{const n=i.target.value;e.renderer??(e.renderer={type:n}),e.renderer.type=n})},children:[t.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),t.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),((P=e.renderer)==null?void 0:P.type)==="component"&&t.jsx(Nt,{value:e}),((y=e.renderer)==null?void 0:y.type)==="react-component"&&t.jsx(At,{value:e}),t.jsx(ce,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,propertiesValue:o,onChange:({value:i,id:n,path:c})=>{const u=[...c,"data"];if(!dt.default(e,u)){se.default.warning(s("cannotFindPropertyKey",{key:u.join(".")}));return}v.propertiesValue[n]={value:i.value}}})]})})}function Ce({config:e}){const{t:s}=_.useLocaleContext();return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(r.Typography,{variant:"subtitle1",children:s("basicInfo")}),t.jsx(r.TextField,{label:s("name"),size:"small",value:e.name||"",onChange:l=>e.name=l.target.value}),t.jsx(r.TextField,{label:s("description"),size:"small",multiline:!0,minRows:2,maxRows:10,inputProps:{maxLength:200},value:e.description||"",onChange:l=>e.description=l.target.value}),t.jsx(r.Autocomplete,{size:"small",options:[],multiple:!0,freeSolo:!0,value:e.tags??[],onChange:(l,o)=>e.tags=o,renderInput:l=>t.jsx(r.TextField,{label:s("tags"),...l})}),t.jsx(Ot,{label:s("previewImage"),value:e.previewImage||"",onChange:l=>e.previewImage=l})]})})}function Oe({data:e,params:s,visible:l,config:o,currentLocale:p,defaultLocale:h,allComponents:d,onUpdateConfig:g}){var P,y,i,n,c,u;const{t:v}=_.useLocaleContext(),b=C.useMemo(()=>e.type==="json"||e.type==="yaml"||e.type==="array"?Vt:U,[e.type]);return t.jsx(Ct,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{g(x=>{if(x.properties){const a=Object.entries(x.properties).sort(([,f],[,k])=>f.index-k.index);delete x.properties[e.id],a.filter(([f])=>f!==e.id).forEach(([,f],k)=>{f.index=k})}})},visible:l,onVisibilityChange:x=>{g(S=>{const a=S.properties[e.id].data;a.visible=x})},alwaysShowActions:!0,children:t.jsxs(r.Stack,{direction:"column",gap:2,children:[t.jsx(r.TextField,{label:v("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:e.key?G(o.properties,e.id,e.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:e.key?G(o.properties,e.id,e.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:e.key?G(o.properties,e.id,e.key)?"warning.main":"primary.main":"error.main"}},value:e.key||"",onChange:x=>{g(S=>{const a=S.properties[e.id].data;a.key=x.target.value.trim()})},InputProps:{endAdornment:!e.key||e.key&&G(o.properties,e.id,e.key)?t.jsx(r.InputAdornment,{position:"end",sx:{width:16,ml:0},children:t.jsx(r.Tooltip,{title:e.key?v("duplicateKey"):v("requiredKey"),children:t.jsx(D.InfoRounded,{sx:{color:e.key?"warning.main":"error.main",fontSize:16}})})}):null}}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(r.TextField,{label:v("label"),size:"small",sx:{flex:1},value:(((y=(P=e.locales)==null?void 0:P[p])==null?void 0:y.name)??((n=(i=e.locales)==null?void 0:i[h])==null?void 0:n.name))||"",onChange:x=>{g(S=>{var j;const a=S.properties[e.id].data;a.locales??(a.locales={}),(j=a.locales)[p]??(j[p]={}),a.locales[p].name=x.target.value})}}),t.jsx(r.TextField,{label:v("type"),size:"small",select:!0,sx:{flex:1},value:e.type==="string"&&e.multiline?"multiline":e.type||"string",onChange:x=>{g(S=>{const a=S.properties[e.id].data;if(a.locales)for(const f of Object.keys(a.locales))a.locales[f].defaultValue=void 0;const j=x.target.value;j==="multiline"?(a.type="string",a.multiline=!0):(typeof a.multiline<"u"&&delete a.multiline,a.type=j)})},children:Tt.map(x=>t.jsx(r.MenuItem,{value:x.value,children:x.label},x.value))})]}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(b,{allComponents:d,defaultLocale:h,component:o,property:e,label:v("defaultValue"),size:"small",fullWidth:!0,value:(u=(c=e.locales)==null?void 0:c[p])==null?void 0:u.defaultValue,onChange:(x,S)=>{g(a=>{var f;const j=a.properties[e.id].data;if(S!=null&&S.forceUpdateProperty){const k=le(j),I=le(x);Object.keys(I).forEach(m=>{k[m]||we.default(j,m,I[m])})}else j.locales??(j.locales={}),(f=j.locales)[p]??(f[p]={}),j.locales[p].defaultValue=x})}}),e.type==="custom"?t.jsx(r.Box,{children:t.jsx(Dt,{property:e,allComponents:d})}):null]})]})})}function _t(e,s){const[l,o]=C.useState(0);return C.useEffect(()=>{const h=setTimeout(()=>{if(e.current){let d=e.current.parentElement,g=0;for(;d;)d.classList.contains("property-container")&&g++,d=d.parentElement;o(g)}},100);return()=>clearTimeout(h)},[e,s]),l}function Te({config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p,useI18nEditor:h=!0}){const{t:d}=_.useLocaleContext(),g=A.usePopupState({variant:"dialog"}),v=e.properties&&E.default(Object.values(e.properties),"index");return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsxs(r.Stack,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between",children:[t.jsx(r.Typography,{variant:"subtitle1",children:d("properties")}),t.jsx(r.Box,{flex:1}),h&&t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...A.bindTrigger(g),children:t.jsx(D.TranslateRounded,{fontSize:"small"})})]}),e.properties&&Object.keys(e.properties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.properties,renderItem:(b,P,y)=>{const i=oe(e.properties,b.id);return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:i?"1px solid":"1px dashed",borderColor:"divider"},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:y,visible:i,config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12},children:d("maker.properties.noProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",onClick:()=>{p(b=>{var y;const P=R.nextId();b.properties??(b.properties={}),(y=b.properties)[P]??(y[P]={index:(v==null?void 0:v.length)||0,data:{id:P}})})},startIcon:t.jsx(D.AddRounded,{}),children:d("addObject",{object:d("property")})}),h&&t.jsx(Be,{...A.bindDialog(g),component:e})]})})}function Dt({property:e,allComponents:s}){const l=A.usePopupState({variant:"popper"});return t.jsxs(t.Fragment,{children:[t.jsx(r.Button,{sx:{minWidth:0},...A.bindTrigger(l),children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Popper,{...A.bindPopper(l),children:t.jsx(Se.ClickAwayListener,{onClickAway:l.close,children:t.jsx(r.Paper,{children:t.jsx(r.Box,{width:500,p:2,children:t.jsx(ee,{value:e.componentId,onChange:(o,p)=>e.componentId=p,allComponents:s})})})})})]})}function Et({value:e,valueImmutable:s,onChange:l,defaultLocale:o,allComponents:p}){var P;const[h,d]=C.useState(!1),{t:g,locale:v}=_.useLocaleContext(),b=typeof(e==null?void 0:e.componentId)=="string"?(P=p[e.componentId])==null?void 0:P.data:void 0;return b?t.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[t.jsx(r.IconButton,{sx:{minWidth:0},disabled:!b,size:"small",onClick:()=>d(!h),color:h?"primary":"default",children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),h&&t.jsx(r.Collapse,{in:h,timeout:"auto",unmountOnExit:!0,sx:{width:"100%",zIndex:10},children:t.jsxs(r.Paper,{elevation:1,sx:{mt:1,p:2,borderRadius:1,border:"1px solid",borderColor:"divider",width:"100%"},children:[t.jsx(r.Box,{width:"100%",mb:2,children:t.jsx(ce,{config:b,currentLocale:v,defaultLocale:o,allComponents:p,propertiesValue:e==null?void 0:e.properties,onChange:({id:y,value:i})=>{const n=at.default(i.value),c=JSON.parse(JSON.stringify(e));c!=null&&c.componentId&&(s?l==null||l({...c,properties:{...c.properties,[y]:{value:n}}}):(c.properties=c.properties??{},c.properties[y]={value:n},l==null||l(c)))}})}),t.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:g("close")})]})})]}):null}function Be({type:e="properties",component:s,...l}){var y,i,n;const{t:o}=_.useLocaleContext(),{state:{components:p,supportedLocales:h,config:{defaultLocale:d}}}=R.useStore(),g=R.useAllComponents(),v=Y.getYjsValue(s).doc,b=e==="properties"?s.properties:e==="parameters"&&((y=s.renderer)==null?void 0:y.type)==="component"?(i=p[s.renderer.componentId])==null?void 0:i.data.properties:void 0,P=((n=s.renderer)==null?void 0:n.type)==="component"?s:void 0;return t.jsxs(r.Dialog,{...l,fullWidth:!0,maxWidth:"lg",children:[t.jsx(r.DialogTitle,{children:o("i18nEditorTitle")}),t.jsx(r.DialogContent,{children:b&&t.jsx(r.Stack,{children:t.jsxs(r.Table,{stickyHeader:!0,sx:{td:{verticalAlign:"top"}},children:[t.jsx(r.TableHead,{children:t.jsx(r.TableRow,{children:h.map(({locale:c,name:u})=>t.jsx(r.TableCell,{children:t.jsxs(r.Typography,{color:"text.primary",children:[u,d===c&&t.jsx(D.StarRounded,{sx:{fontSize:12}})]})},c))})}),t.jsx(r.TableBody,{children:E.default(Object.values(b),"index").map(({data:c})=>t.jsx(r.TableRow,{children:h.map(({locale:u})=>{var x,S,a,j,f,k,I,m,w,O,B,V,N,q,$,W,K,L,J,H,ae,ue,de,pe,me,xe;return t.jsx(r.TableCell,{children:t.jsx(r.Stack,{gap:1,children:e==="properties"?t.jsxs(t.Fragment,{children:[t.jsx(r.TextField,{size:"small",label:"Key",value:c.key||"",onChange:M=>{v.transact(()=>{c.key=M.target.value.trim()})}}),t.jsx(r.TextField,{size:"small",label:o("label"),value:(((S=(x=c.locales)==null?void 0:x[u])==null?void 0:S.name)??((j=(a=c.locales)==null?void 0:a[d])==null?void 0:j.name))||"",onChange:M=>{v.transact(()=>{var F;c.locales??(c.locales={}),(F=c.locales)[u]??(F[u]={}),c.locales[u].name=M.target.value})}}),t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:X.default((k=(f=c.locales)==null?void 0:f[u])==null?void 0:k.defaultValue),value:((m=(I=c.locales)==null?void 0:I[u])==null?void 0:m.defaultValue)??((O=(w=c.locales)==null?void 0:w[d])==null?void 0:O.defaultValue),onChange:M=>{v.transact(()=>{var F;c.locales??(c.locales={}),(F=c.locales)[u]??(F[u]={}),c.locales[u].defaultValue=M})}})})]}):e==="parameters"&&P?t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,valueImmutable:X.default((q=(N=(V=(B=P.renderer.properties)==null?void 0:B[c.id])==null?void 0:V.locales)==null?void 0:N[u])==null?void 0:q.value),value:((L=(K=(W=($=P.renderer.properties)==null?void 0:$[c.id])==null?void 0:W.locales)==null?void 0:K[u])==null?void 0:L.value)??((ue=(ae=(H=(J=P.renderer.properties)==null?void 0:J[c.id])==null?void 0:H.locales)==null?void 0:ae[d])==null?void 0:ue.value)??((pe=(de=c.locales)==null?void 0:de[u])==null?void 0:pe.defaultValue)??((xe=(me=c.locales)==null?void 0:me[d])==null?void 0:xe.defaultValue),onChange:M=>{v.transact(()=>{var F,fe,je,be,he;(F=P.renderer).properties??(F.properties={}),(fe=P.renderer.properties)[je=c.id]??(fe[je]={}),(be=P.renderer.properties[c.id]).locales??(be.locales={}),(he=P.renderer.properties[c.id].locales)[u]??(he[u]={}),P.renderer.properties[c.id].locales[u].value=M})}})}):null},c.id)},u)})},c.id))})]})})}),t.jsx(r.DialogActions,{children:t.jsx(r.Button,{onClick:c=>{var u;return(u=l.onClose)==null?void 0:u.call(l,c,"escapeKeyDown")},children:o("close")})})]})}const ve=(e,s)=>l=>{const o=[l.palette.info.main,l.palette.primary.main,l.palette.secondary.main,l.palette.success.main,l.palette.warning.main],p=Math.min(o.length-1,e),h=o[p],d=r.alpha(h,.5),g=r.alpha(h,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:g,...s}};function Vt({property:e,onChange:s,defaultLocale:l,allComponents:o}){const{t:p,locale:h}=_.useLocaleContext(),d=C.useRef(null),g=_t(d,e),v=C.useCallback(()=>{if(!(e.type!=="json"&&e.type!=="yaml"&&e.type!=="array")&&e.subProperties)try{let b={};E.default(Object.values(e.subProperties),"index").filter(i=>i.data.visible!==!1&&i.data.key).forEach(({data:i})=>{var c,u,x,S;if(!i.key)return;let n=((u=(c=i.locales)==null?void 0:c[h])==null?void 0:u.defaultValue)??((S=(x=i.locales)==null?void 0:x[l])==null?void 0:S.defaultValue);if(i.type==="number")n=Number(n);else if(i.type==="boolean")n=n===!0||n==="true";else if((i.type==="json"||i.type==="yaml")&&typeof n=="string")try{i.type==="json"?n=JSON.parse(n):n=re.parse(n)}catch(a){console.error("Error parsing nested value",n,a),n={}}b[i.key]=n}),e.type==="array"&&!Array.isArray(b)&&(b=ne.default(b)?[]:[b]);const y=R.transformValue(b,e.type);s==null||s(y)}catch(b){console.error("Error converting structure to text:",b)}},[e,h,l,s]);return e.type!=="json"&&e.type!=="yaml"&&e.type!=="array"?null:t.jsxs(r.Stack,{direction:"column",gap:1.5,sx:{width:"100%"},ref:d,children:[t.jsx(r.Divider,{sx:{mt:-1},children:t.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:p("maker.properties.subProperties")})}),e.subProperties&&Object.keys(e.subProperties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.subProperties,renderItem:(b,P,y)=>{const i=b.visible!==!1;return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:i?"1px solid":"1px dashed","&":ve(g)},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:y,visible:i,config:{properties:e.subProperties},currentLocale:h,defaultLocale:l,allComponents:o,onUpdateConfig:n=>{try{const c={properties:e.subProperties||{}};n(c);const u={...e,subProperties:c.properties};s==null||s(u,{forceUpdateProperty:!0}),v()}catch(c){console.error("Error updating property:",c)}}})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12,height:100},children:p("maker.properties.noSubProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",size:"small",startIcon:t.jsx(D.AddRounded,{}),onClick:()=>{try{const b=e.subProperties||{},P=R.nextId(),i={index:Object.values(b).length,data:{id:P,key:"",type:"string",visible:!0,locales:{[h]:{name:"",defaultValue:""}},subProperties:{}}},n={...e,subProperties:{...b,[P]:i}};s==null||s(n,{forceUpdateProperty:!0}),v()}catch(b){console.error("Error adding property:",b)}},sx:{"&":ve(g,{})},children:p("maker.properties.addSubProperty")})]})}function U({component:e,property:s,value:l,onChange:o,valueImmutable:p,defaultLocale:h,allComponents:d,...g}){var n,c,u,x,S;const{locale:v}=_.useLocaleContext(),b=z.useUploader(),P=C.useRef(null),y=()=>{var j;const a=(j=b==null?void 0:b.current)==null?void 0:j.getUploader();a==null||a.open(),P.current&&a.onceUploadSuccess(({response:f})=>{var I,m;let k=((I=f==null?void 0:f.data)==null?void 0:I.filename)||"";k&&(k=`mediakit://${k}`,l&&!l.includes("mediakit://")&&(k+=" # please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address")),(m=P.current)==null||m.call(P,k)})},i=g.label??(((c=(n=s.locales)==null?void 0:n[v])==null?void 0:c.name)||((x=(u=s.locales)==null?void 0:u[h])==null?void 0:x.name)||s.key||s.id);if(s.type==="number")return t.jsx(zt,{...g,label:i,NumberProps:{value:["number","string"].includes(typeof l)?l:null,onChange:(a,j)=>o==null?void 0:o(j)}});if(s.type==="decimal")return t.jsx(r.TextField,{...g,label:i,type:"text",value:l??"",onChange:a=>{const j=a.target.value;if(j===""||j==="-"){o==null||o(j);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(j)){let k=j;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(k)&&(k=Number(k)),o==null||o(k)}}});if(s.type==="boolean")return t.jsx(r.FormControlLabel,{label:i,labelPlacement:"start",control:t.jsx(r.Switch,{checked:l===!0,onChange:(a,j)=>o==null?void 0:o(j)})});if(s.type==="color")return t.jsx(St,{label:i,value:l,onChange:a=>{o==null||o(a)}});if(s.type==="json"||s.type==="yaml")return t.jsx(Pt,{label:i,value:l,onChange:a=>{o==null||o(a)},property:s,component:e,defaultLocale:h,allComponents:d,PropertyValueField:U,onUpload:a=>{P.current=a,y()}});if(s.type==="custom"){const a=(S=d[s.componentId])==null?void 0:S.data;return a?t.jsx(r.Box,{width:"100%",children:t.jsx(Q.CustomComponentRenderer,{componentId:a.id,props:{label:i,value:l,onChange:o},locale:v,dev:{mode:"draft",components:d,defaultLocale:h}})}):t.jsx(r.TextField,{...g,label:i,disabled:!0,placeholder:"Click right button select a component"})}if(s.type==="component")return t.jsxs(r.Stack,{width:"100%",direction:"column",gap:1,children:[t.jsx(ee,{allComponents:d,label:i,value:l==null?void 0:l.componentId,onChange:(a,j)=>{p||!l?o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:j}):typeof l=="object"&&(l.componentId=j,o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:j}))}}),(l==null?void 0:l.componentId)&&t.jsx(Et,{value:l,valueImmutable:p,onChange:o,defaultLocale:h,allComponents:d})]});if(!s.type||["string","url","multiline"].includes(s.type)){let a=s.type==="string"?s.multiline:void 0;s.type==="multiline"&&(a=!0);const j=s.type==="url"?l==null?void 0:l.url:l;return t.jsx(r.TextField,{...g,label:i,value:typeof j=="string"?j:"",multiline:a,minRows:a?2:void 0,maxRows:a?10:void 0,onChange:f=>o==null?void 0:o(s.type==="url"?{...l,url:f.target.value,mediaKitUrl:f.target.value}:f.target.value),InputProps:s.type==="url"?{sx:{pr:0},endAdornment:t.jsxs(r.InputAdornment,{position:"end",children:[t.jsx(z.UploaderButton,{onChange:async({response:f})=>{var w,O,B;const k=((w=f==null?void 0:f.data)==null?void 0:w.url)||((O=f==null?void 0:f.data)==null?void 0:O.fileUrl);let I;k&&(I=await z.getImageSize(k).catch(()=>z.getVideoSize(k)).catch(()=>{}));let m=((B=f==null?void 0:f.data)==null?void 0:B.filename)||"";m&&(m=`mediakit://${m}`),o==null||o({url:k,mediaKitUrl:m,width:I==null?void 0:I.naturalWidth,height:I==null?void 0:I.naturalHeight})}}),t.jsx(r.Tooltip,{title:"If you are using the 'mediaKitUrl' property, please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address.",children:t.jsx(D.InfoRounded,{sx:{cursor:"default",mr:1},fontSize:"small"})})]})}:void 0})}return s.type==="array"?t.jsx(kt,{label:i,value:Array.isArray(l)?l:[],onChange:a=>o==null?void 0:o(a),property:s,renderItem:({item:a,index:j,onChange:f})=>s.subProperties&&Object.keys(s.subProperties).length>0?t.jsx(r.Stack,{gap:1,width:"100%",children:E.default(Object.values(s.subProperties),"index").filter(k=>k.data.visible!==!1).map(({data:k})=>k.key?t.jsx(U,{component:e,property:k,value:a[k.key],onChange:I=>{const m={...a,[k.key]:I};f(m)},size:"small",fullWidth:!0,defaultLocale:h,allComponents:d},k.id):null)},j):t.jsx(r.TextField,{size:g.size,fullWidth:!0,value:a,onChange:k=>f(k.target.value)})}):(console.error("Unsupported property type",s.type),null)}function zt({NumberProps:e,...s}){const{getInputProps:l}=Se.unstable_useNumberInput(e),o=l();return t.jsx(r.TextField,{...s,inputProps:o})}const Re=`import React from '@blocklet/pages-kit/builtin/react'
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),R=require("./chunks/state-DoGBMTzI.js"),De=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),ie=require("@blocklet/code-editor"),Ee=require("@mui/icons-material/AddRounded"),Ve=require("@mui/icons-material/ArrowDownward"),ze=require("@mui/icons-material/ArrowUpward"),Ae=require("@mui/icons-material/DeleteOutline"),r=require("@mui/material"),Ne=require("lodash/sortBy"),C=require("react"),ke=require("react-use"),ye=require("@blocklet/pages-kit/builtin/color-picker"),qe=require("./chunks/config-string-DqWgB7yO.js"),Fe=require("lodash/isEmpty"),Ue=require("lodash/set"),Me=require("yaml"),z=require("@blocklet/pages-kit/builtin/uploader"),We=require("lodash/cloneDeep"),Ke=require("@arcblock/ux/lib/Toast"),Q=require("@blocklet/pages-kit/components"),Le=require("@blocklet/pages-kit/utils/property"),Se=require("@mui/base"),D=require("@mui/icons-material"),Y=require("@syncedstore/core"),Pe=require("ahooks"),Je=require("lodash/assign"),He=require("lodash/get"),Ye=require("lodash/has"),$e=require("lodash/isEqual"),Ge=require("lodash/isNil"),Qe=require("lodash/isObject"),Xe=require("lodash/keyBy"),Ze=require("lodash/omit"),et=require("lodash/pick"),tt=require("lodash/reduce"),A=require("material-ui-popup-state/hooks"),rt=require("react-error-boundary"),st=require("@emotion/css"),te=require("react-dnd"),T=e=>e&&e.__esModule?e:{default:e};function lt(e){if(e&&e.__esModule)return e;const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const o=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(s,l,o.get?o:{enumerable:!0,get:()=>e[l]})}}return s.default=e,Object.freeze(s)}const Z=T(De),ot=T(Ee),it=T(Ve),nt=T(ze),ct=T(Ae),E=T(Ne),ne=T(Fe),we=T(Ue),re=lt(Me),at=T(We),se=T(Ke),ut=T(Je),dt=T(He),pt=T(Ye),mt=T($e),X=T(Ge),xt=T(Qe),ft=T(Xe),jt=T(Ze),bt=T(et),ht=T(tt);function yt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"warning",variant:"outlined",disabled:s,onClick:e,...o,children:t.jsx(ct.default,{fontSize:"small"})})}function gt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(nt.default,{fontSize:"small"})})}function vt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(it.default,{fontSize:"small"})})}function kt({label:e,value:s,onChange:l,disabled:o=!1,itemLabel:p="",emptyHeight:h=40,property:d,renderItem:g,...v}){const{t:b,locale:P}=_.useLocaleContext(),y=ke.useUpdate(),i=C.useCallback(m=>{l(R.transformValue(m,d.type))},[l,d.type]),n=C.useMemo(()=>Array.isArray(s)?s:[],[s]),c=C.useCallback(()=>{const m=[...n,""];i(m),y()},[n,i,y]),u=C.useCallback(()=>{if(!d||!d.subProperties)return c();const m={};E.default(Object.values(d.subProperties),"index").forEach(({data:B})=>{var N,q;if(!B.key)return;const V=((q=(N=B.locales)==null?void 0:N[P])==null?void 0:q.defaultValue)??"";m[B.key]=V});const O=[...n,m];i(O),y()},[n,i,y,d,P,c]),x=C.useCallback(m=>{try{const w=JSON.parse(m);Array.isArray(w)?i(w):console.error("JSON解析结果不是数组")}catch(w){console.error("JSON解析错误:",w)}},[i]),S=C.useCallback(m=>{const w=n.filter((O,B)=>B!==m);i(w),y()},[n,i,y]),a=C.useCallback(m=>{if(m<=0)return;const w=[...n],O=w[m];w[m]=w[m-1],w[m-1]=O,i(w),y()},[n,i,y]),j=C.useCallback(m=>{if(m>=n.length-1)return;const w=[...n],O=w[m];w[m]=w[m+1],w[m+1]=O,i(w),y()},[n,i,y]),f=C.useCallback((m,w)=>{const O=[...n];O[m]=w,i(O)},[n,i]),k=d&&d.subProperties&&Object.keys(d.subProperties).length>0,I=C.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:m})=>t.jsx(r.Typography,{variant:"body1",sx:{bgcolor:"action.hover",borderRadius:"50%",width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:m+1})},{field:"content",headerName:"",renderCell:({row:m,index:w})=>g&&k?g({item:m,index:w,property:d,onChange:O=>f(w,O)}):t.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:o,value:m,placeholder:p||`${b("item")} ${w+1}`,onChange:O=>f(w,O.target.value),...v})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:m})=>t.jsxs(r.Stack,{direction:"column",spacing:.25,children:[t.jsx(gt,{disabled:o||m===0,onClick:()=>a(m)}),t.jsx(vt,{disabled:o||m===n.length-1,onClick:()=>j(m)}),t.jsx(yt,{disabled:o,onClick:()=>S(m)})]})}],[g,k,d,f,p,b,o,v,S,a,j,n.length]);return k?t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),n.length>0?t.jsx(r.TableContainer,{component:r.Paper,variant:"outlined",sx:{borderRadius:1,mb:1},children:t.jsxs(r.Table,{size:"small",sx:{"& .MuiTableCell-root":{py:.25,px:1,whiteSpace:"nowrap"},"& .MuiTableCell-head":{backgroundColor:"action.hover",py:.25,px:1},borderCollapse:"collapse"},children:[t.jsx(r.TableHead,{sx:{display:"none"},children:t.jsx(r.TableRow,{children:I.map(m=>t.jsx(r.TableCell,{width:m.width,align:m.align||"left",sx:{fontWeight:"bold"},children:m.renderHeader?m.renderHeader():m.headerName},m.field))})}),t.jsx(r.TableBody,{children:n.map((m,w,O)=>t.jsx(r.TableRow,{sx:{borderBottom:w<O.length-1?"1px solid":"none",borderColor:"divider","&:hover":{backgroundColor:"action.hover"}},children:I.map(B=>t.jsx(r.TableCell,{width:B.width,align:B.align||"left",sx:{borderBottom:"none"},children:B.renderCell({row:m,index:w,onChange:V=>f(w,V)})},`${w}-${B.field}`))},w))})]})}):t.jsx(Z.default,{style:{fontSize:12,height:h},children:b("maker.properties.arrayEmpty")}),t.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:o,startIcon:t.jsx(ot.default,{}),onClick:u,children:b("maker.properties.addArrayItem")})]}):t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,minHeight:150},children:t.jsx(ie.CodeEditor,{keyId:d.id,locale:P,language:"json",value:JSON.stringify(n,null,2),onChange:m=>x(m||""),fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},d.id)})]})}function St({value:e,onChange:s,...l}){const o=C.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsx(qe.ConfigString,{...l,value:e,onChange:s,InputProps:{endAdornment:t.jsx(r.InputAdornment,{position:"end",children:t.jsx(ye.ColorItem,{color:e??"",style:{width:"1.5rem",height:"1.5rem",padding:0},onClick:()=>{var p;(p=o.current)==null||p.open({value:e??""})}})})}}),t.jsx(ye.ConfigColorDialog,{ref:o,onSave:({value:p},h)=>{s(p),h()}})]})}function Pt({label:e,value:s,onChange:l,property:o,component:p,defaultLocale:h,allComponents:d,PropertyValueField:g,onUpload:v}){const{locale:b}=_.useLocaleContext(),P=C.useRef(null);if(!ne.default(o.subProperties)){const i=E.default(Object.values(o.subProperties||{}),"index").filter(n=>n.data.visible!==!1&&n.data.key);return t.jsxs(r.Stack,{width:"100%",children:[t.jsx(r.FormLabel,{sx:{px:.25,py:.5},children:e}),t.jsx(r.Box,{children:t.jsx(r.Box,{sx:{position:"relative"},children:i.map((n,c)=>{const{data:u}=n,x=u.key??u.id,S=c===i.length-1;let a=null;try{s&&typeof s=="object"?a=s[x]:typeof s=="string"&&(a=(o.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}"))[x])}catch{}a==null&&(u.locales&&b&&u.locales[b]?a=u.locales[b].defaultValue:u.locales&&h&&u.locales[h]&&(a=u.locales[h].defaultValue));const j=k=>{try{let I={};if(typeof s=="string")try{I=o.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(I={...s});we.default(I,x,k);const m=R.transformValue(I,o.type);l==null||l(m)}catch(I){console.error("Error updating property:",I)}},f=8;return t.jsxs(r.Box,{sx:{mb:S?0:1,display:"flex",flexDirection:"row"},children:[t.jsxs(r.Box,{sx:{position:"relative",width:24,flexShrink:0},children:[t.jsx(r.Box,{sx:{position:"absolute",left:f,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),t.jsx(r.Box,{sx:{position:"absolute",left:f,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!S&&t.jsx(r.Box,{sx:{position:"absolute",left:f,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),t.jsx(r.Box,{sx:{flexGrow:1},children:t.jsx(g,{component:p,property:u,value:a,onChange:j,size:"small",fullWidth:!0,defaultLocale:h,allComponents:d})})]},u.id)})})})]})}return t.jsx(r.Stack,{width:"100%",gap:2,children:t.jsxs(r.Stack,{sx:{width:"100%",position:"relative",pt:1,pb:"6px",px:"1px",minHeight:50,".monaco-editor,.overflow-guard":{borderRadius:1}},children:[t.jsx(r.FormLabel,{sx:{position:"absolute",left:0,top:0,transform:"translate(0px, -7px) scale(0.75)"},children:e}),t.jsx(ie.CodeEditor,{keyId:o.id,locale:b,language:o.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:i=>{l==null||l(i)},onUpload:i=>{P.current=i,v&&v(i)},fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},o.id),t.jsx(r.Box,{component:"fieldset",sx:{pointerEvents:"none",position:"absolute",left:0,top:-5,width:"100%",height:"100%",border:1,borderColor:"rgba(0, 0, 0, 0.23)",borderRadius:1,px:1,py:0},children:t.jsx(r.Box,{component:"legend",sx:{fontSize:"0.75em"},children:t.jsx(r.Box,{component:"span",sx:{opacity:0},children:e})})})]})})}const wt=["string","multiline","json","yaml","url","component","custom","array"];function ge(e){return e.type?!wt.includes(e.type):!1}function Ie({disabled:e,list:s,renderItem:l,...o}){const p=C.useRef(null),h=C.useId(),d=Pe.useUpdate(),g=E.default(Object.entries(s),n=>n[1].index).map(n=>n[0]),v=C.useRef(g),b=C.useCallback(n=>{v.current=n,d()},[d]),P=C.useCallback(({index:n},{index:c})=>{const u=[...v.current];u.splice(c,0,...u.splice(n,1)),b(u)},[b]);C.useEffect(()=>{b(g)},[g.join("-")]);const[{isOver:y},i]=te.useDrop({accept:h,collect:n=>({isOver:n.isOver()}),canDrop:()=>!e,drop:()=>{var u;const n=()=>{v.current.forEach((x,S)=>{const a=s[x];a&&(a.index=S)})},c=(u=Y.getYjsValue(s))==null?void 0:u.doc;c?c.transact(()=>{n()}):n()}});return C.useEffect(()=>{y||b(g)},[y]),i(p),t.jsx(r.Box,{...o,ref:p,className:st.cx(y&&"isDragging"),children:v.current.map((n,c)=>t.jsx(It,{type:h,disabled:e,id:n,index:c,itemIndex:u=>v.current.indexOf(u),move:P,children:u=>{const x=s[n];return x?l(x.data,c,u):null}},n))})}function It({disabled:e,id:s,index:l,type:o,children:p,itemIndex:h,move:d}){const g=C.useRef(),[{isDragging:v},b,P]=te.useDrag({type:o,item:()=>({id:s}),canDrag:()=>!e,collect:i=>({isDragging:i.isDragging()})}),[,y]=te.useDrop({accept:o,canDrop:()=>!e,hover(i,n){var f;if(!g.current)return;const c=h(i.id),u=l;if(c===u)return;const x=(f=g.current)==null?void 0:f.getBoundingClientRect(),S=(x.bottom-x.top)/2,j=n.getClientOffset().y-x.top;c<u&&j<S||c>u&&j>S||d({id:i.id,index:c},{id:s,index:l})}});return typeof p=="function"?p({isDragging:v,drag:b,drop:i=>(g.current=i,y(i)),preview:P}):(b(y(P(g))),t.jsx(r.Box,{ref:g,children:p}))}function Ct({drop:e,preview:s,drag:l,disabled:o,isDragging:p,children:h,onDelete:d,onVisibilityChange:g,visible:v=!0,actions:b,alwaysShowActions:P=!1}){const{t:y}=_.useLocaleContext();return t.jsx(r.Box,{ref:e,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:v?1:.5},children:t.jsxs(r.Box,{sx:{position:"relative"},children:[t.jsx(r.Box,{ref:s,sx:{flex:1,borderRadius:.5,bgcolor:p?"action.hover":"background.paper",opacity:.9999},children:h}),!o&&t.jsx(r.Box,{className:P?"":"hover-visible",sx:{maxWidth:P?"100%":0,overflow:"hidden",position:"absolute",right:2,top:2,transition:"max-width 0.3s ease-in-out"},children:t.jsxs(r.Stack,{direction:"row",sx:{bgcolor:i=>r.alpha(i.palette.grey[200],.9),borderRadius:1,p:.5,[`.${r.buttonClasses.root}`]:{minWidth:24,width:24,height:24,p:0}},children:[b,g&&t.jsx(r.Tooltip,{title:y(v?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:()=>g(!v),children:v?t.jsx(D.VisibilityOffRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}}):t.jsx(D.VisibilityRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),d&&t.jsx(r.Tooltip,{title:y("delete"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:d,children:t.jsx(D.DeleteOutlineRounded,{sx:{fontSize:"1.25rem",color:"grey.500"}})})}),t.jsx(r.Tooltip,{title:y("dragSort"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{ref:l,children:t.jsx(D.DragIndicatorRounded,{sx:{color:"grey.500"}})})})]})})]})})}function Ot({label:e,value:s,onChange:l}){const[o,p]=C.useState(!1);return t.jsxs(r.Stack,{gap:1,children:[t.jsx(r.TextField,{label:e,size:"small",value:s,onChange:h=>l==null?void 0:l(h.target.value),InputProps:{endAdornment:t.jsx(z.UploaderButton,{onChange:({response:h})=>{var g;const d=(g=h==null?void 0:h.data)==null?void 0:g.filename;d&&(l==null||l(d))}})}}),s&&t.jsx(r.Box,{component:"img",sx:{objectFit:"contain",borderRadius:1,cursor:"pointer"},src:R.getImageAbsoluteUrl(s),alt:e,maxWidth:100,maxHeight:100,width:"100%",onClick:()=>p(!0)}),t.jsx(r.Dialog,{open:o,onClose:()=>p(!1),children:t.jsx(r.Box,{component:"img",sx:{objectFit:"contain"},src:R.getImageAbsoluteUrl(s),alt:e})})]})}function le(e,s=""){return ht.default(e,(l,o,p)=>{const h=s?`${s}.${p}`:p;return xt.default(o)?ut.default(l,le(o,h)):l[h]=o,l},{})}const Tt=[{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 G(e,s,l){return!e||!l?!1:Object.values(e).some(({data:o})=>o.id!==s&&o.key===l)}function oe(e,s){var l;return!e||!s?!1:((l=e[s])==null?void 0:l.data.visible)??!0}function Bt({componentId:e}){const{state:{components:s}}=R.useStore(),l=s[e],o=l==null?void 0:l.data;return o?t.jsx(r.Stack,{maxHeight:"100%",overflow:"auto",children:t.jsx(r.Box,{p:2,children:t.jsx(rt.ErrorBoundary,{FallbackComponent:R.ErrorView,resetKeys:[e],children:t.jsx(Rt,{value:o})})})}):null}function Rt({value:e}){var b,P,y;const{t:s}=_.useLocaleContext(),{localState:{currentLocale:l,customComponentPreviewerProperties:o},state:{config:{defaultLocale:p}},localActions:{setCustomComponentPreviewerProperties:h}}=R.useStore(),d=Y.getYjsValue(e).doc,g=R.useAllComponents(),v=Pe.useReactive({propertiesValue:{...h}});return C.useEffect(()=>{const i=Object.fromEntries(Object.values(e.properties??{}).map(({data:n})=>{var c,u,x,S,a;return[n.id,{value:((c=v.propertiesValue[n.id])==null?void 0:c.value)??Le.parsePropertyValue(n,((x=(u=n.locales)==null?void 0:u[l])==null?void 0:x.defaultValue)??((a=(S=n.locales)==null?void 0:S[p])==null?void 0:a.defaultValue),{locale:l,defaultLocale:p})}]}));h(i)},[JSON.stringify(v.propertiesValue)]),t.jsx(r.Stack,{height:"100%",children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(Ce,{config:e}),t.jsx(Te,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,onUpdateConfig:i=>{d.transact(()=>{i(e)})}}),t.jsxs(r.Stack,{gap:2,direction:"row",justifyContent:"space-between",alignItems:"center",children:[t.jsx(r.Typography,{variant:"subtitle1",children:s("renderer")}),t.jsxs(r.TextField,{hiddenLabel:!0,size:"small",select:!0,SelectProps:{autoWidth:!0},value:((b=e.renderer)==null?void 0:b.type)||"react-component",onChange:i=>{d.transact(()=>{const n=i.target.value;e.renderer??(e.renderer={type:n}),e.renderer.type=n})},children:[t.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),t.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),((P=e.renderer)==null?void 0:P.type)==="component"&&t.jsx(Nt,{value:e}),((y=e.renderer)==null?void 0:y.type)==="react-component"&&t.jsx(At,{value:e}),t.jsx(ce,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,propertiesValue:o,onChange:({value:i,id:n,path:c})=>{const u=[...c,"data"];if(!dt.default(e,u)){se.default.warning(s("cannotFindPropertyKey",{key:u.join(".")}));return}v.propertiesValue[n]={value:i.value}}})]})})}function Ce({config:e}){const{t:s}=_.useLocaleContext();return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(r.Typography,{variant:"subtitle1",children:s("basicInfo")}),t.jsx(r.TextField,{label:s("name"),size:"small",value:e.name||"",onChange:l=>e.name=l.target.value}),t.jsx(r.TextField,{label:s("description"),size:"small",multiline:!0,minRows:2,maxRows:10,inputProps:{maxLength:200},value:e.description||"",onChange:l=>e.description=l.target.value}),t.jsx(r.Autocomplete,{size:"small",options:[],multiple:!0,freeSolo:!0,value:e.tags??[],onChange:(l,o)=>e.tags=o,renderInput:l=>t.jsx(r.TextField,{label:s("tags"),...l})}),t.jsx(Ot,{label:s("previewImage"),value:e.previewImage||"",onChange:l=>e.previewImage=l})]})})}function Oe({data:e,params:s,visible:l,config:o,currentLocale:p,defaultLocale:h,allComponents:d,onUpdateConfig:g}){var P,y,i,n,c,u;const{t:v}=_.useLocaleContext(),b=C.useMemo(()=>e.type==="json"||e.type==="yaml"||e.type==="array"?Vt:U,[e.type]);return t.jsx(Ct,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{g(x=>{if(x.properties){const a=Object.entries(x.properties).sort(([,f],[,k])=>f.index-k.index);delete x.properties[e.id],a.filter(([f])=>f!==e.id).forEach(([,f],k)=>{f.index=k})}})},visible:l,onVisibilityChange:x=>{g(S=>{const a=S.properties[e.id].data;a.visible=x})},alwaysShowActions:!0,children:t.jsxs(r.Stack,{direction:"column",gap:2,children:[t.jsx(r.TextField,{label:v("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:e.key?G(o.properties,e.id,e.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:e.key?G(o.properties,e.id,e.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:e.key?G(o.properties,e.id,e.key)?"warning.main":"primary.main":"error.main"}},value:e.key||"",onChange:x=>{g(S=>{const a=S.properties[e.id].data;a.key=x.target.value.trim()})},InputProps:{endAdornment:!e.key||e.key&&G(o.properties,e.id,e.key)?t.jsx(r.InputAdornment,{position:"end",sx:{width:16,ml:0},children:t.jsx(r.Tooltip,{title:e.key?v("duplicateKey"):v("requiredKey"),children:t.jsx(D.InfoRounded,{sx:{color:e.key?"warning.main":"error.main",fontSize:16}})})}):null}}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(r.TextField,{label:v("label"),size:"small",sx:{flex:1},value:(((y=(P=e.locales)==null?void 0:P[p])==null?void 0:y.name)??((n=(i=e.locales)==null?void 0:i[h])==null?void 0:n.name))||"",onChange:x=>{g(S=>{var j;const a=S.properties[e.id].data;a.locales??(a.locales={}),(j=a.locales)[p]??(j[p]={}),a.locales[p].name=x.target.value})}}),t.jsx(r.TextField,{label:v("type"),size:"small",select:!0,sx:{flex:1},value:e.type==="string"&&e.multiline?"multiline":e.type||"string",onChange:x=>{g(S=>{const a=S.properties[e.id].data;if(a.locales)for(const f of Object.keys(a.locales))a.locales[f].defaultValue=void 0;const j=x.target.value;j==="multiline"?(a.type="string",a.multiline=!0):(typeof a.multiline<"u"&&delete a.multiline,a.type=j)})},children:Tt.map(x=>t.jsx(r.MenuItem,{value:x.value,children:x.label},x.value))})]}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(b,{allComponents:d,defaultLocale:h,component:o,property:e,label:v("defaultValue"),size:"small",fullWidth:!0,value:(u=(c=e.locales)==null?void 0:c[p])==null?void 0:u.defaultValue,onChange:(x,S)=>{g(a=>{var f;const j=a.properties[e.id].data;if(S!=null&&S.forceUpdateProperty){const k=le(j),I=le(x);Object.keys(I).forEach(m=>{k[m]||we.default(j,m,I[m])})}else j.locales??(j.locales={}),(f=j.locales)[p]??(f[p]={}),j.locales[p].defaultValue=x})}}),e.type==="custom"?t.jsx(r.Box,{children:t.jsx(Dt,{property:e,allComponents:d})}):null]})]})})}function _t(e,s){const[l,o]=C.useState(0);return C.useEffect(()=>{const h=setTimeout(()=>{if(e.current){let d=e.current.parentElement,g=0;for(;d;)d.classList.contains("property-container")&&g++,d=d.parentElement;o(g)}},100);return()=>clearTimeout(h)},[e,s]),l}function Te({config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p,useI18nEditor:h=!0}){const{t:d}=_.useLocaleContext(),g=A.usePopupState({variant:"dialog"}),v=e.properties&&E.default(Object.values(e.properties),"index");return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsxs(r.Stack,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between",children:[t.jsx(r.Typography,{variant:"subtitle1",children:d("properties")}),t.jsx(r.Box,{flex:1}),h&&t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...A.bindTrigger(g),children:t.jsx(D.TranslateRounded,{fontSize:"small"})})]}),e.properties&&Object.keys(e.properties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.properties,renderItem:(b,P,y)=>{const i=oe(e.properties,b.id);return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:i?"1px solid":"1px dashed",borderColor:"divider"},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:y,visible:i,config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12},children:d("maker.properties.noProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",onClick:()=>{p(b=>{var y;const P=R.nextId();b.properties??(b.properties={}),(y=b.properties)[P]??(y[P]={index:(v==null?void 0:v.length)||0,data:{id:P}})})},startIcon:t.jsx(D.AddRounded,{}),children:d("addObject",{object:d("property")})}),h&&t.jsx(Be,{...A.bindDialog(g),component:e})]})})}function Dt({property:e,allComponents:s}){const l=A.usePopupState({variant:"popper"});return t.jsxs(t.Fragment,{children:[t.jsx(r.Button,{sx:{minWidth:0},...A.bindTrigger(l),children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Popper,{...A.bindPopper(l),children:t.jsx(Se.ClickAwayListener,{onClickAway:l.close,children:t.jsx(r.Paper,{children:t.jsx(r.Box,{width:500,p:2,children:t.jsx(ee,{value:e.componentId,onChange:(o,p)=>e.componentId=p,allComponents:s})})})})})]})}function Et({value:e,valueImmutable:s,onChange:l,defaultLocale:o,allComponents:p}){var P;const[h,d]=C.useState(!1),{t:g,locale:v}=_.useLocaleContext(),b=typeof(e==null?void 0:e.componentId)=="string"?(P=p[e.componentId])==null?void 0:P.data:void 0;return b?t.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[t.jsx(r.IconButton,{sx:{minWidth:0},disabled:!b,size:"small",onClick:()=>d(!h),color:h?"primary":"default",children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),h&&t.jsx(r.Collapse,{in:h,timeout:"auto",unmountOnExit:!0,sx:{width:"100%",zIndex:10},children:t.jsxs(r.Paper,{elevation:1,sx:{mt:1,p:2,borderRadius:1,border:"1px solid",borderColor:"divider",width:"100%"},children:[t.jsx(r.Box,{width:"100%",mb:2,children:t.jsx(ce,{config:b,currentLocale:v,defaultLocale:o,allComponents:p,propertiesValue:e==null?void 0:e.properties,onChange:({id:y,value:i})=>{const n=at.default(i.value),c=JSON.parse(JSON.stringify(e));c!=null&&c.componentId&&(s?l==null||l({...c,properties:{...c.properties,[y]:{value:n}}}):(c.properties=c.properties??{},c.properties[y]={value:n},l==null||l(c)))}})}),t.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:g("close")})]})})]}):null}function Be({type:e="properties",component:s,...l}){var y,i,n;const{t:o}=_.useLocaleContext(),{state:{components:p,supportedLocales:h,config:{defaultLocale:d}}}=R.useStore(),g=R.useAllComponents(),v=Y.getYjsValue(s).doc,b=e==="properties"?s.properties:e==="parameters"&&((y=s.renderer)==null?void 0:y.type)==="component"?(i=p[s.renderer.componentId])==null?void 0:i.data.properties:void 0,P=((n=s.renderer)==null?void 0:n.type)==="component"?s:void 0;return t.jsxs(r.Dialog,{...l,fullWidth:!0,maxWidth:"lg",children:[t.jsx(r.DialogTitle,{children:o("i18nEditorTitle")}),t.jsx(r.DialogContent,{children:b&&t.jsx(r.Stack,{children:t.jsxs(r.Table,{stickyHeader:!0,sx:{td:{verticalAlign:"top"}},children:[t.jsx(r.TableHead,{children:t.jsx(r.TableRow,{children:h.map(({locale:c,name:u})=>t.jsx(r.TableCell,{children:t.jsxs(r.Typography,{color:"text.primary",children:[u,d===c&&t.jsx(D.StarRounded,{sx:{fontSize:12}})]})},c))})}),t.jsx(r.TableBody,{children:E.default(Object.values(b),"index").map(({data:c})=>t.jsx(r.TableRow,{children:h.map(({locale:u})=>{var x,S,a,j,f,k,I,m,w,O,B,V,N,q,$,W,K,L,J,H,ae,ue,de,pe,me,xe;return t.jsx(r.TableCell,{children:t.jsx(r.Stack,{gap:1,children:e==="properties"?t.jsxs(t.Fragment,{children:[t.jsx(r.TextField,{size:"small",label:"Key",value:c.key||"",onChange:M=>{v.transact(()=>{c.key=M.target.value.trim()})}}),t.jsx(r.TextField,{size:"small",label:o("label"),value:(((S=(x=c.locales)==null?void 0:x[u])==null?void 0:S.name)??((j=(a=c.locales)==null?void 0:a[d])==null?void 0:j.name))||"",onChange:M=>{v.transact(()=>{var F;c.locales??(c.locales={}),(F=c.locales)[u]??(F[u]={}),c.locales[u].name=M.target.value})}}),t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:X.default((k=(f=c.locales)==null?void 0:f[u])==null?void 0:k.defaultValue),value:((m=(I=c.locales)==null?void 0:I[u])==null?void 0:m.defaultValue)??((O=(w=c.locales)==null?void 0:w[d])==null?void 0:O.defaultValue),onChange:M=>{v.transact(()=>{var F;c.locales??(c.locales={}),(F=c.locales)[u]??(F[u]={}),c.locales[u].defaultValue=M})}})})]}):e==="parameters"&&P?t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:c,size:"small",fullWidth:!0,valueImmutable:X.default((q=(N=(V=(B=P.renderer.properties)==null?void 0:B[c.id])==null?void 0:V.locales)==null?void 0:N[u])==null?void 0:q.value),value:((L=(K=(W=($=P.renderer.properties)==null?void 0:$[c.id])==null?void 0:W.locales)==null?void 0:K[u])==null?void 0:L.value)??((ue=(ae=(H=(J=P.renderer.properties)==null?void 0:J[c.id])==null?void 0:H.locales)==null?void 0:ae[d])==null?void 0:ue.value)??((pe=(de=c.locales)==null?void 0:de[u])==null?void 0:pe.defaultValue)??((xe=(me=c.locales)==null?void 0:me[d])==null?void 0:xe.defaultValue),onChange:M=>{v.transact(()=>{var F,fe,je,be,he;(F=P.renderer).properties??(F.properties={}),(fe=P.renderer.properties)[je=c.id]??(fe[je]={}),(be=P.renderer.properties[c.id]).locales??(be.locales={}),(he=P.renderer.properties[c.id].locales)[u]??(he[u]={}),P.renderer.properties[c.id].locales[u].value=M})}})}):null},c.id)},u)})},c.id))})]})})}),t.jsx(r.DialogActions,{children:t.jsx(r.Button,{onClick:c=>{var u;return(u=l.onClose)==null?void 0:u.call(l,c,"escapeKeyDown")},children:o("close")})})]})}const ve=(e,s)=>l=>{const o=[l.palette.info.main,l.palette.primary.main,l.palette.secondary.main,l.palette.success.main,l.palette.warning.main],p=Math.min(o.length-1,e),h=o[p],d=r.alpha(h,.5),g=r.alpha(h,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:g,...s}};function Vt({property:e,onChange:s,defaultLocale:l,allComponents:o}){const{t:p,locale:h}=_.useLocaleContext(),d=C.useRef(null),g=_t(d,e),v=C.useCallback(()=>{if(!(e.type!=="json"&&e.type!=="yaml"&&e.type!=="array")&&e.subProperties)try{let b={};E.default(Object.values(e.subProperties),"index").filter(i=>i.data.visible!==!1&&i.data.key).forEach(({data:i})=>{var c,u,x,S;if(!i.key)return;let n=((u=(c=i.locales)==null?void 0:c[h])==null?void 0:u.defaultValue)??((S=(x=i.locales)==null?void 0:x[l])==null?void 0:S.defaultValue);if(i.type==="number")n=Number(n);else if(i.type==="boolean")n=n===!0||n==="true";else if((i.type==="json"||i.type==="yaml")&&typeof n=="string")try{i.type==="json"?n=JSON.parse(n):n=re.parse(n)}catch(a){console.error("Error parsing nested value",n,a),n={}}b[i.key]=n}),e.type==="array"&&!Array.isArray(b)&&(b=ne.default(b)?[]:[b]);const y=R.transformValue(b,e.type);s==null||s(y)}catch(b){console.error("Error converting structure to text:",b)}},[e,h,l,s]);return e.type!=="json"&&e.type!=="yaml"&&e.type!=="array"?null:t.jsxs(r.Stack,{direction:"column",gap:1.5,sx:{width:"100%"},ref:d,children:[t.jsx(r.Divider,{sx:{mt:-1},children:t.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:p("maker.properties.subProperties")})}),e.subProperties&&Object.keys(e.subProperties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.subProperties,renderItem:(b,P,y)=>{const i=b.visible!==!1;return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:i?"1px solid":"1px dashed","&":ve(g)},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:y,visible:i,config:{properties:e.subProperties},currentLocale:h,defaultLocale:l,allComponents:o,onUpdateConfig:n=>{try{const c={properties:e.subProperties||{}};n(c);const u={...e,subProperties:c.properties};s==null||s(u,{forceUpdateProperty:!0}),v()}catch(c){console.error("Error updating property:",c)}}})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12,height:100},children:p("maker.properties.noSubProperties")}),t.jsx(r.Button,{fullWidth:!0,variant:"outlined",className:"ignore-style-override",size:"small",startIcon:t.jsx(D.AddRounded,{}),onClick:()=>{try{const b=e.subProperties||{},P=R.nextId(),i={index:Object.values(b).length,data:{id:P,key:"",type:"string",visible:!0,locales:{[h]:{name:"",defaultValue:""}},subProperties:{}}},n={...e,subProperties:{...b,[P]:i}};s==null||s(n,{forceUpdateProperty:!0}),v()}catch(b){console.error("Error adding property:",b)}},sx:{"&":ve(g,{})},children:p("maker.properties.addSubProperty")})]})}function U({component:e,property:s,value:l,onChange:o,valueImmutable:p,defaultLocale:h,allComponents:d,...g}){var n,c,u,x,S;const{locale:v}=_.useLocaleContext(),b=z.useUploader(),P=C.useRef(null),y=()=>{var j;const a=(j=b==null?void 0:b.current)==null?void 0:j.getUploader();a==null||a.open(),P.current&&a.onceUploadSuccess(({response:f})=>{var I,m;let k=((I=f==null?void 0:f.data)==null?void 0:I.filename)||"";k&&(k=`mediakit://${k}`,l&&!l.includes("mediakit://")&&(k+=" # please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address")),(m=P.current)==null||m.call(P,k)})},i=g.label??(((c=(n=s.locales)==null?void 0:n[v])==null?void 0:c.name)||((x=(u=s.locales)==null?void 0:u[h])==null?void 0:x.name)||s.key||s.id);if(s.type==="number")return t.jsx(zt,{...g,label:i,NumberProps:{value:["number","string"].includes(typeof l)?l:null,onChange:(a,j)=>o==null?void 0:o(j)}});if(s.type==="decimal")return t.jsx(r.TextField,{...g,label:i,type:"text",value:l??"",onChange:a=>{const j=a.target.value;if(j===""||j==="-"){o==null||o(j);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(j)){let k=j;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(k)&&(k=Number(k)),o==null||o(k)}}});if(s.type==="boolean")return t.jsx(r.FormControlLabel,{label:i,labelPlacement:"start",control:t.jsx(r.Switch,{checked:l===!0,onChange:(a,j)=>o==null?void 0:o(j)})});if(s.type==="color")return t.jsx(St,{label:i,value:l,onChange:a=>{o==null||o(a)}});if(s.type==="json"||s.type==="yaml")return t.jsx(Pt,{label:i,value:l,onChange:a=>{o==null||o(a)},property:s,component:e,defaultLocale:h,allComponents:d,PropertyValueField:U,onUpload:a=>{P.current=a,y()}});if(s.type==="custom"){const a=(S=d[s.componentId])==null?void 0:S.data;return a?t.jsx(r.Box,{width:"100%",children:t.jsx(Q.CustomComponentRenderer,{componentId:a.id,props:{label:i,value:l,onChange:o},locale:v,dev:{mode:"draft",components:d,defaultLocale:h}})}):t.jsx(r.TextField,{...g,label:i,disabled:!0,placeholder:"Click right button select a component"})}if(s.type==="component")return t.jsxs(r.Stack,{width:"100%",direction:"column",gap:1,children:[t.jsx(ee,{allComponents:d,label:i,value:l==null?void 0:l.componentId,onChange:(a,j)=>{p||!l?o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:j}):typeof l=="object"&&(l.componentId=j,o==null||o({...l&&JSON.parse(JSON.stringify(l)),componentId:j}))}}),(l==null?void 0:l.componentId)&&t.jsx(Et,{value:l,valueImmutable:p,onChange:o,defaultLocale:h,allComponents:d})]});if(!s.type||["string","url","multiline"].includes(s.type)){let a=s.type==="string"?s.multiline:void 0;s.type==="multiline"&&(a=!0);const j=s.type==="url"?l==null?void 0:l.url:l;return t.jsx(r.TextField,{...g,label:i,value:typeof j=="string"?j:"",multiline:a,minRows:a?2:void 0,maxRows:a?10:void 0,onChange:f=>o==null?void 0:o(s.type==="url"?{...l,url:f.target.value,mediaKitUrl:f.target.value}:f.target.value),InputProps:s.type==="url"?{sx:{pr:0},endAdornment:t.jsxs(r.InputAdornment,{position:"end",children:[t.jsx(z.UploaderButton,{onChange:async({response:f})=>{var w,O,B;const k=((w=f==null?void 0:f.data)==null?void 0:w.url)||((O=f==null?void 0:f.data)==null?void 0:O.fileUrl);let I;k&&(I=await z.getImageSize(k).catch(()=>z.getVideoSize(k)).catch(()=>{}));let m=((B=f==null?void 0:f.data)==null?void 0:B.filename)||"";m&&(m=`mediakit://${m}`),o==null||o({url:k,mediaKitUrl:m,width:I==null?void 0:I.naturalWidth,height:I==null?void 0:I.naturalHeight})}}),t.jsx(r.Tooltip,{title:"If you are using the 'mediaKitUrl' property, please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address.",children:t.jsx(D.InfoRounded,{sx:{cursor:"default",mr:1},fontSize:"small"})})]})}:void 0})}return s.type==="array"?t.jsx(kt,{label:i,value:Array.isArray(l)?l:[],onChange:a=>o==null?void 0:o(a),property:s,renderItem:({item:a,index:j,onChange:f})=>s.subProperties&&Object.keys(s.subProperties).length>0?t.jsx(r.Stack,{gap:1,width:"100%",children:E.default(Object.values(s.subProperties),"index").filter(k=>k.data.visible!==!1).map(({data:k})=>k.key?t.jsx(U,{component:e,property:k,value:a[k.key],onChange:I=>{const m={...a,[k.key]:I};f(m)},size:"small",fullWidth:!0,defaultLocale:h,allComponents:d},k.id):null)},j):t.jsx(r.TextField,{size:g.size,fullWidth:!0,value:a,onChange:k=>f(k.target.value)})}):(console.error("Unsupported property type",s.type),null)}function zt({NumberProps:e,...s}){const{getInputProps:l}=Se.unstable_useNumberInput(e),o=l();return t.jsx(r.TextField,{...s,inputProps:o})}const Re=`import React from '@blocklet/pages-kit/builtin/react'
2
2
  import { Box } from '@blocklet/pages-kit/builtin/mui/material'
3
3
 
4
4
  export default function () {
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./chunks/site-state-DvIWP0pO.js");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("crypto");require("fs");require("glob");require("lib0/decoding");require("lib0/encoding");require("lodash/cloneDeep");require("lodash/debounce");require("lodash/get");require("lodash/isEmpty");require("lodash/pick");require("lodash/set");require("lodash/union");require("lru-cache");require("nanoid");require("p-limit");require("path");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.getResourceStates=e.getResourceStates;exports.initPackResourceStates=e.initPackResourceStates;exports.mergeState=e.mergeState;exports.nextId=e.nextId;exports.toPackage=e.toPackage;exports.triggerReloadAllProjectResource=e.triggerReloadAllProjectResource;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"}});const e=require("./chunks/site-state-D5jk8eJT.js");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("crypto");require("fs");require("glob");require("lib0/decoding");require("lib0/encoding");require("lodash/cloneDeep");require("lodash/debounce");require("lodash/get");require("lodash/isEmpty");require("lodash/pick");require("lodash/set");require("lodash/union");require("lru-cache");require("nanoid");require("p-limit");require("path");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.getResourceStates=e.getResourceStates;exports.initPackResourceStates=e.initPackResourceStates;exports.mergeState=e.mergeState;exports.nextId=e.nextId;exports.toPackage=e.toPackage;exports.triggerReloadAllProjectResource=e.triggerReloadAllProjectResource;Object.keys(t).forEach(r=>{r!=="default"&&!Object.prototype.hasOwnProperty.call(exports,r)&&Object.defineProperty(exports,r,{enumerable:!0,get:()=>t[r]})});