PluginProbe
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs / 5.0.1
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs v5.0.1
5.0.1 4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 All 39 releases
blockspare / dist / aigen.js

aigen.js in BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs 5.0.1, at dist/aigen.js

2 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*! For license information please see aigen.js.LICENSE.txt */
2 (()=>{"use strict";var e={1020(e,r,t){var n=t(1594),o=Symbol.for("react.element"),s=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function l(e,r,t){var n,s={},l=null,p=null;for(n in void 0!==t&&(l=""+t),void 0!==r.key&&(l=""+r.key),void 0!==r.ref&&(p=r.ref),r)a.call(r,n)&&!c.hasOwnProperty(n)&&(s[n]=r[n]);if(e&&e.defaultProps)for(n in r=e.defaultProps)void 0===s[n]&&(s[n]=r[n]);return{$$typeof:o,type:e,key:l,ref:p,props:s,_owner:i.current}}r.Fragment=s,r.jsx=l,r.jsxs=l},4848(e,r,t){e.exports=t(1020)},1594(e){e.exports=React}};const r={},t=wp.plugins,n=wp.editor,o=wp.i18n,s=wp.components;var a=function t(n){const o=r[n];if(void 0!==o)return o.exports;const s=r[n]={exports:{}};return e[n](s,s.exports,t),s.exports}(4848);const i={};i.LockIcon=(0,a.jsx)("svg",{version:"1.1",id:"Layer_1",xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink",width:"18px",height:"18px",fill:"#ff9800",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",children:(0,a.jsx)("g",{children:(0,a.jsx)("g",{children:(0,a.jsx)("path",{d:"M463.573,66.88l-98.966,98.966L256.002,57.24L147.394,165.846L48.427,66.881H0V454.76h512V66.88H463.573z M465.455,408.214H46.545V130.824l100.848,100.848l108.608-108.606l108.604,108.606l100.848-100.848V408.214z"})})})});const c=i,l=blockspare_globals.upgradeUrl;function p(){return c.LockIcon,(0,a.jsxs)("p",{style:{color:"#2a47ec"},children:[c.LockIcon," ",(0,a.jsx)("a",{href:l,target:"_blank",rel:"noopener noreferrer",children:(0,o.__)("Available in BlockSpare Pro","blockspare")})]})}const d=wp.element,h=wp.data,g=wp.blocks,{apiFetch:m}=wp;(0,t.registerPlugin)("blockspare-ai-content-generator",{render:()=>{const[e,r]=(0,d.useState)(""),[t,i]=(0,d.useState)(!1),[c,l]=(0,d.useState)(""),[u,x]=(0,d.useState)(""),_=window.blockspareAiPluginData||{isAiSupported:!1,missingReason:"",havePermission:!1,aiProvider:"",aiModel:"",language:"",connectorLink:"",connectorText:"",bsAiLink:"",bsAiText:""},b=e=>(0,a.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:[(0,a.jsx)("path",{fill:e,d:"M12 2l1.7 6.3L20 10l-6.3 1.7L12 18l-1.7-6.3L4 10l6.3-1.7L12 2z"}),(0,a.jsx)("path",{fill:e,d:"M19 15l.8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8L19 15z"})]}),{postId:k,postType:f}=(0,h.useSelect)(e=>({postId:e("core/editor").getCurrentPostId(),postType:e("core/editor").getCurrentPostType()}),[]),{insertBlocks:w}=(0,h.useDispatch)("core/block-editor");return _.isAiSupported?(0,a.jsx)(a.Fragment,{children:_.havePermission&&(0,a.jsxs)(n.PluginDocumentSettingPanel,{name:"ai-content-generator-panel",title:(0,o.__)("AI Content Generator","blockspare"),className:"ai-content-generator-panel",icon:b,children:[(0,a.jsxs)("div",{className:"blockspare-ai-prompt",children:[(0,a.jsxs)("div",{className:"blockspare-ai-prompt-label",children:[(0,a.jsx)("span",{children:(0,o.__)("Enter Prompt for AI","blockspare")}),(0,a.jsx)(s.Icon,{icon:b,size:18,color:"#4b07bf"})]}),(0,a.jsx)(s.TextareaControl,{help:(0,o.__)("Create article content faster with AI, generate ideas, write posts, & refine content.","blockspare"),value:e,onChange:e=>r(e),rows:4,placeholder:(0,o.__)("Tell AI what you want to write...","blockspare"),disabled:t})]}),u&&(0,a.jsx)(s.Notice,{status:"error",isDismissible:!1,children:u}),(0,a.jsxs)(s.Notice,{status:"info",isDismissible:!1,children:[(0,a.jsx)("strong",{children:(0,o.__)("AI Using ","blockspare")}),_.aiProvider," ",_.aiModel," ",_.language,(0,a.jsx)("p",{children:(0,a.jsx)("a",{href:_.bsAiLink,target:"_blank",children:_.bsAiText})})]}),(0,a.jsx)("div",{style:{marginTop:"12px"},children:(0,a.jsx)(s.Button,{variant:"primary",onClick:async()=>{if(e.trim()){i(!0),l("generate"),x("");try{const t=await m({path:"blockspare/v1/generate-content",method:"POST",headers:{"X-WP-Nonce":_.nonce},data:{action:"generate",prompt:e,post_id:k}});if(!t?.content)throw new Error((0,o.__)("Empty response from AI engine.","blockspare"));{const e=t.content.split(/\r?\n\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>(0,g.createBlock)("core/paragraph",{content:e}));w(e),r("")}}catch(e){x(e.message||(0,o.__)("An error occurred during AI generation.","blockspare"))}finally{i(!1),l("")}}else x((0,o.__)("Please enter a prompt first.","blockspare"))},isBusy:t&&"generate"===c,disabled:t||!e.trim(),style:{width:"100%",justifyContent:"center"},children:t&&"generate"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.Spinner,{}),(0,o.__)(" Generating...","blockspare")]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.Icon,{icon:b,color:"#fff",size:18}),(0,o.__)("Generate Content","blockspare")]})})}),(0,a.jsx)("div",{style:{marginTop:"8px"},children:(0,a.jsx)(s.Button,{variant:"secondary",onClick:async()=>{i(!0),l("summarize"),x("");try{const e=await m({path:"blockspare/v1/generate-content",method:"POST",headers:{"X-WP-Nonce":_.nonce},data:{action:"summarize",post_id:k}});if(!e?.content)throw new Error((0,o.__)("Empty summary returned from AI engine.","blockspare"));{const r=(0,g.createBlock)("blockspare/blockspare-notice-bar",{noticeContent:e.content});w(r)}}catch(e){x(e.message||(0,o.__)("An error occurred while summarizing the post.","blockspare"))}finally{i(!1),l("")}},isBusy:t&&"summarize"===c,disabled:t||!k,style:{width:"100%",justifyContent:"center"},children:t&&"summarize"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.Spinner,{}),(0,o.__)(" Summarizing...","blockspare")]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.Icon,{icon:b,size:18,color:"#4b07bf"}),(0,o.__)("Summarize Content","blockspare")]})})}),(0,a.jsxs)("div",{style:{marginTop:"8px"},children:[(0,a.jsx)(s.Button,{variant:"secondary",onClick:async()=>{i(!0),l("highlight_qa"),x("");try{const e=await m({path:"blockspare/v1/generate-content",method:"POST",headers:{"X-WP-Nonce":_.nonce},data:{action:"highlight_qa",post_id:k}});if(!e?.items?.length)throw new Error((0,o.__)("No Q&A items were returned from AI.","blockspare"));{const r=e.items.map((e,r)=>{const t=(0,g.createBlock)("core/paragraph",{content:e.answer});return(0,g.createBlock)("blockspare/accordion-item",{heading:e.question,active:0===r,itemNumber:r+1},[t])}),t=(0,g.createBlock)("blockspare/blockspare-accordion",{},r),n=(0,g.createBlock)("blockspare/blockspare-section-header",{headerTitle:"Frequently Asked Questions",headerSubTitle:"",sectionAlignment:"left",headerlayoutOption:"blockspare-style1",headerTagOption:"h2",align:"center"});w(n),w(t)}}catch(e){console.error("Highlight Q&A error:",e),x(e.message||(0,o.__)("An error occurred while generating Highlight Q&A.","blockspare"))}finally{i(!1),l("")}},disabled:!0,style:{width:"100%",justifyContent:"center",opacity:.6,cursor:"not-allowed"},children:t&&"highlight_qa"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.Spinner,{}),(0,o.__)(" Finding Q&A...","blockspare")]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.Icon,{icon:b,size:18,color:"#4b07bf"}),(0,o.__)("AI Key Q&A","blockspare")]})}),(0,a.jsxs)("p",{className:"components-base-control__help",style:{marginTop:"4px",fontSize:"12px",color:"#757575"},children:[(0,o.__)("Show relevant Q&A from the article automatically, making important information easier to find","blockspare"),(0,a.jsx)(p,{})]})]})]})}):(0,a.jsx)(n.PluginDocumentSettingPanel,{name:"ai-content-generator-panel",title:(0,o.__)("AI Content Generator","blockspare"),className:"ai-content-generator-panel",icon:b,children:(0,a.jsxs)(s.Notice,{status:"warning",isDismissible:!1,children:[_.missingReason||(0,o.__)("AI features are currently unavailable. Please ensure the WordPress AI plugin is installed and active API keys/connectors are set up.","blockspare"),(0,a.jsx)("p",{children:(0,a.jsx)("a",{href:_.connectorLink,target:"_blank",children:_.connectorText})})]})})},icon:"admin-generic"})})();