mirror of
https://gh.wpcy.net/https://github.com/lubusIN/visual-blueprint-builder.git
synced 2026-05-07 04:09:02 +08:00
1 line
No EOL
3.9 KiB
JavaScript
1 line
No EOL
3.9 KiB
JavaScript
(()=>{"use strict";const e=window.wp.element,t=window.wp.i18n,n=window.wp.blocks,i=window.wp.primitives,l=window.ReactJSXRuntime,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",d:"M10.289 4.836A1 1 0 0111.275 4h1.306a1 1 0 01.987.836l.244 1.466c.787.26 1.503.679 2.108 1.218l1.393-.522a1 1 0 011.216.437l.653 1.13a1 1 0 01-.23 1.273l-1.148.944a6.025 6.025 0 010 2.435l1.149.946a1 1 0 01.23 1.272l-.653 1.13a1 1 0 01-1.216.437l-1.394-.522c-.605.54-1.32.958-2.108 1.218l-.244 1.466a1 1 0 01-.987.836h-1.306a1 1 0 01-.986-.836l-.244-1.466a5.995 5.995 0 01-2.108-1.218l-1.394.522a1 1 0 01-1.217-.436l-.653-1.131a1 1 0 01.23-1.272l1.149-.946a6.026 6.026 0 010-2.435l-1.148-.944a1 1 0 01-.23-1.272l.653-1.131a1 1 0 011.217-.437l1.393.522a5.994 5.994 0 012.108-1.218l.244-1.466zM14.929 12a3 3 0 11-6 0 3 3 0 016 0z",clipRule:"evenodd"})}),a=(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"})}),o=(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"})}),r=window.wp.blockEditor,p=window.wp.components,c=JSON.parse('{"UU":"playground-step/define-wp-config-consts","DD":"WP Config"}');(0,n.registerBlockType)(c.UU,{icon:s,edit:function({attributes:n,setAttributes:i,isSelected:d}){const{consts:w}=n,[x,u]=(0,e.useState)(!1),[_,h]=(0,e.useState)(Object.entries(w)),[g,m]=(0,e.useState)(void 0);(0,e.useEffect)((()=>{const e=_.filter((([e,t])=>""!==e.trim()&&""!==t.trim()));i({consts:Object.fromEntries(e)}),d||f()}),[_,d]);const j=(e,t,n)=>{const i=_.map((([i,l],s)=>s===e?"key"===t?[n,l]:[i,n]:[i,l]));h(i)},f=()=>{h(_.filter((([e,t])=>e.trim()&&t.trim()))),u(!1)},v=_.length>0&&(""===_[_.length-1][0]||""===_[_.length-1][1]);return(0,l.jsxs)("div",{...(0,r.useBlockProps)(),children:[(0,l.jsx)(p.Placeholder,{preview:(0,l.jsxs)(p.__experimentalVStack,{style:{width:"100%"},children:[(0,l.jsxs)(p.__experimentalHStack,{justify:"left",align:"center",spacing:3,children:[(0,l.jsx)(p.Icon,{icon:s,size:28,className:"step-icon"}),(0,l.jsxs)(p.__experimentalVStack,{spacing:1,children:[(0,l.jsx)(p.__experimentalText,{upperCase:!0,size:12,weight:500,color:"#949494",children:c.DD}),!d&&(0,l.jsx)(p.__experimentalText,{weight:600,children:(0,l.jsx)("pre",{style:{whiteSpace:"pre-wrap"},children:JSON.stringify(w,null," ")})||(0,t.__)("{config consts}","wp-playground-blueprint-editor")})]})]}),d&&(0,l.jsxs)(p.__experimentalVStack,{spacing:4,children:[_.map((([e,n],i)=>(0,l.jsxs)(p.__experimentalHStack,{justify:"space-between",alignment:"center",children:[(0,l.jsx)(p.__experimentalInputControl,{label:(0,t.__)("Name","wp-playground-blueprint-editor"),value:e,__next40pxDefaultSize:!0,__unstableInputWidth:"200px",onChange:e=>j(i,"key",e)}),(0,l.jsx)(p.__experimentalInputControl,{label:(0,t.__)("Value","wp-playground-blueprint-editor"),value:n,__next40pxDefaultSize:!0,__unstableInputWidth:"200px",onChange:e=>j(i,"value",e)}),(0,l.jsx)(p.Button,{isDestructive:!0,icon:a,label:(0,t.__)("Delete Config","wp-playground-blueprint-editor"),onClick:()=>{m(i),u(!0)},style:{width:"40px",marginTop:"24px"}})]},i))),(0,l.jsx)(p.Button,{icon:o,variant:"secondary",label:(0,t.__)("Add Option","wp-playground-blueprint-editor"),onClick:()=>{_.some((([e,t])=>""===e&&""===t))||h([..._,["",""]])},disabled:v})]})]})}),(0,l.jsx)(p.__experimentalConfirmDialog,{isOpen:x,onConfirm:()=>{h(_.filter(((e,t)=>t!==g))),m(void 0),u(!1)},onCancel:()=>u(!1),children:(0,t.__)("Delete Config?","wp-playground-blueprint-editor")})]})}})})(); |