| 1 |
(()=>{"use strict";const e={n:t=>{const s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{if(Array.isArray(s))for(var i=0;i<s.length;){var n=s[i++],r=s[i++];e.o(t,n)?0===r&&i++:0===r?Object.defineProperty(t,n,{enumerable:!0,value:s[i++]}):Object.defineProperty(t,n,{enumerable:!0,get:r})}else for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.hasOwn(e,t)},t=window.wp.blocks,s=window.wp.i18n,i=window.GetwidComponents,n=window.wp.blockEditor,r=window.wp.components,o=window.wp.element,a=window.wp.data;function c(e){var t,s,i="";if("string"==typeof e||"number"==typeof e)i+=e;else if("object"==typeof e)if(Array.isArray(e)){var n=e.length;for(t=0;t<n;t++)e[t]&&(s=c(e[t]))&&(i&&(i+=" "),i+=s)}else for(s in e)e[s]&&(i&&(i+=" "),i+=s);return i}const l=function(){for(var e,t,s=0,i="",n=arguments.length;s<n;s++)(e=arguments[s])&&(t=c(e))&&(i&&(i+=" "),i+=t);return i},d=window.ReactJSXRuntime;function p(e){return(0,d.jsxs)("svg",{className:e.className,width:e.size||16,height:e.size||16,viewBox:"0 0 20 19",fill:"currentColor",children:[(0,d.jsx)("path",{d:"M12.7046 6.73865C12.7687 6.56531 13.0139 6.56531 13.078 6.73865L13.7127 8.45393C14.3177 10.0889 15.6067 11.3779 17.2417 11.9829L18.9569 12.6176C19.1303 12.6817 19.1303 12.9269 18.9569 12.991L17.2417 13.6257C15.6067 14.2307 14.3177 15.5197 13.7127 17.1547L13.078 18.8699C13.0139 19.0433 12.7687 19.0433 12.7046 18.8699L12.0699 17.1547C11.4649 15.5197 10.1759 14.2307 8.54094 13.6257L6.82565 12.991C6.65231 12.9269 6.65231 12.6817 6.82565 12.6176L8.54094 11.9829C10.1759 11.3779 11.4649 10.0889 12.0699 8.45393L12.7046 6.73865Z"}),(0,d.jsx)("path",{d:"M4.91899 3.39099C4.96175 3.27543 5.1252 3.27543 5.16796 3.39099L5.5911 4.53452C5.99442 5.62446 6.85377 6.48381 7.94372 6.88713L9.08724 7.31027C9.2028 7.35303 9.2028 7.51648 9.08724 7.55924L7.94372 7.98238C6.85377 8.3857 5.99442 9.24505 5.5911 10.335L5.16796 11.4785C5.1252 11.5941 4.96175 11.5941 4.91899 11.4785L4.49585 10.335C4.09253 9.24505 3.23318 8.3857 2.14323 7.98238L0.99971 7.55924C0.88415 7.51648 0.88415 7.35303 0.99971 7.31027L2.14323 6.88713C3.23318 6.48381 4.09253 5.62446 4.49585 4.53452L4.91899 3.39099Z"}),(0,d.jsx)("path",{d:"M10.3259 0.0606688C10.3558 -0.0202228 10.4702 -0.020223 10.5002 0.0606687L10.7964 0.861136C11.0787 1.6241 11.6802 2.22565 12.4432 2.50797L13.2437 2.80417C13.3246 2.8341 13.3246 2.94851 13.2437 2.97844L12.4432 3.27464C11.6802 3.55696 11.0787 4.15851 10.7964 4.92147L10.5002 5.72194C10.4702 5.80283 10.3558 5.80283 10.3259 5.72194L10.0297 4.92147C9.74737 4.15851 9.14583 3.55696 8.38286 3.27464L7.5824 2.97844C7.50151 2.94851 7.50151 2.8341 7.5824 2.80417L8.38286 2.50797C9.14583 2.22565 9.74737 1.6241 10.0297 0.861136L10.3259 0.0606688Z"})]})}function u(e){return(0,d.jsxs)("svg",{className:e.className,width:e.size||16,height:e.size||16,viewBox:"0 0 18 18",fill:"none",children:[(0,d.jsx)("path",{d:"M14.3085 11.9361L15.6817 7.81664C16.8813 4.21793 17.4811 2.41858 16.5312 1.46876C15.5814 0.518948 13.7821 1.11873 10.1834 2.3183L6.06389 3.69146C3.15939 4.65963 1.70714 5.14371 1.29445 5.85359C0.901851 6.5289 0.901851 7.36295 1.29445 8.03827C1.70713 8.74814 3.15939 9.23223 6.06389 10.2004C6.53026 10.3559 6.76344 10.4336 6.95835 10.5641C7.14723 10.6905 7.3095 10.8528 7.43595 11.0417C7.56642 11.2366 7.64416 11.4698 7.79961 11.9361C8.76777 14.8406 9.25186 16.2929 9.96173 16.7056C10.637 17.0981 11.4711 17.0981 12.1464 16.7056C12.8563 16.2929 13.3404 14.8406 14.3085 11.9361Z",stroke:"currentColor",strokeWidth:"1.5"}),(0,d.jsx)("path",{d:"M13.6317 4.36866L10.2633 7.69995",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function w(e){return(0,d.jsx)("svg",{className:e.className,width:e.size||16,height:e.size||16,viewBox:"0 0 17 12",fill:"none",children:(0,d.jsx)("path",{d:"M1 6.2L6 11L16 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function h(e){return(0,d.jsx)("svg",{className:e.className,width:e.size||16,height:e.size||16,viewBox:"0 0 13 13",children:(0,d.jsx)("path",{d:"M12 1L1.00005 12M0.999999 0.999955L12 11.9999",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}const m=window.wp.apiFetch;var g=e.n(m);function C({setTermsAccepted:e}){const[t,i]=(0,o.useState)(!1),[n,a]=(0,o.useState)(!1),c=(0,o.createInterpolateElement)((0,s.__)("In order to use this block, you must accept <link>Terms and Conditions</link>.","getwid"),{link:(0,d.jsx)("a",{href:"https://api2.getmotopress.com/terms-and-conditions/",target:"_blank",rel:"noreferrer"})});return(0,d.jsxs)("div",{className:"wp-block-getwid-ai__terms",children:[n&&(0,d.jsx)("p",{children:(0,s.__)("An error occurred while updating user profile.","getwid")}),(0,d.jsx)("p",{children:c}),(0,d.jsx)(r.Button,{isBusy:t,variant:"primary",size:"default",onClick:function(){i(!0),g()({path:"/wp/v2/users/me",method:"POST",data:{meta:{getwid_ai_accept_terms:!0}}}).then(()=>{e(!0)}).catch(()=>{a(!0)}).finally(()=>{i(!1)})},children:(0,s.__)("Accept","getwid")})]})}const f=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"textdomain":"getwid","name":"getwid/ai-text","description":"Generates text content with AI assistance.","category":"getwid-blocks","title":"AI Assistant","keywords":["ai"],"supports":{"customClassName":false},"attributes":{"prompt":{"type":"string"}},"editorScript":"file:./index.js","editorStyle":"file:./index.css"}');(0,t.registerBlockType)(f,{title:(0,s.__)("AI Assistant","getwid"),icon:(0,d.jsx)(p,{}),description:(0,s.__)("This Getwid block offers automated content generation fueled by the power of AI.","getwid"),edit:(0,i.MaybeBlockIsDisabled)("getwid/ai-text")||function(e){const{attributes:t,clientId:c,setAttributes:m}=e,g=(0,n.useBlockProps)({className:"wp-block-getwid-ai"}),[f,k]=(0,o.useState)(!0),[x,j]=(0,o.useState)(!1),{replaceBlocks:_,insertBlocks:b}=(0,a.useDispatch)(n.store),{loading:L,content:v,makeStreamRequest:y,errors:N,parseBlocks:B,stopLoading:A}=(0,i.useGetwidAI)(),{getBlock:S,getClientIdsOfDescendants:I,currentUser:z}=(0,a.useSelect)(e=>{const t=e(n.store);return{currentUser:e("core").getCurrentUser(),getBlock:t.getBlock,getClientIdsOfDescendants:t.getClientIdsOfDescendants}},[]),M=!(Object.keys(z).length>0)||z.meta?.getwid_ai_accept_terms;return(0,d.jsxs)("div",{...g,children:[f&&v&&(0,d.jsx)(o.RawHTML,{className:"wp-block-getwid-ai__suggestion",children:v}),(0,d.jsx)("div",{className:l("wp-block-getwid-ai__parsed-blocks",{"is-visible":!f&&0===N.length}),children:(0,d.jsx)(n.InnerBlocks,{renderAppender:!1})}),(0,d.jsxs)("div",{className:"wp-block-getwid-ai__prompt-wrapper",children:[M||x?(0,d.jsxs)("form",{className:l("wp-block-getwid-ai__prompt-form",{"is-loading":L}),onSubmit:async function(e){e.preventDefault(),k(!0);const s=await y(t.prompt);!function(e){const t=I([c]);t.length>0?_(t,e):b(e,0,c),k(!1)}(B(s))},autoComplete:"off",children:[(0,d.jsx)("div",{className:"wp-block-getwid-ai__icon",children:L?(0,d.jsx)(r.Spinner,{}):(0,d.jsx)(r.Icon,{size:16,icon:p})}),(0,d.jsx)(r.TextControl,{className:"wp-block-getwid-ai__prompt-input",value:t.prompt||"",onChange:e=>m({prompt:e}),minLength:5,required:!0,disabled:L,placeholder:(0,s.__)("Write your request or question to receive an AI-generated reply","getwid")}),(0,d.jsxs)("div",{className:"wp-block-getwid-ai__prompt-buttons",children:[(!L&&f||N.length>0)&&(0,d.jsx)(r.Button,{className:"send",type:"submit",variant:"tertiary",icon:u,iconSize:16}),!f&&0===N.length&&(0,d.jsx)(r.Button,{className:"accept",disabled:f,variant:"tertiary",onClick:function(){const e=S(c)?.innerBlocks;e&&_(c,e)},icon:w,iconSize:16,children:(0,s.__)("Accept","getwid")}),L&&(0,d.jsx)(r.Button,{className:"stop",variant:"tertiary",onClick:A,icon:h,iconSize:15,children:(0,s.__)("Stop","getwid")})]})]}):(0,d.jsx)(C,{setTermsAccepted:j}),N?.length>0&&(0,d.jsx)("div",{className:"wp-block-getwid-ai__errors",children:(0,d.jsx)("ul",{children:N.map(e=>(0,d.jsx)("li",{children:e},e))})})]})]})},save:()=>null})})(); |