From 9426acd102d78d4e49a5c5f10797056b108c5e25 Mon Sep 17 00:00:00 2001 From: CGastrell Date: Mon, 2 Dec 2024 19:55:21 +0000 Subject: [PATCH] Jetpack AI: remove initial fetch and dead code (#40172) * do not fetch on store initialization * do not return false on bogus response prop * remove references to tierPlansEnabled, they never are now * add changelog Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12126728593 Upstream-Ref: Automattic/jetpack@1d5f28c3407ab1e7c4447991ca0c353357411937 --- CHANGELOG.md | 1 + _inc/blocks/editor-beta.asset.php | 2 +- _inc/blocks/editor-beta.js | 6 +++--- _inc/blocks/editor-experimental.asset.php | 2 +- _inc/blocks/editor-experimental.js | 6 +++--- _inc/blocks/editor-no-post-editor.asset.php | 2 +- _inc/blocks/editor-no-post-editor.js | 4 ++-- _inc/blocks/editor.asset.php | 2 +- _inc/blocks/editor.js | 6 +++--- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f0cd1667f..8a242f7af2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This is an alpha version! The changes listed here are not final. ### Other changes +- Jetpack AI: remove dead and deprecated code - Updated package dependencies. ## 14.1-beta - 2024-12-02 diff --git a/_inc/blocks/editor-beta.asset.php b/_inc/blocks/editor-beta.asset.php index b42b58af9c..a91b5a60eb 100644 --- a/_inc/blocks/editor-beta.asset.php +++ b/_inc/blocks/editor-beta.asset.php @@ -1 +1 @@ - array('jetpack-connection', 'jetpack-script-data', 'lodash', 'moment', 'react', 'react-dom', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-block-serialization-default-parser', 'wp-blocks', 'wp-commands', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-escape-html', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-keycodes', 'wp-media-utils', 'wp-notices', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-rich-text', 'wp-token-list', 'wp-url', 'wp-viewport', 'wp-widgets', 'wp-wordcount'), 'version' => '6266e1e308e1591209e1'); + array('jetpack-connection', 'jetpack-script-data', 'lodash', 'moment', 'react', 'react-dom', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-block-serialization-default-parser', 'wp-blocks', 'wp-commands', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-escape-html', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-keycodes', 'wp-media-utils', 'wp-notices', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-rich-text', 'wp-token-list', 'wp-url', 'wp-viewport', 'wp-widgets', 'wp-wordcount'), 'version' => '9c195c88edec5619125b'); diff --git a/_inc/blocks/editor-beta.js b/_inc/blocks/editor-beta.js index f3f067f666..67363fbde8 100644 --- a/_inc/blocks/editor-beta.js +++ b/_inc/blocks/editor-beta.js @@ -24,7 +24,7 @@ __("%s account connected successfully.","jetpack"),o.label),{type:"snackbar",isD // Translators: %s is the date when the requests will reset. const n=__("Requests will reset on %s.","jetpack");return`${t} ${(0,l.sprintf)(n,e)}`})((e=>{if(!e?.nextStart)return null;const t=new Date(e.nextStart);return t.toLocaleString("default",{month:"long"})+" "+t.getDate()})(e));return(0,i.createInterpolateElement)(t,{link:(0,a.createElement)("a",{href:"https://jetpack.com/redirect/?source=ai-assistant-fair-usage-policy",target:"_blank",rel:"noreferrer"})})})();return"muted"===e?(0,a.createElement)("span",{className:"jetpack-ai-fair-usage-notice-muted-variant"},t):"error"===e?(0,a.createElement)(o.Notice,{status:"error",isDismissible:!1,className:"jetpack-ai-fair-usage-notice"},t):null},b=e=>{const{upgradeType:t,currentTier:n}=(0,m.A)();return 1===n?.value?(0,a.createElement)(v,null):"vip"===t?(({description:e=null,useLightNudge:t=!1})=>{const n=t?g.U:d.c,r=(0,i.createInterpolateElement)(__("You've reached the Jetpack AI rate limit. Please reach out to your VIP account team.","jetpack"),{strong:(0,a.createElement)("strong",null)});return(0,a.createElement)(n,{buttonText:null,checkoutUrl:null,className:"jetpack-ai-upgrade-banner",description:e||r,goToCheckoutPage:null,isRedirecting:null,visible:!0,align:null,title:null,context:null})})({description:e.description,useLightNudge:e?.useLightNudge}):(({placement:e=null,description:t=null,useLightNudge:n=!1})=>{const o=n?g.U:d.c,{checkoutUrl:c}=(0,p.A)(),u=(0,h.C)(),{nextTier:v,tierPlansEnabled:b,currentTier:k,requestsCount:y}=(0,m.A)(),{tracks:E}=(0,s.st)(),w=(0,i.useCallback)((()=>{f("upgrade",e),E.recordEvent("jetpack_ai_upgrade_button",{current_tier_slug:k?.slug,requests_count:y,placement:e})}),[k,y,E,e]),_=(0,i.useCallback)((()=>{f("contact us",e),E.recordEvent("jetpack_ai_upgrade_contact_us",{placement:e})}),[E,e]);if(!u){const e=(0,i.createInterpolateElement)(__("Congratulations on exploring Jetpack AI and reaching the free requests limit! Reach out to the site administrator to upgrade and keep using Jetpack AI.","jetpack"),{strong:(0,a.createElement)("strong",null)});return(0,a.createElement)(o,{showButton:!1,className:"jetpack-ai-upgrade-banner",description:t||e,visible:!0,align:null,title:null,context:null})}if(b){if(!v){const e=(0,r.A)("jetpack-ai-tiers-more-requests-contact"),n=__("You have reached the request limit for your current plan.","jetpack");return(0,a.createElement)(o,{buttonText:__("Contact Us","jetpack"),description:t||n,className:"jetpack-ai-upgrade-banner",checkoutUrl:e,visible:!0,align:null,title:null,context:null,goToCheckoutPage:_,target:"_blank"})}const e=(0,i.createInterpolateElement)((0,l.sprintf)(/* Translators: number of requests */ __("You have reached the requests limit for your current plan. Upgrade now to increase your requests limit to %d.","jetpack"),v.limit),{strong:(0,a.createElement)("strong",null)});return(0,a.createElement)(o,{buttonText:(0,l.sprintf)(/* Translators: number of requests */ -__("Upgrade to %d requests","jetpack"),v.limit),checkoutUrl:c,className:"jetpack-ai-upgrade-banner",description:t||e,goToCheckoutPage:w,visible:!0,align:"center",title:null,context:null,target:"_blank"})}return(0,a.createElement)(o,{buttonText:"Upgrade",checkoutUrl:c,className:"jetpack-ai-upgrade-banner",description:(0,i.createInterpolateElement)(__("Congratulations on exploring Jetpack AI and reaching the free requests limit! Upgrade now to keep using it.","jetpack"),{strong:(0,a.createElement)("strong",null)}),goToCheckoutPage:w,visible:!0,align:null,title:null,context:null,target:"_blank"})})(e)}},93094:(e,t,n)=>{"use strict";n.d(t,{U:()=>o});var a=n(82170),r=n(56427),s=n(27723);const __=s.__,o=({title:e,description:t,buttonText:n=null,checkoutUrl:s=null,goToCheckoutPage:o=null,isRedirecting:i=!1,showButton:l=!0,target:c="_top"})=>{const u=__("Redirecting…","jetpack");return(0,a.createElement)("div",{className:"jetpack-upgrade-plan-banner-light"},(0,a.createElement)(r.Notice,{status:"error",isDismissible:!1},(0,a.createElement)("p",null,e&&(0,a.createElement)("strong",null,e),t," ",l&&(0,a.createElement)(r.Button,{href:i?null:s,onClick:o,variant:"link",target:c},i?u:n))))}},62402:(e,t,n)=>{"use strict";n.d(t,{Ay:()=>g,US:()=>u,hN:()=>h,oZ:()=>p,uQ:()=>d});var a=n(82170),r=n(96865),s=n(85985),o=n(56427),i=n(27723),l=n(29115);n(51609);const __=i.__,c=["formal","informal","optimistic","humorous","serious","skeptical","empathetic","confident","passionate","provocative"],u="formal",d=__("Change tone","jetpack"),p={formal:{label:__("Formal","jetpack"),emoji:"🎩"},informal:{label:__("Informal","jetpack"),emoji:"😊"},optimistic:{label:__("Optimistic","jetpack"),emoji:"😃"},humorous:{label:__("Humorous","jetpack"),emoji:"😂"},serious:{label:__("Serious","jetpack"),emoji:"😐"},skeptical:{label:__("Skeptical","jetpack"),emoji:"🤨"},empathetic:{label:__("Empathetic","jetpack"),emoji:"💗"},confident:{label:__("Confident","jetpack"),emoji:"😎"},passionate:{label:__("Passionate","jetpack"),emoji:"❤️"},provocative:{label:__("Provocative","jetpack"),emoji:"🔥"}},m=({value:e,onChange:t})=>(0,a.createElement)(o.MenuGroup,{label:__("Select tone","jetpack")},c.map((n=>(0,a.createElement)(o.MenuItem,{key:`key-${n}`,onClick:()=>t(n),isSelected:e===n},`${p[n].emoji} ${p[n].label}`))));function h({label:e=d,value:t=u,onChange:n,disabled:s=!1}){return(0,a.createElement)(o.DropdownMenu,{icon:r.Qr,label:e,className:"ai-assistant__tone-dropdown",popoverProps:{variant:"toolbar"},toggleProps:{children:(0,a.createElement)(a.Fragment,null,(0,a.createElement)("div",{className:"ai-assistant__tone-dropdown__toggle-label"},e),(0,a.createElement)(o.Icon,{icon:l.A})),disabled:s}},(({onClose:e})=>(0,a.createElement)(m,{value:t,onChange:t=>{n(t),e()}})))}function g({value:e=u,onChange:t,disabled:n=!1}){const{tracks:i}=(0,s.st)();return n?(0,a.createElement)(o.Tooltip,{text:d},(0,a.createElement)(o.Button,{disabled:!0},(0,a.createElement)(o.Icon,{icon:r.Qr}))):(0,a.createElement)(o.ToolbarDropdownMenu,{icon:r.Qr,label:d,popoverProps:{variant:"toolbar"},disabled:n,onToggle:e=>{e&&i.recordEvent("jetpack_ai_assistant_block_toolbar_menu_show",{tool:"tone"})}},(()=>(0,a.createElement)(m,{value:e,onChange:t})))}},51698:(e,t,n)=>{"use strict";n.d(t,{A:()=>h});var a=n(82170),r=n(94715),s=n(56427),o=n(27723),i=n(83883),l=n(83822),c=n(64425),u=n(2162),d=n(99050),p=n(33468),m=n(62402);const __=o.__,h=({contentIsLoaded:e,getSuggestionFromOpenAI:t,retryRequest:n,handleAcceptContent:o,handleTryAgain:h,showRetry:g,contentBefore:f,hasPostTitle:v,wholeContent:b,setUserPrompt:k,recordEvent:y,isGeneratingTitle:E})=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.BlockControls,null,!g&&(0,a.createElement)(a.Fragment,null,(0,a.createElement)(s.ToolbarGroup,null,(0,a.createElement)(p.Ay,{hasContentBefore:!!f?.length,hasContent:!!b?.length,hasPostTitle:v,contentIsLoaded:e,onPromptSelect:e=>{y("jetpack_editor_ai_assistant_block_toolbar_button_click",{type:"prompt-template",prompt:e.original}),k(e.translated)},onSuggestionSelect:e=>{y("jetpack_editor_ai_assistant_block_toolbar_button_click",{type:"suggestion",suggestion:e}),t(e)}})),(0,a.createElement)(r.BlockControls,{group:"block"},(0,a.createElement)(m.Ay,{value:"neutral",onChange:n=>{y("jetpack_editor_ai_assistant_block_toolbar_button_click",{type:"suggestion",suggestion:c.eJ}),t(c.eJ,{tone:n,contentType:e?"generated":null})},disabled:!e&&!b?.length}),(0,a.createElement)(u.Ay,{value:"en",onChange:n=>{y("jetpack_editor_ai_assistant_block_toolbar_button_click",{type:"suggestion",suggestion:c.Gm}),t(c.Gm,{language:n,contentType:e?"generated":null})},disabled:!e&&!b?.length}),(0,a.createElement)(d.Ay,{onChange:t,exclude:E?["summarize"]:[],disabled:!e}))),(g||h)&&(0,a.createElement)(s.ToolbarGroup,null,!g&&e&&h&&(0,a.createElement)(s.ToolbarButton,{onClick:h},__("Try Again","jetpack")),g&&e&&(0,a.createElement)(s.ToolbarButton,{icon:i.A,onClick:o},__("Accept","jetpack")),g&&(0,a.createElement)(s.ToolbarButton,{icon:l.A,onClick:n},__("Retry","jetpack")))))},3586:(e,t,n)=>{"use strict";n.d(t,{A:()=>S});var a=n(82170),r=n(96865),s=n(85985),o=n(94715),i=n(74997),l=n(56427),c=n(29491),u=n(47143),d=n(86087),p=n(27723),m=n(13022),h=n(27970),g=n(56199),f=n(2274),v=n(58164),b=n(32249),k=n(23e3),y=n(51698),E=n(4393),w=n(92169),_=n(61297),C=n(44732),A=n(76695),x=n(7503);const __=p.__,j="post"===window?.Jetpack_Editor_Initial_State?.screenBase;function S({attributes:e,setAttributes:t,clientId:n,isSelected:p}){const[S,N]=(0,d.useState)(null),{tracks:R}=(0,s.st)(),{getBlock:P}=(0,u.useSelect)("core/block-editor"),L=(0,d.useRef)(null),T=(0,d.useRef)(null),{replaceBlocks:B,removeBlock:M}=(0,u.useDispatch)("core/block-editor"),{editPost:I}=(0,u.useDispatch)("core/editor"),{isOverLimit:D,requireUpgrade:F,increaseRequestsCount:z,requestsCount:O,requestsLimit:H,currentTier:U,loading:V,tierPlansEnabled:q}=(0,_.A)(),G=Math.max(H-O,0),{autosaveAndRedirect:$}=(0,w.A)(),W=(0,v.Bd)(U),Z=()=>{setTimeout((()=>{L.current?.focus?.()}),100)},J=()=>{setTimeout((()=>{T.current?.focus?.()}),100)},K=(0,c.useViewportMatch)("medium","<"),Y=(0,d.useRef)(null),{getSuggestionFromOpenAI:Q,stopSuggestion:X,showRetry:ee,contentBefore:te,postTitle:ne,retryRequest:ae,wholeContent:re,requestingState:se,error:oe}=(0,E.A)({onSuggestionDone:(0,d.useCallback)((()=>{Z(),z()}),[z]),onUnclearPrompt:(0,d.useCallback)((()=>{J(),z()}),[z]),onModeration:Z,attributes:e,clientId:n,content:e.content,tracks:R,userPrompt:e.userPrompt,requireUpgrade:F,initialRequestingState:e.requestingState,contentRef:Y,blockRef:T}),ie="requesting"===se,le=["requesting","suggesting"].includes(se),ce=(0,x.x)(),{productPageUrl:ue}=(0,C.A)(),de=(0,A.y)(n);(0,d.useEffect)((()=>{if(!de)return;const e=JSON.parse(localStorage.getItem(de));if(!e)return;const{type:t,options:n}=e;localStorage.removeItem(de),Q(t,n)}),[de,Q]),(0,d.useEffect)((()=>{oe&&N(!1)}),[oe]),(0,d.useEffect)((()=>{["init","done"].includes(se)&&t({requestingState:se})}),[se,t]);const pe=!!e.content,me="generateTitle"===e.promptType,he=__("Accept","jetpack"),ge=__("Accept title","jetpack"),fe=me?ge:he,ve=async()=>{let t=[],a=(0,r._E)({content:e.content||""});if(a?.split("\n").length>1&&a?.split("\n")?.[0]?.match(/^

.*<\/h1>$/)&&!ne){const e=a.split("\n"),t=e.shift();a=e.join("\n"),I({title:t.replace(/<[^>]*>/g,"")})}t=(0,i.rawHandler)({HTML:a}),await B(n,t);const s=(e=>{let t=null;return e.forEach((e=>{const n=document.querySelector(`.wp-block[data-block="${e.clientId}"]`);if(!n)return;"true"===n.contentEditable&&(t=n);const a=n.querySelectorAll("[contenteditable=true]");t=a.length?a[a.length-1]:t})),t})(t);s&&(e=>{const t=e.ownerDocument.getSelection();t.selectAllChildren(e),t.collapseToEnd(),e.focus()})(s)},be=()=>{ve(),R.recordEvent("jetpack_ai_assistant_block_accept",{feature:"ai-assistant"})},ke=()=>{j?(I({title:e.content?e.content.trim():""}),M(n),R.recordEvent("jetpack_ai_assistant_block_accept",{feature:"ai-assistant"})):be()},ye=()=>{X(),Z(),R.recordEvent("jetpack_ai_assistant_block_stop",{feature:"ai-assistant"})},Ee=(0,o.useBlockProps)({ref:T,className:(0,m.A)({"is-waiting-response":ie})}),we=__("Ask Jetpack AI…","jetpack"),_e=__("Write about… Make a table for…","jetpack"),Ce=(0,a.createElement)(a.Fragment,null,D&&p&&(0,a.createElement)(k.A,{placement:"ai-assistant-block"}),!ce&&(0,a.createElement)(f.A,{block:"AI Assistant"})),Ae=(0,a.createElement)(a.Fragment,null,oe?.message&&!S&&"error_quota_exceeded"!==oe?.code&&(0,a.createElement)(l.Notice,{status:oe.status,isDismissible:!1,className:"jetpack-ai-assistant__error"},oe.message)),xe=D&&W===v.Ti?(0,a.createElement)(k.Q,{variant:"muted"}):null,je=(0,d.useCallback)((e=>{e.preventDefault(),R.recordEvent("jetpack_ai_upgrade_button",{current_tier_slug:U?.slug,requests_count:O,placement:"jetpack_ai_assistant_block"}),$(e)}),[R,U,O,$]);return(0,a.createElement)(l.KeyboardShortcuts,{bindGlobal:!0,shortcuts:{esc:()=>{["requesting","suggesting"].includes(se)&&ye()}}},(0,a.createElement)("div",Ee,pe&&(0,a.createElement)("div",{ref:Y,className:"jetpack-ai-assistant__content"},(0,a.createElement)(d.RawHTML,null,(0,r._E)({content:e.content||""}))),(0,a.createElement)(o.InspectorControls,null,xe&&(0,a.createElement)("div",{className:"block-editor-block-card",style:{paddingTop:0}},(0,a.createElement)("span",{className:"block-editor-block-icon"}),xe),(0,a.createElement)("div",{className:"block-editor-block-card",style:{paddingTop:0}},(0,a.createElement)("span",{className:"block-editor-block-icon"}),(0,a.createElement)(l.ExternalLink,{href:ue},__("Discover all features","jetpack"))),(W===v._X||q&&W!==v.Ti)&&(0,a.createElement)(l.PanelBody,{initialOpen:!0},(0,a.createElement)(l.PanelRow,null,(0,a.createElement)(h.A,{placement:g.k}))),(0,a.createElement)(l.PanelBody,{initialOpen:!0},(0,a.createElement)(l.PanelRow,null,(0,a.createElement)(b.A,null)))),!le&&ce&&!F&&(0,a.createElement)(y.A,{isWaitingState:le,contentIsLoaded:pe,getSuggestionFromOpenAI:Q,retryRequest:ae,handleAcceptContent:be,handleAcceptTitle:ke,handleTryAgain:null,showRetry:ee,contentBefore:te,hasPostTitle:!!ne?.length,wholeContent:re,promptType:e.promptType,setUserPrompt:e=>{if(!L?.current)return;L.current.focus(),t({userPrompt:e})},recordEvent:R.recordEvent,isGeneratingTitle:me}),(0,a.createElement)(r.N0,{ref:L,disabled:F||!ce,value:e.userPrompt,placeholder:e?.content?we:_e,onChange:e=>{N(!0),t({userPrompt:e})},onSend:()=>{((...e)=>{Q(...e),J()})("userPrompt"),R.recordEvent("jetpack_ai_assistant_block_generate",{feature:"ai-assistant"})},onStop:ye,onAccept:()=>{me?ke():be()},onDiscard:()=>{const a=e?.content===P(n).attributes?.content;t({content:e?.originalContent,promptType:void 0,messages:e?.originalMessages}),ve(),a?R.recordEvent("jetpack_ai_assistant_block_dismiss"):R.recordEvent("jetpack_ai_assistant_block_discard",{feature:"ai-assistant"})},state:se,isTransparent:F||!ce,showButtonLabels:!K,showAccept:"init"!==se&&pe&&!le,acceptLabel:fe,showGuideLine:pe,showRemove:e?.content?.length>0,banner:Ce,error:Ae,customFooter:G%5!=0&&1!==O||V||W!==v._X?null:(0,a.createElement)(r.AK,{requestsRemaining:G,onUpgradeClick:je})})))}},61351:(e,t,n)=>{"use strict";var a=n(94375),r=n(54681),s=n(3586),o=n(13802);n(99800);(0,a.M)(r,{edit:s.A,save:()=>null,transforms:o.Ay})},10603:(e,t,n)=>{"use strict";n.d(t,{mt:()=>o});var a=n(96865),r=n(74997),s=n(47143);class o{renderRules=[];firstUpdate=!0;behavior="dropdown";isChildBlock=!1;feature="ai-assistant";adjustPosition=!0;startOpen=!1;hideOnBlockFocus=!0;constructor(e,t=[]){this.clientId=e,this.renderRules=t}getBlock(){const{getBlock:e}=(0,s.select)("core/block-editor");return e(this.clientId)}getContent(){const e=this.getBlock();return t=(0,r.getBlockContent)(e),(0,a.rh)({content:t});var t}renderContent(e){return function(e,t=[]){return(0,a._E)({content:e,rules:t,extension:!0})}(e,this.renderRules)}onSuggestion(e){if(!e)return;const t=this.renderContent(e);this.replaceBlockContent(t)}onDone(e){this.firstUpdate=!0}replaceBlockContent(e){const[t]=(0,r.rawHandler)({HTML:e});if(!t)return;const{updateBlockAttributes:n,replaceInnerBlocks:a,__unstableMarkNextChangeAsNotPersistent:o}=(0,s.dispatch)("core/block-editor");this.firstUpdate?this.firstUpdate=!1:o(),n(this.clientId,t.attributes),o(),a(this.clientId,t.innerBlocks)}getExtensionInputPlaceholder(){return null}}},67607:(e,t,n)=>{"use strict";n.d(t,{A:()=>p});var a=n(82170),r=n(96865),s=n(85985),o=n(86087),i=n(27723),l=n(13022),c=(n(51609),n(92169)),u=n(61297);const __=i.__,d=(0,l.A)("jetpack-ai-assistant-extension-ai-input","wp-block");function p({customPlaceholder:e,className:t,requestingState:n,requestingError:i,inputRef:p,wrapperRef:m,action:h,blockType:g,feature:f,request:v,stopSuggestion:b,close:k,undo:y,tryAgain:E}){const w=e||__("Ask Jetpack AI to edit…","jetpack"),[_,C]=(0,o.useState)(""),[A,x]=(0,o.useState)(w),{checkoutUrl:j}=(0,c.A)(),{tracks:S}=(0,s.st)(),[N,R]=(0,o.useState)(0),[P,L]=(0,o.useState)(!1),{requireUpgrade:T,requestsCount:B,requestsLimit:M,loading:I,nextTier:D,currentTier:F}=(0,u.A)(),z=(0,o.useMemo)((()=>T||["requesting","suggesting"].includes(n)),[T,n]),O=(0,o.useMemo)((()=>T&&1===F?.value),[T,F]),H=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_assistant_extension_generate",{block_type:g,feature:f}),v?.(_)}),[g,f,v,S,_]),U=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_assistant_extension_stop",{block_type:g}),b?.()}),[g,b,S]);const V=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_assistant_undo",{block_type:g}),y?.()}),[g,S,y]),q=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_upgrade_button",{current_tier_slug:F?.slug,requests_count:B,placement:"jetpack_ai_assistant_extension"})}),[F?.slug,B,S]),G=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_assistant_try_again",{block_type:g}),E?.()}),[g,S,E]);return(0,o.useEffect)((()=>{["init","done"].includes(n)&&C("")}),[n]),(0,o.useEffect)((()=>{x(h||w),h&&C("")}),[h,w]),(0,o.useEffect)((()=>{L(!I&&!!D&&0===_.length)}),[I,D,_]),(0,o.useEffect)((()=>{const e=Math.max(M-B,0);R(e)}),[M,B]),(0,a.createElement)(r.FC,{className:(0,l.A)(d,t),placeholder:A,disabled:z,value:_,state:n,showGuideLine:!0,error:i,requestsRemaining:N,showUpgradeMessage:P,showFairUsageMessage:O,upgradeUrl:j,onChange:C,onSend:H,onStop:U,onClose:function(){k?.()},onUndo:V,onUpgrade:q,onTryAgain:G,wrapperRef:m,ref:p})}},31124:(e,t,n)=>{"use strict";n.d(t,{A:()=>m});var a=n(82170),r=n(96865),s=n(85985),o=n(56427),i=n(86087),l=n(27723),c=n(52068),u=n(76695),d=n(2612);const __=l.__;function p({blockType:e,onClose:t,onAskAiAssistant:n,onRequestSuggestion:r}){const{canTransformToAIAssistant:s,transformToAIAssistant:o,getSelectedBlockClientIds:l}=(0,u.A)(),d=(0,i.useCallback)((a=>{const i=l(),[c]=i,u=a?.options?.alwaysTransformToAIAssistant||!1;!(i.length<2)&&s({clientId:c,blockName:e})||u?o({request:a}):(a?r?.(a.promptType,a.options,a.humanText):n?.(),t?.())}),[e,s,l,n,t,r,o]),[p]=l();return(0,a.createElement)(c.Ay,{blockType:e,clientId:p,onRequestSuggestion:(e,t,n)=>{d({promptType:e,options:t,humanText:n})},onAskAiAssistant:async()=>{d()},disabled:!1})}function m({behavior:e,blockType:t,label:n=__("AI Assistant","jetpack"),onAskAiAssistant:l,onRequestSuggestion:c}){const{tracks:u}=(0,s.st)(),m=(0,i.useContext)(d.B),h=(0,i.useCallback)((e=>{e&&u.recordEvent("jetpack_ai_assistant_extension_toolbar_menu_show",{block_type:t})}),[t,u]),g=(0,i.useCallback)((()=>{u.recordEvent("jetpack_editor_ai_assistant_extension_toolbar_prompt_show",{block_type:t}),l?.()}),[t,l,u]),f=(0,i.useCallback)(((e,n,a)=>{u.recordEvent("jetpack_editor_ai_assistant_extension_toolbar_button_click",{suggestion:e,block_type:t}),c?.(e,n,a)}),[t,c,u]);return(0,a.createElement)(o.Dropdown,{popoverProps:{variant:"toolbar"},renderToggle:({isOpen:t,onToggle:s})=>(0,a.createElement)(o.ToolbarButton,{className:"jetpack-ai-assistant__button",showTooltip:!0,onClick:()=>{if("function"!=typeof e)switch(e){case"action":g();break;case"dropdown":s()}else e({onToggle:s,onAskAiAssistant:l,context:m})},"aria-haspopup":"true","aria-expanded":t,label:n,icon:r.cj}),onToggle:h,renderContent:({onClose:e})=>(0,a.createElement)(p,{onClose:e,blockType:t,onAskAiAssistant:g,onRequestSuggestion:f})})}},95396:(e,t,n)=>{"use strict";n.d(t,{L:()=>r,l:()=>a});const a=["jetpack/field-name","jetpack/field-email","jetpack/field-text","jetpack/field-textarea","jetpack/field-checkbox","jetpack/field-date","jetpack/field-telephone","jetpack/field-url","jetpack/field-checkbox-multiple","jetpack/field-radio","jetpack/field-select","jetpack/field-consent","jetpack/button"],r=["core/heading","core/paragraph","core/list-item","core/list","jetpack/contact-form",...a]},2612:(e,t,n)=>{"use strict";n.d(t,{B:()=>g,Q:()=>f});var a=n(86087),r=n(10067),s=n.n(r),o=n(10603),i=n(95396),l=n(42160),c=n(47007),u=n(75430),d=n(24310),p=n(63904);const m=s()("jetpack-ai-assistant:extensions:get-block-handler"),h={"core/heading":l.T,"core/paragraph":p.d,"core/list-item":d.g,"core/list":u.b,"jetpack/contact-form":c.p,...i.l.reduce(((e,t)=>({...e,[t]:c.g})),{})},g=(0,a.createContext)({});function f(e,t){let n=h[e];n||(m(`No handler found for block type: ${e}. Using default handler.`),n=o.mt);const a=new n(t);return{onSuggestion:a.onSuggestion.bind(a),onDone:a.onDone.bind(a),getContent:a.getContent.bind(a),getExtensionInputPlaceholder:a.getExtensionInputPlaceholder.bind(a),behavior:a.behavior,isChildBlock:a.isChildBlock,feature:a.feature,adjustPosition:a.adjustPosition,startOpen:a.startOpen,hideOnBlockFocus:a.hideOnBlockFocus}}},42160:(e,t,n)=>{"use strict";n.d(t,{T:()=>r});var a=n(10603);class r extends a.mt{constructor(e){super(e,[])}onSuggestion(e){const t=this.getBlock();if(e.startsWith("#")||(e=`${"#".repeat(t?.attributes?.level||1)} ${e}`),e.match(/^#*\s*$/))return;const n=this.renderContent(e);this.replaceBlockContent(n)}}},14602:(e,t,n)=>{"use strict";n.d(t,{g:()=>s});var a=n(47143),r=n(10603);class s extends r.mt{jetpackFormBlockName="jetpack/contact-form";constructor(e){super(e,[]),this.behavior=this.handleBehavior,this.isChildBlock=!0,this.hideOnBlockFocus=!1}handleBehavior=({context:e})=>{const t=(0,a.dispatch)("core/block-editor"),{getBlockParentsByBlockName:n}=(0,a.select)("core/block-editor"),r=n(this.clientId,this.jetpackFormBlockName)?.[0];t.selectBlock(r),e?.[this.jetpackFormBlockName]?.handleAskAiAssistant?.()}}},47007:(e,t,n)=>{"use strict";n.d(t,{g:()=>c.g,p:()=>u});var a=n(74997),r=n(47143),s=n(27723),o=n(62514),i=n(96568),l=n(10603),c=n(14602);const __=s.__;class u extends l.mt{currentListOfValidBlocks=[];constructor(e){super(e,[]),this.behavior="action",this.feature="jetpack-form-ai-extension",this.adjustPosition=!1,this.startOpen=!0,this.hideOnBlockFocus=!1}setContent(e,t=!1){const{replaceInnerBlocks:n}=(0,r.dispatch)("core/block-editor"),s=e.replace(//g,""),l=(0,i.d)(s),c=(0,a.parse)(l).filter((e=>e.isValid&&!["core/freeform","core/missing","core/html"].includes(e.name)));let u=!1;if(c.length0){const e=c[c.length-1],t=this.currentListOfValidBlocks[c.length-1];u=!(0,o.w)(e,t)}if(c.length>0&&(c.length!==this.currentListOfValidBlocks.length||u)&&(n(this.clientId,c),this.currentListOfValidBlocks=c),t){const e=c.filter((e=>"jetpack/button"===e.name));if(this.currentListOfValidBlocks=this.currentListOfValidBlocks||[],e.length>1){let t=0;this.currentListOfValidBlocks=this.currentListOfValidBlocks.filter((n=>"jetpack/button"!==n.name||(t++,t===e.length))),n(this.clientId,this.currentListOfValidBlocks)}else 0===e.length&&n(this.clientId,[...this.currentListOfValidBlocks,(0,a.createBlock)("jetpack/button",{label:__("Submit","jetpack"),element:"button",text:__("Submit","jetpack"),borderRadius:8,lock:{remove:!0}})]);this.currentListOfValidBlocks=[]}}getExtensionInputPlaceholder(){if(!this.getContent()){const e=[__("Example: a contact form with name, email, and message fields","jetpack"),__("Example: a pizza ordering form with name, address, phone number and toppings","jetpack"),__("Example: a survey form with multiple choice questions","jetpack")];return e[Math.floor(Math.random()*e.length)]}const e=[__("Example: remove email field","jetpack"),__("Example: make email optional","jetpack"),__("Example: add message field and make it required","jetpack")];return e[Math.floor(Math.random()*e.length)]}getContent(){const e=this.getBlock();if(!e)return"";const{innerBlocks:t}=e;return t?.length?t.reduce(((e,t)=>e+(0,a.serialize)(t)+"\n\n"),""):""}onSuggestion(e){this.setContent(e)}onDone(e){this.setContent(e,!0)}}},10821:(e,t,n)=>{"use strict";n.d(t,{Bi:()=>i});var a=n(74997),r=n(47143),s=n(7503);const o=(0,n(48499).C)("ai-assistant-support");function i(){if(!(0,a.getBlockType)("jetpack/ai-assistant"))return!1;if(!o)return!1;if(!(0,s.x)())return!1;const{errorCode:e}=(0,r.select)("wordpress-com/plans")?.getAiAssistantFeature?.()||{};if(e)return!1;const{getHiddenBlockTypes:t}=(0,r.select)("core/edit-post")||{};return!(t?.()||[]).includes("jetpack/ai-assistant")}},91184:(e,t,n)=>{"use strict";n.d(t,{Y:()=>s});var a=n(95396),r=n(10821);function s(e){return!!(0,r.Bi)()&&!!a.L.includes(e)}},24310:(e,t,n)=>{"use strict";n.d(t,{g:()=>r});var a=n(10603);class r extends a.mt{constructor(e){super(e,["listItem"]),this.isChildBlock=!0}}},75430:(e,t,n)=>{"use strict";n.d(t,{b:()=>r});var a=n(10603);class r extends a.mt{constructor(e){super(e,["list"])}}},63904:(e,t,n)=>{"use strict";n.d(t,{d:()=>i});var a=n(96865),r=n(74997),s=n(10603);const o=new a.OO({fixes:["paragraph"]});class i extends s.mt{constructor(e){super(e,["paragraph"])}getContent(){const e=this.getBlock();return t=(0,r.getBlockContent)(e),o.render({content:t});var t}}},99800:(e,t,n)=>{"use strict";var a=n(82170),r=n(96865),s=n(94715),o=n(29491),i=n(47143),l=n(86087),c=n(52619),u=n(13022),d=n(10067),p=n.n(d),m=(n(51609),n(61297)),h=n(32735),g=n(35317),f=n(4e4),v=n(67607),b=n(31124),k=n(2612),y=n(91184);const E=p()("jetpack-ai-assistant:extensions:with-ai-extension"),w={"core/heading":"heading","core/paragraph":"paragraph","core/list-item":"list-item","core/list":"list","jetpack/contact-form":"form-ai"},_={group:"block"},C=(0,o.createHigherOrderComponent)((e=>{function t(t){const{clientId:n,isSelected:o,name:c,isSelectionEnabled:d}=t,p=(0,l.useRef)(null),g=(0,l.useRef)(0),y=(0,l.useRef)(null),C=(0,l.useRef)(""),A=(0,l.useRef)(null),x=(0,l.useRef)(document),j=(0,l.useRef)([]),[S,N]=(0,l.useState)(""),R=(0,l.useRef)(null),P=(0,l.useRef)(null),{undo:L}=(0,i.useDispatch)("core/editor"),{postId:T}=(0,i.useSelect)((e=>{const{getCurrentPostId:t}=e("core/editor");return{postId:t()}}),[]),{id:B,className:M}=(0,s.useBlockProps)({className:(0,u.A)({[c?.replace?.("/","-")]:!0})}),{increaseRequestsCount:I,dequeueAsyncRequest:D,requireUpgrade:F}=(0,m.A)(),{snapToBottom:z,enableAutoScroll:O,disableAutoScroll:H}=(0,h.A)({current:x?.current?.getElementById(B)},void 0,!0),U=(0,l.useCallback)((()=>{A.current?.focus()}),[]),{onSuggestion:V,onDone:q,getContent:G,getExtensionInputPlaceholder:$,behavior:W,isChildBlock:Z,feature:J,adjustPosition:K,startOpen:Y,hideOnBlockFocus:Q}=(0,l.useMemo)((()=>(0,k.Q)(c,n)),[c,n]),X=$(),[ee,te]=(0,l.useState)(Y),ne=(0,l.useCallback)((()=>{te((e=>!e))}),[]),ae=(0,l.useCallback)((({promptType:e,options:t})=>{const n=G(),a=w[c];return[...j.current,{role:"jetpack-ai",context:{type:(0,f.p$)(e,a),content:n,request:t?.userPrompt,tone:t?.tone,language:t?.language,is_follow_up:j.current.length>0}}]}),[c,G]),re=(0,l.useCallback)((e=>{const t=e||x.current.getElementById(B);t&&p.current&&t.style.setProperty("padding-bottom",`calc(${g.current+16}px + ${C.current||"0px"} )`,"important")}),[B]),se=(0,l.useCallback)((e=>{V(e),K&&re(),z()}),[V,K,z,re]),oe=(0,l.useCallback)((e=>{if(H(),q(e),I(),N(""),R.current?.message){const e={role:"assistant",content:G()};if(j.current.push(R.current.message,e),j.current.length>20){j.current.splice(0,j.current.length-20);const e=j.current.findIndex((e=>"jetpack-ai"===e.role));-1!==e&&(j.current=j.current.slice(e),j.current[0].context={...j.current[0].context,is_follow_up:!1})}}R.current=null,setTimeout((()=>{K&&re(),U()}),100)}),[H,q,I,G,K,U,re]),ie=(0,l.useCallback)((e=>{H(),N(""),E("Request error",e),e.code!==r.mA&&e.code!==r.Or&&I()}),[H,I]),{request:le,stopSuggestion:ce,requestingState:ue,error:de,reset:pe}=(0,r.o2)({onSuggestion:se,onDone:oe,onError:ie,askQuestionOptions:{postId:T,feature:J}});(0,l.useEffect)((()=>{P.current=ue}),[ue]);const me=(0,l.useCallback)(((e,t,n)=>{if(te(!0),F)return;n&&N(n);const a=ae({promptType:e,options:t});E("Request suggestion",e,t);const r=a[a.length-1];R.current={promptType:e,options:t,humanText:n,message:r},D(),O(),le(a)}),[D,O,ae,le,F]),he=(0,l.useCallback)((e=>{const t={userPrompt:e};O(),me("userPrompt",t)}),[O,me]),ge=(0,l.useCallback)((()=>{H(),ce(),U()}),[H,ce,U]),fe=(0,l.useCallback)((()=>{R.current&&me(R.current.promptType,R.current.options,R.current.humanText)}),[R,me]),ve=(0,l.useCallback)((()=>{te(!1),pe(),N(""),R.current=null,j.current=[]}),[pe]),be=(0,l.useCallback)((async()=>{await L(),ve()}),[L,ve]);(0,l.useEffect)((()=>{o||ve()}),[o,ve]),(0,l.useEffect)((()=>{A.current&&d&&(x.current=A.current.ownerDocument,U())}),[ee,U,d]),(0,l.useEffect)((()=>{let e=x.current.getElementById(B);if(e&&K)return ee&&!y.current&&p.current?(C.current=e.style.paddingBottom,y.current=new ResizeObserver((([t])=>{if(e=x.current.getElementById(B),g.current=t.contentRect.height,e&&p.current&&g.current>0){re(e);const{marginBottom:t}=getComputedStyle(e),n=parseFloat(t);p.current.style.setProperty("margin-top",`-${g.current+n}px`,"important"),p.current.style.setProperty("margin-bottom",`${n+16}px`,"important")}})),y.current.observe(p.current)):y.current&&(e.style.paddingBottom=C.current,y.current.disconnect(),y.current=null,g.current=0),()=>{y.current&&y.current.disconnect()}}),[re,K,n,y,B,ee]),(0,l.useEffect)((()=>{if(Q&&ee){const e=x.current.getElementById(B),t=()=>{["requesting","suggesting"].includes(P.current)||(te(!1),e?.removeEventListener("focusin",t))};return e?.addEventListener("focusin",t),()=>{e?.removeEventListener("focusin",t)}}}),[Q,ee,B]);const ke=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(e,t),ee&&(0,a.createElement)(v.A,{customPlaceholder:X||null,className:M,requestingState:ue,requestingError:de,wrapperRef:p,inputRef:A,action:S,blockType:c,feature:J,request:he,stopSuggestion:ge,close:ve,undo:be,tryAgain:fe}),(0,a.createElement)(s.BlockControls,_,(0,a.createElement)(b.A,{blockType:c,onAskAiAssistant:ne,onRequestSuggestion:me,behavior:W})));if(Z)return ke;const ye={value:{[c]:{handleAskAiAssistant:ne,handleRequestSuggestion:me}}};return(0,a.createElement)(k.B.Provider,ye,ke)}return n=>(0,g.A)(n.name)?(0,a.createElement)(t,n):(0,a.createElement)(e,n)}),"blockEditWithAiComponents");(0,c.addFilter)("blocks.registerBlockType","jetpack/ai-assistant-support/with-ai-extension",(function(e,t){return(0,y.Y)(t)?{...e,edit:C(e.edit),supports:{...e.supports,"jetpack/ai":{assistant:!0}}}:e}),100)},4393:(e,t,n)=>{"use strict";n.d(t,{A:()=>m});var a=n(96865),r=n(47143),s=n(86087),o=n(10067),i=n.n(o),l=n(62402),c=n(64425),u=n(16597),d=n(32735);const p=i()("jetpack-ai-assistant:error"),m=({attributes:e,clientId:t,content:n,tracks:o,userPrompt:i,onSuggestionDone:m,onUnclearPrompt:h,onModeration:g,requireUpgrade:f,initialRequestingState:v,contentRef:b,blockRef:k})=>{const[y,E]=(0,s.useState)(!1),[w,_]=(0,s.useState)(""),{updateBlockAttributes:C}=(0,r.useDispatch)("core/block-editor"),{dequeueAiAssistantFeatureAsyncRequest:A,setAiAssistantFeatureRequireUpgrade:x}=(0,r.useDispatch)("wordpress-com/plans"),{snapToBottom:j,enableAutoScroll:S,disableAutoScroll:N}=(0,d.A)(k,b),R=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("title"))),P=(0,r.useSelect)((e=>e("core/editor").getCurrentPostId())),L=(0,s.useRef)([]),T=(0,s.useRef)(void 0),{request:B,stopSuggestion:M,handleErrorQuotaExceededError:I,requestingState:D,error:F}=(0,a.o2)({onSuggestion:e=>{C(t,{content:e?.replaceAll(c.uV,"")}),j()},onDone:e=>{const n=e.replaceAll(c.uV,""),a={role:"assistant",content:n};L.current.push(T.current,a),L.current.length>20&&L.current.splice(0,L.current.length-20),C(t,{content:n,messages:L.current}),j(),N(),m?.()},onStop:()=>{j(),N(),m?.()},onError:e=>{switch(e?.code){case a.cT:E(!1);break;case a.ud:E(!1),g?.();break;case a.mA:case a.AZ:E(!0);break;case a.Or:E(!1),x(!0);break;case a.L9:h?.()}},onAllErrors:e=>{p(e)},initialRequestingState:v,askQuestionOptions:{postId:P,feature:"ai-assistant",functions:{}}}),z=["requesting","suggesting"].includes(D),O=async(a,r={})=>{if(A(),f)return I(),void E(!1);if(r={retryRequest:!1,tone:l.US,...r},z)return;E(!1);let s=w;if(o.recordEvent("jetpack_ai_chat_completion",{post_id:P}),L.current=[...e.messages]??[],T.current={},r.retryRequest)T.current=s[s.length-1];else{const o=e?.isLayoutBuldingModeEnable?(0,u.rJ)(t):(0,u.aB)();s=(0,c.jf)({generatedContent:n,allPostContent:o,postContentAbove:(0,u.b$)(t),currentPostTitle:R,options:r,userPrompt:r?.userPrompt||i,type:a,isGeneratingTitle:"generateTitle"===e.promptType}),T.current=s.pop(),s=[...s,...L.current],s.push(T.current),_(s),"generateTitle"!==e.promptType&&C(t,{promptType:a})}try{S(),await B(s)}catch(e){p(e),E(!0),N()}};return{setShowRetry:E,showRetry:y,postTitle:R,contentBefore:(0,u.b$)(t),wholeContent:(0,u.aB)(),requestingState:D,error:F,getSuggestionFromOpenAI:O,stopSuggestion:M,retryRequest:()=>O("",{retryRequest:!0})}}},92169:(e,t,n)=>{"use strict";n.d(t,{A:()=>l});var a=n(3924),r=n(85985),s=n(10617),o=n(61297);const i=()=>{const e=new URLSearchParams(window.location.search),t=(0,r.GE)();return(0,r.Sy)()&&e.has("post")?`https://wordpress.com/post/${t}/${e.get("post")}`:`https://wordpress.com/home/${t}`};function l(){const{nextTier:e,tierPlansEnabled:t}=(0,o.A)(),n=i(),l=(0,a.A)("jetpack-ai-yearly-tier-upgrade-nudge",{site:(0,r.GE)(),path:t?`jetpack_ai_yearly:-q-${e?.limit}`:"jetpack_ai_yearly",query:`redirect_to=${encodeURIComponent(n)}`}),c=(0,a.A)("jetpack-ai-upgrade-url-for-jetpack-sites",{site:(0,r.GE)(),path:"jetpack_ai_yearly"}),u=(0,r.d9)()||(0,r.Sy)()?l:c,{autosaveAndRedirect:d,isRedirecting:p}=(0,s.A)(u);return{checkoutUrl:u,autosaveAndRedirect:d,isRedirecting:p}}},61297:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var a=n(47143),r=n(58164);function s(){const{data:e,loading:t,requestsLimit:n,requestsCount:s}=(0,a.useSelect)((e=>{const{getAiAssistantFeature:t,getIsRequestingAiAssistantFeature:n}=e("wordpress-com/plans"),a=t(),{currentTier:s,usagePeriod:o,requestsCount:i,requestsLimit:l}=a,c=(0,r.Bd)(s),u=s?.limit||l,d=c===r._X?i:o?.requestsCount,p=c===r._X?l:u;return{data:a,loading:n(),requestsCount:d,requestsLimit:p}}),[]),{fetchAiAssistantFeature:o,increaseAiAssistantRequestsCount:i,dequeueAiAssistantFeatureAsyncRequest:l}=(0,a.useDispatch)("wordpress-com/plans");return{...e,requestsCount:s,requestsLimit:n,loading:t,error:null,refresh:o,increaseRequestsCount:i,dequeueAsyncRequest:l}}},44732:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var a=n(3924),r=n(85985),s=n(10617);function o(){const e=(0,r.$i)()?.jetpack?.is_my_jetpack_available,t=e?`${(0,r.$i)()?.adminUrl||""}admin.php?page=my-jetpack#/jetpack-ai`:(0,a.A)("org-ai"),{autosaveAndRedirect:n,isRedirecting:o}=(0,s.A)(t);return{productPageUrl:t,autosaveAndRedirect:n,isRedirecting:o,isMyJetpackAvailable:e}}},75956:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var a=n(90372),r=n(86087);const s=window?.Jetpack_Editor_Initial_State?.tracksUserData||null,o=parseInt(window?.Jetpack_Editor_Initial_State?.wpcomBlogId)||0,i=()=>((0,r.useEffect)((()=>{s&&a.A.initialize(s?.userid,s?.username,o?{blog_id:o}:{})}),[]),a.A)},32735:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var a=n(86087),r=n(10067);const s=n.n(r)()("jetpack-ai-assistant:use-auto-scroll"),o=(e,t,n=!1)=>{const r=(0,a.useRef)(null),o=(0,a.useRef)(null),i=(0,a.useRef)(!1),l=(0,a.useRef)(!1),c=(0,a.useRef)(!1),u=(0,a.useRef)(!1),d=(0,a.useRef)({scrollPadding:"",scrollMargin:""}),p=(0,a.useCallback)((()=>{s("enabling ignore scroll"),l.current=!0}),[]),m=(0,a.useCallback)((()=>{i.current&&c.current&&!l.current&&p()}),[p]),h=(0,a.useCallback)((()=>{i.current=!0,l.current=!1,c.current=!1,u.current=!1,r.current?.addEventListener("scroll",m),s("enabling auto scroll")}),[m]),g=(0,a.useCallback)((()=>{i.current=!1,l.current=!1,c.current=!1,u.current=!1,r.current?.removeEventListener("scroll",m),o.current?.style&&(o.current.style.scrollPadding=d.current.scrollPadding,o.current.style.scrollMargin=d.current.scrollMargin),r.current=null,s("disabling auto scroll")}),[m]),f=(0,a.useCallback)((()=>{if(!i.current||l.current)return;const a=n?e?.current:t?.current?.firstElementChild?.lastElementChild;a&&!u.current&&(c.current=!0,u.current=!0,r?.current?.removeEventListener?.("scroll",m),a?.scrollIntoView({block:"end",inline:"end"}),setTimeout((()=>{u.current=!1,r?.current?.addEventListener?.("scroll",m)}),200))}),[e,t,n,m]),v=(0,a.useCallback)((e=>{if(null==e)return null;if("BODY"===e?.nodeName)return e;if(e?.ownerDocument!==document)return e.ownerDocument;const{overflow:t}=window.getComputedStyle(e);return t.split(" ").every((e=>"auto"===e||"scroll"===e))?e:e?.parentElement?v(e?.parentElement):e}),[]);return(0,a.useEffect)((()=>{const t=v(e?.current?.parentElement);!r.current&&t&&(r.current=t,o.current=t instanceof HTMLElement?t:t.documentElement,d.current={scrollPadding:o.current.style.scrollPadding,scrollMargin:o.current.style.scrollMargin},i.current&&(o.current.style.scrollPadding="80px",o.current.style.scrollMargin="10px"))}),[e,v]),{snapToBottom:f,enableAutoScroll:h,disableAutoScroll:g}}},35317:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var a=n(85985);const r={"jetpack/contact-form":"contact-form"};function s(e){const t=r[e],{isModuleActive:n}=(0,a.q7)(t);return!t||n}},76695:(e,t,n)=>{"use strict";n.d(t,{A:()=>c,y:()=>l});var a=n(85985),r=n(47143),s=n(51609),o=n(16597),i=n(13802);function l(e){return`ai-assistant-block-${e}`}const c=()=>{const{replaceBlock:e,removeBlocks:t}=(0,r.useDispatch)("core/block-editor"),n=(0,r.useSelect)((e=>e("core/block-editor")),[]),{getSelectedBlockClientIds:c,getBlocksByClientId:u,getBlock:d,getBlockParents:p}=n,{tracks:m}=(0,a.st)();return{canTransformToAIAssistant:(0,s.useCallback)((({clientId:e,blockName:t})=>{if(!d(e))return!1;if(!i.y7.includes(t))return!1;const n=p(e);if(0===n.length)return!0;const a=d(n[n.length-1]);return!["core/list","core/list-item"].includes(a.name)}),[d,p]),transformToAIAssistant:(0,s.useCallback)((({request:n}={})=>{const a=c(),r=u(a),s=(0,o.Sb)(r),[d]=r,[p,...h]=a,g={...d?.attributes||{},content:s},f=(0,i.rr)(d.name,g);if(n?.promptType){m.recordEvent("jetpack_editor_ai_assistant_extension_toolbar_button_click",{suggestion:n.promptType,block_type:d.name});const e={clientId:p,type:n.promptType,options:{...n.options,contentType:"generated",fromExtension:!0}};localStorage.setItem(l(f.clientId),JSON.stringify(e))}else m.recordEvent("jetpack_ai_assistant_prompt_show",{block_type:d.name});e(p,f),t(h)}),[u,c,t,e,m]),getSelectedBlockClientIds:c}}},7503:(e,t,n)=>{"use strict";n.d(t,{C:()=>d,x:()=>u});var a=n(85985),r=n(10067),s=n.n(r);const o=window?.JP_CONNECTION_INITIAL_STATE,i=s()("jetpack-ai-assistant:connection");let l=!1;const c=e=>{l||(i(e),l=!0)};function u(){return(0,a.Sy)()?(c("Simple site connected ✅"),!0):(0,a.d9)()?(c("Atomic site connected ✅"),!0):o?.connectionStatus?.isUserConnected?(c("Jetpack user is connected ✅"),!0):(c("User is not connected ❌"),!1)}function d(){if((0,a.Sy)())return!0;return!1==!(o?.userConnectionData?.currentUser?.permissions??{}).manage_options}},4e4:(e,t,n)=>{"use strict";n.d(t,{J1:()=>i,K6:()=>l,p$:()=>u});var a=n(64425);const r="title",s="content",o=null;function i(e){return{role:"jetpack-ai",context:{type:"ai-assistant-initial-prompt",for:u(e)}}}function l({generatedContent:e,allPostContent:t,postContentAbove:n,currentPostTitle:r,options:s,type:o,userPrompt:i,isGeneratingTitle:l}){const u=[],d="generated"===s?.contentType;let p=null;switch(o){case a.im:p=r;break;case a.sn:case a.A4:case a.yy:p=n;break;case a.vE:p=t;break;case a.br:case a.fD:p=e;break;case a.eJ:case a.UA:case a.Gm:p=d?e:t;break;case a.d5:p=n;break;case a.pE:p=e||t}const m=function(e,t){return!e&&t&&t.length>0?{role:"jetpack-ai",context:{type:"ai-assistant-relevant-content",content:t}}:null}(o===a.pE?!!e?.length:d,p);return m&&u.push(m),u.push({role:"jetpack-ai",context:c({generatedContent:e,allPostContent:t,postContentAbove:n,currentPostTitle:r,options:s,type:o,userPrompt:i,isGeneratingTitle:l})}),u}function c({options:e,type:t,userPrompt:n,isGeneratingTitle:i}){const l=function(e,t,n){return e?r:!t||n?s:o}(i,"generated"===e?.contentType,e?.fromExtension||!1);return{type:u(t),...l?{subject:l}:{},...t===a.eJ&&e?.tone?{tone:e.tone}:{},...t===a.Gm&&e?.language?{language:e.language}:{},...t===a.pE&&n?{request:n}:{}}}function u(e,t){const n={[a.im]:"ai-assistant-summary-by-title",[a.sn]:"ai-assistant-continue-writing",[a.A4]:"ai-assistant-simplify",[a.yy]:"ai-assistant-correct-spelling",[a.vE]:"ai-assistant-generate-title",[a.br]:"ai-assistant-make-longer",[a.fD]:"ai-assistant-make-shorter",[a.eJ]:"ai-assistant-change-tone",[a.UA]:"ai-assistant-summarize",[a.Gm]:"ai-assistant-change-language",[a.pE]:"ai-assistant-user-prompt",[a.d5]:"ai-assistant-transform-list-to-table"};return"form-ai"===t?"form-ai-extension":t?`${n[e]}-${t}-extension`:n[e]}},64425:(e,t,n)=>{"use strict";n.d(t,{A4:()=>o,Gm:()=>m,UA:()=>p,br:()=>c,d5:()=>g,eJ:()=>d,fD:()=>u,im:()=>r,jf:()=>v,pE:()=>h,sn:()=>s,uV:()=>f,vE:()=>l,yy:()=>i});var a=n(4e4);const r="titleSummary",s="continue",o="simplify",i="correctSpelling",l="generateTitle",c="makeLonger",u="makeShorter",d="changeTone",p="summarize",m="changeLanguage",h="userPrompt",g="transformListToTable",f="````";function v({generatedContent:e,allPostContent:t,postContentAbove:n,currentPostTitle:r,options:s,type:o,userPrompt:i,isGeneratingTitle:l}){return[(0,a.J1)(o),...(0,a.K6)({generatedContent:e,allPostContent:t,postContentAbove:n,currentPostTitle:r,options:s,type:o,userPrompt:i,isGeneratingTitle:l})]}},16597:(e,t,n)=>{"use strict";n.d(t,{Sb:()=>l,aB:()=>i,b$:()=>o,rJ:()=>c});var a=n(96865),r=n(74997),s=n(47143);function o(e){if(!e)return"";const t=(0,s.select)("core/block-editor"),n=t.getBlockIndex(e),o=t.getBlocks().slice(0,n)??[];return o?.length?(0,a.rh)({content:(0,r.serialize)(o)}):""}function i(){const e=(0,s.select)("core/block-editor").getBlocks();return e?.length?(0,a.rh)({content:(0,r.serialize)(e)}):""}function l(e){return e.filter((e=>null!=e)).map((e=>(0,r.getBlockContent)(e))).join("\n\n")}function c(e){const t=(0,s.select)("core/block-editor").getBlock(e);return t?.innerBlocks?.length?l(t.innerBlocks):""}},47264:(e,t,n)=>{"use strict";function a(e){return e&&"string"==typeof e?e.charAt(0).toUpperCase()+e.slice(1):""}n.d(t,{Z:()=>a})},62514:(e,t,n)=>{"use strict";n.d(t,{w:()=>s});const a=e=>{delete e.clientId;for(const t of e.innerBlocks??[])a(t);return e},r=e=>a((e=>JSON.parse(JSON.stringify(e)))(e));function s(e,t){const n=r(e),a=r(t);return JSON.stringify(n)===JSON.stringify(a)}},96568:(e,t,n)=>{"use strict";function a(e){const t=document.createElement("div");return t.innerHTML=e,t.innerHTML}n.d(t,{d:()=>a})},48499:(e,t,n)=>{"use strict";n.d(t,{C:()=>r});var a=n(85985);function r(e){return!0===(0,a.FB)(e).available}},13802:(e,t,n)=>{"use strict";n.d(t,{Ay:()=>c,rr:()=>l,y7:()=>o});var a=n(96865),r=n(74997),s=n(54681);const o=["core/heading","core/paragraph","core/list"],i=[];function l(e,t){const{content:n,...o}=t;let i=n;"core/heading"===e&&t?.level&&(i=i.replace(/<(\/?)h\d([^>]*)>/g,`<$1h${t.level}$2>`));const l=(0,a.rh)({content:i}),c=[];return c.push({role:"jetpack-ai",context:{type:"ai-assistant-relevant-content",content:l}}),(0,r.createBlock)(s.name,{...o,content:l,originalContent:l,messages:c,originalMessages:c})}for(const e of o)i.push({type:"block",blocks:[e],isMatch:()=>o.includes(e),transform:(t,n)=>{const a=(0,r.getSaveContent)(e,t,n);return l(e,{...t,content:a})}});const c={from:i}},36920:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var a=n(82170),r=n(27723),s=n(56333),o=n(10617);const __=r.__,i=()=>{let e=window?.Jetpack_Editor_Initial_State?.adminUrl||"";e=e.replace(/wp-admin\/\?frame-nonce=[a-z0-9]+/,"wp-admin/");const t=`${e}admin.php?page=jetpack-search`,{autosaveAndRedirect:n,isRedirecting:r}=(0,o.A)(t);if(window?.Jetpack_AIChatBlock?.jetpackSettings?.instant_search_enabled)return null;return(0,a.createElement)(s.c,{buttonText:__("Enable Jetpack Search","jetpack"),checkoutUrl:t,className:"jetpack-ai-connect-banner",description:__("You need to enable Jetpack Search so that Jetpack AI can index your site.","jetpack"),goToCheckoutPage:e=>{n(e)},isRedirecting:r,visible:!0,align:null,title:null,context:null})}},50443:(e,t,n)=>{"use strict";n.d(t,{G:()=>s,W:()=>r});var a=n(27723);const __=a.__,r=__("Ask","jetpack"),s=__("Ask a question about this site","jetpack")},51686:(e,t,n)=>{"use strict";n.d(t,{z:()=>c});var a=n(82170),r=n(94715),s=n(56427),o=n(3582),i=n(27723),l=n(50443);const __=i.__;function c({setAttributes:e,placeholder:t,showCopy:n,showFeedback:i,showSources:c}){const[u,d]=(0,o.useEntityProp)("root","site","jetpack_search_ai_prompt_override");return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.InspectorControls,null,(0,a.createElement)(s.PanelBody,{title:__("Settings","jetpack"),initialOpen:!1},(0,a.createElement)(s.TextControl,{label:__("Placeholder Text","jetpack"),className:"jetpack-ai-chat__ask-button-text",placeholder:l.G,onChange:t=>e({placeholder:t}),value:t,__nextHasNoMarginBottom:!0}))),(0,a.createElement)(r.InspectorAdvancedControls,null,(0,a.createElement)(s.TextareaControl,{label:__("Additional instructions","jetpack"),help:__("Give Jetpack AI additional instructions for answer length, format, and tone.","jetpack"),value:u,onChange:d,__nextHasNoMarginBottom:!0}),(0,a.createElement)(s.ToggleControl,{label:__("Show copy answer button.","jetpack"),help:__("Allow users to easily copy the answer.","jetpack"),checked:n,onChange:t=>e({showCopy:t}),__nextHasNoMarginBottom:!0}),(0,a.createElement)(s.ToggleControl,{label:__("Show rating button.","jetpack"),help:__("Allow users to rate the answer and give feedback.","jetpack"),checked:i,onChange:t=>e({showFeedback:t}),__nextHasNoMarginBottom:!0}),(0,a.createElement)(s.ToggleControl,{label:__("Show list of sources.","jetpack"),help:__("Show used sources at the bottom of the answer.","jetpack"),checked:c,onChange:t=>e({showSources:t}),__nextHasNoMarginBottom:!0})))}},32908:(e,t,n)=>{"use strict";n.d(t,{A:()=>m});var a=n(82170),r=n(96865),s=n(94715),o=n(56427),i=n(47143),l=n(2274),c=n(26247),u=n(36920),d=n(50443),p=n(51686);function m({attributes:e,setAttributes:t,clientId:n}){const{askButtonLabel:m=d.W,placeholder:h=d.G,showCopy:g,showFeedback:f,showSources:v}=e,b=(0,s.useBlockProps)(),k=(0,i.useSelect)((e=>e("core/block-editor").isBlockSelected(n)),[n]),y=(0,c.A)();return(0,a.createElement)("div",b,!y&&(0,a.createElement)(l.A,{block:"Jetpack AI Search"}),(0,a.createElement)(u.A,null),(0,a.createElement)("div",{className:"jetpack-ai-chat-question-wrapper"},(0,a.createElement)(o.TextControl,{className:"jetpack-ai-chat-question-input",placeholder:h,disabled:!0,__nextHasNoMarginBottom:!0}),(0,a.createElement)(s.RichText,{className:"wp-block-button__link jetpack-ai-chat-question-button",onChange:e=>t({askButtonLabel:e}),value:m,withoutInteractiveFormatting:!0,allowedFormats:["core/bold","core/italic","core/strikethrough"]})),k&&(0,a.createElement)(r.Yj,null),(0,a.createElement)(s.InspectorControls,null,(0,a.createElement)(p.z,{askButtonLabel:m,placeholder:h,setAttributes:t,showCopy:g,showFeedback:f,showSources:v})))}},8393:(e,t,n)=>{"use strict";var a=n(94375),r=n(1629),s=n(32908),o=n(41825);(0,a.M)(r,{edit:s.A,save:o.A})},41825:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var a=n(82170),r=n(94715),s=n(50443);function o({attributes:e}){const t=r.useBlockProps.save({"data-ask-button-label":e.askButtonLabel||s.W});return(0,a.createElement)("div",t)}},97571:(e,t,n)=>{"use strict";n.d(t,{z:()=>o});var a=n(82170),r=n(56427),s=n(27723);const __=s.__;function o({attributes:e,setAttributes:t}){const{statsData:n,statsOption:s}=e,o=[{value:"views",label:__("Views","jetpack")},{value:"visitors",label:__("Visitors","jetpack")}],i=[{value:"site",label:__("My whole site","jetpack")},{value:"post",label:__("This individual post","jetpack")}];return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.PanelBody,{title:__("Settings","jetpack")},(0,a.createElement)(r.RadioControl,{label:__("Views or visitors","jetpack"),selected:n,onChange:e=>t({statsData:e}),options:o,help:__("Views represent site visits, whereas visitors represent unique individuals.","jetpack")}),(0,a.createElement)(r.RadioControl,{label:__("Show stats data for","jetpack"),selected:s,onChange:e=>t({statsOption:e}),options:i,disabled:"visitors"===n,help:"visitors"===n?__("Visitor counts aren't available for individual posts.","jetpack"):null}),(0,a.createElement)("span",{className:"jetpack-blog-stats__delay-notice"},__("Stats are delayed for up to 5 minutes.","jetpack"))))}},20201:(e,t,n)=>{"use strict";n.d(t,{A:()=>h});var a=n(82170),r=n(37975),s=n(85985),o=n(1455),i=n.n(o),l=n(94715),c=n(47143),u=n(86087),d=n(27723),p=n(97571),m=n(51744);const __=d.__,_n=d._n;const h=function({attributes:e,className:t,setAttributes:n}){const{isLoadingModules:o,isChangingStatus:d,isModuleActive:h,changeStatus:g}=(0,s.q7)("stats"),{label:f,statsData:v,statsOption:b}=e,[k,y]=(0,u.useState)(null),[E,w]=(0,u.useState)(),[_,C]=(0,u.useState)(),A=(0,l.useBlockProps)(),x="post"===b?_:"views"===v?k:E,j=(0,c.useSelect)((e=>e("core/editor").getCurrentPostId()),[]);if((0,u.useEffect)((()=>{h&&i()({path:Number.isInteger(j)?`/wpcom/v2/blog-stats?post_id=${j}`:"/wpcom/v2/blog-stats"}).then((e=>{y(e["blog-views"]),w(e["blog-visitors"]),C(Number.isInteger(j)?e["post-views"]:"12345")}))}),[j,h]),(0,u.useEffect)((()=>{"visitors"===v&&n({statsOption:"site"})}),[v,n]),!h&&!o)return(0,a.createElement)(m.k,{className:t,changeStatus:g,isLoading:d});const S=/* Translators: Number of visitors */ +__("Upgrade to %d requests","jetpack"),v.limit),checkoutUrl:c,className:"jetpack-ai-upgrade-banner",description:t||e,goToCheckoutPage:w,visible:!0,align:"center",title:null,context:null,target:"_blank"})}return(0,a.createElement)(o,{buttonText:"Upgrade",checkoutUrl:c,className:"jetpack-ai-upgrade-banner",description:(0,i.createInterpolateElement)(__("Congratulations on exploring Jetpack AI and reaching the free requests limit! Upgrade now to keep using it.","jetpack"),{strong:(0,a.createElement)("strong",null)}),goToCheckoutPage:w,visible:!0,align:null,title:null,context:null,target:"_blank"})})(e)}},93094:(e,t,n)=>{"use strict";n.d(t,{U:()=>o});var a=n(82170),r=n(56427),s=n(27723);const __=s.__,o=({title:e,description:t,buttonText:n=null,checkoutUrl:s=null,goToCheckoutPage:o=null,isRedirecting:i=!1,showButton:l=!0,target:c="_top"})=>{const u=__("Redirecting…","jetpack");return(0,a.createElement)("div",{className:"jetpack-upgrade-plan-banner-light"},(0,a.createElement)(r.Notice,{status:"error",isDismissible:!1},(0,a.createElement)("p",null,e&&(0,a.createElement)("strong",null,e),t," ",l&&(0,a.createElement)(r.Button,{href:i?null:s,onClick:o,variant:"link",target:c},i?u:n))))}},62402:(e,t,n)=>{"use strict";n.d(t,{Ay:()=>g,US:()=>u,hN:()=>h,oZ:()=>p,uQ:()=>d});var a=n(82170),r=n(96865),s=n(85985),o=n(56427),i=n(27723),l=n(29115);n(51609);const __=i.__,c=["formal","informal","optimistic","humorous","serious","skeptical","empathetic","confident","passionate","provocative"],u="formal",d=__("Change tone","jetpack"),p={formal:{label:__("Formal","jetpack"),emoji:"🎩"},informal:{label:__("Informal","jetpack"),emoji:"😊"},optimistic:{label:__("Optimistic","jetpack"),emoji:"😃"},humorous:{label:__("Humorous","jetpack"),emoji:"😂"},serious:{label:__("Serious","jetpack"),emoji:"😐"},skeptical:{label:__("Skeptical","jetpack"),emoji:"🤨"},empathetic:{label:__("Empathetic","jetpack"),emoji:"💗"},confident:{label:__("Confident","jetpack"),emoji:"😎"},passionate:{label:__("Passionate","jetpack"),emoji:"❤️"},provocative:{label:__("Provocative","jetpack"),emoji:"🔥"}},m=({value:e,onChange:t})=>(0,a.createElement)(o.MenuGroup,{label:__("Select tone","jetpack")},c.map((n=>(0,a.createElement)(o.MenuItem,{key:`key-${n}`,onClick:()=>t(n),isSelected:e===n},`${p[n].emoji} ${p[n].label}`))));function h({label:e=d,value:t=u,onChange:n,disabled:s=!1}){return(0,a.createElement)(o.DropdownMenu,{icon:r.Qr,label:e,className:"ai-assistant__tone-dropdown",popoverProps:{variant:"toolbar"},toggleProps:{children:(0,a.createElement)(a.Fragment,null,(0,a.createElement)("div",{className:"ai-assistant__tone-dropdown__toggle-label"},e),(0,a.createElement)(o.Icon,{icon:l.A})),disabled:s}},(({onClose:e})=>(0,a.createElement)(m,{value:t,onChange:t=>{n(t),e()}})))}function g({value:e=u,onChange:t,disabled:n=!1}){const{tracks:i}=(0,s.st)();return n?(0,a.createElement)(o.Tooltip,{text:d},(0,a.createElement)(o.Button,{disabled:!0},(0,a.createElement)(o.Icon,{icon:r.Qr}))):(0,a.createElement)(o.ToolbarDropdownMenu,{icon:r.Qr,label:d,popoverProps:{variant:"toolbar"},disabled:n,onToggle:e=>{e&&i.recordEvent("jetpack_ai_assistant_block_toolbar_menu_show",{tool:"tone"})}},(()=>(0,a.createElement)(m,{value:e,onChange:t})))}},51698:(e,t,n)=>{"use strict";n.d(t,{A:()=>h});var a=n(82170),r=n(94715),s=n(56427),o=n(27723),i=n(83883),l=n(83822),c=n(64425),u=n(2162),d=n(99050),p=n(33468),m=n(62402);const __=o.__,h=({contentIsLoaded:e,getSuggestionFromOpenAI:t,retryRequest:n,handleAcceptContent:o,handleTryAgain:h,showRetry:g,contentBefore:f,hasPostTitle:v,wholeContent:b,setUserPrompt:k,recordEvent:y,isGeneratingTitle:E})=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.BlockControls,null,!g&&(0,a.createElement)(a.Fragment,null,(0,a.createElement)(s.ToolbarGroup,null,(0,a.createElement)(p.Ay,{hasContentBefore:!!f?.length,hasContent:!!b?.length,hasPostTitle:v,contentIsLoaded:e,onPromptSelect:e=>{y("jetpack_editor_ai_assistant_block_toolbar_button_click",{type:"prompt-template",prompt:e.original}),k(e.translated)},onSuggestionSelect:e=>{y("jetpack_editor_ai_assistant_block_toolbar_button_click",{type:"suggestion",suggestion:e}),t(e)}})),(0,a.createElement)(r.BlockControls,{group:"block"},(0,a.createElement)(m.Ay,{value:"neutral",onChange:n=>{y("jetpack_editor_ai_assistant_block_toolbar_button_click",{type:"suggestion",suggestion:c.eJ}),t(c.eJ,{tone:n,contentType:e?"generated":null})},disabled:!e&&!b?.length}),(0,a.createElement)(u.Ay,{value:"en",onChange:n=>{y("jetpack_editor_ai_assistant_block_toolbar_button_click",{type:"suggestion",suggestion:c.Gm}),t(c.Gm,{language:n,contentType:e?"generated":null})},disabled:!e&&!b?.length}),(0,a.createElement)(d.Ay,{onChange:t,exclude:E?["summarize"]:[],disabled:!e}))),(g||h)&&(0,a.createElement)(s.ToolbarGroup,null,!g&&e&&h&&(0,a.createElement)(s.ToolbarButton,{onClick:h},__("Try Again","jetpack")),g&&e&&(0,a.createElement)(s.ToolbarButton,{icon:i.A,onClick:o},__("Accept","jetpack")),g&&(0,a.createElement)(s.ToolbarButton,{icon:l.A,onClick:n},__("Retry","jetpack")))))},3586:(e,t,n)=>{"use strict";n.d(t,{A:()=>S});var a=n(82170),r=n(96865),s=n(85985),o=n(94715),i=n(74997),l=n(56427),c=n(29491),u=n(47143),d=n(86087),p=n(27723),m=n(13022),h=n(27970),g=n(56199),f=n(2274),v=n(58164),b=n(32249),k=n(23e3),y=n(51698),E=n(4393),w=n(92169),_=n(61297),C=n(44732),A=n(76695),x=n(7503);const __=p.__,j="post"===window?.Jetpack_Editor_Initial_State?.screenBase;function S({attributes:e,setAttributes:t,clientId:n,isSelected:p}){const[S,N]=(0,d.useState)(null),{tracks:R}=(0,s.st)(),{getBlock:P}=(0,u.useSelect)("core/block-editor"),L=(0,d.useRef)(null),T=(0,d.useRef)(null),{replaceBlocks:B,removeBlock:M}=(0,u.useDispatch)("core/block-editor"),{editPost:I}=(0,u.useDispatch)("core/editor"),{isOverLimit:D,requireUpgrade:F,increaseRequestsCount:z,requestsCount:O,requestsLimit:H,currentTier:U,loading:V,tierPlansEnabled:q}=(0,_.A)(),G=Math.max(H-O,0),{autosaveAndRedirect:$}=(0,w.A)(),W=(0,v.Bd)(U),Z=()=>{setTimeout((()=>{L.current?.focus?.()}),100)},J=()=>{setTimeout((()=>{T.current?.focus?.()}),100)},K=(0,c.useViewportMatch)("medium","<"),Y=(0,d.useRef)(null),{getSuggestionFromOpenAI:Q,stopSuggestion:X,showRetry:ee,contentBefore:te,postTitle:ne,retryRequest:ae,wholeContent:re,requestingState:se,error:oe}=(0,E.A)({onSuggestionDone:(0,d.useCallback)((()=>{Z(),z()}),[z]),onUnclearPrompt:(0,d.useCallback)((()=>{J(),z()}),[z]),onModeration:Z,attributes:e,clientId:n,content:e.content,tracks:R,userPrompt:e.userPrompt,requireUpgrade:F,initialRequestingState:e.requestingState,contentRef:Y,blockRef:T}),ie="requesting"===se,le=["requesting","suggesting"].includes(se),ce=(0,x.x)(),{productPageUrl:ue}=(0,C.A)(),de=(0,A.y)(n);(0,d.useEffect)((()=>{if(!de)return;const e=JSON.parse(localStorage.getItem(de));if(!e)return;const{type:t,options:n}=e;localStorage.removeItem(de),Q(t,n)}),[de,Q]),(0,d.useEffect)((()=>{oe&&N(!1)}),[oe]),(0,d.useEffect)((()=>{["init","done"].includes(se)&&t({requestingState:se})}),[se,t]);const pe=!!e.content,me="generateTitle"===e.promptType,he=__("Accept","jetpack"),ge=__("Accept title","jetpack"),fe=me?ge:he,ve=async()=>{let t=[],a=(0,r._E)({content:e.content||""});if(a?.split("\n").length>1&&a?.split("\n")?.[0]?.match(/^

.*<\/h1>$/)&&!ne){const e=a.split("\n"),t=e.shift();a=e.join("\n"),I({title:t.replace(/<[^>]*>/g,"")})}t=(0,i.rawHandler)({HTML:a}),await B(n,t);const s=(e=>{let t=null;return e.forEach((e=>{const n=document.querySelector(`.wp-block[data-block="${e.clientId}"]`);if(!n)return;"true"===n.contentEditable&&(t=n);const a=n.querySelectorAll("[contenteditable=true]");t=a.length?a[a.length-1]:t})),t})(t);s&&(e=>{const t=e.ownerDocument.getSelection();t.selectAllChildren(e),t.collapseToEnd(),e.focus()})(s)},be=()=>{ve(),R.recordEvent("jetpack_ai_assistant_block_accept",{feature:"ai-assistant"})},ke=()=>{j?(I({title:e.content?e.content.trim():""}),M(n),R.recordEvent("jetpack_ai_assistant_block_accept",{feature:"ai-assistant"})):be()},ye=()=>{X(),Z(),R.recordEvent("jetpack_ai_assistant_block_stop",{feature:"ai-assistant"})},Ee=(0,o.useBlockProps)({ref:T,className:(0,m.A)({"is-waiting-response":ie})}),we=__("Ask Jetpack AI…","jetpack"),_e=__("Write about… Make a table for…","jetpack"),Ce=(0,a.createElement)(a.Fragment,null,D&&p&&(0,a.createElement)(k.A,{placement:"ai-assistant-block"}),!ce&&(0,a.createElement)(f.A,{block:"AI Assistant"})),Ae=(0,a.createElement)(a.Fragment,null,oe?.message&&!S&&"error_quota_exceeded"!==oe?.code&&(0,a.createElement)(l.Notice,{status:oe.status,isDismissible:!1,className:"jetpack-ai-assistant__error"},oe.message)),xe=D&&W===v.Ti?(0,a.createElement)(k.Q,{variant:"muted"}):null,je=(0,d.useCallback)((e=>{e.preventDefault(),R.recordEvent("jetpack_ai_upgrade_button",{current_tier_slug:U?.slug,requests_count:O,placement:"jetpack_ai_assistant_block"}),$(e)}),[R,U,O,$]);return(0,a.createElement)(l.KeyboardShortcuts,{bindGlobal:!0,shortcuts:{esc:()=>{["requesting","suggesting"].includes(se)&&ye()}}},(0,a.createElement)("div",Ee,pe&&(0,a.createElement)("div",{ref:Y,className:"jetpack-ai-assistant__content"},(0,a.createElement)(d.RawHTML,null,(0,r._E)({content:e.content||""}))),(0,a.createElement)(o.InspectorControls,null,xe&&(0,a.createElement)("div",{className:"block-editor-block-card",style:{paddingTop:0}},(0,a.createElement)("span",{className:"block-editor-block-icon"}),xe),(0,a.createElement)("div",{className:"block-editor-block-card",style:{paddingTop:0}},(0,a.createElement)("span",{className:"block-editor-block-icon"}),(0,a.createElement)(l.ExternalLink,{href:ue},__("Discover all features","jetpack"))),(W===v._X||q&&W!==v.Ti)&&(0,a.createElement)(l.PanelBody,{initialOpen:!0},(0,a.createElement)(l.PanelRow,null,(0,a.createElement)(h.A,{placement:g.k}))),(0,a.createElement)(l.PanelBody,{initialOpen:!0},(0,a.createElement)(l.PanelRow,null,(0,a.createElement)(b.A,null)))),!le&&ce&&!F&&(0,a.createElement)(y.A,{isWaitingState:le,contentIsLoaded:pe,getSuggestionFromOpenAI:Q,retryRequest:ae,handleAcceptContent:be,handleAcceptTitle:ke,handleTryAgain:null,showRetry:ee,contentBefore:te,hasPostTitle:!!ne?.length,wholeContent:re,promptType:e.promptType,setUserPrompt:e=>{if(!L?.current)return;L.current.focus(),t({userPrompt:e})},recordEvent:R.recordEvent,isGeneratingTitle:me}),(0,a.createElement)(r.N0,{ref:L,disabled:F||!ce,value:e.userPrompt,placeholder:e?.content?we:_e,onChange:e=>{N(!0),t({userPrompt:e})},onSend:()=>{((...e)=>{Q(...e),J()})("userPrompt"),R.recordEvent("jetpack_ai_assistant_block_generate",{feature:"ai-assistant"})},onStop:ye,onAccept:()=>{me?ke():be()},onDiscard:()=>{const a=e?.content===P(n).attributes?.content;t({content:e?.originalContent,promptType:void 0,messages:e?.originalMessages}),ve(),a?R.recordEvent("jetpack_ai_assistant_block_dismiss"):R.recordEvent("jetpack_ai_assistant_block_discard",{feature:"ai-assistant"})},state:se,isTransparent:F||!ce,showButtonLabels:!K,showAccept:"init"!==se&&pe&&!le,acceptLabel:fe,showGuideLine:pe,showRemove:e?.content?.length>0,banner:Ce,error:Ae,customFooter:G%5!=0&&1!==O||V||W!==v._X?null:(0,a.createElement)(r.AK,{requestsRemaining:G,onUpgradeClick:je})})))}},61351:(e,t,n)=>{"use strict";var a=n(94375),r=n(54681),s=n(3586),o=n(13802);n(99800);(0,a.M)(r,{edit:s.A,save:()=>null,transforms:o.Ay})},10603:(e,t,n)=>{"use strict";n.d(t,{mt:()=>o});var a=n(96865),r=n(74997),s=n(47143);class o{renderRules=[];firstUpdate=!0;behavior="dropdown";isChildBlock=!1;feature="ai-assistant";adjustPosition=!0;startOpen=!1;hideOnBlockFocus=!0;constructor(e,t=[]){this.clientId=e,this.renderRules=t}getBlock(){const{getBlock:e}=(0,s.select)("core/block-editor");return e(this.clientId)}getContent(){const e=this.getBlock();return t=(0,r.getBlockContent)(e),(0,a.rh)({content:t});var t}renderContent(e){return function(e,t=[]){return(0,a._E)({content:e,rules:t,extension:!0})}(e,this.renderRules)}onSuggestion(e){if(!e)return;const t=this.renderContent(e);this.replaceBlockContent(t)}onDone(e){this.firstUpdate=!0}replaceBlockContent(e){const[t]=(0,r.rawHandler)({HTML:e});if(!t)return;const{updateBlockAttributes:n,replaceInnerBlocks:a,__unstableMarkNextChangeAsNotPersistent:o}=(0,s.dispatch)("core/block-editor");this.firstUpdate?this.firstUpdate=!1:o(),n(this.clientId,t.attributes),o(),a(this.clientId,t.innerBlocks)}getExtensionInputPlaceholder(){return null}}},67607:(e,t,n)=>{"use strict";n.d(t,{A:()=>p});var a=n(82170),r=n(96865),s=n(85985),o=n(86087),i=n(27723),l=n(13022),c=(n(51609),n(92169)),u=n(61297);const __=i.__,d=(0,l.A)("jetpack-ai-assistant-extension-ai-input","wp-block");function p({customPlaceholder:e,className:t,requestingState:n,requestingError:i,inputRef:p,wrapperRef:m,action:h,blockType:g,feature:f,request:v,stopSuggestion:b,close:k,undo:y,tryAgain:E}){const w=e||__("Ask Jetpack AI to edit…","jetpack"),[_,C]=(0,o.useState)(""),[A,x]=(0,o.useState)(w),{checkoutUrl:j}=(0,c.A)(),{tracks:S}=(0,s.st)(),[N,R]=(0,o.useState)(0),[P,L]=(0,o.useState)(!1),{requireUpgrade:T,requestsCount:B,requestsLimit:M,loading:I,nextTier:D,currentTier:F}=(0,u.A)(),z=(0,o.useMemo)((()=>T||["requesting","suggesting"].includes(n)),[T,n]),O=(0,o.useMemo)((()=>T&&1===F?.value),[T,F]),H=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_assistant_extension_generate",{block_type:g,feature:f}),v?.(_)}),[g,f,v,S,_]),U=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_assistant_extension_stop",{block_type:g}),b?.()}),[g,b,S]);const V=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_assistant_undo",{block_type:g}),y?.()}),[g,S,y]),q=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_upgrade_button",{current_tier_slug:F?.slug,requests_count:B,placement:"jetpack_ai_assistant_extension"})}),[F?.slug,B,S]),G=(0,o.useCallback)((()=>{S.recordEvent("jetpack_ai_assistant_try_again",{block_type:g}),E?.()}),[g,S,E]);return(0,o.useEffect)((()=>{["init","done"].includes(n)&&C("")}),[n]),(0,o.useEffect)((()=>{x(h||w),h&&C("")}),[h,w]),(0,o.useEffect)((()=>{L(!I&&!!D&&0===_.length)}),[I,D,_]),(0,o.useEffect)((()=>{const e=Math.max(M-B,0);R(e)}),[M,B]),(0,a.createElement)(r.FC,{className:(0,l.A)(d,t),placeholder:A,disabled:z,value:_,state:n,showGuideLine:!0,error:i,requestsRemaining:N,showUpgradeMessage:P,showFairUsageMessage:O,upgradeUrl:j,onChange:C,onSend:H,onStop:U,onClose:function(){k?.()},onUndo:V,onUpgrade:q,onTryAgain:G,wrapperRef:m,ref:p})}},31124:(e,t,n)=>{"use strict";n.d(t,{A:()=>m});var a=n(82170),r=n(96865),s=n(85985),o=n(56427),i=n(86087),l=n(27723),c=n(52068),u=n(76695),d=n(2612);const __=l.__;function p({blockType:e,onClose:t,onAskAiAssistant:n,onRequestSuggestion:r}){const{canTransformToAIAssistant:s,transformToAIAssistant:o,getSelectedBlockClientIds:l}=(0,u.A)(),d=(0,i.useCallback)((a=>{const i=l(),[c]=i,u=a?.options?.alwaysTransformToAIAssistant||!1;!(i.length<2)&&s({clientId:c,blockName:e})||u?o({request:a}):(a?r?.(a.promptType,a.options,a.humanText):n?.(),t?.())}),[e,s,l,n,t,r,o]),[p]=l();return(0,a.createElement)(c.Ay,{blockType:e,clientId:p,onRequestSuggestion:(e,t,n)=>{d({promptType:e,options:t,humanText:n})},onAskAiAssistant:async()=>{d()},disabled:!1})}function m({behavior:e,blockType:t,label:n=__("AI Assistant","jetpack"),onAskAiAssistant:l,onRequestSuggestion:c}){const{tracks:u}=(0,s.st)(),m=(0,i.useContext)(d.B),h=(0,i.useCallback)((e=>{e&&u.recordEvent("jetpack_ai_assistant_extension_toolbar_menu_show",{block_type:t})}),[t,u]),g=(0,i.useCallback)((()=>{u.recordEvent("jetpack_editor_ai_assistant_extension_toolbar_prompt_show",{block_type:t}),l?.()}),[t,l,u]),f=(0,i.useCallback)(((e,n,a)=>{u.recordEvent("jetpack_editor_ai_assistant_extension_toolbar_button_click",{suggestion:e,block_type:t}),c?.(e,n,a)}),[t,c,u]);return(0,a.createElement)(o.Dropdown,{popoverProps:{variant:"toolbar"},renderToggle:({isOpen:t,onToggle:s})=>(0,a.createElement)(o.ToolbarButton,{className:"jetpack-ai-assistant__button",showTooltip:!0,onClick:()=>{if("function"!=typeof e)switch(e){case"action":g();break;case"dropdown":s()}else e({onToggle:s,onAskAiAssistant:l,context:m})},"aria-haspopup":"true","aria-expanded":t,label:n,icon:r.cj}),onToggle:h,renderContent:({onClose:e})=>(0,a.createElement)(p,{onClose:e,blockType:t,onAskAiAssistant:g,onRequestSuggestion:f})})}},95396:(e,t,n)=>{"use strict";n.d(t,{L:()=>r,l:()=>a});const a=["jetpack/field-name","jetpack/field-email","jetpack/field-text","jetpack/field-textarea","jetpack/field-checkbox","jetpack/field-date","jetpack/field-telephone","jetpack/field-url","jetpack/field-checkbox-multiple","jetpack/field-radio","jetpack/field-select","jetpack/field-consent","jetpack/button"],r=["core/heading","core/paragraph","core/list-item","core/list","jetpack/contact-form",...a]},2612:(e,t,n)=>{"use strict";n.d(t,{B:()=>g,Q:()=>f});var a=n(86087),r=n(10067),s=n.n(r),o=n(10603),i=n(95396),l=n(42160),c=n(47007),u=n(75430),d=n(24310),p=n(63904);const m=s()("jetpack-ai-assistant:extensions:get-block-handler"),h={"core/heading":l.T,"core/paragraph":p.d,"core/list-item":d.g,"core/list":u.b,"jetpack/contact-form":c.p,...i.l.reduce(((e,t)=>({...e,[t]:c.g})),{})},g=(0,a.createContext)({});function f(e,t){let n=h[e];n||(m(`No handler found for block type: ${e}. Using default handler.`),n=o.mt);const a=new n(t);return{onSuggestion:a.onSuggestion.bind(a),onDone:a.onDone.bind(a),getContent:a.getContent.bind(a),getExtensionInputPlaceholder:a.getExtensionInputPlaceholder.bind(a),behavior:a.behavior,isChildBlock:a.isChildBlock,feature:a.feature,adjustPosition:a.adjustPosition,startOpen:a.startOpen,hideOnBlockFocus:a.hideOnBlockFocus}}},42160:(e,t,n)=>{"use strict";n.d(t,{T:()=>r});var a=n(10603);class r extends a.mt{constructor(e){super(e,[])}onSuggestion(e){const t=this.getBlock();if(e.startsWith("#")||(e=`${"#".repeat(t?.attributes?.level||1)} ${e}`),e.match(/^#*\s*$/))return;const n=this.renderContent(e);this.replaceBlockContent(n)}}},14602:(e,t,n)=>{"use strict";n.d(t,{g:()=>s});var a=n(47143),r=n(10603);class s extends r.mt{jetpackFormBlockName="jetpack/contact-form";constructor(e){super(e,[]),this.behavior=this.handleBehavior,this.isChildBlock=!0,this.hideOnBlockFocus=!1}handleBehavior=({context:e})=>{const t=(0,a.dispatch)("core/block-editor"),{getBlockParentsByBlockName:n}=(0,a.select)("core/block-editor"),r=n(this.clientId,this.jetpackFormBlockName)?.[0];t.selectBlock(r),e?.[this.jetpackFormBlockName]?.handleAskAiAssistant?.()}}},47007:(e,t,n)=>{"use strict";n.d(t,{g:()=>c.g,p:()=>u});var a=n(74997),r=n(47143),s=n(27723),o=n(62514),i=n(96568),l=n(10603),c=n(14602);const __=s.__;class u extends l.mt{currentListOfValidBlocks=[];constructor(e){super(e,[]),this.behavior="action",this.feature="jetpack-form-ai-extension",this.adjustPosition=!1,this.startOpen=!0,this.hideOnBlockFocus=!1}setContent(e,t=!1){const{replaceInnerBlocks:n}=(0,r.dispatch)("core/block-editor"),s=e.replace(//g,""),l=(0,i.d)(s),c=(0,a.parse)(l).filter((e=>e.isValid&&!["core/freeform","core/missing","core/html"].includes(e.name)));let u=!1;if(c.length0){const e=c[c.length-1],t=this.currentListOfValidBlocks[c.length-1];u=!(0,o.w)(e,t)}if(c.length>0&&(c.length!==this.currentListOfValidBlocks.length||u)&&(n(this.clientId,c),this.currentListOfValidBlocks=c),t){const e=c.filter((e=>"jetpack/button"===e.name));if(this.currentListOfValidBlocks=this.currentListOfValidBlocks||[],e.length>1){let t=0;this.currentListOfValidBlocks=this.currentListOfValidBlocks.filter((n=>"jetpack/button"!==n.name||(t++,t===e.length))),n(this.clientId,this.currentListOfValidBlocks)}else 0===e.length&&n(this.clientId,[...this.currentListOfValidBlocks,(0,a.createBlock)("jetpack/button",{label:__("Submit","jetpack"),element:"button",text:__("Submit","jetpack"),borderRadius:8,lock:{remove:!0}})]);this.currentListOfValidBlocks=[]}}getExtensionInputPlaceholder(){if(!this.getContent()){const e=[__("Example: a contact form with name, email, and message fields","jetpack"),__("Example: a pizza ordering form with name, address, phone number and toppings","jetpack"),__("Example: a survey form with multiple choice questions","jetpack")];return e[Math.floor(Math.random()*e.length)]}const e=[__("Example: remove email field","jetpack"),__("Example: make email optional","jetpack"),__("Example: add message field and make it required","jetpack")];return e[Math.floor(Math.random()*e.length)]}getContent(){const e=this.getBlock();if(!e)return"";const{innerBlocks:t}=e;return t?.length?t.reduce(((e,t)=>e+(0,a.serialize)(t)+"\n\n"),""):""}onSuggestion(e){this.setContent(e)}onDone(e){this.setContent(e,!0)}}},10821:(e,t,n)=>{"use strict";n.d(t,{Bi:()=>i});var a=n(74997),r=n(47143),s=n(7503);const o=(0,n(48499).C)("ai-assistant-support");function i(){if(!(0,a.getBlockType)("jetpack/ai-assistant"))return!1;if(!o)return!1;if(!(0,s.x)())return!1;const{getHiddenBlockTypes:e}=(0,r.select)("core/edit-post")||{};return!(e?.()||[]).includes("jetpack/ai-assistant")}},91184:(e,t,n)=>{"use strict";n.d(t,{Y:()=>s});var a=n(95396),r=n(10821);function s(e){return!!(0,r.Bi)()&&!!a.L.includes(e)}},24310:(e,t,n)=>{"use strict";n.d(t,{g:()=>r});var a=n(10603);class r extends a.mt{constructor(e){super(e,["listItem"]),this.isChildBlock=!0}}},75430:(e,t,n)=>{"use strict";n.d(t,{b:()=>r});var a=n(10603);class r extends a.mt{constructor(e){super(e,["list"])}}},63904:(e,t,n)=>{"use strict";n.d(t,{d:()=>i});var a=n(96865),r=n(74997),s=n(10603);const o=new a.OO({fixes:["paragraph"]});class i extends s.mt{constructor(e){super(e,["paragraph"])}getContent(){const e=this.getBlock();return t=(0,r.getBlockContent)(e),o.render({content:t});var t}}},99800:(e,t,n)=>{"use strict";var a=n(82170),r=n(96865),s=n(94715),o=n(29491),i=n(47143),l=n(86087),c=n(52619),u=n(13022),d=n(10067),p=n.n(d),m=(n(51609),n(61297)),h=n(32735),g=n(35317),f=n(4e4),v=n(67607),b=n(31124),k=n(2612),y=n(91184);const E=p()("jetpack-ai-assistant:extensions:with-ai-extension"),w={"core/heading":"heading","core/paragraph":"paragraph","core/list-item":"list-item","core/list":"list","jetpack/contact-form":"form-ai"},_={group:"block"},C=(0,o.createHigherOrderComponent)((e=>{function t(t){const{clientId:n,isSelected:o,name:c,isSelectionEnabled:d}=t,p=(0,l.useRef)(null),g=(0,l.useRef)(0),y=(0,l.useRef)(null),C=(0,l.useRef)(""),A=(0,l.useRef)(null),x=(0,l.useRef)(document),j=(0,l.useRef)([]),[S,N]=(0,l.useState)(""),R=(0,l.useRef)(null),P=(0,l.useRef)(null),{undo:L}=(0,i.useDispatch)("core/editor"),{postId:T}=(0,i.useSelect)((e=>{const{getCurrentPostId:t}=e("core/editor");return{postId:t()}}),[]),{id:B,className:M}=(0,s.useBlockProps)({className:(0,u.A)({[c?.replace?.("/","-")]:!0})}),{increaseRequestsCount:I,dequeueAsyncRequest:D,requireUpgrade:F}=(0,m.A)(),{snapToBottom:z,enableAutoScroll:O,disableAutoScroll:H}=(0,h.A)({current:x?.current?.getElementById(B)},void 0,!0),U=(0,l.useCallback)((()=>{A.current?.focus()}),[]),{onSuggestion:V,onDone:q,getContent:G,getExtensionInputPlaceholder:$,behavior:W,isChildBlock:Z,feature:J,adjustPosition:K,startOpen:Y,hideOnBlockFocus:Q}=(0,l.useMemo)((()=>(0,k.Q)(c,n)),[c,n]),X=$(),[ee,te]=(0,l.useState)(Y),ne=(0,l.useCallback)((()=>{te((e=>!e))}),[]),ae=(0,l.useCallback)((({promptType:e,options:t})=>{const n=G(),a=w[c];return[...j.current,{role:"jetpack-ai",context:{type:(0,f.p$)(e,a),content:n,request:t?.userPrompt,tone:t?.tone,language:t?.language,is_follow_up:j.current.length>0}}]}),[c,G]),re=(0,l.useCallback)((e=>{const t=e||x.current.getElementById(B);t&&p.current&&t.style.setProperty("padding-bottom",`calc(${g.current+16}px + ${C.current||"0px"} )`,"important")}),[B]),se=(0,l.useCallback)((e=>{V(e),K&&re(),z()}),[V,K,z,re]),oe=(0,l.useCallback)((e=>{if(H(),q(e),I(),N(""),R.current?.message){const e={role:"assistant",content:G()};if(j.current.push(R.current.message,e),j.current.length>20){j.current.splice(0,j.current.length-20);const e=j.current.findIndex((e=>"jetpack-ai"===e.role));-1!==e&&(j.current=j.current.slice(e),j.current[0].context={...j.current[0].context,is_follow_up:!1})}}R.current=null,setTimeout((()=>{K&&re(),U()}),100)}),[H,q,I,G,K,U,re]),ie=(0,l.useCallback)((e=>{H(),N(""),E("Request error",e),e.code!==r.mA&&e.code!==r.Or&&I()}),[H,I]),{request:le,stopSuggestion:ce,requestingState:ue,error:de,reset:pe}=(0,r.o2)({onSuggestion:se,onDone:oe,onError:ie,askQuestionOptions:{postId:T,feature:J}});(0,l.useEffect)((()=>{P.current=ue}),[ue]);const me=(0,l.useCallback)(((e,t,n)=>{if(te(!0),F)return;n&&N(n);const a=ae({promptType:e,options:t});E("Request suggestion",e,t);const r=a[a.length-1];R.current={promptType:e,options:t,humanText:n,message:r},D(),O(),le(a)}),[D,O,ae,le,F]),he=(0,l.useCallback)((e=>{const t={userPrompt:e};O(),me("userPrompt",t)}),[O,me]),ge=(0,l.useCallback)((()=>{H(),ce(),U()}),[H,ce,U]),fe=(0,l.useCallback)((()=>{R.current&&me(R.current.promptType,R.current.options,R.current.humanText)}),[R,me]),ve=(0,l.useCallback)((()=>{te(!1),pe(),N(""),R.current=null,j.current=[]}),[pe]),be=(0,l.useCallback)((async()=>{await L(),ve()}),[L,ve]);(0,l.useEffect)((()=>{o||ve()}),[o,ve]),(0,l.useEffect)((()=>{A.current&&d&&(x.current=A.current.ownerDocument,U())}),[ee,U,d]),(0,l.useEffect)((()=>{let e=x.current.getElementById(B);if(e&&K)return ee&&!y.current&&p.current?(C.current=e.style.paddingBottom,y.current=new ResizeObserver((([t])=>{if(e=x.current.getElementById(B),g.current=t.contentRect.height,e&&p.current&&g.current>0){re(e);const{marginBottom:t}=getComputedStyle(e),n=parseFloat(t);p.current.style.setProperty("margin-top",`-${g.current+n}px`,"important"),p.current.style.setProperty("margin-bottom",`${n+16}px`,"important")}})),y.current.observe(p.current)):y.current&&(e.style.paddingBottom=C.current,y.current.disconnect(),y.current=null,g.current=0),()=>{y.current&&y.current.disconnect()}}),[re,K,n,y,B,ee]),(0,l.useEffect)((()=>{if(Q&&ee){const e=x.current.getElementById(B),t=()=>{["requesting","suggesting"].includes(P.current)||(te(!1),e?.removeEventListener("focusin",t))};return e?.addEventListener("focusin",t),()=>{e?.removeEventListener("focusin",t)}}}),[Q,ee,B]);const ke=(0,a.createElement)(a.Fragment,null,(0,a.createElement)(e,t),ee&&(0,a.createElement)(v.A,{customPlaceholder:X||null,className:M,requestingState:ue,requestingError:de,wrapperRef:p,inputRef:A,action:S,blockType:c,feature:J,request:he,stopSuggestion:ge,close:ve,undo:be,tryAgain:fe}),(0,a.createElement)(s.BlockControls,_,(0,a.createElement)(b.A,{blockType:c,onAskAiAssistant:ne,onRequestSuggestion:me,behavior:W})));if(Z)return ke;const ye={value:{[c]:{handleAskAiAssistant:ne,handleRequestSuggestion:me}}};return(0,a.createElement)(k.B.Provider,ye,ke)}return n=>(0,g.A)(n.name)?(0,a.createElement)(t,n):(0,a.createElement)(e,n)}),"blockEditWithAiComponents");(0,c.addFilter)("blocks.registerBlockType","jetpack/ai-assistant-support/with-ai-extension",(function(e,t){return(0,y.Y)(t)?{...e,edit:C(e.edit),supports:{...e.supports,"jetpack/ai":{assistant:!0}}}:e}),100)},4393:(e,t,n)=>{"use strict";n.d(t,{A:()=>m});var a=n(96865),r=n(47143),s=n(86087),o=n(10067),i=n.n(o),l=n(62402),c=n(64425),u=n(16597),d=n(32735);const p=i()("jetpack-ai-assistant:error"),m=({attributes:e,clientId:t,content:n,tracks:o,userPrompt:i,onSuggestionDone:m,onUnclearPrompt:h,onModeration:g,requireUpgrade:f,initialRequestingState:v,contentRef:b,blockRef:k})=>{const[y,E]=(0,s.useState)(!1),[w,_]=(0,s.useState)(""),{updateBlockAttributes:C}=(0,r.useDispatch)("core/block-editor"),{dequeueAiAssistantFeatureAsyncRequest:A,setAiAssistantFeatureRequireUpgrade:x}=(0,r.useDispatch)("wordpress-com/plans"),{snapToBottom:j,enableAutoScroll:S,disableAutoScroll:N}=(0,d.A)(k,b),R=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("title"))),P=(0,r.useSelect)((e=>e("core/editor").getCurrentPostId())),L=(0,s.useRef)([]),T=(0,s.useRef)(void 0),{request:B,stopSuggestion:M,handleErrorQuotaExceededError:I,requestingState:D,error:F}=(0,a.o2)({onSuggestion:e=>{C(t,{content:e?.replaceAll(c.uV,"")}),j()},onDone:e=>{const n=e.replaceAll(c.uV,""),a={role:"assistant",content:n};L.current.push(T.current,a),L.current.length>20&&L.current.splice(0,L.current.length-20),C(t,{content:n,messages:L.current}),j(),N(),m?.()},onStop:()=>{j(),N(),m?.()},onError:e=>{switch(e?.code){case a.cT:E(!1);break;case a.ud:E(!1),g?.();break;case a.mA:case a.AZ:E(!0);break;case a.Or:E(!1),x(!0);break;case a.L9:h?.()}},onAllErrors:e=>{p(e)},initialRequestingState:v,askQuestionOptions:{postId:P,feature:"ai-assistant",functions:{}}}),z=["requesting","suggesting"].includes(D),O=async(a,r={})=>{if(A(),f)return I(),void E(!1);if(r={retryRequest:!1,tone:l.US,...r},z)return;E(!1);let s=w;if(o.recordEvent("jetpack_ai_chat_completion",{post_id:P}),L.current=[...e.messages]??[],T.current={},r.retryRequest)T.current=s[s.length-1];else{const o=e?.isLayoutBuldingModeEnable?(0,u.rJ)(t):(0,u.aB)();s=(0,c.jf)({generatedContent:n,allPostContent:o,postContentAbove:(0,u.b$)(t),currentPostTitle:R,options:r,userPrompt:r?.userPrompt||i,type:a,isGeneratingTitle:"generateTitle"===e.promptType}),T.current=s.pop(),s=[...s,...L.current],s.push(T.current),_(s),"generateTitle"!==e.promptType&&C(t,{promptType:a})}try{S(),await B(s)}catch(e){p(e),E(!0),N()}};return{setShowRetry:E,showRetry:y,postTitle:R,contentBefore:(0,u.b$)(t),wholeContent:(0,u.aB)(),requestingState:D,error:F,getSuggestionFromOpenAI:O,stopSuggestion:M,retryRequest:()=>O("",{retryRequest:!0})}}},92169:(e,t,n)=>{"use strict";n.d(t,{A:()=>l});var a=n(3924),r=n(85985),s=n(10617),o=n(61297);const i=()=>{const e=new URLSearchParams(window.location.search),t=(0,r.GE)();return(0,r.Sy)()&&e.has("post")?`https://wordpress.com/post/${t}/${e.get("post")}`:`https://wordpress.com/home/${t}`};function l(){const{nextTier:e,tierPlansEnabled:t}=(0,o.A)(),n=i(),l=(0,a.A)("jetpack-ai-yearly-tier-upgrade-nudge",{site:(0,r.GE)(),path:t?`jetpack_ai_yearly:-q-${e?.limit}`:"jetpack_ai_yearly",query:`redirect_to=${encodeURIComponent(n)}`}),c=(0,a.A)("jetpack-ai-upgrade-url-for-jetpack-sites",{site:(0,r.GE)(),path:"jetpack_ai_yearly"}),u=(0,r.d9)()||(0,r.Sy)()?l:c,{autosaveAndRedirect:d,isRedirecting:p}=(0,s.A)(u);return{checkoutUrl:u,autosaveAndRedirect:d,isRedirecting:p}}},61297:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var a=n(47143),r=n(58164);function s(){const{data:e,loading:t,requestsLimit:n,requestsCount:s}=(0,a.useSelect)((e=>{const{getAiAssistantFeature:t,getIsRequestingAiAssistantFeature:n}=e("wordpress-com/plans"),a=t(),{currentTier:s,usagePeriod:o,requestsCount:i,requestsLimit:l}=a,c=(0,r.Bd)(s),u=s?.limit||l,d=c===r._X?i:o?.requestsCount,p=c===r._X?l:u;return{data:a,loading:n(),requestsCount:d,requestsLimit:p}}),[]),{fetchAiAssistantFeature:o,increaseAiAssistantRequestsCount:i,dequeueAiAssistantFeatureAsyncRequest:l}=(0,a.useDispatch)("wordpress-com/plans");return{...e,requestsCount:s,requestsLimit:n,loading:t,error:null,refresh:o,increaseRequestsCount:i,dequeueAsyncRequest:l}}},44732:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var a=n(3924),r=n(85985),s=n(10617);function o(){const e=(0,r.$i)()?.jetpack?.is_my_jetpack_available,t=e?`${(0,r.$i)()?.adminUrl||""}admin.php?page=my-jetpack#/jetpack-ai`:(0,a.A)("org-ai"),{autosaveAndRedirect:n,isRedirecting:o}=(0,s.A)(t);return{productPageUrl:t,autosaveAndRedirect:n,isRedirecting:o,isMyJetpackAvailable:e}}},75956:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var a=n(90372),r=n(86087);const s=window?.Jetpack_Editor_Initial_State?.tracksUserData||null,o=parseInt(window?.Jetpack_Editor_Initial_State?.wpcomBlogId)||0,i=()=>((0,r.useEffect)((()=>{s&&a.A.initialize(s?.userid,s?.username,o?{blog_id:o}:{})}),[]),a.A)},32735:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var a=n(86087),r=n(10067);const s=n.n(r)()("jetpack-ai-assistant:use-auto-scroll"),o=(e,t,n=!1)=>{const r=(0,a.useRef)(null),o=(0,a.useRef)(null),i=(0,a.useRef)(!1),l=(0,a.useRef)(!1),c=(0,a.useRef)(!1),u=(0,a.useRef)(!1),d=(0,a.useRef)({scrollPadding:"",scrollMargin:""}),p=(0,a.useCallback)((()=>{s("enabling ignore scroll"),l.current=!0}),[]),m=(0,a.useCallback)((()=>{i.current&&c.current&&!l.current&&p()}),[p]),h=(0,a.useCallback)((()=>{i.current=!0,l.current=!1,c.current=!1,u.current=!1,r.current?.addEventListener("scroll",m),s("enabling auto scroll")}),[m]),g=(0,a.useCallback)((()=>{i.current=!1,l.current=!1,c.current=!1,u.current=!1,r.current?.removeEventListener("scroll",m),o.current?.style&&(o.current.style.scrollPadding=d.current.scrollPadding,o.current.style.scrollMargin=d.current.scrollMargin),r.current=null,s("disabling auto scroll")}),[m]),f=(0,a.useCallback)((()=>{if(!i.current||l.current)return;const a=n?e?.current:t?.current?.firstElementChild?.lastElementChild;a&&!u.current&&(c.current=!0,u.current=!0,r?.current?.removeEventListener?.("scroll",m),a?.scrollIntoView({block:"end",inline:"end"}),setTimeout((()=>{u.current=!1,r?.current?.addEventListener?.("scroll",m)}),200))}),[e,t,n,m]),v=(0,a.useCallback)((e=>{if(null==e)return null;if("BODY"===e?.nodeName)return e;if(e?.ownerDocument!==document)return e.ownerDocument;const{overflow:t}=window.getComputedStyle(e);return t.split(" ").every((e=>"auto"===e||"scroll"===e))?e:e?.parentElement?v(e?.parentElement):e}),[]);return(0,a.useEffect)((()=>{const t=v(e?.current?.parentElement);!r.current&&t&&(r.current=t,o.current=t instanceof HTMLElement?t:t.documentElement,d.current={scrollPadding:o.current.style.scrollPadding,scrollMargin:o.current.style.scrollMargin},i.current&&(o.current.style.scrollPadding="80px",o.current.style.scrollMargin="10px"))}),[e,v]),{snapToBottom:f,enableAutoScroll:h,disableAutoScroll:g}}},35317:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var a=n(85985);const r={"jetpack/contact-form":"contact-form"};function s(e){const t=r[e],{isModuleActive:n}=(0,a.q7)(t);return!t||n}},76695:(e,t,n)=>{"use strict";n.d(t,{A:()=>c,y:()=>l});var a=n(85985),r=n(47143),s=n(51609),o=n(16597),i=n(13802);function l(e){return`ai-assistant-block-${e}`}const c=()=>{const{replaceBlock:e,removeBlocks:t}=(0,r.useDispatch)("core/block-editor"),n=(0,r.useSelect)((e=>e("core/block-editor")),[]),{getSelectedBlockClientIds:c,getBlocksByClientId:u,getBlock:d,getBlockParents:p}=n,{tracks:m}=(0,a.st)();return{canTransformToAIAssistant:(0,s.useCallback)((({clientId:e,blockName:t})=>{if(!d(e))return!1;if(!i.y7.includes(t))return!1;const n=p(e);if(0===n.length)return!0;const a=d(n[n.length-1]);return!["core/list","core/list-item"].includes(a.name)}),[d,p]),transformToAIAssistant:(0,s.useCallback)((({request:n}={})=>{const a=c(),r=u(a),s=(0,o.Sb)(r),[d]=r,[p,...h]=a,g={...d?.attributes||{},content:s},f=(0,i.rr)(d.name,g);if(n?.promptType){m.recordEvent("jetpack_editor_ai_assistant_extension_toolbar_button_click",{suggestion:n.promptType,block_type:d.name});const e={clientId:p,type:n.promptType,options:{...n.options,contentType:"generated",fromExtension:!0}};localStorage.setItem(l(f.clientId),JSON.stringify(e))}else m.recordEvent("jetpack_ai_assistant_prompt_show",{block_type:d.name});e(p,f),t(h)}),[u,c,t,e,m]),getSelectedBlockClientIds:c}}},7503:(e,t,n)=>{"use strict";n.d(t,{C:()=>d,x:()=>u});var a=n(85985),r=n(10067),s=n.n(r);const o=window?.JP_CONNECTION_INITIAL_STATE,i=s()("jetpack-ai-assistant:connection");let l=!1;const c=e=>{l||(i(e),l=!0)};function u(){return(0,a.Sy)()?(c("Simple site connected ✅"),!0):(0,a.d9)()?(c("Atomic site connected ✅"),!0):o?.connectionStatus?.isUserConnected?(c("Jetpack user is connected ✅"),!0):(c("User is not connected ❌"),!1)}function d(){if((0,a.Sy)())return!0;return!1==!(o?.userConnectionData?.currentUser?.permissions??{}).manage_options}},4e4:(e,t,n)=>{"use strict";n.d(t,{J1:()=>i,K6:()=>l,p$:()=>u});var a=n(64425);const r="title",s="content",o=null;function i(e){return{role:"jetpack-ai",context:{type:"ai-assistant-initial-prompt",for:u(e)}}}function l({generatedContent:e,allPostContent:t,postContentAbove:n,currentPostTitle:r,options:s,type:o,userPrompt:i,isGeneratingTitle:l}){const u=[],d="generated"===s?.contentType;let p=null;switch(o){case a.im:p=r;break;case a.sn:case a.A4:case a.yy:p=n;break;case a.vE:p=t;break;case a.br:case a.fD:p=e;break;case a.eJ:case a.UA:case a.Gm:p=d?e:t;break;case a.d5:p=n;break;case a.pE:p=e||t}const m=function(e,t){return!e&&t&&t.length>0?{role:"jetpack-ai",context:{type:"ai-assistant-relevant-content",content:t}}:null}(o===a.pE?!!e?.length:d,p);return m&&u.push(m),u.push({role:"jetpack-ai",context:c({generatedContent:e,allPostContent:t,postContentAbove:n,currentPostTitle:r,options:s,type:o,userPrompt:i,isGeneratingTitle:l})}),u}function c({options:e,type:t,userPrompt:n,isGeneratingTitle:i}){const l=function(e,t,n){return e?r:!t||n?s:o}(i,"generated"===e?.contentType,e?.fromExtension||!1);return{type:u(t),...l?{subject:l}:{},...t===a.eJ&&e?.tone?{tone:e.tone}:{},...t===a.Gm&&e?.language?{language:e.language}:{},...t===a.pE&&n?{request:n}:{}}}function u(e,t){const n={[a.im]:"ai-assistant-summary-by-title",[a.sn]:"ai-assistant-continue-writing",[a.A4]:"ai-assistant-simplify",[a.yy]:"ai-assistant-correct-spelling",[a.vE]:"ai-assistant-generate-title",[a.br]:"ai-assistant-make-longer",[a.fD]:"ai-assistant-make-shorter",[a.eJ]:"ai-assistant-change-tone",[a.UA]:"ai-assistant-summarize",[a.Gm]:"ai-assistant-change-language",[a.pE]:"ai-assistant-user-prompt",[a.d5]:"ai-assistant-transform-list-to-table"};return"form-ai"===t?"form-ai-extension":t?`${n[e]}-${t}-extension`:n[e]}},64425:(e,t,n)=>{"use strict";n.d(t,{A4:()=>o,Gm:()=>m,UA:()=>p,br:()=>c,d5:()=>g,eJ:()=>d,fD:()=>u,im:()=>r,jf:()=>v,pE:()=>h,sn:()=>s,uV:()=>f,vE:()=>l,yy:()=>i});var a=n(4e4);const r="titleSummary",s="continue",o="simplify",i="correctSpelling",l="generateTitle",c="makeLonger",u="makeShorter",d="changeTone",p="summarize",m="changeLanguage",h="userPrompt",g="transformListToTable",f="````";function v({generatedContent:e,allPostContent:t,postContentAbove:n,currentPostTitle:r,options:s,type:o,userPrompt:i,isGeneratingTitle:l}){return[(0,a.J1)(o),...(0,a.K6)({generatedContent:e,allPostContent:t,postContentAbove:n,currentPostTitle:r,options:s,type:o,userPrompt:i,isGeneratingTitle:l})]}},16597:(e,t,n)=>{"use strict";n.d(t,{Sb:()=>l,aB:()=>i,b$:()=>o,rJ:()=>c});var a=n(96865),r=n(74997),s=n(47143);function o(e){if(!e)return"";const t=(0,s.select)("core/block-editor"),n=t.getBlockIndex(e),o=t.getBlocks().slice(0,n)??[];return o?.length?(0,a.rh)({content:(0,r.serialize)(o)}):""}function i(){const e=(0,s.select)("core/block-editor").getBlocks();return e?.length?(0,a.rh)({content:(0,r.serialize)(e)}):""}function l(e){return e.filter((e=>null!=e)).map((e=>(0,r.getBlockContent)(e))).join("\n\n")}function c(e){const t=(0,s.select)("core/block-editor").getBlock(e);return t?.innerBlocks?.length?l(t.innerBlocks):""}},47264:(e,t,n)=>{"use strict";function a(e){return e&&"string"==typeof e?e.charAt(0).toUpperCase()+e.slice(1):""}n.d(t,{Z:()=>a})},62514:(e,t,n)=>{"use strict";n.d(t,{w:()=>s});const a=e=>{delete e.clientId;for(const t of e.innerBlocks??[])a(t);return e},r=e=>a((e=>JSON.parse(JSON.stringify(e)))(e));function s(e,t){const n=r(e),a=r(t);return JSON.stringify(n)===JSON.stringify(a)}},96568:(e,t,n)=>{"use strict";function a(e){const t=document.createElement("div");return t.innerHTML=e,t.innerHTML}n.d(t,{d:()=>a})},48499:(e,t,n)=>{"use strict";n.d(t,{C:()=>r});var a=n(85985);function r(e){return!0===(0,a.FB)(e).available}},13802:(e,t,n)=>{"use strict";n.d(t,{Ay:()=>c,rr:()=>l,y7:()=>o});var a=n(96865),r=n(74997),s=n(54681);const o=["core/heading","core/paragraph","core/list"],i=[];function l(e,t){const{content:n,...o}=t;let i=n;"core/heading"===e&&t?.level&&(i=i.replace(/<(\/?)h\d([^>]*)>/g,`<$1h${t.level}$2>`));const l=(0,a.rh)({content:i}),c=[];return c.push({role:"jetpack-ai",context:{type:"ai-assistant-relevant-content",content:l}}),(0,r.createBlock)(s.name,{...o,content:l,originalContent:l,messages:c,originalMessages:c})}for(const e of o)i.push({type:"block",blocks:[e],isMatch:()=>o.includes(e),transform:(t,n)=>{const a=(0,r.getSaveContent)(e,t,n);return l(e,{...t,content:a})}});const c={from:i}},36920:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var a=n(82170),r=n(27723),s=n(56333),o=n(10617);const __=r.__,i=()=>{let e=window?.Jetpack_Editor_Initial_State?.adminUrl||"";e=e.replace(/wp-admin\/\?frame-nonce=[a-z0-9]+/,"wp-admin/");const t=`${e}admin.php?page=jetpack-search`,{autosaveAndRedirect:n,isRedirecting:r}=(0,o.A)(t);if(window?.Jetpack_AIChatBlock?.jetpackSettings?.instant_search_enabled)return null;return(0,a.createElement)(s.c,{buttonText:__("Enable Jetpack Search","jetpack"),checkoutUrl:t,className:"jetpack-ai-connect-banner",description:__("You need to enable Jetpack Search so that Jetpack AI can index your site.","jetpack"),goToCheckoutPage:e=>{n(e)},isRedirecting:r,visible:!0,align:null,title:null,context:null})}},50443:(e,t,n)=>{"use strict";n.d(t,{G:()=>s,W:()=>r});var a=n(27723);const __=a.__,r=__("Ask","jetpack"),s=__("Ask a question about this site","jetpack")},51686:(e,t,n)=>{"use strict";n.d(t,{z:()=>c});var a=n(82170),r=n(94715),s=n(56427),o=n(3582),i=n(27723),l=n(50443);const __=i.__;function c({setAttributes:e,placeholder:t,showCopy:n,showFeedback:i,showSources:c}){const[u,d]=(0,o.useEntityProp)("root","site","jetpack_search_ai_prompt_override");return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.InspectorControls,null,(0,a.createElement)(s.PanelBody,{title:__("Settings","jetpack"),initialOpen:!1},(0,a.createElement)(s.TextControl,{label:__("Placeholder Text","jetpack"),className:"jetpack-ai-chat__ask-button-text",placeholder:l.G,onChange:t=>e({placeholder:t}),value:t,__nextHasNoMarginBottom:!0}))),(0,a.createElement)(r.InspectorAdvancedControls,null,(0,a.createElement)(s.TextareaControl,{label:__("Additional instructions","jetpack"),help:__("Give Jetpack AI additional instructions for answer length, format, and tone.","jetpack"),value:u,onChange:d,__nextHasNoMarginBottom:!0}),(0,a.createElement)(s.ToggleControl,{label:__("Show copy answer button.","jetpack"),help:__("Allow users to easily copy the answer.","jetpack"),checked:n,onChange:t=>e({showCopy:t}),__nextHasNoMarginBottom:!0}),(0,a.createElement)(s.ToggleControl,{label:__("Show rating button.","jetpack"),help:__("Allow users to rate the answer and give feedback.","jetpack"),checked:i,onChange:t=>e({showFeedback:t}),__nextHasNoMarginBottom:!0}),(0,a.createElement)(s.ToggleControl,{label:__("Show list of sources.","jetpack"),help:__("Show used sources at the bottom of the answer.","jetpack"),checked:c,onChange:t=>e({showSources:t}),__nextHasNoMarginBottom:!0})))}},32908:(e,t,n)=>{"use strict";n.d(t,{A:()=>m});var a=n(82170),r=n(96865),s=n(94715),o=n(56427),i=n(47143),l=n(2274),c=n(26247),u=n(36920),d=n(50443),p=n(51686);function m({attributes:e,setAttributes:t,clientId:n}){const{askButtonLabel:m=d.W,placeholder:h=d.G,showCopy:g,showFeedback:f,showSources:v}=e,b=(0,s.useBlockProps)(),k=(0,i.useSelect)((e=>e("core/block-editor").isBlockSelected(n)),[n]),y=(0,c.A)();return(0,a.createElement)("div",b,!y&&(0,a.createElement)(l.A,{block:"Jetpack AI Search"}),(0,a.createElement)(u.A,null),(0,a.createElement)("div",{className:"jetpack-ai-chat-question-wrapper"},(0,a.createElement)(o.TextControl,{className:"jetpack-ai-chat-question-input",placeholder:h,disabled:!0,__nextHasNoMarginBottom:!0}),(0,a.createElement)(s.RichText,{className:"wp-block-button__link jetpack-ai-chat-question-button",onChange:e=>t({askButtonLabel:e}),value:m,withoutInteractiveFormatting:!0,allowedFormats:["core/bold","core/italic","core/strikethrough"]})),k&&(0,a.createElement)(r.Yj,null),(0,a.createElement)(s.InspectorControls,null,(0,a.createElement)(p.z,{askButtonLabel:m,placeholder:h,setAttributes:t,showCopy:g,showFeedback:f,showSources:v})))}},8393:(e,t,n)=>{"use strict";var a=n(94375),r=n(1629),s=n(32908),o=n(41825);(0,a.M)(r,{edit:s.A,save:o.A})},41825:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var a=n(82170),r=n(94715),s=n(50443);function o({attributes:e}){const t=r.useBlockProps.save({"data-ask-button-label":e.askButtonLabel||s.W});return(0,a.createElement)("div",t)}},97571:(e,t,n)=>{"use strict";n.d(t,{z:()=>o});var a=n(82170),r=n(56427),s=n(27723);const __=s.__;function o({attributes:e,setAttributes:t}){const{statsData:n,statsOption:s}=e,o=[{value:"views",label:__("Views","jetpack")},{value:"visitors",label:__("Visitors","jetpack")}],i=[{value:"site",label:__("My whole site","jetpack")},{value:"post",label:__("This individual post","jetpack")}];return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.PanelBody,{title:__("Settings","jetpack")},(0,a.createElement)(r.RadioControl,{label:__("Views or visitors","jetpack"),selected:n,onChange:e=>t({statsData:e}),options:o,help:__("Views represent site visits, whereas visitors represent unique individuals.","jetpack")}),(0,a.createElement)(r.RadioControl,{label:__("Show stats data for","jetpack"),selected:s,onChange:e=>t({statsOption:e}),options:i,disabled:"visitors"===n,help:"visitors"===n?__("Visitor counts aren't available for individual posts.","jetpack"):null}),(0,a.createElement)("span",{className:"jetpack-blog-stats__delay-notice"},__("Stats are delayed for up to 5 minutes.","jetpack"))))}},20201:(e,t,n)=>{"use strict";n.d(t,{A:()=>h});var a=n(82170),r=n(37975),s=n(85985),o=n(1455),i=n.n(o),l=n(94715),c=n(47143),u=n(86087),d=n(27723),p=n(97571),m=n(51744);const __=d.__,_n=d._n;const h=function({attributes:e,className:t,setAttributes:n}){const{isLoadingModules:o,isChangingStatus:d,isModuleActive:h,changeStatus:g}=(0,s.q7)("stats"),{label:f,statsData:v,statsOption:b}=e,[k,y]=(0,u.useState)(null),[E,w]=(0,u.useState)(),[_,C]=(0,u.useState)(),A=(0,l.useBlockProps)(),x="post"===b?_:"views"===v?k:E,j=(0,c.useSelect)((e=>e("core/editor").getCurrentPostId()),[]);if((0,u.useEffect)((()=>{h&&i()({path:Number.isInteger(j)?`/wpcom/v2/blog-stats?post_id=${j}`:"/wpcom/v2/blog-stats"}).then((e=>{y(e["blog-views"]),w(e["blog-visitors"]),C(Number.isInteger(j)?e["post-views"]:"12345")}))}),[j,h]),(0,u.useEffect)((()=>{"visitors"===v&&n({statsOption:"site"})}),[v,n]),!h&&!o)return(0,a.createElement)(m.k,{className:t,changeStatus:g,isLoading:d});const S=/* Translators: Number of visitors */ _n("visitor","visitors",parseInt(x),"jetpack",0),N=/* Translators: Number of views */ _n("hit","hits",parseInt(x),"jetpack",0);return(0,a.createElement)("div",A,(0,a.createElement)(l.InspectorControls,null,(0,a.createElement)(p.z,{attributes:e,setAttributes:n})),(0,a.createElement)("div",{className:t},o||null===k?(0,a.createElement)("p",{className:"jetpack-blog-stats__loading"},__("Loading stats…","jetpack")):(0,a.createElement)("p",null,(0,a.createElement)("span",null,(0,r.A)(x)," "),(0,a.createElement)(l.RichText,{tagName:"span",placeholder:"visitors"===v?S:N,value:f,allowedFormats:["core/bold","core/italic","core/link"],onChange:e=>n({label:e})}))))}},95184:(e,t,n)=>{"use strict";var a=n(74997),r=n(94375),s=n(35116),o=n(20201);(0,r.M)(s,{edit:o.A,save:()=>null,transforms:{from:[{type:"block",blocks:["core/legacy-widget"],isMatch:({idBase:e,instance:t})=>!!t?.raw&&"blog-stats"===e,transform:({instance:e})=>{const t=e.raw.title?(0,a.createBlock)("core/heading",{content:e.raw.title,level:3}):null,n=(0,a.createBlock)("jetpack/blog-stats",{label:e.raw.hits});return t?[t,n]:n}}]}})},51744:(e,t,n)=>{"use strict";n.d(t,{k:()=>l});var a=n(82170),r=n(85985),s=n(56427),o=n(27723),i=n(35116);const __=o.__,l=({className:e,isLoading:t,changeStatus:n})=>{const o=(0,r.d9)()?"https://wordpress.com/support/stats/":"https://jetpack.com/support/jetpack-stats/";return(0,a.createElement)("div",{className:e},(0,a.createElement)(s.Placeholder,{icon:(0,r.sh)(i),instructions:__("You'll need to activate the Stats module to use this block. Please note that hits are only counted while this module is active.","jetpack"),label:i.title},(0,a.createElement)(s.Button,{disabled:t,isBusy:t,onClick:()=>n(!0),variant:"secondary"},t?__("Activating Stats","jetpack"):__("Activate Stats","jetpack",0)),(0,a.createElement)("div",null,(0,a.createElement)(s.ExternalLink,{href:o},__("Learn more about the Stats module.","jetpack")))))}},12169:(e,t,n)=>{"use strict";n.d(t,{A:()=>g});var a=n(82170),r=n(1455),s=n.n(r),o=n(94715),i=n(56427),l=n(47143),c=n(86087),u=n(27723),d=n(93832),p=n(13022),m=n(54919),h=n(9075);const __=u.__,_x=u._x;const g=(0,i.withNotices)((function({attributes:e,noticeOperations:t,noticeUI:n,setAttributes:r}){const g=(0,c.useRef)(!1),{answersLink:f,answersLinkText:v,gravatars:b,promptFetched:k,promptId:y,promptLabel:E,promptText:w,showLabel:_,showResponses:C,tagsAdded:A,isBloganuary:x}=e,j=(0,o.useBlockProps)({className:"jetpack-blogging-prompt"});(0,h.J)(y,A,(e=>r({tagsAdded:e})));const S=(0,l.useSelect)((e=>{const{getEntityRecord:t,hasFinishedResolution:n}=e("core"),a=t("root","site")?.language||"en_US";return n("getEntityRecord",["root","site"])?a:null}),[]);(0,c.useEffect)((()=>{if(!S||g.current||k)return;const e=()=>{r({promptFetched:!1,promptId:null,tagsAdded:!1}),g.current=!1,t.removeAllNotices()};let n="/wpcom/v3/blogging-prompts";if(y)n+="/"+encodeURIComponent(y);else{const e=new Date;n+=`?after=--${(e.getMonth()+1).toString().padStart(2,"0")}-${e.getDate().toString().padStart(2,"0")}&order=desc`}n=(0,d.addQueryArgs)(n,{_locale:S,force_year:(new Date)?.getFullYear()}),g.current=!0,s()({path:n}).then((e=>{const t=y?e:e[0],n=(0,m.i)(S);r({answersLink:t.answered_link+`?locale=${n}`,answersLinkText:t.answered_link_text,gravatars:t.answered_users_sample.map((({avatar:e})=>({url:e}))),promptFetched:!0,promptLabel:t.label,promptText:t.text,promptId:t.id,isBloganuary:!!t.bloganuary_id})})).catch((n=>{r({promptFetched:!0});const s="rest_post_invalid_id"===n.code&&y?(o=y,(0,a.createElement)(a.Fragment,null,(0,u.sprintf)(/* translators: %d is the prompt id. */ __("Prompt with id %d not found.","jetpack"),o)," ",(0,a.createElement)(i.Button,{variant:"link",onClick:e},__("Reset prompt","jetpack")))):(t=>(0,a.createElement)(a.Fragment,null,(0,u.sprintf)(/* translators: %s is the error message. */ @@ -120,7 +120,7 @@ __("Delete %s","jetpack"),o.label),disabled:r===l},r===l?__("Deleting","jetpack" (0,u.sprintf)(__("Allowed formats: %s","jetpack"),m))),(0,a.createElement)("div",{className:"videopress-block-tracks-editor__single-track-editor-label-language"},(0,a.createElement)(i.TextControl,{onChange:t=>n({...e,label:t}),label:__("Label","jetpack"),value:y,help:__("Title of track","jetpack"),disabled:b,__nextHasNoMarginBottom:!0}),(0,a.createElement)(i.TextControl,{onChange:t=>n({...e,srcLang:t}),label:__("Source language","jetpack"),value:E,help:__("Language tag (en, fr, etc.)","jetpack"),disabled:b,__nextHasNoMarginBottom:!0})),(0,a.createElement)(i.SelectControl,{className:"videopress-block-tracks-editor__single-track-editor-kind-select",options:h,value:w,label:/* translators: %s: The kind of video text track e.g: "Subtitles, Captions" */ __("Kind","jetpack"),onChange:t=>{n({...e,kind:t})},disabled:b,__nextHasNoMarginBottom:!0}),(0,a.createElement)("div",{className:"videopress-block-tracks-editor__single-track-editor-buttons-container"},b?(0,a.createElement)(i.Spinner,null):(0,a.createElement)(i.Button,{variant:"secondary",disabled:!e.tmpFile,onClick:()=>{f(null),""===y&&(e.label=__("English","jetpack")),""===E&&(e.srcLang="en"),void 0===e.kind&&(e.kind=p),d(e)?f(__("A track already exists for that language and kind.","jetpack")):(k(!0),v(e,t).then((()=>{n(e),f(null),r()})).catch((e=>{e.message&&f(e.message)})).finally((()=>{k(!1)})))}},__("Save","jetpack")),(0,a.createElement)(i.Button,{variant:"link",onClick:s},__("Close","jetpack"))),g&&(0,a.createElement)("div",{className:"videopress-block-tracks-editor__single-track-editor-error"},/* translators: %s: An error message returned after a failed video track file upload." */ /* translators: %s: An error message returned after a failed video track file upload." */ (0,u.sprintf)(__("Error: %s","jetpack"),g))))}function E({tracks:e=[],onChange:t,guid:n}){const[r,s]=(0,c.useState)(null);return(0,a.createElement)(i.Dropdown,{contentClassName:"videopress-block-tracks-editor",renderToggle:({isOpen:e,onToggle:t})=>(0,a.createElement)(i.ToolbarButton,{label:__("Text tracks","jetpack"),showTooltip:!0,"aria-expanded":e,"aria-haspopup":"true",onClick:t,icon:g}),renderContent:()=>null!==r?(0,a.createElement)(y,{track:e[r],guid:n,onChange:n=>{const a=[...e];a[r]=n,t(a)},onClose:()=>s(null),onCancel:()=>{t(e.filter(((e,t)=>t!==r))),s(null)},trackExists:t=>-1!==e.filter(((e,t)=>t!==r)).findIndex((e=>e.kind===t.kind&&e.srcLang===t.srcLang))}):(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.NavigableMenu,null,(0,a.createElement)(k,{tracks:e,onChange:t,guid:n}),(0,a.createElement)(i.MenuGroup,{className:"videopress-block-tracks-editor__add-tracks-container",label:__("Add tracks","jetpack")},(0,a.createElement)(i.MenuItem,{icon:d.A,onClick:()=>{(()=>{const n=e.length,a=[...e];a[n]||(a[n]={}),a[n]={...e[n]},t(a),s(n)})()}},__("Upload track","jetpack")))))})}},22857:(e,t,n)=>{"use strict";n.d(t,{d:()=>h});var a=n(82170),r=n(94715),s=n(56427),o=n(86087),i=n(27723),l=n(51113),c=n(13022),u=n(12199);const __=i.__,d=["image"],p=e=>{const{videoPosterImageUrl:t}=e;return(0,a.createElement)("div",{className:"resumable-upload__editor-thumb-placeholder"},t?(0,a.createElement)(a.Fragment,null,(0,a.createElement)("img",{src:t,alt:"Poster"}),(0,a.createElement)(l.A,{className:"uploading-editor__play-icon",icon:u.ud})):(0,a.createElement)("span",null,"No Poster Selected"))},m=e=>{const{onSelectPoster:t,onRemovePoster:n}=e;return(0,a.createElement)(s.BaseControl,{className:(0,c.A)(e.className,"editor-video-poster-control")},(0,a.createElement)(p,e),(0,a.createElement)(r.MediaUpload,{title:__("Select Poster Image","jetpack"),onSelect:t,allowedTypes:d,render:({open:e})=>(0,a.createElement)("div",{className:"poster-selector__buttons"},(0,a.createElement)(s.Button,{onClick:n,variant:"link",isDestructive:!0},__("Remove Poster Image","jetpack")),(0,a.createElement)(s.Button,{variant:"secondary",onClick:e},__("Select Poster Image","jetpack")))}))},h=e=>{const{file:t,onSelectPoster:n,onRemovePoster:i,videoPosterImageData:c,title:p,onChangeTitle:h,onVideoFrameSelected:g}=e,[f,v]=(0,o.useState)(0),[b,k]=(0,o.useState)(!0),y=(0,o.useRef)(null),E=(0,o.useRef)(null),w=()=>{k(!1)};(0,o.useEffect)((()=>{null!==t&&y&&(y.current.src=URL.createObjectURL(t))}),[t,y]);const _={};return c&&(_.display="none"),(0,a.createElement)(a.Fragment,null,(0,a.createElement)("div",{className:"uploading-editor"},(0,a.createElement)("div",{className:"uploading-editor__summary"}),(0,a.createElement)("div",{className:"uploading-editor__fields"},(0,a.createElement)(s.TextControl,{label:__("Video title","jetpack"),className:"uploading-editor__title",onChange:h,value:p,__nextHasNoMarginBottom:!0}),(0,a.createElement)("div",{className:"uploading-editor__content"},(0,a.createElement)(s.BaseControl,{__nextHasNoMarginBottom:!0},(0,a.createElement)(s.BaseControl.VisualLabel,null,__("Video poster (optional)","jetpack")),b?(0,a.createElement)(a.Fragment,null,(0,a.createElement)("div",{className:"uploading-editor__video-container"},(0,a.createElement)("div",{className:"uploading-editor__video-poster-wrapper"},c&&(0,a.createElement)(m,{onSelectPoster:n,onRemovePoster:i,videoPosterImageUrl:c.url}),(0,a.createElement)("video",{ref:y,muted:!0,className:"uploading-editor__video",onDurationChange:e=>{const t=e.target.duration;v(t),y.current&&(y.current.currentTime=t/2)},onError:w,onLoadedMetadata:e=>{e.target.videoHeight||w()},style:_})),!c&&(0,a.createElement)(l.A,{className:"uploading-editor__play-icon",icon:u.ud})),(0,a.createElement)("span",{style:_},(0,a.createElement)(s.RangeControl,{className:"uploading-editor__range",min:"0",step:"0.1",max:f,showTooltip:!1,withInputField:!1,onChange:e=>{g(1e3*e),y.current&&(y.current.currentTime=e)},__nextHasNoMarginBottom:!0})),(0,a.createElement)("span",{className:"uploading-editor__scrubber-help",style:_},(0,o.createInterpolateElement)(__("This is how the video will look. Use the slider to choose a poster or select a custom one.","jetpack"),{a:(0,a.createElement)(r.MediaUpload,{title:__("Select Poster Image","jetpack"),onSelect:n,allowedTypes:d,render:({open:e})=>(0,a.createElement)("a",{className:"uploading-editor__upload-link",onClick:e,onKeyDown:e,ref:E,role:"button",tabIndex:0},__("select a custom one","jetpack"))})}))):(0,a.createElement)(m,{onSelectPoster:n,videoPosterImageUrl:c?c.url:null}))))))}},17900:(e,t,n)=>{"use strict";n.d(t,{e:()=>r});var a=n(93832);const r=(e,{autoplay:t,controls:n,loop:r,muted:s,playsinline:o,poster:i,preload:l,seekbarColor:c,seekbarPlayedColor:u,seekbarLoadingColor:d,useAverageColor:p})=>{if(!e)return null;const m={resizeToParent:!0,cover:!0,...t&&{autoPlay:!0},...!n&&{controls:!1},...r&&{loop:!0},...s&&{muted:!0,persistVolume:!1},...o&&{playsinline:!0},...i&&{posterUrl:i},...""!==l&&{preloadContent:l},...""!==c&&{sbc:c},...""!==u&&{sbpc:u},...""!==d&&{sblc:d},...p&&{useAverageColor:!0}};return(0,a.addQueryArgs)(`https://videopress.com/v/${e}`,m)}},47960:(e,t,n)=>{"use strict";n.d(t,{QW:()=>l,T3:()=>i,Zz:()=>o,x1:()=>c});n(74997);var a=n(13022),r=n(74628);const s=e=>{const t=r.C1.reduce(((e,{className:t})=>(e[t]=!1,e)),{"wp-has-aspect-ratio":!1});return(0,a.A)(e,t)};function o(e,t="",n=!0){if(!n)return s(t);const o=document.implementation.createHTMLDocument("");o.body.innerHTML=e;const i=o.body.querySelector("iframe");if(i&&i.height&&i.width){const e=(i.width/i.height).toFixed(2);for(let n=0;n=o.ratio)return(0,a.A)(s(t),o.className,"wp-has-aspect-ratio")}}return t}const i=e=>e.replace(/\.[^/.]+$/,""),l=e=>{if(!e||"string"!=typeof e)return null;const t=e.match(/^https?:\/\/(?video(?:\.word|s\.files\.word)?press\.com)(?:\/v|\/embed)?\/(?[a-zA-Z\d]{8})/);return t?.groups?.guid?t.groups.guid:null},c=e=>{const{guid:t,videoPressTracks:n,isVideoPressExample:a}=e;if(!t?.length)return!1;if(!Array.isArray(n))return!1;return!(!Object.keys(e).includes("isVideoPressExample")||"boolean"!=typeof a)}},58731:(e,t,n)=>{"use strict";n.d(t,{A:()=>g});var a=n(82170),r=n(85985),s=n(94715),o=n(74997),i=n(56427),l=n(47143),c=n(43656),u=(n(86087),n(27723)),d=n(47960),p=n(54746);const __=u.__,m={instances:[]},h=(e=[],t=!1,n=0)=>{if(t&&(m.instances=[]),e.forEach((e=>{if(e.innerBlocks.length)return void h(e.innerBlocks,!1,n+1);const{clientId:t,name:a,attributes:r}=e;"core/video"===a&&(0,d.x1)(r)&&m.instances.push({clientId:t,name:a,attributes:r})})),0===n)return m.instances};function g({clientId:e,attributes:t}){const n=(0,l.useSelect)((e=>e(c.store).getCurrentPostId())),{getBlocks:u}=(0,l.useSelect)(s.store),{replaceBlock:m}=(0,l.useDispatch)(s.store),{tracks:g}=(0,r.st)();return(0,a.createElement)("div",{className:p.A.wrapper},(0,a.createElement)(i.Notice,{status:"info",isDismissible:!1,className:p.A["conversion-notice"]},__("You can transform this post's video blocks to the new VideoPress block to take advantage of new features, such as adding chapters directly in the description or hiding the video's share menu.","jetpack")),(0,a.createElement)(i.Button,{variant:"primary",onClick:()=>{const a=h(u(),!0);a?.length&&(a.find((t=>t.clientId===e))||a.push({clientId:e,name:"core/video",currentBlockAttributes:t}),a.forEach((e=>{const{clientId:t,name:a,attributes:r}=e;"core/video"===a&&(0,d.x1)(r)&&(m(t,(0,o.createBlock)("videopress/video",r)),g.recordEvent("jetpack_editor_videopress_block_manual_conversion_click",{post_id:n}))})))}},__("Transform blocks to VideoPress","jetpack")))}},55159:(e,t,n)=>{"use strict";n.d(t,{A:()=>l});var a=n(82170),r=n(94715),s=n(29491),o=n(47960),i=n(58731);const l=(0,s.createHigherOrderComponent)((e=>t=>(0,o.x1)(t.attributes)?(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.InspectorControls,null,(0,a.createElement)(i.A,{clientId:t.clientId,attributes:t.attributes})),(0,a.createElement)(e,t)):(0,a.createElement)(e,t)))},51983:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var a=n(85985),r=n(55159);const s="videopress/video";function o(e,t){if("core/video"!==t)return e;const{available:n}=(0,a.FB)(s);return n?{...e,edit:(0,r.A)(e.edit)}:e}},5146:(e,t,n)=>{"use strict";n.d(t,{A:()=>d});var a=n(82170),r=n(56427),s=n(27723),o=n(67858),i=n(84605);const __=s.__,l="videopress/video-chapters",c=!!window?.Jetpack_Editor_Initial_State?.available_blocks[l],u=31;function d({isRequestingVideoItem:e}){const{attributes:t,setAttributes:n}=(0,i.A)();if(!c)return null;const{title:s,description:d}=t,p=(0,o.m)(l),m=d?.length?d.split("\n").map((e=>Math.ceil(e.length/u)||1)).reduce(((e,t)=>e+t),0):4,h=Math.min(12,Math.max(m,4));return(0,a.createElement)(r.PanelBody,{title:__("Details","jetpack"),className:p?"is-beta":""},(0,a.createElement)(r.TextControl,{label:__("Title","jetpack"),value:s,placeholder:__("Video title","jetpack"),onChange:e=>{n({title:e})},disabled:e}),(0,a.createElement)(r.TextareaControl,{label:__("Description","jetpack"),value:d,placeholder:__("Video description","jetpack"),onChange:e=>{n({description:e})},disabled:e,rows:h}))}},83112:(e,t,n)=>{"use strict";n.d(t,{A:()=>d});var a=n(82170),r=n(94715),s=n(29491),o=n(86087),i=n(5146),l=n(52753),c=n(95501),u=n(7345);const d=(0,s.createHigherOrderComponent)((e=>t=>{const{attributes:n,setAttributes:s}=t,[d,p]=(0,l.A)(n?.id),[m]=(0,c.n)(n);return(0,o.useEffect)((()=>{if(!d)return;const e={};d?.title&&(e.title=d.title),d?.description&&(e.description=d.description),Object.keys(e).length&&(s(e),m(e))}),[d,s,m]),u.j&&"core/video"!==!t.name&&t.attributes?.guid?(0,a.createElement)(a.Fragment,null,(0,a.createElement)(r.InspectorControls,null,(0,a.createElement)(i.A,{isRequestingVideoItem:p})),(0,a.createElement)(e,t)):(0,a.createElement)(e,t)}))},84605:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var a=n(94715),r=n(47143);function s(){const{clientId:e,attributes:t}=(0,r.useSelect)((e=>{const t=e(a.store).getSelectedBlockClientId();return{clientId:t,attributes:t?e("core/block-editor").getBlockAttributes(t):void 0}})),{updateBlockAttributes:n}=(0,r.useDispatch)(a.store);return{clientId:e,attributes:t,setAttributes:t=>n(e,t)}}},95501:(e,t,n)=>{"use strict";n.d(t,{n:()=>g});var a=n(1455),r=n.n(a),s=n(29491),o=n(3582),i=n(47143),l=n(43656),c=n(86087),u=n(27723),d=n(96247),p=n(17900),m=n(17204),h=n(97393);const __=u.__;function g(e){const{id:t,title:n,description:a,guid:u}=e,g=(0,i.useSelect)((e=>e(l.store).isSavingPost()),[]),f=(0,s.usePrevious)(g),v=(0,i.useDispatch)(o.store).invalidateResolution,[b,k]=(0,c.useState)(),y=(0,c.useCallback)((e=>{k((t=>({...t,...e})))}),[]);(0,c.useEffect)((()=>{k({title:n,description:a})}),[]);const E=function(e){return t=>new Promise(((n,a)=>{r()({path:"/wpcom/v2/videopress/meta",method:"POST",data:{id:e,...t}}).then((e=>{if(200!==e?.data)return a(e);n(e)})).catch(a)}))}(t);return(0,c.useEffect)((()=>{if(!g||f)return;if(!t)return;const r={};if(b?.title!==n&&(r.title=n),b?.description!==a&&(r.description=a),!Object.keys(r).length)return;if(E(r).then((()=>y({title:n,description:a}))),!r?.description?.length)return;const s=(0,m.Ay)(r.description);if(!s?.length)return;const o={label:__("English","jetpack"),srcLang:"en",kind:"chapters",tmpFile:(0,h.Ay)(r.description)};(0,d.n)(o,u).then((()=>{const t=(0,p.e)(u,e);v("getEmbedPreview",[t])}))}),[g,f,n,b?.title,b?.description,a,E,y,e,v,t,u]),[y]}},52753:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var a=n(1455),r=n.n(a),s=n(86087);function o(e){const[t,n]=(0,s.useState)({}),[a,o]=(0,s.useState)(!1);return(0,s.useEffect)((()=>{e&&(o(!0),async function(){try{const t=await r()({path:`/wp/v2/media/${e}`});n(t?.jetpack_videopress||{}),o(!1)}catch(e){throw o(!1),new Error(e)}}())}),[e]),[t,a]}},7345:(e,t,n)=>{"use strict";n.d(t,{A:()=>s,j:()=>r});var a=n(83112);const r=!!window?.Jetpack_Editor_Initial_State?.available_blocks["videopress/video-chapters"];function s(e,t){if(!r)return e;if("core/video"!==t)return e;const n={...e.attributes,title:{type:"string"},description:{type:"string"}};return{...e,attributes:n,edit:(0,a.A)(e.edit)}}},17204:(e,t,n)=>{"use strict";function a(e){return e.split("\n").map((e=>function(e){const t=/(?\(?(?