@blocklet/pages-kit-inner-components 0.5.35 → 0.5.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/add-component.js +2 -2
- package/lib/cjs/chunks/{array-DxhrK2d5.js → array-Ck0L_JhL.js} +1 -1
- package/lib/cjs/chunks/{config-string-DqWgB7yO.js → config-string-CaLe_baf.js} +1 -1
- package/lib/cjs/chunks/{draft-data-DzN2u_NT.js → draft-data-CY1N7Ozn.js} +1 -1
- package/lib/cjs/chunks/{home-0fezWT4S.js → home-CjWVwLEf.js} +3 -3
- package/lib/cjs/chunks/{publish-button-D2jaaXXn.js → publish-button-BDrUGRX4.js} +1 -1
- package/lib/cjs/chunks/site-state-CIPfhJn5.js +57 -0
- package/lib/cjs/chunks/state-D4QeRw7n.js +1 -0
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +1 -1
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +2 -2
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/add-component.js +4 -4
- package/lib/es/chunks/{array-D6qyZucY.js → array-HCA75FfO.js} +1 -1
- package/lib/es/chunks/{config-string-Btybe5Rd.js → config-string-17RNX8vu.js} +1 -1
- package/lib/es/chunks/{draft-data-DQ7_JyJX.js → draft-data-CyeVe0kA.js} +1 -1
- package/lib/es/chunks/{home-Dox9JwvF.js → home-COrN_x32.js} +4 -4
- package/lib/es/chunks/{publish-button-T2YJBoty.js → publish-button-WmGjhj6q.js} +3 -3
- package/lib/es/chunks/site-state-CfrteYXm.js +2137 -0
- package/lib/es/chunks/{state-NhsHvaKm.js → state-Br2xp7Mf.js} +179 -175
- package/lib/es/components.js +1 -1
- package/lib/es/home.js +3 -3
- package/lib/es/project-html.js +1 -1
- package/lib/es/resources.js +1 -1
- package/lib/es/setting.js +541 -534
- package/lib/es/site-state.js +1 -1
- package/package.json +3 -3
- package/lib/cjs/chunks/site-state-D00xEf4T.js +0 -57
- package/lib/cjs/chunks/state-DoGBMTzI.js +0 -1
- package/lib/es/chunks/site-state-nXcBqjeR.js +0 -2076
package/lib/cjs/resources.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const c=require("./chunks/site-state-
|
|
1
|
+
"use strict";const c=require("./chunks/site-state-CIPfhJn5.js"),M=require("async_hooks"),U=require("express"),F=require("fs"),J=require("joi"),X=require("lodash/groupBy"),W=require("lodash/sortBy"),B=require("path"),$=require("@blocklet/sdk/lib/middlewares/auth"),G=require("@blocklet/sdk/lib/component"),y=t=>t&&t.__esModule?t:{default:t},l=y(F),I=y(J),D=y(X),K=y(W),k=y(B),v=y($);new M.AsyncLocalStorage;const Y=async(t,e,o)=>{var n,s,r,i;try{const{projectId:u}=t.params;if(!u)return o();const f=await c.Project.findByPk(u);if(!f)return e==null?void 0:e.status(404).json({error:"Project not found"});const _=(n=t.user)==null?void 0:n.did,E=((s=t.user)==null?void 0:s.role)||"UNKNOWN_ROLE";if(!_)return e==null?void 0:e.status(401).json({error:"Authentication required"});if(c.isMultiTenant()){const w=f.createdBy===_,a=(i=(r=c.getMultiTenantAllProjectAccessPassports())==null?void 0:r.includes)==null?void 0:i.call(r,E);if(!w&&!a)return e==null?void 0:e.status(403).json({error:"No permission to access this project in multi-tenant mode"})}else if(!["owner","admin","pagesEditor"].includes(E))return e==null?void 0:e.status(403).json({error:"No permission to access this project in single-tenant mode"});t.project=f,t.projectId=u,o()}catch(u){c.logger.error("Project middleware error:",u),e==null||e.status(500).json({error:"Internal server error"})}};function b(t,e){return new Promise((o,n)=>{const s=l.default.createReadStream(t),r=l.default.createWriteStream(e);s.on("error",n),r.on("error",n),r.on("finish",o),s.pipe(r)})}async function N(t,e){await l.default.promises.mkdir(e,{recursive:!0});const o=await l.default.promises.readdir(t,{withFileTypes:!0});for(const n of o){const s=k.default.join(t,n.name),r=k.default.join(e,n.name);n.isDirectory()?await N(s,r):await b(s,r)}}async function z(t,e){(await l.default.promises.stat(t)).isDirectory()?await N(t,e):await b(t,e)}const O=(t,e,o)=>c.isMultiTenant()?v.default()(t,e,o):v.default({roles:["owner","admin","pagesEditor"]})(t,e,o),H=(t,e)=>{const o=G.getResourceExportDir({projectId:t,releaseId:e});return B.join(o,c.COMPONENT_DID,c.RESOURCE_TYPE)},h=U.Router(),T="@page",q="@component",P=":",S="ALL",L="@project",C=({pageId:t,projectId:e})=>[T,e,t].join(P),Q=t=>{const[e,o,n]=t.split(P);if(e===T)return{pageId:n,projectId:o}},A=({componentId:t,projectId:e})=>[q,e,t].join(P),V=t=>{const[e,o,n]=t.split(P);if(e===q)return{componentId:n,projectId:o}},Z=t=>[L,t].join(P),tt=t=>{const[e,o]=t.split(P);if(e===L)return o},et=t=>{try{return JSON.parse(t)}catch{}return{}};async function x(t){const e=await c.SiteState.getStateByProjectId(t,"production"),o=await c.Project.findByPk(t),n=e.pageIds.map(r=>{const i=e.pages[r];if(i)return{id:C({pageId:r,projectId:t}),name:i.slug}}).filter(Boolean),s=K.default(Object.values(e.components),r=>r.index).map(({data:r})=>({id:A({componentId:r.id,projectId:t}),name:r.name||r.id}));return{id:Z(t),name:(o==null?void 0:o.name)||"Unnamed Project",children:[{id:C({pageId:S,projectId:t}),name:"Pages",children:n},{id:A({componentId:S,projectId:t}),name:"Components",children:s}]}}h.get("/resources",O,async(t,e)=>{const{projectId:o}=et(t.query.resourcesParams);if(o){t.params={...t.params,projectId:o},await Y(t,e,()=>{});const r=await x(o);e.json({resources:[r]});return}const n=await c.Project.findAll({where:{}}),s=await Promise.all(n.map(r=>x(r.id)));e.json({resources:s})});const ot=I.default.object({projectId:I.default.string().required().min(1),releaseId:I.default.string().allow(""),resources:I.default.array().items(I.default.string()).required(),locale:I.default.string().allow("")});h.post("/resources",O,async(t,e)=>{const{resources:o,projectId:n,releaseId:s}=await ot.validateAsync(t.body),r="production",i=[],u=[];for(const a of o){if(tt(a))continue;const{pageId:m,projectId:j}=Q(a)||{};if(m)m===S||m&&j&&i.push({pageId:m,projectId:j});else{const{componentId:p,projectId:d}=V(a)||{};p===S||p&&d&&u.push({componentId:p,projectId:d})}}const f=D.default(i,"projectId"),_=D.default(u,"projectId"),E=new Set([...Object.keys(f),...Object.keys(_)]),w=H(n,s);l.default.rmSync(w,{recursive:!0,force:!0}),l.default.mkdirSync(w,{recursive:!0});for(const a of E){const m=await c.SiteState.getStateByProjectId(a,r),j=f[a],p=_[a],d=j==null?void 0:j.map(g=>g.pageId),R=p==null?void 0:p.map(g=>g.componentId);if(d!=null&&d.length||R!=null&&R.length){const g=await c.toPackage(m,{exportAssets:!0,pageIds:d,componentIds:R});await z(g,w),l.default.rmSync(g,{recursive:!0,force:!0})}c.logger.info(`Exported resources for project ${a}`,{pageIds:d,componentIds:R})}e.json({})});h.get("/all-resources",O,async(t,e)=>{const{states:o}=await c.getResourceStates(),n=o==null?void 0:o.map(s=>{const r={blockletId:s.blockletId,blockletTitle:s.blockletTitle,components:{}};if(s.state.components&&(r.components=s.state.components),Object.keys(r.components).length!==0)return r}).filter(Boolean);e.json(n)});module.exports=h;
|
package/lib/cjs/setting.js
CHANGED
|
@@ -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-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'
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),R=require("./chunks/state-D4QeRw7n.js"),De=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),oe=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-CaLe_baf.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 i=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(s,l,i.get?i:{enumerable:!0,get:()=>e[l]})}}return s.default=e,Object.freeze(s)}const Z=T(De),it=T(Ee),ot=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),xt=T($e),X=T(Ge),mt=T(Qe),ft=T(Xe),jt=T(Ze),bt=T(et),ht=T(tt);function yt({onClick:e,disabled:s,sx:l,...i}){return t.jsx(r.IconButton,{size:"small",color:"warning",variant:"outlined",disabled:s,onClick:e,...i,children:t.jsx(ct.default,{fontSize:"small"})})}function gt({onClick:e,disabled:s,sx:l,...i}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...i,children:t.jsx(nt.default,{fontSize:"small"})})}function vt({onClick:e,disabled:s,sx:l,...i}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...i,children:t.jsx(ot.default,{fontSize:"small"})})}function kt({label:e,value:s,onChange:l,disabled:i=!1,itemLabel:x="",emptyHeight:h=40,property:d,renderItem:v,...S}){const{t:b,locale:y}=_.useLocaleContext(),g=ke.useUpdate(),o=C.useCallback(f=>{l(R.transformValue(f,d.type))},[l,d.type]),c=C.useMemo(()=>Array.isArray(s)?s:[],[s]),n=C.useCallback(()=>{const f=[...c,""];o(f),g()},[c,o,g]),u=C.useCallback(()=>{if(!d||!d.subProperties)return n();const f={};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[y])==null?void 0:q.defaultValue)??"";f[B.key]=V});const O=[...c,f];o(O),g()},[c,o,g,d,y,n]),j=C.useCallback(f=>{try{const w=JSON.parse(f);Array.isArray(w)?o(w):console.error("JSON解析结果不是数组")}catch(w){console.error("JSON解析错误:",w)}},[o]),k=C.useCallback(f=>{const w=c.filter((O,B)=>B!==f);o(w),g()},[c,o,g]),a=C.useCallback(f=>{if(f<=0)return;const w=[...c],O=w[f];w[f]=w[f-1],w[f-1]=O,o(w),g()},[c,o,g]),m=C.useCallback(f=>{if(f>=c.length-1)return;const w=[...c],O=w[f];w[f]=w[f+1],w[f+1]=O,o(w),g()},[c,o,g]),p=C.useCallback((f,w)=>{const O=[...c];O[f]=w,o(O)},[c,o]),P=d&&d.subProperties&&Object.keys(d.subProperties).length>0,I=C.useMemo(()=>[{field:"index",headerName:"#",width:40,align:"center",renderCell:({index:f})=>t.jsx(r.Typography,{variant:"body1",sx:{bgcolor:"action.hover",borderRadius:"50%",width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:f+1})},{field:"content",headerName:"",renderCell:({row:f,index:w})=>v&&P?v({item:f,index:w,property:d,onChange:O=>p(w,O)}):t.jsx(r.TextField,{fullWidth:!0,size:"small",disabled:i,value:f,placeholder:x||`${b("item")} ${w+1}`,onChange:O=>p(w,O.target.value),...S})},{field:"actions",headerName:"",width:30,align:"center",renderCell:({index:f})=>t.jsxs(r.Stack,{direction:"column",spacing:.25,children:[t.jsx(gt,{disabled:i||f===0,onClick:()=>a(f)}),t.jsx(vt,{disabled:i||f===c.length-1,onClick:()=>m(f)}),t.jsx(yt,{disabled:i,onClick:()=>k(f)})]})}],[v,P,d,p,x,b,i,S,k,a,m,c.length]);return P?t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),c.length>0?t.jsx(r.TableContainer,{component:r.Paper,variant:"outlined",sx:{borderRadius:1,mb:1},children:t.jsxs(r.Table,{size:"small",sx:{"& .MuiTableCell-root":{py:.25,px:1,whiteSpace:"nowrap"},"& .MuiTableCell-head":{backgroundColor:"action.hover",py:.25,px:1},borderCollapse:"collapse"},children:[t.jsx(r.TableHead,{sx:{display:"none"},children:t.jsx(r.TableRow,{children:I.map(f=>t.jsx(r.TableCell,{width:f.width,align:f.align||"left",sx:{fontWeight:"bold"},children:f.renderHeader?f.renderHeader():f.headerName},f.field))})}),t.jsx(r.TableBody,{children:c.map((f,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:f,index:w,onChange:V=>p(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:i,startIcon:t.jsx(it.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(oe.CodeEditor,{keyId:d.id,locale:y,language:"json",value:JSON.stringify(c,null,2),onChange:f=>j(f||""),fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},d.id)})]})}function St({value:e,onChange:s,...l}){const i=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 x;(x=i.current)==null||x.open({value:e??""})}})})}}),t.jsx(ye.ConfigColorDialog,{ref:i,onSave:({value:x},h)=>{s(x),h()}})]})}function Pt({label:e,value:s,onChange:l,property:i,component:x,defaultLocale:h,allComponents:d,PropertyValueField:v,onUpload:S}){const{locale:b}=_.useLocaleContext(),y=C.useRef(null);if(!ne.default(i.subProperties)){const o=E.default(Object.values(i.subProperties||{}),"index").filter(c=>c.data.visible!==!1&&c.data.key);return t.jsxs(r.Stack,{width:"100%",children:[t.jsx(r.FormLabel,{sx:{px:.25,py:.5},children:e}),t.jsx(r.Box,{children:t.jsx(r.Box,{sx:{position:"relative"},children:o.map((c,n)=>{const{data:u}=c,j=u.key??u.id,k=n===o.length-1;let a=null;try{s&&typeof s=="object"?a=s[j]:typeof s=="string"&&(a=(i.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}"))[j])}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 m=P=>{try{let I={};if(typeof s=="string")try{I=i.type==="yaml"?re.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(I={...s});we.default(I,j,P);const f=R.transformValue(I,i.type);l==null||l(f)}catch(I){console.error("Error updating property:",I)}},p=8;return t.jsxs(r.Box,{sx:{mb:k?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:p,top:0,height:16,width:0,borderLeft:"1px dashed",borderColor:"divider"}}),t.jsx(r.Box,{sx:{position:"absolute",left:p,top:16,width:12,height:0,borderTop:"1px dashed",borderColor:"divider"}}),!k&&t.jsx(r.Box,{sx:{position:"absolute",left:p,top:16,bottom:-8,width:0,borderLeft:"1px dashed",borderColor:"divider"}})]}),t.jsx(r.Box,{sx:{flexGrow:1},children:t.jsx(v,{component:x,property:u,value:a,onChange:m,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(oe.CodeEditor,{keyId:i.id,locale:b,language:i.type==="yaml"?"yaml":"json",value:typeof s=="string"?s:"",onChange:o=>{l==null||l(o)},onUpload:o=>{y.current=o,S&&S(o)},fullScreenOptions:{enableEscExit:!0,targetContainer:()=>document.getElementById("parameters-config-dialog")||null}},i.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,...i}){const x=C.useRef(null),h=C.useId(),d=Pe.useUpdate(),v=E.default(Object.entries(s),c=>c[1].index).map(c=>c[0]),S=C.useRef(v),b=C.useCallback(c=>{S.current=c,d()},[d]),y=C.useCallback(({index:c},{index:n})=>{const u=[...S.current];u.splice(n,0,...u.splice(c,1)),b(u)},[b]);C.useEffect(()=>{b(v)},[v.join("-")]);const[{isOver:g},o]=te.useDrop({accept:h,collect:c=>({isOver:c.isOver()}),canDrop:()=>!e,drop:()=>{var u;const c=()=>{S.current.forEach((j,k)=>{const a=s[j];a&&(a.index=k)})},n=(u=Y.getYjsValue(s))==null?void 0:u.doc;n?n.transact(()=>{c()}):c()}});return C.useEffect(()=>{g||b(v)},[g]),o(x),t.jsx(r.Box,{...i,ref:x,className:st.cx(g&&"isDragging"),children:S.current.map((c,n)=>t.jsx(It,{type:h,disabled:e,id:c,index:n,itemIndex:u=>S.current.indexOf(u),move:y,children:u=>{const j=s[c];return j?l(j.data,n,u):null}},c))})}function It({disabled:e,id:s,index:l,type:i,children:x,itemIndex:h,move:d}){const v=C.useRef(),[{isDragging:S},b,y]=te.useDrag({type:i,item:()=>({id:s}),canDrag:()=>!e,collect:o=>({isDragging:o.isDragging()})}),[,g]=te.useDrop({accept:i,canDrop:()=>!e,hover(o,c){var p;if(!v.current)return;const n=h(o.id),u=l;if(n===u)return;const j=(p=v.current)==null?void 0:p.getBoundingClientRect(),k=(j.bottom-j.top)/2,m=c.getClientOffset().y-j.top;n<u&&m<k||n>u&&m>k||d({id:o.id,index:n},{id:s,index:l})}});return typeof x=="function"?x({isDragging:S,drag:b,drop:o=>(v.current=o,g(o)),preview:y}):(b(g(y(v))),t.jsx(r.Box,{ref:v,children:x}))}function Ct({drop:e,preview:s,drag:l,disabled:i,isDragging:x,children:h,onDelete:d,onVisibilityChange:v,visible:S=!0,actions:b,alwaysShowActions:y=!1}){const{t:g}=_.useLocaleContext();return t.jsx(r.Box,{ref:e,sx:{":hover .hover-visible":{maxWidth:"100%"},opacity:S?1:.5},children:t.jsxs(r.Box,{sx:{position:"relative"},children:[t.jsx(r.Box,{ref:s,sx:{flex:1,borderRadius:.5,bgcolor:x?"action.hover":"background.paper",opacity:.9999},children:h}),!i&&t.jsx(r.Box,{className:y?"":"hover-visible",sx:{maxWidth:y?"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:o=>r.alpha(o.palette.grey[200],.9),borderRadius:1,p:.5,[`.${r.buttonClasses.root}`]:{minWidth:24,width:24,height:24,p:0}},children:[b,v&&t.jsx(r.Tooltip,{title:g(S?"hideParameter":"showParameter"),disableInteractive:!0,placement:"top",children:t.jsx(r.Button,{onClick:()=>v(!S),children:S?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:g("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:g("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[i,x]=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 v;const d=(v=h==null?void 0:h.data)==null?void 0:v.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:()=>x(!0)}),t.jsx(r.Dialog,{open:i,onClose:()=>x(!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,i,x)=>{const h=s?`${s}.${x}`:x;return mt.default(i)?ut.default(l,le(i,h)):l[h]=i,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:i})=>i.id!==s&&i.key===l)}function ie(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],i=l==null?void 0:l.data;return i?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:i,componentId:e})})})}):null}function Rt({value:e,componentId:s}){var g,o,c;const{t:l}=_.useLocaleContext(),{localState:{currentLocale:i,customComponentPreviewerProperties:x},state:{config:{defaultLocale:h}},localActions:{setCustomComponentPreviewerProperties:d}}=R.useStore(),v=Y.getYjsValue(e).doc,S=R.useAllComponents(),b=C.useMemo(()=>(x==null?void 0:x[s])??{},[s,x]),y=Pe.useReactive({componentId:s,propertiesValue:{...b}});return C.useEffect(()=>{y.componentId!==s&&(y.componentId=s,y.propertiesValue={...b})},[s,b,y]),C.useEffect(()=>{if(y.componentId!==s)return;const n=Object.fromEntries(Object.values(e.properties??{}).map(({data:u})=>{var j,k,a,m,p;return[u.id,{value:((j=y.propertiesValue[u.id])==null?void 0:j.value)??Le.parsePropertyValue(u,((a=(k=u.locales)==null?void 0:k[i])==null?void 0:a.defaultValue)??((p=(m=u.locales)==null?void 0:m[h])==null?void 0:p.defaultValue),{locale:i,defaultLocale:h})}]}));d(s,n)},[JSON.stringify(y.propertiesValue),s,y.componentId]),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:i,defaultLocale:h,allComponents:S,onUpdateConfig:n=>{v.transact(()=>{n(e)})}}),t.jsxs(r.Stack,{gap:2,direction:"row",justifyContent:"space-between",alignItems:"center",children:[t.jsx(r.Typography,{variant:"subtitle1",children:l("renderer")}),t.jsxs(r.TextField,{hiddenLabel:!0,size:"small",select:!0,SelectProps:{autoWidth:!0},value:((g=e.renderer)==null?void 0:g.type)||"react-component",onChange:n=>{v.transact(()=>{const u=n.target.value;e.renderer??(e.renderer={type:u}),e.renderer.type=u})},children:[t.jsx(r.MenuItem,{value:"react-component",children:"React Component"}),t.jsx(r.MenuItem,{value:"component",children:"Custom Component"})]})]}),((o=e.renderer)==null?void 0:o.type)==="component"&&t.jsx(Nt,{value:e}),((c=e.renderer)==null?void 0:c.type)==="react-component"&&t.jsx(At,{value:e}),t.jsx(ce,{config:e,currentLocale:i,defaultLocale:h,allComponents:S,propertiesValue:b,onChange:({value:n,id:u,path:j})=>{const k=[...j,"data"];if(!dt.default(e,k)){se.default.warning(l("cannotFindPropertyKey",{key:k.join(".")}));return}y.propertiesValue[u]={value:n.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,i)=>e.tags=i,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:i,currentLocale:x,defaultLocale:h,allComponents:d,onUpdateConfig:v}){var y,g,o,c,n,u;const{t:S}=_.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:()=>{v(j=>{if(j.properties){const a=Object.entries(j.properties).sort(([,p],[,P])=>p.index-P.index);delete j.properties[e.id],a.filter(([p])=>p!==e.id).forEach(([,p],P)=>{p.index=P})}})},visible:l,onVisibilityChange:j=>{v(k=>{const a=k.properties[e.id].data;a.visible=j})},alwaysShowActions:!0,children:t.jsxs(r.Stack,{direction:"column",gap:2,children:[t.jsx(r.TextField,{label:S("key"),size:"small",required:!0,sx:{width:"calc(100% - 80px - 8px)",flex:1,"& .MuiOutlinedInput-root":{borderColor:e.key?G(i.properties,e.id,e.key)?"warning.main":void 0:"error.main"},"& .MuiFormLabel-root":{color:e.key?G(i.properties,e.id,e.key)?"warning.main":"text.secondary":"error.main"},"& .MuiFormLabel-root.Mui-focused":{color:e.key?G(i.properties,e.id,e.key)?"warning.main":"primary.main":"error.main"}},value:e.key||"",onChange:j=>{v(k=>{const a=k.properties[e.id].data;a.key=j.target.value.trim()})},InputProps:{endAdornment:!e.key||e.key&&G(i.properties,e.id,e.key)?t.jsx(r.InputAdornment,{position:"end",sx:{width:16,ml:0},children:t.jsx(r.Tooltip,{title:e.key?S("duplicateKey"):S("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:S("label"),size:"small",sx:{flex:1},value:(((g=(y=e.locales)==null?void 0:y[x])==null?void 0:g.name)??((c=(o=e.locales)==null?void 0:o[h])==null?void 0:c.name))||"",onChange:j=>{v(k=>{var m;const a=k.properties[e.id].data;a.locales??(a.locales={}),(m=a.locales)[x]??(m[x]={}),a.locales[x].name=j.target.value})}}),t.jsx(r.TextField,{label:S("type"),size:"small",select:!0,sx:{flex:1},value:e.type==="string"&&e.multiline?"multiline":e.type||"string",onChange:j=>{v(k=>{const a=k.properties[e.id].data;if(a.locales)for(const p of Object.keys(a.locales))a.locales[p].defaultValue=void 0;const m=j.target.value;m==="multiline"?(a.type="string",a.multiline=!0):(typeof a.multiline<"u"&&delete a.multiline,a.type=m)})},children:Tt.map(j=>t.jsx(r.MenuItem,{value:j.value,children:j.label},j.value))})]}),t.jsxs(r.Stack,{direction:"row",gap:1,children:[t.jsx(b,{allComponents:d,defaultLocale:h,component:i,property:e,label:S("defaultValue"),size:"small",fullWidth:!0,value:(u=(n=e.locales)==null?void 0:n[x])==null?void 0:u.defaultValue,onChange:(j,k)=>{v(a=>{var p;const m=a.properties[e.id].data;if(k!=null&&k.forceUpdateProperty){const P=le(m),I=le(j);Object.keys(I).forEach(f=>{P[f]||we.default(m,f,I[f])})}else m.locales??(m.locales={}),(p=m.locales)[x]??(p[x]={}),m.locales[x].defaultValue=j})}}),e.type==="custom"?t.jsx(r.Box,{children:t.jsx(Dt,{property:e,allComponents:d})}):null]})]})})}function _t(e,s){const[l,i]=C.useState(0);return C.useEffect(()=>{const h=setTimeout(()=>{if(e.current){let d=e.current.parentElement,v=0;for(;d;)d.classList.contains("property-container")&&v++,d=d.parentElement;i(v)}},100);return()=>clearTimeout(h)},[e,s]),l}function Te({config:e,currentLocale:s,defaultLocale:l,allComponents:i,onUpdateConfig:x,useI18nEditor:h=!0}){const{t:d}=_.useLocaleContext(),v=A.usePopupState({variant:"dialog"}),S=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(v),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,y,g)=>{const o=ie(e.properties,b.id);return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:o?"1px solid":"1px dashed",borderColor:"divider"},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:g,visible:o,config:e,currentLocale:s,defaultLocale:l,allComponents:i,onUpdateConfig:x})})},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:()=>{x(b=>{var g;const y=R.nextId();b.properties??(b.properties={}),(g=b.properties)[y]??(g[y]={index:(S==null?void 0:S.length)||0,data:{id:y}})})},startIcon:t.jsx(D.AddRounded,{}),children:d("addObject",{object:d("property")})}),h&&t.jsx(Be,{...A.bindDialog(v),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:(i,x)=>e.componentId=x,allComponents:s})})})})})]})}function Et({value:e,valueImmutable:s,onChange:l,defaultLocale:i,allComponents:x}){var y;const[h,d]=C.useState(!1),{t:v,locale:S}=_.useLocaleContext(),b=typeof(e==null?void 0:e.componentId)=="string"?(y=x[e.componentId])==null?void 0:y.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:S,defaultLocale:i,allComponents:x,propertiesValue:e==null?void 0:e.properties,onChange:({id:g,value:o})=>{const c=at.default(o.value),n=JSON.parse(JSON.stringify(e));n!=null&&n.componentId&&(s?l==null||l({...n,properties:{...n.properties,[g]:{value:c}}}):(n.properties=n.properties??{},n.properties[g]={value:c},l==null||l(n)))}})}),t.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:v("close")})]})})]}):null}function Be({type:e="properties",component:s,...l}){var g,o,c;const{t:i}=_.useLocaleContext(),{state:{components:x,supportedLocales:h,config:{defaultLocale:d}}}=R.useStore(),v=R.useAllComponents(),S=Y.getYjsValue(s).doc,b=e==="properties"?s.properties:e==="parameters"&&((g=s.renderer)==null?void 0:g.type)==="component"?(o=x[s.renderer.componentId])==null?void 0:o.data.properties:void 0,y=((c=s.renderer)==null?void 0:c.type)==="component"?s:void 0;return t.jsxs(r.Dialog,{...l,fullWidth:!0,maxWidth:"lg",children:[t.jsx(r.DialogTitle,{children:i("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:n,name:u})=>t.jsx(r.TableCell,{children:t.jsxs(r.Typography,{color:"text.primary",children:[u,d===n&&t.jsx(D.StarRounded,{sx:{fontSize:12}})]})},n))})}),t.jsx(r.TableBody,{children:E.default(Object.values(b),"index").map(({data:n})=>t.jsx(r.TableRow,{children:h.map(({locale:u})=>{var j,k,a,m,p,P,I,f,w,O,B,V,N,q,$,W,K,L,J,H,ae,ue,de,pe,xe,me;return t.jsx(r.TableCell,{children:t.jsx(r.Stack,{gap:1,children:e==="properties"?t.jsxs(t.Fragment,{children:[t.jsx(r.TextField,{size:"small",label:"Key",value:n.key||"",onChange:M=>{S.transact(()=>{n.key=M.target.value.trim()})}}),t.jsx(r.TextField,{size:"small",label:i("label"),value:(((k=(j=n.locales)==null?void 0:j[u])==null?void 0:k.name)??((m=(a=n.locales)==null?void 0:a[d])==null?void 0:m.name))||"",onChange:M=>{S.transact(()=>{var F;n.locales??(n.locales={}),(F=n.locales)[u]??(F[u]={}),n.locales[u].name=M.target.value})}}),t.jsx(r.Box,{children:t.jsx(U,{allComponents:v,defaultLocale:d,component:s,property:n,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:X.default((P=(p=n.locales)==null?void 0:p[u])==null?void 0:P.defaultValue),value:((f=(I=n.locales)==null?void 0:I[u])==null?void 0:f.defaultValue)??((O=(w=n.locales)==null?void 0:w[d])==null?void 0:O.defaultValue),onChange:M=>{S.transact(()=>{var F;n.locales??(n.locales={}),(F=n.locales)[u]??(F[u]={}),n.locales[u].defaultValue=M})}})})]}):e==="parameters"&&y?t.jsx(r.Box,{children:t.jsx(U,{allComponents:v,defaultLocale:d,component:s,property:n,size:"small",fullWidth:!0,valueImmutable:X.default((q=(N=(V=(B=y.renderer.properties)==null?void 0:B[n.id])==null?void 0:V.locales)==null?void 0:N[u])==null?void 0:q.value),value:((L=(K=(W=($=y.renderer.properties)==null?void 0:$[n.id])==null?void 0:W.locales)==null?void 0:K[u])==null?void 0:L.value)??((ue=(ae=(H=(J=y.renderer.properties)==null?void 0:J[n.id])==null?void 0:H.locales)==null?void 0:ae[d])==null?void 0:ue.value)??((pe=(de=n.locales)==null?void 0:de[u])==null?void 0:pe.defaultValue)??((me=(xe=n.locales)==null?void 0:xe[d])==null?void 0:me.defaultValue),onChange:M=>{S.transact(()=>{var F,fe,je,be,he;(F=y.renderer).properties??(F.properties={}),(fe=y.renderer.properties)[je=n.id]??(fe[je]={}),(be=y.renderer.properties[n.id]).locales??(be.locales={}),(he=y.renderer.properties[n.id].locales)[u]??(he[u]={}),y.renderer.properties[n.id].locales[u].value=M})}})}):null},n.id)},u)})},n.id))})]})})}),t.jsx(r.DialogActions,{children:t.jsx(r.Button,{onClick:n=>{var u;return(u=l.onClose)==null?void 0:u.call(l,n,"escapeKeyDown")},children:i("close")})})]})}const ve=(e,s)=>l=>{const i=[l.palette.info.main,l.palette.primary.main,l.palette.secondary.main,l.palette.success.main,l.palette.warning.main],x=Math.min(i.length-1,e),h=i[x],d=r.alpha(h,.5),v=r.alpha(h,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:v,...s}};function Vt({property:e,onChange:s,defaultLocale:l,allComponents:i}){const{t:x,locale:h}=_.useLocaleContext(),d=C.useRef(null),v=_t(d,e),S=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(o=>o.data.visible!==!1&&o.data.key).forEach(({data:o})=>{var n,u,j,k;if(!o.key)return;let c=((u=(n=o.locales)==null?void 0:n[h])==null?void 0:u.defaultValue)??((k=(j=o.locales)==null?void 0:j[l])==null?void 0:k.defaultValue);if(o.type==="number")c=Number(c);else if(o.type==="boolean")c=c===!0||c==="true";else if((o.type==="json"||o.type==="yaml")&&typeof c=="string")try{o.type==="json"?c=JSON.parse(c):c=re.parse(c)}catch(a){console.error("Error parsing nested value",c,a),c={}}b[o.key]=c}),e.type==="array"&&!Array.isArray(b)&&(b=ne.default(b)?[]:[b]);const g=R.transformValue(b,e.type);s==null||s(g)}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:x("maker.properties.subProperties")})}),e.subProperties&&Object.keys(e.subProperties).length>0?t.jsx(Ie,{component:r.Stack,gap:2,list:e.subProperties,renderItem:(b,y,g)=>{const o=b.visible!==!1;return t.jsx(r.Paper,{elevation:0,className:"property-container",sx:{p:1.25,borderRadius:1,border:o?"1px solid":"1px dashed","&":ve(v)},children:t.jsx(r.Stack,{gap:2,children:t.jsx(Oe,{data:b,params:g,visible:o,config:{properties:e.subProperties},currentLocale:h,defaultLocale:l,allComponents:i,onUpdateConfig:c=>{try{const n={properties:e.subProperties||{}};c(n);const u={...e,subProperties:n.properties};s==null||s(u,{forceUpdateProperty:!0}),S()}catch(n){console.error("Error updating property:",n)}}})})},b.id)}}):t.jsx(Z.default,{style:{fontSize:12,height:100},children:x("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||{},y=R.nextId(),o={index:Object.values(b).length,data:{id:y,key:"",type:"string",visible:!0,locales:{[h]:{name:"",defaultValue:""}},subProperties:{}}},c={...e,subProperties:{...b,[y]:o}};s==null||s(c,{forceUpdateProperty:!0}),S()}catch(b){console.error("Error adding property:",b)}},sx:{"&":ve(v,{})},children:x("maker.properties.addSubProperty")})]})}function U({component:e,property:s,value:l,onChange:i,valueImmutable:x,defaultLocale:h,allComponents:d,...v}){var c,n,u,j,k;const{locale:S}=_.useLocaleContext(),b=z.useUploader(),y=C.useRef(null),g=()=>{var m;const a=(m=b==null?void 0:b.current)==null?void 0:m.getUploader();a==null||a.open(),y.current&&a.onceUploadSuccess(({response:p})=>{var I,f;let P=((I=p==null?void 0:p.data)==null?void 0:I.filename)||"";P&&(P=`mediakit://${P}`,l&&!l.includes("mediakit://")&&(P+=" # please use < import { getMediaKitAbsoluteUrl } from '@blocklet/pages-kit/builtin/utils' > to get the full address")),(f=y.current)==null||f.call(y,P)})},o=v.label??(((n=(c=s.locales)==null?void 0:c[S])==null?void 0:n.name)||((j=(u=s.locales)==null?void 0:u[h])==null?void 0:j.name)||s.key||s.id);if(s.type==="number")return t.jsx(zt,{...v,label:o,NumberProps:{value:["number","string"].includes(typeof l)?l:null,onChange:(a,m)=>i==null?void 0:i(m)}});if(s.type==="decimal")return t.jsx(r.TextField,{...v,label:o,type:"text",value:l??"",onChange:a=>{const m=a.target.value;if(m===""||m==="-"){i==null||i(m);return}if(/^-?(?!.*\..*\.)[0-9]*(\.[0-9]{0,9})?$/.test(m)){let P=m;/^-?[1-9]+[0-9]*(\.[0-9]{1,9})?$/.test(P)&&(P=Number(P)),i==null||i(P)}}});if(s.type==="boolean")return t.jsx(r.FormControlLabel,{label:o,labelPlacement:"start",control:t.jsx(r.Switch,{checked:l===!0,onChange:(a,m)=>i==null?void 0:i(m)})});if(s.type==="color")return t.jsx(St,{label:o,value:l,onChange:a=>{i==null||i(a)}});if(s.type==="json"||s.type==="yaml")return t.jsx(Pt,{label:o,value:l,onChange:a=>{i==null||i(a)},property:s,component:e,defaultLocale:h,allComponents:d,PropertyValueField:U,onUpload:a=>{y.current=a,g()}});if(s.type==="custom"){const a=(k=d[s.componentId])==null?void 0:k.data;return a?t.jsx(r.Box,{width:"100%",children:t.jsx(Q.CustomComponentRenderer,{componentId:a.id,props:{label:o,value:l,onChange:i},locale:S,dev:{mode:"draft",components:d,defaultLocale:h}})}):t.jsx(r.TextField,{...v,label:o,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:o,value:l==null?void 0:l.componentId,onChange:(a,m)=>{x||!l?i==null||i({...l&&JSON.parse(JSON.stringify(l)),componentId:m}):typeof l=="object"&&(l.componentId=m,i==null||i({...l&&JSON.parse(JSON.stringify(l)),componentId:m}))}}),(l==null?void 0:l.componentId)&&t.jsx(Et,{value:l,valueImmutable:x,onChange:i,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 m=s.type==="url"?l==null?void 0:l.url:l;return t.jsx(r.TextField,{...v,label:o,value:typeof m=="string"?m:"",multiline:a,minRows:a?2:void 0,maxRows:a?10:void 0,onChange:p=>i==null?void 0:i(s.type==="url"?{...l,url:p.target.value,mediaKitUrl:p.target.value}:p.target.value),InputProps:s.type==="url"?{sx:{pr:0},endAdornment:t.jsxs(r.InputAdornment,{position:"end",children:[t.jsx(z.UploaderButton,{onChange:async({response:p})=>{var w,O,B;const P=((w=p==null?void 0:p.data)==null?void 0:w.url)||((O=p==null?void 0:p.data)==null?void 0:O.fileUrl);let I;P&&(I=await z.getImageSize(P).catch(()=>z.getVideoSize(P)).catch(()=>{}));let f=((B=p==null?void 0:p.data)==null?void 0:B.filename)||"";f&&(f=`mediakit://${f}`),i==null||i({url:P,mediaKitUrl:f,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:o,value:Array.isArray(l)?l:[],onChange:a=>i==null?void 0:i(a),property:s,renderItem:({item:a,index:m,onChange:p})=>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(P=>P.data.visible!==!1).map(({data:P})=>P.key?t.jsx(U,{component:e,property:P,value:a[P.key],onChange:I=>{const f={...a,[P.key]:I};p(f)},size:"small",fullWidth:!0,defaultLocale:h,allComponents:d},P.id):null)},m):t.jsx(r.TextField,{size:v.size,fullWidth:!0,value:a,onChange:P=>p(P.target.value)})}):(console.error("Unsupported property type",s.type),null)}function zt({NumberProps:e,...s}){const{getInputProps:l}=Se.unstable_useNumberInput(e),i=l();return t.jsx(r.TextField,{...s,inputProps:i})}const Re=`import React from '@blocklet/pages-kit/builtin/react'
|
|
2
2
|
import { Box } from '@blocklet/pages-kit/builtin/mui/material'
|
|
3
3
|
|
|
4
4
|
export default function () {
|
|
@@ -8,4 +8,4 @@ export default function () {
|
|
|
8
8
|
</Box>
|
|
9
9
|
)
|
|
10
10
|
}`,_e=`console.log('hello')
|
|
11
|
-
`;function At({value:e}){const{locale:s}=_.useLocaleContext(),l=ke.useUpdate(),
|
|
11
|
+
`;function At({value:e}){const{locale:s}=_.useLocaleContext(),l=ke.useUpdate(),i=Y.getYjsValue(e).doc;return C.useEffect(()=>{var x;(x=e.renderer)!=null&&x.script||(i.transact(()=>{e.renderer.script=e.renderer.type==="react-component"?Re:_e}),l())},[e]),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:t.jsx(oe.CodeEditor,{keyId:e.id,locale:s,language:"typescript",value:e.renderer.script||"",onChange:x=>e.renderer.script=x,typeScriptNoValidation:!1,fullScreenOptions:{enableEscExit:!0}},e.id)})}function Nt({value:e}){var y,g,o;const{t:s}=_.useLocaleContext(),l=Y.getYjsValue(e).doc,{state:{components:i,config:{defaultLocale:x},resources:h},localState:{currentLocale:d}}=R.useStore(),v=R.useAllComponents(),S=((y=i[e.renderer.componentId])==null?void 0:y.data)??((o=(g=h.components)==null?void 0:g[e.renderer.componentId])==null?void 0:o.component),b=A.usePopupState({variant:"dialog"});return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:1,children:[t.jsx(ee,{allComponents:v,excludes:[e.id],value:e.renderer.componentId,onChange:(c,n)=>e.renderer.componentId=n}),S&&t.jsxs(t.Fragment,{children:[t.jsxs(r.Stack,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[t.jsx(r.Typography,{variant:"subtitle2",children:s("parameters")}),t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...A.bindTrigger(b),children:t.jsx(D.TranslateRounded,{fontSize:"small"})})]}),S.properties&&E.default(Object.values(S.properties),"index").map(({data:c})=>{var n,u,j,k,a,m,p,P,I,f,w,O,B,V,N,q;return t.jsx(r.Box,{children:t.jsx(U,{allComponents:v,defaultLocale:x,component:S,property:c,fullWidth:!0,size:"small",valueImmutable:X.default((k=(j=(u=(n=e.renderer.properties)==null?void 0:n[c.id])==null?void 0:u.locales)==null?void 0:j[d])==null?void 0:k.value),value:((P=(p=(m=(a=e.renderer.properties)==null?void 0:a[c.id])==null?void 0:m.locales)==null?void 0:p[d])==null?void 0:P.value)??((O=(w=(f=(I=e.renderer.properties)==null?void 0:I[c.id])==null?void 0:f.locales)==null?void 0:w[x])==null?void 0:O.value)??((V=(B=c.locales)==null?void 0:B[d])==null?void 0:V.defaultValue)??((q=(N=c.locales)==null?void 0:N[x])==null?void 0:q.defaultValue),onChange:$=>{l.transact(()=>{var W,K,L,J,H;(W=e.renderer).properties??(W.properties={}),(K=e.renderer.properties)[L=c.id]??(K[L]={}),(J=e.renderer.properties[c.id]).locales??(J.locales={}),(H=e.renderer.properties[c.id].locales)[d]??(H[d]={}),e.renderer.properties[c.id].locales[d].value=$})}})},c.id)}),t.jsx(Be,{...A.bindDialog(b),component:e,type:"parameters"})]})]})})}function ee({label:e,options:s,excludes:l,value:i,onChange:x,allComponents:h,...d}){var y;const{t:v}=_.useLocaleContext(),S=s??E.default(Object.values(jt.default(h,...l??[])),"index").map(g=>g.data),b=(typeof i=="string"?(y=h[i])==null?void 0:y.data:void 0)??null;return t.jsx(r.Autocomplete,{...d,size:"small",options:S,autoHighlight:!0,isOptionEqualToValue:(g,o)=>g.id===o.id,getOptionKey:g=>g.id,getOptionLabel:g=>g.name||g.id,renderInput:g=>t.jsx(r.TextField,{label:e||v("component"),...g}),value:b,onChange:(g,o)=>{var n,u,j,k,a,m;let c={};o&&(c={blockletId:(n=h[o==null?void 0:o.id])==null?void 0:n.blockletId,blockletTitle:(u=h[o==null?void 0:o.id])==null?void 0:u.blockletTitle,componentName:((k=(j=h[o==null?void 0:o.id])==null?void 0:j.data)==null?void 0:k.name)||((m=(a=h[o==null?void 0:o.id])==null?void 0:a.data)==null?void 0:m.id)}),x==null||x(g,o==null?void 0:o.id,c)}})}function ce({config:e,allComponents:s,defaultLocale:l,propertiesValue:i,currentLocale:x,onChange:h,props:d}){const{t:v}=_.useLocaleContext(),[S,b]=C.useState(e==null?void 0:e.properties),[y,g]=C.useState(null);C.useEffect(()=>{(()=>{var k,a;((k=e==null?void 0:e.renderer)==null?void 0:k.type)==="react-component"&&ne.default(e==null?void 0:e.properties)?Q.transpileAndLoadScript((a=e==null?void 0:e.renderer)==null?void 0:a.script).then(m=>{const p=Q.getPropertiesFromCode(m);b(p)}):b(e==null?void 0:e.properties)})()},[JSON.stringify(e)]);const o=C.useCallback(()=>!e||!S?{}:Object.values(S).reduce((j,{data:k})=>{var m,p,P,I,f;const a=k.key||k.id;return j[k.id]={key:a,value:(d==null?void 0:d[a])??((m=i==null?void 0:i[k.id])==null?void 0:m.value)??((P=(p=k.locales)==null?void 0:p[x])==null?void 0:P.defaultValue)??((f=(I=k.locales)==null?void 0:I[l])==null?void 0:f.defaultValue),id:k.id,type:k.type},j},{}),[JSON.stringify(S),e,i,x,l]),c=C.useMemo(()=>{if(!S)return{canUseProperties:[],visibleProperties:[],canUsePropertiesKeys:[]};const j=E.default(Object.values(S),"index"),k=j.filter(({data:p})=>p.key&&ie(S,p.id)),a=j.filter(({data:p})=>p.key&&p.type!=="component"),m=a.map(({data:p})=>p.key);return{canUseProperties:a,visibleProperties:k,canUsePropertiesKeys:m}},[JSON.stringify(S)]),n=o(),u=ft.default(n,"key");return t.jsx(z.UploaderProvider,{children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(r.Typography,{variant:"subtitle1",children:v("maker.properties.parameters")}),!e||c.canUsePropertiesKeys.length===0?t.jsx(Z.default,{style:{fontSize:12},children:v("maker.properties.noParameters")}):t.jsxs(t.Fragment,{children:[t.jsx(r.Stack,{gap:2,children:c.visibleProperties.map(({data:j})=>{var k,a;return t.jsx(r.Box,{children:t.jsx(U,{allComponents:s,defaultLocale:l,size:"small",fullWidth:!0,component:e,property:j,valueImmutable:X.default((k=i==null?void 0:i[j.id])==null?void 0:k.value),value:(d==null?void 0:d[j.key||j.id])??((a=n[j.id])==null?void 0:a.value),onChange:m=>{h({path:["properties",j.id],id:j.id,value:{value:m},shouldSync:ge(j),excludeKeys:[],key:j.key||j.id})}})},j.id)})}),t.jsx(r.Stack,{gap:2,sx:{width:"100%"},children:t.jsx(Q.CustomComponentRenderer,{componentId:(e==null?void 0:e.id)||"",renderType:"setting",locale:x,properties:n,dev:{mode:"draft",components:s,defaultLocale:l},props:{...bt.default(d??{},c.canUsePropertiesKeys),onChange:j=>{const{canUsePropertiesKeys:k}=c;Object.keys(j).filter(m=>{var p;return!xt.default(j[m],(p=u==null?void 0:u[m])==null?void 0:p.value)}).filter(m=>{var p,P,I,f;return!(m==="locale"&&!pt.default(u[m],"locale")||((p=u[m])==null?void 0:p.type)==="component"||(((P=u[m])==null?void 0:P.type)==="yaml"||((I=u[m])==null?void 0:I.type)==="json")&&ie(S,(f=u[m])==null?void 0:f.id))}).reduce((m,p)=>m.then(()=>{const P=u[p],I=k.includes(p);if(P!=null&&P.id&&I)return h({path:["properties",P.id],id:P.id,value:{value:j[p]},shouldSync:ge(P),excludeKeys:[],key:P.key||P.id}),Promise.resolve();const f=`propertyNotFound${p}`;if(y===f)return Promise.resolve();se.default.close(y);const w=se.default.warning(v("maker.properties.propertyNotFound",{key:p}),{key:f});return g(w),Promise.resolve()}),Promise.resolve())}}})})]})]})})}exports.BasicInfo=Ce;exports.CustomComponentAutocomplete=ee;exports.CustomComponentSettings=Bt;exports.DefaultReactComponentScriptTemplate=Re;exports.DefaultWebComponentScriptTemplate=_e;exports.ParametersConfig=ce;exports.PropertiesConfig=Te;exports.PropertyValueField=U;
|
package/lib/cjs/site-state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./chunks/site-state-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./chunks/site-state-CIPfhJn5.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]})});
|
package/lib/es/add-component.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as e, jsx as I, Fragment as f } from "react/jsx-runtime";
|
|
2
|
-
import { b as gI, i as q, j as AC, n as _, h as iC, k as oC, l as wC, g as sC } from "./chunks/state-
|
|
2
|
+
import { b as gI, i as q, j as AC, n as _, h as iC, k as oC, l as wC, g as sC } from "./chunks/state-Br2xp7Mf.js";
|
|
3
3
|
import tI from "@arcblock/ux/lib/Empty";
|
|
4
4
|
import { useLocaleContext as T } from "@arcblock/ux/lib/Locale/context";
|
|
5
5
|
import { Icon as $ } from "@iconify-icon/react";
|
|
@@ -7,14 +7,14 @@ import MC from "@mui/icons-material/Check";
|
|
|
7
7
|
import { Box as D, styled as nI, InputLabel as uI, TextField as h, IconButton as G, Autocomplete as XI, FormControl as LC, Select as jC, MenuItem as Q, ListItemText as WI, Typography as k, OutlinedInput as JC, useTheme as OC, CircularProgress as AI, InputAdornment as mC, Button as W, Grid as V, Stack as TI, Input as YI, CssBaseline as SC, Menu as BC, Dialog as MI, DialogTitle as LI, DialogContent as jI, DialogActions as JI, Tabs as yC, Tab as DC, Card as eC, CardMedia as bC, CardContent as NC, Skeleton as KC } from "@mui/material";
|
|
8
8
|
import { useDebounceFn as dC, useRequest as zC, useReactive as v, useUpdate as xI, useThrottleFn as rI, useGetState as cC, useAsyncEffect as hI, useBoolean as ZI } from "ahooks";
|
|
9
9
|
import QI, { useState as F, useEffect as n, useMemo as t, createContext as OI, useContext as FC, useRef as Z, useCallback as Y, createElement as aC, forwardRef as mI, useImperativeHandle as SI } from "react";
|
|
10
|
-
import { I as HC, n as bI, A as lC, b as EC, T as tC, c as nC, B as uC } from "./chunks/array-
|
|
10
|
+
import { I as HC, n as bI, A as lC, b as EC, T as tC, c as nC, B as uC } from "./chunks/array-HCA75FfO.js";
|
|
11
11
|
import { styled as iI } from "@arcblock/ux/lib/Theme";
|
|
12
12
|
import "@blocklet/pages-kit/builtin/color-picker";
|
|
13
13
|
import "@blocklet/pages-kit/utils/style";
|
|
14
14
|
import { cx as sI } from "@emotion/css";
|
|
15
15
|
import "lodash/without";
|
|
16
16
|
import { red as XC, pink as WC, purple as TC, indigo as YC, blue as xC, cyan as rC, teal as hC, green as ZC, lime as QC, yellow as kC, amber as RC, orange as pC, brown as UC, grey as fC, blueGrey as GC } from "@mui/material/colors";
|
|
17
|
-
import { C as CI } from "./chunks/config-string-
|
|
17
|
+
import { C as CI } from "./chunks/config-string-17RNX8vu.js";
|
|
18
18
|
import VC from "lodash/cloneDeep";
|
|
19
19
|
import { DragIndicator as NI, SearchRounded as vC, Remove as PC, Add as kI, Language as _C, CopyAll as $C, Settings as qC, Delete as Ig } from "@mui/icons-material";
|
|
20
20
|
import { useDrag as Cg, useDrop as gg } from "react-dnd";
|
|
@@ -2546,7 +2546,7 @@ function QA({
|
|
|
2546
2546
|
components: w || g,
|
|
2547
2547
|
defaultLocale: A
|
|
2548
2548
|
},
|
|
2549
|
-
properties: o
|
|
2549
|
+
properties: (o == null ? void 0 : o[C]) ?? {}
|
|
2550
2550
|
}
|
|
2551
2551
|
);
|
|
2552
2552
|
}
|
|
@@ -5,7 +5,7 @@ import te from "lodash/isEmpty";
|
|
|
5
5
|
import tt from "lodash/pick";
|
|
6
6
|
import ee, { createContext as $t, useMemo as L, useCallback as F, useContext as Ct, Fragment as oe, isValidElement as Nt, useState as et, useEffect as H, useRef as lt } from "react";
|
|
7
7
|
import ot from "lodash/keyBy";
|
|
8
|
-
import { f as T, g as I, E as re, i as st, m as ct } from "./state-
|
|
8
|
+
import { f as T, g as I, E as re, i as st, m as ct } from "./state-Br2xp7Mf.js";
|
|
9
9
|
import { AIForm as ht, AIFormResult as ft } from "@blocklet/ai-runtime/components";
|
|
10
10
|
import { deepmerge as ne } from "@mui/utils";
|
|
11
11
|
import { ErrorBoundary as ie } from "react-error-boundary";
|
|
@@ -4,7 +4,7 @@ import { Icon as P } from "@iconify-icon/react";
|
|
|
4
4
|
import { TextField as A, Stack as w, FormControlLabel as F, Switch as L, Box as j, InputAdornment as k } from "@mui/material";
|
|
5
5
|
import { forwardRef as B, useState as D, useEffect as E, useImperativeHandle as U } from "react";
|
|
6
6
|
import { useDebounce as V } from "react-use";
|
|
7
|
-
import { g as x } from "./state-
|
|
7
|
+
import { g as x } from "./state-Br2xp7Mf.js";
|
|
8
8
|
const J = B(function({ showMarkdown: I, markdown: h, onMarkdownChange: n, showUploader: S, value: o, meta: H, onChange: l, ...a }, z) {
|
|
9
9
|
const [e, c] = D("");
|
|
10
10
|
E(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import { u as a, S as o, a as s, b as n } from "./state-
|
|
2
|
+
import { u as a, S as o, a as s, b as n } from "./state-Br2xp7Mf.js";
|
|
3
3
|
function d({ children: t }) {
|
|
4
4
|
const r = a();
|
|
5
5
|
return /* @__PURE__ */ e(o, { url: s(r ?? ""), name: "root", waitingSynced: !0, children: /* @__PURE__ */ e(i, { children: t }) });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as $ } from "react/jsx-runtime";
|
|
2
|
-
import { u as X, d as Y, e as fe, f as he, g as be, c as ye } from "./state-
|
|
2
|
+
import { u as X, d as Y, e as fe, f as he, g as be, c as ye } from "./state-Br2xp7Mf.js";
|
|
3
3
|
import { useLocaleContext as J } from "@arcblock/ux/lib/Locale/context";
|
|
4
4
|
import Z from "@arcblock/ux/lib/Result";
|
|
5
5
|
import { useHeaderState as ve } from "@blocklet/pages-kit/builtin/page/header";
|
|
@@ -21,7 +21,7 @@ import { Helmet as Be } from "react-helmet";
|
|
|
21
21
|
import { useSearchParams as ue, Routes as Oe, Route as E, Navigate as Fe, ScrollRestoration as _e } from "react-router-dom";
|
|
22
22
|
import { useAsync as pe } from "react-use";
|
|
23
23
|
import { joinURL as S } from "ufo";
|
|
24
|
-
import { S as De, n as K, P as Le, a as Ne, B as $e, g as Ae } from "./array-
|
|
24
|
+
import { S as De, n as K, P as Le, a as Ne, B as $e, g as Ae } from "./array-HCA75FfO.js";
|
|
25
25
|
import { styled as me, useTheme as He } from "@arcblock/ux/lib/Theme";
|
|
26
26
|
import Ue from "@blocklet/ui-react/lib/Footer";
|
|
27
27
|
import "webfontloader";
|
|
@@ -96,7 +96,7 @@ function Je({ mode: t }) {
|
|
|
96
96
|
}
|
|
97
97
|
return /* @__PURE__ */ e(Ze, { children: ({ state: n }) => /* @__PURE__ */ e(V, { mode: t, state: n }) });
|
|
98
98
|
}
|
|
99
|
-
const Ze = le(() => import("./draft-data-
|
|
99
|
+
const Ze = le(() => import("./draft-data-CyeVe0kA.js"));
|
|
100
100
|
function et({
|
|
101
101
|
mode: t,
|
|
102
102
|
children: n
|
|
@@ -439,7 +439,7 @@ function H({
|
|
|
439
439
|
!((I = l.footer) != null && I.hidden) && /* @__PURE__ */ e(We, {})
|
|
440
440
|
] });
|
|
441
441
|
}
|
|
442
|
-
const tt = le(() => import("./publish-button-
|
|
442
|
+
const tt = le(() => import("./publish-button-WmGjhj6q.js")), de = re(xe)`
|
|
443
443
|
&.sticky {
|
|
444
444
|
position: sticky;
|
|
445
445
|
top: 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as t, jsxs as f, Fragment as le } from "react/jsx-runtime";
|
|
2
|
-
import { u as ce, c as de } from "./state-
|
|
2
|
+
import { u as ce, c as de } from "./state-Br2xp7Mf.js";
|
|
3
3
|
import { useLocaleContext as U } from "@arcblock/ux/lib/Locale/context";
|
|
4
4
|
import Q from "@arcblock/ux/lib/Toast";
|
|
5
5
|
import { generateParamCombinations as me } from "@blocklet/pages-kit/utils/route";
|
|
@@ -10,8 +10,8 @@ import { produce as Oe } from "immer";
|
|
|
10
10
|
import ee from "lodash/difference";
|
|
11
11
|
import { useState as j, useMemo as R, useCallback as v, forwardRef as je, useImperativeHandle as ve, useEffect as $, useRef as Te } from "react";
|
|
12
12
|
import { useAsync as Re } from "react-use";
|
|
13
|
-
import { L as ze } from "./home-
|
|
14
|
-
import { p as Le, g as Be } from "./array-
|
|
13
|
+
import { L as ze } from "./home-COrN_x32.js";
|
|
14
|
+
import { p as Le, g as Be } from "./array-HCA75FfO.js";
|
|
15
15
|
function Ee(s) {
|
|
16
16
|
const [y, w] = j(!1);
|
|
17
17
|
return /* @__PURE__ */ t(
|