@blocklet/pages-kit-inner-components 0.4.103 → 0.4.105
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/project-html.js +4 -4
- package/lib/cjs/setting.js +1 -1
- package/lib/es/project-html.js +70 -63
- package/lib/es/setting.js +2 -2
- package/package.json +11 -11
package/lib/cjs/project-html.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const C=require("./chunks/site-state-D6GUd_1A.js"),S=require("@blocklet/crawler/middlewares"),W=require("@blocklet/pages-kit/types"),J=require("@blocklet/pages-kit/utils/preload"),G=require("@blocklet/sdk/lib/component"),I=require("@blocklet/sdk/lib/config"),z=require("cheerio/slim"),K=require("express"),O=require("fs"),Q=require("mustache"),q=require("path"),j=require("ufo"),U=e=>e&&e.__esModule?e:{default:e};function V(e){if(e&&e.__esModule)return e;const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const u=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(s,t,u.get?u:{enumerable:!0,get:()=>e[t]})}}return s.default=e,Object.freeze(s)}const d=U(I),A=V(z),X=U(Q),Y=["/assets/"],D=()=>[!0,"true"].includes(d.default.env.preferences.allowCrawler);function x(){D()?S.initCronCrawlBlocklet({time:"0 0 */12 * * *",options:{}}):S.cancelCronCrawlBlocklet()}x();d.default.events.on(d.default.Events.envUpdate,x);function Z({app:e,viteDevServer:s,state:t}){let u;if(s){const n=O.readFileSync(q.resolve(process.cwd(),"./index.html"),"utf-8");e.use(async(g,b,v)=>{const P=g.originalUrl;u=await s.transformIndexHtml(P,n),v()})}else u=O.readFileSync(q.resolve(process.env.BLOCKLET_APP_DIR,"dist/index.html"),"utf-8");const y=K.Router();y.use((n,g,b)=>{if(n.headers["x-unique-record"]==="dial_http"){C.logger.info("[html] dial http request, return 200 status code"),g.status(200).send("ok");return}b()},S.initSEOMiddleware({autoReturnHtml:!0,allowCrawler:D})),y.get("/:path(*)?",async(n,g,b)=>{var $,E,L;if(Y.some(c=>{var i;return(i=n.path)==null?void 0:i.startsWith(c)})){b();return}const v=performance.now(),P=()=>Math.round(performance.now()-v),R="production";let o,p,w=u;if(n.path.startsWith("/pages")){const c=n.params.lang,i=n.cookies.nf_lang,_=new Set([...d.default.env.languages.map(h=>h.code)]);let f=(c&&_.has(c)?c:void 0)||(_.has(i)?i:void 0)||[..._][0];if((!f||!(($=t.supportedLocales)!=null&&$.find(h=>h.locale===f)))&&(f=((L=(E=t.supportedLocales)==null?void 0:E[0])==null?void 0:L.locale)||""),f){const h=[];Object.values(t.pages).forEach(l=>{const N=Object.values((l==null?void 0:l.sections)??{}).filter(a=>{var k;return a.component==="custom-component"&&((k=a.config)==null?void 0:k.componentId)}).map(a=>{var k,M;return{id:a.id,componentId:a.config.componentId,useCache:a.config.useCache,cacheDuration:a.config.cacheDuration,properties:(M=(k=a.locales)==null?void 0:k[f])==null?void 0:M.properties}});h.push(...N)});const H=new Promise(l=>{setTimeout(()=>{l({})},90*1e3)});try{await Promise.race([H,C.getPreloadComponents({mode:R,req:n,state:t,locale:f,instances:h,module:W.PreloadComponentScriptModule.UMD_FN}).then(l=>{l&&(p=J.injectPreloadComponents(l))})])}catch(l){C.logger.warn("getPreloadComponents timeout in promise race, skip inject html elements"),C.logger.warn(l)}}}try{const c=(o==null?void 0:o.title)||d.default.env.appName,i=(o==null?void 0:o.description)||d.default.env.appDescription,_=j.withQuery(j.joinURL(d.default.env.appUrl,"/.well-known/service/blocklet/og.png"),{title:c,description:i});w=X.default.render(u,{ogTitle:c,ogDescription:i,ogImage:F(o==null?void 0:o.image)||_,pagesPublishedAt:(t==null?void 0:t.config.publishedAt)||new Date().getTime()})}catch{}const r=t==null?void 0:t.config.fontFamily,B=n.query.mode==="draft"||n.url.includes("preview"),m=A.load(w);m("head").find("#injected-head-elements").replaceWith(`
|
|
2
2
|
${o!=null&&o.backgroundColor?`<meta name="theme-color" content="${o.backgroundColor}" /><style>html,body,#app {background-color: ${o.backgroundColor} !important;}</style>`:""}
|
|
3
|
-
${
|
|
4
|
-
${
|
|
3
|
+
${r!=null&&r.title?`<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${r.title}&display=swap">`:""}
|
|
4
|
+
${r!=null&&r.description&&(r==null?void 0:r.description)!==(r==null?void 0:r.title)?`<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${r.description}&display=swap">`:""}
|
|
5
5
|
<script>
|
|
6
6
|
|
|
7
7
|
window.__PAGE_STATE__ = ${JSON.stringify(t,null,0)}
|
|
@@ -20,4 +20,4 @@
|
|
|
20
20
|
darkMode: "class",
|
|
21
21
|
};
|
|
22
22
|
<\/script>`:""}
|
|
23
|
-
`);const T=
|
|
23
|
+
`);const T=I.getBlockletJs();if(T&&m('script[src="__blocklet__.js"]').replaceWith(`<script>${T}<\/script>`),p!=null&&p.html&&m("head").find("#injected-html-elements").replaceWith(p.html),n.cachedHtml){const c=A.load(n.cachedHtml);m("body").html(c("body").html()||"")}w=m.html(),g.send(w),C.logger.info(`[html] render: ${n.path}, ${P()}ms`),m.root().children().remove(),w=null,o=null,p=null}),e.use(y)}function F(e){const s=G.getComponentMountPoint("image-bin");return s&&e&&!/^(https?:\/\/|\/)/.test(e)?d.default.env.appUrl+j.joinURL(s,"uploads",e):e}module.exports=Z;
|
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-BoXTl4DM.js"),Ve=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),ne=require("@blocklet/code-editor"),Ee=require("@mui/icons-material/AddRounded"),ze=require("@mui/icons-material/ArrowDownward"),Ne=require("@mui/icons-material/ArrowUpward"),Ae=require("@mui/icons-material/DeleteOutline"),r=require("@mui/material"),qe=require("lodash/sortBy"),C=require("react"),ke=require("react-use"),te=require("./chunks/config-color-Da8lKUL0.js"),Fe=require("lodash/isEmpty"),Ue=require("lodash/set"),Me=require("yaml"),F=require("./uploader.js"),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"),ye=require("@mui/material/styles"),Y=require("@syncedstore/core"),Pe=require("ahooks"),Je=require("lodash/assign"),He=require("lodash/get"),Ye=require("lodash/has"),$e=require("lodash/isNil"),Ge=require("lodash/isObject"),Qe=require("lodash/keyBy"),Xe=require("lodash/omit"),Ze=require("lodash/pick"),et=require("lodash/reduce"),z=require("material-ui-popup-state/hooks"),tt=require("react-error-boundary"),rt=require("@emotion/css"),re=require("react-dnd"),B=e=>e&&e.__esModule?e:{default:e};function st(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=B(Ve),lt=B(Ee),ot=B(ze),it=B(Ne),nt=B(Ae),V=B(qe),we=B(Fe),Ie=B(Ue),se=st(Me),ct=B(We),le=B(Ke),at=B(Je),ut=B(He),dt=B(Ye),X=B($e),pt=B(Ge),mt=B(Qe),xt=B(Xe),ft=B(Ze),jt=B(et);function bt({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(nt.default,{fontSize:"small"})})}function ht({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 yt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(ot.default,{fontSize:"small"})})}function gt({label:e,value:s,onChange:l,disabled:o=!1,itemLabel:p="",emptyHeight:b=40,property:d,renderItem:g,...v}){const{t:h,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]),a=C.useCallback(()=>{const m=[...n,""];i(m),y()},[n,i,y]),u=C.useCallback(()=>{if(!d||!d.subProperties)return a();const m={};V.default(Object.values(d.subProperties),"index").forEach(({data:T})=>{var N,A;if(!T.key)return;const E=((A=(N=T.locales)==null?void 0:N[P])==null?void 0:A.defaultValue)??"";m[T.key]=E});const O=[...n,m];i(O),y()},[n,i,y,d,P,a]),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,T)=>T!==m);i(w),y()},[n,i,y]),c=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||`${h("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(ht,{disabled:o||m===0,onClick:()=>c(m)}),t.jsx(yt,{disabled:o||m===n.length-1,onClick:()=>j(m)}),t.jsx(bt,{disabled:o,onClick:()=>S(m)})]})}],[g,k,d,f,p,h,o,v,S,c,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(T=>t.jsx(r.TableCell,{width:T.width,align:T.align||"left",sx:{borderBottom:"none"},children:T.renderCell({row:m,index:w,onChange:E=>f(w,E)})},`${w}-${T.field}`))},w))})]})}):t.jsx(Z.default,{style:{fontSize:12,height:b},children:h("maker.properties.arrayEmpty")}),t.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:o,startIcon:t.jsx(lt.default,{}),onClick:u,children:h("maker.properties.addArrayItem")})]}):t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,minHeight:150},children:t.jsx(ne.CodeEditor,{keyId: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 vt({value:e,onChange:s,...l}){const o=C.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsx(te.ConfigString,{...l,value:e,onChange:s,InputProps:{endAdornment:t.jsx(r.InputAdornment,{position:"end",children:t.jsx(te.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(te.ConfigColorDialog,{ref:o,onSave:({value:p},b)=>{s(p),b()}})]})}function kt({label:e,value:s,onChange:l,property:o,component:p,defaultLocale:b,allComponents:d,PropertyValueField:g,onUpload:v}){const{locale:h}=_.useLocaleContext(),P=C.useRef(null);if(!we.default(o.subProperties)){const i=V.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,a)=>{const{data:u}=n,x=u.key??u.id,S=a===i.length-1;let c=null;try{s&&typeof s=="object"?c=s[x]:typeof s=="string"&&(c=(o.type==="yaml"?se.parse(s||""):JSON.parse(s||"{}"))[x])}catch{}c==null&&(u.locales&&h&&u.locales[h]?c=u.locales[h].defaultValue:u.locales&&b&&u.locales[b]&&(c=u.locales[b].defaultValue));const j=k=>{try{let I={};if(typeof s=="string")try{I=o.type==="yaml"?se.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(I={...s});Ie.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:c,onChange:j,size:"small",fullWidth:!0,defaultLocale:b,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(ne.CodeEditor,{keyId:o.id,locale:h,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 St=["string","multiline","json","yaml","url","component","custom"];function ge(e){return e.type?!St.includes(e.type):!1}function Ce({disabled:e,list:s,renderItem:l,...o}){const p=C.useRef(null),b=C.useId(),d=Pe.useUpdate(),g=V.default(Object.entries(s),n=>n[1].index).map(n=>n[0]),v=C.useRef(g),h=C.useCallback(n=>{v.current=n,d()},[d]),P=C.useCallback(({index:n},{index:a})=>{const u=[...v.current];u.splice(a,0,...u.splice(n,1)),h(u)},[h]);C.useEffect(()=>{h(g)},[g.join("-")]);const[{isOver:y},i]=re.useDrop({accept:b,collect:n=>({isOver:n.isOver()}),canDrop:()=>!e,drop:()=>{var u;const n=()=>{v.current.forEach((x,S)=>{const c=s[x];c&&(c.index=S)})},a=(u=Y.getYjsValue(s))==null?void 0:u.doc;a?a.transact(()=>{n()}):n()}});return C.useEffect(()=>{y||h(g)},[y]),i(p),t.jsx(r.Box,{...o,ref:p,className:rt.cx(y&&"isDragging"),children:v.current.map((n,a)=>t.jsx(Pt,{type:b,disabled:e,id:n,index:a,itemIndex:u=>v.current.indexOf(u),move:P,children:u=>{const x=s[n];return x?l(x.data,a,u):null}},n))})}function Pt({disabled:e,id:s,index:l,type:o,children:p,itemIndex:b,move:d}){const g=C.useRef(),[{isDragging:v},h,P]=re.useDrag({type:o,item:()=>({id:s}),canDrag:()=>!e,collect:i=>({isDragging:i.isDragging()})}),[,y]=re.useDrop({accept:o,canDrop:()=>!e,hover(i,n){var f;if(!g.current)return;const a=b(i.id),u=l;if(a===u)return;const x=(f=g.current)==null?void 0:f.getBoundingClientRect(),S=(x.bottom-x.top)/2,j=n.getClientOffset().y-x.top;a<u&&j<S||a>u&&j>S||d({id:i.id,index:a},{id:s,index:l})}});return typeof p=="function"?p({isDragging:v,drag:h,drop:i=>(g.current=i,y(i)),preview:P}):(h(y(P(g))),t.jsx(r.Box,{ref:g,children:p}))}function wt({drop:e,preview:s,drag:l,disabled:o,isDragging:p,children:b,onDelete:d,onVisibilityChange:g,visible:v=!0,actions:h,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:b}),!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:[h,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 It({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:b=>l==null?void 0:l(b.target.value),InputProps:{endAdornment:t.jsx(F.UploaderButton,{onChange:({response:b})=>{var g;const d=(g=b==null?void 0:b.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 oe(e,s=""){return jt.default(e,(l,o,p)=>{const b=s?`${s}.${p}`:p;return pt.default(o)?at.default(l,oe(o,b)):l[b]=o,l},{})}const Ct=[{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 ie(e,s){var l;return!e||!s?!1:((l=e[s])==null?void 0:l.data.visible)??!0}function Ot({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(tt.ErrorBoundary,{FallbackComponent:R.ErrorView,resetKeys:[e],children:t.jsx(Tt,{value:o})})})}):null}function Tt({value:e}){var h,P,y;const{t:s}=_.useLocaleContext(),{localState:{currentLocale:l,customComponentPreviewerProperties:o},state:{config:{defaultLocale:p}},localActions:{setCustomComponentPreviewerProperties:b}}=R.useStore(),d=Y.getYjsValue(e).doc,g=R.useAllComponents(),v=Pe.useReactive({propertiesValue:{...b}});return C.useEffect(()=>{const i=Object.fromEntries(Object.values(e.properties??{}).map(({data:n})=>{var a,u,x,S,c;return[n.id,{value:((a=v.propertiesValue[n.id])==null?void 0:a.value)??Le.parsePropertyValue(n,((x=(u=n.locales)==null?void 0:u[l])==null?void 0:x.defaultValue)??((c=(S=n.locales)==null?void 0:S[p])==null?void 0:c.defaultValue),{locale:l,defaultLocale:p})}]}));b(i)},[JSON.stringify(v.propertiesValue)]),t.jsx(r.Stack,{height:"100%",children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(Oe,{config:e}),t.jsx(Be,{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:((h=e.renderer)==null?void 0:h.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(zt,{value:e}),((y=e.renderer)==null?void 0:y.type)==="react-component"&&t.jsx(Et,{value:e}),t.jsx(ce,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,propertiesValue:o,onChange:({value:i,id:n,path:a})=>{const u=[...a,"data"];if(!ut.default(e,u)){le.default.warning(s("cannotFindPropertyKey",{key:u.join(".")}));return}v.propertiesValue[n]={value:i.value}}})]})})}function Oe({config:e}){const{t:s}=_.useLocaleContext();return t.jsx(F.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(It,{label:s("previewImage"),value:e.previewImage||"",onChange:l=>e.previewImage=l})]})})}function Te({data:e,params:s,visible:l,config:o,currentLocale:p,defaultLocale:b,allComponents:d,onUpdateConfig:g}){var P,y,i,n,a,u;const{t:v}=_.useLocaleContext(),h=C.useMemo(()=>e.type==="json"||e.type==="yaml"||e.type==="array"?Dt:U,[e.type]);return t.jsx(wt,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{g(x=>{if(x.properties){const c=Object.entries(x.properties).sort(([,f],[,k])=>f.index-k.index);delete x.properties[e.id],c.filter(([f])=>f!==e.id).forEach(([,f],k)=>{f.index=k})}})},visible:l,onVisibilityChange:x=>{g(S=>{const c=S.properties[e.id].data;c.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 c=S.properties[e.id].data;c.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[b])==null?void 0:n.name))||"",onChange:x=>{g(S=>{var j;const c=S.properties[e.id].data;c.locales??(c.locales={}),(j=c.locales)[p]??(j[p]={}),c.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 c=S.properties[e.id].data;if(c.locales)for(const f of Object.keys(c.locales))c.locales[f].defaultValue=void 0;const j=x.target.value;j==="multiline"?(c.type="string",c.multiline=!0):(typeof c.multiline<"u"&&delete c.multiline,c.type=j)})},children:Ct.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(h,{allComponents:d,defaultLocale:b,component:o,property:e,label:v("defaultValue"),size:"small",fullWidth:!0,value:(u=(a=e.locales)==null?void 0:a[p])==null?void 0:u.defaultValue,onChange:(x,S)=>{g(c=>{var f;const j=c.properties[e.id].data;if(S!=null&&S.forceUpdateProperty){const k=oe(j),I=oe(x);Object.keys(I).forEach(m=>{k[m]||Ie.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(Rt,{property:e,allComponents:d})}):null]})]})})}function Bt(e,s){const[l,o]=C.useState(0);return C.useEffect(()=>{const b=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(b)},[e,s]),l}function Be({config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p,useI18nEditor:b=!0}){const{t:d}=_.useLocaleContext(),g=z.usePopupState({variant:"dialog"}),v=e.properties&&V.default(Object.values(e.properties),"index");return t.jsx(F.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}),b&&t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...z.bindTrigger(g),children:t.jsx(D.TranslateRounded,{fontSize:"small"})})]}),e.properties&&Object.keys(e.properties).length>0?t.jsx(Ce,{component:r.Stack,gap:2,list:e.properties,renderItem:(h,P,y)=>{const i=ie(e.properties,h.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(Te,{data:h,params:y,visible:i,config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p})})},h.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(h=>{var y;const P=R.nextId();h.properties??(h.properties={}),(y=h.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")})}),b&&t.jsx(Re,{...z.bindDialog(g),component:e})]})})}function Rt({property:e,allComponents:s}){const l=z.usePopupState({variant:"popper"});return t.jsxs(t.Fragment,{children:[t.jsx(r.Button,{sx:{minWidth:0},...z.bindTrigger(l),children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Popper,{...z.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 _t({value:e,valueImmutable:s,onChange:l,defaultLocale:o,allComponents:p}){var P;const[b,d]=C.useState(!1),{t:g,locale:v}=_.useLocaleContext(),h=typeof(e==null?void 0:e.componentId)=="string"?(P=p[e.componentId])==null?void 0:P.data:void 0;return h?t.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[t.jsx(r.IconButton,{sx:{minWidth:0},disabled:!h,size:"small",onClick:()=>d(!b),color:b?"primary":"default",children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Collapse,{in:b,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:h,currentLocale:v,defaultLocale:o,allComponents:p,propertiesValue:e==null?void 0:e.properties,onChange:({id:y,value:i})=>{const n=ct.default(i.value),a=JSON.parse(JSON.stringify(e));s?l==null||l({...a,properties:{...a.properties,[y]:{value:n}}}):(a.properties=a.properties??{},a.properties[y]={value:n},l==null||l(a))}})}),t.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:g("close")})]})})]}):null}function Re({type:e="properties",component:s,...l}){var y,i,n;const{t:o}=_.useLocaleContext(),{state:{components:p,supportedLocales:b,config:{defaultLocale:d}}}=R.useStore(),g=R.useAllComponents(),v=Y.getYjsValue(s).doc,h=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:h&&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:b.map(({locale:a,name:u})=>t.jsxs(r.TableCell,{children:[u,d===a&&t.jsx(D.StarRounded,{sx:{fontSize:12,color:"text.secondary"}})]},a))})}),t.jsx(r.TableBody,{children:V.default(Object.values(h),"index").map(({data:a})=>t.jsx(r.TableRow,{children:b.map(({locale:u})=>{var x,S,c,j,f,k,I,m,w,O,T,E,N,A,$,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:a.key||"",onChange:M=>{v.transact(()=>{a.key=M.target.value.trim()})}}),t.jsx(r.TextField,{size:"small",label:o("label"),value:(((S=(x=a.locales)==null?void 0:x[u])==null?void 0:S.name)??((j=(c=a.locales)==null?void 0:c[d])==null?void 0:j.name))||"",onChange:M=>{v.transact(()=>{var q;a.locales??(a.locales={}),(q=a.locales)[u]??(q[u]={}),a.locales[u].name=M.target.value})}}),t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:a,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:X.default((k=(f=a.locales)==null?void 0:f[u])==null?void 0:k.defaultValue),value:((m=(I=a.locales)==null?void 0:I[u])==null?void 0:m.defaultValue)??((O=(w=a.locales)==null?void 0:w[d])==null?void 0:O.defaultValue),onChange:M=>{v.transact(()=>{var q;a.locales??(a.locales={}),(q=a.locales)[u]??(q[u]={}),a.locales[u].defaultValue=M})}})})]}):e==="parameters"&&P?t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:a,size:"small",fullWidth:!0,valueImmutable:X.default((A=(N=(E=(T=P.renderer.properties)==null?void 0:T[a.id])==null?void 0:E.locales)==null?void 0:N[u])==null?void 0:A.value),value:((L=(K=(W=($=P.renderer.properties)==null?void 0:$[a.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[a.id])==null?void 0:H.locales)==null?void 0:ae[d])==null?void 0:ue.value)??((pe=(de=a.locales)==null?void 0:de[u])==null?void 0:pe.defaultValue)??((xe=(me=a.locales)==null?void 0:me[d])==null?void 0:xe.defaultValue),onChange:M=>{v.transact(()=>{var q,fe,je,be,he;(q=P.renderer).properties??(q.properties={}),(fe=P.renderer.properties)[je=a.id]??(fe[je]={}),(be=P.renderer.properties[a.id]).locales??(be.locales={}),(he=P.renderer.properties[a.id].locales)[u]??(he[u]={}),P.renderer.properties[a.id].locales[u].value=M})}})}):null},a.id)},u)})},a.id))})]})})}),t.jsx(r.DialogActions,{children:t.jsx(r.Button,{onClick:a=>{var u;return(u=l.onClose)==null?void 0:u.call(l,a,"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),b=o[p],d=ye.alpha(b,.5),g=ye.alpha(b,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:g,...s}};function Dt({property:e,onChange:s,defaultLocale:l,allComponents:o}){const{t:p,locale:b}=_.useLocaleContext(),d=C.useRef(null),g=Bt(d,e),v=C.useCallback(()=>{if(!(e.type!=="json"&&e.type!=="yaml"&&e.type!=="array")&&e.subProperties)try{const h={};V.default(Object.values(e.subProperties),"index").filter(i=>i.data.visible!==!1&&i.data.key).forEach(({data:i})=>{var a,u,x,S;if(!i.key)return;let n=((u=(a=i.locales)==null?void 0:a[b])==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=se.parse(n)}catch(c){console.error("Error parsing nested value",n,c),n={}}h[i.key]=n});const y=R.transformValue(h,e.type);s==null||s(y)}catch(h){console.error("Error converting structure to text:",h)}},[e,b,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(Ce,{component:r.Stack,gap:2,list:e.subProperties,renderItem:(h,P,y)=>{const i=h.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(Te,{data:h,params:y,visible:i,config:{properties:e.subProperties},currentLocale:b,defaultLocale:l,allComponents:o,onUpdateConfig:n=>{try{const a={properties:e.subProperties||{}};n(a);const u={...e,subProperties:a.properties};s==null||s(u,{forceUpdateProperty:!0}),v()}catch(a){console.error("Error updating property:",a)}}})})},h.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 h=e.subProperties||{},P=R.nextId(),i={index:Object.values(h).length,data:{id:P,key:"",type:"string",visible:!0,locales:{[b]:{name:"",defaultValue:""}},subProperties:{}}},n={...e,subProperties:{...h,[P]:i}};s==null||s(n,{forceUpdateProperty:!0}),v()}catch(h){console.error("Error adding property:",h)}},sx:{"&":ve(g,{})},children:p("maker.properties.addSubProperty")})]})}function U({component:e,property:s,value:l,onChange:o,valueImmutable:p,defaultLocale:b,allComponents:d,...g}){var n,a,u,x,S;const{locale:v}=_.useLocaleContext(),h=F.useUploader(),P=C.useRef(null),y=()=>{var j;const c=(j=h==null?void 0:h.current)==null?void 0:j.getUploader();c==null||c.open(),P.current&&c.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??(((a=(n=s.locales)==null?void 0:n[v])==null?void 0:a.name)||((x=(u=s.locales)==null?void 0:u[b])==null?void 0:x.name)||s.key||s.id);if(s.type==="number")return t.jsx(Vt,{...g,label:i,NumberProps:{value:["number","string"].includes(typeof l)?l:null,onChange:(c,j)=>o==null?void 0:o(j)}});if(s.type==="decimal")return t.jsx(r.TextField,{...g,label:i,type:"text",value:l??"",onChange:c=>{const j=c.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:(c,j)=>o==null?void 0:o(j)})});if(s.type==="color")return t.jsx(vt,{label:i,value:l,onChange:c=>{o==null||o(c)}});if(s.type==="json"||s.type==="yaml")return t.jsx(kt,{label:i,value:l,onChange:c=>{o==null||o(c)},property:s,component:e,defaultLocale:b,allComponents:d,PropertyValueField:U,onUpload:c=>{P.current=c,y()}});if(s.type==="custom"){const c=(S=d[s.componentId])==null?void 0:S.data;return c?t.jsx(r.Box,{width:"100%",children:t.jsx(Q.CustomComponentRenderer,{componentId:c.id,props:{label:i,value:l,onChange:o},locale:v,dev:{mode:"draft",components:d,defaultLocale:b}})}):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:(c,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(_t,{value:l,valueImmutable:p,onChange:o,defaultLocale:b,allComponents:d})]});if(!s.type||["string","url","multiline"].includes(s.type)){let c=s.type==="string"?s.multiline:void 0;s.type==="multiline"&&(c=!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:c,minRows:c?2:void 0,maxRows:c?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(F.UploaderButton,{onChange:async({response:f})=>{var w,O,T;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 F.getImageSize(k).catch(()=>F.getVideoSize(k)).catch(()=>{}));let m=((T=f==null?void 0:f.data)==null?void 0:T.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(gt,{label:i,value:Array.isArray(l)?l:[],onChange:c=>o==null?void 0:o(c),property:s,renderItem:({item:c,index:j,onChange:f})=>s.subProperties&&Object.keys(s.subProperties).length>0?t.jsx(r.Stack,{gap:1,width:"100%",children:V.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:c[k.key],onChange:I=>{const m={...c,[k.key]:I};f(m)},size:"small",fullWidth:!0,defaultLocale:b,allComponents:d},k.id):null)},j):t.jsx(r.TextField,{size:g.size,fullWidth:!0,value:c,onChange:k=>f(k.target.value)})}):(console.error("Unsupported property type",s.type),null)}function Vt({NumberProps:e,...s}){const{getInputProps:l}=Se.unstable_useNumberInput(e),o=l();return t.jsx(r.TextField,{...s,inputProps:o})}const _e=`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-BoXTl4DM.js"),Ve=require("@arcblock/ux/lib/Empty"),_=require("@arcblock/ux/lib/Locale/context"),ne=require("@blocklet/code-editor"),Ee=require("@mui/icons-material/AddRounded"),ze=require("@mui/icons-material/ArrowDownward"),Ne=require("@mui/icons-material/ArrowUpward"),Ae=require("@mui/icons-material/DeleteOutline"),r=require("@mui/material"),qe=require("lodash/sortBy"),C=require("react"),ke=require("react-use"),te=require("./chunks/config-color-Da8lKUL0.js"),Fe=require("lodash/isEmpty"),Ue=require("lodash/set"),Me=require("yaml"),F=require("./uploader.js"),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"),ye=require("@mui/material/styles"),Y=require("@syncedstore/core"),Pe=require("ahooks"),Je=require("lodash/assign"),He=require("lodash/get"),Ye=require("lodash/has"),$e=require("lodash/isNil"),Ge=require("lodash/isObject"),Qe=require("lodash/keyBy"),Xe=require("lodash/omit"),Ze=require("lodash/pick"),et=require("lodash/reduce"),z=require("material-ui-popup-state/hooks"),tt=require("react-error-boundary"),rt=require("@emotion/css"),re=require("react-dnd"),B=e=>e&&e.__esModule?e:{default:e};function st(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=B(Ve),lt=B(Ee),ot=B(ze),it=B(Ne),nt=B(Ae),V=B(qe),we=B(Fe),Ie=B(Ue),se=st(Me),ct=B(We),le=B(Ke),at=B(Je),ut=B(He),dt=B(Ye),X=B($e),pt=B(Ge),mt=B(Qe),xt=B(Xe),ft=B(Ze),jt=B(et);function bt({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(nt.default,{fontSize:"small"})})}function ht({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 yt({onClick:e,disabled:s,sx:l,...o}){return t.jsx(r.IconButton,{size:"small",color:"primary",disabled:s,onClick:e,...o,children:t.jsx(ot.default,{fontSize:"small"})})}function gt({label:e,value:s,onChange:l,disabled:o=!1,itemLabel:p="",emptyHeight:b=40,property:d,renderItem:g,...v}){const{t:h,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]),a=C.useCallback(()=>{const m=[...n,""];i(m),y()},[n,i,y]),u=C.useCallback(()=>{if(!d||!d.subProperties)return a();const m={};V.default(Object.values(d.subProperties),"index").forEach(({data:T})=>{var N,A;if(!T.key)return;const E=((A=(N=T.locales)==null?void 0:N[P])==null?void 0:A.defaultValue)??"";m[T.key]=E});const O=[...n,m];i(O),y()},[n,i,y,d,P,a]),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,T)=>T!==m);i(w),y()},[n,i,y]),c=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||`${h("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(ht,{disabled:o||m===0,onClick:()=>c(m)}),t.jsx(yt,{disabled:o||m===n.length-1,onClick:()=>j(m)}),t.jsx(bt,{disabled:o,onClick:()=>S(m)})]})}],[g,k,d,f,p,h,o,v,S,c,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(T=>t.jsx(r.TableCell,{width:T.width,align:T.align||"left",sx:{borderBottom:"none"},children:T.renderCell({row:m,index:w,onChange:E=>f(w,E)})},`${w}-${T.field}`))},w))})]})}):t.jsx(Z.default,{style:{fontSize:12,height:b},children:h("maker.properties.arrayEmpty")}),t.jsx(r.Button,{fullWidth:!0,size:"small",variant:"outlined",disabled:o,startIcon:t.jsx(lt.default,{}),onClick:u,children:h("maker.properties.addArrayItem")})]}):t.jsxs(r.Stack,{width:"100%",gap:1,children:[e&&t.jsx(r.FormLabel,{children:e}),t.jsx(r.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,minHeight:150},children:t.jsx(ne.CodeEditor,{keyId: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 vt({value:e,onChange:s,...l}){const o=C.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsx(te.ConfigString,{...l,value:e,onChange:s,InputProps:{endAdornment:t.jsx(r.InputAdornment,{position:"end",children:t.jsx(te.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(te.ConfigColorDialog,{ref:o,onSave:({value:p},b)=>{s(p),b()}})]})}function kt({label:e,value:s,onChange:l,property:o,component:p,defaultLocale:b,allComponents:d,PropertyValueField:g,onUpload:v}){const{locale:h}=_.useLocaleContext(),P=C.useRef(null);if(!we.default(o.subProperties)){const i=V.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,a)=>{const{data:u}=n,x=u.key??u.id,S=a===i.length-1;let c=null;try{s&&typeof s=="object"?c=s[x]:typeof s=="string"&&(c=(o.type==="yaml"?se.parse(s||""):JSON.parse(s||"{}"))[x])}catch{}c==null&&(u.locales&&h&&u.locales[h]?c=u.locales[h].defaultValue:u.locales&&b&&u.locales[b]&&(c=u.locales[b].defaultValue));const j=k=>{try{let I={};if(typeof s=="string")try{I=o.type==="yaml"?se.parse(s||""):JSON.parse(s||"{}")}catch{}else typeof s=="object"&&s!==null&&(I={...s});Ie.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:c,onChange:j,size:"small",fullWidth:!0,defaultLocale:b,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(ne.CodeEditor,{keyId:o.id,locale:h,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 St=["string","multiline","json","yaml","url","component","custom"];function ge(e){return e.type?!St.includes(e.type):!1}function Ce({disabled:e,list:s,renderItem:l,...o}){const p=C.useRef(null),b=C.useId(),d=Pe.useUpdate(),g=V.default(Object.entries(s),n=>n[1].index).map(n=>n[0]),v=C.useRef(g),h=C.useCallback(n=>{v.current=n,d()},[d]),P=C.useCallback(({index:n},{index:a})=>{const u=[...v.current];u.splice(a,0,...u.splice(n,1)),h(u)},[h]);C.useEffect(()=>{h(g)},[g.join("-")]);const[{isOver:y},i]=re.useDrop({accept:b,collect:n=>({isOver:n.isOver()}),canDrop:()=>!e,drop:()=>{var u;const n=()=>{v.current.forEach((x,S)=>{const c=s[x];c&&(c.index=S)})},a=(u=Y.getYjsValue(s))==null?void 0:u.doc;a?a.transact(()=>{n()}):n()}});return C.useEffect(()=>{y||h(g)},[y]),i(p),t.jsx(r.Box,{...o,ref:p,className:rt.cx(y&&"isDragging"),children:v.current.map((n,a)=>t.jsx(Pt,{type:b,disabled:e,id:n,index:a,itemIndex:u=>v.current.indexOf(u),move:P,children:u=>{const x=s[n];return x?l(x.data,a,u):null}},n))})}function Pt({disabled:e,id:s,index:l,type:o,children:p,itemIndex:b,move:d}){const g=C.useRef(),[{isDragging:v},h,P]=re.useDrag({type:o,item:()=>({id:s}),canDrag:()=>!e,collect:i=>({isDragging:i.isDragging()})}),[,y]=re.useDrop({accept:o,canDrop:()=>!e,hover(i,n){var f;if(!g.current)return;const a=b(i.id),u=l;if(a===u)return;const x=(f=g.current)==null?void 0:f.getBoundingClientRect(),S=(x.bottom-x.top)/2,j=n.getClientOffset().y-x.top;a<u&&j<S||a>u&&j>S||d({id:i.id,index:a},{id:s,index:l})}});return typeof p=="function"?p({isDragging:v,drag:h,drop:i=>(g.current=i,y(i)),preview:P}):(h(y(P(g))),t.jsx(r.Box,{ref:g,children:p}))}function wt({drop:e,preview:s,drag:l,disabled:o,isDragging:p,children:b,onDelete:d,onVisibilityChange:g,visible:v=!0,actions:h,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:b}),!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:[h,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 It({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:b=>l==null?void 0:l(b.target.value),InputProps:{endAdornment:t.jsx(F.UploaderButton,{onChange:({response:b})=>{var g;const d=(g=b==null?void 0:b.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 oe(e,s=""){return jt.default(e,(l,o,p)=>{const b=s?`${s}.${p}`:p;return pt.default(o)?at.default(l,oe(o,b)):l[b]=o,l},{})}const Ct=[{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 ie(e,s){var l;return!e||!s?!1:((l=e[s])==null?void 0:l.data.visible)??!0}function Ot({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(tt.ErrorBoundary,{FallbackComponent:R.ErrorView,resetKeys:[e],children:t.jsx(Tt,{value:o})})})}):null}function Tt({value:e}){var h,P,y;const{t:s}=_.useLocaleContext(),{localState:{currentLocale:l,customComponentPreviewerProperties:o},state:{config:{defaultLocale:p}},localActions:{setCustomComponentPreviewerProperties:b}}=R.useStore(),d=Y.getYjsValue(e).doc,g=R.useAllComponents(),v=Pe.useReactive({propertiesValue:{...b}});return C.useEffect(()=>{const i=Object.fromEntries(Object.values(e.properties??{}).map(({data:n})=>{var a,u,x,S,c;return[n.id,{value:((a=v.propertiesValue[n.id])==null?void 0:a.value)??Le.parsePropertyValue(n,((x=(u=n.locales)==null?void 0:u[l])==null?void 0:x.defaultValue)??((c=(S=n.locales)==null?void 0:S[p])==null?void 0:c.defaultValue),{locale:l,defaultLocale:p})}]}));b(i)},[JSON.stringify(v.propertiesValue)]),t.jsx(r.Stack,{height:"100%",children:t.jsxs(r.Stack,{gap:2,children:[t.jsx(Oe,{config:e}),t.jsx(Be,{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:((h=e.renderer)==null?void 0:h.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(zt,{value:e}),((y=e.renderer)==null?void 0:y.type)==="react-component"&&t.jsx(Et,{value:e}),t.jsx(ce,{config:e,currentLocale:l,defaultLocale:p,allComponents:g,propertiesValue:o,onChange:({value:i,id:n,path:a})=>{const u=[...a,"data"];if(!ut.default(e,u)){le.default.warning(s("cannotFindPropertyKey",{key:u.join(".")}));return}v.propertiesValue[n]={value:i.value}}})]})})}function Oe({config:e}){const{t:s}=_.useLocaleContext();return t.jsx(F.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(It,{label:s("previewImage"),value:e.previewImage||"",onChange:l=>e.previewImage=l})]})})}function Te({data:e,params:s,visible:l,config:o,currentLocale:p,defaultLocale:b,allComponents:d,onUpdateConfig:g}){var P,y,i,n,a,u;const{t:v}=_.useLocaleContext(),h=C.useMemo(()=>e.type==="json"||e.type==="yaml"||e.type==="array"?Dt:U,[e.type]);return t.jsx(wt,{preview:s.preview,drop:s.drop,drag:s.drag,isDragging:s.isDragging,onDelete:()=>{g(x=>{if(x.properties){const c=Object.entries(x.properties).sort(([,f],[,k])=>f.index-k.index);delete x.properties[e.id],c.filter(([f])=>f!==e.id).forEach(([,f],k)=>{f.index=k})}})},visible:l,onVisibilityChange:x=>{g(S=>{const c=S.properties[e.id].data;c.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 c=S.properties[e.id].data;c.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[b])==null?void 0:n.name))||"",onChange:x=>{g(S=>{var j;const c=S.properties[e.id].data;c.locales??(c.locales={}),(j=c.locales)[p]??(j[p]={}),c.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 c=S.properties[e.id].data;if(c.locales)for(const f of Object.keys(c.locales))c.locales[f].defaultValue=void 0;const j=x.target.value;j==="multiline"?(c.type="string",c.multiline=!0):(typeof c.multiline<"u"&&delete c.multiline,c.type=j)})},children:Ct.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(h,{allComponents:d,defaultLocale:b,component:o,property:e,label:v("defaultValue"),size:"small",fullWidth:!0,value:(u=(a=e.locales)==null?void 0:a[p])==null?void 0:u.defaultValue,onChange:(x,S)=>{g(c=>{var f;const j=c.properties[e.id].data;if(S!=null&&S.forceUpdateProperty){const k=oe(j),I=oe(x);Object.keys(I).forEach(m=>{k[m]||Ie.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(Rt,{property:e,allComponents:d})}):null]})]})})}function Bt(e,s){const[l,o]=C.useState(0);return C.useEffect(()=>{const b=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(b)},[e,s]),l}function Be({config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p,useI18nEditor:b=!0}){const{t:d}=_.useLocaleContext(),g=z.usePopupState({variant:"dialog"}),v=e.properties&&V.default(Object.values(e.properties),"index");return t.jsx(F.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}),b&&t.jsx(r.Button,{sx:{minWidth:32,minHeight:32,p:0},...z.bindTrigger(g),children:t.jsx(D.TranslateRounded,{fontSize:"small"})})]}),e.properties&&Object.keys(e.properties).length>0?t.jsx(Ce,{component:r.Stack,gap:2,list:e.properties,renderItem:(h,P,y)=>{const i=ie(e.properties,h.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(Te,{data:h,params:y,visible:i,config:e,currentLocale:s,defaultLocale:l,allComponents:o,onUpdateConfig:p})})},h.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(h=>{var y;const P=R.nextId();h.properties??(h.properties={}),(y=h.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")})}),b&&t.jsx(Re,{...z.bindDialog(g),component:e})]})})}function Rt({property:e,allComponents:s}){const l=z.usePopupState({variant:"popper"});return t.jsxs(t.Fragment,{children:[t.jsx(r.Button,{sx:{minWidth:0},...z.bindTrigger(l),children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Popper,{...z.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 _t({value:e,valueImmutable:s,onChange:l,defaultLocale:o,allComponents:p}){var P;const[b,d]=C.useState(!1),{t:g,locale:v}=_.useLocaleContext(),h=typeof(e==null?void 0:e.componentId)=="string"?(P=p[e.componentId])==null?void 0:P.data:void 0;return h?t.jsxs(r.Box,{sx:{width:"100%",position:"relative"},children:[t.jsx(r.IconButton,{sx:{minWidth:0},disabled:!h,size:"small",onClick:()=>d(!b),color:b?"primary":"default",children:t.jsx(D.SettingsRounded,{fontSize:"small"})}),t.jsx(r.Collapse,{in:b,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:h,currentLocale:v,defaultLocale:o,allComponents:p,propertiesValue:e==null?void 0:e.properties,onChange:({id:y,value:i})=>{const n=ct.default(i.value),a=JSON.parse(JSON.stringify(e));s?l==null||l({...a,properties:{...a.properties,[y]:{value:n}}}):(a.properties=a.properties??{},a.properties[y]={value:n},l==null||l(a))}})}),t.jsx(r.Button,{size:"small",onClick:()=>d(!1),sx:{mt:1},children:g("close")})]})})]}):null}function Re({type:e="properties",component:s,...l}){var y,i,n;const{t:o}=_.useLocaleContext(),{state:{components:p,supportedLocales:b,config:{defaultLocale:d}}}=R.useStore(),g=R.useAllComponents(),v=Y.getYjsValue(s).doc,h=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:h&&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:b.map(({locale:a,name:u})=>t.jsxs(r.TableCell,{children:[u,d===a&&t.jsx(D.StarRounded,{sx:{fontSize:12,color:"text.secondary"}})]},a))})}),t.jsx(r.TableBody,{children:V.default(Object.values(h),"index").map(({data:a})=>t.jsx(r.TableRow,{children:b.map(({locale:u})=>{var x,S,c,j,f,k,I,m,w,O,T,E,N,A,$,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:a.key||"",onChange:M=>{v.transact(()=>{a.key=M.target.value.trim()})}}),t.jsx(r.TextField,{size:"small",label:o("label"),value:(((S=(x=a.locales)==null?void 0:x[u])==null?void 0:S.name)??((j=(c=a.locales)==null?void 0:c[d])==null?void 0:j.name))||"",onChange:M=>{v.transact(()=>{var q;a.locales??(a.locales={}),(q=a.locales)[u]??(q[u]={}),a.locales[u].name=M.target.value})}}),t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:a,size:"small",fullWidth:!0,label:"Default Value",valueImmutable:X.default((k=(f=a.locales)==null?void 0:f[u])==null?void 0:k.defaultValue),value:((m=(I=a.locales)==null?void 0:I[u])==null?void 0:m.defaultValue)??((O=(w=a.locales)==null?void 0:w[d])==null?void 0:O.defaultValue),onChange:M=>{v.transact(()=>{var q;a.locales??(a.locales={}),(q=a.locales)[u]??(q[u]={}),a.locales[u].defaultValue=M})}})})]}):e==="parameters"&&P?t.jsx(r.Box,{children:t.jsx(U,{allComponents:g,defaultLocale:d,component:s,property:a,size:"small",fullWidth:!0,valueImmutable:X.default((A=(N=(E=(T=P.renderer.properties)==null?void 0:T[a.id])==null?void 0:E.locales)==null?void 0:N[u])==null?void 0:A.value),value:((L=(K=(W=($=P.renderer.properties)==null?void 0:$[a.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[a.id])==null?void 0:H.locales)==null?void 0:ae[d])==null?void 0:ue.value)??((pe=(de=a.locales)==null?void 0:de[u])==null?void 0:pe.defaultValue)??((xe=(me=a.locales)==null?void 0:me[d])==null?void 0:xe.defaultValue),onChange:M=>{v.transact(()=>{var q,fe,je,be,he;(q=P.renderer).properties??(q.properties={}),(fe=P.renderer.properties)[je=a.id]??(fe[je]={}),(be=P.renderer.properties[a.id]).locales??(be.locales={}),(he=P.renderer.properties[a.id].locales)[u]??(he[u]={}),P.renderer.properties[a.id].locales[u].value=M})}})}):null},a.id)},u)})},a.id))})]})})}),t.jsx(r.DialogActions,{children:t.jsx(r.Button,{onClick:a=>{var u;return(u=l.onClose)==null?void 0:u.call(l,a,"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),b=o[p],d=ye.alpha(b,.5),g=ye.alpha(b,1);return{borderColor:`${d} !important`,borderLeft:"3px solid !important",borderLeftColor:d,color:g,...s}};function Dt({property:e,onChange:s,defaultLocale:l,allComponents:o}){const{t:p,locale:b}=_.useLocaleContext(),d=C.useRef(null),g=Bt(d,e),v=C.useCallback(()=>{if(!(e.type!=="json"&&e.type!=="yaml"&&e.type!=="array")&&e.subProperties)try{const h={};V.default(Object.values(e.subProperties),"index").filter(i=>i.data.visible!==!1&&i.data.key).forEach(({data:i})=>{var a,u,x,S;if(!i.key)return;let n=((u=(a=i.locales)==null?void 0:a[b])==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=se.parse(n)}catch(c){console.error("Error parsing nested value",n,c),n={}}h[i.key]=n});const y=R.transformValue(h,e.type);s==null||s(y)}catch(h){console.error("Error converting structure to text:",h)}},[e,b,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(Ce,{component:r.Stack,gap:2,list:e.subProperties,renderItem:(h,P,y)=>{const i=h.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(Te,{data:h,params:y,visible:i,config:{properties:e.subProperties},currentLocale:b,defaultLocale:l,allComponents:o,onUpdateConfig:n=>{try{const a={properties:e.subProperties||{}};n(a);const u={...e,subProperties:a.properties};s==null||s(u,{forceUpdateProperty:!0}),v()}catch(a){console.error("Error updating property:",a)}}})})},h.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 h=e.subProperties||{},P=R.nextId(),i={index:Object.values(h).length,data:{id:P,key:"",type:"string",visible:!0,locales:{[b]:{name:"",defaultValue:""}},subProperties:{}}},n={...e,subProperties:{...h,[P]:i}};s==null||s(n,{forceUpdateProperty:!0}),v()}catch(h){console.error("Error adding property:",h)}},sx:{"&":ve(g,{})},children:p("maker.properties.addSubProperty")})]})}function U({component:e,property:s,value:l,onChange:o,valueImmutable:p,defaultLocale:b,allComponents:d,...g}){var n,a,u,x,S;const{locale:v}=_.useLocaleContext(),h=F.useUploader(),P=C.useRef(null),y=()=>{var j;const c=(j=h==null?void 0:h.current)==null?void 0:j.getUploader();c==null||c.open(),P.current&&c.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??(((a=(n=s.locales)==null?void 0:n[v])==null?void 0:a.name)||((x=(u=s.locales)==null?void 0:u[b])==null?void 0:x.name)||s.key||s.id);if(s.type==="number")return t.jsx(Vt,{...g,label:i,NumberProps:{value:["number","string"].includes(typeof l)?l:null,onChange:(c,j)=>o==null?void 0:o(j)}});if(s.type==="decimal")return t.jsx(r.TextField,{...g,label:i,type:"text",value:l??"",onChange:c=>{const j=c.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:(c,j)=>o==null?void 0:o(j)})});if(s.type==="color")return t.jsx(vt,{label:i,value:l,onChange:c=>{o==null||o(c)}});if(s.type==="json"||s.type==="yaml")return t.jsx(kt,{label:i,value:l,onChange:c=>{o==null||o(c)},property:s,component:e,defaultLocale:b,allComponents:d,PropertyValueField:U,onUpload:c=>{P.current=c,y()}});if(s.type==="custom"){const c=(S=d[s.componentId])==null?void 0:S.data;return c?t.jsx(r.Box,{width:"100%",children:t.jsx(Q.CustomComponentRenderer,{componentId:c.id,props:{label:i,value:l,onChange:o},locale:v,dev:{mode:"draft",components:d,defaultLocale:b}})}):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:(c,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(_t,{value:l,valueImmutable:p,onChange:o,defaultLocale:b,allComponents:d})]});if(!s.type||["string","url","multiline"].includes(s.type)){let c=s.type==="string"?s.multiline:void 0;s.type==="multiline"&&(c=!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:c,minRows:c?2:void 0,maxRows:c?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(F.UploaderButton,{onChange:async({response:f})=>{var w,O,T;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 F.getImageSize(k).catch(()=>F.getVideoSize(k)).catch(()=>{}));let m=((T=f==null?void 0:f.data)==null?void 0:T.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(gt,{label:i,value:Array.isArray(l)?l:[],onChange:c=>o==null?void 0:o(c),property:s,renderItem:({item:c,index:j,onChange:f})=>s.subProperties&&Object.keys(s.subProperties).length>0?t.jsx(r.Stack,{gap:1,width:"100%",children:V.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:c[k.key],onChange:I=>{const m={...c,[k.key]:I};f(m)},size:"small",fullWidth:!0,defaultLocale:b,allComponents:d},k.id):null)},j):t.jsx(r.TextField,{size:g.size,fullWidth:!0,value:c,onChange:k=>f(k.target.value)})}):(console.error("Unsupported property type",s.type),null)}function Vt({NumberProps:e,...s}){const{getInputProps:l}=Se.unstable_useNumberInput(e),o=l();return t.jsx(r.TextField,{...s,inputProps:o})}const _e=`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 () {
|
package/lib/es/project-html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as y, b as H } from "./chunks/site-state-Bn8mEgOx.js";
|
|
2
2
|
import { initCronCrawlBlocklet as W, cancelCronCrawlBlocklet as N, initSEOMiddleware as J } from "@blocklet/crawler/middlewares";
|
|
3
3
|
import { PreloadComponentScriptModule as G } from "@blocklet/pages-kit/types";
|
|
4
4
|
import { injectPreloadComponents as K } from "@blocklet/pages-kit/utils/preload";
|
|
@@ -11,15 +11,15 @@ import X from "mustache";
|
|
|
11
11
|
import { resolve as j } from "path";
|
|
12
12
|
import { withQuery as Y, joinURL as U } from "ufo";
|
|
13
13
|
const Z = ["/assets/"], M = () => [!0, "true"].includes(a.env.preferences.allowCrawler);
|
|
14
|
-
function
|
|
14
|
+
function x() {
|
|
15
15
|
M() ? W({
|
|
16
16
|
time: "0 0 */12 * * *",
|
|
17
17
|
options: {}
|
|
18
18
|
}) : N();
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
a.events.on(a.Events.envUpdate,
|
|
22
|
-
function
|
|
20
|
+
x();
|
|
21
|
+
a.events.on(a.Events.envUpdate, x);
|
|
22
|
+
function de({
|
|
23
23
|
app: c,
|
|
24
24
|
viteDevServer: h,
|
|
25
25
|
// projectId,
|
|
@@ -27,95 +27,102 @@ function me({
|
|
|
27
27
|
}) {
|
|
28
28
|
let C;
|
|
29
29
|
if (h) {
|
|
30
|
-
const
|
|
31
|
-
c.use(async (b,
|
|
32
|
-
const
|
|
33
|
-
C = await h.transformIndexHtml(
|
|
30
|
+
const o = I(j(process.cwd(), "./index.html"), "utf-8");
|
|
31
|
+
c.use(async (f, b, v) => {
|
|
32
|
+
const $ = f.originalUrl;
|
|
33
|
+
C = await h.transformIndexHtml($, o), v();
|
|
34
34
|
});
|
|
35
35
|
} else
|
|
36
36
|
C = I(j(process.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const _ = V();
|
|
38
|
+
_.use(
|
|
39
|
+
(o, f, b) => {
|
|
40
|
+
if (o.headers["x-unique-record"] === "dial_http") {
|
|
41
|
+
y.info("[html] dial http request, return 200 status code"), f.status(200).send("ok");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
b();
|
|
45
|
+
},
|
|
39
46
|
J({
|
|
40
47
|
autoReturnHtml: !0,
|
|
41
48
|
allowCrawler: M
|
|
42
49
|
})
|
|
43
|
-
),
|
|
50
|
+
), _.get("/:path(*)?", async (o, f, b) => {
|
|
44
51
|
var T, E, S;
|
|
45
|
-
if (Z.some((
|
|
46
|
-
var
|
|
47
|
-
return (
|
|
52
|
+
if (Z.some((r) => {
|
|
53
|
+
var s;
|
|
54
|
+
return (s = o.path) == null ? void 0 : s.startsWith(r);
|
|
48
55
|
})) {
|
|
49
|
-
|
|
56
|
+
b();
|
|
50
57
|
return;
|
|
51
58
|
}
|
|
52
|
-
const
|
|
53
|
-
let e, p,
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
56
|
-
let
|
|
57
|
-
if ((!
|
|
59
|
+
const v = performance.now(), $ = () => Math.round(performance.now() - v), D = "production";
|
|
60
|
+
let e, p, g = C;
|
|
61
|
+
if (o.path.startsWith("/pages")) {
|
|
62
|
+
const r = o.params.lang, s = o.cookies.nf_lang, w = /* @__PURE__ */ new Set([...a.env.languages.map((u) => u.code)]);
|
|
63
|
+
let m = (r && w.has(r) ? r : void 0) || (w.has(s) ? s : void 0) || [...w][0];
|
|
64
|
+
if ((!m || !((T = n.supportedLocales) != null && T.find((u) => u.locale === m))) && (m = ((S = (E = n.supportedLocales) == null ? void 0 : E[0]) == null ? void 0 : S.locale) || ""), m) {
|
|
58
65
|
const u = [];
|
|
59
|
-
Object.values(n.pages).forEach((
|
|
60
|
-
const B = Object.values((
|
|
61
|
-
(
|
|
62
|
-
var
|
|
63
|
-
return
|
|
66
|
+
Object.values(n.pages).forEach((l) => {
|
|
67
|
+
const B = Object.values((l == null ? void 0 : l.sections) ?? {}).filter(
|
|
68
|
+
(i) => {
|
|
69
|
+
var k;
|
|
70
|
+
return i.component === "custom-component" && ((k = i.config) == null ? void 0 : k.componentId);
|
|
64
71
|
}
|
|
65
|
-
).map((
|
|
66
|
-
var
|
|
72
|
+
).map((i) => {
|
|
73
|
+
var k, L;
|
|
67
74
|
return {
|
|
68
|
-
id:
|
|
69
|
-
componentId:
|
|
70
|
-
useCache:
|
|
71
|
-
cacheDuration:
|
|
72
|
-
properties: (L = (
|
|
75
|
+
id: i.id,
|
|
76
|
+
componentId: i.config.componentId,
|
|
77
|
+
useCache: i.config.useCache,
|
|
78
|
+
cacheDuration: i.config.cacheDuration,
|
|
79
|
+
properties: (L = (k = i.locales) == null ? void 0 : k[m]) == null ? void 0 : L.properties
|
|
73
80
|
};
|
|
74
81
|
});
|
|
75
82
|
u.push(...B);
|
|
76
83
|
});
|
|
77
|
-
const
|
|
84
|
+
const R = new Promise((l) => {
|
|
78
85
|
setTimeout(() => {
|
|
79
|
-
|
|
86
|
+
l({});
|
|
80
87
|
}, 90 * 1e3);
|
|
81
88
|
});
|
|
82
89
|
try {
|
|
83
90
|
await Promise.race([
|
|
84
|
-
|
|
91
|
+
R,
|
|
85
92
|
H({
|
|
86
|
-
mode:
|
|
87
|
-
req:
|
|
93
|
+
mode: D,
|
|
94
|
+
req: o,
|
|
88
95
|
state: n,
|
|
89
|
-
locale:
|
|
96
|
+
locale: m,
|
|
90
97
|
instances: u,
|
|
91
98
|
module: G.UMD_FN
|
|
92
|
-
}).then((
|
|
93
|
-
|
|
99
|
+
}).then((l) => {
|
|
100
|
+
l && (p = K(l));
|
|
94
101
|
})
|
|
95
102
|
]);
|
|
96
|
-
} catch (
|
|
97
|
-
|
|
103
|
+
} catch (l) {
|
|
104
|
+
y.warn("getPreloadComponents timeout in promise race, skip inject html elements"), y.warn(l);
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
try {
|
|
102
|
-
const
|
|
103
|
-
title:
|
|
104
|
-
description:
|
|
109
|
+
const r = (e == null ? void 0 : e.title) || a.env.appName, s = (e == null ? void 0 : e.description) || a.env.appDescription, w = Y(U(a.env.appUrl, "/.well-known/service/blocklet/og.png"), {
|
|
110
|
+
title: r,
|
|
111
|
+
description: s
|
|
105
112
|
});
|
|
106
|
-
|
|
107
|
-
ogTitle:
|
|
108
|
-
ogDescription:
|
|
109
|
-
ogImage:
|
|
113
|
+
g = X.render(C, {
|
|
114
|
+
ogTitle: r,
|
|
115
|
+
ogDescription: s,
|
|
116
|
+
ogImage: q(e == null ? void 0 : e.image) || w,
|
|
110
117
|
pagesPublishedAt: (n == null ? void 0 : n.config.publishedAt) || (/* @__PURE__ */ new Date()).getTime()
|
|
111
118
|
});
|
|
112
119
|
} catch {
|
|
113
120
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
121
|
+
const t = n == null ? void 0 : n.config.fontFamily, O = o.query.mode === "draft" || o.url.includes("preview"), d = A.load(g);
|
|
122
|
+
d("head").find("#injected-head-elements").replaceWith(`
|
|
116
123
|
${e != null && e.backgroundColor ? `<meta name="theme-color" content="${e.backgroundColor}" /><style>html,body,#app {background-color: ${e.backgroundColor} !important;}</style>` : ""}
|
|
117
|
-
${
|
|
118
|
-
${
|
|
124
|
+
${t != null && t.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${t.title}&display=swap">` : ""}
|
|
125
|
+
${t != null && t.description && (t == null ? void 0 : t.description) !== (t == null ? void 0 : t.title) ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${t.description}&display=swap">` : ""}
|
|
119
126
|
<script>
|
|
120
127
|
|
|
121
128
|
window.__PAGE_STATE__ = ${JSON.stringify(n, null, 0)}
|
|
@@ -128,7 +135,7 @@ function me({
|
|
|
128
135
|
});
|
|
129
136
|
<\/script>
|
|
130
137
|
|
|
131
|
-
${
|
|
138
|
+
${O ? `<script src="https://cdn.tailwindcss.com"><\/script>
|
|
132
139
|
<script>
|
|
133
140
|
window.tailwind.config = {
|
|
134
141
|
darkMode: "class",
|
|
@@ -136,17 +143,17 @@ function me({
|
|
|
136
143
|
<\/script>` : ""}
|
|
137
144
|
`);
|
|
138
145
|
const P = z();
|
|
139
|
-
if (P &&
|
|
140
|
-
const
|
|
141
|
-
|
|
146
|
+
if (P && d('script[src="__blocklet__.js"]').replaceWith(`<script>${P}<\/script>`), p != null && p.html && d("head").find("#injected-html-elements").replaceWith(p.html), o.cachedHtml) {
|
|
147
|
+
const r = A.load(o.cachedHtml);
|
|
148
|
+
d("body").html(r("body").html() || "");
|
|
142
149
|
}
|
|
143
|
-
|
|
144
|
-
}), c.use(
|
|
150
|
+
g = d.html(), f.send(g), y.info(`[html] render: ${o.path}, ${$()}ms`), d.root().children().remove(), g = null, e = null, p = null;
|
|
151
|
+
}), c.use(_);
|
|
145
152
|
}
|
|
146
|
-
function
|
|
153
|
+
function q(c) {
|
|
147
154
|
const h = Q("image-bin");
|
|
148
155
|
return h && c && !/^(https?:\/\/|\/)/.test(c) ? a.env.appUrl + U(h, "uploads", c) : c;
|
|
149
156
|
}
|
|
150
157
|
export {
|
|
151
|
-
|
|
158
|
+
de as default
|
|
152
159
|
};
|
package/lib/es/setting.js
CHANGED
|
@@ -292,7 +292,7 @@ function rr({
|
|
|
292
292
|
onChange: (p) => m(p || ""),
|
|
293
293
|
fullScreenOptions: {
|
|
294
294
|
enableEscExit: !0,
|
|
295
|
-
targetContainer: document.getElementById("parameters-config-dialog") || null
|
|
295
|
+
targetContainer: () => document.getElementById("parameters-config-dialog") || null
|
|
296
296
|
}
|
|
297
297
|
},
|
|
298
298
|
a.id
|
|
@@ -508,7 +508,7 @@ function lr({
|
|
|
508
508
|
},
|
|
509
509
|
fullScreenOptions: {
|
|
510
510
|
enableEscExit: !0,
|
|
511
|
-
targetContainer: document.getElementById("parameters-config-dialog") || null
|
|
511
|
+
targetContainer: () => document.getElementById("parameters-config-dialog") || null
|
|
512
512
|
}
|
|
513
513
|
},
|
|
514
514
|
l.id
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit-inner-components",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.105",
|
|
4
4
|
"description": "Pages Kit inner components library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"import": "./lib/es/project-html.js",
|
|
53
53
|
"require": "./lib/cjs/project-html.js"
|
|
54
54
|
},
|
|
55
|
-
"./
|
|
56
|
-
"import": "./lib/es
|
|
57
|
-
"require": "./lib/cjs
|
|
55
|
+
"./lib/*": {
|
|
56
|
+
"import": "./lib/es/*.js",
|
|
57
|
+
"require": "./lib/cjs/*.js"
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"files": [
|
|
@@ -75,15 +75,15 @@
|
|
|
75
75
|
"@arcblock/react-hooks": "^2.12.58",
|
|
76
76
|
"@arcblock/ux": "^2.12.58",
|
|
77
77
|
"@blocklet/ai-kit": "^0.1.72",
|
|
78
|
-
"@blocklet/ai-runtime": "^0.4.
|
|
79
|
-
"@blocklet/code-editor": "^0.4.
|
|
80
|
-
"@blocklet/crawler": "^2.2.
|
|
78
|
+
"@blocklet/ai-runtime": "^0.4.256",
|
|
79
|
+
"@blocklet/code-editor": "^0.4.256",
|
|
80
|
+
"@blocklet/crawler": "^2.2.18",
|
|
81
81
|
"@blocklet/embed": "^0.2.3",
|
|
82
82
|
"@blocklet/js-sdk": "^1.16.41",
|
|
83
83
|
"@blocklet/logger": "1.16.36",
|
|
84
|
-
"@blocklet/quickjs": "^0.4.
|
|
84
|
+
"@blocklet/quickjs": "^0.4.256",
|
|
85
85
|
"@blocklet/sdk": "^1.16.41",
|
|
86
|
-
"@blocklet/studio-ui": "^0.4.
|
|
86
|
+
"@blocklet/studio-ui": "^0.4.256",
|
|
87
87
|
"@blocklet/tracker": "^1.16.41",
|
|
88
88
|
"@blocklet/ui-react": "^2.12.58",
|
|
89
89
|
"@blocklet/uploader": "^0.1.82",
|
|
@@ -205,8 +205,8 @@
|
|
|
205
205
|
"yaml": "^2.5.0",
|
|
206
206
|
"yjs": "^13.6.18",
|
|
207
207
|
"zustand": "^4.5.5",
|
|
208
|
-
"@blocklet/pages-kit": "^0.4.
|
|
209
|
-
"@blocklet/pages-kit-block-studio": "^0.4.
|
|
208
|
+
"@blocklet/pages-kit": "^0.4.105",
|
|
209
|
+
"@blocklet/pages-kit-block-studio": "^0.4.105"
|
|
210
210
|
},
|
|
211
211
|
"devDependencies": {
|
|
212
212
|
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
|