0x1998 - MANAGER
Düzenlenen Dosya: extendify-draft-08ba35a8f591ab939cda.js
"use strict";(globalThis.webpackChunkextendify=globalThis.webpackChunkextendify||[]).push([[429],{8225(e,t,a){var n=a(4997),l=a(6087),i=a(790);const s=({completion:e})=>{const t=(0,n.pasteHandler)({plainText:e}),a=(0,l.useRef)();return(0,i.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,i.jsx)("div",{dangerouslySetInnerHTML:{__html:(0,n.serialize)(t)}}):(0,i.jsx)("div",{dangerouslySetInnerHTML:{__html:t}})})};var o=a(7581),r=a(6427),c=a(7723);const d=()=>{const{consentTerms:e,setUserGaveConsent:t}=(0,o.D)();return(0,i.jsx)(r.Panel,{children:(0,i.jsxs)("div",{className:"p-4",children:[(0,i.jsx)("h2",{className:"mb-2 mt-0 text-lg",children:(0,c.__)("Terms of Use","extendify-local")}),(0,i.jsx)("p",{className:"m-0",dangerouslySetInnerHTML:{__html:e}}),(0,i.jsx)("button",{className:"mt-4 w-full rounded-sm 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,c.__)("Accept","extendify-local")})]})})};var u=a(1450);const m=({disabled:e,setInputText:t,setReady:a})=>{const n=[{label:(0,c.__)("A paragraph …","extendify-local"),onClickText:(0,c.__)("Write a paragraph about","extendify-local")},{label:(0,c.__)("Blog post …","extendify-local"),onClickText:(0,c.__)("Write a blog post about","extendify-local")},{label:(0,c.__)("An informative article …","extendify-local"),onClickText:(0,c.__)("Write an informative article about","extendify-local")},{label:(0,c.__)("Headline …","extendify-local"),onClickText:(0,c.__)("Write a headline for","extendify-local")},{label:(0,c.__)("List …","extendify-local"),onClickText:(0,c.__)("Write a list of","extendify-local")}];return(0,i.jsx)(r.MenuGroup,{children:n.map(({label:n,onClickText:l})=>(0,i.jsx)(r.MenuItem,{onClick:()=>(t(`${l} `),void a(!1)),disabled:e,icon:u.A,iconPosition:"left",children:n},n))})};var g=a(7143);const x=()=>{const{getBlockInsertionPoint:e}=(0,g.useSelect)(e=>e("core/block-editor"),[]),{toggleBlockHighlight:t,showInsertionPoint:a,hideInsertionPoint:n}=(0,g.useDispatch)("core/block-editor");return{toggleHighlight:(e,{isHighlighted:a})=>{t(e[0],a)},toggleInsertionPoint:({isVisible:t})=>{if(!t)return void n();const{rootClientId:l,index:i}=e();a(l,i)}}};var p=a(4715);const f=()=>{const{getSelectedBlockClientIds:e,getBlocksByClientId:t}=(0,g.useSelect)(e=>e(p.store),[]),a=e();return{selectedText:(0,l.useCallback)(()=>{const e=t(a);return e?.length?(e=>{try{return(new DOMParser).parseFromString(e,"text/html").body.textContent||""}catch(e){return""}})(e.filter(Boolean).map(({attributes:e})=>e?.content??"").join("\n\n")):""},[t,a])().trim()}},h=((0,c.__)("Below Icon","extendify-local"),(0,c.__)("Check Icon","extendify-local"),(0,c.__)("Longer Icon","extendify-local"),(0,i.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)("title",{children:(0,c.__)("Magic Icon","extendify-local")}),(0,i.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,i.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,i.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"})]})),y=((0,c.__)("Mic Icon","extendify-local"),(0,c.__)("Pencil Icon","extendify-local"),(0,c.__)("Replace Icon","extendify-local"),(0,c.__)("Replay Icon","extendify-local"),(0,c.__)("Shorter Icon","extendify-local"),(0,c.__)("Trash Icon","extendify-local"),(0,i.jsxs)(r.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",children:[(0,i.jsx)("title",{children:(0,c.__)("Two Lines Icon","extendify-local")}),(0,i.jsx)(r.Path,{d:"M4 10.5h16V9H4v1.5ZM4 15h9v-1.5H4V15Z"})]}));(0,c.__)("Wand Icon","extendify-local");var _=a(319),b=a(3488),w=a(3406),j=a(8237),v=a(7947);const k=({disabled:e,setPrompt:t})=>{const{toggleHighlight:a}=x(),{selectedText:n}=f(),s=(0,g.useSelect)(e=>e("core/block-editor").getSelectedBlockClientIds(),[]);(0,l.useEffect)(()=>()=>{a(s,{isHighlighted:!1})},[s,a]);const o=[{label:(0,c.__)("Improve writing","extendify-local"),promptType:"improve-writing",systemMessageKey:"edit",icon:(0,i.jsx)(_.A,{icon:b.A})},{label:(0,c.__)("Fix spelling & grammar","extendify-local"),promptType:"fix-spelling-grammar",icon:(0,i.jsx)(_.A,{icon:w.A})},{label:(0,c.__)("Simplify language","extendify-local"),promptType:"simplify-language",icon:(0,i.jsx)(_.A,{icon:j.A})},{label:(0,c.__)("Make shorter","extendify-local"),promptType:"make-shorter",icon:(0,i.jsx)(_.A,{icon:y})},{label:(0,c.__)("Make longer","extendify-local"),promptType:"make-longer",icon:(0,i.jsx)(_.A,{icon:v.A})}];return(0,i.jsx)(r.MenuGroup,{children:o.map(({label:l,promptType:o,icon:c})=>(0,i.jsx)(r.MenuItem,{onClick:()=>(e=>{t({text:n,promptType:e,systemMessageKey:"edit"})})(o),onMouseEnter:()=>a(s,{isHighlighted:!0}),onMouseLeave:()=>a(s,{isHighlighted:!1}),icon:c,iconPosition:"left",disabled:e,className:"group",children:(0,i.jsx)("span",{className:"whitespace-normal text-left rtl:text-right",children:l})},`${o}-${o}-edit`))})};var N=a(6221),I=a(8845);const C=({value:e,className:t,onChange:a,onKeyDown:n,disabled:s,placeholder:o})=>{const r=(0,l.useRef)(null),[c,d]=(0,l.useState)("auto");return(0,l.useLayoutEffect)(()=>{const t=document.createElement("textarea");t.value=e||o,t.rows=1;const a=window.getComputedStyle(r.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),d(`${t.scrollHeight}px`),document.body.removeChild(t)},[e,o]),(0,l.useEffect)(()=>{const e=r.current;if(!e)return;if(document.activeElement===e)return;const t=e.value.length;e.focus(),e.setSelectionRange(t,t)},[e]),(0,i.jsx)(N.N,{children:(0,i.jsxs)(I.P.div,{className:"m-0.5 w-full",animate:{height:c},transition:{duration:.2},style:{lineHeight:0},children:[(0,i.jsx)("label",{htmlFor:"draft-ai-textarea",className:"sr-only",children:o}),(0,i.jsx)("textarea",{ref:r,id:"draft-ai-textarea",disabled:s,className:t,value:e,rows:1,onChange:a,onKeyDown:n,onScroll:e=>{e.target.scrollTop=0},placeholder:o})]},"input")})};var S=a(6706),A=a(8557),T=a(6942),B=a.n(T);const P=({inputText:e,setInputText:t,ready:a,setReady:n,setPrompt:l,loading:s})=>{const{selectedText:o}=f(),d=i=>{i.preventDefault(),a&&!s&&(t(""),n(!1),l({text:o||e,promptType:o?"custom-requests":"create",systemMessageKey:o?"edit":"generate",details:{followup:o?e:void 0}}))};return(0,i.jsxs)("form",{className:"relative flex items-start",onSubmit:d,children:[(0,i.jsx)(_.A,{icon:h,className:"absolute left-2 top-3.5 h-5 w-5 fill-current text-wp-theme-main rtl:left-auto rtl:right-2"}),(0,i.jsx)(C,{disabled:s,placeholder:s?(0,c.__)("AI is writing...","extendify-local"):o?(0,c.__)("Ask AI to edit","extendify-local"):(0,c.__)("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-hidden 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(),d(e))}}),s&&(0,i.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,i.jsx)(r.Spinner,{style:{margin:"0"}})}),!s&&(0,i.jsx)("button",{type:"submit",disabled:!a,"aria-label":(0,c.__)("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,i.jsx)(_.A,{icon:(0,c.isRTL)()?S.A:A.A,onClick:d,className:"h-6 w-6 fill-current"})})]})};var M=a(4951),L=a(1502),E=a(4275),D=a(3518),R=a(2097);const F=({prompt:e,completion:t,loading:a,setPrompt:s,setInputText:o})=>{const{toggleHighlight:d,toggleInsertionPoint:u}=x(),{insertBlocks:m,replaceBlocks:f}=(0,g.useDispatch)(p.store),{getSelectedBlock:h,getSelectedBlockClientIds:y,getBlockRootClientId:b,getBlockIndex:w,getBlock:j}=(0,g.useSelect)(e=>e(p.store),[]),v=h(),k=y(),N=e=>{const t=(0,n.pasteHandler)({plainText:e});return Array.isArray(t)?t:[(0,n.createBlock)("core/paragraph",{content:t})]},I=async({replaceContent:e=!1,position:a})=>{s({text:"",promptType:"",systemMessageKey:""});const n=v?v?.clientId:k[0],l=j(n),i=(0,g.select)("core/preferences").get("core","renderingModes")||{},o=(0,g.select)("core").getCurrentTheme()?.stylesheet,r="template-locked"===i?.[o]?.page,{set:c}=(0,g.dispatch)("core/preferences"),d=e=>c("core","renderingModes",{...i,[o]:{...i[o]||{},page:e}}),u=N(t);try{if(!n||"end"===a)return r&&(d("post-only"),await new Promise(e=>requestAnimationFrame(e))),void m(u);if("top"===a)return r&&(d("post-only"),await new Promise(e=>requestAnimationFrame(e))),void m(u,0)}finally{r&&d("template-locked")}const x=""===l?.attributes?.content,p=b(n),h=w(k.at(-1),p);if(!e&&!x)return void m(u,h+1,p);const y=(e,t)=>Object.hasOwn(e?.attributes,"content")&&Object.hasOwn(t?.attributes,"content"),_=1===u.length&&y(l,u[0]),I=u.map(e=>({...e,name:_?l.name:e.name,attributes:{...l.attributes,content:(y(e,l),e?.attributes?.content)}}));f(k,I)};return(0,l.useEffect)(()=>()=>{d(k,{isHighlighted:!1})},[k,d]),(0,i.jsxs)(r.MenuGroup,{children:[(0,i.jsx)(r.MenuItem,{onClick:()=>I({replaceContent:!0}),onMouseEnter:()=>d(k,{isHighlighted:!0}),onMouseLeave:()=>d(k,{isHighlighted:!1}),disabled:a||!(()=>{const e=v||j(k[0]);if(!e)return!1;if(["core/list-item","core/button"].includes(e?.name)){const a=N(t);return a[0]?.name===e?.name}return!0})(),icon:M.A,iconPosition:"left","data-test":"replace-selected",className:"h-auto min-h-10 items-start",children:(0,i.jsx)("span",{className:"whitespace-normal break-words text-start",children:(0,c.__)("Replace selected block text","extendify-local")})}),(0,i.jsxs)(r.MenuItem,{onClick:()=>I({replaceContent:!1,position:"top"}),disabled:a,iconPosition:"left","data-test":"insert-top",className:"h-auto min-h-10 items-start",children:[(0,i.jsx)("div",{className:(0,c.isRTL)()?"-mr-1":"-ml-1",children:(0,i.jsx)(_.A,{icon:L.A,className:"rotate-180"})}),(0,i.jsx)("div",{className:"whitespace-normal break-words px-1 text-start",children:(0,c.__)("Insert at top","extendify-local")})]}),(0,i.jsx)(r.MenuItem,{onClick:()=>I({replaceContent:!1}),onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),disabled:a||!(()=>{const e=v||j(k[0]);return!e||!["core/list-item","core/button"].includes(e?.name)})(),icon:E.A,iconPosition:"left","data-test":"insert-after",className:"h-auto min-h-10 items-start",children:(0,i.jsx)("span",{className:"whitespace-normal break-words text-start",children:(0,c.__)("Insert after the selected text","extendify-local")})}),(0,i.jsx)(r.MenuItem,{onClick:()=>I({replaceContent:!1,position:"end"}),disabled:a,icon:L.A,iconPosition:"left","data-test":"insert-bottom",children:(0,c.__)("Insert at bottom","extendify-local")}),(0,i.jsx)(r.__experimentalDivider,{}),(0,i.jsx)(r.MenuItem,{onClick:()=>{o(""),s({text:"",promptType:"",systemMessageKey:""}),setTimeout(()=>s(e))},disabled:a,icon:D.A,iconPosition:"left","data-test":"try-again-button",children:(0,c.__)("Try again","extendify-local")}),(0,i.jsx)(r.MenuItem,{onClick:()=>{o(""),s({text:"",promptType:"",systemMessageKey:""})},disabled:a,icon:R.A,iconPosition:"left","data-test":"discard-button",children:(0,c.__)("Discard","extendify-local")})]})},G=({loading:e})=>{const[t,a]=(0,l.useState)(),{clearSelectedBlock:n}=(0,g.useDispatch)(p.store),{selectedText:s}=f();if((0,l.useEffect)(()=>{a(s)},[a,s]),t)return(0,i.jsxs)("div",{className:"mb-4 flex space-x-2 overflow-hidden rounded-xs border-none bg-gray-100 p-3","data-test":"existing-text-container",children:[(0,i.jsx)("div",{children:(0,i.jsx)(_.A,{icon:u.A,className:"fill-current"})}),(0,i.jsxs)("div",{children:[(0,i.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,i.jsx)("div",{className:"mt-3 flex w-full justify-end",children:(0,i.jsx)(r.Button,{size:"compact",onClick:n,disabled:e,icon:R.A,iconPosition:(0,c.isRTL)()?"right":"left",className:"relative flex-row-reverse rounded-sm bg-gray-300 text-gray-800 hover:bg-gray-400","data-test":"remove-selection",children:(0,c.__)("Remove selection","extendify-local")})})]})]})};var H=a(8969),z=a(4866);const O=["siteId","partnerId","wpVersion","wpLanguage","devbuild","isBlockTheme","userId","siteProfile"],{showAIConsent:q,userGaveConsent:K}=o.D.getState(),$={...Object.fromEntries(Object.entries(window.extSharedData).filter(([e])=>O.includes(e))),showAIConsent:q,userGaveConsent:K},U=(0,i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)("title",{children:(0,c.__)("Image Icon","extendify-local")}),(0,i.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"})]}),V=({usedCredits:e,total:t})=>e<t?(0,i.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,i.jsx)(r.Icon,{className:"fill-gray-700",icon:U,size:"12px"}),(0,i.jsx)("p",{className:"mb-0 text-[12px] text-gray-700",children:(0,c.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,c.__)("%1$s of %2$s daily image credits used","extendify-local"),e,t)})]}):(0,i.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,i.jsx)("div",{children:(0,i.jsx)(r.Icon,{icon:U,className:"fill-gray-900",size:"12px"})}),(0,i.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,i.jsx)("p",{className:"mb-0 text-[12px] font-bold text-gray-700",children:(0,c.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,c.__)("%1$s of %2$s daily image credits used","extendify-local"),e,t)}),(0,i.jsx)("p",{className:"mb-0 text-gray-900",children:(0,c.__)("You can still explore and find great images on Unsplash until your credits reset.","extendify-local")}),(0,i.jsx)(r.Button,{href:"https://unsplash.com/",variant:"primary",target:"_blank",className:"justify-center text-center",children:(0,c.__)("Search on Unsplash","extendify-local")})]})]}),Z=({isGenerating:e,errorMessage:t})=>{const{imageCredits:a,resetImageCredits:n,aiImageOptions:s,setAiImageOption:o}=(0,z.C)(),d=a.total-a.remaining,[u,m]=(0,l.useState)(0),{size:g,prompt:x}=s;return(0,l.useEffect)(()=>{const e=()=>{m(e=>e+1),a.refresh&&(new Date(Number(a.refresh))>new Date||n())};0===u&&e();const t=setTimeout(e,1e3);return()=>clearTimeout(t)},[a,n,u]),(0,i.jsxs)(i.Fragment,{children:[e?null:(0,i.jsxs)("div",{children:[(0,i.jsx)(r.TextareaControl,{id:"draft-ai-image-textarea",autoFocus:!0,placeholder:(0,c.__)("Tell AI about the image you would like to create","extendify-local"),label:(0,c.__)("Image Prompt","extendify-local"),hideLabelFromVision:!0,rows:"7",value:x,onChange:e=>o("prompt",e)}),(0,i.jsxs)(r.__experimentalToggleGroupControl,{isBlock:!0,label:(0,c.__)("Aspect Ratio","extendify-local"),onChange:e=>o("size",e),value:g,children:[(0,i.jsx)(r.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:X,label:(0,c.__)("Square: 1:1","extendify-local"),value:"1024x1024"}),(0,i.jsx)(r.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:W,label:(0,c.__)("Landscape: 4:3","extendify-local"),value:"1536x1024"}),(0,i.jsx)(r.__experimentalToggleGroupControlOptionIcon,{className:"m-auto",type:"button",icon:J,label:(0,c.__)("Portrait: 3:4","extendify-local"),value:"1024x1536"})]})]}),t.length>0&&(0,i.jsx)("p",{className:"mb-0 text-red-500",children:t}),(0,i.jsx)(r.Button,{type:"submit",className:"w-full justify-center",variant:"primary",__next40pxDefaultSize:!0,disabled:e||!x||d>=a.total,children:e?(0,c.__)("Generating image...","extendify-local"):(0,c.__)("Generate image","extendify-local")}),e?null:(0,i.jsx)(V,{usedCredits:d,total:a.total})]})},W=(0,i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"7px 4px"},children:[(0,i.jsx)("title",{children:(0,c.__)("Landscape: 4:3","extendify-local")}),(0,i.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"})]}),J=(0,i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"4px 6px"},children:[(0,i.jsx)("title",{children:(0,c.__)("Portrait: 3:4","extendify-local")}),(0,i.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"})]}),X=(0,i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",style:{padding:"6px"},children:[(0,i.jsx)("title",{children:(0,c.__)("Square: 1:1","extendify-local")}),(0,i.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"})]}),Y=(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,n.createBlock)("core/image",{id:t.id,caption:t.caption.raw,url:t.source_url,alt:t.alt_text});(0,n.insertBlock)(a,null,e.clientId)}"core/cover"===e.name&&a(e.clientId,{id:t.id,url:t.source_url,alt:t.alt_text})};var Q=a(9324),ee=a(4309);const te=({prompt:e,size:t,isGenerating:a,id:n,src:s,clearImageResponse:o})=>{const{openGeneralSidebar:d}=(0,g.useDispatch)(ee.store),{updateBlockAttributes:u}=(0,g.useDispatch)(p.store),[m,x]=(0,l.useState)(!1),f=(0,g.useSelect)(e=>e(p.store).getSelectedBlock(),[]),[h,y]=t.split("x");return""!==s||a?(0,i.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,i.jsx)(N.N,{children:a?(0,i.jsx)(I.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,i.jsx)(r.Spinner,{style:{height:"48px",width:"48px"}})}):(0,i.jsx)(I.P.div,{initial:{opacity:0},animate:{opacity:1},className:"bg-gray-100",style:{aspectRatio:Number(h)/Number(y)},children:(0,i.jsx)("img",{alt:e,src:s,className:"block w-full",style:{aspectRatio:Number(h)/Number(y)}})})}),a?(0,i.jsxs)("p",{children:[(0,c.__)("Generating your image: ","extendify-local"),(0,i.jsxs)("span",{className:"font-bold",children:['"',e,'"']})]}):(0,i.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),x(!0);const t=await(0,Q.GV)(n,s,"ai-generated");t&&(await Y(f,t,u),x(!1),d("edit-post/block"),o())},className:"flex flex-col gap-5",children:[(0,i.jsx)(r.Button,{type:"submit",autoFocus:!0,className:"w-full justify-center",variant:"primary",disabled:m,children:m? // 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,c.__)("Importing image...","extendify-local"):(0,c.__)("Use this image","extendify-local")}),(0,i.jsx)(r.Button,{className:"w-full justify-center bg-gray-200 text-gray-800 disabled:bg-gray-300 disabled:text-gray-700",onClick:o,disabled:m,children:(0,c.__)("Delete image","extendify-local")})]})]}):null};var ae=a(1621),ne=a(7134);const le=(0,i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"8",height:"12",fill:"none",children:[(0,i.jsx)("title",{children:(0,c.__)("Back Arrow","extendify-local")}),(0,i.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"})]});var ie=a(6935);const se=(oe=e=>({imageDetails:{src:"",id:void 0},setImageDetails:t=>{e(e=>({...e,imageDetails:t}))}}),(0,ae.vt)((0,ne.lt)(oe,{name:"Extendify Draft AI Image"})));var oe;const re=[{slug:"ai-image",title:(0,c.__)("AI Image","extendify-local"),component:()=>{const{imageCredits:e,updateImageCredits:t,subtractOneCredit:a,aiImageOptions:n}=(0,z.C)(),[s,o]=(0,l.useState)(!1),[d,u]=(0,l.useState)(""),m=(0,l.useRef)(null),g=0===e.remaining,{imageDetails:x,setImageDetails:p}=se(),{goBack:f}=ve();return(0,l.useEffect)(()=>{x.src||s||document.getElementById("draft-ai-image-textarea")?.focus()},[x.src,s]),(0,i.jsxs)(r.Panel,{children:[(0,i.jsxs)("div",{className:"flex h-12 items-center gap-1 pl-1",children:[(0,i.jsx)("button",{className:"h-9 w-9 border-0 bg-transparent",onClick:f,type:"button","aria-label":(0,c.__)("Go Back","extendify-local"),children:le}),(0,i.jsx)(r.__experimentalHeading,{className:"mb-0",children:(0,c.__)("AI Image Generator","extendify-local")})]}),(0,i.jsx)(r.PanelBody,{className:"-mt-4 border-t-0",children:(0,i.jsxs)(r.BaseControl,{label:(0,c.__)("Image Description","extendify-local"),children:[(0,i.jsx)(te,{prompt:n.prompt,size:n.size,isGenerating:s,id:x?.id,src:x?.src,clearImageResponse:()=>p({src:"",id:void 0})}),x.src?null:(0,i.jsx)("form",{onSubmit:async l=>{if(l.preventDefault(),u(""),g)m.current?.abort();else try{o(!0),a(),m.current=new AbortController;const{imageCredits:e,images:l,id:i}=await(0,ie.Fz)(n,m.current.signal);t(e),p({src:l[0].url,id:i})}catch(a){if(20===a?.code)return;if(!a?.imageCredits)return await new Promise(e=>setTimeout(e,1e3)),u(a.message),void t({remaining:e.remaining});t(a.imageCredits),u(a.message)}finally{o(!1)}},className:"flex flex-col gap-5",children:(0,i.jsx)(Z,{isGenerating:s,errorMessage:d})})]})})]})}}],ce=[{slug:"home",title:(0,c.__)("Home","extendify-local"),component:()=>{const{navigateTo:e}=ve();return(0,i.jsxs)(r.PanelBody,{children:[(0,i.jsx)(r.BaseControl,{id:"extendify-draft-image-gen",label:(0,c.__)("AI Image Generator","extendify-local"),help:(0,c.__)("Use AI to generate custom images based on your description.","extendify-local"),children:(0,i.jsx)(r.Button,{variant:"primary",__next40pxDefaultSize:!0,id:"extendify-draft-image-gen-button",className:"w-full justify-center",onClick:()=>e("ai-image"),children:(0,c.__)("Generate an image","extendify-local")})}),(0,i.jsx)(r.__experimentalSpacer,{marginY:"5"}),(0,i.jsx)(r.__experimentalDivider,{}),(0,i.jsx)(r.BaseControl,{id:"extendify-draft-image-stock-photos",label:(0,c.__)("Discover Stock Photos","extendify-local"),help:(0,c.__)("Search and add free stock photos from Unsplash.com","extendify-local"),children:(0,i.jsx)(r.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,c.__)("Search Unsplash","extendify-local")})})]})}}],de=({image:e,skeletonHeight:t,isInsertingImage:a,onClick:n})=>{const[s,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(!1),u=e?.width?Number(e?.width)/Number(e?.height):122/t;return(0,l.useEffect)(()=>{if(!e?.user?.links?.html)return void o("");const t=new URL(e.user.links.html);t.searchParams.set("utm_source","extendify"),t.searchParams.set("utm_medium","referral"),o(t.toString())},[e]),(0,l.useInsertionEffect)(()=>{if(!e?.urls||c)return;const t=new Image;t.src=e.urls.thumb||e.urls.small,(0,Q.yt)(t).then(()=>d(!0))},[e,c]),(0,i.jsxs)(I.P.div,{className:"relative mb-1",initial:{aspectRatio:u},animate:{aspectRatio:u},children:[(0,i.jsx)(N.N,{children:c?null:(0,i.jsx)(I.P.div,{className:"absolute inset-0 z-10 bg-white",initial:{opacity:1},animate:{opacity:1},exit:{opacity:0},children:(0,i.jsx)("div",{className:"animate-pulse absolute inset-0 z-10 bg-gray-150"})})}),(0,i.jsxs)("div",{className:"group relative",children:[(0,i.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,i.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,i.jsx)(r.Spinner,{style:{height:"24px",width:"24px"}})}),(0,i.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&&s?(0,i.jsx)("a",{href:s,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]})]})},ue=({images:e,isInsertingImage:t,onClick:a,loading:n})=>{const l=e?.length??10;return n||e.length?(0,i.jsx)("div",{className:"columns-2 gap-1",children:Array.from({length:l}).map((n,l)=>{const s=[150,175,200];return(0,i.jsx)(de,{image:e?.[l],skeletonHeight:s[l%s.length],isInsertingImage:t,onClick:a},e?.[l]?.id??l)})}):(0,c.__)("No images found.","extendify-local")};var me=a(9358),ge=a(8455),xe=a(4225);const pe=[{slug:"unsplash",title:(0,c.__)("Unsplash","extendify-local"),component:()=>{const{goBack:e}=ve(),[t,a]=(0,l.useState)(""),[n,s]=(0,l.useState)(""),[o,d]=(0,l.useState)(!1),{data:u,loading:m}=((e,t=null)=>{const a=e||"unsplash",{data:n,error:l}=(0,xe.A)(a,()=>(async(e,t=null)=>{const a=ge.f.getState();return"unsplash"!==e||a.isEmpty()||a.hasExpired()?await(0,me.P)(e,t):a.images})(a,t));return{data:n,error:l,loading:!n&&!l}})(n,"user"),[x,f]=(0,l.useState)(null),h=(0,g.useSelect)(e=>e(p.store).getSelectedBlock(),[]),{updateBlockAttributes:y}=(0,g.useDispatch)(p.store);return(0,l.useEffect)(()=>{d(!1)},[n]),(0,l.useEffect)(()=>{if(!t)return s("");const e=setTimeout(()=>s(t),750);return()=>clearTimeout(e)},[t]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"flex h-12 items-center gap-1 pl-1",children:[(0,i.jsx)("button",{className:"h-9 w-9 border-0 bg-transparent",onClick:e,type:"button","aria-label":(0,c.__)("Go Back","extendify-local"),children:le}),(0,i.jsx)(r.__experimentalHeading,{className:"mb-0",children:(0,c.__)("Photos from Unsplash","extendify-local")})]}),(0,i.jsx)(r.__experimentalDivider,{className:"my-0 border-gray-150"}),(0,i.jsxs)("div",{className:"flex flex-col gap-2 p-4",children:[(0,i.jsx)(r.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,i.jsx)(ue,{images:u,isInsertingImage:x,onClick:async e=>{if(!x){f(e);try{const t=await(0,Q.GV)(e.requestMetadata?.id,e.urls?.regular,"unsplash",e.id);Y(h,t,y)}catch(e){console.error(e)}finally{f(null)}}},loading:m||o})]})]})}}];var fe=a(1077),he=a(1455),ye=a.n(he);const _e=[...ce,...re,...pe],be="/extendify/v1/draft/router-data",we={getItem:async()=>await ye()({path:be}),setItem:async(e,t)=>await ye()({path:be,method:"POST",data:{state:t}})},je=(0,ae.vt)((0,ne.Zr)((0,ne.lt)((e,t)=>({history:[],viewedPages:[],current:null,goBack:()=>{if(t().history.length<2)return;const a=t().history[1];fe.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,l=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),l?{...l,count:l.count+1,lastViewedAt:t}:{slug:a.slug,firstViewedAt:n,lastViewedAt:t,count:1}]}})}}),{name:"Extendify Draft Router"}),{name:"extendify-draft-router",storage:(0,ne.KU)(()=>we),skipHydration:!0,partialize:({viewedPages:e})=>({viewedPages:e})})),ve=()=>{const{current:e,setCurrent:t,history:a,goBack:n}=je(),s=e?.component??(()=>null);return(0,l.useEffect)(()=>{e||t(_e[0])},[e,t]),{current:e,CurrentPage:(0,l.useCallback)(()=>(0,i.jsxs)("section",{"aria-live":"polite",className:"h-full",children:[(0,i.jsx)("h1",{className:"sr-only",children:e?.title}),(0,i.jsx)(s,{})]}),[e]),navigateTo:e=>{const a=_e.find(t=>t.slug===e);if(!a)return t(_e[0]);fe.e.getState().incrementActivity(`draft-${a.slug}`),t(a)},goBack:n,history:a}},ke=()=>{const{selectedText:e}=f(),[t,a]=(0,l.useState)(""),[n,u]=(0,l.useState)(!1),[x,h]=(0,l.useState)({text:"",promptType:"",systemMessageKey:"",details:{}}),{completion:y,loading:_,error:b}=((e,t,a,n)=>{const[i,s]=(0,l.useState)(""),[o,r]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let l,i=!1;const o=new TextDecoder;return e?((async()=>{s(""),r(!1),u(!0);const d=await(async(e,t,a,n)=>{const l=await fetch(`${H.AY}/api/draft/completion`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,promptType:t,systemMessageKey:a,details:n,globalState:z.C.getState(),...$})});if(!l.ok)throw new Error((0,c.__)("Service temporarily unavailable","extendify-local"));return l})(e,t,a,n);l=d.body.getReader();let m=!1;for(;!m;){const{value:e,done:t}=await l.read();if(m=t,e&&!i){const t=o.decode(e);s(e=>e+t)}}})().finally(()=>{i||u(!1)}).catch(e=>{i||r(e)}),()=>{i=!0,l&&l.cancel()}):(u(!1),s(""),void(i=!0))},[e,a,t,n]),{completion:i,error:o,loading:d}})(x.text,x.promptType,x.systemMessageKey,x.details),{selectedBlockClientIds:w,getBlock:j}=(0,g.useSelect)(e=>{const t=e(p.store);return{selectedBlockClientIds:t.getSelectedBlockClientIds(),getBlock:t.getBlock,getBlocks:t.getBlocks}},[]),{CurrentPage:v}=ve(),N=(0,o.D)(e=>e.shouldShowAIConsent("draft"));(0,l.useEffect)(()=>{const e=e=>{N||h(e.detail)};return window.addEventListener("extendify-draft:set-prompt",e),()=>window.removeEventListener("extendify-draft:set-prompt",e)},[N]),(0,l.useEffect)(()=>{b&&a(x.text)},[b,x.text]);const I=()=>{if(0===w.length)return!1;const e=j(w[0]);return!!e&&void 0!==e?.attributes?.content&&""!==e?.attributes?.content};return N?(0,i.jsx)(d,{}):(()=>{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,i.jsx)(v,{}):(0,i.jsx)(r.Panel,{children:(0,i.jsxs)(r.PanelBody,{children:[e&&(0,i.jsx)(G,{loading:_}),(0,i.jsxs)("div",{className:"mb-4 overflow-hidden rounded-xs border-none bg-gray-100",children:[!y&&(0,i.jsx)(P,{inputText:t,setInputText:a,ready:n,setReady:u,setPrompt:h,loading:_}),y&&(0,i.jsx)(s,{completion:y}),b&&(0,i.jsx)("div",{className:"mb-4 mt-2 px-4",children:(0,i.jsx)("p",{className:"m-0 text-xs font-semibold text-red-500",children:b.message})})]}),(y||_)&&!b&&(0,i.jsx)(F,{prompt:x,completion:y,setPrompt:h,setInputText:a,loading:_}),!_&&!y&&I()&&(0,i.jsx)(r.BaseControl,{children:(0,i.jsx)(k,{completion:y,disabled:_,setInputText:a,setPrompt:h})}),!_&&!y&&!I()&&(0,i.jsx)(r.BaseControl,{__nextHasNoMarginBottom:!0,label:(0,c.__)("Suggested prompts","extendify-local"),children:(0,i.jsx)(m,{disabled:_,setInputText:a,setReady:u})})]})})};var Ne=a(3656),Ie=a(2619),Ce=a(2279),Se=a(7828);const Ae=["core/image","core/media-text","core/gallery","core/cover"],Te=()=>{const{openGeneralSidebar:e}=(0,g.useDispatch)(ee.store);return(0,i.jsx)(r.MenuItem,{icon:h,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,c.__)("Get Personalized Image","extendify-local")})},Be=()=>{const{openGeneralSidebar:e}=(0,g.useDispatch)(ee.store);return(0,i.jsx)(r.ToolbarGroup,{className:"extendify-draft",children:(0,i.jsx)(r.ToolbarButton,{className:"py-1.5 pl-2 pr-3 text-white before:bg-editor-main before:content-[''] hover:before:bg-editor-main-darker",icon:h,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,c.__)("Ask AI","extendify-local")})})},Pe=({name:e,attributes:t})=>((0,l.useEffect)(()=>{if(!Ae.includes(e))return;let t,a,n,l,s;return(async()=>{await new Promise(e=>{l=requestAnimationFrame(e)});const e=Array.from(document.querySelectorAll('[data-toolbar-item="true"]'))?.find(e=>e.textContent===(0,c.__)("Replace")||e.textContent===(0,c.__)("Add"));e&&(s=new MutationObserver(e=>{if("true"===e[0].target.getAttribute("aria-expanded")){const e=".block-editor-media-replace-flow__media-upload-menu",l=document.querySelector(e);if(!l)return;return t=document.createElement("div"),l.prepend(t),void(n=requestAnimationFrame(()=>{a=(0,Se.X)((0,i.jsx)(Te,{}),t)}))}cancelAnimationFrame(n),a?.unmount(),t?.remove()}),s.observe(e,{attributes:!0,childList:!1,subtree:!1}))})(),()=>{[n,l].forEach(cancelAnimationFrame),a?.unmount(),t?.remove(),s?.disconnect()}},[e,t]),Ae.includes(e)?(0,i.jsx)(Be,{}):null);var Me=a(6527),Le=a(5492),Ee=a(5367);const De=({text:e,closePopup:t,openDraft:a,updatePrompt:n})=>{const l=[{language:(0,c.__)("Arabic","extendify-local"),code:"ar",languageName:"Arabic"},{language:(0,c.__)("Arabic (Morocco)","extendify-local"),code:"ary",languageName:"Arabic (Morocco)"},{language:(0,c.__)("Bulgarian","extendify-local"),code:"bg_BG",languageName:"Bulgarian"},{language:(0,c.__)("Catalan","extendify-local"),code:"ca",languageName:"Catalan"},{language:(0,c.__)("Czech","extendify-local"),code:"cs_CZ",languageName:"Czech"},{language:(0,c.__)("Danish","extendify-local"),code:"da_DK",languageName:"Danish"},{language:(0,c.__)("Dutch","extendify-local"),code:"nl_NL",languageName:"Dutch"},{language:(0,c.__)("Dutch (Belgium)","extendify-local"),code:"de_BE",languageName:"Dutch (Belgium)"},{language:(0,c.__)("English","extendify-local"),code:"en",languageName:"English"},{language:(0,c.__)("English (UK)","extendify-local"),code:"en_GB",languageName:"English (UK)"},{language:(0,c.__)("Estonian","extendify-local"),code:"et",languageName:"Estonian"},{language:(0,c.__)("Finnish","extendify-local"),code:"fi",languageName:"Finnish"},{language:(0,c.__)("French (Belgium)","extendify-local"),code:"fr_BE",languageName:"French (Belgium)"},{language:(0,c.__)("French (Canada)","extendify-local"),code:"fr_CA",languageName:"French (Canada)"},{language:(0,c.__)("French (France)","extendify-local"),code:"fr_FR",languageName:"French (France)"},{language:(0,c.__)("German","extendify-local"),code:"de_DE",languageName:"German"},{language:(0,c.__)("German (Switzerland)","extendify-local"),code:"de_CH",languageName:"German (Switzerland)"},{language:(0,c.__)("Greek","extendify-local"),code:"el",languageName:"Greek"},{language:(0,c.__)("Hebrew","extendify-local"),code:"he_IL",languageName:"Hebrew"},{language:(0,c.__)("Hindi","extendify-local"),code:"hi_IN",languageName:"Hindi"},{language:(0,c.__)("Hungarian","extendify-local"),code:"hu_HU",languageName:"Hungarian"},{language:(0,c.__)("Indonesian","extendify-local"),code:"id_ID",languageName:"Indonesian"},{language:(0,c.__)("Italian","extendify-local"),code:"it_IT",languageName:"Italian"},{language:(0,c.__)("Japanese","extendify-local"),code:"jp",languageName:"Japanese"},{language:(0,c.__)("Lithuanian","extendify-local"),code:"lt_LT",languageName:"Lithuanian"},{language:(0,c.__)("Latvian","extendify-local"),code:"lv",languageName:"Latvian"},{language:(0,c.__)("Norwegian","extendify-local"),code:"nb_NO",languageName:"Norwegian"},{language:(0,c.__)("Polish","extendify-local"),code:"pl_PL",languageName:"Polish"},{language:(0,c.__)("Portuguese (Brazil)","extendify-local"),code:"pt_BR",languageName:"Portuguese (Brazil)"},{language:(0,c.__)("Portuguese (Portugal)","extendify-local"),code:"pt_PT",languageName:"Portuguese (Portugal)"},{language:(0,c.__)("Romanian","extendify-local"),code:"ro_RO",languageName:"Romanian"},{language:(0,c.__)("Russian","extendify-local"),code:"ru_RU",languageName:"Russian"},{language:(0,c.__)("Slovak","extendify-local"),code:"sk_SK",languageName:"Slovak"},{language:(0,c.__)("Spanish (Spain)","extendify-local"),code:"es_ES",languageName:"Spanish (Spain)"},{language:(0,c.__)("Spanish (Colombia)","extendify-local"),code:"es_CO",languageName:"Spanish (Colombia)"},{language:(0,c.__)("Spanish (Mexico)","extendify-local"),code:"es_MX",languageName:"Spanish (Mexico)"},{language:(0,c.__)("Swedish","extendify-local"),code:"sv_SE",languageName:"Swedish"},{language:(0,c.__)("Turkish","extendify-local"),code:"tr_TR",languageName:"Turkish"},{language:(0,c.__)("Ukrainian","extendify-local"),code:"uk",languageName:"Ukrainian"},{language:(0,c.__)("Vietnamese","extendify-local"),code:"vi",languageName:"Vietnamese"}];return(0,i.jsx)(r.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,i.jsxs)("div",{className:"group flex w-full items-center justify-between hover:text-design-main",children:[(0,i.jsx)(r.MenuItem,{className:"flex w-full justify-between",icon:Me.A,iconPosition:(0,c.isRTL)()?"left":"right",variant:void 0,onClick:t,"aria-expanded":e,children:(0,c.__)("Translate","extendify-local")}),(0,i.jsx)(_.A,{icon:(0,c.isRTL)()?Le.A:Ee.A,size:24,className:"fill-current group-hover:text-current"})]}),renderContent:()=>(0,i.jsx)(r.MenuGroup,{className:"extendify-draft",label:(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)(_.A,{className:"fill-gray-900",size:16,icon:h}),(0,c.__)("Translate to...","extendify-local")]}),children:l.map(({language:l,code:s,languageName:o,promptType:c="translate",systemMessageKey:d="edit"})=>(0,i.jsx)(r.MenuItem,{style:{width:"100%"},isSelected:!1,disabled:!1,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame(()=>window.requestAnimationFrame(()=>n({text:e,promptType:c,systemMessageKey:d,details:{languageInto:o}})))},children:l},`${c}-${s}-${d}`))})})},Re=["core/paragraph","core/list-item","core/verse","core/preformatted","core/heading","core/site-logo"],Fe=(e,t)=>{const{clientId:a}=t,{getBlockName:n,getBlock:l}=(0,g.useSelect)(e=>e(p.store),[]),{getActiveGeneralSidebarName:s}=(0,g.useSelect)(e=>e(ee.store),[]),{openGeneralSidebar:o}=(0,g.useDispatch)(ee.store);if(!Re.includes(n(a)))return(0,i.jsx)(e,{...t});const d=l(a)?.attributes?.content||"",u=()=>o("extendify-draft/draft"),m=e=>window.dispatchEvent(new CustomEvent("extendify-draft:set-prompt",{detail:e}));return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(e,{...t}),(0,i.jsx)(p.BlockControls,{children:(0,i.jsx)(r.ToolbarGroup,{className:"extendify-draft",children:(0,i.jsx)(r.Dropdown,{renderContent:({onClose:e})=>(0,i.jsx)(Ge,{text:d,closePopup:e,openDraft:u,updatePrompt:m}),renderToggle:({isOpen:e,onToggle:t})=>(0,i.jsx)(r.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(!d)return"extendify-draft/draft"===s()?o("edit-post/block"):u();t()},"aria-expanded":e,"aria-haspopup":"true",iconPosition:(0,c.isRTL)()?"right":"left",icon:h,children:(0,c.__)("Ask AI","extendify-local")})})})})]})},Ge=({text:e,closePopup:t,openDraft:a,updatePrompt:n})=>{const l=[{label:(0,c.__)("Improve writing","extendify-local"),promptType:"improve-writing",systemMessageKey:"edit",icon:(0,i.jsx)(_.A,{icon:b.A}),disabled:()=>!1},{label:(0,c.__)("Fix spelling & grammar","extendify-local"),promptType:"fix-spelling-grammar",systemMessageKey:"edit",icon:(0,i.jsx)(_.A,{icon:w.A}),disabled:()=>!1},{label:(0,c.__)("Simplify language","extendify-local"),promptType:"simplify-language",systemMessageKey:"edit",icon:(0,i.jsx)(_.A,{icon:j.A}),disabled:()=>!1},{label:(0,c.__)("Make shorter","extendify-local"),promptType:"make-shorter",systemMessageKey:"edit",icon:(0,i.jsx)(_.A,{icon:y}),disabled:()=>!1},{label:(0,c.__)("Make longer","extendify-local"),promptType:"make-longer",systemMessageKey:"edit",icon:(0,i.jsx)(_.A,{icon:v.A}),disabled:()=>!1}];return(0,i.jsx)(r.NavigableMenu,{orientation:"vertical",role:"menu",style:{minWidth:"200px"},children:(0,i.jsxs)(r.MenuGroup,{className:"extendify-draft",children:[(0,i.jsx)(r.MenuItem,{style:{width:"100%"},isSelected:!1,disabled:!1,iconPosition:"left",icon:h,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame(()=>window.requestAnimationFrame(()=>document.getElementById("draft-ai-textarea").focus()))},children:(0,c.__)("Custom prompt","extendify-local")},"custom-prompt"),l.map(({label:l,promptType:s,systemMessageKey:o,disabled:d,icon:u})=>(0,i.jsx)(r.MenuItem,{style:{width:"100%"},isSelected:!1,disabled:d(),iconPosition:(0,c.isRTL)()?"left":"right",icon:u,variant:void 0,onClick:()=>{a?.(),t?.(),window.requestAnimationFrame(()=>window.requestAnimationFrame(()=>n({text:e,promptType:s,systemMessageKey:o})))},children:l},`${s}-${s}-${o}`)),(0,i.jsx)(De,{text:e,closePopup:t,openDraft:a,updatePrompt:n})]})})};(0,Ce.registerPlugin)("extendify-draft",{render:()=>(0,i.jsxs)(He,{children:[(0,i.jsx)(Ne.PluginSidebarMoreMenuItem,{target:"draft",children:(0,c.__)("AI Tools","extendify-local")}),(0,i.jsx)(Ne.PluginSidebar,{name:"draft",icon:h,title:(0,c.__)("AI Tools","extendify-local"),className:"extendify-draft h-full",children:(0,i.jsx)(r.Flex,{direction:"column",expanded:!0,justify:"space-between",children:(0,i.jsx)(r.FlexBlock,{children:(0,i.jsx)(ke,{})})})})]})});const He=({children:e})=>{const{insertBlocks:t,selectBlock:a}=(0,g.useDispatch)(p.store),{navigateTo:i}=ve(),{openGeneralSidebar:s}=(0,g.useDispatch)(ee.store),o=(0,g.useSelect)(e=>e(ee.store).getActiveGeneralSidebarName()),r=(()=>{const[e,t]=(0,l.useState)(!1),a=(0,g.useSelect)(e=>e(p.store).__unstableIsEditorReady||e(p.store).getBlockCount()>0||e(p.store).getSelectedBlockClientId()),n=(0,g.useSelect)(e=>e(Ne.store).__unstableIsEditorReady||e(Ne.store).isCleanNewPost());return(0,l.useEffect)(()=>{const e=(0,g.subscribe)(()=>{(a||n)&&(t(!0),e())})},[a,n]),e})(),c=(0,l.useRef)(!1),{getBlocks:d}=(0,g.useSelect)(e=>e(p.store),[]);return(0,l.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()}`),i("ai-image");const l=d()?.find(e=>"core/image"===e.name);requestAnimationFrame(()=>l?a(l.clientId):t([(0,n.createBlock)("core/image")])),setTimeout(()=>{document.getElementById("draft-ai-image-textarea")?.focus()},300)},[a,t,i,d]),(0,l.useEffect)(()=>{if(!r||c.current)return;const e=requestAnimationFrame(()=>{"extendify-draft/draft"!==o?s("extendify-draft/draft"):c.current=!0});return()=>cancelAnimationFrame(e)},[s,o,r]),e};(0,Ie.addFilter)("editor.BlockEdit","extendify-draft/draft-toolbar",e=>t=>Fe(e,t)),(0,Ie.addFilter)("editor.BlockEdit","extendify-draft/draft-image",e=>t=>((e,t)=>{const{openGeneralSidebar:a}=(0,g.useDispatch)(ee.store),{clientId:n,name:s}=t;return(0,l.useEffect)(()=>{if(!Ae.includes(s))return;const e=document.querySelector('iframe[name="editor-canvas"]')?.contentDocument,t=e?e.querySelector(`[data-block="${n}"]`):document.querySelector(`[data-block="${n}"]`);if(!t)return;const l=Object.assign(document.createElement("div"),{className:"components-form-file-upload"});let o;t.querySelector(".block-editor-media-placeholder .components-form-file-upload")?.after(l);const d=(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(r.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,c.__)("Get Personalized Image","extendify-local")}),(0,i.jsx)("span",{"aria-hidden":"true"})]}),u=requestAnimationFrame(()=>{o=(0,Se.X)(d,l)});return()=>{cancelAnimationFrame(u),o?.unmount(),l?.remove()}},[n,a,s]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(e,{...t}),(0,i.jsx)(p.BlockControls,{children:(0,i.jsx)(Pe,{...t})})]})})(e,t))},1609(e){e.exports=window.React},790(e){e.exports=window.ReactJSXRuntime},1455(e){e.exports=window.wp.apiFetch},4715(e){e.exports=window.wp.blockEditor},4997(e){e.exports=window.wp.blocks},6427(e){e.exports=window.wp.components},7143(e){e.exports=window.wp.data},4309(e){e.exports=window.wp.editPost},3656(e){e.exports=window.wp.editor},6087(e){e.exports=window.wp.element},2619(e){e.exports=window.wp.hooks},7723(e){e.exports=window.wp.i18n},2279(e){e.exports=window.wp.plugins},5573(e){e.exports=window.wp.primitives},3832(e){e.exports=window.wp.url}},e=>{e.O(0,[65,223],()=>e(e.s=8225)),e.O()}]);
geri dön