visual-blueprint-builder/build/steps/set-site-options/index.js
2025-07-29 18:37:15 +00:00

1 line
No EOL
3.6 KiB
JavaScript

(()=>{"use strict";const e=window.wp.element,t=window.wp.i18n,i=window.wp.blocks,n=window.wp.primitives,l=window.ReactJSXRuntime,s=(0,l.jsxs)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:[(0,l.jsx)(n.Path,{d:"m19 7.5h-7.628c-.3089-.87389-1.1423-1.5-2.122-1.5-.97966 0-1.81309.62611-2.12197 1.5h-2.12803v1.5h2.12803c.30888.87389 1.14231 1.5 2.12197 1.5.9797 0 1.8131-.62611 2.122-1.5h7.628z"}),(0,l.jsx)(n.Path,{d:"m19 15h-2.128c-.3089-.8739-1.1423-1.5-2.122-1.5s-1.8131.6261-2.122 1.5h-7.628v1.5h7.628c.3089.8739 1.1423 1.5 2.122 1.5s1.8131-.6261 2.122-1.5h2.128z"})]}),o=(0,l.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,l.jsx)(n.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"})}),r=(0,l.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,l.jsx)(n.Path,{d:"M11 12.5V17.5H12.5V12.5H17.5V11H12.5V6H11V11H6V12.5H11Z"})}),p=window.wp.blockEditor,a=window.wp.components,c=JSON.parse('{"UU":"playground-step/set-site-options","DD":"Set Site Options"}');(0,i.registerBlockType)(c.UU,{icon:s,edit:function({attributes:i,setAttributes:n,isSelected:d}){const{options:w}=i,[x,h]=(0,e.useState)(!1),[u,_]=(0,e.useState)(Object.entries(w)),[m,g]=(0,e.useState)(void 0);(0,e.useEffect)((()=>{const e=u.filter((([e,t])=>""!==e.trim()&&""!==t.trim()));n({options:Object.fromEntries(e)}),d||v()}),[u,d]);const j=(e,t,i)=>{const n=u.map((([n,l],s)=>s===e?"key"===t?[i,l]:[n,i]:[n,l]));_(n)},v=()=>{_(u.filter((([e,t])=>e.trim()&&t.trim()))),h(!1)},b=u.length>0&&(""===u[u.length-1][0]||""===u[u.length-1][1]);return(0,l.jsxs)("div",{...(0,p.useBlockProps)(),children:[(0,l.jsx)(a.Placeholder,{preview:(0,l.jsxs)(a.__experimentalVStack,{style:{width:"100%"},children:[(0,l.jsxs)(a.__experimentalHStack,{justify:"left",align:"center",spacing:3,children:[(0,l.jsx)(a.Icon,{icon:s,size:28,className:"step-icon"}),(0,l.jsxs)(a.__experimentalVStack,{spacing:1,children:[(0,l.jsx)(a.__experimentalText,{upperCase:!0,size:12,weight:500,color:"#949494",children:c.DD}),!d&&(0,l.jsx)(a.__experimentalText,{weight:600,children:(0,l.jsx)("pre",{style:{whiteSpace:"pre-wrap"},children:JSON.stringify(w,null," ")})||(0,t.__)("{config site options}","wp-playground-blueprint-editor")})]})]}),d&&(0,l.jsxs)(a.__experimentalVStack,{spacing:4,children:[u.map((([e,i],n)=>(0,l.jsxs)(a.__experimentalHStack,{justify:"space-between",alignment:"center",children:[(0,l.jsx)(a.__experimentalInputControl,{label:(0,t.__)("Name","wp-playground-blueprint-editor"),value:e,__next40pxDefaultSize:!0,__unstableInputWidth:"200px",onChange:e=>j(n,"key",e)}),(0,l.jsx)(a.__experimentalInputControl,{label:(0,t.__)("Value","wp-playground-blueprint-editor"),value:i,__next40pxDefaultSize:!0,__unstableInputWidth:"200px",onChange:e=>j(n,"value",e)}),(0,l.jsx)(a.Button,{isDestructive:!0,icon:o,label:(0,t.__)("Delete Config","wp-playground-blueprint-editor"),onClick:()=>{g(n),h(!0)},style:{width:"40px",marginTop:"24px"}})]},n))),(0,l.jsx)(a.Button,{icon:r,variant:"secondary",label:(0,t.__)("Add Option","wp-playground-blueprint-editor"),onClick:()=>{u.some((([e,t])=>""===e&&""===t))||_([...u,["",""]])},disabled:b})]})]})}),(0,l.jsx)(a.__experimentalConfirmDialog,{isOpen:x,onConfirm:()=>{_(u.filter(((e,t)=>t!==m))),h(!1),g(void 0),h(!1)},onCancel:()=>{h(!1)},children:(0,t.__)("Delete Option?","wp-playground-blueprint-editor")})]})}})})();