- 1
- 2
(()=>{var e={942:(e,t)=>{var n;!function(){"use strict";var r={}.hasOwnProperty;function s(){for(var e="",t=0;t{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=ampSiteScanNotice,t=window.wp.domReady;var r=n.n(t);const s=window.wp.element,i=window.wp.i18n,a=window.ReactJSXRuntime,l=(0,s.createContext)();function c({children:e}){const[t,n]=(0,s.useState)(null);return(0,a.jsx)(l.Provider,{value:{error:t,setError:n},children:e})}const o=window.wp.apiFetch;var u=n.n(o);const d=window.wp.url;function p(){const[e,t]=(0,s.useState)();return{error:e,setAsyncError:(0,s.useCallback)((e=>{t((()=>{throw e}))}),[])}}const h=(0,s.createContext)();function m({children:e,optionsRestPath:t,populateDefaultValues:n,hasErrorBoundary:r=!1,delaySave:i=!1}){const[c,o]=(0,s.useState)({}),[m,f]=(0,s.useState)(!1),[_,S]=(0,s.useState)(null),[g,y]=(0,s.useState)({}),[x,b]=(0,s.useState)(!1),[A,E]=(0,s.useState)(!1),[I,v]=(0,s.useState)({}),[C,U]=(0,s.useState)({}),{error:j,setError:w}=(0,s.useContext)(l),{setAsyncError:P}=p(),[T,N]=(0,s.useState)(!1),O=(0,s.useRef)(!1);(0,s.useEffect)((()=>()=>{O.current=!0}),[]);const R=(0,s.useCallback)((()=>{j||m||(async()=>{f(!0);try{const e=await u()({path:(0,d.addQueryArgs)(t,{_fields:["suppressed_plugins","suppressible_plugins"]})});if(!0===O.current)return;v({...I,...e})}catch(e){if(!0===O.current)return;return w(e),void(r&&P(e))}f(!1)})()}),[j,m,r,t,I,P,w]);(0,s.useEffect)((()=>{j||Object.keys(I).length||_||(async()=>{S(!0);try{const e=await u()({path:t});if(!0===O.current)return;n||!1!==e.plugin_configured||(e.mobile_redirect=!0,e.reader_theme=null,e.theme_support=null),v(e)}catch(e){if(!0===O.current)return;return w(e),void(r&&P(e))}S(!1)})()}),[j,_,r,I,t,n,P,w]);const L=(0,s.useCallback)((async()=>{b(!0);try{const e={...c};null===e.reader_theme&&delete e.reader_theme,I.plugin_configured||"mobile_redirect"in e||(e.mobile_redirect=I.mobile_redirect),I.plugin_configured||(e.plugin_configured=!0);const[n]=await Promise.all([u()({method:"post",path:t,data:e}),i?new Promise((e=>{setTimeout(e,1e3)})):()=>{}]);if(!0===O.current)return;v(n),w(null)}catch(e){if(!0===O.current)return;return b(!1),w(e),void(r&&P(e))}U({...C,...c}),(0,s.flushSync)((()=>{y(c),o({}),E(!0)})),b(!1)}),[i,r,t,P,I,w,c,C]),M=(0,s.useCallback)((e=>{o({...c,...e}),E(!1)}),[c]),k=(0,s.useCallback)((e=>{const t={...c};delete t[e],o(t)}),[c]);return(0,a.jsx)(h.Provider,{value:{editedOptions:{...I,...c},fetchingOptions:_,hasOptionsChanges:Boolean(Object.keys(c).length),didSaveOptions:A,updates:c,originalOptions:I,saveOptions:L,savedOptions:g,savingOptions:x,unsetOption:k,updateOptions:M,readerModeWasOverridden:T,refetchPluginSuppression:R,setReaderModeWasOverridden:N,modifiedOptions:C},children:e})}const f=(0,s.createContext)();function _({children:e}){const[t,n]=(0,s.useState)([]),[r,i]=(0,s.useState)(null),[l,c]=(0,s.useState)(),o=(0,s.useRef)(!1);return(0,s.useEffect)((()=>()=>{o.current=!0}),[]),(0,s.useEffect)((()=>{l||t.length>0||r||(async()=>{i(!0);try{const e=await u()({path:(0,d.addQueryArgs)("/wp/v2/plugins",{_fields:["author","name","plugin","status","version"]})});if(!0===o.current)return;n(e)}catch(e){if(!0===o.current)return;c(e)}i(!1)})()}),[l,r,t]),(0,a.jsx)(f.Provider,{value:{fetchingPlugins:r,plugins:t},children:e})}const S="standard";function g(e=""){return e.replace(/\/.*$/,"").replace(/\.php$/,"")}const y=(0,s.createContext)(),x="ACTION_SET_STATUS",b="ACTION_SCANNABLE_URLS_REQUEST",A="ACTION_SCANNABLE_URLS_RECEIVE",E="ACTION_SCAN_INITIALIZE",I="ACTION_SCAN_URL",v="ACTION_SCAN_RECEIVE_RESULTS",C="ACTION_SCAN_COMPLETE",U="ACTION_SCAN_CANCEL",j="STATUS_REQUEST_SCANNABLE_URLS",w="STATUS_FETCHING_SCANNABLE_URLS",P="STATUS_REFETCHING_PLUGIN_SUPPRESSION",T="STATUS_READY",N="STATUS_IDLE",O="STATUS_IN_PROGRESS",R="STATUS_COMPLETED",L="STATUS_FAILED",M="STATUS_CANCELLED",k="STATUS_SKIPPED",B={currentlyScannedUrlIndexes:[],forceStandardMode:!1,scannableUrls:[],scanOnce:!1,status:"",scansCount:0,urlIndexesPendingScan:[]},D=3,W=500;function $(e,t){if(e.status===k)return e;switch(t.type){case x:return{...e,status:t.status};case b:var n;return{...e,status:j,forceStandardMode:null!==(n=t?.forceStandardMode)&&void 0!==n&&n,currentlyScannedUrlIndexes:[],urlIndexesPendingScan:[]};case A:{const n=Array.isArray(t.scannableUrls)&&t.scannableUrls.length>0;return{...e,status:e.scanOnce&&e.scansCount>0||!n?R:T,scannableUrls:n?t.scannableUrls:[]}}case E:return[T,R,L,M].includes(e.status)?e.scanOnce&&e.scansCount>0?{...e,status:R}:{...e,status:N,currentlyScannedUrlIndexes:[],scansCount:e.scansCount+1,urlIndexesPendingScan:e.scannableUrls.map(((e,t)=>t))}:e;case I:return[N,O].includes(e.status)?{...e,status:O,currentlyScannedUrlIndexes:[...e.currentlyScannedUrlIndexes,t.currentlyScannedUrlIndex],urlIndexesPendingScan:e.urlIndexesPendingScan.filter((e=>e!==t.currentlyScannedUrlIndex))}:e;case v:var r;return[N,O].includes(e.status)?{...e,status:N,currentlyScannedUrlIndexes:e.currentlyScannedUrlIndexes.filter((e=>e!==t.currentlyScannedUrlIndex)),scannableUrls:[...e.scannableUrls.slice(0,t.currentlyScannedUrlIndex),{...e.scannableUrls[t.currentlyScannedUrlIndex],stale:!1,error:null!==(r=t.error)&&void 0!==r&&r,validated_url_post:t.error?{}:t.validatedUrlPost,validation_errors:t.error?[]:t.validationErrors},...e.scannableUrls.slice(t.currentlyScannedUrlIndex+1)]}:e;case C:{const t=e.scannableUrls.every((e=>Boolean(e.error)));return{...e,status:t?L:P}}case U:return[N,O].includes(e.status)?{...e,status:M,currentlyScannedUrlIndexes:[],urlIndexesPendingScan:[]}:e;default:throw new Error(`Unhandled action type: ${t.type}`)}}function F({children:e,fetchCachedValidationErrors:t=!1,refetchPluginSuppressionOnScanComplete:n=!1,resetOnOptionsChange:r=!1,scannableUrlsRestPath:i,scanOnce:l=!1,validateNonce:c}){var o;const{originalOptions:{theme_support:m},savedOptions:f,refetchPluginSuppression:_}=(0,s.useContext)(h),{setAsyncError:F}=p(),[V,G]=(0,s.useReducer)($,{...B,scanOnce:l}),{currentlyScannedUrlIndexes:H,forceStandardMode:Q,scannableUrls:z,urlIndexesPendingScan:J,status:K}=V,X=Q||m===S?"url":"amp_url",Y=null!==(o=z?.[0]?.[X])&&void 0!==o?o:"",{hasSiteScanResults:Z,pluginsWithAmpIncompatibility:q,stale:ee,themesWithAmpIncompatibility:te}=(0,s.useMemo)((()=>{if(![T,R,k].includes(K))return{hasSiteScanResults:!1,pluginsWithAmpIncompatibility:[],stale:!1,themesWithAmpIncompatibility:[]};const e=function(e=[],{useAmpUrls:t=!1}={}){const n=new Map,r=new Map;for(const s of e){const{amp_url:e,url:i,validation_errors:a}=s;if(a?.length)for(const s of a)if(s?.sources?.length)for(const a of s.sources)if(a?.type)if("plugin"===a.type){const r=g(a.name);if("gutenberg"===r&&s.sources.length>1)continue;n.set(r,new Set([...n.get(r)||[],t?e:i]))}else"theme"===a.type&&r.set(a.name,new Set([...r.get(a.name)||[],t?e:i]))}return n.delete("amp"),{plugins:[...n].map((([e,t])=>({slug:e,urls:[...t]}))),themes:[...r].map((([e,t])=>({slug:e,urls:[...t]})))}}(z,{useAmpUrls:"amp_url"===X});return{hasSiteScanResults:z.some((e=>Boolean(e?.validation_errors))),pluginsWithAmpIncompatibility:e.plugins,stale:z.some((e=>!0===e?.stale)),themesWithAmpIncompatibility:e.themes}}),[z,K,X]);(0,s.useEffect)((()=>{c||K===k||G({type:x,status:k})}),[K,c]);const ne=(0,s.useRef)(!1);(0,s.useEffect)((()=>()=>{ne.current=!0}),[]);const re=(0,s.useCallback)(((e={})=>{G({type:b,forceStandardMode:e?.forceStandardMode})}),[]),se=(0,s.useCallback)((()=>{G({type:E})}),[]),ie=(0,s.useCallback)((()=>{G({type:U})}),[]);(0,s.useEffect)((()=>{r&&Object.keys(f).length>0&&G({type:b})}),[r,f]),(0,s.useEffect)((()=>{K===T&&Object.keys(f.suppressed_plugins||{}).length>0&&G({type:E})}),[f?.suppressed_plugins,K]),(0,s.useEffect)((()=>{K===P&&(n&&_(),G({type:x,status:R}))}),[_,n,K]);const[ae,le]=(0,s.useState)(!1);return(0,s.useEffect)((()=>{let e;return ae&&(async()=>{await new Promise((t=>{e=setTimeout(t,W)})),!0!==ne.current&&le(!1)})(),()=>{e&&clearTimeout(e)}}),[ae]),(0,s.useEffect)((()=>{(async()=>{if(K===j){G({type:x,status:w});try{const e=["url","amp_url","type","label"],n=await u()({path:(0,d.addQueryArgs)(i,{_fields:t?[...e,"validation_errors","stale"]:e,force_standard_mode:Q?1:void 0})});if(!0===ne.current)return;G({type:A,scannableUrls:n})}catch(e){if(!0===ne.current)return;F(e)}}})()}),[t,Q,i,F,K]),(0,s.useEffect)((()=>{if(![N,O].includes(K))return;if(0===J.length)return void(0===H.length&&G({type:C}));if(ae||H.length>=D)return;le(!0);const e=J[0];G({type:I,currentlyScannedUrlIndex:e}),(async()=>{const t={};try{const n=z[e][X],r={amp_validate:{cache:!0,cache_bust:Math.random(),force_standard_mode:Q||void 0,nonce:c,omit_stylesheets:!0}},s=await fetch((0,d.addQueryArgs)(n,r)),i=await s.json();if(!0===ne.current)return;s.ok?(t.validatedUrlPost=i.validated_url_post,t.validationErrors=i.results.map((({error:e})=>e))):t.error=i?.code||!0}catch(e){if(!0===ne.current)return;t.error=!0}G({type:v,currentlyScannedUrlIndex:e,...t}),le(!1)})()}),[H.length,Q,z,ae,K,J,X,c]),(0,a.jsx)(y.Provider,{value:{cancelSiteScan:ie,fetchScannableUrls:re,forceStandardMode:Q,hasSiteScanResults:Z,isBusy:[N,O].includes(K),isCancelled:K===M,isCompleted:[P,R].includes(K),isFailed:K===L,isFetchingScannableUrls:[j,w].includes(K),isInitializing:!Boolean(K),isReady:K===T,isSiteScannable:z.length>0,isSkipped:K===k,pluginsWithAmpIncompatibility:q,previewPermalink:Y,scannableUrls:z,scannedUrlsMaxIndex:([O,N].includes(K)?Math.min(z.length,...J):0)-1,stale:ee,startSiteScan:se,themesWithAmpIncompatibility:te},children:e})}const V=(0,s.createContext)();function G({children:e}){const[t,n]=(0,s.useState)([]),[r,i]=(0,s.useState)(null),[l,c]=(0,s.useState)(),o=(0,s.useRef)(!1);return(0,s.useEffect)((()=>()=>{o.current=!0}),[]),(0,s.useEffect)((()=>{l||t.length>0||r||(async()=>{i(!0);try{const e=await u()({path:(0,d.addQueryArgs)("/wp/v2/themes",{_fields:["author","name","status","stylesheet","template","version"]})});if(!0===o.current)return;n(e)}catch(e){if(!0===o.current)return;c(e)}i(!1)})()}),[l,r,t]),(0,a.jsx)(V.Provider,{value:{fetchingThemes:r,themes:t},children:e})}const H=window.wp.components,Q=window.wp.compose,z=4e3;function J({children:e,onCopy:t,onFinishCopy:n,text:r,...i}){const l=(0,s.useRef)(),c=(0,Q.useCopyToClipboard)(r,(()=>{t&&t(),clearTimeout(l.current),n&&(l.current=setTimeout((()=>n()),z))}));return(0,s.useEffect)((()=>{clearTimeout(l.current)}),[]),(0,a.jsx)(H.Button,{...i,className:"components-clipboard-button",ref:c,onCopy:e=>{e.target.focus()},children:e})}function K({error:e,finishLinkLabel:t,finishLinkUrl:n,title:r}){const[l,c]=(0,s.useState)(!1),{message:o,stack:u}=e;return(0,a.jsx)("div",{className:"error-screen-container",children:(0,a.jsxs)(H.Panel,{className:"error-screen",children:[(0,a.jsx)("h1",{children:r||(0,i.__)("Something went wrong.","amp")}),(0,a.jsx)("p",{dangerouslySetInnerHTML:{__html:o||(0,i.__)("There was an error loading the page.","amp")}}),(0,a.jsx)("p",{children:(0,s.createInterpolateElement)((0,i.__)("Please submit details to our support forum.","amp"),{a:(0,a.jsx)("a",{href:"https://wordpress.org/support/plugin/amp/",target:"_blank",rel:"noreferrer noopener"})})}),u&&(0,a.jsxs)("details",{children:[(0,a.jsx)("summary",{children:(0,i.__)("Details","amp")}),(0,a.jsx)("pre",{children:u}),(0,a.jsx)(J,{isSmall:!0,isSecondary:!0,text:JSON.stringify({message:o,stack:u},null,2),onCopy:()=>c(!0),onFinishCopy:()=>c(!1),children:l?(0,i.__)("Copied!","amp"):(0,i.__)("Copy Error","amp")})]}),n&&t&&(0,a.jsx)("p",{children:(0,a.jsx)("a",{href:n,children:t})})]})})}class X extends s.Component{constructor(e){super(e),this.timeout=null,this.state={error:null}}componentDidMount(){this.mounted=!0}componentWillUnmount(){this.mounted=!1}componentDidCatch(e){this.setState({error:e})}render(){const{error:e}=this.state,{children:t,exitLinkLabel:n,exitLinkUrl:r,title:s}=this.props;return e?(0,a.jsx)(K,{error:e,finishLinkLabel:n,finishLinkUrl:r,title:s}):t}}var Y=n(942),Z=n.n(Y);const q="info",ee="success",te="warning",ne="error";function re({children:e,className:t,isDismissible:n=!1,onDismiss:r,type:l=q}){const[c,o]=(0,s.useState)(!1),u=(0,s.useCallback)((()=>{o(!0),"function"==typeof r&&r()}),[r]);return n&&c?null:(0,a.jsxs)("div",{className:Z()("amp-admin-notice",t,{"amp-admin-notice--dismissible":n,"amp-admin-notice--info":l===q,"amp-admin-notice--success":l===ee,"amp-admin-notice--warning":l===te,"amp-admin-notice--error":l===ne}),children:[e,n&&(0,a.jsx)("button",{type:"button",onClick:u,className:"amp-admin-notice__dismiss",children:(0,a.jsx)(H.VisuallyHidden,{as:"span",children:(0,i.__)("Dismiss","amp")})})]})}function se({inline:e=!1}){const t=e?"span":"div";return(0,a.jsx)(t,{className:Z()("amp-spinner-container",{"amp-spinner-container--inline":e}),children:(0,a.jsx)(H.Spinner,{})})}const ie=e=>n.g?.location?.host!==new URL(e).host,ae=new URL(e.SETTINGS_LINK);function le({pluginsWithAmpIncompatibility:t}){const{fetchingPlugins:n,plugins:r}=(0,s.useContext)(f),l=(0,s.useMemo)((()=>r?.reduce(((e,t)=>({...e,[g(t.plugin)]:t.name})),{})),[r]);return n?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:(0,i._n)("AMP compatibility issue(s) discovered with the following plugin:","AMP compatibility issue(s) discovered with the following plugins:",t.length,"amp")}),t.map((e=>(0,a.jsxs)("details",{className:"amp-site-scan-notice__source-details",children:[(0,a.jsx)("summary",{className:"amp-site-scan-notice__source-summary",children:(0,s.createInterpolateElement)((0,i.sprintf)(/* translators: 1: plugin name; 2: number of URLs with AMP validation issues. */ /* translators: 1: plugin name; 2: number of URLs with AMP validation issues. */
(0,i._n)("%1$s on %2$d URL","%1$s on %2$d URLs",e.urls.length,"amp"),l[e.slug],e.urls.length),{b:(0,a.jsx)("b",{})})}),(0,a.jsx)("ul",{className:"amp-site-scan-notice__urls-list",children:e.urls.map((e=>(0,a.jsx)("li",{children:(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:e})},e)))})]},e.slug))),(0,a.jsxs)("div",{className:"amp-site-scan-notice__cta",children:[(0,a.jsx)("a",{href:ae.href,className:"button",children:(0,i.__)("Review Plugin Suppression","amp")}),(0,a.jsx)("a",{href:e.AMP_COMPATIBLE_PLUGINS_URL,className:"button",...ie(e.AMP_COMPATIBLE_PLUGINS_URL)?{target:"_blank",rel:"noopener noreferrer"}:{},children:(0,i.__)("View AMP-Compatible Plugins","amp")})]})]})}function ce({themesWithAmpIncompatibility:t}){const{fetchingThemes:n,themes:r}=(0,s.useContext)(V),l=(0,s.useMemo)((()=>r?.reduce(((e,t)=>{var n;return{...e,[t.stylesheet]:null!==(n=t.name?.rendered)&&void 0!==n?n:t.name}}),{})),[r]);return n?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:(0,i._n)("AMP compatibility issue(s) discovered with the following theme:","AMP compatibility issue(s) discovered with the following themes:",t.length,"amp")}),t.map((e=>(0,a.jsxs)("details",{className:"amp-site-scan-notice__source-details",children:[(0,a.jsx)("summary",{className:"amp-site-scan-notice__source-summary",children:(0,s.createInterpolateElement)((0,i.sprintf)(/* translators: 1: theme name; 2: number of URLs with AMP validation issues. */ /* translators: 1: theme name; 2: number of URLs with AMP validation issues. */
(0,i._n)("%1$s on %2$d URL","%1$s on %2$d URLs",e.urls.length,"amp"),l[e.slug],e.urls.length),{b:(0,a.jsx)("b",{})})}),(0,a.jsx)("ul",{className:"amp-site-scan-notice__urls-list",children:e.urls.map((e=>(0,a.jsx)("li",{children:(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:e})},e)))})]},e.slug))),(0,a.jsx)("div",{className:"amp-site-scan-notice__cta",children:(0,a.jsx)("a",{href:e.AMP_COMPATIBLE_THEMES_URL,className:"button",...ie(e.AMP_COMPATIBLE_THEMES_URL)?{target:"_blank",rel:"noopener noreferrer"}:{},children:(0,i.__)("View AMP-Compatible Themes","amp")})})]})}function oe(){const{cancelSiteScan:e,fetchScannableUrls:t,isCancelled:n,isCompleted:r,isFailed:l,isInitializing:c,isReady:o,pluginsWithAmpIncompatibility:u,themesWithAmpIncompatibility:d,startSiteScan:p}=(0,s.useContext)(y);(0,s.useEffect)((()=>e),[e]),(0,s.useEffect)((()=>{c?t():o&&p()}),[t,c,o,p]);const h={className:"amp-site-scan-notice",isDismissible:!0,onDismiss:e};if(l||n)return(0,a.jsx)(re,{type:ne,...h,children:(0,a.jsx)("p",{children:(0,i.__)("AMP could not check your site for compatibility issues.","amp")})});if(r){let e=[u.length>0?(0,a.jsx)(le,{pluginsWithAmpIncompatibility:u},`plugins-${u.length}`):null,d.length>0?(0,a.jsx)(ce,{themesWithAmpIncompatibility:d},`themes-${d.length}`):null];return document.location.href.includes("themes.php")&&(e=e.reverse()),e=e.filter(Boolean),(0,a.jsx)(re,{type:e.length?te:ee,...h,children:e.length?e:(0,a.jsx)("p",{children:(0,i.__)("No AMP compatibility issues detected.","amp")})})}return(0,a.jsx)(re,{type:q,...h,children:(0,a.jsxs)("p",{children:[(0,i.__)("Checking your site for AMP compatibility issues…","amp"),(0,a.jsx)(se,{inline:!0})]})})}let ue;function de({children:t}){return n.g.removeEventListener("error",ue),(0,a.jsx)(c,{children:(0,a.jsx)(X,{title:(0,i.__)("The AMP Site Scanner has experienced an error.","amp"),children:(0,a.jsx)(m,{hasErrorBoundary:!0,optionsRestPath:e.OPTIONS_REST_PATH,populateDefaultValues:!1,children:(0,a.jsx)(_,{children:(0,a.jsx)(G,{children:(0,a.jsx)(F,{scannableUrlsRestPath:e.SCANNABLE_URLS_REST_PATH,validateNonce:e.VALIDATE_NONCE,children:t})})})})})})}ae.hash="plugin-suppression",r()((()=>{let t=document.getElementById(e.APP_ROOT_ID);if(!t){const n=document.getElementById(e.APP_ROOT_SIBLING_ID);if(!n)return;t=document.createElement("div"),t.setAttribute("id",e.APP_ROOT_ID),n.after(t)}ue=e=>{e.filename&&/amp-site-scan-notice(\.min)?\.js/.test(e.filename)&&(0,s.createRoot)(t).render((0,a.jsx)(K,{error:e.error}))},n.g.addEventListener("error",ue),(0,s.createRoot)(t).render((0,a.jsx)(de,{children:(0,a.jsx)(oe,{})}))}))})()})();;