mirror of
https://gh.wpcy.net/https://github.com/lubusIN/visual-blueprint-builder.git
synced 2026-05-06 16:49:00 +08:00
1 line
No EOL
4 KiB
JavaScript
1 line
No EOL
4 KiB
JavaScript
(()=>{"use strict";const e=window.wp.element,t=window.wp.i18n,n=window.wp.blocks,i=window.wp.primitives,l=window.ReactJSXRuntime,r=(0,l.jsx)(i.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,l.jsx)(i.Path,{d:"M10 4.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm2.25 7.5v-1A2.75 2.75 0 0011 8.25H7A2.75 2.75 0 004.25 11v1h1.5v-1c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v1h1.5zM4 20h9v-1.5H4V20zm16-4H4v-1.5h16V16z",fillRule:"evenodd",clipRule:"evenodd"})}),s=(0,l.jsx)(i.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,l.jsx)(i.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})}),a=(0,l.jsx)(i.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,l.jsx)(i.Path,{d:"M11 12.5V17.5H12.5V12.5H17.5V11H12.5V6H11V11H6V12.5H11Z"})}),p=window.wp.blockEditor,o=window.wp.components,d=JSON.parse('{"UU":"playground-step/update-user-meta","DD":"Update User Meta"}');(0,n.registerBlockType)(d.UU,{icon:r,edit:function({attributes:n,setAttributes:i,isSelected:c}){const{meta:u,userId:x}=n,[_,w]=(0,e.useState)(!1),[h,m]=(0,e.useState)(Object.entries(u)),[g,j]=(0,e.useState)(void 0);(0,e.useEffect)((()=>{const e=h.filter((([e,t])=>""!==e.trim()&&""!==t.trim()));i({meta:Object.fromEntries(e)}),c||b()}),[h,c]);const v=(e,t,n)=>{const i=h.map((([i,l],r)=>r===e?"key"===t?[n,l]:[i,n]:[i,l]));m(i)},b=()=>{m(h.filter((([e,t])=>e.trim()&&t.trim()))),w(!1)},f=h.length>0&&(""===h[h.length-1][0]||""===h[h.length-1][1]);return(0,l.jsxs)("div",{...(0,p.useBlockProps)(),children:[(0,l.jsx)(o.Placeholder,{preview:(0,l.jsxs)(o.__experimentalVStack,{style:{width:"100%"},children:[(0,l.jsxs)(o.__experimentalHStack,{justify:"left",align:"center",spacing:3,children:[(0,l.jsx)(o.Icon,{icon:r,size:28,className:"step-icon"}),(0,l.jsxs)(o.__experimentalVStack,{spacing:1,children:[(0,l.jsx)(o.__experimentalText,{upperCase:!0,size:12,weight:500,color:"#949494",children:d.DD}),!c&&(0,l.jsxs)(o.__experimentalVStack,{children:[(0,l.jsx)(o.__experimentalText,{weight:600,children:u?(0,l.jsx)("pre",{style:{whiteSpace:"pre-wrap"},children:JSON.stringify(u,null," ")}):(0,l.jsx)("span",{children:(0,t.__)("{config user meta}","wp-playground-blueprint-editor")})}),(0,l.jsx)(o.__experimentalText,{weight:600,children:x?`${(0,t.__)("for UserId","wp-playground-blueprint-editor")} ${x}`:(0,t.__)("{user Id}","wp-playground-blueprint-editor")})]})]})]}),c&&(0,l.jsxs)(o.__experimentalVStack,{spacing:4,children:[h.map((([e,n],i)=>(0,l.jsxs)(o.__experimentalHStack,{justify:"space-between",alignment:"center",children:[(0,l.jsx)(o.__experimentalInputControl,{label:(0,t.__)("Name","wp-playground-blueprint-editor"),value:e,__next40pxDefaultSize:!0,__unstableInputWidth:"200px",onChange:e=>v(i,"key",e)}),(0,l.jsx)(o.__experimentalInputControl,{label:(0,t.__)("Value","wp-playground-blueprint-editor"),value:n,__next40pxDefaultSize:!0,__unstableInputWidth:"200px",onChange:e=>v(i,"value",e)}),(0,l.jsx)(o.Button,{isDestructive:!0,icon:s,label:(0,t.__)("Delete Config","wp-playground-blueprint-editor"),onClick:()=>{j(i),w(!0)},style:{width:"40px",marginTop:"24px"}})]},i))),(0,l.jsx)(o.__experimentalHStack,{justify:"left",children:(0,l.jsx)(o.__experimentalInputControl,{label:(0,t.__)("User Id","wp-playground-blueprint-editor"),value:x,onChange:e=>i({userId:Number(e)})})}),(0,l.jsx)(o.Button,{icon:a,variant:"secondary",label:(0,t.__)("Add Option","wp-playground-blueprint-editor"),onClick:()=>{h.some((([e,t])=>""===e&&""===t))||m([...h,["",""]])},disabled:f})]})]})}),(0,l.jsx)(o.__experimentalConfirmDialog,{isOpen:_,onConfirm:()=>{m(h.filter(((e,t)=>t!==g))),j(void 0),w(!1)},onCancel:()=>w(!1),children:(0,t.__)("Delete User Meta?","wp-playground-blueprint-editor")})]})}})})(); |