mirror of
https://gh.wpcy.net/https://github.com/lubusIN/visual-blueprint-builder.git
synced 2026-05-02 21:55:09 +08:00
1 line
No EOL
9.7 KiB
JavaScript
1 line
No EOL
9.7 KiB
JavaScript
(()=>{"use strict";const e=window.wp.i18n,t=window.wp.blocks,n=window.wp.primitives,i=window.ReactJSXRuntime,l=(0,i.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(n.Path,{d:"M10.5 4v4h3V4H15v4h1.5a1 1 0 011 1v4l-3 4v2a1 1 0 01-1 1h-3a1 1 0 01-1-1v-2l-3-4V9a1 1 0 011-1H9V4h1.5zm.5 12.5v2h2v-2l3-4v-3H8v3l3 4z"})}),r=window.wp.blockEditor,s=window.wp.components,a=JSON.parse('{"UU":"playground-step/install-plugin","DD":"Install Plugin"}'),o=window.wp.htmlEntities,c=window.wp.element,d=(0,i.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(n.Path,{d:"M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z"})}),p=({item:t,onSelect:n})=>(0,i.jsx)(s.Card,{size:"small",children:(0,i.jsxs)(s.CardBody,{style:{padding:"0"},children:[(0,i.jsx)(s.CardMedia,{children:(0,i.jsx)("img",{src:t.screenshot_url})}),(0,i.jsx)(s.CardBody,{children:(0,i.jsxs)(s.__experimentalHStack,{align:"center",children:[(0,i.jsx)(s.__experimentalHeading,{level:5,children:t.name}),(0,i.jsx)(s.Button,{variant:"secondary",style:{borderRadius:"4px"},onClick:()=>n(t.slug),children:(0,e.__)("Select","wp-playground-blueprint-editor")})]})})]})},t.slug),u=({item:t,onSelect:n})=>{return(0,i.jsx)(s.Card,{size:"small",children:(0,i.jsx)(s.CardBody,{style:{height:"100%"},children:(0,i.jsxs)(s.__experimentalVStack,{justify:"space-between",spacing:4,style:{height:"100%"},children:[(0,i.jsxs)(s.__experimentalVStack,{spacing:4,children:[(0,i.jsxs)(s.__experimentalHStack,{justify:"start",spacing:4,children:[(0,i.jsx)("img",{src:t.icons["1x"]||t.icons.default,alt:`${t.name} Icon`,style:{minWidth:"70px",maxHeight:"70px",objectFit:"contain",borderRadius:"4px"}}),(0,i.jsx)(s.ExternalLink,{href:t.homepage,style:{fontWeight:"bold",color:"#0073aa"},children:(0,o.decodeEntities)(t.name)})]}),(0,i.jsx)(s.__experimentalText,{lineHeight:"1.5em",children:t.short_description||(0,e.__)("No description available","wp-playground-blueprint-editor")}),(0,i.jsxs)(s.__experimentalHStack,{spacing:10,children:[(0,i.jsx)(s.__experimentalText,{color:"#666",children:t.active_installs?`${l=t.active_installs,l>=1e6?l/1e6+"M":l>=1e3?l/1e3+"K":new Intl.NumberFormat("en-IN").format(l)}+ active installations`:(0,e.__)("No data available","wp-playground-blueprint-editor")}),(0,i.jsxs)(s.__experimentalText,{color:"#666",children:[(0,e.__)("Tested with","wp-playground-blueprint-editor")," ",t.tested||(0,e.__)("Unknown","wp-playground-blueprint-editor")]})]})]}),(0,i.jsx)(s.__experimentalHStack,{justify:"right",children:(0,i.jsx)(s.Button,{variant:"secondary",style:{borderRadius:"4px"},onClick:()=>n(t.slug),children:(0,e.__)("Select","wp-playground-blueprint-editor")})})]})})},t.slug);var l},h=function({type:t,onSelect:n}){const[l,r]=(0,c.useState)(!1),[a,o]=(0,c.useState)(""),[h,g]=(0,c.useState)([]),[x,_]=(0,c.useState)([]),[m,w]=(0,c.useState)(!1),b=async(e="")=>{w(!0);const n=!!e.trim(),i=`https://api.wordpress.org/${t}/info/1.2/?action=query_${t}${n?`&request[search]=${e}`:"&request[popular]=1"}`;try{const e=await fetch(i),l=await e.json();n?g(l[t]||[]):_(l[t]||[])}catch(e){console.error(`Error fetching ${t}:`,e)}finally{w(!1)}};(0,c.useEffect)((()=>{l&&!a&&b()}),[l,a]);const f=e=>{n(e),r(!1)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.Button,{variant:"secondary",size:"compact",onClick:()=>r(!0),style:{boxShadow:"none"},children:(0,e.__)("Browse","wp-playground-blueprint-editor")}),l&&(0,i.jsx)(s.Modal,{title:(0,e.__)(`Browse ${t[0].toUpperCase()}${t.slice(1)}`,"wp-playground-blueprint-editor"),onRequestClose:()=>r(!1),shouldCloseOnClickOutside:!1,size:"large",style:{height:"70%"},children:(0,i.jsxs)(s.__experimentalVStack,{spacing:6,justify:"space-between",children:[(0,i.jsx)(s.__experimentalInputControl,{__next40pxDefaultSize:!0,placeholder:(0,e.__)("Search by name or author","wp-playground-blueprint-editor"),value:a,onChange:e=>{o(e),b(e)},suffix:(0,i.jsx)(s.Button,{variant:"link",onClick:()=>b(a),disabled:m,style:{textDecoration:"none",color:"#0073aa"},icon:d})}),(0,i.jsx)(s.__experimentalVStack,{children:m?(0,i.jsx)(s.__experimentalGrid,{columns:2,gap:5,children:Array.from({length:4}).map(((e,n)=>"themes"===t?(0,i.jsx)(y,{},n):(0,i.jsx)(j,{},n)))}):(0,i.jsx)(s.__experimentalGrid,{columns:2,gap:5,children:(a?h:x).map((e=>"themes"===t?(0,i.jsx)(p,{item:e,onSelect:f},e.slug):(0,i.jsx)(u,{item:e,onSelect:f},e.slug)))})})]})})]})},g=window.React,x=g.createContext({}),_=!0;function m({baseColor:e,highlightColor:t,width:n,height:i,borderRadius:l,circle:r,direction:s,duration:a,enableAnimation:o=_,customHighlightBackground:c}){const d={};return"rtl"===s&&(d["--animation-direction"]="reverse"),"number"==typeof a&&(d["--animation-duration"]=`${a}s`),o||(d["--pseudo-element-display"]="none"),"string"!=typeof n&&"number"!=typeof n||(d.width=n),"string"!=typeof i&&"number"!=typeof i||(d.height=i),"string"!=typeof l&&"number"!=typeof l||(d.borderRadius=l),r&&(d.borderRadius="50%"),void 0!==e&&(d["--base-color"]=e),void 0!==t&&(d["--highlight-color"]=t),"string"==typeof c&&(d["--custom-highlight-background"]=c),d}function w({count:e=1,wrapper:t,className:n,containerClassName:i,containerTestId:l,circle:r=!1,style:s,...a}){var o,c,d;const p=g.useContext(x),u={...a};for(const[e,t]of Object.entries(a))void 0===t&&delete u[e];const h={...p,...u,circle:r},w={...s,...m(h)};let j="react-loading-skeleton";n&&(j+=` ${n}`);const y=null!==(o=h.inline)&&void 0!==o&&o,b=[],f=Math.ceil(e);for(let t=0;t<f;t++){let n=w;if(f>e&&t===f-1){const t=null!==(c=n.width)&&void 0!==c?c:"100%",i=e%1,l="number"==typeof t?t*i:`calc(${t} * ${i})`;n={...n,width:l}}const i=g.createElement("span",{className:j,style:n,key:t},"");y?b.push(i):b.push(g.createElement(g.Fragment,{key:t},i,g.createElement("br",null)))}return g.createElement("span",{className:i,"data-testid":l,"aria-live":"polite","aria-busy":null!==(d=h.enableAnimation)&&void 0!==d?d:_},t?b.map(((e,n)=>g.createElement(t,{key:n},e))):b)}const j=function(){return(0,i.jsx)(s.Card,{size:"small",children:(0,i.jsx)(s.CardBody,{children:(0,i.jsxs)(s.__experimentalVStack,{justify:"space-between",spacing:4,style:{height:"100%"},children:[(0,i.jsxs)(s.__experimentalHStack,{expanded:!0,spacing:8,children:[(0,i.jsx)(w,{width:70,height:70,style:{borderRadius:"4px"}}),(0,i.jsx)(s.__experimentalVStack,{style:{width:"100%"},children:(0,i.jsx)(w,{height:20,width:"60%"})})]}),(0,i.jsx)(w,{height:16,width:"90%"}),(0,i.jsxs)(s.__experimentalHStack,{justify:"space-between",children:[(0,i.jsx)(w,{containerClassName:"custom-skeleton",height:10,width:"80%"}),(0,i.jsx)(w,{containerClassName:"custom-skeleton",height:10,width:"100%"})]}),(0,i.jsx)(s.__experimentalHStack,{justify:"right",children:(0,i.jsx)(w,{width:80,height:32,style:{borderRadius:"4px"}})})]})})})},y=function(){return(0,i.jsx)(s.Card,{style:{borderRadius:"4px"},children:(0,i.jsxs)(s.CardBody,{style:{padding:0,lineHeight:"0px"},children:[(0,i.jsx)(w,{width:"100%",height:200,style:{borderRadius:"0px"}}),(0,i.jsxs)(s.__experimentalHStack,{spacing:2,align:"center",justify:"space-between",style:{padding:"12px"},children:[(0,i.jsx)(w,{height:16,width:180}),(0,i.jsx)(w,{width:80,height:32})]})]})})};(0,t.registerBlockType)(a.UU,{icon:l,edit:function({attributes:t,setAttributes:n,isSelected:o}){const{pluginData:c,options:d}=t,{resource:p,path:u,url:g,slug:x}=c,{activate:_}=d,m=(e,t)=>{n({pluginData:{...c,[e]:t}})};return(0,i.jsx)("div",{...(0,r.useBlockProps)(),children:(0,i.jsx)(s.Placeholder,{preview:(0,i.jsxs)(s.__experimentalVStack,{style:{width:"100%"},children:[(0,i.jsxs)(s.__experimentalHStack,{justify:"left",align:"center",spacing:3,children:[(0,i.jsx)(s.Icon,{icon:l,size:28,className:"step-icon"}),(0,i.jsxs)(s.__experimentalVStack,{spacing:1,children:[(0,i.jsx)(s.__experimentalText,{upperCase:!0,size:12,weight:500,color:"#949494",children:a.DD}),!o&&(0,i.jsx)(s.__experimentalText,{weight:600,children:`${p} > ${(e=>{switch(e){case"url":return g;case"vfs":return u;default:return x}})(p)} > ${_?(0,e.__)("Activate","wp-playground-blueprint-editor"):(0,e.__)("Install and keep Inactive","wp-playground-blueprint-editor")}`})]})]}),o&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(s.__experimentalToggleGroupControl,{label:(0,e.__)("Resource","wp-playground-blueprint-editor"),value:p,isBlock:!0,onChange:e=>{let t={resource:e};"vfs"===e?t.path=c.path||"":"url"===e?t.url=c.url||"":"wordpress.org/plugins"===e&&(t.slug=c.slug||""),n({pluginData:t})},children:[(0,i.jsx)(s.__experimentalToggleGroupControlOption,{value:"url",label:(0,e.__)("URL","wp-playground-blueprint-editor")}),(0,i.jsx)(s.__experimentalToggleGroupControlOption,{value:"wordpress.org/plugins",label:(0,e.__)("Plugin","wp-playground-blueprint-editor")}),(0,i.jsx)(s.__experimentalToggleGroupControlOption,{value:"vfs",label:(0,e.__)("VFS","wp-playground-blueprint-editor")})]}),"vfs"===p&&(0,i.jsx)(s.TextControl,{label:(0,e.__)("Path","wp-playground-blueprint-editor"),value:u,placeholder:(0,e.__)("Enter the file path for the plugin ZIP","wp-playground-blueprint-editor"),onChange:e=>m("path",e)}),"url"===p&&(0,i.jsx)(s.TextControl,{label:(0,e.__)("Url","wp-playground-blueprint-editor"),value:g,placeholder:(0,e.__)("Enter the URL of the plugin ZIP file","wp-playground-blueprint-editor"),onChange:e=>m("url",e)}),"wordpress.org/plugins"===p&&(0,i.jsx)(s.__experimentalInputControl,{style:{width:"100%",paddingBottom:"8px"},label:(0,e.__)("Slug","wp-playground-blueprint-editor"),value:x,placeholder:(0,e.__)("Enter plugin slug","wp-playground-blueprint-editor"),onChange:e=>m("slug",e),suffix:(0,i.jsx)(h,{type:"plugins",onSelect:e=>m("slug",e)})}),(0,i.jsx)(s.ToggleControl,{label:(0,e.__)("Activate","wp-playground-blueprint-editor"),checked:_,onChange:()=>n({options:{activate:!_}})})]})]})})})}})})(); |