File "extendify-draft-c25a4375489dbe128705.js"

Full Path: /home/fresvfqn/waterdamagerestorationandrepairsmithtown.com/wp-content/plugins/extendify/public/build/extendify-draft-c25a4375489dbe128705.js
File size: 46.99 KB
MIME-type: text/plain
Charset: utf-8

"use strict";(globalThis.webpackChunkextendify=globalThis.webpackChunkextendify||[]).push([[429],{790:e=>{e.exports=window.ReactJSXRuntime},1455:e=>{e.exports=window.wp.apiFetch},1603:(e,t,a)=>{var n=a(4715),i=a(4997),s=a(6427),l=a(7143),r=a(4309),o=a(6087),c=a(2619),d=a(7723),m=a(2279),u=a(3656),g=a(7581),p=a(790);const x=({completion:e})=>{const t=(0,i.pasteHandler)({plainText:e}),a=(0,o.useRef)();return(0,p.jsx)("div",{ref:a,style:{fontSize:"clamp(1em 1em 1em)"},className:"completion relative max-h-60 overflow-y-auto break-words px-5 pt-4","data-test":"completion-input",children:Array.isArray(t)?(0,p.jsx)("div",{dangerouslySetInnerHTML:{__html:(0,i.serialize)(t)}}):(0,p.jsx)("div",{dangerouslySetInnerHTML:{__html:t}})})},f=()=>{const{consentTermsHTML:e,setUserGaveConsent:t}=(0,g.D)();return(0,p.jsx)(s.Panel,{children:(0,p.jsxs)("div",{className:"p-4",children:[(0,p.jsx)("h2",{className:"mb-2 mt-0 text-lg",children:(0,d.__)("Terms of Use","extendify-local")}),(0,p.jsx)("p",{className:"m-0",dangerouslySetInnerHTML:{__html:e}}),(0,p.jsx)("button",{className:"mt-4 w-full rounded border-0 bg-wp-theme-main px-4 py-2 text-center text-white",type:"button",onClick:()=>t(!0),"data-test":"draft-terms-button",children:(0,d.__)("Accept","extendify-local")})]})})};var h=a(998);const y=({disabled:e,setInputText:t,setReady:a})=>{const n=[{label:(0,d.__)("A paragraph …","extendify-local"),onClickText:(0,d.__)("Write a paragraph about","extendify-local")},{label:(0,d.__)("Blog post …","extendify-local"),onClickText:(0,d.__)("Write a blog post about","extendify-local")},{label:(0,d.__)("An informative article …","extendify-local"),onClickText:(0,d.__)("Write an informative article about","extendify-local")},{label:(0,d.__)("Headline …","extendify-local"),onClickText:(0,d.__)("Write a headline for","extendify-local")},{label:(0,d.__)("List …","extendify-local"),onClickText:(0,d.__)("Write a list of","extendify-local")}];return(0,p.jsx)(s.MenuGroup,{children:n.map((({label:n,onClickText:i})=>(0,p.jsx)(s.MenuItem,{onClick:()=>(t(`${i} `),void a(!1)),disabled:e,icon:h.A,iconPosition:"left",children:n},n)))})};var _=a(7677),b=a(3776),w=a(74),j=a(641),v=a(5221);const N=()=>{const{getBlockInsertionPoint:e}=(0,l.useSelect)((e=>e("core/block-editor")),[]),{toggleBlockHighlight:t,showInsertionPoint:a,hideInsertionPoint:n}=(0,l.useDispatch)("core/block-editor");return{toggleHighlight:(e,{isHighlighted:a})=>{t(e[0],a)},toggleInsertionPoint:({isVisible:t})=>{if(!t)return void n();const{rootClientId:i,index:s}=e();a(i,s)}}},k=()=>{const{getSelectedBlockClientIds:e,getBlocksByClientId:t}=(0,l.useSelect)((e=>e(n.store)),[]),a=e();return{selectedText:(0,o.useCallback)((()=>{const e=t(a);return e?.filter(Boolean)?.map((({attributes:e})=>e.content))?.join("\n\n")}),[t,a])()}},C=(0,p.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,p.jsx)("path",{d:"M17.0909 9.81818L18 7.81818L20 6.90909L18 6L17.0909 4L16.1818 6L14.1818 6.90909L16.1818 7.81818L17.0909 9.81818Z",fill:"currentColor"}),(0,p.jsx)("path",{d:"M17.0909 14.1818L16.1818 16.1818L14.1818 17.0909L16.1818 18L17.0909 20L18 18L20 17.0909L18 16.1818L17.0909 14.1818Z",fill:"currentColor"}),(0,p.jsx)("path",{d:"M11.6364 10.1818L9.81818 6.18182L8 10.1818L4 12L8 13.8182L9.81818 17.8182L11.6364 13.8182L15.6364 12L11.6364 10.1818ZM10.5382 12.72L9.81818 14.3055L9.09818 12.72L7.51273 12L9.09818 11.28L9.81818 9.69455L10.5382 11.28L12.1236 12L10.5382 12.72Z",fill:"currentColor"})]}),I=(0,p.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",children:(0,p.jsx)(s.Path,{d:"M4 10.5h16V9H4v1.5ZM4 15h9v-1.5H4V15Z"})}),S=({disabled:e,setPrompt:t})=>{const{toggleHighlight:a}=N(),{selectedText:n}=k(),i=(0,l.useSelect)((e=>e("core/block-editor").getSelectedBlockClientIds()),[]);(0,o.useEffect)((()=>()=>{a(i,{isHighlighted:!1})}),[i,a]);const r=[{label:(0,d.__)("Improve writing","extendify-local"),promptType:"improve-writing",systemMessageKey:"edit",icon:(0,p.jsx)(_.A,{icon:b.A})},{label:(0,d.__)("Fix spelling & grammar","extendify-local"),promptType:"fix-spelling-grammar",icon:(0,p.jsx)(_.A,{icon:w.A})},{label:(0,d.__)("Simplify language","extendify-local"),promptType:"simplify-language",icon:(0,p.jsx)(_.A,{icon:j.A})},{label:(0,d.__)("Make shorter","extendify-local"),promptType:"make-shorter",icon:(0,p.jsx)(_.A,{icon:I})},{label:(0,d.__)("Make longer","extendify-local"),promptType:"make-longer",icon:(0,p.jsx)(_.A,{icon:v.A})}];return(0,p.jsx)(s.MenuGroup,{children:r.map((({label:l,promptType:r,icon:o})=>(0,p.jsx)(s.MenuItem,{onClick:()=>(e=>{t({text:n,promptType:e,systemMessageKey:"edit"})})(r),onMouseEnter:()=>a(i,{isHighlighted:!0}),onMouseLeave:()=>a(i,{isHighlighted:!1}),icon:o,iconPosition:"left",disabled:e,className:"group",children:(0,p.jsx)("span",{className:"whitespace-normal text-left rtl:text-right",children:l})},`${r}-${r}-edit`)))})};var A=a(7406),T=a(2809),P=a(6942),B=a.n(P),M=a(6221),E=a(9179);const L=({value:e,className:t,onChange:a,onKeyDown:n,disabled:i,placeholder:s})=>{const l=(0,o.useRef)(null),[r,c]=(0,o.useState)("auto");return(0,o.useLayoutEffect)((()=>{const t=document.createElement("textarea");t.value=e||s,t.rows=1;const a=window.getComputedStyle(l.current);["paddingTop","paddingBottom","paddingLeft","paddingRight","width","fontFamily","fontSize","borderWidth"].forEach((e=>t.style[e]=a[e])),Object.assign(t.style,{position:"absolute",left:"-9999px"}),document.body.appendChild(t),c(`${t.scrollHeight}px`),document.body.removeChild(t)}),[e,s]),(0,o.useEffect)((()=>{const e=l.current;if(!e)return;if(document.activeElement===e)return;const t=e.value.length;e.focus(),e.setSelectionRange(t,t)}),[e]),(0,p.jsx)(M.N,{children:(0,p.jsxs)(E.P.div,{className:"m-0.5 w-full",animate:{height:r},transition:{duration:.2},style:{lineHeight:0},children:[(0,p.jsx)("label",{htmlFor:"draft-ai-textarea",className:"sr-only",children:s}),(0,p.jsx)("textarea",{ref:l,id:"draft-ai-textarea",disabled:i,className:t,value:e,rows:1,onChange:a,onKeyDown:n,onScroll:e=>{e.target.scrollTop=0},placeholder:s})]},"input")})},D=({inputText:e,setInputText:t,ready:a,setReady:n,setPrompt:i,loading:l})=>{const{selectedText:r}=k(),o=s=>{s.preventDefault(),a&&!l&&(t(""),n(!1),i({text:r||e,promptType:r?"custom-requests":"create",systemMessageKey:r?"edit":"generate",details:{followup:r?e:void 0}}))};return(0,p.jsxs)("form",{className:"relative flex items-start",onSubmit:o,children:[(0,p.jsx)(_.A,{icon:C,className:"absolute left-2 top-3.5 h-5 w-5 fill-current text-wp-theme-main rtl:left-auto rtl:right-2"}),(0,p.jsx)(L,{disabled:l,placeholder:l?(0,d.__)("AI is writing...","extendify-local"):r?(0,d.__)("Ask AI to edit","extendify-local"):(0,d.__)("Ask AI to generate text","extendify-local"),value:e,className:"h-full w-full resize-none overflow-hidden rounded-none border-transparent bg-transparent px-10 py-3 outline-none focus:ring-1 focus:ring-wp-theme-main",onChange:e=>{t(e.target.value),n(e.target.value.length>0)},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),o(e))}}),l&&(0,p.jsx)("div",{className:"absolute right-4 top-3.5 h-4 w-4 p-1 text-gray-700 rtl:left-4 rtl:right-auto",children:(0,p.jsx)(s.Spinner,{style:{margin:"0"}})}),!l&&(0,p.jsx)("button",{type:"submit",disabled:!a,"aria-label":(0,d.__)("Submit","extendify-local"),className:B()("absolute right-2 top-3.5 border-none bg-transparent p-0 rtl:left-2 rtl:right-auto",{"text-gray-700 hover:text-design-main":a,"text-gray-500":!a}),children:(0,p.jsx)(_.A,{icon:(0,d.isRTL)()?A.A:T.A,onClick:o,className:"h-6 w-6 fill-current"})})]})};var F=a(3519),R=a(5020),G=a(4485),O=a(4848),H=a(5730);const z=({prompt:e,completion:t,loading:a,setPrompt:r,setInputText:c})=>{const{toggleHighlight:m,toggleInsertionPoint:u}=N(),{insertBlocks:g,replaceBlocks:x}=(0,l.useDispatch)(n.store),{getSelectedBlock:f,getSelectedBlockClientIds:h,getBlockRootClientId:y,getBlockIndex:b,getBlock:w}=(0,l.useSelect)((e=>e(n.store)),[]),j=f(),v=h(),k=e=>{const t=(0,i.pasteHandler)({plainText:e});return Array.isArray(t)?t:[(0,i.createBlock)("core/paragraph",{content:t})]},C=async({replaceContent:e=!1,position:a})=>{r({text:"",promptType:"",systemMessageKey:""});const n=j?j?.clientId:v[0],i=w(n),s=(0,l.select)("core/preferences").get("core","renderingModes")||{},o=(0,l.select)("core").getCurrentTheme()?.stylesheet,c="template-locked"===s?.[o]?.page,{set:d}=(0,l.dispatch)("core/preferences"),m=e=>d("core","renderingModes",{...s,[o]:{...s[o]||{},page:e}}),u=k(t);try{if(!n||"end"===a)return c&&(m("post-only"),await new Promise((e=>requestAnimationFrame(e)))),void g(u);if("top"===a)return c&&(m("post-only"),await new Promise((e=>requestAnimationFrame(e)))),void g(u,0)}finally{c&&m("template-locked")}const p=""===i?.attributes?.content,f=y(n),h=b(v.at(-1),f);if(!e&&!p)return void g(u,h+1,f);const _=(e,t)=>Object.prototype.hasOwnProperty.call(e?.attributes,"content")&&Object.prototype.hasOwnProperty.call(t?.attributes,"content"),N=1===u.length&&_(i,u[0]),C=u.map((e=>({...e,name:N?i.name:e.name,attributes:{...i.attributes,content:(_(e,i),e?.attributes?.content)}})));x(v,C)};return(0,o.useEffect)((()=>()=>{m(v,{isHighlighted:!1})}),[v,m]),(0,p.jsxs)(s.MenuGroup,{children:[(0,p.jsx)(s.MenuItem,{onClick:()=>C({replaceContent:!0}),onMouseEnter:()=>m(v,{isHighlighted:!0}),onMouseLeave:()=>m(v,{isHighlighted:!1}),disabled:a||!(()=>{const e=j||w(v[0]);if(!e)return!1;if(["core/list-item","core/button"].includes(e?.name)){const a=k(t);return a[0]?.name===e?.name}return!0})(),icon:F.A,iconPosition:"left","data-test":"replace-selected",className:"h-auto min-h-10 items-start",children:(0,p.jsx)("span",{className:"whitespace-normal break-words text-start",children:(0,d.__)("Replace selected block text","extendify-local")})}),(0,p.jsxs)(s.MenuItem,{onClick:()=>C({replaceContent:!1,position:"top"}),disabled:a,iconPosition:"left","data-test":"insert-top",className:"h-auto min-h-10 items-start",children:[(0,p.jsx)("div",{className:(0,d.isRTL)()?"-mr-1":"-ml-1",children:(0,p.jsx)(_.A,{icon:R.A,className:"rotate-180"})}),(0,p.jsx)("div",{className:"whitespace-normal break-words px-1 text-start",children:(0,d.__)("Insert at top","extendify-local")})]}),(0,p.jsx)(s.MenuItem,{onClick:()=>C({replaceContent:!1}),onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),disabled:a||!(()=>{const e=j||w(v[0]);return!e||!["core/list-item","core/button"].includes(e?.name)})(),icon:G.A,iconPosition:"left","data-test":"insert-after",className:"h-auto min-h-10 items-start",children:(0,p.jsx)("span",{className:"whitespace-normal break-words text-start",children:(0,d.__)("Insert after the selected text","extendify-local")})}),(0,p.jsx)(s.MenuItem,{onClick:()=>C({replaceContent:!1,position:"end"}),disabled:a,icon:R.A,iconPosition:"left","data-test":"insert-bottom",children:(0,d.__)("Insert at bottom","extendify-local")}),(0,p.jsx)(s.__experimentalDivider,{}),(0,p.jsx)(s.MenuItem,{onClick:()=>{c(""),r({text:"",promptType:"",systemMessageKey:""}),setTimeout((()=>r(e)))},disabled:a,icon:O.A,iconPosition:"left","data-test":"try-again-button",children:(0,d.__)("Try again","extendify-local")}),(0,p.jsx)(s.MenuItem,{onClick:()=>{c(""),r({text:"",promptType:"",systemMessageKey:""})},disabled:a,icon:H.A,iconPosition:"left","data-test":"discard-button",children:(0,d.__)("Discard","extendify-local")})]})};var K=a(3803);const q=({loading:e})=>{const[t,a]=(0,o.useState)(),{clearSelectedBlock:i}=(0,l.useDispatch)(n.store),{selectedText:r}=k();if((0,o.useEffect)((()=>{a(r)}),[a,r]),t)return(0,p.jsxs)("div",{className:"mb-4 flex space-x-2 overflow-hidden rounded-sm border-none bg-gray-100 p-3","data-test":"existing-text-container",children:[(0,p.jsx)("div",{children:(0,p.jsx)(_.A,{icon:K.A,className:"fill-current"})}),(0,p.jsxs)("div",{children:[(0,p.jsx)("div",{className:"mb-1 hyphens-auto text-pretty text-gray-800",dangerouslySetInnerHTML:{__html:t.split(" ").length<=20?t:`${t.split(" ",14).join(" ")}... ${t.slice(t.lastIndexOf(" ")-14)}`}}),(0,p.jsx)("div",{className:"mt-3 flex w-full justify-end",children:(0,p.jsx)(s.Button,{size:"compact",onClick:i,disabled:e,icon:H.A,iconPosition:(0,d.isRTL)()?"right":"left",className:"relative flex-row-reverse rounded bg-gray-300 text-gray-800 hover:bg-gray-400","data-test":"remove-selection",children:(0,d.__)("Remove selection","extendify-local")})})]})]})};var $=a(8969),U=a(1455),V=a.n(U),Z=a(6528),W=a(1621),Y=a(7134);const J="/extendify/v1/draft/user-settings",X={getItem:async()=>await V()({path:J}),setItem:async(e,t)=>await V()({path:J,method:"POST",data:{state:t}})},Q={aiImageOptions:{prompt:"",size:"1024x1024"},imageCredits:{remaining:10,total:10,refresh:void 0}},ee=(0,Y.lt)((e=>({...Q,...(0,Z.N)(window.extDraftData?.globalState)?.state,updateImageCredits({remaining:t,total:a,refresh:n}){e((e=>({imageCredits:{...e.imageCredits,...t&&{remaining:t},...a&&{total:a},...n&&{refresh:n}}})))},subtractOneCredit(){e((e=>({imageCredits:{...e.imageCredits,remaining:e.imageCredits.remaining-1,refresh:new Date(Date.now()+864e5).getTime()}})))},resetImageCredits(){e({imageCredits:Q.imageCredits})},setAiImageOption(t,a){e((e=>({aiImageOptions:{...e.aiImageOptions,[t]:a}})))}})),{name:"Extendify Draft Globals"}),te=(0,Y.Zr)(ee,{name:"extendify_draft_settings",storage:(0,Y.KU)((()=>X)),skipHydration:!0,partialize:e=>({...e,aiImageOptions:{...e.aiImageOptions,prompt:""}})}),ae=(0,W.vt)(te),ne=["siteId","partnerId","wpVersion","wpLanguage","devbuild","isBlockTheme","userId","siteProfile"],{showAIConsent:ie,userGaveConsent:se}=g.D.getState(),le={...Object.fromEntries(Object.entries(window.extSharedData).filter((([e])=>ne.includes(e)))),showAIConsent:ie,userGaveConsent:se};var re=a(1077);const oe=(0,p.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",children:(0,p.jsx)("path",{fillRule:"evenodd",d:"M1.33333 1h9.33337c.1841 0 .3333.14924.3333.33333v5.57118L9.0152 4.97484c-.19406-.18867-.50302-.18867-.69708 0L5.93734 7.28948 3.98622 6.02487c-.17383-.11267-.39915-.10648-.56653.01557L1 7.8048V1.33333C1 1.14924 1.14924 1 1.33333 1ZM1 9.04241v1.62429c0 .1841.14924.3333.33333.3333h9.33337c.1841 0 .3333-.1492.3333-.3333V8.26877l-.0152.01565-2.31814-2.25373-2.31813 2.25373c-.16726.16261-.42473.18796-.62049.06108L3.73095 7.05109 1 9.04241ZM0 1.33333C0 .596954.596954 0 1.33333 0h9.33337C11.403 0 12 .596954 12 1.33333v9.33337C12 11.403 11.403 12 10.6667 12H1.33333C.596954 12 0 11.403 0 10.6667V1.33333Z",clipRule:"evenodd"})}),ce=({usedCredits:e,total:t})=>e<t?(0,p.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,p.jsx)(s.Icon,{className:"fill-gray-700",icon:oe,size:"12px"}),(0,p.jsx)("p",{className:"mb-0 text-[12px] text-gray-700",children:(0,d.sprintf)(
// translators: %1$s is the number of used credits, %2$s is the total credits
// translators: %1$s is the number of used credits, %2$s is the total credits
(0,d.__)("%1$s of %2$s daily image credits used","extendify-local"),e,t)})]}):(0,p.jsxs)("div",{className:"flex gap-3 border-y-0 border-l-4 border-r-0 border-solid border-[#3858E9] bg-gray-100 p-3",children:[(0,p.jsx)("div",{children:(0,p.jsx)(s.Icon,{icon:oe,className:"fill-gray-900",size:"12px"})}),(0,p.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,p.jsx)("p",{className:"mb-0 text-[12px] font-bold text-gray-700",children:(0,d.sprintf)(
// translators: %1$s is the number of used credits, %2$s is the total credits
// translators: %1$s is the number of used credits, %2$s is the total credits
(0,d.__)("%1$s of %2$s daily image credits used","extendify-local"),e,t)}),(0,p.jsx)("p",{className:"mb-0 text-gray-900",children:(0,d.__)("You can still explore and find great images on Unsplash until your credits reset.","extendify-local")}),(0,p.jsx)(s.Button,{href:"https://unsplash.com/",variant:"primary",target:"_blank",className:"justify-center text-center",children:(0,d.__)("Search on Unsplash","extendify-local")})]})]}),de=({isGenerating:e,errorMessage:t})=>{const{imageCredits:a,resetImageCredits:n,aiImageOptions:i,setAiImageOption:l}=ae(),r=a.total-a.remaining,[c,m]=(0,o.useState)(0),{size:u,prompt:g}=i;return(0,o.useEffect)((()=>{const e=()=>{m((e=>e+1)),a.refresh&&(new Date(Number(a.refresh))>new Date||n())};0===c&&e();const t=setTimeout(e,1e3);return()=>clearTimeout(t)}),[a,n,c]),(0,p.jsxs)(p.Fragment,{children:[e?null:(0,p.jsxs)("div",{children:[(0,p.jsx)(s.TextareaControl,{id:"draft-ai-image-textarea",autoFocus:!0,placeholder:(0,d.__)("Tell AI about the image you would like to create","extendify-local"),label:(0,d.__)("Image Prompt","extendify-local"),hideLabelFromVision:!0,rows:"7",value:g,onChange:e=>l("prompt",e)}),(0,p.jsxs)(s.__experimentalToggleGroupControl,{isBlock:!0,label:(0,d.__)("Aspect Ratio","extendify-local"),onChange:e=>l("size",e),value:u,children:[(0,p.jsx)(s.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:ge,label:(0,d.__)("Square: 1:1","extendify-local"),value:"1024x1024"}),(0,p.jsx)(s.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:me,label:(0,d.__)("Landscape: 4:3","extendify-local"),value:"1536x1024"}),(0,p.jsx)(s.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:ue,label:(0,d.__)("Portrait: 3:4","extendify-local"),value:"1024x1536"})]})]}),t.length>0&&(0,p.jsx)("p",{className:"mb-0 text-red-500",children:t}),(0,p.jsx)(s.Button,{type:"submit",className:"w-full justify-center",variant:"primary",__next40pxDefaultSize:!0,disabled:e||!g||r>=a.total,children:e?(0,d.__)("Generating image...","extendify-local"):(0,d.__)("Generate image","extendify-local")}),e?null:(0,p.jsx)(ce,{usedCredits:r,total:a.total})]})},me=(0,p.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"7px 4px"},children:(0,p.jsx)("path",{fillRule:"evenodd",d:"M0 1c0-.552285.447715-1 1-1h14c.5523 0 1 .447715 1 1v8c0 .55228-.4477 1-1 1H1c-.552285 0-1-.44772-1-1V1Z",clipRule:"evenodd"})}),ue=(0,p.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"4px 6px"},children:(0,p.jsx)("path",{fillRule:"evenodd",d:"M9.66669 3.5e-7C10.219 3.7e-7 10.6667.447716 10.6667 1v14c0 .5523-.4477 1-1.00001 1h-8c-.55229 0-1.000003-.4477-1.000003-1L.666688 1C.666688.447715 1.1144-2e-8 1.66669 0l8 3.5e-7Z",clipRule:"evenodd"})}),ge=(0,p.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"6px"},children:(0,p.jsx)("path",{fillRule:"evenodd",d:"M11.3333-4e-8c.5523 2e-8 1 .44771504 1 1.00000004v10c0 .5523-.4477 1-1 1H1.33333c-.552283 0-.999998-.4477-.999998-1V.999999C.333332.447715.781047-5e-7 1.33333-4.8e-7L11.3333-4e-8Z",clipRule:"evenodd"})}),pe=e=>new Promise(((t,a)=>{e.onload=()=>t(e),e.onerror=e=>a(e)})),xe=async(e,t,a,n,i={alt:"",caption:""})=>{let s;await((e,t,a={})=>fetch(`${$.AY}/api/draft/image/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,source:t,...a})}))(e,a,{unsplashId:n});try{s=await(async(e,t={})=>{var a,n;const i=new Image;i.src=e,i.crossOrigin="anonymous",await pe(i);const s=document.createElement("canvas");s.width=i.width,s.height=i.height;const l=s.getContext("2d");if(!l)return;l.drawImage(i,0,0);const r=await new Promise((e=>{s.toBlob((t=>{t&&e(t)}),"image/jpeg")})),o=new FormData;return o.append("file",new File([r],t.filename)),o.append("alt_text",null!==(a=t.alt)&&void 0!==a?a:""),o.append("caption",null!==(n=t.caption)&&void 0!==n?n:""),o.append("status","publish"),await V()({path:"wp/v2/media",method:"POST",body:o})})(t,{alt:i.alt,filename:"image.jpg",caption:i.caption})}catch(e){s=await(async(e,t={})=>{var a,n;const i=new FormData;return i.append("source",e),i.append("alt_text",null!==(a=t.alt)&&void 0!==a?a:""),i.append("caption",null!==(n=t.caption)&&void 0!==n?n:""),await V()({path:"/extendify/v1/draft/upload-image",method:"POST",body:i})})(t,{alt:i.alt,filename:"image.jpg",caption:i.caption})}return s},fe=(e,t,a)=>{if("core/image"===e.name&&a(e.clientId,{id:t.id,caption:t.caption.raw,url:t.source_url,alt:t.alt_text}),"core/media-text"===e.name&&a(e.clientId,{mediaId:t.id,caption:t.caption.raw,mediaUrl:t.source_url,mediaAlt:t.alt_text,mediaType:"image"}),"core/gallery"===e.name){const a=(0,i.createBlock)("core/image",{id:t.id,caption:t.caption.raw,url:t.source_url,alt:t.alt_text});(0,i.insertBlock)(a,null,e.clientId)}"core/cover"===e.name&&a(e.clientId,{id:t.id,url:t.source_url,alt:t.alt_text})},he=({prompt:e,size:t,isGenerating:a,id:i,src:c,clearImageResponse:m})=>{const{openGeneralSidebar:u}=(0,l.useDispatch)(r.store),{updateBlockAttributes:g}=(0,l.useDispatch)(n.store),[x,f]=(0,o.useState)(!1),h=(0,l.useSelect)((e=>e(n.store).getSelectedBlock()),[]),[y,_]=t.split("x");return""!==c||a?(0,p.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,p.jsx)(M.N,{children:a?(0,p.jsx)(E.P.div,{initial:{opacity:1},exit:{opacity:0},className:"flex aspect-square w-full items-center justify-center",style:{background:"linear-gradient(135deg, #E8E8E8 47.92%, #F3F3F3 60.42%, #E8E8E8 72.92%)"},children:(0,p.jsx)(s.Spinner,{style:{height:"48px",width:"48px"}})}):(0,p.jsx)(E.P.div,{initial:{opacity:0},animate:{opacity:1},className:"bg-gray-100",style:{aspectRatio:Number(y)/Number(_)},children:(0,p.jsx)("img",{alt:e,src:c,className:"block w-full",style:{aspectRatio:Number(y)/Number(_)}})})}),a?(0,p.jsxs)("p",{children:[(0,d.__)("Generating your image: ","extendify-local"),(0,p.jsxs)("span",{className:"font-bold",children:['"',e,'"']})]}):(0,p.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),f(!0);const t=await xe(i,c,"ai-generated");t&&(await fe(h,t,g),f(!1),u("edit-post/block"),m())},className:"flex flex-col gap-5",children:[(0,p.jsx)(s.Button,{type:"submit",autoFocus:!0,className:"w-full justify-center",variant:"primary",disabled:x,children:x?
// translators: "Importing image" means the image is being added to the WordPress post editor
// translators: "Importing image" means the image is being added to the WordPress post editor
(0,d.__)("Importing image...","extendify-local"):(0,d.__)("Use this image","extendify-local")}),(0,p.jsx)(s.Button,{className:"w-full justify-center bg-gray-200 text-gray-800 disabled:bg-gray-300 disabled:text-gray-700",onClick:m,disabled:x,children:(0,d.__)("Delete image","extendify-local")})]})]}):null},ye=(0,p.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"8",height:"12",fill:"none",children:(0,p.jsx)("path",{fill:"#1E1E1E",fillRule:"evenodd",d:"M6.445 12.004.986 6l5.46-6.005 1.109 1.01L3.014 6l4.541 4.995-1.11 1.01Z",clipRule:"evenodd"})}),_e=(be=e=>({imageDetails:{src:"",id:void 0},setImageDetails:t=>{e((e=>({...e,imageDetails:t})))}}),(0,W.vt)((0,Y.lt)(be,{name:"Extendify Draft AI Image"})));var be;const we=[{slug:"ai-image",title:(0,d.__)("AI Image","extendify-local"),component:()=>{const{imageCredits:e,updateImageCredits:t,subtractOneCredit:a,aiImageOptions:n}=ae(),[i,l]=(0,o.useState)(!1),[r,c]=(0,o.useState)(""),m=(0,o.useRef)(null),u=0===e.remaining,{imageDetails:g,setImageDetails:x}=_e(),{goBack:f}=Be();return(0,o.useEffect)((()=>{g.src||i||document.getElementById("draft-ai-image-textarea")?.focus()}),[g.src,i]),(0,p.jsxs)(s.Panel,{children:[(0,p.jsxs)("div",{className:"flex h-12 items-center gap-1 pl-1",children:[(0,p.jsx)("button",{className:"h-9 w-9 border-0 bg-transparent",onClick:f,type:"button","aria-label":(0,d.__)("Go Back","extendify-local"),children:ye}),(0,p.jsx)(s.__experimentalHeading,{className:"mb-0",children:(0,d.__)("AI Image Generator","extendify-local")})]}),(0,p.jsx)(s.PanelBody,{className:"-mt-4 border-t-0",children:(0,p.jsxs)(s.BaseControl,{label:(0,d.__)("Image Description","extendify-local"),children:[(0,p.jsx)(he,{prompt:n.prompt,size:n.size,isGenerating:i,id:g?.id,src:g?.src,clearImageResponse:()=>x({src:"",id:void 0})}),g.src?null:(0,p.jsx)("form",{onSubmit:async i=>{if(i.preventDefault(),c(""),u)m.current?.abort();else try{l(!0),a(),m.current=new AbortController;const{imageCredits:e,images:i,id:s}=await(async(e,t)=>{const a=await fetch(`${$.AY}/api/draft/image`,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},signal:t,body:JSON.stringify({...e,globalState:ae.getState(),...le})}),n=await a.json(),i={remaining:a.headers.get("x-ratelimit-remaining"),total:a.headers.get("x-ratelimit-limit"),refresh:a.headers.get("x-ratelimit-reset")};if(!a.ok){if(n.status&&"content-policy-violation"===n.status)throw{message:(0,d.__)("Your request was rejected as a result of our safety system. Your prompt may contain text that is not allowed by our safety system.","extendify-local"),imageCredits:i};throw{message:(0,d.__)("Service temporarily unavailable","extendify-local"),imageCredits:i}}return{images:n,imageCredits:i,id:a.headers.get("x-request-id")}})(n,m.current.signal);t(e),x({src:i[0].url,id:s})}catch(a){if(20===a?.code)return;if(!a?.imageCredits)return await new Promise((e=>setTimeout(e,1e3))),c(a.message),void t({remaining:e.remaining});t(a.imageCredits),c(a.message)}finally{l(!1)}},className:"flex flex-col gap-5",children:(0,p.jsx)(de,{isGenerating:i,errorMessage:r})})]})})]})}}],je=[{slug:"home",title:(0,d.__)("Home","extendify-local"),component:()=>{const{navigateTo:e}=Be();return(0,p.jsxs)(s.PanelBody,{children:[(0,p.jsx)(s.BaseControl,{id:"extendify-draft-image-gen",label:(0,d.__)("AI Image Generator","extendify-local"),help:(0,d.__)("Use AI to generate custom images based on your description.","extendify-local"),children:(0,p.jsx)(s.Button,{variant:"primary",__next40pxDefaultSize:!0,id:"extendify-draft-image-gen-button",className:"w-full justify-center",onClick:()=>e("ai-image"),children:(0,d.__)("Generate an image","extendify-local")})}),(0,p.jsx)(s.__experimentalSpacer,{marginY:"5"}),(0,p.jsx)(s.__experimentalDivider,{}),(0,p.jsx)(s.BaseControl,{id:"extendify-draft-image-stock-photos",label:(0,d.__)("Discover Stock Photos","extendify-local"),help:(0,d.__)("Search and add free stock photos from Unsplash.com","extendify-local"),children:(0,p.jsx)(s.Button,{variant:"primary",className:"h-auto min-h-10 w-full justify-center whitespace-normal break-words py-2.5",onClick:()=>e("unsplash"),children:(0,d.__)("Search Unsplash","extendify-local")})})]})}}],ve=({image:e,skeletonHeight:t,isInsertingImage:a,onClick:n})=>{const[i,l]=(0,o.useState)(""),[r,c]=(0,o.useState)(!1),d=e?.width?Number(e?.width)/Number(e?.height):122/t;return(0,o.useEffect)((()=>{if(!e?.user?.links?.html)return void l("");const t=new URL(e.user.links.html);t.searchParams.set("utm_source","extendify"),t.searchParams.set("utm_medium","referral"),l(t.toString())}),[e]),(0,o.useInsertionEffect)((()=>{if(!e?.urls||r)return;const t=new Image;t.src=e.urls.thumb||e.urls.small,pe(t).then((()=>c(!0)))}),[e,r]),(0,p.jsxs)(E.P.div,{className:"relative mb-1",initial:{aspectRatio:d},animate:{aspectRatio:d},children:[(0,p.jsx)(M.N,{children:r?null:(0,p.jsx)(E.P.div,{className:"absolute inset-0 z-10 bg-white",initial:{opacity:1},animate:{opacity:1},exit:{opacity:0},children:(0,p.jsx)("div",{className:"animate-pulse absolute inset-0 z-10 bg-gray-150"})})}),(0,p.jsxs)("div",{className:"group relative",children:[(0,p.jsxs)("button",{type:"button",className:B()("relative block border-0 p-0",{"bg-transparent":!a,"bg-black":a}),onClick:()=>n(e),disabled:a,children:[a&&a?.id===e?.id&&(0,p.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,p.jsx)(s.Spinner,{style:{height:"24px",width:"24px"}})}),(0,p.jsx)("img",{src:e?.urls?.thumb||e?.urls?.small,className:B()("block transition-opacity duration-300",{"opacity-50":a}),alt:e?.alt_description})]}),e?.user?.name&&i?(0,p.jsx)("a",{href:i,target:"_blank",className:B()("absolute bottom-1 bg-black/70 px-1 text-white no-underline opacity-0",{"group-focus-within:opacity-100 group-hover:opacity-100":!a}),children:`${e.user?.name}`}):null]})]})},Ne=({images:e,isInsertingImage:t,onClick:a,loading:n})=>{var i;const s=null!==(i=e?.length)&&void 0!==i?i:10;return n||e.length?(0,p.jsx)("div",{className:"columns-2 gap-1",children:Array.from({length:s}).map(((n,i)=>{var s;const l=[150,175,200];return(0,p.jsx)(ve,{image:e?.[i],skeletonHeight:l[i%l.length],isInsertingImage:t,onClick:a},null!==(s=e?.[i]?.id)&&void 0!==s?s:i)}))}):(0,d.__)("No images found.","extendify-local")};var ke=a(9358),Ce=a(8455),Ie=a(4225);const Se=[...je,...we,{slug:"unsplash",title:(0,d.__)("Unsplash","extendify-local"),component:()=>{const{goBack:e}=Be(),[t,a]=(0,o.useState)(""),[i,r]=(0,o.useState)(""),[c,m]=(0,o.useState)(!1),{data:u,loading:g}=((e,t=null)=>{const a=e||"unsplash",{data:n,error:i}=(0,Ie.A)(a,(()=>(async(e,t=null)=>{const a=Ce.f.getState();return"unsplash"!==e||a.isEmpty()||a.hasExpired()?await(0,ke.P)(e,t):a.images})(a,t)));return{data:n,error:i,loading:!n&&!i}})(i,"user"),[x,f]=(0,o.useState)(null),h=(0,l.useSelect)((e=>e(n.store).getSelectedBlock()),[]),{updateBlockAttributes:y}=(0,l.useDispatch)(n.store);return(0,o.useEffect)((()=>{m(!1)}),[i]),(0,o.useEffect)((()=>{if(!t)return r("");const e=setTimeout((()=>r(t)),750);return()=>clearTimeout(e)}),[t]),(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)("div",{className:"flex h-12 items-center gap-1 pl-1",children:[(0,p.jsx)("button",{className:"h-9 w-9 border-0 bg-transparent",onClick:e,type:"button","aria-label":(0,d.__)("Go Back","extendify-local"),children:ye}),(0,p.jsx)(s.__experimentalHeading,{className:"mb-0",children:(0,d.__)("Photos from Unsplash","extendify-local")})]}),(0,p.jsx)(s.__experimentalDivider,{className:"my-0 border-gray-150"}),(0,p.jsxs)("div",{className:"flex flex-col gap-2 p-4",children:[(0,p.jsx)(s.SearchControl,{autoFocus:!0,className:B()({"pointer-events-none bg-gray-150 opacity-50":x}),disabled:x,"aria-disabled":x,onChange:e=>{x||a(e)},value:t}),(0,p.jsx)(Ne,{images:u,isInsertingImage:x,onClick:async e=>{if(!x){f(e);try{const t=await xe(e.requestMetadata?.id,e.urls?.regular,"unsplash",e.id);fe(h,t,y)}catch(e){console.log(e)}finally{f(null)}}},loading:g||c})]})]})}}],Ae="/extendify/v1/draft/router-data",Te={getItem:async()=>await V()({path:Ae}),setItem:async(e,t)=>await V()({path:Ae,method:"POST",data:{state:t}})},Pe=(0,W.vt)((0,Y.Zr)((0,Y.lt)(((e,t)=>({history:[],viewedPages:[],current:null,goBack:()=>{if(t().history.length<2)return;const a=t().history[1];re.e.getState().incrementActivity(`draft-${a.slug}-back`),e((e=>({history:e.history.slice(1),current:a})))},setCurrent:a=>{a&&t().history[0]?.slug!==a.slug&&e((e=>{const t=(new Date).toISOString(),n=t,i=e.viewedPages.find((e=>e.slug===a.slug));return{history:[a,...e.history].filter(Boolean),current:a,viewedPages:[...e.viewedPages.filter((e=>e.slug!==a.slug)),i?{...i,count:i.count+1,lastViewedAt:t}:{slug:a.slug,firstViewedAt:n,lastViewedAt:t,count:1}]}}))}})),{name:"Extendify Draft Router"}),{name:"extendify-draft-router",storage:(0,Y.KU)((()=>Te)),skipHydration:!0,partialize:({viewedPages:e})=>({viewedPages:e})})),Be=()=>{var e;const{current:t,setCurrent:a,history:n,goBack:i}=Pe(),s=null!==(e=t?.component)&&void 0!==e?e:()=>null;return(0,o.useEffect)((()=>{t||a(Se[0])}),[t,a]),{current:t,CurrentPage:(0,o.useCallback)((()=>(0,p.jsxs)("div",{role:"region","aria-live":"polite",className:"h-full",children:[(0,p.jsx)("h1",{className:"sr-only",children:t?.title}),(0,p.jsx)(s,{})]})),[t]),navigateTo:e=>{const t=Se.find((t=>t.slug===e));if(!t)return a(Se[0]);re.e.getState().incrementActivity(`draft-${t.slug}`),a(t)},goBack:i,history:n}},Me=()=>{var e;const{selectedText:t}=k(),[a,i]=(0,o.useState)(""),[r,c]=(0,o.useState)(!1),[m,u]=(0,o.useState)({text:"",promptType:"",systemMessageKey:"",details:{}}),{completion:h,loading:_,error:b}=((e,t,a,n)=>{const[i,s]=(0,o.useState)(""),[l,r]=(0,o.useState)(null),[c,m]=(0,o.useState)(!1);return(0,o.useEffect)((()=>{let i,l=!1;const o=new TextDecoder;return e?((async()=>{s(""),r(!1),m(!0);const c=await(async(e,t,a,n)=>{const i=await fetch(`${$.AY}/api/draft/completion`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,promptType:t,systemMessageKey:a,details:n,globalState:ae.getState(),...le})});if(!i.ok)throw new Error((0,d.__)("Service temporarily unavailable","extendify-local"));return i})(e,t,a,n);i=c.body.getReader();let u=!1;for(;!u;){const{value:e,done:t}=await i.read();if(u=t,e&&!l){const t=o.decode(e);s((e=>e+t))}}})().finally((()=>{l||m(!1)})).catch((e=>{l||r(e)})),()=>{l=!0,i&&i.cancel()}):(m(!1),s(""),void(l=!0))}),[e,a,t,n]),{completion:i,error:l,loading:c}})(m.text,m.promptType,m.systemMessageKey,m.details),{selectedBlockClientIds:w,getBlock:j}=(0,l.useSelect)((e=>{const t=e(n.store);return{selectedBlockClientIds:t.getSelectedBlockClientIds(),getBlock:t.getBlock,getBlocks:t.getBlocks}}),[]),{CurrentPage:v}=Be(),N=(0,g.D)((e=>e.shouldShowAIConsent("draft")));(0,o.useEffect)((()=>{const e=e=>{N||u(e.detail)};return window.addEventListener("extendify-draft:set-prompt",e),()=>window.removeEventListener("extendify-draft:set-prompt",e)}),[N]),(0,o.useEffect)((()=>{b&&i(m.text)}),[b,m.text]);const C=()=>{if(0===w.length)return!1;const e=j(w[0]);return!!e&&void 0!==e?.attributes?.content&&""!==e?.attributes?.content};return N?(0,p.jsx)(f,{}):(()=>{if(0===w.length)return!1;const e=j(w[0]);return!!e&&["core/image","core/media-text","core/gallery","core/cover"].includes(e.name)})()?(0,p.jsx)(v,{}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(s.Panel,{children:(0,p.jsxs)(s.PanelBody,{children:[t&&(0,p.jsx)(q,{loading:_}),(0,p.jsxs)("div",{className:"mb-4 overflow-hidden rounded-sm border-none bg-gray-100",children:[!h&&(0,p.jsx)(D,{inputText:a,setInputText:i,ready:r,setReady:c,setPrompt:u,loading:_}),h&&(0,p.jsx)(x,{completion:h}),b&&(0,p.jsx)("div",{className:"mb-4 mt-2 px-4",children:(0,p.jsx)("p",{className:"m-0 text-xs font-semibold text-red-500",children:b.message})})]}),(h||_)&&!b&&(0,p.jsx)(z,{prompt:m,completion:h,setPrompt:u,setInputText:i,loading:_}),!_&&!h&&C()&&(0,p.jsx)(s.BaseControl,{children:(0,p.jsx)(S,{completion:h,disabled:_,setInputText:i,setPrompt:u})}),!_&&!h&&!C()&&(0,p.jsx)(s.BaseControl,{label:(0,d.__)("Suggested prompts","extendify-local"),children:(0,p.jsx)(y,{disabled:_,setInputText:i,setReady:c})})]})}),window.extSharedData?.devbuild&&(0,p.jsx)(s.Panel,{children:(0,p.jsxs)(s.PanelBody,{title:"Debug",initialOpen:!1,children:[(0,p.jsx)("label",{children:"prompt text:"}),(0,p.jsx)("pre",{className:"whitespace-pre-wrap",children:m.text}),(0,p.jsx)("label",{children:"prompt system message:"}),(0,p.jsx)("pre",{className:"whitespace-pre-wrap",children:m.systemMessageKey}),(0,p.jsx)("label",{children:"completion:"}),(0,p.jsx)("pre",{className:"whitespace-pre-wrap",children:h}),(0,p.jsx)("label",{children:"error:"}),(0,p.jsx)("pre",{className:"whitespace-pre-wrap",children:null!==(e=b?.message)&&void 0!==e?e:""}),(0,p.jsxs)("label",{children:["loading: ",_?(0,p.jsx)("span",{children:"true"}):(0,p.jsx)("span",{children:"false"})]})]})})]})};var Ee=a(7828);const Le=["core/image","core/media-text","core/gallery","core/cover"],De=()=>{const{openGeneralSidebar:e}=(0,l.useDispatch)(r.store);return(0,p.jsx)(s.MenuItem,{icon:C,onClick:async()=>{e("extendify-draft/draft"),await new Promise((e=>requestAnimationFrame(e)));const t=document.getElementById("extendify-draft-image-gen-button");t?.focus(),t?.classList.add("animate-pulse-flash")},children:(0,d.__)("Get Personalized Image","extendify-local")})},Fe=()=>{const{openGeneralSidebar:e}=(0,l.useDispatch)(r.store);return(0,p.jsx)(s.ToolbarGroup,{className:"extendify-draft",children:(0,p.jsx)(s.ToolbarButton,{className:"py-1.5 pl-2 pr-3 text-white before:bg-editor-main before:content-[''] hover:before:bg-editor-main-darker",icon:C,onClick:async()=>{e("extendify-draft/draft"),await new Promise((e=>requestAnimationFrame(e)));const t=document.getElementById("extendify-draft-image-gen-button");t?.focus(),t?.classList.add("animate-pulse-flash")},children:(0,d.__)("Ask AI","extendify-local")})})},Re=({name:e,attributes:t})=>((0,o.useEffect)((()=>{if(!Le.includes(e))return;let t,a,n,i,s;return(async()=>{await new Promise((e=>i=requestAnimationFrame(e)));const e=Array.from(document.querySelectorAll('[data-toolbar-item="true"]'))?.find((e=>e.textContent===(0,d.__)("Replace")||e.textContent===(0,d.__)("Add")));e&&(s=new MutationObserver((e=>{if("true"===e[0].target.getAttribute("aria-expanded")){const e=".block-editor-media-replace-flow__media-upload-menu",i=document.querySelector(e);if(!i)return;return t=document.createElement("div"),i.prepend(t),void(n=requestAnimationFrame((()=>{a=(0,Ee.X)((0,p.jsx)(De,{}),t)})))}cancelAnimationFrame(n),a?.unmount(),t?.remove()})),s.observe(e,{attributes:!0,childList:!1,subtree:!1}))})(),()=>{[n,i].forEach(cancelAnimationFrame),a?.unmount(),t?.remove(),s?.disconnect()}}),[e,t]),Le.includes(e)?(0,p.jsx)(Fe,{}):null);var Ge=a(2933),Oe=a(3988),He=a(6655);const ze=({text:e,closePopup:t,openDraft:a,updatePrompt:n})=>{const i=[{language:(0,d.__)("Arabic","extendify-local"),code:"ar",languageName:"Arabic"},{language:(0,d.__)("Arabic (Morocco)","extendify-local"),code:"ary",languageName:"Arabic (Morocco)"},{language:(0,d.__)("Bulgarian","extendify-local"),code:"bg_BG",languageName:"Bulgarian"},{language:(0,d.__)("Catalan","extendify-local"),code:"ca",languageName:"Catalan"},{language:(0,d.__)("Czech","extendify-local"),code:"cs_CZ",languageName:"Czech"},{language:(0,d.__)("Danish","extendify-local"),code:"da_DK",languageName:"Danish"},{language:(0,d.__)("Dutch","extendify-local"),code:"nl_NL",languageName:"Dutch"},{language:(0,d.__)("Dutch (Belgium)","extendify-local"),code:"de_BE",languageName:"Dutch (Belgium)"},{language:(0,d.__)("English","extendify-local"),code:"en",languageName:"English"},{language:(0,d.__)("English (UK)","extendify-local"),code:"en_GB",languageName:"English (UK)"},{language:(0,d.__)("Estonian","extendify-local"),code:"et",languageName:"Estonian"},{language:(0,d.__)("Finnish","extendify-local"),code:"fi",languageName:"Finnish"},{language:(0,d.__)("French (Belgium)","extendify-local"),code:"fr_BE",languageName:"French (Belgium)"},{language:(0,d.__)("French (Canada)","extendify-local"),code:"fr_CA",languageName:"French (Canada)"},{language:(0,d.__)("French (France)","extendify-local"),code:"fr_FR",languageName:"French (France)"},{language:(0,d.__)("German","extendify-local"),code:"de_DE",languageName:"German"},{language:(0,d.__)("German (Switzerland)","extendify-local"),code:"de_CH",languageName:"German (Switzerland)"},{language:(0,d.__)("Greek","extendify-local"),code:"el",languageName:"Greek"},{language:(0,d.__)("Hebrew","extendify-local"),code:"he_IL",languageName:"Hebrew"},{language:(0,d.__)("Hindi","extendify-local"),code:"hi_IN",languageName:"Hindi"},{language:(0,d.__)("Hungarian","extendify-local"),code:"hu_HU",languageName:"Hungarian"},{language:(0,d.__)("Indonesian","extendify-local"),code:"id_ID",languageName:"Indonesian"},{language:(0,d.__)("Italian","extendify-local"),code:"it_IT",languageName:"Italian"},{language:(0,d.__)("Japanese","extendify-local"),code:"jp",languageName:"Japanese"},{language:(0,d.__)("Lithuanian","extendify-local"),code:"lt_LT",languageName:"Lithuanian"},{language:(0,d.__)("Norwegian","extendify-local"),code:"nb_NO",languageName:"Norwegian"},{language:(0,d.__)("Polish","extendify-local"),code:"pl_PL",languageName:"Polish"},{language:(0,d.__)("Portuguese (Brazil)","extendify-local"),code:"pt_BR",languageName:"Portuguese (Brazil)"},{language:(0,d.__)("Portuguese (Portugal)","extendify-local"),code:"pt_PT",languageName:"Portuguese (Portugal)"},{language:(0,d.__)("Romanian","extendify-local"),code:"ro_RO",languageName:"Romanian"},{language:(0,d.__)("Russian","extendify-local"),code:"ru_RU",languageName:"Russian"},{language:(0,d.__)("Slovak","extendify-local"),code:"sk_SK",languageName:"Slovak"},{language:(0,d.__)("Spanish (Spain)","extendify-local"),code:"es_ES",languageName:"Spanish (Spain)"},{language:(0,d.__)("Spanish (Colombia)","extendify-local"),code:"es_CO",languageName:"Spanish (Colombia)"},{language:(0,d.__)("Spanish (Mexico)","extendify-local"),code:"es_MX",languageName:"Spanish (Mexico)"},{language:(0,d.__)("Swedish","extendify-local"),code:"sv_SE",languageName:"Swedish"},{language:(0,d.__)("Turkish","extendify-local"),code:"tr_TR",languageName:"Turkish"},{language:(0,d.__)("Ukrainian","extendify-local"),code:"uk",languageName:"Ukrainian"},{language:(0,d.__)("Vietnamese","extendify-local"),code:"vi",languageName:"Vietnamese"}];return(0,p.jsx)(s.Dropdown,{className:"my-container-class-name flex w-full items-center justify-between",contentClassName:"my-dropdown-content-classname",popoverProps:{placement:"right-start"},renderToggle:({isOpen:e,onToggle:t})=>(0,p.jsxs)("div",{className:"group flex w-full items-center justify-between hover:text-design-main",children:[(0,p.jsx)(s.MenuItem,{className:"flex w-full justify-between",icon:Ge.A,iconPosition:(0,d.isRTL)()?"left":"right",variant:void 0,onClick:t,"aria-expanded":e,children:(0,d.__)("Translate","extendify-local")}),(0,p.jsx)(_.A,{icon:(0,d.isRTL)()?Oe.A:He.A,size:24,className:"fill-current group-hover:text-current"})]}),renderContent:()=>(0,p.jsx)(s.MenuGroup,{className:"extendify-draft",label:(0,p.jsxs)("div",{className:"flex items-center gap-2",children:[(0,p.jsx)(_.A,{className:"fill-gray-900",size:16,icon:C}),(0,d.__)("Translate to...","extendify-local")]}),children:i.map((({language:i,code:l,languageName:r,promptType:o="translate",systemMessageKey:c="edit"})=>(0,p.jsx)(s.MenuItem,{style:{width:"100%"},isSelected:!1,disabled:!1,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame((()=>window.requestAnimationFrame((()=>n({text:e,promptType:o,systemMessageKey:c,details:{languageInto:r}})))))},children:i},`${o}-${l}-${c}`)))})})},Ke=["core/paragraph","core/list-item","core/verse","core/preformatted","core/heading"],qe=(e,t)=>{const{clientId:a}=t,{getBlockName:i,getBlock:o}=(0,l.useSelect)((e=>e(n.store)),[]),{getActiveGeneralSidebarName:c}=(0,l.useSelect)((e=>e(r.store)),[]),{openGeneralSidebar:m}=(0,l.useDispatch)(r.store);if(!Ke.includes(i(a)))return(0,p.jsx)(e,{...t});const u=o(a)?.attributes?.content||"",g=()=>m("extendify-draft/draft"),x=e=>window.dispatchEvent(new CustomEvent("extendify-draft:set-prompt",{detail:e}));return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(e,{...t}),(0,p.jsx)(n.BlockControls,{children:(0,p.jsx)(s.ToolbarGroup,{className:"extendify-draft",children:(0,p.jsx)(s.Dropdown,{renderContent:({onClose:e})=>(0,p.jsx)($e,{text:u,closePopup:e,openDraft:g,updatePrompt:x}),renderToggle:({isOpen:e,onToggle:t})=>(0,p.jsx)(s.ToolbarButton,{className:"py-1.5 pl-2 pr-3 text-white before:bg-editor-main before:content-[''] hover:before:bg-editor-main-darker",onClick:()=>{if(!u)return"extendify-draft/draft"===c()?m("edit-post/block"):g();t()},"aria-expanded":e,"aria-haspopup":"true",iconPosition:(0,d.isRTL)()?"right":"left",icon:C,children:(0,d.__)("Ask AI","extendify-local")})})})})]})},$e=({text:e,closePopup:t,openDraft:a,updatePrompt:n})=>{const i=[{label:(0,d.__)("Improve writing","extendify-local"),promptType:"improve-writing",systemMessageKey:"edit",icon:(0,p.jsx)(_.A,{icon:b.A}),disabled:()=>!1},{label:(0,d.__)("Fix spelling & grammar","extendify-local"),promptType:"fix-spelling-grammar",systemMessageKey:"edit",icon:(0,p.jsx)(_.A,{icon:w.A}),disabled:()=>!1},{label:(0,d.__)("Simplify language","extendify-local"),promptType:"simplify-language",systemMessageKey:"edit",icon:(0,p.jsx)(_.A,{icon:j.A}),disabled:()=>!1},{label:(0,d.__)("Make shorter","extendify-local"),promptType:"make-shorter",systemMessageKey:"edit",icon:(0,p.jsx)(_.A,{icon:I}),disabled:()=>!1},{label:(0,d.__)("Make longer","extendify-local"),promptType:"make-longer",systemMessageKey:"edit",icon:(0,p.jsx)(_.A,{icon:v.A}),disabled:()=>!1}];return(0,p.jsx)(s.NavigableMenu,{orientation:"vertical",role:"menu",style:{minWidth:"200px"},children:(0,p.jsxs)(s.MenuGroup,{className:"extendify-draft",children:[(0,p.jsx)(s.MenuItem,{style:{width:"100%"},isSelected:!1,disabled:!1,iconPosition:"left",icon:C,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame((()=>window.requestAnimationFrame((()=>document.getElementById("draft-ai-textarea").focus()))))},children:(0,d.__)("Custom prompt","extendify-local")},"custom-prompt"),i.map((({label:i,promptType:l,systemMessageKey:r,disabled:o,icon:c})=>(0,p.jsx)(s.MenuItem,{style:{width:"100%"},isSelected:!1,disabled:o(),iconPosition:(0,d.isRTL)()?"left":"right",icon:c,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame((()=>window.requestAnimationFrame((()=>n({text:e,promptType:l,systemMessageKey:r})))))},children:i},`${l}-${l}-${r}`))),(0,p.jsx)(ze,{text:e,closePopup:t,openDraft:a,updatePrompt:n})]})})};(0,m.registerPlugin)("extendify-draft",{render:()=>(0,p.jsxs)(Ue,{children:[(0,p.jsx)(r.PluginSidebarMoreMenuItem,{target:"draft",children:(0,d.__)("AI Tools","extendify-local")}),(0,p.jsx)(r.PluginSidebar,{name:"draft",icon:C,title:(0,d.__)("AI Tools","extendify-local"),className:"extendify-draft h-full",children:(0,p.jsx)(s.Flex,{direction:"column",expanded:!0,justify:"space-between",children:(0,p.jsx)(s.FlexBlock,{children:(0,p.jsx)(Me,{})})})})]})});const Ue=({children:e})=>{const{insertBlocks:t,selectBlock:a}=(0,l.useDispatch)(n.store),{navigateTo:s}=Be(),{openGeneralSidebar:c}=(0,l.useDispatch)(r.store),d=(0,l.useSelect)((e=>e(r.store).getActiveGeneralSidebarName())),m=(()=>{const[e,t]=(0,o.useState)(!1),a=(0,l.useSelect)((e=>e(n.store).__unstableIsEditorReady||e(n.store).getBlockCount()>0||e(n.store).getSelectedBlockClientId())),i=(0,l.useSelect)((e=>e(u.store).__unstableIsEditorReady||e(u.store).isCleanNewPost()));return(0,o.useEffect)((()=>{const e=(0,l.subscribe)((()=>{(a||i)&&(t(!0),e())}))}),[a,i]),e})(),g=(0,o.useRef)(!1),{getBlocks:p}=(0,l.useSelect)((e=>e(n.store)),[]);return(0,o.useEffect)((()=>{const e=new URLSearchParams(window.location.search);if(!e.has("ext-add-image-block"))return;e.delete("ext-add-image-block"),window.history.replaceState({},"",window.location.pathname+"?"+e.toString()),s("ai-image");const n=p()?.find((e=>"core/image"===e.name));requestAnimationFrame((()=>n?a(n.clientId):t([(0,i.createBlock)("core/image")]))),setTimeout((()=>{document.getElementById("draft-ai-image-textarea")?.focus()}),300)}),[a,t,s,p]),(0,o.useEffect)((()=>{if(!m||g.current)return;const e=requestAnimationFrame((()=>{"extendify-draft/draft"!==d?c("extendify-draft/draft"):g.current=!0}));return()=>cancelAnimationFrame(e)}),[c,d,m]),e};(0,c.addFilter)("editor.BlockEdit","extendify-draft/draft-toolbar",(e=>t=>qe(e,t))),(0,c.addFilter)("editor.BlockEdit","extendify-draft/draft-image",(e=>t=>((e,t)=>{const{openGeneralSidebar:a}=(0,l.useDispatch)(r.store),{clientId:i,name:c}=t;return(0,o.useEffect)((()=>{if(!Le.includes(c))return;const e=document.querySelector('iframe[name="editor-canvas"]')?.contentDocument,t=e?e.querySelector(`[data-block="${i}"]`):document.querySelector(`[data-block="${i}"]`);if(!t)return;const n=Object.assign(document.createElement("div"),{className:"components-form-file-upload"});let l;t.querySelector(".block-editor-media-placeholder .components-form-file-upload")?.after(n);const r=(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(s.Button,{variant:"primary",__next40pxDefaultSize:!0,onClick:async()=>{a("extendify-draft/draft"),await new Promise((e=>requestAnimationFrame(e)));const e=document.getElementById("extendify-draft-image-gen-button");e?.focus(),e?.classList.add("animate-pulse-flash")},children:(0,d.__)("Get Personalized Image","extendify-local")}),(0,p.jsx)("span",{"aria-hidden":"true"})]}),o=requestAnimationFrame((()=>{l=(0,Ee.X)(r,n)}));return()=>{cancelAnimationFrame(o),l?.unmount(),n?.remove()}}),[i,a,c]),(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(e,{...t}),(0,p.jsx)(n.BlockControls,{children:(0,p.jsx)(Re,{...t})})]})})(e,t)))},1609:e=>{e.exports=window.React},2279:e=>{e.exports=window.wp.plugins},2619:e=>{e.exports=window.wp.hooks},3656:e=>{e.exports=window.wp.editor},4309:e=>{e.exports=window.wp.editPost},4715:e=>{e.exports=window.wp.blockEditor},4997:e=>{e.exports=window.wp.blocks},5573:e=>{e.exports=window.wp.primitives},6087:e=>{e.exports=window.wp.element},6427:e=>{e.exports=window.wp.components},7143:e=>{e.exports=window.wp.data},7723:e=>{e.exports=window.wp.i18n}},e=>{e.O(0,[65,223],(()=>e(e.s=1603))),e.O()}]);